Fri Jul 3 20:37:53 2009

Asterisk developer's documentation


features.h File Reference

Call Parking and Pickup API Includes code and algorithms from the Zapata library. More...

#include "asterisk/linkedlists.h"

Include dependency graph for features.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_call_feature
 main call feature structure More...

Defines

#define FEATURE_APP_ARGS_LEN   256
#define FEATURE_APP_LEN   64
#define FEATURE_EXTEN_LEN   32
#define FEATURE_MAX_LEN   11
#define FEATURE_MOH_LEN   80
#define FEATURE_SNAME_LEN   32
#define PARK_APP_NAME   "Park"

Functions

int ast_bridge_call (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
 Bridge a call, optionally allowing redirection.
int ast_masq_park_call (struct ast_channel *rchan, struct ast_channel *host, int timeout, int *extout)
 Park a call via a masqueraded channel.
int ast_park_call (struct ast_channel *chan, struct ast_channel *host, int timeout, int *extout)
 Park a call and read back parked location.
char * ast_parking_ext (void)
 Determine system parking extension Returns the call parking extension for drivers that provide special call parking help.
int ast_pickup_call (struct ast_channel *chan)
 Pickup a call.
char * ast_pickup_ext (void)
 Determine system call pickup extension.
void ast_register_feature (struct ast_call_feature *feature)
 register new feature into feature_set
void ast_unregister_feature (struct ast_call_feature *feature)
 unregister feature from feature_set


Detailed Description

Call Parking and Pickup API Includes code and algorithms from the Zapata library.

Definition in file features.h.


Define Documentation

#define FEATURE_APP_ARGS_LEN   256

Definition at line 31 of file features.h.

Referenced by load_config().

#define FEATURE_APP_LEN   64

Definition at line 30 of file features.h.

Referenced by load_config().

#define FEATURE_EXTEN_LEN   32

Definition at line 33 of file features.h.

Referenced by load_config().

#define FEATURE_MAX_LEN   11

Definition at line 29 of file features.h.

Referenced by ast_bridge_call().

#define FEATURE_MOH_LEN   80

Definition at line 34 of file features.h.

Referenced by load_config().

#define FEATURE_SNAME_LEN   32

Definition at line 32 of file features.h.

Referenced by load_config().

#define PARK_APP_NAME   "Park"

Definition at line 36 of file features.h.

Referenced by handle_exec().


Function Documentation

int ast_bridge_call ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config 
)

Bridge a call, optionally allowing redirection.

append the event to featurecode. we rely on the string being zero-filled, and not overflowing it.

Todo:
XXX how do we guarantee the latter ?

Definition at line 1466 of file res_features.c.

References ast_channel::_state, ast_channel::accountcode, ast_cdr::accountcode, ast_channel::amaflags, ast_cdr::amaflags, ast_cdr::answer, ast_channel::appl, ast_answer(), ast_bridged_channel(), ast_cdr_alloc(), ast_cdr_answer(), AST_CDR_ANSWERED, ast_cdr_detach(), ast_cdr_dup(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_MAIN, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, ast_cdr_setcid(), ast_cdr_specialized_reset(), ast_cdr_start(), ast_cdr_update(), ast_channel_bridge(), ast_channel_lock, ast_channel_setoption(), ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OPTION, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_copy_string(), ast_default_amaflags, ast_dtmf_stream(), ast_exists_extension(), ast_feature_interpret(), AST_FEATURE_NO_H_EXTEN, AST_FEATURE_PLAY_WARNING, AST_FLAG_BRIDGE_HANGUP_RUN, AST_FLAG_IN_AUTOLOOP, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, ast_frfree, ast_get_channel_by_name_locked(), ast_indicate(), ast_indicate_data(), ast_log(), AST_MAX_EXTENSION, ast_opt_end_cdr_before_h_exten, AST_OPTION_FLAG_REQUEST, AST_PBX_KEEPALIVE, AST_PBX_NO_HANGUP_PEER_PARKED, ast_set2_flag, ast_set_flag, ast_spawn_extension(), AST_STATE_RINGING, AST_STATE_UP, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_verbose(), ast_channel::cdr, ast_cdr::channel, ast_channel::cid, ast_callerid::cid_num, ast_channel::context, ast_option_header::data, ast_frame::data, ast_channel::data, ast_frame::datalen, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_bridge_config::end_bridge_callback, ast_bridge_config::end_bridge_callback_data, ast_bridge_config::end_sound, ast_channel::exten, f, FEATURE_MAX_LEN, FEATURE_RETURN_PASSDIGITS, FEATURE_RETURN_SUCCESS, FEATURE_SENSE_CHAN, FEATURE_SENSE_PEER, ast_bridge_config::feature_timer, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::firstpass, ast_option_header::flag, ast_frame::frametype, ast_cdr::lastapp, ast_cdr::lastdata, LOG_DEBUG, LOG_WARNING, ast_channel::name, ast_cdr::next, ast_option_header::option, option_debug, option_verbose, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), pick_unlocked_cdr(), ast_bridge_config::play_warning, ast_channel::priority, set_config_flags(), ast_cdr::start, ast_bridge_config::start_sound, ast_bridge_config::start_time, ast_frame::subclass, ast_channel::uniqueid, ast_cdr::uniqueid, ast_cdr::userfield, VERBOSE_PREFIX_2, ast_channel::visible_indication, ast_bridge_config::warning_freq, and ast_bridge_config::warning_sound.

Referenced by app_exec(), ast_bridge_call_thread(), bridge_exec(), builtin_atxfer(), park_exec(), and try_calling().

01467 {
01468    /* Copy voice back and forth between the two channels.  Give the peer
01469       the ability to transfer calls with '#<extension' syntax. */
01470    struct ast_frame *f;
01471    struct ast_channel *who;
01472    char chan_featurecode[FEATURE_MAX_LEN + 1]="";
01473    char peer_featurecode[FEATURE_MAX_LEN + 1]="";
01474    char orig_channame[AST_MAX_EXTENSION];
01475    char orig_peername[AST_MAX_EXTENSION];
01476 
01477    int res;
01478    int diff;
01479    int hasfeatures=0;
01480    int hadfeatures=0;
01481    int autoloopflag;
01482    struct ast_option_header *aoh;
01483    struct ast_bridge_config backup_config;
01484    struct ast_cdr *bridge_cdr = NULL;
01485    struct ast_cdr *orig_peer_cdr = NULL;
01486    struct ast_cdr *chan_cdr = pick_unlocked_cdr(chan->cdr); /* the proper chan cdr, if there are forked cdrs */
01487    struct ast_cdr *peer_cdr = pick_unlocked_cdr(peer->cdr); /* the proper chan cdr, if there are forked cdrs */
01488    struct ast_cdr *new_chan_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
01489    struct ast_cdr *new_peer_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
01490 
01491    memset(&backup_config, 0, sizeof(backup_config));
01492 
01493    config->start_time = ast_tvnow();
01494 
01495    if (chan && peer) {
01496       pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
01497       pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
01498    } else if (chan) {
01499       pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
01500    }
01501 
01502    /* This is an interesting case.  One example is if a ringing channel gets redirected to
01503     * an extension that picks up a parked call.  This will make sure that the call taken
01504     * out of parking gets told that the channel it just got bridged to is still ringing. */
01505    if (chan->_state == AST_STATE_RINGING && peer->visible_indication != AST_CONTROL_RINGING) {
01506       ast_indicate(peer, AST_CONTROL_RINGING);
01507    }
01508 
01509    if (monitor_ok) {
01510       const char *monitor_exec;
01511       struct ast_channel *src = NULL;
01512       if (!monitor_app) { 
01513          if (!(monitor_app = pbx_findapp("Monitor")))
01514             monitor_ok=0;
01515       }
01516       if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) 
01517          src = chan;
01518       else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
01519          src = peer;
01520       if (monitor_app && src) {
01521          char *tmp = ast_strdupa(monitor_exec);
01522          pbx_exec(src, monitor_app, tmp);
01523       }
01524    }
01525    
01526    set_config_flags(chan, peer, config);
01527    config->firstpass = 1;
01528 
01529    /* Answer if need be */
01530    if (ast_answer(chan))
01531       return -1;
01532 
01533    ast_copy_string(orig_channame,chan->name,sizeof(orig_channame));
01534    ast_copy_string(orig_peername,peer->name,sizeof(orig_peername));
01535    orig_peer_cdr = peer_cdr;
01536    
01537    if (!chan_cdr || (chan_cdr && !ast_test_flag(chan_cdr, AST_CDR_FLAG_POST_DISABLED))) {
01538          
01539       if (chan_cdr) {
01540          ast_set_flag(chan_cdr, AST_CDR_FLAG_MAIN);
01541          ast_cdr_update(chan);
01542          bridge_cdr = ast_cdr_dup(chan_cdr);
01543          ast_copy_string(bridge_cdr->lastapp, chan->appl, sizeof(bridge_cdr->lastapp));
01544          ast_copy_string(bridge_cdr->lastdata, chan->data, sizeof(bridge_cdr->lastdata));
01545       } else {
01546          /* better yet, in a xfer situation, find out why the chan cdr got zapped (pun unintentional) */
01547          bridge_cdr = ast_cdr_alloc(); /* this should be really, really rare/impossible? */
01548          ast_copy_string(bridge_cdr->channel, chan->name, sizeof(bridge_cdr->channel));
01549          ast_copy_string(bridge_cdr->dstchannel, peer->name, sizeof(bridge_cdr->dstchannel));
01550          ast_copy_string(bridge_cdr->uniqueid, chan->uniqueid, sizeof(bridge_cdr->uniqueid));
01551          ast_copy_string(bridge_cdr->lastapp, chan->appl, sizeof(bridge_cdr->lastapp));
01552          ast_copy_string(bridge_cdr->lastdata, chan->data, sizeof(bridge_cdr->lastdata));
01553          ast_cdr_setcid(bridge_cdr, chan);
01554          bridge_cdr->disposition = (chan->_state == AST_STATE_UP) ?  AST_CDR_ANSWERED : AST_CDR_NULL;
01555          bridge_cdr->amaflags = chan->amaflags ? chan->amaflags :  ast_default_amaflags;
01556          ast_copy_string(bridge_cdr->accountcode, chan->accountcode, sizeof(bridge_cdr->accountcode));
01557          /* Destination information */
01558          ast_copy_string(bridge_cdr->dst, chan->exten, sizeof(bridge_cdr->dst));
01559          ast_copy_string(bridge_cdr->dcontext, chan->context, sizeof(bridge_cdr->dcontext));
01560          if (peer_cdr) {
01561             bridge_cdr->start = peer_cdr->start;
01562             ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
01563          } else {
01564             ast_cdr_start(bridge_cdr);
01565          }
01566       }
01567       /* peer_cdr->answer will be set when a macro runs on the peer;
01568          in that case, the bridge answer will be delayed while the
01569          macro plays on the peer channel. The peer answered the call
01570          before the macro started playing. To the phone system,
01571          this is billable time for the call, even tho the caller
01572          hears nothing but ringing while the macro does its thing. */
01573       if (peer_cdr && !ast_tvzero(peer_cdr->answer)) {
01574          bridge_cdr->answer = peer_cdr->answer;
01575          chan_cdr->answer = peer_cdr->answer;
01576          bridge_cdr->disposition = peer_cdr->disposition;
01577          chan_cdr->disposition = peer_cdr->disposition;
01578       } else {
01579          ast_cdr_answer(bridge_cdr);
01580          ast_cdr_answer(chan_cdr); /* for the sake of cli status checks */
01581       }
01582       ast_set_flag(chan_cdr, AST_CDR_FLAG_BRIDGED);
01583       if (peer_cdr) {
01584          ast_set_flag(peer_cdr, AST_CDR_FLAG_BRIDGED);
01585       }
01586    }
01587    
01588    for (;;) {
01589       struct ast_channel *other; /* used later */
01590       
01591       res = ast_channel_bridge(chan, peer, config, &f, &who);
01592       
01593       if (config->feature_timer) {
01594          /* Update time limit for next pass */
01595          diff = ast_tvdiff_ms(ast_tvnow(), config->start_time);
01596          config->feature_timer -= diff;
01597          if (hasfeatures) {
01598             /* Running on backup config, meaning a feature might be being
01599                activated, but that's no excuse to keep things going 
01600                indefinitely! */
01601             if (backup_config.feature_timer && ((backup_config.feature_timer -= diff) <= 0)) {
01602                if (option_debug)
01603                   ast_log(LOG_DEBUG, "Timed out, realtime this time!\n");
01604                config->feature_timer = 0;
01605                who = chan;
01606                if (f)
01607                   ast_frfree(f);
01608                f = NULL;
01609                res = 0;
01610             } else if (config->feature_timer <= 0) {
01611                /* Not *really* out of time, just out of time for
01612                   digits to come in for features. */
01613                if (option_debug)
01614                   ast_log(LOG_DEBUG, "Timed out for feature!\n");
01615                if (!ast_strlen_zero(peer_featurecode)) {
01616                   ast_dtmf_stream(chan, peer, peer_featurecode, 0);
01617                   memset(peer_featurecode, 0, sizeof(peer_featurecode));
01618                }
01619                if (!ast_strlen_zero(chan_featurecode)) {
01620                   ast_dtmf_stream(peer, chan, chan_featurecode, 0);
01621                   memset(chan_featurecode, 0, sizeof(chan_featurecode));
01622                }
01623                if (f)
01624                   ast_frfree(f);
01625                hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
01626                if (!hasfeatures) {
01627                   /* Restore original (possibly time modified) bridge config */
01628                   memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
01629                   memset(&backup_config, 0, sizeof(backup_config));
01630                }
01631                hadfeatures = hasfeatures;
01632                /* Continue as we were */
01633                continue;
01634             } else if (!f) {
01635                /* The bridge returned without a frame and there is a feature in progress.
01636                 * However, we don't think the feature has quite yet timed out, so just
01637                 * go back into the bridge. */
01638                continue;
01639             }
01640          } else {
01641             if (config->feature_timer <=0) {
01642                /* We ran out of time */
01643                config->feature_timer = 0;
01644                who = chan;
01645                if (f)
01646                   ast_frfree(f);
01647                f = NULL;
01648                res = 0;
01649             }
01650          }
01651       }
01652       if (res < 0) {
01653          if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_test_flag(peer, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan) && !ast_check_hangup(peer))
01654             ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name);
01655          goto before_you_go;
01656       }
01657       
01658       if (!f || (f->frametype == AST_FRAME_CONTROL &&
01659             (f->subclass == AST_CONTROL_HANGUP || f->subclass == AST_CONTROL_BUSY || 
01660                f->subclass == AST_CONTROL_CONGESTION))) {
01661          res = -1;
01662          break;
01663       }
01664       /* many things should be sent to the 'other' channel */
01665       other = (who == chan) ? peer : chan;
01666       if (f->frametype == AST_FRAME_CONTROL) {
01667          switch (f->subclass) {
01668          case AST_CONTROL_RINGING:
01669          case AST_CONTROL_FLASH:
01670          case -1:
01671             ast_indicate(other, f->subclass);
01672             break;
01673          case AST_CONTROL_HOLD:
01674          case AST_CONTROL_UNHOLD:
01675             ast_indicate_data(other, f->subclass, f->data, f->datalen);
01676             break;
01677          case AST_CONTROL_OPTION:
01678             aoh = f->data;
01679             /* Forward option Requests */
01680             if (aoh && aoh->flag == AST_OPTION_FLAG_REQUEST) {
01681                ast_channel_setoption(other, ntohs(aoh->option), aoh->data, 
01682                   f->datalen - sizeof(struct ast_option_header), 0);
01683             }
01684             break;
01685          }
01686       } else if (f->frametype == AST_FRAME_DTMF_BEGIN) {
01687          /* eat it */
01688       } else if (f->frametype == AST_FRAME_DTMF) {
01689          char *featurecode;
01690          int sense;
01691 
01692          hadfeatures = hasfeatures;
01693          /* This cannot overrun because the longest feature is one shorter than our buffer */
01694          if (who == chan) {
01695             sense = FEATURE_SENSE_CHAN;
01696             featurecode = chan_featurecode;
01697          } else  {
01698             sense = FEATURE_SENSE_PEER;
01699             featurecode = peer_featurecode;
01700          }
01701          /*! append the event to featurecode. we rely on the string being zero-filled, and
01702           * not overflowing it. 
01703           * \todo XXX how do we guarantee the latter ?
01704           */
01705          featurecode[strlen(featurecode)] = f->subclass;
01706          /* Get rid of the frame before we start doing "stuff" with the channels */
01707          ast_frfree(f);
01708          f = NULL;
01709          config->feature_timer = backup_config.feature_timer;
01710          res = ast_feature_interpret(chan, peer, config, featurecode, sense);
01711          switch(res) {
01712          case FEATURE_RETURN_PASSDIGITS:
01713             ast_dtmf_stream(other, who, featurecode, 0);
01714             /* Fall through */
01715          case FEATURE_RETURN_SUCCESS:
01716             memset(featurecode, 0, sizeof(chan_featurecode));
01717             break;
01718          }
01719          if (res >= FEATURE_RETURN_PASSDIGITS) {
01720             res = 0;
01721          } else 
01722             break;
01723          hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
01724          if (hadfeatures && !hasfeatures) {
01725             /* Restore backup */
01726             memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
01727             memset(&backup_config, 0, sizeof(struct ast_bridge_config));
01728          } else if (hasfeatures) {
01729             if (!hadfeatures) {
01730                /* Backup configuration */
01731                memcpy(&backup_config, config, sizeof(struct ast_bridge_config));
01732                /* Setup temporary config options */
01733                config->play_warning = 0;
01734                ast_clear_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING);
01735                ast_clear_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING);
01736                config->warning_freq = 0;
01737                config->warning_sound = NULL;
01738                config->end_sound = NULL;
01739                config->start_sound = NULL;
01740                config->firstpass = 0;
01741             }
01742             config->start_time = ast_tvnow();
01743             config->feature_timer = featuredigittimeout;
01744             if (option_debug)
01745                ast_log(LOG_DEBUG, "Set time limit to %ld\n", config->feature_timer);
01746          }
01747       }
01748       if (f)
01749          ast_frfree(f);
01750 
01751    }
01752   before_you_go:
01753    if (res != AST_PBX_KEEPALIVE && config->end_bridge_callback) {
01754       config->end_bridge_callback(config->end_bridge_callback_data);
01755    }
01756 
01757    autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
01758    ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
01759    if (res != AST_PBX_KEEPALIVE && !ast_test_flag(&(config->features_caller),AST_FEATURE_NO_H_EXTEN) && ast_exists_extension(chan, chan->context, "h", 1, chan->cid.cid_num)) {
01760       struct ast_cdr *swapper = NULL;
01761       char savelastapp[AST_MAX_EXTENSION];
01762       char savelastdata[AST_MAX_EXTENSION];
01763       char save_exten[AST_MAX_EXTENSION];
01764       int  save_prio;
01765       
01766       if (bridge_cdr && ast_opt_end_cdr_before_h_exten) {
01767          ast_cdr_end(bridge_cdr);
01768       }
01769       /* swap the bridge cdr and the chan cdr for a moment, and let the endbridge
01770          dialplan code operate on it */
01771       ast_channel_lock(chan);
01772       if (bridge_cdr) {
01773          swapper = chan->cdr;
01774          ast_copy_string(savelastapp, bridge_cdr->lastapp, sizeof(bridge_cdr->lastapp));
01775          ast_copy_string(savelastdata, bridge_cdr->lastdata, sizeof(bridge_cdr->lastdata));
01776          chan->cdr = bridge_cdr;
01777       }
01778       ast_copy_string(save_exten, chan->exten, sizeof(save_exten));
01779       ast_copy_string(chan->exten, "h", sizeof(chan->exten));
01780       save_prio = chan->priority;
01781       chan->priority = 1;
01782       ast_channel_unlock(chan);
01783       while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
01784          if (ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
01785             /* Something bad happened, or a hangup has been requested. */
01786             if (option_debug)
01787                ast_log(LOG_DEBUG, "Spawn h extension (%s,%s,%d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
01788             if (option_verbose > 1)
01789                ast_verbose( VERBOSE_PREFIX_2 "Spawn h extension (%s, %s, %d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
01790             break;
01791          }
01792          chan->priority++;
01793       }
01794       /* swap it back */
01795       ast_channel_lock(chan);
01796       ast_copy_string(chan->exten, save_exten, sizeof(chan->exten));
01797       chan->priority = save_prio;
01798       if (bridge_cdr)
01799          chan->cdr = swapper;
01800       ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_RUN);
01801       ast_channel_unlock(chan);
01802       /* protect the lastapp/lastdata against the effects of the hangup/dialplan code */
01803       if (bridge_cdr) {
01804          ast_copy_string(bridge_cdr->lastapp, savelastapp, sizeof(bridge_cdr->lastapp));
01805          ast_copy_string(bridge_cdr->lastdata, savelastdata, sizeof(bridge_cdr->lastdata));
01806       }
01807    }
01808    ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
01809 
01810    /* obey the NoCDR() wishes. -- move the DISABLED flag to the bridge CDR if it was set on the channel during the bridge... */
01811    if (res != AST_PBX_KEEPALIVE) {
01812       new_chan_cdr = pick_unlocked_cdr(chan->cdr); /* the proper chan cdr, if there are forked cdrs */
01813       if (bridge_cdr && new_chan_cdr && ast_test_flag(new_chan_cdr, AST_CDR_FLAG_POST_DISABLED))
01814          ast_set_flag(bridge_cdr, AST_CDR_FLAG_POST_DISABLED);
01815    }
01816 
01817    /* we can post the bridge CDR at this point */
01818    if (bridge_cdr) {
01819       ast_cdr_end(bridge_cdr);
01820       ast_cdr_detach(bridge_cdr);
01821    }
01822    
01823    /* do a specialized reset on the beginning channel
01824       CDR's, if they still exist, so as not to mess up
01825       issues in future bridges;
01826       
01827       Here are the rules of the game:
01828       1. The chan and peer channel pointers will not change
01829          during the life of the bridge.
01830       2. But, in transfers, the channel names will change.
01831          between the time the bridge is started, and the
01832          time the channel ends. 
01833          Usually, when a channel changes names, it will
01834          also change CDR pointers.
01835       3. Usually, only one of the two channels (chan or peer)
01836          will change names.
01837       4. Usually, if a channel changes names during a bridge,
01838          it is because of a transfer. Usually, in these situations,
01839          it is normal to see 2 bridges running simultaneously, and
01840          it is not unusual to see the two channels that change
01841          swapped between bridges.
01842       5. After a bridge occurs, we have 2 or 3 channels' CDRs
01843          to attend to; if the chan or peer changed names,
01844          we have the before and after attached CDR's.
01845       6. Parking has to be accounted for in the code:
01846          a. Parking will cause ast_bridge_call to return
01847             either AST_PBX_NO_HANGUP_PEER or AST_PBX_NO_HANGUP_PEER_PARKED;
01848           in the latter case, peer is (most likely) a bad
01849           pointer, you can no longer deref it. If it does still
01850           exist, it is under another's thread control, and
01851           could be destroyed at any time.
01852           b. The same applies to AST_PBX_KEEPALIVE, in which
01853            case, the chan ptr cannot be used, as another thread
01854           owns it and may have destroyed the channel.
01855          c. In the former case, you need to check peer to see if it 
01856             still exists before you deref it, and obtain a lock.
01857          d. In neither case should you do an ast_hangup(peer).
01858         e. Do not overwrite the result code from ast_bridge_call.
01859    */
01860    
01861    if (res != AST_PBX_KEEPALIVE && new_chan_cdr) {
01862       struct ast_channel *chan_ptr = NULL;
01863       
01864       if (strcasecmp(orig_channame, chan->name) != 0) { 
01865          /* old channel */
01866          chan_ptr = ast_get_channel_by_name_locked(orig_channame);
01867          if (chan_ptr) {
01868             if (!ast_bridged_channel(chan_ptr)) {
01869                struct ast_cdr *cur;
01870                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
01871                   if (cur == chan_cdr) {
01872                      break;
01873                   }
01874                }
01875                if (cur)
01876                   ast_cdr_specialized_reset(chan_cdr,0);
01877             }
01878             ast_channel_unlock(chan_ptr);
01879          }
01880          /* new channel */
01881          ast_cdr_specialized_reset(new_chan_cdr,0);
01882       } else {
01883          ast_cdr_specialized_reset(chan_cdr,0); /* nothing changed, reset the chan_cdr  */
01884       }
01885    }
01886 
01887    if (res != AST_PBX_NO_HANGUP_PEER_PARKED) { /* if the peer was involved in a park, don't even touch it; it's probably gone */
01888       struct ast_channel *chan_ptr = NULL;
01889       new_peer_cdr = pick_unlocked_cdr(peer->cdr); /* the proper chan cdr, if there are forked cdrs */
01890       if (new_chan_cdr && ast_test_flag(new_chan_cdr, AST_CDR_FLAG_POST_DISABLED) && new_peer_cdr && !ast_test_flag(new_peer_cdr, AST_CDR_FLAG_POST_DISABLED))
01891          ast_set_flag(new_peer_cdr, AST_CDR_FLAG_POST_DISABLED); /* DISABLED is viral-- it will propagate across a bridge */
01892       if (strcasecmp(orig_peername, peer->name) != 0) { 
01893          /* old channel */
01894          chan_ptr = ast_get_channel_by_name_locked(orig_peername);
01895          if (chan_ptr) {
01896             if (!ast_bridged_channel(chan_ptr)) {
01897                struct ast_cdr *cur;
01898                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
01899                   if (cur == peer_cdr) {
01900                      break;
01901                   }
01902                }
01903                if (cur)
01904                   ast_cdr_specialized_reset(peer_cdr,0);
01905             }
01906             ast_channel_unlock(chan_ptr);
01907          }
01908          /* new channel */
01909          ast_cdr_specialized_reset(new_peer_cdr,0);
01910       } else {
01911          ast_cdr_specialized_reset(peer_cdr,0); /* nothing changed, reset the peer_cdr  */
01912       }
01913    }
01914    return res;
01915 }

int ast_masq_park_call ( struct ast_channel *  rchan,
struct ast_channel *  host,
int  timeout,
int *  extout 
)

Park a call via a masqueraded channel.

Parameters:
rchan the real channel to be parked
host the channel to have the parking read to Masquerade the channel rchan into a new, empty channel which is then parked with ast_park_call
timeout is a timeout in milliseconds
extout is a parameter to an int that will hold the parked location, or NULL if you want

Definition at line 550 of file res_features.c.

References masq_park_call().

Referenced by handle_exec(), manager_park(), mgcp_ss(), parkandannounce_exec(), rpt_exec(), and ss_thread().

00551 {
00552    return masq_park_call(rchan, peer, timeout, extout, 0);
00553 }

int ast_park_call ( struct ast_channel *  chan,
struct ast_channel *  peer,
int  timeout,
int *  extout 
)

Park a call and read back parked location.

Parameters:
chan the channel to actually be parked
host the channel which will have the parked location read to Park the channel chan, and read back the parked location to the host. If the call is not picked up within a specified period of time, then the call will return to the last step that it was in (in terms of exten, priority and context)
timeout is a timeout in milliseconds
extout is a parameter to an int that will hold the parked location, or NULL if you want
Park a call and read back parked location.

Note:
We put the user in the parking list, then wake up the parking thread to be sure it looks after these channels too

Definition at line 505 of file res_features.c.

References park_call_full().

Referenced by builtin_parkcall(), iax_park_thread(), and sip_park_thread().

00506 {
00507    return park_call_full(chan, peer, timeout, extout, NULL);
00508 }

char* ast_parking_ext ( void   ) 

Determine system parking extension Returns the call parking extension for drivers that provide special call parking help.

Definition at line 162 of file res_features.c.

Referenced by builtin_blindtransfer(), dp_lookup(), handle_request_refer(), load_config(), mgcp_ss(), socket_process(), and ss_thread().

00163 {
00164    return parking_ext;
00165 }

int ast_pickup_call ( struct ast_channel *  chan  ) 

Pickup a call.

Definition at line 2610 of file res_features.c.

References ast_channel::_state, ast_answer(), ast_channel_masquerade(), ast_channel_unlock, ast_channel_walk_locked(), AST_CONTROL_ANSWER, ast_log(), ast_queue_control(), AST_STATE_RING, AST_STATE_RINGING, ast_channel::callgroup, LOG_DEBUG, LOG_WARNING, ast_channel::name, option_debug, ast_channel::pbx, and ast_channel::pickupgroup.

Referenced by cb_events(), handle_request_invite(), mgcp_ss(), and ss_thread().

02611 {
02612    struct ast_channel *cur = NULL;
02613    int res = -1;
02614 
02615    while ((cur = ast_channel_walk_locked(cur)) != NULL) {
02616       if (!cur->pbx && 
02617          (cur != chan) &&
02618          (chan->pickupgroup & cur->callgroup) &&
02619          ((cur->_state == AST_STATE_RINGING) ||
02620           (cur->_state == AST_STATE_RING))) {
02621             break;
02622       }
02623       ast_channel_unlock(cur);
02624    }
02625    if (cur) {
02626       if (option_debug)
02627          ast_log(LOG_DEBUG, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
02628       res = ast_answer(chan);
02629       if (res)
02630          ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
02631       res = ast_queue_control(chan, AST_CONTROL_ANSWER);
02632       if (res)
02633          ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
02634       res = ast_channel_masquerade(cur, chan);
02635       if (res)
02636          ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name);     /* Done */
02637       ast_channel_unlock(cur);
02638    } else   {
02639       if (option_debug)
02640          ast_log(LOG_DEBUG, "No call pickup possible...\n");
02641    }
02642    return res;
02643 }

char* ast_pickup_ext ( void   ) 

Determine system call pickup extension.

Definition at line 167 of file res_features.c.

Referenced by cb_events(), get_destination(), handle_request_invite(), handle_showfeatures(), mgcp_ss(), and ss_thread().

00168 {
00169    return pickup_ext;
00170 }

void ast_register_feature ( struct ast_call_feature *  feature  ) 

register new feature into feature_set

Parameters:
feature an ast_call_feature object which contains a keysequence and a callback function which is called when this keysequence is pressed during a call.

Definition at line 1035 of file res_features.c.

References ast_log(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verbose(), ast_call_feature::feature_entry, LOG_NOTICE, option_verbose, ast_call_feature::sname, and VERBOSE_PREFIX_2.

Referenced by load_config().

01036 {
01037    if (!feature) {
01038       ast_log(LOG_NOTICE,"You didn't pass a feature!\n");
01039          return;
01040    }
01041   
01042    AST_RWLIST_WRLOCK(&feature_list);
01043    AST_RWLIST_INSERT_HEAD(&feature_list, feature, feature_entry);
01044    AST_RWLIST_UNLOCK(&feature_list);
01045 
01046    if (option_verbose >= 2) {
01047       ast_verbose(VERBOSE_PREFIX_2 "Registered Feature '%s'\n",feature->sname);
01048    }
01049 }

void ast_unregister_feature ( struct ast_call_feature *  feature  ) 

unregister feature from feature_set

Parameters:
feature the ast_call_feature object which was registered before

Definition at line 1052 of file res_features.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_call_feature::feature_entry, and free.

01053 {
01054    if (!feature)
01055       return;
01056 
01057    AST_RWLIST_WRLOCK(&feature_list);
01058    AST_RWLIST_REMOVE(&feature_list, feature, feature_entry);
01059    AST_RWLIST_UNLOCK(&feature_list);
01060    
01061    free(feature);
01062 }


Generated on Fri Jul 3 20:37:53 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9