Wed Mar 2 18:56:23 2011

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 2782 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().

02783 {
02784    /* Copy voice back and forth between the two channels.  Give the peer
02785       the ability to transfer calls with '#<extension' syntax. */
02786    struct ast_frame *f;
02787    struct ast_channel *who;
02788    char chan_featurecode[FEATURE_MAX_LEN + 1]="";
02789    char peer_featurecode[FEATURE_MAX_LEN + 1]="";
02790    char orig_channame[AST_MAX_EXTENSION];
02791    char orig_peername[AST_MAX_EXTENSION];
02792    int res;
02793    int diff;
02794    int hasfeatures=0;
02795    int hadfeatures=0;
02796    int autoloopflag;
02797    struct ast_option_header *aoh;
02798    struct ast_bridge_config backup_config;
02799    struct ast_cdr *bridge_cdr = NULL;
02800    struct ast_cdr *orig_peer_cdr = NULL;
02801    struct ast_cdr *chan_cdr = chan->cdr; /* the proper chan cdr, if there are forked cdrs */
02802    struct ast_cdr *peer_cdr = peer->cdr; /* the proper chan cdr, if there are forked cdrs */
02803    struct ast_cdr *new_chan_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
02804    struct ast_cdr *new_peer_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
02805 
02806    memset(&backup_config, 0, sizeof(backup_config));
02807 
02808    config->start_time = ast_tvnow();
02809 
02810    if (chan && peer) {
02811       pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
02812       pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
02813    } else if (chan) {
02814       pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
02815    }
02816 
02817    set_bridge_features_on_config(config, pbx_builtin_getvar_helper(chan, "BRIDGE_FEATURES"));
02818    add_features_datastores(chan, peer, config);
02819 
02820    /* This is an interesting case.  One example is if a ringing channel gets redirected to
02821     * an extension that picks up a parked call.  This will make sure that the call taken
02822     * out of parking gets told that the channel it just got bridged to is still ringing. */
02823    if (chan->_state == AST_STATE_RINGING && peer->visible_indication != AST_CONTROL_RINGING) {
02824       ast_indicate(peer, AST_CONTROL_RINGING);
02825    }
02826 
02827    if (monitor_ok) {
02828       const char *monitor_exec;
02829       struct ast_channel *src = NULL;
02830       if (!monitor_app) { 
02831          if (!(monitor_app = pbx_findapp("Monitor")))
02832             monitor_ok=0;
02833       }
02834       if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) 
02835          src = chan;
02836       else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
02837          src = peer;
02838       if (monitor_app && src) {
02839          char *tmp = ast_strdupa(monitor_exec);
02840          pbx_exec(src, monitor_app, tmp);
02841       }
02842    }
02843 
02844    set_config_flags(chan, peer, config);
02845    config->firstpass = 1;
02846 
02847    /* Answer if need be */
02848    if (chan->_state != AST_STATE_UP) {
02849       if (ast_raw_answer(chan, 1)) {
02850          return -1;
02851       }
02852    }
02853 
02854    ast_copy_string(orig_channame,chan->name,sizeof(orig_channame));
02855    ast_copy_string(orig_peername,peer->name,sizeof(orig_peername));
02856    orig_peer_cdr = peer_cdr;
02857    
02858    if (!chan_cdr || (chan_cdr && !ast_test_flag(chan_cdr, AST_CDR_FLAG_POST_DISABLED))) {
02859       
02860       if (chan_cdr) {
02861          ast_set_flag(chan_cdr, AST_CDR_FLAG_MAIN);
02862          ast_cdr_update(chan);
02863          bridge_cdr = ast_cdr_dup(chan_cdr);
02864          /* rip any forked CDR's off of the chan_cdr and attach
02865           * them to the bridge_cdr instead */
02866          bridge_cdr->next = chan_cdr->next;
02867          chan_cdr->next = NULL;
02868          ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
02869          ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
02870          if (peer_cdr && !ast_strlen_zero(peer_cdr->userfield)) {
02871             ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
02872          }
02873          ast_cdr_setaccount(peer, chan->accountcode);
02874 
02875       } else {
02876          /* better yet, in a xfer situation, find out why the chan cdr got zapped (pun unintentional) */
02877          bridge_cdr = ast_cdr_alloc(); /* this should be really, really rare/impossible? */
02878          ast_copy_string(bridge_cdr->channel, chan->name, sizeof(bridge_cdr->channel));
02879          ast_copy_string(bridge_cdr->dstchannel, peer->name, sizeof(bridge_cdr->dstchannel));
02880          ast_copy_string(bridge_cdr->uniqueid, chan->uniqueid, sizeof(bridge_cdr->uniqueid));
02881          ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
02882          ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
02883          ast_cdr_setcid(bridge_cdr, chan);
02884          bridge_cdr->disposition = (chan->_state == AST_STATE_UP) ?  AST_CDR_ANSWERED : AST_CDR_NULL;
02885          bridge_cdr->amaflags = chan->amaflags ? chan->amaflags :  ast_default_amaflags;
02886          ast_copy_string(bridge_cdr->accountcode, chan->accountcode, sizeof(bridge_cdr->accountcode));
02887          /* Destination information */
02888          ast_copy_string(bridge_cdr->dst, chan->exten, sizeof(bridge_cdr->dst));
02889          ast_copy_string(bridge_cdr->dcontext, chan->context, sizeof(bridge_cdr->dcontext));
02890          if (peer_cdr) {
02891             bridge_cdr->start = peer_cdr->start;
02892             ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
02893          } else {
02894             ast_cdr_start(bridge_cdr);
02895          }
02896       }
02897       ast_debug(4,"bridge answer set, chan answer set\n");
02898       /* peer_cdr->answer will be set when a macro runs on the peer;
02899          in that case, the bridge answer will be delayed while the
02900          macro plays on the peer channel. The peer answered the call
02901          before the macro started playing. To the phone system,
02902          this is billable time for the call, even tho the caller
02903          hears nothing but ringing while the macro does its thing. */
02904 
02905       /* Another case where the peer cdr's time will be set, is when
02906          A self-parks by pickup up phone and dialing 700, then B
02907          picks up A by dialing its parking slot; there may be more 
02908          practical paths that get the same result, tho... in which
02909          case you get the previous answer time from the Park... which
02910          is before the bridge's start time, so I added in the 
02911          tvcmp check to the if below */
02912 
02913       if (peer_cdr && !ast_tvzero(peer_cdr->answer) && ast_tvcmp(peer_cdr->answer, bridge_cdr->start) >= 0) {
02914          ast_cdr_setanswer(bridge_cdr, peer_cdr->answer);
02915          ast_cdr_setdisposition(bridge_cdr, peer_cdr->disposition);
02916          if (chan_cdr) {
02917             ast_cdr_setanswer(chan_cdr, peer_cdr->answer);
02918             ast_cdr_setdisposition(chan_cdr, peer_cdr->disposition);
02919          }
02920       } else {
02921          ast_cdr_answer(bridge_cdr);
02922          if (chan_cdr) {
02923             ast_cdr_answer(chan_cdr); /* for the sake of cli status checks */
02924          }
02925       }
02926       if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT) && (chan_cdr || peer_cdr)) {
02927          if (chan_cdr) {
02928             ast_set_flag(chan_cdr, AST_CDR_FLAG_BRIDGED);
02929          }
02930          if (peer_cdr) {
02931             ast_set_flag(peer_cdr, AST_CDR_FLAG_BRIDGED);
02932          }
02933       }
02934       /* the DIALED flag may be set if a dialed channel is transfered
02935        * and then bridged to another channel.  In order for the
02936        * bridge CDR to be written, the DIALED flag must not be
02937        * present. */
02938       ast_clear_flag(bridge_cdr, AST_CDR_FLAG_DIALED);
02939    }
02940    for (;;) {
02941       struct ast_channel *other; /* used later */
02942    
02943       res = ast_channel_bridge(chan, peer, config, &f, &who);
02944       
02945       /* When frame is not set, we are probably involved in a situation
02946          where we've timed out.
02947          When frame is set, we'll come this code twice; once for DTMF_BEGIN
02948          and also for DTMF_END. If we flow into the following 'if' for both, then 
02949          our wait times are cut in half, as both will subtract from the
02950          feature_timer. Not good!
02951       */
02952       if (config->feature_timer && (!f || f->frametype == AST_FRAME_DTMF_END)) {
02953          /* Update time limit for next pass */
02954          diff = ast_tvdiff_ms(ast_tvnow(), config->start_time);
02955          if (res == AST_BRIDGE_RETRY) {
02956             /* The feature fully timed out but has not been updated. Skip
02957              * the potential round error from the diff calculation and
02958              * explicitly set to expired. */
02959             config->feature_timer = -1;
02960          } else {
02961             config->feature_timer -= diff;
02962          }
02963 
02964          if (hasfeatures) {
02965             /* Running on backup config, meaning a feature might be being
02966                activated, but that's no excuse to keep things going 
02967                indefinitely! */
02968             if (backup_config.feature_timer && ((backup_config.feature_timer -= diff) <= 0)) {
02969                ast_debug(1, "Timed out, realtime this time!\n");
02970                config->feature_timer = 0;
02971                who = chan;
02972                if (f)
02973                   ast_frfree(f);
02974                f = NULL;
02975                res = 0;
02976             } else if (config->feature_timer <= 0) {
02977                /* Not *really* out of time, just out of time for
02978                   digits to come in for features. */
02979                ast_debug(1, "Timed out for feature!\n");
02980                if (!ast_strlen_zero(peer_featurecode)) {
02981                   ast_dtmf_stream(chan, peer, peer_featurecode, 0, 0);
02982                   memset(peer_featurecode, 0, sizeof(peer_featurecode));
02983                }
02984                if (!ast_strlen_zero(chan_featurecode)) {
02985                   ast_dtmf_stream(peer, chan, chan_featurecode, 0, 0);
02986                   memset(chan_featurecode, 0, sizeof(chan_featurecode));
02987                }
02988                if (f)
02989                   ast_frfree(f);
02990                hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
02991                if (!hasfeatures) {
02992                   /* Restore original (possibly time modified) bridge config */
02993                   memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
02994                   memset(&backup_config, 0, sizeof(backup_config));
02995                }
02996                hadfeatures = hasfeatures;
02997                /* Continue as we were */
02998                continue;
02999             } else if (!f) {
03000                /* The bridge returned without a frame and there is a feature in progress.
03001                 * However, we don't think the feature has quite yet timed out, so just
03002                 * go back into the bridge. */
03003                continue;
03004             }
03005          } else {
03006             if (config->feature_timer <=0) {
03007                /* We ran out of time */
03008                config->feature_timer = 0;
03009                who = chan;
03010                if (f)
03011                   ast_frfree(f);
03012                f = NULL;
03013                res = 0;
03014             }
03015          }
03016       }
03017       if (res < 0) {
03018          if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_test_flag(peer, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan) && !ast_check_hangup(peer))
03019             ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name);
03020          goto before_you_go;
03021       }
03022       
03023       if (!f || (f->frametype == AST_FRAME_CONTROL &&
03024             (f->subclass == AST_CONTROL_HANGUP || f->subclass == AST_CONTROL_BUSY || 
03025                f->subclass == AST_CONTROL_CONGESTION))) {
03026          res = -1;
03027          break;
03028       }
03029       /* many things should be sent to the 'other' channel */
03030       other = (who == chan) ? peer : chan;
03031       if (f->frametype == AST_FRAME_CONTROL) {
03032          switch (f->subclass) {
03033          case AST_CONTROL_RINGING:
03034          case AST_CONTROL_FLASH:
03035          case -1:
03036             ast_indicate(other, f->subclass);
03037             break;
03038          case AST_CONTROL_HOLD:
03039          case AST_CONTROL_UNHOLD:
03040             ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen);
03041             break;
03042          case AST_CONTROL_OPTION:
03043             aoh = f->data.ptr;
03044             /* Forward option Requests */
03045             if (aoh && aoh->flag == AST_OPTION_FLAG_REQUEST) {
03046                ast_channel_setoption(other, ntohs(aoh->option), aoh->data, 
03047                   f->datalen - sizeof(struct ast_option_header), 0);
03048             }
03049             break;
03050          }
03051       } else if (f->frametype == AST_FRAME_DTMF_BEGIN) {
03052          /* eat it */
03053       } else if (f->frametype == AST_FRAME_DTMF) {
03054          char *featurecode;
03055          int sense;
03056 
03057          hadfeatures = hasfeatures;
03058          /* This cannot overrun because the longest feature is one shorter than our buffer */
03059          if (who == chan) {
03060             sense = FEATURE_SENSE_CHAN;
03061             featurecode = chan_featurecode;
03062          } else  {
03063             sense = FEATURE_SENSE_PEER;
03064             featurecode = peer_featurecode;
03065          }
03066          /*! append the event to featurecode. we rely on the string being zero-filled, and
03067           * not overflowing it. 
03068           * \todo XXX how do we guarantee the latter ?
03069           */
03070          featurecode[strlen(featurecode)] = f->subclass;
03071          /* Get rid of the frame before we start doing "stuff" with the channels */
03072          ast_frfree(f);
03073          f = NULL;
03074          config->feature_timer = backup_config.feature_timer;
03075          res = feature_interpret(chan, peer, config, featurecode, sense);
03076          switch(res) {
03077          case AST_FEATURE_RETURN_PASSDIGITS:
03078             ast_dtmf_stream(other, who, featurecode, 0, 0);
03079             /* Fall through */
03080          case AST_FEATURE_RETURN_SUCCESS:
03081             memset(featurecode, 0, sizeof(chan_featurecode));
03082             break;
03083          }
03084          if (res >= AST_FEATURE_RETURN_PASSDIGITS) {
03085             res = 0;
03086          } else 
03087             break;
03088          hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
03089          if (hadfeatures && !hasfeatures) {
03090             /* Restore backup */
03091             memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
03092             memset(&backup_config, 0, sizeof(struct ast_bridge_config));
03093          } else if (hasfeatures) {
03094             if (!hadfeatures) {
03095                /* Backup configuration */
03096                memcpy(&backup_config, config, sizeof(struct ast_bridge_config));
03097                /* Setup temporary config options */
03098                config->play_warning = 0;
03099                ast_clear_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING);
03100                ast_clear_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING);
03101                config->warning_freq = 0;
03102                config->warning_sound = NULL;
03103                config->end_sound = NULL;
03104                config->start_sound = NULL;
03105                config->firstpass = 0;
03106             }
03107             config->start_time = ast_tvnow();
03108             config->feature_timer = featuredigittimeout;
03109             ast_debug(1, "Set time limit to %ld ms\n", config->feature_timer);
03110          }
03111       }
03112       if (f)
03113          ast_frfree(f);
03114 
03115    }
03116    before_you_go:
03117 
03118    if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT)) {
03119       ast_clear_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT); /* its job is done */
03120       if (bridge_cdr) {
03121          ast_cdr_discard(bridge_cdr);
03122          /* QUESTION: should we copy bridge_cdr fields to the peer before we throw it away? */
03123       }
03124       return res; /* if we shouldn't do the h-exten, we shouldn't do the bridge cdr, either! */
03125    }
03126 
03127    if (config->end_bridge_callback) {
03128       config->end_bridge_callback(config->end_bridge_callback_data);
03129    }
03130 
03131    /* run the hangup exten on the chan object IFF it was NOT involved in a parking situation 
03132     * if it were, then chan belongs to a different thread now, and might have been hung up long
03133      * ago.
03134     */
03135    if (!ast_test_flag(&(config->features_caller),AST_FEATURE_NO_H_EXTEN) &&
03136       ast_exists_extension(chan, chan->context, "h", 1, chan->cid.cid_num)) {
03137       struct ast_cdr *swapper = NULL;
03138       char savelastapp[AST_MAX_EXTENSION];
03139       char savelastdata[AST_MAX_EXTENSION];
03140       char save_exten[AST_MAX_EXTENSION];
03141       int  save_prio;
03142       int  found = 0;   /* set if we find at least one match */
03143       int  spawn_error = 0;
03144       
03145       autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
03146       ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
03147       if (bridge_cdr && ast_opt_end_cdr_before_h_exten) {
03148          ast_cdr_end(bridge_cdr);
03149       }
03150       /* swap the bridge cdr and the chan cdr for a moment, and let the endbridge
03151          dialplan code operate on it */
03152       ast_channel_lock(chan);
03153       if (bridge_cdr) {
03154          swapper = chan->cdr;
03155          ast_copy_string(savelastapp, bridge_cdr->lastapp, sizeof(bridge_cdr->lastapp));
03156          ast_copy_string(savelastdata, bridge_cdr->lastdata, sizeof(bridge_cdr->lastdata));
03157          chan->cdr = bridge_cdr;
03158       }
03159       ast_copy_string(save_exten, chan->exten, sizeof(save_exten));
03160       save_prio = chan->priority;
03161       ast_copy_string(chan->exten, "h", sizeof(chan->exten));
03162       chan->priority = 1;
03163       ast_channel_unlock(chan);
03164       while ((spawn_error = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num, &found, 1)) == 0) {
03165          chan->priority++;
03166       }
03167       if (spawn_error && (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num) || ast_check_hangup(chan))) {
03168          /* if the extension doesn't exist or a hangup occurred, this isn't really a spawn error */
03169          spawn_error = 0;
03170       }
03171       if (found && spawn_error) {
03172          /* Something bad happened, or a hangup has been requested. */
03173          ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
03174          ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
03175       }
03176       /* swap it back */
03177       ast_channel_lock(chan);
03178       ast_copy_string(chan->exten, save_exten, sizeof(chan->exten));
03179       chan->priority = save_prio;
03180       if (bridge_cdr) {
03181          if (chan->cdr == bridge_cdr) {
03182             chan->cdr = swapper;
03183          } else {
03184             bridge_cdr = NULL;
03185          }
03186       }
03187       if (!spawn_error) {
03188          ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_RUN);
03189       }
03190       ast_channel_unlock(chan);
03191       /* protect the lastapp/lastdata against the effects of the hangup/dialplan code */
03192       if (bridge_cdr) {
03193          ast_copy_string(bridge_cdr->lastapp, savelastapp, sizeof(bridge_cdr->lastapp));
03194          ast_copy_string(bridge_cdr->lastdata, savelastdata, sizeof(bridge_cdr->lastdata));
03195       }
03196       ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
03197    }
03198    
03199    /* obey the NoCDR() wishes. -- move the DISABLED flag to the bridge CDR if it was set on the channel during the bridge... */
03200    new_chan_cdr = pick_unlocked_cdr(chan->cdr); /* the proper chan cdr, if there are forked cdrs */
03201    if (bridge_cdr && new_chan_cdr && ast_test_flag(new_chan_cdr, AST_CDR_FLAG_POST_DISABLED))
03202       ast_set_flag(bridge_cdr, AST_CDR_FLAG_POST_DISABLED);
03203 
03204    /* we can post the bridge CDR at this point */
03205    if (bridge_cdr) {
03206       ast_cdr_end(bridge_cdr);
03207       ast_cdr_detach(bridge_cdr);
03208    }
03209    
03210    /* do a specialized reset on the beginning channel
03211       CDR's, if they still exist, so as not to mess up
03212       issues in future bridges;
03213       
03214       Here are the rules of the game:
03215       1. The chan and peer channel pointers will not change
03216          during the life of the bridge.
03217       2. But, in transfers, the channel names will change.
03218          between the time the bridge is started, and the
03219          time the channel ends. 
03220          Usually, when a channel changes names, it will
03221          also change CDR pointers.
03222       3. Usually, only one of the two channels (chan or peer)
03223          will change names.
03224       4. Usually, if a channel changes names during a bridge,
03225          it is because of a transfer. Usually, in these situations,
03226          it is normal to see 2 bridges running simultaneously, and
03227          it is not unusual to see the two channels that change
03228          swapped between bridges.
03229       5. After a bridge occurs, we have 2 or 3 channels' CDRs
03230          to attend to; if the chan or peer changed names,
03231          we have the before and after attached CDR's.
03232    */
03233    
03234    if (new_chan_cdr) {
03235       struct ast_channel *chan_ptr = NULL;
03236  
03237       if (strcasecmp(orig_channame, chan->name) != 0) { 
03238          /* old channel */
03239          chan_ptr = ast_get_channel_by_name_locked(orig_channame);
03240          if (chan_ptr) {
03241             if (!ast_bridged_channel(chan_ptr)) {
03242                struct ast_cdr *cur;
03243                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
03244                   if (cur == chan_cdr) {
03245                      break;
03246                   }
03247                }
03248                if (cur)
03249                   ast_cdr_specialized_reset(chan_cdr,0);
03250             }
03251             ast_channel_unlock(chan_ptr);
03252          }
03253          /* new channel */
03254          ast_cdr_specialized_reset(new_chan_cdr,0);
03255       } else {
03256          ast_cdr_specialized_reset(chan->cdr,0); /* nothing changed, reset the chan cdr  */
03257       }
03258    }
03259    
03260    {
03261       struct ast_channel *chan_ptr = NULL;
03262       new_peer_cdr = pick_unlocked_cdr(peer->cdr); /* the proper chan cdr, if there are forked cdrs */
03263       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))
03264          ast_set_flag(new_peer_cdr, AST_CDR_FLAG_POST_DISABLED); /* DISABLED is viral-- it will propagate across a bridge */
03265       if (strcasecmp(orig_peername, peer->name) != 0) { 
03266          /* old channel */
03267          chan_ptr = ast_get_channel_by_name_locked(orig_peername);
03268          if (chan_ptr) {
03269             if (!ast_bridged_channel(chan_ptr)) {
03270                struct ast_cdr *cur;
03271                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
03272                   if (cur == peer_cdr) {
03273                      break;
03274                   }
03275                }
03276                if (cur)
03277                   ast_cdr_specialized_reset(peer_cdr,0);
03278             }
03279             ast_channel_unlock(chan_ptr);
03280          }
03281          /* new channel */
03282          if (new_peer_cdr) {
03283             ast_cdr_specialized_reset(new_peer_cdr, 0);
03284          }
03285       } else {
03286          ast_cdr_specialized_reset(peer->cdr, 0); /* nothing changed, reset the peer cdr  */
03287       }
03288    }
03289    
03290    return res;
03291 }

int ast_features_reload ( void   ) 

Reload call features from features.conf.

Definition at line 4490 of file features.c.

References load_config().

Referenced by handle_features_reload().

04491 {
04492    int res;
04493    /* Release parking lot list */
04494    //ASTOBJ_CONTAINER_MARKALL(&parkinglots);
04495    // TODO: I don't think any marking is necessary
04496 
04497    /* Reload configuration */
04498    res = load_config();
04499    
04500    //ASTOBJ_CONTAINER_PRUNE_MARKED(&parkinglots, parkinglot_destroy);
04501    return res;
04502 }

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

References FEATURES_COUNT, and ast_call_feature::sname.

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

02107 {
02108    int x;
02109    for (x = 0; x < FEATURES_COUNT; x++) {
02110       if (!strcasecmp(name, builtin_features[x].sname))
02111          return &builtin_features[x];
02112    }
02113    return NULL;
02114 }

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 1063 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().

01064 {
01065    return masq_park_call(rchan, peer, timeout, extout, 0, NULL);
01066 }

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

References park_call_full(), and ast_park_call_args::timeout.

Referenced by iax_park_thread(), and sip_park_thread().

00993 {
00994    struct ast_park_call_args args = {
00995       .timeout = timeout,
00996       .extout = extout,
00997    };
00998 
00999    return park_call_full(chan, peer, &args);
01000 }

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 479 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().

00480 {
00481    return parking_ext;
00482 }

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 4886 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().

04887 {
04888    struct ast_channel *cur = ast_channel_search_locked(find_channel_by_group, chan);
04889 
04890    if (cur) {
04891       int res = -1;
04892       ast_debug(1, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
04893       res = ast_answer(chan);
04894       if (res)
04895          ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
04896       res = ast_queue_control(chan, AST_CONTROL_ANSWER);
04897       if (res)
04898          ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
04899       res = ast_channel_masquerade(cur, chan);
04900       if (res)
04901          ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name);     /* Done */
04902       if (!ast_strlen_zero(pickupsound)) {
04903          ast_stream_and_wait(cur, pickupsound, "");
04904       }
04905       ast_channel_unlock(cur);
04906       return res;
04907    } else   {
04908       ast_debug(1, "No call pickup possible...\n");
04909       if (!ast_strlen_zero(pickupfailsound)) {
04910          ast_stream_and_wait(chan, pickupfailsound, "");
04911       }
04912    }
04913    return -1;
04914 }

const char* ast_pickup_ext ( void   ) 

Determine system call pickup extension.

Definition at line 484 of file features.c.

References pickup_ext.

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

00485 {
00486    return pickup_ext;
00487 }

void ast_rdlock_call_features ( void   ) 

Definition at line 2096 of file features.c.

References ast_rwlock_rdlock(), and features_lock.

Referenced by handle_request_info().

02097 {
02098    ast_rwlock_rdlock(&features_lock);
02099 }

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 1930 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().

01931 {
01932    if (!feature) {
01933       ast_log(LOG_NOTICE,"You didn't pass a feature!\n");
01934       return;
01935    }
01936   
01937    AST_RWLIST_WRLOCK(&feature_list);
01938    AST_RWLIST_INSERT_HEAD(&feature_list,feature,feature_entry);
01939    AST_RWLIST_UNLOCK(&feature_list);
01940 
01941    ast_verb(2, "Registered Feature '%s'\n",feature->sname);
01942 }

void ast_unlock_call_features ( void   ) 

Definition at line 2101 of file features.c.

References ast_rwlock_unlock(), and features_lock.

Referenced by handle_request_info().

02102 {
02103    ast_rwlock_unlock(&features_lock);
02104 }

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

References ast_free, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

02021 {
02022    if (!feature) {
02023       return;
02024    }
02025 
02026    AST_RWLIST_WRLOCK(&feature_list);
02027    AST_RWLIST_REMOVE(&feature_list, feature, feature_entry);
02028    AST_RWLIST_UNLOCK(&feature_list);
02029 
02030    ast_free(feature);
02031 }


Generated on Wed Mar 2 18:56:24 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.9