#include "asterisk.h"
#include "asterisk/_private.h"
#include <sys/time.h>
#include <signal.h>
#include <math.h>
#include "asterisk/paths.h"
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/translate.h"
#include "asterisk/manager.h"
#include "asterisk/chanvars.h"
#include "asterisk/linkedlists.h"
#include "asterisk/indications.h"
#include "asterisk/monitor.h"
#include "asterisk/causes.h"
#include "asterisk/callerid.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/transcap.h"
#include "asterisk/devicestate.h"
#include "asterisk/sha1.h"
#include "asterisk/threadstorage.h"
#include "asterisk/slinfactory.h"
#include "asterisk/audiohook.h"
#include "asterisk/timing.h"

Go to the source code of this file.
Data Structures | |
| struct | ast_cause |
| map AST_CAUSE's to readable string representations More... | |
| struct | ast_epoll_data |
| struct | ast_silence_generator |
| struct | backends |
| the list of registered channel types More... | |
| struct | chanlist |
| List of channel drivers. More... | |
| struct | channels |
| the list of channels we have. Note that the lock for this list is used for both the channels list and the backends list. More... | |
| struct | tonepair_def |
| struct | tonepair_state |
Defines | |
| #define | AST_DEFAULT_EMULATE_DTMF_DURATION 100 |
| #define | AST_MIN_DTMF_DURATION 80 |
| #define | AST_MIN_DTMF_GAP 45 |
| #define | FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" |
| #define | STATE2STR_BUFSIZE 32 |
Functions | |
| int | __ast_answer (struct ast_channel *chan, unsigned int delay, int cdr_answer) |
| Answer a channel, with a selectable delay before returning. | |
| struct ast_channel * | __ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *file, int line, const char *function, const char *name_fmt,...) |
| Create a channel structure. | |
| static struct ast_channel *attribute_malloc | __ast_channel_alloc_ap (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *file, int line, const char *function, const char *name_fmt, va_list ap1, va_list ap2) |
| Create a new channel structure. | |
| static int | __ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after) |
| static struct ast_frame * | __ast_read (struct ast_channel *chan, int dropaudio) |
| struct ast_channel * | __ast_request_and_dial (const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh) |
| Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. | |
| static void | __fini_channels (void) |
| static void | __init_channels (void) |
| static void | __init_state2str_threadbuf (void) |
| int | ast_activate_generator (struct ast_channel *chan, struct ast_generator *gen, void *params) |
| int | ast_active_channels (void) |
| returns number of active/allocated channels | |
| int | ast_answer (struct ast_channel *chan) |
| Answer a channel. | |
| void | ast_begin_shutdown (int hangup) |
| Initiate system shutdown. | |
| int | ast_best_codec (int fmts) |
| Pick the best audio codec. | |
| struct ast_channel * | ast_bridged_channel (struct ast_channel *chan) |
| Find bridged channel. | |
| int | ast_call (struct ast_channel *chan, char *addr, int timeout) |
| Make a call. | |
| struct ast_channel * | ast_call_forward (struct ast_channel *caller, struct ast_channel *orig, int *timeout, int format, struct outgoing_helper *oh, int *outstate) |
| Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated. | |
| void | ast_cancel_shutdown (void) |
| Cancel a shutdown in progress. | |
| const char * | ast_cause2str (int cause) |
| Gives the string form of a given hangup cause. | |
| void | ast_change_name (struct ast_channel *chan, char *newname) |
| Change channel name. | |
| 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,...) |
| enum ast_bridge_result | ast_channel_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc) |
| Bridge two channels together. | |
| int | ast_channel_cmpwhentohangup (struct ast_channel *chan, time_t offset) |
| Compare a offset with the settings of when to hang a channel up. | |
| int | ast_channel_cmpwhentohangup_tv (struct ast_channel *chan, struct timeval offset) |
| Compare a offset with when to hangup channel. | |
| int | ast_channel_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore) |
| Add a datastore to a channel. | |
| struct ast_datastore * | ast_channel_datastore_alloc (const struct ast_datastore_info *info, const char *uid) |
| Create a channel data store object. | |
| struct ast_datastore * | ast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid) |
| Find a datastore on a channel. | |
| int | ast_channel_datastore_free (struct ast_datastore *datastore) |
| Free a channel data store object. | |
| int | ast_channel_datastore_inherit (struct ast_channel *from, struct ast_channel *to) |
| Inherit datastores from a parent to a child. | |
| int | ast_channel_datastore_remove (struct ast_channel *chan, struct ast_datastore *datastore) |
| Remove a datastore from a channel. | |
| int | ast_channel_defer_dtmf (struct ast_channel *chan) |
| Set defer DTMF flag on channel. | |
| int | ast_channel_early_bridge (struct ast_channel *c0, struct ast_channel *c1) |
| Bridge two channels together (early). | |
| void | ast_channel_free (struct ast_channel *chan) |
| 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 *chan, struct ast_channel *peer) |
| Makes two channel formats compatible. | |
| static int | ast_channel_make_compatible_helper (struct ast_channel *from, struct ast_channel *to) |
| Set up translation from one channel to another. | |
| int | ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clonechan) |
| Weird function made for call transfers. | |
| int | ast_channel_queryoption (struct ast_channel *chan, int option, void *data, int *datalen, int block) |
| const char * | ast_channel_reason2str (int reason) |
| return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument | |
| int | ast_channel_register (const struct ast_channel_tech *tech) |
| Register a new telephony channel in Asterisk. | |
| int | ast_channel_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen) |
| int | ast_channel_sendurl (struct ast_channel *chan, const char *url) |
| void | ast_channel_set_fd (struct ast_channel *chan, int which, int fd) |
| int | ast_channel_setoption (struct ast_channel *chan, int option, void *data, int datalen, int block) |
| Sets an option on a channel. | |
| void | ast_channel_setwhentohangup (struct ast_channel *chan, time_t offset) |
| Set when to hang a channel up. | |
| void | ast_channel_setwhentohangup_tv (struct ast_channel *chan, struct timeval offset) |
| Set when to hangup channel. | |
| struct ast_silence_generator * | ast_channel_start_silence_generator (struct ast_channel *chan) |
| Starts a silence generator on the given channel. | |
| void | ast_channel_stop_silence_generator (struct ast_channel *chan, struct ast_silence_generator *state) |
| Stops a previously-started silence generator on the given channel. | |
| int | ast_channel_supports_html (struct ast_channel *chan) |
| 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 channel driver. | |
| struct ast_channel * | ast_channel_walk_locked (const struct ast_channel *prev) |
| Browse channels in use. | |
| void | ast_channels_init (void) |
| struct ast_variable * | ast_channeltype_list (void) |
| return an ast_variable list of channeltypes | |
| int | ast_check_hangup (struct ast_channel *chan) |
| Checks to see if a channel is needing hang up. | |
| static int | ast_check_hangup_locked (struct ast_channel *chan) |
| void | ast_deactivate_generator (struct ast_channel *chan) |
| int | ast_do_masquerade (struct ast_channel *original) |
| Masquerade a channel. | |
| static enum ast_bridge_result | ast_generic_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc, struct timeval bridge_end) |
| struct ast_channel * | ast_get_channel_by_exten_locked (const char *exten, const char *context) |
| Get channel by exten (and optionally context) and lock it. | |
| struct ast_channel * | ast_get_channel_by_name_locked (const char *name) |
| Get channel by name and lock it. | |
| struct ast_channel * | ast_get_channel_by_name_prefix_locked (const char *name, const int namelen) |
| Get channel by name prefix and lock it. | |
| struct ast_channel_tech * | ast_get_channel_tech (const char *name) |
| Get handle to channel driver based on name. | |
| ast_group_t | ast_get_group (const char *s) |
| int | ast_hangup (struct ast_channel *chan) |
| Hangup a channel. | |
| int | ast_indicate (struct ast_channel *chan, int condition) |
| Indicates condition of channel. | |
| int | ast_indicate_data (struct ast_channel *chan, int _condition, const void *data, size_t datalen) |
| Indicates condition of channel, with payload. | |
| void | ast_install_music_functions (int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *)) |
| int | ast_internal_timing_enabled (struct ast_channel *chan) |
| Check if the channel can run in internal timing mode. | |
| void | ast_moh_cleanup (struct ast_channel *chan) |
| int | ast_moh_start (struct ast_channel *chan, const char *mclass, const char *interpclass) |
| Turn on music on hold on a given channel. | |
| void | ast_moh_stop (struct ast_channel *chan) |
| Turn off music on hold on a given channel. | |
| void | ast_poll_channel_add (struct ast_channel *chan0, struct ast_channel *chan1) |
| void | ast_poll_channel_del (struct ast_channel *chan0, struct ast_channel *chan1) |
| char * | ast_print_group (char *buf, int buflen, ast_group_t group) |
| Print call group and pickup group ---. | |
| int | ast_prod (struct ast_channel *chan) |
| Send empty audio to prime a channel driver. | |
| int | ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control) |
| Queue a control frame. | |
| int | ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen) |
| Queue a control frame with payload. | |
| int | ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin) |
| Queue one or more frames to a channel's frame queue. | |
| int | ast_queue_frame_head (struct ast_channel *chan, struct ast_frame *fin) |
| Queue one or more frames to the head of a channel's frame queue. | |
| int | ast_queue_hangup (struct ast_channel *chan) |
| Queue a hangup frame for channel. | |
| int | ast_queue_hangup_with_cause (struct ast_channel *chan, int cause) |
| Queue a hangup frame for channel. | |
| int | ast_raw_answer (struct ast_channel *chan, int cdr_answer) |
| Answer a channel. | |
| struct ast_frame * | ast_read (struct ast_channel *chan) |
| Reads a frame. | |
| static void | ast_read_generator_actions (struct ast_channel *chan, struct ast_frame *f) |
| struct ast_frame * | ast_read_noaudio (struct ast_channel *chan) |
| Reads a frame, returning AST_FRAME_NULL frame if audio. | |
| int | ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders) |
| int | ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd) |
| int | ast_recvchar (struct ast_channel *chan, int timeout) |
| Receives a text character from a channel. | |
| char * | ast_recvtext (struct ast_channel *chan, int timeout) |
| Receives a text string from a channel Read a string of text from a channel. | |
| struct ast_channel * | ast_request (const char *type, int format, void *data, int *cause) |
| Requests a channel. | |
| struct ast_channel * | ast_request_and_dial (const char *type, int format, void *data, int timeout, int *outstate, const char *cidnum, const char *cidname) |
| Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. | |
| int | ast_safe_sleep (struct ast_channel *chan, int ms) |
| Wait, look for hangups. | |
| int | ast_safe_sleep_conditional (struct ast_channel *chan, int ms, int(*cond)(void *), void *data) |
| Wait, look for hangups and condition arg. | |
| int | ast_say_character_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
| int | ast_say_digit_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
| int | ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang) |
| int | ast_say_digits_full (struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd) |
| int | ast_say_enumeration (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
| int | ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
| int | ast_say_phonetic_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
| int | ast_senddigit (struct ast_channel *chan, char digit, unsigned int duration) |
| Send a DTMF digit to a channel Send a DTMF digit to a channel. | |
| int | ast_senddigit_begin (struct ast_channel *chan, char digit) |
| Send a DTMF digit to a channel Send a DTMF digit to a channel. | |
| int | ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration) |
| Send a DTMF digit to a channel. | |
| int | ast_sendtext (struct ast_channel *chan, const char *text) |
| Sends text to a channel. | |
| void | ast_set_callerid (struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani) |
| Set caller ID number, name and ANI. | |
| int | ast_set_read_format (struct ast_channel *chan, int fmt) |
| 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 fmt) |
| Sets write format on channel chan Set write format for channel to whichever component of "format" is best. | |
| int | ast_setstate (struct ast_channel *chan, enum ast_channel_state state) |
| Change the state of a channel. | |
| int | ast_settimeout (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data) |
| Enable or disable timer ticks for a channel. | |
| int | ast_shutting_down (void) |
| Returns non-zero if Asterisk is being shut down. | |
| int | ast_softhangup (struct ast_channel *chan, int cause) |
| Softly hangup a channel, lock. | |
| int | ast_softhangup_nolock (struct ast_channel *chan, int cause) |
| Softly hangup a channel, don't lock. | |
| const char * | ast_state2str (enum ast_channel_state state) |
| Gives the string form of a given channel state. | |
| int | ast_str2cause (const char *name) |
| Convert a symbolic hangup cause to number. | |
| int | ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
| int | ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
| void | ast_tonepair_stop (struct ast_channel *chan) |
| int | ast_transfer (struct ast_channel *chan, char *dest) |
| Transfer a call to dest, if the channel supports transfer. | |
| char * | ast_transfercapability2str (int transfercapability) |
| Gives the string form of a given transfer capability. | |
| void | ast_uninstall_music_functions (void) |
| int | ast_waitfor (struct ast_channel *c, int ms) |
| Wait for input on a channel. | |
| struct ast_channel * | ast_waitfor_n (struct ast_channel **c, int n, int *ms) |
| Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds. | |
| int | ast_waitfor_n_fd (int *fds, int n, int *ms, int *exception) |
| Wait for x amount of time on a file descriptor to have input. | |
| struct ast_channel * | ast_waitfor_nandfds (struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms) |
| Wait for x amount of time on a file descriptor to have input. | |
| int | ast_waitfordigit (struct ast_channel *c, int ms) |
| Waits for a digit. | |
| int | ast_waitfordigit_full (struct ast_channel *c, int ms, int audiofd, int cmdfd) |
| Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. | |
| struct ast_channel * | ast_walk_channel_by_exten_locked (const struct ast_channel *chan, const char *exten, const char *context) |
| Get next channel by exten (and optionally context) and lock it. | |
| struct ast_channel * | ast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen) |
| Get next channel by name prefix and lock it. | |
| int | ast_write (struct ast_channel *chan, struct ast_frame *fr) |
| Write a frame to a channel This function writes the given frame to the indicated channel. | |
| int | ast_write_video (struct ast_channel *chan, struct ast_frame *fr) |
| Write video frame to a channel This function writes the given frame to the indicated channel. | |
| static void | bridge_play_sounds (struct ast_channel *c0, struct ast_channel *c1) |
| static void | bridge_playfile (struct ast_channel *chan, struct ast_channel *peer, const char *sound, int remain) |
| static struct ast_channel * | channel_find_locked (const struct ast_channel *prev, const char *name, const int namelen, const char *context, const char *exten) |
| Helper function to find channels. | |
| const char * | channelreloadreason2txt (enum channelreloadreason reason) |
| Convert enum channelreloadreason to text string for manager event. | |
| static void | clone_variables (struct ast_channel *original, struct ast_channel *clonechan) |
| Clone channel variables from 'clone' channel into 'original' channel. | |
| static char * | complete_channeltypes (struct ast_cli_args *a) |
| static void | free_cid (struct ast_callerid *cid) |
| static void | free_translation (struct ast_channel *clonechan) |
| static int | generator_force (const void *data) |
| static void | handle_cause (int cause, int *outstate) |
| static char * | handle_cli_core_show_channeltype (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show details about a channel driver - CLI command. | |
| static char * | handle_cli_core_show_channeltypes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show channel types - CLI command. | |
| static int attribute_const | is_visible_indication (enum ast_control_frame_type condition) |
| static void | manager_bridge_event (int onoff, int type, struct ast_channel *c0, struct ast_channel *c1) |
| Send manager event for bridge link and unlink events. | |
| static void | queue_dtmf_readq (struct ast_channel *chan, struct ast_frame *f) |
| static void | report_new_callerid (const struct ast_channel *chan) |
| static void | send_dtmf_event (const struct ast_channel *chan, const char *direction, const char digit, const char *begin, const char *end) |
| static int | set_format (struct ast_channel *chan, int fmt, int *rawformat, int *format, struct ast_trans_pvt **trans, const int direction) |
| static int | should_skip_dtmf (struct ast_channel *chan) |
| Determine whether or not we should ignore DTMF in the readq. | |
| static void * | silence_generator_alloc (struct ast_channel *chan, void *data) |
| static int | silence_generator_generate (struct ast_channel *chan, void *data, int len, int samples) |
| static void | silence_generator_release (struct ast_channel *chan, void *data) |
| static void * | tonepair_alloc (struct ast_channel *chan, void *params) |
| static int | tonepair_generator (struct ast_channel *chan, void *data, int len, int samples) |
| static void | tonepair_release (struct ast_channel *chan, void *params) |
| static void | update_bridge_vars (struct ast_channel *c0, struct ast_channel *c1) |
Variables | |
| static void(* | ast_moh_cleanup_ptr )(struct ast_channel *) = NULL |
| static int(* | ast_moh_start_ptr )(struct ast_channel *, const char *, const char *) = NULL |
| static void(* | ast_moh_stop_ptr )(struct ast_channel *) = NULL |
| struct ast_cause | causes [] |
| map AST_CAUSE's to readable string representations | |
| static struct ast_cli_entry | cli_channel [] |
| unsigned long | global_fin |
| unsigned long | global_fout |
| static struct ast_channel_tech | null_tech |
| static int | shutting_down |
| Prevent new channel allocation if shutting down. | |
| static struct ast_generator | silence_generator |
| static struct ast_threadstorage | state2str_threadbuf = { .once = PTHREAD_ONCE_INIT, .key_init = __init_state2str_threadbuf , .custom_init = NULL , } |
| static struct ast_generator | tonepair |
| static int | uniqueint |
Definition in file channel.c.
| #define AST_DEFAULT_EMULATE_DTMF_DURATION 100 |
Default amount of time to use when emulating a digit as a begin and end 100ms
Definition at line 92 of file channel.c.
Referenced by __ast_read(), and ast_senddigit().
| #define AST_MIN_DTMF_DURATION 80 |
Minimum allowed digit length - 80ms
Definition at line 95 of file channel.c.
Referenced by __ast_read().
| #define AST_MIN_DTMF_GAP 45 |
Minimum amount of time between the end of the last digit and the beginning of a new one - 45ms
Definition at line 99 of file channel.c.
Referenced by __ast_read(), and should_skip_dtmf().
| #define FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" |
| #define STATE2STR_BUFSIZE 32 |
| int __ast_answer | ( | struct ast_channel * | chan, | |
| unsigned int | delay, | |||
| int | cdr_answer | |||
| ) |
Answer a channel, with a selectable delay before returning.
| chan | channel to answer | |
| delay | maximum amount of time to wait for incoming media | |
| cdr_answer | flag to control whether any associated CDR should be marked as 'answered' |
This function will wait up to 'delay' milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow. If 'delay' is less than 500, the function will wait up to 500 milliseconds.
| 0 | on success | |
| non-zero | on failure |
Definition at line 1801 of file channel.c.
References ast_channel::_state, ast_channel_lock, ast_channel_unlock, AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_log(), ast_queue_frame_head(), ast_raw_answer(), ast_read(), AST_STATE_RING, AST_STATE_RINGING, ast_waitfor(), errno, ast_frame::frame_list, frames, ast_frame::frametype, LOG_WARNING, MAX, ast_channel::name, and ast_frame::subclass.
Referenced by ast_answer(), dial_exec_full(), pbx_builtin_answer(), and pbx_builtin_incomplete().
01802 { 01803 int res = 0; 01804 enum ast_channel_state old_state; 01805 01806 old_state = chan->_state; 01807 if ((res = ast_raw_answer(chan, cdr_answer))) { 01808 return res; 01809 } 01810 01811 switch (old_state) { 01812 case AST_STATE_RINGING: 01813 case AST_STATE_RING: 01814 /* wait for media to start flowing, but don't wait any longer 01815 * than 'delay' or 500 milliseconds, whichever is longer 01816 */ 01817 do { 01818 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 01819 struct ast_frame *cur, *new; 01820 int ms = MAX(delay, 500); 01821 unsigned int done = 0; 01822 01823 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01824 01825 for (;;) { 01826 ms = ast_waitfor(chan, ms); 01827 if (ms < 0) { 01828 ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno)); 01829 res = -1; 01830 break; 01831 } 01832 if (ms == 0) { 01833 ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500)); 01834 break; 01835 } 01836 cur = ast_read(chan); 01837 if (!cur || ((cur->frametype == AST_FRAME_CONTROL) && 01838 (cur->subclass == AST_CONTROL_HANGUP))) { 01839 if (cur) { 01840 ast_frfree(cur); 01841 } 01842 res = -1; 01843 ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name); 01844 break; 01845 } 01846 01847 if ((new = ast_frisolate(cur)) != cur) { 01848 ast_frfree(cur); 01849 } 01850 01851 AST_LIST_INSERT_HEAD(&frames, new, frame_list); 01852 01853 /* if a specific delay period was requested, continue 01854 * until that delay has passed. don't stop just because 01855 * incoming media has arrived. 01856 */ 01857 if (delay) { 01858 continue; 01859 } 01860 01861 switch (new->frametype) { 01862 /* all of these frametypes qualify as 'media' */ 01863 case AST_FRAME_VOICE: 01864 case AST_FRAME_VIDEO: 01865 case AST_FRAME_TEXT: 01866 case AST_FRAME_DTMF_BEGIN: 01867 case AST_FRAME_DTMF_END: 01868 case AST_FRAME_IMAGE: 01869 case AST_FRAME_HTML: 01870 case AST_FRAME_MODEM: 01871 done = 1; 01872 break; 01873 case AST_FRAME_CONTROL: 01874 case AST_FRAME_IAX: 01875 case AST_FRAME_NULL: 01876 case AST_FRAME_CNG: 01877 break; 01878 } 01879 01880 if (done) { 01881 break; 01882 } 01883 } 01884 01885 if (res == 0) { 01886 ast_channel_lock(chan); 01887 while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) { 01888 ast_queue_frame_head(chan, cur); 01889 ast_frfree(cur); 01890 } 01891 ast_channel_unlock(chan); 01892 } 01893 } while (0); 01894 break; 01895 default: 01896 break; 01897 } 01898 01899 return res; 01900 }
| 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 * | file, | |||
| int | line, | |||
| const char * | function, | |||
| const char * | name_fmt, | |||
| ... | ||||
| ) | [read] |
Create a channel structure.
| NULL | failure | |
| non-NULL | successfully allocated channel |
Definition at line 966 of file channel.c.
References __ast_channel_alloc_ap().
00971 { 00972 va_list ap1, ap2; 00973 struct ast_channel *result; 00974 00975 va_start(ap1, name_fmt); 00976 va_start(ap2, name_fmt); 00977 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 00978 amaflag, file, line, function, name_fmt, ap1, ap2); 00979 va_end(ap1); 00980 va_end(ap2); 00981 00982 return result; 00983 }
| static struct ast_channel* attribute_malloc __ast_channel_alloc_ap | ( | int | needqueue, | |
| int | state, | |||
| const char * | cid_num, | |||
| const char * | cid_name, | |||
| const char * | acctcode, | |||
| const char * | exten, | |||
| const char * | context, | |||
| const int | amaflag, | |||
| const char * | file, | |||
| int | line, | |||
| const char * | function, | |||
| const char * | name_fmt, | |||
| va_list | ap1, | |||
| va_list | ap2 | |||
| ) | [static, read] |
Create a new channel structure.
Definition at line 770 of file channel.c.
References __ast_calloc(), ast_channel::_state, ast_channel::accountcode, accountcode, ast_channel::alertpipe, ast_channel::amaflags, AST_ALERT_FD, ast_atomic_fetchadd_int(), ast_calloc, ast_cdr_alloc(), ast_cdr_init(), ast_cdr_start(), ast_channel_set_fd(), ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_default_accountcode, ast_default_amaflags, AST_FLAG_IN_CHANNEL_LIST, ast_free, AST_LIST_HEAD_INIT_NOLOCK, ast_log(), AST_MAX_FDS, ast_mutex_init(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_state2str(), ast_strdup, ast_string_field_build, ast_string_field_build_va, ast_string_field_free_memory, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_timer_close(), ast_timer_fd(), ast_timer_open(), AST_TIMING_FD, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::datastores, defaultlanguage, errno, EVENT_FLAG_CALL, ast_channel::exten, ast_channel::fds, ast_channel::fin, chanlist::flags, ast_channel::fout, language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::name, name, null_tech, ast_channel::priority, S_OR, ast_channel::sched, sched_context_create(), sched_context_destroy(), ast_channel::streamid, ast_channel::tech, ast_channel::timer, ast_channel::timingfd, ast_channel::uniqueid, and ast_channel::varshead.
Referenced by __ast_channel_alloc(), and ast_channel_alloc().
00774 { 00775 struct ast_channel *tmp; 00776 int x; 00777 int flags; 00778 struct varshead *headp; 00779 00780 /* If shutting down, don't allocate any new channels */ 00781 if (shutting_down) { 00782 ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n"); 00783 return NULL; 00784 } 00785 00786 #if defined(__AST_DEBUG_MALLOC) 00787 if (!(tmp = __ast_calloc(1, sizeof(*tmp), file, line, function))) { 00788 return NULL; 00789 } 00790 #else 00791 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { 00792 return NULL; 00793 } 00794 #endif 00795 00796 if (!(tmp->sched = sched_context_create())) { 00797 ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"); 00798 ast_free(tmp); 00799 return NULL; 00800 } 00801 00802 if ((ast_string_field_init(tmp, 128))) { 00803 sched_context_destroy(tmp->sched); 00804 ast_free(tmp); 00805 return NULL; 00806 } 00807 00808 #ifdef HAVE_EPOLL 00809 tmp->epfd = epoll_create(25); 00810 #endif 00811 00812 for (x = 0; x < AST_MAX_FDS; x++) { 00813 tmp->fds[x] = -1; 00814 #ifdef HAVE_EPOLL 00815 tmp->epfd_data[x] = NULL; 00816 #endif 00817 } 00818 00819 if ((tmp->timer = ast_timer_open())) { 00820 needqueue = 0; 00821 tmp->timingfd = ast_timer_fd(tmp->timer); 00822 } else { 00823 tmp->timingfd = -1; 00824 } 00825 00826 if (needqueue) { 00827 if (pipe(tmp->alertpipe)) { 00828 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n"); 00829 alertpipe_failed: 00830 if (tmp->timer) { 00831 ast_timer_close(tmp->timer); 00832 } 00833 00834 sched_context_destroy(tmp->sched); 00835 ast_string_field_free_memory(tmp); 00836 ast_free(tmp); 00837 return NULL; 00838 } else { 00839 flags = fcntl(tmp->alertpipe[0], F_GETFL); 00840 if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 00841 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00842 close(tmp->alertpipe[0]); 00843 close(tmp->alertpipe[1]); 00844 goto alertpipe_failed; 00845 } 00846 flags = fcntl(tmp->alertpipe[1], F_GETFL); 00847 if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) { 00848 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00849 close(tmp->alertpipe[0]); 00850 close(tmp->alertpipe[1]); 00851 goto alertpipe_failed; 00852 } 00853 } 00854 } else /* Make sure we've got it done right if they don't */ 00855 tmp->alertpipe[0] = tmp->alertpipe[1] = -1; 00856 00857 /* Always watch the alertpipe */ 00858 ast_channel_set_fd(tmp, AST_ALERT_FD, tmp->alertpipe[0]); 00859 /* And timing pipe */ 00860 ast_channel_set_fd(tmp, AST_TIMING_FD, tmp->timingfd); 00861 ast_string_field_set(tmp, name, "**Unknown**"); 00862 00863 /* Initial state */ 00864 tmp->_state = state; 00865 00866 tmp->streamid = -1; 00867 00868 tmp->fin = global_fin; 00869 tmp->fout = global_fout; 00870 00871 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) { 00872 ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 00873 ast_atomic_fetchadd_int(&uniqueint, 1)); 00874 } else { 00875 ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 00876 (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1)); 00877 } 00878 00879 tmp->cid.cid_name = ast_strdup(cid_name); 00880 tmp->cid.cid_num = ast_strdup(cid_num); 00881 00882 if (!ast_strlen_zero(name_fmt)) { 00883 /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call. 00884 * And they all use slightly different formats for their name string. 00885 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here. 00886 * This means, that the stringfields must have a routine that takes the va_lists directly, and 00887 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list. 00888 * This new function was written so this can be accomplished. 00889 */ 00890 ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2); 00891 } 00892 00893 /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */ 00894 00895 /* These 4 variables need to be set up for the cdr_init() to work right */ 00896 if (amaflag) 00897 tmp->amaflags = amaflag; 00898 else 00899 tmp->amaflags = ast_default_amaflags; 00900 00901 if (!ast_strlen_zero(acctcode)) 00902 ast_string_field_set(tmp, accountcode, acctcode); 00903 else 00904 ast_string_field_set(tmp, accountcode, ast_default_accountcode); 00905 00906 if (!ast_strlen_zero(context)) 00907 ast_copy_string(tmp->context, context, sizeof(tmp->context)); 00908 else 00909 strcpy(tmp->context, "default"); 00910 00911 if (!ast_strlen_zero(exten)) 00912 ast_copy_string(tmp->exten, exten, sizeof(tmp->exten)); 00913 else 00914 strcpy(tmp->exten, "s"); 00915 00916 tmp->priority = 1; 00917 00918 tmp->cdr = ast_cdr_alloc(); 00919 ast_cdr_init(tmp->cdr, tmp); 00920 ast_cdr_start(tmp->cdr); 00921 00922 headp = &tmp->varshead; 00923 AST_LIST_HEAD_INIT_NOLOCK(headp); 00924 00925 ast_mutex_init(&tmp->lock_dont_use); 00926 00927 AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores); 00928 00929 ast_string_field_set(tmp, language, defaultlanguage); 00930 00931 tmp->tech = &null_tech; 00932 00933 ast_set_flag(tmp, AST_FLAG_IN_CHANNEL_LIST); 00934 00935 AST_RWLIST_WRLOCK(&channels); 00936 AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list); 00937 AST_RWLIST_UNLOCK(&channels); 00938 00939 /*\!note 00940 * and now, since the channel structure is built, and has its name, let's 00941 * call the manager event generator with this Newchannel event. This is the 00942 * proper and correct place to make this call, but you sure do have to pass 00943 * a lot of data into this func to do it here! 00944 */ 00945 if (!ast_strlen_zero(name_fmt)) { 00946 manager_event(EVENT_FLAG_CALL, "Newchannel", 00947 "Channel: %s\r\n" 00948 "ChannelState: %d\r\n" 00949 "ChannelStateDesc: %s\r\n" 00950 "CallerIDNum: %s\r\n" 00951 "CallerIDName: %s\r\n" 00952 "AccountCode: %s\r\n" 00953 "Uniqueid: %s\r\n", 00954 tmp->name, 00955 state, 00956 ast_state2str(state), 00957 S_OR(cid_num, ""), 00958 S_OR(cid_name, ""), 00959 tmp->accountcode, 00960 tmp->uniqueid); 00961 } 00962 00963 return tmp; 00964 }
| static int __ast_queue_frame | ( | struct ast_channel * | chan, | |
| struct ast_frame * | fin, | |||
| int | head, | |||
| struct ast_frame * | after | |||
| ) | [static] |
Definition at line 985 of file channel.c.
References ast_channel::alertpipe, ast_channel_lock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FLAG_BLOCKING, AST_FRAME_CONTROL, AST_FRAME_VOICE, ast_frdup(), ast_frfree, AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_LIST_AFTER, AST_LIST_INSERT_TAIL, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_log(), ast_test_flag, ast_timer_enable_continuous(), ast_channel::blocker, errno, f, ast_frame::frame_list, frames, ast_frame::frametype, LOG_WARNING, ast_channel::name, ast_channel::readq, ast_frame::subclass, ast_channel::timer, and ast_channel::timingfd.
Referenced by __ast_read(), ast_queue_frame(), and ast_queue_frame_head().
00986 { 00987 struct ast_frame *f; 00988 struct ast_frame *cur; 00989 int blah = 1; 00990 unsigned int new_frames = 0; 00991 unsigned int new_voice_frames = 0; 00992 unsigned int queued_frames = 0; 00993 unsigned int queued_voice_frames = 0; 00994 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 00995 00996 ast_channel_lock(chan); 00997 00998 /* See if the last frame on the queue is a hangup, if so don't queue anything */ 00999 if ((cur = AST_LIST_LAST(&chan->readq)) && 01000 (cur->frametype == AST_FRAME_CONTROL) && 01001 (cur->subclass == AST_CONTROL_HANGUP)) { 01002 ast_channel_unlock(chan); 01003 return 0; 01004 } 01005 01006 /* Build copies of all the frames and count them */ 01007 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01008 for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 01009 if (!(f = ast_frdup(cur))) { 01010 ast_frfree(AST_LIST_FIRST(&frames)); 01011 return -1; 01012 } 01013 01014 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01015 new_frames++; 01016 if (f->frametype == AST_FRAME_VOICE) { 01017 new_voice_frames++; 01018 } 01019 } 01020 01021 /* Count how many frames exist on the queue */ 01022 AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) { 01023 queued_frames++; 01024 if (cur->frametype == AST_FRAME_VOICE) { 01025 queued_voice_frames++; 01026 } 01027 } 01028 01029 if ((queued_frames + new_frames) > 128) { 01030 ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name); 01031 while ((f = AST_LIST_REMOVE_HEAD(&frames, frame_list))) { 01032 ast_frfree(f); 01033 } 01034 ast_channel_unlock(chan); 01035 return 0; 01036 } 01037 01038 if ((queued_voice_frames + new_voice_frames) > 96) { 01039 ast_log(LOG_WARNING, "Exceptionally long voice queue length queuing to %s\n", chan->name); 01040 while ((f = AST_LIST_REMOVE_HEAD(&frames, frame_list))) { 01041 ast_frfree(f); 01042 } 01043 ast_channel_unlock(chan); 01044 return 0; 01045 } 01046 01047 if (after) { 01048 AST_LIST_INSERT_LIST_AFTER(&chan->readq, &frames, after, frame_list); 01049 } else { 01050 if (head) { 01051 AST_LIST_APPEND_LIST(&frames, &chan->readq, frame_list); 01052 AST_LIST_HEAD_INIT_NOLOCK(&chan->readq); 01053 } 01054 AST_LIST_APPEND_LIST(&chan->readq, &frames, frame_list); 01055 } 01056 01057 if (chan->alertpipe[1] > -1) { 01058 if (write(chan->alertpipe[1], &blah, new_frames * sizeof(blah)) != (new_frames * sizeof(blah))) { 01059 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n", 01060 chan->name, queued_frames, strerror(errno)); 01061 } 01062 } else if (chan->timingfd > -1) { 01063 ast_timer_enable_continuous(chan->timer); 01064 } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01065 pthread_kill(chan->blocker, SIGURG); 01066 } 01067 01068 ast_channel_unlock(chan); 01069 01070 return 0; 01071 }
| static struct ast_frame* __ast_read | ( | struct ast_channel * | chan, | |
| int | dropaudio | |||
| ) | [static, read] |
Definition at line 2565 of file channel.c.
References __ast_queue_frame(), ast_channel::_softhangup, ast_channel::_state, ast_channel::alertpipe, AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_write_list(), ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, ast_deactivate_generator(), ast_debug, AST_DEFAULT_EMULATE_DTMF_DURATION, ast_do_masquerade(), AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_FLAG_END_DTMF_ONLY, AST_FLAG_EXCEPTION, AST_FLAG_IN_DTMF, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_NULL, AST_FRAME_VOICE, ast_frfree, AST_GENERATOR_FD, ast_getformatname(), ast_getformatname_multiple(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MIN_DTMF_DURATION, AST_MIN_DTMF_GAP, AST_MONITOR_RUNNING, ast_null_frame, ast_queue_frame(), ast_queue_frame_head(), ast_read_generator_actions(), ast_seekstream(), ast_set_flag, ast_setstate(), AST_SOFTHANGUP_DEV, AST_STATE_UP, ast_test_flag, ast_timer_ack(), ast_timer_disable_continuous(), ast_timer_get_event(), ast_timer_set_rate(), AST_TIMING_EVENT_CONTINUOUS, AST_TIMING_EVENT_EXPIRED, AST_TIMING_FD, ast_translate(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_writestream(), ast_channel::audiohooks, ast_channel::blocker, ast_frame::data, DEBUGCHAN_FLAG, ast_generator::digit, ast_channel::dtmf_tv, ast_channel::dtmff, ast_channel::emulate_dtmf_digit, ast_channel::emulate_dtmf_duration, errno, ast_channel_tech::exception, f, ast_channel::fdno, ast_channel::fds, ast_channel::fin, chanlist::flags, ast_frame::frame_list, FRAMECOUNT_INC, ast_frame::frametype, ast_generator::generate, ast_channel::generator, ast_channel::generatordata, ast_channel::hangupcause, ast_channel::insmpl, ast_frame::len, LOG_DTMF, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::masq, ast_channel::monitor, ast_channel::music_state, ast_channel::name, ast_channel::nativeformats, ast_channel::outsmpl, queue_dtmf_readq(), ast_channel_tech::read, ast_channel_monitor::read_stream, ast_channel::readq, ast_channel::readtrans, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), should_skip_dtmf(), ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, ast_channel::timingfunc, and ast_frame::uint32.
Referenced by ast_read(), and ast_read_noaudio().
02566 { 02567 struct ast_frame *f = NULL; /* the return value */ 02568 int blah; 02569 int prestate; 02570 int count = 0, cause = 0; 02571 02572 /* this function is very long so make sure there is only one return 02573 * point at the end (there are only two exceptions to this). 02574 */ 02575 while(ast_channel_trylock(chan)) { 02576 if(count++ > 10) 02577 /*cannot goto done since the channel is not locked*/ 02578 return &ast_null_frame; 02579 usleep(1); 02580 } 02581 02582 if (chan->masq) { 02583 if (ast_do_masquerade(chan)) 02584 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 02585 else 02586 f = &ast_null_frame; 02587 goto done; 02588 } 02589 02590 /* Stop if we're a zombie or need a soft hangup */ 02591 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 02592 if (chan->generator) 02593 ast_deactivate_generator(chan); 02594 goto done; 02595 } 02596 02597 #ifdef AST_DEVMODE 02598 /* 02599 * The ast_waitfor() code records which of the channel's file descriptors reported that 02600 * data is available. In theory, ast_read() should only be called after ast_waitfor() 02601 * reports that a channel has data available for reading. However, there still may be 02602 * some edge cases throughout the code where ast_read() is called improperly. This can 02603 * potentially cause problems, so if this is a developer build, make a lot of noise if 02604 * this happens so that it can be addressed. 02605 */ 02606 if (chan->fdno == -1) { 02607 ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n"); 02608 } 02609 #endif 02610 02611 prestate = chan->_state; 02612 02613 /* Read and ignore anything on the alertpipe, but read only 02614 one sizeof(blah) per frame that we send from it */ 02615 if (chan->alertpipe[0] > -1) { 02616 int flags = fcntl(chan->alertpipe[0], F_GETFL); 02617 /* For some odd reason, the alertpipe occasionally loses nonblocking status, 02618 * which immediately causes a deadlock scenario. Detect and prevent this. */ 02619 if ((flags & O_NONBLOCK) == 0) { 02620 ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", chan->name); 02621 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 02622 ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 02623 f = &ast_null_frame; 02624 goto done; 02625 } 02626 } 02627 if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) { 02628 if (errno != EINTR && errno != EAGAIN) 02629 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); 02630 } 02631 } 02632 02633 if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD) { 02634 enum ast_timer_event res; 02635 02636 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02637 02638 res = ast_timer_get_event(chan->timer); 02639 02640 switch (res) { 02641 case AST_TIMING_EVENT_EXPIRED: 02642 ast_timer_ack(chan->timer, 1); 02643 02644 if (chan->timingfunc) { 02645 /* save a copy of func/data before unlocking the channel */ 02646 int (*func)(const void *) = chan->timingfunc; 02647 void *data = chan->timingdata; 02648 chan->fdno = -1; 02649 ast_channel_unlock(chan); 02650 func(data); 02651 } else { 02652 ast_timer_set_rate(chan->timer, 0); 02653 chan->fdno = -1; 02654 ast_channel_unlock(chan); 02655 } 02656 02657 /* cannot 'goto done' because the channel is already unlocked */ 02658 return &ast_null_frame; 02659 02660 case AST_TIMING_EVENT_CONTINUOUS: 02661 if (AST_LIST_EMPTY(&chan->readq) || 02662 !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) { 02663 ast_timer_disable_continuous(chan->timer); 02664 } 02665 break; 02666 } 02667 02668 } else if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) { 02669 /* if the AST_GENERATOR_FD is set, call the generator with args 02670 * set to -1 so it can do whatever it needs to. 02671 */ 02672 void *tmp = chan->generatordata; 02673 chan->generatordata = NULL; /* reset to let ast_write get through */ 02674 chan->generator->generate(chan, tmp, -1, -1); 02675 chan->generatordata = tmp; 02676 f = &ast_null_frame; 02677 chan->fdno = -1; 02678 goto done; 02679 } 02680 02681 /* Check for pending read queue */ 02682 if (!AST_LIST_EMPTY(&chan->readq)) { 02683 int skip_dtmf = should_skip_dtmf(chan); 02684 02685 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, f, frame_list) { 02686 /* We have to be picky about which frame we pull off of the readq because 02687 * there are cases where we want to leave DTMF frames on the queue until 02688 * some later time. */ 02689 02690 if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) { 02691 continue; 02692 } 02693 02694 AST_LIST_REMOVE_CURRENT(frame_list); 02695 break; 02696 } 02697 AST_LIST_TRAVERSE_SAFE_END; 02698 02699 if (!f) { 02700 /* There were no acceptable frames on the readq. */ 02701 f = &ast_null_frame; 02702 if (chan->alertpipe[0] > -1) { 02703 int poke = 0; 02704 /* Restore the state of the alertpipe since we aren't ready for any 02705 * of the frames in the readq. */ 02706 if (write(chan->alertpipe[1], &poke, sizeof(poke)) != sizeof(poke)) { 02707 ast_log(LOG_ERROR, "Failed to write to alertpipe: %s\n", strerror(errno)); 02708 } 02709 } 02710 } 02711 02712 /* Interpret hangup and return NULL */ 02713 /* XXX why not the same for frames from the channel ? */ 02714 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) { 02715 cause = f->data.uint32; 02716 ast_frfree(f); 02717 f = NULL; 02718 } 02719 } else { 02720 chan->blocker = pthread_self(); 02721 if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) { 02722 if (chan->tech->exception) 02723 f = chan->tech->exception(chan); 02724 else { 02725 ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name); 02726 f = &ast_null_frame; 02727 } 02728 /* Clear the exception flag */ 02729 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02730 } else if (chan->tech->read) 02731 f = chan->tech->read(chan); 02732 else 02733 ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name); 02734 } 02735 02736 /* 02737 * Reset the recorded file descriptor that triggered this read so that we can 02738 * easily detect when ast_read() is called without properly using ast_waitfor(). 02739 */ 02740 chan->fdno = -1; 02741 02742 if (f) { 02743 struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq); 02744 02745 /* if the channel driver returned more than one frame, stuff the excess 02746 into the readq for the next ast_read call 02747 */ 02748 if (AST_LIST_NEXT(f, frame_list)) { 02749 ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list)); 02750 ast_frfree(AST_LIST_NEXT(f, frame_list)); 02751 AST_LIST_NEXT(f, frame_list) = NULL; 02752 } 02753 02754 switch (f->frametype) { 02755 case AST_FRAME_CONTROL: 02756 if (f->subclass == AST_CONTROL_ANSWER) { 02757 if (!ast_test_flag(chan, AST_FLAG_OUTGOING)) { 02758 ast_debug(1, "Ignoring answer on an inbound call!\n"); 02759 ast_frfree(f); 02760 f = &ast_null_frame; 02761 } else if (prestate == AST_STATE_UP) { 02762 ast_debug(1, "Dropping duplicate answer!\n"); 02763 ast_frfree(f); 02764 f = &ast_null_frame; 02765 } else { 02766 /* Answer the CDR */ 02767 ast_setstate(chan, AST_STATE_UP); 02768 /* removed a call to ast_cdr_answer(chan->cdr) from here. */ 02769 } 02770 } 02771 break; 02772 case AST_FRAME_DTMF_END: 02773 send_dtmf_event(chan, "Received", f->subclass, "No", "Yes"); 02774 ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass, chan->name, f->len); 02775 /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */ 02776 if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) || ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 02777 queue_dtmf_readq(chan, f); 02778 ast_frfree(f); 02779 f = &ast_null_frame; 02780 } else if (!ast_test_flag(chan, AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) { 02781 if (!ast_tvzero(chan->dtmf_tv) && 02782 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02783 /* If it hasn't been long enough, defer this digit */ 02784 queue_dtmf_readq(chan, f); 02785 ast_frfree(f); 02786 f = &ast_null_frame; 02787 } else { 02788 /* There was no begin, turn this into a begin and send the end later */ 02789 f->frametype = AST_FRAME_DTMF_BEGIN; 02790 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02791 chan->emulate_dtmf_digit = f->subclass; 02792 chan->dtmf_tv = ast_tvnow(); 02793 if (f->len) { 02794 if (f->len > AST_MIN_DTMF_DURATION) 02795 chan->emulate_dtmf_duration = f->len; 02796 else 02797 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION; 02798 } else 02799 chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION; 02800 ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass, chan->emulate_dtmf_duration, chan->name); 02801 } 02802 if (chan->audiohooks) { 02803 struct ast_frame *old_frame = f; 02804 /*! 02805 * \todo XXX It is possible to write a digit to the audiohook twice 02806 * if the digit was originally read while the channel was in autoservice. */ 02807 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02808 if (old_frame != f) 02809 ast_frfree(old_frame); 02810 } 02811 } else { 02812 struct timeval now = ast_tvnow(); 02813 if (ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02814 ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass, chan->name); 02815 ast_clear_flag(chan, AST_FLAG_IN_DTMF); 02816 if (!f->len) 02817 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02818 } else if (!f->len) { 02819 ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass, chan->name); 02820 f->len = AST_MIN_DTMF_DURATION; 02821 } 02822 if (f->len < AST_MIN_DTMF_DURATION && !ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) { 02823 ast_log(LOG_DTMF, "DTMF end '%c' has duration %ld but want minimum %d, emulating on %s\n", f->subclass, f->len, AST_MIN_DTMF_DURATION, chan->name); 02824 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02825 chan->emulate_dtmf_digit = f->subclass; 02826 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION - f->len; 02827 ast_frfree(f); 02828 f = &ast_null_frame; 02829 } else { 02830 ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass, chan->name); 02831 if (f->len < AST_MIN_DTMF_DURATION) { 02832 f->len = AST_MIN_DTMF_DURATION; 02833 } 02834 chan->dtmf_tv = now; 02835 } 02836 if (chan->audiohooks) { 02837 struct ast_frame *old_frame = f; 02838 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02839 if (old_frame != f) 02840 ast_frfree(old_frame); 02841 } 02842 } 02843 break; 02844 case AST_FRAME_DTMF_BEGIN: 02845 send_dtmf_event(chan, "Received", f->subclass, "Yes", "No"); 02846 ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass, chan->name); 02847 if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) || 02848 (!ast_tvzero(chan->dtmf_tv) && 02849 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) ) { 02850 ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass, chan->name); 02851 ast_frfree(f); 02852 f = &ast_null_frame; 02853 } else { 02854 ast_set_flag(chan, AST_FLAG_IN_DTMF); 02855 chan->dtmf_tv = ast_tvnow(); 02856 ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass, chan->name); 02857 } 02858 break; 02859 case AST_FRAME_NULL: 02860 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 02861 * is reached , because we want to make sure we pass at least one 02862 * voice frame through before starting the next digit, to ensure a gap 02863 * between DTMF digits. */ 02864 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 02865 struct timeval now = ast_tvnow(); 02866 if (!chan->emulate_dtmf_duration) { 02867 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 02868 chan->emulate_dtmf_digit = 0; 02869 } else if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 02870 chan->emulate_dtmf_duration = 0; 02871 ast_frfree(f); 02872 f = &chan->dtmff; 02873 f->frametype = AST_FRAME_DTMF_END; 02874 f->subclass = chan->emulate_dtmf_digit; 02875 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02876 chan->dtmf_tv = now; 02877 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 02878 chan->emulate_dtmf_digit = 0; 02879 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 02880 if (chan->audiohooks) { 02881 struct ast_frame *old_frame = f; 02882 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02883 if (old_frame != f) { 02884 ast_frfree(old_frame); 02885 } 02886 } 02887 } 02888 } 02889 break; 02890 case AST_FRAME_VOICE: 02891 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 02892 * is reached , because we want to make sure we pass at least one 02893 * voice frame through before starting the next digit, to ensure a gap 02894 * between DTMF digits. */ 02895 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !chan->emulate_dtmf_duration) { 02896 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 02897 chan->emulate_dtmf_digit = 0; 02898 } 02899 02900 if (dropaudio || ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02901 if (dropaudio) 02902 ast_read_generator_actions(chan, f); 02903 ast_frfree(f); 02904 f = &ast_null_frame; 02905 } 02906 02907 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02908 struct timeval now = ast_tvnow(); 02909 if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 02910 chan->emulate_dtmf_duration = 0; 02911 ast_frfree(f); 02912 f = &chan->dtmff; 02913 f->frametype = AST_FRAME_DTMF_END; 02914 f->subclass = chan->emulate_dtmf_digit; 02915 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02916 chan->dtmf_tv = now; 02917 if (chan->audiohooks) { 02918 struct ast_frame *old_frame = f; 02919 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02920 if (old_frame != f) 02921 ast_frfree(old_frame); 02922 } 02923 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 02924 } else { 02925 /* Drop voice frames while we're still in the middle of the digit */ 02926 ast_frfree(f); 02927 f = &ast_null_frame; 02928 } 02929 } else if ((f->frametype == AST_FRAME_VOICE) && !(f->subclass & chan->nativeformats)) { 02930 /* This frame is not one of the current native formats -- drop it on the floor */ 02931 char to[200]; 02932 ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n", 02933 chan->name, ast_getformatname(f->subclass), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats)); 02934 ast_frfree(f); 02935 f = &ast_null_frame; 02936 } else if ((f->frametype == AST_FRAME_VOICE)) { 02937 /* Send frame to audiohooks if present */ 02938 if (chan->audiohooks) { 02939 struct ast_frame *old_frame = f; 02940 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02941 if (old_frame != f) 02942 ast_frfree(old_frame); 02943 } 02944 if (chan->monitor && chan->monitor->read_stream ) { 02945 /* XXX what does this do ? */ 02946 #ifndef MONITOR_CONSTANT_DELAY 02947 int jump = chan->outsmpl - chan->insmpl - 4 * f->samples; 02948 if (jump >= 0) { 02949 jump = chan->outsmpl - chan->insmpl; 02950 if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1) 02951 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 02952 chan->insmpl += jump + f->samples; 02953 } else 02954 chan->insmpl+= f->samples; 02955 #else 02956 int jump = chan->outsmpl - chan->insmpl; 02957 if (jump - MONITOR_DELAY >= 0) { 02958 if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1) 02959 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 02960 chan->insmpl += jump; 02961 } else 02962 chan->insmpl += f->samples; 02963 #endif 02964 if (chan->monitor->state == AST_MONITOR_RUNNING) { 02965 if (ast_writestream(chan->monitor->read_stream, f) < 0) 02966 ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n"); 02967 } 02968 } 02969 02970 if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) { 02971 f = &ast_null_frame; 02972 } 02973 02974 /* it is possible for the translation process on chan->readtrans to have 02975 produced multiple frames from the single input frame we passed it; if 02976 this happens, queue the additional frames *before* the frames we may 02977 have queued earlier. if the readq was empty, put them at the head of 02978 the queue, and if it was not, put them just after the frame that was 02979 at the end of the queue. 02980 */ 02981 if (AST_LIST_NEXT(f, frame_list)) { 02982 if (!readq_tail) { 02983 ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list)); 02984 } else { 02985 __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail); 02986 } 02987 ast_frfree(AST_LIST_NEXT(f, frame_list)); 02988 AST_LIST_NEXT(f, frame_list) = NULL; 02989 } 02990 02991 /* Run generator sitting on the line if timing device not available 02992 * and synchronous generation of outgoing frames is necessary */ 02993 ast_read_generator_actions(chan, f); 02994 } 02995 default: 02996 /* Just pass it on! */ 02997 break; 02998 } 02999 } else { 03000 /* Make sure we always return NULL in the future */ 03001 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03002 if (cause) 03003 chan->hangupcause = cause; 03004 if (chan->generator) 03005 ast_deactivate_generator(chan); 03006 /* We no longer End the CDR here */ 03007 } 03008 03009 /* High bit prints debugging */ 03010 if (chan->fin & DEBUGCHAN_FLAG) 03011 ast_frame_dump(chan->name, f, "<<"); 03012 chan->fin = FRAMECOUNT_INC(chan->fin); 03013 03014 done: 03015 if (chan->music_state && chan->generator && chan->generator->digit && f && f->frametype == AST_FRAME_DTMF_END) 03016 chan->generator->digit(chan, f->subclass); 03017 03018 ast_channel_unlock(chan); 03019 return f; 03020 }
| struct ast_channel* __ast_request_and_dial | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int | timeout, | |||
| int * | reason, | |||
| const char * | cid_num, | |||
| const char * | cid_name, | |||
| struct outgoing_helper * | oh | |||
| ) | [read] |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.
| type | type of channel to request | |
| format | requested channel format | |
| data | data to pass to the channel requester | |
| timeout | maximum amount of time to wait for an answer | |
| reason | why unsuccessful (if unsuccessful) | |
| cid_num | Caller-ID Number | |
| cid_name | Caller-ID Name (ascii) | |
| oh | Outgoing helper |
Definition at line 3771 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_disposition(), ast_cdr_end(), ast_cdr_failed(), AST_CDR_FLAG_ORIGINATED, ast_cdr_init(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_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, ast_frame::frametype, handle_cause(), ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, ast_channel::priority, outgoing_helper::priority, ast_frame::subclass, and outgoing_helper::vars.
Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().
03772 { 03773 int dummy_outstate; 03774 int cause = 0; 03775 struct ast_channel *chan; 03776 int res = 0; 03777 int last_subclass = 0; 03778 03779 if (outstate) 03780 *outstate = 0; 03781 else 03782 outstate = &dummy_outstate; /* make outstate always a valid pointer */ 03783 03784 chan = ast_request(type, format, data, &cause); 03785 if (!chan) { 03786 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data); 03787 handle_cause(cause, outstate); 03788 return NULL; 03789 } 03790 03791 if (oh) { 03792 if (oh->vars) 03793 ast_set_variables(chan, oh->vars); 03794 /* XXX why is this necessary, for the parent_channel perhaps ? */ 03795 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) 03796 ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); 03797 if (oh->parent_channel) { 03798 ast_channel_inherit_variables(oh->parent_channel, chan); 03799 ast_channel_datastore_inherit(oh->parent_channel, chan); 03800 } 03801 if (oh->account) 03802 ast_cdr_setaccount(chan, oh->account); 03803 } 03804 ast_set_callerid(chan, cid_num, cid_name, cid_num); 03805 ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED); 03806 03807 if (ast_call(chan, data, 0)) { /* ast_call failed... */ 03808 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data); 03809 } else { 03810 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */ 03811 while (timeout && chan->_state != AST_STATE_UP) { 03812 struct ast_frame *f; 03813 res = ast_waitfor(chan, timeout); 03814 if (res == 0) { /* timeout, treat it like ringing */ 03815 *outstate = AST_CONTROL_RINGING; 03816 break; 03817 } 03818 if (res < 0) /* error or done */ 03819 break; 03820 if (timeout > -1) 03821 timeout = res; 03822 if (!ast_strlen_zero(chan->call_forward)) { 03823 if (!(chan = ast_call_forward(NULL, chan, &timeout, format, oh, outstate))) { 03824 return NULL; 03825 } 03826 continue; 03827 } 03828 03829 f = ast_read(chan); 03830 if (!f) { 03831 *outstate = AST_CONTROL_HANGUP; 03832 res = 0; 03833 break; 03834 } 03835 if (f->frametype == AST_FRAME_CONTROL) { 03836 switch (f->subclass) { 03837 case AST_CONTROL_RINGING: /* record but keep going */ 03838 *outstate = f->subclass; 03839 break; 03840 03841 case AST_CONTROL_BUSY: 03842 case AST_CONTROL_CONGESTION: 03843 case AST_CONTROL_ANSWER: 03844 *outstate = f->subclass; 03845 timeout = 0; /* trick to force exit from the while() */ 03846 break; 03847 03848 /* Ignore these */ 03849 case AST_CONTROL_PROGRESS: 03850 case AST_CONTROL_PROCEEDING: 03851 case AST_CONTROL_HOLD: 03852 case AST_CONTROL_UNHOLD: 03853 case AST_CONTROL_VIDUPDATE: 03854 case AST_CONTROL_SRCUPDATE: 03855 case -1: /* Ignore -- just stopping indications */ 03856 break; 03857 03858 default: 03859 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass); 03860 } 03861 last_subclass = f->subclass; 03862 } 03863 ast_frfree(f); 03864 } 03865 } 03866 03867 /* Final fixups */ 03868 if (oh) { 03869 if (!ast_strlen_zero(oh->context)) 03870 ast_copy_string(chan->context, oh->context, sizeof(chan->context)); 03871 if (!ast_strlen_zero(oh->exten)) 03872 ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten)); 03873 if (oh->priority) 03874 chan->priority = oh->priority; 03875 } 03876 if (chan->_state == AST_STATE_UP) 03877 *outstate = AST_CONTROL_ANSWER; 03878 03879 if (res <= 0) { 03880 if ( AST_CONTROL_RINGING == last_subclass ) 03881 chan->hangupcause = AST_CAUSE_NO_ANSWER; 03882 if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) 03883 ast_cdr_init(chan->cdr, chan); 03884 if (chan->cdr) { 03885 char tmp[256]; 03886 snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data); 03887 ast_cdr_setapp(chan->cdr,"Dial",tmp); 03888 ast_cdr_update(chan); 03889 ast_cdr_start(chan->cdr); 03890 ast_cdr_end(chan->cdr); 03891 /* If the cause wasn't handled properly */ 03892 if (ast_cdr_disposition(chan->cdr,chan->hangupcause)) 03893 ast_cdr_failed(chan->cdr); 03894 } 03895 ast_hangup(chan); 03896 chan = NULL; 03897 } 03898 return chan; 03899 }
| static void __init_state2str_threadbuf | ( | void | ) | [static] |
| int ast_activate_generator | ( | struct ast_channel * | chan, | |
| struct ast_generator * | gen, | |||
| void * | params | |||
| ) |
Activate a given generator
Definition at line 1952 of file channel.c.
References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), ast_channel::generator, generator_force(), ast_channel::generatordata, and ast_generator::release.
Referenced by app_exec(), ast_channel_start_silence_generator(), ast_linear_stream(), ast_playtones_start(), ast_tonepair_start(), channel_spy(), eivr_comm(), local_ast_moh_start(), old_milliwatt_exec(), and transmit_audio().
01953 { 01954 int res = 0; 01955 01956 ast_channel_lock(chan); 01957 01958 if (chan->generatordata) { 01959 if (chan->generator && chan->generator->release) 01960 chan->generator->release(chan, chan->generatordata); 01961 chan->generatordata = NULL; 01962 } 01963 01964 ast_prod(chan); 01965 if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) { 01966 res = -1; 01967 } 01968 01969 if (!res) { 01970 ast_settimeout(chan, 50, generator_force, chan); 01971 chan->generator = gen; 01972 } 01973 01974 ast_channel_unlock(chan); 01975 01976 return res; 01977 }
| int ast_active_channels | ( | void | ) |
returns number of active/allocated channels
Returns number of active/allocated channels
Definition at line 497 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by action_corestatus(), dahdi_restart(), handle_show_settings(), and quit_handler().
00498 { 00499 struct ast_channel *c; 00500 int cnt = 0; 00501 AST_RWLIST_RDLOCK(&channels); 00502 AST_RWLIST_TRAVERSE(&channels, c, chan_list) 00503 cnt++; 00504 AST_RWLIST_UNLOCK(&channels); 00505 return cnt; 00506 }
| int ast_answer | ( | struct ast_channel * | chan | ) |
Answer a channel.
| chan | channel to answer |
This function will wait up to 500 milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow.
| 0 | on success | |
| non-zero | on failure |
Definition at line 1902 of file channel.c.
References __ast_answer().
Referenced by action_bridge(), agi_exec_full(), alarmreceiver_exec(), answer_trunk_chan(), app_exec(), ast_control_streamfile(), ast_pickup_call(), auth_exec(), background_detect_exec(), bridge_exec(), builtin_parkcall(), common_exec(), conf_exec(), count_exec(), dahdiras_exec(), dictate_exec(), directory_exec(), disa_exec(), eivr_comm(), handle_answer(), ices_exec(), login_exec(), minivm_accmess_exec(), minivm_greet_exec(), minivm_record_exec(), old_milliwatt_exec(), park_call_exec(), park_exec_full(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), readexten_exec(), record_exec(), rpt_exec(), sayunixtime_exec(), send_waveform_to_channel(), setup_privacy_args(), skel_exec(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), transmit(), vm_exec(), vm_execmain(), waitfor_exec(), and zapateller_exec().
01903 { 01904 return __ast_answer(chan, 0, 1); 01905 }
| void ast_begin_shutdown | ( | int | hangup | ) |
Initiate system shutdown.
Initiate system shutdown -- prevents new channels from being allocated. If "hangup" is non-zero, all existing channels will receive soft hangups
Definition at line 483 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.
Referenced by quit_handler().
00484 { 00485 struct ast_channel *c; 00486 shutting_down = 1; 00487 if (hangup) { 00488 AST_RWLIST_RDLOCK(&channels); 00489 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 00490 ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN); 00491 } 00492 AST_RWLIST_UNLOCK(&channels); 00493 } 00494 }
| int ast_best_codec | ( | int | fmts | ) |
Pick the best audio codec.
Pick the best codec
Okay, ulaw is used by all telephony equipment, so start with it
Unless of course, you're a silly European, so then prefer ALAW
G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority
Okay, well, signed linear is easy to translate into other stuff
G.726 is standard ADPCM, in RFC3551 packing order
G.726 is standard ADPCM, in AAL2 packing order
ADPCM has great sound quality and is still pretty easy to translate
Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good
iLBC is not too bad
Speex is free, but computationally more expensive than GSM
Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it
G.729a is faster than 723 and slightly less expensive
Down to G.723.1 which is proprietary but at least designed for voice
Definition at line 711 of file channel.c.
References ARRAY_LEN, AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_AUDIO_MASK, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR16, AST_FORMAT_SPEEX, AST_FORMAT_ULAW, ast_log(), LOG_WARNING, and prefs.
Referenced by __oh323_new(), agent_call(), ast_codec_choose(), ast_iax2_new(), ast_speech_new(), builtin_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), jingle_new(), local_new(), login_exec(), mgcp_new(), sip_new(), skinny_new(), skinny_set_rtp_peer(), socket_process(), start_rtp(), transmit_connect(), and unistim_new().
00712 { 00713 /* This just our opinion, expressed in code. We are asked to choose 00714 the best codec to use, given no information */ 00715 int x; 00716 static const int prefs[] = 00717 { 00718 /*! Okay, ulaw is used by all telephony equipment, so start with it */ 00719 AST_FORMAT_ULAW, 00720 /*! Unless of course, you're a silly European, so then prefer ALAW */ 00721 AST_FORMAT_ALAW, 00722 /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */ 00723 AST_FORMAT_G722, 00724 /*! Okay, well, signed linear is easy to translate into other stuff */ 00725 AST_FORMAT_SLINEAR16, 00726 AST_FORMAT_SLINEAR, 00727 /*! G.726 is standard ADPCM, in RFC3551 packing order */ 00728 AST_FORMAT_G726, 00729 /*! G.726 is standard ADPCM, in AAL2 packing order */ 00730 AST_FORMAT_G726_AAL2, 00731 /*! ADPCM has great sound quality and is still pretty easy to translate */ 00732 AST_FORMAT_ADPCM, 00733 /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to 00734 translate and sounds pretty good */ 00735 AST_FORMAT_GSM, 00736 /*! iLBC is not too bad */ 00737 AST_FORMAT_ILBC, 00738 /*! Speex is free, but computationally more expensive than GSM */ 00739 AST_FORMAT_SPEEX, 00740 /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough 00741 to use it */ 00742 AST_FORMAT_LPC10, 00743 /*! G.729a is faster than 723 and slightly less expensive */ 00744 AST_FORMAT_G729A, 00745 /*! Down to G.723.1 which is proprietary but at least designed for voice */ 00746 AST_FORMAT_G723_1, 00747 }; 00748 00749 /* Strip out video */ 00750 fmts &= AST_FORMAT_AUDIO_MASK; 00751 00752 /* Find the first preferred codec in the format given */ 00753 for (x = 0; x < ARRAY_LEN(prefs); x++) { 00754 if (fmts & prefs[x]) 00755 return prefs[x]; 00756 } 00757 00758 ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts); 00759 00760 return 0; 00761 }
| struct ast_channel* ast_bridged_channel | ( | struct ast_channel * | chan | ) | [read] |
Find bridged channel.
| chan | Current channel |
Definition at line 4651 of file channel.c.
References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.
Referenced by __dahdi_exception(), action_agents(), action_coreshowchannels(), agents_show(), agents_show_online(), ast_bridge_call(), ast_channel_masquerade(), ast_park_call_full(), ast_rtp_set_vars(), attempt_transfer(), cb_events(), channel_spy(), check_bridge(), common_exec(), console_transfer(), create_jb(), dahdi_handle_event(), dahdi_hangup(), export_aoc_vars(), get_refer_info(), handle_chanlist(), handle_hd_hf(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_refer(), handle_showchan(), handle_soft_key_event_message(), handle_stimulus_message(), key_call(), key_dial_page(), local_attended_transfer(), mgcp_hangup(), mgcp_ss(), misdn_attempt_transfer(), mixmonitor_thread(), schedule_delivery(), sip_hangup(), sip_read(), sip_set_rtp_peer(), skinny_transfer(), socket_process(), ss_thread(), start_spying(), startmon(), TransferCallStep1(), and unistim_hangup().
04652 { 04653 struct ast_channel *bridged; 04654 bridged = chan->_bridge; 04655 if (bridged && bridged->tech->bridged_channel) 04656 bridged = bridged->tech->bridged_channel(chan, bridged); 04657 return bridged; 04658 }
| 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 3962 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_channel(), connect_link(), dial_exec_full(), do_forward(), findmeexec(), ring_entry(), rpt(), rpt_exec(), and wait_for_answer().
03963 { 03964 /* Place an outgoing call, but don't wait any longer than timeout ms before returning. 03965 If the remote end does not answer within the timeout, then do NOT hang up, but 03966 return anyway. */ 03967 int res = -1; 03968 /* Stop if we're a zombie or need a soft hangup */ 03969 ast_channel_lock(chan); 03970 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 03971 if (chan->cdr) 03972 ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED); 03973 if (chan->tech->call) 03974 res = chan->tech->call(chan, addr, timeout); 03975 ast_set_flag(chan, AST_FLAG_OUTGOING); 03976 } 03977 ast_channel_unlock(chan); 03978 return res; 03979 }
| struct ast_channel* ast_call_forward | ( | struct ast_channel * | caller, | |
| struct ast_channel * | orig, | |||
| int * | timeout, | |||
| int | format, | |||
| struct outgoing_helper * | oh, | |||
| int * | outstate | |||
| ) | [read] |
Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.
| caller | in channel that requested orig | |
| orig | channel being replaced by the call forward channel | |
| timeout | maximum amount of time to wait for setup of new forward channel | |
| format | requested channel format | |
| oh | outgoing helper used with original channel | |
| outstate | reason why unsuccessful (if uncuccessful) |
Definition at line 3699 of file channel.c.
References outgoing_helper::account, ast_channel::accountcode, accountcode, ast_call(), AST_CDR_FLAG_ORIGINATED, ast_cdr_setaccount(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_copy_flags, ast_copy_string(), ast_hangup(), ast_log(), ast_request(), ast_set_callerid(), ast_set_variables(), ast_string_field_set, ast_strlen_zero(), ast_channel::call_forward, ast_channel::cdr, CHANNEL_DEADLOCK_AVOIDANCE, ast_channel::cid, ast_callerid::cid_name, outgoing_helper::cid_name, ast_callerid::cid_num, outgoing_helper::cid_num, ast_channel::context, 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().
03700 { 03701 char tmpchan[256]; 03702 struct ast_channel *new = NULL; 03703 char *data, *type; 03704 int cause = 0; 03705 03706 /* gather data and request the new forward channel */ 03707 ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan)); 03708 if ((data = strchr(tmpchan, '/'))) { 03709 *data++ = '\0'; 03710 type = tmpchan; 03711 } else { 03712 const char *forward_context; 03713 ast_channel_lock(orig); 03714 forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT"); 03715 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context)); 03716 ast_channel_unlock(orig); 03717 data = tmpchan; 03718 type = "Local"; 03719 } 03720 if (!(new = ast_request(type, format, data, &cause))) { 03721 ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause); 03722 handle_cause(cause, outstate); 03723 ast_hangup(orig); 03724 return NULL; 03725 } 03726 03727 /* Copy/inherit important information into new channel */ 03728 if (oh) { 03729 if (oh->vars) { 03730 ast_set_variables(new, oh->vars); 03731 } 03732 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) { 03733 ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num); 03734 } 03735 if (oh->parent_channel) { 03736 ast_channel_inherit_variables(oh->parent_channel, new); 03737 ast_channel_datastore_inherit(oh->parent_channel, new); 03738 } 03739 if (oh->account) { 03740 ast_cdr_setaccount(new, oh->account); 03741 } 03742 } else if (caller) { /* no outgoing helper so use caller if avaliable */ 03743 ast_channel_inherit_variables(caller, new); 03744 ast_channel_datastore_inherit(caller, new); 03745 } 03746 03747 ast_channel_lock(orig); 03748 while (ast_channel_trylock(new)) { 03749 CHANNEL_DEADLOCK_AVOIDANCE(orig); 03750 } 03751 ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED); 03752 ast_string_field_set(new, accountcode, orig->accountcode); 03753 if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) { 03754 ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num); 03755 } 03756 ast_channel_unlock(new); 03757 ast_channel_unlock(orig); 03758 03759 /* call new channel */ 03760 if ((*timeout = ast_call(new, data, 0))) { 03761 ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data); 03762 ast_hangup(orig); 03763 ast_hangup(new); 03764 return NULL; 03765 } 03766 ast_hangup(orig); 03767 03768 return new; 03769 }
| void ast_cancel_shutdown | ( | void | ) |
Cancel a shutdown in progress.
Cancels an existing shutdown and returns to normal operation
Definition at line 509 of file channel.c.
Referenced by handle_abort_shutdown().
00510 { 00511 shutting_down = 0; 00512 }
| const char* ast_cause2str | ( | int | state | ) |
Gives the string form of a given hangup cause.
Gives the string form of a given cause code
| state | cause to get the description of Give a name to a cause code Returns the text form of the binary cause code given |
Definition at line 629 of file channel.c.
References ARRAY_LEN, causes, and ast_cause::desc.
Referenced by __transmit_response(), ast_do_masquerade(), ast_hangup(), dial_exec_full(), findmeexec(), sip_hangup(), and transmit_request_with_auth().
00630 { 00631 int x; 00632 00633 for (x = 0; x < ARRAY_LEN(causes); x++) { 00634 if (causes[x].cause == cause) 00635 return causes[x].desc; 00636 } 00637 00638 return "Unknown"; 00639 }
| void ast_change_name | ( | struct ast_channel * | chan, | |
| char * | newname | |||
| ) |
Change channel name.
Definition at line 4214 of file channel.c.
References ast_string_field_set, EVENT_FLAG_CALL, manager_event, name, ast_channel::name, and ast_channel::uniqueid.
Referenced by update_name().
04215 { 04216 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid); 04217 ast_string_field_set(chan, name, newname); 04218 }
| 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, | |||
| ... | ||||
| ) | [read] |
Definition at line 5794 of file channel.c.
References __ast_channel_alloc_ap().
05798 { 05799 va_list ap1, ap2; 05800 struct ast_channel *result; 05801 05802 05803 va_start(ap1, name_fmt); 05804 va_start(ap2, name_fmt); 05805 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 05806 amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap1, ap2); 05807 va_end(ap1); 05808 va_end(ap2); 05809 05810 return result; 05811 }
| enum ast_bridge_result ast_channel_bridge | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1, | |||
| struct ast_bridge_config * | config, | |||
| struct ast_frame ** | fo, | |||
| struct ast_channel ** | rc | |||
| ) |
Bridge two channels together.
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 4973 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_debug, AST_FEATURE_PLAY_WARNING, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_generic_bridge(), ast_indicate(), ast_log(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_verb, ast_channel::audiohooks, ast_channel_tech::bridge, bridge_play_sounds(), bridge_playfile(), ast_channel::cid, ast_callerid::cid_num, ast_bridge_config::end_sound, EVENT_FLAG_CALL, ast_bridge_config::feature_timer, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::firstpass, ast_bridge_config::flags, ast_channel::generator, LOG_WARNING, manager_bridge_event(), manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_bridge_config::play_warning, ast_channel::readformat, ast_channel_tech::send_digit_begin, ast_bridge_config::start_sound, ast_bridge_config::start_time, ast_channel::tech, ast_bridge_config::timelimit, ast_channel::uniqueid, update_bridge_vars(), ast_bridge_config::warning_freq, ast_bridge_config::warning_sound, and ast_channel::writeformat.
Referenced by ast_bridge_call().
04975 { 04976 struct ast_channel *who = NULL; 04977 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 04978 int nativefailed=0; 04979 int firstpass; 04980 int o0nativeformats; 04981 int o1nativeformats; 04982 long time_left_ms=0; 04983 char caller_warning = 0; 04984 char callee_warning = 0; 04985 04986 if (c0->_bridge) { 04987 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 04988 c0->name, c0->_bridge->name); 04989 return -1; 04990 } 04991 if (c1->_bridge) { 04992 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 04993 c1->name, c1->_bridge->name); 04994 return -1; 04995 } 04996 04997 /* Stop if we're a zombie or need a soft hangup */ 04998 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 04999 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) 05000 return -1; 05001 05002 *fo = NULL; 05003 firstpass = config->firstpass; 05004 config->firstpass = 0; 05005 05006 if (ast_tvzero(config->start_time)) 05007 config->start_time = ast_tvnow(); 05008 time_left_ms = config->timelimit; 05009 05010 caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING); 05011 callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING); 05012 05013 if (config->start_sound && firstpass) { 05014 if (caller_warning) 05015 bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000); 05016 if (callee_warning) 05017 bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000); 05018 } 05019 05020 /* Keep track of bridge */ 05021 c0->_bridge = c1; 05022 c1->_bridge = c0; 05023 05024 05025 o0nativeformats = c0->nativeformats; 05026 o1nativeformats = c1->nativeformats; 05027 05028 if (config->feature_timer && !ast_tvzero(config->nexteventts)) { 05029 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000)); 05030 } else if (config->timelimit && firstpass) { 05031 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05032 if (caller_warning || callee_warning) 05033 config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000)); 05034 } 05035 05036 if (!c0->tech->send_digit_begin) 05037 ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY); 05038 if (!c1->tech->send_digit_begin) 05039 ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); 05040 manager_bridge_event(1, 1, c0, c1); 05041 05042 /* Before we enter in and bridge these two together tell them both the source of audio has changed */ 05043 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 05044 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 05045 05046 for (/* ever */;;) { 05047 struct timeval now = { 0, }; 05048 int to; 05049 05050 to = -1; 05051 05052 if (!ast_tvzero(config->nexteventts)) { 05053 now = ast_tvnow(); 05054 to = ast_tvdiff_ms(config->nexteventts, now); 05055 if (to <= 0) { 05056 if (!config->timelimit) { 05057 res = AST_BRIDGE_COMPLETE; 05058 break; 05059 } 05060 to = 0; 05061 } 05062 } 05063 05064 if (config->timelimit) { 05065 time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time); 05066 if (time_left_ms < to) 05067 to = time_left_ms; 05068 05069 if (time_left_ms <= 0) { 05070 if (caller_warning && config->end_sound) 05071 bridge_playfile(c0, c1, config->end_sound, 0); 05072 if (callee_warning && config->end_sound) 05073 bridge_playfile(c1, c0, config->end_sound, 0); 05074 *fo = NULL; 05075 if (who) 05076 *rc = who; 05077 res = 0; 05078 break; 05079 } 05080 05081 if (!to) { 05082 if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) { 05083 int t = (time_left_ms + 500) / 1000; /* round to nearest second */ 05084 if (caller_warning) 05085 bridge_playfile(c0, c1, config->warning_sound, t); 05086 if (callee_warning) 05087 bridge_playfile(c1, c0, config->warning_sound, t); 05088 } 05089 if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) 05090 config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000)); 05091 else 05092 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05093 } 05094 ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE); 05095 } 05096 05097 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 05098 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05099 c0->_softhangup = 0; 05100 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05101 c1->_softhangup = 0; 05102 c0->_bridge = c1; 05103 c1->_bridge = c0; 05104 ast_debug(1, "Unbridge signal received. Ending native bridge.\n"); 05105 continue; 05106 } 05107 05108 /* Stop if we're a zombie or need a soft hangup */ 05109 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 05110 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { 05111 *fo = NULL; 05112 if (who) 05113 *rc = who; 05114 res = 0; 05115 ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n", 05116 c0->name, c1->name, 05117 ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05118 ast_check_hangup(c0) ? "Yes" : "No", 05119 ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05120 ast_check_hangup(c1) ? "Yes" : "No"); 05121 break; 05122 } 05123 05124 update_bridge_vars(c0, c1); 05125 05126 bridge_play_sounds(c0, c1); 05127 05128 if (c0->tech->bridge && 05129 (c0->tech->bridge == c1->tech->bridge) && 05130 !nativefailed && !c0->monitor && !c1->monitor && 05131 !c0->audiohooks && !c1->audiohooks && 05132 !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) { 05133 /* Looks like they share a bridge method and nothing else is in the way */ 05134 ast_set_flag(c0, AST_FLAG_NBRIDGE); 05135 ast_set_flag(c1, AST_FLAG_NBRIDGE); 05136 if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, to)) == AST_BRIDGE_COMPLETE) { 05137 /* \todo XXX here should check that cid_num is not NULL */ 05138 manager_event(EVENT_FLAG_CALL, "Unlink", 05139 "Channel1: %s\r\n" 05140 "Channel2: %s\r\n" 05141 "Uniqueid1: %s\r\n" 05142 "Uniqueid2: %s\r\n" 05143 "CallerID1: %s\r\n" 05144 "CallerID2: %s\r\n", 05145 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05146 ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name); 05147 05148 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05149 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05150 05151 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05152 continue; 05153 05154 c0->_bridge = NULL; 05155 c1->_bridge = NULL; 05156 05157 return res; 05158 } else { 05159 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05160 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05161 } 05162 switch (res) { 05163 case AST_BRIDGE_RETRY: 05164 if (config->play_warning) { 05165 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 05166 } 05167 continue; 05168 default: 05169 ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name); 05170 /* fallthrough */ 05171 case AST_BRIDGE_FAILED_NOWARN: 05172 nativefailed++; 05173 break; 05174 } 05175 } 05176 05177 if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || 05178 (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && 05179 !(c0->generator || c1->generator)) { 05180 if (ast_channel_make_compatible(c0, c1)) { 05181 ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name); 05182 manager_bridge_event(0, 1, c0, c1); 05183 return AST_BRIDGE_FAILED; 05184 } 05185 o0nativeformats = c0->nativeformats; 05186 o1nativeformats = c1->nativeformats; 05187 } 05188 05189 update_bridge_vars(c0, c1); 05190 05191 res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts); 05192 if (res != AST_BRIDGE_RETRY) { 05193 break; 05194 } else if (config->feature_timer) { 05195 /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */ 05196 break; 05197 } 05198 } 05199 05200 ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY); 05201 ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY); 05202 05203 /* Now that we have broken the bridge the source will change yet again */ 05204 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 05205 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 05206 05207 c0->_bridge = NULL; 05208 c1->_bridge = NULL; 05209 05210 /* \todo XXX here should check that cid_num is not NULL */ 05211 manager_event(EVENT_FLAG_CALL, "Unlink", 05212 "Channel1: %s\r\n" 05213 "Channel2: %s\r\n" 05214 "Uniqueid1: %s\r\n" 05215 "Uniqueid2: %s\r\n" 05216 "CallerID1: %s\r\n" 05217 "CallerID2: %s\r\n", 05218 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05219 ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name); 05220 05221 return res; 05222 }
| int ast_channel_cmpwhentohangup | ( | struct ast_channel * | chan, | |
| time_t | offset | |||
| ) |
Compare a offset with the settings of when to hang a channel up.
| chan | channel on which to check for hang up | |
| offset | offset in seconds from current time |
Definition at line 550 of file channel.c.
References ast_channel_cmpwhentohangup_tv().
00551 { 00552 struct timeval when = { offset, }; 00553 return ast_channel_cmpwhentohangup_tv(chan, when); 00554 }
| int ast_channel_cmpwhentohangup_tv | ( | struct ast_channel * | chan, | |
| struct timeval | offset | |||
| ) |
Compare a offset with when to hangup channel.
Compare a offset with the settings of when to hang a channel up.
Definition at line 535 of file channel.c.
References ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.
Referenced by ast_channel_cmpwhentohangup().
00536 { 00537 struct timeval whentohangup; 00538 00539 if (ast_tvzero(chan->whentohangup)) 00540 return ast_tvzero(offset) ? 0 : -1; 00541 00542 if (ast_tvzero(offset)) 00543 return 1; 00544 00545 whentohangup = ast_tvadd(offset, ast_tvnow()); 00546 00547 return ast_tvdiff_ms(whentohangup, chan->whentohangup); 00548 }
| int ast_channel_datastore_add | ( | struct ast_channel * | chan, | |
| struct ast_datastore * | datastore | |||
| ) |
Add a datastore to a channel.
| 0 | success | |
| non-zero | failure |
Definition at line 1485 of file channel.c.
References AST_LIST_INSERT_HEAD, and ast_channel::datastores.
Referenced by _macro_exec(), acf_iaxvar_write(), acf_odbc_read(), add_features_datastores(), add_to_agi(), ast_iax2_new(), audiohook_volume_get(), authenticate_reply(), dial_exec_full(), dundi_query_read(), enable_jack_hook(), enum_query_read(), get_lock(), gosub_exec(), lua_get_state(), pbx_builtin_raise_exception(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), shared_write(), smdi_msg_retrieve_read(), socket_process(), speech_create(), speex_write(), try_calling(), and volume_write().
01486 { 01487 int res = 0; 01488 01489 AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry); 01490 01491 return res; 01492 }
| struct ast_datastore* ast_channel_datastore_alloc | ( | const struct ast_datastore_info * | info, | |
| const char * | uid | |||
| ) | [read] |
Create a channel data store object.
Definition at line 1458 of file channel.c.
References ast_datastore_alloc.
01459 { 01460 return ast_datastore_alloc(info, uid); 01461 }
| struct ast_datastore* ast_channel_datastore_find | ( | struct ast_channel * | chan, | |
| const struct ast_datastore_info * | info, | |||
| const char * | uid | |||
| ) | [read] |
Find a datastore on a channel.
The datastore returned from this function must not be used if the reference to the channel is released.
| pointer | to the datastore if found | |
| NULL | if not found |
Definition at line 1499 of file channel.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel::datastores, ast_datastore::info, and ast_datastore::uid.
Referenced by _macro_exec(), acf_exception_read(), acf_fetch(), acf_iaxvar_read(), acf_iaxvar_write(), add_agi_cmd(), add_features_datastores(), add_to_agi(), attended_transfer_occurred(), audiohook_volume_callback(), audiohook_volume_get(), builtin_atxfer(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), dundi_result_read(), enable_jack_hook(), enum_result_read(), exec_odbcfinish(), find_speech(), func_inheritance_write(), get_agi_cmd(), get_lock(), gosub_exec(), iax2_call(), jack_hook_callback(), local_read(), local_write(), lock_fixup(), lua_get_state(), manage_parkinglot(), park_exec_full(), pbx_builtin_raise_exception(), pop_exec(), queue_transfer_fixup(), return_exec(), shared_read(), shared_write(), smdi_msg_read(), speech_background(), speech_destroy(), speex_callback(), speex_read(), speex_write(), stop_mixmonitor_exec(), try_calling(), unlock_read(), volume_callback(), and volume_write().
01500 { 01501 struct ast_datastore *datastore = NULL; 01502 01503 if (info == NULL) 01504 return NULL; 01505 01506 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) { 01507 if (datastore->info != info) { 01508 continue; 01509 } 01510 01511 if (uid == NULL) { 01512 /* matched by type only */ 01513 break; 01514 } 01515 01516 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) { 01517 /* Matched by type AND uid */ 01518 break; 01519 } 01520 } 01521 AST_LIST_TRAVERSE_SAFE_END; 01522 01523 return datastore; 01524 }
| int ast_channel_datastore_free | ( | struct ast_datastore * | datastore | ) |
Free a channel data store object.
Definition at line 1463 of file channel.c.
References ast_datastore_free().
01464 { 01465 return ast_datastore_free(datastore); 01466 }
| int ast_channel_datastore_inherit | ( | struct ast_channel * | from, | |
| struct ast_channel * | to | |||
| ) |
Inherit datastores from a parent to a child.
Definition at line 1468 of file channel.c.
References ast_datastore_alloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_channel::datastores, ast_datastore_info::duplicate, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.
Referenced by __ast_request_and_dial(), ast_call_forward(), dial_exec_full(), do_forward(), findmeexec(), local_call(), ring_entry(), and wait_for_answer().
01469 { 01470 struct ast_datastore *datastore = NULL, *datastore2; 01471 01472 AST_LIST_TRAVERSE(&from->datastores, datastore, entry) { 01473 if (datastore->inheritance > 0) { 01474 datastore2 = ast_datastore_alloc(datastore->info, datastore->uid); 01475 if (datastore2) { 01476 datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL; 01477 datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1; 01478 AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry); 01479 } 01480 } 01481 } 01482 return 0; 01483 }
| int ast_channel_datastore_remove | ( | struct ast_channel * | chan, | |
| struct ast_datastore * | datastore | |||
| ) |
Remove a datastore from a channel.
| 0 | success | |
| non-zero | failure |
Definition at line 1494 of file channel.c.
References AST_LIST_REMOVE, and ast_channel::datastores.
Referenced by acf_fetch(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), exec_odbcfinish(), lua_get_state(), queue_transfer_fixup(), speech_background(), speech_destroy(), speex_write(), and try_calling().
01495 { 01496 return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1; 01497 }
| int ast_channel_defer_dtmf | ( | struct ast_channel * | chan | ) |
Set defer DTMF flag on channel.
Defers DTMF
Defer DTMF so that you only read things like hangups and audio. Returns non-zero if channel was already DTMF-deferred or 0 if channel is just now being DTMF-deferred
Definition at line 1139 of file channel.c.
References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.
Referenced by __adsi_transmit_messages(), and find_cache().
01140 { 01141 int pre = 0; 01142 01143 if (chan) { 01144 pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF); 01145 ast_set_flag(chan, AST_FLAG_DEFER_DTMF); 01146 } 01147 return pre; 01148 }
| int ast_channel_early_bridge | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1 | |||
| ) |
Bridge two channels together (early).
Bridge two channels together (early)
| c0 | first channel to bridge | |
| c1 | second channel to bridge Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet. |
Definition at line 4875 of file channel.c.
References ast_channel_tech::early_bridge, and ast_channel::tech.
Referenced by dial_exec_full(), and wait_for_answer().
04876 { 04877 /* Make sure we can early bridge, if not error out */ 04878 if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge))) 04879 return -1; 04880 04881 return c0->tech->early_bridge(c0, c1); 04882 }
| void ast_channel_free | ( | struct ast_channel * | chan | ) |
Free a channel structure.
Definition at line 1345 of file channel.c.
References ast_channel::alertpipe, ast_app_group_discard(), ast_cdr_discard(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), ast_datastore_free(), ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), AST_FLAG_IN_CHANNEL_LIST, ast_free, ast_frfree, ast_jb_destroy(), AST_LIST_REMOVE_HEAD, ast_log(), AST_MAX_FDS, ast_moh_cleanup(), ast_mutex_destroy(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_test_flag, ast_timer_close(), ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, ast_channel::cid, ast_channel::datastores, f, free, free_cid(), ast_channel::lock_dont_use, LOG_WARNING, ast_channel::monitor, ast_channel::music_state, ast_channel::name, name, ast_channel::pbx, ast_channel::readq, ast_channel::readtrans, ast_channel::sched, sched_context_destroy(), ast_channel_monitor::stop, ast_channel::tech_pvt, ast_channel::timer, ast_channel::varshead, 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(), rotate_file(), sendmail(), and sendpage().
01346 { 01347 int fd; 01348 #ifdef HAVE_EPOLL 01349 int i; 01350 #endif 01351 struct ast_var_t *vardata; 01352 struct ast_frame *f; 01353 struct varshead *headp; 01354 struct ast_datastore *datastore = NULL; 01355 char name[AST_CHANNEL_NAME], *dashptr; 01356 int inlist; 01357 01358 headp=&chan->varshead; 01359 01360 inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01361 if (inlist) { 01362 AST_RWLIST_WRLOCK(&channels); 01363 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01364 ast_debug(1, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01365 } 01366 /* Lock and unlock the channel just to be sure nobody has it locked still 01367 due to a reference retrieved from the channel list. */ 01368 ast_channel_lock(chan); 01369 ast_channel_unlock(chan); 01370 } 01371 01372 /* Get rid of each of the data stores on the channel */ 01373 while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry))) 01374 /* Free the data store */ 01375 ast_datastore_free(datastore); 01376 01377 /* Lock and unlock the channel just to be sure nobody has it locked still 01378 due to a reference that was stored in a datastore. (i.e. app_chanspy) */ 01379 ast_channel_lock(chan); 01380 ast_channel_unlock(chan); 01381 01382 if (chan->tech_pvt) { 01383 ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); 01384 ast_free(chan->tech_pvt); 01385 } 01386 01387 if (chan->sched) 01388 sched_context_destroy(chan->sched); 01389 01390 ast_copy_string(name, chan->name, sizeof(name)); 01391 if ((dashptr = strrchr(name, '-'))) { 01392 *dashptr = '\0'; 01393 } 01394 01395 /* Stop monitoring */ 01396 if (chan->monitor) 01397 chan->monitor->stop( chan, 0 ); 01398 01399 /* If there is native format music-on-hold state, free it */ 01400 if (chan->music_state) 01401 ast_moh_cleanup(chan); 01402 01403 /* Free translators */ 01404 if (chan->readtrans) 01405 ast_translator_free_path(chan->readtrans); 01406 if (chan->writetrans) 01407 ast_translator_free_path(chan->writetrans); 01408 if (chan->pbx) 01409 ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); 01410 free_cid(&chan->cid); 01411 /* Close pipes if appropriate */ 01412 if ((fd = chan->alertpipe[0]) > -1) 01413 close(fd); 01414 if ((fd = chan->alertpipe[1]) > -1) 01415 close(fd); 01416 if (chan->timer) { 01417 ast_timer_close(chan->timer); 01418 } 01419 #ifdef HAVE_EPOLL 01420 for (i = 0; i < AST_MAX_FDS; i++) { 01421 if (chan->epfd_data[i]) 01422 free(chan->epfd_data[i]); 01423 } 01424 close(chan->epfd); 01425 #endif 01426 while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list))) 01427 ast_frfree(f); 01428 01429 /* loop over the variables list, freeing all data and deleting list items */ 01430 /* no need to lock the list, as the channel is already locked */ 01431 01432 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) 01433 ast_var_delete(vardata); 01434 01435 ast_app_group_discard(chan); 01436 01437 /* Destroy the jitterbuffer */ 01438 ast_jb_destroy(chan); 01439 01440 if (chan->cdr) { 01441 ast_cdr_discard(chan->cdr); 01442 chan->cdr = NULL; 01443 } 01444 01445 ast_mutex_destroy(&chan->lock_dont_use); 01446 01447 ast_string_field_free_memory(chan); 01448 ast_free(chan); 01449 if (inlist) 01450 AST_RWLIST_UNLOCK(&channels); 01451 01452 /* Queue an unknown state, because, while we know that this particular 01453 * instance is dead, we don't know the state of all other possible 01454 * instances. */ 01455 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 01456 }
| 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 4220 of file channel.c.
References ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), ast_var_t::entries, and ast_channel::varshead.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), begin_dial_channel(), dial_exec_full(), do_forward(), findmeexec(), ring_entry(), and wait_for_answer().
04221 { 04222 struct ast_var_t *current, *newvar; 04223 const char *varname; 04224 04225 AST_LIST_TRAVERSE(&parent->varshead, current, entries) { 04226 int vartype = 0; 04227 04228 varname = ast_var_full_name(current); 04229 if (!varname) 04230 continue; 04231 04232 if (varname[0] == '_') { 04233 vartype = 1; 04234 if (varname[1] == '_') 04235 vartype = 2; 04236 } 04237 04238 switch (vartype) { 04239 case 1: 04240 newvar = ast_var_assign(&varname[1], ast_var_value(current)); 04241 if (newvar) { 04242 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04243 ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar)); 04244 } 04245 break; 04246 case 2: 04247 newvar = ast_var_assign(varname, ast_var_value(current)); 04248 if (newvar) { 04249 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04250 ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar)); 04251 } 04252 break; 04253 default: 04254 ast_debug(1, "Not copying variable %s.\n", ast_var_name(current)); 04255 break; 04256 } 04257 } 04258 }
| 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 4118 of file channel.c.
References ast_channel_make_compatible_helper().
Referenced by action_bridge(), app_exec(), ast_channel_bridge(), bridge_exec(), check_compat(), dial_exec_full(), do_forward(), park_exec_full(), try_calling(), and wait_for_answer().
04119 { 04120 /* Some callers do not check return code, and we must try to set all call legs correctly */ 04121 int rc = 0; 04122 04123 /* Set up translation from the chan to the peer */ 04124 rc = ast_channel_make_compatible_helper(chan, peer); 04125 04126 if (rc < 0) 04127 return rc; 04128 04129 /* Set up translation from the peer to the chan */ 04130 rc = ast_channel_make_compatible_helper(peer, chan); 04131 04132 return rc; 04133 }
| static int ast_channel_make_compatible_helper | ( | struct ast_channel * | from, | |
| struct ast_channel * | to | |||
| ) | [static] |
Set up translation from one channel to another.
Definition at line 4077 of file channel.c.
References AST_FORMAT_AUDIO_MASK, 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(), LOG_WARNING, ast_channel::name, ast_channel::nativeformats, ast_channel::readformat, and ast_channel::writeformat.
Referenced by ast_channel_make_compatible().
04078 { 04079 int src; 04080 int dst; 04081 04082 if (from->readformat == to->writeformat && from->writeformat == to->readformat) { 04083 /* Already compatible! Moving on ... */ 04084 return 0; 04085 } 04086 04087 /* Set up translation from the 'from' channel to the 'to' channel */ 04088 src = from->nativeformats; 04089 dst = to->nativeformats; 04090 04091 /* If there's no audio in this call, don't bother with trying to find a translation path */ 04092 if ((src & AST_FORMAT_AUDIO_MASK) == 0 || (dst & AST_FORMAT_AUDIO_MASK) == 0) 04093 return 0; 04094 04095 if (ast_translator_best_choice(&dst, &src) < 0) { 04096 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", from->name, src, to->name, dst); 04097 return -1; 04098 } 04099 04100 /* if the best path is not 'pass through', then 04101 transcoding is needed; if desired, force transcode path 04102 to use SLINEAR between channels, but only if there is 04103 no direct conversion available */ 04104 if ((src != dst) && ast_opt_transcode_via_slin && 04105 (ast_translate_path_steps(dst, src) != 1)) 04106 dst = AST_FORMAT_SLINEAR; 04107 if (ast_set_read_format(from, dst) < 0) { 04108 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", from->name, dst); 04109 return -1; 04110 } 04111 if (ast_set_write_format(to, dst) < 0) { 04112 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", to->name, dst); 04113 return -1; 04114 } 04115 return 0; 04116 }
| 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 |
Definition at line 4135 of file channel.c.
References ast_channel::_bridge, ast_bridged_channel(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_log(), ast_null_frame, ast_queue_frame(), ast_channel_tech::get_base_channel, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::name, and ast_channel::tech.
Referenced by ast_async_goto(), ast_pickup_call(), attempt_transfer(), builtin_atxfer(), check_availability(), check_bridge(), check_goto_on_transfer(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), masq_park_call(), misdn_attempt_transfer(), pickup_do(), sip_park(), and skinny_transfer().
04136 { 04137 int res = -1; 04138 struct ast_channel *final_orig, *final_clone, *base; 04139 04140 retrymasq: 04141 final_orig = original; 04142 final_clone = clonechan; 04143 04144 ast_channel_lock(original); 04145 while (ast_channel_trylock(clonechan)) { 04146 ast_channel_unlock(original); 04147 usleep(1); 04148 ast_channel_lock(original); 04149 } 04150 04151 /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent) 04152 and if so, we don't really want to masquerade it, but its proxy */ 04153 if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original)) 04154 final_orig = original->_bridge; 04155 04156 if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan)) 04157 final_clone = clonechan->_bridge; 04158 04159 if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) { 04160 final_clone = base; 04161 } 04162 04163 if ((final_orig != original) || (final_clone != clonechan)) { 04164 /* Lots and lots of deadlock avoidance. The main one we're competing with 04165 * is ast_write(), which locks channels recursively, when working with a 04166 * proxy channel. */ 04167 if (ast_channel_trylock(final_orig)) { 04168 ast_channel_unlock(clonechan); 04169 ast_channel_unlock(original); 04170 goto retrymasq; 04171 } 04172 if (ast_channel_trylock(final_clone)) { 04173 ast_channel_unlock(final_orig); 04174 ast_channel_unlock(clonechan); 04175 ast_channel_unlock(original); 04176 goto retrymasq; 04177 } 04178 ast_channel_unlock(clonechan); 04179 ast_channel_unlock(original); 04180 original = final_orig; 04181 clonechan = final_clone; 04182 } 04183 04184 if (original == clonechan) { 04185 ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); 04186 ast_channel_unlock(clonechan); 04187 ast_channel_unlock(original); 04188 return -1; 04189 } 04190 04191 ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n", 04192 clonechan->name, original->name); 04193 if (original->masq) { 04194 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04195 original->masq->name, original->name); 04196 } else if (clonechan->masqr) { 04197 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04198 clonechan->name, clonechan->masqr->name); 04199 } else { 04200 original->masq = clonechan; 04201 clonechan->masqr = original; 04202 ast_queue_frame(original, &ast_null_frame); 04203 ast_queue_frame(clonechan, &ast_null_frame); 04204 ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name); 04205 res = 0; 04206 } 04207 04208 ast_channel_unlock(clonechan); 04209 ast_channel_unlock(original); 04210 04211 return res; 04212 }
| int ast_channel_queryoption | ( | struct ast_channel * | channel, | |
| int | option, | |||
| void * | data, | |||
| int * | datalen, | |||
| int | block | |||
| ) |
Checks the value of an option
Query the value of an option Works similarly to setoption except only reads the options.
Definition at line 5238 of file channel.c.
References ast_log(), errno, LOG_ERROR, ast_channel_tech::queryoption, and ast_channel::tech.
Referenced by ast_channel_get_t38_state().
05239 { 05240 if (!chan->tech->queryoption) { 05241 errno = ENOSYS; 05242 return -1; 05243 } 05244 05245 if (block) 05246 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 05247 05248 return chan->tech->queryoption(chan, option, data, datalen); 05249 }
| const char* ast_channel_reason2str | ( | int | reason | ) |
return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
| reason | The integer argument, usually taken from AST_CONTROL_ macros |
Definition at line 3663 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().
03664 { 03665 switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */ 03666 { 03667 case 0: 03668 return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)"; 03669 case AST_CONTROL_HANGUP: 03670 return "Hangup"; 03671 case AST_CONTROL_RING: 03672 return "Local Ring"; 03673 case AST_CONTROL_RINGING: 03674 return "Remote end Ringing"; 03675 case AST_CONTROL_ANSWER: 03676 return "Remote end has Answered"; 03677 case AST_CONTROL_BUSY: 03678 return "Remote end is Busy"; 03679 case AST_CONTROL_CONGESTION: 03680 return "Congestion (circuits busy)"; 03681 default: 03682 return "Unknown Reason!!"; 03683 } 03684 }
| int ast_channel_register | ( | const struct ast_channel_tech * | tech | ) |
Register a new telephony channel in Asterisk.
Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.
Definition at line 557 of file channel.c.
References ast_calloc, ast_debug, AST_LIST_INSERT_HEAD, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_channel_tech::description, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.
Referenced by load_module(), and unload_module().
00558 { 00559 struct chanlist *chan; 00560 00561 AST_RWLIST_WRLOCK(&channels); 00562 00563 AST_LIST_TRAVERSE(&backends, chan, list) { 00564 if (!strcasecmp(tech->type, chan->tech->type)) { 00565 ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type); 00566 AST_RWLIST_UNLOCK(&channels); 00567 return -1; 00568 } 00569 } 00570 00571 if (!(chan = ast_calloc(1, sizeof(*chan)))) { 00572 AST_RWLIST_UNLOCK(&channels); 00573 return -1; 00574 } 00575 chan->tech = tech; 00576 AST_LIST_INSERT_HEAD(&backends, chan, list); 00577 00578 ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description); 00579 00580 ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description); 00581 00582 AST_RWLIST_UNLOCK(&channels); 00583 return 0; 00584 }
| int ast_channel_sendhtml | ( | struct ast_channel * | channel, | |
| int | subclass, | |||
| const char * | data, | |||
| int | datalen | |||
| ) |
Sends HTML on given channel
Send HTML or URL on link. Returns 0 on success or -1 on failure
Definition at line 4064 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().
04065 { 04066 if (chan->tech->send_html) 04067 return chan->tech->send_html(chan, subclass, data, datalen); 04068 return -1; 04069 }
| int ast_channel_sendurl | ( | struct ast_channel * | channel, | |
| const char * | url | |||
| ) |
Sends a URL on a given link
Send URL on link. Returns 0 on success or -1 on failure
Definition at line 4071 of file channel.c.
References ast_channel_sendhtml(), and AST_HTML_URL.
Referenced by dial_exec_full(), sendurl_exec(), and try_calling().
04072 { 04073 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1); 04074 }
| void ast_channel_set_fd | ( | struct ast_channel * | chan, | |
| int | which, | |||
| int | fd | |||
| ) |
Set the file descriptor on the channel
Definition at line 1527 of file channel.c.
References ast_calloc, ast_epoll_data::chan, ast_channel::fds, free, and ast_epoll_data::which.
Referenced by __ast_channel_alloc_ap(), __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), alsa_new(), ast_deactivate_generator(), ast_do_masquerade(), dahdi_new(), gtalk_new(), jingle_new(), mgcp_new(), misdn_new(), nbs_new(), oss_new(), phone_new(), setformat(), sip_new(), skinny_new(), start_rtp(), and swap_subs().
01528 { 01529 #ifdef HAVE_EPOLL 01530 struct epoll_event ev; 01531 struct ast_epoll_data *aed = NULL; 01532 01533 if (chan->fds[which] > -1) { 01534 epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev); 01535 aed = chan->epfd_data[which]; 01536 } 01537 01538 /* If this new fd is valid, add it to the epoll */ 01539 if (fd > -1) { 01540 if (!aed && (!(aed = ast_calloc(1, sizeof(*aed))))) 01541 return; 01542 01543 chan->epfd_data[which] = aed; 01544 aed->chan = chan; 01545 aed->which = which; 01546 01547 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01548 ev.data.ptr = aed; 01549 epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev); 01550 } else if (aed) { 01551 /* We don't have to keep around this epoll data structure now */ 01552 free(aed); 01553 chan->epfd_data[which] = NULL; 01554 } 01555 #endif 01556 chan->fds[which] = fd; 01557 return; 01558 }
| int ast_channel_setoption | ( | struct ast_channel * | channel, | |
| int | option, | |||
| void * | data, | |||
| int | datalen, | |||
| int | block | |||
| ) |
Sets an option on a channel.
Sets an option on a channel
| channel | channel to set options on | |
| option | option to change | |
| data | data specific to option | |
| datalen | length of the data | |
| block | blocking or not Set an option on a channel (see frame.h), optionally blocking awaiting the reply Returns 0 on success and -1 on failure |
Definition at line 5225 of file channel.c.
References ast_log(), errno, LOG_ERROR, ast_channel_tech::setoption, and ast_channel::tech.
Referenced by ast_bridge_call(), common_exec(), conf_run(), dahdi_hangup(), dial_exec_full(), func_channel_write(), handle_tddmode(), play_record_review(), reset_volumes(), rpt(), rpt_exec(), set_listen_volume(), set_talk_volume(), try_calling(), and vm_forwardoptions().
05226 { 05227 if (!chan->tech->setoption) { 05228 errno = ENOSYS; 05229 return -1; 05230 } 05231 05232 if (block) 05233 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 05234 05235 return chan->tech->setoption(chan, option, data, datalen); 05236 }
| void ast_channel_setwhentohangup | ( | struct ast_channel * | chan, | |
| time_t | offset | |||
| ) |
Set when to hang a channel up.
| chan | channel on which to check for hang up | |
| offset | offset in seconds relative to the current time of when to hang up |
Definition at line 528 of file channel.c.
References ast_channel_setwhentohangup_tv().
00529 { 00530 struct timeval when = { offset, }; 00531 ast_channel_setwhentohangup_tv(chan, when); 00532 }
| void ast_channel_setwhentohangup_tv | ( | struct ast_channel * | chan, | |
| struct timeval | offset | |||
| ) |
Set when to hangup channel.
Set when to hang a channel up.
Definition at line 521 of file channel.c.
References ast_null_frame, ast_queue_frame(), ast_tvadd(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.
Referenced by action_timeout(), ast_channel_setwhentohangup(), handle_autohangup(), and timeout_write().
00522 { 00523 chan->whentohangup = ast_tvzero(offset) ? offset : ast_tvadd(offset, ast_tvnow()); 00524 ast_queue_frame(chan, &ast_null_frame); 00525 return; 00526 }
| struct ast_silence_generator* ast_channel_start_silence_generator | ( | struct ast_channel * | chan | ) | [read] |
Starts a silence generator on the given channel.
| chan | The channel to generate silence on |
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 5558 of file channel.c.
References ast_activate_generator(), ast_calloc, ast_debug, AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, and ast_channel::writeformat.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), channel_spy(), record_exec(), and TransferCallStep1().
05559 { 05560 struct ast_silence_generator *state; 05561 05562 if (!(state = ast_calloc(1, sizeof(*state)))) { 05563 return NULL; 05564 } 05565 05566 state->old_write_format = chan->writeformat; 05567 05568 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { 05569 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n"); 05570 ast_free(state); 05571 return NULL; 05572 } 05573 05574 ast_activate_generator(chan, &silence_generator, state); 05575 05576 ast_debug(1, "Started silence generator on '%s'\n", chan->name); 05577 05578 return state; 05579 }
| 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 5581 of file channel.c.
References ast_deactivate_generator(), ast_debug, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_channel::name, and ast_silence_generator::old_write_format.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), channel_spy(), HandleCallOutgoing(), key_dial_page(), record_exec(), and unistim_hangup().
05582 { 05583 if (!state) 05584 return; 05585 05586 ast_deactivate_generator(chan); 05587 05588 ast_debug(1, "Stopped silence generator on '%s'\n", chan->name); 05589 05590 if (ast_set_write_format(chan, state->old_write_format) < 0) 05591 ast_log(LOG_ERROR, "Could not return write format to its original state\n"); 05592 05593 ast_free(state); 05594 }
| int ast_channel_supports_html | ( | struct ast_channel * | channel | ) |
Checks for HTML support on a channel
Returns 0 if channel does not support HTML or non-zero if it does
Definition at line 4059 of file channel.c.
References ast_channel_tech::send_html, and ast_channel::tech.
Referenced by dial_exec_full(), sendurl_exec(), and try_calling().
| void ast_channel_undefer_dtmf | ( | struct ast_channel * | chan | ) |
Unset defer DTMF flag on channel.
Undo defer. ast_read will return any dtmf characters that were queued
Definition at line 1151 of file channel.c.
References ast_clear_flag, and AST_FLAG_DEFER_DTMF.
Referenced by __adsi_transmit_messages(), find_cache(), and rpt_call().
01152 { 01153 if (chan) 01154 ast_clear_flag(chan, AST_FLAG_DEFER_DTMF); 01155 }
| void ast_channel_unregister | ( | const struct ast_channel_tech * | tech | ) |
Unregister channel driver.
Unregister a channel technology.
Definition at line 587 of file channel.c.
References ast_debug, ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::tech, and ast_channel_tech::type.
Referenced by __unload_module(), load_module(), and unload_module().
00588 { 00589 struct chanlist *chan; 00590 00591 ast_debug(1, "Unregistering channel type '%s'\n", tech->type); 00592 00593 AST_RWLIST_WRLOCK(&channels); 00594 00595 AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) { 00596 if (chan->tech == tech) { 00597 AST_LIST_REMOVE_CURRENT(list); 00598 ast_free(chan); 00599 ast_verb(2, "Unregistered channel type '%s'\n", tech->type); 00600 break; 00601 } 00602 } 00603 AST_LIST_TRAVERSE_SAFE_END; 00604 00605 AST_RWLIST_UNLOCK(&channels); 00606 }
| struct ast_channel* ast_channel_walk_locked | ( | const struct ast_channel * | prev | ) | [read] |
Browse channels in use.
Browse channels in use Browse the channels currently in use.
Definition at line 1265 of file channel.c.
References channel_find_locked().
Referenced by action_coreshowchannels(), action_status(), ast_complete_channels(), ast_pickup_call(), conf_exec(), func_channels_read(), handle_chanlist(), handle_core_set_debug_channel(), next_channel(), pickup_by_exten(), and pickup_by_mark().
01266 { 01267 return channel_find_locked(prev, NULL, 0, NULL, NULL); 01268 }
| void ast_channels_init | ( | void | ) |
Provided by channel.c
Definition at line 5479 of file channel.c.
References ARRAY_LEN, ast_cli_register_multiple(), and cli_channel.
Referenced by main().
05480 { 05481 ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel)); 05482 }
| struct ast_variable* ast_channeltype_list | ( | void | ) | [read] |
return an ast_variable list of channeltypes
Definition at line 185 of file channel.c.
References AST_LIST_TRAVERSE, ast_variable_new(), ast_channel_tech::description, chanlist::tech, ast_channel_tech::type, and var.
00186 { 00187 struct chanlist *cl; 00188 struct ast_variable *var=NULL, *prev = NULL; 00189 AST_LIST_TRAVERSE(&backends, cl, list) { 00190 if (prev) { 00191 if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, ""))) 00192 prev = prev->next; 00193 } else { 00194 var = ast_variable_new(cl->tech->type, cl->tech->description, ""); 00195 prev = var; 00196 } 00197 } 00198 return var; 00199 }
| int ast_check_hangup | ( | struct ast_channel * | chan | ) |
Checks to see if a channel is needing hang up.
Check to see if a channel is needing hang up.
Definition at line 461 of file channel.c.
References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.
Referenced by __ast_pbx_run(), __ast_read(), _macro_exec(), action_redirect(), agent_indicate(), agi_exec(), agi_handle_command(), announce_thread(), ast_bridge_call(), ast_bridge_call_thread(), ast_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_feature_request_and_dial(), ast_indicate_data(), ast_raw_answer(), ast_readstring_full(), ast_recvtext(), ast_rtp_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), autoservice_run(), bridge_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_bridge(), common_exec(), conf_play(), conf_run(), dahdi_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), findmeexec(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), rpt(), rpt_exec(), run_ras(), try_calling(), and wait_for_answer().
00462 { 00463 if (chan->_softhangup) /* yes if soft hangup flag set */ 00464 return 1; 00465 if (ast_tvzero(chan->whentohangup)) /* no if no hangup scheduled */ 00466 return 0; 00467 if (ast_tvdiff_ms(chan->whentohangup, ast_tvnow()) > 0) /* no if hangup time has not come yet. */ 00468 return 0; 00469 chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */ 00470 return 1; 00471 }
| static int ast_check_hangup_locked | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 473 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().
Referenced by ast_channel_bridge().
00474 { 00475 int res; 00476 ast_channel_lock(chan); 00477 res = ast_check_hangup(chan); 00478 ast_channel_unlock(chan); 00479 return res; 00480 }
| void ast_deactivate_generator | ( | struct ast_channel * | chan | ) |
Deactivate an active generator
Definition at line 1907 of file channel.c.
References ast_channel_lock, ast_channel_set_fd(), ast_channel_unlock, ast_clear_flag, AST_FLAG_WRITE_INT, AST_GENERATOR_FD, ast_settimeout(), ast_channel::generator, ast_channel::generatordata, and ast_generator::release.
Referenced by __ast_read(), app_exec(), ast_channel_stop_silence_generator(), ast_openstream_full(), ast_playtones_stop(), ast_quiet_chan(), ast_read_generator_actions(), ast_tonepair_stop(), ast_write(), cb_events(), channel_spy(), dial_exec_full(), generator_force(), local_ast_moh_stop(), old_milliwatt_exec(), transmit_audio(), and wait_for_answer().
01908 { 01909 ast_channel_lock(chan); 01910 if (chan->generatordata) { 01911 if (chan->generator && chan->generator->release) 01912 chan->generator->release(chan, chan->generatordata); 01913 chan->generatordata = NULL; 01914 chan->generator = NULL; 01915 ast_channel_set_fd(chan, AST_GENERATOR_FD, -1); 01916 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 01917 ast_settimeout(chan, 0, NULL, NULL); 01918 } 01919 ast_channel_unlock(chan); 01920 }
| int ast_do_masquerade | ( | struct ast_channel * | original | ) |
Masquerade a channel.
Start masquerading a channel XXX This is a seriously whacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX.
Definition at line 4311 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_NAME, ast_channel_set_fd(), ast_channel_unlock, ast_copy_string(), ast_debug, AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_GENERATOR_FD, ast_indicate(), AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MAX_FDS, ast_null_frame, ast_queue_frame(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), AST_SOFTHANGUP_DEV, ast_state2str(), ast_string_field_set, ast_test_flag, AST_TIMING_FD, ast_channel::blocker, ast_channel::cdr, ast_datastore_info::chan_fixup, ast_channel::cid, clone_variables(), ast_datastore::data, ast_channel::datastores, errno, EVENT_FLAG_CALL, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_channel::hangupcause, ast_datastore::info, ast_channel::language, language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::musicclass, musicclass, name, ast_channel::name, ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::readq, report_new_callerid(), ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, ast_channel::uniqueid, ast_channel::visible_indication, and ast_channel::writeformat.
Referenced by __ast_read(), ast_async_goto(), ast_hangup(), ast_waitfor_nandfds(), ast_write(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), sip_park(), and sip_park_thread().
04312 { 04313 int x,i; 04314 int res=0; 04315 int origstate; 04316 struct ast_frame *current; 04317 const struct ast_channel_tech *t; 04318 void *t_pvt; 04319 struct ast_callerid tmpcid; 04320 struct ast_channel *clonechan = original->masq; 04321 struct ast_cdr *cdr; 04322 int rformat = original->readformat; 04323 int wformat = original->writeformat; 04324 char newn[AST_CHANNEL_NAME]; 04325 char orig[AST_CHANNEL_NAME]; 04326 char masqn[AST_CHANNEL_NAME]; 04327 char zombn[AST_CHANNEL_NAME]; 04328 04329 ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", 04330 clonechan->name, clonechan->_state, original->name, original->_state); 04331 04332 manager_event(EVENT_FLAG_CALL, "Masquerade", "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n", 04333 clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state)); 04334 04335 /* XXX This operation is a bit odd. We're essentially putting the guts of 04336 * the clone channel into the original channel. Start by killing off the 04337 * original channel's backend. While the features are nice, which is the 04338 * reason we're keeping it, it's still awesomely weird. XXX */ 04339 04340 /* We need the clone's lock, too */ 04341 ast_channel_lock(clonechan); 04342 04343 ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clonechan->name, &clonechan->lock_dont_use); 04344 04345 /* Having remembered the original read/write formats, we turn off any translation on either 04346 one */ 04347 free_translation(clonechan); 04348 free_translation(original); 04349 04350 04351 /* Unlink the masquerade */ 04352 original->masq = NULL; 04353 clonechan->masqr = NULL; 04354 04355 /* Save the original name */ 04356 ast_copy_string(orig, original->name, sizeof(orig)); 04357 /* Save the new name */ 04358 ast_copy_string(newn, clonechan->name, sizeof(newn)); 04359 /* Create the masq name */ 04360 snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn); 04361 04362 /* Copy the name from the clone channel */ 04363 ast_string_field_set(original, name, newn); 04364 04365 /* Mangle the name of the clone channel */ 04366 ast_string_field_set(clonechan, name, masqn); 04367 04368 /* Notify any managers of the change, first the masq then the other */ 04369 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clonechan->uniqueid); 04370 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); 04371 04372 /* Swap the technologies */ 04373 t = original->tech; 04374 original->tech = clonechan->tech; 04375 clonechan->tech = t; 04376 04377 /* Swap the cdrs */ 04378 cdr = original->cdr; 04379 original->cdr = clonechan->cdr; 04380 clonechan->cdr = cdr; 04381 04382 t_pvt = original->tech_pvt; 04383 original->tech_pvt = clonechan->tech_pvt; 04384 clonechan->tech_pvt = t_pvt; 04385 04386 /* Swap the alertpipes */ 04387 for (i = 0; i < 2; i++) { 04388 x = original->alertpipe[i]; 04389 original->alertpipe[i] = clonechan->alertpipe[i]; 04390 clonechan->alertpipe[i] = x; 04391 } 04392 04393 /* 04394 * Swap the readq's. The end result should be this: 04395 * 04396 * 1) All frames should be on the new (original) channel. 04397 * 2) Any frames that were already on the new channel before this 04398 * masquerade need to be at the end of the readq, after all of the 04399 * frames on the old (clone) channel. 04400 * 3) The alertpipe needs to get poked for every frame that was already 04401 * on the new channel, since we are now using the alert pipe from the 04402 * old (clone) channel. 04403 */ 04404 { 04405 AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq; 04406 AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL); 04407 04408 AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list); 04409 AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list); 04410 04411 while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) { 04412 AST_LIST_INSERT_TAIL(&original->readq, current, frame_list); 04413 if (original->alertpipe[1] > -1) { 04414 int poke = 0; 04415 04416 if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) { 04417 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 04418 } 04419 } 04420 } 04421 } 04422 04423 /* Swap the raw formats */ 04424 x = original->rawreadformat; 04425 original->rawreadformat = clonechan->rawreadformat; 04426 clonechan->rawreadformat = x; 04427 x = original->rawwriteformat; 04428 original->rawwriteformat = clonechan->rawwriteformat; 04429 clonechan->rawwriteformat = x; 04430 04431 clonechan->_softhangup = AST_SOFTHANGUP_DEV; 04432 04433 /* And of course, so does our current state. Note we need not 04434 call ast_setstate since the event manager doesn't really consider 04435 these separate. We do this early so that the clone has the proper 04436 state of the original channel. */ 04437 origstate = original->_state; 04438 original->_state = clonechan->_state; 04439 clonechan->_state = origstate; 04440 04441 if (clonechan->tech->fixup){ 04442 res = clonechan->tech->fixup(original, clonechan); 04443 if (res) 04444 ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name); 04445 } 04446 04447 /* Start by disconnecting the original's physical side */ 04448 if (clonechan->tech->hangup) 04449 res = clonechan->tech->hangup(clonechan); 04450 if (res) { 04451 ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n"); 04452 ast_channel_unlock(clonechan); 04453 return -1; 04454 } 04455 04456 snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); 04457 /* Mangle the name of the clone channel */ 04458 ast_string_field_set(clonechan, name, zombn); 04459 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clonechan->uniqueid); 04460 04461 /* Update the type. */ 04462 t_pvt = original->monitor; 04463 original->monitor = clonechan->monitor; 04464 clonechan->monitor = t_pvt; 04465 04466 /* Keep the same language. */ 04467 ast_string_field_set(original, language, clonechan->language); 04468 /* Copy the FD's other than the generator fd */ 04469 for (x = 0; x < AST_MAX_FDS; x++) { 04470 if (x != AST_GENERATOR_FD) 04471 ast_channel_set_fd(original, x, clonechan->fds[x]); 04472 } 04473 04474 ast_app_group_update(clonechan, original); 04475 04476 /* Move data stores over */ 04477 if (AST_LIST_FIRST(&clonechan->datastores)) { 04478 struct ast_datastore *ds; 04479 /* We use a safe traversal here because some fixup routines actually 04480 * remove the datastore from the list and free them. 04481 */ 04482 AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) { 04483 if (ds->info->chan_fixup) 04484 ds->info->chan_fixup(ds->data, clonechan, original); 04485 } 04486 AST_LIST_TRAVERSE_SAFE_END; 04487 AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry); 04488 } 04489 04490 clone_variables(original, clonechan); 04491 /* Presense of ADSI capable CPE follows clone */ 04492 original->adsicpe = clonechan->adsicpe; 04493 /* Bridge remains the same */ 04494 /* CDR fields remain the same */ 04495 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */ 04496 /* Application and data remain the same */ 04497 /* Clone exception becomes real one, as with fdno */ 04498 ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION)); 04499 original->fdno = clonechan->fdno; 04500 /* Schedule context remains the same */ 04501 /* Stream stuff stays the same */ 04502 /* Keep the original state. The fixup code will need to work with it most likely */ 04503 04504 /* Just swap the whole structures, nevermind the allocations, they'll work themselves 04505 out. */ 04506 tmpcid = original->cid; 04507 original->cid = clonechan->cid; 04508 clonechan->cid = tmpcid; 04509 report_new_callerid(original); 04510 04511 /* Restore original timing file descriptor */ 04512 ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd); 04513 04514 /* Our native formats are different now */ 04515 original->nativeformats = clonechan->nativeformats; 04516 04517 /* Context, extension, priority, app data, jump table, remain the same */ 04518 /* pvt switches. pbx stays the same, as does next */ 04519 04520 /* Set the write format */ 04521 ast_set_write_format(original, wformat); 04522 04523 /* Set the read format */ 04524 ast_set_read_format(original, rformat); 04525 04526 /* Copy the music class */ 04527 ast_string_field_set(original, musicclass, clonechan->musicclass); 04528 04529 ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat); 04530 04531 /* Okay. Last thing is to let the channel driver know about all this mess, so he 04532 can fix up everything as best as possible */ 04533 if (original->tech->fixup) { 04534 res = original->tech->fixup(clonechan, original); 04535 if (res) { 04536 ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n", 04537 original->tech->type, original->name); 04538 ast_channel_unlock(clonechan); 04539 return -1; 04540 } 04541 } else 04542 ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n", 04543 original->tech->type, original->name); 04544 04545 /* 04546 * If an indication is currently playing, maintain it on the channel 04547 * that is taking the place of original 04548 * 04549 * This is needed because the masquerade is swapping out in the internals 04550 * of this channel, and the new channel private data needs to be made 04551 * aware of the current visible indication (RINGING, CONGESTION, etc.) 04552 */ 04553 if (original->visible_indication) { 04554 ast_indicate(original, original->visible_indication); 04555 } 04556 04557 /* Now, at this point, the "clone" channel is totally F'd up. We mark it as 04558 a zombie so nothing tries to touch it. If it's already been marked as a 04559 zombie, then free it now (since it already is considered invalid). */ 04560 if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) { 04561 ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name); 04562 ast_channel_unlock(clonechan); 04563 manager_event(EVENT_FLAG_CALL, "Hangup", 04564 "Channel: %s\r\n" 04565 "Uniqueid: %s\r\n" 04566 "Cause: %d\r\n" 04567 "Cause-txt: %s\r\n", 04568 clonechan->name, 04569 clonechan->uniqueid, 04570 clonechan->hangupcause, 04571 ast_cause2str(clonechan->hangupcause) 04572 ); 04573 ast_channel_free(clonechan); 04574 } else { 04575 ast_debug(1, "Released clone lock on '%s'\n", clonechan->name); 04576 ast_set_flag(clonechan, AST_FLAG_ZOMBIE); 04577 ast_queue_frame(clonechan, &ast_null_frame); 04578 ast_channel_unlock(clonechan); 04579 } 04580 04581 /* Signal any blocker */ 04582 if (ast_test_flag(original, AST_FLAG_BLOCKING)) 04583 pthread_kill(original->blocker, SIGURG); 04584 ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state); 04585 return 0; 04586 }
| static enum ast_bridge_result ast_generic_bridge | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1, | |||
| struct ast_bridge_config * | config, | |||
| struct ast_frame ** | fo, | |||
| struct ast_channel ** | rc, | |||
| struct timeval | bridge_end | |||
| ) | [static] |
Definition at line 4694 of file channel.c.
References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_IGNORE_SIGS, AST_BRIDGE_RETRY, AST_CONTROL_HOLD, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_debug, AST_FEATURE_WARNING_ACTIVE, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_indicate_data(), ast_jb_do_usecheck(), ast_jb_empty_and_reset(), ast_jb_get_and_deliver(), ast_jb_get_when_to_wakeup(), ast_jb_put(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_waitfor_n(), ast_write(), ast_frame::data, ast_frame::datalen, f, ast_bridge_config::feature_timer, ast_bridge_config::flags, ast_frame::frametype, ast_channel::name, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_bridge_config::partialfeature_timer, ast_frame::ptr, ast_frame::subclass, ast_channel::tech_pvt, and ast_bridge_config::timelimit.
Referenced by ast_channel_bridge().
04697 { 04698 /* Copy voice back and forth between the two channels. */ 04699 struct ast_channel *cs[3]; 04700 struct ast_frame *f; 04701 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 04702 int o0nativeformats; 04703 int o1nativeformats; 04704 int watch_c0_dtmf; 04705 int watch_c1_dtmf; 04706 void *pvt0, *pvt1; 04707 /* Indicates whether a frame was queued into a jitterbuffer */ 04708 int frame_put_in_jb = 0; 04709 int jb_in_use; 04710 int to; 04711 04712 cs[0] = c0; 04713 cs[1] = c1; 04714 pvt0 = c0->tech_pvt; 04715 pvt1 = c1->tech_pvt; 04716 o0nativeformats = c0->nativeformats; 04717 o1nativeformats = c1->nativeformats; 04718 watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0; 04719 watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1; 04720 04721 /* Check the need of a jitterbuffer for each channel */ 04722 jb_in_use = ast_jb_do_usecheck(c0, c1); 04723 if (jb_in_use) 04724 ast_jb_empty_and_reset(c0, c1); 04725 04726 ast_poll_channel_add(c0, c1); 04727 04728 if (config->feature_timer > 0 && ast_tvzero(config->nexteventts)) { 04729 /* calculate when the bridge should possibly break 04730 * if a partial feature match timed out */ 04731 config->partialfeature_timer = ast_tvadd(ast_tvnow(), ast_samp2tv(config->feature_timer, 1000)); 04732 } else { 04733 memset(&config->partialfeature_timer, 0, sizeof(config->partialfeature_timer)); 04734 } 04735 04736 for (;;) { 04737 struct ast_channel *who, *other; 04738 04739 if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) || 04740 (o0nativeformats != c0->nativeformats) || 04741 (o1nativeformats != c1->nativeformats)) { 04742 /* Check for Masquerade, codec changes, etc */ 04743 res = AST_BRIDGE_RETRY; 04744 break; 04745 } 04746 if (bridge_end.tv_sec) { 04747 to = ast_tvdiff_ms(bridge_end, ast_tvnow()); 04748 if (to <= 0) { 04749 if (config->timelimit) { 04750 res = AST_BRIDGE_RETRY; 04751 /* generic bridge ending to play warning */ 04752 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 04753 } else { 04754 res = AST_BRIDGE_COMPLETE; 04755 } 04756 break; 04757 } 04758 } else { 04759 /* If a feature has been started and the bridge is configured to 04760 * to not break, leave the channel bridge when the feature timer 04761 * time has elapsed so the DTMF will be sent to the other side. 04762 */ 04763 if (!ast_tvzero(config->partialfeature_timer)) { 04764 int diff = ast_tvdiff_ms(config->partialfeature_timer, ast_tvnow()); 04765 if (diff <= 0) { 04766 res = AST_BRIDGE_RETRY; 04767 break; 04768 } 04769 } 04770 to = -1; 04771 } 04772 /* Calculate the appropriate max sleep interval - in general, this is the time, 04773 left to the closest jb delivery moment */ 04774 if (jb_in_use) 04775 to = ast_jb_get_when_to_wakeup(c0, c1, to); 04776 who = ast_waitfor_n(cs, 2, &to); 04777 if (!who) { 04778 /* No frame received within the specified timeout - check if we have to deliver now */ 04779 if (jb_in_use) 04780 ast_jb_get_and_deliver(c0, c1); 04781 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 04782 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04783 c0->_softhangup = 0; 04784 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04785 c1->_softhangup = 0; 04786 c0->_bridge = c1; 04787 c1->_bridge = c0; 04788 } 04789 continue; 04790 } 04791 f = ast_read(who); 04792 if (!f) { 04793 *fo = NULL; 04794 *rc = who; 04795 ast_debug(1, "Didn't get a frame from channel: %s\n",who->name); 04796 break; 04797 } 04798 04799 other = (who == c0) ? c1 : c0; /* the 'other' channel */ 04800 /* Try add the frame info the who's bridged channel jitterbuff */ 04801 if (jb_in_use) 04802 frame_put_in_jb = !ast_jb_put(other, f); 04803 04804 if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) { 04805 int bridge_exit = 0; 04806 04807 switch (f->subclass) { 04808 case AST_CONTROL_HOLD: 04809 case AST_CONTROL_UNHOLD: 04810 case AST_CONTROL_VIDUPDATE: 04811 case AST_CONTROL_SRCUPDATE: 04812 case AST_CONTROL_T38_PARAMETERS: 04813 ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen); 04814 if (jb_in_use) { 04815 ast_jb_empty_and_reset(c0, c1); 04816 } 04817 break; 04818 default: 04819 *fo = f; 04820 *rc = who; 04821 bridge_exit = 1; 04822 ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name); 04823 break; 04824 } 04825 if (bridge_exit) 04826 break; 04827 } 04828 if ((f->frametype == AST_FRAME_VOICE) || 04829 (f->frametype == AST_FRAME_DTMF_BEGIN) || 04830 (f->frametype == AST_FRAME_DTMF) || 04831 (f->frametype == AST_FRAME_VIDEO) || 04832 (f->frametype == AST_FRAME_IMAGE) || 04833 (f->frametype == AST_FRAME_HTML) || 04834 (f->frametype == AST_FRAME_MODEM) || 04835 (f->frametype == AST_FRAME_TEXT)) { 04836 /* monitored dtmf causes exit from bridge */ 04837 int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf; 04838 04839 if (monitored_source && 04840 (f->frametype == AST_FRAME_DTMF_END || 04841 f->frametype == AST_FRAME_DTMF_BEGIN)) { 04842 *fo = f; 04843 *rc = who; 04844 ast_debug(1, "Got DTMF %s on channel (%s)\n", 04845 f->frametype == AST_FRAME_DTMF_END ? "end" : "begin", 04846 who->name); 04847 04848 break; 04849 } 04850 /* Write immediately frames, not passed through jb */ 04851 if (!frame_put_in_jb) 04852 ast_write(other, f); 04853 04854 /* Check if we have to deliver now */ 04855 if (jb_in_use) 04856 ast_jb_get_and_deliver(c0, c1); 04857 } 04858 /* XXX do we want to pass on also frames not matched above ? */ 04859 ast_frfree(f); 04860 04861 #ifndef HAVE_EPOLL 04862 /* Swap who gets priority */ 04863 cs[2] = cs[0]; 04864 cs[0] = cs[1]; 04865 cs[1] = cs[2]; 04866 #endif 04867 } 04868 04869 ast_poll_channel_del(c0, c1); 04870 04871 return res; 04872 }
| struct ast_channel* ast_get_channel_by_exten_locked | ( | const char * | exten, | |
| const char * | context | |||
| ) | [read] |
Get channel by exten (and optionally context) and lock it.
Definition at line 1290 of file channel.c.
References channel_find_locked().
01291 { 01292 return channel_find_locked(NULL, NULL, 0, context, exten); 01293 }
| struct ast_channel* ast_get_channel_by_name_locked | ( | const char * | name | ) | [read] |
Get channel by name and lock it.
Get channel by name or uniqueid (locks channel).
Definition at line 1271 of file channel.c.
References channel_find_locked().
Referenced by acf_import(), action_add_agi_cmd(), action_atxfer(), action_getvar(), action_hangup(), action_redirect(), action_sendtext(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), ast_bridge_call(), ast_park_call_full(), asyncgoto_exec(), change_monitor_action(), do_pause_or_unpause(), get_dahdi_channel_locked(), handle_channelstatus(), handle_cli_agi_add_cmd(), handle_core_set_debug_channel(), handle_getvariablefull(), handle_hangup(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), handle_softhangup(), manager_park(), manager_play_dtmf(), pbx_builtin_importvar(), shared_read(), shared_write(), start_monitor_action(), and stop_monitor_action().
01272 { 01273 return channel_find_locked(NULL, name, 0, NULL, NULL); 01274 }
| struct ast_channel* ast_get_channel_by_name_prefix_locked | ( | const char * | name, | |
| const int | namelen | |||
| ) | [read] |
Get channel by name prefix and lock it.
Get channel by name or uniqueid prefix (locks channel).
Definition at line 1277 of file channel.c.
References channel_find_locked().
Referenced by action_bridge(), ast_parse_device_state(), bridge_exec(), common_exec(), handle_cli_mixmonitor(), shared_read(), and shared_write().
01278 { 01279 return channel_find_locked(NULL, name, namelen, NULL, NULL); 01280 }
| struct ast_channel_tech* ast_get_channel_tech | ( | const char * | name | ) | [read] |
Get handle to channel driver based on name.
Get a channel technology structure by name.
Definition at line 609 of file channel.c.
References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, chanlist::tech, and ast_channel_tech::type.
Referenced by _ast_device_state().
00610 { 00611 struct chanlist *chanls; 00612 const struct ast_channel_tech *ret = NULL; 00613 00614 AST_RWLIST_RDLOCK(&channels); 00615 00616 AST_LIST_TRAVERSE(&backends, chanls, list) { 00617 if (!strcasecmp(name, chanls->tech->type)) { 00618 ret = chanls->tech; 00619 break; 00620 } 00621 } 00622 00623 AST_RWLIST_UNLOCK(&channels); 00624 00625 return ret; 00626 }
| ast_group_t ast_get_group | ( | const char * | s | ) |
Definition at line 5403 of file channel.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), LOG_ERROR, LOG_WARNING, and strsep().
Referenced by _parse(), build_device(), build_gateway(), build_peer(), func_channel_write(), process_dahdi(), and read_agent_config().
05404 { 05405 char *piece; 05406 char *c; 05407 int start=0, finish=0, x; 05408 ast_group_t group = 0; 05409 05410 if (ast_strlen_zero(s)) 05411 return 0; 05412 05413 c = ast_strdupa(s); 05414 05415 while ((piece = strsep(&c, ","))) { 05416 if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) { 05417 /* Range */ 05418 } else if (sscanf(piece, "%30d", &start)) { 05419 /* Just one */ 05420 finish = start; 05421 } else { 05422 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece); 05423 continue; 05424 } 05425 for (x = start; x <= finish; x++) { 05426 if ((x > 63) || (x < 0)) { 05427 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x); 05428 } else 05429 group |= ((ast_group_t) 1 << x); 05430 } 05431 } 05432 return group; 05433 }
| int ast_hangup | ( | struct ast_channel * | chan | ) |
Hangup a channel.
Hang up a channel.
Definition at line 1641 of file channel.c.
References ast_assert, ast_audiohook_detach_list(), ast_autoservice_stop(), ast_cause2str(), ast_cdr_detach(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_DIALED, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_IN_CHANNEL_LIST, AST_FLAG_ZOMBIE, ast_log(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_cdr::disposition, EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_ERROR, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_generator::release, S_OR, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, ast_channel::uniqueid, and ast_channel::vstream.
Referenced by __ast_pbx_run(), __ast_request_and_dial(), __oh323_new(), action_bridge(), agent_hangup(), agent_read(), alsa_new(), answer_exec_run(), app_exec(), ast_async_goto(), ast_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_channel(), bridge_exec(), build_conf(), builtin_atxfer(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), connect_link(), console_new(), dahdi_handle_event(), dahdi_new(), dial_exec_full(), do_forward(), do_hang(), findmeexec(), gtalk_new(), handle_call_forward(), handle_callforward_button(), handle_enbloc_call_message(), handle_frame(), handle_frame_ownerless(), handle_hd_hf(), handle_init_event(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_soft_key_event_message(), handle_stimulus_message(), handle_timeout_trip(), handle_transfer_button(), HandleCallOutgoing(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), jingle_new(), local_hangup(), manage_parkinglot(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), nbs_new(), oss_new(), park_exec_full(), parkandannounce_exec(), phone_new(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), try_calling(), unistim_new(), usbradio_new(), wait_for_answer(), and wait_for_winner().
01642 { 01643 int res = 0; 01644 01645 /* Don't actually hang up a channel that will masquerade as someone else, or 01646 if someone is going to masquerade as us */ 01647 ast_channel_lock(chan); 01648 01649 if (chan->audiohooks) { 01650 ast_audiohook_detach_list(chan->audiohooks); 01651 chan->audiohooks = NULL; 01652 } 01653 01654 ast_autoservice_stop(chan); 01655 01656 if (chan->masq) { 01657 if (ast_do_masquerade(chan)) 01658 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 01659 } 01660 01661 if (chan->masq) { 01662 ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name); 01663 ast_channel_unlock(chan); 01664 return 0; 01665 } 01666 /* If this channel is one which will be masqueraded into something, 01667 mark it as a zombie already, so we know to free it later */ 01668 if (chan->masqr) { 01669 ast_set_flag(chan, AST_FLAG_ZOMBIE); 01670 ast_channel_unlock(chan); 01671 return 0; 01672 } 01673 ast_channel_unlock(chan); 01674 01675 AST_RWLIST_WRLOCK(&channels); 01676 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01677 ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01678 } 01679 ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01680 AST_RWLIST_UNLOCK(&channels); 01681 01682 ast_channel_lock(chan); 01683 free_translation(chan); 01684 /* Close audio stream */ 01685 if (chan->stream) { 01686 ast_closestream(chan->stream); 01687 chan->stream = NULL; 01688 } 01689 /* Close video stream */ 01690 if (chan->vstream) { 01691 ast_closestream(chan->vstream); 01692 chan->vstream = NULL; 01693 } 01694 if (chan->sched) { 01695 sched_context_destroy(chan->sched); 01696 chan->sched = NULL; 01697 } 01698 01699 if (chan->generatordata) /* Clear any tone stuff remaining */ 01700 if (chan->generator && chan->generator->release) 01701 chan->generator->release(chan, chan->generatordata); 01702 chan->generatordata = NULL; 01703 chan->generator = NULL; 01704 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01705 ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " 01706 "is blocked by thread %ld in procedure %s! Expect a failure\n", 01707 (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); 01708 ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0); 01709 } 01710 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { 01711 ast_debug(1, "Hanging up channel '%s'\n", chan->name); 01712 if (chan->tech->hangup) 01713 res = chan->tech->hangup(chan); 01714 } else { 01715 ast_debug(1, "Hanging up zombie '%s'\n", chan->name); 01716 } 01717 01718 ast_channel_unlock(chan); 01719 manager_event(EVENT_FLAG_CALL, "Hangup", 01720 "Channel: %s\r\n" 01721 "Uniqueid: %s\r\n" 01722 "CallerIDNum: %s\r\n" 01723 "CallerIDName: %s\r\n" 01724 "Cause: %d\r\n" 01725 "Cause-txt: %s\r\n", 01726 chan->name, 01727 chan->uniqueid, 01728 S_OR(chan->cid.cid_num, "<unknown>"), 01729 S_OR(chan->cid.cid_name, "<unknown>"), 01730 chan->hangupcause, 01731 ast_cause2str(chan->hangupcause) 01732 ); 01733 01734 if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 01735 !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 01736 (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) { 01737 ast_channel_lock(chan); 01738 01739 ast_cdr_end(chan->cdr); 01740 ast_cdr_detach(chan->cdr); 01741 chan->cdr = NULL; 01742 ast_channel_unlock(chan); 01743 } 01744 01745 ast_channel_free(chan); 01746 01747 return res; 01748 }
| 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 3039 of file channel.c.
References ast_indicate_data().
Referenced by __ast_play_and_record(), agent_new(), alsa_call(), answer_trunk_chan(), ast_bridge_call(), ast_channel_bridge(), ast_do_masquerade(), ast_dtmf_stream(), ast_feature_request_and_dial(), ast_park_call_full(), ast_raw_answer(), attempt_transfer(), builtin_atxfer(), builtin_blindtransfer(), cli_console_answer(), conf_run(), console_call(), dial_exec_full(), disa_exec(), do_forward(), finishup(), function_remote(), handle_callforward_button(), handle_frame(), handle_recordfile(), manage_parkinglot(), mgcp_ss(), monitor_dial(), oss_call(), park_exec_full(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_proceeding(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), record_exec(), rpt(), rpt_exec(), say_periodic_announcement(), say_position(), send_waveform_to_channel(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), try_calling(), and wait_for_answer().
03040 { 03041 return ast_indicate_data(chan, condition, NULL, 0); 03042 }
| 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 3079 of file channel.c.
References ast_channel::_state, _XXX_AST_CONTROL_T38, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_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_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_debug, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STATE_UP, ast_test_flag, tone_zone_sound::data, ast_channel_tech::indicate, is_visible_indication(), LOG_WARNING, ast_channel::name, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.
Referenced by agent_hangup(), ast_bridge_call(), ast_generic_bridge(), ast_indicate(), ast_park_call_full(), bridge_native_loop(), bridge_p2p_loop(), login_exec(), manage_parkinglot(), pbx_builtin_waitexten(), transmit_audio(), transmit_t38(), and wait_for_answer().
03081 { 03082 /* By using an enum, we'll get compiler warnings for values not handled 03083 * in switch statements. */ 03084 enum ast_control_frame_type condition = _condition; 03085 const struct tone_zone_sound *ts = NULL; 03086 int res = -1; 03087 03088 ast_channel_lock(chan); 03089 03090 /* Don't bother if the channel is about to go away, anyway. */ 03091 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 03092 ast_channel_unlock(chan); 03093 return -1; 03094 } 03095 03096 if (chan->tech->indicate) { 03097 /* See if the channel driver can handle this condition. */ 03098 res = chan->tech->indicate(chan, condition, data, datalen); 03099 } 03100 03101 ast_channel_unlock(chan); 03102 03103 if (!res) { 03104 /* The channel driver successfully handled this indication */ 03105 if (is_visible_indication(condition)) { 03106 chan->visible_indication = condition; 03107 } 03108 return 0; 03109 } 03110 03111 /* The channel driver does not support this indication, let's fake 03112 * it by doing our own tone generation if applicable. */ 03113 03114 /*!\note If we compare the enumeration type, which does not have any 03115 * negative constants, the compiler may optimize this code away. 03116 * Therefore, we must perform an integer comparison here. */ 03117 if (_condition < 0) { 03118 /* Stop any tones that are playing */ 03119 ast_playtones_stop(chan); 03120 return 0; 03121 } 03122 03123 /* Handle conditions that we have tones for. */ 03124 switch (condition) { 03125 case _XXX_AST_CONTROL_T38: 03126 /* deprecated T.38 control frame */ 03127 return -1; 03128 case AST_CONTROL_T38_PARAMETERS: 03129 /* there is no way to provide 'default' behavior for these 03130 * control frames, so we need to return failure, but there 03131 * is also no value in the log message below being emitted 03132 * since failure to handle these frames is not an 'error' 03133 * so just return right now. 03134 */ 03135 return -1; 03136 case AST_CONTROL_RINGING: 03137 ts = ast_get_indication_tone(chan->zone, "ring"); 03138 /* It is common practice for channel drivers to return -1 if trying 03139 * to indicate ringing on a channel which is up. The idea is to let the 03140 * core generate the ringing inband. However, we don't want the 03141 * warning message about not being able to handle the specific indication 03142 * to print nor do we want ast_indicate_data to return an "error" for this 03143 * condition 03144 */ 03145 if (chan->_state == AST_STATE_UP) { 03146 res = 0; 03147 } 03148 break; 03149 case AST_CONTROL_BUSY: 03150 ts = ast_get_indication_tone(chan->zone, "busy"); 03151 break; 03152 case AST_CONTROL_CONGESTION: 03153 ts = ast_get_indication_tone(chan->zone, "congestion"); 03154 break; 03155 case AST_CONTROL_PROGRESS: 03156 case AST_CONTROL_PROCEEDING: 03157 case AST_CONTROL_VIDUPDATE: 03158 case AST_CONTROL_SRCUPDATE: 03159 case AST_CONTROL_RADIO_KEY: 03160 case AST_CONTROL_RADIO_UNKEY: 03161 case AST_CONTROL_OPTION: 03162 case AST_CONTROL_WINK: 03163 case AST_CONTROL_FLASH: 03164 case AST_CONTROL_OFFHOOK: 03165 case AST_CONTROL_TAKEOFFHOOK: 03166 case AST_CONTROL_ANSWER: 03167 case AST_CONTROL_HANGUP: 03168 case AST_CONTROL_RING: 03169 case AST_CONTROL_HOLD: 03170 case AST_CONTROL_UNHOLD: 03171 /* Nothing left to do for these. */ 03172 res = 0; 03173 break; 03174 } 03175 03176 if (ts && ts->data[0]) { 03177 /* We have a tone to play, yay. */ 03178 ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition); 03179 ast_playtones_start(chan, 0, ts->data, 1); 03180 res = 0; 03181 chan->visible_indication = condition; 03182 } 03183 03184 if (res) { 03185 /* not handled */ 03186 ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name); 03187 } 03188 03189 return res; 03190 }
| void ast_install_music_functions | ( | int(*)(struct ast_channel *, const char *, const char *) | start_ptr, | |
| void(*)(struct ast_channel *) | stop_ptr, | |||
| void(*)(struct ast_channel *) | cleanup_ptr | |||
| ) |
Definition at line 5439 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by load_module().
05442 { 05443 ast_moh_start_ptr = start_ptr; 05444 ast_moh_stop_ptr = stop_ptr; 05445 ast_moh_cleanup_ptr = cleanup_ptr; 05446 }
| 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 3022 of file channel.c.
References ast_debug, ast_opt_internal_timing, and ast_channel::timingfd.
Referenced by add_sdp(), and ast_read_generator_actions().
03023 { 03024 int ret = ast_opt_internal_timing && chan->timingfd > -1; 03025 ast_debug(5, "Internal timing is %s (option_internal_timing=%d chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_internal_timing, chan->timingfd); 03026 return ret; 03027 }
| void ast_moh_cleanup | ( | struct ast_channel * | chan | ) |
Definition at line 5473 of file channel.c.
References ast_moh_cleanup_ptr.
Referenced by ast_channel_free().
05474 { 05475 if (ast_moh_cleanup_ptr) 05476 ast_moh_cleanup_ptr(chan); 05477 }
| int ast_moh_start | ( | struct ast_channel * | chan, | |
| const char * | mclass, | |||
| const char * | interpclass | |||
| ) |
Turn on music on hold on a given channel.
| chan | The channel structure that will get music on hold | |
| mclass | The class to use if the musicclass is not currently set on the channel structure. | |
| interpclass | The class to use if the musicclass is not currently set on the channel structure or in the mclass argument. |
| Zero | on success | |
| non-zero | on failure |
Definition at line 5456 of file channel.c.
References ast_moh_start_ptr, and ast_verb.
Referenced by alsa_indicate(), app_exec(), conf_run(), conf_start_moh(), console_indicate(), dahdi_indicate(), dial_exec_full(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), jingle_indicate(), key_call(), local_indicate(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), skinny_indicate(), start_moh_exec(), TransferCallStep1(), unistim_indicate(), usbradio_indicate(), and wait_moh_exec().
05457 { 05458 if (ast_moh_start_ptr) 05459 return ast_moh_start_ptr(chan, mclass, interpclass); 05460 05461 ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default")); 05462 05463 return 0; 05464 }
| void ast_moh_stop | ( | struct ast_channel * | chan | ) |
Turn off music on hold on a given channel.
Turn off music on hold on a given channel
Definition at line 5467 of file channel.c.
References ast_moh_stop_ptr.
Referenced by alsa_indicate(), app_exec(), ast_quiet_chan(), conf_run(), console_indicate(), dahdi_indicate(), dial_exec_full(), do_bridge_masquerade(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), jingle_indicate(), key_call(), key_dial_page(), local_indicate(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), skinny_indicate(), stop_moh_exec(), try_calling(), unistim_hangup(), unistim_indicate(), usbradio_indicate(), and wait_moh_exec().
05468 { 05469 if (ast_moh_stop_ptr) 05470 ast_moh_stop_ptr(chan); 05471 }
| void ast_poll_channel_add | ( | struct ast_channel * | chan0, | |
| struct ast_channel * | chan1 | |||
| ) |
Add a channel to an optimized waitfor
Definition at line 1561 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_feature_request_and_dial(), ast_generic_bridge(), begin_dial_channel(), bridge_native_loop(), bridge_p2p_loop(), and wait_for_answer().
01562 { 01563 #ifdef HAVE_EPOLL 01564 struct epoll_event ev; 01565 int i = 0; 01566 01567 if (chan0->epfd == -1) 01568 return; 01569 01570 /* Iterate through the file descriptors on chan1, adding them to chan0 */ 01571 for (i = 0; i < AST_MAX_FDS; i++) { 01572 if (chan1->fds[i] == -1) 01573 continue; 01574 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01575 ev.data.ptr = chan1->epfd_data[i]; 01576 epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev); 01577 } 01578 01579 #endif 01580 return; 01581 }
| void ast_poll_channel_del | ( | struct ast_channel * | chan0, | |
| struct ast_channel * | chan1 | |||
| ) |
Delete a channel from an optimized waitfor
Definition at line 1584 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_feature_request_and_dial(), ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), monitor_dial(), and wait_for_answer().
01585 { 01586 #ifdef HAVE_EPOLL 01587 struct epoll_event ev; 01588 int i = 0; 01589 01590 if (chan0->epfd == -1) 01591 return; 01592 01593 for (i = 0; i < AST_MAX_FDS; i++) { 01594 if (chan1->fds[i] == -1) 01595 continue; 01596 epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev); 01597 } 01598 01599 #endif 01600 return; 01601 }
| char* ast_print_group | ( | char * | buf, | |
| int | buflen, | |||
| ast_group_t | group | |||
| ) |
Print call group and pickup group ---.
print call- and pickup groups into buffer
Definition at line 5485 of file channel.c.
Referenced by _sip_show_peer(), func_channel_read(), function_sippeer(), handle_skinny_show_line(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().
05486 { 05487 unsigned int i; 05488 int first = 1; 05489 char num[3]; 05490 05491 buf[0] = '\0'; 05492 05493 if (!group) /* Return empty string if no group */ 05494 return buf; 05495 05496 for (i = 0; i <= 63; i++) { /* Max group is 63 */ 05497 if (group & ((ast_group_t) 1 << i)) { 05498 if (!first) { 05499 strncat(buf, ", ", buflen - strlen(buf) - 1); 05500 } else { 05501 first = 0; 05502 } 05503 snprintf(num, sizeof(num), "%u", i); 05504 strncat(buf, num, buflen - strlen(buf) - 1); 05505 } 05506 } 05507 return buf; 05508 }
| int ast_prod | ( | struct ast_channel * | chan | ) |
Send empty audio to prime a channel driver.
Definition at line 3311 of file channel.c.
References ast_channel::_state, ast_debug, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), ast_frame::data, LOG_WARNING, ast_channel::name, ast_frame::ptr, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.
Referenced by ast_activate_generator().
03312 { 03313 struct ast_frame a = { AST_FRAME_VOICE }; 03314 char nothing[128]; 03315 03316 /* Send an empty audio frame to get things moving */ 03317 if (chan->_state != AST_STATE_UP) { 03318 ast_debug(1, "Prodding channel '%s'\n", chan->name); 03319 a.subclass = chan->rawwriteformat; 03320 a.data.ptr = nothing + AST_FRIENDLY_OFFSET; 03321 a.src = "ast_prod"; 03322 if (ast_write(chan, &a)) 03323 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name); 03324 } 03325 return 0; 03326 }
| int ast_queue_control | ( | struct ast_channel * | chan, | |
| enum ast_control_frame_type | control | |||
| ) |
Queue a control frame.
Queue a control frame with payload.
Definition at line 1116 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and ast_frame::subclass.
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(), HandleCallIncoming(), jingle_is_answered(), jingle_ringing_ack(), mgcp_call(), misdn_attempt_transfer(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), remote_hold(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_transfer(), skinny_unhold(), ss_thread(), unistim_call(), and update_state().
01117 { 01118 struct ast_frame f = { AST_FRAME_CONTROL, }; 01119 01120 f.subclass = control; 01121 01122 return ast_queue_frame(chan, &f); 01123 }
| int ast_queue_control_data | ( | struct ast_channel * | chan, | |
| enum ast_control_frame_type | control, | |||
| const void * | data, | |||
| size_t | datalen | |||
| ) |
Queue a control frame with payload.
| chan | channel to queue frame onto | |
| control | type of control frame | |
| data | pointer to payload data to be included in frame | |
| datalen | number of bytes of payload data |
| 0 | success | |
| non-zero | failure |
The channel does not need to be locked before calling this function.
Definition at line 1126 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::ptr, and ast_frame::subclass.
Referenced by change_t38_state(), dahdi_handle_event(), dahdi_hangup(), iax2_queue_control_data(), process_sdp(), and skinny_hold().
01128 { 01129 struct ast_frame f = { AST_FRAME_CONTROL, }; 01130 01131 f.subclass = control; 01132 f.data.ptr = (void *) data; 01133 f.datalen = datalen; 01134 01135 return ast_queue_frame(chan, &f); 01136 }
| 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 1073 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), action_atxfer(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup_tv(), ast_do_masquerade(), ast_dsp_process(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), cb_events(), cli_console_answer(), cli_console_dial(), cli_console_flash(), cli_console_sendtext(), console_answer(), console_call(), console_dial(), console_do_answer(), console_flash(), console_sendtext(), dahdi_queue_frame(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), jingle_handle_dtmf(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), stream_monitor(), unistim_do_senddigit(), unistim_senddigit_end(), usbradio_read(), and wakeup_sub().
01074 { 01075 return __ast_queue_frame(chan, fin, 0, NULL); 01076 }
| 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 1078 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_answer(), __ast_read(), and ast_autoservice_stop().
01079 { 01080 return __ast_queue_frame(chan, fin, 1, NULL); 01081 }
| int ast_queue_hangup | ( | struct ast_channel * | chan | ) |
Queue a hangup frame for channel.
Queue a hangup frame.
Definition at line 1084 of file channel.c.
References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), and AST_SOFTHANGUP_DEV.
Referenced by cleanup_connection(), cli_console_hangup(), close_call(), gtalk_hangup_farend(), gtalk_is_answered(), handle_onhook_message(), handle_request_bye(), handle_request_cancel(), handle_soft_key_event_message(), iax2_destroy(), iax2_queue_hangup(), jingle_hangup_farend(), local_hangup(), and mgcp_queue_hangup().
01085 { 01086 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01087 /* Yeah, let's not change a lock-critical value without locking */ 01088 if (!ast_channel_trylock(chan)) { 01089 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01090 ast_channel_unlock(chan); 01091 } 01092 return ast_queue_frame(chan, &f); 01093 }
| int ast_queue_hangup_with_cause | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Queue a hangup frame for channel.
Queue a hangup frame with hangupcause set.
Definition at line 1096 of file channel.c.
References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, ast_frame::data, ast_channel::hangupcause, and ast_frame::uint32.
Referenced by __oh323_update_info(), __sip_autodestruct(), close_call(), close_client(), console_hangup(), dahdi_handle_event(), handle_request_bye(), handle_response(), handle_response_invite(), handle_response_notify(), HandleCallOutgoing(), hangup_chan(), hangup_connection(), misdn_answer(), retrans_pkt(), and TransferCallStep1().
01097 { 01098 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01099 01100 if (cause >= 0) 01101 f.data.uint32 = cause; 01102 01103 /* Yeah, let's not change a lock-critical value without locking */ 01104 if (!ast_channel_trylock(chan)) { 01105 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01106 if (cause < 0) 01107 f.data.uint32 = chan->hangupcause; 01108 01109 ast_channel_unlock(chan); 01110 } 01111 01112 return ast_queue_frame(chan, &f); 01113 }
| int ast_raw_answer | ( | struct ast_channel * | chan, | |
| int | cdr_answer | |||
| ) |
Answer a channel.
| chan | channel to answer | |
| cdr_answer | flag to control whether any associated CDR should be marked as 'answered' |
Unlike ast_answer(), this function will not wait for media flow to begin. The caller should be careful before sending media to the channel before incoming media arrives, as the outgoing media may be lost.
| 0 | on success | |
| non-zero | on failure |
Definition at line 1750 of file channel.c.
References ast_channel::_state, ast_channel_tech::answer, ast_cdr_answer(), ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_indicate(), ast_setstate(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_test_flag, ast_channel::cdr, ast_channel::tech, and ast_channel::visible_indication.
Referenced by __ast_answer(), and ast_bridge_call().
01751 { 01752 int res = 0; 01753 01754 ast_channel_lock(chan); 01755 01756 /* You can't answer an outbound call */ 01757 if (ast_test_flag(chan, AST_FLAG_OUTGOING)) { 01758 ast_channel_unlock(chan); 01759 return 0; 01760 } 01761 01762 /* Stop if we're a zombie or need a soft hangup */ 01763 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 01764 ast_channel_unlock(chan); 01765 return -1; 01766 } 01767 01768 ast_channel_unlock(chan); 01769 01770 switch (chan->_state) { 01771 case AST_STATE_RINGING: 01772 case AST_STATE_RING: 01773 ast_channel_lock(chan); 01774 if (chan->tech->answer) { 01775 res = chan->tech->answer(chan); 01776 } 01777 ast_setstate(chan, AST_STATE_UP); 01778 if (cdr_answer) { 01779 ast_cdr_answer(chan->cdr); 01780 } 01781 ast_channel_unlock(chan); 01782 break; 01783 case AST_STATE_UP: 01784 /* Calling ast_cdr_answer when it it has previously been called 01785 * is essentially a no-op, so it is safe. 01786 */ 01787 if (cdr_answer) { 01788 ast_cdr_answer(chan->cdr); 01789 } 01790 break; 01791 default: 01792 break; 01793 } 01794 01795 ast_indicate(chan, -1); 01796 chan->visible_indication = 0; 01797 01798 return res; 01799 }
| struct ast_frame* ast_read | ( | struct ast_channel * | chan | ) | [read] |
Reads a frame.
| chan | channel to read a frame from |
Definition at line 3029 of file channel.c.
References __ast_read().
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), ast_feature_request_and_dial(), ast_generic_bridge(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_udptl_bridge(), ast_waitfordigit_full(), async_wait(), autoservice_run(), background_detect_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_goto_on_transfer(), conf_exec(), conf_flush(), conf_run(), dahdi_bridge(), dictate_exec(), disa_exec(), do_waiting(), echo_exec(), eivr_comm(), find_cache(), handle_recordfile(), handle_speechrecognize(), iax2_bridge(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), manage_parkinglot(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), recordthread(), rpt(), rpt_exec(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().
03030 { 03031 return __ast_read(chan, 0); 03032 }
| static void ast_read_generator_actions | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f | |||
| ) | [static] |
Definition at line 2481 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_deactivate_generator(), ast_debug, ast_format_rate(), AST_FRAME_CNG, ast_internal_timing_enabled(), ast_settimeout(), ast_frame::datalen, ast_frame::frametype, ast_generator::generate, ast_channel::generator, generator_force(), ast_channel::generatordata, ast_frame::samples, ast_frame::subclass, ast_channel::timingfd, ast_channel::timingfunc, and ast_channel::writeformat.
Referenced by __ast_read().
02482 { 02483 if (chan->generator && chan->generator->generate && chan->generatordata && !ast_internal_timing_enabled(chan)) { 02484 void *tmp = chan->generatordata; 02485 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = chan->generator->generate; 02486 int res; 02487 int samples; 02488 02489 if (chan->timingfunc) { 02490 ast_debug(1, "Generator got voice, switching to phase locked mode\n"); 02491 ast_settimeout(chan, 0, NULL, NULL); 02492 } 02493 02494 chan->generatordata = NULL; /* reset, to let writes go through */ 02495 02496 if (f->subclass != chan->writeformat) { 02497 float factor; 02498 factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass)); 02499 samples = (int) ( ((float) f->samples) * factor ); 02500 } else { 02501 samples = f->samples; 02502 } 02503 02504 /* This unlock is here based on two assumptions that hold true at this point in the 02505 * code. 1) this function is only called from within __ast_read() and 2) all generators 02506 * call ast_write() in their generate callback. 02507 * 02508 * The reason this is added is so that when ast_write is called, the lock that occurs 02509 * there will not recursively lock the channel. Doing this will cause intended deadlock 02510 * avoidance not to work in deeper functions 02511 */ 02512 ast_channel_unlock(chan); 02513 res = generate(chan, tmp, f->datalen, samples); 02514 ast_channel_lock(chan); 02515 chan->generatordata = tmp; 02516 if (res) { 02517 ast_debug(1, "Auto-deactivating generator\n"); 02518 ast_deactivate_generator(chan); 02519 } 02520 02521 } else if (f->frametype == AST_FRAME_CNG) { 02522 if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) { 02523 ast_debug(1, "Generator got CNG, switching to timed mode\n"); 02524 ast_settimeout(chan, 50, generator_force, chan); 02525 } 02526 } 02527 }
| struct ast_frame* ast_read_noaudio | ( | struct ast_channel * | chan | ) | [read] |
Reads a frame, returning AST_FRAME_NULL frame if audio.
| chan | channel to read a frame from |
Definition at line 3034 of file channel.c.
References __ast_read().
Referenced by conf_run().
03035 { 03036 return __ast_read(chan, 1); 03037 }
| 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 4006 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().
04007 { 04008 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1); 04009 }
| int ast_readstring_full | ( | struct ast_channel * | c, | |
| char * | s, | |||
| int | len, | |||
| int | timeout, | |||
| int | ftimeout, | |||
| char * | enders, | |||
| int | audiofd, | |||
| int | ctrlfd | |||
| ) |
Definition at line 4011 of file channel.c.
References ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, AST_GETDATA_COMPLETE, AST_GETDATA_EMPTY_END_TERMINATED, AST_GETDATA_FAILED, AST_GETDATA_INTERRUPTED, AST_GETDATA_TIMEOUT, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), ast_waitstream_full(), and ast_channel::stream.
Referenced by ast_app_getdata_full(), and ast_readstring().
04012 { 04013 int pos = 0; /* index in the buffer where we accumulate digits */ 04014 int to = ftimeout; 04015 04016 /* Stop if we're a zombie or need a soft hangup */ 04017 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 04018 return -1; 04019 if (!len) 04020 return -1; 04021 for (;;) { 04022 int d; 04023 if (c->stream) { 04024 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); 04025 ast_stopstream(c); 04026 usleep(1000); 04027 if (!d) 04028 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04029 } else { 04030 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04031 } 04032 if (d < 0) 04033 return AST_GETDATA_FAILED; 04034 if (d == 0) { 04035 s[pos] = '\0'; 04036 return AST_GETDATA_TIMEOUT; 04037 } 04038 if (d == 1) { 04039 s[pos] = '\0'; 04040 return AST_GETDATA_INTERRUPTED; 04041 } 04042 if (strchr(enders, d) && (pos == 0)) { 04043 s[pos] = '\0'; 04044 return AST_GETDATA_EMPTY_END_TERMINATED; 04045 } 04046 if (!strchr(enders, d)) { 04047 s[pos++] = d; 04048 } 04049 if (strchr(enders, d) || (pos >= len)) { 04050 s[pos] = '\0'; 04051 return AST_GETDATA_COMPLETE; 04052 } 04053 to = timeout; 04054 } 04055 /* Never reached */ 04056 return 0; 04057 }
| 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 3192 of file channel.c.
References ast_free, and ast_recvtext().
Referenced by handle_recvchar().
03193 { 03194 int c; 03195 char *buf = ast_recvtext(chan, timeout); 03196 if (buf == NULL) 03197 return -1; /* error or timeout */ 03198 c = *(unsigned char *)buf; 03199 ast_free(buf); 03200 return c; 03201 }
| 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 3203 of file channel.c.
References ast_check_hangup(), AST_CONTROL_HANGUP, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_frfree, ast_read(), ast_strndup, ast_waitfor(), ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, ast_frame::ptr, and ast_frame::subclass.
Referenced by ast_recvchar(), and handle_recvtext().
03204 { 03205 int res, done = 0; 03206 char *buf = NULL; 03207 03208 while (!done) { 03209 struct ast_frame *f; 03210 if (ast_check_hangup(chan)) 03211 break; 03212 res = ast_waitfor(chan, timeout); 03213 if (res <= 0) /* timeout or error */ 03214 break; 03215 timeout = res; /* update timeout */ 03216 f = ast_read(chan); 03217 if (f == NULL) 03218 break; /* no frame */ 03219 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) 03220 done = 1; /* force a break */ 03221 else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ 03222 buf = ast_strndup((char *) f->data.ptr, f->datalen); /* dup and break */ 03223 done = 1; 03224 } 03225 ast_frfree(f); 03226 } 03227 return buf; 03228 }
| struct ast_channel* ast_request | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int * | status | |||
| ) | [read] |
Requests a channel.
| type | type of channel to request | |
| format | requested channel format (codec) | |
| data | data to pass to the channel requester | |
| status | status |
| NULL | failure | |
| non-NULL | channel on success |
Definition at line 3906 of file channel.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_translator_best_choice(), ast_channel_tech::capabilities, capabilities, LOG_WARNING, 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_channel(), build_conf(), chanavail_exec(), conf_run(), connect_link(), dial_exec_full(), do_forward(), findmeexec(), ring_entry(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), and wait_for_answer().
03907 { 03908 struct chanlist *chan; 03909 struct ast_channel *c; 03910 int capabilities; 03911 int fmt; 03912 int res; 03913 int foo; 03914 int videoformat = format & AST_FORMAT_VIDEO_MASK; 03915 int textformat = format & AST_FORMAT_TEXT_MASK; 03916 03917 if (!cause) 03918 cause = &foo; 03919 *cause = AST_CAUSE_NOTDEFINED; 03920 03921 if (AST_RWLIST_RDLOCK(&channels)) { 03922 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 03923 return NULL; 03924 } 03925 03926 AST_LIST_TRAVERSE(&backends, chan, list) { 03927 if (strcasecmp(type, chan->tech->type)) 03928 continue; 03929 03930 capabilities = chan->tech->capabilities; 03931 fmt = format & AST_FORMAT_AUDIO_MASK; 03932 if (fmt) { 03933 /* We have audio - is it possible to connect the various calls to each other? 03934 (Avoid this check for calls without audio, like text+video calls) 03935 */ 03936 res = ast_translator_best_choice(&fmt, &capabilities); 03937 if (res < 0) { 03938 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format); 03939 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 03940 AST_RWLIST_UNLOCK(&channels); 03941 return NULL; 03942 } 03943 } 03944 AST_RWLIST_UNLOCK(&channels); 03945 if (!chan->tech->requester) 03946 return NULL; 03947 03948 if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, data, cause))) 03949 return NULL; 03950 03951 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */ 03952 return c; 03953 } 03954 03955 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type); 03956 *cause = AST_CAUSE_NOSUCHDRIVER; 03957 AST_RWLIST_UNLOCK(&channels); 03958 03959 return NULL; 03960 }
| struct ast_channel* ast_request_and_dial | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int | timeout, | |||
| int * | reason, | |||
| const char * | cid_num, | |||
| const char * | cid_name | |||
| ) | [read] |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.
| type | type of channel to request | |
| format | requested channel format | |
| data | data to pass to the channel requester | |
| timeout | maximum amount of time to wait for an answer | |
| reason | why unsuccessful (if unsuccessful) | |
| cid_num | Caller-ID Number | |
| cid_name | Caller-ID Name (ascii) |
Definition at line 3901 of file channel.c.
References __ast_request_and_dial().
Referenced by ast_pbx_outgoing_exten().
03902 { 03903 return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL); 03904 }
| int ast_safe_sleep | ( | struct ast_channel * | chan, | |
| int | ms | |||
| ) |
Wait, look for hangups.
Wait for a specified amount of time, looking for hangups.
Definition at line 1324 of file channel.c.
References ast_safe_sleep_conditional().
Referenced by _ast_adsi_transmit_message_full(), alarmreceiver_exec(), ast_dtmf_stream(), ast_senddigit(), builtin_atxfer(), builtin_parkcall(), conf_run(), dictate_exec(), disa_exec(), flash_exec(), function_ilink(), handle_callforward_button(), login_exec(), mgcp_ss(), milliwatt_exec(), misdn_check_l2l1(), old_milliwatt_exec(), park_call_exec(), pbx_builtin_wait(), play_moh_exec(), play_tone_pair(), playtone(), privacy_exec(), receive_ademco_contact_id(), rpt_call(), rpt_exec(), rpt_tele_thread(), send_morse(), send_tone_telemetry(), skinny_ss(), ss_thread(), testclient_exec(), testserver_exec(), try_calling(), wait_for_hangup(), wait_interval(), wait_moh_exec(), waituntil_exec(), and zapateller_exec().
01325 { 01326 return ast_safe_sleep_conditional(chan, ms, NULL, NULL); 01327 }
| int ast_safe_sleep_conditional | ( | struct ast_channel * | chan, | |
| int | ms, | |||
| int(*)(void *) | cond, | |||
| void * | data | |||
| ) |
Wait, look for hangups and condition arg.
Wait for a specified amount of time, looking for hangups and a condition argument.
Definition at line 1303 of file channel.c.
References ast_frfree, ast_read(), ast_waitfor(), cond, and f.
Referenced by ast_safe_sleep(), and login_exec().
01304 { 01305 struct ast_frame *f; 01306 01307 while (ms > 0) { 01308 if (cond && ((*cond)(data) == 0)) 01309 return 0; 01310 ms = ast_waitfor(chan, ms); 01311 if (ms < 0) 01312 return -1; 01313 if (ms > 0) { 01314 f = ast_read(chan); 01315 if (!f) 01316 return -1; 01317 ast_frfree(f); 01318 } 01319 } 01320 return 0; 01321 }
| int ast_say_character_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 5757 of file channel.c.
References ast_say_character_str_full.
Referenced by common_exec(), pbx_builtin_saycharacters(), play_mailbox_owner(), rpt_tele_thread(), saycharstr(), and saynode().
05759 { 05760 return ast_say_character_str_full(chan, str, ints, lang, -1, -1); 05761 }
| int ast_say_digit_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 5751 of file channel.c.
References ast_say_digit_str_full.
Referenced by forward_message(), invent_message(), mgcp_ss(), pbx_builtin_saydigits(), play_message_callerid(), and ss_thread().
05753 { 05754 return ast_say_digit_str_full(chan, str, ints, lang, -1, -1); 05755 }
| int ast_say_digits | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 5745 of file channel.c.
References ast_say_digits_full().
Referenced by ast_park_call_full(), common_exec(), conf_exec(), conf_run(), parkandannounce_exec(), and rpt_tele_thread().
05747 { 05748 return ast_say_digits_full(chan, num, ints, lang, -1, -1); 05749 }
| int ast_say_digits_full | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| int | audiofd, | |||
| int | ctrlfd | |||
| ) |
Definition at line 5769 of file channel.c.
References ast_say_digit_str_full.
Referenced by ast_say_digits(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_number_full_cs(), ast_say_number_full_da(), ast_say_number_full_de(), ast_say_number_full_en(), ast_say_number_full_en_GB(), ast_say_number_full_es(), ast_say_number_full_fr(), ast_say_number_full_he(), ast_say_number_full_hu(), ast_say_number_full_it(), ast_say_number_full_ka(), ast_say_number_full_nl(), ast_say_number_full_no(), ast_say_number_full_pt(), ast_say_number_full_ru(), ast_say_number_full_se(), ast_say_number_full_th(), ast_say_number_full_zh(), and say_init_mode().
05771 { 05772 char buf[256]; 05773 05774 snprintf(buf, sizeof(buf), "%d", num); 05775 05776 return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd); 05777 }
| int ast_say_enumeration | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | language, | |||
| const char * | options | |||
| ) |
Definition at line 5739 of file channel.c.
References ast_say_enumeration_full.
Referenced by ast_say_date_da(), ast_say_date_de(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), and ast_say_date_with_format_pl().
05741 { 05742 return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1); 05743 }
| int ast_say_number | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | language, | |||
| const char * | options | |||
| ) |
Definition at line 5733 of file channel.c.
References ast_say_number_full.
Referenced by ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_hu(), ast_say_date_ka(), ast_say_date_nl(), ast_say_date_pt(), ast_say_date_th(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), ast_say_date_with_format_es(), ast_say_date_with_format_fr(), ast_say_date_with_format_it(), ast_say_date_with_format_nl(), ast_say_date_with_format_pl(), ast_say_date_with_format_pt(), ast_say_date_with_format_th(), ast_say_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_he(), ast_say_datetime_from_now_ka(), ast_say_datetime_from_now_pt(), ast_say_datetime_he(), ast_say_datetime_pt(), ast_say_datetime_th(), ast_say_datetime_zh(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_gr(), ast_say_time_hu(), ast_say_time_ka(), ast_say_time_nl(), ast_say_time_pt(), ast_say_time_pt_BR(), ast_say_time_th(), ast_say_time_zh(), bridge_playfile(), conf_exec(), conf_run(), count_exec(), dictate_exec(), get_folder(), gr_say_number_female(), pbx_builtin_saynumber(), play_message(), play_message_duration(), rpt_tele_thread(), say_and_wait(), say_position(), saynum(), try_calling(), vm_intro_gr(), vm_intro_he(), vm_intro_multilang(), vm_intro_pt(), and vm_intro_pt_BR().
05735 { 05736 return ast_say_number_full(chan, num, ints, language, options, -1, -1); 05737 }
| int ast_say_phonetic_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 5763 of file channel.c.
References ast_say_phonetic_str_full.
Referenced by pbx_builtin_sayphonetic().
05765 { 05766 return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1); 05767 }
| int ast_senddigit | ( | struct ast_channel * | chan, | |
| char | digit, | |||
| unsigned int | duration | |||
| ) |
Send a DTMF digit to a channel Send a DTMF digit to a channel.
| chan | channel to act upon | |
| digit | the DTMF digit to send, encoded in ASCII | |
| duration | the duration of the digit ending in ms |
Definition at line 3301 of file channel.c.
References AST_DEFAULT_EMULATE_DTMF_DURATION, ast_safe_sleep(), ast_senddigit_begin(), ast_senddigit_end(), ast_channel_tech::send_digit_begin, and ast_channel::tech.
Referenced by ast_dtmf_stream(), dial_exec_full(), do_dtmf_phone(), manager_play_dtmf(), and rpt_call().
03302 { 03303 if (chan->tech->send_digit_begin) { 03304 ast_senddigit_begin(chan, digit); 03305 ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03306 } 03307 03308 return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03309 }
| int ast_senddigit_begin | ( | struct ast_channel * | chan, | |
| char | digit | |||
| ) |
Send a DTMF digit to a channel Send a DTMF digit to a channel.
| chan | channel to act upon | |
| digit | the DTMF digit to send, encoded in ASCII |
Definition at line 3243 of file channel.c.
References ast_debug, ast_playtones_start(), ast_channel::name, ast_channel_tech::send_digit_begin, and ast_channel::tech.
Referenced by agent_digit_begin(), ast_senddigit(), and ast_write().
03244 { 03245 /* Device does not support DTMF tones, lets fake 03246 * it by doing our own generation. */ 03247 static const char* dtmf_tones[] = { 03248 "941+1336", /* 0 */ 03249 "697+1209", /* 1 */ 03250 "697+1336", /* 2 */ 03251 "697+1477", /* 3 */ 03252 "770+1209", /* 4 */ 03253 "770+1336", /* 5 */ 03254 "770+1477", /* 6 */ 03255 "852+1209", /* 7 */ 03256 "852+1336", /* 8 */ 03257 "852+1477", /* 9 */ 03258 "697+1633", /* A */ 03259 "770+1633", /* B */ 03260 "852+1633", /* C */ 03261 "941+1633", /* D */ 03262 "941+1209", /* * */ 03263 "941+1477" /* # */ 03264 }; 03265 03266 if (!chan->tech->send_digit_begin) 03267 return 0; 03268 03269 if (!chan->tech->send_digit_begin(chan, digit)) 03270 return 0; 03271 03272 if (digit >= '0' && digit <='9') 03273 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0); 03274 else if (digit >= 'A' && digit <= 'D') 03275 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0); 03276 else if (digit == '*') 03277 ast_playtones_start(chan, 0, dtmf_tones[14], 0); 03278 else if (digit == '#') 03279 ast_playtones_start(chan, 0, dtmf_tones[15], 0); 03280 else { 03281 /* not handled */ 03282 ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name); 03283 } 03284 03285 return 0; 03286 }
| int ast_senddigit_end | ( | struct ast_channel * | chan, | |
| char | digit, | |||
| unsigned int | duration | |||
| ) |
Send a DTMF digit to a channel.
Send a DTMF digit to a channel.
| chan | channel to act upon | |
| digit | the DTMF digit to send, encoded in ASCII | |
| duration | the duration of the digit ending in ms |
Definition at line 3288 of file channel.c.
References ast_playtones_stop(), ast_channel::generator, ast_channel_tech::send_digit_end, and ast_channel::tech.
Referenced by agent_digit_end(), ast_senddigit(), and ast_write().
03289 { 03290 int res = -1; 03291 03292 if (chan->tech->send_digit_end) 03293 res = chan->tech->send_digit_end(chan, digit, duration); 03294 03295 if (res && chan->generator) 03296 ast_playtones_stop(chan); 03297 03298 return 0; 03299 }
| int ast_sendtext | ( | struct ast_channel * | chan, | |
| const char * | text | |||
| ) |
Sends text to a channel.
| chan | channel to act upon | |
| text | string of text to send on the channel |
| 0 | on success | |
| -1 | on failure |
Definition at line 3230 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_test_flag, CHECK_BLOCKING, ast_channel_tech::send_text, and ast_channel::tech.
Referenced by action_sendtext(), agent_sendtext(), handle_sendtext(), send_newkey(), and sendtext_exec().
03231 { 03232 int res = 0; 03233 /* Stop if we're a zombie or need a soft hangup */ 03234 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 03235 return -1; 03236 CHECK_BLOCKING(chan); 03237 if (chan->tech->send_text) 03238 res = chan->tech->send_text(chan, text); 03239 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03240 return res; 03241 }
| void ast_set_callerid | ( | struct ast_channel * | chan, | |
| const char * | cid_num, | |||
| const char * | cid_name, | |||
| const char * | cid_ani | |||
| ) |
Set caller ID number, name and ANI.
Definition at line 4588 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, and report_new_callerid().
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), callerid_write(), dahdi_read(), dial_exec_full(), disa_exec(), do_forward(), findmeexec(), handle_setcallerid(), mgcp_ss(), privacy_exec(), read_config(), rpt_exec(), skinny_newcall(), and ss_thread().
04589 { 04590 ast_channel_lock(chan); 04591 04592 if (cid_num) { 04593 if (chan->cid.cid_num) 04594 ast_free(chan->cid.cid_num); 04595 chan->cid.cid_num = ast_strdup(cid_num); 04596 } 04597 if (cid_name) { 04598 if (chan->cid.cid_name) 04599 ast_free(chan->cid.cid_name); 04600 chan->cid.cid_name = ast_strdup(cid_name); 04601 } 04602 if (cid_ani) { 04603 if (chan->cid.cid_ani) 04604 ast_free(chan->cid.cid_ani); 04605 chan->cid.cid_ani = ast_strdup(cid_ani); 04606 } 04607 04608 report_new_callerid(chan); 04609 04610 ast_channel_unlock(chan); 04611 }
| 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 3651 of file channel.c.
References ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().
Referenced by __ast_play_and_record(), __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_do_masquerade(), attempt_reconnect(), background_detect_exec(), build_conf(), conf_run(), connect_link(), dictate_exec(), do_waiting(), eagi_exec(), echo_exec(), gtalk_rtp_read(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), jingle_rtp_read(), login_exec(), measurenoise(), mgcp_rtp_read(), oh323_rtp_read(), old_milliwatt_exec(), process_sdp(), record_exec(), rpt(), rpt_exec(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), transmit_audio(), and unistim_rtp_read().
03652 { 03653 return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat, 03654 &chan->readtrans, 0); 03655 }
| 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 5510 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().
05511 { 05512 struct ast_variable *cur; 05513 05514 for (cur = vars; cur; cur = cur->next) 05515 pbx_builtin_setvar_helper(chan, cur->name, cur->value); 05516 }
| int ast_set_write_format | ( | struct ast_channel * | chan, | |
| int | format | |||
| ) |
Sets write format on channel chan Set write format for channel to whichever component of "format" is best.
| chan | channel to change | |
| format | new format for writing |
Definition at line 3657 of file channel.c.
References ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.
Referenced by __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_do_masquerade(), ast_openstream_full(), ast_stopstream(), attempt_reconnect(), build_conf(), chanspy_exec(), conf_run(), connect_link(), echo_exec(), extenspy_exec(), gtalk_rtp_read(), jack_exec(), jingle_rtp_read(), linear_alloc(), linear_release(), login_exec(), mgcp_rtp_read(), moh_alloc(), moh_files_release(), moh_release(), mp3_exec(), NBScat_exec(), oh323_rtp_read(), old_milliwatt_exec(), playtones_alloc(), playtones_release(), process_sdp(), rpt(), rpt_exec(), send_waveform_to_channel(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), tonepair_alloc(), tonepair_release(), transmit_audio(), and unistim_rtp_read().
03658 { 03659 return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat, 03660 &chan->writetrans, 1); 03661 }
| int ast_setstate | ( | struct ast_channel * | chan, | |
| enum ast_channel_state | state | |||
| ) |
Change the state of a channel.
Definition at line 4613 of file channel.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_copy_string(), AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), ast_state2str(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, ast_channel::name, name, S_OR, and ast_channel::uniqueid.
Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), agent_call(), alsa_answer(), ast_raw_answer(), cb_events(), check_availability(), console_answer(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), do_bridge_masquerade(), gtalk_call(), gtalk_newcall(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_response_invite(), handle_soft_key_event_message(), handle_stimulus_message(), iax2_call(), jingle_call(), jingle_newcall(), mgcp_answer(), mgcp_call(), mgcp_ss(), misdn_call(), misdn_indication(), nbs_call(), nbs_hangup(), oh323_answer(), oss_answer(), pbx_builtin_busy(), pbx_builtin_congestion(), phone_answer(), phone_call(), phone_exception(), phone_hangup(), phone_write(), release_chan(), release_chan_early(), sip_answer(), skinny_answer(), skinny_call(), skinny_newcall(), ss_thread(), unistim_answer(), unistim_call(), unistim_new(), unistim_ss(), update_state(), usbradio_answer(), and usbradio_call().
04614 { 04615 int oldstate = chan->_state; 04616 char name[AST_CHANNEL_NAME], *dashptr; 04617 04618 if (oldstate == state) 04619 return 0; 04620 04621 ast_copy_string(name, chan->name, sizeof(name)); 04622 if ((dashptr = strrchr(name, '-'))) { 04623 *dashptr = '\0'; 04624 } 04625 04626 chan->_state = state; 04627 04628 /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver 04629 * for this channel is using the callback method for device state. If we pass in an actual state here 04630 * we override what they are saying the state is and things go amuck. */ 04631 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 04632 04633 /* setstate used to conditionally report Newchannel; this is no more */ 04634 manager_event(EVENT_FLAG_CALL, 04635 "Newstate", 04636 "Channel: %s\r\n" 04637 "ChannelState: %d\r\n" 04638 "ChannelStateDesc: %s\r\n" 04639 "CallerIDNum: %s\r\n" 04640 "CallerIDName: %s\r\n" 04641 "Uniqueid: %s\r\n", 04642 chan->name, chan->_state, ast_state2str(chan->_state), 04643 S_OR(chan->cid.cid_num, ""), 04644 S_OR(chan->cid.cid_name, ""), 04645 chan->uniqueid); 04646 04647 return 0; 04648 }
| int ast_settimeout | ( | struct ast_channel * | c, | |
| unsigned int | rate, | |||
| int(*)(const void *data) | func, | |||
| void * | data | |||
| ) |
Enable or disable timer ticks for a channel.
| rate | number of timer ticks per second |
Call this function with a rate of 0 to turn off the timer ticks
Definition at line 2356 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, ast_timer_get_max_rate(), ast_timer_set_rate(), ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.
Referenced by ast_activate_generator(), ast_closestream(), ast_deactivate_generator(), ast_read_generator_actions(), ast_readaudio_callback(), and filestream_destructor().
02357 { 02358 int res; 02359 unsigned int real_rate = rate, max_rate; 02360 02361 ast_channel_lock(c); 02362 02363 if (c->timingfd == -1) { 02364 ast_channel_unlock(c); 02365 return -1; 02366 } 02367 02368 if (!func) { 02369 rate = 0; 02370 data = NULL; 02371 } 02372 02373 if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) { 02374 real_rate = max_rate; 02375 } 02376 02377 ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate); 02378 02379 res = ast_timer_set_rate(c->timer, real_rate); 02380 02381 c->timingfunc = func; 02382 c->timingdata = data; 02383 02384 ast_channel_unlock(c); 02385 02386 return res; 02387 }
| int ast_shutting_down | ( | void | ) |
Returns non-zero if Asterisk is being shut down.
Returns non-zero if Asterisk is being shut down
Definition at line 515 of file channel.c.
Referenced by handle_request_options().
00516 { 00517 return shutting_down; 00518 }
| int ast_softhangup | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Softly hangup a channel, lock.
Softly hangup up a channel.
Definition at line 1617 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().
Referenced by __ast_module_user_hangup_all(), __ast_pbx_run(), __unload_module(), action_hangup(), agent_hangup(), agent_logoff(), ast_begin_shutdown(), ast_dial_join(), birdbath(), conf_free(), connect_link(), dahdi_handle_event(), flush_telem(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), login_exec(), manager_park(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), rpt_exec(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().
01618 { 01619 int res; 01620 01621 ast_channel_lock(chan); 01622 res = ast_softhangup_nolock(chan, cause); 01623 ast_channel_unlock(chan); 01624 01625 return res; 01626 }
| int ast_softhangup_nolock | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Softly hangup a channel, don't lock.
Softly hangup up a channel (no channel lock).
Definition at line 1604 of file channel.c.
References ast_channel::_softhangup, ast_debug, AST_FLAG_BLOCKING, ast_null_frame, ast_queue_frame(), ast_test_flag, ast_channel::blocker, and ast_channel::name.
Referenced by ast_async_goto(), ast_softhangup(), attempt_transfer(), check_rtp_timeout(), dahdi_softhangup_all(), oh323_indicate(), proc_session_timer(), sip_indicate(), and skinny_indicate().
01605 { 01606 ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name); 01607 /* Inform channel driver that we need to be hung up, if it cares */ 01608 chan->_softhangup |= cause; 01609 ast_queue_frame(chan, &ast_null_frame); 01610 /* Interrupt any poll call or such */ 01611 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) 01612 pthread_kill(chan->blocker, SIGURG); 01613 return 0; 01614 }
| const char* ast_state2str | ( | enum ast_channel_state | state | ) |
Gives the string form of a given channel state.
Definition at line 656 of file channel.c.
References AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DIALING_OFFHOOK, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_threadstorage_get(), STATE2STR_BUFSIZE, and state2str_threadbuf.
Referenced by __ast_channel_alloc_ap(), action_coreshowchannels(), action_status(), agent_hangup(), ast_do_masquerade(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_invite_replaces(), handle_showchan(), local_attended_transfer(), mgcp_new(), serialize_showchan(), and sip_hangup().
00657 { 00658 char *buf; 00659 00660 switch (state) { 00661 case AST_STATE_DOWN: 00662 return "Down"; 00663 case AST_STATE_RESERVED: 00664 return "Rsrvd"; 00665 case AST_STATE_OFFHOOK: 00666 return "OffHook"; 00667 case AST_STATE_DIALING: 00668 return "Dialing"; 00669 case AST_STATE_RING: 00670 return "Ring"; 00671 case AST_STATE_RINGING: 00672 return "Ringing"; 00673 case AST_STATE_UP: 00674 return "Up"; 00675 case AST_STATE_BUSY: 00676 return "Busy"; 00677 case AST_STATE_DIALING_OFFHOOK: 00678 return "Dialing Offhook"; 00679 case AST_STATE_PRERING: 00680 return "Pre-ring"; 00681 default: 00682 if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE))) 00683 return "Unknown"; 00684 snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state); 00685 return buf; 00686 } 00687 }
| int ast_str2cause | ( | const char * | name | ) |
Convert a symbolic hangup cause to number.
Convert the string form of a cause code to a number
| name | string form of the cause Returns the cause code |
Definition at line 642 of file channel.c.
References ARRAY_LEN, and causes.
Referenced by pbx_builtin_hangup().
00643 { 00644 int x; 00645 00646 for (x = 0; x < ARRAY_LEN(causes); x++) 00647 if (!strncasecmp(causes[x].name, name, strlen(causes[x].name))) 00648 return causes[x].cause; 00649 00650 return -1; 00651 }
| 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 5385 of file channel.c.
References ast_frfree, ast_read(), ast_tonepair_start(), ast_waitfor(), f, and ast_channel::generatordata.
Referenced by zapateller_exec().
05386 { 05387 int res; 05388 05389 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol))) 05390 return res; 05391 05392 /* Give us some wiggle room */ 05393 while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { 05394 struct ast_frame *f = ast_read(chan); 05395 if (f) 05396 ast_frfree(f); 05397 else 05398 return -1; 05399 } 05400 return 0; 05401 }
| int ast_tonepair_start | ( | struct ast_channel * | chan, | |
| int | freq1, | |||
| int | freq2, | |||
| int | duration, | |||
| int | vol | |||
| ) |
Start a tone going
Definition at line 5367 of file channel.c.
References ast_activate_generator(), tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, tonepair, and tonepair_def::vol.
Referenced by ast_tonepair(), pbx_builtin_waitexten(), play_dialtone(), play_tone_pair(), rpt_tele_thread(), and sendnoise().
05368 { 05369 struct tonepair_def d = { 0, }; 05370 05371 d.freq1 = freq1; 05372 d.freq2 = freq2; 05373 d.duration = duration; 05374 d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */ 05375 if (ast_activate_generator(chan, &tonepair, &d)) 05376 return -1; 05377 return 0; 05378 }
| void ast_tonepair_stop | ( | struct ast_channel * | chan | ) |
Stop a tone from playing
Definition at line 5380 of file channel.c.
References ast_deactivate_generator().
Referenced by sendnoise().
05381 { 05382 ast_deactivate_generator(chan); 05383 }
| int ast_transfer |