#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/mod_format.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_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 | plc_ds |
| 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 | __init_state2str_threadbuf (void) |
| static void | adjust_frame_for_plc (struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore) |
| static void | apply_plc (struct ast_channel *chan, struct ast_frame *frame) |
| 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. | |
| struct ast_channel * | ast_channel_search_locked (int(*is_match)(struct ast_channel *, void *), void *data) |
| Search for a channel based on the passed channel matching callback (first match) and return it, locked. | |
| 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. | |
| int | ast_is_deferrable_frame (const struct ast_frame *frame) |
| Should we keep this frame for later? | |
| 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. | |
| int | ast_plc_reload (void) |
| Reload genericplc configuration value from codecs.conf. | |
| 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) |
| says digits of a string | |
| int | ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang) |
| says digits | |
| 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) |
| says an enumeration | |
| int | ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
| says a number | |
| 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 int | calc_monitor_jump (int samples, int sample_rate, int seek_rate) |
| calculates the number of samples to jump forward with in a monitor stream. | |
| 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 | plc_ds_destroy (void *data) |
| 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 { | |
| int cause | |
| const char * desc | |
| const char * name | |
| } | 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 struct ast_datastore_info | plc_ds_info |
| 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 93 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 96 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 100 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 1918 of file channel.c.
References ast_channel::_state, ast_channel_lock, ast_channel_unlock, AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_log(), ast_queue_frame_head(), ast_raw_answer(), ast_read(), AST_STATE_RING, AST_STATE_RINGING, ast_waitfor(), errno, frames, ast_frame::frametype, LOG_WARNING, MAX, ast_channel::name, and ast_frame::subclass.
Referenced by ast_answer(), dial_exec_full(), pbx_builtin_answer(), and pbx_builtin_incomplete().
01919 { 01920 int res = 0; 01921 enum ast_channel_state old_state; 01922 01923 old_state = chan->_state; 01924 if ((res = ast_raw_answer(chan, cdr_answer))) { 01925 return res; 01926 } 01927 01928 switch (old_state) { 01929 case AST_STATE_RINGING: 01930 case AST_STATE_RING: 01931 /* wait for media to start flowing, but don't wait any longer 01932 * than 'delay' or 500 milliseconds, whichever is longer 01933 */ 01934 do { 01935 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 01936 struct ast_frame *cur, *new; 01937 int ms = MAX(delay, 500); 01938 unsigned int done = 0; 01939 01940 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01941 01942 for (;;) { 01943 ms = ast_waitfor(chan, ms); 01944 if (ms < 0) { 01945 ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno)); 01946 res = -1; 01947 break; 01948 } 01949 if (ms == 0) { 01950 ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500)); 01951 break; 01952 } 01953 cur = ast_read(chan); 01954 if (!cur || ((cur->frametype == AST_FRAME_CONTROL) && 01955 (cur->subclass == AST_CONTROL_HANGUP))) { 01956 if (cur) { 01957 ast_frfree(cur); 01958 } 01959 res = -1; 01960 ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name); 01961 break; 01962 } 01963 01964 if ((new = ast_frisolate(cur)) != cur) { 01965 ast_frfree(cur); 01966 } 01967 01968 AST_LIST_INSERT_HEAD(&frames, new, frame_list); 01969 01970 /* if a specific delay period was requested, continue 01971 * until that delay has passed. don't stop just because 01972 * incoming media has arrived. 01973 */ 01974 if (delay) { 01975 continue; 01976 } 01977 01978 switch (new->frametype) { 01979 /* all of these frametypes qualify as 'media' */ 01980 case AST_FRAME_VOICE: 01981 case AST_FRAME_VIDEO: 01982 case AST_FRAME_TEXT: 01983 case AST_FRAME_DTMF_BEGIN: 01984 case AST_FRAME_DTMF_END: 01985 case AST_FRAME_IMAGE: 01986 case AST_FRAME_HTML: 01987 case AST_FRAME_MODEM: 01988 done = 1; 01989 break; 01990 case AST_FRAME_CONTROL: 01991 case AST_FRAME_IAX: 01992 case AST_FRAME_NULL: 01993 case AST_FRAME_CNG: 01994 break; 01995 } 01996 01997 if (done) { 01998 break; 01999 } 02000 } 02001 02002 if (res == 0) { 02003 ast_channel_lock(chan); 02004 while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) { 02005 ast_queue_frame_head(chan, cur); 02006 ast_frfree(cur); 02007 } 02008 ast_channel_unlock(chan); 02009 } 02010 } while (0); 02011 break; 02012 default: 02013 break; 02014 } 02015 02016 return res; 02017 }
| 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 984 of file channel.c.
References __ast_channel_alloc_ap().
00989 { 00990 va_list ap1, ap2; 00991 struct ast_channel *result; 00992 00993 va_start(ap1, name_fmt); 00994 va_start(ap2, name_fmt); 00995 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 00996 amaflag, file, line, function, name_fmt, ap1, ap2); 00997 va_end(ap1); 00998 va_end(ap2); 00999 01000 return result; 01001 }
| 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 772 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_get_channel_tech(), 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_strdupa, 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_get_name(), 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, chanlist::tech, ast_channel::timer, ast_channel::timingfd, ast_channel::uniqueid, and ast_channel::varshead.
Referenced by __ast_channel_alloc(), and ast_channel_alloc().
00776 { 00777 struct ast_channel *tmp; 00778 int x; 00779 int flags; 00780 struct varshead *headp; 00781 char *tech = "", *tech2 = NULL; 00782 00783 /* If shutting down, don't allocate any new channels */ 00784 if (shutting_down) { 00785 ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n"); 00786 return NULL; 00787 } 00788 00789 #if defined(__AST_DEBUG_MALLOC) 00790 if (!(tmp = __ast_calloc(1, sizeof(*tmp), file, line, function))) { 00791 return NULL; 00792 } 00793 #else 00794 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { 00795 return NULL; 00796 } 00797 #endif 00798 00799 if (!(tmp->sched = sched_context_create())) { 00800 ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"); 00801 ast_free(tmp); 00802 return NULL; 00803 } 00804 00805 if ((ast_string_field_init(tmp, 128))) { 00806 sched_context_destroy(tmp->sched); 00807 ast_free(tmp); 00808 return NULL; 00809 } 00810 00811 #ifdef HAVE_EPOLL 00812 tmp->epfd = epoll_create(25); 00813 #endif 00814 00815 for (x = 0; x < AST_MAX_FDS; x++) { 00816 tmp->fds[x] = -1; 00817 #ifdef HAVE_EPOLL 00818 tmp->epfd_data[x] = NULL; 00819 #endif 00820 } 00821 00822 if ((tmp->timer = ast_timer_open())) { 00823 if (strcmp(ast_timer_get_name(tmp->timer), "timerfd")) { 00824 needqueue = 0; 00825 } 00826 tmp->timingfd = ast_timer_fd(tmp->timer); 00827 } else { 00828 tmp->timingfd = -1; 00829 } 00830 00831 if (needqueue) { 00832 if (pipe(tmp->alertpipe)) { 00833 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n"); 00834 alertpipe_failed: 00835 if (tmp->timer) { 00836 ast_timer_close(tmp->timer); 00837 } 00838 00839 sched_context_destroy(tmp->sched); 00840 ast_string_field_free_memory(tmp); 00841 ast_free(tmp); 00842 return NULL; 00843 } else { 00844 flags = fcntl(tmp->alertpipe[0], F_GETFL); 00845 if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 00846 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00847 close(tmp->alertpipe[0]); 00848 close(tmp->alertpipe[1]); 00849 goto alertpipe_failed; 00850 } 00851 flags = fcntl(tmp->alertpipe[1], F_GETFL); 00852 if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) { 00853 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00854 close(tmp->alertpipe[0]); 00855 close(tmp->alertpipe[1]); 00856 goto alertpipe_failed; 00857 } 00858 } 00859 } else /* Make sure we've got it done right if they don't */ 00860 tmp->alertpipe[0] = tmp->alertpipe[1] = -1; 00861 00862 /* Always watch the alertpipe */ 00863 ast_channel_set_fd(tmp, AST_ALERT_FD, tmp->alertpipe[0]); 00864 /* And timing pipe */ 00865 ast_channel_set_fd(tmp, AST_TIMING_FD, tmp->timingfd); 00866 ast_string_field_set(tmp, name, "**Unknown**"); 00867 00868 /* Initial state */ 00869 tmp->_state = state; 00870 00871 tmp->streamid = -1; 00872 00873 tmp->fin = global_fin; 00874 tmp->fout = global_fout; 00875 00876 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) { 00877 ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 00878 ast_atomic_fetchadd_int(&uniqueint, 1)); 00879 } else { 00880 ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 00881 (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1)); 00882 } 00883 00884 tmp->cid.cid_name = ast_strdup(cid_name); 00885 tmp->cid.cid_num = ast_strdup(cid_num); 00886 00887 if (!ast_strlen_zero(name_fmt)) { 00888 char *slash, *slash2; 00889 /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call. 00890 * And they all use slightly different formats for their name string. 00891 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here. 00892 * This means, that the stringfields must have a routine that takes the va_lists directly, and 00893 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list. 00894 * This new function was written so this can be accomplished. 00895 */ 00896 ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2); 00897 tech = ast_strdupa(tmp->name); 00898 if ((slash = strchr(tech, '/'))) { 00899 if ((slash2 = strchr(slash + 1, '/'))) { 00900 tech2 = slash + 1; 00901 *slash2 = '\0'; 00902 } 00903 *slash = '\0'; 00904 } 00905 } 00906 00907 /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */ 00908 00909 /* These 4 variables need to be set up for the cdr_init() to work right */ 00910 if (amaflag) 00911 tmp->amaflags = amaflag; 00912 else 00913 tmp->amaflags = ast_default_amaflags; 00914 00915 if (!ast_strlen_zero(acctcode)) 00916 ast_string_field_set(tmp, accountcode, acctcode); 00917 else 00918 ast_string_field_set(tmp, accountcode, ast_default_accountcode); 00919 00920 if (!ast_strlen_zero(context)) 00921 ast_copy_string(tmp->context, context, sizeof(tmp->context)); 00922 else 00923 strcpy(tmp->context, "default"); 00924 00925 if (!ast_strlen_zero(exten)) 00926 ast_copy_string(tmp->exten, exten, sizeof(tmp->exten)); 00927 else 00928 strcpy(tmp->exten, "s"); 00929 00930 tmp->priority = 1; 00931 00932 tmp->cdr = ast_cdr_alloc(); 00933 ast_cdr_init(tmp->cdr, tmp); 00934 ast_cdr_start(tmp->cdr); 00935 00936 headp = &tmp->varshead; 00937 AST_LIST_HEAD_INIT_NOLOCK(headp); 00938 00939 ast_mutex_init(&tmp->lock_dont_use); 00940 00941 AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores); 00942 00943 ast_string_field_set(tmp, language, defaultlanguage); 00944 00945 tmp->tech = &null_tech; 00946 00947 ast_set_flag(tmp, AST_FLAG_IN_CHANNEL_LIST); 00948 00949 AST_RWLIST_WRLOCK(&channels); 00950 AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list); 00951 AST_RWLIST_UNLOCK(&channels); 00952 00953 /*\!note 00954 * and now, since the channel structure is built, and has its name, let's 00955 * call the manager event generator with this Newchannel event. This is the 00956 * proper and correct place to make this call, but you sure do have to pass 00957 * a lot of data into this func to do it here! 00958 */ 00959 if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) { 00960 manager_event(EVENT_FLAG_CALL, "Newchannel", 00961 "Channel: %s\r\n" 00962 "ChannelState: %d\r\n" 00963 "ChannelStateDesc: %s\r\n" 00964 "CallerIDNum: %s\r\n" 00965 "CallerIDName: %s\r\n" 00966 "AccountCode: %s\r\n" 00967 "Exten: %s\r\n" 00968 "Context: %s\r\n" 00969 "Uniqueid: %s\r\n", 00970 tmp->name, 00971 state, 00972 ast_state2str(state), 00973 S_OR(cid_num, ""), 00974 S_OR(cid_name, ""), 00975 tmp->accountcode, 00976 S_OR(exten, ""), 00977 S_OR(context, ""), 00978 tmp->uniqueid); 00979 } 00980 00981 return tmp; 00982 }
| static int __ast_queue_frame | ( | struct ast_channel * | chan, | |
| struct ast_frame * | fin, | |||
| int | head, | |||
| struct ast_frame * | after | |||
| ) | [static] |
Definition at line 1003 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_NULL, AST_FRAME_VIDEO, 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_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_test_flag, ast_timer_enable_continuous(), ast_channel::blocker, errno, f, 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().
01004 { 01005 struct ast_frame *f; 01006 struct ast_frame *cur; 01007 int blah = 1; 01008 unsigned int new_frames = 0; 01009 unsigned int new_voice_frames = 0; 01010 unsigned int queued_frames = 0; 01011 unsigned int queued_voice_frames = 0; 01012 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 01013 01014 ast_channel_lock(chan); 01015 01016 /* See if the last frame on the queue is a hangup, if so don't queue anything */ 01017 if ((cur = AST_LIST_LAST(&chan->readq)) && 01018 (cur->frametype == AST_FRAME_CONTROL) && 01019 (cur->subclass == AST_CONTROL_HANGUP)) { 01020 ast_channel_unlock(chan); 01021 return 0; 01022 } 01023 01024 /* Build copies of all the frames and count them */ 01025 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01026 for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 01027 if (!(f = ast_frdup(cur))) { 01028 if (AST_LIST_FIRST(&frames)) { 01029 ast_frfree(AST_LIST_FIRST(&frames)); 01030 } 01031 ast_channel_unlock(chan); 01032 return -1; 01033 } 01034 01035 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01036 new_frames++; 01037 if (f->frametype == AST_FRAME_VOICE) { 01038 new_voice_frames++; 01039 } 01040 } 01041 01042 /* Count how many frames exist on the queue */ 01043 AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) { 01044 queued_frames++; 01045 if (cur->frametype == AST_FRAME_VOICE) { 01046 queued_voice_frames++; 01047 } 01048 } 01049 01050 if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) { 01051 int count = 0; 01052 ast_log(LOG_WARNING, "Exceptionally long %squeue length queuing to %s\n", queued_frames + new_frames > 128 ? "" : "voice ", chan->name); 01053 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, cur, frame_list) { 01054 /* Save the most recent frame */ 01055 if (!AST_LIST_NEXT(cur, frame_list)) { 01056 break; 01057 } else if (cur->frametype == AST_FRAME_VOICE || cur->frametype == AST_FRAME_VIDEO || cur->frametype == AST_FRAME_NULL) { 01058 if (++count > 64) { 01059 break; 01060 } 01061 AST_LIST_REMOVE_CURRENT(frame_list); 01062 ast_frfree(cur); 01063 } 01064 } 01065 AST_LIST_TRAVERSE_SAFE_END; 01066 } 01067 01068 if (after) { 01069 AST_LIST_INSERT_LIST_AFTER(&chan->readq, &frames, after, frame_list); 01070 } else { 01071 if (head) { 01072 AST_LIST_APPEND_LIST(&frames, &chan->readq, frame_list); 01073 AST_LIST_HEAD_INIT_NOLOCK(&chan->readq); 01074 } 01075 AST_LIST_APPEND_LIST(&chan->readq, &frames, frame_list); 01076 } 01077 01078 if (chan->alertpipe[1] > -1) { 01079 if (write(chan->alertpipe[1], &blah, new_frames * sizeof(blah)) != (new_frames * sizeof(blah))) { 01080 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n", 01081 chan->name, queued_frames, strerror(errno)); 01082 } 01083 } else if (chan->timingfd > -1) { 01084 ast_timer_enable_continuous(chan->timer); 01085 } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01086 pthread_kill(chan->blocker, SIGURG); 01087 } 01088 01089 ast_channel_unlock(chan); 01090 01091 return 0; 01092 }
| static struct ast_frame* __ast_read | ( | struct ast_channel * | chan, | |
| int | dropaudio | |||
| ) | [static, read] |
Definition at line 2707 of file channel.c.
References __ast_queue_frame(), ast_channel::_softhangup, ast_channel::_state, ast_channel::alertpipe, ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), ast_bridged_channel(), 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_format_rate(), 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_control(), 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, calc_monitor_jump(), cause, 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_filestream::fmt, ast_format::format, 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().
02708 { 02709 struct ast_frame *f = NULL; /* the return value */ 02710 int blah; 02711 int prestate; 02712 int count = 0, cause = 0; 02713 02714 /* this function is very long so make sure there is only one return 02715 * point at the end (there are only two exceptions to this). 02716 */ 02717 while(ast_channel_trylock(chan)) { 02718 if(count++ > 10) 02719 /*cannot goto done since the channel is not locked*/ 02720 return &ast_null_frame; 02721 usleep(1); 02722 } 02723 02724 if (chan->masq) { 02725 if (ast_do_masquerade(chan)) 02726 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 02727 else 02728 f = &ast_null_frame; 02729 goto done; 02730 } 02731 02732 /* Stop if we're a zombie or need a soft hangup */ 02733 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 02734 if (chan->generator) 02735 ast_deactivate_generator(chan); 02736 02737 /* It is possible for chan->_softhangup to be set, yet there still be control 02738 * frames that still need to be read. Instead of just going to 'done' in the 02739 * case of ast_check_hangup(), we instead need to send the HANGUP frame so that 02740 * it can mark the end of the read queue. If there are frames to be read, 02741 * ast_queue_control will be called repeatedly, but will only queue one hangup 02742 * frame. */ 02743 if (ast_check_hangup(chan)) { 02744 ast_queue_control(chan, AST_CONTROL_HANGUP); 02745 } else { 02746 goto done; 02747 } 02748 } 02749 02750 #ifdef AST_DEVMODE 02751 /* 02752 * The ast_waitfor() code records which of the channel's file descriptors reported that 02753 * data is available. In theory, ast_read() should only be called after ast_waitfor() 02754 * reports that a channel has data available for reading. However, there still may be 02755 * some edge cases throughout the code where ast_read() is called improperly. This can 02756 * potentially cause problems, so if this is a developer build, make a lot of noise if 02757 * this happens so that it can be addressed. 02758 */ 02759 if (chan->fdno == -1) { 02760 ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n"); 02761 } 02762 #endif 02763 02764 prestate = chan->_state; 02765 02766 /* Read and ignore anything on the alertpipe, but read only 02767 one sizeof(blah) per frame that we send from it */ 02768 if (chan->alertpipe[0] > -1) { 02769 int flags = fcntl(chan->alertpipe[0], F_GETFL); 02770 /* For some odd reason, the alertpipe occasionally loses nonblocking status, 02771 * which immediately causes a deadlock scenario. Detect and prevent this. */ 02772 if ((flags & O_NONBLOCK) == 0) { 02773 ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", chan->name); 02774 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 02775 ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 02776 f = &ast_null_frame; 02777 goto done; 02778 } 02779 } 02780 if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) { 02781 if (errno != EINTR && errno != EAGAIN) 02782 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); 02783 } 02784 } 02785 02786 if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD) { 02787 enum ast_timer_event res; 02788 02789 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02790 02791 res = ast_timer_get_event(chan->timer); 02792 02793 switch (res) { 02794 case AST_TIMING_EVENT_EXPIRED: 02795 ast_timer_ack(chan->timer, 1); 02796 02797 if (chan->timingfunc) { 02798 /* save a copy of func/data before unlocking the channel */ 02799 int (*func)(const void *) = chan->timingfunc; 02800 void *data = chan->timingdata; 02801 chan->fdno = -1; 02802 ast_channel_unlock(chan); 02803 func(data); 02804 } else { 02805 ast_timer_set_rate(chan->timer, 0); 02806 chan->fdno = -1; 02807 ast_channel_unlock(chan); 02808 } 02809 02810 /* cannot 'goto done' because the channel is already unlocked */ 02811 return &ast_null_frame; 02812 02813 case AST_TIMING_EVENT_CONTINUOUS: 02814 if (AST_LIST_EMPTY(&chan->readq) || 02815 !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) { 02816 ast_timer_disable_continuous(chan->timer); 02817 } 02818 break; 02819 } 02820 02821 } else if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) { 02822 /* if the AST_GENERATOR_FD is set, call the generator with args 02823 * set to -1 so it can do whatever it needs to. 02824 */ 02825 void *tmp = chan->generatordata; 02826 chan->generatordata = NULL; /* reset to let ast_write get through */ 02827 chan->generator->generate(chan, tmp, -1, -1); 02828 chan->generatordata = tmp; 02829 f = &ast_null_frame; 02830 chan->fdno = -1; 02831 goto done; 02832 } 02833 02834 /* Check for pending read queue */ 02835 if (!AST_LIST_EMPTY(&chan->readq)) { 02836 int skip_dtmf = should_skip_dtmf(chan); 02837 02838 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, f, frame_list) { 02839 /* We have to be picky about which frame we pull off of the readq because 02840 * there are cases where we want to leave DTMF frames on the queue until 02841 * some later time. */ 02842 02843 if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) { 02844 continue; 02845 } 02846 02847 AST_LIST_REMOVE_CURRENT(frame_list); 02848 break; 02849 } 02850 AST_LIST_TRAVERSE_SAFE_END; 02851 02852 if (!f) { 02853 /* There were no acceptable frames on the readq. */ 02854 f = &ast_null_frame; 02855 if (chan->alertpipe[0] > -1) { 02856 int poke = 0; 02857 /* Restore the state of the alertpipe since we aren't ready for any 02858 * of the frames in the readq. */ 02859 if (write(chan->alertpipe[1], &poke, sizeof(poke)) != sizeof(poke)) { 02860 ast_log(LOG_ERROR, "Failed to write to alertpipe: %s\n", strerror(errno)); 02861 } 02862 } 02863 } 02864 02865 /* Interpret hangup and return NULL */ 02866 /* XXX why not the same for frames from the channel ? */ 02867 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) { 02868 cause = f->data.uint32; 02869 ast_frfree(f); 02870 f = NULL; 02871 } 02872 } else { 02873 chan->blocker = pthread_self(); 02874 if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) { 02875 if (chan->tech->exception) 02876 f = chan->tech->exception(chan); 02877 else { 02878 ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name); 02879 f = &ast_null_frame; 02880 } 02881 /* Clear the exception flag */ 02882 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02883 } else if (chan->tech->read) 02884 f = chan->tech->read(chan); 02885 else 02886 ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name); 02887 } 02888 02889 /* 02890 * Reset the recorded file descriptor that triggered this read so that we can 02891 * easily detect when ast_read() is called without properly using ast_waitfor(). 02892 */ 02893 chan->fdno = -1; 02894 02895 if (f) { 02896 struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq); 02897 02898 /* if the channel driver returned more than one frame, stuff the excess 02899 into the readq for the next ast_read call 02900 */ 02901 if (AST_LIST_NEXT(f, frame_list)) { 02902 ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list)); 02903 ast_frfree(AST_LIST_NEXT(f, frame_list)); 02904 AST_LIST_NEXT(f, frame_list) = NULL; 02905 } 02906 02907 switch (f->frametype) { 02908 case AST_FRAME_CONTROL: 02909 if (f->subclass == AST_CONTROL_ANSWER) { 02910 if (!ast_test_flag(chan, AST_FLAG_OUTGOING)) { 02911 ast_debug(1, "Ignoring answer on an inbound call!\n"); 02912 ast_frfree(f); 02913 f = &ast_null_frame; 02914 } else if (prestate == AST_STATE_UP && ast_bridged_channel(chan)) { 02915 ast_debug(1, "Dropping duplicate answer!\n"); 02916 ast_frfree(f); 02917 f = &ast_null_frame; 02918 } else { 02919 /* Answer the CDR */ 02920 ast_setstate(chan, AST_STATE_UP); 02921 /* removed a call to ast_cdr_answer(chan->cdr) from here. */ 02922 } 02923 } 02924 break; 02925 case AST_FRAME_DTMF_END: 02926 send_dtmf_event(chan, "Received", f->subclass, "No", "Yes"); 02927 ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass, chan->name, f->len); 02928 /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */ 02929 if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) || ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 02930 queue_dtmf_readq(chan, f); 02931 ast_frfree(f); 02932 f = &ast_null_frame; 02933 } else if (!ast_test_flag(chan, AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) { 02934 if (!ast_tvzero(chan->dtmf_tv) && 02935 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02936 /* If it hasn't been long enough, defer this digit */ 02937 queue_dtmf_readq(chan, f); 02938 ast_frfree(f); 02939 f = &ast_null_frame; 02940 } else { 02941 /* There was no begin, turn this into a begin and send the end later */ 02942 f->frametype = AST_FRAME_DTMF_BEGIN; 02943 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02944 chan->emulate_dtmf_digit = f->subclass; 02945 chan->dtmf_tv = ast_tvnow(); 02946 if (f->len) { 02947 if (f->len > AST_MIN_DTMF_DURATION) 02948 chan->emulate_dtmf_duration = f->len; 02949 else 02950 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION; 02951 } else 02952 chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION; 02953 ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass, chan->emulate_dtmf_duration, chan->name); 02954 } 02955 if (chan->audiohooks) { 02956 struct ast_frame *old_frame = f; 02957 /*! 02958 * \todo XXX It is possible to write a digit to the audiohook twice 02959 * if the digit was originally read while the channel was in autoservice. */ 02960 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02961 if (old_frame != f) 02962 ast_frfree(old_frame); 02963 } 02964 } else { 02965 struct timeval now = ast_tvnow(); 02966 if (ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02967 ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass, chan->name); 02968 ast_clear_flag(chan, AST_FLAG_IN_DTMF); 02969 if (!f->len) 02970 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02971 02972 /* detect tones that were received on 02973 * the wire with durations shorter than 02974 * AST_MIN_DTMF_DURATION and set f->len 02975 * to the actual duration of the DTMF 02976 * frames on the wire. This will cause 02977 * dtmf emulation to be triggered later 02978 * on. 02979 */ 02980 if (ast_tvdiff_ms(now, chan->dtmf_tv) < AST_MIN_DTMF_DURATION) { 02981 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02982 ast_log(LOG_DTMF, "DTMF end '%c' detected to have actual duration %ld on the wire, emulation will be triggered on %s\n", f->subclass, f->len, chan->name); 02983 } 02984 } else if (!f->len) { 02985 ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass, chan->name); 02986 f->len = AST_MIN_DTMF_DURATION; 02987 } 02988 if (f->len < AST_MIN_DTMF_DURATION && !ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) { 02989 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); 02990 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02991 chan->emulate_dtmf_digit = f->subclass; 02992 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION - f->len; 02993 ast_frfree(f); 02994 f = &ast_null_frame; 02995 } else { 02996 ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass, chan->name); 02997 if (f->len < AST_MIN_DTMF_DURATION) { 02998 f->len = AST_MIN_DTMF_DURATION; 02999 } 03000 chan->dtmf_tv = now; 03001 } 03002 if (chan->audiohooks) { 03003 struct ast_frame *old_frame = f; 03004 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 03005 if (old_frame != f) 03006 ast_frfree(old_frame); 03007 } 03008 } 03009 break; 03010 case AST_FRAME_DTMF_BEGIN: 03011 send_dtmf_event(chan, "Received", f->subclass, "Yes", "No"); 03012 ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass, chan->name); 03013 if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) || 03014 (!ast_tvzero(chan->dtmf_tv) && 03015 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) ) { 03016 ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass, chan->name); 03017 ast_frfree(f); 03018 f = &ast_null_frame; 03019 } else { 03020 ast_set_flag(chan, AST_FLAG_IN_DTMF); 03021 chan->dtmf_tv = ast_tvnow(); 03022 ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass, chan->name); 03023 } 03024 break; 03025 case AST_FRAME_NULL: 03026 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 03027 * is reached , because we want to make sure we pass at least one 03028 * voice frame through before starting the next digit, to ensure a gap 03029 * between DTMF digits. */ 03030 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 03031 struct timeval now = ast_tvnow(); 03032 if (!chan->emulate_dtmf_duration) { 03033 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 03034 chan->emulate_dtmf_digit = 0; 03035 } else if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 03036 chan->emulate_dtmf_duration = 0; 03037 ast_frfree(f); 03038 f = &chan->dtmff; 03039 f->frametype = AST_FRAME_DTMF_END; 03040 f->subclass = chan->emulate_dtmf_digit; 03041 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 03042 chan->dtmf_tv = now; 03043 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 03044 chan->emulate_dtmf_digit = 0; 03045 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 03046 if (chan->audiohooks) { 03047 struct ast_frame *old_frame = f; 03048 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 03049 if (old_frame != f) { 03050 ast_frfree(old_frame); 03051 } 03052 } 03053 } 03054 } 03055 break; 03056 case AST_FRAME_VOICE: 03057 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 03058 * is reached , because we want to make sure we pass at least one 03059 * voice frame through before starting the next digit, to ensure a gap 03060 * between DTMF digits. */ 03061 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !chan->emulate_dtmf_duration) { 03062 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 03063 chan->emulate_dtmf_digit = 0; 03064 } 03065 03066 if (dropaudio || ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 03067 if (dropaudio) 03068 ast_read_generator_actions(chan, f); 03069 ast_frfree(f); 03070 f = &ast_null_frame; 03071 } 03072 03073 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 03074 struct timeval now = ast_tvnow(); 03075 if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 03076 chan->emulate_dtmf_duration = 0; 03077 ast_frfree(f); 03078 f = &chan->dtmff; 03079 f->frametype = AST_FRAME_DTMF_END; 03080 f->subclass = chan->emulate_dtmf_digit; 03081 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 03082 chan->dtmf_tv = now; 03083 if (chan->audiohooks) { 03084 struct ast_frame *old_frame = f; 03085 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 03086 if (old_frame != f) 03087 ast_frfree(old_frame); 03088 } 03089 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 03090 } else { 03091 /* Drop voice frames while we're still in the middle of the digit */ 03092 ast_frfree(f); 03093 f = &ast_null_frame; 03094 } 03095 } else if ((f->frametype == AST_FRAME_VOICE) && !(f->subclass & chan->nativeformats)) { 03096 /* This frame is not one of the current native formats -- drop it on the floor */ 03097 char to[200]; 03098 ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n", 03099 chan->name, ast_getformatname(f->subclass), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats)); 03100 ast_frfree(f); 03101 f = &ast_null_frame; 03102 } else if ((f->frametype == AST_FRAME_VOICE)) { 03103 /* Send frame to audiohooks if present */ 03104 if (chan->audiohooks) { 03105 struct ast_frame *old_frame = f; 03106 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 03107 if (old_frame != f) 03108 ast_frfree(old_frame); 03109 } 03110 if (chan->monitor && chan->monitor->read_stream ) { 03111 /* XXX what does this do ? */ 03112 #ifndef MONITOR_CONSTANT_DELAY 03113 int jump = chan->outsmpl - chan->insmpl - 4 * f->samples; 03114 if (jump >= 0) { 03115 jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03116 if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1) 03117 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 03118 chan->insmpl += (chan->outsmpl - chan->insmpl) + f->samples; 03119 } else 03120 chan->insmpl+= f->samples; 03121 #else 03122 int jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03123 if (jump - MONITOR_DELAY >= 0) { 03124 if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1) 03125 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 03126 chan->insmpl += chan->outsmpl - chan->insmpl; 03127 } else 03128 chan->insmpl += f->samples; 03129 #endif 03130 if (chan->monitor->state == AST_MONITOR_RUNNING) { 03131 if (ast_writestream(chan->monitor->read_stream, f) < 0) 03132 ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n"); 03133 } 03134 } 03135 03136 if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) { 03137 f = &ast_null_frame; 03138 } 03139 03140 /* it is possible for the translation process on chan->readtrans to have 03141 produced multiple frames from the single input frame we passed it; if 03142 this happens, queue the additional frames *before* the frames we may 03143 have queued earlier. if the readq was empty, put them at the head of 03144 the queue, and if it was not, put them just after the frame that was 03145 at the end of the queue. 03146 */ 03147 if (AST_LIST_NEXT(f, frame_list)) { 03148 if (!readq_tail) { 03149 ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list)); 03150 } else { 03151 __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail); 03152 } 03153 ast_frfree(AST_LIST_NEXT(f, frame_list)); 03154 AST_LIST_NEXT(f, frame_list) = NULL; 03155 } 03156 03157 /* Run generator sitting on the line if timing device not available 03158 * and synchronous generation of outgoing frames is necessary */ 03159 ast_read_generator_actions(chan, f); 03160 } 03161 default: 03162 /* Just pass it on! */ 03163 break; 03164 } 03165 } else { 03166 /* Make sure we always return NULL in the future */ 03167 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03168 if (cause) 03169 chan->hangupcause = cause; 03170 if (chan->generator) 03171 ast_deactivate_generator(chan); 03172 /* We no longer End the CDR here */ 03173 } 03174 03175 /* High bit prints debugging */ 03176 if (chan->fin & DEBUGCHAN_FLAG) 03177 ast_frame_dump(chan->name, f, "<<"); 03178 chan->fin = FRAMECOUNT_INC(chan->fin); 03179 03180 done: 03181 if (chan->music_state && chan->generator && chan->generator->digit && f && f->frametype == AST_FRAME_DTMF_END) 03182 chan->generator->digit(chan, f->subclass); 03183 03184 if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) { 03185 /* The list gets recreated if audiohooks are added again later */ 03186 ast_audiohook_detach_list(chan->audiohooks); 03187 chan->audiohooks = NULL; 03188 } 03189 ast_channel_unlock(chan); 03190 return f; 03191 }
| 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 4073 of file channel.c.
References ast_channel::_state, outgoing_helper::account, ast_call(), ast_call_forward(), AST_CAUSE_NO_ANSWER, ast_cdr_alloc(), ast_cdr_answer(), ast_cdr_busy(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), AST_CDR_FLAG_ORIGINATED, ast_cdr_init(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_copy_string(), AST_FRAME_CONTROL, ast_frfree, ast_hangup(), ast_log(), ast_read(), ast_request(), ast_set_callerid(), ast_set_flag, ast_set_variables(), AST_STATE_UP, ast_strlen_zero(), ast_waitfor(), ast_channel::call_forward, cause, ast_channel::cdr, 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().
04074 { 04075 int dummy_outstate; 04076 int cause = 0; 04077 struct ast_channel *chan; 04078 int res = 0; 04079 int last_subclass = 0; 04080 04081 if (outstate) 04082 *outstate = 0; 04083 else 04084 outstate = &dummy_outstate; /* make outstate always a valid pointer */ 04085 04086 chan = ast_request(type, format, data, &cause); 04087 if (!chan) { 04088 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data); 04089 handle_cause(cause, outstate); 04090 return NULL; 04091 } 04092 04093 if (oh) { 04094 if (oh->vars) 04095 ast_set_variables(chan, oh->vars); 04096 /* XXX why is this necessary, for the parent_channel perhaps ? */ 04097 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) 04098 ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); 04099 if (oh->parent_channel) { 04100 ast_channel_inherit_variables(oh->parent_channel, chan); 04101 ast_channel_datastore_inherit(oh->parent_channel, chan); 04102 } 04103 if (oh->account) 04104 ast_cdr_setaccount(chan, oh->account); 04105 } 04106 ast_set_callerid(chan, cid_num, cid_name, cid_num); 04107 ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED); 04108 04109 if (ast_call(chan, data, 0)) { /* ast_call failed... */ 04110 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data); 04111 } else { 04112 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */ 04113 while (timeout && chan->_state != AST_STATE_UP) { 04114 struct ast_frame *f; 04115 res = ast_waitfor(chan, timeout); 04116 if (res == 0) { /* timeout, treat it like ringing */ 04117 *outstate = AST_CONTROL_RINGING; 04118 break; 04119 } 04120 if (res < 0) /* error or done */ 04121 break; 04122 if (timeout > -1) 04123 timeout = res; 04124 if (!ast_strlen_zero(chan->call_forward)) { 04125 if (!(chan = ast_call_forward(NULL, chan, NULL, format, oh, outstate))) { 04126 return NULL; 04127 } 04128 continue; 04129 } 04130 04131 f = ast_read(chan); 04132 if (!f) { 04133 *outstate = AST_CONTROL_HANGUP; 04134 res = 0; 04135 break; 04136 } 04137 if (f->frametype == AST_FRAME_CONTROL) { 04138 switch (f->subclass) { 04139 case AST_CONTROL_RINGING: /* record but keep going */ 04140 *outstate = f->subclass; 04141 break; 04142 04143 case AST_CONTROL_BUSY: 04144 ast_cdr_busy(chan->cdr); 04145 *outstate = f->subclass; 04146 timeout = 0; 04147 break; 04148 04149 case AST_CONTROL_CONGESTION: 04150 ast_cdr_failed(chan->cdr); 04151 *outstate = f->subclass; 04152 timeout = 0; 04153 break; 04154 04155 case AST_CONTROL_ANSWER: 04156 ast_cdr_answer(chan->cdr); 04157 *outstate = f->subclass; 04158 timeout = 0; /* trick to force exit from the while() */ 04159 break; 04160 04161 /* Ignore these */ 04162 case AST_CONTROL_PROGRESS: 04163 case AST_CONTROL_PROCEEDING: 04164 case AST_CONTROL_HOLD: 04165 case AST_CONTROL_UNHOLD: 04166 case AST_CONTROL_VIDUPDATE: 04167 case AST_CONTROL_SRCUPDATE: 04168 case AST_CONTROL_SRCCHANGE: 04169 case -1: /* Ignore -- just stopping indications */ 04170 break; 04171 04172 default: 04173 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass); 04174 } 04175 last_subclass = f->subclass; 04176 } 04177 ast_frfree(f); 04178 } 04179 } 04180 04181 /* Final fixups */ 04182 if (oh) { 04183 if (!ast_strlen_zero(oh->context)) 04184 ast_copy_string(chan->context, oh->context, sizeof(chan->context)); 04185 if (!ast_strlen_zero(oh->exten)) 04186 ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten)); 04187 if (oh->priority) 04188 chan->priority = oh->priority; 04189 } 04190 if (chan->_state == AST_STATE_UP) 04191 *outstate = AST_CONTROL_ANSWER; 04192 04193 if (res <= 0) { 04194 if ( AST_CONTROL_RINGING == last_subclass ) 04195 chan->hangupcause = AST_CAUSE_NO_ANSWER; 04196 if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) 04197 ast_cdr_init(chan->cdr, chan); 04198 if (chan->cdr) { 04199 char tmp[256]; 04200 snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data); 04201 ast_cdr_setapp(chan->cdr,"Dial",tmp); 04202 ast_cdr_update(chan); 04203 ast_cdr_start(chan->cdr); 04204 ast_cdr_end(chan->cdr); 04205 /* If the cause wasn't handled properly */ 04206 if (ast_cdr_disposition(chan->cdr,chan->hangupcause)) 04207 ast_cdr_failed(chan->cdr); 04208 } 04209 ast_hangup(chan); 04210 chan = NULL; 04211 } 04212 return chan; 04213 }
| static void __init_state2str_threadbuf | ( | void | ) | [static] |
| static void adjust_frame_for_plc | ( | struct ast_channel * | chan, | |
| struct ast_frame * | frame, | |||
| struct ast_datastore * | datastore | |||
| ) | [static] |
Definition at line 3537 of file channel.c.
References ast_calloc, ast_channel_datastore_remove(), ast_datastore_free(), ast_free, AST_FRIENDLY_OFFSET, ast_frame::data, ast_datastore::data, ast_frame::datalen, plc_ds::num_samples, ast_frame::offset, plc_fillin(), plc_rx(), plc_ds::plc_state, ast_frame::ptr, ast_frame::samples, and plc_ds::samples_buf.
Referenced by apply_plc().
03538 { 03539 int num_new_samples = frame->samples; 03540 struct plc_ds *plc = datastore->data; 03541 03542 /* As a general note, let me explain the somewhat odd calculations used when taking 03543 * the frame offset into account here. According to documentation in frame.h, the frame's 03544 * offset field indicates the number of bytes that the audio is offset. The plc->samples_buf 03545 * is not an array of bytes, but rather an array of 16-bit integers since it holds SLIN 03546 * samples. So I had two choices to make here with the offset. 03547 * 03548 * 1. Make the offset AST_FRIENDLY_OFFSET bytes. The main downside for this is that 03549 * I can't just add AST_FRIENDLY_OFFSET to the plc->samples_buf and have the pointer 03550 * arithmetic come out right. I would have to do some odd casting or division for this to 03551 * work as I wanted. 03552 * 2. Make the offset AST_FRIENDLY_OFFSET * 2 bytes. This allows the pointer arithmetic 03553 * to work out better with the plc->samples_buf. The downside here is that the buffer's 03554 * allocation contains an extra 64 bytes of unused space. 03555 * 03556 * I decided to go with option 2. This is why in the calloc statement and the statement that 03557 * sets the frame's offset, AST_FRIENDLY_OFFSET is multiplied by 2. 03558 */ 03559 03560 /* If this audio frame has no samples to fill in, ignore it */ 03561 if (!num_new_samples) { 03562 return; 03563 } 03564 03565 /* First, we need to be sure that our buffer is large enough to accomodate 03566 * the samples we need to fill in. This will likely only occur on the first 03567 * frame we write. 03568 */ 03569 if (plc->num_samples < num_new_samples) { 03570 ast_free(plc->samples_buf); 03571 plc->samples_buf = ast_calloc(1, (num_new_samples * sizeof(*plc->samples_buf)) + (AST_FRIENDLY_OFFSET * 2)); 03572 if (!plc->samples_buf) { 03573 ast_channel_datastore_remove(chan, datastore); 03574 ast_datastore_free(datastore); 03575 return; 03576 } 03577 plc->num_samples = num_new_samples; 03578 } 03579 03580 if (frame->datalen == 0) { 03581 plc_fillin(&plc->plc_state, plc->samples_buf + AST_FRIENDLY_OFFSET, frame->samples); 03582 frame->data.ptr = plc->samples_buf + AST_FRIENDLY_OFFSET; 03583 frame->datalen = num_new_samples * 2; 03584 frame->offset = AST_FRIENDLY_OFFSET * 2; 03585 } else { 03586 plc_rx(&plc->plc_state, frame->data.ptr, frame->samples); 03587 } 03588 }
| static void apply_plc | ( | struct ast_channel * | chan, | |
| struct ast_frame * | frame | |||
| ) | [static] |
Definition at line 3590 of file channel.c.
References adjust_frame_for_plc(), ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc, ast_datastore_free(), ast_datastore::data, and plc_ds_info.
Referenced by ast_write().
03591 { 03592 struct ast_datastore *datastore; 03593 struct plc_ds *plc; 03594 03595 datastore = ast_channel_datastore_find(chan, &plc_ds_info, NULL); 03596 if (datastore) { 03597 plc = datastore->data; 03598 adjust_frame_for_plc(chan, frame, datastore); 03599 return; 03600 } 03601 03602 datastore = ast_datastore_alloc(&plc_ds_info, NULL); 03603 if (!datastore) { 03604 return; 03605 } 03606 plc = ast_calloc(1, sizeof(*plc)); 03607 if (!plc) { 03608 ast_datastore_free(datastore); 03609 return; 03610 } 03611 datastore->data = plc; 03612 ast_channel_datastore_add(chan, datastore); 03613 adjust_frame_for_plc(chan, frame, datastore); 03614 }
| int ast_activate_generator | ( | struct ast_channel * | chan, | |
| struct ast_generator * | gen, | |||
| void * | params | |||
| ) |
Activate a given generator
Definition at line 2069 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().
02070 { 02071 int res = 0; 02072 02073 ast_channel_lock(chan); 02074 if (chan->generatordata) { 02075 if (chan->generator && chan->generator->release) 02076 chan->generator->release(chan, chan->generatordata); 02077 chan->generatordata = NULL; 02078 } 02079 if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) { 02080 res = -1; 02081 } 02082 if (!res) { 02083 ast_settimeout(chan, 50, generator_force, chan); 02084 chan->generator = gen; 02085 } 02086 ast_channel_unlock(chan); 02087 02088 ast_prod(chan); 02089 02090 return res; 02091 }
| int ast_active_channels | ( | void | ) |
returns number of active/allocated channels
Returns number of active/allocated channels
Definition at line 497 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by action_corestatus(), ast_var_channels(), ast_var_channels_table(), dahdi_restart(), handle_show_settings(), and quit_handler().
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 2019 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().
02020 { 02021 return __ast_answer(chan, 0, 1); 02022 }
| 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_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR16, AST_FORMAT_SPEEX, AST_FORMAT_ULAW, ast_log(), LOG_WARNING, and prefs.
Referenced by __oh323_new(), agent_call(), ast_codec_choose(), ast_iax2_new(), ast_speech_new(), bridge_make_compatible(), builtin_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), jingle_new(), local_new(), login_exec(), mgcp_new(), sip_new(), skinny_new(), skinny_set_rtp_peer(), socket_process(), start_rtp(), transmit_connect(), and unistim_new().
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 AST_FORMAT_SIREN14, 00723 AST_FORMAT_SIREN7, 00724 /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */ 00725 AST_FORMAT_G722, 00726 /*! Okay, well, signed linear is easy to translate into other stuff */ 00727 AST_FORMAT_SLINEAR16, 00728 AST_FORMAT_SLINEAR, 00729 /*! G.726 is standard ADPCM, in RFC3551 packing order */ 00730 AST_FORMAT_G726, 00731 /*! G.726 is standard ADPCM, in AAL2 packing order */ 00732 AST_FORMAT_G726_AAL2, 00733 /*! ADPCM has great sound quality and is still pretty easy to translate */ 00734 AST_FORMAT_ADPCM, 00735 /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to 00736 translate and sounds pretty good */ 00737 AST_FORMAT_GSM, 00738 /*! iLBC is not too bad */ 00739 AST_FORMAT_ILBC, 00740 /*! Speex is free, but computationally more expensive than GSM */ 00741 AST_FORMAT_SPEEX, 00742 /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough 00743 to use it */ 00744 AST_FORMAT_LPC10, 00745 /*! G.729a is faster than 723 and slightly less expensive */ 00746 AST_FORMAT_G729A, 00747 /*! Down to G.723.1 which is proprietary but at least designed for voice */ 00748 AST_FORMAT_G723_1, 00749 }; 00750 00751 /* Strip out video */ 00752 fmts &= AST_FORMAT_AUDIO_MASK; 00753 00754 /* Find the first preferred codec in the format given */ 00755 for (x = 0; x < ARRAY_LEN(prefs); x++) { 00756 if (fmts & prefs[x]) 00757 return prefs[x]; 00758 } 00759 00760 ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts); 00761 00762 return 0; 00763 }
| struct ast_channel* ast_bridged_channel | ( | struct ast_channel * | chan | ) | [read] |
Find bridged channel.
| chan | Current channel |
Definition at line 5003 of file channel.c.
References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.
Referenced by __ast_read(), __dahdi_exception(), _skinny_show_lines(), action_agents(), action_coreshowchannels(), agents_show(), agents_show_online(), ast_bridge_call(), ast_channel_masquerade(), ast_do_masquerade(), ast_rtp_set_vars(), ast_var_channel_bridge(), ast_var_channels_table(), attempt_transfer(), cb_events(), channel_spy(), check_bridge(), common_exec(), console_transfer(), create_jb(), dahdi_handle_event(), dahdi_hangup(), export_aoc_vars(), get_refer_info(), handle_chanlist(), handle_hd_hf(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_refer(), handle_showchan(), handle_soft_key_event_message(), handle_stimulus_message(), key_call(), key_dial_page(), local_attended_transfer(), local_queryoption(), mgcp_hangup(), mgcp_ss(), misdn_attempt_transfer(), mixmonitor_thread(), park_call_full(), schedule_delivery(), sip_hangup(), sip_set_rtp_peer(), skinny_transfer(), socket_process(), ss_thread(), start_spying(), startmon(), TransferCallStep1(), and unistim_hangup().
05004 { 05005 struct ast_channel *bridged; 05006 bridged = chan->_bridge; 05007 if (bridged && bridged->tech->bridged_channel) 05008 bridged = bridged->tech->bridged_channel(chan, bridged); 05009 return bridged; 05010 }
| 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 4276 of file channel.c.
References AST_CDR_FLAG_DIALED, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_set_flag, ast_test_flag, ast_channel_tech::call, ast_channel::cdr, and ast_channel::tech.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), attempt_reconnect(), begin_dial_channel(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), do_idle_thread(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_exec(), and wait_for_answer().
04277 { 04278 /* Place an outgoing call, but don't wait any longer than timeout ms before returning. 04279 If the remote end does not answer within the timeout, then do NOT hang up, but 04280 return anyway. */ 04281 int res = -1; 04282 /* Stop if we're a zombie or need a soft hangup */ 04283 ast_channel_lock(chan); 04284 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 04285 if (chan->cdr) { 04286 ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED); 04287 } 04288 if (chan->tech->call) 04289 res = chan->tech->call(chan, addr, timeout); 04290 ast_set_flag(chan, AST_FLAG_OUTGOING); 04291 } 04292 ast_channel_unlock(chan); 04293 return res; 04294 }
| 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 3996 of file channel.c.
References outgoing_helper::account, ast_channel::accountcode, accountcode, ast_call(), AST_CDR_FLAG_ORIGINATED, ast_cdr_setaccount(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_copy_flags, ast_copy_string(), ast_hangup(), ast_log(), ast_request(), ast_set_callerid(), ast_set_variables(), ast_string_field_set, ast_strlen_zero(), ast_channel::call_forward, cause, ast_channel::cdr, CHANNEL_DEADLOCK_AVOIDANCE, ast_channel::cid, ast_callerid::cid_name, outgoing_helper::cid_name, ast_callerid::cid_num, outgoing_helper::cid_num, ast_channel::context, handle_cause(), LOG_NOTICE, outgoing_helper::parent_channel, pbx_builtin_getvar_helper(), S_OR, type, and outgoing_helper::vars.
Referenced by __ast_request_and_dial(), and feature_request_and_dial().
03997 { 03998 char tmpchan[256]; 03999 struct ast_channel *new = NULL; 04000 char *data, *type; 04001 int cause = 0; 04002 int res; 04003 04004 /* gather data and request the new forward channel */ 04005 ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan)); 04006 if ((data = strchr(tmpchan, '/'))) { 04007 *data++ = '\0'; 04008 type = tmpchan; 04009 } else { 04010 const char *forward_context; 04011 ast_channel_lock(orig); 04012 forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT"); 04013 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context)); 04014 ast_channel_unlock(orig); 04015 data = tmpchan; 04016 type = "Local"; 04017 } 04018 if (!(new = ast_request(type, format, data, &cause))) { 04019 ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause); 04020 handle_cause(cause, outstate); 04021 ast_hangup(orig); 04022 return NULL; 04023 } 04024 04025 /* Copy/inherit important information into new channel */ 04026 if (oh) { 04027 if (oh->vars) { 04028 ast_set_variables(new, oh->vars); 04029 } 04030 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) { 04031 ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num); 04032 } 04033 if (oh->parent_channel) { 04034 ast_channel_inherit_variables(oh->parent_channel, new); 04035 ast_channel_datastore_inherit(oh->parent_channel, new); 04036 } 04037 if (oh->account) { 04038 ast_cdr_setaccount(new, oh->account); 04039 } 04040 } else if (caller) { /* no outgoing helper so use caller if avaliable */ 04041 ast_channel_inherit_variables(caller, new); 04042 ast_channel_datastore_inherit(caller, new); 04043 } 04044 04045 ast_channel_lock(orig); 04046 while (ast_channel_trylock(new)) { 04047 CHANNEL_DEADLOCK_AVOIDANCE(orig); 04048 } 04049 ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED); 04050 ast_string_field_set(new, accountcode, orig->accountcode); 04051 if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) { 04052 ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num); 04053 } 04054 ast_channel_unlock(new); 04055 ast_channel_unlock(orig); 04056 04057 /* call new channel */ 04058 res = ast_call(new, data, 0); 04059 if (timeout) { 04060 *timeout = res; 04061 } 04062 if (res) { 04063 ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data); 04064 ast_hangup(orig); 04065 ast_hangup(new); 04066 return NULL; 04067 } 04068 ast_hangup(orig); 04069 04070 return new; 04071 }
| 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, and causes.
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 4553 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().
04554 { 04555 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid); 04556 ast_string_field_set(chan, name, newname); 04557 }
| 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 6168 of file channel.c.
References __ast_channel_alloc_ap().
06172 { 06173 va_list ap1, ap2; 06174 struct ast_channel *result; 06175 06176 06177 va_start(ap1, name_fmt); 06178 va_start(ap2, name_fmt); 06179 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 06180 amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap1, ap2); 06181 va_end(ap1); 06182 va_end(ap2); 06183 06184 return result; 06185 }
| 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 5326 of file channel.c.
References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_make_compatible(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, ast_debug, AST_FEATURE_PLAY_WARNING, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_generic_bridge(), ast_indicate(), ast_log(), ast_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().
05328 { 05329 struct ast_channel *who = NULL; 05330 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 05331 int nativefailed=0; 05332 int firstpass; 05333 int o0nativeformats; 05334 int o1nativeformats; 05335 long time_left_ms=0; 05336 char caller_warning = 0; 05337 char callee_warning = 0; 05338 05339 if (c0->_bridge) { 05340 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 05341 c0->name, c0->_bridge->name); 05342 return -1; 05343 } 05344 if (c1->_bridge) { 05345 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 05346 c1->name, c1->_bridge->name); 05347 return -1; 05348 } 05349 05350 /* Stop if we're a zombie or need a soft hangup */ 05351 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 05352 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) 05353 return -1; 05354 05355 *fo = NULL; 05356 firstpass = config->firstpass; 05357 config->firstpass = 0; 05358 05359 if (ast_tvzero(config->start_time)) 05360 config->start_time = ast_tvnow(); 05361 time_left_ms = config->timelimit; 05362 05363 caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING); 05364 callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING); 05365 05366 if (config->start_sound && firstpass) { 05367 if (caller_warning) 05368 bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000); 05369 if (callee_warning) 05370 bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000); 05371 } 05372 05373 /* Keep track of bridge */ 05374 c0->_bridge = c1; 05375 c1->_bridge = c0; 05376 05377 05378 o0nativeformats = c0->nativeformats; 05379 o1nativeformats = c1->nativeformats; 05380 05381 if (config->feature_timer && !ast_tvzero(config->nexteventts)) { 05382 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000)); 05383 } else if (config->timelimit && firstpass) { 05384 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05385 if (caller_warning || callee_warning) 05386 config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000)); 05387 } 05388 05389 if (!c0->tech->send_digit_begin) 05390 ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY); 05391 if (!c1->tech->send_digit_begin) 05392 ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); 05393 manager_bridge_event(1, 1, c0, c1); 05394 05395 /* Before we enter in and bridge these two together tell them both the source of audio has changed */ 05396 ast_indicate(c0, AST_CONTROL_SRCCHANGE); 05397 ast_indicate(c1, AST_CONTROL_SRCCHANGE); 05398 05399 for (/* ever */;;) { 05400 struct timeval now = { 0, }; 05401 int to; 05402 05403 to = -1; 05404 05405 if (!ast_tvzero(config->nexteventts)) { 05406 now = ast_tvnow(); 05407 to = ast_tvdiff_ms(config->nexteventts, now); 05408 if (to <= 0) { 05409 if (!config->timelimit) { 05410 res = AST_BRIDGE_COMPLETE; 05411 break; 05412 } 05413 to = 0; 05414 } 05415 } 05416 05417 if (config->timelimit) { 05418 time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time); 05419 if (time_left_ms < to) 05420 to = time_left_ms; 05421 05422 if (time_left_ms <= 0) { 05423 if (caller_warning && config->end_sound) 05424 bridge_playfile(c0, c1, config->end_sound, 0); 05425 if (callee_warning && config->end_sound) 05426 bridge_playfile(c1, c0, config->end_sound, 0); 05427 *fo = NULL; 05428 if (who) 05429 *rc = who; 05430 res = 0; 05431 break; 05432 } 05433 05434 if (!to) { 05435 if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) { 05436 int t = (time_left_ms + 500) / 1000; /* round to nearest second */ 05437 if (caller_warning) 05438 bridge_playfile(c0, c1, config->warning_sound, t); 05439 if (callee_warning) 05440 bridge_playfile(c1, c0, config->warning_sound, t); 05441 } 05442 if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) 05443 config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000)); 05444 else 05445 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05446 } 05447 ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE); 05448 } 05449 05450 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 05451 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05452 c0->_softhangup = 0; 05453 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05454 c1->_softhangup = 0; 05455 c0->_bridge = c1; 05456 c1->_bridge = c0; 05457 ast_debug(1, "Unbridge signal received. Ending native bridge.\n"); 05458 continue; 05459 } 05460 05461 /* Stop if we're a zombie or need a soft hangup */ 05462 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 05463 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { 05464 *fo = NULL; 05465 if (who) 05466 *rc = who; 05467 res = 0; 05468 ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n", 05469 c0->name, c1->name, 05470 ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05471 ast_check_hangup(c0) ? "Yes" : "No", 05472 ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05473 ast_check_hangup(c1) ? "Yes" : "No"); 05474 break; 05475 } 05476 05477 update_bridge_vars(c0, c1); 05478 05479 bridge_play_sounds(c0, c1); 05480 05481 if (c0->tech->bridge && 05482 /* if < 1 ms remains use generic bridging for accurate timing */ 05483 (!config->timelimit || to > 1000 || to == 0) && 05484 (c0->tech->bridge == c1->tech->bridge) && 05485 !nativefailed && !c0->monitor && !c1->monitor && 05486 !c0->audiohooks && !c1->audiohooks && 05487 !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) { 05488 int timeoutms = to - 1000 > 0 ? to - 1000 : to; 05489 /* Looks like they share a bridge method and nothing else is in the way */ 05490 ast_set_flag(c0, AST_FLAG_NBRIDGE); 05491 ast_set_flag(c1, AST_FLAG_NBRIDGE); 05492 if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) { 05493 /* \todo XXX here should check that cid_num is not NULL */ 05494 manager_event(EVENT_FLAG_CALL, "Unlink", 05495 "Channel1: %s\r\n" 05496 "Channel2: %s\r\n" 05497 "Uniqueid1: %s\r\n" 05498 "Uniqueid2: %s\r\n" 05499 "CallerID1: %s\r\n" 05500 "CallerID2: %s\r\n", 05501 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05502 ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name); 05503 05504 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05505 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05506 05507 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05508 continue; 05509 05510 c0->_bridge = NULL; 05511 c1->_bridge = NULL; 05512 05513 return res; 05514 } else { 05515 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05516 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05517 } 05518 switch (res) { 05519 case AST_BRIDGE_RETRY: 05520 if (config->play_warning) { 05521 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 05522 } 05523 continue; 05524 default: 05525 ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name); 05526 /* fallthrough */ 05527 case AST_BRIDGE_FAILED_NOWARN: 05528 nativefailed++; 05529 break; 05530 } 05531 } 05532 05533 if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || 05534 (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && 05535 !(c0->generator || c1->generator)) { 05536 if (ast_channel_make_compatible(c0, c1)) { 05537 ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name); 05538 manager_bridge_event(0, 1, c0, c1); 05539 return AST_BRIDGE_FAILED; 05540 } 05541 o0nativeformats = c0->nativeformats; 05542 o1nativeformats = c1->nativeformats; 05543 } 05544 05545 update_bridge_vars(c0, c1); 05546 05547 res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts); 05548 if (res != AST_BRIDGE_RETRY) { 05549 break; 05550 } else if (config->feature_timer) { 05551 /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */ 05552 break; 05553 } 05554 } 05555 05556 ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY); 05557 ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY); 05558 05559 /* Now that we have broken the bridge the source will change yet again */ 05560 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 05561 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 05562 05563 c0->_bridge = NULL; 05564 c1->_bridge = NULL; 05565 05566 /* \todo XXX here should check that cid_num is not NULL */ 05567 manager_event(EVENT_FLAG_CALL, "Unlink", 05568 "Channel1: %s\r\n" 05569 "Channel2: %s\r\n" 05570 "Uniqueid1: %s\r\n" 05571 "Uniqueid2: %s\r\n" 05572 "CallerID1: %s\r\n" 05573 "CallerID2: %s\r\n", 05574 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05575 ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name); 05576 05577 return res; 05578 }
| 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 1602 of file channel.c.
References AST_LIST_INSERT_HEAD, and ast_channel::datastores.
Referenced by _macro_exec(), acf_curlopt_write(), acf_iaxvar_write(), acf_odbc_read(), add_features_datastores(), add_to_agi(), apply_plc(), ast_iax2_new(), audiohook_volume_get(), authenticate_reply(), dial_exec_full(), dundi_query_read(), enable_jack_hook(), enum_query_read(), find_transaction(), get_lock(), gosub_exec(), lua_get_state(), pbx_builtin_raise_exception(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), shared_write(), smdi_msg_retrieve_read(), socket_process(), speech_create(), speex_write(), try_calling(), and volume_write().
01603 { 01604 int res = 0; 01605 01606 AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry); 01607 01608 return res; 01609 }
| 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 1575 of file channel.c.
References ast_datastore_alloc.
01576 { 01577 return ast_datastore_alloc(info, uid); 01578 }
| 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 1616 of file channel.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel::datastores, ast_datastore::info, and ast_datastore::uid.
Referenced by _macro_exec(), acf_curl_exec(), acf_curlopt_read(), acf_curlopt_write(), acf_exception_read(), acf_fetch(), acf_iaxvar_read(), acf_iaxvar_write(), add_agi_cmd(), add_features_datastores(), add_to_agi(), apply_plc(), ast_odbc_retrieve_transaction_obj(), attended_transfer_occurred(), audiohook_volume_callback(), audiohook_volume_get(), builtin_atxfer(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), dundi_result_read(), enable_jack_hook(), enum_result_read(), exec_odbcfinish(), find_speech(), find_transaction(), func_inheritance_write(), get_agi_cmd(), get_lock(), gosub_exec(), handle_gosub(), iax2_call(), jack_hook_callback(), local_read(), local_write(), lock_fixup(), lua_get_state(), manage_parkinglot(), mark_transaction_active(), park_exec_full(), pbx_builtin_raise_exception(), pop_exec(), queue_transfer_fixup(), release_transaction(), return_exec(), shared_read(), shared_write(), smdi_msg_read(), speech_background(), speech_destroy(), speex_callback(), speex_read(), speex_write(), stop_mixmonitor_exec(), try_calling(), unlock_read(), volume_callback(), and volume_write().
01617 { 01618 struct ast_datastore *datastore = NULL; 01619 01620 if (info == NULL) 01621 return NULL; 01622 01623 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) { 01624 if (datastore->info != info) { 01625 continue; 01626 } 01627 01628 if (uid == NULL) { 01629 /* matched by type only */ 01630 break; 01631 } 01632 01633 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) { 01634 /* Matched by type AND uid */ 01635 break; 01636 } 01637 } 01638 AST_LIST_TRAVERSE_SAFE_END; 01639 01640 return datastore; 01641 }
| int ast_channel_datastore_free | ( | struct ast_datastore * | datastore | ) |
Free a channel data store object.
Definition at line 1580 of file channel.c.
References ast_datastore_free().
01581 { 01582 return ast_datastore_free(datastore); 01583 }
| int ast_channel_datastore_inherit | ( | struct ast_channel * | from, | |
| struct ast_channel * | to | |||
| ) |
Inherit datastores from a parent to a child.
Definition at line 1585 of file channel.c.
References ast_datastore_alloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_channel::datastores, ast_datastore_info::duplicate, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.
Referenced by __ast_request_and_dial(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), do_forward(), findmeexec(), local_call(), ring_entry(), and wait_for_answer().
01586 { 01587 struct ast_datastore *datastore = NULL, *datastore2; 01588 01589 AST_LIST_TRAVERSE(&from->datastores, datastore, entry) { 01590 if (datastore->inheritance > 0) { 01591 datastore2 = ast_datastore_alloc(datastore->info, datastore->uid); 01592 if (datastore2) { 01593 datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL; 01594 datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1; 01595 AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry); 01596 } 01597 } 01598 } 01599 return 0; 01600 }
| 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 1611 of file channel.c.
References AST_LIST_REMOVE, and ast_channel::datastores.
Referenced by acf_fetch(), adjust_frame_for_plc(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), exec_odbcfinish(), lua_get_state(), queue_transfer_fixup(), speech_background(), speech_destroy(), speex_write(), stop_mixmonitor_exec(), and try_calling().
01612 { 01613 return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1; 01614 }
| 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 1160 of file channel.c.
References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.
Referenced by __adsi_transmit_messages(), and find_cache().
01161 { 01162 int pre = 0; 01163 01164 if (chan) { 01165 pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF); 01166 ast_set_flag(chan, AST_FLAG_DEFER_DTMF); 01167 } 01168 return pre; 01169 }
| 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 5228 of file channel.c.
References ast_channel_tech::early_bridge, and ast_channel::tech.
Referenced by dial_exec_full(), and wait_for_answer().
05229 { 05230 /* Make sure we can early bridge, if not error out */ 05231 if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge))) 05232 return -1; 05233 05234 return c0->tech->early_bridge(c0, c1); 05235 }
| void ast_channel_free | ( | struct ast_channel * | chan | ) |
Free a channel structure.
Definition at line 1456 of file channel.c.
References ast_channel::alertpipe, ast_app_group_discard(), ast_cdr_discard(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), ast_datastore_free(), ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), AST_FLAG_IN_CHANNEL_LIST, ast_free, ast_frfree, ast_jb_destroy(), AST_LIST_REMOVE_HEAD, ast_log(), AST_MAX_FDS, ast_moh_cleanup(), ast_mutex_destroy(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_test_flag, ast_timer_close(), ast_tone_zone_unref(), ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, ast_channel::cid, ast_channel::datastores, f, free, free_cid(), ast_channel::lock_dont_use, LOG_WARNING, ast_channel::monitor, ast_channel::music_state, ast_channel::name, name, ast_channel::pbx, ast_channel::readq, ast_channel::readtrans, ast_channel::sched, sched_context_destroy(), ast_channel_monitor::stop, ast_channel::tech_pvt, ast_channel::timer, ast_channel::varshead, ast_channel::writetrans, and ast_channel::zone.
Referenced by acf_odbc_read(), acf_odbc_write(), action_getvar(), agent_cleanup(), agent_new(), ast_do_masquerade(), ast_hangup(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), bridge_request(), cli_odbc_read(), cli_odbc_write(), gtalk_newcall(), local_new(), make_email_file(), pbx_substitute_variables_helper_full(), rotate_file(), sendmail(), and sendpage().
01457 { 01458 int fd; 01459 #ifdef HAVE_EPOLL 01460 int i; 01461 #endif 01462 struct ast_var_t *vardata; 01463 struct ast_frame *f; 01464 struct varshead *headp; 01465 struct ast_datastore *datastore = NULL; 01466 char name[AST_CHANNEL_NAME], *dashptr; 01467 int inlist; 01468 01469 headp=&chan->varshead; 01470 01471 inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01472 if (inlist) { 01473 AST_RWLIST_WRLOCK(&channels); 01474 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01475 ast_debug(1, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01476 } 01477 /* Lock and unlock the channel just to be sure nobody has it locked still 01478 due to a reference retrieved from the channel list. */ 01479 ast_channel_lock(chan); 01480 ast_channel_unlock(chan); 01481 } 01482 01483 /* Get rid of each of the data stores on the channel */ 01484 ast_channel_lock(chan); 01485 while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry))) 01486 /* Free the data store */ 01487 ast_datastore_free(datastore); 01488 ast_channel_unlock(chan); 01489 01490 /* Lock and unlock the channel just to be sure nobody has it locked still 01491 due to a reference that was stored in a datastore. (i.e. app_chanspy) */ 01492 ast_channel_lock(chan); 01493 ast_channel_unlock(chan); 01494 01495 if (chan->tech_pvt) { 01496 ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); 01497 ast_free(chan->tech_pvt); 01498 } 01499 01500 if (chan->sched) 01501 sched_context_destroy(chan->sched); 01502 01503 ast_copy_string(name, chan->name, sizeof(name)); 01504 if ((dashptr = strrchr(name, '-'))) { 01505 *dashptr = '\0'; 01506 } 01507 01508 /* Stop monitoring */ 01509 if (chan->monitor) 01510 chan->monitor->stop( chan, 0 ); 01511 01512 /* If there is native format music-on-hold state, free it */ 01513 if (chan->music_state) 01514 ast_moh_cleanup(chan); 01515 01516 /* Free translators */ 01517 if (chan->readtrans) 01518 ast_translator_free_path(chan->readtrans); 01519 if (chan->writetrans) 01520 ast_translator_free_path(chan->writetrans); 01521 if (chan->pbx) 01522 ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); 01523 free_cid(&chan->cid); 01524 /* Close pipes if appropriate */ 01525 if ((fd = chan->alertpipe[0]) > -1) 01526 close(fd); 01527 if ((fd = chan->alertpipe[1]) > -1) 01528 close(fd); 01529 if (chan->timer) { 01530 ast_timer_close(chan->timer); 01531 } 01532 #ifdef HAVE_EPOLL 01533 for (i = 0; i < AST_MAX_FDS; i++) { 01534 if (chan->epfd_data[i]) 01535 free(chan->epfd_data[i]); 01536 } 01537 close(chan->epfd); 01538 #endif 01539 while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list))) 01540 ast_frfree(f); 01541 01542 /* loop over the variables list, freeing all data and deleting list items */ 01543 /* no need to lock the list, as the channel is already locked */ 01544 01545 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) 01546 ast_var_delete(vardata); 01547 01548 ast_app_group_discard(chan); 01549 01550 /* Destroy the jitterbuffer */ 01551 ast_jb_destroy(chan); 01552 01553 if (chan->cdr) { 01554 ast_cdr_discard(chan->cdr); 01555 chan->cdr = NULL; 01556 } 01557 01558 if (chan->zone) { 01559 chan->zone = ast_tone_zone_unref(chan->zone); 01560 } 01561 01562 ast_mutex_destroy(&chan->lock_dont_use); 01563 01564 ast_string_field_free_memory(chan); 01565 ast_free(chan); 01566 if (inlist) 01567 AST_RWLIST_UNLOCK(&channels); 01568 01569 /* Queue an unknown state, because, while we know that this particular 01570 * instance is dead, we don't know the state of all other possible 01571 * instances. */ 01572 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 01573 }
| 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 4559 of file channel.c.
References ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), ast_var_t::entries, and ast_channel::varshead.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), ring_entry(), and wait_for_answer().
04560 { 04561 struct ast_var_t *current, *newvar; 04562 const char *varname; 04563 04564 AST_LIST_TRAVERSE(&parent->varshead, current, entries) { 04565 int vartype = 0; 04566 04567 varname = ast_var_full_name(current); 04568 if (!varname) 04569 continue; 04570 04571 if (varname[0] == '_') { 04572 vartype = 1; 04573 if (varname[1] == '_') 04574 vartype = 2; 04575 } 04576 04577 switch (vartype) { 04578 case 1: 04579 newvar = ast_var_assign(&varname[1], ast_var_value(current)); 04580 if (newvar) { 04581 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04582 ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar)); 04583 } 04584 break; 04585 case 2: 04586 newvar = ast_var_assign(varname, ast_var_value(current)); 04587 if (newvar) { 04588 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04589 ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar)); 04590 } 04591 break; 04592 default: 04593 ast_debug(1, "Not copying variable %s.\n", ast_var_name(current)); 04594 break; 04595 } 04596 } 04597 }
| 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 4449 of file channel.c.
References ast_channel_make_compatible_helper().
Referenced by action_bridge(), app_exec(), ast_channel_bridge(), bridge_exec(), check_compat(), dial_exec_full(), do_forward(), multiplexed_bridge_join(), park_exec_full(), simple_bridge_join(), try_calling(), and wait_for_answer().
04450 { 04451 /* Some callers do not check return code, and we must try to set all call legs correctly */ 04452 int rc = 0; 04453 04454 /* Set up translation from the chan to the peer */ 04455 rc = ast_channel_make_compatible_helper(chan, peer); 04456 04457 if (rc < 0) 04458 return rc; 04459 04460 /* Set up translation from the peer to the chan */ 04461 rc = ast_channel_make_compatible_helper(peer, chan); 04462 04463 return rc; 04464 }
| 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 4404 of file channel.c.
References AST_FORMAT_AUDIO_MASK, AST_FORMAT_SLINEAR, ast_log(), ast_opt_generic_plc, 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().
04405 { 04406 int src; 04407 int dst; 04408 int use_slin; 04409 04410 if (from->readformat == to->writeformat && from->writeformat == to->readformat) { 04411 /* Already compatible! Moving on ... */ 04412 return 0; 04413 } 04414 04415 /* Set up translation from the 'from' channel to the 'to' channel */ 04416 src = from->nativeformats; 04417 dst = to->nativeformats; 04418 04419 /* If there's no audio in this call, don't bother with trying to find a translation path */ 04420 if ((src & AST_FORMAT_AUDIO_MASK) == 0 || (dst & AST_FORMAT_AUDIO_MASK) == 0) 04421 return 0; 04422 04423 if (ast_translator_best_choice(&dst, &src) < 0) { 04424 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", from->name, src, to->name, dst); 04425 return -1; 04426 } 04427 04428 /* if the best path is not 'pass through', then 04429 * transcoding is needed; if desired, force transcode path 04430 * to use SLINEAR between channels, but only if there is 04431 * no direct conversion available. If generic PLC is 04432 * desired, then transcoding via SLINEAR is a requirement 04433 */ 04434 use_slin = (src == AST_FORMAT_SLINEAR || dst == AST_FORMAT_SLINEAR); 04435 if ((src != dst) && (ast_opt_generic_plc || ast_opt_transcode_via_slin) && 04436 (ast_translate_path_steps(dst, src) != 1 || use_slin)) 04437 dst = AST_FORMAT_SLINEAR; 04438 if (ast_set_read_format(from, dst) < 0) { 04439 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", from->name, dst); 04440 return -1; 04441 } 04442 if (ast_set_write_format(to, dst) < 0) { 04443 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", to->name, dst); 04444 return -1; 04445 } 04446 return 0; 04447 }
| 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 4466 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().
04467 { 04468 int res = -1; 04469 struct ast_channel *final_orig, *final_clone, *base; 04470 04471 retrymasq: 04472 final_orig = original; 04473 final_clone = clonechan; 04474 04475 ast_channel_lock(original); 04476 while (ast_channel_trylock(clonechan)) { 04477 ast_channel_unlock(original); 04478 usleep(1); 04479 ast_channel_lock(original); 04480 } 04481 04482 /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent) 04483 and if so, we don't really want to masquerade it, but its proxy */ 04484 if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original)) 04485 final_orig = original->_bridge; 04486 04487 if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan)) 04488 final_clone = clonechan->_bridge; 04489 04490 if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) { 04491 final_clone = base; 04492 } 04493 04494 if ((final_orig != original) || (final_clone != clonechan)) { 04495 /* Lots and lots of deadlock avoidance. The main one we're competing with 04496 * is ast_write(), which locks channels recursively, when working with a 04497 * proxy channel. */ 04498 if (ast_channel_trylock(final_orig)) { 04499 ast_channel_unlock(clonechan); 04500 ast_channel_unlock(original); 04501 goto retrymasq; 04502 } 04503 if (ast_channel_trylock(final_clone)) { 04504 ast_channel_unlock(final_orig); 04505 ast_channel_unlock(clonechan); 04506 ast_channel_unlock(original); 04507 goto retrymasq; 04508 } 04509 ast_channel_unlock(clonechan); 04510 ast_channel_unlock(original); 04511 original = final_orig; 04512 clonechan = final_clone; 04513 } 04514 04515 if (original == clonechan) { 04516 ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); 04517 ast_channel_unlock(clonechan); 04518 ast_channel_unlock(original); 04519 return -1; 04520 } 04521 04522 ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n", 04523 clonechan->name, original->name); 04524 04525 if (!original->masqr && !original->masq && !clonechan->masq && !clonechan->masqr) { 04526 original->masq = clonechan; 04527 clonechan->masqr = original; 04528 ast_queue_frame(original, &ast_null_frame); 04529 ast_queue_frame(clonechan, &ast_null_frame); 04530 ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name); 04531 res = 0; 04532 } else if (original->masq) { 04533 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04534 original->masq->name, original->name); 04535 } else if (original->masqr) { 04536 /* not yet as a previously planned masq hasn't yet happened */ 04537 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04538 original->name, original->masqr->name); 04539 } else if (clonechan->masq) { 04540 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04541 clonechan->masq->name, clonechan->name); 04542 } else { /* (clonechan->masqr) */ 04543 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04544 clonechan->name, clonechan->masqr->name); 04545 } 04546 04547 ast_channel_unlock(clonechan); 04548 ast_channel_unlock(original); 04549 04550 return res; 04551 }
| 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 5594 of file channel.c.
References ast_log(), errno, LOG_ERROR, ast_channel_tech::queryoption, and ast_channel::tech.
Referenced by ast_channel_get_t38_state(), and local_queryoption().
05595 { 05596 if (!chan->tech->queryoption) { 05597 errno = ENOSYS; 05598 return -1; 05599 } 05600 05601 if (block) 05602 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 05603 05604 return chan->tech->queryoption(chan, option, data, datalen); 05605 }
| 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 3960 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().
03961 { 03962 switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */ 03963 { 03964 case 0: 03965 return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)"; 03966 case AST_CONTROL_HANGUP: 03967 return "Hangup"; 03968 case AST_CONTROL_RING: 03969 return "Local Ring"; 03970 case AST_CONTROL_RINGING: 03971 return "Remote end Ringing"; 03972 case AST_CONTROL_ANSWER: 03973 return "Remote end has Answered"; 03974 case AST_CONTROL_BUSY: 03975 return "Remote end is Busy"; 03976 case AST_CONTROL_CONGESTION: 03977 return "Congestion (circuits busy)"; 03978 default: 03979 return "Unknown Reason!!"; 03980 } 03981 }
| 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 }
| struct ast_channel* ast_channel_search_locked | ( | int(*)(struct ast_channel *, void *) | is_match, | |
| void * | data | |||
| ) | [read] |
Search for a channel based on the passed channel matching callback (first match) and return it, locked.
Search for a channel based on the passed channel matching callback Search for a channel based on the specified is_match callback, and return the first channel that we match. When returned, the channel will be locked. Note that the is_match callback is called with the passed channel locked, and should return 0 if there is no match, and non-zero if there is.
Definition at line 1324 of file channel.c.
References ast_channel_lock, ast_channel_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by ast_pickup_call(), pickup_by_exten(), pickup_by_mark(), and transmit_state_notify().
01325 { 01326 struct ast_channel *c = NULL; 01327 01328 AST_RWLIST_RDLOCK(&channels); 01329 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 01330 ast_channel_lock(c); 01331 if (is_match(c, data)) { 01332 break; 01333 } 01334 ast_channel_unlock(c); 01335 } 01336 AST_RWLIST_UNLOCK(&channels); 01337 01338 return c; 01339 }
| 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 4391 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().
04392 { 04393 if (chan->tech->send_html) 04394 return chan->tech->send_html(chan, subclass, data, datalen); 04395 return -1; 04396 }
| 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 4398 of file channel.c.
References ast_channel_sendhtml(), and AST_HTML_URL.
Referenced by dial_exec_full(), sendurl_exec(), and try_calling().
04399 { 04400 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1); 04401 }
| void ast_channel_set_fd | ( | struct ast_channel * | chan, | |
| int | which, | |||
| int | fd | |||
| ) |
Set the file descriptor on the channel
Definition at line 1644 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(), pri_assign_bearer(), pri_fixup_principle(), setformat(), sip_new(), skinny_new(), start_rtp(), and swap_subs().
01645 { 01646 #ifdef HAVE_EPOLL 01647 struct epoll_event ev; 01648 struct ast_epoll_data *aed = NULL; 01649 01650 if (chan->fds[which] > -1) { 01651 epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev); 01652 aed = chan->epfd_data[which]; 01653 } 01654 01655 /* If this new fd is valid, add it to the epoll */ 01656 if (fd > -1) { 01657 if (!aed && (!(aed = ast_calloc(1, sizeof(*aed))))) 01658 return; 01659 01660 chan->epfd_data[which] = aed; 01661 aed->chan = chan; 01662 aed->which = which; 01663 01664 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01665 ev.data.ptr = aed; 01666 epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev); 01667 } else if (aed) { 01668 /* We don't have to keep around this epoll data structure now */ 01669 free(aed); 01670 chan->epfd_data[which] = NULL; 01671 } 01672 #endif 01673 chan->fds[which] = fd; 01674 return; 01675 }
| 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 5581 of file channel.c.
References ast_log(), errno, LOG_ERROR, ast_channel_tech::setoption, and ast_channel::tech.
Referenced by ast_bridge_call(), common_exec(), conf_run(), dahdi_hangup(), dial_exec_full(), func_channel_write(), func_channel_write_real(), handle_tddmode(), play_record_review(), reset_volumes(), rpt(), rpt_exec(), set_listen_volume(), set_talk_volume(), try_calling(), and vm_forwardoptions().
05582 { 05583 if (!chan->tech->setoption) { 05584 errno = ENOSYS; 05585 return -1; 05586 } 05587 05588 if (block) 05589 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 05590 05591 return chan->tech->setoption(chan, option, data, datalen); 05592 }
| 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 5932 of file channel.c.
References ast_activate_generator(), ast_calloc, ast_debug, AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, and ast_channel::writeformat.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), ast_readstring_full(), ast_safe_sleep_conditional(), channel_spy(), record_exec(), TransferCallStep1(), waitfor_exec(), and waitforring_exec().
05933 { 05934 struct ast_silence_generator *state; 05935 05936 if (!(state = ast_calloc(1, sizeof(*state)))) { 05937 return NULL; 05938 } 05939 05940 state->old_write_format = chan->writeformat; 05941 05942 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { 05943 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n"); 05944 ast_free(state); 05945 return NULL; 05946 } 05947 05948 ast_activate_generator(chan, &silence_generator, state); 05949 05950 ast_debug(1, "Started silence generator on '%s'\n", chan->name); 05951 05952 return state; 05953 }
| 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 5955 of file channel.c.
References ast_deactivate_generator(), ast_debug, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_channel::name, and ast_silence_generator::old_write_format.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), ast_readstring_full(), ast_safe_sleep_conditional(), channel_spy(), HandleCallOutgoing(), key_dial_page(), record_exec(), unistim_hangup(), waitfor_exec(), and waitforring_exec().
05956 { 05957 if (!state) 05958 return; 05959 05960 ast_deactivate_generator(chan); 05961 05962 ast_debug(1, "Stopped silence generator on '%s'\n", chan->name); 05963 05964 if (ast_set_write_format(chan, state->old_write_format) < 0) 05965 ast_log(LOG_ERROR, "Could not return write format to its original state\n"); 05966 05967 ast_free(state); 05968 }
| 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 4386 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 1172 of file channel.c.
References ast_clear_flag, and AST_FLAG_DEFER_DTMF.
Referenced by __adsi_transmit_messages(), find_cache(), and rpt_call().
01173 { 01174 if (chan) 01175 ast_clear_flag(chan, AST_FLAG_DEFER_DTMF); 01176 }
| 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 1286 of file channel.c.
References channel_find_locked().
Referenced by action_coreshowchannels(), action_status(), ast_complete_channels(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), conf_exec(), func_channels_read(), handle_chanlist(), handle_core_set_debug_channel(), and next_channel().
01287 { 01288 return channel_find_locked(prev, NULL, 0, NULL, NULL); 01289 }
| void ast_channels_init | ( | void | ) |
Provided by channel.c
Definition at line 5851 of file channel.c.
References ARRAY_LEN, ast_cli_register_multiple(), ast_plc_reload(), and cli_channel.
Referenced by main().
05852 { 05853 ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel)); 05854 05855 ast_plc_reload(); 05856 }
| struct ast_variable* ast_channeltype_list | ( | void | ) | [read] |
return an ast_variable list of channeltypes
Definition at line 186 of file channel.c.
References AST_LIST_TRAVERSE, ast_variable_new(), ast_channel_tech::description, chanlist::tech, ast_channel_tech::type, and var.
Referenced by ast_var_channel_types(), and ast_var_channel_types_table().
00187 { 00188 struct chanlist *cl; 00189 struct ast_variable *var=NULL, *prev = NULL; 00190 AST_LIST_TRAVERSE(&backends, cl, list) { 00191 if (prev) { 00192 if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, ""))) 00193 prev = prev->next; 00194 } else { 00195 var = ast_variable_new(cl->tech->type, cl->tech->description, ""); 00196 prev = var; 00197 } 00198 } 00199 return var; 00200 }
| 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_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_indicate_data(), ast_raw_answer(), ast_readstring_full(), ast_recvtext(), ast_rtp_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), autoservice_run(), bridge_call_thread(), bridge_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_bridge(), common_exec(), conf_play(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), feature_request_and_dial(), findmeexec(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), local_fixup(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), rpt(), rpt_exec(), run_ras(), try_calling(), and wait_for_answer().
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 2024 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().
02025 { 02026 ast_channel_lock(chan); 02027 if (chan->generatordata) { 02028 if (chan->generator && chan->generator->release) 02029 chan->generator->release(chan, chan->generatordata); 02030 chan->generatordata = NULL; 02031 chan->generator = NULL; 02032 ast_channel_set_fd(chan, AST_GENERATOR_FD, -1); 02033 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 02034 ast_settimeout(chan, 0, NULL, NULL); 02035 } 02036 ast_channel_unlock(chan); 02037 }
| 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 4650 of file channel.c.
References ast_channel::_softhangup, ast_channel::_state, ast_channel::adsicpe, ast_channel::alertpipe, ast_app_group_update(), ast_bridged_channel(), ast_cause2str(), ast_channel_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_set_fd(), ast_channel_unlock, AST_CONTROL_SRCCHANGE, ast_copy_string(), ast_debug, AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_GENERATOR_FD, ast_indicate(), AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MAX_FDS, ast_null_frame, ast_queue_frame(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), AST_SOFTHANGUP_DEV, ast_state2str(), ast_string_field_set, ast_test_flag, AST_TIMING_FD, ast_channel::blocker, ast_channel::cdr, ast_datastore_info::chan_fixup, ast_channel::cid, clone_variables(), ast_datastore::data, ast_channel::datastores, errno, EVENT_FLAG_CALL, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_channel::hangupcause, ast_datastore::info, ast_channel::language, language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::musicclass, musicclass, name, ast_channel::name, ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::readq, report_new_callerid(), ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, ast_channel::uniqueid, ast_channel::visible_indication, and ast_channel::writeformat.
Referenced by __ast_read(), ast_async_goto(), ast_hangup(), ast_waitfor_nandfds(), ast_write(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), sip_park(), and sip_park_thread().
04651 { 04652 int x,i; 04653 int res=0; 04654 int origstate; 04655 struct ast_frame *current; 04656 const struct ast_channel_tech *t; 04657 void *t_pvt; 04658 struct ast_callerid tmpcid; 04659 struct ast_channel *clonechan = original->masq; 04660 struct ast_channel *bridged; 04661 struct ast_cdr *cdr; 04662 int rformat = original->readformat; 04663 int wformat = original->writeformat; 04664 char newn[AST_CHANNEL_NAME]; 04665 char orig[AST_CHANNEL_NAME]; 04666 char masqn[AST_CHANNEL_NAME]; 04667 char zombn[AST_CHANNEL_NAME]; 04668 04669 ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", 04670 clonechan->name, clonechan->_state, original->name, original->_state); 04671 04672 manager_event(EVENT_FLAG_CALL, "Masquerade", "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n", 04673 clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state)); 04674 04675 /* XXX This operation is a bit odd. We're essentially putting the guts of 04676 * the clone channel into the original channel. Start by killing off the 04677 * original channel's backend. While the features are nice, which is the 04678 * reason we're keeping it, it's still awesomely weird. XXX */ 04679 04680 /* We need the clone's lock, too */ 04681 ast_channel_lock(clonechan); 04682 04683 ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clonechan->name, &clonechan->lock_dont_use); 04684 04685 /* Having remembered the original read/write formats, we turn off any translation on either 04686 one */ 04687 free_translation(clonechan); 04688 free_translation(original); 04689 04690 04691 /* Unlink the masquerade */ 04692 original->masq = NULL; 04693 clonechan->masqr = NULL; 04694 04695 /* Save the original name */ 04696 ast_copy_string(orig, original->name, sizeof(orig)); 04697 /* Save the new name */ 04698 ast_copy_string(newn, clonechan->name, sizeof(newn)); 04699 /* Create the masq name */ 04700 snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn); 04701 04702 /* Copy the name from the clone channel */ 04703 ast_string_field_set(original, name, newn); 04704 04705 /* Mangle the name of the clone channel */ 04706 ast_string_field_set(clonechan, name, masqn); 04707 04708 /* Notify any managers of the change, first the masq then the other */ 04709 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clonechan->uniqueid); 04710 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); 04711 04712 /* Swap the technologies */ 04713 t = original->tech; 04714 original->tech = clonechan->tech; 04715 clonechan->tech = t; 04716 04717 /* Swap the cdrs */ 04718 cdr = original->cdr; 04719 original->cdr = clonechan->cdr; 04720 clonechan->cdr = cdr; 04721 04722 t_pvt = original->tech_pvt; 04723 original->tech_pvt = clonechan->tech_pvt; 04724 clonechan->tech_pvt = t_pvt; 04725 04726 /* Swap the alertpipes */ 04727 for (i = 0; i < 2; i++) { 04728 x = original->alertpipe[i]; 04729 original->alertpipe[i] = clonechan->alertpipe[i]; 04730 clonechan->alertpipe[i] = x; 04731 } 04732 04733 /* 04734 * Swap the readq's. The end result should be this: 04735 * 04736 * 1) All frames should be on the new (original) channel. 04737 * 2) Any frames that were already on the new channel before this 04738 * masquerade need to be at the end of the readq, after all of the 04739 * frames on the old (clone) channel. 04740 * 3) The alertpipe needs to get poked for every frame that was already 04741 * on the new channel, since we are now using the alert pipe from the 04742 * old (clone) channel. 04743 */ 04744 { 04745 AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq; 04746 AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL); 04747 04748 AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list); 04749 AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list); 04750 04751 while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) { 04752 AST_LIST_INSERT_TAIL(&original->readq, current, frame_list); 04753 if (original->alertpipe[1] > -1) { 04754 int poke = 0; 04755 04756 if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) { 04757 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 04758 } 04759 } 04760 } 04761 } 04762 04763 /* Swap the raw formats */ 04764 x = original->rawreadformat; 04765 original->rawreadformat = clonechan->rawreadformat; 04766 clonechan->rawreadformat = x; 04767 x = original->rawwriteformat; 04768 original->rawwriteformat = clonechan->rawwriteformat; 04769 clonechan->rawwriteformat = x; 04770 04771 clonechan->_softhangup = AST_SOFTHANGUP_DEV; 04772 04773 /* And of course, so does our current state. Note we need not 04774 call ast_setstate since the event manager doesn't really consider 04775 these separate. We do this early so that the clone has the proper 04776 state of the original channel. */ 04777 origstate = original->_state; 04778 original->_state = clonechan->_state; 04779 clonechan->_state = origstate; 04780 04781 if (clonechan->tech->fixup){ 04782 res = clonechan->tech->fixup(original, clonechan); 04783 if (res) 04784 ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name); 04785 } 04786 04787 /* Start by disconnecting the original's physical side */ 04788 if (clonechan->tech->hangup) 04789 res = clonechan->tech->hangup(clonechan); 04790 if (res) { 04791 ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n"); 04792 ast_channel_unlock(clonechan); 04793 return -1; 04794 } 04795 04796 snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); 04797 /* Mangle the name of the clone channel */ 04798 ast_string_field_set(clonechan, name, zombn); 04799 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clonechan->uniqueid); 04800 04801 /* Update the type. */ 04802 t_pvt = original->monitor; 04803 original->monitor = clonechan->monitor; 04804 clonechan->monitor = t_pvt; 04805 04806 /* Keep the same language. */ 04807 ast_string_field_set(original, language, clonechan->language); 04808 /* Copy the FD's other than the generator fd */ 04809 for (x = 0; x < AST_MAX_FDS; x++) { 04810 if (x != AST_GENERATOR_FD) 04811 ast_channel_set_fd(original, x, clonechan->fds[x]); 04812 } 04813 04814 ast_app_group_update(clonechan, original); 04815 04816 /* Move data stores over */ 04817 if (AST_LIST_FIRST(&clonechan->datastores)) { 04818 struct ast_datastore *ds; 04819 /* We use a safe traversal here because some fixup routines actually 04820 * remove the datastore from the list and free them. 04821 */ 04822 AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) { 04823 if (ds->info->chan_fixup) 04824 ds->info->chan_fixup(ds->data, clonechan, original); 04825 } 04826 AST_LIST_TRAVERSE_SAFE_END; 04827 AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry); 04828 } 04829 04830 clone_variables(original, clonechan); 04831 /* Presense of ADSI capable CPE follows clone */ 04832 original->adsicpe = clonechan->adsicpe; 04833 /* Bridge remains the same */ 04834 /* CDR fields remain the same */ 04835 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */ 04836 /* Application and data remain the same */ 04837 /* Clone exception becomes real one, as with fdno */ 04838 ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION)); 04839 original->fdno = clonechan->fdno; 04840 /* Schedule context remains the same */ 04841 /* Stream stuff stays the same */ 04842 /* Keep the original state. The fixup code will need to work with it most likely */ 04843 04844 /* Just swap the whole structures, nevermind the allocations, they'll work themselves 04845 out. */ 04846 tmpcid = original->cid; 04847 original->cid = clonechan->cid; 04848 clonechan->cid = tmpcid; 04849 report_new_callerid(original); 04850 04851 /* Restore original timing file descriptor */ 04852 ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd); 04853 04854 /* Our native formats are different now */ 04855 original->nativeformats = clonechan->nativeformats; 04856 04857 /* Context, extension, priority, app data, jump table, remain the same */ 04858 /* pvt switches. pbx stays the same, as does next */ 04859 04860 /* Set the write format */ 04861 ast_set_write_format(original, wformat); 04862 04863 /* Set the read format */ 04864 ast_set_read_format(original, rformat); 04865 04866 /* Copy the music class */ 04867 ast_string_field_set(original, musicclass, clonechan->musicclass); 04868 04869 ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat); 04870 04871 /* Okay. Last thing is to let the channel driver know about all this mess, so he 04872 can fix up everything as best as possible */ 04873 if (original->tech->fixup) { 04874 res = original->tech->fixup(clonechan, original); 04875 if (res) { 04876 ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n", 04877 original->tech->type, original->name); 04878 ast_channel_unlock(clonechan); 04879 return -1; 04880 } 04881 } else 04882 ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n", 04883 original->tech->type, original->name); 04884 04885 /* 04886 * If an indication is currently playing, maintain it on the channel 04887 * that is taking the place of original 04888 * 04889 * This is needed because the masquerade is swapping out in the internals 04890 * of this channel, and the new channel private data needs to be made 04891 * aware of the current visible indication (RINGING, CONGESTION, etc.) 04892 */ 04893 if (original->visible_indication) { 04894 ast_indicate(original, original->visible_indication); 04895 } 04896 04897 /* Now, at this point, the "clone" channel is totally F'd up. We mark it as 04898 a zombie so nothing tries to touch it. If it's already been marked as a 04899 zombie, then free it now (since it already is considered invalid). */ 04900 if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) { 04901 ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name); 04902 ast_channel_unlock(clonechan); 04903 manager_event(EVENT_FLAG_CALL, "Hangup", 04904 "Channel: %s\r\n" 04905 "Uniqueid: %s\r\n" 04906 "Cause: %d\r\n" 04907 "Cause-txt: %s\r\n", 04908 clonechan->name, 04909 clonechan->uniqueid, 04910 clonechan->hangupcause, 04911 ast_cause2str(clonechan->hangupcause) 04912 ); 04913 ast_channel_free(clonechan); 04914 } else { 04915 ast_debug(1, "Released clone lock on '%s'\n", clonechan->name); 04916 ast_set_flag(clonechan, AST_FLAG_ZOMBIE); 04917 ast_queue_frame(clonechan, &ast_null_frame); 04918 ast_channel_unlock(clonechan); 04919 } 04920 04921 /* Signal any blocker */ 04922 if (ast_test_flag(original, AST_FLAG_BLOCKING)) 04923 pthread_kill(original->blocker, SIGURG); 04924 ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state); 04925 04926 if ((bridged = ast_bridged_channel(original))) { 04927 ast_channel_lock(bridged); 04928 ast_indicate(bridged, AST_CONTROL_SRCCHANGE); 04929 ast_channel_unlock(bridged); 04930 } 04931 04932 ast_indicate(original, AST_CONTROL_SRCCHANGE); 04933 04934 return 0; 04935 }
| 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 5046 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_SRCCHANGE, 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().
05049 { 05050 /* Copy voice back and forth between the two channels. */ 05051 struct ast_channel *cs[3]; 05052 struct ast_frame *f; 05053 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 05054 int o0nativeformats; 05055 int o1nativeformats; 05056 int watch_c0_dtmf; 05057 int watch_c1_dtmf; 05058 void *pvt0, *pvt1; 05059 /* Indicates whether a frame was queued into a jitterbuffer */ 05060 int frame_put_in_jb = 0; 05061 int jb_in_use; 05062 int to; 05063 05064 cs[0] = c0; 05065 cs[1] = c1; 05066 pvt0 = c0->tech_pvt; 05067 pvt1 = c1->tech_pvt; 05068 o0nativeformats = c0->nativeformats; 05069 o1nativeformats = c1->nativeformats; 05070 watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0; 05071 watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1; 05072 05073 /* Check the need of a jitterbuffer for each channel */ 05074 jb_in_use = ast_jb_do_usecheck(c0, c1); 05075 if (jb_in_use) 05076 ast_jb_empty_and_reset(c0, c1); 05077 05078 ast_poll_channel_add(c0, c1); 05079 05080 if (config->feature_timer > 0 && ast_tvzero(config->nexteventts)) { 05081 /* calculate when the bridge should possibly break 05082 * if a partial feature match timed out */ 05083 config->partialfeature_timer = ast_tvadd(ast_tvnow(), ast_samp2tv(config->feature_timer, 1000)); 05084 } else { 05085 memset(&config->partialfeature_timer, 0, sizeof(config->partialfeature_timer)); 05086 } 05087 05088 for (;;) { 05089 struct ast_channel *who, *other; 05090 05091 if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) || 05092 (o0nativeformats != c0->nativeformats) || 05093 (o1nativeformats != c1->nativeformats)) { 05094 /* Check for Masquerade, codec changes, etc */ 05095 res = AST_BRIDGE_RETRY; 05096 break; 05097 } 05098 if (bridge_end.tv_sec) { 05099 to = ast_tvdiff_ms(bridge_end, ast_tvnow()); 05100 if (to <= 0) { 05101 if (config->timelimit) { 05102 res = AST_BRIDGE_RETRY; 05103 /* generic bridge ending to play warning */ 05104 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 05105 } else { 05106 res = AST_BRIDGE_COMPLETE; 05107 } 05108 break; 05109 } 05110 } else { 05111 /* If a feature has been started and the bridge is configured to 05112 * to not break, leave the channel bridge when the feature timer 05113 * time has elapsed so the DTMF will be sent to the other side. 05114 */ 05115 if (!ast_tvzero(config->partialfeature_timer)) { 05116 int diff = ast_tvdiff_ms(config->partialfeature_timer, ast_tvnow()); 05117 if (diff <= 0) { 05118 res = AST_BRIDGE_RETRY; 05119 break; 05120 } 05121 } 05122 to = -1; 05123 } 05124 /* Calculate the appropriate max sleep interval - in general, this is the time, 05125 left to the closest jb delivery moment */ 05126 if (jb_in_use) 05127 to = ast_jb_get_when_to_wakeup(c0, c1, to); 05128 who = ast_waitfor_n(cs, 2, &to); 05129 if (!who) { 05130 /* No frame received within the specified timeout - check if we have to deliver now */ 05131 if (jb_in_use) 05132 ast_jb_get_and_deliver(c0, c1); 05133 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 05134 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05135 c0->_softhangup = 0; 05136 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05137 c1->_softhangup = 0; 05138 c0->_bridge = c1; 05139 c1->_bridge = c0; 05140 } 05141 continue; 05142 } 05143 f = ast_read(who); 05144 if (!f) { 05145 *fo = NULL; 05146 *rc = who; 05147 ast_debug(1, "Didn't get a frame from channel: %s\n",who->name); 05148 break; 05149 } 05150 05151 other = (who == c0) ? c1 : c0; /* the 'other' channel */ 05152 /* Try add the frame info the who's bridged channel jitterbuff */ 05153 if (jb_in_use) 05154 frame_put_in_jb = !ast_jb_put(other, f); 05155 05156 if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) { 05157 int bridge_exit = 0; 05158 05159 switch (f->subclass) { 05160 case AST_CONTROL_HOLD: 05161 case AST_CONTROL_UNHOLD: 05162 case AST_CONTROL_VIDUPDATE: 05163 case AST_CONTROL_SRCUPDATE: 05164 case AST_CONTROL_SRCCHANGE: 05165 case AST_CONTROL_T38_PARAMETERS: 05166 ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen); 05167 if (jb_in_use) { 05168 ast_jb_empty_and_reset(c0, c1); 05169 } 05170 break; 05171 default: 05172 *fo = f; 05173 *rc = who; 05174 bridge_exit = 1; 05175 ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name); 05176 break; 05177 } 05178 if (bridge_exit) 05179 break; 05180 } 05181 if ((f->frametype == AST_FRAME_VOICE) || 05182 (f->frametype == AST_FRAME_DTMF_BEGIN) || 05183 (f->frametype == AST_FRAME_DTMF) || 05184 (f->frametype == AST_FRAME_VIDEO) || 05185 (f->frametype == AST_FRAME_IMAGE) || 05186 (f->frametype == AST_FRAME_HTML) || 05187 (f->frametype == AST_FRAME_MODEM) || 05188 (f->frametype == AST_FRAME_TEXT)) { 05189 /* monitored dtmf causes exit from bridge */ 05190 int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf; 05191 05192 if (monitored_source && 05193 (f->frametype == AST_FRAME_DTMF_END || 05194 f->frametype == AST_FRAME_DTMF_BEGIN)) { 05195 *fo = f; 05196 *rc = who; 05197 ast_debug(1, "Got DTMF %s on channel (%s)\n", 05198 f->frametype == AST_FRAME_DTMF_END ? "end" : "begin", 05199 who->name); 05200 05201 break; 05202 } 05203 /* Write immediately frames, not passed through jb */ 05204 if (!frame_put_in_jb) 05205 ast_write(other, f); 05206 05207 /* Check if we have to deliver now */ 05208 if (jb_in_use) 05209 ast_jb_get_and_deliver(c0, c1); 05210 } 05211 /* XXX do we want to pass on also frames not matched above ? */ 05212 ast_frfree(f); 05213 05214 #ifndef HAVE_EPOLL 05215 /* Swap who gets priority */ 05216 cs[2] = cs[0]; 05217 cs[0] = cs[1]; 05218 cs[1] = cs[2]; 05219 #endif 05220 } 05221 05222 ast_poll_channel_del(c0, c1); 05223 05224 return res; 05225 }
| 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 1311 of file channel.c.
References channel_find_locked().
01312 { 01313 return channel_find_locked(NULL, NULL, 0, context, exten); 01314 }
| 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 1292 of file channel.c.
References channel_find_locked().
Referenced by acf_import(), action_add_agi_cmd(), action_atxfer(), action_getvar(), action_hangup(), action_redirect(), action_sendtext(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), ast_bridge_call(), asyncgoto_exec(), change_monitor_action(), do_pause_or_unpause(), get_dahdi_channel_locked(), handle_channelstatus(), handle_cli_agi_add_cmd(), handle_core_set_debug_channel(), handle_getvariablefull(), handle_hangup(), handle_redirect(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), handle_softhangup(), manager_park(), manager_play_dtmf(), park_call_full(), pbx_builtin_importvar(), shared_read(), shared_write(), start_monitor_action(), and stop_monitor_action().
01293 { 01294 return channel_find_locked(NULL, name, 0, NULL, NULL); 01295 }
| 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 1298 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().
01299 { 01300 return channel_find_locked(NULL, name, namelen, NULL, NULL); 01301 }
| 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_channel_alloc_ap(), _ast_device_state(), and ast_var_channel_types_table().
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 5759 of file channel.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), LOG_ERROR, LOG_WARNING, and strsep().
Referenced by _parse(), build_device(), build_gateway(), build_peer(), config_parse_variables(), func_channel_write_real(), process_dahdi(), and read_agent_config().
05760 { 05761 char *piece; 05762 char *c; 05763 int start=0, finish=0, x; 05764 ast_group_t group = 0; 05765 05766 if (ast_strlen_zero(s)) 05767 return 0; 05768 05769 c = ast_strdupa(s); 05770 05771 while ((piece = strsep(&c, ","))) { 05772 if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) { 05773 /* Range */ 05774 } else if (sscanf(piece, "%30d", &start)) { 05775 /* Just one */ 05776 finish = start; 05777 } else { 05778 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece); 05779 continue; 05780 } 05781 for (x = start; x <= finish; x++) { 05782 if ((x > 63) || (x < 0)) { 05783 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x); 05784 } else 05785 group |= ((ast_group_t) 1 << x); 05786 } 05787 } 05788 return group; 05789 }
| int ast_hangup | ( | struct ast_channel * | chan | ) |
Hangup a channel.
Hang up a channel.
Definition at line 1758 of file channel.c.
References ast_assert, ast_audiohook_detach_list(), ast_autoservice_stop(), ast_cause2str(), ast_cdr_detach(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_DIALED, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_IN_CHANNEL_LIST, AST_FLAG_ZOMBIE, ast_log(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_cdr::disposition, EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_ERROR, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_generator::release, S_OR, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, ast_channel::uniqueid, and ast_channel::vstream.
Referenced by __ast_pbx_run(), __ast_request_and_dial(), __oh323_new(), action_bridge(), agent_hangup(), agent_read(), alsa_new(), answer_exec_run(), app_exec(), ast_async_goto(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial_channel(), bridge_call_thread(), bridge_channel_thread(), bridge_exec(), build_conf(), builtin_atxfer(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), connect_link(), console_new(), dahdi_handle_event(), dahdi_new(), destroy_conference_bridge(), dial_exec_full(), dial_transfer(), do_forward(), do_hang(), do_idle_thread(), feature_attended_transfer(), feature_request_and_dial(), findmeexec(), gtalk_new(), handle_call_forward(), handle_callforward_button(), handle_enbloc_call_message(), handle_frame(), handle_frame_ownerless(), handle_hd_hf(), handle_init_event(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_soft_key_event_message(), handle_stimulus_message(), handle_timeout_trip(), handle_transfer_button(), HandleCallOutgoing(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), jingle_new(), local_hangup(), manage_parkinglot(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), nbs_new(), oss_new(), park_exec_full(), parkandannounce_exec(), phone_new(), play_sound_file(), pri_dchannel(), 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().
01759 { 01760 int res = 0; 01761 01762 /* Don't actually hang up a channel that will masquerade as someone else, or 01763 if someone is going to masquerade as us */ 01764 ast_channel_lock(chan); 01765 01766 if (chan->audiohooks) { 01767 ast_audiohook_detach_list(chan->audiohooks); 01768 chan->audiohooks = NULL; 01769 } 01770 01771 ast_autoservice_stop(chan); 01772 01773 if (chan->masq) { 01774 if (ast_do_masquerade(chan)) 01775 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 01776 } 01777 01778 if (chan->masq) { 01779 ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name); 01780 ast_channel_unlock(chan); 01781 return 0; 01782 } 01783 /* If this channel is one which will be masqueraded into something, 01784 mark it as a zombie already, so we know to free it later */ 01785 if (chan->masqr) { 01786 ast_set_flag(chan, AST_FLAG_ZOMBIE); 01787 ast_channel_unlock(chan); 01788 return 0; 01789 } 01790 ast_channel_unlock(chan); 01791 01792 AST_RWLIST_WRLOCK(&channels); 01793 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01794 ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01795 } 01796 ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01797 AST_RWLIST_UNLOCK(&channels); 01798 01799 ast_channel_lock(chan); 01800 free_translation(chan); 01801 /* Close audio stream */ 01802 if (chan->stream) { 01803 ast_closestream(chan->stream); 01804 chan->stream = NULL; 01805 } 01806 /* Close video stream */ 01807 if (chan->vstream) { 01808 ast_closestream(chan->vstream); 01809 chan->vstream = NULL; 01810 } 01811 if (chan->sched) { 01812 sched_context_destroy(chan->sched); 01813 chan->sched = NULL; 01814 } 01815 01816 if (chan->generatordata) /* Clear any tone stuff remaining */ 01817 if (chan->generator && chan->generator->release) 01818 chan->generator->release(chan, chan->generatordata); 01819 chan->generatordata = NULL; 01820 chan->generator = NULL; 01821 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01822 ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " 01823 "is blocked by thread %ld in procedure %s! Expect a failure\n", 01824 (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); 01825 ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0); 01826 } 01827 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { 01828 ast_debug(1, "Hanging up channel '%s'\n", chan->name); 01829 if (chan->tech->hangup) 01830 res = chan->tech->hangup(chan); 01831 } else { 01832 ast_debug(1, "Hanging up zombie '%s'\n", chan->name); 01833 } 01834 01835 ast_channel_unlock(chan); 01836 manager_event(EVENT_FLAG_CALL, "Hangup", 01837 "Channel: %s\r\n" 01838 "Uniqueid: %s\r\n" 01839 "CallerIDNum: %s\r\n" 01840 "CallerIDName: %s\r\n" 01841 "Cause: %d\r\n" 01842 "Cause-txt: %s\r\n", 01843 chan->name, 01844 chan->uniqueid, 01845 S_OR(chan->cid.cid_num, "<unknown>"), 01846 S_OR(chan->cid.cid_name, "<unknown>"), 01847 chan->hangupcause, 01848 ast_cause2str(chan->hangupcause) 01849 ); 01850 01851 if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 01852 !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 01853 (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) { 01854 ast_channel_lock(chan); 01855 01856 ast_cdr_end(chan->cdr); 01857 ast_cdr_detach(chan->cdr); 01858 chan->cdr = NULL; 01859 ast_channel_unlock(chan); 01860 } 01861 01862 ast_channel_free(chan); 01863 01864 return res; 01865 }
| 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 3208 of file channel.c.
References ast_indicate_data().
Referenced by __ast_play_and_record(), agent_new(), alsa_call(), answer_trunk_chan(), ast_bridge_call(), ast_channel_bridge(), ast_do_masquerade(), ast_dtmf_stream(), ast_raw_answer(), attempt_transfer(), builtin_atxfer(), builtin_blindtransfer(), cli_console_answer(), conf_run(), console_call(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), finishup(), function_remote(), handle_callforward_button(), handle_frame(), handle_recordfile(), manage_parkinglot(), mgcp_ss(), monitor_dial(), oss_call(), park_call_full(), park_exec_full(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_proceeding(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), record_exec(), rpt(), rpt_exec(), say_periodic_announcement(), say_position(), send_waveform_to_channel(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), try_calling(), and wait_for_answer().
03209 { 03210 return ast_indicate_data(chan, condition, NULL, 0); 03211 }
| 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 3249 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_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_debug, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STATE_UP, ast_test_flag, ast_tone_zone_sound_unref(), ast_tone_zone_sound::data, ast_channel_tech::indicate, is_visible_indication(), LOG_WARNING, ast_channel::name, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.
Referenced by agent_hangup(), ast_bridge_call(), ast_generic_bridge(), ast_indicate(), bridge_native_loop(), bridge_p2p_loop(), login_exec(), manage_parkinglot(), park_call_full(), pbx_builtin_waitexten(), transmit_audio(), transmit_t38(), and wait_for_answer().
03251 { 03252 /* By using an enum, we'll get compiler warnings for values not handled 03253 * in switch statements. */ 03254 enum ast_control_frame_type condition = _condition; 03255 struct ast_tone_zone_sound *ts = NULL; 03256 int res = -1; 03257 03258 ast_channel_lock(chan); 03259 03260 /* Don't bother if the channel is about to go away, anyway. */ 03261 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 03262 ast_channel_unlock(chan); 03263 return -1; 03264 } 03265 03266 if (chan->tech->indicate) { 03267 /* See if the channel driver can handle this condition. */ 03268 res = chan->tech->indicate(chan, condition, data, datalen); 03269 } 03270 03271 ast_channel_unlock(chan); 03272 03273 if (!res) { 03274 /* The channel driver successfully handled this indication */ 03275 if (is_visible_indication(condition)) { 03276 chan->visible_indication = condition; 03277 } 03278 return 0; 03279 } 03280 03281 /* The channel driver does not support this indication, let's fake 03282 * it by doing our own tone generation if applicable. */ 03283 03284 /*!\note If we compare the enumeration type, which does not have any 03285 * negative constants, the compiler may optimize this code away. 03286 * Therefore, we must perform an integer comparison here. */ 03287 if (_condition < 0) { 03288 /* Stop any tones that are playing */ 03289 ast_playtones_stop(chan); 03290 return 0; 03291 } 03292 03293 /* Handle conditions that we have tones for. */ 03294 switch (condition) { 03295 case _XXX_AST_CONTROL_T38: 03296 /* deprecated T.38 control frame */ 03297 return -1; 03298 case AST_CONTROL_T38_PARAMETERS: 03299 /* there is no way to provide 'default' behavior for these 03300 * control frames, so we need to return failure, but there 03301 * is also no value in the log message below being emitted 03302 * since failure to handle these frames is not an 'error' 03303 * so just return right now. in addition, we want to return 03304 * whatever value the channel driver returned, in case it 03305 * has some meaning.*/ 03306 return res; 03307 case AST_CONTROL_RINGING: 03308 ts = ast_get_indication_tone(chan->zone, "ring"); 03309 /* It is common practice for channel drivers to return -1 if trying 03310 * to indicate ringing on a channel which is up. The idea is to let the 03311 * core generate the ringing inband. However, we don't want the 03312 * warning message about not being able to handle the specific indication 03313 * to print nor do we want ast_indicate_data to return an "error" for this 03314 * condition 03315 */ 03316 if (chan->_state == AST_STATE_UP) { 03317 res = 0; 03318 } 03319 break; 03320 case AST_CONTROL_BUSY: 03321 ts = ast_get_indication_tone(chan->zone, "busy"); 03322 break; 03323 case AST_CONTROL_CONGESTION: 03324 ts = ast_get_indication_tone(chan->zone, "congestion"); 03325 break; 03326 case AST_CONTROL_PROGRESS: 03327 case AST_CONTROL_PROCEEDING: 03328 case AST_CONTROL_VIDUPDATE: 03329 case AST_CONTROL_SRCUPDATE: 03330 case AST_CONTROL_SRCCHANGE: 03331 case AST_CONTROL_RADIO_KEY: 03332 case AST_CONTROL_RADIO_UNKEY: 03333 case AST_CONTROL_OPTION: 03334 case AST_CONTROL_WINK: 03335 case AST_CONTROL_FLASH: 03336 case AST_CONTROL_OFFHOOK: 03337 case AST_CONTROL_TAKEOFFHOOK: 03338 case AST_CONTROL_ANSWER: 03339 case AST_CONTROL_HANGUP: 03340 case AST_CONTROL_RING: 03341 case AST_CONTROL_HOLD: 03342 case AST_CONTROL_UNHOLD: 03343 /* Nothing left to do for these. */ 03344 res = 0; 03345 break; 03346 } 03347 03348 if (ts) { 03349 /* We have a tone to play, yay. */ 03350 ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition); 03351 ast_playtones_start(chan, 0, ts->data, 1); 03352 ts = ast_tone_zone_sound_unref(ts); 03353 res = 0; 03354 chan->visible_indication = condition; 03355 } 03356 03357 if (res) { 03358 /* not handled */ 03359 ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name); 03360 } 03361 03362 return res; 03363 }
| 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 5795 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by load_module().
05798 { 05799 ast_moh_start_ptr = start_ptr; 05800 ast_moh_stop_ptr = stop_ptr; 05801 ast_moh_cleanup_ptr = cleanup_ptr; 05802 }
| 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 3193 of file channel.c.
References ast_opt_internal_timing, and ast_channel::timingfd.
Referenced by add_sdp(), and ast_read_generator_actions().
03194 { 03195 return (ast_opt_internal_timing && chan->timingfd > -1); 03196 }
| int ast_is_deferrable_frame | ( | const struct ast_frame * | frame | ) |
Should we keep this frame for later?
There are functions such as ast_safe_sleep which will service a channel to ensure that it does not have a large backlog of queued frames. When this happens, we want to hold on to specific frame types and just drop others. This function will tell if the frame we just read should be held onto.
| frame | The frame we just read |
| 1 | frame should be kept | |
| 0 | frame should be dropped |
Definition at line 1341 of file channel.c.
References AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, and ast_frame::frametype.
Referenced by ast_safe_sleep_conditional(), and autoservice_run().
01342 { 01343 /* Do not add a default entry in this switch statement. Each new 01344 * frame type should be addressed directly as to whether it should 01345 * be queued up or not. 01346 */ 01347 switch (frame->frametype) { 01348 case AST_FRAME_DTMF_END: 01349 case AST_FRAME_CONTROL: 01350 case AST_FRAME_TEXT: 01351 case AST_FRAME_IMAGE: 01352 case AST_FRAME_HTML: 01353 return 1; 01354 01355 case AST_FRAME_DTMF_BEGIN: 01356 case AST_FRAME_VOICE: 01357 case AST_FRAME_VIDEO: 01358 case AST_FRAME_NULL: 01359 case AST_FRAME_IAX: 01360 case AST_FRAME_CNG: 01361 case AST_FRAME_MODEM: 01362 return 0; 01363 } 01364 return 0; 01365 }
| void ast_moh_cleanup | ( | struct ast_channel * | chan | ) |
Definition at line 5829 of file channel.c.
References ast_moh_cleanup_ptr.
Referenced by ast_channel_free().
05830 { 05831 if (ast_moh_cleanup_ptr) 05832 ast_moh_cleanup_ptr(chan); 05833 }
| 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 5812 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(), leave_conference_bridge(), local_indicate(), menu_callback(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), post_join_marked(), post_join_unmarked(), 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().
05813 { 05814 if (ast_moh_start_ptr) 05815 return ast_moh_start_ptr(chan, mclass, interpclass); 05816 05817 ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default")); 05818 05819 return 0; 05820 }
| 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 5823 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(), menu_callback(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), post_join_marked(), post_join_unmarked(), 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().
05824 { 05825 if (ast_moh_stop_ptr) 05826 ast_moh_stop_ptr(chan); 05827 }
| int ast_plc_reload | ( | void | ) |
Reload genericplc configuration value from codecs.conf.
Implementation is in main/channel.c
Definition at line 5835 of file channel.c.
References ast_config_destroy(), ast_config_load2(), AST_OPT_FLAG_GENERIC_PLC, ast_options, ast_set2_flag, ast_true(), ast_variable_browse(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, ast_variable::name, ast_variable::next, ast_variable::value, and var.
Referenced by ast_channels_init().
05836 { 05837 struct ast_variable *var; 05838 struct ast_flags config_flags = { 0 }; 05839 struct ast_config *cfg = ast_config_load2("codecs.conf", "channel", config_flags); 05840 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) 05841 return 0; 05842 for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) { 05843 if (!strcasecmp(var->name, "genericplc")) { 05844 ast_set2_flag(&ast_options, ast_true(var->value), AST_OPT_FLAG_GENERIC_PLC); 05845 } 05846 } 05847 ast_config_destroy(cfg); 05848 return 0; 05849 }
| void ast_poll_channel_add | ( | struct ast_channel * | chan0, | |
| struct ast_channel * | chan1 | |||
| ) |
Add a channel to an optimized waitfor
Definition at line 1678 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_generic_bridge(), begin_dial_channel(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), and wait_for_answer().
01679 { 01680 #ifdef HAVE_EPOLL 01681 struct epoll_event ev; 01682 int i = 0; 01683 01684 if (chan0->epfd == -1) 01685 return; 01686 01687 /* Iterate through the file descriptors on chan1, adding them to chan0 */ 01688 for (i = 0; i < AST_MAX_FDS; i++) { 01689 if (chan1->fds[i] == -1) 01690 continue; 01691 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01692 ev.data.ptr = chan1->epfd_data[i]; 01693 epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev); 01694 } 01695 01696 #endif 01697 return; 01698 }
| void ast_poll_channel_del | ( | struct ast_channel * | chan0, | |
| struct ast_channel * | chan1 | |||
| ) |
Delete a channel from an optimized waitfor
Definition at line 1701 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), monitor_dial(), and wait_for_answer().
01702 { 01703 #ifdef HAVE_EPOLL 01704 struct epoll_event ev; 01705 int i = 0; 01706 01707 if (chan0->epfd == -1) 01708 return; 01709 01710 for (i = 0; i < AST_MAX_FDS; i++) { 01711 if (chan1->fds[i] == -1) 01712 continue; 01713 epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev); 01714 } 01715 01716 #endif 01717 return; 01718 }
| 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 5859 of file channel.c.
Referenced by _sip_show_peer(), _skinny_show_line(), func_channel_read(), function_sippeer(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().
05860 { 05861 unsigned int i; 05862 int first = 1; 05863 char num[3]; 05864 05865 buf[0] = '\0'; 05866 05867 if (!group) /* Return empty string if no group */ 05868 return buf; 05869 05870 for (i = 0; i <= 63; i++) { /* Max group is 63 */ 05871 if (group & ((ast_group_t) 1 << i)) { 05872 if (!first) { 05873 strncat(buf, ", ", buflen - strlen(buf) - 1); 05874 } else { 05875 first = 0; 05876 } 05877 snprintf(num, sizeof(num), "%u", i); 05878 strncat(buf, num, buflen - strlen(buf) - 1); 05879 } 05880 } 05881 return buf; 05882 }
| int ast_prod | ( | struct ast_channel * | chan | ) |
Send empty audio to prime a channel driver.
Definition at line 3484 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().
03485 { 03486 struct ast_frame a = { AST_FRAME_VOICE }; 03487 char nothing[128]; 03488 03489 /* Send an empty audio frame to get things moving */ 03490 if (chan->_state != AST_STATE_UP) { 03491 ast_debug(1, "Prodding channel '%s'\n", chan->name); 03492 a.subclass = chan->rawwriteformat; 03493 a.data.ptr = nothing + AST_FRIENDLY_OFFSET; 03494 a.src = "ast_prod"; /* this better match check in ast_write */ 03495 if (ast_write(chan, &a)) 03496 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name); 03497 } 03498 return 0; 03499 }
| 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 1137 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and ast_frame::subclass.
Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), ast_pickup_call(), attempt_transfer(), auto_congest(), cb_events(), dahdi_handle_event(), dahdi_hangup(), gtalk_is_answered(), gtalk_ringing_ack(), handle_hd_hf(), handle_offhook_message(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_refer(), handle_soft_key_event_message(), handle_stimulus_message(), HandleCallIncoming(), jingle_is_answered(), jingle_ringing_ack(), mgcp_call(), misdn_attempt_transfer(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), remote_hold(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_transfer(), skinny_unhold(), ss_thread(), unistim_call(), and update_state().
01138 { 01139 struct ast_frame f = { AST_FRAME_CONTROL, }; 01140 01141 f.subclass = control; 01142 01143 return ast_queue_frame(chan, &f); 01144 }
| 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 1147 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::ptr, and ast_frame::subclass.
Referenced by change_t38_state(), dahdi_handle_event(), dahdi_hangup(), iax2_queue_control_data(), interpret_t38_parameters(), process_sdp(), and skinny_hold().
01149 { 01150 struct ast_frame f = { AST_FRAME_CONTROL, }; 01151 01152 f.subclass = control; 01153 f.data.ptr = (void *) data; 01154 f.datalen = datalen; 01155 01156 return ast_queue_frame(chan, &f); 01157 }
| 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 1094 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), action_atxfer(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup_tv(), ast_do_masquerade(), ast_dsp_process(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), bridge_write(), cb_events(), cli_console_answer(), cli_console_dial(), cli_console_flash(), cli_console_sendtext(), console_answer(), console_call(), console_dial(), console_do_answer(), console_flash(), console_sendtext(), dahdi_queue_frame(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), jingle_handle_dtmf(), keypad_digit(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), stream_monitor(), unistim_do_senddigit(), unistim_senddigit_end(), usbradio_read(), and wakeup_sub().
01095 { 01096 return __ast_queue_frame(chan, fin, 0, NULL); 01097 }
| 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 1099 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_answer(), __ast_read(), ast_autoservice_stop(), and ast_safe_sleep_conditional().
01100 { 01101 return __ast_queue_frame(chan, fin, 1, NULL); 01102 }
| int ast_queue_hangup | ( | struct ast_channel * | chan | ) |
Queue a hangup frame for channel.
Queue a hangup frame.
Definition at line 1105 of file channel.c.
References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), and AST_SOFTHANGUP_DEV.
Referenced by bridge_queue_hangup(), cleanup_connection(), cli_console_hangup(), close_call(), gtalk_hangup_farend(), gtalk_is_answered(), handle_onhook_message(), handle_request_bye(), handle_request_cancel(), handle_soft_key_event_message(), iax2_destroy(), iax2_queue_hangup(), jingle_hangup_farend(), local_fixup(), local_hangup(), and mgcp_queue_hangup().
01106 { 01107 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01108 /* Yeah, let's not change a lock-critical value without locking */ 01109 if (!ast_channel_trylock(chan)) { 01110 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01111 ast_channel_unlock(chan); 01112 } 01113 return ast_queue_frame(chan, &f); 01114 }
| 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 1117 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(), dahdi_r2_on_call_disconnect(), handle_request_bye(), handle_response(), handle_response_invite(), handle_response_notify(), HandleCallOutgoing(), hangup_chan(), hangup_connection(), misdn_answer(), pri_hangup_all(), retrans_pkt(), and TransferCallStep1().
01118 { 01119 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01120 01121 if (cause >= 0) 01122 f.data.uint32 = cause; 01123 01124 /* Yeah, let's not change a lock-critical value without locking */ 01125 if (!ast_channel_trylock(chan)) { 01126 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01127 if (cause < 0) 01128 f.data.uint32 = chan->hangupcause; 01129 01130 ast_channel_unlock(chan); 01131 } 01132 01133 return ast_queue_frame(chan, &f); 01134 }
| 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 1867 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().
01868 { 01869 int res = 0; 01870 01871 ast_channel_lock(chan); 01872 01873 /* You can't answer an outbound call */ 01874 if (ast_test_flag(chan, AST_FLAG_OUTGOING)) { 01875 ast_channel_unlock(chan); 01876 return 0; 01877 } 01878 01879 /* Stop if we're a zombie or need a soft hangup */ 01880 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 01881 ast_channel_unlock(chan); 01882 return -1; 01883 } 01884 01885 ast_channel_unlock(chan); 01886 01887 switch (chan->_state) { 01888 case AST_STATE_RINGING: 01889 case AST_STATE_RING: 01890 ast_channel_lock(chan); 01891 if (chan->tech->answer) { 01892 res = chan->tech->answer(chan); 01893 } 01894 ast_setstate(chan, AST_STATE_UP); 01895 if (cdr_answer) { 01896 ast_cdr_answer(chan->cdr); 01897 } 01898 ast_channel_unlock(chan); 01899 break; 01900 case AST_STATE_UP: 01901 /* Calling ast_cdr_answer when it it has previously been called 01902 * is essentially a no-op, so it is safe. 01903 */ 01904 if (cdr_answer) { 01905 ast_cdr_answer(chan->cdr); 01906 } 01907 break; 01908 default: 01909 break; 01910 } 01911 01912 ast_indicate(chan, -1); 01913 chan->visible_indication = 0; 01914 01915 return res; 01916 }
| struct ast_frame* ast_read | ( | struct ast_channel * | chan | ) | [read] |
Reads a frame.
| chan | channel to read a frame from |
Definition at line 3198 of file channel.c.
References __ast_read().
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), ast_bridge_handle_trip(), ast_generic_bridge(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_udptl_bridge(), ast_waitfordigit_full(), async_wait(), autoservice_run(), background_detect_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_goto_on_transfer(), conf_exec(), conf_flush(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_bridge(), dial_exec_full(), dictate_exec(), disa_exec(), do_idle_thread(), do_waiting(), echo_exec(), eivr_comm(), feature_request_and_dial(), find_cache(), handle_recordfile(), handle_speechrecognize(), iax2_bridge(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), manage_parkinglot(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), recordthread(), rpt(), rpt_exec(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().
03199 { 03200 return __ast_read(chan, 0); 03201 }
| static void ast_read_generator_actions | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f | |||
| ) | [static] |
Definition at line 2601 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().
02602 { 02603 if (chan->generator && chan->generator->generate && chan->generatordata && !ast_internal_timing_enabled(chan)) { 02604 void *tmp = chan->generatordata; 02605 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = chan->generator->generate; 02606 int res; 02607 int samples; 02608 02609 if (chan->timingfunc) { 02610 ast_debug(1, "Generator got voice, switching to phase locked mode\n"); 02611 ast_settimeout(chan, 0, NULL, NULL); 02612 } 02613 02614 chan->generatordata = NULL; /* reset, to let writes go through */ 02615 02616 if (f->subclass != chan->writeformat) { 02617 float factor; 02618 factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass)); 02619 samples = (int) ( ((float) f->samples) * factor ); 02620 } else { 02621 samples = f->samples; 02622 } 02623 02624 /* This unlock is here based on two assumptions that hold true at this point in the 02625 * code. 1) this function is only called from within __ast_read() and 2) all generators 02626 * call ast_write() in their generate callback. 02627 * 02628 * The reason this is added is so that when ast_write is called, the lock that occurs 02629 * there will not recursively lock the channel. Doing this will cause intended deadlock 02630 * avoidance not to work in deeper functions 02631 */ 02632 ast_channel_unlock(chan); 02633 res = generate(chan, tmp, f->datalen, samples); 02634 ast_channel_lock(chan); 02635 chan->generatordata = tmp; 02636 if (res) { 02637 ast_debug(1, "Auto-deactivating generator\n"); 02638 ast_deactivate_generator(chan); 02639 } 02640 02641 } else if (f->frametype == AST_FRAME_CNG) { 02642 if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) { 02643 ast_debug(1, "Generator got CNG, switching to timed mode\n"); 02644 ast_settimeout(chan, 50, generator_force, chan); 02645 } 02646 } 02647 }
| 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 3203 of file channel.c.
References __ast_read().
Referenced by ast_bridge_handle_trip(), and conf_run().
03204 { 03205 return __ast_read(chan, 1); 03206 }
| 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 4321 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().
04322 { 04323 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1); 04324 }
| 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 4326 of file channel.c.
References ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, AST_GETDATA_COMPLETE, AST_GETDATA_EMPTY_END_TERMINATED, AST_GETDATA_FAILED, AST_GETDATA_INTERRUPTED, AST_GETDATA_TIMEOUT, ast_opt_transmit_silence, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), ast_waitstream_full(), and ast_channel::stream.
Referenced by ast_app_getdata_full(), and ast_readstring().
04327 { 04328 int pos = 0; /* index in the buffer where we accumulate digits */ 04329 int to = ftimeout; 04330 04331 struct ast_silence_generator *silgen = NULL; 04332 04333 /* Stop if we're a zombie or need a soft hangup */ 04334 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 04335 return -1; 04336 if (!len) 04337 return -1; 04338 for (;;) { 04339 int d; 04340 if (c->stream) { 04341 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); 04342 ast_stopstream(c); 04343 if (!silgen && ast_opt_transmit_silence) 04344 silgen = ast_channel_start_silence_generator(c); 04345 usleep(1000); 04346 if (!d) 04347 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04348 } else { 04349 if (!silgen && ast_opt_transmit_silence) 04350 silgen = ast_channel_start_silence_generator(c); 04351 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04352 } 04353 if (d < 0) { 04354 ast_channel_stop_silence_generator(c, silgen); 04355 return AST_GETDATA_FAILED; 04356 } 04357 if (d == 0) { 04358 s[pos] = '\0'; 04359 ast_channel_stop_silence_generator(c, silgen); 04360 return AST_GETDATA_TIMEOUT; 04361 } 04362 if (d == 1) { 04363 s[pos] = '\0'; 04364 ast_channel_stop_silence_generator(c, silgen); 04365 return AST_GETDATA_INTERRUPTED; 04366 } 04367 if (strchr(enders, d) && (pos == 0)) { 04368 s[pos] = '\0'; 04369 ast_channel_stop_silence_generator(c, silgen); 04370 return AST_GETDATA_EMPTY_END_TERMINATED; 04371 } 04372 if (!strchr(enders, d)) { 04373 s[pos++] = d; 04374 } 04375 if (strchr(enders, d) || (pos >= len)) { 04376 s[pos] = '\0'; 04377 ast_channel_stop_silence_generator(c, silgen); 04378 return AST_GETDATA_COMPLETE; 04379 } 04380 to = timeout; 04381 } 04382 /* Never reached */ 04383 return 0; 04384 }
| 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 3365 of file channel.c.
References ast_free, and ast_recvtext().
Referenced by handle_recvchar().
03366 { 03367 int c; 03368 char *buf = ast_recvtext(chan, timeout); 03369 if (buf == NULL) 03370 return -1; /* error or timeout */ 03371 c = *(unsigned char *)buf; 03372 ast_free(buf); 03373 return c; 03374 }
| 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 3376 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().
03377 { 03378 int res, done = 0; 03379 char *buf = NULL; 03380 03381 while (!done) { 03382 struct ast_frame *f; 03383 if (ast_check_hangup(chan)) 03384 break; 03385 res = ast_waitfor(chan, timeout); 03386 if (res <= 0) /* timeout or error */ 03387 break; 03388 timeout = res; /* update timeout */ 03389 f = ast_read(chan); 03390 if (f == NULL) 03391 break; /* no frame */ 03392 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) 03393 done = 1; /* force a break */ 03394 else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ 03395 buf = ast_strndup((char *) f->data.ptr, f->datalen); /* dup and break */ 03396 done = 1; 03397 } 03398 ast_frfree(f); 03399 } 03400 return buf; 03401 }
| 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 4220 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(), attempt_reconnect(), begin_dial_channel(), build_conf(), chanavail_exec(), conf_run(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), and wait_for_answer().
04221 { 04222 struct chanlist *chan; 04223 struct ast_channel *c; 04224 int capabilities; 04225 int fmt; 04226 int res; 04227 int foo; 04228 int videoformat = format & AST_FORMAT_VIDEO_MASK; 04229 int textformat = format & AST_FORMAT_TEXT_MASK; 04230 04231 if (!cause) 04232 cause = &foo; 04233 *cause = AST_CAUSE_NOTDEFINED; 04234 04235 if (AST_RWLIST_RDLOCK(&channels)) { 04236 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 04237 return NULL; 04238 } 04239 04240 AST_LIST_TRAVERSE(&backends, chan, list) { 04241 if (strcasecmp(type, chan->tech->type)) 04242 continue; 04243 04244 capabilities = chan->tech->capabilities; 04245 fmt = format & AST_FORMAT_AUDIO_MASK; 04246 if (fmt) { 04247 /* We have audio - is it possible to connect the various calls to each other? 04248 (Avoid this check for calls without audio, like text+video calls) 04249 */ 04250 res = ast_translator_best_choice(&fmt, &capabilities); 04251 if (res < 0) { 04252 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format); 04253 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 04254 AST_RWLIST_UNLOCK(&channels); 04255 return NULL; 04256 } 04257 } 04258 AST_RWLIST_UNLOCK(&channels); 04259 if (!chan->tech->requester) 04260 return NULL; 04261 04262 if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, data, cause))) 04263 return NULL; 04264 04265 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */ 04266 return c; 04267 } 04268 04269 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type); 04270 *cause = AST_CAUSE_NOSUCHDRIVER; 04271 AST_RWLIST_UNLOCK(&channels); 04272 04273 return NULL; 04274 }
| 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 4215 of file channel.c.
References __ast_request_and_dial().
Referenced by ast_pbx_outgoing_exten().
04216 { 04217 return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL); 04218 }
| 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 1435 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().
01436 { 01437 return ast_safe_sleep_conditional(chan, ms, NULL, NULL); 01438 }
| 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 1368 of file channel.c.
References ast_channel_lock, ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_unlock, ast_frfree, ast_frisolate(), ast_is_deferrable_frame(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_opt_transmit_silence, ast_queue_frame_head(), ast_read(), ast_waitfor(), cond, f, and ast_channel::generatordata.
Referenced by ast_safe_sleep(), and login_exec().
01369 { 01370 struct ast_frame *f; 01371 struct ast_silence_generator *silgen = NULL; 01372 int res = 0; 01373 AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames; 01374 01375 AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames); 01376 01377 /* If no other generator is present, start silencegen while waiting */ 01378 if (ast_opt_transmit_silence && !chan->generatordata) { 01379 silgen = ast_channel_start_silence_generator(chan); 01380 } 01381 01382 while (ms > 0) { 01383 struct ast_frame *dup_f = NULL; 01384 if (cond && ((*cond)(data) == 0)) { 01385 break; 01386 } 01387 ms = ast_waitfor(chan, ms); 01388 if (ms < 0) { 01389 res = -1; 01390 break; 01391 } 01392 if (ms > 0) { 01393 f = ast_read(chan); 01394 if (!f) { 01395 res = -1; 01396 break; 01397 } 01398 01399 if (!ast_is_deferrable_frame(f)) { 01400 ast_frfree(f); 01401 continue; 01402 } 01403 01404 if ((dup_f = ast_frisolate(f))) { 01405 if (dup_f != f) { 01406 ast_frfree(f); 01407 } 01408 AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list); 01409 } 01410 } 01411 } 01412 01413 /* stop silgen if present */ 01414 if (silgen) { 01415 ast_channel_stop_silence_generator(chan, silgen); 01416 } 01417 01418 /* We need to free all the deferred frames, but we only need to 01419 * queue the deferred frames if there was no error and no 01420 * hangup was received 01421 */ 01422 ast_channel_lock(chan); 01423 while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) { 01424 if (!res) { 01425 ast_queue_frame_head(chan, f); 01426 } 01427 ast_frfree(f); 01428 } 01429 ast_channel_unlock(chan); 01430 01431 return res; 01432 }
| int ast_say_character_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 6131 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().
06133 { 06134 return ast_say_character_str_full(chan, str, ints, lang, -1, -1); 06135 }
| int ast_say_digit_str | ( | struct ast_channel * | chan, | |
| const char * | num, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
says digits of a string
| chan | channel to act upon | |
| num | string to speak | |
| ints | which dtmf to interrupt on | |
| lang | language to speak in |
| 0 | on succes | |
| DTMF | if interrupted | |
| -1 | on failure |
Definition at line 6125 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().
06127 { 06128 return ast_say_digit_str_full(chan, str, ints, lang, -1, -1); 06129 }
| int ast_say_digits | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
says digits
| chan | channel to act upon | |
| num | number to speak | |
| ints | which dtmf to interrupt on | |
| lang | language to speak |
| 0 | on success | |
| DTMF | if interrupted | |
| -1 | on failure |
Definition at line 6119 of file channel.c.
References ast_say_digits_full().
Referenced by common_exec(), conf_exec(), conf_run(), park_call_full(), parkandannounce_exec(), and rpt_tele_thread().
06121 { 06122 return ast_say_digits_full(chan, num, ints, lang, -1, -1); 06123 }
| int ast_say_digits_full | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| int | audiofd, | |||
| int | ctrlfd | |||
| ) |
Definition at line 6143 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().
06145 { 06146 char buf[256]; 06147 06148 snprintf(buf, sizeof(buf), "%d", num); 06149 06150 return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd); 06151 }
| int ast_say_enumeration | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| const char * | options | |||
| ) |
says an enumeration
| chan | channel to say them enumeration on | |
| num | number to say on the channel | |
| ints | which dtmf to interrupt on | |
| lang | language to speak the enumeration | |
| options | set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural |
| 0 | on success | |
| DTMF | digit on interrupt | |
| -1 | on failure |
Definition at line 6113 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().
06115 { 06116 return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1); 06117 }
| int ast_say_number | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| const char * | options | |||
| ) |
says a number
| chan | channel to say them number on | |
| num | number to say on the channel | |
| ints | which dtmf to interrupt on | |
| lang | language to speak the number | |
| options | set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural |
| 0 | on success | |
| DTMF | digit on interrupt | |
| -1 | on failure |
Definition at line 6107 of file channel.c.
References ast_say_number_full.
Referenced by announce_user_count(), 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().
06109 { 06110 return ast_say_number_full(chan, num, ints, language, options, -1, -1); 06111 }
| int ast_say_phonetic_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 6137 of file channel.c.
References ast_say_phonetic_str_full.
Referenced by pbx_builtin_sayphonetic().
06139 { 06140 return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1); 06141 }
| 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 3474 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().
03475 { 03476 if (chan->tech->send_digit_begin) { 03477 ast_senddigit_begin(chan, digit); 03478 ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03479 } 03480 03481 return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03482 }
| 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 3416 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().
03417 { 03418 /* Device does not support DTMF tones, lets fake 03419 * it by doing our own generation. */ 03420 static const char* dtmf_tones[] = { 03421 "941+1336", /* 0 */ 03422 "697+1209", /* 1 */ 03423 "697+1336", /* 2 */ 03424 "697+1477", /* 3 */ 03425 "770+1209", /* 4 */ 03426 "770+1336", /* 5 */ 03427 "770+1477", /* 6 */ 03428 "852+1209", /* 7 */ 03429 "852+1336", /* 8 */ 03430 "852+1477", /* 9 */ 03431 "697+1633", /* A */ 03432 "770+1633", /* B */ 03433 "852+1633", /* C */ 03434 "941+1633", /* D */ 03435 "941+1209", /* * */ 03436 "941+1477" /* # */ 03437 }; 03438 03439 if (!chan->tech->send_digit_begin) 03440 return 0; 03441 03442 if (!chan->tech->send_digit_begin(chan, digit)) 03443 return 0; 03444 03445 if (digit >= '0' && digit <='9') 03446 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0); 03447 else if (digit >= 'A' && digit <= 'D') 03448 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0); 03449 else if (digit == '*') 03450 ast_playtones_start(chan, 0, dtmf_tones[14], 0); 03451 else if (digit == '#') 03452 ast_playtones_start(chan, 0, dtmf_tones[15], 0); 03453 else { 03454 /* not handled */ 03455 ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name); 03456 } 03457 03458 return 0; 03459 }
| 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 3461 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().
03462 { 03463 int res = -1; 03464 03465 if (chan->tech->send_digit_end) 03466 res = chan->tech->send_digit_end(chan, digit, duration); 03467 03468 if (res && chan->generator) 03469 ast_playtones_stop(chan); 03470 03471 return 0; 03472 }
| 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 3403 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().
03404 { 03405 int res = 0; 03406 /* Stop if we're a zombie or need a soft hangup */ 03407 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 03408 return -1; 03409 CHECK_BLOCKING(chan); 03410 if (chan->tech->send_text) 03411 res = chan->tech->send_text(chan, text); 03412 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03413 return res; 03414 }
| 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 4937 of file channel.c.
References ast_cdr_setcid(), ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, and report_new_callerid().
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), callerid_write(), dahdi_read(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), findmeexec(), handle_setcallerid(), mgcp_ss(), privacy_exec(), read_config(), rpt_exec(), skinny_newcall(), and ss_thread().
04938 { 04939 ast_channel_lock(chan); 04940 04941 if (cid_num) { 04942 if (chan->cid.cid_num) 04943 ast_free(chan->cid.cid_num); 04944 chan->cid.cid_num = ast_strdup(cid_num); 04945 } 04946 if (cid_name) { 04947 if (chan->cid.cid_name) 04948 ast_free(chan->cid.cid_name); 04949 chan->cid.cid_name = ast_strdup(cid_name); 04950 } 04951 if (cid_ani) { 04952 if (chan->cid.cid_ani) 04953 ast_free(chan->cid.cid_ani); 04954 chan->cid.cid_ani = ast_strdup(cid_ani); 04955 } 04956 if (chan->cdr) { 04957 ast_cdr_setcid(chan->cdr, chan); 04958 } 04959 04960 report_new_callerid(chan); 04961 04962 ast_channel_unlock(chan); 04963 }
| 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 3948 of file channel.c.
References ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().
Referenced by __ast_play_and_record(), __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_do_masquerade(), attempt_reconnect(), background_detect_exec(), bridge_channel_join(), bridge_make_compatible(), build_conf(), conf_run(), connect_link(), dictate_exec(), do_waiting(), eagi_exec(), echo_exec(), gtalk_rtp_read(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), jingle_rtp_read(), login_exec(), measurenoise(), mgcp_rtp_read(), oh323_rtp_read(), old_milliwatt_exec(), process_sdp(), record_exec(), rpt(), rpt_exec(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), transmit_audio(), and unistim_rtp_read().
03949 { 03950 return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat, 03951 &chan->readtrans, 0); 03952 }
| 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 5884 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().
05885 { 05886 struct ast_variable *cur; 05887 05888 for (cur = vars; cur; cur = cur->next) 05889 pbx_builtin_setvar_helper(chan, cur->name, cur->value); 05890 }
| 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 3954 of file channel.c.
References ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.
Referenced by __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_do_masquerade(), ast_openstream_full(), ast_stopstream(), attempt_reconnect(), bridge_channel_join(), bridge_make_compatible(), build_conf(), chanspy_exec(), conf_run(), connect_link(), echo_exec(), extenspy_exec(), gtalk_rtp_read(), jack_exec(), jingle_rtp_read(), linear_alloc(), linear_release(), login_exec(), mgcp_rtp_read(), moh_alloc(), moh_files_release(), moh_release(), mp3_exec(), NBScat_exec(), oh323_rtp_read(), old_milliwatt_exec(), playtones_alloc(), playtones_release(), process_sdp(), rpt(), rpt_exec(), send_waveform_to_channel(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), tonepair_alloc(), tonepair_release(), transmit_audio(), and unistim_rtp_read().
03955 { 03956 return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat, 03957 &chan->writetrans, 1); 03958 }
| int ast_setstate | ( | struct ast_channel * | chan, | |
| enum ast_channel_state | state | |||
| ) |
Change the state of a channel.
Definition at line 4965 of file channel.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_copy_string(), AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), ast_state2str(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, ast_channel::name, name, S_OR, and ast_channel::uniqueid.
Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), agent_call(), alsa_answer(), ast_raw_answer(), cb_events(), check_availability(), console_answer(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), do_bridge_masquerade(), gtalk_call(), gtalk_newcall(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_response_invite(), handle_soft_key_event_message(), handle_stimulus_message(), iax2_call(), jingle_call(), jingle_newcall(), local_queue_frame(), mgcp_answer(), mgcp_call(), mgcp_ss(), misdn_call(), misdn_indication(), nbs_call(), nbs_hangup(), oh323_answer(), oss_answer(), pbx_builtin_busy(), pbx_builtin_congestion(), phone_answer(), phone_call(), phone_exception(), phone_hangup(), phone_write(), release_chan(), release_chan_early(), sip_answer(), skinny_answer(), skinny_call(), skinny_newcall(), ss_thread(), unistim_answer(), unistim_call(), unistim_new(), unistim_ss(), update_state(), usbradio_answer(), and usbradio_call().
04966 { 04967 int oldstate = chan->_state; 04968 char name[AST_CHANNEL_NAME], *dashptr; 04969 04970 if (oldstate == state) 04971 return 0; 04972 04973 ast_copy_string(name, chan->name, sizeof(name)); 04974 if ((dashptr = strrchr(name, '-'))) { 04975 *dashptr = '\0'; 04976 } 04977 04978 chan->_state = state; 04979 04980 /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver 04981 * for this channel is using the callback method for device state. If we pass in an actual state here 04982 * we override what they are saying the state is and things go amuck. */ 04983 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 04984 04985 /* setstate used to conditionally report Newchannel; this is no more */ 04986 manager_event(EVENT_FLAG_CALL, 04987 "Newstate", 04988 "Channel: %s\r\n" 04989 "ChannelState: %d\r\n" 04990 "ChannelStateDesc: %s\r\n" 04991 "CallerIDNum: %s\r\n" 04992 "CallerIDName: %s\r\n" 04993 "Uniqueid: %s\r\n", 04994 chan->name, chan->_state, ast_state2str(chan->_state), 04995 S_OR(chan->cid.cid_num, ""), 04996 S_OR(chan->cid.cid_name, ""), 04997 chan->uniqueid); 04998 04999 return 0; 05000 }
| 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 2475 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().
02476 { 02477 int res; 02478 unsigned int real_rate = rate, max_rate; 02479 02480 ast_channel_lock(c); 02481 02482 if (c->timingfd == -1) { 02483 ast_channel_unlock(c); 02484 return -1; 02485 } 02486 02487 if (!func) { 02488 rate = 0; 02489 data = NULL; 02490 } 02491 02492 if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) { 02493 real_rate = max_rate; 02494 } 02495 02496 ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate); 02497 02498 res = ast_timer_set_rate(c->timer, real_rate); 02499 02500 c->timingfunc = func; 02501 c->timingdata = data; 02502 02503 ast_channel_unlock(c); 02504 02505 return res; 02506 }
| 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 1734 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().
Referenced by __ast_module_user_hangup_all(), __ast_pbx_run(), __unload_module(), action_hangup(), agent_hangup(), agent_logoff(), agent_read(), ast_begin_shutdown(), ast_dial_join(), birdbath(), conf_free(), connect_link(), dahdi_handle_event(), flush_telem(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), login_exec(), manager_park(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), rpt_exec(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().
01735 { 01736 int res; 01737 01738 ast_channel_lock(chan); 01739 res = ast_softhangup_nolock(chan, cause); 01740 ast_channel_unlock(chan); 01741 01742 return res; 01743 }
| 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 1721 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_pendings(), check_rtp_timeout(), dahdi_softhangup_all(), oh323_indicate(), proc_session_timer(), sip_indicate(), and skinny_indicate().
01722 { 01723 ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name); 01724 /* Inform channel driver that we need to be hung up, if it cares */ 01725 chan->_softhangup |= cause; 01726 ast_queue_frame(chan, &ast_null_frame); 01727 /* Interrupt any poll call or such */ 01728 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) 01729 pthread_kill(chan->blocker, SIGURG); 01730 return 0; 01731 }
| 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, cause, 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 5741 of file channel.c.
References ast_frfree, ast_read(), ast_tonepair_start(), ast_waitfor(), f, and ast_channel::generatordata.
Referenced by zapateller_exec().
05742 { 05743 int res; 05744 05745 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol))) 05746 return res; 05747 05748 /* Give us some wiggle room */ 05749 while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { 05750 struct ast_frame *f = ast_read(chan); 05751 if (f) 05752 ast_frfree(f); 05753 else 05754 return -1; 05755 } 05756 return 0; 05757 }
| int ast_tonepair_start | ( | struct ast_channel * | chan, | |
| int | freq1, | |||
| int | freq2, | |||
| int | duration, | |||
| int | vol | |||
| ) |
Start a tone going
Definition at line 5723 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().
05724 { 05725 struct tonepair_def d = { 0, }; 05726 05727 d.freq1 = freq1; 05728 d.freq2 = freq2; 05729 d.duration = duration; 05730 d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */ 05731 if (ast_activate_generator(chan, &tonepair, &d)) 05732 return -1; 05733 return 0; 05734 }
| void ast_tonepair_stop | ( | struct ast_channel * | chan | ) |
Stop a tone from playing
Definition at line 5736 of file channel.c.
References ast_deactivate_generator().
Referenced by sendnoise().
05737 { 05738 ast_deactivate_generator(chan); 05739 }
| int ast_transfer | ( | struct ast_channel * | chan, | |
| char * | dest | |||
| ) |
Transfer a call to dest, if the channel supports transfer.
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
Called by:
Definition at line 4303 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_ZOMBIE, ast_test_flag, ast_channel::tech, and ast_channel_tech::transfer.
Referenced by transfer_exec().
04304 { 04305 int res = -1; 04306 04307 /* Stop if we're a zombie or need a soft hangup */ 04308 ast_channel_lock(chan); 04309 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 04310 if (chan->tech->transfer) { 04311 res = chan->tech->transfer(chan, dest); 04312 if (!res) 04313 res = 1; 04314 } else 04315 res = 0; 04316 } 04317 ast_channel_unlock(chan); 04318 return res; 04319 }
| char* ast_transfercapability2str | ( | int | transfercapability | ) | const |
Gives the string form of a given transfer capability.
Gives the string form of a given transfer capability
| transfercapability | transfercapabilty to get the name of Give a name to a transfercapbility See above Returns the text form of the binary transfer capability |
Definition at line 690 of file channel.c.
References AST_TRANS_CAP_3_1K_AUDIO, AST_TRANS_CAP_DIGITAL, AST_TRANS_CAP_DIGITAL_W_TONES, AST_TRANS_CAP_RESTRICTED_DIGITAL, AST_TRANS_CAP_SPEECH, and AST_TRANS_CAP_VIDEO.
Referenced by cb_events(), dahdi_call(), dahdi_new(), misdn_call(), and oh323_call().
00691 { 00692 switch (transfercapability) { 00693 case AST_TRANS_CAP_SPEECH: 00694 return "SPEECH"; 00695 case AST_TRANS_CAP_DIGITAL: 00696 return "DIGITAL"; 00697 case AST_TRANS_CAP_RESTRICTED_DIGITAL: 00698 return "RESTRICTED_DIGITAL"; 00699 case AST_TRANS_CAP_3_1K_AUDIO: 00700 return "3K1AUDIO"; 00701 case AST_TRANS_CAP_DIGITAL_W_TONES: 00702 return "DIGITAL_W_TONES"; 00703 case AST_TRANS_CAP_VIDEO: 00704 return "VIDEO"; 00705 default: 00706 return "UNKNOWN"; 00707 } 00708 }
| void ast_uninstall_music_functions | ( | void | ) |
Definition at line 5804 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by unload_module().
05805 { 05806 ast_moh_start_ptr = NULL; 05807 ast_moh_stop_ptr = NULL; 05808 ast_moh_cleanup_ptr = NULL; 05809 }
| int ast_waitfor | ( | struct ast_channel * | chan, | |
| int | ms | |||
| ) |
Wait for input on a channel.
| chan | channel to wait on | |
| ms | length of time to wait on the channel Wait for input on a channel for a given # of milliseconds (<0 for indefinite). |
Definition at line 2459 of file channel.c.
References ast_waitfor_nandfds().
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), ast_dtmf_stream(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), async_wait(), background_detect_exec(), channel_spy(), conf_exec(), conf_flush(), dahdi_accept_r2_call_exec(), dictate_exec(), disa_exec(), do_idle_thread(), do_waiting(), echo_exec(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), measurenoise(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), recordthread(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_hangup(), waitforring_exec(), and waitstream_core().
02460 { 02461 int oldms = ms; /* -1 if no timeout */ 02462 02463 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); 02464 if ((ms < 0) && (oldms < 0)) 02465 ms = 0; 02466 return ms; 02467 }
| struct ast_channel* ast_waitfor_n | ( | struct ast_channel ** | chan, | |
| int | n, | |||
| int * | ms | |||
| ) | [read] |
Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.
| chan | an array of pointers to channels | |
| n | number of channels that are to be waited upon | |
| ms | time "ms" is modified in-place, if applicable |
Definition at line 2454 of file channel.c.
References ast_waitfor_nandfds().
Referenced by ast_generic_bridge(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), bridge_p2p_loop(), dahdi_bridge(), dial_exec_full(), feature_request_and_dial(), generic_thread_loop(), iax2_bridge(), misdn_bridge(), monitor_dial(), rpt(), rpt_exec(), wait_for_answer(), and wait_for_winner().
02455 { 02456 return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms); 02457 }
| 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.
Waits for input on an fd This version works on fd's only. Be careful with it.
Definition at line 2094 of file channel.c.
References ast_waitfor_nandfds().
Referenced by dundi_lookup_internal(), dundi_precache_internal(), and softmix_bridge_thread().
02095 { 02096 int winner = -1; 02097 ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms); 02098 return winner; 02099 }
| struct ast_channel* ast_waitfor_nandfds | ( | struct ast_channel ** | c, | |
| int | n, | |||
| int * | fds, | |||
| int | nfds, | |||
| int * | exception, | |||
| int * | outfd, | |||
| int * | ms | |||
| ) | [read] |
Wait for x amount of time on a file descriptor to have input.
Waits for activity on a group of channels.
Definition at line 2106 of file channel.c.
References ast_channel::_softhangup, ast_add_fd(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, ast_log(), AST_MAX_FDS, ast_poll, ast_set_flag, AST_SOFTHANGUP_TIMEOUT, ast_tvcmp(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), CHECK_BLOCKING, errno, ast_channel::fdno, and LOG_WARNING.
Referenced by ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), bridge_channel_join_multithreaded(), conf_run(), eivr_comm(), find_cache(), multiplexed_thread_function(), run_agi(), and waitstream_core().
02109 { 02110 struct timeval start = { 0 , 0 }; 02111 struct pollfd *pfds = NULL; 02112 int res; 02113 long rms; 02114 int x, y, max; 02115 int sz; 02116 struct timeval now = { 0, 0 }; 02117 struct timeval whentohangup = { 0, 0 }, diff; 02118 struct ast_channel *winner = NULL; 02119 struct fdmap { 02120 int chan; 02121 int fdno; 02122 } *fdmap = NULL; 02123 02124 if ((sz = n * AST_MAX_FDS + nfds)) { 02125 pfds = alloca(sizeof(*pfds) * sz); 02126 fdmap = alloca(sizeof(*fdmap) * sz); 02127 } 02128 02129 if (outfd) 02130 *outfd = -99999; 02131 if (exception) 02132 *exception = 0; 02133 02134 /* Perform any pending masquerades */ 02135 for (x = 0; x < n; x++) { 02136 ast_channel_lock(c[x]); 02137 if (c[x]->masq && ast_do_masquerade(c[x])) { 02138 ast_log(LOG_WARNING, "Masquerade failed\n"); 02139 *ms = -1; 02140 ast_channel_unlock(c[x]); 02141 return NULL; 02142 } 02143 if (!ast_tvzero(c[x]->whentohangup)) { 02144 if (ast_tvzero(whentohangup)) 02145 now = ast_tvnow(); 02146 diff = ast_tvsub(c[x]->whentohangup, now); 02147 if (diff.tv_sec < 0 || ast_tvzero(diff)) { 02148 /* Should already be hungup */ 02149 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 02150 ast_channel_unlock(c[x]); 02151 return c[x]; 02152 } 02153 if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0) 02154 whentohangup = diff; 02155 } 02156 ast_channel_unlock(c[x]); 02157 } 02158 /* Wait full interval */ 02159 rms = *ms; 02160 /* INT_MAX, not LONG_MAX, because it matters on 64-bit */ 02161 if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) { 02162 rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000; /* timeout in milliseconds */ 02163 if (*ms >= 0 && *ms < rms) { /* original *ms still smaller */ 02164 rms = *ms; 02165 } 02166 } else if (!ast_tvzero(whentohangup) && rms < 0) { 02167 /* Tiny corner case... call would need to last >24 days */ 02168 rms = INT_MAX; 02169 } 02170 /* 02171 * Build the pollfd array, putting the channels' fds first, 02172 * followed by individual fds. Order is important because 02173 * individual fd's must have priority over channel fds. 02174 */ 02175 max = 0; 02176 for (x = 0; x < n; x++) { 02177 for (y = 0; y < AST_MAX_FDS; y++) { 02178 fdmap[max].fdno = y; /* fd y is linked to this pfds */ 02179 fdmap[max].chan = x; /* channel x is linked to this pfds */ 02180 max += ast_add_fd(&pfds[max], c[x]->fds[y]); 02181 } 02182 CHECK_BLOCKING(c[x]); 02183 } 02184 /* Add the individual fds */ 02185 for (x = 0; x < nfds; x++) { 02186 fdmap[max].chan = -1; 02187 max += ast_add_fd(&pfds[max], fds[x]); 02188 } 02189 02190 if (*ms > 0) 02191 start = ast_tvnow(); 02192 02193 if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */ 02194 do { 02195 int kbrms = rms; 02196 if (kbrms > 600000) 02197 kbrms = 600000; 02198 res = ast_poll(pfds, max, kbrms); 02199 if (!res) 02200 rms -= kbrms; 02201 } while (!res && (rms > 0)); 02202 } else { 02203 res = ast_poll(pfds, max, rms); 02204 } 02205 for (x = 0; x < n; x++) 02206 ast_clear_flag(c[x], AST_FLAG_BLOCKING); 02207 if (res < 0) { /* Simulate a timeout if we were interrupted */ 02208 if (errno != EINTR) 02209 *ms = -1; 02210 return NULL; 02211 } 02212 if (!ast_tvzero(whentohangup)) { /* if we have a timeout, check who expired */ 02213 now = ast_tvnow(); 02214 for (x = 0; x < n; x++) { 02215 if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) { 02216 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 02217 if (winner == NULL) 02218 winner = c[x]; 02219 } 02220 } 02221 } 02222 if (res == 0) { /* no fd ready, reset timeout and done */ 02223 *ms = 0; /* XXX use 0 since we may not have an exact timeout. */ 02224 return winner; 02225 } 02226 /* 02227 * Then check if any channel or fd has a pending event. 02228 * Remember to check channels first and fds last, as they 02229 * must have priority on setting 'winner' 02230 */ 02231 for (x = 0; x < max; x++) { 02232 res = pfds[x].revents; 02233 if (res == 0) 02234 continue; 02235 if (fdmap[x].chan >= 0) { /* this is a channel */ 02236 winner = c[fdmap[x].chan]; /* override previous winners */ 02237 if (res & POLLPRI) 02238 ast_set_flag(winner, AST_FLAG_EXCEPTION); 02239 else 02240 ast_clear_flag(winner, AST_FLAG_EXCEPTION); 02241 winner->fdno = fdmap[x].fdno; 02242 } else { /* this is an fd */ 02243 if (outfd) 02244 *outfd = pfds[x].fd; 02245 if (exception) 02246 *exception = (res & POLLPRI) ? -1 : 0; 02247 winner = NULL; 02248 } 02249 } 02250 if (*ms > 0) { 02251 *ms -= ast_tvdiff_ms(ast_tvnow(), start); 02252 if (*ms < 0) 02253 *ms = 0; 02254 } 02255 return winner; 02256 }
| int ast_waitfordigit | ( | struct ast_channel * | c, | |
| int | ms | |||
| ) |
Waits for a digit.
!
| c | channel to wait for a digit on | |
| ms | how many milliseconds to wait |
Definition at line 2470 of file channel.c.
References ast_waitfordigit_full().
Referenced by _ast_adsi_get_cpeid(), _ast_adsi_get_cpeinfo(), _ast_adsi_print(), _ast_adsi_read_encoded_dtmf(), _ast_adsi_transmit_message_full(), _while_exec(), advanced_options(), ast_app_dtget(), ast_control_streamfile(), ast_record_review(), bridge_channel_feature(), builtin_atxfer(), collect_digits(), common_exec(), cpeid_exec(), dialout(), directory_exec(), forward_message(), get_folder(), ivr_dispatch(), mgcp_ss(), my_getsigstr(), pbx_builtin_waitexten(), play_record_review(), read_exec(), read_newoption(), readexten_exec(), retrydial_exec(), select_item_menu(), select_item_pause(), select_item_seq(), sendnoise(), ss_thread(), testclient_exec(), testserver_exec(), vm_execmain(), vm_forwardoptions(), vm_instructions_en(), vm_options(), vm_tempgreeting(), wait_a_bit(), and wait_our_turn().
02471 { 02472 return ast_waitfordigit_full(c, ms, -1, -1); 02473 }
| int ast_waitfordigit_full | ( | struct ast_channel * | c, | |
| int | ms, | |||
| int | audiofd, | |||
| int | ctrlfd | |||
| ) |
Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
| c | channel to wait for a digit on | |
| ms | how many milliseconds to wait | |
| audiofd | audio file descriptor to write to if audio frames are received | |
| ctrlfd | control file descriptor to monitor for reading |
Definition at line 2508 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_set_flag, ast_test_flag, ast_waitfor_nandfds(), ast_frame::data, ast_frame::datalen, errno, f, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.
Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().
02509 { 02510 /* Stop if we're a zombie or need a soft hangup */ 02511 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 02512 return -1; 02513 02514 /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */ 02515 ast_set_flag(c, AST_FLAG_END_DTMF_ONLY); 02516 02517 /* Wait for a digit, no more than ms milliseconds total. */ 02518 02519 while (ms) { 02520 struct ast_channel *rchan; 02521 int outfd=-1; 02522 02523 errno = 0; 02524 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms); 02525 02526 if (!rchan && outfd < 0 && ms) { 02527 if (errno == 0 || errno == EINTR) 02528 continue; 02529 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno)); 02530 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02531 return -1; 02532 } else if (outfd > -1) { 02533 /* The FD we were watching has something waiting */ 02534 ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n"); 02535 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02536 return 1; 02537 } else if (rchan) { 02538 int res; 02539 struct ast_frame *f = ast_read(c); 02540 if (!f) 02541 return -1; 02542 02543 switch (f->frametype) { 02544 case AST_FRAME_DTMF_BEGIN: 02545 break; 02546 case AST_FRAME_DTMF_END: 02547 res = f->subclass; 02548 ast_frfree(f); 02549 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02550 return res; 02551 case AST_FRAME_CONTROL: 02552 switch (f->subclass) { 02553 case AST_CONTROL_HANGUP: 02554 ast_frfree(f); 02555 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02556 return -1; 02557 case AST_CONTROL_RINGING: 02558 case AST_CONTROL_ANSWER: 02559 case AST_CONTROL_SRCUPDATE: 02560 case AST_CONTROL_SRCCHANGE: 02561 /* Unimportant */ 02562 break; 02563 default: 02564 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass); 02565 break; 02566 } 02567 break; 02568 case AST_FRAME_VOICE: 02569 /* Write audio if appropriate */ 02570 if (audiofd > -1) { 02571 if (write(audiofd, f->data.ptr, f->datalen) < 0) { 02572 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 02573 } 02574 } 02575 default: 02576 /* Ignore */ 02577 break; 02578 } 02579 ast_frfree(f); 02580 } 02581 } 02582 02583 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02584 02585 return 0; /* Time is up */ 02586 }
| struct ast_channel* ast_walk_channel_by_exten_locked | ( | const struct ast_channel * | chan, | |
| const char * | exten, | |||
| const char * | context | |||
| ) | [read] |
Get next channel by exten (and optionally context) and lock it.
Definition at line 1317 of file channel.c.
References channel_find_locked().
Referenced by next_channel().
01319 { 01320 return channel_find_locked(chan, NULL, 0, context, exten); 01321 }
| struct ast_channel* ast_walk_channel_by_name_prefix_locked | ( | const struct ast_channel * | chan, | |
| const char * | name, | |||
| const int | namelen | |||
| ) | [read] |
Get next channel by name prefix and lock it.
Get channel by name or uniqueid prefix (locks channel).
Definition at line 1304 of file channel.c.
References channel_find_locked().
Referenced by my_ast_get_channel_by_name_locked(), next_channel(), and softhangup_exec().
01306 { 01307 return channel_find_locked(chan, name, namelen, NULL, NULL); 01308 }
| int ast_write | ( | struct ast_channel * | chan, | |
| struct ast_frame * | frame | |||
| ) |
Write a frame to a channel This function writes the given frame to the indicated channel.
| chan | destination channel of the frame | |
| frame | frame that will be written |
Definition at line 3616 of file channel.c.
References ast_channel::_softhangup, apply_plc(), ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_deactivate_generator(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, ast_format_rate(), AST_FORMAT_SLINEAR, AST_FORMAT_T140, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_NEXT, ast_log(), AST_MONITOR_RUNNING, ast_opt_generic_plc, ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), ast_channel::audiohooks, calc_monitor_jump(), CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_filestream::fmt, ast_format::format, ast_channel::fout, FRAMECOUNT_INC, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, ast_frame::len, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, chanlist::next, ast_channel::outsmpl, ast_frame::ptr, ast_channel::rawwriteformat, ast_channel_monitor::read_stream, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), ast_channel_tech::send_html, ast_channel_tech::send_text, ast_frame::src, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel_tech::write, ast_channel_monitor::write_stream, ast_channel_tech::write_text, ast_channel_tech::write_video, and ast_channel::writetrans.
Referenced by adsi_careful_send(), agent_write(), ast_generic_bridge(), ast_prod(), ast_readaudio_callback(), ast_readvideo_callback(), ast_udptl_bridge(), ast_write_video(), bridge_native_loop(), bridge_p2p_loop(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), fax_generator_generate(), feature_request_and_dial(), function_ilink(), gen_generate(), handle_jack_audio(), handle_link_data(), iax2_bridge(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), multiplexed_bridge_write(), NBScat_exec(), playtones_generator(), rpt(), rpt_exec(), send_link_dtmf(), send_link_keyquery(), send_tone_burst(), send_usb_txt(), send_waveform_to_channel(), silence_generator_generate(), simple_bridge_write(), sms_generate(), softmix_bridge_poke(), softmix_bridge_write(), spy_generate(), t38_tx_packet_handler(), tonepair_generator(), and wait_for_answer().
03617 { 03618 int res = -1; 03619 struct ast_frame *f = NULL; 03620 int count = 0; 03621 03622 /*Deadlock avoidance*/ 03623 while(ast_channel_trylock(chan)) { 03624 /*cannot goto done since the channel is not locked*/ 03625 if(count++ > 10) { 03626 ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name); 03627 return 0; 03628 } 03629 usleep(1); 03630 } 03631 /* Stop if we're a zombie or need a soft hangup */ 03632 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 03633 goto done; 03634 03635 /* Handle any pending masquerades */ 03636 if (chan->masq && ast_do_masquerade(chan)) { 03637 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 03638 goto done; 03639 } 03640 if (chan->masqr) { 03641 res = 0; /* XXX explain, why 0 ? */ 03642 goto done; 03643 } 03644 if (chan->generatordata && (!fr->src || strcasecmp(fr->src, "ast_prod"))) { 03645 if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) { 03646 ast_deactivate_generator(chan); 03647 } else { 03648 if (fr->frametype == AST_FRAME_DTMF_END) { 03649 /* There is a generator running while we're in the middle of a digit. 03650 * It's probably inband DTMF, so go ahead and pass it so it can 03651 * stop the generator */ 03652 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03653 ast_channel_unlock(chan); 03654 res = ast_senddigit_end(chan, fr->subclass, fr->len); 03655 ast_channel_lock(chan); 03656 CHECK_BLOCKING(chan); 03657 } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) { 03658 /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */ 03659 res = (chan->tech->indicate == NULL) ? 0 : 03660 chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); 03661 } 03662 res = 0; /* XXX explain, why 0 ? */ 03663 goto done; 03664 } 03665 } 03666 /* High bit prints debugging */ 03667 if (chan->fout & DEBUGCHAN_FLAG) 03668 ast_frame_dump(chan->name, fr, ">>"); 03669 CHECK_BLOCKING(chan); 03670 switch (fr->frametype) { 03671 case AST_FRAME_CONTROL: 03672 res = (chan->tech->indicate == NULL) ? 0 : 03673 chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); 03674 break; 03675 case AST_FRAME_DTMF_BEGIN: 03676 if (chan->audiohooks) { 03677 struct ast_frame *old_frame = fr; 03678 fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 03679 if (old_frame != fr) 03680 f = fr; 03681 } 03682 send_dtmf_event(chan, "Sent", fr->subclass, "Yes", "No"); 03683 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03684 ast_channel_unlock(chan); 03685 res = ast_senddigit_begin(chan, fr->subclass); 03686 ast_channel_lock(chan); 03687 CHECK_BLOCKING(chan); 03688 break; 03689 case AST_FRAME_DTMF_END: 03690 if (chan->audiohooks) { 03691 struct ast_frame *new_frame = fr; 03692 03693 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 03694 if (new_frame != fr) { 03695 ast_frfree(new_frame); 03696 } 03697 } 03698 send_dtmf_event(chan, "Sent", fr->subclass, "No", "Yes"); 03699 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03700 ast_channel_unlock(chan); 03701 res = ast_senddigit_end(chan, fr->subclass, fr->len); 03702 ast_channel_lock(chan); 03703 CHECK_BLOCKING(chan); 03704 break; 03705 case AST_FRAME_TEXT: 03706 if (fr->subclass == AST_FORMAT_T140) { 03707 res = (chan->tech->write_text == NULL) ? 0 : 03708 chan->tech->write_text(chan, fr); 03709 } else { 03710 res = (chan->tech->send_text == NULL) ? 0 : 03711 chan->tech->send_text(chan, (char *) fr->data.ptr); 03712 } 03713 break; 03714 case AST_FRAME_HTML: 03715 res = (chan->tech->send_html == NULL) ? 0 : 03716 chan->tech->send_html(chan, fr->subclass, (char *) fr->data.ptr, fr->datalen); 03717 break; 03718 case AST_FRAME_VIDEO: 03719 /* XXX Handle translation of video codecs one day XXX */ 03720 res = (chan->tech->write_video == NULL) ? 0 : 03721 chan->tech->write_video(chan, fr); 03722 break; 03723 case AST_FRAME_MODEM: 03724 res = (chan->tech->write == NULL) ? 0 : 03725 chan->tech->write(chan, fr); 03726 break; 03727 case AST_FRAME_VOICE: 03728 if (chan->tech->write == NULL) 03729 break; /*! \todo XXX should return 0 maybe ? */ 03730 03731 if (ast_opt_generic_plc && fr->subclass == AST_FORMAT_SLINEAR) { 03732 apply_plc(chan, fr); 03733 } 03734 03735 /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */ 03736 if (fr->subclass == chan->rawwriteformat) 03737 f = fr; 03738 else 03739 f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr; 03740 03741 if (!f) { 03742 res = 0; 03743 break; 03744 } 03745 03746 if (chan->audiohooks) { 03747 struct ast_frame *prev = NULL, *new_frame, *cur, *dup; 03748 int freeoldlist = 0; 03749 03750 if (f != fr) { 03751 freeoldlist = 1; 03752 } 03753 03754 /* Since ast_audiohook_write may return a new frame, and the cur frame is 03755 * an item in a list of frames, create a new list adding each cur frame back to it 03756 * regardless if the cur frame changes or not. */ 03757 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 03758 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur); 03759 03760 /* if this frame is different than cur, preserve the end of the list, 03761 * free the old frames, and set cur to be the new frame */ 03762 if (new_frame != cur) { 03763 03764 /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame 03765 * isn't part of local storage, meaning if ast_audiohook_write is called multiple 03766 * times it may override the previous frame we got from it unless we dup it */ 03767 if ((dup = ast_frisolate(new_frame))) { 03768 AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list); 03769 if (freeoldlist) { 03770 AST_LIST_NEXT(cur, frame_list) = NULL; 03771 ast_frfree(cur); 03772 } 03773 if (new_frame != dup) { 03774 ast_frfree(new_frame); 03775 } 03776 cur = dup; 03777 } 03778 } 03779 03780 /* now, regardless if cur is new or not, add it to the new list, 03781 * if the new list has not started, cur will become the first item. */ 03782 if (prev) { 03783 AST_LIST_NEXT(prev, frame_list) = cur; 03784 } else { 03785 f = cur; /* set f to be the beginning of our new list */ 03786 } 03787 prev = cur; 03788 } 03789 } 03790 03791 /* If Monitor is running on this channel, then we have to write frames out there too */ 03792 /* the translator on chan->writetrans may have returned multiple frames 03793 from the single frame we passed in; if so, feed each one of them to the 03794 monitor */ 03795 if (chan->monitor && chan->monitor->write_stream) { 03796 struct ast_frame *cur; 03797 03798 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 03799 /* XXX must explain this code */ 03800 #ifndef MONITOR_CONSTANT_DELAY 03801 int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples; 03802 if (jump >= 0) { 03803 jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03804 if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1) 03805 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03806 chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples; 03807 } else { 03808 chan->outsmpl += cur->samples; 03809 } 03810 #else 03811 int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03812 if (jump - MONITOR_DELAY >= 0) { 03813 if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1) 03814 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03815 chan->outsmpl += chan->insmpl - chan->outsmpl; 03816 } else { 03817 chan->outsmpl += cur->samples; 03818 } 03819 #endif 03820 if (chan->monitor->state == AST_MONITOR_RUNNING) { 03821 if (ast_writestream(chan->monitor->write_stream, cur) < 0) 03822 ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); 03823 } 03824 } 03825 } 03826 03827 /* the translator on chan->writetrans may have returned multiple frames 03828 from the single frame we passed in; if so, feed each one of them to the 03829 channel, freeing each one after it has been written */ 03830 if ((f != fr) && AST_LIST_NEXT(f, frame_list)) { 03831 struct ast_frame *cur, *next; 03832 unsigned int skip = 0; 03833 03834 for (cur = f, next = AST_LIST_NEXT(cur, frame_list); 03835 cur; 03836 cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) { 03837 if (!skip) { 03838 if ((res = chan->tech->write(chan, cur)) < 0) { 03839 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03840 skip = 1; 03841 } else if (next) { 03842 /* don't do this for the last frame in the list, 03843 as the code outside the loop will do it once 03844 */ 03845 chan->fout = FRAMECOUNT_INC(chan->fout); 03846 } 03847 } 03848 ast_frfree(cur); 03849 } 03850 03851 /* reset f so the code below doesn't attempt to free it */ 03852 f = NULL; 03853 } else { 03854 res = chan->tech->write(chan, f); 03855 } 03856 break; 03857 case AST_FRAME_NULL: 03858 case AST_FRAME_IAX: 03859 /* Ignore these */ 03860 res = 0; 03861 break; 03862 default: 03863 /* At this point, fr is the incoming frame and f is NULL. Channels do 03864 * not expect to get NULL as a frame pointer and will segfault. Hence, 03865 * we output the original frame passed in. */ 03866 res = chan->tech->write(chan, fr); 03867 break; 03868 } 03869 03870 if (f && f != fr) 03871 ast_frfree(f); 03872 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03873 03874 /* Consider a write failure to force a soft hangup */ 03875 if (res < 0) { 03876 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03877 } else { 03878 chan->fout = FRAMECOUNT_INC(chan->fout); 03879 } 03880 done: 03881 if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) { 03882 /* The list gets recreated if audiohooks are added again later */ 03883 ast_audiohook_detach_list(chan->audiohooks); 03884 chan->audiohooks = NULL; 03885 } 03886 ast_channel_unlock(chan); 03887 return res; 03888 }
| int ast_write_video | ( | struct ast_channel * | chan, | |
| struct ast_frame * | frame | |||
| ) |
Write video frame to a channel This function writes the given frame to the indicated channel.
| chan | destination channel of the frame | |
| frame | frame that will be written |
Definition at line 3501 of file channel.c.
References ast_write(), ast_channel::tech, and ast_channel_tech::write_video.
03502 { 03503 int res; 03504 if (!chan->tech->write_video) 03505 return 0; 03506 res = ast_write(chan, fr); 03507 if (!res) 03508 res = 1; 03509 return res; 03510 }
| static void bridge_play_sounds | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1 | |||
| ) | [static] |
Definition at line 5298 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_strdupa, bridge_playfile(), pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and s.
Referenced by ast_channel_bridge().
05299 { 05300 const char *s, *sound; 05301 05302 /* See if we need to play an audio file to any side of the bridge */ 05303 05304 ast_channel_lock(c0); 05305 if ((s = pbx_builtin_getvar_helper(c0, "BRIDGE_PLAY_SOUND"))) { 05306 sound = ast_strdupa(s); 05307 ast_channel_unlock(c0); 05308 bridge_playfile(c0, c1, sound, 0); 05309 pbx_builtin_setvar_helper(c0, "BRIDGE_PLAY_SOUND", NULL); 05310 } else { 05311 ast_channel_unlock(c0); 05312 } 05313 05314 ast_channel_lock(c1); 05315 if ((s = pbx_builtin_getvar_helper(c1, "BRIDGE_PLAY_SOUND"))) { 05316 sound = ast_strdupa(s); 05317 ast_channel_unlock(c1); 05318 bridge_playfile(c1, c0, sound, 0); 05319 pbx_builtin_setvar_helper(c1, "BRIDGE_PLAY_SOUND", NULL); 05320 } else { 05321 ast_channel_unlock(c1); 05322 } 05323 }
| static void bridge_playfile | ( | struct ast_channel * | chan, | |
| struct ast_channel * | peer, | |||
| const char * | sound, | |||
| int | remain | |||
| ) | [static] |
Definition at line 5012 of file channel.c.
References ast_autoservice_start(), ast_autoservice_stop(), AST_DIGIT_ANY, ast_say_number(), ast_stream_and_wait(), ast_channel::language, and sec.
Referenced by ast_channel_bridge(), and bridge_play_sounds().
05013 { 05014 int min = 0, sec = 0, check; 05015 05016 check = ast_autoservice_start(peer); 05017 if (check) 05018 return; 05019 05020 if (remain > 0) { 05021 if (remain / 60 > 1) { 05022 min = remain / 60; 05023 sec = remain % 60; 05024 } else { 05025 sec = remain; 05026 } 05027 } 05028 05029 if (!strcmp(sound,"timeleft")) { /* Queue support */ 05030 ast_stream_and_wait(chan, "vm-youhave", ""); 05031 if (min) { 05032 ast_say_number(chan, min, AST_DIGIT_ANY, chan->language, NULL); 05033 ast_stream_and_wait(chan, "queue-minutes", ""); 05034 } 05035 if (sec) { 05036 ast_say_number(chan, sec, AST_DIGIT_ANY, chan->language, NULL); 05037 ast_stream_and_wait(chan, "queue-seconds", ""); 05038 } 05039 } else { 05040 ast_stream_and_wait(chan, sound, ""); 05041 } 05042 05043 ast_autoservice_stop(peer); 05044 }
| static int calc_monitor_jump | ( | int | samples, | |
| int | sample_rate, | |||
| int | seek_rate | |||
| ) | [inline, static] |
calculates the number of samples to jump forward with in a monitor stream.
| number | of samples to seek forward after rate conversion. |
Definition at line 2694 of file channel.c.
Referenced by __ast_read(), and ast_write().
02695 { 02696 int diff = sample_rate - seek_rate; 02697 02698 if (diff > 0) { 02699 samples = samples / (float) (sample_rate / seek_rate); 02700 } else if (diff < 0) { 02701 samples = samples * (float) (seek_rate / sample_rate); 02702 } 02703 02704 return samples; 02705 }
| static struct ast_channel* channel_find_locked | ( | const struct ast_channel * | prev, | |
| const char * | name, | |||
| const int | namelen, | |||
| const char * | context, | |||
| const char * | exten | |||
| ) | [static, read] |
Helper function to find channels.
It supports these modes:
prev != NULL : get channel next in list after prev name != NULL : get channel with matching name name != NULL && namelen != 0 : get channel whose name starts with prefix exten != NULL : get channel whose exten or macroexten matches context != NULL && exten != NULL : get channel whose context or macrocontext
It returns with the channel's lock held. If getting the individual lock fails, unlock and retry quickly up to 10 times, then give up.
XXX also note that accessing fields (e.g. c->name in ast_log()) can only be done with the lock held or someone could delete the object while we work on it. This causes some ugliness in the code. Note that removing the first ast_log() may be harmful, as it would shorten the retry period and possibly cause failures. We should definitely go for a better scheme that is deadlock-free.
Definition at line 1202 of file channel.c.
References ast_channel_trylock, ast_debug, AST_RWLIST_NEXT, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_channel::context, ast_channel::exten, ast_channel::macrocontext, ast_channel::macroexten, msg, ast_channel::name, and ast_channel::uniqueid.
Referenced by ast_channel_walk_locked(), ast_get_channel_by_exten_locked(), ast_get_channel_by_name_locked(), ast_get_channel_by_name_prefix_locked(), ast_walk_channel_by_exten_locked(), and ast_walk_channel_by_name_prefix_locked().
01205 { 01206 const char *msg = prev ? "deadlock" : "initial deadlock"; 01207 int retries; 01208 struct ast_channel *c; 01209 const struct ast_channel *_prev = prev; 01210 01211 for (retries = 0; retries < 200; retries++) { 01212 int done; 01213 /* Reset prev on each retry. See note below for the reason. */ 01214 prev = _prev; 01215 AST_RWLIST_RDLOCK(&channels); 01216 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 01217 if (prev) { /* look for last item, first, before any evaluation */ 01218 if (c != prev) /* not this one */ 01219 continue; 01220 /* found, prepare to return c->next */ 01221 if ((c = AST_RWLIST_NEXT(c, chan_list)) == NULL) break; 01222 /*!\note 01223 * We're done searching through the list for the previous item. 01224 * Any item after this point, we want to evaluate for a match. 01225 * If we didn't set prev to NULL here, then we would only 01226 * return matches for the first matching item (since the above 01227 * "if (c != prev)" would not permit any other potential 01228 * matches to reach the additional matching logic, below). 01229 * Instead, it would just iterate until it once again found the 01230 * original match, then iterate down to the end of the list and 01231 * quit. 01232 */ 01233 prev = NULL; 01234 } 01235 if (name) { /* want match by name */ 01236 if ((!namelen && strcasecmp(c->name, name) && strcmp(c->uniqueid, name)) || 01237 (namelen && strncasecmp(c->name, name, namelen))) 01238 continue; /* name match failed */ 01239 } else if (exten) { 01240 if (context && strcasecmp(c->context, context) && 01241 strcasecmp(c->macrocontext, context)) 01242 continue; /* context match failed */ 01243 if (strcasecmp(c->exten, exten) && 01244 strcasecmp(c->macroexten, exten)) 01245 continue; /* exten match failed */ 01246 } 01247 /* if we get here, c points to the desired record */ 01248 break; 01249 } 01250 /* exit if chan not found or mutex acquired successfully */ 01251 /* this is slightly unsafe, as we _should_ hold the lock to access c->name */ 01252 done = c == NULL || ast_channel_trylock(c) == 0; 01253 if (!done) { 01254 ast_debug(1, "Avoiding %s for channel '%p'\n", msg, c); 01255 if (retries == 199) { 01256 /* We are about to fail due to a deadlock, so report this 01257 * while we still have the list lock. 01258 */ 01259 ast_debug(1, "Failure, could not lock '%p' after %d retries!\n", c, retries); 01260 /* As we have deadlocked, we will skip this channel and 01261 * see if there is another match. 01262 * NOTE: No point doing this for a full-name match, 01263 * as there can be no more matches. 01264 */ 01265 if (!(name && !namelen)) { 01266 _prev = c; 01267 retries = -1; 01268 } 01269 } 01270 } 01271 AST_RWLIST_UNLOCK(&channels); 01272 if (done) 01273 return c; 01274 /* If we reach this point we basically tried to lock a channel and failed. Instead of 01275 * starting from the beginning of the list we can restore our saved pointer to the previous 01276 * channel and start from there. 01277 */ 01278 prev = _prev; 01279 usleep(1); /* give other threads a chance before retrying */ 01280 } 01281 01282 return NULL; 01283 }
| const char* channelreloadreason2txt | ( | enum channelreloadreason | reason | ) |
Convert enum channelreloadreason to text string for manager event.
\ brief Convert channel reloadreason (ENUM) to text string for manager event
Definition at line 5972 of file channel.c.
References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.
Referenced by reload_config().
05973 { 05974 switch (reason) { 05975 case CHANNEL_MODULE_LOAD: 05976 return "LOAD (Channel module load)"; 05977 05978 case CHANNEL_MODULE_RELOAD: 05979 return "RELOAD (Channel module reload)"; 05980 05981 case CHANNEL_CLI_RELOAD: 05982 return "CLIRELOAD (Channel module reload by CLI command)"; 05983 05984 default: 05985 return "MANAGERRELOAD (Channel module reload by manager)"; 05986 } 05987 };
| static void clone_variables | ( | struct ast_channel * | original, | |
| struct ast_channel * | clonechan | |||
| ) | [static] |
Clone channel variables from 'clone' channel into 'original' channel.
All variables except those related to app_groupcount are cloned. Variables are actually _removed_ from 'clone' channel, presumably because it will subsequently be destroyed.
Definition at line 4608 of file channel.c.
References AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_t::entries, ast_var_t::name, ast_var_t::value, and ast_channel::varshead.
Referenced by ast_do_masquerade().
04609 { 04610 struct ast_var_t *current, *newvar; 04611 /* Append variables from clone channel into original channel */ 04612 /* XXX Is this always correct? We have to in order to keep MACROS working XXX */ 04613 if (AST_LIST_FIRST(&clonechan->varshead)) 04614 AST_LIST_APPEND_LIST(&original->varshead, &clonechan->varshead, entries); 04615 04616 /* then, dup the varshead list into the clone */ 04617 04618 AST_LIST_TRAVERSE(&original->varshead, current, entries) { 04619 newvar = ast_var_assign(current->name, current->value); 04620 if (newvar) 04621 AST_LIST_INSERT_TAIL(&clonechan->varshead, newvar, entries); 04622 } 04623 }
| static char* complete_channeltypes | ( | struct ast_cli_args * | a | ) | [static] |
Definition at line 246 of file channel.c.
References AST_LIST_TRAVERSE, ast_strdup, ast_cli_args::n, ast_cli_args::pos, chanlist::tech, ast_channel_tech::type, and ast_cli_args::word.
Referenced by handle_cli_core_show_channeltype().
00247 { 00248 struct chanlist *cl; 00249 int which = 0; 00250 int wordlen; 00251 char *ret = NULL; 00252 00253 if (a->pos != 3) 00254 return NULL; 00255 00256 wordlen = strlen(a->word); 00257 00258 AST_LIST_TRAVERSE(&backends, cl, list) { 00259 if (!strncasecmp(a->word, cl->tech->type, wordlen) && ++which > a->n) { 00260 ret = ast_strdup(cl->tech->type); 00261 break; 00262 } 00263 } 00264 00265 return ret; 00266 }
| static void free_cid | ( | struct ast_callerid * | cid | ) | [static] |
Definition at line 1440 of file channel.c.
References ast_free, ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, and ast_callerid::cid_rdnis.
Referenced by ast_channel_free().
01441 { 01442 if (cid->cid_dnid) 01443 ast_free(cid->cid_dnid); 01444 if (cid->cid_num) 01445 ast_free(cid->cid_num); 01446 if (cid->cid_name) 01447 ast_free(cid->cid_name); 01448 if (cid->cid_ani) 01449 ast_free(cid->cid_ani); 01450 if (cid->cid_rdnis) 01451 ast_free(cid->cid_rdnis); 01452 cid->cid_dnid = cid->cid_num = cid->cid_name = cid->cid_ani = cid->cid_rdnis = NULL; 01453 }
| static void free_translation | ( | struct ast_channel * | clonechan | ) | [static] |
Definition at line 1745 of file channel.c.
References ast_translator_free_path(), ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readtrans, and ast_channel::writetrans.
Referenced by ast_do_masquerade(), and ast_hangup().
01746 { 01747 if (clonechan->writetrans) 01748 ast_translator_free_path(clonechan->writetrans); 01749 if (clonechan->readtrans) 01750 ast_translator_free_path(clonechan->readtrans); 01751 clonechan->writetrans = NULL; 01752 clonechan->readtrans = NULL; 01753 clonechan->rawwriteformat = clonechan->nativeformats; 01754 clonechan->rawreadformat = clonechan->nativeformats; 01755 }
| static int generator_force | ( | const void * | data | ) | [static] |
Definition at line 2039 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_deactivate_generator(), ast_debug, AST_FORMAT_AUDIO_MASK, ast_format_rate(), ast_generator::generate, ast_channel::generator, ast_channel::generatordata, and ast_channel::writeformat.
Referenced by ast_activate_generator(), and ast_read_generator_actions().
02040 { 02041 /* Called if generator doesn't have data */ 02042 void *tmp; 02043 int res; 02044 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL; 02045 struct ast_channel *chan = (struct ast_channel *)data; 02046 02047 ast_channel_lock(chan); 02048 tmp = chan->generatordata; 02049 chan->generatordata = NULL; 02050 if (chan->generator) 02051 generate = chan->generator->generate; 02052 ast_channel_unlock(chan); 02053 02054 if (!tmp || !generate) 02055 return 0; 02056 02057 res = generate(chan, tmp, 0, ast_format_rate(chan->writeformat & AST_FORMAT_AUDIO_MASK) / 50); 02058 02059 chan->generatordata = tmp; 02060 02061 if (res) { 02062 ast_debug(1, "Auto-deactivating generator\n"); 02063 ast_deactivate_generator(chan); 02064 } 02065 02066 return 0; 02067 }
| static void handle_cause | ( | int | cause, | |
| int * | outstate | |||
| ) | [static] |
Definition at line 3983 of file channel.c.
References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CONTROL_BUSY, and AST_CONTROL_CONGESTION.
Referenced by __ast_request_and_dial(), and ast_call_forward().
03984 { 03985 if (outstate) { 03986 /* compute error and return */ 03987 if (cause == AST_CAUSE_BUSY) 03988 *outstate = AST_CONTROL_BUSY; 03989 else if (cause == AST_CAUSE_CONGESTION) 03990 *outstate = AST_CONTROL_CONGESTION; 03991 else 03992 *outstate = 0; 03993 } 03994 }
| static char* handle_cli_core_show_channeltype | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show details about a channel driver - CLI command.
Definition at line 269 of file channel.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_channel_tech::capabilities, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_channeltypes(), ast_channel_tech::devicestate, ast_cli_args::fd, ast_channel_tech::indicate, ast_channel_tech::send_digit_begin, ast_channel_tech::send_digit_end, ast_channel_tech::send_html, ast_channel_tech::send_image, ast_channel_tech::send_text, chanlist::tech, ast_channel_tech::transfer, ast_channel_tech::type, and ast_cli_entry::usage.
00270 { 00271 struct chanlist *cl = NULL; 00272 00273 switch (cmd) { 00274 case CLI_INIT: 00275 e->command = "core show channeltype"; 00276 e->usage = 00277 "Usage: core show channeltype <name>\n" 00278 " Show details about the specified channel type, <name>.\n"; 00279 return NULL; 00280 case CLI_GENERATE: 00281 return complete_channeltypes(a); 00282 } 00283 00284 if (a->argc != 4) 00285 return CLI_SHOWUSAGE; 00286 00287 AST_RWLIST_RDLOCK(&channels); 00288 00289 AST_LIST_TRAVERSE(&backends, cl, list) { 00290 if (!strncasecmp(cl->tech->type, a->argv[3], strlen(cl->tech->type))) 00291 break; 00292 } 00293 00294 00295 if (!cl) { 00296 ast_cli(a->fd, "\n%s is not a registered channel driver.\n", a->argv[3]); 00297 AST_RWLIST_UNLOCK(&channels); 00298 return CLI_FAILURE; 00299 } 00300 00301 ast_cli(a->fd, 00302 "-- Info about channel driver: %s --\n" 00303 " Device State: %s\n" 00304 " Indication: %s\n" 00305 " Transfer : %s\n" 00306 " Capabilities: %d\n" 00307 " Digit Begin: %s\n" 00308 " Digit End: %s\n" 00309 " Send HTML : %s\n" 00310 " Image Support: %s\n" 00311 " Text Support: %s\n", 00312 cl->tech->type, 00313 (cl->tech->devicestate) ? "yes" : "no", 00314 (cl->tech->indicate) ? "yes" : "no", 00315 (cl->tech->transfer) ? "yes" : "no", 00316 (cl->tech->capabilities) ? cl->tech->capabilities : -1, 00317 (cl->tech->send_digit_begin) ? "yes" : "no", 00318 (cl->tech->send_digit_end) ? "yes" : "no", 00319 (cl->tech->send_html) ? "yes" : "no", 00320 (cl->tech->send_image) ? "yes" : "no", 00321 (cl->tech->send_text) ? "yes" : "no" 00322 00323 ); 00324 00325 AST_RWLIST_UNLOCK(&channels); 00326 return CLI_SUCCESS; 00327 }
| static char* handle_cli_core_show_channeltypes | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show channel types - CLI command.
Definition at line 203 of file channel.c.
References ast_cli_args::argc, ast_cli(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_channel_tech::description, ast_channel_tech::devicestate, ast_cli_args::fd, FORMAT, ast_channel_tech::indicate, chanlist::tech, ast_channel_tech::transfer, ast_channel_tech::type, and ast_cli_entry::usage.
00204 { 00205 #define FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" 00206 struct chanlist *cl; 00207 int count_chan = 0; 00208 00209 switch (cmd) { 00210 case CLI_INIT: 00211 e->command = "core show channeltypes"; 00212 e->usage = 00213 "Usage: core show channeltypes\n" 00214 " Lists available channel types registered in your\n" 00215 " Asterisk server.\n"; 00216 return NULL; 00217 case CLI_GENERATE: 00218 return NULL; 00219 } 00220 00221 if (a->argc != 3) 00222 return CLI_SHOWUSAGE; 00223 00224 ast_cli(a->fd, FORMAT, "Type", "Description", "Devicestate", "Indications", "Transfer"); 00225 ast_cli(a->fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------"); 00226 00227 AST_RWLIST_RDLOCK(&channels); 00228 00229 AST_LIST_TRAVERSE(&backends, cl, list) { 00230 ast_cli(a->fd, FORMAT, cl->tech->type, cl->tech->description, 00231 (cl->tech->devicestate) ? "yes" : "no", 00232 (cl->tech->indicate) ? "yes" : "no", 00233 (cl->tech->transfer) ? "yes" : "no"); 00234 count_chan++; 00235 } 00236 00237 AST_RWLIST_UNLOCK(&channels); 00238 00239 ast_cli(a->fd, "----------\n%d channel drivers registered.\n", count_chan); 00240 00241 return CLI_SUCCESS; 00242 00243 #undef FORMAT 00244 }
| static int attribute_const is_visible_indication | ( | enum ast_control_frame_type | condition | ) | [static] |
Definition at line 3213 of file channel.c.
References _XXX_AST_CONTROL_T38, 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_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, and AST_CONTROL_WINK.
Referenced by ast_indicate_data().
03214 { 03215 /* Don't include a default case here so that we get compiler warnings 03216 * when a new type is added. */ 03217 03218 switch (condition) { 03219 case AST_CONTROL_PROGRESS: 03220 case AST_CONTROL_PROCEEDING: 03221 case AST_CONTROL_VIDUPDATE: 03222 case AST_CONTROL_SRCUPDATE: 03223 case AST_CONTROL_SRCCHANGE: 03224 case AST_CONTROL_RADIO_KEY: 03225 case AST_CONTROL_RADIO_UNKEY: 03226 case AST_CONTROL_OPTION: 03227 case AST_CONTROL_WINK: 03228 case AST_CONTROL_FLASH: 03229 case AST_CONTROL_OFFHOOK: 03230 case AST_CONTROL_TAKEOFFHOOK: 03231 case AST_CONTROL_ANSWER: 03232 case AST_CONTROL_HANGUP: 03233 case AST_CONTROL_T38_PARAMETERS: 03234 case _XXX_AST_CONTROL_T38: 03235 break; 03236 03237 case AST_CONTROL_CONGESTION: 03238 case AST_CONTROL_BUSY: 03239 case AST_CONTROL_RINGING: 03240 case AST_CONTROL_RING: 03241 case AST_CONTROL_HOLD: 03242 case AST_CONTROL_UNHOLD: 03243 return 1; 03244 } 03245 03246 return 0; 03247 }
| static void manager_bridge_event | ( | int | onoff, | |
| int | type, | |||
| struct ast_channel * | c0, | |||
| struct ast_channel * | c1 | |||
| ) | [static] |
Send manager event for bridge link and unlink events.
| onoff | Link/Unlinked | |
| type | 1 for core, 2 for native | |
| c0 | first channel in bridge | |
| c1 | second channel in bridge |
Definition at line 5243 of file channel.c.
References ast_channel::cid, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, ast_channel::name, S_OR, and ast_channel::uniqueid.
Referenced by ast_channel_bridge().
05244 { 05245 manager_event(EVENT_FLAG_CALL, "Bridge", 05246 "Bridgestate: %s\r\n" 05247 "Bridgetype: %s\r\n" 05248 "Channel1: %s\r\n" 05249 "Channel2: %s\r\n" 05250 "Uniqueid1: %s\r\n" 05251 "Uniqueid2: %s\r\n" 05252 "CallerID1: %s\r\n" 05253 "CallerID2: %s\r\n", 05254 onoff ? "Link" : "Unlink", 05255 type == 1 ? "core" : "native", 05256 c0->name, c1->name, c0->uniqueid, c1->uniqueid, 05257 S_OR(c0->cid.cid_num, ""), 05258 S_OR(c1->cid.cid_num, "")); 05259 }
| static void plc_ds_destroy | ( | void * | data | ) | [static] |
Definition at line 3525 of file channel.c.
References ast_free, and plc_ds::samples_buf.
03526 { 03527 struct plc_ds *plc = data; 03528 ast_free(plc->samples_buf); 03529 ast_free(plc); 03530 }
| static void queue_dtmf_readq | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f | |||
| ) | [inline, static] |
Definition at line 2649 of file channel.c.
References AST_FRAME_DTMF_END, ast_queue_frame(), ast_channel::dtmff, ast_frame::frametype, ast_frame::len, and ast_frame::subclass.
Referenced by __ast_read().
02650 { 02651 struct ast_frame *fr = &chan->dtmff; 02652 02653 fr->frametype = AST_FRAME_DTMF_END; 02654 fr->subclass = f->subclass; 02655 fr->len = f->len; 02656 02657 /* The only time this function will be called is for a frame that just came 02658 * out of the channel driver. So, we want to stick it on the tail of the 02659 * readq. */ 02660 02661 ast_queue_frame(chan, fr); 02662 }
| static void report_new_callerid | ( | const struct ast_channel * | chan | ) | [static] |
Definition at line 4628 of file channel.c.
References ast_describe_caller_presentation(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, EVENT_FLAG_CALL, manager_event, ast_channel::name, S_OR, and ast_channel::uniqueid.
Referenced by ast_do_masquerade(), and ast_set_callerid().
04629 { 04630 manager_event(EVENT_FLAG_CALL, "NewCallerid", 04631 "Channel: %s\r\n" 04632 "CallerIDNum: %s\r\n" 04633 "CallerIDName: %s\r\n" 04634 "Uniqueid: %s\r\n" 04635 "CID-CallingPres: %d (%s)\r\n", 04636 chan->name, 04637 S_OR(chan->cid.cid_num, ""), 04638 S_OR(chan->cid.cid_name, ""), 04639 chan->uniqueid, 04640 chan->cid.cid_pres, 04641 ast_describe_caller_presentation(chan->cid.cid_pres) 04642 ); 04643 }
| static void send_dtmf_event | ( | const struct ast_channel * | chan, | |
| const char * | direction, | |||
| const char | digit, | |||
| const char * | begin, | |||
| const char * | end | |||
| ) | [static] |
Definition at line 2588 of file channel.c.
References EVENT_FLAG_DTMF, manager_event, ast_channel::name, and ast_channel::uniqueid.
Referenced by __ast_read(), and ast_write().
02589 { 02590 manager_event(EVENT_FLAG_DTMF, 02591 "DTMF", 02592 "Channel: %s\r\n" 02593 "Uniqueid: %s\r\n" 02594 "Digit: %c\r\n" 02595 "Direction: %s\r\n" 02596 "Begin: %s\r\n" 02597 "End: %s\r\n", 02598 chan->name, chan->uniqueid, digit, direction, begin, end); 02599 }
| static int set_format | ( | struct ast_channel * | chan, | |
| int | fmt, | |||
| int * | rawformat, | |||
| int * | format, | |||
| struct ast_trans_pvt ** | trans, | |||
| const int | direction | |||
| ) | [static] |
Definition at line 3890 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, AST_FORMAT_AUDIO_MASK, ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_translator_best_choice(), ast_translator_build_path(), ast_translator_free_path(), LOG_WARNING, ast_channel::name, and ast_channel::nativeformats.
Referenced by ast_set_read_format(), and ast_set_write_format().
03892 { 03893 int native; 03894 int res; 03895 char from[200], to[200]; 03896 03897 /* Make sure we only consider audio */ 03898 fmt &= AST_FORMAT_AUDIO_MASK; 03899 03900 native = chan->nativeformats; 03901 03902 if (!fmt || !native) /* No audio requested */ 03903 return 0; /* Let's try a call without any sounds (video, text) */ 03904 03905 /* Find a translation path from the native format to one of the desired formats */ 03906 if (!direction) 03907 /* reading */ 03908 res = ast_translator_best_choice(&fmt, &native); 03909 else 03910 /* writing */ 03911 res = ast_translator_best_choice(&native, &fmt); 03912 03913 if (res < 0) { 03914 ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n", 03915 ast_getformatname_multiple(from, sizeof(from), native), 03916 ast_getformatname_multiple(to, sizeof(to), fmt)); 03917 return -1; 03918 } 03919 03920 /* Now we have a good choice for both. */ 03921 ast_channel_lock(chan); 03922 03923 if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) { 03924 /* the channel is already in these formats, so nothing to do */ 03925 ast_channel_unlock(chan); 03926 return 0; 03927 } 03928 03929 *rawformat = native; 03930 /* User perspective is fmt */ 03931 *format = fmt; 03932 /* Free any read translation we have right now */ 03933 if (*trans) 03934 ast_translator_free_path(*trans); 03935 /* Build a translation path from the raw format to the desired format */ 03936 if (!direction) 03937 /* reading */ 03938 *trans = ast_translator_build_path(*format, *rawformat); 03939 else 03940 /* writing */ 03941 *trans = ast_translator_build_path(*rawformat, *format); 03942 ast_channel_unlock(chan); 03943 ast_debug(1, "Set channel %s to %s format %s\n", chan->name, 03944 direction ? "write" : "read", ast_getformatname(fmt)); 03945 return 0; 03946 }
| static int should_skip_dtmf | ( | struct ast_channel * | chan | ) | [inline, static] |
Determine whether or not we should ignore DTMF in the readq.
Definition at line 2667 of file channel.c.
References AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_MIN_DTMF_GAP, ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::dtmf_tv.
Referenced by __ast_read().
02668 { 02669 if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF)) { 02670 /* We're in the middle of emulating a digit, or DTMF has been 02671 * explicitly deferred. Skip this digit, then. */ 02672 return 1; 02673 } 02674 02675 if (!ast_tvzero(chan->dtmf_tv) && 02676 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02677 /* We're not in the middle of a digit, but it hasn't been long enough 02678 * since the last digit, so we'll have to skip DTMF for now. */ 02679 return 1; 02680 } 02681 02682 return 0; 02683 }
| static void* silence_generator_alloc | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
| static int silence_generator_generate | ( | struct ast_channel * | chan, | |
| void * | data, | |||
| int | len, | |||
| int | samples | |||
| ) | [static] |
Definition at line 5903 of file channel.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_write(), and ast_frame::frametype.
05904 { 05905 short buf[samples]; 05906 struct ast_frame frame = { 05907 .frametype = AST_FRAME_VOICE, 05908 .subclass = AST_FORMAT_SLINEAR, 05909 .data.ptr = buf, 05910 .samples = samples, 05911 .datalen = sizeof(buf), 05912 }; 05913 05914 memset(buf, 0, sizeof(buf)); 05915 05916 if (ast_write(chan, &frame)) 05917 return -1; 05918 05919 return 0; 05920 }
| static void silence_generator_release | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
| static void* tonepair_alloc | ( | struct ast_channel * | chan, | |
| void * | params | |||
| ) | [static] |
Definition at line 5641 of file channel.c.
References ast_calloc, AST_FLAG_WRITE_INT, AST_FORMAT_SLINEAR, ast_log(), ast_set_flag, ast_set_write_format(), cos, tonepair_def::duration, tonepair_state::duration, tonepair_state::fac1, tonepair_state::fac2, tonepair_def::freq1, tonepair_def::freq2, LOG_WARNING, tonepair_state::modulate, ast_channel::name, tonepair_state::origwfmt, tonepair_release(), tonepair_state::v1_1, tonepair_state::v2_1, tonepair_state::v2_2, tonepair_state::v3_1, tonepair_state::v3_2, tonepair_def::vol, and ast_channel::writeformat.
05642 { 05643 struct tonepair_state *ts; 05644 struct tonepair_def *td = params; 05645 05646 if (!(ts = ast_calloc(1, sizeof(*ts)))) 05647 return NULL; 05648 ts->origwfmt = chan->writeformat; 05649 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { 05650 ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name); 05651 tonepair_release(NULL, ts); 05652 ts = NULL; 05653 } else { 05654 ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0; 05655 ts->v1_1 = 0; 05656 ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 05657 ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 05658 ts->v2_1 = 0; 05659 ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0; 05660 ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 05661 ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 05662 ts->duration = td->duration; 05663 ts->modulate = 0; 05664 } 05665 /* Let interrupts interrupt :) */ 05666 ast_set_flag(chan, AST_FLAG_WRITE_INT); 05667 return ts; 05668 }
| static int tonepair_generator | ( | struct ast_channel * | chan, | |
| void * | data, | |||
| int | len, | |||
| int | samples | |||
| ) | [static] |
Definition at line 5670 of file channel.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame::data, tonepair_state::data, ast_frame::datalen, tonepair_state::duration, tonepair_state::f, tonepair_state::fac1, tonepair_state::fac2, ast_frame::frametype, LOG_WARNING, tonepair_state::modulate, ast_frame::offset, tonepair_state::pos, ast_frame::ptr, ast_frame::samples, ast_frame::subclass, tonepair_state::v1_1, tonepair_state::v1_2, tonepair_state::v2_1, tonepair_state::v2_2, tonepair_state::v3_1, and tonepair_state::v3_2.
05671 { 05672 struct tonepair_state *ts = data; 05673 int x; 05674 05675 /* we need to prepare a frame with 16 * timelen samples as we're 05676 * generating SLIN audio 05677 */ 05678 len = samples * 2; 05679 05680 if (len > sizeof(ts->data) / 2 - 1) { 05681 ast_log(LOG_WARNING, "Can't generate that much data!\n"); 05682 return -1; 05683 } 05684 memset(&ts->f, 0, sizeof(ts->f)); 05685 for (x=0;x<len/2;x++) { 05686 ts->v1_1 = ts->v2_1; 05687 ts->v2_1 = ts->v3_1; 05688 ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1; 05689 05690 ts->v1_2 = ts->v2_2; 05691 ts->v2_2 = ts->v3_2; 05692 ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2; 05693 if (ts->modulate) { 05694 int p; 05695 p = ts->v3_2 - 32768; 05696 if (p < 0) p = -p; 05697 p = ((p * 9) / 10) + 1; 05698 ts->data[x] = (ts->v3_1 * p) >> 15; 05699 } else 05700 ts->data[x] = ts->v3_1 + ts->v3_2; 05701 } 05702 ts->f.frametype = AST_FRAME_VOICE; 05703 ts->f.subclass = AST_FORMAT_SLINEAR; 05704 ts->f.datalen = len; 05705 ts->f.samples = samples; 05706 ts->f.offset = AST_FRIENDLY_OFFSET; 05707 ts->f.data.ptr = ts->data; 05708 ast_write(chan, &ts->f); 05709 ts->pos += x; 05710 if (ts->duration > 0) { 05711 if (ts->pos >= ts->duration * 8) 05712 return -1; 05713 } 05714 return 0; 05715 }
| static void tonepair_release | ( | struct ast_channel * | chan, | |
| void * | params | |||
| ) | [static] |
Definition at line 5632 of file channel.c.
References ast_free, ast_set_write_format(), and tonepair_state::origwfmt.
Referenced by tonepair_alloc().
05633 { 05634 struct tonepair_state *ts = params; 05635 05636 if (chan) 05637 ast_set_write_format(chan, ts->origwfmt); 05638 ast_free(ts); 05639 }
| static void update_bridge_vars | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1 | |||
| ) | [static] |
Definition at line 5261 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_strdupa, ast_strlen_zero(), ast_channel_tech::get_pvt_uniqueid, ast_channel::name, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and ast_channel::tech.
Referenced by ast_channel_bridge().
05262 { 05263 const char *c0_name; 05264 const char *c1_name; 05265 const char *c0_pvtid = NULL; 05266 const char *c1_pvtid = NULL; 05267 05268 ast_channel_lock(c1); 05269 c1_name = ast_strdupa(c1->name); 05270 if (c1->tech->get_pvt_uniqueid) { 05271 c1_pvtid = ast_strdupa(c1->tech->get_pvt_uniqueid(c1)); 05272 } 05273 ast_channel_unlock(c1); 05274 05275 ast_channel_lock(c0); 05276 if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) { 05277 pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1_name); 05278 } 05279 if (c1_pvtid) { 05280 pbx_builtin_setvar_helper(c0, "BRIDGEPVTCALLID", c1_pvtid); 05281 } 05282 c0_name = ast_strdupa(c0->name); 05283 if (c0->tech->get_pvt_uniqueid) { 05284 c0_pvtid = ast_strdupa(c0->tech->get_pvt_uniqueid(c0)); 05285 } 05286 ast_channel_unlock(c0); 05287 05288 ast_channel_lock(c1); 05289 if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) { 05290 pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0_name); 05291 } 05292 if (c0_pvtid) { 05293 pbx_builtin_setvar_helper(c1, "BRIDGEPVTCALLID", c0_pvtid); 05294 } 05295 ast_channel_unlock(c1); 05296 }
void(* ast_moh_cleanup_ptr)(struct ast_channel *) = NULL [static] |
Referenced by ast_install_music_functions(), ast_moh_cleanup(), and ast_uninstall_music_functions().
int(* ast_moh_start_ptr)(struct ast_channel *, const char *, const char *) = NULL [static] |
Referenced by ast_install_music_functions(), ast_moh_start(), and ast_uninstall_music_functions().
void(* ast_moh_stop_ptr)(struct ast_channel *) = NULL [static] |
Referenced by ast_install_music_functions(), ast_moh_stop(), and ast_uninstall_music_functions().
| int cause |
Definition at line 136 of file channel.c.
Referenced by __ast_read(), __ast_request_and_dial(), ast_call_forward(), ast_str2cause(), cb_events(), dahdi_hangup(), dial_exec_full(), dial_transfer(), do_forward(), dump_cause(), feature_request_and_dial(), oh323_hangup(), ospfinished_exec(), ospnext_exec(), parse_disconnect(), parse_release(), parse_release_complete(), parse_status(), pbx_builtin_hangup(), play_sound_file(), pri_dchannel(), sms_messagerx(), and sms_messagerx2().
struct { ... } causes[] [static] |
map AST_CAUSE's to readable string representations
Referenced by ast_cause2str(), ast_str2cause(), and dump_cause().
struct ast_cli_entry cli_channel[] [static] |
Initial value:
{
AST_CLI_DEFINE(handle_cli_core_show_channeltypes, "List available channel types"),
AST_CLI_DEFINE(handle_cli_core_show_channeltype, "Give more details on that channel type")
}
Definition at line 329 of file channel.c.
Referenced by ast_channels_init().
| const char* desc |
Definition at line 138 of file channel.c.
Referenced by acf_retrieve_docs(), ast_tcptls_client_start(), ast_tcptls_server_root(), dump_cause(), handle_cli_ulimit(), init_acf_query(), load_rpt_vars(), misdn_cfg_get_desc(), show_config_description(), and str2desc().
| unsigned long global_fin |
The current value of the debug flags is stored in the two variables global_fin and global_fout (declared in main/channel.c)
Definition at line 86 of file channel.c.
Referenced by handle_core_set_debug_channel().
| unsigned long global_fout |
struct ast_channel_tech null_tech [static] |
Initial value:
{
.type = "NULL",
.description = "Null channel (should not see this)",
}
Definition at line 765 of file channel.c.
Referenced by __ast_channel_alloc_ap().
struct ast_datastore_info plc_ds_info [static] |
Initial value:
{
.type = "plc",
.destroy = plc_ds_destroy,
}
Definition at line 3532 of file channel.c.
Referenced by apply_plc().
int shutting_down [static] |
struct ast_generator silence_generator [static] |
Initial value:
{
.alloc = silence_generator_alloc,
.release = silence_generator_release,
.generate = silence_generator_generate,
}
struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , } [static] |
struct ast_generator tonepair [static] |
Initial value:
{
alloc: tonepair_alloc,
release: tonepair_release,
generate: tonepair_generator,
}
Definition at line 5717 of file channel.c.
Referenced by ast_tonepair_start().
1.5.9