#include "asterisk/abstract_jb.h"
#include <unistd.h>
#include "asterisk/poll-compat.h"
#include "asterisk/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/compiler.h"
Go to the source code of this file.
Data Structures | |
struct | ast_bridge_config |
struct | ast_callerid |
Structure for all kinds of caller ID identifications. 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::datastores |
Data stores on the channel. More... | |
struct | ast_channel_tech |
Structure to describe a channel "technology", ie a channel driver See for examples:. More... | |
struct | ast_datastore |
Structure for a channel data store. More... | |
struct | ast_datastore_info |
Structure for a data store type. More... | |
struct | ast_generator |
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_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 8 |
#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 | LOAD_OH(oh) |
#define | MAX_LANGUAGE 20 |
#define | MAX_MUSICCLASS 80 |
Typedefs | |
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_WHISPER = (1 << 11), AST_FLAG_IN_DTMF = (1 << 12), AST_FLAG_EMULATE_DTMF = (1 << 13), AST_FLAG_END_DTMF_ONLY = (1 << 14), AST_FLAG_MASQ_NOSTREAM = (1 << 15), AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 16), AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 17), AST_FLAG_IN_CHANNEL_LIST = (1 << 19) } |
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_NO_H_EXTEN = (1 << 6), AST_FEATURE_WARNING_ACTIVE = (1 << 7) } |
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) } |
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 | 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 | |
ast_channel * | __ast_request_and_dial (const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname, struct outgoing_helper *oh) |
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 ringing call. | |
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. | |
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. | |
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. | |
ast_channel * | ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt,...) |
Create a channel structure. | |
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. | |
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_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore) |
Add a datastore to a channel. | |
ast_datastore * | ast_channel_datastore_alloc (const struct ast_datastore_info *info, char *uid) |
Create a channel datastore structure. | |
ast_datastore * | ast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, char *uid) |
Find a datastore on a channel. | |
int | ast_channel_datastore_free (struct ast_datastore *datastore) |
Free a channel datastore structure. | |
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. | |
void | ast_channel_free (struct ast_channel *) |
Free a channel structure. | |
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. | |
ast_frame * | ast_channel_queryoption (struct ast_channel *channel, int option, void *data, int *datalen, int block) |
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. | |
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) |
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. | |
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. | |
ast_channel * | ast_channel_walk_locked (const struct ast_channel *prev) |
Browse channels in use Browse the channels currently in use. | |
int | ast_channel_whisper_feed (struct ast_channel *chan, struct ast_frame *f) |
Feed an audio frame into the whisper buffer on a channel. | |
int | ast_channel_whisper_start (struct ast_channel *chan) |
Begin 'whispering' onto a channel. | |
void | ast_channel_whisper_stop (struct ast_channel *chan) |
Stop 'whispering' onto a channel. | |
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 wacked 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 max, int *start) |
Helper function for migrating select to poll. | |
ast_channel * | ast_get_channel_by_exten_locked (const char *exten, const char *context) |
Get channel by exten (and optionally context) and lock it. | |
ast_channel * | ast_get_channel_by_name_locked (const char *chan) |
Get channel by name (locks channel). | |
ast_channel * | ast_get_channel_by_name_prefix_locked (const char *name, const int namelen) |
Get channel by name prefix (locks channel). | |
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. | |
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. | |
ast_frame * | ast_read (struct ast_channel *chan) |
Reads a frame. | |
ast_frame * | ast_read_noaudio (struct ast_channel *chan) |
Reads a frame, returning AST_FRAME_NULL frame if audio. Read a frame. | |
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. | |
ast_channel * | ast_request (const char *type, int format, void *data, int *status) |
Requests a channel. | |
ast_channel * | ast_request_and_dial (const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname) |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. | |
int | ast_safe_sleep (struct ast_channel *chan, int ms) |
Wait for a specied 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 specied amount of time, looking for hangups and a condition argument. | |
char * | ast_safe_string_alloc (const char *fmt,...) |
printf the string into a correctly sized mallocd buffer, and return the buffer | |
static int | ast_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp) |
Waits for activity on a group of channels. | |
int | ast_senddigit (struct ast_channel *chan, char digit) |
Send a DTMF digit to a channel Send a DTMF digit to a channel. | |
int | ast_senddigit_begin (struct ast_channel *chan, char digit) |
int | ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration) |
int | ast_sendtext (struct ast_channel *chan, const char *text) |
Sends text to a channel Write text to a display on a channel. | |
void | ast_set_callerid (struct ast_channel *chan, const char *cidnum, const char *cidname, const char *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 compoent 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, int samples, int(*func)(const void *data), void *data) |
int | ast_shutting_down (void) |
Returns non-zero if Asterisk is being shut down. | |
int | ast_softhangup (struct ast_channel *chan, int cause) |
Softly hangup up a channel. | |
int | ast_softhangup_nolock (struct ast_channel *chan, int cause) |
Softly hangup up a channel (no channel lock). | |
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. | |
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. | |
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. | |
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. | |
ast_channel * | ast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen) |
Get channel by name 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_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. |
Definition in file channel.h.
#define AST_AGENT_FD (AST_MAX_FDS-3) |
used by agents for pass through
Definition at line 127 of file channel.h.
Referenced by agent_read().
#define AST_ALERT_FD (AST_MAX_FDS-1) |
#define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0) |
Report DTMF on channel 0.
Definition at line 1048 of file channel.h.
Referenced by ast_generic_bridge(), bridge_native_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 1050 of file channel.h.
Referenced by ast_generic_bridge(), bridge_native_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 1056 of file channel.h.
Referenced by bridge_native_loop().
#define AST_BRIDGE_REC_CHANNEL_0 (1 << 2) |
#define AST_BRIDGE_REC_CHANNEL_1 (1 << 3) |
#define AST_CHANNEL_NAME 80 |
Max length of an ast_channel name
Definition at line 102 of file channel.h.
Referenced by agent_devicestate_cb(), ast_channel_free(), ast_parse_device_state(), ast_setstate(), create_jb(), fast_originate(), next_channel(), page_exec(), park_call_full(), and softhangup_exec().
#define AST_GENERATOR_FD (AST_MAX_FDS-4) |
used by generator
Definition at line 128 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 101 of file channel.h.
Referenced by _macro_exec(), cleanup_stale_contexts(), conf_run(), gtalk_load_config(), leave_voicemail(), reload_config(), and try_calling().
#define AST_MAX_EXTENSION 80 |
Max length of an extension
Definition at line 100 of file channel.h.
Referenced by add_extensions(), advanced_options(), ast_bridge_call(), ast_device_state_changed(), ast_extension_state2(), ast_hint_state_changed(), ast_ivr_menu_run_internal(), begin_dial(), conf_run(), destroy_station(), disa_exec(), do_parking_thread(), dundi_lookup_local(), forward_message(), function_enum(), get_destination(), gosub_exec(), leave_voicemail(), load_config(), log_exec(), mgcp_ss(), park_add_hints(), park_call_exec(), phone_check_exception(), process_dahdi(), realtime_switch_common(), show_dialplan_helper(), skinny_answer(), skinny_indicate(), skinny_ss(), speech_background(), ss_thread(), transmit_state_notify(), try_calling(), vm_authenticate(), vmauthenticate(), and wait_for_answer().
#define AST_MAX_FDS 8 |
Definition at line 120 of file channel.h.
Referenced by ast_channel_alloc(), ast_do_masquerade(), ast_waitfor_nandfds(), do_parking_thread(), and update_features().
#define AST_TIMING_FD (AST_MAX_FDS-2) |
used for timingfd
Definition at line 126 of file channel.h.
Referenced by __ast_read(), agent_read(), ast_do_masquerade(), and restore_channel().
#define CHECK_BLOCKING | ( | c | ) |
Definition at line 1401 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 118 of file channel.h.
Referenced by _macro_exec(), add_features_datastores(), ast_channel_datastore_inherit(), and try_calling().
#define DEBUGCHAN_FLAG 0x80000000 |
Definition at line 294 of file channel.h.
Referenced by __ast_read(), ast_write(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_nodebugchan_deprecated(), handle_showchan(), handle_showchan_deprecated(), and serialize_showchan().
#define FRAMECOUNT_INC | ( | x | ) | ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) ) |
#define LOAD_OH | ( | oh | ) |
#define MAX_LANGUAGE 20 |
#define MAX_MUSICCLASS 80 |
typedef unsigned long long ast_group_t |
anonymous enum |
ast_channel_tech Properties
Definition at line 464 of file channel.h.
00464 { 00465 /*! \brief Channels have this property if they can accept input with jitter; 00466 * i.e. most VoIP channels */ 00467 AST_CHAN_TP_WANTSJITTER = (1 << 0), 00468 /*! \brief Channels have this property if they can create jitter; 00469 * i.e. most VoIP channels */ 00470 AST_CHAN_TP_CREATESJITTER = (1 << 1), 00471 };
anonymous enum |
ast_channel flags
Definition at line 474 of file channel.h.
00474 { 00475 /*! Queue incoming dtmf, to be released when this flag is turned off */ 00476 AST_FLAG_DEFER_DTMF = (1 << 1), 00477 /*! write should be interrupt generator */ 00478 AST_FLAG_WRITE_INT = (1 << 2), 00479 /*! a thread is blocking on this channel */ 00480 AST_FLAG_BLOCKING = (1 << 3), 00481 /*! This is a zombie channel */ 00482 AST_FLAG_ZOMBIE = (1 << 4), 00483 /*! There is an exception pending */ 00484 AST_FLAG_EXCEPTION = (1 << 5), 00485 /*! Listening to moh XXX anthm promises me this will disappear XXX */ 00486 AST_FLAG_MOH = (1 << 6), 00487 /*! This channel is spying on another channel */ 00488 AST_FLAG_SPYING = (1 << 7), 00489 /*! This channel is in a native bridge */ 00490 AST_FLAG_NBRIDGE = (1 << 8), 00491 /*! the channel is in an auto-incrementing dialplan processor, 00492 * so when ->priority is set, it will get incremented before 00493 * finding the next priority to run */ 00494 AST_FLAG_IN_AUTOLOOP = (1 << 9), 00495 /*! This is an outgoing call */ 00496 AST_FLAG_OUTGOING = (1 << 10), 00497 /*! This channel is being whispered on */ 00498 AST_FLAG_WHISPER = (1 << 11), 00499 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */ 00500 AST_FLAG_IN_DTMF = (1 << 12), 00501 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is 00502 * currently being emulated */ 00503 AST_FLAG_EMULATE_DTMF = (1 << 13), 00504 /*! This is set to tell the channel not to generate DTMF begin frames, and 00505 * to instead only generate END frames. */ 00506 AST_FLAG_END_DTMF_ONLY = (1 << 14), 00507 /*! This flag indicates that on a masquerade, an active stream should not 00508 * be carried over */ 00509 AST_FLAG_MASQ_NOSTREAM = (1 << 15), 00510 /*! This flag indicates that the hangup exten was run when the bridge terminated, 00511 * a message aimed at preventing a subsequent hangup exten being run at the pbx_run 00512 * level */ 00513 AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 16), 00514 /*! This flag indicates that the hangup exten should NOT be run when the 00515 * bridge terminates, this will allow the hangup in the pbx loop to be run instead. 00516 * */ 00517 AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 17), 00518 /*! This flag indicates whether the channel is in the channel list or not. */ 00519 AST_FLAG_IN_CHANNEL_LIST = (1 << 19), 00520 };
anonymous enum |
ast_bridge_config flags
AST_FEATURE_PLAY_WARNING | |
AST_FEATURE_REDIRECT | |
AST_FEATURE_DISCONNECT | |
AST_FEATURE_ATXFER | |
AST_FEATURE_AUTOMON | |
AST_FEATURE_PARKCALL | |
AST_FEATURE_NO_H_EXTEN | |
AST_FEATURE_WARNING_ACTIVE |
Definition at line 523 of file channel.h.
00523 { 00524 AST_FEATURE_PLAY_WARNING = (1 << 0), 00525 AST_FEATURE_REDIRECT = (1 << 1), 00526 AST_FEATURE_DISCONNECT = (1 << 2), 00527 AST_FEATURE_ATXFER = (1 << 3), 00528 AST_FEATURE_AUTOMON = (1 << 4), 00529 AST_FEATURE_PARKCALL = (1 << 5), 00530 AST_FEATURE_NO_H_EXTEN = (1 << 6), 00531 AST_FEATURE_WARNING_ACTIVE = (1 << 7), 00532 };
anonymous enum |
Definition at line 581 of file channel.h.
00581 { 00582 AST_CDR_TRANSFER = (1 << 0), 00583 AST_CDR_FORWARD = (1 << 1), 00584 AST_CDR_CALLWAIT = (1 << 2), 00585 AST_CDR_CONFERENCE = (1 << 3), 00586 };
anonymous enum |
Definition at line 588 of file channel.h.
00588 { 00589 /*! Soft hangup by device */ 00590 AST_SOFTHANGUP_DEV = (1 << 0), 00591 /*! Soft hangup for async goto */ 00592 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), 00593 AST_SOFTHANGUP_SHUTDOWN = (1 << 2), 00594 AST_SOFTHANGUP_TIMEOUT = (1 << 3), 00595 AST_SOFTHANGUP_APPUNLOAD = (1 << 4), 00596 AST_SOFTHANGUP_EXPLICIT = (1 << 5), 00597 AST_SOFTHANGUP_UNBRIDGE = (1 << 6), 00598 };
enum ast_bridge_result |
Definition at line 130 of file channel.h.
00130 { 00131 AST_BRIDGE_COMPLETE = 0, 00132 AST_BRIDGE_FAILED = -1, 00133 AST_BRIDGE_FAILED_NOWARN = -2, 00134 AST_BRIDGE_RETRY = -3, 00135 };
enum ast_channel_adsicpe |
Definition at line 297 of file channel.h.
00297 { 00298 AST_ADSI_UNKNOWN, 00299 AST_ADSI_AVAILABLE, 00300 AST_ADSI_UNAVAILABLE, 00301 AST_ADSI_OFFHOOKONLY, 00302 };
enum ast_channel_state |
ast_channel states
Definition at line 310 of file channel.h.
00310 { 00311 /*! Channel is down and available */ 00312 AST_STATE_DOWN, 00313 /*! Channel is down, but reserved */ 00314 AST_STATE_RESERVED, 00315 /*! Channel is off hook */ 00316 AST_STATE_OFFHOOK, 00317 /*! Digits (or equivalent) have been dialed */ 00318 AST_STATE_DIALING, 00319 /*! Line is ringing */ 00320 AST_STATE_RING, 00321 /*! Remote end is ringing */ 00322 AST_STATE_RINGING, 00323 /*! Line is up */ 00324 AST_STATE_UP, 00325 /*! Line is busy */ 00326 AST_STATE_BUSY, 00327 /*! Digits (or equivalent) have been dialed while offhook */ 00328 AST_STATE_DIALING_OFFHOOK, 00329 /*! Channel has detected an incoming call and is waiting for ring */ 00330 AST_STATE_PRERING, 00331 00332 /*! Do not transmit voice data */ 00333 AST_STATE_MUTE = (1 << 16), 00334 };
enum channelreloadreason |
Channel reload reasons for manager events at load or reload of configuration.
Definition at line 602 of file channel.h.
00602 { 00603 CHANNEL_MODULE_LOAD, 00604 CHANNEL_MODULE_RELOAD, 00605 CHANNEL_CLI_RELOAD, 00606 CHANNEL_MANAGER_RELOAD, 00607 };
struct ast_channel* __ast_request_and_dial | ( | const char * | type, | |
int | format, | |||
void * | data, | |||
int | timeout, | |||
int * | reason, | |||
const char * | cidnum, | |||
const char * | cidname, | |||
struct outgoing_helper * | oh | |||
) |
Definition at line 3255 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_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_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, ast_channel::cdr, outgoing_helper::cid_name, outgoing_helper::cid_num, ast_channel::context, outgoing_helper::context, ast_channel::exten, outgoing_helper::exten, f, handle_cause(), ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, ast_channel::priority, outgoing_helper::priority, and outgoing_helper::vars.
Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().
03256 { 03257 int dummy_outstate; 03258 int cause = 0; 03259 struct ast_channel *chan; 03260 int res = 0; 03261 int last_subclass = 0; 03262 03263 if (outstate) 03264 *outstate = 0; 03265 else 03266 outstate = &dummy_outstate; /* make outstate always a valid pointer */ 03267 03268 chan = ast_request(type, format, data, &cause); 03269 if (!chan) { 03270 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data); 03271 handle_cause(cause, outstate); 03272 return NULL; 03273 } 03274 03275 if (oh) { 03276 if (oh->vars) 03277 ast_set_variables(chan, oh->vars); 03278 /* XXX why is this necessary, for the parent_channel perhaps ? */ 03279 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) 03280 ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); 03281 if (oh->parent_channel) 03282 ast_channel_inherit_variables(oh->parent_channel, chan); 03283 if (oh->account) 03284 ast_cdr_setaccount(chan, oh->account); 03285 } 03286 ast_set_callerid(chan, cid_num, cid_name, cid_num); 03287 ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED); 03288 03289 if (ast_call(chan, data, 0)) { /* ast_call failed... */ 03290 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data); 03291 } else { 03292 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */ 03293 while (timeout && chan->_state != AST_STATE_UP) { 03294 struct ast_frame *f; 03295 res = ast_waitfor(chan, timeout); 03296 if (res == 0) { /* timeout, treat it like ringing */ 03297 *outstate = AST_CONTROL_RINGING; 03298 break; 03299 } 03300 if (res < 0) /* error or done */ 03301 break; 03302 if (timeout > -1) 03303 timeout = res; 03304 if (!ast_strlen_zero(chan->call_forward)) { 03305 if (!(chan = ast_call_forward(NULL, chan, &timeout, format, oh, outstate))) { 03306 return NULL; 03307 } 03308 continue; 03309 } 03310 03311 f = ast_read(chan); 03312 if (!f) { 03313 *outstate = AST_CONTROL_HANGUP; 03314 res = 0; 03315 break; 03316 } 03317 if (f->frametype == AST_FRAME_CONTROL) { 03318 switch (f->subclass) { 03319 case AST_CONTROL_RINGING: /* record but keep going */ 03320 *outstate = f->subclass; 03321 break; 03322 03323 case AST_CONTROL_BUSY: 03324 ast_cdr_busy(chan->cdr); 03325 *outstate = f->subclass; 03326 timeout = 0; 03327 break; 03328 03329 case AST_CONTROL_CONGESTION: 03330 ast_cdr_failed(chan->cdr); 03331 *outstate = f->subclass; 03332 timeout = 0; 03333 break; 03334 03335 case AST_CONTROL_ANSWER: 03336 ast_cdr_answer(chan->cdr); 03337 *outstate = f->subclass; 03338 timeout = 0; /* trick to force exit from the while() */ 03339 break; 03340 03341 /* Ignore these */ 03342 case AST_CONTROL_PROGRESS: 03343 case AST_CONTROL_PROCEEDING: 03344 case AST_CONTROL_HOLD: 03345 case AST_CONTROL_UNHOLD: 03346 case AST_CONTROL_VIDUPDATE: 03347 case AST_CONTROL_SRCUPDATE: 03348 case -1: /* Ignore -- just stopping indications */ 03349 break; 03350 03351 default: 03352 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass); 03353 } 03354 last_subclass = f->subclass; 03355 } 03356 ast_frfree(f); 03357 } 03358 } 03359 03360 /* Final fixups */ 03361 if (oh) { 03362 if (!ast_strlen_zero(oh->context)) 03363 ast_copy_string(chan->context, oh->context, sizeof(chan->context)); 03364 if (!ast_strlen_zero(oh->exten)) 03365 ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten)); 03366 if (oh->priority) 03367 chan->priority = oh->priority; 03368 } 03369 if (chan->_state == AST_STATE_UP) 03370 *outstate = AST_CONTROL_ANSWER; 03371 03372 if (res <= 0) { 03373 if ( AST_CONTROL_RINGING == last_subclass ) 03374 chan->hangupcause = AST_CAUSE_NO_ANSWER; 03375 if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) 03376 ast_cdr_init(chan->cdr, chan); 03377 if (chan->cdr) { 03378 char tmp[256]; 03379 snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data); 03380 ast_cdr_setapp(chan->cdr,"Dial",tmp); 03381 ast_cdr_update(chan); 03382 ast_cdr_start(chan->cdr); 03383 ast_cdr_end(chan->cdr); 03384 /* If the cause wasn't handled properly */ 03385 if (ast_cdr_disposition(chan->cdr,chan->hangupcause)) 03386 ast_cdr_failed(chan->cdr); 03387 } 03388 ast_hangup(chan); 03389 chan = NULL; 03390 } 03391 return chan; 03392 }
int ast_activate_generator | ( | struct ast_channel * | chan, | |
struct ast_generator * | gen, | |||
void * | params | |||
) |
Activate a given generator
Definition at line 1678 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(), local_ast_moh_start(), and old_milliwatt_exec().
01679 { 01680 int res = 0; 01681 01682 ast_channel_lock(chan); 01683 01684 if (chan->generatordata) { 01685 if (chan->generator && chan->generator->release) 01686 chan->generator->release(chan, chan->generatordata); 01687 chan->generatordata = NULL; 01688 } 01689 01690 ast_prod(chan); 01691 if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) { 01692 res = -1; 01693 } 01694 01695 if (!res) { 01696 ast_settimeout(chan, 160, generator_force, chan); 01697 chan->generator = gen; 01698 } 01699 01700 ast_channel_unlock(chan); 01701 01702 return res; 01703 }
int ast_active_channels | ( | void | ) |
returns number of active/allocated channels
Returns number of active/allocated channels
Definition at line 443 of file channel.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, and AST_LIST_UNLOCK.
Referenced by action_corestatus(), dahdi_restart(), handle_show_settings(), and quit_handler().
00444 { 00445 struct ast_channel *c; 00446 int cnt = 0; 00447 AST_LIST_LOCK(&channels); 00448 AST_LIST_TRAVERSE(&channels, c, chan_list) 00449 cnt++; 00450 AST_LIST_UNLOCK(&channels); 00451 return cnt; 00452 }
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 1326 of file channel.h.
Referenced by ast_waitfor_nandfds().
int ast_answer | ( | struct ast_channel * | chan | ) |
Answer a ringing call.
chan | channel to answer This function answers a channel and handles all necessary call setup functions. |
Definition at line 1599 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 __login_exec(), agi_exec_full(), alarmreceiver_exec(), answer_trunk_chan(), app_exec(), ast_bridge_call(), ast_control_streamfile(), ast_pickup_call(), auth_exec(), background_detect_exec(), builtin_parkcall(), common_exec(), conf_exec(), count_exec(), dictate_exec(), directory_exec(), disa_exec(), exec(), features_answer(), handle_answer(), ices_exec(), old_milliwatt_exec(), park_call_exec(), park_exec(), pbx_builtin_answer(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), sayunixtime_exec(), send_waveform_to_channel(), skel_exec(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), vm_exec(), vm_execmain(), waitforsilence_exec(), and zapateller_exec().
01600 { 01601 int res = 0; 01602 ast_channel_lock(chan); 01603 /* You can't answer an outbound call */ 01604 if (ast_test_flag(chan, AST_FLAG_OUTGOING)) { 01605 ast_channel_unlock(chan); 01606 return 0; 01607 } 01608 /* Stop if we're a zombie or need a soft hangup */ 01609 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 01610 ast_channel_unlock(chan); 01611 return -1; 01612 } 01613 switch(chan->_state) { 01614 case AST_STATE_RINGING: 01615 case AST_STATE_RING: 01616 if (chan->tech->answer) 01617 res = chan->tech->answer(chan); 01618 ast_setstate(chan, AST_STATE_UP); 01619 ast_cdr_answer(chan->cdr); 01620 break; 01621 case AST_STATE_UP: 01622 break; 01623 default: 01624 break; 01625 } 01626 ast_indicate(chan, -1); 01627 chan->visible_indication = 0; 01628 ast_channel_unlock(chan); 01629 return res; 01630 }
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 197 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, 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_automonitor(), builtin_blindtransfer(), conf_play(), do_atxfer(), feature_exec_app(), function_realtime_read(), function_realtime_write(), osplookup_exec(), sla_station_exec(), smdi_msg_retrieve_read(), and system_exec_helper().
00198 { 00199 int res = 0; 00200 struct asent *as; 00201 00202 /* Check if the channel already has autoservice */ 00203 AST_LIST_LOCK(&aslist); 00204 AST_LIST_TRAVERSE(&aslist, as, list) { 00205 if (as->chan == chan) { 00206 as->use_count++; 00207 break; 00208 } 00209 } 00210 AST_LIST_UNLOCK(&aslist); 00211 00212 if (as) { 00213 /* Entry exists, autoservice is already handling this channel */ 00214 return 0; 00215 } 00216 00217 if (!(as = ast_calloc(1, sizeof(*as)))) 00218 return -1; 00219 00220 /* New entry created */ 00221 as->chan = chan; 00222 as->use_count = 1; 00223 00224 ast_channel_lock(chan); 00225 as->orig_end_dtmf_flag = ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY) ? 1 : 0; 00226 if (!as->orig_end_dtmf_flag) 00227 ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY); 00228 ast_channel_unlock(chan); 00229 00230 AST_LIST_LOCK(&aslist); 00231 00232 if (AST_LIST_EMPTY(&aslist) && asthread != AST_PTHREADT_NULL) { 00233 ast_cond_signal(&as_cond); 00234 } 00235 00236 AST_LIST_INSERT_HEAD(&aslist, as, list); 00237 00238 if (asthread == AST_PTHREADT_NULL) { /* need start the thread */ 00239 if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) { 00240 ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n"); 00241 /* There will only be a single member in the list at this point, 00242 the one we just added. */ 00243 AST_LIST_REMOVE(&aslist, as, list); 00244 free(as); 00245 asthread = AST_PTHREADT_NULL; 00246 res = -1; 00247 } else { 00248 pthread_kill(asthread, SIGURG); 00249 } 00250 } 00251 00252 AST_LIST_UNLOCK(&aslist); 00253 00254 return res; 00255 }
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 257 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::frame_list, free, asent::list, 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_srv(), ast_get_txt(), ast_hangup(), bridge_playfile(), builtin_automonitor(), conf_play(), do_atxfer(), feature_exec_app(), finishup(), function_realtime_read(), function_realtime_write(), osplookup_exec(), sla_station_exec(), smdi_msg_retrieve_read(), and system_exec_helper().
00258 { 00259 int res = -1; 00260 struct asent *as, *removed = NULL; 00261 struct ast_frame *f; 00262 int chan_list_state; 00263 00264 AST_LIST_LOCK(&aslist); 00265 00266 /* Save the autoservice channel list state. We _must_ verify that the channel 00267 * list has been rebuilt before we return. Because, after we return, the channel 00268 * could get destroyed and we don't want our poor autoservice thread to step on 00269 * it after its gone! */ 00270 chan_list_state = as_chan_list_state; 00271 00272 /* Find the entry, but do not free it because it still can be in the 00273 autoservice thread array */ 00274 AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) { 00275 if (as->chan == chan) { 00276 as->use_count--; 00277 if (as->use_count < 1) { 00278 AST_LIST_REMOVE_CURRENT(&aslist, list); 00279 removed = as; 00280 } 00281 break; 00282 } 00283 } 00284 AST_LIST_TRAVERSE_SAFE_END 00285 00286 if (removed && asthread != AST_PTHREADT_NULL) { 00287 pthread_kill(asthread, SIGURG); 00288 } 00289 00290 AST_LIST_UNLOCK(&aslist); 00291 00292 if (!removed) { 00293 return 0; 00294 } 00295 00296 /* Wait while autoservice thread rebuilds its list. */ 00297 while (chan_list_state == as_chan_list_state) { 00298 usleep(1000); 00299 } 00300 00301 /* Now autoservice thread should have no references to our entry 00302 and we can safely destroy it */ 00303 00304 if (!chan->_softhangup) { 00305 res = 0; 00306 } 00307 00308 if (!as->orig_end_dtmf_flag) { 00309 ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY); 00310 } 00311 00312 ast_channel_lock(chan); 00313 while ((f = AST_LIST_REMOVE_HEAD(&as->deferred_frames, frame_list))) { 00314 ast_queue_frame_head(chan, f); 00315 ast_frfree(f); 00316 } 00317 ast_channel_unlock(chan); 00318 00319 free(as); 00320 00321 return res; 00322 }
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 430 of file channel.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.
Referenced by quit_handler().
00431 { 00432 struct ast_channel *c; 00433 shutting_down = 1; 00434 if (hangup) { 00435 AST_LIST_LOCK(&channels); 00436 AST_LIST_TRAVERSE(&channels, c, chan_list) 00437 ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN); 00438 AST_LIST_UNLOCK(&channels); 00439 } 00440 }
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 655 of file channel.c.
References 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_SLINEAR, AST_FORMAT_SPEEX, AST_FORMAT_ULAW, ast_log(), LOG_WARNING, and prefs.
Referenced by __login_exec(), __oh323_new(), agent_call(), ast_codec_choose(), ast_iax2_new(), do_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), local_new(), mgcp_new(), sip_new(), skinny_new(), socket_process(), and transmit_connect().
00656 { 00657 /* This just our opinion, expressed in code. We are asked to choose 00658 the best codec to use, given no information */ 00659 int x; 00660 static int prefs[] = 00661 { 00662 /*! Okay, ulaw is used by all telephony equipment, so start with it */ 00663 AST_FORMAT_ULAW, 00664 /*! Unless of course, you're a silly European, so then prefer ALAW */ 00665 AST_FORMAT_ALAW, 00666 /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */ 00667 AST_FORMAT_G722, 00668 /*! Okay, well, signed linear is easy to translate into other stuff */ 00669 AST_FORMAT_SLINEAR, 00670 /*! G.726 is standard ADPCM, in RFC3551 packing order */ 00671 AST_FORMAT_G726, 00672 /*! G.726 is standard ADPCM, in AAL2 packing order */ 00673 AST_FORMAT_G726_AAL2, 00674 /*! ADPCM has great sound quality and is still pretty easy to translate */ 00675 AST_FORMAT_ADPCM, 00676 /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to 00677 translate and sounds pretty good */ 00678 AST_FORMAT_GSM, 00679 /*! iLBC is not too bad */ 00680 AST_FORMAT_ILBC, 00681 /*! Speex is free, but computationally more expensive than GSM */ 00682 AST_FORMAT_SPEEX, 00683 /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough 00684 to use it */ 00685 AST_FORMAT_LPC10, 00686 /*! G.729a is faster than 723 and slightly less expensive */ 00687 AST_FORMAT_G729A, 00688 /*! Down to G.723.1 which is proprietary but at least designed for voice */ 00689 AST_FORMAT_G723_1, 00690 }; 00691 00692 /* Strip out video */ 00693 fmts &= AST_FORMAT_AUDIO_MASK; 00694 00695 /* Find the first preferred codec in the format given */ 00696 for (x=0; x < (sizeof(prefs) / sizeof(prefs[0]) ); x++) 00697 if (fmts & prefs[x]) 00698 return prefs[x]; 00699 ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts); 00700 return 0; 00701 }
struct ast_channel* ast_bridged_channel | ( | struct ast_channel * | chan | ) |
Find bridged channel.
chan | Current channel |
Definition at line 4140 of file channel.c.
References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.
Referenced by __dahdi_exception(), action_agents(), agents_show(), agents_show_online(), ast_bridge_call(), ast_channel_masquerade(), attempt_transfer(), cb_events(), check_bridge(), common_exec(), console_transfer(), console_transfer_deprecated(), create_jb(), dahdi_handle_event(), dahdi_hangup(), export_aoc_vars(), handle_chanlist(), handle_chanlist_deprecated(), handle_hd_hf(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_response_invite(), handle_showchan(), handle_showchan_deprecated(), local_attended_transfer(), mgcp_hangup(), mgcp_ss(), misdn_attempt_transfer(), mixmonitor_thread(), park_call_full(), schedule_delivery(), sip_read(), sip_set_rtp_peer(), socket_process(), ss_thread(), start_spying(), and startmon().
04141 { 04142 struct ast_channel *bridged; 04143 bridged = chan->_bridge; 04144 if (bridged && bridged->tech->bridged_channel) 04145 bridged = bridged->tech->bridged_channel(chan, bridged); 04146 return bridged; 04147 }
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 3449 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(), ast_feature_request_and_dial(), attempt_reconnect(), begin_dial(), connect_link(), do_idle_thread(), features_call(), findmeexec(), ring_entry(), rpt(), and wait_for_answer().
03450 { 03451 /* Place an outgoing call, but don't wait any longer than timeout ms before returning. 03452 If the remote end does not answer within the timeout, then do NOT hang up, but 03453 return anyway. */ 03454 int res = -1; 03455 /* Stop if we're a zombie or need a soft hangup */ 03456 ast_channel_lock(chan); 03457 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 03458 if (chan->cdr) 03459 ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED); 03460 if (chan->tech->call) 03461 res = chan->tech->call(chan, addr, timeout); 03462 ast_set_flag(chan, AST_FLAG_OUTGOING); 03463 } 03464 ast_channel_unlock(chan); 03465 return res; 03466 }
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.
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 3188 of file channel.c.
References outgoing_helper::account, ast_channel::accountcode, accountcode, ast_call(), ast_cdr_setaccount(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_unlock, 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, 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 ast_feature_request_and_dial().
03189 { 03190 char tmpchan[256]; 03191 struct ast_channel *new = NULL; 03192 char *data, *type; 03193 int cause = 0; 03194 03195 /* gather data and request the new forward channel */ 03196 ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan)); 03197 if ((data = strchr(tmpchan, '/'))) { 03198 *data++ = '\0'; 03199 type = tmpchan; 03200 } else { 03201 const char *forward_context; 03202 ast_channel_lock(orig); 03203 forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT"); 03204 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context)); 03205 ast_channel_unlock(orig); 03206 data = tmpchan; 03207 type = "Local"; 03208 } 03209 if (!(new = ast_request(type, format, data, &cause))) { 03210 ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause); 03211 handle_cause(cause, outstate); 03212 ast_hangup(orig); 03213 return NULL; 03214 } 03215 03216 /* Copy/inherit important information into new channel */ 03217 if (oh) { 03218 if (oh->vars) { 03219 ast_set_variables(new, oh->vars); 03220 } 03221 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) { 03222 ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num); 03223 } 03224 if (oh->parent_channel) { 03225 ast_channel_inherit_variables(oh->parent_channel, new); 03226 ast_channel_datastore_inherit(oh->parent_channel, new); 03227 } 03228 if (oh->account) { 03229 ast_cdr_setaccount(new, oh->account); 03230 } 03231 } else if (caller) { /* no outgoing helper so use caller if avaliable */ 03232 ast_channel_inherit_variables(caller, new); 03233 ast_channel_datastore_inherit(caller, new); 03234 } 03235 03236 ast_channel_lock(orig); 03237 ast_string_field_set(new, accountcode, orig->accountcode); 03238 if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) { 03239 ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num); 03240 } 03241 ast_channel_unlock(orig); 03242 03243 /* call new channel */ 03244 if ((*timeout = ast_call(new, data, 0))) { 03245 ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data); 03246 ast_hangup(orig); 03247 ast_hangup(new); 03248 return NULL; 03249 } 03250 ast_hangup(orig); 03251 03252 return new; 03253 }
void ast_cancel_shutdown | ( | void | ) |
Cancel a shutdown in progress.
Cancels an existing shutdown and returns to normal operation
Definition at line 455 of file channel.c.
Referenced by handle_abort_halt().
00456 { 00457 shutting_down = 0; 00458 }
const char* ast_cause2str | ( | int | state | ) |
Gives the string form of a given hangup cause.
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 575 of file channel.c.
Referenced by __transmit_response(), ast_do_masquerade(), ast_hangup(), findmeexec(), pbx_retrieve_variable(), sip_hangup(), and transmit_request_with_auth().
00576 { 00577 int x; 00578 00579 for (x=0; x < sizeof(causes) / sizeof(causes[0]); x++) { 00580 if (causes[x].cause == cause) 00581 return causes[x].desc; 00582 } 00583 00584 return "Unknown"; 00585 }
void ast_change_name | ( | struct ast_channel * | chan, | |
char * | newname | |||
) |
Change channel name.
Definition at line 3699 of file channel.c.
References ast_string_field_set, manager_event(), name, ast_channel::name, and ast_channel::uniqueid.
03700 { 03701 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid); 03702 ast_string_field_set(chan, name, newname); 03703 }
struct ast_channel* ast_channel_alloc | ( | int | needqueue, | |
int | state, | |||
const char * | cid_num, | |||
const char * | cid_name, | |||
const char * | acctcode, | |||
const char * | exten, | |||
const char * | context, | |||
const int | amaflag, | |||
const char * | name_fmt, | |||
... | ||||
) |
Create a channel structure.
Definition at line 709 of file channel.c.
References ast_calloc, ast_log(), AST_MAX_FDS, ast_string_field_init, DAHDI_FILE_TIMER, ast_channel::flags, free, HAVE_DAHDI, LOG_WARNING, sched_context_create(), and sched_context_destroy().
Referenced by __oh323_new(), acf_odbc_read(), acf_odbc_write(), action_getvar(), agent_new(), alsa_new(), ast_async_goto(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), ast_pbx_outgoing_exten(), check_goto_on_transfer(), dahdi_new(), do_atxfer(), features_new(), gtalk_new(), iax_park(), local_new(), make_email_file(), masq_park_call(), mgcp_new(), misdn_new(), nbs_new(), oss_new(), pbx_substitute_variables_helper_full(), phone_new(), sendpage(), sip_new(), sip_park(), and skinny_new().
00710 { 00711 struct ast_channel *tmp; 00712 int x; 00713 int flags; 00714 struct varshead *headp; 00715 va_list ap1, ap2; 00716 00717 /* If shutting down, don't allocate any new channels */ 00718 if (shutting_down) { 00719 ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n"); 00720 return NULL; 00721 } 00722 00723 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) 00724 return NULL; 00725 00726 if (!(tmp->sched = sched_context_create())) { 00727 ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"); 00728 free(tmp); 00729 return NULL; 00730 } 00731 00732 if ((ast_string_field_init(tmp, 128))) { 00733 sched_context_destroy(tmp->sched); 00734 free(tmp); 00735 return NULL; 00736 } 00737 00738 /* Don't bother initializing the last two FD here, because they 00739 will *always* be set just a few lines down (AST_TIMING_FD, 00740 AST_ALERT_FD). */ 00741 for (x = 0; x < AST_MAX_FDS - 2; x++) 00742 tmp->fds[x] = -1; 00743 00744 #ifdef HAVE_DAHDI 00745 00746 tmp->timingfd = open(DAHDI_FILE_TIMER, O_RDWR); 00747 00748 if (tmp->timingfd > -1) { 00749 /* Check if timing interface supports new 00750 ping/pong scheme */ 00751 flags = 1; 00752 if (!ioctl(tmp->timingfd, DAHDI_TIMERPONG, &flags)) 00753 needqueue = 0; 00754 } 00755 #else 00756 tmp->timingfd = -1; 00757 #endif 00758 00759 if (needqueue) { 00760 if (pipe(tmp->alertpipe)) { 00761 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n"); 00762 alertpipe_failed: 00763 #ifdef HAVE_DAHDI 00764 if (tmp->timingfd > -1) 00765 close(tmp->timingfd); 00766 #endif 00767 sched_context_destroy(tmp->sched); 00768 ast_string_field_free_memory(tmp); 00769 free(tmp); 00770 return NULL; 00771 } else { 00772 flags = fcntl(tmp->alertpipe[0], F_GETFL); 00773 if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 00774 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00775 close(tmp->alertpipe[0]); 00776 close(tmp->alertpipe[1]); 00777 goto alertpipe_failed; 00778 } 00779 flags = fcntl(tmp->alertpipe[1], F_GETFL); 00780 if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) { 00781 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00782 close(tmp->alertpipe[0]); 00783 close(tmp->alertpipe[1]); 00784 goto alertpipe_failed; 00785 } 00786 } 00787 } else /* Make sure we've got it done right if they don't */ 00788 tmp->alertpipe[0] = tmp->alertpipe[1] = -1; 00789 00790 /* Always watch the alertpipe */ 00791 tmp->fds[AST_ALERT_FD] = tmp->alertpipe[0]; 00792 /* And timing pipe */ 00793 tmp->fds[AST_TIMING_FD] = tmp->timingfd; 00794 ast_string_field_set(tmp, name, "**Unknown**"); 00795 00796 /* Initial state */ 00797 tmp->_state = state; 00798 00799 tmp->streamid = -1; 00800 00801 tmp->fin = global_fin; 00802 tmp->fout = global_fout; 00803 00804 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) { 00805 ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 00806 ast_atomic_fetchadd_int(&uniqueint, 1)); 00807 } else { 00808 ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 00809 (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1)); 00810 } 00811 00812 tmp->cid.cid_name = ast_strdup(cid_name); 00813 tmp->cid.cid_num = ast_strdup(cid_num); 00814 00815 if (!ast_strlen_zero(name_fmt)) { 00816 /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call. 00817 * And they all use slightly different formats for their name string. 00818 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here. 00819 * This means, that the stringfields must have a routine that takes the va_lists directly, and 00820 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list. 00821 * This new function was written so this can be accomplished. 00822 */ 00823 va_start(ap1, name_fmt); 00824 va_start(ap2, name_fmt); 00825 ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2); 00826 va_end(ap1); 00827 va_end(ap2); 00828 } 00829 00830 /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */ 00831 00832 /* These 4 variables need to be set up for the cdr_init() to work right */ 00833 if (amaflag) 00834 tmp->amaflags = amaflag; 00835 else 00836 tmp->amaflags = ast_default_amaflags; 00837 00838 if (!ast_strlen_zero(acctcode)) 00839 ast_string_field_set(tmp, accountcode, acctcode); 00840 else 00841 ast_string_field_set(tmp, accountcode, ast_default_accountcode); 00842 00843 if (!ast_strlen_zero(context)) 00844 ast_copy_string(tmp->context, context, sizeof(tmp->context)); 00845 else 00846 strcpy(tmp->context, "default"); 00847 00848 if (!ast_strlen_zero(exten)) 00849 ast_copy_string(tmp->exten, exten, sizeof(tmp->exten)); 00850 else 00851 strcpy(tmp->exten, "s"); 00852 00853 tmp->priority = 1; 00854 00855 tmp->cdr = ast_cdr_alloc(); 00856 ast_cdr_init(tmp->cdr, tmp); 00857 ast_cdr_start(tmp->cdr); 00858 00859 headp = &tmp->varshead; 00860 AST_LIST_HEAD_INIT_NOLOCK(headp); 00861 00862 ast_mutex_init(&tmp->lock); 00863 00864 AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores); 00865 00866 ast_string_field_set(tmp, language, defaultlanguage); 00867 00868 tmp->tech = &null_tech; 00869 00870 ast_set_flag(tmp, AST_FLAG_IN_CHANNEL_LIST); 00871 00872 AST_LIST_LOCK(&channels); 00873 AST_LIST_INSERT_HEAD(&channels, tmp, chan_list); 00874 AST_LIST_UNLOCK(&channels); 00875 00876 /*\!note 00877 * and now, since the channel structure is built, and has its name, let's 00878 * call the manager event generator with this Newchannel event. This is the 00879 * proper and correct place to make this call, but you sure do have to pass 00880 * a lot of data into this func to do it here! 00881 */ 00882 if (!ast_strlen_zero(name_fmt)) { 00883 manager_event(EVENT_FLAG_CALL, "Newchannel", 00884 "Channel: %s\r\n" 00885 "State: %s\r\n" 00886 "CallerIDNum: %s\r\n" 00887 "CallerIDName: %s\r\n" 00888 "Uniqueid: %s\r\n", 00889 tmp->name, ast_state2str(state), 00890 S_OR(cid_num, "<unknown>"), 00891 S_OR(cid_name, "<unknown>"), 00892 tmp->uniqueid); 00893 } 00894 00895 return tmp; 00896 }
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 4382 of file channel.c.
References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_make_compatible(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCUPDATE, AST_FEATURE_PLAY_WARNING, AST_FEATURE_REDIRECT, 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_verbose(), ast_channel::audiohooks, ast_channel_tech::bridge, bridge_playfile(), ast_channel::cid, ast_callerid::cid_num, config, ast_channel::generator, LOG_DEBUG, manager_event(), ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_channel::nativeformats, option_debug, option_verbose, ast_channel::readformat, ast_channel_tech::send_digit_begin, t, ast_channel::tech, ast_channel::uniqueid, update_bridgepeer(), VERBOSE_PREFIX_3, and ast_channel::writeformat.
Referenced by ast_bridge_call().
04384 { 04385 struct ast_channel *who = NULL; 04386 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 04387 int nativefailed=0; 04388 int firstpass; 04389 int o0nativeformats; 04390 int o1nativeformats; 04391 long time_left_ms=0; 04392 char caller_warning = 0; 04393 char callee_warning = 0; 04394 04395 if (c0->_bridge) { 04396 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 04397 c0->name, c0->_bridge->name); 04398 return -1; 04399 } 04400 if (c1->_bridge) { 04401 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 04402 c1->name, c1->_bridge->name); 04403 return -1; 04404 } 04405 04406 /* Stop if we're a zombie or need a soft hangup */ 04407 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 04408 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) 04409 return -1; 04410 04411 *fo = NULL; 04412 firstpass = config->firstpass; 04413 config->firstpass = 0; 04414 04415 if (ast_tvzero(config->start_time)) 04416 config->start_time = ast_tvnow(); 04417 time_left_ms = config->timelimit; 04418 04419 caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING); 04420 callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING); 04421 04422 if (config->start_sound && firstpass) { 04423 if (caller_warning) 04424 bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000); 04425 if (callee_warning) 04426 bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000); 04427 } 04428 04429 /* Keep track of bridge */ 04430 c0->_bridge = c1; 04431 c1->_bridge = c0; 04432 04433 /* \todo XXX here should check that cid_num is not NULL */ 04434 manager_event(EVENT_FLAG_CALL, "Link", 04435 "Channel1: %s\r\n" 04436 "Channel2: %s\r\n" 04437 "Uniqueid1: %s\r\n" 04438 "Uniqueid2: %s\r\n" 04439 "CallerID1: %s\r\n" 04440 "CallerID2: %s\r\n", 04441 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 04442 04443 o0nativeformats = c0->nativeformats; 04444 o1nativeformats = c1->nativeformats; 04445 04446 if (config->feature_timer && !ast_tvzero(config->nexteventts)) { 04447 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000)); 04448 } else if (config->timelimit && firstpass) { 04449 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 04450 if (caller_warning || callee_warning) 04451 config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000)); 04452 } 04453 04454 if (!c0->tech->send_digit_begin) 04455 ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY); 04456 if (!c1->tech->send_digit_begin) 04457 ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); 04458 04459 /* Before we enter in and bridge these two together tell them both the source of audio has changed */ 04460 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 04461 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 04462 04463 for (/* ever */;;) { 04464 struct timeval now = { 0, }; 04465 int to; 04466 04467 to = -1; 04468 04469 if (!ast_tvzero(config->nexteventts)) { 04470 now = ast_tvnow(); 04471 to = ast_tvdiff_ms(config->nexteventts, now); 04472 if (to <= 0) { 04473 if (!config->timelimit) { 04474 res = AST_BRIDGE_COMPLETE; 04475 break; 04476 } 04477 to = 0; 04478 } 04479 } 04480 04481 if (config->timelimit) { 04482 time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time); 04483 if (time_left_ms < to) 04484 to = time_left_ms; 04485 04486 if (time_left_ms <= 0) { 04487 if (caller_warning && config->end_sound) 04488 bridge_playfile(c0, c1, config->end_sound, 0); 04489 if (callee_warning && config->end_sound) 04490 bridge_playfile(c1, c0, config->end_sound, 0); 04491 *fo = NULL; 04492 if (who) 04493 *rc = who; 04494 res = 0; 04495 break; 04496 } 04497 04498 if (!to) { 04499 if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) { 04500 int t = (time_left_ms + 500) / 1000; /* round to nearest second */ 04501 if (caller_warning) 04502 bridge_playfile(c0, c1, config->warning_sound, t); 04503 if (callee_warning) 04504 bridge_playfile(c1, c0, config->warning_sound, t); 04505 } 04506 if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) 04507 config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000)); 04508 else 04509 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 04510 } 04511 ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE); 04512 } 04513 04514 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 04515 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04516 c0->_softhangup = 0; 04517 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04518 c1->_softhangup = 0; 04519 c0->_bridge = c1; 04520 c1->_bridge = c0; 04521 if (option_debug) 04522 ast_log(LOG_DEBUG, "Unbridge signal received. Ending native bridge.\n"); 04523 continue; 04524 } 04525 04526 /* Stop if we're a zombie or need a soft hangup */ 04527 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 04528 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { 04529 *fo = NULL; 04530 if (who) 04531 *rc = who; 04532 res = 0; 04533 if (option_debug) 04534 ast_log(LOG_DEBUG, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n", 04535 c0->name, c1->name, 04536 ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No", 04537 ast_check_hangup(c0) ? "Yes" : "No", 04538 ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No", 04539 ast_check_hangup(c1) ? "Yes" : "No"); 04540 break; 04541 } 04542 04543 update_bridgepeer(c0, c1); 04544 04545 if (c0->tech->bridge && 04546 (config->timelimit == 0) && 04547 (c0->tech->bridge == c1->tech->bridge) && 04548 !nativefailed && !c0->monitor && !c1->monitor && 04549 !c0->audiohooks && !c1->audiohooks && !ast_test_flag(&(config->features_callee),AST_FEATURE_REDIRECT) && 04550 !ast_test_flag(&(config->features_caller),AST_FEATURE_REDIRECT) && 04551 !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) { 04552 /* Looks like they share a bridge method and nothing else is in the way */ 04553 ast_set_flag(c0, AST_FLAG_NBRIDGE); 04554 ast_set_flag(c1, AST_FLAG_NBRIDGE); 04555 if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, to)) == AST_BRIDGE_COMPLETE) { 04556 /* \todo XXX here should check that cid_num is not NULL */ 04557 manager_event(EVENT_FLAG_CALL, "Unlink", 04558 "Channel1: %s\r\n" 04559 "Channel2: %s\r\n" 04560 "Uniqueid1: %s\r\n" 04561 "Uniqueid2: %s\r\n" 04562 "CallerID1: %s\r\n" 04563 "CallerID2: %s\r\n", 04564 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 04565 if (option_debug) 04566 ast_log(LOG_DEBUG, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name); 04567 04568 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 04569 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 04570 04571 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04572 continue; 04573 04574 c0->_bridge = NULL; 04575 c1->_bridge = NULL; 04576 04577 return res; 04578 } else { 04579 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 04580 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 04581 } 04582 switch (res) { 04583 case AST_BRIDGE_RETRY: 04584 if (config->play_warning) { 04585 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 04586 } 04587 continue; 04588 default: 04589 if (option_verbose > 2) 04590 ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s ended\n", 04591 c0->name, c1->name); 04592 /* fallthrough */ 04593 case AST_BRIDGE_FAILED_NOWARN: 04594 nativefailed++; 04595 break; 04596 } 04597 } 04598 04599 if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || 04600 (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && 04601 !(c0->generator || c1->generator)) { 04602 if (ast_channel_make_compatible(c0, c1)) { 04603 ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name); 04604 /* \todo XXX here should check that cid_num is not NULL */ 04605 manager_event(EVENT_FLAG_CALL, "Unlink", 04606 "Channel1: %s\r\n" 04607 "Channel2: %s\r\n" 04608 "Uniqueid1: %s\r\n" 04609 "Uniqueid2: %s\r\n" 04610 "CallerID1: %s\r\n" 04611 "CallerID2: %s\r\n", 04612 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 04613 return AST_BRIDGE_FAILED; 04614 } 04615 o0nativeformats = c0->nativeformats; 04616 o1nativeformats = c1->nativeformats; 04617 } 04618 04619 update_bridgepeer(c0, c1); 04620 04621 res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts); 04622 if (res != AST_BRIDGE_RETRY) { 04623 break; 04624 } else if (config->feature_timer) { 04625 /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */ 04626 break; 04627 } 04628 } 04629 04630 ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY); 04631 ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY); 04632 04633 /* Now that we have broken the bridge the source will change yet again */ 04634 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 04635 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 04636 04637 c0->_bridge = NULL; 04638 c1->_bridge = NULL; 04639 04640 /* \todo XXX here should check that cid_num is not NULL */ 04641 manager_event(EVENT_FLAG_CALL, "Unlink", 04642 "Channel1: %s\r\n" 04643 "Channel2: %s\r\n" 04644 "Uniqueid1: %s\r\n" 04645 "Uniqueid2: %s\r\n" 04646 "CallerID1: %s\r\n" 04647 "CallerID2: %s\r\n", 04648 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 04649 if (option_debug) 04650 ast_log(LOG_DEBUG, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name); 04651 04652 return res; 04653 }
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 475 of file channel.c.
References ast_channel::whentohangup.
00476 { 00477 time_t whentohangup; 00478 00479 if (chan->whentohangup == 0) { 00480 return (offset == 0) ? 0 : -1; 00481 } else { 00482 if (offset == 0) /* XXX why is this special ? */ 00483 return (1); 00484 else { 00485 whentohangup = offset + time (NULL); 00486 if (chan->whentohangup < whentohangup) 00487 return (1); 00488 else if (chan->whentohangup == whentohangup) 00489 return (0); 00490 else 00491 return (-1); 00492 } 00493 } 00494 }
int ast_channel_datastore_add | ( | struct ast_channel * | chan, | |
struct ast_datastore * | datastore | |||
) |
Add a datastore to a channel.
Definition at line 1404 of file channel.c.
References AST_LIST_INSERT_HEAD, ast_channel::datastores, and ast_datastore::entry.
Referenced by _macro_exec(), add_features_datastores(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), smdi_msg_retrieve_read(), speech_create(), and try_calling().
01405 { 01406 int res = 0; 01407 01408 AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry); 01409 01410 return res; 01411 }
struct ast_datastore* ast_channel_datastore_alloc | ( | const struct ast_datastore_info * | info, | |
char * | uid | |||
) |
Create a channel datastore structure.
Definition at line 1343 of file channel.c.
References ast_calloc, ast_strdup, and ast_datastore::info.
Referenced by _macro_exec(), add_features_datastores(), ast_channel_datastore_inherit(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), smdi_msg_retrieve_read(), speech_create(), and try_calling().
01344 { 01345 struct ast_datastore *datastore = NULL; 01346 01347 /* Make sure we at least have type so we can identify this */ 01348 if (info == NULL) { 01349 return NULL; 01350 } 01351 01352 /* Allocate memory for datastore and clear it */ 01353 datastore = ast_calloc(1, sizeof(*datastore)); 01354 if (datastore == NULL) { 01355 return NULL; 01356 } 01357 01358 datastore->info = info; 01359 01360 datastore->uid = ast_strdup(uid); 01361 01362 return datastore; 01363 }
struct ast_datastore* ast_channel_datastore_find | ( | struct ast_channel * | chan, | |
const struct ast_datastore_info * | info, | |||
char * | uid | |||
) |
Find a datastore on a channel.
Definition at line 1431 of file channel.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel::datastores, ast_datastore::entry, ast_datastore::info, and ast_datastore::uid.
Referenced by _macro_exec(), add_features_datastores(), attended_transfer_occurred(), chanspy_ds_free(), do_atxfer(), do_parking_thread(), find_speech(), func_inheritance_write(), park_exec(), queue_transfer_fixup(), smdi_msg_read(), speech_background(), speech_destroy(), stop_mixmonitor_exec(), and try_calling().
01432 { 01433 struct ast_datastore *datastore = NULL; 01434 01435 if (info == NULL) 01436 return NULL; 01437 01438 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) { 01439 if (datastore->info == info) { 01440 if (uid != NULL && datastore->uid != NULL) { 01441 if (!strcasecmp(uid, datastore->uid)) { 01442 /* Matched by type AND uid */ 01443 break; 01444 } 01445 } else { 01446 /* Matched by type at least */ 01447 break; 01448 } 01449 } 01450 } 01451 AST_LIST_TRAVERSE_SAFE_END 01452 01453 return datastore; 01454 }
int ast_channel_datastore_free | ( | struct ast_datastore * | datastore | ) |
Free a channel datastore structure.
Definition at line 1365 of file channel.c.
References ast_datastore::data, ast_datastore_info::destroy, free, ast_datastore::info, and ast_datastore::uid.
Referenced by add_features_datastores(), ast_channel_free(), chanspy_ds_free(), setup_inheritance_datastore(), and try_calling().
01366 { 01367 int res = 0; 01368 01369 /* Using the destroy function (if present) destroy the data */ 01370 if (datastore->info->destroy != NULL && datastore->data != NULL) { 01371 datastore->info->destroy(datastore->data); 01372 datastore->data = NULL; 01373 } 01374 01375 /* Free allocated UID memory */ 01376 if (datastore->uid != NULL) { 01377 free(datastore->uid); 01378 datastore->uid = NULL; 01379 } 01380 01381 /* Finally free memory used by ourselves */ 01382 free(datastore); 01383 01384 return res; 01385 }
int ast_channel_datastore_inherit | ( | struct ast_channel * | from, | |
struct ast_channel * | to | |||
) |
Inherit datastores from a parent to a child.
Definition at line 1387 of file channel.c.
References ast_channel_datastore_alloc(), AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_channel::datastores, ast_datastore_info::duplicate, ast_datastore::entry, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.
Referenced by ast_call_forward(), findmeexec(), local_call(), ring_entry(), and wait_for_answer().
01388 { 01389 struct ast_datastore *datastore = NULL, *datastore2; 01390 01391 AST_LIST_TRAVERSE(&from->datastores, datastore, entry) { 01392 if (datastore->inheritance > 0) { 01393 datastore2 = ast_channel_datastore_alloc(datastore->info, datastore->uid); 01394 if (datastore2) { 01395 datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL; 01396 datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1; 01397 AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry); 01398 } 01399 } 01400 } 01401 return 0; 01402 }
int ast_channel_datastore_remove | ( | struct ast_channel * | chan, | |
struct ast_datastore * | datastore | |||
) |
Remove a datastore from a channel.
Definition at line 1413 of file channel.c.
References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel::datastores, and ast_datastore::entry.
Referenced by chanspy_ds_free(), queue_transfer_fixup(), speech_background(), speech_destroy(), and try_calling().
01414 { 01415 struct ast_datastore *datastore2 = NULL; 01416 int res = -1; 01417 01418 /* Find our position and remove ourselves */ 01419 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore2, entry) { 01420 if (datastore2 == datastore) { 01421 AST_LIST_REMOVE_CURRENT(&chan->datastores, entry); 01422 res = 0; 01423 break; 01424 } 01425 } 01426 AST_LIST_TRAVERSE_SAFE_END 01427 01428 return res; 01429 }
int ast_channel_defer_dtmf | ( | struct ast_channel * | chan | ) |
Set defer DTMF flag on channel.
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 1036 of file channel.c.
References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.
Referenced by __adsi_transmit_messages(), and find_cache().
01037 { 01038 int pre = 0; 01039 01040 if (chan) { 01041 pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF); 01042 ast_set_flag(chan, AST_FLAG_DEFER_DTMF); 01043 } 01044 return pre; 01045 }
void ast_channel_free | ( | struct ast_channel * | ) |
Free a channel structure.
Definition at line 1243 of file channel.c.
References ast_channel::alertpipe, ast_app_group_discard(), ast_cdr_discard(), ast_channel_datastore_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), ast_device_state_changed_literal(), AST_FLAG_IN_CHANNEL_LIST, ast_frfree, ast_jb_destroy(), AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), ast_moh_cleanup(), ast_mutex_destroy, ast_string_field_free_memory, ast_test_flag, ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, ast_channel::cid, ast_channel::datastores, ast_datastore::entry, f, free, free_cid(), ast_channel::lock, LOG_DEBUG, ast_channel::monitor, ast_channel::music_state, ast_channel::name, name, option_debug, 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::timingfd, ast_channel::varshead, and ast_channel::writetrans.
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(), gtalk_newcall(), local_new(), make_email_file(), pbx_substitute_variables_helper_full(), and sendpage().
01244 { 01245 int fd; 01246 struct ast_var_t *vardata; 01247 struct ast_frame *f; 01248 struct varshead *headp; 01249 struct ast_datastore *datastore = NULL; 01250 char name[AST_CHANNEL_NAME], *dashptr; 01251 int inlist; 01252 01253 headp=&chan->varshead; 01254 01255 inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01256 if (inlist) { 01257 AST_LIST_LOCK(&channels); 01258 if (!AST_LIST_REMOVE(&channels, chan, chan_list)) { 01259 if (option_debug) 01260 ast_log(LOG_DEBUG, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01261 } 01262 /* Lock and unlock the channel just to be sure nobody has it locked still 01263 due to a reference retrieved from the channel list. */ 01264 ast_channel_lock(chan); 01265 ast_channel_unlock(chan); 01266 } 01267 01268 /* Get rid of each of the data stores on the channel */ 01269 while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry))) 01270 /* Free the data store */ 01271 ast_channel_datastore_free(datastore); 01272 01273 /* Lock and unlock the channel just to be sure nobody has it locked still 01274 due to a reference that was stored in a datastore. (i.e. app_chanspy) */ 01275 ast_channel_lock(chan); 01276 ast_channel_unlock(chan); 01277 01278 if (chan->tech_pvt) { 01279 ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); 01280 free(chan->tech_pvt); 01281 } 01282 01283 if (chan->sched) 01284 sched_context_destroy(chan->sched); 01285 01286 ast_copy_string(name, chan->name, sizeof(name)); 01287 if ((dashptr = strrchr(name, '-'))) { 01288 *dashptr = '\0'; 01289 } 01290 01291 /* Stop monitoring */ 01292 if (chan->monitor) 01293 chan->monitor->stop( chan, 0 ); 01294 01295 /* If there is native format music-on-hold state, free it */ 01296 if (chan->music_state) 01297 ast_moh_cleanup(chan); 01298 01299 /* Free translators */ 01300 if (chan->readtrans) 01301 ast_translator_free_path(chan->readtrans); 01302 if (chan->writetrans) 01303 ast_translator_free_path(chan->writetrans); 01304 if (chan->pbx) 01305 ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); 01306 free_cid(&chan->cid); 01307 /* Close pipes if appropriate */ 01308 if ((fd = chan->alertpipe[0]) > -1) 01309 close(fd); 01310 if ((fd = chan->alertpipe[1]) > -1) 01311 close(fd); 01312 if ((fd = chan->timingfd) > -1) 01313 close(fd); 01314 while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list))) 01315 ast_frfree(f); 01316 01317 /* loop over the variables list, freeing all data and deleting list items */ 01318 /* no need to lock the list, as the channel is already locked */ 01319 01320 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) 01321 ast_var_delete(vardata); 01322 01323 ast_app_group_discard(chan); 01324 01325 /* Destroy the jitterbuffer */ 01326 ast_jb_destroy(chan); 01327 01328 if (chan->cdr) { 01329 ast_cdr_discard(chan->cdr); 01330 chan->cdr = NULL; 01331 } 01332 01333 ast_mutex_destroy(&chan->lock); 01334 01335 ast_string_field_free_memory(chan); 01336 free(chan); 01337 if (inlist) 01338 AST_LIST_UNLOCK(&channels); 01339 01340 ast_device_state_changed_literal(name); 01341 }
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 |
Definition at line 3705 of file channel.c.
References AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), ast_var_t::entries, LOG_DEBUG, option_debug, and ast_channel::varshead.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), begin_dial(), findmeexec(), ring_entry(), and wait_for_answer().
03706 { 03707 struct ast_var_t *current, *newvar; 03708 const char *varname; 03709 03710 AST_LIST_TRAVERSE(&parent->varshead, current, entries) { 03711 int vartype = 0; 03712 03713 varname = ast_var_full_name(current); 03714 if (!varname) 03715 continue; 03716 03717 if (varname[0] == '_') { 03718 vartype = 1; 03719 if (varname[1] == '_') 03720 vartype = 2; 03721 } 03722 03723 switch (vartype) { 03724 case 1: 03725 newvar = ast_var_assign(&varname[1], ast_var_value(current)); 03726 if (newvar) { 03727 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 03728 if (option_debug) 03729 ast_log(LOG_DEBUG, "Copying soft-transferable variable %s.\n", ast_var_name(newvar)); 03730 } 03731 break; 03732 case 2: 03733 newvar = ast_var_assign(ast_var_full_name(current), ast_var_value(current)); 03734 if (newvar) { 03735 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 03736 if (option_debug) 03737 ast_log(LOG_DEBUG, "Copying hard-transferable variable %s.\n", ast_var_name(newvar)); 03738 } 03739 break; 03740 default: 03741 if (option_debug) 03742 ast_log(LOG_DEBUG, "Not copying variable %s.\n", ast_var_name(current)); 03743 break; 03744 } 03745 } 03746 }
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 3558 of file channel.c.
References AST_FORMAT_SLINEAR, ast_log(), ast_opt_transcode_via_slin, ast_set_read_format(), ast_set_write_format(), ast_translate_path_steps(), ast_translator_best_choice(), ast_channel::name, ast_channel::nativeformats, ast_channel::readformat, and ast_channel::writeformat.
Referenced by app_exec(), ast_channel_bridge(), check_compat(), park_exec(), and wait_for_answer().
03559 { 03560 int src; 03561 int dst; 03562 03563 if (chan->readformat == peer->writeformat && chan->writeformat == peer->readformat) { 03564 /* Already compatible! Moving on ... */ 03565 return 0; 03566 } 03567 03568 /* Set up translation from the chan to the peer */ 03569 src = chan->nativeformats; 03570 dst = peer->nativeformats; 03571 if (ast_translator_best_choice(&dst, &src) < 0) { 03572 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, src, peer->name, dst); 03573 return -1; 03574 } 03575 03576 /* if the best path is not 'pass through', then 03577 transcoding is needed; if desired, force transcode path 03578 to use SLINEAR between channels, but only if there is 03579 no direct conversion available */ 03580 if ((src != dst) && ast_opt_transcode_via_slin && 03581 (ast_translate_path_steps(dst, src) != 1)) 03582 dst = AST_FORMAT_SLINEAR; 03583 if (ast_set_read_format(chan, dst) < 0) { 03584 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, dst); 03585 return -1; 03586 } 03587 if (ast_set_write_format(peer, dst) < 0) { 03588 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, dst); 03589 return -1; 03590 } 03591 03592 /* Set up translation from the peer to the chan */ 03593 src = peer->nativeformats; 03594 dst = chan->nativeformats; 03595 if (ast_translator_best_choice(&dst, &src) < 0) { 03596 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", peer->name, src, chan->name, dst); 03597 return -1; 03598 } 03599 03600 /* if the best path is not 'pass through', then 03601 transcoding is needed; if desired, force transcode path 03602 to use SLINEAR between channels, but only if there is 03603 no direct conversion available */ 03604 if ((src != dst) && ast_opt_transcode_via_slin && 03605 (ast_translate_path_steps(dst, src) != 1)) 03606 dst = AST_FORMAT_SLINEAR; 03607 if (ast_set_read_format(peer, dst) < 0) { 03608 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst); 03609 return -1; 03610 } 03611 if (ast_set_write_format(chan, dst) < 0) { 03612 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, dst); 03613 return -1; 03614 } 03615 return 0; 03616 }
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 3618 of file channel.c.
References ast_channel::_bridge, ast_bridged_channel(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_log(), ast_null_frame, ast_queue_frame(), ast_channel_tech::get_base_channel, LOG_DEBUG, ast_channel::masq, ast_channel::masqr, ast_channel::name, option_debug, and ast_channel::tech.
Referenced by ast_async_goto(), ast_pickup_call(), attempt_transfer(), check_availability(), check_bridge(), check_goto_on_transfer(), do_atxfer(), handle_invite_replaces(), iax_park(), masq_park_call(), misdn_attempt_transfer(), pickup_do(), and sip_park().
03619 { 03620 int res = -1; 03621 struct ast_channel *final_orig, *final_clone, *base; 03622 03623 retrymasq: 03624 final_orig = original; 03625 final_clone = clone; 03626 03627 ast_channel_lock(original); 03628 while (ast_channel_trylock(clone)) { 03629 ast_channel_unlock(original); 03630 usleep(1); 03631 ast_channel_lock(original); 03632 } 03633 03634 /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent) 03635 and if so, we don't really want to masquerade it, but its proxy */ 03636 if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original)) 03637 final_orig = original->_bridge; 03638 03639 if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)) && (clone->_bridge->_bridge != clone)) 03640 final_clone = clone->_bridge; 03641 03642 if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) { 03643 final_clone = base; 03644 } 03645 03646 if ((final_orig != original) || (final_clone != clone)) { 03647 /* Lots and lots of deadlock avoidance. The main one we're competing with 03648 * is ast_write(), which locks channels recursively, when working with a 03649 * proxy channel. */ 03650 if (ast_channel_trylock(final_orig)) { 03651 ast_channel_unlock(clone); 03652 ast_channel_unlock(original); 03653 goto retrymasq; 03654 } 03655 if (ast_channel_trylock(final_clone)) { 03656 ast_channel_unlock(final_orig); 03657 ast_channel_unlock(clone); 03658 ast_channel_unlock(original); 03659 goto retrymasq; 03660 } 03661 ast_channel_unlock(clone); 03662 ast_channel_unlock(original); 03663 original = final_orig; 03664 clone = final_clone; 03665 } 03666 03667 if (original == clone) { 03668 ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); 03669 ast_channel_unlock(clone); 03670 ast_channel_unlock(original); 03671 return -1; 03672 } 03673 03674 if (option_debug) 03675 ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n", 03676 clone->name, original->name); 03677 if (original->masq) { 03678 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 03679 original->masq->name, original->name); 03680 } else if (clone->masqr) { 03681 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 03682 clone->name, clone->masqr->name); 03683 } else { 03684 original->masq = clone; 03685 clone->masqr = original; 03686 ast_queue_frame(original, &ast_null_frame); 03687 ast_queue_frame(clone, &ast_null_frame); 03688 if (option_debug) 03689 ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name); 03690 res = 0; 03691 } 03692 03693 ast_channel_unlock(clone); 03694 ast_channel_unlock(original); 03695 03696 return res; 03697 }
struct ast_frame* ast_channel_queryoption | ( | struct ast_channel * | channel, | |
int | option, | |||
void * | data, | |||
int * | datalen, | |||
int | block | |||
) |
Query the value of an option, optionally blocking until a reply is received Works similarly to setoption except only reads the options.
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 3152 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().
03153 { 03154 switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */ 03155 { 03156 case 0: 03157 return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)"; 03158 case AST_CONTROL_HANGUP: 03159 return "Hangup"; 03160 case AST_CONTROL_RING: 03161 return "Local Ring"; 03162 case AST_CONTROL_RINGING: 03163 return "Remote end Ringing"; 03164 case AST_CONTROL_ANSWER: 03165 return "Remote end has Answered"; 03166 case AST_CONTROL_BUSY: 03167 return "Remote end is Busy"; 03168 case AST_CONTROL_CONGESTION: 03169 return "Congestion (circuits busy)"; 03170 default: 03171 return "Unknown Reason!!"; 03172 } 03173 }
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 497 of file channel.c.
References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_verbose(), chanlist::list, LOG_DEBUG, LOG_WARNING, option_debug, option_verbose, chanlist::tech, ast_channel_tech::type, and VERBOSE_PREFIX_2.
Referenced by load_module(), and unload_module().
00498 { 00499 struct chanlist *chan; 00500 00501 AST_LIST_LOCK(&channels); 00502 00503 AST_LIST_TRAVERSE(&backends, chan, list) { 00504 if (!strcasecmp(tech->type, chan->tech->type)) { 00505 ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type); 00506 AST_LIST_UNLOCK(&channels); 00507 return -1; 00508 } 00509 } 00510 00511 if (!(chan = ast_calloc(1, sizeof(*chan)))) { 00512 AST_LIST_UNLOCK(&channels); 00513 return -1; 00514 } 00515 chan->tech = tech; 00516 AST_LIST_INSERT_HEAD(&backends, chan, list); 00517 00518 if (option_debug) 00519 ast_log(LOG_DEBUG, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description); 00520 00521 if (option_verbose > 1) 00522 ast_verbose(VERBOSE_PREFIX_2 "Registered channel type '%s' (%s)\n", chan->tech->type, 00523 chan->tech->description); 00524 00525 AST_LIST_UNLOCK(&channels); 00526 return 0; 00527 }
int ast_channel_sendhtml | ( | struct ast_channel * | channel, | |
int | subclass, | |||
const char * | data, | |||
int | datalen | |||
) |
Send HTML or URL on link. Returns 0 on success or -1 on failure
Definition at line 3546 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().
03547 { 03548 if (chan->tech->send_html) 03549 return chan->tech->send_html(chan, subclass, data, datalen); 03550 return -1; 03551 }
int ast_channel_sendurl | ( | struct ast_channel * | channel, | |
const char * | url | |||
) |
Send URL on link. Returns 0 on success or -1 on failure
Definition at line 3553 of file channel.c.
References ast_channel_sendhtml(), and AST_HTML_URL.
Referenced by sendurl_exec().
03554 { 03555 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1); 03556 }
int ast_channel_setoption | ( | struct ast_channel * | channel, | |
int | option, | |||
void * | data, | |||
int | datalen, | |||
int | block | |||
) |
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 4656 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(), func_channel_write(), handle_tddmode(), play_record_review(), reset_volumes(), rpt(), set_listen_volume(), set_talk_volume(), and vm_forwardoptions().
04657 { 04658 int res; 04659 04660 if (chan->tech->setoption) { 04661 res = chan->tech->setoption(chan, option, data, datalen); 04662 if (res < 0) 04663 return res; 04664 } else { 04665 errno = ENOSYS; 04666 return -1; 04667 } 04668 if (block) { 04669 /* XXX Implement blocking -- just wait for our option frame reply, discarding 04670 intermediate packets. XXX */ 04671 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 04672 return -1; 04673 } 04674 return 0; 04675 }
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 from current time of when to hang up This function sets the absolute time out on a channel (when to hang up). |
Definition at line 467 of file channel.c.
References ast_null_frame, ast_queue_frame(), and ast_channel::whentohangup.
Referenced by action_timeout(), and timeout_write().
00468 { 00469 chan->whentohangup = offset ? time(NULL) + offset : 0; 00470 ast_queue_frame(chan, &ast_null_frame); 00471 return; 00472 }
struct ast_silence_generator* ast_channel_start_silence_generator | ( | struct ast_channel * | chan | ) |
Starts a silence generator on the given channel.
chan | The channel to generate silence on |
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 4984 of file channel.c.
References ast_activate_generator(), ast_calloc, AST_FORMAT_SLINEAR, ast_log(), ast_set_write_format(), free, LOG_DEBUG, LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, option_debug, silence_generator, and ast_channel::writeformat.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), and channel_spy().
04985 { 04986 struct ast_silence_generator *state; 04987 04988 if (!(state = ast_calloc(1, sizeof(*state)))) { 04989 return NULL; 04990 } 04991 04992 state->old_write_format = chan->writeformat; 04993 04994 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { 04995 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n"); 04996 free(state); 04997 return NULL; 04998 } 04999 05000 ast_activate_generator(chan, &silence_generator, state); 05001 05002 if (option_debug) 05003 ast_log(LOG_DEBUG, "Started silence generator on '%s'\n", chan->name); 05004 05005 return state; 05006 }
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. |
Definition at line 5008 of file channel.c.
References ast_deactivate_generator(), ast_log(), ast_set_write_format(), free, LOG_DEBUG, LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, and option_debug.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), and channel_spy().
05009 { 05010 if (!state) 05011 return; 05012 05013 ast_deactivate_generator(chan); 05014 05015 if (option_debug) 05016 ast_log(LOG_DEBUG, "Stopped silence generator on '%s'\n", chan->name); 05017 05018 if (ast_set_write_format(chan, state->old_write_format) < 0) 05019 ast_log(LOG_ERROR, "Could not return write format to its original state\n"); 05020 05021 free(state); 05022 }
int ast_channel_supports_html | ( | struct ast_channel * | channel | ) |
Returns 0 if channel does not support HTML or non-zero if it does
Definition at line 3541 of file channel.c.
References ast_channel_tech::send_html, and ast_channel::tech.
Referenced by sendurl_exec().
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 1048 of file channel.c.
References ast_clear_flag, and AST_FLAG_DEFER_DTMF.
Referenced by __adsi_transmit_messages(), find_cache(), and rpt_call().
01049 { 01050 if (chan) 01051 ast_clear_flag(chan, AST_FLAG_DEFER_DTMF); 01052 }
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 529 of file channel.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_verbose(), free, chanlist::list, LOG_DEBUG, option_debug, option_verbose, chanlist::tech, ast_channel_tech::type, and VERBOSE_PREFIX_2.
Referenced by __unload_module(), and unload_module().
00530 { 00531 struct chanlist *chan; 00532 00533 if (option_debug) 00534 ast_log(LOG_DEBUG, "Unregistering channel type '%s'\n", tech->type); 00535 00536 AST_LIST_LOCK(&channels); 00537 00538 AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) { 00539 if (chan->tech == tech) { 00540 AST_LIST_REMOVE_CURRENT(&backends, list); 00541 free(chan); 00542 if (option_verbose > 1) 00543 ast_verbose(VERBOSE_PREFIX_2 "Unregistered channel type '%s'\n", tech->type); 00544 break; 00545 } 00546 } 00547 AST_LIST_TRAVERSE_SAFE_END 00548 00549 AST_LIST_UNLOCK(&channels); 00550 }
struct ast_channel* ast_channel_walk_locked | ( | const struct ast_channel * | prev | ) |
Browse channels in use Browse the channels currently in use.
prev | where you want to start in the channel list |
Definition at line 1164 of file channel.c.
References channel_find_locked().
Referenced by action_status(), ast_complete_channels(), ast_pickup_call(), complete_ch_helper(), conf_exec(), handle_chanlist(), handle_chanlist_deprecated(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_nodebugchan_deprecated(), next_channel(), pickup_by_exten(), pickup_by_mark(), and softhangup_exec().
01165 { 01166 return channel_find_locked(prev, NULL, 0, NULL, NULL); 01167 }
int ast_channel_whisper_feed | ( | struct ast_channel * | chan, | |
struct ast_frame * | f | |||
) |
Feed an audio frame into the whisper buffer on a channel.
chan | The channel to whisper onto | |
f | The frame to to whisper onto chan |
int ast_channel_whisper_start | ( | struct ast_channel * | chan | ) |
Begin 'whispering' onto a channel.
chan | The channel to whisper onto |
Note: This function performs no locking; you must hold the channel's lock before calling this function.
void ast_channel_whisper_stop | ( | struct ast_channel * | chan | ) |
Stop 'whispering' onto a channel.
chan | The channel to whisper onto |
struct ast_variable* ast_channeltype_list | ( | void | ) |
return an ast_variable list of channeltypes
Definition at line 163 of file channel.c.
References AST_LIST_TRAVERSE, ast_variable_new(), ast_channel_tech::description, chanlist::list, chanlist::tech, ast_channel_tech::type, and var.
00164 { 00165 struct chanlist *cl; 00166 struct ast_variable *var=NULL, *prev = NULL; 00167 AST_LIST_TRAVERSE(&backends, cl, list) { 00168 if (prev) { 00169 if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description))) 00170 prev = prev->next; 00171 } else { 00172 var = ast_variable_new(cl->tech->type, cl->tech->description); 00173 prev = var; 00174 } 00175 } 00176 return var; 00177 }
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 385 of file channel.c.
References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_channel::tech_pvt, and ast_channel::whentohangup.
Referenced by __ast_read(), _macro_exec(), action_redirect(), agent_indicate(), agi_handle_command(), announce_thread(), app_exec(), ast_answer(), ast_bridge_call(), ast_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_feature_request_and_dial(), ast_indicate_data(), ast_readstring_full(), ast_recvtext(), ast_rtp_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), bridge_native_loop(), channel_spy(), common_exec(), conf_run(), dahdi_sendtext(), dahdi_setoption(), deadagi_exec(), do_atxfer(), findmeexec(), handle_sendimage(), pbx_exec(), rpt(), and wait_for_answer().
00386 { 00387 if (chan->_softhangup) /* yes if soft hangup flag set */ 00388 return 1; 00389 if (!chan->tech_pvt) /* yes if no technology private data */ 00390 return 1; 00391 if (!chan->whentohangup) /* no if no hangup scheduled */ 00392 return 0; 00393 if (chan->whentohangup > time(NULL)) /* no if hangup time has not come yet. */ 00394 return 0; 00395 chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */ 00396 return 1; 00397 }
void ast_deactivate_generator | ( | struct ast_channel * | chan | ) |
Deactive an active generator
Definition at line 1632 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_clear_flag, AST_FLAG_WRITE_INT, AST_GENERATOR_FD, ast_settimeout(), ast_channel::fds, 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(), generator_force(), local_ast_moh_stop(), old_milliwatt_exec(), and wait_for_answer().
01633 { 01634 ast_channel_lock(chan); 01635 if (chan->generatordata) { 01636 if (chan->generator && chan->generator->release) 01637 chan->generator->release(chan, chan->generatordata); 01638 chan->generatordata = NULL; 01639 chan->generator = NULL; 01640 chan->fds[AST_GENERATOR_FD] = -1; 01641 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 01642 ast_settimeout(chan, 0, NULL, NULL); 01643 } 01644 ast_channel_unlock(chan); 01645 }
int ast_do_masquerade | ( | struct ast_channel * | original | ) |
Start masquerading a channel XXX This is a seriously wacked 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 3799 of file channel.c.
References ast_channel::_softhangup, ast_channel::_state, ast_channel::adsicpe, ast_channel::alertpipe, ast_app_group_update(), ast_cause2str(), ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), 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_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, ast_datastore::entry, errno, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_datastore::info, ast_channel::language, language, ast_channel::lock, LOG_DEBUG, manager_event(), ast_channel::masq, ast_channel::masqr, ast_channel::monitor, musicclass, name, ast_channel::name, ast_channel::nativeformats, option_debug, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::readq, report_new_callerid(), t, ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, ast_cdr::uniqueid, ast_channel::uniqueid, ast_channel::visible_indication, ast_channel::whentohangup, and ast_channel::writeformat.
Referenced by __ast_read(), ast_async_goto(), ast_hangup(), ast_waitfor_nandfds(), ast_write(), handle_invite_replaces(), iax_park(), sip_park(), and sip_park_thread().
03800 { 03801 int x,i; 03802 int res=0; 03803 int origstate; 03804 struct ast_frame *cur; 03805 const struct ast_channel_tech *t; 03806 void *t_pvt; 03807 struct ast_callerid tmpcid; 03808 struct ast_channel *clone = original->masq; 03809 struct ast_cdr *cdr; 03810 int rformat = original->readformat; 03811 int wformat = original->writeformat; 03812 char newn[100]; 03813 char orig[100]; 03814 char masqn[100]; 03815 char zombn[100]; 03816 03817 if (option_debug > 3) 03818 ast_log(LOG_DEBUG, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", 03819 clone->name, clone->_state, original->name, original->_state); 03820 03821 /* XXX This operation is a bit odd. We're essentially putting the guts of 03822 * the clone channel into the original channel. Start by killing off the 03823 * original channel's backend. While the features are nice, which is the 03824 * reason we're keeping it, it's still awesomely weird. XXX */ 03825 03826 /* We need the clone's lock, too */ 03827 ast_channel_lock(clone); 03828 03829 if (option_debug > 1) 03830 ast_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock); 03831 03832 /* Having remembered the original read/write formats, we turn off any translation on either 03833 one */ 03834 free_translation(clone); 03835 free_translation(original); 03836 03837 03838 /* Unlink the masquerade */ 03839 original->masq = NULL; 03840 clone->masqr = NULL; 03841 03842 /* Save the original name */ 03843 ast_copy_string(orig, original->name, sizeof(orig)); 03844 /* Save the new name */ 03845 ast_copy_string(newn, clone->name, sizeof(newn)); 03846 /* Create the masq name */ 03847 snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn); 03848 03849 /* Copy the name from the clone channel */ 03850 ast_string_field_set(original, name, newn); 03851 03852 /* Mangle the name of the clone channel */ 03853 ast_string_field_set(clone, name, masqn); 03854 03855 /* Notify any managers of the change, first the masq then the other */ 03856 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clone->uniqueid); 03857 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); 03858 03859 /* Swap the technologies */ 03860 t = original->tech; 03861 original->tech = clone->tech; 03862 clone->tech = t; 03863 03864 /* Swap the cdrs */ 03865 cdr = original->cdr; 03866 /* swap cdr uniqueid between channels, to get cdr uniqueid = channel uniqueid */ 03867 ast_copy_string(clone->cdr->uniqueid, cdr->uniqueid, sizeof(cdr->uniqueid)); 03868 original->cdr = clone->cdr; 03869 clone->cdr = cdr; 03870 03871 t_pvt = original->tech_pvt; 03872 original->tech_pvt = clone->tech_pvt; 03873 clone->tech_pvt = t_pvt; 03874 03875 /* Swap the alertpipes */ 03876 for (i = 0; i < 2; i++) { 03877 x = original->alertpipe[i]; 03878 original->alertpipe[i] = clone->alertpipe[i]; 03879 clone->alertpipe[i] = x; 03880 } 03881 03882 /* 03883 * Swap the readq's. The end result should be this: 03884 * 03885 * 1) All frames should be on the new (original) channel. 03886 * 2) Any frames that were already on the new channel before this 03887 * masquerade need to be at the end of the readq, after all of the 03888 * frames on the old (clone) channel. 03889 * 3) The alertpipe needs to get poked for every frame that was already 03890 * on the new channel, since we are now using the alert pipe from the 03891 * old (clone) channel. 03892 */ 03893 { 03894 AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq; 03895 AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL); 03896 03897 AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list); 03898 AST_LIST_APPEND_LIST(&original->readq, &clone->readq, frame_list); 03899 03900 while ((cur = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) { 03901 AST_LIST_INSERT_TAIL(&original->readq, cur, frame_list); 03902 if (original->alertpipe[1] > -1) { 03903 int poke = 0; 03904 03905 if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) { 03906 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 03907 } 03908 } 03909 } 03910 } 03911 03912 /* Swap the raw formats */ 03913 x = original->rawreadformat; 03914 original->rawreadformat = clone->rawreadformat; 03915 clone->rawreadformat = x; 03916 x = original->rawwriteformat; 03917 original->rawwriteformat = clone->rawwriteformat; 03918 clone->rawwriteformat = x; 03919 03920 clone->_softhangup = AST_SOFTHANGUP_DEV; 03921 03922 /* And of course, so does our current state. Note we need not 03923 call ast_setstate since the event manager doesn't really consider 03924 these separate. We do this early so that the clone has the proper 03925 state of the original channel. */ 03926 origstate = original->_state; 03927 original->_state = clone->_state; 03928 clone->_state = origstate; 03929 03930 if (clone->tech->fixup){ 03931 res = clone->tech->fixup(original, clone); 03932 if (res) 03933 ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clone->name); 03934 } 03935 03936 /* Start by disconnecting the original's physical side */ 03937 if (clone->tech->hangup) 03938 res = clone->tech->hangup(clone); 03939 if (res) { 03940 ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n"); 03941 ast_channel_unlock(clone); 03942 return -1; 03943 } 03944 03945 snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); 03946 /* Mangle the name of the clone channel */ 03947 ast_string_field_set(clone, name, zombn); 03948 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clone->uniqueid); 03949 03950 /* Update the type. */ 03951 t_pvt = original->monitor; 03952 original->monitor = clone->monitor; 03953 clone->monitor = t_pvt; 03954 03955 /* Keep the same language. */ 03956 ast_string_field_set(original, language, clone->language); 03957 /* Copy the FD's other than the generator fd */ 03958 for (x = 0; x < AST_MAX_FDS; x++) { 03959 if (x != AST_GENERATOR_FD) 03960 original->fds[x] = clone->fds[x]; 03961 } 03962 03963 ast_app_group_update(clone, original); 03964 /* Move data stores over */ 03965 if (AST_LIST_FIRST(&clone->datastores)) { 03966 struct ast_datastore *ds; 03967 /* We use a safe traversal here because some fixup routines actually 03968 * remove the datastore from the list and free them. 03969 */ 03970 AST_LIST_TRAVERSE_SAFE_BEGIN(&clone->datastores, ds, entry) { 03971 if (ds->info->chan_fixup) 03972 ds->info->chan_fixup(ds->data, clone, original); 03973 } 03974 AST_LIST_TRAVERSE_SAFE_END; 03975 AST_LIST_APPEND_LIST(&original->datastores, &clone->datastores, entry); 03976 } 03977 03978 clone_variables(original, clone); 03979 /* Presense of ADSI capable CPE follows clone */ 03980 original->adsicpe = clone->adsicpe; 03981 /* Bridge remains the same */ 03982 /* CDR fields remain the same */ 03983 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */ 03984 /* Application and data remain the same */ 03985 /* Clone exception becomes real one, as with fdno */ 03986 ast_set_flag(original, ast_test_flag(clone, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION)); 03987 original->fdno = clone->fdno; 03988 /* Schedule context remains the same */ 03989 /* Stream stuff stays the same */ 03990 /* Keep the original state. The fixup code will need to work with it most likely */ 03991 03992 /* Just swap the whole structures, nevermind the allocations, they'll work themselves 03993 out. */ 03994 tmpcid = original->cid; 03995 original->cid = clone->cid; 03996 clone->cid = tmpcid; 03997 report_new_callerid(original); 03998 03999 /* Restore original timing file descriptor */ 04000 original->fds[AST_TIMING_FD] = original->timingfd; 04001 04002 /* Our native formats are different now */ 04003 original->nativeformats = clone->nativeformats; 04004 04005 /* Context, extension, priority, app data, jump table, remain the same */ 04006 /* pvt switches. pbx stays the same, as does next */ 04007 04008 /* Set the write format */ 04009 ast_set_write_format(original, wformat); 04010 04011 /* Set the read format */ 04012 ast_set_read_format(original, rformat); 04013 04014 /* Copy the music class */ 04015 ast_string_field_set(original, musicclass, clone->musicclass); 04016 04017 /* Copy whentohangup time */ 04018 original->whentohangup = clone->whentohangup; 04019 04020 if (option_debug) 04021 ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat); 04022 04023 /* Okay. Last thing is to let the channel driver know about all this mess, so he 04024 can fix up everything as best as possible */ 04025 if (original->tech->fixup) { 04026 res = original->tech->fixup(clone, original); 04027 if (res) { 04028 ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n", 04029 original->tech->type, original->name); 04030 ast_channel_unlock(clone); 04031 return -1; 04032 } 04033 } else 04034 ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n", 04035 original->tech->type, original->name); 04036 04037 /* 04038 * If an indication is currently playing, maintain it on the channel 04039 * that is taking the place of original 04040 * 04041 * This is needed because the masquerade is swapping out in the internals 04042 * of this channel, and the new channel private data needs to be made 04043 * aware of the current visible indication (RINGING, CONGESTION, etc.) 04044 */ 04045 if (original->visible_indication) { 04046 ast_indicate(original, original->visible_indication); 04047 } 04048 04049 /* Now, at this point, the "clone" channel is totally F'd up. We mark it as 04050 a zombie so nothing tries to touch it. If it's already been marked as a 04051 zombie, then free it now (since it already is considered invalid). */ 04052 if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) { 04053 if (option_debug) 04054 ast_log(LOG_DEBUG, "Destroying channel clone '%s'\n", clone->name); 04055 ast_channel_unlock(clone); 04056 manager_event(EVENT_FLAG_CALL, "Hangup", 04057 "Channel: %s\r\n" 04058 "Uniqueid: %s\r\n" 04059 "Cause: %d\r\n" 04060 "Cause-txt: %s\r\n", 04061 clone->name, 04062 clone->uniqueid, 04063 clone->hangupcause, 04064 ast_cause2str(clone->hangupcause) 04065 ); 04066 ast_channel_free(clone); 04067 } else { 04068 if (option_debug) 04069 ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name); 04070 ast_set_flag(clone, AST_FLAG_ZOMBIE); 04071 ast_queue_frame(clone, &ast_null_frame); 04072 ast_channel_unlock(clone); 04073 } 04074 04075 /* Signal any blocker */ 04076 if (ast_test_flag(original, AST_FLAG_BLOCKING)) 04077 pthread_kill(original->blocker, SIGURG); 04078 if (option_debug) 04079 ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state); 04080 return 0; 04081 }
static int ast_fdisset | ( | struct pollfd * | pfds, | |
int | fd, | |||
int | max, | |||
int * | start | |||
) | [inline, static] |
Helper function for migrating select to poll.
Definition at line 1334 of file channel.h.
01335 { 01336 int x; 01337 int dummy=0; 01338 01339 if (fd < 0) 01340 return 0; 01341 if (!start) 01342 start = &dummy; 01343 for (x = *start; x<max; x++) 01344 if (pfds[x].fd == fd) { 01345 if (x == *start) 01346 (*start)++; 01347 return pfds[x].revents; 01348 } 01349 return 0; 01350 }
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.
Definition at line 1189 of file channel.c.
References channel_find_locked().
01190 { 01191 return channel_find_locked(NULL, NULL, 0, context, exten); 01192 }
struct ast_channel* ast_get_channel_by_name_locked | ( | const char * | chan | ) |
Get channel by name (locks channel).
Definition at line 1170 of file channel.c.
References channel_find_locked().
Referenced by action_atxfer(), action_getvar(), action_hangup(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), ast_bridge_call(), asyncgoto_exec(), change_monitor_action(), do_pause_or_unpause(), get_zap_channel_locked(), handle_channelstatus(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_getvariablefull(), handle_hangup(), handle_nodebugchan_deprecated(), handle_showchan(), handle_showchan_deprecated(), handle_softhangup(), manager_park(), manager_play_dtmf(), park_call_full(), pbx_builtin_importvar(), start_monitor_action(), and stop_monitor_action().
01171 { 01172 return channel_find_locked(NULL, name, 0, NULL, NULL); 01173 }
struct ast_channel* ast_get_channel_by_name_prefix_locked | ( | const char * | name, | |
const int | namelen | |||
) |
Get channel by name prefix (locks channel).
Definition at line 1176 of file channel.c.
References channel_find_locked().
Referenced by ast_parse_device_state(), common_exec(), and mixmonitor_cli().
01177 { 01178 return channel_find_locked(NULL, name, namelen, NULL, NULL); 01179 }
struct ast_channel_tech* ast_get_channel_tech | ( | const char * | name | ) |
Get a channel technology structure by name.
name | name of technology to find |
Definition at line 552 of file channel.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), chanlist::list, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.
Referenced by ast_device_state().
00553 { 00554 struct chanlist *chanls; 00555 const struct ast_channel_tech *ret = NULL; 00556 00557 if (AST_LIST_LOCK(&channels)) { 00558 ast_log(LOG_WARNING, "Unable to lock channel tech list\n"); 00559 return NULL; 00560 } 00561 00562 AST_LIST_TRAVERSE(&backends, chanls, list) { 00563 if (!strcasecmp(name, chanls->tech->type)) { 00564 ret = chanls->tech; 00565 break; 00566 } 00567 } 00568 00569 AST_LIST_UNLOCK(&channels); 00570 00571 return ret; 00572 }
ast_group_t ast_get_group | ( | const char * | s | ) |
Definition at line 4829 of file channel.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), group, and LOG_ERROR.
Referenced by _parse(), build_device(), build_gateway(), build_peer(), build_user(), func_channel_write(), process_dahdi(), and read_agent_config().
04830 { 04831 char *piece; 04832 char *c; 04833 int start=0, finish=0, x; 04834 ast_group_t group = 0; 04835 04836 if (ast_strlen_zero(s)) 04837 return 0; 04838 04839 c = ast_strdupa(s); 04840 04841 while ((piece = strsep(&c, ","))) { 04842 if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) { 04843 /* Range */ 04844 } else if (sscanf(piece, "%30d", &start)) { 04845 /* Just one */ 04846 finish = start; 04847 } else { 04848 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece); 04849 continue; 04850 } 04851 for (x = start; x <= finish; x++) { 04852 if ((x > 63) || (x < 0)) { 04853 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x); 04854 } else 04855 group |= ((ast_group_t) 1 << x); 04856 } 04857 } 04858 return group; 04859 }
int ast_hangup | ( | struct ast_channel * | chan | ) |
Hang up a channel.
chan | channel to hang up |
Definition at line 1493 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_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_IN_CHANNEL_LIST, AST_FLAG_ZOMBIE, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_log(), ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, ast_cdr::disposition, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_DEBUG, LOG_ERROR, manager_event(), ast_channel::masq, ast_channel::masqr, ast_channel::name, option_debug, ast_generator::release, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, ast_channel::uniqueid, and ast_channel::vstream.
Referenced by __ast_request_and_dial(), __oh323_new(), agent_hangup(), agent_read(), alsa_new(), answer_exec_run(), app_exec(), ast_async_goto(), ast_bridge_call_thread(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), ast_feature_request_and_dial(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial(), build_conf(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_run(), connect_link(), dahdi_handle_event(), dahdi_new(), do_atxfer(), do_hang(), do_idle_thread(), do_parking_thread(), features_hangup(), findmeexec(), gtalk_new(), 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(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), local_attended_transfer(), local_hangup(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), nbs_new(), oss_new(), park_exec(), parkandannounce_exec(), phone_new(), rpt(), rpt_call(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), wait_for_answer(), and wait_for_winner().
01494 { 01495 int res = 0; 01496 01497 /* Don't actually hang up a channel that will masquerade as someone else, or 01498 if someone is going to masquerade as us */ 01499 ast_channel_lock(chan); 01500 01501 if (chan->audiohooks) { 01502 ast_audiohook_detach_list(chan->audiohooks); 01503 chan->audiohooks = NULL; 01504 } 01505 01506 ast_autoservice_stop(chan); 01507 01508 if (chan->masq) { 01509 if (ast_do_masquerade(chan)) 01510 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 01511 } 01512 01513 if (chan->masq) { 01514 ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name); 01515 ast_channel_unlock(chan); 01516 return 0; 01517 } 01518 /* If this channel is one which will be masqueraded into something, 01519 mark it as a zombie already, so we know to free it later */ 01520 if (chan->masqr) { 01521 ast_set_flag(chan, AST_FLAG_ZOMBIE); 01522 ast_channel_unlock(chan); 01523 return 0; 01524 } 01525 ast_channel_unlock(chan); 01526 01527 AST_LIST_LOCK(&channels); 01528 if (!AST_LIST_REMOVE(&channels, chan, chan_list)) { 01529 ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01530 } 01531 ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01532 AST_LIST_UNLOCK(&channels); 01533 01534 ast_channel_lock(chan); 01535 free_translation(chan); 01536 /* Close audio stream */ 01537 if (chan->stream) { 01538 ast_closestream(chan->stream); 01539 chan->stream = NULL; 01540 } 01541 /* Close video stream */ 01542 if (chan->vstream) { 01543 ast_closestream(chan->vstream); 01544 chan->vstream = NULL; 01545 } 01546 if (chan->sched) { 01547 sched_context_destroy(chan->sched); 01548 chan->sched = NULL; 01549 } 01550 01551 if (chan->generatordata) /* Clear any tone stuff remaining */ 01552 chan->generator->release(chan, chan->generatordata); 01553 chan->generatordata = NULL; 01554 chan->generator = NULL; 01555 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01556 ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " 01557 "is blocked by thread %ld in procedure %s! Expect a failure\n", 01558 (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); 01559 ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0); 01560 } 01561 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { 01562 if (option_debug) 01563 ast_log(LOG_DEBUG, "Hanging up channel '%s'\n", chan->name); 01564 if (chan->tech->hangup) 01565 res = chan->tech->hangup(chan); 01566 } else { 01567 if (option_debug) 01568 ast_log(LOG_DEBUG, "Hanging up zombie '%s'\n", chan->name); 01569 } 01570 01571 ast_channel_unlock(chan); 01572 manager_event(EVENT_FLAG_CALL, "Hangup", 01573 "Channel: %s\r\n" 01574 "Uniqueid: %s\r\n" 01575 "Cause: %d\r\n" 01576 "Cause-txt: %s\r\n", 01577 chan->name, 01578 chan->uniqueid, 01579 chan->hangupcause, 01580 ast_cause2str(chan->hangupcause) 01581 ); 01582 01583 if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 01584 !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 01585 (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) { 01586 ast_channel_lock(chan); 01587 01588 ast_cdr_end(chan->cdr); 01589 ast_cdr_detach(chan->cdr); 01590 chan->cdr = NULL; 01591 ast_channel_unlock(chan); 01592 } 01593 01594 ast_channel_free(chan); 01595 01596 return res; 01597 }
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 2537 of file channel.c.
References ast_indicate_data().
Referenced by __ast_play_and_record(), agent_new(), answer_trunk_chan(), ast_answer(), ast_bridge_call(), ast_channel_bridge(), ast_do_masquerade(), ast_dtmf_stream(), ast_feature_request_and_dial(), attempt_transfer(), builtin_blindtransfer(), conf_run(), disa_exec(), do_atxfer(), do_parking_thread(), features_indicate(), finishup(), function_remote(), handle_frame(), handle_recordfile(), mgcp_ss(), monitor_dial(), park_exec(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), rpt(), send_waveform_to_channel(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), and wait_for_answer().
02538 { 02539 return ast_indicate_data(chan, condition, NULL, 0); 02540 }
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 2575 of file channel.c.
References ast_channel::_state, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, 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_SRCUPDATE, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STATE_UP, ast_test_flag, tone_zone_sound::data, ast_channel_tech::indicate, is_visible_indication(), LOG_DEBUG, ast_channel::name, option_debug, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.
Referenced by __login_exec(), agent_hangup(), ast_bridge_call(), ast_indicate(), bridge_native_loop(), do_parking_thread(), park_call_full(), pbx_builtin_waitexten(), and wait_for_answer().
02577 { 02578 /* By using an enum, we'll get compiler warnings for values not handled 02579 * in switch statements. */ 02580 enum ast_control_frame_type condition = _condition; 02581 const struct tone_zone_sound *ts = NULL; 02582 int res = -1; 02583 02584 ast_channel_lock(chan); 02585 02586 /* Don't bother if the channel is about to go away, anyway. */ 02587 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 02588 ast_channel_unlock(chan); 02589 return -1; 02590 } 02591 02592 if (chan->tech->indicate) { 02593 /* See if the channel driver can handle this condition. */ 02594 res = chan->tech->indicate(chan, condition, data, datalen); 02595 } 02596 02597 ast_channel_unlock(chan); 02598 02599 if (chan->tech->indicate && !res) { 02600 /* The channel driver successfully handled this indication */ 02601 if (is_visible_indication(condition)) { 02602 chan->visible_indication = condition; 02603 } 02604 return 0; 02605 } 02606 02607 /* The channel driver does not support this indication, let's fake 02608 * it by doing our own tone generation if applicable. */ 02609 02610 /*!\note If we compare the enumeration type, which does not have any 02611 * negative constants, the compiler may optimize this code away. 02612 * Therefore, we must perform an integer comparison here. */ 02613 if (_condition < 0) { 02614 /* Stop any tones that are playing */ 02615 ast_playtones_stop(chan); 02616 return 0; 02617 } 02618 02619 /* Handle conditions that we have tones for. */ 02620 switch (condition) { 02621 case AST_CONTROL_RINGING: 02622 ts = ast_get_indication_tone(chan->zone, "ring"); 02623 /* It is common practice for channel drivers to return -1 if trying 02624 * to indicate ringing on a channel which is up. The idea is to let the 02625 * core generate the ringing inband. However, we don't want the 02626 * warning message about not being able to handle the specific indication 02627 * to print nor do we want ast_indicate_data to return an "error" for this 02628 * condition 02629 */ 02630 if (chan->_state == AST_STATE_UP) { 02631 res = 0; 02632 } 02633 break; 02634 case AST_CONTROL_BUSY: 02635 ts = ast_get_indication_tone(chan->zone, "busy"); 02636 break; 02637 case AST_CONTROL_CONGESTION: 02638 ts = ast_get_indication_tone(chan->zone, "congestion"); 02639 break; 02640 case AST_CONTROL_PROGRESS: 02641 case AST_CONTROL_PROCEEDING: 02642 case AST_CONTROL_VIDUPDATE: 02643 case AST_CONTROL_SRCUPDATE: 02644 case AST_CONTROL_RADIO_KEY: 02645 case AST_CONTROL_RADIO_UNKEY: 02646 case AST_CONTROL_OPTION: 02647 case AST_CONTROL_WINK: 02648 case AST_CONTROL_FLASH: 02649 case AST_CONTROL_OFFHOOK: 02650 case AST_CONTROL_TAKEOFFHOOK: 02651 case AST_CONTROL_ANSWER: 02652 case AST_CONTROL_HANGUP: 02653 case AST_CONTROL_RING: 02654 case AST_CONTROL_HOLD: 02655 case AST_CONTROL_UNHOLD: 02656 /* Nothing left to do for these. */ 02657 res = 0; 02658 break; 02659 } 02660 02661 if (ts && ts->data[0]) { 02662 /* We have a tone to play, yay. */ 02663 if (option_debug) { 02664 ast_log(LOG_DEBUG, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition); 02665 } 02666 ast_playtones_start(chan, 0, ts->data, 1); 02667 res = 0; 02668 chan->visible_indication = condition; 02669 } 02670 02671 if (res) { 02672 /* not handled */ 02673 ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name); 02674 } 02675 02676 return res; 02677 }
int ast_internal_timing_enabled | ( | struct ast_channel * | chan | ) |
Check if the channel can run in internal timing mode.
chan | The channel to check |
Definition at line 2519 of file channel.c.
References ast_log(), ast_opt_internal_timing, LOG_DEBUG, option_debug, and ast_channel::timingfd.
Referenced by add_sdp(), and ast_read_generator_actions().
02520 { 02521 int ret = ast_opt_internal_timing && chan->timingfd > -1; 02522 if (option_debug > 4) 02523 ast_log(LOG_DEBUG, "Internal timing is %s (option_internal_timing=%d chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_internal_timing, chan->timingfd); 02524 return ret; 02525 }
char* ast_print_group | ( | char * | buf, | |
int | buflen, | |||
ast_group_t | group | |||
) |
print call- and pickup groups into buffer
Definition at line 4914 of file channel.c.
References first.
Referenced by _sip_show_peer(), func_channel_read(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().
04915 { 04916 unsigned int i; 04917 int first=1; 04918 char num[3]; 04919 04920 buf[0] = '\0'; 04921 04922 if (!group) /* Return empty string if no group */ 04923 return buf; 04924 04925 for (i = 0; i <= 63; i++) { /* Max group is 63 */ 04926 if (group & ((ast_group_t) 1 << i)) { 04927 if (!first) { 04928 strncat(buf, ", ", buflen - strlen(buf) - 1); 04929 } else { 04930 first=0; 04931 } 04932 snprintf(num, sizeof(num), "%u", i); 04933 strncat(buf, num, buflen - strlen(buf) - 1); 04934 } 04935 } 04936 return buf; 04937 }
int ast_prod | ( | struct ast_channel * | chan | ) |
Send empty audio to prime a channel driver.
Definition at line 2799 of file channel.c.
References ast_channel::_state, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), ast_frame::data, LOG_DEBUG, ast_channel::name, option_debug, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.
Referenced by ast_activate_generator().
02800 { 02801 struct ast_frame a = { AST_FRAME_VOICE }; 02802 char nothing[128]; 02803 02804 /* Send an empty audio frame to get things moving */ 02805 if (chan->_state != AST_STATE_UP) { 02806 if (option_debug) 02807 ast_log(LOG_DEBUG, "Prodding channel '%s'\n", chan->name); 02808 a.subclass = chan->rawwriteformat; 02809 a.data = nothing + AST_FRIENDLY_OFFSET; 02810 a.src = "ast_prod"; 02811 if (ast_write(chan, &a)) 02812 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name); 02813 } 02814 return 0; 02815 }
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 |
Definition at line 1013 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and f.
Referenced by __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(), mgcp_call(), misdn_attempt_transfer(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_unhold(), ss_thread(), and update_state().
01014 { 01015 struct ast_frame f = { AST_FRAME_CONTROL, }; 01016 01017 f.subclass = control; 01018 01019 return ast_queue_frame(chan, &f); 01020 }
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 |
Definition at line 1023 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and f.
Referenced by action_atxfer(), dahdi_handle_event(), dahdi_hangup(), iax2_queue_control_data(), process_sdp(), and skinny_hold().
01025 { 01026 struct ast_frame f = { AST_FRAME_CONTROL, }; 01027 01028 f.subclass = control; 01029 f.data = (void *) data; 01030 f.datalen = datalen; 01031 01032 return ast_queue_frame(chan, &f); 01033 }
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 990 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup(), ast_do_masquerade(), ast_dsp_process(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_softhangup_nolock(), cb_events(), console_answer(), console_answer_deprecated(), console_dial(), console_dial_deprecated(), console_flash(), console_flash_deprecated(), console_sendtext(), console_sendtext_deprecated(), dahdi_queue_frame(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), and wakeup_sub().
00991 { 00992 return __ast_queue_frame(chan, fin, 0, NULL); 00993 }
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 995 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_read(), and ast_autoservice_stop().
00996 { 00997 return __ast_queue_frame(chan, fin, 1, NULL); 00998 }
int ast_queue_hangup | ( | struct ast_channel * | chan | ) |
Queue a hangup frame.
Definition at line 1001 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, and f.
Referenced by __oh323_update_info(), __sip_autodestruct(), cleanup_connection(), console_hangup(), console_hangup_deprecated(), dahdi_handle_event(), dahdi_r2_on_call_disconnect(), gtalk_hangup_farend(), gtalk_is_answered(), handle_onhook_message(), handle_request_bye(), handle_request_cancel(), handle_response(), handle_response_invite(), handle_soft_key_event_message(), hangup_chan(), hangup_connection(), iax2_destroy(), iax2_queue_hangup(), local_hangup(), mgcp_queue_hangup(), misdn_answer(), pri_hangup_all(), and retrans_pkt().
01002 { 01003 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01004 /* Yeah, let's not change a lock-critical value without locking */ 01005 if (!ast_channel_trylock(chan)) { 01006 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01007 ast_channel_unlock(chan); 01008 } 01009 return ast_queue_frame(chan, &f); 01010 }
struct ast_frame* ast_read | ( | struct ast_channel * | chan | ) |
Reads a frame.
chan | channel to read a frame from Read a frame. |
Definition at line 2527 of file channel.c.
References __ast_read().
Referenced by __adsi_transmit_messages(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), app_exec(), ast_feature_request_and_dial(), 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(), dictate_exec(), disa_exec(), do_atxfer(), do_idle_thread(), do_parking_thread(), do_waiting(), echo_exec(), features_read(), find_cache(), handle_recordfile(), iax_park_thread(), ices_exec(), isAnsweringMachine(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), recordthread(), rpt(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().
02528 { 02529 return __ast_read(chan, 0); 02530 }
struct ast_frame* ast_read_noaudio | ( | struct ast_channel * | chan | ) |
Reads a frame, returning AST_FRAME_NULL frame if audio. Read a frame.
chan | channel to read a frame from |
Definition at line 2532 of file channel.c.
References __ast_read().
Referenced by conf_run().
02533 { 02534 return __ast_read(chan, 1); 02535 }
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 3493 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().
03494 { 03495 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1); 03496 }
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 3498 of file channel.c.
References ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), ast_waitstream_full(), and ast_channel::stream.
Referenced by ast_app_getdata_full(), and ast_readstring().
03499 { 03500 int pos = 0; /* index in the buffer where we accumulate digits */ 03501 int to = ftimeout; 03502 03503 /* Stop if we're a zombie or need a soft hangup */ 03504 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 03505 return -1; 03506 if (!len) 03507 return -1; 03508 for (;;) { 03509 int d; 03510 if (c->stream) { 03511 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); 03512 ast_stopstream(c); 03513 usleep(1000); 03514 if (!d) 03515 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 03516 } else { 03517 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 03518 } 03519 if (d < 0) 03520 return -1; 03521 if (d == 0) { 03522 s[pos]='\0'; 03523 return 1; 03524 } 03525 if (d == 1) { 03526 s[pos]='\0'; 03527 return 2; 03528 } 03529 if (!strchr(enders, d)) 03530 s[pos++] = d; 03531 if (strchr(enders, d) || (pos >= len)) { 03532 s[pos]='\0'; 03533 return 0; 03534 } 03535 to = timeout; 03536 } 03537 /* Never reached */ 03538 return 0; 03539 }
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 2679 of file channel.c.
References ast_recvtext(), and free.
Referenced by handle_recvchar().
02680 { 02681 int c; 02682 char *buf = ast_recvtext(chan, timeout); 02683 if (buf == NULL) 02684 return -1; /* error or timeout */ 02685 c = *(unsigned char *)buf; 02686 free(buf); 02687 return c; 02688 }
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 2690 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(), and f.
Referenced by ast_recvchar(), and handle_recvtext().
02691 { 02692 int res, done = 0; 02693 char *buf = NULL; 02694 02695 while (!done) { 02696 struct ast_frame *f; 02697 if (ast_check_hangup(chan)) 02698 break; 02699 res = ast_waitfor(chan, timeout); 02700 if (res <= 0) /* timeout or error */ 02701 break; 02702 timeout = res; /* update timeout */ 02703 f = ast_read(chan); 02704 if (f == NULL) 02705 break; /* no frame */ 02706 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) 02707 done = 1; /* force a break */ 02708 else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ 02709 buf = ast_strndup((char *) f->data, f->datalen); /* dup and break */ 02710 done = 1; 02711 } 02712 ast_frfree(f); 02713 } 02714 return buf; 02715 }
struct ast_channel* ast_request | ( | const char * | type, | |
int | format, | |||
void * | data, | |||
int * | status | |||
) |
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 |
Definition at line 3399 of file channel.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_translator_best_choice(), ast_channel_tech::capabilities, capabilities, ast_channel_tech::requester, chanlist::tech, and ast_channel_tech::type.
Referenced by __ast_request_and_dial(), agent_request(), ast_call_forward(), ast_feature_request_and_dial(), attempt_reconnect(), begin_dial(), build_conf(), chanavail_exec(), conf_run(), connect_link(), features_alloc(), findmeexec(), ring_entry(), rpt(), rpt_call(), rpt_tele_thread(), and wait_for_answer().
03400 { 03401 struct chanlist *chan; 03402 struct ast_channel *c; 03403 int capabilities; 03404 int fmt; 03405 int res; 03406 int foo; 03407 int videoformat = format & AST_FORMAT_VIDEO_MASK; 03408 03409 if (!cause) 03410 cause = &foo; 03411 *cause = AST_CAUSE_NOTDEFINED; 03412 03413 if (AST_LIST_LOCK(&channels)) { 03414 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 03415 return NULL; 03416 } 03417 03418 AST_LIST_TRAVERSE(&backends, chan, list) { 03419 if (strcasecmp(type, chan->tech->type)) 03420 continue; 03421 03422 capabilities = chan->tech->capabilities; 03423 fmt = format & AST_FORMAT_AUDIO_MASK; 03424 res = ast_translator_best_choice(&fmt, &capabilities); 03425 if (res < 0) { 03426 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format); 03427 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 03428 AST_LIST_UNLOCK(&channels); 03429 return NULL; 03430 } 03431 AST_LIST_UNLOCK(&channels); 03432 if (!chan->tech->requester) 03433 return NULL; 03434 03435 if (!(c = chan->tech->requester(type, capabilities | videoformat, data, cause))) 03436 return NULL; 03437 03438 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */ 03439 return c; 03440 } 03441 03442 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type); 03443 *cause = AST_CAUSE_NOSUCHDRIVER; 03444 AST_LIST_UNLOCK(&channels); 03445 03446 return NULL; 03447 }
struct ast_channel* ast_request_and_dial | ( | const char * | type, | |
int | format, | |||
void * | data, | |||
int | timeout, | |||
int * | reason, | |||
const char * | cidnum, | |||
const char * | cidname | |||
) |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.
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 unsuceessful) | |
cidnum | Caller-ID Number | |
cidname | Caller-ID Name |
Definition at line 3394 of file channel.c.
References __ast_request_and_dial().
Referenced by ast_pbx_outgoing_exten().
03395 { 03396 return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL); 03397 }
int ast_safe_sleep | ( | struct ast_channel * | chan, | |
int | ms | |||
) |
Wait for a specied 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 1223 of file channel.c.
References ast_safe_sleep_conditional().
Referenced by __login_exec(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_dtmf_stream(), ast_senddigit(), builtin_parkcall(), conf_run(), dictate_exec(), flash_exec(), function_ilink(), mgcp_ss(), milliwatt_exec(), moh0_exec(), moh1_exec(), old_milliwatt_exec(), park_call_exec(), pbx_builtin_answer(), pbx_builtin_wait(), 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(), wait_for_hangup(), wait_interval(), and zapateller_exec().
01224 { 01225 return ast_safe_sleep_conditional(chan, ms, NULL, NULL); 01226 }
int ast_safe_sleep_conditional | ( | struct ast_channel * | chan, | |
int | ms, | |||
int(*)(void *) | cond, | |||
void * | data | |||
) |
Wait for a specied 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 1202 of file channel.c.
References ast_frfree, ast_read(), ast_waitfor(), and f.
Referenced by __login_exec(), and ast_safe_sleep().
01203 { 01204 struct ast_frame *f; 01205 01206 while (ms > 0) { 01207 if (cond && ((*cond)(data) == 0)) 01208 return 0; 01209 ms = ast_waitfor(chan, ms); 01210 if (ms < 0) 01211 return -1; 01212 if (ms > 0) { 01213 f = ast_read(chan); 01214 if (!f) 01215 return -1; 01216 ast_frfree(f); 01217 } 01218 } 01219 return 0; 01220 }
char* ast_safe_string_alloc | ( | const char * | fmt, | |
... | ||||
) |
printf the string into a correctly sized mallocd buffer, and return the buffer
return a mallocd string with the result of sprintf of the fmt and following args
Definition at line 409 of file channel.c.
References ast_malloc, and len().
Referenced by dahdi_new(), and features_new().
00410 { 00411 char *b2, buf[1]; 00412 int len; 00413 va_list args; 00414 00415 va_start(args, fmt); 00416 len = vsnprintf(buf, 1, fmt, args); 00417 va_end(args); 00418 00419 if (!(b2 = ast_malloc(len + 1))) 00420 return NULL; 00421 00422 va_start(args, fmt); 00423 vsnprintf(b2, len + 1, fmt, args); 00424 va_end(args); 00425 00426 return b2; 00427 }
static int ast_select | ( | int | nfds, | |
fd_set * | rfds, | |||
fd_set * | wfds, | |||
fd_set * | efds, | |||
struct timeval * | tvp | |||
) | [inline, static] |
Waits for activity on a group of channels.
nfds | the maximum number of file descriptors in the sets | |
rfds | file descriptors to check for read availability | |
wfds | file descriptors to check for write availability | |
efds | file descriptors to check for exceptions (OOB data) | |
tvp | timeout while waiting for events This is the same as a standard select(), except it guarantees the behaviour where the passed struct timeval is updated with how much time was not slept while waiting for the specified events |
Definition at line 1375 of file channel.h.
Referenced by do_monitor(), do_parking_thread(), and sound_thread().
01376 { 01377 #ifdef __linux__ 01378 return select(nfds, rfds, wfds, efds, tvp); 01379 #else 01380 if (tvp) { 01381 struct timeval tv, tvstart, tvend, tvlen; 01382 int res; 01383 01384 tv = *tvp; 01385 gettimeofday(&tvstart, NULL); 01386 res = select(nfds, rfds, wfds, efds, tvp); 01387 gettimeofday(&tvend, NULL); 01388 timersub(&tvend, &tvstart, &tvlen); 01389 timersub(&tv, &tvlen, tvp); 01390 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) { 01391 tvp->tv_sec = 0; 01392 tvp->tv_usec = 0; 01393 } 01394 return res; 01395 } 01396 else 01397 return select(nfds, rfds, wfds, efds, NULL); 01398 #endif 01399 }
int ast_senddigit | ( | 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 2789 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(), do_dtmf_phone(), manager_play_dtmf(), and rpt_call().
02790 { 02791 if (chan->tech->send_digit_begin) { 02792 ast_senddigit_begin(chan, digit); 02793 ast_safe_sleep(chan, AST_DEFAULT_EMULATE_DTMF_DURATION); 02794 } 02795 02796 return ast_senddigit_end(chan, digit, AST_DEFAULT_EMULATE_DTMF_DURATION); 02797 }
int ast_senddigit_begin | ( | struct ast_channel * | chan, | |
char | digit | |||
) |
Definition at line 2730 of file channel.c.
References ast_log(), ast_playtones_start(), LOG_DEBUG, ast_channel::name, option_debug, ast_channel_tech::send_digit_begin, and ast_channel::tech.
Referenced by agent_digit_begin(), ast_senddigit(), ast_write(), and features_digit_begin().
02731 { 02732 /* Device does not support DTMF tones, lets fake 02733 * it by doing our own generation. */ 02734 static const char* dtmf_tones[] = { 02735 "941+1336", /* 0 */ 02736 "697+1209", /* 1 */ 02737 "697+1336", /* 2 */ 02738 "697+1477", /* 3 */ 02739 "770+1209", /* 4 */ 02740 "770+1336", /* 5 */ 02741 "770+1477", /* 6 */ 02742 "852+1209", /* 7 */ 02743 "852+1336", /* 8 */ 02744 "852+1477", /* 9 */ 02745 "697+1633", /* A */ 02746 "770+1633", /* B */ 02747 "852+1633", /* C */ 02748 "941+1633", /* D */ 02749 "941+1209", /* * */ 02750 "941+1477" /* # */ 02751 }; 02752 02753 if (!chan->tech->send_digit_begin) 02754 return 0; 02755 02756 if (!chan->tech->send_digit_begin(chan, digit)) 02757 return 0; 02758 02759 if (digit >= '0' && digit <='9') 02760 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0); 02761 else if (digit >= 'A' && digit <= 'D') 02762 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0); 02763 else if (digit == '*') 02764 ast_playtones_start(chan, 0, dtmf_tones[14], 0); 02765 else if (digit == '#') 02766 ast_playtones_start(chan, 0, dtmf_tones[15], 0); 02767 else { 02768 /* not handled */ 02769 if (option_debug) 02770 ast_log(LOG_DEBUG, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name); 02771 } 02772 02773 return 0; 02774 }
int ast_senddigit_end | ( | struct ast_channel * | chan, | |
char | digit, | |||
unsigned int | duration | |||
) |
Definition at line 2776 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(), ast_write(), and features_digit_end().
02777 { 02778 int res = -1; 02779 02780 if (chan->tech->send_digit_end) 02781 res = chan->tech->send_digit_end(chan, digit, duration); 02782 02783 if (res && chan->generator) 02784 ast_playtones_stop(chan); 02785 02786 return 0; 02787 }
int ast_sendtext | ( | struct ast_channel * | chan, | |
const char * | text | |||
) |
Sends text to a channel Write text to a display on a channel.
chan | channel to act upon | |
text | string of text to send on the channel |
Definition at line 2717 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_test_flag, CHECK_BLOCKING, ast_channel_tech::send_text, and ast_channel::tech.
Referenced by agent_sendtext(), handle_sendtext(), and sendtext_exec().
02718 { 02719 int res = 0; 02720 /* Stop if we're a zombie or need a soft hangup */ 02721 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 02722 return -1; 02723 CHECK_BLOCKING(chan); 02724 if (chan->tech->send_text) 02725 res = chan->tech->send_text(chan, text); 02726 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02727 return res; 02728 }
void ast_set_callerid | ( | struct ast_channel * | chan, | |
const char * | cidnum, | |||
const char * | cidname, | |||
const char * | ani | |||
) |
Definition at line 4083 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_strdup, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, free, and report_new_callerid().
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), callerid_write(), dahdi_read(), disa_exec(), findmeexec(), handle_setcallerid(), lookupcidname_exec(), mgcp_ss(), privacy_exec(), read_config(), setcallerid_exec(), skinny_newcall(), ss_thread(), and wait_for_answer().
04084 { 04085 ast_channel_lock(chan); 04086 04087 if (callerid) { 04088 if (chan->cid.cid_num) 04089 free(chan->cid.cid_num); 04090 chan->cid.cid_num = ast_strdup(callerid); 04091 } 04092 if (calleridname) { 04093 if (chan->cid.cid_name) 04094 free(chan->cid.cid_name); 04095 chan->cid.cid_name = ast_strdup(calleridname); 04096 } 04097 if (ani) { 04098 if (chan->cid.cid_ani) 04099 free(chan->cid.cid_ani); 04100 chan->cid.cid_ani = ast_strdup(ani); 04101 } 04102 04103 report_new_callerid(chan); 04104 04105 ast_channel_unlock(chan); 04106 }
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 3140 of file channel.c.
References ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().
Referenced by __ast_play_and_record(), __login_exec(), __oh323_update_info(), agent_call(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_channel_make_compatible(), ast_do_masquerade(), attempt_reconnect(), background_detect_exec(), build_conf(), conf_run(), connect_link(), dictate_exec(), disa_exec(), do_waiting(), eagi_exec(), echo_exec(), gtalk_rtp_read(), handle_recordfile(), ices_exec(), isAnsweringMachine(), measurenoise(), mgcp_rtp_read(), oh323_rtp_read(), old_milliwatt_exec(), process_sdp(), rpt(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), and update_features().
03141 { 03142 return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat, 03143 &chan->readtrans, 0); 03144 }
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 |
Definition at line 4939 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().
04940 { 04941 struct ast_variable *cur; 04942 04943 for (cur = vars; cur; cur = cur->next) 04944 pbx_builtin_setvar_helper(chan, cur->name, cur->value); 04945 }
int ast_set_write_format | ( | struct ast_channel * | chan, | |
int | format | |||
) |
Sets write format on channel chan Set write format for channel to whichever compoent of "format" is best.
chan | channel to change | |
format | new format for writing |
Definition at line 3146 of file channel.c.
References ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.
Referenced by __login_exec(), __oh323_update_info(), agent_call(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_channel_make_compatible(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_do_masquerade(), ast_openstream_full(), ast_stopstream(), attempt_reconnect(), build_conf(), chanspy_exec(), conf_run(), connect_link(), disa_exec(), echo_exec(), extenspy_exec(), gtalk_rtp_read(), linear_alloc(), linear_release(), 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(), send_waveform_to_channel(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), tonepair_alloc(), tonepair_release(), and update_features().
03147 { 03148 return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat, 03149 &chan->writetrans, 1); 03150 }
int ast_setstate | ( | struct ast_channel * | chan, | |
enum | ast_channel_state | |||
) |
Change the state of a channel.
Definition at line 4108 of file channel.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_copy_string(), ast_device_state_changed_literal(), ast_state2str(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, 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_answer(), cb_events(), check_availability(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), 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(), 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(), and update_state().
04109 { 04110 char name[AST_CHANNEL_NAME], *dashptr; 04111 int oldstate = chan->_state; 04112 04113 if (oldstate == state) 04114 return 0; 04115 04116 ast_copy_string(name, chan->name, sizeof(name)); 04117 if ((dashptr = strrchr(name, '-'))) { 04118 *dashptr = '\0'; 04119 } 04120 04121 chan->_state = state; 04122 ast_device_state_changed_literal(name); 04123 /* setstate used to conditionally report Newchannel; this is no more */ 04124 manager_event(EVENT_FLAG_CALL, 04125 "Newstate", 04126 "Channel: %s\r\n" 04127 "State: %s\r\n" 04128 "CallerID: %s\r\n" 04129 "CallerIDName: %s\r\n" 04130 "Uniqueid: %s\r\n", 04131 chan->name, ast_state2str(chan->_state), 04132 S_OR(chan->cid.cid_num, "<unknown>"), 04133 S_OR(chan->cid.cid_name, "<unknown>"), 04134 chan->uniqueid); 04135 04136 return 0; 04137 }
int ast_settimeout | ( | struct ast_channel * | c, | |
int | samples, | |||
int(*)(const void *data) | func, | |||
void * | data | |||
) |
Definition at line 1883 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_log(), LOG_DEBUG, option_debug, 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().
01884 { 01885 int res = -1; 01886 #ifdef HAVE_DAHDI 01887 ast_channel_lock(c); 01888 if (c->timingfd > -1) { 01889 if (!func) { 01890 samples = 0; 01891 data = 0; 01892 } 01893 if (option_debug) 01894 ast_log(LOG_DEBUG, "Scheduling timer at %d sample intervals\n", samples); 01895 res = ioctl(c->timingfd, DAHDI_TIMERCONFIG, &samples); 01896 c->timingfunc = func; 01897 c->timingdata = data; 01898 } 01899 ast_channel_unlock(c); 01900 #endif 01901 return res; 01902 }
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 461 of file channel.c.
Referenced by handle_request_options().
00462 { 00463 return shutting_down; 00464 }
int ast_softhangup | ( | struct ast_channel * | chan, | |
int | cause | |||
) |
Softly hangup up a channel.
chan | channel to be soft-hung-up 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. | |
reason | an AST_SOFTHANGUP_* reason code |
Definition at line 1471 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().
Referenced by __ast_module_user_hangup_all(), __login_exec(), __unload_module(), action_hangup(), agent_hangup(), agent_logoff(), ast_begin_shutdown(), ast_dial_join(), conf_free(), connect_link(), dahdi_handle_event(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), manager_park(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().
01472 { 01473 int res; 01474 ast_channel_lock(chan); 01475 res = ast_softhangup_nolock(chan, cause); 01476 ast_channel_unlock(chan); 01477 return res; 01478 }
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 1457 of file channel.c.
References ast_channel::_softhangup, AST_FLAG_BLOCKING, ast_log(), ast_null_frame, ast_queue_frame(), ast_test_flag, ast_channel::blocker, LOG_DEBUG, ast_channel::name, and option_debug.
Referenced by ast_async_goto(), ast_softhangup(), attempt_transfer(), dahdi_softhangup_all(), do_monitor(), oh323_indicate(), sip_indicate(), and skinny_indicate().
01458 { 01459 if (option_debug) 01460 ast_log(LOG_DEBUG, "Soft-Hanging up channel '%s'\n", chan->name); 01461 /* Inform channel driver that we need to be hung up, if it cares */ 01462 chan->_softhangup |= cause; 01463 ast_queue_frame(chan, &ast_null_frame); 01464 /* Interrupt any poll call or such */ 01465 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) 01466 pthread_kill(chan->blocker, SIGURG); 01467 return 0; 01468 }
char* ast_state2str | ( | enum | ast_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 600 of file channel.c.
References AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DIALING_OFFHOOK, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_threadstorage_get(), STATE2STR_BUFSIZE, and state2str_threadbuf.
Referenced by action_status(), agent_hangup(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_chanlist_deprecated(), handle_invite_replaces(), handle_showchan(), handle_showchan_deprecated(), local_attended_transfer(), mgcp_new(), serialize_showchan(), and sip_hangup().
00601 { 00602 char *buf; 00603 00604 switch(state) { 00605 case AST_STATE_DOWN: 00606 return "Down"; 00607 case AST_STATE_RESERVED: 00608 return "Rsrvd"; 00609 case AST_STATE_OFFHOOK: 00610 return "OffHook"; 00611 case AST_STATE_DIALING: 00612 return "Dialing"; 00613 case AST_STATE_RING: 00614 return "Ring"; 00615 case AST_STATE_RINGING: 00616 return "Ringing"; 00617 case AST_STATE_UP: 00618 return "Up"; 00619 case AST_STATE_BUSY: 00620 return "Busy"; 00621 case AST_STATE_DIALING_OFFHOOK: 00622 return "Dialing Offhook"; 00623 case AST_STATE_PRERING: 00624 return "Pre-ring"; 00625 default: 00626 if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE))) 00627 return "Unknown"; 00628 snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state); 00629 return buf; 00630 } 00631 }
int ast_str2cause | ( | const char * | name | ) |
Convert a symbolic hangup cause to number.
name | string form of the cause Returns the cause code |
Definition at line 588 of file channel.c.
References causes.
Referenced by pbx_builtin_hangup().
00589 { 00590 int x; 00591 00592 for (x = 0; x < sizeof(causes) / sizeof(causes[0]); x++) 00593 if (strncasecmp(causes[x].name, name, strlen(causes[x].name)) == 0) 00594 return causes[x].cause; 00595 00596 return -1; 00597 }
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 4811 of file channel.c.
References ast_frfree, ast_read(), ast_tonepair_start(), ast_waitfor(), f, and ast_channel::generatordata.
Referenced by zapateller_exec().
04812 { 04813 int res; 04814 04815 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol))) 04816 return res; 04817 04818 /* Give us some wiggle room */ 04819 while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { 04820 struct ast_frame *f = ast_read(chan); 04821 if (f) 04822 ast_frfree(f); 04823 else 04824 return -1; 04825 } 04826 return 0; 04827 }
int ast_tonepair_start | ( | struct ast_channel * | chan, | |
int | freq1, | |||
int | freq2, | |||
int | duration, | |||
int | vol | |||
) |
Start a tone going
Definition at line 4793 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(), play_dialtone(), play_tone_pair(), rpt_tele_thread(), and sendnoise().
04794 { 04795 struct tonepair_def d = { 0, }; 04796 04797 d.freq1 = freq1; 04798 d.freq2 = freq2; 04799 d.duration = duration; 04800 d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */ 04801 if (ast_activate_generator(chan, &tonepair, &d)) 04802 return -1; 04803 return 0; 04804 }
void ast_tonepair_stop | ( | struct ast_channel * | chan | ) |
Stop a tone from playing
Definition at line 4806 of file channel.c.
References ast_deactivate_generator().
Referenced by sendnoise().
04807 { 04808 ast_deactivate_generator(chan); 04809 }
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.
Called by:
Definition at line 3475 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().
03476 { 03477 int res = -1; 03478 03479 /* Stop if we're a zombie or need a soft hangup */ 03480 ast_channel_lock(chan); 03481 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 03482 if (chan->tech->transfer) { 03483 res = chan->tech->transfer(chan, dest); 03484 if (!res) 03485 res = 1; 03486 } else 03487 res = 0; 03488 } 03489 ast_channel_unlock(chan); 03490 return res; 03491 }
char* ast_transfercapability2str | ( | int | transfercapability | ) | const |
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 capbility |
Definition at line 634 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().
00635 { 00636 switch(transfercapability) { 00637 case AST_TRANS_CAP_SPEECH: 00638 return "SPEECH"; 00639 case AST_TRANS_CAP_DIGITAL: 00640 return "DIGITAL"; 00641 case AST_TRANS_CAP_RESTRICTED_DIGITAL: 00642 return "RESTRICTED_DIGITAL"; 00643 case AST_TRANS_CAP_3_1K_AUDIO: 00644 return "3K1AUDIO"; 00645 case AST_TRANS_CAP_DIGITAL_W_TONES: 00646 return "DIGITAL_W_TONES"; 00647 case AST_TRANS_CAP_VIDEO: 00648 return "VIDEO"; 00649 default: 00650 return "UNKNOWN"; 00651 } 00652 }
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 1867 of file channel.c.
References ast_waitfor_nandfds().
Referenced by __adsi_transmit_messages(), __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_idle_thread(), do_waiting(), echo_exec(), handle_recordfile(), ices_exec(), isAnsweringMachine(), measurenoise(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), recordthread(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), wait_for_hangup(), waitforring_exec(), and waitstream_core().
01868 { 01869 int oldms = ms; /* -1 if no timeout */ 01870 01871 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); 01872 if ((ms < 0) && (oldms < 0)) 01873 ms = 0; 01874 return ms; 01875 }
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.
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 1862 of file channel.c.
References ast_waitfor_nandfds().
Referenced by ast_feature_request_and_dial(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), dahdi_bridge(), misdn_bridge(), monitor_dial(), rpt(), wait_for_answer(), and wait_for_winner().
01863 { 01864 return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms); 01865 }
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 1706 of file channel.c.
References ast_waitfor_nandfds().
Referenced by dundi_lookup_internal(), and dundi_precache_internal().
01707 { 01708 int winner = -1; 01709 ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms); 01710 return winner; 01711 }
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.
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 1714 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_tvdiff_ms(), ast_tvnow(), CHECK_BLOCKING, errno, and ast_channel::whentohangup.
Referenced by app_exec(), ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), conf_run(), find_cache(), run_agi(), and waitstream_core().
01716 { 01717 struct timeval start = { 0 , 0 }; 01718 struct pollfd *pfds = NULL; 01719 int res; 01720 long rms; 01721 int x, y, max; 01722 int sz; 01723 time_t now = 0; 01724 long whentohangup = 0, diff; 01725 struct ast_channel *winner = NULL; 01726 struct fdmap { 01727 int chan; 01728 int fdno; 01729 } *fdmap = NULL; 01730 01731 if ((sz = n * AST_MAX_FDS + nfds)) { 01732 pfds = alloca(sizeof(*pfds) * sz); 01733 fdmap = alloca(sizeof(*fdmap) * sz); 01734 } 01735 01736 if (outfd) 01737 *outfd = -99999; 01738 if (exception) 01739 *exception = 0; 01740 01741 /* Perform any pending masquerades */ 01742 for (x=0; x < n; x++) { 01743 ast_channel_lock(c[x]); 01744 if (c[x]->masq) { 01745 if (ast_do_masquerade(c[x])) { 01746 ast_log(LOG_WARNING, "Masquerade failed\n"); 01747 *ms = -1; 01748 ast_channel_unlock(c[x]); 01749 return NULL; 01750 } 01751 } 01752 if (c[x]->whentohangup) { 01753 if (!whentohangup) 01754 time(&now); 01755 diff = c[x]->whentohangup - now; 01756 if (diff < 1) { 01757 /* Should already be hungup */ 01758 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 01759 ast_channel_unlock(c[x]); 01760 return c[x]; 01761 } 01762 if (!whentohangup || (diff < whentohangup)) 01763 whentohangup = diff; 01764 } 01765 ast_channel_unlock(c[x]); 01766 } 01767 /* Wait full interval */ 01768 rms = *ms; 01769 if (whentohangup) { 01770 rms = whentohangup * 1000; /* timeout in milliseconds */ 01771 if (*ms >= 0 && *ms < rms) /* original *ms still smaller */ 01772 rms = *ms; 01773 } 01774 /* 01775 * Build the pollfd array, putting the channels' fds first, 01776 * followed by individual fds. Order is important because 01777 * individual fd's must have priority over channel fds. 01778 */ 01779 max = 0; 01780 for (x=0; x<n; x++) { 01781 for (y=0; y<AST_MAX_FDS; y++) { 01782 fdmap[max].fdno = y; /* fd y is linked to this pfds */ 01783 fdmap[max].chan = x; /* channel x is linked to this pfds */ 01784 max += ast_add_fd(&pfds[max], c[x]->fds[y]); 01785 } 01786 CHECK_BLOCKING(c[x]); 01787 } 01788 /* Add the individual fds */ 01789 for (x=0; x<nfds; x++) { 01790 fdmap[max].chan = -1; 01791 max += ast_add_fd(&pfds[max], fds[x]); 01792 } 01793 01794 if (*ms > 0) 01795 start = ast_tvnow(); 01796 01797 if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */ 01798 do { 01799 int kbrms = rms; 01800 if (kbrms > 600000) 01801 kbrms = 600000; 01802 res = ast_poll(pfds, max, kbrms); 01803 if (!res) 01804 rms -= kbrms; 01805 } while (!res && (rms > 0)); 01806 } else { 01807 res = ast_poll(pfds, max, rms); 01808 } 01809 for (x=0; x<n; x++) 01810 ast_clear_flag(c[x], AST_FLAG_BLOCKING); 01811 if (res < 0) { /* Simulate a timeout if we were interrupted */ 01812 if (errno != EINTR) 01813 *ms = -1; 01814 return NULL; 01815 } 01816 if (whentohangup) { /* if we have a timeout, check who expired */ 01817 time(&now); 01818 for (x=0; x<n; x++) { 01819 if (c[x]->whentohangup && now >= c[x]->whentohangup) { 01820 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 01821 if (winner == NULL) 01822 winner = c[x]; 01823 } 01824 } 01825 } 01826 if (res == 0) { /* no fd ready, reset timeout and done */ 01827 *ms = 0; /* XXX use 0 since we may not have an exact timeout. */ 01828 return winner; 01829 } 01830 /* 01831 * Then check if any channel or fd has a pending event. 01832 * Remember to check channels first and fds last, as they 01833 * must have priority on setting 'winner' 01834 */ 01835 for (x = 0; x < max; x++) { 01836 res = pfds[x].revents; 01837 if (res == 0) 01838 continue; 01839 if (fdmap[x].chan >= 0) { /* this is a channel */ 01840 winner = c[fdmap[x].chan]; /* override previous winners */ 01841 if (res & POLLPRI) 01842 ast_set_flag(winner, AST_FLAG_EXCEPTION); 01843 else 01844 ast_clear_flag(winner, AST_FLAG_EXCEPTION); 01845 winner->fdno = fdmap[x].fdno; 01846 } else { /* this is an fd */ 01847 if (outfd) 01848 *outfd = pfds[x].fd; 01849 if (exception) 01850 *exception = (res & POLLPRI) ? -1 : 0; 01851 winner = NULL; 01852 } 01853 } 01854 if (*ms > 0) { 01855 *ms -= ast_tvdiff_ms(ast_tvnow(), start); 01856 if (*ms < 0) 01857 *ms = 0; 01858 } 01859 return winner; 01860 }
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 1878 of file channel.c.
References ast_waitfordigit_full().
Referenced by _while_exec(), advanced_options(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_print(), ast_adsi_read_encoded_dtmf(), ast_adsi_transmit_message_full(), ast_app_dtget(), ast_control_streamfile(), ast_record_review(), collect_digits(), common_exec(), cpeid_exec(), dialout(), directory_exec(), do_atxfer(), forward_message(), get_folder(), ivr_dispatch(), mgcp_ss(), my_getsigstr(), pbx_builtin_waitexten(), play_mailbox_owner(), play_record_review(), read_exec(), read_newoption(), retrydial_exec(), sendnoise(), ss_thread(), testclient_exec(), testserver_exec(), vm_execmain(), vm_forwardoptions(), vm_instructions(), vm_options(), vm_tempgreeting(), wait_a_bit(), and wait_our_turn().
01879 { 01880 return ast_waitfordigit_full(c, ms, -1, -1); 01881 }
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 1904 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, 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(), errno, and f.
Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().
01905 { 01906 /* Stop if we're a zombie or need a soft hangup */ 01907 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 01908 return -1; 01909 01910 /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */ 01911 ast_set_flag(c, AST_FLAG_END_DTMF_ONLY); 01912 01913 /* Wait for a digit, no more than ms milliseconds total. */ 01914 while (ms) { 01915 struct ast_channel *rchan; 01916 int outfd; 01917 01918 errno = 0; 01919 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms); 01920 if (!rchan && outfd < 0 && ms) { 01921 if (errno == 0 || errno == EINTR) 01922 continue; 01923 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno)); 01924 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 01925 return -1; 01926 } else if (outfd > -1) { 01927 /* The FD we were watching has something waiting */ 01928 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 01929 return 1; 01930 } else if (rchan) { 01931 int res; 01932 struct ast_frame *f = ast_read(c); 01933 if (!f) 01934 return -1; 01935 01936 switch(f->frametype) { 01937 case AST_FRAME_DTMF_BEGIN: 01938 break; 01939 case AST_FRAME_DTMF_END: 01940 res = f->subclass; 01941 ast_frfree(f); 01942 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 01943 return res; 01944 case AST_FRAME_CONTROL: 01945 switch(f->subclass) { 01946 case AST_CONTROL_HANGUP: 01947 ast_frfree(f); 01948 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 01949 return -1; 01950 case AST_CONTROL_RINGING: 01951 case AST_CONTROL_ANSWER: 01952 case AST_CONTROL_SRCUPDATE: 01953 /* Unimportant */ 01954 break; 01955 default: 01956 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass); 01957 break; 01958 } 01959 break; 01960 case AST_FRAME_VOICE: 01961 /* Write audio if appropriate */ 01962 if (audiofd > -1) { 01963 if (write(audiofd, f->data, f->datalen) < 0) { 01964 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 01965 } 01966 } 01967 default: 01968 /* Ignore */ 01969 break; 01970 } 01971 ast_frfree(f); 01972 } 01973 } 01974 01975 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 01976 01977 return 0; /* Time is up */ 01978 }
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.
Definition at line 1195 of file channel.c.
References channel_find_locked().
Referenced by next_channel().
01197 { 01198 return channel_find_locked(chan, NULL, 0, context, exten); 01199 }
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 prefix (locks channel).
Definition at line 1182 of file channel.c.
References channel_find_locked().
Referenced by next_channel().
01184 { 01185 return channel_find_locked(chan, name, namelen, NULL, NULL); 01186 }
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 2828 of file channel.c.
References ast_channel::_softhangup, AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_deactivate_generator(), ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, 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_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), ast_channel::audiohooks, CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_channel::fout, ast_frame::frame_list, FRAMECOUNT_INC, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, ast_frame::len, LOG_DEBUG, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, MONITOR_CONSTANT_DELAY, MONITOR_DELAY, ast_channel::name, ast_frame::next, option_debug, ast_channel::outsmpl, ast_channel::rawwriteformat, ast_frame::samples, SEEK_FORCECUR, ast_channel_tech::send_html, ast_channel_tech::send_text, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel_tech::write, ast_channel_monitor::write_stream, ast_channel_tech::write_video, and ast_channel::writetrans.
Referenced by adsi_careful_send(), agent_write(), ast_feature_request_and_dial(), ast_prod(), ast_readaudio_callback(), ast_readvideo_callback(), ast_udptl_bridge(), ast_write_video(), bridge_native_loop(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), features_write(), function_ilink(), gen_generate(), handle_link_data(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), NBScat_exec(), rpt(), send_link_dtmf(), send_tone_burst(), send_waveform_to_channel(), silence_generator_generate(), spy_generate(), and wait_for_answer().
02829 { 02830 int res = -1; 02831 int count = 0; 02832 struct ast_frame *f = NULL; 02833 02834 /*Deadlock avoidance*/ 02835 while(ast_channel_trylock(chan)) { 02836 /*cannot goto done since the channel is not locked*/ 02837 if(count++ > 10) { 02838 if(option_debug) 02839 ast_log(LOG_DEBUG, "Deadlock avoided for write to channel '%s'\n", chan->name); 02840 return 0; 02841 } 02842 usleep(1); 02843 } 02844 /* Stop if we're a zombie or need a soft hangup */ 02845 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 02846 goto done; 02847 02848 /* Handle any pending masquerades */ 02849 if (chan->masq && ast_do_masquerade(chan)) { 02850 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 02851 goto done; 02852 } 02853 if (chan->masqr) { 02854 res = 0; /* XXX explain, why 0 ? */ 02855 goto done; 02856 } 02857 if (chan->generatordata) { 02858 if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) 02859 ast_deactivate_generator(chan); 02860 else { 02861 if (fr->frametype == AST_FRAME_DTMF_END) { 02862 /* There is a generator running while we're in the middle of a digit. 02863 * It's probably inband DTMF, so go ahead and pass it so it can 02864 * stop the generator */ 02865 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02866 ast_channel_unlock(chan); 02867 res = ast_senddigit_end(chan, fr->subclass, fr->len); 02868 ast_channel_lock(chan); 02869 CHECK_BLOCKING(chan); 02870 } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) { 02871 /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */ 02872 res = (chan->tech->indicate == NULL) ? 0 : 02873 chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen); 02874 } 02875 res = 0; /* XXX explain, why 0 ? */ 02876 goto done; 02877 } 02878 } 02879 /* High bit prints debugging */ 02880 if (chan->fout & DEBUGCHAN_FLAG) 02881 ast_frame_dump(chan->name, fr, ">>"); 02882 CHECK_BLOCKING(chan); 02883 switch(fr->frametype) { 02884 case AST_FRAME_CONTROL: 02885 res = (chan->tech->indicate == NULL) ? 0 : 02886 chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen); 02887 break; 02888 case AST_FRAME_DTMF_BEGIN: 02889 if (chan->audiohooks) { 02890 struct ast_frame *old_frame = fr; 02891 fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 02892 if (old_frame != fr) 02893 f = fr; 02894 } 02895 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02896 ast_channel_unlock(chan); 02897 res = ast_senddigit_begin(chan, fr->subclass); 02898 ast_channel_lock(chan); 02899 CHECK_BLOCKING(chan); 02900 break; 02901 case AST_FRAME_DTMF_END: 02902 if (chan->audiohooks) { 02903 struct ast_frame *new_frame = fr; 02904 02905 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 02906 if (new_frame != fr) { 02907 ast_frfree(new_frame); 02908 } 02909 } 02910 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02911 ast_channel_unlock(chan); 02912 res = ast_senddigit_end(chan, fr->subclass, fr->len); 02913 ast_channel_lock(chan); 02914 CHECK_BLOCKING(chan); 02915 break; 02916 case AST_FRAME_TEXT: 02917 res = (chan->tech->send_text == NULL) ? 0 : 02918 chan->tech->send_text(chan, (char *) fr->data); 02919 break; 02920 case AST_FRAME_HTML: 02921 res = (chan->tech->send_html == NULL) ? 0 : 02922 chan->tech->send_html(chan, fr->subclass, (char *) fr->data, fr->datalen); 02923 break; 02924 case AST_FRAME_VIDEO: 02925 /* XXX Handle translation of video codecs one day XXX */ 02926 res = (chan->tech->write_video == NULL) ? 0 : 02927 chan->tech->write_video(chan, fr); 02928 break; 02929 case AST_FRAME_MODEM: 02930 res = (chan->tech->write == NULL) ? 0 : 02931 chan->tech->write(chan, fr); 02932 break; 02933 case AST_FRAME_VOICE: 02934 if (chan->tech->write == NULL) 02935 break; /*! \todo XXX should return 0 maybe ? */ 02936 02937 /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */ 02938 if (fr->subclass == chan->rawwriteformat) 02939 f = fr; 02940 else 02941 f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr; 02942 02943 /* If we have no frame of audio, then we have to bail out */ 02944 if (!f) { 02945 res = 0; 02946 break; 02947 } 02948 02949 if (chan->audiohooks) { 02950 struct ast_frame *prev = NULL, *new_frame, *cur, *dup; 02951 int freeoldlist = 0; 02952 02953 if (f != fr) { 02954 freeoldlist = 1; 02955 } 02956 02957 /* Since ast_audiohook_write may return a new frame, and the cur frame is 02958 * an item in a list of frames, create a new list adding each cur frame back to it 02959 * regardless if the cur frame changes or not. */ 02960 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 02961 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur); 02962 02963 /* if this frame is different than cur, preserve the end of the list, 02964 * free the old frames, and set cur to be the new frame */ 02965 if (new_frame != cur) { 02966 02967 /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame 02968 * isn't part of local storage, meaning if ast_audiohook_write is called multiple 02969 * times it may override the previous frame we got from it unless we dup it */ 02970 if ((dup = ast_frisolate(new_frame))) { 02971 AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list); 02972 if (freeoldlist) { 02973 AST_LIST_NEXT(cur, frame_list) = NULL; 02974 ast_frfree(cur); 02975 } 02976 cur = dup; 02977 } 02978 } 02979 02980 /* now, regardless if cur is new or not, add it to the new list, 02981 * if the new list has not started, cur will become the first item. */ 02982 if (prev) { 02983 AST_LIST_NEXT(prev, frame_list) = cur; 02984 } else { 02985 f = cur; /* set f to be the beginning of our new list */ 02986 } 02987 prev = cur; 02988 } 02989 } 02990 02991 /* If Monitor is running on this channel, then we have to write frames out there too */ 02992 /* the translator on chan->writetrans may have returned multiple frames 02993 from the single frame we passed in; if so, feed each one of them to the 02994 monitor */ 02995 if (chan->monitor && chan->monitor->write_stream) { 02996 struct ast_frame *cur; 02997 02998 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 02999 /* XXX must explain this code */ 03000 #ifndef MONITOR_CONSTANT_DELAY 03001 int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples; 03002 if (jump >= 0) { 03003 jump = chan->insmpl - chan->outsmpl; 03004 if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1) 03005 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03006 chan->outsmpl += jump + cur->samples; 03007 } else { 03008 chan->outsmpl += cur->samples; 03009 } 03010 #else 03011 int jump = chan->insmpl - chan->outsmpl; 03012 if (jump - MONITOR_DELAY >= 0) { 03013 if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1) 03014 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03015 chan->outsmpl += jump; 03016 } else { 03017 chan->outsmpl += cur->samples; 03018 } 03019 #endif 03020 if (chan->monitor->state == AST_MONITOR_RUNNING) { 03021 if (ast_writestream(chan->monitor->write_stream, cur) < 0) 03022 ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); 03023 } 03024 } 03025 } 03026 03027 /* the translator on chan->writetrans may have returned multiple frames 03028 from the single frame we passed in; if so, feed each one of them to the 03029 channel, freeing each one after it has been written */ 03030 if ((f != fr) && AST_LIST_NEXT(f, frame_list)) { 03031 struct ast_frame *cur, *next; 03032 unsigned int skip = 0; 03033 03034 for (cur = f, next = AST_LIST_NEXT(cur, frame_list); 03035 cur; 03036 cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) { 03037 if (!skip) { 03038 if ((res = chan->tech->write(chan, cur)) < 0) { 03039 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03040 skip = 1; 03041 } else if (next) { 03042 /* don't do this for the last frame in the list, 03043 as the code outside the loop will do it once 03044 */ 03045 chan->fout = FRAMECOUNT_INC(chan->fout); 03046 } 03047 } 03048 ast_frfree(cur); 03049 } 03050 03051 /* reset f so the code below doesn't attempt to free it */ 03052 f = NULL; 03053 } else { 03054 res = chan->tech->write(chan, f); 03055 } 03056 break; 03057 case AST_FRAME_NULL: 03058 case AST_FRAME_IAX: 03059 /* Ignore these */ 03060 res = 0; 03061 break; 03062 default: 03063 /* At this point, fr is the incoming frame and f is NULL. Channels do 03064 * not expect to get NULL as a frame pointer and will segfault. Hence, 03065 * we output the original frame passed in. */ 03066 res = chan->tech->write(chan, fr); 03067 break; 03068 } 03069 03070 if (f && f != fr) 03071 ast_frfree(f); 03072 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03073 03074 /* Consider a write failure to force a soft hangup */ 03075 if (res < 0) { 03076 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03077 } else { 03078 chan->fout = FRAMECOUNT_INC(chan->fout); 03079 } 03080 done: 03081 ast_channel_unlock(chan); 03082 return res; 03083 }
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 2817 of file channel.c.
References ast_write(), ast_channel::tech, and ast_channel_tech::write_video.
02818 { 02819 int res; 02820 if (!chan->tech->write_video) 02821 return 0; 02822 res = ast_write(chan, fr); 02823 if (!res) 02824 res = 1; 02825 return res; 02826 }
const char* channelreloadreason2txt | ( | enum channelreloadreason | reason | ) |
Convert enum channelreloadreason to text string for manager event.
\ brief Convert channel reloadreason (ENUM) to text string for manager event
Definition at line 5026 of file channel.c.
References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.
05027 { 05028 switch (reason) { 05029 case CHANNEL_MODULE_LOAD: 05030 return "LOAD (Channel module load)"; 05031 05032 case CHANNEL_MODULE_RELOAD: 05033 return "RELOAD (Channel module reload)"; 05034 05035 case CHANNEL_CLI_RELOAD: 05036 return "CLIRELOAD (Channel module reload by CLI command)"; 05037 05038 default: 05039 return "MANAGERRELOAD (Channel module reload by manager)"; 05040 } 05041 };