Thu Apr 28 2011 16:57:09

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_featureast_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.


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,configSet start time, check for two channels,check if monitor on check for feature activation, create new CDR
Return values:
reson success.
-1on 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 2792 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_MAX_EXTENSION, 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, chan, 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().

{
   /* Copy voice back and forth between the two channels.  Give the peer
      the ability to transfer calls with '#<extension' syntax. */
   struct ast_frame *f;
   struct ast_channel *who;
   char chan_featurecode[FEATURE_MAX_LEN + 1]="";
   char peer_featurecode[FEATURE_MAX_LEN + 1]="";
   char orig_channame[AST_MAX_EXTENSION];
   char orig_peername[AST_MAX_EXTENSION];
   int res;
   int diff;
   int hasfeatures=0;
   int hadfeatures=0;
   int autoloopflag;
   struct ast_option_header *aoh;
   struct ast_bridge_config backup_config;
   struct ast_cdr *bridge_cdr = NULL;
   struct ast_cdr *orig_peer_cdr = NULL;
   struct ast_cdr *chan_cdr = chan->cdr; /* the proper chan cdr, if there are forked cdrs */
   struct ast_cdr *peer_cdr = peer->cdr; /* the proper chan cdr, if there are forked cdrs */
   struct ast_cdr *new_chan_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
   struct ast_cdr *new_peer_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */

   memset(&backup_config, 0, sizeof(backup_config));

   config->start_time = ast_tvnow();

   if (chan && peer) {
      pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
      pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
   } else if (chan) {
      pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
   }

   set_bridge_features_on_config(config, pbx_builtin_getvar_helper(chan, "BRIDGE_FEATURES"));
   add_features_datastores(chan, peer, config);

   /* This is an interesting case.  One example is if a ringing channel gets redirected to
    * an extension that picks up a parked call.  This will make sure that the call taken
    * out of parking gets told that the channel it just got bridged to is still ringing. */
   if (chan->_state == AST_STATE_RINGING && peer->visible_indication != AST_CONTROL_RINGING) {
      ast_indicate(peer, AST_CONTROL_RINGING);
   }

   if (monitor_ok) {
      const char *monitor_exec;
      struct ast_channel *src = NULL;
      if (!monitor_app) { 
         if (!(monitor_app = pbx_findapp("Monitor")))
            monitor_ok=0;
      }
      if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) 
         src = chan;
      else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
         src = peer;
      if (monitor_app && src) {
         char *tmp = ast_strdupa(monitor_exec);
         pbx_exec(src, monitor_app, tmp);
      }
   }

   set_config_flags(chan, peer, config);
   config->firstpass = 1;

   /* Answer if need be */
   if (chan->_state != AST_STATE_UP) {
      if (ast_raw_answer(chan, 1)) {
         return -1;
      }
   }

   ast_copy_string(orig_channame,chan->name,sizeof(orig_channame));
   ast_copy_string(orig_peername,peer->name,sizeof(orig_peername));
   orig_peer_cdr = peer_cdr;
   
   if (!chan_cdr || (chan_cdr && !ast_test_flag(chan_cdr, AST_CDR_FLAG_POST_DISABLED))) {
      
      if (chan_cdr) {
         ast_set_flag(chan_cdr, AST_CDR_FLAG_MAIN);
         ast_cdr_update(chan);
         bridge_cdr = ast_cdr_dup(chan_cdr);
         /* rip any forked CDR's off of the chan_cdr and attach
          * them to the bridge_cdr instead */
         bridge_cdr->next = chan_cdr->next;
         chan_cdr->next = NULL;
         ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
         ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
         if (peer_cdr && !ast_strlen_zero(peer_cdr->userfield)) {
            ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
         }
         ast_cdr_setaccount(peer, chan->accountcode);

      } else {
         /* better yet, in a xfer situation, find out why the chan cdr got zapped (pun unintentional) */
         bridge_cdr = ast_cdr_alloc(); /* this should be really, really rare/impossible? */
         ast_copy_string(bridge_cdr->channel, chan->name, sizeof(bridge_cdr->channel));
         ast_copy_string(bridge_cdr->dstchannel, peer->name, sizeof(bridge_cdr->dstchannel));
         ast_copy_string(bridge_cdr->uniqueid, chan->uniqueid, sizeof(bridge_cdr->uniqueid));
         ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
         ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
         ast_cdr_setcid(bridge_cdr, chan);
         bridge_cdr->disposition = (chan->_state == AST_STATE_UP) ?  AST_CDR_ANSWERED : AST_CDR_NULL;
         bridge_cdr->amaflags = chan->amaflags ? chan->amaflags :  ast_default_amaflags;
         ast_copy_string(bridge_cdr->accountcode, chan->accountcode, sizeof(bridge_cdr->accountcode));
         /* Destination information */
         ast_copy_string(bridge_cdr->dst, chan->exten, sizeof(bridge_cdr->dst));
         ast_copy_string(bridge_cdr->dcontext, chan->context, sizeof(bridge_cdr->dcontext));
         if (peer_cdr) {
            bridge_cdr->start = peer_cdr->start;
            ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
         } else {
            ast_cdr_start(bridge_cdr);
         }
      }
      ast_debug(4,"bridge answer set, chan answer set\n");
      /* peer_cdr->answer will be set when a macro runs on the peer;
         in that case, the bridge answer will be delayed while the
         macro plays on the peer channel. The peer answered the call
         before the macro started playing. To the phone system,
         this is billable time for the call, even tho the caller
         hears nothing but ringing while the macro does its thing. */

      /* Another case where the peer cdr's time will be set, is when
         A self-parks by pickup up phone and dialing 700, then B
         picks up A by dialing its parking slot; there may be more 
         practical paths that get the same result, tho... in which
         case you get the previous answer time from the Park... which
         is before the bridge's start time, so I added in the 
         tvcmp check to the if below */

      if (peer_cdr && !ast_tvzero(peer_cdr->answer) && ast_tvcmp(peer_cdr->answer, bridge_cdr->start) >= 0) {
         ast_cdr_setanswer(bridge_cdr, peer_cdr->answer);
         ast_cdr_setdisposition(bridge_cdr, peer_cdr->disposition);
         if (chan_cdr) {
            ast_cdr_setanswer(chan_cdr, peer_cdr->answer);
            ast_cdr_setdisposition(chan_cdr, peer_cdr->disposition);
         }
      } else {
         ast_cdr_answer(bridge_cdr);
         if (chan_cdr) {
            ast_cdr_answer(chan_cdr); /* for the sake of cli status checks */
         }
      }
      if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT) && (chan_cdr || peer_cdr)) {
         if (chan_cdr) {
            ast_set_flag(chan_cdr, AST_CDR_FLAG_BRIDGED);
         }
         if (peer_cdr) {
            ast_set_flag(peer_cdr, AST_CDR_FLAG_BRIDGED);
         }
      }
      /* the DIALED flag may be set if a dialed channel is transfered
       * and then bridged to another channel.  In order for the
       * bridge CDR to be written, the DIALED flag must not be
       * present. */
      ast_clear_flag(bridge_cdr, AST_CDR_FLAG_DIALED);
   }
   for (;;) {
      struct ast_channel *other; /* used later */
   
      res = ast_channel_bridge(chan, peer, config, &f, &who);
      
      /* When frame is not set, we are probably involved in a situation
         where we've timed out.
         When frame is set, we'll come this code twice; once for DTMF_BEGIN
         and also for DTMF_END. If we flow into the following 'if' for both, then 
         our wait times are cut in half, as both will subtract from the
         feature_timer. Not good!
      */
      if (config->feature_timer && (!f || f->frametype == AST_FRAME_DTMF_END)) {
         /* Update time limit for next pass */
         diff = ast_tvdiff_ms(ast_tvnow(), config->start_time);
         if (res == AST_BRIDGE_RETRY) {
            /* The feature fully timed out but has not been updated. Skip
             * the potential round error from the diff calculation and
             * explicitly set to expired. */
            config->feature_timer = -1;
         } else {
            config->feature_timer -= diff;
         }

         if (hasfeatures) {
            /* Running on backup config, meaning a feature might be being
               activated, but that's no excuse to keep things going 
               indefinitely! */
            if (backup_config.feature_timer && ((backup_config.feature_timer -= diff) <= 0)) {
               ast_debug(1, "Timed out, realtime this time!\n");
               config->feature_timer = 0;
               who = chan;
               if (f)
                  ast_frfree(f);
               f = NULL;
               res = 0;
            } else if (config->feature_timer <= 0) {
               /* Not *really* out of time, just out of time for
                  digits to come in for features. */
               ast_debug(1, "Timed out for feature!\n");
               if (!ast_strlen_zero(peer_featurecode)) {
                  ast_dtmf_stream(chan, peer, peer_featurecode, 0, 0);
                  memset(peer_featurecode, 0, sizeof(peer_featurecode));
               }
               if (!ast_strlen_zero(chan_featurecode)) {
                  ast_dtmf_stream(peer, chan, chan_featurecode, 0, 0);
                  memset(chan_featurecode, 0, sizeof(chan_featurecode));
               }
               if (f)
                  ast_frfree(f);
               hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
               if (!hasfeatures) {
                  /* Restore original (possibly time modified) bridge config */
                  memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
                  memset(&backup_config, 0, sizeof(backup_config));
               }
               hadfeatures = hasfeatures;
               /* Continue as we were */
               continue;
            } else if (!f) {
               /* The bridge returned without a frame and there is a feature in progress.
                * However, we don't think the feature has quite yet timed out, so just
                * go back into the bridge. */
               continue;
            }
         } else {
            if (config->feature_timer <=0) {
               /* We ran out of time */
               config->feature_timer = 0;
               who = chan;
               if (f)
                  ast_frfree(f);
               f = NULL;
               res = 0;
            }
         }
      }
      if (res < 0) {
         if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_test_flag(peer, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan) && !ast_check_hangup(peer))
            ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name);
         goto before_you_go;
      }
      
      if (!f || (f->frametype == AST_FRAME_CONTROL &&
            (f->subclass == AST_CONTROL_HANGUP || f->subclass == AST_CONTROL_BUSY || 
               f->subclass == AST_CONTROL_CONGESTION))) {
         res = -1;
         break;
      }
      /* many things should be sent to the 'other' channel */
      other = (who == chan) ? peer : chan;
      if (f->frametype == AST_FRAME_CONTROL) {
         switch (f->subclass) {
         case AST_CONTROL_RINGING:
         case AST_CONTROL_FLASH:
         case -1:
            ast_indicate(other, f->subclass);
            break;
         case AST_CONTROL_HOLD:
         case AST_CONTROL_UNHOLD:
            ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen);
            break;
         case AST_CONTROL_OPTION:
            aoh = f->data.ptr;
            /* Forward option Requests */
            if (aoh && aoh->flag == AST_OPTION_FLAG_REQUEST) {
               ast_channel_setoption(other, ntohs(aoh->option), aoh->data, 
                  f->datalen - sizeof(struct ast_option_header), 0);
            }
            break;
         }
      } else if (f->frametype == AST_FRAME_DTMF_BEGIN) {
         /* eat it */
      } else if (f->frametype == AST_FRAME_DTMF) {
         char *featurecode;
         int sense;

         hadfeatures = hasfeatures;
         /* This cannot overrun because the longest feature is one shorter than our buffer */
         if (who == chan) {
            sense = FEATURE_SENSE_CHAN;
            featurecode = chan_featurecode;
         } else  {
            sense = FEATURE_SENSE_PEER;
            featurecode = peer_featurecode;
         }
         /*! 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 ?
          */
         featurecode[strlen(featurecode)] = f->subclass;
         /* Get rid of the frame before we start doing "stuff" with the channels */
         ast_frfree(f);
         f = NULL;
         config->feature_timer = backup_config.feature_timer;
         res = feature_interpret(chan, peer, config, featurecode, sense);
         switch(res) {
         case AST_FEATURE_RETURN_PASSDIGITS:
            ast_dtmf_stream(other, who, featurecode, 0, 0);
            /* Fall through */
         case AST_FEATURE_RETURN_SUCCESS:
            memset(featurecode, 0, sizeof(chan_featurecode));
            break;
         }
         if (res >= AST_FEATURE_RETURN_PASSDIGITS) {
            res = 0;
         } else 
            break;
         hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
         if (hadfeatures && !hasfeatures) {
            /* Restore backup */
            memcpy(config, &backup_config, sizeof(struct ast_bridge_config));
            memset(&backup_config, 0, sizeof(struct ast_bridge_config));
         } else if (hasfeatures) {
            if (!hadfeatures) {
               /* Backup configuration */
               memcpy(&backup_config, config, sizeof(struct ast_bridge_config));
               /* Setup temporary config options */
               config->play_warning = 0;
               ast_clear_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING);
               ast_clear_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING);
               config->warning_freq = 0;
               config->warning_sound = NULL;
               config->end_sound = NULL;
               config->start_sound = NULL;
               config->firstpass = 0;
            }
            config->start_time = ast_tvnow();
            config->feature_timer = featuredigittimeout;
            ast_debug(1, "Set time limit to %ld ms\n", config->feature_timer);
         }
      }
      if (f)
         ast_frfree(f);

   }
   before_you_go:

   if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT)) {
      ast_clear_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT); /* its job is done */
      if (bridge_cdr) {
         ast_cdr_discard(bridge_cdr);
         /* QUESTION: should we copy bridge_cdr fields to the peer before we throw it away? */
      }
      return res; /* if we shouldn't do the h-exten, we shouldn't do the bridge cdr, either! */
   }

   if (config->end_bridge_callback) {
      config->end_bridge_callback(config->end_bridge_callback_data);
   }

   /* run the hangup exten on the chan object IFF it was NOT involved in a parking situation 
    * if it were, then chan belongs to a different thread now, and might have been hung up long
     * ago.
    */
   if (!ast_test_flag(&(config->features_caller),AST_FEATURE_NO_H_EXTEN) &&
      ast_exists_extension(chan, chan->context, "h", 1, chan->cid.cid_num)) {
      struct ast_cdr *swapper = NULL;
      char savelastapp[AST_MAX_EXTENSION];
      char savelastdata[AST_MAX_EXTENSION];
      char save_exten[AST_MAX_EXTENSION];
      int  save_prio;
      int  found = 0;   /* set if we find at least one match */
      int  spawn_error = 0;
      
      autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
      ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
      if (bridge_cdr && ast_opt_end_cdr_before_h_exten) {
         ast_cdr_end(bridge_cdr);
      }
      /* swap the bridge cdr and the chan cdr for a moment, and let the endbridge
         dialplan code operate on it */
      ast_channel_lock(chan);
      if (bridge_cdr) {
         swapper = chan->cdr;
         ast_copy_string(savelastapp, bridge_cdr->lastapp, sizeof(bridge_cdr->lastapp));
         ast_copy_string(savelastdata, bridge_cdr->lastdata, sizeof(bridge_cdr->lastdata));
         chan->cdr = bridge_cdr;
      }
      ast_copy_string(save_exten, chan->exten, sizeof(save_exten));
      save_prio = chan->priority;
      ast_copy_string(chan->exten, "h", sizeof(chan->exten));
      chan->priority = 1;
      ast_channel_unlock(chan);
      while ((spawn_error = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num, &found, 1)) == 0) {
         chan->priority++;
      }
      if (spawn_error && (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num) || ast_check_hangup(chan))) {
         /* if the extension doesn't exist or a hangup occurred, this isn't really a spawn error */
         spawn_error = 0;
      }
      if (found && spawn_error) {
         /* Something bad happened, or a hangup has been requested. */
         ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
         ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
      }
      /* swap it back */
      ast_channel_lock(chan);
      ast_copy_string(chan->exten, save_exten, sizeof(chan->exten));
      chan->priority = save_prio;
      if (bridge_cdr) {
         if (chan->cdr == bridge_cdr) {
            chan->cdr = swapper;
         } else {
            bridge_cdr = NULL;
         }
      }
      if (!spawn_error) {
         ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_RUN);
      }
      ast_channel_unlock(chan);
      /* protect the lastapp/lastdata against the effects of the hangup/dialplan code */
      if (bridge_cdr) {
         ast_copy_string(bridge_cdr->lastapp, savelastapp, sizeof(bridge_cdr->lastapp));
         ast_copy_string(bridge_cdr->lastdata, savelastdata, sizeof(bridge_cdr->lastdata));
      }
      ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
   }
   
   /* obey the NoCDR() wishes. -- move the DISABLED flag to the bridge CDR if it was set on the channel during the bridge... */
   new_chan_cdr = pick_unlocked_cdr(chan->cdr); /* the proper chan cdr, if there are forked cdrs */
   if (bridge_cdr && new_chan_cdr && ast_test_flag(new_chan_cdr, AST_CDR_FLAG_POST_DISABLED))
      ast_set_flag(bridge_cdr, AST_CDR_FLAG_POST_DISABLED);

   /* we can post the bridge CDR at this point */
   if (bridge_cdr) {
      ast_cdr_end(bridge_cdr);
      ast_cdr_detach(bridge_cdr);
   }
   
   /* do a specialized reset on the beginning channel
      CDR's, if they still exist, so as not to mess up
      issues in future bridges;
      
      Here are the rules of the game:
      1. The chan and peer channel pointers will not change
         during the life of the bridge.
      2. But, in transfers, the channel names will change.
         between the time the bridge is started, and the
         time the channel ends. 
         Usually, when a channel changes names, it will
         also change CDR pointers.
      3. Usually, only one of the two channels (chan or peer)
         will change names.
      4. Usually, if a channel changes names during a bridge,
         it is because of a transfer. Usually, in these situations,
         it is normal to see 2 bridges running simultaneously, and
         it is not unusual to see the two channels that change
         swapped between bridges.
      5. After a bridge occurs, we have 2 or 3 channels' CDRs
         to attend to; if the chan or peer changed names,
         we have the before and after attached CDR's.
   */
   
   if (new_chan_cdr) {
      struct ast_channel *chan_ptr = NULL;
 
      if (strcasecmp(orig_channame, chan->name) != 0) { 
         /* old channel */
         chan_ptr = ast_get_channel_by_name_locked(orig_channame);
         if (chan_ptr) {
            if (!ast_bridged_channel(chan_ptr)) {
               struct ast_cdr *cur;
               for (cur = chan_ptr->cdr; cur; cur = cur->next) {
                  if (cur == chan_cdr) {
                     break;
                  }
               }
               if (cur)
                  ast_cdr_specialized_reset(chan_cdr,0);
            }
            ast_channel_unlock(chan_ptr);
         }
         /* new channel */
         ast_cdr_specialized_reset(new_chan_cdr,0);
      } else {
         ast_cdr_specialized_reset(chan->cdr,0); /* nothing changed, reset the chan cdr  */
      }
   }
   
   {
      struct ast_channel *chan_ptr = NULL;
      new_peer_cdr = pick_unlocked_cdr(peer->cdr); /* the proper chan cdr, if there are forked cdrs */
      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))
         ast_set_flag(new_peer_cdr, AST_CDR_FLAG_POST_DISABLED); /* DISABLED is viral-- it will propagate across a bridge */
      if (strcasecmp(orig_peername, peer->name) != 0) { 
         /* old channel */
         chan_ptr = ast_get_channel_by_name_locked(orig_peername);
         if (chan_ptr) {
            if (!ast_bridged_channel(chan_ptr)) {
               struct ast_cdr *cur;
               for (cur = chan_ptr->cdr; cur; cur = cur->next) {
                  if (cur == peer_cdr) {
                     break;
                  }
               }
               if (cur)
                  ast_cdr_specialized_reset(peer_cdr,0);
            }
            ast_channel_unlock(chan_ptr);
         }
         /* new channel */
         if (new_peer_cdr) {
            ast_cdr_specialized_reset(new_peer_cdr, 0);
         }
      } else {
         ast_cdr_specialized_reset(peer->cdr, 0); /* nothing changed, reset the peer cdr  */
      }
   }
   
   return res;
}
int ast_features_reload ( void  )

Reload call features from features.conf.

Definition at line 4500 of file features.c.

References load_config().

Referenced by handle_features_reload().

{
   int res;
   /* Release parking lot list */
   //ASTOBJ_CONTAINER_MARKALL(&parkinglots);
   // TODO: I don't think any marking is necessary

   /* Reload configuration */
   res = load_config();
   
   //ASTOBJ_CONTAINER_PRUNE_MARKED(&parkinglots, parkinglot_destroy);
   return res;
}
struct ast_call_feature* ast_find_call_feature ( const char *  name) [read]

look for a call feature entry by its sname

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

Definition at line 2117 of file features.c.

References FEATURES_COUNT, and ast_call_feature::sname.

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

{
   int x;
   for (x = 0; x < FEATURES_COUNT; x++) {
      if (!strcasecmp(name, builtin_features[x].sname))
         return &builtin_features[x];
   }
   return NULL;
}
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:
rchanthe real channel to be parked
hostthe channel to have the parking read to.
timeoutis a timeout in milliseconds
extoutis 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:
0on success.
-1on 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().

{
   return masq_park_call(rchan, peer, timeout, extout, 0, NULL);
}
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:
chanthe channel to actually be parked
hostthe channel which will have the parked location read to.
timeoutis a timeout in milliseconds
extoutis 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:
0on success.
-1on failure.

Definition at line 992 of file features.c.

References ast_park_call_args::extout, park_call_full(), and ast_park_call_args::timeout.

Referenced by iax_park_thread(), and sip_park_thread().

{
   struct ast_park_call_args args = {
      .timeout = timeout,
      .extout = extout,
   };

   return park_call_full(chan, peer, &args);
}
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().

{
   return parking_ext;
}
int ast_pickup_call ( struct ast_channel chan)

Pickup a call.

Parameters:
chanchannel 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 4897 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().

{
   struct ast_channel *cur = ast_channel_search_locked(find_channel_by_group, chan);

   if (cur) {
      int res = -1;
      ast_debug(1, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
      res = ast_answer(chan);
      if (res)
         ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
      res = ast_queue_control(chan, AST_CONTROL_ANSWER);
      if (res)
         ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan->name);
      res = ast_channel_masquerade(cur, chan);
      if (res)
         ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name);     /* Done */
      if (!ast_strlen_zero(pickupsound)) {
         ast_stream_and_wait(cur, pickupsound, "");
      }
      ast_channel_unlock(cur);
      return res;
   } else   {
      ast_debug(1, "No call pickup possible...\n");
      if (!ast_strlen_zero(pickupfailsound)) {
         ast_stream_and_wait(chan, pickupfailsound, "");
      }
   }
   return -1;
}
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().

{
   return pickup_ext;
}
void ast_rdlock_call_features ( void  )

Definition at line 2107 of file features.c.

References ast_rwlock_rdlock(), and features_lock.

Referenced by handle_request_info().

void ast_register_feature ( struct ast_call_feature feature)

register new feature into feature_set

Parameters:
featurean 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 1941 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().

{
   if (!feature) {
      ast_log(LOG_NOTICE,"You didn't pass a feature!\n");
      return;
   }
  
   AST_RWLIST_WRLOCK(&feature_list);
   AST_RWLIST_INSERT_HEAD(&feature_list,feature,feature_entry);
   AST_RWLIST_UNLOCK(&feature_list);

   ast_verb(2, "Registered Feature '%s'\n",feature->sname);
}
void ast_unlock_call_features ( void  )

Definition at line 2112 of file features.c.

References ast_rwlock_unlock(), and features_lock.

Referenced by handle_request_info().

void ast_unregister_feature ( struct ast_call_feature feature)

unregister feature from feature_set

Parameters:
featurethe ast_call_feature object which was registered before

Definition at line 2031 of file features.c.

References ast_free, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

{
   if (!feature) {
      return;
   }

   AST_RWLIST_WRLOCK(&feature_list);
   AST_RWLIST_REMOVE(&feature_list, feature, feature_entry);
   AST_RWLIST_UNLOCK(&feature_list);

   ast_free(feature);
}