Fri Jan 18 19:57:56 2013

Asterisk developer's documentation


channel.h File Reference

General Asterisk PBX channel definitions. More...

#include "asterisk/abstract_jb.h"
#include "asterisk/astobj2.h"
#include "asterisk/poll-compat.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/chanvars.h"
#include "asterisk/config.h"
#include "asterisk/lock.h"
#include "asterisk/cdr.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/datastore.h"
#include "asterisk/data.h"
#include "asterisk/channelstate.h"
#include "asterisk/ccss.h"
#include "asterisk/framehook.h"
Include dependency graph for channel.h:

Go to the source code of this file.

Data Structures

struct  ast_bridge_config
 bridge configuration More...
struct  ast_chan_write_info_t
 Structure to handle passing func_channel_write info to channels via setoption. More...
struct  ast_channel
 Main Channel structure associated with a channel. More...
struct  ast_channel_tech
 Structure to describe a channel "technology", ie a channel driver See for examples:. More...
struct  ast_generator
struct  ast_group_info
 channel group info More...
struct  ast_party_caller
 Caller Party information. More...
struct  ast_party_connected_line
 Connected Line/Party information. More...
struct  ast_party_dialed
 Dialed/Called Party information. More...
struct  ast_party_id
 Information needed to identify an endpoint in a call. More...
struct  ast_party_name
 Information needed to specify a name in a call. More...
struct  ast_party_number
 Information needed to specify a number in a call. More...
struct  ast_party_redirecting
 Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call diversion or transfer was invoked. More...
struct  ast_party_subaddress
 Information needed to specify a subaddress in a call. More...
struct  ast_set_party_caller
 Indicate what information in ast_party_caller should be set. More...
struct  ast_set_party_connected_line
 Indicate what information in ast_party_connected_line should be set. More...
struct  ast_set_party_id
 Indicate what information in ast_party_id should be set. More...
struct  ast_set_party_redirecting
 Indicate what information in ast_party_redirecting should be set. More...
struct  outgoing_helper

Defines

#define AST_AGENT_FD   (AST_MAX_FDS-3)
#define AST_ALERT_FD   (AST_MAX_FDS-1)
#define AST_BRIDGE_DTMF_CHANNEL_0   (1 << 0)
 Report DTMF on channel 0.
#define AST_BRIDGE_DTMF_CHANNEL_1   (1 << 1)
 Report DTMF on channel 1.
#define AST_BRIDGE_IGNORE_SIGS   (1 << 4)
 Ignore all signal frames except NULL.
#define AST_BRIDGE_REC_CHANNEL_0   (1 << 2)
 Return all voice frames on channel 0.
#define AST_BRIDGE_REC_CHANNEL_1   (1 << 3)
 Return all voice frames on channel 1.
#define AST_CHAN_WRITE_INFO_T_VERSION   1
 ast_chan_write_info_t version. Must be incremented if structure is changed
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag,...)
 Create a channel structure.
#define ast_channel_lock(chan)   ao2_lock(chan)
#define ast_channel_lock_both(chan1, chan2)
 Lock two channels.
#define AST_CHANNEL_NAME   80
#define ast_channel_ref(c)   ({ ao2_ref(c, +1); (c); })
 Increase channel reference count.
#define ast_channel_trylock(chan)   ao2_trylock(chan)
#define ast_channel_unlock(chan)   ao2_unlock(chan)
#define ast_channel_unref(c)   ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })
 Decrease channel reference count.
#define ast_dummy_channel_alloc()   __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
 Create a fake channel structure.
#define AST_GENERATOR_FD   (AST_MAX_FDS-4)
#define AST_MAX_CONTEXT   80
#define AST_MAX_EXTENSION   80
#define AST_MAX_FDS   10
#define AST_TIMING_FD   (AST_MAX_FDS-2)
#define CHECK_BLOCKING(c)
#define DATASTORE_INHERIT_FOREVER   INT_MAX
#define DEBUGCHAN_FLAG   0x80000000
#define FRAMECOUNT_INC(x)   ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
#define MAX_LANGUAGE   40
#define MAX_MUSICCLASS   80

Typedefs

typedef int(* ast_acf_read2_fn_t )(struct ast_channel *, const char *, char *, struct ast_str **, ssize_t)
 Typedef for a custom read2 function.
typedef int(* ast_acf_read_fn_t )(struct ast_channel *, const char *, char *, char *, size_t)
 Typedef for a custom read function.
typedef int(* ast_acf_write_fn_t )(struct ast_channel *, const char *, char *, const char *)
 Typedef for a custom write function.
typedef unsigned long long ast_group_t

Enumerations

enum  { AST_CHAN_TP_WANTSJITTER = (1 << 0), AST_CHAN_TP_CREATESJITTER = (1 << 1) }
 

ast_channel_tech Properties

More...
enum  {
  AST_FLAG_DEFER_DTMF = (1 << 1), AST_FLAG_WRITE_INT = (1 << 2), AST_FLAG_BLOCKING = (1 << 3), AST_FLAG_ZOMBIE = (1 << 4),
  AST_FLAG_EXCEPTION = (1 << 5), AST_FLAG_MOH = (1 << 6), AST_FLAG_SPYING = (1 << 7), AST_FLAG_NBRIDGE = (1 << 8),
  AST_FLAG_IN_AUTOLOOP = (1 << 9), AST_FLAG_OUTGOING = (1 << 10), AST_FLAG_IN_DTMF = (1 << 12), AST_FLAG_EMULATE_DTMF = (1 << 13),
  AST_FLAG_END_DTMF_ONLY = (1 << 14), AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), AST_FLAG_MASQ_NOSTREAM = (1 << 16), AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
  AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18), AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20), AST_FLAG_DISABLE_DEVSTATE_CACHE = (1 << 21)
}
 

ast_channel flags

More...
enum  {
  AST_FEATURE_PLAY_WARNING = (1 << 0), AST_FEATURE_REDIRECT = (1 << 1), AST_FEATURE_DISCONNECT = (1 << 2), AST_FEATURE_ATXFER = (1 << 3),
  AST_FEATURE_AUTOMON = (1 << 4), AST_FEATURE_PARKCALL = (1 << 5), AST_FEATURE_AUTOMIXMON = (1 << 6), AST_FEATURE_NO_H_EXTEN = (1 << 7),
  AST_FEATURE_WARNING_ACTIVE = (1 << 8)
}
 

ast_bridge_config flags

More...
enum  {
  AST_SOFTHANGUP_DEV = (1 << 0), AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), AST_SOFTHANGUP_SHUTDOWN = (1 << 2), AST_SOFTHANGUP_TIMEOUT = (1 << 3),
  AST_SOFTHANGUP_APPUNLOAD = (1 << 4), AST_SOFTHANGUP_EXPLICIT = (1 << 5), AST_SOFTHANGUP_UNBRIDGE = (1 << 6), AST_SOFTHANGUP_ALL = (0xFFFFFFFF)
}
enum  ast_bridge_result { AST_BRIDGE_COMPLETE = 0, AST_BRIDGE_FAILED = -1, AST_BRIDGE_FAILED_NOWARN = -2, AST_BRIDGE_RETRY = -3 }
enum  ast_channel_adsicpe { AST_ADSI_UNKNOWN, AST_ADSI_AVAILABLE, AST_ADSI_UNAVAILABLE, AST_ADSI_OFFHOOKONLY }
enum  AST_PARTY_CHAR_SET {
  AST_PARTY_CHAR_SET_UNKNOWN = 0, AST_PARTY_CHAR_SET_ISO8859_1 = 1, AST_PARTY_CHAR_SET_WITHDRAWN = 2, AST_PARTY_CHAR_SET_ISO8859_2 = 3,
  AST_PARTY_CHAR_SET_ISO8859_3 = 4, AST_PARTY_CHAR_SET_ISO8859_4 = 5, AST_PARTY_CHAR_SET_ISO8859_5 = 6, AST_PARTY_CHAR_SET_ISO8859_7 = 7,
  AST_PARTY_CHAR_SET_ISO10646_BMPSTRING = 8, AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING = 9
}
enum  ast_t38_state {
  T38_STATE_UNAVAILABLE, T38_STATE_UNKNOWN, T38_STATE_NEGOTIATING, T38_STATE_REJECTED,
  T38_STATE_NEGOTIATED
}
 

Possible T38 states on channels.

More...
enum  channelreloadreason { CHANNEL_MODULE_LOAD, CHANNEL_MODULE_RELOAD, CHANNEL_CLI_RELOAD, CHANNEL_MANAGER_RELOAD }
 

Channel reload reasons for manager events at load or reload of configuration.

More...

Functions

int __ast_answer (struct ast_channel *chan, unsigned int delay, int cdr_answer)
 Answer a channel, with a selectable delay before returning.
struct ast_channel
*attribute_malloc 
__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.
struct ast_channel * __ast_dummy_channel_alloc (const char *file, int line, const char *function)
struct ast_channel * __ast_request_and_dial (const char *type, format_t format, const struct ast_channel *requestor, void *data, int timeout, int *reason, 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.
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
static int ast_add_fd (struct pollfd *pfd, int fd)
 if fd is a valid descriptor, set *pfd with the descriptor
int ast_answer (struct ast_channel *chan)
 Answer a channel.
int ast_autoservice_ignore (struct ast_channel *chan, enum ast_frame_type ftype)
 Ignore certain frame types.
int ast_autoservice_start (struct ast_channel *chan)
 Automatically service a channel for us...
int ast_autoservice_stop (struct ast_channel *chan)
 Stop servicing a channel for us...
void ast_begin_shutdown (int hangup)
format_t ast_best_codec (format_t fmts)
 Pick the best audio codec.
struct ast_channel * ast_bridged_channel (struct ast_channel *chan)
 Find bridged channel.
int ast_call (struct ast_channel *chan, char *addr, int timeout)
 Make a call.
struct ast_channel * ast_call_forward (struct ast_channel *caller, struct ast_channel *orig, int *timeout, format_t format, 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 state) attribute_pure
 Gives the string form of a given cause code.
void ast_change_name (struct ast_channel *chan, const char *newname)
 Change channel name.
int 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.
struct ast_channel * ast_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.
void ast_channel_clear_softhangup (struct ast_channel *chan, int flag)
 Clear a set of softhangup flags from a channel.
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 the settings of when to hang a channel up.
int ast_channel_connected_line_macro (struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int caller, int frame)
 Run a connected line interception macro and update a channel's connected line information.
int ast_channel_data_add_structure (struct ast_data *tree, struct ast_channel *chan, int add_bridged)
 Insert into an astdata tree, the channel structure.
int ast_channel_data_cmp_structure (const struct ast_data_search *tree, struct ast_channel *chan, const char *structure_name)
 Compare to channel structures using the data api.
int ast_channel_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore)
 Add a datastore to a channel.
struct ast_datastore
*attribute_malloc 
ast_channel_datastore_alloc (const struct ast_datastore_info *info, const char *uid)
 Create a channel data store object.
struct ast_datastore * ast_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)
 Defers DTMF so that you only read things like hangups and audio.
int ast_channel_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Bridge two channels together (early).
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_params * ast_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.
static enum ast_t38_state ast_channel_get_t38_state (struct ast_channel *chan)
 Retrieves the current T38 state of a channel.
void ast_channel_inherit_variables (const struct ast_channel *parent, struct ast_channel *child)
 Inherits channel variable from parent to child channel.
int ast_channel_make_compatible (struct ast_channel *c0, struct ast_channel *c1)
 Makes two channel formats compatible.
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 *channel, 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_register (const struct ast_channel_tech *tech)
 Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.
struct ast_channel * ast_channel_release (struct ast_channel *chan)
 Unlink and release reference to a channel.
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.
int ast_channel_sendurl (struct ast_channel *channel, 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 linked id between chan and peer
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 *channel, 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 hang a channel up.
struct ast_silence_generator * ast_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 *channel)
 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_unregister (const struct ast_channel_tech *tech)
 Unregister a channel technology.
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.
struct ast_variable * ast_channeltype_list (void)
 return an ast_variable list of channeltypes
int ast_check_hangup (struct ast_channel *chan)
 Check 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 *chan)
 Start masquerading a channel.
static int ast_fdisset (struct pollfd *pfds, int fd, int maximum, int *start)
 Helper function for migrating select to poll.
struct ast_channel_tech * ast_get_channel_tech (const char *name)
 Get a channel technology structure by name.
ast_group_t ast_get_group (const char *s)
int ast_hangup (struct ast_channel *chan)
 Hang up 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.
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_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.
int ast_party_id_presentation (const struct ast_party_id *id)
 Determine the overall presentation value for the given party.
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.
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)
char * ast_print_group (char *buf, int buflen, ast_group_t group)
 print call- and pickup groups into buffer
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 with payload.
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 *f)
 Queue one or more frames to a channel's frame queue.
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.
int ast_queue_hangup (struct ast_channel *chan)
 Queue a hangup frame.
int ast_queue_hangup_with_cause (struct ast_channel *chan, int cause)
 Queue a hangup frame with hangupcause set.
int ast_raw_answer (struct ast_channel *chan, int cdr_answer)
 Answer a channel.
struct ast_frame * ast_read (struct ast_channel *chan)
 Reads a frame.
struct ast_frame * ast_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 rtimeout, char *enders)
 Reads multiple digits.
int ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int rtimeout, 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_channel * ast_request (const char *type, format_t format, const struct ast_channel *requestor, void *data, int *status)
 Requests a channel.
struct ast_channel * ast_request_and_dial (const char *type, format_t format, const struct ast_channel *requestor, void *data, int timeout, int *reason, const char *cid_num, const char *cid_name)
 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 for a specified amount of time, looking for hangups.
int ast_safe_sleep_conditional (struct ast_channel *chan, int ms, int(*cond)(void *), void *data)
 Wait for a specified amount of time, looking for hangups and a condition argument.
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.
int ast_set_read_format (struct ast_channel *chan, format_t format)
 Sets read format on channel chan 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, format_t format)
 Sets write format on channel chan Set write format for channel to whichever component of "format" is best.
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_shutting_down (void)
 Returns non-zero if Asterisk is being shut down.
int ast_softhangup (struct ast_channel *chan, int reason)
 Softly hangup up a channel.
int ast_softhangup_nolock (struct ast_channel *chan, int reason)
 Softly hangup up a channel (no channel lock).
const char * ast_state2str (enum ast_channel_state)
 Gives the string form of a given channel state.
int ast_str2cause (const char *name) attribute_pure
 Convert the string form of a cause code to a 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 channel (if supported).
char * ast_transfercapability2str (int transfercapability) attribute_const
 Gives the string form of a given transfer capability.
int ast_undestroyed_channels (void)
int ast_waitfor (struct ast_channel *chan, int ms)
 Wait for input on a channel.
struct ast_channel * ast_waitfor_n (struct ast_channel **chan, 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)
 Waits for input on an fd.
struct ast_channel * ast_waitfor_nandfds (struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
 Waits for activity on a group of channels.
int ast_waitfordigit (struct ast_channel *c, int ms)
 Waits for a digit.
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.
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.
int ast_write_text (struct ast_channel *chan, struct ast_frame *frame)
 Write text 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 *frame)
 Write video frame to a channel This function writes the given frame to the indicated channel.
const char * channelreloadreason2txt (enum channelreloadreason reason)
 Convert enum channelreloadreason to text string for manager event.



struct ast_channel * ast_channel_get_by_exten (const char *exten, const char *context)
 Find a channel by extension and context.
struct ast_channel * ast_channel_get_by_name (const char *name)
 Find a channel by name.
struct ast_channel * ast_channel_get_by_name_prefix (const char *name, size_t name_len)
 Find a channel by a name prefix.
struct ast_channel_iterator * ast_channel_iterator_all_new (void)
 Create a new channel iterator.
struct ast_channel_iterator * ast_channel_iterator_by_exten_new (const char *exten, const char *context)
 Create a new channel iterator based on extension.
struct ast_channel_iterator * ast_channel_iterator_by_name_new (const char *name, size_t name_len)
 Create a new channel iterator based on name.
struct ast_channel_iterator * ast_channel_iterator_destroy (struct ast_channel_iterator *i)
 Destroy a channel iterator.
struct ast_channel * ast_channel_iterator_next (struct ast_channel_iterator *i)
 Get the next channel for a channel iterator.

Variables

struct ast_channel_tech ast_kill_tech
unsigned long global_fin
unsigned long global_fout

Detailed Description

General Asterisk PBX channel definitions.

See also:

Definition in file channel.h.


Define Documentation

#define AST_AGENT_FD   (AST_MAX_FDS-3)

used by agents for pass through

Definition at line 165 of file channel.h.

Referenced by agent_read().

#define AST_ALERT_FD   (AST_MAX_FDS-1)

used for alertpipe

Definition at line 163 of file channel.h.

Referenced by __ast_channel_alloc_ap().

#define AST_BRIDGE_DTMF_CHANNEL_0   (1 << 0)
#define AST_BRIDGE_DTMF_CHANNEL_1   (1 << 1)
#define AST_BRIDGE_IGNORE_SIGS   (1 << 4)

Ignore all signal frames except NULL.

Definition at line 1929 of file channel.h.

Referenced by ast_generic_bridge(), iax2_bridge(), local_bridge_loop(), and remote_bridge_loop().

#define AST_BRIDGE_REC_CHANNEL_0   (1 << 2)

Return all voice frames on channel 0.

Definition at line 1925 of file channel.h.

#define AST_BRIDGE_REC_CHANNEL_1   (1 << 3)

Return all voice frames on channel 1.

Definition at line 1927 of file channel.h.

#define AST_CHAN_WRITE_INFO_T_VERSION   1

ast_chan_write_info_t version. Must be incremented if structure is changed

Definition at line 484 of file channel.h.

Referenced by func_channel_write(), and local_setoption().

#define ast_channel_alloc ( needqueue,
state,
cid_num,
cid_name,
acctcode,
exten,
context,
linkedid,
amaflag,
...   ) 
Value:
__ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, \
             __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)

Create a channel structure.

Return values:
NULL failure
non-NULL successfully 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 1143 of file channel.h.

Referenced by __oh323_new(), action_bridge(), agent_new(), alsa_new(), ast_async_goto(), ast_iax2_new(), ast_pbx_outgoing_exten(), bridge_exec(), bridge_request(), builtin_atxfer(), check_goto_on_transfer(), console_new(), dahdi_new(), do_notify(), gtalk_new(), iax_park(), jingle_new(), local_new(), masq_park_call(), mgcp_new(), misdn_new(), multicast_rtp_request(), nbs_new(), oss_new(), phone_new(), sip_new(), sip_park(), skinny_new(), and unistim_new().

#define ast_channel_lock ( chan   )     ao2_lock(chan)

Definition at line 2454 of file channel.h.

Referenced by __analog_handle_event(), __ast_answer(), __ast_pbx_run(), __ast_queue_frame(), __ast_read(), __ast_request_and_dial(), __dahdi_exception(), __oh323_destroy(), __sip_destroy(), _macro_exec(), _while_exec(), acf_cc_read(), acf_cc_write(), acf_fetch(), acf_odbc_read(), action_add_agi_cmd(), action_coreshowchannels(), action_hangup(), action_redirect(), action_status(), action_timeout(), add_features_datastore(), add_to_agi(), agent_indicate(), agent_lock_owner(), analog_exception(), app_exec(), ast_activate_generator(), ast_async_goto(), ast_audiohook_attach(), ast_audiohook_detach_source(), ast_audiohook_remove(), ast_audiohook_set_mute(), ast_autochan_destroy(), ast_autochan_setup(), ast_autoservice_start(), ast_autoservice_stop(), ast_bridge_call(), ast_bridge_end_dtmf(), ast_bridge_timelimit(), ast_call(), ast_call_forward(), 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_cel_report_event(), ast_change_name(), ast_channel_clear_softhangup(), ast_channel_cmp_cb(), ast_channel_connected_line_macro(), ast_channel_destructor(), ast_channel_queryoption(), ast_channel_redirecting_macro(), ast_channel_set_caller(), ast_channel_set_caller_event(), ast_channel_set_connected_line(), ast_channel_set_redirecting(), ast_channel_setoption(), ast_check_hangup_locked(), ast_complete_channels(), ast_deactivate_generator(), ast_dial_join(), ast_do_masquerade(), ast_do_pickup(), ast_eivr_getvariable(), ast_explicit_goto(), ast_handle_cc_control_frame(), ast_hangup(), ast_ignore_cc(), ast_indicate_data(), ast_odbc_retrieve_transaction_obj(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_raw_answer(), ast_read_generator_actions(), ast_rtp_instance_bridge(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), ast_rtp_instance_make_compatible(), ast_safe_sleep_conditional(), ast_senddigit_begin(), ast_senddigit_end(), ast_sendtext(), ast_set_callerid(), ast_set_cc_interfaces_chanvar(), ast_set_hangupsource(), ast_settimeout(), ast_setup_cc_recall_datastore(), ast_softhangup(), ast_stopstream(), ast_str_retrieve_variable(), ast_transfer(), ast_udptl_bridge(), ast_var_channel_bridge(), ast_var_channels_table(), ast_waitfor_nandfds(), ast_write(), auth_exec(), awesome_locking(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_blindtransfer(), calendar_event_read(), calendar_query_exec(), calendar_query_result_exec(), call_forward_inherit(), callerid_read(), callerid_write(), cb_events(), cc_build_payload(), cc_interfaces_datastore_init(), cdr_read(), cdr_write(), channel_set_debug(), channel_spy(), check_bridge(), check_goto_on_transfer(), clear_caller(), clear_dialed_interfaces(), common_exec(), conf_run(), conf_start_moh(), confbridge_exec(), connectedline_read(), connectedline_write(), create_dynamic_parkinglot(), crement_function_read(), dahdi_bridge(), dahdi_handle_dtmf(), dahdi_handle_event(), data_channels_provider_handler(), dial_exec_full(), disable_jack_hook(), do_forward(), dundi_query_read(), dundi_result_read(), enable_jack_hook(), end_bridge_callback(), enum_query_read(), enum_result_read(), exec_odbcfinish(), feature_check(), feature_interpret(), feature_request_and_dial(), find_by_mark(), find_by_part(), find_calling_channel(), find_channel_by_group(), find_conf_realtime(), find_details(), find_or_create_details(), find_transaction(), findmeexec(), frame_trace_helper(), func_channel_read(), func_channel_write_real(), func_channels_read(), func_header_read(), func_inheritance_write(), func_mute_write(), function_agent(), function_sipchaninfo_read(), generator_force(), generic_fax_exec(), get_agi_cmd(), get_cid_name(), gosub_exec(), handle_chanlist(), handle_cli_agi_add_cmd(), handle_cli_mixmonitor(), handle_invite_replaces(), handle_request_bye(), handle_request_refer(), handle_showchan(), handle_softhangup(), import_ch(), import_helper(), init_jack_data(), internal_deactivate_generator(), jack_hook_callback(), leave_voicemail(), listfilter(), local_ast_moh_stop(), local_call(), local_hangup(), local_queryoption(), local_queue_frame(), local_read(), local_setoption(), local_write(), login_exec(), lua_get_state(), manage_parked_call(), manager_mutestream(), mark_transaction_active(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_attempt_transfer(), misdn_update_caller_id(), moh_files_generator(), morsecode_exec(), mute_callback(), my_handle_dtmf(), notify_new_message(), park_call_full(), parkandannounce_exec(), parked_call_exec(), pbx_builtin_background(), pbx_builtin_getvar_helper(), pbx_builtin_gotoiftime(), pbx_builtin_pushvar_helper(), pbx_builtin_serialize_variables(), pbx_builtin_setamaflags(), pbx_builtin_setvar_helper(), peek_read(), pickup_by_exten(), pickup_by_name_cb(), pitchshift_helper(), pop_exec(), process_sdp(), queue_exec(), receivefax_exec(), redirecting_read(), redirecting_write(), release_transaction(), report_fax_status(), retrydial_exec(), return_exec(), run_agi(), sendfax_exec(), sendtext_exec(), set_ext_pri(), set_format(), set_security_requirements(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), shared_read(), shared_write(), sip_addheader(), sip_dtmfmode(), sip_new(), sip_pvt_lock_full(), sip_read(), sip_removeheader(), sip_set_rtp_peer(), sip_set_udptl_peer(), smdi_msg_read(), smdi_msg_retrieve_read(), softhangup_exec(), speech_background(), speex_read(), speex_write(), srv_datastore_setup(), srv_query_read(), srv_result_read(), stackpeek_read(), start_monitor_action(), start_monitor_exec(), state_notify_build_xml(), stop_mixmonitor_exec(), transmit_invite(), try_calling(), update_bridge_vars(), volume_write(), and wait_for_answer().

#define ast_channel_lock_both ( chan1,
chan2   ) 
#define AST_CHANNEL_NAME   80
#define ast_channel_ref ( c   )     ({ ao2_ref(c, +1); (c); })
#define ast_channel_trylock ( chan   )     ao2_trylock(chan)
#define ast_channel_unlock ( chan   )     ao2_unlock(chan)

Definition at line 2455 of file channel.h.

Referenced by __analog_handle_event(), __ast_answer(), __ast_channel_masquerade(), __ast_pbx_run(), __ast_queue_frame(), __ast_read(), __ast_request_and_dial(), __dahdi_exception(), __oh323_destroy(), __oh323_rtp_create(), __sip_autodestruct(), __sip_destroy(), _macro_exec(), _while_exec(), acf_cc_read(), acf_cc_write(), acf_fetch(), acf_odbc_read(), action_add_agi_cmd(), action_agents(), action_coreshowchannels(), action_hangup(), action_redirect(), action_status(), action_timeout(), add_features_datastore(), add_to_agi(), agent_indicate(), agent_lock_owner(), agent_logoff(), agent_read(), agents_data_provider_get(), agents_show(), agents_show_online(), alsa_call(), analog_attempt_transfer(), analog_exception(), analog_hangup(), app_exec(), ast_activate_generator(), ast_async_goto(), ast_audiohook_attach(), ast_audiohook_detach_source(), ast_audiohook_remove(), ast_audiohook_set_mute(), ast_autochan_destroy(), ast_autochan_setup(), ast_autoservice_start(), ast_autoservice_stop(), ast_bridge_call(), ast_bridge_end_dtmf(), ast_bridge_timelimit(), ast_call(), ast_call_forward(), 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_cel_report_event(), ast_change_name(), ast_channel_clear_softhangup(), ast_channel_cmp_cb(), ast_channel_connected_line_macro(), ast_channel_destructor(), ast_channel_queryoption(), ast_channel_redirecting_macro(), ast_channel_set_caller(), ast_channel_set_caller_event(), ast_channel_set_connected_line(), ast_channel_set_redirecting(), ast_channel_setoption(), ast_check_hangup_locked(), ast_complete_channels(), ast_deactivate_generator(), ast_dial_join(), ast_do_masquerade(), ast_do_pickup(), ast_eivr_getvariable(), ast_explicit_goto(), ast_handle_cc_control_frame(), ast_hangup(), ast_ignore_cc(), ast_indicate_data(), ast_odbc_retrieve_transaction_obj(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pickup_call(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_raw_answer(), ast_read_generator_actions(), ast_rtp_instance_bridge(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), ast_rtp_instance_make_compatible(), ast_safe_sleep_conditional(), ast_senddigit_begin(), ast_senddigit_end(), ast_sendtext(), ast_set_callerid(), ast_set_cc_interfaces_chanvar(), ast_set_hangupsource(), ast_settimeout(), ast_setup_cc_recall_datastore(), ast_softhangup(), ast_stopstream(), ast_str_retrieve_variable(), ast_transfer(), ast_udptl_bridge(), ast_var_channel_bridge(), ast_var_channels_table(), ast_waitfor_nandfds(), ast_write(), attempt_transfer(), auth_exec(), auto_congest(), awesome_locking(), bridge_play_sounds(), bridge_queue_hangup(), bridge_write(), builtin_atxfer(), builtin_automixmonitor(), builtin_blindtransfer(), calendar_event_read(), calendar_query_exec(), calendar_query_result_exec(), call_forward_inherit(), callerid_read(), callerid_write(), cb_events(), cc_build_payload(), cc_interfaces_datastore_init(), cdr_read(), cdr_write(), channel_set_debug(), channel_spy(), check_bridge(), check_goto_on_transfer(), check_rtp_timeout(), cleanup_connection(), clear_caller(), clear_dialed_interfaces(), common_exec(), conf_run(), conf_start_moh(), confbridge_exec(), connectedline_read(), connectedline_write(), console_answer(), console_hangup(), console_sendtext(), create_dynamic_parkinglot(), crement_function_read(), dahdi_bridge(), dahdi_handle_dtmf(), dahdi_handle_event(), dahdi_queue_frame(), dahdi_softhangup_all(), data_channels_provider_handler(), dial_exec_full(), dial_transfer(), dialog_unlink_all(), disable_jack_hook(), do_bridge_masquerade(), do_forward(), dundi_query_read(), dundi_result_read(), enable_jack_hook(), end_bridge_callback(), enum_query_read(), enum_result_read(), exec_odbcfinish(), fast_originate(), feature_check(), feature_interpret(), feature_request_and_dial(), find_by_mark(), find_by_part(), find_calling_channel(), find_channel_by_group(), find_conf_realtime(), find_details(), find_or_create_details(), find_transaction(), findmeexec(), frame_trace_helper(), func_channel_read(), func_channel_write_real(), func_channels_read(), func_header_read(), func_inheritance_write(), func_mute_write(), function_agent(), function_sipchaninfo_read(), generator_force(), generic_fax_exec(), get_agi_cmd(), get_cid_name(), gosub_exec(), handle_chanlist(), handle_cli_agi_add_cmd(), handle_cli_mixmonitor(), handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_refer(), handle_showchan(), handle_softhangup(), hangup_connection(), iax2_destroy(), iax2_queue_control_data(), iax2_queue_frame(), iax2_queue_hangup(), import_ch(), import_helper(), init_jack_data(), internal_deactivate_generator(), jack_hook_callback(), leave_voicemail(), listfilter(), local_ast_moh_stop(), local_attended_transfer(), local_bridge_loop(), local_call(), local_hangup(), local_queryoption(), local_queue_frame(), local_read(), local_setoption(), local_write(), login_exec(), lua_get_state(), manage_parked_call(), manager_mutestream(), mark_transaction_active(), mgcp_pktcgate_remove(), mgcp_queue_frame(), mgcp_queue_hangup(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_attempt_transfer(), misdn_update_caller_id(), moh_files_generator(), morsecode_exec(), mute_callback(), my_handle_dtmf(), notify_new_message(), oh323_rtp_read(), oh323_simulate_dtmf_end(), park_call_full(), parkandannounce_exec(), parked_call_exec(), pbx_builtin_background(), pbx_builtin_getvar_helper(), pbx_builtin_gotoiftime(), pbx_builtin_pushvar_helper(), pbx_builtin_serialize_variables(), pbx_builtin_setamaflags(), pbx_builtin_setvar_helper(), peek_read(), pickup_by_channel(), pickup_by_exten(), pickup_by_group(), pickup_by_mark(), pickup_by_name_cb(), pickup_by_part(), pitchshift_helper(), pop_exec(), proc_session_timer(), process_sdp(), queue_exec(), receive_digit(), receivefax_exec(), redirecting_read(), redirecting_write(), reinvite_timeout(), release_chan(), release_chan_early(), release_transaction(), remote_bridge_loop(), remote_hold(), report_fax_status(), retrans_pkt(), retrydial_exec(), return_exec(), ring_entry(), run_agi(), schedule_delivery(), send_provisional_keepalive_full(), sendfax_exec(), sendtext_exec(), set_ext_pri(), set_format(), set_hangup_source_and_cause(), set_security_requirements(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_rtp_connection(), setup_transfer_datastore(), shared_read(), shared_write(), sip_addheader(), sip_dtmfmode(), sip_hangup(), sip_new(), sip_pvt_lock_full(), sip_queue_hangup_cause(), sip_read(), sip_reinvite_retry(), sip_removeheader(), sip_request_call(), sip_set_rtp_peer(), sip_set_udptl_peer(), smdi_msg_read(), smdi_msg_retrieve_read(), socket_process(), softhangup_exec(), speech_background(), speex_read(), speex_write(), srv_datastore_setup(), srv_query_read(), srv_result_read(), stackpeek_read(), start_monitor_action(), start_monitor_exec(), state_notify_build_xml(), stop_mixmonitor_exec(), transmit_invite(), try_calling(), update_bridge_vars(), update_state(), volume_write(), wait_for_answer(), and wakeup_sub().

#define ast_channel_unref ( c   )     ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })

Decrease channel reference count.

Parameters:
c the channel
Return values:
NULL always
Since:
1.8

Definition at line 2490 of file channel.h.

Referenced by __ast_channel_alloc_ap(), __ast_dummy_channel_alloc(), __sip_autodestruct(), acf_odbc_read(), acf_odbc_write(), action_add_agi_cmd(), action_agents(), action_aocmessage(), action_atxfer(), action_bridge(), action_coreshowchannels(), action_getvar(), action_hangup(), action_redirect(), action_sendtext(), action_setvar(), action_status(), action_timeout(), agent_hangup(), agent_lock_owner(), agent_logoff(), agent_read(), agents_data_provider_get(), agents_show(), agents_show_online(), ast_add_extension2_lockopt(), ast_async_goto_by_name(), ast_autochan_destroy(), ast_autochan_new_channel(), ast_bridge_call(), ast_cel_fabricate_channel_from_event(), ast_cel_report_event(), ast_channel_release(), ast_complete_channels(), ast_do_masquerade(), ast_hangup(), ast_parse_device_state(), ast_pbx_outgoing_cdr_failed(), ast_pickup_call(), ast_set_hangupsource(), ast_str_substitute_variables_full(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), asyncgoto_exec(), awesome_locking(), bridge_exec(), change_monitor_action(), check_bridge(), cli_odbc_read(), cli_odbc_write(), common_exec(), custom_log(), data_channels_provider_handler(), dialog_unlink_all(), do_pause_or_unpause(), func_channels_read(), func_mchan_read(), func_mchan_write(), handle_chanlist(), handle_channelstatus(), handle_cli_agi_add_cmd(), handle_cli_mixmonitor(), handle_core_set_debug_channel(), handle_getvariablefull(), handle_hangup(), handle_incoming(), handle_invite_replaces(), handle_redirect(), handle_request_do(), handle_request_refer(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), handle_softhangup(), import_helper(), local_attended_transfer(), local_call(), local_hangup(), local_queryoption(), local_queue_frame(), local_setoption(), make_email_file(), manager_log(), manager_mute_mixmonitor(), manager_mutestream(), manager_optimize_away(), manager_park(), manager_play_dtmf(), next_channel(), park_call_full(), pbx_builtin_importvar(), pbx_substitute_variables_helper_full(), pickup_by_channel(), pickup_by_exten(), pickup_by_group(), pickup_by_mark(), pickup_by_part(), reinvite_timeout(), rotate_file(), send_provisional_keepalive_full(), senddtmf_exec(), sendmail(), sendpage(), set_hangup_source_and_cause(), shared_read(), shared_write(), sip_pickup(), sip_pickup_thread(), sip_pvt_lock_full(), sip_queue_hangup_cause(), socket_process(), softhangup_exec(), start_monitor_action(), state_notify_build_xml(), stop_monitor_action(), syslog_log(), and write_cdr().

 
#define ast_dummy_channel_alloc (  )     __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)

Create a fake channel structure.

Return values:
NULL failure
non-NULL successfully 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 1164 of file channel.h.

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

#define AST_GENERATOR_FD   (AST_MAX_FDS-4)

used by generator

Definition at line 166 of file channel.h.

Referenced by __ast_read(), ast_deactivate_generator(), ast_do_masquerade(), and internal_deactivate_generator().

#define AST_MAX_CONTEXT   80
#define AST_MAX_EXTENSION   80
#define AST_MAX_FDS   10
#define AST_TIMING_FD   (AST_MAX_FDS-2)

used for timingfd

Definition at line 164 of file channel.h.

Referenced by __ast_channel_alloc_ap(), __ast_read(), agent_read(), ast_do_masquerade(), and ast_settimeout().

#define CHECK_BLOCKING ( c   ) 

Definition at line 2415 of file channel.h.

Referenced by ast_sendtext(), ast_waitfor_nandfds(), ast_write(), dahdi_read(), and phone_read().

#define DATASTORE_INHERIT_FOREVER   INT_MAX
#define DEBUGCHAN_FLAG   0x80000000

The high bit of the frame count is used as a debug marker, so increments of the counters must be done with care. Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.

Definition at line 648 of file channel.h.

Referenced by __ast_read(), ast_write(), channel_set_debug(), handle_core_set_debug_channel(), handle_showchan(), and serialize_showchan().

#define FRAMECOUNT_INC ( x   )     ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )

Definition at line 651 of file channel.h.

Referenced by __ast_read(), and ast_write().

#define MAX_LANGUAGE   40

Max length of the language setting

Definition at line 138 of file channel.h.

Referenced by ast_readconfig().

#define MAX_MUSICCLASS   80

Max length of the music class setting

Definition at line 139 of file channel.h.


Typedef Documentation

typedef int(* ast_acf_read2_fn_t)(struct ast_channel *, const char *, char *, struct ast_str **, ssize_t)

Typedef for a custom read2 function.

Definition at line 476 of file channel.h.

typedef int(* ast_acf_read_fn_t)(struct ast_channel *, const char *, char *, char *, size_t)

Typedef for a custom read function.

Definition at line 473 of file channel.h.

typedef int(* ast_acf_write_fn_t)(struct ast_channel *, const char *, char *, const char *)

Typedef for a custom write function.

Definition at line 479 of file channel.h.

typedef unsigned long long ast_group_t

Definition at line 175 of file channel.h.


Enumeration Type Documentation

anonymous enum

ast_channel_tech Properties

Enumerator:
AST_CHAN_TP_WANTSJITTER 

Channels have this property if they can accept input with jitter; i.e. most VoIP channels.

AST_CHAN_TP_CREATESJITTER 

Channels have this property if they can create jitter; i.e. most VoIP channels.

Definition at line 878 of file channel.h.

00878      {
00879    /*!
00880      * \brief Channels have this property if they can accept input with jitter;
00881     * i.e. most VoIP channels
00882     */
00883    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00884    /*!
00885      * \brief Channels have this property if they can create jitter;
00886     * i.e. most VoIP channels
00887     */
00888    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00889 };

anonymous enum

ast_channel flags

Enumerator:
AST_FLAG_DEFER_DTMF 

Queue incoming DTMF, to be released when this flag is turned off

AST_FLAG_WRITE_INT 

write should be interrupt generator

AST_FLAG_BLOCKING 

a thread is blocking on this channel

AST_FLAG_ZOMBIE 

This is a zombie channel

AST_FLAG_EXCEPTION 

There is an exception pending

AST_FLAG_MOH 

Listening to moh XXX anthm promises me this will disappear XXX

AST_FLAG_SPYING 

This channel is spying on another channel

AST_FLAG_NBRIDGE 

This channel is in a native bridge

AST_FLAG_IN_AUTOLOOP 

the channel is in an auto-incrementing dialplan processor, so when ->priority is set, it will get incremented before finding the next priority to run

AST_FLAG_OUTGOING 

This is an outgoing call

AST_FLAG_IN_DTMF 

A DTMF_BEGIN frame has been read from this channel, but not yet an END

AST_FLAG_EMULATE_DTMF 

A DTMF_END was received when not IN_DTMF, so the length of the digit is currently being emulated

AST_FLAG_END_DTMF_ONLY 

This is set to tell the channel not to generate DTMF begin frames, and to instead only generate END frames.

AST_FLAG_ANSWERED_ELSEWHERE 

Flag to show channels that this call is hangup due to the fact that the call was indeed answered, but in another channel

AST_FLAG_MASQ_NOSTREAM 

This flag indicates that on a masquerade, an active stream should not be carried over

AST_FLAG_BRIDGE_HANGUP_RUN 

This flag indicates that the hangup exten was run when the bridge terminated, a message aimed at preventing a subsequent hangup exten being run at the pbx_run level

AST_FLAG_BRIDGE_HANGUP_DONT 

This flag indicates that the hangup exten should NOT be run when the bridge terminates, this will allow the hangup in the pbx loop to be run instead.

AST_FLAG_DISABLE_WORKAROUNDS 

Disable certain workarounds. This reintroduces certain bugs, but allows some non-traditional dialplans (like AGI) to continue to function.

AST_FLAG_DISABLE_DEVSTATE_CACHE 

Disable device state event caching. This allows allows channel drivers to selectively prevent device state events from being cached by certain channels such as anonymous calls which have no persistent represenatation that can be tracked.

Definition at line 892 of file channel.h.

00892      {
00893    /*! Queue incoming DTMF, to be released when this flag is turned off */
00894    AST_FLAG_DEFER_DTMF =    (1 << 1),
00895    /*! write should be interrupt generator */
00896    AST_FLAG_WRITE_INT =     (1 << 2),
00897    /*! a thread is blocking on this channel */
00898    AST_FLAG_BLOCKING =      (1 << 3),
00899    /*! This is a zombie channel */
00900    AST_FLAG_ZOMBIE =        (1 << 4),
00901    /*! There is an exception pending */
00902    AST_FLAG_EXCEPTION =     (1 << 5),
00903    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00904    AST_FLAG_MOH =           (1 << 6),
00905    /*! This channel is spying on another channel */
00906    AST_FLAG_SPYING =        (1 << 7),
00907    /*! This channel is in a native bridge */
00908    AST_FLAG_NBRIDGE =       (1 << 8),
00909    /*! the channel is in an auto-incrementing dialplan processor,
00910     *  so when ->priority is set, it will get incremented before
00911     *  finding the next priority to run */
00912    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00913    /*! This is an outgoing call */
00914    AST_FLAG_OUTGOING =      (1 << 10),
00915    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00916    AST_FLAG_IN_DTMF =       (1 << 12),
00917    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
00918     *  currently being emulated */
00919    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00920    /*! This is set to tell the channel not to generate DTMF begin frames, and
00921     *  to instead only generate END frames. */
00922    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00923    /*! Flag to show channels that this call is hangup due to the fact that the call
00924        was indeed answered, but in another channel */
00925    AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
00926    /*! This flag indicates that on a masquerade, an active stream should not
00927     *  be carried over */
00928    AST_FLAG_MASQ_NOSTREAM = (1 << 16),
00929    /*! This flag indicates that the hangup exten was run when the bridge terminated,
00930     *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
00931     *  level */
00932    AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
00933    /*! This flag indicates that the hangup exten should NOT be run when the
00934     *  bridge terminates, this will allow the hangup in the pbx loop to be run instead.
00935     *  */
00936    AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18),
00937    /*! Disable certain workarounds.  This reintroduces certain bugs, but allows
00938     *  some non-traditional dialplans (like AGI) to continue to function.
00939     */
00940    AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
00941    /*! Disable device state event caching.  This allows allows channel
00942     * drivers to selectively prevent device state events from being cached
00943     * by certain channels such as anonymous calls which have no persistent
00944     * represenatation that can be tracked.
00945     */
00946    AST_FLAG_DISABLE_DEVSTATE_CACHE = (1 << 21),
00947 };

anonymous enum

ast_bridge_config flags

Enumerator:
AST_FEATURE_PLAY_WARNING 
AST_FEATURE_REDIRECT 
AST_FEATURE_DISCONNECT 
AST_FEATURE_ATXFER 
AST_FEATURE_AUTOMON 
AST_FEATURE_PARKCALL 
AST_FEATURE_AUTOMIXMON 
AST_FEATURE_NO_H_EXTEN 
AST_FEATURE_WARNING_ACTIVE 

Definition at line 950 of file channel.h.

00950      {
00951    AST_FEATURE_PLAY_WARNING = (1 << 0),
00952    AST_FEATURE_REDIRECT =     (1 << 1),
00953    AST_FEATURE_DISCONNECT =   (1 << 2),
00954    AST_FEATURE_ATXFER =       (1 << 3),
00955    AST_FEATURE_AUTOMON =      (1 << 4),
00956    AST_FEATURE_PARKCALL =     (1 << 5),
00957    AST_FEATURE_AUTOMIXMON =   (1 << 6),
00958    AST_FEATURE_NO_H_EXTEN =   (1 << 7),
00959    AST_FEATURE_WARNING_ACTIVE = (1 << 8),
00960 };

anonymous enum
Enumerator:
AST_SOFTHANGUP_DEV 

Soft hangup requested by device or other internal reason. Actual hangup needed.

AST_SOFTHANGUP_ASYNCGOTO 

Used to break the normal frame flow so an async goto can be done instead of actually hanging up.

AST_SOFTHANGUP_SHUTDOWN 

Soft hangup requested by system shutdown. Actual hangup needed.

AST_SOFTHANGUP_TIMEOUT 

Used to break the normal frame flow after a timeout so an implicit async goto can be done to the 'T' exten if it exists instead of actually hanging up. If the exten does not exist then actually hangup.

AST_SOFTHANGUP_APPUNLOAD 

Soft hangup requested by application/channel-driver being unloaded. Actual hangup needed.

AST_SOFTHANGUP_EXPLICIT 

Soft hangup requested by non-associated party. Actual hangup needed.

AST_SOFTHANGUP_UNBRIDGE 

Used to break a bridge so the channel can be spied upon instead of actually hanging up.

AST_SOFTHANGUP_ALL 

All softhangup flags.

This can be used as an argument to ast_channel_softhangup_clear to clear all softhangup flags from a channel.

Definition at line 998 of file channel.h.

00998      {
00999    /*!
01000     * Soft hangup requested by device or other internal reason.
01001     * Actual hangup needed.
01002     */
01003    AST_SOFTHANGUP_DEV =       (1 << 0),
01004    /*!
01005     * Used to break the normal frame flow so an async goto can be
01006     * done instead of actually hanging up.
01007     */
01008    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
01009    /*!
01010     * Soft hangup requested by system shutdown.  Actual hangup
01011     * needed.
01012     */
01013    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
01014    /*!
01015     * Used to break the normal frame flow after a timeout so an
01016     * implicit async goto can be done to the 'T' exten if it exists
01017     * instead of actually hanging up.  If the exten does not exist
01018     * then actually hangup.
01019     */
01020    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
01021    /*!
01022     * Soft hangup requested by application/channel-driver being
01023     * unloaded.  Actual hangup needed.
01024     */
01025    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
01026    /*!
01027     * Soft hangup requested by non-associated party.  Actual hangup
01028     * needed.
01029     */
01030    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
01031    /*!
01032     * Used to break a bridge so the channel can be spied upon
01033     * instead of actually hanging up.
01034     */
01035    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
01036 
01037 
01038    /*!
01039     * \brief All softhangup flags.
01040     *
01041     * This can be used as an argument to ast_channel_softhangup_clear
01042     * to clear all softhangup flags from a channel.
01043     */
01044    AST_SOFTHANGUP_ALL =       (0xFFFFFFFF)
01045 };

Enumerator:
AST_BRIDGE_COMPLETE 
AST_BRIDGE_FAILED 
AST_BRIDGE_FAILED_NOWARN 
AST_BRIDGE_RETRY 

Definition at line 168 of file channel.h.

00168                        {
00169    AST_BRIDGE_COMPLETE = 0,
00170    AST_BRIDGE_FAILED = -1,
00171    AST_BRIDGE_FAILED_NOWARN = -2,
00172    AST_BRIDGE_RETRY = -3,
00173 };

Enumerator:
AST_ADSI_UNKNOWN 
AST_ADSI_AVAILABLE 
AST_ADSI_UNAVAILABLE 
AST_ADSI_OFFHOOKONLY 

Definition at line 659 of file channel.h.

Party name character set enumeration values (values from Q.SIG)

Enumerator:
AST_PARTY_CHAR_SET_UNKNOWN 
AST_PARTY_CHAR_SET_ISO8859_1 
AST_PARTY_CHAR_SET_WITHDRAWN 
AST_PARTY_CHAR_SET_ISO8859_2 
AST_PARTY_CHAR_SET_ISO8859_3 
AST_PARTY_CHAR_SET_ISO8859_4 
AST_PARTY_CHAR_SET_ISO8859_5 
AST_PARTY_CHAR_SET_ISO8859_7 
AST_PARTY_CHAR_SET_ISO10646_BMPSTRING 
AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING 

Definition at line 192 of file channel.h.

Possible T38 states on channels.

Enumerator:
T38_STATE_UNAVAILABLE 

T38 is unavailable on this channel or disabled by configuration

T38_STATE_UNKNOWN 

The channel supports T38 but the current status is unknown

T38_STATE_NEGOTIATING 

T38 is being negotiated

T38_STATE_REJECTED 

Remote side has rejected our offer

T38_STATE_NEGOTIATED 

T38 established

Definition at line 669 of file channel.h.

00669                    {
00670    T38_STATE_UNAVAILABLE,  /*!< T38 is unavailable on this channel or disabled by configuration */
00671    T38_STATE_UNKNOWN,   /*!< The channel supports T38 but the current status is unknown */
00672    T38_STATE_NEGOTIATING,  /*!< T38 is being negotiated */
00673    T38_STATE_REJECTED,  /*!< Remote side has rejected our offer */
00674    T38_STATE_NEGOTIATED,   /*!< T38 established */
00675 };

Channel reload reasons for manager events at load or reload of configuration.

Enumerator:
CHANNEL_MODULE_LOAD 
CHANNEL_MODULE_RELOAD 
CHANNEL_CLI_RELOAD 
CHANNEL_MANAGER_RELOAD 

Definition at line 1049 of file channel.h.


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:
chan channel to answer
delay maximum amount of time to wait for incoming media
cdr_answer flag 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:
0 on success
non-zero on failure

Definition at line 2978 of file channel.c.

References ast_channel::_state, ast_channel_lock, 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().

02979 {
02980    int res = 0;
02981    enum ast_channel_state old_state;
02982 
02983    old_state = chan->_state;
02984    if ((res = ast_raw_answer(chan, cdr_answer))) {
02985       return res;
02986    }
02987 
02988    switch (old_state) {
02989    case AST_STATE_RINGING:
02990    case AST_STATE_RING:
02991       /* wait for media to start flowing, but don't wait any longer
02992        * than 'delay' or 500 milliseconds, whichever is longer
02993        */
02994       do {
02995          AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
02996          struct ast_frame *cur, *new;
02997          int timeout_ms = MAX(delay, 500);
02998          unsigned int done = 0;
02999          struct timeval start;
03000 
03001          AST_LIST_HEAD_INIT_NOLOCK(&frames);
03002 
03003          start = ast_tvnow();
03004          for (;;) {
03005             int ms = ast_remaining_ms(start, timeout_ms);
03006             ms = ast_waitfor(chan, ms);
03007             if (ms < 0) {
03008                ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno));
03009                res = -1;
03010                break;
03011             }
03012             if (ms == 0) {
03013                ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500));
03014                break;
03015             }
03016             cur = ast_read(chan);
03017             if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
03018                     (cur->subclass.integer == AST_CONTROL_HANGUP))) {
03019                if (cur) {
03020                   ast_frfree(cur);
03021                }
03022                res = -1;
03023                ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name);
03024                break;
03025             }
03026 
03027             if ((new = ast_frisolate(cur)) != cur) {
03028                ast_frfree(cur);
03029             }
03030 
03031             AST_LIST_INSERT_HEAD(&frames, new, frame_list);
03032 
03033             /* if a specific delay period was requested, continue
03034              * until that delay has passed. don't stop just because
03035              * incoming media has arrived.
03036              */
03037             if (delay) {
03038                continue;
03039             }
03040 
03041             switch (new->frametype) {
03042                /* all of these frametypes qualify as 'media' */
03043             case AST_FRAME_VOICE:
03044             case AST_FRAME_VIDEO:
03045             case AST_FRAME_TEXT:
03046             case AST_FRAME_DTMF_BEGIN:
03047             case AST_FRAME_DTMF_END:
03048             case AST_FRAME_IMAGE:
03049             case AST_FRAME_HTML:
03050             case AST_FRAME_MODEM:
03051                done = 1;
03052                break;
03053             case AST_FRAME_CONTROL:
03054             case AST_FRAME_IAX:
03055             case AST_FRAME_NULL:
03056             case AST_FRAME_CNG:
03057                break;
03058             }
03059 
03060             if (done) {
03061                break;
03062             }
03063          }
03064 
03065          if (res == 0) {
03066             ast_channel_lock(chan);
03067             while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
03068                ast_queue_frame_head(chan, cur);
03069                ast_frfree(cur);
03070             }
03071             ast_channel_unlock(chan);
03072          }
03073       } while (0);
03074       break;
03075    default:
03076       break;
03077    }
03078 
03079    return res;
03080 }

struct ast_channel* attribute_malloc __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:
NULL failure
non-NULL successfully 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 1362 of file channel.c.

References __ast_channel_alloc_ap().

01368 {
01369    va_list ap1, ap2;
01370    struct ast_channel *result;
01371 
01372    va_start(ap1, name_fmt);
01373    va_start(ap2, name_fmt);
01374    result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
01375                linkedid, amaflag, file, line, function, name_fmt, ap1, ap2);
01376    va_end(ap1);
01377    va_end(ap2);
01378 
01379    return result;
01380 }

struct ast_channel* __ast_dummy_channel_alloc ( const char *  file,
int  line,
const char *  function 
) [read]

Definition at line 1385 of file channel.c.

References __ao2_alloc_debug(), ast_channel::alertpipe, ao2_alloc, ARRAY_LEN, ast_channel_unref, ast_dummy_channel_destructor(), AST_LIST_HEAD_INIT_NOLOCK, ast_string_field_init, ast_channel::fds, ast_channel::timingfd, and ast_channel::varshead.

01389 {
01390    struct ast_channel *tmp;
01391    struct varshead *headp;
01392    int x;
01393 
01394 #if defined(REF_DEBUG)
01395    tmp = __ao2_alloc_debug(sizeof(*tmp), ast_dummy_channel_destructor, "dummy channel",
01396       file, line, function, 1);
01397 #elif defined(__AST_DEBUG_MALLOC)
01398    tmp = __ao2_alloc_debug(sizeof(*tmp), ast_dummy_channel_destructor, "dummy channel",
01399       file, line, function, 0);
01400 #else
01401    tmp = ao2_alloc(sizeof(*tmp), ast_dummy_channel_destructor);
01402 #endif
01403    if (!tmp) {
01404       /* Dummy channel structure allocation failure. */
01405       return NULL;
01406    }
01407 
01408    if ((ast_string_field_init(tmp, 128))) {
01409       return ast_channel_unref(tmp);
01410    }
01411 
01412    /*
01413     * Init file descriptors to unopened state just in case
01414     * autoservice is called on the channel or something tries to
01415     * read a frame from it.
01416     */
01417    tmp->timingfd = -1;
01418    for (x = 0; x < ARRAY_LEN(tmp->alertpipe); ++x) {
01419       tmp->alertpipe[x] = -1;
01420    }
01421    for (x = 0; x < ARRAY_LEN(tmp->fds); ++x) {
01422       tmp->fds[x] = -1;
01423    }
01424 #ifdef HAVE_EPOLL
01425    tmp->epfd = -1;
01426 #endif
01427 
01428    headp = &tmp->varshead;
01429    AST_LIST_HEAD_INIT_NOLOCK(headp);
01430 
01431    return tmp;
01432 }

struct ast_channel* __ast_request_and_dial ( const char *  type,
format_t  format,
const struct ast_channel *  requestor,
void *  data,
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:
type type of channel to request
format requested channel format
requestor channel requesting data
data data to pass to the channel requester
timeout maximum amount of time to wait for an answer
reason why unsuccessful (if unsuccessful)
cid_num Caller-ID Number
cid_name Caller-ID Name (ascii)
oh Outgoing 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 5407 of file channel.c.

References ast_channel::_state, 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_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_lock_both, 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_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_copy_string(), 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(), cause, ast_channel::cdr, outgoing_helper::cid_name, outgoing_helper::cid_num, ast_channel::connected, ast_channel::context, outgoing_helper::context, ast_channel::exten, outgoing_helper::exten, ast_frame::frametype, handle_cause(), ast_channel::hangupcause, 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, ast_channel::priority, outgoing_helper::priority, 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().

05408 {
05409    int dummy_outstate;
05410    int cause = 0;
05411    struct ast_channel *chan;
05412    int res = 0;
05413    int last_subclass = 0;
05414    struct ast_party_connected_line connected;
05415    
05416    if (outstate)
05417       *outstate = 0;
05418    else
05419       outstate = &dummy_outstate;   /* make outstate always a valid pointer */
05420 
05421    chan = ast_request(type, format, requestor, data, &cause);
05422    if (!chan) {
05423       ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
05424       handle_cause(cause, outstate);
05425       return NULL;
05426    }
05427 
05428    if (oh) {
05429       if (oh->vars) {
05430          ast_set_variables(chan, oh->vars);
05431       }
05432       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
05433          /*
05434           * Use the oh values instead of the function parameters for the
05435           * outgoing CallerID.
05436           */
05437          cid_num = oh->cid_num;
05438          cid_name = oh->cid_name;
05439       }
05440       if (oh->parent_channel) {
05441          /* Safely inherit variables and datastores from the parent channel. */
05442          ast_channel_lock_both(oh->parent_channel, chan);
05443          ast_channel_inherit_variables(oh->parent_channel, chan);
05444          ast_channel_datastore_inherit(oh->parent_channel, chan);
05445          ast_channel_unlock(oh->parent_channel);
05446          ast_channel_unlock(chan);
05447       }
05448       if (oh->account) {
05449          ast_channel_lock(chan);
05450          ast_cdr_setaccount(chan, oh->account);
05451          ast_channel_unlock(chan);
05452       }
05453    }
05454 
05455    /*
05456     * I seems strange to set the CallerID on an outgoing call leg
05457     * to whom we are calling, but this function's callers are doing
05458     * various Originate methods.  This call leg goes to the local
05459     * user.  Once the local user answers, the dialplan needs to be
05460     * able to access the CallerID from the CALLERID function as if
05461     * the local user had placed this call.
05462     */
05463    ast_set_callerid(chan, cid_num, cid_name, cid_num);
05464 
05465    ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED);
05466    ast_party_connected_line_set_init(&connected, &chan->connected);
05467    if (cid_num) {
05468       connected.id.number.valid = 1;
05469       connected.id.number.str = (char *) cid_num;
05470       connected.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
05471    }
05472    if (cid_name) {
05473       connected.id.name.valid = 1;
05474       connected.id.name.str = (char *) cid_name;
05475       connected.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
05476    }
05477    ast_channel_set_connected_line(chan, &connected, NULL);
05478 
05479    if (ast_call(chan, data, 0)) {   /* ast_call failed... */
05480       ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
05481    } else {
05482       struct timeval start = ast_tvnow();
05483       res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
05484       while (timeout && chan->_state != AST_STATE_UP) {
05485          struct ast_frame *f;
05486          int ms = ast_remaining_ms(start, timeout);
05487 
05488          res = ast_waitfor(chan, ms);
05489          if (res == 0) { /* timeout, treat it like ringing */
05490             *outstate = AST_CONTROL_RINGING;
05491             break;
05492          }
05493          if (res < 0) /* error or done */
05494             break;
05495          if (!ast_strlen_zero(chan->call_forward)) {
05496             if (!(chan = ast_call_forward(NULL, chan, NULL, format, oh, outstate))) {
05497                return NULL;
05498             }
05499             continue;
05500          }
05501 
05502          f = ast_read(chan);
05503          if (!f) {
05504             *outstate = AST_CONTROL_HANGUP;
05505             res = 0;
05506             break;
05507          }
05508          if (f->frametype == AST_FRAME_CONTROL) {
05509             switch (f->subclass.integer) {
05510             case AST_CONTROL_RINGING:  /* record but keep going */
05511                *outstate = f->subclass.integer;
05512                break;
05513 
05514             case AST_CONTROL_BUSY:
05515                ast_cdr_busy(chan->cdr);
05516                *outstate = f->subclass.integer;
05517                timeout = 0;
05518                break;
05519 
05520             case AST_CONTROL_INCOMPLETE:
05521                ast_cdr_failed(chan->cdr);
05522                *outstate = AST_CONTROL_CONGESTION;
05523                timeout = 0;
05524                break;
05525 
05526             case AST_CONTROL_CONGESTION:
05527                ast_cdr_failed(chan->cdr);
05528                *outstate = f->subclass.integer;
05529                timeout = 0;
05530                break;
05531 
05532             case AST_CONTROL_ANSWER:
05533                ast_cdr_answer(chan->cdr);
05534                *outstate = f->subclass.integer;
05535                timeout = 0;      /* trick to force exit from the while() */
05536                break;
05537 
05538             /* Ignore these */
05539             case AST_CONTROL_PROGRESS:
05540             case AST_CONTROL_PROCEEDING:
05541             case AST_CONTROL_HOLD:
05542             case AST_CONTROL_UNHOLD:
05543             case AST_CONTROL_VIDUPDATE:
05544             case AST_CONTROL_SRCUPDATE:
05545             case AST_CONTROL_SRCCHANGE:
05546             case AST_CONTROL_CONNECTED_LINE:
05547             case AST_CONTROL_REDIRECTING:
05548             case AST_CONTROL_CC:
05549             case -1:       /* Ignore -- just stopping indications */
05550                break;
05551 
05552             default:
05553                ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass.integer);
05554             }
05555             last_subclass = f->subclass.integer;
05556          }
05557          ast_frfree(f);
05558       }
05559    }
05560 
05561    /* Final fixups */
05562    if (oh) {
05563       if (!ast_strlen_zero(oh->context))
05564          ast_copy_string(chan->context, oh->context, sizeof(chan->context));
05565       if (!ast_strlen_zero(oh->exten))
05566          ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
05567       if (oh->priority) 
05568          chan->priority = oh->priority;
05569    }
05570    if (chan->_state == AST_STATE_UP)
05571       *outstate = AST_CONTROL_ANSWER;
05572 
05573    if (res <= 0) {
05574       ast_channel_lock(chan);
05575       if (AST_CONTROL_RINGING == last_subclass) {
05576          chan->hangupcause = AST_CAUSE_NO_ANSWER;
05577       }
05578       if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) {
05579          ast_cdr_init(chan->cdr, chan);
05580       }
05581       if (chan->cdr) {
05582          char tmp[256];
05583 
05584          snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data);
05585          ast_cdr_setapp(chan->cdr, "Dial", tmp);
05586          ast_cdr_update(chan);
05587          ast_cdr_start(chan->cdr);
05588          ast_cdr_end(chan->cdr);
05589          /* If the cause wasn't handled properly */
05590          if (ast_cdr_disposition(chan->cdr, chan->hangupcause)) {
05591             ast_cdr_failed(chan->cdr);
05592          }
05593       }
05594       ast_channel_unlock(chan);
05595       ast_hangup(chan);
05596       chan = NULL;
05597    }
05598    return chan;
05599 }

int ast_activate_generator ( struct ast_channel *  chan,
struct ast_generator *  gen,
void *  params 
)

Activate a given generator

Definition at line 3136 of file channel.c.

References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), ast_channel::generator, generator_force(), ast_channel::generatordata, and ast_generator::release.

Referenced by app_exec(), ast_channel_start_silence_generator(), ast_linear_stream(), ast_playtones_start(), ast_tonepair_start(), channel_spy(), eivr_comm(), local_ast_moh_start(), old_milliwatt_exec(), and transmit_audio().

03137 {
03138    int res = 0;
03139 
03140    ast_channel_lock(chan);
03141    if (chan->generatordata) {
03142       if (chan->generator && chan->generator->release)
03143          chan->generator->release(chan, chan->generatordata);
03144       chan->generatordata = NULL;
03145    }
03146    if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) {
03147       res = -1;
03148    }
03149    if (!res) {
03150       ast_settimeout(chan, 50, generator_force, chan);
03151       chan->generator = gen;
03152    }
03153    ast_channel_unlock(chan);
03154 
03155    ast_prod(chan);
03156 
03157    return res;
03158 }

int ast_active_channels ( void   ) 

returns number of active/allocated channels

Returns:
number of channels available for lookup

Definition at line 844 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().

00845 {
00846    return channels ? ao2_container_count(channels) : 0;
00847 }

static int ast_add_fd ( struct pollfd *  pfd,
int  fd 
) [inline, static]

if fd is a valid descriptor, set *pfd with the descriptor

Returns:
Return 1 (not -1!) if added, 0 otherwise (so we can add the return value to the index into the array)

Definition at line 2378 of file channel.h.

Referenced by ast_waitfor_nandfds().

02379 {
02380    pfd->fd = fd;
02381    pfd->events = POLLIN | POLLPRI;
02382    return fd >= 0;
02383 }

int ast_answer ( struct ast_channel *  chan  ) 

Answer a channel.

Parameters:
chan channel 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:
0 on success
non-zero on failure

Definition at line 3082 of file channel.c.

References __ast_answer().

Referenced by action_bridge(), agi_exec_full(), alarmreceiver_exec(), answer_trunk_chan(), app_exec(), ast_control_streamfile(), ast_do_pickup(), ast_pickup_call(), auth_exec(), background_detect_exec(), bridge_exec(), builtin_parkcall(), common_exec(), conf_exec(), 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(), 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(), waitfor_exec(), and zapateller_exec().

03083 {
03084    return __ast_answer(chan, 0, 1);
03085 }

int ast_autoservice_ignore ( struct ast_channel *  chan,
enum ast_frame_type  ftype 
)

Ignore certain frame types.

Note:
Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames while a channel is in autoservice and queue them up when taken out of autoservice. When this is not desireable, this API may be used to cause the channel to ignore those frametypes after the channel is put into autoservice, but before autoservice is stopped.
Return values:
0 success
-1 channel is not in autoservice

Definition at line 306 of file autoservice.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, asent::chan, asent::ignore_frame_types, and asent::list.

Referenced by builtin_automixmonitor(), feature_exec_app(), and play_message_on_chan().

00307 {
00308    struct asent *as;
00309    int res = -1;
00310 
00311    AST_LIST_LOCK(&aslist);
00312    AST_LIST_TRAVERSE(&aslist, as, list) {
00313       if (as->chan == chan) {
00314          res = 0;
00315          as->ignore_frame_types |= (1 << ftype);
00316          break;
00317       }
00318    }
00319    AST_LIST_UNLOCK(&aslist);
00320    return res;
00321 }

int ast_autoservice_start ( struct ast_channel *  chan  ) 

Automatically service a channel for us...

Return values:
0 success
-1 failure, or the channel is already being autoserviced

Definition at line 178 of file autoservice.c.

References as_cond, ast_calloc, ast_channel_lock, ast_channel_unlock, ast_cond_signal, AST_FLAG_END_DTMF_ONLY, AST_LIST_EMPTY, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_pthread_create_background, AST_PTHREADT_NULL, ast_set_flag, ast_test_flag, asthread, autoservice_run(), asent::chan, free, asent::list, LOG_WARNING, asent::orig_end_dtmf_flag, and asent::use_count.

Referenced by _macro_exec(), acf_curl_helper(), acf_jabberreceive_read(), acf_odbc_read(), acf_odbc_write(), ast_app_run_macro(), ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), ast_masq_park_call_exten(), ast_park_call_exten(), bridge_playfile(), builtin_atxfer(), builtin_automixmonitor(), builtin_blindtransfer(), conf_play(), confbridge_exec(), dial_exec_full(), exec(), feature_exec_app(), feature_request_and_dial(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), leave_conference_bridge(), lock_read(), lua_autoservice_start(), lua_get_variable_value(), lua_pbx_exec(), lua_set_variable(), lua_set_variable_value(), originate_exec(), osplookup_exec(), pbx_find_extension(), play_message_on_chan(), realtimefield_read(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), srv_datastore_setup(), system_exec_helper(), try_calling(), and trylock_read().

00179 {
00180    int res = 0;
00181    struct asent *as;
00182 
00183    AST_LIST_LOCK(&aslist);
00184    AST_LIST_TRAVERSE(&aslist, as, list) {
00185       if (as->chan == chan) {
00186          as->use_count++;
00187          break;
00188       }
00189    }
00190    AST_LIST_UNLOCK(&aslist);
00191 
00192    if (as) {
00193       /* Entry exists, autoservice is already handling this channel */
00194       return 0;
00195    }
00196 
00197    if (!(as = ast_calloc(1, sizeof(*as))))
00198       return -1;
00199    
00200    /* New entry created */
00201    as->chan = chan;
00202    as->use_count = 1;
00203 
00204    ast_channel_lock(chan);
00205    as->orig_end_dtmf_flag = ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY) ? 1 : 0;
00206    if (!as->orig_end_dtmf_flag)
00207       ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
00208    ast_channel_unlock(chan);
00209 
00210    AST_LIST_LOCK(&aslist);
00211 
00212    if (AST_LIST_EMPTY(&aslist) && asthread != AST_PTHREADT_NULL) {
00213       ast_cond_signal(&as_cond);
00214    }
00215 
00216    AST_LIST_INSERT_HEAD(&aslist, as, list);
00217 
00218    if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
00219       if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
00220          ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
00221          /* There will only be a single member in the list at this point,
00222             the one we just added. */
00223          AST_LIST_REMOVE(&aslist, as, list);
00224          free(as);
00225          asthread = AST_PTHREADT_NULL;
00226          res = -1;
00227       } else {
00228          pthread_kill(asthread, SIGURG);
00229       }
00230    }
00231 
00232    AST_LIST_UNLOCK(&aslist);
00233 
00234    return res;
00235 }

int ast_autoservice_stop ( struct ast_channel *  chan  ) 

Stop servicing a channel for us...

Note:
if chan is locked prior to calling ast_autoservice_stop, it is likely that there will be a deadlock between the thread that calls ast_autoservice_stop and the autoservice thread. It is important that chan is not locked prior to this call
Parameters:
chan 
Return values:
0 success
-1 error, or the channel has been hungup

Definition at line 237 of file autoservice.c.

References ast_channel::_softhangup, as_chan_list_state, ast_channel_lock, ast_channel_unlock, ast_clear_flag, AST_FLAG_END_DTMF_ONLY, ast_frfree, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, AST_PTHREADT_NULL, ast_queue_frame_head(), asthread, asent::chan, asent::deferred_frames, f, ast_frame::frametype, free, asent::ignore_frame_types, asent::list, asent::orig_end_dtmf_flag, and asent::use_count.

Referenced by _macro_exec(), acf_curl_helper(), acf_jabberreceive_read(), acf_odbc_read(), acf_odbc_write(), array(), ast_app_run_macro(), ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), ast_hangup(), ast_masq_park_call_exten(), ast_park_call_exten(), bridge_playfile(), builtin_atxfer(), builtin_automixmonitor(), conf_play(), confbridge_exec(), dial_exec_full(), exec(), feature_exec_app(), feature_request_and_dial(), finishup(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), leave_conference_bridge(), lock_read(), lua_autoservice_stop(), lua_get_variable_value(), lua_pbx_exec(), lua_set_variable(), lua_set_variable_value(), originate_exec(), osplookup_exec(), pbx_find_extension(), play_message_on_chan(), realtimefield_read(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), srv_datastore_setup(), system_exec_helper(), try_calling(), and trylock_read().

00238 {
00239    int res = -1;
00240    struct asent *as, *removed = NULL;
00241    struct ast_frame *f;
00242    int chan_list_state;
00243 
00244    AST_LIST_LOCK(&aslist);
00245 
00246    /* Save the autoservice channel list state.  We _must_ verify that the channel
00247     * list has been rebuilt before we return.  Because, after we return, the channel
00248     * could get destroyed and we don't want our poor autoservice thread to step on
00249     * it after its gone! */
00250    chan_list_state = as_chan_list_state;
00251 
00252    /* Find the entry, but do not free it because it still can be in the
00253       autoservice thread array */
00254    AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) {  
00255       if (as->chan == chan) {
00256          as->use_count--;
00257          if (as->use_count < 1) {
00258             AST_LIST_REMOVE_CURRENT(list);
00259             removed = as;
00260          }
00261          break;
00262       }
00263    }
00264    AST_LIST_TRAVERSE_SAFE_END;
00265 
00266    if (removed && asthread != AST_PTHREADT_NULL) {
00267       pthread_kill(asthread, SIGURG);
00268    }
00269 
00270    AST_LIST_UNLOCK(&aslist);
00271 
00272    if (!removed) {
00273       return 0;
00274    }
00275 
00276    /* Wait while autoservice thread rebuilds its list. */
00277    while (chan_list_state == as_chan_list_state) {
00278       usleep(1000);
00279    }
00280 
00281    /* Now autoservice thread should have no references to our entry
00282       and we can safely destroy it */
00283 
00284    if (!chan->_softhangup) {
00285       res = 0;
00286    }
00287 
00288    if (!as->orig_end_dtmf_flag) {
00289       ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
00290    }
00291 
00292    ast_channel_lock(chan);
00293    while ((f = AST_LIST_REMOVE_HEAD(&as->deferred_frames, frame_list))) {
00294       if (!((1 << f->frametype) & as->ignore_frame_types)) {
00295          ast_queue_frame_head(chan, f);
00296       }
00297       ast_frfree(f);
00298    }
00299    ast_channel_unlock(chan);
00300 
00301    free(as);
00302 
00303    return res;
00304 }

void ast_begin_shutdown ( int  hangup  ) 

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

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

Definition at line 834 of file channel.c.

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

Referenced by can_safely_quit().

00835 {
00836    shutting_down = 1;
00837 
00838    if (hangup) {
00839       ao2_callback(channels, OBJ_NODATA | OBJ_MULTIPLE, ast_channel_softhangup_cb, NULL);
00840    }
00841 }

format_t ast_best_codec ( format_t  fmts  ) 

Pick the best audio codec.

Pick the best codec Choose the best codec... Uhhh... Yah.

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

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 1058 of file channel.c.

References ARRAY_LEN, AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_AUDIO_MASK, 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_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR16, AST_FORMAT_SPEEX, AST_FORMAT_SPEEX16, AST_FORMAT_TESTLAW, AST_FORMAT_ULAW, ast_getformatname_multiple(), ast_log(), LOG_WARNING, and prefs.

Referenced by __oh323_new(), agent_call(), ast_codec_choose(), ast_iax2_new(), ast_speech_new(), bridge_make_compatible(), builtin_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), jingle_new(), local_new(), login_exec(), mgcp_new(), multicast_rtp_request(), set_format(), sip_new(), skinny_new(), skinny_set_rtp_peer(), socket_process(), start_rtp(), transmit_connect(), and unistim_new().

01059 {
01060    /* This just our opinion, expressed in code.  We are asked to choose
01061       the best codec to use, given no information */
01062    int x;
01063    static const format_t prefs[] =
01064    {
01065       /*! Okay, ulaw is used by all telephony equipment, so start with it */
01066       AST_FORMAT_ULAW,
01067       /*! Unless of course, you're a silly European, so then prefer ALAW */
01068       AST_FORMAT_ALAW,
01069       AST_FORMAT_G719,
01070       AST_FORMAT_SIREN14,
01071       AST_FORMAT_SIREN7,
01072       AST_FORMAT_TESTLAW,
01073       /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
01074       AST_FORMAT_G722,
01075       /*! Okay, well, signed linear is easy to translate into other stuff */
01076       AST_FORMAT_SLINEAR16,
01077       AST_FORMAT_SLINEAR,
01078       /*! G.726 is standard ADPCM, in RFC3551 packing order */
01079       AST_FORMAT_G726,
01080       /*! G.726 is standard ADPCM, in AAL2 packing order */
01081       AST_FORMAT_G726_AAL2,
01082       /*! ADPCM has great sound quality and is still pretty easy to translate */
01083       AST_FORMAT_ADPCM,
01084       /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
01085           translate and sounds pretty good */
01086       AST_FORMAT_GSM,
01087       /*! iLBC is not too bad */
01088       AST_FORMAT_ILBC,
01089       /*! Speex is free, but computationally more expensive than GSM */
01090       AST_FORMAT_SPEEX16,
01091       AST_FORMAT_SPEEX,
01092       /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
01093           to use it */
01094       AST_FORMAT_LPC10,
01095       /*! G.729a is faster than 723 and slightly less expensive */
01096       AST_FORMAT_G729A,
01097       /*! Down to G.723.1 which is proprietary but at least designed for voice */
01098       AST_FORMAT_G723_1,
01099    };
01100    char buf[512];
01101 
01102    /* Strip out video */
01103    fmts &= AST_FORMAT_AUDIO_MASK;
01104    
01105    /* Find the first preferred codec in the format given */
01106    for (x = 0; x < ARRAY_LEN(prefs); x++) {
01107       if (fmts & prefs[x])
01108          return prefs[x];
01109    }
01110 
01111    ast_log(LOG_WARNING, "Don't know any of %s formats\n", ast_getformatname_multiple(buf, sizeof(buf), fmts));
01112 
01113    return 0;
01114 }

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:
chan Current channel
Returns:
A pointer to the bridged channel

Definition at line 7080 of file channel.c.

References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.

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(), 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_call(), 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(), schedule_delivery(), serialize_showchan(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_set_rtp_peer(), skinny_transfer(), socket_process(), start_spying(), startmon(), TransferCallStep1(), and unistim_hangup().

07081 {
07082    struct ast_channel *bridged;
07083    bridged = chan->_bridge;
07084    if (bridged && bridged->tech->bridged_channel)
07085       bridged = bridged->tech->bridged_channel(chan, bridged);
07086    return bridged;
07087 }

int ast_call ( struct ast_channel *  chan,
char *  addr,
int  timeout 
)

Make a call.

Note:
Absolutely _NO_ channel locks should be held before calling this function.
Parameters:
chan which channel to make the call on
addr destination of the call (Should be treated as const char *)
timeout time to wait on for connect

Place a call, take no longer than timeout ms.

Returns:
-1 on failure, 0 on not enough time (does not automatically stop ringing), and the number of seconds the connect took otherwise.

Definition at line 5712 of file channel.c.

References AST_CDR_FLAG_DIALED, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_set_flag, ast_test_flag, ast_channel_tech::call, ast_channel::cdr, and ast_channel::tech.

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

05713 {
05714    /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
05715       If the remote end does not answer within the timeout, then do NOT hang up, but
05716       return anyway.  */
05717    int res = -1;
05718    /* Stop if we're a zombie or need a soft hangup */
05719    ast_channel_lock(chan);
05720    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
05721       if (chan->cdr) {
05722          ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED);
05723       }
05724       if (chan->tech->call)
05725          res = chan->tech->call(chan, addr, timeout);
05726       ast_set_flag(chan, AST_FLAG_OUTGOING);
05727    }
05728    ast_channel_unlock(chan);
05729    return res;
05730 }

struct ast_channel* ast_call_forward ( struct ast_channel *  caller,
struct ast_channel *  orig,
int *  timeout,
format_t  format,
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:
caller in channel that requested orig
orig channel being replaced by the call forward channel
timeout maximum amount of time to wait for setup of new forward channel
format requested channel format
oh outgoing helper used with original channel
outstate reason why unsuccessful (if uncuccessful)
Returns:
Returns the forwarded call's ast_channel on success or NULL on failure

Definition at line 5337 of file channel.c.

References outgoing_helper::account, accountcode, ast_call(), AST_CDR_FLAG_ORIGINATED, ast_cdr_setaccount(), ast_channel_lock, ast_channel_lock_both, 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(), ast_string_field_set, call_forward_inherit(), cause, ast_channel::cdr, ast_channel::connected, ast_channel::context, handle_cause(), LOG_NOTICE, outgoing_helper::parent_channel, pbx_builtin_getvar_helper(), ast_channel::redirecting, S_OR, type, and outgoing_helper::vars.

Referenced by __ast_request_and_dial(), and feature_request_and_dial().

05338 {
05339    char tmpchan[256];
05340    struct ast_channel *new_chan = NULL;
05341    char *data, *type;
05342    int cause = 0;
05343    int res;
05344 
05345    /* gather data and request the new forward channel */
05346    ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan));
05347    if ((data = strchr(tmpchan, '/'))) {
05348       *data++ = '\0';
05349       type = tmpchan;
05350    } else {
05351       const char *forward_context;
05352       ast_channel_lock(orig);
05353       forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
05354       snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context));
05355       ast_channel_unlock(orig);
05356       data = tmpchan;
05357       type = "Local";
05358    }
05359    if (!(new_chan = ast_request(type, format, orig, data, &cause))) {
05360       ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
05361       handle_cause(cause, outstate);
05362       ast_hangup(orig);
05363       return NULL;
05364    }
05365 
05366    /* Copy/inherit important information into new channel */
05367    if (oh) {
05368       if (oh->vars) {
05369          ast_set_variables(new_chan, oh->vars);
05370       }
05371       if (oh->parent_channel) {
05372          call_forward_inherit(new_chan, oh->parent_channel, orig);
05373       }
05374       if (oh->account) {
05375          ast_channel_lock(new_chan);
05376          ast_cdr_setaccount(new_chan, oh->account);
05377          ast_channel_unlock(new_chan);
05378       }
05379    } else if (caller) { /* no outgoing helper so use caller if avaliable */
05380       call_forward_inherit(new_chan, caller, orig);
05381    }
05382 
05383    ast_channel_lock_both(orig, new_chan);
05384    ast_copy_flags(new_chan->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED);
05385    ast_string_field_set(new_chan, accountcode, orig->accountcode);
05386    ast_party_connected_line_copy(&new_chan->connected, &orig->connected);
05387    ast_party_redirecting_copy(&new_chan->redirecting, &orig->redirecting);
05388    ast_channel_unlock(new_chan);
05389    ast_channel_unlock(orig);
05390 
05391    /* call new channel */
05392    res = ast_call(new_chan, data, 0);
05393    if (timeout) {
05394       *timeout = res;
05395    }
05396    if (res) {
05397       ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
05398       ast_hangup(orig);
05399       ast_hangup(new_chan);
05400       return NULL;
05401    }
05402    ast_hangup(orig);
05403 
05404    return new_chan;
05405 }

void ast_cancel_shutdown ( void   ) 

Cancel a shutdown in progress.

Cancels an existing shutdown and returns to normal operation

Definition at line 855 of file channel.c.

Referenced by handle_abort_shutdown().

00856 {
00857    shutting_down = 0;
00858 }

const char* ast_cause2str ( int  cause  ) 

Gives the string form of a given cause code.

Parameters:
state cause to get the description of
Returns:
the text form of the binary cause code given

Definition at line 976 of file channel.c.

References ARRAY_LEN, and causes.

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

00977 {
00978    int x;
00979 
00980    for (x = 0; x < ARRAY_LEN(causes); x++) {
00981       if (causes[x].cause == cause)
00982          return causes[x].desc;
00983    }
00984 
00985    return "Unknown";
00986 }

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:
chan the channel to change the name of
newname the 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 6180 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().

06181 {
06182    /* We must re-link, as the hash value will change here. */
06183    ao2_lock(channels);
06184    ast_channel_lock(chan);
06185    ao2_unlink(channels, chan);
06186    __ast_change_name_nolink(chan, newname);
06187    ao2_link(channels, chan);
06188    ast_channel_unlock(chan);
06189    ao2_unlock(channels);
06190 }

int 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:
c0 first channel to bridge
c1 second channel to bridge
config config for the channels
fo destination frame(?)
rc destination 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 7423 of file channel.c.

References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_clear_softhangup(), ast_channel_make_compatible(), 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_framehook_list_is_empty(), ast_generic_bridge(), ast_indicate(), ast_log(), ast_manager_event_multichan, ast_samp2tv(), ast_set_flag, ast_set_owners_and_peers(), AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_verb, ast_channel::audiohooks, ast_channel_tech::bridge, bridge_play_sounds(), bridge_playfile(), ast_channel::caller, ast_bridge_config::end_sound, EVENT_FLAG_CALL, 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, ast_channel::framehooks, ast_channel::generator, ast_party_caller::id, LOG_WARNING, manager_bridge_event(), ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_party_id::number, ast_bridge_config::play_warning, ast_channel::readformat, S_COR, ast_channel_tech::send_digit_begin, ast_bridge_config::start_sound, ast_bridge_config::start_time, ast_party_number::str, ast_channel::tech, ast_bridge_config::timelimit, update_bridge_vars(), ast_party_number::valid, ast_bridge_config::warning_freq, ast_bridge_config::warning_sound, and ast_channel::writeformat.

Referenced by ast_bridge_call().

07425 {
07426    struct ast_channel *chans[2] = { c0, c1 };
07427    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
07428    format_t o0nativeformats;
07429    format_t o1nativeformats;
07430    long time_left_ms=0;
07431    char caller_warning = 0;
07432    char callee_warning = 0;
07433 
07434    *fo = NULL;
07435 
07436    if (c0->_bridge) {
07437       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
07438          c0->name, c0->_bridge->name);
07439       return -1;
07440    }
07441    if (c1->_bridge) {
07442       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
07443          c1->name, c1->_bridge->name);
07444       return -1;
07445    }
07446    
07447    /* Stop if we're a zombie or need a soft hangup */
07448    if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
07449        ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
07450       return -1;
07451 
07452    caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
07453    callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
07454 
07455    if (ast_tvzero(config->start_time)) {
07456       config->start_time = ast_tvnow();
07457       if (config->start_sound) {
07458          if (caller_warning) {
07459             bridge_playfile(c0, c1, config->start_sound, config->timelimit / 1000);
07460          }
07461          if (callee_warning) {
07462             bridge_playfile(c1, c0, config->start_sound, config->timelimit / 1000);
07463          }
07464       }
07465    }
07466 
07467    /* Keep track of bridge */
07468    c0->_bridge = c1;
07469    c1->_bridge = c0;
07470 
07471    ast_set_owners_and_peers(c0, c1);
07472 
07473    o0nativeformats = c0->nativeformats;
07474    o1nativeformats = c1->nativeformats;
07475 
07476    if (config->feature_timer && !ast_tvzero(config->nexteventts)) {
07477       config->nexteventts = ast_tvadd(config->feature_start_time, ast_samp2tv(config->feature_timer, 1000));
07478    } else if (config->timelimit) {
07479       time_left_ms = config->timelimit - ast_tvdiff_ms(ast_tvnow(), config->start_time);
07480       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
07481       if ((caller_warning || callee_warning) && config->play_warning) {
07482          long next_warn = config->play_warning;
07483          if (time_left_ms < config->play_warning && config->warning_freq > 0) {
07484             /* At least one warning was played, which means we are returning after feature */
07485             long warns_passed = (config->play_warning - time_left_ms) / config->warning_freq;
07486             /* It is 'warns_passed * warning_freq' NOT '(warns_passed + 1) * warning_freq',
07487                because nexteventts will be updated once again in the 'if (!to)' block */
07488             next_warn = config->play_warning - warns_passed * config->warning_freq;
07489          }
07490          config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(next_warn, 1000));
07491       }
07492    } else {
07493       config->nexteventts.tv_sec = 0;
07494       config->nexteventts.tv_usec = 0;
07495    }
07496 
07497    if (!c0->tech->send_digit_begin)
07498       ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY);
07499    if (!c1->tech->send_digit_begin)
07500       ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY);
07501    manager_bridge_event(1, 1, c0, c1);
07502 
07503    /* Before we enter in and bridge these two together tell them both the source of audio has changed */
07504    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
07505    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
07506 
07507    for (/* ever */;;) {
07508       struct timeval now = { 0, };
07509       int to;
07510 
07511       to = -1;
07512 
07513       if (!ast_tvzero(config->nexteventts)) {
07514          now = ast_tvnow();
07515          to = ast_tvdiff_ms(config->nexteventts, now);
07516          if (to <= 0) {
07517             if (!config->timelimit) {
07518                res = AST_BRIDGE_COMPLETE;
07519                break;
07520             }
07521             to = 0;
07522          }
07523       }
07524 
07525       if (config->timelimit) {
07526          time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
07527          if (time_left_ms < to)
07528             to = time_left_ms;
07529 
07530          if (time_left_ms <= 0) {
07531             if (caller_warning && config->end_sound)
07532                bridge_playfile(c0, c1, config->end_sound, 0);
07533             if (callee_warning && config->end_sound)
07534                bridge_playfile(c1, c0, config->end_sound, 0);
07535             *fo = NULL;
07536             res = 0;
07537             break;
07538          }
07539 
07540          if (!to) {
07541             if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) {
07542                int t = (time_left_ms + 500) / 1000; /* round to nearest second */
07543                if (caller_warning)
07544                   bridge_playfile(c0, c1, config->warning_sound, t);
07545                if (callee_warning)
07546                   bridge_playfile(c1, c0, config->warning_sound, t);
07547             }
07548 
07549             if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) {
07550                config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000));
07551             } else {
07552                config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
07553             }
07554          }
07555          ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
07556       }
07557 
07558       if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
07559          if (c0->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
07560             ast_channel_clear_softhangup(c0, AST_SOFTHANGUP_UNBRIDGE);
07561          }
07562          if (c1->_softhangup & AST_SOFTHANGUP_UNBRIDGE) {
07563             ast_channel_clear_softhangup(c1, AST_SOFTHANGUP_UNBRIDGE);
07564          }
07565          c0->_bridge = c1;
07566          c1->_bridge = c0;
07567          ast_debug(1, "Unbridge signal received. Ending native bridge.\n");
07568          continue;
07569       }
07570 
07571       /* Stop if we're a zombie or need a soft hangup */
07572       if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
07573           ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
07574          *fo = NULL;
07575          res = 0;
07576          ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",
07577             c0->name, c1->name,
07578             ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No",
07579             ast_check_hangup(c0) ? "Yes" : "No",
07580             ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No",
07581             ast_check_hangup(c1) ? "Yes" : "No");
07582          break;
07583       }
07584 
07585       update_bridge_vars(c0, c1);
07586 
07587       bridge_play_sounds(c0, c1);
07588 
07589       if (c0->tech->bridge &&
07590          /* if < 1 ms remains use generic bridging for accurate timing */
07591          (!config->timelimit || to > 1000 || to == 0) &&
07592           (c0->tech->bridge == c1->tech->bridge) &&
07593           !c0->monitor && !c1->monitor &&
07594           !c0->audiohooks && !c1->audiohooks &&
07595           ast_framehook_list_is_empty(c0->framehooks) && ast_framehook_list_is_empty(c1->framehooks) &&
07596           !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) {
07597          int timeoutms = to - 1000 > 0 ? to - 1000 : to;
07598          /* Looks like they share a bridge method and nothing else is in the way */
07599          ast_set_flag(c0, AST_FLAG_NBRIDGE);
07600          ast_set_flag(c1, AST_FLAG_NBRIDGE);
07601          if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) {
07602             ast_manager_event_multichan(EVENT_FLAG_CALL, "Unlink", 2, chans,
07603                "Channel1: %s\r\n"
07604                "Channel2: %s\r\n"
07605                "Uniqueid1: %s\r\n"
07606                "Uniqueid2: %s\r\n"
07607                "CallerID1: %s\r\n"
07608                "CallerID2: %s\r\n",
07609                c0->name, c1->name,
07610                c0->uniqueid, c1->uniqueid,
07611                S_COR(c0->caller.id.number.valid, c0->caller.id.number.str, "<unknown>"),
07612                S_COR(c1->caller.id.number.valid, c1->caller.id.number.str, "<unknown>"));
07613 
07614             ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name);
07615 
07616             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
07617             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
07618 
07619             if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */
07620                continue;
07621             }
07622 
07623             c0->_bridge = NULL;
07624             c1->_bridge = NULL;
07625             return res;
07626          } else {
07627             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
07628             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
07629          }
07630          switch (res) {
07631          case AST_BRIDGE_RETRY:
07632             if (config->play_warning) {
07633                ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
07634             }
07635             continue;
07636          default:
07637             ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name);
07638             /* fallthrough */
07639          case AST_BRIDGE_FAILED_NOWARN:
07640             break;
07641          }
07642       }
07643 
07644       if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
07645           (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
07646           !(c0->generator || c1->generator)) {
07647          if (ast_channel_make_compatible(c0, c1)) {
07648             ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
07649             manager_bridge_event(0, 1, c0, c1);
07650             return AST_BRIDGE_FAILED;
07651          }
07652          o0nativeformats = c0->nativeformats;
07653          o1nativeformats = c1->nativeformats;
07654       }
07655 
07656       update_bridge_vars(c0, c1);
07657 
07658       res = ast_generic_bridge(c0, c1, config, fo, rc);
07659       if (res != AST_BRIDGE_RETRY) {
07660          break;
07661       } else if (config->feature_timer) {
07662          /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */
07663          break;
07664       }
07665    }
07666 
07667    ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY);
07668    ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY);
07669 
07670    /* Now that we have broken the bridge the source will change yet again */
07671    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
07672    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
07673 
07674    c0->_bridge = NULL;
07675    c1->_bridge = NULL;
07676 
07677    ast_manager_event_multichan(EVENT_FLAG_CALL, "Unlink", 2, chans,
07678       "Channel1: %s\r\n"
07679       "Channel2: %s\r\n"
07680       "Uniqueid1: %s\r\n"
07681       "Uniqueid2: %s\r\n"
07682       "CallerID1: %s\r\n"
07683       "CallerID2: %s\r\n",
07684       c0->name, c1->name,
07685       c0->uniqueid, c1->uniqueid,
07686       S_COR(c0->caller.id.number.valid, c0->caller.id.number.str, "<unknown>"),
07687       S_COR(c1->caller.id.number.valid, c1->caller.id.number.str, "<unknown>"));
07688    ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
07689 
07690    return res;
07691 }

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 1630 of file channel.c.

References ao2_callback_data, and channels.

Referenced by ast_pickup_call(), handle_core_set_debug_channel(), my_ast_get_channel_by_name_locked(), pickup_by_group(), pickup_by_mark(), pickup_by_part(), and state_notify_build_xml().

01632 {
01633    return ao2_callback_data(channels, ao2_flags, cb_fn, arg, data);
01634 }

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:
chan The channel to create the datastore on
base_params CCSS parameters we wish to copy into the channel
Return values:
0 Success
-1 Failure

Definition at line 9634 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().

09636 {
09637    struct ast_cc_config_params *cc_params;
09638    struct ast_datastore *cc_datastore;
09639 
09640    if (!(cc_params = ast_cc_config_params_init())) {
09641       return -1;
09642    }
09643 
09644    if (!(cc_datastore = ast_datastore_alloc(&cc_channel_datastore_info, NULL))) {
09645       ast_cc_config_params_destroy(cc_params);
09646       return -1;
09647    }
09648 
09649    if (base_params) {
09650       ast_cc_copy_config_params(cc_params, base_params);
09651    }
09652    cc_datastore->data = cc_params;
09653    ast_channel_datastore_add(chan, cc_datastore);
09654    return 0;
09655 }

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:
chan the channel to clear the flag on
flag the flag or flags to clear
Returns:
Nothing.

Definition at line 2703 of file channel.c.

References ast_channel::_softhangup, ast_channel_lock, 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(), check_goto_on_transfer(), and collect_digits().

02704 {
02705    ast_channel_lock(chan);
02706 
02707    chan->_softhangup &= ~flag;
02708 
02709    if (!chan->_softhangup) {
02710       struct ast_frame *fr;
02711 
02712       /* If we have completely cleared the softhangup flag,
02713        * then we need to fully abort the hangup process.  This requires
02714        * pulling the END_OF_Q frame out of the channel frame queue if it
02715        * still happens to be there. */
02716 
02717       fr = AST_LIST_LAST(&chan->readq);
02718       if (fr && fr->frametype == AST_FRAME_CONTROL &&
02719             fr->subclass.integer == AST_CONTROL_END_OF_Q) {
02720          AST_LIST_REMOVE(&chan->readq, fr, frame_list);
02721          ast_frfree(fr);
02722       }
02723    }
02724 
02725    ast_channel_unlock(chan);
02726 }

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:
chan channel on which to check for hang up
offset offset 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 896 of file channel.c.

References ast_channel_cmpwhentohangup_tv().

00897 {
00898    struct timeval when = { offset, };
00899    return ast_channel_cmpwhentohangup_tv(chan, when);
00900 }

int ast_channel_cmpwhentohangup_tv ( struct ast_channel *  chan,
struct timeval  offset 
)

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

Parameters:
chan channel on which to check for hangup
offset offset in seconds and microseconds 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.
Since:
1.6.1

Definition at line 881 of file channel.c.

References ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.

Referenced by ast_channel_cmpwhentohangup().

00882 {
00883    struct timeval whentohangup;
00884 
00885    if (ast_tvzero(chan->whentohangup))
00886       return ast_tvzero(offset) ? 0 : -1;
00887 
00888    if (ast_tvzero(offset))
00889       return 1;
00890 
00891    whentohangup = ast_tvadd(offset, ast_tvnow());
00892 
00893    return ast_tvdiff_ms(whentohangup, chan->whentohangup);
00894 }

int ast_channel_connected_line_macro ( struct ast_channel *  autoservice_chan,
struct ast_channel *  macro_chan,
const void *  connected_info,
int  caller,
int  frame 
)

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

Since:
1.8 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_chan Channel to place into autoservice while the macro is running. It is perfectly safe for this to be NULL
macro_chan The channel to run the macro on. Also the channel from which we determine which macro we need to run.
connected_info Either an ast_party_connected_line or ast_frame pointer of type AST_CONTROL_CONNECTED_LINE
caller If true, then run CONNECTED_LINE_CALLER_SEND_MACRO, otherwise run CONNECTED_LINE_CALLEE_SEND_MACRO
frame If true, then connected_info is an ast_frame pointer, otherwise it is an ast_party_connected_line pointer.
Return values:
0 Success
-1 Either 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 9521 of file channel.c.

References ast_app_run_macro(), 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_strdupa, ast_strlen_zero(), chanlist::connected, ast_channel::connected, ast_frame::data, ast_frame::datalen, 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().

09522 {
09523    const char *macro;
09524    const char *macro_args;
09525    int retval;
09526 
09527    ast_channel_lock(macro_chan);
09528    macro = pbx_builtin_getvar_helper(macro_chan, is_caller
09529       ? "CONNECTED_LINE_CALLER_SEND_MACRO" : "CONNECTED_LINE_CALLEE_SEND_MACRO");
09530    macro = ast_strdupa(S_OR(macro, ""));
09531    macro_args = pbx_builtin_getvar_helper(macro_chan, is_caller
09532       ? "CONNECTED_LINE_CALLER_SEND_MACRO_ARGS" : "CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS");
09533    macro_args = ast_strdupa(S_OR(macro_args, ""));
09534 
09535    if (ast_strlen_zero(macro)) {
09536       ast_channel_unlock(macro_chan);
09537       return -1;
09538    }
09539 
09540    if (is_frame) {
09541       const struct ast_frame *frame = connected_info;
09542 
09543       ast_connected_line_parse_data(frame->data.ptr, frame->datalen, &macro_chan->connected);
09544    } else {
09545       const struct ast_party_connected_line *connected = connected_info;
09546 
09547       ast_party_connected_line_copy(&macro_chan->connected, connected);
09548    }
09549    ast_channel_unlock(macro_chan);
09550 
09551    retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
09552    if (!retval) {
09553       struct ast_party_connected_line saved_connected;
09554 
09555       ast_party_connected_line_init(&saved_connected);
09556       ast_channel_lock(macro_chan);
09557       ast_party_connected_line_copy(&saved_connected, &macro_chan->connected);
09558       ast_channel_unlock(macro_chan);
09559       ast_channel_update_connected_line(macro_chan, &saved_connected, NULL);
09560       ast_party_connected_line_free(&saved_connected);
09561    }
09562 
09563    return retval;
09564 }

int ast_channel_data_add_structure ( struct ast_data *  tree,
struct ast_channel *  chan,
int  add_bridged 
)

Insert into an astdata tree, the channel structure.

Parameters:
[in] tree The ast data tree.
[in] chan The channel structure to add to tree.
[in] add_bridged Add the bridged channel to the structure.
Return values:
<0 on error.
0 on success.

Definition at line 354 of file channel.c.

References ast_channel::_softhangup, ast_channel::_state, ast_channel::amaflags, ast_bridged_channel(), ast_cause2str(), ast_cdr_data_add_structure(), ast_cdr_flags2str(), ast_channel_data_add_structure(), ast_data_add_bool(), ast_data_add_codecs(), ast_data_add_int(), ast_data_add_node(), ast_data_add_str(), ast_data_add_structure, ast_data_add_uint(), AST_SOFTHANGUP_APPUNLOAD, AST_SOFTHANGUP_ASYNCGOTO, AST_SOFTHANGUP_DEV, AST_SOFTHANGUP_EXPLICIT, AST_SOFTHANGUP_SHUTDOWN, AST_SOFTHANGUP_TIMEOUT, AST_SOFTHANGUP_UNBRIDGE, ast_state2str(), ast_tone_zone_data_add_structure(), ast_transfercapability2str(), ast_channel::cdr, channel_data_add_flags(), ast_channel::hangupcause, ast_channel::nativeformats, ast_channel::oldwriteformat, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::transfercapability, ast_channel::whentohangup, ast_channel::writeformat, and ast_channel::zone.

Referenced by agents_data_provider_get(), ast_channel_data_add_structure(), data_channels_provider_handler(), queues_data_provider_get_helper(), and user_add_provider_cb().

00356 {
00357    struct ast_channel *bc;
00358    struct ast_data *data_bridged;
00359    struct ast_data *data_cdr;
00360    struct ast_data *data_flags;
00361    struct ast_data *data_zones;
00362    struct ast_data *enum_node;
00363    struct ast_data *data_softhangup;
00364 #if 0 /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
00365    struct ast_data *data_callerid;
00366    char value_str[100];
00367 #endif
00368 
00369    if (!tree) {
00370       return -1;
00371    }
00372 
00373    ast_data_add_structure(ast_channel, tree, chan);
00374 
00375    if (add_bridged) {
00376       bc = ast_bridged_channel(chan);
00377       if (bc) {
00378          data_bridged = ast_data_add_node(tree, "bridged");
00379          if (!data_bridged) {
00380             return -1;
00381          }
00382          ast_channel_data_add_structure(data_bridged, bc, 0);
00383       }
00384    }
00385 
00386    ast_data_add_codecs(tree, "oldwriteformat", chan->oldwriteformat);
00387    ast_data_add_codecs(tree, "nativeformats", chan->nativeformats);
00388    ast_data_add_codecs(tree, "readformat", chan->readformat);
00389    ast_data_add_codecs(tree, "writeformat", chan->writeformat);
00390    ast_data_add_codecs(tree, "rawreadformat", chan->rawreadformat);
00391    ast_data_add_codecs(tree, "rawwriteformat", chan->rawwriteformat);
00392 
00393    /* state */
00394    enum_node = ast_data_add_node(tree, "state");
00395    if (!enum_node) {
00396       return -1;
00397    }
00398    ast_data_add_str(enum_node, "text", ast_state2str(chan->_state));
00399    ast_data_add_int(enum_node, "value", chan->_state);
00400 
00401    /* hangupcause */
00402    enum_node = ast_data_add_node(tree, "hangupcause");
00403    if (!enum_node) {
00404       return -1;
00405    }
00406    ast_data_add_str(enum_node, "text", ast_cause2str(chan->hangupcause));
00407    ast_data_add_int(enum_node, "value", chan->hangupcause);
00408 
00409    /* amaflags */
00410    enum_node = ast_data_add_node(tree, "amaflags");
00411    if (!enum_node) {
00412       return -1;
00413    }
00414    ast_data_add_str(enum_node, "text", ast_cdr_flags2str(chan->amaflags));
00415    ast_data_add_int(enum_node, "value", chan->amaflags);
00416 
00417    /* transfercapability */
00418    enum_node = ast_data_add_node(tree, "transfercapability");
00419    if (!enum_node) {
00420       return -1;
00421    }
00422    ast_data_add_str(enum_node, "text", ast_transfercapability2str(chan->transfercapability));
00423    ast_data_add_int(enum_node, "value", chan->transfercapability);
00424 
00425    /* _softphangup */
00426    data_softhangup = ast_data_add_node(tree, "softhangup");
00427    if (!data_softhangup) {
00428       return -1;
00429    }
00430    ast_data_add_bool(data_softhangup, "dev", chan->_softhangup & AST_SOFTHANGUP_DEV);
00431    ast_data_add_bool(data_softhangup, "asyncgoto", chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO);
00432    ast_data_add_bool(data_softhangup, "shutdown", chan->_softhangup & AST_SOFTHANGUP_SHUTDOWN);
00433    ast_data_add_bool(data_softhangup, "timeout", chan->_softhangup & AST_SOFTHANGUP_TIMEOUT);
00434    ast_data_add_bool(data_softhangup, "appunload", chan->_softhangup & AST_SOFTHANGUP_APPUNLOAD);
00435    ast_data_add_bool(data_softhangup, "explicit", chan->_softhangup & AST_SOFTHANGUP_EXPLICIT);
00436    ast_data_add_bool(data_softhangup, "unbridge", chan->_softhangup & AST_SOFTHANGUP_UNBRIDGE);
00437 
00438    /* channel flags */
00439    data_flags = ast_data_add_node(tree, "flags");
00440    if (!data_flags) {
00441       return -1;
00442    }
00443    channel_data_add_flags(data_flags, chan);
00444 
00445    ast_data_add_uint(tree, "timetohangup", chan->whentohangup.tv_sec);
00446 
00447 #if 0 /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
00448    /* callerid */
00449    data_callerid = ast_data_add_node(tree, "callerid");
00450    if (!data_callerid) {
00451       return -1;
00452    }
00453    ast_data_add_structure(ast_callerid, data_callerid, &(chan->cid));
00454    /* insert the callerid ton */
00455    enum_node = ast_data_add_node(data_callerid, "cid_ton");
00456    if (!enum_node) {
00457       return -1;
00458    }
00459    ast_data_add_int(enum_node, "value", chan->cid.cid_ton);
00460    snprintf(value_str, sizeof(value_str), "TON: %s/Plan: %s",
00461       party_number_ton2str(chan->cid.cid_ton),
00462       party_number_plan2str(chan->cid.cid_ton));
00463    ast_data_add_str(enum_node, "text", value_str);
00464 #endif
00465 
00466    /* tone zone */
00467    if (chan->zone) {
00468       data_zones = ast_data_add_node(tree, "zone");
00469       if (!data_zones) {
00470          return -1;
00471       }
00472       ast_tone_zone_data_add_structure(data_zones, chan->zone);
00473    }
00474 
00475    /* insert cdr */
00476    data_cdr = ast_data_add_node(tree, "cdr");
00477    if (!data_cdr) {
00478       return -1;
00479    }
00480 
00481    ast_cdr_data_add_structure(data_cdr, chan->cdr, 1);
00482 
00483    return 0;
00484 }

int ast_channel_data_cmp_structure ( const struct ast_data_search *  tree,
struct ast_channel *  chan,
const char *  structure_name 
)

Compare to channel structures using the data api.

Parameters:
[in] tree The search tree generated by the data api.
[in] chan The channel to compare.
[in] structure_name The name of the node of the channel structure.
Return values:
0 The structure matches.
1 The structure doesn't matches.

Definition at line 486 of file channel.c.

References ast_data_search_cmp_structure.

00488 {
00489    return ast_data_search_cmp_structure(tree, ast_channel, chan, structure_name);
00490 }

int ast_channel_datastore_add ( struct ast_channel *  chan,
struct ast_datastore *  datastore 
)
struct ast_datastore* attribute_malloc 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 2559 of file channel.c.

References ast_datastore_alloc.

02560 {
02561    return ast_datastore_alloc(info, uid);
02562 }

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:
pointer to the datastore if found
NULL if not found

Definition at line 2600 of file channel.c.

References 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(), builtin_atxfer(), calendar_event_read(), calendar_query_exec(), calendar_query_result_exec(), cc_build_payload(), 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_lock(), gosub_exec(), handle_gosub(), iax2_call(), jack_hook_callback(), local_read(), local_write(), lock_fixup(), lua_get_state(), manage_parked_call(), manager_mutestream(), mark_transaction_active(), 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_exec(), try_calling(), unlock_read(), volume_callback(), and volume_write().

02601 {
02602    struct ast_datastore *datastore = NULL;
02603    
02604    if (info == NULL)
02605       return NULL;
02606 
02607    AST_LIST_TRAVERSE(&chan->datastores, datastore, entry) {
02608       if (datastore->info != info) {
02609          continue;
02610       }
02611 
02612       if (uid == NULL) {
02613          /* matched by type only */
02614          break;
02615       }
02616 
02617       if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
02618          /* Matched by type AND uid */
02619          break;
02620       }
02621    }
02622 
02623    return datastore;
02624 }

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 2564 of file channel.c.

References ast_datastore_free().

02565 {
02566    return ast_datastore_free(datastore);
02567 }

int ast_channel_datastore_inherit ( struct ast_channel *  from,
struct ast_channel *  to 
)

Inherit datastores from a parent to a child.

Definition at line 2569 of file channel.c.

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

02570 {
02571    struct ast_datastore *datastore = NULL, *datastore2;
02572 
02573    AST_LIST_TRAVERSE(&from->datastores, datastore, entry) {
02574       if (datastore->inheritance > 0) {
02575          datastore2 = ast_datastore_alloc(datastore->info, datastore->uid);
02576          if (datastore2) {
02577             datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
02578             datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
02579             AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry);
02580          }
02581       }
02582    }
02583    return 0;
02584 }

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:
0 success
non-zero failure

Definition at line 2595 of file channel.c.

References AST_LIST_REMOVE.

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

02596 {
02597    return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1;
02598 }

int ast_channel_defer_dtmf ( struct ast_channel *  chan  ) 

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

Returns:
non-zero if channel was already DTMF-deferred or 0 if channel is just now being DTMF-deferred

Definition at line 1612 of file channel.c.

References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.

Referenced by __adsi_transmit_messages(), and find_cache().

01613 {
01614    int pre = 0;
01615 
01616    if (chan) {
01617       pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
01618       ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
01619    }
01620    return pre;
01621 }

int ast_channel_early_bridge ( struct ast_channel *  c0,
struct ast_channel *  c1 
)

Bridge two channels together (early).

Parameters:
c0 first channel to bridge
c1 second 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 7323 of file channel.c.

References ast_channel_tech::early_bridge, and ast_channel::tech.

Referenced by dial_exec_full(), and wait_for_answer().

07324 {
07325    /* Make sure we can early bridge, if not error out */
07326    if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge)))
07327       return -1;
07328 
07329    return c0->tech->early_bridge(c0, c1);
07330 }

struct ast_channel* ast_channel_get_by_exten ( const char *  exten,
const char *  context 
) [read]

Find a channel by extension and context.

  • exten the extension to search for
  • context the context to search for (optional)

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

Return values:
a channel that is at the specified extension and context
NULL if no channel was found
Since:
1.8

Definition at line 1809 of file channel.c.

References ast_channel_get_full().

01810 {
01811    return ast_channel_get_full(NULL, 0, exten, context);
01812 }

struct ast_channel* ast_channel_get_by_name ( const char *  name  )  [read]
struct ast_channel* ast_channel_get_by_name_prefix ( const char *  name,
size_t  name_len 
) [read]

Find a channel by a name prefix.

  • name The channel name or uniqueid prefix to search for
  • name_len Only 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:
a channel with the name prefix specified by the arguments
NULL if no channel was found
Since:
1.8

Definition at line 1804 of file channel.c.

References ast_channel_get_full().

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

01805 {
01806    return ast_channel_get_full(name, name_len, NULL, NULL);
01807 }

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:
chan The channel for which we wish to retrieve the agent type
[out] agent_type The type of agent the channel driver wants us to use
size The size of the buffer to write to

Definition at line 9696 of file channel.c.

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

Referenced by find_agent_callbacks().

09697 {
09698    int len = size;
09699    char *slash;
09700 
09701    if (!ast_channel_queryoption(chan, AST_OPTION_CC_AGENT_TYPE, agent_type, &len, 0)) {
09702       return 0;
09703    }
09704 
09705    ast_copy_string(agent_type, chan->name, size);
09706    if ((slash = strchr(agent_type, '/'))) {
09707       *slash = '\0';
09708    }
09709    return 0;
09710 }

struct ast_cc_config_params* ast_channel_get_cc_config_params ( struct ast_channel *  chan  )  [read]

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:
chan Channel to retrieve parameters from
Return values:
NULL Failure
non-NULL The parameters desired

Definition at line 9657 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(), and local_request().

09658 {
09659    struct ast_datastore *cc_datastore;
09660 
09661    if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
09662       /* If we can't find the datastore, it almost definitely means that the channel type being
09663        * used has not had its driver modified to parse CC config parameters. The best action
09664        * to take here is to create the parameters on the spot with the defaults set.
09665        */
09666       if (ast_channel_cc_params_init(chan, NULL)) {
09667          return NULL;
09668       }
09669       if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
09670          /* Should be impossible */
09671          return NULL;
09672       }
09673    }
09674 
09675    ast_assert(cc_datastore->data != NULL);
09676    return cc_datastore->data;
09677 }

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:
chan The channel to retrieve the information from
[out] device_name The buffer to place the device's name into
name_buffer_length The allocated space for the device_name
Returns:
0 always

Definition at line 9679 of file channel.c.

References 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(), sip_call(), and sip_handle_cc().

09680 {
09681    int len = name_buffer_length;
09682    char *dash;
09683    if (!ast_channel_queryoption(chan, AST_OPTION_DEVICE_NAME, device_name, &len, 0)) {
09684       return 0;
09685    }
09686 
09687    /* Dang. Do it the old-fashioned way */
09688    ast_copy_string(device_name, chan->name, name_buffer_length);
09689    if ((dash = strrchr(device_name, '-'))) {
09690       *dash = '\0';
09691    }
09692 
09693    return 0;
09694 }

static enum ast_t38_state ast_channel_get_t38_state ( struct ast_channel *  chan  )  [inline, static]

Retrieves the current T38 state of a channel.

Definition at line 2405 of file channel.h.

References ast_channel_queryoption(), AST_OPTION_T38_STATE, and T38_STATE_UNAVAILABLE.

Referenced by generic_fax_exec(), receivefax_exec(), receivefax_t38_init(), sendfax_exec(), sendfax_t38_init(), set_fax_t38_caps(), transmit(), transmit_audio(), and transmit_t38().

02406 {
02407    enum ast_t38_state state = T38_STATE_UNAVAILABLE;
02408    int datalen = sizeof(state);
02409 
02410    ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
02411 
02412    return state;
02413 }

void ast_channel_inherit_variables ( const struct ast_channel *  parent,
struct ast_channel *  child 
)

Inherits channel variable from parent to child channel.

Parameters:
parent Parent channel
child Child 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 6192 of file channel.c.

References ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), and ast_channel::varshead.

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

06193 {
06194    struct ast_var_t *current, *newvar;
06195    const char *varname;
06196 
06197    AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
06198       int vartype = 0;
06199 
06200       varname = ast_var_full_name(current);
06201       if (!varname)
06202          continue;
06203 
06204       if (varname[0] == '_') {
06205          vartype = 1;
06206          if (varname[1] == '_')
06207             vartype = 2;
06208       }
06209 
06210       switch (vartype) {
06211       case 1:
06212          newvar = ast_var_assign(&varname[1], ast_var_value(current));
06213          if (newvar) {
06214             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
06215             ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar));
06216          }
06217          break;
06218       case 2:
06219          newvar = ast_var_assign(varname, ast_var_value(current));
06220          if (newvar) {
06221             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
06222             ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar));
06223          }
06224          break;
06225       default:
06226          ast_debug(1, "Not copying variable %s.\n", ast_var_name(current));
06227          break;
06228       }
06229    }
06230 }

struct ast_channel_iterator* ast_channel_iterator_all_new ( void   )  [read]

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.

Return values:
NULL on failure
a new channel iterator
Since:
1.8

Definition at line 1697 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_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(), and handle_softhangup().

01698 {
01699    struct ast_channel_iterator *i;
01700 
01701    if (!(i = ast_calloc(1, sizeof(*i)))) {
01702       return NULL;
01703    }
01704 
01705    i->simple_iterator = ao2_iterator_init(channels, 0);
01706    i->active_iterator = &i->simple_iterator;
01707 
01708    return i;
01709 }

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.

  • exten The extension that channels must be in
  • context The context that channels must be in (optional)

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.

Return values:
NULL on failure
a new channel iterator based on the specified parameters
Since:
1.8

Definition at line 1687 of file channel.c.

References channel_iterator_search().

Referenced by common_exec(), and pickup_by_exten().

01688 {
01689    return channel_iterator_search(NULL, 0, exten, context);
01690 }

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.

  • name channel name or channel uniqueid to match
  • name_len number 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.

Return values:
NULL on failure
a new channel iterator based on the specified parameters
Since:
1.8

Definition at line 1692 of file channel.c.

References channel_iterator_search().

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

01693 {
01694    return channel_iterator_search(name, name_len, NULL, NULL);
01695 }

struct ast_channel_iterator* ast_channel_iterator_destroy ( struct ast_channel_iterator *  i  )  [read]

Destroy a channel iterator.

  • i the itereator to destroy

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

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

Definition at line 1645 of file channel.c.

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

Referenced by action_coreshowchannels(), 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_softhangup(), pickup_by_exten(), and softhangup_exec().

01646 {
01647    ao2_iterator_destroy(i->active_iterator);
01648    ast_free(i);
01649 
01650    return NULL;
01651 }

struct ast_channel* ast_channel_iterator_next ( struct ast_channel_iterator *  i  )  [read]

Get the next channel for a channel iterator.

  • i the channel iterator that was created using one of the channel_iterator_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:
the next channel that matches the parameters used when the iterator was created.
NULL,if no more channels match the iterator parameters.
Since:
1.8

Definition at line 1711 of file channel.c.

References ast_channel_iterator::active_iterator, and ao2_iterator_next.

Referenced by action_coreshowchannels(), 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(), handle_chanlist(), handle_softhangup(), next_channel(), pickup_by_exten(), and softhangup_exec().

01712 {
01713    return ao2_iterator_next(i->active_iterator);
01714 }

int ast_channel_make_compatible ( struct ast_channel *  c0,
struct ast_channel *  c1 
)

Makes two channel formats compatible.

Parameters:
c0 first channel to make compatible
c1 other 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 5921 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(), multiplexed_bridge_join(), parked_call_exec(), simple_bridge_join(), try_calling(), and wait_for_answer().

05922 {
05923    /* Some callers do not check return code, and we must try to set all call legs correctly */
05924    int rc = 0;
05925 
05926    /* Set up translation from the chan to the peer */
05927    rc = ast_channel_make_compatible_helper(chan, peer);
05928 
05929    if (rc < 0)
05930       return rc;
05931 
05932    /* Set up translation from the peer to the chan */
05933    rc = ast_channel_make_compatible_helper(peer, chan);
05934 
05935    return rc;
05936 }

int ast_channel_masquerade ( struct ast_channel *  original,
struct ast_channel *  clone 
)

Weird function made for call transfers.

Parameters:
original channel to make a copy of
clone copy 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 6061 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().

06062 {
06063    return __ast_channel_masquerade(original, clone, NULL);
06064 }

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 7714 of file channel.c.

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

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

07715 {
07716    int res;
07717 
07718    ast_channel_lock(chan);
07719    if (!chan->tech->queryoption) {
07720       errno = ENOSYS;
07721       ast_channel_unlock(chan);
07722       return -1;
07723    }
07724 
07725    if (block)
07726       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
07727 
07728    res = chan->tech->queryoption(chan, option, data, datalen);
07729    ast_channel_unlock(chan);
07730 
07731    return res;
07732 }

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:
chan Asterisk channel to indicate connected line information
connected Connected line information
update What connected line information to update. NULL if all.
Returns:
Nothing

Definition at line 9001 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(), and sip_call().

09002 {
09003    unsigned char data[1024];  /* This should be large enough */
09004    size_t datalen;
09005 
09006    datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
09007    if (datalen == (size_t) -1) {
09008       return;
09009    }
09010 
09011    ast_queue_control_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
09012 }

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:
chan Asterisk channel to indicate redirecting id information
redirecting Redirecting id information
update What redirecting information to update. NULL if all.
Returns:
Nothing

Definition at line 9508 of file channel.c.

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

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

09509 {
09510    unsigned char data[1024];  /* This should be large enough */
09511    size_t datalen;
09512 
09513    datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
09514    if (datalen == (size_t) -1) {
09515       return;
09516    }
09517 
09518    ast_queue_control_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
09519 }

const char* ast_channel_reason2str ( int  reason  ) 

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

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

Definition at line 5264 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().

05265 {
05266    switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
05267    {
05268    case 0:
05269       return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
05270    case AST_CONTROL_HANGUP:
05271       return "Hangup";
05272    case AST_CONTROL_RING:
05273       return "Local Ring";
05274    case AST_CONTROL_RINGING:
05275       return "Remote end Ringing";
05276    case AST_CONTROL_ANSWER:
05277       return "Remote end has Answered";
05278    case AST_CONTROL_BUSY:
05279       return "Remote end is Busy";
05280    case AST_CONTROL_CONGESTION:
05281       return "Congestion (circuits busy)";
05282    default:
05283       return "Unknown Reason!!";
05284    }
05285 }

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

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_chan Channel to place into autoservice while the macro is running. It is perfectly safe for this to be NULL
macro_chan The channel to run the macro on. Also the channel from which we determine which macro we need to run.
redirecting_info Either an ast_party_redirecting or ast_frame pointer of type AST_CONTROL_REDIRECTING
is_caller If true, then run REDIRECTING_CALLER_SEND_MACRO, otherwise run REDIRECTING_CALLEE_SEND_MACRO
is_frame If true, then redirecting_info is an ast_frame pointer, otherwise it is an ast_party_redirecting pointer.
Return values:
0 Success
-1 Either 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 9566 of file channel.c.

References ast_app_run_macro(), ast_channel_lock, ast_channel_unlock, ast_channel_update_redirecting(), ast_party_redirecting_copy(), ast_party_redirecting_free(), ast_party_redirecting_init(), ast_redirecting_parse_data(), ast_strdupa, ast_strlen_zero(), ast_frame::data, ast_frame::datalen, pbx_builtin_getvar_helper(), ast_frame::ptr, ast_channel::redirecting, 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().

09567 {
09568    const char *macro;
09569    const char *macro_args;
09570    int retval;
09571 
09572    ast_channel_lock(macro_chan);
09573    macro = pbx_builtin_getvar_helper(macro_chan, is_caller
09574       ? "REDIRECTING_CALLER_SEND_MACRO" : "REDIRECTING_CALLEE_SEND_MACRO");
09575    macro = ast_strdupa(S_OR(macro, ""));
09576    macro_args = pbx_builtin_getvar_helper(macro_chan, is_caller
09577       ? "REDIRECTING_CALLER_SEND_MACRO_ARGS" : "REDIRECTING_CALLEE_SEND_MACRO_ARGS");
09578    macro_args = ast_strdupa(S_OR(macro_args, ""));
09579 
09580    if (ast_strlen_zero(macro)) {
09581       ast_channel_unlock(macro_chan);
09582       return -1;
09583    }
09584 
09585    if (is_frame) {
09586       const struct ast_frame *frame = redirecting_info;
09587 
09588       ast_redirecting_parse_data(frame->data.ptr, frame->datalen, &macro_chan->redirecting);
09589    } else {
09590       const struct ast_party_redirecting *redirecting = redirecting_info;
09591 
09592       ast_party_redirecting_copy(&macro_chan->redirecting, redirecting);
09593    }
09594    ast_channel_unlock(macro_chan);
09595 
09596    retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
09597    if (!retval) {
09598       struct ast_party_redirecting saved_redirecting;
09599 
09600       ast_party_redirecting_init(&saved_redirecting);
09601       ast_channel_lock(macro_chan);
09602       ast_party_redirecting_copy(&saved_redirecting, &macro_chan->redirecting);
09603       ast_channel_unlock(macro_chan);
09604       ast_channel_update_redirecting(macro_chan, &saved_redirecting, NULL);
09605       ast_party_redirecting_free(&saved_redirecting);
09606    }
09607 
09608    return retval;
09609 }

int ast_channel_register ( const struct ast_channel_tech *  tech  ) 

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

Parameters:
tech Structure defining channel technology or "type"
Returns:
Returns 0 on success, -1 on failure.

Definition at line 903 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, ast_channel_tech::description, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.

Referenced by load_module(), and unload_module().

00904 {
00905    struct chanlist *chan;
00906 
00907    AST_RWLIST_WRLOCK(&backends);
00908 
00909    AST_RWLIST_TRAVERSE(&backends, chan, list) {
00910       if (!strcasecmp(tech->type, chan->tech->type)) {
00911          ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
00912          AST_RWLIST_UNLOCK(&backends);
00913          return -1;
00914       }
00915    }
00916    
00917    if (!(chan = ast_calloc(1, sizeof(*chan)))) {
00918       AST_RWLIST_UNLOCK(&backends);
00919       return -1;
00920    }
00921    chan->tech = tech;
00922    AST_RWLIST_INSERT_HEAD(&backends, chan, list);
00923 
00924    ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
00925 
00926    ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description);
00927 
00928    AST_RWLIST_UNLOCK(&backends);
00929 
00930    return 0;
00931 }

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 1917 of file channel.c.

References ao2_unlink, ast_channel_unref, and channels.

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

01918 {
01919    /* Safe, even if already unlinked. */
01920    ao2_unlink(channels, chan);
01921    return ast_channel_unref(chan);
01922 }

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 5858 of file channel.c.

References ast_channel_tech::send_html, and ast_channel::tech.

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

05859 {
05860    if (chan->tech->send_html)
05861       return chan->tech->send_html(chan, subclass, data, datalen);
05862    return -1;
05863 }

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 5865 of file channel.c.

References ast_channel_sendhtml(), and AST_HTML_URL.

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

05866 {
05867    return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
05868 }

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:
chan Asterisk channel to set caller id information
caller Caller id information
update What 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 6999 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_party_caller_set(), and ast_channel::caller.

07000 {
07001    if (&chan->caller == caller) {
07002       /* Don't set to self */
07003       return;
07004    }
07005 
07006    ast_channel_lock(chan);
07007    ast_party_caller_set(&chan->caller, caller, update);
07008    ast_channel_unlock(chan);
07009 }

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:
chan Asterisk channel to set caller id information
caller Caller id information
update What 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 7011 of file channel.c.

References ast_cdr_setcid(), ast_channel_lock, ast_channel_unlock, ast_party_caller_set(), ast_channel::caller, ast_channel::cdr, ast_party_caller::id, ast_party_id::name, ast_party_id::number, report_new_callerid(), S_COR, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

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

07012 {
07013    const char *pre_set_number;
07014    const char *pre_set_name;
07015 
07016    if (&chan->caller == caller) {
07017       /* Don't set to self */
07018       return;
07019    }
07020 
07021    ast_channel_lock(chan);
07022    pre_set_number =
07023       S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL);
07024    pre_set_name = S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, NULL);
07025    ast_party_caller_set(&chan->caller, caller, update);
07026    if (S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL)
07027          != pre_set_number
07028       || S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, NULL)
07029          != pre_set_name) {
07030       /* The caller id name or number changed. */
07031       report_new_callerid(chan);
07032    }
07033    if (chan->cdr) {
07034       ast_cdr_setcid(chan->cdr, chan);
07035    }
07036    ast_channel_unlock(chan);
07037 }

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:
chan Asterisk channel to set connected line information
connected Connected line information
update What 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 8361 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_party_connected_line_set(), and ast_channel::connected.

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

08362 {
08363    if (&chan->connected == connected) {
08364       /* Don't set to self */
08365       return;
08366    }
08367 
08368    ast_channel_lock(chan);
08369    ast_party_connected_line_set(&chan->connected, connected, update);
08370    ast_channel_unlock(chan);
08371 }

void ast_channel_set_fd ( struct ast_channel *  chan,
int  which,
int  fd 
)

Set the file descriptor on the channel

Definition at line 2627 of file channel.c.

References ast_calloc, ast_epoll_data::chan, ast_channel::fds, free, 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(), 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().

02628 {
02629 #ifdef HAVE_EPOLL
02630    struct epoll_event ev;
02631    struct ast_epoll_data *aed = NULL;
02632 
02633    if (chan->fds[which] > -1) {
02634       epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev);
02635       aed = chan->epfd_data[which];
02636    }
02637 
02638    /* If this new fd is valid, add it to the epoll */
02639    if (fd > -1) {
02640       if (!aed && (!(aed = ast_calloc(1, sizeof(*aed)))))
02641          return;
02642       
02643       chan->epfd_data[which] = aed;
02644       aed->chan = chan;
02645       aed->which = which;
02646       
02647       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
02648       ev.data.ptr = aed;
02649       epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev);
02650    } else if (aed) {
02651       /* We don't have to keep around this epoll data structure now */
02652       free(aed);
02653       chan->epfd_data[which] = NULL;
02654    }
02655 #endif
02656    chan->fds[which] = fd;
02657    return;
02658 }

void ast_channel_set_linkgroup ( struct ast_channel *  chan,
struct ast_channel *  peer 
)

propagate the linked id between chan and peer

Definition at line 6337 of file channel.c.

References ast_channel::_bridge, ast_bridged_channel(), ast_channel_change_linkedid(), ast_strdupa, and oldest_linkedid().

Referenced by ast_bridge_call(), and ast_do_masquerade().

06338 {
06339    const char* linkedid=NULL;
06340    struct ast_channel *bridged;
06341 
06342    linkedid = oldest_linkedid(chan->linkedid, peer->linkedid);
06343    linkedid = oldest_linkedid(linkedid, chan->uniqueid);
06344    linkedid = oldest_linkedid(linkedid, peer->uniqueid);
06345    if (chan->_bridge) {
06346       bridged = ast_bridged_channel(chan);
06347       if (bridged != peer) {
06348          linkedid = oldest_linkedid(linkedid, bridged->linkedid);
06349          linkedid = oldest_linkedid(linkedid, bridged->uniqueid);
06350       }
06351    }
06352    if (peer->_bridge) {
06353       bridged = ast_bridged_channel(peer);
06354       if (bridged != chan) {
06355          linkedid = oldest_linkedid(linkedid, bridged->linkedid);
06356          linkedid = oldest_linkedid(linkedid, bridged->uniqueid);
06357       }
06358    }
06359 
06360    /* just in case setting a stringfield to itself causes problems */
06361    linkedid = ast_strdupa(linkedid);
06362 
06363    ast_channel_change_linkedid(chan, linkedid);
06364    ast_channel_change_linkedid(peer, linkedid);
06365    if (chan->_bridge) {
06366       bridged = ast_bridged_channel(chan);
06367       if (bridged != peer) {
06368          ast_channel_change_linkedid(bridged, linkedid);
06369       }
06370    }
06371    if (peer->_bridge) {
06372       bridged = ast_bridged_channel(peer);
06373       if (bridged != chan) {
06374          ast_channel_change_linkedid(bridged, linkedid);
06375       }
06376    }
06377 }

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:
chan Asterisk channel to set redirecting id information
redirecting Redirecting id information
update What 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 9014 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_party_redirecting_set(), and ast_channel::redirecting.

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

09015 {
09016    if (&chan->redirecting == redirecting) {
09017       /* Don't set to self */
09018       return;
09019    }
09020 
09021    ast_channel_lock(chan);
09022    ast_party_redirecting_set(&chan->redirecting, redirecting, update);
09023    ast_channel_unlock(chan);
09024 }

int ast_channel_setoption ( struct ast_channel *  channel,
int  option,
void *  data,
int  datalen,
int  block 
)

Sets an option on a channel.

Parameters:
channel channel to set options on
option option to change
data data specific to option
datalen length of the data
block blocking 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 7694 of file channel.c.

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

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

07695 {
07696    int res;
07697 
07698    ast_channel_lock(chan);
07699    if (!chan->tech->setoption) {
07700       errno = ENOSYS;
07701       ast_channel_unlock(chan);
07702       return -1;
07703    }
07704 
07705    if (block)
07706       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
07707 
07708    res = chan->tech->setoption(chan, option, data, datalen);
07709    ast_channel_unlock(chan);
07710 
07711    return res;
07712 }

void ast_channel_setwhentohangup ( struct ast_channel *  chan,
time_t  offset 
)

Set when to hang a channel up.

Parameters:
chan channel on which to check for hang up
offset offset 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 874 of file channel.c.

References ast_channel_setwhentohangup_tv().

00875 {
00876    struct timeval when = { offset, };
00877    ast_channel_setwhentohangup_tv(chan, when);
00878 }

void ast_channel_setwhentohangup_tv ( struct ast_channel *  chan,
struct timeval  offset 
)

Set when to hang a channel up.

Parameters:
chan channel on which to check for hang up
offset offset in seconds and useconds 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
Since:
1.6.1

Definition at line 867 of file channel.c.

References ast_null_frame, ast_queue_frame(), ast_tvadd(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.

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

00868 {
00869    chan->whentohangup = ast_tvzero(offset) ? offset : ast_tvadd(offset, ast_tvnow());
00870    ast_queue_frame(chan, &ast_null_frame);
00871    return;
00872 }

struct ast_silence_generator* ast_channel_start_silence_generator ( struct ast_channel *  chan  )  [read]

Starts a silence generator on the given channel.

Parameters:
chan The 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 8207 of file channel.c.

References ast_activate_generator(), ast_calloc, ast_debug, AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_silence_generator::old_write_format, and ast_channel::writeformat.

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

08208 {
08209    struct ast_silence_generator *state;
08210 
08211    if (!(state = ast_calloc(1, sizeof(*state)))) {
08212       return NULL;
08213    }
08214 
08215    state->old_write_format = chan->writeformat;
08216 
08217    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
08218       ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
08219       ast_free(state);
08220       return NULL;
08221    }
08222 
08223    ast_activate_generator(chan, &silence_generator, state);
08224 
08225    ast_debug(1, "Started silence generator on '%s'\n", chan->name);
08226 
08227    return state;
08228 }

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:
chan The channel to operate on
state The 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 8259 of file channel.c.

References 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(), HandleCallOutgoing(), key_dial_page(), record_exec(), unistim_hangup(), waitfor_exec(), and waitforring_exec().

08260 {
08261    if (!state)
08262       return;
08263 
08264    if (internal_deactivate_generator(chan, &silence_generator)) {
08265       ast_debug(1, "Stopped silence generator on '%s'\n", chan->name);
08266 
08267       if (ast_set_write_format(chan, state->old_write_format) < 0)
08268          ast_log(LOG_ERROR, "Could not return write format to its original state\n");
08269    }
08270    ast_free(state);
08271 }

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 5853 of file channel.c.

References ast_channel_tech::send_html, and ast_channel::tech.

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

05854 {
05855    return (chan->tech->send_html) ? 1 : 0;
05856 }

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_chan Target of the call transfer. (Masquerade original channel)
target_id New connected line information for the target channel.
target_held TRUE if the target call is on hold.
transferee_chan Transferee of the call transfer. (Masquerade clone channel)
transferee_id New connected line information for the transferee channel.
transferee_held TRUE 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:
0 on success.
-1 on error.

Definition at line 6135 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(), and misdn_attempt_transfer().

06142 {
06143    struct ast_datastore *xfer_ds;
06144    struct xfer_masquerade_ds *xfer_colp;
06145    int res;
06146 
06147    xfer_ds = ast_datastore_alloc(&xfer_ds_info, NULL);
06148    if (!xfer_ds) {
06149       return -1;
06150    }
06151 
06152    xfer_colp = ast_calloc(1, sizeof(*xfer_colp));
06153    if (!xfer_colp) {
06154       ast_datastore_free(xfer_ds);
06155       return -1;
06156    }
06157    party_connected_line_copy_transfer(&xfer_colp->target_id, target_id);
06158    xfer_colp->target_held = target_held;
06159    party_connected_line_copy_transfer(&xfer_colp->transferee_id, transferee_id);
06160    xfer_colp->transferee_held = transferee_held;
06161    xfer_ds->data = xfer_colp;
06162 
06163    res = __ast_channel_masquerade(target_chan, transferee_chan, xfer_ds);
06164    if (res) {
06165       ast_datastore_free(xfer_ds);
06166    }
06167    return res;
06168 }

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 1624 of file channel.c.

References ast_clear_flag, and AST_FLAG_DEFER_DTMF.

Referenced by __adsi_transmit_messages(), and find_cache().

01625 {
01626    if (chan)
01627       ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
01628 }

void ast_channel_unregister ( const struct ast_channel_tech *  tech  ) 

Unregister a channel technology.

Parameters:
tech Structure defining channel technology or "type" that was previously registered
Returns:
No return value.

Definition at line 934 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::tech, and ast_channel_tech::type.

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

00935 {
00936    struct chanlist *chan;
00937 
00938    ast_debug(1, "Unregistering channel type '%s'\n", tech->type);
00939 
00940    AST_RWLIST_WRLOCK(&backends);
00941 
00942    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
00943       if (chan->tech == tech) {
00944          AST_LIST_REMOVE_CURRENT(list);
00945          ast_free(chan);
00946          ast_verb(2, "Unregistered channel type '%s'\n", tech->type);
00947          break;   
00948       }
00949    }
00950    AST_LIST_TRAVERSE_SAFE_END;
00951 
00952    AST_RWLIST_UNLOCK(&backends);
00953 }

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:
chan Asterisk channel to indicate connected line information
connected Connected line information
update What connected line information to update. NULL if all.
Returns:
Nothing

Definition at line 8988 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_do_pickup(), atxfer_fail_cleanup(), builtin_atxfer(), connectedline_write(), parked_call_exec(), and wait_for_answer().

08989 {
08990    unsigned char data[1024];  /* This should be large enough */
08991    size_t datalen;
08992 
08993    datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
08994    if (datalen == (size_t) -1) {
08995       return;
08996    }
08997 
08998    ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
08999 }

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:
chan Asterisk channel to indicate redirecting id information
redirecting Redirecting id information
update What redirecting information to update. NULL if all.
Returns:
Nothing

Definition at line 9495 of file channel.c.

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

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

09496 {
09497    unsigned char data[1024];  /* This should be large enough */
09498    size_t datalen;
09499 
09500    datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
09501    if (datalen == (size_t) -1) {
09502       return;
09503    }
09504 
09505    ast_indicate_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
09506 }

struct ast_variable* ast_channeltype_list ( void   )  [read]

return an ast_variable list of channeltypes

Definition at line 258 of file channel.c.

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

Referenced by ast_var_channel_types(), and ast_var_channel_types_table().

00259 {
00260    struct chanlist *cl;
00261    struct ast_variable *var = NULL, *prev = NULL;
00262 
00263    AST_RWLIST_RDLOCK(&backends);
00264    AST_RWLIST_TRAVERSE(&backends, cl, list) {
00265       if (prev)  {
00266          if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, "")))
00267             prev = prev->next;
00268       } else {
00269          var = ast_variable_new(cl->tech->type, cl->tech->description, "");
00270          prev = var;
00271       }
00272    }
00273    AST_RWLIST_UNLOCK(&backends);
00274 
00275    return var;
00276 }

int ast_check_hangup ( struct ast_channel *  chan  ) 

Check to see if a channel is needing hang up.

Parameters:
chan channel on which to check for hang up This function determines if the channel is being requested to be hung up.
Returns:
Returns 0 if not, or 1 if hang up is requested (including time-out).

Definition at line 803 of file channel.c.

References ast_channel::_softhangup, ast_debug, AST_SOFTHANGUP_TIMEOUT, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.

Referenced by __ast_pbx_run(), __ast_read(), _macro_exec(), agent_indicate(), agi_exec(), agi_handle_command(), announce_thread(), ast_bridge_call(), ast_bridge_end_dtmf(), 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_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), feature_request_and_dial(), findmeexec(), func_channel_read(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), local_bridge_loop(), local_fixup(), 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().

00804 {
00805    if (chan->_softhangup)     /* yes if soft hangup flag set */
00806       return 1;
00807    if (ast_tvzero(chan->whentohangup)) /* no if no hangup scheduled */
00808       return 0;
00809    if (ast_tvdiff_ms(chan->whentohangup, ast_tvnow()) > 0)  /* no if hangup time has not come yet. */
00810       return 0;
00811    ast_debug(4, "Hangup time has come: %" PRIi64 "\n", ast_tvdiff_ms(chan->whentohangup, ast_tvnow()));
00812    chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */
00813    return 1;
00814 }

int ast_check_hangup_locked ( struct ast_channel *  chan  ) 

Definition at line 816 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().

Referenced by action_redirect(), and ast_channel_bridge().

00817 {
00818    int res;
00819    ast_channel_lock(chan);
00820    res = ast_check_hangup(chan);
00821    ast_channel_unlock(chan);
00822    return res;
00823 }

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:
data Buffer to fill with the frame data
datalen Size of the buffer to fill
connected Connected line information
update What connected line information to build. NULL if all.
Return values:
-1 if error
Amount of data buffer used

Definition at line 8728 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_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_set_party_connected_line::id, ast_party_connected_line::id, LOG_WARNING, ast_party_id_ies::name, party_id_build_data(), 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().

08729 {
08730    int32_t value;
08731    size_t pos = 0;
08732    int res;
08733 
08734    static const struct ast_party_id_ies ies = {
08735       .name.str = AST_CONNECTED_LINE_NAME,
08736       .name.char_set = AST_CONNECTED_LINE_NAME_CHAR_SET,
08737       .name.presentation = AST_CONNECTED_LINE_NAME_PRESENTATION,
08738       .name.valid = AST_CONNECTED_LINE_NAME_VALID,
08739 
08740       .number.str = AST_CONNECTED_LINE_NUMBER,
08741       .number.plan = AST_CONNECTED_LINE_NUMBER_PLAN,
08742       .number.presentation = AST_CONNECTED_LINE_NUMBER_PRESENTATION,
08743       .number.valid = AST_CONNECTED_LINE_NUMBER_VALID,
08744 
08745       .subaddress.str = AST_CONNECTED_LINE_SUBADDRESS,
08746       .subaddress.type = AST_CONNECTED_LINE_SUBADDRESS_TYPE,
08747       .subaddress.odd_even_indicator = AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN,
08748       .subaddress.valid = AST_CONNECTED_LINE_SUBADDRESS_VALID,
08749 
08750       .tag = AST_CONNECTED_LINE_TAG,
08751       .combined_presentation = AST_CONNECTED_LINE_ID_PRESENTATION,
08752    };
08753 
08754    /*
08755     * The size of integer values must be fixed in case the frame is
08756     * shipped to another machine.
08757     */
08758 
08759    /* Connected line frame version */
08760    if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
08761       ast_log(LOG_WARNING, "No space left for connected line frame version\n");
08762       return -1;
08763    }
08764    data[pos++] = AST_CONNECTED_LINE_VERSION;
08765    data[pos++] = 1;
08766    data[pos++] = 2;/* Version 1 did not have a version ie */
08767 
08768    res = party_id_build_data(data + pos, datalen - pos, &connected->id,
08769       "connected line", &ies, update ? &update->id : NULL);
08770    if (res < 0) {
08771       return -1;
08772    }
08773    pos += res;
08774 
08775    /* Connected line source */
08776    if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
08777       ast_log(LOG_WARNING, "No space left for connected line source\n");
08778       return -1;
08779    }
08780    data[pos++] = AST_CONNECTED_LINE_SOURCE;
08781    data[pos++] = sizeof(value);
08782    value = htonl(connected->source);
08783    memcpy(data + pos, &value, sizeof(value));
08784    pos += sizeof(value);
08785 
08786    return pos;
08787 }

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:
dest Destination connected line information
src Source caller information
Returns:
Nothing
Note:
Assumes locks are already acquired

Definition at line 8346 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().

08347 {
08348    ast_party_id_copy(&dest->id, &src->id);
08349    ast_party_id_copy(&dest->ani, &src->ani);
08350    dest->ani2 = src->ani2;
08351 }

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:
dest Destination caller information
src Source connected line information
Returns:
Nothing
Note:
Assumes locks are already acquired

Definition at line 8353 of file channel.c.

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

Referenced by local_call(), and local_indicate().

08354 {
08355    ast_party_id_copy(&dest->id, &src->id);
08356    ast_party_id_copy(&dest->ani, &src->ani);
08357 
08358    dest->ani2 = src->ani2;
08359 }

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:
data Buffer with the frame data to parse
datalen Size of the buffer
connected Extracted connected line information
Return values:
0 on success.
-1 on 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 8789 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_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_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_DEBUG, LOG_WARNING, ast_party_id::name, ast_party_id::number, ast_party_subaddress::odd_even_indicator, ast_party_number::plan, ast_party_number::presentation, ast_party_name::presentation, ast_party_connected_line::source, ast_party_subaddress::str, ast_party_number::str, ast_party_name::str, ast_party_id::subaddress, ast_party_id::tag, ast_party_subaddress::type, ast_party_subaddress::valid, ast_party_number::valid, ast_party_name::valid, and value.

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

08790 {
08791    size_t pos;
08792    unsigned char ie_len;
08793    unsigned char ie_id;
08794    int32_t value;
08795    int frame_version = 1;
08796    int combined_presentation = 0;
08797    int got_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
08798 
08799    for (pos = 0; pos < datalen; pos += ie_len) {
08800       if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
08801          ast_log(LOG_WARNING, "Invalid connected line update\n");
08802          return -1;
08803       }
08804       ie_id = data[pos++];
08805       ie_len = data[pos++];
08806       if (datalen < pos + ie_len) {
08807          ast_log(LOG_WARNING, "Invalid connected line update\n");
08808          return -1;
08809       }
08810 
08811       switch (ie_id) {
08812 /* Connected line party frame version */
08813       case AST_CONNECTED_LINE_VERSION:
08814          if (ie_len != 1) {
08815             ast_log(LOG_WARNING, "Invalid connected line frame version (%u)\n",
08816                (unsigned) ie_len);
08817             break;
08818          }
08819          frame_version = data[pos];
08820          break;
08821 /* Connected line party id name */
08822       case AST_CONNECTED_LINE_NAME:
08823          ast_free(connected->id.name.str);
08824          connected->id.name.str = ast_malloc(ie_len + 1);
08825          if (connected->id.name.str) {
08826             memcpy(connected->id.name.str, data + pos, ie_len);
08827             connected->id.name.str[ie_len] = 0;
08828          }
08829          break;
08830       case AST_CONNECTED_LINE_NAME_CHAR_SET:
08831          if (ie_len != 1) {
08832             ast_log(LOG_WARNING, "Invalid connected line name char set (%u)\n",
08833                (unsigned) ie_len);
08834             break;
08835          }
08836          connected->id.name.char_set = data[pos];
08837          break;
08838       case AST_CONNECTED_LINE_NAME_PRESENTATION:
08839          if (ie_len != 1) {
08840             ast_log(LOG_WARNING, "Invalid connected line name presentation (%u)\n",
08841                (unsigned) ie_len);
08842             break;
08843          }
08844          connected->id.name.presentation = data[pos];
08845          break;
08846       case AST_CONNECTED_LINE_NAME_VALID:
08847          if (ie_len != 1) {
08848             ast_log(LOG_WARNING, "Invalid connected line name valid (%u)\n",
08849                (unsigned) ie_len);
08850             break;
08851          }
08852          connected->id.name.valid = data[pos];
08853          break;
08854 /* Connected line party id number */
08855       case AST_CONNECTED_LINE_NUMBER:
08856          ast_free(connected->id.number.str);
08857          connected->id.number.str = ast_malloc(ie_len + 1);
08858          if (connected->id.number.str) {
08859             memcpy(connected->id.number.str, data + pos, ie_len);
08860             connected->id.number.str[ie_len] = 0;
08861          }
08862          break;
08863       case AST_CONNECTED_LINE_NUMBER_PLAN:
08864          if (ie_len != 1) {
08865             ast_log(LOG_WARNING, "Invalid connected line numbering plan (%u)\n",
08866                (unsigned) ie_len);
08867             break;
08868          }
08869          connected->id.number.plan = data[pos];
08870          break;
08871       case AST_CONNECTED_LINE_NUMBER_PRESENTATION:
08872          if (ie_len != 1) {
08873             ast_log(LOG_WARNING, "Invalid connected line number presentation (%u)\n",
08874                (unsigned) ie_len);
08875             break;
08876          }
08877          connected->id.number.presentation = data[pos];
08878          break;
08879       case AST_CONNECTED_LINE_NUMBER_VALID:
08880          if (ie_len != 1) {
08881             ast_log(LOG_WARNING, "Invalid connected line number valid (%u)\n",
08882                (unsigned) ie_len);
08883             break;
08884          }
08885          connected->id.number.valid = data[pos];
08886          break;
08887 /* Connected line party id combined presentation */
08888       case AST_CONNECTED_LINE_ID_PRESENTATION:
08889          if (ie_len != 1) {
08890             ast_log(LOG_WARNING, "Invalid connected line combined presentation (%u)\n",
08891                (unsigned) ie_len);
08892             break;
08893          }
08894          combined_presentation = data[pos];
08895          got_combined_presentation = 1;
08896          break;
08897 /* Connected line party id subaddress */
08898       case AST_CONNECTED_LINE_SUBADDRESS:
08899          ast_free(connected->id.subaddress.str);
08900          connected->id.subaddress.str = ast_malloc(ie_len + 1);
08901          if (connected->id.subaddress.str) {
08902             memcpy(connected->id.subaddress.str, data + pos, ie_len);
08903             connected->id.subaddress.str[ie_len] = 0;
08904          }
08905          break;
08906       case AST_CONNECTED_LINE_SUBADDRESS_TYPE:
08907          if (ie_len != 1) {
08908             ast_log(LOG_WARNING, "Invalid connected line type of subaddress (%u)\n",
08909                (unsigned) ie_len);
08910             break;
08911          }
08912          connected->id.subaddress.type = data[pos];
08913          break;
08914       case AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN:
08915          if (ie_len != 1) {
08916             ast_log(LOG_WARNING,
08917                "Invalid connected line subaddress odd-even indicator (%u)\n",
08918                (unsigned) ie_len);
08919             break;
08920          }
08921          connected->id.subaddress.odd_even_indicator = data[pos];
08922          break;
08923       case AST_CONNECTED_LINE_SUBADDRESS_VALID:
08924          if (ie_len != 1) {
08925             ast_log(LOG_WARNING, "Invalid connected line subaddress valid (%u)\n",
08926                (unsigned) ie_len);
08927             break;
08928          }
08929          connected->id.subaddress.valid = data[pos];
08930          break;
08931 /* Connected line party tag */
08932       case AST_CONNECTED_LINE_TAG:
08933          ast_free(connected->id.tag);
08934          connected->id.tag = ast_malloc(ie_len + 1);
08935          if (connected->id.tag) {
08936             memcpy(connected->id.tag, data + pos, ie_len);
08937             connected->id.tag[ie_len] = 0;
08938          }
08939          break;
08940 /* Connected line party source */
08941       case AST_CONNECTED_LINE_SOURCE:
08942          if (ie_len != sizeof(value)) {
08943             ast_log(LOG_WARNING, "Invalid connected line source (%u)\n",
08944                (unsigned) ie_len);
08945             break;
08946          }
08947          memcpy(&value, data + pos, sizeof(value));
08948          connected->source = ntohl(value);
08949          break;
08950 /* Connected line party unknown element */
08951       default:
08952          ast_log(LOG_DEBUG, "Unknown connected line element: %u (%u)\n",
08953             (unsigned) ie_id, (unsigned) ie_len);
08954          break;
08955       }
08956    }
08957 
08958    switch (frame_version) {
08959    case 1:
08960       /*
08961        * The other end is an earlier version that we need to adjust
08962        * for compatibility.
08963        */
08964       connected->id.name.valid = 1;
08965       connected->id.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
08966       connected->id.number.valid = 1;
08967       if (got_combined_presentation) {
08968          connected->id.name.presentation = combined_presentation;
08969          connected->id.number.presentation = combined_presentation;
08970       }
08971       break;
08972    case 2:
08973       /* The other end is at the same level as we are. */
08974       break;
08975    default:
08976       /*
08977        * The other end is newer than we are.
08978        * We need to assume that they are compatible with us.
08979        */
08980       ast_log(LOG_DEBUG, "Connected line frame has newer version: %u\n",
08981          (unsigned) frame_version);
08982       break;
08983    }
08984 
08985    return 0;
08986 }

void ast_deactivate_generator ( struct ast_channel *  chan  ) 
int ast_do_masquerade ( struct ast_channel *  original  ) 

Start masquerading a channel.

Note:
absolutely _NO_ channel locks should be held before calling this function.

XXX This is a seriously whacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX

Parameters:
chan Channel to masquerade

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 6496 of file channel.c.

References __ast_change_name_nolink(), ast_channel::_bridge, ast_channel::_softhangup, ast_channel::_state, accountcode, ast_channel::adsicpe, ast_channel::alertpipe, ao2_link, ao2_lock, ao2_unlink, ao2_unlock, ast_app_group_update(), ast_autochan_new_channel(), ast_bridge_end_dtmf(), ast_bridged_channel(), ast_cause2str(), AST_CEL_BRIDGE_UPDATE, ast_cel_report_event(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_lock_both, AST_CHANNEL_NAME, ast_channel_ref, ast_channel_set_fd(), ast_channel_set_linkgroup(), ast_channel_unlock, ast_channel_unref, AST_CONTROL_SRCCHANGE, AST_CONTROL_UNHOLD, ast_copy_string(), ast_datastore_free(), ast_debug, AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_GENERATOR_FD, ast_getformatname(), ast_indicate(), ast_kill_tech, 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, ast_manager_event_multichan, AST_MAX_FDS, ast_null_frame, ast_queue_frame(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), AST_SOFTHANGUP_DEV, ast_state2str(), ast_string_field_set, ast_test_flag, AST_TIMING_FD, ast_channel::blocker, ast_channel::caller, ast_channel::cdr, ast_datastore_info::chan_fixup, channels, clone_variables(), ast_channel::connected, ast_datastore::data, ast_channel::dialed, errno, EVENT_FLAG_CALL, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_channel::hangupcause, ast_datastore::info, language, LOG_WARNING, ast_channel::masq, ast_channel::masqr, masquerade_colp_transfer(), ast_channel::monitor, musicclass, ast_channel::nativeformats, parkinglot, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::redirecting, report_new_callerid(), S_OR, ast_channel::sending_dtmf_digit, ast_channel::sending_dtmf_tv, ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, xfer_masquerade_ds::transferee_held, ast_channel_tech::type, ast_channel::visible_indication, and ast_channel::writeformat.

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

06497 {
06498    int x;
06499    int i;
06500    int origstate;
06501    int visible_indication;
06502    int clone_was_zombie = 0;/*!< TRUE if the clonechan was a zombie before the masquerade. */
06503    struct ast_frame *current;
06504    const struct ast_channel_tech *t;
06505    void *t_pvt;
06506    union {
06507       struct ast_party_dialed dialed;
06508       struct ast_party_caller caller;
06509       struct ast_party_connected_line connected;
06510       struct ast_party_redirecting redirecting;
06511    } exchange;
06512    struct ast_channel *clonechan, *chans[2];
06513    struct ast_channel *bridged;
06514    struct ast_cdr *cdr;
06515    struct ast_datastore *xfer_ds;
06516    struct xfer_masquerade_ds *xfer_colp;
06517    format_t rformat;
06518    format_t wformat;
06519    format_t tmp_format;
06520    char newn[AST_CHANNEL_NAME];
06521    char orig[AST_CHANNEL_NAME];
06522    char masqn[AST_CHANNEL_NAME];
06523    char zombn[AST_CHANNEL_NAME];
06524    char clone_sending_dtmf_digit;
06525    struct timeval clone_sending_dtmf_tv;
06526 
06527    /* XXX This operation is a bit odd.  We're essentially putting the guts of
06528     * the clone channel into the original channel.  Start by killing off the
06529     * original channel's backend.  While the features are nice, which is the
06530     * reason we're keeping it, it's still awesomely weird. XXX */
06531 
06532    /*
06533     * The reasoning for the channels ao2_container lock here is
06534     * complex.
06535     *
06536     * There is a race condition that exists for this function.
06537     * Since all pvt and channel locks must be let go before calling
06538     * ast_do_masquerade, it is possible that it could be called
06539     * multiple times for the same channel.  In order to prevent the
06540     * race condition with competing threads to do the masquerade
06541     * and new masquerade attempts, the channels container must be
06542     * locked for the entire masquerade.  The original and clonechan
06543     * need to be unlocked earlier to avoid potential deadlocks with
06544     * the chan_local deadlock avoidance method.
06545     *
06546     * The container lock blocks competing masquerade attempts from
06547     * starting as well as being necessary for proper locking order
06548     * because the channels must to be unlinked to change their
06549     * names.
06550     *
06551     * The original and clonechan locks must be held while the
06552     * channel contents are shuffled around for the masquerade.
06553     *
06554     * The masq and masqr pointers need to be left alone until the
06555     * masquerade has restabilized the channels to prevent another
06556     * masquerade request until the AST_FLAG_ZOMBIE can be set on
06557     * the clonechan.
06558     */
06559    ao2_lock(channels);
06560 
06561    /*
06562     * Lock the original channel to determine if the masquerade is
06563     * still required.
06564     */
06565    ast_channel_lock(original);
06566 
06567    clonechan = original->masq;
06568    if (!clonechan) {
06569       /*
06570        * The masq is already completed by another thread or never
06571        * needed to be done to begin with.
06572        */
06573       ast_channel_unlock(original);
06574       ao2_unlock(channels);
06575       return 0;
06576    }
06577 
06578    /* Bump the refs to ensure that they won't dissapear on us. */
06579    ast_channel_ref(original);
06580    ast_channel_ref(clonechan);
06581 
06582    /* unlink from channels container as name (which is the hash value) will change */
06583    ao2_unlink(channels, original);
06584    ao2_unlink(channels, clonechan);
06585 
06586    /* Get any transfer masquerade connected line exchange data. */
06587    xfer_ds = ast_channel_datastore_find(original, &xfer_ds_info, NULL);
06588    if (xfer_ds) {
06589       ast_channel_datastore_remove(original, xfer_ds);
06590       xfer_colp = xfer_ds->data;
06591    } else {
06592       xfer_colp = NULL;
06593    }
06594 
06595    /*
06596     * Stop any visible indication on the original channel so we can
06597     * transfer it to the clonechan taking the original's place.
06598     */
06599    visible_indication = original->visible_indication;
06600    ast_channel_unlock(original);
06601    ast_indicate(original, -1);
06602 
06603    /*
06604     * Release any hold on the transferee channel before going any
06605     * further with the masquerade.
06606     */
06607    if (xfer_colp && xfer_colp->transferee_held) {
06608       ast_indicate(clonechan, AST_CONTROL_UNHOLD);
06609    }
06610 
06611    /* Start the masquerade channel contents rearangement. */
06612    ast_channel_lock_both(original, clonechan);
06613 
06614    ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
06615       clonechan->name, clonechan->_state, original->name, original->_state);
06616 
06617    chans[0] = clonechan;
06618    chans[1] = original;
06619    ast_manager_event_multichan(EVENT_FLAG_CALL, "Masquerade", 2, chans,
06620       "Clone: %s\r\n"
06621       "CloneState: %s\r\n"
06622       "Original: %s\r\n"
06623       "OriginalState: %s\r\n",
06624       clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state));
06625 
06626    /*
06627     * Remember the original read/write formats.  We turn off any
06628     * translation on either one
06629     */
06630    rformat = original->readformat;
06631    wformat = original->writeformat;
06632    free_translation(clonechan);
06633    free_translation(original);
06634 
06635    /* Save the current DTMF digit being sent if any. */
06636    clone_sending_dtmf_digit = clonechan->sending_dtmf_digit;
06637    clone_sending_dtmf_tv = clonechan->sending_dtmf_tv;
06638 
06639    /* Save the original name */
06640    ast_copy_string(orig, original->name, sizeof(orig));
06641    /* Save the new name */
06642    ast_copy_string(newn, clonechan->name, sizeof(newn));
06643    /* Create the masq name */
06644    snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
06645 
06646    /* Mangle the name of the clone channel */
06647    __ast_change_name_nolink(clonechan, masqn);
06648 
06649    /* Copy the name from the clone channel */
06650    __ast_change_name_nolink(original, newn);
06651 
06652    /* share linked id's */
06653    ast_channel_set_linkgroup(original, clonechan);
06654 
06655    /* Swap the technologies */
06656    t = original->tech;
06657    original->tech = clonechan->tech;
06658    clonechan->tech = t;
06659 
06660    t_pvt = original->tech_pvt;
06661    original->tech_pvt = clonechan->tech_pvt;
06662    clonechan->tech_pvt = t_pvt;
06663 
06664    /* Swap the cdrs */
06665    cdr = original->cdr;
06666    original->cdr = clonechan->cdr;
06667    clonechan->cdr = cdr;
06668 
06669    /* Swap the alertpipes */
06670    for (i = 0; i < 2; i++) {
06671       x = original->alertpipe[i];
06672       original->alertpipe[i] = clonechan->alertpipe[i];
06673       clonechan->alertpipe[i] = x;
06674    }
06675 
06676    /*
06677     * Swap the readq's.  The end result should be this:
06678     *
06679     *  1) All frames should be on the new (original) channel.
06680     *  2) Any frames that were already on the new channel before this
06681     *     masquerade need to be at the end of the readq, after all of the
06682     *     frames on the old (clone) channel.
06683     *  3) The alertpipe needs to get poked for every frame that was already
06684     *     on the new channel, since we are now using the alert pipe from the
06685     *     old (clone) channel.
06686     */
06687    {
06688       AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;
06689 
06690       AST_LIST_HEAD_INIT_NOLOCK(&tmp_readq);
06691       AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list);
06692       AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list);
06693 
06694       while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
06695          AST_LIST_INSERT_TAIL(&original->readq, current, frame_list);
06696          if (original->alertpipe[1] > -1) {
06697             int poke = 0;
06698 
06699             if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) {
06700                ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
06701             }
06702          }
06703       }
06704    }
06705 
06706    /* Swap the raw formats */
06707    tmp_format = original->rawreadformat;
06708    original->rawreadformat = clonechan->rawreadformat;
06709    clonechan->rawreadformat = tmp_format;
06710 
06711    tmp_format = original->rawwriteformat;
06712    original->rawwriteformat = clonechan->rawwriteformat;
06713    clonechan->rawwriteformat = tmp_format;
06714 
06715    clonechan->_softhangup = AST_SOFTHANGUP_DEV;
06716 
06717    /* And of course, so does our current state.  Note we need not
06718       call ast_setstate since the event manager doesn't really consider
06719       these separate.  We do this early so that the clone has the proper
06720       state of the original channel. */
06721    origstate = original->_state;
06722    original->_state = clonechan->_state;
06723    clonechan->_state = origstate;
06724 
06725    /* Mangle the name of the clone channel */
06726    snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); /* quick, hide the brains! */
06727    __ast_change_name_nolink(clonechan, zombn);
06728 
06729    /* Update the type. */
06730    t_pvt = original->monitor;
06731    original->monitor = clonechan->monitor;
06732    clonechan->monitor = t_pvt;
06733 
06734    /* Keep the same language.  */
06735    ast_string_field_set(original, language, clonechan->language);
06736 
06737    /* Keep the same parkinglot. */
06738    ast_string_field_set(original, parkinglot, clonechan->parkinglot);
06739 
06740    /* Copy the FD's other than the generator fd */
06741    for (x = 0; x < AST_MAX_FDS; x++) {
06742       if (x != AST_GENERATOR_FD)
06743          ast_channel_set_fd(original, x, clonechan->fds[x]);
06744    }
06745 
06746    ast_app_group_update(clonechan, original);
06747 
06748    /* Move data stores over */
06749    if (AST_LIST_FIRST(&clonechan->datastores)) {
06750       struct ast_datastore *ds;
06751       /* We use a safe traversal here because some fixup routines actually
06752        * remove the datastore from the list and free them.
06753        */
06754       AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) {
06755          if (ds->info->chan_fixup)
06756             ds->info->chan_fixup(ds->data, clonechan, original);
06757       }
06758       AST_LIST_TRAVERSE_SAFE_END;
06759       AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry);
06760    }
06761 
06762    ast_autochan_new_channel(clonechan, original);
06763 
06764    clone_variables(original, clonechan);
06765    /* Presense of ADSI capable CPE follows clone */
06766    original->adsicpe = clonechan->adsicpe;
06767    /* Bridge remains the same */
06768    /* CDR fields remain the same */
06769    /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
06770    /* Application and data remain the same */
06771    /* Clone exception  becomes real one, as with fdno */
06772    ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_EXCEPTION | AST_FLAG_OUTGOING));
06773    original->fdno = clonechan->fdno;
06774    /* Schedule context remains the same */
06775    /* Stream stuff stays the same */
06776    /* Keep the original state.  The fixup code will need to work with it most likely */
06777 
06778    /*
06779     * Just swap the whole structures, nevermind the allocations,
06780     * they'll work themselves out.
06781     */
06782    exchange.dialed = original->dialed;
06783    original->dialed = clonechan->dialed;
06784    clonechan->dialed = exchange.dialed;
06785 
06786    exchange.caller = original->caller;
06787    original->caller = clonechan->caller;
06788    clonechan->caller = exchange.caller;
06789 
06790    exchange.connected = original->connected;
06791    original->connected = clonechan->connected;
06792    clonechan->connected = exchange.connected;
06793 
06794    exchange.redirecting = original->redirecting;
06795    original->redirecting = clonechan->redirecting;
06796    clonechan->redirecting = exchange.redirecting;
06797 
06798    report_new_callerid(original);
06799 
06800    /* Restore original timing file descriptor */
06801    ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd);
06802 
06803    /* Our native formats are different now */
06804    original->nativeformats = clonechan->nativeformats;
06805 
06806    /* Context, extension, priority, app data, jump table,  remain the same */
06807    /* pvt switches.  pbx stays the same, as does next */
06808 
06809    /* Set the write format */
06810    ast_set_write_format(original, wformat);
06811 
06812    /* Set the read format */
06813    ast_set_read_format(original, rformat);
06814 
06815    /* Copy the music class */
06816    ast_string_field_set(original, musicclass, clonechan->musicclass);
06817 
06818    /* copy over accuntcode and set peeraccount across the bridge */
06819    ast_string_field_set(original, accountcode, S_OR(clonechan->accountcode, ""));
06820    if (original->_bridge) {
06821       /* XXX - should we try to lock original->_bridge here? */
06822       ast_string_field_set(original->_bridge, peeraccount, S_OR(clonechan->accountcode, ""));
06823       ast_cel_report_event(original, AST_CEL_BRIDGE_UPDATE, NULL, NULL, NULL);
06824    }
06825 
06826    ast_debug(1, "Putting channel %s in %s/%s formats\n", original->name,
06827       ast_getformatname(wformat), ast_getformatname(rformat));
06828 
06829    /* Fixup the original clonechan's physical side */
06830    if (original->tech->fixup && original->tech->fixup(clonechan, original)) {
06831       ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (clonechan)\n",
06832          original->tech->type, original->name);
06833    }
06834 
06835    /* Fixup the original original's physical side */
06836    if (clonechan->tech->fixup && clonechan->tech->fixup(original, clonechan)) {
06837       ast_log(LOG_WARNING, "Channel type '%s' could not fixup channel %s, strange things may happen. (original)\n",
06838          clonechan->tech->type, clonechan->name);
06839    }
06840 
06841    /*
06842     * Now, at this point, the "clone" channel is totally F'd up.
06843     * We mark it as a zombie so nothing tries to touch it.  If it's
06844     * already been marked as a zombie, then we must free it (since
06845     * it already is considered invalid).
06846     *
06847     * This must be done before we unlock clonechan to prevent
06848     * setting up another masquerade on the clonechan.
06849     */
06850    if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) {
06851       clone_was_zombie = 1;
06852    } else {
06853       ast_set_flag(clonechan, AST_FLAG_ZOMBIE);
06854       ast_queue_frame(clonechan, &ast_null_frame);
06855    }
06856 
06857    /* clear the masquerade channels */
06858    original->masq = NULL;
06859    clonechan->masqr = NULL;
06860 
06861    /*
06862     * When we unlock original here, it can be immediately setup to
06863     * masquerade again or hungup.  The new masquerade or hangup
06864     * will not actually happen until we release the channels
06865     * container lock.
06866     */
06867    ast_channel_unlock(original);
06868 
06869    /* Disconnect the original original's physical side */
06870    if (clonechan->tech->hangup && clonechan->tech->hangup(clonechan)) {
06871       ast_log(LOG_WARNING, "Hangup failed!  Strange things may happen!\n");
06872    } else {
06873       /*
06874        * We just hung up the original original's physical side of the
06875        * channel.  Set the new zombie to use the kill channel driver
06876        * for safety.
06877        */
06878       clonechan->tech = &ast_kill_tech;
06879    }
06880 
06881    ast_channel_unlock(clonechan);
06882 
06883    if (clone_sending_dtmf_digit) {
06884       /*
06885        * The clonechan was sending a DTMF digit that was not completed
06886        * before the masquerade.
06887        */
06888       ast_bridge_end_dtmf(original, clone_sending_dtmf_digit, clone_sending_dtmf_tv,
06889          "masquerade");
06890    }
06891 
06892    /*
06893     * If an indication is currently playing, maintain it on the
06894     * channel that is taking the place of original.
06895     *
06896     * This is needed because the masquerade is swapping out the
06897     * internals of the channel, and the new channel private data
06898     * needs to be made aware of the current visible indication
06899     * (RINGING, CONGESTION, etc.)
06900     */
06901    if (visible_indication) {
06902       ast_indicate(original, visible_indication);
06903    }
06904 
06905    ast_channel_lock(original);
06906 
06907    /* Signal any blocker */
06908    if (ast_test_flag(original, AST_FLAG_BLOCKING)) {
06909       pthread_kill(original->blocker, SIGURG);
06910    }
06911 
06912    ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state);
06913 
06914    if ((bridged = ast_bridged_channel(original))) {
06915       ast_channel_ref(bridged);
06916       ast_channel_unlock(original);
06917       ast_indicate(bridged, AST_CONTROL_SRCCHANGE);
06918       ast_channel_unref(bridged);
06919    } else {
06920       ast_channel_unlock(original);
06921    }
06922    ast_indicate(original, AST_CONTROL_SRCCHANGE);
06923 
06924    if (xfer_colp) {
06925       /*
06926        * After the masquerade, the original channel pointer actually
06927        * points to the new transferee channel and the bridged channel
06928        * is still the intended transfer target party.
06929        */
06930       masquerade_colp_transfer(original, xfer_colp);
06931    }
06932 
06933    if (xfer_ds) {
06934       ast_datastore_free(xfer_ds);
06935    }
06936 
06937    if (clone_was_zombie) {
06938       ast_channel_lock(clonechan);
06939       ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name);
06940       ast_manager_event(clonechan, EVENT_FLAG_CALL, "Hangup",
06941          "Channel: %s\r\n"
06942          "Uniqueid: %s\r\n"
06943          "Cause: %d\r\n"
06944          "Cause-txt: %s\r\n",
06945          clonechan->name,
06946          clonechan->uniqueid,
06947          clonechan->hangupcause,
06948          ast_cause2str(clonechan->hangupcause)
06949          );
06950       ast_channel_unlock(clonechan);
06951 
06952       /*
06953        * Drop the system reference to destroy the channel since it is
06954        * already unlinked.
06955        */
06956       ast_channel_unref(clonechan);
06957    } else {
06958       ao2_link(channels, clonechan);
06959    }
06960 
06961    ao2_link(channels, original);
06962    ao2_unlock(channels);
06963 
06964    /* Release our held safety references. */
06965    ast_channel_unref(original);
06966    ast_channel_unref(clonechan);
06967 
06968    return 0;
06969 }

static int ast_fdisset ( struct pollfd *  pfds,
int  fd,
int  maximum,
int *  start 
) [inline, static]

Helper function for migrating select to poll.

Definition at line 2386 of file channel.h.

References dummy().

Referenced by do_monitor().

02387 {
02388    int x;
02389    int dummy = 0;
02390 
02391    if (fd < 0)
02392       return 0;
02393    if (!start)
02394       start = &dummy;
02395    for (x = *start; x < maximum; x++)
02396       if (pfds[x].fd == fd) {
02397          if (x == *start)
02398             (*start)++;
02399          return pfds[x].revents;
02400       }
02401    return 0;
02402 }

struct ast_channel_tech* ast_get_channel_tech ( const char *  name  )  [read]

Get a channel technology structure by name.

Parameters:
name name of technology to find
Returns:
a pointer to the structure, or NULL if no matching technology found

Definition at line 956 of file channel.c.

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

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

00957 {
00958    struct chanlist *chanls;
00959    const struct ast_channel_tech *ret = NULL;
00960 
00961    AST_RWLIST_RDLOCK(&backends);
00962 
00963    AST_RWLIST_TRAVERSE(&backends, chanls, list) {
00964       if (!strcasecmp(name, chanls->tech->type)) {
00965          ret = chanls->tech;
00966          break;
00967       }
00968    }
00969 
00970    AST_RWLIST_UNLOCK(&backends);
00971    
00972    return ret;
00973 }

ast_group_t ast_get_group ( const char *  s  ) 

Definition at line 7886 of file channel.c.

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

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

07887 {
07888    char *piece;
07889    char *c;
07890    int start=0, finish=0, x;
07891    ast_group_t group = 0;
07892 
07893    if (ast_strlen_zero(s))
07894       return 0;
07895 
07896    c = ast_strdupa(s);
07897    
07898    while ((piece = strsep(&c, ","))) {
07899       if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) {
07900          /* Range */
07901       } else if (sscanf(piece, "%30d", &start)) {
07902          /* Just one */
07903          finish = start;
07904       } else {
07905          ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
07906          continue;
07907       }
07908       for (x = start; x <= finish; x++) {
07909          if ((x > 63) || (x < 0)) {
07910             ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
07911          } else
07912             group |= ((ast_group_t) 1 << x);
07913       }
07914    }
07915    return group;
07916 }

int ast_hangup ( struct ast_channel *  chan  ) 

Hang up a channel.

Note:
Absolutely _NO_ channel locks should be held before calling this function.
This function performs a hard hangup on a channel. Unlike the soft-hangup, this function performs all stream stopping, etc, on the channel that needs to end. chan is no longer valid after this call.
Parameters:
chan channel to hang up
Returns:
Returns 0 on success, -1 on failure.

Definition at line 2800 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_lock, ast_channel_unlock, ast_channel_unref, ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_log(), ast_manager_event, ast_set_flag, ast_test_flag, ast_channel::blocker, ast_channel::blockproc, ast_channel::caller, ast_channel::cdr, channels, ast_channel::connected, destroy_hooks(), ast_cdr::disposition, EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, ast_party_connected_line::id, ast_party_caller::id, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_party_id::name, ast_party_id::number, pbx_builtin_getvar_helper(), ast_generator::release, S_COR, S_OR, ast_channel::sched, sched_context_destroy(), ast_party_name::str, ast_party_number::str, ast_channel::stream, ast_channel::tech, ast_party_name::valid, ast_party_number::valid, and ast_channel::vstream.

Referenced by __analog_handle_event(), __analog_ss_thread(), __ast_pbx_run(), __ast_request_and_dial(), __oh323_new(), action_bridge(), alsa_new(), analog_handle_init_event(), analog_ss_thread(), answer_exec_run(), app_exec(), ast_async_goto(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), 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_compat(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), console_new(), dahdi_handle_event(), dahdi_new(), destroy_conference_bridge(), dial_exec_full(), dial_transfer(), do_forward(), do_hang(), do_monitor(), feature_attended_transfer(), feature_request_and_dial(), findmeexec(), generic_recall(), gtalk_new(), handle_call_forward(), handle_callforward_button(), handle_enbloc_call_message(), handle_frame(), handle_frame_ownerless(), handle_hd_hf(), handle_init_event(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_soft_key_event_message(), handle_stimulus_message(), handle_timeout_trip(), handle_transfer_button(), HandleCallOutgoing(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), jingle_new(), local_hangup(), manage_parked_call(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), my_distinctive_ring(), my_handle_notify_message(), nbs_new(), oss_new(), parkandannounce_exec(), parked_call_exec(), phone_new(), play_sound_file(), sip_park(), sip_park_thread(), sip_pickup_thread(), skinny_new(), skinny_ss(), try_calling(), unistim_new(), wait_for_answer(), and wait_for_winner().

02801 {
02802    char extra_str[64]; /* used for cel logging below */
02803    int was_zombie;
02804 
02805    ast_autoservice_stop(chan);
02806 
02807    ast_channel_lock(chan);
02808 
02809    /*
02810     * Do the masquerade if someone is setup to masquerade into us.
02811     *
02812     * NOTE: We must hold the channel lock after testing for a
02813     * pending masquerade and setting the channel as a zombie to
02814     * prevent __ast_channel_masquerade() from setting up a
02815     * masquerade with a dead channel.
02816     */
02817    while (chan->masq) {
02818       ast_channel_unlock(chan);
02819       ast_do_masquerade(chan);
02820       ast_channel_lock(chan);
02821    }
02822 
02823    if (chan->masqr) {
02824       /*
02825        * This channel is one which will be masqueraded into something.
02826        * Mark it as a zombie already so ast_do_masquerade() will know
02827        * to free it later.
02828        */
02829       ast_set_flag(chan, AST_FLAG_ZOMBIE);
02830       destroy_hooks(chan);
02831       ast_channel_unlock(chan);
02832       return 0;
02833    }
02834 
02835    /* Mark as a zombie so a masquerade cannot be setup on this channel. */
02836    if (!(was_zombie = ast_test_flag(chan, AST_FLAG_ZOMBIE))) {
02837       ast_set_flag(chan, AST_FLAG_ZOMBIE);
02838    }
02839 
02840    ast_channel_unlock(chan);
02841    ao2_unlink(channels, chan);
02842    ast_channel_lock(chan);
02843 
02844    destroy_hooks(chan);
02845 
02846    free_translation(chan);
02847    /* Close audio stream */
02848    if (chan->stream) {
02849       ast_closestream(chan->stream);
02850       chan->stream = NULL;
02851    }
02852    /* Close video stream */
02853    if (chan->vstream) {
02854       ast_closestream(chan->vstream);
02855       chan->vstream = NULL;
02856    }
02857    if (chan->sched) {
02858       sched_context_destroy(chan->sched);
02859       chan->sched = NULL;
02860    }
02861 
02862    if (chan->generatordata) { /* Clear any tone stuff remaining */
02863       if (chan->generator && chan->generator->release) {
02864          chan->generator->release(chan, chan->generatordata);
02865       }
02866    }
02867    chan->generatordata = NULL;
02868    chan->generator = NULL;
02869 
02870    snprintf(extra_str, sizeof(extra_str), "%d,%s,%s", chan->hangupcause, chan->hangupsource, S_OR(pbx_builtin_getvar_helper(chan, "DIALSTATUS"), ""));
02871    ast_cel_report_event(chan, AST_CEL_HANGUP, NULL, extra_str, NULL);
02872 
02873    if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
02874       ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
02875          "is blocked by thread %ld in procedure %s!  Expect a failure\n",
02876          (long) pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
02877       ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0);
02878    }
02879    if (!was_zombie) {
02880       ast_debug(1, "Hanging up channel '%s'\n", chan->name);
02881 
02882       if (chan->tech->hangup) {
02883          chan->tech->hangup(chan);
02884       }
02885    } else {
02886       ast_debug(1, "Hanging up zombie '%s'\n", chan->name);
02887    }
02888 
02889    ast_channel_unlock(chan);
02890 
02891    ast_cc_offer(chan);
02892    ast_manager_event(chan, EVENT_FLAG_CALL, "Hangup",
02893       "Channel: %s\r\n"
02894       "Uniqueid: %s\r\n"
02895       "CallerIDNum: %s\r\n"
02896       "CallerIDName: %s\r\n"
02897       "ConnectedLineNum: %s\r\n"
02898       "ConnectedLineName: %s\r\n"
02899       "Cause: %d\r\n"
02900       "Cause-txt: %s\r\n",
02901       chan->name,
02902       chan->uniqueid,
02903       S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, "<unknown>"),
02904       S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, "<unknown>"),
02905       S_COR(chan->connected.id.number.valid, chan->connected.id.number.str, "<unknown>"),
02906       S_COR(chan->connected.id.name.valid, chan->connected.id.name.str, "<unknown>"),
02907       chan->hangupcause,
02908       ast_cause2str(chan->hangupcause)
02909       );
02910 
02911    if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) &&
02912       !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) &&
02913       (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) {
02914       ast_channel_lock(chan);
02915       ast_cdr_end(chan->cdr);
02916       ast_cdr_detach(chan->cdr);
02917       chan->cdr = NULL;
02918       ast_channel_unlock(chan);
02919    }
02920 
02921    ast_channel_unref(chan);
02922 
02923    return 0;
02924 }

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:
chan channel to change the indication
condition which condition to indicate on the channel
Returns:
Returns 0 on success, -1 on failure

Definition at line 4344 of file channel.c.

References ast_indicate_data().

Referenced by __ast_play_and_record(), agent_request(), alsa_call(), answer_trunk_chan(), ast_bridge_call(), 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(), 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(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), try_calling(), and wait_for_answer().

04345 {
04346    return ast_indicate_data(chan, condition, NULL, 0);
04347 }

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:
chan channel to change the indication
condition which condition to indicate on the channel
data pointer to payload data
datalen size 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 4398 of file channel.c.

References ast_channel::_state, _XXX_AST_CONTROL_T38, ast_channel_lock, ast_channel_set_connected_line(), ast_channel_set_redirecting(), ast_channel_unlock, 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_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, 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_channel::connected, ast_tone_zone_sound::data, ast_frame::data, ast_frame::datalen, ast_channel::framehooks, ast_frame::frametype, ast_channel_tech::indicate, ast_frame_subclass::integer, is_visible_indication(), LOG_WARNING, ast_frame::ptr, ast_channel::redirecting, ast_frame::subclass, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.

Referenced by __ast_read(), action_aocmessage(), agent_hangup(), ast_bridge_call(), ast_channel_update_connected_line(), ast_channel_update_redirecting(), ast_generic_bridge(), ast_handle_cc_control_frame(), ast_indicate(), disable_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(), and wait_for_answer().

04400 {
04401    /* By using an enum, we'll get compiler warnings for values not handled 
04402     * in switch statements. */
04403    enum ast_control_frame_type condition = _condition;
04404    struct ast_tone_zone_sound *ts = NULL;
04405    int res;
04406    /* this frame is used by framehooks. if it is set, we must free it at the end of this function */
04407    struct ast_frame *awesome_frame = NULL;
04408 
04409    ast_channel_lock(chan);
04410 
04411    /* Don't bother if the channel is about to go away, anyway. */
04412    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
04413       res = -1;
04414       goto indicate_cleanup;
04415    }
04416 
04417    if (!ast_framehook_list_is_empty(chan->framehooks)) {
04418       /* Do framehooks now, do it, go, go now */
04419       struct ast_frame frame = {
04420          .frametype = AST_FRAME_CONTROL,
04421          .subclass.integer = condition,
04422          .data.ptr = (void *) data, /* this cast from const is only okay because we do the ast_frdup below */
04423          .datalen = datalen
04424       };
04425 
04426       /* we have now committed to freeing this frame */
04427       awesome_frame = ast_frdup(&frame);
04428 
04429       /* who knows what we will get back! the anticipation is killing me. */
04430       if (!(awesome_frame = ast_framehook_list_write_event(chan->framehooks, awesome_frame))
04431          || awesome_frame->frametype != AST_FRAME_CONTROL) {
04432 
04433          res = 0;
04434          goto indicate_cleanup;
04435       }
04436 
04437       condition = awesome_frame->subclass.integer;
04438       data = awesome_frame->data.ptr;
04439       datalen = awesome_frame->datalen;
04440    }
04441 
04442    switch (condition) {
04443    case AST_CONTROL_CONNECTED_LINE:
04444       {
04445          struct ast_party_connected_line connected;
04446 
04447          ast_party_connected_line_set_init(&connected, &chan->connected);
04448          res = ast_connected_line_parse_data(data, datalen, &connected);
04449          if (!res) {
04450             ast_channel_set_connected_line(chan, &connected, NULL);
04451          }
04452          ast_party_connected_line_free(&connected);
04453       }
04454       break;
04455 
04456    case AST_CONTROL_REDIRECTING:
04457       {
04458          struct ast_party_redirecting redirecting;
04459 
04460          ast_party_redirecting_set_init(&redirecting, &chan->redirecting);
04461          res = ast_redirecting_parse_data(data, datalen, &redirecting);
04462          if (!res) {
04463             ast_channel_set_redirecting(chan, &redirecting, NULL);
04464          }
04465          ast_party_redirecting_free(&redirecting);
04466       }
04467       break;
04468    
04469    default:
04470       break;
04471    }
04472 
04473    if (is_visible_indication(condition)) {
04474       /* A new visible indication is requested. */
04475       chan->visible_indication = condition;
04476    } else if (condition == AST_CONTROL_UNHOLD || _condition < 0) {
04477       /* Visible indication is cleared/stopped. */
04478       chan->visible_indication = 0;
04479    }
04480 
04481    if (chan->tech->indicate) {
04482       /* See if the channel driver can handle this condition. */
04483       res = chan->tech->indicate(chan, condition, data, datalen);
04484    } else {
04485       res = -1;
04486    }
04487 
04488    if (!res) {
04489       /* The channel driver successfully handled this indication */
04490       res = 0;
04491       goto indicate_cleanup;
04492    }
04493 
04494    /* The channel driver does not support this indication, let's fake
04495     * it by doing our own tone generation if applicable. */
04496 
04497    /*!\note If we compare the enumeration type, which does not have any
04498     * negative constants, the compiler may optimize this code away.
04499     * Therefore, we must perform an integer comparison here. */
04500    if (_condition < 0) {
04501       /* Stop any tones that are playing */
04502       ast_playtones_stop(chan);
04503       res = 0;
04504       goto indicate_cleanup;
04505    }
04506 
04507    /* Handle conditions that we have tones for. */
04508    switch (condition) {
04509    case _XXX_AST_CONTROL_T38:
04510       /* deprecated T.38 control frame */
04511       res = -1;
04512       goto indicate_cleanup;
04513    case AST_CONTROL_T38_PARAMETERS:
04514       /* there is no way to provide 'default' behavior for these
04515        * control frames, so we need to return failure, but there
04516        * is also no value in the log message below being emitted
04517        * since failure to handle these frames is not an 'error'
04518        * so just return right now. in addition, we want to return
04519        * whatever value the channel driver returned, in case it
04520        * has some meaning.*/
04521       goto indicate_cleanup;
04522    case AST_CONTROL_RINGING:
04523       ts = ast_get_indication_tone(chan->zone, "ring");
04524       /* It is common practice for channel drivers to return -1 if trying
04525        * to indicate ringing on a channel which is up. The idea is to let the
04526        * core generate the ringing inband. However, we don't want the
04527        * warning message about not being able to handle the specific indication
04528        * to print nor do we want ast_indicate_data to return an "error" for this
04529        * condition
04530        */
04531       if (chan->_state == AST_STATE_UP) {
04532          res = 0;
04533       }
04534       break;
04535    case AST_CONTROL_BUSY:
04536       ts = ast_get_indication_tone(chan->zone, "busy");
04537       break;
04538    case AST_CONTROL_INCOMPLETE:
04539    case AST_CONTROL_CONGESTION:
04540       ts = ast_get_indication_tone(chan->zone, "congestion");
04541       break;
04542    case AST_CONTROL_PROGRESS:
04543    case AST_CONTROL_PROCEEDING:
04544    case AST_CONTROL_VIDUPDATE:
04545    case AST_CONTROL_SRCUPDATE:
04546    case AST_CONTROL_SRCCHANGE:
04547    case AST_CONTROL_RADIO_KEY:
04548    case AST_CONTROL_RADIO_UNKEY:
04549    case AST_CONTROL_OPTION:
04550    case AST_CONTROL_WINK:
04551    case AST_CONTROL_FLASH:
04552    case AST_CONTROL_OFFHOOK:
04553    case AST_CONTROL_TAKEOFFHOOK:
04554    case AST_CONTROL_ANSWER:
04555    case AST_CONTROL_HANGUP:
04556    case AST_CONTROL_RING:
04557    case AST_CONTROL_HOLD:
04558    case AST_CONTROL_UNHOLD:
04559    case AST_CONTROL_TRANSFER:
04560    case AST_CONTROL_CONNECTED_LINE:
04561    case AST_CONTROL_REDIRECTING:
04562    case AST_CONTROL_CC:
04563    case AST_CONTROL_READ_ACTION:
04564    case AST_CONTROL_AOC:
04565    case AST_CONTROL_END_OF_Q:
04566    case AST_CONTROL_UPDATE_RTP_PEER:
04567       /* Nothing left to do for these. */
04568       res = 0;
04569       break;
04570    }
04571 
04572    if (ts) {
04573       /* We have a tone to play, yay. */
04574       ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
04575       res = ast_playtones_start(chan, 0, ts->data, 1);
04576       ts = ast_tone_zone_sound_unref(ts);
04577    }
04578 
04579    if (res) {
04580       /* not handled */
04581       ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name);
04582    }
04583 
04584 indicate_cleanup:
04585    ast_channel_unlock(chan);
04586    if (awesome_frame) {
04587       ast_frfree(awesome_frame);
04588    }
04589 
04590    return res;
04591 }

int ast_internal_timing_enabled ( struct ast_channel *  chan  ) 

Check if the channel can run in internal timing mode.

Parameters:
chan The channel to check
Returns:
boolean

This function will return 1 if internal timing is enabled and the timing device is available.

Definition at line 4329 of file channel.c.

References ast_opt_internal_timing, and ast_channel::timingfd.

Referenced by add_sdp(), and ast_read_generator_actions().

04330 {
04331    return (ast_opt_internal_timing && chan->timingfd > -1);
04332 }

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:
frame The frame we just read
Return values:
1 frame should be kept
0 frame should be dropped

Definition at line 1814 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().

01815 {
01816    /* Do not add a default entry in this switch statement.  Each new
01817     * frame type should be addressed directly as to whether it should
01818     * be queued up or not.
01819     */
01820    switch (frame->frametype) {
01821    case AST_FRAME_CONTROL:
01822    case AST_FRAME_TEXT:
01823    case AST_FRAME_IMAGE:
01824    case AST_FRAME_HTML:
01825       return 1;
01826 
01827    case AST_FRAME_DTMF_END:
01828    case AST_FRAME_DTMF_BEGIN:
01829    case AST_FRAME_VOICE:
01830    case AST_FRAME_VIDEO:
01831    case AST_FRAME_NULL:
01832    case AST_FRAME_IAX:
01833    case AST_FRAME_CNG:
01834    case AST_FRAME_MODEM:
01835       return 0;
01836    }
01837    return 0;
01838 }

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:
dest Destination caller
src Source caller
Returns:
Nothing

Definition at line 2272 of file channel.c.

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

02273 {
02274    if (dest == src) {
02275       /* Don't copy to self */
02276       return;
02277    }
02278 
02279    ast_party_id_copy(&dest->id, &src->id);
02280    ast_party_id_copy(&dest->ani, &src->ani);
02281    dest->ani2 = src->ani2;
02282 }

void ast_party_caller_free ( struct ast_party_caller *  doomed  ) 

Destroy the caller party contents.

Since:
1.8
Parameters:
doomed The caller party to destroy.
Returns:
Nothing

Definition at line 2298 of file channel.c.

References ast_party_caller::ani, ast_party_id_free(), and ast_party_caller::id.

Referenced by ast_channel_destructor(), ast_dummy_channel_destructor(), callerid_write(), dial_trunk(), and sla_ring_station().

02299 {
02300    ast_party_id_free(&doomed->id);
02301    ast_party_id_free(&doomed->ani);
02302 }

void ast_party_caller_init ( struct ast_party_caller *  init  ) 

Initialize the given caller structure.

Since:
1.8
Parameters:
init Caller structure to initialize.
Returns:
Nothing

Definition at line 2265 of file channel.c.

References ast_party_caller::ani, ast_party_caller::ani2, ast_party_id_init(), and ast_party_caller::id.

Referenced by __ast_channel_alloc_ap(), dial_trunk(), and sla_ring_station().

02266 {
02267    ast_party_id_init(&init->id);
02268    ast_party_id_init(&init->ani);
02269    init->ani2 = 0;
02270 }

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:
dest The caller one wishes to update
src The new caller values to update the dest
update What caller information to update. NULL if all.
Returns:
Nada

Definition at line 2291 of file channel.c.

References ast_set_party_caller::ani, ast_party_caller::ani, ast_party_caller::ani2, ast_party_id_set(), ast_set_party_caller::id, and ast_party_caller::id.

Referenced by ast_channel_set_caller(), ast_channel_set_caller_event(), and callerid_write().

02292 {
02293    ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
02294    ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
02295    dest->ani2 = src->ani2;
02296 }

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:
init Caller structure to initialize.
guide Source caller to use as a guide in initializing.
Returns:
Nothing

Definition at line 2284 of file channel.c.

References ast_party_caller::ani, ast_party_caller::ani2, ast_party_id_set_init(), and ast_party_caller::id.

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

02285 {
02286    ast_party_id_set_init(&init->id, &guide->id);
02287    ast_party_id_set_init(&init->ani, &guide->ani);
02288    init->ani2 = guide->ani2;
02289 }

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:
connected Collected caller information for the connected line
caller Caller 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 2341 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, and ast_party_connected_line::source.

02342 {
02343    connected->id = caller->id;
02344    connected->ani = caller->ani;
02345    connected->ani2 = caller->ani2;
02346    connected->source = AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN;
02347 }

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:
dest Destination connected line
src Source connected line
Returns:
Nothing

Definition at line 2312 of file channel.c.

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

Referenced by __ast_read(), ast_call_forward(), ast_channel_connected_line_macro(), 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().

02313 {
02314    if (dest == src) {
02315       /* Don't copy to self */
02316       return;
02317    }
02318 
02319    ast_party_id_copy(&dest->id, &src->id);
02320    ast_party_id_copy(&dest->ani, &src->ani);
02321    dest->ani2 = src->ani2;
02322    dest->source = src->source;
02323 }

void ast_party_connected_line_free ( struct ast_party_connected_line *  doomed  ) 
void ast_party_connected_line_init ( struct ast_party_connected_line *  init  ) 
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:
dest The connected line one wishes to update
src The new connected line values to update the dest
update What connected line information to update. NULL if all.
Returns:
Nothing

Definition at line 2333 of file channel.c.

References ast_set_party_connected_line::ani, ast_party_connected_line::ani, ast_party_connected_line::ani2, ast_party_id_set(), ast_set_party_connected_line::id, ast_party_connected_line::id, and ast_party_connected_line::source.

Referenced by ast_channel_set_connected_line(), wait_for_answer(), and wait_for_winner().

02334 {
02335    ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
02336    ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
02337    dest->ani2 = src->ani2;
02338    dest->source = src->source;
02339 }

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:
init Connected line structure to initialize.
guide Source connected line to use as a guide in initializing.
Returns:
Nothing

Definition at line 2325 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, 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().

02326 {
02327    ast_party_id_set_init(&init->id, &guide->id);
02328    ast_party_id_set_init(&init->ani, &guide->ani);
02329    init->ani2 = guide->ani2;
02330    init->source = guide->source;
02331 }

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:
dest Destination dialed party
src Source dialed party
Returns:
Nothing

Definition at line 2223 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().

02224 {
02225    if (dest == src) {
02226       /* Don't copy to self */
02227       return;
02228    }
02229 
02230    ast_free(dest->number.str);
02231    dest->number.str = ast_strdup(src->number.str);
02232    dest->number.plan = src->number.plan;
02233    ast_party_subaddress_copy(&dest->subaddress, &src->subaddress);
02234    dest->transit_network_select = src->transit_network_select;
02235 }

void ast_party_dialed_free ( struct ast_party_dialed *  doomed  ) 

Destroy the dialed party contents.

Since:
1.8
Parameters:
doomed The dialed party to destroy.
Returns:
Nothing

Definition at line 2258 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().

02259 {
02260    ast_free(doomed->number.str);
02261    doomed->number.str = NULL;
02262    ast_party_subaddress_free(&doomed->subaddress);
02263 }

void ast_party_dialed_init ( struct ast_party_dialed *  init  ) 

Initialize the given dialed structure.

Since:
1.8
Parameters:
init Dialed structure to initialize.
Returns:
Nothing

Definition at line 2215 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().

02216 {
02217    init->number.str = NULL;
02218    init->number.plan = 0;/* Unknown */
02219    ast_party_subaddress_init(&init->subaddress);
02220    init->transit_network_select = 0;
02221 }

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:
dest The dialed one wishes to update
src The new dialed values to update the dest
Returns:
Nada

Definition at line 2245 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().

02246 {
02247    if (src->number.str && src->number.str != dest->number.str) {
02248       ast_free(dest->number.str);
02249       dest->number.str = ast_strdup(src->number.str);
02250    }
02251    dest->number.plan = src->number.plan;
02252 
02253    ast_party_subaddress_set(&dest->subaddress, &src->subaddress);
02254 
02255    dest->transit_network_select = src->transit_network_select;
02256 }

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:
init Caller structure to initialize.
guide Source dialed to use as a guide in initializing.
Returns:
Nothing

Definition at line 2237 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().

02238 {
02239    init->number.str = NULL;
02240    init->number.plan = guide->number.plan;
02241    ast_party_subaddress_set_init(&init->subaddress, &guide->subaddress);
02242    init->transit_network_select = guide->transit_network_select;
02243 }

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:
dest Destination party id
src Source party id
Returns:
Nothing

Definition at line 2091 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_redirecting_copy(), and parkandannounce_exec().

02092 {
02093    if (dest == src) {
02094       /* Don't copy to self */
02095       return;
02096    }
02097 
02098    ast_party_name_copy(&dest->name, &src->name);
02099    ast_party_number_copy(&dest->number, &src->number);
02100    ast_party_subaddress_copy(&dest->subaddress, &src->subaddress);
02101 
02102    ast_free(dest->tag);
02103    dest->tag = ast_strdup(src->tag);
02104 }

void ast_party_id_free ( struct ast_party_id *  doomed  ) 

Destroy the party id contents.

Since:
1.8
Parameters:
doomed The party id to destroy.
Returns:
Nothing

Definition at line 2137 of file channel.c.

References ast_free, ast_party_name_free(), ast_party_number_free(), ast_party_subaddress_free(), ast_party_id::name, ast_party_id::number, ast_party_id::subaddress, and ast_party_id::tag.

Referenced by ast_party_caller_free(), ast_party_connected_line_free(), ast_party_redirecting_free(), and parkandannounce_exec().

02138 {
02139    ast_party_name_free(&doomed->name);
02140    ast_party_number_free(&doomed->number);
02141    ast_party_subaddress_free(&doomed->subaddress);
02142 
02143    ast_free(doomed->tag);
02144    doomed->tag = NULL;
02145 }

void ast_party_id_init ( struct ast_party_id *  init  ) 

Initialize the given party id structure.

Since:
1.8
Parameters:
init Party id structure to initialize.
Returns:
Nothing

Definition at line 2083 of file channel.c.

References ast_party_name_init(), ast_party_number_init(), ast_party_subaddress_init(), ast_party_id::name, ast_party_id::number, ast_party_id::subaddress, and ast_party_id::tag.

Referenced by ast_party_caller_init(), ast_party_connected_line_init(), ast_party_redirecting_init(), dial_exec_full(), and parkandannounce_exec().

02084 {
02085    ast_party_name_init(&init->name);
02086    ast_party_number_init(&init->number);
02087    ast_party_subaddress_init(&init->subaddress);
02088    init->tag = NULL;
02089 }

int ast_party_id_presentation ( const struct ast_party_id *  id  ) 

Determine the overall presentation value for the given party.

Since:
1.8
Parameters:
id Party to determine the overall presentation value.
Returns:
Overall presentation value for the given party.

Definition at line 2147 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_number::valid, and ast_party_name::valid.

Referenced by add_rpid(), ast_str_retrieve_variable(), ast_var_channels_table(), callerpres_read(), iax2_call(), initreqprep(), oh323_call(), party_id_build_data(), party_id_read(), redirecting_read(), report_new_callerid(), setup_env(), sip_call(), and socket_process().

02148 {
02149    int number_priority;
02150    int number_value;
02151    int number_screening;
02152    int name_priority;
02153    int name_value;
02154 
02155    /* Determine name presentation priority. */
02156    if (!id->name.valid) {
02157       name_value = AST_PRES_UNAVAILABLE;
02158       name_priority = 3;
02159    } else {
02160       name_value = id->name.presentation & AST_PRES_RESTRICTION;
02161       switch (name_value) {
02162       case AST_PRES_RESTRICTED:
02163          name_priority = 0;
02164          break;
02165       case AST_PRES_ALLOWED:
02166          name_priority = 1;
02167          break;
02168       case AST_PRES_UNAVAILABLE:
02169          name_priority = 2;
02170          break;
02171       default:
02172          name_value = AST_PRES_UNAVAILABLE;
02173          name_priority = 3;
02174          break;
02175       }
02176    }
02177 
02178    /* Determine number presentation priority. */
02179    if (!id->number.valid) {
02180       number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
02181       number_value = AST_PRES_UNAVAILABLE;
02182       number_priority = 3;
02183    } else {
02184       number_screening = id->number.presentation & AST_PRES_NUMBER_TYPE;
02185       number_value = id->number.presentation & AST_PRES_RESTRICTION;
02186       switch (number_value) {
02187       case AST_PRES_RESTRICTED:
02188          number_priority = 0;
02189          break;
02190       case AST_PRES_ALLOWED:
02191          number_priority = 1;
02192          break;
02193       case AST_PRES_UNAVAILABLE:
02194          number_priority = 2;
02195          break;
02196       default:
02197          number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
02198          number_value = AST_PRES_UNAVAILABLE;
02199          number_priority = 3;
02200          break;
02201       }
02202    }
02203 
02204    /* Select the wining presentation value. */
02205    if (name_priority < number_priority) {
02206       number_value = name_value;
02207    }
02208    if (number_value == AST_PRES_UNAVAILABLE) {
02209       return AST_PRES_NUMBER_NOT_AVAILABLE;
02210    }
02211 
02212    return number_value | number_screening;
02213 }

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:
dest The id one wishes to update
src The new id values to update the dest
update What id information to update. NULL if all.
Returns:
Nothing

Definition at line 2114 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().

02115 {
02116    if (dest == src) {
02117       /* Don't set to self */
02118       return;
02119    }
02120 
02121    if (!update || update->name) {
02122       ast_party_name_set(&dest->name, &src->name);
02123    }
02124    if (!update || update->number) {
02125       ast_party_number_set(&dest->number, &src->number);
02126    }
02127    if (!update || update->subaddress) {
02128       ast_party_subaddress_set(&dest->subaddress, &src->subaddress);
02129    }
02130 
02131    if (src->tag && src->tag != dest->tag) {
02132       ast_free(dest->tag);
02133       dest->tag = ast_strdup(src->tag);
02134    }
02135 }

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:
init Party id structure to initialize.
guide Source party id to use as a guide in initializing.
Returns:
Nothing

Definition at line 2106 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().

02107 {
02108    ast_party_name_set_init(&init->name, &guide->name);
02109    ast_party_number_set_init(&init->number, &guide->number);
02110    ast_party_subaddress_set_init(&init->subaddress, &guide->subaddress);
02111    init->tag = NULL;
02112 }

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:
dest Destination party name
src Source party name
Returns:
Nothing

Definition at line 1932 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().

01933 {
01934    if (dest == src) {
01935       /* Don't copy to self */
01936       return;
01937    }
01938 
01939    ast_free(dest->str);
01940    dest->str = ast_strdup(src->str);
01941    dest->char_set = src->char_set;
01942    dest->presentation = src->presentation;
01943    dest->valid = src->valid;
01944 }

void ast_party_name_free ( struct ast_party_name *  doomed  ) 

Destroy the party name contents.

Since:
1.8
Parameters:
doomed The party name to destroy.
Returns:
Nothing

Definition at line 1971 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().

01972 {
01973    ast_free(doomed->str);
01974    doomed->str = NULL;
01975 }

void ast_party_name_init ( struct ast_party_name *  init  ) 

Initialize the given name structure.

Since:
1.8
Parameters:
init Name structure to initialize.
Returns:
Nothing

Definition at line 1924 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().

01925 {
01926    init->str = NULL;
01927    init->char_set = AST_PARTY_CHAR_SET_ISO8859_1;
01928    init->presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
01929    init->valid = 0;
01930 }

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:
dest The name one wishes to update
src The new name values to update the dest
Returns:
Nothing

Definition at line 1954 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().

01955 {
01956    if (dest == src) {
01957       /* Don't set to self */
01958       return;
01959    }
01960 
01961    if (src->str && src->str != dest->str) {
01962       ast_free(dest->str);
01963       dest->str = ast_strdup(src->str);
01964    }
01965 
01966    dest->char_set = src->char_set;
01967    dest->presentation = src->presentation;
01968    dest->valid = src->valid;
01969 }

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:
init Party name structure to initialize.
guide Source party name to use as a guide in initializing.
Returns:
Nothing

Definition at line 1946 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().

01947 {
01948    init->str = NULL;
01949    init->char_set = guide->char_set;
01950    init->presentation = guide->presentation;
01951    init->valid = guide->valid;
01952 }

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:
dest Destination party number
src Source party number
Returns:
Nothing

Definition at line 1985 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().

01986 {
01987    if (dest == src) {
01988       /* Don't copy to self */
01989       return;
01990    }
01991 
01992    ast_free(dest->str);
01993    dest->str = ast_strdup(src->str);
01994    dest->plan = src->plan;
01995    dest->presentation = src->presentation;
01996    dest->valid = src->valid;
01997 }

void ast_party_number_free ( struct ast_party_number *  doomed  ) 

Destroy the party number contents.

Since:
1.8
Parameters:
doomed The party number to destroy.
Returns:
Nothing

Definition at line 2024 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().

02025 {
02026    ast_free(doomed->str);
02027    doomed->str = NULL;
02028 }

void ast_party_number_init ( struct ast_party_number *  init  ) 

Initialize the given number structure.

Since:
1.8
Parameters:
init Number structure to initialize.
Returns:
Nothing

Definition at line 1977 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().

01978 {
01979    init->str = NULL;
01980    init->plan = 0;/* Unknown */
01981    init->presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
01982    init->valid = 0;
01983 }

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:
dest The number one wishes to update
src The new number values to update the dest
Returns:
Nothing

Definition at line 2007 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().

02008 {
02009    if (dest == src) {
02010       /* Don't set to self */
02011       return;
02012    }
02013 
02014    if (src->str && src->str != dest->str) {
02015       ast_free(dest->str);
02016       dest->str = ast_strdup(src->str);
02017    }
02018 
02019    dest->plan = src->plan;
02020    dest->presentation = src->presentation;
02021    dest->valid = src->valid;
02022 }

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:
init Party number structure to initialize.
guide Source party number to use as a guide in initializing.
Returns:
Nothing

Definition at line 1999 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().

02000 {
02001    init->str = NULL;
02002    init->plan = guide->plan;
02003    init->presentation = guide->presentation;
02004    init->valid = guide->valid;
02005 }

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.

Since:
1.8
Parameters:
dest Destination redirecting
src Source redirecting
Returns:
Nothing

Definition at line 2363 of file channel.c.

References ast_party_id_copy(), ast_party_redirecting::count, ast_party_redirecting::from, ast_party_redirecting::reason, and ast_party_redirecting::to.

Referenced by ast_call_forward(), ast_channel_redirecting_macro(), begin_dial_channel(), call_forward_inherit(), dial_exec_full(), do_forward(), local_call(), ring_entry(), and wait_for_answer().

02364 {
02365    if (dest == src) {
02366       /* Don't copy to self */
02367       return;
02368    }
02369 
02370    ast_party_id_copy(&dest->from, &src->from);
02371    ast_party_id_copy(&dest->to, &src->to);
02372    dest->count = src->count;
02373    dest->reason = src->reason;
02374 }

void ast_party_redirecting_free ( struct ast_party_redirecting *  doomed  ) 

Destroy the redirecting information contents.

Since:
1.8
Parameters:
doomed The redirecting information to destroy.
Returns:
Nothing

Definition at line 2392 of file channel.c.

References ast_party_id_free(), ast_party_redirecting::from, and ast_party_redirecting::to.

Referenced by ast_channel_destructor(), ast_channel_redirecting_macro(), ast_dummy_channel_destructor(), ast_indicate_data(), call_forward_inherit(), do_forward(), handle_request_invite(), handle_response(), handle_response_invite(), redirecting_write(), and wait_for_answer().

02393 {
02394    ast_party_id_free(&doomed->from);
02395    ast_party_id_free(&doomed->to);
02396 }

void ast_party_redirecting_init ( struct ast_party_redirecting *  init  ) 

Initialize the given redirecting structure.

Since:
1.8
Parameters:
init Redirecting structure to initialize.
Returns:
Nothing

Definition at line 2355 of file channel.c.

References ast_party_id_init(), AST_REDIRECTING_REASON_UNKNOWN, ast_party_redirecting::count, ast_party_redirecting::from, ast_party_redirecting::reason, and ast_party_redirecting::to.

Referenced by __ast_channel_alloc_ap(), ast_channel_redirecting_macro(), call_forward_inherit(), do_forward(), handle_request_invite(), handle_response(), handle_response_invite(), and wait_for_answer().

02356 {
02357    ast_party_id_init(&init->from);
02358    ast_party_id_init(&init->to);
02359    init->count = 0;
02360    init->reason = AST_REDIRECTING_REASON_UNKNOWN;
02361 }

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:
dest The redirecting one wishes to update
src The new redirecting values to update the dest
update What redirecting information to update. NULL if all.
Returns:
Nothing

Definition at line 2384 of file channel.c.

References ast_party_id_set(), ast_party_redirecting::count, ast_set_party_redirecting::from, ast_party_redirecting::from, ast_party_redirecting::reason, ast_set_party_redirecting::to, and ast_party_redirecting::to.

Referenced by ast_channel_set_redirecting().

02385 {
02386    ast_party_id_set(&dest->from, &src->from, update ? &update->from : NULL);
02387    ast_party_id_set(&dest->to, &src->to, update ? &update->to : NULL);
02388    dest->reason = src->reason;
02389    dest->count = src->count;
02390 }

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:
init Redirecting id structure to initialize.
guide Source redirecting id to use as a guide in initializing.
Returns:
Nothing

Definition at line 2376 of file channel.c.

References ast_party_id_set_init(), ast_party_redirecting::count, ast_party_redirecting::from, ast_party_redirecting::reason, and ast_party_redirecting::to.

Referenced by ast_indicate_data(), misdn_copy_redirecting_to_ast(), and redirecting_write().

02377 {
02378    ast_party_id_set_init(&init->from, &guide->from);
02379    ast_party_id_set_init(&init->to, &guide->to);
02380    init->count = guide->count;
02381    init->reason = guide->reason;
02382 }

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:
dest Destination party subaddress
src Source party subaddress
Returns:
Nothing

Definition at line 2038 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().

02039 {
02040    if (dest == src) {
02041       /* Don't copy to self */
02042       return;
02043    }
02044 
02045    ast_free(dest->str);
02046    dest->str = ast_strdup(src->str);
02047    dest->type = src->type;
02048    dest->odd_even_indicator = src->odd_even_indicator;
02049    dest->valid = src->valid;
02050 }

void ast_party_subaddress_free ( struct ast_party_subaddress *  doomed  ) 

Destroy the party subaddress contents.

Since:
1.8
Parameters:
doomed The party subaddress to destroy.
Returns:
Nothing

Definition at line 2077 of file channel.c.

References ast_free, and ast_party_subaddress::str.

Referenced by ast_party_dialed_free(), and ast_party_id_free().

02078 {
02079    ast_free(doomed->str);
02080    doomed->str = NULL;
02081 }

void ast_party_subaddress_init ( struct ast_party_subaddress *  init  ) 

Initialize the given subaddress structure.

Since:
1.8
Parameters:
init Subaddress structure to initialize.
Returns:
Nothing

Definition at line 2030 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(), and ast_party_id_init().

02031 {
02032    init->str = NULL;
02033    init->type = 0;
02034    init->odd_even_indicator = 0;
02035    init->valid = 0;
02036 }

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:
dest The subaddress one wishes to update
src The new subaddress values to update the dest
Returns:
Nothing

Definition at line 2060 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().

02061 {
02062    if (dest == src) {
02063       /* Don't set to self */
02064       return;
02065    }
02066 
02067    if (src->str && src->str != dest->str) {
02068       ast_free(dest->str);
02069       dest->str = ast_strdup(src->str);
02070    }
02071 
02072    dest->type = src->type;
02073    dest->odd_even_indicator = src->odd_even_indicator;
02074    dest->valid = src->valid;
02075 }

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:
init Party subaddress structure to initialize.
guide Source party subaddress to use as a guide in initializing.
Returns:
Nothing

Definition at line 2052 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().

02053 {
02054    init->str = NULL;
02055    init->type = guide->type;
02056    init->odd_even_indicator = guide->odd_even_indicator;
02057    init->valid = guide->valid;
02058 }

void ast_poll_channel_add ( struct ast_channel *  chan0,
struct ast_channel *  chan1 
)

Add a channel to an optimized waitfor

Definition at line 2661 of file channel.c.

References AST_MAX_FDS, and ast_channel::fds.

Referenced by ast_generic_bridge(), begin_dial_channel(), feature_request_and_dial(), local_bridge_loop(), remote_bridge_loop(), and wait_for_answer().

02662 {
02663 #ifdef HAVE_EPOLL
02664    struct epoll_event ev;
02665    int i = 0;
02666 
02667    if (chan0->epfd == -1)
02668       return;
02669 
02670    /* Iterate through the file descriptors on chan1, adding them to chan0 */
02671    for (i = 0; i < AST_MAX_FDS; i++) {
02672       if (chan1->fds[i] == -1)
02673          continue;
02674       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
02675       ev.data.ptr = chan1->epfd_data[i];
02676       epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev);
02677    }
02678 
02679 #endif
02680    return;
02681 }

void ast_poll_channel_del ( struct ast_channel *  chan0,
struct ast_channel *  chan1 
)

Delete a channel from an optimized waitfor

Definition at line 2684 of file channel.c.

References AST_MAX_FDS, and ast_channel::fds.

Referenced by ast_generic_bridge(), feature_request_and_dial(), local_bridge_loop(), monitor_dial(), remote_bridge_loop(), and wait_for_answer().

02685 {
02686 #ifdef HAVE_EPOLL
02687    struct epoll_event ev;
02688    int i = 0;
02689 
02690    if (chan0->epfd == -1)
02691       return;
02692 
02693    for (i = 0; i < AST_MAX_FDS; i++) {
02694       if (chan1->fds[i] == -1)
02695          continue;
02696       epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev);
02697    }
02698 
02699 #endif
02700    return;
02701 }

char* ast_print_group ( char *  buf,
int  buflen,
ast_group_t  group 
)

print call- and pickup groups into buffer

Definition at line 8134 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().

08135 {
08136    unsigned int i;
08137    int first = 1;
08138    char num[3];
08139 
08140    buf[0] = '\0';
08141    
08142    if (!group) /* Return empty string if no group */
08143       return buf;
08144 
08145    for (i = 0; i <= 63; i++) {   /* Max group is 63 */
08146       if (group & ((ast_group_t) 1 << i)) {
08147             if (!first) {
08148             strncat(buf, ", ", buflen - strlen(buf) - 1);
08149          } else {
08150             first = 0;
08151          }
08152          snprintf(num, sizeof(num), "%u", i);
08153          strncat(buf, num, buflen - strlen(buf) - 1);
08154       }
08155    }
08156    return buf;
08157 }

int ast_prod ( struct ast_channel *  chan  ) 

Send empty audio to prime a channel driver.

Definition at line 4735 of file channel.c.

References ast_channel::_state, ast_debug, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), ast_frame_subclass::codec, ast_frame::data, LOG_WARNING, ast_frame::ptr, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.

Referenced by ast_activate_generator().

04736 {
04737    struct ast_frame a = { AST_FRAME_VOICE };
04738    char nothing[128];
04739 
04740    /* Send an empty audio frame to get things moving */
04741    if (chan->_state != AST_STATE_UP) {
04742       ast_debug(1, "Prodding channel '%s'\n", chan->name);
04743       a.subclass.codec = chan->rawwriteformat;
04744       a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
04745       a.src = "ast_prod"; /* this better match check in ast_write */
04746       if (ast_write(chan, &a))
04747          ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name);
04748    }
04749    return 0;
04750 }

int ast_queue_control ( struct ast_channel *  chan,
enum ast_control_frame_type  control 
)

Queue a control frame with payload.

Parameters:
chan channel to queue frame onto
control type of control frame
Note:
The channel does not need to be locked before calling this function.
Return values:
zero on success
non-zero on failure

Definition at line 1597 of file channel.c.

References AST_FRAME_CONTROL, and ast_queue_frame().

Referenced by __analog_handle_event(), __analog_ss_thread(), __ast_read(), __dahdi_exception(), __oh323_update_info(), analog_call(), analog_exception(), analog_hangup(), analog_ss_thread(), ast_do_pickup(), attempt_transfer(), auto_congest(), cb_events(), cli_console_answer(), cli_console_flash(), console_answer(), console_call(), console_sendtext(), dahdi_handle_event(), dahdi_hangup(), gtalk_is_answered(), gtalk_ringing_ack(), handle_hd_hf(), handle_incoming(), handle_offhook_message(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_refer(), handle_soft_key_event_message(), handle_stimulus_message(), HandleCallIncoming(), jingle_is_answered(), jingle_ringing_ack(), masquerade_colp_transfer(), misdn_facility_ie_handler(), multicast_rtp_call(), nbs_call(), phone_call(), process_sdp(), receive_digit(), remote_hold(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_transfer(), skinny_unhold(), unistim_call(), and update_state().

01598 {
01599    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control };
01600    return ast_queue_frame(chan, &f);
01601 }

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:
chan channel to queue frame onto
control type of control frame
data pointer to payload data to be included in frame
datalen number of bytes of payload data
Return values:
0 success
non-zero failure

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 1604 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(), handle_request_notify(), handle_response_refer(), iax2_queue_control_data(), iax2_transfer(), interpret_t38_parameters(), local_attended_transfer(), masquerade_colp_transfer(), process_sdp(), sip_sipredirect(), and skinny_hold().

01606 {
01607    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control, .data.ptr = (void *) data, .datalen = datalen };
01608    return ast_queue_frame(chan, &f);
01609 }

int ast_queue_frame ( struct ast_channel *  chan,
struct ast_frame *  f 
)
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:
chan the channel to queue the frame(s) on
f the 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:
0 success
non-zero failure

Definition at line 1559 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().

01560 {
01561    return __ast_queue_frame(chan, fin, 1, NULL);
01562 }

int ast_queue_hangup ( struct ast_channel *  chan  ) 

Queue a hangup frame.

Note:
The channel does not need to be locked before calling this function.

Definition at line 1565 of file channel.c.

References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), and AST_SOFTHANGUP_DEV.

Referenced by bridge_queue_hangup(), cleanup_connection(), cli_console_hangup(), close_call(), gtalk_hangup_farend(), gtalk_is_answered(), handle_onhook_message(), handle_request_bye(), handle_soft_key_event_message(), iax2_destroy(), iax2_queue_hangup(), jingle_hangup_farend(), local_fixup(), local_hangup(), mgcp_queue_hangup(), and sip_queue_hangup_cause().

01566 {
01567    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
01568    /* Yeah, let's not change a lock-critical value without locking */
01569    if (!ast_channel_trylock(chan)) {
01570       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01571       ast_channel_unlock(chan);
01572    }
01573    return ast_queue_frame(chan, &f);
01574 }

int ast_queue_hangup_with_cause ( struct ast_channel *  chan,
int  cause 
)

Queue a hangup frame with hangupcause set.

Note:
The channel does not need to be locked before calling this function.
Parameters:
[in] chan channel to queue frame onto
[in] cause the hangup cause
Returns:
0 on success, -1 on error
Since:
1.6.1

Definition at line 1577 of file channel.c.

References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, ast_frame::data, ast_channel::hangupcause, and ast_frame::uint32.

Referenced by __analog_handle_event(), __oh323_update_info(), __sip_autodestruct(), close_call(), close_client(), console_hangup(), dahdi_handle_event(), handle_request_bye(), handle_response(), handle_response_invite(), HandleCallOutgoing(), hangup_chan(), hangup_connection(), misdn_answer(), retrans_pkt(), sip_queue_hangup_cause(), and TransferCallStep1().

01578 {
01579    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
01580 
01581    if (cause >= 0)
01582       f.data.uint32 = cause;
01583 
01584    /* Yeah, let's not change a lock-critical value without locking */
01585    if (!ast_channel_trylock(chan)) {
01586       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01587       if (cause < 0)
01588          f.data.uint32 = chan->hangupcause;
01589 
01590       ast_channel_unlock(chan);
01591    }
01592 
01593    return ast_queue_frame(chan, &f);
01594 }

int ast_raw_answer ( struct ast_channel *  chan,
int  cdr_answer 
)

Answer a channel.

Parameters:
chan channel to answer
cdr_answer flag 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:
0 on success
non-zero on failure

Definition at line 2926 of file channel.c.

References ast_channel::_state, ast_channel_tech::answer, ast_cdr_answer(), AST_CEL_ANSWER, ast_cel_report_event(), ast_channel_lock, 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, ast_test_flag, ast_channel::cdr, and ast_channel::tech.

Referenced by __ast_answer(), and ast_bridge_call().

02927 {
02928    int res = 0;
02929 
02930    ast_channel_lock(chan);
02931 
02932    /* You can't answer an outbound call */
02933    if (ast_test_flag(chan, AST_FLAG_OUTGOING)) {
02934       ast_channel_unlock(chan);
02935       return 0;
02936    }
02937 
02938    /* Stop if we're a zombie or need a soft hangup */
02939    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
02940       ast_channel_unlock(chan);
02941       return -1;
02942    }
02943 
02944    ast_channel_unlock(chan);
02945 
02946    switch (chan->_state) {
02947    case AST_STATE_RINGING:
02948    case AST_STATE_RING:
02949       ast_channel_lock(chan);
02950       if (chan->tech->answer) {
02951          res = chan->tech->answer(chan);
02952       }
02953       ast_setstate(chan, AST_STATE_UP);
02954       if (cdr_answer) {
02955          ast_cdr_answer(chan->cdr);
02956       }
02957       ast_cel_report_event(chan, AST_CEL_ANSWER, NULL, NULL, NULL);
02958       ast_channel_unlock(chan);
02959       break;
02960    case AST_STATE_UP:
02961       ast_cel_report_event(chan, AST_CEL_ANSWER, NULL, NULL, NULL);
02962       /* Calling ast_cdr_answer when it it has previously been called
02963        * is essentially a no-op, so it is safe.
02964        */
02965       if (cdr_answer) {
02966          ast_cdr_answer(chan->cdr);
02967       }
02968       break;
02969    default:
02970       break;
02971    }
02972 
02973    ast_indicate(chan, -1);
02974 
02975    return res;
02976 }

struct ast_frame* ast_read ( struct ast_channel *  chan  )  [read]

Reads a frame.

Parameters:
chan channel 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 4334 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_bridge(), dial_exec_full(), dictate_exec(), disa_exec(), disable_t38(), 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().

04335 {
04336    return __ast_read(chan, 0);
04337 }

struct ast_frame* ast_read_noaudio ( struct ast_channel *  chan  )  [read]

Reads a frame, returning AST_FRAME_NULL frame if audio.

Parameters:
chan channel 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 4339 of file channel.c.

References __ast_read().

Referenced by ast_bridge_handle_trip(), and conf_run().

04340 {
04341    return __ast_read(chan, 1);
04342 }

int ast_readstring ( struct ast_channel *  c,
char *  s,
int  len,
int  timeout,
int  rtimeout,
char *  enders 
)

Reads multiple digits.

Parameters:
c channel to read from
s string to read in to. Must be at least the size of your length
len how many digits to read (maximum)
timeout how long to timeout between digits
rtimeout timeout to wait on the first digit
enders digits 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 5788 of file channel.c.

References ast_readstring_full().

Referenced by __adsi_transmit_messages(), adsi_begin_download(), adsi_get_cpeinfo(), adsi_load_session(), ast_app_getdata(), dialout(), do_directory(), forward_message(), privacy_exec(), vm_authenticate(), vm_newuser(), and vm_options().

05789 {
05790    return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
05791 }

int ast_readstring_full ( struct ast_channel *  c,
char *  s,
int  len,
int  timeout,
int  rtimeout,
char *  enders,
int  audiofd,
int  ctrlfd 
)

Definition at line 5793 of file channel.c.

References ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), 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(), ast_waitstream_full(), and ast_channel::stream.

Referenced by ast_app_getdata_full(), and ast_readstring().

05794 {
05795    int pos = 0;   /* index in the buffer where we accumulate digits */
05796    int to = ftimeout;
05797 
05798    struct ast_silence_generator *silgen = NULL;
05799 
05800    /* Stop if we're a zombie or need a soft hangup */
05801    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
05802       return -1;
05803    if (!len)
05804       return -1;
05805    for (;;) {
05806       int d;
05807       if (c->stream) {
05808          d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
05809          ast_stopstream(c);
05810          if (!silgen && ast_opt_transmit_silence)
05811             silgen = ast_channel_start_silence_generator(c);
05812          usleep(1000);
05813          if (!d)
05814             d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
05815       } else {
05816          if (!silgen && ast_opt_transmit_silence)
05817             silgen = ast_channel_start_silence_generator(c);
05818          d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
05819       }
05820       if (d < 0) {
05821          ast_channel_stop_silence_generator(c, silgen);
05822          return AST_GETDATA_FAILED;
05823       }
05824       if (d == 0) {
05825          s[pos] = '\0';
05826          ast_channel_stop_silence_generator(c, silgen);
05827          return AST_GETDATA_TIMEOUT;
05828       }
05829       if (d == 1) {
05830          s[pos] = '\0';
05831          ast_channel_stop_silence_generator(c, silgen);
05832          return AST_GETDATA_INTERRUPTED;
05833       }
05834       if (strchr(enders, d) && (pos == 0)) {
05835          s[pos] = '\0';
05836          ast_channel_stop_silence_generator(c, silgen);
05837          return AST_GETDATA_EMPTY_END_TERMINATED;
05838       }
05839       if (!strchr(enders, d)) {
05840          s[pos++] = d;
05841       }
05842       if (strchr(enders, d) || (pos >= len)) {
05843          s[pos] = '\0';
05844          ast_channel_stop_silence_generator(c, silgen);
05845          return AST_GETDATA_COMPLETE;
05846       }
05847       to = timeout;
05848    }
05849    /* Never reached */
05850    return 0;
05851 }

int ast_recvchar ( struct ast_channel *  chan,
int  timeout 
)

Receives a text character from a channel.

Parameters:
chan channel to act upon
timeout timeout in milliseconds (0 for infinite wait)

Read a char of text from a channel

Returns:
0 on success, -1 on failure

Definition at line 4593 of file channel.c.

References ast_free, and ast_recvtext().

Referenced by handle_recvchar().

04594 {
04595    int c;
04596    char *buf = ast_recvtext(chan, timeout);
04597    if (buf == NULL)
04598       return -1;  /* error or timeout */
04599    c = *(unsigned char *)buf;
04600    ast_free(buf);
04601    return c;
04602 }

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:
chan channel to act upon
timeout timeout in milliseconds (0 for infinite wait)
Returns:
the received text, or NULL to signify failure.

Definition at line 4604 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, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::ptr, and ast_frame::subclass.

Referenced by ast_recvchar(), and handle_recvtext().

04605 {
04606    int res;
04607    char *buf = NULL;
04608    struct timeval start = ast_tvnow();
04609    int ms;
04610 
04611    while ((ms = ast_remaining_ms(start, timeout))) {
04612       struct ast_frame *f;
04613 
04614       if (ast_check_hangup(chan)) {
04615          break;
04616       }
04617       res = ast_waitfor(chan, ms);
04618       if (res <= 0)  {/* timeout or error */
04619          break;
04620       }
04621       f = ast_read(chan);
04622       if (f == NULL) {
04623          break; /* no frame */
04624       }
04625       if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_HANGUP) {
04626          ast_frfree(f);
04627          break;
04628       } else if (f->frametype == AST_FRAME_TEXT) {    /* what we want */
04629          buf = ast_strndup((char *) f->data.ptr, f->datalen);  /* dup and break */
04630          ast_frfree(f);
04631          break;
04632       }
04633       ast_frfree(f);
04634    }
04635    return buf;
04636 }

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:
data Buffer to fill with the frame data
datalen Size of the buffer to fill
redirecting Redirecting id information
update What redirecting information to build. NULL if all.
Return values:
-1 if error
Amount of data buffer used

Definition at line 9064 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_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_set_party_redirecting::from, ast_party_redirecting::from, LOG_WARNING, ast_party_id_ies::name, party_id_build_data(), ast_party_redirecting::reason, ast_party_name_ies::str, ast_set_party_redirecting::to, ast_party_redirecting::to, and value.

Referenced by ast_channel_queue_redirecting_update(), ast_channel_update_redirecting(), and local_indicate().

09065 {
09066    int32_t value;
09067    size_t pos = 0;
09068    int res;
09069 
09070    static const struct ast_party_id_ies from_ies = {
09071       .name.str = AST_REDIRECTING_FROM_NAME,
09072       .name.char_set = AST_REDIRECTING_FROM_NAME_CHAR_SET,
09073       .name.presentation = AST_REDIRECTING_FROM_NAME_PRESENTATION,
09074       .name.valid = AST_REDIRECTING_FROM_NAME_VALID,
09075 
09076       .number.str = AST_REDIRECTING_FROM_NUMBER,
09077       .number.plan = AST_REDIRECTING_FROM_NUMBER_PLAN,
09078       .number.presentation = AST_REDIRECTING_FROM_NUMBER_PRESENTATION,
09079       .number.valid = AST_REDIRECTING_FROM_NUMBER_VALID,
09080 
09081       .subaddress.str = AST_REDIRECTING_FROM_SUBADDRESS,
09082       .subaddress.type = AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
09083       .subaddress.odd_even_indicator = AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN,
09084       .subaddress.valid = AST_REDIRECTING_FROM_SUBADDRESS_VALID,
09085 
09086       .tag = AST_REDIRECTING_FROM_TAG,
09087       .combined_presentation = AST_REDIRECTING_FROM_ID_PRESENTATION,
09088    };
09089    static const struct ast_party_id_ies to_ies = {
09090       .name.str = AST_REDIRECTING_TO_NAME,
09091       .name.char_set = AST_REDIRECTING_TO_NAME_CHAR_SET,
09092       .name.presentation = AST_REDIRECTING_TO_NAME_PRESENTATION,
09093       .name.valid = AST_REDIRECTING_TO_NAME_VALID,
09094 
09095       .number.str = AST_REDIRECTING_TO_NUMBER,
09096       .number.plan = AST_REDIRECTING_TO_NUMBER_PLAN,
09097       .number.presentation = AST_REDIRECTING_TO_NUMBER_PRESENTATION,
09098       .number.valid = AST_REDIRECTING_TO_NUMBER_VALID,
09099 
09100       .subaddress.str = AST_REDIRECTING_TO_SUBADDRESS,
09101       .subaddress.type = AST_REDIRECTING_TO_SUBADDRESS_TYPE,
09102       .subaddress.odd_even_indicator = AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN,
09103       .subaddress.valid = AST_REDIRECTING_TO_SUBADDRESS_VALID,
09104 
09105       .tag = AST_REDIRECTING_TO_TAG,
09106       .combined_presentation = AST_REDIRECTING_TO_ID_PRESENTATION,
09107    };
09108 
09109    /* Redirecting frame version */
09110    if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
09111       ast_log(LOG_WARNING, "No space left for redirecting frame version\n");
09112       return -1;
09113    }
09114    data[pos++] = AST_REDIRECTING_VERSION;
09115    data[pos++] = 1;
09116    data[pos++] = 2;/* Version 1 did not have a version ie */
09117 
09118    res = party_id_build_data(data + pos, datalen - pos, &redirecting->from,
09119       "redirecting-from", &from_ies, update ? &update->from : NULL);
09120    if (res < 0) {
09121       return -1;
09122    }
09123    pos += res;
09124 
09125    res = party_id_build_data(data + pos, datalen - pos, &redirecting->to,
09126       "redirecting-to", &to_ies, update ? &update->to : NULL);
09127    if (res < 0) {
09128       return -1;
09129    }
09130    pos += res;
09131 
09132    /* Redirecting reason */
09133    if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
09134       ast_log(LOG_WARNING, "No space left for redirecting reason\n");
09135       return -1;
09136    }
09137    data[pos++] = AST_REDIRECTING_REASON;
09138    data[pos++] = sizeof(value);
09139    value = htonl(redirecting->reason);
09140    memcpy(data + pos, &value, sizeof(value));
09141    pos += sizeof(value);
09142 
09143    /* Redirecting count */
09144    if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
09145       ast_log(LOG_WARNING, "No space left for redirecting count\n");
09146       return -1;
09147    }
09148    data[pos++] = AST_REDIRECTING_COUNT;
09149    data[pos++] = sizeof(value);
09150    value = htonl(redirecting->count);
09151    memcpy(data + pos, &value, sizeof(value));
09152    pos += sizeof(value);
09153 
09154    return pos;
09155 }

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:
data Buffer with the frame data to parse
datalen Size of the buffer
redirecting Extracted redirecting id information
Return values:
0 on success.
-1 on 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 9157 of file channel.c.

References 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_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_DEBUG, LOG_WARNING, ast_party_id::name, ast_party_id::number, ast_party_subaddress::odd_even_indicator, ast_party_number::plan, ast_party_number::presentation, ast_party_name::presentation, ast_party_redirecting::reason, ast_party_subaddress::str, ast_party_number::str, ast_party_name::str, ast_party_id::subaddress, ast_party_id::tag, ast_party_redirecting::to, ast_party_subaddress::type, ast_party_subaddress::valid, ast_party_number::valid, ast_party_name::valid, and value.

Referenced by ast_channel_redirecting_macro(), and ast_indicate_data().

09158 {
09159    size_t pos;
09160    unsigned char ie_len;
09161    unsigned char ie_id;
09162    int32_t value;
09163    int frame_version = 1;
09164    int from_combined_presentation = 0;
09165    int got_from_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
09166    int to_combined_presentation = 0;
09167    int got_to_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
09168 
09169    for (pos = 0; pos < datalen; pos += ie_len) {
09170       if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
09171          ast_log(LOG_WARNING, "Invalid redirecting update\n");
09172          return -1;
09173       }
09174       ie_id = data[pos++];
09175       ie_len = data[pos++];
09176       if (datalen < pos + ie_len) {
09177          ast_log(LOG_WARNING, "Invalid redirecting update\n");
09178          return -1;
09179       }
09180 
09181       switch (ie_id) {
09182 /* Redirecting frame version */
09183       case AST_REDIRECTING_VERSION:
09184          if (ie_len != 1) {
09185             ast_log(LOG_WARNING, "Invalid redirecting frame version (%u)\n",
09186                (unsigned) ie_len);
09187             break;
09188          }
09189          frame_version = data[pos];
09190          break;
09191 /* Redirecting-from party id name */
09192       case AST_REDIRECTING_FROM_NAME:
09193          ast_free(redirecting->from.name.str);
09194          redirecting->from.name.str = ast_malloc(ie_len + 1);
09195          if (redirecting->from.name.str) {
09196             memcpy(redirecting->from.name.str, data + pos, ie_len);
09197             redirecting->from.name.str[ie_len] = 0;
09198          }
09199          break;
09200       case AST_REDIRECTING_FROM_NAME_CHAR_SET:
09201          if (ie_len != 1) {
09202             ast_log(LOG_WARNING, "Invalid redirecting-from name char set (%u)\n",
09203                (unsigned) ie_len);
09204             break;
09205          }
09206          redirecting->from.name.char_set = data[pos];
09207          break;
09208       case AST_REDIRECTING_FROM_NAME_PRESENTATION:
09209          if (ie_len != 1) {
09210             ast_log(LOG_WARNING, "Invalid redirecting-from name presentation (%u)\n",
09211                (unsigned) ie_len);
09212             break;
09213          }
09214          redirecting->from.name.presentation = data[pos];
09215          break;
09216       case AST_REDIRECTING_FROM_NAME_VALID:
09217          if (ie_len != 1) {
09218             ast_log(LOG_WARNING, "Invalid redirecting-from name valid (%u)\n",
09219                (unsigned) ie_len);
09220             break;
09221          }
09222          redirecting->from.name.valid = data[pos];
09223          break;
09224 /* Redirecting-from party id number */
09225       case AST_REDIRECTING_FROM_NUMBER:
09226          ast_free(redirecting->from.number.str);
09227          redirecting->from.number.str = ast_malloc(ie_len + 1);
09228          if (redirecting->from.number.str) {
09229             memcpy(redirecting->from.number.str, data + pos, ie_len);
09230             redirecting->from.number.str[ie_len] = 0;
09231          }
09232          break;
09233       case AST_REDIRECTING_FROM_NUMBER_PLAN:
09234          if (ie_len != 1) {
09235             ast_log(LOG_WARNING, "Invalid redirecting-from numbering plan (%u)\n",
09236                (unsigned) ie_len);
09237             break;
09238          }
09239          redirecting->from.number.plan = data[pos];
09240          break;
09241       case AST_REDIRECTING_FROM_NUMBER_PRESENTATION:
09242          if (ie_len != 1) {
09243             ast_log(LOG_WARNING, "Invalid redirecting-from number presentation (%u)\n",
09244                (unsigned) ie_len);
09245             break;
09246          }
09247          redirecting->from.number.presentation = data[pos];
09248          break;
09249       case AST_REDIRECTING_FROM_NUMBER_VALID:
09250          if (ie_len != 1) {
09251             ast_log(LOG_WARNING, "Invalid redirecting-from number valid (%u)\n",
09252                (unsigned) ie_len);
09253             break;
09254          }
09255          redirecting->from.number.valid = data[pos];
09256          break;
09257 /* Redirecting-from party id combined presentation */
09258       case AST_REDIRECTING_FROM_ID_PRESENTATION:
09259          if (ie_len != 1) {
09260             ast_log(LOG_WARNING, "Invalid redirecting-from combined presentation (%u)\n",
09261                (unsigned) ie_len);
09262             break;
09263          }
09264          from_combined_presentation = data[pos];
09265          got_from_combined_presentation = 1;
09266          break;
09267 /* Redirecting-from party id subaddress */
09268       case AST_REDIRECTING_FROM_SUBADDRESS:
09269          ast_free(redirecting->from.subaddress.str);
09270          redirecting->from.subaddress.str = ast_malloc(ie_len + 1);
09271          if (redirecting->from.subaddress.str) {
09272             memcpy(redirecting->from.subaddress.str, data + pos, ie_len);
09273             redirecting->from.subaddress.str[ie_len] = 0;
09274          }
09275          break;
09276       case AST_REDIRECTING_FROM_SUBADDRESS_TYPE:
09277          if (ie_len != 1) {
09278             ast_log(LOG_WARNING, "Invalid redirecting-from type of subaddress (%u)\n",
09279                (unsigned) ie_len);
09280             break;
09281          }
09282          redirecting->from.subaddress.type = data[pos];
09283          break;
09284       case AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN:
09285          if (ie_len != 1) {
09286             ast_log(LOG_WARNING,
09287                "Invalid redirecting-from subaddress odd-even indicator (%u)\n",
09288                (unsigned) ie_len);
09289             break;
09290          }
09291          redirecting->from.subaddress.odd_even_indicator = data[pos];
09292          break;
09293       case AST_REDIRECTING_FROM_SUBADDRESS_VALID:
09294          if (ie_len != 1) {
09295             ast_log(LOG_WARNING, "Invalid redirecting-from subaddress valid (%u)\n",
09296                (unsigned) ie_len);
09297             break;
09298          }
09299          redirecting->from.subaddress.valid = data[pos];
09300          break;
09301 /* Redirecting-from party id tag */
09302       case AST_REDIRECTING_FROM_TAG:
09303          ast_free(redirecting->from.tag);
09304          redirecting->from.tag = ast_malloc(ie_len + 1);
09305          if (redirecting->from.tag) {
09306             memcpy(redirecting->from.tag, data + pos, ie_len);
09307             redirecting->from.tag[ie_len] = 0;
09308          }
09309          break;
09310 /* Redirecting-to party id name */
09311       case AST_REDIRECTING_TO_NAME:
09312          ast_free(redirecting->to.name.str);
09313          redirecting->to.name.str = ast_malloc(ie_len + 1);
09314          if (redirecting->to.name.str) {
09315             memcpy(redirecting->to.name.str, data + pos, ie_len);
09316             redirecting->to.name.str[ie_len] = 0;
09317          }
09318          break;
09319       case AST_REDIRECTING_TO_NAME_CHAR_SET:
09320          if (ie_len != 1) {
09321             ast_log(LOG_WARNING, "Invalid redirecting-to name char set (%u)\n",
09322                (unsigned) ie_len);
09323             break;
09324          }
09325          redirecting->to.name.char_set = data[pos];
09326          break;
09327       case AST_REDIRECTING_TO_NAME_PRESENTATION:
09328          if (ie_len != 1) {
09329             ast_log(LOG_WARNING, "Invalid redirecting-to name presentation (%u)\n",
09330                (unsigned) ie_len);
09331             break;
09332          }
09333          redirecting->to.name.presentation = data[pos];
09334          break;
09335       case AST_REDIRECTING_TO_NAME_VALID:
09336          if (ie_len != 1) {
09337             ast_log(LOG_WARNING, "Invalid redirecting-to name valid (%u)\n",
09338                (unsigned) ie_len);
09339             break;
09340          }
09341          redirecting->to.name.valid = data[pos];
09342          break;
09343 /* Redirecting-to party id number */
09344       case AST_REDIRECTING_TO_NUMBER:
09345          ast_free(redirecting->to.number.str);
09346          redirecting->to.number.str = ast_malloc(ie_len + 1);
09347          if (redirecting->to.number.str) {
09348             memcpy(redirecting->to.number.str, data + pos, ie_len);
09349             redirecting->to.number.str[ie_len] = 0;
09350          }
09351          break;
09352       case AST_REDIRECTING_TO_NUMBER_PLAN:
09353          if (ie_len != 1) {
09354             ast_log(LOG_WARNING, "Invalid redirecting-to numbering plan (%u)\n",
09355                (unsigned) ie_len);
09356             break;
09357          }
09358          redirecting->to.number.plan = data[pos];
09359          break;
09360       case AST_REDIRECTING_TO_NUMBER_PRESENTATION:
09361          if (ie_len != 1) {
09362             ast_log(LOG_WARNING, "Invalid redirecting-to number presentation (%u)\n",
09363                (unsigned) ie_len);
09364             break;
09365          }
09366          redirecting->to.number.presentation = data[pos];
09367          break;
09368       case AST_REDIRECTING_TO_NUMBER_VALID:
09369          if (ie_len != 1) {
09370             ast_log(LOG_WARNING, "Invalid redirecting-to number valid (%u)\n",
09371                (unsigned) ie_len);
09372             break;
09373          }
09374          redirecting->to.number.valid = data[pos];
09375          break;
09376 /* Redirecting-to party id combined presentation */
09377       case AST_REDIRECTING_TO_ID_PRESENTATION:
09378          if (ie_len != 1) {
09379             ast_log(LOG_WARNING, "Invalid redirecting-to combined presentation (%u)\n",
09380                (unsigned) ie_len);
09381             break;
09382          }
09383          to_combined_presentation = data[pos];
09384          got_to_combined_presentation = 1;
09385          break;
09386 /* Redirecting-to party id subaddress */
09387       case AST_REDIRECTING_TO_SUBADDRESS:
09388          ast_free(redirecting->to.subaddress.str);
09389          redirecting->to.subaddress.str = ast_malloc(ie_len + 1);
09390          if (redirecting->to.subaddress.str) {
09391             memcpy(redirecting->to.subaddress.str, data + pos, ie_len);
09392             redirecting->to.subaddress.str[ie_len] = 0;
09393          }
09394          break;
09395       case AST_REDIRECTING_TO_SUBADDRESS_TYPE:
09396          if (ie_len != 1) {
09397             ast_log(LOG_WARNING, "Invalid redirecting-to type of subaddress (%u)\n",
09398                (unsigned) ie_len);
09399             break;
09400          }
09401          redirecting->to.subaddress.type = data[pos];
09402          break;
09403       case AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN:
09404          if (ie_len != 1) {
09405             ast_log(LOG_WARNING,
09406                "Invalid redirecting-to subaddress odd-even indicator (%u)\n",
09407                (unsigned) ie_len);
09408             break;
09409          }
09410          redirecting->to.subaddress.odd_even_indicator = data[pos];
09411          break;
09412       case AST_REDIRECTING_TO_SUBADDRESS_VALID:
09413          if (ie_len != 1) {
09414             ast_log(LOG_WARNING, "Invalid redirecting-to subaddress valid (%u)\n",
09415                (unsigned) ie_len);
09416             break;
09417          }
09418          redirecting->to.subaddress.valid = data[pos];
09419          break;
09420 /* Redirecting-to party id tag */
09421       case AST_REDIRECTING_TO_TAG:
09422          ast_free(redirecting->to.tag);
09423          redirecting->to.tag = ast_malloc(ie_len + 1);
09424          if (redirecting->to.tag) {
09425             memcpy(redirecting->to.tag, data + pos, ie_len);
09426             redirecting->to.tag[ie_len] = 0;
09427          }
09428          break;
09429 /* Redirecting reason */
09430       case AST_REDIRECTING_REASON:
09431          if (ie_len != sizeof(value)) {
09432             ast_log(LOG_WARNING, "Invalid redirecting reason (%u)\n",
09433                (unsigned) ie_len);
09434             break;
09435          }
09436          memcpy(&value, data + pos, sizeof(value));
09437          redirecting->reason = ntohl(value);
09438          break;
09439 /* Redirecting count */
09440       case AST_REDIRECTING_COUNT:
09441          if (ie_len != sizeof(value)) {
09442             ast_log(LOG_WARNING, "Invalid redirecting count (%u)\n",
09443                (unsigned) ie_len);
09444             break;
09445          }
09446          memcpy(&value, data + pos, sizeof(value));
09447          redirecting->count = ntohl(value);
09448          break;
09449 /* Redirecting unknown element */
09450       default:
09451          ast_log(LOG_DEBUG, "Unknown redirecting element: %u (%u)\n",
09452             (unsigned) ie_id, (unsigned) ie_len);
09453          break;
09454       }
09455    }
09456 
09457    switch (frame_version) {
09458    case 1:
09459       /*
09460        * The other end is an earlier version that we need to adjust
09461        * for compatibility.
09462        */
09463       redirecting->from.name.valid = 1;
09464       redirecting->from.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
09465       redirecting->from.number.valid = 1;
09466       if (got_from_combined_presentation) {
09467          redirecting->from.name.presentation = from_combined_presentation;
09468          redirecting->from.number.presentation = from_combined_presentation;
09469       }
09470 
09471       redirecting->to.name.valid = 1;
09472       redirecting->to.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
09473       redirecting->to.number.valid = 1;
09474       if (got_to_combined_presentation) {
09475          redirecting->to.name.presentation = to_combined_presentation;
09476          redirecting->to.number.presentation = to_combined_presentation;
09477       }
09478       break;
09479    case 2:
09480       /* The other end is at the same level as we are. */
09481       break;
09482    default:
09483       /*
09484        * The other end is newer than we are.
09485        * We need to assume that they are compatible with us.
09486        */
09487       ast_log(LOG_DEBUG, "Redirecting frame has newer version: %u\n",
09488          (unsigned) frame_version);
09489       break;
09490    }
09491 
09492    return 0;
09493 }

struct ast_channel* ast_request ( const char *  type,
format_t  format,
const struct ast_channel *  requestor,
void *  data,
int *  status 
) [read]

Requests a channel.

Parameters:
type type of channel to request
format requested channel format (codec)
requestor channel asking for data
data data to pass to the channel requester (Should be treated as const char *)
status status

Request a channel of a given type, with data as optional information used by the low level module

Return values:
NULL failure
non-NULL channel on success

Definition at line 5646 of file channel.c.

References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, ast_channel_release(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, ast_getformatname_multiple(), ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_translator_best_choice(), ast_channel_tech::capabilities, capabilities, LOG_WARNING, ast_channel_tech::requester, set_security_requirements(), chanlist::tech, and ast_channel_tech::type.

Referenced by __ast_request_and_dial(), ast_call_forward(), begin_dial_channel(), build_conf(), chanavail_exec(), conf_run(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), and wait_for_answer().

05647 {
05648    struct chanlist *chan;
05649    struct ast_channel *c;
05650    format_t capabilities;
05651    format_t fmt;
05652    int res;
05653    int foo;
05654    format_t videoformat = format & AST_FORMAT_VIDEO_MASK;
05655    format_t textformat = format & AST_FORMAT_TEXT_MASK;
05656 
05657    if (!cause)
05658       cause = &foo;
05659    *cause = AST_CAUSE_NOTDEFINED;
05660 
05661    if (AST_RWLIST_RDLOCK(&backends)) {
05662       ast_log(LOG_WARNING, "Unable to lock technology backend list\n");
05663       return NULL;
05664    }
05665 
05666    AST_RWLIST_TRAVERSE(&backends, chan, list) {
05667       if (strcasecmp(type, chan->tech->type))
05668          continue;
05669 
05670       capabilities = chan->tech->capabilities;
05671       fmt = format & AST_FORMAT_AUDIO_MASK;
05672       if (fmt) {
05673          /* We have audio - is it possible to connect the various calls to each other? 
05674             (Avoid this check for calls without audio, like text+video calls)
05675          */
05676          res = ast_translator_best_choice(&fmt, &capabilities);
05677          if (res < 0) {
05678             char tmp1[256], tmp2[256];
05679             ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %s) to %s\n", type,
05680                ast_getformatname_multiple(tmp1, sizeof(tmp1), chan->tech->capabilities),
05681                ast_getformatname_multiple(tmp2, sizeof(tmp2), format));
05682             *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
05683             AST_RWLIST_UNLOCK(&backends);
05684             return NULL;
05685          }
05686       }
05687       AST_RWLIST_UNLOCK(&backends);
05688       if (!chan->tech->requester)
05689          return NULL;
05690 
05691       if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, requestor, data, cause)))
05692          return NULL;
05693 
05694       if (set_security_requirements(requestor, c)) {
05695          ast_log(LOG_WARNING, "Setting security requirements failed\n");
05696          c = ast_channel_release(c);
05697          *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
05698          return NULL;
05699       }
05700 
05701       /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
05702       return c;
05703    }
05704 
05705    ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
05706    *cause = AST_CAUSE_NOSUCHDRIVER;
05707    AST_RWLIST_UNLOCK(&backends);
05708 
05709    return NULL;
05710 }

struct ast_channel* ast_request_and_dial ( const char *  type,
format_t  format,
const struct ast_channel *  requestor,
void *  data,
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:
type type of channel to request
format requested channel format
requestor channel asking for data
data data to pass to the channel requester
timeout maximum amount of time to wait for an answer
reason why unsuccessful (if unsuccessful)
cid_num Caller-ID Number
cid_name Caller-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 5601 of file channel.c.

References __ast_request_and_dial().

Referenced by ast_pbx_outgoing_exten(), and generic_recall().

05602 {
05603    return __ast_request_and_dial(type, format, requestor, data, timeout, outstate, cidnum, cidname, NULL);
05604 }

int ast_safe_sleep ( struct ast_channel *  chan,
int  ms 
)

Wait for a specified amount of time, looking for hangups.

Parameters:
chan channel to wait for
ms length of time in milliseconds to sleep. This should never be less than zero.

Waits for a specified amount of time, servicing the channel as required.

Returns:
returns -1 on hangup, otherwise 0.

Definition at line 1912 of file channel.c.

References ast_safe_sleep_conditional().

Referenced by __analog_ss_thread(), adsi_transmit_message_full(), alarmreceiver_exec(), analog_ss_thread(), ast_dtmf_stream(), ast_senddigit(), builtin_atxfer(), builtin_parkcall(), conf_run(), dictate_exec(), disa_exec(), flash_exec(), handle_callforward_button(), login_exec(), mgcp_ss(), milliwatt_exec(), misdn_check_l2l1(), old_milliwatt_exec(), park_call_exec(), pbx_builtin_wait(), play_moh_exec(), playtone(), privacy_exec(), receive_ademco_contact_id(), skinny_ss(), testclient_exec(), testserver_exec(), try_calling(), wait_for_hangup(), wait_moh_exec(), waituntil_exec(), and zapateller_exec().

01913 {
01914    return ast_safe_sleep_conditional(chan, ms, NULL, NULL);
01915 }

int ast_safe_sleep_conditional ( struct ast_channel *  chan,
int  timeout_ms,
int(*)(void *)  cond,
void *  data 
)

Wait for a specified amount of time, looking for hangups and a condition argument.

Parameters:
chan channel to wait for
ms length of time in milliseconds to sleep.
cond a function pointer for testing continue condition
data argument to be passed to the condition test function
Returns:
returns -1 on hangup, otherwise 0.

Waits for a specified amount of time, servicing the channel as required. If cond returns 0, this function returns.

Definition at line 1841 of file channel.c.

References 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 ast_channel::generatordata.

Referenced by ast_safe_sleep(), and login_exec().

01842 {
01843    struct ast_frame *f;
01844    struct ast_silence_generator *silgen = NULL;
01845    int res = 0;
01846    struct timeval start;
01847    int ms;
01848    AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
01849 
01850    AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
01851 
01852    /* If no other generator is present, start silencegen while waiting */
01853    if (ast_opt_transmit_silence && !chan->generatordata) {
01854       silgen = ast_channel_start_silence_generator(chan);
01855    }
01856 
01857    start = ast_tvnow();
01858    while ((ms = ast_remaining_ms(start, timeout_ms))) {
01859       struct ast_frame *dup_f = NULL;
01860 
01861       if (cond && ((*cond)(data) == 0)) {
01862          break;
01863       }
01864       ms = ast_waitfor(chan, ms);
01865       if (ms < 0) {
01866          res = -1;
01867          break;
01868       }
01869       if (ms > 0) {
01870          f = ast_read(chan);
01871          if (!f) {
01872             res = -1;
01873             break;
01874          }
01875 
01876          if (!ast_is_deferrable_frame(f)) {
01877             ast_frfree(f);
01878             continue;
01879          }
01880          
01881          if ((dup_f = ast_frisolate(f))) {
01882             if (dup_f != f) {
01883                ast_frfree(f);
01884             }
01885             AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
01886          }
01887       }
01888    }
01889 
01890    /* stop silgen if present */
01891    if (silgen) {
01892       ast_channel_stop_silence_generator(chan, silgen);
01893    }
01894 
01895    /* We need to free all the deferred frames, but we only need to
01896     * queue the deferred frames if there was no error and no
01897     * hangup was received
01898     */
01899    ast_channel_lock(chan);
01900    while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
01901       if (!res) {
01902          ast_queue_frame_head(chan, f);
01903       }
01904       ast_frfree(f);
01905    }
01906    ast_channel_unlock(chan);
01907 
01908    return res;
01909 }

int ast_senddigit ( struct ast_channel *  chan,
char  digit,
unsigned int  duration 
)

Send a DTMF digit to a channel.

Parameters:
chan channel to act upon
digit the DTMF digit to send, encoded in ASCII
duration the duration of the digit ending in ms
Returns:
0 on success, -1 on failure

Definition at line 4725 of file channel.c.

References AST_DEFAULT_EMULATE_DTMF_DURATION, ast_safe_sleep(), ast_senddigit_begin(), ast_senddigit_end(), ast_channel_tech::send_digit_begin, and ast_channel::tech.

Referenced by ast_dtmf_stream(), dial_exec_full(), and manager_play_dtmf().

04726 {
04727    if (chan->tech->send_digit_begin) {
04728       ast_senddigit_begin(chan, digit);
04729       ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
04730    }
04731    
04732    return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
04733 }

int ast_senddigit_begin ( struct ast_channel *  chan,
char  digit 
)

Send a DTMF digit to a channel.

Parameters:
chan channel to act upon
digit the DTMF digit to send, encoded in ASCII
Returns:
0 on success, -1 on failure

Definition at line 4656 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_debug, ast_playtones_start(), ast_tvnow(), ast_channel_tech::send_digit_begin, ast_channel::sending_dtmf_digit, ast_channel::sending_dtmf_tv, and ast_channel::tech.

Referenced by agent_digit_begin(), ast_senddigit(), and ast_write().

04657 {
04658    /* Device does not support DTMF tones, lets fake
04659     * it by doing our own generation. */
04660    static const char * const dtmf_tones[] = {
04661       "941+1336", /* 0 */
04662       "697+1209", /* 1 */
04663       "697+1336", /* 2 */
04664       "697+1477", /* 3 */
04665       "770+1209", /* 4 */
04666       "770+1336", /* 5 */
04667       "770+1477", /* 6 */
04668       "852+1209", /* 7 */
04669       "852+1336", /* 8 */
04670       "852+1477", /* 9 */
04671       "697+1633", /* A */
04672       "770+1633", /* B */
04673       "852+1633", /* C */
04674       "941+1633", /* D */
04675       "941+1209", /* * */
04676       "941+1477"  /* # */
04677    };
04678 
04679    if (!chan->tech->send_digit_begin)
04680       return 0;
04681 
04682    ast_channel_lock(chan);
04683    chan->sending_dtmf_digit = digit;
04684    chan->sending_dtmf_tv = ast_tvnow();
04685    ast_channel_unlock(chan);
04686 
04687    if (!chan->tech->send_digit_begin(chan, digit))
04688       return 0;
04689 
04690    if (digit >= '0' && digit <='9')
04691       ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
04692    else if (digit >= 'A' && digit <= 'D')
04693       ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
04694    else if (digit == '*')
04695       ast_playtones_start(chan, 0, dtmf_tones[14], 0);
04696    else if (digit == '#')
04697       ast_playtones_start(chan, 0, dtmf_tones[15], 0);
04698    else {
04699       /* not handled */
04700       ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name);
04701    }
04702 
04703    return 0;
04704 }

int ast_senddigit_end ( struct ast_channel *  chan,
char  digit,
unsigned int  duration 
)

Send a DTMF digit to a channel.

Parameters:
chan channel to act upon
digit the DTMF digit to send, encoded in ASCII
duration the duration of the digit ending in ms
Returns:
Returns 0 on success, -1 on failure

Definition at line 4706 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_playtones_stop(), ast_channel::generator, ast_channel_tech::send_digit_end, ast_channel::sending_dtmf_digit, and ast_channel::tech.

Referenced by agent_digit_end(), ast_bridge_end_dtmf(), ast_senddigit(), and ast_write().

04707 {
04708    int res = -1;
04709 
04710    ast_channel_lock(chan);
04711    if (chan->sending_dtmf_digit == digit) {
04712       chan->sending_dtmf_digit = 0;
04713    }
04714    ast_channel_unlock(chan);
04715 
04716    if (chan->tech->send_digit_end)
04717       res = chan->tech->send_digit_end(chan, digit, duration);
04718 
04719    if (res && chan->generator)
04720       ast_playtones_stop(chan);
04721    
04722    return 0;
04723 }

int ast_sendtext ( struct ast_channel *  chan,
const char *  text 
)

Sends text to a channel.

Parameters:
chan channel to act upon
text string 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:
0 on success
-1 on failure

Definition at line 4638 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_test_flag, CHECK_BLOCKING, ast_channel_tech::send_text, and ast_channel::tech.

Referenced by action_sendtext(), agent_sendtext(), handle_sendtext(), and sendtext_exec().

04639 {
04640    int res = 0;
04641 
04642    ast_channel_lock(chan);
04643    /* Stop if we're a zombie or need a soft hangup */
04644    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
04645       ast_channel_unlock(chan);
04646       return -1;
04647    }
04648    CHECK_BLOCKING(chan);
04649    if (chan->tech->send_text)
04650       res = chan->tech->send_text(chan, text);
04651    ast_clear_flag(chan, AST_FLAG_BLOCKING);
04652    ast_channel_unlock(chan);
04653    return res;
04654 }

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 6971 of file channel.c.

References ast_party_caller::ani, ast_cdr_setcid(), ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, ast_channel::caller, ast_channel::cdr, ast_party_caller::id, 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().

06972 {
06973    ast_channel_lock(chan);
06974 
06975    if (cid_num) {
06976       chan->caller.id.number.valid = 1;
06977       ast_free(chan->caller.id.number.str);
06978       chan->caller.id.number.str = ast_strdup(cid_num);
06979    }
06980    if (cid_name) {
06981       chan->caller.id.name.valid = 1;
06982       ast_free(chan->caller.id.name.str);
06983       chan->caller.id.name.str = ast_strdup(cid_name);
06984    }
06985    if (cid_ani) {
06986       chan->caller.ani.number.valid = 1;
06987       ast_free(chan->caller.ani.number.str);
06988       chan->caller.ani.number.str = ast_strdup(cid_ani);
06989    }
06990    if (chan->cdr) {
06991       ast_cdr_setcid(chan->cdr, chan);
06992    }
06993 
06994    report_new_callerid(chan);
06995 
06996    ast_channel_unlock(chan);
06997 }

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:
chan channel to set the field on
source a 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 2765 of file channel.c.

References ast_bridged_channel(), ast_channel_lock, ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_string_field_set, 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().

02766 {
02767    struct ast_channel *bridge;
02768 
02769    ast_channel_lock(chan);
02770    if (force || ast_strlen_zero(chan->hangupsource)) {
02771       ast_string_field_set(chan, hangupsource, source);
02772    }
02773    bridge = ast_bridged_channel(chan);
02774    if (bridge) {
02775       ast_channel_ref(bridge);
02776    }
02777    ast_channel_unlock(chan);
02778 
02779    if (bridge) {
02780       ast_channel_lock(bridge);
02781       if (force || ast_strlen_zero(bridge->hangupsource)) {
02782          ast_string_field_set(bridge, hangupsource, source);
02783       }
02784       ast_channel_unlock(bridge);
02785       ast_channel_unref(bridge);
02786    }
02787 }

int ast_set_read_format ( struct ast_channel *  chan,
format_t  format 
)
void ast_set_variables ( struct ast_channel *  chan,
struct ast_variable *  vars 
)

adds a list of channel variables to a channel

Parameters:
chan the channel
vars a 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 8159 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().

08160 {
08161    struct ast_variable *cur;
08162 
08163    for (cur = vars; cur; cur = cur->next)
08164       pbx_builtin_setvar_helper(chan, cur->name, cur->value);  
08165 }

int ast_set_write_format ( struct ast_channel *  chan,
format_t  format 
)
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:
c channel
rate number of timer ticks per second
func callback 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 3540 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_debug, ast_timer_get_max_rate(), ast_timer_set_rate(), AST_TIMING_FD, ast_channel::fdno, ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.

Referenced by ast_activate_generator(), ast_deactivate_generator(), ast_read_generator_actions(), ast_readaudio_callback(), filestream_close(), and internal_deactivate_generator().

03541 {
03542    int res;
03543    unsigned int real_rate = rate, max_rate;
03544 
03545    ast_channel_lock(c);
03546 
03547    if (c->timingfd == -1) {
03548       ast_channel_unlock(c);
03549       return -1;
03550    }
03551 
03552    if (!func) {
03553       rate = 0;
03554       data = NULL;
03555    }
03556 
03557    if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) {
03558       real_rate = max_rate;
03559    }
03560 
03561    ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate);
03562 
03563    res = ast_timer_set_rate(c->timer, real_rate);
03564 
03565    c->timingfunc = func;
03566    c->timingdata = data;
03567 
03568    if (func == NULL && rate == 0 && c->fdno == AST_TIMING_FD) {
03569       /* Clearing the timing func and setting the rate to 0
03570        * means that we don't want to be reading from the timingfd
03571        * any more. Setting c->fdno to -1 means we won't have any
03572        * errant reads from the timingfd, meaning we won't potentially
03573        * miss any important frames.
03574        */
03575       c->fdno = -1;
03576    }
03577 
03578    ast_channel_unlock(c);
03579 
03580    return res;
03581 }

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 861 of file channel.c.

Referenced by handle_request_options().

00862 {
00863    return shutting_down;
00864 }

int ast_softhangup ( struct ast_channel *  chan,
int  cause 
)

Softly hangup up a channel.

Parameters:
chan channel to be soft-hung-up
reason an AST_SOFTHANGUP_* reason code

Call the protocol layer, but don't destroy the channel structure (use this if you are trying to safely hangup a channel managed by another thread.

Note:
The channel passed to this function does not need to be locked.
Returns:
Returns 0 regardless

Definition at line 2742 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().

Referenced by __analog_handle_event(), __ast_module_user_hangup_all(), __ast_pbx_run(), __unload_module(), agent_hangup(), agent_logoff(), agent_read(), ast_bridge_call(), 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().

02743 {
02744    int res;
02745 
02746    ast_channel_lock(chan);
02747    res = ast_softhangup_nolock(chan, cause);
02748    ast_channel_unlock(chan);
02749 
02750    return res;
02751 }

int ast_softhangup_nolock ( struct ast_channel *  chan,
int  cause 
)

Softly hangup up a channel (no channel lock).

Parameters:
chan channel to be soft-hung-up
reason an AST_SOFTHANGUP_* reason code

Definition at line 2729 of file channel.c.

References ast_channel::_softhangup, ast_debug, AST_FLAG_BLOCKING, ast_null_frame, ast_queue_frame(), ast_test_flag, and ast_channel::blocker.

Referenced by __analog_handle_event(), action_hangup(), ast_async_goto(), ast_softhangup(), attempt_transfer(), check_pendings(), check_rtp_timeout(), dahdi_softhangup_all(), oh323_indicate(), proc_session_timer(), sip_indicate(), and skinny_indicate().

02730 {
02731    ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name);
02732    /* Inform channel driver that we need to be hung up, if it cares */
02733    chan->_softhangup |= cause;
02734    ast_queue_frame(chan, &ast_null_frame);
02735    /* Interrupt any poll call or such */
02736    if (ast_test_flag(chan, AST_FLAG_BLOCKING))
02737       pthread_kill(chan->blocker, SIGURG);
02738    return 0;
02739 }

const char* ast_state2str ( enum ast_channel_state  state  ) 

Gives the string form of a given channel state.

Parameters:
ast_channel_state state to get the name of
Returns:
the text form of the binary state given
Note:
This function is not reentrant.

Definition at line 1003 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().

01004 {
01005    char *buf;
01006 
01007    switch (state) {
01008    case AST_STATE_DOWN:
01009       return "Down";
01010    case AST_STATE_RESERVED:
01011       return "Rsrvd";
01012    case AST_STATE_OFFHOOK:
01013       return "OffHook";
01014    case AST_STATE_DIALING:
01015       return "Dialing";
01016    case AST_STATE_RING:
01017       return "Ring";
01018    case AST_STATE_RINGING:
01019       return "Ringing";
01020    case AST_STATE_UP:
01021       return "Up";
01022    case AST_STATE_BUSY:
01023       return "Busy";
01024    case AST_STATE_DIALING_OFFHOOK:
01025       return "Dialing Offhook";
01026    case AST_STATE_PRERING:
01027       return "Pre-ring";
01028    default:
01029       if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
01030          return "Unknown";
01031       snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state);
01032       return buf;
01033    }
01034 }

int ast_str2cause ( const char *  name  ) 

Convert the string form of a cause code to a number.

Parameters:
name string form of the cause
Returns:
the cause code

Definition at line 989 of file channel.c.

References ARRAY_LEN, cause, and causes.

Referenced by pbx_builtin_hangup().

00990 {
00991    int x;
00992 
00993    for (x = 0; x < ARRAY_LEN(causes); x++)
00994       if (!strncasecmp(causes[x].name, name, strlen(causes[x].name)))
00995          return causes[x].cause;
00996 
00997    return -1;
00998 }

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 7868 of file channel.c.

References ast_frfree, ast_read(), ast_tonepair_start(), ast_waitfor(), and ast_channel::generatordata.

Referenced by zapateller_exec().

07869 {
07870    int res;
07871 
07872    if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
07873       return res;
07874 
07875    /* Give us some wiggle room */
07876    while (chan->generatordata && ast_waitfor(chan, 100) >= 0) {
07877       struct ast_frame *f = ast_read(chan);
07878       if (f)
07879          ast_frfree(f);
07880       else
07881          return -1;
07882    }
07883    return 0;
07884 }

int ast_tonepair_start ( struct ast_channel *  chan,
int  freq1,
int  freq2,
int  duration,
int  vol 
)

Start a tone going

Definition at line 7850 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().

07851 {
07852    struct tonepair_def d = { 0, };
07853 
07854    d.freq1 = freq1;
07855    d.freq2 = freq2;
07856    d.duration = duration;
07857    d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
07858    if (ast_activate_generator(chan, &tonepair, &d))
07859       return -1;
07860    return 0;
07861 }

void ast_tonepair_stop ( struct ast_channel *  chan  ) 

Stop a tone from playing

Definition at line 7863 of file channel.c.

References ast_deactivate_generator().

Referenced by sendnoise().

07864 {
07865    ast_deactivate_generator(chan);
07866 }

int ast_transfer ( struct ast_channel *  chan,
char *  dest 
)

Transfer a channel (if supported).

Return values:
-1 on error
0 if not supported
1 if supported and requested
Parameters:
chan current channel
dest destination extension for transfer

Transfer a channel (if supported).

Called by:

  • app_transfer
  • the manager interface

Definition at line 5739 of file channel.c.

References ast_channel_lock, 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, ast_channel::tech, and ast_channel_tech::transfer.

Referenced by transfer_exec().

05740 {
05741    int res = -1;
05742 
05743    /* Stop if we're a zombie or need a soft hangup */
05744    ast_channel_lock(chan);
05745    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
05746       if (chan->tech->transfer) {
05747          res = chan->tech->transfer(chan, dest);
05748          if (!res)
05749             res = 1;
05750       } else
05751          res = 0;
05752    }
05753    ast_channel_unlock(chan);
05754 
05755    if (res <= 0) {
05756       return res;
05757    }
05758 
05759    for (;;) {
05760       struct ast_frame *fr;
05761 
05762       res = ast_waitfor(chan, -1);
05763 
05764       if (res < 0 || !(fr = ast_read(chan))) {
05765          res = -1;
05766          break;
05767       }
05768 
05769       if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_TRANSFER) {
05770          enum ast_control_transfer *message = fr->data.ptr;
05771 
05772          if (*message == AST_TRANSFER_SUCCESS) {
05773             res = 1;
05774          } else {
05775             res = -1;
05776          }
05777 
05778          ast_frfree(fr);
05779          break;
05780       }
05781 
05782       ast_frfree(fr);
05783    }
05784 
05785    return res;
05786 }

char* ast_transfercapability2str ( int  transfercapability  )  const

Gives the string form of a given transfer capability.

Parameters:
transfercapability transfer capability to get the name of
Returns:
the text form of the binary transfer capability

Definition at line 1037 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(), and oh323_call().

01038 {
01039    switch (transfercapability) {
01040    case AST_TRANS_CAP_SPEECH:
01041       return "SPEECH";
01042    case AST_TRANS_CAP_DIGITAL:
01043       return "DIGITAL";
01044    case AST_TRANS_CAP_RESTRICTED_DIGITAL:
01045       return "RESTRICTED_DIGITAL";
01046    case AST_TRANS_CAP_3_1K_AUDIO:
01047       return "3K1AUDIO";
01048    case AST_TRANS_CAP_DIGITAL_W_TONES:
01049       return "DIGITAL_W_TONES";
01050    case AST_TRANS_CAP_VIDEO:
01051       return "VIDEO";
01052    default:
01053       return "UNKNOWN";
01054    }
01055 }

int ast_undestroyed_channels ( void   ) 
Returns:
the number of channels not yet destroyed

Definition at line 849 of file channel.c.

References ast_atomic_fetchadd_int().

Referenced by can_safely_quit().

00850 {
00851    return ast_atomic_fetchadd_int(&chancount, 0);
00852 }

int ast_waitfor ( struct ast_channel *  chan,
int  ms 
)

Wait for input on a channel.

Parameters:
chan channel to wait on
ms length of time to wait on the channel

Wait for input on a channel for a given # of milliseconds (<0 for indefinite).

Return values:
< 0 on failure
0 if nothing ever arrived
the # of ms remaining otherwise

Definition at line 3522 of file channel.c.

References ast_waitfor_nandfds().

Referenced by __adsi_transmit_messages(), __analog_ss_thread(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), analog_ss_thread(), ast_dtmf_stream(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_transfer(), async_wait(), background_detect_exec(), channel_spy(), conf_flush(), dictate_exec(), disa_exec(), disable_t38(), do_waiting(), echo_exec(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), measurenoise(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), receivefax_t38_init(), record_exec(), recordthread(), send_tone_burst(), send_waveform_to_channel(), sendfax_t38_init(), sendurl_exec(), speech_background(), transmit_audio(), transmit_t38(), wait_for_hangup(), waitforring_exec(), and waitstream_core().

03523 {
03524    if (ms < 0) {
03525       do {
03526          ms = 100000;
03527          ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
03528       } while (!ms);
03529    } else {
03530       ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
03531    }
03532    return ms;
03533 }

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:
chan an array of pointers to channels
n number of channels that are to be waited upon
ms time "ms" is modified in-place, if applicable

Definition at line 3517 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().

03518 {
03519    return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
03520 }

int ast_waitfor_n_fd ( int *  fds,
int  n,
int *  ms,
int *  exception 
)

Waits for input on an fd.

Note:
This version works on fd's only. Be careful with it.

Definition at line 3161 of file channel.c.

References ast_waitfor_nandfds().

Referenced by dundi_lookup_internal(), dundi_precache_internal(), and softmix_bridge_thread().

03162 {
03163    int winner = -1;
03164    ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
03165    return winner;
03166 }

struct ast_channel* ast_waitfor_nandfds ( struct ast_channel **  c,
int  n,
int *  fds,
int  nfds,
int *  exception,
int *  outfd,
int *  ms 
) [read]

Waits for activity on a group of channels.

Parameters:
chan an array of pointers to channels
n number of channels that are to be waited upon
fds an array of fds to wait upon
nfds the number of fds to wait upon
exception exception flag
outfd fd that had activity on it
ms how long the wait was

Big momma function here. Wait for activity on any of the n channels, or any of the nfds file descriptors.

Returns:
Returns the channel with activity, or NULL on error or if an FD came first. If the FD came first, it will be returned in outfd, otherwise, outfd will be -1

Definition at line 3173 of file channel.c.

References ast_channel::_softhangup, ast_add_fd(), ast_alloca, ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_MAX_FDS, ast_poll, ast_set_flag, AST_SOFTHANGUP_TIMEOUT, ast_tvcmp(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), CHECK_BLOCKING, errno, and ast_channel::fdno.

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

03176 {
03177    struct timeval start = { 0 , 0 };
03178    struct pollfd *pfds = NULL;
03179    int res;
03180    long rms;
03181    int x, y, max;
03182    int sz;
03183    struct timeval now = { 0, 0 };
03184    struct timeval whentohangup = { 0, 0 }, diff;
03185    struct ast_channel *winner = NULL;
03186    struct fdmap {
03187       int chan;
03188       int fdno;
03189    } *fdmap = NULL;
03190 
03191    if (outfd)
03192       *outfd = -99999;
03193    if (exception)
03194       *exception = 0;
03195    
03196    if ((sz = n * AST_MAX_FDS + nfds)) {
03197       pfds = ast_alloca(sizeof(*pfds) * sz);
03198       fdmap = ast_alloca(sizeof(*fdmap) * sz);
03199    } else {
03200       /* nothing to allocate and no FDs to check */
03201       return NULL;
03202    }
03203 
03204    /* Perform any pending masquerades */
03205    for (x = 0; x < n; x++) {
03206       while (c[x]->masq) {
03207          ast_do_masquerade(c[x]);
03208       }
03209 
03210       ast_channel_lock(c[x]);
03211       if (!ast_tvzero(c[x]->whentohangup)) {
03212          if (ast_tvzero(whentohangup))
03213             now = ast_tvnow();
03214          diff = ast_tvsub(c[x]->whentohangup, now);
03215          if (diff.tv_sec < 0 || ast_tvzero(diff)) {
03216             /* Should already be hungup */
03217             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
03218             ast_channel_unlock(c[x]);
03219             return c[x];
03220          }
03221          if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0)
03222             whentohangup = diff;
03223       }
03224       ast_channel_unlock(c[x]);
03225    }
03226    /* Wait full interval */
03227    rms = *ms;
03228    /* INT_MAX, not LONG_MAX, because it matters on 64-bit */
03229    if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) {
03230       rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000;              /* timeout in milliseconds */
03231       if (*ms >= 0 && *ms < rms) {                                                 /* original *ms still smaller */
03232          rms =  *ms;
03233       }
03234    } else if (!ast_tvzero(whentohangup) && rms < 0) {
03235       /* Tiny corner case... call would need to last >24 days */
03236       rms = INT_MAX;
03237    }
03238    /*
03239     * Build the pollfd array, putting the channels' fds first,
03240     * followed by individual fds. Order is important because
03241     * individual fd's must have priority over channel fds.
03242     */
03243    max = 0;
03244    for (x = 0; x < n; x++) {
03245       for (y = 0; y < AST_MAX_FDS; y++) {
03246          fdmap[max].fdno = y;  /* fd y is linked to this pfds */
03247          fdmap[max].chan = x;  /* channel x is linked to this pfds */
03248          max += ast_add_fd(&pfds[max], c[x]->fds[y]);
03249       }
03250       CHECK_BLOCKING(c[x]);
03251    }
03252    /* Add the individual fds */
03253    for (x = 0; x < nfds; x++) {
03254       fdmap[max].chan = -1;
03255       max += ast_add_fd(&pfds[max], fds[x]);
03256    }
03257 
03258    if (*ms > 0)
03259       start = ast_tvnow();
03260    
03261    if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
03262       do {
03263          int kbrms = rms;
03264          if (kbrms > 600000)
03265             kbrms = 600000;
03266          res = ast_poll(pfds, max, kbrms);
03267          if (!res)
03268             rms -= kbrms;
03269       } while (!res && (rms > 0));
03270    } else {
03271       res = ast_poll(pfds, max, rms);
03272    }
03273    for (x = 0; x < n; x++)
03274       ast_clear_flag(c[x], AST_FLAG_BLOCKING);
03275    if (res < 0) { /* Simulate a timeout if we were interrupted */
03276       if (errno != EINTR)
03277          *ms = -1;
03278       return NULL;
03279    }
03280    if (!ast_tvzero(whentohangup)) {   /* if we have a timeout, check who expired */
03281       now = ast_tvnow();
03282       for (x = 0; x < n; x++) {
03283          if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) {
03284             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
03285             if (winner == NULL)
03286                winner = c[x];
03287          }
03288       }
03289    }
03290    if (res == 0) { /* no fd ready, reset timeout and done */
03291       *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
03292       return winner;
03293    }
03294    /*
03295     * Then check if any channel or fd has a pending event.
03296     * Remember to check channels first and fds last, as they
03297     * must have priority on setting 'winner'
03298     */
03299    for (x = 0; x < max; x++) {
03300       res = pfds[x].revents;
03301       if (res == 0)
03302          continue;
03303       if (fdmap[x].chan >= 0) {  /* this is a channel */
03304          winner = c[fdmap[x].chan]; /* override previous winners */
03305          if (res & POLLPRI)
03306             ast_set_flag(winner, AST_FLAG_EXCEPTION);
03307          else
03308             ast_clear_flag(winner, AST_FLAG_EXCEPTION);
03309          winner->fdno = fdmap[x].fdno;
03310       } else {       /* this is an fd */
03311          if (outfd)
03312             *outfd = pfds[x].fd;
03313          if (exception)
03314             *exception = (res & POLLPRI) ? -1 : 0;
03315          winner = NULL;
03316       }
03317    }
03318    if (*ms > 0) {
03319       *ms -= ast_tvdiff_ms(ast_tvnow(), start);
03320       if (*ms < 0)
03321          *ms = 0;
03322    }
03323    return winner;
03324 }

int ast_waitfordigit ( struct ast_channel *  c,
int  ms 
)
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:
c channel to wait for a digit on
ms how many milliseconds to wait (<0 for indefinite).
audiofd audio file descriptor to write to if audio frames are received
ctrlfd control file descriptor to monitor for reading
Returns:
Returns 1 if ctrlfd becomes available

Definition at line 3583 of file channel.c.

References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, 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().

03584 {
03585    struct timeval start = ast_tvnow();
03586    int ms;
03587 
03588    /* Stop if we're a zombie or need a soft hangup */
03589    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
03590       return -1;
03591 
03592    /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
03593    ast_set_flag(c, AST_FLAG_END_DTMF_ONLY);
03594 
03595    /* Wait for a digit, no more than timeout_ms milliseconds total.
03596     * Or, wait indefinitely if timeout_ms is <0.
03597     */
03598    while ((ms = ast_remaining_ms(start, timeout_ms))) {
03599       struct ast_channel *rchan;
03600       int outfd = -1;
03601 
03602       errno = 0;
03603       /* While ast_waitfor_nandfds tries to help by reducing the timeout by how much was waited,
03604        * it is unhelpful if it waited less than a millisecond.
03605        */
03606       rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
03607 
03608       if (!rchan && outfd < 0 && ms) {
03609          if (errno == 0 || errno == EINTR)
03610             continue;
03611          ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
03612          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03613          return -1;
03614       } else if (outfd > -1) {
03615          /* The FD we were watching has something waiting */
03616          ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n");
03617          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03618          return 1;
03619       } else if (rchan) {
03620          int res;
03621          struct ast_frame *f = ast_read(c);
03622          if (!f)
03623             return -1;
03624 
03625          switch (f->frametype) {
03626          case AST_FRAME_DTMF_BEGIN:
03627             break;
03628          case AST_FRAME_DTMF_END:
03629             res = f->subclass.integer;
03630             ast_frfree(f);
03631             ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03632             return res;
03633          case AST_FRAME_CONTROL:
03634             switch (f->subclass.integer) {
03635             case AST_CONTROL_HANGUP:
03636                ast_frfree(f);
03637                ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03638                return -1;
03639             case AST_CONTROL_RINGING:
03640             case AST_CONTROL_ANSWER:
03641             case AST_CONTROL_SRCUPDATE:
03642             case AST_CONTROL_SRCCHANGE:
03643             case AST_CONTROL_CONNECTED_LINE:
03644             case AST_CONTROL_REDIRECTING:
03645             case AST_CONTROL_UPDATE_RTP_PEER:
03646             case AST_CONTROL_HOLD:
03647             case AST_CONTROL_UNHOLD:
03648             case -1:
03649                /* Unimportant */
03650                break;
03651             default:
03652                ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass.integer);
03653                break;
03654             }
03655             break;
03656          case AST_FRAME_VOICE:
03657             /* Write audio if appropriate */
03658             if (audiofd > -1) {
03659                if (write(audiofd, f->data.ptr, f->datalen) < 0) {
03660                   ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
03661                }
03662             }
03663          default:
03664             /* Ignore */
03665             break;
03666          }
03667          ast_frfree(f);
03668       }
03669    }
03670 
03671    ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03672 
03673    return 0; /* Time is up */
03674 }

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:
chan destination channel of the frame
frame frame that will be written
Returns:
It returns 0 on success, -1 on failure.

Todo:
XXX should return 0 maybe ?

Definition at line 4867 of file channel.c.

References ast_channel::_softhangup, apply_plc(), ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, 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_AUDIO_MASK, 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(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), ast_channel::audiohooks, calc_monitor_jump(), CHECK_BLOCKING, ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, ast_filestream::fmt, ast_format::format, ast_channel::fout, FRAMECOUNT_INC, ast_channel::framehooks, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, ast_frame_subclass::integer, ast_frame::len, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::nativeformats, chanlist::next, ast_channel::outsmpl, ast_frame::ptr, ast_channel::rawwriteformat, ast_channel_monitor::read_stream, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), ast_channel_tech::send_html, ast_channel_tech::send_text, ast_frame::src, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel_tech::write, ast_channel_monitor::write_stream, ast_channel_tech::write_text, ast_channel_tech::write_video, ast_channel::writeformat, and ast_channel::writetrans.

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(), spy_generate(), t38_tx_packet_handler(), tonepair_generator(), and wait_for_answer().

04868 {
04869    int res = -1;
04870    struct ast_frame *f = NULL;
04871    int count = 0;
04872 
04873    /*Deadlock avoidance*/
04874    while(ast_channel_trylock(chan)) {
04875       /*cannot goto done since the channel is not locked*/
04876       if(count++ > 10) {
04877          ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name);
04878          return 0;
04879       }
04880       usleep(1);
04881    }
04882    /* Stop if we're a zombie or need a soft hangup */
04883    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
04884       goto done;
04885 
04886    /* Handle any pending masquerades */
04887    while (chan->masq) {
04888       ast_channel_unlock(chan);
04889       ast_do_masquerade(chan);
04890       ast_channel_lock(chan);
04891    }
04892    if (chan->masqr) {
04893       res = 0; /* XXX explain, why 0 ? */
04894       goto done;
04895    }
04896 
04897    /* Perform the framehook write event here. After the frame enters the framehook list
04898     * there is no telling what will happen, how awesome is that!!! */
04899    if (!(fr = ast_framehook_list_write_event(chan->framehooks, fr))) {
04900       res = 0;
04901       goto done;
04902    }
04903 
04904    if (chan->generatordata && (!fr->src || strcasecmp(fr->src, "ast_prod"))) {
04905       if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) {
04906             ast_deactivate_generator(chan);
04907       } else {
04908          if (fr->frametype == AST_FRAME_DTMF_END) {
04909             /* There is a generator running while we're in the middle of a digit.
04910              * It's probably inband DTMF, so go ahead and pass it so it can
04911              * stop the generator */
04912             ast_clear_flag(chan, AST_FLAG_BLOCKING);
04913             ast_channel_unlock(chan);
04914             res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
04915             ast_channel_lock(chan);
04916             CHECK_BLOCKING(chan);
04917          } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_UNHOLD) {
04918             /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */
04919             res = (chan->tech->indicate == NULL) ? 0 :
04920                chan->tech->indicate(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
04921          }
04922          res = 0; /* XXX explain, why 0 ? */
04923          goto done;
04924       }
04925    }
04926    /* High bit prints debugging */
04927    if (chan->fout & DEBUGCHAN_FLAG)
04928       ast_frame_dump(chan->name, fr, ">>");
04929    CHECK_BLOCKING(chan);
04930    switch (fr->frametype) {
04931    case AST_FRAME_CONTROL:
04932       res = (chan->tech->indicate == NULL) ? 0 :
04933          chan->tech->indicate(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
04934       break;
04935    case AST_FRAME_DTMF_BEGIN:
04936       if (chan->audiohooks) {
04937          struct ast_frame *old_frame = fr;
04938          fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
04939          if (old_frame != fr)
04940             f = fr;
04941       }
04942       send_dtmf_event(chan, "Sent", fr->subclass.integer, "Yes", "No");
04943       ast_clear_flag(chan, AST_FLAG_BLOCKING);
04944       ast_channel_unlock(chan);
04945       res = ast_senddigit_begin(chan, fr->subclass.integer);
04946       ast_channel_lock(chan);
04947       CHECK_BLOCKING(chan);
04948       break;
04949    case AST_FRAME_DTMF_END:
04950       if (chan->audiohooks) {
04951          struct ast_frame *new_frame = fr;
04952 
04953          new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
04954          if (new_frame != fr) {
04955             ast_frfree(new_frame);
04956          }
04957       }
04958       send_dtmf_event(chan, "Sent", fr->subclass.integer, "No", "Yes");
04959       ast_clear_flag(chan, AST_FLAG_BLOCKING);
04960       ast_channel_unlock(chan);
04961       res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
04962       ast_channel_lock(chan);
04963       CHECK_BLOCKING(chan);
04964       break;
04965    case AST_FRAME_TEXT:
04966       if (fr->subclass.integer == AST_FORMAT_T140) {
04967          res = (chan->tech->write_text == NULL) ? 0 :
04968             chan->tech->write_text(chan, fr);
04969       } else {
04970          res = (chan->tech->send_text == NULL) ? 0 :
04971             chan->tech->send_text(chan, (char *) fr->data.ptr);
04972       }
04973       break;
04974    case AST_FRAME_HTML:
04975       res = (chan->tech->send_html == NULL) ? 0 :
04976          chan->tech->send_html(chan, fr->subclass.integer, (char *) fr->data.ptr, fr->datalen);
04977       break;
04978    case AST_FRAME_VIDEO:
04979       /* XXX Handle translation of video codecs one day XXX */
04980       res = (chan->tech->write_video == NULL) ? 0 :
04981          chan->tech->write_video(chan, fr);
04982       break;
04983    case AST_FRAME_MODEM:
04984       res = (chan->tech->write == NULL) ? 0 :
04985          chan->tech->write(chan, fr);
04986       break;
04987    case AST_FRAME_VOICE:
04988       if (chan->tech->write == NULL)
04989          break;   /*! \todo XXX should return 0 maybe ? */
04990 
04991       if (ast_opt_generic_plc && fr->subclass.codec == AST_FORMAT_SLINEAR) {
04992          apply_plc(chan, fr);
04993       }
04994 
04995       /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
04996       if (fr->subclass.codec == chan->rawwriteformat) {
04997          f = fr;
04998       } else {
04999          if ((!(fr->subclass.codec & chan->nativeformats)) && (chan->writeformat != fr->subclass.codec)) {
05000             char nf[512];
05001 
05002             /*
05003              * XXX Something is not right.  We are not compatible with this
05004              * frame.  Bad things can happen.  Problems range from no audio,
05005              * one-way audio, to unexplained line hangups.  As a last resort
05006              * try to adjust the format.  Ideally, we do not want to do this
05007              * because it indicates a deeper problem.  For now, we log these
05008              * events to reduce user impact and help identify the problem
05009              * areas.
05010              */
05011             ast_log(LOG_WARNING, "Codec mismatch on channel %s setting write format to %s from %s native formats %s\n",
05012                chan->name, ast_getformatname(fr->subclass.codec), ast_getformatname(chan->writeformat),
05013                ast_getformatname_multiple(nf, sizeof(nf), chan->nativeformats & AST_FORMAT_AUDIO_MASK));
05014             ast_set_write_format(chan, fr->subclass.codec);
05015          }
05016 
05017          f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
05018       }
05019 
05020       if (!f) {
05021          res = 0;
05022          break;
05023       }
05024 
05025       if (chan->audiohooks) {
05026          struct ast_frame *prev = NULL, *new_frame, *cur, *dup;
05027          int freeoldlist = 0;
05028 
05029          if (f != fr) {
05030             freeoldlist = 1;
05031          }
05032 
05033          /* Since ast_audiohook_write may return a new frame, and the cur frame is
05034           * an item in a list of frames, create a new list adding each cur frame back to it
05035           * regardless if the cur frame changes or not. */
05036          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
05037             new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur);
05038 
05039             /* if this frame is different than cur, preserve the end of the list,
05040              * free the old frames, and set cur to be the new frame */
05041             if (new_frame != cur) {
05042 
05043                /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame
05044                 * isn't part of local storage, meaning if ast_audiohook_write is called multiple
05045                 * times it may override the previous frame we got from it unless we dup it */
05046                if ((dup = ast_frisolate(new_frame))) {
05047                   AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list);
05048                   if (freeoldlist) {
05049                      AST_LIST_NEXT(cur, frame_list) = NULL;
05050                      ast_frfree(cur);
05051                   }
05052                   if (new_frame != dup) {
05053                      ast_frfree(new_frame);
05054                   }
05055                   cur = dup;
05056                }
05057             }
05058 
05059             /* now, regardless if cur is new or not, add it to the new list,
05060              * if the new list has not started, cur will become the first item. */
05061             if (prev) {
05062                AST_LIST_NEXT(prev, frame_list) = cur;
05063             } else {
05064                f = cur; /* set f to be the beginning of our new list */
05065             }
05066             prev = cur;
05067          }
05068       }
05069       
05070       /* If Monitor is running on this channel, then we have to write frames out there too */
05071       /* the translator on chan->writetrans may have returned multiple frames
05072          from the single frame we passed in; if so, feed each one of them to the
05073          monitor */
05074       if (chan->monitor && chan->monitor->write_stream) {
05075          struct ast_frame *cur;
05076 
05077          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
05078          /* XXX must explain this code */
05079 #ifndef MONITOR_CONSTANT_DELAY
05080             int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples;
05081             if (jump >= 0) {
05082                jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass.codec), ast_format_rate(chan->monitor->read_stream->fmt->format));
05083                if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
05084                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
05085                chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples;
05086             } else {
05087                chan->outsmpl += cur->samples;
05088             }
05089 #else
05090             int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass.codec), ast_format_rate(chan->monitor->read_stream->fmt->format));
05091             if (jump - MONITOR_DELAY >= 0) {
05092                if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1)
05093                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
05094                chan->outsmpl += chan->insmpl - chan->outsmpl;
05095             } else {
05096                chan->outsmpl += cur->samples;
05097             }
05098 #endif
05099             if (chan->monitor->state == AST_MONITOR_RUNNING) {
05100                if (ast_writestream(chan->monitor->write_stream, cur) < 0)
05101                   ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
05102             }
05103          }
05104       }
05105 
05106       /* the translator on chan->writetrans may have returned multiple frames
05107          from the single frame we passed in; if so, feed each one of them to the
05108          channel, freeing each one after it has been written */
05109       if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
05110          struct ast_frame *cur, *next;
05111          unsigned int skip = 0;
05112 
05113          for (cur = f, next = AST_LIST_NEXT(cur, frame_list);
05114               cur;
05115               cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) {
05116             if (!skip) {
05117                if ((res = chan->tech->write(chan, cur)) < 0) {
05118                   chan->_softhangup |= AST_SOFTHANGUP_DEV;
05119                   skip = 1;
05120                } else if (next) {
05121                   /* don't do this for the last frame in the list,
05122                      as the code outside the loop will do it once
05123                   */
05124                   chan->fout = FRAMECOUNT_INC(chan->fout);
05125                }
05126             }
05127             ast_frfree(cur);
05128          }
05129 
05130          /* reset f so the code below doesn't attempt to free it */
05131          f = NULL;
05132       } else {
05133          res = chan->tech->write(chan, f);
05134       }
05135       break;
05136    case AST_FRAME_NULL:
05137    case AST_FRAME_IAX:
05138       /* Ignore these */
05139       res = 0;
05140       break;
05141    default:
05142       /* At this point, fr is the incoming frame and f is NULL.  Channels do
05143        * not expect to get NULL as a frame pointer and will segfault.  Hence,
05144        * we output the original frame passed in. */
05145       res = chan->tech->write(chan, fr);
05146       break;
05147    }
05148 
05149    if (f && f != fr)
05150       ast_frfree(f);
05151    ast_clear_flag(chan, AST_FLAG_BLOCKING);
05152 
05153    /* Consider a write failure to force a soft hangup */
05154    if (res < 0) {
05155       chan->_softhangup |= AST_SOFTHANGUP_DEV;
05156    } else {
05157       chan->fout = FRAMECOUNT_INC(chan->fout);
05158    }
05159 done:
05160    if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) {
05161       /* The list gets recreated if audiohooks are added again later */
05162       ast_audiohook_detach_list(chan->audiohooks);
05163       chan->audiohooks = NULL;
05164    }
05165    ast_channel_unlock(chan);
05166    return res;
05167 }

int ast_write_text ( struct ast_channel *  chan,
struct ast_frame *  frame 
)

Write text frame to a channel This function writes the given frame to the indicated channel.

Parameters:
chan destination channel of the frame
frame frame that will be written
Returns:
It returns 1 on success, 0 if not implemented, and -1 on failure.
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:
chan destination channel of the frame
frame frame that will be written
Returns:
It returns 1 on success, 0 if not implemented, and -1 on failure.

Definition at line 4752 of file channel.c.

References ast_write(), ast_channel::tech, and ast_channel_tech::write_video.

04753 {
04754    int res;
04755    if (!chan->tech->write_video)
04756       return 0;
04757    res = ast_write(chan, fr);
04758    if (!res)
04759       res = 1;
04760    return res;
04761 }

const char* channelreloadreason2txt ( enum channelreloadreason  reason  ) 

Convert enum channelreloadreason to text string for manager event.

Parameters:
reason The reason for reload (manager, cli, start etc)

\ brief Convert channel reloadreason (ENUM) to text string for manager event

Definition at line 8275 of file channel.c.

References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.

Referenced by reload_config().

08276 {
08277    switch (reason) {
08278    case CHANNEL_MODULE_LOAD:
08279       return "LOAD (Channel module load)";
08280 
08281    case CHANNEL_MODULE_RELOAD:
08282       return "RELOAD (Channel module reload)";
08283 
08284    case CHANNEL_CLI_RELOAD:
08285       return "CLIRELOAD (Channel module reload by CLI command)";
08286 
08287    default:
08288       return "MANAGERRELOAD (Channel module reload by manager)";
08289    }
08290 };


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 665 of file channel.c.

Referenced by ast_do_masquerade().

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 103 of file channel.c.

Referenced by handle_core_set_debug_channel().

unsigned long global_fout

Definition at line 103 of file channel.c.

Referenced by handle_core_set_debug_channel().


Generated on 18 Jan 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1