Wed Aug 11 01:08:11 2010

Asterisk developer's documentation


features.h File Reference

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

#include "asterisk/pbx.h"
#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

Defines

#define AST_FEATURE_RETURN_HANGUP   -1
#define AST_FEATURE_RETURN_KEEPTRYING   24
#define AST_FEATURE_RETURN_PARKFAILED   25
#define AST_FEATURE_RETURN_PASSDIGITS   21
#define AST_FEATURE_RETURN_STOREDIGITS   22
#define AST_FEATURE_RETURN_SUCCESS   23
#define AST_FEATURE_RETURN_SUCCESSBREAK   0
#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"

Enumerations

enum  {
  AST_FEATURE_FLAG_NEEDSDTMF = (1 << 0), AST_FEATURE_FLAG_ONPEER = (1 << 1), AST_FEATURE_FLAG_ONSELF = (1 << 2), AST_FEATURE_FLAG_BYCALLEE = (1 << 3),
  AST_FEATURE_FLAG_BYCALLER = (1 << 4), AST_FEATURE_FLAG_BYBOTH = (3 << 3)
}
 main call feature structure More...

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_features_reload (void)
 Reload call features from features.conf.
struct ast_call_feature * ast_find_call_feature (const char *name)
 look for a call feature entry by its sname
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.
const char * ast_parking_ext (void)
 Determine system parking extension.
int ast_pickup_call (struct ast_channel *chan)
 Pickup a call.
const char * ast_pickup_ext (void)
 Determine system call pickup extension.
void ast_rdlock_call_features (void)
void ast_register_feature (struct ast_call_feature *feature)
 register new feature into feature_set
void ast_unlock_call_features (void)
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 AST_FEATURE_RETURN_HANGUP   -1

Definition at line 64 of file features.h.

Referenced by builtin_disconnect().

#define AST_FEATURE_RETURN_KEEPTRYING   24

Definition at line 69 of file features.h.

Referenced by feature_exec_app(), and feature_interpret().

#define AST_FEATURE_RETURN_PARKFAILED   25

Definition at line 70 of file features.h.

Referenced by builtin_blindtransfer(), and masq_park_call().

#define AST_FEATURE_RETURN_PASSDIGITS   21

Definition at line 66 of file features.h.

Referenced by ast_bridge_call(), and feature_interpret().

#define AST_FEATURE_RETURN_STOREDIGITS   22

Definition at line 67 of file features.h.

Referenced by feature_interpret().

#define AST_FEATURE_RETURN_SUCCESS   23

#define AST_FEATURE_RETURN_SUCCESSBREAK   0

Definition at line 65 of file features.h.

Referenced by feature_exec_app().

#define FEATURE_APP_ARGS_LEN   256

Definition at line 32 of file features.h.

Referenced by load_config().

#define FEATURE_APP_LEN   64

Definition at line 31 of file features.h.

Referenced by load_config().

#define FEATURE_EXTEN_LEN   32

Definition at line 34 of file features.h.

Referenced by load_config().

#define FEATURE_MAX_LEN   11

Definition at line 30 of file features.h.

Referenced by ast_bridge_call().

#define FEATURE_MOH_LEN   80

Definition at line 35 of file features.h.

Referenced by load_config().

#define FEATURE_SNAME_LEN   32

Definition at line 33 of file features.h.

Referenced by load_config().

#define PARK_APP_NAME   "Park"

Definition at line 37 of file features.h.

Referenced by handle_exec().


Enumeration Type Documentation

anonymous enum

main call feature structure

Enumerator:
AST_FEATURE_FLAG_NEEDSDTMF 
AST_FEATURE_FLAG_ONPEER 
AST_FEATURE_FLAG_ONSELF 
AST_FEATURE_FLAG_BYCALLEE 
AST_FEATURE_FLAG_BYCALLER 
AST_FEATURE_FLAG_BYBOTH 

Definition at line 41 of file features.h.

00041      {
00042    AST_FEATURE_FLAG_NEEDSDTMF = (1 << 0),
00043    AST_FEATURE_FLAG_ONPEER =    (1 << 1),
00044    AST_FEATURE_FLAG_ONSELF =    (1 << 2),
00045    AST_FEATURE_FLAG_BYCALLEE =  (1 << 3),
00046    AST_FEATURE_FLAG_BYCALLER =  (1 << 4),
00047    AST_FEATURE_FLAG_BYBOTH  =   (3 << 3),
00048 };


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.

Bridge a call, optionally allowing redirection.

Parameters:
chan,peer,config Set start time, check for two channels,check if monitor on check for feature activation, create new CDR
Return values:
res on success.
-1 on failure to bridge.

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 2494 of file features.c.

References ast_channel::_state, ast_cdr::accountcode, ast_channel::accountcode, add_features_datastores(), ast_channel::amaflags, ast_cdr::amaflags, ast_cdr::answer, ast_channel::appl, AST_BRIDGE_RETRY, ast_bridged_channel(), ast_cdr_alloc(), ast_cdr_answer(), AST_CDR_ANSWERED, ast_cdr_detach(), ast_cdr_discard(), ast_cdr_dup(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_DIALED, AST_CDR_FLAG_MAIN, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, ast_cdr_setaccount(), ast_cdr_setanswer(), ast_cdr_setcid(), ast_cdr_setdisposition(), 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_debug, ast_default_amaflags, ast_dtmf_stream(), ast_exists_extension(), AST_FEATURE_NO_H_EXTEN, AST_FEATURE_PLAY_WARNING, AST_FEATURE_RETURN_PASSDIGITS, AST_FEATURE_RETURN_SUCCESS, AST_FLAG_BRIDGE_HANGUP_DONT, AST_FLAG_BRIDGE_HANGUP_RUN, AST_FLAG_IN_AUTOLOOP, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frfree, ast_get_channel_by_name_locked(), ast_indicate(), ast_indicate_data(), ast_log(), ast_opt_end_cdr_before_h_exten, AST_OPTION_FLAG_REQUEST, ast_raw_answer(), ast_set2_flag, ast_set_flag, ast_spawn_extension(), AST_STATE_RINGING, AST_STATE_UP, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_tvcmp(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_verb, 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_interpret(), FEATURE_MAX_LEN, FEATURE_SENSE_CHAN, FEATURE_SENSE_PEER, ast_bridge_config::feature_timer, featuredigittimeout, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::firstpass, ast_frame::frametype, ast_cdr::lastapp, ast_cdr::lastdata, LOG_WARNING, monitor_app, monitor_ok, ast_channel::name, ast_cdr::next, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), pick_unlocked_cdr(), ast_bridge_config::play_warning, ast_channel::priority, ast_frame::ptr, S_OR, set_bridge_features_on_config(), 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, ast_channel::visible_indication, ast_bridge_config::warning_freq, and ast_bridge_config::warning_sound.

Referenced by app_exec(), bridge_call_thread(), bridge_exec(), builtin_atxfer(), dial_exec_full(), park_exec_full(), and try_calling().

02495 {
02496    /* Copy voice back and forth between the two channels.  Give the peer
02497       the ability to transfer calls with '#<extension' syntax. */
02498    struct ast_frame *f;
02499    struct ast_channel *who;
02500    char chan_featurecode[FEATURE_MAX_LEN + 1]="";
02501    char peer_featurecode[FEATURE_MAX_LEN + 1]="";
02502    char orig_channame[AST_MAX_EXTENSION];
02503    char orig_peername[AST_MAX_EXTENSION];
02504    int res;
02505    int diff;
02506    int hasfeatures=0;
02507    int hadfeatures=0;
02508    int autoloopflag;
02509    struct ast_option_header *aoh;
02510    struct ast_bridge_config backup_config;
02511    struct ast_cdr *bridge_cdr = NULL;
02512    struct ast_cdr *orig_peer_cdr = NULL;
02513    struct ast_cdr *chan_cdr = chan->cdr; /* the proper chan cdr, if there are forked cdrs */
02514    struct ast_cdr *peer_cdr = peer->cdr; /* the proper chan cdr, if there are forked cdrs */
02515    struct ast_cdr *new_chan_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
02516    struct ast_cdr *new_peer_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
02517 
02518    memset(&backup_config, 0, sizeof(backup_config));
02519 
02520    config->start_time = ast_tvnow();
02521 
02522    if (chan && peer) {
02523       pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
02524       pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
02525    } else if (chan) {
02526       pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
02527    }
02528 
02529    set_bridge_features_on_config(config, pbx_builtin_getvar_helper(chan, "BRIDGE_FEATURES"));
02530    add_features_datastores(chan, peer, config);
02531 
02532    /* This is an interesting case.  One example is if a ringing channel gets redirected to
02533     * an extension that picks up a parked call.  This will make sure that the call taken
02534     * out of parking gets told that the channel it just got bridged to is still ringing. */
02535    if (chan->_state == AST_STATE_RINGING && peer->visible_indication != AST_CONTROL_RINGING) {
02536       ast_indicate(peer, AST_CONTROL_RINGING);
02537    }
02538 
02539    if (monitor_ok) {
02540       const char *monitor_exec;
02541       struct ast_channel *src = NULL;
02542       if (!monitor_app) { 
02543          if (!(monitor_app = pbx_findapp("Monitor")))
02544             monitor_ok=0;
02545       }
02546       if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) 
02547          src = chan;
02548       else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
02549          src = peer;
02550       if (monitor_app && src) {
02551          char *tmp = ast_strdupa(monitor_exec);
02552          pbx_exec(src, monitor_app, tmp);
02553       }
02554    }
02555 
02556    set_config_flags(chan, peer, config);
02557    config->firstpass = 1;
02558 
02559    /* Answer if need be */
02560    if (chan->_state != AST_STATE_UP) {
02561       if (ast_raw_answer(chan, 1)) {
02562          return -1;
02563       }
02564    }
02565 
02566    ast_copy_string(orig_channame,chan->name,sizeof(orig_channame));
02567    ast_copy_string(orig_peername,peer->name,sizeof(orig_peername));
02568    orig_peer_cdr = peer_cdr;
02569    
02570    if (!chan_cdr || (chan_cdr && !ast_test_flag(chan_cdr, AST_CDR_FLAG_POST_DISABLED))) {
02571       
02572       if (chan_cdr) {
02573          ast_set_flag(chan_cdr, AST_CDR_FLAG_MAIN);
02574          ast_cdr_update(chan);
02575          bridge_cdr = ast_cdr_dup(chan_cdr);
02576          /* rip any forked CDR's off of the chan_cdr and attach
02577           * them to the bridge_cdr instead */
02578          bridge_cdr->next = chan_cdr->next;
02579          chan_cdr->next = NULL;
02580          ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
02581          ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
02582          if (peer_cdr && !ast_strlen_zero(peer_cdr->userfield)) {
02583             ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
02584          }
02585          ast_cdr_setaccount(peer, chan->accountcode);
02586 
02587       } else {
02588          /* better yet, in a xfer situation, find out why the chan cdr got zapped (pun unintentional) */
02589          bridge_cdr = ast_cdr_alloc(); /* this should be really, really rare/impossible? */
02590          ast_copy_string(bridge_cdr->channel, chan->name, sizeof(bridge_cdr->channel));
02591          ast_copy_string(bridge_cdr->dstchannel, peer->name, sizeof(bridge_cdr->dstchannel));
02592          ast_copy_string(bridge_cdr->uniqueid, chan->uniqueid, sizeof(bridge_cdr->uniqueid));
02593          ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
02594          ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
02595          ast_cdr_setcid(bridge_cdr, chan);
02596          bridge_cdr->disposition = (chan->_state == AST_STATE_UP) ?  AST_CDR_ANSWERED : AST_CDR_NULL;
02597          bridge_cdr->amaflags = chan->amaflags ? chan->amaflags :  ast_default_amaflags;
02598          ast_copy_string(bridge_cdr->accountcode, chan->accountcode, sizeof(bridge_cdr->accountcode));
02599          /* Destination information */
02600          ast_copy_string(bridge_cdr->dst, chan->exten, sizeof(bridge_cdr->dst));
02601          ast_copy_string(bridge_cdr->dcontext, chan->context, sizeof(bridge_cdr->dcontext));
02602          if (peer_cdr) {
02603             bridge_cdr->start = peer_cdr->start;
02604             ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
02605          } else {
02606             ast_cdr_start(bridge_cdr);
02607          }
02608       }
02609       ast_debug(4,"bridge answer set, chan answer set\n");
02610       /* peer_cdr->answer will be set when a macro runs on the peer;
02611          in that case, the bridge answer will be delayed while the
02612          macro plays on the peer channel. The peer answered the call
02613          before the macro started playing. To the phone system,
02614          this is billable time for the call, even tho the caller
02615          hears nothing but ringing while the macro does its thing. */
02616 
02617       /* Another case where the peer cdr's time will be set, is when
02618          A self-parks by pickup up phone and dialing 700, then B
02619          picks up A by dialing its parking slot; there may be more 
02620          practical paths that get the same result, tho... in which
02621          case you get the previous answer time from the Park... which
02622          is before the bridge's start time, so I added in the 
02623          tvcmp check to the if below */
02624 
02625       if (peer_cdr && !ast_tvzero(peer_cdr->answer) && ast_tvcmp(peer_cdr->answer, bridge_cdr->start) >= 0) {
02626          ast_cdr_setanswer(bridge_cdr, peer_cdr->answer);
02627          ast_cdr_setdisposition(bridge_cdr, peer_cdr->disposition);
02628          if (chan_cdr) {
02629             ast_cdr_setanswer(chan_cdr, peer_cdr->answer);
02630             ast_cdr_setdisposition(chan_cdr, peer_cdr->disposition);
02631          }
02632       } else {
02633          ast_cdr_answer(bridge_cdr);
02634          if (chan_cdr) {
02635             ast_cdr_answer(chan_cdr); /* for the sake of cli status checks */
02636          }
02637       }
02638       if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT) && (chan_cdr || peer_cdr)) {
02639          if (chan_cdr) {
02640             ast_set_flag(chan_cdr, AST_CDR_FLAG_BRIDGED);
02641          }
02642          if (peer_cdr) {
02643             ast_set_flag(peer_cdr, AST_CDR_FLAG_BRIDGED);
02644          }
02645       }
02646       /* the DIALED flag may be set if a dialed channel is transfered
02647        * and then bridged to another channel.  In order for the
02648        * bridge CDR to be written, the DIALED flag must not be
02649        * present. */
02650       ast_clear_flag(bridge_cdr, AST_CDR_FLAG_DIALED);
02651    }
02652    for (;;) {
02653       struct ast_channel *other; /* used later */
02654    
02655       res = ast_channel_bridge(chan, peer, config, &f, &who);
02656       
02657       /* When frame is not set, we are probably involved in a situation
02658          where we've timed out.
02659          When frame is set, we'll come this code twice; once for DTMF_BEGIN
02660          and also for DTMF_END. If we flow into the following 'if' for both, then 
02661          our wait times are cut in half, as both will subtract from the
02662          feature_timer. Not good!
02663       */
02664       if (config->feature_timer && (!f || f->frametype == AST_FRAME_DTMF_END)) {
02665          /* Update time limit for next pass */
02666          diff = ast_tvdiff_ms(ast_tvnow(), config->start_time);
02667          if (res == AST_BRIDGE_RETRY) {
02668             /* The feature fully timed out but has not been updated. Skip
02669              * the potential round error from the diff calculation and
02670              * explicitly set to expired. */
02671             config->feature_timer = -1;
02672          } else {
02673             config->feature_timer -= diff;
02674          }
02675 
02676          if (hasfeatures) {
02677             /* Running on backup config, meaning a feature might be being
02678                activated, but that's no excuse to keep things going 
02679                indefinitely! */
02680             if (backup_config.feature_timer && ((backup_config.feature_timer -= diff) <= 0)) {
02681                ast_debug(1, "Timed out, realtime this time!\n");
02682                config->feature_timer = 0;
02683                who = chan;
02684                if (f)
02685                   ast_frfree(f);
02686                f = NULL;
02687                res = 0;
02688             } else if (config->feature_timer <= 0) {
02689                /* Not *really* out of time, just out of time for
02690                   digits to come in for features. */
02691                ast_debug(1, "Timed out for feature!\n");
02692                if (!ast_strlen_zero(peer_featurecode)) {
02693                   ast_dtmf_stream(chan, peer, peer_featurecode, 0, 0);
02694                   memset(peer_featurecode, 0, sizeof(peer_featurecode));
02695                }
02696                if (!ast_strlen_zero(chan_featurecode)) {
02697                   ast_dtmf_stream(peer, chan, chan_featurecode, 0, 0);
02698                   memset(chan_featurecode, 0, sizeof(chan_featurecode));
02699                }
02700                if (f)
02701                   ast_frfree(f);
02702                hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
02703                if (!hasfeatures) {
02704                   /* Restore original (possibly time modified) bridge config */
02705                   memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
02706                   memset(&backup_config, 0, sizeof(backup_config));
02707                }
02708                hadfeatures = hasfeatures;
02709                /* Continue as we were */
02710                continue;
02711             } else if (!f) {
02712                /* The bridge returned without a frame and there is a feature in progress.
02713                 * However, we don't think the feature has quite yet timed out, so just
02714                 * go back into the bridge. */
02715                continue;
02716             }
02717          } else {
02718             if (config->feature_timer <=0) {
02719                /* We ran out of time */
02720                config->feature_timer = 0;
02721                who = chan;
02722                if (f)
02723                   ast_frfree(f);
02724                f = NULL;
02725                res = 0;
02726             }
02727          }
02728       }
02729       if (res < 0) {
02730          if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_test_flag(peer, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan) && !ast_check_hangup(peer))
02731             ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name);
02732          goto before_you_go;
02733       }
02734       
02735       if (!f || (f->frametype == AST_FRAME_CONTROL &&
02736             (f->subclass == AST_CONTROL_HANGUP || f->subclass == AST_CONTROL_BUSY || 
02737                f->subclass == AST_CONTROL_CONGESTION))) {
02738          res = -1;
02739          break;
02740       }
02741       /* many things should be sent to the 'other' channel */
02742       other = (who == chan) ? peer : chan;
02743       if (f->frametype == AST_FRAME_CONTROL) {
02744          switch (f->subclass) {
02745          case AST_CONTROL_RINGING:
02746          case AST_CONTROL_FLASH:
02747          case -1:
02748             ast_indicate(other, f->subclass);
02749             break;
02750          case AST_CONTROL_HOLD:
02751          case AST_CONTROL_UNHOLD:
02752             ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen);
02753             break;
02754          case AST_CONTROL_OPTION:
02755             aoh = f->data.ptr;
02756             /* Forward option Requests */
02757             if (aoh && aoh->flag == AST_OPTION_FLAG_REQUEST) {
02758                ast_channel_setoption(other, ntohs(aoh->option), aoh->data, 
02759                   f->datalen - sizeof(struct ast_option_header), 0);
02760             }
02761             break;
02762          }
02763       } else if (f->frametype == AST_FRAME_DTMF_BEGIN) {
02764          /* eat it */
02765       } else if (f->frametype == AST_FRAME_DTMF) {
02766          char *featurecode;
02767          int sense;
02768 
02769          hadfeatures = hasfeatures;
02770          /* This cannot overrun because the longest feature is one shorter than our buffer */
02771          if (who == chan) {
02772             sense = FEATURE_SENSE_CHAN;
02773             featurecode = chan_featurecode;
02774          } else  {
02775             sense = FEATURE_SENSE_PEER;
02776             featurecode = peer_featurecode;
02777          }
02778          /*! append the event to featurecode. we rely on the string being zero-filled, and
02779           * not overflowing it. 
02780           * \todo XXX how do we guarantee the latter ?
02781           */
02782          featurecode[strlen(featurecode)] = f->subclass;
02783          /* Get rid of the frame before we start doing "stuff" with the channels */
02784          ast_frfree(f);
02785          f = NULL;
02786          config->feature_timer = backup_config.feature_timer;
02787          res = feature_interpret(chan, peer, config, featurecode, sense);
02788          switch(res) {
02789          case AST_FEATURE_RETURN_PASSDIGITS:
02790             ast_dtmf_stream(other, who, featurecode, 0, 0);
02791             /* Fall through */
02792          case AST_FEATURE_RETURN_SUCCESS:
02793             memset(featurecode, 0, sizeof(chan_featurecode));
02794             break;
02795          }
02796          if (res >= AST_FEATURE_RETURN_PASSDIGITS) {
02797             res = 0;
02798          } else 
02799             break;
02800          hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
02801          if (hadfeatures && !hasfeatures) {
02802             /* Restore backup */
02803             memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
02804             memset(&backup_config, 0, sizeof(struct ast_bridge_config));
02805          } else if (hasfeatures) {
02806             if (!hadfeatures) {
02807                /* Backup configuration */
02808                memcpy(&backup_config, config, sizeof(struct ast_bridge_config));
02809                /* Setup temporary config options */
02810                config->play_warning = 0;
02811                ast_clear_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING);
02812                ast_clear_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING);
02813                config->warning_freq = 0;
02814                config->warning_sound = NULL;
02815                config->end_sound = NULL;
02816                config->start_sound = NULL;
02817                config->firstpass = 0;
02818             }
02819             config->start_time = ast_tvnow();
02820             config->feature_timer = featuredigittimeout;
02821             ast_debug(1, "Set time limit to %ld\n", config->feature_timer);
02822          }
02823       }
02824       if (f)
02825          ast_frfree(f);
02826 
02827    }
02828    before_you_go:
02829 
02830    if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT)) {
02831       ast_clear_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT); /* its job is done */
02832       if (bridge_cdr) {
02833          ast_cdr_discard(bridge_cdr);
02834          /* QUESTION: should we copy bridge_cdr fields to the peer before we throw it away? */
02835       }
02836       return res; /* if we shouldn't do the h-exten, we shouldn't do the bridge cdr, either! */
02837    }
02838 
02839    if (config->end_bridge_callback) {
02840       config->end_bridge_callback(config->end_bridge_callback_data);
02841    }
02842 
02843    /* run the hangup exten on the chan object IFF it was NOT involved in a parking situation 
02844     * if it were, then chan belongs to a different thread now, and might have been hung up long
02845      * ago.
02846     */
02847    if (!ast_test_flag(&(config->features_caller),AST_FEATURE_NO_H_EXTEN) &&
02848       ast_exists_extension(chan, chan->context, "h", 1, chan->cid.cid_num)) {
02849       struct ast_cdr *swapper = NULL;
02850       char savelastapp[AST_MAX_EXTENSION];
02851       char savelastdata[AST_MAX_EXTENSION];
02852       char save_exten[AST_MAX_EXTENSION];
02853       int  save_prio;
02854       int  found = 0;   /* set if we find at least one match */
02855       int  spawn_error = 0;
02856       
02857       autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
02858       ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
02859       if (bridge_cdr && ast_opt_end_cdr_before_h_exten) {
02860          ast_cdr_end(bridge_cdr);
02861       }
02862       /* swap the bridge cdr and the chan cdr for a moment, and let the endbridge
02863          dialplan code operate on it */
02864       ast_channel_lock(chan);
02865       if (bridge_cdr) {
02866          swapper = chan->cdr;
02867          ast_copy_string(savelastapp, bridge_cdr->lastapp, sizeof(bridge_cdr->lastapp));
02868          ast_copy_string(savelastdata, bridge_cdr->lastdata, sizeof(bridge_cdr->lastdata));
02869          chan->cdr = bridge_cdr;
02870       }
02871       ast_copy_string(save_exten, chan->exten, sizeof(save_exten));
02872       save_prio = chan->priority;
02873       ast_copy_string(chan->exten, "h", sizeof(chan->exten));
02874       chan->priority = 1;
02875       ast_channel_unlock(chan);
02876       while ((spawn_error = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num, &found, 1)) == 0) {
02877          chan->priority++;
02878       }
02879       if (spawn_error && (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num) || ast_check_hangup(chan))) {
02880          /* if the extension doesn't exist or a hangup occurred, this isn't really a spawn error */
02881          spawn_error = 0;
02882       }
02883       if (found && spawn_error) {
02884          /* Something bad happened, or a hangup has been requested. */
02885          ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
02886          ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
02887       }
02888       /* swap it back */
02889       ast_channel_lock(chan);
02890       ast_copy_string(chan->exten, save_exten, sizeof(chan->exten));
02891       chan->priority = save_prio;
02892       if (bridge_cdr) {
02893          if (chan->cdr == bridge_cdr) {
02894             chan->cdr = swapper;
02895          } else {
02896             bridge_cdr = NULL;
02897          }
02898       }
02899       if (!spawn_error) {
02900          ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_RUN);
02901       }
02902       ast_channel_unlock(chan);
02903       /* protect the lastapp/lastdata against the effects of the hangup/dialplan code */
02904       if (bridge_cdr) {
02905          ast_copy_string(bridge_cdr->lastapp, savelastapp, sizeof(bridge_cdr->lastapp));
02906          ast_copy_string(bridge_cdr->lastdata, savelastdata, sizeof(bridge_cdr->lastdata));
02907       }
02908       ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
02909    }
02910    
02911    /* obey the NoCDR() wishes. -- move the DISABLED flag to the bridge CDR if it was set on the channel during the bridge... */
02912    new_chan_cdr = pick_unlocked_cdr(chan->cdr); /* the proper chan cdr, if there are forked cdrs */
02913    if (bridge_cdr && new_chan_cdr && ast_test_flag(new_chan_cdr, AST_CDR_FLAG_POST_DISABLED))
02914       ast_set_flag(bridge_cdr, AST_CDR_FLAG_POST_DISABLED);
02915 
02916    /* we can post the bridge CDR at this point */
02917    if (bridge_cdr) {
02918       ast_cdr_end(bridge_cdr);
02919       ast_cdr_detach(bridge_cdr);
02920    }
02921    
02922    /* do a specialized reset on the beginning channel
02923       CDR's, if they still exist, so as not to mess up
02924       issues in future bridges;
02925       
02926       Here are the rules of the game:
02927       1. The chan and peer channel pointers will not change
02928          during the life of the bridge.
02929       2. But, in transfers, the channel names will change.
02930          between the time the bridge is started, and the
02931          time the channel ends. 
02932          Usually, when a channel changes names, it will
02933          also change CDR pointers.
02934       3. Usually, only one of the two channels (chan or peer)
02935          will change names.
02936       4. Usually, if a channel changes names during a bridge,
02937          it is because of a transfer. Usually, in these situations,
02938          it is normal to see 2 bridges running simultaneously, and
02939          it is not unusual to see the two channels that change
02940          swapped between bridges.
02941       5. After a bridge occurs, we have 2 or 3 channels' CDRs
02942          to attend to; if the chan or peer changed names,
02943          we have the before and after attached CDR's.
02944    */
02945    
02946    if (new_chan_cdr) {
02947       struct ast_channel *chan_ptr = NULL;
02948  
02949       if (strcasecmp(orig_channame, chan->name) != 0) { 
02950          /* old channel */
02951          chan_ptr = ast_get_channel_by_name_locked(orig_channame);
02952          if (chan_ptr) {
02953             if (!ast_bridged_channel(chan_ptr)) {
02954                struct ast_cdr *cur;
02955                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
02956                   if (cur == chan_cdr) {
02957                      break;
02958                   }
02959                }
02960                if (cur)
02961                   ast_cdr_specialized_reset(chan_cdr,0);
02962             }
02963             ast_channel_unlock(chan_ptr);
02964          }
02965          /* new channel */
02966          ast_cdr_specialized_reset(new_chan_cdr,0);
02967       } else {
02968          ast_cdr_specialized_reset(chan->cdr,0); /* nothing changed, reset the chan cdr  */
02969       }
02970    }
02971    
02972    {
02973       struct ast_channel *chan_ptr = NULL;
02974       new_peer_cdr = pick_unlocked_cdr(peer->cdr); /* the proper chan cdr, if there are forked cdrs */
02975       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))
02976          ast_set_flag(new_peer_cdr, AST_CDR_FLAG_POST_DISABLED); /* DISABLED is viral-- it will propagate across a bridge */
02977       if (strcasecmp(orig_peername, peer->name) != 0) { 
02978          /* old channel */
02979          chan_ptr = ast_get_channel_by_name_locked(orig_peername);
02980          if (chan_ptr) {
02981             if (!ast_bridged_channel(chan_ptr)) {
02982                struct ast_cdr *cur;
02983                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
02984                   if (cur == peer_cdr) {
02985                      break;
02986                   }
02987                }
02988                if (cur)
02989                   ast_cdr_specialized_reset(peer_cdr,0);
02990             }
02991             ast_channel_unlock(chan_ptr);
02992          }
02993          /* new channel */
02994          if (new_peer_cdr) {
02995             ast_cdr_specialized_reset(new_peer_cdr, 0);
02996          }
02997       } else {
02998          ast_cdr_specialized_reset(peer->cdr, 0); /* nothing changed, reset the peer cdr  */
02999       }
03000    }
03001    
03002    return res;
03003 }

int ast_features_reload ( void   ) 

Reload call features from features.conf.

Definition at line 4166 of file features.c.

References load_config().

Referenced by handle_features_reload().

04167 {
04168    int res;
04169    /* Release parking lot list */
04170    //ASTOBJ_CONTAINER_MARKALL(&parkinglots);
04171    // TODO: I don't think any marking is necessary
04172 
04173    /* Reload configuration */
04174    res = load_config();
04175    
04176    //ASTOBJ_CONTAINER_PRUNE_MARKED(&parkinglots, parkinglot_destroy);
04177    return res;
04178 }

struct ast_call_feature* ast_find_call_feature ( const char *  name  )  [read]

look for a call feature entry by its sname

Parameters:
name a string ptr, should match "automon", "blindxfer", "atxfer", etc.

Definition at line 1914 of file features.c.

References FEATURES_COUNT, and ast_call_feature::sname.

Referenced by action_atxfer(), handle_request_info(), and load_config().

01915 {
01916    int x;
01917    for (x = 0; x < FEATURES_COUNT; x++) {
01918       if (!strcasecmp(name, builtin_features[x].sname))
01919          return &builtin_features[x];
01920    }
01921    return NULL;
01922 }

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.
timeout is a timeout in milliseconds
extout is a parameter to an int that will hold the parked location, or NULL if you want.
Masquerade the channel rchan into a new, empty channel which is then parked with ast_park_call
Return values:
0 on success.
-1 on failure.

Definition at line 897 of file features.c.

References masq_park_call().

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

00898 {
00899    return masq_park_call(rchan, peer, timeout, extout, 0, NULL);
00900 }

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.
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 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)
Return values:
0 on success.
-1 on failure.

Definition at line 826 of file features.c.

References park_call_full(), and ast_park_call_args::timeout.

Referenced by iax_park_thread(), and sip_park_thread().

00827 {
00828    struct ast_park_call_args args = {
00829       .timeout = timeout,
00830       .extout = extout,
00831    };
00832 
00833    return park_call_full(chan, peer, &args);
00834 }

const 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 316 of file features.c.

References parking_ext.

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

00317 {
00318    return parking_ext;
00319 }

int ast_pickup_call ( struct ast_channel *  chan  ) 

Pickup a call.

Parameters:
chan channel that initiated pickup.
Walk list of channels, checking it is not itself, channel is pbx one, check that the callgroup for both channels are the same and the channel is ringing. Answer calling channel, flag channel as answered on queue, masq channels together.

Definition at line 4562 of file features.c.

References ast_answer(), ast_channel_masquerade(), ast_channel_search_locked(), ast_channel_unlock, AST_CONTROL_ANSWER, ast_debug, ast_log(), ast_queue_control(), ast_stream_and_wait(), ast_strlen_zero(), find_channel_by_group(), LOG_WARNING, ast_channel::name, pickupfailsound, and pickupsound.

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

04563 {
04564    struct ast_channel *cur = ast_channel_search_locked(find_channel_by_group, chan);
04565 
04566    if (cur) {
04567       int res = -1;
04568       ast_debug(1, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
04569       res = ast_answer(chan);
04570       if (res)
04571          ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
04572       res = ast_queue_control(chan, AST_CONTROL_ANSWER);
04573       if (res)
04574          ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
04575       res = ast_channel_masquerade(cur, chan);
04576       if (res)
04577          ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name);     /* Done */
04578       if (!ast_strlen_zero(pickupsound)) {
04579          ast_stream_and_wait(cur, pickupsound, "");
04580       }
04581       ast_channel_unlock(cur);
04582       return res;
04583    } else   {
04584       ast_debug(1, "No call pickup possible...\n");
04585       if (!ast_strlen_zero(pickupfailsound)) {
04586          ast_stream_and_wait(chan, pickupfailsound, "");
04587       }
04588    }
04589    return -1;
04590 }

const char* ast_pickup_ext ( void   ) 

Determine system call pickup extension.

Definition at line 321 of file features.c.

References pickup_ext.

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

00322 {
00323    return pickup_ext;
00324 }

void ast_rdlock_call_features ( void   ) 

Definition at line 1904 of file features.c.

References ast_rwlock_rdlock(), and features_lock.

Referenced by handle_request_info().

01905 {
01906    ast_rwlock_rdlock(&features_lock);
01907 }

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 1738 of file features.c.

References ast_log(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_call_feature::feature_entry, LOG_NOTICE, and ast_call_feature::sname.

Referenced by load_config().

01739 {
01740    if (!feature) {
01741       ast_log(LOG_NOTICE,"You didn't pass a feature!\n");
01742       return;
01743    }
01744   
01745    AST_RWLIST_WRLOCK(&feature_list);
01746    AST_RWLIST_INSERT_HEAD(&feature_list,feature,feature_entry);
01747    AST_RWLIST_UNLOCK(&feature_list);
01748 
01749    ast_verb(2, "Registered Feature '%s'\n",feature->sname);
01750 }

void ast_unlock_call_features ( void   ) 

Definition at line 1909 of file features.c.

References ast_rwlock_unlock(), and features_lock.

Referenced by handle_request_info().

01910 {
01911    ast_rwlock_unlock(&features_lock);
01912 }

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 1828 of file features.c.

References ast_free, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

01829 {
01830    if (!feature) {
01831       return;
01832    }
01833 
01834    AST_RWLIST_WRLOCK(&feature_list);
01835    AST_RWLIST_REMOVE(&feature_list, feature, feature_entry);
01836    AST_RWLIST_UNLOCK(&feature_list);
01837 
01838    ast_free(feature);
01839 }


Generated on Wed Aug 11 01:08:12 2010 for Asterisk - the Open Source PBX by  doxygen 1.5.9