Wed Aug 11 01:07:33 2010

Asterisk developer's documentation


channel.h File Reference

General Asterisk PBX channel definitions. More...

#include "asterisk/abstract_jb.h"
#include "asterisk/poll-compat.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/chanvars.h"
#include "asterisk/config.h"
#include "asterisk/lock.h"
#include "asterisk/cdr.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/datastore.h"

Include dependency graph for channel.h:

Go to the source code of this file.

Data Structures

struct  ast_bridge_config
 bridge configuration More...
struct  ast_callerid
 Structure for all kinds of caller ID identifications. More...
struct  ast_channel
 Main Channel structure associated with a channel. This is the side of it mostly used by the pbx and call management. More...
struct  ast_channel_tech
 Structure to describe a channel "technology", ie a channel driver See for examples:. More...
struct  ast_generator
struct  ast_group_info
 channel group info More...
struct  datastores
struct  outgoing_helper

Defines

#define AST_AGENT_FD   (AST_MAX_FDS-3)
#define AST_ALERT_FD   (AST_MAX_FDS-1)
#define AST_BRIDGE_DTMF_CHANNEL_0   (1 << 0)
 Report DTMF on channel 0.
#define AST_BRIDGE_DTMF_CHANNEL_1   (1 << 1)
 Report DTMF on channel 1.
#define AST_BRIDGE_IGNORE_SIGS   (1 << 4)
 Ignore all signal frames except NULL.
#define AST_BRIDGE_REC_CHANNEL_0   (1 << 2)
 Return all voice frames on channel 0.
#define AST_BRIDGE_REC_CHANNEL_1   (1 << 3)
 Return all voice frames on channel 1.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, amaflag,...)
#define AST_CHANNEL_NAME   80
#define AST_GENERATOR_FD   (AST_MAX_FDS-4)
#define AST_MAX_CONTEXT   80
#define AST_MAX_EXTENSION   80
#define AST_MAX_FDS   10
#define AST_TIMING_FD   (AST_MAX_FDS-2)
#define CHECK_BLOCKING(c)
#define DATASTORE_INHERIT_FOREVER   INT_MAX
#define DEBUGCHAN_FLAG   0x80000000
#define FRAMECOUNT_INC(x)   ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
#define MAX_LANGUAGE   20
#define MAX_MUSICCLASS   80

Typedefs

typedef unsigned long long ast_group_t

Enumerations

enum  { AST_CHAN_TP_WANTSJITTER = (1 << 0), AST_CHAN_TP_CREATESJITTER = (1 << 1) }
 ast_channel_tech Properties More...
enum  {
  AST_FLAG_DEFER_DTMF = (1 << 1), AST_FLAG_WRITE_INT = (1 << 2), AST_FLAG_BLOCKING = (1 << 3), AST_FLAG_ZOMBIE = (1 << 4),
  AST_FLAG_EXCEPTION = (1 << 5), AST_FLAG_MOH = (1 << 6), AST_FLAG_SPYING = (1 << 7), AST_FLAG_NBRIDGE = (1 << 8),
  AST_FLAG_IN_AUTOLOOP = (1 << 9), AST_FLAG_OUTGOING = (1 << 10), AST_FLAG_IN_DTMF = (1 << 12), AST_FLAG_EMULATE_DTMF = (1 << 13),
  AST_FLAG_END_DTMF_ONLY = (1 << 14), AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), AST_FLAG_MASQ_NOSTREAM = (1 << 16), AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
  AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18), AST_FLAG_IN_CHANNEL_LIST = (1 << 19), AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20)
}
 ast_channel flags More...
enum  {
  AST_FEATURE_PLAY_WARNING = (1 << 0), AST_FEATURE_REDIRECT = (1 << 1), AST_FEATURE_DISCONNECT = (1 << 2), AST_FEATURE_ATXFER = (1 << 3),
  AST_FEATURE_AUTOMON = (1 << 4), AST_FEATURE_PARKCALL = (1 << 5), AST_FEATURE_AUTOMIXMON = (1 << 6), AST_FEATURE_NO_H_EXTEN = (1 << 7),
  AST_FEATURE_WARNING_ACTIVE = (1 << 8)
}
 ast_bridge_config flags More...
enum  { AST_CDR_TRANSFER = (1 << 0), AST_CDR_FORWARD = (1 << 1), AST_CDR_CALLWAIT = (1 << 2), AST_CDR_CONFERENCE = (1 << 3) }
enum  {
  AST_SOFTHANGUP_DEV = (1 << 0), AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), AST_SOFTHANGUP_SHUTDOWN = (1 << 2), AST_SOFTHANGUP_TIMEOUT = (1 << 3),
  AST_SOFTHANGUP_APPUNLOAD = (1 << 4), AST_SOFTHANGUP_EXPLICIT = (1 << 5), AST_SOFTHANGUP_UNBRIDGE = (1 << 6)
}
enum  ast_bridge_result { AST_BRIDGE_COMPLETE = 0, AST_BRIDGE_FAILED = -1, AST_BRIDGE_FAILED_NOWARN = -2, AST_BRIDGE_RETRY = -3 }
enum  ast_channel_adsicpe { AST_ADSI_UNKNOWN, AST_ADSI_AVAILABLE, AST_ADSI_UNAVAILABLE, AST_ADSI_OFFHOOKONLY }
enum  ast_channel_state {
  AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_OFFHOOK, AST_STATE_DIALING,
  AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, AST_STATE_BUSY,
  AST_STATE_DIALING_OFFHOOK, AST_STATE_PRERING, AST_STATE_MUTE = (1 << 16)
}
 ast_channel states More...
enum  ast_t38_state {
  T38_STATE_UNAVAILABLE, T38_STATE_UNKNOWN, T38_STATE_NEGOTIATING, T38_STATE_REJECTED,
  T38_STATE_NEGOTIATED
}
 Possible T38 states on channels. More...
enum  channelreloadreason { CHANNEL_MODULE_LOAD, CHANNEL_MODULE_RELOAD, CHANNEL_CLI_RELOAD, CHANNEL_MANAGER_RELOAD }
 Channel reload reasons for manager events at load or reload of configuration. More...

Functions

int __ast_answer (struct ast_channel *chan, unsigned int delay, int cdr_answer)
 Answer a channel, with a selectable delay before returning.
struct ast_channel
*attribute_malloc 
__ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *file, int line, const char *function, const char *name_fmt,...)
 Create a channel structure.
struct ast_channel * __ast_request_and_dial (const char *type, int format, void *data, int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
 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_activate_generator (struct ast_channel *chan, struct ast_generator *gen, void *params)
int ast_active_channels (void)
 returns number of active/allocated channels
static int ast_add_fd (struct pollfd *pfd, int fd)
 if fd is a valid descriptor, set *pfd with the descriptor
int ast_answer (struct ast_channel *chan)
 Answer a channel.
int ast_autoservice_ignore (struct ast_channel *chan, enum ast_frame_type ftype)
 Ignore certain frame types.
int ast_autoservice_start (struct ast_channel *chan)
 Automatically service a channel for us...
int ast_autoservice_stop (struct ast_channel *chan)
 Stop servicing a channel for us...
void ast_begin_shutdown (int hangup)
 Initiate system shutdown.
int ast_best_codec (int fmts)
 Pick the best audio codec.
struct ast_channel * ast_bridged_channel (struct ast_channel *chan)
 Find bridged channel.
int ast_call (struct ast_channel *chan, char *addr, int timeout)
 Make a call.
struct ast_channel * ast_call_forward (struct ast_channel *caller, struct ast_channel *orig, int *timeout, int format, struct outgoing_helper *oh, int *outstate)
 Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.
void ast_cancel_shutdown (void)
 Cancel a shutdown in progress.
const char * ast_cause2str (int state) attribute_pure
 Gives the string form of a given hangup cause.
void ast_change_name (struct ast_channel *chan, char *newname)
 Change channel name.
int ast_channel_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc)
 Bridge two channels together.
int ast_channel_cmpwhentohangup (struct ast_channel *chan, time_t offset)
 Compare a offset with the settings of when to hang a channel up.
int ast_channel_cmpwhentohangup_tv (struct ast_channel *chan, struct timeval 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.
struct ast_datastore
*attribute_malloc 
ast_channel_datastore_alloc (const struct ast_datastore_info *info, const char *uid)
 Create a channel data store object.
struct ast_datastore * ast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
 Find a datastore on a channel.
int ast_channel_datastore_free (struct ast_datastore *datastore)
 Free a channel data store object.
int ast_channel_datastore_inherit (struct ast_channel *from, struct ast_channel *to)
 Inherit datastores from a parent to a child.
int ast_channel_datastore_remove (struct ast_channel *chan, struct ast_datastore *datastore)
 Remove a datastore from a channel.
int ast_channel_defer_dtmf (struct ast_channel *chan)
 Set defer DTMF flag on channel.
int ast_channel_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Bridge two channels together (early).
void ast_channel_free (struct ast_channel *)
 Free a channel structure.
static enum ast_t38_state ast_channel_get_t38_state (struct ast_channel *chan)
 Retrieves the current T38 state of a channel.
void ast_channel_inherit_variables (const struct ast_channel *parent, struct ast_channel *child)
 Inherits channel variable from parent to child channel.
int ast_channel_make_compatible (struct ast_channel *c0, struct ast_channel *c1)
 Makes two channel formats compatible.
int ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clone)
 Weird function made for call transfers.
int ast_channel_queryoption (struct ast_channel *channel, int option, void *data, int *datalen, int block)
const char * ast_channel_reason2str (int reason)
 return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
int ast_channel_register (const struct ast_channel_tech *tech)
 Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.
struct ast_channel * ast_channel_search_locked (int(*is_match)(struct ast_channel *, void *), void *data)
 Search for a channel based on the passed channel matching callback Search for a channel based on the specified is_match callback, and return the first channel that we match. When returned, the channel will be locked. Note that the is_match callback is called with the passed channel locked, and should return 0 if there is no match, and non-zero if there is.
int ast_channel_sendhtml (struct ast_channel *channel, int subclass, const char *data, int datalen)
int ast_channel_sendurl (struct ast_channel *channel, const char *url)
void ast_channel_set_fd (struct ast_channel *chan, int which, int fd)
int ast_channel_setoption (struct ast_channel *channel, int option, void *data, int datalen, int block)
 Sets an option on a channel.
void ast_channel_setwhentohangup (struct ast_channel *chan, time_t offset)
 Set when to hang a channel up.
void ast_channel_setwhentohangup_tv (struct ast_channel *chan, struct timeval offset)
 Set when to hang a channel up.
struct ast_silence_generator * ast_channel_start_silence_generator (struct ast_channel *chan)
 Starts a silence generator on the given channel.
void ast_channel_stop_silence_generator (struct ast_channel *chan, struct ast_silence_generator *state)
 Stops a previously-started silence generator on the given channel.
int ast_channel_supports_html (struct ast_channel *channel)
void ast_channel_undefer_dtmf (struct ast_channel *chan)
 Unset defer DTMF flag on channel.
void ast_channel_unregister (const struct ast_channel_tech *tech)
 Unregister a channel technology.
struct ast_channel * ast_channel_walk_locked (const struct ast_channel *prev)
 Browse channels in use Browse the channels currently in use.
struct ast_variable * ast_channeltype_list (void)
 return an ast_variable list of channeltypes
int ast_check_hangup (struct ast_channel *chan)
 Check to see if a channel is needing hang up.
void ast_deactivate_generator (struct ast_channel *chan)
int ast_do_masquerade (struct ast_channel *chan)
 Start masquerading a channel XXX This is a seriously whacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX.
static int ast_fdisset (struct pollfd *pfds, int fd, int maximum, int *start)
 Helper function for migrating select to poll.
struct ast_channel * ast_get_channel_by_exten_locked (const char *exten, const char *context)
 Get channel by exten (and optionally context) and lock it.
struct ast_channel * ast_get_channel_by_name_locked (const char *chan)
 Get channel by name or uniqueid (locks channel).
struct ast_channel * ast_get_channel_by_name_prefix_locked (const char *name, const int namelen)
 Get channel by name or uniqueid prefix (locks channel).
struct ast_channel_tech * ast_get_channel_tech (const char *name)
 Get a channel technology structure by name.
ast_group_t ast_get_group (const char *s)
int ast_hangup (struct ast_channel *chan)
 Hang up a channel.
int ast_indicate (struct ast_channel *chan, int condition)
 Indicates condition of channel.
int ast_indicate_data (struct ast_channel *chan, int condition, const void *data, size_t datalen)
 Indicates condition of channel, with payload.
int ast_internal_timing_enabled (struct ast_channel *chan)
 Check if the channel can run in internal timing mode.
int ast_is_deferrable_frame (const struct ast_frame *frame)
 Should we keep this frame for later?
void ast_poll_channel_add (struct ast_channel *chan0, struct ast_channel *chan1)
void ast_poll_channel_del (struct ast_channel *chan0, struct ast_channel *chan1)
char * ast_print_group (char *buf, int buflen, ast_group_t group)
 print call- and pickup groups into buffer
int ast_prod (struct ast_channel *chan)
 Send empty audio to prime a channel driver.
int ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control)
 Queue a control frame with payload.
int ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
 Queue a control frame with payload.
int ast_queue_frame (struct ast_channel *chan, struct ast_frame *f)
 Queue one or more frames to a channel's frame queue.
int ast_queue_frame_head (struct ast_channel *chan, struct ast_frame *f)
 Queue one or more frames to the head of a channel's frame queue.
int ast_queue_hangup (struct ast_channel *chan)
 Queue a hangup frame.
int ast_queue_hangup_with_cause (struct ast_channel *chan, int cause)
 Queue a hangup frame with hangupcause set.
int ast_raw_answer (struct ast_channel *chan, int cdr_answer)
 Answer a channel.
struct ast_frame * ast_read (struct ast_channel *chan)
 Reads a frame.
struct ast_frame * ast_read_noaudio (struct ast_channel *chan)
 Reads a frame, returning AST_FRAME_NULL frame if audio.
int ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders)
int ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd)
int ast_recvchar (struct ast_channel *chan, int timeout)
 Receives a text character from a channel.
char * ast_recvtext (struct ast_channel *chan, int timeout)
 Receives a text string from a channel Read a string of text from a channel.
struct ast_channel * ast_request (const char *type, int format, void *data, int *status)
 Requests a channel.
struct ast_channel * ast_request_and_dial (const char *type, int format, void *data, int timeout, int *reason, const char *cid_num, const char *cid_name)
 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 specified 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 specified amount of time, looking for hangups and a condition argument.
static int ast_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
 Waits for activity on a group of channels.
int ast_senddigit (struct ast_channel *chan, char digit, unsigned int duration)
 Send a DTMF digit to a channel Send a DTMF digit to a channel.
int ast_senddigit_begin (struct ast_channel *chan, char digit)
 Send a DTMF digit to a channel Send a DTMF digit to a channel.
int ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration)
 Send a DTMF digit to a channel.
int ast_sendtext (struct ast_channel *chan, const char *text)
 Sends text to a channel.
void ast_set_callerid (struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
 Set caller ID number, name and ANI.
int ast_set_read_format (struct ast_channel *chan, int format)
 Sets read format on channel chan Set read format for channel to whichever component of "format" is best.
void ast_set_variables (struct ast_channel *chan, struct ast_variable *vars)
 adds a list of channel variables to a channel
int ast_set_write_format (struct ast_channel *chan, int format)
 Sets write format on channel chan Set write format for channel to whichever component of "format" is best.
int ast_setstate (struct ast_channel *chan, enum ast_channel_state)
 Change the state of a channel.
int ast_settimeout (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data)
 Enable or disable timer ticks for a channel.
int ast_shutting_down (void)
 Returns non-zero if Asterisk is being shut down.
int ast_softhangup (struct ast_channel *chan, int reason)
 Softly hangup up a channel.
int ast_softhangup_nolock (struct ast_channel *chan, int reason)
 Softly hangup up a channel (no channel lock).
const char * ast_state2str (enum ast_channel_state)
 Gives the string form of a given channel state.
int ast_str2cause (const char *name) attribute_pure
 Convert a symbolic hangup cause to number.
int ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
int ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
void ast_tonepair_stop (struct ast_channel *chan)
int ast_transfer (struct ast_channel *chan, char *dest)
 Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
char * ast_transfercapability2str (int transfercapability) attribute_const
 Gives the string form of a given transfer capability.
int ast_waitfor (struct ast_channel *chan, int ms)
 Wait for input on a channel.
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.
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.
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.
int ast_waitfordigit (struct ast_channel *c, int ms)
 Waits for a digit.
int ast_waitfordigit_full (struct ast_channel *c, int ms, int audiofd, int ctrlfd)
 Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
struct ast_channel * ast_walk_channel_by_exten_locked (const struct ast_channel *chan, const char *exten, const char *context)
 Get next channel by exten (and optionally context) and lock it.
struct ast_channel * ast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen)
 Get channel by name or uniqueid prefix (locks channel).
int ast_write (struct ast_channel *chan, struct ast_frame *frame)
 Write a frame to a channel This function writes the given frame to the indicated channel.
int ast_write_text (struct ast_channel *chan, struct ast_frame *frame)
 Write text frame to a channel This function writes the given frame to the indicated channel.
int ast_write_video (struct ast_channel *chan, struct ast_frame *frame)
 Write video frame to a channel This function writes the given frame to the indicated channel.
const char * channelreloadreason2txt (enum channelreloadreason reason)
 Convert enum channelreloadreason to text string for manager event.

Variables

unsigned long global_fin
unsigned long global_fout


Detailed Description

General Asterisk PBX channel definitions.

See also:

Definition in file channel.h.


Define Documentation

#define AST_AGENT_FD   (AST_MAX_FDS-3)

used by agents for pass through

Definition at line 160 of file channel.h.

Referenced by agent_read().

#define AST_ALERT_FD   (AST_MAX_FDS-1)

used for alertpipe

Definition at line 158 of file channel.h.

Referenced by __ast_channel_alloc_ap().

#define AST_BRIDGE_DTMF_CHANNEL_0   (1 << 0)

#define AST_BRIDGE_DTMF_CHANNEL_1   (1 << 1)

#define AST_BRIDGE_IGNORE_SIGS   (1 << 4)

Ignore all signal frames except NULL.

Definition at line 1395 of file channel.h.

Referenced by ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), and iax2_bridge().

#define AST_BRIDGE_REC_CHANNEL_0   (1 << 2)

Return all voice frames on channel 0.

Definition at line 1391 of file channel.h.

#define AST_BRIDGE_REC_CHANNEL_1   (1 << 3)

Return all voice frames on channel 1.

Definition at line 1393 of file channel.h.

#define ast_channel_alloc ( needqueue,
state,
cid_num,
cid_name,
acctcode,
exten,
context,
amaflag,
...   ) 

#define AST_CHANNEL_NAME   80

#define AST_GENERATOR_FD   (AST_MAX_FDS-4)

used by generator

Definition at line 161 of file channel.h.

Referenced by __ast_read(), ast_deactivate_generator(), and ast_do_masquerade().

#define AST_MAX_CONTEXT   80

#define AST_MAX_EXTENSION   80

#define AST_MAX_FDS   10

#define AST_TIMING_FD   (AST_MAX_FDS-2)

used for timingfd

Definition at line 159 of file channel.h.

Referenced by __ast_channel_alloc_ap(), __ast_read(), agent_read(), and ast_do_masquerade().

#define CHECK_BLOCKING ( c   ) 

Definition at line 1792 of file channel.h.

Referenced by ast_sendtext(), ast_waitfor_nandfds(), ast_write(), dahdi_read(), and phone_read().

#define DATASTORE_INHERIT_FOREVER   INT_MAX

#define DEBUGCHAN_FLAG   0x80000000

The high bit of the frame count is used as a debug marker, so increments of the counters must be done with care. Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.

Definition at line 334 of file channel.h.

Referenced by __ast_read(), ast_write(), handle_core_set_debug_channel(), handle_showchan(), and serialize_showchan().

#define FRAMECOUNT_INC ( x   )     ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )

Definition at line 337 of file channel.h.

Referenced by __ast_read(), and ast_write().

#define MAX_LANGUAGE   20

Max length of the language setting

Definition at line 137 of file channel.h.

#define MAX_MUSICCLASS   80

Max length of the music class setting

Definition at line 138 of file channel.h.


Typedef Documentation

typedef unsigned long long ast_group_t

Definition at line 170 of file channel.h.


Enumeration Type Documentation

anonymous enum

ast_channel_tech Properties

Enumerator:
AST_CHAN_TP_WANTSJITTER  Channels have this property if they can accept input with jitter; i.e. most VoIP channels.
AST_CHAN_TP_CREATESJITTER  Channels have this property if they can create jitter; i.e. most VoIP channels.

Definition at line 511 of file channel.h.

00511      {
00512    /*! \brief Channels have this property if they can accept input with jitter;
00513     *         i.e. most VoIP channels */
00514    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00515    /*! \brief Channels have this property if they can create jitter;
00516     *         i.e. most VoIP channels */
00517    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00518 };

anonymous enum

ast_channel flags

Enumerator:
AST_FLAG_DEFER_DTMF  Queue incoming dtmf, to be released when this flag is turned off
AST_FLAG_WRITE_INT  write should be interrupt generator
AST_FLAG_BLOCKING  a thread is blocking on this channel
AST_FLAG_ZOMBIE  This is a zombie channel
AST_FLAG_EXCEPTION  There is an exception pending
AST_FLAG_MOH  Listening to moh XXX anthm promises me this will disappear XXX
AST_FLAG_SPYING  This channel is spying on another channel
AST_FLAG_NBRIDGE  This channel is in a native bridge
AST_FLAG_IN_AUTOLOOP  the channel is in an auto-incrementing dialplan processor, so when ->priority is set, it will get incremented before finding the next priority to run
AST_FLAG_OUTGOING  This is an outgoing call
AST_FLAG_IN_DTMF  A DTMF_BEGIN frame has been read from this channel, but not yet an END
AST_FLAG_EMULATE_DTMF  A DTMF_END was received when not IN_DTMF, so the length of the digit is currently being emulated
AST_FLAG_END_DTMF_ONLY  This is set to tell the channel not to generate DTMF begin frames, and to instead only generate END frames.
AST_FLAG_ANSWERED_ELSEWHERE  Flag to show channels that this call is hangup due to the fact that the call was indeed anwered, but in another channel
AST_FLAG_MASQ_NOSTREAM  This flag indicates that on a masquerade, an active stream should not be carried over
AST_FLAG_BRIDGE_HANGUP_RUN  This flag indicates that the hangup exten was run when the bridge terminated, a message aimed at preventing a subsequent hangup exten being run at the pbx_run level
AST_FLAG_BRIDGE_HANGUP_DONT  This flag indicates that the hangup exten should NOT be run when the bridge terminates, this will allow the hangup in the pbx loop to be run instead.
AST_FLAG_IN_CHANNEL_LIST  This flag indicates whether the channel is in the channel list or not.
AST_FLAG_DISABLE_WORKAROUNDS  Disable certain workarounds. This reintroduces certain bugs, but allows some non-traditional dialplans (like AGI) to continue to function.

Definition at line 521 of file channel.h.

00521      {
00522    /*! Queue incoming dtmf, to be released when this flag is turned off */
00523    AST_FLAG_DEFER_DTMF =    (1 << 1),
00524    /*! write should be interrupt generator */
00525    AST_FLAG_WRITE_INT =     (1 << 2),
00526    /*! a thread is blocking on this channel */
00527    AST_FLAG_BLOCKING =      (1 << 3),
00528    /*! This is a zombie channel */
00529    AST_FLAG_ZOMBIE =        (1 << 4),
00530    /*! There is an exception pending */
00531    AST_FLAG_EXCEPTION =     (1 << 5),
00532    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00533    AST_FLAG_MOH =           (1 << 6),
00534    /*! This channel is spying on another channel */
00535    AST_FLAG_SPYING =        (1 << 7),
00536    /*! This channel is in a native bridge */
00537    AST_FLAG_NBRIDGE =       (1 << 8),
00538    /*! the channel is in an auto-incrementing dialplan processor,
00539     *  so when ->priority is set, it will get incremented before
00540     *  finding the next priority to run */
00541    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00542    /*! This is an outgoing call */
00543    AST_FLAG_OUTGOING =      (1 << 10),
00544    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00545    AST_FLAG_IN_DTMF =       (1 << 12),
00546    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
00547     *  currently being emulated */
00548    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00549    /*! This is set to tell the channel not to generate DTMF begin frames, and
00550     *  to instead only generate END frames. */
00551    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00552    /*! Flag to show channels that this call is hangup due to the fact that the call
00553        was indeed anwered, but in another channel */
00554    AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
00555    /*! This flag indicates that on a masquerade, an active stream should not
00556     *  be carried over */
00557    AST_FLAG_MASQ_NOSTREAM = (1 << 16),
00558    /*! This flag indicates that the hangup exten was run when the bridge terminated,
00559     *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
00560     *  level */
00561    AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
00562    /*! This flag indicates that the hangup exten should NOT be run when the
00563     *  bridge terminates, this will allow the hangup in the pbx loop to be run instead.
00564     *  */
00565    AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18),
00566    /*! This flag indicates whether the channel is in the channel list or not. */
00567    AST_FLAG_IN_CHANNEL_LIST = (1 << 19),
00568    /*! Disable certain workarounds.  This reintroduces certain bugs, but allows
00569     *  some non-traditional dialplans (like AGI) to continue to function.
00570     */
00571    AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
00572 };

anonymous enum

ast_bridge_config flags

Enumerator:
AST_FEATURE_PLAY_WARNING 
AST_FEATURE_REDIRECT 
AST_FEATURE_DISCONNECT 
AST_FEATURE_ATXFER 
AST_FEATURE_AUTOMON 
AST_FEATURE_PARKCALL 
AST_FEATURE_AUTOMIXMON 
AST_FEATURE_NO_H_EXTEN 
AST_FEATURE_WARNING_ACTIVE 

Definition at line 575 of file channel.h.

00575      {
00576    AST_FEATURE_PLAY_WARNING = (1 << 0),
00577    AST_FEATURE_REDIRECT =     (1 << 1),
00578    AST_FEATURE_DISCONNECT =   (1 << 2),
00579    AST_FEATURE_ATXFER =       (1 << 3),
00580    AST_FEATURE_AUTOMON =      (1 << 4),
00581    AST_FEATURE_PARKCALL =     (1 << 5),
00582    AST_FEATURE_AUTOMIXMON =   (1 << 6),
00583    AST_FEATURE_NO_H_EXTEN =   (1 << 7),
00584    AST_FEATURE_WARNING_ACTIVE = (1 << 8),
00585 };

anonymous enum

Enumerator:
AST_CDR_TRANSFER 
AST_CDR_FORWARD 
AST_CDR_CALLWAIT 
AST_CDR_CONFERENCE 

Definition at line 624 of file channel.h.

00624      {
00625    AST_CDR_TRANSFER =   (1 << 0),
00626    AST_CDR_FORWARD =    (1 << 1),
00627    AST_CDR_CALLWAIT =   (1 << 2),
00628    AST_CDR_CONFERENCE = (1 << 3),
00629 };

anonymous enum

Enumerator:
AST_SOFTHANGUP_DEV  Soft hangup by device
AST_SOFTHANGUP_ASYNCGOTO  Soft hangup for async goto
AST_SOFTHANGUP_SHUTDOWN 
AST_SOFTHANGUP_TIMEOUT 
AST_SOFTHANGUP_APPUNLOAD 
AST_SOFTHANGUP_EXPLICIT 
AST_SOFTHANGUP_UNBRIDGE 

Definition at line 631 of file channel.h.

00631      {
00632    /*! Soft hangup by device */
00633    AST_SOFTHANGUP_DEV =       (1 << 0),
00634    /*! Soft hangup for async goto */
00635    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00636    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00637    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00638    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00639    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00640    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00641 };

Enumerator:
AST_BRIDGE_COMPLETE 
AST_BRIDGE_FAILED 
AST_BRIDGE_FAILED_NOWARN 
AST_BRIDGE_RETRY 

Definition at line 163 of file channel.h.

00163                        {
00164    AST_BRIDGE_COMPLETE = 0,
00165    AST_BRIDGE_FAILED = -1,
00166    AST_BRIDGE_FAILED_NOWARN = -2,
00167    AST_BRIDGE_RETRY = -3,
00168 };

Enumerator:
AST_ADSI_UNKNOWN 
AST_ADSI_AVAILABLE 
AST_ADSI_UNAVAILABLE 
AST_ADSI_OFFHOOKONLY 

Definition at line 345 of file channel.h.

ast_channel states

Note:
Bits 0-15 of state are reserved for the state (up/down) of the line Bits 16-32 of state are reserved for flags
Enumerator:
AST_STATE_DOWN  Channel is down and available
AST_STATE_RESERVED  Channel is down, but reserved
AST_STATE_OFFHOOK  Channel is off hook
AST_STATE_DIALING  Digits (or equivalent) have been dialed
AST_STATE_RING  Line is ringing
AST_STATE_RINGING  Remote end is ringing
AST_STATE_UP  Line is up
AST_STATE_BUSY  Line is busy
AST_STATE_DIALING_OFFHOOK  Digits (or equivalent) have been dialed while offhook
AST_STATE_PRERING  Channel has detected an incoming call and is waiting for ring
AST_STATE_MUTE  Do not transmit voice data

Definition at line 358 of file channel.h.

00358                        {
00359    AST_STATE_DOWN,         /*!< Channel is down and available */
00360    AST_STATE_RESERVED,     /*!< Channel is down, but reserved */
00361    AST_STATE_OFFHOOK,      /*!< Channel is off hook */
00362    AST_STATE_DIALING,      /*!< Digits (or equivalent) have been dialed */
00363    AST_STATE_RING,         /*!< Line is ringing */
00364    AST_STATE_RINGING,      /*!< Remote end is ringing */
00365    AST_STATE_UP,        /*!< Line is up */
00366    AST_STATE_BUSY,         /*!< Line is busy */
00367    AST_STATE_DIALING_OFFHOOK, /*!< Digits (or equivalent) have been dialed while offhook */
00368    AST_STATE_PRERING,      /*!< Channel has detected an incoming call and is waiting for ring */
00369 
00370    AST_STATE_MUTE = (1 << 16),   /*!< Do not transmit voice data */
00371 };

Possible T38 states on channels.

Enumerator:
T38_STATE_UNAVAILABLE  T38 is unavailable on this channel or disabled by configuration
T38_STATE_UNKNOWN  The channel supports T38 but the current status is unknown
T38_STATE_NEGOTIATING  T38 is being negotiated
T38_STATE_REJECTED  Remote side has rejected our offer
T38_STATE_NEGOTIATED  T38 established

Definition at line 376 of file channel.h.

00376                    {
00377    T38_STATE_UNAVAILABLE,  /*!< T38 is unavailable on this channel or disabled by configuration */
00378    T38_STATE_UNKNOWN,   /*!< The channel supports T38 but the current status is unknown */
00379    T38_STATE_NEGOTIATING,  /*!< T38 is being negotiated */
00380    T38_STATE_REJECTED,  /*!< Remote side has rejected our offer */
00381    T38_STATE_NEGOTIATED,   /*!< T38 established */
00382 };

Channel reload reasons for manager events at load or reload of configuration.

Enumerator:
CHANNEL_MODULE_LOAD 
CHANNEL_MODULE_RELOAD 
CHANNEL_CLI_RELOAD 
CHANNEL_MANAGER_RELOAD 

Definition at line 645 of file channel.h.


Function Documentation

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

Answer a channel, with a selectable delay before returning.

Parameters:
chan channel to answer
delay maximum amount of time to wait for incoming media
cdr_answer flag to control whether any associated CDR should be marked as 'answered'
This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.

This function will wait up to 'delay' milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow. If 'delay' is less than 500, the function will wait up to 500 milliseconds.

Return values:
0 on success
non-zero on failure

Definition at line 1910 of file channel.c.

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

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

01911 {
01912    int res = 0;
01913    enum ast_channel_state old_state;
01914 
01915    old_state = chan->_state;
01916    if ((res = ast_raw_answer(chan, cdr_answer))) {
01917       return res;
01918    }
01919 
01920    switch (old_state) {
01921    case AST_STATE_RINGING:
01922    case AST_STATE_RING:
01923       /* wait for media to start flowing, but don't wait any longer
01924        * than 'delay' or 500 milliseconds, whichever is longer
01925        */
01926       do {
01927          AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
01928          struct ast_frame *cur, *new;
01929          int ms = MAX(delay, 500);
01930          unsigned int done = 0;
01931 
01932          AST_LIST_HEAD_INIT_NOLOCK(&frames);
01933 
01934          for (;;) {
01935             ms = ast_waitfor(chan, ms);
01936             if (ms < 0) {
01937                ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno));
01938                res = -1;
01939                break;
01940             }
01941             if (ms == 0) {
01942                ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500));
01943                break;
01944             }
01945             cur = ast_read(chan);
01946             if (!cur || ((cur->frametype == AST_FRAME_CONTROL) &&
01947                     (cur->subclass == AST_CONTROL_HANGUP))) {
01948                if (cur) {
01949                   ast_frfree(cur);
01950                }
01951                res = -1;
01952                ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name);
01953                break;
01954             }
01955 
01956             if ((new = ast_frisolate(cur)) != cur) {
01957                ast_frfree(cur);
01958             }
01959 
01960             AST_LIST_INSERT_HEAD(&frames, new, frame_list);
01961 
01962             /* if a specific delay period was requested, continue
01963              * until that delay has passed. don't stop just because
01964              * incoming media has arrived.
01965              */
01966             if (delay) {
01967                continue;
01968             }
01969 
01970             switch (new->frametype) {
01971                /* all of these frametypes qualify as 'media' */
01972             case AST_FRAME_VOICE:
01973             case AST_FRAME_VIDEO:
01974             case AST_FRAME_TEXT:
01975             case AST_FRAME_DTMF_BEGIN:
01976             case AST_FRAME_DTMF_END:
01977             case AST_FRAME_IMAGE:
01978             case AST_FRAME_HTML:
01979             case AST_FRAME_MODEM:
01980                done = 1;
01981                break;
01982             case AST_FRAME_CONTROL:
01983             case AST_FRAME_IAX:
01984             case AST_FRAME_NULL:
01985             case AST_FRAME_CNG:
01986                break;
01987             }
01988 
01989             if (done) {
01990                break;
01991             }
01992          }
01993 
01994          if (res == 0) {
01995             ast_channel_lock(chan);
01996             while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
01997                ast_queue_frame_head(chan, cur);
01998                ast_frfree(cur);
01999             }
02000             ast_channel_unlock(chan);
02001          }
02002       } while (0);
02003       break;
02004    default:
02005       break;
02006    }
02007 
02008    return res;
02009 }

struct ast_channel* attribute_malloc __ast_channel_alloc ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const int  amaflag,
const char *  file,
int  line,
const char *  function,
const char *  name_fmt,
  ... 
) [read]

Create a channel structure.

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

Definition at line 978 of file channel.c.

References __ast_channel_alloc_ap().

00983 {
00984    va_list ap1, ap2;
00985    struct ast_channel *result;
00986 
00987    va_start(ap1, name_fmt);
00988    va_start(ap2, name_fmt);
00989    result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
00990                amaflag, file, line, function, name_fmt, ap1, ap2);
00991    va_end(ap1);
00992    va_end(ap2);
00993 
00994    return result;
00995 }

struct ast_channel* __ast_request_and_dial ( const char *  type,
int  format,
void *  data,
int  timeout,
int *  reason,
const char *  cid_num,
const char *  cid_name,
struct outgoing_helper *  oh 
) [read]

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

Parameters:
type type of channel to request
format requested channel format
data data to pass to the channel requester
timeout maximum amount of time to wait for an answer
reason why unsuccessful (if unsuccessful)
cid_num Caller-ID Number
cid_name Caller-ID Name (ascii)
oh Outgoing helper
Returns:
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 4036 of file channel.c.

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

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

04037 {
04038    int dummy_outstate;
04039    int cause = 0;
04040    struct ast_channel *chan;
04041    int res = 0;
04042    int last_subclass = 0;
04043    
04044    if (outstate)
04045       *outstate = 0;
04046    else
04047       outstate = &dummy_outstate;   /* make outstate always a valid pointer */
04048 
04049    chan = ast_request(type, format, data, &cause);
04050    if (!chan) {
04051       ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
04052       handle_cause(cause, outstate);
04053       return NULL;
04054    }
04055 
04056    if (oh) {
04057       if (oh->vars)  
04058          ast_set_variables(chan, oh->vars);
04059       /* XXX why is this necessary, for the parent_channel perhaps ? */
04060       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name))
04061          ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
04062       if (oh->parent_channel) {
04063          ast_channel_inherit_variables(oh->parent_channel, chan);
04064          ast_channel_datastore_inherit(oh->parent_channel, chan);
04065       }
04066       if (oh->account)
04067          ast_cdr_setaccount(chan, oh->account); 
04068    }
04069    ast_set_callerid(chan, cid_num, cid_name, cid_num);
04070    ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED);
04071 
04072    if (ast_call(chan, data, 0)) {   /* ast_call failed... */
04073       ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
04074    } else {
04075       res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
04076       while (timeout && chan->_state != AST_STATE_UP) {
04077          struct ast_frame *f;
04078          res = ast_waitfor(chan, timeout);
04079          if (res == 0) { /* timeout, treat it like ringing */
04080             *outstate = AST_CONTROL_RINGING;
04081             break;
04082          }
04083          if (res < 0) /* error or done */
04084             break;
04085          if (timeout > -1)
04086             timeout = res;
04087          if (!ast_strlen_zero(chan->call_forward)) {
04088             if (!(chan = ast_call_forward(NULL, chan, &timeout, format, oh, outstate))) {
04089                return NULL;
04090             }
04091             continue;
04092          }
04093 
04094          f = ast_read(chan);
04095          if (!f) {
04096             *outstate = AST_CONTROL_HANGUP;
04097             res = 0;
04098             break;
04099          }
04100          if (f->frametype == AST_FRAME_CONTROL) {
04101             switch (f->subclass) {
04102             case AST_CONTROL_RINGING:  /* record but keep going */
04103                *outstate = f->subclass;
04104                break;
04105 
04106             case AST_CONTROL_BUSY:
04107                ast_cdr_busy(chan->cdr);
04108                *outstate = f->subclass;
04109                timeout = 0;
04110                break;
04111 
04112             case AST_CONTROL_CONGESTION:
04113                ast_cdr_failed(chan->cdr);
04114                *outstate = f->subclass;
04115                timeout = 0;
04116                break;
04117 
04118             case AST_CONTROL_ANSWER:
04119                ast_cdr_answer(chan->cdr);
04120                *outstate = f->subclass;
04121                timeout = 0;      /* trick to force exit from the while() */
04122                break;
04123 
04124             /* Ignore these */
04125             case AST_CONTROL_PROGRESS:
04126             case AST_CONTROL_PROCEEDING:
04127             case AST_CONTROL_HOLD:
04128             case AST_CONTROL_UNHOLD:
04129             case AST_CONTROL_VIDUPDATE:
04130             case AST_CONTROL_SRCUPDATE:
04131             case AST_CONTROL_SRCCHANGE:
04132             case -1:       /* Ignore -- just stopping indications */
04133                break;
04134 
04135             default:
04136                ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass);
04137             }
04138             last_subclass = f->subclass;
04139          }
04140          ast_frfree(f);
04141       }
04142    }
04143 
04144    /* Final fixups */
04145    if (oh) {
04146       if (!ast_strlen_zero(oh->context))
04147          ast_copy_string(chan->context, oh->context, sizeof(chan->context));
04148       if (!ast_strlen_zero(oh->exten))
04149          ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
04150       if (oh->priority) 
04151          chan->priority = oh->priority;
04152    }
04153    if (chan->_state == AST_STATE_UP)
04154       *outstate = AST_CONTROL_ANSWER;
04155 
04156    if (res <= 0) {
04157       if ( AST_CONTROL_RINGING == last_subclass ) 
04158          chan->hangupcause = AST_CAUSE_NO_ANSWER;
04159       if (!chan->cdr && (chan->cdr = ast_cdr_alloc()))
04160          ast_cdr_init(chan->cdr, chan);
04161       if (chan->cdr) {
04162          char tmp[256];
04163          snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data);
04164          ast_cdr_setapp(chan->cdr,"Dial",tmp);
04165          ast_cdr_update(chan);
04166          ast_cdr_start(chan->cdr);
04167          ast_cdr_end(chan->cdr);
04168          /* If the cause wasn't handled properly */
04169          if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
04170             ast_cdr_failed(chan->cdr);
04171       }
04172       ast_hangup(chan);
04173       chan = NULL;
04174    }
04175    return chan;
04176 }

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

Activate a given generator

Definition at line 2061 of file channel.c.

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

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

02062 {
02063    int res = 0;
02064 
02065    ast_channel_lock(chan);
02066    if (chan->generatordata) {
02067       if (chan->generator && chan->generator->release)
02068          chan->generator->release(chan, chan->generatordata);
02069       chan->generatordata = NULL;
02070    }
02071    if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) {
02072       res = -1;
02073    }
02074    if (!res) {
02075       ast_settimeout(chan, 50, generator_force, chan);
02076       chan->generator = gen;
02077    }
02078    ast_channel_unlock(chan);
02079 
02080    ast_prod(chan);
02081 
02082    return res;
02083 }

int ast_active_channels ( void   ) 

returns number of active/allocated channels

Returns number of active/allocated channels

Definition at line 497 of file channel.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.

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

00498 {
00499    struct ast_channel *c;
00500    int cnt = 0;
00501    AST_RWLIST_RDLOCK(&channels);
00502    AST_RWLIST_TRAVERSE(&channels, c, chan_list)
00503       cnt++;
00504    AST_RWLIST_UNLOCK(&channels);
00505    return cnt;
00506 }

static int ast_add_fd ( struct pollfd *  pfd,
int  fd 
) [inline, static]

if fd is a valid descriptor, set *pfd with the descriptor

Returns:
Return 1 (not -1!) if added, 0 otherwise (so we can add the return value to the index into the array)

Definition at line 1706 of file channel.h.

Referenced by ast_waitfor_nandfds().

01707 {
01708    pfd->fd = fd;
01709    pfd->events = POLLIN | POLLPRI;
01710    return fd >= 0;
01711 }

int ast_answer ( struct ast_channel *  chan  ) 

Answer a channel.

Parameters:
chan channel to answer
This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.

This function will wait up to 500 milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow.

Return values:
0 on success
non-zero on failure

Definition at line 2011 of file channel.c.

References __ast_answer().

Referenced by action_bridge(), agi_exec_full(), alarmreceiver_exec(), answer_trunk_chan(), app_exec(), ast_control_streamfile(), ast_pickup_call(), auth_exec(), background_detect_exec(), bridge_exec(), builtin_parkcall(), common_exec(), conf_exec(), count_exec(), dahdiras_exec(), dictate_exec(), directory_exec(), disa_exec(), eivr_comm(), handle_answer(), ices_exec(), login_exec(), minivm_accmess_exec(), minivm_greet_exec(), minivm_record_exec(), old_milliwatt_exec(), park_call_exec(), park_exec_full(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), readexten_exec(), record_exec(), rpt_exec(), sayunixtime_exec(), send_waveform_to_channel(), setup_privacy_args(), skel_exec(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), transmit(), vm_exec(), vm_execmain(), waitfor_exec(), and zapateller_exec().

02012 {
02013    return __ast_answer(chan, 0, 1);
02014 }

int ast_autoservice_ignore ( struct ast_channel *  chan,
enum ast_frame_type  ftype 
)

Ignore certain frame types.

Note:
Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames while a channel is in autoservice and queue them up when taken out of autoservice. When this is not desireable, this API may be used to cause the channel to ignore those frametypes after the channel is put into autoservice, but before autoservice is stopped.
Return values:
0 success
-1 channel is not in autoservice

Definition at line 302 of file autoservice.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, asent::chan, asent::ignore_frame_types, and asent::list.

Referenced by builtin_atxfer(), builtin_automixmonitor(), builtin_blindtransfer(), feature_exec_app(), and play_message_in_bridged_call().

00303 {
00304    struct asent *as;
00305    int res = -1;
00306 
00307    AST_LIST_LOCK(&aslist);
00308    AST_LIST_TRAVERSE(&aslist, as, list) {
00309       if (as->chan == chan) {
00310          res = 0;
00311          as->ignore_frame_types |= (1 << ftype);
00312          break;
00313       }
00314    }
00315    AST_LIST_UNLOCK(&aslist);
00316    return res;
00317 }

int ast_autoservice_start ( struct ast_channel *  chan  ) 

Automatically service a channel for us...

Return values:
0 success
-1 failure, or the channel is already being autoserviced

Definition at line 174 of file autoservice.c.

References as_cond, ast_calloc, ast_channel_lock, ast_channel_unlock, ast_cond_signal(), AST_FLAG_END_DTMF_ONLY, AST_LIST_EMPTY, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_pthread_create_background, AST_PTHREADT_NULL, ast_set_flag, ast_test_flag, asthread, autoservice_run(), asent::chan, free, asent::list, LOG_WARNING, asent::orig_end_dtmf_flag, and asent::use_count.

Referenced by _macro_exec(), acf_curl_exec(), acf_odbc_read(), acf_odbc_write(), ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), bridge_playfile(), builtin_atxfer(), builtin_automixmonitor(), builtin_blindtransfer(), conf_play(), confbridge_exec(), dial_exec_full(), feature_exec_app(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), leave_conference_bridge(), lock_read(), lua_autoservice_start(), lua_get_variable_value(), lua_pbx_exec(), lua_set_variable(), lua_set_variable_value(), originate_exec(), osplookup_exec(), pbx_find_extension(), play_message_in_bridged_call(), post_join_marked(), realtimefield_read(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), system_exec_helper(), try_calling(), and trylock_read().

00175 {
00176    int res = 0;
00177    struct asent *as;
00178 
00179    AST_LIST_LOCK(&aslist);
00180    AST_LIST_TRAVERSE(&aslist, as, list) {
00181       if (as->chan == chan) {
00182          as->use_count++;
00183          break;
00184       }
00185    }
00186    AST_LIST_UNLOCK(&aslist);
00187 
00188    if (as) {
00189       /* Entry exists, autoservice is already handling this channel */
00190       return 0;
00191    }
00192 
00193    if (!(as = ast_calloc(1, sizeof(*as))))
00194       return -1;
00195    
00196    /* New entry created */
00197    as->chan = chan;
00198    as->use_count = 1;
00199 
00200    ast_channel_lock(chan);
00201    as->orig_end_dtmf_flag = ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY) ? 1 : 0;
00202    if (!as->orig_end_dtmf_flag)
00203       ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
00204    ast_channel_unlock(chan);
00205 
00206    AST_LIST_LOCK(&aslist);
00207 
00208    if (AST_LIST_EMPTY(&aslist) && asthread != AST_PTHREADT_NULL) {
00209       ast_cond_signal(&as_cond);
00210    }
00211 
00212    AST_LIST_INSERT_HEAD(&aslist, as, list);
00213 
00214    if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
00215       if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
00216          ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
00217          /* There will only be a single member in the list at this point,
00218             the one we just added. */
00219          AST_LIST_REMOVE(&aslist, as, list);
00220          free(as);
00221          asthread = AST_PTHREADT_NULL;
00222          res = -1;
00223       } else {
00224          pthread_kill(asthread, SIGURG);
00225       }
00226    }
00227 
00228    AST_LIST_UNLOCK(&aslist);
00229 
00230    return res;
00231 }

int ast_autoservice_stop ( struct ast_channel *  chan  ) 

Stop servicing a channel for us...

Note:
if chan is locked prior to calling ast_autoservice_stop, it is likely that there will be a deadlock between the thread that calls ast_autoservice_stop and the autoservice thread. It is important that chan is not locked prior to this call
Return values:
0 success
-1 error, or the channel has been hungup

Definition at line 233 of file autoservice.c.

References ast_channel::_softhangup, as_chan_list_state, ast_channel_lock, ast_channel_unlock, ast_clear_flag, AST_FLAG_END_DTMF_ONLY, ast_frfree, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, AST_PTHREADT_NULL, ast_queue_frame_head(), asthread, asent::chan, asent::deferred_frames, f, ast_frame::frametype, free, asent::ignore_frame_types, asent::list, asent::orig_end_dtmf_flag, and asent::use_count.

Referenced by _macro_exec(), acf_curl_exec(), acf_odbc_read(), acf_odbc_write(), array(), ast_dtmf_stream(), ast_get_enum(), ast_get_srv(), ast_get_txt(), ast_hangup(), bridge_playfile(), builtin_atxfer(), builtin_automixmonitor(), conf_play(), confbridge_exec(), dial_exec_full(), feature_exec_app(), finishup(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), leave_conference_bridge(), lock_read(), lua_autoservice_stop(), lua_get_variable_value(), lua_pbx_exec(), lua_set_variable(), lua_set_variable_value(), originate_exec(), osplookup_exec(), pbx_find_extension(), play_message_in_bridged_call(), post_join_marked(), realtimefield_read(), shell_helper(), sla_station_exec(), smdi_msg_retrieve_read(), system_exec_helper(), try_calling(), and trylock_read().

00234 {
00235    int res = -1;
00236    struct asent *as, *removed = NULL;
00237    struct ast_frame *f;
00238    int chan_list_state;
00239 
00240    AST_LIST_LOCK(&aslist);
00241 
00242    /* Save the autoservice channel list state.  We _must_ verify that the channel
00243     * list has been rebuilt before we return.  Because, after we return, the channel
00244     * could get destroyed and we don't want our poor autoservice thread to step on
00245     * it after its gone! */
00246    chan_list_state = as_chan_list_state;
00247 
00248    /* Find the entry, but do not free it because it still can be in the
00249       autoservice thread array */
00250    AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) {  
00251       if (as->chan == chan) {
00252          as->use_count--;
00253          if (as->use_count < 1) {
00254             AST_LIST_REMOVE_CURRENT(list);
00255             removed = as;
00256          }
00257          break;
00258       }
00259    }
00260    AST_LIST_TRAVERSE_SAFE_END;
00261 
00262    if (removed && asthread != AST_PTHREADT_NULL) {
00263       pthread_kill(asthread, SIGURG);
00264    }
00265 
00266    AST_LIST_UNLOCK(&aslist);
00267 
00268    if (!removed) {
00269       return 0;
00270    }
00271 
00272    /* Wait while autoservice thread rebuilds its list. */
00273    while (chan_list_state == as_chan_list_state) {
00274       usleep(1000);
00275    }
00276 
00277    /* Now autoservice thread should have no references to our entry
00278       and we can safely destroy it */
00279 
00280    if (!chan->_softhangup) {
00281       res = 0;
00282    }
00283 
00284    if (!as->orig_end_dtmf_flag) {
00285       ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
00286    }
00287 
00288    ast_channel_lock(chan);
00289    while ((f = AST_LIST_REMOVE_HEAD(&as->deferred_frames, frame_list))) {
00290       if (!((1 << f->frametype) & as->ignore_frame_types)) {
00291          ast_queue_frame_head(chan, f);
00292       }
00293       ast_frfree(f);
00294    }
00295    ast_channel_unlock(chan);
00296 
00297    free(as);
00298 
00299    return res;
00300 }

void ast_begin_shutdown ( int  hangup  ) 

Initiate system shutdown.

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

Definition at line 483 of file channel.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.

Referenced by quit_handler().

00484 {
00485    struct ast_channel *c;
00486    shutting_down = 1;
00487    if (hangup) {
00488       AST_RWLIST_RDLOCK(&channels);
00489       AST_RWLIST_TRAVERSE(&channels, c, chan_list) {
00490          ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN);
00491       }
00492       AST_RWLIST_UNLOCK(&channels);
00493    }
00494 }

int ast_best_codec ( int  fmts  ) 

Pick the best audio codec.

Pick the best codec

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

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

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

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

G.726 is standard ADPCM, in RFC3551 packing order

G.726 is standard ADPCM, in AAL2 packing order

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

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

iLBC is not too bad

Speex is free, but computationally more expensive than GSM

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

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

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

Definition at line 711 of file channel.c.

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

Referenced by __oh323_new(), agent_call(), ast_codec_choose(), ast_iax2_new(), ast_speech_new(), bridge_make_compatible(), builtin_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), jingle_new(), local_new(), login_exec(), mgcp_new(), sip_new(), skinny_new(), skinny_set_rtp_peer(), socket_process(), start_rtp(), transmit_connect(), and unistim_new().

00712 {
00713    /* This just our opinion, expressed in code.  We are asked to choose
00714       the best codec to use, given no information */
00715    int x;
00716    static const int prefs[] =
00717    {
00718       /*! Okay, ulaw is used by all telephony equipment, so start with it */
00719       AST_FORMAT_ULAW,
00720       /*! Unless of course, you're a silly European, so then prefer ALAW */
00721       AST_FORMAT_ALAW,
00722       AST_FORMAT_SIREN14,
00723       AST_FORMAT_SIREN7,
00724       /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
00725       AST_FORMAT_G722,
00726       /*! Okay, well, signed linear is easy to translate into other stuff */
00727       AST_FORMAT_SLINEAR16,
00728       AST_FORMAT_SLINEAR,
00729       /*! G.726 is standard ADPCM, in RFC3551 packing order */
00730       AST_FORMAT_G726,
00731       /*! G.726 is standard ADPCM, in AAL2 packing order */
00732       AST_FORMAT_G726_AAL2,
00733       /*! ADPCM has great sound quality and is still pretty easy to translate */
00734       AST_FORMAT_ADPCM,
00735       /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
00736           translate and sounds pretty good */
00737       AST_FORMAT_GSM,
00738       /*! iLBC is not too bad */
00739       AST_FORMAT_ILBC,
00740       /*! Speex is free, but computationally more expensive than GSM */
00741       AST_FORMAT_SPEEX,
00742       /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
00743           to use it */
00744       AST_FORMAT_LPC10,
00745       /*! G.729a is faster than 723 and slightly less expensive */
00746       AST_FORMAT_G729A,
00747       /*! Down to G.723.1 which is proprietary but at least designed for voice */
00748       AST_FORMAT_G723_1,
00749    };
00750 
00751    /* Strip out video */
00752    fmts &= AST_FORMAT_AUDIO_MASK;
00753    
00754    /* Find the first preferred codec in the format given */
00755    for (x = 0; x < ARRAY_LEN(prefs); x++) {
00756       if (fmts & prefs[x])
00757          return prefs[x];
00758    }
00759 
00760    ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts);
00761 
00762    return 0;
00763 }

struct ast_channel* ast_bridged_channel ( struct ast_channel *  chan  )  [read]

int ast_call ( struct ast_channel *  chan,
char *  addr,
int  timeout 
)

Make a call.

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

Definition at line 4239 of file channel.c.

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

Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), attempt_reconnect(), begin_dial_channel(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), do_idle_thread(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_exec(), and wait_for_answer().

04240 {
04241    /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
04242       If the remote end does not answer within the timeout, then do NOT hang up, but
04243       return anyway.  */
04244    int res = -1;
04245    /* Stop if we're a zombie or need a soft hangup */
04246    ast_channel_lock(chan);
04247    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
04248       if (chan->cdr) {
04249          ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED);
04250       }
04251       if (chan->tech->call)
04252          res = chan->tech->call(chan, addr, timeout);
04253       ast_set_flag(chan, AST_FLAG_OUTGOING);
04254    }
04255    ast_channel_unlock(chan);
04256    return res;
04257 }

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

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

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

Definition at line 3964 of file channel.c.

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

Referenced by __ast_request_and_dial(), and feature_request_and_dial().

03965 {
03966    char tmpchan[256];
03967    struct ast_channel *new = NULL;
03968    char *data, *type;
03969    int cause = 0;
03970 
03971    /* gather data and request the new forward channel */
03972    ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan));
03973    if ((data = strchr(tmpchan, '/'))) {
03974       *data++ = '\0';
03975       type = tmpchan;
03976    } else {
03977       const char *forward_context;
03978       ast_channel_lock(orig);
03979       forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT");
03980       snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context));
03981       ast_channel_unlock(orig);
03982       data = tmpchan;
03983       type = "Local";
03984    }
03985    if (!(new = ast_request(type, format, data, &cause))) {
03986       ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause);
03987       handle_cause(cause, outstate);
03988       ast_hangup(orig);
03989       return NULL;
03990    }
03991 
03992    /* Copy/inherit important information into new channel */
03993    if (oh) {
03994       if (oh->vars) {
03995          ast_set_variables(new, oh->vars);
03996       }
03997       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
03998          ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num);
03999       }
04000       if (oh->parent_channel) {
04001          ast_channel_inherit_variables(oh->parent_channel, new);
04002          ast_channel_datastore_inherit(oh->parent_channel, new);
04003       }
04004       if (oh->account) {
04005          ast_cdr_setaccount(new, oh->account);
04006       }
04007    } else if (caller) { /* no outgoing helper so use caller if avaliable */
04008       ast_channel_inherit_variables(caller, new);
04009       ast_channel_datastore_inherit(caller, new);
04010    }
04011 
04012    ast_channel_lock(orig);
04013    while (ast_channel_trylock(new)) {
04014       CHANNEL_DEADLOCK_AVOIDANCE(orig);
04015    }
04016    ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED);
04017    ast_string_field_set(new, accountcode, orig->accountcode);
04018    if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) {
04019       ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num);
04020    }
04021    ast_channel_unlock(new);
04022    ast_channel_unlock(orig);
04023 
04024    /* call new channel */
04025    if ((*timeout = ast_call(new, data, 0))) {
04026       ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data);
04027       ast_hangup(orig);
04028       ast_hangup(new);
04029       return NULL;
04030    }
04031    ast_hangup(orig);
04032 
04033    return new;
04034 }

void ast_cancel_shutdown ( void   ) 

Cancel a shutdown in progress.

Cancels an existing shutdown and returns to normal operation

Definition at line 509 of file channel.c.

Referenced by handle_abort_shutdown().

00510 {
00511    shutting_down = 0;
00512 }

const char* ast_cause2str ( int  state  ) 

Gives the string form of a given hangup cause.

Gives the string form of a given cause code

Parameters:
state cause to get the description of Give a name to a cause code Returns the text form of the binary cause code given

Definition at line 629 of file channel.c.

References ARRAY_LEN, and causes.

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

00630 {
00631    int x;
00632 
00633    for (x = 0; x < ARRAY_LEN(causes); x++) {
00634       if (causes[x].cause == cause)
00635          return causes[x].desc;
00636    }
00637 
00638    return "Unknown";
00639 }

void ast_change_name ( struct ast_channel *  chan,
char *  newname 
)

Change channel name.

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

Definition at line 4496 of file channel.c.

References ast_string_field_set, EVENT_FLAG_CALL, manager_event, name, ast_channel::name, and ast_channel::uniqueid.

Referenced by update_name().

04497 {
04498    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid);
04499    ast_string_field_set(chan, name, newname);
04500 }

int ast_channel_bridge ( struct ast_channel *  c0,
struct ast_channel *  c1,
struct ast_bridge_config *  config,
struct ast_frame **  fo,
struct ast_channel **  rc 
)

Bridge two channels together.

Bridge two channels together

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

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

Referenced by ast_bridge_call().

05258 {
05259    struct ast_channel *who = NULL;
05260    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
05261    int nativefailed=0;
05262    int firstpass;
05263    int o0nativeformats;
05264    int o1nativeformats;
05265    long time_left_ms=0;
05266    char caller_warning = 0;
05267    char callee_warning = 0;
05268 
05269    if (c0->_bridge) {
05270       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
05271          c0->name, c0->_bridge->name);
05272       return -1;
05273    }
05274    if (c1->_bridge) {
05275       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
05276          c1->name, c1->_bridge->name);
05277       return -1;
05278    }
05279    
05280    /* Stop if we're a zombie or need a soft hangup */
05281    if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
05282        ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
05283       return -1;
05284 
05285    *fo = NULL;
05286    firstpass = config->firstpass;
05287    config->firstpass = 0;
05288 
05289    if (ast_tvzero(config->start_time))
05290       config->start_time = ast_tvnow();
05291    time_left_ms = config->timelimit;
05292 
05293    caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
05294    callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
05295 
05296    if (config->start_sound && firstpass) {
05297       if (caller_warning)
05298          bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000);
05299       if (callee_warning)
05300          bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000);
05301    }
05302 
05303    /* Keep track of bridge */
05304    c0->_bridge = c1;
05305    c1->_bridge = c0;
05306 
05307 
05308    o0nativeformats = c0->nativeformats;
05309    o1nativeformats = c1->nativeformats;
05310 
05311    if (config->feature_timer && !ast_tvzero(config->nexteventts)) {
05312       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000));
05313    } else if (config->timelimit && firstpass) {
05314       config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
05315       if (caller_warning || callee_warning)
05316          config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000));
05317    }
05318 
05319    if (!c0->tech->send_digit_begin)
05320       ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY);
05321    if (!c1->tech->send_digit_begin)
05322       ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY);
05323    manager_bridge_event(1, 1, c0, c1);
05324 
05325    /* Before we enter in and bridge these two together tell them both the source of audio has changed */
05326    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
05327    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
05328 
05329    for (/* ever */;;) {
05330       struct timeval now = { 0, };
05331       int to;
05332 
05333       to = -1;
05334 
05335       if (!ast_tvzero(config->nexteventts)) {
05336          now = ast_tvnow();
05337          to = ast_tvdiff_ms(config->nexteventts, now);
05338          if (to <= 0) {
05339             if (!config->timelimit) {
05340                res = AST_BRIDGE_COMPLETE;
05341                break;
05342             }
05343             to = 0;
05344          }
05345       }
05346 
05347       if (config->timelimit) {
05348          time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
05349          if (time_left_ms < to)
05350             to = time_left_ms;
05351 
05352          if (time_left_ms <= 0) {
05353             if (caller_warning && config->end_sound)
05354                bridge_playfile(c0, c1, config->end_sound, 0);
05355             if (callee_warning && config->end_sound)
05356                bridge_playfile(c1, c0, config->end_sound, 0);
05357             *fo = NULL;
05358             if (who)
05359                *rc = who;
05360             res = 0;
05361             break;
05362          }
05363 
05364          if (!to) {
05365             if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) {
05366                int t = (time_left_ms + 500) / 1000; /* round to nearest second */
05367                if (caller_warning)
05368                   bridge_playfile(c0, c1, config->warning_sound, t);
05369                if (callee_warning)
05370                   bridge_playfile(c1, c0, config->warning_sound, t);
05371             }
05372             if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000)))
05373                config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000));
05374             else
05375                config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
05376          }
05377          ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE);
05378       }
05379 
05380       if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
05381          if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
05382             c0->_softhangup = 0;
05383          if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
05384             c1->_softhangup = 0;
05385          c0->_bridge = c1;
05386          c1->_bridge = c0;
05387          ast_debug(1, "Unbridge signal received. Ending native bridge.\n");
05388          continue;
05389       }
05390 
05391       /* Stop if we're a zombie or need a soft hangup */
05392       if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
05393           ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
05394          *fo = NULL;
05395          if (who)
05396             *rc = who;
05397          res = 0;
05398          ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",
05399             c0->name, c1->name,
05400             ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No",
05401             ast_check_hangup(c0) ? "Yes" : "No",
05402             ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No",
05403             ast_check_hangup(c1) ? "Yes" : "No");
05404          break;
05405       }
05406 
05407       update_bridge_vars(c0, c1);
05408 
05409       bridge_play_sounds(c0, c1);
05410 
05411       if (c0->tech->bridge &&
05412          /* if < 1 ms remains use generic bridging for accurate timing */
05413          (!config->timelimit || to > 1000 || to == 0) &&
05414           (c0->tech->bridge == c1->tech->bridge) &&
05415           !nativefailed && !c0->monitor && !c1->monitor &&
05416           !c0->audiohooks && !c1->audiohooks &&
05417           !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) {
05418          int timeoutms = to - 1000 > 0 ? to - 1000 : to;
05419          /* Looks like they share a bridge method and nothing else is in the way */
05420          ast_set_flag(c0, AST_FLAG_NBRIDGE);
05421          ast_set_flag(c1, AST_FLAG_NBRIDGE);
05422          if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) {
05423             /* \todo  XXX here should check that cid_num is not NULL */
05424             manager_event(EVENT_FLAG_CALL, "Unlink",
05425                      "Channel1: %s\r\n"
05426                      "Channel2: %s\r\n"
05427                      "Uniqueid1: %s\r\n"
05428                      "Uniqueid2: %s\r\n"
05429                      "CallerID1: %s\r\n"
05430                      "CallerID2: %s\r\n",
05431                      c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
05432             ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name);
05433 
05434             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
05435             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
05436 
05437             if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
05438                continue;
05439 
05440             c0->_bridge = NULL;
05441             c1->_bridge = NULL;
05442 
05443             return res;
05444          } else {
05445             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
05446             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
05447          }
05448          switch (res) {
05449          case AST_BRIDGE_RETRY:
05450             if (config->play_warning) {
05451                ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE);
05452             }
05453             continue;
05454          default:
05455             ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name);
05456             /* fallthrough */
05457          case AST_BRIDGE_FAILED_NOWARN:
05458             nativefailed++;
05459             break;
05460          }
05461       }
05462 
05463       if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
05464           (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
05465           !(c0->generator || c1->generator)) {
05466          if (ast_channel_make_compatible(c0, c1)) {
05467             ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
05468             manager_bridge_event(0, 1, c0, c1);
05469             return AST_BRIDGE_FAILED;
05470          }
05471          o0nativeformats = c0->nativeformats;
05472          o1nativeformats = c1->nativeformats;
05473       }
05474 
05475       update_bridge_vars(c0, c1);
05476 
05477       res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts);
05478       if (res != AST_BRIDGE_RETRY) {
05479          break;
05480       } else if (config->feature_timer) {
05481          /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */
05482          break;
05483       }
05484    }
05485 
05486    ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY);
05487    ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY);
05488 
05489    /* Now that we have broken the bridge the source will change yet again */
05490    ast_indicate(c0, AST_CONTROL_SRCUPDATE);
05491    ast_indicate(c1, AST_CONTROL_SRCUPDATE);
05492 
05493    c0->_bridge = NULL;
05494    c1->_bridge = NULL;
05495 
05496    /* \todo  XXX here should check that cid_num is not NULL */
05497    manager_event(EVENT_FLAG_CALL, "Unlink",
05498             "Channel1: %s\r\n"
05499             "Channel2: %s\r\n"
05500             "Uniqueid1: %s\r\n"
05501             "Uniqueid2: %s\r\n"
05502             "CallerID1: %s\r\n"
05503             "CallerID2: %s\r\n",
05504             c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
05505    ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
05506 
05507    return res;
05508 }

int ast_channel_cmpwhentohangup ( struct ast_channel *  chan,
time_t  offset 
)

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

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

Definition at line 550 of file channel.c.

References ast_channel_cmpwhentohangup_tv().

00551 {
00552    struct timeval when = { offset, };
00553    return ast_channel_cmpwhentohangup_tv(chan, when);
00554 }

int ast_channel_cmpwhentohangup_tv ( struct ast_channel *  chan,
struct timeval  offset 
)

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

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

Definition at line 535 of file channel.c.

References ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.

Referenced by ast_channel_cmpwhentohangup().

00536 {
00537    struct timeval whentohangup;
00538 
00539    if (ast_tvzero(chan->whentohangup))
00540       return ast_tvzero(offset) ? 0 : -1;
00541 
00542    if (ast_tvzero(offset))
00543       return 1;
00544 
00545    whentohangup = ast_tvadd(offset, ast_tvnow());
00546 
00547    return ast_tvdiff_ms(whentohangup, chan->whentohangup);
00548 }

int ast_channel_datastore_add ( struct ast_channel *  chan,
struct ast_datastore *  datastore 
)

struct ast_datastore* attribute_malloc ast_channel_datastore_alloc ( const struct ast_datastore_info *  info,
const char *  uid 
) [read]

Create a channel data store object.

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

Definition at line 1567 of file channel.c.

References ast_datastore_alloc.

01568 {
01569    return ast_datastore_alloc(info, uid);
01570 }

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

Find a datastore on a channel.

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

The datastore returned from this function must not be used if the reference to the channel is released.

Return values:
pointer to the datastore if found
NULL if not found

Definition at line 1608 of file channel.c.

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

Referenced by _macro_exec(), acf_curl_exec(), acf_curlopt_read(), acf_curlopt_write(), acf_exception_read(), acf_fetch(), acf_iaxvar_read(), acf_iaxvar_write(), add_agi_cmd(), add_features_datastores(), add_to_agi(), apply_plc(), ast_odbc_retrieve_transaction_obj(), attended_transfer_occurred(), audiohook_volume_callback(), audiohook_volume_get(), builtin_atxfer(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), dundi_result_read(), enable_jack_hook(), enum_result_read(), exec_odbcfinish(), find_speech(), find_transaction(), func_inheritance_write(), get_agi_cmd(), get_lock(), gosub_exec(), handle_gosub(), iax2_call(), jack_hook_callback(), local_read(), local_write(), lock_fixup(), lua_get_state(), manage_parkinglot(), mark_transaction_active(), park_exec_full(), pbx_builtin_raise_exception(), pop_exec(), queue_transfer_fixup(), release_transaction(), return_exec(), shared_read(), shared_write(), smdi_msg_read(), speech_background(), speech_destroy(), speex_callback(), speex_read(), speex_write(), stop_mixmonitor_exec(), try_calling(), unlock_read(), volume_callback(), and volume_write().

01609 {
01610    struct ast_datastore *datastore = NULL;
01611    
01612    if (info == NULL)
01613       return NULL;
01614 
01615    AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) {
01616       if (datastore->info != info) {
01617          continue;
01618       }
01619 
01620       if (uid == NULL) {
01621          /* matched by type only */
01622          break;
01623       }
01624 
01625       if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) {
01626          /* Matched by type AND uid */
01627          break;
01628       }
01629    }
01630    AST_LIST_TRAVERSE_SAFE_END;
01631 
01632    return datastore;
01633 }

int ast_channel_datastore_free ( struct ast_datastore *  datastore  ) 

Free a channel data store object.

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

Definition at line 1572 of file channel.c.

References ast_datastore_free().

01573 {
01574    return ast_datastore_free(datastore);
01575 }

int ast_channel_datastore_inherit ( struct ast_channel *  from,
struct ast_channel *  to 
)

Inherit datastores from a parent to a child.

Definition at line 1577 of file channel.c.

References ast_datastore_alloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_channel::datastores, ast_datastore_info::duplicate, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.

Referenced by __ast_request_and_dial(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), do_forward(), findmeexec(), local_call(), ring_entry(), and wait_for_answer().

01578 {
01579    struct ast_datastore *datastore = NULL, *datastore2;
01580 
01581    AST_LIST_TRAVERSE(&from->datastores, datastore, entry) {
01582       if (datastore->inheritance > 0) {
01583          datastore2 = ast_datastore_alloc(datastore->info, datastore->uid);
01584          if (datastore2) {
01585             datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL;
01586             datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
01587             AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry);
01588          }
01589       }
01590    }
01591    return 0;
01592 }

int ast_channel_datastore_remove ( struct ast_channel *  chan,
struct ast_datastore *  datastore 
)

Remove a datastore from a channel.

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

Definition at line 1603 of file channel.c.

References AST_LIST_REMOVE, and ast_channel::datastores.

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

01604 {
01605    return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1;
01606 }

int ast_channel_defer_dtmf ( struct ast_channel *  chan  ) 

Set defer DTMF flag on channel.

Defers DTMF

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

Definition at line 1152 of file channel.c.

References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.

Referenced by __adsi_transmit_messages(), and find_cache().

01153 {
01154    int pre = 0;
01155 
01156    if (chan) {
01157       pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
01158       ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
01159    }
01160    return pre;
01161 }

int ast_channel_early_bridge ( struct ast_channel *  c0,
struct ast_channel *  c1 
)

Bridge two channels together (early).

Bridge two channels together (early)

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

Definition at line 5158 of file channel.c.

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

Referenced by dial_exec_full(), and wait_for_answer().

05159 {
05160    /* Make sure we can early bridge, if not error out */
05161    if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge)))
05162       return -1;
05163 
05164    return c0->tech->early_bridge(c0, c1);
05165 }

void ast_channel_free ( struct ast_channel *   ) 

Free a channel structure.

Definition at line 1448 of file channel.c.

References ast_channel::alertpipe, ast_app_group_discard(), ast_cdr_discard(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), ast_datastore_free(), ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), AST_FLAG_IN_CHANNEL_LIST, ast_free, ast_frfree, ast_jb_destroy(), AST_LIST_REMOVE_HEAD, ast_log(), AST_MAX_FDS, ast_moh_cleanup(), ast_mutex_destroy(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_test_flag, ast_timer_close(), ast_tone_zone_unref(), ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, ast_channel::cid, ast_channel::datastores, f, free, free_cid(), ast_channel::lock_dont_use, LOG_WARNING, ast_channel::monitor, ast_channel::music_state, ast_channel::name, name, ast_channel::pbx, ast_channel::readq, ast_channel::readtrans, ast_channel::sched, sched_context_destroy(), ast_channel_monitor::stop, ast_channel::tech_pvt, ast_channel::timer, ast_channel::varshead, ast_channel::writetrans, and ast_channel::zone.

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

01449 {
01450    int fd;
01451 #ifdef HAVE_EPOLL
01452    int i;
01453 #endif
01454    struct ast_var_t *vardata;
01455    struct ast_frame *f;
01456    struct varshead *headp;
01457    struct ast_datastore *datastore = NULL;
01458    char name[AST_CHANNEL_NAME], *dashptr;
01459    int inlist;
01460    
01461    headp=&chan->varshead;
01462    
01463    inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST);
01464    if (inlist) {
01465       AST_RWLIST_WRLOCK(&channels);
01466       if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) {
01467          ast_debug(1, "Unable to find channel in list to free. Assuming it has already been done.\n");
01468       }
01469       /* Lock and unlock the channel just to be sure nobody has it locked still
01470          due to a reference retrieved from the channel list. */
01471       ast_channel_lock(chan);
01472       ast_channel_unlock(chan);
01473    }
01474 
01475    /* Get rid of each of the data stores on the channel */
01476    ast_channel_lock(chan);
01477    while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry)))
01478       /* Free the data store */
01479       ast_datastore_free(datastore);
01480    ast_channel_unlock(chan);
01481 
01482    /* Lock and unlock the channel just to be sure nobody has it locked still
01483       due to a reference that was stored in a datastore. (i.e. app_chanspy) */
01484    ast_channel_lock(chan);
01485    ast_channel_unlock(chan);
01486 
01487    if (chan->tech_pvt) {
01488       ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name);
01489       ast_free(chan->tech_pvt);
01490    }
01491 
01492    if (chan->sched)
01493       sched_context_destroy(chan->sched);
01494 
01495    ast_copy_string(name, chan->name, sizeof(name));
01496    if ((dashptr = strrchr(name, '-'))) {
01497       *dashptr = '\0';
01498    }
01499 
01500    /* Stop monitoring */
01501    if (chan->monitor)
01502       chan->monitor->stop( chan, 0 );
01503 
01504    /* If there is native format music-on-hold state, free it */
01505    if (chan->music_state)
01506       ast_moh_cleanup(chan);
01507 
01508    /* Free translators */
01509    if (chan->readtrans)
01510       ast_translator_free_path(chan->readtrans);
01511    if (chan->writetrans)
01512       ast_translator_free_path(chan->writetrans);
01513    if (chan->pbx)
01514       ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
01515    free_cid(&chan->cid);
01516    /* Close pipes if appropriate */
01517    if ((fd = chan->alertpipe[0]) > -1)
01518       close(fd);
01519    if ((fd = chan->alertpipe[1]) > -1)
01520       close(fd);
01521    if (chan->timer) {
01522       ast_timer_close(chan->timer);
01523    }
01524 #ifdef HAVE_EPOLL
01525    for (i = 0; i < AST_MAX_FDS; i++) {
01526       if (chan->epfd_data[i])
01527          free(chan->epfd_data[i]);
01528    }
01529    close(chan->epfd);
01530 #endif
01531    while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list)))
01532       ast_frfree(f);
01533    
01534    /* loop over the variables list, freeing all data and deleting list items */
01535    /* no need to lock the list, as the channel is already locked */
01536    
01537    while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
01538       ast_var_delete(vardata);
01539 
01540    ast_app_group_discard(chan);
01541 
01542    /* Destroy the jitterbuffer */
01543    ast_jb_destroy(chan);
01544 
01545    if (chan->cdr) {
01546       ast_cdr_discard(chan->cdr);
01547       chan->cdr = NULL;
01548    }
01549 
01550    if (chan->zone) {
01551       chan->zone = ast_tone_zone_unref(chan->zone);
01552    }
01553 
01554    ast_mutex_destroy(&chan->lock_dont_use);
01555 
01556    ast_string_field_free_memory(chan);
01557    ast_free(chan);
01558    if (inlist)
01559       AST_RWLIST_UNLOCK(&channels);
01560 
01561    /* Queue an unknown state, because, while we know that this particular
01562     * instance is dead, we don't know the state of all other possible
01563     * instances. */
01564    ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name);
01565 }

static enum ast_t38_state ast_channel_get_t38_state ( struct ast_channel *  chan  )  [inline, static]

Retrieves the current T38 state of a channel.

Definition at line 1782 of file channel.h.

References ast_channel_queryoption(), AST_OPTION_T38_STATE, and T38_STATE_UNAVAILABLE.

Referenced by transmit(), transmit_audio(), and transmit_t38().

01783 {
01784    enum ast_t38_state state = T38_STATE_UNAVAILABLE;
01785    int datalen = sizeof(state);
01786 
01787    ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
01788 
01789    return state;
01790 }

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

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

Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), ring_entry(), and wait_for_answer().

04503 {
04504    struct ast_var_t *current, *newvar;
04505    const char *varname;
04506 
04507    AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
04508       int vartype = 0;
04509 
04510       varname = ast_var_full_name(current);
04511       if (!varname)
04512          continue;
04513 
04514       if (varname[0] == '_') {
04515          vartype = 1;
04516          if (varname[1] == '_')
04517             vartype = 2;
04518       }
04519 
04520       switch (vartype) {
04521       case 1:
04522          newvar = ast_var_assign(&varname[1], ast_var_value(current));
04523          if (newvar) {
04524             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
04525             ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar));
04526          }
04527          break;
04528       case 2:
04529          newvar = ast_var_assign(varname, ast_var_value(current));
04530          if (newvar) {
04531             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
04532             ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar));
04533          }
04534          break;
04535       default:
04536          ast_debug(1, "Not copying variable %s.\n", ast_var_name(current));
04537          break;
04538       }
04539    }
04540 }

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

References ast_channel_make_compatible_helper().

Referenced by action_bridge(), app_exec(), ast_channel_bridge(), bridge_exec(), check_compat(), dial_exec_full(), do_forward(), multiplexed_bridge_join(), park_exec_full(), simple_bridge_join(), try_calling(), and wait_for_answer().

04401 {
04402    /* Some callers do not check return code, and we must try to set all call legs correctly */
04403    int rc = 0;
04404 
04405    /* Set up translation from the chan to the peer */
04406    rc = ast_channel_make_compatible_helper(chan, peer);
04407 
04408    if (rc < 0)
04409       return rc;
04410 
04411    /* Set up translation from the peer to the chan */
04412    rc = ast_channel_make_compatible_helper(peer, chan);
04413 
04414    return rc;
04415 }

int ast_channel_masquerade ( struct ast_channel *  original,
struct ast_channel *  clone 
)

Weird function made for call transfers.

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

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

Definition at line 4417 of file channel.c.

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

Referenced by ast_async_goto(), ast_pickup_call(), attempt_transfer(), builtin_atxfer(), check_availability(), check_bridge(), check_goto_on_transfer(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), masq_park_call(), misdn_attempt_transfer(), pickup_do(), sip_park(), and skinny_transfer().

04418 {
04419    int res = -1;
04420    struct ast_channel *final_orig, *final_clone, *base;
04421 
04422 retrymasq:
04423    final_orig = original;
04424    final_clone = clonechan;
04425 
04426    ast_channel_lock(original);
04427    while (ast_channel_trylock(clonechan)) {
04428       ast_channel_unlock(original);
04429       usleep(1);
04430       ast_channel_lock(original);
04431    }
04432 
04433    /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
04434       and if so, we don't really want to masquerade it, but its proxy */
04435    if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original))
04436       final_orig = original->_bridge;
04437 
04438    if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan))
04439       final_clone = clonechan->_bridge;
04440    
04441    if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) {
04442       final_clone = base;
04443    }
04444 
04445    if ((final_orig != original) || (final_clone != clonechan)) {
04446       /* Lots and lots of deadlock avoidance.  The main one we're competing with
04447        * is ast_write(), which locks channels recursively, when working with a
04448        * proxy channel. */
04449       if (ast_channel_trylock(final_orig)) {
04450          ast_channel_unlock(clonechan);
04451          ast_channel_unlock(original);
04452          goto retrymasq;
04453       }
04454       if (ast_channel_trylock(final_clone)) {
04455          ast_channel_unlock(final_orig);
04456          ast_channel_unlock(clonechan);
04457          ast_channel_unlock(original);
04458          goto retrymasq;
04459       }
04460       ast_channel_unlock(clonechan);
04461       ast_channel_unlock(original);
04462       original = final_orig;
04463       clonechan = final_clone;
04464    }
04465 
04466    if (original == clonechan) {
04467       ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
04468       ast_channel_unlock(clonechan);
04469       ast_channel_unlock(original);
04470       return -1;
04471    }
04472 
04473    ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n",
04474       clonechan->name, original->name);
04475    if (original->masq) {
04476       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
04477          original->masq->name, original->name);
04478    } else if (clonechan->masqr) {
04479       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
04480          clonechan->name, clonechan->masqr->name);
04481    } else {
04482       original->masq = clonechan;
04483       clonechan->masqr = original;
04484       ast_queue_frame(original, &ast_null_frame);
04485       ast_queue_frame(clonechan, &ast_null_frame);
04486       ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name);
04487       res = 0;
04488    }
04489 
04490    ast_channel_unlock(clonechan);
04491    ast_channel_unlock(original);
04492 
04493    return res;
04494 }

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

Checks the value of an option

Query the value of an option Works similarly to setoption except only reads the options.

Definition at line 5524 of file channel.c.

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

Referenced by ast_channel_get_t38_state().

05525 {
05526    if (!chan->tech->queryoption) {
05527       errno = ENOSYS;
05528       return -1;
05529    }
05530 
05531    if (block)
05532       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
05533 
05534    return chan->tech->queryoption(chan, option, data, datalen);
05535 }

const char* ast_channel_reason2str ( int  reason  ) 

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

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

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

03929 {
03930    switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */
03931    {
03932    case 0:
03933       return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)";
03934    case AST_CONTROL_HANGUP:
03935       return "Hangup";
03936    case AST_CONTROL_RING:
03937       return "Local Ring";
03938    case AST_CONTROL_RINGING:
03939       return "Remote end Ringing";
03940    case AST_CONTROL_ANSWER:
03941       return "Remote end has Answered";
03942    case AST_CONTROL_BUSY:
03943       return "Remote end is Busy";
03944    case AST_CONTROL_CONGESTION:
03945       return "Congestion (circuits busy)";
03946    default:
03947       return "Unknown Reason!!";
03948    }
03949 }

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

References ast_calloc, ast_debug, AST_LIST_INSERT_HEAD, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_channel_tech::description, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.

Referenced by load_module(), and unload_module().

00558 {
00559    struct chanlist *chan;
00560 
00561    AST_RWLIST_WRLOCK(&channels);
00562 
00563    AST_LIST_TRAVERSE(&backends, chan, list) {
00564       if (!strcasecmp(tech->type, chan->tech->type)) {
00565          ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
00566          AST_RWLIST_UNLOCK(&channels);
00567          return -1;
00568       }
00569    }
00570    
00571    if (!(chan = ast_calloc(1, sizeof(*chan)))) {
00572       AST_RWLIST_UNLOCK(&channels);
00573       return -1;
00574    }
00575    chan->tech = tech;
00576    AST_LIST_INSERT_HEAD(&backends, chan, list);
00577 
00578    ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
00579 
00580    ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description);
00581 
00582    AST_RWLIST_UNLOCK(&channels);
00583    return 0;
00584 }

struct ast_channel* ast_channel_search_locked ( int(*)(struct ast_channel *, void *)  is_match,
void *  data 
) [read]

Search for a channel based on the passed channel matching callback Search for a channel based on the specified is_match callback, and return the first channel that we match. When returned, the channel will be locked. Note that the is_match callback is called with the passed channel locked, and should return 0 if there is no match, and non-zero if there is.

Parameters:
is_match callback executed on each channel until non-zero is returned, or we run out of channels to search.
data data passed to the is_match callback during each invocation.
Returns:
Returns the matched channel, or NULL if no channel was matched.

Definition at line 1316 of file channel.c.

References ast_channel_lock, ast_channel_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.

Referenced by ast_pickup_call(), pickup_by_exten(), pickup_by_mark(), and transmit_state_notify().

01317 {
01318    struct ast_channel *c = NULL;
01319 
01320    AST_RWLIST_RDLOCK(&channels);
01321    AST_RWLIST_TRAVERSE(&channels, c, chan_list) {
01322       ast_channel_lock(c);
01323       if (is_match(c, data)) {
01324          break;
01325       }
01326       ast_channel_unlock(c);
01327    }
01328    AST_RWLIST_UNLOCK(&channels);
01329 
01330    return c;
01331 }

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

Sends HTML on given channel

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

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

04343 {
04344    if (chan->tech->send_html)
04345       return chan->tech->send_html(chan, subclass, data, datalen);
04346    return -1;
04347 }

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

Sends a URL on a given link

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

Definition at line 4349 of file channel.c.

References ast_channel_sendhtml(), and AST_HTML_URL.

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

04350 {
04351    return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
04352 }

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

Set the file descriptor on the channel

Definition at line 1636 of file channel.c.

References ast_calloc, ast_epoll_data::chan, ast_channel::fds, free, and ast_epoll_data::which.

Referenced by __ast_channel_alloc_ap(), __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), alsa_new(), ast_deactivate_generator(), ast_do_masquerade(), dahdi_new(), gtalk_new(), jingle_new(), mgcp_new(), misdn_new(), nbs_new(), oss_new(), phone_new(), pri_assign_bearer(), pri_fixup_principle(), setformat(), sip_new(), skinny_new(), start_rtp(), and swap_subs().

01637 {
01638 #ifdef HAVE_EPOLL
01639    struct epoll_event ev;
01640    struct ast_epoll_data *aed = NULL;
01641 
01642    if (chan->fds[which] > -1) {
01643       epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev);
01644       aed = chan->epfd_data[which];
01645    }
01646 
01647    /* If this new fd is valid, add it to the epoll */
01648    if (fd > -1) {
01649       if (!aed && (!(aed = ast_calloc(1, sizeof(*aed)))))
01650          return;
01651       
01652       chan->epfd_data[which] = aed;
01653       aed->chan = chan;
01654       aed->which = which;
01655       
01656       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
01657       ev.data.ptr = aed;
01658       epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev);
01659    } else if (aed) {
01660       /* We don't have to keep around this epoll data structure now */
01661       free(aed);
01662       chan->epfd_data[which] = NULL;
01663    }
01664 #endif
01665    chan->fds[which] = fd;
01666    return;
01667 }

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

Sets an option on a channel.

Sets an option on a channel

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

Definition at line 5511 of file channel.c.

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

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

05512 {
05513    if (!chan->tech->setoption) {
05514       errno = ENOSYS;
05515       return -1;
05516    }
05517 
05518    if (block)
05519       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
05520 
05521    return chan->tech->setoption(chan, option, data, datalen);
05522 }

void ast_channel_setwhentohangup ( struct ast_channel *  chan,
time_t  offset 
)

Set when to hang a channel up.

Parameters:
chan channel on which to check for hang up
offset offset in seconds relative to the current time of when to hang up
This function sets the absolute time out on a channel (when to hang up).

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

Definition at line 528 of file channel.c.

References ast_channel_setwhentohangup_tv().

00529 {
00530    struct timeval when = { offset, };
00531    ast_channel_setwhentohangup_tv(chan, when);
00532 }

void ast_channel_setwhentohangup_tv ( struct ast_channel *  chan,
struct timeval  offset 
)

Set when to hang a channel up.

Parameters:
chan channel on which to check for hang up
offset offset in seconds and useconds relative to the current time of when to hang up
This function sets the absolute time out on a channel (when to hang up).

Note:
This function does not require that the channel is locked before calling it.
Returns:
Nothing
Since:
1.6.1

Definition at line 521 of file channel.c.

References ast_null_frame, ast_queue_frame(), ast_tvadd(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.

Referenced by action_timeout(), ast_channel_setwhentohangup(), handle_autohangup(), and timeout_write().

00522 {
00523    chan->whentohangup = ast_tvzero(offset) ? offset : ast_tvadd(offset, ast_tvnow());
00524    ast_queue_frame(chan, &ast_null_frame);
00525    return;
00526 }

struct ast_silence_generator* ast_channel_start_silence_generator ( struct ast_channel *  chan  )  [read]

Starts a silence generator on the given channel.

Parameters:
chan The channel to generate silence on
Returns:
An ast_silence_generator pointer, or NULL if an error occurs
This function will cause SLINEAR silence to be generated on the supplied channel until it is disabled; if the channel cannot be put into SLINEAR mode then the function will fail.

The pointer returned by this function must be preserved and passed to ast_channel_stop_silence_generator when you wish to stop the silence generation.

Definition at line 5862 of file channel.c.

References ast_activate_generator(), ast_calloc, ast_debug, AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, and ast_channel::writeformat.

Referenced by __ast_play_and_record(), ast_dtmf_stream(), ast_safe_sleep_conditional(), channel_spy(), record_exec(), TransferCallStep1(), waitfor_exec(), and waitforring_exec().

05863 {
05864    struct ast_silence_generator *state;
05865 
05866    if (!(state = ast_calloc(1, sizeof(*state)))) {
05867       return NULL;
05868    }
05869 
05870    state->old_write_format = chan->writeformat;
05871 
05872    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
05873       ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
05874       ast_free(state);
05875       return NULL;
05876    }
05877 
05878    ast_activate_generator(chan, &silence_generator, state);
05879 
05880    ast_debug(1, "Started silence generator on '%s'\n", chan->name);
05881 
05882    return state;
05883 }

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

References ast_deactivate_generator(), ast_debug, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_channel::name, and ast_silence_generator::old_write_format.

Referenced by __ast_play_and_record(), ast_dtmf_stream(), ast_safe_sleep_conditional(), channel_spy(), HandleCallOutgoing(), key_dial_page(), record_exec(), unistim_hangup(), waitfor_exec(), and waitforring_exec().

05886 {
05887    if (!state)
05888       return;
05889 
05890    ast_deactivate_generator(chan);
05891 
05892    ast_debug(1, "Stopped silence generator on '%s'\n", chan->name);
05893 
05894    if (ast_set_write_format(chan, state->old_write_format) < 0)
05895       ast_log(LOG_ERROR, "Could not return write format to its original state\n");
05896 
05897    ast_free(state);
05898 }

int ast_channel_supports_html ( struct ast_channel *  channel  ) 

Checks for HTML support on a channel

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

Definition at line 4337 of file channel.c.

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

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

04338 {
04339    return (chan->tech->send_html) ? 1 : 0;
04340 }

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

References ast_clear_flag, and AST_FLAG_DEFER_DTMF.

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

01165 {
01166    if (chan)
01167       ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
01168 }

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

References ast_debug, ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::tech, and ast_channel_tech::type.

Referenced by __unload_module(), load_module(), and unload_module().

00588 {
00589    struct chanlist *chan;
00590 
00591    ast_debug(1, "Unregistering channel type '%s'\n", tech->type);
00592 
00593    AST_RWLIST_WRLOCK(&channels);
00594 
00595    AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
00596       if (chan->tech == tech) {
00597          AST_LIST_REMOVE_CURRENT(list);
00598          ast_free(chan);
00599          ast_verb(2, "Unregistered channel type '%s'\n", tech->type);
00600          break;   
00601       }
00602    }
00603    AST_LIST_TRAVERSE_SAFE_END;
00604 
00605    AST_RWLIST_UNLOCK(&channels);
00606 }

struct ast_channel* ast_channel_walk_locked ( const struct ast_channel *  prev  )  [read]

Browse channels in use Browse 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 1278 of file channel.c.

References channel_find_locked().

Referenced by action_coreshowchannels(), action_status(), ast_complete_channels(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), conf_exec(), func_channels_read(), handle_chanlist(), handle_core_set_debug_channel(), and next_channel().

01279 {
01280    return channel_find_locked(prev, NULL, 0, NULL, NULL);
01281 }

struct ast_variable* ast_channeltype_list ( void   )  [read]

return an ast_variable list of channeltypes

Definition at line 186 of file channel.c.

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

Referenced by ast_var_channel_types(), and ast_var_channel_types_table().

00187 {
00188    struct chanlist *cl;
00189    struct ast_variable *var=NULL, *prev = NULL;
00190    AST_LIST_TRAVERSE(&backends, cl, list) {
00191       if (prev)  {
00192          if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, "")))
00193             prev = prev->next;
00194       } else {
00195          var = ast_variable_new(cl->tech->type, cl->tech->description, "");
00196          prev = var;
00197       }
00198    }
00199    return var;
00200 }

int ast_check_hangup ( struct ast_channel *  chan  ) 

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

References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.

Referenced by __ast_pbx_run(), __ast_read(), _macro_exec(), action_redirect(), agent_indicate(), agi_exec(), agi_handle_command(), announce_thread(), ast_bridge_call(), ast_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_indicate_data(), ast_raw_answer(), ast_readstring_full(), ast_recvtext(), ast_rtp_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), autoservice_run(), bridge_call_thread(), bridge_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_bridge(), common_exec(), conf_play(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), feature_request_and_dial(), findmeexec(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), rpt(), rpt_exec(), run_ras(), try_calling(), and wait_for_answer().

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

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 whacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX.

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

Note:
Assumes channel will be locked when called

Definition at line 4593 of file channel.c.

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

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

04594 {
04595    int x,i;
04596    int res=0;
04597    int origstate;
04598    struct ast_frame *current;
04599    const struct ast_channel_tech *t;
04600    void *t_pvt;
04601    struct ast_callerid tmpcid;
04602    struct ast_channel *clonechan = original->masq;
04603    struct ast_cdr *cdr;
04604    int rformat = original->readformat;
04605    int wformat = original->writeformat;
04606    char newn[AST_CHANNEL_NAME];
04607    char orig[AST_CHANNEL_NAME];
04608    char masqn[AST_CHANNEL_NAME];
04609    char zombn[AST_CHANNEL_NAME];
04610 
04611    ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
04612       clonechan->name, clonechan->_state, original->name, original->_state);
04613 
04614    manager_event(EVENT_FLAG_CALL, "Masquerade", "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n",
04615             clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state));
04616 
04617    /* XXX This operation is a bit odd.  We're essentially putting the guts of
04618     * the clone channel into the original channel.  Start by killing off the
04619     * original channel's backend.  While the features are nice, which is the
04620     * reason we're keeping it, it's still awesomely weird. XXX */
04621 
04622    /* We need the clone's lock, too */
04623    ast_channel_lock(clonechan);
04624 
04625    ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clonechan->name, &clonechan->lock_dont_use);
04626 
04627    /* Having remembered the original read/write formats, we turn off any translation on either
04628       one */
04629    free_translation(clonechan);
04630    free_translation(original);
04631 
04632 
04633    /* Unlink the masquerade */
04634    original->masq = NULL;
04635    clonechan->masqr = NULL;
04636    
04637    /* Save the original name */
04638    ast_copy_string(orig, original->name, sizeof(orig));
04639    /* Save the new name */
04640    ast_copy_string(newn, clonechan->name, sizeof(newn));
04641    /* Create the masq name */
04642    snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
04643       
04644    /* Copy the name from the clone channel */
04645    ast_string_field_set(original, name, newn);
04646 
04647    /* Mangle the name of the clone channel */
04648    ast_string_field_set(clonechan, name, masqn);
04649    
04650    /* Notify any managers of the change, first the masq then the other */
04651    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clonechan->uniqueid);
04652    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid);
04653 
04654    /* Swap the technologies */   
04655    t = original->tech;
04656    original->tech = clonechan->tech;
04657    clonechan->tech = t;
04658 
04659    /* Swap the cdrs */
04660    cdr = original->cdr;
04661    original->cdr = clonechan->cdr;
04662    clonechan->cdr = cdr;
04663 
04664    t_pvt = original->tech_pvt;
04665    original->tech_pvt = clonechan->tech_pvt;
04666    clonechan->tech_pvt = t_pvt;
04667 
04668    /* Swap the alertpipes */
04669    for (i = 0; i < 2; i++) {
04670       x = original->alertpipe[i];
04671       original->alertpipe[i] = clonechan->alertpipe[i];
04672       clonechan->alertpipe[i] = x;
04673    }
04674 
04675    /* 
04676     * Swap the readq's.  The end result should be this:
04677     *
04678     *  1) All frames should be on the new (original) channel.
04679     *  2) Any frames that were already on the new channel before this
04680     *     masquerade need to be at the end of the readq, after all of the
04681     *     frames on the old (clone) channel.
04682     *  3) The alertpipe needs to get poked for every frame that was already
04683     *     on the new channel, since we are now using the alert pipe from the
04684     *     old (clone) channel.
04685     */
04686    {
04687       AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq;
04688       AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL);
04689 
04690       AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list);
04691       AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list);
04692 
04693       while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) {
04694          AST_LIST_INSERT_TAIL(&original->readq, current, frame_list);
04695          if (original->alertpipe[1] > -1) {
04696             int poke = 0;
04697 
04698             if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) {
04699                ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
04700             }
04701          }
04702       }
04703    }
04704 
04705    /* Swap the raw formats */
04706    x = original->rawreadformat;
04707    original->rawreadformat = clonechan->rawreadformat;
04708    clonechan->rawreadformat = x;
04709    x = original->rawwriteformat;
04710    original->rawwriteformat = clonechan->rawwriteformat;
04711    clonechan->rawwriteformat = x;
04712 
04713    clonechan->_softhangup = AST_SOFTHANGUP_DEV;
04714 
04715    /* And of course, so does our current state.  Note we need not
04716       call ast_setstate since the event manager doesn't really consider
04717       these separate.  We do this early so that the clone has the proper
04718       state of the original channel. */
04719    origstate = original->_state;
04720    original->_state = clonechan->_state;
04721    clonechan->_state = origstate;
04722 
04723    if (clonechan->tech->fixup){
04724       res = clonechan->tech->fixup(original, clonechan);
04725       if (res)
04726          ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name);
04727    }
04728 
04729    /* Start by disconnecting the original's physical side */
04730    if (clonechan->tech->hangup)
04731       res = clonechan->tech->hangup(clonechan);
04732    if (res) {
04733       ast_log(LOG_WARNING, "Hangup failed!  Strange things may happen!\n");
04734       ast_channel_unlock(clonechan);
04735       return -1;
04736    }
04737 
04738    snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig);
04739    /* Mangle the name of the clone channel */
04740    ast_string_field_set(clonechan, name, zombn);
04741    manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clonechan->uniqueid);
04742 
04743    /* Update the type. */
04744    t_pvt = original->monitor;
04745    original->monitor = clonechan->monitor;
04746    clonechan->monitor = t_pvt;
04747 
04748    /* Keep the same language.  */
04749    ast_string_field_set(original, language, clonechan->language);
04750    /* Copy the FD's other than the generator fd */
04751    for (x = 0; x < AST_MAX_FDS; x++) {
04752       if (x != AST_GENERATOR_FD)
04753          ast_channel_set_fd(original, x, clonechan->fds[x]);
04754    }
04755 
04756    ast_app_group_update(clonechan, original);
04757 
04758    /* Move data stores over */
04759    if (AST_LIST_FIRST(&clonechan->datastores)) {
04760       struct ast_datastore *ds;
04761       /* We use a safe traversal here because some fixup routines actually
04762        * remove the datastore from the list and free them.
04763        */
04764       AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) {
04765          if (ds->info->chan_fixup)
04766             ds->info->chan_fixup(ds->data, clonechan, original);
04767       }
04768       AST_LIST_TRAVERSE_SAFE_END;
04769       AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry);
04770    }
04771 
04772    clone_variables(original, clonechan);
04773    /* Presense of ADSI capable CPE follows clone */
04774    original->adsicpe = clonechan->adsicpe;
04775    /* Bridge remains the same */
04776    /* CDR fields remain the same */
04777    /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
04778    /* Application and data remain the same */
04779    /* Clone exception  becomes real one, as with fdno */
04780    ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION));
04781    original->fdno = clonechan->fdno;
04782    /* Schedule context remains the same */
04783    /* Stream stuff stays the same */
04784    /* Keep the original state.  The fixup code will need to work with it most likely */
04785 
04786    /* Just swap the whole structures, nevermind the allocations, they'll work themselves
04787       out. */
04788    tmpcid = original->cid;
04789    original->cid = clonechan->cid;
04790    clonechan->cid = tmpcid;
04791    report_new_callerid(original);
04792 
04793    /* Restore original timing file descriptor */
04794    ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd);
04795 
04796    /* Our native formats are different now */
04797    original->nativeformats = clonechan->nativeformats;
04798 
04799    /* Context, extension, priority, app data, jump table,  remain the same */
04800    /* pvt switches.  pbx stays the same, as does next */
04801 
04802    /* Set the write format */
04803    ast_set_write_format(original, wformat);
04804 
04805    /* Set the read format */
04806    ast_set_read_format(original, rformat);
04807 
04808    /* Copy the music class */
04809    ast_string_field_set(original, musicclass, clonechan->musicclass);
04810 
04811    ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
04812 
04813    /* Okay.  Last thing is to let the channel driver know about all this mess, so he
04814       can fix up everything as best as possible */
04815    if (original->tech->fixup) {
04816       res = original->tech->fixup(clonechan, original);
04817       if (res) {
04818          ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n",
04819             original->tech->type, original->name);
04820          ast_channel_unlock(clonechan);
04821          return -1;
04822       }
04823    } else
04824       ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)!  Bad things may happen.\n",
04825          original->tech->type, original->name);
04826 
04827    /* 
04828     * If an indication is currently playing, maintain it on the channel 
04829     * that is taking the place of original 
04830     *
04831     * This is needed because the masquerade is swapping out in the internals
04832     * of this channel, and the new channel private data needs to be made
04833     * aware of the current visible indication (RINGING, CONGESTION, etc.)
04834     */
04835    if (original->visible_indication) {
04836       ast_indicate(original, original->visible_indication);
04837    }
04838    
04839    /* Now, at this point, the "clone" channel is totally F'd up.  We mark it as
04840       a zombie so nothing tries to touch it.  If it's already been marked as a
04841       zombie, then free it now (since it already is considered invalid). */
04842    if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) {
04843       ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name);
04844       ast_channel_unlock(clonechan);
04845       manager_event(EVENT_FLAG_CALL, "Hangup",
04846          "Channel: %s\r\n"
04847          "Uniqueid: %s\r\n"
04848          "Cause: %d\r\n"
04849          "Cause-txt: %s\r\n",
04850          clonechan->name,
04851          clonechan->uniqueid,
04852          clonechan->hangupcause,
04853          ast_cause2str(clonechan->hangupcause)
04854          );
04855       ast_channel_free(clonechan);
04856    } else {
04857       ast_debug(1, "Released clone lock on '%s'\n", clonechan->name);
04858       ast_set_flag(clonechan, AST_FLAG_ZOMBIE);
04859       ast_queue_frame(clonechan, &ast_null_frame);
04860       ast_channel_unlock(clonechan);
04861    }
04862 
04863    /* Signal any blocker */
04864    if (ast_test_flag(original, AST_FLAG_BLOCKING))
04865       pthread_kill(original->blocker, SIGURG);
04866    ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state);
04867    return 0;
04868 }

static int ast_fdisset ( struct pollfd *  pfds,
int  fd,
int  maximum,
int *  start 
) [inline, static]

Helper function for migrating select to poll.

Definition at line 1714 of file channel.h.

References dummy().

Referenced by do_monitor().

01715 {
01716    int x;
01717    int dummy = 0;
01718 
01719    if (fd < 0)
01720       return 0;
01721    if (!start)
01722       start = &dummy;
01723    for (x = *start; x < maximum; x++)
01724       if (pfds[x].fd == fd) {
01725          if (x == *start)
01726             (*start)++;
01727          return pfds[x].revents;
01728       }
01729    return 0;
01730 }

struct ast_channel* ast_get_channel_by_exten_locked ( const char *  exten,
const char *  context 
) [read]

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

Definition at line 1303 of file channel.c.

References channel_find_locked().

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

struct ast_channel* ast_get_channel_by_name_locked ( const char *  name  )  [read]

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

Get channel by name or uniqueid prefix (locks channel).

Definition at line 1290 of file channel.c.

References channel_find_locked().

Referenced by action_bridge(), ast_parse_device_state(), bridge_exec(), common_exec(), handle_cli_mixmonitor(), shared_read(), and shared_write().

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

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

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

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

Referenced by __ast_channel_alloc_ap(), _ast_device_state(), and ast_var_channel_types_table().

00610 {
00611    struct chanlist *chanls;
00612    const struct ast_channel_tech *ret = NULL;
00613 
00614    AST_RWLIST_RDLOCK(&channels);
00615 
00616    AST_LIST_TRAVERSE(&backends, chanls, list) {
00617       if (!strcasecmp(name, chanls->tech->type)) {
00618          ret = chanls->tech;
00619          break;
00620       }
00621    }
00622 
00623    AST_RWLIST_UNLOCK(&channels);
00624    
00625    return ret;
00626 }

ast_group_t ast_get_group ( const char *  s  ) 

Definition at line 5689 of file channel.c.

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

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

05690 {
05691    char *piece;
05692    char *c;
05693    int start=0, finish=0, x;
05694    ast_group_t group = 0;
05695 
05696    if (ast_strlen_zero(s))
05697       return 0;
05698 
05699    c = ast_strdupa(s);
05700    
05701    while ((piece = strsep(&c, ","))) {
05702       if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) {
05703          /* Range */
05704       } else if (sscanf(piece, "%30d", &start)) {
05705          /* Just one */
05706          finish = start;
05707       } else {
05708          ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
05709          continue;
05710       }
05711       for (x = start; x <= finish; x++) {
05712          if ((x > 63) || (x < 0)) {
05713             ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
05714          } else
05715             group |= ((ast_group_t) 1 << x);
05716       }
05717    }
05718    return group;
05719 }

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

References ast_assert, ast_audiohook_detach_list(), ast_autoservice_stop(), ast_cause2str(), ast_cdr_detach(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_DIALED, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_IN_CHANNEL_LIST, AST_FLAG_ZOMBIE, ast_log(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_cdr::disposition, EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_ERROR, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_generator::release, S_OR, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, ast_channel::uniqueid, and ast_channel::vstream.

Referenced by __ast_pbx_run(), __ast_request_and_dial(), __oh323_new(), action_bridge(), agent_hangup(), agent_read(), alsa_new(), answer_exec_run(), app_exec(), ast_async_goto(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial_channel(), bridge_call_thread(), bridge_channel_thread(), bridge_exec(), build_conf(), builtin_atxfer(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), connect_link(), console_new(), dahdi_handle_event(), dahdi_new(), destroy_conference_bridge(), dial_exec_full(), dial_transfer(), do_forward(), do_hang(), do_idle_thread(), feature_attended_transfer(), feature_request_and_dial(), findmeexec(), gtalk_new(), handle_call_forward(), handle_callforward_button(), handle_enbloc_call_message(), handle_frame(), handle_frame_ownerless(), handle_hd_hf(), handle_init_event(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_soft_key_event_message(), handle_stimulus_message(), handle_timeout_trip(), handle_transfer_button(), HandleCallOutgoing(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), jingle_new(), local_hangup(), manage_parkinglot(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), nbs_new(), oss_new(), park_exec_full(), parkandannounce_exec(), phone_new(), play_sound_file(), pri_dchannel(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), try_calling(), unistim_new(), usbradio_new(), wait_for_answer(), and wait_for_winner().

01751 {
01752    int res = 0;
01753 
01754    /* Don't actually hang up a channel that will masquerade as someone else, or
01755       if someone is going to masquerade as us */
01756    ast_channel_lock(chan);
01757 
01758    if (chan->audiohooks) {
01759       ast_audiohook_detach_list(chan->audiohooks);
01760       chan->audiohooks = NULL;
01761    }
01762 
01763    ast_autoservice_stop(chan);
01764 
01765    if (chan->masq) {
01766       if (ast_do_masquerade(chan))
01767          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
01768    }
01769 
01770    if (chan->masq) {
01771       ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name);
01772       ast_channel_unlock(chan);
01773       return 0;
01774    }
01775    /* If this channel is one which will be masqueraded into something,
01776       mark it as a zombie already, so we know to free it later */
01777    if (chan->masqr) {
01778       ast_set_flag(chan, AST_FLAG_ZOMBIE);
01779       ast_channel_unlock(chan);
01780       return 0;
01781    }
01782    ast_channel_unlock(chan);
01783 
01784    AST_RWLIST_WRLOCK(&channels);
01785    if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) {
01786       ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n");
01787    }
01788    ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST);
01789    AST_RWLIST_UNLOCK(&channels);
01790 
01791    ast_channel_lock(chan);
01792    free_translation(chan);
01793    /* Close audio stream */
01794    if (chan->stream) {
01795       ast_closestream(chan->stream);
01796       chan->stream = NULL;
01797    }
01798    /* Close video stream */
01799    if (chan->vstream) {
01800       ast_closestream(chan->vstream);
01801       chan->vstream = NULL;
01802    }
01803    if (chan->sched) {
01804       sched_context_destroy(chan->sched);
01805       chan->sched = NULL;
01806    }
01807    
01808    if (chan->generatordata)   /* Clear any tone stuff remaining */
01809       if (chan->generator && chan->generator->release)
01810          chan->generator->release(chan, chan->generatordata);
01811    chan->generatordata = NULL;
01812    chan->generator = NULL;
01813    if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
01814       ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
01815                "is blocked by thread %ld in procedure %s!  Expect a failure\n",
01816                (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
01817       ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0);
01818    }
01819    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
01820       ast_debug(1, "Hanging up channel '%s'\n", chan->name);
01821       if (chan->tech->hangup)
01822          res = chan->tech->hangup(chan);
01823    } else {
01824       ast_debug(1, "Hanging up zombie '%s'\n", chan->name);
01825    }
01826          
01827    ast_channel_unlock(chan);
01828    manager_event(EVENT_FLAG_CALL, "Hangup",
01829          "Channel: %s\r\n"
01830          "Uniqueid: %s\r\n"
01831          "CallerIDNum: %s\r\n"
01832          "CallerIDName: %s\r\n"
01833          "Cause: %d\r\n"
01834          "Cause-txt: %s\r\n",
01835          chan->name,
01836          chan->uniqueid,
01837          S_OR(chan->cid.cid_num, "<unknown>"),
01838          S_OR(chan->cid.cid_name, "<unknown>"),
01839          chan->hangupcause,
01840          ast_cause2str(chan->hangupcause)
01841          );
01842 
01843    if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 
01844       !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 
01845        (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) {
01846       ast_channel_lock(chan);
01847          
01848       ast_cdr_end(chan->cdr);
01849       ast_cdr_detach(chan->cdr);
01850       chan->cdr = NULL;
01851       ast_channel_unlock(chan);
01852    }
01853    
01854    ast_channel_free(chan);
01855 
01856    return res;
01857 }

int ast_indicate ( struct ast_channel *  chan,
int  condition 
)

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

Indicates condition of channel, with payload.

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

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

Definition at line 3225 of file channel.c.

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

Referenced by agent_hangup(), ast_bridge_call(), ast_generic_bridge(), ast_indicate(), bridge_native_loop(), bridge_p2p_loop(), login_exec(), manage_parkinglot(), park_call_full(), pbx_builtin_waitexten(), transmit_audio(), transmit_t38(), and wait_for_answer().

03227 {
03228    /* By using an enum, we'll get compiler warnings for values not handled 
03229     * in switch statements. */
03230    enum ast_control_frame_type condition = _condition;
03231    struct ast_tone_zone_sound *ts = NULL;
03232    int res = -1;
03233 
03234    ast_channel_lock(chan);
03235 
03236    /* Don't bother if the channel is about to go away, anyway. */
03237    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
03238       ast_channel_unlock(chan);
03239       return -1;
03240    }
03241 
03242    if (chan->tech->indicate) {
03243       /* See if the channel driver can handle this condition. */
03244       res = chan->tech->indicate(chan, condition, data, datalen);
03245    }
03246 
03247    ast_channel_unlock(chan);
03248 
03249    if (!res) {
03250       /* The channel driver successfully handled this indication */
03251       if (is_visible_indication(condition)) {
03252          chan->visible_indication = condition;
03253       }
03254       return 0;
03255    }
03256 
03257    /* The channel driver does not support this indication, let's fake
03258     * it by doing our own tone generation if applicable. */
03259 
03260    /*!\note If we compare the enumeration type, which does not have any
03261     * negative constants, the compiler may optimize this code away.
03262     * Therefore, we must perform an integer comparison here. */
03263    if (_condition < 0) {
03264       /* Stop any tones that are playing */
03265       ast_playtones_stop(chan);
03266       return 0;
03267    }
03268 
03269    /* Handle conditions that we have tones for. */
03270    switch (condition) {
03271    case _XXX_AST_CONTROL_T38:
03272       /* deprecated T.38 control frame */
03273       return -1;
03274    case AST_CONTROL_T38_PARAMETERS:
03275       /* there is no way to provide 'default' behavior for these
03276        * control frames, so we need to return failure, but there
03277        * is also no value in the log message below being emitted
03278        * since failure to handle these frames is not an 'error'
03279        * so just return right now. in addition, we want to return
03280        * whatever value the channel driver returned, in case it
03281        * has some meaning.*/
03282       return res;
03283    case AST_CONTROL_RINGING:
03284       ts = ast_get_indication_tone(chan->zone, "ring");
03285       /* It is common practice for channel drivers to return -1 if trying
03286        * to indicate ringing on a channel which is up. The idea is to let the
03287        * core generate the ringing inband. However, we don't want the
03288        * warning message about not being able to handle the specific indication
03289        * to print nor do we want ast_indicate_data to return an "error" for this
03290        * condition
03291        */
03292       if (chan->_state == AST_STATE_UP) {
03293          res = 0;
03294       }
03295       break;
03296    case AST_CONTROL_BUSY:
03297       ts = ast_get_indication_tone(chan->zone, "busy");
03298       break;
03299    case AST_CONTROL_CONGESTION:
03300       ts = ast_get_indication_tone(chan->zone, "congestion");
03301       break;
03302    case AST_CONTROL_PROGRESS:
03303    case AST_CONTROL_PROCEEDING:
03304    case AST_CONTROL_VIDUPDATE:
03305    case AST_CONTROL_SRCUPDATE:
03306    case AST_CONTROL_SRCCHANGE:
03307    case AST_CONTROL_RADIO_KEY:
03308    case AST_CONTROL_RADIO_UNKEY:
03309    case AST_CONTROL_OPTION:
03310    case AST_CONTROL_WINK:
03311    case AST_CONTROL_FLASH:
03312    case AST_CONTROL_OFFHOOK:
03313    case AST_CONTROL_TAKEOFFHOOK:
03314    case AST_CONTROL_ANSWER:
03315    case AST_CONTROL_HANGUP:
03316    case AST_CONTROL_RING:
03317    case AST_CONTROL_HOLD:
03318    case AST_CONTROL_UNHOLD:
03319       /* Nothing left to do for these. */
03320       res = 0;
03321       break;
03322    }
03323 
03324    if (ts) {
03325       /* We have a tone to play, yay. */
03326       ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
03327       ast_playtones_start(chan, 0, ts->data, 1);
03328       ts = ast_tone_zone_sound_unref(ts);
03329       res = 0;
03330       chan->visible_indication = condition;
03331    }
03332 
03333    if (res) {
03334       /* not handled */
03335       ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name);
03336    }
03337 
03338    return res;
03339 }

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

References ast_opt_internal_timing, and ast_channel::timingfd.

Referenced by add_sdp(), and ast_read_generator_actions().

03170 {
03171    return (ast_opt_internal_timing && chan->timingfd > -1);
03172 }

int ast_is_deferrable_frame ( const struct ast_frame *  frame  ) 

Should we keep this frame for later?

There are functions such as ast_safe_sleep which will service a channel to ensure that it does not have a large backlog of queued frames. When this happens, we want to hold on to specific frame types and just drop others. This function will tell if the frame we just read should be held onto.

Parameters:
frame The frame we just read
Return values:
1 frame should be kept
0 frame should be dropped

Definition at line 1333 of file channel.c.

References AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, and ast_frame::frametype.

Referenced by ast_safe_sleep_conditional(), and autoservice_run().

01334 {
01335    /* Do not add a default entry in this switch statement.  Each new
01336     * frame type should be addressed directly as to whether it should
01337     * be queued up or not.
01338     */
01339    switch (frame->frametype) {
01340    case AST_FRAME_DTMF_END:
01341    case AST_FRAME_CONTROL:
01342    case AST_FRAME_TEXT:
01343    case AST_FRAME_IMAGE:
01344    case AST_FRAME_HTML:
01345       return 1;
01346 
01347    case AST_FRAME_DTMF_BEGIN:
01348    case AST_FRAME_VOICE:
01349    case AST_FRAME_VIDEO:
01350    case AST_FRAME_NULL:
01351    case AST_FRAME_IAX:
01352    case AST_FRAME_CNG:
01353    case AST_FRAME_MODEM:
01354       return 0;
01355    }
01356    return 0;
01357 }

void ast_poll_channel_add ( struct ast_channel *  chan0,
struct ast_channel *  chan1 
)

Add a channel to an optimized waitfor

Definition at line 1670 of file channel.c.

References AST_MAX_FDS, and ast_channel::fds.

Referenced by ast_generic_bridge(), begin_dial_channel(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), and wait_for_answer().

01671 {
01672 #ifdef HAVE_EPOLL
01673    struct epoll_event ev;
01674    int i = 0;
01675 
01676    if (chan0->epfd == -1)
01677       return;
01678 
01679    /* Iterate through the file descriptors on chan1, adding them to chan0 */
01680    for (i = 0; i < AST_MAX_FDS; i++) {
01681       if (chan1->fds[i] == -1)
01682          continue;
01683       ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
01684       ev.data.ptr = chan1->epfd_data[i];
01685       epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev);
01686    }
01687 
01688 #endif
01689    return;
01690 }

void ast_poll_channel_del ( struct ast_channel *  chan0,
struct ast_channel *  chan1 
)

Delete a channel from an optimized waitfor

Definition at line 1693 of file channel.c.

References AST_MAX_FDS, and ast_channel::fds.

Referenced by ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), monitor_dial(), and wait_for_answer().

01694 {
01695 #ifdef HAVE_EPOLL
01696    struct epoll_event ev;
01697    int i = 0;
01698 
01699    if (chan0->epfd == -1)
01700       return;
01701 
01702    for (i = 0; i < AST_MAX_FDS; i++) {
01703       if (chan1->fds[i] == -1)
01704          continue;
01705       epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev);
01706    }
01707 
01708 #endif
01709    return;
01710 }

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

print call- and pickup groups into buffer

Definition at line 5789 of file channel.c.

References first, and num.

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

05790 {
05791    unsigned int i;
05792    int first = 1;
05793    char num[3];
05794 
05795    buf[0] = '\0';
05796    
05797    if (!group) /* Return empty string if no group */
05798       return buf;
05799 
05800    for (i = 0; i <= 63; i++) {   /* Max group is 63 */
05801       if (group & ((ast_group_t) 1 << i)) {
05802             if (!first) {
05803             strncat(buf, ", ", buflen - strlen(buf) - 1);
05804          } else {
05805             first = 0;
05806          }
05807          snprintf(num, sizeof(num), "%u", i);
05808          strncat(buf, num, buflen - strlen(buf) - 1);
05809       }
05810    }
05811    return buf;
05812 }

int ast_prod ( struct ast_channel *  chan  ) 

Send empty audio to prime a channel driver.

Definition at line 3460 of file channel.c.

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

Referenced by ast_activate_generator().

03461 {
03462    struct ast_frame a = { AST_FRAME_VOICE };
03463    char nothing[128];
03464 
03465    /* Send an empty audio frame to get things moving */
03466    if (chan->_state != AST_STATE_UP) {
03467       ast_debug(1, "Prodding channel '%s'\n", chan->name);
03468       a.subclass = chan->rawwriteformat;
03469       a.data.ptr = nothing + AST_FRIENDLY_OFFSET;
03470       a.src = "ast_prod"; /* this better match check in ast_write */
03471       if (ast_write(chan, &a))
03472          ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name);
03473    }
03474    return 0;
03475 }

int ast_queue_control ( struct ast_channel *  chan,
enum ast_control_frame_type  control 
)

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

Queue a control frame with payload.

Parameters:
chan channel to queue frame onto
control type of control frame
data pointer to payload data to be included in frame
datalen number of bytes of payload data
Return values:
0 success
non-zero failure
The supplied payload data is copied into the frame, so the caller's copy is not modified nor freed, and the resulting frame will retain a copy of the data even if the caller frees their local copy.

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

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

Definition at line 1139 of file channel.c.

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

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

01141 {
01142    struct ast_frame f = { AST_FRAME_CONTROL, };
01143 
01144    f.subclass = control;
01145    f.data.ptr = (void *) data;
01146    f.datalen = datalen;
01147 
01148    return ast_queue_frame(chan, &f);
01149 }

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

References __ast_queue_frame().

Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), action_atxfer(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup_tv(), ast_do_masquerade(), ast_dsp_process(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), bridge_write(), cb_events(), cli_console_answer(), cli_console_dial(), cli_console_flash(), cli_console_sendtext(), console_answer(), console_call(), console_dial(), console_do_answer(), console_flash(), console_sendtext(), dahdi_queue_frame(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), jingle_handle_dtmf(), keypad_digit(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), stream_monitor(), unistim_do_senddigit(), unistim_senddigit_end(), usbradio_read(), and wakeup_sub().

01087 {
01088    return __ast_queue_frame(chan, fin, 0, NULL);
01089 }

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

References __ast_queue_frame().

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

01092 {
01093    return __ast_queue_frame(chan, fin, 1, NULL);
01094 }

int ast_queue_hangup ( struct ast_channel *  chan  ) 

Queue a hangup frame.

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

Definition at line 1097 of file channel.c.

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

Referenced by bridge_queue_hangup(), cleanup_connection(), cli_console_hangup(), close_call(), gtalk_hangup_farend(), gtalk_is_answered(), handle_onhook_message(), handle_request_bye(), handle_request_cancel(), handle_soft_key_event_message(), iax2_destroy(), iax2_queue_hangup(), jingle_hangup_farend(), local_hangup(), and mgcp_queue_hangup().

01098 {
01099    struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
01100    /* Yeah, let's not change a lock-critical value without locking */
01101    if (!ast_channel_trylock(chan)) {
01102       chan->_softhangup |= AST_SOFTHANGUP_DEV;
01103       ast_channel_unlock(chan);
01104    }
01105    return ast_queue_frame(chan, &f);
01106 }

int ast_queue_hangup_with_cause ( struct ast_channel *  chan,
int  cause 
)

Queue a hangup frame with hangupcause set.

Note:
The channel does not need to be locked before calling this function.
Parameters:
[in] chan channel to queue frame onto
[in] cause the hangup cause
Returns:
0 on success, -1 on error
Since:
1.6.1

Definition at line 1109 of file channel.c.

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

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

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

int ast_raw_answer ( struct ast_channel *  chan,
int  cdr_answer 
)

Answer a channel.

Parameters:
chan channel to answer
cdr_answer flag to control whether any associated CDR should be marked as 'answered'
This function answers a channel and handles all necessary call setup functions.

Note:
The channel passed does not need to be locked, but is locked by the function when needed.

Unlike ast_answer(), this function will not wait for media flow to begin. The caller should be careful before sending media to the channel before incoming media arrives, as the outgoing media may be lost.

Return values:
0 on success
non-zero on failure

Definition at line 1859 of file channel.c.

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

Referenced by __ast_answer(), and ast_bridge_call().

01860 {
01861    int res = 0;
01862 
01863    ast_channel_lock(chan);
01864 
01865    /* You can't answer an outbound call */
01866    if (ast_test_flag(chan, AST_FLAG_OUTGOING)) {
01867       ast_channel_unlock(chan);
01868       return 0;
01869    }
01870 
01871    /* Stop if we're a zombie or need a soft hangup */
01872    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
01873       ast_channel_unlock(chan);
01874       return -1;
01875    }
01876 
01877    ast_channel_unlock(chan);
01878 
01879    switch (chan->_state) {
01880    case AST_STATE_RINGING:
01881    case AST_STATE_RING:
01882       ast_channel_lock(chan);
01883       if (chan->tech->answer) {
01884          res = chan->tech->answer(chan);
01885       }
01886       ast_setstate(chan, AST_STATE_UP);
01887       if (cdr_answer) {
01888          ast_cdr_answer(chan->cdr);
01889       }
01890       ast_channel_unlock(chan);
01891       break;
01892    case AST_STATE_UP:
01893       /* Calling ast_cdr_answer when it it has previously been called
01894        * is essentially a no-op, so it is safe.
01895        */
01896       if (cdr_answer) {
01897          ast_cdr_answer(chan->cdr);
01898       }
01899       break;
01900    default:
01901       break;
01902    }
01903 
01904    ast_indicate(chan, -1);
01905    chan->visible_indication = 0;
01906 
01907    return res;
01908 }

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

Reads a frame.

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

Definition at line 3174 of file channel.c.

References __ast_read().

Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), ast_bridge_handle_trip(), ast_generic_bridge(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_udptl_bridge(), ast_waitfordigit_full(), async_wait(), autoservice_run(), background_detect_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_goto_on_transfer(), conf_exec(), conf_flush(), conf_run(), dahdi_accept_r2_call_exec(), dahdi_bridge(), dial_exec_full(), dictate_exec(), disa_exec(), do_idle_thread(), do_waiting(), echo_exec(), eivr_comm(), feature_request_and_dial(), find_cache(), handle_recordfile(), handle_speechrecognize(), iax2_bridge(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), manage_parkinglot(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), recordthread(), rpt(), rpt_exec(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().

03175 {
03176    return __ast_read(chan, 0);
03177 }

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

Reads a frame, returning AST_FRAME_NULL frame if audio.

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

Definition at line 3179 of file channel.c.

References __ast_read().

Referenced by ast_bridge_handle_trip(), and conf_run().

03180 {
03181    return __ast_read(chan, 1);
03182 }

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

04285 {
04286    return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
04287 }

int ast_readstring_full ( struct ast_channel *  c,
char *  s,
int  len,
int  timeout,
int  rtimeout,
char *  enders,
int  audiofd,
int  ctrlfd 
)

Definition at line 4289 of file channel.c.

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

Referenced by ast_app_getdata_full(), and ast_readstring().

04290 {
04291    int pos = 0;   /* index in the buffer where we accumulate digits */
04292    int to = ftimeout;
04293 
04294    /* Stop if we're a zombie or need a soft hangup */
04295    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
04296       return -1;
04297    if (!len)
04298       return -1;
04299    for (;;) {
04300       int d;
04301       if (c->stream) {
04302          d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
04303          ast_stopstream(c);
04304          usleep(1000);
04305          if (!d)
04306             d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
04307       } else {
04308          d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
04309       }
04310       if (d < 0)
04311          return AST_GETDATA_FAILED;
04312       if (d == 0) {
04313          s[pos] = '\0';
04314          return AST_GETDATA_TIMEOUT;
04315       }
04316       if (d == 1) {
04317          s[pos] = '\0';
04318          return AST_GETDATA_INTERRUPTED;
04319       }
04320       if (strchr(enders, d) && (pos == 0)) {
04321          s[pos] = '\0';
04322          return AST_GETDATA_EMPTY_END_TERMINATED;
04323       }
04324       if (!strchr(enders, d)) {
04325          s[pos++] = d;
04326       }
04327       if (strchr(enders, d) || (pos >= len)) {
04328          s[pos] = '\0';
04329          return AST_GETDATA_COMPLETE;
04330       }
04331       to = timeout;
04332    }
04333    /* Never reached */
04334    return 0;
04335 }

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

References ast_free, and ast_recvtext().

Referenced by handle_recvchar().

03342 {
03343    int c;
03344    char *buf = ast_recvtext(chan, timeout);
03345    if (buf == NULL)
03346       return -1;  /* error or timeout */
03347    c = *(unsigned char *)buf;
03348    ast_free(buf);
03349    return c;
03350 }

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

References ast_check_hangup(), AST_CONTROL_HANGUP, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_frfree, ast_read(), ast_strndup, ast_waitfor(), ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, ast_frame::ptr, and ast_frame::subclass.

Referenced by ast_recvchar(), and handle_recvtext().

03353 {
03354    int res, done = 0;
03355    char *buf = NULL;
03356    
03357    while (!done) {
03358       struct ast_frame *f;
03359       if (ast_check_hangup(chan))
03360          break;
03361       res = ast_waitfor(chan, timeout);
03362       if (res <= 0) /* timeout or error */
03363          break;
03364       timeout = res; /* update timeout */
03365       f = ast_read(chan);
03366       if (f == NULL)
03367          break; /* no frame */
03368       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
03369          done = 1;   /* force a break */
03370       else if (f->frametype == AST_FRAME_TEXT) {      /* what we want */
03371          buf = ast_strndup((char *) f->data.ptr, f->datalen);  /* dup and break */
03372          done = 1;
03373       }
03374       ast_frfree(f);
03375    }
03376    return buf;
03377 }

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

Requests a channel.

Parameters:
type type of channel to request
format requested channel format (codec)
data data to pass to the channel requester
status status
Request a channel of a given type, with data as optional information used by the low level module

Return values:
NULL failure
non-NULL channel on success

Definition at line 4183 of file channel.c.

References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_translator_best_choice(), ast_channel_tech::capabilities, capabilities, LOG_WARNING, ast_channel_tech::requester, chanlist::tech, and ast_channel_tech::type.

Referenced by __ast_request_and_dial(), agent_request(), ast_call_forward(), attempt_reconnect(), begin_dial_channel(), build_conf(), chanavail_exec(), conf_run(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), and wait_for_answer().

04184 {
04185    struct chanlist *chan;
04186    struct ast_channel *c;
04187    int capabilities;
04188    int fmt;
04189    int res;
04190    int foo;
04191    int videoformat = format & AST_FORMAT_VIDEO_MASK;
04192    int textformat = format & AST_FORMAT_TEXT_MASK;
04193 
04194    if (!cause)
04195       cause = &foo;
04196    *cause = AST_CAUSE_NOTDEFINED;
04197 
04198    if (AST_RWLIST_RDLOCK(&channels)) {
04199       ast_log(LOG_WARNING, "Unable to lock channel list\n");
04200       return NULL;
04201    }
04202 
04203    AST_LIST_TRAVERSE(&backends, chan, list) {
04204       if (strcasecmp(type, chan->tech->type))
04205          continue;
04206 
04207       capabilities = chan->tech->capabilities;
04208       fmt = format & AST_FORMAT_AUDIO_MASK;
04209       if (fmt) {
04210          /* We have audio - is it possible to connect the various calls to each other? 
04211             (Avoid this check for calls without audio, like text+video calls)
04212          */
04213          res = ast_translator_best_choice(&fmt, &capabilities);
04214          if (res < 0) {
04215             ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format);
04216             *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
04217             AST_RWLIST_UNLOCK(&channels);
04218             return NULL;
04219          }
04220       }
04221       AST_RWLIST_UNLOCK(&channels);
04222       if (!chan->tech->requester)
04223          return NULL;
04224       
04225       if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, data, cause)))
04226          return NULL;
04227       
04228       /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
04229       return c;
04230    }
04231 
04232    ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
04233    *cause = AST_CAUSE_NOSUCHDRIVER;
04234    AST_RWLIST_UNLOCK(&channels);
04235 
04236    return NULL;
04237 }

struct ast_channel* ast_request_and_dial ( const char *  type,
int  format,
void *  data,
int  timeout,
int *  reason,
const char *  cid_num,
const char *  cid_name 
) [read]

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

Parameters:
type type of channel to request
format requested channel format
data data to pass to the channel requester
timeout maximum amount of time to wait for an answer
reason why unsuccessful (if unsuccessful)
cid_num Caller-ID Number
cid_name Caller-ID Name (ascii)
Returns:
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 4178 of file channel.c.

References __ast_request_and_dial().

Referenced by ast_pbx_outgoing_exten().

04179 {
04180    return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL);
04181 }

int ast_safe_sleep ( struct ast_channel *  chan,
int  ms 
)

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

Wait for a specified 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 1360 of file channel.c.

References ast_channel_lock, ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_unlock, ast_frfree, ast_frisolate(), ast_is_deferrable_frame(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_opt_transmit_silence, ast_queue_frame_head(), ast_read(), ast_waitfor(), cond, f, and ast_channel::generatordata.

Referenced by ast_safe_sleep(), and login_exec().

01361 {
01362    struct ast_frame *f;
01363    struct ast_silence_generator *silgen = NULL;
01364    int res = 0;
01365    AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
01366 
01367    AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
01368 
01369    /* If no other generator is present, start silencegen while waiting */
01370    if (ast_opt_transmit_silence && !chan->generatordata) {
01371       silgen = ast_channel_start_silence_generator(chan);
01372    }
01373 
01374    while (ms > 0) {
01375       struct ast_frame *dup_f = NULL;
01376       if (cond && ((*cond)(data) == 0)) {
01377          break;
01378       }
01379       ms = ast_waitfor(chan, ms);
01380       if (ms < 0) {
01381          res = -1;
01382          break;
01383       }
01384       if (ms > 0) {
01385          f = ast_read(chan);
01386          if (!f) {
01387             res = -1;
01388             break;
01389          }
01390 
01391          if (!ast_is_deferrable_frame(f)) {
01392             ast_frfree(f);
01393             continue;
01394          }
01395          
01396          if ((dup_f = ast_frisolate(f))) {
01397             if (dup_f != f) {
01398                ast_frfree(f);
01399             }
01400             AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list);
01401          }
01402       }
01403    }
01404 
01405    /* stop silgen if present */
01406    if (silgen) {
01407       ast_channel_stop_silence_generator(chan, silgen);
01408    }
01409 
01410    /* We need to free all the deferred frames, but we only need to
01411     * queue the deferred frames if there was no error and no
01412     * hangup was received
01413     */
01414    ast_channel_lock(chan);
01415    while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
01416       if (!res) {
01417          ast_queue_frame_head(chan, f);
01418       }
01419       ast_frfree(f);
01420    }
01421    ast_channel_unlock(chan);
01422 
01423    return res;
01424 }

static int ast_select ( int  nfds,
fd_set *  rfds,
fd_set *  wfds,
fd_set *  efds,
struct timeval *  tvp 
) [inline, static]

Waits for activity on a group of channels.

Parameters:
nfds the maximum number of file descriptors in the sets
rfds file descriptors to check for read availability
wfds file descriptors to check for write availability
efds file descriptors to check for exceptions (OOB data)
tvp timeout while waiting for events This is the same as a standard select(), except it guarantees the behaviour where the passed struct timeval is updated with how much time was not slept while waiting for the specified events

Definition at line 1755 of file channel.h.

Referenced by aji_io_recv(), ast_stun_request(), dispatch_thread_handler(), do_monitor(), do_parking_thread(), and hidthread().

01756 {
01757 #ifdef __linux__
01758    return select(nfds, rfds, wfds, efds, tvp);
01759 #else
01760    if (tvp) {
01761       struct timeval tv, tvstart, tvend, tvlen;
01762       int res;
01763 
01764       tv = *tvp;
01765       gettimeofday(&tvstart, NULL);
01766       res = select(nfds, rfds, wfds, efds, tvp);
01767       gettimeofday(&tvend, NULL);
01768       timersub(&tvend, &tvstart, &tvlen);
01769       timersub(&tv, &tvlen, tvp);
01770       if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
01771          tvp->tv_sec = 0;
01772          tvp->tv_usec = 0;
01773       }
01774       return res;
01775    }
01776    else
01777       return select(nfds, rfds, wfds, efds, NULL);
01778 #endif
01779 }

int ast_senddigit ( struct ast_channel *  chan,
char  digit,
unsigned int  duration 
)

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

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

Definition at line 3450 of file channel.c.

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

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

03451 {
03452    if (chan->tech->send_digit_begin) {
03453       ast_senddigit_begin(chan, digit);
03454       ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
03455    }
03456    
03457    return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION));
03458 }

int ast_senddigit_begin ( struct ast_channel *  chan,
char  digit 
)

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

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

Definition at line 3392 of file channel.c.

References ast_debug, ast_playtones_start(), ast_channel::name, ast_channel_tech::send_digit_begin, and ast_channel::tech.

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

03393 {
03394    /* Device does not support DTMF tones, lets fake
03395     * it by doing our own generation. */
03396    static const char* dtmf_tones[] = {
03397       "941+1336", /* 0 */
03398       "697+1209", /* 1 */
03399       "697+1336", /* 2 */
03400       "697+1477", /* 3 */
03401       "770+1209", /* 4 */
03402       "770+1336", /* 5 */
03403       "770+1477", /* 6 */
03404       "852+1209", /* 7 */
03405       "852+1336", /* 8 */
03406       "852+1477", /* 9 */
03407       "697+1633", /* A */
03408       "770+1633", /* B */
03409       "852+1633", /* C */
03410       "941+1633", /* D */
03411       "941+1209", /* * */
03412       "941+1477"  /* # */
03413    };
03414 
03415    if (!chan->tech->send_digit_begin)
03416       return 0;
03417 
03418    if (!chan->tech->send_digit_begin(chan, digit))
03419       return 0;
03420 
03421    if (digit >= '0' && digit <='9')
03422       ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
03423    else if (digit >= 'A' && digit <= 'D')
03424       ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
03425    else if (digit == '*')
03426       ast_playtones_start(chan, 0, dtmf_tones[14], 0);
03427    else if (digit == '#')
03428       ast_playtones_start(chan, 0, dtmf_tones[15], 0);
03429    else {
03430       /* not handled */
03431       ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name);
03432    }
03433 
03434    return 0;
03435 }

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

Send a DTMF digit to a channel.

Send a DTMF digit to a channel.

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

Definition at line 3437 of file channel.c.

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

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

03438 {
03439    int res = -1;
03440 
03441    if (chan->tech->send_digit_end)
03442       res = chan->tech->send_digit_end(chan, digit, duration);
03443 
03444    if (res && chan->generator)
03445       ast_playtones_stop(chan);
03446    
03447    return 0;
03448 }

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

Sends text to a channel.

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

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

Definition at line 3379 of file channel.c.

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

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

03380 {
03381    int res = 0;
03382    /* Stop if we're a zombie or need a soft hangup */
03383    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
03384       return -1;
03385    CHECK_BLOCKING(chan);
03386    if (chan->tech->send_text)
03387       res = chan->tech->send_text(chan, text);
03388    ast_clear_flag(chan, AST_FLAG_BLOCKING);
03389    return res;
03390 }

void ast_set_callerid ( struct ast_channel *  chan,
const char *  cid_num,
const char *  cid_name,
const char *  cid_ani 
)

Set caller ID number, name and ANI.

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

Definition at line 4870 of file channel.c.

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

Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), callerid_write(), dahdi_read(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), findmeexec(), handle_setcallerid(), mgcp_ss(), privacy_exec(), read_config(), rpt_exec(), skinny_newcall(), and ss_thread().

04871 {
04872    ast_channel_lock(chan);
04873 
04874    if (cid_num) {
04875       if (chan->cid.cid_num)
04876          ast_free(chan->cid.cid_num);
04877       chan->cid.cid_num = ast_strdup(cid_num);
04878    }
04879    if (cid_name) {
04880       if (chan->cid.cid_name)
04881          ast_free(chan->cid.cid_name);
04882       chan->cid.cid_name = ast_strdup(cid_name);
04883    }
04884    if (cid_ani) {
04885       if (chan->cid.cid_ani)
04886          ast_free(chan->cid.cid_ani);
04887       chan->cid.cid_ani = ast_strdup(cid_ani);
04888    }
04889 
04890    report_new_callerid(chan);
04891 
04892    ast_channel_unlock(chan);
04893 }

int ast_set_read_format ( struct ast_channel *  chan,
int  format 
)

void ast_set_variables ( struct ast_channel *  chan,
struct ast_variable *  vars 
)

adds a list of channel variables to a channel

Parameters:
chan the channel
vars a linked list of variables
Variable names can be for a regular channel variable or a dialplan function that has the ability to be written to.

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

05815 {
05816    struct ast_variable *cur;
05817 
05818    for (cur = vars; cur; cur = cur->next)
05819       pbx_builtin_setvar_helper(chan, cur->name, cur->value);  
05820 }

int ast_set_write_format ( struct ast_channel *  chan,
int  format 
)

int ast_setstate ( struct ast_channel *  chan,
enum  ast_channel_state 
)

Change the state of a channel.

Definition at line 4895 of file channel.c.

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

Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), agent_call(), alsa_answer(), ast_raw_answer(), cb_events(), check_availability(), console_answer(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), do_bridge_masquerade(), gtalk_call(), gtalk_newcall(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_response_invite(), handle_soft_key_event_message(), handle_stimulus_message(), iax2_call(), jingle_call(), jingle_newcall(), local_queue_frame(), mgcp_answer(), mgcp_call(), mgcp_ss(), misdn_call(), misdn_indication(), nbs_call(), nbs_hangup(), oh323_answer(), oss_answer(), pbx_builtin_busy(), pbx_builtin_congestion(), phone_answer(), phone_call(), phone_exception(), phone_hangup(), phone_write(), release_chan(), release_chan_early(), sip_answer(), skinny_answer(), skinny_call(), skinny_newcall(), ss_thread(), unistim_answer(), unistim_call(), unistim_new(), unistim_ss(), update_state(), usbradio_answer(), and usbradio_call().

04896 {
04897    int oldstate = chan->_state;
04898    char name[AST_CHANNEL_NAME], *dashptr;
04899 
04900    if (oldstate == state)
04901       return 0;
04902 
04903    ast_copy_string(name, chan->name, sizeof(name));
04904    if ((dashptr = strrchr(name, '-'))) {
04905       *dashptr = '\0';
04906    }
04907 
04908    chan->_state = state;
04909 
04910    /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver
04911     * for this channel is using the callback method for device state. If we pass in an actual state here
04912     * we override what they are saying the state is and things go amuck. */
04913    ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name);
04914 
04915    /* setstate used to conditionally report Newchannel; this is no more */
04916    manager_event(EVENT_FLAG_CALL,
04917             "Newstate",
04918             "Channel: %s\r\n"
04919             "ChannelState: %d\r\n"
04920             "ChannelStateDesc: %s\r\n"
04921             "CallerIDNum: %s\r\n"
04922             "CallerIDName: %s\r\n"
04923             "Uniqueid: %s\r\n",
04924             chan->name, chan->_state, ast_state2str(chan->_state),
04925             S_OR(chan->cid.cid_num, ""),
04926             S_OR(chan->cid.cid_name, ""),
04927             chan->uniqueid);
04928 
04929    return 0;
04930 }

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

Enable or disable timer ticks for a channel.

Parameters:
rate number of timer ticks per second
If timers are supported, force a scheduled expiration on the timer fd, at which point we call the callback function / data

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

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

Definition at line 2467 of file channel.c.

References ast_channel_lock, ast_channel_unlock, ast_debug, ast_timer_get_max_rate(), ast_timer_set_rate(), ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.

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

02468 {
02469    int res;
02470    unsigned int real_rate = rate, max_rate;
02471 
02472    ast_channel_lock(c);
02473 
02474    if (c->timingfd == -1) {
02475       ast_channel_unlock(c);
02476       return -1;
02477    }
02478 
02479    if (!func) {
02480       rate = 0;
02481       data = NULL;
02482    }
02483 
02484    if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) {
02485       real_rate = max_rate;
02486    }
02487 
02488    ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate);
02489 
02490    res = ast_timer_set_rate(c->timer, real_rate);
02491 
02492    c->timingfunc = func;
02493    c->timingdata = data;
02494 
02495    ast_channel_unlock(c);
02496 
02497    return res;
02498 }

int ast_shutting_down ( void   ) 

Returns non-zero if Asterisk is being shut down.

Returns non-zero if Asterisk is being shut down

Definition at line 515 of file channel.c.

Referenced by handle_request_options().

00516 {
00517    return shutting_down;
00518 }

int ast_softhangup ( struct ast_channel *  chan,
int  cause 
)

Softly hangup up a channel.

Parameters:
chan channel to be soft-hung-up
reason an AST_SOFTHANGUP_* reason code
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.

Note:
The channel passed to this function does not need to be locked.
Returns:
Returns 0 regardless

Definition at line 1726 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().

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

01727 {
01728    int res;
01729 
01730    ast_channel_lock(chan);
01731    res = ast_softhangup_nolock(chan, cause);
01732    ast_channel_unlock(chan);
01733 
01734    return res;
01735 }

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
reason an AST_SOFTHANGUP_* reason code

Definition at line 1713 of file channel.c.

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

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

01714 {
01715    ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name);
01716    /* Inform channel driver that we need to be hung up, if it cares */
01717    chan->_softhangup |= cause;
01718    ast_queue_frame(chan, &ast_null_frame);
01719    /* Interrupt any poll call or such */
01720    if (ast_test_flag(chan, AST_FLAG_BLOCKING))
01721       pthread_kill(chan->blocker, SIGURG);
01722    return 0;
01723 }

const char* ast_state2str ( enum ast_channel_state  state  ) 

Gives the string form of a given 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
Note:
This function is not reentrant.

Definition at line 656 of file channel.c.

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

Referenced by __ast_channel_alloc_ap(), action_coreshowchannels(), action_status(), agent_hangup(), ast_do_masquerade(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_invite_replaces(), handle_showchan(), local_attended_transfer(), mgcp_new(), serialize_showchan(), and sip_hangup().

00657 {
00658    char *buf;
00659 
00660    switch (state) {
00661    case AST_STATE_DOWN:
00662       return "Down";
00663    case AST_STATE_RESERVED:
00664       return "Rsrvd";
00665    case AST_STATE_OFFHOOK:
00666       return "OffHook";
00667    case AST_STATE_DIALING:
00668       return "Dialing";
00669    case AST_STATE_RING:
00670       return "Ring";
00671    case AST_STATE_RINGING:
00672       return "Ringing";
00673    case AST_STATE_UP:
00674       return "Up";
00675    case AST_STATE_BUSY:
00676       return "Busy";
00677    case AST_STATE_DIALING_OFFHOOK:
00678       return "Dialing Offhook";
00679    case AST_STATE_PRERING:
00680       return "Pre-ring";
00681    default:
00682       if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
00683          return "Unknown";
00684       snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state);
00685       return buf;
00686    }
00687 }

int ast_str2cause ( const char *  name  ) 

Convert a symbolic hangup cause to number.

Convert the string form of a cause code to a number

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

Definition at line 642 of file channel.c.

References ARRAY_LEN, cause, and causes.

Referenced by pbx_builtin_hangup().

00643 {
00644    int x;
00645 
00646    for (x = 0; x < ARRAY_LEN(causes); x++)
00647       if (!strncasecmp(causes[x].name, name, strlen(causes[x].name)))
00648          return causes[x].cause;
00649 
00650    return -1;
00651 }

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

Play a tone pair for a given amount of time

Definition at line 5671 of file channel.c.

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

Referenced by zapateller_exec().

05672 {
05673    int res;
05674 
05675    if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
05676       return res;
05677 
05678    /* Give us some wiggle room */
05679    while (chan->generatordata && ast_waitfor(chan, 100) >= 0) {
05680       struct ast_frame *f = ast_read(chan);
05681       if (f)
05682          ast_frfree(f);
05683       else
05684          return -1;
05685    }
05686    return 0;
05687 }

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

Start a tone going

Definition at line 5653 of file channel.c.

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

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

05654 {
05655    struct tonepair_def d = { 0, };
05656 
05657    d.freq1 = freq1;
05658    d.freq2 = freq2;
05659    d.duration = duration;
05660    d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
05661    if (ast_activate_generator(chan, &tonepair, &d))
05662       return -1;
05663    return 0;
05664 }

void ast_tonepair_stop ( struct ast_channel *  chan  ) 

Stop a tone from playing

Definition at line 5666 of file channel.c.

References ast_deactivate_generator().

Referenced by sendnoise().

05667 {
05668    ast_deactivate_generator(chan);
05669 }

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.

Parameters:
chan current channel
dest destination extension for transfer
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.

Called by:

  • app_transfer
  • the manager interface

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

04267 {
04268    int res = -1;
04269 
04270    /* Stop if we're a zombie or need a soft hangup */
04271    ast_channel_lock(chan);
04272    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
04273       if (chan->tech->transfer) {
04274          res = chan->tech->transfer(chan, dest);
04275          if (!res)
04276             res = 1;
04277       } else
04278          res = 0;
04279    }
04280    ast_channel_unlock(chan);
04281    return res;
04282 }

char* ast_transfercapability2str ( int  transfercapability  )  const

Gives the string form of a given transfer capability.

Gives the string form of a given transfer capability

Parameters:
transfercapability transfercapabilty to get the name of Give a name to a transfercapbility See above Returns the text form of the binary transfer capability

Definition at line 690 of file channel.c.

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

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

00691 {
00692    switch (transfercapability) {
00693    case AST_TRANS_CAP_SPEECH:
00694       return "SPEECH";
00695    case AST_TRANS_CAP_DIGITAL:
00696       return "DIGITAL";
00697    case AST_TRANS_CAP_RESTRICTED_DIGITAL:
00698       return "RESTRICTED_DIGITAL";
00699    case AST_TRANS_CAP_3_1K_AUDIO:
00700       return "3K1AUDIO";
00701    case AST_TRANS_CAP_DIGITAL_W_TONES:
00702       return "DIGITAL_W_TONES";
00703    case AST_TRANS_CAP_VIDEO:
00704       return "VIDEO";
00705    default:
00706       return "UNKNOWN";
00707    }
00708 }

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

References ast_waitfor_nandfds().

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

02452 {
02453    int oldms = ms;   /* -1 if no timeout */
02454 
02455    ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
02456    if ((ms < 0) && (oldms < 0))
02457       ms = 0;
02458    return ms;
02459 }

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

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

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

Definition at line 2446 of file channel.c.

References ast_waitfor_nandfds().

Referenced by ast_generic_bridge(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), bridge_p2p_loop(), dahdi_bridge(), dial_exec_full(), feature_request_and_dial(), generic_thread_loop(), iax2_bridge(), misdn_bridge(), monitor_dial(), rpt(), rpt_exec(), wait_for_answer(), and wait_for_winner().

02447 {
02448    return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
02449 }

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

References ast_waitfor_nandfds().

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

02087 {
02088    int winner = -1;
02089    ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
02090    return winner;
02091 }

struct ast_channel* ast_waitfor_nandfds ( struct ast_channel **  c,
int  n,
int *  fds,
int  nfds,
int *  exception,
int *  outfd,
int *  ms 
) [read]

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

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

Referenced by ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), bridge_channel_join_multithreaded(), conf_run(), eivr_comm(), find_cache(), multiplexed_thread_function(), run_agi(), and waitstream_core().

02101 {
02102    struct timeval start = { 0 , 0 };
02103    struct pollfd *pfds = NULL;
02104    int res;
02105    long rms;
02106    int x, y, max;
02107    int sz;
02108    struct timeval now = { 0, 0 };
02109    struct timeval whentohangup = { 0, 0 }, diff;
02110    struct ast_channel *winner = NULL;
02111    struct fdmap {
02112       int chan;
02113       int fdno;
02114    } *fdmap = NULL;
02115 
02116    if ((sz = n * AST_MAX_FDS + nfds)) {
02117       pfds = alloca(sizeof(*pfds) * sz);
02118       fdmap = alloca(sizeof(*fdmap) * sz);
02119    }
02120 
02121    if (outfd)
02122       *outfd = -99999;
02123    if (exception)
02124       *exception = 0;
02125    
02126    /* Perform any pending masquerades */
02127    for (x = 0; x < n; x++) {
02128       ast_channel_lock(c[x]);
02129       if (c[x]->masq && ast_do_masquerade(c[x])) {
02130          ast_log(LOG_WARNING, "Masquerade failed\n");
02131          *ms = -1;
02132          ast_channel_unlock(c[x]);
02133          return NULL;
02134       }
02135       if (!ast_tvzero(c[x]->whentohangup)) {
02136          if (ast_tvzero(whentohangup))
02137             now = ast_tvnow();
02138          diff = ast_tvsub(c[x]->whentohangup, now);
02139          if (diff.tv_sec < 0 || ast_tvzero(diff)) {
02140             /* Should already be hungup */
02141             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
02142             ast_channel_unlock(c[x]);
02143             return c[x];
02144          }
02145          if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0)
02146             whentohangup = diff;
02147       }
02148       ast_channel_unlock(c[x]);
02149    }
02150    /* Wait full interval */
02151    rms = *ms;
02152    /* INT_MAX, not LONG_MAX, because it matters on 64-bit */
02153    if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) {
02154       rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000;              /* timeout in milliseconds */
02155       if (*ms >= 0 && *ms < rms) {                                                 /* original *ms still smaller */
02156          rms =  *ms;
02157       }
02158    } else if (!ast_tvzero(whentohangup) && rms < 0) {
02159       /* Tiny corner case... call would need to last >24 days */
02160       rms = INT_MAX;
02161    }
02162    /*
02163     * Build the pollfd array, putting the channels' fds first,
02164     * followed by individual fds. Order is important because
02165     * individual fd's must have priority over channel fds.
02166     */
02167    max = 0;
02168    for (x = 0; x < n; x++) {
02169       for (y = 0; y < AST_MAX_FDS; y++) {
02170          fdmap[max].fdno = y;  /* fd y is linked to this pfds */
02171          fdmap[max].chan = x;  /* channel x is linked to this pfds */
02172          max += ast_add_fd(&pfds[max], c[x]->fds[y]);
02173       }
02174       CHECK_BLOCKING(c[x]);
02175    }
02176    /* Add the individual fds */
02177    for (x = 0; x < nfds; x++) {
02178       fdmap[max].chan = -1;
02179       max += ast_add_fd(&pfds[max], fds[x]);
02180    }
02181 
02182    if (*ms > 0)
02183       start = ast_tvnow();
02184    
02185    if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
02186       do {
02187          int kbrms = rms;
02188          if (kbrms > 600000)
02189             kbrms = 600000;
02190          res = ast_poll(pfds, max, kbrms);
02191          if (!res)
02192             rms -= kbrms;
02193       } while (!res && (rms > 0));
02194    } else {
02195       res = ast_poll(pfds, max, rms);
02196    }
02197    for (x = 0; x < n; x++)
02198       ast_clear_flag(c[x], AST_FLAG_BLOCKING);
02199    if (res < 0) { /* Simulate a timeout if we were interrupted */
02200       if (errno != EINTR)
02201          *ms = -1;
02202       return NULL;
02203    }
02204    if (!ast_tvzero(whentohangup)) {   /* if we have a timeout, check who expired */
02205       now = ast_tvnow();
02206       for (x = 0; x < n; x++) {
02207          if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) {
02208             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
02209             if (winner == NULL)
02210                winner = c[x];
02211          }
02212       }
02213    }
02214    if (res == 0) { /* no fd ready, reset timeout and done */
02215       *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
02216       return winner;
02217    }
02218    /*
02219     * Then check if any channel or fd has a pending event.
02220     * Remember to check channels first and fds last, as they
02221     * must have priority on setting 'winner'
02222     */
02223    for (x = 0; x < max; x++) {
02224       res = pfds[x].revents;
02225       if (res == 0)
02226          continue;
02227       if (fdmap[x].chan >= 0) {  /* this is a channel */
02228          winner = c[fdmap[x].chan]; /* override previous winners */
02229          if (res & POLLPRI)
02230             ast_set_flag(winner, AST_FLAG_EXCEPTION);
02231          else
02232             ast_clear_flag(winner, AST_FLAG_EXCEPTION);
02233          winner->fdno = fdmap[x].fdno;
02234       } else {       /* this is an fd */
02235          if (outfd)
02236             *outfd = pfds[x].fd;
02237          if (exception)
02238             *exception = (res & POLLPRI) ? -1 : 0;
02239          winner = NULL;
02240       }
02241    }
02242    if (*ms > 0) {
02243       *ms -= ast_tvdiff_ms(ast_tvnow(), start);
02244       if (*ms < 0)
02245          *ms = 0;
02246    }
02247    return winner;
02248 }

int ast_waitfordigit ( struct ast_channel *  c,
int  ms 
)

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

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

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

Definition at line 2500 of file channel.c.

References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_set_flag, ast_test_flag, ast_waitfor_nandfds(), ast_frame::data, ast_frame::datalen, errno, f, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.

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

02501 {
02502    /* Stop if we're a zombie or need a soft hangup */
02503    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
02504       return -1;
02505 
02506    /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */
02507    ast_set_flag(c, AST_FLAG_END_DTMF_ONLY);
02508 
02509    /* Wait for a digit, no more than ms milliseconds total. */
02510    
02511    while (ms) {
02512       struct ast_channel *rchan;
02513       int outfd=-1;
02514 
02515       errno = 0;
02516       rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
02517       
02518       if (!rchan && outfd < 0 && ms) {
02519          if (errno == 0 || errno == EINTR)
02520             continue;
02521          ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
02522          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02523          return -1;
02524       } else if (outfd > -1) {
02525          /* The FD we were watching has something waiting */
02526          ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n");
02527          ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02528          return 1;
02529       } else if (rchan) {
02530          int res;
02531          struct ast_frame *f = ast_read(c);
02532          if (!f)
02533             return -1;
02534 
02535          switch (f->frametype) {
02536          case AST_FRAME_DTMF_BEGIN:
02537             break;
02538          case AST_FRAME_DTMF_END:
02539             res = f->subclass;
02540             ast_frfree(f);
02541             ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02542             return res;
02543          case AST_FRAME_CONTROL:
02544             switch (f->subclass) {
02545             case AST_CONTROL_HANGUP:
02546                ast_frfree(f);
02547                ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02548                return -1;
02549             case AST_CONTROL_RINGING:
02550             case AST_CONTROL_ANSWER:
02551             case AST_CONTROL_SRCUPDATE:
02552             case AST_CONTROL_SRCCHANGE:
02553                /* Unimportant */
02554                break;
02555             default:
02556                ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass);
02557                break;
02558             }
02559             break;
02560          case AST_FRAME_VOICE:
02561             /* Write audio if appropriate */
02562             if (audiofd > -1) {
02563                if (write(audiofd, f->data.ptr, f->datalen) < 0) {
02564                   ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno));
02565                }
02566             }
02567          default:
02568             /* Ignore */
02569             break;
02570          }
02571          ast_frfree(f);
02572       }
02573    }
02574 
02575    ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
02576 
02577    return 0; /* Time is up */
02578 }

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

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

Definition at line 1309 of file channel.c.

References channel_find_locked().

Referenced by next_channel().

01311 {
01312    return channel_find_locked(chan, NULL, 0, context, exten);
01313 }

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

Get channel by name or uniqueid prefix (locks channel).

Definition at line 1296 of file channel.c.

References channel_find_locked().

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

01298 {
01299    return channel_find_locked(chan, name, namelen, NULL, NULL);
01300 }

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

References ast_channel::_softhangup, apply_plc(), AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_deactivate_generator(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, ast_format_rate(), AST_FORMAT_SLINEAR, AST_FORMAT_T140, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_NEXT, ast_log(), AST_MONITOR_RUNNING, ast_opt_generic_plc, ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), ast_channel::audiohooks, calc_monitor_jump(), CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_filestream::fmt, ast_format::format, ast_channel::fout, FRAMECOUNT_INC, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, ast_frame::len, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, chanlist::next, ast_channel::outsmpl, ast_frame::ptr, ast_channel::rawwriteformat, ast_channel_monitor::read_stream, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), ast_channel_tech::send_html, ast_channel_tech::send_text, ast_frame::src, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel_tech::write, ast_channel_monitor::write_stream, ast_channel_tech::write_text, ast_channel_tech::write_video, and ast_channel::writetrans.

Referenced by adsi_careful_send(), agent_write(), ast_generic_bridge(), ast_prod(), ast_readaudio_callback(), ast_readvideo_callback(), ast_udptl_bridge(), ast_write_video(), bridge_native_loop(), bridge_p2p_loop(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), fax_generator_generate(), feature_request_and_dial(), function_ilink(), gen_generate(), handle_jack_audio(), handle_link_data(), iax2_bridge(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), multiplexed_bridge_write(), NBScat_exec(), playtones_generator(), rpt(), rpt_exec(), send_link_dtmf(), send_link_keyquery(), send_tone_burst(), send_usb_txt(), send_waveform_to_channel(), silence_generator_generate(), simple_bridge_write(), sms_generate(), softmix_bridge_poke(), softmix_bridge_write(), spy_generate(), t38_tx_packet_handler(), tonepair_generator(), and wait_for_answer().

03593 {
03594    int res = -1;
03595    struct ast_frame *f = NULL;
03596    int count = 0;
03597 
03598    /*Deadlock avoidance*/
03599    while(ast_channel_trylock(chan)) {
03600       /*cannot goto done since the channel is not locked*/
03601       if(count++ > 10) {
03602          ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name);
03603          return 0;
03604       }
03605       usleep(1);
03606    }
03607    /* Stop if we're a zombie or need a soft hangup */
03608    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
03609       goto done;
03610 
03611    /* Handle any pending masquerades */
03612    if (chan->masq && ast_do_masquerade(chan)) {
03613       ast_log(LOG_WARNING, "Failed to perform masquerade\n");
03614       goto done;
03615    }
03616    if (chan->masqr) {
03617       res = 0; /* XXX explain, why 0 ? */
03618       goto done;
03619    }
03620    if (chan->generatordata && (!fr->src || strcasecmp(fr->src, "ast_prod"))) {
03621       if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) {
03622             ast_deactivate_generator(chan);
03623       } else {
03624          if (fr->frametype == AST_FRAME_DTMF_END) {
03625             /* There is a generator running while we're in the middle of a digit.
03626              * It's probably inband DTMF, so go ahead and pass it so it can
03627              * stop the generator */
03628             ast_clear_flag(chan, AST_FLAG_BLOCKING);
03629             ast_channel_unlock(chan);
03630             res = ast_senddigit_end(chan, fr->subclass, fr->len);
03631             ast_channel_lock(chan);
03632             CHECK_BLOCKING(chan);
03633          } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) {
03634             /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */
03635             res = (chan->tech->indicate == NULL) ? 0 :
03636                chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen);
03637          }
03638          res = 0; /* XXX explain, why 0 ? */
03639          goto done;
03640       }
03641    }
03642    /* High bit prints debugging */
03643    if (chan->fout & DEBUGCHAN_FLAG)
03644       ast_frame_dump(chan->name, fr, ">>");
03645    CHECK_BLOCKING(chan);
03646    switch (fr->frametype) {
03647    case AST_FRAME_CONTROL:
03648       res = (chan->tech->indicate == NULL) ? 0 :
03649          chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen);
03650       break;
03651    case AST_FRAME_DTMF_BEGIN:
03652       if (chan->audiohooks) {
03653          struct ast_frame *old_frame = fr;
03654          fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
03655          if (old_frame != fr)
03656             f = fr;
03657       }
03658       send_dtmf_event(chan, "Sent", fr->subclass, "Yes", "No");
03659       ast_clear_flag(chan, AST_FLAG_BLOCKING);
03660       ast_channel_unlock(chan);
03661       res = ast_senddigit_begin(chan, fr->subclass);
03662       ast_channel_lock(chan);
03663       CHECK_BLOCKING(chan);
03664       break;
03665    case AST_FRAME_DTMF_END:
03666       if (chan->audiohooks) {
03667          struct ast_frame *new_frame = fr;
03668 
03669          new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
03670          if (new_frame != fr) {
03671             ast_frfree(new_frame);
03672          }
03673       }
03674       send_dtmf_event(chan, "Sent", fr->subclass, "No", "Yes");
03675       ast_clear_flag(chan, AST_FLAG_BLOCKING);
03676       ast_channel_unlock(chan);
03677       res = ast_senddigit_end(chan, fr->subclass, fr->len);
03678       ast_channel_lock(chan);
03679       CHECK_BLOCKING(chan);
03680       break;
03681    case AST_FRAME_TEXT:
03682       if (fr->subclass == AST_FORMAT_T140) {
03683          res = (chan->tech->write_text == NULL) ? 0 :
03684             chan->tech->write_text(chan, fr);
03685       } else {
03686          res = (chan->tech->send_text == NULL) ? 0 :
03687             chan->tech->send_text(chan, (char *) fr->data.ptr);
03688       }
03689       break;
03690    case AST_FRAME_HTML:
03691       res = (chan->tech->send_html == NULL) ? 0 :
03692          chan->tech->send_html(chan, fr->subclass, (char *) fr->data.ptr, fr->datalen);
03693       break;
03694    case AST_FRAME_VIDEO:
03695       /* XXX Handle translation of video codecs one day XXX */
03696       res = (chan->tech->write_video == NULL) ? 0 :
03697          chan->tech->write_video(chan, fr);
03698       break;
03699    case AST_FRAME_MODEM:
03700       res = (chan->tech->write == NULL) ? 0 :
03701          chan->tech->write(chan, fr);
03702       break;
03703    case AST_FRAME_VOICE:
03704       if (chan->tech->write == NULL)
03705          break;   /*! \todo XXX should return 0 maybe ? */
03706 
03707       if (ast_opt_generic_plc && fr->subclass == AST_FORMAT_SLINEAR) {
03708          apply_plc(chan, fr);
03709       }
03710 
03711       /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
03712       if (fr->subclass == chan->rawwriteformat)
03713          f = fr;
03714       else
03715          f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
03716 
03717       if (!f) {
03718          res = 0;
03719          break;
03720       }
03721 
03722       if (chan->audiohooks) {
03723          struct ast_frame *prev = NULL, *new_frame, *cur, *dup;
03724          int freeoldlist = 0;
03725 
03726          if (f != fr) {
03727             freeoldlist = 1;
03728          }
03729 
03730          /* Since ast_audiohook_write may return a new frame, and the cur frame is
03731           * an item in a list of frames, create a new list adding each cur frame back to it
03732           * regardless if the cur frame changes or not. */
03733          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
03734             new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur);
03735 
03736             /* if this frame is different than cur, preserve the end of the list,
03737              * free the old frames, and set cur to be the new frame */
03738             if (new_frame != cur) {
03739 
03740                /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame
03741                 * isn't part of local storage, meaning if ast_audiohook_write is called multiple
03742                 * times it may override the previous frame we got from it unless we dup it */
03743                if ((dup = ast_frisolate(new_frame))) {
03744                   AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list);
03745                   if (freeoldlist) {
03746                      AST_LIST_NEXT(cur, frame_list) = NULL;
03747                      ast_frfree(cur);
03748                   }
03749                   cur = dup;
03750                }
03751             }
03752 
03753             /* now, regardless if cur is new or not, add it to the new list,
03754              * if the new list has not started, cur will become the first item. */
03755             if (prev) {
03756                AST_LIST_NEXT(prev, frame_list) = cur;
03757             } else {
03758                f = cur; /* set f to be the beginning of our new list */
03759             }
03760             prev = cur;
03761          }
03762       }
03763       
03764       /* If Monitor is running on this channel, then we have to write frames out there too */
03765       /* the translator on chan->writetrans may have returned multiple frames
03766          from the single frame we passed in; if so, feed each one of them to the
03767          monitor */
03768       if (chan->monitor && chan->monitor->write_stream) {
03769          struct ast_frame *cur;
03770 
03771          for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
03772          /* XXX must explain this code */
03773 #ifndef MONITOR_CONSTANT_DELAY
03774             int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples;
03775             if (jump >= 0) {
03776                jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format));
03777                if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
03778                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
03779                chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples;
03780             } else {
03781                chan->outsmpl += cur->samples;
03782             }
03783 #else
03784             int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format));
03785             if (jump - MONITOR_DELAY >= 0) {
03786                if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1)
03787                   ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
03788                chan->outsmpl += chan->insmpl - chan->outsmpl;
03789             } else {
03790                chan->outsmpl += cur->samples;
03791             }
03792 #endif
03793             if (chan->monitor->state == AST_MONITOR_RUNNING) {
03794                if (ast_writestream(chan->monitor->write_stream, cur) < 0)
03795                   ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
03796             }
03797          }
03798       }
03799 
03800       /* the translator on chan->writetrans may have returned multiple frames
03801          from the single frame we passed in; if so, feed each one of them to the
03802          channel, freeing each one after it has been written */
03803       if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
03804          struct ast_frame *cur, *next;
03805          unsigned int skip = 0;
03806 
03807          for (cur = f, next = AST_LIST_NEXT(cur, frame_list);
03808               cur;
03809               cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) {
03810             if (!skip) {
03811                if ((res = chan->tech->write(chan, cur)) < 0) {
03812                   chan->_softhangup |= AST_SOFTHANGUP_DEV;
03813                   skip = 1;
03814                } else if (next) {
03815                   /* don't do this for the last frame in the list,
03816                      as the code outside the loop will do it once
03817                   */
03818                   chan->fout = FRAMECOUNT_INC(chan->fout);
03819                }
03820             }
03821             ast_frfree(cur);
03822          }
03823 
03824          /* reset f so the code below doesn't attempt to free it */
03825          f = NULL;
03826       } else {
03827          res = chan->tech->write(chan, f);
03828       }
03829       break;
03830    case AST_FRAME_NULL:
03831    case AST_FRAME_IAX:
03832       /* Ignore these */
03833       res = 0;
03834       break;
03835    default:
03836       /* At this point, fr is the incoming frame and f is NULL.  Channels do
03837        * not expect to get NULL as a frame pointer and will segfault.  Hence,
03838        * we output the original frame passed in. */
03839       res = chan->tech->write(chan, fr);
03840       break;
03841    }
03842 
03843    if (f && f != fr)
03844       ast_frfree(f);
03845    ast_clear_flag(chan, AST_FLAG_BLOCKING);
03846 
03847    /* Consider a write failure to force a soft hangup */
03848    if (res < 0) {
03849       chan->_softhangup |= AST_SOFTHANGUP_DEV;
03850    } else {
03851       chan->fout = FRAMECOUNT_INC(chan->fout);
03852    }
03853 done:
03854    ast_channel_unlock(chan);
03855    return res;
03856 }

int ast_write_text ( struct ast_channel *  chan,
struct ast_frame *  frame 
)

Write text 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.

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

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

03478 {
03479    int res;
03480    if (!chan->tech->write_video)
03481       return 0;
03482    res = ast_write(chan, fr);
03483    if (!res)
03484       res = 1;
03485    return res;
03486 }

const char* channelreloadreason2txt ( enum channelreloadreason  reason  ) 

Convert enum channelreloadreason to text string for manager event.

Parameters:
reason Enum channelreloadreason - reason for reload (manager, cli, start etc)
\ brief Convert channel reloadreason (ENUM) to text string for manager event

Definition at line 5902 of file channel.c.

References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.

Referenced by reload_config().

05903 {
05904    switch (reason) {
05905    case CHANNEL_MODULE_LOAD:
05906       return "LOAD (Channel module load)";
05907 
05908    case CHANNEL_MODULE_RELOAD:
05909       return "RELOAD (Channel module reload)";
05910 
05911    case CHANNEL_CLI_RELOAD:
05912       return "CLIRELOAD (Channel module reload by CLI command)";
05913 
05914    default:
05915       return "MANAGERRELOAD (Channel module reload by manager)";
05916    }
05917 };


Variable Documentation

unsigned long global_fin

The current value of the debug flags is stored in the two variables global_fin and global_fout (declared in main/channel.c)

Definition at line 86 of file channel.c.

Referenced by handle_core_set_debug_channel().

unsigned long global_fout

Definition at line 86 of file channel.c.

Referenced by handle_core_set_debug_channel().


Generated on Wed Aug 11 01:07:35 2010 for Asterisk - the Open Source PBX by  doxygen 1.5.9