General Asterisk PBX channel definitions. More...
#include "asterisk/abstract_jb.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/abstract_jb.h"
#include "asterisk/poll-compat.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/chanvars.h"
#include "asterisk/config.h"
#include "asterisk/cdr.h"
#include "asterisk/stringfields.h"
#include "asterisk/datastore.h"
Go to the source code of this file.
Data Structures | |
struct | ast_bridge_config |
bridge configuration More... | |
struct | ast_callerid |
Structure for all kinds of caller ID identifications. 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. This is the side of it mostly used by the pbx and call management. 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_channel::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, amaflag,...) |
#define | AST_CHANNEL_NAME 80 |
#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 20 |
#define | MAX_MUSICCLASS 80 |
Typedefs | |
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_IN_CHANNEL_LIST = (1 << 19), 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_CDR_TRANSFER = (1 << 0), AST_CDR_FORWARD = (1 << 1), AST_CDR_CALLWAIT = (1 << 2), AST_CDR_CONFERENCE = (1 << 3) } |
enum | { AST_SOFTHANGUP_DEV = (1 << 0), AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), AST_SOFTHANGUP_SHUTDOWN = (1 << 2), AST_SOFTHANGUP_TIMEOUT = (1 << 3), AST_SOFTHANGUP_APPUNLOAD = (1 << 4), AST_SOFTHANGUP_EXPLICIT = (1 << 5), AST_SOFTHANGUP_UNBRIDGE = (1 << 6), AST_SOFTHANGUP_ALL = (0xFFFFFFFF) } |
enum | ast_bridge_result { AST_BRIDGE_COMPLETE = 0, AST_BRIDGE_FAILED = -1, AST_BRIDGE_FAILED_NOWARN = -2, AST_BRIDGE_RETRY = -3 } |
enum | ast_channel_adsicpe { AST_ADSI_UNKNOWN, AST_ADSI_AVAILABLE, AST_ADSI_UNAVAILABLE, AST_ADSI_OFFHOOKONLY } |
enum | ast_channel_state { AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_OFFHOOK, AST_STATE_DIALING, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, AST_STATE_BUSY, AST_STATE_DIALING_OFFHOOK, AST_STATE_PRERING, AST_STATE_MUTE = (1 << 16) } |
ast_channel states More... | |
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 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, int format, 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) |
Initiate system shutdown. | |
int | ast_best_codec (int 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, int 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 hangup cause. | |
void | ast_change_name (struct ast_channel *chan, 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. | |
void | ast_channel_clear_softhangup (struct ast_channel *chan, int flag) |
Clear a set of softhangup flags from a channel. | |
int | ast_channel_cmpwhentohangup (struct ast_channel *chan, time_t offset) |
Compare a offset with the settings of when to hang a channel up. | |
int | ast_channel_cmpwhentohangup_tv (struct ast_channel *chan, struct timeval offset) |
Compare a offset with the settings of when to hang a channel up. | |
int | ast_channel_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) |
Set defer DTMF flag on channel. | |
int | ast_channel_early_bridge (struct ast_channel *c0, struct ast_channel *c1) |
Bridge two channels together (early) | |
void | ast_channel_free (struct ast_channel *) |
Free a 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) |
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_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_search_locked (int(*is_match)(struct ast_channel *, void *), void *data) |
Search for a channel based on the passed channel matching callback Search for a channel based on the specified is_match callback, and return the first channel that we match. When returned, the channel will be locked. Note that the is_match callback is called with the passed channel locked, and should return 0 if there is no match, and non-zero if there is. | |
int | ast_channel_sendhtml (struct ast_channel *channel, int subclass, const char *data, int datalen) |
int | ast_channel_sendurl (struct ast_channel *channel, const char *url) |
void | ast_channel_set_fd (struct ast_channel *chan, int which, int fd) |
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) |
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. | |
struct ast_channel * | ast_channel_walk_locked (const struct ast_channel *prev) |
Browse channels in use Browse the channels currently in use. | |
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. | |
void | ast_deactivate_generator (struct ast_channel *chan) |
int | ast_do_masquerade (struct ast_channel *chan) |
Start masquerading a channel 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. | |
static int | ast_fdisset (struct pollfd *pfds, int fd, int maximum, int *start) |
Helper function for migrating select to poll. | |
struct ast_channel * | ast_get_channel_by_exten_locked (const char *exten, const char *context) |
Get channel by exten (and optionally context) and lock it. | |
struct ast_channel * | ast_get_channel_by_name_locked (const char *chan) |
Get channel by name or uniqueid (locks channel) | |
struct ast_channel * | ast_get_channel_by_name_prefix_locked (const char *name, const int namelen) |
Get channel by name or uniqueid prefix (locks channel) | |
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_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) |
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. | |
struct ast_channel * | ast_request (const char *type, int format, void *data, int *status) |
Requests a channel. | |
struct ast_channel * | ast_request_and_dial (const char *type, int format, 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 Send a DTMF digit to a channel. | |
int | ast_senddigit_begin (struct ast_channel *chan, char digit) |
Send a DTMF digit to a channel 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. | |
int | ast_set_read_format (struct ast_channel *chan, int 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, int format) |
Sets write format on channel chan Set write format for channel to whichever component of "format" is best. | |
int | ast_setstate (struct ast_channel *chan, enum ast_channel_state) |
Change the state of a channel. | |
int | ast_settimeout (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data) |
Enable or disable timer ticks for a channel. | |
int | ast_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 a symbolic hangup cause to number. | |
int | ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
int | ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
void | ast_tonepair_stop (struct ast_channel *chan) |
int | ast_transfer (struct ast_channel *chan, char *dest) |
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested. | |
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 This version works on fd's only. Be careful with it. | |
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. | |
struct ast_channel * | ast_walk_channel_by_exten_locked (const struct ast_channel *chan, const char *exten, const char *context) |
Get next channel by exten (and optionally context) and lock it. | |
struct ast_channel * | ast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen) |
Get channel by name or uniqueid prefix (locks channel) | |
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. | |
Variables | |
unsigned long | global_fin |
unsigned long | global_fout |
General Asterisk PBX channel definitions.
Definition in file channel.h.
#define AST_AGENT_FD (AST_MAX_FDS-3) |
used by agents for pass through
Definition at line 160 of file channel.h.
Referenced by agent_read().
#define AST_ALERT_FD (AST_MAX_FDS-1) |
used for alertpipe
Definition at line 158 of file channel.h.
Referenced by __ast_channel_alloc_ap().
#define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0) |
Report DTMF on channel 0.
Definition at line 1456 of file channel.h.
Referenced by ast_generic_bridge(), ast_rtp_bridge(), bridge_native_loop(), bridge_p2p_loop(), dahdi_bridge(), iax2_bridge(), misdn_bridge(), and set_config_flags().
#define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1) |
Report DTMF on channel 1.
Definition at line 1458 of file channel.h.
Referenced by ast_generic_bridge(), ast_rtp_bridge(), bridge_native_loop(), bridge_p2p_loop(), dahdi_bridge(), iax2_bridge(), misdn_bridge(), and set_config_flags().
#define AST_BRIDGE_IGNORE_SIGS (1 << 4) |
Ignore all signal frames except NULL.
Definition at line 1464 of file channel.h.
Referenced by ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), and iax2_bridge().
#define AST_BRIDGE_REC_CHANNEL_0 (1 << 2) |
#define AST_BRIDGE_REC_CHANNEL_1 (1 << 3) |
#define AST_CHAN_WRITE_INFO_T_VERSION 1 |
ast_chan_write_info_t version. Must be incremented if structure is changed
Definition at line 222 of file channel.h.
Referenced by func_channel_write(), and local_setoption().
#define AST_CHANNEL_NAME 80 |
Max length of an ast_channel name
Definition at line 136 of file channel.h.
Referenced by ast_channel_free(), ast_do_masquerade(), ast_parse_device_state(), ast_setstate(), common_exec(), create_jb(), fast_originate(), page_exec(), park_call_full(), and softhangup_exec().
#define AST_GENERATOR_FD (AST_MAX_FDS-4) |
used by generator
Definition at line 161 of file channel.h.
Referenced by __ast_read(), ast_deactivate_generator(), and ast_do_masquerade().
#define AST_MAX_CONTEXT 80 |
Max length of a context
Definition at line 135 of file channel.h.
Referenced by _macro_exec(), cleanup_stale_contexts(), common_exec(), conf_run(), config_parse_variables(), dial_transfer(), do_magic_pickup(), gtalk_load_config(), handle_gosub(), handle_request_invite(), reload_config(), and try_calling().
#define AST_MAX_EXTENSION 80 |
Max length of an extension
Definition at line 134 of file channel.h.
Referenced by add_extensions(), advanced_options(), ast_bridge_call(), ast_device_state_changed(), ast_devstate_changed(), ast_ivr_menu_run_internal(), begin_dial_channel(), build_device(), conf_run(), destroy_station(), dial_exec_full(), dial_transfer(), disa_exec(), do_forward(), do_magic_pickup(), dundi_lookup_local(), feature_attended_transfer(), feature_blind_transfer(), find_conf_realtime(), forward_message(), function_enum(), get_destination(), handle_gosub(), handle_request_invite(), load_config(), load_module(), log_exec(), manage_parkinglot(), manager_show_dialplan_helper(), mgcp_ss(), park_add_hints(), park_call_exec(), phone_check_exception(), process_dahdi(), realtime_switch_common(), search_directory_sub(), show_dialplan_helper(), skinny_extensionstate_cb(), skinny_ss(), sla_build_station(), speech_background(), ss_thread(), transmit_state_notify(), try_calling(), vm_authenticate(), and vmauthenticate().
#define AST_MAX_FDS 10 |
Definition at line 153 of file channel.h.
Referenced by __ast_channel_alloc_ap(), ast_channel_free(), ast_do_masquerade(), ast_poll_channel_add(), ast_poll_channel_del(), ast_waitfor_nandfds(), and manage_parkinglot().
#define AST_TIMING_FD (AST_MAX_FDS-2) |
used for timingfd
Definition at line 159 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 1812 of file channel.h.
Referenced by ast_sendtext(), ast_waitfor_nandfds(), ast_write(), dahdi_read(), and phone_read().
#define DATASTORE_INHERIT_FOREVER INT_MAX |
Definition at line 151 of file channel.h.
Referenced by _macro_exec(), acf_iaxvar_write(), add_features_datastores(), ast_channel_datastore_inherit(), ast_iax2_new(), authenticate_reply(), dial_exec_full(), socket_process(), and try_calling().
#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 352 of file channel.h.
Referenced by __ast_read(), ast_write(), handle_core_set_debug_channel(), handle_showchan(), and serialize_showchan().
#define FRAMECOUNT_INC | ( | x | ) | ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) ) |
Definition at line 355 of file channel.h.
Referenced by __ast_read(), and ast_write().
#define MAX_LANGUAGE 20 |
#define MAX_MUSICCLASS 80 |
typedef int(* ast_acf_read_fn_t)(struct ast_channel *, const char *, char *, char *, size_t) |
typedef int(* ast_acf_write_fn_t)(struct ast_channel *, const char *, char *, const char *) |
typedef unsigned long long ast_group_t |
anonymous enum |
ast_channel_tech Properties
Definition at line 529 of file channel.h.
{ /*! \brief Channels have this property if they can accept input with jitter; * i.e. most VoIP channels */ AST_CHAN_TP_WANTSJITTER = (1 << 0), /*! \brief Channels have this property if they can create jitter; * i.e. most VoIP channels */ AST_CHAN_TP_CREATESJITTER = (1 << 1), };
anonymous enum |
ast_channel flags
Definition at line 539 of file channel.h.
{ /*! Queue incoming dtmf, to be released when this flag is turned off */ AST_FLAG_DEFER_DTMF = (1 << 1), /*! write should be interrupt generator */ AST_FLAG_WRITE_INT = (1 << 2), /*! a thread is blocking on this channel */ AST_FLAG_BLOCKING = (1 << 3), /*! This is a zombie channel */ AST_FLAG_ZOMBIE = (1 << 4), /*! There is an exception pending */ AST_FLAG_EXCEPTION = (1 << 5), /*! Listening to moh XXX anthm promises me this will disappear XXX */ AST_FLAG_MOH = (1 << 6), /*! This channel is spying on another channel */ AST_FLAG_SPYING = (1 << 7), /*! This channel is in a native bridge */ AST_FLAG_NBRIDGE = (1 << 8), /*! 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_IN_AUTOLOOP = (1 << 9), /*! This is an outgoing call */ AST_FLAG_OUTGOING = (1 << 10), /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */ AST_FLAG_IN_DTMF = (1 << 12), /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is * currently being emulated */ AST_FLAG_EMULATE_DTMF = (1 << 13), /*! This is set to tell the channel not to generate DTMF begin frames, and * to instead only generate END frames. */ AST_FLAG_END_DTMF_ONLY = (1 << 14), /*! Flag to show channels that this call is hangup due to the fact that the call was indeed anwered, but in another channel */ AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), /*! This flag indicates that on a masquerade, an active stream should not * be carried over */ AST_FLAG_MASQ_NOSTREAM = (1 << 16), /*! 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_RUN = (1 << 17), /*! 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_BRIDGE_HANGUP_DONT = (1 << 18), /*! This flag indicates whether the channel is in the channel list or not. */ AST_FLAG_IN_CHANNEL_LIST = (1 << 19), /*! Disable certain workarounds. This reintroduces certain bugs, but allows * some non-traditional dialplans (like AGI) to continue to function. */ AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20), };
anonymous enum |
ast_bridge_config flags
Definition at line 593 of file channel.h.
{ 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), };
anonymous enum |
Definition at line 642 of file channel.h.
{ AST_CDR_TRANSFER = (1 << 0), AST_CDR_FORWARD = (1 << 1), AST_CDR_CALLWAIT = (1 << 2), AST_CDR_CONFERENCE = (1 << 3), };
anonymous enum |
Definition at line 649 of file channel.h.
{ /*! * Soft hangup requested by device or other internal reason. * Actual hangup needed. */ AST_SOFTHANGUP_DEV = (1 << 0), /*! * Used to break the normal frame flow so an async goto can be * done instead of actually hanging up. */ AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), /*! * Soft hangup requested by system shutdown. Actual hangup * needed. */ AST_SOFTHANGUP_SHUTDOWN = (1 << 2), /*! * Used to break the normal frame flow after a timeout so an * implicit async goto can be done to the 'T' exten if it exists * instead of actually hanging up. If the exten does not exist * then actually hangup. */ AST_SOFTHANGUP_TIMEOUT = (1 << 3), /*! * Soft hangup requested by application/channel-driver being * unloaded. Actual hangup needed. */ AST_SOFTHANGUP_APPUNLOAD = (1 << 4), /*! * Soft hangup requested by non-associated party. Actual hangup * needed. */ AST_SOFTHANGUP_EXPLICIT = (1 << 5), /*! * Used to break a bridge so the channel can be spied upon * instead of actually hanging up. */ AST_SOFTHANGUP_UNBRIDGE = (1 << 6), /*! * \brief All softhangup flags. * * This can be used as an argument to ast_channel_softhangup_clear * to clear all softhangup flags from a channel. */ AST_SOFTHANGUP_ALL = (0xFFFFFFFF) };
enum ast_bridge_result |
Definition at line 163 of file channel.h.
{ AST_BRIDGE_COMPLETE = 0, AST_BRIDGE_FAILED = -1, AST_BRIDGE_FAILED_NOWARN = -2, AST_BRIDGE_RETRY = -3, };
enum ast_channel_adsicpe |
enum ast_channel_state |
ast_channel states
Definition at line 376 of file channel.h.
{ AST_STATE_DOWN, /*!< Channel is down and available */ AST_STATE_RESERVED, /*!< Channel is down, but reserved */ AST_STATE_OFFHOOK, /*!< Channel is off hook */ AST_STATE_DIALING, /*!< Digits (or equivalent) have been dialed */ AST_STATE_RING, /*!< Line is ringing */ AST_STATE_RINGING, /*!< Remote end is ringing */ AST_STATE_UP, /*!< Line is up */ AST_STATE_BUSY, /*!< Line is busy */ AST_STATE_DIALING_OFFHOOK, /*!< Digits (or equivalent) have been dialed while offhook */ AST_STATE_PRERING, /*!< Channel has detected an incoming call and is waiting for ring */ AST_STATE_MUTE = (1 << 16), /*!< Do not transmit voice data */ };
enum ast_t38_state |
Possible T38 states on channels.
Definition at line 394 of file channel.h.
{ 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 */ };
enum channelreloadreason |
Channel reload reasons for manager events at load or reload of configuration.
int __ast_answer | ( | struct ast_channel * | chan, |
unsigned int | delay, | ||
int | cdr_answer | ||
) |
Answer a channel, with a selectable delay before returning.
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.
0 | on success |
non-zero | on failure |
Definition at line 1970 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, LOG_WARNING, MAX, ast_channel::name, and ast_frame::subclass.
Referenced by ast_answer(), dial_exec_full(), pbx_builtin_answer(), and pbx_builtin_incomplete().
{ int res = 0; enum ast_channel_state old_state; old_state = chan->_state; if ((res = ast_raw_answer(chan, cdr_answer))) { return res; } switch (old_state) { case AST_STATE_RINGING: case AST_STATE_RING: /* wait for media to start flowing, but don't wait any longer * than 'delay' or 500 milliseconds, whichever is longer */ do { AST_LIST_HEAD_NOLOCK(, ast_frame) frames; struct ast_frame *cur, *new; int ms = MAX(delay, 500); unsigned int done = 0; AST_LIST_HEAD_INIT_NOLOCK(&frames); for (;;) { ms = ast_waitfor(chan, ms); if (ms < 0) { ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno)); res = -1; break; } if (ms == 0) { ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500)); break; } cur = ast_read(chan); if (!cur || ((cur->frametype == AST_FRAME_CONTROL) && (cur->subclass == AST_CONTROL_HANGUP))) { if (cur) { ast_frfree(cur); } res = -1; ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name); break; } if ((new = ast_frisolate(cur)) != cur) { ast_frfree(cur); } AST_LIST_INSERT_HEAD(&frames, new, frame_list); /* if a specific delay period was requested, continue * until that delay has passed. don't stop just because * incoming media has arrived. */ if (delay) { continue; } switch (new->frametype) { /* all of these frametypes qualify as 'media' */ case AST_FRAME_VOICE: case AST_FRAME_VIDEO: case AST_FRAME_TEXT: case AST_FRAME_DTMF_BEGIN: case AST_FRAME_DTMF_END: case AST_FRAME_IMAGE: case AST_FRAME_HTML: case AST_FRAME_MODEM: done = 1; break; case AST_FRAME_CONTROL: case AST_FRAME_IAX: case AST_FRAME_NULL: case AST_FRAME_CNG: break; } if (done) { break; } } if (res == 0) { ast_channel_lock(chan); while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) { ast_queue_frame_head(chan, cur); ast_frfree(cur); } ast_channel_unlock(chan); } } while (0); break; default: break; } return res; }
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 int | amaflag, | ||
const char * | file, | ||
int | line, | ||
const char * | function, | ||
const char * | name_fmt, | ||
... | |||
) | [read] |
Create a channel structure.
NULL | failure |
non-NULL | successfully allocated channel |
Definition at line 984 of file channel.c.
References __ast_channel_alloc_ap().
{ va_list ap1, ap2; struct ast_channel *result; va_start(ap1, name_fmt); va_start(ap2, name_fmt); result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, amaflag, file, line, function, name_fmt, ap1, ap2); va_end(ap1); va_end(ap2); return result; }
struct ast_channel* __ast_request_and_dial | ( | const char * | type, |
int | format, | ||
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.
type | type of channel to request |
format | requested channel format |
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 |
Definition at line 4158 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_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, 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_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, chanlist::chan, outgoing_helper::cid_name, outgoing_helper::cid_num, ast_channel::context, outgoing_helper::context, ast_channel::exten, outgoing_helper::exten, f, ast_frame::frametype, handle_cause(), ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, ast_channel::priority, outgoing_helper::priority, ast_frame::subclass, and outgoing_helper::vars.
Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().
{ int dummy_outstate; int cause = 0; struct ast_channel *chan; int res = 0; int last_subclass = 0; if (outstate) *outstate = 0; else outstate = &dummy_outstate; /* make outstate always a valid pointer */ chan = ast_request(type, format, data, &cause); if (!chan) { ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data); handle_cause(cause, outstate); return NULL; } if (oh) { if (oh->vars) ast_set_variables(chan, oh->vars); /* XXX why is this necessary, for the parent_channel perhaps ? */ if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); if (oh->parent_channel) { ast_channel_inherit_variables(oh->parent_channel, chan); ast_channel_datastore_inherit(oh->parent_channel, chan); } if (oh->account) ast_cdr_setaccount(chan, oh->account); } ast_set_callerid(chan, cid_num, cid_name, cid_num); ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED); if (ast_call(chan, data, 0)) { /* ast_call failed... */ ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data); } else { res = 1; /* mark success in case chan->_state is already AST_STATE_UP */ while (timeout && chan->_state != AST_STATE_UP) { struct ast_frame *f; res = ast_waitfor(chan, timeout); if (res == 0) { /* timeout, treat it like ringing */ *outstate = AST_CONTROL_RINGING; break; } if (res < 0) /* error or done */ break; if (timeout > -1) timeout = res; if (!ast_strlen_zero(chan->call_forward)) { if (!(chan = ast_call_forward(NULL, chan, NULL, format, oh, outstate))) { return NULL; } continue; } f = ast_read(chan); if (!f) { *outstate = AST_CONTROL_HANGUP; res = 0; break; } if (f->frametype == AST_FRAME_CONTROL) { switch (f->subclass) { case AST_CONTROL_RINGING: /* record but keep going */ *outstate = f->subclass; break; case AST_CONTROL_BUSY: ast_cdr_busy(chan->cdr); *outstate = f->subclass; timeout = 0; break; case AST_CONTROL_CONGESTION: ast_cdr_failed(chan->cdr); *outstate = f->subclass; timeout = 0; break; case AST_CONTROL_ANSWER: ast_cdr_answer(chan->cdr); *outstate = f->subclass; timeout = 0; /* trick to force exit from the while() */ break; /* Ignore these */ case AST_CONTROL_PROGRESS: case AST_CONTROL_PROCEEDING: case AST_CONTROL_HOLD: case AST_CONTROL_UNHOLD: case AST_CONTROL_VIDUPDATE: case AST_CONTROL_SRCUPDATE: case AST_CONTROL_SRCCHANGE: case -1: /* Ignore -- just stopping indications */ break; default: ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass); } last_subclass = f->subclass; } ast_frfree(f); } } /* Final fixups */ if (oh) { if (!ast_strlen_zero(oh->context)) ast_copy_string(chan->context, oh->context, sizeof(chan->context)); if (!ast_strlen_zero(oh->exten)) ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten)); if (oh->priority) chan->priority = oh->priority; } if (chan->_state == AST_STATE_UP) *outstate = AST_CONTROL_ANSWER; if (res <= 0) { if ( AST_CONTROL_RINGING == last_subclass ) chan->hangupcause = AST_CAUSE_NO_ANSWER; if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) ast_cdr_init(chan->cdr, chan); if (chan->cdr) { char tmp[256]; snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data); ast_cdr_setapp(chan->cdr,"Dial",tmp); ast_cdr_update(chan); ast_cdr_start(chan->cdr); ast_cdr_end(chan->cdr); /* If the cause wasn't handled properly */ if (ast_cdr_disposition(chan->cdr,chan->hangupcause)) ast_cdr_failed(chan->cdr); } ast_hangup(chan); chan = NULL; } return chan; }
int ast_activate_generator | ( | struct ast_channel * | chan, |
struct ast_generator * | gen, | ||
void * | params | ||
) |
Activate a given generator
Definition at line 2121 of file channel.c.
References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), gen, 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().
{ int res = 0; ast_channel_lock(chan); if (chan->generatordata) { if (chan->generator && chan->generator->release) chan->generator->release(chan, chan->generatordata); chan->generatordata = NULL; } if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) { res = -1; } if (!res) { ast_settimeout(chan, 50, generator_force, chan); chan->generator = gen; } ast_channel_unlock(chan); ast_prod(chan); return res; }
int ast_active_channels | ( | void | ) |
returns number of active/allocated channels
Returns number of active/allocated channels
Definition at line 497 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by action_corestatus(), ast_var_channels(), ast_var_channels_table(), dahdi_restart(), handle_show_settings(), and quit_handler().
{ struct ast_channel *c; int cnt = 0; AST_RWLIST_RDLOCK(&channels); AST_RWLIST_TRAVERSE(&channels, c, chan_list) cnt++; AST_RWLIST_UNLOCK(&channels); return cnt; }
static int ast_add_fd | ( | struct pollfd * | pfd, |
int | fd | ||
) | [inline, static] |
if fd is a valid descriptor, set *pfd with the descriptor
Definition at line 1775 of file channel.h.
Referenced by ast_waitfor_nandfds().
{
pfd->fd = fd;
pfd->events = POLLIN | POLLPRI;
return fd >= 0;
}
int ast_answer | ( | struct ast_channel * | chan | ) |
Answer a channel.
chan | channel to answer |
This function answers a channel and handles all necessary call setup functions.
0 | on success |
non-zero | on failure |
Definition at line 2071 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(), builtin_parkcall(), common_exec(), conf_exec(), count_exec(), dahdiras_exec(), 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(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), readexten_exec(), record_exec(), rpt_exec(), sayunixtime_exec(), send_waveform_to_channel(), setup_privacy_args(), skel_exec(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), transmit(), vm_exec(), vm_execmain(), waitfor_exec(), and zapateller_exec().
{ return __ast_answer(chan, 0, 1); }
int ast_autoservice_ignore | ( | struct ast_channel * | chan, |
enum ast_frame_type | ftype | ||
) |
Ignore certain frame types.
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_automixmonitor(), builtin_blindtransfer(), feature_exec_app(), and play_message_in_bridged_call().
{ struct asent *as; int res = -1; AST_LIST_LOCK(&aslist); AST_LIST_TRAVERSE(&aslist, as, list) { if (as->chan == chan) { res = 0; as->ignore_frame_types |= (1 << ftype); break; } } AST_LIST_UNLOCK(&aslist); return res; }
int ast_autoservice_start | ( | struct ast_channel * | chan | ) |
Automatically service a channel for us...
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_exec(), acf_odbc_read(), acf_odbc_write(), 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(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), system_exec_helper(), try_calling(), and trylock_read().
{ int res = 0; struct asent *as; AST_LIST_LOCK(&aslist); AST_LIST_TRAVERSE(&aslist, as, list) { if (as->chan == chan) { as->use_count++; break; } } AST_LIST_UNLOCK(&aslist); if (as) { /* Entry exists, autoservice is already handling this channel */ return 0; } if (!(as = ast_calloc(1, sizeof(*as)))) return -1; /* New entry created */ as->chan = chan; as->use_count = 1; ast_channel_lock(chan); as->orig_end_dtmf_flag = ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY) ? 1 : 0; if (!as->orig_end_dtmf_flag) ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY); ast_channel_unlock(chan); AST_LIST_LOCK(&aslist); if (AST_LIST_EMPTY(&aslist) && asthread != AST_PTHREADT_NULL) { ast_cond_signal(&as_cond); } AST_LIST_INSERT_HEAD(&aslist, as, list); if (asthread == AST_PTHREADT_NULL) { /* need start the thread */ if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) { ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n"); /* There will only be a single member in the list at this point, the one we just added. */ AST_LIST_REMOVE(&aslist, as, list); free(as); asthread = AST_PTHREADT_NULL; res = -1; } else { pthread_kill(asthread, SIGURG); } } AST_LIST_UNLOCK(&aslist); return res; }
int ast_autoservice_stop | ( | struct ast_channel * | chan | ) |
Stop servicing a channel for us...
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_exec(), acf_odbc_read(), acf_odbc_write(), array(), 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(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), system_exec_helper(), try_calling(), and trylock_read().
{ int res = -1; struct asent *as, *removed = NULL; struct ast_frame *f; int chan_list_state; AST_LIST_LOCK(&aslist); /* Save the autoservice channel list state. We _must_ verify that the channel * list has been rebuilt before we return. Because, after we return, the channel * could get destroyed and we don't want our poor autoservice thread to step on * it after its gone! */ chan_list_state = as_chan_list_state; /* Find the entry, but do not free it because it still can be in the autoservice thread array */ AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) { if (as->chan == chan) { as->use_count--; if (as->use_count < 1) { AST_LIST_REMOVE_CURRENT(list); removed = as; } break; } } AST_LIST_TRAVERSE_SAFE_END; if (removed && asthread != AST_PTHREADT_NULL) { pthread_kill(asthread, SIGURG); } AST_LIST_UNLOCK(&aslist); if (!removed) { return 0; } /* Wait while autoservice thread rebuilds its list. */ while (chan_list_state == as_chan_list_state) { usleep(1000); } /* Now autoservice thread should have no references to our entry and we can safely destroy it */ if (!chan->_softhangup) { res = 0; } if (!as->orig_end_dtmf_flag) { ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY); } ast_channel_lock(chan); while ((f = AST_LIST_REMOVE_HEAD(&as->deferred_frames, frame_list))) { if (!((1 << f->frametype) & as->ignore_frame_types)) { ast_queue_frame_head(chan, f); } ast_frfree(f); } ast_channel_unlock(chan); free(as); return res; }
void ast_begin_shutdown | ( | int | hangup | ) |
Initiate system shutdown.
Initiate system shutdown -- prevents new channels from being allocated. If "hangup" is non-zero, all existing channels will receive soft hangups
Definition at line 483 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.
Referenced by quit_handler().
{ struct ast_channel *c; shutting_down = 1; if (hangup) { AST_RWLIST_RDLOCK(&channels); AST_RWLIST_TRAVERSE(&channels, c, chan_list) { ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN); } AST_RWLIST_UNLOCK(&channels); } }
int ast_best_codec | ( | int | fmts | ) |
Pick the best audio codec.
Pick the best codec
Okay, ulaw is used by all telephony equipment, so start with it
Unless of course, you're a silly European, so then prefer ALAW
G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority
Okay, well, signed linear is easy to translate into other stuff
G.726 is standard ADPCM, in RFC3551 packing order
G.726 is standard ADPCM, in AAL2 packing order
ADPCM has great sound quality and is still pretty easy to translate
Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good
iLBC is not too bad
Speex is free, but computationally more expensive than GSM
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 711 of file channel.c.
References ARRAY_LEN, AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_AUDIO_MASK, 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_ULAW, 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(), sip_new(), skinny_new(), skinny_set_rtp_peer(), socket_process(), start_rtp(), transmit_connect(), and unistim_new().
{ /* This just our opinion, expressed in code. We are asked to choose the best codec to use, given no information */ int x; static const int prefs[] = { /*! Okay, ulaw is used by all telephony equipment, so start with it */ AST_FORMAT_ULAW, /*! Unless of course, you're a silly European, so then prefer ALAW */ AST_FORMAT_ALAW, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */ AST_FORMAT_G722, /*! Okay, well, signed linear is easy to translate into other stuff */ AST_FORMAT_SLINEAR16, AST_FORMAT_SLINEAR, /*! G.726 is standard ADPCM, in RFC3551 packing order */ AST_FORMAT_G726, /*! G.726 is standard ADPCM, in AAL2 packing order */ AST_FORMAT_G726_AAL2, /*! ADPCM has great sound quality and is still pretty easy to translate */ AST_FORMAT_ADPCM, /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good */ AST_FORMAT_GSM, /*! iLBC is not too bad */ AST_FORMAT_ILBC, /*! Speex is free, but computationally more expensive than GSM */ AST_FORMAT_SPEEX, /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it */ AST_FORMAT_LPC10, /*! G.729a is faster than 723 and slightly less expensive */ AST_FORMAT_G729A, /*! Down to G.723.1 which is proprietary but at least designed for voice */ AST_FORMAT_G723_1, }; /* Strip out video */ fmts &= AST_FORMAT_AUDIO_MASK; /* Find the first preferred codec in the format given */ for (x = 0; x < ARRAY_LEN(prefs); x++) { if (fmts & prefs[x]) return prefs[x]; } ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts); return 0; }
struct ast_channel* ast_bridged_channel | ( | struct ast_channel * | chan | ) | [read] |
Find bridged channel.
chan | Current channel |
Definition at line 5088 of file channel.c.
References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.
Referenced by __ast_read(), __dahdi_exception(), _skinny_show_lines(), action_agents(), action_coreshowchannels(), agents_show(), agents_show_online(), ast_bridge_call(), ast_channel_masquerade(), ast_do_masquerade(), ast_rtp_set_vars(), 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(), 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(), park_call_full(), schedule_delivery(), sip_hangup(), sip_set_rtp_peer(), skinny_transfer(), socket_process(), ss_thread(), start_spying(), startmon(), TransferCallStep1(), and unistim_hangup().
{ struct ast_channel *bridged; bridged = chan->_bridge; if (bridged && bridged->tech->bridged_channel) bridged = bridged->tech->bridged_channel(chan, bridged); return bridged; }
int ast_call | ( | struct ast_channel * | chan, |
char * | addr, | ||
int | timeout | ||
) |
Make a call.
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. |
Definition at line 4361 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(), agent_call(), ast_call_forward(), attempt_reconnect(), begin_dial_channel(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_exec(), and wait_for_answer().
{ /* Place an outgoing call, but don't wait any longer than timeout ms before returning. If the remote end does not answer within the timeout, then do NOT hang up, but return anyway. */ int res = -1; /* Stop if we're a zombie or need a soft hangup */ ast_channel_lock(chan); if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { if (chan->cdr) { ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED); } if (chan->tech->call) res = chan->tech->call(chan, addr, timeout); ast_set_flag(chan, AST_FLAG_OUTGOING); } ast_channel_unlock(chan); return res; }
struct ast_channel* ast_call_forward | ( | struct ast_channel * | caller, |
struct ast_channel * | orig, | ||
int * | timeout, | ||
int | 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.
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) |
Definition at line 4081 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_trylock, ast_channel_unlock, ast_copy_flags, ast_copy_string(), ast_hangup(), ast_log(), ast_request(), ast_set_callerid(), ast_set_variables(), ast_string_field_set, ast_strlen_zero(), ast_channel::call_forward, cause, ast_channel::cdr, CHANNEL_DEADLOCK_AVOIDANCE, ast_channel::cid, ast_callerid::cid_name, outgoing_helper::cid_name, ast_callerid::cid_num, outgoing_helper::cid_num, ast_channel::context, ast_channel::data, handle_cause(), LOG_NOTICE, outgoing_helper::parent_channel, pbx_builtin_getvar_helper(), S_OR, type, and outgoing_helper::vars.
Referenced by __ast_request_and_dial(), and feature_request_and_dial().
{ char tmpchan[256]; struct ast_channel *new = NULL; char *data, *type; int cause = 0; int res; /* gather data and request the new forward channel */ ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan)); if ((data = strchr(tmpchan, '/'))) { *data++ = '\0'; type = tmpchan; } else { const char *forward_context; ast_channel_lock(orig); forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT"); snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context)); ast_channel_unlock(orig); data = tmpchan; type = "Local"; } if (!(new = ast_request(type, format, data, &cause))) { ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause); handle_cause(cause, outstate); ast_hangup(orig); return NULL; } /* Copy/inherit important information into new channel */ if (oh) { if (oh->vars) { ast_set_variables(new, oh->vars); } if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) { ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num); } if (oh->parent_channel) { ast_channel_inherit_variables(oh->parent_channel, new); ast_channel_datastore_inherit(oh->parent_channel, new); } if (oh->account) { ast_cdr_setaccount(new, oh->account); } } else if (caller) { /* no outgoing helper so use caller if avaliable */ ast_channel_inherit_variables(caller, new); ast_channel_datastore_inherit(caller, new); } ast_channel_lock(orig); while (ast_channel_trylock(new)) { CHANNEL_DEADLOCK_AVOIDANCE(orig); } ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED); ast_string_field_set(new, accountcode, orig->accountcode); if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) { ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num); } ast_channel_unlock(new); ast_channel_unlock(orig); /* call new channel */ res = ast_call(new, data, 0); if (timeout) { *timeout = res; } if (res) { ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data); ast_hangup(orig); ast_hangup(new); return NULL; } ast_hangup(orig); return new; }
void ast_cancel_shutdown | ( | void | ) |
Cancel a shutdown in progress.
Cancels an existing shutdown and returns to normal operation
Definition at line 509 of file channel.c.
Referenced by handle_abort_shutdown().
{ shutting_down = 0; }
const char* ast_cause2str | ( | int | state | ) |
Gives the string form of a given hangup cause.
Gives the string form of a given cause code
state | cause to get the description of Give a name to a cause code Returns the text form of the binary cause code given |
Definition at line 629 of file channel.c.
References ARRAY_LEN, and causes.
Referenced by __transmit_response(), ast_do_masquerade(), ast_hangup(), dial_exec_full(), findmeexec(), sip_hangup(), and transmit_request_with_auth().
void ast_change_name | ( | struct ast_channel * | chan, |
char * | newname | ||
) |
Change channel name.
Definition at line 4638 of file channel.c.
References ast_string_field_set, EVENT_FLAG_CALL, manager_event, name, ast_channel::name, and ast_channel::uniqueid.
Referenced by update_name().
{ manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid); ast_string_field_set(chan, name, newname); }
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.
Bridge two channels together
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 5413 of file channel.c.
References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_clear_softhangup(), ast_channel_make_compatible(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCUPDATE, ast_debug, AST_FEATURE_PLAY_WARNING, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_generic_bridge(), ast_indicate(), ast_log(), ast_samp2tv(), ast_set_flag, 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::cid, ast_callerid::cid_num, ast_bridge_config::end_sound, EVENT_FLAG_CALL, ast_bridge_config::feature_timer, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::firstpass, ast_bridge_config::flags, ast_channel::generator, LOG_WARNING, manager_bridge_event(), manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_bridge_config::play_warning, ast_channel::readformat, ast_channel_tech::send_digit_begin, ast_bridge_config::start_sound, ast_bridge_config::start_time, ast_channel::tech, ast_bridge_config::timelimit, ast_channel::uniqueid, update_bridge_vars(), ast_bridge_config::warning_freq, ast_bridge_config::warning_sound, and ast_channel::writeformat.
Referenced by ast_bridge_call().
{ enum ast_bridge_result res = AST_BRIDGE_COMPLETE; int nativefailed=0; int firstpass; int o0nativeformats; int o1nativeformats; long time_left_ms=0; char caller_warning = 0; char callee_warning = 0; if (c0->_bridge) { ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", c0->name, c0->_bridge->name); return -1; } if (c1->_bridge) { ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", c1->name, c1->_bridge->name); return -1; } /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) return -1; *fo = NULL; firstpass = config->firstpass; config->firstpass = 0; if (ast_tvzero(config->start_time)) config->start_time = ast_tvnow(); time_left_ms = config->timelimit; caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING); callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING); if (config->start_sound && firstpass) { if (caller_warning) bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000); if (callee_warning) bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000); } /* Keep track of bridge */ c0->_bridge = c1; c1->_bridge = c0; o0nativeformats = c0->nativeformats; o1nativeformats = c1->nativeformats; if (config->feature_timer && !ast_tvzero(config->nexteventts)) { config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000)); } else if (config->timelimit && firstpass) { config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); if (caller_warning || callee_warning) config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000)); } if (!c0->tech->send_digit_begin) ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY); if (!c1->tech->send_digit_begin) ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); manager_bridge_event(1, 1, c0, c1); /* Before we enter in and bridge these two together tell them both the source of audio has changed */ ast_indicate(c0, AST_CONTROL_SRCUPDATE); ast_indicate(c1, AST_CONTROL_SRCUPDATE); for (/* ever */;;) { struct timeval now = { 0, }; int to; to = -1; if (!ast_tvzero(config->nexteventts)) { now = ast_tvnow(); to = ast_tvdiff_ms(config->nexteventts, now); if (to <= 0) { if (!config->timelimit) { res = AST_BRIDGE_COMPLETE; break; } to = 0; } } if (config->timelimit) { time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time); if (time_left_ms < to) to = time_left_ms; if (time_left_ms <= 0) { if (caller_warning && config->end_sound) bridge_playfile(c0, c1, config->end_sound, 0); if (callee_warning && config->end_sound) bridge_playfile(c1, c0, config->end_sound, 0); *fo = NULL; res = 0; break; } if (!to) { if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) { int t = (time_left_ms + 500) / 1000; /* round to nearest second */ if (caller_warning) bridge_playfile(c0, c1, config->warning_sound, t); if (callee_warning) bridge_playfile(c1, c0, config->warning_sound, t); } if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000)); else config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); } ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE); } if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */ if (c0->_softhangup & AST_SOFTHANGUP_UNBRIDGE) { ast_channel_clear_softhangup(c0, AST_SOFTHANGUP_UNBRIDGE); } if (c1->_softhangup & AST_SOFTHANGUP_UNBRIDGE) { ast_channel_clear_softhangup(c1, AST_SOFTHANGUP_UNBRIDGE); } c0->_bridge = c1; c1->_bridge = c0; ast_debug(1, "Unbridge signal received. Ending native bridge.\n"); continue; } /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { *fo = NULL; res = 0; ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n", c0->name, c1->name, ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No", ast_check_hangup(c0) ? "Yes" : "No", ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No", ast_check_hangup(c1) ? "Yes" : "No"); break; } update_bridge_vars(c0, c1); bridge_play_sounds(c0, c1); if (c0->tech->bridge && /* if < 1 ms remains use generic bridging for accurate timing */ (!config->timelimit || to > 1000 || to == 0) && (c0->tech->bridge == c1->tech->bridge) && !nativefailed && !c0->monitor && !c1->monitor && !c0->audiohooks && !c1->audiohooks && !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) { int timeoutms = to - 1000 > 0 ? to - 1000 : to; /* Looks like they share a bridge method and nothing else is in the way */ ast_set_flag(c0, AST_FLAG_NBRIDGE); ast_set_flag(c1, AST_FLAG_NBRIDGE); if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) { /* \todo XXX here should check that cid_num is not NULL */ manager_event(EVENT_FLAG_CALL, "Unlink", "Channel1: %s\r\n" "Channel2: %s\r\n" "Uniqueid1: %s\r\n" "Uniqueid2: %s\r\n" "CallerID1: %s\r\n" "CallerID2: %s\r\n", c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name); ast_clear_flag(c0, AST_FLAG_NBRIDGE); ast_clear_flag(c1, AST_FLAG_NBRIDGE); if ((c0->_softhangup | c1->_softhangup) & AST_SOFTHANGUP_UNBRIDGE) {/* Bit operators are intentional. */ continue; } c0->_bridge = NULL; c1->_bridge = NULL; return res; } else { ast_clear_flag(c0, AST_FLAG_NBRIDGE); ast_clear_flag(c1, AST_FLAG_NBRIDGE); } switch (res) { case AST_BRIDGE_RETRY: if (config->play_warning) { ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); } continue; default: ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name); /* fallthrough */ case AST_BRIDGE_FAILED_NOWARN: nativefailed++; break; } } if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && !(c0->generator || c1->generator)) { if (ast_channel_make_compatible(c0, c1)) { ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name); manager_bridge_event(0, 1, c0, c1); return AST_BRIDGE_FAILED; } o0nativeformats = c0->nativeformats; o1nativeformats = c1->nativeformats; } update_bridge_vars(c0, c1); res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts); if (res != AST_BRIDGE_RETRY) { break; } else if (config->feature_timer) { /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */ break; } } ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY); ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY); /* Now that we have broken the bridge the source will change yet again */ ast_indicate(c0, AST_CONTROL_SRCUPDATE); ast_indicate(c1, AST_CONTROL_SRCUPDATE); c0->_bridge = NULL; c1->_bridge = NULL; /* \todo XXX here should check that cid_num is not NULL */ manager_event(EVENT_FLAG_CALL, "Unlink", "Channel1: %s\r\n" "Channel2: %s\r\n" "Uniqueid1: %s\r\n" "Uniqueid2: %s\r\n" "CallerID1: %s\r\n" "CallerID2: %s\r\n", c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name); return res; }
void ast_channel_clear_softhangup | ( | struct ast_channel * | chan, |
int | flag | ||
) |
Clear a set of softhangup flags from a channel.
Never clear a softhangup flag from a channel directly. Instead, use this function. This ensures that all aspects of the softhangup process are aborted.
chan | the channel to clear the flag on |
flag | the flag or flags to clear |
Definition at line 1747 of file channel.c.
References ast_channel::_softhangup, ast_channel_lock, ast_channel_unlock, AST_CONTROL_END_OF_Q, AST_FRAME_CONTROL, ast_frfree, AST_LIST_LAST, AST_LIST_REMOVE, ast_frame::frametype, ast_channel::readq, and ast_frame::subclass.
Referenced by __ast_pbx_run(), ast_channel_bridge(), ast_generic_bridge(), check_goto_on_transfer(), and collect_digits().
{ ast_channel_lock(chan); chan->_softhangup &= ~flag; if (!chan->_softhangup) { struct ast_frame *fr; /* If we have completely cleared the softhangup flag, * then we need to fully abort the hangup process. This requires * pulling the END_OF_Q frame out of the channel frame queue if it * still happens to be there. */ fr = AST_LIST_LAST(&chan->readq); if (fr && fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_END_OF_Q) { AST_LIST_REMOVE(&chan->readq, fr, frame_list); ast_frfree(fr); } } ast_channel_unlock(chan); }
int ast_channel_cmpwhentohangup | ( | struct ast_channel * | chan, |
time_t | offset | ||
) |
Compare a offset with the settings of when to hang a channel up.
chan | channel on which to check for hang up |
offset | offset in seconds from current time |
Definition at line 550 of file channel.c.
References ast_channel_cmpwhentohangup_tv().
{ struct timeval when = { offset, }; return ast_channel_cmpwhentohangup_tv(chan, when); }
int ast_channel_cmpwhentohangup_tv | ( | struct ast_channel * | chan, |
struct timeval | offset | ||
) |
Compare a offset with the settings of when to hang a channel up.
chan | channel on which to check for hangup |
offset | offset in seconds and microseconds from current time |
Definition at line 535 of file channel.c.
References ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.
Referenced by ast_channel_cmpwhentohangup().
{ struct timeval whentohangup; if (ast_tvzero(chan->whentohangup)) return ast_tvzero(offset) ? 0 : -1; if (ast_tvzero(offset)) return 1; whentohangup = ast_tvadd(offset, ast_tvnow()); return ast_tvdiff_ms(whentohangup, chan->whentohangup); }
int ast_channel_datastore_add | ( | struct ast_channel * | chan, |
struct ast_datastore * | datastore | ||
) |
Add a datastore to a channel.
0 | success |
non-zero | failure |
Definition at line 1629 of file channel.c.
References AST_LIST_INSERT_HEAD, and ast_channel::datastores.
Referenced by _macro_exec(), acf_curlopt_write(), acf_iaxvar_write(), acf_odbc_read(), add_features_datastores(), add_to_agi(), apply_plc(), ast_iax2_new(), audiohook_volume_get(), authenticate_reply(), dial_exec_full(), dundi_query_read(), enable_jack_hook(), enum_query_read(), find_transaction(), get_lock(), gosub_exec(), lua_get_state(), pbx_builtin_raise_exception(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), shared_write(), smdi_msg_retrieve_read(), socket_process(), speech_create(), speex_write(), try_calling(), and volume_write().
{ int res = 0; AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry); return res; }
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.
Definition at line 1602 of file channel.c.
References ast_datastore_alloc().
{ return ast_datastore_alloc(info, uid); }
struct ast_datastore* ast_channel_datastore_find | ( | struct ast_channel * | chan, |
const struct ast_datastore_info * | info, | ||
const char * | uid | ||
) | [read] |
Find a datastore on a channel.
pointer | to the datastore if found |
NULL | if not found |
Definition at line 1643 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_exec(), acf_curlopt_read(), acf_curlopt_write(), acf_exception_read(), acf_fetch(), acf_iaxvar_read(), acf_iaxvar_write(), add_agi_cmd(), add_features_datastores(), add_to_agi(), apply_plc(), ast_odbc_retrieve_transaction_obj(), attended_transfer_occurred(), audiohook_volume_callback(), audiohook_volume_get(), builtin_atxfer(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), dundi_result_read(), enable_jack_hook(), enum_result_read(), exec_odbcfinish(), find_speech(), find_transaction(), func_inheritance_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(), mark_transaction_active(), park_exec_full(), pbx_builtin_raise_exception(), pop_exec(), queue_transfer_fixup(), release_transaction(), return_exec(), shared_read(), shared_write(), smdi_msg_read(), speech_background(), speech_destroy(), speex_callback(), speex_read(), speex_write(), stop_mixmonitor_exec(), try_calling(), unlock_read(), volume_callback(), and volume_write().
{ struct ast_datastore *datastore = NULL; if (info == NULL) return NULL; AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) { if (datastore->info != info) { continue; } if (uid == NULL) { /* matched by type only */ break; } if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) { /* Matched by type AND uid */ break; } } AST_LIST_TRAVERSE_SAFE_END; return datastore; }
int ast_channel_datastore_free | ( | struct ast_datastore * | datastore | ) |
Free a channel data store object.
Definition at line 1607 of file channel.c.
References ast_datastore_free().
{ return ast_datastore_free(datastore); }
int ast_channel_datastore_inherit | ( | struct ast_channel * | from, |
struct ast_channel * | to | ||
) |
Inherit datastores from a parent to a child.
Definition at line 1612 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().
{ struct ast_datastore *datastore = NULL, *datastore2; AST_LIST_TRAVERSE(&from->datastores, datastore, entry) { if (datastore->inheritance > 0) { datastore2 = ast_datastore_alloc(datastore->info, datastore->uid); if (datastore2) { datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL; datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1; AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry); } } } return 0; }
int ast_channel_datastore_remove | ( | struct ast_channel * | chan, |
struct ast_datastore * | datastore | ||
) |
Remove a datastore from a channel.
0 | success |
non-zero | failure |
Definition at line 1638 of file channel.c.
References AST_LIST_REMOVE, and ast_channel::datastores.
Referenced by acf_fetch(), adjust_frame_for_plc(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), exec_odbcfinish(), lua_get_state(), queue_transfer_fixup(), speech_background(), speech_destroy(), speex_write(), stop_mixmonitor_exec(), and try_calling().
{ return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1; }
int ast_channel_defer_dtmf | ( | struct ast_channel * | chan | ) |
Set defer DTMF flag on channel.
Defers DTMF
Defer 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 1187 of file channel.c.
References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.
Referenced by __adsi_transmit_messages(), and find_cache().
{ int pre = 0; if (chan) { pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF); ast_set_flag(chan, AST_FLAG_DEFER_DTMF); } return pre; }
int ast_channel_early_bridge | ( | struct ast_channel * | c0, |
struct ast_channel * | c1 | ||
) |
Bridge two channels together (early)
Bridge two channels together (early)
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. |
Definition at line 5315 of file channel.c.
References ast_channel_tech::early_bridge, and ast_channel::tech.
Referenced by dial_exec_full(), and wait_for_answer().
{ /* Make sure we can early bridge, if not error out */ if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge))) return -1; return c0->tech->early_bridge(c0, c1); }
void ast_channel_free | ( | struct ast_channel * | ) |
Free a channel structure.
Definition at line 1483 of file channel.c.
References ast_channel::alertpipe, ast_app_group_discard(), ast_cdr_discard(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), ast_datastore_free(), ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), AST_FLAG_IN_CHANNEL_LIST, ast_free, ast_frfree, ast_jb_destroy(), AST_LIST_REMOVE_HEAD, ast_log(), AST_MAX_FDS, ast_moh_cleanup(), ast_mutex_destroy(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_test_flag, ast_timer_close(), ast_tone_zone_unref(), ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, ast_channel::cid, ast_channel::datastores, f, free, free_cid(), ast_channel::lock_dont_use, LOG_WARNING, ast_channel::monitor, ast_channel::music_state, ast_channel::name, name, ast_channel::pbx, ast_channel::readq, ast_channel::readtrans, ast_channel::sched, sched_context_destroy(), ast_channel_monitor::stop, ast_channel::tech_pvt, ast_channel::timer, ast_channel::varshead, ast_channel::writetrans, and ast_channel::zone.
Referenced by acf_odbc_read(), acf_odbc_write(), action_getvar(), agent_cleanup(), agent_new(), ast_do_masquerade(), ast_hangup(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), bridge_request(), cli_odbc_read(), cli_odbc_write(), gtalk_newcall(), local_new(), make_email_file(), pbx_substitute_variables_helper_full(), rotate_file(), sendmail(), and sendpage().
{ int fd; #ifdef HAVE_EPOLL int i; #endif struct ast_var_t *vardata; struct ast_frame *f; struct varshead *headp; struct ast_datastore *datastore = NULL; char name[AST_CHANNEL_NAME], *dashptr; int inlist; headp=&chan->varshead; inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST); if (inlist) { AST_RWLIST_WRLOCK(&channels); if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { ast_debug(1, "Unable to find channel in list to free. Assuming it has already been done.\n"); } /* Lock and unlock the channel just to be sure nobody has it locked still due to a reference retrieved from the channel list. */ ast_channel_lock(chan); ast_channel_unlock(chan); } /* Get rid of each of the data stores on the channel */ ast_channel_lock(chan); while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry))) /* Free the data store */ ast_datastore_free(datastore); ast_channel_unlock(chan); /* Lock and unlock the channel just to be sure nobody has it locked still due to a reference that was stored in a datastore. (i.e. app_chanspy) */ ast_channel_lock(chan); ast_channel_unlock(chan); if (chan->tech_pvt) { ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); ast_free(chan->tech_pvt); } if (chan->sched) sched_context_destroy(chan->sched); ast_copy_string(name, chan->name, sizeof(name)); if ((dashptr = strrchr(name, '-'))) { *dashptr = '\0'; } /* Stop monitoring */ if (chan->monitor) chan->monitor->stop( chan, 0 ); /* If there is native format music-on-hold state, free it */ if (chan->music_state) ast_moh_cleanup(chan); /* Free translators */ if (chan->readtrans) ast_translator_free_path(chan->readtrans); if (chan->writetrans) ast_translator_free_path(chan->writetrans); if (chan->pbx) ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); free_cid(&chan->cid); /* Close pipes if appropriate */ if ((fd = chan->alertpipe[0]) > -1) close(fd); if ((fd = chan->alertpipe[1]) > -1) close(fd); if (chan->timer) { ast_timer_close(chan->timer); } #ifdef HAVE_EPOLL for (i = 0; i < AST_MAX_FDS; i++) { if (chan->epfd_data[i]) free(chan->epfd_data[i]); } close(chan->epfd); #endif while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list))) ast_frfree(f); /* loop over the variables list, freeing all data and deleting list items */ /* no need to lock the list, as the channel is already locked */ while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) ast_var_delete(vardata); ast_app_group_discard(chan); /* Destroy the jitterbuffer */ ast_jb_destroy(chan); if (chan->cdr) { ast_cdr_discard(chan->cdr); chan->cdr = NULL; } if (chan->zone) { chan->zone = ast_tone_zone_unref(chan->zone); } ast_mutex_destroy(&chan->lock_dont_use); ast_string_field_free_memory(chan); ast_free(chan); if (inlist) AST_RWLIST_UNLOCK(&channels); /* Queue an unknown state, because, while we know that this particular * instance is dead, we don't know the state of all other possible * instances. */ ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); }
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 1802 of file channel.h.
References ast_channel_queryoption(), AST_OPTION_T38_STATE, and T38_STATE_UNAVAILABLE.
Referenced by transmit(), transmit_audio(), and transmit_t38().
{ enum ast_t38_state state = T38_STATE_UNAVAILABLE; int datalen = sizeof(state); ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0); return state; }
void ast_channel_inherit_variables | ( | const struct ast_channel * | parent, |
struct ast_channel * | child | ||
) |
Inherits channel variable from parent to child channel.
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 4644 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(), agent_call(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), ring_entry(), and wait_for_answer().
{ struct ast_var_t *current, *newvar; const char *varname; AST_LIST_TRAVERSE(&parent->varshead, current, entries) { int vartype = 0; varname = ast_var_full_name(current); if (!varname) continue; if (varname[0] == '_') { vartype = 1; if (varname[1] == '_') vartype = 2; } switch (vartype) { case 1: newvar = ast_var_assign(&varname[1], ast_var_value(current)); if (newvar) { AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar)); } break; case 2: newvar = ast_var_assign(varname, ast_var_value(current)); if (newvar) { AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar)); } break; default: ast_debug(1, "Not copying variable %s.\n", ast_var_name(current)); break; } } }
int ast_channel_make_compatible | ( | struct ast_channel * | c0, |
struct ast_channel * | c1 | ||
) |
Makes two channel formats compatible.
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 . |
Definition at line 4534 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().
{ /* Some callers do not check return code, and we must try to set all call legs correctly */ int rc = 0; /* Set up translation from the chan to the peer */ rc = ast_channel_make_compatible_helper(chan, peer); if (rc < 0) return rc; /* Set up translation from the peer to the chan */ rc = ast_channel_make_compatible_helper(peer, chan); return rc; }
int ast_channel_masquerade | ( | struct ast_channel * | original, |
struct ast_channel * | clone | ||
) |
Weird function made for call transfers.
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.
Definition at line 4551 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 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(), sip_park(), and skinny_transfer().
{ int res = -1; struct ast_channel *final_orig, *final_clone, *base; retrymasq: final_orig = original; final_clone = clonechan; ast_channel_lock(original); while (ast_channel_trylock(clonechan)) { ast_channel_unlock(original); usleep(1); ast_channel_lock(original); } /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent) and if so, we don't really want to masquerade it, but its proxy */ if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original)) final_orig = original->_bridge; if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan)) final_clone = clonechan->_bridge; if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) { final_clone = base; } if ((final_orig != original) || (final_clone != clonechan)) { /* Lots and lots of deadlock avoidance. The main one we're competing with * is ast_write(), which locks channels recursively, when working with a * proxy channel. */ if (ast_channel_trylock(final_orig)) { ast_channel_unlock(clonechan); ast_channel_unlock(original); goto retrymasq; } if (ast_channel_trylock(final_clone)) { ast_channel_unlock(final_orig); ast_channel_unlock(clonechan); ast_channel_unlock(original); goto retrymasq; } ast_channel_unlock(clonechan); ast_channel_unlock(original); original = final_orig; clonechan = final_clone; } if (original == clonechan) { ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); ast_channel_unlock(clonechan); ast_channel_unlock(original); return -1; } ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name); if (!original->masqr && !original->masq && !clonechan->masq && !clonechan->masqr) { original->masq = clonechan; clonechan->masqr = original; ast_queue_frame(original, &ast_null_frame); ast_queue_frame(clonechan, &ast_null_frame); ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name); res = 0; } else if (original->masq) { ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", original->masq->name, original->name); } else if (original->masqr) { /* not yet as a previously planned masq hasn't yet happened */ ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", original->name, original->masqr->name); } else if (clonechan->masq) { ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", clonechan->masq->name, clonechan->name); } else { /* (clonechan->masqr) */ ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", clonechan->name, clonechan->masqr->name); } ast_channel_unlock(clonechan); ast_channel_unlock(original); return res; }
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 5679 of file channel.c.
References ast_log(), errno, LOG_ERROR, ast_channel_tech::queryoption, and ast_channel::tech.
Referenced by ast_channel_get_t38_state(), and local_queryoption().
const char* ast_channel_reason2str | ( | int | reason | ) |
return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
reason | The integer argument, usually taken from AST_CONTROL_ macros |
Definition at line 4045 of file channel.c.
References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RING, and AST_CONTROL_RINGING.
Referenced by attempt_thread().
{ switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */ { case 0: return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)"; case AST_CONTROL_HANGUP: return "Hangup"; case AST_CONTROL_RING: return "Local Ring"; case AST_CONTROL_RINGING: return "Remote end Ringing"; case AST_CONTROL_ANSWER: return "Remote end has Answered"; case AST_CONTROL_BUSY: return "Remote end is Busy"; case AST_CONTROL_CONGESTION: return "Congestion (circuits busy)"; default: return "Unknown Reason!!"; } }
int ast_channel_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.
tech | Structure defining channel technology or "type" |
Definition at line 557 of file channel.c.
References ast_calloc, ast_debug, AST_LIST_INSERT_HEAD, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::chan, ast_channel_tech::description, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.
Referenced by load_module(), and unload_module().
{ struct chanlist *chan; AST_RWLIST_WRLOCK(&channels); AST_LIST_TRAVERSE(&backends, chan, list) { if (!strcasecmp(tech->type, chan->tech->type)) { ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type); AST_RWLIST_UNLOCK(&channels); return -1; } } if (!(chan = ast_calloc(1, sizeof(*chan)))) { AST_RWLIST_UNLOCK(&channels); return -1; } chan->tech = tech; AST_LIST_INSERT_HEAD(&backends, chan, list); ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description); ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description); AST_RWLIST_UNLOCK(&channels); return 0; }
struct ast_channel* ast_channel_search_locked | ( | int(*)(struct ast_channel *, void *) | is_match, |
void * | data | ||
) | [read] |
Search for a channel based on the passed channel matching callback Search for a channel based on the specified is_match callback, and return the first channel that we match. When returned, the channel will be locked. Note that the is_match callback is called with the passed channel locked, and should return 0 if there is no match, and non-zero if there is.
is_match | callback executed on each channel until non-zero is returned, or we run out of channels to search. |
data | data passed to the is_match callback during each invocation. |
Definition at line 1351 of file channel.c.
References ast_channel_lock, ast_channel_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by ast_pickup_call(), pickup_by_exten(), pickup_by_mark(), and transmit_state_notify().
{ struct ast_channel *c = NULL; AST_RWLIST_RDLOCK(&channels); AST_RWLIST_TRAVERSE(&channels, c, chan_list) { ast_channel_lock(c); if (is_match(c, data)) { break; } ast_channel_unlock(c); } AST_RWLIST_UNLOCK(&channels); return c; }
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 4476 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().
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 4483 of file channel.c.
References ast_channel_sendhtml(), and AST_HTML_URL.
Referenced by dial_exec_full(), sendurl_exec(), and try_calling().
{ return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1); }
void ast_channel_set_fd | ( | struct ast_channel * | chan, |
int | which, | ||
int | fd | ||
) |
Set the file descriptor on the channel
Definition at line 1671 of file channel.c.
References ast_calloc, chanlist::chan, 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(), nbs_new(), oss_new(), phone_new(), setformat(), sip_new(), skinny_new(), start_rtp(), and swap_subs().
{ #ifdef HAVE_EPOLL struct epoll_event ev; struct ast_epoll_data *aed = NULL; if (chan->fds[which] > -1) { epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev); aed = chan->epfd_data[which]; } /* If this new fd is valid, add it to the epoll */ if (fd > -1) { if (!aed && (!(aed = ast_calloc(1, sizeof(*aed))))) return; chan->epfd_data[which] = aed; aed->chan = chan; aed->which = which; ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; ev.data.ptr = aed; epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev); } else if (aed) { /* We don't have to keep around this epoll data structure now */ free(aed); chan->epfd_data[which] = NULL; } #endif chan->fds[which] = fd; return; }
int ast_channel_setoption | ( | struct ast_channel * | channel, |
int | option, | ||
void * | data, | ||
int | datalen, | ||
int | block | ||
) |
Sets an option on a channel.
Sets an option on a channel
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 5666 of file channel.c.
References ast_log(), errno, LOG_ERROR, ast_channel_tech::setoption, and ast_channel::tech.
Referenced by ast_bridge_call(), common_exec(), conf_run(), dahdi_hangup(), dial_exec_full(), func_channel_write(), func_channel_write_real(), handle_tddmode(), play_record_review(), reset_volumes(), rpt(), rpt_exec(), set_listen_volume(), set_talk_volume(), try_calling(), and vm_forwardoptions().
void ast_channel_setwhentohangup | ( | struct ast_channel * | chan, |
time_t | offset | ||
) |
Set when to hang a channel up.
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).
Definition at line 528 of file channel.c.
References ast_channel_setwhentohangup_tv().
{ struct timeval when = { offset, }; ast_channel_setwhentohangup_tv(chan, when); }
void ast_channel_setwhentohangup_tv | ( | struct ast_channel * | chan, |
struct timeval | offset | ||
) |
Set when to hang a channel up.
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).
Definition at line 521 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().
{ chan->whentohangup = ast_tvzero(offset) ? offset : ast_tvadd(offset, ast_tvnow()); ast_queue_frame(chan, &ast_null_frame); return; }
struct ast_silence_generator* ast_channel_start_silence_generator | ( | struct ast_channel * | chan | ) | [read] |
Starts a silence generator on the given channel.
chan | The channel to generate silence on |
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.
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 6017 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().
{ struct ast_silence_generator *state; if (!(state = ast_calloc(1, sizeof(*state)))) { return NULL; } state->old_write_format = chan->writeformat; if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n"); ast_free(state); return NULL; } ast_activate_generator(chan, &silence_generator, state); ast_debug(1, "Started silence generator on '%s'\n", chan->name); return state; }
void ast_channel_stop_silence_generator | ( | struct ast_channel * | chan, |
struct ast_silence_generator * | state | ||
) |
Stops a previously-started silence generator on the given channel.
chan | The channel to operate on |
state | The ast_silence_generator pointer return by a previous call to ast_channel_start_silence_generator. |
This function will stop the operating silence generator and return the channel to its previous write format.
Definition at line 6040 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().
{ if (!state) return; ast_deactivate_generator(chan); ast_debug(1, "Stopped silence generator on '%s'\n", chan->name); if (ast_set_write_format(chan, state->old_write_format) < 0) ast_log(LOG_ERROR, "Could not return write format to its original state\n"); ast_free(state); }
int ast_channel_supports_html | ( | struct ast_channel * | channel | ) |
Checks for HTML support on a channel
Returns 0 if channel does not support HTML or non-zero if it does
Definition at line 4471 of file channel.c.
References ast_channel_tech::send_html, and ast_channel::tech.
Referenced by dial_exec_full(), sendurl_exec(), and try_calling().
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 1199 of file channel.c.
References ast_clear_flag, and AST_FLAG_DEFER_DTMF.
Referenced by __adsi_transmit_messages(), find_cache(), and rpt_call().
{ if (chan) ast_clear_flag(chan, AST_FLAG_DEFER_DTMF); }
void ast_channel_unregister | ( | const struct ast_channel_tech * | tech | ) |
Unregister a channel technology.
tech | Structure defining channel technology or "type" that was previously registered |
Definition at line 587 of file channel.c.
References ast_debug, ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::chan, chanlist::tech, and ast_channel_tech::type.
Referenced by __unload_module(), load_module(), and unload_module().
{ struct chanlist *chan; ast_debug(1, "Unregistering channel type '%s'\n", tech->type); AST_RWLIST_WRLOCK(&channels); AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) { if (chan->tech == tech) { AST_LIST_REMOVE_CURRENT(list); ast_free(chan); ast_verb(2, "Unregistered channel type '%s'\n", tech->type); break; } } AST_LIST_TRAVERSE_SAFE_END; AST_RWLIST_UNLOCK(&channels); }
struct ast_channel* ast_channel_walk_locked | ( | const struct ast_channel * | prev | ) | [read] |
Browse channels in use Browse the channels currently in use.
prev | where you want to start in the channel list |
Definition at line 1313 of file channel.c.
References channel_find_locked().
Referenced by action_coreshowchannels(), action_status(), ast_complete_channels(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), conf_exec(), func_channels_read(), handle_chanlist(), handle_core_set_debug_channel(), and next_channel().
{ return channel_find_locked(prev, NULL, 0, NULL, NULL); }
struct ast_variable* ast_channeltype_list | ( | void | ) | [read] |
return an ast_variable list of channeltypes
Definition at line 186 of file channel.c.
References AST_LIST_TRAVERSE, 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().
{ struct chanlist *cl; struct ast_variable *var=NULL, *prev = NULL; AST_LIST_TRAVERSE(&backends, cl, list) { if (prev) { if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, ""))) prev = prev->next; } else { var = ast_variable_new(cl->tech->type, cl->tech->description, ""); prev = var; } } return var; }
int ast_check_hangup | ( | struct ast_channel * | chan | ) |
Check to see if a channel is needing hang up.
chan | channel on which to check for hang up This function determines if the channel is being requested to be hung up. |
Definition at line 461 of file channel.c.
References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.
Referenced by __ast_pbx_run(), __ast_read(), _macro_exec(), action_redirect(), 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_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), autoservice_run(), bridge_call_thread(), bridge_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_bridge(), common_exec(), conf_play(), conf_run(), dahdi_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), feature_request_and_dial(), findmeexec(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), local_fixup(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), rpt(), rpt_exec(), run_ras(), try_calling(), and wait_for_answer().
{ if (chan->_softhangup) /* yes if soft hangup flag set */ return 1; if (ast_tvzero(chan->whentohangup)) /* no if no hangup scheduled */ return 0; if (ast_tvdiff_ms(chan->whentohangup, ast_tvnow()) > 0) /* no if hangup time has not come yet. */ return 0; chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */ return 1; }
void ast_deactivate_generator | ( | struct ast_channel * | chan | ) |
Deactivate an active generator
Definition at line 2076 of file channel.c.
References ast_channel_lock, ast_channel_set_fd(), ast_channel_unlock, ast_clear_flag, AST_FLAG_WRITE_INT, AST_GENERATOR_FD, ast_settimeout(), ast_channel::generator, ast_channel::generatordata, and ast_generator::release.
Referenced by __ast_read(), app_exec(), ast_channel_stop_silence_generator(), ast_openstream_full(), ast_playtones_stop(), ast_quiet_chan(), ast_read_generator_actions(), ast_tonepair_stop(), ast_write(), cb_events(), channel_spy(), dial_exec_full(), generator_force(), local_ast_moh_stop(), old_milliwatt_exec(), transmit_audio(), and wait_for_answer().
{ ast_channel_lock(chan); if (chan->generatordata) { if (chan->generator && chan->generator->release) chan->generator->release(chan, chan->generatordata); chan->generatordata = NULL; chan->generator = NULL; ast_channel_set_fd(chan, AST_GENERATOR_FD, -1); ast_clear_flag(chan, AST_FLAG_WRITE_INT); ast_settimeout(chan, 0, NULL, NULL); } ast_channel_unlock(chan); }
int ast_do_masquerade | ( | struct ast_channel * | original | ) |
Start masquerading a channel 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.
chan | Channel to masquerade |
Start masquerading a channel 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.
Definition at line 4735 of file channel.c.
References ast_channel::_softhangup, ast_channel::_state, ast_channel::adsicpe, ast_channel::alertpipe, ast_app_group_update(), ast_bridged_channel(), ast_cause2str(), ast_channel_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_set_fd(), 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_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_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::cdr, ast_datastore_info::chan_fixup, ast_channel::cid, clone_variables(), ast_datastore::data, ast_channel::datastores, 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, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::musicclass, musicclass, name, ast_channel::name, ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::readq, report_new_callerid(), 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(), builtin_atxfer(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), sip_park(), and sip_park_thread().
{ int x,i; int res=0; int origstate; struct ast_frame *current; const struct ast_channel_tech *t; void *t_pvt; struct ast_callerid tmpcid; struct ast_channel *clonechan = original->masq; struct ast_channel *bridged; struct ast_cdr *cdr; int rformat = original->readformat; int wformat = original->writeformat; char newn[AST_CHANNEL_NAME]; char orig[AST_CHANNEL_NAME]; char masqn[AST_CHANNEL_NAME]; char zombn[AST_CHANNEL_NAME]; ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", clonechan->name, clonechan->_state, original->name, original->_state); manager_event(EVENT_FLAG_CALL, "Masquerade", "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n", clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state)); /* XXX This operation is a bit odd. We're essentially putting the guts of * the clone channel into the original channel. Start by killing off the * original channel's backend. While the features are nice, which is the * reason we're keeping it, it's still awesomely weird. XXX */ /* We need the clone's lock, too */ ast_channel_lock(clonechan); ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clonechan->name, &clonechan->lock_dont_use); /* Having remembered the original read/write formats, we turn off any translation on either one */ free_translation(clonechan); free_translation(original); /* Unlink the masquerade */ original->masq = NULL; clonechan->masqr = NULL; /* Save the original name */ ast_copy_string(orig, original->name, sizeof(orig)); /* Save the new name */ ast_copy_string(newn, clonechan->name, sizeof(newn)); /* Create the masq name */ snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn); /* Copy the name from the clone channel */ ast_string_field_set(original, name, newn); /* Mangle the name of the clone channel */ ast_string_field_set(clonechan, name, masqn); /* Notify any managers of the change, first the masq then the other */ manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clonechan->uniqueid); manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); /* Swap the technologies */ t = original->tech; original->tech = clonechan->tech; clonechan->tech = t; /* Swap the cdrs */ cdr = original->cdr; original->cdr = clonechan->cdr; clonechan->cdr = cdr; t_pvt = original->tech_pvt; original->tech_pvt = clonechan->tech_pvt; clonechan->tech_pvt = t_pvt; /* Swap the alertpipes */ for (i = 0; i < 2; i++) { x = original->alertpipe[i]; original->alertpipe[i] = clonechan->alertpipe[i]; clonechan->alertpipe[i] = x; } /* * Swap the readq's. The end result should be this: * * 1) All frames should be on the new (original) channel. * 2) Any frames that were already on the new channel before this * masquerade need to be at the end of the readq, after all of the * frames on the old (clone) channel. * 3) The alertpipe needs to get poked for every frame that was already * on the new channel, since we are now using the alert pipe from the * old (clone) channel. */ { AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq; AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL); AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list); AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list); while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) { AST_LIST_INSERT_TAIL(&original->readq, current, frame_list); if (original->alertpipe[1] > -1) { int poke = 0; if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) { ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); } } } } /* Swap the raw formats */ x = original->rawreadformat; original->rawreadformat = clonechan->rawreadformat; clonechan->rawreadformat = x; x = original->rawwriteformat; original->rawwriteformat = clonechan->rawwriteformat; clonechan->rawwriteformat = x; clonechan->_softhangup = AST_SOFTHANGUP_DEV; /* And of course, so does our current state. Note we need not call ast_setstate since the event manager doesn't really consider these separate. We do this early so that the clone has the proper state of the original channel. */ origstate = original->_state; original->_state = clonechan->_state; clonechan->_state = origstate; if (clonechan->tech->fixup){ res = clonechan->tech->fixup(original, clonechan); if (res) ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name); } /* Start by disconnecting the original's physical side */ if (clonechan->tech->hangup) res = clonechan->tech->hangup(clonechan); if (res) { ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n"); ast_channel_unlock(clonechan); return -1; } snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); /* Mangle the name of the clone channel */ ast_string_field_set(clonechan, name, zombn); manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clonechan->uniqueid); /* Update the type. */ t_pvt = original->monitor; original->monitor = clonechan->monitor; clonechan->monitor = t_pvt; /* Keep the same language. */ ast_string_field_set(original, language, clonechan->language); /* Copy the FD's other than the generator fd */ for (x = 0; x < AST_MAX_FDS; x++) { if (x != AST_GENERATOR_FD) ast_channel_set_fd(original, x, clonechan->fds[x]); } ast_app_group_update(clonechan, original); /* Move data stores over */ if (AST_LIST_FIRST(&clonechan->datastores)) { struct ast_datastore *ds; /* We use a safe traversal here because some fixup routines actually * remove the datastore from the list and free them. */ AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) { if (ds->info->chan_fixup) ds->info->chan_fixup(ds->data, clonechan, original); } AST_LIST_TRAVERSE_SAFE_END; AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry); } clone_variables(original, clonechan); /* Presense of ADSI capable CPE follows clone */ original->adsicpe = clonechan->adsicpe; /* Bridge remains the same */ /* CDR fields remain the same */ /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */ /* Application and data remain the same */ /* Clone exception becomes real one, as with fdno */ ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION)); original->fdno = clonechan->fdno; /* Schedule context remains the same */ /* Stream stuff stays the same */ /* Keep the original state. The fixup code will need to work with it most likely */ /* Just swap the whole structures, nevermind the allocations, they'll work themselves out. */ tmpcid = original->cid; original->cid = clonechan->cid; clonechan->cid = tmpcid; report_new_callerid(original); /* Restore original timing file descriptor */ ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd); /* Our native formats are different now */ original->nativeformats = clonechan->nativeformats; /* Context, extension, priority, app data, jump table, remain the same */ /* pvt switches. pbx stays the same, as does next */ /* Set the write format */ ast_set_write_format(original, wformat); /* Set the read format */ ast_set_read_format(original, rformat); /* Copy the music class */ ast_string_field_set(original, musicclass, clonechan->musicclass); ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat); /* Okay. Last thing is to let the channel driver know about all this mess, so he can fix up everything as best as possible */ if (original->tech->fixup) { res = original->tech->fixup(clonechan, original); if (res) { ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n", original->tech->type, original->name); ast_channel_unlock(clonechan); return -1; } } else ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n", original->tech->type, original->name); /* * If an indication is currently playing, maintain it on the channel * that is taking the place of original * * This is needed because the masquerade is swapping out in the internals * of this channel, and the new channel private data needs to be made * aware of the current visible indication (RINGING, CONGESTION, etc.) */ if (original->visible_indication) { ast_indicate(original, original->visible_indication); } /* Now, at this point, the "clone" channel is totally F'd up. We mark it as a zombie so nothing tries to touch it. If it's already been marked as a zombie, then free it now (since it already is considered invalid). */ if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) { ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name); ast_channel_unlock(clonechan); manager_event(EVENT_FLAG_CALL, "Hangup", "Channel: %s\r\n" "Uniqueid: %s\r\n" "Cause: %d\r\n" "Cause-txt: %s\r\n", clonechan->name, clonechan->uniqueid, clonechan->hangupcause, ast_cause2str(clonechan->hangupcause) ); ast_channel_free(clonechan); } else { ast_debug(1, "Released clone lock on '%s'\n", clonechan->name); ast_set_flag(clonechan, AST_FLAG_ZOMBIE); ast_queue_frame(clonechan, &ast_null_frame); ast_channel_unlock(clonechan); } /* Signal any blocker */ if (ast_test_flag(original, AST_FLAG_BLOCKING)) pthread_kill(original->blocker, SIGURG); ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state); if ((bridged = ast_bridged_channel(original))) { ast_channel_lock(bridged); ast_indicate(bridged, AST_CONTROL_SRCCHANGE); ast_channel_unlock(bridged); } ast_indicate(original, AST_CONTROL_SRCCHANGE); return 0; }
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 1783 of file channel.h.
References dummy().
Referenced by do_monitor().
struct ast_channel* ast_get_channel_by_exten_locked | ( | const char * | exten, |
const char * | context | ||
) | [read] |
Get channel by exten (and optionally context) and lock it.
Definition at line 1338 of file channel.c.
References channel_find_locked().
{ return channel_find_locked(NULL, NULL, 0, context, exten); }
struct ast_channel* ast_get_channel_by_name_locked | ( | const char * | name | ) | [read] |
Get channel by name or uniqueid (locks channel)
Definition at line 1319 of file channel.c.
References channel_find_locked().
Referenced by acf_import(), action_add_agi_cmd(), action_atxfer(), action_getvar(), action_hangup(), action_redirect(), action_sendtext(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), ast_bridge_call(), asyncgoto_exec(), change_monitor_action(), do_pause_or_unpause(), get_dahdi_channel_locked(), handle_channelstatus(), handle_cli_agi_add_cmd(), handle_core_set_debug_channel(), handle_getvariablefull(), handle_hangup(), handle_redirect(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), handle_softhangup(), manager_park(), manager_play_dtmf(), park_call_full(), pbx_builtin_importvar(), shared_read(), shared_write(), start_monitor_action(), and stop_monitor_action().
{ return channel_find_locked(NULL, name, 0, NULL, NULL); }
struct ast_channel* ast_get_channel_by_name_prefix_locked | ( | const char * | name, |
const int | namelen | ||
) | [read] |
Get channel by name or uniqueid prefix (locks channel)
Definition at line 1325 of file channel.c.
References channel_find_locked().
Referenced by action_bridge(), ast_parse_device_state(), bridge_exec(), common_exec(), handle_cli_mixmonitor(), shared_read(), and shared_write().
{ return channel_find_locked(NULL, name, namelen, NULL, NULL); }
struct ast_channel_tech* ast_get_channel_tech | ( | const char * | name | ) | [read] |
Get a channel technology structure by name.
name | name of technology to find |
Definition at line 609 of file channel.c.
References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, chanlist::tech, and ast_channel_tech::type.
Referenced by __ast_channel_alloc_ap(), _ast_device_state(), and ast_var_channel_types_table().
{ struct chanlist *chanls; const struct ast_channel_tech *ret = NULL; AST_RWLIST_RDLOCK(&channels); AST_LIST_TRAVERSE(&backends, chanls, list) { if (!strcasecmp(name, chanls->tech->type)) { ret = chanls->tech; break; } } AST_RWLIST_UNLOCK(&channels); return ret; }
ast_group_t ast_get_group | ( | const char * | s | ) |
Definition at line 5844 of file channel.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), group, 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().
{ char *piece; char *c; int start=0, finish=0, x; ast_group_t group = 0; if (ast_strlen_zero(s)) return 0; c = ast_strdupa(s); while ((piece = strsep(&c, ","))) { if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) { /* Range */ } else if (sscanf(piece, "%30d", &start)) { /* Just one */ finish = start; } else { ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece); continue; } for (x = start; x <= finish; x++) { if ((x > 63) || (x < 0)) { ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x); } else group |= ((ast_group_t) 1 << x); } } return group; }
int ast_hangup | ( | struct ast_channel * | chan | ) |
Hang up a channel.
chan | channel to hang up |
Definition at line 1810 of file channel.c.
References ast_assert, ast_audiohook_detach_list(), ast_autoservice_stop(), ast_cause2str(), ast_cdr_detach(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_DIALED, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_IN_CHANNEL_LIST, AST_FLAG_ZOMBIE, ast_log(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_cdr::disposition, EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_ERROR, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_generator::release, S_OR, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, ast_channel::uniqueid, and ast_channel::vstream.
Referenced by __ast_pbx_run(), __ast_request_and_dial(), __oh323_new(), action_bridge(), agent_hangup(), agent_read(), alsa_new(), 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(), feature_attended_transfer(), feature_request_and_dial(), findmeexec(), 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(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), nbs_new(), oss_new(), park_exec_full(), parkandannounce_exec(), phone_new(), play_sound_file(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), try_calling(), unistim_new(), usbradio_new(), wait_for_answer(), and wait_for_winner().
{ int res = 0; /* Don't actually hang up a channel that will masquerade as someone else, or if someone is going to masquerade as us */ ast_channel_lock(chan); if (chan->audiohooks) { ast_audiohook_detach_list(chan->audiohooks); chan->audiohooks = NULL; } ast_autoservice_stop(chan); if (chan->masq) { if (ast_do_masquerade(chan)) ast_log(LOG_WARNING, "Failed to perform masquerade\n"); } if (chan->masq) { ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name); ast_channel_unlock(chan); return 0; } /* If this channel is one which will be masqueraded into something, mark it as a zombie already, so we know to free it later */ if (chan->masqr) { ast_set_flag(chan, AST_FLAG_ZOMBIE); ast_channel_unlock(chan); return 0; } ast_channel_unlock(chan); AST_RWLIST_WRLOCK(&channels); if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n"); } ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST); AST_RWLIST_UNLOCK(&channels); ast_channel_lock(chan); free_translation(chan); /* Close audio stream */ if (chan->stream) { ast_closestream(chan->stream); chan->stream = NULL; } /* Close video stream */ if (chan->vstream) { ast_closestream(chan->vstream); chan->vstream = NULL; } if (chan->sched) { sched_context_destroy(chan->sched); chan->sched = NULL; } if (chan->generatordata) /* Clear any tone stuff remaining */ if (chan->generator && chan->generator->release) chan->generator->release(chan, chan->generatordata); chan->generatordata = NULL; chan->generator = NULL; if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " "is blocked by thread %ld in procedure %s! Expect a failure\n", (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0); } if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { ast_debug(1, "Hanging up channel '%s'\n", chan->name); if (chan->tech->hangup) res = chan->tech->hangup(chan); } else { ast_debug(1, "Hanging up zombie '%s'\n", chan->name); } ast_channel_unlock(chan); manager_event(EVENT_FLAG_CALL, "Hangup", "Channel: %s\r\n" "Uniqueid: %s\r\n" "CallerIDNum: %s\r\n" "CallerIDName: %s\r\n" "Cause: %d\r\n" "Cause-txt: %s\r\n", chan->name, chan->uniqueid, S_OR(chan->cid.cid_num, "<unknown>"), S_OR(chan->cid.cid_name, "<unknown>"), chan->hangupcause, ast_cause2str(chan->hangupcause) ); if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) { ast_channel_lock(chan); ast_cdr_end(chan->cdr); ast_cdr_detach(chan->cdr); chan->cdr = NULL; ast_channel_unlock(chan); } ast_channel_free(chan); return res; }
int ast_indicate | ( | struct ast_channel * | chan, |
int | condition | ||
) |
Indicates condition of channel.
chan | channel to change the indication |
condition | which condition to indicate on the channel |
Definition at line 3274 of file channel.c.
References ast_indicate_data().
Referenced by __ast_play_and_record(), agent_new(), alsa_call(), answer_trunk_chan(), ast_bridge_call(), ast_channel_bridge(), ast_do_masquerade(), ast_dtmf_stream(), ast_raw_answer(), attempt_transfer(), builtin_atxfer(), builtin_blindtransfer(), cli_console_answer(), conf_run(), console_call(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), finishup(), function_remote(), handle_callforward_button(), handle_frame(), handle_recordfile(), handle_request_refer(), manage_parkinglot(), mgcp_ss(), monitor_dial(), oss_call(), park_call_full(), park_exec_full(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_proceeding(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), record_exec(), rpt(), rpt_exec(), say_periodic_announcement(), say_position(), send_waveform_to_channel(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), try_calling(), and wait_for_answer().
{ return ast_indicate_data(chan, condition, NULL, 0); }
int ast_indicate_data | ( | struct ast_channel * | chan, |
int | condition, | ||
const void * | data, | ||
size_t | datalen | ||
) |
Indicates condition of channel, with payload.
chan | channel to change the indication |
condition | which condition to indicate on the channel |
data | pointer to payload data |
datalen | size of payload data |
Definition at line 3316 of file channel.c.
References ast_channel::_state, _XXX_AST_CONTROL_T38, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_END_OF_Q, 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_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_debug, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STATE_UP, ast_test_flag, ast_tone_zone_sound_unref(), ast_tone_zone_sound::data, ast_channel_tech::indicate, is_visible_indication(), LOG_WARNING, ast_channel::name, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.
Referenced by agent_hangup(), ast_bridge_call(), ast_generic_bridge(), ast_indicate(), bridge_native_loop(), bridge_p2p_loop(), login_exec(), manage_parkinglot(), park_call_full(), pbx_builtin_waitexten(), transmit_audio(), transmit_t38(), and wait_for_answer().
{ /* By using an enum, we'll get compiler warnings for values not handled * in switch statements. */ enum ast_control_frame_type condition = _condition; struct ast_tone_zone_sound *ts = NULL; int res = -1; ast_channel_lock(chan); /* Don't bother if the channel is about to go away, anyway. */ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { ast_channel_unlock(chan); return -1; } if (chan->tech->indicate) { /* See if the channel driver can handle this condition. */ res = chan->tech->indicate(chan, condition, data, datalen); } ast_channel_unlock(chan); if (!res) { /* The channel driver successfully handled this indication */ if (is_visible_indication(condition)) { chan->visible_indication = condition; } return 0; } /* The channel driver does not support this indication, let's fake * it by doing our own tone generation if applicable. */ /*!\note If we compare the enumeration type, which does not have any * negative constants, the compiler may optimize this code away. * Therefore, we must perform an integer comparison here. */ if (_condition < 0) { /* Stop any tones that are playing */ ast_playtones_stop(chan); return 0; } /* Handle conditions that we have tones for. */ switch (condition) { case _XXX_AST_CONTROL_T38: /* deprecated T.38 control frame */ return -1; case AST_CONTROL_T38_PARAMETERS: /* there is no way to provide 'default' behavior for these * control frames, so we need to return failure, but there * is also no value in the log message below being emitted * since failure to handle these frames is not an 'error' * so just return right now. in addition, we want to return * whatever value the channel driver returned, in case it * has some meaning.*/ return res; case AST_CONTROL_RINGING: ts = ast_get_indication_tone(chan->zone, "ring"); /* It is common practice for channel drivers to return -1 if trying * to indicate ringing on a channel which is up. The idea is to let the * core generate the ringing inband. However, we don't want the * warning message about not being able to handle the specific indication * to print nor do we want ast_indicate_data to return an "error" for this * condition */ if (chan->_state == AST_STATE_UP) { res = 0; } break; case AST_CONTROL_BUSY: ts = ast_get_indication_tone(chan->zone, "busy"); break; case AST_CONTROL_CONGESTION: ts = ast_get_indication_tone(chan->zone, "congestion"); break; case AST_CONTROL_PROGRESS: case AST_CONTROL_PROCEEDING: case AST_CONTROL_VIDUPDATE: case AST_CONTROL_SRCUPDATE: case AST_CONTROL_SRCCHANGE: case AST_CONTROL_RADIO_KEY: case AST_CONTROL_RADIO_UNKEY: case AST_CONTROL_OPTION: case AST_CONTROL_WINK: case AST_CONTROL_FLASH: case AST_CONTROL_OFFHOOK: case AST_CONTROL_TAKEOFFHOOK: case AST_CONTROL_ANSWER: case AST_CONTROL_HANGUP: case AST_CONTROL_RING: case AST_CONTROL_HOLD: case AST_CONTROL_UNHOLD: case AST_CONTROL_END_OF_Q: /* Nothing left to do for these. */ res = 0; break; } if (ts) { /* We have a tone to play, yay. */ ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition); res = ast_playtones_start(chan, 0, ts->data, 1); ts = ast_tone_zone_sound_unref(ts); chan->visible_indication = condition; } if (res) { /* not handled */ ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name); } return res; }
int ast_internal_timing_enabled | ( | struct ast_channel * | chan | ) |
Check if the channel can run in internal timing mode.
chan | The channel to check |
This function will return 1 if internal timing is enabled and the timing device is available.
Definition at line 3259 of file channel.c.
References ast_opt_internal_timing, and ast_channel::timingfd.
Referenced by add_sdp(), and ast_read_generator_actions().
{ return (ast_opt_internal_timing && chan->timingfd > -1); }
int ast_is_deferrable_frame | ( | const struct ast_frame * | frame | ) |
Should we keep this frame for later?
There are functions such as ast_safe_sleep which will service a channel to ensure that it does not have a large backlog of queued frames. When this happens, we want to hold on to specific frame types and just drop others. This function will tell if the frame we just read should be held onto.
frame | The frame we just read |
1 | frame should be kept |
0 | frame should be dropped |
Definition at line 1368 of file channel.c.
References AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, and ast_frame::frametype.
Referenced by ast_safe_sleep_conditional(), autoservice_run(), and feature_request_and_dial().
{ /* Do not add a default entry in this switch statement. Each new * frame type should be addressed directly as to whether it should * be queued up or not. */ switch (frame->frametype) { case AST_FRAME_CONTROL: case AST_FRAME_TEXT: case AST_FRAME_IMAGE: case AST_FRAME_HTML: return 1; case AST_FRAME_DTMF_END: case AST_FRAME_DTMF_BEGIN: case AST_FRAME_VOICE: case AST_FRAME_VIDEO: case AST_FRAME_NULL: case AST_FRAME_IAX: case AST_FRAME_CNG: case AST_FRAME_MODEM: return 0; } return 0; }
void ast_poll_channel_add | ( | struct ast_channel * | chan0, |
struct ast_channel * | chan1 | ||
) |
Add a channel to an optimized waitfor
Definition at line 1705 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_generic_bridge(), begin_dial_channel(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), and wait_for_answer().
{ #ifdef HAVE_EPOLL struct epoll_event ev; int i = 0; if (chan0->epfd == -1) return; /* Iterate through the file descriptors on chan1, adding them to chan0 */ for (i = 0; i < AST_MAX_FDS; i++) { if (chan1->fds[i] == -1) continue; ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; ev.data.ptr = chan1->epfd_data[i]; epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev); } #endif return; }
void ast_poll_channel_del | ( | struct ast_channel * | chan0, |
struct ast_channel * | chan1 | ||
) |
Delete a channel from an optimized waitfor
Definition at line 1728 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), monitor_dial(), and wait_for_answer().
{ #ifdef HAVE_EPOLL struct epoll_event ev; int i = 0; if (chan0->epfd == -1) return; for (i = 0; i < AST_MAX_FDS; i++) { if (chan1->fds[i] == -1) continue; epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev); } #endif return; }
char* ast_print_group | ( | char * | buf, |
int | buflen, | ||
ast_group_t | group | ||
) |
print call- and pickup groups into buffer
Definition at line 5944 of file channel.c.
References buf, first, and num.
Referenced by _sip_show_peer(), _skinny_show_line(), func_channel_read(), function_sippeer(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().
{ unsigned int i; int first = 1; char num[3]; buf[0] = '\0'; if (!group) /* Return empty string if no group */ return buf; for (i = 0; i <= 63; i++) { /* Max group is 63 */ if (group & ((ast_group_t) 1 << i)) { if (!first) { strncat(buf, ", ", buflen - strlen(buf) - 1); } else { first = 0; } snprintf(num, sizeof(num), "%u", i); strncat(buf, num, buflen - strlen(buf) - 1); } } return buf; }
int ast_prod | ( | struct ast_channel * | chan | ) |
Send empty audio to prime a channel driver.
Definition at line 3556 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::data, LOG_WARNING, ast_channel::name, ast_frame::ptr, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.
Referenced by ast_activate_generator().
{ struct ast_frame a = { AST_FRAME_VOICE }; char nothing[128]; /* Send an empty audio frame to get things moving */ if (chan->_state != AST_STATE_UP) { ast_debug(1, "Prodding channel '%s'\n", chan->name); a.subclass = chan->rawwriteformat; a.data.ptr = nothing + AST_FRIENDLY_OFFSET; a.src = "ast_prod"; /* this better match check in ast_write */ if (ast_write(chan, &a)) ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name); } return 0; }
int ast_queue_control | ( | struct ast_channel * | chan, |
enum ast_control_frame_type | control | ||
) |
Queue a control frame with payload.
chan | channel to queue frame onto |
control | type of control frame |
zero | on success |
non-zero | on failure |
Definition at line 1164 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and ast_frame::subclass.
Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), ast_pickup_call(), attempt_transfer(), auto_congest(), cb_events(), 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(), mgcp_call(), misdn_attempt_transfer(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), remote_hold(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_transfer(), skinny_unhold(), ss_thread(), unistim_call(), and update_state().
{ struct ast_frame f = { AST_FRAME_CONTROL, }; f.subclass = control; return ast_queue_frame(chan, &f); }
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.
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 |
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.
Definition at line 1174 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::ptr, and ast_frame::subclass.
Referenced by change_t38_state(), dahdi_handle_event(), dahdi_hangup(), iax2_queue_control_data(), interpret_t38_parameters(), process_sdp(), and skinny_hold().
{ struct ast_frame f = { AST_FRAME_CONTROL, }; f.subclass = control; f.data.ptr = (void *) data; f.datalen = datalen; return ast_queue_frame(chan, &f); }
int ast_queue_frame | ( | struct ast_channel * | chan, |
struct ast_frame * | f | ||
) |
Queue one or more frames to a channel's frame queue.
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. |
0 | success |
non-zero | failure |
Definition at line 1121 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_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), bridge_write(), cb_events(), cli_console_answer(), cli_console_dial(), cli_console_flash(), cli_console_sendtext(), console_answer(), console_call(), console_dial(), console_do_answer(), console_flash(), console_sendtext(), dahdi_queue_frame(), dahdi_read(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), jingle_handle_dtmf(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), stream_monitor(), unistim_do_senddigit(), unistim_senddigit_end(), usbradio_read(), and wakeup_sub().
{ return __ast_queue_frame(chan, fin, 0, NULL); }
int ast_queue_frame_head | ( | struct ast_channel * | chan, |
struct ast_frame * | f | ||
) |
Queue one or more frames to the head of a channel's frame queue.
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. |
0 | success |
non-zero | failure |
Definition at line 1126 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_answer(), __ast_read(), ast_autoservice_stop(), ast_safe_sleep_conditional(), and feature_request_and_dial().
{ return __ast_queue_frame(chan, fin, 1, NULL); }
int ast_queue_hangup | ( | struct ast_channel * | chan | ) |
Queue a hangup frame.
Definition at line 1132 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().
{ struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; /* Yeah, let's not change a lock-critical value without locking */ if (!ast_channel_trylock(chan)) { chan->_softhangup |= AST_SOFTHANGUP_DEV; ast_channel_unlock(chan); } return ast_queue_frame(chan, &f); }
int ast_queue_hangup_with_cause | ( | struct ast_channel * | chan, |
int | cause | ||
) |
Queue a hangup frame with hangupcause set.
[in] | chan | channel to queue frame onto |
[in] | cause | the hangup cause |
Definition at line 1144 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, cause, ast_frame::data, ast_channel::hangupcause, and ast_frame::uint32.
Referenced by __oh323_update_info(), __sip_autodestruct(), close_call(), close_client(), console_hangup(), dahdi_handle_event(), handle_request_bye(), handle_response(), handle_response_invite(), handle_response_notify(), HandleCallOutgoing(), hangup_chan(), hangup_connection(), misdn_answer(), retrans_pkt(), and TransferCallStep1().
{ struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; if (cause >= 0) f.data.uint32 = cause; /* Yeah, let's not change a lock-critical value without locking */ if (!ast_channel_trylock(chan)) { chan->_softhangup |= AST_SOFTHANGUP_DEV; if (cause < 0) f.data.uint32 = chan->hangupcause; ast_channel_unlock(chan); } return ast_queue_frame(chan, &f); }
int ast_raw_answer | ( | struct ast_channel * | chan, |
int | cdr_answer | ||
) |
Answer a channel.
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.
0 | on success |
non-zero | on failure |
Definition at line 1919 of file channel.c.
References ast_channel::_state, ast_channel_tech::answer, ast_cdr_answer(), 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().
{ int res = 0; ast_channel_lock(chan); /* You can't answer an outbound call */ if (ast_test_flag(chan, AST_FLAG_OUTGOING)) { ast_channel_unlock(chan); return 0; } /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { ast_channel_unlock(chan); return -1; } ast_channel_unlock(chan); switch (chan->_state) { case AST_STATE_RINGING: case AST_STATE_RING: ast_channel_lock(chan); if (chan->tech->answer) { res = chan->tech->answer(chan); } ast_setstate(chan, AST_STATE_UP); if (cdr_answer) { ast_cdr_answer(chan->cdr); } ast_channel_unlock(chan); break; case AST_STATE_UP: /* Calling ast_cdr_answer when it it has previously been called * is essentially a no-op, so it is safe. */ if (cdr_answer) { ast_cdr_answer(chan->cdr); } break; default: break; } ast_indicate(chan, -1); chan->visible_indication = 0; return res; }
struct ast_frame* ast_read | ( | struct ast_channel * | chan | ) | [read] |
Reads a frame.
chan | channel to read a frame from |
Definition at line 3264 of file channel.c.
References __ast_read().
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), ast_bridge_handle_trip(), ast_generic_bridge(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_udptl_bridge(), ast_waitfordigit_full(), async_wait(), autoservice_run(), background_detect_exec(), bridge_native_loop(), bridge_p2p_loop(), channel_spy(), check_goto_on_transfer(), conf_exec(), conf_flush(), conf_run(), dahdi_bridge(), dial_exec_full(), dictate_exec(), disa_exec(), do_waiting(), echo_exec(), eivr_comm(), feature_request_and_dial(), find_cache(), handle_recordfile(), handle_speechrecognize(), iax2_bridge(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), manage_parkinglot(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), recordthread(), rpt(), rpt_exec(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().
{ return __ast_read(chan, 0); }
struct ast_frame* ast_read_noaudio | ( | struct ast_channel * | chan | ) | [read] |
Reads a frame, returning AST_FRAME_NULL frame if audio.
chan | channel to read a frame from |
Definition at line 3269 of file channel.c.
References __ast_read().
Referenced by ast_bridge_handle_trip(), and conf_run().
{ return __ast_read(chan, 1); }
int ast_readstring | ( | struct ast_channel * | c, |
char * | s, | ||
int | len, | ||
int | timeout, | ||
int | rtimeout, | ||
char * | enders | ||
) |
Reads multiple digits
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 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 4406 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().
{ return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1); }
int ast_readstring_full | ( | struct ast_channel * | c, |
char * | s, | ||
int | len, | ||
int | timeout, | ||
int | rtimeout, | ||
char * | enders, | ||
int | audiofd, | ||
int | ctrlfd | ||
) |
Definition at line 4411 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().
{ int pos = 0; /* index in the buffer where we accumulate digits */ int to = ftimeout; struct ast_silence_generator *silgen = NULL; /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) return -1; if (!len) return -1; for (;;) { int d; if (c->stream) { d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); ast_stopstream(c); if (!silgen && ast_opt_transmit_silence) silgen = ast_channel_start_silence_generator(c); usleep(1000); if (!d) d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); } else { if (!silgen && ast_opt_transmit_silence) silgen = ast_channel_start_silence_generator(c); d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); } if (d < 0) { ast_channel_stop_silence_generator(c, silgen); return AST_GETDATA_FAILED; } if (d == 0) { s[pos] = '\0'; ast_channel_stop_silence_generator(c, silgen); return AST_GETDATA_TIMEOUT; } if (d == 1) { s[pos] = '\0'; ast_channel_stop_silence_generator(c, silgen); return AST_GETDATA_INTERRUPTED; } if (strchr(enders, d) && (pos == 0)) { s[pos] = '\0'; ast_channel_stop_silence_generator(c, silgen); return AST_GETDATA_EMPTY_END_TERMINATED; } if (!strchr(enders, d)) { s[pos++] = d; } if (strchr(enders, d) || (pos >= len)) { s[pos] = '\0'; ast_channel_stop_silence_generator(c, silgen); return AST_GETDATA_COMPLETE; } to = timeout; } /* Never reached */ return 0; }
int ast_recvchar | ( | struct ast_channel * | chan, |
int | timeout | ||
) |
Receives a text character from a channel.
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 3432 of file channel.c.
References ast_free, and ast_recvtext().
Referenced by handle_recvchar().
{ int c; char *buf = ast_recvtext(chan, timeout); if (buf == NULL) return -1; /* error or timeout */ c = *(unsigned char *)buf; ast_free(buf); return c; }
char* ast_recvtext | ( | struct ast_channel * | chan, |
int | timeout | ||
) |
Receives a text string from a channel Read a string of text from a channel.
chan | channel to act upon |
timeout | timeout in milliseconds (0 for infinite wait) |
Definition at line 3443 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(), buf, ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, ast_frame::ptr, and ast_frame::subclass.
Referenced by ast_recvchar(), and handle_recvtext().
{ int res, done = 0; char *buf = NULL; while (!done) { struct ast_frame *f; if (ast_check_hangup(chan)) break; res = ast_waitfor(chan, timeout); if (res <= 0) /* timeout or error */ break; timeout = res; /* update timeout */ f = ast_read(chan); if (f == NULL) break; /* no frame */ if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) done = 1; /* force a break */ else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ buf = ast_strndup((char *) f->data.ptr, f->datalen); /* dup and break */ done = 1; } ast_frfree(f); } return buf; }
struct ast_channel* ast_request | ( | const char * | type, |
int | format, | ||
void * | data, | ||
int * | status | ||
) | [read] |
Requests a channel.
type | type of channel to request |
format | requested channel format (codec) |
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
NULL | failure |
non-NULL | channel on success |
Definition at line 4305 of file channel.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_translator_best_choice(), ast_channel_tech::capabilities, capabilities, chanlist::chan, LOG_WARNING, ast_channel_tech::requester, chanlist::tech, and ast_channel_tech::type.
Referenced by __ast_request_and_dial(), agent_request(), 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().
{ struct chanlist *chan; struct ast_channel *c; int capabilities; int fmt; int res; int foo; int videoformat = format & AST_FORMAT_VIDEO_MASK; int textformat = format & AST_FORMAT_TEXT_MASK; if (!cause) cause = &foo; *cause = AST_CAUSE_NOTDEFINED; if (AST_RWLIST_RDLOCK(&channels)) { ast_log(LOG_WARNING, "Unable to lock channel list\n"); return NULL; } AST_LIST_TRAVERSE(&backends, chan, list) { if (strcasecmp(type, chan->tech->type)) continue; capabilities = chan->tech->capabilities; fmt = format & AST_FORMAT_AUDIO_MASK; if (fmt) { /* We have audio - is it possible to connect the various calls to each other? (Avoid this check for calls without audio, like text+video calls) */ res = ast_translator_best_choice(&fmt, &capabilities); if (res < 0) { ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format); *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; AST_RWLIST_UNLOCK(&channels); return NULL; } } AST_RWLIST_UNLOCK(&channels); if (!chan->tech->requester) return NULL; if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, data, cause))) return NULL; /* no need to generate a Newchannel event here; it is done in the channel_alloc call */ return c; } ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type); *cause = AST_CAUSE_NOSUCHDRIVER; AST_RWLIST_UNLOCK(&channels); return NULL; }
struct ast_channel* ast_request_and_dial | ( | const char * | type, |
int | format, | ||
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.
type | type of channel to request |
format | requested channel format |
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) |
Definition at line 4300 of file channel.c.
References __ast_request_and_dial().
Referenced by ast_pbx_outgoing_exten().
{ return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL); }
int ast_safe_sleep | ( | struct ast_channel * | chan, |
int | ms | ||
) |
Wait for a specified amount of time, looking for hangups.
chan | channel to wait for |
ms | length of time in milliseconds to sleep Waits for a specified amount of time, servicing the channel as required. |
Definition at line 1462 of file channel.c.
References ast_safe_sleep_conditional().
Referenced by _ast_adsi_transmit_message_full(), alarmreceiver_exec(), ast_dtmf_stream(), ast_senddigit(), builtin_atxfer(), builtin_parkcall(), conf_run(), dictate_exec(), disa_exec(), flash_exec(), function_ilink(), handle_callforward_button(), login_exec(), mgcp_ss(), milliwatt_exec(), misdn_check_l2l1(), old_milliwatt_exec(), park_call_exec(), pbx_builtin_wait(), play_moh_exec(), play_tone_pair(), playtone(), privacy_exec(), receive_ademco_contact_id(), rpt_call(), rpt_exec(), rpt_tele_thread(), send_morse(), send_tone_telemetry(), skinny_ss(), ss_thread(), testclient_exec(), testserver_exec(), try_calling(), wait_for_hangup(), wait_interval(), wait_moh_exec(), waituntil_exec(), and zapateller_exec().
{ return ast_safe_sleep_conditional(chan, ms, NULL, NULL); }
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.
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 |
Definition at line 1395 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, f, and ast_channel::generatordata.
Referenced by ast_safe_sleep(), and login_exec().
{ struct ast_frame *f; struct ast_silence_generator *silgen = NULL; int res = 0; AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames; AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames); /* If no other generator is present, start silencegen while waiting */ if (ast_opt_transmit_silence && !chan->generatordata) { silgen = ast_channel_start_silence_generator(chan); } while (ms > 0) { struct ast_frame *dup_f = NULL; if (cond && ((*cond)(data) == 0)) { break; } ms = ast_waitfor(chan, ms); if (ms < 0) { res = -1; break; } if (ms > 0) { f = ast_read(chan); if (!f) { res = -1; break; } if (!ast_is_deferrable_frame(f)) { ast_frfree(f); continue; } if ((dup_f = ast_frisolate(f))) { if (dup_f != f) { ast_frfree(f); } AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list); } } } /* stop silgen if present */ if (silgen) { ast_channel_stop_silence_generator(chan, silgen); } /* We need to free all the deferred frames, but we only need to * queue the deferred frames if there was no error and no * hangup was received */ ast_channel_lock(chan); while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) { if (!res) { ast_queue_frame_head(chan, f); } ast_frfree(f); } ast_channel_unlock(chan); return res; }
int ast_senddigit | ( | struct ast_channel * | chan, |
char | digit, | ||
unsigned int | duration | ||
) |
Send a DTMF digit to a channel Send a DTMF digit to a channel.
chan | channel to act upon |
digit | the DTMF digit to send, encoded in ASCII |
duration | the duration of the digit ending in ms |
Definition at line 3546 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().
{ if (chan->tech->send_digit_begin) { ast_senddigit_begin(chan, digit); ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); } return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); }
int ast_senddigit_begin | ( | struct ast_channel * | chan, |
char | digit | ||
) |
Send a DTMF digit to a channel Send a DTMF digit to a channel.
chan | channel to act upon |
digit | the DTMF digit to send, encoded in ASCII |
Definition at line 3488 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().
{ /* Device does not support DTMF tones, lets fake * it by doing our own generation. */ static const char* dtmf_tones[] = { "941+1336", /* 0 */ "697+1209", /* 1 */ "697+1336", /* 2 */ "697+1477", /* 3 */ "770+1209", /* 4 */ "770+1336", /* 5 */ "770+1477", /* 6 */ "852+1209", /* 7 */ "852+1336", /* 8 */ "852+1477", /* 9 */ "697+1633", /* A */ "770+1633", /* B */ "852+1633", /* C */ "941+1633", /* D */ "941+1209", /* * */ "941+1477" /* # */ }; if (!chan->tech->send_digit_begin) return 0; if (!chan->tech->send_digit_begin(chan, digit)) return 0; if (digit >= '0' && digit <='9') ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0); else if (digit >= 'A' && digit <= 'D') ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0); else if (digit == '*') ast_playtones_start(chan, 0, dtmf_tones[14], 0); else if (digit == '#') ast_playtones_start(chan, 0, dtmf_tones[15], 0); else { /* not handled */ ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name); } return 0; }
int ast_senddigit_end | ( | struct ast_channel * | chan, |
char | digit, | ||
unsigned int | duration | ||
) |
Send a DTMF digit to a channel.
Send a DTMF digit to a channel.
chan | channel to act upon |
digit | the DTMF digit to send, encoded in ASCII |
duration | the duration of the digit ending in ms |
Definition at line 3533 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().
{ int res = -1; if (chan->tech->send_digit_end) res = chan->tech->send_digit_end(chan, digit, duration); if (res && chan->generator) ast_playtones_stop(chan); return 0; }
int ast_sendtext | ( | struct ast_channel * | chan, |
const char * | text | ||
) |
Sends text to a channel.
chan | channel to act upon |
text | string of text to send on the channel |
Write text to a display on a channel
0 | on success |
-1 | on failure |
Definition at line 3470 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_test_flag, CHECK_BLOCKING, ast_channel_tech::send_text, and ast_channel::tech.
Referenced by action_sendtext(), agent_sendtext(), handle_sendtext(), send_newkey(), and sendtext_exec().
{ int res = 0; ast_channel_lock(chan); /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { ast_channel_unlock(chan); return -1; } CHECK_BLOCKING(chan); if (chan->tech->send_text) res = chan->tech->send_text(chan, text); ast_clear_flag(chan, AST_FLAG_BLOCKING); ast_channel_unlock(chan); return res; }
void ast_set_callerid | ( | struct ast_channel * | chan, |
const char * | cid_num, | ||
const char * | cid_name, | ||
const char * | cid_ani | ||
) |
Set caller ID number, name and ANI.
Definition at line 5022 of file channel.c.
References ast_cdr_setcid(), ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, and report_new_callerid().
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), callerid_write(), dahdi_read(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), findmeexec(), handle_setcallerid(), mgcp_ss(), privacy_exec(), read_config(), rpt_exec(), skinny_newcall(), and ss_thread().
{ ast_channel_lock(chan); if (cid_num) { if (chan->cid.cid_num) ast_free(chan->cid.cid_num); chan->cid.cid_num = ast_strdup(cid_num); } if (cid_name) { if (chan->cid.cid_name) ast_free(chan->cid.cid_name); chan->cid.cid_name = ast_strdup(cid_name); } if (cid_ani) { if (chan->cid.cid_ani) ast_free(chan->cid.cid_ani); chan->cid.cid_ani = ast_strdup(cid_ani); } if (chan->cdr) { ast_cdr_setcid(chan->cdr, chan); } report_new_callerid(chan); ast_channel_unlock(chan); }
int ast_set_read_format | ( | struct ast_channel * | chan, |
int | format | ||
) |
Sets read format on channel chan Set read format for channel to whichever component of "format" is best.
chan | channel to change |
format | format to change to |
Definition at line 4033 of file channel.c.
References ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().
Referenced by __ast_play_and_record(), __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_do_masquerade(), attempt_reconnect(), background_detect_exec(), bridge_channel_join(), bridge_make_compatible(), build_conf(), conf_run(), connect_link(), dictate_exec(), do_waiting(), eagi_exec(), echo_exec(), gtalk_rtp_read(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), jingle_rtp_read(), login_exec(), measurenoise(), mgcp_rtp_read(), oh323_rtp_read(), old_milliwatt_exec(), process_sdp(), record_exec(), rpt(), rpt_exec(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), transmit_audio(), and unistim_rtp_read().
{ return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat, &chan->readtrans, 0); }
void ast_set_variables | ( | struct ast_channel * | chan, |
struct ast_variable * | vars | ||
) |
adds a list of channel variables to a channel
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 5969 of file channel.c.
References ast_variable::name, ast_variable::next, pbx_builtin_setvar_helper(), and ast_variable::value.
Referenced by __ast_request_and_dial(), ast_call_forward(), ast_pbx_outgoing_app(), and ast_pbx_outgoing_exten().
{ struct ast_variable *cur; for (cur = vars; cur; cur = cur->next) pbx_builtin_setvar_helper(chan, cur->name, cur->value); }
int ast_set_write_format | ( | struct ast_channel * | chan, |
int | format | ||
) |
Sets write format on channel chan Set write format for channel to whichever component of "format" is best.
chan | channel to change |
format | new format for writing |
Definition at line 4039 of file channel.c.
References ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.
Referenced by __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_do_masquerade(), ast_openstream_full(), ast_stopstream(), attempt_reconnect(), bridge_channel_join(), bridge_make_compatible(), build_conf(), chanspy_exec(), conf_run(), connect_link(), echo_exec(), extenspy_exec(), gtalk_rtp_read(), jack_exec(), jingle_rtp_read(), linear_alloc(), linear_release(), login_exec(), mgcp_rtp_read(), moh_alloc(), moh_files_release(), moh_release(), mp3_exec(), NBScat_exec(), oh323_rtp_read(), old_milliwatt_exec(), playtones_alloc(), playtones_release(), process_sdp(), rpt(), rpt_exec(), send_waveform_to_channel(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), tonepair_alloc(), tonepair_release(), transmit_audio(), and unistim_rtp_read().
{ return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat, &chan->writetrans, 1); }
int ast_setstate | ( | struct ast_channel * | chan, |
enum | ast_channel_state | ||
) |
Change the state of a channel.
Definition at line 5050 of file channel.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_copy_string(), AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), ast_state2str(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, ast_channel::name, name, S_OR, and ast_channel::uniqueid.
Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), agent_call(), alsa_answer(), ast_raw_answer(), cb_events(), check_availability(), console_answer(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), do_bridge_masquerade(), gtalk_call(), gtalk_newcall(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_response_invite(), handle_soft_key_event_message(), handle_stimulus_message(), iax2_call(), jingle_call(), jingle_newcall(), local_queue_frame(), mgcp_answer(), mgcp_call(), mgcp_ss(), misdn_call(), misdn_indication(), nbs_call(), nbs_hangup(), oh323_answer(), oss_answer(), pbx_builtin_busy(), pbx_builtin_congestion(), phone_answer(), phone_call(), phone_exception(), phone_hangup(), phone_write(), release_chan(), release_chan_early(), sip_answer(), skinny_answer(), skinny_call(), skinny_newcall(), ss_thread(), unistim_answer(), unistim_call(), unistim_new(), unistim_ss(), update_state(), usbradio_answer(), and usbradio_call().
{ int oldstate = chan->_state; char name[AST_CHANNEL_NAME], *dashptr; if (oldstate == state) return 0; ast_copy_string(name, chan->name, sizeof(name)); if ((dashptr = strrchr(name, '-'))) { *dashptr = '\0'; } chan->_state = state; /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver * for this channel is using the callback method for device state. If we pass in an actual state here * we override what they are saying the state is and things go amuck. */ ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); /* setstate used to conditionally report Newchannel; this is no more */ manager_event(EVENT_FLAG_CALL, "Newstate", "Channel: %s\r\n" "ChannelState: %d\r\n" "ChannelStateDesc: %s\r\n" "CallerIDNum: %s\r\n" "CallerIDName: %s\r\n" "Uniqueid: %s\r\n", chan->name, chan->_state, ast_state2str(chan->_state), S_OR(chan->cid.cid_num, ""), S_OR(chan->cid.cid_name, ""), chan->uniqueid); return 0; }
int ast_settimeout | ( | struct ast_channel * | c, |
unsigned int | rate, | ||
int(*)(const void *data) | func, | ||
void * | data | ||
) |
Enable or disable timer ticks for a channel.
rate | number of timer ticks per second |
If timers are supported, force a scheduled expiration on the timer fd, at which point we call the callback function / data
Call this function with a rate of 0 to turn off the timer ticks
Definition at line 2527 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, ast_timer_get_max_rate(), ast_timer_set_rate(), ast_channel::data, 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().
{ int res; unsigned int real_rate = rate, max_rate; ast_channel_lock(c); if (c->timingfd == -1) { ast_channel_unlock(c); return -1; } if (!func) { rate = 0; data = NULL; } if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) { real_rate = max_rate; } ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate); res = ast_timer_set_rate(c->timer, real_rate); c->timingfunc = func; c->timingdata = data; ast_channel_unlock(c); return res; }
int ast_shutting_down | ( | void | ) |
Returns non-zero if Asterisk is being shut down.
Returns non-zero if Asterisk is being shut down
Definition at line 515 of file channel.c.
References shutting_down.
Referenced by handle_request_options().
{ return shutting_down; }
int ast_softhangup | ( | struct ast_channel * | chan, |
int | cause | ||
) |
Softly hangup up a channel.
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.
Definition at line 1786 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().
Referenced by __ast_module_user_hangup_all(), __ast_pbx_run(), __unload_module(), action_hangup(), agent_hangup(), agent_logoff(), agent_read(), ast_begin_shutdown(), ast_dial_join(), birdbath(), conf_free(), connect_link(), dahdi_handle_event(), flush_telem(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), login_exec(), manager_park(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), rpt_exec(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().
{ int res; ast_channel_lock(chan); res = ast_softhangup_nolock(chan, cause); ast_channel_unlock(chan); return res; }
int ast_softhangup_nolock | ( | struct ast_channel * | chan, |
int | cause | ||
) |
Softly hangup up a channel (no channel lock)
chan | channel to be soft-hung-up |
reason | an AST_SOFTHANGUP_* reason code |
Definition at line 1773 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, cause, and ast_channel::name.
Referenced by ast_async_goto(), ast_softhangup(), attempt_transfer(), check_pendings(), check_rtp_timeout(), dahdi_softhangup_all(), oh323_indicate(), proc_session_timer(), sip_indicate(), and skinny_indicate().
{ ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name); /* Inform channel driver that we need to be hung up, if it cares */ chan->_softhangup |= cause; ast_queue_frame(chan, &ast_null_frame); /* Interrupt any poll call or such */ if (ast_test_flag(chan, AST_FLAG_BLOCKING)) pthread_kill(chan->blocker, SIGURG); return 0; }
const char* ast_state2str | ( | enum ast_channel_state | state | ) |
Gives the string form of a given channel state.
Gives the string form of a given channel state
ast_channel_state | state to get the name of Give a name to a state Returns the text form of the binary state given |
Definition at line 656 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(), buf, and STATE2STR_BUFSIZE.
Referenced by __ast_channel_alloc_ap(), action_coreshowchannels(), action_status(), agent_hangup(), ast_do_masquerade(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_invite_replaces(), handle_showchan(), local_attended_transfer(), mgcp_new(), serialize_showchan(), and sip_hangup().
{ char *buf; switch (state) { case AST_STATE_DOWN: return "Down"; case AST_STATE_RESERVED: return "Rsrvd"; case AST_STATE_OFFHOOK: return "OffHook"; case AST_STATE_DIALING: return "Dialing"; case AST_STATE_RING: return "Ring"; case AST_STATE_RINGING: return "Ringing"; case AST_STATE_UP: return "Up"; case AST_STATE_BUSY: return "Busy"; case AST_STATE_DIALING_OFFHOOK: return "Dialing Offhook"; case AST_STATE_PRERING: return "Pre-ring"; default: if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE))) return "Unknown"; snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state); return buf; } }
int ast_str2cause | ( | const char * | name | ) |
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 5826 of file channel.c.
References ast_frfree, ast_read(), ast_tonepair_start(), ast_waitfor(), f, and ast_channel::generatordata.
Referenced by zapateller_exec().
{ int res; if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol))) return res; /* Give us some wiggle room */ while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { struct ast_frame *f = ast_read(chan); if (f) ast_frfree(f); else return -1; } return 0; }
int ast_tonepair_start | ( | struct ast_channel * | chan, |
int | freq1, | ||
int | freq2, | ||
int | duration, | ||
int | vol | ||
) |
Start a tone going
Definition at line 5808 of file channel.c.
References ast_activate_generator(), tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, tonepair, and tonepair_def::vol.
Referenced by ast_tonepair(), pbx_builtin_waitexten(), play_dialtone(), play_tone_pair(), rpt_tele_thread(), and sendnoise().
void ast_tonepair_stop | ( | struct ast_channel * | chan | ) |
Stop a tone from playing
Definition at line 5821 of file channel.c.
References ast_deactivate_generator().
Referenced by sendnoise().
{ ast_deactivate_generator(chan); }
int ast_transfer | ( | struct ast_channel * | chan, |
char * | dest | ||
) |
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
chan | current channel |
dest | destination extension for transfer |
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
Called by:
Definition at line 4388 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_ZOMBIE, ast_test_flag, ast_channel::tech, and ast_channel_tech::transfer.
Referenced by transfer_exec().
{ int res = -1; /* Stop if we're a zombie or need a soft hangup */ ast_channel_lock(chan); if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { if (chan->tech->transfer) { res = chan->tech->transfer(chan, dest); if (!res) res = 1; } else res = 0; } ast_channel_unlock(chan); return res; }
char* ast_transfercapability2str | ( | int | transfercapability | ) | const |
Gives the string form of a given transfer capability.
Gives the string form of a given transfer capability
transfercapability | transfercapabilty to get the name of Give a name to a transfercapbility See above Returns the text form of the binary transfer capability |
Definition at line 690 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 cb_events(), dahdi_call(), dahdi_new(), misdn_call(), and oh323_call().
{ switch (transfercapability) { case AST_TRANS_CAP_SPEECH: return "SPEECH"; case AST_TRANS_CAP_DIGITAL: return "DIGITAL"; case AST_TRANS_CAP_RESTRICTED_DIGITAL: return "RESTRICTED_DIGITAL"; case AST_TRANS_CAP_3_1K_AUDIO: return "3K1AUDIO"; case AST_TRANS_CAP_DIGITAL_W_TONES: return "DIGITAL_W_TONES"; case AST_TRANS_CAP_VIDEO: return "VIDEO"; default: return "UNKNOWN"; } }
int ast_waitfor | ( | struct ast_channel * | chan, |
int | ms | ||
) |
Wait for input on a channel.
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). |
Definition at line 2511 of file channel.c.
References ast_waitfor_nandfds().
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), ast_dtmf_stream(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), async_wait(), background_detect_exec(), channel_spy(), conf_exec(), conf_flush(), dictate_exec(), disa_exec(), do_waiting(), echo_exec(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), measurenoise(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), recordthread(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_hangup(), waitforring_exec(), and waitstream_core().
{ int oldms = ms; /* -1 if no timeout */ ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); if ((ms < 0) && (oldms < 0)) ms = 0; return ms; }
struct ast_channel* ast_waitfor_n | ( | struct ast_channel ** | chan, |
int | n, | ||
int * | ms | ||
) | [read] |
Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.
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 2506 of file channel.c.
References ast_waitfor_nandfds().
Referenced by ast_generic_bridge(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), bridge_p2p_loop(), dahdi_bridge(), dial_exec_full(), feature_request_and_dial(), generic_thread_loop(), iax2_bridge(), misdn_bridge(), monitor_dial(), rpt(), rpt_exec(), wait_for_answer(), and wait_for_winner().
{ return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms); }
int ast_waitfor_n_fd | ( | int * | fds, |
int | n, | ||
int * | ms, | ||
int * | exception | ||
) |
Waits for input on an fd This version works on fd's only. Be careful with it.
Definition at line 2146 of file channel.c.
References ast_waitfor_nandfds().
Referenced by dundi_lookup_internal(), dundi_precache_internal(), and softmix_bridge_thread().
{ int winner = -1; ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms); return winner; }
struct ast_channel* ast_waitfor_nandfds | ( | struct ast_channel ** | c, |
int | n, | ||
int * | fds, | ||
int | nfds, | ||
int * | exception, | ||
int * | outfd, | ||
int * | ms | ||
) | [read] |
Waits for activity on a group of channels.
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. |
Definition at line 2158 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(), chanlist::chan, 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(), multiplexed_thread_function(), run_agi(), and waitstream_core().
{ struct timeval start = { 0 , 0 }; struct pollfd *pfds = NULL; int res; long rms; int x, y, max; int sz; struct timeval now = { 0, 0 }; struct timeval whentohangup = { 0, 0 }, diff; struct ast_channel *winner = NULL; struct fdmap { int chan; int fdno; } *fdmap = NULL; if ((sz = n * AST_MAX_FDS + nfds)) { pfds = alloca(sizeof(*pfds) * sz); fdmap = alloca(sizeof(*fdmap) * sz); } if (outfd) *outfd = -99999; if (exception) *exception = 0; /* Perform any pending masquerades */ for (x = 0; x < n; x++) { ast_channel_lock(c[x]); if (c[x]->masq && ast_do_masquerade(c[x])) { ast_log(LOG_WARNING, "Masquerade failed\n"); *ms = -1; ast_channel_unlock(c[x]); return NULL; } if (!ast_tvzero(c[x]->whentohangup)) { if (ast_tvzero(whentohangup)) now = ast_tvnow(); diff = ast_tvsub(c[x]->whentohangup, now); if (diff.tv_sec < 0 || ast_tvzero(diff)) { /* Should already be hungup */ c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; ast_channel_unlock(c[x]); return c[x]; } if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0) whentohangup = diff; } ast_channel_unlock(c[x]); } /* Wait full interval */ rms = *ms; /* INT_MAX, not LONG_MAX, because it matters on 64-bit */ if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) { rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000; /* timeout in milliseconds */ if (*ms >= 0 && *ms < rms) { /* original *ms still smaller */ rms = *ms; } } else if (!ast_tvzero(whentohangup) && rms < 0) { /* Tiny corner case... call would need to last >24 days */ rms = INT_MAX; } /* * Build the pollfd array, putting the channels' fds first, * followed by individual fds. Order is important because * individual fd's must have priority over channel fds. */ max = 0; for (x = 0; x < n; x++) { for (y = 0; y < AST_MAX_FDS; y++) { fdmap[max].fdno = y; /* fd y is linked to this pfds */ fdmap[max].chan = x; /* channel x is linked to this pfds */ max += ast_add_fd(&pfds[max], c[x]->fds[y]); } CHECK_BLOCKING(c[x]); } /* Add the individual fds */ for (x = 0; x < nfds; x++) { fdmap[max].chan = -1; max += ast_add_fd(&pfds[max], fds[x]); } if (*ms > 0) start = ast_tvnow(); if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */ do { int kbrms = rms; if (kbrms > 600000) kbrms = 600000; res = ast_poll(pfds, max, kbrms); if (!res) rms -= kbrms; } while (!res && (rms > 0)); } else { res = ast_poll(pfds, max, rms); } for (x = 0; x < n; x++) ast_clear_flag(c[x], AST_FLAG_BLOCKING); if (res < 0) { /* Simulate a timeout if we were interrupted */ if (errno != EINTR) *ms = -1; return NULL; } if (!ast_tvzero(whentohangup)) { /* if we have a timeout, check who expired */ now = ast_tvnow(); for (x = 0; x < n; x++) { if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) { c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; if (winner == NULL) winner = c[x]; } } } if (res == 0) { /* no fd ready, reset timeout and done */ *ms = 0; /* XXX use 0 since we may not have an exact timeout. */ return winner; } /* * Then check if any channel or fd has a pending event. * Remember to check channels first and fds last, as they * must have priority on setting 'winner' */ for (x = 0; x < max; x++) { res = pfds[x].revents; if (res == 0) continue; if (fdmap[x].chan >= 0) { /* this is a channel */ winner = c[fdmap[x].chan]; /* override previous winners */ if (res & POLLPRI) ast_set_flag(winner, AST_FLAG_EXCEPTION); else ast_clear_flag(winner, AST_FLAG_EXCEPTION); winner->fdno = fdmap[x].fdno; } else { /* this is an fd */ if (outfd) *outfd = pfds[x].fd; if (exception) *exception = (res & POLLPRI) ? -1 : 0; winner = NULL; } } if (*ms > 0) { *ms -= ast_tvdiff_ms(ast_tvnow(), start); if (*ms < 0) *ms = 0; } return winner; }
int ast_waitfordigit | ( | struct ast_channel * | c, |
int | ms | ||
) |
Waits for a digit.
!
c | channel to wait for a digit on |
ms | how many milliseconds to wait |
Definition at line 2522 of file channel.c.
References ast_waitfordigit_full().
Referenced by _ast_adsi_get_cpeid(), _ast_adsi_get_cpeinfo(), _ast_adsi_print(), _ast_adsi_read_encoded_dtmf(), _ast_adsi_transmit_message_full(), _while_exec(), advanced_options(), ast_app_dtget(), ast_control_streamfile(), ast_record_review(), bridge_channel_feature(), builtin_atxfer(), collect_digits(), common_exec(), cpeid_exec(), dialout(), directory_exec(), forward_message(), get_folder(), ivr_dispatch(), mgcp_ss(), my_getsigstr(), pbx_builtin_waitexten(), play_record_review(), read_exec(), read_newoption(), readexten_exec(), retrydial_exec(), select_item_menu(), select_item_pause(), select_item_seq(), sendnoise(), ss_thread(), testclient_exec(), testserver_exec(), vm_execmain(), vm_forwardoptions(), vm_instructions_en(), vm_options(), vm_tempgreeting(), wait_a_bit(), and wait_our_turn().
{ return ast_waitfordigit_full(c, ms, -1, -1); }
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.
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 |
Definition at line 2560 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, 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, f, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.
Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().
{ /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) return -1; /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */ ast_set_flag(c, AST_FLAG_END_DTMF_ONLY); /* Wait for a digit, no more than ms milliseconds total. */ while (ms) { struct ast_channel *rchan; int outfd=-1; errno = 0; rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms); if (!rchan && outfd < 0 && ms) { if (errno == 0 || errno == EINTR) continue; ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno)); ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); return -1; } else if (outfd > -1) { /* The FD we were watching has something waiting */ ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n"); ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); return 1; } else if (rchan) { int res; struct ast_frame *f = ast_read(c); if (!f) return -1; switch (f->frametype) { case AST_FRAME_DTMF_BEGIN: break; case AST_FRAME_DTMF_END: res = f->subclass; ast_frfree(f); ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); return res; case AST_FRAME_CONTROL: switch (f->subclass) { case AST_CONTROL_HANGUP: ast_frfree(f); ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); return -1; case AST_CONTROL_RINGING: case AST_CONTROL_ANSWER: case AST_CONTROL_SRCUPDATE: case AST_CONTROL_SRCCHANGE: /* Unimportant */ break; default: ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass); break; } break; case AST_FRAME_VOICE: /* Write audio if appropriate */ if (audiofd > -1) { if (write(audiofd, f->data.ptr, f->datalen) < 0) { ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); } } default: /* Ignore */ break; } ast_frfree(f); } } ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); return 0; /* Time is up */ }
struct ast_channel* ast_walk_channel_by_exten_locked | ( | const struct ast_channel * | chan, |
const char * | exten, | ||
const char * | context | ||
) | [read] |
Get next channel by exten (and optionally context) and lock it.
Definition at line 1344 of file channel.c.
References channel_find_locked().
Referenced by next_channel().
{ return channel_find_locked(chan, NULL, 0, context, exten); }
struct ast_channel* ast_walk_channel_by_name_prefix_locked | ( | const struct ast_channel * | chan, |
const char * | name, | ||
const int | namelen | ||
) | [read] |
Get channel by name or uniqueid prefix (locks channel)
Definition at line 1331 of file channel.c.
References channel_find_locked().
Referenced by my_ast_get_channel_by_name_locked(), next_channel(), and softhangup_exec().
{ return channel_find_locked(chan, name, namelen, NULL, NULL); }
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.
chan | destination channel of the frame |
frame | frame that will be written |
Definition at line 3688 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_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::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_filestream::fmt, ast_format::format, ast_channel::fout, FRAMECOUNT_INC, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, 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(), bridge_native_loop(), bridge_p2p_loop(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), fax_generator_generate(), feature_request_and_dial(), function_ilink(), gen_generate(), handle_jack_audio(), handle_link_data(), iax2_bridge(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), multiplexed_bridge_write(), NBScat_exec(), playtones_generator(), 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().
{ int res = -1; struct ast_frame *f = NULL; int count = 0; /*Deadlock avoidance*/ while(ast_channel_trylock(chan)) { /*cannot goto done since the channel is not locked*/ if(count++ > 10) { ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name); return 0; } usleep(1); } /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) goto done; /* Handle any pending masquerades */ if (chan->masq && ast_do_masquerade(chan)) { ast_log(LOG_WARNING, "Failed to perform masquerade\n"); goto done; } if (chan->masqr) { res = 0; /* XXX explain, why 0 ? */ goto done; } if (chan->generatordata && (!fr->src || strcasecmp(fr->src, "ast_prod"))) { if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) { ast_deactivate_generator(chan); } else { if (fr->frametype == AST_FRAME_DTMF_END) { /* There is a generator running while we're in the middle of a digit. * It's probably inband DTMF, so go ahead and pass it so it can * stop the generator */ ast_clear_flag(chan, AST_FLAG_BLOCKING); ast_channel_unlock(chan); res = ast_senddigit_end(chan, fr->subclass, fr->len); ast_channel_lock(chan); CHECK_BLOCKING(chan); } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) { /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */ res = (chan->tech->indicate == NULL) ? 0 : chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); } res = 0; /* XXX explain, why 0 ? */ goto done; } } /* High bit prints debugging */ if (chan->fout & DEBUGCHAN_FLAG) ast_frame_dump(chan->name, fr, ">>"); CHECK_BLOCKING(chan); switch (fr->frametype) { case AST_FRAME_CONTROL: res = (chan->tech->indicate == NULL) ? 0 : chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); break; case AST_FRAME_DTMF_BEGIN: if (chan->audiohooks) { struct ast_frame *old_frame = fr; fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); if (old_frame != fr) f = fr; } send_dtmf_event(chan, "Sent", fr->subclass, "Yes", "No"); ast_clear_flag(chan, AST_FLAG_BLOCKING); ast_channel_unlock(chan); res = ast_senddigit_begin(chan, fr->subclass); ast_channel_lock(chan); CHECK_BLOCKING(chan); break; case AST_FRAME_DTMF_END: if (chan->audiohooks) { struct ast_frame *new_frame = fr; new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); if (new_frame != fr) { ast_frfree(new_frame); } } send_dtmf_event(chan, "Sent", fr->subclass, "No", "Yes"); ast_clear_flag(chan, AST_FLAG_BLOCKING); ast_channel_unlock(chan); res = ast_senddigit_end(chan, fr->subclass, fr->len); ast_channel_lock(chan); CHECK_BLOCKING(chan); break; case AST_FRAME_TEXT: if (fr->subclass == AST_FORMAT_T140) { res = (chan->tech->write_text == NULL) ? 0 : chan->tech->write_text(chan, fr); } else { res = (chan->tech->send_text == NULL) ? 0 : chan->tech->send_text(chan, (char *) fr->data.ptr); } break; case AST_FRAME_HTML: res = (chan->tech->send_html == NULL) ? 0 : chan->tech->send_html(chan, fr->subclass, (char *) fr->data.ptr, fr->datalen); break; case AST_FRAME_VIDEO: /* XXX Handle translation of video codecs one day XXX */ res = (chan->tech->write_video == NULL) ? 0 : chan->tech->write_video(chan, fr); break; case AST_FRAME_MODEM: res = (chan->tech->write == NULL) ? 0 : chan->tech->write(chan, fr); break; case AST_FRAME_VOICE: if (chan->tech->write == NULL) break; /*! \todo XXX should return 0 maybe ? */ if (ast_opt_generic_plc && fr->subclass == AST_FORMAT_SLINEAR) { apply_plc(chan, fr); } /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */ if (fr->subclass == chan->rawwriteformat) f = fr; else f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr; if (!f) { res = 0; break; } if (chan->audiohooks) { struct ast_frame *prev = NULL, *new_frame, *cur, *dup; int freeoldlist = 0; if (f != fr) { freeoldlist = 1; } /* Since ast_audiohook_write may return a new frame, and the cur frame is * an item in a list of frames, create a new list adding each cur frame back to it * regardless if the cur frame changes or not. */ for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur); /* if this frame is different than cur, preserve the end of the list, * free the old frames, and set cur to be the new frame */ if (new_frame != cur) { /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame * isn't part of local storage, meaning if ast_audiohook_write is called multiple * times it may override the previous frame we got from it unless we dup it */ if ((dup = ast_frisolate(new_frame))) { AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list); if (freeoldlist) { AST_LIST_NEXT(cur, frame_list) = NULL; ast_frfree(cur); } if (new_frame != dup) { ast_frfree(new_frame); } cur = dup; } } /* now, regardless if cur is new or not, add it to the new list, * if the new list has not started, cur will become the first item. */ if (prev) { AST_LIST_NEXT(prev, frame_list) = cur; } else { f = cur; /* set f to be the beginning of our new list */ } prev = cur; } } /* If Monitor is running on this channel, then we have to write frames out there too */ /* the translator on chan->writetrans may have returned multiple frames from the single frame we passed in; if so, feed each one of them to the monitor */ if (chan->monitor && chan->monitor->write_stream) { struct ast_frame *cur; for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { /* XXX must explain this code */ #ifndef MONITOR_CONSTANT_DELAY int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples; if (jump >= 0) { jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1) ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples; } else { chan->outsmpl += cur->samples; } #else int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); if (jump - MONITOR_DELAY >= 0) { if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1) ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); chan->outsmpl += chan->insmpl - chan->outsmpl; } else { chan->outsmpl += cur->samples; } #endif if (chan->monitor->state == AST_MONITOR_RUNNING) { if (ast_writestream(chan->monitor->write_stream, cur) < 0) ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); } } } /* the translator on chan->writetrans may have returned multiple frames from the single frame we passed in; if so, feed each one of them to the channel, freeing each one after it has been written */ if ((f != fr) && AST_LIST_NEXT(f, frame_list)) { struct ast_frame *cur, *next; unsigned int skip = 0; for (cur = f, next = AST_LIST_NEXT(cur, frame_list); cur; cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) { if (!skip) { if ((res = chan->tech->write(chan, cur)) < 0) { chan->_softhangup |= AST_SOFTHANGUP_DEV; skip = 1; } else if (next) { /* don't do this for the last frame in the list, as the code outside the loop will do it once */ chan->fout = FRAMECOUNT_INC(chan->fout); } } ast_frfree(cur); } /* reset f so the code below doesn't attempt to free it */ f = NULL; } else { res = chan->tech->write(chan, f); } break; case AST_FRAME_NULL: case AST_FRAME_IAX: /* Ignore these */ res = 0; break; default: /* At this point, fr is the incoming frame and f is NULL. Channels do * not expect to get NULL as a frame pointer and will segfault. Hence, * we output the original frame passed in. */ res = chan->tech->write(chan, fr); break; } if (f && f != fr) ast_frfree(f); ast_clear_flag(chan, AST_FLAG_BLOCKING); /* Consider a write failure to force a soft hangup */ if (res < 0) { chan->_softhangup |= AST_SOFTHANGUP_DEV; } else { chan->fout = FRAMECOUNT_INC(chan->fout); } done: if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) { /* The list gets recreated if audiohooks are added again later */ ast_audiohook_detach_list(chan->audiohooks); chan->audiohooks = NULL; } ast_channel_unlock(chan); return res; }
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.
chan | destination channel of the frame |
frame | frame that will be written |
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.
chan | destination channel of the frame |
frame | frame that will be written |
Definition at line 3573 of file channel.c.
References ast_write(), ast_channel::tech, and ast_channel_tech::write_video.
{ int res; if (!chan->tech->write_video) return 0; res = ast_write(chan, fr); if (!res) res = 1; return res; }
const char* channelreloadreason2txt | ( | enum channelreloadreason | reason | ) |
Convert enum channelreloadreason to text string for manager event.
reason | Enum channelreloadreason - reason for reload (manager, cli, start etc) |
\ brief Convert channel reloadreason (ENUM) to text string for manager event
Definition at line 6057 of file channel.c.
References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.
Referenced by reload_config().
{ switch (reason) { case CHANNEL_MODULE_LOAD: return "LOAD (Channel module load)"; case CHANNEL_MODULE_RELOAD: return "RELOAD (Channel module reload)"; case CHANNEL_CLI_RELOAD: return "CLIRELOAD (Channel module reload by CLI command)"; default: return "MANAGERRELOAD (Channel module reload by manager)"; } };
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 86 of file channel.c.
Referenced by __ast_channel_alloc_ap(), and handle_core_set_debug_channel().
unsigned long global_fout |
Definition at line 86 of file channel.c.
Referenced by __ast_channel_alloc_ap(), and handle_core_set_debug_channel().