Fri Nov 12 11:57:52 2010

Asterisk developer's documentation


channel.c File Reference

Channel Management. More...

#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"
Include dependency graph for channel.c:

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  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)
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_channelast_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_channelast_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_channelast_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_datastoreast_channel_datastore_alloc (const struct ast_datastore_info *info, const char *uid)
 Create a channel data store object.
struct ast_datastoreast_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_channelast_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_generatorast_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_channelast_channel_walk_locked (const struct ast_channel *prev)
 Browse channels in use.
void ast_channels_init (void)
struct ast_variableast_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_channelast_get_channel_by_exten_locked (const char *exten, const char *context)
 Get channel by exten (and optionally context) and lock it.
struct ast_channelast_get_channel_by_name_locked (const char *name)
 Get channel by name and lock it.
struct ast_channelast_get_channel_by_name_prefix_locked (const char *name, const int namelen)
 Get channel by name prefix and lock it.
struct ast_channel_techast_get_channel_tech (const char *name)
 Get handle to channel driver based on name.
ast_group_t ast_get_group (const char *s)
int ast_hangup (struct ast_channel *chan)
 Hangup a channel.
int ast_indicate (struct ast_channel *chan, int condition)
 Indicates condition of channel.
int ast_indicate_data (struct ast_channel *chan, int _condition, const void *data, size_t datalen)
 Indicates condition of channel, with payload.
void ast_install_music_functions (int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *))
int ast_internal_timing_enabled (struct ast_channel *chan)
 Check if the channel can run in internal timing mode.
void ast_moh_cleanup (struct ast_channel *chan)
int ast_moh_start (struct ast_channel *chan, const char *mclass, const char *interpclass)
 Turn on music on hold on a given channel.
void ast_moh_stop (struct ast_channel *chan)
 Turn off music on hold on a given channel.
void ast_poll_channel_add (struct ast_channel *chan0, struct ast_channel *chan1)
void ast_poll_channel_del (struct ast_channel *chan0, struct ast_channel *chan1)
char * ast_print_group (char *buf, int buflen, ast_group_t group)
 Print call group and pickup group ---.
int ast_prod (struct ast_channel *chan)
 Send empty audio to prime a channel driver.
int ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control)
 Queue a control frame.
int ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
 Queue a control frame with payload.
int ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin)
 Queue one or more frames to a channel's frame queue.
int ast_queue_frame_head (struct ast_channel *chan, struct ast_frame *fin)
 Queue one or more frames to the head of a channel's frame queue.
int ast_queue_hangup (struct ast_channel *chan)
 Queue a hangup frame for channel.
int ast_queue_hangup_with_cause (struct ast_channel *chan, int cause)
 Queue a hangup frame for channel.
int ast_raw_answer (struct ast_channel *chan, int cdr_answer)
 Answer a channel.
struct ast_frameast_read (struct ast_channel *chan)
 Reads a frame.
static void ast_read_generator_actions (struct ast_channel *chan, struct ast_frame *f)
struct ast_frameast_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_channelast_request (const char *type, int format, void *data, int *cause)
 Requests a channel.
struct ast_channelast_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_channelast_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_channelast_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_channelast_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_channelast_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_channelchannel_find_locked (const struct ast_channel *prev, const char *name, const int namelen, const char *context, const char *exten)
 Helper function to find channels.
const char * channelreloadreason2txt (enum channelreloadreason reason)
 Convert enum channelreloadreason to text string for manager event.
static void clone_variables (struct ast_channel *original, struct ast_channel *clonechan)
 Clone channel variables from 'clone' channel into 'original' channel.
static char * complete_channeltypes (struct ast_cli_args *a)
static void free_cid (struct ast_callerid *cid)
static void free_translation (struct ast_channel *clonechan)
static int generator_force (const void *data)
static void handle_cause (int cause, int *outstate)
static char * handle_cli_core_show_channeltype (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show details about a channel driver - CLI command.
static char * handle_cli_core_show_channeltypes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show channel types - CLI command.
static int attribute_const is_visible_indication (enum ast_control_frame_type condition)
static void manager_bridge_event (int onoff, int type, struct ast_channel *c0, struct ast_channel *c1)
 Send manager event for bridge link and unlink events.
static void queue_dtmf_readq (struct ast_channel *chan, struct ast_frame *f)
static void report_new_callerid (const struct ast_channel *chan)
static void send_dtmf_event (const struct ast_channel *chan, const char *direction, const char digit, const char *begin, const char *end)
static int set_format (struct ast_channel *chan, int fmt, int *rawformat, int *format, struct ast_trans_pvt **trans, const int direction)
static int should_skip_dtmf (struct ast_channel *chan)
 Determine whether or not we should ignore DTMF in the readq.
static void * silence_generator_alloc (struct ast_channel *chan, void *data)
static int silence_generator_generate (struct ast_channel *chan, void *data, int len, int samples)
static void silence_generator_release (struct ast_channel *chan, void *data)
static void * tonepair_alloc (struct ast_channel *chan, void *params)
static int tonepair_generator (struct ast_channel *chan, void *data, int len, int samples)
static void tonepair_release (struct ast_channel *chan, void *params)
static void update_bridge_vars (struct ast_channel *c0, struct ast_channel *c1)

Variables

static void(* ast_moh_cleanup_ptr )(struct ast_channel *) = NULL
static int(* ast_moh_start_ptr )(struct ast_channel *, const char *, const char *) = NULL
static void(* ast_moh_stop_ptr )(struct ast_channel *) = NULL
struct {
   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 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

Detailed Description

Channel Management.

Author:
Mark Spencer <markster@digium.com>

Definition in file channel.c.


Define Documentation

#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

Definition at line 89 of file channel.c.

Referenced by ast_state2str().


Function Documentation

int __ast_answer ( struct ast_channel chan,
unsigned int  delay,
int  cdr_answer 
)

Answer a channel, with a selectable delay before returning.

Parameters:
chan channel to answer
delay maximum amount of time to wait for incoming media
cdr_answer flag to control whether any associated CDR should be marked as 'answered'

This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.
This function will wait up to 'delay' milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow. If 'delay' is less than 500, the function will wait up to 500 milliseconds.
Return values:
0 on success
non-zero on failure

Definition at line 1850 of file channel.c.

References ast_channel::_state, ast_channel_lock, ast_channel_unlock, AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_log(), ast_queue_frame_head(), ast_raw_answer(), ast_read(), AST_STATE_RING, AST_STATE_RINGING, ast_waitfor(), errno, ast_frame::frame_list, frames, ast_frame::frametype, LOG_WARNING, MAX, ast_channel::name, and ast_frame::subclass.

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

01851 {
01852    int res = 0;
01853    enum ast_channel_state old_state;
01854 
01855    old_state = chan->_state;
01856    if ((res = ast_raw_answer(chan, cdr_answer))) {
01857       return res;
01858    }
01859 
01860    switch (old_state) {
01861    case AST_STATE_RINGING:
01862    case AST_STATE_RING:
01863       /* wait for media to start flowing, but don't wait any longer
01864        * than 'delay' or 500 milliseconds, whichever is longer
01865        */
01866       do {
01867          AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
01868          struct ast_frame *cur, *new;
01869          int ms = MAX(delay, 500);
01870          unsigned int done = 0;
01871 
01872          AST_LIST_HEAD_INIT_NOLOCK(&frames);
01873 
01874          for (;;) {
01875             ms = ast_waitfor(chan, ms);
01876             if (ms < 0) {
01877                ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno));
01878                res = -1;
01879                break;
01880             }
01881             if (ms == 0) {
01882                ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500));
01883                break;
01884             }
01885             cur = ast_read(chan);
01886             if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
01887                     (cur->subclass == AST_CONTROL_HANGUP))) {
01888                if (cur) {
01889                   ast_frfree(cur);
01890                }
01891                res = -1;
01892                ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name);
01893                break;
01894             }
01895 
01896             if ((new = ast_frisolate(cur)) != cur) {
01897                ast_frfree(cur);
01898             }
01899 
01900             AST_LIST_INSERT_HEAD(&frames, new, frame_list);
01901 
01902             /* if a specific delay period was requested, continue
01903              * until that delay has passed. don't stop just because
01904              * incoming media has arrived.
01905              */
01906             if (delay) {
01907                continue;
01908             }
01909 
01910             switch (new->frametype) {
01911                /* all of these frametypes qualify as 'media' */
01912             case AST_FRAME_VOICE:
01913             case AST_FRAME_VIDEO:
01914             case AST_FRAME_TEXT:
01915             case AST_FRAME_DTMF_BEGIN:
01916             case AST_FRAME_DTMF_END:
01917             case AST_FRAME_IMAGE:
01918             case AST_FRAME_HTML:
01919             case AST_FRAME_MODEM:
01920                done = 1;
01921                break;
01922             case AST_FRAME_CONTROL:
01923             case AST_FRAME_IAX:
01924             case AST_FRAME_NULL:
01925             case AST_FRAME_CNG:
01926                break;
01927             }
01928 
01929             if (done) {
01930                break;
01931             }
01932          }
01933 
01934          if (res == 0) {
01935             ast_channel_lock(chan);
01936             while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
01937                ast_queue_frame_head(chan, cur);
01938                ast_frfree(cur);
01939             }
01940             ast_channel_unlock(chan);
01941          }
01942       } while (0);
01943       break;
01944    default:
01945       break;
01946    }
01947 
01948    return res;
01949 }

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.

Return values:
NULL failure
non-NULL successfully allocated channel
Note:
By default, new channels are set to the "s" extension and "default" context.

Definition at line 972 of file channel.c.

References __ast_channel_alloc_ap().

00977 {
00978    va_list ap1, ap2;
00979    struct ast_channel *result;
00980 
00981    va_start(ap1, name_fmt);
00982    va_start(ap2, name_fmt);
00983    result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
00984                amaflag, file, line, function, name_fmt, ap1, ap2);
00985    va_end(ap1);
00986    va_end(ap2);
00987 
00988    return result;
00989 }

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_LIST_HEAD_INIT_NOLOCK, ast_log(), AST_MAX_FDS, ast_mutex_init(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_state2str(), ast_strdup, ast_string_field_build, ast_string_field_build_va, ast_string_field_free_memory, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_timer_close(), ast_timer_fd(), ast_timer_open(), AST_TIMING_FD, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::datastores, defaultlanguage, errno, EVENT_FLAG_CALL, ast_channel::exten, ast_channel::fds, ast_channel::fin, chanlist::flags, ast_channel::fout, language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::name, name, null_tech, ast_channel::priority, S_OR, ast_channel::sched, sched_context_create(), sched_context_destroy(), ast_channel::streamid, ast_channel::tech, ast_channel::timer, ast_channel::timingfd, ast_channel::uniqueid, and ast_channel::varshead.

Referenced by __ast_channel_alloc(), and ast_channel_alloc().

00776 {
00777    struct ast_channel *tmp;
00778    int x;
00779    int flags;
00780    struct varshead *headp;
00781 
00782    /* If shutting down, don't allocate any new channels */
00783    if (shutting_down) {
00784       ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
00785       return NULL;
00786    }
00787 
00788 #if defined(__AST_DEBUG_MALLOC)
00789    if (!(tmp = __ast_calloc(1, sizeof(*tmp), file, line, function))) {
00790       return NULL;
00791    }
00792 #else
00793    if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
00794       return NULL;
00795    }
00796 #endif
00797 
00798    if (!(tmp->sched = sched_context_create())) {
00799       ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
00800       ast_free(tmp);
00801       return NULL;
00802    }
00803    
00804    if ((ast_string_field_init(tmp, 128))) {
00805       sched_context_destroy(tmp->sched);
00806       ast_free(tmp);
00807       return NULL;
00808    }
00809 
00810 #ifdef HAVE_EPOLL
00811    tmp->epfd = epoll_create(25);
00812 #endif
00813 
00814    for (x = 0; x < AST_MAX_FDS; x++) {
00815       tmp->fds[x] = -1;
00816 #ifdef HAVE_EPOLL
00817       tmp->epfd_data[x] = NULL;
00818 #endif
00819    }
00820 
00821    if ((tmp->timer = ast_timer_open())) {
00822       needqueue = 0;
00823       tmp->timingfd = ast_timer_fd(tmp->timer);
00824    } else {
00825       tmp->timingfd = -1;
00826    }
00827 
00828    if (needqueue) {
00829       if (pipe(tmp->alertpipe)) {
00830          ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n");
00831 alertpipe_failed:
00832          if (tmp->timer) {
00833             ast_timer_close(tmp->timer);
00834          }
00835 
00836          sched_context_destroy(tmp->sched);
00837          ast_string_field_free_memory(tmp);
00838          ast_free(tmp);
00839          return NULL;
00840       } else {
00841          flags = fcntl(tmp->alertpipe[0], F_GETFL);
00842          if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
00843             ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
00844             close(tmp->alertpipe[0]);
00845             close(tmp->alertpipe[1]);
00846             goto alertpipe_failed;
00847          }
00848          flags = fcntl(tmp->alertpipe[1], F_GETFL);
00849          if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
00850             ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
00851             close(tmp->alertpipe[0]);
00852             close(tmp->alertpipe[1]);
00853             goto alertpipe_failed;
00854          }
00855       }
00856    } else   /* Make sure we've got it done right if they don't */
00857       tmp->alertpipe[0] = tmp->alertpipe[1] = -1;
00858 
00859    /* Always watch the alertpipe */
00860    ast_channel_set_fd(tmp, AST_ALERT_FD, tmp->alertpipe[0]);
00861    /* And timing pipe */
00862    ast_channel_set_fd(tmp, AST_TIMING_FD, tmp->timingfd);
00863    ast_string_field_set(tmp, name, "**Unknown**");
00864 
00865    /* Initial state */
00866    tmp->_state = state;
00867 
00868    tmp->streamid = -1;
00869    
00870    tmp->fin = global_fin;
00871    tmp->fout = global_fout;
00872 
00873    if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
00874       ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 
00875                    ast_atomic_fetchadd_int(&uniqueint, 1));
00876    } else {
00877       ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 
00878                    (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1));
00879    }
00880 
00881    tmp->cid.cid_name = ast_strdup(cid_name);
00882    tmp->cid.cid_num = ast_strdup(cid_num);
00883    
00884    if (!ast_strlen_zero(name_fmt)) {
00885       /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
00886        * And they all use slightly different formats for their name string.
00887        * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
00888        * This means, that the stringfields must have a routine that takes the va_lists directly, and 
00889        * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
00890        * This new function was written so this can be accomplished.
00891        */
00892       ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
00893    }
00894 
00895    /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */
00896 
00897    /* These 4 variables need to be set up for the cdr_init() to work right */
00898    if (amaflag)
00899       tmp->amaflags = amaflag;
00900    else
00901       tmp->amaflags = ast_default_amaflags;
00902    
00903    if (!ast_strlen_zero(acctcode))
00904       ast_string_field_set(tmp, accountcode, acctcode);
00905    else
00906       ast_string_field_set(tmp, accountcode, ast_default_accountcode);
00907       
00908    if (!ast_strlen_zero(context))
00909       ast_copy_string(tmp->context, context, sizeof(tmp->context));
00910    else
00911       strcpy(tmp->context, "default");
00912 
00913    if (!ast_strlen_zero(exten))
00914       ast_copy_string(tmp->exten, exten, sizeof(tmp->exten));
00915    else
00916       strcpy(tmp->exten, "s");
00917 
00918    tmp->priority = 1;
00919       
00920    tmp->cdr = ast_cdr_alloc();
00921    ast_cdr_init(tmp->cdr, tmp);
00922    ast_cdr_start(tmp->cdr);
00923    
00924    headp = &tmp->varshead;
00925    AST_LIST_HEAD_INIT_NOLOCK(headp);
00926    
00927    ast_mutex_init(&tmp->lock_dont_use);
00928    
00929    AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores);
00930    
00931    ast_string_field_set(tmp, language, defaultlanguage);
00932 
00933    tmp->tech = &null_tech;
00934 
00935    ast_set_flag(tmp, AST_FLAG_IN_CHANNEL_LIST);
00936 
00937    AST_RWLIST_WRLOCK(&channels);
00938    AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list);
00939    AST_RWLIST_UNLOCK(&channels);
00940 
00941    /*\!note
00942     * and now, since the channel structure is built, and has its name, let's
00943     * call the manager event generator with this Newchannel event. This is the
00944     * proper and correct place to make this call, but you sure do have to pass
00945     * a lot of data into this func to do it here!
00946     */
00947    if (!ast_strlen_zero(name_fmt)) {
00948       manager_event(EVENT_FLAG_CALL, "Newchannel",
00949          "Channel: %s\r\n"
00950          "ChannelState: %d\r\n"
00951          "ChannelStateDesc: %s\r\n"
00952          "CallerIDNum: %s\r\n"
00953          "CallerIDName: %s\r\n"
00954          "AccountCode: %s\r\n"
00955          "Exten: %s\r\n"
00956          "Context: %s\r\n"
00957          "Uniqueid: %s\r\n",
00958          tmp->name, 
00959          state, 
00960          ast_state2str(state),
00961          S_OR(cid_num, ""),
00962          S_OR(cid_name, ""),
00963          tmp->accountcode,
00964          S_OR(exten, ""),
00965          S_OR(context, ""),
00966          tmp->uniqueid);
00967    }
00968 
00969    return tmp;
00970 }

static int __ast_queue_frame ( struct ast_channel chan,
struct ast_frame fin,
int  head,
struct ast_frame after 
) [static]

Definition at line 991 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, ast_frame::frame_list, frames, ast_frame::frametype, LOG_WARNING, ast_channel::name, ast_channel::readq, ast_frame::subclass, ast_channel::timer, and ast_channel::timingfd.

Referenced by __ast_read(), ast_queue_frame(), and ast_queue_frame_head().

00992 {
00993    struct ast_frame *f;
00994    struct ast_frame *cur;
00995    int blah = 1;
00996    unsigned int new_frames = 0;
00997    unsigned int new_voice_frames = 0;
00998    unsigned int queued_frames = 0;
00999    unsigned int queued_voice_frames = 0;
01000    AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
01001 
01002    ast_channel_lock(chan);
01003 
01004    /* See if the last frame on the queue is a hangup, if so don't queue anything */
01005    if ((cur = AST_LIST_LAST(&chan->readq)) &&
01006        (cur->frametype == AST_FRAME_CONTROL) &&
01007        (cur->subclass == AST_CONTROL_HANGUP)) {
01008       ast_channel_unlock(chan);
01009       return 0;
01010    }
01011 
01012    /* Build copies of all the frames and count them */
01013    AST_LIST_HEAD_INIT_NOLOCK(&frames);
01014    for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
01015       if (!(f = ast_frdup(cur))) {
01016          ast_frfree(AST_LIST_FIRST(&frames));
01017          ast_channel_unlock(chan);
01018          return -1;
01019       }
01020 
01021       AST_LIST_INSERT_TAIL(&frames, f, frame_list);
01022       new_frames++;
01023       if (f->frametype == AST_FRAME_VOICE) {
01024          new_voice_frames++;
01025       }
01026    }
01027 
01028    /* Count how many frames exist on the queue */
01029    AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) {
01030       queued_frames++;
01031       if (cur->frametype == AST_FRAME_VOICE) {
01032          queued_voice_frames++;
01033       }
01034    }
01035 
01036    if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) {
01037       int count = 0;
01038       ast_log(LOG_WARNING, "Exceptionally long %squeue length queuing to %s\n", queued_frames + new_frames > 128 ? "" : "voice ", chan->name);
01039       AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, cur, frame_list) {
01040          /* Save the most recent frame */
01041          if (!AST_LIST_NEXT(cur, frame_list)) {
01042             break;
01043          } else if (cur->frametype == AST_FRAME_VOICE || cur->frametype == AST_FRAME_VIDEO || cur->frametype == AST_FRAME_NULL) {
01044             if (++count > 64) {
01045                break;
01046             }
01047             AST_LIST_REMOVE_CURRENT(frame_list);
01048             ast_frfree(cur);
01049          }
01050       }
01051       AST_LIST_TRAVERSE_SAFE_END;
01052    }
01053 
01054    if (after) {
01055       AST_LIST_INSERT_LIST_AFTER(&chan->readq, &frames, after, frame_list);
01056    } else {
01057       if (head) {
01058          AST_LIST_APPEND_LIST(&frames, &chan->readq, frame_list);
01059          AST_LIST_HEAD_INIT_NOLOCK(&chan->readq);
01060       }
01061       AST_LIST_APPEND_LIST(&chan->readq, &frames, frame_list);
01062    }
01063 
01064    if (chan->alertpipe[1] > -1) {
01065       if (write(chan->alertpipe[1], &blah, new_frames * sizeof(blah)) != (new_frames * sizeof(blah))) {
01066          ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n",
01067             chan->name, queued_frames, strerror(errno));
01068       }
01069    } else if (chan->timingfd > -1) {
01070       ast_timer_enable_continuous(chan->timer);
01071    } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
01072       pthread_kill(chan->blocker, SIGURG);
01073    }
01074 
01075    ast_channel_unlock(chan);
01076 
01077    return 0;
01078 }

static struct ast_frame* __ast_read ( struct ast_channel chan,
int  dropaudio 
) [static, read]

Todo:
XXX It is possible to write a digit to the audiohook twice if the digit was originally read while the channel was in autoservice.

Definition at line 2636 of file channel.c.

References __ast_queue_frame(), ast_channel::_softhangup, ast_channel::_state, ast_channel::alertpipe, AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_write_list(), ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, ast_deactivate_generator(), ast_debug, AST_DEFAULT_EMULATE_DTMF_DURATION, ast_do_masquerade(), AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_FLAG_END_DTMF_ONLY, AST_FLAG_EXCEPTION, AST_FLAG_IN_DTMF, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_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_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, ast_frame::frame_list, FRAMECOUNT_INC, ast_frame::frametype, ast_generator::generate, ast_channel::generator, ast_channel::generatordata, ast_channel::hangupcause, ast_channel::insmpl, ast_frame::len, LOG_DTMF, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::masq, ast_channel::monitor, ast_channel::music_state, ast_channel::name, ast_channel::nativeformats, ast_channel::outsmpl, queue_dtmf_readq(), ast_channel_tech::read, ast_channel_monitor::read_stream, ast_channel::readq, ast_channel::readtrans, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), should_skip_dtmf(), ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, ast_channel::timingfunc, and ast_frame::uint32.

Referenced by ast_read(), and ast_read_noaudio().

02637 {
02638    struct ast_frame *f = NULL;   /* the return value */
02639    int blah;
02640    int prestate;
02641    int count = 0, cause = 0;
02642 
02643    /* this function is very long so make sure there is only one return
02644     * point at the end (there are only two exceptions to this).
02645     */
02646    while(ast_channel_trylock(chan)) {
02647       if(count++ > 10) 
02648          /*cannot goto done since the channel is not locked*/
02649          return &ast_null_frame;
02650       usleep(1);
02651    }
02652 
02653    if (chan->masq) {
02654       if (ast_do_masquerade(chan))
02655          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
02656       else
02657          f =  &ast_null_frame;
02658       goto done;
02659    }
02660 
02661    /* Stop if we're a zombie or need a soft hangup */
02662    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
02663       if (chan->generator)
02664          ast_deactivate_generator(chan);
02665       goto done;
02666    }
02667 
02668 #ifdef AST_DEVMODE
02669    /* 
02670     * The ast_waitfor() code records which of the channel's file descriptors reported that
02671     * data is available.  In theory, ast_read() should only be called after ast_waitfor()
02672     * reports that a channel has data available for reading.  However, there still may be
02673     * some edge cases throughout the code where ast_read() is called improperly.  This can
02674     * potentially cause problems, so if this is a developer build, make a lot of noise if
02675     * this happens so that it can be addressed. 
02676     */
02677    if (chan->fdno == -1) {
02678       ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n");
02679    }
02680 #endif
02681 
02682    prestate = chan->_state;
02683 
02684    /* Read and ignore anything on the alertpipe, but read only
02685       one sizeof(blah) per frame that we send from it */
02686    if (chan->alertpipe[0] > -1) {
02687       int flags = fcntl(chan->alertpipe[0], F_GETFL);
02688       /* For some odd reason, the alertpipe occasionally loses nonblocking status,
02689        * which immediately causes a deadlock scenario.  Detect and prevent this. */
02690       if ((flags & O_NONBLOCK) == 0) {
02691          ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", chan->name);
02692          if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
02693             ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
02694             f = &ast_null_frame;
02695             goto done;
02696          }
02697       }
02698       if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) {
02699          if (errno != EINTR && errno != EAGAIN)
02700             ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
02701       }
02702    }
02703 
02704    if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD) {
02705       enum ast_timer_event res;
02706 
02707       ast_clear_flag(chan, AST_FLAG_EXCEPTION);
02708 
02709       res = ast_timer_get_event(chan->timer);
02710 
02711       switch (res) {
02712       case AST_TIMING_EVENT_EXPIRED:
02713          ast_timer_ack(chan->timer, 1);
02714 
02715          if (chan->timingfunc) {
02716             /* save a copy of func/data before unlocking the channel */
02717             int (*func)(const void *) = chan->timingfunc;
02718             void *data = chan->timingdata;
02719             chan->fdno = -1;
02720             ast_channel_unlock(chan);
02721             func(data);
02722          } else {
02723             ast_timer_set_rate(chan->timer, 0);
02724             chan->fdno = -1;
02725             ast_channel_unlock(chan);
02726          }
02727 
02728          /* cannot 'goto done' because the channel is already unlocked */
02729          return &ast_null_frame;
02730 
02731       case AST_TIMING_EVENT_CONTINUOUS:
02732          if (AST_LIST_EMPTY(&chan->readq) || 
02733             !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) {
02734             ast_timer_disable_continuous(chan->timer);
02735          }
02736          break;
02737       }
02738 
02739    } else if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) {
02740       /* if the AST_GENERATOR_FD is set, call the generator with args
02741        * set to -1 so it can do whatever it needs to.
02742        */
02743       void *tmp = chan->generatordata;
02744       chan->generatordata = NULL;     /* reset to let ast_write get through */
02745       chan->generator->generate(chan, tmp, -1, -1);
02746       chan->generatordata = tmp;
02747       f = &ast_null_frame;
02748       chan->fdno = -1;
02749       goto done;
02750    }
02751 
02752    /* Check for pending read queue */
02753    if (!AST_LIST_EMPTY(&chan->readq)) {
02754       int skip_dtmf = should_skip_dtmf(chan);
02755 
02756       AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, f, frame_list) {
02757          /* We have to be picky about which frame we pull off of the readq because
02758           * there are cases where we want to leave DTMF frames on the queue until
02759           * some later time. */
02760 
02761          if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) {
02762             continue;
02763          }
02764 
02765          AST_LIST_REMOVE_CURRENT(frame_list);
02766          break;
02767       }
02768       AST_LIST_TRAVERSE_SAFE_END;
02769       
02770       if (!f) {
02771          /* There were no acceptable frames on the readq. */
02772          f = &ast_null_frame;
02773          if (chan->alertpipe[0] > -1) {
02774             int poke = 0;
02775             /* Restore the state of the alertpipe since we aren't ready for any
02776              * of the frames in the readq. */
02777             if (write(chan->alertpipe[1], &poke, sizeof(poke)) != sizeof(poke)) {
02778                ast_log(LOG_ERROR, "Failed to write to alertpipe: %s\n", strerror(errno));
02779             }
02780          }
02781       }
02782 
02783       /* Interpret hangup and return NULL */
02784       /* XXX why not the same for frames from the channel ? */
02785       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) {
02786          cause = f->data.uint32;
02787          ast_frfree(f);
02788          f = NULL;
02789       }
02790    } else {
02791       chan->blocker = pthread_self();
02792       if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
02793          if (chan->tech->exception)
02794             f = chan->tech->exception(chan);
02795          else {
02796             ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name);
02797             f = &ast_null_frame;
02798          }
02799          /* Clear the exception flag */
02800          ast_clear_flag(chan, AST_FLAG_EXCEPTION);
02801       } else if (chan->tech->read)
02802          f = chan->tech->read(chan);
02803       else
02804          ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name);
02805    }
02806 
02807    /*
02808     * Reset the recorded file descriptor that triggered this read so that we can
02809     * easily detect when ast_read() is called without properly using ast_waitfor().
02810     */
02811    chan->fdno = -1;
02812 
02813    if (f) {
02814       struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq);
02815 
02816       /* if the channel driver returned more than one frame, stuff the excess
02817          into the readq for the next ast_read call
02818       */
02819       if (AST_LIST_NEXT(f, frame_list)) {
02820          ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list));
02821          ast_frfree(AST_LIST_NEXT(f, frame_list));
02822          AST_LIST_NEXT(f, frame_list) = NULL;
02823       }
02824 
02825       switch (f->frametype) {
02826       case AST_FRAME_CONTROL:
02827          if (f->subclass == AST_CONTROL_ANSWER) {
02828             if (!ast_test_flag(chan, AST_FLAG_OUTGOING)) {
02829                ast_debug(1, "Ignoring answer on an inbound call!\n");
02830                ast_frfree(f);
02831                f = &ast_null_frame;
02832             } else if (prestate == AST_STATE_UP) {
02833                ast_debug(1, "Dropping duplicate answer!\n");
02834                ast_frfree(f);
02835                f = &ast_null_frame;
02836             } else {
02837                /* Answer the CDR */
02838                ast_setstate(chan, AST_STATE_UP);
02839                /* removed a call to ast_cdr_answer(chan->cdr) from here. */
02840             }
02841          }
02842          break;
02843       case AST_FRAME_DTMF_END:
02844          send_dtmf_event(chan, "Received", f->subclass, "No", "Yes");
02845          ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass, chan->name, f->len);
02846          /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
02847          if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) || ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) {
02848             queue_dtmf_readq(chan, f);
02849             ast_frfree(f);
02850             f = &ast_null_frame;
02851          } else if (!ast_test_flag(chan, AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) {
02852             if (!ast_tvzero(chan->dtmf_tv) && 
02853                 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) {
02854                /* If it hasn't been long enough, defer this digit */
02855                queue_dtmf_readq(chan, f);
02856                ast_frfree(f);
02857                f = &ast_null_frame;
02858             } else {
02859                /* There was no begin, turn this into a begin and send the end later */
02860                f->frametype = AST_FRAME_DTMF_BEGIN;
02861                ast_set_flag(chan, AST_FLAG_EMULATE_DTMF);
02862                chan->emulate_dtmf_digit = f->subclass;
02863                chan->dtmf_tv = ast_tvnow();
02864                if (f->len) {
02865                   if (f->len > AST_MIN_DTMF_DURATION)
02866                      chan->emulate_dtmf_duration = f->len;
02867                   else 
02868                      chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION;
02869                } else
02870                   chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION;
02871                ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass, chan->emulate_dtmf_duration, chan->name);
02872             }
02873             if (chan->audiohooks) {
02874                struct ast_frame *old_frame = f;
02875                /*!
02876                 * \todo XXX It is possible to write a digit to the audiohook twice
02877                 * if the digit was originally read while the channel was in autoservice. */
02878                f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02879                if (old_frame != f)
02880                   ast_frfree(old_frame);
02881             }
02882          } else {
02883             struct timeval now = ast_tvnow();
02884             if (ast_test_flag(chan, AST_FLAG_IN_DTMF)) {
02885                ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass, chan->name);
02886                ast_clear_flag(chan, AST_FLAG_IN_DTMF);
02887                if (!f->len)
02888                   f->len = ast_tvdiff_ms(now, chan->dtmf_tv);
02889             } else if (!f->len) {
02890                ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass, chan->name);
02891                f->len = AST_MIN_DTMF_DURATION;
02892             }
02893             if (f->len < AST_MIN_DTMF_DURATION && !ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) {
02894                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);
02895                ast_set_flag(chan, AST_FLAG_EMULATE_DTMF);
02896                chan->emulate_dtmf_digit = f->subclass;
02897                chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION - f->len;
02898                ast_frfree(f);
02899                f = &ast_null_frame;
02900             } else {
02901                ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass, chan->name);
02902                if (f->len < AST_MIN_DTMF_DURATION) {
02903                   f->len = AST_MIN_DTMF_DURATION;
02904                }
02905                chan->dtmf_tv = now;
02906             }
02907             if (chan->audiohooks) {
02908                struct ast_frame *old_frame = f;
02909                f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02910                if (old_frame != f)
02911                   ast_frfree(old_frame);
02912             }
02913          }
02914          break;
02915       case AST_FRAME_DTMF_BEGIN:
02916          send_dtmf_event(chan, "Received", f->subclass, "Yes", "No");
02917          ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass, chan->name);
02918          if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) || 
02919              (!ast_tvzero(chan->dtmf_tv) && 
02920                ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) ) {
02921             ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass, chan->name);
02922             ast_frfree(f);
02923             f = &ast_null_frame;
02924          } else {
02925             ast_set_flag(chan, AST_FLAG_IN_DTMF);
02926             chan->dtmf_tv = ast_tvnow();
02927             ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass, chan->name);
02928          }
02929          break;
02930       case AST_FRAME_NULL:
02931          /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
02932           * is reached , because we want to make sure we pass at least one
02933           * voice frame through before starting the next digit, to ensure a gap
02934           * between DTMF digits. */
02935          if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) {
02936             struct timeval now = ast_tvnow();
02937             if (!chan->emulate_dtmf_duration) {
02938                ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF);
02939                chan->emulate_dtmf_digit = 0;
02940             } else if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) {
02941                chan->emulate_dtmf_duration = 0;
02942                ast_frfree(f);
02943                f = &chan->dtmff;
02944                f->frametype = AST_FRAME_DTMF_END;
02945                f->subclass = chan->emulate_dtmf_digit;
02946                f->len = ast_tvdiff_ms(now, chan->dtmf_tv);
02947                chan->dtmf_tv = now;
02948                ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF);
02949                chan->emulate_dtmf_digit = 0;
02950                ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name);
02951                if (chan->audiohooks) {
02952                   struct ast_frame *old_frame = f;
02953                   f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02954                   if (old_frame != f) {
02955                      ast_frfree(old_frame);
02956                   }
02957                }
02958             }
02959          }
02960          break;
02961       case AST_FRAME_VOICE:
02962          /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
02963           * is reached , because we want to make sure we pass at least one
02964           * voice frame through before starting the next digit, to ensure a gap
02965           * between DTMF digits. */
02966          if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !chan->emulate_dtmf_duration) {
02967             ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF);
02968             chan->emulate_dtmf_digit = 0;
02969          }
02970 
02971          if (dropaudio || ast_test_flag(chan, AST_FLAG_IN_DTMF)) {
02972             if (dropaudio)
02973                ast_read_generator_actions(chan, f);
02974             ast_frfree(f);
02975             f = &ast_null_frame;
02976          }
02977 
02978          if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !ast_test_flag(chan, AST_FLAG_IN_DTMF)) {
02979             struct timeval now = ast_tvnow();
02980             if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) {
02981                chan->emulate_dtmf_duration = 0;
02982                ast_frfree(f);
02983                f = &chan->dtmff;
02984                f->frametype = AST_FRAME_DTMF_END;
02985                f->subclass = chan->emulate_dtmf_digit;
02986                f->len = ast_tvdiff_ms(now, chan->dtmf_tv);
02987                chan->dtmf_tv = now;
02988                if (chan->audiohooks) {
02989                   struct ast_frame *old_frame = f;
02990                   f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02991                   if (old_frame != f)
02992                      ast_frfree(old_frame);
02993                }
02994                ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name);
02995             } else {
02996                /* Drop voice frames while we're still in the middle of the digit */
02997                ast_frfree(f);
02998                f = &ast_null_frame;
02999             }
03000          } else if ((f->frametype == AST_FRAME_VOICE) && !(f->subclass & chan->nativeformats)) {
03001             /* This frame is not one of the current native formats -- drop it on the floor */
03002             char to[200];
03003             ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n",
03004                chan->name, ast_getformatname(f->subclass), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats));
03005             ast_frfree(f);
03006             f = &ast_null_frame;
03007          } else if ((f->frametype == AST_FRAME_VOICE)) {
03008             /* Send frame to audiohooks if present */
03009             if (chan->audiohooks) {
03010                struct ast_frame *old_frame = f;
03011                f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
03012                if (old_frame != f)
03013                   ast_frfree(old_frame);
03014             }
03015             if (chan->monitor && chan->monitor->read_stream ) {
03016                /* XXX what does this do ? */
03017 #ifndef MONITOR_CONSTANT_DELAY
03018                int jump = chan->outsmpl - chan->insmpl - 4 * f->samples;
03019                if (jump >= 0) {
03020                   jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format));
03021                   if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1)
03022                      ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
03023                   chan->insmpl += (chan->outsmpl - chan->insmpl) + f->samples;
03024                } else
03025                   chan->insmpl+= f->samples;
03026 #else
03027                int jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format));
03028                if (jump - MONITOR_DELAY >= 0) {
03029                   if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1)
03030                      ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
03031                   chan->insmpl += chan->outsmpl - chan->insmpl;
03032                } else
03033                   chan->insmpl += f->samples;
03034 #endif
03035                if (chan->monitor->state == AST_MONITOR_RUNNING) {
03036                   if (ast_writestream(chan->monitor->read_stream, f) < 0)
03037                      ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n");
03038                }
03039             }
03040 
03041             if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) {
03042                f = &ast_null_frame;
03043             }
03044 
03045             /* it is possible for the translation process on chan->readtrans to have
03046                produced multiple frames from the single input frame we passed it; if
03047                this happens, queue the additional frames *before* the frames we may
03048                have queued earlier. if the readq was empty, put them at the head of
03049                the queue, and if it was not, put them just after the frame that was
03050                at the end of the queue.
03051             */
03052             if (AST_LIST_NEXT(f, frame_list)) {
03053                if (!readq_tail) {
03054                   ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list));
03055                } else {
03056                   __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail);
03057                }
03058                ast_frfree(AST_LIST_NEXT(f, frame_list));
03059                AST_LIST_NEXT(f, frame_list) = NULL;
03060             }
03061 
03062             /* Run generator sitting on the line if timing device not available
03063             * and synchronous generation of outgoing frames is necessary       */
03064             ast_read_generator_actions(chan, f);
03065          }
03066       default:
03067          /* Just pass it on! */
03068          break;
03069       }
03070    } else {
03071       /* Make sure we always return NULL in the future */
03072       chan->_softhangup |= AST_SOFTHANGUP_DEV;
03073       if (cause)
03074          chan->hangupcause = cause;
03075       if (chan->generator)
03076          ast_deactivate_generator(chan);
03077       /* We no longer End the CDR here */
03078    }
03079 
03080    /* High bit prints debugging */
03081    if (chan->fin & DEBUGCHAN_FLAG)
03082       ast_frame_dump(chan->name, f, "<<");
03083    chan->fin = FRAMECOUNT_INC(chan->fin);
03084 
03085 done:
03086    if (chan->music_state && chan->generator && chan->generator->digit && f && f->frametype == AST_FRAME_DTMF_END)
03087       chan->generator->digit(chan, f->subclass);
03088 
03089    ast_channel_unlock(chan);
03090    return f;
03091 }

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.

Parameters:
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
Returns:
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 3851 of file channel.c.

References ast_channel::_state, outgoing_helper::account, ast_call(), ast_call_forward(), AST_CAUSE_NO_ANSWER, ast_cdr_alloc(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), AST_CDR_FLAG_ORIGINATED, ast_cdr_init(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_copy_string(), AST_FRAME_CONTROL, ast_frfree, ast_hangup(), ast_log(), ast_read(), ast_request(), ast_set_callerid(), ast_set_flag, ast_set_variables(), AST_STATE_UP, ast_strlen_zero(), ast_waitfor(), ast_channel::call_forward, 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().

03852 {
03853    int dummy_outstate;
03854    int cause = 0;
03855    struct ast_channel *chan;
03856    int res = 0;
03857    int last_subclass = 0;
03858    
03859    if (outstate)
03860       *outstate = 0;
03861    else
03862       outstate = &dummy_outstate;   /* make outstate always a valid pointer */
03863 
03864    chan = ast_request(type, format, data, &cause);
03865    if (!chan) {
03866       ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
03867       handle_cause(cause, outstate);
03868       return NULL;
03869    }
03870 
03871    if (oh) {
03872       if (oh->vars)  
03873          ast_set_variables(chan, oh->vars);
03874       /* XXX why is this necessary, for the parent_channel perhaps ? */
03875       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name))
03876          ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
03877       if (oh->parent_channel) {
03878          ast_channel_inherit_variables(oh->parent_channel, chan);
03879          ast_channel_datastore_inherit(oh->parent_channel, chan);
03880       }
03881       if (oh->account)
03882          ast_cdr_setaccount(chan, oh->account); 
03883    }
03884    ast_set_callerid(chan, cid_num, cid_name, cid_num);
03885    ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED);
03886 
03887    if (ast_call(chan, data, 0)) {   /* ast_call failed... */
03888       ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
03889    } else {
03890       res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
03891       while (timeout && chan->_state != AST_STATE_UP) {
03892          struct ast_frame *f;
03893          res = ast_waitfor(chan, timeout);
03894          if (res == 0) { /* timeout, treat it like ringing */
03895             *outstate = AST_CONTROL_RINGING;
03896             break;
03897          }
03898          if (res < 0) /* error or done */
03899             break;
03900          if (timeout > -1)
03901             timeout = res;
03902          if (!ast_strlen_zero(chan->call_forward)) {
03903             if (!(chan = ast_call_forward(NULL, chan, &timeout, format, oh, outstate))) {
03904                return NULL;
03905             }
03906             continue;
03907          }
03908 
03909          f = ast_read(chan);
03910          if (!f) {
03911             *outstate = AST_CONTROL_HANGUP;
03912             res = 0;
03913             break;
03914          }
03915          if (f->frametype == AST_FRAME_CONTROL) {
03916             switch (f->subclass) {
03917             case AST_CONTROL_RINGING:  /* record but keep going */
03918                *outstate = f->subclass;
03919                break;
03920 
03921             case AST_CONTROL_BUSY:
03922             case AST_CONTROL_CONGESTION:
03923             case AST_CONTROL_ANSWER:
03924                *outstate = f->subclass;
03925                timeout = 0;      /* trick to force exit from the while() */
03926                break;
03927 
03928             /* Ignore these */
03929             case AST_CONTROL_PROGRESS:
03930             case AST_CONTROL_PROCEEDING:
03931             case AST_CONTROL_HOLD:
03932             case AST_CONTROL_UNHOLD:
03933             case AST_CONTROL_VIDUPDATE:
03934             case AST_CONTROL_SRCUPDATE:
03935             case -1:       /* Ignore -- just stopping indications */
03936                break;
03937 
03938             default:
03939                ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass);
03940             }
03941             last_subclass = f->subclass;
03942          }
03943          ast_frfree(f);
03944       }
03945    }
03946 
03947    /* Final fixups */
03948    if (oh) {
03949       if (!ast_strlen_zero(oh->context))
03950          ast_copy_string(chan->context, oh->context, sizeof(chan->context));
03951       if (!ast_strlen_zero(oh->exten))
03952          ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
03953       if (oh->priority) 
03954          chan->priority = oh->priority;
03955    }
03956    if (chan->_state == AST_STATE_UP)
03957       *outstate = AST_CONTROL_ANSWER;
03958 
03959    if (res <= 0) {
03960       if ( AST_CONTROL_RINGING == last_subclass ) 
03961          chan->hangupcause = AST_CAUSE_NO_ANSWER;
03962       if (!chan->cdr && (chan->cdr = ast_cdr_alloc()))
03963          ast_cdr_init(chan->cdr, chan);
03964       if (chan->cdr) {
03965          char tmp[256];
03966          snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data);
03967          ast_cdr_setapp(chan->cdr,"Dial",tmp);
03968          ast_cdr_update(chan);
03969          ast_cdr_start(chan->cdr);
03970          ast_cdr_end(chan->cdr);
03971          /* If the cause wasn't handled properly */
03972          if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
03973             ast_cdr_failed(chan->cdr);
03974       }
03975       ast_hangup(chan);
03976       chan = NULL;
03977    }
03978    return chan;
03979 }

static void __init_state2str_threadbuf ( void   )  [static]

Definition at line 88 of file channel.c.

00103 {

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

Activate a given generator

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

02002 {
02003    int res = 0;
02004 
02005    ast_channel_lock(chan);
02006 
02007    if (chan->generatordata) {
02008       if (chan->generator && chan->generator->release)
02009          chan->generator->release(chan, chan->generatordata);
02010       chan->generatordata = NULL;
02011    }
02012 
02013    ast_prod(chan);
02014    if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) {
02015       res = -1;
02016    }
02017    
02018    if (!res) {
02019       ast_settimeout(chan, 50, generator_force, chan);
02020       chan->generator = gen;
02021    }
02022 
02023    ast_channel_unlock(chan);
02024 
02025    return res;
02026 }

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.

Parameters:
chan channel to answer

This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.
This function will wait up to 500 milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow.
Return values:
0 on success
non-zero on failure

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

01952 {
01953    return __ast_answer(chan, 0, 1);
01954 }

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]
int ast_call ( struct ast_channel chan,
char *  addr,
int  timeout 
)

Make a call.

Parameters:
chan which channel to make the call on
addr destination of the call
timeout time to wait on for connect Place a call, take no longer than timeout ms.
Returns:
Returns -1 on failure, 0 on not enough time (does not automatically stop ringing), and the number of seconds the connect took otherwise.

Definition at line 4042 of file channel.c.

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

04043 {
04044    /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
04045       If the remote end does not answer within the timeout, then do NOT hang up, but
04046       return anyway.  */
04047    int res = -1;
04048    /* Stop if we're a zombie or need a soft hangup */
04049    ast_channel_lock(chan);
04050    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
04051       if (chan->cdr) {
04052          ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED);
04053          ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED);
04054       }
04055       if (chan->tech->call)
04056          res = chan->tech->call(chan, addr, timeout);
04057       ast_set_flag(chan, AST_FLAG_OUTGOING);
04058    }
04059    ast_channel_unlock(chan);
04060    return res;
04061 }

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.

Parameters:
caller in channel that requested orig
orig channel being replaced by the call forward channel
timeout maximum amount of time to wait for setup of new forward channel
format requested channel format
oh outgoing helper used with original channel
outstate reason why unsuccessful (if uncuccessful)
Returns:
Returns the forwarded call's ast_channel on success or NULL on failure

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

03780 {
03781    char tmpchan[256];
03782    struct ast_channel *new = NULL;
03783    char *data, *type;
03784    int cause = 0;
03785 
03786    /* gather data and request the new forward channel */
03787    ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan));
03788    if ((data = strchr(tmpchan, '/'))) {
03789       *data++ = '\0';
03790       type = tmpchan;
03791    } else {
03792       const char *forward_context;
03793       ast_channel_lock(orig);
03794       forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
03795       snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context));
03796       ast_channel_unlock(orig);
03797       data = tmpchan;
03798       type = "Local";
03799    }
03800    if (!(new = ast_request(type, format, data, &cause))) {
03801       ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
03802       handle_cause(cause, outstate);
03803       ast_hangup(orig);
03804       return NULL;
03805    }
03806 
03807    /* Copy/inherit important information into new channel */
03808    if (oh) {
03809       if (oh->vars) {
03810          ast_set_variables(new, oh->vars);
03811       }
03812       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
03813          ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num);
03814       }
03815       if (oh->parent_channel) {
03816          ast_channel_inherit_variables(oh->parent_channel, new);
03817          ast_channel_datastore_inherit(oh->parent_channel, new);
03818       }
03819       if (oh->account) {
03820          ast_cdr_setaccount(new, oh->account);
03821       }
03822    } else if (caller) { /* no outgoing helper so use caller if avaliable */
03823       ast_channel_inherit_variables(caller, new);
03824       ast_channel_datastore_inherit(caller, new);
03825    }
03826 
03827    ast_channel_lock(orig);
03828    while (ast_channel_trylock(new)) {
03829       CHANNEL_DEADLOCK_AVOIDANCE(orig);
03830    }
03831    ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED);
03832    ast_string_field_set(new, accountcode, orig->accountcode);
03833    if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) {
03834       ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num);
03835    }
03836    ast_channel_unlock(new);
03837    ast_channel_unlock(orig);
03838 
03839    /* call new channel */
03840    if ((*timeout = ast_call(new, data, 0))) {
03841       ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
03842       ast_hangup(orig);
03843       ast_hangup(new);
03844       return NULL;
03845    }
03846    ast_hangup(orig);
03847 
03848    return new;
03849 }

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

Parameters:
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.

Note:
The channel must be locked before calling this function.

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

04297 {
04298    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid);
04299    ast_string_field_set(chan, name, newname);
04300 }

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

References __ast_channel_alloc_ap().

05880 {
05881    va_list ap1, ap2;
05882    struct ast_channel *result;
05883 
05884 
05885    va_start(ap1, name_fmt);
05886    va_start(ap2, name_fmt);
05887    result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
05888                amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap1, ap2);
05889    va_end(ap1);
05890    va_end(ap2);
05891 
05892    return result;
05893 }

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

Parameters:
c0 first channel to bridge
c1 second channel to bridge
config config for the channels
fo destination frame(?)
rc destination channel(?) Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in rf (remember, it could be NULL) and which channel (0 or 1) in rc

Definition at line 5055 of file channel.c.

References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_make_compatible(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCUPDATE, ast_debug, AST_FEATURE_PLAY_WARNING, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_generic_bridge(), ast_indicate(), ast_log(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_verb, ast_channel::audiohooks, ast_channel_tech::bridge, bridge_play_sounds(), bridge_playfile(), ast_channel::cid, ast_callerid::cid_num, ast_bridge_config::end_sound, EVENT_FLAG_CALL, ast_bridge_config::feature_timer, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::firstpass, ast_bridge_config::flags, ast_channel::generator, LOG_WARNING, manager_bridge_event(), manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_bridge_config::play_warning, ast_channel::readformat, ast_channel_tech::send_digit_begin, ast_bridge_config::start_sound, ast_bridge_config::start_time, ast_channel::tech, ast_bridge_config::timelimit, ast_channel::uniqueid, update_bridge_vars(), ast_bridge_config::warning_freq, ast_bridge_config::warning_sound, and ast_channel::writeformat.

Referenced by ast_bridge_call().

05057 {
05058    struct ast_channel *who = NULL;
05059    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
05060    int nativefailed=0;
05061    int firstpass;
05062    int o0nativeformats;
05063    int o1nativeformats;
05064    long time_left_ms=0;
05065    char caller_warning = 0;
05066    char callee_warning = 0;
05067 
05068    if (c0->_bridge) {
05069       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
05070          c0->name, c0->_bridge->name);
05071       return -1;
05072    }
05073    if (c1->_bridge) {
05074       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
05075          c1->name, c1->_bridge->name);
05076       return -1;
05077    }
05078    
05079    /* Stop if we're a zombie or need a soft hangup */
05080    if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
05081        ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
05082       return -1;
05083 
05084    *fo = NULL;
05085    firstpass = config->firstpass;
05086    config->firstpass = 0;
05087 
05088    if (ast_tvzero(config->start_time))
05089       config->start_time = ast_tvnow();
05090    time_left_ms = config->timelimit;
05091 
05092    caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
05093    callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
05094 
05095    if (config->start_sound && firstpass) {
05096       if (caller_warning)
05097          bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000);
05098       if (callee_warning)
05099          bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000);
05100    }
05101 
05102    /* Keep track of bridge */
05103    c0->_bridge = c1;
05104    c1->_bridge = c0;
05105 
05106 
05107    o0nativeformats = c0->nativeformats;
05108    o1nativeformats = c1->nativeformats;
05109 
05110    if (config->feature_timer && !ast_tvzero(config->nexteventts)) {
05111       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000));
05112    } else if (config->timelimit && firstpass) {
05113       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
05114       if (caller_warning || callee_warning)
05115          config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000));
05116    }
05117 
05118    if (!c0->tech->send_digit_begin)
05119       ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY);
05120    if (!c1->tech->send_digit_begin)
05121       ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY);
05122    manager_bridge_event(1, 1, c0, c1);
05123 
05124    /* Before we enter in and bridge these two together tell them both the source of audio has changed */
05125    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
05126    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
05127 
05128    for (/* ever */;;) {
05129       struct timeval now = { 0, };
05130       int to;
05131 
05132       to = -1;
05133 
05134       if (!ast_tvzero(config->nexteventts)) {
05135          now = ast_tvnow();
05136          to = ast_tvdiff_ms(config->nexteventts, now);
05137          if (to <= 0) {
05138             if (!config->timelimit) {
05139                res = AST_BRIDGE_COMPLETE;
05140                break;
05141             }
05142             to = 0;
05143          }
05144       }
05145 
05146       if (config->timelimit) {
05147          time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
05148          if (time_left_ms < to)
05149             to = time_left_ms;
05150 
05151          if (time_left_ms <= 0) {
05152             if (caller_warning && config->end_sound)
05153                bridge_playfile(c0, c1, config->end_sound, 0);
05154             if (callee_warning && config->end_sound)
05155                bridge_playfile(c1, c0, config->end_sound, 0);
05156             *fo = NULL;
05157             if (who)
05158                *rc = who;
05159             res = 0;
05160             break;
05161          }
05162 
05163          if (!to) {
05164             if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) {
05165                int t = (time_left_ms + 500) / 1000; /* round to nearest second */
05166                if (caller_warning)
05167                   bridge_playfile(c0, c1, config->warning_sound, t);
05168                if (callee_warning)
05169                   bridge_playfile(c1, c0, config->warning_sound, t);
05170             }
05171             if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000)))
05172                config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000));
05173             else
05174                config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
05175          }
05176          ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
05177       }
05178 
05179       if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
05180          if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
05181             c0->_softhangup = 0;
05182          if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
05183             c1->_softhangup = 0;
05184          c0->_bridge = c1;
05185          c1->_bridge = c0;
05186          ast_debug(1, "Unbridge signal received. Ending native bridge.\n");
05187          continue;
05188       }
05189 
05190       /* Stop if we're a zombie or need a soft hangup */
05191       if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
05192           ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
05193          *fo = NULL;
05194          if (who)
05195             *rc = who;
05196          res = 0;
05197          ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",
05198             c0->name, c1->name,
05199             ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No",
05200             ast_check_hangup(c0) ? "Yes" : "No",
05201             ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No",
05202             ast_check_hangup(c1) ? "Yes" : "No");
05203          break;
05204       }
05205 
05206       update_bridge_vars(c0, c1);
05207 
05208       bridge_play_sounds(c0, c1);
05209 
05210       if (c0->tech->bridge &&
05211           (c0->tech->bridge == c1->tech->bridge) &&
05212           !nativefailed && !c0->monitor && !c1->monitor &&
05213           !c0->audiohooks && !c1->audiohooks && 
05214           !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) {
05215          /* Looks like they share a bridge method and nothing else is in the way */
05216          ast_set_flag(c0, AST_FLAG_NBRIDGE);
05217          ast_set_flag(c1, AST_FLAG_NBRIDGE);
05218          if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, to)) == AST_BRIDGE_COMPLETE) {
05219             /* \todo  XXX here should check that cid_num is not NULL */
05220             manager_event(EVENT_FLAG_CALL, "Unlink",
05221                      "Channel1: %s\r\n"
05222                      "Channel2: %s\r\n"
05223                      "Uniqueid1: %s\r\n"
05224                      "Uniqueid2: %s\r\n"
05225                      "CallerID1: %s\r\n"
05226                      "CallerID2: %s\r\n",
05227                      c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
05228             ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name);
05229 
05230             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
05231             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
05232 
05233             if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
05234                continue;
05235 
05236             c0->_bridge = NULL;
05237             c1->_bridge = NULL;
05238 
05239             return res;
05240          } else {
05241             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
05242             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
05243          }
05244          switch (res) {
05245          case AST_BRIDGE_RETRY:
05246             if (config->play_warning) {
05247                ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
05248             }
05249             continue;
05250          default:
05251             ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name);
05252             /* fallthrough */
05253          case AST_BRIDGE_FAILED_NOWARN:
05254             nativefailed++;
05255             break;
05256          }
05257       }
05258 
05259       if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
05260           (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
05261           !(c0->generator || c1->generator)) {
05262          if (ast_channel_make_compatible(c0, c1)) {
05263             ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
05264             manager_bridge_event(0, 1, c0, c1);
05265             return AST_BRIDGE_FAILED;
05266          }
05267          o0nativeformats = c0->nativeformats;
05268          o1nativeformats = c1->nativeformats;
05269       }
05270 
05271       update_bridge_vars(c0, c1);
05272 
05273       res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts);
05274       if (res != AST_BRIDGE_RETRY) {
05275          break;
05276       } else if (config->feature_timer) {
05277          /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */
05278          break;
05279       }
05280    }
05281 
05282    ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY);
05283    ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY);
05284 
05285    /* Now that we have broken the bridge the source will change yet again */
05286    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
05287    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
05288 
05289    c0->_bridge = NULL;
05290    c1->_bridge = NULL;
05291 
05292    /* \todo  XXX here should check that cid_num is not NULL */
05293    manager_event(EVENT_FLAG_CALL, "Unlink",
05294             "Channel1: %s\r\n"
05295             "Channel2: %s\r\n"
05296             "Uniqueid1: %s\r\n"
05297             "Uniqueid2: %s\r\n"
05298             "CallerID1: %s\r\n"
05299             "CallerID2: %s\r\n",
05300             c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
05301    ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
05302 
05303    return res;
05304 }

int ast_channel_cmpwhentohangup ( struct ast_channel chan,
time_t  offset 
)

Compare a offset with the settings of when to hang a channel up.

Parameters:
chan channel on which to check for hang up
offset offset in seconds from current time
Returns:
1, 0, or -1 This function compares a offset from current time with the absolute time out on a channel (when to hang up). If the absolute time out on a channel is earlier than current time plus the offset, it returns 1, if the two time values are equal, it return 0, otherwise, it return -1.
See also:
ast_channel_cmpwhentohangup_tv()
Version:
1.6.1 deprecated function (only had seconds precision)

Definition at line 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 
)
struct ast_datastore* ast_channel_datastore_alloc ( const struct ast_datastore_info info,
const char *  uid 
) [read]

Create a channel data store object.

Note:
None of the datastore API calls lock the ast_channel they are using. So, the channel should be locked before calling the functions that take a channel argument.
Deprecated:
You should use the ast_datastore_alloc() generic function instead.
Version:
1.6.1 deprecated

Definition at line 1507 of file channel.c.

References ast_datastore_alloc.

01508 {
01509    return ast_datastore_alloc(info, uid);
01510 }

struct ast_datastore* ast_channel_datastore_find ( struct ast_channel chan,
const struct ast_datastore_info info,
const char *  uid 
) [read]

Find a datastore on a channel.

Note:
The channel should be locked before calling this function.
The datastore returned from this function must not be used if the reference to the channel is released.
Return values:
pointer to the datastore if found
NULL if not found

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

01549 {
01550    struct ast_datastore *datastore = NULL;
01551    
01552    if (info == NULL)
01553       return NULL;
01554 
01555    AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) {
01556       if (datastore->info != info) {
01557          continue;
01558       }
01559 
01560       if (uid == NULL) {
01561          /* matched by type only */
01562          break;
01563       }
01564 
01565       if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
01566          /* Matched by type AND uid */
01567          break;
01568       }
01569    }
01570    AST_LIST_TRAVERSE_SAFE_END;
01571 
01572    return datastore;
01573 }

int ast_channel_datastore_free ( struct ast_datastore datastore  ) 

Free a channel data store object.

Deprecated:
You should use the ast_datastore_free() generic function instead.
Version:
1.6.1 deprecated

Definition at line 1512 of file channel.c.

References ast_datastore_free().

01513 {
01514    return ast_datastore_free(datastore);
01515 }

int ast_channel_datastore_inherit ( struct ast_channel from,
struct ast_channel to 
)

Inherit datastores from a parent to a child.

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

01518 {
01519    struct ast_datastore *datastore = NULL, *datastore2;
01520 
01521    AST_LIST_TRAVERSE(&from->datastores, datastore, entry) {
01522       if (datastore->inheritance > 0) {
01523          datastore2 = ast_datastore_alloc(datastore->info, datastore->uid);
01524          if (datastore2) {
01525             datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
01526             datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
01527             AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry);
01528          }
01529       }
01530    }
01531    return 0;
01532 }

int ast_channel_datastore_remove ( struct ast_channel chan,
struct ast_datastore datastore 
)

Remove a datastore from a channel.

Note:
The channel should be locked before calling this function.
Return values:
0 success
non-zero failure

Definition at line 1543 of file channel.c.

References AST_LIST_REMOVE, and ast_channel::datastores.

Referenced by acf_fetch(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), exec_odbcfinish(), lua_get_state(), queue_transfer_fixup(), speech_background(), speech_destroy(), speex_write(), stop_mixmonitor_exec(), and try_calling().

01544 {
01545    return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1;
01546 }

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

References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.

Referenced by __adsi_transmit_messages(), and find_cache().

01147 {
01148    int pre = 0;
01149 
01150    if (chan) {
01151       pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
01152       ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
01153    }
01154    return pre;
01155 }

int ast_channel_early_bridge ( struct ast_channel c0,
struct ast_channel c1 
)

Bridge two channels together (early).

Bridge two channels together (early)

Parameters:
c0 first channel to bridge
c1 second channel to bridge Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
Returns:
Returns 0 on success and -1 if it could not be done

Definition at line 4957 of file channel.c.

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

Referenced by dial_exec_full(), and wait_for_answer().

04958 {
04959    /* Make sure we can early bridge, if not error out */
04960    if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge)))
04961       return -1;
04962 
04963    return c0->tech->early_bridge(c0, c1);
04964 }

void ast_channel_free ( struct ast_channel chan  ) 

Free a channel structure.

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

01389 {
01390    int fd;
01391 #ifdef HAVE_EPOLL
01392    int i;
01393 #endif
01394    struct ast_var_t *vardata;
01395    struct ast_frame *f;
01396    struct varshead *headp;
01397    struct ast_datastore *datastore = NULL;
01398    char name[AST_CHANNEL_NAME], *dashptr;
01399    int inlist;
01400    
01401    headp=&chan->varshead;
01402    
01403    inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST);
01404    if (inlist) {
01405       AST_RWLIST_WRLOCK(&channels);
01406       if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) {
01407          ast_debug(1, "Unable to find channel in list to free. Assuming it has already been done.\n");
01408       }
01409       /* Lock and unlock the channel just to be sure nobody has it locked still
01410          due to a reference retrieved from the channel list. */
01411       ast_channel_lock(chan);
01412       ast_channel_unlock(chan);
01413    }
01414 
01415    /* Get rid of each of the data stores on the channel */
01416    ast_channel_lock(chan);
01417    while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry)))
01418       /* Free the data store */
01419       ast_datastore_free(datastore);
01420    ast_channel_unlock(chan);
01421 
01422    /* Lock and unlock the channel just to be sure nobody has it locked still
01423       due to a reference that was stored in a datastore. (i.e. app_chanspy) */
01424    ast_channel_lock(chan);
01425    ast_channel_unlock(chan);
01426 
01427    if (chan->tech_pvt) {
01428       ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name);
01429       ast_free(chan->tech_pvt);
01430    }
01431 
01432    if (chan->sched)
01433       sched_context_destroy(chan->sched);
01434 
01435    ast_copy_string(name, chan->name, sizeof(name));
01436    if ((dashptr = strrchr(name, '-'))) {
01437       *dashptr = '\0';
01438    }
01439 
01440    /* Stop monitoring */
01441    if (chan->monitor)
01442       chan->monitor->stop( chan, 0 );
01443 
01444    /* If there is native format music-on-hold state, free it */
01445    if (chan->music_state)
01446       ast_moh_cleanup(chan);
01447 
01448    /* Free translators */
01449    if (chan->readtrans)
01450       ast_translator_free_path(chan->readtrans);
01451    if (chan->writetrans)
01452       ast_translator_free_path(chan->writetrans);
01453    if (chan->pbx)
01454       ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
01455    free_cid(&chan->cid);
01456    /* Close pipes if appropriate */
01457    if ((fd = chan->alertpipe[0]) > -1)
01458       close(fd);
01459    if ((fd = chan->alertpipe[1]) > -1)
01460       close(fd);
01461    if (chan->timer) {
01462       ast_timer_close(chan->timer);
01463    }
01464 #ifdef HAVE_EPOLL
01465    for (i = 0; i < AST_MAX_FDS; i++) {
01466       if (chan->epfd_data[i])
01467          free(chan->epfd_data[i]);
01468    }
01469    close(chan->epfd);
01470 #endif
01471    while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list)))
01472       ast_frfree(f);
01473    
01474    /* loop over the variables list, freeing all data and deleting list items */
01475    /* no need to lock the list, as the channel is already locked */
01476    
01477    while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
01478       ast_var_delete(vardata);
01479 
01480    ast_app_group_discard(chan);
01481 
01482    /* Destroy the jitterbuffer */
01483    ast_jb_destroy(chan);
01484 
01485    if (chan->cdr) {
01486       ast_cdr_discard(chan->cdr);
01487       chan->cdr = NULL;
01488    }
01489 
01490    if (chan->zone) {
01491       chan->zone = ast_tone_zone_unref(chan->zone);
01492    }
01493 
01494    ast_mutex_destroy(&chan->lock_dont_use);
01495 
01496    ast_string_field_free_memory(chan);
01497    ast_free(chan);
01498    if (inlist)
01499       AST_RWLIST_UNLOCK(&channels);
01500 
01501    /* Queue an unknown state, because, while we know that this particular
01502     * instance is dead, we don't know the state of all other possible
01503     * instances. */
01504    ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name);
01505 }

void ast_channel_inherit_variables ( const struct ast_channel parent,
struct ast_channel child 
)

Inherits channel variable from parent to child channel.

Parameters:
parent Parent channel
child Child channel

Scans all channel variables in the parent channel, looking for those that should be copied into the child channel. Variables whose names begin with a single '_' are copied into the child channel with the prefix removed. Variables whose names begin with '__' are copied into the child channel with their names unchanged.

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

04303 {
04304    struct ast_var_t *current, *newvar;
04305    const char *varname;
04306 
04307    AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
04308       int vartype = 0;
04309 
04310       varname = ast_var_full_name(current);
04311       if (!varname)
04312          continue;
04313 
04314       if (varname[0] == '_') {
04315          vartype = 1;
04316          if (varname[1] == '_')
04317             vartype = 2;
04318       }
04319 
04320       switch (vartype) {
04321       case 1:
04322          newvar = ast_var_assign(&varname[1], ast_var_value(current));
04323          if (newvar) {
04324             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
04325             ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar));
04326          }
04327          break;
04328       case 2:
04329          newvar = ast_var_assign(varname, ast_var_value(current));
04330          if (newvar) {
04331             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
04332             ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar));
04333          }
04334          break;
04335       default:
04336          ast_debug(1, "Not copying variable %s.\n", ast_var_name(current));
04337          break;
04338       }
04339    }
04340 }

int ast_channel_make_compatible ( struct ast_channel c0,
struct ast_channel c1 
)

Makes two channel formats compatible.

Parameters:
c0 first channel to make compatible
c1 other channel to make compatible Set two channels to compatible formats -- call before ast_channel_bridge in general .
Returns:
Returns 0 on success and -1 if it could not be done

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

04201 {
04202    /* Some callers do not check return code, and we must try to set all call legs correctly */
04203    int rc = 0;
04204 
04205    /* Set up translation from the chan to the peer */
04206    rc = ast_channel_make_compatible_helper(chan, peer);
04207 
04208    if (rc < 0)
04209       return rc;
04210 
04211    /* Set up translation from the peer to the chan */
04212    rc = ast_channel_make_compatible_helper(peer, chan);
04213 
04214    return rc;
04215 }

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

References AST_FORMAT_AUDIO_MASK, AST_FORMAT_SLINEAR, ast_log(), ast_opt_transcode_via_slin, ast_set_read_format(), ast_set_write_format(), ast_translate_path_steps(), ast_translator_best_choice(), LOG_WARNING, ast_channel::name, ast_channel::nativeformats, ast_channel::readformat, and ast_channel::writeformat.

Referenced by ast_channel_make_compatible().

04160 {
04161    int src;
04162    int dst;
04163 
04164    if (from->readformat == to->writeformat && from->writeformat == to->readformat) {
04165       /* Already compatible!  Moving on ... */
04166       return 0;
04167    }
04168 
04169    /* Set up translation from the 'from' channel to the 'to' channel */
04170    src = from->nativeformats;
04171    dst = to->nativeformats;
04172 
04173    /* If there's no audio in this call, don't bother with trying to find a translation path */
04174    if ((src & AST_FORMAT_AUDIO_MASK) == 0 || (dst & AST_FORMAT_AUDIO_MASK) == 0)
04175       return 0;
04176 
04177    if (ast_translator_best_choice(&dst, &src) < 0) {
04178       ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", from->name, src, to->name, dst);
04179       return -1;
04180    }
04181 
04182    /* if the best path is not 'pass through', then
04183       transcoding is needed; if desired, force transcode path
04184       to use SLINEAR between channels, but only if there is
04185       no direct conversion available */
04186    if ((src != dst) && ast_opt_transcode_via_slin &&
04187        (ast_translate_path_steps(dst, src) != 1))
04188       dst = AST_FORMAT_SLINEAR;
04189    if (ast_set_read_format(from, dst) < 0) {
04190       ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", from->name, dst);
04191       return -1;
04192    }
04193    if (ast_set_write_format(to, dst) < 0) {
04194       ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", to->name, dst);
04195       return -1;
04196    }
04197    return 0;
04198 }

int ast_channel_masquerade ( struct ast_channel original,
struct ast_channel clone 
)

Weird function made for call transfers.

Parameters:
original channel to make a copy of
clone copy of the original channel

This is a very strange and freaky function used primarily for transfer. Suppose that "original" and "clone" are two channels in random situations. This function takes the guts out of "clone" and puts them into the "original" channel, then alerts the channel driver of the change, asking it to fixup any private information (like the p->owner pointer) that is affected by the change. The physical layer of the original channel is hung up.

Note:
Neither channel passed here needs to be locked before calling this function.

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

04218 {
04219    int res = -1;
04220    struct ast_channel *final_orig, *final_clone, *base;
04221 
04222 retrymasq:
04223    final_orig = original;
04224    final_clone = clonechan;
04225 
04226    ast_channel_lock(original);
04227    while (ast_channel_trylock(clonechan)) {
04228       ast_channel_unlock(original);
04229       usleep(1);
04230       ast_channel_lock(original);
04231    }
04232 
04233    /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
04234       and if so, we don't really want to masquerade it, but its proxy */
04235    if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original))
04236       final_orig = original->_bridge;
04237 
04238    if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan))
04239       final_clone = clonechan->_bridge;
04240    
04241    if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) {
04242       final_clone = base;
04243    }
04244 
04245    if ((final_orig != original) || (final_clone != clonechan)) {
04246       /* Lots and lots of deadlock avoidance.  The main one we're competing with
04247        * is ast_write(), which locks channels recursively, when working with a
04248        * proxy channel. */
04249       if (ast_channel_trylock(final_orig)) {
04250          ast_channel_unlock(clonechan);
04251          ast_channel_unlock(original);
04252          goto retrymasq;
04253       }
04254       if (ast_channel_trylock(final_clone)) {
04255          ast_channel_unlock(final_orig);
04256          ast_channel_unlock(clonechan);
04257          ast_channel_unlock(original);
04258          goto retrymasq;
04259       }
04260       ast_channel_unlock(clonechan);
04261       ast_channel_unlock(original);
04262       original = final_orig;
04263       clonechan = final_clone;
04264    }
04265 
04266    if (original == clonechan) {
04267       ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
04268       ast_channel_unlock(clonechan);
04269       ast_channel_unlock(original);
04270       return -1;
04271    }
04272 
04273    ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n",
04274       clonechan->name, original->name);
04275    if (original->masq) {
04276       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
04277          original->masq->name, original->name);
04278    } else if (clonechan->masqr) {
04279       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
04280          clonechan->name, clonechan->masqr->name);
04281    } else {
04282       original->masq = clonechan;
04283       clonechan->masqr = original;
04284       ast_queue_frame(original, &ast_null_frame);
04285       ast_queue_frame(clonechan, &ast_null_frame);
04286       ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name);
04287       res = 0;
04288    }
04289 
04290    ast_channel_unlock(clonechan);
04291    ast_channel_unlock(original);
04292 
04293    return res;
04294 }

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

05321 {
05322    if (!chan->tech->queryoption) {
05323       errno = ENOSYS;
05324       return -1;
05325    }
05326 
05327    if (block)
05328       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
05329 
05330    return chan->tech->queryoption(chan, option, data, datalen);
05331 }

const char* ast_channel_reason2str ( int  reason  ) 

return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument

Parameters:
reason The integer argument, usually taken from AST_CONTROL_ macros
Returns:
char pointer explaining the code

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

03744 {
03745    switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
03746    {
03747    case 0:
03748       return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
03749    case AST_CONTROL_HANGUP:
03750       return "Hangup";
03751    case AST_CONTROL_RING:
03752       return "Local Ring";
03753    case AST_CONTROL_RINGING:
03754       return "Remote end Ringing";
03755    case AST_CONTROL_ANSWER:
03756       return "Remote end has Answered";
03757    case AST_CONTROL_BUSY:
03758       return "Remote end is Busy";
03759    case AST_CONTROL_CONGESTION:
03760       return "Congestion (circuits busy)";
03761    default:
03762       return "Unknown Reason!!";
03763    }
03764 }

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

01311 {
01312    struct ast_channel *c = NULL;
01313 
01314    AST_RWLIST_RDLOCK(&channels);
01315    AST_RWLIST_TRAVERSE(&channels, c, chan_list) {
01316       ast_channel_lock(c);
01317       if (is_match(c, data)) {
01318          break;
01319       }
01320       ast_channel_unlock(c);
01321    }
01322    AST_RWLIST_UNLOCK(&channels);
01323 
01324    return c;
01325 }

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

04147 {
04148    if (chan->tech->send_html)
04149       return chan->tech->send_html(chan, subclass, data, datalen);
04150    return -1;
04151 }

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

References ast_channel_sendhtml(), and AST_HTML_URL.

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

04154 {
04155    return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
04156 }

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

Set the file descriptor on the channel

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

01577 {
01578 #ifdef HAVE_EPOLL
01579    struct epoll_event ev;
01580    struct ast_epoll_data *aed = NULL;
01581 
01582    if (chan->fds[which] > -1) {
01583       epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev);
01584       aed = chan->epfd_data[which];
01585    }
01586 
01587    /* If this new fd is valid, add it to the epoll */
01588    if (fd > -1) {
01589       if (!aed && (!(aed = ast_calloc(1, sizeof(*aed)))))
01590          return;
01591       
01592       chan->epfd_data[which] = aed;
01593       aed->chan = chan;
01594       aed->which = which;
01595       
01596       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
01597       ev.data.ptr = aed;
01598       epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev);
01599    } else if (aed) {
01600       /* We don't have to keep around this epoll data structure now */
01601       free(aed);
01602       chan->epfd_data[which] = NULL;
01603    }
01604 #endif
01605    chan->fds[which] = fd;
01606    return;
01607 }

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

Parameters:
channel channel to set options on
option option to change
data data specific to option
datalen length of the data
block blocking or not Set an option on a channel (see frame.h), optionally blocking awaiting the reply Returns 0 on success and -1 on failure

Definition at line 5307 of file channel.c.

References ast_log(), errno, LOG_ERROR, ast_channel_tech::setoption, and ast_channel::tech.

Referenced by ast_bridge_call(), common_exec(), conf_run(), dahdi_hangup(), dial_exec_full(), func_channel_write(), handle_tddmode(), play_record_review(), reset_volumes(), rpt(), rpt_exec(), set_listen_volume(), set_talk_volume(), try_calling(), and vm_forwardoptions().

05308 {
05309    if (!chan->tech->setoption) {
05310       errno = ENOSYS;
05311       return -1;
05312    }
05313 
05314    if (block)
05315       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
05316 
05317    return chan->tech->setoption(chan, option, data, datalen);
05318 }

void ast_channel_setwhentohangup ( struct ast_channel chan,
time_t  offset 
)

Set when to hang a channel up.

Parameters:
chan channel on which to check for hang up
offset offset in seconds relative to the current time of when to hang up

This function sets the absolute time out on a channel (when to hang up).

Note:
This function does not require that the channel is locked before calling it.
Returns:
Nothing
See also:
ast_channel_setwhentohangup_tv()
Version:
1.6.1 deprecated function (only had seconds precision)

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

Parameters:
chan The channel to generate silence on
Returns:
An ast_silence_generator pointer, or NULL if an error occurs

This function will cause SLINEAR silence to be generated on the supplied channel until it is disabled; if the channel cannot be put into SLINEAR mode then the function will fail.

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 5640 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_safe_sleep_conditional(), channel_spy(), record_exec(), TransferCallStep1(), waitfor_exec(), and waitforring_exec().

05641 {
05642    struct ast_silence_generator *state;
05643 
05644    if (!(state = ast_calloc(1, sizeof(*state)))) {
05645       return NULL;
05646    }
05647 
05648    state->old_write_format = chan->writeformat;
05649 
05650    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
05651       ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
05652       ast_free(state);
05653       return NULL;
05654    }
05655 
05656    ast_activate_generator(chan, &silence_generator, state);
05657 
05658    ast_debug(1, "Started silence generator on '%s'\n", chan->name);
05659 
05660    return state;
05661 }

void ast_channel_stop_silence_generator ( struct ast_channel chan,
struct ast_silence_generator state 
)

Stops a previously-started silence generator on the given channel.

Parameters:
chan The channel to operate on
state The ast_silence_generator pointer return by a previous call to ast_channel_start_silence_generator.
Returns:
nothing

This function will stop the operating silence generator and return the channel to its previous write format.

Definition at line 5663 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_safe_sleep_conditional(), channel_spy(), HandleCallOutgoing(), key_dial_page(), record_exec(), unistim_hangup(), waitfor_exec(), and waitforring_exec().

05664 {
05665    if (!state)
05666       return;
05667 
05668    ast_deactivate_generator(chan);
05669 
05670    ast_debug(1, "Stopped silence generator on '%s'\n", chan->name);
05671 
05672    if (ast_set_write_format(chan, state->old_write_format) < 0)
05673       ast_log(LOG_ERROR, "Could not return write format to its original state\n");
05674 
05675    ast_free(state);
05676 }

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

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

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

04142 {
04143    return (chan->tech->send_html) ? 1 : 0;
04144 }

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

References ast_clear_flag, and AST_FLAG_DEFER_DTMF.

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

01159 {
01160    if (chan)
01161       ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
01162 }

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

01273 {
01274    return channel_find_locked(prev, NULL, 0, NULL, NULL);
01275 }

void ast_channels_init ( void   ) 

Provided by channel.c

Definition at line 5561 of file channel.c.

References ARRAY_LEN, ast_cli_register_multiple(), and cli_channel.

Referenced by main().

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_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), feature_request_and_dial(), findmeexec(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), rpt(), rpt_exec(), run_ras(), try_calling(), and wait_for_answer().

00462 {
00463    if (chan->_softhangup)     /* yes if soft hangup flag set */
00464       return 1;
00465    if (ast_tvzero(chan->whentohangup)) /* no if no hangup scheduled */
00466       return 0;
00467    if (ast_tvdiff_ms(chan->whentohangup, ast_tvnow()) > 0)  /* no if hangup time has not come yet. */
00468       return 0;
00469    chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */
00470    return 1;
00471 }

static int ast_check_hangup_locked ( struct ast_channel chan  )  [static]

Definition at line 473 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().

Referenced by ast_channel_bridge().

00474 {
00475    int res;
00476    ast_channel_lock(chan);
00477    res = ast_check_hangup(chan);
00478    ast_channel_unlock(chan);
00479    return res;
00480 }

void ast_deactivate_generator ( struct ast_channel chan  ) 
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.

Note:
Assumes channel will be locked when called

Definition at line 4393 of file channel.c.

References ast_channel::_softhangup, ast_channel::_state, ast_channel::adsicpe, ast_channel::alertpipe, ast_app_group_update(), ast_cause2str(), ast_channel_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_set_fd(), ast_channel_unlock, ast_copy_string(), ast_debug, AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_GENERATOR_FD, ast_indicate(), AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MAX_FDS, ast_null_frame, ast_queue_frame(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), AST_SOFTHANGUP_DEV, ast_state2str(), ast_string_field_set, ast_test_flag, AST_TIMING_FD, ast_channel::blocker, ast_channel::cdr, ast_datastore_info::chan_fixup, ast_channel::cid, clone_variables(), ast_datastore::data, ast_channel::datastores, errno, EVENT_FLAG_CALL, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_channel::hangupcause, ast_datastore::info, ast_channel::language, language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::musicclass, musicclass, name, ast_channel::name, ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::readq, report_new_callerid(), ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, ast_channel::uniqueid, ast_channel::visible_indication, and ast_channel::writeformat.

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

04394 {
04395    int x,i;
04396    int res=0;
04397    int origstate;
04398    struct ast_frame *current;
04399    const struct ast_channel_tech *t;
04400    void *t_pvt;
04401    struct ast_callerid tmpcid;
04402    struct ast_channel *clonechan = original->masq;
04403    struct ast_cdr *cdr;
04404    int rformat = original->readformat;
04405    int wformat = original->writeformat;
04406    char newn[AST_CHANNEL_NAME];
04407    char orig[AST_CHANNEL_NAME];
04408    char masqn[AST_CHANNEL_NAME];
04409    char zombn[AST_CHANNEL_NAME];
04410 
04411    ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
04412       clonechan->name, clonechan->_state, original->name, original->_state);
04413 
04414    manager_event(EVENT_FLAG_CALL, "Masquerade", "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n",
04415             clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state));
04416 
04417    /* XXX This operation is a bit odd.  We're essentially putting the guts of
04418     * the clone channel into the original channel.  Start by killing off the
04419     * original channel's backend.  While the features are nice, which is the
04420     * reason we're keeping it, it's still awesomely weird. XXX */
04421 
04422    /* We need the clone's lock, too */
04423    ast_channel_lock(clonechan);
04424 
04425    ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clonechan->name, &clonechan->lock_dont_use);
04426 
04427    /* Having remembered the original read/write formats, we turn off any translation on either
04428       one */
04429    free_translation(clonechan);
04430    free_translation(original);
04431 
04432 
04433    /* Unlink the masquerade */
04434    original->masq = NULL;
04435    clonechan->masqr = NULL;
04436    
04437    /* Save the original name */
04438    ast_copy_string(orig, original->name, sizeof(orig));
04439    /* Save the new name */
04440    ast_copy_string(newn, clonechan->name, sizeof(newn));
04441    /* Create the masq name */
04442    snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
04443       
04444    /* Copy the name from the clone channel */
04445    ast_string_field_set(original, name, newn);
04446 
04447    /* Mangle the name of the clone channel */
04448    ast_string_field_set(clonechan, name, masqn);
04449    
04450    /* Notify any managers of the change, first the masq then the other */
04451    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clonechan->uniqueid);
04452    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid);
04453 
04454    /* Swap the technologies */   
04455    t = original->tech;
04456    original->tech = clonechan->tech;
04457    clonechan->tech = t;
04458 
04459    /* Swap the cdrs */
04460    cdr = original->cdr;
04461    original->cdr = clonechan->cdr;
04462    clonechan->cdr = cdr;
04463 
04464    t_pvt = original->tech_pvt;
04465    original->tech_pvt = clonechan->tech_pvt;
04466    clonechan->tech_pvt = t_pvt;
04467 
04468    /* Swap the alertpipes */
04469    for (i = 0; i < 2; i++) {
04470       x = original->alertpipe[i];
04471       original->alertpipe[i] = clonechan->alertpipe[i];
04472       clonechan->alertpipe[i] = x;
04473    }
04474 
04475    /* 
04476     * Swap the readq's.  The end result should be this:
04477     *
04478     *  1) All frames should be on the new (original) channel.
04479     *  2) Any frames that were already on the new channel before this
04480     *     masquerade need to be at the end of the readq, after all of the
04481     *     frames on the old (clone) channel.
04482     *  3) The alertpipe needs to get poked for every frame that was already
04483     *     on the new channel, since we are now using the alert pipe from the
04484     *     old (clone) channel.
04485     */
04486    {
04487       AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;
04488       AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL);
04489 
04490       AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list);
04491       AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list);
04492 
04493       while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
04494          AST_LIST_INSERT_TAIL(&original->readq, current, frame_list);
04495          if (original->alertpipe[1] > -1) {
04496             int poke = 0;
04497 
04498             if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) {
04499                ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
04500             }
04501          }
04502       }
04503    }
04504 
04505    /* Swap the raw formats */
04506    x = original->rawreadformat;
04507    original->rawreadformat = clonechan->rawreadformat;
04508    clonechan->rawreadformat = x;
04509    x = original->rawwriteformat;
04510    original->rawwriteformat = clonechan->rawwriteformat;
04511    clonechan->rawwriteformat = x;
04512 
04513    clonechan->_softhangup = AST_SOFTHANGUP_DEV;
04514 
04515    /* And of course, so does our current state.  Note we need not
04516       call ast_setstate since the event manager doesn't really consider
04517       these separate.  We do this early so that the clone has the proper
04518       state of the original channel. */
04519    origstate = original->_state;
04520    original->_state = clonechan->_state;
04521    clonechan->_state = origstate;
04522 
04523    if (clonechan->tech->fixup){
04524       res = clonechan->tech->fixup(original, clonechan);
04525       if (res)
04526          ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name);
04527    }
04528 
04529    /* Start by disconnecting the original's physical side */
04530    if (clonechan->tech->hangup)
04531       res = clonechan->tech->hangup(clonechan);
04532    if (res) {
04533       ast_log(LOG_WARNING, "Hangup failed!  Strange things may happen!\n");
04534       ast_channel_unlock(clonechan);
04535       return -1;
04536    }
04537 
04538    snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig);
04539    /* Mangle the name of the clone channel */
04540    ast_string_field_set(clonechan, name, zombn);
04541    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clonechan->uniqueid);
04542 
04543    /* Update the type. */
04544    t_pvt = original->monitor;
04545    original->monitor = clonechan->monitor;
04546    clonechan->monitor = t_pvt;
04547 
04548    /* Keep the same language.  */
04549    ast_string_field_set(original, language, clonechan->language);
04550    /* Copy the FD's other than the generator fd */
04551    for (x = 0; x < AST_MAX_FDS; x++) {
04552       if (x != AST_GENERATOR_FD)
04553          ast_channel_set_fd(original, x, clonechan->fds[x]);
04554    }
04555 
04556    ast_app_group_update(clonechan, original);
04557 
04558    /* Move data stores over */
04559    if (AST_LIST_FIRST(&clonechan->datastores)) {
04560       struct ast_datastore *ds;
04561       /* We use a safe traversal here because some fixup routines actually
04562        * remove the datastore from the list and free them.
04563        */
04564       AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) {
04565          if (ds->info->chan_fixup)
04566             ds->info->chan_fixup(ds->data, clonechan, original);
04567       }
04568       AST_LIST_TRAVERSE_SAFE_END;
04569       AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry);
04570    }
04571 
04572    clone_variables(original, clonechan);
04573    /* Presense of ADSI capable CPE follows clone */
04574    original->adsicpe = clonechan->adsicpe;
04575    /* Bridge remains the same */
04576    /* CDR fields remain the same */
04577    /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
04578    /* Application and data remain the same */
04579    /* Clone exception  becomes real one, as with fdno */
04580    ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION));
04581    original->fdno = clonechan->fdno;
04582    /* Schedule context remains the same */
04583    /* Stream stuff stays the same */
04584    /* Keep the original state.  The fixup code will need to work with it most likely */
04585 
04586    /* Just swap the whole structures, nevermind the allocations, they'll work themselves
04587       out. */
04588    tmpcid = original->cid;
04589    original->cid = clonechan->cid;
04590    clonechan->cid = tmpcid;
04591    report_new_callerid(original);
04592 
04593    /* Restore original timing file descriptor */
04594    ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd);
04595 
04596    /* Our native formats are different now */
04597    original->nativeformats = clonechan->nativeformats;
04598 
04599    /* Context, extension, priority, app data, jump table,  remain the same */
04600    /* pvt switches.  pbx stays the same, as does next */
04601 
04602    /* Set the write format */
04603    ast_set_write_format(original, wformat);
04604 
04605    /* Set the read format */
04606    ast_set_read_format(original, rformat);
04607 
04608    /* Copy the music class */
04609    ast_string_field_set(original, musicclass, clonechan->musicclass);
04610 
04611    ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
04612 
04613    /* Okay.  Last thing is to let the channel driver know about all this mess, so he
04614       can fix up everything as best as possible */
04615    if (original->tech->fixup) {
04616       res = original->tech->fixup(clonechan, original);
04617       if (res) {
04618          ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n",
04619             original->tech->type, original->name);
04620          ast_channel_unlock(clonechan);
04621          return -1;
04622       }
04623    } else
04624       ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)!  Bad things may happen.\n",
04625          original->tech->type, original->name);
04626 
04627    /* 
04628     * If an indication is currently playing, maintain it on the channel 
04629     * that is taking the place of original 
04630     *
04631     * This is needed because the masquerade is swapping out in the internals
04632     * of this channel, and the new channel private data needs to be made
04633     * aware of the current visible indication (RINGING, CONGESTION, etc.)
04634     */
04635    if (original->visible_indication) {
04636       ast_indicate(original, original->visible_indication);
04637    }
04638    
04639    /* Now, at this point, the "clone" channel is totally F'd up.  We mark it as
04640       a zombie so nothing tries to touch it.  If it's already been marked as a
04641       zombie, then free it now (since it already is considered invalid). */
04642    if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) {
04643       ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name);
04644       ast_channel_unlock(clonechan);
04645       manager_event(EVENT_FLAG_CALL, "Hangup",
04646          "Channel: %s\r\n"
04647          "Uniqueid: %s\r\n"
04648          "Cause: %d\r\n"
04649          "Cause-txt: %s\r\n",
04650          clonechan->name,
04651          clonechan->uniqueid,
04652          clonechan->hangupcause,
04653          ast_cause2str(clonechan->hangupcause)
04654          );
04655       ast_channel_free(clonechan);
04656    } else {
04657       ast_debug(1, "Released clone lock on '%s'\n", clonechan->name);
04658       ast_set_flag(clonechan, AST_FLAG_ZOMBIE);
04659       ast_queue_frame(clonechan, &ast_null_frame);
04660       ast_channel_unlock(clonechan);
04661    }
04662 
04663    /* Signal any blocker */
04664    if (ast_test_flag(original, AST_FLAG_BLOCKING))
04665       pthread_kill(original->blocker, SIGURG);
04666    ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state);
04667    return 0;
04668 }

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

References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_IGNORE_SIGS, AST_BRIDGE_RETRY, AST_CONTROL_HOLD, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_debug, AST_FEATURE_WARNING_ACTIVE, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_indicate_data(), ast_jb_do_usecheck(), ast_jb_empty_and_reset(), ast_jb_get_and_deliver(), ast_jb_get_when_to_wakeup(), ast_jb_put(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_waitfor_n(), ast_write(), ast_frame::data, ast_frame::datalen, f, ast_bridge_config::feature_timer, ast_bridge_config::flags, ast_frame::frametype, ast_channel::name, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_bridge_config::partialfeature_timer, ast_frame::ptr, ast_frame::subclass, ast_channel::tech_pvt, and ast_bridge_config::timelimit.

Referenced by ast_channel_bridge().

04779 {
04780    /* Copy voice back and forth between the two channels. */
04781    struct ast_channel *cs[3];
04782    struct ast_frame *f;
04783    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
04784    int o0nativeformats;
04785    int o1nativeformats;
04786    int watch_c0_dtmf;
04787    int watch_c1_dtmf;
04788    void *pvt0, *pvt1;
04789    /* Indicates whether a frame was queued into a jitterbuffer */
04790    int frame_put_in_jb = 0;
04791    int jb_in_use;
04792    int to;
04793    
04794    cs[0] = c0;
04795    cs[1] = c1;
04796    pvt0 = c0->tech_pvt;
04797    pvt1 = c1->tech_pvt;
04798    o0nativeformats = c0->nativeformats;
04799    o1nativeformats = c1->nativeformats;
04800    watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0;
04801    watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1;
04802 
04803    /* Check the need of a jitterbuffer for each channel */
04804    jb_in_use = ast_jb_do_usecheck(c0, c1);
04805    if (jb_in_use)
04806       ast_jb_empty_and_reset(c0, c1);
04807 
04808    ast_poll_channel_add(c0, c1);
04809 
04810    if (config->feature_timer > 0 && ast_tvzero(config->nexteventts)) {
04811       /* calculate when the bridge should possibly break
04812        * if a partial feature match timed out */
04813       config->partialfeature_timer = ast_tvadd(ast_tvnow(), ast_samp2tv(config->feature_timer, 1000));
04814    } else {
04815       memset(&config->partialfeature_timer, 0, sizeof(config->partialfeature_timer));
04816    }
04817 
04818    for (;;) {
04819       struct ast_channel *who, *other;
04820 
04821       if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) ||
04822           (o0nativeformats != c0->nativeformats) ||
04823           (o1nativeformats != c1->nativeformats)) {
04824          /* Check for Masquerade, codec changes, etc */
04825          res = AST_BRIDGE_RETRY;
04826          break;
04827       }
04828       if (bridge_end.tv_sec) {
04829          to = ast_tvdiff_ms(bridge_end, ast_tvnow());
04830          if (to <= 0) {
04831             if (config->timelimit) {
04832                res = AST_BRIDGE_RETRY;
04833                /* generic bridge ending to play warning */
04834                ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
04835             } else {
04836                res = AST_BRIDGE_COMPLETE;
04837             }
04838             break;
04839          }
04840       } else {
04841          /* If a feature has been started and the bridge is configured to 
04842           * to not break, leave the channel bridge when the feature timer
04843           * time has elapsed so the DTMF will be sent to the other side. 
04844           */
04845          if (!ast_tvzero(config->partialfeature_timer)) {
04846             int diff = ast_tvdiff_ms(config->partialfeature_timer, ast_tvnow());
04847             if (diff <= 0) {
04848                res = AST_BRIDGE_RETRY;
04849                break;
04850             }
04851          }
04852          to = -1;
04853       }
04854       /* Calculate the appropriate max sleep interval - in general, this is the time,
04855          left to the closest jb delivery moment */
04856       if (jb_in_use)
04857          to = ast_jb_get_when_to_wakeup(c0, c1, to);
04858       who = ast_waitfor_n(cs, 2, &to);
04859       if (!who) {
04860          /* No frame received within the specified timeout - check if we have to deliver now */
04861          if (jb_in_use)
04862             ast_jb_get_and_deliver(c0, c1);
04863          if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
04864             if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04865                c0->_softhangup = 0;
04866             if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04867                c1->_softhangup = 0;
04868             c0->_bridge = c1;
04869             c1->_bridge = c0;
04870          }
04871          continue;
04872       }
04873       f = ast_read(who);
04874       if (!f) {
04875          *fo = NULL;
04876          *rc = who;
04877          ast_debug(1, "Didn't get a frame from channel: %s\n",who->name);
04878          break;
04879       }
04880 
04881       other = (who == c0) ? c1 : c0; /* the 'other' channel */
04882       /* Try add the frame info the who's bridged channel jitterbuff */
04883       if (jb_in_use)
04884          frame_put_in_jb = !ast_jb_put(other, f);
04885 
04886       if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) {
04887          int bridge_exit = 0;
04888 
04889          switch (f->subclass) {
04890          case AST_CONTROL_HOLD:
04891          case AST_CONTROL_UNHOLD:
04892          case AST_CONTROL_VIDUPDATE:
04893          case AST_CONTROL_SRCUPDATE:
04894          case AST_CONTROL_T38_PARAMETERS:
04895             ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen);
04896             if (jb_in_use) {
04897                ast_jb_empty_and_reset(c0, c1);
04898             }
04899             break;
04900          default:
04901             *fo = f;
04902             *rc = who;
04903             bridge_exit = 1;
04904             ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name);
04905             break;
04906          }
04907          if (bridge_exit)
04908             break;
04909       }
04910       if ((f->frametype == AST_FRAME_VOICE) ||
04911           (f->frametype == AST_FRAME_DTMF_BEGIN) ||
04912           (f->frametype == AST_FRAME_DTMF) ||
04913           (f->frametype == AST_FRAME_VIDEO) ||
04914           (f->frametype == AST_FRAME_IMAGE) ||
04915           (f->frametype == AST_FRAME_HTML) ||
04916           (f->frametype == AST_FRAME_MODEM) ||
04917           (f->frametype == AST_FRAME_TEXT)) {
04918          /* monitored dtmf causes exit from bridge */
04919          int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf;
04920 
04921          if (monitored_source && 
04922             (f->frametype == AST_FRAME_DTMF_END || 
04923             f->frametype == AST_FRAME_DTMF_BEGIN)) {
04924             *fo = f;
04925             *rc = who;
04926             ast_debug(1, "Got DTMF %s on channel (%s)\n", 
04927                f->frametype == AST_FRAME_DTMF_END ? "end" : "begin",
04928                who->name);
04929 
04930             break;
04931          }
04932          /* Write immediately frames, not passed through jb */
04933          if (!frame_put_in_jb)
04934             ast_write(other, f);
04935             
04936          /* Check if we have to deliver now */
04937          if (jb_in_use)
04938             ast_jb_get_and_deliver(c0, c1);
04939       }
04940       /* XXX do we want to pass on also frames not matched above ? */
04941       ast_frfree(f);
04942 
04943 #ifndef HAVE_EPOLL
04944       /* Swap who gets priority */
04945       cs[2] = cs[0];
04946       cs[0] = cs[1];
04947       cs[1] = cs[2];
04948 #endif
04949    }
04950 
04951    ast_poll_channel_del(c0, c1);
04952 
04953    return res;
04954 }

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

References channel_find_locked().

01298 {
01299    return channel_find_locked(NULL, NULL, 0, context, exten);
01300 }

struct ast_channel* ast_get_channel_by_name_locked ( const char *  name  )  [read]
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 1284 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().

01285 {
01286    return channel_find_locked(NULL, name, namelen, NULL, NULL);
01287 }

struct ast_channel_tech* ast_get_channel_tech ( const char *  name  )  [read]

Get handle to channel driver based on name.

Get a channel technology structure by name.

Definition at line 609 of file channel.c.

References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, chanlist::tech, and ast_channel_tech::type.

Referenced by _ast_device_state(), 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 5485 of file channel.c.

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

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

05486 {
05487    char *piece;
05488    char *c;
05489    int start=0, finish=0, x;
05490    ast_group_t group = 0;
05491 
05492    if (ast_strlen_zero(s))
05493       return 0;
05494 
05495    c = ast_strdupa(s);
05496    
05497    while ((piece = strsep(&c, ","))) {
05498       if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) {
05499          /* Range */
05500       } else if (sscanf(piece, "%30d", &start)) {
05501          /* Just one */
05502          finish = start;
05503       } else {
05504          ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
05505          continue;
05506       }
05507       for (x = start; x <= finish; x++) {
05508          if ((x > 63) || (x < 0)) {
05509             ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
05510          } else
05511             group |= ((ast_group_t) 1 << x);
05512       }
05513    }
05514    return group;
05515 }

int ast_hangup ( struct ast_channel chan  ) 

Hangup a channel.

Hang up a channel.

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

01691 {
01692    int res = 0;
01693 
01694    /* Don't actually hang up a channel that will masquerade as someone else, or
01695       if someone is going to masquerade as us */
01696    ast_channel_lock(chan);
01697 
01698    if (chan->audiohooks) {
01699       ast_audiohook_detach_list(chan->audiohooks);
01700       chan->audiohooks = NULL;
01701    }
01702 
01703    ast_autoservice_stop(chan);
01704 
01705    if (chan->masq) {
01706       if (ast_do_masquerade(chan))
01707          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
01708    }
01709 
01710    if (chan->masq) {
01711       ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name);
01712       ast_channel_unlock(chan);
01713       return 0;
01714    }
01715    /* If this channel is one which will be masqueraded into something,
01716       mark it as a zombie already, so we know to free it later */
01717    if (chan->masqr) {
01718       ast_set_flag(chan, AST_FLAG_ZOMBIE);
01719       ast_channel_unlock(chan);
01720       return 0;
01721    }
01722    ast_channel_unlock(chan);
01723 
01724    AST_RWLIST_WRLOCK(&channels);
01725    if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) {
01726       ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n");
01727    }
01728    ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST);
01729    AST_RWLIST_UNLOCK(&channels);
01730 
01731    ast_channel_lock(chan);
01732    free_translation(chan);
01733    /* Close audio stream */
01734    if (chan->stream) {
01735       ast_closestream(chan->stream);
01736       chan->stream = NULL;
01737    }
01738    /* Close video stream */
01739    if (chan->vstream) {
01740       ast_closestream(chan->vstream);
01741       chan->vstream = NULL;
01742    }
01743    if (chan->sched) {
01744       sched_context_destroy(chan->sched);
01745       chan->sched = NULL;
01746    }
01747    
01748    if (chan->generatordata)   /* Clear any tone stuff remaining */
01749       if (chan->generator && chan->generator->release)
01750          chan->generator->release(chan, chan->generatordata);
01751    chan->generatordata = NULL;
01752    chan->generator = NULL;
01753    if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
01754       ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
01755                "is blocked by thread %ld in procedure %s!  Expect a failure\n",
01756                (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
01757       ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0);
01758    }
01759    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
01760       ast_debug(1, "Hanging up channel '%s'\n", chan->name);
01761       if (chan->tech->hangup)
01762          res = chan->tech->hangup(chan);
01763    } else {
01764       ast_debug(1, "Hanging up zombie '%s'\n", chan->name);
01765    }
01766          
01767    ast_channel_unlock(chan);
01768    manager_event(EVENT_FLAG_CALL, "Hangup",
01769          "Channel: %s\r\n"
01770          "Uniqueid: %s\r\n"
01771          "CallerIDNum: %s\r\n"
01772          "CallerIDName: %s\r\n"
01773          "Cause: %d\r\n"
01774          "Cause-txt: %s\r\n",
01775          chan->name,
01776          chan->uniqueid,
01777          S_OR(chan->cid.cid_num, "<unknown>"),
01778          S_OR(chan->cid.cid_name, "<unknown>"),
01779          chan->hangupcause,
01780          ast_cause2str(chan->hangupcause)
01781          );
01782 
01783    if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 
01784       !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 
01785        (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) {
01786       ast_channel_lock(chan);
01787          
01788       ast_cdr_end(chan->cdr);
01789       ast_cdr_detach(chan->cdr);
01790       chan->cdr = NULL;
01791       ast_channel_unlock(chan);
01792    }
01793    
01794    ast_channel_free(chan);
01795 
01796    return res;
01797 }

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

Indicates condition of channel, with payload.

Note:
Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
Parameters:
chan channel to change the indication
condition which condition to indicate on the channel
data pointer to payload data
datalen size of payload data
Returns:
Returns 0 on success, -1 on failure

Note:
If we compare the enumeration type, which does not have any negative constants, the compiler may optimize this code away. Therefore, we must perform an integer comparison here.

Definition at line 3150 of file channel.c.

References ast_channel::_state, _XXX_AST_CONTROL_T38, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_debug, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STATE_UP, ast_test_flag, 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().

03152 {
03153    /* By using an enum, we'll get compiler warnings for values not handled 
03154     * in switch statements. */
03155    enum ast_control_frame_type condition = _condition;
03156    struct ast_tone_zone_sound *ts = NULL;
03157    int res = -1;
03158 
03159    ast_channel_lock(chan);
03160 
03161    /* Don't bother if the channel is about to go away, anyway. */
03162    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
03163       ast_channel_unlock(chan);
03164       return -1;
03165    }
03166 
03167    if (chan->tech->indicate) {
03168       /* See if the channel driver can handle this condition. */
03169       res = chan->tech->indicate(chan, condition, data, datalen);
03170    }
03171 
03172    ast_channel_unlock(chan);
03173 
03174    if (!res) {
03175       /* The channel driver successfully handled this indication */
03176       if (is_visible_indication(condition)) {
03177          chan->visible_indication = condition;
03178       }
03179       return 0;
03180    }
03181 
03182    /* The channel driver does not support this indication, let's fake
03183     * it by doing our own tone generation if applicable. */
03184 
03185    /*!\note If we compare the enumeration type, which does not have any
03186     * negative constants, the compiler may optimize this code away.
03187     * Therefore, we must perform an integer comparison here. */
03188    if (_condition < 0) {
03189       /* Stop any tones that are playing */
03190       ast_playtones_stop(chan);
03191       return 0;
03192    }
03193 
03194    /* Handle conditions that we have tones for. */
03195    switch (condition) {
03196    case _XXX_AST_CONTROL_T38:
03197       /* deprecated T.38 control frame */
03198       return -1;
03199    case AST_CONTROL_T38_PARAMETERS:
03200       /* there is no way to provide 'default' behavior for these
03201        * control frames, so we need to return failure, but there
03202        * is also no value in the log message below being emitted
03203        * since failure to handle these frames is not an 'error'
03204        * so just return right now.
03205        */
03206       return -1;
03207    case AST_CONTROL_RINGING:
03208       ts = ast_get_indication_tone(chan->zone, "ring");
03209       /* It is common practice for channel drivers to return -1 if trying
03210        * to indicate ringing on a channel which is up. The idea is to let the
03211        * core generate the ringing inband. However, we don't want the
03212        * warning message about not being able to handle the specific indication
03213        * to print nor do we want ast_indicate_data to return an "error" for this
03214        * condition
03215        */
03216       if (chan->_state == AST_STATE_UP) {
03217          res = 0;
03218       }
03219       break;
03220    case AST_CONTROL_BUSY:
03221       ts = ast_get_indication_tone(chan->zone, "busy");
03222       break;
03223    case AST_CONTROL_CONGESTION:
03224       ts = ast_get_indication_tone(chan->zone, "congestion");
03225       break;
03226    case AST_CONTROL_PROGRESS:
03227    case AST_CONTROL_PROCEEDING:
03228    case AST_CONTROL_VIDUPDATE:
03229    case AST_CONTROL_SRCUPDATE:
03230    case AST_CONTROL_RADIO_KEY:
03231    case AST_CONTROL_RADIO_UNKEY:
03232    case AST_CONTROL_OPTION:
03233    case AST_CONTROL_WINK:
03234    case AST_CONTROL_FLASH:
03235    case AST_CONTROL_OFFHOOK:
03236    case AST_CONTROL_TAKEOFFHOOK:
03237    case AST_CONTROL_ANSWER:
03238    case AST_CONTROL_HANGUP:
03239    case AST_CONTROL_RING:
03240    case AST_CONTROL_HOLD:
03241    case AST_CONTROL_UNHOLD:
03242       /* Nothing left to do for these. */
03243       res = 0;
03244       break;
03245    }
03246 
03247    if (ts) {
03248       /* We have a tone to play, yay. */
03249       ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
03250       ast_playtones_start(chan, 0, ts->data, 1);
03251       ts = ast_tone_zone_sound_unref(ts);
03252       res = 0;
03253       chan->visible_indication = condition;
03254    }
03255 
03256    if (res) {
03257       /* not handled */
03258       ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name);
03259    }
03260 
03261    return res;
03262 }

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

References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.

Referenced by load_module(), and reload().

05524 {
05525    ast_moh_start_ptr = start_ptr;
05526    ast_moh_stop_ptr = stop_ptr;
05527    ast_moh_cleanup_ptr = cleanup_ptr;
05528 }

int ast_internal_timing_enabled ( struct ast_channel chan  ) 

Check if the channel can run in internal timing mode.

Parameters:
chan The channel to check
Returns:
boolean

This function will return 1 if internal timing is enabled and the timing device is available.

Definition at line 3093 of file channel.c.

References ast_debug, ast_opt_internal_timing, and ast_channel::timingfd.

Referenced by add_sdp(), and ast_read_generator_actions().

03094 {
03095    int ret = ast_opt_internal_timing && chan->timingfd > -1;
03096    ast_debug(5, "Internal timing is %s (option_internal_timing=%d chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_internal_timing, chan->timingfd);
03097    return ret;
03098 }

void ast_moh_cleanup ( struct ast_channel chan  ) 

Definition at line 5555 of file channel.c.

References ast_moh_cleanup_ptr.

Referenced by ast_channel_free().

05556 {
05557    if (ast_moh_cleanup_ptr)
05558       ast_moh_cleanup_ptr(chan);
05559 }

int ast_moh_start ( struct ast_channel chan,
const char *  mclass,
const char *  interpclass 
)

Turn on music on hold on a given channel.

Parameters:
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.
Return values:
Zero on success
non-zero on failure

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

05539 {
05540    if (ast_moh_start_ptr)
05541       return ast_moh_start_ptr(chan, mclass, interpclass);
05542 
05543    ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default"));
05544 
05545    return 0;
05546 }

void ast_moh_stop ( struct ast_channel chan  ) 
void ast_poll_channel_add ( struct ast_channel chan0,
struct ast_channel chan1 
)

Add a channel to an optimized waitfor

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

01611 {
01612 #ifdef HAVE_EPOLL
01613    struct epoll_event ev;
01614    int i = 0;
01615 
01616    if (chan0->epfd == -1)
01617       return;
01618 
01619    /* Iterate through the file descriptors on chan1, adding them to chan0 */
01620    for (i = 0; i < AST_MAX_FDS; i++) {
01621       if (chan1->fds[i] == -1)
01622          continue;
01623       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
01624       ev.data.ptr = chan1->epfd_data[i];
01625       epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev);
01626    }
01627 
01628 #endif
01629    return;
01630 }

void ast_poll_channel_del ( struct ast_channel chan0,
struct ast_channel chan1 
)

Delete a channel from an optimized waitfor

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

01634 {
01635 #ifdef HAVE_EPOLL
01636    struct epoll_event ev;
01637    int i = 0;
01638 
01639    if (chan0->epfd == -1)
01640       return;
01641 
01642    for (i = 0; i < AST_MAX_FDS; i++) {
01643       if (chan1->fds[i] == -1)
01644          continue;
01645       epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev);
01646    }
01647 
01648 #endif
01649    return;
01650 }

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

References first, and num.

Referenced by _sip_show_peer(), _skinny_show_line(), func_channel_read(), function_sippeer(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().

05568 {
05569    unsigned int i;
05570    int first = 1;
05571    char num[3];
05572 
05573    buf[0] = '\0';
05574    
05575    if (!group) /* Return empty string if no group */
05576       return buf;
05577 
05578    for (i = 0; i <= 63; i++) {   /* Max group is 63 */
05579       if (group & ((ast_group_t) 1 << i)) {
05580             if (!first) {
05581             strncat(buf, ", ", buflen - strlen(buf) - 1);
05582          } else {
05583             first = 0;
05584          }
05585          snprintf(num, sizeof(num), "%u", i);
05586          strncat(buf, num, buflen - strlen(buf) - 1);
05587       }
05588    }
05589    return buf;
05590 }

int ast_prod ( struct ast_channel chan  ) 

Send empty audio to prime a channel driver.

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

03384 {
03385    struct ast_frame a = { AST_FRAME_VOICE };
03386    char nothing[128];
03387 
03388    /* Send an empty audio frame to get things moving */
03389    if (chan->_state != AST_STATE_UP) {
03390       ast_debug(1, "Prodding channel '%s'\n", chan->name);
03391       a.subclass = chan->rawwriteformat;
03392       a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
03393       a.src = "ast_prod";
03394       if (ast_write(chan, &a))
03395          ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name);
03396    }
03397    return 0;
03398 }

int ast_queue_control ( struct ast_channel chan,
enum ast_control_frame_type  control 
)
int ast_queue_control_data ( struct ast_channel chan,
enum ast_control_frame_type  control,
const void *  data,
size_t  datalen 
)

Queue a control frame with payload.

Parameters:
chan channel to queue frame onto
control type of control frame
data pointer to payload data to be included in frame
datalen number of bytes of payload data
Return values:
0 success
non-zero failure

The supplied payload data is copied into the frame, so the caller's copy is not modified nor freed, and the resulting frame will retain a copy of the data even if the caller frees their local copy.

Note:
This method should be treated as a 'network transport'; in other words, your frames may be transferred across an IAX2 channel to another system, which may be a different endianness than yours. Because of this, you should ensure that either your frames will never be expected to work across systems, or that you always put your payload data into 'network byte order' before calling this function.
The channel does not need to be locked before calling this function.

Definition at line 1133 of file channel.c.

References AST_FRAME_CONTROL, ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::ptr, and ast_frame::subclass.

Referenced by change_t38_state(), dahdi_handle_event(), dahdi_hangup(), iax2_queue_control_data(), process_sdp(), and skinny_hold().

01135 {
01136    struct ast_frame f = { AST_FRAME_CONTROL, };
01137 
01138    f.subclass = control;
01139    f.data.ptr = (void *) data;
01140    f.datalen = datalen;
01141 
01142    return ast_queue_frame(chan, &f);
01143 }

int ast_queue_frame ( struct ast_channel chan,
struct ast_frame f 
)

Queue one or more frames to a channel's frame queue.

Parameters:
chan the channel to queue the frame(s) on
f the frame(s) to queue. Note that the frame(s) will be duplicated by this function. It is the responsibility of the caller to handle freeing the memory associated with the frame(s) being passed if necessary.
Return values:
0 success
non-zero failure

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

01081 {
01082    return __ast_queue_frame(chan, fin, 0, NULL);
01083 }

int ast_queue_frame_head ( struct ast_channel chan,
struct ast_frame f 
)

Queue one or more frames to the head of a channel's frame queue.

Parameters:
chan the channel to queue the frame(s) on
f the frame(s) to queue. Note that the frame(s) will be duplicated by this function. It is the responsibility of the caller to handle freeing the memory associated with the frame(s) being passed if necessary.
Return values:
0 success
non-zero failure

Definition at line 1085 of file channel.c.

References __ast_queue_frame().

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

01086 {
01087    return __ast_queue_frame(chan, fin, 1, NULL);
01088 }

int ast_queue_hangup ( struct ast_channel chan  ) 
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 1103 of file channel.c.

References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, ast_frame::data, ast_channel::hangupcause, and ast_frame::uint32.

Referenced by __oh323_update_info(), __sip_autodestruct(), close_call(), close_client(), console_hangup(), dahdi_handle_event(), handle_request_bye(), handle_response(), handle_response_invite(), handle_response_notify(), HandleCallOutgoing(), hangup_chan(), hangup_connection(), misdn_answer(), pri_hangup_all(), retrans_pkt(), and TransferCallStep1().

01104 {
01105    struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
01106 
01107    if (cause >= 0)
01108       f.data.uint32 = cause;
01109 
01110    /* Yeah, let's not change a lock-critical value without locking */
01111    if (!ast_channel_trylock(chan)) {
01112       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01113       if (cause < 0)
01114          f.data.uint32 = chan->hangupcause;
01115 
01116       ast_channel_unlock(chan);
01117    }
01118 
01119    return ast_queue_frame(chan, &f);
01120 }

int ast_raw_answer ( struct ast_channel chan,
int  cdr_answer 
)

Answer a channel.

Parameters:
chan channel to answer
cdr_answer flag to control whether any associated CDR should be marked as 'answered'

This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.
Unlike ast_answer(), this function will not wait for media flow to begin. The caller should be careful before sending media to the channel before incoming media arrives, as the outgoing media may be lost.
Return values:
0 on success
non-zero on failure

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

01800 {
01801    int res = 0;
01802 
01803    ast_channel_lock(chan);
01804 
01805    /* You can't answer an outbound call */
01806    if (ast_test_flag(chan, AST_FLAG_OUTGOING)) {
01807       ast_channel_unlock(chan);
01808       return 0;
01809    }
01810 
01811    /* Stop if we're a zombie or need a soft hangup */
01812    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
01813       ast_channel_unlock(chan);
01814       return -1;
01815    }
01816 
01817    ast_channel_unlock(chan);
01818 
01819    switch (chan->_state) {
01820    case AST_STATE_RINGING:
01821    case AST_STATE_RING:
01822       ast_channel_lock(chan);
01823       if (chan->tech->answer) {
01824          res = chan->tech->answer(chan);
01825       }
01826       ast_setstate(chan, AST_STATE_UP);
01827       if (cdr_answer) {
01828          ast_cdr_answer(chan->cdr);
01829       }
01830       ast_channel_unlock(chan);
01831       break;
01832    case AST_STATE_UP:
01833       /* Calling ast_cdr_answer when it it has previously been called
01834        * is essentially a no-op, so it is safe.
01835        */
01836       if (cdr_answer) {
01837          ast_cdr_answer(chan->cdr);
01838       }
01839       break;
01840    default:
01841       break;
01842    }
01843 
01844    ast_indicate(chan, -1);
01845    chan->visible_indication = 0;
01846 
01847    return res;
01848 }

struct ast_frame* ast_read ( struct ast_channel chan  )  [read]

Reads a frame.

Parameters:
chan channel to read a frame from
Returns:
Returns a frame, or NULL on error. If it returns NULL, you best just stop reading frames and assume the channel has been disconnected.

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

03101 {
03102    return __ast_read(chan, 0);
03103 }

static void ast_read_generator_actions ( struct ast_channel chan,
struct ast_frame f 
) [static]

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

02531 {
02532    if (chan->generator && chan->generator->generate && chan->generatordata &&  !ast_internal_timing_enabled(chan)) {
02533       void *tmp = chan->generatordata;
02534       int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = chan->generator->generate;
02535       int res;
02536       int samples;
02537 
02538       if (chan->timingfunc) {
02539          ast_debug(1, "Generator got voice, switching to phase locked mode\n");
02540          ast_settimeout(chan, 0, NULL, NULL);
02541       }
02542 
02543       chan->generatordata = NULL;     /* reset, to let writes go through */
02544 
02545       if (f->subclass != chan->writeformat) {
02546          float factor;
02547          factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass));
02548          samples = (int) ( ((float) f->samples) * factor );
02549       } else {
02550          samples = f->samples;
02551       }
02552       
02553       /* This unlock is here based on two assumptions that hold true at this point in the
02554        * code. 1) this function is only called from within __ast_read() and 2) all generators
02555        * call ast_write() in their generate callback.
02556        *
02557        * The reason this is added is so that when ast_write is called, the lock that occurs 
02558        * there will not recursively lock the channel. Doing this will cause intended deadlock 
02559        * avoidance not to work in deeper functions
02560        */
02561       ast_channel_unlock(chan);
02562       res = generate(chan, tmp, f->datalen, samples);
02563       ast_channel_lock(chan);
02564       chan->generatordata = tmp;
02565       if (res) {
02566          ast_debug(1, "Auto-deactivating generator\n");
02567          ast_deactivate_generator(chan);
02568       }
02569 
02570    } else if (f->frametype == AST_FRAME_CNG) {
02571       if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) {
02572          ast_debug(1, "Generator got CNG, switching to timed mode\n");
02573          ast_settimeout(chan, 50, generator_force, chan);
02574       }
02575    }
02576 }

struct ast_frame* ast_read_noaudio ( struct ast_channel chan  )  [read]

Reads a frame, returning AST_FRAME_NULL frame if audio.

Parameters:
chan channel to read a frame from
Returns:
Returns a frame, or NULL on error. If it returns NULL, you best just stop reading frames and assume the channel has been disconnected.
Note:
Audio is replaced with AST_FRAME_NULL to avoid transcode when the resulting audio is not necessary.

Definition at line 3105 of file channel.c.

References __ast_read().

Referenced by ast_bridge_handle_trip(), and conf_run().

03106 {
03107    return __ast_read(chan, 1);
03108 }

int ast_readstring ( struct ast_channel c,
char *  s,
int  len,
int  timeout,
int  rtimeout,
char *  enders 
)

Reads multiple digits

Parameters:
c channel to read from
s string to read in to. Must be at least the size of your length
len how many digits to read (maximum)
timeout how long to timeout between digits
rtimeout timeout to wait on the first digit
enders digits to end the string Read in a digit string "s", max length "len", maximum timeout between digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout for the first digit. Returns 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 4088 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().

04089 {
04090    return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
04091 }

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

References ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, AST_GETDATA_COMPLETE, AST_GETDATA_EMPTY_END_TERMINATED, AST_GETDATA_FAILED, AST_GETDATA_INTERRUPTED, AST_GETDATA_TIMEOUT, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), ast_waitstream_full(), and ast_channel::stream.

Referenced by ast_app_getdata_full(), and ast_readstring().

04094 {
04095    int pos = 0;   /* index in the buffer where we accumulate digits */
04096    int to = ftimeout;
04097 
04098    /* Stop if we're a zombie or need a soft hangup */
04099    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
04100       return -1;
04101    if (!len)
04102       return -1;
04103    for (;;) {
04104       int d;
04105       if (c->stream) {
04106          d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
04107          ast_stopstream(c);
04108          usleep(1000);
04109          if (!d)
04110             d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
04111       } else {
04112          d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
04113       }
04114       if (d < 0)
04115          return AST_GETDATA_FAILED;
04116       if (d == 0) {
04117          s[pos] = '\0';
04118          return AST_GETDATA_TIMEOUT;
04119       }
04120       if (d == 1) {
04121          s[pos] = '\0';
04122          return AST_GETDATA_INTERRUPTED;
04123       }
04124       if (strchr(enders, d) && (pos == 0)) {
04125          s[pos] = '\0';
04126          return AST_GETDATA_EMPTY_END_TERMINATED;
04127       }
04128       if (!strchr(enders, d)) {
04129          s[pos++] = d;
04130       }
04131       if (strchr(enders, d) || (pos >= len)) {
04132          s[pos] = '\0';
04133          return AST_GETDATA_COMPLETE;
04134       }
04135       to = timeout;
04136    }
04137    /* Never reached */
04138    return 0;
04139 }

int ast_recvchar ( struct ast_channel chan,
int  timeout 
)

Receives a text character from a channel.

Parameters:
chan channel to act upon
timeout timeout in milliseconds (0 for infinite wait) Read a char of text from a channel Returns 0 on success, -1 on failure

Definition at line 3264 of file channel.c.

References ast_free, and ast_recvtext().

Referenced by handle_recvchar().

03265 {
03266    int c;
03267    char *buf = ast_recvtext(chan, timeout);
03268    if (buf == NULL)
03269       return -1;  /* error or timeout */
03270    c = *(unsigned char *)buf;
03271    ast_free(buf);
03272    return c;
03273 }

char* ast_recvtext ( struct ast_channel chan,
int  timeout 
)

Receives a text string from a channel Read a string of text from a channel.

Parameters:
chan channel to act upon
timeout timeout in milliseconds (0 for infinite wait)
Returns:
the received text, or NULL to signify failure.

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

03276 {
03277    int res, done = 0;
03278    char *buf = NULL;
03279    
03280    while (!done) {
03281       struct ast_frame *f;
03282       if (ast_check_hangup(chan))
03283          break;
03284       res = ast_waitfor(chan, timeout);
03285       if (res <= 0) /* timeout or error */
03286          break;
03287       timeout = res; /* update timeout */
03288       f = ast_read(chan);
03289       if (f == NULL)
03290          break; /* no frame */
03291       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
03292          done = 1;   /* force a break */
03293       else if (f->frametype == AST_FRAME_TEXT) {      /* what we want */
03294          buf = ast_strndup((char *) f->data.ptr, f->datalen);  /* dup and break */
03295          done = 1;
03296       }
03297       ast_frfree(f);
03298    }
03299    return buf;
03300 }

struct ast_channel* ast_request ( const char *  type,
int  format,
void *  data,
int *  status 
) [read]

Requests a channel.

Parameters:
type type of channel to request
format requested channel format (codec)
data data to pass to the channel requester
status status

Request a channel of a given type, with data as optional information used by the low level module

Return values:
NULL failure
non-NULL channel on success

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

03987 {
03988    struct chanlist *chan;
03989    struct ast_channel *c;
03990    int capabilities;
03991    int fmt;
03992    int res;
03993    int foo;
03994    int videoformat = format & AST_FORMAT_VIDEO_MASK;
03995    int textformat = format & AST_FORMAT_TEXT_MASK;
03996 
03997    if (!cause)
03998       cause = &foo;
03999    *cause = AST_CAUSE_NOTDEFINED;
04000 
04001    if (AST_RWLIST_RDLOCK(&channels)) {
04002       ast_log(LOG_WARNING, "Unable to lock channel list\n");
04003       return NULL;
04004    }
04005 
04006    AST_LIST_TRAVERSE(&backends, chan, list) {
04007       if (strcasecmp(type, chan->tech->type))
04008          continue;
04009 
04010       capabilities = chan->tech->capabilities;
04011       fmt = format & AST_FORMAT_AUDIO_MASK;
04012       if (fmt) {
04013          /* We have audio - is it possible to connect the various calls to each other? 
04014             (Avoid this check for calls without audio, like text+video calls)
04015          */
04016          res = ast_translator_best_choice(&fmt, &capabilities);
04017          if (res < 0) {
04018             ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format);
04019             *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
04020             AST_RWLIST_UNLOCK(&channels);
04021             return NULL;
04022          }
04023       }
04024       AST_RWLIST_UNLOCK(&channels);
04025       if (!chan->tech->requester)
04026          return NULL;
04027       
04028       if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, data, cause)))
04029          return NULL;
04030       
04031       /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
04032       return c;
04033    }
04034 
04035    ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
04036    *cause = AST_CAUSE_NOSUCHDRIVER;
04037    AST_RWLIST_UNLOCK(&channels);
04038 
04039    return NULL;
04040 }

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.

Parameters:
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)
Returns:
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 3981 of file channel.c.

References __ast_request_and_dial().

Referenced by ast_pbx_outgoing_exten().

03982 {
03983    return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL);
03984 }

int ast_safe_sleep ( struct ast_channel chan,
int  ms 
)
int ast_safe_sleep_conditional ( struct ast_channel chan,
int  ms,
int(*)(void *)  cond,
void *  data 
)

Wait, look for hangups and condition arg.

Wait for a specified amount of time, looking for hangups and a condition argument.

Definition at line 1328 of file channel.c.

References ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_frfree, ast_opt_transmit_silence, ast_read(), ast_waitfor(), cond, f, and ast_channel::generatordata.

Referenced by ast_safe_sleep(), and login_exec().

01329 {
01330    struct ast_frame *f;
01331    struct ast_silence_generator *silgen = NULL;
01332    int res = 0;
01333 
01334    /* If no other generator is present, start silencegen while waiting */
01335    if (ast_opt_transmit_silence && !chan->generatordata) {
01336       silgen = ast_channel_start_silence_generator(chan);
01337    }
01338 
01339    while (ms > 0) {
01340       if (cond && ((*cond)(data) == 0)) {
01341          break;
01342       }
01343       ms = ast_waitfor(chan, ms);
01344       if (ms < 0) {
01345          res = -1;
01346          break;
01347       }
01348       if (ms > 0) {
01349          f = ast_read(chan);
01350          if (!f) {
01351             res = -1;
01352             break;
01353          }
01354          ast_frfree(f);
01355       }
01356    }
01357 
01358    /* stop silgen if present */
01359    if (silgen) {
01360       ast_channel_stop_silence_generator(chan, silgen);
01361    }
01362 
01363    return res;
01364 }

int ast_say_character_str ( struct ast_channel chan,
const char *  str,
const char *  ints,
const char *  lang 
)

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

05841 {
05842    return ast_say_character_str_full(chan, str, ints, lang, -1, -1);
05843 }

int ast_say_digit_str ( struct ast_channel chan,
const char *  num,
const char *  ints,
const char *  lang 
)

says digits of a string

Parameters:
chan channel to act upon
num string to speak
ints which dtmf to interrupt on
lang language to speak in

Vocally says the digits of a given string

Return values:
0 on succes
DTMF if interrupted
-1 on failure

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

05835 {
05836    return ast_say_digit_str_full(chan, str, ints, lang, -1, -1);
05837 }

int ast_say_digits ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang 
)

says digits

Parameters:
chan channel to act upon
num number to speak
ints which dtmf to interrupt on
lang language to speak

Vocally says digits of a given number

Return values:
0 on success
DTMF if interrupted
-1 on failure

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

05829 {
05830    return ast_say_digits_full(chan, num, ints, lang, -1, -1);
05831 }

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 *  lang,
const char *  options 
)

says an enumeration

Parameters:
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

Vocally says an enumeration on a given channel (first, sencond, third, forth, thirtyfirst, hundredth, ....) Especially useful for dates and messages. Says 'last' if num equals to INT_MAX

Return values:
0 on success
DTMF digit on interrupt
-1 on failure

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

05823 {
05824    return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1);
05825 }

int ast_say_number ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang,
const char *  options 
)

says a number

Parameters:
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

Vocally says a number on a given channel

Return values:
0 on success
DTMF digit on interrupt
-1 on failure

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

05817 {
05818    return ast_say_number_full(chan, num, ints, language, options, -1, -1);
05819 }

int ast_say_phonetic_str ( struct ast_channel chan,
const char *  str,
const char *  ints,
const char *  lang 
)

Definition at line 5845 of file channel.c.

References ast_say_phonetic_str_full.

Referenced by pbx_builtin_sayphonetic().

05847 {
05848    return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1);
05849 }

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.

Parameters:
chan channel to act upon
digit the DTMF digit to send, encoded in ASCII
duration the duration of the digit ending in ms
Returns:
Returns 0 on success, -1 on failure

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

03374 {
03375    if (chan->tech->send_digit_begin) {
03376       ast_senddigit_begin(chan, digit);
03377       ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
03378    }
03379    
03380    return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
03381 }

int ast_senddigit_begin ( struct ast_channel chan,
char  digit 
)

Send a DTMF digit to a channel Send a DTMF digit to a channel.

Parameters:
chan channel to act upon
digit the DTMF digit to send, encoded in ASCII
Returns:
Returns 0 on success, -1 on failure

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

03316 {
03317    /* Device does not support DTMF tones, lets fake
03318     * it by doing our own generation. */
03319    static const char* dtmf_tones[] = {
03320       "941+1336", /* 0 */
03321       "697+1209", /* 1 */
03322       "697+1336", /* 2 */
03323       "697+1477", /* 3 */
03324       "770+1209", /* 4 */
03325       "770+1336", /* 5 */
03326       "770+1477", /* 6 */
03327       "852+1209", /* 7 */
03328       "852+1336", /* 8 */
03329       "852+1477", /* 9 */
03330       "697+1633", /* A */
03331       "770+1633", /* B */
03332       "852+1633", /* C */
03333       "941+1633", /* D */
03334       "941+1209", /* * */
03335       "941+1477"  /* # */
03336    };
03337 
03338    if (!chan->tech->send_digit_begin)
03339       return 0;
03340 
03341    if (!chan->tech->send_digit_begin(chan, digit))
03342       return 0;
03343 
03344    if (digit >= '0' && digit <='9')
03345       ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
03346    else if (digit >= 'A' && digit <= 'D')
03347       ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
03348    else if (digit == '*')
03349       ast_playtones_start(chan, 0, dtmf_tones[14], 0);
03350    else if (digit == '#')
03351       ast_playtones_start(chan, 0, dtmf_tones[15], 0);
03352    else {
03353       /* not handled */
03354       ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name);
03355    }
03356 
03357    return 0;
03358 }

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.

Parameters:
chan channel to act upon
digit the DTMF digit to send, encoded in ASCII
duration the duration of the digit ending in ms
Returns:
Returns 0 on success, -1 on failure

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

03361 {
03362    int res = -1;
03363 
03364    if (chan->tech->send_digit_end)
03365       res = chan->tech->send_digit_end(chan, digit, duration);
03366 
03367    if (res && chan->generator)
03368       ast_playtones_stop(chan);
03369    
03370    return 0;
03371 }

int ast_sendtext ( struct ast_channel chan,
const char *  text 
)

Sends text to a channel.

Parameters:
chan channel to act upon
text string of text to send on the channel

Write text to a display on a channel

Note:
The channel does not need to be locked before calling this function.
Return values:
0 on success
-1 on failure

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

03303 {
03304    int res = 0;
03305    /* Stop if we're a zombie or need a soft hangup */
03306    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
03307       return -1;
03308    CHECK_BLOCKING(chan);
03309    if (chan->tech->send_text)
03310       res = chan->tech->send_text(chan, text);
03311    ast_clear_flag(chan, AST_FLAG_BLOCKING);
03312    return res;
03313 }

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.

Note:
The channel does not need to be locked before calling this function.

Definition at line 4670 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, and report_new_callerid().

Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), 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().

04671 {
04672    ast_channel_lock(chan);
04673 
04674    if (cid_num) {
04675       if (chan->cid.cid_num)
04676          ast_free(chan->cid.cid_num);
04677       chan->cid.cid_num = ast_strdup(cid_num);
04678    }
04679    if (cid_name) {
04680       if (chan->cid.cid_name)
04681          ast_free(chan->cid.cid_name);
04682       chan->cid.cid_name = ast_strdup(cid_name);
04683    }
04684    if (cid_ani) {
04685       if (chan->cid.cid_ani)
04686          ast_free(chan->cid.cid_ani);
04687       chan->cid.cid_ani = ast_strdup(cid_ani);
04688    }
04689 
04690    report_new_callerid(chan);
04691 
04692    ast_channel_unlock(chan);
04693 }

int ast_set_read_format ( struct ast_channel chan,
int  format 
)
void ast_set_variables ( struct ast_channel chan,
struct ast_variable vars 
)

adds a list of channel variables to a channel

Parameters:
chan the channel
vars a linked list of variables

Variable names can be for a regular channel variable or a dialplan function that has the ability to be written to.

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

05593 {
05594    struct ast_variable *cur;
05595 
05596    for (cur = vars; cur; cur = cur->next)
05597       pbx_builtin_setvar_helper(chan, cur->name, cur->value);  
05598 }

int ast_set_write_format ( struct ast_channel chan,
int  format 
)
int ast_setstate ( struct ast_channel chan,
enum ast_channel_state  state 
)

Change the state of a channel.

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

04696 {
04697    int oldstate = chan->_state;
04698    char name[AST_CHANNEL_NAME], *dashptr;
04699 
04700    if (oldstate == state)
04701       return 0;
04702 
04703    ast_copy_string(name, chan->name, sizeof(name));
04704    if ((dashptr = strrchr(name, '-'))) {
04705       *dashptr = '\0';
04706    }
04707 
04708    chan->_state = state;
04709 
04710    /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver
04711     * for this channel is using the callback method for device state. If we pass in an actual state here
04712     * we override what they are saying the state is and things go amuck. */
04713    ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name);
04714 
04715    /* setstate used to conditionally report Newchannel; this is no more */
04716    manager_event(EVENT_FLAG_CALL,
04717             "Newstate",
04718             "Channel: %s\r\n"
04719             "ChannelState: %d\r\n"
04720             "ChannelStateDesc: %s\r\n"
04721             "CallerIDNum: %s\r\n"
04722             "CallerIDName: %s\r\n"
04723             "Uniqueid: %s\r\n",
04724             chan->name, chan->_state, ast_state2str(chan->_state),
04725             S_OR(chan->cid.cid_num, ""),
04726             S_OR(chan->cid.cid_name, ""),
04727             chan->uniqueid);
04728 
04729    return 0;
04730 }

int ast_settimeout ( struct ast_channel c,
unsigned int  rate,
int(*)(const void *data)  func,
void *  data 
)

Enable or disable timer ticks for a channel.

Parameters:
rate number of timer ticks per second

If timers are supported, force a scheduled expiration on the timer fd, at which point we call the callback function / data

Call this function with a rate of 0 to turn off the timer ticks

Version:
1.6.1 changed samples parameter to rate, accomodates new timing methods

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

02406 {
02407    int res;
02408    unsigned int real_rate = rate, max_rate;
02409 
02410    ast_channel_lock(c);
02411 
02412    if (c->timingfd == -1) {
02413       ast_channel_unlock(c);
02414       return -1;
02415    }
02416 
02417    if (!func) {
02418       rate = 0;
02419       data = NULL;
02420    }
02421 
02422    if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) {
02423       real_rate = max_rate;
02424    }
02425 
02426    ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate);
02427 
02428    res = ast_timer_set_rate(c->timer, real_rate);
02429 
02430    c->timingfunc = func;
02431    c->timingdata = data;
02432 
02433    ast_channel_unlock(c);
02434 
02435    return res;
02436 }

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

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

Referenced by ast_async_goto(), ast_softhangup(), attempt_transfer(), check_rtp_timeout(), dahdi_softhangup_all(), oh323_indicate(), proc_session_timer(), sip_indicate(), and skinny_indicate().

01654 {
01655    ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name);
01656    /* Inform channel driver that we need to be hung up, if it cares */
01657    chan->_softhangup |= cause;
01658    ast_queue_frame(chan, &ast_null_frame);
01659    /* Interrupt any poll call or such */
01660    if (ast_test_flag(chan, AST_FLAG_BLOCKING))
01661       pthread_kill(chan->blocker, SIGURG);
01662    return 0;
01663 }

const char* ast_state2str ( enum ast_channel_state  state  ) 

Gives the string form of a given channel state.

Note:
This function is not reentrant.

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

Parameters:
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 5467 of file channel.c.

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

Referenced by zapateller_exec().

05468 {
05469    int res;
05470 
05471    if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
05472       return res;
05473 
05474    /* Give us some wiggle room */
05475    while (chan->generatordata && ast_waitfor(chan, 100) >= 0) {
05476       struct ast_frame *f = ast_read(chan);
05477       if (f)
05478          ast_frfree(f);
05479       else
05480          return -1;
05481    }
05482    return 0;
05483 }

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

Start a tone going

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

05450 {
05451    struct tonepair_def d = { 0, };
05452 
05453    d.freq1 = freq1;
05454    d.freq2 = freq2;
05455    d.duration = duration;
05456    d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
05457    if (ast_activate_generator(chan, &tonepair, &d))
05458       return -1;
05459    return 0;
05460 }

void ast_tonepair_stop ( struct ast_channel chan  ) 

Stop a tone from playing

Definition at line 5462 of file channel.c.

References ast_deactivate_generator().

Referenced by sendnoise().

05463 {
05464    ast_deactivate_generator(chan);
05465 }

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:

  • app_transfer
  • the manager interface

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

04071 {
04072    int res = -1;
04073 
04074    /* Stop if we're a zombie or need a soft hangup */
04075    ast_channel_lock(chan);
04076    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
04077       if (chan->tech->transfer) {
04078          res = chan->tech->transfer(chan, dest);
04079          if (!res)
04080             res = 1;
04081       } else
04082          res = 0;
04083    }
04084    ast_channel_unlock(chan);
04085    return res;
04086 }

char* ast_transfercapability2str ( int  transfercapability  )  const

Gives the string form of a given transfer capability.

Gives the string form of a given transfer capability

Parameters:
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 5530 of file channel.c.

References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.

Referenced by unload_module().

05531 {
05532    ast_moh_start_ptr = NULL;
05533    ast_moh_stop_ptr = NULL;
05534    ast_moh_cleanup_ptr = NULL;
05535 }

int ast_waitfor ( struct ast_channel chan,
int  ms 
)

Wait for input on a channel.

Parameters:
chan channel to wait on
ms length of time to wait on the channel Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
Returns:
Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise

Definition at line 2389 of file channel.c.

References ast_waitfor_nandfds().

Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), ast_dtmf_stream(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), async_wait(), background_detect_exec(), channel_spy(), conf_exec(), conf_flush(), dictate_exec(), disa_exec(), do_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().

02390 {
02391    int oldms = ms;   /* -1 if no timeout */
02392 
02393    ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
02394    if ((ms < 0) && (oldms < 0))
02395       ms = 0;
02396    return ms;
02397 }

struct ast_channel* ast_waitfor_n ( struct ast_channel **  chan,
int  n,
int *  ms 
) [read]

Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.

Returns:
Return channel with activity, or NULL if none has activity.
Parameters:
chan an array of pointers to channels
n number of channels that are to be waited upon
ms time "ms" is modified in-place, if applicable

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

02385 {
02386    return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
02387 }

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

References ast_waitfor_nandfds().

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

02030 {
02031    int winner = -1;
02032    ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
02033    return winner;
02034 }

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

02044 {
02045    struct timeval start = { 0 , 0 };
02046    struct pollfd *pfds = NULL;
02047    int res;
02048    long rms;
02049    int x, y, max;
02050    int sz;
02051    struct timeval now = { 0, 0 };
02052    struct timeval whentohangup = { 0, 0 }, diff;
02053    struct ast_channel *winner = NULL;
02054    struct fdmap {
02055       int chan;
02056       int fdno;
02057    } *fdmap = NULL;
02058 
02059    if ((sz = n * AST_MAX_FDS + nfds)) {
02060       pfds = alloca(sizeof(*pfds) * sz);
02061       fdmap = alloca(sizeof(*fdmap) * sz);
02062    }
02063 
02064    if (outfd)
02065       *outfd = -99999;
02066    if (exception)
02067       *exception = 0;
02068    
02069    /* Perform any pending masquerades */
02070    for (x = 0; x < n; x++) {
02071       ast_channel_lock(c[x]);
02072       if (c[x]->masq && ast_do_masquerade(c[x])) {
02073          ast_log(LOG_WARNING, "Masquerade failed\n");
02074          *ms = -1;
02075          ast_channel_unlock(c[x]);
02076          return NULL;
02077       }
02078       if (!ast_tvzero(c[x]->whentohangup)) {
02079          if (ast_tvzero(whentohangup))
02080             now = ast_tvnow();
02081          diff = ast_tvsub(c[x]->whentohangup, now);
02082          if (diff.tv_sec < 0 || ast_tvzero(diff)) {
02083             /* Should already be hungup */
02084             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
02085             ast_channel_unlock(c[x]);
02086             return c[x];
02087          }
02088          if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0)
02089             whentohangup = diff;
02090       }
02091       ast_channel_unlock(c[x]);
02092    }
02093    /* Wait full interval */
02094    rms = *ms;
02095    if (!ast_tvzero(whentohangup)) {
02096       rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000;              /* timeout in milliseconds */
02097       if (*ms >= 0 && *ms < rms)    /* original *ms still smaller */
02098          rms =  *ms;
02099    }
02100    /*
02101     * Build the pollfd array, putting the channels' fds first,
02102     * followed by individual fds. Order is important because
02103     * individual fd's must have priority over channel fds.
02104     */
02105    max = 0;
02106    for (x = 0; x < n; x++) {
02107       for (y = 0; y < AST_MAX_FDS; y++) {
02108          fdmap[max].fdno = y;  /* fd y is linked to this pfds */
02109          fdmap[max].chan = x;  /* channel x is linked to this pfds */
02110          max += ast_add_fd(&pfds[max], c[x]->fds[y]);
02111       }
02112       CHECK_BLOCKING(c[x]);
02113    }
02114    /* Add the individual fds */
02115    for (x = 0; x < nfds; x++) {
02116       fdmap[max].chan = -1;
02117       max += ast_add_fd(&pfds[max], fds[x]);
02118    }
02119 
02120    if (*ms > 0)
02121       start = ast_tvnow();
02122    
02123    if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
02124       do {
02125          int kbrms = rms;
02126          if (kbrms > 600000)
02127             kbrms = 600000;
02128          res = ast_poll(pfds, max, kbrms);
02129          if (!res)
02130             rms -= kbrms;
02131       } while (!res && (rms > 0));
02132    } else {
02133       res = ast_poll(pfds, max, rms);
02134    }
02135    for (x = 0; x < n; x++)
02136       ast_clear_flag(c[x], AST_FLAG_BLOCKING);
02137    if (res < 0) { /* Simulate a timeout if we were interrupted */
02138       if (errno != EINTR)
02139          *ms = -1;
02140       return NULL;
02141    }
02142    if (!ast_tvzero(whentohangup)) {   /* if we have a timeout, check who expired */
02143       now = ast_tvnow();
02144       for (x = 0; x < n; x++) {
02145          if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) {
02146             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
02147             if (winner == NULL)
02148                winner = c[x];
02149          }
02150       }
02151    }
02152    if (res == 0) { /* no fd ready, reset timeout and done */
02153       *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
02154       return winner;
02155    }
02156    /*
02157     * Then check if any channel or fd has a pending event.
02158     * Remember to check channels first and fds last, as they
02159     * must have priority on setting 'winner'
02160     */
02161    for (x = 0; x < max; x++) {
02162       res = pfds[x].revents;
02163       if (res == 0)
02164          continue;
02165       if (fdmap[x].chan >= 0) {  /* this is a channel */
02166          winner = c[fdmap[x].chan]; /* override previous winners */
02167          if (res & POLLPRI)
02168             ast_set_flag(winner, AST_FLAG_EXCEPTION);
02169          else
02170             ast_clear_flag(winner, AST_FLAG_EXCEPTION);
02171          winner->fdno = fdmap[x].fdno;
02172       } else {       /* this is an fd */
02173          if (outfd)
02174             *outfd = pfds[x].fd;
02175          if (exception)
02176             *exception = (res & POLLPRI) ? -1 : 0;
02177          winner = NULL;
02178       }
02179    }
02180    if (*ms > 0) {
02181       *ms -= ast_tvdiff_ms(ast_tvnow(), start);
02182       if (*ms < 0)
02183          *ms = 0;
02184    }
02185    return winner;
02186 }

int ast_waitfordigit ( struct ast_channel c,
int  ms 
)
int ast_waitfordigit_full ( struct ast_channel c,
int  ms,
int  audiofd,
int  ctrlfd 
)

Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.

Parameters:
c channel to wait for a digit on
ms how many milliseconds to wait
audiofd audio file descriptor to write to if audio frames are received
ctrlfd control file descriptor to monitor for reading
Returns:
Returns 1 if ctrlfd becomes available

Definition at line 2438 of file channel.c.

References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_set_flag, ast_test_flag, ast_waitfor_nandfds(), 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().

02439 {
02440    /* Stop if we're a zombie or need a soft hangup */
02441    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
02442       return -1;
02443 
02444    /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
02445    ast_set_flag(c, AST_FLAG_END_DTMF_ONLY);
02446 
02447    /* Wait for a digit, no more than ms milliseconds total. */
02448    
02449    while (ms) {
02450       struct ast_channel *rchan;
02451       int outfd=-1;
02452 
02453       errno = 0;
02454       rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
02455       
02456       if (!rchan && outfd < 0 && ms) {
02457          if (errno == 0 || errno == EINTR)
02458             continue;
02459          ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
02460          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02461          return -1;
02462       } else if (outfd > -1) {
02463          /* The FD we were watching has something waiting */
02464          ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n");
02465          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02466          return 1;
02467       } else if (rchan) {
02468          int res;
02469          struct ast_frame *f = ast_read(c);
02470          if (!f)
02471             return -1;
02472 
02473          switch (f->frametype) {
02474          case AST_FRAME_DTMF_BEGIN:
02475             break;
02476          case AST_FRAME_DTMF_END:
02477             res = f->subclass;
02478             ast_frfree(f);
02479             ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02480             return res;
02481          case AST_FRAME_CONTROL:
02482             switch (f->subclass) {
02483             case AST_CONTROL_HANGUP:
02484                ast_frfree(f);
02485                ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02486                return -1;
02487             case AST_CONTROL_RINGING:
02488             case AST_CONTROL_ANSWER:
02489             case AST_CONTROL_SRCUPDATE:
02490                /* Unimportant */
02491                break;
02492             default:
02493                ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass);
02494                break;
02495             }
02496             break;
02497          case AST_FRAME_VOICE:
02498             /* Write audio if appropriate */
02499             if (audiofd > -1) {
02500                if (write(audiofd, f->data.ptr, f->datalen) < 0) {
02501                   ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
02502                }
02503             }
02504          default:
02505             /* Ignore */
02506             break;
02507          }
02508          ast_frfree(f);
02509       }
02510    }
02511 
02512    ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02513 
02514    return 0; /* Time is up */
02515 }

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

References channel_find_locked().

Referenced by next_channel().

01305 {
01306    return channel_find_locked(chan, NULL, 0, context, exten);
01307 }

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

References channel_find_locked().

Referenced by my_ast_get_channel_by_name_locked(), next_channel(), and softhangup_exec().

01292 {
01293    return channel_find_locked(chan, name, namelen, NULL, NULL);
01294 }

int ast_write ( struct ast_channel chan,
struct ast_frame frame 
)

Write a frame to a channel This function writes the given frame to the indicated channel.

Parameters:
chan destination channel of the frame
frame frame that will be written
Returns:
It returns 0 on success, -1 on failure.

Todo:
XXX should return 0 maybe ?

Definition at line 3411 of file channel.c.

References ast_channel::_softhangup, AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_deactivate_generator(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, ast_format_rate(), 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_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, ast_frame::frame_list, 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_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().

03412 {
03413    int res = -1;
03414    struct ast_frame *f = NULL;
03415    int count = 0;
03416 
03417    /*Deadlock avoidance*/
03418    while(ast_channel_trylock(chan)) {
03419       /*cannot goto done since the channel is not locked*/
03420       if(count++ > 10) {
03421          ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name);
03422          return 0;
03423       }
03424       usleep(1);
03425    }
03426    /* Stop if we're a zombie or need a soft hangup */
03427    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
03428       goto done;
03429 
03430    /* Handle any pending masquerades */
03431    if (chan->masq && ast_do_masquerade(chan)) {
03432       ast_log(LOG_WARNING, "Failed to perform masquerade\n");
03433       goto done;
03434    }
03435    if (chan->masqr) {
03436       res = 0; /* XXX explain, why 0 ? */
03437       goto done;
03438    }
03439    if (chan->generatordata) {
03440       if (ast_test_flag(chan, AST_FLAG_WRITE_INT))
03441          ast_deactivate_generator(chan);
03442       else {
03443          if (fr->frametype == AST_FRAME_DTMF_END) {
03444             /* There is a generator running while we're in the middle of a digit.
03445              * It's probably inband DTMF, so go ahead and pass it so it can
03446              * stop the generator */
03447             ast_clear_flag(chan, AST_FLAG_BLOCKING);
03448             ast_channel_unlock(chan);
03449             res = ast_senddigit_end(chan, fr->subclass, fr->len);
03450             ast_channel_lock(chan);
03451             CHECK_BLOCKING(chan);
03452          } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) {
03453             /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */
03454             res = (chan->tech->indicate == NULL) ? 0 :
03455                chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen);
03456          }
03457          res = 0; /* XXX explain, why 0 ? */
03458          goto done;
03459       }
03460    }
03461    /* High bit prints debugging */
03462    if (chan->fout & DEBUGCHAN_FLAG)
03463       ast_frame_dump(chan->name, fr, ">>");
03464    CHECK_BLOCKING(chan);
03465    switch (fr->frametype) {
03466    case AST_FRAME_CONTROL:
03467       res = (chan->tech->indicate == NULL) ? 0 :
03468          chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen);
03469       break;
03470    case AST_FRAME_DTMF_BEGIN:
03471       if (chan->audiohooks) {
03472          struct ast_frame *old_frame = fr;
03473          fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
03474          if (old_frame != fr)
03475             f = fr;
03476       }
03477       send_dtmf_event(chan, "Sent", fr->subclass, "Yes", "No");
03478       ast_clear_flag(chan, AST_FLAG_BLOCKING);
03479       ast_channel_unlock(chan);
03480       res = ast_senddigit_begin(chan, fr->subclass);
03481       ast_channel_lock(chan);
03482       CHECK_BLOCKING(chan);
03483       break;
03484    case AST_FRAME_DTMF_END:
03485       if (chan->audiohooks) {
03486          struct ast_frame *new_frame = fr;
03487 
03488          new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
03489          if (new_frame != fr) {
03490             ast_frfree(new_frame);
03491          }
03492       }
03493       send_dtmf_event(chan, "Sent", fr->subclass, "No", "Yes");
03494       ast_clear_flag(chan, AST_FLAG_BLOCKING);
03495       ast_channel_unlock(chan);
03496       res = ast_senddigit_end(chan, fr->subclass, fr->len);
03497       ast_channel_lock(chan);
03498       CHECK_BLOCKING(chan);
03499       break;
03500    case AST_FRAME_TEXT:
03501       if (fr->subclass == AST_FORMAT_T140) {
03502          res = (chan->tech->write_text == NULL) ? 0 :
03503             chan->tech->write_text(chan, fr);
03504       } else {
03505          res = (chan->tech->send_text == NULL) ? 0 :
03506             chan->tech->send_text(chan, (char *) fr->data.ptr);
03507       }
03508       break;
03509    case AST_FRAME_HTML:
03510       res = (chan->tech->send_html == NULL) ? 0 :
03511          chan->tech->send_html(chan, fr->subclass, (char *) fr->data.ptr, fr->datalen);
03512       break;
03513    case AST_FRAME_VIDEO:
03514       /* XXX Handle translation of video codecs one day XXX */
03515       res = (chan->tech->write_video == NULL) ? 0 :
03516          chan->tech->write_video(chan, fr);
03517       break;
03518    case AST_FRAME_MODEM:
03519       res = (chan->tech->write == NULL) ? 0 :
03520          chan->tech->write(chan, fr);
03521       break;
03522    case AST_FRAME_VOICE:
03523       if (chan->tech->write == NULL)
03524          break;   /*! \todo XXX should return 0 maybe ? */
03525 
03526       /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
03527       if (fr->subclass == chan->rawwriteformat)
03528          f = fr;
03529       else
03530          f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
03531 
03532       if (!f) {
03533          res = 0;
03534          break;
03535       }
03536 
03537       if (chan->audiohooks) {
03538          struct ast_frame *prev = NULL, *new_frame, *cur, *dup;
03539          int freeoldlist = 0;
03540 
03541          if (f != fr) {
03542             freeoldlist = 1;
03543          }
03544 
03545          /* Since ast_audiohook_write may return a new frame, and the cur frame is
03546           * an item in a list of frames, create a new list adding each cur frame back to it
03547           * regardless if the cur frame changes or not. */
03548          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
03549             new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur);
03550 
03551             /* if this frame is different than cur, preserve the end of the list,
03552              * free the old frames, and set cur to be the new frame */
03553             if (new_frame != cur) {
03554 
03555                /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame
03556                 * isn't part of local storage, meaning if ast_audiohook_write is called multiple
03557                 * times it may override the previous frame we got from it unless we dup it */
03558                if ((dup = ast_frisolate(new_frame))) {
03559                   AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list);
03560                   if (freeoldlist) {
03561                      AST_LIST_NEXT(cur, frame_list) = NULL;
03562                      ast_frfree(cur);
03563                   }
03564                   cur = dup;
03565                }
03566             }
03567 
03568             /* now, regardless if cur is new or not, add it to the new list,
03569              * if the new list has not started, cur will become the first item. */
03570             if (prev) {
03571                AST_LIST_NEXT(prev, frame_list) = cur;
03572             } else {
03573                f = cur; /* set f to be the beginning of our new list */
03574             }
03575             prev = cur;
03576          }
03577       }
03578       
03579       /* If Monitor is running on this channel, then we have to write frames out there too */
03580       /* the translator on chan->writetrans may have returned multiple frames
03581          from the single frame we passed in; if so, feed each one of them to the
03582          monitor */
03583       if (chan->monitor && chan->monitor->write_stream) {
03584          struct ast_frame *cur;
03585 
03586          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
03587          /* XXX must explain this code */
03588 #ifndef MONITOR_CONSTANT_DELAY
03589             int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples;
03590             if (jump >= 0) {
03591                jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format));
03592                if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
03593                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
03594                chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples;
03595             } else {
03596                chan->outsmpl += cur->samples;
03597             }
03598 #else
03599             int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format));
03600             if (jump - MONITOR_DELAY >= 0) {
03601                if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1)
03602                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
03603                chan->outsmpl += chan->insmpl - chan->outsmpl;
03604             } else {
03605                chan->outsmpl += cur->samples;
03606             }
03607 #endif
03608             if (chan->monitor->state == AST_MONITOR_RUNNING) {
03609                if (ast_writestream(chan->monitor->write_stream, cur) < 0)
03610                   ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
03611             }
03612          }
03613       }
03614 
03615       /* the translator on chan->writetrans may have returned multiple frames
03616          from the single frame we passed in; if so, feed each one of them to the
03617          channel, freeing each one after it has been written */
03618       if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
03619          struct ast_frame *cur, *next;
03620          unsigned int skip = 0;
03621 
03622          for (cur = f, next = AST_LIST_NEXT(cur, frame_list);
03623               cur;
03624               cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) {
03625             if (!skip) {
03626                if ((res = chan->tech->write(chan, cur)) < 0) {
03627                   chan->_softhangup |= AST_SOFTHANGUP_DEV;
03628                   skip = 1;
03629                } else if (next) {
03630                   /* don't do this for the last frame in the list,
03631                      as the code outside the loop will do it once
03632                   */
03633                   chan->fout = FRAMECOUNT_INC(chan->fout);
03634                }
03635             }
03636             ast_frfree(cur);
03637          }
03638 
03639          /* reset f so the code below doesn't attempt to free it */
03640          f = NULL;
03641       } else {
03642          res = chan->tech->write(chan, f);
03643       }
03644       break;
03645    case AST_FRAME_NULL:
03646    case AST_FRAME_IAX:
03647       /* Ignore these */
03648       res = 0;
03649       break;
03650    default:
03651       /* At this point, fr is the incoming frame and f is NULL.  Channels do
03652        * not expect to get NULL as a frame pointer and will segfault.  Hence,
03653        * we output the original frame passed in. */
03654       res = chan->tech->write(chan, fr);
03655       break;
03656    }
03657 
03658    if (f && f != fr)
03659       ast_frfree(f);
03660    ast_clear_flag(chan, AST_FLAG_BLOCKING);
03661 
03662    /* Consider a write failure to force a soft hangup */
03663    if (res < 0) {
03664       chan->_softhangup |= AST_SOFTHANGUP_DEV;
03665    } else {
03666       chan->fout = FRAMECOUNT_INC(chan->fout);
03667    }
03668 done:
03669    ast_channel_unlock(chan);
03670    return res;
03671 }

int ast_write_video ( struct ast_channel chan,
struct ast_frame frame 
)

Write video frame to a channel This function writes the given frame to the indicated channel.

Parameters:
chan destination channel of the frame
frame frame that will be written
Returns:
It returns 1 on success, 0 if not implemented, and -1 on failure.

Definition at line 3400 of file channel.c.

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

03401 {
03402    int res;
03403    if (!chan->tech->write_video)
03404       return 0;
03405    res = ast_write(chan, fr);
03406    if (!res)
03407       res = 1;
03408    return res;
03409 }

static void bridge_play_sounds ( struct ast_channel c0,
struct ast_channel c1 
) [static]

Definition at line 5027 of file channel.c.

References ast_channel_lock, ast_channel_unlock, bridge_playfile(), pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and s.

Referenced by ast_channel_bridge().

05028 {
05029    const char *s, *sound;
05030 
05031    /* See if we need to play an audio file to any side of the bridge */
05032 
05033    ast_channel_lock(c0);
05034    if ((s = pbx_builtin_getvar_helper(c0, "BRIDGE_PLAY_SOUND"))) {
05035       sound = ast_strdupa(s);
05036       ast_channel_unlock(c0);
05037       bridge_playfile(c0, c1, sound, 0);
05038       pbx_builtin_setvar_helper(c0, "BRIDGE_PLAY_SOUND", NULL);
05039    } else {
05040       ast_channel_unlock(c0);
05041    }
05042 
05043    ast_channel_lock(c1);
05044    if ((s = pbx_builtin_getvar_helper(c1, "BRIDGE_PLAY_SOUND"))) {
05045       sound = ast_strdupa(s);
05046       ast_channel_unlock(c1);
05047       bridge_playfile(c1, c0, sound, 0);
05048       pbx_builtin_setvar_helper(c1, "BRIDGE_PLAY_SOUND", NULL);
05049    } else {
05050       ast_channel_unlock(c1);
05051    }
05052 }

static void bridge_playfile ( struct ast_channel chan,
struct ast_channel peer,
const char *  sound,
int  remain 
) [static]

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

04743 {
04744    int min = 0, sec = 0, check;
04745 
04746    check = ast_autoservice_start(peer);
04747    if (check)
04748       return;
04749 
04750    if (remain > 0) {
04751       if (remain / 60 > 1) {
04752          min = remain / 60;
04753          sec = remain % 60;
04754       } else {
04755          sec = remain;
04756       }
04757    }
04758    
04759    if (!strcmp(sound,"timeleft")) { /* Queue support */
04760       ast_stream_and_wait(chan, "vm-youhave", "");
04761       if (min) {
04762          ast_say_number(chan, min, AST_DIGIT_ANY, chan->language, NULL);
04763          ast_stream_and_wait(chan, "queue-minutes", "");
04764       }
04765       if (sec) {
04766          ast_say_number(chan, sec, AST_DIGIT_ANY, chan->language, NULL);
04767          ast_stream_and_wait(chan, "queue-seconds", "");
04768       }
04769    } else {
04770       ast_stream_and_wait(chan, sound, "");
04771    }
04772 
04773    ast_autoservice_stop(peer);
04774 }

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.

Note:
When using ast_seekstream() with the read and write streams of a monitor, the number of samples to seek forward must be of the same sample rate as the stream or else the jump will not be calculated correctly.
Return values:
number of samples to seek forward after rate conversion.

Definition at line 2623 of file channel.c.

Referenced by __ast_read(), and ast_write().

02624 {
02625    int diff = sample_rate - seek_rate;
02626 
02627    if (diff > 0) {
02628       samples = samples / (float) (sample_rate / seek_rate);
02629    } else if (diff < 0) {
02630       samples = samples * (float) (seek_rate / sample_rate);
02631    }
02632 
02633    return samples;
02634 }

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.

Note:
XXX Note that this code has cost O(N) because of the need to verify that the object is still on the global list.
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.

Note:
We're done searching through the list for the previous item. Any item after this point, we want to evaluate for a match. If we didn't set prev to NULL here, then we would only return matches for the first matching item (since the above "if (c != prev)" would not permit any other potential matches to reach the additional matching logic, below). Instead, it would just iterate until it once again found the original match, then iterate down to the end of the list and quit.

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

01191 {
01192    const char *msg = prev ? "deadlock" : "initial deadlock";
01193    int retries;
01194    struct ast_channel *c;
01195    const struct ast_channel *_prev = prev;
01196 
01197    for (retries = 0; retries < 200; retries++) {
01198       int done;
01199       /* Reset prev on each retry.  See note below for the reason. */
01200       prev = _prev;
01201       AST_RWLIST_RDLOCK(&channels);
01202       AST_RWLIST_TRAVERSE(&channels, c, chan_list) {
01203          if (prev) { /* look for last item, first, before any evaluation */
01204             if (c != prev) /* not this one */
01205                continue;
01206             /* found, prepare to return c->next */
01207             if ((c = AST_RWLIST_NEXT(c, chan_list)) == NULL) break;
01208             /*!\note
01209              * We're done searching through the list for the previous item.
01210              * Any item after this point, we want to evaluate for a match.
01211              * If we didn't set prev to NULL here, then we would only
01212              * return matches for the first matching item (since the above
01213              * "if (c != prev)" would not permit any other potential
01214              * matches to reach the additional matching logic, below).
01215              * Instead, it would just iterate until it once again found the
01216              * original match, then iterate down to the end of the list and
01217              * quit.
01218              */
01219             prev = NULL;
01220          }
01221          if (name) { /* want match by name */
01222             if ((!namelen && strcasecmp(c->name, name) && strcmp(c->uniqueid, name)) ||
01223                 (namelen && strncasecmp(c->name, name, namelen)))
01224                continue;   /* name match failed */
01225          } else if (exten) {
01226             if (context && strcasecmp(c->context, context) &&
01227                 strcasecmp(c->macrocontext, context))
01228                continue;   /* context match failed */
01229             if (strcasecmp(c->exten, exten) &&
01230                 strcasecmp(c->macroexten, exten))
01231                continue;   /* exten match failed */
01232          }
01233          /* if we get here, c points to the desired record */
01234          break;
01235       }
01236       /* exit if chan not found or mutex acquired successfully */
01237       /* this is slightly unsafe, as we _should_ hold the lock to access c->name */
01238       done = c == NULL || ast_channel_trylock(c) == 0;
01239       if (!done) {
01240          ast_debug(1, "Avoiding %s for channel '%p'\n", msg, c);
01241          if (retries == 199) {
01242             /* We are about to fail due to a deadlock, so report this
01243              * while we still have the list lock.
01244              */
01245             ast_debug(1, "Failure, could not lock '%p' after %d retries!\n", c, retries);
01246             /* As we have deadlocked, we will skip this channel and
01247              * see if there is another match.
01248              * NOTE: No point doing this for a full-name match,
01249              * as there can be no more matches.
01250              */
01251             if (!(name && !namelen)) {
01252                prev = c;
01253                retries = -1;
01254             }
01255          }
01256       }
01257       AST_RWLIST_UNLOCK(&channels);
01258       if (done)
01259          return c;
01260       /* If we reach this point we basically tried to lock a channel and failed. Instead of
01261        * starting from the beginning of the list we can restore our saved pointer to the previous
01262        * channel and start from there.
01263        */
01264       prev = _prev;
01265       usleep(1);  /* give other threads a chance before retrying */
01266    }
01267 
01268    return NULL;
01269 }

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

References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.

Referenced by reload_config().

05681 {
05682    switch (reason) {
05683    case CHANNEL_MODULE_LOAD:
05684       return "LOAD (Channel module load)";
05685 
05686    case CHANNEL_MODULE_RELOAD:
05687       return "RELOAD (Channel module reload)";
05688 
05689    case CHANNEL_CLI_RELOAD:
05690       return "CLIRELOAD (Channel module reload by CLI command)";
05691 
05692    default:
05693       return "MANAGERRELOAD (Channel module reload by manager)";
05694    }
05695 };

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.

Note:
Assumes locks will be in place on both channels when called.

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

04352 {
04353    struct ast_var_t *current, *newvar;
04354    /* Append variables from clone channel into original channel */
04355    /* XXX Is this always correct?  We have to in order to keep MACROS working XXX */
04356    if (AST_LIST_FIRST(&clonechan->varshead))
04357       AST_LIST_APPEND_LIST(&original->varshead, &clonechan->varshead, entries);
04358 
04359    /* then, dup the varshead list into the clone */
04360    
04361    AST_LIST_TRAVERSE(&original->varshead, current, entries) {
04362       newvar = ast_var_assign(current->name, current->value);
04363       if (newvar)
04364          AST_LIST_INSERT_TAIL(&clonechan->varshead, newvar, entries);
04365    }
04366 }

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

01373 {
01374    if (cid->cid_dnid)
01375       ast_free(cid->cid_dnid);
01376    if (cid->cid_num)
01377       ast_free(cid->cid_num); 
01378    if (cid->cid_name)
01379       ast_free(cid->cid_name);   
01380    if (cid->cid_ani)
01381       ast_free(cid->cid_ani);
01382    if (cid->cid_rdnis)
01383       ast_free(cid->cid_rdnis);
01384    cid->cid_dnid = cid->cid_num = cid->cid_name = cid->cid_ani = cid->cid_rdnis = NULL;
01385 }

static void free_translation ( struct ast_channel clonechan  )  [static]

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

01678 {
01679    if (clonechan->writetrans)
01680       ast_translator_free_path(clonechan->writetrans);
01681    if (clonechan->readtrans)
01682       ast_translator_free_path(clonechan->readtrans);
01683    clonechan->writetrans = NULL;
01684    clonechan->readtrans = NULL;
01685    clonechan->rawwriteformat = clonechan->nativeformats;
01686    clonechan->rawreadformat = clonechan->nativeformats;
01687 }

static int generator_force ( const void *  data  )  [static]

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

01972 {
01973    /* Called if generator doesn't have data */
01974    void *tmp;
01975    int res;
01976    int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL;
01977    struct ast_channel *chan = (struct ast_channel *)data;
01978 
01979    ast_channel_lock(chan);
01980    tmp = chan->generatordata;
01981    chan->generatordata = NULL;
01982    if (chan->generator)
01983       generate = chan->generator->generate;
01984    ast_channel_unlock(chan);
01985 
01986    if (!tmp || !generate)
01987       return 0;
01988 
01989    res = generate(chan, tmp, 0, ast_format_rate(chan->writeformat & AST_FORMAT_AUDIO_MASK) / 50);
01990 
01991    chan->generatordata = tmp;
01992 
01993    if (res) {
01994       ast_debug(1, "Auto-deactivating generator\n");
01995       ast_deactivate_generator(chan);
01996    }
01997 
01998    return 0;
01999 }

static void handle_cause ( int  cause,
int *  outstate 
) [static]

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

03767 {
03768    if (outstate) {
03769       /* compute error and return */
03770       if (cause == AST_CAUSE_BUSY)
03771          *outstate = AST_CONTROL_BUSY;
03772       else if (cause == AST_CAUSE_CONGESTION)
03773          *outstate = AST_CONTROL_CONGESTION;
03774       else
03775          *outstate = 0;
03776    }
03777 }

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 3115 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_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, and AST_CONTROL_WINK.

Referenced by ast_indicate_data().

03116 {
03117    /* Don't include a default case here so that we get compiler warnings
03118     * when a new type is added. */
03119 
03120    switch (condition) {
03121    case AST_CONTROL_PROGRESS:
03122    case AST_CONTROL_PROCEEDING:
03123    case AST_CONTROL_VIDUPDATE:
03124    case AST_CONTROL_SRCUPDATE:
03125    case AST_CONTROL_RADIO_KEY:
03126    case AST_CONTROL_RADIO_UNKEY:
03127    case AST_CONTROL_OPTION:
03128    case AST_CONTROL_WINK:
03129    case AST_CONTROL_FLASH:
03130    case AST_CONTROL_OFFHOOK:
03131    case AST_CONTROL_TAKEOFFHOOK:
03132    case AST_CONTROL_ANSWER:
03133    case AST_CONTROL_HANGUP:
03134    case AST_CONTROL_T38_PARAMETERS:
03135    case _XXX_AST_CONTROL_T38:
03136       break;
03137 
03138    case AST_CONTROL_CONGESTION:
03139    case AST_CONTROL_BUSY:
03140    case AST_CONTROL_RINGING:
03141    case AST_CONTROL_RING:
03142    case AST_CONTROL_HOLD:
03143    case AST_CONTROL_UNHOLD:
03144       return 1;
03145    }
03146 
03147    return 0;
03148 }

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.

Parameters:
onoff Link/Unlinked
type 1 for core, 2 for native
c0 first channel in bridge
c1 second channel in bridge

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

04973 {
04974    manager_event(EVENT_FLAG_CALL, "Bridge",
04975          "Bridgestate: %s\r\n"
04976            "Bridgetype: %s\r\n"
04977             "Channel1: %s\r\n"
04978             "Channel2: %s\r\n"
04979             "Uniqueid1: %s\r\n"
04980             "Uniqueid2: %s\r\n"
04981             "CallerID1: %s\r\n"
04982             "CallerID2: %s\r\n",
04983          onoff ? "Link" : "Unlink",
04984          type == 1 ? "core" : "native",
04985          c0->name, c1->name, c0->uniqueid, c1->uniqueid, 
04986          S_OR(c0->cid.cid_num, ""), 
04987          S_OR(c1->cid.cid_num, ""));
04988 }

static void queue_dtmf_readq ( struct ast_channel chan,
struct ast_frame f 
) [inline, static]

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

02579 {
02580    struct ast_frame *fr = &chan->dtmff;
02581 
02582    fr->frametype = AST_FRAME_DTMF_END;
02583    fr->subclass = f->subclass;
02584    fr->len = f->len;
02585 
02586    /* The only time this function will be called is for a frame that just came
02587     * out of the channel driver.  So, we want to stick it on the tail of the
02588     * readq. */
02589 
02590    ast_queue_frame(chan, fr);
02591 }

static void report_new_callerid ( const struct ast_channel chan  )  [static]
Precondition:
chan is locked

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

04372 {
04373    manager_event(EVENT_FLAG_CALL, "NewCallerid",
04374             "Channel: %s\r\n"
04375             "CallerIDNum: %s\r\n"
04376             "CallerIDName: %s\r\n"
04377             "Uniqueid: %s\r\n"
04378             "CID-CallingPres: %d (%s)\r\n",
04379             chan->name,
04380             S_OR(chan->cid.cid_num, ""),
04381             S_OR(chan->cid.cid_name, ""),
04382             chan->uniqueid,
04383             chan->cid.cid_pres,
04384             ast_describe_caller_presentation(chan->cid.cid_pres)
04385             );
04386 }

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

References EVENT_FLAG_DTMF, manager_event, ast_channel::name, and ast_channel::uniqueid.

Referenced by __ast_read(), and ast_write().

02518 {
02519    manager_event(EVENT_FLAG_DTMF,
02520          "DTMF",
02521          "Channel: %s\r\n"
02522          "Uniqueid: %s\r\n"
02523          "Digit: %c\r\n"
02524          "Direction: %s\r\n"
02525          "Begin: %s\r\n"
02526          "End: %s\r\n",
02527          chan->name, chan->uniqueid, digit, direction, begin, end);
02528 }

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

03675 {
03676    int native;
03677    int res;
03678    char from[200], to[200];
03679    
03680    /* Make sure we only consider audio */
03681    fmt &= AST_FORMAT_AUDIO_MASK;
03682    
03683    native = chan->nativeformats;
03684 
03685    if (!fmt || !native) /* No audio requested */
03686       return 0;   /* Let's try a call without any sounds (video, text) */
03687    
03688    /* Find a translation path from the native format to one of the desired formats */
03689    if (!direction)
03690       /* reading */
03691       res = ast_translator_best_choice(&fmt, &native);
03692    else
03693       /* writing */
03694       res = ast_translator_best_choice(&native, &fmt);
03695 
03696    if (res < 0) {
03697       ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n",
03698          ast_getformatname_multiple(from, sizeof(from), native),
03699          ast_getformatname_multiple(to, sizeof(to), fmt));
03700       return -1;
03701    }
03702    
03703    /* Now we have a good choice for both. */
03704    ast_channel_lock(chan);
03705 
03706    if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) {
03707       /* the channel is already in these formats, so nothing to do */
03708       ast_channel_unlock(chan);
03709       return 0;
03710    }
03711 
03712    *rawformat = native;
03713    /* User perspective is fmt */
03714    *format = fmt;
03715    /* Free any read translation we have right now */
03716    if (*trans)
03717       ast_translator_free_path(*trans);
03718    /* Build a translation path from the raw format to the desired format */
03719    if (!direction)
03720       /* reading */
03721       *trans = ast_translator_build_path(*format, *rawformat);
03722    else
03723       /* writing */
03724       *trans = ast_translator_build_path(*rawformat, *format);
03725    ast_channel_unlock(chan);
03726    ast_debug(1, "Set channel %s to %s format %s\n", chan->name,
03727       direction ? "write" : "read", ast_getformatname(fmt));
03728    return 0;
03729 }

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

02597 {
02598    if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF)) {
02599       /* We're in the middle of emulating a digit, or DTMF has been
02600        * explicitly deferred.  Skip this digit, then. */
02601       return 1;
02602    }
02603          
02604    if (!ast_tvzero(chan->dtmf_tv) && 
02605          ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) {
02606       /* We're not in the middle of a digit, but it hasn't been long enough
02607        * since the last digit, so we'll have to skip DTMF for now. */
02608       return 1;
02609    }
02610 
02611    return 0;
02612 }

static void* silence_generator_alloc ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 5600 of file channel.c.

05601 {
05602    /* just store the data pointer in the channel structure */
05603    return data;
05604 }

static int silence_generator_generate ( struct ast_channel chan,
void *  data,
int  len,
int  samples 
) [static]

Definition at line 5611 of file channel.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_write(), and ast_frame::frametype.

05612 {
05613    short buf[samples];
05614    struct ast_frame frame = {
05615       .frametype = AST_FRAME_VOICE,
05616       .subclass = AST_FORMAT_SLINEAR,
05617       .data.ptr = buf,
05618       .samples = samples,
05619       .datalen = sizeof(buf),
05620    };
05621 
05622    memset(buf, 0, sizeof(buf));
05623 
05624    if (ast_write(chan, &frame))
05625       return -1;
05626 
05627    return 0;
05628 }

static void silence_generator_release ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 5606 of file channel.c.

05607 {
05608    /* nothing to do */
05609 }

static void* tonepair_alloc ( struct ast_channel chan,
void *  params 
) [static]

Definition at line 5367 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.

05368 {
05369    struct tonepair_state *ts;
05370    struct tonepair_def *td = params;
05371 
05372    if (!(ts = ast_calloc(1, sizeof(*ts))))
05373       return NULL;
05374    ts->origwfmt = chan->writeformat;
05375    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
05376       ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
05377       tonepair_release(NULL, ts);
05378       ts = NULL;
05379    } else {
05380       ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0;
05381       ts->v1_1 = 0;
05382       ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
05383       ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
05384       ts->v2_1 = 0;
05385       ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0;
05386       ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
05387       ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
05388       ts->duration = td->duration;
05389       ts->modulate = 0;
05390    }
05391    /* Let interrupts interrupt :) */
05392    ast_set_flag(chan, AST_FLAG_WRITE_INT);
05393    return ts;
05394 }

static int tonepair_generator ( struct ast_channel chan,
void *  data,
int  len,
int  samples 
) [static]

Definition at line 5396 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.

05397 {
05398    struct tonepair_state *ts = data;
05399    int x;
05400 
05401    /* we need to prepare a frame with 16 * timelen samples as we're
05402     * generating SLIN audio
05403     */
05404    len = samples * 2;
05405 
05406    if (len > sizeof(ts->data) / 2 - 1) {
05407       ast_log(LOG_WARNING, "Can't generate that much data!\n");
05408       return -1;
05409    }
05410    memset(&ts->f, 0, sizeof(ts->f));
05411    for (x=0;x<len/2;x++) {
05412       ts->v1_1 = ts->v2_1;
05413       ts->v2_1 = ts->v3_1;
05414       ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1;
05415       
05416       ts->v1_2 = ts->v2_2;
05417       ts->v2_2 = ts->v3_2;
05418       ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2;
05419       if (ts->modulate) {
05420          int p;
05421          p = ts->v3_2 - 32768;
05422          if (p < 0) p = -p;
05423          p = ((p * 9) / 10) + 1;
05424          ts->data[x] = (ts->v3_1 * p) >> 15;
05425       } else
05426          ts->data[x] = ts->v3_1 + ts->v3_2; 
05427    }
05428    ts->f.frametype = AST_FRAME_VOICE;
05429    ts->f.subclass = AST_FORMAT_SLINEAR;
05430    ts->f.datalen = len;
05431    ts->f.samples = samples;
05432    ts->f.offset = AST_FRIENDLY_OFFSET;
05433    ts->f.data.ptr = ts->data;
05434    ast_write(chan, &ts->f);
05435    ts->pos += x;
05436    if (ts->duration > 0) {
05437       if (ts->pos >= ts->duration * 8)
05438          return -1;
05439    }
05440    return 0;
05441 }

static void tonepair_release ( struct ast_channel chan,
void *  params 
) [static]

Definition at line 5358 of file channel.c.

References ast_free, ast_set_write_format(), and tonepair_state::origwfmt.

Referenced by tonepair_alloc().

05359 {
05360    struct tonepair_state *ts = params;
05361 
05362    if (chan)
05363       ast_set_write_format(chan, ts->origwfmt);
05364    ast_free(ts);
05365 }

static void update_bridge_vars ( struct ast_channel c0,
struct ast_channel c1 
) [static]

Definition at line 4990 of file channel.c.

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

04991 {
04992    const char *c0_name;
04993    const char *c1_name;
04994    const char *c0_pvtid = NULL;
04995    const char *c1_pvtid = NULL;
04996 
04997    ast_channel_lock(c1);
04998    c1_name = ast_strdupa(c1->name);
04999    if (c1->tech->get_pvt_uniqueid) {
05000       c1_pvtid = ast_strdupa(c1->tech->get_pvt_uniqueid(c1));
05001    }
05002    ast_channel_unlock(c1);
05003 
05004    ast_channel_lock(c0);
05005    if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) {
05006       pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1_name);
05007    }
05008    if (c1_pvtid) {
05009       pbx_builtin_setvar_helper(c0, "BRIDGEPVTCALLID", c1_pvtid);
05010    }
05011    c0_name = ast_strdupa(c0->name);
05012    if (c0->tech->get_pvt_uniqueid) {
05013       c0_pvtid = ast_strdupa(c0->tech->get_pvt_uniqueid(c0));
05014    }
05015    ast_channel_unlock(c0);
05016 
05017    ast_channel_lock(c1);
05018    if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) {
05019       pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0_name);
05020    }
05021    if (c0_pvtid) {
05022       pbx_builtin_setvar_helper(c1, "BRIDGEPVTCALLID", c0_pvtid);
05023    }
05024    ast_channel_unlock(c1);
05025 }


Variable Documentation

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 [static]
int cause
struct { ... } causes[] [static]

map AST_CAUSE's to readable string representations

causes.h

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

Definition at line 86 of file channel.c.

Referenced by handle_core_set_debug_channel().

const char* name

Definition at line 137 of file channel.c.

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

int shutting_down [static]

Prevent new channel allocation if shutting down.

Definition at line 82 of file channel.c.

Initial value:

Definition at line 5630 of file channel.c.

struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , } [static]

Definition at line 88 of file channel.c.

Referenced by ast_state2str().

struct ast_generator tonepair [static]
Initial value:
 {
   alloc: tonepair_alloc,
   release: tonepair_release,
   generate: tonepair_generator,
}

Definition at line 5443 of file channel.c.

Referenced by ast_tonepair_start().

int uniqueint [static]

Definition at line 84 of file channel.c.


Generated by  doxygen 1.6.2