Tue Jul 14 23:10:19 2009

Asterisk developer's documentation


channel.c File Reference

Channel Management. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include <sys/ioctl.h>
#include "asterisk/dahdi_compat.h"
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/audiohook.h"
#include "asterisk/musiconhold.h"
#include "asterisk/logger.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"

Go to the source code of this file.

Data Structures

struct  ast_cause
struct  ast_silence_generator
struct  backends
struct  chanlist
struct  channels
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 MONITOR_CONSTANT_DELAY
#define MONITOR_DELAY   150 * 8
#define STATE2STR_BUFSIZE   32

Functions

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)
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)
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 ringing call.
void ast_begin_shutdown (int hangup)
 Initiate system shutdown.
int ast_best_codec (int fmts)
 Pick the best audio codec.
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.
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.
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,...)
 Create a channel structure.
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_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore)
 Add a datastore to a channel.
ast_datastoreast_channel_datastore_alloc (const struct ast_datastore_info *info, char *uid)
 Create a channel datastore structure.
ast_datastoreast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, char *uid)
 Find a datastore on a channel.
int ast_channel_datastore_free (struct ast_datastore *datastore)
 Free a channel datastore structure.
int ast_channel_datastore_inherit (struct ast_channel *from, struct ast_channel *to)
 Inherit datastores from a parent to a child.
int ast_channel_datastore_remove (struct ast_channel *chan, struct ast_datastore *datastore)
 Remove a datastore from a channel.
int ast_channel_defer_dtmf (struct ast_channel *chan)
 Set defer DTMF flag on channel.
void ast_channel_free (struct ast_channel *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.
int ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clone)
 Weird function made for call transfers.
char * ast_channel_reason2str (int reason)
 return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
int ast_channel_register (const struct ast_channel_tech *tech)
 Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.
int ast_channel_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen)
int ast_channel_sendurl (struct ast_channel *chan, const char *url)
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.
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 a channel technology.
ast_channelast_channel_walk_locked (const struct ast_channel *prev)
 Browse channels in use Browse the channels currently in use.
void ast_channels_init (void)
ast_variableast_channeltype_list (void)
 return an ast_variable list of channeltypes
int ast_check_hangup (struct ast_channel *chan)
 Check to see if a channel is needing hang up.
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)
 Start masquerading a channel XXX This is a seriously wacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX.
static 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)
ast_channelast_get_channel_by_exten_locked (const char *exten, const char *context)
 Get channel by exten (and optionally context) and lock it.
ast_channelast_get_channel_by_name_locked (const char *name)
 Get channel by name (locks channel).
ast_channelast_get_channel_by_name_prefix_locked (const char *name, const int namelen)
 Get channel by name prefix (locks channel).
ast_channel_techast_get_channel_tech (const char *name)
 Get a channel technology structure by name.
ast_group_t ast_get_group (const char *s)
int ast_hangup (struct ast_channel *chan)
 Hang up a channel.
int ast_indicate (struct ast_channel *chan, int condition)
 Indicates condition of channel.
int ast_indicate_data (struct ast_channel *chan, int _condition, const void *data, size_t datalen)
 Indicates condition of channel, with payload.
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.
char * ast_print_group (char *buf, int buflen, ast_group_t group)
 print call- and pickup groups into buffer
int ast_prod (struct ast_channel *chan)
 Send empty audio to prime a channel driver.
int ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control)
 Queue a control frame with payload.
int ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
 Queue a control frame with payload.
int ast_queue_frame (struct ast_channel *chan, struct ast_frame *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.
ast_frameast_read (struct ast_channel *chan)
 Reads a frame.
static void ast_read_generator_actions (struct ast_channel *chan, struct ast_frame *f)
ast_frameast_read_noaudio (struct ast_channel *chan)
 Reads a frame, returning AST_FRAME_NULL frame if audio. Read a frame.
int ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int 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.
ast_channelast_request (const char *type, int format, void *data, int *cause)
 Requests a channel.
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 for a specied amount of time, looking for hangups.
int ast_safe_sleep_conditional (struct ast_channel *chan, int ms, int(*cond)(void *), void *data)
 Wait for a specied amount of time, looking for hangups and a condition argument.
char * ast_safe_string_alloc (const char *fmt,...)
 printf the string into a correctly sized mallocd buffer, and return the buffer
int ast_say_character_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
int ast_say_digit_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
int ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang)
int ast_say_digits_full (struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd)
int ast_say_enumeration (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
int ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options)
int ast_say_phonetic_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang)
int ast_senddigit (struct ast_channel *chan, char digit)
 Send a DTMF digit to a channel Send a DTMF digit to a channel.
int ast_senddigit_begin (struct ast_channel *chan, char digit)
int ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration)
int ast_sendtext (struct ast_channel *chan, const char *text)
 Sends text to a channel Write text to a display on a channel.
void ast_set_callerid (struct ast_channel *chan, const char *callerid, const char *calleridname, const char *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 compoent 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, int samples, int(*func)(const void *data), void *data)
int ast_shutting_down (void)
 Returns non-zero if Asterisk is being shut down.
int ast_softhangup (struct ast_channel *chan, int cause)
 Softly hangup up a channel.
int ast_softhangup_nolock (struct ast_channel *chan, int cause)
 Softly hangup up a channel (no channel lock).
char * ast_state2str (enum ast_channel_state 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 channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
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.
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)
 Waits for input on an fd This version works on fd's only. Be careful with it.
ast_channelast_waitfor_nandfds (struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
 Waits for activity on a group of channels.
int ast_waitfordigit (struct ast_channel *c, int ms)
 Waits for a digit.
int ast_waitfordigit_full (struct ast_channel *c, int ms, int audiofd, int cmdfd)
 Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
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.
ast_channelast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen)
 Get channel by name prefix (locks channel).
int ast_write (struct ast_channel *chan, struct ast_frame *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_playfile (struct ast_channel *chan, struct ast_channel *peer, const char *sound, int remain)
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 *clone)
 Clone channel variables from 'clone' channel into 'original' channel.
static char * complete_channeltypes (const char *line, const char *word, int pos, int state)
static char * complete_channeltypes_deprecated (const char *line, const char *word, int pos, int state)
static void free_cid (struct ast_callerid *cid)
static void free_translation (struct ast_channel *clone)
static int generator_force (const void *data)
static void handle_cause (int cause, int *outstate)
static int attribute_const is_visible_indication (enum ast_control_frame_type condition)
static void queue_dtmf_readq (struct ast_channel *chan, struct ast_frame *f)
static void report_new_callerid (const struct ast_channel *chan)
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 int show_channeltype (int fd, int argc, char *argv[])
static int show_channeltype_deprecated (int fd, int argc, char *argv[])
static int show_channeltypes (int fd, int argc, char *argv[])
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 state2str_threadbuf_init (void)
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_bridgepeer (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
ast_cause causes []
static struct ast_cli_entry cli_channel []
static struct ast_cli_entry cli_show_channeltype_deprecated
static struct ast_cli_entry cli_show_channeltypes_deprecated
unsigned long global_fin
unsigned long global_fout
static struct ast_channel_tech null_tech
static char show_channeltype_usage []
static char show_channeltypes_usage []
static int shutting_down
static struct ast_generator silence_generator
static struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT, .key_init = state2str_threadbuf_init , }
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 89 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 92 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 96 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 MONITOR_CONSTANT_DELAY

Definition at line 74 of file channel.c.

Referenced by ast_write().

#define MONITOR_DELAY   150 * 8

Definition at line 75 of file channel.c.

Referenced by __ast_read(), and ast_write().

#define STATE2STR_BUFSIZE   32

Definition at line 85 of file channel.c.

Referenced by ast_state2str().


Function Documentation

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

Definition at line 896 of file channel.c.

References ast_channel::alertpipe, ast_channel_lock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FLAG_BLOCKING, AST_FRAME_CONTROL, AST_FRAME_VOICE, ast_frdup(), ast_frfree, AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_LIST_AFTER, AST_LIST_INSERT_TAIL, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_log(), ast_test_flag, ast_channel::blocker, errno, f, ast_frame::frame_list, frames, ast_frame::frametype, ast_channel::name, ast_channel::readq, ast_frame::subclass, and ast_channel::timingfd.

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

00897 {
00898    struct ast_frame *f;
00899    struct ast_frame *cur;
00900    int blah = 1;
00901    unsigned int new_frames = 0;
00902    unsigned int new_voice_frames = 0;
00903    unsigned int queued_frames = 0;
00904    unsigned int queued_voice_frames = 0;
00905    AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
00906 
00907    ast_channel_lock(chan);
00908 
00909    /* See if the last frame on the queue is a hangup, if so don't queue anything */
00910    if ((cur = AST_LIST_LAST(&chan->readq)) &&
00911        (cur->frametype == AST_FRAME_CONTROL) &&
00912        (cur->subclass == AST_CONTROL_HANGUP)) {
00913       ast_channel_unlock(chan);
00914       return 0;
00915    }
00916 
00917    /* Build copies of all the frames and count them */
00918    AST_LIST_HEAD_INIT_NOLOCK(&frames);
00919    for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
00920       if (!(f = ast_frdup(cur))) {
00921          ast_frfree(AST_LIST_FIRST(&frames));
00922          return -1;
00923       }
00924 
00925       AST_LIST_INSERT_TAIL(&frames, f, frame_list);
00926       new_frames++;
00927       if (f->frametype == AST_FRAME_VOICE) {
00928          new_voice_frames++;
00929       }
00930    }
00931 
00932    /* Count how many frames exist on the queue */
00933    AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) {
00934       queued_frames++;
00935       if (cur->frametype == AST_FRAME_VOICE) {
00936          queued_voice_frames++;
00937       }
00938    }
00939 
00940    if ((queued_frames + new_frames) > 128) {
00941       ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name);
00942       while ((f = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
00943          ast_frfree(f);
00944       }
00945       ast_channel_unlock(chan);
00946       return 0;
00947    }
00948 
00949    if ((queued_voice_frames + new_voice_frames) > 96) {
00950       ast_log(LOG_WARNING, "Exceptionally long voice queue length queuing to %s\n", chan->name);
00951       while ((f = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
00952          ast_frfree(f);
00953       }
00954       ast_channel_unlock(chan);
00955       return 0;
00956    }
00957 
00958    if (after) {
00959       AST_LIST_INSERT_LIST_AFTER(&chan->readq, &frames, after, frame_list);
00960    } else {
00961       if (head) {
00962          AST_LIST_APPEND_LIST(&frames, &chan->readq, frame_list);
00963          AST_LIST_HEAD_INIT_NOLOCK(&chan->readq);
00964       }
00965       AST_LIST_APPEND_LIST(&chan->readq, &frames, frame_list);
00966    }
00967 
00968    if (chan->alertpipe[1] > -1) {
00969       if (write(chan->alertpipe[1], &blah, new_frames * sizeof(blah)) != (new_frames * sizeof(blah))) {
00970          ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n",
00971             chan->name, queued_frames, strerror(errno));
00972       }
00973 #ifdef HAVE_DAHDI
00974    } else if (chan->timingfd > -1) {
00975       while (new_frames--) {
00976          ioctl(chan->timingfd, DAHDI_TIMERPING, &blah);
00977       }
00978 #endif            
00979    } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
00980       pthread_kill(chan->blocker, SIGURG);
00981    }
00982 
00983    ast_channel_unlock(chan);
00984 
00985    return 0;
00986 }

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

Definition at line 2050 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_DEFAULT_EMULATE_DTMF_DURATION, ast_do_masquerade(), AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_FLAG_END_DTMF_ONLY, AST_FLAG_EXCEPTION, AST_FLAG_IN_DTMF, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_NULL, AST_FRAME_VOICE, ast_frfree, AST_GENERATOR_FD, ast_getformatname(), ast_getformatname_multiple(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MIN_DTMF_DURATION, AST_MIN_DTMF_GAP, AST_MONITOR_RUNNING, ast_null_frame, ast_queue_frame(), ast_queue_frame_head(), ast_read_generator_actions(), ast_seekstream(), ast_set_flag, ast_setstate(), AST_SOFTHANGUP_DEV, AST_STATE_UP, ast_test_flag, AST_TIMING_FD, ast_translate(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_writestream(), ast_channel::audiohooks, ast_channel::blocker, ast_frame::data, DEBUGCHAN_FLAG, ast_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, ast_frame::flags, ast_frame::frame_list, FRAMECOUNT_INC, ast_generator::generate, ast_channel::generator, ast_channel::generatordata, ast_channel::insmpl, LOG_DEBUG, LOG_DTMF, LOG_ERROR, LOG_NOTICE, ast_channel::masq, ast_channel::monitor, MONITOR_DELAY, ast_channel::name, ast_channel::nativeformats, option_debug, ast_channel::outsmpl, queue_dtmf_readq(), ast_channel_tech::read, ast_channel_monitor::read_stream, ast_channel::readq, ast_channel::readtrans, SEEK_FORCECUR, should_skip_dtmf(), ast_channel_monitor::state, ast_channel::tech, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.

Referenced by ast_read(), and ast_read_noaudio().

02051 {
02052    struct ast_frame *f = NULL;   /* the return value */
02053    int blah;
02054    int prestate;
02055    int count = 0;
02056 
02057    /* this function is very long so make sure there is only one return
02058     * point at the end (there are only two exceptions to this).
02059     */
02060    while(ast_channel_trylock(chan)) {
02061       if(count++ > 10) 
02062          /*cannot goto done since the channel is not locked*/
02063          return &ast_null_frame;
02064       usleep(1);
02065    }
02066 
02067    if (chan->masq) {
02068       if (ast_do_masquerade(chan))
02069          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
02070       else
02071          f =  &ast_null_frame;
02072       goto done;
02073    }
02074 
02075    /* Stop if we're a zombie or need a soft hangup */
02076    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
02077       if (chan->generator)
02078          ast_deactivate_generator(chan);
02079       goto done;
02080    }
02081 
02082    if (chan->fdno == -1) {
02083 #ifdef AST_DEVMODE
02084       ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n");
02085 #else
02086       if (option_debug > 1) {
02087          ast_log(LOG_DEBUG, "ast_read() called with no recorded file descriptor.\n");
02088       }
02089 #endif
02090       f = &ast_null_frame;
02091       goto done;
02092    }
02093    prestate = chan->_state;
02094 
02095    /* Read and ignore anything on the alertpipe, but read only
02096       one sizeof(blah) per frame that we send from it */
02097    if (chan->alertpipe[0] > -1) {
02098       int flags = fcntl(chan->alertpipe[0], F_GETFL);
02099       /* For some odd reason, the alertpipe occasionally loses nonblocking status,
02100        * which immediately causes a deadlock scenario.  Detect and prevent this. */
02101       if ((flags & O_NONBLOCK) == 0) {
02102          ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", chan->name);
02103          if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
02104             ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
02105             f = &ast_null_frame;
02106             goto done;
02107          }
02108       }
02109       if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) {
02110          if (errno != EINTR && errno != EAGAIN)
02111             ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
02112       }
02113    }
02114 
02115 #ifdef HAVE_DAHDI
02116    if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD && ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
02117       int res;
02118 
02119       ast_clear_flag(chan, AST_FLAG_EXCEPTION);
02120       blah = -1;
02121       /* IF we can't get event, assume it's an expired as-per the old interface */
02122       res = ioctl(chan->timingfd, DAHDI_GETEVENT, &blah);
02123       if (res)
02124          blah = DAHDI_EVENT_TIMER_EXPIRED;
02125 
02126       if (blah == DAHDI_EVENT_TIMER_PING) {
02127          if (AST_LIST_EMPTY(&chan->readq) || !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) {
02128             /* Acknowledge PONG unless we need it again */
02129             if (ioctl(chan->timingfd, DAHDI_TIMERPONG, &blah)) {
02130                ast_log(LOG_WARNING, "Failed to pong timer on '%s': %s\n", chan->name, strerror(errno));
02131             }
02132          }
02133       } else if (blah == DAHDI_EVENT_TIMER_EXPIRED) {
02134          ioctl(chan->timingfd, DAHDI_TIMERACK, &blah);
02135          if (chan->timingfunc) {
02136             /* save a copy of func/data before unlocking the channel */
02137             int (*func)(const void *) = chan->timingfunc;
02138             void *data = chan->timingdata;
02139             chan->fdno = -1;
02140             ast_channel_unlock(chan);
02141             func(data);
02142          } else {
02143             blah = 0;
02144             ioctl(chan->timingfd, DAHDI_TIMERCONFIG, &blah);
02145             chan->timingdata = NULL;
02146             chan->fdno = -1;
02147             ast_channel_unlock(chan);
02148          }
02149          /* cannot 'goto done' because the channel is already unlocked */
02150          return &ast_null_frame;
02151       } else
02152          ast_log(LOG_NOTICE, "No/unknown event '%d' on timer for '%s'?\n", blah, chan->name);
02153    } else
02154 #endif
02155    if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) {
02156       /* if the AST_GENERATOR_FD is set, call the generator with args
02157        * set to -1 so it can do whatever it needs to.
02158        */
02159       void *tmp = chan->generatordata;
02160       chan->generatordata = NULL;     /* reset to let ast_write get through */
02161       chan->generator->generate(chan, tmp, -1, -1);
02162       chan->generatordata = tmp;
02163       f = &ast_null_frame;
02164       chan->fdno = -1;
02165       goto done;
02166    }
02167 
02168    /* Check for pending read queue */
02169    if (!AST_LIST_EMPTY(&chan->readq)) {
02170       int skip_dtmf = should_skip_dtmf(chan);
02171 
02172       AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, f, frame_list) {
02173          /* We have to be picky about which frame we pull off of the readq because
02174           * there are cases where we want to leave DTMF frames on the queue until
02175           * some later time. */
02176 
02177          if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) {
02178             continue;
02179          }
02180 
02181          AST_LIST_REMOVE_CURRENT(&chan->readq, frame_list);
02182          break;
02183       }
02184       AST_LIST_TRAVERSE_SAFE_END;
02185       
02186       if (!f) {
02187          /* There were no acceptable frames on the readq. */
02188          f = &ast_null_frame;
02189          if (chan->alertpipe[0] > -1) {
02190             int poke = 0;
02191             /* Restore the state of the alertpipe since we aren't ready for any
02192              * of the frames in the readq. */
02193             if (write(chan->alertpipe[1], &poke, sizeof(poke)) != sizeof(poke)) {
02194                ast_log(LOG_ERROR, "Failed to write to alertpipe: %s\n", strerror(errno));
02195             }
02196          }
02197       }
02198 
02199       /* Interpret hangup and return NULL */
02200       /* XXX why not the same for frames from the channel ? */
02201       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) {
02202          ast_frfree(f);
02203          f = NULL;
02204       }
02205    } else {
02206       chan->blocker = pthread_self();
02207       if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
02208          if (chan->tech->exception)
02209             f = chan->tech->exception(chan);
02210          else {
02211             ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name);
02212             f = &ast_null_frame;
02213          }
02214          /* Clear the exception flag */
02215          ast_clear_flag(chan, AST_FLAG_EXCEPTION);
02216       } else if (chan->tech->read)
02217          f = chan->tech->read(chan);
02218       else
02219          ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name);
02220    }
02221 
02222    /*
02223     * Reset the recorded file descriptor that triggered this read so that we can
02224     * easily detect when ast_read() is called without properly using ast_waitfor().
02225     */
02226    chan->fdno = -1;
02227 
02228    if (f) {
02229       struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq);
02230 
02231       /* if the channel driver returned more than one frame, stuff the excess
02232          into the readq for the next ast_read call
02233       */
02234       if (AST_LIST_NEXT(f, frame_list)) {
02235          ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list));
02236          ast_frfree(AST_LIST_NEXT(f, frame_list));
02237          AST_LIST_NEXT(f, frame_list) = NULL;
02238       }
02239 
02240       switch (f->frametype) {
02241       case AST_FRAME_CONTROL:
02242          if (f->subclass == AST_CONTROL_ANSWER) {
02243             if (!ast_test_flag(chan, AST_FLAG_OUTGOING)) {
02244                if (option_debug)
02245                   ast_log(LOG_DEBUG, "Ignoring answer on an inbound call!\n");
02246                ast_frfree(f);
02247                f = &ast_null_frame;
02248             } else if (prestate == AST_STATE_UP) {
02249                if (option_debug)
02250                   ast_log(LOG_DEBUG, "Dropping duplicate answer!\n");
02251                ast_frfree(f);
02252                f = &ast_null_frame;
02253             } else {
02254                /* Answer the CDR */
02255                ast_setstate(chan, AST_STATE_UP);
02256                /* removed a call to ast_cdr_answer(chan->cdr) from here. */
02257             }
02258          }
02259          break;
02260       case AST_FRAME_DTMF_END:
02261          ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass, chan->name, f->len);
02262          /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
02263          if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) || ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) {
02264             queue_dtmf_readq(chan, f);
02265             ast_frfree(f);
02266             f = &ast_null_frame;
02267          } else if (!ast_test_flag(chan, AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) {
02268             if (!ast_tvzero(chan->dtmf_tv) && 
02269                 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) {
02270                /* If it hasn't been long enough, defer this digit */
02271                queue_dtmf_readq(chan, f);
02272                ast_frfree(f);
02273                f = &ast_null_frame;
02274             } else {
02275                /* There was no begin, turn this into a begin and send the end later */
02276                f->frametype = AST_FRAME_DTMF_BEGIN;
02277                ast_set_flag(chan, AST_FLAG_EMULATE_DTMF);
02278                chan->emulate_dtmf_digit = f->subclass;
02279                chan->dtmf_tv = ast_tvnow();
02280                if (f->len) {
02281                   if (f->len > AST_MIN_DTMF_DURATION)
02282                      chan->emulate_dtmf_duration = f->len;
02283                   else 
02284                      chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION;
02285                } else
02286                   chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION;
02287                ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass, chan->emulate_dtmf_duration, chan->name);
02288             }
02289             if (chan->audiohooks) {
02290                struct ast_frame *old_frame = f;
02291                f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02292                if (old_frame != f)
02293                   ast_frfree(old_frame);
02294                                 }
02295          } else {
02296             struct timeval now = ast_tvnow();
02297             if (ast_test_flag(chan, AST_FLAG_IN_DTMF)) {
02298                ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass, chan->name);
02299                ast_clear_flag(chan, AST_FLAG_IN_DTMF);
02300                if (!f->len)
02301                   f->len = ast_tvdiff_ms(now, chan->dtmf_tv);
02302             } else if (!f->len) {
02303                ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass, chan->name);
02304                f->len = AST_MIN_DTMF_DURATION;
02305             }
02306             if (f->len < AST_MIN_DTMF_DURATION && !ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) {
02307                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);
02308                ast_set_flag(chan, AST_FLAG_EMULATE_DTMF);
02309                chan->emulate_dtmf_digit = f->subclass;
02310                chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION - f->len;
02311                ast_frfree(f);
02312                f = &ast_null_frame;
02313             } else {
02314                ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass, chan->name);
02315                if (f->len < AST_MIN_DTMF_DURATION) {
02316                   f->len = AST_MIN_DTMF_DURATION;
02317                }
02318                chan->dtmf_tv = now;
02319             }
02320             if (chan->audiohooks) {
02321                struct ast_frame *old_frame = f;
02322                f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02323                if (old_frame != f)
02324                   ast_frfree(old_frame);
02325             }
02326          }
02327          break;
02328       case AST_FRAME_DTMF_BEGIN:
02329          ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass, chan->name);
02330          if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) || 
02331              (!ast_tvzero(chan->dtmf_tv) && 
02332                ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) ) {
02333             ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass, chan->name);
02334             ast_frfree(f);
02335             f = &ast_null_frame;
02336          } else {
02337             ast_set_flag(chan, AST_FLAG_IN_DTMF);
02338             chan->dtmf_tv = ast_tvnow();
02339             ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass, chan->name);
02340          }
02341          break;
02342       case AST_FRAME_NULL:
02343          /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
02344           * is reached , because we want to make sure we pass at least one
02345           * voice frame through before starting the next digit, to ensure a gap
02346           * between DTMF digits. */
02347          if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) {
02348             struct timeval now = ast_tvnow();
02349             if (!chan->emulate_dtmf_duration) {
02350                ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF);
02351                chan->emulate_dtmf_digit = 0;
02352             } else if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) {
02353                chan->emulate_dtmf_duration = 0;
02354                ast_frfree(f);
02355                f = &chan->dtmff;
02356                f->frametype = AST_FRAME_DTMF_END;
02357                f->subclass = chan->emulate_dtmf_digit;
02358                f->len = ast_tvdiff_ms(now, chan->dtmf_tv);
02359                chan->dtmf_tv = now;
02360                ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF);
02361                chan->emulate_dtmf_digit = 0;
02362                ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name);
02363                if (chan->audiohooks) {
02364                   struct ast_frame *old_frame = f;
02365                   f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02366                   if (old_frame != f) {
02367                      ast_frfree(old_frame);
02368                   }
02369                }
02370             }
02371          }
02372          break;
02373       case AST_FRAME_VOICE:
02374          /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration
02375           * is reached , because we want to make sure we pass at least one
02376           * voice frame through before starting the next digit, to ensure a gap
02377           * between DTMF digits. */
02378          if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !chan->emulate_dtmf_duration) {
02379             ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF);
02380             chan->emulate_dtmf_digit = 0;
02381          }
02382 
02383          if (dropaudio || ast_test_flag(chan, AST_FLAG_IN_DTMF)) {
02384             if (dropaudio)
02385                ast_read_generator_actions(chan, f);
02386             ast_frfree(f);
02387             f = &ast_null_frame;
02388          }
02389 
02390          if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !ast_test_flag(chan, AST_FLAG_IN_DTMF)) {
02391             struct timeval now = ast_tvnow();
02392             if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) {
02393                chan->emulate_dtmf_duration = 0;
02394                ast_frfree(f);
02395                f = &chan->dtmff;
02396                f->frametype = AST_FRAME_DTMF_END;
02397                f->subclass = chan->emulate_dtmf_digit;
02398                f->len = ast_tvdiff_ms(now, chan->dtmf_tv);
02399                chan->dtmf_tv = now;
02400                if (chan->audiohooks) {
02401                   struct ast_frame *old_frame = f;
02402                   f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02403                   if (old_frame != f)
02404                      ast_frfree(old_frame);
02405                }
02406                ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name);
02407             } else {
02408                /* Drop voice frames while we're still in the middle of the digit */
02409                ast_frfree(f);
02410                f = &ast_null_frame;
02411             }
02412          } else if ((f->frametype == AST_FRAME_VOICE) && !(f->subclass & chan->nativeformats)) {
02413             /* This frame is not one of the current native formats -- drop it on the floor */
02414             char to[200];
02415             ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n",
02416                chan->name, ast_getformatname(f->subclass), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats));
02417             ast_frfree(f);
02418             f = &ast_null_frame;
02419          } else if ((f->frametype == AST_FRAME_VOICE)) {
02420             if (chan->audiohooks) {
02421                struct ast_frame *old_frame = f;
02422                f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
02423                if (old_frame != f)
02424                   ast_frfree(old_frame);
02425             }
02426             if (chan->monitor && chan->monitor->read_stream ) {
02427                /* XXX what does this do ? */
02428 #ifndef MONITOR_CONSTANT_DELAY
02429                int jump = chan->outsmpl - chan->insmpl - 4 * f->samples;
02430                if (jump >= 0) {
02431                   jump = chan->outsmpl - chan->insmpl;
02432                   if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1)
02433                      ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
02434                   chan->insmpl += jump + f->samples;
02435                } else
02436                   chan->insmpl+= f->samples;
02437 #else
02438                int jump = chan->outsmpl - chan->insmpl;
02439                if (jump - MONITOR_DELAY >= 0) {
02440                   if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1)
02441                      ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
02442                   chan->insmpl += jump;
02443                } else
02444                   chan->insmpl += f->samples;
02445 #endif
02446                if (chan->monitor->state == AST_MONITOR_RUNNING) {
02447                   if (ast_writestream(chan->monitor->read_stream, f) < 0)
02448                      ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n");
02449                }
02450             }
02451 
02452             if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) {
02453                f = &ast_null_frame;
02454             }
02455 
02456             /* it is possible for the translation process on chan->readtrans to have
02457                produced multiple frames from the single input frame we passed it; if
02458                this happens, queue the additional frames *before* the frames we may
02459                have queued earlier. if the readq was empty, put them at the head of
02460                the queue, and if it was not, put them just after the frame that was
02461                at the end of the queue.
02462             */
02463             if (AST_LIST_NEXT(f, frame_list)) {
02464                if (!readq_tail) {
02465                   ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list));
02466                } else {
02467                   __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail);
02468                }
02469                ast_frfree(AST_LIST_NEXT(f, frame_list));
02470                AST_LIST_NEXT(f, frame_list) = NULL;
02471             }
02472 
02473             /* Run generator sitting on the line if timing device not available
02474             * and synchronous generation of outgoing frames is necessary       */
02475             ast_read_generator_actions(chan, f);
02476          }
02477       default:
02478          /* Just pass it on! */
02479          break;
02480       }
02481    } else {
02482       /* Make sure we always return NULL in the future */
02483       chan->_softhangup |= AST_SOFTHANGUP_DEV;
02484       if (chan->generator)
02485          ast_deactivate_generator(chan);
02486       /* We no longer End the CDR here */
02487    }
02488 
02489    /* High bit prints debugging */
02490    if (chan->fin & DEBUGCHAN_FLAG)
02491       ast_frame_dump(chan->name, f, "<<");
02492    chan->fin = FRAMECOUNT_INC(chan->fin);
02493 
02494 done:
02495    ast_channel_unlock(chan);
02496    return f;
02497 }

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 
)

Definition at line 3204 of file channel.c.

References ast_channel::_state, outgoing_helper::account, ast_call(), ast_call_forward(), AST_CAUSE_NO_ANSWER, ast_cdr_alloc(), ast_cdr_answer(), ast_cdr_busy(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), AST_CDR_FLAG_ORIGINATED, ast_cdr_init(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_channel_inherit_variables(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_copy_string(), AST_FRAME_CONTROL, ast_frfree, ast_hangup(), ast_log(), ast_read(), ast_request(), ast_set_callerid(), ast_set_flag, ast_set_variables(), AST_STATE_UP, ast_strlen_zero(), ast_waitfor(), ast_channel::call_forward, ast_channel::cdr, outgoing_helper::cid_name, outgoing_helper::cid_num, outgoing_helper::context, ast_channel::context, outgoing_helper::exten, ast_channel::exten, f, handle_cause(), ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, outgoing_helper::priority, ast_channel::priority, and outgoing_helper::vars.

Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().

03205 {
03206    int dummy_outstate;
03207    int cause = 0;
03208    struct ast_channel *chan;
03209    int res = 0;
03210    int last_subclass = 0;
03211    
03212    if (outstate)
03213       *outstate = 0;
03214    else
03215       outstate = &dummy_outstate;   /* make outstate always a valid pointer */
03216 
03217    chan = ast_request(type, format, data, &cause);
03218    if (!chan) {
03219       ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
03220       handle_cause(cause, outstate);
03221       return NULL;
03222    }
03223 
03224    if (oh) {
03225       if (oh->vars)  
03226          ast_set_variables(chan, oh->vars);
03227       /* XXX why is this necessary, for the parent_channel perhaps ? */
03228       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name))
03229          ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
03230       if (oh->parent_channel)
03231          ast_channel_inherit_variables(oh->parent_channel, chan);
03232       if (oh->account)
03233          ast_cdr_setaccount(chan, oh->account); 
03234    }
03235    ast_set_callerid(chan, cid_num, cid_name, cid_num);
03236    ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED);
03237 
03238    if (ast_call(chan, data, 0)) {   /* ast_call failed... */
03239       ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
03240    } else {
03241       res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
03242       while (timeout && chan->_state != AST_STATE_UP) {
03243          struct ast_frame *f;
03244          res = ast_waitfor(chan, timeout);
03245          if (res <= 0) /* error, timeout, or done */
03246             break;
03247          if (timeout > -1)
03248             timeout = res;
03249          if (!ast_strlen_zero(chan->call_forward)) {
03250             if (!(chan = ast_call_forward(NULL, chan, &timeout, format, oh, outstate))) {
03251                return NULL;
03252             }
03253             continue;
03254          }
03255 
03256          f = ast_read(chan);
03257          if (!f) {
03258             *outstate = AST_CONTROL_HANGUP;
03259             res = 0;
03260             break;
03261          }
03262          if (f->frametype == AST_FRAME_CONTROL) {
03263             switch (f->subclass) {
03264             case AST_CONTROL_RINGING:  /* record but keep going */
03265                *outstate = f->subclass;
03266                break;
03267 
03268             case AST_CONTROL_BUSY:
03269                ast_cdr_busy(chan->cdr);
03270                *outstate = f->subclass;
03271                timeout = 0;
03272                break;
03273 
03274             case AST_CONTROL_CONGESTION:
03275                ast_cdr_failed(chan->cdr);
03276                *outstate = f->subclass;
03277                timeout = 0;
03278                break;
03279 
03280             case AST_CONTROL_ANSWER:
03281                ast_cdr_answer(chan->cdr);
03282                *outstate = f->subclass;
03283                timeout = 0;      /* trick to force exit from the while() */
03284                break;
03285 
03286             /* Ignore these */
03287             case AST_CONTROL_PROGRESS:
03288             case AST_CONTROL_PROCEEDING:
03289             case AST_CONTROL_HOLD:
03290             case AST_CONTROL_UNHOLD:
03291             case AST_CONTROL_VIDUPDATE:
03292             case AST_CONTROL_SRCUPDATE:
03293             case -1:       /* Ignore -- just stopping indications */
03294                break;
03295 
03296             default:
03297                ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass);
03298             }
03299             last_subclass = f->subclass;
03300          }
03301          ast_frfree(f);
03302       }
03303    }
03304 
03305    /* Final fixups */
03306    if (oh) {
03307       if (!ast_strlen_zero(oh->context))
03308          ast_copy_string(chan->context, oh->context, sizeof(chan->context));
03309       if (!ast_strlen_zero(oh->exten))
03310          ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
03311       if (oh->priority) 
03312          chan->priority = oh->priority;
03313    }
03314    if (chan->_state == AST_STATE_UP)
03315       *outstate = AST_CONTROL_ANSWER;
03316 
03317    if (res <= 0) {
03318       if ( AST_CONTROL_RINGING == last_subclass ) 
03319          chan->hangupcause = AST_CAUSE_NO_ANSWER;
03320       if (!chan->cdr && (chan->cdr = ast_cdr_alloc()))
03321          ast_cdr_init(chan->cdr, chan);
03322       if (chan->cdr) {
03323          char tmp[256];
03324          snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data);
03325          ast_cdr_setapp(chan->cdr,"Dial",tmp);
03326          ast_cdr_update(chan);
03327          ast_cdr_start(chan->cdr);
03328          ast_cdr_end(chan->cdr);
03329          /* If the cause wasn't handled properly */
03330          if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
03331             ast_cdr_failed(chan->cdr);
03332       }
03333       ast_hangup(chan);
03334       chan = NULL;
03335    }
03336    return chan;
03337 }

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

Activate a given generator

Definition at line 1658 of file channel.c.

References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), gen, ast_channel::generator, generator_force(), ast_channel::generatordata, and ast_generator::release.

Referenced by app_exec(), ast_channel_start_silence_generator(), ast_linear_stream(), ast_playtones_start(), ast_tonepair_start(), channel_spy(), local_ast_moh_start(), and old_milliwatt_exec().

01659 {
01660    int res = 0;
01661 
01662    ast_channel_lock(chan);
01663 
01664    if (chan->generatordata) {
01665       if (chan->generator && chan->generator->release)
01666          chan->generator->release(chan, chan->generatordata);
01667       chan->generatordata = NULL;
01668    }
01669 
01670    ast_prod(chan);
01671    if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) {
01672       res = -1;
01673    }
01674    
01675    if (!res) {
01676       ast_settimeout(chan, 160, generator_force, chan);
01677       chan->generator = gen;
01678    }
01679 
01680    ast_channel_unlock(chan);
01681 
01682    return res;
01683 }

int ast_active_channels ( void   ) 

returns number of active/allocated channels

Returns number of active/allocated channels

Definition at line 443 of file channel.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, and AST_LIST_UNLOCK.

Referenced by action_corestatus(), dahdi_restart(), handle_show_settings(), and quit_handler().

00444 {
00445    struct ast_channel *c;
00446    int cnt = 0;
00447    AST_LIST_LOCK(&channels);
00448    AST_LIST_TRAVERSE(&channels, c, chan_list)
00449       cnt++;
00450    AST_LIST_UNLOCK(&channels);
00451    return cnt;
00452 }

int ast_answer ( struct ast_channel chan  ) 

Answer a ringing call.

Parameters:
chan channel to answer This function answers a channel and handles all necessary call setup functions.
Returns:
Returns 0 on success, -1 on failure

Definition at line 1579 of file channel.c.

References ast_channel::_state, ast_channel_tech::answer, ast_cdr_answer(), ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_indicate(), ast_setstate(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_test_flag, ast_channel::cdr, ast_channel::tech, and ast_channel::visible_indication.

Referenced by __login_exec(), agi_exec_full(), alarmreceiver_exec(), answer_trunk_chan(), app_exec(), ast_bridge_call(), ast_control_streamfile(), ast_pickup_call(), auth_exec(), background_detect_exec(), builtin_parkcall(), common_exec(), conf_exec(), count_exec(), dictate_exec(), directory_exec(), disa_exec(), exec(), features_answer(), handle_answer(), ices_exec(), old_milliwatt_exec(), park_call_exec(), park_exec(), pbx_builtin_answer(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), sayunixtime_exec(), send_waveform_to_channel(), skel_exec(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), vm_exec(), vm_execmain(), waitforsilence_exec(), and zapateller_exec().

01580 {
01581    int res = 0;
01582    ast_channel_lock(chan);
01583    /* You can't answer an outbound call */
01584    if (ast_test_flag(chan, AST_FLAG_OUTGOING)) {
01585       ast_channel_unlock(chan);
01586       return 0;
01587    }
01588    /* Stop if we're a zombie or need a soft hangup */
01589    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
01590       ast_channel_unlock(chan);
01591       return -1;
01592    }
01593    switch(chan->_state) {
01594    case AST_STATE_RINGING:
01595    case AST_STATE_RING:
01596       if (chan->tech->answer)
01597          res = chan->tech->answer(chan);
01598       ast_setstate(chan, AST_STATE_UP);
01599       ast_cdr_answer(chan->cdr);
01600       break;
01601    case AST_STATE_UP:
01602       break;
01603    default:
01604       break;
01605    }
01606    ast_indicate(chan, -1);
01607    chan->visible_indication = 0;
01608    ast_channel_unlock(chan);
01609    return res;
01610 }

void ast_begin_shutdown ( int  hangup  ) 

Initiate system shutdown.

Initiate system shutdown -- prevents new channels from being allocated. If "hangup" is non-zero, all existing channels will receive soft hangups

Definition at line 430 of file channel.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.

Referenced by quit_handler().

00431 {
00432    struct ast_channel *c;
00433    shutting_down = 1;
00434    if (hangup) {
00435       AST_LIST_LOCK(&channels);
00436       AST_LIST_TRAVERSE(&channels, c, chan_list)
00437          ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN);
00438       AST_LIST_UNLOCK(&channels);
00439    }
00440 }

int ast_best_codec ( int  fmts  ) 

Pick the best audio codec.

Pick the best codec

Okay, ulaw is used by all telephony equipment, so start with it

Unless of course, you're a silly European, so then prefer ALAW

G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority

Okay, well, signed linear is easy to translate into other stuff

G.726 is standard ADPCM, in RFC3551 packing order

G.726 is standard ADPCM, in AAL2 packing order

ADPCM has great sound quality and is still pretty easy to translate

Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good

iLBC is not too bad

Speex is free, but computationally more expensive than GSM

Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it

G.729a is faster than 723 and slightly less expensive

Down to G.723.1 which is proprietary but at least designed for voice

Definition at line 655 of file channel.c.

References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_AUDIO_MASK, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_SLINEAR, AST_FORMAT_SPEEX, AST_FORMAT_ULAW, ast_log(), LOG_WARNING, and prefs.

Referenced by __login_exec(), __oh323_new(), agent_call(), ast_codec_choose(), ast_iax2_new(), do_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), local_new(), mgcp_new(), sip_new(), skinny_new(), socket_process(), and transmit_connect().

00656 {
00657    /* This just our opinion, expressed in code.  We are asked to choose
00658       the best codec to use, given no information */
00659    int x;
00660    static int prefs[] =
00661    {
00662       /*! Okay, ulaw is used by all telephony equipment, so start with it */
00663       AST_FORMAT_ULAW,
00664       /*! Unless of course, you're a silly European, so then prefer ALAW */
00665       AST_FORMAT_ALAW,
00666       /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
00667       AST_FORMAT_G722,
00668       /*! Okay, well, signed linear is easy to translate into other stuff */
00669       AST_FORMAT_SLINEAR,
00670       /*! G.726 is standard ADPCM, in RFC3551 packing order */
00671       AST_FORMAT_G726,
00672       /*! G.726 is standard ADPCM, in AAL2 packing order */
00673       AST_FORMAT_G726_AAL2,
00674       /*! ADPCM has great sound quality and is still pretty easy to translate */
00675       AST_FORMAT_ADPCM,
00676       /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
00677           translate and sounds pretty good */
00678       AST_FORMAT_GSM,
00679       /*! iLBC is not too bad */
00680       AST_FORMAT_ILBC,
00681       /*! Speex is free, but computationally more expensive than GSM */
00682       AST_FORMAT_SPEEX,
00683       /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
00684           to use it */
00685       AST_FORMAT_LPC10,
00686       /*! G.729a is faster than 723 and slightly less expensive */
00687       AST_FORMAT_G729A,
00688       /*! Down to G.723.1 which is proprietary but at least designed for voice */
00689       AST_FORMAT_G723_1,
00690    };
00691 
00692    /* Strip out video */
00693    fmts &= AST_FORMAT_AUDIO_MASK;
00694    
00695    /* Find the first preferred codec in the format given */
00696    for (x=0; x < (sizeof(prefs) / sizeof(prefs[0]) ); x++)
00697       if (fmts & prefs[x])
00698          return prefs[x];
00699    ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts);
00700    return 0;
00701 }

struct ast_channel* ast_bridged_channel ( struct ast_channel chan  ) 

Find bridged channel.

Parameters:
chan Current channel

Definition at line 4082 of file channel.c.

References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.

Referenced by __dahdi_exception(), action_agents(), agents_show(), agents_show_online(), ast_bridge_call(), ast_channel_masquerade(), attempt_transfer(), cb_events(), check_bridge(), common_exec(), console_transfer(), console_transfer_deprecated(), create_jb(), dahdi_handle_event(), dahdi_hangup(), export_aoc_vars(), handle_chanlist(), handle_chanlist_deprecated(), handle_hd_hf(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_response_invite(), handle_showchan(), handle_showchan_deprecated(), local_attended_transfer(), mgcp_hangup(), mgcp_ss(), misdn_transfer_bc(), mixmonitor_thread(), park_call_full(), schedule_delivery(), sip_read(), sip_set_rtp_peer(), socket_process(), ss_thread(), start_spying(), and startmon().

04083 {
04084    struct ast_channel *bridged;
04085    bridged = chan->_bridge;
04086    if (bridged && bridged->tech->bridged_channel)
04087       bridged = bridged->tech->bridged_channel(chan, bridged);
04088    return bridged;
04089 }

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

References AST_CDR_FLAG_DIALED, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_set_flag, ast_test_flag, ast_channel_tech::call, ast_channel::cdr, and ast_channel::tech.

Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), attempt_reconnect(), begin_dial(), connect_link(), do_idle_thread(), features_call(), findmeexec(), ring_entry(), rpt(), and wait_for_answer().

03395 {
03396    /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
03397       If the remote end does not answer within the timeout, then do NOT hang up, but
03398       return anyway.  */
03399    int res = -1;
03400    /* Stop if we're a zombie or need a soft hangup */
03401    ast_channel_lock(chan);
03402    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
03403       if (chan->cdr)
03404          ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED);
03405       if (chan->tech->call)
03406          res = chan->tech->call(chan, addr, timeout);
03407       ast_set_flag(chan, AST_FLAG_OUTGOING);
03408    }
03409    ast_channel_unlock(chan);
03410    return res;
03411 }

struct ast_channel* ast_call_forward ( struct ast_channel caller,
struct ast_channel orig,
int *  timeout,
int  format,
struct outgoing_helper oh,
int *  outstate 
)

Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.

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

References outgoing_helper::account, accountcode, ast_channel::accountcode, ast_call(), ast_cdr_setaccount(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_hangup(), ast_log(), ast_request(), ast_set_callerid(), ast_set_variables(), ast_string_field_set, ast_strlen_zero(), ast_channel::call_forward, ast_channel::cid, outgoing_helper::cid_name, ast_callerid::cid_name, outgoing_helper::cid_num, ast_callerid::cid_num, ast_channel::context, ast_channel::data, handle_cause(), LOG_NOTICE, outgoing_helper::parent_channel, pbx_builtin_getvar_helper(), S_OR, type, and outgoing_helper::vars.

Referenced by __ast_request_and_dial(), and ast_feature_request_and_dial().

03138 {
03139    char tmpchan[256];
03140    struct ast_channel *new = NULL;
03141    char *data, *type;
03142    int cause = 0;
03143 
03144    /* gather data and request the new forward channel */
03145    ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan));
03146    if ((data = strchr(tmpchan, '/'))) {
03147       *data++ = '\0';
03148       type = tmpchan;
03149    } else {
03150       const char *forward_context;
03151       ast_channel_lock(orig);
03152       forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
03153       snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context));
03154       ast_channel_unlock(orig);
03155       data = tmpchan;
03156       type = "Local";
03157    }
03158    if (!(new = ast_request(type, format, data, &cause))) {
03159       ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
03160       handle_cause(cause, outstate);
03161       ast_hangup(orig);
03162       return NULL;
03163    }
03164 
03165    /* Copy/inherit important information into new channel */
03166    if (oh) {
03167       if (oh->vars) {
03168          ast_set_variables(new, oh->vars);
03169       }
03170       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
03171          ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num);
03172       }
03173       if (oh->parent_channel) {
03174          ast_channel_inherit_variables(oh->parent_channel, new);
03175          ast_channel_datastore_inherit(oh->parent_channel, new);
03176       }
03177       if (oh->account) {
03178          ast_cdr_setaccount(new, oh->account);
03179       }
03180    } else if (caller) { /* no outgoing helper so use caller if avaliable */
03181       ast_channel_inherit_variables(caller, new);
03182       ast_channel_datastore_inherit(caller, new);
03183    }
03184 
03185    ast_channel_lock(orig);
03186    ast_string_field_set(new, accountcode, orig->accountcode);
03187    if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) {
03188       ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num);
03189    }
03190    ast_channel_unlock(orig);
03191 
03192    /* call new channel */
03193    if ((*timeout = ast_call(new, data, 0))) {
03194       ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
03195       ast_hangup(orig);
03196       ast_hangup(new);
03197       return NULL;
03198    }
03199    ast_hangup(orig);
03200 
03201    return new;
03202 }

void ast_cancel_shutdown ( void   ) 

Cancel a shutdown in progress.

Cancels an existing shutdown and returns to normal operation

Definition at line 455 of file channel.c.

Referenced by handle_abort_halt().

00456 {
00457    shutting_down = 0;
00458 }

const char* ast_cause2str ( int  state  ) 

Gives the string form of a given hangup cause.

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

References causes, and desc.

Referenced by __transmit_response(), ast_do_masquerade(), ast_hangup(), findmeexec(), pbx_retrieve_variable(), sip_hangup(), and transmit_request_with_auth().

00576 {
00577    int x;
00578 
00579    for (x=0; x < sizeof(causes) / sizeof(causes[0]); x++) {
00580       if (causes[x].cause == cause)
00581          return causes[x].desc;
00582    }
00583 
00584    return "Unknown";
00585 }

void ast_change_name ( struct ast_channel chan,
char *  newname 
)

Change channel name.

Definition at line 3644 of file channel.c.

References ast_string_field_set, manager_event(), ast_channel::name, name, and ast_channel::uniqueid.

03645 {
03646    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid);
03647    ast_string_field_set(chan, name, newname);
03648 }

struct ast_channel* ast_channel_alloc ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const int  amaflag,
const char *  name_fmt,
  ... 
)

Create a channel structure.

Returns:
Returns NULL on failure to allocate.
Note:
New channels are by default set to the "default" context and extension "s"

Definition at line 709 of file channel.c.

References ast_calloc, ast_log(), AST_MAX_FDS, ast_string_field_init, DAHDI_FILE_TIMER, ast_channel::flags, free, HAVE_DAHDI, LOG_WARNING, sched_context_create(), and sched_context_destroy().

Referenced by __oh323_new(), acf_odbc_read(), acf_odbc_write(), action_getvar(), agent_new(), alsa_new(), ast_async_goto(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), ast_pbx_outgoing_exten(), check_goto_on_transfer(), dahdi_new(), do_atxfer(), features_new(), gtalk_new(), iax_park(), local_new(), make_email_file(), masq_park_call(), mgcp_new(), misdn_new(), nbs_new(), oss_new(), pbx_substitute_variables_helper_full(), phone_new(), sendpage(), sip_new(), sip_park(), and skinny_new().

00710 {
00711    struct ast_channel *tmp;
00712    int x;
00713    int flags;
00714    struct varshead *headp;
00715    va_list ap1, ap2;
00716 
00717    /* If shutting down, don't allocate any new channels */
00718    if (shutting_down) {
00719       ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
00720       return NULL;
00721    }
00722 
00723    if (!(tmp = ast_calloc(1, sizeof(*tmp))))
00724       return NULL;
00725 
00726    if (!(tmp->sched = sched_context_create())) {
00727       ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
00728       free(tmp);
00729       return NULL;
00730    }
00731    
00732    if ((ast_string_field_init(tmp, 128))) {
00733       sched_context_destroy(tmp->sched);
00734       free(tmp);
00735       return NULL;
00736    }
00737 
00738    /* Don't bother initializing the last two FD here, because they
00739       will *always* be set just a few lines down (AST_TIMING_FD,
00740       AST_ALERT_FD). */
00741    for (x = 0; x < AST_MAX_FDS - 2; x++)
00742       tmp->fds[x] = -1;
00743 
00744 #ifdef HAVE_DAHDI
00745 
00746    tmp->timingfd = open(DAHDI_FILE_TIMER, O_RDWR);
00747 
00748    if (tmp->timingfd > -1) {
00749       /* Check if timing interface supports new
00750          ping/pong scheme */
00751       flags = 1;
00752       if (!ioctl(tmp->timingfd, DAHDI_TIMERPONG, &flags))
00753          needqueue = 0;
00754    }
00755 #else
00756    tmp->timingfd = -1;              
00757 #endif               
00758 
00759    if (needqueue) {
00760       if (pipe(tmp->alertpipe)) {
00761          ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
00762 alertpipe_failed:
00763 #ifdef HAVE_DAHDI
00764          if (tmp->timingfd > -1)
00765             close(tmp->timingfd);
00766 #endif
00767          sched_context_destroy(tmp->sched);
00768          ast_string_field_free_memory(tmp);
00769          free(tmp);
00770          return NULL;
00771       } else {
00772          flags = fcntl(tmp->alertpipe[0], F_GETFL);
00773          if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
00774             ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
00775             close(tmp->alertpipe[0]);
00776             close(tmp->alertpipe[1]);
00777             goto alertpipe_failed;
00778          }
00779          flags = fcntl(tmp->alertpipe[1], F_GETFL);
00780          if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
00781             ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
00782             close(tmp->alertpipe[0]);
00783             close(tmp->alertpipe[1]);
00784             goto alertpipe_failed;
00785          }
00786       }
00787    } else   /* Make sure we've got it done right if they don't */
00788       tmp->alertpipe[0] = tmp->alertpipe[1] = -1;
00789 
00790    /* Always watch the alertpipe */
00791    tmp->fds[AST_ALERT_FD] = tmp->alertpipe[0];
00792    /* And timing pipe */
00793    tmp->fds[AST_TIMING_FD] = tmp->timingfd;
00794    ast_string_field_set(tmp, name, "**Unknown**");
00795 
00796    /* Initial state */
00797    tmp->_state = state;
00798 
00799    tmp->streamid = -1;
00800    
00801    tmp->fin = global_fin;
00802    tmp->fout = global_fout;
00803 
00804    if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
00805       ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 
00806          ast_atomic_fetchadd_int(&uniqueint, 1));
00807    } else {
00808       ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 
00809          (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1));
00810    }
00811 
00812    tmp->cid.cid_name = ast_strdup(cid_name);
00813    tmp->cid.cid_num = ast_strdup(cid_num);
00814    
00815    if (!ast_strlen_zero(name_fmt)) {
00816       /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
00817        * And they all use slightly different formats for their name string.
00818        * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
00819        * This means, that the stringfields must have a routine that takes the va_lists directly, and 
00820        * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
00821        * This new function was written so this can be accomplished.
00822        */
00823       va_start(ap1, name_fmt);
00824       va_start(ap2, name_fmt);
00825       ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
00826       va_end(ap1);
00827       va_end(ap2);
00828    }
00829 
00830    /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */
00831 
00832    /* These 4 variables need to be set up for the cdr_init() to work right */
00833    if (amaflag)
00834       tmp->amaflags = amaflag;
00835    else
00836       tmp->amaflags = ast_default_amaflags;
00837    
00838    if (!ast_strlen_zero(acctcode))
00839       ast_string_field_set(tmp, accountcode, acctcode);
00840    else
00841       ast_string_field_set(tmp, accountcode, ast_default_accountcode);
00842       
00843    if (!ast_strlen_zero(context))
00844       ast_copy_string(tmp->context, context, sizeof(tmp->context));
00845    else
00846       strcpy(tmp->context, "default");
00847 
00848    if (!ast_strlen_zero(exten))
00849       ast_copy_string(tmp->exten, exten, sizeof(tmp->exten));
00850    else
00851       strcpy(tmp->exten, "s");
00852 
00853    tmp->priority = 1;
00854       
00855    tmp->cdr = ast_cdr_alloc();
00856    ast_cdr_init(tmp->cdr, tmp);
00857    ast_cdr_start(tmp->cdr);
00858    
00859    headp = &tmp->varshead;
00860    AST_LIST_HEAD_INIT_NOLOCK(headp);
00861    
00862    ast_mutex_init(&tmp->lock);
00863    
00864    AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores);
00865    
00866    ast_string_field_set(tmp, language, defaultlanguage);
00867 
00868    tmp->tech = &null_tech;
00869 
00870    AST_LIST_LOCK(&channels);
00871    AST_LIST_INSERT_HEAD(&channels, tmp, chan_list);
00872    AST_LIST_UNLOCK(&channels);
00873 
00874    /*\!note
00875     * and now, since the channel structure is built, and has its name, let's
00876     * call the manager event generator with this Newchannel event. This is the
00877     * proper and correct place to make this call, but you sure do have to pass
00878     * a lot of data into this func to do it here!
00879     */
00880    if (!ast_strlen_zero(name_fmt)) {
00881       manager_event(EVENT_FLAG_CALL, "Newchannel",
00882             "Channel: %s\r\n"
00883             "State: %s\r\n"
00884             "CallerIDNum: %s\r\n"
00885             "CallerIDName: %s\r\n"
00886             "Uniqueid: %s\r\n",
00887             tmp->name, ast_state2str(state),
00888             S_OR(cid_num, "<unknown>"),
00889             S_OR(cid_name, "<unknown>"),
00890             tmp->uniqueid);
00891    }
00892 
00893    return tmp;
00894 }

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

References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_make_compatible(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCUPDATE, AST_FEATURE_PLAY_WARNING, AST_FEATURE_REDIRECT, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_generic_bridge(), ast_indicate(), ast_log(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_verbose(), ast_channel::audiohooks, ast_channel_tech::bridge, bridge_playfile(), ast_channel::cid, ast_callerid::cid_num, config, ast_channel::generator, LOG_DEBUG, manager_event(), ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_channel::nativeformats, option_debug, option_verbose, ast_channel::readformat, ast_channel_tech::send_digit_begin, t, ast_channel::tech, ast_channel::uniqueid, update_bridgepeer(), VERBOSE_PREFIX_3, and ast_channel::writeformat.

Referenced by ast_bridge_call().

04326 {
04327    struct ast_channel *who = NULL;
04328    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
04329    int nativefailed=0;
04330    int firstpass;
04331    int o0nativeformats;
04332    int o1nativeformats;
04333    long time_left_ms=0;
04334    char caller_warning = 0;
04335    char callee_warning = 0;
04336 
04337    if (c0->_bridge) {
04338       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
04339          c0->name, c0->_bridge->name);
04340       return -1;
04341    }
04342    if (c1->_bridge) {
04343       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
04344          c1->name, c1->_bridge->name);
04345       return -1;
04346    }
04347    
04348    /* Stop if we're a zombie or need a soft hangup */
04349    if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
04350        ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
04351       return -1;
04352 
04353    *fo = NULL;
04354    firstpass = config->firstpass;
04355    config->firstpass = 0;
04356 
04357    if (ast_tvzero(config->start_time))
04358       config->start_time = ast_tvnow();
04359    time_left_ms = config->timelimit;
04360 
04361    caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
04362    callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
04363 
04364    if (config->start_sound && firstpass) {
04365       if (caller_warning)
04366          bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000);
04367       if (callee_warning)
04368          bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000);
04369    }
04370 
04371    /* Keep track of bridge */
04372    c0->_bridge = c1;
04373    c1->_bridge = c0;
04374 
04375    /* \todo  XXX here should check that cid_num is not NULL */
04376    manager_event(EVENT_FLAG_CALL, "Link",
04377             "Channel1: %s\r\n"
04378             "Channel2: %s\r\n"
04379             "Uniqueid1: %s\r\n"
04380             "Uniqueid2: %s\r\n"
04381             "CallerID1: %s\r\n"
04382             "CallerID2: %s\r\n",
04383             c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04384 
04385    o0nativeformats = c0->nativeformats;
04386    o1nativeformats = c1->nativeformats;
04387 
04388    if (config->feature_timer && !ast_tvzero(config->nexteventts)) {
04389       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000));
04390    } else if (config->timelimit && firstpass) {
04391       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
04392       if (caller_warning || callee_warning)
04393          config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000));
04394    }
04395 
04396    if (!c0->tech->send_digit_begin)
04397       ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY);
04398    if (!c1->tech->send_digit_begin)
04399       ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY);
04400 
04401    /* Before we enter in and bridge these two together tell them both the source of audio has changed */
04402    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
04403    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
04404 
04405    for (/* ever */;;) {
04406       struct timeval now = { 0, };
04407       int to;
04408 
04409       to = -1;
04410 
04411       if (!ast_tvzero(config->nexteventts)) {
04412          now = ast_tvnow();
04413          to = ast_tvdiff_ms(config->nexteventts, now);
04414          if (to <= 0) {
04415             if (!config->timelimit) {
04416                res = AST_BRIDGE_COMPLETE;
04417                break;
04418             }
04419             to = 0;
04420          }
04421       }
04422 
04423       if (config->timelimit) {
04424          time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
04425          if (time_left_ms < to)
04426             to = time_left_ms;
04427 
04428          if (time_left_ms <= 0) {
04429             if (caller_warning && config->end_sound)
04430                bridge_playfile(c0, c1, config->end_sound, 0);
04431             if (callee_warning && config->end_sound)
04432                bridge_playfile(c1, c0, config->end_sound, 0);
04433             *fo = NULL;
04434             if (who)
04435                *rc = who;
04436             res = 0;
04437             break;
04438          }
04439 
04440          if (!to) {
04441             if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) {
04442                int t = (time_left_ms + 500) / 1000; /* round to nearest second */
04443                if (caller_warning)
04444                   bridge_playfile(c0, c1, config->warning_sound, t);
04445                if (callee_warning)
04446                   bridge_playfile(c1, c0, config->warning_sound, t);
04447             }
04448             if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000)))
04449                config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000));
04450             else
04451                config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
04452          }
04453          ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
04454       }
04455 
04456       if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
04457          if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04458             c0->_softhangup = 0;
04459          if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04460             c1->_softhangup = 0;
04461          c0->_bridge = c1;
04462          c1->_bridge = c0;
04463          if (option_debug)
04464             ast_log(LOG_DEBUG, "Unbridge signal received. Ending native bridge.\n");
04465          continue;
04466       }
04467 
04468       /* Stop if we're a zombie or need a soft hangup */
04469       if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
04470           ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
04471          *fo = NULL;
04472          if (who)
04473             *rc = who;
04474          res = 0;
04475          if (option_debug)
04476             ast_log(LOG_DEBUG, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",
04477                c0->name, c1->name,
04478                ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No",
04479                ast_check_hangup(c0) ? "Yes" : "No",
04480                ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No",
04481                ast_check_hangup(c1) ? "Yes" : "No");
04482          break;
04483       }
04484 
04485       update_bridgepeer(c0, c1);
04486 
04487       if (c0->tech->bridge &&
04488           (config->timelimit == 0) &&
04489           (c0->tech->bridge == c1->tech->bridge) &&
04490           !nativefailed && !c0->monitor && !c1->monitor &&
04491           !c0->audiohooks && !c1->audiohooks && !ast_test_flag(&(config->features_callee),AST_FEATURE_REDIRECT) &&
04492           !ast_test_flag(&(config->features_caller),AST_FEATURE_REDIRECT) &&
04493           !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) {
04494          /* Looks like they share a bridge method and nothing else is in the way */
04495          ast_set_flag(c0, AST_FLAG_NBRIDGE);
04496          ast_set_flag(c1, AST_FLAG_NBRIDGE);
04497          if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, to)) == AST_BRIDGE_COMPLETE) {
04498             /* \todo  XXX here should check that cid_num is not NULL */
04499             manager_event(EVENT_FLAG_CALL, "Unlink",
04500                      "Channel1: %s\r\n"
04501                      "Channel2: %s\r\n"
04502                      "Uniqueid1: %s\r\n"
04503                      "Uniqueid2: %s\r\n"
04504                      "CallerID1: %s\r\n"
04505                      "CallerID2: %s\r\n",
04506                      c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04507             if (option_debug)
04508                ast_log(LOG_DEBUG, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name);
04509 
04510             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
04511             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
04512 
04513             if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04514                continue;
04515 
04516             c0->_bridge = NULL;
04517             c1->_bridge = NULL;
04518 
04519             return res;
04520          } else {
04521             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
04522             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
04523          }
04524          switch (res) {
04525          case AST_BRIDGE_RETRY:
04526             if (config->play_warning) {
04527                ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
04528             }
04529             continue;
04530          default:
04531             if (option_verbose > 2)
04532                ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s ended\n",
04533                       c0->name, c1->name);
04534             /* fallthrough */
04535          case AST_BRIDGE_FAILED_NOWARN:
04536             nativefailed++;
04537             break;
04538          }
04539       }
04540 
04541       if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
04542           (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
04543           !(c0->generator || c1->generator)) {
04544          if (ast_channel_make_compatible(c0, c1)) {
04545             ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
04546             /* \todo  XXX here should check that cid_num is not NULL */
04547                                 manager_event(EVENT_FLAG_CALL, "Unlink",
04548                      "Channel1: %s\r\n"
04549                      "Channel2: %s\r\n"
04550                      "Uniqueid1: %s\r\n"
04551                      "Uniqueid2: %s\r\n"
04552                      "CallerID1: %s\r\n"
04553                      "CallerID2: %s\r\n",
04554                      c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04555             return AST_BRIDGE_FAILED;
04556          }
04557          o0nativeformats = c0->nativeformats;
04558          o1nativeformats = c1->nativeformats;
04559       }
04560 
04561       update_bridgepeer(c0, c1);
04562 
04563       res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts);
04564       if (res != AST_BRIDGE_RETRY) {
04565          break;
04566       } else if (config->feature_timer) {
04567          /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */
04568          break;
04569       }
04570    }
04571 
04572    ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY);
04573    ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY);
04574 
04575    /* Now that we have broken the bridge the source will change yet again */
04576    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
04577    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
04578 
04579    c0->_bridge = NULL;
04580    c1->_bridge = NULL;
04581 
04582    /* \todo  XXX here should check that cid_num is not NULL */
04583    manager_event(EVENT_FLAG_CALL, "Unlink",
04584             "Channel1: %s\r\n"
04585             "Channel2: %s\r\n"
04586             "Uniqueid1: %s\r\n"
04587             "Uniqueid2: %s\r\n"
04588             "CallerID1: %s\r\n"
04589             "CallerID2: %s\r\n",
04590             c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04591    if (option_debug)
04592       ast_log(LOG_DEBUG, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
04593 
04594    return res;
04595 }

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 retturn -1.

Definition at line 475 of file channel.c.

References ast_channel::whentohangup.

00476 {
00477    time_t whentohangup;
00478 
00479    if (chan->whentohangup == 0) {
00480       return (offset == 0) ? 0 : -1;
00481    } else {
00482       if (offset == 0)  /* XXX why is this special ? */
00483          return (1);
00484       else {
00485          whentohangup = offset + time (NULL);
00486          if (chan->whentohangup < whentohangup)
00487             return (1);
00488          else if (chan->whentohangup == whentohangup)
00489             return (0);
00490          else
00491             return (-1);
00492       }
00493    }
00494 }

int ast_channel_datastore_add ( struct ast_channel chan,
struct ast_datastore datastore 
)

Add a datastore to a channel.

Definition at line 1396 of file channel.c.

References AST_LIST_INSERT_HEAD, ast_channel::datastores, and ast_datastore::entry.

Referenced by _macro_exec(), add_features_datastores(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), smdi_msg_retrieve_read(), speech_create(), and try_calling().

01397 {
01398    int res = 0;
01399 
01400    AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry);
01401 
01402    return res;
01403 }

struct ast_datastore* ast_channel_datastore_alloc ( const struct ast_datastore_info info,
char *  uid 
)

Create a channel datastore structure.

Definition at line 1335 of file channel.c.

References ast_calloc, ast_strdup, and ast_datastore::info.

Referenced by _macro_exec(), add_features_datastores(), ast_channel_datastore_inherit(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), smdi_msg_retrieve_read(), speech_create(), and try_calling().

01336 {
01337    struct ast_datastore *datastore = NULL;
01338 
01339    /* Make sure we at least have type so we can identify this */
01340    if (info == NULL) {
01341       return NULL;
01342    }
01343 
01344    /* Allocate memory for datastore and clear it */
01345    datastore = ast_calloc(1, sizeof(*datastore));
01346    if (datastore == NULL) {
01347       return NULL;
01348    }
01349 
01350    datastore->info = info;
01351 
01352    datastore->uid = ast_strdup(uid);
01353 
01354    return datastore;
01355 }

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

Find a datastore on a channel.

Definition at line 1423 of file channel.c.

References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel::datastores, ast_datastore::entry, ast_datastore::info, and ast_datastore::uid.

Referenced by _macro_exec(), add_features_datastores(), attended_transfer_occurred(), chanspy_ds_free(), do_atxfer(), do_parking_thread(), find_speech(), func_inheritance_write(), park_exec(), queue_transfer_fixup(), smdi_msg_read(), speech_background(), speech_destroy(), stop_mixmonitor_exec(), and try_calling().

01424 {
01425    struct ast_datastore *datastore = NULL;
01426    
01427    if (info == NULL)
01428       return NULL;
01429 
01430    AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) {
01431       if (datastore->info == info) {
01432          if (uid != NULL && datastore->uid != NULL) {
01433             if (!strcasecmp(uid, datastore->uid)) {
01434                /* Matched by type AND uid */
01435                break;
01436             }
01437          } else {
01438             /* Matched by type at least */
01439             break;
01440          }
01441       }
01442    }
01443    AST_LIST_TRAVERSE_SAFE_END
01444 
01445    return datastore;
01446 }

int ast_channel_datastore_free ( struct ast_datastore datastore  ) 

Free a channel datastore structure.

Definition at line 1357 of file channel.c.

References ast_datastore::data, ast_datastore_info::destroy, free, ast_datastore::info, and ast_datastore::uid.

Referenced by add_features_datastores(), ast_channel_free(), chanspy_ds_free(), setup_inheritance_datastore(), and try_calling().

01358 {
01359    int res = 0;
01360 
01361    /* Using the destroy function (if present) destroy the data */
01362    if (datastore->info->destroy != NULL && datastore->data != NULL) {
01363       datastore->info->destroy(datastore->data);
01364       datastore->data = NULL;
01365    }
01366 
01367    /* Free allocated UID memory */
01368    if (datastore->uid != NULL) {
01369       free(datastore->uid);
01370       datastore->uid = NULL;
01371    }
01372 
01373    /* Finally free memory used by ourselves */
01374    free(datastore);
01375 
01376    return res;
01377 }

int ast_channel_datastore_inherit ( struct ast_channel from,
struct ast_channel to 
)

Inherit datastores from a parent to a child.

Definition at line 1379 of file channel.c.

References ast_channel_datastore_alloc(), AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_channel::datastores, ast_datastore_info::duplicate, ast_datastore::entry, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.

Referenced by ast_call_forward(), local_call(), and wait_for_answer().

01380 {
01381    struct ast_datastore *datastore = NULL, *datastore2;
01382 
01383    AST_LIST_TRAVERSE(&from->datastores, datastore, entry) {
01384       if (datastore->inheritance > 0) {
01385          datastore2 = ast_channel_datastore_alloc(datastore->info, datastore->uid);
01386          if (datastore2) {
01387             datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
01388             datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
01389             AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry);
01390          }
01391       }
01392    }
01393    return 0;
01394 }

int ast_channel_datastore_remove ( struct ast_channel chan,
struct ast_datastore datastore 
)

Remove a datastore from a channel.

Definition at line 1405 of file channel.c.

References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel::datastores, and ast_datastore::entry.

Referenced by chanspy_ds_free(), queue_transfer_fixup(), speech_background(), speech_destroy(), and try_calling().

01406 {
01407    struct ast_datastore *datastore2 = NULL;
01408    int res = -1;
01409 
01410    /* Find our position and remove ourselves */
01411    AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore2, entry) {
01412       if (datastore2 == datastore) {
01413          AST_LIST_REMOVE_CURRENT(&chan->datastores, entry);
01414          res = 0;
01415          break;
01416       }
01417    }
01418    AST_LIST_TRAVERSE_SAFE_END
01419 
01420    return res;
01421 }

int ast_channel_defer_dtmf ( struct ast_channel chan  ) 

Set defer DTMF flag on channel.

Defer DTMF so that you only read things like hangups and audio. Returns non-zero if channel was already DTMF-deferred or 0 if channel is just now being DTMF-deferred

Definition at line 1034 of file channel.c.

References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.

Referenced by __adsi_transmit_messages(), and find_cache().

01035 {
01036    int pre = 0;
01037 
01038    if (chan) {
01039       pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
01040       ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
01041    }
01042    return pre;
01043 }

void ast_channel_free ( struct ast_channel chan  ) 

Free a channel structure.

Definition at line 1241 of file channel.c.

References ast_channel::alertpipe, ast_app_group_discard(), ast_cdr_discard(), ast_channel_datastore_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), ast_device_state_changed_literal(), ast_frfree, ast_jb_destroy(), AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), ast_moh_cleanup(), ast_mutex_destroy(), ast_string_field_free_memory, ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, ast_channel::cid, ast_channel::datastores, ast_datastore::entry, f, free, free_cid(), ast_channel::lock, LOG_ERROR, ast_channel::monitor, ast_channel::music_state, name, ast_channel::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::timingfd, ast_channel::varshead, and ast_channel::writetrans.

Referenced by acf_odbc_read(), acf_odbc_write(), action_getvar(), agent_cleanup(), agent_new(), ast_do_masquerade(), ast_hangup(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), gtalk_newcall(), local_new(), make_email_file(), pbx_substitute_variables_helper_full(), and sendpage().

01242 {
01243    int fd;
01244    struct ast_var_t *vardata;
01245    struct ast_frame *f;
01246    struct varshead *headp;
01247    struct ast_datastore *datastore = NULL;
01248    char name[AST_CHANNEL_NAME], *dashptr;
01249    
01250    headp=&chan->varshead;
01251    
01252    AST_LIST_LOCK(&channels);
01253    if (!AST_LIST_REMOVE(&channels, chan, chan_list)) {
01254       ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n");
01255    }
01256    /* Lock and unlock the channel just to be sure nobody has it locked still
01257       due to a reference retrieved from the channel list. */
01258    ast_channel_lock(chan);
01259    ast_channel_unlock(chan);
01260 
01261    /* Get rid of each of the data stores on the channel */
01262    while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry)))
01263       /* Free the data store */
01264       ast_channel_datastore_free(datastore);
01265 
01266    /* Lock and unlock the channel just to be sure nobody has it locked still
01267       due to a reference that was stored in a datastore. (i.e. app_chanspy) */
01268    ast_channel_lock(chan);
01269    ast_channel_unlock(chan);
01270 
01271    if (chan->tech_pvt) {
01272       ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name);
01273       free(chan->tech_pvt);
01274    }
01275 
01276    if (chan->sched)
01277       sched_context_destroy(chan->sched);
01278 
01279    ast_copy_string(name, chan->name, sizeof(name));
01280    if ((dashptr = strrchr(name, '-'))) {
01281       *dashptr = '\0';
01282    }
01283 
01284    /* Stop monitoring */
01285    if (chan->monitor)
01286       chan->monitor->stop( chan, 0 );
01287 
01288    /* If there is native format music-on-hold state, free it */
01289    if (chan->music_state)
01290       ast_moh_cleanup(chan);
01291 
01292    /* Free translators */
01293    if (chan->readtrans)
01294       ast_translator_free_path(chan->readtrans);
01295    if (chan->writetrans)
01296       ast_translator_free_path(chan->writetrans);
01297    if (chan->pbx)
01298       ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
01299    free_cid(&chan->cid);
01300    /* Close pipes if appropriate */
01301    if ((fd = chan->alertpipe[0]) > -1)
01302       close(fd);
01303    if ((fd = chan->alertpipe[1]) > -1)
01304       close(fd);
01305    if ((fd = chan->timingfd) > -1)
01306       close(fd);
01307    while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list)))
01308       ast_frfree(f);
01309    
01310    /* loop over the variables list, freeing all data and deleting list items */
01311    /* no need to lock the list, as the channel is already locked */
01312    
01313    while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
01314       ast_var_delete(vardata);
01315 
01316    ast_app_group_discard(chan);
01317 
01318    /* Destroy the jitterbuffer */
01319    ast_jb_destroy(chan);
01320 
01321    if (chan->cdr) {
01322       ast_cdr_discard(chan->cdr);
01323       chan->cdr = NULL;
01324    }
01325    
01326    ast_mutex_destroy(&chan->lock);
01327 
01328    ast_string_field_free_memory(chan);
01329    free(chan);
01330    AST_LIST_UNLOCK(&channels);
01331 
01332    ast_device_state_changed_literal(name);
01333 }

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

References AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), ast_var_t::entries, LOG_DEBUG, option_debug, and ast_channel::varshead.

Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), begin_dial(), findmeexec(), ring_entry(), and wait_for_answer().

03651 {
03652    struct ast_var_t *current, *newvar;
03653    const char *varname;
03654 
03655    AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
03656       int vartype = 0;
03657 
03658       varname = ast_var_full_name(current);
03659       if (!varname)
03660          continue;
03661 
03662       if (varname[0] == '_') {
03663          vartype = 1;
03664          if (varname[1] == '_')
03665             vartype = 2;
03666       }
03667 
03668       switch (vartype) {
03669       case 1:
03670          newvar = ast_var_assign(&varname[1], ast_var_value(current));
03671          if (newvar) {
03672             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
03673             if (option_debug)
03674                ast_log(LOG_DEBUG, "Copying soft-transferable variable %s.\n", ast_var_name(newvar));
03675          }
03676          break;
03677       case 2:
03678          newvar = ast_var_assign(ast_var_full_name(current), ast_var_value(current));
03679          if (newvar) {
03680             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
03681             if (option_debug)
03682                ast_log(LOG_DEBUG, "Copying hard-transferable variable %s.\n", ast_var_name(newvar));
03683          }
03684          break;
03685       default:
03686          if (option_debug)
03687             ast_log(LOG_DEBUG, "Not copying variable %s.\n", ast_var_name(current));
03688          break;
03689       }
03690    }
03691 }

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

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

Referenced by app_exec(), ast_channel_bridge(), check_compat(), park_exec(), and wait_for_answer().

03504 {
03505    int src;
03506    int dst;
03507 
03508    if (chan->readformat == peer->writeformat && chan->writeformat == peer->readformat) {
03509       /* Already compatible!  Moving on ... */
03510       return 0;
03511    }
03512 
03513    /* Set up translation from the chan to the peer */
03514    src = chan->nativeformats;
03515    dst = peer->nativeformats;
03516    if (ast_translator_best_choice(&dst, &src) < 0) {
03517       ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, src, peer->name, dst);
03518       return -1;
03519    }
03520 
03521    /* if the best path is not 'pass through', then
03522       transcoding is needed; if desired, force transcode path
03523       to use SLINEAR between channels, but only if there is
03524       no direct conversion available */
03525    if ((src != dst) && ast_opt_transcode_via_slin &&
03526        (ast_translate_path_steps(dst, src) != 1))
03527       dst = AST_FORMAT_SLINEAR;
03528    if (ast_set_read_format(chan, dst) < 0) {
03529       ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, dst);
03530       return -1;
03531    }
03532    if (ast_set_write_format(peer, dst) < 0) {
03533       ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, dst);
03534       return -1;
03535    }
03536 
03537    /* Set up translation from the peer to the chan */
03538    src = peer->nativeformats;
03539    dst = chan->nativeformats;
03540    if (ast_translator_best_choice(&dst, &src) < 0) {
03541       ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", peer->name, src, chan->name, dst);
03542       return -1;
03543    }
03544 
03545    /* if the best path is not 'pass through', then
03546       transcoding is needed; if desired, force transcode path
03547       to use SLINEAR between channels, but only if there is
03548       no direct conversion available */
03549    if ((src != dst) && ast_opt_transcode_via_slin &&
03550        (ast_translate_path_steps(dst, src) != 1))
03551       dst = AST_FORMAT_SLINEAR;
03552    if (ast_set_read_format(peer, dst) < 0) {
03553       ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst);
03554       return -1;
03555    }
03556    if (ast_set_write_format(chan, dst) < 0) {
03557       ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, dst);
03558       return -1;
03559    }
03560    return 0;
03561 }

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.

Definition at line 3563 of file channel.c.

References ast_channel::_bridge, ast_bridged_channel(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_log(), ast_null_frame, ast_queue_frame(), ast_channel_tech::get_base_channel, LOG_DEBUG, ast_channel::masq, ast_channel::masqr, ast_channel::name, option_debug, and ast_channel::tech.

Referenced by ast_async_goto(), ast_pickup_call(), attempt_transfer(), check_availability(), check_bridge(), check_goto_on_transfer(), do_atxfer(), handle_invite_replaces(), iax_park(), masq_park_call(), misdn_transfer_bc(), pickup_do(), and sip_park().

03564 {
03565    int res = -1;
03566    struct ast_channel *final_orig, *final_clone, *base;
03567 
03568 retrymasq:
03569    final_orig = original;
03570    final_clone = clone;
03571 
03572    ast_channel_lock(original);
03573    while (ast_channel_trylock(clone)) {
03574       ast_channel_unlock(original);
03575       usleep(1);
03576       ast_channel_lock(original);
03577    }
03578 
03579    /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
03580       and if so, we don't really want to masquerade it, but its proxy */
03581    if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original))
03582       final_orig = original->_bridge;
03583 
03584    if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)) && (clone->_bridge->_bridge != clone))
03585       final_clone = clone->_bridge;
03586    
03587    if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) {
03588       final_clone = base;
03589    }
03590 
03591    if ((final_orig != original) || (final_clone != clone)) {
03592       /* Lots and lots of deadlock avoidance.  The main one we're competing with
03593        * is ast_write(), which locks channels recursively, when working with a
03594        * proxy channel. */
03595       if (ast_channel_trylock(final_orig)) {
03596          ast_channel_unlock(clone);
03597          ast_channel_unlock(original);
03598          goto retrymasq;
03599       }
03600       if (ast_channel_trylock(final_clone)) {
03601          ast_channel_unlock(final_orig);
03602          ast_channel_unlock(clone);
03603          ast_channel_unlock(original);
03604          goto retrymasq;
03605       }
03606       ast_channel_unlock(clone);
03607       ast_channel_unlock(original);
03608       original = final_orig;
03609       clone = final_clone;
03610    }
03611 
03612    if (original == clone) {
03613       ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
03614       ast_channel_unlock(clone);
03615       ast_channel_unlock(original);
03616       return -1;
03617    }
03618 
03619    if (option_debug)
03620       ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n",
03621          clone->name, original->name);
03622    if (original->masq) {
03623       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
03624          original->masq->name, original->name);
03625    } else if (clone->masqr) {
03626       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
03627          clone->name, clone->masqr->name);
03628    } else {
03629       original->masq = clone;
03630       clone->masqr = original;
03631       ast_queue_frame(original, &ast_null_frame);
03632       ast_queue_frame(clone, &ast_null_frame);
03633       if (option_debug)
03634          ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name);
03635       res = 0;
03636    }
03637 
03638    ast_channel_unlock(clone);
03639    ast_channel_unlock(original);
03640 
03641    return res;
03642 }

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

03102 {
03103    switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
03104    {
03105    case 0:
03106       return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
03107    case AST_CONTROL_HANGUP:
03108       return "Hangup";
03109    case AST_CONTROL_RING:
03110       return "Local Ring";
03111    case AST_CONTROL_RINGING:
03112       return "Remote end Ringing";
03113    case AST_CONTROL_ANSWER:
03114       return "Remote end has Answered";
03115    case AST_CONTROL_BUSY:
03116       return "Remote end is Busy";
03117    case AST_CONTROL_CONGESTION:
03118       return "Congestion (circuits busy)";
03119    default:
03120       return "Unknown Reason!!";
03121    }
03122 }

int ast_channel_register ( const struct ast_channel_tech tech  ) 

Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.

Parameters:
tech Structure defining channel technology or "type"
Returns:
Returns 0 on success, -1 on failure.

Definition at line 497 of file channel.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_verbose(), chanlist::list, LOG_DEBUG, LOG_WARNING, option_debug, option_verbose, chanlist::tech, ast_channel_tech::type, and VERBOSE_PREFIX_2.

Referenced by load_module(), and unload_module().

00498 {
00499    struct chanlist *chan;
00500 
00501    AST_LIST_LOCK(&channels);
00502 
00503    AST_LIST_TRAVERSE(&backends, chan, list) {
00504       if (!strcasecmp(tech->type, chan->tech->type)) {
00505          ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
00506          AST_LIST_UNLOCK(&channels);
00507          return -1;
00508       }
00509    }
00510    
00511    if (!(chan = ast_calloc(1, sizeof(*chan)))) {
00512       AST_LIST_UNLOCK(&channels);
00513       return -1;
00514    }
00515    chan->tech = tech;
00516    AST_LIST_INSERT_HEAD(&backends, chan, list);
00517 
00518    if (option_debug)
00519       ast_log(LOG_DEBUG, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
00520 
00521    if (option_verbose > 1)
00522       ast_verbose(VERBOSE_PREFIX_2 "Registered channel type '%s' (%s)\n", chan->tech->type,
00523              chan->tech->description);
00524 
00525    AST_LIST_UNLOCK(&channels);
00526    return 0;
00527 }

int ast_channel_sendhtml ( struct ast_channel channel,
int  subclass,
const char *  data,
int  datalen 
)

Send HTML or URL on link. Returns 0 on success or -1 on failure

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

03492 {
03493    if (chan->tech->send_html)
03494       return chan->tech->send_html(chan, subclass, data, datalen);
03495    return -1;
03496 }

int ast_channel_sendurl ( struct ast_channel channel,
const char *  url 
)

Send URL on link. Returns 0 on success or -1 on failure

Definition at line 3498 of file channel.c.

References ast_channel_sendhtml(), and AST_HTML_URL.

Referenced by sendurl_exec().

03499 {
03500    return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
03501 }

int ast_channel_setoption ( struct ast_channel channel,
int  option,
void *  data,
int  datalen,
int  block 
)

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

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

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

04599 {
04600    int res;
04601 
04602    if (chan->tech->setoption) {
04603       res = chan->tech->setoption(chan, option, data, datalen);
04604       if (res < 0)
04605          return res;
04606    } else {
04607       errno = ENOSYS;
04608       return -1;
04609    }
04610    if (block) {
04611       /* XXX Implement blocking -- just wait for our option frame reply, discarding
04612          intermediate packets. XXX */
04613       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
04614       return -1;
04615    }
04616    return 0;
04617 }

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 from current time of when to hang up This function sets the absolute time out on a channel (when to hang up).

Definition at line 467 of file channel.c.

References ast_null_frame, ast_queue_frame(), and ast_channel::whentohangup.

Referenced by action_timeout(), and timeout_write().

00468 {
00469    chan->whentohangup = offset ? time(NULL) + offset : 0;
00470    ast_queue_frame(chan, &ast_null_frame);
00471    return;
00472 }

struct ast_silence_generator* ast_channel_start_silence_generator ( struct ast_channel chan  ) 

Starts a silence generator on the given channel.

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

References ast_activate_generator(), ast_calloc, AST_FORMAT_SLINEAR, ast_log(), ast_set_write_format(), free, LOG_DEBUG, LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, option_debug, silence_generator, and ast_channel::writeformat.

Referenced by __ast_play_and_record(), ast_dtmf_stream(), and channel_spy().

04927 {
04928    struct ast_silence_generator *state;
04929 
04930    if (!(state = ast_calloc(1, sizeof(*state)))) {
04931       return NULL;
04932    }
04933 
04934    state->old_write_format = chan->writeformat;
04935 
04936    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
04937       ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
04938       free(state);
04939       return NULL;
04940    }
04941 
04942    ast_activate_generator(chan, &silence_generator, state);
04943 
04944    if (option_debug)
04945       ast_log(LOG_DEBUG, "Started silence generator on '%s'\n", chan->name);
04946 
04947    return state;
04948 }

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

References ast_deactivate_generator(), ast_log(), ast_set_write_format(), free, LOG_DEBUG, LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, and option_debug.

Referenced by __ast_play_and_record(), ast_dtmf_stream(), and channel_spy().

04951 {
04952    if (!state)
04953       return;
04954 
04955    ast_deactivate_generator(chan);
04956 
04957    if (option_debug)
04958       ast_log(LOG_DEBUG, "Stopped silence generator on '%s'\n", chan->name);
04959 
04960    if (ast_set_write_format(chan, state->old_write_format) < 0)
04961       ast_log(LOG_ERROR, "Could not return write format to its original state\n");
04962 
04963    free(state);
04964 }

int ast_channel_supports_html ( struct ast_channel channel  ) 

Returns 0 if channel does not support HTML or non-zero if it does

Definition at line 3486 of file channel.c.

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

Referenced by sendurl_exec().

03487 {
03488    return (chan->tech->send_html) ? 1 : 0;
03489 }

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

References ast_clear_flag, and AST_FLAG_DEFER_DTMF.

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

01047 {
01048    if (chan)
01049       ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
01050 }

void ast_channel_unregister ( const struct ast_channel_tech tech  ) 

Unregister a channel technology.

Parameters:
tech Structure defining channel technology or "type" that was previously registered
Returns:
No return value.

Definition at line 529 of file channel.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_verbose(), free, chanlist::list, LOG_DEBUG, option_debug, option_verbose, chanlist::tech, ast_channel_tech::type, and VERBOSE_PREFIX_2.

Referenced by __unload_module(), and unload_module().

00530 {
00531    struct chanlist *chan;
00532 
00533    if (option_debug)
00534       ast_log(LOG_DEBUG, "Unregistering channel type '%s'\n", tech->type);
00535 
00536    AST_LIST_LOCK(&channels);
00537 
00538    AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
00539       if (chan->tech == tech) {
00540          AST_LIST_REMOVE_CURRENT(&backends, list);
00541          free(chan);
00542          if (option_verbose > 1)
00543             ast_verbose(VERBOSE_PREFIX_2 "Unregistered channel type '%s'\n", tech->type);
00544          break;   
00545       }
00546    }
00547    AST_LIST_TRAVERSE_SAFE_END
00548 
00549    AST_LIST_UNLOCK(&channels);
00550 }

struct ast_channel* ast_channel_walk_locked ( const struct ast_channel prev  ) 

Browse channels in use Browse the channels currently in use.

Parameters:
prev where you want to start in the channel list
Returns:
Returns the next channel in the list, NULL on end. If it returns a channel, that channel *has been locked*!

Definition at line 1162 of file channel.c.

References channel_find_locked().

Referenced by action_status(), ast_complete_channels(), ast_pickup_call(), complete_ch_helper(), conf_exec(), handle_chanlist(), handle_chanlist_deprecated(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_nodebugchan_deprecated(), next_channel(), pickup_by_exten(), pickup_by_mark(), and softhangup_exec().

01163 {
01164    return channel_find_locked(prev, NULL, 0, NULL, NULL);
01165 }

void ast_channels_init ( void   ) 

Provided by channel.c

Definition at line 4850 of file channel.c.

References ast_cli_register_multiple(), and cli_channel.

Referenced by main().

04851 {
04852    ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry));
04853 }

struct ast_variable* ast_channeltype_list ( void   ) 

return an ast_variable list of channeltypes

Definition at line 163 of file channel.c.

References AST_LIST_TRAVERSE, ast_variable_new(), ast_channel_tech::description, chanlist::list, chanlist::tech, ast_channel_tech::type, and var.

00164 {
00165    struct chanlist *cl;
00166    struct ast_variable *var=NULL, *prev = NULL;
00167    AST_LIST_TRAVERSE(&backends, cl, list) {
00168       if (prev)  {
00169          if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description)))
00170             prev = prev->next;
00171       } else {
00172          var = ast_variable_new(cl->tech->type, cl->tech->description);
00173          prev = var;
00174       }
00175    }
00176    return var;
00177 }

int ast_check_hangup ( struct ast_channel chan  ) 

Check to see if a channel is needing hang up.

Parameters:
chan channel on which to check for hang up This function determines if the channel is being requested to be hung up.
Returns:
Returns 0 if not, or 1 if hang up is requested (including time-out).

Definition at line 385 of file channel.c.

References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_channel::tech_pvt, and ast_channel::whentohangup.

Referenced by __ast_read(), _macro_exec(), action_redirect(), agent_indicate(), agi_handle_command(), announce_thread(), app_exec(), ast_answer(), ast_bridge_call(), ast_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_feature_request_and_dial(), ast_indicate_data(), ast_readstring_full(), ast_recvtext(), ast_rtp_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), bridge_native_loop(), channel_spy(), common_exec(), conf_run(), dahdi_sendtext(), dahdi_setoption(), deadagi_exec(), do_atxfer(), findmeexec(), handle_sendimage(), pbx_exec(), rpt(), and wait_for_answer().

00386 {
00387    if (chan->_softhangup)     /* yes if soft hangup flag set */
00388       return 1;
00389    if (!chan->tech_pvt)    /* yes if no technology private data */
00390       return 1;
00391    if (!chan->whentohangup)   /* no if no hangup scheduled */
00392       return 0;
00393    if (chan->whentohangup > time(NULL))   /* no if hangup time has not come yet. */
00394       return 0;
00395    chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */
00396    return 1;
00397 }

static int ast_check_hangup_locked ( struct ast_channel chan  )  [static]

Definition at line 399 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().

Referenced by ast_channel_bridge().

00400 {
00401    int res;
00402    ast_channel_lock(chan);
00403    res = ast_check_hangup(chan);
00404    ast_channel_unlock(chan);
00405    return res;
00406 }

void ast_deactivate_generator ( struct ast_channel chan  ) 

Deactive an active generator

Definition at line 1612 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_clear_flag, AST_FLAG_WRITE_INT, AST_GENERATOR_FD, ast_settimeout(), ast_channel::fds, ast_channel::generator, ast_channel::generatordata, and ast_generator::release.

Referenced by __ast_read(), app_exec(), ast_channel_stop_silence_generator(), ast_openstream_full(), ast_playtones_stop(), ast_quiet_chan(), ast_read_generator_actions(), ast_tonepair_stop(), ast_write(), cb_events(), channel_spy(), generator_force(), local_ast_moh_stop(), old_milliwatt_exec(), and wait_for_answer().

01613 {
01614    ast_channel_lock(chan);
01615    if (chan->generatordata) {
01616       if (chan->generator && chan->generator->release)
01617          chan->generator->release(chan, chan->generatordata);
01618       chan->generatordata = NULL;
01619       chan->generator = NULL;
01620       chan->fds[AST_GENERATOR_FD] = -1;
01621       ast_clear_flag(chan, AST_FLAG_WRITE_INT);
01622       ast_settimeout(chan, 0, NULL, NULL);
01623    }
01624    ast_channel_unlock(chan);
01625 }

int ast_do_masquerade ( struct ast_channel original  ) 

Start masquerading a channel XXX This is a seriously wacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX.

Note:
Assumes channel will be locked when called

Definition at line 3744 of file channel.c.

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

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

03745 {
03746    int x,i;
03747    int res=0;
03748    int origstate;
03749    struct ast_frame *cur;
03750    const struct ast_channel_tech *t;
03751    void *t_pvt;
03752    struct ast_callerid tmpcid;
03753    struct ast_channel *clone = original->masq;
03754    struct ast_cdr *cdr;
03755    int rformat = original->readformat;
03756    int wformat = original->writeformat;
03757    char newn[100];
03758    char orig[100];
03759    char masqn[100];
03760    char zombn[100];
03761 
03762    if (option_debug > 3)
03763       ast_log(LOG_DEBUG, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
03764          clone->name, clone->_state, original->name, original->_state);
03765 
03766    /* XXX This is a seriously wacked out operation.  We're essentially putting the guts of
03767       the clone channel into the original channel.  Start by killing off the original
03768       channel's backend.   I'm not sure we're going to keep this function, because
03769       while the features are nice, the cost is very high in terms of pure nastiness. XXX */
03770 
03771    /* We need the clone's lock, too */
03772    ast_channel_lock(clone);
03773 
03774    if (option_debug > 1)
03775       ast_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock);
03776 
03777    /* Having remembered the original read/write formats, we turn off any translation on either
03778       one */
03779    free_translation(clone);
03780    free_translation(original);
03781 
03782 
03783    /* Unlink the masquerade */
03784    original->masq = NULL;
03785    clone->masqr = NULL;
03786    
03787    /* Save the original name */
03788    ast_copy_string(orig, original->name, sizeof(orig));
03789    /* Save the new name */
03790    ast_copy_string(newn, clone->name, sizeof(newn));
03791    /* Create the masq name */
03792    snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
03793       
03794    /* Copy the name from the clone channel */
03795    ast_string_field_set(original, name, newn);
03796 
03797    /* Mangle the name of the clone channel */
03798    ast_string_field_set(clone, name, masqn);
03799    
03800    /* Notify any managers of the change, first the masq then the other */
03801    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clone->uniqueid);
03802    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid);
03803 
03804    /* Swap the technologies */   
03805    t = original->tech;
03806    original->tech = clone->tech;
03807    clone->tech = t;
03808 
03809    /* Swap the cdrs */
03810    cdr = original->cdr;
03811    /* swap cdr uniqueid between channels, to get cdr uniqueid = channel uniqueid */
03812    ast_copy_string(clone->cdr->uniqueid, cdr->uniqueid, sizeof(cdr->uniqueid));
03813    original->cdr = clone->cdr;
03814    clone->cdr = cdr;
03815 
03816    t_pvt = original->tech_pvt;
03817    original->tech_pvt = clone->tech_pvt;
03818    clone->tech_pvt = t_pvt;
03819 
03820    /* Swap the alertpipes */
03821    for (i = 0; i < 2; i++) {
03822       x = original->alertpipe[i];
03823       original->alertpipe[i] = clone->alertpipe[i];
03824       clone->alertpipe[i] = x;
03825    }
03826 
03827    /* 
03828     * Swap the readq's.  The end result should be this:
03829     *
03830     *  1) All frames should be on the new (original) channel.
03831     *  2) Any frames that were already on the new channel before this
03832     *     masquerade need to be at the end of the readq, after all of the
03833     *     frames on the old (clone) channel.
03834     *  3) The alertpipe needs to get poked for every frame that was already
03835     *     on the new channel, since we are now using the alert pipe from the
03836     *     old (clone) channel.
03837     */
03838    {
03839       AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;
03840       AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL);
03841 
03842       AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list);
03843       AST_LIST_APPEND_LIST(&original->readq, &clone->readq, frame_list);
03844 
03845       while ((cur = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
03846          AST_LIST_INSERT_TAIL(&original->readq, cur, frame_list);
03847          if (original->alertpipe[1] > -1) {
03848             int poke = 0;
03849 
03850             if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) {
03851                ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
03852             }
03853          }
03854       }
03855    }
03856 
03857    /* Swap the raw formats */
03858    x = original->rawreadformat;
03859    original->rawreadformat = clone->rawreadformat;
03860    clone->rawreadformat = x;
03861    x = original->rawwriteformat;
03862    original->rawwriteformat = clone->rawwriteformat;
03863    clone->rawwriteformat = x;
03864 
03865    clone->_softhangup = AST_SOFTHANGUP_DEV;
03866 
03867    /* And of course, so does our current state.  Note we need not
03868       call ast_setstate since the event manager doesn't really consider
03869       these separate.  We do this early so that the clone has the proper
03870       state of the original channel. */
03871    origstate = original->_state;
03872    original->_state = clone->_state;
03873    clone->_state = origstate;
03874 
03875    if (clone->tech->fixup){
03876       res = clone->tech->fixup(original, clone);
03877       if (res)
03878          ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clone->name);
03879    }
03880 
03881    /* Start by disconnecting the original's physical side */
03882    if (clone->tech->hangup)
03883       res = clone->tech->hangup(clone);
03884    if (res) {
03885       ast_log(LOG_WARNING, "Hangup failed!  Strange things may happen!\n");
03886       ast_channel_unlock(clone);
03887       return -1;
03888    }
03889    
03890    snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig);
03891    /* Mangle the name of the clone channel */
03892    ast_string_field_set(clone, name, zombn);
03893    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clone->uniqueid);
03894 
03895    /* Update the type. */
03896    t_pvt = original->monitor;
03897    original->monitor = clone->monitor;
03898    clone->monitor = t_pvt;
03899    
03900    /* Keep the same language.  */
03901    ast_string_field_set(original, language, clone->language);
03902    /* Copy the FD's other than the generator fd */
03903    for (x = 0; x < AST_MAX_FDS; x++) {
03904       if (x != AST_GENERATOR_FD)
03905          original->fds[x] = clone->fds[x];
03906    }
03907 
03908    ast_app_group_update(clone, original);
03909    /* Move data stores over */
03910    if (AST_LIST_FIRST(&clone->datastores)) {
03911       struct ast_datastore *ds;
03912       /* We use a safe traversal here because some fixup routines actually
03913        * remove the datastore from the list and free them.
03914        */
03915       AST_LIST_TRAVERSE_SAFE_BEGIN(&clone->datastores, ds, entry) {
03916          if (ds->info->chan_fixup)
03917             ds->info->chan_fixup(ds->data, clone, original);
03918       }
03919       AST_LIST_TRAVERSE_SAFE_END;
03920       AST_LIST_APPEND_LIST(&original->datastores, &clone->datastores, entry);
03921    }
03922 
03923    clone_variables(original, clone);
03924    /* Presense of ADSI capable CPE follows clone */
03925    original->adsicpe = clone->adsicpe;
03926    /* Bridge remains the same */
03927    /* CDR fields remain the same */
03928    /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
03929    /* Application and data remain the same */
03930    /* Clone exception  becomes real one, as with fdno */
03931    ast_set_flag(original, ast_test_flag(clone, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION));
03932    original->fdno = clone->fdno;
03933    /* Schedule context remains the same */
03934    /* Stream stuff stays the same */
03935    /* Keep the original state.  The fixup code will need to work with it most likely */
03936 
03937    /* Just swap the whole structures, nevermind the allocations, they'll work themselves
03938       out. */
03939    tmpcid = original->cid;
03940    original->cid = clone->cid;
03941    clone->cid = tmpcid;
03942    report_new_callerid(original);
03943 
03944    /* Restore original timing file descriptor */
03945    original->fds[AST_TIMING_FD] = original->timingfd;
03946    
03947    /* Our native formats are different now */
03948    original->nativeformats = clone->nativeformats;
03949    
03950    /* Context, extension, priority, app data, jump table,  remain the same */
03951    /* pvt switches.  pbx stays the same, as does next */
03952    
03953    /* Set the write format */
03954    ast_set_write_format(original, wformat);
03955 
03956    /* Set the read format */
03957    ast_set_read_format(original, rformat);
03958 
03959    /* Copy the music class */
03960    ast_string_field_set(original, musicclass, clone->musicclass);
03961 
03962    if (option_debug)
03963       ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
03964 
03965    /* Okay.  Last thing is to let the channel driver know about all this mess, so he
03966       can fix up everything as best as possible */
03967    if (original->tech->fixup) {
03968       res = original->tech->fixup(clone, original);
03969       if (res) {
03970          ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n",
03971             original->tech->type, original->name);
03972          ast_channel_unlock(clone);
03973          return -1;
03974       }
03975    } else
03976       ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)!  Bad things may happen.\n",
03977          original->tech->type, original->name);
03978 
03979    /* 
03980     * If an indication is currently playing, maintain it on the channel 
03981     * that is taking the place of original 
03982     *
03983     * This is needed because the masquerade is swapping out in the internals
03984     * of this channel, and the new channel private data needs to be made
03985     * aware of the current visible indication (RINGING, CONGESTION, etc.)
03986     */
03987    if (original->visible_indication) {
03988       ast_indicate(original, original->visible_indication);
03989    }
03990    
03991    /* Now, at this point, the "clone" channel is totally F'd up.  We mark it as
03992       a zombie so nothing tries to touch it.  If it's already been marked as a
03993       zombie, then free it now (since it already is considered invalid). */
03994    if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) {
03995       if (option_debug)
03996          ast_log(LOG_DEBUG, "Destroying channel clone '%s'\n", clone->name);
03997       ast_channel_unlock(clone);
03998       manager_event(EVENT_FLAG_CALL, "Hangup",
03999          "Channel: %s\r\n"
04000          "Uniqueid: %s\r\n"
04001          "Cause: %d\r\n"
04002          "Cause-txt: %s\r\n",
04003          clone->name,
04004          clone->uniqueid,
04005          clone->hangupcause,
04006          ast_cause2str(clone->hangupcause)
04007          );
04008       ast_channel_free(clone);
04009    } else {
04010       if (option_debug)
04011          ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name);
04012       ast_set_flag(clone, AST_FLAG_ZOMBIE);
04013       ast_queue_frame(clone, &ast_null_frame);
04014       ast_channel_unlock(clone);
04015    }
04016    
04017    /* Signal any blocker */
04018    if (ast_test_flag(original, AST_FLAG_BLOCKING))
04019       pthread_kill(original->blocker, SIGURG);
04020    if (option_debug)
04021       ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state);
04022    return 0;
04023 }

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

References AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_RETRY, AST_FEATURE_WARNING_ACTIVE, ast_jb_do_usecheck(), ast_jb_empty_and_reset(), ast_samp2tv(), ast_set_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), config, f, ast_channel::nativeformats, and ast_channel::tech_pvt.

Referenced by ast_channel_bridge().

04128 {
04129    /* Copy voice back and forth between the two channels. */
04130    struct ast_channel *cs[3];
04131    struct ast_frame *f;
04132    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
04133    int o0nativeformats;
04134    int o1nativeformats;
04135    int watch_c0_dtmf;
04136    int watch_c1_dtmf;
04137    void *pvt0, *pvt1;
04138    /* Indicates whether a frame was queued into a jitterbuffer */
04139    int frame_put_in_jb = 0;
04140    int jb_in_use;
04141    int to;
04142    
04143    cs[0] = c0;
04144    cs[1] = c1;
04145    pvt0 = c0->tech_pvt;
04146    pvt1 = c1->tech_pvt;
04147    o0nativeformats = c0->nativeformats;
04148    o1nativeformats = c1->nativeformats;
04149    watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0;
04150    watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1;
04151 
04152    /* Check the need of a jitterbuffer for each channel */
04153    jb_in_use = ast_jb_do_usecheck(c0, c1);
04154    if (jb_in_use)
04155       ast_jb_empty_and_reset(c0, c1);
04156 
04157    if (config->feature_timer > 0 && ast_tvzero(config->nexteventts)) {
04158       /* calculate when the bridge should possibly break
04159        * if a partial feature match timed out */
04160       config->partialfeature_timer = ast_tvadd(ast_tvnow(), ast_samp2tv(config->feature_timer, 1000));
04161    } else {
04162       memset(&config->partialfeature_timer, 0, sizeof(config->partialfeature_timer));
04163    }
04164 
04165    for (;;) {
04166       struct ast_channel *who, *other;
04167 
04168       if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) ||
04169           (o0nativeformats != c0->nativeformats) ||
04170           (o1nativeformats != c1->nativeformats)) {
04171          /* Check for Masquerade, codec changes, etc */
04172          res = AST_BRIDGE_RETRY;
04173          break;
04174       }
04175       if (bridge_end.tv_sec) {
04176          to = ast_tvdiff_ms(bridge_end, ast_tvnow());
04177          if (to <= 0) {
04178             if (config->timelimit) {
04179                res = AST_BRIDGE_RETRY;
04180                /* generic bridge ending to play warning */
04181                ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
04182             } else {
04183                res = AST_BRIDGE_COMPLETE;
04184             }
04185             break;
04186          }
04187       } else {
04188          /* If a feature has been started and the bridge is configured to 
04189           * to not break, leave the channel bridge when the feature timer
04190           * time has elapsed so the DTMF will be sent to the other side. 
04191           */
04192          if (!ast_tvzero(config->partialfeature_timer)) {
04193             int diff = ast_tvdiff_ms(config->partialfeature_timer, ast_tvnow());
04194             if (diff <= 0) {
04195                res = AST_BRIDGE_RETRY;
04196                break;
04197             }
04198          }
04199          to = -1;
04200       }
04201       /* Calculate the appropriate max sleep interval - in general, this is the time,
04202          left to the closest jb delivery moment */
04203       if (jb_in_use)
04204          to = ast_jb_get_when_to_wakeup(c0, c1, to);
04205       who = ast_waitfor_n(cs, 2, &to);
04206       if (!who) {
04207          /* No frame received within the specified timeout - check if we have to deliver now */
04208          if (jb_in_use)
04209             ast_jb_get_and_deliver(c0, c1);
04210          if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
04211             if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04212                c0->_softhangup = 0;
04213             if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04214                c1->_softhangup = 0;
04215             c0->_bridge = c1;
04216             c1->_bridge = c0;
04217          }
04218          continue;
04219       }
04220       f = ast_read(who);
04221       if (!f) {
04222          *fo = NULL;
04223          *rc = who;
04224          if (option_debug)
04225             ast_log(LOG_DEBUG, "Didn't get a frame from channel: %s\n",who->name);
04226          break;
04227       }
04228 
04229       other = (who == c0) ? c1 : c0; /* the 'other' channel */
04230       /* Try add the frame info the who's bridged channel jitterbuff */
04231       if (jb_in_use)
04232          frame_put_in_jb = !ast_jb_put(other, f);
04233 
04234       if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) {
04235          int bridge_exit = 0;
04236 
04237          switch (f->subclass) {
04238          case AST_CONTROL_HOLD:
04239          case AST_CONTROL_UNHOLD:
04240          case AST_CONTROL_VIDUPDATE:
04241          case AST_CONTROL_SRCUPDATE:
04242             ast_indicate_data(other, f->subclass, f->data, f->datalen);
04243             if (jb_in_use) {
04244                ast_jb_empty_and_reset(c0, c1);
04245             }
04246             break;
04247          default:
04248             *fo = f;
04249             *rc = who;
04250             bridge_exit = 1;
04251             if (option_debug)
04252                ast_log(LOG_DEBUG, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name);
04253             break;
04254          }
04255          if (bridge_exit)
04256             break;
04257       }
04258       if ((f->frametype == AST_FRAME_VOICE) ||
04259           (f->frametype == AST_FRAME_DTMF_BEGIN) ||
04260           (f->frametype == AST_FRAME_DTMF) ||
04261           (f->frametype == AST_FRAME_VIDEO) ||
04262           (f->frametype == AST_FRAME_IMAGE) ||
04263           (f->frametype == AST_FRAME_HTML) ||
04264           (f->frametype == AST_FRAME_MODEM) ||
04265           (f->frametype == AST_FRAME_TEXT)) {
04266          /* monitored dtmf causes exit from bridge */
04267          int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf;
04268 
04269          if (monitored_source && 
04270             (f->frametype == AST_FRAME_DTMF_END || 
04271             f->frametype == AST_FRAME_DTMF_BEGIN)) {
04272             *fo = f;
04273             *rc = who;
04274             if (option_debug)
04275                ast_log(LOG_DEBUG, "Got DTMF %s on channel (%s)\n", 
04276                   f->frametype == AST_FRAME_DTMF_END ? "end" : "begin",
04277                   who->name);
04278 
04279             break;
04280          }
04281          /* Write immediately frames, not passed through jb */
04282          if (!frame_put_in_jb)
04283             ast_write(other, f);
04284             
04285          /* Check if we have to deliver now */
04286          if (jb_in_use)
04287             ast_jb_get_and_deliver(c0, c1);
04288       }
04289       /* XXX do we want to pass on also frames not matched above ? */
04290       ast_frfree(f);
04291 
04292       /* Swap who gets priority */
04293       cs[2] = cs[0];
04294       cs[0] = cs[1];
04295       cs[1] = cs[2];
04296    }
04297    return res;
04298 }

struct ast_channel* ast_get_channel_by_exten_locked ( const char *  exten,
const char *  context 
)

Get channel by exten (and optionally context) and lock it.

Definition at line 1187 of file channel.c.

References channel_find_locked().

01188 {
01189    return channel_find_locked(NULL, NULL, 0, context, exten);
01190 }

struct ast_channel* ast_get_channel_by_name_locked ( const char *  name  ) 

Get channel by name (locks channel).

Definition at line 1168 of file channel.c.

References channel_find_locked().

Referenced by action_atxfer(), action_getvar(), action_hangup(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), ast_bridge_call(), asyncgoto_exec(), change_monitor_action(), do_pause_or_unpause(), get_zap_channel_locked(), handle_channelstatus(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_getvariablefull(), handle_hangup(), handle_nodebugchan_deprecated(), handle_showchan(), handle_showchan_deprecated(), handle_softhangup(), manager_park(), manager_play_dtmf(), park_call_full(), pbx_builtin_importvar(), start_monitor_action(), and stop_monitor_action().

01169 {
01170    return channel_find_locked(NULL, name, 0, NULL, NULL);
01171 }

struct ast_channel* ast_get_channel_by_name_prefix_locked ( const char *  name,
const int  namelen 
)

Get channel by name prefix (locks channel).

Definition at line 1174 of file channel.c.

References channel_find_locked().

Referenced by ast_parse_device_state(), common_exec(), and mixmonitor_cli().

01175 {
01176    return channel_find_locked(NULL, name, namelen, NULL, NULL);
01177 }

struct ast_channel_tech* ast_get_channel_tech ( const char *  name  ) 

Get a channel technology structure by name.

Parameters:
name name of technology to find
Returns:
a pointer to the structure, or NULL if no matching technology found

Definition at line 552 of file channel.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), chanlist::list, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.

Referenced by ast_device_state().

00553 {
00554    struct chanlist *chanls;
00555    const struct ast_channel_tech *ret = NULL;
00556 
00557    if (AST_LIST_LOCK(&channels)) {
00558       ast_log(LOG_WARNING, "Unable to lock channel tech list\n");
00559       return NULL;
00560    }
00561 
00562    AST_LIST_TRAVERSE(&backends, chanls, list) {
00563       if (!strcasecmp(name, chanls->tech->type)) {
00564          ret = chanls->tech;
00565          break;
00566       }
00567    }
00568 
00569    AST_LIST_UNLOCK(&channels);
00570    
00571    return ret;
00572 }

ast_group_t ast_get_group ( const char *  s  ) 

Definition at line 4771 of file channel.c.

References ast_log(), ast_strdupa, ast_strlen_zero(), group, and LOG_ERROR.

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

04772 {
04773    char *piece;
04774    char *c;
04775    int start=0, finish=0, x;
04776    ast_group_t group = 0;
04777 
04778    if (ast_strlen_zero(s))
04779       return 0;
04780 
04781    c = ast_strdupa(s);
04782    
04783    while ((piece = strsep(&c, ","))) {
04784       if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
04785          /* Range */
04786       } else if (sscanf(piece, "%d", &start)) {
04787          /* Just one */
04788          finish = start;
04789       } else {
04790          ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
04791          continue;
04792       }
04793       for (x = start; x <= finish; x++) {
04794          if ((x > 63) || (x < 0)) {
04795             ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
04796          } else
04797             group |= ((ast_group_t) 1 << x);
04798       }
04799    }
04800    return group;
04801 }

int ast_hangup ( struct ast_channel chan  ) 

Hang up a channel.

Note:
This function performs a hard hangup on a channel. Unlike the soft-hangup, this function performs all stream stopping, etc, on the channel that needs to end. chan is no longer valid after this call.
Parameters:
chan channel to hang up
Returns:
Returns 0 on success, -1 on failure.

Definition at line 1485 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_closestream(), ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_log(), ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, ast_cdr::disposition, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_DEBUG, manager_event(), ast_channel::masq, ast_channel::masqr, ast_channel::name, option_debug, ast_generator::release, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, ast_channel::uniqueid, and ast_channel::vstream.

Referenced by __ast_request_and_dial(), __oh323_new(), agent_hangup(), agent_read(), alsa_new(), answer_exec_run(), app_exec(), ast_async_goto(), ast_bridge_call_thread(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), ast_feature_request_and_dial(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial(), build_conf(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_run(), connect_link(), dahdi_handle_event(), dahdi_new(), do_atxfer(), do_hang(), do_idle_thread(), do_parking_thread(), features_hangup(), findmeexec(), gtalk_new(), handle_enbloc_call_message(), handle_frame(), handle_frame_ownerless(), handle_hd_hf(), handle_init_event(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_soft_key_event_message(), handle_stimulus_message(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), local_attended_transfer(), local_hangup(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), nbs_new(), oss_new(), park_exec(), parkandannounce_exec(), phone_new(), rpt(), rpt_call(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), wait_for_answer(), and wait_for_winner().

01486 {
01487    int res = 0;
01488 
01489    /* Don't actually hang up a channel that will masquerade as someone else, or
01490       if someone is going to masquerade as us */
01491    ast_channel_lock(chan);
01492 
01493    if (chan->audiohooks) {
01494       ast_audiohook_detach_list(chan->audiohooks);
01495       chan->audiohooks = NULL;
01496    }
01497 
01498    ast_autoservice_stop(chan);
01499 
01500    if (chan->masq) {
01501       if (ast_do_masquerade(chan))
01502          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
01503    }
01504 
01505    if (chan->masq) {
01506       ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name);
01507       ast_channel_unlock(chan);
01508       return 0;
01509    }
01510    /* If this channel is one which will be masqueraded into something,
01511       mark it as a zombie already, so we know to free it later */
01512    if (chan->masqr) {
01513       ast_set_flag(chan, AST_FLAG_ZOMBIE);
01514       ast_channel_unlock(chan);
01515       return 0;
01516    }
01517    free_translation(chan);
01518    /* Close audio stream */
01519    if (chan->stream) {
01520       ast_closestream(chan->stream);
01521       chan->stream = NULL;
01522    }
01523    /* Close video stream */
01524    if (chan->vstream) {
01525       ast_closestream(chan->vstream);
01526       chan->vstream = NULL;
01527    }
01528    if (chan->sched) {
01529       sched_context_destroy(chan->sched);
01530       chan->sched = NULL;
01531    }
01532    
01533    if (chan->generatordata)   /* Clear any tone stuff remaining */
01534       chan->generator->release(chan, chan->generatordata);
01535    chan->generatordata = NULL;
01536    chan->generator = NULL;
01537    if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
01538       ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
01539                "is blocked by thread %ld in procedure %s!  Expect a failure\n",
01540                (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
01541       ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0);
01542    }
01543    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
01544       if (option_debug)
01545          ast_log(LOG_DEBUG, "Hanging up channel '%s'\n", chan->name);
01546       if (chan->tech->hangup)
01547          res = chan->tech->hangup(chan);
01548    } else {
01549       if (option_debug)
01550          ast_log(LOG_DEBUG, "Hanging up zombie '%s'\n", chan->name);
01551    }
01552          
01553    ast_channel_unlock(chan);
01554    manager_event(EVENT_FLAG_CALL, "Hangup",
01555          "Channel: %s\r\n"
01556          "Uniqueid: %s\r\n"
01557          "Cause: %d\r\n"
01558          "Cause-txt: %s\r\n",
01559          chan->name,
01560          chan->uniqueid,
01561          chan->hangupcause,
01562          ast_cause2str(chan->hangupcause)
01563          );
01564 
01565    if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 
01566       !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 
01567        (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) {
01568          
01569       ast_cdr_end(chan->cdr);
01570       ast_cdr_detach(chan->cdr);
01571       chan->cdr = NULL;
01572    }
01573    
01574    ast_channel_free(chan);
01575 
01576    return res;
01577 }

int ast_indicate ( struct ast_channel chan,
int  condition 
)

Indicates condition of channel.

Note:
Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
Parameters:
chan channel to change the indication
condition which condition to indicate on the channel
Returns:
Returns 0 on success, -1 on failure

Definition at line 2517 of file channel.c.

References ast_indicate_data().

Referenced by __ast_play_and_record(), agent_new(), answer_trunk_chan(), ast_answer(), ast_bridge_call(), ast_channel_bridge(), ast_do_masquerade(), ast_dtmf_stream(), ast_feature_request_and_dial(), attempt_transfer(), builtin_blindtransfer(), conf_run(), disa_exec(), do_atxfer(), do_parking_thread(), features_indicate(), finishup(), function_remote(), handle_frame(), handle_recordfile(), mgcp_ss(), monitor_dial(), park_exec(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), rpt(), send_waveform_to_channel(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), and wait_for_answer().

02518 {
02519    return ast_indicate_data(chan, condition, NULL, 0);
02520 }

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_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
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 2555 of file channel.c.

References ast_channel::_state, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STATE_UP, ast_test_flag, tone_zone_sound::data, ast_channel_tech::indicate, is_visible_indication(), LOG_DEBUG, ast_channel::name, option_debug, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.

Referenced by __login_exec(), agent_hangup(), ast_bridge_call(), ast_indicate(), bridge_native_loop(), do_parking_thread(), park_call_full(), pbx_builtin_waitexten(), and wait_for_answer().

02557 {
02558    /* By using an enum, we'll get compiler warnings for values not handled 
02559     * in switch statements. */
02560    enum ast_control_frame_type condition = _condition;
02561    const struct tone_zone_sound *ts = NULL;
02562    int res = -1;
02563 
02564    ast_channel_lock(chan);
02565 
02566    /* Don't bother if the channel is about to go away, anyway. */
02567    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
02568       ast_channel_unlock(chan);
02569       return -1;
02570    }
02571 
02572    if (chan->tech->indicate) {
02573       /* See if the channel driver can handle this condition. */
02574       res = chan->tech->indicate(chan, condition, data, datalen);
02575    }
02576 
02577    ast_channel_unlock(chan);
02578 
02579    if (chan->tech->indicate && !res) {
02580       /* The channel driver successfully handled this indication */
02581       if (is_visible_indication(condition)) {
02582          chan->visible_indication = condition;
02583       }
02584       return 0;
02585    }
02586 
02587    /* The channel driver does not support this indication, let's fake
02588     * it by doing our own tone generation if applicable. */
02589 
02590    /*!\note If we compare the enumeration type, which does not have any
02591     * negative constants, the compiler may optimize this code away.
02592     * Therefore, we must perform an integer comparison here. */
02593    if (_condition < 0) {
02594       /* Stop any tones that are playing */
02595       ast_playtones_stop(chan);
02596       return 0;
02597    }
02598 
02599    /* Handle conditions that we have tones for. */
02600    switch (condition) {
02601    case AST_CONTROL_RINGING:
02602       ts = ast_get_indication_tone(chan->zone, "ring");
02603       /* It is common practice for channel drivers to return -1 if trying
02604        * to indicate ringing on a channel which is up. The idea is to let the
02605        * core generate the ringing inband. However, we don't want the
02606        * warning message about not being able to handle the specific indication
02607        * to print nor do we want ast_indicate_data to return an "error" for this
02608        * condition
02609        */
02610       if (chan->_state == AST_STATE_UP) {
02611          res = 0;
02612       }
02613       break;
02614    case AST_CONTROL_BUSY:
02615       ts = ast_get_indication_tone(chan->zone, "busy");
02616       break;
02617    case AST_CONTROL_CONGESTION:
02618       ts = ast_get_indication_tone(chan->zone, "congestion");
02619       break;
02620    case AST_CONTROL_PROGRESS:
02621    case AST_CONTROL_PROCEEDING:
02622    case AST_CONTROL_VIDUPDATE:
02623    case AST_CONTROL_SRCUPDATE:
02624    case AST_CONTROL_RADIO_KEY:
02625    case AST_CONTROL_RADIO_UNKEY:
02626    case AST_CONTROL_OPTION:
02627    case AST_CONTROL_WINK:
02628    case AST_CONTROL_FLASH:
02629    case AST_CONTROL_OFFHOOK:
02630    case AST_CONTROL_TAKEOFFHOOK:
02631    case AST_CONTROL_ANSWER:
02632    case AST_CONTROL_HANGUP:
02633    case AST_CONTROL_RING:
02634    case AST_CONTROL_HOLD:
02635    case AST_CONTROL_UNHOLD:
02636       /* Nothing left to do for these. */
02637       res = 0;
02638       break;
02639    }
02640 
02641    if (ts && ts->data[0]) {
02642       /* We have a tone to play, yay. */
02643       if (option_debug) {
02644             ast_log(LOG_DEBUG, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
02645       }
02646       ast_playtones_start(chan, 0, ts->data, 1);
02647       res = 0;
02648       chan->visible_indication = condition;
02649    }
02650 
02651    if (res) {
02652       /* not handled */
02653       ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name);
02654    }
02655 
02656    return res;
02657 }

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

References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.

Referenced by load_module(), and reload().

04810 {
04811    ast_moh_start_ptr = start_ptr;
04812    ast_moh_stop_ptr = stop_ptr;
04813    ast_moh_cleanup_ptr = cleanup_ptr;
04814 }

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

References ast_log(), ast_opt_internal_timing, LOG_DEBUG, option_debug, and ast_channel::timingfd.

Referenced by add_sdp(), and ast_read_generator_actions().

02500 {
02501    int ret = ast_opt_internal_timing && chan->timingfd > -1;
02502    if (option_debug > 4)
02503       ast_log(LOG_DEBUG, "Internal timing is %s (option_internal_timing=%d chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_internal_timing, chan->timingfd);
02504    return ret;
02505 }

void ast_moh_cleanup ( struct ast_channel chan  ) 

Definition at line 4844 of file channel.c.

References ast_moh_cleanup_ptr.

Referenced by ast_channel_free().

04845 {
04846    if (ast_moh_cleanup_ptr)
04847       ast_moh_cleanup_ptr(chan);
04848 }

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:
0 success
non-zero failure

Definition at line 4824 of file channel.c.

References ast_moh_start_ptr, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.

Referenced by alsa_indicate(), app_exec(), cb_events(), conf_run(), dahdi_indicate(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), local_indicate(), mgcp_indicate(), misdn_indication(), moh0_exec(), moh1_exec(), moh3_exec(), oh323_indicate(), oss_indicate(), phone_indicate(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), and skinny_indicate().

04825 {
04826    if (ast_moh_start_ptr)
04827       return ast_moh_start_ptr(chan, mclass, interpclass);
04828 
04829    if (option_verbose > 2) {
04830       ast_verbose(VERBOSE_PREFIX_3 "Music class %s requested but no musiconhold loaded.\n", 
04831          mclass ? mclass : (interpclass ? interpclass : "default"));
04832    }
04833 
04834    return 0;
04835 }

void ast_moh_stop ( struct ast_channel chan  ) 

Turn off music on hold on a given channel.

Turn off music on hold on a given channel

Definition at line 4838 of file channel.c.

References ast_moh_stop_ptr.

Referenced by alsa_indicate(), app_exec(), ast_quiet_chan(), cb_events(), conf_run(), dahdi_indicate(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), local_indicate(), mgcp_indicate(), misdn_indication(), misdn_transfer_bc(), moh0_exec(), moh1_exec(), moh4_exec(), oh323_indicate(), oss_indicate(), phone_indicate(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), and skinny_indicate().

04839 {
04840    if (ast_moh_stop_ptr)
04841       ast_moh_stop_ptr(chan);
04842 }

char* ast_print_group ( char *  buf,
int  buflen,
ast_group_t  group 
)

print call- and pickup groups into buffer

Definition at line 4856 of file channel.c.

References first.

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

04857 {
04858    unsigned int i;
04859    int first=1;
04860    char num[3];
04861 
04862    buf[0] = '\0';
04863    
04864    if (!group) /* Return empty string if no group */
04865       return buf;
04866 
04867    for (i = 0; i <= 63; i++) {   /* Max group is 63 */
04868       if (group & ((ast_group_t) 1 << i)) {
04869             if (!first) {
04870             strncat(buf, ", ", buflen - strlen(buf) - 1);
04871          } else {
04872             first=0;
04873          }
04874          snprintf(num, sizeof(num), "%u", i);
04875          strncat(buf, num, buflen - strlen(buf) - 1);
04876       }
04877    }
04878    return buf;
04879 }

int ast_prod ( struct ast_channel chan  ) 

Send empty audio to prime a channel driver.

Definition at line 2779 of file channel.c.

References ast_channel::_state, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), ast_frame::data, LOG_DEBUG, ast_channel::name, option_debug, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.

Referenced by ast_activate_generator().

02780 {
02781    struct ast_frame a = { AST_FRAME_VOICE };
02782    char nothing[128];
02783 
02784    /* Send an empty audio frame to get things moving */
02785    if (chan->_state != AST_STATE_UP) {
02786       if (option_debug)
02787          ast_log(LOG_DEBUG, "Prodding channel '%s'\n", chan->name);
02788       a.subclass = chan->rawwriteformat;
02789       a.data = nothing + AST_FRIENDLY_OFFSET;
02790       a.src = "ast_prod";
02791       if (ast_write(chan, &a))
02792          ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name);
02793    }
02794    return 0;
02795 }

int ast_queue_control ( struct ast_channel chan,
enum ast_control_frame_type  control 
)

Queue a control frame with payload.

Parameters:
chan channel to queue frame onto
control type of control frame
Returns:
zero on success, non-zero on failure

Definition at line 1011 of file channel.c.

References AST_FRAME_CONTROL, ast_queue_frame(), and f.

Referenced by __dahdi_exception(), __oh323_update_info(), ast_pickup_call(), attempt_transfer(), auto_congest(), cb_events(), dahdi_handle_event(), dahdi_hangup(), gtalk_is_answered(), gtalk_ringing_ack(), handle_hd_hf(), handle_offhook_message(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_refer(), handle_soft_key_event_message(), handle_stimulus_message(), mgcp_call(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_unhold(), ss_thread(), and update_state().

01012 {
01013    struct ast_frame f = { AST_FRAME_CONTROL, };
01014 
01015    f.subclass = control;
01016 
01017    return ast_queue_frame(chan, &f);
01018 }

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
Returns:
zero on success, non-zero on 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.

Definition at line 1021 of file channel.c.

References AST_FRAME_CONTROL, ast_queue_frame(), and f.

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

01023 {
01024    struct ast_frame f = { AST_FRAME_CONTROL, };
01025 
01026    f.subclass = control;
01027    f.data = (void *) data;
01028    f.datalen = datalen;
01029 
01030    return ast_queue_frame(chan, &f);
01031 }

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

References __ast_queue_frame().

Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup(), ast_do_masquerade(), ast_dsp_process(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_softhangup_nolock(), cb_events(), console_answer(), console_answer_deprecated(), console_dial(), console_dial_deprecated(), console_flash(), console_flash_deprecated(), console_sendtext(), console_sendtext_deprecated(), dahdi_queue_frame(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), and wakeup_sub().

00989 {
00990    return __ast_queue_frame(chan, fin, 0, NULL);
00991 }

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

References __ast_queue_frame().

Referenced by __ast_read(), and ast_autoservice_stop().

00994 {
00995    return __ast_queue_frame(chan, fin, 1, NULL);
00996 }

int ast_queue_hangup ( struct ast_channel chan  ) 

Queue a hangup frame.

Definition at line 999 of file channel.c.

References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, and f.

Referenced by __oh323_update_info(), __sip_autodestruct(), cleanup_connection(), console_hangup(), console_hangup_deprecated(), dahdi_handle_event(), gtalk_hangup_farend(), gtalk_is_answered(), handle_onhook_message(), handle_request_bye(), handle_request_cancel(), handle_response(), handle_response_invite(), handle_soft_key_event_message(), hangup_chan(), hangup_connection(), iax2_destroy(), iax2_queue_hangup(), local_hangup(), mgcp_queue_hangup(), misdn_answer(), pri_hangup_all(), and retrans_pkt().

01000 {
01001    struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
01002    /* Yeah, let's not change a lock-critical value without locking */
01003    if (!ast_channel_trylock(chan)) {
01004       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01005       ast_channel_unlock(chan);
01006    }
01007    return ast_queue_frame(chan, &f);
01008 }

struct ast_frame* ast_read ( struct ast_channel chan  ) 

Reads a frame.

Parameters:
chan channel to read a frame from Read a frame.
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 2507 of file channel.c.

References __ast_read().

Referenced by __adsi_transmit_messages(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), app_exec(), ast_feature_request_and_dial(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_udptl_bridge(), ast_waitfordigit_full(), async_wait(), autoservice_run(), background_detect_exec(), bridge_native_loop(), bridge_p2p_loop(), channel_spy(), check_goto_on_transfer(), conf_exec(), conf_flush(), conf_run(), dahdi_bridge(), dictate_exec(), disa_exec(), do_atxfer(), do_idle_thread(), do_parking_thread(), do_waiting(), echo_exec(), features_read(), find_cache(), handle_invite_replaces(), handle_recordfile(), iax_park_thread(), ices_exec(), isAnsweringMachine(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), recordthread(), rpt(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().

02508 {
02509    return __ast_read(chan, 0);
02510 }

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

Definition at line 1960 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_deactivate_generator(), ast_format_rate(), AST_FRAME_CNG, ast_internal_timing_enabled(), ast_log(), ast_settimeout(), f, ast_generator::generate, ast_channel::generator, generator_force(), ast_channel::generatordata, LOG_DEBUG, option_debug, ast_channel::timingfd, ast_channel::timingfunc, and ast_channel::writeformat.

Referenced by __ast_read().

01961 {
01962    if (chan->generatordata &&  !ast_internal_timing_enabled(chan)) {
01963       void *tmp = chan->generatordata;
01964       int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL;
01965       int res;
01966       int samples;
01967 
01968       if (chan->timingfunc) {
01969          if (option_debug > 1)
01970             ast_log(LOG_DEBUG, "Generator got voice, switching to phase locked mode\n");
01971          ast_settimeout(chan, 0, NULL, NULL);
01972       }
01973 
01974       chan->generatordata = NULL;     /* reset, to let writes go through */
01975 
01976       if (f->subclass != chan->writeformat) {
01977          float factor;
01978          factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass));
01979          samples = (int) ( ((float) f->samples) * factor );
01980       } else {
01981          samples = f->samples;
01982       }
01983 
01984       if (chan->generator->generate) {
01985          generate = chan->generator->generate;
01986       }
01987       /* This unlock is here based on two assumptions that hold true at this point in the
01988        * code. 1) this function is only called from within __ast_read() and 2) all generators
01989        * call ast_write() in their generate callback.
01990        *
01991        * The reason this is added is so that when ast_write is called, the lock that occurs 
01992        * there will not recursively lock the channel. Doing this will cause intended deadlock 
01993        * avoidance not to work in deeper functions
01994        */
01995       ast_channel_unlock(chan);
01996       res = generate(chan, tmp, f->datalen, samples);
01997       ast_channel_lock(chan);
01998       chan->generatordata = tmp;
01999       if (res) {
02000          if (option_debug > 1)
02001             ast_log(LOG_DEBUG, "Auto-deactivating generator\n");
02002          ast_deactivate_generator(chan);
02003       }
02004 
02005    } else if (f->frametype == AST_FRAME_CNG) {
02006       if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) {
02007          if (option_debug > 1)
02008             ast_log(LOG_DEBUG, "Generator got CNG, switching to timed mode\n");
02009          ast_settimeout(chan, 160, generator_force, chan);
02010       }
02011    }
02012 }

struct ast_frame* ast_read_noaudio ( struct ast_channel chan  ) 

Reads a frame, returning AST_FRAME_NULL frame if audio. Read 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.
Note:
Audio is replaced with AST_FRAME_NULL to avoid transcode when the resulting audio is not necessary.

Definition at line 2512 of file channel.c.

References __ast_read().

Referenced by conf_run().

02513 {
02514    return __ast_read(chan, 1);
02515 }

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

03439 {
03440    return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
03441 }

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

References ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), ast_waitstream_full(), and ast_channel::stream.

Referenced by ast_app_getdata_full(), and ast_readstring().

03444 {
03445    int pos = 0;   /* index in the buffer where we accumulate digits */
03446    int to = ftimeout;
03447 
03448    /* Stop if we're a zombie or need a soft hangup */
03449    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
03450       return -1;
03451    if (!len)
03452       return -1;
03453    for (;;) {
03454       int d;
03455       if (c->stream) {
03456          d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
03457          ast_stopstream(c);
03458          usleep(1000);
03459          if (!d)
03460             d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
03461       } else {
03462          d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
03463       }
03464       if (d < 0)
03465          return -1;
03466       if (d == 0) {
03467          s[pos]='\0';
03468          return 1;
03469       }
03470       if (d == 1) {
03471          s[pos]='\0';
03472          return 2;
03473       }
03474       if (!strchr(enders, d))
03475          s[pos++] = d;
03476       if (strchr(enders, d) || (pos >= len)) {
03477          s[pos]='\0';
03478          return 0;
03479       }
03480       to = timeout;
03481    }
03482    /* Never reached */
03483    return 0;
03484 }

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

References ast_recvtext(), and free.

Referenced by handle_recvchar().

02660 {
02661    int c;
02662    char *buf = ast_recvtext(chan, timeout);
02663    if (buf == NULL)
02664       return -1;  /* error or timeout */
02665    c = *(unsigned char *)buf;
02666    free(buf);
02667    return c;
02668 }

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

References ast_check_hangup(), AST_CONTROL_HANGUP, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_frfree, ast_read(), ast_strndup, ast_waitfor(), and f.

Referenced by ast_recvchar(), and handle_recvtext().

02671 {
02672    int res, done = 0;
02673    char *buf = NULL;
02674    
02675    while (!done) {
02676       struct ast_frame *f;
02677       if (ast_check_hangup(chan))
02678          break;
02679       res = ast_waitfor(chan, timeout);
02680       if (res <= 0) /* timeout or error */
02681          break;
02682       timeout = res; /* update timeout */
02683       f = ast_read(chan);
02684       if (f == NULL)
02685          break; /* no frame */
02686       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
02687          done = 1;   /* force a break */
02688       else if (f->frametype == AST_FRAME_TEXT) {      /* what we want */
02689          buf = ast_strndup((char *) f->data, f->datalen);   /* dup and break */
02690          done = 1;
02691       }
02692       ast_frfree(f);
02693    }
02694    return buf;
02695 }

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

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
Returns:
Returns an ast_channel on success, NULL on failure.

Definition at line 3344 of file channel.c.

References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_translator_best_choice(), capabilities, ast_channel_tech::capabilities, ast_channel_tech::requester, chanlist::tech, and ast_channel_tech::type.

Referenced by __ast_request_and_dial(), agent_request(), ast_call_forward(), ast_feature_request_and_dial(), attempt_reconnect(), begin_dial(), build_conf(), chanavail_exec(), conf_run(), connect_link(), features_alloc(), findmeexec(), ring_entry(), rpt(), rpt_call(), rpt_tele_thread(), and wait_for_answer().

03345 {
03346    struct chanlist *chan;
03347    struct ast_channel *c;
03348    int capabilities;
03349    int fmt;
03350    int res;
03351    int foo;
03352    int videoformat = format & AST_FORMAT_VIDEO_MASK;
03353 
03354    if (!cause)
03355       cause = &foo;
03356    *cause = AST_CAUSE_NOTDEFINED;
03357 
03358    if (AST_LIST_LOCK(&channels)) {
03359       ast_log(LOG_WARNING, "Unable to lock channel list\n");
03360       return NULL;
03361    }
03362 
03363    AST_LIST_TRAVERSE(&backends, chan, list) {
03364       if (strcasecmp(type, chan->tech->type))
03365          continue;
03366 
03367       capabilities = chan->tech->capabilities;
03368       fmt = format & AST_FORMAT_AUDIO_MASK;
03369       res = ast_translator_best_choice(&fmt, &capabilities);
03370       if (res < 0) {
03371          ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format);
03372          *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
03373          AST_LIST_UNLOCK(&channels);
03374          return NULL;
03375       }
03376       AST_LIST_UNLOCK(&channels);
03377       if (!chan->tech->requester)
03378          return NULL;
03379       
03380       if (!(c = chan->tech->requester(type, capabilities | videoformat, data, cause)))
03381          return NULL;
03382 
03383       /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
03384       return c;
03385    }
03386 
03387    ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
03388    *cause = AST_CAUSE_NOSUCHDRIVER;
03389    AST_LIST_UNLOCK(&channels);
03390 
03391    return NULL;
03392 }

struct ast_channel* ast_request_and_dial ( const char *  type,
int  format,
void *  data,
int  timeout,
int *  reason,
const char *  cidnum,
const char *  cidname 
)

Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.

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 unsuceessful)
cidnum Caller-ID Number
cidname Caller-ID Name
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 3339 of file channel.c.

References __ast_request_and_dial().

Referenced by ast_pbx_outgoing_exten().

03340 {
03341    return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL);
03342 }

int ast_safe_sleep ( struct ast_channel chan,
int  ms 
)

Wait for a specied amount of time, looking for hangups.

Parameters:
chan channel to wait for
ms length of time in milliseconds to sleep Waits for a specified amount of time, servicing the channel as required.
Returns:
returns -1 on hangup, otherwise 0.

Definition at line 1221 of file channel.c.

References ast_safe_sleep_conditional().

Referenced by __login_exec(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_dtmf_stream(), ast_senddigit(), builtin_parkcall(), conf_run(), dictate_exec(), flash_exec(), function_ilink(), mgcp_ss(), milliwatt_exec(), moh0_exec(), moh1_exec(), old_milliwatt_exec(), park_call_exec(), pbx_builtin_answer(), pbx_builtin_wait(), play_tone_pair(), playtone(), privacy_exec(), receive_ademco_contact_id(), rpt_call(), rpt_exec(), rpt_tele_thread(), send_morse(), send_tone_telemetry(), skinny_ss(), ss_thread(), testclient_exec(), testserver_exec(), wait_for_hangup(), wait_interval(), and zapateller_exec().

01222 {
01223    return ast_safe_sleep_conditional(chan, ms, NULL, NULL);
01224 }

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

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

Parameters:
chan channel to wait for
ms length of time in milliseconds to sleep
cond a function pointer for testing continue condition
data argument to be passed to the condition test function
Returns:
returns -1 on hangup, otherwise 0. Waits for a specified amount of time, servicing the channel as required. If cond returns 0, this function returns.

Definition at line 1200 of file channel.c.

References ast_frfree, ast_read(), ast_waitfor(), and f.

Referenced by __login_exec(), and ast_safe_sleep().

01201 {
01202    struct ast_frame *f;
01203 
01204    while (ms > 0) {
01205       if (cond && ((*cond)(data) == 0))
01206          return 0;
01207       ms = ast_waitfor(chan, ms);
01208       if (ms < 0)
01209          return -1;
01210       if (ms > 0) {
01211          f = ast_read(chan);
01212          if (!f)
01213             return -1;
01214          ast_frfree(f);
01215       }
01216    }
01217    return 0;
01218 }

char* ast_safe_string_alloc ( const char *  fmt,
  ... 
)

printf the string into a correctly sized mallocd buffer, and return the buffer

return a mallocd string with the result of sprintf of the fmt and following args

Definition at line 409 of file channel.c.

References ast_malloc, and len().

Referenced by dahdi_new(), and features_new().

00410 {
00411    char *b2, buf[1];
00412    int len;
00413    va_list args;
00414 
00415    va_start(args, fmt);
00416    len = vsnprintf(buf, 1, fmt, args);
00417    va_end(args);
00418 
00419    if (!(b2 = ast_malloc(len + 1)))
00420       return NULL;
00421 
00422    va_start(args, fmt);
00423    vsnprintf(b2, len + 1,  fmt, args);
00424    va_end(args);
00425 
00426    return b2;
00427 }

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

Definition at line 5138 of file channel.c.

References ast_say_character_str_full.

Referenced by common_exec(), pbx_builtin_saycharacters(), play_mailbox_owner(), rpt_tele_thread(), and saycharstr().

05140 {
05141         return ast_say_character_str_full(chan, str, ints, lang, -1, -1);
05142 }

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

Definition at line 5132 of file channel.c.

References ast_say_digit_str_full.

Referenced by invent_message(), mgcp_ss(), pbx_builtin_saydigits(), play_message_callerid(), and ss_thread().

05134 {
05135         return ast_say_digit_str_full(chan, str, ints, lang, -1, -1);
05136 }

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

Definition at line 5126 of file channel.c.

References ast_say_digits_full().

Referenced by common_exec(), conf_exec(), park_call_full(), parkandannounce_exec(), and rpt_tele_thread().

05128 {
05129         return ast_say_digits_full(chan, num, ints, lang, -1, -1);
05130 }

int ast_say_digits_full ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  lang,
int  audiofd,
int  ctrlfd 
)

Definition at line 5150 of file channel.c.

References ast_say_digit_str_full.

Referenced by __say_init(), ast_say_digits(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_number_full_cs(), ast_say_number_full_da(), ast_say_number_full_de(), ast_say_number_full_en(), ast_say_number_full_en_GB(), ast_say_number_full_es(), ast_say_number_full_fr(), ast_say_number_full_he(), ast_say_number_full_it(), ast_say_number_full_ka(), ast_say_number_full_nl(), ast_say_number_full_no(), ast_say_number_full_pt(), ast_say_number_full_ru(), ast_say_number_full_se(), and ast_say_number_full_zh().

05152 {
05153         char buf[256];
05154 
05155         snprintf(buf, sizeof(buf), "%d", num);
05156         return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd);
05157 }

int ast_say_enumeration ( struct ast_channel chan,
int  num,
const char *  ints,
const char *  language,
const char *  options 
)

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

05122 {
05123         return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1);
05124 }

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

Definition at line 5114 of file channel.c.

References ast_say_number_full.

Referenced by ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_es(), ast_say_date_fr(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_ka(), ast_say_date_nl(), ast_say_date_pt(), 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_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_zh(), ast_say_time_de(), ast_say_time_en(), ast_say_time_es(), ast_say_time_fr(), ast_say_time_gr(), ast_say_time_ka(), ast_say_time_nl(), ast_say_time_pt(), ast_say_time_pt_BR(), 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(), vm_intro_gr(), vm_intro_he(), vm_intro_multilang(), vm_intro_pt(), and vm_intro_pt_BR().

05116 {
05117         return ast_say_number_full(chan, num, ints, language, options, -1, -1);
05118 }

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

Definition at line 5144 of file channel.c.

References ast_say_phonetic_str_full.

Referenced by pbx_builtin_sayphonetic().

05146 {
05147         return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1);
05148 }

int ast_senddigit ( 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 2769 of file channel.c.

References AST_DEFAULT_EMULATE_DTMF_DURATION, ast_safe_sleep(), ast_senddigit_begin(), ast_senddigit_end(), ast_channel_tech::send_digit_begin, and ast_channel::tech.

Referenced by ast_dtmf_stream(), do_dtmf_phone(), manager_play_dtmf(), and rpt_call().

02770 {
02771    if (chan->tech->send_digit_begin) {
02772       ast_senddigit_begin(chan, digit);
02773       ast_safe_sleep(chan, AST_DEFAULT_EMULATE_DTMF_DURATION);
02774    }
02775    
02776    return ast_senddigit_end(chan, digit, AST_DEFAULT_EMULATE_DTMF_DURATION);
02777 }

int ast_senddigit_begin ( struct ast_channel chan,
char  digit 
)

Definition at line 2710 of file channel.c.

References ast_log(), ast_playtones_start(), LOG_DEBUG, ast_channel::name, option_debug, ast_channel_tech::send_digit_begin, and ast_channel::tech.

Referenced by agent_digit_begin(), ast_senddigit(), ast_write(), and features_digit_begin().

02711 {
02712    /* Device does not support DTMF tones, lets fake
02713     * it by doing our own generation. */
02714    static const char* dtmf_tones[] = {
02715       "941+1336", /* 0 */
02716       "697+1209", /* 1 */
02717       "697+1336", /* 2 */
02718       "697+1477", /* 3 */
02719       "770+1209", /* 4 */
02720       "770+1336", /* 5 */
02721       "770+1477", /* 6 */
02722       "852+1209", /* 7 */
02723       "852+1336", /* 8 */
02724       "852+1477", /* 9 */
02725       "697+1633", /* A */
02726       "770+1633", /* B */
02727       "852+1633", /* C */
02728       "941+1633", /* D */
02729       "941+1209", /* * */
02730       "941+1477"  /* # */
02731    };
02732 
02733    if (!chan->tech->send_digit_begin)
02734       return 0;
02735 
02736    if (!chan->tech->send_digit_begin(chan, digit))
02737       return 0;
02738 
02739    if (digit >= '0' && digit <='9')
02740       ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
02741    else if (digit >= 'A' && digit <= 'D')
02742       ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
02743    else if (digit == '*')
02744       ast_playtones_start(chan, 0, dtmf_tones[14], 0);
02745    else if (digit == '#')
02746       ast_playtones_start(chan, 0, dtmf_tones[15], 0);
02747    else {
02748       /* not handled */
02749       if (option_debug)
02750          ast_log(LOG_DEBUG, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name);
02751    }
02752 
02753    return 0;
02754 }

int ast_senddigit_end ( struct ast_channel chan,
char  digit,
unsigned int  duration 
)

Definition at line 2756 of file channel.c.

References ast_playtones_stop(), ast_channel::generator, ast_channel_tech::send_digit_end, and ast_channel::tech.

Referenced by agent_digit_end(), ast_senddigit(), ast_write(), and features_digit_end().

02757 {
02758    int res = -1;
02759 
02760    if (chan->tech->send_digit_end)
02761       res = chan->tech->send_digit_end(chan, digit, duration);
02762 
02763    if (res && chan->generator)
02764       ast_playtones_stop(chan);
02765    
02766    return 0;
02767 }

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

Sends text to a channel Write text to a display on a channel.

Parameters:
chan channel to act upon
text string of text to send on the channel
Returns:
Returns 0 on success, -1 on failure

Definition at line 2697 of file channel.c.

References ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_test_flag, CHECK_BLOCKING, ast_channel_tech::send_text, and ast_channel::tech.

Referenced by agent_sendtext(), handle_sendtext(), and sendtext_exec().

02698 {
02699    int res = 0;
02700    /* Stop if we're a zombie or need a soft hangup */
02701    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
02702       return -1;
02703    CHECK_BLOCKING(chan);
02704    if (chan->tech->send_text)
02705       res = chan->tech->send_text(chan, text);
02706    ast_clear_flag(chan, AST_FLAG_BLOCKING);
02707    return res;
02708 }

void ast_set_callerid ( struct ast_channel chan,
const char *  cidnum,
const char *  cidname,
const char *  ani 
)

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

Definition at line 4025 of file channel.c.

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

Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), callerid_write(), dahdi_read(), disa_exec(), findmeexec(), handle_setcallerid(), lookupcidname_exec(), mgcp_ss(), privacy_exec(), read_config(), setcallerid_exec(), skinny_newcall(), ss_thread(), and wait_for_answer().

04026 {
04027    ast_channel_lock(chan);
04028 
04029    if (callerid) {
04030       if (chan->cid.cid_num)
04031          free(chan->cid.cid_num);
04032       chan->cid.cid_num = ast_strdup(callerid);
04033    }
04034    if (calleridname) {
04035       if (chan->cid.cid_name)
04036          free(chan->cid.cid_name);
04037       chan->cid.cid_name = ast_strdup(calleridname);
04038    }
04039    if (ani) {
04040       if (chan->cid.cid_ani)
04041          free(chan->cid.cid_ani);
04042       chan->cid.cid_ani = ast_strdup(ani);
04043    }
04044 
04045    report_new_callerid(chan);
04046 
04047    ast_channel_unlock(chan);
04048 }

int ast_set_read_format ( struct ast_channel chan,
int  format 
)

Sets read format on channel chan Set read format for channel to whichever component of "format" is best.

Parameters:
chan channel to change
format format to change to
Returns:
Returns 0 on success, -1 on failure

Definition at line 3089 of file channel.c.

References ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().

Referenced by __ast_play_and_record(), __login_exec(), __oh323_update_info(), agent_call(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_channel_make_compatible(), ast_do_masquerade(), attempt_reconnect(), background_detect_exec(), build_conf(), conf_run(), connect_link(), dictate_exec(), disa_exec(), do_waiting(), eagi_exec(), echo_exec(), gtalk_rtp_read(), handle_recordfile(), ices_exec(), isAnsweringMachine(), measurenoise(), mgcp_rtp_read(), oh323_rtp_read(), old_milliwatt_exec(), process_sdp(), rpt(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), and update_features().

03090 {
03091    return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat,
03092            &chan->readtrans, 0);
03093 }

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

04882 {
04883    struct ast_variable *cur;
04884 
04885    for (cur = vars; cur; cur = cur->next)
04886       pbx_builtin_setvar_helper(chan, cur->name, cur->value);  
04887 }

int ast_set_write_format ( struct ast_channel chan,
int  format 
)

Sets write format on channel chan Set write format for channel to whichever compoent of "format" is best.

Parameters:
chan channel to change
format new format for writing
Returns:
Returns 0 on success, -1 on failure

Definition at line 3095 of file channel.c.

References ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.

Referenced by __login_exec(), __oh323_update_info(), agent_call(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_channel_make_compatible(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_do_masquerade(), ast_openstream_full(), ast_stopstream(), attempt_reconnect(), build_conf(), chanspy_exec(), conf_run(), connect_link(), disa_exec(), echo_exec(), extenspy_exec(), gtalk_rtp_read(), linear_alloc(), linear_release(), mgcp_rtp_read(), moh_alloc(), moh_files_release(), moh_release(), mp3_exec(), NBScat_exec(), oh323_rtp_read(), old_milliwatt_exec(), playtones_alloc(), playtones_release(), process_sdp(), rpt(), send_waveform_to_channel(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), tonepair_alloc(), tonepair_release(), and update_features().

03096 {
03097    return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat,
03098            &chan->writetrans, 1);
03099 }

int ast_setstate ( struct ast_channel chan,
enum ast_channel_state  state 
)

Change the state of a channel.

Definition at line 4050 of file channel.c.

References ast_channel::_state, AST_CHANNEL_NAME, ast_copy_string(), ast_device_state_changed_literal(), ast_state2str(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, manager_event(), name, ast_channel::name, S_OR, and ast_channel::uniqueid.

Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), agent_call(), alsa_answer(), ast_answer(), cb_events(), check_availability(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), gtalk_call(), gtalk_newcall(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_response_invite(), handle_soft_key_event_message(), handle_stimulus_message(), iax2_call(), mgcp_answer(), mgcp_call(), mgcp_ss(), misdn_call(), misdn_indication(), nbs_call(), nbs_hangup(), oh323_answer(), oss_answer(), pbx_builtin_busy(), pbx_builtin_congestion(), phone_answer(), phone_call(), phone_exception(), phone_hangup(), phone_write(), release_chan(), sip_answer(), skinny_answer(), skinny_call(), skinny_newcall(), ss_thread(), and update_state().

04051 {
04052    char name[AST_CHANNEL_NAME], *dashptr;
04053    int oldstate = chan->_state;
04054 
04055    if (oldstate == state)
04056       return 0;
04057 
04058    ast_copy_string(name, chan->name, sizeof(name));
04059    if ((dashptr = strrchr(name, '-'))) {
04060       *dashptr = '\0';
04061    }
04062 
04063    chan->_state = state;
04064    ast_device_state_changed_literal(name);
04065    /* setstate used to conditionally report Newchannel; this is no more */
04066    manager_event(EVENT_FLAG_CALL,
04067             "Newstate",
04068             "Channel: %s\r\n"
04069             "State: %s\r\n"
04070             "CallerID: %s\r\n"
04071             "CallerIDName: %s\r\n"
04072             "Uniqueid: %s\r\n",
04073             chan->name, ast_state2str(chan->_state),
04074             S_OR(chan->cid.cid_num, "<unknown>"),
04075             S_OR(chan->cid.cid_name, "<unknown>"),
04076             chan->uniqueid);
04077 
04078    return 0;
04079 }

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

Definition at line 1863 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_log(), LOG_DEBUG, option_debug, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.

Referenced by ast_activate_generator(), ast_deactivate_generator(), ast_read_generator_actions(), ast_readaudio_callback(), and filestream_destructor().

01864 {
01865    int res = -1;
01866 #ifdef HAVE_DAHDI
01867    ast_channel_lock(c);
01868    if (c->timingfd > -1) {
01869       if (!func) {
01870          samples = 0;
01871          data = 0;
01872       }
01873       if (option_debug)
01874          ast_log(LOG_DEBUG, "Scheduling timer at %d sample intervals\n", samples);
01875       res = ioctl(c->timingfd, DAHDI_TIMERCONFIG, &samples);
01876       c->timingfunc = func;
01877       c->timingdata = data;
01878    }
01879    ast_channel_unlock(c);
01880 #endif   
01881    return res;
01882 }

int ast_shutting_down ( void   ) 

Returns non-zero if Asterisk is being shut down.

Returns non-zero if Asterisk is being shut down

Definition at line 461 of file channel.c.

Referenced by handle_request_options().

00462 {
00463    return shutting_down;
00464 }

int ast_softhangup ( struct ast_channel chan,
int  cause 
)

Softly hangup up a channel.

Parameters:
chan channel to be soft-hung-up Call the protocol layer, but don't destroy the channel structure (use this if you are trying to safely hangup a channel managed by another thread.
cause Ast hangupcause for hangup
Returns:
Returns 0 regardless

Definition at line 1463 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().

Referenced by __ast_module_user_hangup_all(), __login_exec(), __unload_module(), action_hangup(), agent_hangup(), agent_logoff(), ast_begin_shutdown(), ast_dial_join(), conf_free(), connect_link(), dahdi_handle_event(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), manager_park(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().

01464 {
01465    int res;
01466    ast_channel_lock(chan);
01467    res = ast_softhangup_nolock(chan, cause);
01468    ast_channel_unlock(chan);
01469    return res;
01470 }

int ast_softhangup_nolock ( struct ast_channel chan,
int  cause 
)

Softly hangup up a channel (no channel lock).

Parameters:
chan channel to be soft-hung-up
cause Ast hangupcause for hangup (see cause.h)

Definition at line 1449 of file channel.c.

References ast_channel::_softhangup, AST_FLAG_BLOCKING, ast_log(), ast_null_frame, ast_queue_frame(), ast_test_flag, ast_channel::blocker, LOG_DEBUG, ast_channel::name, and option_debug.

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

01450 {
01451    if (option_debug)
01452       ast_log(LOG_DEBUG, "Soft-Hanging up channel '%s'\n", chan->name);
01453    /* Inform channel driver that we need to be hung up, if it cares */
01454    chan->_softhangup |= cause;
01455    ast_queue_frame(chan, &ast_null_frame);
01456    /* Interrupt any poll call or such */
01457    if (ast_test_flag(chan, AST_FLAG_BLOCKING))
01458       pthread_kill(chan->blocker, SIGURG);
01459    return 0;
01460 }

char* ast_state2str ( enum  ast_channel_state  ) 

Gives the string form of a given channel state.

Parameters:
ast_channel_state state to get the name of Give a name to a state Returns the text form of the binary state given

Definition at line 600 of file channel.c.

References AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DIALING_OFFHOOK, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_threadstorage_get(), STATE2STR_BUFSIZE, and state2str_threadbuf.

Referenced by action_status(), agent_hangup(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_chanlist_deprecated(), handle_invite_replaces(), handle_showchan(), handle_showchan_deprecated(), local_attended_transfer(), mgcp_new(), serialize_showchan(), and sip_hangup().

00601 {
00602    char *buf;
00603 
00604    switch(state) {
00605    case AST_STATE_DOWN:
00606       return "Down";
00607    case AST_STATE_RESERVED:
00608       return "Rsrvd";
00609    case AST_STATE_OFFHOOK:
00610       return "OffHook";
00611    case AST_STATE_DIALING:
00612       return "Dialing";
00613    case AST_STATE_RING:
00614       return "Ring";
00615    case AST_STATE_RINGING:
00616       return "Ringing";
00617    case AST_STATE_UP:
00618       return "Up";
00619    case AST_STATE_BUSY:
00620       return "Busy";
00621    case AST_STATE_DIALING_OFFHOOK:
00622       return "Dialing Offhook";
00623    case AST_STATE_PRERING:
00624       return "Pre-ring";
00625    default:
00626       if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
00627          return "Unknown";
00628       snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state);
00629       return buf;
00630    }
00631 }

int ast_str2cause ( const char *  name  ) 

Convert a symbolic hangup cause to number.

Parameters:
name string form of the cause Returns the cause code

Definition at line 588 of file channel.c.

References causes.

Referenced by pbx_builtin_hangup().

00589 {
00590    int x;
00591 
00592    for (x = 0; x < sizeof(causes) / sizeof(causes[0]); x++)
00593       if (strncasecmp(causes[x].name, name, strlen(causes[x].name)) == 0)
00594          return causes[x].cause;
00595 
00596    return -1;
00597 }

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

Play a tone pair for a given amount of time

Definition at line 4753 of file channel.c.

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

Referenced by zapateller_exec().

04754 {
04755    int res;
04756 
04757    if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
04758       return res;
04759 
04760    /* Give us some wiggle room */
04761    while (chan->generatordata && ast_waitfor(chan, 100) >= 0) {
04762       struct ast_frame *f = ast_read(chan);
04763       if (f)
04764          ast_frfree(f);
04765       else
04766          return -1;
04767    }
04768    return 0;
04769 }

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

Start a tone going

Definition at line 4735 of file channel.c.

References ast_activate_generator(), tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, tonepair, and tonepair_def::vol.

Referenced by ast_tonepair(), play_dialtone(), play_tone_pair(), rpt_tele_thread(), and sendnoise().

04736 {
04737    struct tonepair_def d = { 0, };
04738 
04739    d.freq1 = freq1;
04740    d.freq2 = freq2;
04741    d.duration = duration;
04742    d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
04743    if (ast_activate_generator(chan, &tonepair, &d))
04744       return -1;
04745    return 0;
04746 }

void ast_tonepair_stop ( struct ast_channel chan  ) 

Stop a tone from playing

Definition at line 4748 of file channel.c.

References ast_deactivate_generator().

Referenced by sendnoise().

04749 {
04750    ast_deactivate_generator(chan);
04751 }

int ast_transfer ( struct ast_channel chan,
char *  dest 
)

Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.

Called by:

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

03421 {
03422    int res = -1;
03423 
03424    /* Stop if we're a zombie or need a soft hangup */
03425    ast_channel_lock(chan);
03426    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
03427       if (chan->tech->transfer) {
03428          res = chan->tech->transfer(chan, dest);
03429          if (!res)
03430             res = 1;
03431       } else
03432          res = 0;
03433    }
03434    ast_channel_unlock(chan);
03435    return res;
03436 }

char* ast_transfercapability2str ( int  transfercapability  )  const

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 capbility

Definition at line 634 of file channel.c.

References AST_TRANS_CAP_3_1K_AUDIO, AST_TRANS_CAP_DIGITAL, AST_TRANS_CAP_DIGITAL_W_TONES, AST_TRANS_CAP_RESTRICTED_DIGITAL, AST_TRANS_CAP_SPEECH, and AST_TRANS_CAP_VIDEO.

Referenced by cb_events(), dahdi_call(), dahdi_new(), misdn_call(), and oh323_call().

00635 {
00636    switch(transfercapability) {
00637    case AST_TRANS_CAP_SPEECH:
00638       return "SPEECH";
00639    case AST_TRANS_CAP_DIGITAL:
00640       return "DIGITAL";
00641    case AST_TRANS_CAP_RESTRICTED_DIGITAL:
00642       return "RESTRICTED_DIGITAL";
00643    case AST_TRANS_CAP_3_1K_AUDIO:
00644       return "3K1AUDIO";
00645    case AST_TRANS_CAP_DIGITAL_W_TONES:
00646       return "DIGITAL_W_TONES";
00647    case AST_TRANS_CAP_VIDEO:
00648       return "VIDEO";
00649    default:
00650       return "UNKNOWN";
00651    }
00652 }

void ast_uninstall_music_functions ( void   ) 

Definition at line 4816 of file channel.c.

References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.

Referenced by unload_module().

04817 {
04818    ast_moh_start_ptr = NULL;
04819    ast_moh_stop_ptr = NULL;
04820    ast_moh_cleanup_ptr = NULL;
04821 }

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

References ast_waitfor_nandfds().

Referenced by __adsi_transmit_messages(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), ast_dtmf_stream(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), async_wait(), background_detect_exec(), channel_spy(), conf_exec(), conf_flush(), dictate_exec(), disa_exec(), do_idle_thread(), do_waiting(), echo_exec(), handle_recordfile(), ices_exec(), isAnsweringMachine(), measurenoise(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), recordthread(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), wait_for_hangup(), waitforring_exec(), and waitstream_core().

01848 {
01849    int oldms = ms;   /* -1 if no timeout */
01850 
01851    ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
01852    if ((ms < 0) && (oldms < 0))
01853       ms = 0;
01854    return ms;
01855 }

struct ast_channel* ast_waitfor_n ( struct ast_channel **  chan,
int  n,
int *  ms 
)

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

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

References ast_waitfor_nandfds().

Referenced by ast_feature_request_and_dial(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), dahdi_bridge(), misdn_bridge(), monitor_dial(), rpt(), wait_for_answer(), and wait_for_winner().

01843 {
01844    return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
01845 }

int ast_waitfor_n_fd ( int *  fds,
int  n,
int *  ms,
int *  exception 
)

Waits for input on an fd This version works on fd's only. Be careful with it.

Definition at line 1686 of file channel.c.

References ast_waitfor_nandfds().

Referenced by dundi_lookup_internal(), and dundi_precache_internal().

01687 {
01688    int winner = -1;
01689    ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
01690    return winner;
01691 }

struct ast_channel* ast_waitfor_nandfds ( struct ast_channel **  chan,
int  n,
int *  fds,
int  nfds,
int *  exception,
int *  outfd,
int *  ms 
)

Waits for activity on a group of channels.

Parameters:
chan an array of pointers to channels
n number of channels that are to be waited upon
fds an array of fds to wait upon
nfds the number of fds to wait upon
exception exception flag
outfd fd that had activity on it
ms how long the wait was Big momma function here. Wait for activity on any of the n channels, or any of the nfds file descriptors.
Returns:
Returns the channel with activity, or NULL on error or if an FD came first. If the FD came first, it will be returned in outfd, otherwise, outfd will be -1

Definition at line 1694 of file channel.c.

References ast_channel::_softhangup, ast_add_fd(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, ast_log(), AST_MAX_FDS, ast_poll, ast_set_flag, AST_SOFTHANGUP_TIMEOUT, ast_tvdiff_ms(), ast_tvnow(), CHECK_BLOCKING, errno, and ast_channel::whentohangup.

Referenced by app_exec(), ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), conf_run(), find_cache(), run_agi(), and waitstream_core().

01696 {
01697    struct timeval start = { 0 , 0 };
01698    struct pollfd *pfds = NULL;
01699    int res;
01700    long rms;
01701    int x, y, max;
01702    int sz;
01703    time_t now = 0;
01704    long whentohangup = 0, diff;
01705    struct ast_channel *winner = NULL;
01706    struct fdmap {
01707       int chan;
01708       int fdno;
01709    } *fdmap = NULL;
01710 
01711    if ((sz = n * AST_MAX_FDS + nfds)) {
01712       pfds = alloca(sizeof(*pfds) * sz);
01713       fdmap = alloca(sizeof(*fdmap) * sz);
01714    }
01715 
01716    if (outfd)
01717       *outfd = -99999;
01718    if (exception)
01719       *exception = 0;
01720    
01721    /* Perform any pending masquerades */
01722    for (x=0; x < n; x++) {
01723       ast_channel_lock(c[x]);
01724       if (c[x]->masq) {
01725          if (ast_do_masquerade(c[x])) {
01726             ast_log(LOG_WARNING, "Masquerade failed\n");
01727             *ms = -1;
01728             ast_channel_unlock(c[x]);
01729             return NULL;
01730          }
01731       }
01732       if (c[x]->whentohangup) {
01733          if (!whentohangup)
01734             time(&now);
01735          diff = c[x]->whentohangup - now;
01736          if (diff < 1) {
01737             /* Should already be hungup */
01738             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
01739             ast_channel_unlock(c[x]);
01740             return c[x];
01741          }
01742          if (!whentohangup || (diff < whentohangup))
01743             whentohangup = diff;
01744       }
01745       ast_channel_unlock(c[x]);
01746    }
01747    /* Wait full interval */
01748    rms = *ms;
01749    if (whentohangup) {
01750       rms = whentohangup * 1000;              /* timeout in milliseconds */
01751       if (*ms >= 0 && *ms < rms)    /* original *ms still smaller */
01752          rms =  *ms;
01753    }
01754    /*
01755     * Build the pollfd array, putting the channels' fds first,
01756     * followed by individual fds. Order is important because
01757     * individual fd's must have priority over channel fds.
01758     */
01759    max = 0;
01760    for (x=0; x<n; x++) {
01761       for (y=0; y<AST_MAX_FDS; y++) {
01762          fdmap[max].fdno = y;  /* fd y is linked to this pfds */
01763          fdmap[max].chan = x;  /* channel x is linked to this pfds */
01764          max += ast_add_fd(&pfds[max], c[x]->fds[y]);
01765       }
01766       CHECK_BLOCKING(c[x]);
01767    }
01768    /* Add the individual fds */
01769    for (x=0; x<nfds; x++) {
01770       fdmap[max].chan = -1;
01771       max += ast_add_fd(&pfds[max], fds[x]);
01772    }
01773 
01774    if (*ms > 0)
01775       start = ast_tvnow();
01776    
01777    if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
01778       do {
01779          int kbrms = rms;
01780          if (kbrms > 600000)
01781             kbrms = 600000;
01782          res = ast_poll(pfds, max, kbrms);
01783          if (!res)
01784             rms -= kbrms;
01785       } while (!res && (rms > 0));
01786    } else {
01787       res = ast_poll(pfds, max, rms);
01788    }
01789    for (x=0; x<n; x++)
01790       ast_clear_flag(c[x], AST_FLAG_BLOCKING);
01791    if (res < 0) { /* Simulate a timeout if we were interrupted */
01792       if (errno != EINTR)
01793          *ms = -1;
01794       return NULL;
01795    }
01796    if (whentohangup) {   /* if we have a timeout, check who expired */
01797       time(&now);
01798       for (x=0; x<n; x++) {
01799          if (c[x]->whentohangup && now >= c[x]->whentohangup) {
01800             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
01801             if (winner == NULL)
01802                winner = c[x];
01803          }
01804       }
01805    }
01806    if (res == 0) { /* no fd ready, reset timeout and done */
01807       *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
01808       return winner;
01809    }
01810    /*
01811     * Then check if any channel or fd has a pending event.
01812     * Remember to check channels first and fds last, as they
01813     * must have priority on setting 'winner'
01814     */
01815    for (x = 0; x < max; x++) {
01816       res = pfds[x].revents;
01817       if (res == 0)
01818          continue;
01819       if (fdmap[x].chan >= 0) {  /* this is a channel */
01820          winner = c[fdmap[x].chan]; /* override previous winners */
01821          if (res & POLLPRI)
01822             ast_set_flag(winner, AST_FLAG_EXCEPTION);
01823          else
01824             ast_clear_flag(winner, AST_FLAG_EXCEPTION);
01825          winner->fdno = fdmap[x].fdno;
01826       } else {       /* this is an fd */
01827          if (outfd)
01828             *outfd = pfds[x].fd;
01829          if (exception)
01830             *exception = (res & POLLPRI) ? -1 : 0;
01831          winner = NULL;
01832       }
01833    }
01834    if (*ms > 0) {
01835       *ms -= ast_tvdiff_ms(ast_tvnow(), start);
01836       if (*ms < 0)
01837          *ms = 0;
01838    }
01839    return winner;
01840 }

int ast_waitfordigit ( struct ast_channel c,
int  ms 
)

Waits for a digit.

!

Parameters:
c channel to wait for a digit on
ms how many milliseconds to wait
Returns:
Returns <0 on error, 0 on no entry, and the digit on success.

Definition at line 1858 of file channel.c.

References ast_waitfordigit_full().

Referenced by _while_exec(), advanced_options(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_print(), ast_adsi_read_encoded_dtmf(), ast_adsi_transmit_message_full(), ast_app_dtget(), ast_control_streamfile(), ast_record_review(), collect_digits(), common_exec(), cpeid_exec(), dialout(), directory_exec(), do_atxfer(), forward_message(), get_folder(), ivr_dispatch(), mgcp_ss(), my_getsigstr(), pbx_builtin_waitexten(), play_mailbox_owner(), play_record_review(), read_exec(), read_newoption(), retrydial_exec(), sendnoise(), ss_thread(), testclient_exec(), testserver_exec(), vm_execmain(), vm_forwardoptions(), vm_instructions(), vm_options(), vm_tempgreeting(), wait_a_bit(), and wait_our_turn().

01859 {
01860    return ast_waitfordigit_full(c, ms, -1, -1);
01861 }

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

References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_set_flag, ast_test_flag, ast_waitfor_nandfds(), errno, and f.

Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().

01885 {
01886    /* Stop if we're a zombie or need a soft hangup */
01887    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
01888       return -1;
01889 
01890    /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
01891    ast_set_flag(c, AST_FLAG_END_DTMF_ONLY);
01892 
01893    /* Wait for a digit, no more than ms milliseconds total. */
01894    while (ms) {
01895       struct ast_channel *rchan;
01896       int outfd;
01897 
01898       errno = 0;
01899       rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
01900       if (!rchan && outfd < 0 && ms) {
01901          if (errno == 0 || errno == EINTR)
01902             continue;
01903          ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
01904          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
01905          return -1;
01906       } else if (outfd > -1) {
01907          /* The FD we were watching has something waiting */
01908          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
01909          return 1;
01910       } else if (rchan) {
01911          int res;
01912          struct ast_frame *f = ast_read(c);
01913          if (!f)
01914             return -1;
01915 
01916          switch(f->frametype) {
01917          case AST_FRAME_DTMF_BEGIN:
01918             break;
01919          case AST_FRAME_DTMF_END:
01920             res = f->subclass;
01921             ast_frfree(f);
01922             ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
01923             return res;
01924          case AST_FRAME_CONTROL:
01925             switch(f->subclass) {
01926             case AST_CONTROL_HANGUP:
01927                ast_frfree(f);
01928                ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
01929                return -1;
01930             case AST_CONTROL_RINGING:
01931             case AST_CONTROL_ANSWER:
01932             case AST_CONTROL_SRCUPDATE:
01933                /* Unimportant */
01934                break;
01935             default:
01936                ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass);
01937                break;
01938             }
01939             break;
01940          case AST_FRAME_VOICE:
01941             /* Write audio if appropriate */
01942             if (audiofd > -1) {
01943                if (write(audiofd, f->data, f->datalen) < 0) {
01944                   ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
01945                }
01946             }
01947          default:
01948             /* Ignore */
01949             break;
01950          }
01951          ast_frfree(f);
01952       }
01953    }
01954 
01955    ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
01956 
01957    return 0; /* Time is up */
01958 }

struct ast_channel* ast_walk_channel_by_exten_locked ( const struct ast_channel chan,
const char *  exten,
const char *  context 
)

Get next channel by exten (and optionally context) and lock it.

Definition at line 1193 of file channel.c.

References channel_find_locked().

Referenced by next_channel().

01195 {
01196    return channel_find_locked(chan, NULL, 0, context, exten);
01197 }

struct ast_channel* ast_walk_channel_by_name_prefix_locked ( const struct ast_channel chan,
const char *  name,
const int  namelen 
)

Get channel by name prefix (locks channel).

Definition at line 1180 of file channel.c.

References channel_find_locked().

Referenced by next_channel().

01182 {
01183    return channel_find_locked(chan, name, namelen, NULL, NULL);
01184 }

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

References ast_channel::_softhangup, AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_deactivate_generator(), ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, AST_LIST_NEXT, ast_log(), AST_MONITOR_RUNNING, ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), ast_channel::audiohooks, CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_channel::fout, ast_frame::frame_list, FRAMECOUNT_INC, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, ast_frame::len, LOG_DEBUG, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, MONITOR_CONSTANT_DELAY, MONITOR_DELAY, ast_channel::name, ast_frame::next, option_debug, ast_channel::outsmpl, ast_channel::rawwriteformat, ast_frame::samples, SEEK_FORCECUR, ast_channel_tech::send_html, ast_channel_tech::send_text, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel_tech::write, ast_channel_monitor::write_stream, ast_channel_tech::write_video, and ast_channel::writetrans.

Referenced by adsi_careful_send(), agent_write(), ast_prod(), ast_readaudio_callback(), ast_readvideo_callback(), ast_udptl_bridge(), ast_write_video(), bridge_native_loop(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), features_write(), function_ilink(), gen_generate(), handle_link_data(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), NBScat_exec(), rpt(), send_link_dtmf(), send_tone_burst(), send_waveform_to_channel(), silence_generator_generate(), spy_generate(), and wait_for_answer().

02809 {
02810    int res = -1;
02811    int count = 0;
02812    struct ast_frame *f = NULL;
02813 
02814    /*Deadlock avoidance*/
02815    while(ast_channel_trylock(chan)) {
02816       /*cannot goto done since the channel is not locked*/
02817       if(count++ > 10) {
02818          if(option_debug)
02819             ast_log(LOG_DEBUG, "Deadlock avoided for write to channel '%s'\n", chan->name);
02820          return 0;
02821       }
02822       usleep(1);
02823    }
02824    /* Stop if we're a zombie or need a soft hangup */
02825    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
02826       goto done;
02827 
02828    /* Handle any pending masquerades */
02829    if (chan->masq && ast_do_masquerade(chan)) {
02830       ast_log(LOG_WARNING, "Failed to perform masquerade\n");
02831       goto done;
02832    }
02833    if (chan->masqr) {
02834       res = 0; /* XXX explain, why 0 ? */
02835       goto done;
02836    }
02837    if (chan->generatordata) {
02838       if (ast_test_flag(chan, AST_FLAG_WRITE_INT))
02839          ast_deactivate_generator(chan);
02840       else {
02841          if (fr->frametype == AST_FRAME_DTMF_END) {
02842             /* There is a generator running while we're in the middle of a digit.
02843              * It's probably inband DTMF, so go ahead and pass it so it can
02844              * stop the generator */
02845             ast_clear_flag(chan, AST_FLAG_BLOCKING);
02846             ast_channel_unlock(chan);
02847             res = ast_senddigit_end(chan, fr->subclass, fr->len);
02848             ast_channel_lock(chan);
02849             CHECK_BLOCKING(chan);
02850          } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) {
02851             /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */
02852             res = (chan->tech->indicate == NULL) ? 0 :
02853                chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen);
02854          }
02855          res = 0; /* XXX explain, why 0 ? */
02856          goto done;
02857       }
02858    }
02859    /* High bit prints debugging */
02860    if (chan->fout & DEBUGCHAN_FLAG)
02861       ast_frame_dump(chan->name, fr, ">>");
02862    CHECK_BLOCKING(chan);
02863    switch(fr->frametype) {
02864    case AST_FRAME_CONTROL:
02865       res = (chan->tech->indicate == NULL) ? 0 :
02866          chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen);
02867       break;
02868    case AST_FRAME_DTMF_BEGIN:
02869       if (chan->audiohooks) {
02870          struct ast_frame *old_frame = fr;
02871          fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
02872          if (old_frame != fr)
02873             f = fr;
02874       }
02875       ast_clear_flag(chan, AST_FLAG_BLOCKING);
02876       ast_channel_unlock(chan);
02877       res = ast_senddigit_begin(chan, fr->subclass);
02878       ast_channel_lock(chan);
02879       CHECK_BLOCKING(chan);
02880       break;
02881    case AST_FRAME_DTMF_END:
02882       if (chan->audiohooks) {
02883          struct ast_frame *new_frame = fr;
02884 
02885          new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
02886          if (new_frame != fr) {
02887             ast_frfree(new_frame);
02888          }
02889       }
02890       ast_clear_flag(chan, AST_FLAG_BLOCKING);
02891       ast_channel_unlock(chan);
02892       res = ast_senddigit_end(chan, fr->subclass, fr->len);
02893       ast_channel_lock(chan);
02894       CHECK_BLOCKING(chan);
02895       break;
02896    case AST_FRAME_TEXT:
02897       res = (chan->tech->send_text == NULL) ? 0 :
02898          chan->tech->send_text(chan, (char *) fr->data);
02899       break;
02900    case AST_FRAME_HTML:
02901       res = (chan->tech->send_html == NULL) ? 0 :
02902          chan->tech->send_html(chan, fr->subclass, (char *) fr->data, fr->datalen);
02903       break;
02904    case AST_FRAME_VIDEO:
02905       /* XXX Handle translation of video codecs one day XXX */
02906       res = (chan->tech->write_video == NULL) ? 0 :
02907          chan->tech->write_video(chan, fr);
02908       break;
02909    case AST_FRAME_MODEM:
02910       res = (chan->tech->write == NULL) ? 0 :
02911          chan->tech->write(chan, fr);
02912       break;
02913    case AST_FRAME_VOICE:
02914       if (chan->tech->write == NULL)
02915          break;   /*! \todo XXX should return 0 maybe ? */
02916 
02917       /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
02918       if (fr->subclass == chan->rawwriteformat)
02919          f = fr;
02920       else
02921          f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
02922 
02923       /* If we have no frame of audio, then we have to bail out */
02924       if (!f) {
02925          res = 0;
02926          break;
02927       }
02928 
02929       if (chan->audiohooks) {
02930          struct ast_frame *new_frame, *cur;
02931 
02932          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
02933             new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur);
02934             if (new_frame != cur) {
02935                ast_frfree(new_frame);
02936             }
02937          }
02938       }
02939       
02940       /* If Monitor is running on this channel, then we have to write frames out there too */
02941       /* the translator on chan->writetrans may have returned multiple frames
02942          from the single frame we passed in; if so, feed each one of them to the
02943          monitor */
02944       if (chan->monitor && chan->monitor->write_stream) {
02945          struct ast_frame *cur;
02946 
02947          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
02948          /* XXX must explain this code */
02949 #ifndef MONITOR_CONSTANT_DELAY
02950             int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples;
02951             if (jump >= 0) {
02952                jump = chan->insmpl - chan->outsmpl;
02953                if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
02954                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
02955                chan->outsmpl += jump + cur->samples;
02956             } else {
02957                chan->outsmpl += cur->samples;
02958             }
02959 #else
02960             int jump = chan->insmpl - chan->outsmpl;
02961             if (jump - MONITOR_DELAY >= 0) {
02962                if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1)
02963                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
02964                chan->outsmpl += jump;
02965             } else {
02966                chan->outsmpl += cur->samples;
02967             }
02968 #endif
02969             if (chan->monitor->state == AST_MONITOR_RUNNING) {
02970                if (ast_writestream(chan->monitor->write_stream, cur) < 0)
02971                   ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
02972             }
02973          }
02974       }
02975 
02976       /* the translator on chan->writetrans may have returned multiple frames
02977          from the single frame we passed in; if so, feed each one of them to the
02978          channel, freeing each one after it has been written */
02979       if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
02980          struct ast_frame *cur, *next;
02981          unsigned int skip = 0;
02982 
02983          for (cur = f, next = AST_LIST_NEXT(cur, frame_list);
02984               cur;
02985               cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) {
02986             if (!skip) {
02987                if ((res = chan->tech->write(chan, cur)) < 0) {
02988                   chan->_softhangup |= AST_SOFTHANGUP_DEV;
02989                   skip = 1;
02990                } else if (next) {
02991                   /* don't do this for the last frame in the list,
02992                      as the code outside the loop will do it once
02993                   */
02994                   chan->fout = FRAMECOUNT_INC(chan->fout);
02995                }
02996             }
02997             ast_frfree(cur);
02998          }
02999 
03000          /* reset f so the code below doesn't attempt to free it */
03001          f = NULL;
03002       } else {
03003          res = chan->tech->write(chan, f);
03004       }
03005       break;
03006    case AST_FRAME_NULL:
03007    case AST_FRAME_IAX:
03008       /* Ignore these */
03009       res = 0;
03010       break;
03011    default:
03012       /* At this point, fr is the incoming frame and f is NULL.  Channels do
03013        * not expect to get NULL as a frame pointer and will segfault.  Hence,
03014        * we output the original frame passed in. */
03015       res = chan->tech->write(chan, fr);
03016       break;
03017    }
03018 
03019    if (f && f != fr)
03020       ast_frfree(f);
03021    ast_clear_flag(chan, AST_FLAG_BLOCKING);
03022 
03023    /* Consider a write failure to force a soft hangup */
03024    if (res < 0) {
03025       chan->_softhangup |= AST_SOFTHANGUP_DEV;
03026    } else {
03027       chan->fout = FRAMECOUNT_INC(chan->fout);
03028    }
03029 done:
03030    ast_channel_unlock(chan);
03031    return res;
03032 }

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

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

02798 {
02799    int res;
02800    if (!chan->tech->write_video)
02801       return 0;
02802    res = ast_write(chan, fr);
02803    if (!res)
02804       res = 1;
02805    return res;
02806 }

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

Definition at line 4091 of file channel.c.

References ast_autoservice_start(), ast_autoservice_stop(), AST_DIGIT_ANY, ast_say_number(), ast_stream_and_wait(), and ast_channel::language.

Referenced by ast_channel_bridge().

04092 {
04093    int min = 0, sec = 0, check;
04094 
04095    check = ast_autoservice_start(peer);
04096    if (check)
04097       return;
04098 
04099    if (remain > 0) {
04100       if (remain / 60 > 1) {
04101          min = remain / 60;
04102          sec = remain % 60;
04103       } else {
04104          sec = remain;
04105       }
04106    }
04107    
04108    if (!strcmp(sound,"timeleft")) { /* Queue support */
04109       ast_stream_and_wait(chan, "vm-youhave", chan->language, "");
04110       if (min) {
04111          ast_say_number(chan, min, AST_DIGIT_ANY, chan->language, NULL);
04112          ast_stream_and_wait(chan, "queue-minutes", chan->language, "");
04113       }
04114       if (sec) {
04115          ast_say_number(chan, sec, AST_DIGIT_ANY, chan->language, NULL);
04116          ast_stream_and_wait(chan, "queue-seconds", chan->language, "");
04117       }
04118    } else {
04119       ast_stream_and_wait(chan, sound, chan->language, "");
04120    }
04121 
04122    ast_autoservice_stop(peer);
04123 }

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]

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

References ast_channel_trylock, AST_LIST_LOCK, AST_LIST_NEXT, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel::context, ast_channel::exten, LOG_DEBUG, ast_channel::macrocontext, ast_channel::macroexten, ast_channel::name, and option_debug.

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

01079 {
01080    const char *msg = prev ? "deadlock" : "initial deadlock";
01081    int retries;
01082    struct ast_channel *c;
01083    const struct ast_channel *_prev = prev;
01084 
01085    for (retries = 0; retries < 200; retries++) {
01086       int done;
01087       /* Reset prev on each retry.  See note below for the reason. */
01088       prev = _prev;
01089       AST_LIST_LOCK(&channels);
01090       AST_LIST_TRAVERSE(&channels, c, chan_list) {
01091          if (prev) { /* look for last item, first, before any evaluation */
01092             if (c != prev) /* not this one */
01093                continue;
01094             /* found, prepare to return c->next */
01095             if ((c = AST_LIST_NEXT(c, chan_list)) == NULL) break;
01096             /*!\note
01097              * We're done searching through the list for the previous item.
01098              * Any item after this point, we want to evaluate for a match.
01099              * If we didn't set prev to NULL here, then we would only
01100              * return matches for the first matching item (since the above
01101              * "if (c != prev)" would not permit any other potential
01102              * matches to reach the additional matching logic, below).
01103              * Instead, it would just iterate until it once again found the
01104              * original match, then iterate down to the end of the list and
01105              * quit.
01106              */
01107             prev = NULL;
01108          }
01109          if (name) { /* want match by name */
01110             if ((!namelen && strcasecmp(c->name, name)) ||
01111                 (namelen && strncasecmp(c->name, name, namelen)))
01112                continue;   /* name match failed */
01113          } else if (exten) {
01114             if (context && strcasecmp(c->context, context) &&
01115                 strcasecmp(c->macrocontext, context))
01116                continue;   /* context match failed */
01117             if (strcasecmp(c->exten, exten) &&
01118                 strcasecmp(c->macroexten, exten))
01119                continue;   /* exten match failed */
01120          }
01121          /* if we get here, c points to the desired record */
01122          break;
01123       }
01124       /* exit if chan not found or mutex acquired successfully */
01125       /* this is slightly unsafe, as we _should_ hold the lock to access c->name */
01126       done = c == NULL || ast_channel_trylock(c) == 0;
01127       if (!done) {
01128          if (option_debug)
01129             ast_log(LOG_DEBUG, "Avoiding %s for channel '%p'\n", msg, c);
01130          if (retries == 199) {
01131             /* We are about to fail due to a deadlock, so report this
01132              * while we still have the list lock.
01133              */
01134             if (option_debug)
01135                ast_log(LOG_DEBUG, "Failure, could not lock '%p' after %d retries!\n", c, retries);
01136             /* As we have deadlocked, we will skip this channel and
01137              * see if there is another match.
01138              * NOTE: No point doing this for a full-name match,
01139              * as there can be no more matches.
01140              */
01141             if (!(name && !namelen)) {
01142                prev = c;
01143                retries = -1;
01144             }
01145          }
01146       }
01147       AST_LIST_UNLOCK(&channels);
01148       if (done)
01149          return c;
01150       /* If we reach this point we basically tried to lock a channel and failed. Instead of
01151        * starting from the beginning of the list we can restore our saved pointer to the previous
01152        * channel and start from there.
01153        */
01154       prev = _prev;
01155       usleep(1);  /* give other threads a chance before retrying */
01156    }
01157 
01158    return NULL;
01159 }

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

References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.

04969 {
04970    switch (reason) {
04971    case CHANNEL_MODULE_LOAD:
04972       return "LOAD (Channel module load)";
04973 
04974    case CHANNEL_MODULE_RELOAD:
04975       return "RELOAD (Channel module reload)";
04976 
04977    case CHANNEL_CLI_RELOAD:
04978       return "CLIRELOAD (Channel module reload by CLI command)";
04979 
04980    default:
04981       return "MANAGERRELOAD (Channel module reload by manager)";
04982    }
04983 };

static void clone_variables ( struct ast_channel original,
struct ast_channel clone 
) [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 3702 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().

03703 {
03704    struct ast_var_t *current, *newvar;
03705    /* Append variables from clone channel into original channel */
03706    /* XXX Is this always correct?  We have to in order to keep MACROS working XXX */
03707    if (AST_LIST_FIRST(&clone->varshead))
03708       AST_LIST_APPEND_LIST(&original->varshead, &clone->varshead, entries);
03709 
03710    /* then, dup the varshead list into the clone */
03711    
03712    AST_LIST_TRAVERSE(&original->varshead, current, entries) {
03713       newvar = ast_var_assign(current->name, current->value);
03714       if (newvar)
03715          AST_LIST_INSERT_TAIL(&clone->varshead, newvar, entries);
03716    }
03717 }

static char* complete_channeltypes ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 334 of file channel.c.

References AST_LIST_TRAVERSE, chanlist::list, strdup, chanlist::tech, and ast_channel_tech::type.

00335 {
00336    struct chanlist *cl;
00337    int which = 0;
00338    int wordlen;
00339    char *ret = NULL;
00340 
00341    if (pos != 3)
00342       return NULL;
00343 
00344    wordlen = strlen(word);
00345 
00346    AST_LIST_TRAVERSE(&backends, cl, list) {
00347       if (!strncasecmp(word, cl->tech->type, wordlen) && ++which > state) {
00348          ret = strdup(cl->tech->type);
00349          break;
00350       }
00351    }
00352    
00353    return ret;
00354 }

static char* complete_channeltypes_deprecated ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 312 of file channel.c.

References AST_LIST_TRAVERSE, chanlist::list, strdup, chanlist::tech, and ast_channel_tech::type.

00313 {
00314    struct chanlist *cl;
00315    int which = 0;
00316    int wordlen;
00317    char *ret = NULL;
00318 
00319    if (pos != 2)
00320       return NULL;
00321 
00322    wordlen = strlen(word);
00323 
00324    AST_LIST_TRAVERSE(&backends, cl, list) {
00325       if (!strncasecmp(word, cl->tech->type, wordlen) && ++which > state) {
00326          ret = strdup(cl->tech->type);
00327          break;
00328       }
00329    }
00330    
00331    return ret;
00332 }

static void free_cid ( struct ast_callerid cid  )  [static]

Definition at line 1226 of file channel.c.

References ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_rdnis, and free.

Referenced by ast_channel_free().

01227 {
01228    if (cid->cid_dnid)
01229       free(cid->cid_dnid);
01230    if (cid->cid_num)
01231       free(cid->cid_num);  
01232    if (cid->cid_name)
01233       free(cid->cid_name); 
01234    if (cid->cid_ani)
01235       free(cid->cid_ani);
01236    if (cid->cid_rdnis)
01237       free(cid->cid_rdnis);
01238 }

static void free_translation ( struct ast_channel clone  )  [static]

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

01473 {
01474    if (clone->writetrans)
01475       ast_translator_free_path(clone->writetrans);
01476    if (clone->readtrans)
01477       ast_translator_free_path(clone->readtrans);
01478    clone->writetrans = NULL;
01479    clone->readtrans = NULL;
01480    clone->rawwriteformat = clone->nativeformats;
01481    clone->rawreadformat = clone->nativeformats;
01482 }

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

Definition at line 1627 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_deactivate_generator(), AST_FORMAT_AUDIO_MASK, ast_format_rate(), ast_log(), LOG_DEBUG, and option_debug.

Referenced by ast_activate_generator(), and ast_read_generator_actions().

01628 {
01629    /* Called if generator doesn't have data */
01630    void *tmp;
01631    int res;
01632    int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL;
01633    struct ast_channel *chan = (struct ast_channel *)data;
01634 
01635    ast_channel_lock(chan);
01636    tmp = chan->generatordata;
01637    chan->generatordata = NULL;
01638    if (chan->generator)
01639       generate = chan->generator->generate;
01640    ast_channel_unlock(chan);
01641 
01642    if (!tmp || !generate)
01643       return 0;
01644 
01645    res = generate(chan, tmp, 0, ast_format_rate(chan->writeformat & AST_FORMAT_AUDIO_MASK) / 50);
01646 
01647    chan->generatordata = tmp;
01648 
01649    if (res) {
01650       if (option_debug)
01651          ast_log(LOG_DEBUG, "Auto-deactivating generator\n");
01652       ast_deactivate_generator(chan);
01653    }
01654 
01655    return 0;
01656 }

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

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

03125 {
03126    if (outstate) {
03127       /* compute error and return */
03128       if (cause == AST_CAUSE_BUSY)
03129          *outstate = AST_CONTROL_BUSY;
03130       else if (cause == AST_CAUSE_CONGESTION)
03131          *outstate = AST_CONTROL_CONGESTION;
03132       else
03133          *outstate = 0;
03134    }
03135 }

static int attribute_const is_visible_indication ( enum ast_control_frame_type  condition  )  [static]

Definition at line 2522 of file channel.c.

References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, and AST_CONTROL_WINK.

Referenced by ast_indicate_data().

02523 {
02524    /* Don't include a default case here so that we get compiler warnings
02525     * when a new type is added. */
02526 
02527    switch (condition) {
02528    case AST_CONTROL_PROGRESS:
02529    case AST_CONTROL_PROCEEDING:
02530    case AST_CONTROL_VIDUPDATE:
02531    case AST_CONTROL_SRCUPDATE:
02532    case AST_CONTROL_RADIO_KEY:
02533    case AST_CONTROL_RADIO_UNKEY:
02534    case AST_CONTROL_OPTION:
02535    case AST_CONTROL_WINK:
02536    case AST_CONTROL_FLASH:
02537    case AST_CONTROL_OFFHOOK:
02538    case AST_CONTROL_TAKEOFFHOOK:
02539    case AST_CONTROL_ANSWER:
02540    case AST_CONTROL_HANGUP:
02541       return 0;
02542 
02543    case AST_CONTROL_CONGESTION:
02544    case AST_CONTROL_BUSY:
02545    case AST_CONTROL_RINGING:
02546    case AST_CONTROL_RING:
02547    case AST_CONTROL_HOLD:
02548    case AST_CONTROL_UNHOLD:
02549       return 1;
02550    }
02551 
02552    return 0;
02553 }

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

Definition at line 2014 of file channel.c.

References AST_FRAME_DTMF_END, ast_queue_frame(), ast_channel::dtmff, f, ast_frame::frametype, ast_frame::len, and ast_frame::subclass.

Referenced by __ast_read().

02015 {
02016    struct ast_frame *fr = &chan->dtmff;
02017 
02018    fr->frametype = AST_FRAME_DTMF_END;
02019    fr->subclass = f->subclass;
02020    fr->len = f->len;
02021 
02022    /* The only time this function will be called is for a frame that just came
02023     * out of the channel driver.  So, we want to stick it on the tail of the
02024     * readq. */
02025 
02026    ast_queue_frame(chan, fr);
02027 }

static void report_new_callerid ( const struct ast_channel chan  )  [static]

Precondition:
chan is locked

Definition at line 3722 of file channel.c.

References ast_describe_caller_presentation(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, manager_event(), ast_channel::name, S_OR, and ast_channel::uniqueid.

Referenced by ast_do_masquerade(), and ast_set_callerid().

03723 {
03724    manager_event(EVENT_FLAG_CALL, "Newcallerid",
03725             "Channel: %s\r\n"
03726             "CallerID: %s\r\n"
03727             "CallerIDName: %s\r\n"
03728             "Uniqueid: %s\r\n"
03729             "CID-CallingPres: %d (%s)\r\n",
03730             chan->name,
03731             S_OR(chan->cid.cid_num, "<Unknown>"),
03732             S_OR(chan->cid.cid_name, "<Unknown>"),
03733             chan->uniqueid,
03734             chan->cid.cid_pres,
03735             ast_describe_caller_presentation(chan->cid.cid_pres)
03736             );
03737 }

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

References ast_channel_lock, ast_channel_unlock, AST_FORMAT_AUDIO_MASK, ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_translator_best_choice(), ast_translator_build_path(), ast_translator_free_path(), LOG_DEBUG, ast_channel::name, ast_channel::nativeformats, and option_debug.

Referenced by ast_set_read_format(), and ast_set_write_format().

03036 {
03037    int native;
03038    int res;
03039    char from[200], to[200];
03040    
03041    /* Make sure we only consider audio */
03042    fmt &= AST_FORMAT_AUDIO_MASK;
03043    
03044    native = chan->nativeformats;
03045    /* Find a translation path from the native format to one of the desired formats */
03046    if (!direction)
03047       /* reading */
03048       res = ast_translator_best_choice(&fmt, &native);
03049    else
03050       /* writing */
03051       res = ast_translator_best_choice(&native, &fmt);
03052 
03053    if (res < 0) {
03054       ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n",
03055          ast_getformatname_multiple(from, sizeof(from), native),
03056          ast_getformatname_multiple(to, sizeof(to), fmt));
03057       return -1;
03058    }
03059    
03060    /* Now we have a good choice for both. */
03061    ast_channel_lock(chan);
03062 
03063    if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) {
03064       /* the channel is already in these formats, so nothing to do */
03065       ast_channel_unlock(chan);
03066       return 0;
03067    }
03068 
03069    *rawformat = native;
03070    /* User perspective is fmt */
03071    *format = fmt;
03072    /* Free any read translation we have right now */
03073    if (*trans)
03074       ast_translator_free_path(*trans);
03075    /* Build a translation path from the raw format to the desired format */
03076    if (!direction)
03077       /* reading */
03078       *trans = ast_translator_build_path(*format, *rawformat);
03079    else
03080       /* writing */
03081       *trans = ast_translator_build_path(*rawformat, *format);
03082    ast_channel_unlock(chan);
03083    if (option_debug)
03084       ast_log(LOG_DEBUG, "Set channel %s to %s format %s\n", chan->name,
03085          direction ? "write" : "read", ast_getformatname(fmt));
03086    return 0;
03087 }

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

02033 {
02034    if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF)) {
02035       /* We're in the middle of emulating a digit, or DTMF has been
02036        * explicitly deferred.  Skip this digit, then. */
02037       return 1;
02038    }
02039          
02040    if (!ast_tvzero(chan->dtmf_tv) && 
02041          ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) {
02042       /* We're not in the middle of a digit, but it hasn't been long enough
02043        * since the last digit, so we'll have to skip DTMF for now. */
02044       return 1;
02045    }
02046 
02047    return 0;
02048 }

static int show_channeltype ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 259 of file channel.c.

References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel_tech::capabilities, ast_channel_tech::devicestate, ast_channel_tech::indicate, chanlist::list, LOG_WARNING, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, 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, and ast_channel_tech::type.

00260 {
00261    struct chanlist *cl = NULL;
00262 
00263    if (argc != 4)
00264       return RESULT_SHOWUSAGE;
00265    
00266    if (AST_LIST_LOCK(&channels)) {
00267       ast_log(LOG_WARNING, "Unable to lock channel list\n");
00268       return RESULT_FAILURE;
00269    }
00270 
00271    AST_LIST_TRAVERSE(&backends, cl, list) {
00272       if (!strncasecmp(cl->tech->type, argv[3], strlen(cl->tech->type))) {
00273          break;
00274       }
00275    }
00276 
00277 
00278    if (!cl) {
00279       ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[3]);
00280       AST_LIST_UNLOCK(&channels);
00281       return RESULT_FAILURE;
00282    }
00283 
00284    ast_cli(fd,
00285       "-- Info about channel driver: %s --\n"
00286       "  Device State: %s\n"
00287       "    Indication: %s\n"
00288       "     Transfer : %s\n"
00289       "  Capabilities: %d\n"
00290       "   Digit Begin: %s\n"
00291       "     Digit End: %s\n"
00292       "    Send HTML : %s\n"
00293       " Image Support: %s\n"
00294       "  Text Support: %s\n",
00295       cl->tech->type,
00296       (cl->tech->devicestate) ? "yes" : "no",
00297       (cl->tech->indicate) ? "yes" : "no",
00298       (cl->tech->transfer) ? "yes" : "no",
00299       (cl->tech->capabilities) ? cl->tech->capabilities : -1,
00300       (cl->tech->send_digit_begin) ? "yes" : "no",
00301       (cl->tech->send_digit_end) ? "yes" : "no",
00302       (cl->tech->send_html) ? "yes" : "no",
00303       (cl->tech->send_image) ? "yes" : "no",
00304       (cl->tech->send_text) ? "yes" : "no"
00305       
00306    );
00307 
00308    AST_LIST_UNLOCK(&channels);
00309    return RESULT_SUCCESS;
00310 }

static int show_channeltype_deprecated ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 206 of file channel.c.

References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel_tech::capabilities, ast_channel_tech::devicestate, ast_channel_tech::indicate, chanlist::list, LOG_WARNING, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, 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, and ast_channel_tech::type.

00207 {
00208    struct chanlist *cl = NULL;
00209 
00210    if (argc != 3)
00211       return RESULT_SHOWUSAGE;
00212    
00213    if (AST_LIST_LOCK(&channels)) {
00214       ast_log(LOG_WARNING, "Unable to lock channel list\n");
00215       return RESULT_FAILURE;
00216    }
00217 
00218    AST_LIST_TRAVERSE(&backends, cl, list) {
00219       if (!strncasecmp(cl->tech->type, argv[2], strlen(cl->tech->type))) {
00220          break;
00221       }
00222    }
00223 
00224 
00225    if (!cl) {
00226       ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[2]);
00227       AST_LIST_UNLOCK(&channels);
00228       return RESULT_FAILURE;
00229    }
00230 
00231    ast_cli(fd,
00232       "-- Info about channel driver: %s --\n"
00233       "  Device State: %s\n"
00234       "    Indication: %s\n"
00235       "     Transfer : %s\n"
00236       "  Capabilities: %d\n"
00237       "   Digit Begin: %s\n"
00238       "     Digit End: %s\n"
00239       "    Send HTML : %s\n"
00240       " Image Support: %s\n"
00241       "  Text Support: %s\n",
00242       cl->tech->type,
00243       (cl->tech->devicestate) ? "yes" : "no",
00244       (cl->tech->indicate) ? "yes" : "no",
00245       (cl->tech->transfer) ? "yes" : "no",
00246       (cl->tech->capabilities) ? cl->tech->capabilities : -1,
00247       (cl->tech->send_digit_begin) ? "yes" : "no",
00248       (cl->tech->send_digit_end) ? "yes" : "no",
00249       (cl->tech->send_html) ? "yes" : "no",
00250       (cl->tech->send_image) ? "yes" : "no",
00251       (cl->tech->send_text) ? "yes" : "no"
00252       
00253    );
00254 
00255    AST_LIST_UNLOCK(&channels);
00256    return RESULT_SUCCESS;
00257 }

static int show_channeltypes ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 179 of file channel.c.

References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel_tech::description, ast_channel_tech::devicestate, FORMAT, ast_channel_tech::indicate, chanlist::list, LOG_WARNING, RESULT_SUCCESS, chanlist::tech, ast_channel_tech::transfer, and ast_channel_tech::type.

00180 {
00181 #define FORMAT  "%-10.10s  %-40.40s %-12.12s %-12.12s %-12.12s\n"
00182    struct chanlist *cl;
00183    int count_chan = 0;
00184 
00185    ast_cli(fd, FORMAT, "Type", "Description",       "Devicestate", "Indications", "Transfer");
00186    ast_cli(fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------");
00187    if (AST_LIST_LOCK(&channels)) {
00188       ast_log(LOG_WARNING, "Unable to lock channel list\n");
00189       return -1;
00190    }
00191    AST_LIST_TRAVERSE(&backends, cl, list) {
00192       ast_cli(fd, FORMAT, cl->tech->type, cl->tech->description,
00193          (cl->tech->devicestate) ? "yes" : "no",
00194          (cl->tech->indicate) ? "yes" : "no",
00195          (cl->tech->transfer) ? "yes" : "no");
00196       count_chan++;
00197    }
00198    AST_LIST_UNLOCK(&channels);
00199    ast_cli(fd, "----------\n%d channel drivers registered.\n", count_chan);
00200    return RESULT_SUCCESS;
00201 
00202 #undef FORMAT
00203 
00204 }

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

Definition at line 4889 of file channel.c.

04890 {
04891    /* just store the data pointer in the channel structure */
04892    return data;
04893 }

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

Definition at line 4900 of file channel.c.

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

04901 {
04902    short buf[samples];
04903    struct ast_frame frame = {
04904       .frametype = AST_FRAME_VOICE,
04905       .subclass = AST_FORMAT_SLINEAR,
04906       .data = buf,
04907       .samples = samples,
04908       .datalen = sizeof(buf),
04909    };
04910    memset(buf, 0, sizeof(buf));
04911    if (ast_write(chan, &frame))
04912       return -1;
04913    return 0;
04914 }

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

Definition at line 4895 of file channel.c.

04896 {
04897    /* nothing to do */
04898 }

static void state2str_threadbuf_init ( void   )  [static]

Definition at line 84 of file channel.c.

00098 {

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

Definition at line 4653 of file channel.c.

References ast_calloc, AST_FLAG_WRITE_INT, AST_FORMAT_SLINEAR, ast_log(), ast_set_flag, ast_set_write_format(), tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, ast_channel::name, tonepair_release(), tonepair_def::vol, and ast_channel::writeformat.

04654 {
04655    struct tonepair_state *ts;
04656    struct tonepair_def *td = params;
04657 
04658    if (!(ts = ast_calloc(1, sizeof(*ts))))
04659       return NULL;
04660    ts->origwfmt = chan->writeformat;
04661    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
04662       ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
04663       tonepair_release(NULL, ts);
04664       ts = NULL;
04665    } else {
04666       ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0;
04667       ts->v1_1 = 0;
04668       ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
04669       ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
04670       ts->v2_1 = 0;
04671       ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0;
04672       ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
04673       ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
04674       ts->duration = td->duration;
04675       ts->modulate = 0;
04676    }
04677    /* Let interrupts interrupt :) */
04678    ast_set_flag(chan, AST_FLAG_WRITE_INT);
04679    return ts;
04680 }

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

Definition at line 4682 of file channel.c.

References ast_log(), tonepair_state::data, tonepair_state::f, tonepair_state::fac1, tonepair_state::fac2, tonepair_state::modulate, 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.

04683 {
04684    struct tonepair_state *ts = data;
04685    int x;
04686 
04687    /* we need to prepare a frame with 16 * timelen samples as we're
04688     * generating SLIN audio
04689     */
04690    len = samples * 2;
04691 
04692    if (len > sizeof(ts->data) / 2 - 1) {
04693       ast_log(LOG_WARNING, "Can't generate that much data!\n");
04694       return -1;
04695    }
04696    memset(&ts->f, 0, sizeof(ts->f));
04697    for (x=0;x<len/2;x++) {
04698       ts->v1_1 = ts->v2_1;
04699       ts->v2_1 = ts->v3_1;
04700       ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1;
04701       
04702       ts->v1_2 = ts->v2_2;
04703       ts->v2_2 = ts->v3_2;
04704       ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2;
04705       if (ts->modulate) {
04706          int p;
04707          p = ts->v3_2 - 32768;
04708          if (p < 0) p = -p;
04709          p = ((p * 9) / 10) + 1;
04710          ts->data[x] = (ts->v3_1 * p) >> 15;
04711       } else
04712          ts->data[x] = ts->v3_1 + ts->v3_2; 
04713    }
04714    ts->f.frametype = AST_FRAME_VOICE;
04715    ts->f.subclass = AST_FORMAT_SLINEAR;
04716    ts->f.datalen = len;
04717    ts->f.samples = samples;
04718    ts->f.offset = AST_FRIENDLY_OFFSET;
04719    ts->f.data = ts->data;
04720    ast_write(chan, &ts->f);
04721    ts->pos += x;
04722    if (ts->duration > 0) {
04723       if (ts->pos >= ts->duration * 8)
04724          return -1;
04725    }
04726    return 0;
04727 }

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

Definition at line 4644 of file channel.c.

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

Referenced by tonepair_alloc().

04645 {
04646    struct tonepair_state *ts = params;
04647 
04648    if (chan)
04649       ast_set_write_format(chan, ts->origwfmt);
04650    free(ts);
04651 }

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

Definition at line 4300 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_strdupa, ast_strlen_zero(), ast_channel::name, pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper().

Referenced by ast_channel_bridge().

04301 {
04302    const char *c0_name;
04303    const char *c1_name;
04304 
04305    ast_channel_lock(c1);
04306    c1_name = ast_strdupa(c1->name);
04307    ast_channel_unlock(c1);
04308 
04309    ast_channel_lock(c0);
04310    if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) {
04311       pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1_name);
04312    }
04313    c0_name = ast_strdupa(c0->name);
04314    ast_channel_unlock(c0);
04315 
04316    ast_channel_lock(c1);
04317    if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) {
04318       pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0_name);
04319    }
04320    ast_channel_unlock(c1);
04321 }


Variable Documentation

void(*) ast_moh_cleanup_ptr(struct ast_channel *) = NULL [static]

Definition at line 4805 of file channel.c.

Referenced by ast_install_music_functions(), ast_moh_cleanup(), and ast_uninstall_music_functions().

int(*) ast_moh_start_ptr(struct ast_channel *, const char *, const char *) = NULL [static]

Definition at line 4803 of file channel.c.

Referenced by ast_install_music_functions(), ast_moh_start(), and ast_uninstall_music_functions().

void(*) ast_moh_stop_ptr(struct ast_channel *) = NULL [static]

Definition at line 4804 of file channel.c.

Referenced by ast_install_music_functions(), ast_moh_stop(), and ast_uninstall_music_functions().

struct ast_cause causes[]

map AST_CAUSE's to readable string representations

Referenced by ast_cause2str(), ast_str2cause(), and dump_cause().

struct ast_cli_entry cli_channel[] [static]

Definition at line 374 of file channel.c.

Referenced by ast_channels_init().

struct ast_cli_entry cli_show_channeltype_deprecated [static]

Initial value:

 {
   { "show", "channeltype", NULL },
   show_channeltype_deprecated, NULL,
   NULL, complete_channeltypes_deprecated }

Definition at line 369 of file channel.c.

struct ast_cli_entry cli_show_channeltypes_deprecated [static]

Initial value:

 {
   { "show", "channeltypes", NULL },
   show_channeltypes, NULL,
   NULL }

Definition at line 364 of file channel.c.

unsigned long global_fin

Definition at line 82 of file channel.c.

unsigned long global_fout

Definition at line 82 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 703 of file channel.c.

char show_channeltype_usage[] [static]

Initial value:

"Usage: core show channeltype <name>\n"
"  Show details about the specified channel type, <name>.\n"

Definition at line 360 of file channel.c.

char show_channeltypes_usage[] [static]

Initial value:

"Usage: core show channeltypes\n"
"       Lists available channel types registered in your Asterisk server.\n"

Definition at line 356 of file channel.c.

int shutting_down [static]

Prevent new channel allocation if shutting down.

Definition at line 78 of file channel.c.

struct ast_generator silence_generator [static]

Initial value:

Definition at line 4916 of file channel.c.

Referenced by ast_channel_start_silence_generator().

struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT, .key_init = state2str_threadbuf_init , } [static]

Definition at line 84 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 4729 of file channel.c.

Referenced by ast_tonepair_start().

int uniqueint [static]

Definition at line 80 of file channel.c.


Generated on Tue Jul 14 23:10:20 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7