Sat Mar 26 11:17:36 2011

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  autochans
struct  datastores
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,...)
#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_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_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)
}
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_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.
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.
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.
struct ast_channel * ast_dummy_channel_alloc (void)
 Create a fake channel structure.
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_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

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 1821 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 1817 of file channel.h.

#define AST_BRIDGE_REC_CHANNEL_1   (1 << 3)

Return all voice frames on channel 1.

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

#define ast_channel_lock ( chan   )     ao2_lock(chan)

Definition at line 2295 of file channel.h.

Referenced by __ast_answer(), __ast_queue_frame(), __ast_read(), __oh323_destroy(), __sip_destroy(), _macro_exec(), _while_exec(), acf_cc_read(), acf_cc_write(), acf_odbc_read(), action_add_agi_cmd(), action_coreshowchannels(), action_hangup(), action_redirect(), action_sendtext(), action_status(), action_timeout(), add_features_datastores(), add_to_agi(), agent_hangup(), agent_indicate(), 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_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_cmp_cb(), ast_channel_connected_line_macro(), ast_channel_destructor(), ast_channel_masquerade(), ast_channel_redirecting_macro(), ast_channel_set_caller(), ast_channel_set_caller_event(), ast_channel_set_connected_line(), ast_channel_set_redirecting(), ast_check_hangup_locked(), ast_complete_channels(), ast_deactivate_generator(), ast_dial_join(), ast_do_masquerade(), 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_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(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), calendar_event_read(), calendar_query_exec(), calendar_query_result_exec(), callerid_read(), callerid_write(), cb_events(), cc_build_payload(), cc_interfaces_datastore_init(), channel_set_debug(), channel_spy(), common_exec(), conf_run(), conf_start_moh(), confbridge_exec(), connectedline_read(), connectedline_write(), crement_function_read(), dahdi_bridge(), dahdi_handle_dtmfup(), data_channels_provider_handler(), dial_exec_full(), dialog_unlink_all(), disable_jack_hook(), do_forward(), dundi_query_read(), dundi_result_read(), enable_jack_hook(), end_bridge_callback(), enum_query_read(), enum_result_read(), feature_interpret(), feature_request_and_dial(), find_by_mark(), find_by_part(), find_calling_channel(), find_conf_realtime(), find_details(), find_or_create_details(), find_transaction(), 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(), handle_chanlist(), handle_cli_mixmonitor(), handle_invite_replaces(), handle_request_bye(), handle_request_invite(), handle_showchan(), handle_softhangup(), import_ch(), import_helper(), init_jack_data(), jack_hook_callback(), leave_voicemail(), linkedid_match(), listfilter(), local_ast_moh_stop(), local_call(), local_hangup(), local_read(), local_setoption(), login_exec(), lua_get_state(), manage_parkinglot(), manager_mutestream(), manager_park(), mark_transaction_active(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_update_caller_id(), moh_files_generator(), morsecode_exec(), mute_callback(), my_handle_dtmfup(), notify_new_message(), park_call_full(), park_exec_full(), park_space_reserve(), pbx_builtin_background(), pbx_builtin_getvar_helper(), pbx_builtin_gotoiftime(), pbx_builtin_pushvar_helper(), pbx_builtin_serialize_variables(), pbx_builtin_setvar_helper(), peek_read(), pickup_by_exten(), pickup_by_mark(), pickup_by_name_cb(), pickup_by_part(), pickup_do(), pitchshift_helper(), process_sdp(), queue_exec(), receivefax_exec(), redirecting_read(), redirecting_write(), release_transaction(), report_fax_status(), retrydial_exec(), ring_entry(), 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_read(), sip_removeheader(), smdi_msg_read(), smdi_msg_retrieve_read(), softhangup_exec(), speech_background(), speex_read(), speex_write(), srv_datastore_setup(), srv_query_read(), srv_result_read(), start_monitor_action(), state_notify_build_xml(), stop_mixmonitor_exec(), transmit_invite(), try_calling(), update_bridge_vars(), and wait_for_answer().

#define ast_channel_lock_both ( chan1,
chan2   ) 

Lock two channels.

Definition at line 2302 of file channel.h.

Referenced by ast_pickup_call(), and do_bridge_masquerade().

#define AST_CHANNEL_NAME   80

#define ast_channel_ref ( c   )     ({ ao2_ref(c, +1); (c); })

Increase channel reference count.

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

Definition at line 2320 of file channel.h.

Referenced by ast_autochan_new_channel(), ast_autochan_setup(), ast_cel_report_event(), handle_getvariablefull(), handle_incoming(), handle_invite_replaces(), handle_request_refer(), and local_attended_transfer().

#define ast_channel_trylock ( chan   )     ao2_trylock(chan)

#define ast_channel_unlock ( chan   )     ao2_unlock(chan)

Definition at line 2296 of file channel.h.

Referenced by __analog_handle_event(), __ast_answer(), __ast_queue_frame(), __ast_read(), __oh323_destroy(), __oh323_rtp_create(), __sip_autodestruct(), __sip_destroy(), _macro_exec(), _while_exec(), acf_cc_read(), acf_cc_write(), acf_odbc_read(), action_add_agi_cmd(), action_coreshowchannels(), action_hangup(), action_redirect(), action_sendtext(), action_status(), action_timeout(), add_features_datastores(), add_header_max_forwards(), add_to_agi(), agent_hangup(), agent_indicate(), agent_logoff(), agent_read(), alsa_call(), analog_attempt_transfer(), analog_hangup(), 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_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_cmp_cb(), ast_channel_connected_line_macro(), ast_channel_destructor(), ast_channel_masquerade(), ast_channel_redirecting_macro(), ast_channel_set_caller(), ast_channel_set_caller_event(), ast_channel_set_connected_line(), ast_channel_set_redirecting(), ast_check_hangup_locked(), ast_complete_channels(), ast_deactivate_generator(), ast_dial_join(), ast_do_masquerade(), 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_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(), auto_congest(), bridge_exec(), bridge_play_sounds(), bridge_queue_hangup(), bridge_write(), builtin_atxfer(), builtin_automixmonitor(), calendar_event_read(), calendar_query_exec(), calendar_query_result_exec(), callerid_read(), callerid_write(), cb_events(), cc_build_payload(), cc_interfaces_datastore_init(), channel_set_debug(), channel_spy(), check_bridge(), check_rtp_timeout(), cleanup_connection(), common_exec(), conf_run(), conf_start_moh(), confbridge_exec(), connectedline_read(), connectedline_write(), console_answer(), console_hangup(), console_sendtext(), crement_function_read(), dahdi_bridge(), dahdi_handle_dtmfup(), dahdi_handle_event(), dahdi_queue_frame(), dahdi_softhangup_all(), data_channels_provider_handler(), dial_exec_full(), 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(), fast_originate(), feature_interpret(), feature_request_and_dial(), find_by_mark(), find_by_part(), find_calling_channel(), find_conf_realtime(), find_details(), find_or_create_details(), find_transaction(), 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(), 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(), jack_hook_callback(), leave_voicemail(), linkedid_match(), listfilter(), local_ast_moh_stop(), local_attended_transfer(), local_bridge_loop(), local_call(), local_hangup(), local_queryoption(), local_queue_frame(), local_read(), local_setoption(), login_exec(), lua_get_state(), manage_parkinglot(), manager_mutestream(), manager_park(), mark_transaction_active(), mgcp_pktcgate_remove(), mgcp_queue_frame(), mgcp_queue_hangup(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_update_caller_id(), moh_files_generator(), morsecode_exec(), mute_callback(), my_handle_dtmfup(), notify_new_message(), oh323_rtp_read(), oh323_simulate_dtmf_end(), park_call_full(), park_exec_full(), park_space_reserve(), pbx_builtin_background(), pbx_builtin_getvar_helper(), pbx_builtin_gotoiftime(), pbx_builtin_pushvar_helper(), pbx_builtin_serialize_variables(), pbx_builtin_setvar_helper(), peek_read(), pickup_by_channel(), pickup_by_exten(), pickup_by_mark(), pickup_by_name_cb(), pickup_by_part(), pickup_do(), pitchshift_helper(), pri_dchannel(), pri_queue_frame(), proc_session_timer(), process_sdp(), queue_exec(), receive_digit(), receivefax_exec(), redirecting_read(), redirecting_write(), release_chan(), release_chan_early(), release_transaction(), remote_bridge_loop(), remote_hold(), report_fax_status(), retrans_pkt(), retrydial_exec(), ring_entry(), run_agi(), schedule_delivery(), scheduler_process_request_queue(), 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(), sig_pri_attempt_transfer(), sig_pri_cc_generic_check(), sig_pri_handle_hold(), sig_pri_handle_subcmds(), sig_ss7_queue_frame(), sip_addheader(), sip_dtmfmode(), sip_hangup(), sip_new(), sip_park(), sip_read(), sip_reinvite_retry(), sip_removeheader(), 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(), start_monitor_action(), state_notify_build_xml(), stop_mixmonitor_exec(), transmit_invite(), try_calling(), update_bridge_vars(), update_state(), 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 2331 of file channel.h.

Referenced by __ast_channel_alloc_ap(), action_add_agi_cmd(), action_aocmessage(), action_atxfer(), action_bridge(), action_coreshowchannels(), action_getvar(), action_hangup(), action_redirect(), action_sendtext(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), ast_autochan_destroy(), ast_autochan_new_channel(), ast_bridge_call(), ast_cel_check_retire_linkedid(), ast_cel_report_event(), ast_channel_release(), ast_complete_channels(), ast_dummy_channel_alloc(), ast_parse_device_state(), ast_pickup_call(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), asyncgoto_exec(), bridge_exec(), change_monitor_action(), common_exec(), data_channels_provider_handler(), 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_refer(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), handle_softhangup(), import_helper(), local_attended_transfer(), manager_mute_mixmonitor(), manager_mutestream(), manager_optimize_away(), manager_park(), manager_play_dtmf(), park_call_full(), pbx_builtin_importvar(), pickup_by_channel(), pickup_by_exten(), pickup_by_mark(), pickup_by_part(), senddtmf_exec(), shared_read(), shared_write(), softhangup_exec(), start_monitor_action(), state_notify_build_xml(), and stop_monitor_action().

#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(), and ast_do_masquerade().

#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(), and ast_do_masquerade().

#define CHECK_BLOCKING ( c   ) 

Definition at line 2256 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 639 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 642 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.

#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 867 of file channel.h.

00867      {
00868    /*!
00869      * \brief Channels have this property if they can accept input with jitter;
00870     * i.e. most VoIP channels
00871     */
00872    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00873    /*!
00874      * \brief Channels have this property if they can create jitter;
00875     * i.e. most VoIP channels
00876     */
00877    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00878 };

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.

Definition at line 881 of file channel.h.

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

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 933 of file channel.h.

00933      {
00934    AST_FEATURE_PLAY_WARNING = (1 << 0),
00935    AST_FEATURE_REDIRECT =     (1 << 1),
00936    AST_FEATURE_DISCONNECT =   (1 << 2),
00937    AST_FEATURE_ATXFER =       (1 << 3),
00938    AST_FEATURE_AUTOMON =      (1 << 4),
00939    AST_FEATURE_PARKCALL =     (1 << 5),
00940    AST_FEATURE_AUTOMIXMON =   (1 << 6),
00941    AST_FEATURE_NO_H_EXTEN =   (1 << 7),
00942    AST_FEATURE_WARNING_ACTIVE = (1 << 8),
00943 };

anonymous enum

Enumerator:
AST_SOFTHANGUP_DEV  Soft hangup by device
AST_SOFTHANGUP_ASYNCGOTO  Soft hangup for async goto
AST_SOFTHANGUP_SHUTDOWN 
AST_SOFTHANGUP_TIMEOUT 
AST_SOFTHANGUP_APPUNLOAD 
AST_SOFTHANGUP_EXPLICIT 
AST_SOFTHANGUP_UNBRIDGE 

Definition at line 981 of file channel.h.

00981      {
00982    /*! Soft hangup by device */
00983    AST_SOFTHANGUP_DEV =       (1 << 0),
00984    /*! Soft hangup for async goto */
00985    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00986    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00987    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00988    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00989    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00990    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00991 };

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 650 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 660 of file channel.h.

00660                    {
00661    T38_STATE_UNAVAILABLE,  /*!< T38 is unavailable on this channel or disabled by configuration */
00662    T38_STATE_UNKNOWN,   /*!< The channel supports T38 but the current status is unknown */
00663    T38_STATE_NEGOTIATING,  /*!< T38 is being negotiated */
00664    T38_STATE_REJECTED,  /*!< Remote side has rejected our offer */
00665    T38_STATE_NEGOTIATED,   /*!< T38 established */
00666 };

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 995 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 2797 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_STATE_RING, AST_STATE_RINGING, ast_waitfor(), errno, frames, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, MAX, ast_channel::name, and ast_frame::subclass.

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

02798 {
02799    int res = 0;
02800    enum ast_channel_state old_state;
02801 
02802    old_state = chan->_state;
02803    if ((res = ast_raw_answer(chan, cdr_answer))) {
02804       return res;
02805    }
02806 
02807    switch (old_state) {
02808    case AST_STATE_RINGING:
02809    case AST_STATE_RING:
02810       /* wait for media to start flowing, but don't wait any longer
02811        * than 'delay' or 500 milliseconds, whichever is longer
02812        */
02813       do {
02814          AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
02815          struct ast_frame *cur, *new;
02816          int ms = MAX(delay, 500);
02817          unsigned int done = 0;
02818 
02819          AST_LIST_HEAD_INIT_NOLOCK(&frames);
02820 
02821          for (;;) {
02822             ms = ast_waitfor(chan, ms);
02823             if (ms < 0) {
02824                ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno));
02825                res = -1;
02826                break;
02827             }
02828             if (ms == 0) {
02829                ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500));
02830                break;
02831             }
02832             cur = ast_read(chan);
02833             if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
02834                     (cur->subclass.integer == AST_CONTROL_HANGUP))) {
02835                if (cur) {
02836                   ast_frfree(cur);
02837                }
02838                res = -1;
02839                ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name);
02840                break;
02841             }
02842 
02843             if ((new = ast_frisolate(cur)) != cur) {
02844                ast_frfree(cur);
02845             }
02846 
02847             AST_LIST_INSERT_HEAD(&frames, new, frame_list);
02848 
02849             /* if a specific delay period was requested, continue
02850              * until that delay has passed. don't stop just because
02851              * incoming media has arrived.
02852              */
02853             if (delay) {
02854                continue;
02855             }
02856 
02857             switch (new->frametype) {
02858                /* all of these frametypes qualify as 'media' */
02859             case AST_FRAME_VOICE:
02860             case AST_FRAME_VIDEO:
02861             case AST_FRAME_TEXT:
02862             case AST_FRAME_DTMF_BEGIN:
02863             case AST_FRAME_DTMF_END:
02864             case AST_FRAME_IMAGE:
02865             case AST_FRAME_HTML:
02866             case AST_FRAME_MODEM:
02867                done = 1;
02868                break;
02869             case AST_FRAME_CONTROL:
02870             case AST_FRAME_IAX:
02871             case AST_FRAME_NULL:
02872             case AST_FRAME_CNG:
02873                break;
02874             }
02875 
02876             if (done) {
02877                break;
02878             }
02879          }
02880 
02881          if (res == 0) {
02882             ast_channel_lock(chan);
02883             while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
02884                ast_queue_frame_head(chan, cur);
02885                ast_frfree(cur);
02886             }
02887             ast_channel_unlock(chan);
02888          }
02889       } while (0);
02890       break;
02891    default:
02892       break;
02893    }
02894 
02895    return res;
02896 }

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:
By default, new channels are set to the "s" extension and "default" context.

Definition at line 1293 of file channel.c.

References __ast_channel_alloc_ap().

01299 {
01300    va_list ap1, ap2;
01301    struct ast_channel *result;
01302 
01303    va_start(ap1, name_fmt);
01304    va_start(ap2, name_fmt);
01305    result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
01306                linkedid, amaflag, file, line, function, name_fmt, ap1, ap2);
01307    va_end(ap1);
01308    va_end(ap2);
01309 
01310    return result;
01311 }

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 5090 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_set_connected_line(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, 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_request(), ast_set_callerid(), ast_set_flag, ast_set_variables(), AST_STATE_UP, ast_strlen_zero(), ast_waitfor(), ast_channel::call_forward, 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().

05091 {
05092    int dummy_outstate;
05093    int cause = 0;
05094    struct ast_channel *chan;
05095    int res = 0;
05096    int last_subclass = 0;
05097    struct ast_party_connected_line connected;
05098    
05099    if (outstate)
05100       *outstate = 0;
05101    else
05102       outstate = &dummy_outstate;   /* make outstate always a valid pointer */
05103 
05104    chan = ast_request(type, format, requestor, data, &cause);
05105    if (!chan) {
05106       ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
05107       handle_cause(cause, outstate);
05108       return NULL;
05109    }
05110 
05111    if (oh) {
05112       if (oh->vars)  
05113          ast_set_variables(chan, oh->vars);
05114       /* XXX why is this necessary, for the parent_channel perhaps ? */
05115       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name))
05116          ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
05117       if (oh->parent_channel) {
05118          ast_channel_inherit_variables(oh->parent_channel, chan);
05119          ast_channel_datastore_inherit(oh->parent_channel, chan);
05120       }
05121       if (oh->account)
05122          ast_cdr_setaccount(chan, oh->account); 
05123    }
05124 
05125    ast_set_callerid(chan, cid_num, cid_name, cid_num);
05126    ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED);
05127    ast_party_connected_line_set_init(&connected, &chan->connected);
05128    if (cid_num) {
05129       connected.id.number.valid = 1;
05130       connected.id.number.str = (char *) cid_num;
05131       connected.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
05132    }
05133    if (cid_name) {
05134       connected.id.name.valid = 1;
05135       connected.id.name.str = (char *) cid_name;
05136       connected.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
05137    }
05138    ast_channel_set_connected_line(chan, &connected, NULL);
05139 
05140    if (ast_call(chan, data, 0)) {   /* ast_call failed... */
05141       ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
05142    } else {
05143       res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
05144       while (timeout && chan->_state != AST_STATE_UP) {
05145          struct ast_frame *f;
05146          res = ast_waitfor(chan, timeout);
05147          if (res == 0) { /* timeout, treat it like ringing */
05148             *outstate = AST_CONTROL_RINGING;
05149             break;
05150          }
05151          if (res < 0) /* error or done */
05152             break;
05153          if (timeout > -1)
05154             timeout = res;
05155          if (!ast_strlen_zero(chan->call_forward)) {
05156             if (!(chan = ast_call_forward(NULL, chan, NULL, format, oh, outstate))) {
05157                return NULL;
05158             }
05159             continue;
05160          }
05161 
05162          f = ast_read(chan);
05163          if (!f) {
05164             *outstate = AST_CONTROL_HANGUP;
05165             res = 0;
05166             break;
05167          }
05168          if (f->frametype == AST_FRAME_CONTROL) {
05169             switch (f->subclass.integer) {
05170             case AST_CONTROL_RINGING:  /* record but keep going */
05171                *outstate = f->subclass.integer;
05172                break;
05173 
05174             case AST_CONTROL_BUSY:
05175                ast_cdr_busy(chan->cdr);
05176                *outstate = f->subclass.integer;
05177                timeout = 0;
05178                break;
05179 
05180             case AST_CONTROL_CONGESTION:
05181                ast_cdr_failed(chan->cdr);
05182                *outstate = f->subclass.integer;
05183                timeout = 0;
05184                break;
05185 
05186             case AST_CONTROL_ANSWER:
05187                ast_cdr_answer(chan->cdr);
05188                *outstate = f->subclass.integer;
05189                timeout = 0;      /* trick to force exit from the while() */
05190                break;
05191 
05192             /* Ignore these */
05193             case AST_CONTROL_PROGRESS:
05194             case AST_CONTROL_PROCEEDING:
05195             case AST_CONTROL_HOLD:
05196             case AST_CONTROL_UNHOLD:
05197             case AST_CONTROL_VIDUPDATE:
05198             case AST_CONTROL_SRCUPDATE:
05199             case AST_CONTROL_SRCCHANGE:
05200             case AST_CONTROL_CONNECTED_LINE:
05201             case AST_CONTROL_REDIRECTING:
05202             case AST_CONTROL_CC:
05203             case -1:       /* Ignore -- just stopping indications */
05204                break;
05205 
05206             default:
05207                ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass.integer);
05208             }
05209             last_subclass = f->subclass.integer;
05210          }
05211          ast_frfree(f);
05212       }
05213    }
05214 
05215    /* Final fixups */
05216    if (oh) {
05217       if (!ast_strlen_zero(oh->context))
05218          ast_copy_string(chan->context, oh->context, sizeof(chan->context));
05219       if (!ast_strlen_zero(oh->exten))
05220          ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
05221       if (oh->priority) 
05222          chan->priority = oh->priority;
05223    }
05224    if (chan->_state == AST_STATE_UP)
05225       *outstate = AST_CONTROL_ANSWER;
05226 
05227    if (res <= 0) {
05228       if ( AST_CONTROL_RINGING == last_subclass ) 
05229          chan->hangupcause = AST_CAUSE_NO_ANSWER;
05230       if (!chan->cdr && (chan->cdr = ast_cdr_alloc()))
05231          ast_cdr_init(chan->cdr, chan);
05232       if (chan->cdr) {
05233          char tmp[256];
05234          snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data);
05235          ast_cdr_setapp(chan->cdr,"Dial",tmp);
05236          ast_cdr_update(chan);
05237          ast_cdr_start(chan->cdr);
05238          ast_cdr_end(chan->cdr);
05239          /* If the cause wasn't handled properly */
05240          if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
05241             ast_cdr_failed(chan->cdr);
05242       }
05243       ast_hangup(chan);
05244       chan = NULL;
05245    }
05246    return chan;
05247 }

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

Activate a given generator

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

02949 {
02950    int res = 0;
02951 
02952    ast_channel_lock(chan);
02953    if (chan->generatordata) {
02954       if (chan->generator && chan->generator->release)
02955          chan->generator->release(chan, chan->generatordata);
02956       chan->generatordata = NULL;
02957    }
02958    if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) {
02959       res = -1;
02960    }
02961    if (!res) {
02962       ast_settimeout(chan, 50, generator_force, chan);
02963       chan->generator = gen;
02964    }
02965    ast_channel_unlock(chan);
02966 
02967    ast_prod(chan);
02968 
02969    return res;
02970 }

int ast_active_channels ( void   ) 

returns number of active/allocated channels

Returns:
number of active/allocated channels

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

00784 {
00785    return channels ? ao2_container_count(channels) : 0;
00786 }

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 2219 of file channel.h.

Referenced by ast_waitfor_nandfds().

02220 {
02221    pfd->fd = fd;
02222    pfd->events = POLLIN | POLLPRI;
02223    return fd >= 0;
02224 }

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 2898 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_pickup_call(), auth_exec(), background_detect_exec(), bridge_exec(), 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(), park_exec_full(), parkcall_helper(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), readexten_exec(), receivefax_exec(), record_exec(), rpt_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().

02899 {
02900    return __ast_answer(chan, 0, 1);
02901 }

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 302 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_atxfer(), builtin_automixmonitor(), builtin_blindtransfer(), feature_exec_app(), and play_message_in_bridged_call().

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

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 174 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(), bridge_playfile(), builtin_atxfer(), builtin_automixmonitor(), builtin_blindtransfer(), conf_play(), confbridge_exec(), dial_exec_full(), feature_exec_app(), 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_in_bridged_call(), post_join_marked(), realtimefield_read(), senddtmf_exec(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), srv_datastore_setup(), system_exec_helper(), try_calling(), and trylock_read().

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

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 233 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(), bridge_playfile(), builtin_atxfer(), builtin_automixmonitor(), conf_play(), confbridge_exec(), dial_exec_full(), feature_exec_app(), 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_in_bridged_call(), post_join_marked(), realtimefield_read(), senddtmf_exec(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), srv_datastore_setup(), system_exec_helper(), try_calling(), and trylock_read().

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

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

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

Referenced by quit_handler().

00774 {
00775    shutting_down = 1;
00776 
00777    if (hangup) {
00778       ao2_callback(channels, OBJ_NODATA | OBJ_MULTIPLE, ast_channel_softhangup_cb, NULL);
00779    }
00780 }

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

00993 {
00994    /* This just our opinion, expressed in code.  We are asked to choose
00995       the best codec to use, given no information */
00996    int x;
00997    static const format_t prefs[] =
00998    {
00999       /*! Okay, ulaw is used by all telephony equipment, so start with it */
01000       AST_FORMAT_ULAW,
01001       /*! Unless of course, you're a silly European, so then prefer ALAW */
01002       AST_FORMAT_ALAW,
01003       AST_FORMAT_G719,
01004       AST_FORMAT_SIREN14,
01005       AST_FORMAT_SIREN7,
01006       AST_FORMAT_TESTLAW,
01007       /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
01008       AST_FORMAT_G722,
01009       /*! Okay, well, signed linear is easy to translate into other stuff */
01010       AST_FORMAT_SLINEAR16,
01011       AST_FORMAT_SLINEAR,
01012       /*! G.726 is standard ADPCM, in RFC3551 packing order */
01013       AST_FORMAT_G726,
01014       /*! G.726 is standard ADPCM, in AAL2 packing order */
01015       AST_FORMAT_G726_AAL2,
01016       /*! ADPCM has great sound quality and is still pretty easy to translate */
01017       AST_FORMAT_ADPCM,
01018       /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
01019           translate and sounds pretty good */
01020       AST_FORMAT_GSM,
01021       /*! iLBC is not too bad */
01022       AST_FORMAT_ILBC,
01023       /*! Speex is free, but computationally more expensive than GSM */
01024       AST_FORMAT_SPEEX16,
01025       AST_FORMAT_SPEEX,
01026       /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
01027           to use it */
01028       AST_FORMAT_LPC10,
01029       /*! G.729a is faster than 723 and slightly less expensive */
01030       AST_FORMAT_G729A,
01031       /*! Down to G.723.1 which is proprietary but at least designed for voice */
01032       AST_FORMAT_G723_1,
01033    };
01034    char buf[512];
01035 
01036    /* Strip out video */
01037    fmts &= AST_FORMAT_AUDIO_MASK;
01038    
01039    /* Find the first preferred codec in the format given */
01040    for (x = 0; x < ARRAY_LEN(prefs); x++) {
01041       if (fmts & prefs[x])
01042          return prefs[x];
01043    }
01044 
01045    ast_log(LOG_WARNING, "Don't know any of %s formats\n", ast_getformatname_multiple(buf, sizeof(buf), fmts));
01046 
01047    return 0;
01048 }

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 6408 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_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_masquerade(), 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(), pri_dchannel(), schedule_delivery(), sig_pri_attempt_transfer(), sig_pri_handle_hold(), sip_hangup(), sip_set_rtp_peer(), skinny_transfer(), socket_process(), start_spying(), startmon(), TransferCallStep1(), and unistim_hangup().

06409 {
06410    struct ast_channel *bridged;
06411    bridged = chan->_bridge;
06412    if (bridged && bridged->tech->bridged_channel)
06413       bridged = bridged->tech->bridged_channel(chan, bridged);
06414    return bridged;
06415 }

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

Make a call.

Parameters:
chan which channel to make the call on
addr destination of the call
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 5360 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(), attempt_reconnect(), begin_dial_channel(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), do_idle_thread(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_exec(), and wait_for_answer().

05361 {
05362    /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
05363       If the remote end does not answer within the timeout, then do NOT hang up, but
05364       return anyway.  */
05365    int res = -1;
05366    /* Stop if we're a zombie or need a soft hangup */
05367    ast_channel_lock(chan);
05368    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
05369       if (chan->cdr) {
05370          ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED);
05371       }
05372       if (chan->tech->call)
05373          res = chan->tech->call(chan, addr, timeout);
05374       ast_set_flag(chan, AST_FLAG_OUTGOING);
05375    }
05376    ast_channel_unlock(chan);
05377    return res;
05378 }

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

References outgoing_helper::account, ast_channel::accountcode, accountcode, ast_call(), AST_CDR_FLAG_ORIGINATED, ast_cdr_setaccount(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_set_redirecting(), ast_channel_trylock, ast_channel_unlock, ast_channel_update_redirecting(), ast_copy_flags, ast_copy_string(), ast_hangup(), ast_log(), ast_party_caller_copy(), ast_party_connected_line_copy(), ast_request(), ast_set_callerid(), ast_set_variables(), ast_string_field_set, ast_strlen_zero(), ast_channel::call_forward, ast_channel::caller, cause, ast_channel::cdr, CHANNEL_DEADLOCK_AVOIDANCE, outgoing_helper::cid_name, outgoing_helper::cid_num, 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().

05010 {
05011    char tmpchan[256];
05012    struct ast_channel *new = NULL;
05013    struct ast_party_redirecting *apr = &orig->redirecting;
05014    char *data, *type;
05015    int cause = 0;
05016    int res;
05017 
05018    /* gather data and request the new forward channel */
05019    ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan));
05020    if ((data = strchr(tmpchan, '/'))) {
05021       *data++ = '\0';
05022       type = tmpchan;
05023    } else {
05024       const char *forward_context;
05025       ast_channel_lock(orig);
05026       forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
05027       snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context));
05028       ast_channel_unlock(orig);
05029       data = tmpchan;
05030       type = "Local";
05031    }
05032    if (!(new = ast_request(type, format, orig, data, &cause))) {
05033       ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
05034       handle_cause(cause, outstate);
05035       ast_hangup(orig);
05036       return NULL;
05037    }
05038 
05039    ast_channel_set_redirecting(new, apr, NULL);
05040 
05041    /* Copy/inherit important information into new channel */
05042    if (oh) {
05043       if (oh->vars) {
05044          ast_set_variables(new, oh->vars);
05045       }
05046       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
05047          ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num);
05048       }
05049       if (oh->parent_channel) {
05050          ast_channel_update_redirecting(oh->parent_channel, apr, NULL);
05051          ast_channel_inherit_variables(oh->parent_channel, new);
05052          ast_channel_datastore_inherit(oh->parent_channel, new);
05053       }
05054       if (oh->account) {
05055          ast_cdr_setaccount(new, oh->account);
05056       }
05057    } else if (caller) { /* no outgoing helper so use caller if avaliable */
05058       ast_channel_update_redirecting(caller, apr, NULL);
05059       ast_channel_inherit_variables(caller, new);
05060       ast_channel_datastore_inherit(caller, new);
05061    }
05062 
05063    ast_channel_lock(orig);
05064    while (ast_channel_trylock(new)) {
05065       CHANNEL_DEADLOCK_AVOIDANCE(orig);
05066    }
05067    ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED);
05068    ast_string_field_set(new, accountcode, orig->accountcode);
05069    ast_party_caller_copy(&new->caller, &orig->caller);
05070    ast_party_connected_line_copy(&new->connected, &orig->connected);
05071    ast_channel_unlock(new);
05072    ast_channel_unlock(orig);
05073 
05074    /* call new channel */
05075    res = ast_call(new, data, 0);
05076    if (timeout) {
05077       *timeout = res;
05078    }
05079    if (res) {
05080       ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
05081       ast_hangup(orig);
05082       ast_hangup(new);
05083       return NULL;
05084    }
05085    ast_hangup(orig);
05086 
05087    return new;
05088 }

void ast_cancel_shutdown ( void   ) 

Cancel a shutdown in progress.

Cancels an existing shutdown and returns to normal operation

Definition at line 789 of file channel.c.

Referenced by handle_abort_shutdown().

00790 {
00791    shutting_down = 0;
00792 }

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

00911 {
00912    int x;
00913 
00914    for (x = 0; x < ARRAY_LEN(causes); x++) {
00915       if (causes[x].cause == cause)
00916          return causes[x].desc;
00917    }
00918 
00919    return "Unknown";
00920 }

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

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

Referenced by update_name().

05684 {
05685    /* We must re-link, as the hash value will change here. */
05686    ao2_unlink(channels, chan);
05687    ast_channel_lock(chan);
05688    __ast_change_name_nolink(chan, newname);
05689    ast_channel_unlock(chan);
05690    ao2_link(channels, chan);
05691 }

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 6749 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_make_compatible(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCCHANGE, 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_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::generator, ast_party_caller::id, LOG_WARNING, manager_bridge_event(), ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, 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, ast_channel::uniqueid, 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().

06751 {
06752    struct ast_channel *who = NULL, *chans[2] = { c0, c1 };
06753    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
06754    format_t o0nativeformats;
06755    format_t o1nativeformats;
06756    long time_left_ms=0;
06757    char caller_warning = 0;
06758    char callee_warning = 0;
06759 
06760    if (c0->_bridge) {
06761       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
06762          c0->name, c0->_bridge->name);
06763       return -1;
06764    }
06765    if (c1->_bridge) {
06766       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
06767          c1->name, c1->_bridge->name);
06768       return -1;
06769    }
06770    
06771    /* Stop if we're a zombie or need a soft hangup */
06772    if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
06773        ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
06774       return -1;
06775 
06776    *fo = NULL;
06777 
06778    if (ast_tvzero(config->start_time)) {
06779       config->start_time = ast_tvnow();
06780       if (config->start_sound) {
06781          if (caller_warning) {
06782             bridge_playfile(c0, c1, config->start_sound, config->timelimit / 1000);
06783          }
06784          if (callee_warning) {
06785             bridge_playfile(c1, c0, config->start_sound, config->timelimit / 1000);
06786          }
06787       }
06788    }
06789 
06790    /* Keep track of bridge */
06791    c0->_bridge = c1;
06792    c1->_bridge = c0;
06793 
06794    ast_set_owners_and_peers(c0, c1);
06795 
06796    o0nativeformats = c0->nativeformats;
06797    o1nativeformats = c1->nativeformats;
06798 
06799    if (config->feature_timer && !ast_tvzero(config->nexteventts)) {
06800       config->nexteventts = ast_tvadd(config->feature_start_time, ast_samp2tv(config->feature_timer, 1000));
06801    } else if (config->timelimit) {
06802       time_left_ms = config->timelimit - ast_tvdiff_ms(ast_tvnow(), config->start_time);
06803       caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
06804       callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
06805       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
06806       if ((caller_warning || callee_warning) && config->play_warning) {
06807          long next_warn = config->play_warning;
06808          if (time_left_ms < config->play_warning) {
06809             /* At least one warning was played, which means we are returning after feature */
06810             long warns_passed = (config->play_warning - time_left_ms) / config->warning_freq;
06811             /* It is 'warns_passed * warning_freq' NOT '(warns_passed + 1) * warning_freq',
06812                because nexteventts will be updated once again in the 'if (!to)' block */
06813             next_warn = config->play_warning - warns_passed * config->warning_freq;
06814          }
06815          config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(next_warn, 1000));
06816       }
06817    } else {
06818       config->nexteventts.tv_sec = 0;
06819       config->nexteventts.tv_usec = 0;
06820    }
06821 
06822    if (!c0->tech->send_digit_begin)
06823       ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY);
06824    if (!c1->tech->send_digit_begin)
06825       ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY);
06826    manager_bridge_event(1, 1, c0, c1);
06827 
06828    /* Before we enter in and bridge these two together tell them both the source of audio has changed */
06829    ast_indicate(c0, AST_CONTROL_SRCCHANGE);
06830    ast_indicate(c1, AST_CONTROL_SRCCHANGE);
06831 
06832    for (/* ever */;;) {
06833       struct timeval now = { 0, };
06834       int to;
06835 
06836       to = -1;
06837 
06838       if (!ast_tvzero(config->nexteventts)) {
06839          now = ast_tvnow();
06840          to = ast_tvdiff_ms(config->nexteventts, now);
06841          if (to <= 0) {
06842             if (!config->timelimit) {
06843                res = AST_BRIDGE_COMPLETE;
06844                break;
06845             }
06846             to = 0;
06847          }
06848       }
06849 
06850       if (config->timelimit) {
06851          time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
06852          if (time_left_ms < to)
06853             to = time_left_ms;
06854 
06855          if (time_left_ms <= 0) {
06856             if (caller_warning && config->end_sound)
06857                bridge_playfile(c0, c1, config->end_sound, 0);
06858             if (callee_warning && config->end_sound)
06859                bridge_playfile(c1, c0, config->end_sound, 0);
06860             *fo = NULL;
06861             if (who)
06862                *rc = who;
06863             res = 0;
06864             break;
06865          }
06866 
06867          if (!to) {
06868             if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) {
06869                int t = (time_left_ms + 500) / 1000; /* round to nearest second */
06870                if (caller_warning)
06871                   bridge_playfile(c0, c1, config->warning_sound, t);
06872                if (callee_warning)
06873                   bridge_playfile(c1, c0, config->warning_sound, t);
06874             }
06875 
06876             if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) {
06877                config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000));
06878             } else {
06879                config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
06880             }
06881          }
06882          ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
06883       }
06884 
06885       if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
06886          if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
06887             c0->_softhangup = 0;
06888          if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
06889             c1->_softhangup = 0;
06890          c0->_bridge = c1;
06891          c1->_bridge = c0;
06892          ast_debug(1, "Unbridge signal received. Ending native bridge.\n");
06893          continue;
06894       }
06895 
06896       /* Stop if we're a zombie or need a soft hangup */
06897       if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
06898           ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
06899          *fo = NULL;
06900          if (who)
06901             *rc = who;
06902          res = 0;
06903          ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",
06904             c0->name, c1->name,
06905             ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No",
06906             ast_check_hangup(c0) ? "Yes" : "No",
06907             ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No",
06908             ast_check_hangup(c1) ? "Yes" : "No");
06909          break;
06910       }
06911 
06912       update_bridge_vars(c0, c1);
06913 
06914       bridge_play_sounds(c0, c1);
06915 
06916       if (c0->tech->bridge &&
06917          /* if < 1 ms remains use generic bridging for accurate timing */
06918          (!config->timelimit || to > 1000 || to == 0) &&
06919           (c0->tech->bridge == c1->tech->bridge) &&
06920           !c0->monitor && !c1->monitor &&
06921           !c0->audiohooks && !c1->audiohooks &&
06922           !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) {
06923          int timeoutms = to - 1000 > 0 ? to - 1000 : to;
06924          /* Looks like they share a bridge method and nothing else is in the way */
06925          ast_set_flag(c0, AST_FLAG_NBRIDGE);
06926          ast_set_flag(c1, AST_FLAG_NBRIDGE);
06927          if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) {
06928             ast_manager_event_multichan(EVENT_FLAG_CALL, "Unlink", 2, chans,
06929                "Channel1: %s\r\n"
06930                "Channel2: %s\r\n"
06931                "Uniqueid1: %s\r\n"
06932                "Uniqueid2: %s\r\n"
06933                "CallerID1: %s\r\n"
06934                "CallerID2: %s\r\n",
06935                c0->name, c1->name,
06936                c0->uniqueid, c1->uniqueid,
06937                S_COR(c0->caller.id.number.valid, c0->caller.id.number.str, "<unknown>"),
06938                S_COR(c1->caller.id.number.valid, c1->caller.id.number.str, "<unknown>"));
06939 
06940             ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name);
06941 
06942             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
06943             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
06944 
06945             if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
06946                continue;
06947 
06948             c0->_bridge = NULL;
06949             c1->_bridge = NULL;
06950             return res;
06951          } else {
06952             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
06953             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
06954          }
06955          switch (res) {
06956          case AST_BRIDGE_RETRY:
06957             if (config->play_warning) {
06958                ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
06959             }
06960             continue;
06961          default:
06962             ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name);
06963             /* fallthrough */
06964          case AST_BRIDGE_FAILED_NOWARN:
06965             break;
06966          }
06967       }
06968 
06969       if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
06970           (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
06971           !(c0->generator || c1->generator)) {
06972          if (ast_channel_make_compatible(c0, c1)) {
06973             ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
06974             manager_bridge_event(0, 1, c0, c1);
06975             return AST_BRIDGE_FAILED;
06976          }
06977          o0nativeformats = c0->nativeformats;
06978          o1nativeformats = c1->nativeformats;
06979       }
06980 
06981       update_bridge_vars(c0, c1);
06982 
06983       res = ast_generic_bridge(c0, c1, config, fo, rc);
06984       if (res != AST_BRIDGE_RETRY) {
06985          break;
06986       } else if (config->feature_timer) {
06987          /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */
06988          break;
06989       }
06990    }
06991 
06992    ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY);
06993    ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY);
06994 
06995    /* Now that we have broken the bridge the source will change yet again */
06996    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
06997    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
06998 
06999    c0->_bridge = NULL;
07000    c1->_bridge = NULL;
07001 
07002    ast_manager_event_multichan(EVENT_FLAG_CALL, "Unlink", 2, chans,
07003       "Channel1: %s\r\n"
07004       "Channel2: %s\r\n"
07005       "Uniqueid1: %s\r\n"
07006       "Uniqueid2: %s\r\n"
07007       "CallerID1: %s\r\n"
07008       "CallerID2: %s\r\n",
07009       c0->name, c1->name,
07010       c0->uniqueid, c1->uniqueid,
07011       S_COR(c0->caller.id.number.valid, c0->caller.id.number.str, "<unknown>"),
07012       S_COR(c1->caller.id.number.valid, c1->caller.id.number.str, "<unknown>"));
07013    ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
07014 
07015    return res;
07016 }

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.

Since:
1.8

Definition at line 1515 of file channel.c.

References ao2_callback_data, and channels.

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

01517 {
01518    return ao2_callback_data(channels, ao2_flags, cb_fn, arg, data);
01519 }

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

08897 {
08898    struct ast_cc_config_params *cc_params;
08899    struct ast_datastore *cc_datastore;
08900 
08901    if (!(cc_params = ast_cc_config_params_init())) {
08902       return -1;
08903    }
08904 
08905    if (!(cc_datastore = ast_datastore_alloc(&cc_channel_datastore_info, NULL))) {
08906       ast_cc_config_params_destroy(cc_params);
08907       return -1;
08908    }
08909 
08910    if (base_params) {
08911       ast_cc_copy_config_params(cc_params, base_params);
08912    }
08913    cc_datastore->data = cc_params;
08914    ast_channel_datastore_add(chan, cc_datastore);
08915    return 0;
08916 }

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

References ast_channel_cmpwhentohangup_tv().

00831 {
00832    struct timeval when = { offset, };
00833    return ast_channel_cmpwhentohangup_tv(chan, when);
00834 }

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

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

Referenced by ast_channel_cmpwhentohangup().

00816 {
00817    struct timeval whentohangup;
00818 
00819    if (ast_tvzero(chan->whentohangup))
00820       return ast_tvzero(offset) ? 0 : -1;
00821 
00822    if (ast_tvzero(offset))
00823       return 1;
00824 
00825    whentohangup = ast_tvadd(offset, ast_tvnow());
00826 
00827    return ast_tvdiff_ms(whentohangup, chan->whentohangup);
00828 }

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 8793 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_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(), ast_bridge_call(), ast_generic_bridge(), ast_pickup_call(), builtin_atxfer(), builtin_blindtransfer(), feature_request_and_dial(), handle_frame(), local_bridge_loop(), pickup_do(), remote_bridge_loop(), and wait_for_answer().

08794 {
08795    const char *macro;
08796    const char *macro_args;
08797    int retval;
08798 
08799    ast_channel_lock(macro_chan);
08800    macro = pbx_builtin_getvar_helper(macro_chan, is_caller
08801       ? "CONNECTED_LINE_CALLER_SEND_MACRO" : "CONNECTED_LINE_CALLEE_SEND_MACRO");
08802    macro = ast_strdupa(S_OR(macro, ""));
08803    macro_args = pbx_builtin_getvar_helper(macro_chan, is_caller
08804       ? "CONNECTED_LINE_CALLER_SEND_MACRO_ARGS" : "CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS");
08805    macro_args = ast_strdupa(S_OR(macro_args, ""));
08806 
08807    if (ast_strlen_zero(macro)) {
08808       ast_channel_unlock(macro_chan);
08809       return -1;
08810    }
08811 
08812    if (is_frame) {
08813       const struct ast_frame *frame = connected_info;
08814 
08815       ast_connected_line_parse_data(frame->data.ptr, frame->datalen, &macro_chan->connected);
08816    } else {
08817       const struct ast_party_connected_line *connected = connected_info;
08818 
08819       ast_party_connected_line_copy(&macro_chan->connected, connected);
08820    }
08821    ast_channel_unlock(macro_chan);
08822 
08823    if (!(retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args))) {
08824       ast_channel_lock(macro_chan);
08825       ast_channel_update_connected_line(macro_chan, &macro_chan->connected, NULL);
08826       ast_channel_unlock(macro_chan);
08827    }
08828 
08829    return retval;
08830 }

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

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

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

References ast_data_search_cmp_structure.

00477 {
00478    return ast_data_search_cmp_structure(tree, ast_channel, chan, structure_name);
00479 }

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

References ast_datastore_alloc.

02429 {
02430    return ast_datastore_alloc(info, uid);
02431 }

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

References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel::datastores, 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_datastores(), add_to_agi(), apply_plc(), 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_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(), 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_parkinglot(), manager_mutestream(), mark_transaction_active(), mute_callback(), park_exec_full(), pbx_builtin_raise_exception(), pitchshift_cb(), pitchshift_helper(), pop_exec(), queue_transfer_fixup(), 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(), stop_mixmonitor_exec(), try_calling(), unlock_read(), volume_callback(), and volume_write().

02470 {
02471    struct ast_datastore *datastore = NULL;
02472    
02473    if (info == NULL)
02474       return NULL;
02475 
02476    AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) {
02477       if (datastore->info != info) {
02478          continue;
02479       }
02480 
02481       if (uid == NULL) {
02482          /* matched by type only */
02483          break;
02484       }
02485 
02486       if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
02487          /* Matched by type AND uid */
02488          break;
02489       }
02490    }
02491    AST_LIST_TRAVERSE_SAFE_END;
02492 
02493    return datastore;
02494 }

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

References ast_datastore_free().

02434 {
02435    return ast_datastore_free(datastore);
02436 }

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

Inherit datastores from a parent to a child.

Definition at line 2438 of file channel.c.

References ast_datastore_alloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_channel::datastores, ast_datastore_info::duplicate, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.

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

02439 {
02440    struct ast_datastore *datastore = NULL, *datastore2;
02441 
02442    AST_LIST_TRAVERSE(&from->datastores, datastore, entry) {
02443       if (datastore->inheritance > 0) {
02444          datastore2 = ast_datastore_alloc(datastore->info, datastore->uid);
02445          if (datastore2) {
02446             datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
02447             datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
02448             AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry);
02449          }
02450       }
02451    }
02452    return 0;
02453 }

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

References AST_LIST_REMOVE, and ast_channel::datastores.

Referenced by acf_fetch(), acf_odbc_read(), adjust_frame_for_plc(), 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().

02465 {
02466    return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1;
02467 }

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

References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.

Referenced by __adsi_transmit_messages(), and find_cache().

01498 {
01499    int pre = 0;
01500 
01501    if (chan) {
01502       pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
01503       ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
01504    }
01505    return pre;
01506 }

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

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

Referenced by dial_exec_full(), and wait_for_answer().

06650 {
06651    /* Make sure we can early bridge, if not error out */
06652    if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge)))
06653       return -1;
06654 
06655    return c0->tech->early_bridge(c0, c1);
06656 }

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

References ast_channel_get_full().

01695 {
01696    return ast_channel_get_full(NULL, 0, exten, context);
01697 }

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

01690 {
01691    return ast_channel_get_full(name, name_len, NULL, NULL);
01692 }

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

References ast_channel_queryoption(), ast_copy_string(), AST_OPTION_CC_AGENT_TYPE, and ast_channel::name.

Referenced by find_agent_callbacks().

08958 {
08959    int len = size;
08960    char *slash;
08961 
08962    if (!ast_channel_queryoption(chan, AST_OPTION_CC_AGENT_TYPE, agent_type, &len, 0)) {
08963       return 0;
08964    }
08965 
08966    ast_copy_string(agent_type, chan->name, size);
08967    if ((slash = strchr(agent_type, '/'))) {
08968       *slash = '\0';
08969    }
08970    return 0;
08971 }

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

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

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

08919 {
08920    struct ast_datastore *cc_datastore;
08921 
08922    if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
08923       /* If we can't find the datastore, it almost definitely means that the channel type being
08924        * used has not had its driver modified to parse CC config parameters. The best action
08925        * to take here is to create the parameters on the spot with the defaults set.
08926        */
08927       if (ast_channel_cc_params_init(chan, NULL)) {
08928          return NULL;
08929       }
08930       if (!(cc_datastore = ast_channel_datastore_find(chan, &cc_channel_datastore_info, NULL))) {
08931          /* Should be impossible */
08932          return NULL;
08933       }
08934    }
08935 
08936    ast_assert(cc_datastore->data != NULL);
08937    return cc_datastore->data;
08938 }

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

References ast_channel_queryoption(), ast_copy_string(), AST_OPTION_DEVICE_NAME, and ast_channel::name.

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

08941 {
08942    int len = name_buffer_length;
08943    char *dash;
08944    if (!ast_channel_queryoption(chan, AST_OPTION_DEVICE_NAME, device_name, &len, 0)) {
08945       return 0;
08946    }
08947 
08948    /* Dang. Do it the old-fashioned way */
08949    ast_copy_string(device_name, chan->name, name_buffer_length);
08950    if ((dash = strrchr(device_name, '-'))) {
08951       *dash = '\0';
08952    }
08953 
08954    return 0;
08955 }

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

02247 {
02248    enum ast_t38_state state = T38_STATE_UNAVAILABLE;
02249    int datalen = sizeof(state);
02250 
02251    ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
02252 
02253    return state;
02254 }

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 5693 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(), ast_var_t::entries, and ast_channel::varshead.

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

05694 {
05695    struct ast_var_t *current, *newvar;
05696    const char *varname;
05697 
05698    AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
05699       int vartype = 0;
05700 
05701       varname = ast_var_full_name(current);
05702       if (!varname)
05703          continue;
05704 
05705       if (varname[0] == '_') {
05706          vartype = 1;
05707          if (varname[1] == '_')
05708             vartype = 2;
05709       }
05710 
05711       switch (vartype) {
05712       case 1:
05713          newvar = ast_var_assign(&varname[1], ast_var_value(current));
05714          if (newvar) {
05715             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
05716             ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar));
05717          }
05718          break;
05719       case 2:
05720          newvar = ast_var_assign(varname, ast_var_value(current));
05721          if (newvar) {
05722             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
05723             ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar));
05724          }
05725          break;
05726       default:
05727          ast_debug(1, "Not copying variable %s.\n", ast_var_name(current));
05728          break;
05729       }
05730    }
05731 }

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

01583 {
01584    struct ast_channel_iterator *i;
01585 
01586    if (!(i = ast_calloc(1, sizeof(*i)))) {
01587       return NULL;
01588    }
01589 
01590    i->simple_iterator = ao2_iterator_init(channels, 0);
01591    i->active_iterator = &i->simple_iterator;
01592 
01593    return i;
01594 }

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

References channel_iterator_search().

Referenced by common_exec(), and pickup_by_exten().

01573 {
01574    return channel_iterator_search(NULL, 0, exten, context);
01575 }

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

References channel_iterator_search().

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

01578 {
01579    return channel_iterator_search(name, name_len, NULL, NULL);
01580 }

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

01531 {
01532    ao2_iterator_destroy(i->active_iterator);
01533    ast_free(i);
01534 
01535    return NULL;
01536 }

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

01597 {
01598    return ao2_iterator_next(i->active_iterator);
01599 }

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 5569 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(), park_exec_full(), simple_bridge_join(), try_calling(), and wait_for_answer().

05570 {
05571    /* Some callers do not check return code, and we must try to set all call legs correctly */
05572    int rc = 0;
05573 
05574    /* Set up translation from the chan to the peer */
05575    rc = ast_channel_make_compatible_helper(chan, peer);
05576 
05577    if (rc < 0)
05578       return rc;
05579 
05580    /* Set up translation from the peer to the chan */
05581    rc = ast_channel_make_compatible_helper(peer, chan);
05582 
05583    return rc;
05584 }

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 needs to be locked before calling this function.

Definition at line 5586 of file channel.c.

References ast_channel::_bridge, ast_bridged_channel(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_log(), ast_null_frame, ast_queue_frame(), ast_channel_tech::get_base_channel, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::name, and ast_channel::tech.

Referenced by analog_attempt_transfer(), ast_async_goto(), ast_pickup_call(), attempt_transfer(), builtin_atxfer(), check_availability(), check_bridge(), check_goto_on_transfer(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), masq_park_call(), misdn_attempt_transfer(), pickup_do(), sig_pri_attempt_transfer(), sip_park(), and skinny_transfer().

05587 {
05588    int res = -1;
05589    struct ast_channel *final_orig, *final_clone, *base;
05590 
05591 retrymasq:
05592    final_orig = original;
05593    final_clone = clonechan;
05594 
05595    ast_channel_lock(original);
05596    while (ast_channel_trylock(clonechan)) {
05597       ast_channel_unlock(original);
05598       usleep(1);
05599       ast_channel_lock(original);
05600    }
05601 
05602    /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
05603       and if so, we don't really want to masquerade it, but its proxy */
05604    if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original))
05605       final_orig = original->_bridge;
05606 
05607    if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan))
05608       final_clone = clonechan->_bridge;
05609    
05610    if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) {
05611       final_clone = base;
05612    }
05613 
05614    if ((final_orig != original) || (final_clone != clonechan)) {
05615       /* Lots and lots of deadlock avoidance.  The main one we're competing with
05616        * is ast_write(), which locks channels recursively, when working with a
05617        * proxy channel. */
05618       if (ast_channel_trylock(final_orig)) {
05619          ast_channel_unlock(clonechan);
05620          ast_channel_unlock(original);
05621          goto retrymasq;
05622       }
05623       if (ast_channel_trylock(final_clone)) {
05624          ast_channel_unlock(final_orig);
05625          ast_channel_unlock(clonechan);
05626          ast_channel_unlock(original);
05627          goto retrymasq;
05628       }
05629       ast_channel_unlock(clonechan);
05630       ast_channel_unlock(original);
05631       original = final_orig;
05632       clonechan = final_clone;
05633    }
05634 
05635    if (original == clonechan) {
05636       ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
05637       ast_channel_unlock(clonechan);
05638       ast_channel_unlock(original);
05639       return -1;
05640    }
05641 
05642    ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n",
05643       clonechan->name, original->name);
05644 
05645    if (!original->masqr && !original->masq && !clonechan->masq && !clonechan->masqr) {
05646       original->masq = clonechan;
05647       clonechan->masqr = original;
05648       ast_queue_frame(original, &ast_null_frame);
05649       ast_queue_frame(clonechan, &ast_null_frame);
05650       ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name);
05651       res = 0;
05652    } else if (original->masq) {
05653       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
05654          original->masq->name, original->name);
05655    } else if (original->masqr) {
05656       /* not yet as a previously planned masq hasn't yet happened */
05657       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
05658          original->name, original->masqr->name);
05659    } else if (clonechan->masq) {
05660       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
05661          clonechan->masq->name, clonechan->name);
05662    } else { /* (clonechan->masqr) */
05663       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
05664       clonechan->name, clonechan->masqr->name);
05665    }
05666 
05667    ast_channel_unlock(clonechan);
05668    ast_channel_unlock(original);
05669 
05670    return res;
05671 }

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

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

07033 {
07034    if (!chan->tech->queryoption) {
07035       errno = ENOSYS;
07036       return -1;
07037    }
07038 
07039    if (block)
07040       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
07041 
07042    return chan->tech->queryoption(chan, option, data, datalen);
07043 }

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

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

Referenced by ast_pickup_call(), handle_request_invite(), handle_request_update(), handle_response_invite(), local_attended_transfer(), misdn_queue_connected_line_update(), pickup_do(), and sig_pri_handle_subcmds().

08274 {
08275    unsigned char data[1024];  /* This should be large enough */
08276    size_t datalen;
08277 
08278    datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
08279    if (datalen == (size_t) -1) {
08280       return;
08281    }
08282 
08283    ast_queue_control_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
08284 }

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

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

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

08781 {
08782    unsigned char data[1024];  /* This should be large enough */
08783    size_t datalen;
08784 
08785    datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
08786    if (datalen == (size_t) -1) {
08787       return;
08788    }
08789 
08790    ast_queue_control_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
08791 }

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

04974 {
04975    switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
04976    {
04977    case 0:
04978       return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
04979    case AST_CONTROL_HANGUP:
04980       return "Hangup";
04981    case AST_CONTROL_RING:
04982       return "Local Ring";
04983    case AST_CONTROL_RINGING:
04984       return "Remote end Ringing";
04985    case AST_CONTROL_ANSWER:
04986       return "Remote end has Answered";
04987    case AST_CONTROL_BUSY:
04988       return "Remote end is Busy";
04989    case AST_CONTROL_CONGESTION:
04990       return "Congestion (circuits busy)";
04991    default:
04992       return "Unknown Reason!!";
04993    }
04994 }

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

References ast_app_run_macro(), ast_channel_lock, ast_channel_unlock, ast_channel_update_redirecting(), ast_party_redirecting_copy(), 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(), do_forward(), feature_request_and_dial(), handle_frame(), local_bridge_loop(), remote_bridge_loop(), and wait_for_answer().

08833 {
08834    const char *macro;
08835    const char *macro_args;
08836    int retval;
08837 
08838    ast_channel_lock(macro_chan);
08839    macro = pbx_builtin_getvar_helper(macro_chan, is_caller
08840       ? "REDIRECTING_CALLER_SEND_MACRO" : "REDIRECTING_CALLEE_SEND_MACRO");
08841    macro = ast_strdupa(S_OR(macro, ""));
08842    macro_args = pbx_builtin_getvar_helper(macro_chan, is_caller
08843       ? "REDIRECTING_CALLER_SEND_MACRO_ARGS" : "REDIRECTING_CALLEE_SEND_MACRO_ARGS");
08844    macro_args = ast_strdupa(S_OR(macro_args, ""));
08845 
08846    if (ast_strlen_zero(macro)) {
08847       ast_channel_unlock(macro_chan);
08848       return -1;
08849    }
08850 
08851    if (is_frame) {
08852       const struct ast_frame *frame = redirecting_info;
08853 
08854       ast_redirecting_parse_data(frame->data.ptr, frame->datalen, &macro_chan->redirecting);
08855    } else {
08856       const struct ast_party_redirecting *redirecting = redirecting_info;
08857 
08858       ast_party_redirecting_copy(&macro_chan->redirecting, redirecting);
08859    }
08860    ast_channel_unlock(macro_chan);
08861 
08862    retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
08863    if (!retval) {
08864       ast_channel_lock(macro_chan);
08865       ast_channel_update_redirecting(macro_chan, &macro_chan->redirecting, NULL);
08866       ast_channel_unlock(macro_chan);
08867    }
08868 
08869    return retval;
08870 }

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

00838 {
00839    struct chanlist *chan;
00840 
00841    AST_RWLIST_WRLOCK(&backends);
00842 
00843    AST_RWLIST_TRAVERSE(&backends, chan, list) {
00844       if (!strcasecmp(tech->type, chan->tech->type)) {
00845          ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
00846          AST_RWLIST_UNLOCK(&backends);
00847          return -1;
00848       }
00849    }
00850    
00851    if (!(chan = ast_calloc(1, sizeof(*chan)))) {
00852       AST_RWLIST_UNLOCK(&backends);
00853       return -1;
00854    }
00855    chan->tech = tech;
00856    AST_RWLIST_INSERT_HEAD(&backends, chan, list);
00857 
00858    ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
00859 
00860    ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description);
00861 
00862    AST_RWLIST_UNLOCK(&backends);
00863 
00864    return 0;
00865 }

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
Since:
1.8

Definition at line 1798 of file channel.c.

References ao2_unlink, ast_channel_unref, and channels.

Referenced by acf_odbc_read(), acf_odbc_write(), action_getvar(), agent_cleanup(), agent_new(), ast_add_extension2_lockopt(), ast_cel_fabricate_channel_from_event(), ast_do_masquerade(), ast_hangup(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), ast_request(), ast_str_substitute_variables_full(), bridge_request(), cli_odbc_read(), cli_odbc_write(), custom_log(), do_notify(), gtalk_newcall(), local_new(), local_request(), make_email_file(), manager_log(), pbx_substitute_variables_helper_full(), rotate_file(), sendmail(), sendpage(), syslog_log(), and write_cdr().

01799 {
01800    /* Safe, even if already unlinked. */
01801    ao2_unlink(channels, chan);
01802    return ast_channel_unref(chan);
01803 }

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

05507 {
05508    if (chan->tech->send_html)
05509       return chan->tech->send_html(chan, subclass, data, datalen);
05510    return -1;
05511 }

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

References ast_channel_sendhtml(), and AST_HTML_URL.

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

05514 {
05515    return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
05516 }

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

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

06335 {
06336    if (&chan->caller == caller) {
06337       /* Don't set to self */
06338       return;
06339    }
06340 
06341    ast_channel_lock(chan);
06342    ast_party_caller_set(&chan->caller, caller, update);
06343    ast_channel_unlock(chan);
06344 }

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 6346 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(), misdn_update_caller_id(), and ring_entry().

06347 {
06348    struct ast_party_caller pre_set;
06349 
06350    if (&chan->caller == caller) {
06351       /* Don't set to self */
06352       return;
06353    }
06354 
06355    ast_channel_lock(chan);
06356    pre_set = chan->caller;
06357    ast_party_caller_set(&chan->caller, caller, update);
06358    if (S_COR(pre_set.id.number.valid, pre_set.id.number.str, NULL)
06359          != S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL)
06360       || S_COR(pre_set.id.name.valid, pre_set.id.name.str, NULL)
06361          != S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, NULL)) {
06362       /* The caller id name or number changed. */
06363       report_new_callerid(chan);
06364    }
06365    if (chan->cdr) {
06366       ast_cdr_setcid(chan->cdr, chan);
06367    }
06368    ast_channel_unlock(chan);
06369 }

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 7633 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(), and dial_exec_full().

07634 {
07635    if (&chan->connected == connected) {
07636       /* Don't set to self */
07637       return;
07638    }
07639 
07640    ast_channel_lock(chan);
07641    ast_party_connected_line_set(&chan->connected, connected, update);
07642    ast_channel_unlock(chan);
07643 }

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

Set the file descriptor on the channel

Definition at line 2497 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(), jingle_new(), mgcp_new(), misdn_new(), my_swap_subchannels(), nbs_new(), oss_new(), phone_new(), setformat(), sip_new(), skinny_new(), start_rtp(), and swap_subs().

02498 {
02499 #ifdef HAVE_EPOLL
02500    struct epoll_event ev;
02501    struct ast_epoll_data *aed = NULL;
02502 
02503    if (chan->fds[which] > -1) {
02504       epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev);
02505       aed = chan->epfd_data[which];
02506    }
02507 
02508    /* If this new fd is valid, add it to the epoll */
02509    if (fd > -1) {
02510       if (!aed && (!(aed = ast_calloc(1, sizeof(*aed)))))
02511          return;
02512       
02513       chan->epfd_data[which] = aed;
02514       aed->chan = chan;
02515       aed->which = which;
02516       
02517       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
02518       ev.data.ptr = aed;
02519       epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev);
02520    } else if (aed) {
02521       /* We don't have to keep around this epoll data structure now */
02522       free(aed);
02523       chan->epfd_data[which] = NULL;
02524    }
02525 #endif
02526    chan->fds[which] = fd;
02527    return;
02528 }

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

propagate the linked id between chan and peer

Definition at line 5837 of file channel.c.

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

Referenced by ast_bridge_call(), and ast_do_masquerade().

05838 {
05839    const char* linkedid=NULL;
05840    struct ast_channel *bridged;
05841 
05842    linkedid = oldest_linkedid(chan->linkedid, peer->linkedid);
05843    linkedid = oldest_linkedid(linkedid, chan->uniqueid);
05844    linkedid = oldest_linkedid(linkedid, peer->uniqueid);
05845    if (chan->_bridge) {
05846       bridged = ast_bridged_channel(chan);
05847       if (bridged != peer) {
05848          linkedid = oldest_linkedid(linkedid, bridged->linkedid);
05849          linkedid = oldest_linkedid(linkedid, bridged->uniqueid);
05850       }
05851    }
05852    if (peer->_bridge) {
05853       bridged = ast_bridged_channel(peer);
05854       if (bridged != chan) {
05855          linkedid = oldest_linkedid(linkedid, bridged->linkedid);
05856          linkedid = oldest_linkedid(linkedid, bridged->uniqueid);
05857       }
05858    }
05859 
05860    /* just in case setting a stringfield to itself causes problems */
05861    linkedid = ast_strdupa(linkedid);
05862 
05863    ast_channel_change_linkedid(chan, linkedid);
05864    ast_channel_change_linkedid(peer, linkedid);
05865    if (chan->_bridge) {
05866       bridged = ast_bridged_channel(chan);
05867       if (bridged != peer) {
05868          ast_channel_change_linkedid(bridged, linkedid);
05869       }
05870    }
05871    if (peer->_bridge) {
05872       bridged = ast_bridged_channel(peer);
05873       if (bridged != chan) {
05874          ast_channel_change_linkedid(bridged, linkedid);
05875       }
05876    }
05877 }

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

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

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

08287 {
08288    if (&chan->redirecting == redirecting) {
08289       /* Don't set to self */
08290       return;
08291    }
08292 
08293    ast_channel_lock(chan);
08294    ast_party_redirecting_set(&chan->redirecting, redirecting, update);
08295    ast_channel_unlock(chan);
08296 }

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

References 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(), rpt(), rpt_exec(), set_format(), set_listen_volume(), set_security_requirements(), set_talk_volume(), sndfax_exec(), try_calling(), and vm_forwardoptions().

07020 {
07021    if (!chan->tech->setoption) {
07022       errno = ENOSYS;
07023       return -1;
07024    }
07025 
07026    if (block)
07027       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
07028 
07029    return chan->tech->setoption(chan, option, data, datalen);
07030 }

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

References ast_channel_setwhentohangup_tv().

00809 {
00810    struct timeval when = { offset, };
00811    ast_channel_setwhentohangup_tv(chan, when);
00812 }

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

00802 {
00803    chan->whentohangup = ast_tvzero(offset) ? offset : ast_tvadd(offset, ast_tvnow());
00804    ast_queue_frame(chan, &ast_null_frame);
00805    return;
00806 }

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 7507 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_channel::name, ast_silence_generator::old_write_format, and ast_channel::writeformat.

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

07508 {
07509    struct ast_silence_generator *state;
07510 
07511    if (!(state = ast_calloc(1, sizeof(*state)))) {
07512       return NULL;
07513    }
07514 
07515    state->old_write_format = chan->writeformat;
07516 
07517    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
07518       ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
07519       ast_free(state);
07520       return NULL;
07521    }
07522 
07523    ast_activate_generator(chan, &silence_generator, state);
07524 
07525    ast_debug(1, "Started silence generator on '%s'\n", chan->name);
07526 
07527    return state;
07528 }

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

References ast_deactivate_generator(), ast_debug, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_channel::name, and ast_silence_generator::old_write_format.

Referenced by __ast_play_and_record(), 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().

07531 {
07532    if (!state)
07533       return;
07534 
07535    ast_deactivate_generator(chan);
07536 
07537    ast_debug(1, "Stopped silence generator on '%s'\n", chan->name);
07538 
07539    if (ast_set_write_format(chan, state->old_write_format) < 0)
07540       ast_log(LOG_ERROR, "Could not return write format to its original state\n");
07541 
07542    ast_free(state);
07543 }

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

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

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

05502 {
05503    return (chan->tech->send_html) ? 1 : 0;
05504 }

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

References ast_clear_flag, and AST_FLAG_DEFER_DTMF.

Referenced by __adsi_transmit_messages(), find_cache(), and rpt_call().

01510 {
01511    if (chan)
01512       ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
01513 }

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

00869 {
00870    struct chanlist *chan;
00871 
00872    ast_debug(1, "Unregistering channel type '%s'\n", tech->type);
00873 
00874    AST_RWLIST_WRLOCK(&backends);
00875 
00876    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
00877       if (chan->tech == tech) {
00878          AST_LIST_REMOVE_CURRENT(list);
00879          ast_free(chan);
00880          ast_verb(2, "Unregistered channel type '%s'\n", tech->type);
00881          break;   
00882       }
00883    }
00884    AST_LIST_TRAVERSE_SAFE_END;
00885 
00886    AST_RWLIST_UNLOCK(&backends);
00887 }

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

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

Referenced by ast_channel_connected_line_macro(), ast_pickup_call(), builtin_atxfer(), builtin_blindtransfer(), connectedline_write(), pickup_do(), and wait_for_answer().

08261 {
08262    unsigned char data[1024];  /* This should be large enough */
08263    size_t datalen;
08264 
08265    datalen = ast_connected_line_build_data(data, sizeof(data), connected, update);
08266    if (datalen == (size_t) -1) {
08267       return;
08268    }
08269 
08270    ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE, data, datalen);
08271 }

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

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

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

08768 {
08769    unsigned char data[1024];  /* This should be large enough */
08770    size_t datalen;
08771 
08772    datalen = ast_redirecting_build_data(data, sizeof(data), redirecting, update);
08773    if (datalen == (size_t) -1) {
08774       return;
08775    }
08776 
08777    ast_indicate_data(chan, AST_CONTROL_REDIRECTING, data, datalen);
08778 }

struct ast_variable* ast_channeltype_list ( void   )  [read]

return an ast_variable list of channeltypes

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

00249 {
00250    struct chanlist *cl;
00251    struct ast_variable *var = NULL, *prev = NULL;
00252 
00253    AST_RWLIST_RDLOCK(&backends);
00254    AST_RWLIST_TRAVERSE(&backends, cl, list) {
00255       if (prev)  {
00256          if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, "")))
00257             prev = prev->next;
00258       } else {
00259          var = ast_variable_new(cl->tech->type, cl->tech->description, "");
00260          prev = var;
00261       }
00262    }
00263    AST_RWLIST_UNLOCK(&backends);
00264 
00265    return var;
00266 }

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 742 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_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(), channel_spy(), check_bridge(), common_exec(), conf_play(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), feature_request_and_dial(), findmeexec(), func_channel_read(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), local_bridge_loop(), local_fixup(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), remote_bridge_loop(), rpt(), rpt_exec(), run_ras(), try_calling(), and wait_for_answer().

00743 {
00744    if (chan->_softhangup)     /* yes if soft hangup flag set */
00745       return 1;
00746    if (ast_tvzero(chan->whentohangup)) /* no if no hangup scheduled */
00747       return 0;
00748    if (ast_tvdiff_ms(chan->whentohangup, ast_tvnow()) > 0)  /* no if hangup time has not come yet. */
00749       return 0;
00750    ast_debug(4, "Hangup time has come: %" PRIi64 "\n", ast_tvdiff_ms(chan->whentohangup, ast_tvnow()));
00751    chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */
00752    return 1;
00753 }

int ast_check_hangup_locked ( struct ast_channel *  chan  ) 

Definition at line 755 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().

Referenced by action_redirect(), and ast_channel_bridge().

00756 {
00757    int res;
00758    ast_channel_lock(chan);
00759    res = ast_check_hangup(chan);
00760    ast_channel_unlock(chan);
00761    return res;
00762 }

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 8000 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(), and local_indicate().

08001 {
08002    int32_t value;
08003    size_t pos = 0;
08004    int res;
08005 
08006    static const struct ast_party_id_ies ies = {
08007       .name.str = AST_CONNECTED_LINE_NAME,
08008       .name.char_set = AST_CONNECTED_LINE_NAME_CHAR_SET,
08009       .name.presentation = AST_CONNECTED_LINE_NAME_PRESENTATION,
08010       .name.valid = AST_CONNECTED_LINE_NAME_VALID,
08011 
08012       .number.str = AST_CONNECTED_LINE_NUMBER,
08013       .number.plan = AST_CONNECTED_LINE_NUMBER_PLAN,
08014       .number.presentation = AST_CONNECTED_LINE_NUMBER_PRESENTATION,
08015       .number.valid = AST_CONNECTED_LINE_NUMBER_VALID,
08016 
08017       .subaddress.str = AST_CONNECTED_LINE_SUBADDRESS,
08018       .subaddress.type = AST_CONNECTED_LINE_SUBADDRESS_TYPE,
08019       .subaddress.odd_even_indicator = AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN,
08020       .subaddress.valid = AST_CONNECTED_LINE_SUBADDRESS_VALID,
08021 
08022       .tag = AST_CONNECTED_LINE_TAG,
08023       .combined_presentation = AST_CONNECTED_LINE_ID_PRESENTATION,
08024    };
08025 
08026    /*
08027     * The size of integer values must be fixed in case the frame is
08028     * shipped to another machine.
08029     */
08030 
08031    /* Connected line frame version */
08032    if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
08033       ast_log(LOG_WARNING, "No space left for connected line frame version\n");
08034       return -1;
08035    }
08036    data[pos++] = AST_CONNECTED_LINE_VERSION;
08037    data[pos++] = 1;
08038    data[pos++] = 2;/* Version 1 did not have a version ie */
08039 
08040    res = party_id_build_data(data + pos, datalen - pos, &connected->id,
08041       "connected line", &ies, update ? &update->id : NULL);
08042    if (res < 0) {
08043       return -1;
08044    }
08045    pos += res;
08046 
08047    /* Connected line source */
08048    if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
08049       ast_log(LOG_WARNING, "No space left for connected line source\n");
08050       return -1;
08051    }
08052    data[pos++] = AST_CONNECTED_LINE_SOURCE;
08053    data[pos++] = sizeof(value);
08054    value = htonl(connected->source);
08055    memcpy(data + pos, &value, sizeof(value));
08056    pos += sizeof(value);
08057 
08058    return pos;
08059 }

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 7618 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 begin_dial_channel(), builtin_atxfer(), dial_exec_full(), feature_request_and_dial(), local_call(), pickup_do(), ring_entry(), and wait_for_answer().

07619 {
07620    ast_party_id_copy(&dest->id, &src->id);
07621    ast_party_id_copy(&dest->ani, &src->ani);
07622    dest->ani2 = src->ani2;
07623 }

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

07626 {
07627    ast_party_id_copy(&dest->id, &src->id);
07628    ast_party_id_copy(&dest->ani, &src->ani);
07629 
07630    dest->ani2 = src->ani2;
07631 }

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 8061 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(), socket_process(), and wait_for_answer().

08062 {
08063    size_t pos;
08064    unsigned char ie_len;
08065    unsigned char ie_id;
08066    int32_t value;
08067    int frame_version = 1;
08068    int combined_presentation = 0;
08069    int got_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
08070 
08071    for (pos = 0; pos < datalen; pos += ie_len) {
08072       if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
08073          ast_log(LOG_WARNING, "Invalid connected line update\n");
08074          return -1;
08075       }
08076       ie_id = data[pos++];
08077       ie_len = data[pos++];
08078       if (datalen < pos + ie_len) {
08079          ast_log(LOG_WARNING, "Invalid connected line update\n");
08080          return -1;
08081       }
08082 
08083       switch (ie_id) {
08084 /* Connected line party frame version */
08085       case AST_CONNECTED_LINE_VERSION:
08086          if (ie_len != 1) {
08087             ast_log(LOG_WARNING, "Invalid connected line frame version (%u)\n",
08088                (unsigned) ie_len);
08089             break;
08090          }
08091          frame_version = data[pos];
08092          break;
08093 /* Connected line party id name */
08094       case AST_CONNECTED_LINE_NAME:
08095          ast_free(connected->id.name.str);
08096          connected->id.name.str = ast_malloc(ie_len + 1);
08097          if (connected->id.name.str) {
08098             memcpy(connected->id.name.str, data + pos, ie_len);
08099             connected->id.name.str[ie_len] = 0;
08100          }
08101          break;
08102       case AST_CONNECTED_LINE_NAME_CHAR_SET:
08103          if (ie_len != 1) {
08104             ast_log(LOG_WARNING, "Invalid connected line name char set (%u)\n",
08105                (unsigned) ie_len);
08106             break;
08107          }
08108          connected->id.name.char_set = data[pos];
08109          break;
08110       case AST_CONNECTED_LINE_NAME_PRESENTATION:
08111          if (ie_len != 1) {
08112             ast_log(LOG_WARNING, "Invalid connected line name presentation (%u)\n",
08113                (unsigned) ie_len);
08114             break;
08115          }
08116          connected->id.name.presentation = data[pos];
08117          break;
08118       case AST_CONNECTED_LINE_NAME_VALID:
08119          if (ie_len != 1) {
08120             ast_log(LOG_WARNING, "Invalid connected line name valid (%u)\n",
08121                (unsigned) ie_len);
08122             break;
08123          }
08124          connected->id.name.valid = data[pos];
08125          break;
08126 /* Connected line party id number */
08127       case AST_CONNECTED_LINE_NUMBER:
08128          ast_free(connected->id.number.str);
08129          connected->id.number.str = ast_malloc(ie_len + 1);
08130          if (connected->id.number.str) {
08131             memcpy(connected->id.number.str, data + pos, ie_len);
08132             connected->id.number.str[ie_len] = 0;
08133          }
08134          break;
08135       case AST_CONNECTED_LINE_NUMBER_PLAN:
08136          if (ie_len != 1) {
08137             ast_log(LOG_WARNING, "Invalid connected line numbering plan (%u)\n",
08138                (unsigned) ie_len);
08139             break;
08140          }
08141          connected->id.number.plan = data[pos];
08142          break;
08143       case AST_CONNECTED_LINE_NUMBER_PRESENTATION:
08144          if (ie_len != 1) {
08145             ast_log(LOG_WARNING, "Invalid connected line number presentation (%u)\n",
08146                (unsigned) ie_len);
08147             break;
08148          }
08149          connected->id.number.presentation = data[pos];
08150          break;
08151       case AST_CONNECTED_LINE_NUMBER_VALID:
08152          if (ie_len != 1) {
08153             ast_log(LOG_WARNING, "Invalid connected line number valid (%u)\n",
08154                (unsigned) ie_len);
08155             break;
08156          }
08157          connected->id.number.valid = data[pos];
08158          break;
08159 /* Connected line party id combined presentation */
08160       case AST_CONNECTED_LINE_ID_PRESENTATION:
08161          if (ie_len != 1) {
08162             ast_log(LOG_WARNING, "Invalid connected line combined presentation (%u)\n",
08163                (unsigned) ie_len);
08164             break;
08165          }
08166          combined_presentation = data[pos];
08167          got_combined_presentation = 1;
08168          break;
08169 /* Connected line party id subaddress */
08170       case AST_CONNECTED_LINE_SUBADDRESS:
08171          ast_free(connected->id.subaddress.str);
08172          connected->id.subaddress.str = ast_malloc(ie_len + 1);
08173          if (connected->id.subaddress.str) {
08174             memcpy(connected->id.subaddress.str, data + pos, ie_len);
08175             connected->id.subaddress.str[ie_len] = 0;
08176          }
08177          break;
08178       case AST_CONNECTED_LINE_SUBADDRESS_TYPE:
08179          if (ie_len != 1) {
08180             ast_log(LOG_WARNING, "Invalid connected line type of subaddress (%u)\n",
08181                (unsigned) ie_len);
08182             break;
08183          }
08184          connected->id.subaddress.type = data[pos];
08185          break;
08186       case AST_CONNECTED_LINE_SUBADDRESS_ODD_EVEN:
08187          if (ie_len != 1) {
08188             ast_log(LOG_WARNING,
08189                "Invalid connected line subaddress odd-even indicator (%u)\n",
08190                (unsigned) ie_len);
08191             break;
08192          }
08193          connected->id.subaddress.odd_even_indicator = data[pos];
08194          break;
08195       case AST_CONNECTED_LINE_SUBADDRESS_VALID:
08196          if (ie_len != 1) {
08197             ast_log(LOG_WARNING, "Invalid connected line subaddress valid (%u)\n",
08198                (unsigned) ie_len);
08199             break;
08200          }
08201          connected->id.subaddress.valid = data[pos];
08202          break;
08203 /* Connected line party tag */
08204       case AST_CONNECTED_LINE_TAG:
08205          ast_free(connected->id.tag);
08206          connected->id.tag = ast_malloc(ie_len + 1);
08207          if (connected->id.tag) {
08208             memcpy(connected->id.tag, data + pos, ie_len);
08209             connected->id.tag[ie_len] = 0;
08210          }
08211          break;
08212 /* Connected line party source */
08213       case AST_CONNECTED_LINE_SOURCE:
08214          if (ie_len != sizeof(value)) {
08215             ast_log(LOG_WARNING, "Invalid connected line source (%u)\n",
08216                (unsigned) ie_len);
08217             break;
08218          }
08219          memcpy(&value, data + pos, sizeof(value));
08220          connected->source = ntohl(value);
08221          break;
08222 /* Connected line party unknown element */
08223       default:
08224          ast_log(LOG_DEBUG, "Unknown connected line element: %u (%u)\n",
08225             (unsigned) ie_id, (unsigned) ie_len);
08226          break;
08227       }
08228    }
08229 
08230    switch (frame_version) {
08231    case 1:
08232       /*
08233        * The other end is an earlier version that we need to adjust
08234        * for compatibility.
08235        */
08236       connected->id.name.valid = 1;
08237       connected->id.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
08238       connected->id.number.valid = 1;
08239       if (got_combined_presentation) {
08240          connected->id.name.presentation = combined_presentation;
08241          connected->id.number.presentation = combined_presentation;
08242       }
08243       break;
08244    case 2:
08245       /* The other end is at the same level as we are. */
08246       break;
08247    default:
08248       /*
08249        * The other end is newer than we are.
08250        * We need to assume that they are compatible with us.
08251        */
08252       ast_log(LOG_DEBUG, "Connected line frame has newer version: %u\n",
08253          (unsigned) frame_version);
08254       break;
08255    }
08256 
08257    return 0;
08258 }

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.

Definition at line 5945 of file channel.c.

References __ast_change_name_nolink(), ast_channel::_bridge, ast_channel::_softhangup, ast_channel::_state, ast_channel::accountcode, accountcode, ast_channel::adsicpe, ast_channel::alertpipe, ao2_link, ao2_lock, ao2_unlink, ao2_unlock, ast_app_group_update(), ast_autochan_new_channel(), ast_bridged_channel(), ast_cause2str(), AST_CEL_BRIDGE_UPDATE, ast_cel_report_event(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_release(), ast_channel_set_fd(), ast_channel_set_linkgroup(), ast_channel_trylock, ast_channel_unlock, AST_CONTROL_SRCCHANGE, ast_copy_string(), ast_debug, AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_GENERATOR_FD, ast_getformatname(), ast_indicate(), AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK, AST_LIST_HEAD_SET_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, CHANNEL_DEADLOCK_AVOIDANCE, channels, clone_variables(), ast_channel::connected, ast_datastore::data, ast_channel::datastores, 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, ast_channel::language, language, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::musicclass, musicclass, ast_channel::name, ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::readq, ast_channel::redirecting, report_new_callerid(), S_OR, ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, ast_channel::uniqueid, ast_channel::visible_indication, and ast_channel::writeformat.

Referenced by __ast_read(), ast_async_goto(), ast_hangup(), ast_waitfor_nandfds(), ast_write(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), local_attended_transfer(), sip_park(), and sip_park_thread().

05946 {
05947    format_t x;
05948    int i;
05949    int res=0;
05950    int origstate;
05951    struct ast_frame *current;
05952    const struct ast_channel_tech *t;
05953    void *t_pvt;
05954    union {
05955       struct ast_party_dialed dialed;
05956       struct ast_party_caller caller;
05957       struct ast_party_connected_line connected;
05958       struct ast_party_redirecting redirecting;
05959    } exchange;
05960    struct ast_channel *clonechan, *chans[2];
05961    struct ast_channel *bridged;
05962    struct ast_cdr *cdr;
05963    format_t rformat = original->readformat;
05964    format_t wformat = original->writeformat;
05965    char newn[AST_CHANNEL_NAME];
05966    char orig[AST_CHANNEL_NAME];
05967    char masqn[AST_CHANNEL_NAME];
05968    char zombn[AST_CHANNEL_NAME];
05969 
05970    /* XXX This operation is a bit odd.  We're essentially putting the guts of
05971     * the clone channel into the original channel.  Start by killing off the
05972     * original channel's backend.  While the features are nice, which is the
05973     * reason we're keeping it, it's still awesomely weird. XXX */
05974 
05975    /* The reasoning for the channels ao2_container lock here is complex.
05976     * 
05977     * In order to check for a race condition, the original channel must
05978     * be locked.  If it is determined that the masquerade should proceed
05979     * the original channel can absolutely not be unlocked until the end
05980     * of the function.  Since after determining the masquerade should
05981     * continue requires the channels to be unlinked from the ao2_container,
05982     * the container lock must be held first to achieve proper locking order.
05983     */
05984    ao2_lock(channels);
05985 
05986    /* lock the original channel to determine if the masquerade is require or not */
05987    ast_channel_lock(original);
05988 
05989    /* This checks to see if the masquerade has already happened or not.  There is a
05990     * race condition that exists for this function. Since all pvt and channel locks
05991     * must be let go before calling do_masquerade, it is possible that it could be
05992     * called multiple times for the same channel.  This check verifies whether
05993     * or not the masquerade has already been completed by another thread */
05994    if (!original->masq) {
05995       ast_channel_unlock(original);
05996       ao2_unlock(channels);
05997       return 0; /* masq already completed by another thread, or never needed to be done to begin with */
05998    }
05999 
06000    /* now that we have verified no race condition exists, set the clone channel */
06001    clonechan = original->masq;
06002 
06003    /* since this function already holds the global container lock, unlocking original
06004     * for deadlock avoidance will not result in any sort of masquerade race condition.
06005     * If masq is called by a different thread while this happens, it will be stuck waiting
06006     * until we unlock the container. */
06007    while (ast_channel_trylock(clonechan)) {
06008       CHANNEL_DEADLOCK_AVOIDANCE(original);
06009    }
06010 
06011    /* clear the masquerade channels */
06012    original->masq = NULL;
06013    clonechan->masqr = NULL;
06014 
06015    /* unlink from channels container as name (which is the hash value) will change */
06016    ao2_unlink(channels, original);
06017    ao2_unlink(channels, clonechan);
06018 
06019    ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
06020       clonechan->name, clonechan->_state, original->name, original->_state);
06021 
06022    chans[0] = clonechan;
06023    chans[1] = original;
06024    ast_manager_event_multichan(EVENT_FLAG_CALL, "Masquerade", 2, chans, "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n",
06025             clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state));
06026 
06027    /* Having remembered the original read/write formats, we turn off any translation on either
06028       one */
06029    free_translation(clonechan);
06030    free_translation(original);
06031 
06032    /* Save the original name */
06033    ast_copy_string(orig, original->name, sizeof(orig));
06034    /* Save the new name */
06035    ast_copy_string(newn, clonechan->name, sizeof(newn));
06036    /* Create the masq name */
06037    snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
06038 
06039    /* Mangle the name of the clone channel */
06040    __ast_change_name_nolink(clonechan, masqn);
06041 
06042    /* Copy the name from the clone channel */
06043    __ast_change_name_nolink(original, newn);
06044 
06045    /* share linked id's */
06046    ast_channel_set_linkgroup(original, clonechan);
06047 
06048    /* Swap the technologies */
06049    t = original->tech;
06050    original->tech = clonechan->tech;
06051    clonechan->tech = t;
06052 
06053    /* Swap the cdrs */
06054    cdr = original->cdr;
06055    original->cdr = clonechan->cdr;
06056    clonechan->cdr = cdr;
06057 
06058    t_pvt = original->tech_pvt;
06059    original->tech_pvt = clonechan->tech_pvt;
06060    clonechan->tech_pvt = t_pvt;
06061 
06062    /* Swap the alertpipes */
06063    for (i = 0; i < 2; i++) {
06064       x = original->alertpipe[i];
06065       original->alertpipe[i] = clonechan->alertpipe[i];
06066       clonechan->alertpipe[i] = x;
06067    }
06068 
06069    /* 
06070     * Swap the readq's.  The end result should be this:
06071     *
06072     *  1) All frames should be on the new (original) channel.
06073     *  2) Any frames that were already on the new channel before this
06074     *     masquerade need to be at the end of the readq, after all of the
06075     *     frames on the old (clone) channel.
06076     *  3) The alertpipe needs to get poked for every frame that was already
06077     *     on the new channel, since we are now using the alert pipe from the
06078     *     old (clone) channel.
06079     */
06080    {
06081       AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;
06082       AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL);
06083 
06084       AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list);
06085       AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list);
06086 
06087       while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
06088          AST_LIST_INSERT_TAIL(&original->readq, current, frame_list);
06089          if (original->alertpipe[1] > -1) {
06090             int poke = 0;
06091 
06092             if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) {
06093                ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
06094             }
06095          }
06096       }
06097    }
06098 
06099    /* Swap the raw formats */
06100    x = original->rawreadformat;
06101    original->rawreadformat = clonechan->rawreadformat;
06102    clonechan->rawreadformat = x;
06103    x = original->rawwriteformat;
06104    original->rawwriteformat = clonechan->rawwriteformat;
06105    clonechan->rawwriteformat = x;
06106 
06107    clonechan->_softhangup = AST_SOFTHANGUP_DEV;
06108 
06109    /* And of course, so does our current state.  Note we need not
06110       call ast_setstate since the event manager doesn't really consider
06111       these separate.  We do this early so that the clone has the proper
06112       state of the original channel. */
06113    origstate = original->_state;
06114    original->_state = clonechan->_state;
06115    clonechan->_state = origstate;
06116 
06117    if (clonechan->tech->fixup && clonechan->tech->fixup(original, clonechan)) {
06118       ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name);
06119    }
06120 
06121    /* Start by disconnecting the original's physical side */
06122    if (clonechan->tech->hangup && clonechan->tech->hangup(clonechan)) {
06123       ast_log(LOG_WARNING, "Hangup failed!  Strange things may happen!\n");
06124       res = -1;
06125       goto done;
06126    }
06127 
06128    /* Mangle the name of the clone channel */
06129    snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); /* quick, hide the brains! */
06130    __ast_change_name_nolink(clonechan, zombn);
06131 
06132    /* Update the type. */
06133    t_pvt = original->monitor;
06134    original->monitor = clonechan->monitor;
06135    clonechan->monitor = t_pvt;
06136 
06137    /* Keep the same language.  */
06138    ast_string_field_set(original, language, clonechan->language);
06139    /* Copy the FD's other than the generator fd */
06140    for (x = 0; x < AST_MAX_FDS; x++) {
06141       if (x != AST_GENERATOR_FD)
06142          ast_channel_set_fd(original, x, clonechan->fds[x]);
06143    }
06144 
06145    ast_app_group_update(clonechan, original);
06146 
06147    /* Move data stores over */
06148    if (AST_LIST_FIRST(&clonechan->datastores)) {
06149       struct ast_datastore *ds;
06150       /* We use a safe traversal here because some fixup routines actually
06151        * remove the datastore from the list and free them.
06152        */
06153       AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) {
06154          if (ds->info->chan_fixup)
06155             ds->info->chan_fixup(ds->data, clonechan, original);
06156       }
06157       AST_LIST_TRAVERSE_SAFE_END;
06158       AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry);
06159    }
06160 
06161    ast_autochan_new_channel(clonechan, original);
06162 
06163    clone_variables(original, clonechan);
06164    /* Presense of ADSI capable CPE follows clone */
06165    original->adsicpe = clonechan->adsicpe;
06166    /* Bridge remains the same */
06167    /* CDR fields remain the same */
06168    /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
06169    /* Application and data remain the same */
06170    /* Clone exception  becomes real one, as with fdno */
06171    ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_EXCEPTION | AST_FLAG_OUTGOING));
06172    original->fdno = clonechan->fdno;
06173    /* Schedule context remains the same */
06174    /* Stream stuff stays the same */
06175    /* Keep the original state.  The fixup code will need to work with it most likely */
06176 
06177    /*
06178     * Just swap the whole structures, nevermind the allocations,
06179     * they'll work themselves out.
06180     */
06181    exchange.dialed = original->dialed;
06182    original->dialed = clonechan->dialed;
06183    clonechan->dialed = exchange.dialed;
06184 
06185    exchange.caller = original->caller;
06186    original->caller = clonechan->caller;
06187    clonechan->caller = exchange.caller;
06188 
06189    exchange.connected = original->connected;
06190    original->connected = clonechan->connected;
06191    clonechan->connected = exchange.connected;
06192 
06193    exchange.redirecting = original->redirecting;
06194    original->redirecting = clonechan->redirecting;
06195    clonechan->redirecting = exchange.redirecting;
06196 
06197    report_new_callerid(original);
06198 
06199    /* Restore original timing file descriptor */
06200    ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd);
06201 
06202    /* Our native formats are different now */
06203    original->nativeformats = clonechan->nativeformats;
06204 
06205    /* Context, extension, priority, app data, jump table,  remain the same */
06206    /* pvt switches.  pbx stays the same, as does next */
06207 
06208    /* Set the write format */
06209    ast_set_write_format(original, wformat);
06210 
06211    /* Set the read format */
06212    ast_set_read_format(original, rformat);
06213 
06214    /* Copy the music class */
06215    ast_string_field_set(original, musicclass, clonechan->musicclass);
06216 
06217    /* copy over accuntcode and set peeraccount across the bridge */
06218    ast_string_field_set(original, accountcode, S_OR(clonechan->accountcode, ""));
06219    if (original->_bridge) {
06220       /* XXX - should we try to lock original->_bridge here? */
06221       ast_string_field_set(original->_bridge, peeraccount, S_OR(clonechan->accountcode, ""));
06222       ast_cel_report_event(original, AST_CEL_BRIDGE_UPDATE, NULL, NULL, NULL);
06223    }
06224 
06225    ast_debug(1, "Putting channel %s in %s/%s formats\n", original->name,
06226       ast_getformatname(wformat), ast_getformatname(rformat));
06227 
06228    /* Okay.  Last thing is to let the channel driver know about all this mess, so he
06229       can fix up everything as best as possible */
06230    if (original->tech->fixup) {
06231       if (original->tech->fixup(clonechan, original)) {
06232          ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n",
06233             original->tech->type, original->name);
06234          res = -1;
06235          goto done;
06236       }
06237    } else
06238       ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)!  Bad things may happen.\n",
06239          original->tech->type, original->name);
06240 
06241    /* 
06242     * If an indication is currently playing, maintain it on the channel 
06243     * that is taking the place of original 
06244     *
06245     * This is needed because the masquerade is swapping out in the internals
06246     * of this channel, and the new channel private data needs to be made
06247     * aware of the current visible indication (RINGING, CONGESTION, etc.)
06248     */
06249    if (original->visible_indication) {
06250       ast_indicate(original, original->visible_indication);
06251    }
06252 
06253    /* Now, at this point, the "clone" channel is totally F'd up.  We mark it as
06254       a zombie so nothing tries to touch it.  If it's already been marked as a
06255       zombie, then free it now (since it already is considered invalid). */
06256    if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) {
06257       ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name);
06258       ast_channel_unlock(clonechan);
06259       ast_manager_event(clonechan, EVENT_FLAG_CALL, "Hangup",
06260          "Channel: %s\r\n"
06261          "Uniqueid: %s\r\n"
06262          "Cause: %d\r\n"
06263          "Cause-txt: %s\r\n",
06264          clonechan->name,
06265          clonechan->uniqueid,
06266          clonechan->hangupcause,
06267          ast_cause2str(clonechan->hangupcause)
06268          );
06269       clonechan = ast_channel_release(clonechan);
06270    } else {
06271       ast_debug(1, "Released clone lock on '%s'\n", clonechan->name);
06272       ast_set_flag(clonechan, AST_FLAG_ZOMBIE);
06273       ast_queue_frame(clonechan, &ast_null_frame);
06274    }
06275 
06276    /* Signal any blocker */
06277    if (ast_test_flag(original, AST_FLAG_BLOCKING))
06278       pthread_kill(original->blocker, SIGURG);
06279    ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state);
06280 
06281    if ((bridged = ast_bridged_channel(original))) {
06282       ast_channel_lock(bridged);
06283       ast_indicate(bridged, AST_CONTROL_SRCCHANGE);
06284       ast_channel_unlock(bridged);
06285    }
06286 
06287    ast_indicate(original, AST_CONTROL_SRCCHANGE);
06288 
06289 done:
06290    /* it is possible for the clone channel to disappear during this */
06291    if (clonechan) {
06292       ast_channel_unlock(original);
06293       ast_channel_unlock(clonechan);
06294       ao2_link(channels, clonechan);
06295       ao2_link(channels, original);
06296    } else {
06297       ast_channel_unlock(original);
06298       ao2_link(channels, original);
06299    }
06300 
06301    ao2_unlock(channels);
06302 
06303    return 0;
06304 }

struct ast_channel* ast_dummy_channel_alloc ( void   )  [read]

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.

Definition at line 1318 of file channel.c.

References __ao2_alloc_debug(), ao2_alloc, ast_channel_unref, ast_dummy_channel_destructor(), AST_LIST_HEAD_INIT_NOLOCK, ast_string_field_init, and ast_channel::varshead.

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

01320 {
01321    struct ast_channel *tmp;
01322    struct varshead *headp;
01323 
01324 #if defined(REF_DEBUG)
01325    tmp = __ao2_alloc_debug(sizeof(*tmp), ast_dummy_channel_destructor, "dummy channel",
01326       file, line, function, 1);
01327 #elif defined(__AST_DEBUG_MALLOC)
01328    tmp = __ao2_alloc_debug(sizeof(*tmp), ast_dummy_channel_destructor, "dummy channel",
01329       file, line, function, 0);
01330 #else
01331    tmp = ao2_alloc(sizeof(*tmp), ast_dummy_channel_destructor);
01332 #endif
01333    if (!tmp) {
01334       /* Dummy channel structure allocation failure. */
01335       return NULL;
01336    }
01337 
01338    if ((ast_string_field_init(tmp, 128))) {
01339       return ast_channel_unref(tmp);
01340    }
01341 
01342    headp = &tmp->varshead;
01343    AST_LIST_HEAD_INIT_NOLOCK(headp);
01344 
01345    return tmp;
01346 }

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 2227 of file channel.h.

References dummy().

Referenced by do_monitor().

02228 {
02229    int x;
02230    int dummy = 0;
02231 
02232    if (fd < 0)
02233       return 0;
02234    if (!start)
02235       start = &dummy;
02236    for (x = *start; x < maximum; x++)
02237       if (pfds[x].fd == fd) {
02238          if (x == *start)
02239             (*start)++;
02240          return pfds[x].revents;
02241       }
02242    return 0;
02243 }

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

00891 {
00892    struct chanlist *chanls;
00893    const struct ast_channel_tech *ret = NULL;
00894 
00895    AST_RWLIST_RDLOCK(&backends);
00896 
00897    AST_RWLIST_TRAVERSE(&backends, chanls, list) {
00898       if (!strcasecmp(name, chanls->tech->type)) {
00899          ret = chanls->tech;
00900          break;
00901       }
00902    }
00903 
00904    AST_RWLIST_UNLOCK(&backends);
00905    
00906    return ret;
00907 }

ast_group_t ast_get_group ( const char *  s  ) 

Definition at line 7197 of file channel.c.

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

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

07198 {
07199    char *piece;
07200    char *c;
07201    int start=0, finish=0, x;
07202    ast_group_t group = 0;
07203 
07204    if (ast_strlen_zero(s))
07205       return 0;
07206 
07207    c = ast_strdupa(s);
07208    
07209    while ((piece = strsep(&c, ","))) {
07210       if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) {
07211          /* Range */
07212       } else if (sscanf(piece, "%30d", &start)) {
07213          /* Just one */
07214          finish = start;
07215       } else {
07216          ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
07217          continue;
07218       }
07219       for (x = start; x <= finish; x++) {
07220          if ((x > 63) || (x < 0)) {
07221             ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
07222          } else
07223             group |= ((ast_group_t) 1 << x);
07224       }
07225    }
07226    return group;
07227 }

int ast_hangup ( struct ast_channel *  chan  ) 

Hang up a channel.

Note:
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 2629 of file channel.c.

References ao2_unlink, ast_assert, ast_audiohook_detach_list(), 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_release(), ast_channel_unlock, ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_framehook_list_destroy(), ast_log(), ast_manager_event, ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::caller, ast_channel::cdr, channels, ast_cdr::disposition, EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, ast_channel::hangupsource, ast_party_caller::id, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_party_id::name, ast_channel::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_channel::uniqueid, 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_channel_thread(), bridge_exec(), build_conf(), builtin_atxfer(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), connect_link(), console_new(), dahdi_handle_event(), dahdi_new(), destroy_conference_bridge(), dial_exec_full(), dial_transfer(), do_forward(), do_hang(), do_idle_thread(), 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_parkinglot(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), my_distinctive_ring(), my_handle_notify_message(), nbs_new(), oss_new(), park_exec_full(), parkandannounce_exec(), phone_new(), play_sound_file(), pri_dchannel(), pri_ss_thread(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss7_start_call(), try_calling(), unistim_new(), usbradio_new(), wait_for_answer(), and wait_for_winner().

02630 {
02631    int res = 0;
02632    char extra_str[64]; /* used for cel logging below */
02633 
02634    /* Don't actually hang up a channel that will masquerade as someone else, or
02635       if someone is going to masquerade as us */
02636    ast_channel_lock(chan);
02637 
02638    if (chan->audiohooks) {
02639       ast_audiohook_detach_list(chan->audiohooks);
02640       chan->audiohooks = NULL;
02641    }
02642 
02643    ast_framehook_list_destroy(chan);
02644 
02645    ast_autoservice_stop(chan);
02646 
02647    if (chan->masq) {
02648       ast_channel_unlock(chan);
02649       if (ast_do_masquerade(chan)) {
02650          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
02651       }
02652       ast_channel_lock(chan);
02653    }
02654 
02655    if (chan->masq) {
02656       ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name);
02657       ast_channel_unlock(chan);
02658       return 0;
02659    }
02660    /* If this channel is one which will be masqueraded into something,
02661       mark it as a zombie already, so we know to free it later */
02662    if (chan->masqr) {
02663       ast_set_flag(chan, AST_FLAG_ZOMBIE);
02664       ast_channel_unlock(chan);
02665       return 0;
02666    }
02667    ast_channel_unlock(chan);
02668 
02669    ao2_unlink(channels, chan);
02670 
02671    ast_channel_lock(chan);
02672    free_translation(chan);
02673    /* Close audio stream */
02674    if (chan->stream) {
02675       ast_closestream(chan->stream);
02676       chan->stream = NULL;
02677    }
02678    /* Close video stream */
02679    if (chan->vstream) {
02680       ast_closestream(chan->vstream);
02681       chan->vstream = NULL;
02682    }
02683    if (chan->sched) {
02684       sched_context_destroy(chan->sched);
02685       chan->sched = NULL;
02686    }
02687 
02688    if (chan->generatordata)   /* Clear any tone stuff remaining */
02689       if (chan->generator && chan->generator->release)
02690          chan->generator->release(chan, chan->generatordata);
02691    chan->generatordata = NULL;
02692    chan->generator = NULL;
02693 
02694    snprintf(extra_str, sizeof(extra_str), "%d,%s,%s", chan->hangupcause, chan->hangupsource, S_OR(pbx_builtin_getvar_helper(chan, "DIALSTATUS"), ""));
02695    ast_cel_report_event(chan, AST_CEL_HANGUP, NULL, extra_str, NULL);
02696 
02697    if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
02698       ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
02699                "is blocked by thread %ld in procedure %s!  Expect a failure\n",
02700                (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
02701       ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0);
02702    }
02703    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
02704       ast_debug(1, "Hanging up channel '%s'\n", chan->name);
02705       if (chan->tech->hangup)
02706          res = chan->tech->hangup(chan);
02707    } else {
02708       ast_debug(1, "Hanging up zombie '%s'\n", chan->name);
02709    }
02710          
02711    ast_channel_unlock(chan);
02712    ast_cc_offer(chan);
02713    ast_manager_event(chan, EVENT_FLAG_CALL, "Hangup",
02714       "Channel: %s\r\n"
02715       "Uniqueid: %s\r\n"
02716       "CallerIDNum: %s\r\n"
02717       "CallerIDName: %s\r\n"
02718       "Cause: %d\r\n"
02719       "Cause-txt: %s\r\n",
02720       chan->name,
02721       chan->uniqueid,
02722       S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, "<unknown>"),
02723       S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, "<unknown>"),
02724       chan->hangupcause,
02725       ast_cause2str(chan->hangupcause)
02726       );
02727 
02728    if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 
02729       !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 
02730        (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) {
02731       ast_channel_lock(chan);
02732          
02733       ast_cdr_end(chan->cdr);
02734       ast_cdr_detach(chan->cdr);
02735       chan->cdr = NULL;
02736       ast_channel_unlock(chan);
02737    }
02738 
02739    chan = ast_channel_release(chan);
02740 
02741    return res;
02742 }

int ast_indicate ( struct ast_channel *  chan,
int  condition 
)

int ast_indicate_data ( struct ast_channel *  chan,
int  condition,
const void *  data,
size_t  datalen 
)

Indicates condition of channel, with payload.

Note:
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 4164 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_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, 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_VIDUPDATE, AST_CONTROL_WINK, ast_debug, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, ast_framehook_list_is_empty(), ast_framehook_list_read_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_channel::name, 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_parkinglot(), 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().

04166 {
04167    /* By using an enum, we'll get compiler warnings for values not handled 
04168     * in switch statements. */
04169    enum ast_control_frame_type condition = _condition;
04170    struct ast_tone_zone_sound *ts = NULL;
04171    int res;
04172    /* this frame is used by framehooks. if it is set, we must free it at the end of this function */
04173    struct ast_frame *awesome_frame = NULL;
04174 
04175    ast_channel_lock(chan);
04176 
04177    /* Don't bother if the channel is about to go away, anyway. */
04178    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
04179       ast_channel_unlock(chan);
04180       res = -1;
04181       goto indicate_cleanup;
04182    }
04183 
04184    if (!ast_framehook_list_is_empty(chan->framehooks)) {
04185       /* Do framehooks now, do it, go, go now */
04186       struct ast_frame frame = {
04187          .frametype = AST_FRAME_CONTROL,
04188          .subclass.integer = condition,
04189          .data.ptr = (void *) data, /* this cast from const is only okay because we do the ast_frdup below */
04190          .datalen = datalen
04191       };
04192 
04193       /* we have now committed to freeing this frame */
04194       awesome_frame = ast_frdup(&frame);
04195 
04196       /* who knows what we will get back! the anticipation is killing me. */
04197       if (!(awesome_frame = ast_framehook_list_read_event(chan->framehooks, &frame))) {
04198          ast_channel_unlock(chan);
04199          res = 0;
04200          goto indicate_cleanup;
04201       }
04202 
04203       condition = awesome_frame->subclass.integer;
04204       data = awesome_frame->data.ptr;
04205       datalen = awesome_frame->datalen;
04206    }
04207 
04208    switch (condition) {
04209    case AST_CONTROL_CONNECTED_LINE:
04210       {
04211          struct ast_party_connected_line connected;
04212 
04213          ast_party_connected_line_set_init(&connected, &chan->connected);
04214          res = ast_connected_line_parse_data(data, datalen, &connected);
04215          if (!res) {
04216             ast_channel_set_connected_line(chan, &connected, NULL);
04217          }
04218          ast_party_connected_line_free(&connected);
04219       }
04220       break;
04221 
04222    case AST_CONTROL_REDIRECTING:
04223       {
04224          struct ast_party_redirecting redirecting;
04225 
04226          ast_party_redirecting_set_init(&redirecting, &chan->redirecting);
04227          res = ast_redirecting_parse_data(data, datalen, &redirecting);
04228          if (!res) {
04229             ast_channel_set_redirecting(chan, &redirecting, NULL);
04230          }
04231          ast_party_redirecting_free(&redirecting);
04232       }
04233       break;
04234    
04235    default:
04236       break;
04237    }
04238 
04239    if (chan->tech->indicate) {
04240       /* See if the channel driver can handle this condition. */
04241       res = chan->tech->indicate(chan, condition, data, datalen);
04242    } else {
04243       res = -1;
04244    }
04245 
04246    ast_channel_unlock(chan);
04247 
04248    if (!res) {
04249       /* The channel driver successfully handled this indication */
04250       if (is_visible_indication(condition)) {
04251          chan->visible_indication = condition;
04252       }
04253       res = 0;
04254       goto indicate_cleanup;
04255    }
04256 
04257    /* The channel driver does not support this indication, let's fake
04258     * it by doing our own tone generation if applicable. */
04259 
04260    /*!\note If we compare the enumeration type, which does not have any
04261     * negative constants, the compiler may optimize this code away.
04262     * Therefore, we must perform an integer comparison here. */
04263    if (_condition < 0) {
04264       /* Stop any tones that are playing */
04265       ast_playtones_stop(chan);
04266       res = 0;
04267       goto indicate_cleanup;
04268    }
04269 
04270    /* Handle conditions that we have tones for. */
04271    switch (condition) {
04272    case _XXX_AST_CONTROL_T38:
04273       /* deprecated T.38 control frame */
04274       res = -1;
04275       goto indicate_cleanup;
04276    case AST_CONTROL_T38_PARAMETERS:
04277       /* there is no way to provide 'default' behavior for these
04278        * control frames, so we need to return failure, but there
04279        * is also no value in the log message below being emitted
04280        * since failure to handle these frames is not an 'error'
04281        * so just return right now. in addition, we want to return
04282        * whatever value the channel driver returned, in case it
04283        * has some meaning.*/
04284       goto indicate_cleanup;
04285    case AST_CONTROL_RINGING:
04286       ts = ast_get_indication_tone(chan->zone, "ring");
04287       /* It is common practice for channel drivers to return -1 if trying
04288        * to indicate ringing on a channel which is up. The idea is to let the
04289        * core generate the ringing inband. However, we don't want the
04290        * warning message about not being able to handle the specific indication
04291        * to print nor do we want ast_indicate_data to return an "error" for this
04292        * condition
04293        */
04294       if (chan->_state == AST_STATE_UP) {
04295          res = 0;
04296       }
04297       break;
04298    case AST_CONTROL_BUSY:
04299       ts = ast_get_indication_tone(chan->zone, "busy");
04300       break;
04301    case AST_CONTROL_CONGESTION:
04302       ts = ast_get_indication_tone(chan->zone, "congestion");
04303       break;
04304    case AST_CONTROL_PROGRESS:
04305    case AST_CONTROL_PROCEEDING:
04306    case AST_CONTROL_VIDUPDATE:
04307    case AST_CONTROL_SRCUPDATE:
04308    case AST_CONTROL_SRCCHANGE:
04309    case AST_CONTROL_RADIO_KEY:
04310    case AST_CONTROL_RADIO_UNKEY:
04311    case AST_CONTROL_OPTION:
04312    case AST_CONTROL_WINK:
04313    case AST_CONTROL_FLASH:
04314    case AST_CONTROL_OFFHOOK:
04315    case AST_CONTROL_TAKEOFFHOOK:
04316    case AST_CONTROL_ANSWER:
04317    case AST_CONTROL_HANGUP:
04318    case AST_CONTROL_RING:
04319    case AST_CONTROL_HOLD:
04320    case AST_CONTROL_UNHOLD:
04321    case AST_CONTROL_TRANSFER:
04322    case AST_CONTROL_CONNECTED_LINE:
04323    case AST_CONTROL_REDIRECTING:
04324    case AST_CONTROL_CC:
04325    case AST_CONTROL_READ_ACTION:
04326    case AST_CONTROL_AOC:
04327       /* Nothing left to do for these. */
04328       res = 0;
04329       break;
04330    }
04331 
04332    if (ts) {
04333       /* We have a tone to play, yay. */
04334       ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
04335       ast_playtones_start(chan, 0, ts->data, 1);
04336       ts = ast_tone_zone_sound_unref(ts);
04337       res = 0;
04338       chan->visible_indication = condition;
04339    }
04340 
04341    if (res) {
04342       /* not handled */
04343       ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name);
04344    }
04345 
04346 indicate_cleanup:
04347    if (awesome_frame) {
04348       ast_frfree(awesome_frame);
04349    }
04350 
04351    return res;
04352 }

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

References ast_opt_internal_timing, and ast_channel::timingfd.

Referenced by add_sdp(), and ast_read_generator_actions().

04103 {
04104    return (ast_opt_internal_timing && chan->timingfd > -1);
04105 }

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 1699 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(), and autoservice_run().

01700 {
01701    /* Do not add a default entry in this switch statement.  Each new
01702     * frame type should be addressed directly as to whether it should
01703     * be queued up or not.
01704     */
01705    switch (frame->frametype) {
01706    case AST_FRAME_DTMF_END:
01707    case AST_FRAME_CONTROL:
01708    case AST_FRAME_TEXT:
01709    case AST_FRAME_IMAGE:
01710    case AST_FRAME_HTML:
01711       return 1;
01712 
01713    case AST_FRAME_DTMF_BEGIN:
01714    case AST_FRAME_VOICE:
01715    case AST_FRAME_VIDEO:
01716    case AST_FRAME_NULL:
01717    case AST_FRAME_IAX:
01718    case AST_FRAME_CNG:
01719    case AST_FRAME_MODEM:
01720       return 0;
01721    }
01722    return 0;
01723 }

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

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

Referenced by ast_call_forward(), do_forward(), and wait_for_answer().

02151 {
02152    if (dest == src) {
02153       /* Don't copy to self */
02154       return;
02155    }
02156 
02157    ast_party_id_copy(&dest->id, &src->id);
02158    ast_party_id_copy(&dest->ani, &src->ani);
02159    dest->ani2 = src->ani2;
02160 }

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

02177 {
02178    ast_party_id_free(&doomed->id);
02179    ast_party_id_free(&doomed->ani);
02180 }

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 2143 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(), sig_pri_set_caller_id(), sig_ss7_set_caller_id(), and sla_ring_station().

02144 {
02145    ast_party_id_init(&init->id);
02146    ast_party_id_init(&init->ani);
02147    init->ani2 = 0;
02148 }

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

02170 {
02171    ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
02172    ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
02173    dest->ani2 = src->ani2;
02174 }

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 2162 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(), misdn_update_caller_id(), and ring_entry().

02163 {
02164    ast_party_id_set_init(&init->id, &guide->id);
02165    ast_party_id_set_init(&init->ani, &guide->ani);
02166    init->ani2 = guide->ani2;
02167 }

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

Referenced by ast_pickup_call().

02220 {
02221    connected->id = caller->id;
02222    connected->ani = caller->ani;
02223    connected->ani2 = caller->ani2;
02224    connected->source = AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN;
02225 }

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 2190 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(), builtin_atxfer(), dial_exec_full(), do_forward(), local_attended_transfer(), pickup_do(), try_calling(), and wait_for_answer().

02191 {
02192    if (dest == src) {
02193       /* Don't copy to self */
02194       return;
02195    }
02196 
02197    ast_party_id_copy(&dest->id, &src->id);
02198    ast_party_id_copy(&dest->ani, &src->ani);
02199    dest->ani2 = src->ani2;
02200    dest->source = src->source;
02201 }

void ast_party_connected_line_free ( struct ast_party_connected_line *  doomed  ) 

Destroy the connected line information contents.

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

Definition at line 2227 of file channel.c.

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

Referenced by __ast_read(), ast_channel_destructor(), ast_dummy_channel_destructor(), ast_indicate_data(), builtin_atxfer(), callattempt_free(), chanlist_free(), connectedline_write(), local_attended_transfer(), pickup_do(), sig_pri_handle_subcmds(), socket_process(), and wait_for_answer().

02228 {
02229    ast_party_id_free(&doomed->id);
02230    ast_party_id_free(&doomed->ani);
02231 }

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 2211 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(), and wait_for_answer().

02212 {
02213    ast_party_id_set(&dest->id, &src->id, update ? &update->id : NULL);
02214    ast_party_id_set(&dest->ani, &src->ani, update ? &update->ani : NULL);
02215    dest->ani2 = src->ani2;
02216    dest->source = src->source;
02217 }

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 2203 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(), and wait_for_answer().

02204 {
02205    ast_party_id_set_init(&init->id, &guide->id);
02206    ast_party_id_set_init(&init->ani, &guide->ani);
02207    init->ani2 = guide->ani2;
02208    init->source = guide->source;
02209 }

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

References ast_free, ast_party_subaddress_copy(), ast_strdup, ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by local_call().

02102 {
02103    if (dest == src) {
02104       /* Don't copy to self */
02105       return;
02106    }
02107 
02108    ast_free(dest->number.str);
02109    dest->number.str = ast_strdup(src->number.str);
02110    dest->number.plan = src->number.plan;
02111    ast_party_subaddress_copy(&dest->subaddress, &src->subaddress);
02112    dest->transit_network_select = src->transit_network_select;
02113 }

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

References ast_free, ast_party_subaddress_free(), ast_party_dialed::number, ast_party_dialed::str, and ast_party_dialed::subaddress.

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

02137 {
02138    ast_free(doomed->number.str);
02139    doomed->number.str = NULL;
02140    ast_party_subaddress_free(&doomed->subaddress);
02141 }

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

References ast_party_subaddress_init(), ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by __ast_channel_alloc_ap().

02094 {
02095    init->number.str = NULL;
02096    init->number.plan = 0;/* Unknown */
02097    ast_party_subaddress_init(&init->subaddress);
02098    init->transit_network_select = 0;
02099 }

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

References ast_free, ast_party_subaddress_set(), ast_strdup, ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by callerid_write().

02124 {
02125    if (src->number.str && src->number.str != dest->number.str) {
02126       ast_free(dest->number.str);
02127       dest->number.str = ast_strdup(src->number.str);
02128    }
02129    dest->number.plan = src->number.plan;
02130 
02131    ast_party_subaddress_set(&dest->subaddress, &src->subaddress);
02132 
02133    dest->transit_network_select = src->transit_network_select;
02134 }

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

References ast_party_subaddress_set_init(), ast_party_dialed::number, ast_party_dialed::plan, ast_party_dialed::str, ast_party_dialed::subaddress, and ast_party_dialed::transit_network_select.

Referenced by callerid_write().

02116 {
02117    init->number.str = NULL;
02118    init->number.plan = guide->number.plan;
02119    ast_party_subaddress_set_init(&init->subaddress, &guide->subaddress);
02120    init->transit_network_select = guide->transit_network_select;
02121 }

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 1972 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(), and ast_party_redirecting_copy().

01973 {
01974    if (dest == src) {
01975       /* Don't copy to self */
01976       return;
01977    }
01978 
01979    ast_party_name_copy(&dest->name, &src->name);
01980    ast_party_number_copy(&dest->number, &src->number);
01981    ast_party_subaddress_copy(&dest->subaddress, &src->subaddress);
01982 
01983    ast_free(dest->tag);
01984    dest->tag = ast_strdup(src->tag);
01985 }

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

02019 {
02020    ast_party_name_free(&doomed->name);
02021    ast_party_number_free(&doomed->number);
02022    ast_party_subaddress_free(&doomed->subaddress);
02023 
02024    ast_free(doomed->tag);
02025    doomed->tag = NULL;
02026 }

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 1964 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(), and do_forward().

01965 {
01966    ast_party_name_init(&init->name);
01967    ast_party_number_init(&init->number);
01968    ast_party_subaddress_init(&init->subaddress);
01969    init->tag = NULL;
01970 }

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

References AST_PRES_ALLOWED, 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(), my_set_callerid(), oh323_call(), party_id_build_data(), party_id_read(), redirecting_read(), report_new_callerid(), setup_env(), sig_pri_handle_subcmds(), sip_call(), and socket_process().

02029 {
02030    int number_priority;
02031    int number_value;
02032    int number_screening;
02033    int name_priority;
02034    int name_value;
02035 
02036    /* Determine name presentation priority. */
02037    if (!id->name.valid) {
02038       name_value = AST_PRES_UNAVAILABLE;
02039       name_priority = 3;
02040    } else {
02041       name_value = id->name.presentation & AST_PRES_RESTRICTION;
02042       switch (name_value) {
02043       case AST_PRES_RESTRICTED:
02044          name_priority = 0;
02045          break;
02046       case AST_PRES_ALLOWED:
02047          name_priority = 1;
02048          break;
02049       case AST_PRES_UNAVAILABLE:
02050          name_priority = 2;
02051          break;
02052       default:
02053          name_value = AST_PRES_UNAVAILABLE;
02054          name_priority = 3;
02055          break;
02056       }
02057    }
02058 
02059    /* Determine number presentation priority. */
02060    if (!id->number.valid) {
02061       number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
02062       number_value = AST_PRES_UNAVAILABLE;
02063       number_priority = 3;
02064    } else {
02065       number_screening = id->number.presentation & AST_PRES_NUMBER_TYPE;
02066       number_value = id->number.presentation & AST_PRES_RESTRICTION;
02067       switch (number_value) {
02068       case AST_PRES_RESTRICTED:
02069          number_priority = 0;
02070          break;
02071       case AST_PRES_ALLOWED:
02072          number_priority = 1;
02073          break;
02074       case AST_PRES_UNAVAILABLE:
02075          number_priority = 2;
02076          break;
02077       default:
02078          number_screening = AST_PRES_USER_NUMBER_UNSCREENED;
02079          number_value = AST_PRES_UNAVAILABLE;
02080          number_priority = 3;
02081          break;
02082       }
02083    }
02084 
02085    /* Select the wining presentation value. */
02086    if (name_priority < number_priority) {
02087       number_value = name_value;
02088    }
02089 
02090    return number_value | number_screening;
02091 }

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

01996 {
01997    if (dest == src) {
01998       /* Don't set to self */
01999       return;
02000    }
02001 
02002    if (!update || update->name) {
02003       ast_party_name_set(&dest->name, &src->name);
02004    }
02005    if (!update || update->number) {
02006       ast_party_number_set(&dest->number, &src->number);
02007    }
02008    if (!update || update->subaddress) {
02009       ast_party_subaddress_set(&dest->subaddress, &src->subaddress);
02010    }
02011 
02012    if (src->tag && src->tag != dest->tag) {
02013       ast_free(dest->tag);
02014       dest->tag = ast_strdup(src->tag);
02015    }
02016 }

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 1987 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(), and ast_party_redirecting_set_init().

01988 {
01989    ast_party_name_set_init(&init->name, &guide->name);
01990    ast_party_number_set_init(&init->number, &guide->number);
01991    ast_party_subaddress_set_init(&init->subaddress, &guide->subaddress);
01992    init->tag = NULL;
01993 }

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

01814 {
01815    if (dest == src) {
01816       /* Don't copy to self */
01817       return;
01818    }
01819 
01820    ast_free(dest->str);
01821    dest->str = ast_strdup(src->str);
01822    dest->char_set = src->char_set;
01823    dest->presentation = src->presentation;
01824    dest->valid = src->valid;
01825 }

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

01853 {
01854    ast_free(doomed->str);
01855    doomed->str = NULL;
01856 }

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

01806 {
01807    init->str = NULL;
01808    init->char_set = AST_PARTY_CHAR_SET_ISO8859_1;
01809    init->presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
01810    init->valid = 0;
01811 }

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

01836 {
01837    if (dest == src) {
01838       /* Don't set to self */
01839       return;
01840    }
01841 
01842    if (src->str && src->str != dest->str) {
01843       ast_free(dest->str);
01844       dest->str = ast_strdup(src->str);
01845    }
01846 
01847    dest->char_set = src->char_set;
01848    dest->presentation = src->presentation;
01849    dest->valid = src->valid;
01850 }

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

01828 {
01829    init->str = NULL;
01830    init->char_set = guide->char_set;
01831    init->presentation = guide->presentation;
01832    init->valid = guide->valid;
01833 }

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

01867 {
01868    if (dest == src) {
01869       /* Don't copy to self */
01870       return;
01871    }
01872 
01873    ast_free(dest->str);
01874    dest->str = ast_strdup(src->str);
01875    dest->plan = src->plan;
01876    dest->presentation = src->presentation;
01877    dest->valid = src->valid;
01878 }

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

01906 {
01907    ast_free(doomed->str);
01908    doomed->str = NULL;
01909 }

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

01859 {
01860    init->str = NULL;
01861    init->plan = 0;/* Unknown */
01862    init->presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
01863    init->valid = 0;
01864 }

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

01889 {
01890    if (dest == src) {
01891       /* Don't set to self */
01892       return;
01893    }
01894 
01895    if (src->str && src->str != dest->str) {
01896       ast_free(dest->str);
01897       dest->str = ast_strdup(src->str);
01898    }
01899 
01900    dest->plan = src->plan;
01901    dest->presentation = src->presentation;
01902    dest->valid = src->valid;
01903 }

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

01881 {
01882    init->str = NULL;
01883    init->plan = guide->plan;
01884    init->presentation = guide->presentation;
01885    init->valid = guide->valid;
01886 }

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 2241 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_channel_redirecting_macro(), begin_dial_channel(), dial_exec_full(), do_forward(), local_call(), ring_entry(), and wait_for_answer().

02242 {
02243    if (dest == src) {
02244       /* Don't copy to self */
02245       return;
02246    }
02247 
02248    ast_party_id_copy(&dest->from, &src->from);
02249    ast_party_id_copy(&dest->to, &src->to);
02250    dest->count = src->count;
02251    dest->reason = src->reason;
02252 }

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

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

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

02271 {
02272    ast_party_id_free(&doomed->from);
02273    ast_party_id_free(&doomed->to);
02274 }

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 2233 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(), do_forward(), handle_request_invite(), handle_response(), handle_response_invite(), and wait_for_answer().

02234 {
02235    ast_party_id_init(&init->from);
02236    ast_party_id_init(&init->to);
02237    init->count = 0;
02238    init->reason = AST_REDIRECTING_REASON_UNKNOWN;
02239 }

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

02263 {
02264    ast_party_id_set(&dest->from, &src->from, update ? &update->from : NULL);
02265    ast_party_id_set(&dest->to, &src->to, update ? &update->to : NULL);
02266    dest->reason = src->reason;
02267    dest->count = src->count;
02268 }

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 2254 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(), redirecting_write(), and sig_pri_redirecting_convert().

02255 {
02256    ast_party_id_set_init(&init->from, &guide->from);
02257    ast_party_id_set_init(&init->to, &guide->to);
02258    init->count = guide->count;
02259    init->reason = guide->reason;
02260 }

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

01920 {
01921    if (dest == src) {
01922       /* Don't copy to self */
01923       return;
01924    }
01925 
01926    ast_free(dest->str);
01927    dest->str = ast_strdup(src->str);
01928    dest->type = src->type;
01929    dest->odd_even_indicator = src->odd_even_indicator;
01930    dest->valid = src->valid;
01931 }

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

References ast_free, and ast_party_subaddress::str.

Referenced by ast_party_dialed_free(), ast_party_id_free(), and pri_dchannel().

01959 {
01960    ast_free(doomed->str);
01961    doomed->str = NULL;
01962 }

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

References ast_party_subaddress::odd_even_indicator, ast_party_subaddress::str, ast_party_subaddress::type, and ast_party_subaddress::valid.

Referenced by ast_party_dialed_init(), ast_party_id_init(), pri_dchannel(), sig_pri_call(), and sig_pri_set_subaddress().

01912 {
01913    init->str = NULL;
01914    init->type = 0;
01915    init->odd_even_indicator = 0;
01916    init->valid = 0;
01917 }

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 1941 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(), ast_party_id_set(), and sig_pri_handle_subcmds().

01942 {
01943    if (dest == src) {
01944       /* Don't set to self */
01945       return;
01946    }
01947 
01948    if (src->str && src->str != dest->str) {
01949       ast_free(dest->str);
01950       dest->str = ast_strdup(src->str);
01951    }
01952 
01953    dest->type = src->type;
01954    dest->odd_even_indicator = src->odd_even_indicator;
01955    dest->valid = src->valid;
01956 }

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

01934 {
01935    init->str = NULL;
01936    init->type = guide->type;
01937    init->odd_even_indicator = guide->odd_even_indicator;
01938    init->valid = guide->valid;
01939 }

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

Add a channel to an optimized waitfor

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

02532 {
02533 #ifdef HAVE_EPOLL
02534    struct epoll_event ev;
02535    int i = 0;
02536 
02537    if (chan0->epfd == -1)
02538       return;
02539 
02540    /* Iterate through the file descriptors on chan1, adding them to chan0 */
02541    for (i = 0; i < AST_MAX_FDS; i++) {
02542       if (chan1->fds[i] == -1)
02543          continue;
02544       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
02545       ev.data.ptr = chan1->epfd_data[i];
02546       epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev);
02547    }
02548 
02549 #endif
02550    return;
02551 }

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

Delete a channel from an optimized waitfor

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

02555 {
02556 #ifdef HAVE_EPOLL
02557    struct epoll_event ev;
02558    int i = 0;
02559 
02560    if (chan0->epfd == -1)
02561       return;
02562 
02563    for (i = 0; i < AST_MAX_FDS; i++) {
02564       if (chan1->fds[i] == -1)
02565          continue;
02566       epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev);
02567    }
02568 
02569 #endif
02570    return;
02571 }

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

print call- and pickup groups into buffer

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

07435 {
07436    unsigned int i;
07437    int first = 1;
07438    char num[3];
07439 
07440    buf[0] = '\0';
07441    
07442    if (!group) /* Return empty string if no group */
07443       return buf;
07444 
07445    for (i = 0; i <= 63; i++) {   /* Max group is 63 */
07446       if (group & ((ast_group_t) 1 << i)) {
07447             if (!first) {
07448             strncat(buf, ", ", buflen - strlen(buf) - 1);
07449          } else {
07450             first = 0;
07451          }
07452          snprintf(num, sizeof(num), "%u", i);
07453          strncat(buf, num, buflen - strlen(buf) - 1);
07454       }
07455    }
07456    return buf;
07457 }

int ast_prod ( struct ast_channel *  chan  ) 

Send empty audio to prime a channel driver.

Definition at line 4473 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_channel::name, ast_frame::ptr, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.

Referenced by ast_activate_generator().

04474 {
04475    struct ast_frame a = { AST_FRAME_VOICE };
04476    char nothing[128];
04477 
04478    /* Send an empty audio frame to get things moving */
04479    if (chan->_state != AST_STATE_UP) {
04480       ast_debug(1, "Prodding channel '%s'\n", chan->name);
04481       a.subclass.codec = chan->rawwriteformat;
04482       a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
04483       a.src = "ast_prod"; /* this better match check in ast_write */
04484       if (ast_write(chan, &a))
04485          ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name);
04486    }
04487    return 0;
04488 }

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 1482 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_attempt_transfer(), analog_call(), analog_exception(), analog_hangup(), analog_ss_thread(), ast_pickup_call(), 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_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(), misdn_attempt_transfer(), misdn_facility_ie_handler(), multicast_rtp_call(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), remote_hold(), send_cause2ast(), setup_rtp_connection(), sig_pri_attempt_transfer(), sig_pri_handle_subcmds(), skinny_call(), skinny_transfer(), skinny_unhold(), unistim_call(), and update_state().

01483 {
01484    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control };
01485    return ast_queue_frame(chan, &f);
01486 }

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 1489 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(), process_sdp(), sip_sipredirect(), and skinny_hold().

01491 {
01492    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = control, .data.ptr = (void *) data, .datalen = datalen };
01493    return ast_queue_frame(chan, &f);
01494 }

int ast_queue_frame ( struct ast_channel *  chan,
struct ast_frame *  f 
)

Queue one or more frames to 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 1439 of file channel.c.

References __ast_queue_frame().

Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), action_atxfer(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup_tv(), ast_do_masquerade(), ast_dsp_process(), ast_queue_cc_frame(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), bridge_write(), cb_events(), cli_console_dial(), cli_console_sendtext(), console_dial(), console_do_answer(), console_flash(), console_sendtext(), dahdi_queue_frame(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), jingle_handle_dtmf(), keypad_digit(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), pri_queue_frame(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), sig_pri_handle_hold(), sig_ss7_queue_frame(), stream_monitor(), unistim_do_senddigit(), unistim_senddigit_end(), usbradio_read(), and wakeup_sub().

01440 {
01441    return __ast_queue_frame(chan, fin, 0, NULL);
01442 }

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

References __ast_queue_frame().

Referenced by __ast_answer(), __ast_read(), ast_autoservice_stop(), and ast_safe_sleep_conditional().

01445 {
01446    return __ast_queue_frame(chan, fin, 1, NULL);
01447 }

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 1450 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_request_cancel(), handle_soft_key_event_message(), iax2_destroy(), iax2_queue_hangup(), jingle_hangup_farend(), local_fixup(), local_hangup(), and mgcp_queue_hangup().

01451 {
01452    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
01453    /* Yeah, let's not change a lock-critical value without locking */
01454    if (!ast_channel_trylock(chan)) {
01455       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01456       ast_channel_unlock(chan);
01457    }
01458    return ast_queue_frame(chan, &f);
01459 }

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 1462 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(), dahdi_r2_on_call_disconnect(), handle_request_bye(), handle_response(), handle_response_invite(), handle_response_notify(), HandleCallOutgoing(), hangup_chan(), hangup_connection(), misdn_answer(), retrans_pkt(), and TransferCallStep1().

01463 {
01464    struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
01465 
01466    if (cause >= 0)
01467       f.data.uint32 = cause;
01468 
01469    /* Yeah, let's not change a lock-critical value without locking */
01470    if (!ast_channel_trylock(chan)) {
01471       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01472       if (cause < 0)
01473          f.data.uint32 = chan->hangupcause;
01474 
01475       ast_channel_unlock(chan);
01476    }
01477 
01478    return ast_queue_frame(chan, &f);
01479 }

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 2744 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, ast_channel::tech, and ast_channel::visible_indication.

Referenced by __ast_answer(), and ast_bridge_call().

02745 {
02746    int res = 0;
02747 
02748    ast_channel_lock(chan);
02749 
02750    /* You can't answer an outbound call */
02751    if (ast_test_flag(chan, AST_FLAG_OUTGOING)) {
02752       ast_channel_unlock(chan);
02753       return 0;
02754    }
02755 
02756    /* Stop if we're a zombie or need a soft hangup */
02757    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
02758       ast_channel_unlock(chan);
02759       return -1;
02760    }
02761 
02762    ast_channel_unlock(chan);
02763 
02764    switch (chan->_state) {
02765    case AST_STATE_RINGING:
02766    case AST_STATE_RING:
02767       ast_channel_lock(chan);
02768       if (chan->tech->answer) {
02769          res = chan->tech->answer(chan);
02770       }
02771       ast_setstate(chan, AST_STATE_UP);
02772       if (cdr_answer) {
02773          ast_cdr_answer(chan->cdr);
02774       }
02775       ast_cel_report_event(chan, AST_CEL_ANSWER, NULL, NULL, NULL);
02776       ast_channel_unlock(chan);
02777       break;
02778    case AST_STATE_UP:
02779       ast_cel_report_event(chan, AST_CEL_ANSWER, NULL, NULL, NULL);
02780       /* Calling ast_cdr_answer when it it has previously been called
02781        * is essentially a no-op, so it is safe.
02782        */
02783       if (cdr_answer) {
02784          ast_cdr_answer(chan->cdr);
02785       }
02786       break;
02787    default:
02788       break;
02789    }
02790 
02791    ast_indicate(chan, -1);
02792    chan->visible_indication = 0;
02793 
02794    return res;
02795 }

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 4107 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_wait(), autoservice_run(), background_detect_exec(), builtin_atxfer(), channel_spy(), check_goto_on_transfer(), conf_flush(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_bridge(), dial_exec_full(), dictate_exec(), disa_exec(), disable_t38(), do_idle_thread(), do_waiting(), echo_exec(), eivr_comm(), feature_request_and_dial(), find_cache(), generic_fax_exec(), handle_recordfile(), handle_speechrecognize(), iax2_bridge(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), local_bridge_loop(), manage_parkinglot(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), receivefax_t38_init(), record_exec(), recordthread(), remote_bridge_loop(), rpt(), rpt_exec(), 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().

04108 {
04109    return __ast_read(chan, 0);
04110 }

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

References __ast_read().

Referenced by ast_bridge_handle_trip(), and conf_run().

04113 {
04114    return __ast_read(chan, 1);
04115 }

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

References ast_readstring_full().

Referenced by __adsi_transmit_messages(), ast_adsi_begin_download(), ast_adsi_get_cpeinfo(), ast_adsi_load_session(), ast_app_getdata(), dialout(), do_directory(), forward_message(), privacy_exec(), vm_authenticate(), vm_newuser(), and vm_options().

05437 {
05438    return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
05439 }

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

05442 {
05443    int pos = 0;   /* index in the buffer where we accumulate digits */
05444    int to = ftimeout;
05445 
05446    struct ast_silence_generator *silgen = NULL;
05447 
05448    /* Stop if we're a zombie or need a soft hangup */
05449    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
05450       return -1;
05451    if (!len)
05452       return -1;
05453    for (;;) {
05454       int d;
05455       if (c->stream) {
05456          d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
05457          ast_stopstream(c);
05458          if (!silgen && ast_opt_transmit_silence)
05459             silgen = ast_channel_start_silence_generator(c);
05460          usleep(1000);
05461          if (!d)
05462             d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
05463       } else {
05464          if (!silgen && ast_opt_transmit_silence)
05465             silgen = ast_channel_start_silence_generator(c);
05466          d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
05467       }
05468       if (d < 0) {
05469          ast_channel_stop_silence_generator(c, silgen);
05470          return AST_GETDATA_FAILED;
05471       }
05472       if (d == 0) {
05473          s[pos] = '\0';
05474          ast_channel_stop_silence_generator(c, silgen);
05475          return AST_GETDATA_TIMEOUT;
05476       }
05477       if (d == 1) {
05478          s[pos] = '\0';
05479          ast_channel_stop_silence_generator(c, silgen);
05480          return AST_GETDATA_INTERRUPTED;
05481       }
05482       if (strchr(enders, d) && (pos == 0)) {
05483          s[pos] = '\0';
05484          ast_channel_stop_silence_generator(c, silgen);
05485          return AST_GETDATA_EMPTY_END_TERMINATED;
05486       }
05487       if (!strchr(enders, d)) {
05488          s[pos++] = d;
05489       }
05490       if (strchr(enders, d) || (pos >= len)) {
05491          s[pos] = '\0';
05492          ast_channel_stop_silence_generator(c, silgen);
05493          return AST_GETDATA_COMPLETE;
05494       }
05495       to = timeout;
05496    }
05497    /* Never reached */
05498    return 0;
05499 }

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

References ast_free, and ast_recvtext().

Referenced by handle_recvchar().

04355 {
04356    int c;
04357    char *buf = ast_recvtext(chan, timeout);
04358    if (buf == NULL)
04359       return -1;  /* error or timeout */
04360    c = *(unsigned char *)buf;
04361    ast_free(buf);
04362    return c;
04363 }

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

References ast_check_hangup(), AST_CONTROL_HANGUP, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_frfree, ast_read(), ast_strndup, 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().

04366 {
04367    int res, done = 0;
04368    char *buf = NULL;
04369    
04370    while (!done) {
04371       struct ast_frame *f;
04372       if (ast_check_hangup(chan))
04373          break;
04374       res = ast_waitfor(chan, timeout);
04375       if (res <= 0) /* timeout or error */
04376          break;
04377       timeout = res; /* update timeout */
04378       f = ast_read(chan);
04379       if (f == NULL)
04380          break; /* no frame */
04381       if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_HANGUP)
04382          done = 1;   /* force a break */
04383       else if (f->frametype == AST_FRAME_TEXT) {      /* what we want */
04384          buf = ast_strndup((char *) f->data.ptr, f->datalen);  /* dup and break */
04385          done = 1;
04386       }
04387       ast_frfree(f);
04388    }
04389    return buf;
04390 }

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

08337 {
08338    int32_t value;
08339    size_t pos = 0;
08340    int res;
08341 
08342    static const struct ast_party_id_ies from_ies = {
08343       .name.str = AST_REDIRECTING_FROM_NAME,
08344       .name.char_set = AST_REDIRECTING_FROM_NAME_CHAR_SET,
08345       .name.presentation = AST_REDIRECTING_FROM_NAME_PRESENTATION,
08346       .name.valid = AST_REDIRECTING_FROM_NAME_VALID,
08347 
08348       .number.str = AST_REDIRECTING_FROM_NUMBER,
08349       .number.plan = AST_REDIRECTING_FROM_NUMBER_PLAN,
08350       .number.presentation = AST_REDIRECTING_FROM_NUMBER_PRESENTATION,
08351       .number.valid = AST_REDIRECTING_FROM_NUMBER_VALID,
08352 
08353       .subaddress.str = AST_REDIRECTING_FROM_SUBADDRESS,
08354       .subaddress.type = AST_REDIRECTING_FROM_SUBADDRESS_TYPE,
08355       .subaddress.odd_even_indicator = AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN,
08356       .subaddress.valid = AST_REDIRECTING_FROM_SUBADDRESS_VALID,
08357 
08358       .tag = AST_REDIRECTING_FROM_TAG,
08359       .combined_presentation = AST_REDIRECTING_FROM_ID_PRESENTATION,
08360    };
08361    static const struct ast_party_id_ies to_ies = {
08362       .name.str = AST_REDIRECTING_TO_NAME,
08363       .name.char_set = AST_REDIRECTING_TO_NAME_CHAR_SET,
08364       .name.presentation = AST_REDIRECTING_TO_NAME_PRESENTATION,
08365       .name.valid = AST_REDIRECTING_TO_NAME_VALID,
08366 
08367       .number.str = AST_REDIRECTING_TO_NUMBER,
08368       .number.plan = AST_REDIRECTING_TO_NUMBER_PLAN,
08369       .number.presentation = AST_REDIRECTING_TO_NUMBER_PRESENTATION,
08370       .number.valid = AST_REDIRECTING_TO_NUMBER_VALID,
08371 
08372       .subaddress.str = AST_REDIRECTING_TO_SUBADDRESS,
08373       .subaddress.type = AST_REDIRECTING_TO_SUBADDRESS_TYPE,
08374       .subaddress.odd_even_indicator = AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN,
08375       .subaddress.valid = AST_REDIRECTING_TO_SUBADDRESS_VALID,
08376 
08377       .tag = AST_REDIRECTING_TO_TAG,
08378       .combined_presentation = AST_REDIRECTING_TO_ID_PRESENTATION,
08379    };
08380 
08381    /* Redirecting frame version */
08382    if (datalen < pos + (sizeof(data[0]) * 2) + 1) {
08383       ast_log(LOG_WARNING, "No space left for redirecting frame version\n");
08384       return -1;
08385    }
08386    data[pos++] = AST_REDIRECTING_VERSION;
08387    data[pos++] = 1;
08388    data[pos++] = 2;/* Version 1 did not have a version ie */
08389 
08390    res = party_id_build_data(data + pos, datalen - pos, &redirecting->from,
08391       "redirecting-from", &from_ies, update ? &update->from : NULL);
08392    if (res < 0) {
08393       return -1;
08394    }
08395    pos += res;
08396 
08397    res = party_id_build_data(data + pos, datalen - pos, &redirecting->to,
08398       "redirecting-to", &to_ies, update ? &update->to : NULL);
08399    if (res < 0) {
08400       return -1;
08401    }
08402    pos += res;
08403 
08404    /* Redirecting reason */
08405    if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
08406       ast_log(LOG_WARNING, "No space left for redirecting reason\n");
08407       return -1;
08408    }
08409    data[pos++] = AST_REDIRECTING_REASON;
08410    data[pos++] = sizeof(value);
08411    value = htonl(redirecting->reason);
08412    memcpy(data + pos, &value, sizeof(value));
08413    pos += sizeof(value);
08414 
08415    /* Redirecting count */
08416    if (datalen < pos + (sizeof(data[0]) * 2) + sizeof(value)) {
08417       ast_log(LOG_WARNING, "No space left for redirecting count\n");
08418       return -1;
08419    }
08420    data[pos++] = AST_REDIRECTING_COUNT;
08421    data[pos++] = sizeof(value);
08422    value = htonl(redirecting->count);
08423    memcpy(data + pos, &value, sizeof(value));
08424    pos += sizeof(value);
08425 
08426    return pos;
08427 }

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

08430 {
08431    size_t pos;
08432    unsigned char ie_len;
08433    unsigned char ie_id;
08434    int32_t value;
08435    int frame_version = 1;
08436    int from_combined_presentation = 0;
08437    int got_from_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
08438    int to_combined_presentation = 0;
08439    int got_to_combined_presentation = 0;/* TRUE if got a combined name and number presentation value. */
08440 
08441    for (pos = 0; pos < datalen; pos += ie_len) {
08442       if (datalen < pos + sizeof(ie_id) + sizeof(ie_len)) {
08443          ast_log(LOG_WARNING, "Invalid redirecting update\n");
08444          return -1;
08445       }
08446       ie_id = data[pos++];
08447       ie_len = data[pos++];
08448       if (datalen < pos + ie_len) {
08449          ast_log(LOG_WARNING, "Invalid redirecting update\n");
08450          return -1;
08451       }
08452 
08453       switch (ie_id) {
08454 /* Redirecting frame version */
08455       case AST_REDIRECTING_VERSION:
08456          if (ie_len != 1) {
08457             ast_log(LOG_WARNING, "Invalid redirecting frame version (%u)\n",
08458                (unsigned) ie_len);
08459             break;
08460          }
08461          frame_version = data[pos];
08462          break;
08463 /* Redirecting-from party id name */
08464       case AST_REDIRECTING_FROM_NAME:
08465          ast_free(redirecting->from.name.str);
08466          redirecting->from.name.str = ast_malloc(ie_len + 1);
08467          if (redirecting->from.name.str) {
08468             memcpy(redirecting->from.name.str, data + pos, ie_len);
08469             redirecting->from.name.str[ie_len] = 0;
08470          }
08471          break;
08472       case AST_REDIRECTING_FROM_NAME_CHAR_SET:
08473          if (ie_len != 1) {
08474             ast_log(LOG_WARNING, "Invalid redirecting-from name char set (%u)\n",
08475                (unsigned) ie_len);
08476             break;
08477          }
08478          redirecting->from.name.char_set = data[pos];
08479          break;
08480       case AST_REDIRECTING_FROM_NAME_PRESENTATION:
08481          if (ie_len != 1) {
08482             ast_log(LOG_WARNING, "Invalid redirecting-from name presentation (%u)\n",
08483                (unsigned) ie_len);
08484             break;
08485          }
08486          redirecting->from.name.presentation = data[pos];
08487          break;
08488       case AST_REDIRECTING_FROM_NAME_VALID:
08489          if (ie_len != 1) {
08490             ast_log(LOG_WARNING, "Invalid redirecting-from name valid (%u)\n",
08491                (unsigned) ie_len);
08492             break;
08493          }
08494          redirecting->from.name.valid = data[pos];
08495          break;
08496 /* Redirecting-from party id number */
08497       case AST_REDIRECTING_FROM_NUMBER:
08498          ast_free(redirecting->from.number.str);
08499          redirecting->from.number.str = ast_malloc(ie_len + 1);
08500          if (redirecting->from.number.str) {
08501             memcpy(redirecting->from.number.str, data + pos, ie_len);
08502             redirecting->from.number.str[ie_len] = 0;
08503          }
08504          break;
08505       case AST_REDIRECTING_FROM_NUMBER_PLAN:
08506          if (ie_len != 1) {
08507             ast_log(LOG_WARNING, "Invalid redirecting-from numbering plan (%u)\n",
08508                (unsigned) ie_len);
08509             break;
08510          }
08511          redirecting->from.number.plan = data[pos];
08512          break;
08513       case AST_REDIRECTING_FROM_NUMBER_PRESENTATION:
08514          if (ie_len != 1) {
08515             ast_log(LOG_WARNING, "Invalid redirecting-from number presentation (%u)\n",
08516                (unsigned) ie_len);
08517             break;
08518          }
08519          redirecting->from.number.presentation = data[pos];
08520          break;
08521       case AST_REDIRECTING_FROM_NUMBER_VALID:
08522          if (ie_len != 1) {
08523             ast_log(LOG_WARNING, "Invalid redirecting-from number valid (%u)\n",
08524                (unsigned) ie_len);
08525             break;
08526          }
08527          redirecting->from.number.valid = data[pos];
08528          break;
08529 /* Redirecting-from party id combined presentation */
08530       case AST_REDIRECTING_FROM_ID_PRESENTATION:
08531          if (ie_len != 1) {
08532             ast_log(LOG_WARNING, "Invalid redirecting-from combined presentation (%u)\n",
08533                (unsigned) ie_len);
08534             break;
08535          }
08536          from_combined_presentation = data[pos];
08537          got_from_combined_presentation = 1;
08538          break;
08539 /* Redirecting-from party id subaddress */
08540       case AST_REDIRECTING_FROM_SUBADDRESS:
08541          ast_free(redirecting->from.subaddress.str);
08542          redirecting->from.subaddress.str = ast_malloc(ie_len + 1);
08543          if (redirecting->from.subaddress.str) {
08544             memcpy(redirecting->from.subaddress.str, data + pos, ie_len);
08545             redirecting->from.subaddress.str[ie_len] = 0;
08546          }
08547          break;
08548       case AST_REDIRECTING_FROM_SUBADDRESS_TYPE:
08549          if (ie_len != 1) {
08550             ast_log(LOG_WARNING, "Invalid redirecting-from type of subaddress (%u)\n",
08551                (unsigned) ie_len);
08552             break;
08553          }
08554          redirecting->from.subaddress.type = data[pos];
08555          break;
08556       case AST_REDIRECTING_FROM_SUBADDRESS_ODD_EVEN:
08557          if (ie_len != 1) {
08558             ast_log(LOG_WARNING,
08559                "Invalid redirecting-from subaddress odd-even indicator (%u)\n",
08560                (unsigned) ie_len);
08561             break;
08562          }
08563          redirecting->from.subaddress.odd_even_indicator = data[pos];
08564          break;
08565       case AST_REDIRECTING_FROM_SUBADDRESS_VALID:
08566          if (ie_len != 1) {
08567             ast_log(LOG_WARNING, "Invalid redirecting-from subaddress valid (%u)\n",
08568                (unsigned) ie_len);
08569             break;
08570          }
08571          redirecting->from.subaddress.valid = data[pos];
08572          break;
08573 /* Redirecting-from party id tag */
08574       case AST_REDIRECTING_FROM_TAG:
08575          ast_free(redirecting->from.tag);
08576          redirecting->from.tag = ast_malloc(ie_len + 1);
08577          if (redirecting->from.tag) {
08578             memcpy(redirecting->from.tag, data + pos, ie_len);
08579             redirecting->from.tag[ie_len] = 0;
08580          }
08581          break;
08582 /* Redirecting-to party id name */
08583       case AST_REDIRECTING_TO_NAME:
08584          ast_free(redirecting->to.name.str);
08585          redirecting->to.name.str = ast_malloc(ie_len + 1);
08586          if (redirecting->to.name.str) {
08587             memcpy(redirecting->to.name.str, data + pos, ie_len);
08588             redirecting->to.name.str[ie_len] = 0;
08589          }
08590          break;
08591       case AST_REDIRECTING_TO_NAME_CHAR_SET:
08592          if (ie_len != 1) {
08593             ast_log(LOG_WARNING, "Invalid redirecting-to name char set (%u)\n",
08594                (unsigned) ie_len);
08595             break;
08596          }
08597          redirecting->to.name.char_set = data[pos];
08598          break;
08599       case AST_REDIRECTING_TO_NAME_PRESENTATION:
08600          if (ie_len != 1) {
08601             ast_log(LOG_WARNING, "Invalid redirecting-to name presentation (%u)\n",
08602                (unsigned) ie_len);
08603             break;
08604          }
08605          redirecting->to.name.presentation = data[pos];
08606          break;
08607       case AST_REDIRECTING_TO_NAME_VALID:
08608          if (ie_len != 1) {
08609             ast_log(LOG_WARNING, "Invalid redirecting-to name valid (%u)\n",
08610                (unsigned) ie_len);
08611             break;
08612          }
08613          redirecting->to.name.valid = data[pos];
08614          break;
08615 /* Redirecting-to party id number */
08616       case AST_REDIRECTING_TO_NUMBER:
08617          ast_free(redirecting->to.number.str);
08618          redirecting->to.number.str = ast_malloc(ie_len + 1);
08619          if (redirecting->to.number.str) {
08620             memcpy(redirecting->to.number.str, data + pos, ie_len);
08621             redirecting->to.number.str[ie_len] = 0;
08622          }
08623          break;
08624       case AST_REDIRECTING_TO_NUMBER_PLAN:
08625          if (ie_len != 1) {
08626             ast_log(LOG_WARNING, "Invalid redirecting-to numbering plan (%u)\n",
08627                (unsigned) ie_len);
08628             break;
08629          }
08630          redirecting->to.number.plan = data[pos];
08631          break;
08632       case AST_REDIRECTING_TO_NUMBER_PRESENTATION:
08633          if (ie_len != 1) {
08634             ast_log(LOG_WARNING, "Invalid redirecting-to number presentation (%u)\n",
08635                (unsigned) ie_len);
08636             break;
08637          }
08638          redirecting->to.number.presentation = data[pos];
08639          break;
08640       case AST_REDIRECTING_TO_NUMBER_VALID:
08641          if (ie_len != 1) {
08642             ast_log(LOG_WARNING, "Invalid redirecting-to number valid (%u)\n",
08643                (unsigned) ie_len);
08644             break;
08645          }
08646          redirecting->to.number.valid = data[pos];
08647          break;
08648 /* Redirecting-to party id combined presentation */
08649       case AST_REDIRECTING_TO_ID_PRESENTATION:
08650          if (ie_len != 1) {
08651             ast_log(LOG_WARNING, "Invalid redirecting-to combined presentation (%u)\n",
08652                (unsigned) ie_len);
08653             break;
08654          }
08655          to_combined_presentation = data[pos];
08656          got_to_combined_presentation = 1;
08657          break;
08658 /* Redirecting-to party id subaddress */
08659       case AST_REDIRECTING_TO_SUBADDRESS:
08660          ast_free(redirecting->to.subaddress.str);
08661          redirecting->to.subaddress.str = ast_malloc(ie_len + 1);
08662          if (redirecting->to.subaddress.str) {
08663             memcpy(redirecting->to.subaddress.str, data + pos, ie_len);
08664             redirecting->to.subaddress.str[ie_len] = 0;
08665          }
08666          break;
08667       case AST_REDIRECTING_TO_SUBADDRESS_TYPE:
08668          if (ie_len != 1) {
08669             ast_log(LOG_WARNING, "Invalid redirecting-to type of subaddress (%u)\n",
08670                (unsigned) ie_len);
08671             break;
08672          }
08673          redirecting->to.subaddress.type = data[pos];
08674          break;
08675       case AST_REDIRECTING_TO_SUBADDRESS_ODD_EVEN:
08676          if (ie_len != 1) {
08677             ast_log(LOG_WARNING,
08678                "Invalid redirecting-to subaddress odd-even indicator (%u)\n",
08679                (unsigned) ie_len);
08680             break;
08681          }
08682          redirecting->to.subaddress.odd_even_indicator = data[pos];
08683          break;
08684       case AST_REDIRECTING_TO_SUBADDRESS_VALID:
08685          if (ie_len != 1) {
08686             ast_log(LOG_WARNING, "Invalid redirecting-to subaddress valid (%u)\n",
08687                (unsigned) ie_len);
08688             break;
08689          }
08690          redirecting->to.subaddress.valid = data[pos];
08691          break;
08692 /* Redirecting-to party id tag */
08693       case AST_REDIRECTING_TO_TAG:
08694          ast_free(redirecting->to.tag);
08695          redirecting->to.tag = ast_malloc(ie_len + 1);
08696          if (redirecting->to.tag) {
08697             memcpy(redirecting->to.tag, data + pos, ie_len);
08698             redirecting->to.tag[ie_len] = 0;
08699          }
08700          break;
08701 /* Redirecting reason */
08702       case AST_REDIRECTING_REASON:
08703          if (ie_len != sizeof(value)) {
08704             ast_log(LOG_WARNING, "Invalid redirecting reason (%u)\n",
08705                (unsigned) ie_len);
08706             break;
08707          }
08708          memcpy(&value, data + pos, sizeof(value));
08709          redirecting->reason = ntohl(value);
08710          break;
08711 /* Redirecting count */
08712       case AST_REDIRECTING_COUNT:
08713          if (ie_len != sizeof(value)) {
08714             ast_log(LOG_WARNING, "Invalid redirecting count (%u)\n",
08715                (unsigned) ie_len);
08716             break;
08717          }
08718          memcpy(&value, data + pos, sizeof(value));
08719          redirecting->count = ntohl(value);
08720          break;
08721 /* Redirecting unknown element */
08722       default:
08723          ast_log(LOG_DEBUG, "Unknown redirecting element: %u (%u)\n",
08724             (unsigned) ie_id, (unsigned) ie_len);
08725          break;
08726       }
08727    }
08728 
08729    switch (frame_version) {
08730    case 1:
08731       /*
08732        * The other end is an earlier version that we need to adjust
08733        * for compatibility.
08734        */
08735       redirecting->from.name.valid = 1;
08736       redirecting->from.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
08737       redirecting->from.number.valid = 1;
08738       if (got_from_combined_presentation) {
08739          redirecting->from.name.presentation = from_combined_presentation;
08740          redirecting->from.number.presentation = from_combined_presentation;
08741       }
08742 
08743       redirecting->to.name.valid = 1;
08744       redirecting->to.name.char_set = AST_PARTY_CHAR_SET_ISO8859_1;
08745       redirecting->to.number.valid = 1;
08746       if (got_to_combined_presentation) {
08747          redirecting->to.name.presentation = to_combined_presentation;
08748          redirecting->to.number.presentation = to_combined_presentation;
08749       }
08750       break;
08751    case 2:
08752       /* The other end is at the same level as we are. */
08753       break;
08754    default:
08755       /*
08756        * The other end is newer than we are.
08757        * We need to assume that they are compatible with us.
08758        */
08759       ast_log(LOG_DEBUG, "Redirecting frame has newer version: %u\n",
08760          (unsigned) frame_version);
08761       break;
08762    }
08763 
08764    return 0;
08765 }

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
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 5294 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(), attempt_reconnect(), begin_dial_channel(), build_conf(), chanavail_exec(), conf_run(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), and wait_for_answer().

05295 {
05296    struct chanlist *chan;
05297    struct ast_channel *c;
05298    format_t capabilities;
05299    format_t fmt;
05300    int res;
05301    int foo;
05302    format_t videoformat = format & AST_FORMAT_VIDEO_MASK;
05303    format_t textformat = format & AST_FORMAT_TEXT_MASK;
05304 
05305    if (!cause)
05306       cause = &foo;
05307    *cause = AST_CAUSE_NOTDEFINED;
05308 
05309    if (AST_RWLIST_RDLOCK(&backends)) {
05310       ast_log(LOG_WARNING, "Unable to lock technology backend list\n");
05311       return NULL;
05312    }
05313 
05314    AST_RWLIST_TRAVERSE(&backends, chan, list) {
05315       if (strcasecmp(type, chan->tech->type))
05316          continue;
05317 
05318       capabilities = chan->tech->capabilities;
05319       fmt = format & AST_FORMAT_AUDIO_MASK;
05320       if (fmt) {
05321          /* We have audio - is it possible to connect the various calls to each other? 
05322             (Avoid this check for calls without audio, like text+video calls)
05323          */
05324          res = ast_translator_best_choice(&fmt, &capabilities);
05325          if (res < 0) {
05326             char tmp1[256], tmp2[256];
05327             ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %s) to %s\n", type,
05328                ast_getformatname_multiple(tmp1, sizeof(tmp1), chan->tech->capabilities),
05329                ast_getformatname_multiple(tmp2, sizeof(tmp2), format));
05330             *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
05331             AST_RWLIST_UNLOCK(&backends);
05332             return NULL;
05333          }
05334       }
05335       AST_RWLIST_UNLOCK(&backends);
05336       if (!chan->tech->requester)
05337          return NULL;
05338 
05339       if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, requestor, data, cause)))
05340          return NULL;
05341 
05342       if (set_security_requirements(requestor, c)) {
05343          ast_log(LOG_WARNING, "Setting security requirements failed\n");
05344          c = ast_channel_release(c);
05345          *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
05346          return NULL;
05347       }
05348 
05349       /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
05350       return c;
05351    }
05352 
05353    ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
05354    *cause = AST_CAUSE_NOSUCHDRIVER;
05355    AST_RWLIST_UNLOCK(&backends);
05356 
05357    return NULL;
05358 }

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

References __ast_request_and_dial().

Referenced by ast_pbx_outgoing_exten(), and generic_recall().

05250 {
05251    return __ast_request_and_dial(type, format, requestor, data, timeout, outstate, cidnum, cidname, NULL);
05252 }

int ast_safe_sleep ( struct ast_channel *  chan,
int  ms 
)

int ast_safe_sleep_conditional ( struct ast_channel *  chan,
int  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 1726 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_waitfor(), cond, and ast_channel::generatordata.

Referenced by ast_safe_sleep(), and login_exec().

01727 {
01728    struct ast_frame *f;
01729    struct ast_silence_generator *silgen = NULL;
01730    int res = 0;
01731    AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
01732 
01733    AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
01734 
01735    /* If no other generator is present, start silencegen while waiting */
01736    if (ast_opt_transmit_silence && !chan->generatordata) {
01737       silgen = ast_channel_start_silence_generator(chan);
01738    }
01739 
01740    while (ms > 0) {
01741       struct ast_frame *dup_f = NULL;
01742       if (cond && ((*cond)(data) == 0)) {
01743          break;
01744       }
01745       ms = ast_waitfor(chan, ms);
01746       if (ms < 0) {
01747          res = -1;
01748          break;
01749       }
01750       if (ms > 0) {
01751          f = ast_read(chan);
01752          if (!f) {
01753             res = -1;
01754             break;
01755          }
01756 
01757          if (!ast_is_deferrable_frame(f)) {
01758             ast_frfree(f);
01759             continue;
01760          }
01761          
01762          if ((dup_f = ast_frisolate(f))) {
01763             if (dup_f != f) {
01764                ast_frfree(f);
01765             }
01766             AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
01767          }
01768       }
01769    }
01770 
01771    /* stop silgen if present */
01772    if (silgen) {
01773       ast_channel_stop_silence_generator(chan, silgen);
01774    }
01775 
01776    /* We need to free all the deferred frames, but we only need to
01777     * queue the deferred frames if there was no error and no
01778     * hangup was received
01779     */
01780    ast_channel_lock(chan);
01781    while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
01782       if (!res) {
01783          ast_queue_frame_head(chan, f);
01784       }
01785       ast_frfree(f);
01786    }
01787    ast_channel_unlock(chan);
01788 
01789    return res;
01790 }

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 4463 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(), do_dtmf_phone(), manager_play_dtmf(), and rpt_call().

04464 {
04465    if (chan->tech->send_digit_begin) {
04466       ast_senddigit_begin(chan, digit);
04467       ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
04468    }
04469    
04470    return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
04471 }

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

References ast_debug, ast_playtones_start(), ast_channel::name, ast_channel_tech::send_digit_begin, and ast_channel::tech.

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

04406 {
04407    /* Device does not support DTMF tones, lets fake
04408     * it by doing our own generation. */
04409    static const char * const dtmf_tones[] = {
04410       "941+1336", /* 0 */
04411       "697+1209", /* 1 */
04412       "697+1336", /* 2 */
04413       "697+1477", /* 3 */
04414       "770+1209", /* 4 */
04415       "770+1336", /* 5 */
04416       "770+1477", /* 6 */
04417       "852+1209", /* 7 */
04418       "852+1336", /* 8 */
04419       "852+1477", /* 9 */
04420       "697+1633", /* A */
04421       "770+1633", /* B */
04422       "852+1633", /* C */
04423       "941+1633", /* D */
04424       "941+1209", /* * */
04425       "941+1477"  /* # */
04426    };
04427 
04428    if (!chan->tech->send_digit_begin)
04429       return 0;
04430 
04431    if (!chan->tech->send_digit_begin(chan, digit))
04432       return 0;
04433 
04434    if (digit >= '0' && digit <='9')
04435       ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
04436    else if (digit >= 'A' && digit <= 'D')
04437       ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
04438    else if (digit == '*')
04439       ast_playtones_start(chan, 0, dtmf_tones[14], 0);
04440    else if (digit == '#')
04441       ast_playtones_start(chan, 0, dtmf_tones[15], 0);
04442    else {
04443       /* not handled */
04444       ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name);
04445    }
04446 
04447    return 0;
04448 }

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

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

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

04451 {
04452    int res = -1;
04453 
04454    if (chan->tech->send_digit_end)
04455       res = chan->tech->send_digit_end(chan, digit, duration);
04456 
04457    if (res && chan->generator)
04458       ast_playtones_stop(chan);
04459    
04460    return 0;
04461 }

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

References 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(), send_newkey(), and sendtext_exec().

04393 {
04394    int res = 0;
04395    /* Stop if we're a zombie or need a soft hangup */
04396    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
04397       return -1;
04398    CHECK_BLOCKING(chan);
04399    if (chan->tech->send_text)
04400       res = chan->tech->send_text(chan, text);
04401    ast_clear_flag(chan, AST_FLAG_BLOCKING);
04402    return res;
04403 }

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 6306 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(), ast_call_forward(), cb_events(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), findmeexec(), get_pai(), get_rpid(), handle_setcallerid(), mgcp_ss(), privacy_exec(), ring_entry(), rpt_exec(), sig_pri_handle_subcmds(), skinny_newcall(), and socket_process().

06307 {
06308    ast_channel_lock(chan);
06309 
06310    if (cid_num) {
06311       chan->caller.id.number.valid = 1;
06312       ast_free(chan->caller.id.number.str);
06313       chan->caller.id.number.str = ast_strdup(cid_num);
06314    }
06315    if (cid_name) {
06316       chan->caller.id.name.valid = 1;
06317       ast_free(chan->caller.id.name.str);
06318       chan->caller.id.name.str = ast_strdup(cid_name);
06319    }
06320    if (cid_ani) {
06321       chan->caller.ani.number.valid = 1;
06322       ast_free(chan->caller.ani.number.str);
06323       chan->caller.ani.number.str = ast_strdup(cid_ani);
06324    }
06325    if (chan->cdr) {
06326       ast_cdr_setcid(chan->cdr, chan);
06327    }
06328 
06329    report_new_callerid(chan);
06330 
06331    ast_channel_unlock(chan);
06332 }

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

References ast_bridged_channel(), ast_channel_lock, ast_channel_unlock, ast_string_field_set, ast_strlen_zero(), ast_channel::bridge, and ast_channel::hangupsource.

Referenced by __dahdi_exception(), func_channel_write_real(), handle_hangup(), handle_request_bye(), handle_request_cancel(), handle_response_invite(), pbx_builtin_hangup(), and set_hangup_source_and_cause().

02611 {
02612    struct ast_channel *bridge;
02613 
02614    ast_channel_lock(chan);
02615    if (force || ast_strlen_zero(chan->hangupsource)) {
02616       ast_string_field_set(chan, hangupsource, source);
02617    }
02618    bridge = ast_bridged_channel(chan);
02619    ast_channel_unlock(chan);
02620 
02621    if (bridge && (force || ast_strlen_zero(bridge->hangupsource))) {
02622       ast_channel_lock(bridge);
02623       ast_string_field_set(chan, hangupsource, source);
02624       ast_channel_unlock(bridge);
02625    }
02626 }

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

07460 {
07461    struct ast_variable *cur;
07462 
07463    for (cur = vars; cur; cur = cur->next)
07464       pbx_builtin_setvar_helper(chan, cur->name, cur->value);  
07465 }

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

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

Referenced by ast_activate_generator(), ast_closestream(), ast_deactivate_generator(), ast_read_generator_actions(), ast_readaudio_callback(), and filestream_destructor().

03354 {
03355    int res;
03356    unsigned int real_rate = rate, max_rate;
03357 
03358    ast_channel_lock(c);
03359 
03360    if (c->timingfd == -1) {
03361       ast_channel_unlock(c);
03362       return -1;
03363    }
03364 
03365    if (!func) {
03366       rate = 0;
03367       data = NULL;
03368    }
03369 
03370    if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) {
03371       real_rate = max_rate;
03372    }
03373 
03374    ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate);
03375 
03376    res = ast_timer_set_rate(c->timer, real_rate);
03377 
03378    c->timingfunc = func;
03379    c->timingdata = data;
03380 
03381    ast_channel_unlock(c);
03382 
03383    return res;
03384 }

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

Referenced by handle_request_options().

00796 {
00797    return shutting_down;
00798 }

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 2587 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_channel_softhangup_cb(), ast_dial_join(), birdbath(), cc_generic_agent_stop_ringing(), conf_free(), connect_link(), dahdi_handle_event(), flush_telem(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), login_exec(), manager_park(), mgcp_pktcgate_remove(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), rpt_exec(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().

02588 {
02589    int res;
02590 
02591    ast_channel_lock(chan);
02592    res = ast_softhangup_nolock(chan, cause);
02593    ast_channel_unlock(chan);
02594 
02595    return res;
02596 }

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

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

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

02575 {
02576    ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name);
02577    /* Inform channel driver that we need to be hung up, if it cares */
02578    chan->_softhangup |= cause;
02579    ast_queue_frame(chan, &ast_null_frame);
02580    /* Interrupt any poll call or such */
02581    if (ast_test_flag(chan, AST_FLAG_BLOCKING))
02582       pthread_kill(chan->blocker, SIGURG);
02583    return 0;
02584 }

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

00938 {
00939    char *buf;
00940 
00941    switch (state) {
00942    case AST_STATE_DOWN:
00943       return "Down";
00944    case AST_STATE_RESERVED:
00945       return "Rsrvd";
00946    case AST_STATE_OFFHOOK:
00947       return "OffHook";
00948    case AST_STATE_DIALING:
00949       return "Dialing";
00950    case AST_STATE_RING:
00951       return "Ring";
00952    case AST_STATE_RINGING:
00953       return "Ringing";
00954    case AST_STATE_UP:
00955       return "Up";
00956    case AST_STATE_BUSY:
00957       return "Busy";
00958    case AST_STATE_DIALING_OFFHOOK:
00959       return "Dialing Offhook";
00960    case AST_STATE_PRERING:
00961       return "Pre-ring";
00962    default:
00963       if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
00964          return "Unknown";
00965       snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state);
00966       return buf;
00967    }
00968 }

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

References ARRAY_LEN, cause, and causes.

Referenced by pbx_builtin_hangup().

00924 {
00925    int x;
00926 
00927    for (x = 0; x < ARRAY_LEN(causes); x++)
00928       if (!strncasecmp(causes[x].name, name, strlen(causes[x].name)))
00929          return causes[x].cause;
00930 
00931    return -1;
00932 }

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

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

Referenced by zapateller_exec().

07180 {
07181    int res;
07182 
07183    if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
07184       return res;
07185 
07186    /* Give us some wiggle room */
07187    while (chan->generatordata && ast_waitfor(chan, 100) >= 0) {
07188       struct ast_frame *f = ast_read(chan);
07189       if (f)
07190          ast_frfree(f);
07191       else
07192          return -1;
07193    }
07194    return 0;
07195 }

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

Start a tone going

Definition at line 7161 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(), play_tone_pair(), rpt_tele_thread(), and sendnoise().

07162 {
07163    struct tonepair_def d = { 0, };
07164 
07165    d.freq1 = freq1;
07166    d.freq2 = freq2;
07167    d.duration = duration;
07168    d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
07169    if (ast_activate_generator(chan, &tonepair, &d))
07170       return -1;
07171    return 0;
07172 }

void ast_tonepair_stop ( struct ast_channel *  chan  ) 

Stop a tone from playing

Definition at line 7174 of file channel.c.

References ast_deactivate_generator().

Referenced by sendnoise().

07175 {
07176    ast_deactivate_generator(chan);
07177 }

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

05388 {
05389    int res = -1;
05390 
05391    /* Stop if we're a zombie or need a soft hangup */
05392    ast_channel_lock(chan);
05393    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
05394       if (chan->tech->transfer) {
05395          res = chan->tech->transfer(chan, dest);
05396          if (!res)
05397             res = 1;
05398       } else
05399          res = 0;
05400    }
05401    ast_channel_unlock(chan);
05402 
05403    if (res <= 0) {
05404       return res;
05405    }
05406 
05407    for (;;) {
05408       struct ast_frame *fr;
05409 
05410       res = ast_waitfor(chan, -1);
05411 
05412       if (res < 0 || !(fr = ast_read(chan))) {
05413          res = -1;
05414          break;
05415       }
05416 
05417       if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_TRANSFER) {
05418          enum ast_control_transfer *message = fr->data.ptr;
05419 
05420          if (*message == AST_TRANSFER_SUCCESS) {
05421             res = 1;
05422          } else {
05423             res = -1;
05424          }
05425 
05426          ast_frfree(fr);
05427          break;
05428       }
05429 
05430       ast_frfree(fr);
05431    }
05432 
05433    return res;
05434 }

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

References AST_TRANS_CAP_3_1K_AUDIO, AST_TRANS_CAP_DIGITAL, AST_TRANS_CAP_DIGITAL_W_TONES, AST_TRANS_CAP_RESTRICTED_DIGITAL, AST_TRANS_CAP_SPEECH, and AST_TRANS_CAP_VIDEO.

Referenced by ast_channel_data_add_structure(), cb_events(), misdn_call(), oh323_call(), sig_pri_call(), sig_pri_new_ast_channel(), and sig_ss7_new_ast_channel().

00972 {
00973    switch (transfercapability) {
00974    case AST_TRANS_CAP_SPEECH:
00975       return "SPEECH";
00976    case AST_TRANS_CAP_DIGITAL:
00977       return "DIGITAL";
00978    case AST_TRANS_CAP_RESTRICTED_DIGITAL:
00979       return "RESTRICTED_DIGITAL";
00980    case AST_TRANS_CAP_3_1K_AUDIO:
00981       return "3K1AUDIO";
00982    case AST_TRANS_CAP_DIGITAL_W_TONES:
00983       return "DIGITAL_W_TONES";
00984    case AST_TRANS_CAP_VIDEO:
00985       return "VIDEO";
00986    default:
00987       return "UNKNOWN";
00988    }
00989 }

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 3337 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(), dahdi_accept_r2_call_exec(), dictate_exec(), disa_exec(), disable_t38(), do_idle_thread(), 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().

03338 {
03339    int oldms = ms;   /* -1 if no timeout */
03340 
03341    ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
03342    if ((ms < 0) && (oldms < 0))
03343       ms = 0;
03344    return ms;
03345 }

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 3332 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(), rpt(), rpt_exec(), wait_for_answer(), and wait_for_winner().

03333 {
03334    return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
03335 }

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

References ast_waitfor_nandfds().

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

02974 {
02975    int winner = -1;
02976    ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
02977    return winner;
02978 }

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

References ast_channel::_softhangup, ast_add_fd(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, ast_log(), 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, ast_channel::fdno, and LOG_WARNING.

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

02988 {
02989    struct timeval start = { 0 , 0 };
02990    struct pollfd *pfds = NULL;
02991    int res;
02992    long rms;
02993    int x, y, max;
02994    int sz;
02995    struct timeval now = { 0, 0 };
02996    struct timeval whentohangup = { 0, 0 }, diff;
02997    struct ast_channel *winner = NULL;
02998    struct fdmap {
02999       int chan;
03000       int fdno;
03001    } *fdmap = NULL;
03002 
03003    if ((sz = n * AST_MAX_FDS + nfds)) {
03004       pfds = alloca(sizeof(*pfds) * sz);
03005       fdmap = alloca(sizeof(*fdmap) * sz);
03006    }
03007 
03008    if (outfd)
03009       *outfd = -99999;
03010    if (exception)
03011       *exception = 0;
03012    
03013    /* Perform any pending masquerades */
03014    for (x = 0; x < n; x++) {
03015       if (c[x]->masq && ast_do_masquerade(c[x])) {
03016          ast_log(LOG_WARNING, "Masquerade failed\n");
03017          *ms = -1;
03018          return NULL;
03019       }
03020 
03021       ast_channel_lock(c[x]);
03022       if (!ast_tvzero(c[x]->whentohangup)) {
03023          if (ast_tvzero(whentohangup))
03024             now = ast_tvnow();
03025          diff = ast_tvsub(c[x]->whentohangup, now);
03026          if (diff.tv_sec < 0 || ast_tvzero(diff)) {
03027             /* Should already be hungup */
03028             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
03029             ast_channel_unlock(c[x]);
03030             return c[x];
03031          }
03032          if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0)
03033             whentohangup = diff;
03034       }
03035       ast_channel_unlock(c[x]);
03036    }
03037    /* Wait full interval */
03038    rms = *ms;
03039    /* INT_MAX, not LONG_MAX, because it matters on 64-bit */
03040    if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) {
03041       rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000;              /* timeout in milliseconds */
03042       if (*ms >= 0 && *ms < rms) {                                                 /* original *ms still smaller */
03043          rms =  *ms;
03044       }
03045    } else if (!ast_tvzero(whentohangup) && rms < 0) {
03046       /* Tiny corner case... call would need to last >24 days */
03047       rms = INT_MAX;
03048    }
03049    /*
03050     * Build the pollfd array, putting the channels' fds first,
03051     * followed by individual fds. Order is important because
03052     * individual fd's must have priority over channel fds.
03053     */
03054    max = 0;
03055    for (x = 0; x < n; x++) {
03056       for (y = 0; y < AST_MAX_FDS; y++) {
03057          fdmap[max].fdno = y;  /* fd y is linked to this pfds */
03058          fdmap[max].chan = x;  /* channel x is linked to this pfds */
03059          max += ast_add_fd(&pfds[max], c[x]->fds[y]);
03060       }
03061       CHECK_BLOCKING(c[x]);
03062    }
03063    /* Add the individual fds */
03064    for (x = 0; x < nfds; x++) {
03065       fdmap[max].chan = -1;
03066       max += ast_add_fd(&pfds[max], fds[x]);
03067    }
03068 
03069    if (*ms > 0)
03070       start = ast_tvnow();
03071    
03072    if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
03073       do {
03074          int kbrms = rms;
03075          if (kbrms > 600000)
03076             kbrms = 600000;
03077          res = ast_poll(pfds, max, kbrms);
03078          if (!res)
03079             rms -= kbrms;
03080       } while (!res && (rms > 0));
03081    } else {
03082       res = ast_poll(pfds, max, rms);
03083    }
03084    for (x = 0; x < n; x++)
03085       ast_clear_flag(c[x], AST_FLAG_BLOCKING);
03086    if (res < 0) { /* Simulate a timeout if we were interrupted */
03087       if (errno != EINTR)
03088          *ms = -1;
03089       return NULL;
03090    }
03091    if (!ast_tvzero(whentohangup)) {   /* if we have a timeout, check who expired */
03092       now = ast_tvnow();
03093       for (x = 0; x < n; x++) {
03094          if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) {
03095             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
03096             if (winner == NULL)
03097                winner = c[x];
03098          }
03099       }
03100    }
03101    if (res == 0) { /* no fd ready, reset timeout and done */
03102       *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
03103       return winner;
03104    }
03105    /*
03106     * Then check if any channel or fd has a pending event.
03107     * Remember to check channels first and fds last, as they
03108     * must have priority on setting 'winner'
03109     */
03110    for (x = 0; x < max; x++) {
03111       res = pfds[x].revents;
03112       if (res == 0)
03113          continue;
03114       if (fdmap[x].chan >= 0) {  /* this is a channel */
03115          winner = c[fdmap[x].chan]; /* override previous winners */
03116          if (res & POLLPRI)
03117             ast_set_flag(winner, AST_FLAG_EXCEPTION);
03118          else
03119             ast_clear_flag(winner, AST_FLAG_EXCEPTION);
03120          winner->fdno = fdmap[x].fdno;
03121       } else {       /* this is an fd */
03122          if (outfd)
03123             *outfd = pfds[x].fd;
03124          if (exception)
03125             *exception = (res & POLLPRI) ? -1 : 0;
03126          winner = NULL;
03127       }
03128    }
03129    if (*ms > 0) {
03130       *ms -= ast_tvdiff_ms(ast_tvnow(), start);
03131       if (*ms < 0)
03132          *ms = 0;
03133    }
03134    return winner;
03135 }

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

References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, 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_set_flag, ast_test_flag, 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().

03387 {
03388    /* Stop if we're a zombie or need a soft hangup */
03389    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
03390       return -1;
03391 
03392    /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
03393    ast_set_flag(c, AST_FLAG_END_DTMF_ONLY);
03394 
03395    /* Wait for a digit, no more than ms milliseconds total. */
03396    
03397    while (ms) {
03398       struct ast_channel *rchan;
03399       int outfd=-1;
03400 
03401       errno = 0;
03402       rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
03403       
03404       if (!rchan && outfd < 0 && ms) {
03405          if (errno == 0 || errno == EINTR)
03406             continue;
03407          ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
03408          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03409          return -1;
03410       } else if (outfd > -1) {
03411          /* The FD we were watching has something waiting */
03412          ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n");
03413          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03414          return 1;
03415       } else if (rchan) {
03416          int res;
03417          struct ast_frame *f = ast_read(c);
03418          if (!f)
03419             return -1;
03420 
03421          switch (f->frametype) {
03422          case AST_FRAME_DTMF_BEGIN:
03423             break;
03424          case AST_FRAME_DTMF_END:
03425             res = f->subclass.integer;
03426             ast_frfree(f);
03427             ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03428             return res;
03429          case AST_FRAME_CONTROL:
03430             switch (f->subclass.integer) {
03431             case AST_CONTROL_HANGUP:
03432                ast_frfree(f);
03433                ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03434                return -1;
03435             case AST_CONTROL_RINGING:
03436             case AST_CONTROL_ANSWER:
03437             case AST_CONTROL_SRCUPDATE:
03438             case AST_CONTROL_SRCCHANGE:
03439             case AST_CONTROL_CONNECTED_LINE:
03440             case AST_CONTROL_REDIRECTING:
03441             case -1:
03442                /* Unimportant */
03443                break;
03444             default:
03445                ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass.integer);
03446                break;
03447             }
03448             break;
03449          case AST_FRAME_VOICE:
03450             /* Write audio if appropriate */
03451             if (audiofd > -1) {
03452                if (write(audiofd, f->data.ptr, f->datalen) < 0) {
03453                   ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
03454                }
03455             }
03456          default:
03457             /* Ignore */
03458             break;
03459          }
03460          ast_frfree(f);
03461       }
03462    }
03463 
03464    ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
03465 
03466    return 0; /* Time is up */
03467 }

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 4605 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_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_LIST_NEXT, ast_log(), AST_MONITOR_RUNNING, ast_opt_generic_plc, ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), 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::name, 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, and ast_channel::writetrans.

Referenced by adsi_careful_send(), agent_write(), 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(), function_ilink(), gen_generate(), generic_fax_exec(), handle_jack_audio(), handle_link_data(), 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(), rpt(), rpt_exec(), send_link_dtmf(), send_link_keyquery(), send_tone_burst(), send_usb_txt(), 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().

04606 {
04607    int res = -1;
04608    struct ast_frame *f = NULL;
04609    int count = 0;
04610 
04611    /*Deadlock avoidance*/
04612    while(ast_channel_trylock(chan)) {
04613       /*cannot goto done since the channel is not locked*/
04614       if(count++ > 10) {
04615          ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name);
04616          return 0;
04617       }
04618       usleep(1);
04619    }
04620    /* Stop if we're a zombie or need a soft hangup */
04621    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
04622       goto done;
04623 
04624    /* Handle any pending masquerades */
04625    if (chan->masq) {
04626       ast_channel_unlock(chan);
04627       if (ast_do_masquerade(chan)) {
04628          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
04629          return res; /* no need to goto done: chan is already unlocked for masq */
04630       }
04631       ast_channel_lock(chan);
04632    }
04633    if (chan->masqr) {
04634       res = 0; /* XXX explain, why 0 ? */
04635       goto done;
04636    }
04637 
04638    /* Perform the framehook write event here. After the frame enters the framehook list
04639     * there is no telling what will happen, how awesome is that!!! */
04640    if (!(fr = ast_framehook_list_write_event(chan->framehooks, fr))) {
04641       res = 0;
04642       goto done;
04643    }
04644 
04645    if (chan->generatordata && (!fr->src || strcasecmp(fr->src, "ast_prod"))) {
04646       if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) {
04647             ast_deactivate_generator(chan);
04648       } else {
04649          if (fr->frametype == AST_FRAME_DTMF_END) {
04650             /* There is a generator running while we're in the middle of a digit.
04651              * It's probably inband DTMF, so go ahead and pass it so it can
04652              * stop the generator */
04653             ast_clear_flag(chan, AST_FLAG_BLOCKING);
04654             ast_channel_unlock(chan);
04655             res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
04656             ast_channel_lock(chan);
04657             CHECK_BLOCKING(chan);
04658          } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_UNHOLD) {
04659             /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */
04660             res = (chan->tech->indicate == NULL) ? 0 :
04661                chan->tech->indicate(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
04662          }
04663          res = 0; /* XXX explain, why 0 ? */
04664          goto done;
04665       }
04666    }
04667    /* High bit prints debugging */
04668    if (chan->fout & DEBUGCHAN_FLAG)
04669       ast_frame_dump(chan->name, fr, ">>");
04670    CHECK_BLOCKING(chan);
04671    switch (fr->frametype) {
04672    case AST_FRAME_CONTROL:
04673       res = (chan->tech->indicate == NULL) ? 0 :
04674          chan->tech->indicate(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
04675       break;
04676    case AST_FRAME_DTMF_BEGIN:
04677       if (chan->audiohooks) {
04678          struct ast_frame *old_frame = fr;
04679          fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
04680          if (old_frame != fr)
04681             f = fr;
04682       }
04683       send_dtmf_event(chan, "Sent", fr->subclass.integer, "Yes", "No");
04684       ast_clear_flag(chan, AST_FLAG_BLOCKING);
04685       ast_channel_unlock(chan);
04686       res = ast_senddigit_begin(chan, fr->subclass.integer);
04687       ast_channel_lock(chan);
04688       CHECK_BLOCKING(chan);
04689       break;
04690    case AST_FRAME_DTMF_END:
04691       if (chan->audiohooks) {
04692          struct ast_frame *new_frame = fr;
04693 
04694          new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
04695          if (new_frame != fr) {
04696             ast_frfree(new_frame);
04697          }
04698       }
04699       send_dtmf_event(chan, "Sent", fr->subclass.integer, "No", "Yes");
04700       ast_clear_flag(chan, AST_FLAG_BLOCKING);
04701       ast_channel_unlock(chan);
04702       res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);
04703       ast_channel_lock(chan);
04704       CHECK_BLOCKING(chan);
04705       break;
04706    case AST_FRAME_TEXT:
04707       if (fr->subclass.integer == AST_FORMAT_T140) {
04708          res = (chan->tech->write_text == NULL) ? 0 :
04709             chan->tech->write_text(chan, fr);
04710       } else {
04711          res = (chan->tech->send_text == NULL) ? 0 :
04712             chan->tech->send_text(chan, (char *) fr->data.ptr);
04713       }
04714       break;
04715    case AST_FRAME_HTML:
04716       res = (chan->tech->send_html == NULL) ? 0 :
04717          chan->tech->send_html(chan, fr->subclass.integer, (char *) fr->data.ptr, fr->datalen);
04718       break;
04719    case AST_FRAME_VIDEO:
04720       /* XXX Handle translation of video codecs one day XXX */
04721       res = (chan->tech->write_video == NULL) ? 0 :
04722          chan->tech->write_video(chan, fr);
04723       break;
04724    case AST_FRAME_MODEM:
04725       res = (chan->tech->write == NULL) ? 0 :
04726          chan->tech->write(chan, fr);
04727       break;
04728    case AST_FRAME_VOICE:
04729       if (chan->tech->write == NULL)
04730          break;   /*! \todo XXX should return 0 maybe ? */
04731 
04732       if (ast_opt_generic_plc && fr->subclass.codec == AST_FORMAT_SLINEAR) {
04733          apply_plc(chan, fr);
04734       }
04735 
04736       /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
04737       if (fr->subclass.codec == chan->rawwriteformat)
04738          f = fr;
04739       else
04740          f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
04741 
04742       if (!f) {
04743          res = 0;
04744          break;
04745       }
04746 
04747       if (chan->audiohooks) {
04748          struct ast_frame *prev = NULL, *new_frame, *cur, *dup;
04749          int freeoldlist = 0;
04750 
04751          if (f != fr) {
04752             freeoldlist = 1;
04753          }
04754 
04755          /* Since ast_audiohook_write may return a new frame, and the cur frame is
04756           * an item in a list of frames, create a new list adding each cur frame back to it
04757           * regardless if the cur frame changes or not. */
04758          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
04759             new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur);
04760 
04761             /* if this frame is different than cur, preserve the end of the list,
04762              * free the old frames, and set cur to be the new frame */
04763             if (new_frame != cur) {
04764 
04765                /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame
04766                 * isn't part of local storage, meaning if ast_audiohook_write is called multiple
04767                 * times it may override the previous frame we got from it unless we dup it */
04768                if ((dup = ast_frisolate(new_frame))) {
04769                   AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list);
04770                   if (freeoldlist) {
04771                      AST_LIST_NEXT(cur, frame_list) = NULL;
04772                      ast_frfree(cur);
04773                   }
04774                   if (new_frame != dup) {
04775                      ast_frfree(new_frame);
04776                   }
04777                   cur = dup;
04778                }
04779             }
04780 
04781             /* now, regardless if cur is new or not, add it to the new list,
04782              * if the new list has not started, cur will become the first item. */
04783             if (prev) {
04784                AST_LIST_NEXT(prev, frame_list) = cur;
04785             } else {
04786                f = cur; /* set f to be the beginning of our new list */
04787             }
04788             prev = cur;
04789          }
04790       }
04791       
04792       /* If Monitor is running on this channel, then we have to write frames out there too */
04793       /* the translator on chan->writetrans may have returned multiple frames
04794          from the single frame we passed in; if so, feed each one of them to the
04795          monitor */
04796       if (chan->monitor && chan->monitor->write_stream) {
04797          struct ast_frame *cur;
04798 
04799          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
04800          /* XXX must explain this code */
04801 #ifndef MONITOR_CONSTANT_DELAY
04802             int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples;
04803             if (jump >= 0) {
04804                jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass.codec), ast_format_rate(chan->monitor->read_stream->fmt->format));
04805                if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
04806                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
04807                chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples;
04808             } else {
04809                chan->outsmpl += cur->samples;
04810             }
04811 #else
04812             int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass.codec), ast_format_rate(chan->monitor->read_stream->fmt->format));
04813             if (jump - MONITOR_DELAY >= 0) {
04814                if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1)
04815                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
04816                chan->outsmpl += chan->insmpl - chan->outsmpl;
04817             } else {
04818                chan->outsmpl += cur->samples;
04819             }
04820 #endif
04821             if (chan->monitor->state == AST_MONITOR_RUNNING) {
04822                if (ast_writestream(chan->monitor->write_stream, cur) < 0)
04823                   ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
04824             }
04825          }
04826       }
04827 
04828       /* the translator on chan->writetrans may have returned multiple frames
04829          from the single frame we passed in; if so, feed each one of them to the
04830          channel, freeing each one after it has been written */
04831       if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
04832          struct ast_frame *cur, *next;
04833          unsigned int skip = 0;
04834 
04835          for (cur = f, next = AST_LIST_NEXT(cur, frame_list);
04836               cur;
04837               cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) {
04838             if (!skip) {
04839                if ((res = chan->tech->write(chan, cur)) < 0) {
04840                   chan->_softhangup |= AST_SOFTHANGUP_DEV;
04841                   skip = 1;
04842                } else if (next) {
04843                   /* don't do this for the last frame in the list,
04844                      as the code outside the loop will do it once
04845                   */
04846                   chan->fout = FRAMECOUNT_INC(chan->fout);
04847                }
04848             }
04849             ast_frfree(cur);
04850          }
04851 
04852          /* reset f so the code below doesn't attempt to free it */
04853          f = NULL;
04854       } else {
04855          res = chan->tech->write(chan, f);
04856       }
04857       break;
04858    case AST_FRAME_NULL:
04859    case AST_FRAME_IAX:
04860       /* Ignore these */
04861       res = 0;
04862       break;
04863    default:
04864       /* At this point, fr is the incoming frame and f is NULL.  Channels do
04865        * not expect to get NULL as a frame pointer and will segfault.  Hence,
04866        * we output the original frame passed in. */
04867       res = chan->tech->write(chan, fr);
04868       break;
04869    }
04870 
04871    if (f && f != fr)
04872       ast_frfree(f);
04873    ast_clear_flag(chan, AST_FLAG_BLOCKING);
04874 
04875    /* Consider a write failure to force a soft hangup */
04876    if (res < 0) {
04877       chan->_softhangup |= AST_SOFTHANGUP_DEV;
04878    } else {
04879       chan->fout = FRAMECOUNT_INC(chan->fout);
04880    }
04881 done:
04882    if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) {
04883       /* The list gets recreated if audiohooks are added again later */
04884       ast_audiohook_detach_list(chan->audiohooks);
04885       chan->audiohooks = NULL;
04886    }
04887    ast_channel_unlock(chan);
04888    return res;
04889 }

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

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

04491 {
04492    int res;
04493    if (!chan->tech->write_video)
04494       return 0;
04495    res = ast_write(chan, fr);
04496    if (!res)
04497       res = 1;
04498    return res;
04499 }

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

References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.

Referenced by reload_config().

07548 {
07549    switch (reason) {
07550    case CHANNEL_MODULE_LOAD:
07551       return "LOAD (Channel module load)";
07552 
07553    case CHANNEL_MODULE_RELOAD:
07554       return "RELOAD (Channel module reload)";
07555 
07556    case CHANNEL_CLI_RELOAD:
07557       return "CLIRELOAD (Channel module reload by CLI command)";
07558 
07559    default:
07560       return "MANAGERRELOAD (Channel module reload by manager)";
07561    }
07562 };


Variable Documentation

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

Referenced by handle_core_set_debug_channel().

unsigned long global_fout

Definition at line 98 of file channel.c.

Referenced by handle_core_set_debug_channel().


Generated on Sat Mar 26 11:17:45 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9