Thu Aug 30 20:44:31 2012

Asterisk developer's documentation


features.c File Reference

Routines implementing call features as call pickup, parking and transfer. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include <pthread.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <netinet/in.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/causes.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/app.h"
#include "asterisk/say.h"
#include "asterisk/features.h"
#include "asterisk/musiconhold.h"
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/utils.h"
#include "asterisk/adsi.h"
#include "asterisk/devicestate.h"
#include "asterisk/monitor.h"
#include "asterisk/audiohook.h"
#include "asterisk/global_datastores.h"
#include "asterisk/astobj2.h"
#include "asterisk/cel.h"
#include "asterisk/test.h"
Include dependency graph for features.c:

Go to the source code of this file.

Data Structures

struct  ast_bridge_thread_obj
struct  ast_dial_features
struct  ast_park_call_args
struct  ast_parkinglot
 Structure for parking lots which are put in a container. More...
struct  feature_group
struct  feature_group_exten
struct  feature_groups
struct  feature_list
struct  park_app_args
struct  parkeduser
 Description of one parked call, added to a list while active, then removed. The list belongs to a parkinglot. More...
struct  parking_dp_context
struct  parking_dp_map
struct  parking_dp_ramp
struct  parking_dp_ramp_map
struct  parking_dp_space_map
struct  parking_dp_spaces
struct  parkinglot_cfg
struct  parkinglot_parklist

Defines

#define AST_MAX_WATCHERS   256
#define DEFAULT_ATXFER_CALLBACK_RETRIES   2
#define DEFAULT_ATXFER_DROP_CALL   0
#define DEFAULT_ATXFER_LOOP_DELAY   10000
#define DEFAULT_FEATURE_DIGIT_TIMEOUT   1000
#define DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER   15000
#define DEFAULT_PARK_EXTENSION   "700"
#define DEFAULT_PARK_TIME   45000
#define DEFAULT_TRANSFER_DIGIT_TIMEOUT   3000
#define FEATURES_COUNT   ARRAY_LEN(builtin_features)
#define HFS_FORMAT   "%-25s %-7s %-7s\n"
#define MAX_DIAL_FEATURE_OPTIONS   30

Enumerations

enum  {
  BRIDGE_OPT_PLAYTONE = (1 << 0), OPT_CALLEE_HANGUP = (1 << 1), OPT_CALLER_HANGUP = (1 << 2), OPT_DURATION_LIMIT = (1 << 3),
  OPT_DURATION_STOP = (1 << 4), OPT_CALLEE_TRANSFER = (1 << 5), OPT_CALLER_TRANSFER = (1 << 6), OPT_CALLEE_MONITOR = (1 << 7),
  OPT_CALLER_MONITOR = (1 << 8), OPT_CALLEE_PARK = (1 << 9), OPT_CALLER_PARK = (1 << 10), OPT_CALLEE_KILL = (1 << 11)
}
enum  { OPT_ARG_DURATION_LIMIT = 0, OPT_ARG_DURATION_STOP, OPT_ARG_ARRAY_SIZE }
enum  ast_park_call_options { AST_PARK_OPT_RINGING = (1 << 0), AST_PARK_OPT_RANDOMIZE = (1 << 1), AST_PARK_OPT_SILENCE = (1 << 2) }
enum  feature_interpret_op { FEATURE_INTERPRET_DETECT, FEATURE_INTERPRET_DO, FEATURE_INTERPRET_CHECK }

Functions

static int action_bridge (struct mansession *s, const struct message *m)
 Bridge channels together.
static int add_features_datastore (struct ast_channel *chan, const struct ast_flags *my_features, const struct ast_flags *peer_features)
static void add_features_datastores (struct ast_channel *caller, struct ast_channel *callee, struct ast_bridge_config *config)
static int adsi_announce_park (struct ast_channel *chan, char *parkingexten)
 Announce call parking by ADSI.
int ast_bridge_call (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
 bridge the call and set CDR
int ast_bridge_timelimit (struct ast_channel *chan, struct ast_bridge_config *config, char *parse, struct timeval *calldurationlimit)
 parse L option and read associated channel variables to set warning, warning frequency, and timelimit
int ast_can_pickup (struct ast_channel *chan)
 Test if a channel can be picked up.
void ast_channel_log (char *title, struct ast_channel *chan)
int ast_do_pickup (struct ast_channel *chan, struct ast_channel *target)
 Pickup a call target.
int ast_feature_detect (struct ast_channel *chan, struct ast_flags *features, const char *code, struct ast_call_feature *feature)
 detect a feature before bridging
int ast_features_init (void)
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 *peer, int timeout, int *extout)
 Park a call via a masqueraded channel.
int ast_masq_park_call_exten (struct ast_channel *park_me, struct ast_channel *parker, const char *park_exten, const char *park_context, int timeout, int *extout)
 Park a call via a masqueraded channel.
int ast_park_call (struct ast_channel *park_me, struct ast_channel *parker, int timeout, const char *park_exten, int *extout)
 Park a call and read back parked location.
int ast_park_call_exten (struct ast_channel *park_me, struct ast_channel *parker, const char *park_exten, const char *park_context, int timeout, int *extout)
 Park a call and read back parked location.
int ast_parking_ext_valid (const char *exten_str, struct ast_channel *chan, const char *context)
 Determine if parking extension exists in a given context.
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_list
void ast_unlock_call_features (void)
void ast_unregister_feature (struct ast_call_feature *feature)
 unregister feature from feature_set
static void ast_unregister_features (void)
 Remove all features in the list.
static void ast_unregister_groups (void)
 Remove all feature groups in the list.
static void atxfer_fail_cleanup (struct ast_channel *transferee, struct ast_channel *transferer, struct ast_party_connected_line *connected_line)
static void * bridge_call_thread (void *data)
 bridge the call
static void bridge_call_thread_launch (struct ast_bridge_thread_obj *data)
 create thread for the parked call
static int bridge_exec (struct ast_channel *chan, const char *data)
 Bridge channels.
static struct parking_dp_context * build_dialplan_useage_context (struct ast_parkinglot *lot)
static int build_dialplan_useage_map (struct parking_dp_map *usage_map, int complain)
static struct parking_dp_ramp * build_dialplan_useage_ramp (const char *exten, int exclusive)
static struct parking_dp_spaces * build_dialplan_useage_spaces (int start, int stop)
static struct ast_parkinglot * build_parkinglot (const char *pl_name, struct ast_variable *var)
 Build parkinglot from configuration and chain it in if it doesn't already exist.
static int builtin_atxfer (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
 Attended transfer.
static int builtin_automixmonitor (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
static int builtin_automonitor (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
 Monitor a channel by DTMF.
static int builtin_blindtransfer (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
 Blind transfer user to another extension.
static int builtin_disconnect (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
static int builtin_parkcall (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
 support routing for one touch call parking
static char * callback_dialoptions (struct ast_flags *features_callee, struct ast_flags *features_caller, char *options, size_t len)
static int check_compat (struct ast_channel *c, struct ast_channel *newchan)
 make channels compatible
static void check_goto_on_transfer (struct ast_channel *chan)
 Check goto on transfer.
static void clear_dialed_interfaces (struct ast_channel *chan)
static struct ast_parkinglot * copy_parkinglot (const char *name, const struct ast_parkinglot *parkinglot)
 Copy parkinglot and store it with new name.
static struct ast_parkinglot * create_dynamic_parkinglot (const char *name, struct ast_channel *chan)
static struct ast_parkinglot * create_parkinglot (const char *name)
 Allocate parking lot structure.
static void destroy_dialplan_usage_context (struct parking_dp_context *doomed)
static void destroy_dialplan_usage_map (struct parking_dp_map *doomed)
static void destroy_space (const char *context, int space)
static void dial_features_destroy (void *data)
static void * dial_features_duplicate (void *data)
static int dialplan_usage_add_parkinglot (struct parking_dp_map *usage_map, struct ast_parkinglot *lot, int complain)
static int dialplan_usage_add_parkinglot_data (struct parking_dp_context *ctx_node, struct ast_parkinglot *lot, int complain)
static int do_bridge_masquerade (struct ast_channel *chan, struct ast_channel *tmpchan)
 Actual bridge.
static void * do_parking_thread (void *ignore)
 Take care of parked calls and unpark them if needed.
static int feature_check (struct ast_channel *chan, struct ast_flags *features, char *code)
 Check if a feature exists.
static int feature_exec_app (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, void *data)
 exec an app by feature
static int feature_interpret (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense)
 Check the dynamic features.
static int feature_interpret_helper (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense, char *dynamic_features_buf, struct ast_flags *features, feature_interpret_op operation, struct ast_call_feature *feature)
 Helper function for feature_interpret and ast_feature_detect.
static struct ast_channel * feature_request_and_dial (struct ast_channel *caller, const char *caller_name, struct ast_channel *requestor, struct ast_channel *transferee, const char *type, format_t format, void *data, int timeout, int *outstate, const char *language)
static int find_channel_by_group (void *obj, void *arg, void *data, int flags)
static struct ast_call_feature * find_dynamic_feature (const char *name)
 find a call feature by name
static struct feature_group * find_group (const char *name)
 Find a group by name.
static struct ast_parkinglot * find_parkinglot (const char *name)
 Find parkinglot by name.
static const char * findparkinglotname (struct ast_channel *chan)
 Find parking lot name from channel.
static int finishup (struct ast_channel *chan)
static struct ast_exten * get_parking_exten (const char *exten_str, struct ast_channel *chan, const char *context)
static char * handle_feature_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to list configured features.
static char * handle_features_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_parkedcalls (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to list parked calls.
static int load_config (int reload)
static int manage_parked_call (struct parkeduser *pu, const struct pollfd *pfds, int nfds, struct pollfd **new_pfds, int *new_nfds, int *ms)
static void manage_parkinglot (struct ast_parkinglot *curlot, const struct pollfd *pfds, int nfds, struct pollfd **new_pfds, int *new_nfds, int *ms)
 Run management on parkinglots, called once per parkinglot.
static int manager_park (struct mansession *s, const struct message *m)
 Create manager event for parked calls.
static int manager_parking_status (struct mansession *s, const struct message *m)
 Dump parking lot status.
static int masq_park_call (struct ast_channel *rchan, struct ast_channel *peer, struct ast_park_call_args *args)
 Park call via masqueraded channel and announce parking spot on peer channel.
static enum ast_device_state metermaidstate (const char *data)
 metermaids callback from devicestate.c
static void notify_metermaids (const char *exten, char *context, enum ast_device_state state)
 Notify metermaids that we've changed an extension.
static void park_add_hints (const char *context, int start, int stop)
 Add parking hints for all defined parking spaces.
static int park_call_exec (struct ast_channel *chan, const char *data)
 Park a call.
static int park_call_full (struct ast_channel *chan, struct ast_channel *peer, struct ast_park_call_args *args)
static void park_space_abort (struct parkeduser *pu)
static struct parkeduser * park_space_reserve (struct ast_channel *park_me, struct ast_channel *parker, struct ast_park_call_args *args)
static int parked_call_exec (struct ast_channel *chan, const char *data)
 Pickup parked call.
static int parkinglot_activate (struct ast_parkinglot *parkinglot)
static int parkinglot_activate_cb (void *obj, void *arg, int flags)
static struct ast_parkinglot * parkinglot_addref (struct ast_parkinglot *parkinglot)
static int parkinglot_cmp_cb (void *obj, void *arg, int flags)
static int parkinglot_config_read (const char *pl_name, struct parkinglot_cfg *cfg, struct ast_variable *var)
static void parkinglot_destroy (void *obj)
 Destroy a parking lot.
static void parkinglot_feature_flag_cfg (const char *pl_name, int *param, struct ast_variable *var)
static int parkinglot_hash_cb (const void *obj, const int flags)
static int parkinglot_is_marked_cb (void *obj, void *arg, int flags)
static int parkinglot_markall_cb (void *obj, void *arg, int flags)
static void parkinglot_unref (struct ast_parkinglot *parkinglot)
 Unreference parkinglot object.
static struct ast_cdr * pick_unlocked_cdr (struct ast_cdr *cdr)
 return the first unlocked cdr in a possible chain
static int play_message_in_bridged_call (struct ast_channel *caller_chan, struct ast_channel *callee_chan, const char *audiofile)
 Play message to both caller and callee in bridged call, plays synchronously, autoservicing the other channel during the message, so please don't use this for very long messages.
static int play_message_on_chan (struct ast_channel *play_to, struct ast_channel *other, const char *msg, const char *audiofile)
static int play_message_to_chans (struct ast_channel *left, struct ast_channel *right, int which, const char *msg, const char *audiofile)
static void post_manager_event (const char *s, struct parkeduser *pu)
 Output parking event to manager.
static void process_applicationmap_line (struct ast_variable *var)
static int process_config (struct ast_config *cfg)
static const char * real_ctx (struct ast_channel *transferer, struct ast_channel *transferee)
 Find the context for the transfer.
static struct feature_group * register_group (const char *fgname)
 Add new feature group.
static void register_group_feature (struct feature_group *fg, const char *exten, struct ast_call_feature *feature)
 Add feature to group.
static int remap_feature (const char *name, const char *value)
static void remove_dead_context_usage (const char *context, struct parking_dp_context *old_ctx, struct parking_dp_context *new_ctx)
static void remove_dead_dialplan_useage (struct parking_dp_map *old_map, struct parking_dp_map *new_map)
static void remove_dead_ramp_usage (const char *context, struct parking_dp_ramp_map *old_ramps, struct parking_dp_ramp_map *new_ramps)
static void remove_dead_spaces_usage (const char *context, struct parking_dp_space_map *old_spaces, struct parking_dp_space_map *new_spaces, void(*destroy_space)(const char *context, int space))
static void remove_exten_if_exist (const char *context, const char *exten, int priority)
static void set_bridge_features_on_config (struct ast_bridge_config *config, const char *features)
static void set_c_e_p (struct ast_channel *chan, const char *context, const char *ext, int pri)
 store context, extension and priority
static void set_config_flags (struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
static void set_peers (struct ast_channel **caller, struct ast_channel **callee, struct ast_channel *peer, struct ast_channel *chan, int sense)
 set caller and callee according to the direction
static void unmap_features (void)
static int usage_context_add_ramp (struct parking_dp_ramp_map *ramp_map, const char *exten, int exclusive, struct ast_parkinglot *lot, int complain)
static int usage_context_add_spaces (struct parking_dp_space_map *space_map, int start, int stop, struct ast_parkinglot *lot, int complain)
static int xfer_park_call_helper (struct ast_channel *park_me, struct ast_channel *parker, struct ast_exten *park_exten)

Variables

static int adsipark
static char * app_bridge = "Bridge"
static unsigned int atxfercallbackretries
static unsigned int atxferdropcall
static unsigned int atxferloopdelay
static int atxfernoanswertimeout
static struct ast_app_option bridge_exec_options [128] = { [ 'p' ] = { .flag = BRIDGE_OPT_PLAYTONE }, [ 'h' ] = { .flag = OPT_CALLEE_HANGUP }, [ 'H' ] = { .flag = OPT_CALLER_HANGUP }, [ 'k' ] = { .flag = OPT_CALLEE_PARK }, [ 'K' ] = { .flag = OPT_CALLER_PARK }, [ 'L' ] = { .flag = OPT_DURATION_LIMIT , .arg_index = OPT_ARG_DURATION_LIMIT + 1 }, [ 'S' ] = { .flag = OPT_DURATION_STOP , .arg_index = OPT_ARG_DURATION_STOP + 1 }, [ 't' ] = { .flag = OPT_CALLEE_TRANSFER }, [ 'T' ] = { .flag = OPT_CALLER_TRANSFER }, [ 'w' ] = { .flag = OPT_CALLEE_MONITOR }, [ 'W' ] = { .flag = OPT_CALLER_MONITOR }, [ 'x' ] = { .flag = OPT_CALLEE_KILL }, }
static struct ast_call_feature builtin_features []
static struct ast_cli_entry cli_features []
static int comebacktoorigin = 1
static char courtesytone [256]
static struct ast_parkinglot * default_parkinglot
 Default parking lot.
static struct ast_datastore_info dial_features_info
static int featuredigittimeout
static ast_rwlock_t features_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, 1 }
static ast_mutex_t features_reload_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
static int force_reload_load
static struct ast_app * mixmonitor_app = NULL
static int mixmonitor_ok = 1
static struct ast_app * monitor_app = NULL
static int monitor_ok = 1
static struct ast_app_option park_call_options [128] = { [ 'r' ] = { .flag = AST_PARK_OPT_RINGING }, [ 'R' ] = { .flag = AST_PARK_OPT_RANDOMIZE }, [ 's' ] = { .flag = AST_PARK_OPT_SILENCE }, }
static const char * parkcall = "Park"
static const char * parkedcall = "ParkedCall"
static int parkeddynamic = 0
static int parkedplay = 0
static char parking_con_dial [] = "park-dial"
 Context for parking dialback to parker.
static pthread_t parking_thread
static struct parkinglot_cfg parkinglot_cfg_default
static struct parkinglot_cfg parkinglot_cfg_default_default
static struct ao2_container * parkinglots
 The configured parking lots container. Always at least one - the default parking lot.
static struct ast_datastore_info pickup_active
static char pickup_ext [AST_MAX_EXTENSION]
static char pickupfailsound [256]
static char pickupsound [256]
static char * registrar = "features"
static struct ast_app * stopmixmonitor_app = NULL
static int stopmixmonitor_ok = 1
static int transferdigittimeout
static char xferfailsound [256]
static char xfersound [256]

Detailed Description

Routines implementing call features as call pickup, parking and transfer.

Author:
Mark Spencer <markster@digium.com>

Definition in file features.c.


Define Documentation

#define AST_MAX_WATCHERS   256

Definition at line 392 of file features.c.

#define DEFAULT_ATXFER_CALLBACK_RETRIES   2

Definition at line 390 of file features.c.

Referenced by process_config().

#define DEFAULT_ATXFER_DROP_CALL   0

Do not drop call.

Definition at line 388 of file features.c.

Referenced by process_config().

#define DEFAULT_ATXFER_LOOP_DELAY   10000

ms

Definition at line 389 of file features.c.

Referenced by process_config().

#define DEFAULT_FEATURE_DIGIT_TIMEOUT   1000

ms

Definition at line 386 of file features.c.

Referenced by process_config().

#define DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER   15000

ms

Definition at line 387 of file features.c.

Referenced by process_config().

#define DEFAULT_PARK_EXTENSION   "700"

Definition at line 384 of file features.c.

#define DEFAULT_PARK_TIME   45000

ms

Definition at line 383 of file features.c.

#define DEFAULT_TRANSFER_DIGIT_TIMEOUT   3000

ms

Definition at line 385 of file features.c.

Referenced by process_config().

#define FEATURES_COUNT   ARRAY_LEN(builtin_features)
#define HFS_FORMAT   "%-25s %-7s %-7s\n"

Referenced by handle_feature_show().

#define MAX_DIAL_FEATURE_OPTIONS   30

Definition at line 393 of file features.c.

Referenced by manage_parked_call().


Enumeration Type Documentation

anonymous enum
Enumerator:
BRIDGE_OPT_PLAYTONE 
OPT_CALLEE_HANGUP 
OPT_CALLER_HANGUP 
OPT_DURATION_LIMIT 
OPT_DURATION_STOP 
OPT_CALLEE_TRANSFER 
OPT_CALLER_TRANSFER 
OPT_CALLEE_MONITOR 
OPT_CALLER_MONITOR 
OPT_CALLEE_PARK 
OPT_CALLER_PARK 
OPT_CALLEE_KILL 

Definition at line 7376 of file features.c.

07376      {
07377    BRIDGE_OPT_PLAYTONE = (1 << 0),
07378    OPT_CALLEE_HANGUP =  (1 << 1),
07379    OPT_CALLER_HANGUP =  (1 << 2),
07380    OPT_DURATION_LIMIT = (1 << 3),
07381    OPT_DURATION_STOP =  (1 << 4),
07382    OPT_CALLEE_TRANSFER = (1 << 5),
07383    OPT_CALLER_TRANSFER = (1 << 6),
07384    OPT_CALLEE_MONITOR = (1 << 7),
07385    OPT_CALLER_MONITOR = (1 << 8),
07386    OPT_CALLEE_PARK = (1 << 9),
07387    OPT_CALLER_PARK = (1 << 10),
07388    OPT_CALLEE_KILL = (1 << 11),
07389 };

anonymous enum
Enumerator:
OPT_ARG_DURATION_LIMIT 
OPT_ARG_DURATION_STOP 
OPT_ARG_ARRAY_SIZE 

Definition at line 7391 of file features.c.

07391      {
07392    OPT_ARG_DURATION_LIMIT = 0,
07393    OPT_ARG_DURATION_STOP,
07394    /* note: this entry _MUST_ be the last one in the enum */
07395    OPT_ARG_ARRAY_SIZE,
07396 };

Options to pass to park_call_full

Enumerator:
AST_PARK_OPT_RINGING 

Provide ringing to the parked caller instead of music on hold

AST_PARK_OPT_RANDOMIZE 

Randomly choose a parking spot for the caller instead of choosing the first one that is available.

AST_PARK_OPT_SILENCE 

Do not announce the parking number

Definition at line 1090 of file features.c.

01090                            {
01091    /*! Provide ringing to the parked caller instead of music on hold */
01092    AST_PARK_OPT_RINGING =   (1 << 0),
01093    /*! Randomly choose a parking spot for the caller instead of choosing
01094     *  the first one that is available. */
01095    AST_PARK_OPT_RANDOMIZE = (1 << 1),
01096    /*! Do not announce the parking number */
01097    AST_PARK_OPT_SILENCE = (1 << 2),
01098 };

Enumerator:
FEATURE_INTERPRET_DETECT 
FEATURE_INTERPRET_DO 
FEATURE_INTERPRET_CHECK 

Definition at line 413 of file features.c.

00413              {
00414    FEATURE_INTERPRET_DETECT, /* Used by ast_feature_detect */
00415    FEATURE_INTERPRET_DO,     /* Used by feature_interpret */
00416    FEATURE_INTERPRET_CHECK,  /* Used by feature_check */
00417 } feature_interpret_op;


Function Documentation

static int action_bridge ( struct mansession *  s,
const struct message *  m 
) [static]

Bridge channels together.

Parameters:
s 
m Make sure valid channels were specified, send errors if any of the channels could not be found/locked, answer channels if needed, create the placeholder channels and grab the other channels make the channels compatible, send error if we fail doing so setup the bridge thread object and start the bridge.
Return values:
0 

Definition at line 6856 of file features.c.

References ast_channel::_state, ast_answer(), ast_calloc, ast_channel_alloc, ast_channel_get_by_name_prefix(), ast_channel_make_compatible(), ast_channel_unref, ast_hangup(), ast_log(), ast_manager_event_multichan, AST_STATE_DOWN, AST_STATE_UP, ast_streamfile(), ast_strlen_zero(), ast_true(), ast_waitstream(), astman_get_header(), astman_send_ack(), astman_send_error(), bridge_call_thread_launch(), ast_bridge_thread_obj::chan, do_bridge_masquerade(), errno, EVENT_FLAG_CALL, LOG_WARNING, ast_bridge_thread_obj::peer, playtone(), ast_bridge_thread_obj::return_to_pbx, and xfersound.

Referenced by ast_features_init().

06857 {
06858    const char *channela = astman_get_header(m, "Channel1");
06859    const char *channelb = astman_get_header(m, "Channel2");
06860    const char *playtone = astman_get_header(m, "Tone");
06861    struct ast_channel *chana = NULL, *chanb = NULL, *chans[2];
06862    struct ast_channel *tmpchana = NULL, *tmpchanb = NULL;
06863    struct ast_bridge_thread_obj *tobj = NULL;
06864    char buf[256];
06865 
06866    /* make sure valid channels were specified */
06867    if (ast_strlen_zero(channela) || ast_strlen_zero(channelb)) {
06868       astman_send_error(s, m, "Missing channel parameter in request");
06869       return 0;
06870    }
06871 
06872    /* Start with chana */
06873    chana = ast_channel_get_by_name_prefix(channela, strlen(channela));
06874    if (!chana) {
06875       snprintf(buf, sizeof(buf), "Channel1 does not exists: %s", channela);
06876       astman_send_error(s, m, buf);
06877       return 0;
06878    }
06879 
06880    /* Answer the channels if needed */
06881    if (chana->_state != AST_STATE_UP)
06882       ast_answer(chana);
06883 
06884    /* create the placeholder channels and grab the other channels */
06885    if (!(tmpchana = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, 
06886       NULL, NULL, chana->linkedid, 0, "Bridge/%s", chana->name))) {
06887       astman_send_error(s, m, "Unable to create temporary channel!");
06888       chana = ast_channel_unref(chana);
06889       return 0;
06890    }
06891 
06892    if (do_bridge_masquerade(chana, tmpchana)) {
06893       snprintf(buf, sizeof(buf), "Unable to masquerade channel %s!", channela);
06894       astman_send_error(s, m, buf);
06895       ast_hangup(tmpchana);
06896       chana = ast_channel_unref(chana);
06897       return 0;
06898    }
06899 
06900    chana = ast_channel_unref(chana);
06901 
06902    /* now do chanb */
06903    chanb = ast_channel_get_by_name_prefix(channelb, strlen(channelb));
06904    if (!chanb) {
06905       snprintf(buf, sizeof(buf), "Channel2 does not exists: %s", channelb);
06906       astman_send_error(s, m, buf);
06907       ast_hangup(tmpchana);
06908       return 0;
06909    }
06910 
06911    /* Answer the channels if needed */
06912    if (chanb->_state != AST_STATE_UP)
06913       ast_answer(chanb);
06914 
06915    /* create the placeholder channels and grab the other channels */
06916    if (!(tmpchanb = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, 
06917       NULL, NULL, chanb->linkedid, 0, "Bridge/%s", chanb->name))) {
06918       astman_send_error(s, m, "Unable to create temporary channels!");
06919       ast_hangup(tmpchana);
06920       chanb = ast_channel_unref(chanb);
06921       return 0;
06922    }
06923 
06924    if (do_bridge_masquerade(chanb, tmpchanb)) {
06925       snprintf(buf, sizeof(buf), "Unable to masquerade channel %s!", channelb);
06926       astman_send_error(s, m, buf);
06927       ast_hangup(tmpchana);
06928       ast_hangup(tmpchanb);
06929       chanb = ast_channel_unref(chanb);
06930       return 0;
06931    }
06932 
06933    chanb = ast_channel_unref(chanb);
06934 
06935    /* make the channels compatible, send error if we fail doing so */
06936    if (ast_channel_make_compatible(tmpchana, tmpchanb)) {
06937       ast_log(LOG_WARNING, "Could not make channels %s and %s compatible for manager bridge\n", tmpchana->name, tmpchanb->name);
06938       astman_send_error(s, m, "Could not make channels compatible for manager bridge");
06939       ast_hangup(tmpchana);
06940       ast_hangup(tmpchanb);
06941       return 0;
06942    }
06943 
06944    /* setup the bridge thread object and start the bridge */
06945    if (!(tobj = ast_calloc(1, sizeof(*tobj)))) {
06946       ast_log(LOG_WARNING, "Unable to spawn a new bridge thread on %s and %s: %s\n", tmpchana->name, tmpchanb->name, strerror(errno));
06947       astman_send_error(s, m, "Unable to spawn a new bridge thread");
06948       ast_hangup(tmpchana);
06949       ast_hangup(tmpchanb);
06950       return 0;
06951    }
06952 
06953    tobj->chan = tmpchana;
06954    tobj->peer = tmpchanb;
06955    tobj->return_to_pbx = 1;
06956 
06957    if (ast_true(playtone)) {
06958       if (!ast_strlen_zero(xfersound) && !ast_streamfile(tmpchanb, xfersound, tmpchanb->language)) {
06959          if (ast_waitstream(tmpchanb, "") < 0)
06960             ast_log(LOG_WARNING, "Failed to play a courtesy tone on chan %s\n", tmpchanb->name);
06961       }
06962    }
06963 
06964    chans[0] = tmpchana;
06965    chans[1] = tmpchanb;
06966 
06967    ast_manager_event_multichan(EVENT_FLAG_CALL, "BridgeAction", 2, chans,
06968             "Response: Success\r\n"
06969             "Channel1: %s\r\n"
06970             "Channel2: %s\r\n", tmpchana->name, tmpchanb->name);
06971 
06972    bridge_call_thread_launch(tobj);
06973 
06974    astman_send_ack(s, m, "Launched bridge thread with success");
06975 
06976    return 0;
06977 }

static int add_features_datastore ( struct ast_channel *  chan,
const struct ast_flags *  my_features,
const struct ast_flags *  peer_features 
) [static]

Definition at line 764 of file features.c.

References ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_copy_flags, ast_datastore_alloc, ast_datastore_free(), AST_FLAGS_ALL, ast_log(), ast_datastore::data, DATASTORE_INHERIT_FOREVER, dial_features_info, ast_datastore::inheritance, LOG_WARNING, ast_dial_features::my_features, and ast_dial_features::peer_features.

Referenced by add_features_datastores(), and builtin_atxfer().

00765 {
00766    struct ast_datastore *datastore;
00767    struct ast_dial_features *dialfeatures;
00768 
00769    ast_channel_lock(chan);
00770    datastore = ast_channel_datastore_find(chan, &dial_features_info, NULL);
00771    ast_channel_unlock(chan);
00772    if (datastore) {
00773       /* Already exists. */
00774       return 1;
00775    }
00776 
00777    /* Create a new datastore with specified feature flags. */
00778    datastore = ast_datastore_alloc(&dial_features_info, NULL);
00779    if (!datastore) {
00780       ast_log(LOG_WARNING, "Unable to create channel features datastore.\n");
00781       return 0;
00782    }
00783    dialfeatures = ast_calloc(1, sizeof(*dialfeatures));
00784    if (!dialfeatures) {
00785       ast_log(LOG_WARNING, "Unable to allocate memory for feature flags.\n");
00786       ast_datastore_free(datastore);
00787       return 0;
00788    }
00789    ast_copy_flags(&dialfeatures->my_features, my_features, AST_FLAGS_ALL);
00790    ast_copy_flags(&dialfeatures->peer_features, peer_features, AST_FLAGS_ALL);
00791    datastore->inheritance = DATASTORE_INHERIT_FOREVER;
00792    datastore->data = dialfeatures;
00793    ast_channel_lock(chan);
00794    ast_channel_datastore_add(chan, datastore);
00795    ast_channel_unlock(chan);
00796    return 0;
00797 }

static void add_features_datastores ( struct ast_channel *  caller,
struct ast_channel *  callee,
struct ast_bridge_config *  config 
) [static]

Definition at line 3833 of file features.c.

References add_features_datastore(), ast_bridge_config::features_callee, and ast_bridge_config::features_caller.

Referenced by ast_bridge_call().

03834 {
03835    if (add_features_datastore(caller, &config->features_caller, &config->features_callee)) {
03836       /*
03837        * If we don't return here, then when we do a builtin_atxfer we
03838        * will copy the disconnect flags over from the atxfer to the
03839        * callee (Party C).
03840        */
03841       return;
03842    }
03843 
03844    add_features_datastore(callee, &config->features_callee, &config->features_caller);
03845 }

static int adsi_announce_park ( struct ast_channel *  chan,
char *  parkingexten 
) [static]

Announce call parking by ADSI.

Parameters:
chan .
parkingexten . Create message to show for ADSI, display message.
Return values:
0 on success.
-1 on failure.

Definition at line 1028 of file features.c.

References ADSI_JUST_CENT, ast_adsi_load_session(), ast_adsi_print(), and justify.

Referenced by park_call_full().

01029 {
01030    int res;
01031    int justify[5] = {ADSI_JUST_CENT, ADSI_JUST_CENT, ADSI_JUST_CENT, ADSI_JUST_CENT};
01032    char tmp[256];
01033    char *message[5] = {NULL, NULL, NULL, NULL, NULL};
01034 
01035    snprintf(tmp, sizeof(tmp), "Parked on %s", parkingexten);
01036    message[0] = tmp;
01037    res = ast_adsi_load_session(chan, NULL, 0, 1);
01038    if (res == -1)
01039       return res;
01040    return ast_adsi_print(chan, message, justify, 1);
01041 }

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

bridge the call and set CDR

Bridge a call, optionally allowing redirection.

Parameters:
chan The bridge considers this channel the caller.
peer The bridge considers this channel the callee.
config Configuration for this bridge.

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

References ast_channel::_softhangup, ast_channel::_state, ast_cdr::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_appenduserfield(), ast_cdr_copy_vars(), ast_cdr_detach(), ast_cdr_discard(), ast_cdr_dup_unique_swap(), 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_setuserfield(), ast_cdr_specialized_reset(), ast_cdr_start(), ast_cdr_update(), AST_CEL_BRIDGE_END, AST_CEL_BRIDGE_START, ast_cel_report_event(), ast_channel_bridge(), ast_channel_connected_line_macro(), ast_channel_get_by_name(), ast_channel_lock, ast_channel_lock_both, ast_channel_log(), AST_CHANNEL_NAME, ast_channel_redirecting_macro(), ast_channel_set_linkgroup(), ast_channel_setoption(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_unlock, ast_channel_unref, ast_check_hangup(), ast_clear_flag, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OPTION, AST_CONTROL_REDIRECTING, 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_RETURN_PASSDIGITS, AST_FEATURE_RETURN_SUCCESS, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_BRIDGE_HANGUP_DONT, AST_FLAG_BRIDGE_HANGUP_RUN, AST_FLAG_IN_AUTOLOOP, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frfree, ast_indicate(), ast_indicate_data(), ast_log(), AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_opt_end_cdr_before_h_exten, ast_opt_transmit_silence, AST_OPTION_AUDIO_MODE, AST_OPTION_DIGIT_DETECT, AST_OPTION_FAX_DETECT, AST_OPTION_FLAG_REQUEST, AST_OPTION_RELAXDTMF, AST_OPTION_TDD, AST_OPTION_TONE_VERIFY, ast_raw_answer(), ast_set2_flag, ast_set_flag, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, AST_SOFTHANGUP_ASYNCGOTO, AST_SOFTHANGUP_UNBRIDGE, 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_write(), ast_channel::caller, ast_channel::cdr, ast_cdr::channel, clear_dialed_interfaces(), 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_channel::exten, f, feature_check(), feature_interpret(), FEATURE_MAX_LEN, FEATURE_SENSE_CHAN, FEATURE_SENSE_PEER, ast_bridge_config::feature_start_time, ast_bridge_config::feature_timer, featuredigittimeout, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_frame::frametype, ast_party_caller::id, ast_frame_subclass::integer, ast_cdr::lastapp, ast_cdr::lastdata, LOG_DEBUG, LOG_WARNING, ast_channel::macrocontext, monitor_app, monitor_ok, ast_cdr::next, ast_party_id::number, option_debug, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), pick_unlocked_cdr(), ast_channel::priority, ast_frame::ptr, S_COR, S_OR, set_bridge_features_on_config(), set_config_flags(), ast_cdr::start, ast_party_number::str, ast_frame::subclass, ast_bridge_config::timelimit, ast_cdr::uniqueid, ast_cdr::userfield, ast_party_number::valid, and ast_channel::visible_indication.

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

03876 {
03877    /* Copy voice back and forth between the two channels.  Give the peer
03878       the ability to transfer calls with '#<extension' syntax. */
03879    struct ast_frame *f;
03880    struct ast_channel *who;
03881    char chan_featurecode[FEATURE_MAX_LEN + 1]="";
03882    char peer_featurecode[FEATURE_MAX_LEN + 1]="";
03883    char orig_channame[AST_CHANNEL_NAME];
03884    char orig_peername[AST_CHANNEL_NAME];
03885    int res;
03886    int diff;
03887    int hasfeatures=0;
03888    int hadfeatures=0;
03889    int autoloopflag;
03890    int sendingdtmfdigit = 0;
03891    int we_disabled_peer_cdr = 0;
03892    struct ast_option_header *aoh;
03893    struct ast_cdr *bridge_cdr = NULL;
03894    struct ast_cdr *chan_cdr = chan->cdr; /* the proper chan cdr, if there are forked cdrs */
03895    struct ast_cdr *peer_cdr = peer->cdr; /* the proper chan cdr, if there are forked cdrs */
03896    struct ast_cdr *new_chan_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
03897    struct ast_cdr *new_peer_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
03898    struct ast_silence_generator *silgen = NULL;
03899    const char *h_context;
03900 
03901    pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
03902    pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
03903 
03904    /* Clear any BLINDTRANSFER since the transfer has completed. */
03905    pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
03906    pbx_builtin_setvar_helper(peer, "BLINDTRANSFER", NULL);
03907 
03908    set_bridge_features_on_config(config, pbx_builtin_getvar_helper(chan, "BRIDGE_FEATURES"));
03909    add_features_datastores(chan, peer, config);
03910 
03911    /* This is an interesting case.  One example is if a ringing channel gets redirected to
03912     * an extension that picks up a parked call.  This will make sure that the call taken
03913     * out of parking gets told that the channel it just got bridged to is still ringing. */
03914    if (chan->_state == AST_STATE_RINGING && peer->visible_indication != AST_CONTROL_RINGING) {
03915       ast_indicate(peer, AST_CONTROL_RINGING);
03916    }
03917 
03918    if (monitor_ok) {
03919       const char *monitor_exec;
03920       struct ast_channel *src = NULL;
03921       if (!monitor_app) {
03922          if (!(monitor_app = pbx_findapp("Monitor")))
03923             monitor_ok=0;
03924       }
03925       if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) 
03926          src = chan;
03927       else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
03928          src = peer;
03929       if (monitor_app && src) {
03930          char *tmp = ast_strdupa(monitor_exec);
03931          pbx_exec(src, monitor_app, tmp);
03932       }
03933    }
03934 
03935    set_config_flags(chan, peer, config);
03936 
03937    /* Answer if need be */
03938    if (chan->_state != AST_STATE_UP) {
03939       if (ast_raw_answer(chan, 1)) {
03940          return -1;
03941       }
03942    }
03943 
03944 #ifdef FOR_DEBUG
03945    /* show the two channels and cdrs involved in the bridge for debug & devel purposes */
03946    ast_channel_log("Pre-bridge CHAN Channel info", chan);
03947    ast_channel_log("Pre-bridge PEER Channel info", peer);
03948 #endif
03949    /* two channels are being marked as linked here */
03950    ast_channel_set_linkgroup(chan,peer);
03951 
03952    /* copy the userfield from the B-leg to A-leg if applicable */
03953    if (chan->cdr && peer->cdr && !ast_strlen_zero(peer->cdr->userfield)) {
03954       char tmp[256];
03955 
03956       ast_channel_lock(chan);
03957       if (!ast_strlen_zero(chan->cdr->userfield)) {
03958          snprintf(tmp, sizeof(tmp), "%s;%s", chan->cdr->userfield, peer->cdr->userfield);
03959          ast_cdr_appenduserfield(chan, tmp);
03960       } else {
03961          ast_cdr_setuserfield(chan, peer->cdr->userfield);
03962       }
03963       ast_channel_unlock(chan);
03964       /* Don't delete the CDR; just disable it. */
03965       ast_set_flag(peer->cdr, AST_CDR_FLAG_POST_DISABLED);
03966       we_disabled_peer_cdr = 1;
03967    }
03968    ast_copy_string(orig_channame,chan->name,sizeof(orig_channame));
03969    ast_copy_string(orig_peername,peer->name,sizeof(orig_peername));
03970 
03971    if (!chan_cdr || (chan_cdr && !ast_test_flag(chan_cdr, AST_CDR_FLAG_POST_DISABLED))) {
03972       ast_channel_lock_both(chan, peer);
03973       if (chan_cdr) {
03974          ast_set_flag(chan_cdr, AST_CDR_FLAG_MAIN);
03975          ast_cdr_update(chan);
03976          bridge_cdr = ast_cdr_dup_unique_swap(chan_cdr);
03977          /* rip any forked CDR's off of the chan_cdr and attach
03978           * them to the bridge_cdr instead */
03979          bridge_cdr->next = chan_cdr->next;
03980          chan_cdr->next = NULL;
03981          ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
03982          ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
03983          if (peer_cdr && !ast_strlen_zero(peer_cdr->userfield)) {
03984             ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
03985          }
03986          ast_cdr_setaccount(peer, chan->accountcode);
03987       } else {
03988          /* better yet, in a xfer situation, find out why the chan cdr got zapped (pun unintentional) */
03989          bridge_cdr = ast_cdr_alloc(); /* this should be really, really rare/impossible? */
03990          ast_copy_string(bridge_cdr->channel, chan->name, sizeof(bridge_cdr->channel));
03991          ast_copy_string(bridge_cdr->dstchannel, peer->name, sizeof(bridge_cdr->dstchannel));
03992          ast_copy_string(bridge_cdr->uniqueid, chan->uniqueid, sizeof(bridge_cdr->uniqueid));
03993          ast_copy_string(bridge_cdr->lastapp, S_OR(chan->appl, ""), sizeof(bridge_cdr->lastapp));
03994          ast_copy_string(bridge_cdr->lastdata, S_OR(chan->data, ""), sizeof(bridge_cdr->lastdata));
03995          ast_cdr_setcid(bridge_cdr, chan);
03996          bridge_cdr->disposition = (chan->_state == AST_STATE_UP) ?  AST_CDR_ANSWERED : AST_CDR_NULL;
03997          bridge_cdr->amaflags = chan->amaflags ? chan->amaflags :  ast_default_amaflags;
03998          ast_copy_string(bridge_cdr->accountcode, chan->accountcode, sizeof(bridge_cdr->accountcode));
03999          /* Destination information */
04000          ast_copy_string(bridge_cdr->dst, chan->exten, sizeof(bridge_cdr->dst));
04001          ast_copy_string(bridge_cdr->dcontext, chan->context, sizeof(bridge_cdr->dcontext));
04002          if (peer_cdr) {
04003             bridge_cdr->start = peer_cdr->start;
04004             ast_copy_string(bridge_cdr->userfield, peer_cdr->userfield, sizeof(bridge_cdr->userfield));
04005          } else {
04006             ast_cdr_start(bridge_cdr);
04007          }
04008       }
04009       ast_channel_unlock(chan);
04010       ast_channel_unlock(peer);
04011 
04012       ast_debug(4,"bridge answer set, chan answer set\n");
04013       /* peer_cdr->answer will be set when a macro runs on the peer;
04014          in that case, the bridge answer will be delayed while the
04015          macro plays on the peer channel. The peer answered the call
04016          before the macro started playing. To the phone system,
04017          this is billable time for the call, even tho the caller
04018          hears nothing but ringing while the macro does its thing. */
04019 
04020       /* Another case where the peer cdr's time will be set, is when
04021          A self-parks by pickup up phone and dialing 700, then B
04022          picks up A by dialing its parking slot; there may be more 
04023          practical paths that get the same result, tho... in which
04024          case you get the previous answer time from the Park... which
04025          is before the bridge's start time, so I added in the 
04026          tvcmp check to the if below */
04027 
04028       if (peer_cdr && !ast_tvzero(peer_cdr->answer) && ast_tvcmp(peer_cdr->answer, bridge_cdr->start) >= 0) {
04029          ast_cdr_setanswer(bridge_cdr, peer_cdr->answer);
04030          ast_cdr_setdisposition(bridge_cdr, peer_cdr->disposition);
04031          if (chan_cdr) {
04032             ast_cdr_setanswer(chan_cdr, peer_cdr->answer);
04033             ast_cdr_setdisposition(chan_cdr, peer_cdr->disposition);
04034          }
04035       } else {
04036          ast_cdr_answer(bridge_cdr);
04037          if (chan_cdr) {
04038             ast_cdr_answer(chan_cdr); /* for the sake of cli status checks */
04039          }
04040       }
04041       if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT) && (chan_cdr || peer_cdr)) {
04042          if (chan_cdr) {
04043             ast_set_flag(chan_cdr, AST_CDR_FLAG_BRIDGED);
04044          }
04045          if (peer_cdr) {
04046             ast_set_flag(peer_cdr, AST_CDR_FLAG_BRIDGED);
04047          }
04048       }
04049       /* the DIALED flag may be set if a dialed channel is transfered
04050        * and then bridged to another channel.  In order for the
04051        * bridge CDR to be written, the DIALED flag must not be
04052        * present. */
04053       ast_clear_flag(bridge_cdr, AST_CDR_FLAG_DIALED);
04054    }
04055    ast_cel_report_event(chan, AST_CEL_BRIDGE_START, NULL, NULL, peer);
04056 
04057    /* If we are bridging a call, stop worrying about forwarding loops. We presume that if
04058     * a call is being bridged, that the humans in charge know what they're doing. If they
04059     * don't, well, what can we do about that? */
04060    clear_dialed_interfaces(chan);
04061    clear_dialed_interfaces(peer);
04062 
04063    for (;;) {
04064       struct ast_channel *other; /* used later */
04065    
04066       res = ast_channel_bridge(chan, peer, config, &f, &who);
04067 
04068       if (ast_test_flag(chan, AST_FLAG_ZOMBIE)
04069          || ast_test_flag(peer, AST_FLAG_ZOMBIE)) {
04070          /* Zombies are present time to leave! */
04071          res = -1;
04072          if (f) {
04073             ast_frfree(f);
04074          }
04075          goto before_you_go;
04076       }
04077 
04078       /* When frame is not set, we are probably involved in a situation
04079          where we've timed out.
04080          When frame is set, we'll come this code twice; once for DTMF_BEGIN
04081          and also for DTMF_END. If we flow into the following 'if' for both, then 
04082          our wait times are cut in half, as both will subtract from the
04083          feature_timer. Not good!
04084       */
04085       if (config->feature_timer && (!f || f->frametype == AST_FRAME_DTMF_END)) {
04086          /* Update feature timer for next pass */
04087          diff = ast_tvdiff_ms(ast_tvnow(), config->feature_start_time);
04088          if (res == AST_BRIDGE_RETRY) {
04089             /* The feature fully timed out but has not been updated. Skip
04090              * the potential round error from the diff calculation and
04091              * explicitly set to expired. */
04092             config->feature_timer = -1;
04093          } else {
04094             config->feature_timer -= diff;
04095          }
04096 
04097          if (hasfeatures) {
04098             if (config->feature_timer <= 0) {
04099                /* Not *really* out of time, just out of time for
04100                   digits to come in for features. */
04101                ast_debug(1, "Timed out for feature!\n");
04102                if (!ast_strlen_zero(peer_featurecode)) {
04103                   ast_dtmf_stream(chan, peer, peer_featurecode, 0, 0);
04104                   memset(peer_featurecode, 0, sizeof(peer_featurecode));
04105                }
04106                if (!ast_strlen_zero(chan_featurecode)) {
04107                   ast_dtmf_stream(peer, chan, chan_featurecode, 0, 0);
04108                   memset(chan_featurecode, 0, sizeof(chan_featurecode));
04109                }
04110                if (f)
04111                   ast_frfree(f);
04112                hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
04113                if (!hasfeatures) {
04114                   /* No more digits expected - reset the timer */
04115                   config->feature_timer = 0;
04116                }
04117                hadfeatures = hasfeatures;
04118                /* Continue as we were */
04119                continue;
04120             } else if (!f) {
04121                /* The bridge returned without a frame and there is a feature in progress.
04122                 * However, we don't think the feature has quite yet timed out, so just
04123                 * go back into the bridge. */
04124                continue;
04125             }
04126          } else {
04127             if (config->feature_timer <=0) {
04128                /* We ran out of time */
04129                config->feature_timer = 0;
04130                who = chan;
04131                if (f)
04132                   ast_frfree(f);
04133                f = NULL;
04134                res = 0;
04135             }
04136          }
04137       }
04138       if (res < 0) {
04139          if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_test_flag(peer, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan) && !ast_check_hangup(peer)) {
04140             ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name);
04141          }
04142          goto before_you_go;
04143       }
04144       
04145       if (!f || (f->frametype == AST_FRAME_CONTROL &&
04146             (f->subclass.integer == AST_CONTROL_HANGUP || f->subclass.integer == AST_CONTROL_BUSY ||
04147                f->subclass.integer == AST_CONTROL_CONGESTION))) {
04148          /*
04149           * If the bridge was broken for a hangup that isn't real,
04150           * then don't run the h extension, because the channel isn't
04151           * really hung up. This should really only happen with AST_SOFTHANGUP_ASYNCGOTO,
04152           * but it doesn't hurt to check AST_SOFTHANGUP_UNBRIDGE either.
04153           */
04154          ast_channel_lock(chan);
04155          if (chan->_softhangup & (AST_SOFTHANGUP_ASYNCGOTO | AST_SOFTHANGUP_UNBRIDGE)) {
04156             ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT);
04157          }
04158          ast_channel_unlock(chan);
04159          res = -1;
04160          break;
04161       }
04162       /* many things should be sent to the 'other' channel */
04163       other = (who == chan) ? peer : chan;
04164       if (f->frametype == AST_FRAME_CONTROL) {
04165          switch (f->subclass.integer) {
04166          case AST_CONTROL_RINGING:
04167          case AST_CONTROL_FLASH:
04168          case -1:
04169             ast_indicate(other, f->subclass.integer);
04170             break;
04171          case AST_CONTROL_CONNECTED_LINE:
04172             if (!ast_channel_connected_line_macro(who, other, f, who != chan, 1)) {
04173                break;
04174             }
04175             ast_indicate_data(other, f->subclass.integer, f->data.ptr, f->datalen);
04176             break;
04177          case AST_CONTROL_REDIRECTING:
04178             if (!ast_channel_redirecting_macro(who, other, f, who != chan, 1)) {
04179                break;
04180             }
04181             ast_indicate_data(other, f->subclass.integer, f->data.ptr, f->datalen);
04182             break;
04183          case AST_CONTROL_AOC:
04184          case AST_CONTROL_HOLD:
04185          case AST_CONTROL_UNHOLD:
04186             ast_indicate_data(other, f->subclass.integer, f->data.ptr, f->datalen);
04187             break;
04188          case AST_CONTROL_OPTION:
04189             aoh = f->data.ptr;
04190             /* Forward option Requests, but only ones we know are safe
04191              * These are ONLY sent by chan_iax2 and I'm not convinced that
04192              * they are useful. I haven't deleted them entirely because I
04193              * just am not sure of the ramifications of removing them. */
04194             if (aoh && aoh->flag == AST_OPTION_FLAG_REQUEST) {
04195                   switch (ntohs(aoh->option)) {
04196                case AST_OPTION_TONE_VERIFY:
04197                case AST_OPTION_TDD:
04198                case AST_OPTION_RELAXDTMF:
04199                case AST_OPTION_AUDIO_MODE:
04200                case AST_OPTION_DIGIT_DETECT:
04201                case AST_OPTION_FAX_DETECT:
04202                   ast_channel_setoption(other, ntohs(aoh->option), aoh->data, 
04203                      f->datalen - sizeof(struct ast_option_header), 0);
04204                }
04205             }
04206             break;
04207          }
04208       } else if (f->frametype == AST_FRAME_DTMF_BEGIN) {
04209          struct ast_flags *cfg;
04210          char dtmfcode[2] = { f->subclass.integer, };
04211          size_t featurelen;
04212 
04213          if (who == chan) {
04214             featurelen = strlen(chan_featurecode);
04215             cfg = &(config->features_caller);
04216          } else {
04217             featurelen = strlen(peer_featurecode);
04218             cfg = &(config->features_callee);
04219          }
04220          /* Take a peek if this (possibly) matches a feature. If not, just pass this
04221           * DTMF along untouched. If this is not the first digit of a multi-digit code
04222           * then we need to fall through and stream the characters if it matches */
04223          if (featurelen == 0
04224             && feature_check(chan, cfg, &dtmfcode[0]) == AST_FEATURE_RETURN_PASSDIGITS) {
04225             if (option_debug > 3) {
04226                ast_log(LOG_DEBUG, "Passing DTMF through, since it is not a feature code\n");
04227             }
04228             ast_write(other, f);
04229             sendingdtmfdigit = 1;
04230          } else {
04231             /* If ast_opt_transmit_silence is set, then we need to make sure we are
04232              * transmitting something while we hold on to the DTMF waiting for a
04233              * feature. */
04234             if (!silgen && ast_opt_transmit_silence) {
04235                silgen = ast_channel_start_silence_generator(other);
04236             }
04237             if (option_debug > 3) {
04238                ast_log(LOG_DEBUG, "Not passing DTMF through, since it may be a feature code\n");
04239             }
04240          }
04241       } else if (f->frametype == AST_FRAME_DTMF_END) {
04242          char *featurecode;
04243          int sense;
04244 
04245          hadfeatures = hasfeatures;
04246          /* This cannot overrun because the longest feature is one shorter than our buffer */
04247          if (who == chan) {
04248             sense = FEATURE_SENSE_CHAN;
04249             featurecode = chan_featurecode;
04250          } else  {
04251             sense = FEATURE_SENSE_PEER;
04252             featurecode = peer_featurecode;
04253          }
04254 
04255          if (sendingdtmfdigit == 1) {
04256             /* We let the BEGIN go through happily, so let's not bother with the END,
04257              * since we already know it's not something we bother with */
04258             ast_write(other, f);
04259             sendingdtmfdigit = 0;
04260          } else {
04261             /*! append the event to featurecode. we rely on the string being zero-filled, and
04262              * not overflowing it. 
04263              * \todo XXX how do we guarantee the latter ?
04264              */
04265             featurecode[strlen(featurecode)] = f->subclass.integer;
04266             /* Get rid of the frame before we start doing "stuff" with the channels */
04267             ast_frfree(f);
04268             f = NULL;
04269             if (silgen) {
04270                ast_channel_stop_silence_generator(other, silgen);
04271                silgen = NULL;
04272             }
04273             config->feature_timer = 0;
04274             res = feature_interpret(chan, peer, config, featurecode, sense);
04275             switch(res) {
04276             case AST_FEATURE_RETURN_PASSDIGITS:
04277                ast_dtmf_stream(other, who, featurecode, 0, 0);
04278                /* Fall through */
04279             case AST_FEATURE_RETURN_SUCCESS:
04280                memset(featurecode, 0, sizeof(chan_featurecode));
04281                break;
04282             }
04283             if (res >= AST_FEATURE_RETURN_PASSDIGITS) {
04284                res = 0;
04285             } else {
04286                break;
04287             }
04288             hasfeatures = !ast_strlen_zero(chan_featurecode) || !ast_strlen_zero(peer_featurecode);
04289             if (hadfeatures && !hasfeatures) {
04290                /* Feature completed or timed out */
04291                config->feature_timer = 0;
04292             } else if (hasfeatures) {
04293                if (config->timelimit) {
04294                   /* No warning next time - we are waiting for feature code */
04295                   ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
04296                }
04297                config->feature_start_time = ast_tvnow();
04298                config->feature_timer = featuredigittimeout;
04299                ast_debug(1, "Set feature timer to %ld ms\n", config->feature_timer);
04300             }
04301          }
04302       }
04303       if (f)
04304          ast_frfree(f);
04305    }
04306    ast_cel_report_event(chan, AST_CEL_BRIDGE_END, NULL, NULL, peer);
04307 
04308 before_you_go:
04309    /* Just in case something weird happened and we didn't clean up the silence generator... */
04310    if (silgen) {
04311       ast_channel_stop_silence_generator(who == chan ? peer : chan, silgen);
04312       silgen = NULL;
04313    }
04314 
04315    if (ast_test_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT)) {
04316       ast_clear_flag(chan,AST_FLAG_BRIDGE_HANGUP_DONT); /* its job is done */
04317       if (bridge_cdr) {
04318          ast_cdr_discard(bridge_cdr);
04319          /* QUESTION: should we copy bridge_cdr fields to the peer before we throw it away? */
04320       }
04321       return res; /* if we shouldn't do the h-exten, we shouldn't do the bridge cdr, either! */
04322    }
04323 
04324    if (config->end_bridge_callback) {
04325       config->end_bridge_callback(config->end_bridge_callback_data);
04326    }
04327 
04328    /* run the hangup exten on the chan object IFF it was NOT involved in a parking situation 
04329     * if it were, then chan belongs to a different thread now, and might have been hung up long
04330      * ago.
04331     */
04332    if (ast_test_flag(&config->features_caller, AST_FEATURE_NO_H_EXTEN)) {
04333       h_context = NULL;
04334    } else if (ast_exists_extension(chan, chan->context, "h", 1,
04335       S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
04336       h_context = chan->context;
04337    } else if (!ast_strlen_zero(chan->macrocontext)
04338       && ast_exists_extension(chan, chan->macrocontext, "h", 1,
04339          S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
04340       h_context = chan->macrocontext;
04341    } else {
04342       h_context = NULL;
04343    }
04344    if (h_context) {
04345       struct ast_cdr *swapper = NULL;
04346       char savelastapp[AST_MAX_EXTENSION];
04347       char savelastdata[AST_MAX_EXTENSION];
04348       char save_context[AST_MAX_CONTEXT];
04349       char save_exten[AST_MAX_EXTENSION];
04350       int  save_prio;
04351       int  found = 0;   /* set if we find at least one match */
04352       int  spawn_error = 0;
04353 
04354       /*
04355        * Make sure that the channel is marked as hungup since we are
04356        * going to run the "h" exten on it.
04357        */
04358       ast_softhangup(chan, AST_SOFTHANGUP_APPUNLOAD);
04359 
04360       autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP);
04361       ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP);
04362       if (bridge_cdr && ast_opt_end_cdr_before_h_exten) {
04363          ast_cdr_end(bridge_cdr);
04364       }
04365 
04366       /* swap the bridge cdr and the chan cdr for a moment, and let the endbridge
04367          dialplan code operate on it */
04368       ast_channel_lock(chan);
04369       if (bridge_cdr) {
04370          swapper = chan->cdr;
04371          ast_copy_string(savelastapp, bridge_cdr->lastapp, sizeof(bridge_cdr->lastapp));
04372          ast_copy_string(savelastdata, bridge_cdr->lastdata, sizeof(bridge_cdr->lastdata));
04373          chan->cdr = bridge_cdr;
04374       }
04375       ast_copy_string(save_context, chan->context, sizeof(save_context));
04376       ast_copy_string(save_exten, chan->exten, sizeof(save_exten));
04377       save_prio = chan->priority;
04378       if (h_context != chan->context) {
04379          ast_copy_string(chan->context, h_context, sizeof(chan->context));
04380       }
04381       ast_copy_string(chan->exten, "h", sizeof(chan->exten));
04382       chan->priority = 1;
04383       ast_channel_unlock(chan);
04384 
04385       while ((spawn_error = ast_spawn_extension(chan, chan->context, chan->exten,
04386          chan->priority,
04387          S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL),
04388          &found, 1)) == 0) {
04389          chan->priority++;
04390       }
04391       if (found && spawn_error) {
04392          /* Something bad happened, or a hangup has been requested. */
04393          ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
04394          ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", chan->context, chan->exten, chan->priority, chan->name);
04395       }
04396 
04397       /* swap it back */
04398       ast_channel_lock(chan);
04399       ast_copy_string(chan->context, save_context, sizeof(chan->context));
04400       ast_copy_string(chan->exten, save_exten, sizeof(chan->exten));
04401       chan->priority = save_prio;
04402       if (bridge_cdr) {
04403          if (chan->cdr == bridge_cdr) {
04404             chan->cdr = swapper;
04405          } else {
04406             bridge_cdr = NULL;
04407          }
04408       }
04409       /* An "h" exten has been run, so indicate that one has been run. */
04410       ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_RUN);
04411       ast_channel_unlock(chan);
04412 
04413       /* protect the lastapp/lastdata against the effects of the hangup/dialplan code */
04414       if (bridge_cdr) {
04415          ast_copy_string(bridge_cdr->lastapp, savelastapp, sizeof(bridge_cdr->lastapp));
04416          ast_copy_string(bridge_cdr->lastdata, savelastdata, sizeof(bridge_cdr->lastdata));
04417       }
04418       ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
04419    }
04420    
04421    /* obey the NoCDR() wishes. -- move the DISABLED flag to the bridge CDR if it was set on the channel during the bridge... */
04422    new_chan_cdr = pick_unlocked_cdr(chan->cdr); /* the proper chan cdr, if there are forked cdrs */
04423    /* If the channel CDR has been modified during the call, record the changes in the bridge cdr,
04424     * BUT, if we've gone through the h extension block above, the CDR got swapped so don't overwrite
04425     * what was done in the h extension. What a mess. This is why you never touch CDR code. */
04426    if (new_chan_cdr && bridge_cdr && !h_context) {
04427       ast_cdr_copy_vars(bridge_cdr, new_chan_cdr);
04428       ast_copy_string(bridge_cdr->userfield, new_chan_cdr->userfield, sizeof(bridge_cdr->userfield));
04429       bridge_cdr->amaflags = new_chan_cdr->amaflags;
04430       ast_copy_string(bridge_cdr->accountcode, new_chan_cdr->accountcode, sizeof(bridge_cdr->accountcode));
04431       if (ast_test_flag(new_chan_cdr, AST_CDR_FLAG_POST_DISABLED)) {
04432          ast_set_flag(bridge_cdr, AST_CDR_FLAG_POST_DISABLED);
04433       }
04434    }
04435 
04436    /* we can post the bridge CDR at this point */
04437    if (bridge_cdr) {
04438       ast_cdr_end(bridge_cdr);
04439       ast_cdr_detach(bridge_cdr);
04440    }
04441    
04442    /* do a specialized reset on the beginning channel
04443       CDR's, if they still exist, so as not to mess up
04444       issues in future bridges;
04445       
04446       Here are the rules of the game:
04447       1. The chan and peer channel pointers will not change
04448          during the life of the bridge.
04449       2. But, in transfers, the channel names will change.
04450          between the time the bridge is started, and the
04451          time the channel ends. 
04452          Usually, when a channel changes names, it will
04453          also change CDR pointers.
04454       3. Usually, only one of the two channels (chan or peer)
04455          will change names.
04456       4. Usually, if a channel changes names during a bridge,
04457          it is because of a transfer. Usually, in these situations,
04458          it is normal to see 2 bridges running simultaneously, and
04459          it is not unusual to see the two channels that change
04460          swapped between bridges.
04461       5. After a bridge occurs, we have 2 or 3 channels' CDRs
04462          to attend to; if the chan or peer changed names,
04463          we have the before and after attached CDR's.
04464    */
04465 
04466    if (new_chan_cdr) {
04467       struct ast_channel *chan_ptr = NULL;
04468 
04469       if (strcasecmp(orig_channame, chan->name) != 0) { 
04470          /* old channel */
04471          if ((chan_ptr = ast_channel_get_by_name(orig_channame))) {
04472             ast_channel_lock(chan_ptr);
04473             if (!ast_bridged_channel(chan_ptr)) {
04474                struct ast_cdr *cur;
04475                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
04476                   if (cur == chan_cdr) {
04477                      break;
04478                   }
04479                }
04480                if (cur) {
04481                   ast_cdr_specialized_reset(chan_cdr, 0);
04482                }
04483             }
04484             ast_channel_unlock(chan_ptr);
04485             chan_ptr = ast_channel_unref(chan_ptr);
04486          }
04487          /* new channel */
04488          ast_cdr_specialized_reset(new_chan_cdr, 0);
04489       } else {
04490          ast_cdr_specialized_reset(chan->cdr, 0); /* nothing changed, reset the chan cdr  */
04491       }
04492    }
04493 
04494    {
04495       struct ast_channel *chan_ptr = NULL;
04496       new_peer_cdr = pick_unlocked_cdr(peer->cdr); /* the proper chan cdr, if there are forked cdrs */
04497       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))
04498          ast_set_flag(new_peer_cdr, AST_CDR_FLAG_POST_DISABLED); /* DISABLED is viral-- it will propagate across a bridge */
04499       if (strcasecmp(orig_peername, peer->name) != 0) { 
04500          /* old channel */
04501          if ((chan_ptr = ast_channel_get_by_name(orig_peername))) {
04502             ast_channel_lock(chan_ptr);
04503             if (!ast_bridged_channel(chan_ptr)) {
04504                struct ast_cdr *cur;
04505                for (cur = chan_ptr->cdr; cur; cur = cur->next) {
04506                   if (cur == peer_cdr) {
04507                      break;
04508                   }
04509                }
04510                if (cur) {
04511                   ast_cdr_specialized_reset(peer_cdr, 0);
04512                }
04513             }
04514             ast_channel_unlock(chan_ptr);
04515             chan_ptr = ast_channel_unref(chan_ptr);
04516          }
04517          /* new channel */
04518          if (new_peer_cdr) {
04519             ast_cdr_specialized_reset(new_peer_cdr, 0);
04520          }
04521       } else {
04522          if (we_disabled_peer_cdr) {
04523             ast_clear_flag(peer->cdr, AST_CDR_FLAG_POST_DISABLED);
04524          }
04525          ast_cdr_specialized_reset(peer->cdr, 0); /* nothing changed, reset the peer cdr  */
04526       }
04527    }
04528    
04529    return res;
04530 }

int ast_bridge_timelimit ( struct ast_channel *  chan,
struct ast_bridge_config *  config,
char *  parse,
struct timeval *  calldurationlimit 
)

parse L option and read associated channel variables to set warning, warning frequency, and timelimit

Note:
caller must be aware of freeing memory for warning_sound, end_sound, and start_sound

Definition at line 7413 of file features.c.

References ast_channel_lock, ast_channel_unlock, AST_FEATURE_PLAY_WARNING, ast_log(), ast_set_flag, ast_strdup, ast_strdupa, ast_strlen_zero(), ast_true(), ast_verb, ast_bridge_config::end_sound, ast_bridge_config::features_callee, ast_bridge_config::features_caller, LOG_WARNING, pbx_builtin_getvar_helper(), ast_bridge_config::play_warning, S_OR, ast_bridge_config::start_sound, ast_bridge_config::timelimit, var, ast_bridge_config::warning_freq, and ast_bridge_config::warning_sound.

Referenced by bridge_exec(), and dial_exec_full().

07415 {
07416    char *stringp = ast_strdupa(parse);
07417    char *limit_str, *warning_str, *warnfreq_str;
07418    const char *var;
07419    int play_to_caller = 0, play_to_callee = 0;
07420    int delta;
07421 
07422    limit_str = strsep(&stringp, ":");
07423    warning_str = strsep(&stringp, ":");
07424    warnfreq_str = strsep(&stringp, ":");
07425 
07426    config->timelimit = atol(limit_str);
07427    if (warning_str)
07428       config->play_warning = atol(warning_str);
07429    if (warnfreq_str)
07430       config->warning_freq = atol(warnfreq_str);
07431 
07432    if (!config->timelimit) {
07433       ast_log(LOG_WARNING, "Bridge does not accept L(%s), hanging up.\n", limit_str);
07434       config->timelimit = config->play_warning = config->warning_freq = 0;
07435       config->warning_sound = NULL;
07436       return -1; /* error */
07437    } else if ( (delta = config->play_warning - config->timelimit) > 0) {
07438       int w = config->warning_freq;
07439 
07440       /*
07441        * If the first warning is requested _after_ the entire call
07442        * would end, and no warning frequency is requested, then turn
07443        * off the warning. If a warning frequency is requested, reduce
07444        * the 'first warning' time by that frequency until it falls
07445        * within the call's total time limit.
07446        *
07447        * Graphically:
07448        *                timelim->|    delta        |<-playwarning
07449        *      0__________________|_________________|
07450        *                       | w  |    |    |    |
07451        *
07452        * so the number of intervals to cut is 1+(delta-1)/w
07453        */
07454       if (w == 0) {
07455          config->play_warning = 0;
07456       } else {
07457          config->play_warning -= w * ( 1 + (delta-1)/w );
07458          if (config->play_warning < 1)
07459             config->play_warning = config->warning_freq = 0;
07460       }
07461    }
07462    
07463    ast_channel_lock(chan);
07464 
07465    var = pbx_builtin_getvar_helper(chan, "LIMIT_PLAYAUDIO_CALLER");
07466    play_to_caller = var ? ast_true(var) : 1;
07467 
07468    var = pbx_builtin_getvar_helper(chan, "LIMIT_PLAYAUDIO_CALLEE");
07469    play_to_callee = var ? ast_true(var) : 0;
07470 
07471    if (!play_to_caller && !play_to_callee)
07472       play_to_caller = 1;
07473 
07474    var = pbx_builtin_getvar_helper(chan, "LIMIT_WARNING_FILE");
07475    config->warning_sound = !ast_strlen_zero(var) ? ast_strdup(var) : ast_strdup("timeleft");
07476 
07477    /* The code looking at config wants a NULL, not just "", to decide
07478     * that the message should not be played, so we replace "" with NULL.
07479     * Note, pbx_builtin_getvar_helper _can_ return NULL if the variable is
07480     * not found.
07481     */
07482 
07483    var = pbx_builtin_getvar_helper(chan, "LIMIT_TIMEOUT_FILE");
07484    config->end_sound = !ast_strlen_zero(var) ? ast_strdup(var) : NULL;
07485 
07486    var = pbx_builtin_getvar_helper(chan, "LIMIT_CONNECT_FILE");
07487    config->start_sound = !ast_strlen_zero(var) ? ast_strdup(var) : NULL;
07488 
07489    ast_channel_unlock(chan);
07490 
07491    /* undo effect of S(x) in case they are both used */
07492    calldurationlimit->tv_sec = 0;
07493    calldurationlimit->tv_usec = 0;
07494 
07495    /* more efficient to do it like S(x) does since no advanced opts */
07496    if (!config->play_warning && !config->start_sound && !config->end_sound && config->timelimit) {
07497       calldurationlimit->tv_sec = config->timelimit / 1000;
07498       calldurationlimit->tv_usec = (config->timelimit % 1000) * 1000;
07499       ast_verb(3, "Setting call duration limit to %.3lf seconds.\n",
07500          calldurationlimit->tv_sec + calldurationlimit->tv_usec / 1000000.0);
07501       config->timelimit = play_to_caller = play_to_callee =
07502       config->play_warning = config->warning_freq = 0;
07503    } else {
07504       ast_verb(4, "Limit Data for this call:\n");
07505       ast_verb(4, "timelimit      = %ld ms (%.3lf s)\n", config->timelimit, config->timelimit / 1000.0);
07506       ast_verb(4, "play_warning   = %ld ms (%.3lf s)\n", config->play_warning, config->play_warning / 1000.0);
07507       ast_verb(4, "play_to_caller = %s\n", play_to_caller ? "yes" : "no");
07508       ast_verb(4, "play_to_callee = %s\n", play_to_callee ? "yes" : "no");
07509       ast_verb(4, "warning_freq   = %ld ms (%.3lf s)\n", config->warning_freq, config->warning_freq / 1000.0);
07510       ast_verb(4, "start_sound    = %s\n", S_OR(config->start_sound, ""));
07511       ast_verb(4, "warning_sound  = %s\n", config->warning_sound);
07512       ast_verb(4, "end_sound      = %s\n", S_OR(config->end_sound, ""));
07513    }
07514    if (play_to_caller)
07515       ast_set_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING);
07516    if (play_to_callee)
07517       ast_set_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING);
07518    return 0;
07519 }

int ast_can_pickup ( struct ast_channel *  chan  ) 

Test if a channel can be picked up.

Parameters:
chan Channel to test if can be picked up.
Note:
This function assumes that chan is locked.
Returns:
TRUE if channel can be picked up.

Definition at line 7219 of file features.c.

References ast_channel::_state, ast_channel_datastore_find(), AST_FLAG_ZOMBIE, AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, ast_test_flag, ast_channel::masq, and ast_channel::pbx.

Referenced by find_by_mark(), find_by_part(), find_channel_by_group(), pickup_by_exten(), and pickup_by_name_cb().

07220 {
07221    if (!chan->pbx && !chan->masq && !ast_test_flag(chan, AST_FLAG_ZOMBIE)
07222       && (chan->_state == AST_STATE_RINGING
07223          || chan->_state == AST_STATE_RING
07224          /*
07225           * Check the down state as well because some SIP devices do not
07226           * give 180 ringing when they can just give 183 session progress
07227           * instead.  Issue 14005.  (Some ISDN switches as well for that
07228           * matter.)
07229           */
07230          || chan->_state == AST_STATE_DOWN)
07231       && !ast_channel_datastore_find(chan, &pickup_active, NULL)) {
07232       return 1;
07233    }
07234    return 0;
07235 }

void ast_channel_log ( char *  title,
struct ast_channel *  chan 
)

Definition at line 3768 of file features.c.

References ast_log(), and LOG_NOTICE.

Referenced by ast_bridge_call().

03769 {
03770        ast_log(LOG_NOTICE, "______ %s (%lx)______\n", title, (unsigned long)chan);
03771        ast_log(LOG_NOTICE, "CHAN: name: %s;  appl: %s; data: %s; contxt: %s;  exten: %s; pri: %d;\n",
03772                        chan->name, chan->appl, chan->data, chan->context, chan->exten, chan->priority);
03773        ast_log(LOG_NOTICE, "CHAN: acctcode: %s;  dialcontext: %s; amaflags: %x; maccontxt: %s;  macexten: %s; macpri: %d;\n",
03774                        chan->accountcode, chan->dialcontext, chan->amaflags, chan->macrocontext, chan->macroexten, chan->macropriority);
03775        ast_log(LOG_NOTICE, "CHAN: masq: %p;  masqr: %p; _bridge: %p; uniqueID: %s; linkedID:%s\n",
03776                        chan->masq, chan->masqr,
03777                        chan->_bridge, chan->uniqueid, chan->linkedid);
03778        if (chan->masqr)
03779                ast_log(LOG_NOTICE, "CHAN: masquerading as: %s;  cdr: %p;\n",
03780                                chan->masqr->name, chan->masqr->cdr);
03781        if (chan->_bridge)
03782                ast_log(LOG_NOTICE, "CHAN: Bridged to %s\n", chan->_bridge->name);
03783 
03784    ast_log(LOG_NOTICE, "===== done ====\n");
03785 }

int ast_do_pickup ( struct ast_channel *  chan,
struct ast_channel *  target 
)

Pickup a call target.

Parameters:
chan channel that initiated pickup.
target channel to be picked up.
Note:
This function assumes that target is locked.
Return values:
0 on success.
-1 on failure.

< A masquerade changes channel names.

< A masquerade changes channel names.

Definition at line 7295 of file features.c.

References ast_answer(), AST_CEL_PICKUP, ast_cel_report_event(), ast_channel_connected_line_macro(), ast_channel_datastore_add(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_masquerade(), ast_channel_queue_connected_line_update(), ast_channel_unlock, ast_channel_update_connected_line(), ast_connected_line_copy_from_caller(), AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER, AST_CONTROL_ANSWER, ast_datastore_alloc, ast_datastore_free(), ast_debug, ast_do_masquerade(), AST_FLAG_ANSWERED_ELSEWHERE, ast_log(), ast_manager_event_multichan, ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_queue_control(), ast_set_flag, ast_strdupa, ast_channel::caller, ast_channel::connected, EVENT_FLAG_CALL, LOG_WARNING, and ast_party_connected_line::source.

Referenced by ast_pickup_call(), pickup_by_channel(), pickup_by_exten(), pickup_by_group(), pickup_by_mark(), and pickup_by_part().

07296 {
07297    struct ast_party_connected_line connected_caller;
07298    struct ast_channel *chans[2] = { chan, target };
07299    struct ast_datastore *ds_pickup;
07300    const char *chan_name;/*!< A masquerade changes channel names. */
07301    const char *target_name;/*!< A masquerade changes channel names. */
07302    int res = -1;
07303 
07304    target_name = ast_strdupa(target->name);
07305    ast_debug(1, "Call pickup on '%s' by '%s'\n", target_name, chan->name);
07306 
07307    /* Mark the target to block any call pickup race. */
07308    ds_pickup = ast_datastore_alloc(&pickup_active, NULL);
07309    if (!ds_pickup) {
07310       ast_log(LOG_WARNING,
07311          "Unable to create channel datastore on '%s' for call pickup\n", target_name);
07312       return -1;
07313    }
07314    ast_channel_datastore_add(target, ds_pickup);
07315 
07316    ast_party_connected_line_init(&connected_caller);
07317    ast_party_connected_line_copy(&connected_caller, &target->connected);
07318    ast_channel_unlock(target);/* The pickup race is avoided so we do not need the lock anymore. */
07319    connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
07320    if (ast_channel_connected_line_macro(NULL, chan, &connected_caller, 0, 0)) {
07321       ast_channel_update_connected_line(chan, &connected_caller, NULL);
07322    }
07323    ast_party_connected_line_free(&connected_caller);
07324 
07325    ast_channel_lock(chan);
07326    chan_name = ast_strdupa(chan->name);
07327    ast_connected_line_copy_from_caller(&connected_caller, &chan->caller);
07328    ast_channel_unlock(chan);
07329    connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
07330 
07331    ast_cel_report_event(target, AST_CEL_PICKUP, NULL, NULL, chan);
07332 
07333    if (ast_answer(chan)) {
07334       ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan_name);
07335       goto pickup_failed;
07336    }
07337 
07338    if (ast_queue_control(chan, AST_CONTROL_ANSWER)) {
07339       ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n", chan_name);
07340       goto pickup_failed;
07341    }
07342    
07343    ast_channel_queue_connected_line_update(chan, &connected_caller, NULL);
07344 
07345    /* setting this flag to generate a reason header in the cancel message to the ringing channel */
07346    ast_set_flag(chan, AST_FLAG_ANSWERED_ELSEWHERE);
07347 
07348    if (ast_channel_masquerade(target, chan)) {
07349       ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan_name,
07350          target_name);
07351       goto pickup_failed;
07352    }
07353 
07354    /* If you want UniqueIDs, set channelvars in manager.conf to CHANNEL(uniqueid) */
07355    ast_manager_event_multichan(EVENT_FLAG_CALL, "Pickup", 2, chans,
07356       "Channel: %s\r\n"
07357       "TargetChannel: %s\r\n",
07358       chan_name, target_name);
07359 
07360    /* Do the masquerade manually to make sure that it is completed. */
07361    ast_do_masquerade(target);
07362    res = 0;
07363 
07364 pickup_failed:
07365    ast_channel_lock(target);
07366    if (!ast_channel_datastore_remove(target, ds_pickup)) {
07367       ast_datastore_free(ds_pickup);
07368    }
07369    ast_party_connected_line_free(&connected_caller);
07370 
07371    return res;
07372 }

int ast_feature_detect ( struct ast_channel *  chan,
struct ast_flags *  features,
const char *  code,
struct ast_call_feature *  feature 
)

detect a feature before bridging

Parameters:
chan 
features an ast_flags ptr
code ptr of input code
feature 
Return values:
ast_call_feature ptr to be set if found

Definition at line 3370 of file features.c.

References FEATURE_INTERPRET_DETECT, and feature_interpret_helper().

Referenced by detect_disconnect().

03370                                                                                                                                  {
03371 
03372    return feature_interpret_helper(chan, NULL, NULL, code, 0, NULL, features, FEATURE_INTERPRET_DETECT, feature);
03373 }

int ast_features_init ( void   ) 

Provided by features.c

Definition at line 8193 of file features.c.

References action_bridge(), ao2_container_alloc, ARRAY_LEN, ast_cli_register_multiple(), ast_devstate_prov_add(), ast_manager_register_xml, ast_pthread_create, ast_register_application2(), AST_TEST_REGISTER, bridge_exec(), do_parking_thread(), EVENT_FLAG_CALL, load_config(), manager_park(), manager_parking_status(), metermaidstate(), park_call_exec(), parkcall, parked_call_exec(), parking_thread, parkinglot_cmp_cb(), parkinglot_hash_cb(), and parkinglots.

Referenced by main().

08194 {
08195    int res;
08196 
08197    parkinglots = ao2_container_alloc(7, parkinglot_hash_cb, parkinglot_cmp_cb);
08198    if (!parkinglots) {
08199       return -1;
08200    }
08201 
08202    res = load_config(0);
08203    if (res) {
08204       return res;
08205    }
08206    ast_cli_register_multiple(cli_features, ARRAY_LEN(cli_features));
08207    if (ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL)) {
08208       return -1;
08209    }
08210    ast_register_application2(app_bridge, bridge_exec, NULL, NULL, NULL);
08211    res = ast_register_application2(parkedcall, parked_call_exec, NULL, NULL, NULL);
08212    if (!res)
08213       res = ast_register_application2(parkcall, park_call_exec, NULL, NULL, NULL);
08214    if (!res) {
08215       ast_manager_register_xml("ParkedCalls", 0, manager_parking_status);
08216       ast_manager_register_xml("Park", EVENT_FLAG_CALL, manager_park);
08217       ast_manager_register_xml("Bridge", EVENT_FLAG_CALL, action_bridge);
08218    }
08219 
08220    res |= ast_devstate_prov_add("Park", metermaidstate);
08221 #if defined(TEST_FRAMEWORK)
08222    res |= AST_TEST_REGISTER(features_test);
08223 #endif   /* defined(TEST_FRAMEWORK) */
08224 
08225    return res;
08226 }

int ast_features_reload ( void   ) 

Reload call features from features.conf.

Definition at line 6760 of file features.c.

References ast_context_destroy(), ast_context_find(), ast_mutex_lock, ast_mutex_unlock, features_reload_lock, load_config(), parking_con_dial, and registrar.

Referenced by handle_features_reload().

06761 {
06762    struct ast_context *con;
06763    int res;
06764 
06765    ast_mutex_lock(&features_reload_lock);/* Searialize reloading features.conf */
06766 
06767    /*
06768     * Always destroy the parking_con_dial context to remove buildup
06769     * of recalled extensions in the context.  At worst, the parked
06770     * call gets hungup attempting to run an invalid extension when
06771     * we are trying to callback the parker or the preset return
06772     * extension.  This is a small window of opportunity on an
06773     * execution chain that is not expected to happen very often.
06774     */
06775    con = ast_context_find(parking_con_dial);
06776    if (con) {
06777       ast_context_destroy(con, registrar);
06778    }
06779 
06780    res = load_config(1);
06781    ast_mutex_unlock(&features_reload_lock);
06782 
06783    return res;
06784 }

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

References FEATURES_COUNT, and ast_call_feature::sname.

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

03103 {
03104    int x;
03105    for (x = 0; x < FEATURES_COUNT; x++) {
03106       if (!strcasecmp(name, builtin_features[x].sname))
03107          return &builtin_features[x];
03108    }
03109    return NULL;
03110 }

int ast_masq_park_call ( struct ast_channel *  park_me,
struct ast_channel *  parker,
int  timeout,
int *  extout 
)

Park a call via a masqueraded channel.

Parameters:
park_me Channel to be parked.
parker Channel parking the call.
timeout is a timeout in milliseconds
extout is a parameter to an int that will hold the parked location, or NULL if you want.

Masquerade the park_me channel into a new, empty channel which is then parked.

Note:
Use ast_masq_park_call_exten() instead.
Return values:
0 on success.
-1 on failure.

Definition at line 1814 of file features.c.

References ast_strdupa, masq_park_call(), ast_park_call_args::orig_chan_name, and ast_park_call_args::timeout.

Referenced by handle_soft_key_event_message(), handle_stimulus_message(), and parkandannounce_exec().

01815 {
01816    struct ast_park_call_args args = {
01817       .timeout = timeout,
01818       .extout = extout,
01819    };
01820 
01821    if (peer) {
01822       args.orig_chan_name = ast_strdupa(peer->name);
01823    }
01824    return masq_park_call(rchan, peer, &args);
01825 }

int ast_masq_park_call_exten ( struct ast_channel *  park_me,
struct ast_channel *  parker,
const char *  park_exten,
const char *  park_context,
int  timeout,
int *  extout 
)

Park a call via a masqueraded channel.

Since:
1.8.9
Parameters:
park_me Channel to be parked.
parker Channel parking the call.
park_exten Parking lot access extension
park_context Parking lot context
timeout is a timeout in milliseconds
extout is a parameter to an int that will hold the parked location, or NULL if you want.

Masquerade the park_me channel into a new, empty channel which is then parked.

Return values:
0 on success.
-1 on failure.

Definition at line 1760 of file features.c.

References ast_autoservice_start(), ast_autoservice_stop(), ast_get_extension_app_data(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), create_dynamic_parkinglot(), find_parkinglot(), get_parking_exten(), masq_park_call(), ast_park_call_args::orig_chan_name, parkeddynamic, ast_park_call_args::parkinglot, parkinglot_unref(), parse(), park_app_args::pl_name, and ast_park_call_args::timeout.

Referenced by __analog_ss_thread(), analog_ss_thread(), and mgcp_ss().

01761 {
01762    int res;
01763    char *parse;
01764    const char *app_data;
01765    struct ast_exten *exten;
01766    struct park_app_args app_args;
01767    struct ast_park_call_args args = {
01768       .timeout = timeout,
01769       .extout = extout,
01770    };
01771 
01772    if (parker) {
01773       args.orig_chan_name = ast_strdupa(parker->name);
01774    }
01775    if (!park_exten || !park_context) {
01776       return masq_park_call(park_me, parker, &args);
01777    }
01778 
01779    /*
01780     * Determiine if the specified park extension has an exclusive
01781     * parking lot to use.
01782     */
01783    if (parker && parker != park_me) {
01784       ast_autoservice_start(park_me);
01785    }
01786    exten = get_parking_exten(park_exten, parker, park_context);
01787    if (exten) {
01788       app_data = ast_get_extension_app_data(exten);
01789       if (!app_data) {
01790          app_data = "";
01791       }
01792       parse = ast_strdupa(app_data);
01793       AST_STANDARD_APP_ARGS(app_args, parse);
01794    
01795       if (!ast_strlen_zero(app_args.pl_name)) {
01796          /* Find the specified exclusive parking lot */
01797          args.parkinglot = find_parkinglot(app_args.pl_name);
01798          if (!args.parkinglot && parkeddynamic) {
01799             args.parkinglot = create_dynamic_parkinglot(app_args.pl_name, park_me);
01800          }
01801       }
01802    }
01803    if (parker && parker != park_me) {
01804       ast_autoservice_stop(park_me);
01805    }
01806 
01807    res = masq_park_call(park_me, parker, &args);
01808    if (args.parkinglot) {
01809       parkinglot_unref(args.parkinglot);
01810    }
01811    return res;
01812 }

int ast_park_call ( struct ast_channel *  park_me,
struct ast_channel *  parker,
int  timeout,
const char *  park_exten,
int *  extout 
)

Park a call and read back parked location.

Parameters:
park_me Channel to be parked.
parker Channel parking the call.
timeout is a timeout in milliseconds
park_exten Parking lot access extension (Not used)
extout is a parameter to an int that will hold the parked location, or NULL if you want.

Park the park_me channel, and read back the parked location to the parker channel. 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).

Note:
Use ast_park_call_exten() instead.
Return values:
0 on success.
-1 on failure.

Definition at line 1663 of file features.c.

References park_call_full(), and ast_park_call_args::timeout.

01664 {
01665    struct ast_park_call_args args = {
01666       .timeout = timeout,
01667       .extout = extout,
01668    };
01669 
01670    return park_call_full(park_me, parker, &args);
01671 }

int ast_park_call_exten ( struct ast_channel *  park_me,
struct ast_channel *  parker,
const char *  park_exten,
const char *  park_context,
int  timeout,
int *  extout 
)

Park a call and read back parked location.

Since:
1.8.9
Parameters:
park_me Channel to be parked.
parker Channel parking the call.
park_exten Parking lot access extension
park_context Parking lot context
timeout is a timeout in milliseconds
extout is a parameter to an int that will hold the parked location, or NULL if you want.

Park the park_me channel, and read back the parked location to the parker channel. 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 1612 of file features.c.

References ast_autoservice_start(), ast_autoservice_stop(), ast_get_extension_app_data(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), create_dynamic_parkinglot(), find_parkinglot(), get_parking_exten(), park_call_full(), parkeddynamic, ast_park_call_args::parkinglot, parkinglot_unref(), parse(), park_app_args::pl_name, and ast_park_call_args::timeout.

Referenced by iax_park_thread(), and sip_park_thread().

01613 {
01614    int res;
01615    char *parse;
01616    const char *app_data;
01617    struct ast_exten *exten;
01618    struct park_app_args app_args;
01619    struct ast_park_call_args args = {
01620       .timeout = timeout,
01621       .extout = extout,
01622    };
01623 
01624    if (!park_exten || !park_context) {
01625       return park_call_full(park_me, parker, &args);
01626    }
01627 
01628    /*
01629     * Determiine if the specified park extension has an exclusive
01630     * parking lot to use.
01631     */
01632    if (parker && parker != park_me) {
01633       ast_autoservice_start(park_me);
01634    }
01635    exten = get_parking_exten(park_exten, parker, park_context);
01636    if (exten) {
01637       app_data = ast_get_extension_app_data(exten);
01638       if (!app_data) {
01639          app_data = "";
01640       }
01641       parse = ast_strdupa(app_data);
01642       AST_STANDARD_APP_ARGS(app_args, parse);
01643    
01644       if (!ast_strlen_zero(app_args.pl_name)) {
01645          /* Find the specified exclusive parking lot */
01646          args.parkinglot = find_parkinglot(app_args.pl_name);
01647          if (!args.parkinglot && parkeddynamic) {
01648             args.parkinglot = create_dynamic_parkinglot(app_args.pl_name, park_me);
01649          }
01650       }
01651    }
01652    if (parker && parker != park_me) {
01653       ast_autoservice_stop(park_me);
01654    }
01655 
01656    res = park_call_full(park_me, parker, &args);
01657    if (args.parkinglot) {
01658       parkinglot_unref(args.parkinglot);
01659    }
01660    return res;
01661 }

int ast_parking_ext_valid ( const char *  exten_str,
struct ast_channel *  chan,
const char *  context 
)

Determine if parking extension exists in a given context.

Return values:
0 if extension does not exist
1 if extension does exist

Definition at line 840 of file features.c.

References get_parking_exten().

Referenced by __analog_ss_thread(), analog_ss_thread(), dp_lookup(), handle_request_refer(), mgcp_ss(), and socket_process().

00841 {
00842    return get_parking_exten(exten_str, chan, context) ? 1 : 0;
00843 }

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.

< Potential pickup target

Definition at line 7261 of file features.c.

References ast_answer(), ast_channel_callback(), ast_channel_unlock, ast_channel_unref, ast_debug, ast_do_pickup(), ast_log(), ast_stream_and_wait(), ast_strlen_zero(), find_channel_by_group(), LOG_NOTICE, LOG_WARNING, pbx_builtin_setvar_helper(), pickupfailsound, and pickupsound.

Referenced by __analog_ss_thread(), analog_ss_thread(), cb_events(), mgcp_ss(), and sip_pickup_thread().

07262 {
07263    struct ast_channel *target;/*!< Potential pickup target */
07264    int res = -1;
07265    ast_debug(1, "pickup attempt by %s\n", chan->name);
07266 
07267    /* The found channel is already locked. */
07268    target = ast_channel_callback(find_channel_by_group, NULL, chan, 0);
07269    if (target) {
07270       ast_log(LOG_NOTICE, "pickup %s attempt by %s\n", target->name, chan->name);
07271 
07272       res = ast_do_pickup(chan, target);
07273       ast_channel_unlock(target);
07274       if (!res) {
07275          if (!ast_strlen_zero(pickupsound)) {
07276             pbx_builtin_setvar_helper(target, "BRIDGE_PLAY_SOUND", pickupsound);
07277          }
07278       } else {
07279          ast_log(LOG_WARNING, "pickup %s failed by %s\n", target->name, chan->name);
07280       }
07281       target = ast_channel_unref(target);
07282    }
07283 
07284    if (res < 0) {
07285       ast_debug(1, "No call pickup possible... for %s\n", chan->name);
07286       if (!ast_strlen_zero(pickupfailsound)) {
07287          ast_answer(chan);
07288          ast_stream_and_wait(chan, pickupfailsound, "");
07289       }
07290    }
07291 
07292    return res;
07293 }

const char* ast_pickup_ext ( void   ) 
void ast_rdlock_call_features ( void   ) 

Definition at line 3092 of file features.c.

References ast_rwlock_rdlock, and features_lock.

Referenced by handle_request_info().

03093 {
03094    ast_rwlock_rdlock(&features_lock);
03095 }

void ast_register_feature ( struct ast_call_feature *  feature  ) 

register new feature into feature_list

register new feature into feature_set

Definition at line 2936 of file features.c.

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

Referenced by process_applicationmap_line().

02937 {
02938    if (!feature) {
02939       ast_log(LOG_NOTICE,"You didn't pass a feature!\n");
02940       return;
02941    }
02942   
02943    AST_RWLIST_WRLOCK(&feature_list);
02944    AST_RWLIST_INSERT_HEAD(&feature_list,feature,feature_entry);
02945    AST_RWLIST_UNLOCK(&feature_list);
02946 
02947    ast_verb(2, "Registered Feature '%s'\n",feature->sname);
02948 }

void ast_unlock_call_features ( void   ) 

Definition at line 3097 of file features.c.

References ast_rwlock_unlock, and features_lock.

Referenced by handle_request_info().

03098 {
03099    ast_rwlock_unlock(&features_lock);
03100 }

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

References ast_free, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

03017 {
03018    if (!feature) {
03019       return;
03020    }
03021 
03022    AST_RWLIST_WRLOCK(&feature_list);
03023    AST_RWLIST_REMOVE(&feature_list, feature, feature_entry);
03024    AST_RWLIST_UNLOCK(&feature_list);
03025 
03026    ast_free(feature);
03027 }

static void ast_unregister_features ( void   )  [static]

Remove all features in the list.

Definition at line 3030 of file features.c.

References ast_free, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by process_config().

03031 {
03032    struct ast_call_feature *feature;
03033 
03034    AST_RWLIST_WRLOCK(&feature_list);
03035    while ((feature = AST_RWLIST_REMOVE_HEAD(&feature_list, feature_entry))) {
03036       ast_free(feature);
03037    }
03038    AST_RWLIST_UNLOCK(&feature_list);
03039 }

static void ast_unregister_groups ( void   )  [static]

Remove all feature groups in the list.

Definition at line 3056 of file features.c.

References ast_free, AST_LIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, and feature_group::features.

Referenced by process_config().

03057 {
03058    struct feature_group *fg;
03059    struct feature_group_exten *fge;
03060 
03061    AST_RWLIST_WRLOCK(&feature_groups);
03062    while ((fg = AST_LIST_REMOVE_HEAD(&feature_groups, entry))) {
03063       while ((fge = AST_LIST_REMOVE_HEAD(&fg->features, entry))) {
03064          ast_string_field_free_memory(fge);
03065          ast_free(fge);
03066       }
03067 
03068       ast_string_field_free_memory(fg);
03069       ast_free(fg);
03070    }
03071    AST_RWLIST_UNLOCK(&feature_groups);
03072 }

static void atxfer_fail_cleanup ( struct ast_channel *  transferee,
struct ast_channel *  transferer,
struct ast_party_connected_line *  connected_line 
) [static]

Definition at line 2438 of file features.c.

References ast_channel_connected_line_macro(), ast_channel_update_connected_line(), ast_party_connected_line_free(), and finishup().

Referenced by builtin_atxfer().

02439 {
02440    finishup(transferee);
02441 
02442    /*
02443     * Restore party B connected line info about party A.
02444     *
02445     * Party B was the caller to party C and is the last known mode
02446     * for party B.
02447     */
02448    if (ast_channel_connected_line_macro(transferee, transferer, connected_line, 1, 0)) {
02449       ast_channel_update_connected_line(transferer, connected_line, NULL);
02450    }
02451    ast_party_connected_line_free(connected_line);
02452 }

static void* bridge_call_thread ( void *  data  )  [static]

bridge the call

Parameters:
data thread bridge.

Set Last Data for respective channels, reset cdr for channels bridge call, check if we're going back to dialplan if not hangup both legs of the call

Definition at line 956 of file features.c.

References ast_channel::appl, ast_bridge_call(), ast_check_hangup(), ast_free, ast_hangup(), ast_log(), ast_pbx_start(), ast_bridge_thread_obj::bconfig, ast_bridge_thread_obj::chan, ast_channel::data, LOG_VERBOSE, LOG_WARNING, ast_bridge_thread_obj::peer, and ast_bridge_thread_obj::return_to_pbx.

Referenced by bridge_call_thread_launch().

00957 {
00958    struct ast_bridge_thread_obj *tobj = data;
00959 
00960    tobj->chan->appl = !tobj->return_to_pbx ? "Transferred Call" : "ManagerBridge";
00961    tobj->chan->data = tobj->peer->name;
00962    tobj->peer->appl = !tobj->return_to_pbx ? "Transferred Call" : "ManagerBridge";
00963    tobj->peer->data = tobj->chan->name;
00964 
00965    ast_bridge_call(tobj->peer, tobj->chan, &tobj->bconfig);
00966 
00967    if (tobj->return_to_pbx) {
00968       if (!ast_check_hangup(tobj->peer)) {
00969          ast_log(LOG_VERBOSE, "putting peer %s into PBX again\n", tobj->peer->name);
00970          if (ast_pbx_start(tobj->peer)) {
00971             ast_log(LOG_WARNING, "FAILED continuing PBX on peer %s\n", tobj->peer->name);
00972             ast_hangup(tobj->peer);
00973          }
00974       } else {
00975          ast_hangup(tobj->peer);
00976       }
00977       if (!ast_check_hangup(tobj->chan)) {
00978          ast_log(LOG_VERBOSE, "putting chan %s into PBX again\n", tobj->chan->name);
00979          if (ast_pbx_start(tobj->chan)) {
00980             ast_log(LOG_WARNING, "FAILED continuing PBX on chan %s\n", tobj->chan->name);
00981             ast_hangup(tobj->chan);
00982          }
00983       } else {
00984          ast_hangup(tobj->chan);
00985       }
00986    } else {
00987       ast_hangup(tobj->chan);
00988       ast_hangup(tobj->peer);
00989    }
00990 
00991    ast_free(tobj);
00992 
00993    return NULL;
00994 }

static void bridge_call_thread_launch ( struct ast_bridge_thread_obj *  data  )  [static]

create thread for the parked call

Parameters:
data Create thread and attributes, call bridge_call_thread

Definition at line 1002 of file features.c.

References ast_hangup(), ast_log(), ast_pthread_create, bridge_call_thread(), ast_bridge_thread_obj::chan, LOG_ERROR, ast_bridge_thread_obj::peer, and thread.

Referenced by action_bridge(), and builtin_atxfer().

01003 {
01004    pthread_t thread;
01005    pthread_attr_t attr;
01006    struct sched_param sched;
01007 
01008    pthread_attr_init(&attr);
01009    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
01010    if (ast_pthread_create(&thread, &attr, bridge_call_thread, data)) {
01011       ast_hangup(data->chan);
01012       ast_hangup(data->peer);
01013       ast_log(LOG_ERROR, "Failed to create bridge_call_thread.\n");
01014    }
01015    pthread_attr_destroy(&attr);
01016    memset(&sched, 0, sizeof(sched));
01017    pthread_setschedparam(thread, SCHED_RR, &sched);
01018 }

static int bridge_exec ( struct ast_channel *  chan,
const char *  data 
) [static]

Bridge channels.

Parameters:
chan 
data channel to bridge with.

Split data, check we aren't bridging with ourself, check valid channel, answer call if not already, check compatible channels, setup bridge config now bridge call, if transfered party hangs up return to PBX extension.

Definition at line 7531 of file features.c.

References ast_channel::_state, args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_bridge_call(), ast_bridge_timelimit(), ast_channel_alloc, ast_channel_get_by_name_prefix(), ast_channel_make_compatible(), ast_channel_unref, ast_check_hangup(), ast_debug, AST_DECLARE_APP_ARGS, AST_FEATURE_AUTOMON, AST_FEATURE_DISCONNECT, AST_FEATURE_PARKCALL, AST_FEATURE_REDIRECT, AST_FLAG_BRIDGE_HANGUP_DONT, ast_free, ast_hangup(), ast_log(), ast_manager_event, ast_manager_event_multichan, ast_pbx_start(), ast_set_flag, AST_STANDARD_APP_ARGS, AST_STATE_DOWN, AST_STATE_UP, ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitstream(), bridge_exec_options, BRIDGE_OPT_PLAYTONE, ast_channel::context, do_bridge_masquerade(), ast_bridge_config::end_sound, EVENT_FLAG_CALL, ast_channel::exten, ast_bridge_config::features_callee, ast_bridge_config::features_caller, LOG_WARNING, OPT_ARG_ARRAY_SIZE, OPT_ARG_DURATION_LIMIT, OPT_CALLEE_HANGUP, OPT_CALLEE_KILL, OPT_CALLEE_MONITOR, OPT_CALLEE_PARK, OPT_CALLEE_TRANSFER, OPT_CALLER_HANGUP, OPT_CALLER_MONITOR, OPT_CALLER_PARK, OPT_CALLER_TRANSFER, OPT_DURATION_LIMIT, pbx_builtin_setvar_helper(), ast_channel::priority, ast_bridge_config::start_sound, ast_bridge_config::warning_sound, and xfersound.

Referenced by ast_features_init().

07532 {
07533    struct ast_channel *current_dest_chan, *final_dest_chan, *chans[2];
07534    char *tmp_data  = NULL;
07535    struct ast_flags opts = { 0, };
07536    struct ast_bridge_config bconfig = { { 0, }, };
07537    char *opt_args[OPT_ARG_ARRAY_SIZE];
07538    struct timeval calldurationlimit = { 0, };
07539 
07540    AST_DECLARE_APP_ARGS(args,
07541       AST_APP_ARG(dest_chan);
07542       AST_APP_ARG(options);
07543    );
07544 
07545    if (ast_strlen_zero(data)) {
07546       ast_log(LOG_WARNING, "Bridge require at least 1 argument specifying the other end of the bridge\n");
07547       return -1;
07548    }
07549 
07550    tmp_data = ast_strdupa(data);
07551    AST_STANDARD_APP_ARGS(args, tmp_data);
07552    if (!ast_strlen_zero(args.options))
07553       ast_app_parse_options(bridge_exec_options, &opts, opt_args, args.options);
07554 
07555    /* avoid bridge with ourselves */
07556    if (!strcmp(chan->name, args.dest_chan)) {
07557       ast_log(LOG_WARNING, "Unable to bridge channel %s with itself\n", chan->name);
07558       ast_manager_event(chan, EVENT_FLAG_CALL, "BridgeExec",
07559          "Response: Failed\r\n"
07560          "Reason: Unable to bridge channel to itself\r\n"
07561          "Channel1: %s\r\n"
07562          "Channel2: %s\r\n",
07563          chan->name, args.dest_chan);
07564       pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "LOOP");
07565       return 0;
07566    }
07567 
07568    /* make sure we have a valid end point */
07569    if (!(current_dest_chan = ast_channel_get_by_name_prefix(args.dest_chan,
07570          strlen(args.dest_chan)))) {
07571       ast_log(LOG_WARNING, "Bridge failed because channel %s does not exist\n",
07572          args.dest_chan);
07573       ast_manager_event(chan, EVENT_FLAG_CALL, "BridgeExec",
07574          "Response: Failed\r\n"
07575          "Reason: Channel2 does not exist\r\n"
07576          "Channel1: %s\r\n"
07577          "Channel2: %s\r\n", chan->name, args.dest_chan);
07578       pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "NONEXISTENT");
07579       return 0;
07580    }
07581 
07582    /* try to allocate a place holder where current_dest_chan will be placed */
07583    if (!(final_dest_chan = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, 
07584       NULL, NULL, current_dest_chan->linkedid, 0, "Bridge/%s", current_dest_chan->name))) {
07585       ast_log(LOG_WARNING, "Cannot create placeholder channel for chan %s\n", args.dest_chan);
07586       ast_manager_event(chan, EVENT_FLAG_CALL, "BridgeExec",
07587          "Response: Failed\r\n"
07588          "Reason: Cannot create placeholder channel\r\n"
07589          "Channel1: %s\r\n"
07590          "Channel2: %s\r\n", chan->name, args.dest_chan);
07591       pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "FAILURE");
07592       ast_channel_unref(current_dest_chan);
07593       return 0;
07594    }
07595 
07596    if (ast_test_flag(&opts, OPT_DURATION_LIMIT)
07597       && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])
07598       && ast_bridge_timelimit(chan, &bconfig, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit)) {
07599       ast_manager_event(chan, EVENT_FLAG_CALL, "BridgeExec",
07600          "Response: Failed\r\n"
07601          "Reason: Cannot setup bridge time limit\r\n"
07602          "Channel1: %s\r\n"
07603          "Channel2: %s\r\n", chan->name, args.dest_chan);
07604       ast_hangup(final_dest_chan);
07605       pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "FAILURE");
07606       current_dest_chan = ast_channel_unref(current_dest_chan);
07607       goto done;
07608    }
07609 
07610    if (do_bridge_masquerade(current_dest_chan, final_dest_chan)) {
07611       ast_manager_event(chan, EVENT_FLAG_CALL, "BridgeExec",
07612          "Response: Failed\r\n"
07613          "Reason: Cannot masquerade channels\r\n"
07614          "Channel1: %s\r\n"
07615          "Channel2: %s\r\n", chan->name, args.dest_chan);
07616       ast_hangup(final_dest_chan);
07617       pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "FAILURE");
07618       current_dest_chan = ast_channel_unref(current_dest_chan);
07619       goto done;
07620    }
07621 
07622    /* answer the channel if needed */
07623    if (final_dest_chan->_state != AST_STATE_UP) {
07624       ast_answer(final_dest_chan);
07625    }
07626 
07627    chans[0] = current_dest_chan;
07628    chans[1] = final_dest_chan;
07629 
07630    /* now current_dest_chan is a ZOMBIE and with softhangup set to 1 and final_dest_chan is our end point */
07631    /* try to make compatible, send error if we fail */
07632    if (ast_channel_make_compatible(chan, final_dest_chan) < 0) {
07633       ast_log(LOG_WARNING, "Could not make channels %s and %s compatible for bridge\n", chan->name, final_dest_chan->name);
07634       ast_manager_event_multichan(EVENT_FLAG_CALL, "BridgeExec", 2, chans,
07635          "Response: Failed\r\n"
07636          "Reason: Could not make channels compatible for bridge\r\n"
07637          "Channel1: %s\r\n"
07638          "Channel2: %s\r\n", chan->name, final_dest_chan->name);
07639 
07640       /* Maybe we should return this channel to the PBX? */
07641       ast_hangup(final_dest_chan);
07642 
07643       pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "INCOMPATIBLE");
07644       current_dest_chan = ast_channel_unref(current_dest_chan);
07645       goto done;
07646    }
07647 
07648    /* Report that the bridge will be successfull */
07649    ast_manager_event_multichan(EVENT_FLAG_CALL, "BridgeExec", 2, chans,
07650       "Response: Success\r\n"
07651       "Channel1: %s\r\n"
07652       "Channel2: %s\r\n", chan->name, final_dest_chan->name);
07653 
07654    current_dest_chan = ast_channel_unref(current_dest_chan);
07655 
07656    /* we have 2 valid channels to bridge, now it is just a matter of setting up the bridge config and starting the bridge */  
07657    if (ast_test_flag(&opts, BRIDGE_OPT_PLAYTONE) && !ast_strlen_zero(xfersound)) {
07658       if (!ast_streamfile(final_dest_chan, xfersound, final_dest_chan->language)) {
07659          if (ast_waitstream(final_dest_chan, "") < 0)
07660             ast_log(LOG_WARNING, "Failed to play courtesy tone on %s\n", final_dest_chan->name);
07661       }
07662    }
07663 
07664    if (ast_test_flag(&opts, OPT_CALLEE_TRANSFER))
07665       ast_set_flag(&(bconfig.features_callee), AST_FEATURE_REDIRECT);
07666    if (ast_test_flag(&opts, OPT_CALLER_TRANSFER))
07667       ast_set_flag(&(bconfig.features_caller), AST_FEATURE_REDIRECT);
07668    if (ast_test_flag(&opts, OPT_CALLEE_HANGUP))
07669       ast_set_flag(&(bconfig.features_callee), AST_FEATURE_DISCONNECT);
07670    if (ast_test_flag(&opts, OPT_CALLER_HANGUP))
07671       ast_set_flag(&(bconfig.features_caller), AST_FEATURE_DISCONNECT);
07672    if (ast_test_flag(&opts, OPT_CALLEE_MONITOR))
07673       ast_set_flag(&(bconfig.features_callee), AST_FEATURE_AUTOMON);
07674    if (ast_test_flag(&opts, OPT_CALLER_MONITOR))
07675       ast_set_flag(&(bconfig.features_caller), AST_FEATURE_AUTOMON);
07676    if (ast_test_flag(&opts, OPT_CALLEE_PARK))
07677       ast_set_flag(&(bconfig.features_callee), AST_FEATURE_PARKCALL);
07678    if (ast_test_flag(&opts, OPT_CALLER_PARK))
07679       ast_set_flag(&(bconfig.features_caller), AST_FEATURE_PARKCALL);
07680 
07681    /*
07682     * Don't let the after-bridge code run the h-exten.  We want to
07683     * continue in the dialplan.
07684     */
07685    ast_set_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT);
07686    ast_bridge_call(chan, final_dest_chan, &bconfig);
07687 
07688    /* The bridge has ended, set BRIDGERESULT to SUCCESS. */
07689    pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "SUCCESS");
07690 
07691    /* If the other channel has not been hung up, return it to the PBX */
07692    if (!ast_check_hangup(final_dest_chan)) {
07693       if (!ast_test_flag(&opts, OPT_CALLEE_KILL)) {
07694          ast_debug(1, "starting new PBX in %s,%s,%d for chan %s\n",
07695             final_dest_chan->context, final_dest_chan->exten,
07696             final_dest_chan->priority, final_dest_chan->name);
07697 
07698          if (ast_pbx_start(final_dest_chan)) {
07699             ast_log(LOG_WARNING, "FAILED continuing PBX on dest chan %s\n", final_dest_chan->name);
07700             ast_hangup(final_dest_chan);
07701          } else {
07702             ast_debug(1, "SUCCESS continuing PBX on chan %s\n", final_dest_chan->name);
07703          }
07704       } else {
07705          ast_hangup(final_dest_chan);
07706       }
07707    } else {
07708       ast_debug(1, "chan %s was hungup\n", final_dest_chan->name);
07709       ast_hangup(final_dest_chan);
07710    }
07711 done:
07712    ast_free((char *) bconfig.warning_sound);
07713    ast_free((char *) bconfig.end_sound);
07714    ast_free((char *) bconfig.start_sound);
07715 
07716    return 0;
07717 }

static struct parking_dp_context* build_dialplan_useage_context ( struct ast_parkinglot *  lot  )  [static, read]

Definition at line 6204 of file features.c.

References ast_calloc, ast_parkinglot::cfg, parking_dp_context::context, destroy_dialplan_usage_context(), dialplan_usage_add_parkinglot_data(), and parkinglot_cfg::parking_con.

Referenced by dialplan_usage_add_parkinglot().

06205 {
06206    struct parking_dp_context *ctx_node;
06207 
06208    ctx_node = ast_calloc(1, sizeof(*ctx_node) + strlen(lot->cfg.parking_con));
06209    if (!ctx_node) {
06210       return NULL;
06211    }
06212    if (dialplan_usage_add_parkinglot_data(ctx_node, lot, 0)) {
06213       destroy_dialplan_usage_context(ctx_node);
06214       return NULL;
06215    }
06216    strcpy(ctx_node->context, lot->cfg.parking_con);
06217    return ctx_node;
06218 }

static int build_dialplan_useage_map ( struct parking_dp_map *  usage_map,
int  complain 
) [static]

Definition at line 6276 of file features.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, dialplan_usage_add_parkinglot(), parkinglots, and status.

Referenced by load_config().

06277 {
06278    int status = 0;
06279    struct ao2_iterator iter;
06280    struct ast_parkinglot *curlot;
06281 
06282    /* For all parking lots */
06283    iter = ao2_iterator_init(parkinglots, 0);
06284    for (; (curlot = ao2_iterator_next(&iter)); ao2_ref(curlot, -1)) {
06285       /* Add the parking lot to the map. */
06286       if (dialplan_usage_add_parkinglot(usage_map, curlot, complain)) {
06287          ao2_ref(curlot, -1);
06288          status = -1;
06289          break;
06290       }
06291    }
06292    ao2_iterator_destroy(&iter);
06293 
06294    return status;
06295 }

static struct parking_dp_ramp* build_dialplan_useage_ramp ( const char *  exten,
int  exclusive 
) [static, read]

Definition at line 5967 of file features.c.

References ast_calloc, parking_dp_ramp::exclusive, and parking_dp_ramp::exten.

Referenced by usage_context_add_ramp().

05968 {
05969    struct parking_dp_ramp *ramp_node;
05970 
05971    ramp_node = ast_calloc(1, sizeof(*ramp_node) + strlen(exten));
05972    if (!ramp_node) {
05973       return NULL;
05974    }
05975    ramp_node->exclusive = exclusive;
05976    strcpy(ramp_node->exten, exten);
05977    return ramp_node;
05978 }

static struct parking_dp_spaces* build_dialplan_useage_spaces ( int  start,
int  stop 
) [static, read]

Definition at line 6048 of file features.c.

References ast_calloc, parking_dp_spaces::start, and parking_dp_spaces::stop.

Referenced by usage_context_add_spaces().

06049 {
06050    struct parking_dp_spaces *spaces_node;
06051 
06052    spaces_node = ast_calloc(1, sizeof(*spaces_node));
06053    if (!spaces_node) {
06054       return NULL;
06055    }
06056    spaces_node->start = start;
06057    spaces_node->stop = stop;
06058    return spaces_node;
06059 }

static struct ast_parkinglot* build_parkinglot ( const char *  pl_name,
struct ast_variable *  var 
) [static, read]

Build parkinglot from configuration and chain it in if it doesn't already exist.

Definition at line 5569 of file features.c.

References ao2_link, ao2_lock, ao2_unlock, ast_debug, AST_LIST_EMPTY, ast_log(), ast_parkinglot::cfg, create_parkinglot(), DEFAULT_PARKINGLOT, find_parkinglot(), force_reload_load, LOG_WARNING, ast_parkinglot::name, parkinglot_config_read(), parkinglot_unref(), parkinglots, ast_parkinglot::parkings, and ast_parkinglot::the_mark.

Referenced by load_config(), and process_config().

05570 {
05571    struct ast_parkinglot *parkinglot;
05572    const struct parkinglot_cfg *cfg_defaults;
05573    struct parkinglot_cfg new_cfg;
05574    int cfg_error;
05575    int oldparkinglot = 0;
05576 
05577    parkinglot = find_parkinglot(pl_name);
05578    if (parkinglot) {
05579       oldparkinglot = 1;
05580    } else {
05581       parkinglot = create_parkinglot(pl_name);
05582       if (!parkinglot) {
05583          return NULL;
05584       }
05585    }
05586    if (!strcmp(parkinglot->name, DEFAULT_PARKINGLOT)) {
05587       cfg_defaults = &parkinglot_cfg_default_default;
05588    } else {
05589       cfg_defaults = &parkinglot_cfg_default;
05590    }
05591    new_cfg = *cfg_defaults;
05592 
05593    ast_debug(1, "Building parking lot %s\n", parkinglot->name);
05594 
05595    ao2_lock(parkinglot);
05596 
05597    /* Do some config stuff */
05598    cfg_error = parkinglot_config_read(parkinglot->name, &new_cfg, var);
05599    if (oldparkinglot) {
05600       if (cfg_error) {
05601          /* Bad configuration read.  Keep using the original config. */
05602          ast_log(LOG_WARNING, "Changes to parking lot %s are discarded.\n",
05603             parkinglot->name);
05604          cfg_error = 0;
05605       } else if (!AST_LIST_EMPTY(&parkinglot->parkings)
05606          && memcmp(&new_cfg, &parkinglot->cfg, sizeof(parkinglot->cfg))) {
05607          /* Try reloading later when parking lot is empty. */
05608          ast_log(LOG_WARNING,
05609             "Parking lot %s has parked calls.  Parking lot changes discarded.\n",
05610             parkinglot->name);
05611          force_reload_load = 1;
05612       } else {
05613          /* Accept the new config */
05614          parkinglot->cfg = new_cfg;
05615       }
05616    } else {
05617       /* Load the initial parking lot config. */
05618       parkinglot->cfg = new_cfg;
05619    }
05620    parkinglot->the_mark = 0;
05621 
05622    ao2_unlock(parkinglot);
05623 
05624    if (cfg_error) {
05625       /* Only new parking lots could have config errors here. */
05626       ast_log(LOG_WARNING, "New parking lot %s is discarded.\n", parkinglot->name);
05627       parkinglot_unref(parkinglot);
05628       return NULL;
05629    }
05630 
05631    /* Move it into the list, if it wasn't already there */
05632    if (!oldparkinglot) {
05633       ao2_link(parkinglots, parkinglot);
05634    }
05635    parkinglot_unref(parkinglot);
05636 
05637    return parkinglot;
05638 }

static int builtin_atxfer ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
void *  data 
) [static]

Attended transfer.

Parameters:
chan transfered user
peer person transfering call
config 
code 
sense feature options
data Get extension to transfer to, if you cannot generate channel (or find extension) return to host channel. After called channel answered wait for hangup of transferer, bridge call between transfer peer (taking them off hold) to attended transfer channel.
Returns:
-1 on failure

Definition at line 2469 of file features.c.

References ast_channel::_state, add_features_datastore(), ast_app_dtget(), ast_autoservice_start(), ast_autoservice_stop(), ast_best_codec(), ast_bridge_call(), ast_calloc, AST_CEL_ATTENDEDTRANSFER, ast_cel_report_event(), ast_channel_alloc, ast_channel_connected_line_macro(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_masquerade(), ast_channel_unlock, ast_channel_update_connected_line(), ast_check_hangup(), ast_clear_flag, ast_connected_line_copy_from_caller(), AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_copy_flags, ast_debug, AST_DIGIT_ANY, ast_do_masquerade(), ast_explicit_goto(), AST_FEATURE_DISCONNECT, AST_FEATURE_RETURN_SUCCESS, AST_FLAG_BRIDGE_HANGUP_DONT, AST_FLAGS_ALL, ast_hangup(), ast_indicate(), ast_log(), ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_safe_sleep(), ast_set_flag, AST_STATE_DOWN, AST_STATE_UP, ast_strdupa, ast_stream_and_wait(), ast_strlen_zero(), ast_test_flag, ast_waitfordigit(), atxfer_fail_cleanup(), atxfercallbackretries, atxferdropcall, atxferloopdelay, atxfernoanswertimeout, ast_bridge_thread_obj::bconfig, bridge_call_thread_launch(), ast_channel::caller, ast_bridge_thread_obj::chan, check_compat(), ast_channel::connected, ast_channel::context, ast_datastore::data, dial_features_info, ast_bridge_config::end_bridge_callback_data_fixup, ast_channel::exten, feature_request_and_dial(), ast_bridge_config::features_callee, ast_bridge_config::features_caller, finishup(), get_parking_exten(), LOG_WARNING, ast_dial_features::my_features, ast_channel::nativeformats, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), ast_bridge_thread_obj::peer, ast_dial_features::peer_features, ast_channel::priority, ast_channel::readformat, real_ctx(), set_peers(), ast_party_connected_line::source, transferdigittimeout, ast_channel::visible_indication, ast_channel::writeformat, xfer_park_call_helper(), xferfailsound, and xfersound.

02470 {
02471    struct ast_channel *transferer;/* Party B */
02472    struct ast_channel *transferee;/* Party A */
02473    struct ast_exten *park_exten;
02474    const char *chan1_attended_sound;
02475    const char *chan2_attended_sound;
02476    const char *transferer_real_context;
02477    char xferto[256] = "";
02478    int res;
02479    int outstate=0;
02480    struct ast_channel *newchan;
02481    struct ast_channel *xferchan;
02482    struct ast_bridge_thread_obj *tobj;
02483    struct ast_bridge_config bconfig;
02484    int l;
02485    struct ast_party_connected_line connected_line;
02486    struct ast_datastore *features_datastore;
02487    struct ast_dial_features *dialfeatures;
02488    char *transferer_tech;
02489    char *transferer_name;
02490    char *transferer_name_orig;
02491    char *dash;
02492 
02493    ast_debug(1, "Executing Attended Transfer %s, %s (sense=%d) \n", chan->name, peer->name, sense);
02494    set_peers(&transferer, &transferee, peer, chan, sense);
02495    transferer_real_context = real_ctx(transferer, transferee);
02496 
02497    /* Start autoservice on transferee while we talk to the transferer */
02498    ast_autoservice_start(transferee);
02499    ast_indicate(transferee, AST_CONTROL_HOLD);
02500 
02501    /* Transfer */
02502    res = ast_stream_and_wait(transferer, "pbx-transfer", AST_DIGIT_ANY);
02503    if (res < 0) {
02504       finishup(transferee);
02505       return -1;
02506    }
02507    if (res > 0) { /* If they've typed a digit already, handle it */
02508       xferto[0] = (char) res;
02509    }
02510 
02511    /* this is specific of atxfer */
02512    res = ast_app_dtget(transferer, transferer_real_context, xferto, sizeof(xferto), 100, transferdigittimeout);
02513    if (res < 0) {  /* hangup or error, (would be 0 for invalid and 1 for valid) */
02514       finishup(transferee);
02515       return -1;
02516    }
02517    l = strlen(xferto);
02518    if (res == 0) {
02519       if (l) {
02520          ast_log(LOG_WARNING, "Extension '%s' does not exist in context '%s'\n",
02521             xferto, transferer_real_context);
02522       } else {
02523          /* Does anyone care about this case? */
02524          ast_log(LOG_WARNING, "No digits dialed for atxfer.\n");
02525       }
02526       ast_stream_and_wait(transferer, "pbx-invalid", "");
02527       finishup(transferee);
02528       return AST_FEATURE_RETURN_SUCCESS;
02529    }
02530 
02531    park_exten = get_parking_exten(xferto, transferer, transferer_real_context);
02532    if (park_exten) {
02533       /* We are transfering the transferee to a parking lot. */
02534       return xfer_park_call_helper(transferee, transferer, park_exten);
02535    }
02536 
02537    /*
02538     * Append context to dialed transfer number.
02539     *
02540     * NOTE: The local channel needs the /n flag so party C will use
02541     * the feature flags set by the dialplan when calling that
02542     * party.
02543     */
02544    snprintf(xferto + l, sizeof(xferto) - l, "@%s/n", transferer_real_context);
02545 
02546    /* If we are performing an attended transfer and we have two channels involved then
02547       copy sound file information to play upon attended transfer completion */
02548    chan1_attended_sound = pbx_builtin_getvar_helper(transferer, "ATTENDED_TRANSFER_COMPLETE_SOUND");
02549    chan2_attended_sound = pbx_builtin_getvar_helper(transferee, "ATTENDED_TRANSFER_COMPLETE_SOUND");
02550    if (!ast_strlen_zero(chan1_attended_sound)) {
02551       pbx_builtin_setvar_helper(transferer, "BRIDGE_PLAY_SOUND", chan1_attended_sound);
02552    }
02553    if (!ast_strlen_zero(chan2_attended_sound)) {
02554       pbx_builtin_setvar_helper(transferee, "BRIDGE_PLAY_SOUND", chan2_attended_sound);
02555    }
02556 
02557    /* Extract redial transferer information from the channel name. */
02558    transferer_name_orig = ast_strdupa(transferer->name);
02559    transferer_name = ast_strdupa(transferer_name_orig);
02560    transferer_tech = strsep(&transferer_name, "/");
02561    dash = strrchr(transferer_name, '-');
02562    if (dash) {
02563       /* Trim off channel name sequence/serial number. */
02564       *dash = '\0';
02565    }
02566 
02567    /* Stop autoservice so we can monitor all parties involved in the transfer. */
02568    if (ast_autoservice_stop(transferee) < 0) {
02569       ast_indicate(transferee, AST_CONTROL_UNHOLD);
02570       return -1;
02571    }
02572 
02573    /* Save connected line info for party B about party A in case transfer fails. */
02574    ast_party_connected_line_init(&connected_line);
02575    ast_channel_lock(transferer);
02576    ast_party_connected_line_copy(&connected_line, &transferer->connected);
02577    ast_channel_unlock(transferer);
02578    connected_line.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
02579 
02580    /* Dial party C */
02581    newchan = feature_request_and_dial(transferer, transferer_name_orig, transferer,
02582       transferee, "Local", ast_best_codec(transferer->nativeformats), xferto,
02583       atxfernoanswertimeout, &outstate, transferer->language);
02584    ast_debug(2, "Dial party C result: newchan:%d, outstate:%d\n", !!newchan, outstate);
02585 
02586    if (!ast_check_hangup(transferer)) {
02587       int hangup_dont = 0;
02588 
02589       /* Transferer (party B) is up */
02590       ast_debug(1, "Actually doing an attended transfer.\n");
02591 
02592       /* Start autoservice on transferee while the transferer deals with party C. */
02593       ast_autoservice_start(transferee);
02594 
02595       ast_indicate(transferer, -1);
02596       if (!newchan) {
02597          /* any reason besides user requested cancel and busy triggers the failed sound */
02598          switch (outstate) {
02599          case AST_CONTROL_UNHOLD:/* Caller requested cancel or party C answer timeout. */
02600          case AST_CONTROL_BUSY:
02601          case AST_CONTROL_CONGESTION:
02602             if (ast_stream_and_wait(transferer, xfersound, "")) {
02603                ast_log(LOG_WARNING, "Failed to play transfer sound!\n");
02604             }
02605             break;
02606          default:
02607             if (ast_stream_and_wait(transferer, xferfailsound, "")) {
02608                ast_log(LOG_WARNING, "Failed to play transfer failed sound!\n");
02609             }
02610             break;
02611          }
02612          atxfer_fail_cleanup(transferee, transferer, &connected_line);
02613          return AST_FEATURE_RETURN_SUCCESS;
02614       }
02615 
02616       if (check_compat(transferer, newchan)) {
02617          if (ast_stream_and_wait(transferer, xferfailsound, "")) {
02618             ast_log(LOG_WARNING, "Failed to play transfer failed sound!\n");
02619          }
02620          atxfer_fail_cleanup(transferee, transferer, &connected_line);
02621          return AST_FEATURE_RETURN_SUCCESS;
02622       }
02623       memset(&bconfig,0,sizeof(struct ast_bridge_config));
02624       ast_set_flag(&(bconfig.features_caller), AST_FEATURE_DISCONNECT);
02625       ast_set_flag(&(bconfig.features_callee), AST_FEATURE_DISCONNECT);
02626 
02627       /*
02628        * ast_bridge_call clears AST_FLAG_BRIDGE_HANGUP_DONT, but we
02629        * don't want that to happen here because the transferer is in
02630        * another bridge already.
02631        */
02632       if (ast_test_flag(transferer, AST_FLAG_BRIDGE_HANGUP_DONT)) {
02633          hangup_dont = 1;
02634       }
02635 
02636       /*
02637        * Don't let the after-bridge code run the h-exten.  It is the
02638        * wrong bridge to run the h-exten after.
02639        */
02640       ast_set_flag(transferer, AST_FLAG_BRIDGE_HANGUP_DONT);
02641 
02642       /*
02643        * Let party B and C talk as long as they want while party A
02644        * languishes in autoservice listening to MOH.
02645        */
02646       ast_bridge_call(transferer, newchan, &bconfig);
02647 
02648       if (hangup_dont) {
02649          /* Restore the AST_FLAG_BRIDGE_HANGUP_DONT flag */
02650          ast_set_flag(transferer, AST_FLAG_BRIDGE_HANGUP_DONT);
02651       }
02652 
02653       if (ast_check_hangup(newchan) || !ast_check_hangup(transferer)) {
02654          ast_hangup(newchan);
02655          if (ast_stream_and_wait(transferer, xfersound, "")) {
02656             ast_log(LOG_WARNING, "Failed to play transfer sound!\n");
02657          }
02658          atxfer_fail_cleanup(transferee, transferer, &connected_line);
02659          return AST_FEATURE_RETURN_SUCCESS;
02660       }
02661 
02662       /* Transferer (party B) is confirmed hung up at this point. */
02663       if (check_compat(transferee, newchan)) {
02664          finishup(transferee);
02665          ast_party_connected_line_free(&connected_line);
02666          return -1;
02667       }
02668 
02669       ast_indicate(transferee, AST_CONTROL_UNHOLD);
02670       if ((ast_autoservice_stop(transferee) < 0)
02671          || (ast_waitfordigit(transferee, 100) < 0)
02672          || (ast_waitfordigit(newchan, 100) < 0)
02673          || ast_check_hangup(transferee)
02674          || ast_check_hangup(newchan)) {
02675          ast_hangup(newchan);
02676          ast_party_connected_line_free(&connected_line);
02677          return -1;
02678       }
02679    } else if (!ast_check_hangup(transferee)) {
02680       /* Transferer (party B) has hung up at this point.  Doing blonde transfer. */
02681       ast_debug(1, "Actually doing a blonde transfer.\n");
02682 
02683       if (!newchan && !atxferdropcall) {
02684          /* Party C is not available, try to call party B back. */
02685          unsigned int tries = 0;
02686 
02687          if (ast_strlen_zero(transferer_name) || ast_strlen_zero(transferer_tech)) {
02688             ast_log(LOG_WARNING,
02689                "Transferer channel name: '%s' cannot be used for callback.\n",
02690                transferer_name_orig);
02691             ast_indicate(transferee, AST_CONTROL_UNHOLD);
02692             ast_party_connected_line_free(&connected_line);
02693             return -1;
02694          }
02695 
02696          tries = 0;
02697          for (;;) {
02698             /* Try to get party B back. */
02699             ast_debug(1, "We're trying to callback %s/%s\n",
02700                transferer_tech, transferer_name);
02701             newchan = feature_request_and_dial(transferer, transferer_name_orig,
02702                transferee, transferee, transferer_tech,
02703                ast_best_codec(transferee->nativeformats), transferer_name,
02704                atxfernoanswertimeout, &outstate, transferer->language);
02705             ast_debug(2, "Dial party B result: newchan:%d, outstate:%d\n",
02706                !!newchan, outstate);
02707             if (newchan) {
02708                /*
02709                 * We have recalled party B (newchan).  We need to give this
02710                 * call leg the same feature flags as the original party B call
02711                 * leg.
02712                 */
02713                ast_channel_lock(transferer);
02714                features_datastore = ast_channel_datastore_find(transferer,
02715                   &dial_features_info, NULL);
02716                if (features_datastore && (dialfeatures = features_datastore->data)) {
02717                   struct ast_flags my_features = { 0 };
02718                   struct ast_flags peer_features = { 0 };
02719 
02720                   ast_copy_flags(&my_features, &dialfeatures->my_features,
02721                      AST_FLAGS_ALL);
02722                   ast_copy_flags(&peer_features, &dialfeatures->peer_features,
02723                      AST_FLAGS_ALL);
02724                   ast_channel_unlock(transferer);
02725                   add_features_datastore(newchan, &my_features, &peer_features);
02726                } else {
02727                   ast_channel_unlock(transferer);
02728                }
02729                break;
02730             }
02731             if (ast_check_hangup(transferee)) {
02732                break;
02733             }
02734 
02735             ++tries;
02736             if (atxfercallbackretries <= tries) {
02737                /* No more callback tries remaining. */
02738                break;
02739             }
02740 
02741             if (atxferloopdelay) {
02742                /* Transfer failed, sleeping */
02743                ast_debug(1, "Sleeping for %d ms before retrying atxfer.\n",
02744                   atxferloopdelay);
02745                ast_safe_sleep(transferee, atxferloopdelay);
02746                if (ast_check_hangup(transferee)) {
02747                   ast_party_connected_line_free(&connected_line);
02748                   return -1;
02749                }
02750             }
02751 
02752             /* Retry dialing party C. */
02753             ast_debug(1, "We're retrying to call %s/%s\n", "Local", xferto);
02754             newchan = feature_request_and_dial(transferer, transferer_name_orig,
02755                transferer, transferee, "Local",
02756                ast_best_codec(transferee->nativeformats), xferto,
02757                atxfernoanswertimeout, &outstate, transferer->language);
02758             ast_debug(2, "Redial party C result: newchan:%d, outstate:%d\n",
02759                !!newchan, outstate);
02760             if (newchan || ast_check_hangup(transferee)) {
02761                break;
02762             }
02763          }
02764       }
02765       ast_indicate(transferee, AST_CONTROL_UNHOLD);
02766       if (!newchan) {
02767          /* No party C or could not callback party B. */
02768          ast_party_connected_line_free(&connected_line);
02769          return -1;
02770       }
02771 
02772       /* newchan is up, we should prepare transferee and bridge them */
02773       if (ast_check_hangup(newchan)) {
02774          ast_hangup(newchan);
02775          ast_party_connected_line_free(&connected_line);
02776          return -1;
02777       }
02778       if (check_compat(transferee, newchan)) {
02779          ast_party_connected_line_free(&connected_line);
02780          return -1;
02781       }
02782    } else {
02783       /*
02784        * Both the transferer and transferee have hungup.  If newchan
02785        * is up, hang it up as it has no one to talk to.
02786        */
02787       ast_debug(1, "Everyone is hungup.\n");
02788       if (newchan) {
02789          ast_hangup(newchan);
02790       }
02791       ast_party_connected_line_free(&connected_line);
02792       return -1;
02793    }
02794 
02795    /* Initiate the channel transfer of party A to party C (or recalled party B). */
02796    ast_cel_report_event(transferee, AST_CEL_ATTENDEDTRANSFER, NULL, NULL, newchan);
02797 
02798    xferchan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", transferee->linkedid, 0, "Transfered/%s", transferee->name);
02799    if (!xferchan) {
02800       ast_hangup(newchan);
02801       ast_party_connected_line_free(&connected_line);
02802       return -1;
02803    }
02804 
02805    /* Give party A a momentary ringback tone during transfer. */
02806    xferchan->visible_indication = AST_CONTROL_RINGING;
02807 
02808    /* Make formats okay */
02809    xferchan->readformat = transferee->readformat;
02810    xferchan->writeformat = transferee->writeformat;
02811 
02812    if (ast_channel_masquerade(xferchan, transferee)) {
02813       ast_hangup(xferchan);
02814       ast_hangup(newchan);
02815       ast_party_connected_line_free(&connected_line);
02816       return -1;
02817    }
02818    ast_explicit_goto(xferchan, transferee->context, transferee->exten, transferee->priority);
02819    xferchan->_state = AST_STATE_UP;
02820    ast_clear_flag(xferchan, AST_FLAGS_ALL);
02821 
02822    /* Do the masquerade manually to make sure that is is completed. */
02823    ast_do_masquerade(xferchan);
02824 
02825    newchan->_state = AST_STATE_UP;
02826    ast_clear_flag(newchan, AST_FLAGS_ALL);
02827    tobj = ast_calloc(1, sizeof(*tobj));
02828    if (!tobj) {
02829       ast_hangup(xferchan);
02830       ast_hangup(newchan);
02831       ast_party_connected_line_free(&connected_line);
02832       return -1;
02833    }
02834 
02835    tobj->chan = newchan;
02836    tobj->peer = xferchan;
02837    tobj->bconfig = *config;
02838 
02839    ast_channel_lock(newchan);
02840    features_datastore = ast_channel_datastore_find(newchan, &dial_features_info, NULL);
02841    if (features_datastore && (dialfeatures = features_datastore->data)) {
02842       ast_copy_flags(&tobj->bconfig.features_callee, &dialfeatures->my_features,
02843          AST_FLAGS_ALL);
02844    }
02845    ast_channel_unlock(newchan);
02846 
02847    ast_channel_lock(xferchan);
02848    features_datastore = ast_channel_datastore_find(xferchan, &dial_features_info, NULL);
02849    if (features_datastore && (dialfeatures = features_datastore->data)) {
02850       ast_copy_flags(&tobj->bconfig.features_caller, &dialfeatures->my_features,
02851          AST_FLAGS_ALL);
02852    }
02853    ast_channel_unlock(xferchan);
02854 
02855    if (tobj->bconfig.end_bridge_callback_data_fixup) {
02856       tobj->bconfig.end_bridge_callback_data_fixup(&tobj->bconfig, tobj->peer, tobj->chan);
02857    }
02858 
02859    /*
02860     * xferchan is transferee, and newchan is the transfer target
02861     * So...in a transfer, who is the caller and who is the callee?
02862     *
02863     * When the call is originally made, it is clear who is caller and callee.
02864     * When a transfer occurs, it is my humble opinion that the transferee becomes
02865     * the caller, and the transfer target is the callee.
02866     *
02867     * The problem is that these macros were set with the intention of the original
02868     * caller and callee taking those roles.  A transfer can totally mess things up,
02869     * to be technical.  What sucks even more is that you can't effectively change
02870     * the macros in the dialplan during the call from the transferer to the transfer
02871     * target because the transferee is stuck with whatever role he originally had.
02872     *
02873     * I think the answer here is just to make sure that it is well documented that
02874     * during a transfer, the transferee is the "caller" and the transfer target
02875     * is the "callee."
02876     *
02877     * This means that if party B calls party A, and party B transfers party A to
02878     * party C, then A has switched roles for the call.  Now party A will have the
02879     * caller macro called on his channel instead of the callee macro.
02880     *
02881     * Luckily, the method by which the party B to party C bridge is
02882     * launched above ensures that the transferee is the "chan" on
02883     * the bridge and the transfer target is the "peer," so my idea
02884     * for the roles post-transfer does not require extensive code
02885     * changes.
02886     */
02887 
02888    /* Transfer party C connected line to party A */
02889    ast_channel_lock(transferer);
02890    /*
02891     * Due to a limitation regarding when callerID is set on a Local channel,
02892     * we use the transferer's connected line information here.
02893     */
02894    ast_party_connected_line_copy(&connected_line, &transferer->connected);
02895    ast_channel_unlock(transferer);
02896    connected_line.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
02897    if (ast_channel_connected_line_macro(newchan, xferchan, &connected_line, 1, 0)) {
02898       ast_channel_update_connected_line(xferchan, &connected_line, NULL);
02899    }
02900 
02901    /* Transfer party A connected line to party C */
02902    ast_channel_lock(xferchan);
02903    ast_connected_line_copy_from_caller(&connected_line, &xferchan->caller);
02904    ast_channel_unlock(xferchan);
02905    connected_line.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
02906    if (ast_channel_connected_line_macro(xferchan, newchan, &connected_line, 0, 0)) {
02907       ast_channel_update_connected_line(newchan, &connected_line, NULL);
02908    }
02909 
02910    if (ast_stream_and_wait(newchan, xfersound, ""))
02911       ast_log(LOG_WARNING, "Failed to play transfer sound!\n");
02912    bridge_call_thread_launch(tobj);
02913 
02914    ast_party_connected_line_free(&connected_line);
02915    return -1;/* The transferee is masqueraded and the original bridged channels can be hungup. */
02916 }

static int builtin_automixmonitor ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
void *  data 
) [static]

Definition at line 2148 of file features.c.

References args, AST_AUDIOHOOK_TYPE_SPY, ast_autoservice_ignore(), ast_autoservice_start(), ast_autoservice_stop(), ast_channel_audiohook_count_by_source(), ast_channel_audiohook_count_by_source_running(), ast_channel_lock, ast_channel_unlock, AST_FEATURE_RETURN_SUCCESS, AST_FRAME_DTMF_END, ast_log(), ast_strdupa, ast_stream_and_wait(), ast_strlen_zero(), ast_verb, ast_channel::caller, courtesytone, ast_party_caller::id, LOG_ERROR, LOG_WARNING, mixmonitor_app, mixmonitor_ok, mixmonitor_spy_type, ast_party_id::number, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), S_COR, S_OR, set_peers(), stopmixmonitor_app, stopmixmonitor_ok, ast_party_number::str, and ast_party_number::valid.

02149 {
02150    char *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL, *touch_filename = NULL;
02151    int x = 0;
02152    size_t len;
02153    struct ast_channel *caller_chan, *callee_chan;
02154    const char *mixmonitor_spy_type = "MixMonitor";
02155    const char *touch_format;
02156    const char *touch_monitor;
02157    int count = 0;
02158 
02159    if (!mixmonitor_ok) {
02160       ast_log(LOG_ERROR,"Cannot record the call. The mixmonitor application is disabled.\n");
02161       return -1;
02162    }
02163 
02164    if (!(mixmonitor_app = pbx_findapp("MixMonitor"))) {
02165       mixmonitor_ok = 0;
02166       ast_log(LOG_ERROR,"Cannot record the call. The mixmonitor application is disabled.\n");
02167       return -1;
02168    }
02169 
02170    set_peers(&caller_chan, &callee_chan, peer, chan, sense);
02171 
02172    if (!ast_strlen_zero(courtesytone)) {
02173       if (ast_autoservice_start(callee_chan))
02174          return -1;
02175       ast_autoservice_ignore(callee_chan, AST_FRAME_DTMF_END);
02176       if (ast_stream_and_wait(caller_chan, courtesytone, "")) {
02177          ast_log(LOG_WARNING, "Failed to play courtesy tone!\n");
02178          ast_autoservice_stop(callee_chan);
02179          return -1;
02180       }
02181       if (ast_autoservice_stop(callee_chan))
02182          return -1;
02183    }
02184 
02185    ast_channel_lock(callee_chan);
02186    count = ast_channel_audiohook_count_by_source(callee_chan, mixmonitor_spy_type, AST_AUDIOHOOK_TYPE_SPY);
02187    ast_channel_unlock(callee_chan);
02188 
02189    /* This means a mixmonitor is attached to the channel, running or not is unknown. */
02190    if (count > 0) {
02191       ast_verb(3, "User hit '%s' to stop recording call.\n", code);
02192 
02193       /* Make sure they are running */
02194       ast_channel_lock(callee_chan);
02195       count = ast_channel_audiohook_count_by_source_running(callee_chan, mixmonitor_spy_type, AST_AUDIOHOOK_TYPE_SPY);
02196       ast_channel_unlock(callee_chan);
02197       if (count > 0) {
02198          if (!stopmixmonitor_ok) {
02199             ast_log(LOG_ERROR,"Cannot stop recording the call. The stopmixmonitor application is disabled.\n");
02200             return -1;
02201          }
02202          if (!(stopmixmonitor_app = pbx_findapp("StopMixMonitor"))) {
02203             stopmixmonitor_ok = 0;
02204             ast_log(LOG_ERROR,"Cannot stop recording the call. The stopmixmonitor application is disabled.\n");
02205             return -1;
02206          } else {
02207             pbx_exec(callee_chan, stopmixmonitor_app, "");
02208             return AST_FEATURE_RETURN_SUCCESS;
02209          }
02210       }
02211       
02212       ast_log(LOG_WARNING,"Stopped MixMonitors are attached to the channel.\n"); 
02213    }        
02214 
02215    touch_format = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MIXMONITOR_FORMAT");
02216    touch_monitor = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MIXMONITOR");
02217 
02218    if (!touch_format)
02219       touch_format = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MIXMONITOR_FORMAT");
02220 
02221    if (!touch_monitor)
02222       touch_monitor = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MIXMONITOR");
02223 
02224    if (touch_monitor) {
02225       len = strlen(touch_monitor) + 50;
02226       args = alloca(len);
02227       touch_filename = alloca(len);
02228       snprintf(touch_filename, len, "auto-%ld-%s", (long)time(NULL), touch_monitor);
02229       snprintf(args, len, "%s.%s,b", touch_filename, (touch_format) ? touch_format : "wav");
02230    } else {
02231       caller_chan_id = ast_strdupa(S_COR(caller_chan->caller.id.number.valid,
02232          caller_chan->caller.id.number.str, caller_chan->name));
02233       callee_chan_id = ast_strdupa(S_COR(callee_chan->caller.id.number.valid,
02234          callee_chan->caller.id.number.str, callee_chan->name));
02235       len = strlen(caller_chan_id) + strlen(callee_chan_id) + 50;
02236       args = alloca(len);
02237       touch_filename = alloca(len);
02238       snprintf(touch_filename, len, "auto-%ld-%s-%s", (long)time(NULL), caller_chan_id, callee_chan_id);
02239       snprintf(args, len, "%s.%s,b", touch_filename, S_OR(touch_format, "wav"));
02240    }
02241 
02242    for( x = 0; x < strlen(args); x++) {
02243       if (args[x] == '/')
02244          args[x] = '-';
02245    }
02246 
02247    ast_verb(3, "User hit '%s' to record call. filename: %s\n", code, touch_filename);
02248 
02249    pbx_exec(callee_chan, mixmonitor_app, args);
02250    pbx_builtin_setvar_helper(callee_chan, "TOUCH_MIXMONITOR_OUTPUT", touch_filename);
02251    pbx_builtin_setvar_helper(caller_chan, "TOUCH_MIXMONITOR_OUTPUT", touch_filename);
02252    return AST_FEATURE_RETURN_SUCCESS;
02253 }

static int builtin_automonitor ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
void *  data 
) [static]

Monitor a channel by DTMF.

Parameters:
chan channel requesting monitor
peer channel to be monitored
config 
code 
sense feature options
data Check monitor app enabled, setup channels, both caller/callee chans not null get TOUCH_MONITOR variable for filename if exists, exec monitor app.
Return values:
AST_FEATURE_RETURN_SUCCESS on success.
-1 on error.

Definition at line 2055 of file features.c.

References args, AST_FEATURE_RETURN_SUCCESS, ast_log(), ast_strdupa, ast_strlen_zero(), ast_verb, ast_channel::caller, courtesytone, ast_party_caller::id, LOG_ERROR, ast_channel::monitor, monitor_app, monitor_ok, ast_party_id::number, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), play_message_in_bridged_call(), S_COR, S_OR, set_peers(), ast_channel_monitor::stop, ast_party_number::str, and ast_party_number::valid.

02056 {
02057    char *caller_chan_id = NULL, *callee_chan_id = NULL, *args = NULL, *touch_filename = NULL;
02058    int x = 0;
02059    size_t len;
02060    struct ast_channel *caller_chan, *callee_chan;
02061    const char *automon_message_start = NULL;
02062    const char *automon_message_stop = NULL;
02063    const char *touch_format = NULL;
02064    const char *touch_monitor = NULL;
02065    const char *touch_monitor_prefix = NULL;
02066 
02067    if (!monitor_ok) {
02068       ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
02069       return -1;
02070    }
02071 
02072    if (!monitor_app && !(monitor_app = pbx_findapp("Monitor"))) {
02073       monitor_ok = 0;
02074       ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
02075       return -1;
02076    }
02077 
02078    set_peers(&caller_chan, &callee_chan, peer, chan, sense);
02079 
02080    /* Find extra messages */
02081    automon_message_start = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_MESSAGE_START");
02082    automon_message_stop = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_MESSAGE_STOP");
02083 
02084    if (!ast_strlen_zero(courtesytone)) {  /* Play courtesy tone if configured */
02085       if(play_message_in_bridged_call(caller_chan, callee_chan, courtesytone) == -1) {
02086          return -1;
02087       }
02088    }
02089    
02090    if (callee_chan->monitor) {
02091       ast_verb(4, "User hit '%s' to stop recording call.\n", code);
02092       if (!ast_strlen_zero(automon_message_stop)) {
02093          play_message_in_bridged_call(caller_chan, callee_chan, automon_message_stop);
02094       }
02095       callee_chan->monitor->stop(callee_chan, 1);
02096       return AST_FEATURE_RETURN_SUCCESS;
02097    }
02098 
02099    touch_format = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_FORMAT");
02100    touch_monitor = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR");
02101    touch_monitor_prefix = pbx_builtin_getvar_helper(caller_chan, "TOUCH_MONITOR_PREFIX");
02102 
02103    if (!touch_format)
02104       touch_format = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR_FORMAT");
02105 
02106    if (!touch_monitor)
02107       touch_monitor = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR");
02108 
02109    if (!touch_monitor_prefix)
02110       touch_monitor_prefix = pbx_builtin_getvar_helper(callee_chan, "TOUCH_MONITOR_PREFIX");
02111 
02112    if (touch_monitor) {
02113       len = strlen(touch_monitor) + 50;
02114       args = alloca(len);
02115       touch_filename = alloca(len);
02116       snprintf(touch_filename, len, "%s-%ld-%s", S_OR(touch_monitor_prefix, "auto"), (long)time(NULL), touch_monitor);
02117       snprintf(args, len, "%s,%s,m", S_OR(touch_format, "wav"), touch_filename);
02118    } else {
02119       caller_chan_id = ast_strdupa(S_COR(caller_chan->caller.id.number.valid,
02120          caller_chan->caller.id.number.str, caller_chan->name));
02121       callee_chan_id = ast_strdupa(S_COR(callee_chan->caller.id.number.valid,
02122          callee_chan->caller.id.number.str, callee_chan->name));
02123       len = strlen(caller_chan_id) + strlen(callee_chan_id) + 50;
02124       args = alloca(len);
02125       touch_filename = alloca(len);
02126       snprintf(touch_filename, len, "%s-%ld-%s-%s", S_OR(touch_monitor_prefix, "auto"), (long)time(NULL), caller_chan_id, callee_chan_id);
02127       snprintf(args, len, "%s,%s,m", S_OR(touch_format, "wav"), touch_filename);
02128    }
02129 
02130    for(x = 0; x < strlen(args); x++) {
02131       if (args[x] == '/')
02132          args[x] = '-';
02133    }
02134    
02135    ast_verb(4, "User hit '%s' to record call. filename: %s\n", code, args);
02136 
02137    pbx_exec(callee_chan, monitor_app, args);
02138    pbx_builtin_setvar_helper(callee_chan, "TOUCH_MONITOR_OUTPUT", touch_filename);
02139    pbx_builtin_setvar_helper(caller_chan, "TOUCH_MONITOR_OUTPUT", touch_filename);
02140 
02141    if (!ast_strlen_zero(automon_message_start)) {  /* Play start message for both channels */
02142       play_message_in_bridged_call(caller_chan, callee_chan, automon_message_start);
02143    }
02144 
02145    return AST_FEATURE_RETURN_SUCCESS;
02146 }

static int builtin_blindtransfer ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
void *  data 
) [static]

Blind transfer user to another extension.

Parameters:
chan channel to be transfered
peer channel initiated blind transfer
config 
code 
data 
sense feature options

Place chan on hold, check if transferred to parkinglot extension, otherwise check extension exists and transfer caller.

Return values:
AST_FEATURE_RETURN_SUCCESS. 
-1 on failure.

Definition at line 2298 of file features.c.

References ast_app_dtget(), ast_async_goto(), ast_autoservice_start(), ast_cdr_alloc(), ast_cdr_init(), ast_cdr_start(), AST_CEL_BLINDTRANSFER, ast_cel_report_event(), ast_channel_lock, ast_channel_unlock, AST_CONTROL_HOLD, ast_debug, AST_DIGIT_ANY, AST_FEATURE_RETURN_SUCCESS, AST_FEATURE_RETURN_SUCCESSBREAK, AST_FLAG_BRIDGE_HANGUP_DONT, ast_indicate(), ast_log(), ast_set_flag, ast_stream_and_wait(), ast_verb, ast_channel::cdr, ast_cdr::channel, check_goto_on_transfer(), ast_cdr::dstchannel, finishup(), get_parking_exten(), ast_cdr::lastapp, ast_cdr::lastdata, LOG_WARNING, ast_channel::pbx, pbx_builtin_setvar_helper(), real_ctx(), set_c_e_p(), set_peers(), transferdigittimeout, and xfer_park_call_helper().

02299 {
02300    struct ast_channel *transferer;
02301    struct ast_channel *transferee;
02302    struct ast_exten *park_exten;
02303    const char *transferer_real_context;
02304    char xferto[256] = "";
02305    int res;
02306 
02307    ast_debug(1, "Executing Blind Transfer %s, %s (sense=%d) \n", chan->name, peer->name, sense);
02308    set_peers(&transferer, &transferee, peer, chan, sense);
02309    transferer_real_context = real_ctx(transferer, transferee);
02310 
02311    /* Start autoservice on transferee while we talk to the transferer */
02312    ast_autoservice_start(transferee);
02313    ast_indicate(transferee, AST_CONTROL_HOLD);
02314 
02315    /* Transfer */
02316    res = ast_stream_and_wait(transferer, "pbx-transfer", AST_DIGIT_ANY);
02317    if (res < 0) {
02318       finishup(transferee);
02319       return -1; /* error ? */
02320    }
02321    if (res > 0) { /* If they've typed a digit already, handle it */
02322       xferto[0] = (char) res;
02323    }
02324 
02325    res = ast_app_dtget(transferer, transferer_real_context, xferto, sizeof(xferto), 100, transferdigittimeout);
02326    if (res < 0) {  /* hangup or error, (would be 0 for invalid and 1 for valid) */
02327       finishup(transferee);
02328       return -1;
02329    }
02330    if (res == 0) {
02331       if (xferto[0]) {
02332          ast_log(LOG_WARNING, "Extension '%s' does not exist in context '%s'\n",
02333             xferto, transferer_real_context);
02334       } else {
02335          /* Does anyone care about this case? */
02336          ast_log(LOG_WARNING, "No digits dialed.\n");
02337       }
02338       ast_stream_and_wait(transferer, "pbx-invalid", "");
02339       finishup(transferee);
02340       return AST_FEATURE_RETURN_SUCCESS;
02341    }
02342 
02343    park_exten = get_parking_exten(xferto, transferer, transferer_real_context);
02344    if (park_exten) {
02345       /* We are transfering the transferee to a parking lot. */
02346       return xfer_park_call_helper(transferee, transferer, park_exten);
02347    }
02348 
02349    /* Do blind transfer. */
02350    ast_verb(3, "Blind transferring %s to '%s' (context %s) priority 1\n",
02351       transferee->name, xferto, transferer_real_context);
02352    ast_cel_report_event(transferer, AST_CEL_BLINDTRANSFER, NULL, xferto, transferee);
02353    pbx_builtin_setvar_helper(transferer, "BLINDTRANSFER", transferee->name);
02354    pbx_builtin_setvar_helper(transferee, "BLINDTRANSFER", transferer->name);
02355    finishup(transferee);
02356    ast_channel_lock(transferer);
02357    if (!transferer->cdr) { /* this code should never get called (in a perfect world) */
02358       transferer->cdr = ast_cdr_alloc();
02359       if (transferer->cdr) {
02360          ast_cdr_init(transferer->cdr, transferer); /* initialize our channel's cdr */
02361          ast_cdr_start(transferer->cdr);
02362       }
02363    }
02364    ast_channel_unlock(transferer);
02365    if (transferer->cdr) {
02366       struct ast_cdr *swap = transferer->cdr;
02367 
02368       ast_debug(1,
02369          "transferer=%s; transferee=%s; lastapp=%s; lastdata=%s; chan=%s; dstchan=%s\n",
02370          transferer->name, transferee->name, transferer->cdr->lastapp,
02371          transferer->cdr->lastdata, transferer->cdr->channel,
02372          transferer->cdr->dstchannel);
02373       ast_debug(1, "TRANSFEREE; lastapp=%s; lastdata=%s, chan=%s; dstchan=%s\n",
02374          transferee->cdr->lastapp, transferee->cdr->lastdata, transferee->cdr->channel,
02375          transferee->cdr->dstchannel);
02376       ast_debug(1, "transferer_real_context=%s; xferto=%s\n",
02377          transferer_real_context, xferto);
02378       /* swap cdrs-- it will save us some time & work */
02379       transferer->cdr = transferee->cdr;
02380       transferee->cdr = swap;
02381    }
02382    if (!transferee->pbx) {
02383       /* Doh!  Use our handy async_goto functions */
02384       ast_debug(1, "About to ast_async_goto %s.\n", transferee->name);
02385       if (ast_async_goto(transferee, transferer_real_context, xferto, 1)) {
02386          ast_log(LOG_WARNING, "Async goto failed :-(\n");
02387       }
02388 
02389       /* The transferee is masqueraded and the original bridged channels can be hungup. */
02390       res = -1;
02391    } else {
02392       /* Set the transferee's new extension, since it exists, using transferer context */
02393       ast_debug(1, "About to explicit goto %s, it has a PBX.\n", transferee->name);
02394       ast_set_flag(transferee, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
02395       set_c_e_p(transferee, transferer_real_context, xferto, 0);
02396 
02397       /*
02398        * Break the bridge.  The transferee needs to resume executing
02399        * dialplan at the xferto location.
02400        */
02401       res = AST_FEATURE_RETURN_SUCCESSBREAK;
02402    }
02403    check_goto_on_transfer(transferer);
02404    return res;
02405 }

static int builtin_disconnect ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
void *  data 
) [static]

Definition at line 2255 of file features.c.

References AST_FEATURE_RETURN_HANGUP, and ast_verb.

02256 {
02257    ast_verb(4, "User hit '%s' to disconnect call.\n", code);
02258    return AST_FEATURE_RETURN_HANGUP;
02259 }

static int builtin_parkcall ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
void *  data 
) [static]

support routing for one touch call parking

Parameters:
chan channel parking call
peer channel to be parked
config unsed
code unused
sense feature options
data unused
Return values:
-1 on successful park.
-1 on chan hangup.
AST_FEATURE_RETURN_SUCCESS on error to keep the bridge connected.

Definition at line 1933 of file features.c.

References ast_channel::_state, ast_answer(), AST_FEATURE_RETURN_SUCCESS, ast_safe_sleep(), AST_STATE_UP, masq_park_call(), and set_peers().

01934 {
01935    struct ast_channel *parker;
01936    struct ast_channel *parkee;
01937    struct ast_park_call_args args = { 0, };
01938 
01939    /*
01940     * We used to set chan's exten and priority to "s" and 1 here,
01941     * but this generates (in some cases) an invalid extension, and
01942     * if "s" exists, could errantly cause execution of extensions
01943     * you don't expect.  It makes more sense to let nature take its
01944     * course when chan finishes, and let the pbx do its thing and
01945     * hang up when the park is over.
01946     */
01947 
01948    /* Answer if call is not up */
01949    if (chan->_state != AST_STATE_UP) {
01950       /*
01951        * XXX Why are we doing this?  Both of the channels should be up
01952        * since you cannot do DTMF features unless you are bridged.
01953        */
01954       if (ast_answer(chan)) {
01955          return -1;
01956       }
01957 
01958       /* Sleep to allow VoIP streams to settle down */
01959       if (ast_safe_sleep(chan, 1000)) {
01960          return -1;
01961       }
01962    }
01963 
01964    /* one direction used to call park_call.... */
01965    set_peers(&parker, &parkee, peer, chan, sense);
01966    return masq_park_call(parkee, parker, &args) ? AST_FEATURE_RETURN_SUCCESS : -1;
01967 }

static char* callback_dialoptions ( struct ast_flags *  features_callee,
struct ast_flags *  features_caller,
char *  options,
size_t  len 
) [static]

Definition at line 4555 of file features.c.

References AST_FEATURE_AUTOMON, AST_FEATURE_DISCONNECT, AST_FEATURE_PARKCALL, AST_FEATURE_REDIRECT, and ast_test_flag.

Referenced by manage_parked_call().

04556 {
04557    int i = 0;
04558    enum {
04559       OPT_CALLEE_REDIRECT   = 't',
04560       OPT_CALLER_REDIRECT   = 'T',
04561       OPT_CALLEE_AUTOMON    = 'w',
04562       OPT_CALLER_AUTOMON    = 'W',
04563       OPT_CALLEE_DISCONNECT = 'h',
04564       OPT_CALLER_DISCONNECT = 'H',
04565       OPT_CALLEE_PARKCALL   = 'k',
04566       OPT_CALLER_PARKCALL   = 'K',
04567    };
04568 
04569    memset(options, 0, len);
04570    if (ast_test_flag(features_caller, AST_FEATURE_REDIRECT) && i < len) {
04571       options[i++] = OPT_CALLER_REDIRECT;
04572    }
04573    if (ast_test_flag(features_caller, AST_FEATURE_AUTOMON) && i < len) {
04574       options[i++] = OPT_CALLER_AUTOMON;
04575    }
04576    if (ast_test_flag(features_caller, AST_FEATURE_DISCONNECT) && i < len) {
04577       options[i++] = OPT_CALLER_DISCONNECT;
04578    }
04579    if (ast_test_flag(features_caller, AST_FEATURE_PARKCALL) && i < len) {
04580       options[i++] = OPT_CALLER_PARKCALL;
04581    }
04582 
04583    if (ast_test_flag(features_callee, AST_FEATURE_REDIRECT) && i < len) {
04584       options[i++] = OPT_CALLEE_REDIRECT;
04585    }
04586    if (ast_test_flag(features_callee, AST_FEATURE_AUTOMON) && i < len) {
04587       options[i++] = OPT_CALLEE_AUTOMON;
04588    }
04589    if (ast_test_flag(features_callee, AST_FEATURE_DISCONNECT) && i < len) {
04590       options[i++] = OPT_CALLEE_DISCONNECT;
04591    }
04592    if (ast_test_flag(features_callee, AST_FEATURE_PARKCALL) && i < len) {
04593       options[i++] = OPT_CALLEE_PARKCALL;
04594    }
04595 
04596    return options;
04597 }

static int check_compat ( struct ast_channel *  c,
struct ast_channel *  newchan 
) [static]

make channels compatible

Parameters:
c 
newchan 
Return values:
0 on success.
-1 on failure.

Definition at line 2414 of file features.c.

References ast_channel_make_compatible(), ast_hangup(), ast_log(), and LOG_WARNING.

Referenced by builtin_atxfer().

02415 {
02416    if (ast_channel_make_compatible(c, newchan) < 0) {
02417       ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n",
02418          c->name, newchan->name);
02419       ast_hangup(newchan);
02420       return -1;
02421    }
02422    return 0;
02423 }

static void check_goto_on_transfer ( struct ast_channel *  chan  )  [static]

Check goto on transfer.

Parameters:
chan Check if channel has 'GOTO_ON_BLINDXFR' set, if not exit. When found make sure the types are compatible. Check if channel is valid if so start the new channel else hangup the call.

Definition at line 892 of file features.c.

References ast_channel::_state, ast_channel_alloc, ast_channel_clear_softhangup(), ast_channel_lock, ast_channel_masquerade(), ast_channel_unlock, ast_clear_flag, ast_debug, ast_do_masquerade(), AST_FLAGS_ALL, ast_hangup(), ast_parseable_goto(), ast_pbx_start(), AST_SOFTHANGUP_ALL, AST_STATE_DOWN, AST_STATE_UP, ast_strdupa, ast_strlen_zero(), pbx_builtin_getvar_helper(), ast_channel::readformat, and ast_channel::writeformat.

Referenced by builtin_blindtransfer().

00893 {
00894    struct ast_channel *xferchan;
00895    const char *val;
00896    char *goto_on_transfer;
00897    char *x;
00898 
00899    ast_channel_lock(chan);
00900    val = pbx_builtin_getvar_helper(chan, "GOTO_ON_BLINDXFR");
00901    if (ast_strlen_zero(val)) {
00902       ast_channel_unlock(chan);
00903       return;
00904    }
00905    goto_on_transfer = ast_strdupa(val);
00906    ast_channel_unlock(chan);
00907 
00908    ast_debug(1, "Attempting GOTO_ON_BLINDXFR=%s for %s.\n", val, chan->name);
00909 
00910    xferchan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", chan->linkedid, 0,
00911       "%s", chan->name);
00912    if (!xferchan) {
00913       return;
00914    }
00915 
00916    /* Make formats okay */
00917    xferchan->readformat = chan->readformat;
00918    xferchan->writeformat = chan->writeformat;
00919 
00920    if (ast_channel_masquerade(xferchan, chan)) {
00921       /* Failed to setup masquerade. */
00922       ast_hangup(xferchan);
00923       return;
00924    }
00925 
00926    for (x = goto_on_transfer; *x; ++x) {
00927       if (*x == '^') {
00928          *x = ',';
00929       }
00930    }
00931    ast_parseable_goto(xferchan, goto_on_transfer);
00932    xferchan->_state = AST_STATE_UP;
00933    ast_clear_flag(xferchan, AST_FLAGS_ALL);  
00934    ast_channel_clear_softhangup(xferchan, AST_SOFTHANGUP_ALL);
00935 
00936    ast_do_masquerade(xferchan);
00937    if (ast_pbx_start(xferchan)) {
00938       /* Failed to start PBX. */
00939       ast_hangup(xferchan);
00940    }
00941 }

static void clear_dialed_interfaces ( struct ast_channel *  chan  )  [static]

Definition at line 3847 of file features.c.

References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, ast_datastore_free(), ast_log(), dialed_interface_info, LOG_DEBUG, and option_debug.

Referenced by ast_bridge_call().

03848 {
03849    struct ast_datastore *di_datastore;
03850 
03851    ast_channel_lock(chan);
03852    if ((di_datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL))) {
03853       if (option_debug) {
03854          ast_log(LOG_DEBUG, "Removing dialed interfaces datastore on %s since we're bridging\n", chan->name);
03855       }
03856       if (!ast_channel_datastore_remove(chan, di_datastore)) {
03857          ast_datastore_free(di_datastore);
03858       }
03859    }
03860    ast_channel_unlock(chan);
03861 }

static struct ast_parkinglot * copy_parkinglot ( const char *  name,
const struct ast_parkinglot *  parkinglot 
) [static, read]

Copy parkinglot and store it with new name.

Definition at line 4920 of file features.c.

References ao2_ref, ast_debug, ast_parkinglot::cfg, create_parkinglot(), and find_parkinglot().

Referenced by create_dynamic_parkinglot().

04921 {
04922    struct ast_parkinglot *copylot;
04923 
04924    if ((copylot = find_parkinglot(name))) { /* Parkinglot with that name already exists */
04925       ao2_ref(copylot, -1);
04926       return NULL;
04927    }
04928 
04929    copylot = create_parkinglot(name);
04930    if (!copylot) {
04931       return NULL;
04932    }
04933 
04934    ast_debug(1, "Building parking lot %s\n", name);
04935 
04936    /* Copy the source parking lot configuration. */
04937    copylot->cfg = parkinglot->cfg;
04938 
04939    return copylot;
04940 }

static struct ast_parkinglot* create_dynamic_parkinglot ( const char *  name,
struct ast_channel *  chan 
) [static, read]

Definition at line 1130 of file features.c.

References ao2_link, ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_debug, ast_log(), ast_strdupa, ast_strlen_zero(), ast_parkinglot::cfg, copy_parkinglot(), default_parkinglot, find_parkinglot(), parkinglot_cfg::is_invalid, LOG_ERROR, LOG_WARNING, ast_parkinglot::name, parkinglot_cfg::parkext, parkinglot_cfg::parkext_exclusive, parkinglot_cfg::parking_con, parkinglot_cfg::parking_start, parkinglot_cfg::parking_stop, parkinglot_activate(), parkinglot_addref(), parkinglot_unref(), parkinglots, pbx_builtin_getvar_helper(), and S_OR.

Referenced by ast_masq_park_call_exten(), ast_park_call_exten(), park_call_exec(), park_space_reserve(), and xfer_park_call_helper().

01131 {
01132    const char *dyn_context;
01133    const char *dyn_exten;
01134    const char *dyn_range;
01135    const char *template_name;
01136    struct ast_parkinglot *template_parkinglot = NULL;
01137    struct ast_parkinglot *parkinglot;
01138    int dyn_start;
01139    int dyn_end;
01140 
01141    ast_channel_lock(chan);
01142    template_name = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNAMIC"), ""));
01143    dyn_context = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNCONTEXT"), ""));
01144    dyn_exten = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNEXTEN"), ""));
01145    dyn_range = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNPOS"), ""));
01146    ast_channel_unlock(chan);
01147 
01148    if (!ast_strlen_zero(template_name)) {
01149       template_parkinglot = find_parkinglot(template_name);
01150       if (!template_parkinglot) {
01151          ast_debug(1, "PARKINGDYNAMIC lot %s does not exist.\n",
01152             template_name);
01153       } else if (template_parkinglot->cfg.is_invalid) {
01154          ast_debug(1, "PARKINGDYNAMIC lot %s has invalid config.\n",
01155             template_name);
01156          parkinglot_unref(template_parkinglot);
01157          template_parkinglot = NULL;
01158       }
01159    }
01160    if (!template_parkinglot) {
01161       template_parkinglot = parkinglot_addref(default_parkinglot);
01162       ast_debug(1, "Using default parking lot for template\n");
01163    }
01164 
01165    parkinglot = copy_parkinglot(name, template_parkinglot);
01166    if (!parkinglot) {
01167       ast_log(LOG_ERROR, "Could not build dynamic parking lot!\n");
01168    } else {
01169       /* Configure the dynamic parking lot. */
01170       if (!ast_strlen_zero(dyn_context)) {
01171          ast_copy_string(parkinglot->cfg.parking_con, dyn_context,
01172             sizeof(parkinglot->cfg.parking_con));
01173       }
01174       if (!ast_strlen_zero(dyn_exten)) {
01175          ast_copy_string(parkinglot->cfg.parkext, dyn_exten,
01176             sizeof(parkinglot->cfg.parkext));
01177       }
01178       if (!ast_strlen_zero(dyn_range)) {
01179          if (sscanf(dyn_range, "%30d-%30d", &dyn_start, &dyn_end) != 2) {
01180             ast_log(LOG_WARNING,
01181                "Format for parking positions is a-b, where a and b are numbers\n");
01182          } else if (dyn_end < dyn_start || dyn_start <= 0 || dyn_end <= 0) {
01183             ast_log(LOG_WARNING,
01184                "Format for parking positions is a-b, where a <= b\n");
01185          } else {
01186             parkinglot->cfg.parking_start = dyn_start;
01187             parkinglot->cfg.parking_stop = dyn_end;
01188          }
01189       }
01190 
01191       /*
01192        * Sanity check for dynamic parking lot configuration.
01193        *
01194        * XXX It may be desirable to instead check if the dynamic
01195        * parking lot overlaps any existing lots like what is done for
01196        * a reload.
01197        */
01198       if (!strcmp(parkinglot->cfg.parking_con, template_parkinglot->cfg.parking_con)) {
01199          if (!strcmp(parkinglot->cfg.parkext, template_parkinglot->cfg.parkext)
01200             && parkinglot->cfg.parkext_exclusive) {
01201             ast_log(LOG_WARNING,
01202                "Parking lot '%s' conflicts with template parking lot '%s'!\n"
01203                "Change either PARKINGDYNCONTEXT or PARKINGDYNEXTEN.\n",
01204                parkinglot->name, template_parkinglot->name);
01205          }
01206          if ((template_parkinglot->cfg.parking_start <= parkinglot->cfg.parking_start
01207                && parkinglot->cfg.parking_start <= template_parkinglot->cfg.parking_stop)
01208             || (template_parkinglot->cfg.parking_start <= parkinglot->cfg.parking_stop
01209                && parkinglot->cfg.parking_stop <= template_parkinglot->cfg.parking_stop)
01210             || (parkinglot->cfg.parking_start < template_parkinglot->cfg.parking_start
01211                && template_parkinglot->cfg.parking_stop < parkinglot->cfg.parking_stop)) {
01212             ast_log(LOG_WARNING,
01213                "Parking lot '%s' parking spaces overlap template parking lot '%s'!\n"
01214                "Change PARKINGDYNPOS.\n",
01215                parkinglot->name, template_parkinglot->name);
01216          }
01217       }
01218 
01219       parkinglot_activate(parkinglot);
01220       ao2_link(parkinglots, parkinglot);
01221    }
01222    parkinglot_unref(template_parkinglot);
01223 
01224    return parkinglot;
01225 }

static struct ast_parkinglot * create_parkinglot ( const char *  name  )  [static, read]

Allocate parking lot structure.

Definition at line 5345 of file features.c.

References ao2_alloc, ast_copy_string(), AST_LIST_HEAD_INIT, ast_strlen_zero(), ast_parkinglot::cfg, parkinglot_cfg::is_invalid, ast_parkinglot::name, parkinglot_destroy(), and ast_parkinglot::parkings.

Referenced by build_parkinglot(), and copy_parkinglot().

05346 {
05347    struct ast_parkinglot *newlot;
05348 
05349    if (ast_strlen_zero(name)) { /* No name specified */
05350       return NULL;
05351    }
05352 
05353    newlot = ao2_alloc(sizeof(*newlot), parkinglot_destroy);
05354    if (!newlot)
05355       return NULL;
05356    
05357    ast_copy_string(newlot->name, name, sizeof(newlot->name));
05358    newlot->cfg.is_invalid = 1;/* No config is set yet. */
05359    AST_LIST_HEAD_INIT(&newlot->parkings);
05360 
05361    return newlot;
05362 }

static void destroy_dialplan_usage_context ( struct parking_dp_context *  doomed  )  [static]

Definition at line 5923 of file features.c.

References parking_dp_context::access_extens, ast_free, AST_LIST_REMOVE_HEAD, parking_dp_context::hints, and parking_dp_context::spaces.

Referenced by build_dialplan_useage_context(), and destroy_dialplan_usage_map().

05924 {
05925    struct parking_dp_ramp *ramp;
05926    struct parking_dp_spaces *spaces;
05927 
05928    while ((ramp = AST_LIST_REMOVE_HEAD(&doomed->access_extens, node))) {
05929       ast_free(ramp);
05930    }
05931    while ((spaces = AST_LIST_REMOVE_HEAD(&doomed->spaces, node))) {
05932       ast_free(spaces);
05933    }
05934    while ((spaces = AST_LIST_REMOVE_HEAD(&doomed->hints, node))) {
05935       ast_free(spaces);
05936    }
05937    ast_free(doomed);
05938 }

static void destroy_dialplan_usage_map ( struct parking_dp_map *  doomed  )  [static]

Definition at line 5948 of file features.c.

References AST_LIST_REMOVE_HEAD, and destroy_dialplan_usage_context().

Referenced by load_config().

05949 {
05950    struct parking_dp_context *item;
05951 
05952    while ((item = AST_LIST_REMOVE_HEAD(doomed, node))) {
05953       destroy_dialplan_usage_context(item);
05954    }
05955 }

static void destroy_space ( const char *  context,
int  space 
) [static]

Definition at line 6378 of file features.c.

References AST_MAX_EXTENSION, PRIORITY_HINT, and remove_exten_if_exist().

Referenced by remove_dead_context_usage(), and remove_dead_spaces_usage().

06379 {
06380    char exten[AST_MAX_EXTENSION];
06381 
06382    /* Destroy priorities of the parking space that we registered. */
06383    snprintf(exten, sizeof(exten), "%d", space);
06384    remove_exten_if_exist(context, exten, PRIORITY_HINT);
06385    remove_exten_if_exist(context, exten, 1);
06386 }

static void dial_features_destroy ( void *  data  )  [static]

Definition at line 740 of file features.c.

References ast_free.

00741 {
00742    struct ast_dial_features *df = data;
00743    if (df) {
00744       ast_free(df);
00745    }
00746 }

static void* dial_features_duplicate ( void *  data  )  [static]

Definition at line 727 of file features.c.

References ast_calloc.

00728 {
00729    struct ast_dial_features *df = data, *df_copy;
00730  
00731    if (!(df_copy = ast_calloc(1, sizeof(*df)))) {
00732       return NULL;
00733    }
00734  
00735    memcpy(df_copy, df, sizeof(*df));
00736  
00737    return df_copy;
00738 }

static int dialplan_usage_add_parkinglot ( struct parking_dp_map *  usage_map,
struct ast_parkinglot *  lot,
int  complain 
) [static]

Definition at line 6231 of file features.c.

References AST_LIST_INSERT_BEFORE_CURRENT, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, build_dialplan_useage_context(), ast_parkinglot::cfg, parking_dp_context::context, dialplan_usage_add_parkinglot_data(), and parkinglot_cfg::parking_con.

Referenced by build_dialplan_useage_map().

06232 {
06233    struct parking_dp_context *cur_ctx;
06234    struct parking_dp_context *new_ctx;
06235    int cmp;
06236 
06237    AST_LIST_TRAVERSE_SAFE_BEGIN(usage_map, cur_ctx, node) {
06238       cmp = strcmp(lot->cfg.parking_con, cur_ctx->context);
06239       if (cmp > 0) {
06240          /* The parking lot context goes after this node. */
06241          continue;
06242       }
06243       if (cmp == 0) {
06244          /* This is the node we will add parking lot spaces to the map. */
06245          return dialplan_usage_add_parkinglot_data(cur_ctx, lot, complain);
06246       }
06247       /* The new parking lot context goes before this node. */
06248       new_ctx = build_dialplan_useage_context(lot);
06249       if (!new_ctx) {
06250          return -1;
06251       }
06252       AST_LIST_INSERT_BEFORE_CURRENT(new_ctx, node);
06253       return 0;
06254    }
06255    AST_LIST_TRAVERSE_SAFE_END;
06256 
06257    /* New parking lot context goes on the end. */
06258    new_ctx = build_dialplan_useage_context(lot);
06259    if (!new_ctx) {
06260       return -1;
06261    }
06262    AST_LIST_INSERT_TAIL(usage_map, new_ctx, node);
06263    return 0;
06264 }

static int dialplan_usage_add_parkinglot_data ( struct parking_dp_context *  ctx_node,
struct ast_parkinglot *  lot,
int  complain 
) [static]

Definition at line 6177 of file features.c.

References parking_dp_context::access_extens, ast_parkinglot::cfg, parking_dp_context::hints, parkinglot_cfg::parkaddhints, parkinglot_cfg::parkext, parkinglot_cfg::parkext_exclusive, parkinglot_cfg::parking_start, parkinglot_cfg::parking_stop, parking_dp_context::spaces, usage_context_add_ramp(), and usage_context_add_spaces().

Referenced by build_dialplan_useage_context(), and dialplan_usage_add_parkinglot().

06178 {
06179    if (usage_context_add_ramp(&ctx_node->access_extens, lot->cfg.parkext,
06180       lot->cfg.parkext_exclusive, lot, complain)) {
06181       return -1;
06182    }
06183    if (usage_context_add_spaces(&ctx_node->spaces, lot->cfg.parking_start,
06184       lot->cfg.parking_stop, lot, complain)) {
06185       return -1;
06186    }
06187    if (lot->cfg.parkaddhints
06188       && usage_context_add_spaces(&ctx_node->hints, lot->cfg.parking_start,
06189          lot->cfg.parking_stop, lot, 0)) {
06190       return -1;
06191    }
06192    return 0;
06193 }

static int do_bridge_masquerade ( struct ast_channel *  chan,
struct ast_channel *  tmpchan 
) [static]

Actual bridge.

Parameters:
chan 
tmpchan Stop hold music, lock both channels, masq channels, after bridge return channel to next priority.
Return values:
0 on success.
-1 on error.

Definition at line 6814 of file features.c.

References ast_channel::_state, ast_channel_lock_both, ast_channel_masquerade(), ast_channel_unlock, ast_do_masquerade(), ast_explicit_goto(), ast_moh_stop(), ast_setstate(), ast_strdupa, ast_channel::context, ast_channel::exten, ast_channel::priority, ast_channel::readformat, and ast_channel::writeformat.

Referenced by action_bridge(), and bridge_exec().

06815 {
06816    const char *context;
06817    const char *exten;
06818    int priority;
06819 
06820    ast_moh_stop(chan);
06821    ast_channel_lock_both(chan, tmpchan);
06822    context = ast_strdupa(chan->context);
06823    exten = ast_strdupa(chan->exten);
06824    priority = chan->priority;
06825    ast_setstate(tmpchan, chan->_state);
06826    tmpchan->readformat = chan->readformat;
06827    tmpchan->writeformat = chan->writeformat;
06828    ast_channel_unlock(chan);
06829    ast_channel_unlock(tmpchan);
06830 
06831    /* Masquerade setup and execution must be done without any channel locks held */
06832    if (ast_channel_masquerade(tmpchan, chan)) {
06833       return -1;
06834    }
06835    ast_do_masquerade(tmpchan);
06836 
06837    /* when returning from bridge, the channel will continue at the next priority */
06838    ast_explicit_goto(tmpchan, context, exten, priority + 1);
06839 
06840    return 0;
06841 }

static void* do_parking_thread ( void *  ignore  )  [static]

Take care of parked calls and unpark them if needed.

Parameters:
ignore unused var.

Start inf loop, lock parking lot, check if any parked channels have gone above timeout if so, remove channel from parking lot and return it to the extension that parked it. Check if parked channel decided to hangup, wait until next FD via select().

Definition at line 4870 of file features.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_free, ast_poll, manage_parkinglot(), and parkinglots.

Referenced by ast_features_init().

04871 {
04872    struct pollfd *pfds = NULL, *new_pfds = NULL;
04873    int nfds = 0, new_nfds = 0;
04874 
04875    for (;;) {
04876       struct ao2_iterator iter;
04877       struct ast_parkinglot *curlot;
04878       int ms = -1;   /* poll2 timeout, uninitialized */
04879 
04880       iter = ao2_iterator_init(parkinglots, 0);
04881       while ((curlot = ao2_iterator_next(&iter))) {
04882          manage_parkinglot(curlot, pfds, nfds, &new_pfds, &new_nfds, &ms);
04883          ao2_ref(curlot, -1);
04884       }
04885       ao2_iterator_destroy(&iter);
04886 
04887       /* Recycle */
04888       ast_free(pfds);
04889       pfds = new_pfds;
04890       nfds = new_nfds;
04891       new_pfds = NULL;
04892       new_nfds = 0;
04893 
04894       /* Wait for something to happen */
04895       ast_poll(pfds, nfds, ms);
04896       pthread_testcancel();
04897    }
04898    /* If this WERE reached, we'd need to free(pfds) */
04899    return NULL;   /* Never reached */
04900 }

static int feature_check ( struct ast_channel *  chan,
struct ast_flags *  features,
char *  code 
) [static]

Check if a feature exists.

Definition at line 3376 of file features.c.

References ast_channel_lock, ast_channel_unlock, ast_strdupa, FEATURE_INTERPRET_CHECK, feature_interpret_helper(), pbx_builtin_getvar_helper(), and S_OR.

Referenced by ast_bridge_call().

03376                                                                                            {
03377    char *chan_dynamic_features;
03378    ast_channel_lock(chan);
03379    chan_dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES"),""));
03380    ast_channel_unlock(chan);
03381 
03382    return feature_interpret_helper(chan, NULL, NULL, code, 0, chan_dynamic_features, features, FEATURE_INTERPRET_CHECK, NULL);
03383 }

static int feature_exec_app ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
void *  data 
) [static]

exec an app by feature

Parameters:
chan,peer,config,code,sense,data Find a feature, determine which channel activated
Return values:
AST_FEATURE_RETURN_NO_HANGUP_PEER 
-1 error.
-2 when an application cannot be found.

Todo:
XXX should probably return res

Definition at line 3121 of file features.c.

References ast_call_feature::app, app, ast_call_feature::app_args, ast_autoservice_ignore(), ast_autoservice_start(), ast_autoservice_stop(), AST_FEATURE_FLAG_BYCALLEE, AST_FEATURE_FLAG_BYCALLER, AST_FEATURE_FLAG_ONSELF, AST_FEATURE_RETURN_KEEPTRYING, AST_FEATURE_RETURN_SUCCESS, AST_FEATURE_RETURN_SUCCESSBREAK, AST_FRAME_DTMF_END, ast_log(), ast_moh_start(), ast_moh_stop(), ast_strlen_zero(), ast_test_flag, FEATURE_SENSE_CHAN, LOG_NOTICE, LOG_WARNING, ast_call_feature::moh_class, pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), and ast_call_feature::sname.

Referenced by process_applicationmap_line().

03122 {
03123    struct ast_app *app;
03124    struct ast_call_feature *feature = data;
03125    struct ast_channel *work, *idle;
03126    int res;
03127 
03128    if (!feature) { /* shouldn't ever happen! */
03129       ast_log(LOG_NOTICE, "Found feature before, but at execing we've lost it??\n");
03130       return -1; 
03131    }
03132 
03133    if (sense == FEATURE_SENSE_CHAN) {
03134       if (!ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLER))
03135          return AST_FEATURE_RETURN_KEEPTRYING;
03136       if (ast_test_flag(feature, AST_FEATURE_FLAG_ONSELF)) {
03137          work = chan;
03138          idle = peer;
03139       } else {
03140          work = peer;
03141          idle = chan;
03142       }
03143    } else {
03144       if (!ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLEE))
03145          return AST_FEATURE_RETURN_KEEPTRYING;
03146       if (ast_test_flag(feature, AST_FEATURE_FLAG_ONSELF)) {
03147          work = peer;
03148          idle = chan;
03149       } else {
03150          work = chan;
03151          idle = peer;
03152       }
03153    }
03154 
03155    if (!(app = pbx_findapp(feature->app))) {
03156       ast_log(LOG_WARNING, "Could not find application (%s)\n", feature->app);
03157       return -2;
03158    }
03159 
03160    ast_autoservice_start(idle);
03161    ast_autoservice_ignore(idle, AST_FRAME_DTMF_END);
03162    
03163    pbx_builtin_setvar_helper(work, "DYNAMIC_PEERNAME", idle->name);
03164    pbx_builtin_setvar_helper(idle, "DYNAMIC_PEERNAME", work->name);
03165    pbx_builtin_setvar_helper(work, "DYNAMIC_FEATURENAME", feature->sname);
03166    pbx_builtin_setvar_helper(idle, "DYNAMIC_FEATURENAME", feature->sname);
03167 
03168    if (!ast_strlen_zero(feature->moh_class))
03169       ast_moh_start(idle, feature->moh_class, NULL);
03170 
03171    res = pbx_exec(work, app, feature->app_args);
03172 
03173    if (!ast_strlen_zero(feature->moh_class))
03174       ast_moh_stop(idle);
03175 
03176    ast_autoservice_stop(idle);
03177 
03178    if (res) {
03179       return AST_FEATURE_RETURN_SUCCESSBREAK;
03180    }
03181    return AST_FEATURE_RETURN_SUCCESS;  /*! \todo XXX should probably return res */
03182 }

static int feature_interpret ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense 
) [static]

Check the dynamic features.

Parameters:
chan,peer,config,code,sense 
Return values:
res on success.
-1 on failure.

Definition at line 3339 of file features.c.

References ast_channel_lock, ast_channel_unlock, ast_copy_flags, ast_debug, AST_FLAGS_ALL, ast_strdupa, FEATURE_INTERPRET_DO, feature_interpret_helper(), FEATURE_SENSE_CHAN, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_flags::flags, pbx_builtin_getvar_helper(), and S_OR.

Referenced by ast_bridge_call().

03339                                                                                                                                                 {
03340 
03341    char dynamic_features_buf[128];
03342    const char *peer_dynamic_features, *chan_dynamic_features;
03343    struct ast_flags features;
03344    struct ast_call_feature feature;
03345    if (sense == FEATURE_SENSE_CHAN) {
03346       /* Coverity - This uninit_use should be ignored since this macro initializes the flags */
03347       ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
03348    }
03349    else {
03350       /* Coverity - This uninit_use should be ignored since this macro initializes the flags */
03351       ast_copy_flags(&features, &(config->features_callee), AST_FLAGS_ALL);
03352    }
03353 
03354    ast_channel_lock(peer);
03355    peer_dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(peer, "DYNAMIC_FEATURES"),""));
03356    ast_channel_unlock(peer);
03357 
03358    ast_channel_lock(chan);
03359    chan_dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES"),""));
03360    ast_channel_unlock(chan);
03361 
03362    snprintf(dynamic_features_buf, sizeof(dynamic_features_buf), "%s%s%s", S_OR(chan_dynamic_features, ""), chan_dynamic_features && peer_dynamic_features ? "#" : "", S_OR(peer_dynamic_features,""));
03363 
03364    ast_debug(3, "Feature interpret: chan=%s, peer=%s, code=%s, sense=%d, features=%d, dynamic=%s\n", chan->name, peer->name, code, sense, features.flags, dynamic_features_buf);
03365 
03366    return feature_interpret_helper(chan, peer, config, code, sense, dynamic_features_buf, &features, FEATURE_INTERPRET_DO, &feature);
03367 }

static int feature_interpret_helper ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config,
const char *  code,
int  sense,
char *  dynamic_features_buf,
struct ast_flags *  features,
feature_interpret_op  operation,
struct ast_call_feature *  feature 
) [static]

Helper function for feature_interpret and ast_feature_detect.

Parameters:
chan,peer,config,code,sense,dynamic_features_buf,features,operation,feature Lock features list, browse for code, unlock list If a feature is found and the operation variable is set, that feature's operation is executed. The first feature found is copied to the feature parameter.
Return values:
res on success.
-1 on failure.

Definition at line 3222 of file features.c.

References ast_debug, AST_FEATURE_RETURN_KEEPTRYING, AST_FEATURE_RETURN_PASSDIGITS, AST_FEATURE_RETURN_STOREDIGITS, AST_FEATURE_RETURN_SUCCESS, AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_rwlock_rdlock, ast_rwlock_unlock, ast_strlen_zero(), ast_test_flag, ast_verb, ast_call_feature::exten, feature_group_exten::exten, feature_group_exten::feature, FEATURE_INTERPRET_CHECK, FEATURE_INTERPRET_DO, ast_call_feature::feature_mask, feature_group::features, FEATURES_COUNT, features_lock, find_dynamic_feature(), find_group(), ast_call_feature::fname, ast_call_feature::operation, and ast_call_feature::sname.

Referenced by ast_feature_detect(), feature_check(), and feature_interpret().

03225 {
03226    int x;
03227    struct feature_group *fg = NULL;
03228    struct feature_group_exten *fge;
03229    struct ast_call_feature *tmpfeature;
03230    char *tmp, *tok;
03231    int res = AST_FEATURE_RETURN_PASSDIGITS;
03232    int feature_detected = 0;
03233 
03234    if (!(peer && chan && config) && operation == FEATURE_INTERPRET_DO) {
03235       return -1; /* can not run feature operation */
03236    }
03237 
03238    ast_rwlock_rdlock(&features_lock);
03239    for (x = 0; x < FEATURES_COUNT; x++) {
03240       if ((ast_test_flag(features, builtin_features[x].feature_mask)) &&
03241           !ast_strlen_zero(builtin_features[x].exten)) {
03242          /* Feature is up for consideration */
03243          if (!strcmp(builtin_features[x].exten, code)) {
03244             ast_debug(3, "Feature detected: fname=%s sname=%s exten=%s\n", builtin_features[x].fname, builtin_features[x].sname, builtin_features[x].exten);
03245             if (operation == FEATURE_INTERPRET_CHECK) {
03246                res = AST_FEATURE_RETURN_SUCCESS; /* We found something */
03247             } else if (operation == FEATURE_INTERPRET_DO) {
03248                res = builtin_features[x].operation(chan, peer, config, code, sense, NULL);
03249             }
03250             if (feature) {
03251                memcpy(feature, &builtin_features[x], sizeof(*feature));
03252             }
03253             feature_detected = 1;
03254             break;
03255          } else if (!strncmp(builtin_features[x].exten, code, strlen(code))) {
03256             if (res == AST_FEATURE_RETURN_PASSDIGITS) {
03257                res = AST_FEATURE_RETURN_STOREDIGITS;
03258             }
03259          }
03260       }
03261    }
03262    ast_rwlock_unlock(&features_lock);
03263 
03264    if (ast_strlen_zero(dynamic_features_buf) || feature_detected) {
03265       return res;
03266    }
03267 
03268    tmp = dynamic_features_buf;
03269 
03270    while ((tok = strsep(&tmp, "#"))) {
03271       AST_RWLIST_RDLOCK(&feature_groups);
03272 
03273       fg = find_group(tok);
03274 
03275       if (fg) {
03276          AST_LIST_TRAVERSE(&fg->features, fge, entry) {
03277             if (!strcmp(fge->exten, code)) {
03278                if (operation) {
03279                   res = fge->feature->operation(chan, peer, config, code, sense, fge->feature);
03280                }
03281                if (feature) {
03282                   memcpy(feature, fge->feature, sizeof(*feature));
03283                }
03284                if (res != AST_FEATURE_RETURN_KEEPTRYING) {
03285                   AST_RWLIST_UNLOCK(&feature_groups);
03286                   break;
03287                }
03288                res = AST_FEATURE_RETURN_PASSDIGITS;
03289             } else if (!strncmp(fge->exten, code, strlen(code))) {
03290                res = AST_FEATURE_RETURN_STOREDIGITS;
03291             }
03292          }
03293          if (fge) {
03294             break;
03295          }
03296       }
03297 
03298       AST_RWLIST_UNLOCK(&feature_groups);
03299 
03300       AST_RWLIST_RDLOCK(&feature_list);
03301 
03302       if (!(tmpfeature = find_dynamic_feature(tok))) {
03303          AST_RWLIST_UNLOCK(&feature_list);
03304          continue;
03305       }
03306 
03307       /* Feature is up for consideration */
03308       if (!strcmp(tmpfeature->exten, code)) {
03309          ast_verb(3, " Feature Found: %s exten: %s\n",tmpfeature->sname, tok);
03310          if (operation == FEATURE_INTERPRET_CHECK) {
03311             res = AST_FEATURE_RETURN_SUCCESS; /* We found something */
03312          } else if (operation == FEATURE_INTERPRET_DO) {
03313             res = tmpfeature->operation(chan, peer, config, code, sense, tmpfeature);
03314          }
03315          if (feature) {
03316             memcpy(feature, tmpfeature, sizeof(*feature));
03317          }
03318          if (res != AST_FEATURE_RETURN_KEEPTRYING) {
03319             AST_RWLIST_UNLOCK(&feature_list);
03320             break;
03321          }
03322          res = AST_FEATURE_RETURN_PASSDIGITS;
03323       } else if (!strncmp(tmpfeature->exten, code, strlen(code)))
03324          res = AST_FEATURE_RETURN_STOREDIGITS;
03325 
03326       AST_RWLIST_UNLOCK(&feature_list);
03327    }
03328 
03329    return res;
03330 }

static struct ast_channel * feature_request_and_dial ( struct ast_channel *  caller,
const char *  caller_name,
struct ast_channel *  requestor,
struct ast_channel *  transferee,
const char *  type,
format_t  format,
void *  data,
int  timeout,
int *  outstate,
const char *  language 
) [static, read]

Definition at line 3480 of file features.c.

References ast_channel::_state, ast_autoservice_start(), ast_autoservice_stop(), ast_call(), ast_call_forward(), AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, ast_channel_connected_line_macro(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_redirecting_macro(), ast_channel_set_connected_line(), ast_channel_unlock, ast_check_hangup(), ast_connected_line_copy_from_caller(), ast_connected_line_parse_data(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_INCOMPLETE, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), ast_hangup(), ast_indicate(), ast_indicate_data(), ast_is_deferrable_frame(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_log(), ast_party_connected_line_free(), ast_party_connected_line_set_init(), ast_poll_channel_add(), ast_poll_channel_del(), ast_queue_frame_head(), ast_read(), ast_request(), ast_rwlock_rdlock, ast_rwlock_unlock, AST_STATE_UP, ast_string_field_set, ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, ast_waitfor_n(), ast_write(), ast_channel::caller, cause, ast_channel::connected, ast_frame::data, ast_frame::datalen, ast_channel::exten, ast_call_feature::exten, f, FEATURES_COUNT, features_lock, ast_frame::frametype, ast_channel::hangupcause, ast_frame_subclass::integer, LOG_NOTICE, pbx_builtin_setvar_helper(), ast_frame::ptr, and ast_frame::subclass.

Referenced by builtin_atxfer().

03484 {
03485    int state = 0;
03486    int cause = 0;
03487    int to;
03488    int caller_hungup;
03489    int transferee_hungup;
03490    struct ast_channel *chan;
03491    struct ast_channel *monitor_chans[3];
03492    struct ast_channel *active_channel;
03493    int res;
03494    int ready = 0;
03495    struct timeval started;
03496    int x, len = 0;
03497    char *disconnect_code = NULL, *dialed_code = NULL;
03498    struct ast_frame *f;
03499    AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
03500 
03501    caller_hungup = ast_check_hangup(caller);
03502 
03503    if (!(chan = ast_request(type, format, requestor, data, &cause))) {
03504       ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
03505       switch (cause) {
03506       case AST_CAUSE_BUSY:
03507          state = AST_CONTROL_BUSY;
03508          break;
03509       case AST_CAUSE_CONGESTION:
03510          state = AST_CONTROL_CONGESTION;
03511          break;
03512       default:
03513          state = 0;
03514          break;
03515       }
03516       goto done;
03517    }
03518 
03519    ast_string_field_set(chan, language, language);
03520    ast_channel_inherit_variables(caller, chan);
03521    pbx_builtin_setvar_helper(chan, "TRANSFERERNAME", caller_name);
03522 
03523    ast_channel_lock(chan);
03524    ast_connected_line_copy_from_caller(&chan->connected, &requestor->caller);
03525    ast_channel_unlock(chan);
03526 
03527    if (ast_call(chan, data, timeout)) {
03528       ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
03529       switch (chan->hangupcause) {
03530       case AST_CAUSE_BUSY:
03531          state = AST_CONTROL_BUSY;
03532          break;
03533       case AST_CAUSE_CONGESTION:
03534          state = AST_CONTROL_CONGESTION;
03535          break;
03536       default:
03537          state = 0;
03538          break;
03539       }
03540       goto done;
03541    }
03542 
03543    /* support dialing of the featuremap disconnect code while performing an attended tranfer */
03544    ast_rwlock_rdlock(&features_lock);
03545    for (x = 0; x < FEATURES_COUNT; x++) {
03546       if (strcasecmp(builtin_features[x].sname, "disconnect"))
03547          continue;
03548 
03549       disconnect_code = builtin_features[x].exten;
03550       len = strlen(disconnect_code) + 1;
03551       dialed_code = alloca(len);
03552       memset(dialed_code, 0, len);
03553       break;
03554    }
03555    ast_rwlock_unlock(&features_lock);
03556    x = 0;
03557    started = ast_tvnow();
03558    to = timeout;
03559    AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
03560 
03561    ast_poll_channel_add(caller, chan);
03562 
03563    transferee_hungup = 0;
03564    while (!ast_check_hangup(transferee) && (chan->_state != AST_STATE_UP)) {
03565       int num_chans = 0;
03566 
03567       monitor_chans[num_chans++] = transferee;
03568       monitor_chans[num_chans++] = chan;
03569       if (!caller_hungup) {
03570          if (ast_check_hangup(caller)) {
03571             caller_hungup = 1;
03572 
03573 #if defined(ATXFER_NULL_TECH)
03574             /* Change caller's name to ensure that it will remain unique. */
03575             set_new_chan_name(caller);
03576 
03577             /*
03578              * Get rid of caller's physical technology so it is free for
03579              * other calls.
03580              */
03581             set_kill_chan_tech(caller);
03582 #endif   /* defined(ATXFER_NULL_TECH) */
03583          } else {
03584             /* caller is not hungup so monitor it. */
03585             monitor_chans[num_chans++] = caller;
03586          }
03587       }
03588 
03589       /* see if the timeout has been violated */
03590       if (ast_tvdiff_ms(ast_tvnow(), started) > timeout) {
03591          state = AST_CONTROL_UNHOLD;
03592          ast_log(LOG_NOTICE, "We exceeded our AT-timeout for %s\n", chan->name);
03593          break; /*doh! timeout*/
03594       }
03595 
03596       active_channel = ast_waitfor_n(monitor_chans, num_chans, &to);
03597       if (!active_channel)
03598          continue;
03599 
03600       f = NULL;
03601       if (transferee == active_channel) {
03602          struct ast_frame *dup_f;
03603 
03604          f = ast_read(transferee);
03605          if (f == NULL) { /*doh! where'd he go?*/
03606             transferee_hungup = 1;
03607             state = 0;
03608             break;
03609          }
03610          if (ast_is_deferrable_frame(f)) {
03611             dup_f = ast_frisolate(f);
03612             if (dup_f) {
03613                if (dup_f == f) {
03614                   f = NULL;
03615                }
03616                AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
03617             }
03618          }
03619       } else if (chan == active_channel) {
03620          if (!ast_strlen_zero(chan->call_forward)) {
03621             state = 0;
03622             ast_autoservice_start(transferee);
03623             chan = ast_call_forward(caller, chan, NULL, format, NULL, &state);
03624             ast_autoservice_stop(transferee);
03625             if (!chan) {
03626                break;
03627             }
03628             continue;
03629          }
03630          f = ast_read(chan);
03631          if (f == NULL) { /*doh! where'd he go?*/
03632             switch (chan->hangupcause) {
03633             case AST_CAUSE_BUSY:
03634                state = AST_CONTROL_BUSY;
03635                break;
03636             case AST_CAUSE_CONGESTION:
03637                state = AST_CONTROL_CONGESTION;
03638                break;
03639             default:
03640                state = 0;
03641                break;
03642             }
03643             break;
03644          }
03645 
03646          if (f->frametype == AST_FRAME_CONTROL) {
03647             if (f->subclass.integer == AST_CONTROL_RINGING) {
03648                ast_verb(3, "%s is ringing\n", chan->name);
03649                ast_indicate(caller, AST_CONTROL_RINGING);
03650             } else if (f->subclass.integer == AST_CONTROL_BUSY) {
03651                state = f->subclass.integer;
03652                ast_verb(3, "%s is busy\n", chan->name);
03653                ast_indicate(caller, AST_CONTROL_BUSY);
03654                ast_frfree(f);
03655                break;
03656             } else if (f->subclass.integer == AST_CONTROL_INCOMPLETE) {
03657                ast_verb(3, "%s dialed incomplete extension %s; ignoring\n", chan->name, chan->exten);
03658             } else if (f->subclass.integer == AST_CONTROL_CONGESTION) {
03659                state = f->subclass.integer;
03660                ast_verb(3, "%s is congested\n", chan->name);
03661                ast_indicate(caller, AST_CONTROL_CONGESTION);
03662                ast_frfree(f);
03663                break;
03664             } else if (f->subclass.integer == AST_CONTROL_ANSWER) {
03665                /* This is what we are hoping for */
03666                state = f->subclass.integer;
03667                ast_frfree(f);
03668                ready=1;
03669                break;
03670             } else if (f->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
03671                if (caller_hungup) {
03672                   struct ast_party_connected_line connected;
03673 
03674                   /* Just save it for the transfer. */
03675                   ast_party_connected_line_set_init(&connected, &caller->connected);
03676                   res = ast_connected_line_parse_data(f->data.ptr, f->datalen,
03677                      &connected);
03678                   if (!res) {
03679                      ast_channel_set_connected_line(caller, &connected, NULL);
03680                   }
03681                   ast_party_connected_line_free(&connected);
03682                } else {
03683                   ast_autoservice_start(transferee);
03684                   if (ast_channel_connected_line_macro(chan, caller, f, 1, 1)) {
03685                      ast_indicate_data(caller, AST_CONTROL_CONNECTED_LINE,
03686                         f->data.ptr, f->datalen);
03687                   }
03688                   ast_autoservice_stop(transferee);
03689                }
03690             } else if (f->subclass.integer == AST_CONTROL_REDIRECTING) {
03691                if (!caller_hungup) {
03692                   ast_autoservice_start(transferee);
03693                   if (ast_channel_redirecting_macro(chan, caller, f, 1, 1)) {
03694                      ast_indicate_data(caller, AST_CONTROL_REDIRECTING,
03695                         f->data.ptr, f->datalen);
03696                   }
03697                   ast_autoservice_stop(transferee);
03698                }
03699             } else if (f->subclass.integer != -1
03700                && f->subclass.integer != AST_CONTROL_PROGRESS
03701                && f->subclass.integer != AST_CONTROL_PROCEEDING) {
03702                ast_log(LOG_NOTICE, "Don't know what to do about control frame: %d\n", f->subclass.integer);
03703             }
03704             /* else who cares */
03705          } else if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) {
03706             ast_write(caller, f);
03707          }
03708       } else if (caller == active_channel) {
03709          f = ast_read(caller);
03710          if (f) {
03711             if (f->frametype == AST_FRAME_DTMF) {
03712                dialed_code[x++] = f->subclass.integer;
03713                dialed_code[x] = '\0';
03714                if (strlen(dialed_code) == len) {
03715                   x = 0;
03716                } else if (x && strncmp(dialed_code, disconnect_code, x)) {
03717                   x = 0;
03718                   dialed_code[x] = '\0';
03719                }
03720                if (*dialed_code && !strcmp(dialed_code, disconnect_code)) {
03721                   /* Caller Canceled the call */
03722                   state = AST_CONTROL_UNHOLD;
03723                   ast_frfree(f);
03724                   break;
03725                }
03726             } else if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO) {
03727                ast_write(chan, f);
03728             }
03729          }
03730       }
03731       if (f)
03732          ast_frfree(f);
03733    } /* end while */
03734 
03735    ast_poll_channel_del(caller, chan);
03736 
03737    /*
03738     * We need to free all the deferred frames, but we only need to
03739     * queue the deferred frames if no hangup was received.
03740     */
03741    ast_channel_lock(transferee);
03742    transferee_hungup = (transferee_hungup || ast_check_hangup(transferee));
03743    while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
03744       if (!transferee_hungup) {
03745          ast_queue_frame_head(transferee, f);
03746       }
03747       ast_frfree(f);
03748    }
03749    ast_channel_unlock(transferee);
03750 
03751 done:
03752    ast_indicate(caller, -1);
03753    if (chan && (ready || chan->_state == AST_STATE_UP)) {
03754       state = AST_CONTROL_ANSWER;
03755    } else if (chan) {
03756       ast_hangup(chan);
03757       chan = NULL;
03758    }
03759 
03760    if (outstate)
03761       *outstate = state;
03762 
03763    return chan;
03764 }

static int find_channel_by_group ( void *  obj,
void *  arg,
void *  data,
int  flags 
) [static]

< Potential pickup target

< Channel wanting to pickup call

Definition at line 7237 of file features.c.

References ast_can_pickup(), ast_channel_lock, ast_channel_unlock, ast_channel::callgroup, CMP_MATCH, CMP_STOP, and ast_channel::pickupgroup.

Referenced by ast_pickup_call().

07238 {
07239    struct ast_channel *target = obj;/*!< Potential pickup target */
07240    struct ast_channel *chan = data;/*!< Channel wanting to pickup call */
07241 
07242    ast_channel_lock(target);
07243    if (chan != target && (chan->pickupgroup & target->callgroup)
07244       && ast_can_pickup(target)) {
07245       /* Return with the channel still locked on purpose */
07246       return CMP_MATCH | CMP_STOP;
07247    }
07248    ast_channel_unlock(target);
07249 
07250    return 0;
07251 }

static struct ast_call_feature* find_dynamic_feature ( const char *  name  )  [static, read]

find a call feature by name

Definition at line 3042 of file features.c.

References AST_RWLIST_TRAVERSE, and ast_call_feature::sname.

Referenced by feature_interpret_helper(), process_applicationmap_line(), process_config(), and set_config_flags().

03043 {
03044    struct ast_call_feature *tmp;
03045 
03046    AST_RWLIST_TRAVERSE(&feature_list, tmp, feature_entry) {
03047       if (!strcasecmp(tmp->sname, name)) {
03048          break;
03049       }
03050    }
03051 
03052    return tmp;
03053 }

static struct feature_group* find_group ( const char *  name  )  [static, read]

Find a group by name.

Parameters:
name feature name
Return values:
feature group on success.
NULL on failure.

Definition at line 3080 of file features.c.

References AST_LIST_TRAVERSE, and feature_group::gname.

Referenced by feature_interpret_helper().

03081 {
03082    struct feature_group *fg = NULL;
03083 
03084    AST_LIST_TRAVERSE(&feature_groups, fg, entry) {
03085       if (!strcasecmp(fg->gname, name))
03086          break;
03087    }
03088 
03089    return fg;
03090 }

static struct ast_parkinglot * find_parkinglot ( const char *  name  )  [static, read]

Find parkinglot by name.

Definition at line 4903 of file features.c.

References ao2_find, ast_debug, ast_strlen_zero(), ast_parkinglot::name, and parkinglots.

Referenced by ast_masq_park_call_exten(), ast_park_call_exten(), build_parkinglot(), copy_parkinglot(), create_dynamic_parkinglot(), manager_park(), park_call_exec(), park_space_reserve(), parked_call_exec(), and xfer_park_call_helper().

04904 {
04905    struct ast_parkinglot *parkinglot;
04906 
04907    if (ast_strlen_zero(name)) {
04908       return NULL;
04909    }
04910 
04911    parkinglot = ao2_find(parkinglots, (void *) name, 0);
04912    if (parkinglot) {
04913       ast_debug(1, "Found Parking lot: %s\n", parkinglot->name);
04914    }
04915 
04916    return parkinglot;
04917 }

static const char* findparkinglotname ( struct ast_channel *  chan  )  [static]

Find parking lot name from channel.

Note:
Channel needs to be locked while the returned string is in use.

Definition at line 1047 of file features.c.

References ast_strlen_zero(), name, and pbx_builtin_getvar_helper().

Referenced by park_call_exec(), park_space_reserve(), parked_call_exec(), and xfer_park_call_helper().

01048 {
01049    const char *name;
01050 
01051    /* The channel variable overrides everything */
01052    name = pbx_builtin_getvar_helper(chan, "PARKINGLOT");
01053    if (!name && !ast_strlen_zero(chan->parkinglot)) {
01054       /* Use the channel's parking lot. */
01055       name = chan->parkinglot;
01056    }
01057    return name;
01058 }

static int finishup ( struct ast_channel *  chan  )  [static]

Definition at line 1827 of file features.c.

References ast_autoservice_stop(), AST_CONTROL_UNHOLD, and ast_indicate().

Referenced by atxfer_fail_cleanup(), builtin_atxfer(), builtin_blindtransfer(), and xfer_park_call_helper().

01828 {
01829    ast_indicate(chan, AST_CONTROL_UNHOLD);
01830 
01831    return ast_autoservice_stop(chan);
01832 }

static struct ast_exten* get_parking_exten ( const char *  exten_str,
struct ast_channel *  chan,
const char *  context 
) [static, read]

Definition at line 819 of file features.c.

References ast_debug, ast_get_extension_app(), E_MATCH, parkcall, pbx_find_extension(), and pbx_find_info::stacklen.

Referenced by ast_masq_park_call_exten(), ast_park_call_exten(), ast_parking_ext_valid(), builtin_atxfer(), and builtin_blindtransfer().

00820 {
00821    struct ast_exten *exten;
00822    struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
00823    const char *app_at_exten;
00824 
00825    ast_debug(4, "Checking if %s@%s is a parking exten\n", exten_str, context);
00826    exten = pbx_find_extension(chan, NULL, &q, context, exten_str, 1, NULL, NULL,
00827       E_MATCH);
00828    if (!exten) {
00829       return NULL;
00830    }
00831 
00832    app_at_exten = ast_get_extension_app(exten);
00833    if (!app_at_exten || strcasecmp(parkcall, app_at_exten)) {
00834       return NULL;
00835    }
00836 
00837    return exten;
00838 }

static char* handle_feature_show ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

CLI command to list configured features.

Parameters:
e 
cmd 
a 
Return values:
CLI_SUCCESS on success.
NULL when tab completion is used.

Definition at line 6680 of file features.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), AST_CLI_YESNO, AST_LIST_TRAVERSE, ast_pickup_ext(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_rwlock_rdlock, ast_rwlock_unlock, ast_parkinglot::cfg, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_call_feature::default_exten, ast_parkinglot::disabled, feature_group_exten::exten, ast_call_feature::exten, ast_cli_args::fd, feature_group_exten::feature, feature_group::features, FEATURES_COUNT, features_lock, ast_call_feature::fname, feature_group::gname, HFS_FORMAT, parkinglot_cfg::mohclass, ast_parkinglot::name, parkinglot_cfg::parkext, parkinglot_cfg::parking_con, parkinglot_cfg::parking_start, parkinglot_cfg::parking_stop, parkinglots, parkinglot_cfg::parkingtime, ast_call_feature::sname, and ast_cli_entry::usage.

06681 {
06682    int i;
06683    struct ast_call_feature *feature;
06684    struct ao2_iterator iter;
06685    struct ast_parkinglot *curlot;
06686 #define HFS_FORMAT "%-25s %-7s %-7s\n"
06687 
06688    switch (cmd) {
06689    
06690    case CLI_INIT:
06691       e->command = "features show";
06692       e->usage =
06693          "Usage: features show\n"
06694          "       Lists configured features\n";
06695       return NULL;
06696    case CLI_GENERATE:
06697       return NULL;
06698    }
06699 
06700    ast_cli(a->fd, HFS_FORMAT, "Builtin Feature", "Default", "Current");
06701    ast_cli(a->fd, HFS_FORMAT, "---------------", "-------", "-------");
06702 
06703    ast_cli(a->fd, HFS_FORMAT, "Pickup", "*8", ast_pickup_ext());          /* default hardcoded above, so we'll hardcode it here */
06704 
06705    ast_rwlock_rdlock(&features_lock);
06706    for (i = 0; i < FEATURES_COUNT; i++)
06707       ast_cli(a->fd, HFS_FORMAT, builtin_features[i].fname, builtin_features[i].default_exten, builtin_features[i].exten);
06708    ast_rwlock_unlock(&features_lock);
06709 
06710    ast_cli(a->fd, "\n");
06711    ast_cli(a->fd, HFS_FORMAT, "Dynamic Feature", "Default", "Current");
06712    ast_cli(a->fd, HFS_FORMAT, "---------------", "-------", "-------");
06713    if (AST_RWLIST_EMPTY(&feature_list)) {
06714       ast_cli(a->fd, "(none)\n");
06715    } else {
06716       AST_RWLIST_RDLOCK(&feature_list);
06717       AST_RWLIST_TRAVERSE(&feature_list, feature, feature_entry) {
06718          ast_cli(a->fd, HFS_FORMAT, feature->sname, "no def", feature->exten);
06719       }
06720       AST_RWLIST_UNLOCK(&feature_list);
06721    }
06722 
06723    ast_cli(a->fd, "\nFeature Groups:\n");
06724    ast_cli(a->fd, "---------------\n");
06725    if (AST_RWLIST_EMPTY(&feature_groups)) {
06726       ast_cli(a->fd, "(none)\n");
06727    } else {
06728       struct feature_group *fg;
06729       struct feature_group_exten *fge;
06730 
06731       AST_RWLIST_RDLOCK(&feature_groups);
06732       AST_RWLIST_TRAVERSE(&feature_groups, fg, entry) {
06733          ast_cli(a->fd, "===> Group: %s\n", fg->gname);
06734          AST_LIST_TRAVERSE(&fg->features, fge, entry) {
06735             ast_cli(a->fd, "===> --> %s (%s)\n", fge->feature->sname, fge->exten);
06736          }
06737       }
06738       AST_RWLIST_UNLOCK(&feature_groups);
06739    }
06740 
06741    iter = ao2_iterator_init(parkinglots, 0);
06742    while ((curlot = ao2_iterator_next(&iter))) {
06743       ast_cli(a->fd, "\nCall parking (Parking lot: %s)\n", curlot->name);
06744       ast_cli(a->fd, "------------\n");
06745       ast_cli(a->fd,"%-22s:      %s\n", "Parking extension", curlot->cfg.parkext);
06746       ast_cli(a->fd,"%-22s:      %s\n", "Parking context", curlot->cfg.parking_con);
06747       ast_cli(a->fd,"%-22s:      %d-%d\n", "Parked call extensions",
06748          curlot->cfg.parking_start, curlot->cfg.parking_stop);
06749       ast_cli(a->fd,"%-22s:      %d ms\n", "Parkingtime", curlot->cfg.parkingtime);
06750       ast_cli(a->fd,"%-22s:      %s\n", "MusicOnHold class", curlot->cfg.mohclass);
06751       ast_cli(a->fd,"%-22s:      %s\n", "Enabled", AST_CLI_YESNO(!curlot->disabled));
06752       ast_cli(a->fd,"\n");
06753       ao2_ref(curlot, -1);
06754    }
06755    ao2_iterator_destroy(&iter);
06756 
06757    return CLI_SUCCESS;
06758 }

static char* handle_features_reload ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 6786 of file features.c.

References ast_features_reload(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, and ast_cli_entry::usage.

06787 {
06788    switch (cmd) { 
06789    case CLI_INIT:
06790       e->command = "features reload";
06791       e->usage =
06792          "Usage: features reload\n"
06793          "       Reloads configured call features from features.conf\n";
06794       return NULL;
06795    case CLI_GENERATE:
06796       return NULL;
06797    }
06798    ast_features_reload();
06799 
06800    return CLI_SUCCESS;
06801 }

static char* handle_parkedcalls ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

CLI command to list parked calls.

Parameters:
e 
cmd 
a Check right usage, lock parking lot, display parked calls, unlock parking lot list.
Return values:
CLI_SUCCESS on success.
CLI_SHOWUSAGE on incorrect number of arguments.
NULL when tab completion is used.

Definition at line 6990 of file features.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli_args::argc, ast_cli_entry::args, ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, parkeduser::chan, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, parkeduser::context, default_parkinglot, ESS, parkeduser::exten, ast_cli_args::fd, ast_parkinglot::name, parkeduser::parkingexten, parkinglots, ast_parkinglot::parkings, parkeduser::parkingtime, parkeduser::priority, parkeduser::start, and ast_cli_entry::usage.

06991 {
06992    struct parkeduser *cur;
06993    int numparked = 0;
06994    struct ao2_iterator iter;
06995    struct ast_parkinglot *curlot;
06996 
06997    switch (cmd) {
06998    case CLI_INIT:
06999       e->command = "parkedcalls show";
07000       e->usage =
07001          "Usage: parkedcalls show\n"
07002          "       List currently parked calls\n";
07003       return NULL;
07004    case CLI_GENERATE:
07005       return NULL;
07006    }
07007 
07008    if (a->argc > e->args)
07009       return CLI_SHOWUSAGE;
07010 
07011    ast_cli(a->fd, "%-10s %-25s (%-15s %-12s %4s) %s\n", "Num", "Channel",
07012       "Context", "Extension", "Pri", "Timeout");
07013 
07014    iter = ao2_iterator_init(parkinglots, 0);
07015    while ((curlot = ao2_iterator_next(&iter))) {
07016       int lotparked = 0;
07017 
07018       /* subtract ref for iterator and for configured parking lot */
07019       ast_cli(a->fd, "*** Parking lot: %s (%d)\n", curlot->name,
07020          ao2_ref(curlot, 0) - 2 - (curlot == default_parkinglot));
07021 
07022       AST_LIST_LOCK(&curlot->parkings);
07023       AST_LIST_TRAVERSE(&curlot->parkings, cur, list) {
07024          ast_cli(a->fd, "%-10.10s %-25s (%-15s %-12s %4d) %6lds\n",
07025             cur->parkingexten, cur->chan->name, cur->context, cur->exten,
07026             cur->priority,
07027             (long) (cur->start.tv_sec + (cur->parkingtime / 1000) - time(NULL)));
07028          ++lotparked;
07029       }
07030       AST_LIST_UNLOCK(&curlot->parkings);
07031       if (lotparked) {
07032          numparked += lotparked;
07033          ast_cli(a->fd, "   %d parked call%s in parking lot %s\n", lotparked,
07034             ESS(lotparked), curlot->name);
07035       }
07036 
07037       ao2_ref(curlot, -1);
07038    }
07039    ao2_iterator_destroy(&iter);
07040 
07041    ast_cli(a->fd, "---\n%d parked call%s in total.\n", numparked, ESS(numparked));
07042 
07043    return CLI_SUCCESS;
07044 }

static int load_config ( int  reload  )  [static]

Definition at line 6597 of file features.c.

References ao2_t_callback, ast_config_destroy(), ast_config_load2(), ast_debug, AST_LIST_HEAD_NOLOCK_INIT_VALUE, ast_log(), build_dialplan_useage_map(), build_parkinglot(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_PARKINGLOT, default_parkinglot, destroy_dialplan_usage_map(), force_reload_load, LOG_ERROR, LOG_WARNING, OBJ_NODATA, OBJ_UNLINK, parkinglot_activate_cb(), parkinglot_addref(), parkinglot_is_marked_cb(), parkinglot_markall_cb(), parkinglots, process_config(), and remove_dead_dialplan_useage().

Referenced by ast_features_init(), and ast_features_reload().

06598 {
06599    struct ast_flags config_flags = {
06600       reload && !force_reload_load ? CONFIG_FLAG_FILEUNCHANGED : 0 };
06601    struct ast_config *cfg;
06602    struct parking_dp_map old_usage_map = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
06603    struct parking_dp_map new_usage_map = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
06604 
06605    /* We are reloading now and have already determined if we will force the reload. */
06606    force_reload_load = 0;
06607 
06608    if (!default_parkinglot) {
06609       /* Must create the default default parking lot */
06610       default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
06611       if (!default_parkinglot) {
06612          ast_log(LOG_ERROR, "Configuration of default default parking lot failed.\n");
06613          return -1;
06614       }
06615       ast_debug(1, "Configuration of default default parking lot done.\n");
06616       parkinglot_addref(default_parkinglot);
06617    }
06618 
06619    cfg = ast_config_load2("features.conf", "features", config_flags);
06620    if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
06621       /* No sense in asking for reload trouble if nothing changed. */
06622       ast_debug(1, "features.conf did not change.\n");
06623       return 0;
06624    }
06625    if (cfg == CONFIG_STATUS_FILEMISSING
06626       || cfg == CONFIG_STATUS_FILEINVALID) {
06627       ast_log(LOG_WARNING, "Could not load features.conf\n");
06628       return 0;
06629    }
06630 
06631    /* Save current parking lot dialplan needs. */
06632    if (build_dialplan_useage_map(&old_usage_map, 0)) {
06633       destroy_dialplan_usage_map(&old_usage_map);
06634 
06635       /* Allow reloading later to see if conditions have improved. */
06636       force_reload_load = 1;
06637       return -1;
06638    }
06639 
06640    ao2_t_callback(parkinglots, OBJ_NODATA, parkinglot_markall_cb, NULL,
06641       "callback to mark all parking lots");
06642    process_config(cfg);
06643    ast_config_destroy(cfg);
06644    ao2_t_callback(parkinglots, OBJ_NODATA | OBJ_UNLINK, parkinglot_is_marked_cb, NULL,
06645       "callback to remove marked parking lots");
06646 
06647    /* Save updated parking lot dialplan needs. */
06648    if (build_dialplan_useage_map(&new_usage_map, 1)) {
06649       /*
06650        * Yuck, if this failure caused any parking lot dialplan items
06651        * to be lost, they will likely remain lost until Asterisk is
06652        * restarted.
06653        */
06654       destroy_dialplan_usage_map(&old_usage_map);
06655       destroy_dialplan_usage_map(&new_usage_map);
06656       return -1;
06657    }
06658 
06659    /* Remove no longer needed parking lot dialplan usage. */
06660    remove_dead_dialplan_useage(&old_usage_map, &new_usage_map);
06661 
06662    destroy_dialplan_usage_map(&old_usage_map);
06663    destroy_dialplan_usage_map(&new_usage_map);
06664 
06665    ao2_t_callback(parkinglots, OBJ_NODATA, parkinglot_activate_cb, NULL,
06666       "callback to activate all parking lots");
06667 
06668    return 0;
06669 }

static int manage_parked_call ( struct parkeduser *  pu,
const struct pollfd *  pfds,
int  nfds,
struct pollfd **  new_pfds,
int *  new_nfds,
int *  ms 
) [static]

Definition at line 4607 of file features.c.

References ast_add_extension(), AST_CEL_PARK_END, ast_cel_report_event(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_context_find_or_create(), AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_debug, AST_FLAG_EXCEPTION, AST_FRAME_CONTROL, ast_free_ptr(), ast_frfree, ast_hangup(), ast_indicate(), ast_indicate_data(), ast_log(), AST_MAX_EXTENSION, ast_pbx_start(), ast_read(), ast_realloc, ast_set_flag, ast_strdup, ast_strdupa, ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, callback_dialoptions(), ast_parkinglot::cfg, parkeduser::chan, comebacktoorigin, ast_channel::context, parkeduser::context, ast_datastore::data, dial_features_info, ast_channel::exten, parkeduser::exten, f, ast_channel::fdno, ast_channel::fds, ast_frame::frametype, ast_channel::generatordata, parkeduser::hold_method, ast_frame_subclass::integer, LOG_ERROR, LOG_NOTICE, LOG_WARNING, MAX_DIAL_FEATURE_OPTIONS, parkeduser::moh_trys, parkinglot_cfg::mohclass, ast_dial_features::my_features, ast_parkinglot::name, parkeduser::options_specified, parking_con_dial, parkeduser::parkinglot, parkeduser::parkingnum, parkeduser::parkingtime, pbx_builtin_setvar_helper(), ast_dial_features::peer_features, parkeduser::peername, post_manager_event(), ast_channel::priority, parkeduser::priority, registrar, S_OR, set_c_e_p(), parkeduser::start, and ast_frame::subclass.

Referenced by manage_parkinglot().

04608 {
04609    struct ast_channel *chan = pu->chan;   /* shorthand */
04610    int tms;        /* timeout for this item */
04611    int x;          /* fd index in channel */
04612 
04613    tms = ast_tvdiff_ms(ast_tvnow(), pu->start);
04614    if (tms > pu->parkingtime) {
04615       /*
04616        * Call has been parked too long.
04617        * Stop entertaining the caller.
04618        */
04619       switch (pu->hold_method) {
04620       case AST_CONTROL_HOLD:
04621          ast_indicate(pu->chan, AST_CONTROL_UNHOLD);
04622          break;
04623       case AST_CONTROL_RINGING:
04624          ast_indicate(pu->chan, -1);
04625          break;
04626       default:
04627          break;
04628       }
04629       pu->hold_method = 0;
04630 
04631       /* Get chan, exten from derived kludge */
04632       if (pu->peername[0]) {
04633          char *peername;
04634          char *dash;
04635          char *peername_flat; /* using something like DAHDI/52 for an extension name is NOT a good idea */
04636          int i;
04637 
04638          peername = ast_strdupa(pu->peername);
04639          dash = strrchr(peername, '-');
04640          if (dash) {
04641             *dash = '\0';
04642          }
04643 
04644          peername_flat = ast_strdupa(peername);
04645          for (i = 0; peername_flat[i]; i++) {
04646             if (peername_flat[i] == '/') {
04647                peername_flat[i] = '_';
04648             }
04649          }
04650 
04651          if (!ast_context_find_or_create(NULL, NULL, parking_con_dial, registrar)) {
04652             ast_log(LOG_ERROR,
04653                "Parking dial context '%s' does not exist and unable to create\n",
04654                parking_con_dial);
04655          } else {
04656             char returnexten[AST_MAX_EXTENSION];
04657             struct ast_datastore *features_datastore;
04658             struct ast_dial_features *dialfeatures;
04659 
04660             if (!strncmp(peername, "Parked/", 7)) {
04661                peername += 7;
04662             }
04663 
04664             ast_channel_lock(chan);
04665             features_datastore = ast_channel_datastore_find(chan, &dial_features_info,
04666                NULL);
04667             if (features_datastore && (dialfeatures = features_datastore->data)) {
04668                char buf[MAX_DIAL_FEATURE_OPTIONS] = {0,};
04669 
04670                snprintf(returnexten, sizeof(returnexten), "%s,30,%s", peername,
04671                   callback_dialoptions(&dialfeatures->peer_features,
04672                      &dialfeatures->my_features, buf, sizeof(buf)));
04673             } else { /* Existing default */
04674                ast_log(LOG_NOTICE, "Dial features not found on %s, using default!\n",
04675                   chan->name);
04676                snprintf(returnexten, sizeof(returnexten), "%s,30,t", peername);
04677             }
04678             ast_channel_unlock(chan);
04679 
04680             if (ast_add_extension(parking_con_dial, 1, peername_flat, 1, NULL, NULL,
04681                "Dial", ast_strdup(returnexten), ast_free_ptr, registrar)) {
04682                ast_log(LOG_ERROR,
04683                   "Could not create parking return dial exten: %s@%s\n",
04684                   peername_flat, parking_con_dial);
04685             }
04686          }
04687          if (pu->options_specified) {
04688             /*
04689              * Park() was called with overriding return arguments, respect
04690              * those arguments.
04691              */
04692             set_c_e_p(chan, pu->context, pu->exten, pu->priority);
04693          } else if (comebacktoorigin) {
04694             set_c_e_p(chan, parking_con_dial, peername_flat, 1);
04695          } else {
04696             char parkingslot[AST_MAX_EXTENSION];
04697 
04698             snprintf(parkingslot, sizeof(parkingslot), "%d", pu->parkingnum);
04699             pbx_builtin_setvar_helper(chan, "PARKINGSLOT", parkingslot);
04700             set_c_e_p(chan, "parkedcallstimeout", peername_flat, 1);
04701          }
04702       } else {
04703          /*
04704           * They've been waiting too long, send them back to where they
04705           * came.  Theoretically they should have their original
04706           * extensions and such, but we copy to be on the safe side.
04707           */
04708          set_c_e_p(chan, pu->context, pu->exten, pu->priority);
04709       }
04710       post_manager_event("ParkedCallTimeOut", pu);
04711       ast_cel_report_event(pu->chan, AST_CEL_PARK_END, NULL, "ParkedCallTimeOut", NULL);
04712 
04713       ast_verb(2, "Timeout for %s parked on %d (%s). Returning to %s,%s,%d\n",
04714          pu->chan->name, pu->parkingnum, pu->parkinglot->name, pu->chan->context,
04715          pu->chan->exten, pu->chan->priority);
04716 
04717       /* Start up the PBX, or hang them up */
04718       if (ast_pbx_start(chan))  {
04719          ast_log(LOG_WARNING,
04720             "Unable to restart the PBX for user on '%s', hanging them up...\n",
04721             pu->chan->name);
04722          ast_hangup(chan);
04723       }
04724 
04725       /* And take them out of the parking lot */
04726       return 1;
04727    }
04728 
04729    /* still within parking time, process descriptors */
04730    if (pfds) {
04731       for (x = 0; x < AST_MAX_FDS; x++) {
04732          struct ast_frame *f;
04733          int y;
04734 
04735          if (chan->fds[x] == -1) {
04736             continue;   /* nothing on this descriptor */
04737          }
04738 
04739          for (y = 0; y < nfds; y++) {
04740             if (pfds[y].fd == chan->fds[x]) {
04741                /* Found poll record! */
04742                break;
04743             }
04744          }
04745          if (y == nfds) {
04746             /* Not found */
04747             continue;
04748          }
04749 
04750          if (!(pfds[y].revents & (POLLIN | POLLERR | POLLPRI))) {
04751             /* Next x */
04752             continue;
04753          }
04754 
04755          if (pfds[y].revents & POLLPRI) {
04756             ast_set_flag(chan, AST_FLAG_EXCEPTION);
04757          } else {
04758             ast_clear_flag(chan, AST_FLAG_EXCEPTION);
04759          }
04760          chan->fdno = x;
04761 
04762          /* See if they need servicing */
04763          f = ast_read(pu->chan);
04764          /* Hangup? */
04765          if (!f || (f->frametype == AST_FRAME_CONTROL
04766             && f->subclass.integer == AST_CONTROL_HANGUP)) {
04767             if (f) {
04768                ast_frfree(f);
04769             }
04770             post_manager_event("ParkedCallGiveUp", pu);
04771             ast_cel_report_event(pu->chan, AST_CEL_PARK_END, NULL, "ParkedCallGiveUp",
04772                NULL);
04773 
04774             /* There's a problem, hang them up */
04775             ast_verb(2, "%s got tired of being parked\n", chan->name);
04776             ast_hangup(chan);
04777 
04778             /* And take them out of the parking lot */
04779             return 1;
04780          } else {
04781             /* XXX Maybe we could do something with packets, like dial "0" for operator or something XXX */
04782             ast_frfree(f);
04783             if (pu->hold_method == AST_CONTROL_HOLD
04784                && pu->moh_trys < 3
04785                && !chan->generatordata) {
04786                ast_debug(1,
04787                   "MOH on parked call stopped by outside source.  Restarting on channel %s.\n",
04788                   chan->name);
04789                ast_indicate_data(chan, AST_CONTROL_HOLD,
04790                   S_OR(pu->parkinglot->cfg.mohclass, NULL),
04791                   (!ast_strlen_zero(pu->parkinglot->cfg.mohclass)
04792                      ? strlen(pu->parkinglot->cfg.mohclass) + 1 : 0));
04793                pu->moh_trys++;
04794             }
04795             break;
04796          }
04797       } /* End for */
04798    }
04799 
04800    /* mark fds for next round */
04801    for (x = 0; x < AST_MAX_FDS; x++) {
04802       if (chan->fds[x] > -1) {
04803          void *tmp = ast_realloc(*new_pfds,
04804             (*new_nfds + 1) * sizeof(struct pollfd));
04805 
04806          if (!tmp) {
04807             continue;
04808          }
04809          *new_pfds = tmp;
04810          (*new_pfds)[*new_nfds].fd = chan->fds[x];
04811          (*new_pfds)[*new_nfds].events = POLLIN | POLLERR | POLLPRI;
04812          (*new_pfds)[*new_nfds].revents = 0;
04813          (*new_nfds)++;
04814       }
04815    }
04816    /* Keep track of our shortest wait */
04817    if (tms < *ms || *ms < 0) {
04818       *ms = tms;
04819    }
04820 
04821    /* Stay in the parking lot. */
04822    return 0;
04823 }

static void manage_parkinglot ( struct ast_parkinglot *  curlot,
const struct pollfd *  pfds,
int  nfds,
struct pollfd **  new_pfds,
int *  new_nfds,
int *  ms 
) [static]

Run management on parkinglots, called once per parkinglot.

Definition at line 4826 of file features.c.

References ast_context_find(), ast_context_remove_extension2(), AST_DEVICE_NOT_INUSE, ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_parkinglot::cfg, LOG_WARNING, manage_parked_call(), ast_parkinglot::name, notify_metermaids(), parkeduser::notquiteyet, parkinglot_cfg::parking_con, parkeduser::parkingexten, parkeduser::parkinglot, parkinglot_unref(), and ast_parkinglot::parkings.

Referenced by do_parking_thread().

04827 {
04828    struct parkeduser *pu;
04829    struct ast_context *con;
04830 
04831    /* Lock parkings list */
04832    AST_LIST_LOCK(&curlot->parkings);
04833    AST_LIST_TRAVERSE_SAFE_BEGIN(&curlot->parkings, pu, list) {
04834       if (pu->notquiteyet) { /* Pretend this one isn't here yet */
04835          continue;
04836       }
04837       if (manage_parked_call(pu, pfds, nfds, new_pfds, new_nfds, ms)) {
04838          /* Parking is complete for this call so remove it from the parking lot. */
04839          con = ast_context_find(pu->parkinglot->cfg.parking_con);
04840          if (con) {
04841             if (ast_context_remove_extension2(con, pu->parkingexten, 1, NULL, 0)) {
04842                ast_log(LOG_WARNING,
04843                   "Whoa, failed to remove the parking extension %s@%s!\n",
04844                   pu->parkingexten, pu->parkinglot->cfg.parking_con);
04845             }
04846             notify_metermaids(pu->parkingexten, pu->parkinglot->cfg.parking_con,
04847                AST_DEVICE_NOT_INUSE);
04848          } else {
04849             ast_log(LOG_WARNING,
04850                "Whoa, parking lot '%s' context '%s' does not exist.\n",
04851                pu->parkinglot->name, pu->parkinglot->cfg.parking_con);
04852          }
04853          AST_LIST_REMOVE_CURRENT(list);
04854          parkinglot_unref(pu->parkinglot);
04855          ast_free(pu);
04856       }
04857    }
04858    AST_LIST_TRAVERSE_SAFE_END;
04859    AST_LIST_UNLOCK(&curlot->parkings);
04860 }

static int manager_park ( struct mansession *  s,
const struct message *  m 
) [static]

Create manager event for parked calls.

Parameters:
s 
m Get channels involved in park, create event.
Returns:
Always 0
Note:
ADSI is not compatible with this AMI action for the same reason ch2 can no longer announce the parking space.

Definition at line 7126 of file features.c.

References ast_channel_get_by_name(), ast_channel_unref, AST_PARK_OPT_SILENCE, ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), find_parkinglot(), ast_park_call_args::flags, masq_park_call(), ast_park_call_args::parkinglot, parkinglot_unref(), and ast_park_call_args::timeout.

Referenced by ast_features_init().

07127 {
07128    const char *channel = astman_get_header(m, "Channel");
07129    const char *channel2 = astman_get_header(m, "Channel2");
07130    const char *timeout = astman_get_header(m, "Timeout");
07131    const char *parkinglotname = astman_get_header(m, "Parkinglot");
07132    char buf[BUFSIZ];
07133    int res = 0;
07134    struct ast_channel *ch1, *ch2;
07135    struct ast_park_call_args args = {
07136          /*
07137           * Don't say anything to ch2 since AMI is a third party parking
07138           * a call and we will likely crash if we do.
07139           *
07140           * XXX When the AMI action was originally implemented, the
07141           * parking space was announced to ch2.  Unfortunately, grabbing
07142           * the ch2 lock and holding it while the announcement is played
07143           * was not really a good thing to do to begin with since it
07144           * could hold up the system.  Also holding the lock is no longer
07145           * possible with a masquerade.
07146           *
07147           * Restoring the announcement to ch2 is not easily doable for
07148           * the following reasons:
07149           *
07150           * 1) The AMI manager is not the thread processing ch2.
07151           *
07152           * 2) ch2 could be the same as ch1, bridged to ch1, or some
07153           * random uninvolved channel.
07154           */
07155          .flags = AST_PARK_OPT_SILENCE,
07156       };
07157 
07158    if (ast_strlen_zero(channel)) {
07159       astman_send_error(s, m, "Channel not specified");
07160       return 0;
07161    }
07162 
07163    if (ast_strlen_zero(channel2)) {
07164       astman_send_error(s, m, "Channel2 not specified");
07165       return 0;
07166    }
07167 
07168    if (!ast_strlen_zero(timeout)) {
07169       if (sscanf(timeout, "%30d", &args.timeout) != 1) {
07170          astman_send_error(s, m, "Invalid timeout value.");
07171          return 0;
07172       }
07173    }
07174 
07175    if (!(ch1 = ast_channel_get_by_name(channel))) {
07176       snprintf(buf, sizeof(buf), "Channel does not exist: %s", channel);
07177       astman_send_error(s, m, buf);
07178       return 0;
07179    }
07180 
07181    if (!(ch2 = ast_channel_get_by_name(channel2))) {
07182       snprintf(buf, sizeof(buf), "Channel does not exist: %s", channel2);
07183       astman_send_error(s, m, buf);
07184       ast_channel_unref(ch1);
07185       return 0;
07186    }
07187 
07188    if (!ast_strlen_zero(parkinglotname)) {
07189       args.parkinglot = find_parkinglot(parkinglotname);
07190    }
07191 
07192    res = masq_park_call(ch1, ch2, &args);
07193    if (!res) {
07194       ast_softhangup(ch2, AST_SOFTHANGUP_EXPLICIT);
07195       astman_send_ack(s, m, "Park successful");
07196    } else {
07197       astman_send_error(s, m, "Park failure");
07198    }
07199 
07200    if (args.parkinglot) {
07201       parkinglot_unref(args.parkinglot);
07202    }
07203    ch1 = ast_channel_unref(ch1);
07204    ch2 = ast_channel_unref(ch2);
07205 
07206    return 0;
07207 }

static int manager_parking_status ( struct mansession *  s,
const struct message *  m 
) [static]

Dump parking lot status.

Parameters:
s 
m Lock parking lot, iterate list and append parked calls status, unlock parking lot.
Returns:
Always RESULT_SUCCESS

Definition at line 7060 of file features.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), ast_channel::caller, parkeduser::chan, ast_channel::connected, ast_party_connected_line::id, ast_party_caller::id, ast_party_id::name, ast_parkinglot::name, ast_party_id::number, parkinglots, parkeduser::parkingnum, ast_parkinglot::parkings, parkeduser::parkingtime, parkeduser::peername, RESULT_SUCCESS, S_COR, parkeduser::start, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by ast_features_init().

07061 {
07062    struct parkeduser *cur;
07063    const char *id = astman_get_header(m, "ActionID");
07064    char idText[256] = "";
07065    struct ao2_iterator iter;
07066    struct ast_parkinglot *curlot;
07067    int numparked = 0;
07068 
07069    if (!ast_strlen_zero(id))
07070       snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
07071 
07072    astman_send_ack(s, m, "Parked calls will follow");
07073 
07074    iter = ao2_iterator_init(parkinglots, 0);
07075    while ((curlot = ao2_iterator_next(&iter))) {
07076       AST_LIST_LOCK(&curlot->parkings);
07077       AST_LIST_TRAVERSE(&curlot->parkings, cur, list) {
07078          astman_append(s, "Event: ParkedCall\r\n"
07079             "Parkinglot: %s\r\n"
07080             "Exten: %d\r\n"
07081             "Channel: %s\r\n"
07082             "From: %s\r\n"
07083             "Timeout: %ld\r\n"
07084             "CallerIDNum: %s\r\n"
07085             "CallerIDName: %s\r\n"
07086             "ConnectedLineNum: %s\r\n"
07087             "ConnectedLineName: %s\r\n"
07088             "%s"
07089             "\r\n",
07090             curlot->name,
07091             cur->parkingnum, cur->chan->name, cur->peername,
07092             (long) cur->start.tv_sec + (long) (cur->parkingtime / 1000) - (long) time(NULL),
07093             S_COR(cur->chan->caller.id.number.valid, cur->chan->caller.id.number.str, ""),   /* XXX in other places it is <unknown> */
07094             S_COR(cur->chan->caller.id.name.valid, cur->chan->caller.id.name.str, ""),
07095             S_COR(cur->chan->connected.id.number.valid, cur->chan->connected.id.number.str, ""),   /* XXX in other places it is <unknown> */
07096             S_COR(cur->chan->connected.id.name.valid, cur->chan->connected.id.name.str, ""),
07097             idText);
07098          ++numparked;
07099       }
07100       AST_LIST_UNLOCK(&curlot->parkings);
07101       ao2_ref(curlot, -1);
07102    }
07103    ao2_iterator_destroy(&iter);
07104 
07105    astman_append(s,
07106       "Event: ParkedCallsComplete\r\n"
07107       "Total: %d\r\n"
07108       "%s"
07109       "\r\n",
07110       numparked, idText);
07111 
07112    return RESULT_SUCCESS;
07113 }

static int masq_park_call ( struct ast_channel *  rchan,
struct ast_channel *  peer,
struct ast_park_call_args *  args 
) [static]

Park call via masqueraded channel and announce parking spot on peer channel.

Parameters:
rchan the real channel to be parked
peer the channel to have the parking read to.
args Additional parking options when parking a call.
Return values:
0 on success.
-1 on failure.

Definition at line 1683 of file features.c.

References ast_channel::amaflags, ast_channel_alloc, ast_channel_masquerade(), ast_copy_string(), ast_do_masquerade(), ast_hangup(), ast_log(), AST_PARK_OPT_SILENCE, AST_STATE_DOWN, ast_stream_and_wait(), ast_test_flag, ast_channel::context, ast_channel::exten, LOG_WARNING, ast_channel::macrocontext, ast_channel::macroexten, ast_channel::macropriority, park_call_full(), park_space_abort(), park_space_reserve(), play_message_on_chan(), ast_channel::priority, ast_park_call_args::pu, ast_channel::readformat, set_c_e_p(), and ast_channel::writeformat.

Referenced by ast_masq_park_call(), ast_masq_park_call_exten(), builtin_parkcall(), manager_park(), park_call_exec(), and xfer_park_call_helper().

01684 {
01685    struct ast_channel *chan;
01686 
01687    /* Make a new, channel that we'll use to masquerade in the real one */
01688    chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, rchan->accountcode, rchan->exten,
01689       rchan->context, rchan->linkedid, rchan->amaflags, "Parked/%s", rchan->name);
01690    if (!chan) {
01691       ast_log(LOG_WARNING, "Unable to create parked channel\n");
01692       if (!ast_test_flag(args, AST_PARK_OPT_SILENCE)) {
01693          if (peer == rchan) {
01694             /* Only have one channel to worry about. */
01695             ast_stream_and_wait(peer, "pbx-parkingfailed", "");
01696          } else if (peer) {
01697             /* Have two different channels to worry about. */
01698             play_message_on_chan(peer, rchan, "failure message", "pbx-parkingfailed");
01699          }
01700       }
01701       return -1;
01702    }
01703 
01704    args->pu = park_space_reserve(rchan, peer, args);
01705    if (!args->pu) {
01706       ast_hangup(chan);
01707       if (!ast_test_flag(args, AST_PARK_OPT_SILENCE)) {
01708          if (peer == rchan) {
01709             /* Only have one channel to worry about. */
01710             ast_stream_and_wait(peer, "pbx-parkingfailed", "");
01711          } else if (peer) {
01712             /* Have two different channels to worry about. */
01713             play_message_on_chan(peer, rchan, "failure message", "pbx-parkingfailed");
01714          }
01715       }
01716       return -1;
01717    }
01718 
01719    /* Make formats okay */
01720    chan->readformat = rchan->readformat;
01721    chan->writeformat = rchan->writeformat;
01722 
01723    if (ast_channel_masquerade(chan, rchan)) {
01724       park_space_abort(args->pu);
01725       args->pu = NULL;
01726       ast_hangup(chan);
01727       if (!ast_test_flag(args, AST_PARK_OPT_SILENCE)) {
01728          if (peer == rchan) {
01729             /* Only have one channel to worry about. */
01730             ast_stream_and_wait(peer, "pbx-parkingfailed", "");
01731          } else if (peer) {
01732             /* Have two different channels to worry about. */
01733             play_message_on_chan(peer, rchan, "failure message", "pbx-parkingfailed");
01734          }
01735       }
01736       return -1;
01737    }
01738 
01739    /* Setup the extensions and such */
01740    set_c_e_p(chan, rchan->context, rchan->exten, rchan->priority);
01741 
01742    /* Setup the macro extension and such */
01743    ast_copy_string(chan->macrocontext,rchan->macrocontext,sizeof(chan->macrocontext));
01744    ast_copy_string(chan->macroexten,rchan->macroexten,sizeof(chan->macroexten));
01745    chan->macropriority = rchan->macropriority;
01746 
01747    /* Manually do the masquerade to make sure it is complete. */
01748    ast_do_masquerade(chan);
01749 
01750    if (peer == rchan) {
01751       peer = chan;
01752    }
01753 
01754    /* parking space reserved, return code check unnecessary */
01755    park_call_full(chan, peer, args);
01756 
01757    return 0;
01758 }

static enum ast_device_state metermaidstate ( const char *  data  )  [static]

metermaids callback from devicestate.c

Definition at line 1070 of file features.c.

References ast_debug, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, ast_exists_extension(), and ast_strdupa.

Referenced by ast_features_init().

01071 {
01072    char *context;
01073    char *exten;
01074 
01075    context = ast_strdupa(data);
01076 
01077    exten = strsep(&context, "@");
01078    if (!context)
01079       return AST_DEVICE_INVALID;
01080    
01081    ast_debug(4, "Checking state of exten %s in context %s\n", exten, context);
01082 
01083    if (!ast_exists_extension(NULL, context, exten, 1, NULL))
01084       return AST_DEVICE_NOT_INUSE;
01085 
01086    return AST_DEVICE_INUSE;
01087 }

static void notify_metermaids ( const char *  exten,
char *  context,
enum ast_device_state  state 
) [static]

Notify metermaids that we've changed an extension.

Definition at line 1061 of file features.c.

References ast_debug, ast_devstate2str(), and ast_devstate_changed().

Referenced by manage_parkinglot(), park_call_full(), parked_call_exec(), and parkinglot_activate().

01062 {
01063    ast_debug(4, "Notification of state change to metermaids %s@%s\n to state '%s'", 
01064       exten, context, ast_devstate2str(state));
01065 
01066    ast_devstate_changed(state, "park:%s@%s", exten, context);
01067 }

static void park_add_hints ( const char *  context,
int  start,
int  stop 
) [static]

Add parking hints for all defined parking spaces.

Parameters:
context Dialplan context to add the hints.
start Starting space in parkinglot.
stop Ending space in parkinglot.

Definition at line 5370 of file features.c.

References ast_add_extension(), AST_MAX_EXTENSION, PRIORITY_HINT, and registrar.

Referenced by parkinglot_activate().

05371 {
05372    int numext;
05373    char device[AST_MAX_EXTENSION];
05374    char exten[10];
05375 
05376    for (numext = start; numext <= stop; numext++) {
05377       snprintf(exten, sizeof(exten), "%d", numext);
05378       snprintf(device, sizeof(device), "park:%s@%s", exten, context);
05379       ast_add_extension(context, 1, exten, PRIORITY_HINT, NULL, NULL, device, NULL, NULL, registrar);
05380    }
05381 }

static int park_call_exec ( struct ast_channel *  chan,
const char *  data 
) [static]

Park a call.

Definition at line 4949 of file features.c.

References ast_channel::_state, ast_answer(), ast_app_parse_options(), ast_copy_string(), ast_log(), AST_MAX_EXTENSION, AST_PARK_OPT_SILENCE, ast_safe_sleep(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_stream_and_wait(), ast_strlen_zero(), ast_test_flag, create_dynamic_parkinglot(), default_parkinglot, ast_channel::exten, find_parkinglot(), findparkinglotname(), ast_flags::flags, ast_park_call_args::flags, LOG_WARNING, masq_park_call(), park_app_args::options, ast_park_call_args::orig_chan_name, orig_exten(), park_call_options, parkeddynamic, ast_park_call_args::parkinglot, parkinglot_addref(), parkinglot_unref(), parse(), pbx_builtin_getvar_helper(), park_app_args::pl_name, ast_channel::priority, ast_park_call_args::return_con, park_app_args::return_con, ast_park_call_args::return_ext, park_app_args::return_ext, ast_park_call_args::return_pri, park_app_args::return_pri, S_OR, ast_park_call_args::timeout, and park_app_args::timeout.

Referenced by ast_features_init().

04950 {
04951    struct ast_park_call_args args = { 0, };
04952    struct ast_flags flags = { 0 };
04953    char orig_exten[AST_MAX_EXTENSION];
04954    int orig_priority;
04955    int res;
04956    const char *pl_name;
04957    char *parse;
04958    struct park_app_args app_args;
04959 
04960    /*
04961     * Cache the original channel name because we are going to
04962     * masquerade the channel.  Prefer the BLINDTRANSFER channel
04963     * name over this channel name.  BLINDTRANSFER could be set if
04964     * the parking access extension did not get detected and we are
04965     * executing the Park application from the dialplan.
04966     *
04967     * The orig_chan_name is used to return the call to the
04968     * originator on parking timeout.
04969     */
04970    args.orig_chan_name = ast_strdupa(S_OR(
04971       pbx_builtin_getvar_helper(chan, "BLINDTRANSFER"), chan->name));
04972 
04973    /* Answer if call is not up */
04974    if (chan->_state != AST_STATE_UP) {
04975       if (ast_answer(chan)) {
04976          return -1;
04977       }
04978 
04979       /* Sleep to allow VoIP streams to settle down */
04980       if (ast_safe_sleep(chan, 1000)) {
04981          return -1;
04982       }
04983    }
04984 
04985    /* Process the dialplan application options. */
04986    parse = ast_strdupa(data);
04987    AST_STANDARD_APP_ARGS(app_args, parse);
04988 
04989    if (!ast_strlen_zero(app_args.timeout)) {
04990       if (sscanf(app_args.timeout, "%30d", &args.timeout) != 1) {
04991          ast_log(LOG_WARNING, "Invalid timeout '%s' provided\n", app_args.timeout);
04992          args.timeout = 0;
04993       }
04994    }
04995    if (!ast_strlen_zero(app_args.return_con)) {
04996       args.return_con = app_args.return_con;
04997    }
04998    if (!ast_strlen_zero(app_args.return_ext)) {
04999       args.return_ext = app_args.return_ext;
05000    }
05001    if (!ast_strlen_zero(app_args.return_pri)) {
05002       if (sscanf(app_args.return_pri, "%30d", &args.return_pri) != 1) {
05003          ast_log(LOG_WARNING, "Invalid priority '%s' specified\n", app_args.return_pri);
05004          args.return_pri = 0;
05005       }
05006    }
05007 
05008    ast_app_parse_options(park_call_options, &flags, NULL, app_args.options);
05009    args.flags = flags.flags;
05010 
05011    /*
05012     * Setup the exten/priority to be s/1 since we don't know where
05013     * this call should return.
05014     */
05015    ast_copy_string(orig_exten, chan->exten, sizeof(orig_exten));
05016    orig_priority = chan->priority;
05017    strcpy(chan->exten, "s");
05018    chan->priority = 1;
05019 
05020    /* Park the call */
05021    if (!ast_strlen_zero(app_args.pl_name)) {
05022       pl_name = app_args.pl_name;
05023    } else {
05024       pl_name = findparkinglotname(chan);
05025    }
05026    if (ast_strlen_zero(pl_name)) {
05027       /* Parking lot is not specified, so use the default parking lot. */
05028       args.parkinglot = parkinglot_addref(default_parkinglot);
05029    } else {
05030       args.parkinglot = find_parkinglot(pl_name);
05031       if (!args.parkinglot && parkeddynamic) {
05032          args.parkinglot = create_dynamic_parkinglot(pl_name, chan);
05033       }
05034    }
05035    if (args.parkinglot) {
05036       res = masq_park_call(chan, chan, &args);
05037       parkinglot_unref(args.parkinglot);
05038    } else {
05039       /* Parking failed because the parking lot does not exist. */
05040       if (!ast_test_flag(&args, AST_PARK_OPT_SILENCE)) {
05041          ast_stream_and_wait(chan, "pbx-parkingfailed", "");
05042       }
05043       res = -1;
05044    }
05045    if (res) {
05046       /* Park failed, try to continue in the dialplan. */
05047       ast_copy_string(chan->exten, orig_exten, sizeof(chan->exten));
05048       chan->priority = orig_priority;
05049       res = 0;
05050    } else {
05051       /* Park succeeded. */
05052       res = -1;
05053    }
05054 
05055    return res;
05056 }

static int park_call_full ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_park_call_args *  args 
) [static]

< Channel name that is parking the call.

Definition at line 1435 of file features.c.

References adsi_announce_park(), adsipark, ast_channel::appl, ast_add_extension(), ast_adsi_available(), ast_adsi_unload_session(), ast_bridged_channel(), AST_CEL_PARK_START, ast_cel_report_event(), ast_channel_get_by_name(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_channel_unref, ast_clear_flag, AST_CONTROL_HOLD, AST_CONTROL_RINGING, ast_copy_string(), ast_debug, AST_DEVICE_INUSE, AST_FLAG_MASQ_NOSTREAM, ast_free_ptr(), ast_indicate(), ast_indicate_data(), AST_LIST_UNLOCK, ast_log(), ast_manager_event, AST_MAX_CONTEXT, AST_MAX_EXTENSION, AST_PARK_OPT_RINGING, AST_PARK_OPT_SILENCE, ast_say_digits(), ast_set_flag, ast_strdup, ast_strlen_zero(), ast_test_flag, ast_tvnow(), ast_verb, ast_channel::caller, ast_parkinglot::cfg, parkeduser::chan, ast_channel::connected, ast_channel::context, parkeduser::context, ast_channel::data, EVENT_FLAG_CALL, ast_channel::exten, parkeduser::exten, ast_park_call_args::extout, parkeduser::hold_method, ast_party_connected_line::id, ast_party_caller::id, LOG_ERROR, ast_channel::macrocontext, ast_channel::macroexten, ast_channel::macropriority, parkinglot_cfg::mohclass, ast_party_id::name, ast_parkinglot::name, notify_metermaids(), parkeduser::notquiteyet, ast_party_id::number, parkeduser::options_specified, ast_park_call_args::orig_chan_name, park_space_reserve(), parkinglot_cfg::parking_con, parking_thread, parkeduser::parkingexten, parkeduser::parkinglot, parkeduser::parkingnum, ast_parkinglot::parkings, parkinglot_cfg::parkingtime, parkeduser::parkingtime, pbx_builtin_getvar_helper(), parkeduser::peername, ast_channel::priority, parkeduser::priority, ast_park_call_args::pu, registrar, ast_park_call_args::return_con, ast_park_call_args::return_ext, ast_park_call_args::return_pri, S_COR, S_OR, parkeduser::start, ast_party_name::str, ast_party_number::str, ast_channel::tech, ast_park_call_args::timeout, ast_channel_tech::type, ast_party_name::valid, and ast_party_number::valid.

Referenced by ast_park_call(), ast_park_call_exten(), and masq_park_call().

01436 {
01437    struct parkeduser *pu = args->pu;
01438    const char *event_from;    /*!< Channel name that is parking the call. */
01439    char app_data[AST_MAX_EXTENSION + AST_MAX_CONTEXT];
01440 
01441    if (pu == NULL) {
01442       args->pu = pu = park_space_reserve(chan, peer, args);
01443       if (pu == NULL) {
01444          return -1;
01445       }
01446    }
01447 
01448    chan->appl = "Parked Call";
01449    chan->data = NULL;
01450 
01451    pu->chan = chan;
01452 
01453    /* Put the parked channel on hold if we have two different channels */
01454    if (chan != peer) {
01455       if (ast_test_flag(args, AST_PARK_OPT_RINGING)) {
01456          pu->hold_method = AST_CONTROL_RINGING;
01457          ast_indicate(chan, AST_CONTROL_RINGING);
01458       } else {
01459          pu->hold_method = AST_CONTROL_HOLD;
01460          ast_indicate_data(chan, AST_CONTROL_HOLD,
01461             S_OR(pu->parkinglot->cfg.mohclass, NULL),
01462             !ast_strlen_zero(pu->parkinglot->cfg.mohclass) ? strlen(pu->parkinglot->cfg.mohclass) + 1 : 0);
01463       }
01464    }
01465    
01466    pu->start = ast_tvnow();
01467    pu->parkingtime = (args->timeout > 0) ? args->timeout : pu->parkinglot->cfg.parkingtime;
01468    if (args->extout)
01469       *(args->extout) = pu->parkingnum;
01470 
01471    if (peer) {
01472       event_from = S_OR(args->orig_chan_name, peer->name);
01473 
01474       /*
01475        * This is so ugly that it hurts, but implementing
01476        * get_base_channel() on local channels could have ugly side
01477        * effects.  We could have
01478        * transferer<->local,1<->local,2<->parking and we need the
01479        * callback name to be that of transferer.  Since local,1/2 have
01480        * the same name we can be tricky and just grab the bridged
01481        * channel from the other side of the local.
01482        */
01483       if (!strcasecmp(peer->tech->type, "Local")) {
01484          struct ast_channel *tmpchan, *base_peer;
01485          char other_side[AST_CHANNEL_NAME];
01486          char *c;
01487 
01488          ast_copy_string(other_side, event_from, sizeof(other_side));
01489          if ((c = strrchr(other_side, ';'))) {
01490             *++c = '1';
01491          }
01492          if ((tmpchan = ast_channel_get_by_name(other_side))) {
01493             ast_channel_lock(tmpchan);
01494             if ((base_peer = ast_bridged_channel(tmpchan))) {
01495                ast_copy_string(pu->peername, base_peer->name, sizeof(pu->peername));
01496             }
01497             ast_channel_unlock(tmpchan);
01498             tmpchan = ast_channel_unref(tmpchan);
01499          }
01500       } else {
01501          ast_copy_string(pu->peername, event_from, sizeof(pu->peername));
01502       }
01503    } else {
01504       event_from = S_OR(pbx_builtin_getvar_helper(chan, "BLINDTRANSFER"), chan->name);
01505    }
01506 
01507    /*
01508     * Remember what had been dialed, so that if the parking
01509     * expires, we try to come back to the same place
01510     */
01511    pu->options_specified = (!ast_strlen_zero(args->return_con) || !ast_strlen_zero(args->return_ext) || args->return_pri);
01512 
01513    /*
01514     * If extension has options specified, they override all other
01515     * possibilities such as the returntoorigin flag and transferred
01516     * context.  Information on extension options is lost here, so
01517     * we set a flag
01518     */
01519    ast_copy_string(pu->context, 
01520       S_OR(args->return_con, S_OR(chan->macrocontext, chan->context)), 
01521       sizeof(pu->context));
01522    ast_copy_string(pu->exten, 
01523       S_OR(args->return_ext, S_OR(chan->macroexten, chan->exten)), 
01524       sizeof(pu->exten));
01525    pu->priority = args->return_pri ? args->return_pri : 
01526       (chan->macropriority ? chan->macropriority : chan->priority);
01527 
01528    /*
01529     * If parking a channel directly, don't quite yet get parking
01530     * running on it.  All parking lot entries are put into the
01531     * parking lot with notquiteyet on.
01532     */
01533    if (peer != chan) {
01534       pu->notquiteyet = 0;
01535    }
01536 
01537    /* Wake up the (presumably select()ing) thread */
01538    pthread_kill(parking_thread, SIGURG);
01539    ast_verb(2, "Parked %s on %d (lot %s). Will timeout back to extension [%s] %s, %d in %d seconds\n",
01540       chan->name, pu->parkingnum, pu->parkinglot->name,
01541       pu->context, pu->exten, pu->priority, (pu->parkingtime / 1000));
01542 
01543    ast_cel_report_event(chan, AST_CEL_PARK_START, NULL, pu->parkinglot->name, peer);
01544 
01545    ast_manager_event(chan, EVENT_FLAG_CALL, "ParkedCall",
01546       "Exten: %s\r\n"
01547       "Channel: %s\r\n"
01548       "Parkinglot: %s\r\n"
01549       "From: %s\r\n"
01550       "Timeout: %ld\r\n"
01551       "CallerIDNum: %s\r\n"
01552       "CallerIDName: %s\r\n"
01553       "ConnectedLineNum: %s\r\n"
01554       "ConnectedLineName: %s\r\n"
01555       "Uniqueid: %s\r\n",
01556       pu->parkingexten, chan->name, pu->parkinglot->name, event_from,
01557       (long)pu->start.tv_sec + (long)(pu->parkingtime/1000) - (long)time(NULL),
01558       S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, "<unknown>"),
01559       S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, "<unknown>"),
01560       S_COR(chan->connected.id.number.valid, chan->connected.id.number.str, "<unknown>"),
01561       S_COR(chan->connected.id.name.valid, chan->connected.id.name.str, "<unknown>"),
01562       chan->uniqueid
01563       );
01564    ast_debug(4, "peer->name: %s\n", peer ? peer->name : "-No peer-");
01565    ast_debug(4, "args->orig_chan_name: %s\n", args->orig_chan_name ? args->orig_chan_name : "-none-");
01566    ast_debug(4, "pu->peername: %s\n", pu->peername);
01567    ast_debug(4, "AMI ParkedCall Channel: %s\n", chan->name);
01568    ast_debug(4, "AMI ParkedCall From: %s\n", event_from);
01569 
01570    if (peer && adsipark && ast_adsi_available(peer)) {
01571       adsi_announce_park(peer, pu->parkingexten);  /* Only supports parking numbers */
01572       ast_adsi_unload_session(peer);
01573    }
01574 
01575    snprintf(app_data, sizeof(app_data), "%s,%s", pu->parkingexten,
01576       pu->parkinglot->name);
01577    if (ast_add_extension(pu->parkinglot->cfg.parking_con, 1, pu->parkingexten, 1,
01578       NULL, NULL, parkedcall, ast_strdup(app_data), ast_free_ptr, registrar)) {
01579       ast_log(LOG_ERROR, "Could not create parked call exten: %s@%s\n",
01580          pu->parkingexten, pu->parkinglot->cfg.parking_con);
01581    } else {
01582       notify_metermaids(pu->parkingexten, pu->parkinglot->cfg.parking_con, AST_DEVICE_INUSE);
01583    }
01584 
01585    AST_LIST_UNLOCK(&pu->parkinglot->parkings);
01586 
01587    /* Only say number if it's a number and the channel hasn't been masqueraded away */
01588    if (peer && !ast_test_flag(args, AST_PARK_OPT_SILENCE)
01589       && (ast_strlen_zero(args->orig_chan_name) || !strcasecmp(peer->name, args->orig_chan_name))) {
01590       /*
01591        * If a channel is masqueraded into peer while playing back the
01592        * parking space number do not continue playing it back.  This
01593        * is the case if an attended transfer occurs.
01594        */
01595       ast_set_flag(peer, AST_FLAG_MASQ_NOSTREAM);
01596       /* Tell the peer channel the number of the parking space */
01597       ast_say_digits(peer, pu->parkingnum, "", peer->language);
01598       ast_clear_flag(peer, AST_FLAG_MASQ_NOSTREAM);
01599    }
01600    if (peer == chan) { /* pu->notquiteyet = 1 */
01601       /* Wake up parking thread if we're really done */
01602       pu->hold_method = AST_CONTROL_HOLD;
01603       ast_indicate_data(chan, AST_CONTROL_HOLD,
01604          S_OR(pu->parkinglot->cfg.mohclass, NULL),
01605          !ast_strlen_zero(pu->parkinglot->cfg.mohclass) ? strlen(pu->parkinglot->cfg.mohclass) + 1 : 0);
01606       pu->notquiteyet = 0;
01607       pthread_kill(parking_thread, SIGURG);
01608    }
01609    return 0;
01610 }

static void park_space_abort ( struct parkeduser *  pu  )  [static]

Definition at line 1237 of file features.c.

References ast_free, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_parkinglot::next_parking_space, parkeduser::parkinglot, parkinglot_unref(), and ast_parkinglot::parkings.

Referenced by masq_park_call().

01238 {
01239    struct ast_parkinglot *parkinglot;
01240 
01241    parkinglot = pu->parkinglot;
01242 
01243    /* Put back the parking space just allocated. */
01244    --parkinglot->next_parking_space;
01245 
01246    AST_LIST_REMOVE(&parkinglot->parkings, pu, list);
01247 
01248    AST_LIST_UNLOCK(&parkinglot->parkings);
01249    parkinglot_unref(parkinglot);
01250    ast_free(pu);
01251 }

static struct parkeduser* park_space_reserve ( struct ast_channel *  park_me,
struct ast_channel *  parker,
struct ast_park_call_args *  args 
) [static, read]

Note:
The API forces us to specify a numeric parking slot, even though the architecture would tend to support non-numeric extensions (as are possible with SIP, for example). Hence, we enforce that limitation here. If extout was not numeric, we could permit arbitrary non-numeric extensions.

Definition at line 1264 of file features.c.

References ast_calloc, ast_debug, ast_free, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), AST_PARK_OPT_RANDOMIZE, ast_random(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_parkinglot::cfg, create_dynamic_parkinglot(), default_parkinglot, ast_parkinglot::disabled, find_parkinglot(), findparkinglotname(), parkinglot_cfg::is_invalid, LOG_WARNING, ast_parkinglot::name, ast_parkinglot::next_parking_space, parkeduser::notquiteyet, parkeddynamic, parkinglot_cfg::parkfindnext, parkinglot_cfg::parking_start, parkinglot_cfg::parking_stop, parkeduser::parkingexten, parkeduser::parkinglot, ast_park_call_args::parkinglot, parkinglot_addref(), parkinglot_unref(), parkeduser::parkingnum, ast_parkinglot::parkings, pbx_builtin_getvar_helper(), and S_OR.

Referenced by masq_park_call(), and park_call_full().

01265 {
01266    struct parkeduser *pu;
01267    int i;
01268    int parking_space = -1;
01269    const char *parkinglotname;
01270    const char *parkingexten;
01271    struct parkeduser *cur;
01272    struct ast_parkinglot *parkinglot = NULL;
01273 
01274    if (args->parkinglot) {
01275       parkinglot = parkinglot_addref(args->parkinglot);
01276       parkinglotname = parkinglot->name;
01277    } else {
01278       if (parker) {
01279          parkinglotname = findparkinglotname(parker);
01280       } else { /* parker was NULL, check park_me (ParkAndAnnounce / res_agi) */
01281          parkinglotname = findparkinglotname(park_me);
01282       }
01283       if (!ast_strlen_zero(parkinglotname)) {
01284          parkinglot = find_parkinglot(parkinglotname);
01285       } else {
01286          /* Parking lot is not specified, so use the default parking lot. */
01287          ast_debug(4, "This could be an indication channel driver needs updating, using default lot.\n");
01288          parkinglot = parkinglot_addref(default_parkinglot);
01289       }
01290    }
01291 
01292    /* Dynamically create parkinglot */
01293    if (!parkinglot && parkeddynamic && !ast_strlen_zero(parkinglotname)) {
01294       parkinglot = create_dynamic_parkinglot(parkinglotname, park_me);
01295    }
01296 
01297    if (!parkinglot) {
01298       ast_log(LOG_WARNING, "Parking lot not available to park %s.\n", park_me->name);
01299       return NULL;
01300    }
01301 
01302    ast_debug(1, "Parking lot: %s\n", parkinglot->name);
01303    if (parkinglot->disabled || parkinglot->cfg.is_invalid) {
01304       ast_log(LOG_WARNING, "Parking lot %s is not in a useable state.\n",
01305          parkinglot->name);
01306       parkinglot_unref(parkinglot);
01307       return NULL;
01308    }
01309 
01310    /* Allocate memory for parking data */
01311    if (!(pu = ast_calloc(1, sizeof(*pu)))) {
01312       parkinglot_unref(parkinglot);
01313       return NULL;
01314    }
01315 
01316    /* Lock parking list */
01317    AST_LIST_LOCK(&parkinglot->parkings);
01318 
01319    /* Check for channel variable PARKINGEXTEN */
01320    parkingexten = ast_strdupa(S_OR(pbx_builtin_getvar_helper(park_me, "PARKINGEXTEN"), ""));
01321    if (!ast_strlen_zero(parkingexten)) {
01322       /*!
01323        * \note The API forces us to specify a numeric parking slot, even
01324        * though the architecture would tend to support non-numeric extensions
01325        * (as are possible with SIP, for example).  Hence, we enforce that
01326        * limitation here.  If extout was not numeric, we could permit
01327        * arbitrary non-numeric extensions.
01328        */
01329       if (sscanf(parkingexten, "%30d", &parking_space) != 1 || parking_space <= 0) {
01330          ast_log(LOG_WARNING, "PARKINGEXTEN='%s' is not a valid parking space.\n",
01331             parkingexten);
01332          AST_LIST_UNLOCK(&parkinglot->parkings);
01333          parkinglot_unref(parkinglot);
01334          ast_free(pu);
01335          return NULL;
01336       }
01337 
01338       if (parking_space < parkinglot->cfg.parking_start
01339          || parkinglot->cfg.parking_stop < parking_space) {
01340          /*
01341           * Cannot allow park because parking lots are not setup for
01342           * spaces outside of the lot.  (Things like dialplan hints don't
01343           * exist for outside lot space.)
01344           */
01345          ast_log(LOG_WARNING, "PARKINGEXTEN=%d is not in %s (%d-%d).\n",
01346             parking_space, parkinglot->name, parkinglot->cfg.parking_start,
01347             parkinglot->cfg.parking_stop);
01348          AST_LIST_UNLOCK(&parkinglot->parkings);
01349          parkinglot_unref(parkinglot);
01350          ast_free(pu);
01351          return NULL;
01352       }
01353 
01354       /* Check if requested parking space is in use. */
01355       AST_LIST_TRAVERSE(&parkinglot->parkings, cur, list) {
01356          if (cur->parkingnum == parking_space) {
01357             ast_log(LOG_WARNING, "PARKINGEXTEN=%d is already in use in %s\n",
01358                parking_space, parkinglot->name);
01359             AST_LIST_UNLOCK(&parkinglot->parkings);
01360             parkinglot_unref(parkinglot);
01361             ast_free(pu);
01362             return NULL;
01363          }
01364       }
01365    } else {
01366       /* PARKINGEXTEN is empty, so find a usable extension in the lot to park the call */
01367       int start; /* The first slot we look in the parkinglot. It can be randomized. */
01368       int start_checked = 0; /* flag raised once the first slot is checked */
01369 
01370       /* If using randomize mode, set start to random position on parking range */
01371       if (ast_test_flag(args, AST_PARK_OPT_RANDOMIZE)) {
01372          start = ast_random() % (parkinglot->cfg.parking_stop - parkinglot->cfg.parking_start + 1);
01373          start += parkinglot->cfg.parking_start;
01374       } else if (parkinglot->cfg.parkfindnext
01375          && parkinglot->cfg.parking_start <= parkinglot->next_parking_space
01376          && parkinglot->next_parking_space <= parkinglot->cfg.parking_stop) {
01377          /* Start looking with the next parking space in the lot. */
01378          start = parkinglot->next_parking_space;
01379       } else {
01380          /* Otherwise, just set it to the start position. */
01381          start = parkinglot->cfg.parking_start;
01382       }
01383 
01384       /* free parking extension linear search: O(n^2) */
01385       for (i = start; ; i++) {
01386          /* If we are past the end, wrap around to the first parking slot*/
01387          if (i == parkinglot->cfg.parking_stop + 1) {
01388             i = parkinglot->cfg.parking_start;
01389          }
01390 
01391          if (i == start) {
01392             /* At this point, if start_checked, we've exhausted all the possible slots. */
01393             if (start_checked) {
01394                break;
01395             } else {
01396                start_checked = 1;
01397             }
01398          }
01399 
01400          /* Search the list of parked calls already in use for i. If we find it, it's in use. */
01401          AST_LIST_TRAVERSE(&parkinglot->parkings, cur, list) {
01402             if (cur->parkingnum == i) {
01403                break;
01404             }
01405          }
01406          if (!cur) {
01407             /* We found a parking space. */
01408             parking_space = i;
01409             break;
01410          }
01411       }
01412       if (parking_space == -1) {
01413          /* We did not find a parking space.  Lot is full. */
01414          ast_log(LOG_WARNING, "No more parking spaces in %s\n", parkinglot->name);
01415          AST_LIST_UNLOCK(&parkinglot->parkings);
01416          parkinglot_unref(parkinglot);
01417          ast_free(pu);
01418          return NULL;
01419       }
01420    }
01421 
01422    /* Prepare for next parking space search. */
01423    parkinglot->next_parking_space = parking_space + 1;
01424 
01425    snprintf(pu->parkingexten, sizeof(pu->parkingexten), "%d", parking_space);
01426    pu->notquiteyet = 1;
01427    pu->parkingnum = parking_space;
01428    pu->parkinglot = parkinglot;
01429    AST_LIST_INSERT_TAIL(&parkinglot->parkings, pu, list);
01430 
01431    return pu;
01432 }

static int parked_call_exec ( struct ast_channel *  chan,
const char *  data 
) [static]

Pickup parked call.

< Parking lot space to retrieve if present.

< Parking lot name to use if present.

< Place to put any remaining args string.

Definition at line 5059 of file features.c.

References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_bridge_call(), ast_cdr_setdestchan(), AST_CEL_PARK_END, ast_cel_report_event(), ast_channel_connected_line_macro(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_make_compatible(), ast_channel_unlock, ast_channel_update_connected_line(), ast_connected_line_copy_from_caller(), AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER, ast_context_find(), ast_context_remove_extension2(), AST_CONTROL_HOLD, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_copy_flags, AST_DECLARE_APP_ARGS, AST_DEVICE_NOT_INUSE, AST_FEATURE_AUTOMON, AST_FEATURE_DISCONNECT, AST_FEATURE_FLAG_BYBOTH, AST_FEATURE_FLAG_BYCALLEE, AST_FEATURE_FLAG_BYCALLER, AST_FEATURE_PARKCALL, AST_FEATURE_REDIRECT, AST_FLAGS_ALL, ast_free, ast_hangup(), ast_indicate(), AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_manager_event, ast_party_connected_line_free(), ast_party_connected_line_init(), ast_set_flag, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_stream_and_wait(), ast_strlen_zero(), ast_verb, ast_channel::caller, ast_channel::cdr, ast_parkinglot::cfg, parkeduser::chan, ast_channel::connected, courtesytone, ast_datastore::data, default_parkinglot, dial_features_info, EVENT_FLAG_CALL, ast_bridge_config::features_callee, ast_bridge_config::features_caller, find_parkinglot(), findparkinglotname(), parkeduser::hold_method, ast_party_connected_line::id, ast_party_caller::id, LOG_WARNING, ast_dial_features::my_features, ast_party_id::name, ast_parkinglot::name, notify_metermaids(), parkeduser::notquiteyet, ast_party_id::number, parkinglot_cfg::parkedcallhangup, parkinglot_cfg::parkedcallrecording, parkinglot_cfg::parkedcallreparking, parkinglot_cfg::parkedcalltransfers, parkedplay, parkinglot_cfg::parking_con, parkeduser::parkingexten, parkeduser::parkinglot, parkinglot_addref(), parkinglot_unref(), parkeduser::parkingnum, ast_parkinglot::parkings, parse(), ast_channel::pbx, pbx_builtin_setvar_helper(), play_message_to_chans(), S_COR, ast_party_connected_line::source, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by ast_features_init().

05060 {
05061    int res;
05062    struct ast_channel *peer = NULL;
05063    struct parkeduser *pu;
05064    struct ast_context *con;
05065    char *parse;
05066    const char *pl_name;
05067    int park = 0;
05068    struct ast_bridge_config config;
05069    struct ast_parkinglot *parkinglot;
05070    AST_DECLARE_APP_ARGS(app_args,
05071       AST_APP_ARG(pl_space);  /*!< Parking lot space to retrieve if present. */
05072       AST_APP_ARG(pl_name);   /*!< Parking lot name to use if present. */
05073       AST_APP_ARG(dummy);     /*!< Place to put any remaining args string. */
05074    );
05075 
05076    parse = ast_strdupa(data);
05077    AST_STANDARD_APP_ARGS(app_args, parse);
05078 
05079    if (!ast_strlen_zero(app_args.pl_space)) {
05080       if (sscanf(app_args.pl_space, "%30u", &park) != 1) {
05081          ast_log(LOG_WARNING, "Specified parking extension not a number: %s\n",
05082             app_args.pl_space);
05083          park = -1;
05084       }
05085    }
05086 
05087    if (!ast_strlen_zero(app_args.pl_name)) {
05088       pl_name = app_args.pl_name;
05089    } else {
05090       pl_name = findparkinglotname(chan);
05091    }
05092    if (ast_strlen_zero(pl_name)) {
05093       /* Parking lot is not specified, so use the default parking lot. */
05094       parkinglot = parkinglot_addref(default_parkinglot);
05095    } else {
05096       parkinglot = find_parkinglot(pl_name);
05097       if (!parkinglot) {
05098          /* It helps to answer the channel if not already up. :) */
05099          if (chan->_state != AST_STATE_UP) {
05100             ast_answer(chan);
05101          }
05102          if (ast_stream_and_wait(chan, "pbx-invalidpark", "")) {
05103             ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n",
05104                "pbx-invalidpark", chan->name);
05105          }
05106          ast_log(LOG_WARNING,
05107             "Channel %s tried to retrieve parked call from unknown parking lot '%s'\n",
05108             chan->name, pl_name);
05109          return -1;
05110       }
05111    }
05112 
05113    AST_LIST_LOCK(&parkinglot->parkings);
05114    AST_LIST_TRAVERSE_SAFE_BEGIN(&parkinglot->parkings, pu, list) {
05115       if ((ast_strlen_zero(app_args.pl_space) || pu->parkingnum == park)
05116          && !pu->notquiteyet && !pu->chan->pbx) {
05117          /* The parking space has a call and can be picked up now. */
05118          AST_LIST_REMOVE_CURRENT(list);
05119          break;
05120       }
05121    }
05122    AST_LIST_TRAVERSE_SAFE_END;
05123    if (pu) {
05124       /* Found a parked call to pickup. */
05125       peer = pu->chan;
05126       con = ast_context_find(parkinglot->cfg.parking_con);
05127       if (con) {
05128          if (ast_context_remove_extension2(con, pu->parkingexten, 1, NULL, 0)) {
05129             ast_log(LOG_WARNING, "Whoa, failed to remove the extension!\n");
05130          } else {
05131             notify_metermaids(pu->parkingexten, parkinglot->cfg.parking_con, AST_DEVICE_NOT_INUSE);
05132          }
05133       } else {
05134          ast_log(LOG_WARNING, "Whoa, no parking context?\n");
05135       }
05136 
05137       ast_cel_report_event(pu->chan, AST_CEL_PARK_END, NULL, "UnParkedCall", chan);
05138       ast_manager_event(pu->chan, EVENT_FLAG_CALL, "UnParkedCall",
05139          "Exten: %s\r\n"
05140          "Channel: %s\r\n"
05141          "Parkinglot: %s\r\n"
05142          "From: %s\r\n"
05143          "CallerIDNum: %s\r\n"
05144          "CallerIDName: %s\r\n"
05145          "ConnectedLineNum: %s\r\n"
05146          "ConnectedLineName: %s\r\n"
05147          "Uniqueid: %s\r\n",
05148          pu->parkingexten, pu->chan->name, pu->parkinglot->name, chan->name,
05149          S_COR(pu->chan->caller.id.number.valid, pu->chan->caller.id.number.str, "<unknown>"),
05150          S_COR(pu->chan->caller.id.name.valid, pu->chan->caller.id.name.str, "<unknown>"),
05151          S_COR(pu->chan->connected.id.number.valid, pu->chan->connected.id.number.str, "<unknown>"),
05152          S_COR(pu->chan->connected.id.name.valid, pu->chan->connected.id.name.str, "<unknown>"),
05153          pu->chan->uniqueid
05154          );
05155 
05156       /* Stop entertaining the caller. */
05157       switch (pu->hold_method) {
05158       case AST_CONTROL_HOLD:
05159          ast_indicate(pu->chan, AST_CONTROL_UNHOLD);
05160          break;
05161       case AST_CONTROL_RINGING:
05162          ast_indicate(pu->chan, -1);
05163          break;
05164       default:
05165          break;
05166       }
05167       pu->hold_method = 0;
05168 
05169       parkinglot_unref(pu->parkinglot);
05170       ast_free(pu);
05171    }
05172    AST_LIST_UNLOCK(&parkinglot->parkings);
05173 
05174    if (peer) {
05175       /* Update connected line between retrieving call and parked call. */
05176       struct ast_party_connected_line connected;
05177 
05178       ast_party_connected_line_init(&connected);
05179 
05180       /* Send our caller-id to peer. */
05181       ast_channel_lock(chan);
05182       ast_connected_line_copy_from_caller(&connected, &chan->caller);
05183       ast_channel_unlock(chan);
05184       connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
05185       if (ast_channel_connected_line_macro(chan, peer, &connected, 0, 0)) {
05186          ast_channel_update_connected_line(peer, &connected, NULL);
05187       }
05188 
05189       /*
05190        * Get caller-id from peer.
05191        *
05192        * Update the retrieving call before it is answered if possible
05193        * for best results.  Some phones do not support updating the
05194        * connected line information after connection.
05195        */
05196       ast_channel_lock(peer);
05197       ast_connected_line_copy_from_caller(&connected, &peer->caller);
05198       ast_channel_unlock(peer);
05199       connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
05200       if (ast_channel_connected_line_macro(peer, chan, &connected, 1, 0)) {
05201          ast_channel_update_connected_line(chan, &connected, NULL);
05202       }
05203 
05204       ast_party_connected_line_free(&connected);
05205    }
05206 
05207    /* JK02: it helps to answer the channel if not already up */
05208    if (chan->_state != AST_STATE_UP) {
05209       ast_answer(chan);
05210    }
05211 
05212    if (peer) {
05213       struct ast_datastore *features_datastore;
05214       struct ast_dial_features *dialfeatures;
05215 
05216       /* Play a courtesy to the source(s) configured to prefix the bridge connecting */
05217       if (!ast_strlen_zero(courtesytone)) {
05218          static const char msg[] = "courtesy tone";
05219 
05220          switch (parkedplay) {
05221          case 0:/* Courtesy tone to pickup chan */
05222             res = play_message_to_chans(chan, peer, -1, msg, courtesytone);
05223             break;
05224          case 1:/* Courtesy tone to parked chan */
05225             res = play_message_to_chans(chan, peer, 1, msg, courtesytone);
05226             break;
05227          case 2:/* Courtesy tone to both chans */
05228             res = play_message_to_chans(chan, peer, 0, msg, courtesytone);
05229             break;
05230          default:
05231             res = 0;
05232             break;
05233          }
05234          if (res) {
05235             ast_hangup(peer);
05236             parkinglot_unref(parkinglot);
05237             return -1;
05238          }
05239       }
05240 
05241       res = ast_channel_make_compatible(chan, peer);
05242       if (res < 0) {
05243          ast_log(LOG_WARNING, "Could not make channels %s and %s compatible for bridge\n", chan->name, peer->name);
05244          ast_hangup(peer);
05245          parkinglot_unref(parkinglot);
05246          return -1;
05247       }
05248       /* This runs sorta backwards, since we give the incoming channel control, as if it
05249          were the person called. */
05250       ast_verb(3, "Channel %s connected to parked call %d\n", chan->name, park);
05251 
05252       pbx_builtin_setvar_helper(chan, "PARKEDCHANNEL", peer->name);
05253       ast_cdr_setdestchan(chan->cdr, peer->name);
05254       memset(&config, 0, sizeof(struct ast_bridge_config));
05255 
05256       /* Get datastore for peer and apply it's features to the callee side of the bridge config */
05257       ast_channel_lock(peer);
05258       features_datastore = ast_channel_datastore_find(peer, &dial_features_info, NULL);
05259       if (features_datastore && (dialfeatures = features_datastore->data)) {
05260          ast_copy_flags(&config.features_callee, &dialfeatures->my_features,
05261             AST_FLAGS_ALL);
05262       }
05263       ast_channel_unlock(peer);
05264 
05265       if ((parkinglot->cfg.parkedcalltransfers == AST_FEATURE_FLAG_BYCALLEE) || (parkinglot->cfg.parkedcalltransfers == AST_FEATURE_FLAG_BYBOTH)) {
05266          ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
05267       }
05268       if ((parkinglot->cfg.parkedcalltransfers == AST_FEATURE_FLAG_BYCALLER) || (parkinglot->cfg.parkedcalltransfers == AST_FEATURE_FLAG_BYBOTH)) {
05269          ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
05270       }
05271       if ((parkinglot->cfg.parkedcallreparking == AST_FEATURE_FLAG_BYCALLEE) || (parkinglot->cfg.parkedcallreparking == AST_FEATURE_FLAG_BYBOTH)) {
05272          ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
05273       }
05274       if ((parkinglot->cfg.parkedcallreparking == AST_FEATURE_FLAG_BYCALLER) || (parkinglot->cfg.parkedcallreparking == AST_FEATURE_FLAG_BYBOTH)) {
05275          ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
05276       }
05277       if ((parkinglot->cfg.parkedcallhangup == AST_FEATURE_FLAG_BYCALLEE) || (parkinglot->cfg.parkedcallhangup == AST_FEATURE_FLAG_BYBOTH)) {
05278          ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
05279       }
05280       if ((parkinglot->cfg.parkedcallhangup == AST_FEATURE_FLAG_BYCALLER) || (parkinglot->cfg.parkedcallhangup == AST_FEATURE_FLAG_BYBOTH)) {
05281          ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
05282       }
05283       if ((parkinglot->cfg.parkedcallrecording == AST_FEATURE_FLAG_BYCALLEE) || (parkinglot->cfg.parkedcallrecording == AST_FEATURE_FLAG_BYBOTH)) {
05284          ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
05285       }
05286       if ((parkinglot->cfg.parkedcallrecording == AST_FEATURE_FLAG_BYCALLER) || (parkinglot->cfg.parkedcallrecording == AST_FEATURE_FLAG_BYBOTH)) {
05287          ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
05288       }
05289 
05290       res = ast_bridge_call(chan, peer, &config);
05291 
05292       pbx_builtin_setvar_helper(chan, "PARKEDCHANNEL", peer->name);
05293       ast_cdr_setdestchan(chan->cdr, peer->name);
05294 
05295       /* Simulate the PBX hanging up */
05296       ast_hangup(peer);
05297    } else {
05298       if (ast_stream_and_wait(chan, "pbx-invalidpark", "")) {
05299          ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", "pbx-invalidpark",
05300             chan->name);
05301       }
05302       ast_verb(3, "Channel %s tried to retrieve nonexistent parked call %d\n",
05303          chan->name, park);
05304       res = -1;
05305    }
05306 
05307    parkinglot_unref(parkinglot);
05308    return res;
05309 }

static int parkinglot_activate ( struct ast_parkinglot *  parkinglot  )  [static]

Definition at line 5520 of file features.c.

References ast_add_extension(), ast_context_find_or_create(), AST_DEVICE_INUSE, ast_free_ptr(), ast_log(), AST_MAX_CONTEXT, ast_strdup, ast_parkinglot::cfg, ast_parkinglot::disabled, LOG_ERROR, ast_parkinglot::name, notify_metermaids(), park_add_hints(), parkinglot_cfg::parkaddhints, parkcall, parkinglot_cfg::parkext, parkinglot_cfg::parkext_exclusive, parkinglot_cfg::parking_con, parkinglot_cfg::parking_start, parkinglot_cfg::parking_stop, and registrar.

Referenced by create_dynamic_parkinglot(), and parkinglot_activate_cb().

05521 {
05522    int disabled = 0;
05523    char app_data[5 + AST_MAX_CONTEXT];
05524 
05525    /* Create Park option list.  Must match with struct park_app_args options. */
05526    if (parkinglot->cfg.parkext_exclusive) {
05527       /* Specify the parking lot this parking extension parks calls. */
05528       snprintf(app_data, sizeof(app_data), ",,,,,%s", parkinglot->name);
05529    } else {
05530       /* The dialplan must specify which parking lot to use. */
05531       app_data[0] = '\0';
05532    }
05533 
05534    /* Create context */
05535    if (!ast_context_find_or_create(NULL, NULL, parkinglot->cfg.parking_con, registrar)) {
05536       ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n",
05537          parkinglot->cfg.parking_con);
05538       disabled = 1;
05539 
05540    /* Add a parking extension into the context */
05541    } else if (ast_add_extension(parkinglot->cfg.parking_con, 1, parkinglot->cfg.parkext,
05542       1, NULL, NULL, parkcall, ast_strdup(app_data), ast_free_ptr, registrar)) {
05543       ast_log(LOG_ERROR, "Could not create parking lot %s access exten %s@%s\n",
05544          parkinglot->name, parkinglot->cfg.parkext, parkinglot->cfg.parking_con);
05545       disabled = 1;
05546    } else {
05547       /* Add parking hints */
05548       if (parkinglot->cfg.parkaddhints) {
05549          park_add_hints(parkinglot->cfg.parking_con, parkinglot->cfg.parking_start,
05550             parkinglot->cfg.parking_stop);
05551       }
05552 
05553       /*
05554        * XXX Not sure why we should need to notify the metermaids for
05555        * this exten.  It was originally done for the default parking
05556        * lot entry exten only but should be done for all entry extens
05557        * if we do it for one.
05558        */
05559       /* Notify metermaids about parking lot entry exten state. */
05560       notify_metermaids(parkinglot->cfg.parkext, parkinglot->cfg.parking_con,
05561          AST_DEVICE_INUSE);
05562    }
05563 
05564    parkinglot->disabled = disabled;
05565    return disabled ? -1 : 0;
05566 }

static int parkinglot_activate_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 6569 of file features.c.

References ast_debug, ast_log(), ast_parkinglot::cfg, force_reload_load, LOG_WARNING, ast_parkinglot::name, parkinglot_cfg::parking_start, parkinglot_cfg::parking_stop, parkinglot_activate(), and ast_parkinglot::the_mark.

Referenced by load_config().

06570 {
06571    struct ast_parkinglot *parkinglot = obj;
06572 
06573    if (parkinglot->the_mark) {
06574       /*
06575        * Don't activate a parking lot that still bears the_mark since
06576        * it is effectively deleted.
06577        */
06578       return 0;
06579    }
06580 
06581    if (parkinglot_activate(parkinglot)) {
06582       /*
06583        * The parking lot failed to activate.  Allow reloading later to
06584        * see if that fixes it.
06585        */
06586       force_reload_load = 1;
06587       ast_log(LOG_WARNING, "Parking lot %s not open for business.\n", parkinglot->name);
06588    } else {
06589       ast_debug(1, "Parking lot %s now open for business. (parkpos %d-%d)\n",
06590          parkinglot->name, parkinglot->cfg.parking_start,
06591          parkinglot->cfg.parking_stop);
06592    }
06593 
06594    return 0;
06595 }

static struct ast_parkinglot * parkinglot_addref ( struct ast_parkinglot *  parkinglot  )  [static, read]

Definition at line 5321 of file features.c.

References ao2_ref, ast_debug, and ast_parkinglot::name.

Referenced by create_dynamic_parkinglot(), load_config(), park_call_exec(), park_space_reserve(), parked_call_exec(), and xfer_park_call_helper().

05322 {
05323    int refcount;
05324 
05325    refcount = ao2_ref(parkinglot, +1);
05326    ast_debug(3, "Multiparking: %s refcount now %d\n", parkinglot->name, refcount + 1);
05327    return parkinglot;
05328 }

static int parkinglot_cmp_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 865 of file features.c.

References CMP_MATCH, CMP_STOP, and ast_parkinglot::name.

Referenced by ast_features_init().

00866 {
00867    struct ast_parkinglot *parkinglot = obj;
00868    struct ast_parkinglot *parkinglot2 = arg;
00869 
00870    return !strcasecmp(parkinglot->name, parkinglot2->name) ? CMP_MATCH | CMP_STOP : 0;
00871 }

static int parkinglot_config_read ( const char *  pl_name,
struct parkinglot_cfg *  cfg,
struct ast_variable *  var 
) [static]

Definition at line 5432 of file features.c.

References ast_copy_string(), ast_log(), ast_strlen_zero(), ast_true(), ast_variable::file, parkinglot_cfg::is_invalid, ast_variable::lineno, LOG_WARNING, parkinglot_cfg::mohclass, ast_variable::name, ast_variable::next, parkinglot_cfg::parkaddhints, parkinglot_cfg::parkedcallhangup, parkinglot_cfg::parkedcallrecording, parkinglot_cfg::parkedcallreparking, parkinglot_cfg::parkedcalltransfers, parkinglot_cfg::parkext, parkinglot_cfg::parkext_exclusive, parkinglot_cfg::parkfindnext, parkinglot_cfg::parking_con, parkinglot_cfg::parking_start, parkinglot_cfg::parking_stop, parkinglot_feature_flag_cfg(), parkinglot_cfg::parkingtime, and ast_variable::value.

Referenced by build_parkinglot().

05433 {
05434    int error = 0;
05435 
05436    while (var) {
05437       if (!strcasecmp(var->name, "context")) {
05438          ast_copy_string(cfg->parking_con, var->value, sizeof(cfg->parking_con));
05439       } else if (!strcasecmp(var->name, "parkext")) {
05440          ast_copy_string(cfg->parkext, var->value, sizeof(cfg->parkext));
05441       } else if (!strcasecmp(var->name, "parkext_exclusive")) {
05442          cfg->parkext_exclusive = ast_true(var->value);
05443       } else if (!strcasecmp(var->name, "parkinghints")) {
05444          cfg->parkaddhints = ast_true(var->value);
05445       } else if (!strcasecmp(var->name, "parkedmusicclass")) {
05446          ast_copy_string(cfg->mohclass, var->value, sizeof(cfg->mohclass));
05447       } else if (!strcasecmp(var->name, "parkingtime")) {
05448          int parkingtime = 0;
05449 
05450          if ((sscanf(var->value, "%30d", &parkingtime) != 1) || parkingtime < 1) {
05451             ast_log(LOG_WARNING, "%s is not a valid parkingtime\n", var->value);
05452             error = -1;
05453          } else {
05454             cfg->parkingtime = parkingtime * 1000;
05455          }
05456       } else if (!strcasecmp(var->name, "parkpos")) {
05457          int start = 0;
05458          int end = 0;
05459 
05460          if (sscanf(var->value, "%30d-%30d", &start, &end) != 2) {
05461             ast_log(LOG_WARNING,
05462                "Format for parking positions is a-b, where a and b are numbers at line %d of %s\n",
05463                var->lineno, var->file);
05464             error = -1;
05465          } else if (end < start || start <= 0 || end <= 0) {
05466             ast_log(LOG_WARNING, "Parking range is invalid. Must be a <= b, at line %d of %s\n",
05467                var->lineno, var->file);
05468             error = -1;
05469          } else {
05470             cfg->parking_start = start;
05471             cfg->parking_stop = end;
05472          }
05473       } else if (!strcasecmp(var->name, "findslot")) {
05474          cfg->parkfindnext = (!strcasecmp(var->value, "next"));
05475       } else if (!strcasecmp(var->name, "parkedcalltransfers")) {
05476          parkinglot_feature_flag_cfg(pl_name, &cfg->parkedcalltransfers, var);
05477       } else if (!strcasecmp(var->name, "parkedcallreparking")) {
05478          parkinglot_feature_flag_cfg(pl_name, &cfg->parkedcallreparking, var);
05479       } else if (!strcasecmp(var->name, "parkedcallhangup")) {
05480          parkinglot_feature_flag_cfg(pl_name, &cfg->parkedcallhangup, var);
05481       } else if (!strcasecmp(var->name, "parkedcallrecording")) {
05482          parkinglot_feature_flag_cfg(pl_name, &cfg->parkedcallrecording, var);
05483       }
05484       var = var->next;
05485    }
05486 
05487    /* Check for configuration errors */
05488    if (ast_strlen_zero(cfg->parking_con)) {
05489       ast_log(LOG_WARNING, "Parking lot %s needs context\n", pl_name);
05490       error = -1;
05491    }
05492    if (ast_strlen_zero(cfg->parkext)) {
05493       ast_log(LOG_WARNING, "Parking lot %s needs parkext\n", pl_name);
05494       error = -1;
05495    }
05496    if (!cfg->parking_start) {
05497       ast_log(LOG_WARNING, "Parking lot %s needs parkpos\n", pl_name);
05498       error = -1;
05499    }
05500    if (error) {
05501       cfg->is_invalid = 1;
05502    }
05503 
05504    return error;
05505 }

static void parkinglot_destroy ( void *  obj  )  [static]

Destroy a parking lot.

Definition at line 5331 of file features.c.

References ast_assert, AST_LIST_EMPTY, AST_LIST_HEAD_DESTROY, and ast_parkinglot::parkings.

Referenced by create_parkinglot().

05332 {
05333    struct ast_parkinglot *doomed = obj;
05334 
05335    /*
05336     * No need to destroy parked calls here because any parked call
05337     * holds a parking lot reference.  Therefore the parkings list
05338     * must be empty.
05339     */
05340    ast_assert(AST_LIST_EMPTY(&doomed->parkings));
05341    AST_LIST_HEAD_DESTROY(&doomed->parkings);
05342 }

static void parkinglot_feature_flag_cfg ( const char *  pl_name,
int *  param,
struct ast_variable *  var 
) [static]

Definition at line 5409 of file features.c.

References ast_debug, AST_FEATURE_FLAG_BYBOTH, AST_FEATURE_FLAG_BYCALLEE, AST_FEATURE_FLAG_BYCALLER, ast_variable::name, and ast_variable::value.

Referenced by parkinglot_config_read().

05410 {
05411    ast_debug(1, "Setting parking lot %s %s to %s\n", pl_name, var->name, var->value);
05412    if (!strcasecmp(var->value, "both")) {
05413       *param = AST_FEATURE_FLAG_BYBOTH;
05414    } else if (!strcasecmp(var->value, "caller")) {
05415       *param = AST_FEATURE_FLAG_BYCALLER;
05416    } else if (!strcasecmp(var->value, "callee")) {
05417       *param = AST_FEATURE_FLAG_BYCALLEE;
05418    }
05419 }

static int parkinglot_hash_cb ( const void *  obj,
const int  flags 
) [static]

Definition at line 858 of file features.c.

References ast_str_case_hash(), and ast_parkinglot::name.

Referenced by ast_features_init().

00859 {
00860    const struct ast_parkinglot *parkinglot = obj;
00861 
00862    return ast_str_case_hash(parkinglot->name);
00863 }

static int parkinglot_is_marked_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 6549 of file features.c.

References AST_LIST_EMPTY, ast_log(), CMP_MATCH, ast_parkinglot::disabled, force_reload_load, LOG_WARNING, ast_parkinglot::name, ast_parkinglot::parkings, and ast_parkinglot::the_mark.

Referenced by load_config().

06550 {
06551    struct ast_parkinglot *parkinglot = obj;
06552 
06553    if (parkinglot->the_mark) {
06554       if (AST_LIST_EMPTY(&parkinglot->parkings)) {
06555          /* This parking lot can actually be deleted. */
06556          return CMP_MATCH;
06557       }
06558       /* Try reloading later when parking lot is empty. */
06559       ast_log(LOG_WARNING,
06560          "Parking lot %s has parked calls.  Could not remove.\n",
06561          parkinglot->name);
06562       parkinglot->disabled = 1;
06563       force_reload_load = 1;
06564    }
06565 
06566    return 0;
06567 }

static int parkinglot_markall_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 6541 of file features.c.

References ast_parkinglot::the_mark.

Referenced by load_config().

06542 {
06543    struct ast_parkinglot *parkinglot = obj;
06544 
06545    parkinglot->the_mark = 1;
06546    return 0;
06547 }

static void parkinglot_unref ( struct ast_parkinglot *  parkinglot  )  [static]

Unreference parkinglot object.

Definition at line 5314 of file features.c.

References ao2_ref, ast_debug, and ast_parkinglot::name.

Referenced by ast_masq_park_call_exten(), ast_park_call_exten(), build_parkinglot(), create_dynamic_parkinglot(), manage_parkinglot(), manager_park(), park_call_exec(), park_space_abort(), park_space_reserve(), parked_call_exec(), and xfer_park_call_helper().

05315 {
05316    ast_debug(3, "Multiparking: %s refcount now %d\n", parkinglot->name,
05317       ao2_ref(parkinglot, 0) - 1);
05318    ao2_ref(parkinglot, -1);
05319 }

static struct ast_cdr* pick_unlocked_cdr ( struct ast_cdr *  cdr  )  [static, read]

return the first unlocked cdr in a possible chain

Definition at line 3790 of file features.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, and ast_cdr::next.

Referenced by ast_bridge_call().

03791 {
03792    struct ast_cdr *cdr_orig = cdr;
03793    while (cdr) {
03794       if (!ast_test_flag(cdr,AST_CDR_FLAG_LOCKED))
03795          return cdr;
03796       cdr = cdr->next;
03797    }
03798    return cdr_orig; /* everybody LOCKED or some other weirdness, like a NULL */
03799 }

static int play_message_in_bridged_call ( struct ast_channel *  caller_chan,
struct ast_channel *  callee_chan,
const char *  audiofile 
) [static]

Play message to both caller and callee in bridged call, plays synchronously, autoservicing the other channel during the message, so please don't use this for very long messages.

Definition at line 2035 of file features.c.

References play_message_to_chans().

Referenced by builtin_automonitor().

02036 {
02037    return play_message_to_chans(caller_chan, callee_chan, 0, "automon message",
02038       audiofile);
02039 }

static int play_message_on_chan ( struct ast_channel *  play_to,
struct ast_channel *  other,
const char *  msg,
const char *  audiofile 
) [static]

Definition at line 1981 of file features.c.

References ast_autoservice_ignore(), ast_autoservice_start(), ast_autoservice_stop(), AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_log(), ast_stream_and_wait(), and LOG_WARNING.

Referenced by masq_park_call(), and play_message_to_chans().

01982 {
01983    /* Put other channel in autoservice. */
01984    if (ast_autoservice_start(other)) {
01985       return -1;
01986    }
01987    ast_autoservice_ignore(other, AST_FRAME_DTMF_BEGIN);
01988    ast_autoservice_ignore(other, AST_FRAME_DTMF_END);
01989    if (ast_stream_and_wait(play_to, audiofile, "")) {
01990       ast_log(LOG_WARNING, "Failed to play %s '%s'!\n", msg, audiofile);
01991       ast_autoservice_stop(other);
01992       return -1;
01993    }
01994    if (ast_autoservice_stop(other)) {
01995       return -1;
01996    }
01997    return 0;
01998 }

static int play_message_to_chans ( struct ast_channel *  left,
struct ast_channel *  right,
int  which,
const char *  msg,
const char *  audiofile 
) [static]

Definition at line 2016 of file features.c.

References play_message_on_chan().

Referenced by parked_call_exec(), and play_message_in_bridged_call().

02017 {
02018    /* First play the file to the left channel if requested. */
02019    if (which <= 0 && play_message_on_chan(left, right, msg, audiofile)) {
02020       return -1;
02021    }
02022 
02023    /* Then play the file to the right channel if requested. */
02024    if (which >= 0 && play_message_on_chan(right, left, msg, audiofile)) {
02025       return -1;
02026    }
02027 
02028    return 0;
02029 }

static void post_manager_event ( const char *  s,
struct parkeduser *  pu 
) [static]

Output parking event to manager.

Definition at line 4533 of file features.c.

References ast_channel::caller, parkeduser::chan, ast_channel::connected, EVENT_FLAG_CALL, ast_party_connected_line::id, ast_party_caller::id, manager_event, ast_party_id::name, ast_parkinglot::name, ast_party_id::number, parkeduser::parkingexten, parkeduser::parkinglot, S_COR, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by manage_parked_call().

04534 {
04535    manager_event(EVENT_FLAG_CALL, s,
04536       "Exten: %s\r\n"
04537       "Channel: %s\r\n"
04538       "Parkinglot: %s\r\n"
04539       "CallerIDNum: %s\r\n"
04540       "CallerIDName: %s\r\n"
04541       "ConnectedLineNum: %s\r\n"
04542       "ConnectedLineName: %s\r\n"
04543       "UniqueID: %s\r\n",
04544       pu->parkingexten, 
04545       pu->chan->name,
04546       pu->parkinglot->name,
04547       S_COR(pu->chan->caller.id.number.valid, pu->chan->caller.id.number.str, "<unknown>"),
04548       S_COR(pu->chan->caller.id.name.valid, pu->chan->caller.id.name.str, "<unknown>"),
04549       S_COR(pu->chan->connected.id.number.valid, pu->chan->connected.id.number.str, "<unknown>"),
04550       S_COR(pu->chan->connected.id.name.valid, pu->chan->connected.id.name.str, "<unknown>"),
04551       pu->chan->uniqueid
04552       );
04553 }

static void process_applicationmap_line ( struct ast_variable *  var  )  [static]

Todo:
XXX var_name or app_args ?

Definition at line 5648 of file features.c.

References ast_call_feature::app, app, ast_call_feature::app_args, args, AST_APP_ARG, ast_calloc, ast_copy_string(), AST_DECLARE_APP_ARGS, AST_FEATURE_FLAG_BYBOTH, AST_FEATURE_FLAG_BYCALLEE, AST_FEATURE_FLAG_BYCALLER, AST_FEATURE_FLAG_NEEDSDTMF, AST_FEATURE_FLAG_ONPEER, AST_FEATURE_FLAG_ONSELF, ast_free, ast_log(), ast_register_feature(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_set_flag, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_verb, ast_call_feature::exten, FEATURE_APP_ARGS_LEN, FEATURE_APP_LEN, feature_exec_app(), FEATURE_EXTEN_LEN, FEATURE_MOH_LEN, FEATURE_SNAME_LEN, find_dynamic_feature(), LOG_NOTICE, LOG_WARNING, ast_call_feature::moh_class, ast_variable::name, ast_call_feature::operation, ast_call_feature::sname, and ast_variable::value.

Referenced by process_config().

05649 {
05650    char *tmp_val = ast_strdupa(var->value);
05651    char *activateon, *new_syn;
05652    struct ast_call_feature *feature;
05653    AST_DECLARE_APP_ARGS(args,
05654       AST_APP_ARG(exten);
05655       AST_APP_ARG(activatedby);
05656       AST_APP_ARG(app);
05657       AST_APP_ARG(app_args);
05658       AST_APP_ARG(moh_class);
05659    );
05660 
05661    AST_STANDARD_APP_ARGS(args, tmp_val);
05662    if ((new_syn = strchr(args.app, '('))) {
05663       /* New syntax */
05664       args.moh_class = args.app_args;
05665       args.app_args = new_syn;
05666       *args.app_args++ = '\0';
05667       if (args.app_args[strlen(args.app_args) - 1] == ')') {
05668          args.app_args[strlen(args.app_args) - 1] = '\0';
05669       }
05670    }
05671 
05672    activateon = strsep(&args.activatedby, "/");
05673 
05674    /*! \todo XXX var_name or app_args ? */
05675    if (ast_strlen_zero(args.app)
05676       || ast_strlen_zero(args.exten)
05677       || ast_strlen_zero(activateon)
05678       || ast_strlen_zero(var->name)) {
05679       ast_log(LOG_NOTICE,
05680          "Please check the feature Mapping Syntax, either extension, name, or app aren't provided %s %s %s %s\n",
05681          args.app, args.exten, activateon, var->name);
05682       return;
05683    }
05684 
05685    AST_RWLIST_RDLOCK(&feature_list);
05686    if (find_dynamic_feature(var->name)) {
05687       AST_RWLIST_UNLOCK(&feature_list);
05688       ast_log(LOG_WARNING, "Dynamic Feature '%s' specified more than once!\n",
05689          var->name);
05690       return;
05691    }
05692    AST_RWLIST_UNLOCK(&feature_list);
05693 
05694    if (!(feature = ast_calloc(1, sizeof(*feature)))) {
05695       return;
05696    }
05697 
05698    ast_copy_string(feature->sname, var->name, FEATURE_SNAME_LEN);
05699    ast_copy_string(feature->app, args.app, FEATURE_APP_LEN);
05700    ast_copy_string(feature->exten, args.exten, FEATURE_EXTEN_LEN);
05701 
05702    if (args.app_args) {
05703       ast_copy_string(feature->app_args, args.app_args, FEATURE_APP_ARGS_LEN);
05704    }
05705 
05706    if (args.moh_class) {
05707       ast_copy_string(feature->moh_class, args.moh_class, FEATURE_MOH_LEN);
05708    }
05709 
05710    ast_copy_string(feature->exten, args.exten, sizeof(feature->exten));
05711    feature->operation = feature_exec_app;
05712    ast_set_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF);
05713 
05714    /* Allow caller and callee to be specified for backwards compatability */
05715    if (!strcasecmp(activateon, "self") || !strcasecmp(activateon, "caller")) {
05716       ast_set_flag(feature, AST_FEATURE_FLAG_ONSELF);
05717    } else if (!strcasecmp(activateon, "peer") || !strcasecmp(activateon, "callee")) {
05718       ast_set_flag(feature, AST_FEATURE_FLAG_ONPEER);
05719    } else {
05720       ast_log(LOG_NOTICE, "Invalid 'ActivateOn' specification for feature '%s',"
05721          " must be 'self', or 'peer'\n", var->name);
05722       ast_free(feature);
05723       return;
05724    }
05725 
05726    if (ast_strlen_zero(args.activatedby)) {
05727       ast_set_flag(feature, AST_FEATURE_FLAG_BYBOTH);
05728    } else if (!strcasecmp(args.activatedby, "caller")) {
05729       ast_set_flag(feature, AST_FEATURE_FLAG_BYCALLER);
05730    } else if (!strcasecmp(args.activatedby, "callee")) {
05731       ast_set_flag(feature, AST_FEATURE_FLAG_BYCALLEE);
05732    } else if (!strcasecmp(args.activatedby, "both")) {
05733       ast_set_flag(feature, AST_FEATURE_FLAG_BYBOTH);
05734    } else {
05735       ast_log(LOG_NOTICE, "Invalid 'ActivatedBy' specification for feature '%s',"
05736          " must be 'caller', or 'callee', or 'both'\n", var->name);
05737       ast_free(feature);
05738       return;
05739    }
05740 
05741    ast_register_feature(feature);
05742 
05743    ast_verb(2, "Mapping Feature '%s' to app '%s(%s)' with code '%s'\n",
05744       var->name, args.app, args.app_args, args.exten);
05745 }

static int process_config ( struct ast_config *  cfg  )  [static]

Definition at line 5747 of file features.c.

References adsipark, ARRAY_LEN, ast_category_browse(), ast_copy_string(), ast_debug, ast_find_call_feature(), ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_true(), ast_unregister_features(), ast_unregister_groups(), ast_variable_browse(), atxfercallbackretries, atxferdropcall, atxferloopdelay, atxfernoanswertimeout, build_parkinglot(), comebacktoorigin, courtesytone, DEFAULT_ATXFER_CALLBACK_RETRIES, DEFAULT_ATXFER_DROP_CALL, DEFAULT_ATXFER_LOOP_DELAY, DEFAULT_FEATURE_DIGIT_TIMEOUT, DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER, DEFAULT_PARKINGLOT, DEFAULT_TRANSFER_DIGIT_TIMEOUT, featuredigittimeout, find_dynamic_feature(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, parkeddynamic, parkedplay, pickupfailsound, pickupsound, process_applicationmap_line(), register_group(), register_group_feature(), remap_feature(), transferdigittimeout, unmap_features(), ast_variable::value, var, xferfailsound, and xfersound.

Referenced by load_config().

05748 {
05749    int i;
05750    struct ast_variable *var = NULL;
05751    struct feature_group *fg = NULL;
05752    char *ctg; 
05753    static const char * const categories[] = { 
05754       /* Categories in features.conf that are not
05755        * to be parsed as group categories
05756        */
05757       "general",
05758       "featuremap",
05759       "applicationmap"
05760    };
05761 
05762    /* Set general features global defaults. */
05763    featuredigittimeout = DEFAULT_FEATURE_DIGIT_TIMEOUT;
05764 
05765    /* Set global call pickup defaults. */
05766    strcpy(pickup_ext, "*8");
05767    pickupsound[0] = '\0';
05768    pickupfailsound[0] = '\0';
05769 
05770    /* Set global call transfer defaults. */
05771    strcpy(xfersound, "beep");
05772    strcpy(xferfailsound, "beeperr");
05773    transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
05774    atxfernoanswertimeout = DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER;
05775    atxferloopdelay = DEFAULT_ATXFER_LOOP_DELAY;
05776    atxferdropcall = DEFAULT_ATXFER_DROP_CALL;
05777    atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
05778 
05779    /* Set global call parking defaults. */
05780    comebacktoorigin = 1;
05781    courtesytone[0] = '\0';
05782    parkedplay = 0;
05783    adsipark = 0;
05784    parkeddynamic = 0;
05785 
05786    var = ast_variable_browse(cfg, "general");
05787    build_parkinglot(DEFAULT_PARKINGLOT, var);
05788    for (; var; var = var->next) {
05789       if (!strcasecmp(var->name, "parkeddynamic")) {
05790          parkeddynamic = ast_true(var->value);
05791       } else if (!strcasecmp(var->name, "adsipark")) {
05792          adsipark = ast_true(var->value);
05793       } else if (!strcasecmp(var->name, "transferdigittimeout")) {
05794          if ((sscanf(var->value, "%30d", &transferdigittimeout) != 1) || (transferdigittimeout < 1)) {
05795             ast_log(LOG_WARNING, "%s is not a valid transferdigittimeout\n", var->value);
05796             transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
05797          } else {
05798             transferdigittimeout = transferdigittimeout * 1000;
05799          }
05800       } else if (!strcasecmp(var->name, "featuredigittimeout")) {
05801          if ((sscanf(var->value, "%30d", &featuredigittimeout) != 1) || (featuredigittimeout < 1)) {
05802             ast_log(LOG_WARNING, "%s is not a valid featuredigittimeout\n", var->value);
05803             featuredigittimeout = DEFAULT_FEATURE_DIGIT_TIMEOUT;
05804          }
05805       } else if (!strcasecmp(var->name, "atxfernoanswertimeout")) {
05806          if ((sscanf(var->value, "%30d", &atxfernoanswertimeout) != 1) || (atxfernoanswertimeout < 1)) {
05807             ast_log(LOG_WARNING, "%s is not a valid atxfernoanswertimeout\n", var->value);
05808             atxfernoanswertimeout = DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER;
05809          } else {
05810             atxfernoanswertimeout = atxfernoanswertimeout * 1000;
05811          }
05812       } else if (!strcasecmp(var->name, "atxferloopdelay")) {
05813          if ((sscanf(var->value, "%30u", &atxferloopdelay) != 1)) {
05814             ast_log(LOG_WARNING, "%s is not a valid atxferloopdelay\n", var->value);
05815             atxferloopdelay = DEFAULT_ATXFER_LOOP_DELAY;
05816          } else {
05817             atxferloopdelay *= 1000;
05818          }
05819       } else if (!strcasecmp(var->name, "atxferdropcall")) {
05820          atxferdropcall = ast_true(var->value);
05821       } else if (!strcasecmp(var->name, "atxfercallbackretries")) {
05822          if ((sscanf(var->value, "%30u", &atxfercallbackretries) != 1)) {
05823             ast_log(LOG_WARNING, "%s is not a valid atxfercallbackretries\n", var->value);
05824             atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
05825          }
05826       } else if (!strcasecmp(var->name, "courtesytone")) {
05827          ast_copy_string(courtesytone, var->value, sizeof(courtesytone));
05828       }  else if (!strcasecmp(var->name, "parkedplay")) {
05829          if (!strcasecmp(var->value, "both")) {
05830             parkedplay = 2;
05831          } else if (!strcasecmp(var->value, "parked")) {
05832             parkedplay = 1;
05833          } else {
05834             parkedplay = 0;
05835          }
05836       } else if (!strcasecmp(var->name, "xfersound")) {
05837          ast_copy_string(xfersound, var->value, sizeof(xfersound));
05838       } else if (!strcasecmp(var->name, "xferfailsound")) {
05839          ast_copy_string(xferfailsound, var->value, sizeof(xferfailsound));
05840       } else if (!strcasecmp(var->name, "pickupexten")) {
05841          ast_copy_string(pickup_ext, var->value, sizeof(pickup_ext));
05842       } else if (!strcasecmp(var->name, "pickupsound")) {
05843          ast_copy_string(pickupsound, var->value, sizeof(pickupsound));
05844       } else if (!strcasecmp(var->name, "pickupfailsound")) {
05845          ast_copy_string(pickupfailsound, var->value, sizeof(pickupfailsound));
05846       } else if (!strcasecmp(var->name, "comebacktoorigin")) {
05847          comebacktoorigin = ast_true(var->value);
05848       }
05849    }
05850 
05851    unmap_features();
05852    for (var = ast_variable_browse(cfg, "featuremap"); var; var = var->next) {
05853       if (remap_feature(var->name, var->value)) {
05854          ast_log(LOG_NOTICE, "Unknown feature '%s'\n", var->name);
05855       }
05856    }
05857 
05858    /* Map a key combination to an application */
05859    ast_unregister_features();
05860    for (var = ast_variable_browse(cfg, "applicationmap"); var; var = var->next) {
05861       process_applicationmap_line(var);
05862    }
05863 
05864    ast_unregister_groups();
05865    AST_RWLIST_WRLOCK(&feature_groups);
05866 
05867    ctg = NULL;
05868    while ((ctg = ast_category_browse(cfg, ctg))) {
05869       /* Is this a parkinglot definition ? */
05870       if (!strncasecmp(ctg, "parkinglot_", strlen("parkinglot_"))) {
05871          ast_debug(2, "Found configuration section %s, assume parking context\n", ctg);
05872          if (!build_parkinglot(ctg, ast_variable_browse(cfg, ctg))) {
05873             ast_log(LOG_ERROR, "Could not build parking lot %s. Configuration error.\n", ctg);
05874          } else {
05875             ast_debug(1, "Configured parking context %s\n", ctg);
05876          }
05877          continue;   
05878       }
05879 
05880       /* No, check if it's a group */
05881       for (i = 0; i < ARRAY_LEN(categories); i++) {
05882          if (!strcasecmp(categories[i], ctg)) {
05883             break;
05884          }
05885       }
05886       if (i < ARRAY_LEN(categories)) {
05887          continue;
05888       }
05889 
05890       if (!(fg = register_group(ctg))) {
05891          continue;
05892       }
05893 
05894       for (var = ast_variable_browse(cfg, ctg); var; var = var->next) {
05895          struct ast_call_feature *feature;
05896 
05897          AST_RWLIST_RDLOCK(&feature_list);
05898          if (!(feature = find_dynamic_feature(var->name)) && 
05899              !(feature = ast_find_call_feature(var->name))) {
05900             AST_RWLIST_UNLOCK(&feature_list);
05901             ast_log(LOG_WARNING, "Feature '%s' was not found.\n", var->name);
05902             continue;
05903          }
05904          AST_RWLIST_UNLOCK(&feature_list);
05905 
05906          register_group_feature(fg, var->value, feature);
05907       }
05908    }
05909 
05910    AST_RWLIST_UNLOCK(&feature_groups);
05911 
05912    return 0;
05913 }

static const char* real_ctx ( struct ast_channel *  transferer,
struct ast_channel *  transferee 
) [static]

Find the context for the transfer.

Parameters:
transferer 
transferee Grab the TRANSFER_CONTEXT, if fails try grabbing macrocontext.
Returns:
a context string

Definition at line 2269 of file features.c.

References ast_strlen_zero(), ast_channel::context, ast_channel::macrocontext, and pbx_builtin_getvar_helper().

Referenced by builtin_atxfer(), and builtin_blindtransfer().

02270 {
02271    const char *s = pbx_builtin_getvar_helper(transferer, "TRANSFER_CONTEXT");
02272    if (ast_strlen_zero(s)) {
02273       s = pbx_builtin_getvar_helper(transferee, "TRANSFER_CONTEXT");
02274    }
02275    if (ast_strlen_zero(s)) { /* Use the non-macro context to transfer the call XXX ? */
02276       s = transferer->macrocontext;
02277    }
02278    if (ast_strlen_zero(s)) {
02279       s = transferer->context;
02280    }
02281    return s;  
02282 }

static struct feature_group* register_group ( const char *  fgname  )  [static, read]

Add new feature group.

Parameters:
fgname feature group name.

Add new feature group to the feature group list insert at head of list.

Note:
This function MUST be called while feature_groups is locked.

Definition at line 2957 of file features.c.

References ast_calloc_with_stringfields, AST_LIST_INSERT_HEAD, ast_log(), ast_string_field_set, ast_verb, feature_group::gname, and LOG_NOTICE.

Referenced by process_config().

02958 {
02959    struct feature_group *fg;
02960 
02961    if (!fgname) {
02962       ast_log(LOG_NOTICE, "You didn't pass a new group name!\n");
02963       return NULL;
02964    }
02965 
02966    if (!(fg = ast_calloc_with_stringfields(1, struct feature_group, 128))) {
02967       return NULL;
02968    }
02969 
02970    ast_string_field_set(fg, gname, fgname);
02971 
02972    AST_LIST_INSERT_HEAD(&feature_groups, fg, entry);
02973 
02974    ast_verb(2, "Registered group '%s'\n", fg->gname);
02975 
02976    return fg;
02977 }

static void register_group_feature ( struct feature_group *  fg,
const char *  exten,
struct ast_call_feature *  feature 
) [static]

Add feature to group.

Parameters:
fg feature group
exten 
feature feature to add.

Check fg and feature specified, add feature to list

Note:
This function MUST be called while feature_groups is locked.

Definition at line 2988 of file features.c.

References ast_calloc_with_stringfields, AST_LIST_INSERT_HEAD, ast_log(), ast_string_field_set, ast_verb, feature_group_exten::exten, ast_call_feature::exten, feature_group_exten::feature, feature_group::features, feature_group::gname, LOG_NOTICE, S_OR, and ast_call_feature::sname.

Referenced by process_config().

02989 {
02990    struct feature_group_exten *fge;
02991 
02992    if (!fg) {
02993       ast_log(LOG_NOTICE, "You didn't pass a group!\n");
02994       return;
02995    }
02996 
02997    if (!feature) {
02998       ast_log(LOG_NOTICE, "You didn't pass a feature!\n");
02999       return;
03000    }
03001 
03002    if (!(fge = ast_calloc_with_stringfields(1, struct feature_group_exten, 128))) {
03003       return;
03004    }
03005 
03006    ast_string_field_set(fge, exten, S_OR(exten, feature->exten));
03007 
03008    fge->feature = feature;
03009 
03010    AST_LIST_INSERT_HEAD(&fg->features, fge, entry);
03011 
03012    ast_verb(2, "Registered feature '%s' for group '%s' at exten '%s'\n",
03013                feature->sname, fg->gname, fge->exten);
03014 }

static int remap_feature ( const char *  name,
const char *  value 
) [static]

Definition at line 3194 of file features.c.

References ast_copy_string(), ast_rwlock_unlock, ast_rwlock_wrlock, FEATURES_COUNT, and features_lock.

Referenced by process_config().

03195 {
03196    int x, res = -1;
03197 
03198    ast_rwlock_wrlock(&features_lock);
03199    for (x = 0; x < FEATURES_COUNT; x++) {
03200       if (strcasecmp(builtin_features[x].sname, name))
03201          continue;
03202 
03203       ast_copy_string(builtin_features[x].exten, value, sizeof(builtin_features[x].exten));
03204       res = 0;
03205       break;
03206    }
03207    ast_rwlock_unlock(&features_lock);
03208 
03209    return res;
03210 }

static void remove_dead_context_usage ( const char *  context,
struct parking_dp_context *  old_ctx,
struct parking_dp_context *  new_ctx 
) [static]

Definition at line 6474 of file features.c.

References parking_dp_context::access_extens, destroy_space(), parking_dp_context::hints, remove_dead_ramp_usage(), remove_dead_spaces_usage(), and parking_dp_context::spaces.

Referenced by remove_dead_dialplan_useage().

06475 {
06476    remove_dead_ramp_usage(context, &old_ctx->access_extens, &new_ctx->access_extens);
06477    remove_dead_spaces_usage(context, &old_ctx->spaces, &new_ctx->spaces, destroy_space);
06478 #if 0
06479    /* I don't think we should destroy hints if the parking space still exists. */
06480    remove_dead_spaces_usage(context, &old_ctx->hints, &new_ctx->hints, destroy_space_hint);
06481 #endif
06482 }

static void remove_dead_dialplan_useage ( struct parking_dp_map *  old_map,
struct parking_dp_map *  new_map 
) [static]

Definition at line 6497 of file features.c.

References ast_context_destroy(), ast_context_find(), AST_LIST_FIRST, AST_LIST_NEXT, parking_dp_context::context, registrar, and remove_dead_context_usage().

Referenced by load_config().

06498 {
06499    struct parking_dp_context *old_ctx;
06500    struct parking_dp_context *new_ctx;
06501    struct ast_context *con;
06502    int cmp;
06503 
06504    old_ctx = AST_LIST_FIRST(old_map);
06505    new_ctx = AST_LIST_FIRST(new_map);
06506 
06507    while (new_ctx) {
06508       if (!old_ctx) {
06509          /* No old contexts left, so no dead stuff can remain. */
06510          return;
06511       }
06512       cmp = strcmp(old_ctx->context, new_ctx->context);
06513       if (cmp < 0) {
06514          /* New map does not have old map context. */
06515          con = ast_context_find(old_ctx->context);
06516          if (con) {
06517             ast_context_destroy(con, registrar);
06518          }
06519          old_ctx = AST_LIST_NEXT(old_ctx, node);
06520          continue;
06521       }
06522       if (cmp == 0) {
06523          /* Old and new map have this context. */
06524          remove_dead_context_usage(old_ctx->context, old_ctx, new_ctx);
06525          old_ctx = AST_LIST_NEXT(old_ctx, node);
06526       } else {
06527          /* Old map does not have new map context. */
06528       }
06529       new_ctx = AST_LIST_NEXT(new_ctx, node);
06530    }
06531 
06532    /* Any old contexts left must be dead. */
06533    for (; old_ctx; old_ctx = AST_LIST_NEXT(old_ctx, node)) {
06534       con = ast_context_find(old_ctx->context);
06535       if (con) {
06536          ast_context_destroy(con, registrar);
06537       }
06538    }
06539 }

static void remove_dead_ramp_usage ( const char *  context,
struct parking_dp_ramp_map *  old_ramps,
struct parking_dp_ramp_map *  new_ramps 
) [static]

Definition at line 6333 of file features.c.

References AST_LIST_FIRST, AST_LIST_NEXT, parking_dp_ramp::exten, and remove_exten_if_exist().

Referenced by remove_dead_context_usage().

06334 {
06335    struct parking_dp_ramp *old_ramp;
06336    struct parking_dp_ramp *new_ramp;
06337    int cmp;
06338 
06339    old_ramp = AST_LIST_FIRST(old_ramps);
06340    new_ramp = AST_LIST_FIRST(new_ramps);
06341 
06342    while (new_ramp) {
06343       if (!old_ramp) {
06344          /* No old ramps left, so no dead ramps can remain. */
06345          return;
06346       }
06347       cmp = strcmp(old_ramp->exten, new_ramp->exten);
06348       if (cmp < 0) {
06349          /* New map does not have old ramp. */
06350          remove_exten_if_exist(context, old_ramp->exten, 1);
06351          old_ramp = AST_LIST_NEXT(old_ramp, node);
06352          continue;
06353       }
06354       if (cmp == 0) {
06355          /* Old and new map have this ramp. */
06356          old_ramp = AST_LIST_NEXT(old_ramp, node);
06357       } else {
06358          /* Old map does not have new ramp. */
06359       }
06360       new_ramp = AST_LIST_NEXT(new_ramp, node);
06361    }
06362 
06363    /* Any old ramps left must be dead. */
06364    for (; old_ramp; old_ramp = AST_LIST_NEXT(old_ramp, node)) {
06365       remove_exten_if_exist(context, old_ramp->exten, 1);
06366    }
06367 }

static void remove_dead_spaces_usage ( const char *  context,
struct parking_dp_space_map *  old_spaces,
struct parking_dp_space_map *  new_spaces,
void(*)(const char *context, int space)  destroy_space 
) [static]

< Current position in the current old range.

Definition at line 6403 of file features.c.

References AST_LIST_FIRST, AST_LIST_NEXT, destroy_space(), parking_dp_spaces::start, and parking_dp_spaces::stop.

Referenced by remove_dead_context_usage().

06406 {
06407    struct parking_dp_spaces *old_range;
06408    struct parking_dp_spaces *new_range;
06409    int space;/*!< Current position in the current old range. */
06410    int stop;
06411 
06412    old_range = AST_LIST_FIRST(old_spaces);
06413    new_range = AST_LIST_FIRST(new_spaces);
06414    space = -1;
06415 
06416    while (old_range) {
06417       if (space < old_range->start) {
06418          space = old_range->start;
06419       }
06420       if (new_range) {
06421          if (space < new_range->start) {
06422             /* Current position in old range starts before new range. */
06423             if (old_range->stop < new_range->start) {
06424                /* Old range ends before new range. */
06425                stop = old_range->stop;
06426                old_range = AST_LIST_NEXT(old_range, node);
06427             } else {
06428                /* Tail of old range overlaps new range. */
06429                stop = new_range->start - 1;
06430             }
06431          } else if (/* new_range->start <= space && */ space <= new_range->stop) {
06432             /* Current position in old range overlaps new range. */
06433             if (old_range->stop <= new_range->stop) {
06434                /* Old range ends at or before new range. */
06435                old_range = AST_LIST_NEXT(old_range, node);
06436             } else {
06437                /* Old range extends beyond end of new range. */
06438                space = new_range->stop + 1;
06439                new_range = AST_LIST_NEXT(new_range, node);
06440             }
06441             continue;
06442          } else /* if (new_range->stop < space) */ {
06443             /* Current position in old range starts after new range. */
06444             new_range = AST_LIST_NEXT(new_range, node);
06445             continue;
06446          }
06447       } else {
06448          /* No more new ranges.  All remaining old spaces are dead. */
06449          stop = old_range->stop;
06450          old_range = AST_LIST_NEXT(old_range, node);
06451       }
06452 
06453       /* Destroy dead parking spaces. */
06454       for (; space <= stop; ++space) {
06455          destroy_space(context, space);
06456       }
06457    }
06458 }

static void remove_exten_if_exist ( const char *  context,
const char *  exten,
int  priority 
) [static]

Definition at line 6307 of file features.c.

References ast_context_remove_extension(), ast_debug, E_MATCH, pbx_find_extension(), registrar, and pbx_find_info::stacklen.

Referenced by destroy_space(), and remove_dead_ramp_usage().

06308 {
06309    struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
06310 
06311    if (pbx_find_extension(NULL, NULL, &q, context, exten, priority, NULL, NULL,
06312       E_MATCH)) {
06313       ast_debug(1, "Removing unneeded parking lot exten: %s@%s priority:%d\n",
06314          context, exten, priority);
06315       ast_context_remove_extension(context, exten, priority, registrar);
06316    }
06317 }

static void set_bridge_features_on_config ( struct ast_bridge_config *  config,
const char *  features 
) [static]

Definition at line 3801 of file features.c.

References AST_FEATURE_AUTOMON, AST_FEATURE_DISCONNECT, AST_FEATURE_PARKCALL, AST_FEATURE_REDIRECT, ast_log(), ast_set_flag, ast_strlen_zero(), ast_bridge_config::features_caller, and LOG_WARNING.

Referenced by ast_bridge_call().

03802 {
03803    const char *feature;
03804 
03805    if (ast_strlen_zero(features)) {
03806       return;
03807    }
03808 
03809    for (feature = features; *feature; feature++) {
03810       switch (*feature) {
03811       case 'T' :
03812       case 't' :
03813          ast_set_flag(&(config->features_caller), AST_FEATURE_REDIRECT);
03814          break;
03815       case 'K' :
03816       case 'k' :
03817          ast_set_flag(&(config->features_caller), AST_FEATURE_PARKCALL);
03818          break;
03819       case 'H' :
03820       case 'h' :
03821          ast_set_flag(&(config->features_caller), AST_FEATURE_DISCONNECT);
03822          break;
03823       case 'W' :
03824       case 'w' :
03825          ast_set_flag(&(config->features_caller), AST_FEATURE_AUTOMON);
03826          break;
03827       default :
03828          ast_log(LOG_WARNING, "Skipping unknown feature code '%c'\n", *feature);
03829       }
03830    }
03831 }

static void set_c_e_p ( struct ast_channel *  chan,
const char *  context,
const char *  ext,
int  pri 
) [static]

store context, extension and priority

Parameters:
chan,context,ext,pri 

Definition at line 877 of file features.c.

References ast_copy_string(), ast_channel::context, ast_channel::exten, and ast_channel::priority.

Referenced by builtin_blindtransfer(), manage_parked_call(), and masq_park_call().

00878 {
00879    ast_copy_string(chan->context, context, sizeof(chan->context));
00880    ast_copy_string(chan->exten, ext, sizeof(chan->exten));
00881    chan->priority = pri;
00882 }

static void set_config_flags ( struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_bridge_config *  config 
) [static]

Definition at line 3385 of file features.c.

References AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, ast_clear_flag, AST_FEATURE_FLAG_BYCALLEE, AST_FEATURE_FLAG_BYCALLER, AST_FEATURE_FLAG_NEEDSDTMF, AST_FLAGS_ALL, AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_rwlock_rdlock, ast_rwlock_unlock, ast_set_flag, ast_strdupa, ast_test_flag, feature_group_exten::feature, ast_call_feature::feature_mask, feature_group::features, ast_bridge_config::features_callee, ast_bridge_config::features_caller, FEATURES_COUNT, features_lock, find_dynamic_feature(), and pbx_builtin_getvar_helper().

Referenced by ast_bridge_call().

03386 {
03387    int x;
03388 
03389    ast_clear_flag(config, AST_FLAGS_ALL);
03390 
03391    ast_rwlock_rdlock(&features_lock);
03392    for (x = 0; x < FEATURES_COUNT; x++) {
03393       if (!ast_test_flag(builtin_features + x, AST_FEATURE_FLAG_NEEDSDTMF))
03394          continue;
03395 
03396       if (ast_test_flag(&(config->features_caller), builtin_features[x].feature_mask))
03397          ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
03398 
03399       if (ast_test_flag(&(config->features_callee), builtin_features[x].feature_mask))
03400          ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
03401    }
03402    ast_rwlock_unlock(&features_lock);
03403 
03404    if (chan && peer && !(ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_0) && ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_1))) {
03405       const char *dynamic_features = pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES");
03406 
03407       if (dynamic_features) {
03408          char *tmp = ast_strdupa(dynamic_features);
03409          char *tok;
03410          struct ast_call_feature *feature;
03411 
03412          /* while we have a feature */
03413          while ((tok = strsep(&tmp, "#"))) {
03414             struct feature_group *fg;
03415 
03416             AST_RWLIST_RDLOCK(&feature_groups);
03417             AST_RWLIST_TRAVERSE(&feature_groups, fg, entry) {
03418                struct feature_group_exten *fge;
03419 
03420                AST_LIST_TRAVERSE(&fg->features, fge, entry) {
03421                   if (ast_test_flag(fge->feature, AST_FEATURE_FLAG_BYCALLER)) {
03422                      ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
03423                   }
03424                   if (ast_test_flag(fge->feature, AST_FEATURE_FLAG_BYCALLEE)) {
03425                      ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
03426                   }
03427                }
03428             }
03429             AST_RWLIST_UNLOCK(&feature_groups);
03430 
03431             AST_RWLIST_RDLOCK(&feature_list);
03432             if ((feature = find_dynamic_feature(tok)) && ast_test_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF)) {
03433                if (ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLER)) {
03434                   ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
03435                }
03436                if (ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLEE)) {
03437                   ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
03438                }
03439             }
03440             AST_RWLIST_UNLOCK(&feature_list);
03441          }
03442       }
03443    }
03444 }

static void set_peers ( struct ast_channel **  caller,
struct ast_channel **  callee,
struct ast_channel *  peer,
struct ast_channel *  chan,
int  sense 
) [static]

set caller and callee according to the direction

Parameters:
caller,callee,peer,chan,sense Detect who triggered feature and set callee/caller variables accordingly

Definition at line 1908 of file features.c.

References FEATURE_SENSE_PEER.

Referenced by builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), builtin_blindtransfer(), and builtin_parkcall().

01910 {
01911    if (sense == FEATURE_SENSE_PEER) {
01912       *caller = peer;
01913       *callee = chan;
01914    } else {
01915       *callee = peer;
01916       *caller = chan;
01917    }
01918 }

static void unmap_features ( void   )  [static]

Definition at line 3184 of file features.c.

References ast_rwlock_unlock, ast_rwlock_wrlock, FEATURES_COUNT, and features_lock.

Referenced by process_config().

03185 {
03186    int x;
03187 
03188    ast_rwlock_wrlock(&features_lock);
03189    for (x = 0; x < FEATURES_COUNT; x++)
03190       strcpy(builtin_features[x].exten, builtin_features[x].default_exten);
03191    ast_rwlock_unlock(&features_lock);
03192 }

static int usage_context_add_ramp ( struct parking_dp_ramp_map *  ramp_map,
const char *  exten,
int  exclusive,
struct ast_parkinglot *  lot,
int  complain 
) [static]

Definition at line 5993 of file features.c.

References AST_LIST_INSERT_BEFORE_CURRENT, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), build_dialplan_useage_ramp(), ast_parkinglot::cfg, parking_dp_ramp::exclusive, parking_dp_ramp::exten, LOG_WARNING, ast_parkinglot::name, and parkinglot_cfg::parking_con.

Referenced by dialplan_usage_add_parkinglot_data().

05994 {
05995    struct parking_dp_ramp *cur_ramp;
05996    struct parking_dp_ramp *new_ramp;
05997    int cmp;
05998 
05999    /* Make sure that exclusive is only 0 or 1 */
06000    if (exclusive) {
06001       exclusive = 1;
06002    }
06003 
06004    AST_LIST_TRAVERSE_SAFE_BEGIN(ramp_map, cur_ramp, node) {
06005       cmp = strcmp(exten, cur_ramp->exten);
06006       if (cmp > 0) {
06007          /* The parking lot ramp goes after this node. */
06008          continue;
06009       }
06010       if (cmp == 0) {
06011          /* The ramp is already in the map. */
06012          if (complain && (cur_ramp->exclusive || exclusive)) {
06013             ast_log(LOG_WARNING,
06014                "Parking lot '%s' parkext %s@%s used by another parking lot.\n",
06015                lot->name, exten, lot->cfg.parking_con);
06016          }
06017          return 0;
06018       }
06019       /* The new parking lot ramp goes before this node. */
06020       new_ramp = build_dialplan_useage_ramp(exten, exclusive);
06021       if (!new_ramp) {
06022          return -1;
06023       }
06024       AST_LIST_INSERT_BEFORE_CURRENT(new_ramp, node);
06025       return 0;
06026    }
06027    AST_LIST_TRAVERSE_SAFE_END;
06028 
06029    /* New parking lot access ramp goes on the end. */
06030    new_ramp = build_dialplan_useage_ramp(exten, exclusive);
06031    if (!new_ramp) {
06032       return -1;
06033    }
06034    AST_LIST_INSERT_TAIL(ramp_map, new_ramp, node);
06035    return 0;
06036 }

static int usage_context_add_spaces ( struct parking_dp_space_map *  space_map,
int  start,
int  stop,
struct ast_parkinglot *  lot,
int  complain 
) [static]

Definition at line 6074 of file features.c.

References ast_free, AST_LIST_INSERT_BEFORE_CURRENT, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), build_dialplan_useage_spaces(), ast_parkinglot::cfg, LOG_WARNING, ast_parkinglot::name, parkinglot_cfg::parking_con, parking_dp_spaces::start, and parking_dp_spaces::stop.

Referenced by dialplan_usage_add_parkinglot_data().

06075 {
06076    struct parking_dp_spaces *cur_node;
06077    struct parking_dp_spaces *expand_node;
06078    struct parking_dp_spaces *new_node;
06079 
06080    expand_node = NULL;
06081    AST_LIST_TRAVERSE_SAFE_BEGIN(space_map, cur_node, node) {
06082       /* NOTE: stop + 1 to combine immediately adjacent nodes into one. */
06083       if (expand_node) {
06084          /* The previous node is expanding to possibly eat following nodes. */
06085          if (expand_node->stop + 1 < cur_node->start) {
06086             /* Current node is completely after expanding node. */
06087             return 0;
06088          }
06089 
06090          if (complain
06091             && ((cur_node->start <= start && start <= cur_node->stop)
06092                || (cur_node->start <= stop && stop <= cur_node->stop)
06093                || (start < cur_node->start && cur_node->stop < stop))) {
06094             /* Only complain once per range add. */
06095             complain = 0;
06096             ast_log(LOG_WARNING,
06097                "Parking lot '%s' parkpos %d-%d@%s overlaps another parking lot.\n",
06098                lot->name, start, stop, lot->cfg.parking_con);
06099          }
06100 
06101          /* Current node is eaten by the expanding node. */
06102          if (expand_node->stop < cur_node->stop) {
06103             expand_node->stop = cur_node->stop;
06104          }
06105          AST_LIST_REMOVE_CURRENT(node);
06106          ast_free(cur_node);
06107          continue;
06108       }
06109 
06110       if (cur_node->stop + 1 < start) {
06111          /* New range is completely after current node. */
06112          continue;
06113       }
06114       if (stop + 1 < cur_node->start) {
06115          /* New range is completely before current node. */
06116          new_node = build_dialplan_useage_spaces(start, stop);
06117          if (!new_node) {
06118             return -1;
06119          }
06120          AST_LIST_INSERT_BEFORE_CURRENT(new_node, node);
06121          return 0;
06122       }
06123 
06124       if (complain
06125          && ((cur_node->start <= start && start <= cur_node->stop)
06126             || (cur_node->start <= stop && stop <= cur_node->stop)
06127             || (start < cur_node->start && cur_node->stop < stop))) {
06128          /* Only complain once per range add. */
06129          complain = 0;
06130          ast_log(LOG_WARNING,
06131             "Parking lot '%s' parkpos %d-%d@%s overlaps another parking lot.\n",
06132             lot->name, start, stop, lot->cfg.parking_con);
06133       }
06134 
06135       /* Current node range overlaps or is immediately adjacent to new range. */
06136       if (start < cur_node->start) {
06137          /* Expand the current node in the front. */
06138          cur_node->start = start;
06139       }
06140       if (stop <= cur_node->stop) {
06141          /* Current node is not expanding in the rear. */
06142          return 0;
06143       }
06144       cur_node->stop = stop;
06145       expand_node = cur_node;
06146    }
06147    AST_LIST_TRAVERSE_SAFE_END;
06148 
06149    if (expand_node) {
06150       /*
06151        * The previous node expanded and either ate all following nodes
06152        * or it was the last node.
06153        */
06154       return 0;
06155    }
06156 
06157    /* New range goes on the end. */
06158    new_node = build_dialplan_useage_spaces(start, stop);
06159    if (!new_node) {
06160       return -1;
06161    }
06162    AST_LIST_INSERT_TAIL(space_map, new_node, node);
06163    return 0;
06164 }

static int xfer_park_call_helper ( struct ast_channel *  park_me,
struct ast_channel *  parker,
struct ast_exten *  park_exten 
) [static]

Definition at line 1848 of file features.c.

References AST_FEATURE_RETURN_SUCCESS, ast_get_extension_app_data(), AST_PARK_OPT_SILENCE, AST_STANDARD_APP_ARGS, ast_strdupa, ast_stream_and_wait(), ast_strlen_zero(), ast_test_flag, create_dynamic_parkinglot(), default_parkinglot, find_parkinglot(), findparkinglotname(), finishup(), masq_park_call(), parkeddynamic, ast_park_call_args::parkinglot, parkinglot_addref(), parkinglot_unref(), parse(), and park_app_args::pl_name.

Referenced by builtin_atxfer(), and builtin_blindtransfer().

01849 {
01850    char *parse;
01851    const char *app_data;
01852    const char *pl_name;
01853    struct ast_park_call_args args = { 0, };
01854    struct park_app_args app_args;
01855    int res;
01856 
01857    app_data = ast_get_extension_app_data(park_exten);
01858    if (!app_data) {
01859       app_data = "";
01860    }
01861    parse = ast_strdupa(app_data);
01862    AST_STANDARD_APP_ARGS(app_args, parse);
01863 
01864    /* Find the parking lot */
01865    if (!ast_strlen_zero(app_args.pl_name)) {
01866       pl_name = app_args.pl_name;
01867    } else {
01868       pl_name = findparkinglotname(parker);
01869    }
01870    if (ast_strlen_zero(pl_name)) {
01871       /* Parking lot is not specified, so use the default parking lot. */
01872       args.parkinglot = parkinglot_addref(default_parkinglot);
01873    } else {
01874       args.parkinglot = find_parkinglot(pl_name);
01875       if (!args.parkinglot && parkeddynamic) {
01876          args.parkinglot = create_dynamic_parkinglot(pl_name, park_me);
01877       }
01878    }
01879 
01880    if (args.parkinglot) {
01881       /* Park the call */
01882       res = finishup(park_me);
01883       if (res) {
01884          /* park_me hungup on us. */
01885          parkinglot_unref(args.parkinglot);
01886          return -1;
01887       }
01888       res = masq_park_call(park_me, parker, &args);
01889       parkinglot_unref(args.parkinglot);
01890    } else {
01891       /* Parking failed because parking lot does not exist. */
01892       if (!ast_test_flag(&args, AST_PARK_OPT_SILENCE)) {
01893          ast_stream_and_wait(parker, "pbx-parkingfailed", "");
01894       }
01895       finishup(park_me);
01896       res = -1;
01897    }
01898 
01899    return res ? AST_FEATURE_RETURN_SUCCESS : -1;
01900 }


Variable Documentation

int adsipark [static]

Definition at line 608 of file features.c.

Referenced by park_call_full(), and process_config().

char* app_bridge = "Bridge" [static]

Definition at line 7374 of file features.c.

unsigned int atxfercallbackretries [static]

Definition at line 617 of file features.c.

Referenced by builtin_atxfer(), and process_config().

unsigned int atxferdropcall [static]

Definition at line 615 of file features.c.

Referenced by builtin_atxfer(), and process_config().

unsigned int atxferloopdelay [static]

Definition at line 616 of file features.c.

Referenced by builtin_atxfer(), and process_config().

int atxfernoanswertimeout [static]

Definition at line 614 of file features.c.

Referenced by builtin_atxfer(), and process_config().

struct ast_app_option bridge_exec_options[128] = { [ 'p' ] = { .flag = BRIDGE_OPT_PLAYTONE }, [ 'h' ] = { .flag = OPT_CALLEE_HANGUP }, [ 'H' ] = { .flag = OPT_CALLER_HANGUP }, [ 'k' ] = { .flag = OPT_CALLEE_PARK }, [ 'K' ] = { .flag = OPT_CALLER_PARK }, [ 'L' ] = { .flag = OPT_DURATION_LIMIT , .arg_index = OPT_ARG_DURATION_LIMIT + 1 }, [ 'S' ] = { .flag = OPT_DURATION_STOP , .arg_index = OPT_ARG_DURATION_STOP + 1 }, [ 't' ] = { .flag = OPT_CALLEE_TRANSFER }, [ 'T' ] = { .flag = OPT_CALLER_TRANSFER }, [ 'w' ] = { .flag = OPT_CALLEE_MONITOR }, [ 'W' ] = { .flag = OPT_CALLER_MONITOR }, [ 'x' ] = { .flag = OPT_CALLEE_KILL }, } [static]

Definition at line 7411 of file features.c.

Referenced by bridge_exec().

Definition at line 2923 of file features.c.

struct ast_cli_entry cli_features[] [static]
Initial value:
 {
   AST_CLI_DEFINE(handle_feature_show, "Lists configured features"),
   AST_CLI_DEFINE(handle_features_reload, "Reloads configured features"),
   AST_CLI_DEFINE(handle_parkedcalls, "List currently parked calls"),
}

Definition at line 7046 of file features.c.

int comebacktoorigin = 1 [static]

Definition at line 612 of file features.c.

Referenced by manage_parked_call(), and process_config().

char courtesytone[256] [static]

Courtesy tone used to pickup parked calls and on-touch-record

Definition at line 589 of file features.c.

Referenced by builtin_automixmonitor(), builtin_automonitor(), parked_call_exec(), and process_config().

Default parking lot.

Note:
Holds a parkinglot reference.
Will not be NULL while running.

Definition at line 582 of file features.c.

Referenced by create_dynamic_parkinglot(), handle_parkedcalls(), load_config(), park_call_exec(), park_space_reserve(), parked_call_exec(), and xfer_park_call_helper().

Initial value:
 {
   .type = "dial-features",
   .destroy = dial_features_destroy,
   .duplicate = dial_features_duplicate,
}

Definition at line 748 of file features.c.

Referenced by add_features_datastore(), builtin_atxfer(), manage_parked_call(), and parked_call_exec().

int featuredigittimeout [static]

Definition at line 611 of file features.c.

Referenced by ast_bridge_call(), and process_config().

ast_rwlock_t features_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, 1 } [static]
ast_mutex_t features_reload_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } [static]

Ensure that features.conf reloads on one thread at a time.

Definition at line 606 of file features.c.

Referenced by ast_features_reload().

int force_reload_load [static]

Force a config reload to reload regardless of config file timestamp.

Definition at line 585 of file features.c.

Referenced by build_parkinglot(), load_config(), parkinglot_activate_cb(), and parkinglot_is_marked_cb().

struct ast_app* mixmonitor_app = NULL [static]

Definition at line 638 of file features.c.

Referenced by builtin_automixmonitor().

int mixmonitor_ok = 1 [static]

Definition at line 639 of file features.c.

Referenced by builtin_automixmonitor().

struct ast_app* monitor_app = NULL [static]

Definition at line 635 of file features.c.

Referenced by ast_bridge_call(), and builtin_automonitor().

int monitor_ok = 1 [static]

Definition at line 636 of file features.c.

Referenced by ast_bridge_call(), and builtin_automonitor().

struct ast_app_option park_call_options[128] = { [ 'r' ] = { .flag = AST_PARK_OPT_RINGING }, [ 'R' ] = { .flag = AST_PARK_OPT_RANDOMIZE }, [ 's' ] = { .flag = AST_PARK_OPT_SILENCE }, } [static]

Definition at line 4946 of file features.c.

Referenced by park_call_exec().

const char* parkcall = "Park" [static]

Definition at line 633 of file features.c.

Referenced by ast_features_init(), get_parking_exten(), and parkinglot_activate().

const char* parkedcall = "ParkedCall" [static]

Definition at line 419 of file features.c.

int parkeddynamic = 0 [static]

Enable creation of parkinglots dynamically

Definition at line 588 of file features.c.

Referenced by ast_masq_park_call_exten(), ast_park_call_exten(), park_call_exec(), park_space_reserve(), process_config(), and xfer_park_call_helper().

int parkedplay = 0 [static]

Who to play courtesytone to when someone picks up a parked call.

Definition at line 587 of file features.c.

Referenced by parked_call_exec(), and process_config().

char parking_con_dial[] = "park-dial" [static]

Context for parking dialback to parker.

Note:
The need for the context is a KLUDGE.
Todo:
Might be able to eliminate the parking_con_dial context kludge by running app_dial directly in its own thread to simulate a PBX.

Definition at line 603 of file features.c.

Referenced by ast_features_reload(), and manage_parked_call().

pthread_t parking_thread [static]

Definition at line 644 of file features.c.

Referenced by ast_features_init(), and park_call_full().

Initial value:
 {
   .parkext = DEFAULT_PARK_EXTENSION,
   .parkingtime = DEFAULT_PARK_TIME,
}

Default configuration for normal parking lots.

Definition at line 5394 of file features.c.

Default configuration for default parking lot.

Definition at line 5384 of file features.c.

struct ao2_container* parkinglots [static]

The configured parking lots container. Always at least one - the default parking lot.

Definition at line 575 of file features.c.

Referenced by ast_features_init(), build_dialplan_useage_map(), build_parkinglot(), create_dynamic_parkinglot(), do_parking_thread(), find_parkinglot(), handle_feature_show(), handle_parkedcalls(), load_config(), and manager_parking_status().

Initial value:
 {
   .type = "pickup-active",
}

The presence of this datastore on the channel indicates that someone is attemting to pickup or has picked up the channel. The purpose is to prevent a race between two channels attempting to pickup the same channel.

Definition at line 7215 of file features.c.

char pickup_ext[AST_MAX_EXTENSION] [static]

Call pickup extension

Definition at line 421 of file features.c.

Referenced by analog_canmatch_featurecode(), and canmatch_featurecode().

char pickupfailsound[256] [static]

Pickup failure sound

Definition at line 593 of file features.c.

Referenced by ast_pickup_call(), and process_config().

char pickupsound[256] [static]

Pickup sound

Definition at line 592 of file features.c.

Referenced by ast_pickup_call(), and process_config().

char* registrar = "features" [static]
struct ast_app* stopmixmonitor_app = NULL [static]

Definition at line 641 of file features.c.

Referenced by builtin_automixmonitor().

int stopmixmonitor_ok = 1 [static]

Definition at line 642 of file features.c.

Referenced by builtin_automixmonitor().

int transferdigittimeout [static]

Definition at line 610 of file features.c.

Referenced by builtin_atxfer(), builtin_blindtransfer(), and process_config().

char xferfailsound[256] [static]

Call transfer failure sound

Definition at line 591 of file features.c.

Referenced by builtin_atxfer(), and process_config().

char xfersound[256] [static]

Call transfer sound

Definition at line 590 of file features.c.

Referenced by action_bridge(), bridge_exec(), builtin_atxfer(), local_attended_transfer(), and process_config().


Generated on 30 Aug 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1