Sat Apr 26 2014 22:02:38

Asterisk developer's documentation


channel.c File Reference

Channel Management. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include <sys/time.h>
#include <signal.h>
#include <math.h>
#include "asterisk/paths.h"
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/mod_format.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/translate.h"
#include "asterisk/manager.h"
#include "asterisk/cel.h"
#include "asterisk/chanvars.h"
#include "asterisk/linkedlists.h"
#include "asterisk/indications.h"
#include "asterisk/monitor.h"
#include "asterisk/causes.h"
#include "asterisk/callerid.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/transcap.h"
#include "asterisk/devicestate.h"
#include "asterisk/threadstorage.h"
#include "asterisk/slinfactory.h"
#include "asterisk/audiohook.h"
#include "asterisk/framehook.h"
#include "asterisk/timing.h"
#include "asterisk/autochan.h"
#include "asterisk/stringfields.h"
#include "asterisk/global_datastores.h"
#include "asterisk/data.h"
#include "asterisk/channel_internal.h"
#include "asterisk/features.h"
#include "asterisk/test.h"
Include dependency graph for channel.c:

Go to the source code of this file.

Data Structures

struct  ast_channel_iterator
struct  ast_epoll_data
struct  ast_party_id_ies
struct  ast_party_name_ies
struct  ast_party_number_ies
struct  ast_party_subaddress_ies
struct  ast_silence_generator
struct  backends
 the list of registered channel types More...
struct  causes_map
 map AST_CAUSE's to readable string representations More...
struct  chanlist
 List of channel drivers. More...
struct  namedgroup_member
 Named group member structure. More...
struct  plc_ds
struct  set_format_trans_access
struct  tonepair_def
struct  tonepair_state
struct  xfer_masquerade_ds

Defines

#define AST_DEFAULT_EMULATE_DTMF_DURATION   100
#define AST_MIN_DTMF_GAP   45
#define FORMAT   "%-15.15s %-40.40s %-12.12s %-12.12s %-12.12s\n"
#define NUM_CHANNEL_BUCKETS   1567
#define STATE2STR_BUFSIZE   32

Enumerations

enum  {
  AST_CONNECTED_LINE_NUMBER, AST_CONNECTED_LINE_NAME, AST_CONNECTED_LINE_NUMBER_PLAN, AST_CONNECTED_LINE_ID_PRESENTATION,
  AST_CONNECTED_LINE_SOURCE, AST_CONNECTED_LINE_SUBADDRESS, AST_CONNECTED_LINE_SUBADDRESS_TYPE, AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN,
  AST_CONNECTED_LINE_SUBADDRESS_VALID, AST_CONNECTED_LINE_TAG, AST_CONNECTED_LINE_VERSION, AST_CONNECTED_LINE_NAME_VALID,
  AST_CONNECTED_LINE_NAME_CHAR_SET, AST_CONNECTED_LINE_NAME_PRESENTATION, AST_CONNECTED_LINE_NUMBER_VALID, AST_CONNECTED_LINE_NUMBER_PRESENTATION,
  AST_CONNECTED_LINE_PRIV_NUMBER, AST_CONNECTED_LINE_PRIV_NUMBER_PLAN, AST_CONNECTED_LINE_PRIV_NUMBER_VALID, AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION,
  AST_CONNECTED_LINE_PRIV_NAME, AST_CONNECTED_LINE_PRIV_NAME_VALID, AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET, AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION,
  AST_CONNECTED_LINE_PRIV_SUBADDRESS, AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE, AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN, AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID,
  AST_CONNECTED_LINE_PRIV_TAG
}
 Element identifiers for connected line indication frame data. More...
enum  {
  AST_REDIRECTING_FROM_NUMBER, AST_REDIRECTING_FROM_NAME, AST_REDIRECTING_FROM_NUMBER_PLAN, AST_REDIRECTING_FROM_ID_PRESENTATION,
  AST_REDIRECTING_TO_NUMBER, AST_REDIRECTING_TO_NAME, AST_REDIRECTING_TO_NUMBER_PLAN, AST_REDIRECTING_TO_ID_PRESENTATION,
  AST_REDIRECTING_REASON, AST_REDIRECTING_COUNT, AST_REDIRECTING_FROM_SUBADDRESS, AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
  AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_FROM_SUBADDRESS_VALID, AST_REDIRECTING_TO_SUBADDRESS, AST_REDIRECTING_TO_SUBADDRESS_TYPE,
  AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_TO_SUBADDRESS_VALID, AST_REDIRECTING_FROM_TAG, AST_REDIRECTING_TO_TAG,
  AST_REDIRECTING_VERSION, AST_REDIRECTING_FROM_NAME_VALID, AST_REDIRECTING_FROM_NAME_CHAR_SET, AST_REDIRECTING_FROM_NAME_PRESENTATION,
  AST_REDIRECTING_FROM_NUMBER_VALID, AST_REDIRECTING_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_TO_NAME_VALID, AST_REDIRECTING_TO_NAME_CHAR_SET,
  AST_REDIRECTING_TO_NAME_PRESENTATION, AST_REDIRECTING_TO_NUMBER_VALID, AST_REDIRECTING_TO_NUMBER_PRESENTATION, AST_REDIRECTING_ORIG_NUMBER,
  AST_REDIRECTING_ORIG_NUMBER_VALID, AST_REDIRECTING_ORIG_NUMBER_PLAN, AST_REDIRECTING_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_ORIG_NAME,
  AST_REDIRECTING_ORIG_NAME_VALID, AST_REDIRECTING_ORIG_NAME_CHAR_SET, AST_REDIRECTING_ORIG_NAME_PRESENTATION, AST_REDIRECTING_ORIG_SUBADDRESS,
  AST_REDIRECTING_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_ORIG_TAG,
  AST_REDIRECTING_ORIG_REASON, AST_REDIRECTING_PRIV_TO_NUMBER, AST_REDIRECTING_PRIV_TO_NUMBER_PLAN, AST_REDIRECTING_PRIV_TO_NUMBER_VALID,
  AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_TO_NAME, AST_REDIRECTING_PRIV_TO_NAME_VALID, AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET,
  AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION, AST_REDIRECTING_PRIV_TO_SUBADDRESS, AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN,
  AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_TO_TAG, AST_REDIRECTING_PRIV_FROM_NUMBER, AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN,
  AST_REDIRECTING_PRIV_FROM_NUMBER_VALID, AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_FROM_NAME, AST_REDIRECTING_PRIV_FROM_NAME_VALID,
  AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET, AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION, AST_REDIRECTING_PRIV_FROM_SUBADDRESS, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE,
  AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_FROM_TAG, AST_REDIRECTING_PRIV_ORIG_NUMBER,
  AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID, AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN, AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_NAME,
  AST_REDIRECTING_PRIV_ORIG_NAME_VALID, AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET, AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS,
  AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_ORIG_TAG
}
 Element identifiers for redirecting indication frame data. More...

Functions

int __ast_answer (struct ast_channel *chan, unsigned int delay, int cdr_answer)
 Answer a channel, with a selectable delay before returning.
static void __ast_change_name_nolink (struct ast_channel *chan, const char *newname)
 this function simply changes the name of the channel and issues a manager_event with out unlinking and linking the channel from the ao2_container. This should only be used when the channel has already been unlinked from the ao2_container.
struct ast_channel__ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *file, int line, const char *function, const char *name_fmt,...)
 Create a channel structure.
static struct ast_channel
*attribute_malloc 
__ast_channel_alloc_ap (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *file, int line, const char *function, const char *name_fmt, va_list ap)
 Create a new channel structure.
static int __ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clonechan, struct ast_datastore *xfer_ds)
static int __ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after)
static struct ast_frame__ast_read (struct ast_channel *chan, int dropaudio)
struct ast_channel__ast_request_and_dial (const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
 Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.
static void __init_state2str_threadbuf (void)
static void adjust_frame_for_plc (struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore)
static void apply_plc (struct ast_channel *chan, struct ast_frame *frame)
int ast_activate_generator (struct ast_channel *chan, struct ast_generator *gen, void *params)
int ast_active_channels (void)
 returns number of active/allocated channels
int ast_answer (struct ast_channel *chan)
 Answer a channel.
void ast_begin_shutdown (int hangup)
struct ast_formatast_best_codec (struct ast_format_cap *cap, struct ast_format *result)
 Pick the best audio codec.
struct ast_channelast_bridged_channel (struct ast_channel *chan)
 Find bridged channel.
int ast_call (struct ast_channel *chan, const char *addr, int timeout)
 Make a call.
struct ast_channelast_call_forward (struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate)
 Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.
void ast_cancel_shutdown (void)
 Cancel a shutdown in progress.
const char * ast_cause2str (int cause)
 Gives the string form of a given hangup cause.
void ast_change_name (struct ast_channel *chan, const char *newname)
 Change channel name.
struct ast_channelast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *name_fmt,...)
enum ast_bridge_result ast_channel_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc)
 Bridge two channels together.
static int ast_channel_by_exten_cb (void *obj, void *arg, void *data, int flags)
static int ast_channel_by_name_cb (void *obj, void *arg, void *data, int flags)
static int ast_channel_by_uniqueid_cb (void *obj, void *arg, void *data, int flags)
struct ast_channelast_channel_callback (ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
 Call a function with every active channel.
int ast_channel_cc_params_init (struct ast_channel *chan, const struct ast_cc_config_params *base_params)
 Set up datastore with CCSS parameters for a channel.
static void ast_channel_change_linkedid (struct ast_channel *chan, const char *linkedid)
void ast_channel_clear_softhangup (struct ast_channel *chan, int flag)
 Clear a set of softhangup flags from a channel.
static int ast_channel_cmp_cb (void *obj, void *arg, int flags)
int ast_channel_cmpwhentohangup (struct ast_channel *chan, time_t offset)
 Compare a offset with the settings of when to hang a channel up.
int ast_channel_cmpwhentohangup_tv (struct ast_channel *chan, struct timeval offset)
 Compare a offset with when to hangup channel.
int ast_channel_connected_line_macro (struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int is_frame)
 Run a connected line interception macro and update a channel's connected line information.
int ast_channel_connected_line_sub (struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int is_frame)
 Run a connected line interception subroutine and update a channel's connected line information.
int ast_channel_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore)
 Add a datastore to a channel.
struct ast_datastoreast_channel_datastore_alloc (const struct ast_datastore_info *info, const char *uid)
 Create a channel data store object.
struct ast_datastoreast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
 Find a datastore on a channel.
int ast_channel_datastore_free (struct ast_datastore *datastore)
 Free a channel data store object.
int ast_channel_datastore_inherit (struct ast_channel *from, struct ast_channel *to)
 Inherit datastores from a parent to a child.
int ast_channel_datastore_remove (struct ast_channel *chan, struct ast_datastore *datastore)
 Remove a datastore from a channel.
int ast_channel_defer_dtmf (struct ast_channel *chan)
 Set defer DTMF flag on channel.
static void ast_channel_destructor (void *obj)
 Free a channel structure.
int ast_channel_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Bridge two channels together (early)
struct ast_channelast_channel_get_by_exten (const char *exten, const char *context)
 Find a channel by extension and context.
struct ast_channelast_channel_get_by_name (const char *name)
 Find a channel by name.
struct ast_channelast_channel_get_by_name_prefix (const char *name, size_t name_len)
 Find a channel by a name prefix.
int ast_channel_get_cc_agent_type (struct ast_channel *chan, char *agent_type, size_t size)
 Find the appropriate CC agent type to use given a channel.
struct ast_cc_config_paramsast_channel_get_cc_config_params (struct ast_channel *chan)
 Get the CCSS parameters from a channel.
int ast_channel_get_device_name (struct ast_channel *chan, char *device_name, size_t name_buffer_length)
 Get a device name given its channel structure.
void ast_channel_hangupcause_hash_set (struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
 Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel.
static int ast_channel_hash_cb (const void *obj, const int flags)
void ast_channel_inherit_variables (const struct ast_channel *parent, struct ast_channel *child)
 Inherits channel variable from parent to child channel.
struct ast_channel_iteratorast_channel_iterator_all_new (void)
 Create a new channel iterator.
struct ast_channel_iteratorast_channel_iterator_by_exten_new (const char *exten, const char *context)
 Create a new channel iterator based on extension.
struct ast_channel_iteratorast_channel_iterator_by_name_new (const char *name, size_t name_len)
 Create a new channel iterator based on name.
struct ast_channel_iteratorast_channel_iterator_destroy (struct ast_channel_iterator *i)
 Destroy a channel iterator.
struct ast_channelast_channel_iterator_next (struct ast_channel_iterator *i)
 Get the next channel for a channel iterator.
int ast_channel_make_compatible (struct ast_channel *chan, struct ast_channel *peer)
 Makes two channel formats compatible.
static int ast_channel_make_compatible_helper (struct ast_channel *from, struct ast_channel *to)
 Set up translation from one channel to another.
int ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clone)
 Weird function made for call transfers.
int ast_channel_queryoption (struct ast_channel *chan, int option, void *data, int *datalen, int block)
 Checks the value of an option.
void ast_channel_queue_connected_line_update (struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Queue a connected line update frame on a channel.
void ast_channel_queue_redirecting_update (struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Queue a redirecting update frame on a channel.
const char * ast_channel_reason2str (int reason)
 return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
int ast_channel_redirecting_macro (struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame)
 Run a redirecting interception macro and update a channel's redirecting information.
int ast_channel_redirecting_sub (struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
 Run a redirecting interception subroutine and update a channel's redirecting information.
int ast_channel_register (const struct ast_channel_tech *tech)
 Register a new telephony channel in Asterisk.
struct ast_channelast_channel_release (struct ast_channel *chan)
 Unlink and release reference to a channel.
int ast_channel_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen)
 Sends HTML on given channel Send HTML or URL on link.
int ast_channel_sendurl (struct ast_channel *chan, const char *url)
 Sends a URL on a given link Send URL on link.
void ast_channel_set_caller (struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
 Set the caller id information in the Asterisk channel.
void ast_channel_set_caller_event (struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
 Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name or number changed.
void ast_channel_set_connected_line (struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Set the connected line information in the Asterisk channel.
void ast_channel_set_fd (struct ast_channel *chan, int which, int fd)
void ast_channel_set_linkgroup (struct ast_channel *chan, struct ast_channel *peer)
 Propagate the oldest linkedid between associated channels.
void ast_channel_set_redirecting (struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Set the redirecting id information in the Asterisk channel.
int ast_channel_setoption (struct ast_channel *chan, int option, void *data, int datalen, int block)
 Sets an option on a channel.
void ast_channel_setwhentohangup (struct ast_channel *chan, time_t offset)
 Set when to hang a channel up.
void ast_channel_setwhentohangup_tv (struct ast_channel *chan, struct timeval offset)
 Set when to hangup channel.
static int ast_channel_softhangup_cb (void *obj, void *arg, int flags)
void ast_channel_softhangup_withcause_locked (struct ast_channel *chan, int causecode)
 Lock the given channel, then request softhangup on the channel with the given causecode.
struct ast_silence_generatorast_channel_start_silence_generator (struct ast_channel *chan)
 Starts a silence generator on the given channel.
void ast_channel_stop_silence_generator (struct ast_channel *chan, struct ast_silence_generator *state)
 Stops a previously-started silence generator on the given channel.
int ast_channel_supports_html (struct ast_channel *chan)
 Checks for HTML support on a channel.
int ast_channel_transfer_masquerade (struct ast_channel *target_chan, const struct ast_party_connected_line *target_id, int target_held, struct ast_channel *transferee_chan, const struct ast_party_connected_line *transferee_id, int transferee_held)
 Setup a masquerade to transfer a call.
void ast_channel_undefer_dtmf (struct ast_channel *chan)
 Unset defer DTMF flag on channel.
void ast_channel_unlink (struct ast_channel *chan)
 Remove a channel from the global channels container.
void ast_channel_unregister (const struct ast_channel_tech *tech)
 Unregister channel driver.
void ast_channel_update_connected_line (struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Indicate that the connected line information has changed.
void ast_channel_update_redirecting (struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Indicate that the redirecting id has changed.
void ast_channels_init (void)
struct ast_variableast_channeltype_list (void)
 return an ast_variable list of channeltypes
int ast_check_hangup (struct ast_channel *chan)
 Checks to see if a channel is needing hang up.
int ast_check_hangup_locked (struct ast_channel *chan)
int ast_connected_line_build_data (unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
 Build the connected line information data frame.
void ast_connected_line_copy_from_caller (struct ast_party_connected_line *dest, const struct ast_party_caller *src)
 Copy the caller information to the connected line information.
void ast_connected_line_copy_to_caller (struct ast_party_caller *dest, const struct ast_party_connected_line *src)
 Copy the connected line information to the caller information.
int ast_connected_line_parse_data (const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
 Parse connected line indication frame data.
void ast_deactivate_generator (struct ast_channel *chan)
int ast_do_masquerade (struct ast_channel *original)
 Masquerade a channel.
struct ast_channelast_dummy_channel_alloc (void)
 Create a fake channel structure.
static void ast_dummy_channel_destructor (void *obj)
 Free a dummy channel structure.
static enum ast_bridge_result ast_generic_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc)
struct ast_channel_techast_get_channel_tech (const char *name)
 Get handle to channel driver based on name.
ast_group_t ast_get_group (const char *s)
struct ast_namedgroups * ast_get_namedgroups (const char *s)
 Create an ast_namedgroups set with group names from comma separated string.
int ast_hangup (struct ast_channel *chan)
 Hangup a channel.
int ast_indicate (struct ast_channel *chan, int condition)
 Indicates condition of channel.
int ast_indicate_data (struct ast_channel *chan, int _condition, const void *data, size_t datalen)
 Indicates condition of channel, with payload.
void ast_install_music_functions (int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *))
int ast_internal_timing_enabled (struct ast_channel *chan)
 Check if the channel can run in internal timing mode.
int ast_is_deferrable_frame (const struct ast_frame *frame)
 Should we keep this frame for later?
void ast_moh_cleanup (struct ast_channel *chan)
int ast_moh_start (struct ast_channel *chan, const char *mclass, const char *interpclass)
 Turn on music on hold on a given channel.
void ast_moh_stop (struct ast_channel *chan)
 Turn off music on hold on a given channel.
int ast_namedgroups_intersect (struct ast_namedgroups *a, struct ast_namedgroups *b)
 Return TRUE if group a and b contain at least one common groupname.
void ast_party_caller_copy (struct ast_party_caller *dest, const struct ast_party_caller *src)
 Copy the source caller information to the destination caller.
void ast_party_caller_free (struct ast_party_caller *doomed)
 Destroy the caller party contents.
void ast_party_caller_init (struct ast_party_caller *init)
 Initialize the given caller structure.
void ast_party_caller_set (struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update)
 Set the caller information based on another caller source.
void ast_party_caller_set_init (struct ast_party_caller *init, const struct ast_party_caller *guide)
 Initialize the given caller structure using the given guide for a set update operation.
void ast_party_connected_line_collect_caller (struct ast_party_connected_line *connected, struct ast_party_caller *caller)
 Collect the caller party information into a connected line structure.
void ast_party_connected_line_copy (struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
 Copy the source connected line information to the destination connected line.
void ast_party_connected_line_free (struct ast_party_connected_line *doomed)
 Destroy the connected line information contents.
void ast_party_connected_line_init (struct ast_party_connected_line *init)
 Initialize the given connected line structure.
void ast_party_connected_line_set (struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update)
 Set the connected line information based on another connected line source.
void ast_party_connected_line_set_init (struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
 Initialize the given connected line structure using the given guide for a set update operation.
void ast_party_dialed_copy (struct ast_party_dialed *dest, const struct ast_party_dialed *src)
 Copy the source dialed party information to the destination dialed party.
void ast_party_dialed_free (struct ast_party_dialed *doomed)
 Destroy the dialed party contents.
void ast_party_dialed_init (struct ast_party_dialed *init)
 Initialize the given dialed structure.
void ast_party_dialed_set (struct ast_party_dialed *dest, const struct ast_party_dialed *src)
 Set the dialed information based on another dialed source.
void ast_party_dialed_set_init (struct ast_party_dialed *init, const struct ast_party_dialed *guide)
 Initialize the given dialed structure using the given guide for a set update operation.
void ast_party_id_copy (struct ast_party_id *dest, const struct ast_party_id *src)
 Copy the source party id information to the destination party id.
void ast_party_id_free (struct ast_party_id *doomed)
 Destroy the party id contents.
void ast_party_id_init (struct ast_party_id *init)
 Initialize the given party id structure.
void ast_party_id_invalidate (struct ast_party_id *id)
 Invalidate all components of the given party id.
struct ast_party_id ast_party_id_merge (struct ast_party_id *base, struct ast_party_id *overlay)
 Merge a given party id into another given party id.
void ast_party_id_merge_copy (struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay)
 Copy a merge of a given party id into another given party id to a given destination party id.
int ast_party_id_presentation (const struct ast_party_id *id)
 Determine the overall presentation value for the given party.
void ast_party_id_reset (struct ast_party_id *id)
 Destroy and initialize the given party id structure.
void ast_party_id_set (struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update)
 Set the source party id information into the destination party id.
void ast_party_id_set_init (struct ast_party_id *init, const struct ast_party_id *guide)
 Initialize the given party id structure using the given guide for a set update operation.
void ast_party_name_copy (struct ast_party_name *dest, const struct ast_party_name *src)
 Copy the source party name information to the destination party name.
void ast_party_name_free (struct ast_party_name *doomed)
 Destroy the party name contents.
void ast_party_name_init (struct ast_party_name *init)
 Initialize the given name structure.
void ast_party_name_set (struct ast_party_name *dest, const struct ast_party_name *src)
 Set the source party name information into the destination party name.
void ast_party_name_set_init (struct ast_party_name *init, const struct ast_party_name *guide)
 Initialize the given party name structure using the given guide for a set update operation.
void ast_party_number_copy (struct ast_party_number *dest, const struct ast_party_number *src)
 Copy the source party number information to the destination party number.
void ast_party_number_free (struct ast_party_number *doomed)
 Destroy the party number contents.
void ast_party_number_init (struct ast_party_number *init)
 Initialize the given number structure.
void ast_party_number_set (struct ast_party_number *dest, const struct ast_party_number *src)
 Set the source party number information into the destination party number.
void ast_party_number_set_init (struct ast_party_number *init, const struct ast_party_number *guide)
 Initialize the given party number structure using the given guide for a set update operation.
void ast_party_redirecting_copy (struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
 Copy the source redirecting information to the destination redirecting.
void ast_party_redirecting_free (struct ast_party_redirecting *doomed)
 Destroy the redirecting information contents.
void ast_party_redirecting_init (struct ast_party_redirecting *init)
 Initialize the given redirecting structure.
void ast_party_redirecting_set (struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update)
 Set the redirecting information based on another redirecting source.
void ast_party_redirecting_set_init (struct ast_party_redirecting *init, const struct ast_party_redirecting *guide)
 Initialize the given redirecting id structure using the given guide for a set update operation.
void ast_party_subaddress_copy (struct ast_party_subaddress *dest, const struct ast_party_subaddress *src)
 Copy the source party subaddress information to the destination party subaddress.
void ast_party_subaddress_free (struct ast_party_subaddress *doomed)
 Destroy the party subaddress contents.
void ast_party_subaddress_init (struct ast_party_subaddress *init)
 Initialize the given subaddress structure.
void ast_party_subaddress_set (struct ast_party_subaddress *dest, const struct ast_party_subaddress *src)
 Set the source party subaddress information into the destination party subaddress.
void ast_party_subaddress_set_init (struct ast_party_subaddress *init, const struct ast_party_subaddress *guide)
 Initialize the given party subaddress structure using the given guide for a set update operation.
int ast_plc_reload (void)
 Reload genericplc configuration value from codecs.conf.
void ast_poll_channel_add (struct ast_channel *chan0, struct ast_channel *chan1)
void ast_poll_channel_del (struct ast_channel *chan0, struct ast_channel *chan1)
int ast_pre_call (struct ast_channel *chan, const char *sub_args)
 Execute a Gosub call on the channel before a call is placed.
char * ast_print_group (char *buf, int buflen, ast_group_t group)
 Print call group and pickup group ---.
char * ast_print_namedgroups (struct ast_str **buf, struct ast_namedgroups *group)
 Print named call groups and named pickup groups.
int ast_prod (struct ast_channel *chan)
 Send empty audio to prime a channel driver.
int ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control)
 Queue a control frame.
int ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
 Queue a control frame with payload.
int ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin)
 Queue one or more frames to a channel's frame queue.
int ast_queue_frame_head (struct ast_channel *chan, struct ast_frame *fin)
 Queue one or more frames to the head of a channel's frame queue.
int ast_queue_hangup (struct ast_channel *chan)
 Queue a hangup frame for channel.
int ast_queue_hangup_with_cause (struct ast_channel *chan, int cause)
 Queue a hangup frame for channel.
int ast_raw_answer (struct ast_channel *chan, int cdr_answer)
 Answer a channel.
struct ast_frameast_read (struct ast_channel *chan)
 Reads a frame.
static void ast_read_generator_actions (struct ast_channel *chan, struct ast_frame *f)
struct ast_frameast_read_noaudio (struct ast_channel *chan)
 Reads a frame, returning AST_FRAME_NULL frame if audio.
int ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders)
 Reads multiple digits.
int ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd)
int ast_recvchar (struct ast_channel *chan, int timeout)
 Receives a text character from a channel.
char * ast_recvtext (struct ast_channel *chan, int timeout)
 Receives a text string from a channel Read a string of text from a channel.
int ast_redirecting_build_data (unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
 Build the redirecting id data frame.
int ast_redirecting_parse_data (const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting)
 Parse redirecting indication frame data.
struct ast_namedgroups * ast_ref_namedgroups (struct ast_namedgroups *groups)
struct ast_channelast_request (const char *type, struct ast_format_cap *request_cap, const struct ast_channel *requestor, const char *addr, int *cause)
 Requests a channel.
struct ast_channelast_request_and_dial (const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr, int timeout, int *outstate, const char *cidnum, const char *cidname)
 Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.
int ast_safe_sleep (struct ast_channel *chan, int ms)
 Wait, look for hangups.
int ast_safe_sleep_conditional (struct ast_channel *chan, int timeout_ms, int(*cond)(void *), void *data)
 Wait, look for hangups and condition arg.
int ast_say_character_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
 function to pronounce character and phonetic strings
int ast_say_digit_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
 says digits of a string
int ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang)
 says digits
int ast_say_digits_full (struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd)
 Same as ast_say_digits() with audiofd for received audio and returns 1 on ctrlfd being readable.
int ast_say_enumeration (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
 says an enumeration
int ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
 says a number
int ast_say_phonetic_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
int ast_senddigit (struct ast_channel *chan, char digit, unsigned int duration)
 Send a DTMF digit to a channel.
int ast_senddigit_begin (struct ast_channel *chan, char digit)
 Send a DTMF digit to a channel.
int ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration)
 Send a DTMF digit to a channel.
int ast_sendtext (struct ast_channel *chan, const char *text)
 Sends text to a channel.
void ast_set_callerid (struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
 Set caller ID number, name and ANI and generate AMI event.
void ast_set_hangupsource (struct ast_channel *chan, const char *source, int force)
 Set the source of the hangup in this channel and it's bridge.
static void ast_set_owners_and_peers (struct ast_channel *chan1, struct ast_channel *chan2)
void ast_set_party_id_all (struct ast_set_party_id *update_id)
 Set the update marker to update all information of a corresponding party id.
int ast_set_read_format (struct ast_channel *chan, struct ast_format *format)
 Sets read format on channel chan.
int ast_set_read_format_by_id (struct ast_channel *chan, enum ast_format_id id)
 Sets read format on channel chan by id.
int ast_set_read_format_from_cap (struct ast_channel *chan, struct ast_format_cap *cap)
 Sets read format on channel chan from capabilities Set read format for channel to whichever component of "format" is best.
void ast_set_variables (struct ast_channel *chan, struct ast_variable *vars)
 adds a list of channel variables to a channel
int ast_set_write_format (struct ast_channel *chan, struct ast_format *format)
 Sets write format on channel chan.
int ast_set_write_format_by_id (struct ast_channel *chan, enum ast_format_id id)
 Sets write format on channel chan.
int ast_set_write_format_from_cap (struct ast_channel *chan, struct ast_format_cap *cap)
 Sets write format on channel chan Set write format for channel to whichever component of "format" is best.
int ast_setstate (struct ast_channel *chan, enum ast_channel_state state)
 Change the state of a channel.
int ast_settimeout (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data)
 Enable or disable timer ticks for a channel.
int ast_settimeout_full (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data, unsigned int is_ao2_obj)
int ast_shutting_down (void)
 Returns non-zero if Asterisk is being shut down.
int ast_softhangup (struct ast_channel *chan, int cause)
 Softly hangup a channel, lock.
int ast_softhangup_nolock (struct ast_channel *chan, int cause)
 Softly hangup a channel, don't lock.
const char * ast_state2str (enum ast_channel_state state)
 Gives the string form of a given channel state.
int ast_str2cause (const char *name)
 Convert a symbolic hangup cause to number.
int ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
int ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
void ast_tonepair_stop (struct ast_channel *chan)
int ast_transfer (struct ast_channel *chan, char *dest)
 Transfer a call to dest, if the channel supports transfer.
char * ast_transfercapability2str (int transfercapability)
 Gives the string form of a given transfer capability.
int ast_undestroyed_channels (void)
void ast_uninstall_music_functions (void)
struct ast_namedgroups * ast_unref_namedgroups (struct ast_namedgroups *groups)
int ast_waitfor (struct ast_channel *c, int ms)
 Wait for input on a channel.
struct ast_channelast_waitfor_n (struct ast_channel **c, int n, int *ms)
 Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.
int ast_waitfor_n_fd (int *fds, int n, int *ms, int *exception)
 Wait for x amount of time on a file descriptor to have input.
struct ast_channelast_waitfor_nandfds (struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
 Wait for x amount of time on a file descriptor to have input.
int ast_waitfordigit (struct ast_channel *c, int ms)
 Waits for a digit.
int ast_waitfordigit_full (struct ast_channel *c, int timeout_ms, int audiofd, int cmdfd)
 Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
int ast_write (struct ast_channel *chan, struct ast_frame *fr)
 Write a frame to a channel This function writes the given frame to the indicated channel.
int ast_write_video (struct ast_channel *chan, struct ast_frame *fr)
 Write video frame to a channel This function writes the given frame to the indicated channel.
static void bridge_play_sounds (struct ast_channel *c0, struct ast_channel *c1)
static void bridge_playfile (struct ast_channel *chan, struct ast_channel *peer, const char *sound, int remain)
static int calc_monitor_jump (int samples, int sample_rate, int seek_rate)
 calculates the number of samples to jump forward with in a monitor stream.
static void call_forward_inherit (struct ast_channel *new_chan, struct ast_channel *parent, struct ast_channel *orig)
static void * channel_cc_params_copy (void *data)
static void channel_cc_params_destroy (void *data)
const char * channelreloadreason2txt (enum channelreloadreason reason)
 Convert enum channelreloadreason to text string for manager event.
static void channels_shutdown (void)
static void clone_variables (struct ast_channel *original, struct ast_channel *clonechan)
 Clone channel variables from 'clone' channel into 'original' channel.
static char * complete_channeltypes (struct ast_cli_args *a)
static int data_channels_provider_handler (const struct ast_data_search *search, struct ast_data *root)
static int data_channeltypes_provider_handler (const struct ast_data_search *search, struct ast_data *data_root)
static void destroy_hooks (struct ast_channel *chan)
static void free_translation (struct ast_channel *clonechan)
static int generator_force (const void *data)
static void generator_write_format_change (struct ast_channel *chan)
static void handle_cause (int cause, int *outstate)
static char * handle_cli_core_show_channeltype (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show details about a channel driver - CLI command.
static char * handle_cli_core_show_channeltypes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show channel types - CLI command.
static int internal_deactivate_generator (struct ast_channel *chan, void *generator)
static int attribute_const is_visible_indication (enum ast_control_frame_type condition)
static struct ast_framekill_exception (struct ast_channel *chan)
static int kill_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
static int kill_hangup (struct ast_channel *chan)
static struct ast_framekill_read (struct ast_channel *chan)
static int kill_write (struct ast_channel *chan, struct ast_frame *frame)
static void manager_bridge_event (int onoff, int type, struct ast_channel *c0, struct ast_channel *c1)
 Send manager event for bridge link and unlink events.
static void masquerade_colp_transfer (struct ast_channel *transferee, struct xfer_masquerade_ds *colp)
static int namedgroup_cmp_cb (void *obj, void *arg, int flags)
 Comparison function used for named group container.
static int namedgroup_hash_cb (const void *obj, const int flags)
 Hashing function used for named group container.
static int namedgroup_match (void *obj, void *arg, int flags)
static const char * oldest_linkedid (const char *a, const char *b)
static void party_connected_line_copy_transfer (struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
static int party_id_build_data (unsigned char *data, size_t datalen, const struct ast_party_id *id, const char *label, const struct ast_party_id_ies *ies, const struct ast_set_party_id *update)
static int party_name_build_data (unsigned char *data, size_t datalen, const struct ast_party_name *name, const char *label, const struct ast_party_name_ies *ies)
static int party_number_build_data (unsigned char *data, size_t datalen, const struct ast_party_number *number, const char *label, const struct ast_party_number_ies *ies)
static int party_subaddress_build_data (unsigned char *data, size_t datalen, const struct ast_party_subaddress *subaddress, const char *label, const struct ast_party_subaddress_ies *ies)
static void plc_ds_destroy (void *data)
static void queue_dtmf_readq (struct ast_channel *chan, struct ast_frame *f)
static void report_new_callerid (struct ast_channel *chan)
static void send_dtmf_event (struct ast_channel *chan, const char *direction, const char digit, const char *begin, const char *end)
static int set_format (struct ast_channel *chan, struct ast_format_cap *cap_set, struct ast_format *rawformat, struct ast_format *format, const struct set_format_trans_access *trans, const int direction)
static int set_security_requirements (const struct ast_channel *requestor, struct ast_channel *out)
static int should_skip_dtmf (struct ast_channel *chan)
 Determine whether or not we should ignore DTMF in the readq.
static void * silence_generator_alloc (struct ast_channel *chan, void *data)
static int silence_generator_generate (struct ast_channel *chan, void *data, int len, int samples)
static void silence_generator_release (struct ast_channel *chan, void *data)
static void * tonepair_alloc (struct ast_channel *chan, void *params)
static int tonepair_generator (struct ast_channel *chan, void *data, int len, int samples)
static void tonepair_release (struct ast_channel *chan, void *params)
static void update_bridge_vars (struct ast_channel *c0, struct ast_channel *c1)
static void xfer_ds_destroy (void *data)

Variables

struct ast_channel_tech ast_kill_tech
 Kill the channel channel driver technology descriptor.
static void(* ast_moh_cleanup_ptr )(struct ast_channel *) = NULL
static int(* ast_moh_start_ptr )(struct ast_channel *, const char *, const char *) = NULL
static void(* ast_moh_stop_ptr )(struct ast_channel *) = NULL
static struct backends backends
static struct causes_map causes []
static struct ast_datastore_info cc_channel_datastore_info
static int chancount
static struct ast_data_entry channel_providers []
static struct ao2_containerchannels
 All active channels on the system.
static struct ast_data_handler channels_provider
static struct ast_data_handler channeltypes_provider
static struct ast_cli_entry cli_channel []
unsigned long global_fin
unsigned long global_fout
static struct ast_channel_tech null_tech
static struct ast_datastore_info plc_ds_info
static struct
set_format_trans_access 
set_format_readtrans
static struct
set_format_trans_access 
set_format_writetrans
static int shutting_down
 Prevent new channel allocation if shutting down.
static struct ast_generator silence_generator
static struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , }
static struct ast_generator tonepair
static int uniqueint
static struct ast_datastore_info xfer_ds_info

Detailed Description

Channel Management.

Author:
Mark Spencer <markster@digium.com>

Definition in file channel.c.


Define Documentation

Default amount of time to use when emulating a digit as a begin and end 100ms

Definition at line 115 of file channel.c.

Referenced by __ast_read(), and ast_senddigit().

#define AST_MIN_DTMF_GAP   45

Minimum amount of time between the end of the last digit and the beginning of a new one - 45ms

Definition at line 119 of file channel.c.

Referenced by __ast_read(), and should_skip_dtmf().

#define FORMAT   "%-15.15s %-40.40s %-12.12s %-12.12s %-12.12s\n"
#define NUM_CHANNEL_BUCKETS   1567

Definition at line 149 of file channel.c.

Referenced by ast_channels_init().

#define STATE2STR_BUFSIZE   32

Definition at line 111 of file channel.c.

Referenced by ast_state2str().


Enumeration Type Documentation

anonymous enum

Element identifiers for connected line indication frame data.

Note:
Only add to the end of this enum.
Enumerator:
AST_CONNECTED_LINE_NUMBER 
AST_CONNECTED_LINE_NAME 
AST_CONNECTED_LINE_NUMBER_PLAN 
AST_CONNECTED_LINE_ID_PRESENTATION 
AST_CONNECTED_LINE_SOURCE 
AST_CONNECTED_LINE_SUBADDRESS 
AST_CONNECTED_LINE_SUBADDRESS_TYPE 
AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN 
AST_CONNECTED_LINE_SUBADDRESS_VALID 
AST_CONNECTED_LINE_TAG 
AST_CONNECTED_LINE_VERSION 
AST_CONNECTED_LINE_NAME_VALID 
AST_CONNECTED_LINE_NAME_CHAR_SET 
AST_CONNECTED_LINE_NAME_PRESENTATION 
AST_CONNECTED_LINE_NUMBER_VALID 
AST_CONNECTED_LINE_NUMBER_PRESENTATION 
AST_CONNECTED_LINE_PRIV_NUMBER 
AST_CONNECTED_LINE_PRIV_NUMBER_PLAN 
AST_CONNECTED_LINE_PRIV_NUMBER_VALID 
AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION 
AST_CONNECTED_LINE_PRIV_NAME 
AST_CONNECTED_LINE_PRIV_NAME_VALID 
AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET 
AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION 
AST_CONNECTED_LINE_PRIV_SUBADDRESS 
AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE 
AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN 
AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID 
AST_CONNECTED_LINE_PRIV_TAG 

Definition at line 9284 of file channel.c.

anonymous enum

Element identifiers for redirecting indication frame data.

Note:
Only add to the end of this enum.
Enumerator:
AST_REDIRECTING_FROM_NUMBER 
AST_REDIRECTING_FROM_NAME 
AST_REDIRECTING_FROM_NUMBER_PLAN 
AST_REDIRECTING_FROM_ID_PRESENTATION 
AST_REDIRECTING_TO_NUMBER 
AST_REDIRECTING_TO_NAME 
AST_REDIRECTING_TO_NUMBER_PLAN 
AST_REDIRECTING_TO_ID_PRESENTATION 
AST_REDIRECTING_REASON 
AST_REDIRECTING_COUNT 
AST_REDIRECTING_FROM_SUBADDRESS 
AST_REDIRECTING_FROM_SUBADDRESS_TYPE 
AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_FROM_SUBADDRESS_VALID 
AST_REDIRECTING_TO_SUBADDRESS 
AST_REDIRECTING_TO_SUBADDRESS_TYPE 
AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_TO_SUBADDRESS_VALID 
AST_REDIRECTING_FROM_TAG 
AST_REDIRECTING_TO_TAG 
AST_REDIRECTING_VERSION 
AST_REDIRECTING_FROM_NAME_VALID 
AST_REDIRECTING_FROM_NAME_CHAR_SET 
AST_REDIRECTING_FROM_NAME_PRESENTATION 
AST_REDIRECTING_FROM_NUMBER_VALID 
AST_REDIRECTING_FROM_NUMBER_PRESENTATION 
AST_REDIRECTING_TO_NAME_VALID 
AST_REDIRECTING_TO_NAME_CHAR_SET 
AST_REDIRECTING_TO_NAME_PRESENTATION 
AST_REDIRECTING_TO_NUMBER_VALID 
AST_REDIRECTING_TO_NUMBER_PRESENTATION 
AST_REDIRECTING_ORIG_NUMBER 
AST_REDIRECTING_ORIG_NUMBER_VALID 
AST_REDIRECTING_ORIG_NUMBER_PLAN 
AST_REDIRECTING_ORIG_NUMBER_PRESENTATION 
AST_REDIRECTING_ORIG_NAME 
AST_REDIRECTING_ORIG_NAME_VALID 
AST_REDIRECTING_ORIG_NAME_CHAR_SET 
AST_REDIRECTING_ORIG_NAME_PRESENTATION 
AST_REDIRECTING_ORIG_SUBADDRESS 
AST_REDIRECTING_ORIG_SUBADDRESS_TYPE 
AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_ORIG_SUBADDRESS_VALID 
AST_REDIRECTING_ORIG_TAG 
AST_REDIRECTING_ORIG_REASON 
AST_REDIRECTING_PRIV_TO_NUMBER 
AST_REDIRECTING_PRIV_TO_NUMBER_PLAN 
AST_REDIRECTING_PRIV_TO_NUMBER_VALID 
AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION 
AST_REDIRECTING_PRIV_TO_NAME 
AST_REDIRECTING_PRIV_TO_NAME_VALID 
AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET 
AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION 
AST_REDIRECTING_PRIV_TO_SUBADDRESS 
AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE 
AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID 
AST_REDIRECTING_PRIV_TO_TAG 
AST_REDIRECTING_PRIV_FROM_NUMBER 
AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN 
AST_REDIRECTING_PRIV_FROM_NUMBER_VALID 
AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION 
AST_REDIRECTING_PRIV_FROM_NAME 
AST_REDIRECTING_PRIV_FROM_NAME_VALID 
AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET 
AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID 
AST_REDIRECTING_PRIV_FROM_TAG 
AST_REDIRECTING_PRIV_ORIG_NUMBER 
AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID 
AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN 
AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION 
AST_REDIRECTING_PRIV_ORIG_NAME 
AST_REDIRECTING_PRIV_ORIG_NAME_VALID 
AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET 
AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN 
AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID 
AST_REDIRECTING_PRIV_ORIG_TAG 

Definition at line 9758 of file channel.c.

     {
   AST_REDIRECTING_FROM_NUMBER,
   AST_REDIRECTING_FROM_NAME,
   AST_REDIRECTING_FROM_NUMBER_PLAN,
   AST_REDIRECTING_FROM_ID_PRESENTATION,/* Combined number and name presentation. */
   AST_REDIRECTING_TO_NUMBER,
   AST_REDIRECTING_TO_NAME,
   AST_REDIRECTING_TO_NUMBER_PLAN,
   AST_REDIRECTING_TO_ID_PRESENTATION,/* Combined number and name presentation. */
   AST_REDIRECTING_REASON,
   AST_REDIRECTING_COUNT,
   AST_REDIRECTING_FROM_SUBADDRESS,
   AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
   AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN,
   AST_REDIRECTING_FROM_SUBADDRESS_VALID,
   AST_REDIRECTING_TO_SUBADDRESS,
   AST_REDIRECTING_TO_SUBADDRESS_TYPE,
   AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN,
   AST_REDIRECTING_TO_SUBADDRESS_VALID,
   AST_REDIRECTING_FROM_TAG,
   AST_REDIRECTING_TO_TAG,
   AST_REDIRECTING_VERSION,
   /*
    * No more party id combined number and name presentation values
    * need to be created.
    */
   AST_REDIRECTING_FROM_NAME_VALID,
   AST_REDIRECTING_FROM_NAME_CHAR_SET,
   AST_REDIRECTING_FROM_NAME_PRESENTATION,
   AST_REDIRECTING_FROM_NUMBER_VALID,
   AST_REDIRECTING_FROM_NUMBER_PRESENTATION,
   AST_REDIRECTING_TO_NAME_VALID,
   AST_REDIRECTING_TO_NAME_CHAR_SET,
   AST_REDIRECTING_TO_NAME_PRESENTATION,
   AST_REDIRECTING_TO_NUMBER_VALID,
   AST_REDIRECTING_TO_NUMBER_PRESENTATION,
   AST_REDIRECTING_ORIG_NUMBER,
   AST_REDIRECTING_ORIG_NUMBER_VALID,
   AST_REDIRECTING_ORIG_NUMBER_PLAN,
   AST_REDIRECTING_ORIG_NUMBER_PRESENTATION,
   AST_REDIRECTING_ORIG_NAME,
   AST_REDIRECTING_ORIG_NAME_VALID,
   AST_REDIRECTING_ORIG_NAME_CHAR_SET,
   AST_REDIRECTING_ORIG_NAME_PRESENTATION,
   AST_REDIRECTING_ORIG_SUBADDRESS,
   AST_REDIRECTING_ORIG_SUBADDRESS_TYPE,
   AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN,
   AST_REDIRECTING_ORIG_SUBADDRESS_VALID,
   AST_REDIRECTING_ORIG_TAG,
   AST_REDIRECTING_ORIG_REASON,
   AST_REDIRECTING_PRIV_TO_NUMBER,
   AST_REDIRECTING_PRIV_TO_NUMBER_PLAN,
   AST_REDIRECTING_PRIV_TO_NUMBER_VALID,
   AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION,
   AST_REDIRECTING_PRIV_TO_NAME,
   AST_REDIRECTING_PRIV_TO_NAME_VALID,
   AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET,
   AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION,
   AST_REDIRECTING_PRIV_TO_SUBADDRESS,
   AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE,
   AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN,
   AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID,
   AST_REDIRECTING_PRIV_TO_TAG,
   AST_REDIRECTING_PRIV_FROM_NUMBER,
   AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN,
   AST_REDIRECTING_PRIV_FROM_NUMBER_VALID,
   AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION,
   AST_REDIRECTING_PRIV_FROM_NAME,
   AST_REDIRECTING_PRIV_FROM_NAME_VALID,
   AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET,
   AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION,
   AST_REDIRECTING_PRIV_FROM_SUBADDRESS,
   AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE,
   AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN,
   AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID,
   AST_REDIRECTING_PRIV_FROM_TAG,
   AST_REDIRECTING_PRIV_ORIG_NUMBER,
   AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID,
   AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN,
   AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION,
   AST_REDIRECTING_PRIV_ORIG_NAME,
   AST_REDIRECTING_PRIV_ORIG_NAME_VALID,
   AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET,
   AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION,
   AST_REDIRECTING_PRIV_ORIG_SUBADDRESS,
   AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE,
   AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN,
   AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID,
   AST_REDIRECTING_PRIV_ORIG_TAG,
};

Function Documentation

int __ast_answer ( struct ast_channel chan,
unsigned int  delay,
int  cdr_answer 
)

Answer a channel, with a selectable delay before returning.

Parameters:
chanchannel to answer
delaymaximum amount of time to wait for incoming media
cdr_answerflag to control whether any associated CDR should be marked as 'answered'

This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.
This function will wait up to 'delay' milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow. If 'delay' is less than 500, the function will wait up to 500 milliseconds.
Return values:
0on success
non-zeroon failure

Definition at line 2949 of file channel.c.

References ast_channel_lock, ast_channel_name(), ast_channel_unlock, AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_log(), ast_queue_frame_head(), ast_raw_answer(), ast_read(), ast_remaining_ms(), AST_STATE_RING, AST_STATE_RINGING, ast_tvnow(), ast_waitfor(), errno, frames, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, MAX, and ast_frame::subclass.

Referenced by ast_answer(), pbx_builtin_answer(), and pbx_builtin_incomplete().

{
   int res = 0;
   enum ast_channel_state old_state;

   old_state = ast_channel_state(chan);
   if ((res = ast_raw_answer(chan, cdr_answer))) {
      return res;
   }

   switch (old_state) {
   case AST_STATE_RINGING:
   case AST_STATE_RING:
      /* wait for media to start flowing, but don't wait any longer
       * than 'delay' or 500 milliseconds, whichever is longer
       */
      do {
         AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
         struct ast_frame *cur, *new;
         int timeout_ms = MAX(delay, 500);
         unsigned int done = 0;
         struct timeval start;

         AST_LIST_HEAD_INIT_NOLOCK(&frames);

         start = ast_tvnow();
         for (;;) {
            int ms = ast_remaining_ms(start, timeout_ms);
            ms = ast_waitfor(chan, ms);
            if (ms < 0) {
               ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", ast_channel_name(chan), strerror(errno));
               res = -1;
               break;
            }
            if (ms == 0) {
               ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", ast_channel_name(chan), MAX(delay, 500));
               break;
            }
            cur = ast_read(chan);
            if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
                    (cur->subclass.integer == AST_CONTROL_HANGUP))) {
               if (cur) {
                  ast_frfree(cur);
               }
               res = -1;
               ast_debug(2, "Hangup of channel %s detected in answer routine\n", ast_channel_name(chan));
               break;
            }

            if ((new = ast_frisolate(cur)) != cur) {
               ast_frfree(cur);
            }

            AST_LIST_INSERT_HEAD(&frames, new, frame_list);

            /* if a specific delay period was requested, continue
             * until that delay has passed. don't stop just because
             * incoming media has arrived.
             */
            if (delay) {
               continue;
            }

            switch (new->frametype) {
               /* all of these frametypes qualify as 'media' */
            case AST_FRAME_VOICE:
            case AST_FRAME_VIDEO:
            case AST_FRAME_TEXT:
            case AST_FRAME_DTMF_BEGIN:
            case AST_FRAME_DTMF_END:
            case AST_FRAME_IMAGE:
            case AST_FRAME_HTML:
            case AST_FRAME_MODEM:
               done = 1;
               break;
            case AST_FRAME_CONTROL:
            case AST_FRAME_IAX:
            case AST_FRAME_NULL:
            case AST_FRAME_CNG:
               break;
            }

            if (done) {
               break;
            }
         }

         if (res == 0) {
            ast_channel_lock(chan);
            while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
               ast_queue_frame_head(chan, cur);
               ast_frfree(cur);
            }
            ast_channel_unlock(chan);
         }
      } while (0);
      break;
   default:
      break;
   }

   return res;
}
static void __ast_change_name_nolink ( struct ast_channel chan,
const char *  newname 
) [static]

this function simply changes the name of the channel and issues a manager_event with out unlinking and linking the channel from the ao2_container. This should only be used when the channel has already been unlinked from the ao2_container.

Definition at line 6474 of file channel.c.

References ast_channel_name(), ast_channel_name_set(), ast_channel_uniqueid(), ast_manager_event, and EVENT_FLAG_CALL.

Referenced by ast_change_name(), and ast_do_masquerade().

{
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when the name of a channel is changed.</synopsis>
      </managerEventInstance>
   ***/
   ast_manager_event(chan, EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", ast_channel_name(chan), newname, ast_channel_uniqueid(chan));
   ast_channel_name_set(chan, newname);
}
struct ast_channel* __ast_channel_alloc ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const char *  linkedid,
const int  amaflag,
const char *  file,
int  line,
const char *  function,
const char *  name_fmt,
  ... 
) [read]

Create a channel structure.

Since:
1.8
Return values:
NULLfailure
non-NULLsuccessfully allocated channel
Note:
Absolutely _NO_ channel locks should be held before calling this function.
By default, new channels are set to the "s" extension and "default" context.

Definition at line 1179 of file channel.c.

References __ast_channel_alloc_ap().

{
   va_list ap;
   struct ast_channel *result;

   va_start(ap, name_fmt);
   result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
               linkedid, amaflag, file, line, function, name_fmt, ap);
   va_end(ap);

   return result;
}
static struct ast_channel* attribute_malloc __ast_channel_alloc_ap ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const char *  linkedid,
const int  amaflag,
const char *  file,
int  line,
const char *  function,
const char *  name_fmt,
va_list  ap 
) [static, read]

Create a new channel structure.

Definition at line 955 of file channel.c.

References ao2_link, ao2_ref, AST_ALERT_FD, ast_atomic_fetchadd_int(), ast_cdr_alloc(), ast_cdr_init(), ast_cdr_start(), AST_CEL_CHANNEL_START, ast_cel_report_event(), ast_channel_accountcode(), ast_channel_amaflags_set(), ast_channel_autochans(), ast_channel_caller(), ast_channel_cdr(), ast_channel_cdr_set(), ast_channel_connected(), ast_channel_context_set(), ast_channel_creationtime_set(), ast_channel_datastores(), ast_channel_destructor(), ast_channel_dialed(), ast_channel_epfd_set(), ast_channel_exten_set(), ast_channel_fin_set(), ast_channel_fout_set(), ast_channel_internal_alert_readfd(), ast_channel_internal_alertpipe_clear(), ast_channel_internal_alertpipe_init(), ast_channel_internal_alloc, ast_channel_internal_fd_clear_all(), ast_channel_internal_finalize(), ast_channel_linkedid_set(), ast_channel_name(), ast_channel_name_set(), ast_channel_nativeformats_set(), ast_channel_priority_set(), ast_channel_redirecting(), ast_channel_sched_set(), ast_channel_set_fd(), ast_channel_state_set(), ast_channel_streamid_set(), ast_channel_tech_set(), ast_channel_timer(), ast_channel_timer_set(), ast_channel_timingfd(), ast_channel_timingfd_set(), ast_channel_uniqueid(), ast_channel_unref, ast_channel_varshead(), ast_config_AST_SYSTEM_NAME, ast_default_accountcode, ast_default_amaflags, ast_defaultlanguage, ast_format_cap_alloc(), ast_get_channel_tech(), AST_LIST_HEAD_INIT_NOLOCK, ast_log(), ast_manager_event, ast_party_caller_init(), ast_party_connected_line_init(), ast_party_dialed_init(), ast_party_redirecting_init(), ast_pbx_hangup_handler_init(), ast_sched_context_create(), ast_shutting_down(), ast_state2str(), ast_strdup, ast_strlen_zero(), ast_timer_fd(), ast_timer_get_name(), ast_timer_open(), AST_TIMING_FD, ast_tvnow(), channels, EVENT_FLAG_CALL, ast_party_caller::id, LOG_WARNING, name, ast_party_id::name, null_tech, ast_party_id::number, S_OR, ast_party_name::str, ast_party_number::str, chanlist::tech, timer, ast_party_name::valid, and ast_party_number::valid.

Referenced by __ast_channel_alloc(), and ast_channel_alloc().

{
   struct ast_channel *tmp;
   struct varshead *headp;
   char *tech = "", *tech2 = NULL;
   struct ast_format_cap *nativeformats;
   struct ast_sched_context *schedctx;
   struct ast_timer *timer;
   struct timeval now;

   /* If shutting down, don't allocate any new channels */
   if (ast_shutting_down()) {
      ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
      return NULL;
   }

   if (!(tmp = ast_channel_internal_alloc(ast_channel_destructor))) {
      /* Channel structure allocation failure. */
      return NULL;
   }
   if (!(nativeformats = ast_format_cap_alloc())) {
      ao2_ref(tmp, -1);
      /* format capabilities structure allocation failure */
      return NULL;
   }
   ast_channel_nativeformats_set(tmp, nativeformats);

   /*
    * Init file descriptors to unopened state so
    * the destructor can know not to close them.
    */
   ast_channel_timingfd_set(tmp, -1);
   ast_channel_internal_alertpipe_clear(tmp);
   ast_channel_internal_fd_clear_all(tmp);

#ifdef HAVE_EPOLL
   ast_channel_epfd_set(tmp, epoll_create(25));
#endif

   if (!(schedctx = ast_sched_context_create())) {
      ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
      return ast_channel_unref(tmp);
   }
   ast_channel_sched_set(tmp, schedctx);

   ast_party_dialed_init(ast_channel_dialed(tmp));
   ast_party_caller_init(ast_channel_caller(tmp));
   ast_party_connected_line_init(ast_channel_connected(tmp));
   ast_party_redirecting_init(ast_channel_redirecting(tmp));

   if (cid_name) {
      ast_channel_caller(tmp)->id.name.valid = 1;
      ast_channel_caller(tmp)->id.name.str = ast_strdup(cid_name);
      if (!ast_channel_caller(tmp)->id.name.str) {
         return ast_channel_unref(tmp);
      }
   }
   if (cid_num) {
      ast_channel_caller(tmp)->id.number.valid = 1;
      ast_channel_caller(tmp)->id.number.str = ast_strdup(cid_num);
      if (!ast_channel_caller(tmp)->id.number.str) {
         return ast_channel_unref(tmp);
      }
   }

   if ((timer = ast_timer_open())) {
      ast_channel_timer_set(tmp, timer);
      if (strcmp(ast_timer_get_name(ast_channel_timer(tmp)), "timerfd")) {
         needqueue = 0;
      }
      ast_channel_timingfd_set(tmp, ast_timer_fd(ast_channel_timer(tmp)));
   }

   /*
    * This is the last place the channel constructor can fail.
    *
    * The destructor takes advantage of this fact to ensure that the
    * AST_CEL_CHANNEL_END is not posted if we have not posted the
    * AST_CEL_CHANNEL_START yet.
    */

   if (needqueue && ast_channel_internal_alertpipe_init(tmp)) {
      return ast_channel_unref(tmp);
   }

   /* Always watch the alertpipe */
   ast_channel_set_fd(tmp, AST_ALERT_FD, ast_channel_internal_alert_readfd(tmp));
   /* And timing pipe */
   ast_channel_set_fd(tmp, AST_TIMING_FD, ast_channel_timingfd(tmp));

   /* Initial state */
   ast_channel_state_set(tmp, state);

   ast_channel_streamid_set(tmp, -1);

   ast_channel_fin_set(tmp, global_fin);
   ast_channel_fout_set(tmp, global_fout);

   now = ast_tvnow();
   ast_channel_creationtime_set(tmp, &now);

   if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
      ast_channel_uniqueid_build(tmp, "%li.%d", (long) time(NULL),
         ast_atomic_fetchadd_int(&uniqueint, 1));
   } else {
      ast_channel_uniqueid_build(tmp, "%s-%li.%d", ast_config_AST_SYSTEM_NAME,
         (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1));
   }

   if (!ast_strlen_zero(linkedid)) {
      ast_channel_linkedid_set(tmp, linkedid);
   } else {
      ast_channel_linkedid_set(tmp, ast_channel_uniqueid(tmp));
   }

   if (!ast_strlen_zero(name_fmt)) {
      char *slash, *slash2;
      /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
       * And they all use slightly different formats for their name string.
       * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
       * This means, that the stringfields must have a routine that takes the va_lists directly, and
       * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
       * This new function was written so this can be accomplished.
       */
      ast_channel_name_build_va(tmp, name_fmt, ap);
      tech = ast_strdupa(ast_channel_name(tmp));
      if ((slash = strchr(tech, '/'))) {
         if ((slash2 = strchr(slash + 1, '/'))) {
            tech2 = slash + 1;
            *slash2 = '\0';
         }
         *slash = '\0';
      }
   } else {
      /*
       * Start the string with '-' so it becomes an empty string
       * in the destructor.
       */
      ast_channel_name_set(tmp, "-**Unknown**");
   }

   /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */

   /* These 4 variables need to be set up for the cdr_init() to work right */
   if (amaflag) {
      ast_channel_amaflags_set(tmp, amaflag);
   } else {
      ast_channel_amaflags_set(tmp, ast_default_amaflags);
   }

   if (!ast_strlen_zero(acctcode))
      ast_channel_accountcode_set(tmp, acctcode);
   else
      ast_channel_accountcode_set(tmp, ast_default_accountcode);

   ast_channel_context_set(tmp, S_OR(context, "default"));
   ast_channel_exten_set(tmp, S_OR(exten, "s"));
   ast_channel_priority_set(tmp, 1);

   ast_channel_cdr_set(tmp, ast_cdr_alloc());
   ast_cdr_init(ast_channel_cdr(tmp), tmp);
   ast_cdr_start(ast_channel_cdr(tmp));

   ast_atomic_fetchadd_int(&chancount, +1);
   ast_cel_report_event(tmp, AST_CEL_CHANNEL_START, NULL, NULL, NULL);

   headp = ast_channel_varshead(tmp);
   AST_LIST_HEAD_INIT_NOLOCK(headp);

   ast_pbx_hangup_handler_init(tmp);
   AST_LIST_HEAD_INIT_NOLOCK(ast_channel_datastores(tmp));

   AST_LIST_HEAD_INIT_NOLOCK(ast_channel_autochans(tmp));

   ast_channel_language_set(tmp, ast_defaultlanguage);

   ast_channel_tech_set(tmp, &null_tech);

   ao2_link(channels, tmp);

   /*
    * And now, since the channel structure is built, and has its name, let's
    * call the manager event generator with this Newchannel event. This is the
    * proper and correct place to make this call, but you sure do have to pass
    * a lot of data into this func to do it here!
    */
   if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) {
      /*** DOCUMENTATION
         <managerEventInstance>
            <synopsis>Raised when a new channel is created.</synopsis>
            <syntax>
               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newstate']/managerEventInstance/syntax/parameter[@name='ChannelState'])" />
               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newstate']/managerEventInstance/syntax/parameter[@name='ChannelStateDesc'])" />
            </syntax>
         </managerEventInstance>
      ***/
      ast_manager_event(tmp, EVENT_FLAG_CALL, "Newchannel",
         "Channel: %s\r\n"
         "ChannelState: %d\r\n"
         "ChannelStateDesc: %s\r\n"
         "CallerIDNum: %s\r\n"
         "CallerIDName: %s\r\n"
         "AccountCode: %s\r\n"
         "Exten: %s\r\n"
         "Context: %s\r\n"
         "Uniqueid: %s\r\n",
         ast_channel_name(tmp),
         state,
         ast_state2str(state),
         S_OR(cid_num, ""),
         S_OR(cid_name, ""),
         ast_channel_accountcode(tmp),
         S_OR(exten, ""),
         S_OR(context, ""),
         ast_channel_uniqueid(tmp));
   }

   ast_channel_internal_finalize(tmp);
   return tmp;
}
static int __ast_channel_masquerade ( struct ast_channel original,
struct ast_channel clonechan,
struct ast_datastore xfer_ds 
) [static]

Definition at line 6238 of file channel.c.

References ast_bridged_channel(), ast_channel_datastore_add(), ast_channel_flags(), ast_channel_internal_bridged_channel(), ast_channel_lock_both, ast_channel_masq(), ast_channel_masq_set(), ast_channel_masqr(), ast_channel_masqr_set(), ast_channel_name(), ast_channel_tech(), ast_channel_trylock, ast_channel_unlock, ast_debug, AST_FLAG_ZOMBIE, ast_log(), ast_null_frame, ast_queue_frame(), ast_test_flag, and LOG_WARNING.

Referenced by ast_channel_masquerade(), and ast_channel_transfer_masquerade().

{
   int res = -1;
   struct ast_channel *final_orig, *final_clone, *base;

   for (;;) {
      final_orig = original;
      final_clone = clonechan;

      ast_channel_lock_both(original, clonechan);

      if (ast_test_flag(ast_channel_flags(original), AST_FLAG_ZOMBIE)
         || ast_test_flag(ast_channel_flags(clonechan), AST_FLAG_ZOMBIE)) {
         /* Zombies! Run! */
         ast_log(LOG_WARNING,
            "Can't setup masquerade. One or both channels is dead. (%s <-- %s)\n",
            ast_channel_name(original), ast_channel_name(clonechan));
         ast_channel_unlock(clonechan);
         ast_channel_unlock(original);
         return -1;
      }

      /*
       * Each of these channels may be sitting behind a channel proxy
       * (i.e. chan_agent) and if so, we don't really want to
       * masquerade it, but its proxy
       */
      if (ast_channel_internal_bridged_channel(original)
         && (ast_channel_internal_bridged_channel(original) != ast_bridged_channel(original))
         && (ast_channel_internal_bridged_channel(ast_channel_internal_bridged_channel(original)) != original)) {
         final_orig = ast_channel_internal_bridged_channel(original);
      }
      if (ast_channel_internal_bridged_channel(clonechan)
         && (ast_channel_internal_bridged_channel(clonechan) != ast_bridged_channel(clonechan))
         && (ast_channel_internal_bridged_channel(ast_channel_internal_bridged_channel(clonechan)) != clonechan)) {
         final_clone = ast_channel_internal_bridged_channel(clonechan);
      }
      if (ast_channel_tech(final_clone)->get_base_channel
         && (base = ast_channel_tech(final_clone)->get_base_channel(final_clone))) {
         final_clone = base;
      }

      if ((final_orig != original) || (final_clone != clonechan)) {
         /*
          * Lots and lots of deadlock avoidance.  The main one we're
          * competing with is ast_write(), which locks channels
          * recursively, when working with a proxy channel.
          */
         if (ast_channel_trylock(final_orig)) {
            ast_channel_unlock(clonechan);
            ast_channel_unlock(original);

            /* Try again */
            continue;
         }
         if (ast_channel_trylock(final_clone)) {
            ast_channel_unlock(final_orig);
            ast_channel_unlock(clonechan);
            ast_channel_unlock(original);

            /* Try again */
            continue;
         }
         ast_channel_unlock(clonechan);
         ast_channel_unlock(original);
         original = final_orig;
         clonechan = final_clone;

         if (ast_test_flag(ast_channel_flags(original), AST_FLAG_ZOMBIE)
            || ast_test_flag(ast_channel_flags(clonechan), AST_FLAG_ZOMBIE)) {
            /* Zombies! Run! */
            ast_log(LOG_WARNING,
               "Can't setup masquerade. One or both channels is dead. (%s <-- %s)\n",
               ast_channel_name(original), ast_channel_name(clonechan));
            ast_channel_unlock(clonechan);
            ast_channel_unlock(original);
            return -1;
         }
      }
      break;
   }

   if (original == clonechan) {
      ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", ast_channel_name(original));
      ast_channel_unlock(clonechan);
      ast_channel_unlock(original);
      return -1;
   }

   ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n",
      ast_channel_name(clonechan), ast_channel_name(original));

   if (!ast_channel_masqr(original) && !ast_channel_masq(original) && !ast_channel_masq(clonechan) && !ast_channel_masqr(clonechan)) {
      ast_channel_masq_set(original, clonechan);
      ast_channel_masqr_set(clonechan, original);
      if (xfer_ds) {
         ast_channel_datastore_add(original, xfer_ds);
      }
      ast_queue_frame(original, &ast_null_frame);
      ast_queue_frame(clonechan, &ast_null_frame);
      ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", ast_channel_name(clonechan), ast_channel_name(original));
      res = 0;
   } else if (ast_channel_masq(original)) {
      ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
         ast_channel_name(ast_channel_masq(original)), ast_channel_name(original));
   } else if (ast_channel_masqr(original)) {
      /* not yet as a previously planned masq hasn't yet happened */
      ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
         ast_channel_name(original), ast_channel_name(ast_channel_masqr(original)));
   } else if (ast_channel_masq(clonechan)) {
      ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
         ast_channel_name(ast_channel_masq(clonechan)), ast_channel_name(clonechan));
   } else { /* (clonechan->masqr) */
      ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
      ast_channel_name(clonechan), ast_channel_name(ast_channel_masqr(clonechan)));
   }

   ast_channel_unlock(clonechan);
   ast_channel_unlock(original);

   return res;
}
static int __ast_queue_frame ( struct ast_channel chan,
struct ast_frame fin,
int  head,
struct ast_frame after 
) [static]

Definition at line 1234 of file channel.c.

References ast_channel_alert_writable(), ast_channel_alert_write(), ast_channel_blocker(), ast_channel_flags(), ast_channel_lock, ast_channel_name(), ast_channel_readq(), ast_channel_timer(), ast_channel_timingfd(), ast_channel_unlock, AST_CONTROL_END_OF_Q, AST_CONTROL_HANGUP, AST_FLAG_BLOCKING, AST_FRAME_CONTROL, AST_FRAME_NULL, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frdup(), ast_frfree, AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_LIST_AFTER, AST_LIST_INSERT_TAIL, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_test_flag, ast_timer_enable_continuous(), errno, f, frames, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, and ast_frame::subclass.

Referenced by __ast_read(), ast_queue_frame(), and ast_queue_frame_head().

{
   struct ast_frame *f;
   struct ast_frame *cur;
   unsigned int new_frames = 0;
   unsigned int new_voice_frames = 0;
   unsigned int queued_frames = 0;
   unsigned int queued_voice_frames = 0;
   AST_LIST_HEAD_NOLOCK(,ast_frame) frames;

   ast_channel_lock(chan);

   /*
    * Check the last frame on the queue if we are queuing the new
    * frames after it.
    */
   cur = AST_LIST_LAST(ast_channel_readq(chan));
   if (cur && cur->frametype == AST_FRAME_CONTROL && !head && (!after || after == cur)) {
      switch (cur->subclass.integer) {
      case AST_CONTROL_END_OF_Q:
         if (fin->frametype == AST_FRAME_CONTROL
            && fin->subclass.integer == AST_CONTROL_HANGUP) {
            /*
             * Destroy the end-of-Q marker frame so we can queue the hangup
             * frame in its place.
             */
            AST_LIST_REMOVE(ast_channel_readq(chan), cur, frame_list);
            ast_frfree(cur);

            /*
             * This has degenerated to a normal queue append anyway.  Since
             * we just destroyed the last frame in the queue we must make
             * sure that "after" is NULL or bad things will happen.
             */
            after = NULL;
            break;
         }
         /* Fall through */
      case AST_CONTROL_HANGUP:
         /* Don't queue anything. */
         ast_channel_unlock(chan);
         return 0;
      default:
         break;
      }
   }

   /* Build copies of all the new frames and count them */
   AST_LIST_HEAD_INIT_NOLOCK(&frames);
   for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
      if (!(f = ast_frdup(cur))) {
         if (AST_LIST_FIRST(&frames)) {
            ast_frfree(AST_LIST_FIRST(&frames));
         }
         ast_channel_unlock(chan);
         return -1;
      }

      AST_LIST_INSERT_TAIL(&frames, f, frame_list);
      new_frames++;
      if (f->frametype == AST_FRAME_VOICE) {
         new_voice_frames++;
      }
   }

   /* Count how many frames exist on the queue */
   AST_LIST_TRAVERSE(ast_channel_readq(chan), cur, frame_list) {
      queued_frames++;
      if (cur->frametype == AST_FRAME_VOICE) {
         queued_voice_frames++;
      }
   }

   if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) {
      int count = 0;
      ast_log(LOG_WARNING, "Exceptionally long %squeue length queuing to %s\n", queued_frames + new_frames > 128 ? "" : "voice ", ast_channel_name(chan));
      AST_LIST_TRAVERSE_SAFE_BEGIN(ast_channel_readq(chan), cur, frame_list) {
         /* Save the most recent frame */
         if (!AST_LIST_NEXT(cur, frame_list)) {
            break;
         } else if (cur->frametype == AST_FRAME_VOICE || cur->frametype == AST_FRAME_VIDEO || cur->frametype == AST_FRAME_NULL) {
            if (++count > 64) {
               break;
            }
            AST_LIST_REMOVE_CURRENT(frame_list);
            ast_frfree(cur);
         }
      }
      AST_LIST_TRAVERSE_SAFE_END;
   }

   if (after) {
      AST_LIST_INSERT_LIST_AFTER(ast_channel_readq(chan), &frames, after, frame_list);
   } else {
      if (head) {
         AST_LIST_APPEND_LIST(&frames, ast_channel_readq(chan), frame_list);
         AST_LIST_HEAD_INIT_NOLOCK(ast_channel_readq(chan));
      }
      AST_LIST_APPEND_LIST(ast_channel_readq(chan), &frames, frame_list);
   }

   if (ast_channel_alert_writable(chan)) {
      if (ast_channel_alert_write(chan)) {
         ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n",
            ast_channel_name(chan), queued_frames, strerror(errno));
      }
   } else if (ast_channel_timingfd(chan) > -1) {
      ast_timer_enable_continuous(ast_channel_timer(chan));
   } else if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING)) {
      pthread_kill(ast_channel_blocker(chan), SIGURG);
   }

   ast_channel_unlock(chan);

   return 0;
}
static struct ast_frame* __ast_read ( struct ast_channel chan,
int  dropaudio 
) [static, read]
Todo:
XXX It is possible to write a digit to the audiohook twice if the digit was originally read while the channel was in autoservice.

Definition at line 3853 of file channel.c.

References __ast_queue_frame(), ast_control_read_action_payload::action, ao2_ref, AST_ALERT_READ_FATAL, ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), ast_bridged_channel(), AST_CEL_ANSWER, ast_cel_report_event(), ast_channel_alert_write(), ast_channel_audiohooks(), ast_channel_audiohooks_set(), ast_channel_blocker_set(), ast_channel_connected(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_channel_dtmf_digit_to_emulate(), ast_channel_dtmf_digit_to_emulate_set(), ast_channel_dtmf_tv(), ast_channel_dtmf_tv_set(), ast_channel_dtmff(), ast_channel_emulate_dtmf_duration(), ast_channel_emulate_dtmf_duration_set(), ast_channel_fd_isset(), ast_channel_fdno(), ast_channel_fdno_set(), ast_channel_fin(), ast_channel_fin_set(), ast_channel_flags(), ast_channel_framehooks(), ast_channel_generator(), ast_channel_generatordata(), ast_channel_generatordata_set(), ast_channel_hangupcause_set(), ast_channel_insmpl(), ast_channel_insmpl_set(), ast_channel_internal_alert_read(), ast_channel_lock, ast_channel_masq(), ast_channel_monitor(), ast_channel_music_state(), ast_channel_name(), ast_channel_nativeformats(), ast_channel_outsmpl(), ast_channel_readq(), ast_channel_readtrans(), ast_channel_softhangup_internal_flag(), ast_channel_softhangup_internal_flag_add(), ast_channel_tech(), ast_channel_timer(), ast_channel_timingdata(), ast_channel_timingfd(), ast_channel_timingfunc(), ast_channel_unlock, ast_check_hangup(), ast_clear_flag, ast_connected_line_parse_data(), AST_CONTROL_ANSWER, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_END_OF_Q, AST_CONTROL_HANGUP, AST_CONTROL_READ_ACTION, ast_deactivate_generator(), ast_debug, AST_DEFAULT_EMULATE_DTMF_DURATION, ast_do_masquerade(), AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_FLAG_END_DTMF_ONLY, AST_FLAG_EXCEPTION, AST_FLAG_IN_DTMF, AST_FLAG_OUTGOING, AST_FLAG_TIMINGDATA_IS_AO2_OBJ, AST_FLAG_ZOMBIE, ast_format_cap_iscompatible(), ast_format_rate(), AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_NULL, AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO, AST_FRAME_VOICE, ast_framehook_list_read_event(), ast_frfree, AST_GENERATOR_FD, ast_getformatname(), ast_getformatname_multiple(), ast_indicate_data(), AST_JITTERBUFFER_FD, AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MIN_DTMF_GAP, AST_MONITOR_RUNNING, ast_null_frame, ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_queue_control(), ast_queue_frame(), ast_queue_frame_head(), ast_read_generator_actions(), ast_seekstream(), ast_set_flag, ast_setstate(), AST_SOFTHANGUP_DEV, AST_STATE_UP, ast_test_flag, ast_timer_ack(), ast_timer_disable_continuous(), ast_timer_get_event(), ast_timer_set_rate(), AST_TIMING_EVENT_CONTINUOUS, AST_TIMING_EVENT_EXPIRED, AST_TIMING_FD, ast_translate(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_writestream(), calc_monitor_jump(), ast_frame::data, DEBUGCHAN_FLAG, ast_generator::digit, ast_channel_tech::exception, f, ast_channel_monitor::format, ast_frame_subclass::format, FRAMECOUNT_INC, ast_frame::frametype, ast_generator::generate, ast_frame_subclass::integer, ast_frame::len, LOG_DTMF, LOG_ERROR, LOG_NOTICE, LOG_WARNING, option_dtmfminduration, ast_control_read_action_payload::payload, ast_control_read_action_payload::payload_size, ast_frame::ptr, queue_dtmf_readq(), ast_channel_tech::read, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), should_skip_dtmf(), ast_frame::subclass, and ast_frame::uint32.

Referenced by ast_read(), and ast_read_noaudio().

{
   struct ast_frame *f = NULL;   /* the return value */
   int prestate;
   int cause = 0;

   /* this function is very long so make sure there is only one return
    * point at the end (there are only two exceptions to this).
    */

   if (ast_channel_masq(chan)) {
      ast_do_masquerade(chan);
      return &ast_null_frame;
   }

   /* if here, no masq has happened, lock the channel and proceed */
   ast_channel_lock(chan);

   /* Stop if we're a zombie or need a soft hangup */
   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
      if (ast_channel_generator(chan))
         ast_deactivate_generator(chan);

      /*
       * It is possible for chan->_softhangup to be set and there
       * still be control frames that need to be read.  Instead of
       * just going to 'done' in the case of ast_check_hangup(), we
       * need to queue the end-of-Q frame so that it can mark the end
       * of the read queue.  If there are frames to be read,
       * ast_queue_control() will be called repeatedly, but will only
       * queue the first end-of-Q frame.
       */
      if (ast_channel_softhangup_internal_flag(chan)) {
         ast_queue_control(chan, AST_CONTROL_END_OF_Q);
      } else {
         goto done;
      }
   } else {
#ifdef AST_DEVMODE
      /*
       * The ast_waitfor() code records which of the channel's file
       * descriptors reported that data is available.  In theory,
       * ast_read() should only be called after ast_waitfor() reports
       * that a channel has data available for reading.  However,
       * there still may be some edge cases throughout the code where
       * ast_read() is called improperly.  This can potentially cause
       * problems, so if this is a developer build, make a lot of
       * noise if this happens so that it can be addressed.
       *
       * One of the potential problems is blocking on a dead channel.
       */
      if (ast_channel_fdno(chan) == -1) {
         ast_log(LOG_ERROR,
            "ast_read() on chan '%s' called with no recorded file descriptor.\n",
            ast_channel_name(chan));
      }
#endif
   }

   prestate = ast_channel_state(chan);

   if (ast_channel_timingfd(chan) > -1 && ast_channel_fdno(chan) == AST_TIMING_FD) {
      enum ast_timer_event res;

      ast_clear_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION);

      res = ast_timer_get_event(ast_channel_timer(chan));

      switch (res) {
      case AST_TIMING_EVENT_EXPIRED:
         if (ast_timer_ack(ast_channel_timer(chan), 1) < 0) {
            ast_log(LOG_ERROR, "Failed to acknoweldge timer in ast_read\n");
            goto done;
         }

         if (ast_channel_timingfunc(chan)) {
            /* save a copy of func/data before unlocking the channel */
            ast_timing_func_t func = ast_channel_timingfunc(chan);
            void *data = ast_channel_timingdata(chan);
            int got_ref = 0;
            if (data && ast_test_flag(ast_channel_flags(chan), AST_FLAG_TIMINGDATA_IS_AO2_OBJ)) {
               ao2_ref(data, 1);
               got_ref = 1;
            }
            ast_channel_fdno_set(chan, -1);
            ast_channel_unlock(chan);
            func(data);
            if (got_ref) {
               ao2_ref(data, -1);
            }
         } else {
            ast_timer_set_rate(ast_channel_timer(chan), 0);
            ast_channel_fdno_set(chan, -1);
            ast_channel_unlock(chan);
         }

         /* cannot 'goto done' because the channel is already unlocked */
         return &ast_null_frame;

      case AST_TIMING_EVENT_CONTINUOUS:
         if (AST_LIST_EMPTY(ast_channel_readq(chan)) ||
            !AST_LIST_NEXT(AST_LIST_FIRST(ast_channel_readq(chan)), frame_list)) {
            ast_timer_disable_continuous(ast_channel_timer(chan));
         }
         break;
      }

   } else if (ast_channel_fd_isset(chan, AST_GENERATOR_FD) && ast_channel_fdno(chan) == AST_GENERATOR_FD) {
      /* if the AST_GENERATOR_FD is set, call the generator with args
       * set to -1 so it can do whatever it needs to.
       */
      void *tmp = ast_channel_generatordata(chan);
      ast_channel_generatordata_set(chan, NULL);     /* reset to let ast_write get through */
      ast_channel_generator(chan)->generate(chan, tmp, -1, -1);
      ast_channel_generatordata_set(chan, tmp);
      f = &ast_null_frame;
      ast_channel_fdno_set(chan, -1);
      goto done;
   } else if (ast_channel_fd_isset(chan, AST_JITTERBUFFER_FD) && ast_channel_fdno(chan) == AST_JITTERBUFFER_FD) {
      ast_clear_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION);
   }

   /* Read and ignore anything on the alertpipe, but read only
      one sizeof(blah) per frame that we send from it */
   if (ast_channel_internal_alert_read(chan) == AST_ALERT_READ_FATAL) {
      f = &ast_null_frame;
      goto done;
   }

   /* Check for pending read queue */
   if (!AST_LIST_EMPTY(ast_channel_readq(chan))) {
      int skip_dtmf = should_skip_dtmf(chan);

      AST_LIST_TRAVERSE_SAFE_BEGIN(ast_channel_readq(chan), f, frame_list) {
         /* We have to be picky about which frame we pull off of the readq because
          * there are cases where we want to leave DTMF frames on the queue until
          * some later time. */

         if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) {
            continue;
         }

         AST_LIST_REMOVE_CURRENT(frame_list);
         break;
      }
      AST_LIST_TRAVERSE_SAFE_END;

      if (!f) {
         /* There were no acceptable frames on the readq. */
         f = &ast_null_frame;
         ast_channel_alert_write(chan);
      }

      /* Interpret hangup and end-of-Q frames to return NULL */
      /* XXX why not the same for frames from the channel ? */
      if (f->frametype == AST_FRAME_CONTROL) {
         switch (f->subclass.integer) {
         case AST_CONTROL_HANGUP:
            ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
            cause = f->data.uint32;
            /* Fall through */
         case AST_CONTROL_END_OF_Q:
            ast_frfree(f);
            f = NULL;
            break;
         default:
            break;
         }
      }
   } else {
      ast_channel_blocker_set(chan, pthread_self());
      if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION)) {
         if (ast_channel_tech(chan)->exception)
            f = ast_channel_tech(chan)->exception(chan);
         else {
            ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", ast_channel_name(chan));
            f = &ast_null_frame;
         }
         /* Clear the exception flag */
         ast_clear_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION);
      } else if (ast_channel_tech(chan) && ast_channel_tech(chan)->read)
         f = ast_channel_tech(chan)->read(chan);
      else
         ast_log(LOG_WARNING, "No read routine on channel %s\n", ast_channel_name(chan));
   }

   /* Perform the framehook read event here. After the frame enters the framehook list
    * there is no telling what will happen, <insert mad scientist laugh here>!!! */
   f = ast_framehook_list_read_event(ast_channel_framehooks(chan), f);

   /*
    * Reset the recorded file descriptor that triggered this read so that we can
    * easily detect when ast_read() is called without properly using ast_waitfor().
    */
   ast_channel_fdno_set(chan, -1);

   if (f) {
      struct ast_frame *readq_tail = AST_LIST_LAST(ast_channel_readq(chan));
      struct ast_control_read_action_payload *read_action_payload;
      struct ast_party_connected_line connected;

      /* if the channel driver returned more than one frame, stuff the excess
         into the readq for the next ast_read call
      */
      if (AST_LIST_NEXT(f, frame_list)) {
         ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list));
         ast_frfree(AST_LIST_NEXT(f, frame_list));
         AST_LIST_NEXT(f, frame_list) = NULL;
      }

      switch (f->frametype) {
      case AST_FRAME_CONTROL:
         if (f->subclass.integer == AST_CONTROL_ANSWER) {
            if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING)) {
               ast_debug(1, "Ignoring answer on an inbound call!\n");
               ast_frfree(f);
               f = &ast_null_frame;
            } else if (prestate == AST_STATE_UP && ast_bridged_channel(chan)) {
               ast_debug(1, "Dropping duplicate answer!\n");
               ast_frfree(f);
               f = &ast_null_frame;
            } else {
               /* Answer the CDR */
               ast_setstate(chan, AST_STATE_UP);
               /* removed a call to ast_cdr_answer(chan->cdr) from here. */
               ast_cel_report_event(chan, AST_CEL_ANSWER, NULL, NULL, NULL);
            }
         } else if (f->subclass.integer == AST_CONTROL_READ_ACTION) {
            read_action_payload = f->data.ptr;
            switch (read_action_payload->action) {
            case AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO:
               ast_party_connected_line_init(&connected);
               ast_party_connected_line_copy(&connected, ast_channel_connected(chan));
               if (ast_connected_line_parse_data(read_action_payload->payload,
                  read_action_payload->payload_size, &connected)) {
                  ast_party_connected_line_free(&connected);
                  break;
               }
               ast_channel_unlock(chan);
               if (ast_channel_connected_line_sub(NULL, chan, &connected, 0) &&
                  ast_channel_connected_line_macro(NULL, chan, &connected, 1, 0)) {
                  ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE,
                     read_action_payload->payload,
                     read_action_payload->payload_size);
               }
               ast_party_connected_line_free(&connected);
               ast_channel_lock(chan);
               break;
            }
            ast_frfree(f);
            f = &ast_null_frame;
         }
         break;
      case AST_FRAME_DTMF_END:
         send_dtmf_event(chan, "Received", f->subclass.integer, "No", "Yes");
         ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass.integer, ast_channel_name(chan), f->len);
         /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
         if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF) || ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF)) {
            queue_dtmf_readq(chan, f);
            ast_frfree(f);
            f = &ast_null_frame;
         } else if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) {
            if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
                ast_tvdiff_ms(ast_tvnow(), *ast_channel_dtmf_tv(chan)) < AST_MIN_DTMF_GAP) {
               /* If it hasn't been long enough, defer this digit */
               queue_dtmf_readq(chan, f);
               ast_frfree(f);
               f = &ast_null_frame;
            } else {
               /* There was no begin, turn this into a begin and send the end later */
               struct timeval tv = ast_tvnow();
               f->frametype = AST_FRAME_DTMF_BEGIN;
               ast_set_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF);
               ast_channel_dtmf_digit_to_emulate_set(chan, f->subclass.integer);
               ast_channel_dtmf_tv_set(chan, &tv);
               if (f->len) {
                  if (f->len > option_dtmfminduration)
                     ast_channel_emulate_dtmf_duration_set(chan, f->len);
                  else
                     ast_channel_emulate_dtmf_duration_set(chan, option_dtmfminduration);
               } else
                  ast_channel_emulate_dtmf_duration_set(chan, AST_DEFAULT_EMULATE_DTMF_DURATION);
               ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass.integer, ast_channel_emulate_dtmf_duration(chan), ast_channel_name(chan));
            }
            if (ast_channel_audiohooks(chan)) {
               struct ast_frame *old_frame = f;
               /*!
                * \todo XXX It is possible to write a digit to the audiohook twice
                * if the digit was originally read while the channel was in autoservice. */
               f = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_READ, f);
               if (old_frame != f)
                  ast_frfree(old_frame);
            }
         } else {
            struct timeval now = ast_tvnow();
            if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF)) {
               ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
               ast_clear_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF);
               if (!f->len)
                  f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));

               /* detect tones that were received on
                * the wire with durations shorter than
                * option_dtmfminduration and set f->len
                * to the actual duration of the DTMF
                * frames on the wire.  This will cause
                * dtmf emulation to be triggered later
                * on.
                */
               if (ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan)) < option_dtmfminduration) {
                  f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
                  ast_log(LOG_DTMF, "DTMF end '%c' detected to have actual duration %ld on the wire, emulation will be triggered on %s\n", f->subclass.integer, f->len, ast_channel_name(chan));
               }
            } else if (!f->len) {
               ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
               f->len = option_dtmfminduration;
            }
            if (f->len < option_dtmfminduration && !ast_test_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY)) {
               ast_log(LOG_DTMF, "DTMF end '%c' has duration %ld but want minimum %d, emulating on %s\n", f->subclass.integer, f->len, option_dtmfminduration, ast_channel_name(chan));
               ast_set_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF);
               ast_channel_dtmf_digit_to_emulate_set(chan, f->subclass.integer);
               ast_channel_emulate_dtmf_duration_set(chan, option_dtmfminduration - f->len);
               ast_frfree(f);
               f = &ast_null_frame;
            } else {
               ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
               if (f->len < option_dtmfminduration) {
                  f->len = option_dtmfminduration;
               }
               ast_channel_dtmf_tv_set(chan, &now);
            }
            if (ast_channel_audiohooks(chan)) {
               struct ast_frame *old_frame = f;
               f = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_READ, f);
               if (old_frame != f)
                  ast_frfree(old_frame);
            }
         }
         break;
      case AST_FRAME_DTMF_BEGIN:
         send_dtmf_event(chan, "Received", f->subclass.integer, "Yes", "No");
         ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass.integer, ast_channel_name(chan));
         if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) ||
             (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
               ast_tvdiff_ms(ast_tvnow(), *ast_channel_dtmf_tv(chan)) < AST_MIN_DTMF_GAP) ) {
            ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
            ast_frfree(f);
            f = &ast_null_frame;
         } else {
            struct timeval now = ast_tvnow();
            ast_set_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF);
            ast_channel_dtmf_tv_set(chan, &now);
            ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass.integer, ast_channel_name(chan));
         }
         break;
      case AST_FRAME_NULL:
         /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
          * is reached , because we want to make sure we pass at least one
          * voice frame through before starting the next digit, to ensure a gap
          * between DTMF digits. */
         if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF)) {
            struct timeval now = ast_tvnow();
            if (!ast_channel_emulate_dtmf_duration(chan)) {
               ast_clear_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF);
               ast_channel_dtmf_digit_to_emulate_set(chan, 0);
            } else if (ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan)) >= ast_channel_emulate_dtmf_duration(chan)) {
               ast_channel_emulate_dtmf_duration_set(chan, 0);
               ast_frfree(f);
               f = ast_channel_dtmff(chan);
               f->frametype = AST_FRAME_DTMF_END;
               f->subclass.integer = ast_channel_dtmf_digit_to_emulate(chan);
               f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
               ast_channel_dtmf_tv_set(chan, &now);
               ast_clear_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF);
               ast_channel_dtmf_digit_to_emulate_set(chan, 0);
               ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
               if (ast_channel_audiohooks(chan)) {
                  struct ast_frame *old_frame = f;
                  f = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_READ, f);
                  if (old_frame != f) {
                     ast_frfree(old_frame);
                  }
               }
            }
         }
         break;
      case AST_FRAME_VOICE:
         /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
          * is reached , because we want to make sure we pass at least one
          * voice frame through before starting the next digit, to ensure a gap
          * between DTMF digits. */
         if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF) && !ast_channel_emulate_dtmf_duration(chan)) {
            ast_clear_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF);
            ast_channel_dtmf_digit_to_emulate_set(chan, 0);
         }

         if (dropaudio || ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF)) {
            if (dropaudio)
               ast_read_generator_actions(chan, f);
            ast_frfree(f);
            f = &ast_null_frame;
         }

         if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF) && !ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF)) {
            struct timeval now = ast_tvnow();
            if (ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan)) >= ast_channel_emulate_dtmf_duration(chan)) {
               ast_channel_emulate_dtmf_duration_set(chan, 0);
               ast_frfree(f);
               f = ast_channel_dtmff(chan);
               f->frametype = AST_FRAME_DTMF_END;
               f->subclass.integer = ast_channel_dtmf_digit_to_emulate(chan);
               f->len = ast_tvdiff_ms(now, *ast_channel_dtmf_tv(chan));
               ast_channel_dtmf_tv_set(chan, &now);
               if (ast_channel_audiohooks(chan)) {
                  struct ast_frame *old_frame = f;
                  f = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_READ, f);
                  if (old_frame != f)
                     ast_frfree(old_frame);
               }
               ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass.integer, ast_channel_name(chan));
            } else {
               /* Drop voice frames while we're still in the middle of the digit */
               ast_frfree(f);
               f = &ast_null_frame;
            }
         } else if ((f->frametype == AST_FRAME_VOICE) && !ast_format_cap_iscompatible(ast_channel_nativeformats(chan), &f->subclass.format)) {
            /* This frame is not one of the current native formats -- drop it on the floor */
            char to[200];
            ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n",
               ast_channel_name(chan), ast_getformatname(&f->subclass.format), ast_getformatname_multiple(to, sizeof(to), ast_channel_nativeformats(chan)));
            ast_frfree(f);
            f = &ast_null_frame;
         } else if ((f->frametype == AST_FRAME_VOICE)) {
            /* Send frame to audiohooks if present */
            if (ast_channel_audiohooks(chan)) {
               struct ast_frame *old_frame = f;
               f = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_READ, f);
               if (old_frame != f)
                  ast_frfree(old_frame);
            }
            if (ast_channel_monitor(chan) && ast_channel_monitor(chan)->read_stream ) {
               /* XXX what does this do ? */
#ifndef MONITOR_CONSTANT_DELAY
               int jump = ast_channel_outsmpl(chan) - ast_channel_insmpl(chan) - 4 * f->samples;
               if (jump >= 0) {
                  jump = calc_monitor_jump((ast_channel_outsmpl(chan) - ast_channel_insmpl(chan)), ast_format_rate(&f->subclass.format), ast_format_rate(&ast_channel_monitor(chan)->read_stream->fmt->format));
                  if (ast_seekstream(ast_channel_monitor(chan)->read_stream, jump, SEEK_FORCECUR) == -1) {
                     ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
                  }
                  ast_channel_insmpl_set(chan, ast_channel_insmpl(chan) + (ast_channel_outsmpl(chan) - ast_channel_insmpl(chan)) + f->samples);
               } else {
                  ast_channel_insmpl_set(chan, ast_channel_insmpl(chan) + f->samples);
               }
#else
               int jump = calc_monitor_jump((ast_channel_outsmpl(chan) - ast_channel_insmpl(chan)), ast_format_rate(f->subclass.codec), ast_format_rate(ast_channel_monitor(chan)->read_stream->fmt->format));
               if (jump - MONITOR_DELAY >= 0) {
                  if (ast_seekstream(ast_channel_monitor(chan)->read_stream, jump - f->samples, SEEK_FORCECUR) == -1)
                     ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
                  ast_channel_insmpl(chan) += ast_channel_outsmpl(chan) - ast_channel_insmpl(chan);
               } else
                  ast_channel_insmpl(chan) += f->samples;
#endif
               if (ast_channel_monitor(chan)->state == AST_MONITOR_RUNNING) {
                  if (ast_writestream(ast_channel_monitor(chan)->read_stream, f) < 0)
                     ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n");
               }
            }

            if (ast_channel_readtrans(chan) && (f = ast_translate(ast_channel_readtrans(chan), f, 1)) == NULL) {
               f = &ast_null_frame;
            }

            /* it is possible for the translation process on chan->readtrans to have
               produced multiple frames from the single input frame we passed it; if
               this happens, queue the additional frames *before* the frames we may
               have queued earlier. if the readq was empty, put them at the head of
               the queue, and if it was not, put them just after the frame that was
               at the end of the queue.
            */
            if (AST_LIST_NEXT(f, frame_list)) {
               if (!readq_tail) {
                  ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list));
               } else {
                  __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail);
               }
               ast_frfree(AST_LIST_NEXT(f, frame_list));
               AST_LIST_NEXT(f, frame_list) = NULL;
            }

            /* Run generator sitting on the line if timing device not available
            * and synchronous generation of outgoing frames is necessary       */
            ast_read_generator_actions(chan, f);
         }
         break;
      default:
         /* Just pass it on! */
         break;
      }
   } else {
      /* Make sure we always return NULL in the future */
      if (!ast_channel_softhangup_internal_flag(chan)) {
         ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
      }
      if (cause)
         ast_channel_hangupcause_set(chan, cause);
      if (ast_channel_generator(chan))
         ast_deactivate_generator(chan);
      /* We no longer End the CDR here */
   }

   /* High bit prints debugging */
   if (ast_channel_fin(chan) & DEBUGCHAN_FLAG)
      ast_frame_dump(ast_channel_name(chan), f, "<<");
   ast_channel_fin_set(chan, FRAMECOUNT_INC(ast_channel_fin(chan)));

done:
   if (ast_channel_music_state(chan) && ast_channel_generator(chan) && ast_channel_generator(chan)->digit && f && f->frametype == AST_FRAME_DTMF_END)
      ast_channel_generator(chan)->digit(chan, f->subclass.integer);

   if (ast_channel_audiohooks(chan) && ast_audiohook_write_list_empty(ast_channel_audiohooks(chan))) {
      /* The list gets recreated if audiohooks are added again later */
      ast_audiohook_detach_list(ast_channel_audiohooks(chan));
      ast_channel_audiohooks_set(chan, NULL);
   }
   ast_channel_unlock(chan);
   return f;
}
struct ast_channel* __ast_request_and_dial ( const char *  type,
struct ast_format_cap cap,
const struct ast_channel requestor,
const char *  addr,
int  timeout,
int *  reason,
const char *  cid_num,
const char *  cid_name,
struct outgoing_helper oh 
) [read]

Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.

Parameters:
typetype of channel to request
formatcapabilities for requested channel
requestorchannel requesting data
addrdestination of the call
timeoutmaximum amount of time to wait for an answer
reasonwhy unsuccessful (if unsuccessful)
cid_numCaller-ID Number
cid_nameCaller-ID Name (ascii)
ohOutgoing helper
Returns:
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 5645 of file channel.c.

References outgoing_helper::account, ast_call(), ast_call_forward(), AST_CAUSE_NO_ANSWER, ast_cdr_alloc(), ast_cdr_answer(), ast_cdr_busy(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), AST_CDR_FLAG_ORIGINATED, ast_cdr_init(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_channel_call_forward(), ast_channel_cdr(), ast_channel_cdr_set(), ast_channel_connected(), ast_channel_context_set(), ast_channel_datastore_inherit(), ast_channel_exten_set(), ast_channel_hangupcause(), ast_channel_hangupcause_hash_set(), ast_channel_hangupcause_set(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_lock_both, ast_channel_priority_set(), ast_channel_set_connected_line(), ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_FRAME_CONTROL, ast_frfree, ast_hangup(), ast_log(), ast_party_connected_line_set_init(), AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, ast_read(), ast_remaining_ms(), ast_request(), ast_set_callerid(), ast_set_flag, ast_set_variables(), AST_STATE_UP, ast_strlen_zero(), ast_tvnow(), ast_waitfor(), chanlist::chan, outgoing_helper::cid_name, outgoing_helper::cid_num, outgoing_helper::connect_on_early_media, outgoing_helper::context, ast_frame::data, ast_frame::datalen, outgoing_helper::exten, f, ast_frame::frametype, handle_cause(), ast_party_connected_line::id, ast_frame_subclass::integer, LOG_NOTICE, ast_party_id::name, ast_party_id::number, outgoing_helper::parent_channel, ast_party_name::presentation, ast_party_number::presentation, outgoing_helper::priority, ast_frame::ptr, ast_party_name::str, ast_party_number::str, ast_frame::subclass, ast_party_name::valid, ast_party_number::valid, and outgoing_helper::vars.

Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().

{
   int dummy_outstate;
   int cause = 0;
   struct ast_channel *chan;
   int res = 0;
   int last_subclass = 0;
   struct ast_party_connected_line connected;

   if (outstate)
      *outstate = 0;
   else
      outstate = &dummy_outstate;   /* make outstate always a valid pointer */

   chan = ast_request(type, cap, requestor, addr, &cause);
   if (!chan) {
      ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, addr);
      handle_cause(cause, outstate);
      return NULL;
   }

   if (oh) {
      if (oh->vars) {
         ast_set_variables(chan, oh->vars);
      }
      if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
         /*
          * Use the oh values instead of the function parameters for the
          * outgoing CallerID.
          */
         cid_num = oh->cid_num;
         cid_name = oh->cid_name;
      }
      if (oh->parent_channel) {
         /* Safely inherit variables and datastores from the parent channel. */
         ast_channel_lock_both(oh->parent_channel, chan);
         ast_channel_inherit_variables(oh->parent_channel, chan);
         ast_channel_datastore_inherit(oh->parent_channel, chan);
         ast_channel_unlock(oh->parent_channel);
         ast_channel_unlock(chan);
      }
      if (oh->account) {
         ast_channel_lock(chan);
         ast_cdr_setaccount(chan, oh->account);
         ast_channel_unlock(chan);
      }
   }

   /*
    * I seems strange to set the CallerID on an outgoing call leg
    * to whom we are calling, but this function's callers are doing
    * various Originate methods.  This call leg goes to the local
    * user.  Once the local user answers, the dialplan needs to be
    * able to access the CallerID from the CALLERID function as if
    * the local user had placed this call.
    */
   ast_set_callerid(chan, cid_num, cid_name, cid_num);

   ast_set_flag(ast_channel_cdr(chan), AST_CDR_FLAG_ORIGINATED);
   ast_party_connected_line_set_init(&connected, ast_channel_connected(chan));
   if (cid_num) {
      connected.id.number.valid = 1;
      connected.id.number.str = (char *) cid_num;
      connected.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
   }
   if (cid_name) {
      connected.id.name.valid = 1;
      connected.id.name.str = (char *) cid_name;
      connected.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
   }
   ast_channel_set_connected_line(chan, &connected, NULL);

   if (ast_call(chan, addr, 0)) {   /* ast_call failed... */
      ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, addr);
   } else {
      struct timeval start = ast_tvnow();
      res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
      while (timeout && ast_channel_state(chan) != AST_STATE_UP) {
         struct ast_frame *f;
         int ms = ast_remaining_ms(start, timeout);

         res = ast_waitfor(chan, ms);
         if (res == 0) { /* timeout, treat it like ringing */
            *outstate = AST_CONTROL_RINGING;
            break;
         }
         if (res < 0) /* error or done */
            break;
         if (!ast_strlen_zero(ast_channel_call_forward(chan))) {
            if (!(chan = ast_call_forward(NULL, chan, NULL, cap, oh, outstate))) {
               return NULL;
            }
            continue;
         }

         f = ast_read(chan);
         if (!f) {
            *outstate = AST_CONTROL_HANGUP;
            res = 0;
            break;
         }
         if (f->frametype == AST_FRAME_CONTROL) {
            switch (f->subclass.integer) {
            case AST_CONTROL_RINGING:  /* record but keep going */
               *outstate = f->subclass.integer;
               break;

            case AST_CONTROL_BUSY:
               ast_cdr_busy(ast_channel_cdr(chan));
               *outstate = f->subclass.integer;
               timeout = 0;
               break;

            case AST_CONTROL_INCOMPLETE:
               ast_cdr_failed(ast_channel_cdr(chan));
               *outstate = AST_CONTROL_CONGESTION;
               timeout = 0;
               break;

            case AST_CONTROL_CONGESTION:
               ast_cdr_failed(ast_channel_cdr(chan));
               *outstate = f->subclass.integer;
               timeout = 0;
               break;

            case AST_CONTROL_ANSWER:
               ast_cdr_answer(ast_channel_cdr(chan));
               *outstate = f->subclass.integer;
               timeout = 0;      /* trick to force exit from the while() */
               break;

            case AST_CONTROL_PVT_CAUSE_CODE:
               ast_channel_hangupcause_hash_set(chan, f->data.ptr, f->datalen);
               break;

            case AST_CONTROL_PROGRESS:
               if (oh && oh->connect_on_early_media) {
                  *outstate = f->subclass.integer;
                  timeout = 0;      /* trick to force exit from the while() */
                  break;
               }
               /* Fallthrough */
            /* Ignore these */
            case AST_CONTROL_PROCEEDING:
            case AST_CONTROL_HOLD:
            case AST_CONTROL_UNHOLD:
            case AST_CONTROL_VIDUPDATE:
            case AST_CONTROL_SRCUPDATE:
            case AST_CONTROL_SRCCHANGE:
            case AST_CONTROL_CONNECTED_LINE:
            case AST_CONTROL_REDIRECTING:
            case AST_CONTROL_CC:
            case -1:       /* Ignore -- just stopping indications */
               break;

            default:
               ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass.integer);
            }
            last_subclass = f->subclass.integer;
         }
         ast_frfree(f);
      }
   }

   /* Final fixups */
   if (oh) {
      if (!ast_strlen_zero(oh->context))
         ast_channel_context_set(chan, oh->context);
      if (!ast_strlen_zero(oh->exten))
         ast_channel_exten_set(chan, oh->exten);
      if (oh->priority)
         ast_channel_priority_set(chan, oh->priority);
   }
   if (ast_channel_state(chan) == AST_STATE_UP)
      *outstate = AST_CONTROL_ANSWER;

   if (res <= 0) {
      struct ast_cdr *chancdr;
      ast_channel_lock(chan);
      if (AST_CONTROL_RINGING == last_subclass) {
         ast_channel_hangupcause_set(chan, AST_CAUSE_NO_ANSWER);
      }
      if (!ast_channel_cdr(chan) && (chancdr = ast_cdr_alloc())) {
         ast_channel_cdr_set(chan, chancdr);
         ast_cdr_init(ast_channel_cdr(chan), chan);
      }
      if (ast_channel_cdr(chan)) {
         char tmp[256];

         snprintf(tmp, sizeof(tmp), "%s/%s", type, addr);
         ast_cdr_setapp(ast_channel_cdr(chan), "Dial", tmp);
         ast_cdr_update(chan);
         ast_cdr_start(ast_channel_cdr(chan));
         ast_cdr_end(ast_channel_cdr(chan));
         /* If the cause wasn't handled properly */
         if (ast_cdr_disposition(ast_channel_cdr(chan), ast_channel_hangupcause(chan))) {
            ast_cdr_failed(ast_channel_cdr(chan));
         }
      }
      ast_channel_unlock(chan);
      ast_hangup(chan);
      chan = NULL;
   }
   return chan;
}
static void __init_state2str_threadbuf ( void  ) [static]

Definition at line 110 of file channel.c.

{
static void adjust_frame_for_plc ( struct ast_channel chan,
struct ast_frame frame,
struct ast_datastore datastore 
) [static]

Definition at line 4881 of file channel.c.

References ast_calloc, ast_channel_datastore_remove(), ast_datastore_free(), ast_free, AST_FRIENDLY_OFFSET, ast_datastore::data, ast_frame::data, ast_frame::datalen, plc_ds::num_samples, ast_frame::offset, plc_fillin(), plc_rx(), plc_ds::plc_state, ast_frame::ptr, ast_frame::samples, and plc_ds::samples_buf.

Referenced by apply_plc().

{
   int num_new_samples = frame->samples;
   struct plc_ds *plc = datastore->data;

   /* As a general note, let me explain the somewhat odd calculations used when taking
    * the frame offset into account here. According to documentation in frame.h, the frame's
    * offset field indicates the number of bytes that the audio is offset. The plc->samples_buf
    * is not an array of bytes, but rather an array of 16-bit integers since it holds SLIN
    * samples. So I had two choices to make here with the offset.
    *
    * 1. Make the offset AST_FRIENDLY_OFFSET bytes. The main downside for this is that
    *    I can't just add AST_FRIENDLY_OFFSET to the plc->samples_buf and have the pointer
    *    arithmetic come out right. I would have to do some odd casting or division for this to
    *    work as I wanted.
    * 2. Make the offset AST_FRIENDLY_OFFSET * 2 bytes. This allows the pointer arithmetic
    *    to work out better with the plc->samples_buf. The downside here is that the buffer's
    *    allocation contains an extra 64 bytes of unused space.
    *
    * I decided to go with option 2. This is why in the calloc statement and the statement that
    * sets the frame's offset, AST_FRIENDLY_OFFSET is multiplied by 2.
    */

   /* If this audio frame has no samples to fill in, ignore it */
   if (!num_new_samples) {
      return;
   }

   /* First, we need to be sure that our buffer is large enough to accomodate
    * the samples we need to fill in. This will likely only occur on the first
    * frame we write.
    */
   if (plc->num_samples < num_new_samples) {
      ast_free(plc->samples_buf);
      plc->samples_buf = ast_calloc(1, (num_new_samples * sizeof(*plc->samples_buf)) + (AST_FRIENDLY_OFFSET * 2));
      if (!plc->samples_buf) {
         ast_channel_datastore_remove(chan, datastore);
         ast_datastore_free(datastore);
         return;
      }
      plc->num_samples = num_new_samples;
   }

   if (frame->datalen == 0) {
      plc_fillin(&plc->plc_state, plc->samples_buf + AST_FRIENDLY_OFFSET, frame->samples);
      frame->data.ptr = plc->samples_buf + AST_FRIENDLY_OFFSET;
      frame->datalen = num_new_samples * 2;
      frame->offset = AST_FRIENDLY_OFFSET * 2;
   } else {
      plc_rx(&plc->plc_state, frame->data.ptr, frame->samples);
   }
}
static void apply_plc ( struct ast_channel chan,
struct ast_frame frame 
) [static]

Definition at line 4934 of file channel.c.

References adjust_frame_for_plc(), ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc(), ast_datastore_free(), and ast_datastore::data.

Referenced by ast_write().

{
   struct ast_datastore *datastore;
   struct plc_ds *plc;

   datastore = ast_channel_datastore_find(chan, &plc_ds_info, NULL);
   if (datastore) {
      plc = datastore->data;
      adjust_frame_for_plc(chan, frame, datastore);
      return;
   }

   datastore = ast_datastore_alloc(&plc_ds_info, NULL);
   if (!datastore) {
      return;
   }
   plc = ast_calloc(1, sizeof(*plc));
   if (!plc) {
      ast_datastore_free(datastore);
      return;
   }
   datastore->data = plc;
   ast_channel_datastore_add(chan, datastore);
   adjust_frame_for_plc(chan, frame, datastore);
}
int ast_active_channels ( void  )

returns number of active/allocated channels

Returns:
number of channels available for lookup

Definition at line 657 of file channel.c.

References ao2_container_count(), and channels.

Referenced by action_corestatus(), ast_var_channels(), ast_var_channels_table(), dahdi_restart(), handle_chanlist(), handle_show_settings(), and really_quit().

int ast_answer ( struct ast_channel chan)

Answer a channel.

Parameters:
chanchannel to answer

This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.
This function will wait up to 500 milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow.
Return values:
0on success
non-zeroon failure

Definition at line 3053 of file channel.c.

References __ast_answer().

Referenced by action_bridge(), agi_exec_full(), alarmreceiver_exec(), answer_trunk_chan(), app_exec(), ast_do_pickup(), ast_pickup_call(), auth_exec(), background_detect_exec(), bridge_exec(), bridge_request(), builtin_parkcall(), common_exec(), conf_exec(), confbridge_exec(), control_streamfile(), count_exec(), dahdiras_exec(), dial_exec_full(), dictate_exec(), directory_exec(), disa_exec(), eivr_comm(), handle_answer(), ices_exec(), login_exec(), minivm_accmess_exec(), minivm_greet_exec(), minivm_record_exec(), old_milliwatt_exec(), park_call_exec(), parked_call_exec(), pbx_builtin_background(), playback_exec(), privacy_exec(), read_exec(), readexten_exec(), receivefax_exec(), record_exec(), record_thread(), sayunixtime_exec(), send_waveform_to_channel(), sendfax_exec(), setup_privacy_args(), skel_exec(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), transmit(), vm_exec(), vm_execmain(), vm_playmsgexec(), waitfor_exec(), and zapateller_exec().

{
   return __ast_answer(chan, 0, 1);
}
void ast_begin_shutdown ( int  hangup)

Initiate system shutdown -- prevents new channels from being allocated.

Parameters:
hangupIf "hangup" is non-zero, all existing channels will receive soft hangups

Definition at line 647 of file channel.c.

References ao2_callback, ast_channel_softhangup_cb(), channels, OBJ_MULTIPLE, and OBJ_NODATA.

Referenced by can_safely_quit().

struct ast_format* ast_best_codec ( struct ast_format_cap cap,
struct ast_format result 
) [read]

Pick the best audio codec.

Pick the best codec.

Okay, ulaw is used by all telephony equipment, so start with it

Unless of course, you're a silly European, so then prefer ALAW

G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority

Okay, well, signed linear is easy to translate into other stuff

G.726 is standard ADPCM, in RFC3551 packing order

G.726 is standard ADPCM, in AAL2 packing order

ADPCM has great sound quality and is still pretty easy to translate

Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good

iLBC is not too bad

Speex is free, but computationally more expensive than GSM

SILK is pretty awesome.

CELT supports crazy high sample rates

Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it

G.729a is faster than 723 and slightly less expensive

Down to G.723.1 which is proprietary but at least designed for voice

Definition at line 876 of file channel.c.

References ARRAY_LEN, AST_FORMAT_ADPCM, AST_FORMAT_ALAW, ast_format_cap_best_byid(), AST_FORMAT_CELT, ast_format_clear(), AST_FORMAT_G719, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_SILK, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR12, AST_FORMAT_SLINEAR16, AST_FORMAT_SLINEAR192, AST_FORMAT_SLINEAR24, AST_FORMAT_SLINEAR32, AST_FORMAT_SLINEAR44, AST_FORMAT_SLINEAR48, AST_FORMAT_SLINEAR96, AST_FORMAT_SPEEX, AST_FORMAT_SPEEX16, AST_FORMAT_SPEEX32, AST_FORMAT_TESTLAW, AST_FORMAT_ULAW, ast_getformatname_multiple(), ast_log(), LOG_WARNING, and prefs.

Referenced by __oh323_new(), ast_codec_choose(), ast_iax2_new(), ast_speech_new(), bridge_make_compatible(), echo_exec(), feature_request_and_dial(), free_translation(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_best_codec(), iax2_request(), jingle_new(), local_new(), mgcp_new(), misdn_new(), multicast_rtp_request(), phone_new(), set_format(), skinny_new(), skinny_set_rtp_peer(), start_rtp(), transmit_connect(), and unistim_new().

{
   /* This just our opinion, expressed in code.  We are asked to choose
      the best codec to use, given no information */
   static const enum ast_format_id prefs[] =
   {
      /*! Okay, ulaw is used by all telephony equipment, so start with it */
      AST_FORMAT_ULAW,
      /*! Unless of course, you're a silly European, so then prefer ALAW */
      AST_FORMAT_ALAW,
      AST_FORMAT_G719,
      AST_FORMAT_SIREN14,
      AST_FORMAT_SIREN7,
      AST_FORMAT_TESTLAW,
      /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
      AST_FORMAT_G722,
      /*! Okay, well, signed linear is easy to translate into other stuff */
      AST_FORMAT_SLINEAR192,
      AST_FORMAT_SLINEAR96,
      AST_FORMAT_SLINEAR48,
      AST_FORMAT_SLINEAR44,
      AST_FORMAT_SLINEAR32,
      AST_FORMAT_SLINEAR24,
      AST_FORMAT_SLINEAR16,
      AST_FORMAT_SLINEAR12,
      AST_FORMAT_SLINEAR,
      /*! G.726 is standard ADPCM, in RFC3551 packing order */
      AST_FORMAT_G726,
      /*! G.726 is standard ADPCM, in AAL2 packing order */
      AST_FORMAT_G726_AAL2,
      /*! ADPCM has great sound quality and is still pretty easy to translate */
      AST_FORMAT_ADPCM,
      /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
          translate and sounds pretty good */
      AST_FORMAT_GSM,
      /*! iLBC is not too bad */
      AST_FORMAT_ILBC,
      /*! Speex is free, but computationally more expensive than GSM */
      AST_FORMAT_SPEEX32,
      AST_FORMAT_SPEEX16,
      AST_FORMAT_SPEEX,
      /*! SILK is pretty awesome. */
      AST_FORMAT_SILK,
      /*! CELT supports crazy high sample rates */
      AST_FORMAT_CELT,
      /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
          to use it */
      AST_FORMAT_LPC10,
      /*! G.729a is faster than 723 and slightly less expensive */
      AST_FORMAT_G729A,
      /*! Down to G.723.1 which is proprietary but at least designed for voice */
      AST_FORMAT_G723_1,
   };
   char buf[512];
   int x;

   /* Find the first preferred codec in the format given */
   for (x = 0; x < ARRAY_LEN(prefs); x++) {
      if (ast_format_cap_best_byid(cap, prefs[x], result)) {
         return result;
      }
   }

   ast_format_clear(result);
   ast_log(LOG_WARNING, "Don't know any of %s formats\n", ast_getformatname_multiple(buf, sizeof(buf), cap));

   return NULL;
}
struct ast_channel* ast_bridged_channel ( struct ast_channel chan) [read]

Find bridged channel.

Note:
This function does _not_ return a reference to the bridged channel. The reason for this is mostly historical. It _should_ return a reference, but it will take a lot of work to make the code base account for that. So, for now, the old rules still apply for how to handle this function. If this function is being used from the channel thread that owns the channel, then a reference is already held, and channel locking is not required to guarantee that the channel will stay around. If this function is used outside of the associated channel thread, the channel parameter 'chan' MUST be locked before calling this function. Also, 'chan' must remain locked for the entire time that the result of this function is being used.
Parameters:
chanCurrent channel
Returns:
A pointer to the bridged channel

Definition at line 7455 of file channel.c.

References ast_channel_internal_bridged_channel(), ast_channel_tech(), ast_channel::bridged_channel, and ast_channel_tech::bridged_channel.

Referenced by __analog_handle_event(), __analog_ss_thread(), __ast_channel_masquerade(), __ast_read(), __dahdi_exception(), _skinny_show_lines(), action_agents(), action_coreshowchannels(), agents_data_provider_get(), agents_show(), agents_show_online(), analog_attempt_transfer(), analog_exception(), analog_hangup(), analog_ss_thread(), ast_bridge_call(), ast_cel_report_event(), ast_channel_data_add_structure(), ast_channel_set_linkgroup(), ast_do_masquerade(), ast_rtp_instance_set_stats_vars(), ast_set_hangupsource(), ast_var_channel_bridge(), ast_var_channels_table(), attempt_transfer(), cb_events(), channel_spy(), check_bridge(), common_exec(), console_transfer(), create_jb(), dahdi_handle_event(), dahdi_hangup(), export_aoc_vars(), fax_detect_framehook(), fax_gateway_framehook(), func_channel_read(), get_refer_info(), handle_chanlist(), handle_hd_hf(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_refer(), handle_showchan(), handle_soft_key_event_message(), handle_stimulus_message(), key_dial_page(), local_attended_transfer(), local_queryoption(), mgcp_hangup(), mgcp_ss(), misdn_attempt_transfer(), mixmonitor_thread(), my_get_sigpvt_bridged_channel(), park_call_full(), pri_dchannel(), schedule_delivery(), serialize_showchan(), sig_pri_attempt_transfer(), sip_hangup(), sip_set_rtp_peer(), skinny_transfer(), socket_process_helper(), spandsp_fax_gateway_start(), start_spying(), startmon(), transfer_call_step1(), transfer_cancel_step2(), and unistim_hangup().

{
   struct ast_channel *bridged;
   bridged = ast_channel_internal_bridged_channel(chan);
   if (bridged && ast_channel_tech(bridged)->bridged_channel)
      bridged = ast_channel_tech(bridged)->bridged_channel(chan, bridged);
   return bridged;
}
int ast_call ( struct ast_channel chan,
const char *  addr,
int  timeout 
)

Make a call.

Note:
Absolutely _NO_ channel locks should be held before calling this function.
Parameters:
chanwhich channel to make the call on
addrdestination of the call
timeouttime to wait on for connect (Doesn't seem to be used.)

Place a call, take no longer than timeout ms.

Return values:
0on success
-1on failure

Definition at line 6004 of file channel.c.

References AST_CDR_FLAG_DIALED, ast_channel_cdr(), ast_channel_flags(), ast_channel_lock, ast_channel_tech(), ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_set_flag, ast_test_flag, and ast_channel_tech::call.

Referenced by __ast_request_and_dial(), alloc_playback_chan(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), dial_transfer(), do_forward(), do_idle_thread(), feature_request_and_dial(), findmeexec(), ring_entry(), and wait_for_answer().

{
   /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
      If the remote end does not answer within the timeout, then do NOT hang up, but
      return anyway.  */
   int res = -1;
   /* Stop if we're a zombie or need a soft hangup */
   ast_channel_lock(chan);
   if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
      if (ast_channel_cdr(chan)) {
         ast_set_flag(ast_channel_cdr(chan), AST_CDR_FLAG_DIALED);
      }
      if (ast_channel_tech(chan)->call)
         res = ast_channel_tech(chan)->call(chan, addr, timeout);
      ast_set_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
   }
   ast_channel_unlock(chan);
   return res;
}
struct ast_channel* ast_call_forward ( struct ast_channel caller,
struct ast_channel orig,
int *  timeout,
struct ast_format_cap cap,
struct outgoing_helper oh,
int *  outstate 
) [read]

Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.

Parameters:
callerin channel that requested orig
origchannel being replaced by the call forward channel
timeoutmaximum amount of time to wait for setup of new forward channel
formatcapabilities for requested channel
ohoutgoing helper used with original channel
outstatereason why unsuccessful (if uncuccessful)
Returns:
Returns the forwarded call's ast_channel on success or NULL on failure

Definition at line 5575 of file channel.c.

References outgoing_helper::account, ast_call(), AST_CDR_FLAG_ORIGINATED, ast_cdr_setaccount(), ast_channel_accountcode(), ast_channel_call_forward(), ast_channel_cdr(), ast_channel_connected(), ast_channel_context(), ast_channel_lock, ast_channel_lock_both, ast_channel_redirecting(), ast_channel_unlock, ast_copy_flags, ast_copy_string(), ast_hangup(), ast_log(), ast_party_connected_line_copy(), ast_party_redirecting_copy(), ast_request(), ast_set_variables(), call_forward_inherit(), ast_channel::data, handle_cause(), LOG_NOTICE, outgoing_helper::parent_channel, pbx_builtin_getvar_helper(), S_OR, type, and outgoing_helper::vars.

Referenced by __ast_request_and_dial(), and feature_request_and_dial().

{
   char tmpchan[256];
   struct ast_channel *new_chan = NULL;
   char *data, *type;
   int cause = 0;
   int res;

   /* gather data and request the new forward channel */
   ast_copy_string(tmpchan, ast_channel_call_forward(orig), sizeof(tmpchan));
   if ((data = strchr(tmpchan, '/'))) {
      *data++ = '\0';
      type = tmpchan;
   } else {
      const char *forward_context;
      ast_channel_lock(orig);
      forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
      snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(orig), S_OR(forward_context, ast_channel_context(orig)));
      ast_channel_unlock(orig);
      data = tmpchan;
      type = "Local";
   }
   if (!(new_chan = ast_request(type, cap, orig, data, &cause))) {
      ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
      handle_cause(cause, outstate);
      ast_hangup(orig);
      return NULL;
   }

   /* Copy/inherit important information into new channel */
   if (oh) {
      if (oh->vars) {
         ast_set_variables(new_chan, oh->vars);
      }
      if (oh->parent_channel) {
         call_forward_inherit(new_chan, oh->parent_channel, orig);
      }
      if (oh->account) {
         ast_channel_lock(new_chan);
         ast_cdr_setaccount(new_chan, oh->account);
         ast_channel_unlock(new_chan);
      }
   } else if (caller) { /* no outgoing helper so use caller if available */
      call_forward_inherit(new_chan, caller, orig);
   }

   ast_channel_lock_both(orig, new_chan);
   ast_copy_flags(ast_channel_cdr(new_chan), ast_channel_cdr(orig), AST_CDR_FLAG_ORIGINATED);
   ast_channel_accountcode_set(new_chan, ast_channel_accountcode(orig));
   ast_party_connected_line_copy(ast_channel_connected(new_chan), ast_channel_connected(orig));
   ast_party_redirecting_copy(ast_channel_redirecting(new_chan), ast_channel_redirecting(orig));
   ast_channel_unlock(new_chan);
   ast_channel_unlock(orig);

   /* call new channel */
   res = ast_call(new_chan, data, 0);
   if (timeout) {
      *timeout = res;
   }
   if (res) {
      ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
      ast_hangup(orig);
      ast_hangup(new_chan);
      return NULL;
   }
   ast_hangup(orig);

   return new_chan;
}
void ast_cancel_shutdown ( void  )

Cancel a shutdown in progress.

Cancels an existing shutdown and returns to normal operation

Definition at line 668 of file channel.c.

Referenced by handle_abort_shutdown().

{
   shutting_down = 0;
}
const char* ast_cause2str ( int  cause)

Gives the string form of a given hangup cause.

Gives the string form of a given cause code.

Definition at line 794 of file channel.c.

References ARRAY_LEN, causes, and causes_map::desc.

Referenced by __transmit_response(), ast_channel_data_add_structure(), ast_hangup(), dial_exec_full(), findmeexec(), hangupcause_read(), sip_hangup(), and transmit_request_with_auth().

{
   int x;

   for (x = 0; x < ARRAY_LEN(causes); x++) {
      if (causes[x].cause == cause)
         return causes[x].desc;
   }

   return "Unknown";
}
void ast_change_name ( struct ast_channel chan,
const char *  newname 
)

Change channel name.

Precondition:
Absolutely all channels _MUST_ be unlocked before calling this function.
Parameters:
chanthe channel to change the name of
newnamethe name to change to
Returns:
nothing
Note:
this function must _NEVER_ be used when any channels are locked regardless if it is the channel who's name is being changed or not because it invalidates our channel container locking order... lock container first, then the individual channels, never the other way around.

Definition at line 6485 of file channel.c.

References __ast_change_name_nolink(), ao2_link, ao2_lock, ao2_unlink, ao2_unlock, ast_channel_lock, ast_channel_unlock, and channels.

Referenced by update_name().

{
   /* We must re-link, as the hash value will change here. */
   ao2_lock(channels);
   ast_channel_lock(chan);
   ao2_unlink(channels, chan);
   __ast_change_name_nolink(chan, newname);
   ao2_link(channels, chan);
   ast_channel_unlock(chan);
   ao2_unlock(channels);
}
struct ast_channel * ast_channel_alloc ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const char *  linkedid,
const int  amaflag,
const char *  name_fmt,
  ... 
) [read]
enum ast_bridge_result ast_channel_bridge ( struct ast_channel c0,
struct ast_channel c1,
struct ast_bridge_config config,
struct ast_frame **  fo,
struct ast_channel **  rc 
)

Bridge two channels together.

Parameters:
c0first channel to bridge
c1second channel to bridge
configconfig for the channels
fodestination frame(?)
rcdestination channel(?)

Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in *rf (remember, it could be NULL) and which channel (0 or 1) in rc

Definition at line 7834 of file channel.c.

References AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_audiohooks(), ast_channel_clear_softhangup(), ast_channel_flags(), ast_channel_framehooks(), ast_channel_generator(), ast_channel_internal_bridged_channel(), ast_channel_internal_bridged_channel_set(), ast_channel_lock_both, ast_channel_make_compatible(), ast_channel_masq(), ast_channel_masqr(), ast_channel_monitor(), ast_channel_name(), ast_channel_nativeformats(), ast_channel_readformat(), ast_channel_softhangup_internal_flag(), ast_channel_tech(), ast_channel_unlock, ast_channel_writeformat(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCUPDATE, ast_debug, AST_FEATURE_PLAY_WARNING, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_format_cap_copy(), ast_format_cap_destroy(), ast_format_cap_dup(), ast_format_cap_identical(), ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_framehook_list_is_empty(), ast_generic_bridge(), ast_indicate(), ast_log(), ast_samp2tv(), ast_set_flag, ast_set_owners_and_peers(), AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_test_suite_event_notify, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_verb, bridge_play_sounds(), bridge_playfile(), ast_bridge_config::end_sound, ast_bridge_config::feature_start_time, ast_bridge_config::feature_timer, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::flags, LOG_WARNING, manager_bridge_event(), ast_bridge_config::nexteventts, ast_bridge_config::play_warning, ast_bridge_config::start_sound, ast_bridge_config::start_time, ast_bridge_config::timelimit, update_bridge_vars(), ast_bridge_config::warning_freq, and ast_bridge_config::warning_sound.

Referenced by ast_bridge_call().

{
   enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
   struct ast_format_cap *o0nativeformats;
   struct ast_format_cap *o1nativeformats;
   long time_left_ms=0;
   char caller_warning = 0;
   char callee_warning = 0;

   *fo = NULL;

   if (ast_channel_internal_bridged_channel(c0)) {
      ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
         ast_channel_name(c0), ast_channel_name(ast_channel_internal_bridged_channel(c0)));
      return -1;
   }
   if (ast_channel_internal_bridged_channel(c1)) {
      ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
         ast_channel_name(c1), ast_channel_name(ast_channel_internal_bridged_channel(c1)));
      return -1;
   }

   /* Stop if we're a zombie or need a soft hangup */
   if (ast_test_flag(ast_channel_flags(c0), AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
       ast_test_flag(ast_channel_flags(c1), AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
      return -1;

   o0nativeformats = ast_format_cap_dup(ast_channel_nativeformats(c0));
   o1nativeformats = ast_format_cap_dup(ast_channel_nativeformats(c1));
   if (!o0nativeformats || !o1nativeformats) {
      ast_format_cap_destroy(o0nativeformats);
      ast_format_cap_destroy(o1nativeformats);
      ast_log(LOG_WARNING, "failed to copy native formats\n");
      return -1;
   }

   caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
   callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);

   if (ast_tvzero(config->start_time)) {
      config->start_time = ast_tvnow();
      if (config->start_sound) {
         if (caller_warning) {
            bridge_playfile(c0, c1, config->start_sound, config->timelimit / 1000);
         }
         if (callee_warning) {
            bridge_playfile(c1, c0, config->start_sound, config->timelimit / 1000);
         }
      }
   }

   /* Keep track of bridge */
   ast_channel_lock_both(c0, c1);
   ast_channel_internal_bridged_channel_set(c0, c1);
   ast_channel_internal_bridged_channel_set(c1, c0);
   ast_channel_unlock(c0);
   ast_channel_unlock(c1);

   ast_set_owners_and_peers(c0, c1);

   if (config->feature_timer && !ast_tvzero(config->nexteventts)) {
      config->nexteventts = ast_tvadd(config->feature_start_time, ast_samp2tv(config->feature_timer, 1000));
   } else if (config->timelimit) {
      time_left_ms = config->timelimit - ast_tvdiff_ms(ast_tvnow(), config->start_time);
      config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
      if ((caller_warning || callee_warning) && config->play_warning) {
         long next_warn = config->play_warning;
         if (time_left_ms < config->play_warning && config->warning_freq > 0) {
            /* At least one warning was played, which means we are returning after feature */
            long warns_passed = (config->play_warning - time_left_ms) / config->warning_freq;
            /* It is 'warns_passed * warning_freq' NOT '(warns_passed + 1) * warning_freq',
               because nexteventts will be updated once again in the 'if (!to)' block */
            next_warn = config->play_warning - warns_passed * config->warning_freq;
         }
         config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(next_warn, 1000));
      }
   } else {
      config->nexteventts.tv_sec = 0;
      config->nexteventts.tv_usec = 0;
   }

   if (!ast_channel_tech(c0)->send_digit_begin)
      ast_set_flag(ast_channel_flags(c1), AST_FLAG_END_DTMF_ONLY);
   if (!ast_channel_tech(c1)->send_digit_begin)
      ast_set_flag(ast_channel_flags(c0), AST_FLAG_END_DTMF_ONLY);
   manager_bridge_event(1, 1, c0, c1);

   /* Before we enter in and bridge these two together tell them both the source of audio has changed */
   ast_indicate(c0, AST_CONTROL_SRCUPDATE);
   ast_indicate(c1, AST_CONTROL_SRCUPDATE);

   for (/* ever */;;) {
      struct timeval now = { 0, };
      int to;

      to = -1;

      if (!ast_tvzero(config->nexteventts)) {
         now = ast_tvnow();
         to = ast_tvdiff_ms(config->nexteventts, now);
         if (to <= 0) {
            if (!config->timelimit) {
               res = AST_BRIDGE_COMPLETE;
               break;
            }
            to = 0;
         }
      }

      if (config->timelimit) {
         time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
         if (time_left_ms < to)
            to = time_left_ms;

         if (time_left_ms <= 0) {
            if (caller_warning && config->end_sound)
               bridge_playfile(c0, c1, config->end_sound, 0);
            if (callee_warning && config->end_sound)
               bridge_playfile(c1, c0, config->end_sound, 0);
            *fo = NULL;
            res = 0;
            ast_test_suite_event_notify("BRIDGE_TIMELIMIT", "Channel1: %s\r\nChannel2: %s", ast_channel_name(c0), ast_channel_name(c1));
            break;
         }

         if (!to) {
            if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) {
               int t = (time_left_ms + 500) / 1000; /* round to nearest second */
               if (caller_warning)
                  bridge_playfile(c0, c1, config->warning_sound, t);
               if (callee_warning)
                  bridge_playfile(c1, c0, config->warning_sound, t);
            }

            if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) {
               config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000));
            } else {
               config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
            }
         }
         ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
      }

      if ((ast_channel_softhangup_internal_flag(c0) | ast_channel_softhangup_internal_flag(c1)) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
         if (ast_channel_softhangup_internal_flag(c0) & AST_SOFTHANGUP_UNBRIDGE) {
            ast_channel_clear_softhangup(c0, AST_SOFTHANGUP_UNBRIDGE);
         }
         if (ast_channel_softhangup_internal_flag(c1) & AST_SOFTHANGUP_UNBRIDGE) {
            ast_channel_clear_softhangup(c1, AST_SOFTHANGUP_UNBRIDGE);
         }
         ast_channel_lock_both(c0, c1);
         ast_channel_internal_bridged_channel_set(c0, c1);
         ast_channel_internal_bridged_channel_set(c1, c0);
         ast_channel_unlock(c0);
         ast_channel_unlock(c1);
         ast_debug(1, "Unbridge signal received. Ending native bridge.\n");
         continue;
      }

      /* Stop if we're a zombie or need a soft hangup */
      if (ast_test_flag(ast_channel_flags(c0), AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
          ast_test_flag(ast_channel_flags(c1), AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
         *fo = NULL;
         res = 0;
         ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",
            ast_channel_name(c0), ast_channel_name(c1),
            ast_test_flag(ast_channel_flags(c0), AST_FLAG_ZOMBIE) ? "Yes" : "No",
            ast_check_hangup(c0) ? "Yes" : "No",
            ast_test_flag(ast_channel_flags(c1), AST_FLAG_ZOMBIE) ? "Yes" : "No",
            ast_check_hangup(c1) ? "Yes" : "No");
         break;
      }

      update_bridge_vars(c0, c1);

      bridge_play_sounds(c0, c1);

      if (ast_channel_tech(c0)->bridge &&
         /* if < 1 ms remains use generic bridging for accurate timing */
         (!config->timelimit || to > 1000 || to == 0) &&
          (ast_channel_tech(c0)->bridge == ast_channel_tech(c1)->bridge) &&
          !ast_channel_monitor(c0) && !ast_channel_monitor(c1) &&
          !ast_channel_audiohooks(c0) && !ast_channel_audiohooks(c1) &&
          ast_framehook_list_is_empty(ast_channel_framehooks(c0)) && ast_framehook_list_is_empty(ast_channel_framehooks(c1)) &&
          !ast_channel_masq(c0) && !ast_channel_masqr(c0) && !ast_channel_masq(c1) && !ast_channel_masqr(c1)) {
         int timeoutms = to - 1000 > 0 ? to - 1000 : to;
         /* Looks like they share a bridge method and nothing else is in the way */
         ast_set_flag(ast_channel_flags(c0), AST_FLAG_NBRIDGE);
         ast_set_flag(ast_channel_flags(c1), AST_FLAG_NBRIDGE);
         if ((res = ast_channel_tech(c0)->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) {
            manager_bridge_event(0, 1, c0, c1);
            ast_debug(1, "Returning from native bridge, channels: %s, %s\n", ast_channel_name(c0), ast_channel_name(c1));

            ast_clear_flag(ast_channel_flags(c0), AST_FLAG_NBRIDGE);
            ast_clear_flag(ast_channel_flags(c1), AST_FLAG_NBRIDGE);

            if ((ast_channel_softhangup_internal_flag(c0) | ast_channel_softhangup_internal_flag(c1)) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
               continue;
            }

            ast_channel_lock_both(c0, c1);
            ast_channel_internal_bridged_channel_set(c0, NULL);
            ast_channel_internal_bridged_channel_set(c1, NULL);
            ast_channel_unlock(c0);
            ast_channel_unlock(c1);
            ast_format_cap_destroy(o0nativeformats);
            ast_format_cap_destroy(o1nativeformats);
            return res;
         } else {
            ast_clear_flag(ast_channel_flags(c0), AST_FLAG_NBRIDGE);
            ast_clear_flag(ast_channel_flags(c1), AST_FLAG_NBRIDGE);
         }
         switch (res) {
         case AST_BRIDGE_RETRY:
            if (config->play_warning) {
               ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
            }
            continue;
         default:
            ast_verb(3, "Native bridging %s and %s ended\n", ast_channel_name(c0), ast_channel_name(c1));
            /* fallthrough */
         case AST_BRIDGE_FAILED_NOWARN:
            break;
         }
      }

      if (((ast_format_cmp(ast_channel_readformat(c1), ast_channel_writeformat(c0)) == AST_FORMAT_CMP_NOT_EQUAL) ||
         (ast_format_cmp(ast_channel_readformat(c0), ast_channel_writeformat(c1)) == AST_FORMAT_CMP_NOT_EQUAL) ||
          !ast_format_cap_identical(ast_channel_nativeformats(c0), o0nativeformats) ||
         !ast_format_cap_identical(ast_channel_nativeformats(c1), o1nativeformats)) &&
          !(ast_channel_generator(c0) || ast_channel_generator(c1))) {
         if (ast_channel_make_compatible(c0, c1)) {
            ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", ast_channel_name(c0), ast_channel_name(c1));
            manager_bridge_event(0, 1, c0, c1);
            ast_format_cap_destroy(o0nativeformats);
            ast_format_cap_destroy(o1nativeformats);
            return AST_BRIDGE_FAILED;
         }

         ast_format_cap_copy(o0nativeformats, ast_channel_nativeformats(c0));
         ast_format_cap_copy(o1nativeformats, ast_channel_nativeformats(c1));
      }

      update_bridge_vars(c0, c1);

      res = ast_generic_bridge(c0, c1, config, fo, rc);
      if (res != AST_BRIDGE_RETRY) {
         break;
      } else if (config->feature_timer) {
         /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */
         break;
      }
   }

   ast_clear_flag(ast_channel_flags(c0), AST_FLAG_END_DTMF_ONLY);
   ast_clear_flag(ast_channel_flags(c1), AST_FLAG_END_DTMF_ONLY);

   /* Now that we have broken the bridge the source will change yet again */
   ast_indicate(c0, AST_CONTROL_SRCUPDATE);
   ast_indicate(c1, AST_CONTROL_SRCUPDATE);

   ast_channel_lock_both(c0, c1);
   ast_channel_internal_bridged_channel_set(c0, NULL);
   ast_channel_internal_bridged_channel_set(c1, NULL);
   ast_channel_unlock(c0);
   ast_channel_unlock(c1);

   manager_bridge_event(0, 1, c0, c1);
   ast_debug(1, "Bridge stops bridging channels %s and %s\n", ast_channel_name(c0), ast_channel_name(c1));

   ast_format_cap_destroy(o0nativeformats);
   ast_format_cap_destroy(o1nativeformats);
   return res;
}
static int ast_channel_by_exten_cb ( void *  obj,
void *  arg,
void *  data,
int  flags 
) [static]

Definition at line 1485 of file channel.c.

References ast_channel_context(), ast_channel_exten(), ast_channel_lock, ast_channel_macrocontext(), ast_channel_macroexten(), ast_channel_unlock, ast_log(), ast_strlen_zero(), CMP_MATCH, CMP_STOP, context, ast_channel::data, exten, and LOG_ERROR.

Referenced by ast_channel_get_by_exten(), and ast_channel_iterator_by_exten_new().

{
   struct ast_channel *chan = obj;
   char *context = arg;
   char *exten = data;
   int ret = CMP_MATCH;

   if (ast_strlen_zero(exten) || ast_strlen_zero(context)) {
      ast_log(LOG_ERROR, "BUG! Must have a context and extension to match!\n");
      return CMP_STOP;
   }

   ast_channel_lock(chan);
   if (strcasecmp(ast_channel_context(chan), context) && strcasecmp(ast_channel_macrocontext(chan), context)) {
      ret = 0; /* Context match failed, continue */
   } else if (strcasecmp(ast_channel_exten(chan), exten) && strcasecmp(ast_channel_macroexten(chan), exten)) {
      ret = 0; /* Extension match failed, continue */
   }
   ast_channel_unlock(chan);

   return ret;
}
static int ast_channel_by_name_cb ( void *  obj,
void *  arg,
void *  data,
int  flags 
) [static]

Definition at line 1463 of file channel.c.

References ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_log(), ast_strlen_zero(), CMP_MATCH, CMP_STOP, LOG_ERROR, and name.

Referenced by ast_channel_get_by_name_prefix(), and ast_channel_iterator_by_name_new().

{
   struct ast_channel *chan = obj;
   const char *name = arg;
   size_t name_len = *(size_t *) data;
   int ret = CMP_MATCH;

   if (ast_strlen_zero(name)) {
      ast_log(LOG_ERROR, "BUG! Must supply a channel name or partial name to match!\n");
      return CMP_STOP;
   }

   ast_channel_lock(chan);
   if ((!name_len && strcasecmp(ast_channel_name(chan), name))
      || (name_len && strncasecmp(ast_channel_name(chan), name, name_len))) {
      ret = 0; /* name match failed, keep looking */
   }
   ast_channel_unlock(chan);

   return ret;
}
static int ast_channel_by_uniqueid_cb ( void *  obj,
void *  arg,
void *  data,
int  flags 
) [static]

Definition at line 1508 of file channel.c.

References ast_channel_lock, ast_channel_uniqueid(), ast_channel_unlock, ast_log(), ast_strlen_zero(), CMP_MATCH, CMP_STOP, LOG_ERROR, and ast_channel::uniqueid.

Referenced by ast_channel_get_by_name_prefix().

{
   struct ast_channel *chan = obj;
   char *uniqueid = arg;
   size_t id_len = *(size_t *) data;
   int ret = CMP_MATCH;

   if (ast_strlen_zero(uniqueid)) {
      ast_log(LOG_ERROR, "BUG! Must supply a uniqueid or partial uniqueid to match!\n");
      return CMP_STOP;
   }

   ast_channel_lock(chan);
   if ((!id_len && strcasecmp(ast_channel_uniqueid(chan), uniqueid))
      || (id_len && strncasecmp(ast_channel_uniqueid(chan), uniqueid, id_len))) {
      ret = 0; /* uniqueid match failed, keep looking */
   }
   ast_channel_unlock(chan);

   return ret;
}
struct ast_channel* ast_channel_callback ( ao2_callback_data_fn cb_fn,
void *  arg,
void *  data,
int  ao2_flags 
) [read]

Call a function with every active channel.

This function executes a callback one time for each active channel on the system. The channel is provided as an argument to the function.

Note:
Absolutely _NO_ channel locks should be held before calling this function.
Since:
1.8

Definition at line 1457 of file channel.c.

References ao2_callback_data, and channels.

Referenced by ast_channel_get_by_exten(), ast_channel_get_by_name_prefix(), ast_channel_iterator_by_exten_new(), ast_channel_iterator_by_name_new(), ast_pickup_find_by_group(), handle_core_set_debug_channel(), my_ast_get_channel_by_name_locked(), pickup_by_mark(), and pickup_by_part().

{
   return ao2_callback_data(channels, ao2_flags, cb_fn, arg, data);
}
int ast_channel_cc_params_init ( struct ast_channel chan,
const struct ast_cc_config_params base_params 
)

Set up datastore with CCSS parameters for a channel.

Since:
1.8
Note:
If base_params is NULL, the channel will get the default values for all CCSS parameters.

This function makes use of datastore operations on the channel, so it is important to lock the channel before calling this function.

Parameters:
chanThe channel to create the datastore on
base_paramsCCSS parameters we wish to copy into the channel
Return values:
0Success
-1Failure

Definition at line 11079 of file channel.c.

References ast_cc_config_params_destroy(), ast_cc_config_params_init, ast_cc_copy_config_params(), ast_channel_datastore_add(), ast_datastore_alloc(), and ast_datastore::data.

Referenced by ast_channel_get_cc_config_params(), dahdi_new(), local_call(), local_request(), and sip_new().

{
   struct ast_cc_config_params *cc_params;
   struct ast_datastore *cc_datastore;

   if (!(cc_params = ast_cc_config_params_init())) {
      return -1;
   }

   if (!(cc_datastore = ast_datastore_alloc(&cc_channel_datastore_info, NULL))) {
      ast_cc_config_params_destroy(cc_params);
      return -1;
   }

   if (base_params) {
      ast_cc_copy_config_params(cc_params, base_params);
   }
   cc_datastore->data = cc_params;
   ast_channel_datastore_add(chan, cc_datastore);
   return 0;
}
static void ast_channel_change_linkedid ( struct ast_channel chan,
const char *  linkedid 
) [static]

Set the channel's linkedid to the given string, and also check to see if the channel's old linkedid is now being retired

Definition at line 6626 of file channel.c.

References ast_assert, ast_cel_check_retire_linkedid(), ast_cel_linkedid_ref(), ast_channel_linkedid(), and ast_channel_linkedid_set().

Referenced by ast_channel_set_linkgroup().

{
   ast_assert(linkedid != NULL);
   /* if the linkedid for this channel is being changed from something, check... */
   if (ast_channel_linkedid(chan) && !strcmp(ast_channel_linkedid(chan), linkedid)) {
      return;
   }

   ast_cel_check_retire_linkedid(chan);
   ast_channel_linkedid_set(chan, linkedid);
   ast_cel_linkedid_ref(linkedid);
}
void ast_channel_clear_softhangup ( struct ast_channel chan,
int  flag 
)

Clear a set of softhangup flags from a channel.

Never clear a softhangup flag from a channel directly. Instead, use this function. This ensures that all aspects of the softhangup process are aborted.

Parameters:
chanthe channel to clear the flag on
flagthe flag or flags to clear
Returns:
Nothing.

Definition at line 2633 of file channel.c.

References ast_channel_lock, ast_channel_readq(), ast_channel_softhangup_internal_flag(), ast_channel_softhangup_internal_flag_clear(), ast_channel_unlock, AST_CONTROL_END_OF_Q, AST_FRAME_CONTROL, ast_frfree, AST_LIST_LAST, AST_LIST_REMOVE, ast_frame::frametype, ast_frame_subclass::integer, and ast_frame::subclass.

Referenced by __ast_pbx_run(), ast_channel_bridge(), ast_generic_bridge(), chan_cleanup(), check_goto_on_transfer(), collect_digits(), and gosub_run().

{
   ast_channel_lock(chan);

   ast_channel_softhangup_internal_flag_clear(chan, flag);

   if (!ast_channel_softhangup_internal_flag(chan)) {
      struct ast_frame *fr;

      /* If we have completely cleared the softhangup flag,
       * then we need to fully abort the hangup process.  This requires
       * pulling the END_OF_Q frame out of the channel frame queue if it
       * still happens to be there. */

      fr = AST_LIST_LAST(ast_channel_readq(chan));
      if (fr && fr->frametype == AST_FRAME_CONTROL &&
            fr->subclass.integer == AST_CONTROL_END_OF_Q) {
         AST_LIST_REMOVE(ast_channel_readq(chan), fr, frame_list);
         ast_frfree(fr);
      }
   }

   ast_channel_unlock(chan);
}
static int ast_channel_cmp_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 1607 of file channel.c.

References ast_log(), CMP_STOP, and LOG_ERROR.

Referenced by ast_channels_init().

{
   ast_log(LOG_ERROR, "BUG! Should never be called!\n");
   return CMP_STOP;
}
int ast_channel_cmpwhentohangup ( struct ast_channel chan,
time_t  offset 
)

Compare a offset with the settings of when to hang a channel up.

Parameters:
chanchannel on which to check for hang up
offsetoffset in seconds from current time
Returns:
1, 0, or -1

This function compares a offset from current time with the absolute time out on a channel (when to hang up). If the absolute time out on a channel is earlier than current time plus the offset, it returns 1, if the two time values are equal, it return 0, otherwise, it return -1.

See also:
ast_channel_cmpwhentohangup_tv()
Version:
1.6.1 deprecated function (only had seconds precision)

Definition at line 714 of file channel.c.

References ast_channel_cmpwhentohangup_tv().

{
   struct timeval when = { offset, };
   return ast_channel_cmpwhentohangup_tv(chan, when);
}
int ast_channel_cmpwhentohangup_tv ( struct ast_channel chan,
struct timeval  offset 
)

Compare a offset with when to hangup channel.

Compare a offset with the settings of when to hang a channel up.

Definition at line 699 of file channel.c.

References ast_channel_whentohangup(), ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), and ast_tvzero().

Referenced by ast_channel_cmpwhentohangup().

{
   struct timeval whentohangup;

   if (ast_tvzero(*ast_channel_whentohangup(chan)))
      return ast_tvzero(offset) ? 0 : -1;

   if (ast_tvzero(offset))
      return 1;

   whentohangup = ast_tvadd(offset, ast_tvnow());

   return ast_tvdiff_ms(whentohangup, *ast_channel_whentohangup(chan));
}
int ast_channel_connected_line_macro ( struct ast_channel autoservice_chan,
struct ast_channel macro_chan,
const void *  connected_info,
int  is_caller,
int  frame 
)

Run a connected line interception macro and update a channel's connected line information.

Since:
1.8
Deprecated:
You should use the ast_channel_connected_line_sub() function instead.

Whenever we want to update a channel's connected line information, we may need to run a macro so that an administrator can manipulate the information before sending it out. This function both runs the macro and sends the update to the channel.

Parameters:
autoservice_chanChannel to place into autoservice while the macro is running. It is perfectly safe for this to be NULL
macro_chanThe channel to run the macro on. Also the channel from which we determine which macro we need to run.
connected_infoEither an ast_party_connected_line or ast_frame pointer of type AST_CONTROL_CONNECTED_LINE
is_callerIf true, then run CONNECTED_LINE_CALLER_SEND_MACRO with arguments from CONNECTED_LINE_CALLER_SEND_MACRO_ARGS, otherwise run CONNECTED_LINE_CALLEE_SEND_MACRO with arguments from CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS
frameIf true, then connected_info is an ast_frame pointer, otherwise it is an ast_party_connected_line pointer.
Return values:
0Success
-1Either the macro does not exist, or there was an error while attempting to run the macro
Todo:

Have multiple return codes based on the MACRO_RESULT

Make constants so that caller and frame can be more expressive than just '1' and '0'

Definition at line 10870 of file channel.c.

References ast_app_run_macro(), ast_channel_connected(), ast_channel_lock, ast_channel_unlock, ast_channel_update_connected_line(), ast_connected_line_parse_data(), ast_log(), ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_strlen_zero(), chanlist::connected, ast_frame::data, ast_frame::datalen, LOG_WARNING, pbx_builtin_getvar_helper(), ast_frame::ptr, and S_OR.

Referenced by __ast_read(), app_exec(), ast_bridge_call(), ast_do_pickup(), ast_generic_bridge(), atxfer_fail_cleanup(), builtin_atxfer(), feature_request_and_dial(), handle_frame(), local_bridge_loop(), parked_call_exec(), remote_bridge_loop(), and wait_for_answer().

{
   static int deprecation_warning = 0;
   const char *macro;
   const char *macro_args;
   int retval;

   ast_channel_lock(macro_chan);
   macro = pbx_builtin_getvar_helper(macro_chan, is_caller
      ? "CONNECTED_LINE_CALLER_SEND_MACRO" : "CONNECTED_LINE_CALLEE_SEND_MACRO");
   macro = ast_strdupa(S_OR(macro, ""));
   macro_args = pbx_builtin_getvar_helper(macro_chan, is_caller
      ? "CONNECTED_LINE_CALLER_SEND_MACRO_ARGS" : "CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS");
   macro_args = ast_strdupa(S_OR(macro_args, ""));

   if (ast_strlen_zero(macro)) {
      ast_channel_unlock(macro_chan);
      return -1;
   }

   if (!deprecation_warning) {
      deprecation_warning = 1;
      ast_log(LOG_WARNING, "Usage of CONNECTED_LINE_CALLE[ER]_SEND_MACRO is deprecated.  Please use CONNECTED_LINE_SEND_SUB instead.\n");
   }
   if (is_frame) {
      const struct ast_frame *frame = connected_info;

      ast_connected_line_parse_data(frame->data.ptr, frame->datalen, ast_channel_connected(macro_chan));
   } else {
      const struct ast_party_connected_line *connected = connected_info;

      ast_party_connected_line_copy(ast_channel_connected(macro_chan), connected);
   }
   ast_channel_unlock(macro_chan);

   retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
   if (!retval) {
      struct ast_party_connected_line saved_connected;

      ast_party_connected_line_init(&saved_connected);
      ast_channel_lock(macro_chan);
      ast_party_connected_line_copy(&saved_connected, ast_channel_connected(macro_chan));
      ast_channel_unlock(macro_chan);
      ast_channel_update_connected_line(macro_chan, &saved_connected, NULL);
      ast_party_connected_line_free(&saved_connected);
   }

   return retval;
}
int ast_channel_connected_line_sub ( struct ast_channel autoservice_chan,
struct ast_channel sub_chan,
const void *  connected_info,
int  frame 
)

Run a connected line interception subroutine and update a channel's connected line information.

Since:
11 Whenever we want to update a channel's connected line information, we may need to run a subroutine so that an administrator can manipulate the information before sending it out. This function both runs the subroutine specified by CONNECTED_LINE_SEND_SUB and sends the update to the channel.
Parameters:
autoservice_chanChannel to place into autoservice while the sub is running. It is perfectly safe for this to be NULL
sub_chanThe channel to run the subroutine on. Also the channel from which we determine which subroutine we need to run.
connected_infoEither an ast_party_connected_line or ast_frame pointer of type AST_CONTROL_CONNECTED_LINE
frameIf true, then connected_info is an ast_frame pointer, otherwise it is an ast_party_connected_line pointer.
Return values:
0Success
-1Either the subroutine does not exist, or there was an error while attempting to run the subroutine

Definition at line 10970 of file channel.c.

References ast_app_run_sub(), ast_channel_connected(), ast_channel_lock, ast_channel_unlock, ast_channel_update_connected_line(), ast_connected_line_parse_data(), ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_strlen_zero(), chanlist::connected, ast_frame::data, ast_frame::datalen, pbx_builtin_getvar_helper(), ast_frame::ptr, S_OR, and sub.

Referenced by __ast_read(), app_exec(), ast_bridge_call(), ast_do_pickup(), ast_generic_bridge(), atxfer_fail_cleanup(), builtin_atxfer(), feature_request_and_dial(), handle_frame(), local_bridge_loop(), parked_call_exec(), remote_bridge_loop(), and wait_for_answer().

{
   const char *sub;
   const char *sub_args;
   int retval;

   ast_channel_lock(sub_chan);
   sub = pbx_builtin_getvar_helper(sub_chan, "CONNECTED_LINE_SEND_SUB");
   sub = ast_strdupa(S_OR(sub, ""));
   sub_args = pbx_builtin_getvar_helper(sub_chan, "CONNECTED_LINE_SEND_SUB_ARGS");
   sub_args = ast_strdupa(S_OR(sub_args, ""));

   if (ast_strlen_zero(sub)) {
      ast_channel_unlock(sub_chan);
      return -1;
   }

   if (is_frame) {
      const struct ast_frame *frame = connected_info;

      ast_connected_line_parse_data(frame->data.ptr, frame->datalen, ast_channel_connected(sub_chan));
   } else {
      const struct ast_party_connected_line *connected = connected_info;

      ast_party_connected_line_copy(ast_channel_connected(sub_chan), connected);
   }
   ast_channel_unlock(sub_chan);

   retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);
   if (!retval) {
      struct ast_party_connected_line saved_connected;

      ast_party_connected_line_init(&saved_connected);
      ast_channel_lock(sub_chan);
      ast_party_connected_line_copy(&saved_connected, ast_channel_connected(sub_chan));
      ast_channel_unlock(sub_chan);
      ast_channel_update_connected_line(sub_chan, &saved_connected, NULL);
      ast_party_connected_line_free(&saved_connected);
   }

   return retval;
}
struct ast_datastore* ast_channel_datastore_alloc ( const struct ast_datastore_info info,
const char *  uid 
) [read]

Create a channel data store object.

Note:
None of the datastore API calls lock the ast_channel they are using. So, the channel should be locked before calling the functions that take a channel argument.
Deprecated:
You should use the ast_datastore_alloc() generic function instead.
Version:
1.6.1 deprecated

Definition at line 2487 of file channel.c.

References ast_datastore_alloc().

{
   return ast_datastore_alloc(info, uid);
}
struct ast_datastore* ast_channel_datastore_find ( struct ast_channel chan,
const struct ast_datastore_info info,
const char *  uid 
) [read]

Find a datastore on a channel.

Note:
The channel should be locked before calling this function.
The datastore returned from this function must not be used if the reference to the channel is released.
Return values:
pointerto the datastore if found
NULLif not found

Definition at line 2528 of file channel.c.

References ast_channel_datastores(), AST_LIST_TRAVERSE, ast_datastore::info, and ast_datastore::uid.

Referenced by _macro_exec(), acf_curl_helper(), acf_curlopt_helper(), acf_curlopt_write(), acf_exception_read(), acf_fetch(), acf_iaxvar_read(), acf_iaxvar_write(), acf_odbc_read(), add_agi_cmd(), add_features_datastore(), add_to_agi(), apply_plc(), ast_can_pickup(), ast_cc_agent_set_interfaces_chanvar(), ast_cc_call_init(), ast_cc_completed(), ast_cc_extension_monitor_add_dialstring(), ast_cc_get_current_core_id(), ast_cc_is_recall(), ast_cc_offer(), ast_channel_get_cc_config_params(), ast_do_masquerade(), ast_handle_cc_control_frame(), ast_ignore_cc(), ast_odbc_retrieve_transaction_obj(), ast_set_cc_interfaces_chanvar(), attended_transfer_occurred(), audiohook_volume_callback(), audiohook_volume_get(), balance_stack(), builtin_atxfer(), calendar_event_read(), calendar_query_exec(), calendar_query_result_exec(), cc_build_payload(), chan_cleanup(), clear_dialed_interfaces(), dial_exec_full(), disable_jack_hook(), dundi_result_read(), enable_jack_hook(), enum_result_read(), exec_odbcfinish(), find_details(), find_speech(), find_transaction(), frame_trace_helper(), func_channel_read(), func_channel_write_real(), func_inheritance_write(), func_mute_write(), get_agi_cmd(), get_feature_ds(), get_lock(), gosub_exec(), gosub_run(), handle_gosub(), iax2_call(), jack_hook_callback(), jb_helper(), local_read(), local_write(), lock_fixup(), lua_get_state(), manage_parked_call(), manager_mutestream(), mark_transaction_active(), msg_data_func_read(), msg_datastore_find_or_create(), msg_func_read(), msg_q_cb(), msg_send_exec(), mute_callback(), parked_call_exec(), pitchshift_cb(), pitchshift_helper(), pop_exec(), queue_transfer_fixup(), raise_exception(), release_transaction(), return_exec(), set_security_requirements(), shared_read(), shared_write(), smdi_msg_read(), speech_background(), speech_destroy(), speex_callback(), speex_read(), speex_write(), srv_query_read(), srv_result_read(), stackpeek_read(), stop_mixmonitor_full(), try_calling(), unlock_read(), volume_callback(), and volume_write().

{
   struct ast_datastore *datastore = NULL;

   if (info == NULL)
      return NULL;

   AST_LIST_TRAVERSE(ast_channel_datastores(chan), datastore, entry) {
      if (datastore->info != info) {
         continue;
      }

      if (uid == NULL) {
         /* matched by type only */
         break;
      }

      if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
         /* Matched by type AND uid */
         break;
      }
   }

   return datastore;
}
int ast_channel_datastore_free ( struct ast_datastore datastore)

Free a channel data store object.

Deprecated:
You should use the ast_datastore_free() generic function instead.
Version:
1.6.1 deprecated

Definition at line 2492 of file channel.c.

References ast_datastore_free().

{
   return ast_datastore_free(datastore);
}
int ast_channel_datastore_inherit ( struct ast_channel from,
struct ast_channel to 
)

Inherit datastores from a parent to a child.

Definition at line 2497 of file channel.c.

References ast_channel_datastores(), ast_datastore_alloc(), AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_datastore_info::duplicate, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.

Referenced by __ast_request_and_dial(), begin_dial_channel(), call_forward_inherit(), dial_exec_full(), dial_transfer(), do_forward(), findmeexec(), local_call(), ring_entry(), and wait_for_answer().

{
   struct ast_datastore *datastore = NULL, *datastore2;

   AST_LIST_TRAVERSE(ast_channel_datastores(from), datastore, entry) {
      if (datastore->inheritance > 0) {
         datastore2 = ast_datastore_alloc(datastore->info, datastore->uid);
         if (datastore2) {
            datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
            datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
            AST_LIST_INSERT_TAIL(ast_channel_datastores(to), datastore2, entry);
         }
      }
   }
   return 0;
}
int ast_channel_datastore_remove ( struct ast_channel chan,
struct ast_datastore datastore 
)

Remove a datastore from a channel.

Note:
The channel should be locked before calling this function.
Return values:
0success
non-zerofailure

Definition at line 2523 of file channel.c.

References ast_channel_datastores(), and AST_LIST_REMOVE.

Referenced by acf_fetch(), acf_odbc_read(), adjust_frame_for_plc(), ast_do_masquerade(), ast_do_pickup(), chan_cleanup(), clear_dialed_interfaces(), dial_exec_full(), disable_jack_hook(), exec_odbcfinish(), frame_trace_helper(), jb_helper(), lua_get_state(), queue_transfer_fixup(), speech_background(), speech_destroy(), speex_write(), srv_query_read(), stop_mixmonitor_full(), and try_calling().

{
   return AST_LIST_REMOVE(ast_channel_datastores(chan), datastore, entry) ? 0 : -1;
}
int ast_channel_defer_dtmf ( struct ast_channel chan)

Set defer DTMF flag on channel.

Defers DTMF so that you only read things like hangups and audio.

Definition at line 1439 of file channel.c.

References ast_channel_flags(), AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.

Referenced by __adsi_transmit_messages(), and find_cache().

{
   int pre = 0;

   if (chan) {
      pre = ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF);
      ast_set_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF);
   }
   return pre;
}
static void ast_channel_destructor ( void *  obj) [static]

Free a channel structure.

Definition at line 2312 of file channel.c.

References ast_app_group_discard(), ast_atomic_fetchadd_int(), ast_callid_unref, ast_cdr_discard(), AST_CEL_CHANNEL_END, ast_cel_check_retire_linkedid(), ast_cel_report_event(), ast_channel_caller(), ast_channel_callid(), ast_channel_callid_cleanup(), ast_channel_cdr(), ast_channel_cdr_set(), ast_channel_connected(), ast_channel_datastores(), ast_channel_dialed(), ast_channel_epfd(), ast_channel_flags(), ast_channel_internal_alertpipe_close(), ast_channel_internal_cleanup(), ast_channel_internal_is_finalized(), ast_channel_lock, ast_channel_monitor(), ast_channel_music_state(), AST_CHANNEL_NAME, ast_channel_name(), ast_channel_named_callgroups_set(), ast_channel_named_pickupgroups_set(), ast_channel_nativeformats(), ast_channel_nativeformats_set(), ast_channel_pbx(), ast_channel_readq(), ast_channel_readtrans(), ast_channel_redirecting(), ast_channel_sched(), ast_channel_tech_pvt(), ast_channel_timer(), ast_channel_timer_set(), ast_channel_unlock, ast_channel_varshead(), ast_channel_writetrans(), ast_channel_zone(), ast_channel_zone_set(), ast_copy_string(), ast_datastore_free(), AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, ast_devstate_changed_literal(), AST_DEVSTATE_NOT_CACHABLE, AST_FLAG_DISABLE_DEVSTATE_CACHE, ast_format_cap_destroy(), ast_free, ast_frfree, ast_jb_destroy(), AST_LIST_REMOVE_HEAD, ast_log_callid(), AST_MAX_FDS, ast_moh_cleanup(), ast_party_caller_free(), ast_party_connected_line_free(), ast_party_dialed_free(), ast_party_redirecting_free(), ast_pbx_hangup_handler_destroy(), ast_sched_context_destroy(), ast_test_flag, ast_timer_close(), ast_tone_zone_unref(), ast_translator_free_path(), ast_var_delete(), f, LOG_WARNING, and ast_channel_monitor::stop.

Referenced by __ast_channel_alloc_ap().

{
   struct ast_channel *chan = obj;
#ifdef HAVE_EPOLL
   int i;
#endif
   struct ast_var_t *vardata;
   struct ast_frame *f;
   struct varshead *headp;
   struct ast_datastore *datastore;
   char device_name[AST_CHANNEL_NAME];
   struct ast_callid *callid;

   if (ast_channel_internal_is_finalized(chan)) {
      ast_cel_report_event(chan, AST_CEL_CHANNEL_END, NULL, NULL, NULL);
      ast_cel_check_retire_linkedid(chan);
   }

   ast_pbx_hangup_handler_destroy(chan);

   ast_channel_lock(chan);

   /* Get rid of each of the data stores on the channel */
   while ((datastore = AST_LIST_REMOVE_HEAD(ast_channel_datastores(chan), entry)))
      /* Free the data store */
      ast_datastore_free(datastore);

   /* While the channel is locked, take the reference to its callid while we tear down the call. */
   callid = ast_channel_callid(chan);
   ast_channel_callid_cleanup(chan);

   ast_channel_unlock(chan);

   /* Lock and unlock the channel just to be sure nobody has it locked still
      due to a reference that was stored in a datastore. (i.e. app_chanspy) */
   ast_channel_lock(chan);
   ast_channel_unlock(chan);

   if (ast_channel_tech_pvt(chan)) {
      ast_log_callid(LOG_WARNING, callid, "Channel '%s' may not have been hung up properly\n", ast_channel_name(chan));
      ast_free(ast_channel_tech_pvt(chan));
   }

   if (ast_channel_sched(chan)) {
      ast_sched_context_destroy(ast_channel_sched(chan));
   }

   if (ast_channel_internal_is_finalized(chan)) {
      char *dashptr;

      ast_copy_string(device_name, ast_channel_name(chan), sizeof(device_name));
      if ((dashptr = strrchr(device_name, '-'))) {
         *dashptr = '\0';
      }
   } else {
      device_name[0] = '\0';
   }

   /* Stop monitoring */
   if (ast_channel_monitor(chan))
      ast_channel_monitor(chan)->stop( chan, 0 );

   /* If there is native format music-on-hold state, free it */
   if (ast_channel_music_state(chan))
      ast_moh_cleanup(chan);

   /* Free translators */
   if (ast_channel_readtrans(chan))
      ast_translator_free_path(ast_channel_readtrans(chan));
   if (ast_channel_writetrans(chan))
      ast_translator_free_path(ast_channel_writetrans(chan));
   if (ast_channel_pbx(chan))
      ast_log_callid(LOG_WARNING, callid, "PBX may not have been terminated properly on '%s'\n", ast_channel_name(chan));

   ast_party_dialed_free(ast_channel_dialed(chan));
   ast_party_caller_free(ast_channel_caller(chan));
   ast_party_connected_line_free(ast_channel_connected(chan));
   ast_party_redirecting_free(ast_channel_redirecting(chan));

   /* Close pipes if appropriate */
   ast_channel_internal_alertpipe_close(chan);
   if (ast_channel_timer(chan)) {
      ast_timer_close(ast_channel_timer(chan));
      ast_channel_timer_set(chan, NULL);
   }
#ifdef HAVE_EPOLL
   for (i = 0; i < AST_MAX_FDS; i++) {
      if (ast_channel_internal_epfd_data(chan, i)) {
         ast_free(ast_channel_internal_epfd_data(chan, i));
      }
   }
   close(ast_channel_epfd(chan));
#endif
   while ((f = AST_LIST_REMOVE_HEAD(ast_channel_readq(chan), frame_list)))
      ast_frfree(f);

   /* loop over the variables list, freeing all data and deleting list items */
   /* no need to lock the list, as the channel is already locked */
   headp = ast_channel_varshead(chan);
   while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
      ast_var_delete(vardata);

   ast_app_group_discard(chan);

   /* Destroy the jitterbuffer */
   ast_jb_destroy(chan);

   if (ast_channel_cdr(chan)) {
      ast_cdr_discard(ast_channel_cdr(chan));
      ast_channel_cdr_set(chan, NULL);
   }

   if (ast_channel_zone(chan)) {
      ast_channel_zone_set(chan, ast_tone_zone_unref(ast_channel_zone(chan)));
   }

   ast_channel_internal_cleanup(chan);

   if (device_name[0]) {
      /*
       * We have a device name to notify of a new state.
       *
       * Queue an unknown state, because, while we know that this particular
       * instance is dead, we don't know the state of all other possible
       * instances.
       */
      ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), device_name);
   }

   ast_channel_nativeformats_set(chan, ast_format_cap_destroy(ast_channel_nativeformats(chan)));
   if (callid) {
      ast_callid_unref(callid);
   }

   ast_channel_named_callgroups_set(chan, NULL);
   ast_channel_named_pickupgroups_set(chan, NULL);

   ast_atomic_fetchadd_int(&chancount, -1);
}
int ast_channel_early_bridge ( struct ast_channel c0,
struct ast_channel c1 
)

Bridge two channels together (early)

Parameters:
c0first channel to bridge
c1second channel to bridge

Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.

Returns:
Returns 0 on success and -1 if it could not be done

Definition at line 7715 of file channel.c.

References ast_channel_tech(), and ast_channel_tech::early_bridge.

Referenced by dial_exec_full(), and wait_for_answer().

{
   /* Make sure we can early bridge, if not error out */
   if (!ast_channel_tech(c0)->early_bridge || (c1 && (!ast_channel_tech(c1)->early_bridge || ast_channel_tech(c0)->early_bridge != ast_channel_tech(c1)->early_bridge)))
      return -1;

   return ast_channel_tech(c0)->early_bridge(c0, c1);
}
struct ast_channel* ast_channel_get_by_exten ( const char *  exten,
const char *  context 
) [read]

Find a channel by extension and context.

Parameters:
extenthe extension to search for
contextthe context to search for

Return a channel that is currently at the specified extension and context.

Return values:
achannel that is at the specified extension and context
NULLif no channel was found
Since:
1.8

Definition at line 1638 of file channel.c.

References ast_channel_by_exten_cb(), and ast_channel_callback().

{
   char *l_exten = (char *) exten;
   char *l_context = (char *) context;

   return ast_channel_callback(ast_channel_by_exten_cb, l_context, l_exten, 0);
}
struct ast_channel* ast_channel_get_by_name_prefix ( const char *  name,
size_t  name_len 
) [read]

Find a channel by a name prefix.

Parameters:
nameThe channel name or uniqueid prefix to search for
name_lenOnly search for up to this many characters from the name

Find a channel that has the same name prefix as specified by the arguments.

Return values:
achannel with the name prefix specified by the arguments
NULLif no channel was found
Since:
1.8

Definition at line 1613 of file channel.c.

References ast_channel_by_name_cb(), ast_channel_by_uniqueid_cb(), ast_channel_callback(), ast_strlen_zero(), chanlist::chan, and OBJ_KEY.

Referenced by action_aocmessage(), action_bridge(), ast_channel_get_by_name(), ast_parse_device_state(), bridge_exec(), cc_generic_agent_stop_ringing(), common_exec(), handle_cli_mixmonitor(), shared_read(), and shared_write().

{
   struct ast_channel *chan;
   char *l_name = (char *) name;

   chan = ast_channel_callback(ast_channel_by_name_cb, l_name, &name_len,
      (name_len == 0) /* optimize if it is a complete name match */ ? OBJ_KEY : 0);
   if (chan) {
      return chan;
   }

   if (ast_strlen_zero(l_name)) {
      /* We didn't have a name to search for so quit. */
      return NULL;
   }

   /* Now try a search for uniqueid. */
   return ast_channel_callback(ast_channel_by_uniqueid_cb, l_name, &name_len, 0);
}
int ast_channel_get_cc_agent_type ( struct ast_channel chan,
char *  agent_type,
size_t  size 
)

Find the appropriate CC agent type to use given a channel.

Since:
1.8

During call completion, we will need to create a call completion agent structure. To figure out the type of agent to construct, we need to ask the channel driver for the appropriate type.

Prior to adding this function, the call completion core attempted to figure this out for itself by stripping the technology off the channel's name. However, in the case of chan_dahdi, there are multiple agent types registered, and so simply searching for an agent type called "DAHDI" is not possible. In a case where multiple agent types are defined, the channel driver must have a queryoption callback defined in its channel_tech, and the queryoption callback must handle AST_OPTION_CC_AGENT_TYPE

If a channel driver does not have a queryoption callback or if the queryoption callback does not handle AST_OPTION_CC_AGENT_TYPE, then the old behavior of using the technology portion of the channel name is used instead. This is perfectly suitable for channel drivers whose channel technologies are a one-to-one match with the agent types defined within.

Note that this function is only called when the agent policy on a given channel is set to "native." Generic agents' type can be determined automatically by the core.

Parameters:
chanThe channel for which we wish to retrieve the agent type
[out]agent_typeThe type of agent the channel driver wants us to use
sizeThe size of the buffer to write to

Definition at line 11141 of file channel.c.

References ast_channel_name(), ast_channel_queryoption(), ast_copy_string(), and AST_OPTION_CC_AGENT_TYPE.

Referenced by find_agent_callbacks().

{
   int len = size;
   char *slash;

   if (!ast_channel_queryoption(chan, AST_OPTION_CC_AGENT_TYPE, agent_type, &len, 0)) {
      return 0;
   }

   ast_copy_string(agent_type, ast_channel_name(chan), size);
   if ((slash = strchr(agent_type, '/'))) {
      *slash = '\0';
   }
   return 0;
}

Get the CCSS parameters from a channel.

Since:
1.8

This function makes use of datastore operations on the channel, so it is important to lock the channel before calling this function.

Parameters:
chanChannel to retrieve parameters from
Return values:
NULLFailure
non-NULLThe parameters desired

Definition at line 11102 of file channel.c.

References ast_assert, ast_channel_cc_params_init(), ast_channel_datastore_find(), and ast_datastore::data.

Referenced by acf_cc_read(), acf_cc_write(), analog_call(), ast_cc_call_failed(), ast_cc_call_init(), ast_queue_cc_frame(), cc_agent_init(), cc_core_init_instance(), find_agent_callbacks(), local_call(), local_request(), sig_pri_cc_available(), and sig_pri_cc_generic_check().

{
   struct ast_datastore *cc_datastore;

   if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
      /* If we can't find the datastore, it almost definitely means that the channel type being
       * used has not had its driver modified to parse CC config parameters. The best action
       * to take here is to create the parameters on the spot with the defaults set.
       */
      if (ast_channel_cc_params_init(chan, NULL)) {
         return NULL;
      }
      if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
         /* Should be impossible */
         return NULL;
      }
   }

   ast_assert(cc_datastore->data != NULL);
   return cc_datastore->data;
}
int ast_channel_get_device_name ( struct ast_channel chan,
char *  device_name,
size_t  name_buffer_length 
)

Get a device name given its channel structure.

Since:
1.8

A common practice in Asterisk is to determine the device being talked to by dissecting the channel name. For certain channel types, this is not accurate. For instance, an ISDN channel is named based on what B channel is used, not the device being communicated with.

This function interfaces with a channel tech's queryoption callback to retrieve the name of the device being communicated with. If the channel does not implement this specific option, then the traditional method of using the channel name is used instead.

Parameters:
chanThe channel to retrieve the information from
[out]device_nameThe buffer to place the device's name into
name_buffer_lengthThe allocated space for the device_name
Returns:
0 always

Definition at line 11124 of file channel.c.

References ast_channel_name(), ast_channel_queryoption(), ast_copy_string(), and AST_OPTION_DEVICE_NAME.

Referenced by ast_cc_call_failed(), ast_cc_is_recall(), ast_queue_cc_frame(), cc_core_init_instance(), cccancel_exec(), ccreq_exec(), dial_exec_full(), sig_pri_call(), sig_pri_cc_available(), sig_pri_cc_generic_check(), sip_call(), and sip_handle_cc().

{
   int len = name_buffer_length;
   char *dash;
   if (!ast_channel_queryoption(chan, AST_OPTION_DEVICE_NAME, device_name, &len, 0)) {
      return 0;
   }

   /* Dang. Do it the old-fashioned way */
   ast_copy_string(device_name, ast_channel_name(chan), name_buffer_length);
   if ((dash = strrchr(device_name, '-'))) {
      *dash = '\0';
   }

   return 0;
}
void ast_channel_hangupcause_hash_set ( struct ast_channel chan,
const struct ast_control_pvt_cause_code cause_code,
int  datalen 
)

Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel.

Parameters:
chanchannel on which to set the cause information
cause_codeast_control_pvt_cause_code structure containing cause information
datalentotal length of the structure since it may vary

Definition at line 4452 of file channel.c.

References ast_channel_dialed_causes_add(), ast_channel_name(), ast_func_write(), ast_log(), ast_control_pvt_cause_code::chan_name, ast_control_pvt_cause_code::code, ast_control_pvt_cause_code::emulate_sip_cause, and LOG_WARNING.

Referenced by __analog_handle_event(), __ast_request_and_dial(), ast_indicate_data(), dahdi_bridge(), dahdi_r2_on_call_disconnect(), handle_incoming(), iax2_bridge(), jingle_action_session_terminate(), local_bridge_loop(), misdn_bridge(), pri_queue_pvt_cause_data(), remote_bridge_loop(), socket_process_helper(), and ss7_queue_pvt_cause_data().

{
   char causevar[256];

   if (ast_channel_dialed_causes_add(chan, cause_code, datalen)) {
      ast_log(LOG_WARNING, "Unable to store hangup cause for %s on %s\n", cause_code->chan_name, ast_channel_name(chan));
   }

   if (cause_code->emulate_sip_cause) {
      snprintf(causevar, sizeof(causevar), "HASH(SIP_CAUSE,%s)", cause_code->chan_name);
      ast_func_write(chan, causevar, cause_code->code);
   }
}
static int ast_channel_hash_cb ( const void *  obj,
const int  flags 
) [static]

Definition at line 8475 of file channel.c.

References ast_channel_name(), ast_str_case_hash(), ast_strlen_zero(), name, and OBJ_KEY.

Referenced by ast_channels_init().

{
   const char *name = (flags & OBJ_KEY) ? obj : ast_channel_name((struct ast_channel *) obj);

   /* If the name isn't set, return 0 so that the ao2_find() search will
    * start in the first bucket. */
   if (ast_strlen_zero(name)) {
      return 0;
   }

   return ast_str_case_hash(name);
}
void ast_channel_inherit_variables ( const struct ast_channel parent,
struct ast_channel child 
)

Inherits channel variable from parent to child channel.

Parameters:
parentParent channel
childChild channel

Scans all channel variables in the parent channel, looking for those that should be copied into the child channel. Variables whose names begin with a single '_' are copied into the child channel with the prefix removed. Variables whose names begin with '__' are copied into the child channel with their names unchanged.

Definition at line 6497 of file channel.c.

References ast_channel_name(), ast_channel_varshead(), ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), and ast_var_t::entries.

Referenced by __ast_request_and_dial(), begin_dial_channel(), call_forward_inherit(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), ring_entry(), and wait_for_answer().

{
   struct ast_var_t *current, *newvar;
   const char *varname;

   AST_LIST_TRAVERSE(ast_channel_varshead((struct ast_channel *) parent), current, entries) {
      int vartype = 0;

      varname = ast_var_full_name(current);
      if (!varname)
         continue;

      if (varname[0] == '_') {
         vartype = 1;
         if (varname[1] == '_')
            vartype = 2;
      }

      switch (vartype) {
      case 1:
         newvar = ast_var_assign(&varname[1], ast_var_value(current));
         if (newvar) {
            AST_LIST_INSERT_TAIL(ast_channel_varshead(child), newvar, entries);
            ast_debug(1, "Inheriting variable %s from %s to %s.\n",
               ast_var_name(newvar), ast_channel_name(parent), ast_channel_name(child));
         }
         break;
      case 2:
         newvar = ast_var_assign(varname, ast_var_value(current));
         if (newvar) {
            AST_LIST_INSERT_TAIL(ast_channel_varshead(child), newvar, entries);
            ast_debug(1, "Inheriting variable %s from %s to %s.\n",
               ast_var_name(newvar), ast_channel_name(parent), ast_channel_name(child));
         }
         break;
      default:
         break;
      }
   }
}

Create a new channel iterator.

After creating an iterator using this function, the ast_channel_iterator_next() function can be used to iterate through all channels that exist.

Note:
You must call ast_channel_iterator_destroy() when done.
Return values:
NULLon failure
anew channel iterator
Since:
1.8

Definition at line 1587 of file channel.c.

References ast_channel_iterator::active_iterator, ao2_iterator_init(), ast_calloc, channels, and ast_channel_iterator::simple_iterator.

Referenced by action_coreshowchannels(), action_hangup(), action_status(), ast_complete_channels(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), common_exec(), data_channels_provider_handler(), func_channels_read(), handle_chanlist(), handle_show_hangup_all(), and handle_softhangup().

{
   struct ast_channel_iterator *i;

   if (!(i = ast_calloc(1, sizeof(*i)))) {
      return NULL;
   }

   i->simple_iterator = ao2_iterator_init(channels, 0);
   i->active_iterator = &i->simple_iterator;

   return i;
}
struct ast_channel_iterator* ast_channel_iterator_by_exten_new ( const char *  exten,
const char *  context 
) [read]

Create a new channel iterator based on extension.

Parameters:
extenThe extension that channels must be in
contextThe context that channels must be in

After creating an iterator using this function, the ast_channel_iterator_next() function can be used to iterate through all channels that are currently in the specified context and extension.

Note:
You must call ast_channel_iterator_destroy() when done.
Return values:
NULLon failure
anew channel iterator based on the specified parameters
Since:
1.8

Definition at line 1547 of file channel.c.

References ast_channel_iterator::active_iterator, ast_calloc, ast_channel_by_exten_cb(), ast_channel_callback(), ast_free, and OBJ_MULTIPLE.

Referenced by common_exec(), and pickup_by_exten().

{
   struct ast_channel_iterator *i;
   char *l_exten = (char *) exten;
   char *l_context = (char *) context;

   if (!(i = ast_calloc(1, sizeof(*i)))) {
      return NULL;
   }

   i->active_iterator = (void *) ast_channel_callback(ast_channel_by_exten_cb,
      l_context, l_exten, OBJ_MULTIPLE);
   if (!i->active_iterator) {
      ast_free(i);
      return NULL;
   }

   return i;
}
struct ast_channel_iterator* ast_channel_iterator_by_name_new ( const char *  name,
size_t  name_len 
) [read]

Create a new channel iterator based on name.

Parameters:
namechannel name or channel uniqueid to match
name_lennumber of characters in the channel name to match on. This would be used to match based on name prefix. If matching on the full channel name is desired, then this parameter should be 0.

After creating an iterator using this function, the ast_channel_iterator_next() function can be used to iterate through all channels that exist that have the specified name or name prefix.

Note:
You must call ast_channel_iterator_destroy() when done.
Return values:
NULLon failure
anew channel iterator based on the specified parameters
Since:
1.8

Definition at line 1567 of file channel.c.

References ast_channel_iterator::active_iterator, ast_calloc, ast_channel_by_name_cb(), ast_channel_callback(), ast_free, OBJ_KEY, and OBJ_MULTIPLE.

Referenced by ast_complete_channels(), common_exec(), get_device_state_causing_channels(), and softhangup_exec().

{
   struct ast_channel_iterator *i;
   char *l_name = (char *) name;

   if (!(i = ast_calloc(1, sizeof(*i)))) {
      return NULL;
   }

   i->active_iterator = (void *) ast_channel_callback(ast_channel_by_name_cb,
      l_name, &name_len,
      OBJ_MULTIPLE | (name_len == 0 /* match the whole word, so optimize */ ? OBJ_KEY : 0));
   if (!i->active_iterator) {
      ast_free(i);
      return NULL;
   }

   return i;
}

Destroy a channel iterator.

Parameters:
ithe itereator to destroy

This function is used to destroy a channel iterator that was retrieved by using one of the channel_iterator_xxx_new() functions.

Returns:
NULL, for convenience to clear out the pointer to the iterator that was just destroyed.
Since:
1.8

Definition at line 1539 of file channel.c.

References ast_channel_iterator::active_iterator, ao2_iterator_destroy(), and ast_free.

Referenced by action_coreshowchannels(), action_hangup(), action_status(), ast_complete_channels(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), common_exec(), data_channels_provider_handler(), func_channels_read(), get_device_state_causing_channels(), handle_chanlist(), handle_show_hangup_all(), handle_softhangup(), pickup_by_exten(), and softhangup_exec().

{
   ao2_iterator_destroy(i->active_iterator);
   ast_free(i);

   return NULL;
}

Get the next channel for a channel iterator.

Parameters:
ithe channel iterator that was created using one of the channel_iterator_xxx_new() functions.

This function should be used to iterate through all channels that match a specified set of parameters that were provided when the iterator was created.

Return values:
thenext channel that matches the parameters used when the iterator was created.
NULL,ifno more channels match the iterator parameters.
Since:
1.8

Definition at line 1601 of file channel.c.

References ast_channel_iterator::active_iterator, and ao2_iterator_next.

Referenced by action_coreshowchannels(), action_hangup(), action_status(), ast_complete_channels(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), data_channels_provider_handler(), func_channels_read(), get_device_state_causing_channels(), handle_chanlist(), handle_show_hangup_all(), handle_softhangup(), next_channel(), pickup_by_exten(), and softhangup_exec().

int ast_channel_make_compatible ( struct ast_channel c0,
struct ast_channel c1 
)

Makes two channel formats compatible.

Parameters:
c0first channel to make compatible
c1other channel to make compatible

Set two channels to compatible formats -- call before ast_channel_bridge in general.

Returns:
Returns 0 on success and -1 if it could not be done

Definition at line 6221 of file channel.c.

References ast_channel_make_compatible_helper().

Referenced by action_bridge(), app_exec(), ast_channel_bridge(), bridge_exec(), check_compat(), dial_exec_full(), do_forward(), fax_detect_framehook(), fax_gateway_framehook(), multiplexed_bridge_join(), parked_call_exec(), simple_bridge_join(), try_calling(), and wait_for_answer().

{
   /* Some callers do not check return code, and we must try to set all call legs correctly */
   int rc = 0;

   /* Set up translation from the chan to the peer */
   rc = ast_channel_make_compatible_helper(chan, peer);

   if (rc < 0)
      return rc;

   /* Set up translation from the peer to the chan */
   rc = ast_channel_make_compatible_helper(peer, chan);

   return rc;
}
static int ast_channel_make_compatible_helper ( struct ast_channel from,
struct ast_channel to 
) [static]

Set up translation from one channel to another.

Definition at line 6163 of file channel.c.

References ast_channel_name(), ast_channel_nativeformats(), ast_channel_readformat(), ast_channel_setoption(), ast_channel_tech(), ast_channel_writeformat(), ast_format_cap_has_type(), ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_is_slinear(), ast_format_rate(), ast_format_set(), ast_format_slin_by_rate(), AST_FORMAT_TYPE_AUDIO, ast_getformatname(), ast_log(), ast_opt_generic_plc, ast_opt_transcode_via_slin, AST_OPTION_MAKE_COMPATIBLE, ast_set_read_format(), ast_set_write_format(), ast_translate_path_steps(), ast_translator_best_choice(), and LOG_WARNING.

Referenced by ast_channel_make_compatible().

{
   struct ast_format_cap *src_cap = ast_channel_nativeformats(from); /* shallow copy, do not destroy */
   struct ast_format_cap *dst_cap = ast_channel_nativeformats(to);   /* shallow copy, do not destroy */
   struct ast_format best_src_fmt;
   struct ast_format best_dst_fmt;
   int use_slin;

   /* See if the channel driver can natively make these two channels compatible */
   if (ast_channel_tech(from)->bridge && ast_channel_tech(from)->bridge == ast_channel_tech(to)->bridge &&
       !ast_channel_setoption(from, AST_OPTION_MAKE_COMPATIBLE, to, sizeof(struct ast_channel *), 0)) {
      return 0;
   }

   if ((ast_format_cmp(ast_channel_readformat(from), ast_channel_writeformat(to)) != AST_FORMAT_CMP_NOT_EQUAL) &&
      (ast_format_cmp(ast_channel_readformat(to), ast_channel_writeformat(from)) != AST_FORMAT_CMP_NOT_EQUAL)) {
      /* Already compatible!  Moving on ... */
      return 0;
   }

   /* If there's no audio in this call, don't bother with trying to find a translation path */
   if (!ast_format_cap_has_type(src_cap, AST_FORMAT_TYPE_AUDIO) || !ast_format_cap_has_type(dst_cap, AST_FORMAT_TYPE_AUDIO))
      return 0;

   if (ast_translator_best_choice(dst_cap, src_cap, &best_src_fmt, &best_dst_fmt) < 0) {
      ast_log(LOG_WARNING, "No path to translate from %s to %s\n", ast_channel_name(from), ast_channel_name(to));
      return -1;
   }

   /* if the best path is not 'pass through', then
    * transcoding is needed; if desired, force transcode path
    * to use SLINEAR between channels, but only if there is
    * no direct conversion available. If generic PLC is
    * desired, then transcoding via SLINEAR is a requirement
    */
   use_slin = ast_format_is_slinear(&best_src_fmt) || ast_format_is_slinear(&best_dst_fmt) ? 1 : 0;
   if ((ast_format_cmp(&best_src_fmt, &best_dst_fmt) == AST_FORMAT_CMP_NOT_EQUAL) &&
      (ast_opt_generic_plc || ast_opt_transcode_via_slin) &&
       (ast_translate_path_steps(&best_dst_fmt, &best_src_fmt) != 1 || use_slin)) {

      int best_sample_rate = ast_format_rate(&best_src_fmt) > ast_format_rate(&best_dst_fmt) ?
         ast_format_rate(&best_src_fmt) : ast_format_rate(&best_dst_fmt);

      /* pick the best signed linear format based upon what preserves the sample rate the best. */
      ast_format_set(&best_dst_fmt, ast_format_slin_by_rate(best_sample_rate), 0);
   }

   if (ast_set_read_format(from, &best_dst_fmt) < 0) {
      ast_log(LOG_WARNING, "Unable to set read format on channel %s to %s\n", ast_channel_name(from), ast_getformatname(&best_dst_fmt));
      return -1;
   }
   if (ast_set_write_format(to, &best_dst_fmt) < 0) {
      ast_log(LOG_WARNING, "Unable to set write format on channel %s to %s\n", ast_channel_name(to), ast_getformatname(&best_dst_fmt));
      return -1;
   }
   return 0;
}
int ast_channel_masquerade ( struct ast_channel original,
struct ast_channel clone 
)

Weird function made for call transfers.

Parameters:
originalchannel to make a copy of
clonecopy of the original channel

This is a very strange and freaky function used primarily for transfer. Suppose that "original" and "clone" are two channels in random situations. This function takes the guts out of "clone" and puts them into the "original" channel, then alerts the channel driver of the change, asking it to fixup any private information (like the p->owner pointer) that is affected by the change. The physical layer of the original channel is hung up.

Note:
Neither channel passed here should be locked before calling this function. This function performs deadlock avoidance involving these two channels.

Definition at line 6361 of file channel.c.

References __ast_channel_masquerade().

Referenced by ast_async_goto(), ast_do_pickup(), attempt_transfer(), builtin_atxfer(), check_availability(), check_bridge(), check_goto_on_transfer(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), masq_park_call(), sip_park(), and skinny_transfer().

{
   return __ast_channel_masquerade(original, clone, NULL);
}
int ast_channel_queryoption ( struct ast_channel channel,
int  option,
void *  data,
int *  datalen,
int  block 
)

Checks the value of an option.

Query the value of an option Works similarly to setoption except only reads the options.

Definition at line 8131 of file channel.c.

References ast_channel_lock, ast_channel_tech(), ast_channel_unlock, ast_log(), errno, LOG_ERROR, and ast_channel_tech::queryoption.

Referenced by ast_channel_get_cc_agent_type(), ast_channel_get_device_name(), ast_channel_get_t38_state(), local_queryoption(), rcvfax_exec(), and sndfax_exec().

{
   int res;

   ast_channel_lock(chan);
   if (!ast_channel_tech(chan)->queryoption) {
      errno = ENOSYS;
      ast_channel_unlock(chan);
      return -1;
   }

   if (block)
      ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");

   res = ast_channel_tech(chan)->queryoption(chan, option, data, datalen);
   ast_channel_unlock(chan);

   return res;
}
void ast_channel_queue_connected_line_update ( struct ast_channel chan,
const struct ast_party_connected_line connected,
const struct ast_set_party_connected_line update 
)

Queue a connected line update frame on a channel.

Since:
1.8
Parameters:
chanAsterisk channel to indicate connected line information
connectedConnected line information
updateWhat connected line information to update. NULL if all.
Returns:
Nothing

Definition at line 9729 of file channel.c.

References ast_connected_line_build_data(), AST_CONTROL_CONNECTED_LINE, and ast_queue_control_data().

Referenced by ast_do_pickup(), handle_request_invite(), handle_request_update(), handle_response_invite(), local_attended_transfer(), masquerade_colp_transfer(), misdn_queue_connected_line_update(), sig_pri_handle_subcmds(), and sip_call().

{
   unsigned char data[1024];  /* This should be large enough */
   size_t datalen;

   datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
   if (datalen == (size_t) -1) {
      return;
   }

   ast_queue_control_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
}
void ast_channel_queue_redirecting_update ( struct ast_channel chan,
const struct ast_party_redirecting redirecting,
const struct ast_set_party_redirecting update 
)

Queue a redirecting update frame on a channel.

Since:
1.8
Parameters:
chanAsterisk channel to indicate redirecting id information
redirectingRedirecting id information
updateWhat redirecting information to update. NULL if all.
Returns:
Nothing

Definition at line 10857 of file channel.c.

References AST_CONTROL_REDIRECTING, ast_queue_control_data(), and ast_redirecting_build_data().

Referenced by cb_events(), handle_response_invite(), misdn_facility_ie_handler(), and sig_pri_handle_subcmds().

{
   unsigned char data[1024];  /* This should be large enough */
   size_t datalen;

   datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
   if (datalen == (size_t) -1) {
      return;
   }

   ast_queue_control_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
}
const char* ast_channel_reason2str ( int  reason)

return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument

Parameters:
reasonThe integer argument, usually taken from AST_CONTROL_ macros
Returns:
char pointer explaining the code

Definition at line 5501 of file channel.c.

References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RING, and AST_CONTROL_RINGING.

Referenced by attempt_thread().

{
   switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
   {
   case 0:
      return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
   case AST_CONTROL_HANGUP:
      return "Hangup";
   case AST_CONTROL_RING:
      return "Local Ring";
   case AST_CONTROL_RINGING:
      return "Remote end Ringing";
   case AST_CONTROL_ANSWER:
      return "Remote end has Answered";
   case AST_CONTROL_BUSY:
      return "Remote end is Busy";
   case AST_CONTROL_CONGESTION:
      return "Congestion (circuits busy)";
   default:
      return "Unknown Reason!!";
   }
}
int ast_channel_redirecting_macro ( struct ast_channel autoservice_chan,
struct ast_channel macro_chan,
const void *  redirecting_info,
int  is_caller,
int  is_frame 
)

Run a redirecting interception macro and update a channel's redirecting information.

Since:
1.8
Deprecated:
You should use the ast_channel_redirecting_sub() function instead.

Whenever we want to update a channel's redirecting information, we may need to run a macro so that an administrator can manipulate the information before sending it out. This function both runs the macro and sends the update to the channel.

Parameters:
autoservice_chanChannel to place into autoservice while the macro is running. It is perfectly safe for this to be NULL
macro_chanThe channel to run the macro on. Also the channel from which we determine which macro we need to run.
redirecting_infoEither an ast_party_redirecting or ast_frame pointer of type AST_CONTROL_REDIRECTING
is_callerIf true, then run REDIRECTING_CALLER_SEND_MACRO with arguments from REDIRECTING_CALLER_SEND_MACRO_ARGS, otherwise run REDIRECTING_CALLEE_SEND_MACRO with arguments from REDIRECTING_CALLEE_SEND_MACRO_ARGS
is_frameIf true, then redirecting_info is an ast_frame pointer, otherwise it is an ast_party_redirecting pointer.
Return values:
0Success
-1Either the macro does not exist, or there was an error while attempting to run the macro
Todo:

Have multiple return codes based on the MACRO_RESULT

Make constants so that caller and frame can be more expressive than just '1' and '0'

Definition at line 10920 of file channel.c.

References ast_app_run_macro(), ast_channel_lock, ast_channel_redirecting(), ast_channel_unlock, ast_channel_update_redirecting(), ast_log(), ast_party_redirecting_copy(), ast_party_redirecting_free(), ast_party_redirecting_init(), ast_redirecting_parse_data(), ast_strlen_zero(), ast_frame::data, ast_frame::datalen, LOG_WARNING, pbx_builtin_getvar_helper(), ast_frame::ptr, and S_OR.

Referenced by ast_bridge_call(), ast_generic_bridge(), call_forward_inherit(), do_forward(), feature_request_and_dial(), handle_frame(), local_bridge_loop(), remote_bridge_loop(), and wait_for_answer().

{
   static int deprecation_warning = 0;
   const char *macro;
   const char *macro_args;
   int retval;

   ast_channel_lock(macro_chan);
   macro = pbx_builtin_getvar_helper(macro_chan, is_caller
      ? "REDIRECTING_CALLER_SEND_MACRO" : "REDIRECTING_CALLEE_SEND_MACRO");
   macro = ast_strdupa(S_OR(macro, ""));
   macro_args = pbx_builtin_getvar_helper(macro_chan, is_caller
      ? "REDIRECTING_CALLER_SEND_MACRO_ARGS" : "REDIRECTING_CALLEE_SEND_MACRO_ARGS");
   macro_args = ast_strdupa(S_OR(macro_args, ""));

   if (ast_strlen_zero(macro)) {
      ast_channel_unlock(macro_chan);
      return -1;
   }

   if (!deprecation_warning) {
      deprecation_warning = 1;
      ast_log(LOG_WARNING, "Usage of REDIRECTING_CALLE[ER]_SEND_MACRO is deprecated.  Please use REDIRECTING_SEND_SUB instead.\n");
   }
   if (is_frame) {
      const struct ast_frame *frame = redirecting_info;

      ast_redirecting_parse_data(frame->data.ptr, frame->datalen, ast_channel_redirecting(macro_chan));
   } else {
      const struct ast_party_redirecting *redirecting = redirecting_info;

      ast_party_redirecting_copy(ast_channel_redirecting(macro_chan), redirecting);
   }
   ast_channel_unlock(macro_chan);

   retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
   if (!retval) {
      struct ast_party_redirecting saved_redirecting;

      ast_party_redirecting_init(&saved_redirecting);
      ast_channel_lock(macro_chan);
      ast_party_redirecting_copy(&saved_redirecting, ast_channel_redirecting(macro_chan));
      ast_channel_unlock(macro_chan);
      ast_channel_update_redirecting(macro_chan, &saved_redirecting, NULL);
      ast_party_redirecting_free(&saved_redirecting);
   }

   return retval;
}
int ast_channel_redirecting_sub ( struct ast_channel autoservice_chan,
struct ast_channel sub_chan,
const void *  redirecting_info,
int  is_frame 
)

Run a redirecting interception subroutine and update a channel's redirecting information.

Since:
11

Whenever we want to update a channel's redirecting information, we may need to run a subroutine so that an administrator can manipulate the information before sending it out. This function both runs the subroutine specified by REDIRECTING_SEND_SUB and sends the update to the channel.

Parameters:
autoservice_chanChannel to place into autoservice while the subroutine is running. It is perfectly safe for this to be NULL
sub_chanThe channel to run the subroutine on. Also the channel from which we determine which subroutine we need to run.
redirecting_infoEither an ast_party_redirecting or ast_frame pointer of type AST_CONTROL_REDIRECTING
is_frameIf true, then redirecting_info is an ast_frame pointer, otherwise it is an ast_party_redirecting pointer.
Return values:
0Success
-1Either the subroutine does not exist, or there was an error while attempting to run the subroutine

Definition at line 11013 of file channel.c.

References ast_app_run_sub(), ast_channel_lock, ast_channel_redirecting(), ast_channel_unlock, ast_channel_update_redirecting(), ast_party_redirecting_copy(), ast_party_redirecting_free(), ast_party_redirecting_init(), ast_redirecting_parse_data(), ast_strlen_zero(), ast_frame::data, ast_frame::datalen, pbx_builtin_getvar_helper(), ast_frame::ptr, S_OR, and sub.

Referenced by ast_bridge_call(), ast_generic_bridge(), call_forward_inherit(), do_forward(), feature_request_and_dial(), handle_frame(), local_bridge_loop(), remote_bridge_loop(), and wait_for_answer().

{
   const char *sub;
   const char *sub_args;
   int retval;

   ast_channel_lock(sub_chan);
   sub = pbx_builtin_getvar_helper(sub_chan, "REDIRECTING_SEND_SUB");
   sub = ast_strdupa(S_OR(sub, ""));
   sub_args = pbx_builtin_getvar_helper(sub_chan, "REDIRECTING_SEND_SUB_ARGS");
   sub_args = ast_strdupa(S_OR(sub_args, ""));

   if (ast_strlen_zero(sub)) {
      ast_channel_unlock(sub_chan);
      return -1;
   }

   if (is_frame) {
      const struct ast_frame *frame = redirecting_info;

      ast_redirecting_parse_data(frame->data.ptr, frame->datalen, ast_channel_redirecting(sub_chan));
   } else {
      const struct ast_party_redirecting *redirecting = redirecting_info;

      ast_party_redirecting_copy(ast_channel_redirecting(sub_chan), redirecting);
   }
   ast_channel_unlock(sub_chan);

   retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);
   if (!retval) {
      struct ast_party_redirecting saved_redirecting;

      ast_party_redirecting_init(&saved_redirecting);
      ast_channel_lock(sub_chan);
      ast_party_redirecting_copy(&saved_redirecting, ast_channel_redirecting(sub_chan));
      ast_channel_unlock(sub_chan);
      ast_channel_update_redirecting(sub_chan, &saved_redirecting, NULL);
      ast_party_redirecting_free(&saved_redirecting);
   }

   return retval;
}
int ast_channel_register ( const struct ast_channel_tech tech)

Register a new telephony channel in Asterisk.

Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.

Definition at line 721 of file channel.c.

References ast_calloc, ast_debug, ast_log(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::chan, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.

Referenced by load_module(), and unload_module().

{
   struct chanlist *chan;

   AST_RWLIST_WRLOCK(&backends);

   AST_RWLIST_TRAVERSE(&backends, chan, list) {
      if (!strcasecmp(tech->type, chan->tech->type)) {
         ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
         AST_RWLIST_UNLOCK(&backends);
         return -1;
      }
   }

   if (!(chan = ast_calloc(1, sizeof(*chan)))) {
      AST_RWLIST_UNLOCK(&backends);
      return -1;
   }
   chan->tech = tech;
   AST_RWLIST_INSERT_HEAD(&backends, chan, list);

   ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);

   ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description);

   AST_RWLIST_UNLOCK(&backends);

   return 0;
}
struct ast_channel* ast_channel_release ( struct ast_channel chan) [read]

Unlink and release reference to a channel.

This function will unlink the channel from the global channels container if it is still there and also release the current reference to the channel.

Returns:
NULL, convenient for clearing invalid pointers
Note:
Absolutely _NO_ channel locks should be held before calling this function.
Since:
1.8

Definition at line 1749 of file channel.c.

References ao2_unlink, ast_channel_unref, and channels.

Referenced by agent_cleanup(), ast_iax2_new(), ast_request(), bridge_request(), destroy_msg_q_chan(), do_notify(), gtalk_newcall(), local_new(), and local_request().

{
   /* Safe, even if already unlinked. */
   ao2_unlink(channels, chan);
   return ast_channel_unref(chan);
}
int ast_channel_sendhtml ( struct ast_channel channel,
int  subclass,
const char *  data,
int  datalen 
)

Sends HTML on given channel Send HTML or URL on link.

Returns:
0 on success or -1 on failure

Definition at line 6150 of file channel.c.

References ast_channel_tech(), and ast_channel_tech::send_html.

Referenced by agent_sendhtml(), ast_channel_sendurl(), and wait_for_answer().

{
   if (ast_channel_tech(chan)->send_html)
      return ast_channel_tech(chan)->send_html(chan, subclass, data, datalen);
   return -1;
}
int ast_channel_sendurl ( struct ast_channel channel,
const char *  url 
)

Sends a URL on a given link Send URL on link.

Returns:
0 on success or -1 on failure

Definition at line 6157 of file channel.c.

References ast_channel_sendhtml(), and AST_HTML_URL.

Referenced by dial_exec_full(), sendurl_exec(), and try_calling().

{
   return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
}
void ast_channel_set_caller ( struct ast_channel chan,
const struct ast_party_caller caller,
const struct ast_set_party_caller update 
)

Set the caller id information in the Asterisk channel.

Since:
1.8
Parameters:
chanAsterisk channel to set caller id information
callerCaller id information
updateWhat caller information to update. NULL if all.
Returns:
Nothing
Note:
The channel does not need to be locked before calling this function.

Definition at line 7349 of file channel.c.

References ast_channel_caller(), ast_channel_lock, ast_channel_unlock, and ast_party_caller_set().

{
   if (ast_channel_caller(chan) == caller) {
      /* Don't set to self */
      return;
   }

   ast_channel_lock(chan);
   ast_party_caller_set(ast_channel_caller(chan), caller, update);
   ast_channel_unlock(chan);
}
void ast_channel_set_caller_event ( struct ast_channel chan,
const struct ast_party_caller caller,
const struct ast_set_party_caller update 
)

Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name or number changed.

Since:
1.8
Parameters:
chanAsterisk channel to set caller id information
callerCaller id information
updateWhat caller information to update. NULL if all.
Returns:
Nothing
Note:
The channel does not need to be locked before calling this function.

Definition at line 7361 of file channel.c.

References ast_cdr_setcid(), ast_channel_caller(), ast_channel_cdr(), ast_channel_lock, ast_channel_unlock, ast_party_caller_set(), name, report_new_callerid(), and S_COR.

Referenced by callerid_write(), dial_exec_full(), do_forward(), misdn_update_caller_id(), ring_entry(), and sig_pri_handle_subcmds().

{
   const char *pre_set_number;
   const char *pre_set_name;

   if (ast_channel_caller(chan) == caller) {
      /* Don't set to self */
      return;
   }

   ast_channel_lock(chan);
   pre_set_number =
      S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL);
   pre_set_name = S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, NULL);
   ast_party_caller_set(ast_channel_caller(chan), caller, update);
   if (S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)
         != pre_set_number
      || S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, NULL)
         != pre_set_name) {
      /* The caller id name or number changed. */
      report_new_callerid(chan);
   }
   if (ast_channel_cdr(chan)) {
      ast_cdr_setcid(ast_channel_cdr(chan), chan);
   }
   ast_channel_unlock(chan);
}
void ast_channel_set_connected_line ( struct ast_channel chan,
const struct ast_party_connected_line connected,
const struct ast_set_party_connected_line update 
)

Set the connected line information in the Asterisk channel.

Since:
1.8
Parameters:
chanAsterisk channel to set connected line information
connectedConnected line information
updateWhat connected line information to update. NULL if all.
Returns:
Nothing
Note:
The channel does not need to be locked before calling this function.

Definition at line 8933 of file channel.c.

References ast_channel_connected(), ast_channel_lock, ast_channel_unlock, and ast_party_connected_line_set().

Referenced by __ast_request_and_dial(), ast_indicate_data(), connectedline_write(), dial_exec_full(), and feature_request_and_dial().

{
   if (ast_channel_connected(chan) == connected) {
      /* Don't set to self */
      return;
   }

   ast_channel_lock(chan);
   ast_party_connected_line_set(ast_channel_connected(chan), connected, update);
   ast_channel_unlock(chan);
}
void ast_channel_set_fd ( struct ast_channel chan,
int  which,
int  fd 
)

Set the file descriptor on the channel

Definition at line 2555 of file channel.c.

References ast_calloc, ast_channel_epfd(), ast_channel_fd(), ast_channel_fd_isset(), ast_channel_internal_fd_set(), ast_free, ast_epoll_data::chan, chanlist::chan, and ast_epoll_data::which.

Referenced by __ast_channel_alloc_ap(), __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), alsa_new(), ast_deactivate_generator(), ast_do_masquerade(), dahdi_new(), gtalk_new(), initialize_udptl(), internal_deactivate_generator(), jb_helper(), jingle_enable_video(), jingle_new(), mgcp_new(), misdn_new(), my_swap_subchannels(), nbs_new(), oss_new(), phone_new(), process_sdp(), setformat(), sip_new(), sip_set_rtp_peer(), skinny_new(), start_rtp(), and swap_subs().

{
#ifdef HAVE_EPOLL
   struct epoll_event ev;
   struct ast_epoll_data *aed = NULL;

   if (ast_channel_fd_isset(chan, which)) {
      epoll_ctl(ast_channel_epfd(chan), EPOLL_CTL_DEL, ast_channel_fd(chan, which), &ev);
      aed = ast_channel_internal_epfd_data(chan, which);
   }

   /* If this new fd is valid, add it to the epoll */
   if (fd > -1) {
      if (!aed && (!(aed = ast_calloc(1, sizeof(*aed)))))
         return;

      ast_channel_internal_epfd_data_set(chan, which, aed);
      aed->chan = chan;
      aed->which = which;

      ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
      ev.data.ptr = aed;
      epoll_ctl(ast_channel_epfd(chan), EPOLL_CTL_ADD, fd, &ev);
   } else if (aed) {
      /* We don't have to keep around this epoll data structure now */
      ast_free(aed);
      ast_channel_epfd_data_set(chan, which, NULL);
   }
#endif
   ast_channel_internal_fd_set(chan, which, fd);
   return;
}
void ast_channel_set_linkgroup ( struct ast_channel chan,
struct ast_channel peer 
)

Propagate the oldest linkedid between associated channels.

propagate the linked id between chan and peer

Definition at line 6643 of file channel.c.

References ast_bridged_channel(), ast_channel_change_linkedid(), ast_channel_internal_bridged_channel(), ast_channel_linkedid(), ast_channel_uniqueid(), and oldest_linkedid().

Referenced by ast_bridge_call(), and ast_do_masquerade().

{
   const char* linkedid=NULL;
   struct ast_channel *bridged;

   linkedid = oldest_linkedid(ast_channel_linkedid(chan), ast_channel_linkedid(peer));
   linkedid = oldest_linkedid(linkedid, ast_channel_uniqueid(chan));
   linkedid = oldest_linkedid(linkedid, ast_channel_uniqueid(peer));
   if (ast_channel_internal_bridged_channel(chan)) {
      bridged = ast_bridged_channel(chan);
      if (bridged && bridged != peer) {
         linkedid = oldest_linkedid(linkedid, ast_channel_linkedid(bridged));
         linkedid = oldest_linkedid(linkedid, ast_channel_uniqueid(bridged));
      }
   }
   if (ast_channel_internal_bridged_channel(peer)) {
      bridged = ast_bridged_channel(peer);
      if (bridged && bridged != chan) {
         linkedid = oldest_linkedid(linkedid, ast_channel_linkedid(bridged));
         linkedid = oldest_linkedid(linkedid, ast_channel_uniqueid(bridged));
      }
   }

   /* just in case setting a stringfield to itself causes problems */
   linkedid = ast_strdupa(linkedid);

   ast_channel_change_linkedid(chan, linkedid);
   ast_channel_change_linkedid(peer, linkedid);
   if (ast_channel_internal_bridged_channel(chan)) {
      bridged = ast_bridged_channel(chan);
      if (bridged && bridged != peer) {
         ast_channel_change_linkedid(bridged, linkedid);
      }
   }
   if (ast_channel_internal_bridged_channel(peer)) {
      bridged = ast_bridged_channel(peer);
      if (bridged && bridged != chan) {
         ast_channel_change_linkedid(bridged, linkedid);
      }
   }
}
void ast_channel_set_redirecting ( struct ast_channel chan,
const struct ast_party_redirecting redirecting,
const struct ast_set_party_redirecting update 
)

Set the redirecting id information in the Asterisk channel.

Since:
1.8
Parameters:
chanAsterisk channel to set redirecting id information
redirectingRedirecting id information
updateWhat redirecting information to update. NULL if all.
Returns:
Nothing
Note:
The channel does not need to be locked before calling this function.

Definition at line 9742 of file channel.c.

References ast_channel_lock, ast_channel_redirecting(), ast_channel_unlock, and ast_party_redirecting_set().

Referenced by ast_indicate_data(), handle_request_invite(), handle_response(), misdn_copy_redirecting_to_ast(), redirecting_write(), and sig_pri_handle_subcmds().

{
   if (ast_channel_redirecting(chan) == redirecting) {
      /* Don't set to self */
      return;
   }

   ast_channel_lock(chan);
   ast_party_redirecting_set(ast_channel_redirecting(chan), redirecting, update);
   ast_channel_unlock(chan);
}
int ast_channel_setoption ( struct ast_channel channel,
int  option,
void *  data,
int  datalen,
int  block 
)

Sets an option on a channel.

Parameters:
channelchannel to set options on
optionoption to change
datadata specific to option
datalenlength of the data
blockblocking or not

Set an option on a channel (see frame.h), optionally blocking awaiting the reply

Returns:
0 on success and -1 on failure

Definition at line 8111 of file channel.c.

References ast_channel_lock, ast_channel_tech(), ast_channel_unlock, ast_log(), errno, LOG_ERROR, and ast_channel_tech::setoption.

Referenced by analog_hangup(), ast_bridge_call(), ast_channel_make_compatible_helper(), common_exec(), conf_run(), dahdi_hangup(), dial_exec_full(), func_channel_write(), func_channel_write_real(), handle_tddmode(), play_record_review(), rcvfax_exec(), reset_volumes(), set_format(), set_listen_volume(), set_security_requirements(), set_talk_volume(), sndfax_exec(), try_calling(), and vm_forwardoptions().

{
   int res;

   ast_channel_lock(chan);
   if (!ast_channel_tech(chan)->setoption) {
      errno = ENOSYS;
      ast_channel_unlock(chan);
      return -1;
   }

   if (block)
      ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");

   res = ast_channel_tech(chan)->setoption(chan, option, data, datalen);
   ast_channel_unlock(chan);

   return res;
}
void ast_channel_setwhentohangup ( struct ast_channel chan,
time_t  offset 
)

Set when to hang a channel up.

Parameters:
chanchannel on which to check for hang up
offsetoffset in seconds relative to the current time of when to hang up

This function sets the absolute time out on a channel (when to hang up).

Note:
This function does not require that the channel is locked before calling it.
Returns:
Nothing
See also:
ast_channel_setwhentohangup_tv()
Version:
1.6.1 deprecated function (only had seconds precision)

Definition at line 692 of file channel.c.

References ast_channel_setwhentohangup_tv().

{
   struct timeval when = { offset, };
   ast_channel_setwhentohangup_tv(chan, when);
}
void ast_channel_setwhentohangup_tv ( struct ast_channel chan,
struct timeval  offset 
)

Set when to hangup channel.

Set when to hang a channel up.

Definition at line 680 of file channel.c.

References ast_channel_whentohangup_set(), ast_null_frame, ast_queue_frame(), ast_tvadd(), ast_tvnow(), and ast_tvzero().

Referenced by action_timeout(), ast_channel_setwhentohangup(), handle_autohangup(), sig_pri_send_aoce_termination_request(), and timeout_write().

{
   if (ast_tvzero(offset)) {
      ast_channel_whentohangup_set(chan, &offset);
   } else {
      struct timeval tv = ast_tvadd(offset, ast_tvnow());
      ast_channel_whentohangup_set(chan, &tv);
   }
   ast_queue_frame(chan, &ast_null_frame);
   return;
}
static int ast_channel_softhangup_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 638 of file channel.c.

References ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.

Referenced by ast_begin_shutdown().

{
   struct ast_channel *chan = obj;

   ast_softhangup(chan, AST_SOFTHANGUP_SHUTDOWN);

   return 0;
}
void ast_channel_softhangup_withcause_locked ( struct ast_channel chan,
int  causecode 
)

Lock the given channel, then request softhangup on the channel with the given causecode.

Parameters:
chanchannel on which to hang up
causecodecause code to use (Zero if don't use cause code)
Returns:
Nothing

Definition at line 622 of file channel.c.

References ast_channel_hangupcause(), ast_channel_hangupcause_set(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_debug, AST_SOFTHANGUP_EXPLICIT, and ast_softhangup_nolock().

Referenced by action_hangup().

{
   ast_channel_lock(chan);

   if (causecode > 0) {
      ast_debug(1, "Setting hangupcause of channel %s to %d (is %d now)\n",
         ast_channel_name(chan), causecode, ast_channel_hangupcause(chan));

      ast_channel_hangupcause_set(chan, causecode);
   }

   ast_softhangup_nolock(chan, AST_SOFTHANGUP_EXPLICIT);

   ast_channel_unlock(chan);
}

Starts a silence generator on the given channel.

Parameters:
chanThe channel to generate silence on
Returns:
An ast_silence_generator pointer, or NULL if an error occurs

This function will cause SLINEAR silence to be generated on the supplied channel until it is disabled; if the channel cannot be put into SLINEAR mode then the function will fail.

Note:
The pointer returned by this function must be preserved and passed to ast_channel_stop_silence_generator when you wish to stop the silence generation.

Definition at line 8780 of file channel.c.

References ast_activate_generator(), ast_calloc, ast_channel_name(), ast_channel_writeformat(), ast_debug, ast_format_copy(), AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_write_format_by_id(), LOG_ERROR, ast_silence_generator::old_write_format, and state.

Referenced by __ast_play_and_record(), ast_bridge_call(), ast_dtmf_stream(), ast_readstring_full(), ast_safe_sleep_conditional(), channel_spy(), record_exec(), sub_start_silence(), waitfor_exec(), and waitforring_exec().

{
   struct ast_silence_generator *state;

   if (!(state = ast_calloc(1, sizeof(*state)))) {
      return NULL;
   }

   ast_format_copy(&state->old_write_format, ast_channel_writeformat(chan));

   if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
      ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
      ast_free(state);
      return NULL;
   }

   ast_activate_generator(chan, &silence_generator, state);

   ast_debug(1, "Started silence generator on '%s'\n", ast_channel_name(chan));

   return state;
}
void ast_channel_stop_silence_generator ( struct ast_channel chan,
struct ast_silence_generator state 
)

Stops a previously-started silence generator on the given channel.

Parameters:
chanThe channel to operate on
stateThe ast_silence_generator pointer return by a previous call to ast_channel_start_silence_generator.
Returns:
nothing

This function will stop the operating silence generator and return the channel to its previous write format.

Definition at line 8832 of file channel.c.

References ast_channel_name(), ast_debug, ast_free, ast_log(), ast_set_write_format(), internal_deactivate_generator(), LOG_ERROR, and ast_silence_generator::old_write_format.

Referenced by __ast_play_and_record(), ast_bridge_call(), ast_dtmf_stream(), ast_readstring_full(), ast_safe_sleep_conditional(), channel_spy(), record_exec(), sub_stop_silence(), waitfor_exec(), and waitforring_exec().

{
   if (!state)
      return;

   if (internal_deactivate_generator(chan, &silence_generator)) {
      ast_debug(1, "Stopped silence generator on '%s'\n", ast_channel_name(chan));
      if (ast_set_write_format(chan, &state->old_write_format) < 0)
         ast_log(LOG_ERROR, "Could not return write format to its original state\n");
   }
   ast_free(state);
}
int ast_channel_supports_html ( struct ast_channel channel)

Checks for HTML support on a channel.

Returns:
0 if channel does not support HTML or non-zero if it does

Definition at line 6145 of file channel.c.

References ast_channel_tech().

Referenced by dial_exec_full(), sendurl_exec(), and try_calling().

{
   return (ast_channel_tech(chan)->send_html) ? 1 : 0;
}
int ast_channel_transfer_masquerade ( struct ast_channel target_chan,
const struct ast_party_connected_line target_id,
int  target_held,
struct ast_channel transferee_chan,
const struct ast_party_connected_line transferee_id,
int  transferee_held 
)

Setup a masquerade to transfer a call.

Since:
1.8
Parameters:
target_chanTarget of the call transfer. (Masquerade original channel)
target_idNew connected line information for the target channel.
target_heldTRUE if the target call is on hold.
transferee_chanTransferee of the call transfer. (Masquerade clone channel)
transferee_idNew connected line information for the transferee channel.
transferee_heldTRUE if the transferee call is on hold.

Party A - Transferee Party B - Transferer Party C - Target of transfer

Party B transfers A to C.

Party A is connected to bridged channel B1. Party B is connected to channels C1 and C2. Party C is connected to bridged channel B2.

Party B -- C1 == B1 -- Party A __/ / Party B -- C2 == B2 -- Party C

Bridged channel B1 is masqueraded into channel C2. Where B1 is the masquerade clone channel and C2 is the masquerade original channel.

See also:
ast_channel_masquerade()
Note:
Has the same locking requirements as ast_channel_masquerade().
Return values:
0on success.
-1on error.

Definition at line 6435 of file channel.c.

References __ast_channel_masquerade(), ast_calloc, ast_datastore_alloc(), ast_datastore_free(), ast_datastore::data, party_connected_line_copy_transfer(), xfer_masquerade_ds::target_held, xfer_masquerade_ds::target_id, xfer_masquerade_ds::transferee_held, and xfer_masquerade_ds::transferee_id.

Referenced by analog_attempt_transfer(), misdn_attempt_transfer(), and sig_pri_attempt_transfer().

{
   struct ast_datastore *xfer_ds;
   struct xfer_masquerade_ds *xfer_colp;
   int res;

   xfer_ds = ast_datastore_alloc(&xfer_ds_info, NULL);
   if (!xfer_ds) {
      return -1;
   }

   xfer_colp = ast_calloc(1, sizeof(*xfer_colp));
   if (!xfer_colp) {
      ast_datastore_free(xfer_ds);
      return -1;
   }
   party_connected_line_copy_transfer(&xfer_colp->target_id, target_id);
   xfer_colp->target_held = target_held;
   party_connected_line_copy_transfer(&xfer_colp->transferee_id, transferee_id);
   xfer_colp->transferee_held = transferee_held;
   xfer_ds->data = xfer_colp;

   res = __ast_channel_masquerade(target_chan, transferee_chan, xfer_ds);
   if (res) {
      ast_datastore_free(xfer_ds);
   }
   return res;
}
void ast_channel_undefer_dtmf ( struct ast_channel chan)

Unset defer DTMF flag on channel.

Undo defer. ast_read will return any DTMF characters that were queued

Definition at line 1451 of file channel.c.

References ast_channel_flags(), ast_clear_flag, and AST_FLAG_DEFER_DTMF.

Referenced by __adsi_transmit_messages(), and find_cache().

void ast_channel_unlink ( struct ast_channel chan)

Remove a channel from the global channels container.

Parameters:
chanchannel to remove

In a case where it is desired that a channel not be available in any lookups in the global channels conatiner, use this function.

Definition at line 11191 of file channel.c.

References ao2_unlink, and channels.

Referenced by create_msg_q_chan().

{
   ao2_unlink(channels, chan);
}
void ast_channel_unregister ( const struct ast_channel_tech tech)

Unregister channel driver.

Unregister a channel technology.

Definition at line 752 of file channel.c.

References ast_debug, ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_END, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::chan, chanlist::tech, and ast_channel_tech::type.

Referenced by __unload_module(), load_module(), and unload_module().

{
   struct chanlist *chan;

   ast_debug(1, "Unregistering channel type '%s'\n", tech->type);

   AST_RWLIST_WRLOCK(&backends);

   AST_RWLIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
      if (chan->tech == tech) {
         AST_LIST_REMOVE_CURRENT(list);
         ast_free(chan);
         ast_verb(2, "Unregistered channel type '%s'\n", tech->type);
         break;
      }
   }
   AST_LIST_TRAVERSE_SAFE_END;

   AST_RWLIST_UNLOCK(&backends);
}
void ast_channel_update_connected_line ( struct ast_channel chan,
const struct ast_party_connected_line connected,
const struct ast_set_party_connected_line update 
)

Indicate that the connected line information has changed.

Since:
1.8
Parameters:
chanAsterisk channel to indicate connected line information
connectedConnected line information
updateWhat connected line information to update. NULL if all.
Returns:
Nothing

Definition at line 9716 of file channel.c.

References ast_connected_line_build_data(), AST_CONTROL_CONNECTED_LINE, and ast_indicate_data().

Referenced by app_exec(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_do_pickup(), atxfer_fail_cleanup(), builtin_atxfer(), connectedline_write(), parked_call_exec(), and wait_for_answer().

{
   unsigned char data[1024];  /* This should be large enough */
   size_t datalen;

   datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
   if (datalen == (size_t) -1) {
      return;
   }

   ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
}
void ast_channel_update_redirecting ( struct ast_channel chan,
const struct ast_party_redirecting redirecting,
const struct ast_set_party_redirecting update 
)

Indicate that the redirecting id has changed.

Since:
1.8
Parameters:
chanAsterisk channel to indicate redirecting id information
redirectingRedirecting id information
updateWhat redirecting information to update. NULL if all.
Returns:
Nothing

Definition at line 10844 of file channel.c.

References AST_CONTROL_REDIRECTING, ast_indicate_data(), and ast_redirecting_build_data().

Referenced by ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), call_forward_inherit(), do_forward(), handle_request_refer(), redirecting_write(), and wait_for_answer().

{
   unsigned char data[1024];  /* This should be large enough */
   size_t datalen;

   datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
   if (datalen == (size_t) -1) {
      return;
   }

   ast_indicate_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
}
struct ast_variable* ast_channeltype_list ( void  ) [read]

return an ast_variable list of channeltypes

Definition at line 217 of file channel.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_variable_new(), chanlist::tech, and var.

Referenced by ast_var_channel_types(), and ast_var_channel_types_table().

{
   struct chanlist *cl;
   struct ast_variable *var = NULL, *prev = NULL;

   AST_RWLIST_RDLOCK(&backends);
   AST_RWLIST_TRAVERSE(&backends, cl, list) {
      if (prev)  {
         if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, "")))
            prev = prev->next;
      } else {
         var = ast_variable_new(cl->tech->type, cl->tech->description, "");
         prev = var;
      }
   }
   AST_RWLIST_UNLOCK(&backends);

   return var;
}
int ast_check_hangup ( struct ast_channel chan)

Checks to see if a channel is needing hang up.

Check to see if a channel is needing hang up.

Definition at line 599 of file channel.c.

References ast_channel_name(), ast_channel_softhangup_internal_flag(), ast_channel_softhangup_internal_flag_add(), ast_channel_whentohangup(), ast_debug, AST_SOFTHANGUP_TIMEOUT, ast_test_suite_event_notify, ast_tvdiff_ms(), ast_tvnow(), and ast_tvzero().

Referenced by __ast_pbx_run(), __ast_read(), _macro_exec(), agent_indicate(), agi_exec(), agi_handle_command(), announce_thread(), ast_bridge_call(), ast_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_indicate_data(), ast_raw_answer(), ast_readstring_full(), ast_recvtext(), ast_rtp_instance_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), autoservice_run(), bridge_call_thread(), bridge_exec(), builtin_atxfer(), call_forward_inherit(), channel_spy(), check_bridge(), common_exec(), conf_play(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), feature_request_and_dial(), findmeexec(), func_channel_read(), gosub_run(), handle_sendimage(), iax2_bridge(), join_conference_bridge(), launch_asyncagi(), local_bridge_loop(), local_fixup(), login_exec(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_builtin_waitexten(), pbx_exec(), read_exec(), readexten_exec(), remote_bridge_loop(), run_agi(), run_ras(), try_calling(), and wait_for_answer().

{
   if (ast_channel_softhangup_internal_flag(chan))    /* yes if soft hangup flag set */
      return 1;
   if (ast_tvzero(*ast_channel_whentohangup(chan)))   /* no if no hangup scheduled */
      return 0;
   if (ast_tvdiff_ms(*ast_channel_whentohangup(chan), ast_tvnow()) > 0)    /* no if hangup time has not come yet. */
      return 0;
   ast_debug(4, "Hangup time has come: %" PRIi64 "\n", ast_tvdiff_ms(*ast_channel_whentohangup(chan), ast_tvnow()));
   ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(chan));
   ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_TIMEOUT); /* record event */
   return 1;
}
int ast_check_hangup_locked ( struct ast_channel chan)

Definition at line 613 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().

Referenced by action_redirect(), ast_channel_bridge(), and bridge_channel_feature().

{
   int res;
   ast_channel_lock(chan);
   res = ast_check_hangup(chan);
   ast_channel_unlock(chan);
   return res;
}
int ast_connected_line_build_data ( unsigned char *  data,
size_t  datalen,
const struct ast_party_connected_line connected,
const struct ast_set_party_connected_line update 
)

Build the connected line information data frame.

Since:
1.8
Parameters:
dataBuffer to fill with the frame data
datalenSize of the buffer to fill
connectedConnected line information
updateWhat connected line information to build. NULL if all.
Return values:
-1if error
Amountof data buffer used

Definition at line 9320 of file channel.c.

References AST_CONNECTED_LINE_ID_PRESENTATION, AST_CONNECTED_LINE_NAME, AST_CONNECTED_LINE_NAME_CHAR_SET, AST_CONNECTED_LINE_NAME_PRESENTATION, AST_CONNECTED_LINE_NAME_VALID, AST_CONNECTED_LINE_NUMBER, AST_CONNECTED_LINE_NUMBER_PLAN, AST_CONNECTED_LINE_NUMBER_PRESENTATION, AST_CONNECTED_LINE_NUMBER_VALID, AST_CONNECTED_LINE_PRIV_NAME, AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET, AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION, AST_CONNECTED_LINE_PRIV_NAME_VALID, AST_CONNECTED_LINE_PRIV_NUMBER, AST_CONNECTED_LINE_PRIV_NUMBER_PLAN, AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION, AST_CONNECTED_LINE_PRIV_NUMBER_VALID, AST_CONNECTED_LINE_PRIV_SUBADDRESS, AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN, AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE, AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID, AST_CONNECTED_LINE_PRIV_TAG, AST_CONNECTED_LINE_SOURCE, AST_CONNECTED_LINE_SUBADDRESS, AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN, AST_CONNECTED_LINE_SUBADDRESS_TYPE, AST_CONNECTED_LINE_SUBADDRESS_VALID, AST_CONNECTED_LINE_TAG, AST_CONNECTED_LINE_VERSION, ast_log(), ast_party_connected_line::id, ast_set_party_connected_line::id, LOG_WARNING, ast_party_id_ies::name, party_id_build_data(), ast_party_connected_line::priv, ast_set_party_connected_line::priv, ast_party_connected_line::source, ast_party_name_ies::str, and value.

Referenced by ast_channel_queue_connected_line_update(), ast_channel_update_connected_line(), local_attended_transfer(), local_indicate(), and masquerade_colp_transfer().

{
   int32_t value;
   size_t pos = 0;
   int res;

   static const struct ast_party_id_ies ies = {
      .name.str = AST_CONNECTED_LINE_NAME,
      .name.char_set = AST_CONNECTED_LINE_NAME_CHAR_SET,
      .name.presentation = AST_CONNECTED_LINE_NAME_PRESENTATION,
      .name.valid = AST_CONNECTED_LINE_NAME_VALID,

      .number.str = AST_CONNECTED_LINE_NUMBER,
      .number.plan = AST_CONNECTED_LINE_NUMBER_PLAN,
      .number.presentation = AST_CONNECTED_LINE_NUMBER_PRESENTATION,
      .number.valid = AST_CONNECTED_LINE_NUMBER_VALID,

      .subaddress.str = AST_CONNECTED_LINE_SUBADDRESS,
      .subaddress.type = AST_CONNECTED_LINE_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_CONNECTED_LINE_SUBADDRESS_VALID,

      .tag = AST_CONNECTED_LINE_TAG,
      .combined_presentation = AST_CONNECTED_LINE_ID_PRESENTATION,
   };

   static const struct ast_party_id_ies priv_ies = {
      .name.str = AST_CONNECTED_LINE_PRIV_NAME,
      .name.char_set = AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET,
      .name.presentation = AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION,
      .name.valid = AST_CONNECTED_LINE_PRIV_NAME_VALID,

      .number.str = AST_CONNECTED_LINE_PRIV_NUMBER,
      .number.plan = AST_CONNECTED_LINE_PRIV_NUMBER_PLAN,
      .number.presentation = AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION,
      .number.valid = AST_CONNECTED_LINE_PRIV_NUMBER_VALID,

      .subaddress.str = AST_CONNECTED_LINE_PRIV_SUBADDRESS,
      .subaddress.type = AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID,

      .tag = AST_CONNECTED_LINE_PRIV_TAG,
      .combined_presentation = 0,/* Not sent. */
   };

   /*
    * The size of integer values must be fixed in case the frame is
    * shipped to another machine.
    */

   /* Connected line frame version */
   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for connected line frame version\n");
      return -1;
   }
   data[pos++] = AST_CONNECTED_LINE_VERSION;
   data[pos++] = 1;
   data[pos++] = 2;/* Version 1 did not have a version ie */

   res = party_id_build_data(data + pos, datalen - pos, &connected->id,
      "connected line", &ies, update ? &update->id : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   res = party_id_build_data(data + pos, datalen - pos, &connected->priv,
      "connected line priv", &priv_ies, update ? &update->priv : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   /* Connected line source */
   if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
      ast_log(LOG_WARNING, "No space left for connected line source\n");
      return -1;
   }
   data[pos++] = AST_CONNECTED_LINE_SOURCE;
   data[pos++] = sizeof(value);
   value = htonl(connected->source);
   memcpy(data + pos, &value, sizeof(value));
   pos += sizeof(value);

   return pos;
}
void ast_connected_line_copy_from_caller ( struct ast_party_connected_line dest,
const struct ast_party_caller src 
)

Copy the caller information to the connected line information.

Since:
1.8
Parameters:
destDestination connected line information
srcSource caller information
Returns:
Nothing
Note:
Assumes locks are already acquired

Definition at line 8918 of file channel.c.

References ast_party_caller::ani, ast_party_connected_line::ani, ast_party_caller::ani2, ast_party_connected_line::ani2, ast_party_id_copy(), ast_party_caller::id, and ast_party_connected_line::id.

Referenced by app_exec(), ast_do_pickup(), begin_dial_channel(), builtin_atxfer(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), local_call(), parked_call_exec(), ring_entry(), and wait_for_answer().

{
   ast_party_id_copy(&dest->id, &src->id);
   ast_party_id_copy(&dest->ani, &src->ani);
   dest->ani2 = src->ani2;
}
void ast_connected_line_copy_to_caller ( struct ast_party_caller dest,
const struct ast_party_connected_line src 
)

Copy the connected line information to the caller information.

Since:
1.8
Parameters:
destDestination caller information
srcSource connected line information
Returns:
Nothing
Note:
Assumes locks are already acquired

Definition at line 8925 of file channel.c.

References ast_party_caller::ani, ast_party_connected_line::ani, ast_party_caller::ani2, ast_party_connected_line::ani2, ast_party_id_copy(), ast_party_caller::id, and ast_party_connected_line::id.

Referenced by local_call(), and local_indicate().

{
   ast_party_id_copy(&dest->id, &src->id);
   ast_party_id_copy(&dest->ani, &src->ani);

   dest->ani2 = src->ani2;
}
int ast_connected_line_parse_data ( const unsigned char *  data,
size_t  datalen,
struct ast_party_connected_line connected 
)

Parse connected line indication frame data.

Since:
1.8
Parameters:
dataBuffer with the frame data to parse
datalenSize of the buffer
connectedExtracted connected line information
Return values:
0on success.
-1on error.
Note:
The filled in connected line structure needs to be initialized by ast_party_connected_line_set_init() before calling. If defaults are not required use ast_party_connected_line_init().
The filled in connected line structure needs to be destroyed by ast_party_connected_line_free() when it is no longer needed.

Definition at line 9408 of file channel.c.

References AST_CONNECTED_LINE_ID_PRESENTATION, AST_CONNECTED_LINE_NAME, AST_CONNECTED_LINE_NAME_CHAR_SET, AST_CONNECTED_LINE_NAME_PRESENTATION, AST_CONNECTED_LINE_NAME_VALID, AST_CONNECTED_LINE_NUMBER, AST_CONNECTED_LINE_NUMBER_PLAN, AST_CONNECTED_LINE_NUMBER_PRESENTATION, AST_CONNECTED_LINE_NUMBER_VALID, AST_CONNECTED_LINE_PRIV_NAME, AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET, AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION, AST_CONNECTED_LINE_PRIV_NAME_VALID, AST_CONNECTED_LINE_PRIV_NUMBER, AST_CONNECTED_LINE_PRIV_NUMBER_PLAN, AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION, AST_CONNECTED_LINE_PRIV_NUMBER_VALID, AST_CONNECTED_LINE_PRIV_SUBADDRESS, AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN, AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE, AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID, AST_CONNECTED_LINE_PRIV_TAG, AST_CONNECTED_LINE_SOURCE, AST_CONNECTED_LINE_SUBADDRESS, AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN, AST_CONNECTED_LINE_SUBADDRESS_TYPE, AST_CONNECTED_LINE_SUBADDRESS_VALID, AST_CONNECTED_LINE_TAG, AST_CONNECTED_LINE_VERSION, ast_debug, ast_free, ast_log(), ast_malloc, AST_PARTY_CHAR_SET_ISO8859_1, ast_party_name::char_set, ast_party_id_ies::combined_presentation, ast_party_connected_line::id, LOG_WARNING, ast_party_id::name, ast_party_id::number, ast_party_subaddress::odd_even_indicator, ast_party_number::plan, ast_party_name::presentation, ast_party_number::presentation, ast_party_connected_line::priv, ast_party_connected_line::source, ast_party_name::str, ast_party_number::str, ast_party_subaddress::str, ast_party_id::subaddress, ast_party_id::tag, ast_party_subaddress::type, ast_party_name::valid, ast_party_number::valid, ast_party_subaddress::valid, and value.

Referenced by __ast_read(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_indicate_data(), feature_request_and_dial(), socket_process_helper(), wait_for_answer(), and wait_for_winner().

{
   size_t pos;
   unsigned char ie_len;
   unsigned char ie_id;
   int32_t value;
   int frame_version = 1;
   int combined_presentation = 0;
   int got_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */

   for (pos = 0; pos < datalen; pos += ie_len) {
      if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
         ast_log(LOG_WARNING, "Invalid connected line update\n");
         return -1;
      }
      ie_id = data[pos++];
      ie_len = data[pos++];
      if (datalen < pos + ie_len) {
         ast_log(LOG_WARNING, "Invalid connected line update\n");
         return -1;
      }

      switch (ie_id) {
/* Connected line party frame version */
      case AST_CONNECTED_LINE_VERSION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line frame version (%u)\n",
               (unsigned) ie_len);
            break;
         }
         frame_version = data[pos];
         break;
/* Connected line party id name */
      case AST_CONNECTED_LINE_NAME:
         ast_free(connected->id.name.str);
         connected->id.name.str = ast_malloc(ie_len + 1);
         if (connected->id.name.str) {
            memcpy(connected->id.name.str, data + pos, ie_len);
            connected->id.name.str[ie_len] = 0;
         }
         break;
      case AST_CONNECTED_LINE_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.name.char_set = data[pos];
         break;
      case AST_CONNECTED_LINE_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.name.presentation = data[pos];
         break;
      case AST_CONNECTED_LINE_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.name.valid = data[pos];
         break;
/* Connected line party id number */
      case AST_CONNECTED_LINE_NUMBER:
         ast_free(connected->id.number.str);
         connected->id.number.str = ast_malloc(ie_len + 1);
         if (connected->id.number.str) {
            memcpy(connected->id.number.str, data + pos, ie_len);
            connected->id.number.str[ie_len] = 0;
         }
         break;
      case AST_CONNECTED_LINE_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.number.plan = data[pos];
         break;
      case AST_CONNECTED_LINE_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.number.presentation = data[pos];
         break;
      case AST_CONNECTED_LINE_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.number.valid = data[pos];
         break;
/* Connected line party id subaddress */
      case AST_CONNECTED_LINE_SUBADDRESS:
         ast_free(connected->id.subaddress.str);
         connected->id.subaddress.str = ast_malloc(ie_len + 1);
         if (connected->id.subaddress.str) {
            memcpy(connected->id.subaddress.str, data + pos, ie_len);
            connected->id.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_CONNECTED_LINE_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.subaddress.type = data[pos];
         break;
      case AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid connected line subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_CONNECTED_LINE_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->id.subaddress.valid = data[pos];
         break;
/* Connected line party tag */
      case AST_CONNECTED_LINE_TAG:
         ast_free(connected->id.tag);
         connected->id.tag = ast_malloc(ie_len + 1);
         if (connected->id.tag) {
            memcpy(connected->id.tag, data + pos, ie_len);
            connected->id.tag[ie_len] = 0;
         }
         break;
/* Connected line party id combined presentation */
      case AST_CONNECTED_LINE_ID_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line combined presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         combined_presentation = data[pos];
         got_combined_presentation = 1;
         break;
/* Private connected line party id name */
      case AST_CONNECTED_LINE_PRIV_NAME:
         ast_free(connected->priv.name.str);
         connected->priv.name.str = ast_malloc(ie_len + 1);
         if (connected->priv.name.str) {
            memcpy(connected->priv.name.str, data + pos, ie_len);
            connected->priv.name.str[ie_len] = 0;
         }
         break;
      case AST_CONNECTED_LINE_PRIV_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.name.char_set = data[pos];
         break;
      case AST_CONNECTED_LINE_PRIV_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.name.presentation = data[pos];
         break;
      case AST_CONNECTED_LINE_PRIV_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.name.valid = data[pos];
         break;
/* Private connected line party id number */
      case AST_CONNECTED_LINE_PRIV_NUMBER:
         ast_free(connected->priv.number.str);
         connected->priv.number.str = ast_malloc(ie_len + 1);
         if (connected->priv.number.str) {
            memcpy(connected->priv.number.str, data + pos, ie_len);
            connected->priv.number.str[ie_len] = 0;
         }
         break;
      case AST_CONNECTED_LINE_PRIV_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.number.plan = data[pos];
         break;
      case AST_CONNECTED_LINE_PRIV_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.number.presentation = data[pos];
         break;
      case AST_CONNECTED_LINE_PRIV_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.number.valid = data[pos];
         break;
/* Private connected line party id subaddress */
      case AST_CONNECTED_LINE_PRIV_SUBADDRESS:
         ast_free(connected->priv.subaddress.str);
         connected->priv.subaddress.str = ast_malloc(ie_len + 1);
         if (connected->priv.subaddress.str) {
            memcpy(connected->priv.subaddress.str, data + pos, ie_len);
            connected->priv.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_CONNECTED_LINE_PRIV_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.subaddress.type = data[pos];
         break;
      case AST_CONNECTED_LINE_PRIV_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid connected line private subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_CONNECTED_LINE_PRIV_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid connected line private subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         connected->priv.subaddress.valid = data[pos];
         break;
/* Private connected line party tag */
      case AST_CONNECTED_LINE_PRIV_TAG:
         ast_free(connected->priv.tag);
         connected->priv.tag = ast_malloc(ie_len + 1);
         if (connected->priv.tag) {
            memcpy(connected->priv.tag, data + pos, ie_len);
            connected->priv.tag[ie_len] = 0;
         }
         break;
/* Connected line party source */
      case AST_CONNECTED_LINE_SOURCE:
         if (ie_len != sizeof(value)) {
            ast_log(LOG_WARNING, "Invalid connected line source (%u)\n",
               (unsigned) ie_len);
            break;
         }
         memcpy(&value, data + pos, sizeof(value));
         connected->source = ntohl(value);
         break;
/* Connected line party unknown element */
      default:
         ast_debug(1, "Unknown connected line element: %u (%u)\n",
            (unsigned) ie_id, (unsigned) ie_len);
         break;
      }
   }

   switch (frame_version) {
   case 1:
      /*
       * The other end is an earlier version that we need to adjust
       * for compatibility.
       */
      connected->id.name.valid = 1;
      connected->id.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
      connected->id.number.valid = 1;
      if (got_combined_presentation) {
         connected->id.name.presentation = combined_presentation;
         connected->id.number.presentation = combined_presentation;
      }
      break;
   case 2:
      /* The other end is at the same level as we are. */
      break;
   default:
      /*
       * The other end is newer than we are.
       * We need to assume that they are compatible with us.
       */
      ast_debug(1, "Connected line frame has newer version: %u\n",
         (unsigned) frame_version);
      break;
   }

   return 0;
}
int ast_do_masquerade ( struct ast_channel original)

Masquerade a channel.

Start masquerading a channel.

Note:
Assumes _NO_ channels and _NO_ channel pvt's are locked. If a channel is locked while calling this function, it invalidates our channel container locking order. All channels must be unlocked before it is permissible to lock the channels' ao2 container.

< TRUE if the clonechan was a zombie before the masquerade.

Definition at line 6817 of file channel.c.

References __ast_change_name_nolink(), ao2_link, ao2_lock, ao2_unlink, ao2_unlock, ast_app_group_update(), ast_autochan_new_channel(), ast_bridge_end_dtmf(), ast_bridged_channel(), AST_CEL_BRIDGE_UPDATE, ast_cel_report_event(), ast_channel_accountcode(), ast_channel_adsicpe_set(), ast_channel_alert_write(), ast_channel_blocker(), ast_channel_caller(), ast_channel_caller_set(), ast_channel_cdr(), ast_channel_cdr_set(), ast_channel_connected(), ast_channel_connected_set(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_datastores(), ast_channel_dialed(), ast_channel_dialed_set(), ast_channel_fd(), ast_channel_fdno(), ast_channel_fdno_set(), ast_channel_flags(), ast_channel_hangup_handlers(), ast_channel_internal_alertpipe_swap(), ast_channel_internal_bridged_channel(), ast_channel_language(), ast_channel_lock, ast_channel_lock_both, ast_channel_masq(), ast_channel_masq_set(), ast_channel_masqr_set(), ast_channel_monitor(), ast_channel_monitor_set(), ast_channel_musicclass(), AST_CHANNEL_NAME, ast_channel_name(), ast_channel_nativeformats(), ast_channel_parkinglot(), ast_channel_rawreadformat(), ast_channel_rawwriteformat(), ast_channel_readformat(), ast_channel_readq(), ast_channel_redirecting(), ast_channel_redirecting_set(), ast_channel_ref, ast_channel_sending_dtmf_digit(), ast_channel_sending_dtmf_tv(), ast_channel_set_fd(), ast_channel_set_linkgroup(), ast_channel_softhangup_internal_flag_set(), ast_channel_state_set(), ast_channel_tech(), ast_channel_tech_pvt(), ast_channel_tech_pvt_set(), ast_channel_tech_set(), ast_channel_timingfd(), ast_channel_unlock, ast_channel_unref, ast_channel_visible_indication(), ast_channel_writeformat(), ast_clear_flag, AST_CONTROL_SRCCHANGE, AST_CONTROL_UNHOLD, ast_copy_string(), ast_datastore_free(), ast_debug, AST_FLAG_BLOCKING, AST_FLAG_DISABLE_DEVSTATE_CACHE, AST_FLAG_EXCEPTION, AST_FLAG_MOH, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_format_cap_copy(), ast_format_copy(), AST_GENERATOR_FD, ast_getformatname(), ast_hangup(), ast_indicate(), AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_manager_event_multichan, AST_MAX_FDS, ast_moh_start(), ast_null_frame, ast_party_id_reset(), ast_queue_frame(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), AST_SOFTHANGUP_DEV, ast_state2str(), ast_test_flag, AST_TIMING_FD, ast_channel::caller, ast_datastore_info::chan_fixup, channels, clone_variables(), ast_channel::connected, ast_datastore::data, ast_channel::dialed, errno, EVENT_FLAG_CALL, free_translation(), ast_datastore::info, LOG_WARNING, masquerade_colp_transfer(), ast_channel::redirecting, report_new_callerid(), S_OR, xfer_masquerade_ds::transferee_held, and type.

Referenced by __ast_read(), ast_async_goto(), ast_do_pickup(), ast_hangup(), ast_waitfor_nandfds(), ast_write(), builtin_atxfer(), check_bridge(), check_goto_on_transfer(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), local_attended_transfer(), masq_park_call(), and sip_park().

{
   int x;
   int origstate;
   unsigned int orig_disablestatecache;
   unsigned int clone_disablestatecache;
   int visible_indication;
   int moh_is_playing;
   int clone_was_zombie = 0;/*!< TRUE if the clonechan was a zombie before the masquerade. */
   struct ast_frame *current;
   const struct ast_channel_tech *t;
   void *t_pvt;
   union {
      struct ast_hangup_handler_list handlers;
      struct ast_party_dialed dialed;
      struct ast_party_caller caller;
      struct ast_party_connected_line connected;
      struct ast_party_redirecting redirecting;
   } exchange;
   struct ast_channel *clonechan, *chans[2];
   struct ast_channel *bridged;
   struct ast_cdr *cdr;
   struct ast_datastore *xfer_ds;
   struct xfer_masquerade_ds *xfer_colp;
   struct ast_format rformat;
   struct ast_format wformat;
   struct ast_format tmp_format;
   char newn[AST_CHANNEL_NAME];
   char orig[AST_CHANNEL_NAME];
   char masqn[AST_CHANNEL_NAME];
   char zombn[AST_CHANNEL_NAME];
   char clone_sending_dtmf_digit;
   struct timeval clone_sending_dtmf_tv;

   /* XXX This operation is a bit odd.  We're essentially putting the guts of
    * the clone channel into the original channel.  Start by killing off the
    * original channel's backend.  While the features are nice, which is the
    * reason we're keeping it, it's still awesomely weird. XXX */

   /*
    * The reasoning for the channels ao2_container lock here is
    * complex.
    *
    * There is a race condition that exists for this function.
    * Since all pvt and channel locks must be let go before calling
    * ast_do_masquerade, it is possible that it could be called
    * multiple times for the same channel.  In order to prevent the
    * race condition with competing threads to do the masquerade
    * and new masquerade attempts, the channels container must be
    * locked for the entire masquerade.  The original and clonechan
    * need to be unlocked earlier to avoid potential deadlocks with
    * the chan_local deadlock avoidance method.
    *
    * The container lock blocks competing masquerade attempts from
    * starting as well as being necessary for proper locking order
    * because the channels must to be unlinked to change their
    * names.
    *
    * The original and clonechan locks must be held while the
    * channel contents are shuffled around for the masquerade.
    *
    * The masq and masqr pointers need to be left alone until the
    * masquerade has restabilized the channels to prevent another
    * masquerade request until the AST_FLAG_ZOMBIE can be set on
    * the clonechan.
    */
   ao2_lock(channels);

   /*
    * Lock the original channel to determine if the masquerade is
    * still required.
    */
   ast_channel_lock(original);

   clonechan = ast_channel_masq(original);
   if (!clonechan) {
      /*
       * The masq is already completed by another thread or never
       * needed to be done to begin with.
       */
      ast_channel_unlock(original);
      ao2_unlock(channels);
      return 0;
   }

   /* Bump the refs to ensure that they won't dissapear on us. */
   ast_channel_ref(original);
   ast_channel_ref(clonechan);

   /* unlink from channels container as name (which is the hash value) will change */
   ao2_unlink(channels, original);
   ao2_unlink(channels, clonechan);

   /* Get any transfer masquerade connected line exchange data. */
   xfer_ds = ast_channel_datastore_find(original, &xfer_ds_info, NULL);
   if (xfer_ds) {
      ast_channel_datastore_remove(original, xfer_ds);
      xfer_colp = xfer_ds->data;
   } else {
      xfer_colp = NULL;
   }

   moh_is_playing = ast_test_flag(ast_channel_flags(original), AST_FLAG_MOH);

   /*
    * Stop any visible indication on the original channel so we can
    * transfer it to the clonechan taking the original's place.
    */
   visible_indication = ast_channel_visible_indication(original);
   ast_channel_unlock(original);
   ast_indicate(original, -1);

   /*
    * Release any hold on the transferee channel before going any
    * further with the masquerade.
    */
   if (xfer_colp && xfer_colp->transferee_held) {
      ast_indicate(clonechan, AST_CONTROL_UNHOLD);
   }

   /* Start the masquerade channel contents rearangement. */
   ast_channel_lock_both(original, clonechan);

   ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
      ast_channel_name(clonechan), ast_channel_state(clonechan), ast_channel_name(original), ast_channel_state(original));

   chans[0] = clonechan;
   chans[1] = original;
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a masquerade occurs between two channels, wherein the Clone channel's internal information replaces the Original channel's information.</synopsis>
         <syntax>
            <parameter name="Clone">
               <para>The name of the channel whose information will be going into the Original channel.</para>
            </parameter>
            <parameter name="CloneState">
               <para>The current state of the clone channel.</para>
            </parameter>
            <parameter name="Original">
               <para>The name of the channel whose information will be replaced by the Clone channel's information.</para>
            </parameter>
            <parameter name="OriginalState">
               <para>The current state of the original channel.</para>
            </parameter>
         </syntax>
      </managerEventInstance>
   ***/
   ast_manager_event_multichan(EVENT_FLAG_CALL, "Masquerade", 2, chans,
      "Clone: %s\r\n"
      "CloneState: %s\r\n"
      "Original: %s\r\n"
      "OriginalState: %s\r\n",
      ast_channel_name(clonechan), ast_state2str(ast_channel_state(clonechan)), ast_channel_name(original), ast_state2str(ast_channel_state(original)));

   /*
    * Remember the original read/write formats.  We turn off any
    * translation on either one
    */
   ast_format_copy(&rformat, ast_channel_readformat(original));
   ast_format_copy(&wformat, ast_channel_writeformat(original));
   free_translation(clonechan);
   free_translation(original);

   /* Save the current DTMF digit being sent if any. */
   clone_sending_dtmf_digit = ast_channel_sending_dtmf_digit(clonechan);
   clone_sending_dtmf_tv = ast_channel_sending_dtmf_tv(clonechan);

   /* Save the original name */
   ast_copy_string(orig, ast_channel_name(original), sizeof(orig));
   /* Save the new name */
   ast_copy_string(newn, ast_channel_name(clonechan), sizeof(newn));
   /* Create the masq name */
   snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);

   /* Mangle the name of the clone channel */
   __ast_change_name_nolink(clonechan, masqn);

   /* Copy the name from the clone channel */
   __ast_change_name_nolink(original, newn);

   /* share linked id's */
   ast_channel_set_linkgroup(original, clonechan);

   /* Swap the technologies */
   t = ast_channel_tech(original);
   ast_channel_tech_set(original, ast_channel_tech(clonechan));
   ast_channel_tech_set(clonechan, t);

   t_pvt = ast_channel_tech_pvt(original);
   ast_channel_tech_pvt_set(original, ast_channel_tech_pvt(clonechan));
   ast_channel_tech_pvt_set(clonechan, t_pvt);

   /* Swap the cdrs */
   cdr = ast_channel_cdr(original);
   ast_channel_cdr_set(original, ast_channel_cdr(clonechan));
   ast_channel_cdr_set(clonechan, cdr);

   /* Swap the alertpipes */
   ast_channel_internal_alertpipe_swap(original, clonechan);

   /*
    * Swap the readq's.  The end result should be this:
    *
    *  1) All frames should be on the new (original) channel.
    *  2) Any frames that were already on the new channel before this
    *     masquerade need to be at the end of the readq, after all of the
    *     frames on the old (clone) channel.
    *  3) The alertpipe needs to get poked for every frame that was already
    *     on the new channel, since we are now using the alert pipe from the
    *     old (clone) channel.
    */
   {
      AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;

      AST_LIST_HEAD_INIT_NOLOCK(&tmp_readq);
      AST_LIST_APPEND_LIST(&tmp_readq, ast_channel_readq(original), frame_list);
      AST_LIST_APPEND_LIST(ast_channel_readq(original), ast_channel_readq(clonechan), frame_list);

      while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
         AST_LIST_INSERT_TAIL(ast_channel_readq(original), current, frame_list);
         if (ast_channel_alert_write(original)) {
            ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
         }
      }
   }

   /* Swap the raw formats */
   ast_format_copy(&tmp_format, ast_channel_rawreadformat(original));
   ast_format_copy(ast_channel_rawreadformat(original), ast_channel_rawreadformat(clonechan));
   ast_format_copy(ast_channel_rawreadformat(clonechan), &tmp_format);

   ast_format_copy(&tmp_format, ast_channel_rawwriteformat(original));
   ast_format_copy(ast_channel_rawwriteformat(original), ast_channel_rawwriteformat(clonechan));
   ast_format_copy(ast_channel_rawwriteformat(clonechan), &tmp_format);

   ast_channel_softhangup_internal_flag_set(clonechan, AST_SOFTHANGUP_DEV);

   /* And of course, so does our current state.  Note we need not
      call ast_setstate since the event manager doesn't really consider
      these separate.  We do this early so that the clone has the proper
      state of the original channel. */
   origstate = ast_channel_state(original);
   ast_channel_state_set(original, ast_channel_state(clonechan));
   ast_channel_state_set(clonechan, origstate);

   /* And the swap the cachable state too. Otherwise we'd start caching
    * Local channels and ignoring real ones. */
   orig_disablestatecache = ast_test_flag(ast_channel_flags(original), AST_FLAG_DISABLE_DEVSTATE_CACHE);
   clone_disablestatecache = ast_test_flag(ast_channel_flags(clonechan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
   if (orig_disablestatecache != clone_disablestatecache) {
      if (orig_disablestatecache) {
         ast_clear_flag(ast_channel_flags(original), AST_FLAG_DISABLE_DEVSTATE_CACHE);
         ast_set_flag(ast_channel_flags(clonechan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
      } else {
         ast_set_flag(ast_channel_flags(original), AST_FLAG_DISABLE_DEVSTATE_CACHE);
         ast_clear_flag(ast_channel_flags(clonechan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
      }
   }

   /* Mangle the name of the clone channel */
   snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); /* quick, hide the brains! */
   __ast_change_name_nolink(clonechan, zombn);

   /* Update the type. */
   t_pvt = ast_channel_monitor(original);
   ast_channel_monitor_set(original, ast_channel_monitor(clonechan));
   ast_channel_monitor_set(clonechan, t_pvt);

   /* Keep the same language.  */
   ast_channel_language_set(original, ast_channel_language(clonechan));

   /* Keep the same parkinglot. */
   ast_channel_parkinglot_set(original, ast_channel_parkinglot(clonechan));

   /* Copy the FD's other than the generator fd */
   for (x = 0; x < AST_MAX_FDS; x++) {
      if (x != AST_GENERATOR_FD)
         ast_channel_set_fd(original, x, ast_channel_fd(clonechan, x));
   }

   ast_app_group_update(clonechan, original);

   /* Swap hangup handlers. */
   exchange.handlers = *ast_channel_hangup_handlers(original);
   *ast_channel_hangup_handlers(original) = *ast_channel_hangup_handlers(clonechan);
   *ast_channel_hangup_handlers(clonechan) = exchange.handlers;

   /* Move data stores over */
   if (AST_LIST_FIRST(ast_channel_datastores(clonechan))) {
      struct ast_datastore *ds;
      /* We use a safe traversal here because some fixup routines actually
       * remove the datastore from the list and free them.
       */
      AST_LIST_TRAVERSE_SAFE_BEGIN(ast_channel_datastores(clonechan), ds, entry) {
         if (ds->info->chan_fixup)
            ds->info->chan_fixup(ds->data, clonechan, original);
      }
      AST_LIST_TRAVERSE_SAFE_END;
      AST_LIST_APPEND_LIST(ast_channel_datastores(original), ast_channel_datastores(clonechan), entry);
   }

   ast_autochan_new_channel(clonechan, original);

   clone_variables(original, clonechan);
   /* Presense of ADSI capable CPE follows clone */
   ast_channel_adsicpe_set(original, ast_channel_adsicpe(clonechan));
   /* Bridge remains the same */
   /* CDR fields remain the same */
   /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
   /* Application and data remain the same */
   /* Clone exception  becomes real one, as with fdno */
   ast_set_flag(ast_channel_flags(original), ast_test_flag(ast_channel_flags(clonechan), AST_FLAG_EXCEPTION | AST_FLAG_OUTGOING));
   ast_channel_fdno_set(original, ast_channel_fdno(clonechan));
   /* Schedule context remains the same */
   /* Stream stuff stays the same */
   /* Keep the original state.  The fixup code will need to work with it most likely */

   /*
    * Just swap the whole structures, nevermind the allocations,
    * they'll work themselves out.
    */
   exchange.dialed = *ast_channel_dialed(original);
   ast_channel_dialed_set(original, ast_channel_dialed(clonechan));
   ast_channel_dialed_set(clonechan, &exchange.dialed);

   /* Reset any earlier private caller id representations */
   ast_party_id_reset(&ast_channel_caller(original)->priv);
   ast_party_id_reset(&ast_channel_caller(clonechan)->priv);

   exchange.caller = *ast_channel_caller(original);
   ast_channel_caller_set(original, ast_channel_caller(clonechan));
   ast_channel_caller_set(clonechan, &exchange.caller);

   /* Reset any earlier private connected id representations */
   ast_party_id_reset(&ast_channel_connected(original)->priv);
   ast_party_id_reset(&ast_channel_connected(clonechan)->priv);

   exchange.connected = *ast_channel_connected(original);
   ast_channel_connected_set(original, ast_channel_connected(clonechan));
   ast_channel_connected_set(clonechan, &exchange.connected);

   /* Reset any earlier private redirecting orig, from or to representations */
   ast_party_id_reset(&ast_channel_redirecting(original)->priv_orig);
   ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_orig);
   ast_party_id_reset(&ast_channel_redirecting(original)->priv_from);
   ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_from);
   ast_party_id_reset(&ast_channel_redirecting(original)->priv_to);
   ast_party_id_reset(&ast_channel_redirecting(clonechan)->priv_to);

   exchange.redirecting = *ast_channel_redirecting(original);
   ast_channel_redirecting_set(original, ast_channel_redirecting(clonechan));
   ast_channel_redirecting_set(clonechan, &exchange.redirecting);

   report_new_callerid(original);

   /* Restore original timing file descriptor */
   ast_channel_set_fd(original, AST_TIMING_FD, ast_channel_timingfd(original));

   /* Our native formats are different now */
   ast_format_cap_copy(ast_channel_nativeformats(original), ast_channel_nativeformats(clonechan));

   /* Context, extension, priority, app data, jump table,  remain the same */
   /* pvt switches.  pbx stays the same, as does next */

   /* Set the write format */
   ast_set_write_format(original, &wformat);

   /* Set the read format */
   ast_set_read_format(original, &rformat);

   /* Copy the music class */
   ast_channel_musicclass_set(original, ast_channel_musicclass(clonechan));

   /* copy over accuntcode and set peeraccount across the bridge */
   ast_channel_accountcode_set(original, S_OR(ast_channel_accountcode(clonechan), ""));
   if (ast_channel_internal_bridged_channel(original)) {
      /* XXX - should we try to lock original's bridged channel here? */
      ast_channel_peeraccount_set(ast_channel_internal_bridged_channel(original), S_OR(ast_channel_accountcode(clonechan), ""));
      ast_cel_report_event(original, AST_CEL_BRIDGE_UPDATE, NULL, NULL, NULL);
   }

   ast_debug(1, "Putting channel %s in %s/%s formats\n", ast_channel_name(original),
      ast_getformatname(&wformat), ast_getformatname(&rformat));

   /* Fixup the original clonechan's physical side */
   if (ast_channel_tech(original)->fixup && ast_channel_tech(original)->fixup(clonechan, original)) {
      ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (clonechan)\n",
         ast_channel_tech(original)->type, ast_channel_name(original));
   }

   /* Fixup the original original's physical side */
   if (ast_channel_tech(clonechan)->fixup && ast_channel_tech(clonechan)->fixup(original, clonechan)) {
      ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (original)\n",
         ast_channel_tech(clonechan)->type, ast_channel_name(clonechan));
   }

   /*
    * Now, at this point, the "clone" channel is totally F'd up.
    * We mark it as a zombie so nothing tries to touch it.  If it's
    * already been marked as a zombie, then we must free it (since
    * it already is considered invalid).
    *
    * This must be done before we unlock clonechan to prevent
    * setting up another masquerade on the clonechan.
    */
   if (ast_test_flag(ast_channel_flags(clonechan), AST_FLAG_ZOMBIE)) {
      clone_was_zombie = 1;
   } else {
      ast_set_flag(ast_channel_flags(clonechan), AST_FLAG_ZOMBIE);
      ast_queue_frame(clonechan, &ast_null_frame);
   }

   /* clear the masquerade channels */
   ast_channel_masq_set(original, NULL);
   ast_channel_masqr_set(clonechan, NULL);

   /*
    * When we unlock original here, it can be immediately setup to
    * masquerade again or hungup.  The new masquerade or hangup
    * will not actually happen until we release the channels
    * container lock.
    */
   ast_channel_unlock(original);
   ast_channel_unlock(clonechan);

   if (clone_sending_dtmf_digit) {
      /*
       * The clonechan was sending a DTMF digit that was not completed
       * before the masquerade.
       */
      ast_bridge_end_dtmf(original, clone_sending_dtmf_digit, clone_sending_dtmf_tv,
         "masquerade");
   }

   /*
    * If an indication is currently playing, maintain it on the
    * channel that is taking the place of original.
    *
    * This is needed because the masquerade is swapping out the
    * internals of the channel, and the new channel private data
    * needs to be made aware of the current visible indication
    * (RINGING, CONGESTION, etc.)
    */
   if (visible_indication) {
      ast_indicate(original, visible_indication);
   }

   /* if moh is playing on the original channel then it needs to be
      maintained on the channel that is replacing it. */
   if (moh_is_playing) {
      ast_moh_start(original, NULL, NULL);
   }

   ast_channel_lock(original);

   /* Signal any blocker */
   if (ast_test_flag(ast_channel_flags(original), AST_FLAG_BLOCKING)) {
      pthread_kill(ast_channel_blocker(original), SIGURG);
   }

   ast_debug(1, "Done Masquerading %s (%d)\n", ast_channel_name(original), ast_channel_state(original));

   if ((bridged = ast_bridged_channel(original))) {
      ast_channel_ref(bridged);
      ast_channel_unlock(original);
      ast_indicate(bridged, AST_CONTROL_SRCCHANGE);
      ast_channel_unref(bridged);
   } else {
      ast_channel_unlock(original);
   }
   ast_indicate(original, AST_CONTROL_SRCCHANGE);

   if (xfer_colp) {
      /*
       * After the masquerade, the original channel pointer actually
       * points to the new transferee channel and the bridged channel
       * is still the intended transfer target party.
       */
      masquerade_colp_transfer(original, xfer_colp);
   }

   if (xfer_ds) {
      ast_datastore_free(xfer_ds);
   }

   if (!clone_was_zombie) {
      ao2_link(channels, clonechan);
   }
   ao2_link(channels, original);
   ao2_unlock(channels);

   if (clone_was_zombie) {
      /* Restart the ast_hangup() that was deferred because of this masquerade. */
      ast_debug(1, "Destroying channel clone '%s'\n", ast_channel_name(clonechan));
      ast_hangup(clonechan);
   }

   /* Release our held safety references. */
   ast_channel_unref(original);
   ast_channel_unref(clonechan);

   return 0;
}
struct ast_channel* ast_dummy_channel_alloc ( void  ) [read]

Create a fake channel structure.

Return values:
NULLfailure
non-NULLsuccessfully allocated channel
Note:
This function should ONLY be used to create a fake channel that can then be populated with data for use in variable substitution when a real channel does not exist.
The created dummy channel should be destroyed by ast_channel_unref(). Using ast_channel_release() needlessly grabs the channel container lock and can cause a deadlock as a result. Also grabbing the channel container lock reduces system performance.

Definition at line 1202 of file channel.c.

References ast_channel_datastores(), ast_channel_epfd_set(), ast_channel_internal_alertpipe_clear(), ast_channel_internal_alloc, ast_channel_internal_fd_clear_all(), ast_channel_timingfd_set(), ast_channel_varshead(), ast_dummy_channel_destructor(), AST_LIST_HEAD_INIT_NOLOCK, and ast_pbx_hangup_handler_init().

Referenced by acf_odbc_read(), acf_odbc_write(), action_getvar(), ast_add_extension2_lockopt(), ast_cel_fabricate_channel_from_event(), ast_pbx_outgoing_cdr_failed(), ast_str_substitute_variables_full(), cli_odbc_read(), cli_odbc_write(), custom_log(), make_email_file(), manager_log(), pbx_substitute_variables_helper_full(), rotate_file(), sendmail(), sendpage(), syslog_log(), and write_cdr().

{
   struct ast_channel *tmp;
   struct varshead *headp;

   if (!(tmp = ast_channel_internal_alloc(ast_dummy_channel_destructor))) {
      /* Dummy channel structure allocation failure. */
      return NULL;
   }

   ast_pbx_hangup_handler_init(tmp);
   AST_LIST_HEAD_INIT_NOLOCK(ast_channel_datastores(tmp));

   /*
    * Init file descriptors to unopened state just in case
    * autoservice is called on the channel or something tries to
    * read a frame from it.
    */
   ast_channel_timingfd_set(tmp, -1);
   ast_channel_internal_alertpipe_clear(tmp);
   ast_channel_internal_fd_clear_all(tmp);
#ifdef HAVE_EPOLL
   ast_channel_epfd_set(tmp, -1);
#endif

   headp = ast_channel_varshead(tmp);
   AST_LIST_HEAD_INIT_NOLOCK(headp);

   return tmp;
}
static void ast_dummy_channel_destructor ( void *  obj) [static]

Free a dummy channel structure.

Definition at line 2453 of file channel.c.

References ast_cdr_discard(), ast_channel_caller(), ast_channel_cdr(), ast_channel_cdr_set(), ast_channel_connected(), ast_channel_datastores(), ast_channel_dialed(), ast_channel_internal_cleanup(), ast_channel_redirecting(), ast_channel_varshead(), ast_datastore_free(), AST_LIST_REMOVE_HEAD, ast_party_caller_free(), ast_party_connected_line_free(), ast_party_dialed_free(), ast_party_redirecting_free(), ast_pbx_hangup_handler_destroy(), and ast_var_delete().

Referenced by ast_dummy_channel_alloc().

{
   struct ast_channel *chan = obj;
   struct ast_datastore *datastore;
   struct ast_var_t *vardata;
   struct varshead *headp;

   ast_pbx_hangup_handler_destroy(chan);

   /* Get rid of each of the data stores on the channel */
   while ((datastore = AST_LIST_REMOVE_HEAD(ast_channel_datastores(chan), entry))) {
      /* Free the data store */
      ast_datastore_free(datastore);
   }

   ast_party_dialed_free(ast_channel_dialed(chan));
   ast_party_caller_free(ast_channel_caller(chan));
   ast_party_connected_line_free(ast_channel_connected(chan));
   ast_party_redirecting_free(ast_channel_redirecting(chan));

   /* loop over the variables list, freeing all data and deleting list items */
   /* no need to lock the list, as the channel is already locked */
   headp = ast_channel_varshead(chan);
   while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
      ast_var_delete(vardata);

   if (ast_channel_cdr(chan)) {
      ast_cdr_discard(ast_channel_cdr(chan));
      ast_channel_cdr_set(chan, NULL);
   }

   ast_channel_internal_cleanup(chan);
}
static enum ast_bridge_result ast_generic_bridge ( struct ast_channel c0,
struct ast_channel c1,
struct ast_bridge_config config,
struct ast_frame **  fo,
struct ast_channel **  rc 
) [static]

Definition at line 7498 of file channel.c.

References AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_FAILED, AST_BRIDGE_IGNORE_SIGS, AST_BRIDGE_RETRY, ast_channel_clear_softhangup(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_channel_internal_bridged_channel_set(), ast_channel_lock_both, ast_channel_name(), ast_channel_nativeformats(), ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), ast_channel_softhangup_internal_flag(), ast_channel_tech_pvt(), ast_channel_unlock, ast_clear_flag, AST_CONTROL_AOC, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HOLD, AST_CONTROL_MCID, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_REDIRECTING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_debug, AST_FEATURE_WARNING_ACTIVE, ast_format_cap_destroy(), ast_format_cap_dup(), ast_format_cap_identical(), AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_indicate_data(), ast_jb_do_usecheck(), ast_jb_empty_and_reset(), ast_jb_get_and_deliver(), ast_jb_get_when_to_wakeup(), ast_jb_put(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_waitfor_n(), ast_write(), ast_frame::data, ast_frame::datalen, f, ast_bridge_config::feature_timer, ast_bridge_config::flags, ast_frame::frametype, ast_frame_subclass::integer, ast_bridge_config::nexteventts, ast_frame::ptr, ast_frame::subclass, and ast_bridge_config::timelimit.

Referenced by ast_channel_bridge().

{
   /* Copy voice back and forth between the two channels. */
   struct ast_channel *cs[3];
   struct ast_frame *f;
   enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
   struct ast_format_cap *o0nativeformats;
   struct ast_format_cap *o1nativeformats;
   int watch_c0_dtmf;
   int watch_c1_dtmf;
   void *pvt0, *pvt1;
   /* Indicates whether a frame was queued into a jitterbuffer */
   int frame_put_in_jb = 0;
   int jb_in_use;
   int to;

   o0nativeformats = ast_format_cap_dup(ast_channel_nativeformats(c0));
   o1nativeformats = ast_format_cap_dup(ast_channel_nativeformats(c1));

   if (!o0nativeformats || !o1nativeformats) {
      ast_format_cap_destroy(o0nativeformats); /* NULL safe */
      ast_format_cap_destroy(o1nativeformats); /* NULL safe */
      return AST_BRIDGE_FAILED;
   }

   cs[0] = c0;
   cs[1] = c1;
   pvt0 = ast_channel_tech_pvt(c0);
   pvt1 = ast_channel_tech_pvt(c1);
   watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0;
   watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1;

   /* Check the need of a jitterbuffer for each channel */
   jb_in_use = ast_jb_do_usecheck(c0, c1);
   if (jb_in_use)
      ast_jb_empty_and_reset(c0, c1);

   ast_poll_channel_add(c0, c1);

   if (config->feature_timer > 0 && ast_tvzero(config->nexteventts)) {
      /* nexteventts is not set when the bridge is not scheduled to
       * break, so calculate when the bridge should possibly break
       * if a partial feature match timed out */
      config->nexteventts = ast_tvadd(ast_tvnow(), ast_samp2tv(config->feature_timer, 1000));
   }

   for (;;) {
      struct ast_channel *who, *other;

      if ((ast_channel_tech_pvt(c0) != pvt0) || (ast_channel_tech_pvt(c1) != pvt1) ||
          (!ast_format_cap_identical(o0nativeformats, ast_channel_nativeformats(c0))) ||
          (!ast_format_cap_identical(o1nativeformats, ast_channel_nativeformats(c1)))) {
         /* Check for Masquerade, codec changes, etc */
         res = AST_BRIDGE_RETRY;
         break;
      }
      if (config->nexteventts.tv_sec) {
         to = ast_tvdiff_ms(config->nexteventts, ast_tvnow());
         if (to <= 0) {
            if (config->timelimit && !config->feature_timer && !ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) {
               res = AST_BRIDGE_RETRY;
               /* generic bridge ending to play warning */
               ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
            } else if (config->feature_timer) {
               /* feature timer expired - make sure we do not play warning */
               ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
               res = AST_BRIDGE_RETRY;
            } else {
               res = AST_BRIDGE_COMPLETE;
            }
            break;
         }
      } else {
         /* If a feature has been started and the bridge is configured to
          * to not break, leave the channel bridge when the feature timer
          * time has elapsed so the DTMF will be sent to the other side.
          */
         if (!ast_tvzero(config->nexteventts)) {
            int diff = ast_tvdiff_ms(config->nexteventts, ast_tvnow());
            if (diff <= 0) {
               res = AST_BRIDGE_RETRY;
               break;
            }
         }
         to = -1;
      }
      /* Calculate the appropriate max sleep interval - in general, this is the time,
         left to the closest jb delivery moment */
      if (jb_in_use)
         to = ast_jb_get_when_to_wakeup(c0, c1, to);
      who = ast_waitfor_n(cs, 2, &to);
      if (!who) {
         /* No frame received within the specified timeout - check if we have to deliver now */
         if (jb_in_use)
            ast_jb_get_and_deliver(c0, c1);
         if ((ast_channel_softhangup_internal_flag(c0) | ast_channel_softhangup_internal_flag(c1)) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
            if (ast_channel_softhangup_internal_flag(c0) & AST_SOFTHANGUP_UNBRIDGE) {
               ast_channel_clear_softhangup(c0, AST_SOFTHANGUP_UNBRIDGE);
            }
            if (ast_channel_softhangup_internal_flag(c1) & AST_SOFTHANGUP_UNBRIDGE) {
               ast_channel_clear_softhangup(c1, AST_SOFTHANGUP_UNBRIDGE);
            }
            ast_channel_lock_both(c0, c1);
            ast_channel_internal_bridged_channel_set(c0, c1);
            ast_channel_internal_bridged_channel_set(c1, c0);
            ast_channel_unlock(c0);
            ast_channel_unlock(c1);
         }
         continue;
      }
      f = ast_read(who);
      if (!f) {
         *fo = NULL;
         *rc = who;
         ast_debug(1, "Didn't get a frame from channel: %s\n", ast_channel_name(who));
         break;
      }

      other = (who == c0) ? c1 : c0; /* the 'other' channel */
      /* Try add the frame info the who's bridged channel jitterbuff */
      if (jb_in_use)
         frame_put_in_jb = !ast_jb_put(other, f);

      if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) {
         int bridge_exit = 0;

         switch (f->subclass.integer) {
         case AST_CONTROL_PVT_CAUSE_CODE:
         case AST_CONTROL_AOC:
         case AST_CONTROL_MCID:
            ast_indicate_data(other, f->subclass.integer, f->data.ptr, f->datalen);
            break;
         case AST_CONTROL_REDIRECTING:
            if (ast_channel_redirecting_sub(who, other, f, 1) &&
               ast_channel_redirecting_macro(who, other, f, other == c0, 1)) {
               ast_indicate_data(other, f->subclass.integer, f->data.ptr, f->datalen);
            }
            break;
         case AST_CONTROL_CONNECTED_LINE:
            if (ast_channel_connected_line_sub(who, other, f, 1) &&
               ast_channel_connected_line_macro(who, other, f, other == c0, 1)) {
               ast_indicate_data(other, f->subclass.integer, f->data.ptr, f->datalen);
            }
            break;
         case AST_CONTROL_HOLD:
         case AST_CONTROL_UNHOLD:
         case AST_CONTROL_VIDUPDATE:
         case AST_CONTROL_SRCUPDATE:
         case AST_CONTROL_SRCCHANGE:
         case AST_CONTROL_T38_PARAMETERS:
            ast_indicate_data(other, f->subclass.integer, f->data.ptr, f->datalen);
            if (jb_in_use) {
               ast_jb_empty_and_reset(c0, c1);
            }
            break;
         default:
            *fo = f;
            *rc = who;
            bridge_exit = 1;
            ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass.integer, ast_channel_name(who));
            break;
         }
         if (bridge_exit)
            break;
      }
      if ((f->frametype == AST_FRAME_VOICE) ||
          (f->frametype == AST_FRAME_DTMF_BEGIN) ||
          (f->frametype == AST_FRAME_DTMF) ||
          (f->frametype == AST_FRAME_VIDEO) ||
          (f->frametype == AST_FRAME_IMAGE) ||
          (f->frametype == AST_FRAME_HTML) ||
          (f->frametype == AST_FRAME_MODEM) ||
          (f->frametype == AST_FRAME_TEXT)) {
         /* monitored dtmf causes exit from bridge */
         int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf;

         if (monitored_source &&
            (f->frametype == AST_FRAME_DTMF_END ||
            f->frametype == AST_FRAME_DTMF_BEGIN)) {
            *fo = f;
            *rc = who;
            ast_debug(1, "Got DTMF %s on channel (%s)\n",
               f->frametype == AST_FRAME_DTMF_END ? "end" : "begin",
               ast_channel_name(who));

            break;
         }
         /* Write immediately frames, not passed through jb */
         if (!frame_put_in_jb)
            ast_write(other, f);

         /* Check if we have to deliver now */
         if (jb_in_use)
            ast_jb_get_and_deliver(c0, c1);
      }
      /* XXX do we want to pass on also frames not matched above ? */
      ast_frfree(f);

#ifndef HAVE_EPOLL
      /* Swap who gets priority */
      cs[2] = cs[0];
      cs[0] = cs[1];
      cs[1] = cs[2];
#endif
   }

   ast_poll_channel_del(c0, c1);

   ast_format_cap_destroy(o0nativeformats);
   ast_format_cap_destroy(o1nativeformats);

   return res;
}
struct ast_channel_tech* ast_get_channel_tech ( const char *  name) [read]

Get handle to channel driver based on name.

Get a channel technology structure by name.

Definition at line 774 of file channel.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and chanlist::tech.

Referenced by __ast_channel_alloc_ap(), _ast_device_state(), ast_cc_callback(), and ast_var_channel_types_table().

{
   struct chanlist *chanls;
   const struct ast_channel_tech *ret = NULL;

   AST_RWLIST_RDLOCK(&backends);

   AST_RWLIST_TRAVERSE(&backends, chanls, list) {
      if (!strcasecmp(name, chanls->tech->type)) {
         ret = chanls->tech;
         break;
      }
   }

   AST_RWLIST_UNLOCK(&backends);

   return ret;
}
ast_group_t ast_get_group ( const char *  s)

Definition at line 8303 of file channel.c.

References ast_log(), ast_strlen_zero(), group, LOG_ERROR, and LOG_WARNING.

Referenced by _parse(), build_device(), build_gateway(), build_peer(), config_parse_variables(), custom_group_handler(), func_channel_write_real(), process_dahdi(), and read_agent_config().

{
   char *piece;
   char *c;
   int start=0, finish=0, x;
   ast_group_t group = 0;

   if (ast_strlen_zero(s))
      return 0;

   c = ast_strdupa(s);

   while ((piece = strsep(&c, ","))) {
      if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) {
         /* Range */
      } else if (sscanf(piece, "%30d", &start)) {
         /* Just one */
         finish = start;
      } else {
         ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
         continue;
      }
      for (x = start; x <= finish; x++) {
         if ((x > 63) || (x < 0)) {
            ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
         } else
            group |= ((ast_group_t) 1 << x);
      }
   }
   return group;
}
struct ast_namedgroups* ast_get_namedgroups ( const char *  s) [read]

Create an ast_namedgroups set with group names from comma separated string.

Remove leading and trailing whitespace

Definition at line 8360 of file channel.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_container_alloc_options, ao2_container_count(), ao2_find, ao2_link, ao2_ref, ast_skip_blanks(), ast_str_hash(), ast_strip(), ast_strlen_zero(), ast_trim_blanks(), namedgroup_member::hash, len(), namedgroup_member::name, namedgroup_cmp_cb(), namedgroup_hash_cb(), OBJ_NODATA, OBJ_POINTER, and OBJ_UNLINK.

Referenced by _parse(), build_peer(), func_channel_write_real(), and process_dahdi().

{
   struct ao2_container *namedgroups;
   char *piece;
   char *c;

   if (!s) {
      return NULL;
   }

   /*! \brief Remove leading and trailing whitespace */
   c = ast_trim_blanks(ast_strdupa(ast_skip_blanks(s)));
   if (ast_strlen_zero(c)) {
      return NULL;
   }

   namedgroups = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 19,
      namedgroup_hash_cb, namedgroup_cmp_cb);
   if (!namedgroups) {
      return NULL;
   }

   while ((piece = strsep(&c, ","))) {
      struct namedgroup_member *member;
      size_t len;

      /* remove leading/trailing whitespace */
      piece = ast_strip(piece);

      len = strlen(piece);
      if (!len) {
         continue;
      }

      member = ao2_alloc_options(sizeof(*member) + len, NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
      if (!member) {
         ao2_ref(namedgroups, -1);
         return NULL;
      }
      strcpy(member->name, piece);/* Safe */
      member->hash = ast_str_hash(member->name);

      /* every group name may exist only once, delete duplicates */
      ao2_find(namedgroups, member, OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
      ao2_link(namedgroups, member);
      ao2_ref(member, -1);
   }

   if (!ao2_container_count(namedgroups)) {
      /* There were no group names specified. */
      ao2_ref(namedgroups, -1);
      namedgroups = NULL;
   }

   return (struct ast_namedgroups *) namedgroups;
}
int ast_hangup ( struct ast_channel chan)

Hangup a channel.

Hang up a channel.

Definition at line 2752 of file channel.c.

References ao2_unlink, ast_assert, ast_autoservice_stop(), ast_cause2str(), ast_cc_offer(), ast_cdr_detach(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_DIALED, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, AST_CEL_HANGUP, ast_cel_report_event(), ast_channel_accountcode(), ast_channel_blocker(), ast_channel_blockproc(), ast_channel_caller(), ast_channel_cdr(), ast_channel_cdr_set(), ast_channel_connected(), ast_channel_flags(), ast_channel_generator(), ast_channel_generator_set(), ast_channel_generatordata(), ast_channel_generatordata_set(), ast_channel_hangupcause(), ast_channel_hangupsource(), ast_channel_lock, ast_channel_masq(), ast_channel_masqr(), ast_channel_name(), ast_channel_sched(), ast_channel_sched_set(), ast_channel_stream(), ast_channel_stream_set(), ast_channel_tech(), ast_channel_uniqueid(), ast_channel_unlock, ast_channel_unref, ast_channel_vstream(), ast_channel_vstream_set(), ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_log(), ast_manager_event, ast_pbx_hangup_handler_run(), ast_sched_context_destroy(), ast_set_flag, ast_test_flag, channels, destroy_hooks(), EVENT_FLAG_CALL, free_translation(), ast_channel_tech::hangup, LOG_WARNING, name, pbx_builtin_getvar_helper(), ast_generator::release, S_COR, and S_OR.

Referenced by __analog_handle_event(), __analog_ss_thread(), __ast_pbx_run(), __ast_request_and_dial(), __oh323_new(), action_bridge(), agent_request(), alloc_playback_chan(), alsa_new(), analog_handle_init_event(), analog_ss_thread(), answer_exec_run(), ast_async_goto(), ast_autoservice_chan_hangup_peer(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), ast_do_masquerade(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial_channel(), bridge_call_thread(), bridge_call_thread_launch(), bridge_channel_thread(), bridge_exec(), build_conf(), builtin_atxfer(), chanavail_exec(), check_availability(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), console_new(), create_msg_q_chan(), dahdi_handle_event(), dahdi_new(), destroy_conference_bridge(), dial_exec_full(), dial_transfer(), do_forward(), do_hang(), do_idle_thread(), do_monitor(), feature_attended_transfer(), feature_request_and_dial(), generic_recall(), gtalk_new(), handle_call_forward(), handle_call_outgoing(), handle_callforward_button(), handle_frame(), handle_frame_ownerless(), handle_hd_hf(), handle_init_event(), handle_invite_replaces(), handle_request_invite(), handle_timeout_trip(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), jingle_action_session_initiate(), jingle_new(), local_hangup(), manage_parked_call(), masq_park_call(), meetme_menu_admin_extended(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), my_distinctive_ring(), my_handle_notify_message(), nbs_new(), oss_new(), parkandannounce_exec(), phone_new(), pri_dchannel(), pri_ss_thread(), record_thread(), setsubstate(), sip_park(), sip_park_thread(), sip_pickup_thread(), skinny_new(), ss7_start_call(), unistim_new(), and wait_for_answer().

{
   char extra_str[64]; /* used for cel logging below */

   ast_autoservice_stop(chan);

   ast_channel_lock(chan);

   /*
    * Do the masquerade if someone is setup to masquerade into us.
    *
    * NOTE: We must hold the channel lock after testing for a
    * pending masquerade and setting the channel as a zombie to
    * prevent __ast_channel_masquerade() from setting up a
    * masquerade with a dead channel.
    */
   while (ast_channel_masq(chan)) {
      ast_channel_unlock(chan);
      ast_do_masquerade(chan);
      ast_channel_lock(chan);
   }

   if (ast_channel_masqr(chan)) {
      /*
       * This channel is one which will be masqueraded into something.
       * Mark it as a zombie already so ast_do_masquerade() will know
       * to free it later.
       */
      ast_set_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE);
      destroy_hooks(chan);
      ast_channel_unlock(chan);
      return 0;
   }

   /* Mark as a zombie so a masquerade cannot be setup on this channel. */
   ast_set_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE);

   ast_channel_unlock(chan);

   /*
    * XXX if running the hangup handlers here causes problems
    * because the handlers take too long to execute, we could move
    * the meat of this function into another thread.  A thread
    * where channels go to die.
    *
    * If this is done, ast_autoservice_chan_hangup_peer() will no
    * longer be needed.
    */
   ast_pbx_hangup_handler_run(chan);
   ao2_unlink(channels, chan);
   ast_channel_lock(chan);

   destroy_hooks(chan);

   free_translation(chan);
   /* Close audio stream */
   if (ast_channel_stream(chan)) {
      ast_closestream(ast_channel_stream(chan));
      ast_channel_stream_set(chan, NULL);
   }
   /* Close video stream */
   if (ast_channel_vstream(chan)) {
      ast_closestream(ast_channel_vstream(chan));
      ast_channel_vstream_set(chan, NULL);
   }
   if (ast_channel_sched(chan)) {
      ast_sched_context_destroy(ast_channel_sched(chan));
      ast_channel_sched_set(chan, NULL);
   }

   if (ast_channel_generatordata(chan)) { /* Clear any tone stuff remaining */
      if (ast_channel_generator(chan) && ast_channel_generator(chan)->release) {
         ast_channel_generator(chan)->release(chan, ast_channel_generatordata(chan));
      }
   }
   ast_channel_generatordata_set(chan, NULL);
   ast_channel_generator_set(chan, NULL);

   snprintf(extra_str, sizeof(extra_str), "%d,%s,%s", ast_channel_hangupcause(chan), ast_channel_hangupsource(chan), S_OR(pbx_builtin_getvar_helper(chan, "DIALSTATUS"), ""));
   ast_cel_report_event(chan, AST_CEL_HANGUP, NULL, extra_str, NULL);

   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING)) {
      ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
         "is blocked by thread %ld in procedure %s!  Expect a failure\n",
         (long) pthread_self(), ast_channel_name(chan), (long)ast_channel_blocker(chan), ast_channel_blockproc(chan));
      ast_assert(ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING) == 0);
   }

   ast_debug(1, "Hanging up channel '%s'\n", ast_channel_name(chan));
   if (ast_channel_tech(chan)->hangup) {
      ast_channel_tech(chan)->hangup(chan);
   }

   ast_channel_unlock(chan);

   ast_cc_offer(chan);
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a channel is hung up.</synopsis>
            <syntax>
               <parameter name="Cause">
                  <para>A numeric cause code for why the channel was hung up.</para>
               </parameter>
               <parameter name="Cause-txt">
                  <para>A description of why the channel was hung up.</para>
               </parameter>
            </syntax>
      </managerEventInstance>
   ***/
   ast_manager_event(chan, EVENT_FLAG_CALL, "Hangup",
      "Channel: %s\r\n"
      "Uniqueid: %s\r\n"
      "CallerIDNum: %s\r\n"
      "CallerIDName: %s\r\n"
      "ConnectedLineNum: %s\r\n"
      "ConnectedLineName: %s\r\n"
      "AccountCode: %s\r\n"
      "Cause: %d\r\n"
      "Cause-txt: %s\r\n",
      ast_channel_name(chan),
      ast_channel_uniqueid(chan),
      S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, "<unknown>"),
      S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, "<unknown>"),
      S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, "<unknown>"),
      S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, "<unknown>"),
      ast_channel_accountcode(chan),
      ast_channel_hangupcause(chan),
      ast_cause2str(ast_channel_hangupcause(chan))
      );

   if (ast_channel_cdr(chan) && !ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_BRIDGED) &&
      !ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_POST_DISABLED) &&
      (ast_channel_cdr(chan)->disposition != AST_CDR_NULL || ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_DIALED))) {
      ast_channel_lock(chan);
      ast_cdr_end(ast_channel_cdr(chan));
      ast_cdr_detach(ast_channel_cdr(chan));
      ast_channel_cdr_set(chan, NULL);
      ast_channel_unlock(chan);
   }

   ast_channel_unref(chan);

   return 0;
}
int ast_indicate ( struct ast_channel chan,
int  condition 
)

Indicates condition of channel.

Note:
Absolutely _NO_ channel locks should be held before calling this function.
Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
Parameters:
chanchannel to change the indication
conditionwhich condition to indicate on the channel
Returns:
Returns 0 on success, -1 on failure

Definition at line 4396 of file channel.c.

References ast_indicate_data().

Referenced by __ast_play_and_record(), agent_request(), alsa_call(), answer_trunk_chan(), app_exec(), ast_bridge_call(), ast_bridge_set_single_src_video_mode(), ast_bridge_update_talker_src_video_mode(), ast_channel_bridge(), ast_do_masquerade(), ast_dtmf_stream(), ast_raw_answer(), attempt_transfer(), builtin_atxfer(), builtin_blindtransfer(), cli_console_answer(), conf_run(), console_call(), dial_exec_full(), dial_trunk(), dialandactivatesub(), disa_exec(), do_forward(), feature_request_and_dial(), finishup(), handle_callforward_button(), handle_frame(), handle_recordfile(), handle_request_refer(), local_attended_transfer(), manage_parked_call(), mgcp_ss(), monitor_dial(), oss_call(), park_call_full(), parked_call_exec(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_incomplete(), pbx_builtin_proceeding(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), record_exec(), rna(), say_periodic_announcement(), say_position(), send_waveform_to_channel(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), try_calling(), and wait_for_answer().

{
   return ast_indicate_data(chan, condition, NULL, 0);
}
int ast_indicate_data ( struct ast_channel chan,
int  condition,
const void *  data,
size_t  datalen 
)

Indicates condition of channel, with payload.

Note:
Absolutely _NO_ channel locks should be held before calling this function.
Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
Parameters:
chanchannel to change the indication
conditionwhich condition to indicate on the channel
datapointer to payload data
datalensize of payload data
Returns:
Returns 0 on success, -1 on failure
Note:
If we compare the enumeration type, which does not have any negative constants, the compiler may optimize this code away. Therefore, we must perform an integer comparison here.

Definition at line 4466 of file channel.c.

References _XXX_AST_CONTROL_T38, ast_channel_connected(), ast_channel_flags(), ast_channel_framehooks(), ast_channel_hangupcause_hash_set(), ast_channel_lock, ast_channel_name(), ast_channel_redirecting(), ast_channel_set_connected_line(), ast_channel_set_redirecting(), ast_channel_tech(), ast_channel_unlock, ast_channel_visible_indication_set(), ast_channel_zone(), ast_check_hangup(), ast_connected_line_parse_data(), AST_CONTROL_ANSWER, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_END_OF_Q, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_MCID, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_READ_ACTION, AST_CONTROL_REDIRECTING, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_TRANSFER, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_debug, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, ast_framehook_list_is_empty(), ast_framehook_list_write_event(), ast_frdup(), ast_frfree, ast_get_indication_tone(), ast_log(), ast_party_connected_line_free(), ast_party_connected_line_set_init(), ast_party_redirecting_free(), ast_party_redirecting_set_init(), ast_playtones_start(), ast_playtones_stop(), ast_redirecting_parse_data(), AST_STATE_UP, ast_test_flag, ast_tone_zone_sound_unref(), ast_tone_zone_sound::data, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_channel_tech::indicate, ast_frame_subclass::integer, is_visible_indication(), LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

Referenced by __ast_read(), action_aocmessage(), agent_hangup(), app_exec(), ast_bridge_call(), ast_channel_update_connected_line(), ast_channel_update_redirecting(), ast_generic_bridge(), ast_handle_cc_control_frame(), ast_indicate(), disable_t38(), fax_gateway_indicate_t38(), feature_request_and_dial(), generic_fax_exec(), handle_frame(), local_bridge_loop(), login_exec(), manage_parked_call(), park_call_full(), pbx_builtin_waitexten(), receivefax_t38_init(), remote_bridge_loop(), sendfax_t38_init(), set_fax_t38_caps(), transmit_audio(), transmit_t38(), wait_for_answer(), and wait_for_winner().

{
   /* By using an enum, we'll get compiler warnings for values not handled
    * in switch statements. */
   enum ast_control_frame_type condition = _condition;
   struct ast_tone_zone_sound *ts = NULL;
   int res;
   /* this frame is used by framehooks. if it is set, we must free it at the end of this function */
   struct ast_frame *awesome_frame = NULL;

   ast_channel_lock(chan);

   /* Don't bother if the channel is about to go away, anyway. */
   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
      res = -1;
      goto indicate_cleanup;
   }

   if (!ast_framehook_list_is_empty(ast_channel_framehooks(chan))) {
      /* Do framehooks now, do it, go, go now */
      struct ast_frame frame = {
         .frametype = AST_FRAME_CONTROL,
         .subclass.integer = condition,
         .data.ptr = (void *) data, /* this cast from const is only okay because we do the ast_frdup below */
         .datalen = datalen
      };

      /* we have now committed to freeing this frame */
      awesome_frame = ast_frdup(&frame);

      /* who knows what we will get back! the anticipation is killing me. */
      if (!(awesome_frame = ast_framehook_list_write_event(ast_channel_framehooks(chan), awesome_frame))
         || awesome_frame->frametype != AST_FRAME_CONTROL) {

         res = 0;
         goto indicate_cleanup;
      }

      condition = awesome_frame->subclass.integer;
      data = awesome_frame->data.ptr;
      datalen = awesome_frame->datalen;
   }

   switch (condition) {
   case AST_CONTROL_CONNECTED_LINE:
      {
         struct ast_party_connected_line connected;

         ast_party_connected_line_set_init(&connected, ast_channel_connected(chan));
         res = ast_connected_line_parse_data(data, datalen, &connected);
         if (!res) {
            ast_channel_set_connected_line(chan, &connected, NULL);
         }
         ast_party_connected_line_free(&connected);
      }
      break;

   case AST_CONTROL_REDIRECTING:
      {
         struct ast_party_redirecting redirecting;

         ast_party_redirecting_set_init(&redirecting, ast_channel_redirecting(chan));
         res = ast_redirecting_parse_data(data, datalen, &redirecting);
         if (!res) {
            ast_channel_set_redirecting(chan, &redirecting, NULL);
         }
         ast_party_redirecting_free(&redirecting);
      }
      break;

   default:
      break;
   }

   if (is_visible_indication(condition)) {
      /* A new visible indication is requested. */
      ast_channel_visible_indication_set(chan, condition);
   } else if (condition == AST_CONTROL_UNHOLD || _condition < 0) {
      /* Visible indication is cleared/stopped. */
      ast_channel_visible_indication_set(chan, 0);
   }

   if (ast_channel_tech(chan)->indicate) {
      /* See if the channel driver can handle this condition. */
      res = ast_channel_tech(chan)->indicate(chan, condition, data, datalen);
   } else {
      res = -1;
   }

   if (!res) {
      /* The channel driver successfully handled this indication */
      res = 0;
      goto indicate_cleanup;
   }

   /* The channel driver does not support this indication, let's fake
    * it by doing our own tone generation if applicable. */

   /*!\note If we compare the enumeration type, which does not have any
    * negative constants, the compiler may optimize this code away.
    * Therefore, we must perform an integer comparison here. */
   if (_condition < 0) {
      /* Stop any tones that are playing */
      ast_playtones_stop(chan);
      res = 0;
      goto indicate_cleanup;
   }

   /* Handle conditions that we have tones for. */
   switch (condition) {
   case _XXX_AST_CONTROL_T38:
      /* deprecated T.38 control frame */
      res = -1;
      goto indicate_cleanup;
   case AST_CONTROL_T38_PARAMETERS:
      /* there is no way to provide 'default' behavior for these
       * control frames, so we need to return failure, but there
       * is also no value in the log message below being emitted
       * since failure to handle these frames is not an 'error'
       * so just return right now. in addition, we want to return
       * whatever value the channel driver returned, in case it
       * has some meaning.*/
      goto indicate_cleanup;
   case AST_CONTROL_RINGING:
      ts = ast_get_indication_tone(ast_channel_zone(chan), "ring");
      /* It is common practice for channel drivers to return -1 if trying
       * to indicate ringing on a channel which is up. The idea is to let the
       * core generate the ringing inband. However, we don't want the
       * warning message about not being able to handle the specific indication
       * to print nor do we want ast_indicate_data to return an "error" for this
       * condition
       */
      if (ast_channel_state(chan) == AST_STATE_UP) {
         res = 0;
      }
      break;
   case AST_CONTROL_BUSY:
      ts = ast_get_indication_tone(ast_channel_zone(chan), "busy");
      break;
   case AST_CONTROL_INCOMPLETE:
   case AST_CONTROL_CONGESTION:
      ts = ast_get_indication_tone(ast_channel_zone(chan), "congestion");
      break;
   case AST_CONTROL_PVT_CAUSE_CODE:
      ast_channel_hangupcause_hash_set(chan, data, datalen);
      res = 0;
      break;
   case AST_CONTROL_PROGRESS:
   case AST_CONTROL_PROCEEDING:
   case AST_CONTROL_VIDUPDATE:
   case AST_CONTROL_SRCUPDATE:
   case AST_CONTROL_SRCCHANGE:
   case AST_CONTROL_RADIO_KEY:
   case AST_CONTROL_RADIO_UNKEY:
   case AST_CONTROL_OPTION:
   case AST_CONTROL_WINK:
   case AST_CONTROL_FLASH:
   case AST_CONTROL_OFFHOOK:
   case AST_CONTROL_TAKEOFFHOOK:
   case AST_CONTROL_ANSWER:
   case AST_CONTROL_HANGUP:
   case AST_CONTROL_RING:
   case AST_CONTROL_HOLD:
   case AST_CONTROL_UNHOLD:
   case AST_CONTROL_TRANSFER:
   case AST_CONTROL_CONNECTED_LINE:
   case AST_CONTROL_REDIRECTING:
   case AST_CONTROL_CC:
   case AST_CONTROL_READ_ACTION:
   case AST_CONTROL_AOC:
   case AST_CONTROL_END_OF_Q:
   case AST_CONTROL_MCID:
   case AST_CONTROL_UPDATE_RTP_PEER:
      /* Nothing left to do for these. */
      res = 0;
      break;
   }

   if (ts) {
      /* We have a tone to play, yay. */
      ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", ast_channel_name(chan), condition);
      res = ast_playtones_start(chan, 0, ts->data, 1);
      ts = ast_tone_zone_sound_unref(ts);
   }

   if (res) {
      /* not handled */
      ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, ast_channel_name(chan));
   }

indicate_cleanup:
   ast_channel_unlock(chan);
   if (awesome_frame) {
      ast_frfree(awesome_frame);
   }

   return res;
}
void ast_install_music_functions ( int(*)(struct ast_channel *, const char *, const char *)  start_ptr,
void(*)(struct ast_channel *)  stop_ptr,
void(*)(struct ast_channel *)  cleanup_ptr 
)

Definition at line 8435 of file channel.c.

References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.

Referenced by load_module(), and reload().

{
   ast_moh_start_ptr = start_ptr;
   ast_moh_stop_ptr = stop_ptr;
   ast_moh_cleanup_ptr = cleanup_ptr;
}
int ast_internal_timing_enabled ( struct ast_channel chan)

Check if the channel can run in internal timing mode.

Parameters:
chanThe channel to check
Returns:
boolean

This function will return 1 if internal timing is enabled and the timing device is available.

Definition at line 4381 of file channel.c.

References ast_channel_timingfd(), and ast_opt_internal_timing.

Referenced by add_sdp(), and ast_read_generator_actions().

{
   return (ast_opt_internal_timing && ast_channel_timingfd(chan) > -1);
}
int ast_is_deferrable_frame ( const struct ast_frame frame)

Should we keep this frame for later?

There are functions such as ast_safe_sleep which will service a channel to ensure that it does not have a large backlog of queued frames. When this happens, we want to hold on to specific frame types and just drop others. This function will tell if the frame we just read should be held onto.

Parameters:
frameThe frame we just read
Return values:
1frame should be kept
0frame should be dropped

Definition at line 1646 of file channel.c.

References AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, and ast_frame::frametype.

Referenced by ast_safe_sleep_conditional(), autoservice_run(), and feature_request_and_dial().

{
   /* Do not add a default entry in this switch statement.  Each new
    * frame type should be addressed directly as to whether it should
    * be queued up or not.
    */
   switch (frame->frametype) {
   case AST_FRAME_CONTROL:
   case AST_FRAME_TEXT:
   case AST_FRAME_IMAGE:
   case AST_FRAME_HTML:
      return 1;

   case AST_FRAME_DTMF_END:
   case AST_FRAME_DTMF_BEGIN:
   case AST_FRAME_VOICE:
   case AST_FRAME_VIDEO:
   case AST_FRAME_NULL:
   case AST_FRAME_IAX:
   case AST_FRAME_CNG:
   case AST_FRAME_MODEM:
      return 0;
   }
   return 0;
}
void ast_moh_cleanup ( struct ast_channel chan)

Definition at line 8469 of file channel.c.

References ast_moh_cleanup_ptr.

Referenced by ast_channel_destructor().

int ast_moh_start ( struct ast_channel chan,
const char *  mclass,
const char *  interpclass 
)

Turn on music on hold on a given channel.

Parameters:
chanThe channel structure that will get music on hold
mclassThe class to use if the musicclass is not currently set on the channel structure.
interpclassThe class to use if the musicclass is not currently set on the channel structure or in the mclass argument.
Return values:
Zeroon success
non-zeroon failure

Definition at line 8452 of file channel.c.

References ast_moh_start_ptr, and ast_verb.

Referenced by alsa_indicate(), app_exec(), ast_do_masquerade(), conf_moh_start(), conf_moh_unsuspend(), conf_start_moh(), console_indicate(), dahdi_indicate(), dial_exec_full(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), jingle_indicate(), local_indicate(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), queue_exec(), retrydial_exec(), rna(), say_periodic_announcement(), say_position(), sig_pri_indicate(), sig_pri_moh_fsm_hold(), sig_pri_moh_fsm_hold_req(), sig_pri_moh_fsm_idle(), sig_pri_moh_fsm_moh(), sig_pri_moh_fsm_notify(), sig_pri_moh_fsm_pend_hold(), sig_ss7_indicate(), sip_indicate(), skinny_indicate(), start_moh_exec(), transfer_call_step1(), unistim_indicate(), and wait_moh_exec().

{
   if (ast_moh_start_ptr)
      return ast_moh_start_ptr(chan, mclass, interpclass);

   ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default"));

   return 0;
}
int ast_namedgroups_intersect ( struct ast_namedgroups *  a,
struct ast_namedgroups *  b 
)

Return TRUE if group a and b contain at least one common groupname.

Definition at line 8707 of file channel.c.

References ao2_callback, ao2_cleanup, ao2_container_count(), match(), namedgroup_match(), and SWAP.

Referenced by find_channel_by_group().

{
   void *match;
   struct ao2_container *group_a = (struct ao2_container *) a;
   struct ao2_container *group_b = (struct ao2_container *) b;

   if (!a || !b) {
      return 0;
   }

   /*
    * Do groups a and b intersect?  Since a and b are hash tables,
    * the average time complexity is:
    * O(a.count <= b.count ? a.count : b.count)
    */
   if (ao2_container_count(group_b) < ao2_container_count(group_a)) {
      /* Traverse over the smaller group. */
      SWAP(group_a, group_b);
   }
   match = ao2_callback(group_a, 0, namedgroup_match, group_b);
   ao2_cleanup(match);

   return match != NULL;
}
void ast_party_caller_copy ( struct ast_party_caller dest,
const struct ast_party_caller src 
)

Copy the source caller information to the destination caller.

Since:
1.8
Parameters:
destDestination caller
srcSource caller
Returns:
Nothing

Definition at line 2151 of file channel.c.

References ast_party_caller::ani, ast_party_caller::ani2, ast_party_id_copy(), ast_party_caller::id, and ast_party_caller::priv.

{
   if (dest == src) {
      /* Don't copy to self */
      return;
   }

   ast_party_id_copy(&dest->id, &src->id);
   ast_party_id_copy(&dest->ani, &src->ani);
   ast_party_id_copy(&dest->priv, &src->priv);
   dest->ani2 = src->ani2;
}
void ast_party_caller_free ( struct ast_party_caller doomed)

Destroy the caller party contents.

Since:
1.8
Parameters:
doomedThe caller party to destroy.
Returns:
Nothing

Definition at line 2180 of file channel.c.

References ast_party_caller::ani, ast_party_id_free(), ast_party_caller::id, and ast_party_caller::priv.

Referenced by ast_channel_destructor(), ast_dummy_channel_destructor(), callerid_write(), dial_trunk(), and sla_ring_station().

{
   ast_party_id_free(&doomed->id);
   ast_party_id_free(&doomed->ani);
   ast_party_id_free(&doomed->priv);
}
void ast_party_caller_init ( struct ast_party_caller init)

Initialize the given caller structure.

Since:
1.8
Parameters:
initCaller structure to initialize.
Returns:
Nothing

Definition at line 2143 of file channel.c.

References ast_party_caller::ani, ast_party_caller::ani2, ast_party_id_init(), ast_party_caller::id, and ast_party_caller::priv.

Referenced by __ast_channel_alloc_ap(), dial_trunk(), sig_pri_set_caller_id(), sig_ss7_set_caller_id(), and sla_ring_station().

{
   ast_party_id_init(&init->id);
   ast_party_id_init(&init->ani);
   ast_party_id_init(&init->priv);
   init->ani2 = 0;
}
void ast_party_caller_set ( struct ast_party_caller dest,
const struct ast_party_caller src,
const struct ast_set_party_caller update 
)

Set the caller information based on another caller source.

Since:
1.8

This is similar to ast_party_caller_copy, except that NULL values for strings in the src parameter indicate not to update the corresponding dest values.

Parameters:
destThe caller one wishes to update
srcThe new caller values to update the dest
updateWhat caller information to update. NULL if all.
Returns:
Nada

Definition at line 2172 of file channel.c.

References ast_party_caller::ani, ast_set_party_caller::ani, ast_party_caller::ani2, ast_party_id_set(), ast_party_caller::id, ast_set_party_caller::id, ast_party_caller::priv, and ast_set_party_caller::priv.

Referenced by ast_channel_set_caller(), ast_channel_set_caller_event(), and callerid_write().

{
   ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
   ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
   ast_party_id_set(&dest->priv, &src->priv, update ? &update->priv : NULL);
   dest->ani2 = src->ani2;
}
void ast_party_caller_set_init ( struct ast_party_caller init,
const struct ast_party_caller guide 
)

Initialize the given caller structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initCaller structure to initialize.
guideSource caller to use as a guide in initializing.
Returns:
Nothing

Definition at line 2164 of file channel.c.

References ast_party_caller::ani, ast_party_caller::ani2, ast_party_id_set_init(), ast_party_caller::id, and ast_party_caller::priv.

Referenced by callerid_write(), dial_exec_full(), do_forward(), misdn_update_caller_id(), ring_entry(), and sig_pri_handle_subcmds().

{
   ast_party_id_set_init(&init->id, &guide->id);
   ast_party_id_set_init(&init->ani, &guide->ani);
   ast_party_id_set_init(&init->priv, &guide->priv);
   init->ani2 = guide->ani2;
}
void ast_party_connected_line_collect_caller ( struct ast_party_connected_line connected,
struct ast_party_caller caller 
)

Collect the caller party information into a connected line structure.

Since:
1.8
Parameters:
connectedCollected caller information for the connected line
callerCaller information.
Returns:
Nothing
Warning:
This is a shallow copy.
DO NOT call ast_party_connected_line_free() on the filled in connected line structure!

Definition at line 2228 of file channel.c.

References ast_party_caller::ani, ast_party_connected_line::ani, ast_party_caller::ani2, ast_party_connected_line::ani2, AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN, ast_party_caller::id, ast_party_connected_line::id, ast_party_caller::priv, ast_party_connected_line::priv, and ast_party_connected_line::source.

{
   connected->id = caller->id;
   connected->ani = caller->ani;
   connected->priv = caller->priv;
   connected->ani2 = caller->ani2;
   connected->source = AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN;
}
void ast_party_connected_line_copy ( struct ast_party_connected_line dest,
const struct ast_party_connected_line src 
)

Copy the source connected line information to the destination connected line.

Since:
1.8
Parameters:
destDestination connected line
srcSource connected line
Returns:
Nothing

Definition at line 2196 of file channel.c.

References ast_party_connected_line::ani, ast_party_connected_line::ani2, ast_party_id_copy(), ast_party_connected_line::id, ast_party_connected_line::priv, and ast_party_connected_line::source.

Referenced by __ast_read(), ast_call_forward(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_do_pickup(), builtin_atxfer(), dial_exec_full(), do_forward(), local_attended_transfer(), misdn_attempt_transfer(), party_connected_line_copy_transfer(), try_calling(), and wait_for_answer().

{
   if (dest == src) {
      /* Don't copy to self */
      return;
   }

   ast_party_id_copy(&dest->id, &src->id);
   ast_party_id_copy(&dest->ani, &src->ani);
   ast_party_id_copy(&dest->priv, &src->priv);
   dest->ani2 = src->ani2;
   dest->source = src->source;
}
void ast_party_connected_line_set ( struct ast_party_connected_line dest,
const struct ast_party_connected_line src,
const struct ast_set_party_connected_line update 
)

Set the connected line information based on another connected line source.

Since:
1.8 This is similar to ast_party_connected_line_copy, except that NULL values for strings in the src parameter indicate not to update the corresponding dest values.
Parameters:
destThe connected line one wishes to update
srcThe new connected line values to update the dest
updateWhat connected line information to update. NULL if all.
Returns:
Nothing

Definition at line 2219 of file channel.c.

References ast_party_connected_line::ani, ast_set_party_connected_line::ani, ast_party_connected_line::ani2, ast_party_id_set(), ast_party_connected_line::id, ast_set_party_connected_line::id, ast_party_connected_line::priv, ast_set_party_connected_line::priv, and ast_party_connected_line::source.

Referenced by ast_channel_set_connected_line(), wait_for_answer(), and wait_for_winner().

{
   ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
   ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
   ast_party_id_set(&dest->priv, &src->priv, update ? &update->priv : NULL);
   dest->ani2 = src->ani2;
   dest->source = src->source;
}
void ast_party_connected_line_set_init ( struct ast_party_connected_line init,
const struct ast_party_connected_line guide 
)

Initialize the given connected line structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initConnected line structure to initialize.
guideSource connected line to use as a guide in initializing.
Returns:
Nothing

Definition at line 2210 of file channel.c.

References ast_party_connected_line::ani, ast_party_connected_line::ani2, ast_party_id_set_init(), ast_party_connected_line::id, ast_party_connected_line::priv, and ast_party_connected_line::source.

Referenced by __ast_request_and_dial(), ast_indicate_data(), connectedline_write(), dial_exec_full(), feature_request_and_dial(), wait_for_answer(), and wait_for_winner().

{
   ast_party_id_set_init(&init->id, &guide->id);
   ast_party_id_set_init(&init->ani, &guide->ani);
   ast_party_id_set_init(&init->priv, &guide->priv);
   init->ani2 = guide->ani2;
   init->source = guide->source;
}
void ast_party_dialed_copy ( struct ast_party_dialed dest,
const struct ast_party_dialed src 
)

Copy the source dialed party information to the destination dialed party.

Since:
1.8
Parameters:
destDestination dialed party
srcSource dialed party
Returns:
Nothing

Definition at line 2101 of file channel.c.

References ast_free, ast_party_subaddress_copy(), ast_strdup, ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by local_call().

{
   if (dest == src) {
      /* Don't copy to self */
      return;
   }

   ast_free(dest->number.str);
   dest->number.str = ast_strdup(src->number.str);
   dest->number.plan = src->number.plan;
   ast_party_subaddress_copy(&dest->subaddress, &src->subaddress);
   dest->transit_network_select = src->transit_network_select;
}
void ast_party_dialed_free ( struct ast_party_dialed doomed)

Destroy the dialed party contents.

Since:
1.8
Parameters:
doomedThe dialed party to destroy.
Returns:
Nothing

Definition at line 2136 of file channel.c.

References ast_free, ast_party_subaddress_free(), ast_party_dialed::number, ast_party_dialed::str, and ast_party_dialed::subaddress.

Referenced by ast_channel_destructor(), ast_dummy_channel_destructor(), and callerid_write().

{
   ast_free(doomed->number.str);
   doomed->number.str = NULL;
   ast_party_subaddress_free(&doomed->subaddress);
}
void ast_party_dialed_init ( struct ast_party_dialed init)

Initialize the given dialed structure.

Since:
1.8
Parameters:
initDialed structure to initialize.
Returns:
Nothing

Definition at line 2093 of file channel.c.

References ast_party_subaddress_init(), ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by __ast_channel_alloc_ap().

{
   init->number.str = NULL;
   init->number.plan = 0;/* Unknown */
   ast_party_subaddress_init(&init->subaddress);
   init->transit_network_select = 0;
}
void ast_party_dialed_set ( struct ast_party_dialed dest,
const struct ast_party_dialed src 
)

Set the dialed information based on another dialed source.

Since:
1.8

This is similar to ast_party_dialed_copy, except that NULL values for strings in the src parameter indicate not to update the corresponding dest values.

Parameters:
destThe dialed one wishes to update
srcThe new dialed values to update the dest
Returns:
Nada

Definition at line 2123 of file channel.c.

References ast_free, ast_party_subaddress_set(), ast_strdup, ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by callerid_write().

{
   if (src->number.str && src->number.str != dest->number.str) {
      ast_free(dest->number.str);
      dest->number.str = ast_strdup(src->number.str);
   }
   dest->number.plan = src->number.plan;

   ast_party_subaddress_set(&dest->subaddress, &src->subaddress);

   dest->transit_network_select = src->transit_network_select;
}
void ast_party_dialed_set_init ( struct ast_party_dialed init,
const struct ast_party_dialed guide 
)

Initialize the given dialed structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initCaller structure to initialize.
guideSource dialed to use as a guide in initializing.
Returns:
Nothing

Definition at line 2115 of file channel.c.

References ast_party_subaddress_set_init(), ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by callerid_write().

void ast_party_id_copy ( struct ast_party_id dest,
const struct ast_party_id src 
)

Copy the source party id information to the destination party id.

Since:
1.8
Parameters:
destDestination party id
srcSource party id
Returns:
Nothing

Definition at line 1930 of file channel.c.

References ast_free, ast_party_name_copy(), ast_party_number_copy(), ast_party_subaddress_copy(), ast_strdup, ast_party_id::name, ast_party_id::number, ast_party_id::subaddress, and ast_party_id::tag.

Referenced by ast_connected_line_copy_from_caller(), ast_connected_line_copy_to_caller(), ast_party_caller_copy(), ast_party_connected_line_copy(), ast_party_id_merge_copy(), ast_party_redirecting_copy(), and parkandannounce_exec().

{
   if (dest == src) {
      /* Don't copy to self */
      return;
   }

   ast_party_name_copy(&dest->name, &src->name);
   ast_party_number_copy(&dest->number, &src->number);
   ast_party_subaddress_copy(&dest->subaddress, &src->subaddress);

   ast_free(dest->tag);
   dest->tag = ast_strdup(src->tag);
}
void ast_party_id_invalidate ( struct ast_party_id id)

Invalidate all components of the given party id.

Since:
11.0
Parameters:
idThe party id to invalidate.
Returns:
Nothing

Definition at line 2054 of file channel.c.

Referenced by sig_pri_handle_subcmds().

{
   id->name.valid = 0;
   id->number.valid = 0;
   id->subaddress.valid = 0;
}
struct ast_party_id ast_party_id_merge ( struct ast_party_id base,
struct ast_party_id overlay 
) [read]

Merge a given party id into another given party id.

Since:
11.0

This function will generate an effective party id.

Each party id component of the party id 'base' is overwritten by components of the party id 'overlay' if the overlay component is marked as valid. However the component 'tag' of the base party id remains untouched.

Parameters:
baseThe party id which is merged.
overlayThe party id which is used to merge into.
Returns:
The merged party id as a struct, not as a pointer.
Note:
The merged party id returned is a shallow copy and must not be freed.

Definition at line 2067 of file channel.c.

References ast_party_id::name.

Referenced by ast_channel_connected_effective_id(), ast_channel_redirecting_effective_from(), ast_channel_redirecting_effective_orig(), ast_channel_redirecting_effective_to(), and ast_party_id_merge_copy().

{
   struct ast_party_id merged;

   merged = *base;
   if (overlay->name.valid) {
      merged.name = overlay->name;
   }
   if (overlay->number.valid) {
      merged.number = overlay->number;
   }
   if (overlay->subaddress.valid) {
      merged.subaddress = overlay->subaddress;
   }
   /* Note the actual structure is returned and not a pointer to it! */
   return merged;
}
void ast_party_id_merge_copy ( struct ast_party_id dest,
struct ast_party_id base,
struct ast_party_id overlay 
)

Copy a merge of a given party id into another given party id to a given destination party id.

Since:
11.0

Each party id component of the party id 'base' is overwritten by components of the party id 'overlay' if the 'overlay' component is marked as valid. However the component 'tag' of the 'base' party id remains untouched. The result is copied into the given party id 'dest'.

Note:
The resulting merged party id is a real copy and has to be freed.
Parameters:
destThe resulting merged party id.
baseThe party id which is merged.
overlayThe party id which is used to merge into.
Returns:
Nothing

Definition at line 2085 of file channel.c.

References ast_party_id_copy(), and ast_party_id_merge().

{
   struct ast_party_id merged;

   merged = ast_party_id_merge(base, overlay);
   ast_party_id_copy(dest, &merged);
}
int ast_party_id_presentation ( const struct ast_party_id id)

Determine the overall presentation value for the given party.

Since:
1.8
Parameters:
idParty to determine the overall presentation value.
Returns:
Overall presentation value for the given party.

Definition at line 1986 of file channel.c.

References AST_PRES_ALLOWED, AST_PRES_NUMBER_NOT_AVAILABLE, AST_PRES_NUMBER_TYPE, AST_PRES_RESTRICTED, AST_PRES_RESTRICTION, AST_PRES_UNAVAILABLE, AST_PRES_USER_NUMBER_UNSCREENED, ast_party_id::name, ast_party_id::number, ast_party_name::valid, and ast_party_number::valid.

Referenced by add_rpid(), ast_str_retrieve_variable(), ast_var_channels_table(), callerpres_read(), iax2_call(), initreqprep(), my_set_callerid(), oh323_call(), party_id_build_data(), party_id_read(), redirecting_read(), report_new_callerid(), setup_env(), sig_pri_event_party_id(), sig_pri_handle_subcmds(), sip_call(), and socket_process_helper().

{
   int number_priority;
   int number_value;
   int number_screening;
   int name_priority;
   int name_value;

   /* Determine name presentation priority. */
   if (!id->name.valid) {
      name_value = AST_PRES_UNAVAILABLE;
      name_priority = 3;
   } else {
      name_value = id->name.presentation & AST_PRES_RESTRICTION;
      switch (name_value) {
      case AST_PRES_RESTRICTED:
         name_priority = 0;
         break;
      case AST_PRES_ALLOWED:
         name_priority = 1;
         break;
      case AST_PRES_UNAVAILABLE:
         name_priority = 2;
         break;
      default:
         name_value = AST_PRES_UNAVAILABLE;
         name_priority = 3;
         break;
      }
   }

   /* Determine number presentation priority. */
   if (!id->number.valid) {
      number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
      number_value = AST_PRES_UNAVAILABLE;
      number_priority = 3;
   } else {
      number_screening = id->number.presentation & AST_PRES_NUMBER_TYPE;
      number_value = id->number.presentation & AST_PRES_RESTRICTION;
      switch (number_value) {
      case AST_PRES_RESTRICTED:
         number_priority = 0;
         break;
      case AST_PRES_ALLOWED:
         number_priority = 1;
         break;
      case AST_PRES_UNAVAILABLE:
         number_priority = 2;
         break;
      default:
         number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
         number_value = AST_PRES_UNAVAILABLE;
         number_priority = 3;
         break;
      }
   }

   /* Select the wining presentation value. */
   if (name_priority < number_priority) {
      number_value = name_value;
   }
   if (number_value == AST_PRES_UNAVAILABLE) {
      return AST_PRES_NUMBER_NOT_AVAILABLE;
   }

   return number_value | number_screening;
}
void ast_party_id_reset ( struct ast_party_id id)

Destroy and initialize the given party id structure.

Since:
11.0
Parameters:
idThe party id to reset.
Returns:
Nothing

Definition at line 2061 of file channel.c.

References ast_party_id_free(), and ast_party_id_init().

Referenced by ast_do_masquerade(), ast_do_pickup(), cb_events(), local_attended_transfer(), masquerade_colp_transfer(), misdn_attempt_transfer(), and misdn_facility_ie_handler().

void ast_party_id_set ( struct ast_party_id dest,
const struct ast_party_id src,
const struct ast_set_party_id update 
)

Set the source party id information into the destination party id.

Since:
1.8
Parameters:
destThe id one wishes to update
srcThe new id values to update the dest
updateWhat id information to update. NULL if all.
Returns:
Nothing

Definition at line 1953 of file channel.c.

References ast_free, ast_party_name_set(), ast_party_number_set(), ast_party_subaddress_set(), ast_strdup, ast_party_id::name, ast_set_party_id::name, ast_party_id::number, ast_set_party_id::number, ast_party_id::subaddress, ast_set_party_id::subaddress, and ast_party_id::tag.

Referenced by ast_party_caller_set(), ast_party_connected_line_set(), and ast_party_redirecting_set().

{
   if (dest == src) {
      /* Don't set to self */
      return;
   }

   if (!update || update->name) {
      ast_party_name_set(&dest->name, &src->name);
   }
   if (!update || update->number) {
      ast_party_number_set(&dest->number, &src->number);
   }
   if (!update || update->subaddress) {
      ast_party_subaddress_set(&dest->subaddress, &src->subaddress);
   }

   if (src->tag && src->tag != dest->tag) {
      ast_free(dest->tag);
      dest->tag = ast_strdup(src->tag);
   }
}
void ast_party_id_set_init ( struct ast_party_id init,
const struct ast_party_id guide 
)

Initialize the given party id structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initParty id structure to initialize.
guideSource party id to use as a guide in initializing.
Returns:
Nothing

Definition at line 1945 of file channel.c.

References ast_party_name_set_init(), ast_party_number_set_init(), ast_party_subaddress_set_init(), ast_party_id::name, ast_party_id::number, ast_party_id::subaddress, and ast_party_id::tag.

Referenced by ast_party_caller_set_init(), ast_party_connected_line_set_init(), ast_party_redirecting_set_init(), and dial_exec_full().

{
   ast_party_name_set_init(&init->name, &guide->name);
   ast_party_number_set_init(&init->number, &guide->number);
   ast_party_subaddress_set_init(&init->subaddress, &guide->subaddress);
   init->tag = NULL;
}
void ast_party_name_copy ( struct ast_party_name dest,
const struct ast_party_name src 
)

Copy the source party name information to the destination party name.

Since:
1.8
Parameters:
destDestination party name
srcSource party name
Returns:
Nothing

Definition at line 1764 of file channel.c.

References ast_free, ast_strdup, ast_party_name::char_set, ast_party_name::presentation, ast_party_name::str, and ast_party_name::valid.

Referenced by ast_party_id_copy().

{
   if (dest == src) {
      /* Don't copy to self */
      return;
   }

   ast_free(dest->str);
   dest->str = ast_strdup(src->str);
   dest->char_set = src->char_set;
   dest->presentation = src->presentation;
   dest->valid = src->valid;
}
void ast_party_name_free ( struct ast_party_name doomed)

Destroy the party name contents.

Since:
1.8
Parameters:
doomedThe party name to destroy.
Returns:
Nothing

Definition at line 1803 of file channel.c.

References ast_free, and ast_party_name::str.

Referenced by __analog_ss_thread(), analog_ss_thread(), ast_party_id_free(), and skinny_newcall().

{
   ast_free(doomed->str);
   doomed->str = NULL;
}
void ast_party_name_init ( struct ast_party_name init)

Initialize the given name structure.

Since:
1.8
Parameters:
initName structure to initialize.
Returns:
Nothing

Definition at line 1756 of file channel.c.

References AST_PARTY_CHAR_SET_ISO8859_1, AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, ast_party_name::char_set, ast_party_name::presentation, ast_party_name::str, and ast_party_name::valid.

Referenced by __analog_ss_thread(), analog_ss_thread(), ast_party_id_init(), and skinny_newcall().

void ast_party_name_set ( struct ast_party_name dest,
const struct ast_party_name src 
)

Set the source party name information into the destination party name.

Since:
1.8
Parameters:
destThe name one wishes to update
srcThe new name values to update the dest
Returns:
Nothing

Definition at line 1786 of file channel.c.

References ast_free, ast_strdup, ast_party_name::char_set, ast_party_name::presentation, ast_party_name::str, and ast_party_name::valid.

Referenced by ast_party_id_set().

{
   if (dest == src) {
      /* Don't set to self */
      return;
   }

   if (src->str && src->str != dest->str) {
      ast_free(dest->str);
      dest->str = ast_strdup(src->str);
   }

   dest->char_set = src->char_set;
   dest->presentation = src->presentation;
   dest->valid = src->valid;
}
void ast_party_name_set_init ( struct ast_party_name init,
const struct ast_party_name guide 
)

Initialize the given party name structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initParty name structure to initialize.
guideSource party name to use as a guide in initializing.
Returns:
Nothing

Definition at line 1778 of file channel.c.

References ast_party_name::char_set, ast_party_name::presentation, ast_party_name::str, and ast_party_name::valid.

Referenced by ast_party_id_set_init().

{
   init->str = NULL;
   init->char_set = guide->char_set;
   init->presentation = guide->presentation;
   init->valid = guide->valid;
}
void ast_party_number_copy ( struct ast_party_number dest,
const struct ast_party_number src 
)

Copy the source party number information to the destination party number.

Since:
1.8
Parameters:
destDestination party number
srcSource party number
Returns:
Nothing

Definition at line 1817 of file channel.c.

References ast_free, ast_strdup, ast_party_number::plan, ast_party_number::presentation, ast_party_number::str, and ast_party_number::valid.

Referenced by ast_party_id_copy().

{
   if (dest == src) {
      /* Don't copy to self */
      return;
   }

   ast_free(dest->str);
   dest->str = ast_strdup(src->str);
   dest->plan = src->plan;
   dest->presentation = src->presentation;
   dest->valid = src->valid;
}
void ast_party_number_free ( struct ast_party_number doomed)

Destroy the party number contents.

Since:
1.8
Parameters:
doomedThe party number to destroy.
Returns:
Nothing

Definition at line 1856 of file channel.c.

References ast_free, and ast_party_number::str.

Referenced by __analog_ss_thread(), analog_ss_thread(), ast_party_id_free(), do_forward(), skinny_newcall(), and wait_for_answer().

{
   ast_free(doomed->str);
   doomed->str = NULL;
}
void ast_party_number_init ( struct ast_party_number init)

Initialize the given number structure.

Since:
1.8
Parameters:
initNumber structure to initialize.
Returns:
Nothing

Definition at line 1809 of file channel.c.

References AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, ast_party_number::plan, ast_party_number::presentation, ast_party_number::str, and ast_party_number::valid.

Referenced by __analog_ss_thread(), analog_ss_thread(), ast_party_id_init(), do_forward(), skinny_newcall(), and wait_for_answer().

{
   init->str = NULL;
   init->plan = 0;/* Unknown */
   init->presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
   init->valid = 0;
}
void ast_party_number_set ( struct ast_party_number dest,
const struct ast_party_number src 
)

Set the source party number information into the destination party number.

Since:
1.8
Parameters:
destThe number one wishes to update
srcThe new number values to update the dest
Returns:
Nothing

Definition at line 1839 of file channel.c.

References ast_free, ast_strdup, ast_party_number::plan, ast_party_number::presentation, ast_party_number::str, and ast_party_number::valid.

Referenced by ast_party_id_set().

{
   if (dest == src) {
      /* Don't set to self */
      return;
   }

   if (src->str && src->str != dest->str) {
      ast_free(dest->str);
      dest->str = ast_strdup(src->str);
   }

   dest->plan = src->plan;
   dest->presentation = src->presentation;
   dest->valid = src->valid;
}
void ast_party_number_set_init ( struct ast_party_number init,
const struct ast_party_number guide 
)

Initialize the given party number structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initParty number structure to initialize.
guideSource party number to use as a guide in initializing.
Returns:
Nothing

Definition at line 1831 of file channel.c.

References ast_party_number::plan, ast_party_number::presentation, ast_party_number::str, and ast_party_number::valid.

Referenced by ast_party_id_set_init().

{
   init->str = NULL;
   init->plan = guide->plan;
   init->presentation = guide->presentation;
   init->valid = guide->valid;
}
void ast_party_redirecting_copy ( struct ast_party_redirecting dest,
const struct ast_party_redirecting src 
)
void ast_party_redirecting_set ( struct ast_party_redirecting dest,
const struct ast_party_redirecting src,
const struct ast_set_party_redirecting update 
)

Set the redirecting information based on another redirecting source.

Since:
1.8

This is similar to ast_party_redirecting_copy, except that NULL values for strings in the src parameter indicate not to update the corresponding dest values.

Parameters:
destThe redirecting one wishes to update
srcThe new redirecting values to update the dest
updateWhat redirecting information to update. NULL if all.
Returns:
Nothing

Definition at line 2288 of file channel.c.

References ast_party_id_set(), ast_party_redirecting::count, ast_party_redirecting::from, ast_set_party_redirecting::from, ast_party_redirecting::orig, ast_set_party_redirecting::orig, ast_party_redirecting::orig_reason, ast_party_redirecting::priv_from, ast_set_party_redirecting::priv_from, ast_party_redirecting::priv_orig, ast_set_party_redirecting::priv_orig, ast_party_redirecting::priv_to, ast_set_party_redirecting::priv_to, ast_party_redirecting::reason, ast_party_redirecting::to, and ast_set_party_redirecting::to.

Referenced by ast_channel_set_redirecting().

{
   ast_party_id_set(&dest->orig, &src->orig, update ? &update->orig : NULL);
   ast_party_id_set(&dest->from, &src->from, update ? &update->from : NULL);
   ast_party_id_set(&dest->to, &src->to, update ? &update->to : NULL);
   ast_party_id_set(&dest->priv_orig, &src->priv_orig, update ? &update->priv_orig : NULL);
   ast_party_id_set(&dest->priv_from, &src->priv_from, update ? &update->priv_from : NULL);
   ast_party_id_set(&dest->priv_to, &src->priv_to, update ? &update->priv_to : NULL);
   dest->count = src->count;
   dest->reason = src->reason;
   dest->orig_reason = src->orig_reason;
}
void ast_party_redirecting_set_init ( struct ast_party_redirecting init,
const struct ast_party_redirecting guide 
)

Initialize the given redirecting id structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initRedirecting id structure to initialize.
guideSource redirecting id to use as a guide in initializing.
Returns:
Nothing

Definition at line 2275 of file channel.c.

References ast_party_id_set_init(), ast_party_redirecting::count, ast_party_redirecting::from, ast_party_redirecting::orig, ast_party_redirecting::orig_reason, ast_party_redirecting::priv_from, ast_party_redirecting::priv_orig, ast_party_redirecting::priv_to, ast_party_redirecting::reason, and ast_party_redirecting::to.

Referenced by ast_indicate_data(), misdn_copy_redirecting_to_ast(), redirecting_write(), and sig_pri_redirecting_convert().

{
   ast_party_id_set_init(&init->orig, &guide->orig);
   ast_party_id_set_init(&init->from, &guide->from);
   ast_party_id_set_init(&init->to, &guide->to);
   ast_party_id_set_init(&init->priv_orig, &guide->priv_orig);
   ast_party_id_set_init(&init->priv_from, &guide->priv_from);
   ast_party_id_set_init(&init->priv_to, &guide->priv_to);
   init->count = guide->count;
   init->reason = guide->reason;
   init->orig_reason = guide->orig_reason;
}
void ast_party_subaddress_copy ( struct ast_party_subaddress dest,
const struct ast_party_subaddress src 
)

Copy the source party subaddress information to the destination party subaddress.

Since:
1.8
Parameters:
destDestination party subaddress
srcSource party subaddress
Returns:
Nothing

Definition at line 1870 of file channel.c.

References ast_free, ast_strdup, ast_party_subaddress::odd_even_indicator, ast_party_subaddress::str, ast_party_subaddress::type, and ast_party_subaddress::valid.

Referenced by ast_party_dialed_copy(), and ast_party_id_copy().

{
   if (dest == src) {
      /* Don't copy to self */
      return;
   }

   ast_free(dest->str);
   dest->str = ast_strdup(src->str);
   dest->type = src->type;
   dest->odd_even_indicator = src->odd_even_indicator;
   dest->valid = src->valid;
}

Destroy the party subaddress contents.

Since:
1.8
Parameters:
doomedThe party subaddress to destroy.
Returns:
Nothing

Definition at line 1909 of file channel.c.

References ast_free, and ast_party_subaddress::str.

Referenced by ast_party_dialed_free(), ast_party_id_free(), and pri_dchannel().

{
   ast_free(doomed->str);
   doomed->str = NULL;
}

Initialize the given subaddress structure.

Since:
1.8
Parameters:
initSubaddress structure to initialize.
Returns:
Nothing

Definition at line 1862 of file channel.c.

References ast_party_subaddress::odd_even_indicator, ast_party_subaddress::str, ast_party_subaddress::type, and ast_party_subaddress::valid.

Referenced by ast_party_dialed_init(), ast_party_id_init(), pri_dchannel(), sig_pri_call(), and sig_pri_set_subaddress().

{
   init->str = NULL;
   init->type = 0;
   init->odd_even_indicator = 0;
   init->valid = 0;
}
void ast_party_subaddress_set ( struct ast_party_subaddress dest,
const struct ast_party_subaddress src 
)

Set the source party subaddress information into the destination party subaddress.

Since:
1.8
Parameters:
destThe subaddress one wishes to update
srcThe new subaddress values to update the dest
Returns:
Nothing

Definition at line 1892 of file channel.c.

References ast_free, ast_strdup, ast_party_subaddress::odd_even_indicator, ast_party_subaddress::str, ast_party_subaddress::type, and ast_party_subaddress::valid.

Referenced by ast_party_dialed_set(), and ast_party_id_set().

{
   if (dest == src) {
      /* Don't set to self */
      return;
   }

   if (src->str && src->str != dest->str) {
      ast_free(dest->str);
      dest->str = ast_strdup(src->str);
   }

   dest->type = src->type;
   dest->odd_even_indicator = src->odd_even_indicator;
   dest->valid = src->valid;
}
void ast_party_subaddress_set_init ( struct ast_party_subaddress init,
const struct ast_party_subaddress guide 
)

Initialize the given party subaddress structure using the given guide for a set update operation.

Since:
1.8

The initialization is needed to allow a set operation to know if a value needs to be updated. Simple integers need the guide's original value in case the set operation is not trying to set a new value. String values are simply set to NULL pointers if they are not going to be updated.

Parameters:
initParty subaddress structure to initialize.
guideSource party subaddress to use as a guide in initializing.
Returns:
Nothing

Definition at line 1884 of file channel.c.

References ast_party_subaddress::odd_even_indicator, ast_party_subaddress::str, ast_party_subaddress::type, and ast_party_subaddress::valid.

Referenced by ast_party_dialed_set_init(), and ast_party_id_set_init().

{
   init->str = NULL;
   init->type = guide->type;
   init->odd_even_indicator = guide->odd_even_indicator;
   init->valid = guide->valid;
}
int ast_plc_reload ( void  )

Reload genericplc configuration value from codecs.conf.

Implementation is in main/channel.c

Definition at line 8488 of file channel.c.

References ast_config_destroy(), ast_config_load, AST_OPT_FLAG_GENERIC_PLC, ast_options, ast_set2_flag, ast_true(), ast_variable_browse(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, ast_variable::name, ast_variable::next, ast_variable::value, and var.

Referenced by ast_channels_init().

{
   struct ast_variable *var;
   struct ast_flags config_flags = { 0 };
   struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
   if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID)
      return 0;
   for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
      if (!strcasecmp(var->name, "genericplc")) {
         ast_set2_flag(&ast_options, ast_true(var->value), AST_OPT_FLAG_GENERIC_PLC);
      }
   }
   ast_config_destroy(cfg);
   return 0;
}
void ast_poll_channel_add ( struct ast_channel chan0,
struct ast_channel chan1 
)

Add a channel to an optimized waitfor

Definition at line 2589 of file channel.c.

References ast_channel_epfd(), ast_channel_fd(), ast_channel_fd_isset(), and AST_MAX_FDS.

Referenced by ast_generic_bridge(), begin_dial_channel(), feature_request_and_dial(), local_bridge_loop(), remote_bridge_loop(), and wait_for_answer().

{
#ifdef HAVE_EPOLL
   struct epoll_event ev;
   int i = 0;

   if (ast_channel_epfd(chan0) == -1)
      return;

   /* Iterate through the file descriptors on chan1, adding them to chan0 */
   for (i = 0; i < AST_MAX_FDS; i++) {
      if (!ast_channel_fd_isset(chan1, i)) {
         continue;
      }
      ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
      ev.data.ptr = ast_channel_internal_epfd_data(chan1, i);
      epoll_ctl(ast_channel_epfd(chan0), EPOLL_CTL_ADD, ast_channel_fd(chan1, i), &ev);
   }

#endif
   return;
}
void ast_poll_channel_del ( struct ast_channel chan0,
struct ast_channel chan1 
)

Delete a channel from an optimized waitfor

Definition at line 2613 of file channel.c.

References ast_channel_epfd(), ast_channel_fd(), ast_channel_fd_isset(), and AST_MAX_FDS.

Referenced by ast_generic_bridge(), feature_request_and_dial(), local_bridge_loop(), monitor_dial(), remote_bridge_loop(), and wait_for_answer().

{
#ifdef HAVE_EPOLL
   struct epoll_event ev;
   int i = 0;

   if (ast_channel_epfd(chan0) == -1)
      return;

   for (i = 0; i < AST_MAX_FDS; i++) {
      if (!ast_channel_fd_isset(chan1, i)) {
         continue;
      }
      epoll_ctl(ast_channel_epfd(chan0), EPOLL_CTL_DEL, ast_channel_fd(chan1, i), &ev);
   }

#endif
   return;
}
int ast_pre_call ( struct ast_channel chan,
const char *  sub_args 
)

Execute a Gosub call on the channel before a call is placed.

Since:
11.0

This is called between ast_request() and ast_call() to execute a predial routine on the newly created channel.

Parameters:
chanChannel to execute Gosub.
sub_argsGosub application parameter string.
Note:
Absolutely _NO_ channel locks should be held before calling this function.
Return values:
0on success.
-1on error.

Definition at line 5987 of file channel.c.

References ast_app_exec_sub(), ast_channel_lock, ast_channel_tech(), ast_channel_unlock, chanlist::chan, and ast_channel_tech::pre_call.

Referenced by dial_exec_full(), and findmeexec().

{
   int (*pre_call)(struct ast_channel *chan, const char *sub_args);

   ast_channel_lock(chan);
   pre_call = ast_channel_tech(chan)->pre_call;
   if (pre_call) {
      int res;

      res = pre_call(chan, sub_args);
      ast_channel_unlock(chan);
      return res;
   }
   ast_channel_unlock(chan);
   return ast_app_exec_sub(NULL, chan, sub_args, 0);
}
char* ast_print_group ( char *  buf,
int  buflen,
ast_group_t  group 
)

Print call group and pickup group ---.

Print call and pickup groups into buffer.

Definition at line 8648 of file channel.c.

References first.

Referenced by _sip_show_peer(), _skinny_show_line(), func_channel_read(), function_sippeer(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().

{
   unsigned int i;
   int first = 1;
   char num[3];

   buf[0] = '\0';

   if (!group) /* Return empty string if no group */
      return buf;

   for (i = 0; i <= 63; i++) {   /* Max group is 63 */
      if (group & ((ast_group_t) 1 << i)) {
         if (!first) {
            strncat(buf, ", ", buflen - strlen(buf) - 1);
         } else {
            first = 0;
         }
         snprintf(num, sizeof(num), "%u", i);
         strncat(buf, num, buflen - strlen(buf) - 1);
      }
   }
   return buf;
}
char* ast_print_namedgroups ( struct ast_str **  buf,
struct ast_namedgroups *  group 
)

Print named call groups and named pickup groups.

Definition at line 8673 of file channel.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_str_append(), ast_str_buffer(), first, and namedgroup_member::name.

Referenced by _sip_show_peer(), func_channel_read(), function_sippeer(), misdn_cfg_get_config_string(), print_named_groups(), and read_config().

{
   struct ao2_container *grp = (struct ao2_container *) group;
   struct namedgroup_member *ng;
   int first = 1;
   struct ao2_iterator it;

   if (!grp) {
      return ast_str_buffer(*buf);
   }

   for (it = ao2_iterator_init(grp, 0); (ng = ao2_iterator_next(&it)); ao2_ref(ng, -1)) {
      if (!first) {
         ast_str_append(buf, 0, ", ");
      } else {
         first = 0;
      }
      ast_str_append(buf, 0, "%s", ng->name);
   }
   ao2_iterator_destroy(&it);

   return ast_str_buffer(*buf);
}
int ast_prod ( struct ast_channel chan)

Send empty audio to prime a channel driver.

Definition at line 4828 of file channel.c.

References ast_channel_name(), ast_channel_rawwriteformat(), ast_debug, ast_format_copy(), AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), ast_frame::data, ast_frame_subclass::format, LOG_WARNING, ast_frame::ptr, ast_frame::src, and ast_frame::subclass.

Referenced by ast_activate_generator().

{
   struct ast_frame a = { AST_FRAME_VOICE };
   char nothing[128];

   /* Send an empty audio frame to get things moving */
   if (ast_channel_state(chan) != AST_STATE_UP) {
      ast_debug(1, "Prodding channel '%s'\n", ast_channel_name(chan));
      ast_format_copy(&a.subclass.format, ast_channel_rawwriteformat(chan));
      a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
      a.src = "ast_prod"; /* this better match check in ast_write */
      if (ast_write(chan, &a))
         ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", ast_channel_name(chan));
   }
   return 0;
}
int ast_queue_control_data ( struct ast_channel chan,
enum ast_control_frame_type  control,
const void *  data,
size_t  datalen 
)

Queue a control frame with payload.

Parameters:
chanchannel to queue frame onto
controltype of control frame
datapointer to payload data to be included in frame
datalennumber of bytes of payload data
Return values:
0success
non-zerofailure

The supplied payload data is copied into the frame, so the caller's copy is not modified nor freed, and the resulting frame will retain a copy of the data even if the caller frees their local copy.

Note:
This method should be treated as a 'network transport'; in other words, your frames may be transferred across an IAX2 channel to another system, which may be a different endianness than yours. Because of this, you should ensure that either your frames will never be expected to work across systems, or that you always put your payload data into 'network byte order' before calling this function.
The channel does not need to be locked before calling this function.

Definition at line 1431 of file channel.c.

References AST_FRAME_CONTROL, and ast_queue_frame().

Referenced by __analog_handle_event(), analog_hangup(), ast_channel_queue_connected_line_update(), ast_channel_queue_redirecting_update(), change_t38_state(), dahdi_handle_event(), dahdi_hangup(), dahdi_r2_on_call_disconnect(), fax_gateway_indicate_t38(), handle_incoming(), handle_request_notify(), handle_response_refer(), iax2_queue_control_data(), iax2_transfer(), interpret_t38_parameters(), jingle_action_session_terminate(), local_attended_transfer(), masquerade_colp_transfer(), pri_queue_pvt_cause_data(), process_sdp(), setsubstate(), sig_pri_aoc_d_from_pri(), sig_pri_aoc_e_from_pri(), sig_pri_aoc_s_from_pri(), sig_pri_send_aoce_termination_request(), sip_sipredirect(), socket_process_helper(), ss7_queue_pvt_cause_data(), sub_hold(), and sub_unhold().

{
   struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control, .data.ptr = (void *) data, .datalen = datalen };
   return ast_queue_frame(chan, &f);
}
int ast_queue_frame ( struct ast_channel chan,
struct ast_frame f 
)

Queue one or more frames to a channel's frame queue.

Parameters:
chanthe channel to queue the frame(s) on
fthe frame(s) to queue. Note that the frame(s) will be duplicated by this function. It is the responsibility of the caller to handle freeing the memory associated with the frame(s) being passed if necessary.
Return values:
0success
non-zerofailure

Definition at line 1351 of file channel.c.

References __ast_queue_frame().

Referenced by __ast_channel_masquerade(), __ast_read(), __oh323_rtp_create(), __oh323_update_info(), action_atxfer(), agent_request(), alsa_call(), ast_channel_setwhentohangup_tv(), ast_do_masquerade(), ast_dsp_process(), ast_queue_cc_frame(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), bridge_write(), cb_events(), cli_console_dial(), cli_console_sendtext(), conf_stop_record(), console_dial(), console_do_answer(), console_flash(), console_sendtext(), dahdi_queue_frame(), dahdi_read(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), jingle_handle_dtmf(), keypad_digit(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), pri_queue_frame(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), sig_pri_dial_complete(), sig_pri_handle_subcmds(), sig_ss7_queue_frame(), stream_monitor(), t38_tx_packet_handler(), unistim_do_senddigit(), unistim_senddigit_end(), and wakeup_sub().

{
   return __ast_queue_frame(chan, fin, 0, NULL);
}
int ast_queue_frame_head ( struct ast_channel chan,
struct ast_frame f 
)

Queue one or more frames to the head of a channel's frame queue.

Parameters:
chanthe channel to queue the frame(s) on
fthe frame(s) to queue. Note that the frame(s) will be duplicated by this function. It is the responsibility of the caller to handle freeing the memory associated with the frame(s) being passed if necessary.
Return values:
0success
non-zerofailure

Definition at line 1356 of file channel.c.

References __ast_queue_frame().

Referenced by __ast_answer(), __ast_read(), ast_autoservice_stop(), ast_safe_sleep_conditional(), and feature_request_and_dial().

{
   return __ast_queue_frame(chan, fin, 1, NULL);
}
int ast_queue_hangup ( struct ast_channel chan)

Queue a hangup frame for channel.

Queue a hangup frame.

Definition at line 1362 of file channel.c.

References ast_channel_lock, ast_channel_name(), ast_channel_softhangup_internal_flag_add(), ast_channel_uniqueid(), ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, EVENT_FLAG_CALL, and manager_event.

Referenced by cleanup_connection(), cli_console_hangup(), close_call(), gtalk_hangup_farend(), gtalk_is_answered(), handle_request_bye(), iax2_destroy(), iax2_queue_hangup(), jingle_hangup_farend(), local_fixup(), local_hangup(), mgcp_queue_hangup(), setsubstate(), and sip_queue_hangup_cause().

{
   struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
   int res;

   /* Yeah, let's not change a lock-critical value without locking */
   ast_channel_lock(chan);
   ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a hangup is requested with no set cause.</synopsis>
      </managerEventInstance>
   ***/
   manager_event(EVENT_FLAG_CALL, "HangupRequest",
      "Channel: %s\r\n"
      "Uniqueid: %s\r\n",
      ast_channel_name(chan),
      ast_channel_uniqueid(chan));

   res = ast_queue_frame(chan, &f);
   ast_channel_unlock(chan);
   return res;
}
int ast_queue_hangup_with_cause ( struct ast_channel chan,
int  cause 
)

Queue a hangup frame for channel.

Queue a hangup frame with hangupcause set.

Definition at line 1387 of file channel.c.

References ast_channel_hangupcause(), ast_channel_lock, ast_channel_name(), ast_channel_softhangup_internal_flag_add(), ast_channel_uniqueid(), ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, ast_frame::data, EVENT_FLAG_CALL, manager_event, and ast_frame::uint32.

Referenced by __analog_handle_event(), __oh323_update_info(), __sip_autodestruct(), close_call(), close_client(), console_hangup(), dahdi_handle_event(), dahdi_r2_on_call_disconnect(), discard_call(), handle_call_outgoing(), handle_request_bye(), handle_response(), handle_response_invite(), hangup_chan(), hangup_connection(), jingle_action_session_terminate(), jingle_queue_hangup_with_cause(), misdn_answer(), retrans_pkt(), sip_queue_hangup_cause(), and transfer_cancel_step2().

{
   struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
   int res;

   if (cause >= 0) {
      f.data.uint32 = cause;
   }

   /* Yeah, let's not change a lock-critical value without locking */
   ast_channel_lock(chan);
   ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
   if (cause < 0) {
      f.data.uint32 = ast_channel_hangupcause(chan);
   }
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a hangup is requested with a specific cause code.</synopsis>
            <syntax>
               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
            </syntax>
      </managerEventInstance>
   ***/
   manager_event(EVENT_FLAG_CALL, "HangupRequest",
      "Channel: %s\r\n"
      "Uniqueid: %s\r\n"
      "Cause: %d\r\n",
      ast_channel_name(chan),
      ast_channel_uniqueid(chan),
      cause);

   res = ast_queue_frame(chan, &f);
   ast_channel_unlock(chan);
   return res;
}
int ast_raw_answer ( struct ast_channel chan,
int  cdr_answer 
)

Answer a channel.

Parameters:
chanchannel to answer
cdr_answerflag to control whether any associated CDR should be marked as 'answered'

This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.
Unlike ast_answer(), this function will not wait for media flow to begin. The caller should be careful before sending media to the channel before incoming media arrives, as the outgoing media may be lost.
Return values:
0on success
non-zeroon failure

Definition at line 2897 of file channel.c.

References ast_channel_tech::answer, ast_cdr_answer(), AST_CEL_ANSWER, ast_cel_report_event(), ast_channel_cdr(), ast_channel_flags(), ast_channel_lock, ast_channel_tech(), ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_indicate(), ast_setstate(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, and ast_test_flag.

Referenced by __ast_answer(), and ast_bridge_call().

{
   int res = 0;

   ast_channel_lock(chan);

   /* You can't answer an outbound call */
   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING)) {
      ast_channel_unlock(chan);
      return 0;
   }

   /* Stop if we're a zombie or need a soft hangup */
   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
      ast_channel_unlock(chan);
      return -1;
   }

   ast_channel_unlock(chan);

   switch (ast_channel_state(chan)) {
   case AST_STATE_RINGING:
   case AST_STATE_RING:
      ast_channel_lock(chan);
      if (ast_channel_tech(chan)->answer) {
         res = ast_channel_tech(chan)->answer(chan);
      }
      ast_setstate(chan, AST_STATE_UP);
      if (cdr_answer) {
         ast_cdr_answer(ast_channel_cdr(chan));
      }
      ast_cel_report_event(chan, AST_CEL_ANSWER, NULL, NULL, NULL);
      ast_channel_unlock(chan);
      break;
   case AST_STATE_UP:
      ast_cel_report_event(chan, AST_CEL_ANSWER, NULL, NULL, NULL);
      /* Calling ast_cdr_answer when it it has previously been called
       * is essentially a no-op, so it is safe.
       */
      if (cdr_answer) {
         ast_cdr_answer(ast_channel_cdr(chan));
      }
      break;
   default:
      break;
   }

   ast_indicate(chan, -1);

   return res;
}
struct ast_frame* ast_read ( struct ast_channel chan) [read]

Reads a frame.

Parameters:
chanchannel to read a frame from
Returns:
Returns a frame, or NULL on error. If it returns NULL, you best just stop reading frames and assume the channel has been disconnected.

Definition at line 4386 of file channel.c.

References __ast_read().

Referenced by __adsi_transmit_messages(), __analog_ss_thread(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), analog_ss_thread(), ast_bridge_handle_trip(), ast_generic_bridge(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), async_agi_read_frame(), async_wait(), autoservice_run(), background_detect_exec(), channel_spy(), conf_flush(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_bridge(), dial_exec_full(), dictate_exec(), disa_exec(), disable_t38(), do_idle_thread(), do_waiting(), echo_exec(), eivr_comm(), feature_request_and_dial(), find_cache(), generic_fax_exec(), handle_recordfile(), handle_speechrecognize(), iax2_bridge(), ices_exec(), isAnsweringMachine(), jack_exec(), local_bridge_loop(), manage_parked_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), receivefax_t38_init(), record_exec(), recordthread(), remote_bridge_loop(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendfax_t38_init(), sendurl_exec(), speech_background(), transmit_audio(), transmit_t38(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().

{
   return __ast_read(chan, 0);
}
static void ast_read_generator_actions ( struct ast_channel chan,
struct ast_frame f 
) [static]

Definition at line 3747 of file channel.c.

References ast_channel_generator(), ast_channel_generatordata(), ast_channel_generatordata_set(), ast_channel_lock, ast_channel_timingfd(), ast_channel_timingfunc(), ast_channel_unlock, ast_channel_writeformat(), ast_deactivate_generator(), ast_debug, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_rate(), AST_FRAME_CNG, ast_internal_timing_enabled(), ast_settimeout(), chanlist::chan, ast_frame::datalen, ast_frame_subclass::format, ast_frame::frametype, ast_generator::generate, generator_force(), ast_frame::samples, and ast_frame::subclass.

Referenced by __ast_read().

{
   if (ast_channel_generator(chan) && ast_channel_generator(chan)->generate && ast_channel_generatordata(chan) &&  !ast_internal_timing_enabled(chan)) {
      void *tmp = ast_channel_generatordata(chan);
      int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = ast_channel_generator(chan)->generate;
      int res;
      int samples;

      if (ast_channel_timingfunc(chan)) {
         ast_debug(1, "Generator got voice, switching to phase locked mode\n");
         ast_settimeout(chan, 0, NULL, NULL);
      }

      ast_channel_generatordata_set(chan, NULL);     /* reset, to let writes go through */

      if (ast_format_cmp(&f->subclass.format, ast_channel_writeformat(chan)) == AST_FORMAT_CMP_NOT_EQUAL) {
         float factor;
         factor = ((float) ast_format_rate(ast_channel_writeformat(chan))) / ((float) ast_format_rate(&f->subclass.format));
         samples = (int) ( ((float) f->samples) * factor );
      } else {
         samples = f->samples;
      }

      /* This unlock is here based on two assumptions that hold true at this point in the
       * code. 1) this function is only called from within __ast_read() and 2) all generators
       * call ast_write() in their generate callback.
       *
       * The reason this is added is so that when ast_write is called, the lock that occurs
       * there will not recursively lock the channel. Doing this will cause intended deadlock
       * avoidance not to work in deeper functions
       */
      ast_channel_unlock(chan);
      res = generate(chan, tmp, f->datalen, samples);
      ast_channel_lock(chan);
      ast_channel_generatordata_set(chan, tmp);
      if (res) {
         ast_debug(1, "Auto-deactivating generator\n");
         ast_deactivate_generator(chan);
      }

   } else if (f->frametype == AST_FRAME_CNG) {
      if (ast_channel_generator(chan) && !ast_channel_timingfunc(chan) && (ast_channel_timingfd(chan) > -1)) {
         ast_debug(1, "Generator got CNG, switching to timed mode\n");
         ast_settimeout(chan, 50, generator_force, chan);
      }
   }
}
struct ast_frame* ast_read_noaudio ( struct ast_channel chan) [read]

Reads a frame, returning AST_FRAME_NULL frame if audio.

Parameters:
chanchannel to read a frame from
Returns:
Returns a frame, or NULL on error. If it returns NULL, you best just stop reading frames and assume the channel has been disconnected.
Note:
Audio is replaced with AST_FRAME_NULL to avoid transcode when the resulting audio is not necessary.

Definition at line 4391 of file channel.c.

References __ast_read().

Referenced by ast_bridge_handle_trip(), and conf_run().

{
   return __ast_read(chan, 1);
}
int ast_readstring ( struct ast_channel c,
char *  s,
int  len,
int  timeout,
int  rtimeout,
char *  enders 
)

Reads multiple digits.

Parameters:
cchannel to read from
sstring to read in to. Must be at least the size of your length
lenhow many digits to read (maximum)
timeouthow long to timeout between digits
rtimeouttimeout to wait on the first digit
endersdigits to end the string

Read in a digit string "s", max length "len", maximum timeout between digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout for the first digit.

Returns:
Returns 0 on normal return, or 1 on a timeout. In the case of a timeout, any digits that were read before the timeout will still be available in s. RETURNS 2 in full version when ctrlfd is available, NOT 1

Definition at line 6080 of file channel.c.

References ast_readstring_full().

Referenced by __adsi_transmit_messages(), adsi_begin_download(), adsi_get_cpeinfo(), adsi_load_session(), app_exec(), ast_app_getdata(), dialout(), do_directory(), forward_message(), privacy_exec(), vm_authenticate(), vm_newuser(), and vm_options().

{
   return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
}
int ast_readstring_full ( struct ast_channel c,
char *  s,
int  len,
int  timeout,
int  ftimeout,
char *  enders,
int  audiofd,
int  ctrlfd 
)

Definition at line 6085 of file channel.c.

References ast_channel_flags(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_stream(), ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, AST_GETDATA_COMPLETE, AST_GETDATA_EMPTY_END_TERMINATED, AST_GETDATA_FAILED, AST_GETDATA_INTERRUPTED, AST_GETDATA_TIMEOUT, ast_opt_transmit_silence, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), and ast_waitstream_full().

Referenced by ast_app_getdata_full(), and ast_readstring().

{
   int pos = 0;   /* index in the buffer where we accumulate digits */
   int to = ftimeout;

   struct ast_silence_generator *silgen = NULL;

   /* Stop if we're a zombie or need a soft hangup */
   if (ast_test_flag(ast_channel_flags(c), AST_FLAG_ZOMBIE) || ast_check_hangup(c))
      return -1;
   if (!len)
      return -1;
   for (;;) {
      int d;
      if (ast_channel_stream(c)) {
         d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
         ast_stopstream(c);
         if (!silgen && ast_opt_transmit_silence)
            silgen = ast_channel_start_silence_generator(c);
         usleep(1000);
         if (!d)
            d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
      } else {
         if (!silgen && ast_opt_transmit_silence)
            silgen = ast_channel_start_silence_generator(c);
         d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
      }
      if (d < 0) {
         ast_channel_stop_silence_generator(c, silgen);
         return AST_GETDATA_FAILED;
      }
      if (d == 0) {
         s[pos] = '\0';
         ast_channel_stop_silence_generator(c, silgen);
         return AST_GETDATA_TIMEOUT;
      }
      if (d == 1) {
         s[pos] = '\0';
         ast_channel_stop_silence_generator(c, silgen);
         return AST_GETDATA_INTERRUPTED;
      }
      if (strchr(enders, d) && (pos == 0)) {
         s[pos] = '\0';
         ast_channel_stop_silence_generator(c, silgen);
         return AST_GETDATA_EMPTY_END_TERMINATED;
      }
      if (!strchr(enders, d)) {
         s[pos++] = d;
      }
      if (strchr(enders, d) || (pos >= len)) {
         s[pos] = '\0';
         ast_channel_stop_silence_generator(c, silgen);
         return AST_GETDATA_COMPLETE;
      }
      to = timeout;
   }
   /* Never reached */
   return 0;
}
int ast_recvchar ( struct ast_channel chan,
int  timeout 
)

Receives a text character from a channel.

Parameters:
chanchannel to act upon
timeouttimeout in milliseconds (0 for infinite wait)

Read a char of text from a channel

Returns:
0 on success, -1 on failure

Definition at line 4666 of file channel.c.

References ast_free, and ast_recvtext().

Referenced by handle_recvchar().

{
   int c;
   char *buf = ast_recvtext(chan, timeout);
   if (buf == NULL)
      return -1;  /* error or timeout */
   c = *(unsigned char *)buf;
   ast_free(buf);
   return c;
}
char* ast_recvtext ( struct ast_channel chan,
int  timeout 
)

Receives a text string from a channel Read a string of text from a channel.

Parameters:
chanchannel to act upon
timeouttimeout in milliseconds (0 for infinite wait)
Returns:
the received text, or NULL to signify failure.

Definition at line 4677 of file channel.c.

References ast_check_hangup(), AST_CONTROL_HANGUP, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_frfree, ast_read(), ast_remaining_ms(), ast_strndup, ast_tvnow(), ast_waitfor(), ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::ptr, and ast_frame::subclass.

Referenced by ast_recvchar(), and handle_recvtext().

{
   int res;
   char *buf = NULL;
   struct timeval start = ast_tvnow();
   int ms;

   while ((ms = ast_remaining_ms(start, timeout))) {
      struct ast_frame *f;

      if (ast_check_hangup(chan)) {
         break;
      }
      res = ast_waitfor(chan, ms);
      if (res <= 0)  {/* timeout or error */
         break;
      }
      f = ast_read(chan);
      if (f == NULL) {
         break; /* no frame */
      }
      if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_HANGUP) {
         ast_frfree(f);
         break;
      } else if (f->frametype == AST_FRAME_TEXT) {    /* what we want */
         buf = ast_strndup((char *) f->data.ptr, f->datalen);  /* dup and break */
         ast_frfree(f);
         break;
      }
      ast_frfree(f);
   }
   return buf;
}
int ast_redirecting_build_data ( unsigned char *  data,
size_t  datalen,
const struct ast_party_redirecting redirecting,
const struct ast_set_party_redirecting update 
)

Build the redirecting id data frame.

Since:
1.8
Parameters:
dataBuffer to fill with the frame data
datalenSize of the buffer to fill
redirectingRedirecting id information
updateWhat redirecting information to build. NULL if all.
Return values:
-1if error
Amountof data buffer used

Definition at line 9849 of file channel.c.

References ast_log(), AST_REDIRECTING_COUNT, AST_REDIRECTING_FROM_ID_PRESENTATION, AST_REDIRECTING_FROM_NAME, AST_REDIRECTING_FROM_NAME_CHAR_SET, AST_REDIRECTING_FROM_NAME_PRESENTATION, AST_REDIRECTING_FROM_NAME_VALID, AST_REDIRECTING_FROM_NUMBER, AST_REDIRECTING_FROM_NUMBER_PLAN, AST_REDIRECTING_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_FROM_NUMBER_VALID, AST_REDIRECTING_FROM_SUBADDRESS, AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_FROM_SUBADDRESS_TYPE, AST_REDIRECTING_FROM_SUBADDRESS_VALID, AST_REDIRECTING_FROM_TAG, AST_REDIRECTING_ORIG_NAME, AST_REDIRECTING_ORIG_NAME_CHAR_SET, AST_REDIRECTING_ORIG_NAME_PRESENTATION, AST_REDIRECTING_ORIG_NAME_VALID, AST_REDIRECTING_ORIG_NUMBER, AST_REDIRECTING_ORIG_NUMBER_PLAN, AST_REDIRECTING_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_ORIG_NUMBER_VALID, AST_REDIRECTING_ORIG_REASON, AST_REDIRECTING_ORIG_SUBADDRESS, AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_ORIG_TAG, AST_REDIRECTING_PRIV_FROM_NAME, AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET, AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION, AST_REDIRECTING_PRIV_FROM_NAME_VALID, AST_REDIRECTING_PRIV_FROM_NUMBER, AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN, AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_FROM_NUMBER_VALID, AST_REDIRECTING_PRIV_FROM_SUBADDRESS, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_FROM_TAG, AST_REDIRECTING_PRIV_ORIG_NAME, AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET, AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_NAME_VALID, AST_REDIRECTING_PRIV_ORIG_NUMBER, AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN, AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_ORIG_TAG, AST_REDIRECTING_PRIV_TO_NAME, AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET, AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION, AST_REDIRECTING_PRIV_TO_NAME_VALID, AST_REDIRECTING_PRIV_TO_NUMBER, AST_REDIRECTING_PRIV_TO_NUMBER_PLAN, AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_TO_NUMBER_VALID, AST_REDIRECTING_PRIV_TO_SUBADDRESS, AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_TO_TAG, AST_REDIRECTING_TO_ID_PRESENTATION, AST_REDIRECTING_TO_NAME, AST_REDIRECTING_TO_NAME_CHAR_SET, AST_REDIRECTING_TO_NAME_PRESENTATION, AST_REDIRECTING_TO_NAME_VALID, AST_REDIRECTING_TO_NUMBER, AST_REDIRECTING_TO_NUMBER_PLAN, AST_REDIRECTING_TO_NUMBER_PRESENTATION, AST_REDIRECTING_TO_NUMBER_VALID, AST_REDIRECTING_TO_SUBADDRESS, AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_TO_SUBADDRESS_TYPE, AST_REDIRECTING_TO_SUBADDRESS_VALID, AST_REDIRECTING_TO_TAG, AST_REDIRECTING_VERSION, ast_party_redirecting::count, ast_party_redirecting::from, ast_set_party_redirecting::from, LOG_WARNING, ast_party_id_ies::name, ast_party_redirecting::orig, ast_set_party_redirecting::orig, ast_party_redirecting::orig_reason, party_id_build_data(), ast_party_redirecting::priv_from, ast_set_party_redirecting::priv_from, ast_party_redirecting::priv_orig, ast_set_party_redirecting::priv_orig, ast_party_redirecting::priv_to, ast_set_party_redirecting::priv_to, ast_party_redirecting::reason, ast_party_name_ies::str, ast_party_redirecting::to, ast_set_party_redirecting::to, and value.

Referenced by ast_channel_queue_redirecting_update(), ast_channel_update_redirecting(), and local_indicate().

{
   int32_t value;
   size_t pos = 0;
   int res;

   static const struct ast_party_id_ies orig_ies = {
      .name.str = AST_REDIRECTING_ORIG_NAME,
      .name.char_set = AST_REDIRECTING_ORIG_NAME_CHAR_SET,
      .name.presentation = AST_REDIRECTING_ORIG_NAME_PRESENTATION,
      .name.valid = AST_REDIRECTING_ORIG_NAME_VALID,

      .number.str = AST_REDIRECTING_ORIG_NUMBER,
      .number.plan = AST_REDIRECTING_ORIG_NUMBER_PLAN,
      .number.presentation = AST_REDIRECTING_ORIG_NUMBER_PRESENTATION,
      .number.valid = AST_REDIRECTING_ORIG_NUMBER_VALID,

      .subaddress.str = AST_REDIRECTING_ORIG_SUBADDRESS,
      .subaddress.type = AST_REDIRECTING_ORIG_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_REDIRECTING_ORIG_SUBADDRESS_VALID,

      .tag = AST_REDIRECTING_ORIG_TAG,
      .combined_presentation = 0,/* Not sent. */
   };
   static const struct ast_party_id_ies from_ies = {
      .name.str = AST_REDIRECTING_FROM_NAME,
      .name.char_set = AST_REDIRECTING_FROM_NAME_CHAR_SET,
      .name.presentation = AST_REDIRECTING_FROM_NAME_PRESENTATION,
      .name.valid = AST_REDIRECTING_FROM_NAME_VALID,

      .number.str = AST_REDIRECTING_FROM_NUMBER,
      .number.plan = AST_REDIRECTING_FROM_NUMBER_PLAN,
      .number.presentation = AST_REDIRECTING_FROM_NUMBER_PRESENTATION,
      .number.valid = AST_REDIRECTING_FROM_NUMBER_VALID,

      .subaddress.str = AST_REDIRECTING_FROM_SUBADDRESS,
      .subaddress.type = AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_REDIRECTING_FROM_SUBADDRESS_VALID,

      .tag = AST_REDIRECTING_FROM_TAG,
      .combined_presentation = AST_REDIRECTING_FROM_ID_PRESENTATION,
   };
   static const struct ast_party_id_ies to_ies = {
      .name.str = AST_REDIRECTING_TO_NAME,
      .name.char_set = AST_REDIRECTING_TO_NAME_CHAR_SET,
      .name.presentation = AST_REDIRECTING_TO_NAME_PRESENTATION,
      .name.valid = AST_REDIRECTING_TO_NAME_VALID,

      .number.str = AST_REDIRECTING_TO_NUMBER,
      .number.plan = AST_REDIRECTING_TO_NUMBER_PLAN,
      .number.presentation = AST_REDIRECTING_TO_NUMBER_PRESENTATION,
      .number.valid = AST_REDIRECTING_TO_NUMBER_VALID,

      .subaddress.str = AST_REDIRECTING_TO_SUBADDRESS,
      .subaddress.type = AST_REDIRECTING_TO_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_REDIRECTING_TO_SUBADDRESS_VALID,

      .tag = AST_REDIRECTING_TO_TAG,
      .combined_presentation = AST_REDIRECTING_TO_ID_PRESENTATION,
   };
   static const struct ast_party_id_ies priv_orig_ies = {
      .name.str = AST_REDIRECTING_PRIV_ORIG_NAME,
      .name.char_set = AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET,
      .name.presentation = AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION,
      .name.valid = AST_REDIRECTING_PRIV_ORIG_NAME_VALID,

      .number.str = AST_REDIRECTING_PRIV_ORIG_NUMBER,
      .number.plan = AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN,
      .number.presentation = AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION,
      .number.valid = AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID,

      .subaddress.str = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS,
      .subaddress.type = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID,

      .tag = AST_REDIRECTING_PRIV_ORIG_TAG,
      .combined_presentation = 0,/* Not sent. */
   };
   static const struct ast_party_id_ies priv_from_ies = {
      .name.str = AST_REDIRECTING_PRIV_FROM_NAME,
      .name.char_set = AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET,
      .name.presentation = AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION,
      .name.valid = AST_REDIRECTING_PRIV_FROM_NAME_VALID,

      .number.str = AST_REDIRECTING_PRIV_FROM_NUMBER,
      .number.plan = AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN,
      .number.presentation = AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION,
      .number.valid = AST_REDIRECTING_PRIV_FROM_NUMBER_VALID,

      .subaddress.str = AST_REDIRECTING_PRIV_FROM_SUBADDRESS,
      .subaddress.type = AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID,

      .tag = AST_REDIRECTING_PRIV_FROM_TAG,
      .combined_presentation = 0,/* Not sent. */
   };
   static const struct ast_party_id_ies priv_to_ies = {
      .name.str = AST_REDIRECTING_PRIV_TO_NAME,
      .name.char_set = AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET,
      .name.presentation = AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION,
      .name.valid = AST_REDIRECTING_PRIV_TO_NAME_VALID,

      .number.str = AST_REDIRECTING_PRIV_TO_NUMBER,
      .number.plan = AST_REDIRECTING_PRIV_TO_NUMBER_PLAN,
      .number.presentation = AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION,
      .number.valid = AST_REDIRECTING_PRIV_TO_NUMBER_VALID,

      .subaddress.str = AST_REDIRECTING_PRIV_TO_SUBADDRESS,
      .subaddress.type = AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE,
      .subaddress.odd_even_indicator = AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN,
      .subaddress.valid = AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID,

      .tag = AST_REDIRECTING_PRIV_TO_TAG,
      .combined_presentation = 0,/* Not sent. */
   };

   /* Redirecting frame version */
   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for redirecting frame version\n");
      return -1;
   }
   data[pos++] = AST_REDIRECTING_VERSION;
   data[pos++] = 1;
   data[pos++] = 2;/* Version 1 did not have a version ie */

   res = party_id_build_data(data + pos, datalen - pos, &redirecting->orig,
      "redirecting-orig", &orig_ies, update ? &update->orig : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   res = party_id_build_data(data + pos, datalen - pos, &redirecting->from,
      "redirecting-from", &from_ies, update ? &update->from : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   res = party_id_build_data(data + pos, datalen - pos, &redirecting->to,
      "redirecting-to", &to_ies, update ? &update->to : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_orig,
      "redirecting-priv-orig", &priv_orig_ies, update ? &update->priv_orig : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_from,
      "redirecting-priv-from", &priv_from_ies, update ? &update->priv_from : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   res = party_id_build_data(data + pos, datalen - pos, &redirecting->priv_to,
      "redirecting-priv-to", &priv_to_ies, update ? &update->priv_to : NULL);
   if (res < 0) {
      return -1;
   }
   pos += res;

   /* Redirecting reason */
   if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
      ast_log(LOG_WARNING, "No space left for redirecting reason\n");
      return -1;
   }
   data[pos++] = AST_REDIRECTING_REASON;
   data[pos++] = sizeof(value);
   value = htonl(redirecting->reason);
   memcpy(data + pos, &value, sizeof(value));
   pos += sizeof(value);

   /* Redirecting original reason */
   if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
      ast_log(LOG_WARNING, "No space left for redirecting original reason\n");
      return -1;
   }
   data[pos++] = AST_REDIRECTING_ORIG_REASON;
   data[pos++] = sizeof(value);
   value = htonl(redirecting->orig_reason);
   memcpy(data + pos, &value, sizeof(value));
   pos += sizeof(value);

   /* Redirecting count */
   if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
      ast_log(LOG_WARNING, "No space left for redirecting count\n");
      return -1;
   }
   data[pos++] = AST_REDIRECTING_COUNT;
   data[pos++] = sizeof(value);
   value = htonl(redirecting->count);
   memcpy(data + pos, &value, sizeof(value));
   pos += sizeof(value);

   return pos;
}
int ast_redirecting_parse_data ( const unsigned char *  data,
size_t  datalen,
struct ast_party_redirecting redirecting 
)

Parse redirecting indication frame data.

Since:
1.8
Parameters:
dataBuffer with the frame data to parse
datalenSize of the buffer
redirectingExtracted redirecting id information
Return values:
0on success.
-1on error.
Note:
The filled in id structure needs to be initialized by ast_party_redirecting_set_init() before calling.
The filled in id structure needs to be destroyed by ast_party_redirecting_free() when it is no longer needed.

Definition at line 10057 of file channel.c.

References ast_debug, ast_free, ast_log(), ast_malloc, AST_PARTY_CHAR_SET_ISO8859_1, AST_REDIRECTING_COUNT, AST_REDIRECTING_FROM_ID_PRESENTATION, AST_REDIRECTING_FROM_NAME, AST_REDIRECTING_FROM_NAME_CHAR_SET, AST_REDIRECTING_FROM_NAME_PRESENTATION, AST_REDIRECTING_FROM_NAME_VALID, AST_REDIRECTING_FROM_NUMBER, AST_REDIRECTING_FROM_NUMBER_PLAN, AST_REDIRECTING_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_FROM_NUMBER_VALID, AST_REDIRECTING_FROM_SUBADDRESS, AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_FROM_SUBADDRESS_TYPE, AST_REDIRECTING_FROM_SUBADDRESS_VALID, AST_REDIRECTING_FROM_TAG, AST_REDIRECTING_ORIG_NAME, AST_REDIRECTING_ORIG_NAME_CHAR_SET, AST_REDIRECTING_ORIG_NAME_PRESENTATION, AST_REDIRECTING_ORIG_NAME_VALID, AST_REDIRECTING_ORIG_NUMBER, AST_REDIRECTING_ORIG_NUMBER_PLAN, AST_REDIRECTING_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_ORIG_NUMBER_VALID, AST_REDIRECTING_ORIG_REASON, AST_REDIRECTING_ORIG_SUBADDRESS, AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_ORIG_TAG, AST_REDIRECTING_PRIV_FROM_NAME, AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET, AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION, AST_REDIRECTING_PRIV_FROM_NAME_VALID, AST_REDIRECTING_PRIV_FROM_NUMBER, AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN, AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_FROM_NUMBER_VALID, AST_REDIRECTING_PRIV_FROM_SUBADDRESS, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_FROM_TAG, AST_REDIRECTING_PRIV_ORIG_NAME, AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET, AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_NAME_VALID, AST_REDIRECTING_PRIV_ORIG_NUMBER, AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN, AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_ORIG_TAG, AST_REDIRECTING_PRIV_TO_NAME, AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET, AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION, AST_REDIRECTING_PRIV_TO_NAME_VALID, AST_REDIRECTING_PRIV_TO_NUMBER, AST_REDIRECTING_PRIV_TO_NUMBER_PLAN, AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION, AST_REDIRECTING_PRIV_TO_NUMBER_VALID, AST_REDIRECTING_PRIV_TO_SUBADDRESS, AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE, AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID, AST_REDIRECTING_PRIV_TO_TAG, AST_REDIRECTING_TO_ID_PRESENTATION, AST_REDIRECTING_TO_NAME, AST_REDIRECTING_TO_NAME_CHAR_SET, AST_REDIRECTING_TO_NAME_PRESENTATION, AST_REDIRECTING_TO_NAME_VALID, AST_REDIRECTING_TO_NUMBER, AST_REDIRECTING_TO_NUMBER_PLAN, AST_REDIRECTING_TO_NUMBER_PRESENTATION, AST_REDIRECTING_TO_NUMBER_VALID, AST_REDIRECTING_TO_SUBADDRESS, AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN, AST_REDIRECTING_TO_SUBADDRESS_TYPE, AST_REDIRECTING_TO_SUBADDRESS_VALID, AST_REDIRECTING_TO_TAG, AST_REDIRECTING_VERSION, ast_party_name::char_set, ast_party_redirecting::count, ast_party_redirecting::from, LOG_WARNING, ast_party_id::name, ast_party_id::number, ast_party_subaddress::odd_even_indicator, ast_party_redirecting::orig, ast_party_redirecting::orig_reason, ast_party_number::plan, ast_party_name::presentation, ast_party_number::presentation, ast_party_redirecting::priv_from, ast_party_redirecting::priv_orig, ast_party_redirecting::priv_to, ast_party_redirecting::reason, ast_party_name::str, ast_party_number::str, ast_party_subaddress::str, ast_party_id::subaddress, ast_party_id::tag, ast_party_redirecting::to, ast_party_subaddress::type, ast_party_name::valid, ast_party_number::valid, ast_party_subaddress::valid, and value.

Referenced by ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), and ast_indicate_data().

{
   size_t pos;
   unsigned char ie_len;
   unsigned char ie_id;
   int32_t value;
   int frame_version = 1;
   int from_combined_presentation = 0;
   int got_from_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
   int to_combined_presentation = 0;
   int got_to_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */

   for (pos = 0; pos < datalen; pos += ie_len) {
      if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
         ast_log(LOG_WARNING, "Invalid redirecting update\n");
         return -1;
      }
      ie_id = data[pos++];
      ie_len = data[pos++];
      if (datalen < pos + ie_len) {
         ast_log(LOG_WARNING, "Invalid redirecting update\n");
         return -1;
      }

      switch (ie_id) {
/* Redirecting frame version */
      case AST_REDIRECTING_VERSION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting frame version (%u)\n",
               (unsigned) ie_len);
            break;
         }
         frame_version = data[pos];
         break;
/* Redirecting-orig party id name */
      case AST_REDIRECTING_ORIG_NAME:
         ast_free(redirecting->orig.name.str);
         redirecting->orig.name.str = ast_malloc(ie_len + 1);
         if (redirecting->orig.name.str) {
            memcpy(redirecting->orig.name.str, data + pos, ie_len);
            redirecting->orig.name.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_ORIG_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.name.char_set = data[pos];
         break;
      case AST_REDIRECTING_ORIG_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.name.presentation = data[pos];
         break;
      case AST_REDIRECTING_ORIG_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.name.valid = data[pos];
         break;
/* Redirecting-orig party id number */
      case AST_REDIRECTING_ORIG_NUMBER:
         ast_free(redirecting->orig.number.str);
         redirecting->orig.number.str = ast_malloc(ie_len + 1);
         if (redirecting->orig.number.str) {
            memcpy(redirecting->orig.number.str, data + pos, ie_len);
            redirecting->orig.number.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_ORIG_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.number.plan = data[pos];
         break;
      case AST_REDIRECTING_ORIG_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.number.presentation = data[pos];
         break;
      case AST_REDIRECTING_ORIG_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.number.valid = data[pos];
         break;
/* Redirecting-orig party id subaddress */
      case AST_REDIRECTING_ORIG_SUBADDRESS:
         ast_free(redirecting->orig.subaddress.str);
         redirecting->orig.subaddress.str = ast_malloc(ie_len + 1);
         if (redirecting->orig.subaddress.str) {
            memcpy(redirecting->orig.subaddress.str, data + pos, ie_len);
            redirecting->orig.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_ORIG_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.subaddress.type = data[pos];
         break;
      case AST_REDIRECTING_ORIG_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid redirecting-orig subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_REDIRECTING_ORIG_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-orig subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->orig.subaddress.valid = data[pos];
         break;
/* Redirecting-orig party id tag */
      case AST_REDIRECTING_ORIG_TAG:
         ast_free(redirecting->orig.tag);
         redirecting->orig.tag = ast_malloc(ie_len + 1);
         if (redirecting->orig.tag) {
            memcpy(redirecting->orig.tag, data + pos, ie_len);
            redirecting->orig.tag[ie_len] = 0;
         }
         break;
/* Redirecting-from party id name */
      case AST_REDIRECTING_FROM_NAME:
         ast_free(redirecting->from.name.str);
         redirecting->from.name.str = ast_malloc(ie_len + 1);
         if (redirecting->from.name.str) {
            memcpy(redirecting->from.name.str, data + pos, ie_len);
            redirecting->from.name.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_FROM_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.name.char_set = data[pos];
         break;
      case AST_REDIRECTING_FROM_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.name.presentation = data[pos];
         break;
      case AST_REDIRECTING_FROM_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.name.valid = data[pos];
         break;
/* Redirecting-from party id number */
      case AST_REDIRECTING_FROM_NUMBER:
         ast_free(redirecting->from.number.str);
         redirecting->from.number.str = ast_malloc(ie_len + 1);
         if (redirecting->from.number.str) {
            memcpy(redirecting->from.number.str, data + pos, ie_len);
            redirecting->from.number.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_FROM_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.number.plan = data[pos];
         break;
      case AST_REDIRECTING_FROM_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.number.presentation = data[pos];
         break;
      case AST_REDIRECTING_FROM_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.number.valid = data[pos];
         break;
/* Redirecting-from party id combined presentation */
      case AST_REDIRECTING_FROM_ID_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from combined presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         from_combined_presentation = data[pos];
         got_from_combined_presentation = 1;
         break;
/* Redirecting-from party id subaddress */
      case AST_REDIRECTING_FROM_SUBADDRESS:
         ast_free(redirecting->from.subaddress.str);
         redirecting->from.subaddress.str = ast_malloc(ie_len + 1);
         if (redirecting->from.subaddress.str) {
            memcpy(redirecting->from.subaddress.str, data + pos, ie_len);
            redirecting->from.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_FROM_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.subaddress.type = data[pos];
         break;
      case AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid redirecting-from subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_REDIRECTING_FROM_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-from subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->from.subaddress.valid = data[pos];
         break;
/* Redirecting-from party id tag */
      case AST_REDIRECTING_FROM_TAG:
         ast_free(redirecting->from.tag);
         redirecting->from.tag = ast_malloc(ie_len + 1);
         if (redirecting->from.tag) {
            memcpy(redirecting->from.tag, data + pos, ie_len);
            redirecting->from.tag[ie_len] = 0;
         }
         break;
/* Redirecting-to party id name */
      case AST_REDIRECTING_TO_NAME:
         ast_free(redirecting->to.name.str);
         redirecting->to.name.str = ast_malloc(ie_len + 1);
         if (redirecting->to.name.str) {
            memcpy(redirecting->to.name.str, data + pos, ie_len);
            redirecting->to.name.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_TO_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.name.char_set = data[pos];
         break;
      case AST_REDIRECTING_TO_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.name.presentation = data[pos];
         break;
      case AST_REDIRECTING_TO_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.name.valid = data[pos];
         break;
/* Redirecting-to party id number */
      case AST_REDIRECTING_TO_NUMBER:
         ast_free(redirecting->to.number.str);
         redirecting->to.number.str = ast_malloc(ie_len + 1);
         if (redirecting->to.number.str) {
            memcpy(redirecting->to.number.str, data + pos, ie_len);
            redirecting->to.number.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_TO_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.number.plan = data[pos];
         break;
      case AST_REDIRECTING_TO_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.number.presentation = data[pos];
         break;
      case AST_REDIRECTING_TO_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.number.valid = data[pos];
         break;
/* Redirecting-to party id combined presentation */
      case AST_REDIRECTING_TO_ID_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to combined presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         to_combined_presentation = data[pos];
         got_to_combined_presentation = 1;
         break;
/* Redirecting-to party id subaddress */
      case AST_REDIRECTING_TO_SUBADDRESS:
         ast_free(redirecting->to.subaddress.str);
         redirecting->to.subaddress.str = ast_malloc(ie_len + 1);
         if (redirecting->to.subaddress.str) {
            memcpy(redirecting->to.subaddress.str, data + pos, ie_len);
            redirecting->to.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_TO_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.subaddress.type = data[pos];
         break;
      case AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid redirecting-to subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_REDIRECTING_TO_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid redirecting-to subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->to.subaddress.valid = data[pos];
         break;
/* Redirecting-to party id tag */
      case AST_REDIRECTING_TO_TAG:
         ast_free(redirecting->to.tag);
         redirecting->to.tag = ast_malloc(ie_len + 1);
         if (redirecting->to.tag) {
            memcpy(redirecting->to.tag, data + pos, ie_len);
            redirecting->to.tag[ie_len] = 0;
         }
         break;
/* Private redirecting-orig party id name */
      case AST_REDIRECTING_PRIV_ORIG_NAME:
         ast_free(redirecting->priv_orig.name.str);
         redirecting->priv_orig.name.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_orig.name.str) {
            memcpy(redirecting->priv_orig.name.str, data + pos, ie_len);
            redirecting->priv_orig.name.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_ORIG_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.name.char_set = data[pos];
         break;
      case AST_REDIRECTING_PRIV_ORIG_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.name.presentation = data[pos];
         break;
      case AST_REDIRECTING_PRIV_ORIG_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.name.valid = data[pos];
         break;
/* Private redirecting-orig party id number */
      case AST_REDIRECTING_PRIV_ORIG_NUMBER:
         ast_free(redirecting->priv_orig.number.str);
         redirecting->priv_orig.number.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_orig.number.str) {
            memcpy(redirecting->priv_orig.number.str, data + pos, ie_len);
            redirecting->priv_orig.number.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_ORIG_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.number.plan = data[pos];
         break;
      case AST_REDIRECTING_PRIV_ORIG_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.number.presentation = data[pos];
         break;
      case AST_REDIRECTING_PRIV_ORIG_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.number.valid = data[pos];
         break;
/* Private redirecting-orig party id subaddress */
      case AST_REDIRECTING_PRIV_ORIG_SUBADDRESS:
         ast_free(redirecting->priv_orig.subaddress.str);
         redirecting->priv_orig.subaddress.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_orig.subaddress.str) {
            memcpy(redirecting->priv_orig.subaddress.str, data + pos, ie_len);
            redirecting->priv_orig.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.subaddress.type = data[pos];
         break;
      case AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid private redirecting-orig subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_REDIRECTING_PRIV_ORIG_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-orig subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_orig.subaddress.valid = data[pos];
         break;
/* Private redirecting-orig party id tag */
      case AST_REDIRECTING_PRIV_ORIG_TAG:
         ast_free(redirecting->priv_orig.tag);
         redirecting->priv_orig.tag = ast_malloc(ie_len + 1);
         if (redirecting->priv_orig.tag) {
            memcpy(redirecting->priv_orig.tag, data + pos, ie_len);
            redirecting->priv_orig.tag[ie_len] = 0;
         }
         break;
/* Private redirecting-from party id name */
      case AST_REDIRECTING_PRIV_FROM_NAME:
         ast_free(redirecting->priv_from.name.str);
         redirecting->priv_from.name.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_from.name.str) {
            memcpy(redirecting->priv_from.name.str, data + pos, ie_len);
            redirecting->priv_from.name.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_FROM_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.name.char_set = data[pos];
         break;
      case AST_REDIRECTING_PRIV_FROM_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.name.presentation = data[pos];
         break;
      case AST_REDIRECTING_PRIV_FROM_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.name.valid = data[pos];
         break;
/* Private redirecting-from party id number */
      case AST_REDIRECTING_PRIV_FROM_NUMBER:
         ast_free(redirecting->priv_from.number.str);
         redirecting->priv_from.number.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_from.number.str) {
            memcpy(redirecting->priv_from.number.str, data + pos, ie_len);
            redirecting->priv_from.number.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_FROM_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.number.plan = data[pos];
         break;
      case AST_REDIRECTING_PRIV_FROM_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.number.presentation = data[pos];
         break;
      case AST_REDIRECTING_PRIV_FROM_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.number.valid = data[pos];
         break;
/* Private redirecting-from party id subaddress */
      case AST_REDIRECTING_PRIV_FROM_SUBADDRESS:
         ast_free(redirecting->priv_from.subaddress.str);
         redirecting->priv_from.subaddress.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_from.subaddress.str) {
            memcpy(redirecting->priv_from.subaddress.str, data + pos, ie_len);
            redirecting->priv_from.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_FROM_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.subaddress.type = data[pos];
         break;
      case AST_REDIRECTING_PRIV_FROM_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid private redirecting-from subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_REDIRECTING_PRIV_FROM_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-from subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_from.subaddress.valid = data[pos];
         break;
/* Private redirecting-from party id tag */
      case AST_REDIRECTING_PRIV_FROM_TAG:
         ast_free(redirecting->priv_from.tag);
         redirecting->priv_from.tag = ast_malloc(ie_len + 1);
         if (redirecting->priv_from.tag) {
            memcpy(redirecting->priv_from.tag, data + pos, ie_len);
            redirecting->priv_from.tag[ie_len] = 0;
         }
         break;
/* Private redirecting-to party id name */
      case AST_REDIRECTING_PRIV_TO_NAME:
         ast_free(redirecting->priv_to.name.str);
         redirecting->priv_to.name.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_to.name.str) {
            memcpy(redirecting->priv_to.name.str, data + pos, ie_len);
            redirecting->priv_to.name.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_TO_NAME_CHAR_SET:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to name char set (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.name.char_set = data[pos];
         break;
      case AST_REDIRECTING_PRIV_TO_NAME_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to name presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.name.presentation = data[pos];
         break;
      case AST_REDIRECTING_PRIV_TO_NAME_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to name valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.name.valid = data[pos];
         break;
/* Private redirecting-to party id number */
      case AST_REDIRECTING_PRIV_TO_NUMBER:
         ast_free(redirecting->priv_to.number.str);
         redirecting->priv_to.number.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_to.number.str) {
            memcpy(redirecting->priv_to.number.str, data + pos, ie_len);
            redirecting->priv_to.number.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_TO_NUMBER_PLAN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to numbering plan (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.number.plan = data[pos];
         break;
      case AST_REDIRECTING_PRIV_TO_NUMBER_PRESENTATION:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to number presentation (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.number.presentation = data[pos];
         break;
      case AST_REDIRECTING_PRIV_TO_NUMBER_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to number valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.number.valid = data[pos];
         break;
/* Private redirecting-to party id subaddress */
      case AST_REDIRECTING_PRIV_TO_SUBADDRESS:
         ast_free(redirecting->priv_to.subaddress.str);
         redirecting->priv_to.subaddress.str = ast_malloc(ie_len + 1);
         if (redirecting->priv_to.subaddress.str) {
            memcpy(redirecting->priv_to.subaddress.str, data + pos, ie_len);
            redirecting->priv_to.subaddress.str[ie_len] = 0;
         }
         break;
      case AST_REDIRECTING_PRIV_TO_SUBADDRESS_TYPE:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to type of subaddress (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.subaddress.type = data[pos];
         break;
      case AST_REDIRECTING_PRIV_TO_SUBADDRESS_ODD_EVEN:
         if (ie_len != 1) {
            ast_log(LOG_WARNING,
               "Invalid private redirecting-to subaddress odd-even indicator (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.subaddress.odd_even_indicator = data[pos];
         break;
      case AST_REDIRECTING_PRIV_TO_SUBADDRESS_VALID:
         if (ie_len != 1) {
            ast_log(LOG_WARNING, "Invalid private redirecting-to subaddress valid (%u)\n",
               (unsigned) ie_len);
            break;
         }
         redirecting->priv_to.subaddress.valid = data[pos];
         break;
/* Private redirecting-to party id tag */
      case AST_REDIRECTING_PRIV_TO_TAG:
         ast_free(redirecting->priv_to.tag);
         redirecting->priv_to.tag = ast_malloc(ie_len + 1);
         if (redirecting->priv_to.tag) {
            memcpy(redirecting->priv_to.tag, data + pos, ie_len);
            redirecting->priv_to.tag[ie_len] = 0;
         }
         break;
/* Redirecting reason */
      case AST_REDIRECTING_REASON:
         if (ie_len != sizeof(value)) {
            ast_log(LOG_WARNING, "Invalid redirecting reason (%u)\n",
               (unsigned) ie_len);
            break;
         }
         memcpy(&value, data + pos, sizeof(value));
         redirecting->reason = ntohl(value);
         break;
/* Redirecting orig-reason */
      case AST_REDIRECTING_ORIG_REASON:
         if (ie_len != sizeof(value)) {
            ast_log(LOG_WARNING, "Invalid redirecting original reason (%u)\n",
               (unsigned) ie_len);
            break;
         }
         memcpy(&value, data + pos, sizeof(value));
         redirecting->orig_reason = ntohl(value);
         break;
/* Redirecting count */
      case AST_REDIRECTING_COUNT:
         if (ie_len != sizeof(value)) {
            ast_log(LOG_WARNING, "Invalid redirecting count (%u)\n",
               (unsigned) ie_len);
            break;
         }
         memcpy(&value, data + pos, sizeof(value));
         redirecting->count = ntohl(value);
         break;
/* Redirecting unknown element */
      default:
         ast_debug(1, "Unknown redirecting element: %u (%u)\n",
            (unsigned) ie_id, (unsigned) ie_len);
         break;
      }
   }

   switch (frame_version) {
   case 1:
      /*
       * The other end is an earlier version that we need to adjust
       * for compatibility.
       *
       * The earlier version did not have the orig party id or
       * orig_reason value.
       */
      redirecting->from.name.valid = 1;
      redirecting->from.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
      redirecting->from.number.valid = 1;
      if (got_from_combined_presentation) {
         redirecting->from.name.presentation = from_combined_presentation;
         redirecting->from.number.presentation = from_combined_presentation;
      }

      redirecting->to.name.valid = 1;
      redirecting->to.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
      redirecting->to.number.valid = 1;
      if (got_to_combined_presentation) {
         redirecting->to.name.presentation = to_combined_presentation;
         redirecting->to.number.presentation = to_combined_presentation;
      }
      break;
   case 2:
      /* The other end is at the same level as we are. */
      break;
   default:
      /*
       * The other end is newer than we are.
       * We need to assume that they are compatible with us.
       */
      ast_debug(1, "Redirecting frame has newer version: %u\n",
         (unsigned) frame_version);
      break;
   }

   return 0;
}
struct ast_namedgroups* ast_ref_namedgroups ( struct ast_namedgroups *  groups) [read]
struct ast_channel* ast_request ( const char *  type,
struct ast_format_cap request_cap,
const struct ast_channel requestor,
const char *  addr,
int *  cause 
) [read]

Requests a channel.

Parameters:
typetype of channel to request
request_capFormat capabilities for requested channel
requestorchannel asking for data
addrdestination of the call
causeCause of failure

Request a channel of a given type, with addr as optional information used by the low level module

Return values:
NULLfailure
non-NULLchannel on success

Definition at line 5896 of file channel.c.

References ast_callid_unref, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, ast_channel_callid(), ast_channel_callid_set(), ast_channel_release(), ast_format_cap_add(), ast_format_cap_destroy(), ast_format_cap_dup(), ast_format_cap_get_type(), ast_format_cap_remove_bytype(), ast_format_clear(), AST_FORMAT_TYPE_AUDIO, ast_getformatname_multiple(), ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_translator_best_choice(), chanlist::chan, LOG_WARNING, set_security_requirements(), and chanlist::tech.

Referenced by __ast_request_and_dial(), alloc_playback_chan(), ast_call_forward(), begin_dial_channel(), build_conf(), chanavail_exec(), conf_run(), conf_start_record(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), meetme_menu_admin_extended(), ring_entry(), and wait_for_answer().

{
   struct chanlist *chan;
   struct ast_channel *c;
   int res;
   int foo;

   if (!cause)
      cause = &foo;
   *cause = AST_CAUSE_NOTDEFINED;

   if (AST_RWLIST_RDLOCK(&backends)) {
      ast_log(LOG_WARNING, "Unable to lock technology backend list\n");
      return NULL;
   }

   AST_RWLIST_TRAVERSE(&backends, chan, list) {
      struct ast_format_cap *tmp_cap;
      struct ast_format tmp_fmt;
      struct ast_format best_audio_fmt;
      struct ast_format_cap *joint_cap;

      if (strcasecmp(type, chan->tech->type))
         continue;

      ast_format_clear(&best_audio_fmt);
      /* find the best audio format to use */
      if ((tmp_cap = ast_format_cap_get_type(request_cap, AST_FORMAT_TYPE_AUDIO))) {
         /* We have audio - is it possible to connect the various calls to each other?
            (Avoid this check for calls without audio, like text+video calls)
         */
         res = ast_translator_best_choice(tmp_cap, chan->tech->capabilities, &tmp_fmt, &best_audio_fmt);
         ast_format_cap_destroy(tmp_cap);
         if (res < 0) {
            char tmp1[256], tmp2[256];
            ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %s) to %s\n", type,
               ast_getformatname_multiple(tmp1, sizeof(tmp1), chan->tech->capabilities),
               ast_getformatname_multiple(tmp2, sizeof(tmp2), request_cap));
            *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
            AST_RWLIST_UNLOCK(&backends);
            return NULL;
         }
      }
      AST_RWLIST_UNLOCK(&backends);
      if (!chan->tech->requester)
         return NULL;

      /* XXX Only the audio format calculated as being the best for translation
       * purposes is used for the request. This needs to be re-evaluated.  It may be
       * a better choice to send all the audio formats capable of being translated
       * during the request and allow the channel drivers to pick the best one. */
      if (!(joint_cap = ast_format_cap_dup(request_cap))) {
         return NULL;
      }
      ast_format_cap_remove_bytype(joint_cap, AST_FORMAT_TYPE_AUDIO);
      ast_format_cap_add(joint_cap, &best_audio_fmt);

      if (!(c = chan->tech->requester(type, joint_cap, requestor, addr, cause))) {
         ast_format_cap_destroy(joint_cap);
         return NULL;
      }

      /* Set newly created channel callid to same as the requestor */
      if (requestor) {
         struct ast_callid *callid = ast_channel_callid(requestor);
         if (callid) {
            ast_channel_callid_set(c, callid);
            callid = ast_callid_unref(callid);
         }
      }

      joint_cap = ast_format_cap_destroy(joint_cap);

      if (set_security_requirements(requestor, c)) {
         ast_log(LOG_WARNING, "Setting security requirements failed\n");
         c = ast_channel_release(c);
         *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
         return NULL;
      }

      /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
      return c;
   }

   ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
   *cause = AST_CAUSE_NOSUCHDRIVER;
   AST_RWLIST_UNLOCK(&backends);

   return NULL;
}
struct ast_channel* ast_request_and_dial ( const char *  type,
struct ast_format_cap cap,
const struct ast_channel requestor,
const char *  addr,
int  timeout,
int *  reason,
const char *  cid_num,
const char *  cid_name 
) [read]

Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.

Parameters:
typetype of channel to request
formatcapabilities for requested channel
requestorchannel asking for data
addrdestination of the call
timeoutmaximum amount of time to wait for an answer
reasonwhy unsuccessful (if unsuccessful)
cid_numCaller-ID Number
cid_nameCaller-ID Name (ascii)
Returns:
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 5851 of file channel.c.

References __ast_request_and_dial().

Referenced by ast_pbx_outgoing_exten(), and generic_recall().

{
   return __ast_request_and_dial(type, cap, requestor, addr, timeout, outstate, cidnum, cidname, NULL);
}
int ast_safe_sleep_conditional ( struct ast_channel chan,
int  timeout_ms,
int(*)(void *)  cond,
void *  data 
)

Wait, look for hangups and condition arg.

Wait for a specified amount of time, looking for hangups and a condition argument.

Definition at line 1673 of file channel.c.

References ast_channel_generatordata(), ast_channel_lock, ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_unlock, ast_frfree, ast_frisolate(), ast_is_deferrable_frame(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_opt_transmit_silence, ast_queue_frame_head(), ast_read(), ast_remaining_ms(), ast_tvnow(), ast_waitfor(), cond, and f.

Referenced by ast_safe_sleep(), and login_exec().

{
   struct ast_frame *f;
   struct ast_silence_generator *silgen = NULL;
   int res = 0;
   struct timeval start;
   int ms;
   AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;

   AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);

   /* If no other generator is present, start silencegen while waiting */
   if (ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
      silgen = ast_channel_start_silence_generator(chan);
   }

   start = ast_tvnow();
   while ((ms = ast_remaining_ms(start, timeout_ms))) {
      struct ast_frame *dup_f = NULL;

      if (cond && ((*cond)(data) == 0)) {
         break;
      }
      ms = ast_waitfor(chan, ms);
      if (ms < 0) {
         res = -1;
         break;
      }
      if (ms > 0) {
         f = ast_read(chan);
         if (!f) {
            res = -1;
            break;
         }

         if (!ast_is_deferrable_frame(f)) {
            ast_frfree(f);
            continue;
         }

         if ((dup_f = ast_frisolate(f))) {
            if (dup_f != f) {
               ast_frfree(f);
            }
            AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
         }
      }
   }

   /* stop silgen if present */
   if (silgen) {
      ast_channel_stop_silence_generator(chan, silgen);
   }

   /* We need to free all the deferred frames, but we only need to
    * queue the deferred frames if there was no error and no
    * hangup was received
    */
   ast_channel_lock(chan);
   while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
      if (!res) {
         ast_queue_frame_head(chan, f);
      }
      ast_frfree(f);
   }
   ast_channel_unlock(chan);

   return res;
}
int ast_say_character_str ( struct ast_channel chan,
const char *  str,
const char *  ints,
const char *  lang 
)

function to pronounce character and phonetic strings

Definition at line 8896 of file channel.c.

References ast_say_character_str_full.

Referenced by common_exec(), pbx_builtin_saycharacters(), play_mailbox_owner(), and vmsayname_exec().

{
   return ast_say_character_str_full(chan, str, ints, lang, -1, -1);
}
int ast_say_digit_str ( struct ast_channel chan,
const char *  num,
const char *  ints,
const char *  lang 
)

says digits of a string

Parameters:
chanchannel to act upon
numstring to speak
intswhich dtmf to interrupt on
langlanguage to speak in

Vocally says the digits of a given string

Return values:
0on succes
DTMFif interrupted
-1on failure

Definition at line 8890 of file channel.c.

References ast_say_digit_str_full.

Referenced by __analog_ss_thread(), forward_message(), invent_message(), mgcp_ss(), pbx_builtin_saydigits(), and play_message_callerid().

{
   return ast_say_digit_str_full(chan, str, ints, lang, -1, -1);
}
int ast_say_digits ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang 
)

says digits

Parameters:
chanchannel to act upon
numnumber to speak
intswhich dtmf to interrupt on
langlanguage to speak

Vocally says digits of a given number

Return values:
0on success
DTMFif interrupted
-1on failure

Definition at line 8884 of file channel.c.

References ast_say_digits_full().

Referenced by common_exec(), conf_exec(), conf_run(), park_call_full(), and parkandannounce_exec().

{
   return ast_say_digits_full(chan, num, ints, lang, -1, -1);
}
int ast_say_enumeration ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang,
const char *  options 
)

says an enumeration

Parameters:
chanchannel to say them enumeration on
numnumber to say on the channel
intswhich dtmf to interrupt on
langlanguage to speak the enumeration
optionsset to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural

Vocally says an enumeration on a given channel (first, sencond, third, forth, thirtyfirst, hundredth, ....) Especially useful for dates and messages. Says 'last' if num equals to INT_MAX

Return values:
0on success
DTMFdigit on interrupt
-1on failure

Definition at line 8878 of file channel.c.

References ast_say_enumeration_full.

Referenced by ast_say_date_da(), ast_say_date_de(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), ast_say_date_with_format_pl(), and ast_say_date_with_format_vi().

{
   return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1);
}
int ast_say_number ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang,
const char *  options 
)

says a number

Parameters:
chanchannel to say them number on
numnumber to say on the channel
intswhich dtmf to interrupt on
langlanguage to speak the number
optionsset to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural

Vocally says a number on a given channel

Return values:
0on success
DTMFdigit on interrupt
-1on failure

Definition at line 8872 of file channel.c.

References ast_say_number_full.

Referenced by announce_user_count(), app_exec(), ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_hu(), ast_say_date_ka(), ast_say_date_nl(), ast_say_date_pt(), ast_say_date_th(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), ast_say_date_with_format_es(), ast_say_date_with_format_fr(), ast_say_date_with_format_it(), ast_say_date_with_format_nl(), ast_say_date_with_format_pl(), ast_say_date_with_format_pt(), ast_say_date_with_format_th(), ast_say_date_with_format_vi(), ast_say_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_he(), ast_say_datetime_from_now_ka(), ast_say_datetime_from_now_pt(), ast_say_datetime_he(), ast_say_datetime_pt(), ast_say_datetime_th(), ast_say_datetime_zh(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_gr(), ast_say_time_hu(), ast_say_time_ka(), ast_say_time_nl(), ast_say_time_pt(), ast_say_time_pt_BR(), ast_say_time_th(), ast_say_time_zh(), bridge_playfile(), conf_run(), count_exec(), dictate_exec(), get_folder(), gr_say_number_female(), meetme_menu_admin_extended(), pbx_builtin_saynumber(), play_message(), play_message_duration(), play_sound_helper(), say_and_wait(), say_position(), try_calling(), vm_intro_gr(), vm_intro_he(), vm_intro_multilang(), vm_intro_pt(), and vm_intro_pt_BR().

{
   return ast_say_number_full(chan, num, ints, language, options, -1, -1);
}
int ast_say_phonetic_str ( struct ast_channel chan,
const char *  str,
const char *  ints,
const char *  lang 
)

Definition at line 8902 of file channel.c.

References ast_say_phonetic_str_full.

Referenced by pbx_builtin_sayphonetic().

{
   return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1);
}
int ast_senddigit ( struct ast_channel chan,
char  digit,
unsigned int  duration 
)

Send a DTMF digit to a channel.

Parameters:
chanchannel to act upon
digitthe DTMF digit to send, encoded in ASCII
durationthe duration of the digit ending in ms
Returns:
0 on success, -1 on failure

Definition at line 4818 of file channel.c.

References ast_channel_tech(), AST_DEFAULT_EMULATE_DTMF_DURATION, ast_safe_sleep(), ast_senddigit_begin(), and ast_senddigit_end().

Referenced by ast_dtmf_stream(), dial_exec_full(), and manager_play_dtmf().

{
   if (ast_channel_tech(chan)->send_digit_begin) {
      ast_senddigit_begin(chan, digit);
      ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
   }

   return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
}
int ast_senddigit_begin ( struct ast_channel chan,
char  digit 
)

Send a DTMF digit to a channel.

Parameters:
chanchannel to act upon
digitthe DTMF digit to send, encoded in ASCII
Returns:
0 on success, -1 on failure

Definition at line 4749 of file channel.c.

References ast_channel_lock, ast_channel_name(), ast_channel_sending_dtmf_digit_set(), ast_channel_sending_dtmf_tv_set(), ast_channel_tech(), ast_channel_unlock, ast_debug, ast_playtones_start(), and ast_tvnow().

Referenced by agent_digit_begin(), ast_senddigit(), and ast_write().

{
   /* Device does not support DTMF tones, lets fake
    * it by doing our own generation. */
   static const char * const dtmf_tones[] = {
      "941+1336", /* 0 */
      "697+1209", /* 1 */
      "697+1336", /* 2 */
      "697+1477", /* 3 */
      "770+1209", /* 4 */
      "770+1336", /* 5 */
      "770+1477", /* 6 */
      "852+1209", /* 7 */
      "852+1336", /* 8 */
      "852+1477", /* 9 */
      "697+1633", /* A */
      "770+1633", /* B */
      "852+1633", /* C */
      "941+1633", /* D */
      "941+1209", /* * */
      "941+1477"  /* # */
   };

   if (!ast_channel_tech(chan)->send_digit_begin)
      return 0;

   ast_channel_lock(chan);
   ast_channel_sending_dtmf_digit_set(chan, digit);
   ast_channel_sending_dtmf_tv_set(chan, ast_tvnow());
   ast_channel_unlock(chan);

   if (!ast_channel_tech(chan)->send_digit_begin(chan, digit))
      return 0;

   if (digit >= '0' && digit <='9')
      ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
   else if (digit >= 'A' && digit <= 'D')
      ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
   else if (digit == '*')
      ast_playtones_start(chan, 0, dtmf_tones[14], 0);
   else if (digit == '#')
      ast_playtones_start(chan, 0, dtmf_tones[15], 0);
   else {
      /* not handled */
      ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, ast_channel_name(chan));
   }

   return 0;
}
int ast_senddigit_end ( struct ast_channel chan,
char  digit,
unsigned int  duration 
)

Send a DTMF digit to a channel.

Parameters:
chanchannel to act upon
digitthe DTMF digit to send, encoded in ASCII
durationthe duration of the digit ending in ms
Returns:
Returns 0 on success, -1 on failure

Definition at line 4799 of file channel.c.

References ast_channel_generator(), ast_channel_lock, ast_channel_sending_dtmf_digit(), ast_channel_sending_dtmf_digit_set(), ast_channel_tech(), ast_channel_unlock, ast_playtones_stop(), and ast_channel_tech::send_digit_end.

Referenced by agent_digit_end(), ast_bridge_end_dtmf(), ast_senddigit(), and ast_write().

{
   int res = -1;

   if (ast_channel_tech(chan)->send_digit_end)
      res = ast_channel_tech(chan)->send_digit_end(chan, digit, duration);

   ast_channel_lock(chan);
   if (ast_channel_sending_dtmf_digit(chan) == digit) {
      ast_channel_sending_dtmf_digit_set(chan, 0);
   }
   ast_channel_unlock(chan);

   if (res && ast_channel_generator(chan))
      ast_playtones_stop(chan);

   return 0;
}
int ast_sendtext ( struct ast_channel chan,
const char *  text 
)

Sends text to a channel.

Parameters:
chanchannel to act upon
textstring of text to send on the channel

Write text to a display on a channel

Note:
The channel does not need to be locked before calling this function.
Return values:
0on success
-1on failure

Definition at line 4711 of file channel.c.

References ast_channel_flags(), ast_channel_lock, ast_channel_nativeformats(), ast_channel_tech(), ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_format_cap_has_type(), ast_format_set(), AST_FORMAT_T140, AST_FORMAT_TYPE_TEXT, AST_FRAME_TEXT, AST_MALLOCD_DATA, ast_strdup, ast_strlen_zero(), ast_test_flag, CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, ast_frame_subclass::format, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_frame::ptr, ast_channel_tech::send_text, send_text(), ast_frame::seqno, ast_frame::src, ast_frame::subclass, and ast_channel_tech::write_text.

Referenced by action_sendtext(), agent_sendtext(), handle_sendtext(), and sendtext_exec().

{
   int res = 0;

   ast_channel_lock(chan);
   /* Stop if we're a zombie or need a soft hangup */
   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
      ast_channel_unlock(chan);
      return -1;
   }

   if (ast_strlen_zero(text)) {
      ast_channel_unlock(chan);
      return 0;
   }

   CHECK_BLOCKING(chan);
   if (ast_channel_tech(chan)->write_text && (ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_TEXT))) {
      struct ast_frame f;

      f.frametype = AST_FRAME_TEXT;
      f.src = "DIALPLAN";
      f.mallocd = AST_MALLOCD_DATA;
      f.datalen = strlen(text);
      f.data.ptr = ast_strdup(text);
      f.offset = 0;
      f.seqno = 0;

      ast_format_set(&f.subclass.format, AST_FORMAT_T140, 0);
      res = ast_channel_tech(chan)->write_text(chan, &f);
   } else if (ast_channel_tech(chan)->send_text) {
      res = ast_channel_tech(chan)->send_text(chan, text);
   }
   ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
   ast_channel_unlock(chan);
   return res;
}
void ast_set_callerid ( struct ast_channel chan,
const char *  cid_num,
const char *  cid_name,
const char *  cid_ani 
)

Set caller ID number, name and ANI and generate AMI event.

Note:
Use ast_channel_set_caller() and ast_channel_set_caller_event() instead.
The channel does not need to be locked before calling this function.

Definition at line 7321 of file channel.c.

References ast_party_caller::ani, ast_cdr_setcid(), ast_channel_caller(), ast_channel_cdr(), ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, ast_party_caller::id, name, ast_party_id::name, ast_party_id::number, report_new_callerid(), ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by __analog_ss_thread(), __ast_request_and_dial(), analog_ss_thread(), cb_events(), disa_exec(), get_pai(), get_rpid(), handle_setcallerid(), mgcp_ss(), privacy_exec(), ring_entry(), skinny_newcall(), and socket_process_helper().

void ast_set_hangupsource ( struct ast_channel chan,
const char *  source,
int  force 
)

Set the source of the hangup in this channel and it's bridge.

Parameters:
chanchannel to set the field on
sourcea string describing the source of the hangup for this channel
force
Note:
Absolutely _NO_ channel locks should be held before calling this function.
Since:
1.8

Hangupsource is generally the channel name that caused the bridge to be hung up, but it can also be other things such as "dialplan/agi" This can then be logged in the CDR or CEL

Definition at line 2717 of file channel.c.

References ast_bridged_channel(), ast_channel_hangupsource(), ast_channel_lock, ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_strlen_zero(), and ast_channel::bridge.

Referenced by __dahdi_exception(), analog_exception(), func_channel_write_real(), handle_hangup(), pbx_builtin_hangup(), set_hangup_source_and_cause(), and sip_queue_hangup_cause().

{
   struct ast_channel *bridge;

   ast_channel_lock(chan);
   if (force || ast_strlen_zero(ast_channel_hangupsource(chan))) {
      ast_channel_hangupsource_set(chan, source);
   }
   bridge = ast_bridged_channel(chan);
   if (bridge) {
      ast_channel_ref(bridge);
   }
   ast_channel_unlock(chan);

   if (bridge) {
      ast_channel_lock(bridge);
      if (force || ast_strlen_zero(ast_channel_hangupsource(bridge))) {
         ast_channel_hangupsource_set(bridge, source);
      }
      ast_channel_unlock(bridge);
      ast_channel_unref(bridge);
   }
}
static void ast_set_owners_and_peers ( struct ast_channel chan1,
struct ast_channel chan2 
) [static]

Definition at line 6686 of file channel.c.

References ast_channel_accountcode(), ast_channel_name(), ast_channel_peeraccount(), ast_debug, and ast_strlen_zero().

Referenced by ast_channel_bridge().

{
   if (!ast_strlen_zero(ast_channel_accountcode(chan1)) && ast_strlen_zero(ast_channel_peeraccount(chan2))) {
      ast_debug(1, "setting peeraccount to %s for %s from data on channel %s\n",
            ast_channel_accountcode(chan1), ast_channel_name(chan2), ast_channel_name(chan1));
      ast_channel_peeraccount_set(chan2, ast_channel_accountcode(chan1));
   }
   if (!ast_strlen_zero(ast_channel_accountcode(chan2)) && ast_strlen_zero(ast_channel_peeraccount(chan1))) {
      ast_debug(1, "setting peeraccount to %s for %s from data on channel %s\n",
            ast_channel_accountcode(chan2), ast_channel_name(chan1), ast_channel_name(chan2));
      ast_channel_peeraccount_set(chan1, ast_channel_accountcode(chan2));
   }
   if (!ast_strlen_zero(ast_channel_peeraccount(chan1)) && ast_strlen_zero(ast_channel_accountcode(chan2))) {
      ast_debug(1, "setting accountcode to %s for %s from data on channel %s\n",
            ast_channel_peeraccount(chan1), ast_channel_name(chan2), ast_channel_name(chan1));
      ast_channel_accountcode_set(chan2, ast_channel_peeraccount(chan1));
   }
   if (!ast_strlen_zero(ast_channel_peeraccount(chan2)) && ast_strlen_zero(ast_channel_accountcode(chan1))) {
      ast_debug(1, "setting accountcode to %s for %s from data on channel %s\n",
            ast_channel_peeraccount(chan2), ast_channel_name(chan1), ast_channel_name(chan2));
      ast_channel_accountcode_set(chan1, ast_channel_peeraccount(chan2));
   }
   if (0 != strcmp(ast_channel_accountcode(chan1), ast_channel_peeraccount(chan2))) {
      ast_debug(1, "changing peeraccount from %s to %s on %s to match channel %s\n",
            ast_channel_peeraccount(chan2), ast_channel_peeraccount(chan1), ast_channel_name(chan2), ast_channel_name(chan1));
      ast_channel_peeraccount_set(chan2, ast_channel_accountcode(chan1));
   }
   if (0 != strcmp(ast_channel_accountcode(chan2), ast_channel_peeraccount(chan1))) {
      ast_debug(1, "changing peeraccount from %s to %s on %s to match channel %s\n",
            ast_channel_peeraccount(chan1), ast_channel_peeraccount(chan2), ast_channel_name(chan1), ast_channel_name(chan2));
      ast_channel_peeraccount_set(chan1, ast_channel_accountcode(chan2));
   }
}
void ast_set_party_id_all ( struct ast_set_party_id update_id)

Set the update marker to update all information of a corresponding party id.

Since:
11.0
Parameters:
update_idThe update marker for a corresponding party id.
Returns:
Nothing

Definition at line 1915 of file channel.c.

References ast_set_party_id::name, ast_set_party_id::number, and ast_set_party_id::subaddress.

Referenced by handle_request_invite(), handle_request_update(), handle_response_invite(), misdn_queue_connected_line_update(), and sip_call().

{
   update_id->name = 1;
   update_id->number = 1;
   update_id->subaddress = 1;
}
int ast_set_read_format_from_cap ( struct ast_channel chan,
struct ast_format_cap formats 
)

Sets read format on channel chan from capabilities Set read format for channel to whichever component of "format" is best.

Parameters:
chanchannel to change
formatsnew formats to pick from for reading
Returns:
Returns 0 on success, -1 on failure

Definition at line 5438 of file channel.c.

References ast_channel_rawreadformat(), ast_channel_readformat(), and set_format().

Referenced by agent_call(), and login_exec().

void ast_set_variables ( struct ast_channel chan,
struct ast_variable vars 
)

adds a list of channel variables to a channel

Parameters:
chanthe channel
varsa linked list of variables

Variable names can be for a regular channel variable or a dialplan function that has the ability to be written to.

Definition at line 8732 of file channel.c.

References ast_variable::name, ast_variable::next, pbx_builtin_setvar_helper(), and ast_variable::value.

Referenced by __ast_request_and_dial(), ast_call_forward(), ast_pbx_outgoing_app(), and ast_pbx_outgoing_exten().

{
   struct ast_variable *cur;

   for (cur = vars; cur; cur = cur->next)
      pbx_builtin_setvar_helper(chan, cur->name, cur->value);
}
int ast_set_write_format ( struct ast_channel chan,
struct ast_format format 
)
int ast_set_write_format_from_cap ( struct ast_channel chan,
struct ast_format_cap formats 
)

Sets write format on channel chan Set write format for channel to whichever component of "format" is best.

Parameters:
chanchannel to change
formatsnew formats to pick from for writing
Returns:
Returns 0 on success, -1 on failure

Definition at line 5491 of file channel.c.

References ast_channel_rawwriteformat(), ast_channel_writeformat(), and set_format().

Referenced by agent_call(), ast_openstream_full(), and login_exec().

int ast_setstate ( struct ast_channel chan,
enum ast_channel_state  state 
)

Change the state of a channel.

Definition at line 7389 of file channel.c.

References ast_channel_caller(), ast_channel_connected(), ast_channel_flags(), AST_CHANNEL_NAME, ast_channel_name(), ast_channel_state_set(), ast_channel_uniqueid(), ast_copy_string(), AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, ast_devstate_changed_literal(), AST_DEVSTATE_NOT_CACHABLE, AST_FLAG_DISABLE_DEVSTATE_CACHE, ast_manager_event, ast_state2str(), ast_test_flag, EVENT_FLAG_CALL, name, and S_COR.

Referenced by __analog_handle_event(), __analog_ss_thread(), __ast_read(), __dahdi_exception(), __oh323_update_info(), agent_call(), alsa_answer(), analog_answer(), analog_call(), analog_exception(), analog_ss_thread(), ast_raw_answer(), cb_events(), check_availability(), console_answer(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), do_bridge_masquerade(), gtalk_call(), gtalk_newcall(), handle_invite_replaces(), handle_request_invite(), handle_response_invite(), iax2_call(), jingle_action_session_info(), jingle_action_session_initiate(), jingle_call(), jingle_newcall(), local_queue_frame(), mgcp_answer(), mgcp_call(), mgcp_ss(), misdn_call(), misdn_indication(), my_set_waitingfordt(), nbs_call(), nbs_hangup(), oh323_answer(), oss_answer(), pbx_builtin_busy(), pbx_builtin_congestion(), phone_answer(), phone_call(), phone_exception(), phone_hangup(), phone_write(), pri_dchannel(), pri_ss_thread(), release_chan(), release_chan_early(), setsubstate(), sig_pri_answer(), sig_pri_call(), sig_pri_indicate(), sig_ss7_call(), sig_ss7_indicate(), sip_answer(), skinny_answer(), skinny_newcall(), ss7_linkset(), unistim_answer(), unistim_call(), unistim_new(), unistim_ss(), and update_state().

{
   int oldstate = ast_channel_state(chan);
   char name[AST_CHANNEL_NAME], *dashptr;

   if (oldstate == state)
      return 0;

   ast_copy_string(name, ast_channel_name(chan), sizeof(name));
   if ((dashptr = strrchr(name, '-'))) {
      *dashptr = '\0';
   }

   ast_channel_state_set(chan, state);

   /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver
    * for this channel is using the callback method for device state. If we pass in an actual state here
    * we override what they are saying the state is and things go amuck. */
   ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), name);

   /* setstate used to conditionally report Newchannel; this is no more */
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a channel's state changes.</synopsis>
         <syntax>
            <parameter name="ChannelState">
               <para>A numeric code for the channel's current state, related to ChannelStateDesc</para>
            </parameter>
            <parameter name="ChannelStateDesc">
               <enumlist>
                  <enum name="Down"/>
                  <enum name="Rsrvd"/>
                  <enum name="OffHook"/>
                  <enum name="Dialing"/>
                  <enum name="Ring"/>
                  <enum name="Ringing"/>
                  <enum name="Up"/>
                  <enum name="Busy"/>
                  <enum name="Dialing Offhook"/>
                  <enum name="Pre-ring"/>
                  <enum name="Unknown"/>
               </enumlist>
            </parameter>
         </syntax>
      </managerEventInstance>
   ***/
   ast_manager_event(chan, EVENT_FLAG_CALL, "Newstate",
      "Channel: %s\r\n"
      "ChannelState: %d\r\n"
      "ChannelStateDesc: %s\r\n"
      "CallerIDNum: %s\r\n"
      "CallerIDName: %s\r\n"
      "ConnectedLineNum: %s\r\n"
      "ConnectedLineName: %s\r\n"
      "Uniqueid: %s\r\n",
      ast_channel_name(chan), ast_channel_state(chan), ast_state2str(ast_channel_state(chan)),
      S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
      S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""),
      S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, ""),
      S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, ""),
      ast_channel_uniqueid(chan));

   return 0;
}
int ast_settimeout ( struct ast_channel c,
unsigned int  rate,
int(*)(const void *data)  func,
void *  data 
)

Enable or disable timer ticks for a channel.

Parameters:
cchannel
ratenumber of timer ticks per second
funccallback function
data

If timers are supported, force a scheduled expiration on the timer fd, at which point we call the callback function / data

Note:
Call this function with a rate of 0 to turn off the timer ticks
Version:
1.6.1 changed samples parameter to rate, accomodates new timing methods

Definition at line 3556 of file channel.c.

References ast_settimeout_full().

Referenced by ast_activate_generator(), ast_deactivate_generator(), ast_read_generator_actions(), ast_readaudio_callback(), filestream_close(), and internal_deactivate_generator().

{
   return ast_settimeout_full(c, rate, func, data, 0);
}
int ast_settimeout_full ( struct ast_channel c,
unsigned int  rate,
int(*)(const void *data)  func,
void *  data,
unsigned int  is_ao2_obj 
)

Definition at line 3561 of file channel.c.

References ao2_ref, ast_channel_fdno(), ast_channel_fdno_set(), ast_channel_flags(), ast_channel_lock, ast_channel_timer(), ast_channel_timingdata(), ast_channel_timingdata_set(), ast_channel_timingfd(), ast_channel_timingfunc_set(), ast_channel_unlock, ast_clear_flag, ast_debug, AST_FLAG_TIMINGDATA_IS_AO2_OBJ, ast_set_flag, ast_test_flag, ast_timer_get_max_rate(), ast_timer_set_rate(), and AST_TIMING_FD.

Referenced by ast_readaudio_callback(), and ast_settimeout().

{
   int res;
   unsigned int real_rate = rate, max_rate;

   ast_channel_lock(c);

   if (ast_channel_timingfd(c) == -1) {
      ast_channel_unlock(c);
      return -1;
   }

   if (!func) {
      rate = 0;
      data = NULL;
   }

   if (rate && rate > (max_rate = ast_timer_get_max_rate(ast_channel_timer(c)))) {
      real_rate = max_rate;
   }

   ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate);

   res = ast_timer_set_rate(ast_channel_timer(c), real_rate);

   if (ast_channel_timingdata(c) && ast_test_flag(ast_channel_flags(c), AST_FLAG_TIMINGDATA_IS_AO2_OBJ)) {
      ao2_ref(ast_channel_timingdata(c), -1);
   }

   ast_channel_timingfunc_set(c, func);
   ast_channel_timingdata_set(c, data);

   if (data && is_ao2_obj) {
      ao2_ref(data, 1);
      ast_set_flag(ast_channel_flags(c), AST_FLAG_TIMINGDATA_IS_AO2_OBJ);
   } else {
      ast_clear_flag(ast_channel_flags(c), AST_FLAG_TIMINGDATA_IS_AO2_OBJ);
   }

   if (func == NULL && rate == 0 && ast_channel_fdno(c) == AST_TIMING_FD) {
      /* Clearing the timing func and setting the rate to 0
       * means that we don't want to be reading from the timingfd
       * any more. Setting c->fdno to -1 means we won't have any
       * errant reads from the timingfd, meaning we won't potentially
       * miss any important frames.
       */
      ast_channel_fdno_set(c, -1);
   }

   ast_channel_unlock(c);

   return res;
}
int ast_shutting_down ( void  )

Returns non-zero if Asterisk is being shut down.

Returns:
non-zero if Asterisk is being shut down

Definition at line 674 of file channel.c.

References shutting_down.

Referenced by __ast_channel_alloc_ap(), confbridge_exec(), and handle_request_options().

{
   return shutting_down;
}
int ast_softhangup ( struct ast_channel chan,
int  cause 
)

Softly hangup a channel, lock.

Softly hangup up a channel.

Definition at line 2672 of file channel.c.

References ast_channel_lock, ast_channel_name(), ast_channel_uniqueid(), ast_channel_unlock, ast_softhangup_nolock(), EVENT_FLAG_CALL, and manager_event.

Referenced by __analog_handle_event(), __ast_module_user_hangup_all(), __ast_pbx_run(), __unload_module(), agent_hangup(), agent_logoff(), agent_read(), ast_channel_softhangup_cb(), ast_dial_join(), cc_generic_agent_stop_ringing(), conf_free(), dahdi_handle_event(), handle_hangup(), handle_softhangup(), login_exec(), manager_park(), mgcp_pktcgate_remove(), read_agent_config(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().

{
   int res;

   ast_channel_lock(chan);
   res = ast_softhangup_nolock(chan, cause);
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a soft hangup is requested with a specific cause code.</synopsis>
            <syntax>
               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
            </syntax>
      </managerEventInstance>
   ***/
   manager_event(EVENT_FLAG_CALL, "SoftHangupRequest",
      "Channel: %s\r\n"
      "Uniqueid: %s\r\n"
      "Cause: %d\r\n",
      ast_channel_name(chan),
      ast_channel_uniqueid(chan),
      cause);
   ast_channel_unlock(chan);

   return res;
}
const char* ast_state2str ( enum ast_channel_state  state)

Gives the string form of a given channel state.

Note:
This function is not reentrant.

Definition at line 821 of file channel.c.

References AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DIALING_OFFHOOK, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_threadstorage_get(), STATE2STR_BUFSIZE, and state2str_threadbuf.

Referenced by __ast_channel_alloc_ap(), action_coreshowchannels(), action_status(), agent_hangup(), ast_channel_data_add_structure(), ast_do_masquerade(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_showchan(), local_attended_transfer(), mgcp_new(), serialize_showchan(), sip_hangup(), and update_connectedline().

{
   char *buf;

   switch (state) {
   case AST_STATE_DOWN:
      return "Down";
   case AST_STATE_RESERVED:
      return "Rsrvd";
   case AST_STATE_OFFHOOK:
      return "OffHook";
   case AST_STATE_DIALING:
      return "Dialing";
   case AST_STATE_RING:
      return "Ring";
   case AST_STATE_RINGING:
      return "Ringing";
   case AST_STATE_UP:
      return "Up";
   case AST_STATE_BUSY:
      return "Busy";
   case AST_STATE_DIALING_OFFHOOK:
      return "Dialing Offhook";
   case AST_STATE_PRERING:
      return "Pre-ring";
   default:
      if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
         return "Unknown";
      snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state);
      return buf;
   }
}
int ast_str2cause ( const char *  name)

Convert a symbolic hangup cause to number.

Convert the string form of a cause code to a number.

Definition at line 807 of file channel.c.

References ARRAY_LEN, and causes.

Referenced by pbx_builtin_hangup().

{
   int x;

   for (x = 0; x < ARRAY_LEN(causes); x++)
      if (!strncasecmp(causes[x].name, name, strlen(causes[x].name)))
         return causes[x].cause;

   return -1;
}
int ast_tonepair ( struct ast_channel chan,
int  freq1,
int  freq2,
int  duration,
int  vol 
)

Play a tone pair for a given amount of time

Definition at line 8285 of file channel.c.

References ast_channel_generatordata(), ast_frfree, ast_read(), ast_tonepair_start(), and ast_waitfor().

Referenced by zapateller_exec().

{
   int res;

   if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
      return res;

   /* Give us some wiggle room */
   while (ast_channel_generatordata(chan) && ast_waitfor(chan, 100) >= 0) {
      struct ast_frame *f = ast_read(chan);
      if (f)
         ast_frfree(f);
      else
         return -1;
   }
   return 0;
}
int ast_tonepair_start ( struct ast_channel chan,
int  freq1,
int  freq2,
int  duration,
int  vol 
)

Start a tone going

Definition at line 8267 of file channel.c.

References ast_activate_generator(), tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, and tonepair_def::vol.

Referenced by ast_tonepair(), pbx_builtin_waitexten(), play_dialtone(), and sendnoise().

{
   struct tonepair_def d = { 0, };

   d.freq1 = freq1;
   d.freq2 = freq2;
   d.duration = duration;
   d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
   if (ast_activate_generator(chan, &tonepair, &d))
      return -1;
   return 0;
}
void ast_tonepair_stop ( struct ast_channel chan)

Stop a tone from playing

Definition at line 8280 of file channel.c.

References ast_deactivate_generator().

Referenced by sendnoise().

int ast_transfer ( struct ast_channel chan,
char *  dest 
)

Transfer a call to dest, if the channel supports transfer.

Transfer a channel (if supported).

Called by:

  • app_transfer
  • the manager interface

Definition at line 6031 of file channel.c.

References ast_channel_flags(), ast_channel_lock, ast_channel_tech(), ast_channel_unlock, ast_check_hangup(), AST_CONTROL_TRANSFER, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, ast_frfree, ast_read(), ast_test_flag, AST_TRANSFER_SUCCESS, ast_waitfor(), ast_frame::data, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::ptr, ast_frame::subclass, transfer, and ast_channel_tech::transfer.

Referenced by transfer_exec().

{
   int res = -1;

   /* Stop if we're a zombie or need a soft hangup */
   ast_channel_lock(chan);
   if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
      if (ast_channel_tech(chan)->transfer) {
         res = ast_channel_tech(chan)->transfer(chan, dest);
         if (!res)
            res = 1;
      } else
         res = 0;
   }
   ast_channel_unlock(chan);

   if (res <= 0) {
      return res;
   }

   for (;;) {
      struct ast_frame *fr;

      res = ast_waitfor(chan, -1);

      if (res < 0 || !(fr = ast_read(chan))) {
         res = -1;
         break;
      }

      if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_TRANSFER) {
         enum ast_control_transfer *message = fr->data.ptr;

         if (*message == AST_TRANSFER_SUCCESS) {
            res = 1;
         } else {
            res = -1;
         }

         ast_frfree(fr);
         break;
      }

      ast_frfree(fr);
   }

   return res;
}
char* ast_transfercapability2str ( int  transfercapability) const

Gives the string form of a given transfer capability.

Parameters:
transfercapabilitytransfer capability to get the name of
Returns:
the text form of the binary transfer capability

Definition at line 855 of file channel.c.

References AST_TRANS_CAP_3_1K_AUDIO, AST_TRANS_CAP_DIGITAL, AST_TRANS_CAP_DIGITAL_W_TONES, AST_TRANS_CAP_RESTRICTED_DIGITAL, AST_TRANS_CAP_SPEECH, and AST_TRANS_CAP_VIDEO.

Referenced by ast_channel_data_add_structure(), cb_events(), misdn_call(), oh323_call(), sig_pri_call(), sig_pri_new_ast_channel(), and sig_ss7_new_ast_channel().

{
   switch (transfercapability) {
   case AST_TRANS_CAP_SPEECH:
      return "SPEECH";
   case AST_TRANS_CAP_DIGITAL:
      return "DIGITAL";
   case AST_TRANS_CAP_RESTRICTED_DIGITAL:
      return "RESTRICTED_DIGITAL";
   case AST_TRANS_CAP_3_1K_AUDIO:
      return "3K1AUDIO";
   case AST_TRANS_CAP_DIGITAL_W_TONES:
      return "DIGITAL_W_TONES";
   case AST_TRANS_CAP_VIDEO:
      return "VIDEO";
   default:
      return "UNKNOWN";
   }
}
int ast_undestroyed_channels ( void  )
Returns:
the number of channels not yet destroyed

Definition at line 662 of file channel.c.

References ast_atomic_fetchadd_int().

Referenced by can_safely_quit().

Definition at line 8444 of file channel.c.

References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.

Referenced by unload_module().

int ast_waitfor ( struct ast_channel chan,
int  ms 
)
struct ast_channel* ast_waitfor_n ( struct ast_channel **  chan,
int  n,
int *  ms 
) [read]

Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.

Returns:
Return channel with activity, or NULL if none has activity.
Parameters:
chanan array of pointers to channels
nnumber of channels that are to be waited upon
mstime "ms" is modified in-place, if applicable

Definition at line 3533 of file channel.c.

References ast_waitfor_nandfds().

Referenced by ast_generic_bridge(), ast_udptl_bridge(), autoservice_run(), dahdi_bridge(), dial_exec_full(), feature_request_and_dial(), generic_thread_loop(), iax2_bridge(), local_bridge_loop(), misdn_bridge(), monitor_dial(), remote_bridge_loop(), wait_for_answer(), and wait_for_winner().

{
   return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
}
int ast_waitfor_n_fd ( int *  fds,
int  n,
int *  ms,
int *  exception 
)

Wait for x amount of time on a file descriptor to have input.

Waits for input on an fd.

Definition at line 3144 of file channel.c.

References ast_waitfor_nandfds().

Referenced by dundi_lookup_internal(), dundi_precache_internal(), and softmix_bridge_thread().

{
   int winner = -1;
   ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
   return winner;
}
struct ast_channel* ast_waitfor_nandfds ( struct ast_channel **  c,
int  n,
int *  fds,
int  nfds,
int *  exception,
int *  outfd,
int *  ms 
) [read]

Wait for x amount of time on a file descriptor to have input.

Waits for activity on a group of channels.

Definition at line 3156 of file channel.c.

References ast_add_fd(), ast_alloca, ast_channel_fd(), ast_channel_fdno_set(), ast_channel_flags(), ast_channel_lock, ast_channel_masq(), ast_channel_name(), ast_channel_softhangup_internal_flag_add(), ast_channel_unlock, ast_channel_whentohangup(), ast_clear_flag, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_MAX_FDS, ast_poll, ast_set_flag, AST_SOFTHANGUP_TIMEOUT, ast_test_suite_event_notify, ast_tvcmp(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), chanlist::chan, CHECK_BLOCKING, and errno.

Referenced by ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), bridge_channel_join_multithreaded(), conf_run(), eivr_comm(), find_cache(), generic_fax_exec(), multiplexed_thread_function(), run_agi(), and waitstream_core().

{
   struct timeval start = { 0 , 0 };
   struct pollfd *pfds = NULL;
   int res;
   long rms;
   int x, y, max;
   int sz;
   struct timeval now = { 0, 0 };
   struct timeval whentohangup = { 0, 0 }, diff;
   struct ast_channel *winner = NULL;
   struct fdmap {
      int chan;
      int fdno;
   } *fdmap = NULL;

   if (outfd) {
      *outfd = -99999;
   }
   if (exception) {
      *exception = 0;
   }

   if ((sz = n * AST_MAX_FDS + nfds)) {
      pfds = ast_alloca(sizeof(*pfds) * sz);
      fdmap = ast_alloca(sizeof(*fdmap) * sz);
   } else {
      /* nothing to allocate and no FDs to check */
      return NULL;
   }

   /* Perform any pending masquerades */
   for (x = 0; x < n; x++) {
      while (ast_channel_masq(c[x])) {
         ast_do_masquerade(c[x]);
      }

      ast_channel_lock(c[x]);
      if (!ast_tvzero(*ast_channel_whentohangup(c[x]))) {
         if (ast_tvzero(whentohangup))
            now = ast_tvnow();
         diff = ast_tvsub(*ast_channel_whentohangup(c[x]), now);
         if (diff.tv_sec < 0 || ast_tvzero(diff)) {
            ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(c[x]));
            /* Should already be hungup */
            ast_channel_softhangup_internal_flag_add(c[x], AST_SOFTHANGUP_TIMEOUT);
            ast_channel_unlock(c[x]);
            return c[x];
         }
         if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0)
            whentohangup = diff;
      }
      ast_channel_unlock(c[x]);
   }
   /* Wait full interval */
   rms = *ms;
   /* INT_MAX, not LONG_MAX, because it matters on 64-bit */
   if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) {
      rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000;              /* timeout in milliseconds */
      if (*ms >= 0 && *ms < rms) {                                                 /* original *ms still smaller */
         rms =  *ms;
      }
   } else if (!ast_tvzero(whentohangup) && rms < 0) {
      /* Tiny corner case... call would need to last >24 days */
      rms = INT_MAX;
   }
   /*
    * Build the pollfd array, putting the channels' fds first,
    * followed by individual fds. Order is important because
    * individual fd's must have priority over channel fds.
    */
   max = 0;
   for (x = 0; x < n; x++) {
      for (y = 0; y < AST_MAX_FDS; y++) {
         fdmap[max].fdno = y;  /* fd y is linked to this pfds */
         fdmap[max].chan = x;  /* channel x is linked to this pfds */
         max += ast_add_fd(&pfds[max], ast_channel_fd(c[x], y));
      }
      CHECK_BLOCKING(c[x]);
   }
   /* Add the individual fds */
   for (x = 0; x < nfds; x++) {
      fdmap[max].chan = -1;
      max += ast_add_fd(&pfds[max], fds[x]);
   }

   if (*ms > 0) {
      start = ast_tvnow();
   }

   if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
      do {
         int kbrms = rms;
         if (kbrms > 600000) {
            kbrms = 600000;
         }
         res = ast_poll(pfds, max, kbrms);
         if (!res) {
            rms -= kbrms;
         }
      } while (!res && (rms > 0));
   } else {
      res = ast_poll(pfds, max, rms);
   }
   for (x = 0; x < n; x++) {
      ast_clear_flag(ast_channel_flags(c[x]), AST_FLAG_BLOCKING);
   }
   if (res < 0) { /* Simulate a timeout if we were interrupted */
      if (errno != EINTR) {
         *ms = -1;
      }
      return NULL;
   }
   if (!ast_tvzero(whentohangup)) {   /* if we have a timeout, check who expired */
      now = ast_tvnow();
      for (x = 0; x < n; x++) {
         if (!ast_tvzero(*ast_channel_whentohangup(c[x])) && ast_tvcmp(*ast_channel_whentohangup(c[x]), now) <= 0) {
            ast_test_suite_event_notify("HANGUP_TIME", "Channel: %s", ast_channel_name(c[x]));
            ast_channel_softhangup_internal_flag_add(c[x], AST_SOFTHANGUP_TIMEOUT);
            if (winner == NULL) {
               winner = c[x];
            }
         }
      }
   }
   if (res == 0) { /* no fd ready, reset timeout and done */
      *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
      return winner;
   }
   /*
    * Then check if any channel or fd has a pending event.
    * Remember to check channels first and fds last, as they
    * must have priority on setting 'winner'
    */
   for (x = 0; x < max; x++) {
      res = pfds[x].revents;
      if (res == 0) {
         continue;
      }
      if (fdmap[x].chan >= 0) {  /* this is a channel */
         winner = c[fdmap[x].chan]; /* override previous winners */
         if (res & POLLPRI) {
            ast_set_flag(ast_channel_flags(winner), AST_FLAG_EXCEPTION);
         } else {
            ast_clear_flag(ast_channel_flags(winner), AST_FLAG_EXCEPTION);
         }
         ast_channel_fdno_set(winner, fdmap[x].fdno);
      } else {       /* this is an fd */
         if (outfd) {
            *outfd = pfds[x].fd;
         }
         if (exception) {
            *exception = (res & POLLPRI) ? -1 : 0;
         }
         winner = NULL;
      }
   }
   if (*ms > 0) {
      *ms -= ast_tvdiff_ms(ast_tvnow(), start);
      if (*ms < 0) {
         *ms = 0;
      }
   }
   return winner;
}
int ast_waitfordigit_full ( struct ast_channel c,
int  ms,
int  audiofd,
int  ctrlfd 
)

Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.

Parameters:
cchannel to wait for a digit on
mshow many milliseconds to wait (<0 for indefinite).
audiofdaudio file descriptor to write to if audio frames are received
ctrlfdcontrol file descriptor to monitor for reading
Returns:
Returns 1 if ctrlfd becomes available

Definition at line 3615 of file channel.c.

References ast_channel_flags(), ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_FLAG_END_DTMF_ONLY, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_remaining_ms(), ast_set_flag, ast_test_flag, ast_tvnow(), ast_waitfor_nandfds(), ast_frame::data, ast_frame::datalen, errno, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().

{
   struct timeval start = ast_tvnow();
   int ms;

   /* Stop if we're a zombie or need a soft hangup */
   if (ast_test_flag(ast_channel_flags(c), AST_FLAG_ZOMBIE) || ast_check_hangup(c))
      return -1;

   /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
   ast_set_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);

   /* Wait for a digit, no more than timeout_ms milliseconds total.
    * Or, wait indefinitely if timeout_ms is <0.
    */
   while ((ms = ast_remaining_ms(start, timeout_ms))) {
      struct ast_channel *rchan;
      int outfd = -1;

      errno = 0;
      /* While ast_waitfor_nandfds tries to help by reducing the timeout by how much was waited,
       * it is unhelpful if it waited less than a millisecond.
       */
      rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);

      if (!rchan && outfd < 0 && ms) {
         if (errno == 0 || errno == EINTR)
            continue;
         ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
         ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
         return -1;
      } else if (outfd > -1) {
         /* The FD we were watching has something waiting */
         ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n");
         ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
         return 1;
      } else if (rchan) {
         int res;
         struct ast_frame *f = ast_read(c);
         if (!f)
            return -1;

         switch (f->frametype) {
         case AST_FRAME_DTMF_BEGIN:
            break;
         case AST_FRAME_DTMF_END:
            res = f->subclass.integer;
            ast_frfree(f);
            ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
            return res;
         case AST_FRAME_CONTROL:
            switch (f->subclass.integer) {
            case AST_CONTROL_HANGUP:
               ast_frfree(f);
               ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
               return -1;
            case AST_CONTROL_PVT_CAUSE_CODE:
            case AST_CONTROL_RINGING:
            case AST_CONTROL_ANSWER:
            case AST_CONTROL_SRCUPDATE:
            case AST_CONTROL_SRCCHANGE:
            case AST_CONTROL_CONNECTED_LINE:
            case AST_CONTROL_REDIRECTING:
            case AST_CONTROL_UPDATE_RTP_PEER:
            case AST_CONTROL_HOLD:
            case AST_CONTROL_UNHOLD:
            case -1:
               /* Unimportant */
               break;
            default:
               ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass.integer);
               break;
            }
            break;
         case AST_FRAME_VOICE:
            /* Write audio if appropriate */
            if (audiofd > -1) {
               if (write(audiofd, f->data.ptr, f->datalen) < 0) {
                  ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
               }
            }
         default:
            /* Ignore */
            break;
         }
         ast_frfree(f);
      }
   }

   ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);

   return 0; /* Time is up */
}
int ast_write ( struct ast_channel chan,
struct ast_frame frame 
)

Write a frame to a channel This function writes the given frame to the indicated channel.

Parameters:
chandestination channel of the frame
frameframe that will be written
Returns:
It returns 0 on success, -1 on failure.
Todo:
XXX should return 0 maybe ?

Definition at line 4960 of file channel.c.

References apply_plc(), ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), ast_channel_audiohooks(), ast_channel_audiohooks_set(), ast_channel_flags(), ast_channel_fout(), ast_channel_fout_set(), ast_channel_framehooks(), ast_channel_generatordata(), ast_channel_insmpl(), ast_channel_lock, ast_channel_masq(), ast_channel_masqr(), ast_channel_monitor(), ast_channel_name(), ast_channel_nativeformats(), ast_channel_outsmpl(), ast_channel_outsmpl_set(), ast_channel_rawwriteformat(), ast_channel_softhangup_internal_flag_add(), ast_channel_tech(), ast_channel_trylock, ast_channel_unlock, ast_channel_writeformat(), ast_channel_writetrans(), ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_deactivate_generator(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, ast_format_cap_iscompatible(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_rate(), AST_FORMAT_SLINEAR, AST_FORMAT_T140, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_framehook_list_write_event(), ast_frfree, ast_frisolate(), ast_getformatname(), ast_getformatname_multiple(), AST_LIST_NEXT, ast_log(), AST_MONITOR_RUNNING, ast_opt_generic_plc, ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), ast_set_write_format_by_id(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), calc_monitor_jump(), CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_channel_monitor::format, ast_frame_subclass::format, FRAMECOUNT_INC, ast_frame::frametype, ast_format::id, ast_channel_tech::indicate, ast_frame_subclass::integer, ast_frame::len, LOG_WARNING, chanlist::next, ast_frame::ptr, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), ast_channel_tech::send_html, ast_channel_tech::send_text, ast_frame::src, ast_frame::subclass, ast_channel_tech::write, write_stream(), ast_channel_tech::write_text, and ast_channel_tech::write_video.

Referenced by adsi_careful_send(), agent_write(), ast_bridge_call(), ast_generic_bridge(), ast_prod(), ast_readaudio_callback(), ast_readvideo_callback(), ast_udptl_bridge(), ast_write_video(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), fax_generator_generate(), feature_request_and_dial(), gen_generate(), generic_fax_exec(), handle_jack_audio(), iax2_bridge(), jb_get_and_deliver(), linear_generator(), local_bridge_loop(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), multiplexed_bridge_write(), NBScat_exec(), playtones_generator(), remote_bridge_loop(), send_tone_burst(), send_waveform_to_channel(), silence_generator_generate(), simple_bridge_write(), sms_generate(), softmix_bridge_poke(), softmix_bridge_write(), softmix_pass_dtmf(), softmix_pass_video_all(), softmix_pass_video_top_priority(), spandsp_fax_gw_t30_gen(), spy_generate(), t38_tx_packet_handler(), tonepair_generator(), and wait_for_answer().

{
   int res = -1;
   struct ast_frame *f = NULL;
   int count = 0;

   /*Deadlock avoidance*/
   while(ast_channel_trylock(chan)) {
      /*cannot goto done since the channel is not locked*/
      if(count++ > 10) {
         ast_debug(1, "Deadlock avoided for write to channel '%s'\n", ast_channel_name(chan));
         return 0;
      }
      usleep(1);
   }
   /* Stop if we're a zombie or need a soft hangup */
   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
      goto done;

   /* Handle any pending masquerades */
   while (ast_channel_masq(chan)) {
      ast_channel_unlock(chan);
      ast_do_masquerade(chan);
      ast_channel_lock(chan);
   }
   if (ast_channel_masqr(chan)) {
      res = 0; /* XXX explain, why 0 ? */
      goto done;
   }

   /* Perform the framehook write event here. After the frame enters the framehook list
    * there is no telling what will happen, how awesome is that!!! */
   if (!(fr = ast_framehook_list_write_event(ast_channel_framehooks(chan), fr))) {
      res = 0;
      goto done;
   }

   if (ast_channel_generatordata(chan) && (!fr->src || strcasecmp(fr->src, "ast_prod"))) {
      if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT)) {
            ast_deactivate_generator(chan);
      } else {
         if (fr->frametype == AST_FRAME_DTMF_END) {
            /* There is a generator running while we're in the middle of a digit.
             * It's probably inband DTMF, so go ahead and pass it so it can
             * stop the generator */
            ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
            ast_channel_unlock(chan);
            res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
            ast_channel_lock(chan);
            CHECK_BLOCKING(chan);
         } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_UNHOLD) {
            /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */
            res = (ast_channel_tech(chan)->indicate == NULL) ? 0 :
               ast_channel_tech(chan)->indicate(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
         }
         res = 0; /* XXX explain, why 0 ? */
         goto done;
      }
   }
   /* High bit prints debugging */
   if (ast_channel_fout(chan) & DEBUGCHAN_FLAG)
      ast_frame_dump(ast_channel_name(chan), fr, ">>");
   CHECK_BLOCKING(chan);
   switch (fr->frametype) {
   case AST_FRAME_CONTROL:
      res = (ast_channel_tech(chan)->indicate == NULL) ? 0 :
         ast_channel_tech(chan)->indicate(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
      break;
   case AST_FRAME_DTMF_BEGIN:
      if (ast_channel_audiohooks(chan)) {
         struct ast_frame *old_frame = fr;
         fr = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_WRITE, fr);
         if (old_frame != fr)
            f = fr;
      }
      send_dtmf_event(chan, "Sent", fr->subclass.integer, "Yes", "No");
      ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
      ast_channel_unlock(chan);
      res = ast_senddigit_begin(chan, fr->subclass.integer);
      ast_channel_lock(chan);
      CHECK_BLOCKING(chan);
      break;
   case AST_FRAME_DTMF_END:
      if (ast_channel_audiohooks(chan)) {
         struct ast_frame *new_frame = fr;

         new_frame = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_WRITE, fr);
         if (new_frame != fr) {
            ast_frfree(new_frame);
         }
      }
      send_dtmf_event(chan, "Sent", fr->subclass.integer, "No", "Yes");
      ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
      ast_channel_unlock(chan);
      res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
      ast_channel_lock(chan);
      CHECK_BLOCKING(chan);
      break;
   case AST_FRAME_TEXT:
      if (fr->subclass.integer == AST_FORMAT_T140) {
         res = (ast_channel_tech(chan)->write_text == NULL) ? 0 :
            ast_channel_tech(chan)->write_text(chan, fr);
      } else {
         res = (ast_channel_tech(chan)->send_text == NULL) ? 0 :
            ast_channel_tech(chan)->send_text(chan, (char *) fr->data.ptr);
      }
      break;
   case AST_FRAME_HTML:
      res = (ast_channel_tech(chan)->send_html == NULL) ? 0 :
         ast_channel_tech(chan)->send_html(chan, fr->subclass.integer, (char *) fr->data.ptr, fr->datalen);
      break;
   case AST_FRAME_VIDEO:
      /* XXX Handle translation of video codecs one day XXX */
      res = (ast_channel_tech(chan)->write_video == NULL) ? 0 :
         ast_channel_tech(chan)->write_video(chan, fr);
      break;
   case AST_FRAME_MODEM:
      res = (ast_channel_tech(chan)->write == NULL) ? 0 :
         ast_channel_tech(chan)->write(chan, fr);
      break;
   case AST_FRAME_VOICE:
      if (ast_channel_tech(chan)->write == NULL)
         break;   /*! \todo XXX should return 0 maybe ? */

      if (ast_opt_generic_plc && fr->subclass.format.id == AST_FORMAT_SLINEAR) {
         apply_plc(chan, fr);
      }

      /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
      if (ast_format_cmp(&fr->subclass.format, ast_channel_rawwriteformat(chan)) != AST_FORMAT_CMP_NOT_EQUAL) {
         f = fr;
      } else {
         if ((!ast_format_cap_iscompatible(ast_channel_nativeformats(chan), &fr->subclass.format)) &&
             (ast_format_cmp(ast_channel_writeformat(chan), &fr->subclass.format) != AST_FORMAT_CMP_EQUAL)) {
            char nf[512];

            /*
             * XXX Something is not right.  We are not compatible with this
             * frame.  Bad things can happen.  Problems range from no audio,
             * one-way audio, to unexplained line hangups.  As a last resort
             * try to adjust the format.  Ideally, we do not want to do this
             * because it indicates a deeper problem.  For now, we log these
             * events to reduce user impact and help identify the problem
             * areas.
             */
            ast_log(LOG_WARNING, "Codec mismatch on channel %s setting write format to %s from %s native formats %s\n",
               ast_channel_name(chan), ast_getformatname(&fr->subclass.format), ast_getformatname(ast_channel_writeformat(chan)),
               ast_getformatname_multiple(nf, sizeof(nf), ast_channel_nativeformats(chan)));
            ast_set_write_format_by_id(chan, fr->subclass.format.id);
         }

         f = (ast_channel_writetrans(chan)) ? ast_translate(ast_channel_writetrans(chan), fr, 0) : fr;
      }

      if (!f) {
         res = 0;
         break;
      }

      if (ast_channel_audiohooks(chan)) {
         struct ast_frame *prev = NULL, *new_frame, *cur, *dup;
         int freeoldlist = 0;

         if (f != fr) {
            freeoldlist = 1;
         }

         /* Since ast_audiohook_write may return a new frame, and the cur frame is
          * an item in a list of frames, create a new list adding each cur frame back to it
          * regardless if the cur frame changes or not. */
         for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
            new_frame = ast_audiohook_write_list(chan, ast_channel_audiohooks(chan), AST_AUDIOHOOK_DIRECTION_WRITE, cur);

            /* if this frame is different than cur, preserve the end of the list,
             * free the old frames, and set cur to be the new frame */
            if (new_frame != cur) {

               /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame
                * isn't part of local storage, meaning if ast_audiohook_write is called multiple
                * times it may override the previous frame we got from it unless we dup it */
               if ((dup = ast_frisolate(new_frame))) {
                  AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list);
                  if (freeoldlist) {
                     AST_LIST_NEXT(cur, frame_list) = NULL;
                     ast_frfree(cur);
                  }
                  if (new_frame != dup) {
                     ast_frfree(new_frame);
                  }
                  cur = dup;
               }
            }

            /* now, regardless if cur is new or not, add it to the new list,
             * if the new list has not started, cur will become the first item. */
            if (prev) {
               AST_LIST_NEXT(prev, frame_list) = cur;
            } else {
               f = cur; /* set f to be the beginning of our new list */
            }
            prev = cur;
         }
      }

      /* If Monitor is running on this channel, then we have to write frames out there too */
      /* the translator on chan->writetrans may have returned multiple frames
         from the single frame we passed in; if so, feed each one of them to the
         monitor */
      if (ast_channel_monitor(chan) && ast_channel_monitor(chan)->write_stream) {
         struct ast_frame *cur;

         for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
         /* XXX must explain this code */
#ifndef MONITOR_CONSTANT_DELAY
            int jump = ast_channel_insmpl(chan) - ast_channel_outsmpl(chan) - 4 * cur->samples;
            if (jump >= 0) {
               jump = calc_monitor_jump((ast_channel_insmpl(chan) - ast_channel_outsmpl(chan)), ast_format_rate(&f->subclass.format), ast_format_rate(&ast_channel_monitor(chan)->read_stream->fmt->format));
               if (ast_seekstream(ast_channel_monitor(chan)->write_stream, jump, SEEK_FORCECUR) == -1) {
                  ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
               }
               ast_channel_outsmpl_set(chan, ast_channel_outsmpl(chan) + (ast_channel_insmpl(chan) - ast_channel_outsmpl(chan)) + cur->samples);
            } else {
               ast_channel_outsmpl_set(chan, ast_channel_outsmpl(chan) + cur->samples);
            }
#else
            int jump = calc_monitor_jump((ast_channel_insmpl(chan) - ast_channel_outsmpl(chan)), ast_format_rate(f->subclass.codec), ast_format_rate(ast_channel_monitor(chan)->read_stream->fmt->format));
            if (jump - MONITOR_DELAY >= 0) {
               if (ast_seekstream(ast_channel_monitor(chan)->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1) {
                  ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
               }
               ast_channel_outsmpl_set(chan, ast_channel_outsmpl(chan) + ast_channel_insmpl(chan) - ast_channel_outsmpl(chan));
            } else {
               ast_channel_outsmpl_set(chan, ast_channel_outsmpl(chan) + cur->samples);
            }
#endif
            if (ast_channel_monitor(chan)->state == AST_MONITOR_RUNNING) {
               if (ast_writestream(ast_channel_monitor(chan)->write_stream, cur) < 0)
                  ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
            }
         }
      }

      /* the translator on chan->writetrans may have returned multiple frames
         from the single frame we passed in; if so, feed each one of them to the
         channel, freeing each one after it has been written */
      if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
         struct ast_frame *cur, *next = NULL;
         unsigned int skip = 0;

         cur = f;
         while (cur) {
            next = AST_LIST_NEXT(cur, frame_list);
            AST_LIST_NEXT(cur, frame_list) = NULL;
            if (!skip) {
               if ((res = ast_channel_tech(chan)->write(chan, cur)) < 0) {
                  ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
                  skip = 1;
               } else if (next) {
                  /* don't do this for the last frame in the list,
                     as the code outside the loop will do it once
                  */
                  ast_channel_fout_set(chan, FRAMECOUNT_INC(ast_channel_fout(chan)));
               }
            }
            ast_frfree(cur);
            cur = next;
         }

         /* reset f so the code below doesn't attempt to free it */
         f = NULL;
      } else {
         res = ast_channel_tech(chan)->write(chan, f);
      }
      break;
   case AST_FRAME_NULL:
   case AST_FRAME_IAX:
      /* Ignore these */
      res = 0;
      break;
   default:
      /* At this point, fr is the incoming frame and f is NULL.  Channels do
       * not expect to get NULL as a frame pointer and will segfault.  Hence,
       * we output the original frame passed in. */
      res = ast_channel_tech(chan)->write(chan, fr);
      break;
   }

   if (f && f != fr)
      ast_frfree(f);
   ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);

   /* Consider a write failure to force a soft hangup */
   if (res < 0) {
      ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
   } else {
      ast_channel_fout_set(chan, FRAMECOUNT_INC(ast_channel_fout(chan)));
   }
done:
   if (ast_channel_audiohooks(chan) && ast_audiohook_write_list_empty(ast_channel_audiohooks(chan))) {
      /* The list gets recreated if audiohooks are added again later */
      ast_audiohook_detach_list(ast_channel_audiohooks(chan));
      ast_channel_audiohooks_set(chan, NULL);
   }
   ast_channel_unlock(chan);
   return res;
}
int ast_write_video ( struct ast_channel chan,
struct ast_frame frame 
)

Write video frame to a channel This function writes the given frame to the indicated channel.

Parameters:
chandestination channel of the frame
frameframe that will be written
Returns:
It returns 1 on success, 0 if not implemented, and -1 on failure.

Definition at line 4845 of file channel.c.

References ast_channel_tech(), and ast_write().

{
   int res;
   if (!ast_channel_tech(chan)->write_video)
      return 0;
   res = ast_write(chan, fr);
   if (!res)
      res = 1;
   return res;
}
static void bridge_play_sounds ( struct ast_channel c0,
struct ast_channel c1 
) [static]

Definition at line 7806 of file channel.c.

References ast_channel_lock, ast_channel_unlock, bridge_playfile(), pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper().

Referenced by ast_channel_bridge().

{
   const char *s, *sound;

   /* See if we need to play an audio file to any side of the bridge */

   ast_channel_lock(c0);
   if ((s = pbx_builtin_getvar_helper(c0, "BRIDGE_PLAY_SOUND"))) {
      sound = ast_strdupa(s);
      ast_channel_unlock(c0);
      bridge_playfile(c0, c1, sound, 0);
      pbx_builtin_setvar_helper(c0, "BRIDGE_PLAY_SOUND", NULL);
   } else {
      ast_channel_unlock(c0);
   }

   ast_channel_lock(c1);
   if ((s = pbx_builtin_getvar_helper(c1, "BRIDGE_PLAY_SOUND"))) {
      sound = ast_strdupa(s);
      ast_channel_unlock(c1);
      bridge_playfile(c1, c0, sound, 0);
      pbx_builtin_setvar_helper(c1, "BRIDGE_PLAY_SOUND", NULL);
   } else {
      ast_channel_unlock(c1);
   }
}
static void bridge_playfile ( struct ast_channel chan,
struct ast_channel peer,
const char *  sound,
int  remain 
) [static]

Definition at line 7464 of file channel.c.

References ast_autoservice_start(), ast_autoservice_stop(), ast_channel_language(), AST_DIGIT_ANY, ast_say_number(), and ast_stream_and_wait().

Referenced by ast_channel_bridge(), and bridge_play_sounds().

{
   int min = 0, sec = 0, check;

   check = ast_autoservice_start(peer);
   if (check)
      return;

   if (remain > 0) {
      if (remain / 60 > 1) {
         min = remain / 60;
         sec = remain % 60;
      } else {
         sec = remain;
      }
   }

   if (!strcmp(sound,"timeleft")) { /* Queue support */
      ast_stream_and_wait(chan, "vm-youhave", "");
      if (min) {
         ast_say_number(chan, min, AST_DIGIT_ANY, ast_channel_language(chan), NULL);
         ast_stream_and_wait(chan, "queue-minutes", "");
      }
      if (sec) {
         ast_say_number(chan, sec, AST_DIGIT_ANY, ast_channel_language(chan), NULL);
         ast_stream_and_wait(chan, "queue-seconds", "");
      }
   } else {
      ast_stream_and_wait(chan, sound, "");
   }

   ast_autoservice_stop(peer);
}
static int calc_monitor_jump ( int  samples,
int  sample_rate,
int  seek_rate 
) [inline, static]

calculates the number of samples to jump forward with in a monitor stream.

Note:
When using ast_seekstream() with the read and write streams of a monitor, the number of samples to seek forward must be of the same sample rate as the stream or else the jump will not be calculated correctly.
Return values:
numberof samples to seek forward after rate conversion.

Definition at line 3840 of file channel.c.

References ast_frame::samples.

Referenced by __ast_read(), and ast_write().

{
   int diff = sample_rate - seek_rate;

   if (diff > 0) {
      samples = samples / (float) (sample_rate / seek_rate);
   } else if (diff < 0) {
      samples = samples * (float) (seek_rate / sample_rate);
   }

   return samples;
}
static void call_forward_inherit ( struct ast_channel new_chan,
struct ast_channel parent,
struct ast_channel orig 
) [static]

Definition at line 5547 of file channel.c.

References ast_channel_datastore_inherit(), ast_channel_flags(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_lock_both, ast_channel_redirecting(), ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), ast_channel_unlock, ast_channel_update_redirecting(), ast_check_hangup(), AST_FLAG_ZOMBIE, ast_party_redirecting_copy(), ast_party_redirecting_free(), ast_party_redirecting_init(), and ast_test_flag.

Referenced by ast_call_forward().

{
   if (!ast_test_flag(ast_channel_flags(parent), AST_FLAG_ZOMBIE) && !ast_check_hangup(parent)) {
      struct ast_party_redirecting redirecting;

      /*
       * The parent is not a ZOMBIE or hungup so update it with the
       * original channel's redirecting information.
       */
      ast_party_redirecting_init(&redirecting);
      ast_channel_lock(orig);
      ast_party_redirecting_copy(&redirecting, ast_channel_redirecting(orig));
      ast_channel_unlock(orig);
      if (ast_channel_redirecting_sub(orig, parent, &redirecting, 0) &&
         ast_channel_redirecting_macro(orig, parent, &redirecting, 1, 0)) {
         ast_channel_update_redirecting(parent, &redirecting, NULL);
      }
      ast_party_redirecting_free(&redirecting);
   }

   /* Safely inherit variables and datastores from the parent channel. */
   ast_channel_lock_both(parent, new_chan);
   ast_channel_inherit_variables(parent, new_chan);
   ast_channel_datastore_inherit(parent, new_chan);
   ast_channel_unlock(new_chan);
   ast_channel_unlock(parent);
}
static void* channel_cc_params_copy ( void *  data) [static]

Definition at line 11056 of file channel.c.

References ast_cc_config_params_init, and ast_cc_copy_config_params().

{
   const struct ast_cc_config_params *src = data;
   struct ast_cc_config_params *dest = ast_cc_config_params_init();
   if (!dest) {
      return NULL;
   }
   ast_cc_copy_config_params(dest, src);
   return dest;
}
static void channel_cc_params_destroy ( void *  data) [static]

Definition at line 11067 of file channel.c.

References ast_cc_config_params_destroy().

{
   struct ast_cc_config_params *cc_params = data;
   ast_cc_config_params_destroy(cc_params);
}
const char* channelreloadreason2txt ( enum channelreloadreason  reason)

Convert enum channelreloadreason to text string for manager event.

\ brief Convert channel reloadreason (ENUM) to text string for manager event

Definition at line 8847 of file channel.c.

References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.

Referenced by reload_config().

{
   switch (reason) {
   case CHANNEL_MODULE_LOAD:
      return "LOAD (Channel module load)";

   case CHANNEL_MODULE_RELOAD:
      return "RELOAD (Channel module reload)";

   case CHANNEL_CLI_RELOAD:
      return "CLIRELOAD (Channel module reload by CLI command)";

   default:
      return "MANAGERRELOAD (Channel module reload by manager)";
   }
};
static void clone_variables ( struct ast_channel original,
struct ast_channel clonechan 
) [static]

Clone channel variables from 'clone' channel into 'original' channel.

All variables except those related to app_groupcount are cloned. Variables are actually _removed_ from 'clone' channel, presumably because it will subsequently be destroyed.

Note:
Assumes locks will be in place on both channels when called.

Definition at line 6547 of file channel.c.

References ast_channel_varshead(), AST_LIST_APPEND_LIST, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_t::entries, ast_var_t::name, and ast_var_t::value.

Referenced by ast_do_masquerade().

{
   struct ast_var_t *current, *newvar;
   /* Append variables from clone channel into original channel */
   /* XXX Is this always correct?  We have to in order to keep MACROS working XXX */
   AST_LIST_APPEND_LIST(ast_channel_varshead(original), ast_channel_varshead(clonechan), entries);

   /* then, dup the varshead list into the clone */

   AST_LIST_TRAVERSE(ast_channel_varshead(original), current, entries) {
      newvar = ast_var_assign(current->name, current->value);
      if (newvar)
         AST_LIST_INSERT_TAIL(ast_channel_varshead(clonechan), newvar, entries);
   }
}
static char* complete_channeltypes ( struct ast_cli_args a) [static]

Definition at line 331 of file channel.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_cli_args::n, ast_cli_args::pos, chanlist::tech, and ast_cli_args::word.

Referenced by handle_cli_core_show_channeltype().

{
   struct chanlist *cl;
   int which = 0;
   int wordlen;
   char *ret = NULL;

   if (a->pos != 3)
      return NULL;

   wordlen = strlen(a->word);

   AST_RWLIST_RDLOCK(&backends);
   AST_RWLIST_TRAVERSE(&backends, cl, list) {
      if (!strncasecmp(a->word, cl->tech->type, wordlen) && ++which > a->n) {
         ret = ast_strdup(cl->tech->type);
         break;
      }
   }
   AST_RWLIST_UNLOCK(&backends);

   return ret;
}
static int data_channels_provider_handler ( const struct ast_data_search search,
struct ast_data root 
) [static]

Definition at line 8508 of file channel.c.

References ast_channel_data_add_structure(), ast_channel_iterator_all_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_channel_unref, ast_data_add_node(), ast_data_remove_node(), ast_data_search_match(), ast_log(), and LOG_ERROR.

{
   struct ast_channel *c;
   struct ast_channel_iterator *iter = NULL;
   struct ast_data *data_channel;

   for (iter = ast_channel_iterator_all_new();
      iter && (c = ast_channel_iterator_next(iter)); ast_channel_unref(c)) {
      ast_channel_lock(c);

      data_channel = ast_data_add_node(root, "channel");
      if (!data_channel) {
         ast_channel_unlock(c);
         continue;
      }

      if (ast_channel_data_add_structure(data_channel, c, 1) < 0) {
         ast_log(LOG_ERROR, "Unable to add channel structure for channel: %s\n", ast_channel_name(c));
      }

      ast_channel_unlock(c);

      if (!ast_data_search_match(search, data_channel)) {
         ast_data_remove_node(root, data_channel);
      }
   }
   if (iter) {
      ast_channel_iterator_destroy(iter);
   }

   return 0;
}
static int data_channeltypes_provider_handler ( const struct ast_data_search search,
struct ast_data data_root 
) [static]

Definition at line 8546 of file channel.c.

References ast_data_add_bool(), ast_data_add_codecs(), ast_data_add_node(), ast_data_add_str(), ast_data_remove_node(), ast_data_search_match(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and chanlist::tech.

{
   struct chanlist *cl;
   struct ast_data *data_type;

   AST_RWLIST_RDLOCK(&backends);
   AST_RWLIST_TRAVERSE(&backends, cl, list) {
      data_type = ast_data_add_node(data_root, "type");
      if (!data_type) {
         continue;
      }
      ast_data_add_str(data_type, "name", cl->tech->type);
      ast_data_add_str(data_type, "description", cl->tech->description);
      ast_data_add_bool(data_type, "devicestate", cl->tech->devicestate ? 1 : 0);
      ast_data_add_bool(data_type, "indications", cl->tech->indicate ? 1 : 0);
      ast_data_add_bool(data_type, "transfer", cl->tech->transfer ? 1 : 0);
      ast_data_add_bool(data_type, "send_digit_begin", cl->tech->send_digit_begin ? 1 : 0);
      ast_data_add_bool(data_type, "send_digit_end", cl->tech->send_digit_end ? 1 : 0);
      ast_data_add_bool(data_type, "call", cl->tech->call ? 1 : 0);
      ast_data_add_bool(data_type, "hangup", cl->tech->hangup ? 1 : 0);
      ast_data_add_bool(data_type, "answer", cl->tech->answer ? 1 : 0);
      ast_data_add_bool(data_type, "read", cl->tech->read ? 1 : 0);
      ast_data_add_bool(data_type, "write", cl->tech->write ? 1 : 0);
      ast_data_add_bool(data_type, "send_text", cl->tech->send_text ? 1 : 0);
      ast_data_add_bool(data_type, "send_image", cl->tech->send_image ? 1 : 0);
      ast_data_add_bool(data_type, "send_html", cl->tech->send_html ? 1 : 0);
      ast_data_add_bool(data_type, "exception", cl->tech->exception ? 1 : 0);
      ast_data_add_bool(data_type, "bridge", cl->tech->bridge ? 1 : 0);
      ast_data_add_bool(data_type, "early_bridge", cl->tech->early_bridge ? 1 : 0);
      ast_data_add_bool(data_type, "fixup", cl->tech->fixup ? 1 : 0);
      ast_data_add_bool(data_type, "setoption", cl->tech->setoption ? 1 : 0);
      ast_data_add_bool(data_type, "queryoption", cl->tech->queryoption ? 1 : 0);
      ast_data_add_bool(data_type, "write_video", cl->tech->write_video ? 1 : 0);
      ast_data_add_bool(data_type, "write_text", cl->tech->write_text ? 1 : 0);
      ast_data_add_bool(data_type, "bridged_channel", cl->tech->bridged_channel ? 1 : 0);
      ast_data_add_bool(data_type, "func_channel_read", cl->tech->func_channel_read ? 1 : 0);
      ast_data_add_bool(data_type, "func_channel_write", cl->tech->func_channel_write ? 1 : 0);
      ast_data_add_bool(data_type, "get_base_channel", cl->tech->get_base_channel ? 1 : 0);
      ast_data_add_bool(data_type, "set_base_channel", cl->tech->set_base_channel ? 1 : 0);
      ast_data_add_bool(data_type, "get_pvt_uniqueid", cl->tech->get_pvt_uniqueid ? 1 : 0);
      ast_data_add_bool(data_type, "cc_callback", cl->tech->cc_callback ? 1 : 0);

      ast_data_add_codecs(data_type, "capabilities", cl->tech->capabilities);

      if (!ast_data_search_match(search, data_type)) {
         ast_data_remove_node(data_root, data_type);
      }
   }
   AST_RWLIST_UNLOCK(&backends);

   return 0;
}
static int generator_force ( const void *  data) [static]

Definition at line 3083 of file channel.c.

References ast_channel_generator(), ast_channel_generatordata(), ast_channel_generatordata_set(), ast_channel_lock, ast_channel_unlock, ast_channel_writeformat(), ast_deactivate_generator(), ast_debug, ast_format_rate(), chanlist::chan, and ast_generator::generate.

Referenced by ast_activate_generator(), and ast_read_generator_actions().

{
   /* Called if generator doesn't have data */
   void *tmp;
   int res;
   int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL;
   struct ast_channel *chan = (struct ast_channel *)data;

   ast_channel_lock(chan);
   tmp = ast_channel_generatordata(chan);
   ast_channel_generatordata_set(chan, NULL);
   if (ast_channel_generator(chan))
      generate = ast_channel_generator(chan)->generate;
   ast_channel_unlock(chan);

   if (!tmp || !generate)
      return 0;

   res = generate(chan, tmp, 0, ast_format_rate(ast_channel_writeformat(chan)) / 50);

   ast_channel_lock(chan);
   if (ast_channel_generator(chan) && generate == ast_channel_generator(chan)->generate) {
      ast_channel_generatordata_set(chan, tmp);
   }
   ast_channel_unlock(chan);

   if (res) {
      ast_debug(1, "Auto-deactivating generator\n");
      ast_deactivate_generator(chan);
   }

   return 0;
}
static void handle_cause ( int  cause,
int *  outstate 
) [static]

Definition at line 5524 of file channel.c.

References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CONTROL_BUSY, and AST_CONTROL_CONGESTION.

Referenced by __ast_request_and_dial(), and ast_call_forward().

{
   if (outstate) {
      /* compute error and return */
      if (cause == AST_CAUSE_BUSY)
         *outstate = AST_CONTROL_BUSY;
      else if (cause == AST_CAUSE_CONGESTION)
         *outstate = AST_CONTROL_CONGESTION;
      else
         *outstate = 0;
   }
}
static char* handle_cli_core_show_channeltype ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Show details about a channel driver - CLI command.

Definition at line 356 of file channel.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_getformatname_multiple(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_channeltypes(), ast_cli_args::fd, chanlist::tech, and ast_cli_entry::usage.

{
   struct chanlist *cl = NULL;
   char buf[512];

   switch (cmd) {
   case CLI_INIT:
      e->command = "core show channeltype";
      e->usage =
         "Usage: core show channeltype <name>\n"
         "  Show details about the specified channel type, <name>.\n";
      return NULL;
   case CLI_GENERATE:
      return complete_channeltypes(a);
   }

   if (a->argc != 4)
      return CLI_SHOWUSAGE;

   AST_RWLIST_RDLOCK(&backends);

   AST_RWLIST_TRAVERSE(&backends, cl, list) {
      if (!strncasecmp(cl->tech->type, a->argv[3], strlen(cl->tech->type)))
         break;
   }


   if (!cl) {
      ast_cli(a->fd, "\n%s is not a registered channel driver.\n", a->argv[3]);
      AST_RWLIST_UNLOCK(&backends);
      return CLI_FAILURE;
   }

   ast_cli(a->fd,
      "-- Info about channel driver: %s --\n"
      "  Device State: %s\n"
      "    Indication: %s\n"
      "     Transfer : %s\n"
      "  Capabilities: %s\n"
      "   Digit Begin: %s\n"
      "     Digit End: %s\n"
      "    Send HTML : %s\n"
      " Image Support: %s\n"
      "  Text Support: %s\n",
      cl->tech->type,
      (cl->tech->devicestate) ? "yes" : "no",
      (cl->tech->indicate) ? "yes" : "no",
      (cl->tech->transfer) ? "yes" : "no",
      ast_getformatname_multiple(buf, sizeof(buf), cl->tech->capabilities),
      (cl->tech->send_digit_begin) ? "yes" : "no",
      (cl->tech->send_digit_end) ? "yes" : "no",
      (cl->tech->send_html) ? "yes" : "no",
      (cl->tech->send_image) ? "yes" : "no",
      (cl->tech->send_text) ? "yes" : "no"

   );

   AST_RWLIST_UNLOCK(&backends);

   return CLI_SUCCESS;
}
static char* handle_cli_core_show_channeltypes ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Show channel types - CLI command.

Definition at line 290 of file channel.c.

References ast_cli_args::argc, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT, chanlist::tech, and ast_cli_entry::usage.

{
#define FORMAT  "%-15.15s  %-40.40s %-12.12s %-12.12s %-12.12s\n"
   struct chanlist *cl;
   int count_chan = 0;

   switch (cmd) {
   case CLI_INIT:
      e->command = "core show channeltypes";
      e->usage =
         "Usage: core show channeltypes\n"
         "       Lists available channel types registered in your\n"
         "       Asterisk server.\n";
      return NULL;
   case CLI_GENERATE:
      return NULL;
   }

   if (a->argc != 3)
      return CLI_SHOWUSAGE;

   ast_cli(a->fd, FORMAT, "Type", "Description",       "Devicestate", "Indications", "Transfer");
   ast_cli(a->fd, FORMAT, "-----------", "-----------", "-----------", "-----------", "-----------");

   AST_RWLIST_RDLOCK(&backends);
   AST_RWLIST_TRAVERSE(&backends, cl, list) {
      ast_cli(a->fd, FORMAT, cl->tech->type, cl->tech->description,
         (cl->tech->devicestate) ? "yes" : "no",
         (cl->tech->indicate) ? "yes" : "no",
         (cl->tech->transfer) ? "yes" : "no");
      count_chan++;
   }
   AST_RWLIST_UNLOCK(&backends);

   ast_cli(a->fd, "----------\n%d channel drivers registered.\n", count_chan);

   return CLI_SUCCESS;

#undef FORMAT
}
static int internal_deactivate_generator ( struct ast_channel chan,
void *  generator 
) [static]

Definition at line 8803 of file channel.c.

References ast_channel_flags(), ast_channel_generator(), ast_channel_generator_set(), ast_channel_generatordata(), ast_channel_generatordata_set(), ast_channel_lock, ast_channel_name(), ast_channel_set_fd(), ast_channel_unlock, ast_clear_flag, ast_debug, AST_FLAG_WRITE_INT, AST_GENERATOR_FD, ast_settimeout(), and ast_generator::release.

Referenced by ast_channel_stop_silence_generator().

{
   ast_channel_lock(chan);

   if (!ast_channel_generatordata(chan)) {
      ast_debug(1, "Trying to stop silence generator when there is no "
          "generator on '%s'\n", ast_channel_name(chan));
      ast_channel_unlock(chan);
      return 0;
   }
   if (ast_channel_generator(chan) != generator) {
      ast_debug(1, "Trying to stop silence generator when it is not the current "
          "generator on '%s'\n", ast_channel_name(chan));
      ast_channel_unlock(chan);
      return 0;
   }
   if (ast_channel_generator(chan) && ast_channel_generator(chan)->release) {
      ast_channel_generator(chan)->release(chan, ast_channel_generatordata(chan));
   }
   ast_channel_generatordata_set(chan, NULL);
   ast_channel_generator_set(chan, NULL);
   ast_channel_set_fd(chan, AST_GENERATOR_FD, -1);
   ast_clear_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
   ast_settimeout(chan, 0, NULL, NULL);
   ast_channel_unlock(chan);

   return 1;
}
static int attribute_const is_visible_indication ( enum ast_control_frame_type  condition) [static]

Definition at line 4401 of file channel.c.

References _XXX_AST_CONTROL_T38, AST_CONTROL_ANSWER, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_END_OF_Q, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_MCID, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_READ_ACTION, AST_CONTROL_REDIRECTING, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_TRANSFER, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_CONTROL_VIDUPDATE, and AST_CONTROL_WINK.

Referenced by ast_indicate_data().

{
   /* Don't include a default case here so that we get compiler warnings
    * when a new type is added. */

   switch (condition) {
   case AST_CONTROL_PROGRESS:
   case AST_CONTROL_PROCEEDING:
   case AST_CONTROL_VIDUPDATE:
   case AST_CONTROL_SRCUPDATE:
   case AST_CONTROL_SRCCHANGE:
   case AST_CONTROL_RADIO_KEY:
   case AST_CONTROL_RADIO_UNKEY:
   case AST_CONTROL_OPTION:
   case AST_CONTROL_WINK:
   case AST_CONTROL_FLASH:
   case AST_CONTROL_OFFHOOK:
   case AST_CONTROL_TAKEOFFHOOK:
   case AST_CONTROL_ANSWER:
   case AST_CONTROL_HANGUP:
   case AST_CONTROL_CONNECTED_LINE:
   case AST_CONTROL_REDIRECTING:
   case AST_CONTROL_TRANSFER:
   case AST_CONTROL_T38_PARAMETERS:
   case _XXX_AST_CONTROL_T38:
   case AST_CONTROL_CC:
   case AST_CONTROL_READ_ACTION:
   case AST_CONTROL_AOC:
   case AST_CONTROL_END_OF_Q:
   case AST_CONTROL_MCID:
   case AST_CONTROL_UPDATE_RTP_PEER:
   case AST_CONTROL_PVT_CAUSE_CODE:
      break;

   case AST_CONTROL_INCOMPLETE:
   case AST_CONTROL_CONGESTION:
   case AST_CONTROL_BUSY:
   case AST_CONTROL_RINGING:
   case AST_CONTROL_RING:
   case AST_CONTROL_HOLD:
      /* You can hear these */
      return 1;

   case AST_CONTROL_UNHOLD:
      /* This is a special case.  You stop hearing this. */
      break;
   }

   return 0;
}
static struct ast_frame* kill_exception ( struct ast_channel chan) [static, read]

Definition at line 429 of file channel.c.

{
   /* Hangup channel. */
   return NULL;
}
static int kill_fixup ( struct ast_channel oldchan,
struct ast_channel newchan 
) [static]

Definition at line 441 of file channel.c.

{
   /* No problem fixing up the channel. */
   return 0;
}
static int kill_hangup ( struct ast_channel chan) [static]

Definition at line 447 of file channel.c.

References ast_channel_tech_pvt_set().

{
   ast_channel_tech_pvt_set(chan, NULL);
   return 0;
}
static struct ast_frame* kill_read ( struct ast_channel chan) [static, read]

Definition at line 423 of file channel.c.

{
   /* Hangup channel. */
   return NULL;
}
static int kill_write ( struct ast_channel chan,
struct ast_frame frame 
) [static]

Definition at line 435 of file channel.c.

{
   /* Hangup channel. */
   return -1;
}
static void manager_bridge_event ( int  onoff,
int  type,
struct ast_channel c0,
struct ast_channel c1 
) [static]

Send manager event for bridge link and unlink events.

Parameters:
onoffLink/Unlinked
type1 for core, 2 for native
c0first channel in bridge
c1second channel in bridge

Definition at line 7730 of file channel.c.

References ast_channel_caller(), ast_channel_name(), ast_channel_uniqueid(), ast_manager_event_multichan, EVENT_FLAG_CALL, and S_COR.

Referenced by ast_channel_bridge().

{
   struct ast_channel *chans[2] = { c0, c1 };
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a bridge changes between two channels.</synopsis>
         <syntax>
            <parameter name="Bridgestate">
               <enumlist>
                  <enum name="Link"/>
                  <enum name="Unlink"/>
               </enumlist>
            </parameter>
            <parameter name="Bridgetype">
               <enumlist>
                  <enum name="core"/>
                  <enum name="native"/>
               </enumlist>
            </parameter>
         </syntax>
      </managerEventInstance>
   ***/
   ast_manager_event_multichan(EVENT_FLAG_CALL, "Bridge", 2, chans,
      "Bridgestate: %s\r\n"
      "Bridgetype: %s\r\n"
      "Channel1: %s\r\n"
      "Channel2: %s\r\n"
      "Uniqueid1: %s\r\n"
      "Uniqueid2: %s\r\n"
      "CallerID1: %s\r\n"
      "CallerID2: %s\r\n",
      onoff ? "Link" : "Unlink",
      type == 1 ? "core" : "native",
      ast_channel_name(c0), ast_channel_name(c1),
      ast_channel_uniqueid(c0), ast_channel_uniqueid(c1),
      S_COR(ast_channel_caller(c0)->id.number.valid, ast_channel_caller(c0)->id.number.str, ""),
      S_COR(ast_channel_caller(c1)->id.number.valid, ast_channel_caller(c1)->id.number.str, ""));
}
static void masquerade_colp_transfer ( struct ast_channel transferee,
struct xfer_masquerade_ds colp 
) [static]

Definition at line 6764 of file channel.c.

References ast_alloca, ast_channel_queue_connected_line_update(), ast_connected_line_build_data(), AST_CONTROL_READ_ACTION, AST_CONTROL_UNHOLD, AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO, ast_party_id_reset(), ast_queue_control(), ast_queue_control_data(), frame_size, ast_control_read_action_payload::payload_size, ast_party_connected_line::priv, xfer_masquerade_ds::target_held, xfer_masquerade_ds::target_id, and xfer_masquerade_ds::transferee_id.

Referenced by ast_do_masquerade().

{
   struct ast_control_read_action_payload *frame_payload;
   int payload_size;
   int frame_size;
   unsigned char connected_line_data[1024];

   /* Release any hold on the target. */
   if (colp->target_held) {
      ast_queue_control(transferee, AST_CONTROL_UNHOLD);
   }

   /*
    * Since transferee may not actually be bridged to another channel,
    * there is no way for us to queue a frame so that its connected
    * line status will be updated.  Instead, we use the somewhat
    * hackish approach of using a special control frame type that
    * instructs ast_read() to perform a specific action.  In this
    * case, the frame we queue tells ast_read() to call the
    * connected line interception macro configured for transferee.
    */

   /* Reset any earlier private connected id representation */
   ast_party_id_reset(&colp->target_id.priv);
   ast_party_id_reset(&colp->transferee_id.priv);

   payload_size = ast_connected_line_build_data(connected_line_data,
      sizeof(connected_line_data), &colp->target_id, NULL);
   if (payload_size != -1) {
      frame_size = payload_size + sizeof(*frame_payload);
      frame_payload = ast_alloca(frame_size);
      frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO;
      frame_payload->payload_size = payload_size;
      memcpy(frame_payload->payload, connected_line_data, payload_size);
      ast_queue_control_data(transferee, AST_CONTROL_READ_ACTION, frame_payload,
         frame_size);
   }
   /*
    * In addition to queueing the read action frame so that the
    * connected line info on transferee will be updated, we also are
    * going to queue a plain old connected line update on transferee to
    * update the target.
    */
   ast_channel_queue_connected_line_update(transferee, &colp->transferee_id, NULL);
}
static int namedgroup_cmp_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Comparison function used for named group container.

Definition at line 8344 of file channel.c.

References CMP_MATCH, CMP_STOP, and namedgroup_member::name.

Referenced by ast_get_namedgroups().

{
   const struct namedgroup_member *an = obj;
   const struct namedgroup_member *bn = arg;

   return strcmp(an->name, bn->name) ? 0 : CMP_MATCH | CMP_STOP;
}
static int namedgroup_hash_cb ( const void *  obj,
const int  flags 
) [static]

Hashing function used for named group container.

Definition at line 8353 of file channel.c.

References namedgroup_member::hash.

Referenced by ast_get_namedgroups().

{
   const struct namedgroup_member *member = obj;

   return member->hash;
}
static int namedgroup_match ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 8697 of file channel.c.

References ao2_cleanup, ao2_find, CMP_MATCH, CMP_STOP, match(), and OBJ_POINTER.

Referenced by ast_namedgroups_intersect().

{
   void *match;

   match = ao2_find(arg, obj, OBJ_POINTER);
   ao2_cleanup(match);

   return match ? CMP_MATCH | CMP_STOP : 0;
}
static const char* oldest_linkedid ( const char *  a,
const char *  b 
) [static]

Definition at line 6576 of file channel.c.

References ast_strlen_zero().

Referenced by ast_channel_set_linkgroup().

{
   const char *satime, *saseq;
   const char *sbtime, *sbseq;
   const char *dash;

   unsigned int atime, aseq, btime, bseq;

   if (ast_strlen_zero(a))
      return b;

   if (ast_strlen_zero(b))
      return a;

   satime = a;
   sbtime = b;

   /* jump over the system name */
   if ((dash = strrchr(satime, '-'))) {
      satime = dash+1;
   }
   if ((dash = strrchr(sbtime, '-'))) {
      sbtime = dash+1;
   }

   /* the sequence comes after the '.' */
   saseq = strchr(satime, '.');
   sbseq = strchr(sbtime, '.');
   if (!saseq || !sbseq)
      return NULL;
   saseq++;
   sbseq++;

   /* convert it all to integers */
   atime = atoi(satime); /* note that atoi is ignoring the '.' after the time string */
   btime = atoi(sbtime); /* note that atoi is ignoring the '.' after the time string */
   aseq = atoi(saseq);
   bseq = atoi(sbseq);

   /* and finally compare */
   if (atime == btime) {
      return (aseq < bseq) ? a : b;
   }
   else {
      return (atime < btime) ? a : b;
   }
}
static void party_connected_line_copy_transfer ( struct ast_party_connected_line dest,
const struct ast_party_connected_line src 
) [static]

Definition at line 6376 of file channel.c.

References AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER, ast_party_connected_line_copy(), and ast_party_connected_line::source.

Referenced by ast_channel_transfer_masquerade().

{
   struct ast_party_connected_line connected;

   connected = *((struct ast_party_connected_line *) src);
   connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;

   /* Make sure empty strings will be erased. */
   if (!connected.id.name.str) {
      connected.id.name.str = "";
   }
   if (!connected.id.number.str) {
      connected.id.number.str = "";
   }
   if (!connected.id.subaddress.str) {
      connected.id.subaddress.str = "";
   }
   if (!connected.id.tag) {
      connected.id.tag = "";
   }

   ast_party_connected_line_copy(dest, &connected);
}
static int party_id_build_data ( unsigned char *  data,
size_t  datalen,
const struct ast_party_id id,
const char *  label,
const struct ast_party_id_ies ies,
const struct ast_set_party_id update 
) [static]

Definition at line 9200 of file channel.c.

References ast_log(), ast_party_id_presentation(), ast_party_id_ies::combined_presentation, LOG_WARNING, ast_party_id::name, ast_set_party_id::name, ast_party_id_ies::name, ast_party_id::number, ast_set_party_id::number, ast_party_id_ies::number, party_name_build_data(), party_number_build_data(), party_subaddress_build_data(), ast_party_id::subaddress, ast_set_party_id::subaddress, ast_party_id_ies::subaddress, ast_party_id::tag, and ast_party_id_ies::tag.

Referenced by ast_connected_line_build_data(), and ast_redirecting_build_data().

{
   size_t length;
   size_t pos = 0;
   int res;

   /*
    * The size of integer values must be fixed in case the frame is
    * shipped to another machine.
    */

   if (!update || update->name) {
      res = party_name_build_data(data + pos, datalen - pos, &id->name, label,
         &ies->name);
      if (res < 0) {
         return -1;
      }
      pos += res;
   }

   if (!update || update->number) {
      res = party_number_build_data(data + pos, datalen - pos, &id->number, label,
         &ies->number);
      if (res < 0) {
         return -1;
      }
      pos += res;
   }

   if (!update || update->subaddress) {
      res = party_subaddress_build_data(data + pos, datalen - pos, &id->subaddress,
         label, &ies->subaddress);
      if (res < 0) {
         return -1;
      }
      pos += res;
   }

   /* *************** Party id user tag **************************** */
   if (id->tag) {
      length = strlen(id->tag);
      if (datalen < pos + (sizeof(data[0]) * 2) + length) {
         ast_log(LOG_WARNING, "No space left for %s tag\n", label);
         return -1;
      }
      data[pos++] = ies->tag;
      data[pos++] = length;
      memcpy(data + pos, id->tag, length);
      pos += length;
   }

   /* *************** Party id combined presentation *************** */
   if (ies->combined_presentation && (!update || update->number)) {
      int presentation;

      if (!update || update->name) {
         presentation = ast_party_id_presentation(id);
      } else {
         /*
          * We must compromise because not all the information is available
          * to determine a combined presentation value.
          * We will only send the number presentation instead.
          */
         presentation = id->number.presentation;
      }

      if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
         ast_log(LOG_WARNING, "No space left for %s combined presentation\n", label);
         return -1;
      }
      data[pos++] = ies->combined_presentation;
      data[pos++] = 1;
      data[pos++] = presentation;
   }

   return pos;
}
static int party_name_build_data ( unsigned char *  data,
size_t  datalen,
const struct ast_party_name name,
const char *  label,
const struct ast_party_name_ies ies 
) [static]

Definition at line 8971 of file channel.c.

References ast_log(), ast_party_name::char_set, ast_party_name_ies::char_set, LOG_WARNING, ast_party_name::presentation, ast_party_name_ies::presentation, ast_party_name::str, ast_party_name_ies::str, ast_party_name::valid, and ast_party_name_ies::valid.

Referenced by party_id_build_data().

{
   size_t length;
   size_t pos = 0;

   /*
    * The size of integer values must be fixed in case the frame is
    * shipped to another machine.
    */
   if (name->str) {
      length = strlen(name->str);
      if (datalen < pos + (sizeof(data[0]) * 2) + length) {
         ast_log(LOG_WARNING, "No space left for %s name\n", label);
         return -1;
      }
      data[pos++] = ies->str;
      data[pos++] = length;
      memcpy(data + pos, name->str, length);
      pos += length;
   }

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s name char set\n", label);
      return -1;
   }
   data[pos++] = ies->char_set;
   data[pos++] = 1;
   data[pos++] = name->char_set;

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s name presentation\n", label);
      return -1;
   }
   data[pos++] = ies->presentation;
   data[pos++] = 1;
   data[pos++] = name->presentation;

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s name valid\n", label);
      return -1;
   }
   data[pos++] = ies->valid;
   data[pos++] = 1;
   data[pos++] = name->valid;

   return pos;
}
static int party_number_build_data ( unsigned char *  data,
size_t  datalen,
const struct ast_party_number number,
const char *  label,
const struct ast_party_number_ies ies 
) [static]

Definition at line 9045 of file channel.c.

References ast_log(), LOG_WARNING, ast_party_number::plan, ast_party_number_ies::plan, ast_party_number::presentation, ast_party_number_ies::presentation, ast_party_number::str, ast_party_number_ies::str, ast_party_number::valid, and ast_party_number_ies::valid.

Referenced by party_id_build_data().

{
   size_t length;
   size_t pos = 0;

   /*
    * The size of integer values must be fixed in case the frame is
    * shipped to another machine.
    */
   if (number->str) {
      length = strlen(number->str);
      if (datalen < pos + (sizeof(data[0]) * 2) + length) {
         ast_log(LOG_WARNING, "No space left for %s number\n", label);
         return -1;
      }
      data[pos++] = ies->str;
      data[pos++] = length;
      memcpy(data + pos, number->str, length);
      pos += length;
   }

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s numbering plan\n", label);
      return -1;
   }
   data[pos++] = ies->plan;
   data[pos++] = 1;
   data[pos++] = number->plan;

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s number presentation\n", label);
      return -1;
   }
   data[pos++] = ies->presentation;
   data[pos++] = 1;
   data[pos++] = number->presentation;

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s number valid\n", label);
      return -1;
   }
   data[pos++] = ies->valid;
   data[pos++] = 1;
   data[pos++] = number->valid;

   return pos;
}
static int party_subaddress_build_data ( unsigned char *  data,
size_t  datalen,
const struct ast_party_subaddress subaddress,
const char *  label,
const struct ast_party_subaddress_ies ies 
) [static]

Definition at line 9119 of file channel.c.

References ast_log(), LOG_WARNING, ast_party_subaddress::odd_even_indicator, ast_party_subaddress_ies::odd_even_indicator, ast_party_subaddress::str, ast_party_subaddress_ies::str, ast_party_subaddress::type, ast_party_subaddress_ies::type, ast_party_subaddress::valid, and ast_party_subaddress_ies::valid.

Referenced by party_id_build_data().

{
   size_t length;
   size_t pos = 0;

   /*
    * The size of integer values must be fixed in case the frame is
    * shipped to another machine.
    */
   if (subaddress->str) {
      length = strlen(subaddress->str);
      if (datalen < pos + (sizeof(data[0]) * 2) + length) {
         ast_log(LOG_WARNING, "No space left for %s subaddress\n", label);
         return -1;
      }
      data[pos++] = ies->str;
      data[pos++] = length;
      memcpy(data + pos, subaddress->str, length);
      pos += length;
   }

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s type of subaddress\n", label);
      return -1;
   }
   data[pos++] = ies->type;
   data[pos++] = 1;
   data[pos++] = subaddress->type;

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING,
         "No space left for %s subaddress odd-even indicator\n", label);
      return -1;
   }
   data[pos++] = ies->odd_even_indicator;
   data[pos++] = 1;
   data[pos++] = subaddress->odd_even_indicator;

   if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
      ast_log(LOG_WARNING, "No space left for %s subaddress valid\n", label);
      return -1;
   }
   data[pos++] = ies->valid;
   data[pos++] = 1;
   data[pos++] = subaddress->valid;

   return pos;
}
static void plc_ds_destroy ( void *  data) [static]

Definition at line 4869 of file channel.c.

References ast_free, and plc_ds::samples_buf.

{
   struct plc_ds *plc = data;
   ast_free(plc->samples_buf);
   ast_free(plc);
}
static void queue_dtmf_readq ( struct ast_channel chan,
struct ast_frame f 
) [inline, static]

Definition at line 3795 of file channel.c.

References ast_channel_dtmff(), AST_FRAME_DTMF_END, ast_queue_frame(), ast_frame::frametype, ast_frame_subclass::integer, ast_frame::len, and ast_frame::subclass.

Referenced by __ast_read().

{
   struct ast_frame *fr = ast_channel_dtmff(chan);

   fr->frametype = AST_FRAME_DTMF_END;
   fr->subclass.integer = f->subclass.integer;
   fr->len = f->len;

   /* The only time this function will be called is for a frame that just came
    * out of the channel driver.  So, we want to stick it on the tail of the
    * readq. */

   ast_queue_frame(chan, fr);
}
static void report_new_callerid ( struct ast_channel chan) [static]
Precondition:
chan is locked

Definition at line 6724 of file channel.c.

References ast_channel_caller(), ast_channel_name(), ast_channel_uniqueid(), ast_describe_caller_presentation(), ast_manager_event, ast_party_id_presentation(), EVENT_FLAG_CALL, name, and S_COR.

Referenced by ast_channel_set_caller_event(), ast_do_masquerade(), and ast_set_callerid().

{
   int pres;

   pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a channel receives new Caller ID information.</synopsis>
         <syntax>
            <parameter name="CID-CallingPres">
               <para>A description of the Caller ID presentation.</para>
            </parameter>
         </syntax>
      </managerEventInstance>
   ***/
   ast_manager_event(chan, EVENT_FLAG_CALL, "NewCallerid",
      "Channel: %s\r\n"
      "CallerIDNum: %s\r\n"
      "CallerIDName: %s\r\n"
      "Uniqueid: %s\r\n"
      "CID-CallingPres: %d (%s)\r\n",
      ast_channel_name(chan),
      S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
      S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""),
      ast_channel_uniqueid(chan),
      pres,
      ast_describe_caller_presentation(pres)
      );
}
static void send_dtmf_event ( struct ast_channel chan,
const char *  direction,
const char  digit,
const char *  begin,
const char *  end 
) [static]

Definition at line 3709 of file channel.c.

References ast_channel_name(), ast_channel_uniqueid(), ast_manager_event, and EVENT_FLAG_DTMF.

Referenced by __ast_read(), and ast_write().

{
   /*** DOCUMENTATION
      <managerEventInstance>
         <synopsis>Raised when a DTMF digit has started or ended on a channel.</synopsis>
            <syntax>
               <parameter name="Direction">
                  <enumlist>
                     <enum name="Received"/>
                     <enum name="Sent"/>
                  </enumlist>
               </parameter>
               <parameter name="Begin">
                  <enumlist>
                     <enum name="Yes"/>
                     <enum name="No"/>
                  </enumlist>
               </parameter>
               <parameter name="End">
                  <enumlist>
                     <enum name="Yes"/>
                     <enum name="No"/>
                  </enumlist>
               </parameter>
            </syntax>
      </managerEventInstance>
   ***/
   ast_manager_event(chan, EVENT_FLAG_DTMF,
         "DTMF",
         "Channel: %s\r\n"
         "Uniqueid: %s\r\n"
         "Digit: %c\r\n"
         "Direction: %s\r\n"
         "Begin: %s\r\n"
         "End: %s\r\n",
         ast_channel_name(chan), ast_channel_uniqueid(chan), digit, direction, begin, end);
}
static int set_format ( struct ast_channel chan,
struct ast_format_cap cap_set,
struct ast_format rawformat,
struct ast_format format,
const struct set_format_trans_access trans,
const int  direction 
) [static]

Definition at line 5282 of file channel.c.

References ast_best_codec(), ast_channel_generatordata(), ast_channel_lock, ast_channel_name(), ast_channel_nativeformats(), ast_channel_setoption(), ast_channel_unlock, ast_debug, ast_format_cap_set(), ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_copy(), ast_getformatname(), ast_getformatname_multiple(), ast_log(), AST_OPTION_FORMAT_READ, AST_OPTION_FORMAT_WRITE, ast_translator_best_choice(), ast_translator_build_path(), ast_translator_free_path(), generator_write_format_change(), set_format_trans_access::get, LOG_WARNING, and set_format_trans_access::set.

Referenced by ast_set_read_format(), ast_set_read_format_by_id(), ast_set_read_format_from_cap(), ast_set_write_format(), ast_set_write_format_by_id(), and ast_set_write_format_from_cap().

{
   struct ast_trans_pvt *trans_pvt;
   struct ast_format_cap *cap_native = ast_channel_nativeformats(chan);
   struct ast_format best_set_fmt;
   struct ast_format best_native_fmt;
   int res;
   char from[200], to[200];

   ast_best_codec(cap_set, &best_set_fmt);

   /* See if the underlying channel driver is capable of performing transcoding for us */
   if (!ast_channel_setoption(chan, direction ? AST_OPTION_FORMAT_WRITE : AST_OPTION_FORMAT_READ, &best_set_fmt, sizeof(best_set_fmt), 0)) {
      ast_debug(1, "Channel driver natively set channel %s to %s format %s\n", ast_channel_name(chan),
           direction ? "write" : "read", ast_getformatname(&best_set_fmt));

      ast_channel_lock(chan);
      ast_format_copy(format, &best_set_fmt);
      ast_format_copy(rawformat, &best_set_fmt);
      ast_format_cap_set(ast_channel_nativeformats(chan), &best_set_fmt);
      ast_channel_unlock(chan);

      trans_pvt = trans->get(chan);
      if (trans_pvt) {
         ast_translator_free_path(trans_pvt);
         trans->set(chan, NULL);
      }

      /* If there is a generator on the channel, it needs to know about this
       * change if it is the write format. */
      if (direction && ast_channel_generatordata(chan)) {
         generator_write_format_change(chan);
      }
      return 0;
   }

   /* Find a translation path from the native format to one of the desired formats */
   if (!direction) {
      /* reading */
      res = ast_translator_best_choice(cap_set, cap_native, &best_set_fmt, &best_native_fmt);
   } else {
      /* writing */
      res = ast_translator_best_choice(cap_native, cap_set, &best_native_fmt, &best_set_fmt);
   }

   if (res < 0) {
      ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n",
         ast_getformatname_multiple(from, sizeof(from), cap_native),
         ast_getformatname_multiple(to, sizeof(to), cap_set));
      return -1;
   }

   /* Now we have a good choice for both. */
   ast_channel_lock(chan);

   if ((ast_format_cmp(rawformat, &best_native_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
      (ast_format_cmp(format, &best_set_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
      ((ast_format_cmp(rawformat, format) != AST_FORMAT_CMP_NOT_EQUAL) || trans->get(chan))) {
      /* the channel is already in these formats, so nothing to do */
      ast_channel_unlock(chan);
      return 0;
   }

   ast_format_copy(rawformat, &best_native_fmt);
   /* User perspective is fmt */
   ast_format_copy(format, &best_set_fmt);

   /* Free any translation we have right now */
   trans_pvt = trans->get(chan);
   if (trans_pvt) {
      ast_translator_free_path(trans_pvt);
      trans->set(chan, NULL);
   }

   /* Build a translation path from the raw format to the desired format */
   if (ast_format_cmp(format, rawformat) != AST_FORMAT_CMP_NOT_EQUAL) {
      /*
       * If we were able to swap the native format to the format that
       * has been requested, then there is no need to try to build
       * a translation path.
       */
      res = 0;
   } else {
      if (!direction) {
         /* reading */
         trans_pvt = ast_translator_build_path(format, rawformat);
      } else {
         /* writing */
         trans_pvt = ast_translator_build_path(rawformat, format);
      }
      trans->set(chan, trans_pvt);
      res = trans_pvt ? 0 : -1;
   }
   ast_channel_unlock(chan);

   ast_debug(1, "Set channel %s to %s format %s\n",
      ast_channel_name(chan),
      direction ? "write" : "read",
      ast_getformatname(&best_set_fmt));

   /* If there is a generator on the channel, it needs to know about this
    * change if it is the write format. */
   if (direction && ast_channel_generatordata(chan)) {
      generator_write_format_change(chan);
   }
   return res;
}
static int set_security_requirements ( const struct ast_channel requestor,
struct ast_channel out 
) [static]

Definition at line 5856 of file channel.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_setoption(), ast_channel_unlock, AST_OPTION_SECURE_MEDIA, AST_OPTION_SECURE_SIGNALING, ast_datastore::data, ast_secure_call_store::media, secure_call_info, and ast_secure_call_store::signaling.

Referenced by ast_request().

{
   int ops[2][2] = {
      {AST_OPTION_SECURE_SIGNALING, 0},
      {AST_OPTION_SECURE_MEDIA, 0},
   };
   int i;
   struct ast_channel *r = (struct ast_channel *) requestor; /* UGLY */
   struct ast_datastore *ds;

   if (!requestor || !out) {
      return 0;
   }

   ast_channel_lock(r);
   if ((ds = ast_channel_datastore_find(r, &secure_call_info, NULL))) {
      struct ast_secure_call_store *encrypt = ds->data;
      ops[0][1] = encrypt->signaling;
      ops[1][1] = encrypt->media;
   } else {
      ast_channel_unlock(r);
      return 0;
   }
   ast_channel_unlock(r);

   for (i = 0; i < 2; i++) {
      if (ops[i][1]) {
         if (ast_channel_setoption(out, ops[i][0], &ops[i][1], sizeof(ops[i][1]), 0)) {
            /* We require a security feature, but the channel won't provide it */
            return -1;
         }
      } else {
         /* We don't care if we can't clear the option on a channel that doesn't support it */
         ast_channel_setoption(out, ops[i][0], &ops[i][1], sizeof(ops[i][1]), 0);
      }
   }

   return 0;
}
static int should_skip_dtmf ( struct ast_channel chan) [inline, static]

Determine whether or not we should ignore DTMF in the readq.

Definition at line 3813 of file channel.c.

References ast_channel_dtmf_tv(), ast_channel_flags(), AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_MIN_DTMF_GAP, ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), and ast_tvzero().

Referenced by __ast_read().

{
   if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF)) {
      /* We're in the middle of emulating a digit, or DTMF has been
       * explicitly deferred.  Skip this digit, then. */
      return 1;
   }

   if (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
         ast_tvdiff_ms(ast_tvnow(), *ast_channel_dtmf_tv(chan)) < AST_MIN_DTMF_GAP) {
      /* We're not in the middle of a digit, but it hasn't been long enough
       * since the last digit, so we'll have to skip DTMF for now. */
      return 1;
   }

   return 0;
}
static void* silence_generator_alloc ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 8740 of file channel.c.

{
   /* just store the data pointer in the channel structure */
   return data;
}
static int silence_generator_generate ( struct ast_channel chan,
void *  data,
int  len,
int  samples 
) [static]

Definition at line 8751 of file channel.c.

References ast_format_set(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_write(), ast_frame_subclass::format, ast_frame::frametype, ast_frame::samples, and ast_frame::subclass.

{
   short buf[samples];
   struct ast_frame frame = {
      .frametype = AST_FRAME_VOICE,
      .data.ptr = buf,
      .samples = samples,
      .datalen = sizeof(buf),
   };
   ast_format_set(&frame.subclass.format, AST_FORMAT_SLINEAR, 0);

   memset(buf, 0, sizeof(buf));

   if (ast_write(chan, &frame))
      return -1;

   return 0;
}
static void silence_generator_release ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 8746 of file channel.c.

{
   /* nothing to do */
}
static void* tonepair_alloc ( struct ast_channel chan,
void *  params 
) [static]

Definition at line 8185 of file channel.c.

References ast_calloc, ast_channel_flags(), ast_channel_name(), ast_channel_writeformat(), AST_FLAG_WRITE_INT, ast_format_copy(), AST_FORMAT_SLINEAR, ast_log(), ast_set_flag, ast_set_write_format_by_id(), cos, tonepair_def::duration, tonepair_state::duration, tonepair_state::fac1, tonepair_state::fac2, tonepair_def::freq1, tonepair_def::freq2, LOG_WARNING, M_PI, tonepair_state::modulate, tonepair_state::origwfmt, tonepair_release(), tonepair_state::v1_1, tonepair_state::v2_1, tonepair_state::v2_2, tonepair_state::v3_1, tonepair_state::v3_2, and tonepair_def::vol.

{
   struct tonepair_state *ts;
   struct tonepair_def *td = params;

   if (!(ts = ast_calloc(1, sizeof(*ts))))
      return NULL;
   ast_format_copy(&ts->origwfmt, ast_channel_writeformat(chan));
   if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) {
      ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan));
      tonepair_release(NULL, ts);
      ts = NULL;
   } else {
      ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0;
      ts->v1_1 = 0;
      ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
      ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
      ts->v2_1 = 0;
      ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0;
      ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
      ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
      ts->duration = td->duration;
      ts->modulate = 0;
   }
   /* Let interrupts interrupt :) */
   ast_set_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
   return ts;
}
static int tonepair_generator ( struct ast_channel chan,
void *  data,
int  len,
int  samples 
) [static]

Definition at line 8214 of file channel.c.

References ast_format_set(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame::data, tonepair_state::data, ast_frame::datalen, tonepair_state::duration, tonepair_state::f, tonepair_state::fac1, tonepair_state::fac2, ast_frame_subclass::format, ast_frame::frametype, len(), LOG_WARNING, tonepair_state::modulate, ast_frame::offset, tonepair_state::pos, ast_frame::ptr, ast_frame::samples, ast_frame::subclass, tonepair_state::v1_1, tonepair_state::v1_2, tonepair_state::v2_1, tonepair_state::v2_2, tonepair_state::v3_1, and tonepair_state::v3_2.

{
   struct tonepair_state *ts = data;
   int x;

   /* we need to prepare a frame with 16 * timelen samples as we're
    * generating SLIN audio
    */
   len = samples * 2;

   if (len > sizeof(ts->data) / 2 - 1) {
      ast_log(LOG_WARNING, "Can't generate that much data!\n");
      return -1;
   }
   memset(&ts->f, 0, sizeof(ts->f));
   for (x=0;x<len/2;x++) {
      ts->v1_1 = ts->v2_1;
      ts->v2_1 = ts->v3_1;
      ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1;

      ts->v1_2 = ts->v2_2;
      ts->v2_2 = ts->v3_2;
      ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2;
      if (ts->modulate) {
         int p;
         p = ts->v3_2 - 32768;
         if (p < 0) p = -p;
         p = ((p * 9) / 10) + 1;
         ts->data[x] = (ts->v3_1 * p) >> 15;
      } else
         ts->data[x] = ts->v3_1 + ts->v3_2;
   }
   ts->f.frametype = AST_FRAME_VOICE;
   ast_format_set(&ts->f.subclass.format, AST_FORMAT_SLINEAR, 0);
   ts->f.datalen = len;
   ts->f.samples = samples;
   ts->f.offset = AST_FRIENDLY_OFFSET;
   ts->f.data.ptr = ts->data;
   ast_write(chan, &ts->f);
   ts->pos += x;
   if (ts->duration > 0) {
      if (ts->pos >= ts->duration * 8)
         return -1;
   }
   return 0;
}
static void tonepair_release ( struct ast_channel chan,
void *  params 
) [static]

Definition at line 8176 of file channel.c.

References ast_free, ast_set_write_format(), and tonepair_state::origwfmt.

Referenced by tonepair_alloc().

{
   struct tonepair_state *ts = params;

   if (chan)
      ast_set_write_format(chan, &ts->origwfmt);
   ast_free(ts);
}
static void update_bridge_vars ( struct ast_channel c0,
struct ast_channel c1 
) [static]

Definition at line 7769 of file channel.c.

References ast_channel_lock, ast_channel_name(), ast_channel_tech(), ast_channel_unlock, ast_strlen_zero(), pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper().

Referenced by ast_channel_bridge().

{
   const char *c0_name;
   const char *c1_name;
   const char *c0_pvtid = NULL;
   const char *c1_pvtid = NULL;

   ast_channel_lock(c1);
   c1_name = ast_strdupa(ast_channel_name(c1));
   if (ast_channel_tech(c1)->get_pvt_uniqueid) {
      c1_pvtid = ast_strdupa(ast_channel_tech(c1)->get_pvt_uniqueid(c1));
   }
   ast_channel_unlock(c1);

   ast_channel_lock(c0);
   if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) {
      pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1_name);
   }
   if (c1_pvtid) {
      pbx_builtin_setvar_helper(c0, "BRIDGEPVTCALLID", c1_pvtid);
   }
   c0_name = ast_strdupa(ast_channel_name(c0));
   if (ast_channel_tech(c0)->get_pvt_uniqueid) {
      c0_pvtid = ast_strdupa(ast_channel_tech(c0)->get_pvt_uniqueid(c0));
   }
   ast_channel_unlock(c0);

   ast_channel_lock(c1);
   if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) {
      pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0_name);
   }
   if (c0_pvtid) {
      pbx_builtin_setvar_helper(c1, "BRIDGEPVTCALLID", c0_pvtid);
   }
   ast_channel_unlock(c1);
}

Variable Documentation

Kill the channel channel driver technology descriptor.

The purpose of this channel technology is to encourage the channel to hangup as quickly as possible.

Note:
Used by DTMF atxfer and zombie channels.

Definition at line 462 of file channel.c.

void(* ast_moh_cleanup_ptr)(struct ast_channel *) = NULL [static]
int(* ast_moh_start_ptr)(struct ast_channel *, const char *, const char *) = NULL [static]
void(* ast_moh_stop_ptr)(struct ast_channel *) = NULL [static]
struct backends backends [static]
struct causes_map causes[] [static]

Definition at line 165 of file channel.c.

Referenced by ast_cause2str(), ast_str2cause(), and dump_cause().

Initial value:
 {
   .type = "Call Completion",
   .duplicate = channel_cc_params_copy,
   .destroy = channel_cc_params_destroy,
}

Definition at line 11073 of file channel.c.

int chancount [static]

Definition at line 106 of file channel.c.

Referenced by __ast_manager_event_multichan(), and generic_fax_exec().

struct ast_data_entry channel_providers[] [static]
Initial value:
 {
   AST_DATA_ENTRY("/asterisk/core/channels", &channels_provider),
   AST_DATA_ENTRY("/asterisk/core/channeltypes", &channeltypes_provider),
}

Definition at line 8618 of file channel.c.

Initial value:

Definition at line 8604 of file channel.c.

Initial value:

Definition at line 8613 of file channel.c.

struct ast_cli_entry cli_channel[] [static]
Initial value:
 {
   AST_CLI_DEFINE(handle_cli_core_show_channeltypes, "List available channel types"),
   AST_CLI_DEFINE(handle_cli_core_show_channeltype,  "Give more details on that channel type")
}

Definition at line 418 of file channel.c.

Referenced by ast_channels_init(), and channels_shutdown().

unsigned long global_fin

The current value of the debug flags is stored in the two variables global_fin and global_fout (declared in main/channel.c)

Definition at line 108 of file channel.c.

Referenced by handle_core_set_debug_channel().

unsigned long global_fout

Definition at line 108 of file channel.c.

Referenced by handle_core_set_debug_channel().

struct ast_channel_tech null_tech [static]
Initial value:
 {
   .type = "NULL",
   .description = "Null channel (should not see this)",
}

Definition at line 945 of file channel.c.

Referenced by __ast_channel_alloc_ap().

Initial value:
 {
   .type = "plc",
   .destroy = plc_ds_destroy,
}

Definition at line 4876 of file channel.c.

Initial value:

Definition at line 5272 of file channel.c.

Initial value:

Definition at line 5277 of file channel.c.

int shutting_down [static]

Prevent new channel allocation if shutting down.

Definition at line 103 of file channel.c.

Referenced by ast_shutting_down().

Initial value:

Definition at line 8770 of file channel.c.

struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , } [static]

Definition at line 110 of file channel.c.

Referenced by ast_state2str().

struct ast_generator tonepair [static]
Initial value:
 {
   .alloc = tonepair_alloc,
   .release = tonepair_release,
   .generate = tonepair_generator,
}

Definition at line 8261 of file channel.c.

int uniqueint [static]

Definition at line 105 of file channel.c.

Initial value:
 {
   .type = "xfer_colp",
   .destroy = xfer_ds_destroy,
}

Definition at line 6430 of file channel.c.