Fri Jan 29 14:25:14 2010

Asterisk developer's documentation


channel.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief General Asterisk PBX channel definitions.
00021  * \par See also:
00022  *  \arg \ref Def_Channel
00023  *  \arg \ref channel_drivers
00024  */
00025 
00026 /*! \page Def_Channel Asterisk Channels
00027    \par What is a Channel?
00028    A phone call through Asterisk consists of an incoming
00029    connection and an outbound connection. Each call comes
00030    in through a channel driver that supports one technology,
00031    like SIP, ZAP, IAX2 etc. 
00032    \par
00033    Each channel driver, technology, has it's own private
00034    channel or dialog structure, that is technology-dependent.
00035    Each private structure is "owned" by a generic Asterisk
00036    channel structure, defined in channel.h and handled by
00037    channel.c .
00038    \par Call scenario
00039    This happens when an incoming call arrives to Asterisk
00040    -# Call arrives on a channel driver interface
00041    -# Channel driver creates a PBX channel and starts a 
00042       pbx thread on the channel
00043    -# The dial plan is executed
00044    -# At this point at least two things can happen:
00045       -# The call is answered by Asterisk and 
00046          Asterisk plays a media stream or reads media
00047       -# The dial plan forces Asterisk to create an outbound 
00048          call somewhere with the dial (see \ref app_dial.c)
00049          application
00050    .
00051 
00052    \par Bridging channels
00053    If Asterisk dials out this happens:
00054    -# Dial creates an outbound PBX channel and asks one of the
00055       channel drivers to create a call
00056    -# When the call is answered, Asterisk bridges the media streams
00057       so the caller on the first channel can speak with the callee
00058       on the second, outbound channel
00059    -# In some cases where we have the same technology on both
00060       channels and compatible codecs, a native bridge is used.
00061       In a native bridge, the channel driver handles forwarding
00062       of incoming audio to the outbound stream internally, without
00063       sending audio frames through the PBX.
00064    -# In SIP, theres an "external native bridge" where Asterisk
00065       redirects the endpoint, so audio flows directly between the
00066       caller's phone and the callee's phone. Signalling stays in
00067       Asterisk in order to be able to provide a proper CDR record
00068       for the call.
00069 
00070    
00071    \par Masquerading channels
00072    In some cases, a channel can masquerade itself into another
00073    channel. This happens frequently in call transfers, where 
00074    a new channel takes over a channel that is already involved
00075    in a call. The new channel sneaks in and takes over the bridge
00076    and the old channel, now a zombie, is hung up.
00077    
00078    \par Reference
00079    \arg channel.c - generic functions
00080    \arg channel.h - declarations of functions, flags and structures
00081    \arg translate.h - Transcoding support functions
00082    \arg \ref channel_drivers - Implemented channel drivers
00083    \arg \ref Def_Frame Asterisk Multimedia Frames
00084 
00085 */
00086 
00087 #ifndef _ASTERISK_CHANNEL_H
00088 #define _ASTERISK_CHANNEL_H
00089 
00090 #include "asterisk/abstract_jb.h"
00091 
00092 #include <unistd.h>
00093 
00094 #include "asterisk/poll-compat.h"
00095 
00096 #if defined(__cplusplus) || defined(c_plusplus)
00097 extern "C" {
00098 #endif
00099 
00100 #define AST_MAX_EXTENSION  80 /*!< Max length of an extension */
00101 #define AST_MAX_CONTEXT    80 /*!< Max length of a context */
00102 #define AST_CHANNEL_NAME   80 /*!< Max length of an ast_channel name */
00103 #define MAX_LANGUAGE    20 /*!< Max length of the language setting */
00104 #define MAX_MUSICCLASS     80 /*!< Max length of the music class setting */
00105 
00106 #include "asterisk/compat.h"
00107 #include "asterisk/frame.h"
00108 #include "asterisk/sched.h"
00109 #include "asterisk/chanvars.h"
00110 #include "asterisk/config.h"
00111 #include "asterisk/lock.h"
00112 #include "asterisk/cdr.h"
00113 #include "asterisk/utils.h"
00114 #include "asterisk/linkedlists.h"
00115 #include "asterisk/stringfields.h"
00116 #include "asterisk/compiler.h"
00117 
00118 #define DATASTORE_INHERIT_FOREVER   INT_MAX
00119 
00120 #define AST_MAX_FDS     8
00121 /*
00122  * We have AST_MAX_FDS file descriptors in a channel.
00123  * Some of them have a fixed use:
00124  */
00125 #define AST_ALERT_FD (AST_MAX_FDS-1)      /*!< used for alertpipe */
00126 #define AST_TIMING_FD   (AST_MAX_FDS-2)      /*!< used for timingfd */
00127 #define AST_AGENT_FD (AST_MAX_FDS-3)      /*!< used by agents for pass through */
00128 #define AST_GENERATOR_FD   (AST_MAX_FDS-4)   /*!< used by generator */
00129 
00130 enum ast_bridge_result {
00131    AST_BRIDGE_COMPLETE = 0,
00132    AST_BRIDGE_FAILED = -1,
00133    AST_BRIDGE_FAILED_NOWARN = -2,
00134    AST_BRIDGE_RETRY = -3,
00135 };
00136 
00137 typedef unsigned long long ast_group_t;
00138 
00139 struct ast_generator {
00140    void *(*alloc)(struct ast_channel *chan, void *params);
00141    void (*release)(struct ast_channel *chan, void *data);
00142    /*! This function gets called with the channel unlocked, but is called in
00143     *  the context of the channel thread so we know the channel is not going
00144     *  to disappear.  This callback is responsible for locking the channel as
00145     *  necessary. */
00146    int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
00147 };
00148 
00149 /*! \brief Structure for a data store type */
00150 struct ast_datastore_info {
00151    const char *type;    /*!< Type of data store */
00152    void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */
00153    void (*destroy)(void *data);  /*!< Destroy function */
00154    /*!
00155     * \brief Fix up channel references
00156     *
00157     * \arg data The datastore data
00158     * \arg old_chan The old channel owning the datastore
00159     * \arg new_chan The new channel owning the datastore
00160     *
00161     * This is exactly like the fixup callback of the channel technology interface.
00162     * It allows a datastore to fix any pointers it saved to the owning channel
00163     * in case that the owning channel has changed.  Generally, this would happen
00164     * when the datastore is set to be inherited, and a masquerade occurs.
00165     *
00166     * \return nothing.
00167     */
00168    void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);
00169 };
00170 
00171 /*! \brief Structure for a channel data store */
00172 struct ast_datastore {
00173    char *uid;     /*!< Unique data store identifier */
00174    void *data;    /*!< Contained data */
00175    const struct ast_datastore_info *info; /*!< Data store type information */
00176    unsigned int inheritance;  /*!Number of levels this item will continue to be inherited */
00177    AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
00178 };
00179 
00180 /*! \brief Structure for all kinds of caller ID identifications.
00181  * \note All string fields here are malloc'ed, so they need to be
00182  * freed when the structure is deleted.
00183  * Also, NULL and "" must be considered equivalent.
00184  */
00185 struct ast_callerid {
00186    char *cid_dnid;      /*!< Malloc'd Dialed Number Identifier */
00187    char *cid_num;    /*!< Malloc'd Caller Number */
00188    char *cid_name;      /*!< Malloc'd Caller Name */
00189    char *cid_ani;    /*!< Malloc'd ANI */
00190    char *cid_rdnis;  /*!< Malloc'd RDNIS */
00191    int cid_pres;     /*!< Callerid presentation/screening */
00192    int cid_ani2;     /*!< Callerid ANI 2 (Info digits) */
00193    int cid_ton;      /*!< Callerid Type of Number */
00194    int cid_tns;      /*!< Callerid Transit Network Select */
00195 };
00196 
00197 /*! \brief 
00198    Structure to describe a channel "technology", ie a channel driver 
00199    See for examples:
00200    \arg chan_iax2.c - The Inter-Asterisk exchange protocol
00201    \arg chan_sip.c - The SIP channel driver
00202    \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
00203 
00204    If you develop your own channel driver, this is where you
00205    tell the PBX at registration of your driver what properties
00206    this driver supports and where different callbacks are 
00207    implemented.
00208 */
00209 struct ast_channel_tech {
00210    const char * const type;
00211    const char * const description;
00212 
00213    int capabilities;    /*!< Bitmap of formats this channel can handle */
00214 
00215    int properties;         /*!< Technology Properties */
00216 
00217    /*! \brief Requester - to set up call data structures (pvt's) */
00218    struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
00219 
00220    int (* const devicestate)(void *data); /*!< Devicestate call back */
00221 
00222    /*! \brief Start sending a literal DTMF digit */
00223    int (* const send_digit_begin)(struct ast_channel *chan, char digit);
00224 
00225    /*! \brief Stop sending a literal DTMF digit */
00226    int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
00227 
00228    /*! \brief Call a given phone number (address, etc), but don't
00229       take longer than timeout seconds to do so.  */
00230    int (* const call)(struct ast_channel *chan, char *addr, int timeout);
00231 
00232    /*! \brief Hangup (and possibly destroy) the channel */
00233    int (* const hangup)(struct ast_channel *chan);
00234 
00235    /*! \brief Answer the channel */
00236    int (* const answer)(struct ast_channel *chan);
00237 
00238    /*! \brief Read a frame, in standard format (see frame.h) */
00239    struct ast_frame * (* const read)(struct ast_channel *chan);
00240 
00241    /*! \brief Write a frame, in standard format (see frame.h) */
00242    int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
00243 
00244    /*! \brief Display or transmit text */
00245    int (* const send_text)(struct ast_channel *chan, const char *text);
00246 
00247    /*! \brief Display or send an image */
00248    int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
00249 
00250    /*! \brief Send HTML data */
00251    int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
00252 
00253    /*! \brief Handle an exception, reading a frame */
00254    struct ast_frame * (* const exception)(struct ast_channel *chan);
00255 
00256    /*! \brief Bridge two channels of the same type together */
00257    enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
00258                   struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00259 
00260    /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
00261    int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
00262 
00263    /*! \brief Fix up a channel:  If a channel is consumed, this is called.  Basically update any ->owner links */
00264    int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
00265 
00266    /*! \brief Set a given option */
00267    int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
00268 
00269    /*! \brief Query a given option */
00270    int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
00271 
00272    /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
00273    int (* const transfer)(struct ast_channel *chan, const char *newdest);
00274 
00275    /*! \brief Write a frame, in standard format */
00276    int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
00277 
00278    /*! \brief Find bridged channel */
00279    struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
00280 
00281    /*! \brief Provide additional read items for CHANNEL() dialplan function */
00282    int (* func_channel_read)(struct ast_channel *chan, char *function, char *data, char *buf, size_t len);
00283 
00284    /*! \brief Provide additional write items for CHANNEL() dialplan function */
00285    int (* func_channel_write)(struct ast_channel *chan, char *function, char *data, const char *value);
00286 
00287    /*! \brief Retrieve base channel (agent and local) */
00288    struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
00289    
00290    /*! \brief Set base channel (agent and local) */
00291    int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
00292 };
00293 
00294 #define  DEBUGCHAN_FLAG  0x80000000
00295 #define  FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
00296 
00297 enum ast_channel_adsicpe {
00298    AST_ADSI_UNKNOWN,
00299    AST_ADSI_AVAILABLE,
00300    AST_ADSI_UNAVAILABLE,
00301    AST_ADSI_OFFHOOKONLY,
00302 };
00303 
00304 /*! 
00305  * \brief ast_channel states
00306  *
00307  * \note Bits 0-15 of state are reserved for the state (up/down) of the line
00308  *       Bits 16-32 of state are reserved for flags
00309  */
00310 enum ast_channel_state {
00311    /*! Channel is down and available */
00312    AST_STATE_DOWN,
00313    /*! Channel is down, but reserved */
00314    AST_STATE_RESERVED,
00315    /*! Channel is off hook */
00316    AST_STATE_OFFHOOK,
00317    /*! Digits (or equivalent) have been dialed */
00318    AST_STATE_DIALING,
00319    /*! Line is ringing */
00320    AST_STATE_RING,
00321    /*! Remote end is ringing */
00322    AST_STATE_RINGING,
00323    /*! Line is up */
00324    AST_STATE_UP,
00325    /*! Line is busy */
00326    AST_STATE_BUSY,
00327    /*! Digits (or equivalent) have been dialed while offhook */
00328    AST_STATE_DIALING_OFFHOOK,
00329    /*! Channel has detected an incoming call and is waiting for ring */
00330    AST_STATE_PRERING,
00331 
00332    /*! Do not transmit voice data */
00333    AST_STATE_MUTE = (1 << 16),
00334 };
00335 
00336 /*! \brief Main Channel structure associated with a channel. 
00337  * This is the side of it mostly used by the pbx and call management.
00338  *
00339  * \note XXX It is important to remember to increment .cleancount each time
00340  *       this structure is changed. XXX
00341  */
00342 struct ast_channel {
00343    /*! \brief Technology (point to channel driver) */
00344    const struct ast_channel_tech *tech;
00345 
00346    /*! \brief Private data used by the technology driver */
00347    void *tech_pvt;
00348 
00349    AST_DECLARE_STRING_FIELDS(
00350       AST_STRING_FIELD(name);       /*!< ASCII unique channel name */
00351       AST_STRING_FIELD(language);      /*!< Language requested for voice prompts */
00352       AST_STRING_FIELD(musicclass);    /*!< Default music class */
00353       AST_STRING_FIELD(accountcode);      /*!< Account code for billing */
00354       AST_STRING_FIELD(call_forward);     /*!< Where to forward to if asked to dial on this interface */
00355       AST_STRING_FIELD(uniqueid);      /*!< Unique Channel Identifier */
00356    );
00357    
00358    /*! \brief File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1.  */
00359    int fds[AST_MAX_FDS];         
00360 
00361    void *music_state;            /*!< Music State*/
00362    void *generatordata;          /*!< Current generator data if there is any */
00363    struct ast_generator *generator;    /*!< Current active data generator */
00364 
00365    /*! \brief Who are we bridged to, if we're bridged. Who is proxying for us,
00366      if we are proxied (i.e. chan_agent).
00367      Do not access directly, use ast_bridged_channel(chan) */
00368    struct ast_channel *_bridge;
00369    struct ast_channel *masq;        /*!< Channel that will masquerade as us */
00370    struct ast_channel *masqr;       /*!< Who we are masquerading as */
00371    int cdrflags;              /*!< Call Detail Record Flags */
00372 
00373    /*! \brief Whether or not we have been hung up...  Do not set this value
00374        directly, use ast_softhangup */
00375    int _softhangup;
00376    time_t   whentohangup;           /*!< Non-zero, set to actual time when channel is to be hung up */
00377    pthread_t blocker;            /*!< If anyone is blocking, this is them */
00378    ast_mutex_t lock;          /*!< Lock, can be used to lock a channel for some operations */
00379    const char *blockproc;           /*!< Procedure causing blocking */
00380 
00381    const char *appl;          /*!< Current application */
00382    const char *data;          /*!< Data passed to current application */
00383    int fdno;               /*!< Which fd had an event detected on */
00384    struct sched_context *sched;        /*!< Schedule context */
00385    int streamid;              /*!< For streaming playback, the schedule ID */
00386    struct ast_filestream *stream;         /*!< Stream itself. */
00387    int vstreamid;             /*!< For streaming video playback, the schedule ID */
00388    struct ast_filestream *vstream;        /*!< Video Stream itself. */
00389    int oldwriteformat;           /*!< Original writer format */
00390    
00391    int timingfd;              /*!< Timing fd */
00392    int (*timingfunc)(const void *data);
00393    void *timingdata;
00394 
00395    enum ast_channel_state _state;         /*!< State of line -- Don't write directly, use ast_setstate */
00396    int rings;              /*!< Number of rings so far */
00397    struct ast_callerid cid;         /*!< Caller ID, name, presentation etc */
00398    char unused_old_dtmfq[AST_MAX_EXTENSION]; /*!< The DTMFQ is deprecated.  All frames should go to the readq. */
00399    struct ast_frame dtmff;          /*!< DTMF frame */
00400 
00401    char context[AST_MAX_CONTEXT];         /*!< Dialplan: Current extension context */
00402    char exten[AST_MAX_EXTENSION];         /*!< Dialplan: Current extension number */
00403    int priority;              /*!< Dialplan: Current extension priority */
00404    char macrocontext[AST_MAX_CONTEXT];    /*!< Macro: Current non-macro context. See app_macro.c */
00405    char macroexten[AST_MAX_EXTENSION];    /*!< Macro: Current non-macro extension. See app_macro.c */
00406    int macropriority;            /*!< Macro: Current non-macro priority. See app_macro.c */
00407    char dialcontext[AST_MAX_CONTEXT];              /*!< Dial: Extension context that we were called from */
00408 
00409    struct ast_pbx *pbx;          /*!< PBX private structure for this channel */
00410    int amaflags;              /*!< Set BEFORE PBX is started to determine AMA flags */
00411    struct ast_cdr *cdr;          /*!< Call Detail Record */
00412    enum ast_channel_adsicpe adsicpe;      /*!< Whether or not ADSI is detected on CPE */
00413 
00414    struct tone_zone *zone;          /*!< Tone zone as set in indications.conf or
00415                         in the CHANNEL dialplan function */
00416 
00417    struct ast_channel_monitor *monitor;      /*!< Channel monitoring */
00418 
00419    /*! Track the read/written samples for monitor use */
00420    unsigned long insmpl;
00421    unsigned long outsmpl;
00422 
00423    /* Frames in/out counters. The high bit is a debug mask, so
00424     * the counter is only in the remaining bits
00425     */
00426    unsigned int fin;
00427    unsigned int fout;
00428    int hangupcause;           /*!< Why is the channel hanged up. See causes.h */
00429    struct varshead varshead;        /*!< A linked list for channel variables */
00430    ast_group_t callgroup;           /*!< Call group for call pickups */
00431    ast_group_t pickupgroup;         /*!< Pickup group - which calls groups can be picked up? */
00432    unsigned int flags;           /*!< channel flags of AST_FLAG_ type */
00433    unsigned short transfercapability;     /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
00434    AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
00435    int alertpipe[2];
00436 
00437    int nativeformats;            /*!< Kinds of data this channel can natively handle */
00438    int readformat;               /*!< Requested read format */
00439    int writeformat;           /*!< Requested write format */
00440    struct ast_trans_pvt *writetrans;      /*!< Write translation path */
00441    struct ast_trans_pvt *readtrans;    /*!< Read translation path */
00442    int rawreadformat;            /*!< Raw read format */
00443    int rawwriteformat;           /*!< Raw write format */
00444 
00445    struct ast_audiohook_list *audiohooks;
00446    void *unused; /*! This pointer should stay for Asterisk 1.4.  It just keeps the struct size the same
00447           *  for the sake of ABI compatability. */
00448 
00449    AST_LIST_ENTRY(ast_channel) chan_list;    /*!< For easy linking */
00450    
00451    struct ast_jb jb;          /*!< The jitterbuffer state  */
00452 
00453    char emulate_dtmf_digit;         /*!< Digit being emulated */
00454    unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
00455    struct timeval dtmf_tv;       /*!< The time that an in process digit began, or the last digit ended */
00456 
00457    int visible_indication;                         /*!< Indication currently playing on the channel */
00458 
00459    /*! \brief Data stores on the channel */
00460    AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores;
00461 };
00462 
00463 /*! \brief ast_channel_tech Properties */
00464 enum {
00465    /*! \brief Channels have this property if they can accept input with jitter; 
00466     *         i.e. most VoIP channels */
00467    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00468    /*! \brief Channels have this property if they can create jitter; 
00469     *         i.e. most VoIP channels */
00470    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00471 };
00472 
00473 /*! \brief ast_channel flags */
00474 enum {
00475    /*! Queue incoming dtmf, to be released when this flag is turned off */
00476    AST_FLAG_DEFER_DTMF =    (1 << 1),
00477    /*! write should be interrupt generator */
00478    AST_FLAG_WRITE_INT =     (1 << 2),
00479    /*! a thread is blocking on this channel */
00480    AST_FLAG_BLOCKING =      (1 << 3),
00481    /*! This is a zombie channel */
00482    AST_FLAG_ZOMBIE =        (1 << 4),
00483    /*! There is an exception pending */
00484    AST_FLAG_EXCEPTION =     (1 << 5),
00485    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00486    AST_FLAG_MOH =           (1 << 6),
00487    /*! This channel is spying on another channel */
00488    AST_FLAG_SPYING =        (1 << 7),
00489    /*! This channel is in a native bridge */
00490    AST_FLAG_NBRIDGE =       (1 << 8),
00491    /*! the channel is in an auto-incrementing dialplan processor,
00492     *  so when ->priority is set, it will get incremented before
00493     *  finding the next priority to run */
00494    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00495    /*! This is an outgoing call */
00496    AST_FLAG_OUTGOING =      (1 << 10),
00497    /*! This channel is being whispered on */
00498    AST_FLAG_WHISPER =       (1 << 11),
00499    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00500    AST_FLAG_IN_DTMF =       (1 << 12),
00501    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is 
00502     *  currently being emulated */
00503    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00504    /*! This is set to tell the channel not to generate DTMF begin frames, and
00505     *  to instead only generate END frames. */
00506    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00507    /*! This flag indicates that on a masquerade, an active stream should not
00508     *  be carried over */
00509    AST_FLAG_MASQ_NOSTREAM = (1 << 15),
00510    /*! This flag indicates that the hangup exten was run when the bridge terminated,
00511     *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
00512     *  level */
00513    AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 16),
00514    /*! This flag indicates that the hangup exten should NOT be run when the 
00515     *  bridge terminates, this will allow the hangup in the pbx loop to be run instead.
00516     *  */
00517    AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 17),
00518    /*! This flag indicates whether the channel is in the channel list or not. */
00519    AST_FLAG_IN_CHANNEL_LIST = (1 << 19),
00520    /*! Disable certain workarounds.  This reintroduces certain bugs, but allows
00521     *  some non-traditional dialplans (like AGI) to continue to function.
00522     */
00523    AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
00524 };
00525 
00526 /*! \brief ast_bridge_config flags */
00527 enum {
00528    AST_FEATURE_PLAY_WARNING = (1 << 0),
00529    AST_FEATURE_REDIRECT =     (1 << 1),
00530    AST_FEATURE_DISCONNECT =   (1 << 2),
00531    AST_FEATURE_ATXFER =       (1 << 3),
00532    AST_FEATURE_AUTOMON =      (1 << 4),
00533    AST_FEATURE_PARKCALL =     (1 << 5),
00534    AST_FEATURE_NO_H_EXTEN =   (1 << 6),
00535    AST_FEATURE_WARNING_ACTIVE = (1 << 7),
00536 };
00537 
00538 struct ast_bridge_config {
00539    struct ast_flags features_caller;
00540    struct ast_flags features_callee;
00541    struct timeval start_time;
00542    struct timeval nexteventts;
00543    struct timeval partialfeature_timer;
00544    long feature_timer;
00545    long timelimit;
00546    long play_warning;
00547    long warning_freq;
00548    const char *warning_sound;
00549    const char *end_sound;
00550    const char *start_sound;
00551    int firstpass;
00552    unsigned int flags;
00553    void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
00554    void *end_bridge_callback_data;         /*!< Data passed to the callback */
00555    /*! If the end_bridge_callback_data refers to a channel which no longer is going to
00556     * exist when the end_bridge_callback is called, then it needs to be fixed up properly
00557     */
00558    void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
00559 };
00560 
00561 struct chanmon;
00562 
00563 #define LOAD_OH(oh) {   \
00564    oh.context = context; \
00565    oh.exten = exten; \
00566    oh.priority = priority; \
00567    oh.cid_num = cid_num; \
00568    oh.cid_name = cid_name; \
00569    oh.account = account; \
00570    oh.vars = vars; \
00571    oh.parent_channel = NULL; \
00572 } 
00573 
00574 struct outgoing_helper {
00575    const char *context;
00576    const char *exten;
00577    int priority;
00578    const char *cid_num;
00579    const char *cid_name;
00580    const char *account;
00581    struct ast_variable *vars;
00582    struct ast_channel *parent_channel;
00583 };
00584 
00585 enum {
00586    AST_CDR_TRANSFER =   (1 << 0),
00587    AST_CDR_FORWARD =    (1 << 1),
00588    AST_CDR_CALLWAIT =   (1 << 2),
00589    AST_CDR_CONFERENCE = (1 << 3),
00590 };
00591 
00592 enum {
00593    /*! Soft hangup by device */
00594    AST_SOFTHANGUP_DEV =       (1 << 0),
00595    /*! Soft hangup for async goto */
00596    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00597    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00598    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00599    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00600    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00601    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00602 };
00603 
00604 
00605 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
00606 enum channelreloadreason {
00607    CHANNEL_MODULE_LOAD,
00608    CHANNEL_MODULE_RELOAD,
00609    CHANNEL_CLI_RELOAD,
00610    CHANNEL_MANAGER_RELOAD,
00611 };
00612 
00613 /*! \brief Create a channel datastore structure */
00614 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, char *uid);
00615 
00616 /*! \brief Free a channel datastore structure */
00617 int ast_channel_datastore_free(struct ast_datastore *datastore);
00618 
00619 /*! \brief Inherit datastores from a parent to a child. */
00620 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
00621 
00622 /*! \brief Add a datastore to a channel */
00623 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
00624 
00625 /*! \brief Remove a datastore from a channel */
00626 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
00627 
00628 /*! \brief Find a datastore on a channel */
00629 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, char *uid);
00630 
00631 /*! \brief Change the state of a channel */
00632 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
00633 
00634 /*! \brief Create a channel structure 
00635     \return Returns NULL on failure to allocate.
00636    \note New channels are 
00637    by default set to the "default" context and
00638    extension "s"
00639  */
00640 struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt, ...) __attribute__((format(printf, 9, 10)));
00641 
00642 /*!
00643  * \brief Queue one or more frames to a channel's frame queue
00644  *
00645  * \param chan the channel to queue the frame(s) on
00646  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
00647  *        by this function.  It is the responsibility of the caller to handle
00648  *        freeing the memory associated with the frame(s) being passed if
00649  *        necessary.
00650  *
00651  * \retval 0 success
00652  * \retval non-zero failure
00653  */
00654 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
00655 
00656 /*!
00657  * \brief Queue one or more frames to the head of a channel's frame queue
00658  *
00659  * \param chan the channel to queue the frame(s) on
00660  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
00661  *        by this function.  It is the responsibility of the caller to handle
00662  *        freeing the memory associated with the frame(s) being passed if
00663  *        necessary.
00664  *
00665  * \retval 0 success
00666  * \retval non-zero failure
00667  */
00668 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
00669 
00670 /*! \brief Queue a hangup frame */
00671 int ast_queue_hangup(struct ast_channel *chan);
00672 
00673 /*!
00674   \brief Queue a control frame with payload
00675   \param chan channel to queue frame onto
00676   \param control type of control frame
00677   \return zero on success, non-zero on failure
00678 */
00679 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
00680 
00681 /*!
00682   \brief Queue a control frame with payload
00683   \param chan channel to queue frame onto
00684   \param control type of control frame
00685   \param data pointer to payload data to be included in frame
00686   \param datalen number of bytes of payload data
00687   \return zero on success, non-zero on failure
00688 
00689   The supplied payload data is copied into the frame, so the caller's copy
00690   is not modified nor freed, and the resulting frame will retain a copy of
00691   the data even if the caller frees their local copy.
00692 
00693   \note This method should be treated as a 'network transport'; in other
00694   words, your frames may be transferred across an IAX2 channel to another
00695   system, which may be a different endianness than yours. Because of this,
00696   you should ensure that either your frames will never be expected to work
00697   across systems, or that you always put your payload data into 'network byte
00698   order' before calling this function.
00699 */
00700 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
00701             const void *data, size_t datalen);
00702 
00703 /*! \brief Change channel name */
00704 void ast_change_name(struct ast_channel *chan, char *newname);
00705 
00706 /*! \brief Free a channel structure */
00707 void  ast_channel_free(struct ast_channel *);
00708 
00709 /*! \brief Requests a channel 
00710  * \param type type of channel to request
00711  * \param format requested channel format (codec)
00712  * \param data data to pass to the channel requester
00713  * \param status status
00714  * Request a channel of a given type, with data as optional information used 
00715  * by the low level module
00716  * \return Returns an ast_channel on success, NULL on failure.
00717  */
00718 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
00719 
00720 /*!
00721  * \brief Request a channel of a given type, with data as optional information used 
00722  * by the low level module and attempt to place a call on it
00723  * \param type type of channel to request
00724  * \param format requested channel format
00725  * \param data data to pass to the channel requester
00726  * \param timeout maximum amount of time to wait for an answer
00727  * \param reason why unsuccessful (if unsuceessful)
00728  * \param cidnum Caller-ID Number
00729  * \param cidname Caller-ID Name
00730  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00731  * to know if the call was answered or not.
00732  */
00733 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname);
00734 
00735 struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname, struct outgoing_helper *oh);
00736 
00737 /*!
00738 * \brief 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.
00739 * \param caller in channel that requested orig
00740 * \param orig channel being replaced by the call forward channel
00741 * \param timeout maximum amount of time to wait for setup of new forward channel
00742 * \param format requested channel format
00743 * \param oh outgoing helper used with original channel
00744 * \param outstate reason why unsuccessful (if uncuccessful)
00745 * \return Returns the forwarded call's ast_channel on success or NULL on failure
00746 */
00747 struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, int format, struct outgoing_helper *oh, int *outstate);
00748 
00749 /*!\brief Register a channel technology (a new channel driver)
00750  * Called by a channel module to register the kind of channels it supports.
00751  * \param tech Structure defining channel technology or "type"
00752  * \return Returns 0 on success, -1 on failure.
00753  */
00754 int ast_channel_register(const struct ast_channel_tech *tech);
00755 
00756 /*! \brief Unregister a channel technology 
00757  * \param tech Structure defining channel technology or "type" that was previously registered
00758  * \return No return value.
00759  */
00760 void ast_channel_unregister(const struct ast_channel_tech *tech);
00761 
00762 /*! \brief Get a channel technology structure by name
00763  * \param name name of technology to find
00764  * \return a pointer to the structure, or NULL if no matching technology found
00765  */
00766 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
00767 
00768 /*! \brief Hang up a channel  
00769  * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
00770  * performs all stream stopping, etc, on the channel that needs to end.
00771  * chan is no longer valid after this call.
00772  * \param chan channel to hang up
00773  * \return Returns 0 on success, -1 on failure.
00774  */
00775 int ast_hangup(struct ast_channel *chan);
00776 
00777 /*! \brief Softly hangup up a channel 
00778  * \param chan channel to be soft-hung-up
00779  * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to
00780  * safely hangup a channel managed by another thread.
00781  * \param reason an AST_SOFTHANGUP_* reason code
00782  * \return Returns 0 regardless
00783  */
00784 int ast_softhangup(struct ast_channel *chan, int cause);
00785 
00786 /*! \brief Softly hangup up a channel (no channel lock) 
00787  * \param chan channel to be soft-hung-up
00788  * \param reason an AST_SOFTHANGUP_* reason code */
00789 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
00790 
00791 /*! \brief Check to see if a channel is needing hang up 
00792  * \param chan channel on which to check for hang up
00793  * This function determines if the channel is being requested to be hung up.
00794  * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
00795  */
00796 int ast_check_hangup(struct ast_channel *chan);
00797 
00798 /*! \brief Compare a offset with the settings of when to hang a channel up 
00799  * \param chan channel on which to check for hang up
00800  * \param offset offset in seconds from current time
00801  * \return 1, 0, or -1
00802  * This function compares a offset from current time with the absolute time 
00803  * out on a channel (when to hang up). If the absolute time out on a channel
00804  * is earlier than current time plus the offset, it returns 1, if the two
00805  * time values are equal, it return 0, otherwise, it retturn -1.
00806  */
00807 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset);
00808 
00809 /*! \brief Set when to hang a channel up 
00810  * \param chan channel on which to check for hang up
00811  * \param offset offset in seconds from current time of when to hang up
00812  * This function sets the absolute time out on a channel (when to hang up).
00813  */
00814 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
00815 
00816 /*! \brief Answer a ringing call 
00817  * \param chan channel to answer
00818  * This function answers a channel and handles all necessary call
00819  * setup functions.
00820  * \return Returns 0 on success, -1 on failure
00821  */
00822 int ast_answer(struct ast_channel *chan);
00823 
00824 /*! \brief Make a call 
00825  * \param chan which channel to make the call on
00826  * \param addr destination of the call
00827  * \param timeout time to wait on for connect
00828  * Place a call, take no longer than timeout ms. 
00829    \return Returns -1 on failure, 0 on not enough time 
00830    (does not automatically stop ringing), and  
00831    the number of seconds the connect took otherwise.
00832    */
00833 int ast_call(struct ast_channel *chan, char *addr, int timeout);
00834 
00835 /*! \brief Indicates condition of channel 
00836  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
00837  * \param chan channel to change the indication
00838  * \param condition which condition to indicate on the channel
00839  * \return Returns 0 on success, -1 on failure
00840  */
00841 int ast_indicate(struct ast_channel *chan, int condition);
00842 
00843 /*! \brief Indicates condition of channel, with payload
00844  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
00845  * \param chan channel to change the indication
00846  * \param condition which condition to indicate on the channel
00847  * \param data pointer to payload data
00848  * \param datalen size of payload data
00849  * \return Returns 0 on success, -1 on failure
00850  */
00851 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
00852 
00853 /* Misc stuff ------------------------------------------------ */
00854 
00855 /*! \brief Wait for input on a channel 
00856  * \param chan channel to wait on
00857  * \param ms length of time to wait on the channel
00858  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 
00859   \return Returns < 0 on  failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
00860 int ast_waitfor(struct ast_channel *chan, int ms);
00861 
00862 /*! \brief Wait for a specied amount of time, looking for hangups 
00863  * \param chan channel to wait for
00864  * \param ms length of time in milliseconds to sleep
00865  * Waits for a specified amount of time, servicing the channel as required.
00866  * \return returns -1 on hangup, otherwise 0.
00867  */
00868 int ast_safe_sleep(struct ast_channel *chan, int ms);
00869 
00870 /*! \brief Wait for a specied amount of time, looking for hangups and a condition argument 
00871  * \param chan channel to wait for
00872  * \param ms length of time in milliseconds to sleep
00873  * \param cond a function pointer for testing continue condition
00874  * \param data argument to be passed to the condition test function
00875  * \return returns -1 on hangup, otherwise 0.
00876  * Waits for a specified amount of time, servicing the channel as required. If cond
00877  * returns 0, this function returns.
00878  */
00879 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
00880 
00881 /*! \brief Waits for activity on a group of channels 
00882  * \param chan an array of pointers to channels
00883  * \param n number of channels that are to be waited upon
00884  * \param fds an array of fds to wait upon
00885  * \param nfds the number of fds to wait upon
00886  * \param exception exception flag
00887  * \param outfd fd that had activity on it
00888  * \param ms how long the wait was
00889  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
00890    file descriptors.
00891    \return Returns the channel with activity, or NULL on error or if an FD
00892    came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
00893    will be -1 */
00894 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms);
00895 
00896 /*! \brief Waits for input on a group of channels
00897    Wait for input on an array of channels for a given # of milliseconds. 
00898    \return Return channel with activity, or NULL if none has activity.  
00899    \param chan an array of pointers to channels
00900    \param n number of channels that are to be waited upon
00901    \param ms time "ms" is modified in-place, if applicable */
00902 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
00903 
00904 /*! \brief Waits for input on an fd
00905    This version works on fd's only.  Be careful with it. */
00906 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
00907 
00908 
00909 /*! \brief Reads a frame
00910  * \param chan channel to read a frame from
00911    Read a frame.  
00912    \return Returns a frame, or NULL on error.  If it returns NULL, you
00913       best just stop reading frames and assume the channel has been
00914       disconnected. */
00915 struct ast_frame *ast_read(struct ast_channel *chan);
00916 
00917 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio. 
00918  * Read a frame. 
00919    \param chan channel to read a frame from
00920    \return  Returns a frame, or NULL on error.  If it returns NULL, you
00921       best just stop reading frames and assume the channel has been
00922       disconnected.  
00923    \note Audio is replaced with AST_FRAME_NULL to avoid 
00924    transcode when the resulting audio is not necessary. */
00925 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
00926 
00927 /*! \brief Write a frame to a channel 
00928  * This function writes the given frame to the indicated channel.
00929  * \param chan destination channel of the frame
00930  * \param frame frame that will be written
00931  * \return It returns 0 on success, -1 on failure.
00932  */
00933 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
00934 
00935 /*! \brief Write video frame to a channel 
00936  * This function writes the given frame to the indicated channel.
00937  * \param chan destination channel of the frame
00938  * \param frame frame that will be written
00939  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
00940  */
00941 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
00942 
00943 /*! \brief Send empty audio to prime a channel driver */
00944 int ast_prod(struct ast_channel *chan);
00945 
00946 /*! \brief Sets read format on channel chan
00947  * Set read format for channel to whichever component of "format" is best. 
00948  * \param chan channel to change
00949  * \param format format to change to
00950  * \return Returns 0 on success, -1 on failure
00951  */
00952 int ast_set_read_format(struct ast_channel *chan, int format);
00953 
00954 /*! \brief Sets write format on channel chan
00955  * Set write format for channel to whichever compoent of "format" is best. 
00956  * \param chan channel to change
00957  * \param format new format for writing
00958  * \return Returns 0 on success, -1 on failure
00959  */
00960 int ast_set_write_format(struct ast_channel *chan, int format);
00961 
00962 /*! \brief Sends text to a channel 
00963  * Write text to a display on a channel
00964  * \param chan channel to act upon
00965  * \param text string of text to send on the channel
00966  * \return Returns 0 on success, -1 on failure
00967  */
00968 int ast_sendtext(struct ast_channel *chan, const char *text);
00969 
00970 /*! \brief Receives a text character from a channel
00971  * \param chan channel to act upon
00972  * \param timeout timeout in milliseconds (0 for infinite wait)
00973  * Read a char of text from a channel
00974  * Returns 0 on success, -1 on failure
00975  */
00976 int ast_recvchar(struct ast_channel *chan, int timeout);
00977 
00978 /*! \brief Send a DTMF digit to a channel
00979  * Send a DTMF digit to a channel.
00980  * \param chan channel to act upon
00981  * \param digit the DTMF digit to send, encoded in ASCII
00982  * \return Returns 0 on success, -1 on failure
00983  */
00984 int ast_senddigit(struct ast_channel *chan, char digit);
00985 
00986 int ast_senddigit_begin(struct ast_channel *chan, char digit);
00987 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
00988 
00989 /*! \brief Receives a text string from a channel
00990  * Read a string of text from a channel
00991  * \param chan channel to act upon
00992  * \param timeout timeout in milliseconds (0 for infinite wait)
00993  * \return the received text, or NULL to signify failure.
00994  */
00995 char *ast_recvtext(struct ast_channel *chan, int timeout);
00996 
00997 /*! \brief Browse channels in use
00998  * Browse the channels currently in use 
00999  * \param prev where you want to start in the channel list
01000  * \return Returns the next channel in the list, NULL on end.
01001  *    If it returns a channel, that channel *has been locked*!
01002  */
01003 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
01004 
01005 /*! \brief Get channel by name (locks channel) */
01006 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
01007 
01008 /*! \brief Get channel by name prefix (locks channel) */
01009 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
01010 
01011 /*! \brief Get channel by name prefix (locks channel) */
01012 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
01013 
01014 /*! \brief Get channel by exten (and optionally context) and lock it */
01015 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
01016 
01017 /*! \brief Get next channel by exten (and optionally context) and lock it */
01018 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
01019                        const char *context);
01020 
01021 /*! ! \brief Waits for a digit
01022  * \param c channel to wait for a digit on
01023  * \param ms how many milliseconds to wait
01024  * \return Returns <0 on error, 0 on no entry, and the digit on success. */
01025 int ast_waitfordigit(struct ast_channel *c, int ms);
01026 
01027 /*! \brief Wait for a digit
01028  Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. 
01029  * \param c channel to wait for a digit on
01030  * \param ms how many milliseconds to wait
01031  * \param audiofd audio file descriptor to write to if audio frames are received
01032  * \param ctrlfd control file descriptor to monitor for reading
01033  * \return Returns 1 if ctrlfd becomes available */
01034 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
01035 
01036 /*! Reads multiple digits 
01037  * \param c channel to read from
01038  * \param s string to read in to.  Must be at least the size of your length
01039  * \param len how many digits to read (maximum)
01040  * \param timeout how long to timeout between digits
01041  * \param rtimeout timeout to wait on the first digit
01042  * \param enders digits to end the string
01043  * Read in a digit string "s", max length "len", maximum timeout between 
01044    digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
01045    for the first digit.  Returns 0 on normal return, or 1 on a timeout.  In the case of
01046    a timeout, any digits that were read before the timeout will still be available in s.  
01047    RETURNS 2 in full version when ctrlfd is available, NOT 1*/
01048 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
01049 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
01050 
01051 /*! \brief Report DTMF on channel 0 */
01052 #define AST_BRIDGE_DTMF_CHANNEL_0      (1 << 0)    
01053 /*! \brief Report DTMF on channel 1 */
01054 #define AST_BRIDGE_DTMF_CHANNEL_1      (1 << 1)    
01055 /*! \brief Return all voice frames on channel 0 */
01056 #define AST_BRIDGE_REC_CHANNEL_0    (1 << 2)    
01057 /*! \brief Return all voice frames on channel 1 */
01058 #define AST_BRIDGE_REC_CHANNEL_1    (1 << 3)    
01059 /*! \brief Ignore all signal frames except NULL */
01060 #define AST_BRIDGE_IGNORE_SIGS         (1 << 4)    
01061 
01062 
01063 /*! \brief Makes two channel formats compatible 
01064  * \param c0 first channel to make compatible
01065  * \param c1 other channel to make compatible
01066  * Set two channels to compatible formats -- call before ast_channel_bridge in general .  
01067  * \return Returns 0 on success and -1 if it could not be done */
01068 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
01069 
01070 /*! Bridge two channels together 
01071  * \param c0 first channel to bridge
01072  * \param c1 second channel to bridge
01073  * \param config config for the channels
01074  * \param fo destination frame(?)
01075  * \param rc destination channel(?)
01076  * Bridge two channels (c0 and c1) together.  If an important frame occurs, we return that frame in
01077    *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
01078 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
01079 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);
01080 
01081 /*! \brief Weird function made for call transfers
01082  * \param original channel to make a copy of
01083  * \param clone copy of the original channel
01084  * This is a very strange and freaky function used primarily for transfer.  Suppose that
01085    "original" and "clone" are two channels in random situations.  This function takes
01086    the guts out of "clone" and puts them into the "original" channel, then alerts the
01087    channel driver of the change, asking it to fixup any private information (like the
01088    p->owner pointer) that is affected by the change.  The physical layer of the original
01089    channel is hung up.  */
01090 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
01091 
01092 /*! Gives the string form of a given cause code */
01093 /*! 
01094  * \param state cause to get the description of
01095  * Give a name to a cause code
01096  * Returns the text form of the binary cause code given
01097  */
01098 const char *ast_cause2str(int state) attribute_pure;
01099 
01100 /*! Convert the string form of a cause code to a number */
01101 /*! 
01102  * \param name string form of the cause
01103  * Returns the cause code
01104  */
01105 int ast_str2cause(const char *name) attribute_pure;
01106 
01107 /*! Gives the string form of a given channel state */
01108 /*! 
01109  * \param ast_channel_state state to get the name of
01110  * Give a name to a state 
01111  * Returns the text form of the binary state given
01112  */
01113 char *ast_state2str(enum ast_channel_state);
01114 
01115 /*! Gives the string form of a given transfer capability */
01116 /*!
01117  * \param transfercapability transfercapabilty to get the name of
01118  * Give a name to a transfercapbility
01119  * See above
01120  * Returns the text form of the binary transfer capbility
01121  */
01122 char *ast_transfercapability2str(int transfercapability) attribute_const;
01123 
01124 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
01125    low level channel.  See frame.h for options.  Note that many channel drivers may support
01126    none or a subset of those features, and you should not count on this if you want your
01127    asterisk application to be portable.  They're mainly useful for tweaking performance */
01128 
01129 /*! Sets an option on a channel */
01130 /*! 
01131  * \param channel channel to set options on
01132  * \param option option to change
01133  * \param data data specific to option
01134  * \param datalen length of the data
01135  * \param block blocking or not
01136  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 
01137  * Returns 0 on success and -1 on failure
01138  */
01139 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
01140 
01141 /*! Pick the best codec  */
01142 /* Choose the best codec...  Uhhh...   Yah. */
01143 int ast_best_codec(int fmts);
01144 
01145 
01146 /*! Checks the value of an option */
01147 /*! 
01148  * Query the value of an option, optionally blocking until a reply is received
01149  * Works similarly to setoption except only reads the options.
01150  */
01151 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
01152 
01153 /*! Checks for HTML support on a channel */
01154 /*! Returns 0 if channel does not support HTML or non-zero if it does */
01155 int ast_channel_supports_html(struct ast_channel *channel);
01156 
01157 /*! Sends HTML on given channel */
01158 /*! Send HTML or URL on link.  Returns 0 on success or -1 on failure */
01159 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
01160 
01161 /*! Sends a URL on a given link */
01162 /*! Send URL on link.  Returns 0 on success or -1 on failure */
01163 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
01164 
01165 /*! Defers DTMF */
01166 /*! Defer DTMF so that you only read things like hangups and audio.  Returns
01167    non-zero if channel was already DTMF-deferred or 0 if channel is just now
01168    being DTMF-deferred */
01169 int ast_channel_defer_dtmf(struct ast_channel *chan);
01170 
01171 /*! Undeos a defer */
01172 /*! Undo defer.  ast_read will return any dtmf characters that were queued */
01173 void ast_channel_undefer_dtmf(struct ast_channel *chan);
01174 
01175 /*! Initiate system shutdown -- prevents new channels from being allocated.
01176     If "hangup" is non-zero, all existing channels will receive soft
01177      hangups */
01178 void ast_begin_shutdown(int hangup);
01179 
01180 /*! Cancels an existing shutdown and returns to normal operation */
01181 void ast_cancel_shutdown(void);
01182 
01183 /*! Returns number of active/allocated channels */
01184 int ast_active_channels(void);
01185 
01186 /*! Returns non-zero if Asterisk is being shut down */
01187 int ast_shutting_down(void);
01188 
01189 /*! Activate a given generator */
01190 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
01191 
01192 /*! Deactive an active generator */
01193 void ast_deactivate_generator(struct ast_channel *chan);
01194 
01195 /*!
01196  * \note The channel does not need to be locked before calling this function.
01197  */
01198 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani);
01199 
01200 
01201 /*! return a mallocd string with the result of sprintf of the fmt and following args */
01202 char __attribute__((format(printf, 1, 2))) *ast_safe_string_alloc(const char *fmt, ...);
01203 
01204 
01205 /*! Start a tone going */
01206 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01207 /*! Stop a tone from playing */
01208 void ast_tonepair_stop(struct ast_channel *chan);
01209 /*! Play a tone pair for a given amount of time */
01210 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01211 
01212 /*!
01213  * \brief Automatically service a channel for us... 
01214  *
01215  * \retval 0 success
01216  * \retval -1 failure, or the channel is already being autoserviced
01217  */
01218 int ast_autoservice_start(struct ast_channel *chan);
01219 
01220 /*! 
01221  * \brief Stop servicing a channel for us...  
01222  *
01223  * \note if chan is locked prior to calling ast_autoservice_stop, it
01224  * is likely that there will be a deadlock between the thread that calls
01225  * ast_autoservice_stop and the autoservice thread. It is important
01226  * that chan is not locked prior to this call
01227  *
01228  * \retval 0 success
01229  * \retval -1 error, or the channel has been hungup 
01230  */
01231 int ast_autoservice_stop(struct ast_channel *chan);
01232 
01233 /* If built with DAHDI optimizations, force a scheduled expiration on the
01234    timer fd, at which point we call the callback function / data */
01235 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data);
01236 
01237 /*!   \brief Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
01238    and 1 if supported and requested 
01239    \param chan current channel
01240    \param dest destination extension for transfer
01241 */
01242 int ast_transfer(struct ast_channel *chan, char *dest);
01243 
01244 /*!   \brief  Start masquerading a channel
01245    XXX This is a seriously wacked out operation.  We're essentially putting the guts of
01246            the clone channel into the original channel.  Start by killing off the original
01247            channel's backend.   I'm not sure we're going to keep this function, because
01248            while the features are nice, the cost is very high in terms of pure nastiness. XXX
01249    \param chan    Channel to masquerade
01250 */
01251 int ast_do_masquerade(struct ast_channel *chan);
01252 
01253 /*!   \brief Find bridged channel 
01254    \param chan Current channel
01255 */
01256 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
01257 
01258 /*!
01259   \brief Inherits channel variable from parent to child channel
01260   \param parent Parent channel
01261   \param child Child channel
01262 
01263   Scans all channel variables in the parent channel, looking for those
01264   that should be copied into the child channel.
01265   Variables whose names begin with a single '_' are copied into the
01266   child channel with the prefix removed.
01267   Variables whose names begin with '__' are copied into the child
01268   channel with their names unchanged.
01269 */
01270 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
01271 
01272 /*!
01273   \brief adds a list of channel variables to a channel
01274   \param chan the channel
01275   \param vars a linked list of variables
01276 
01277   Variable names can be for a regular channel variable or a dialplan function
01278   that has the ability to be written to.
01279 */
01280 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
01281 
01282 /*!
01283   \brief An opaque 'object' structure use by silence generators on channels.
01284  */
01285 struct ast_silence_generator;
01286 
01287 /*!
01288   \brief Starts a silence generator on the given channel.
01289   \param chan The channel to generate silence on
01290   \return An ast_silence_generator pointer, or NULL if an error occurs
01291 
01292   This function will cause SLINEAR silence to be generated on the supplied
01293   channel until it is disabled; if the channel cannot be put into SLINEAR
01294   mode then the function will fail.
01295 
01296   The pointer returned by this function must be preserved and passed to
01297   ast_channel_stop_silence_generator when you wish to stop the silence
01298   generation.
01299  */
01300 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
01301 
01302 /*!
01303   \brief Stops a previously-started silence generator on the given channel.
01304   \param chan The channel to operate on
01305   \param state The ast_silence_generator pointer return by a previous call to
01306   ast_channel_start_silence_generator.
01307   \return nothing
01308 
01309   This function will stop the operating silence generator and return the channel
01310   to its previous write format.
01311  */
01312 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
01313 
01314 /*!
01315   \brief Check if the channel can run in internal timing mode.
01316   \param chan The channel to check
01317   \return boolean
01318 
01319   This function will return 1 if internal timing is enabled and the timing
01320   device is available.
01321  */
01322 int ast_internal_timing_enabled(struct ast_channel *chan);
01323 
01324 /* Misc. functions below */
01325 
01326 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
01327  * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
01328  * return value to the index into the array)
01329  */
01330 static inline int ast_add_fd(struct pollfd *pfd, int fd)
01331 {
01332    pfd->fd = fd;
01333    pfd->events = POLLIN | POLLPRI;
01334    return fd >= 0;
01335 }
01336 
01337 /*! \brief Helper function for migrating select to poll */
01338 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
01339 {
01340    int x;
01341    int dummy=0;
01342 
01343    if (fd < 0)
01344       return 0;
01345    if (!start)
01346       start = &dummy;
01347    for (x = *start; x<max; x++)
01348       if (pfds[x].fd == fd) {
01349          if (x == *start)
01350             (*start)++;
01351          return pfds[x].revents;
01352       }
01353    return 0;
01354 }
01355 
01356 #ifndef HAVE_TIMERSUB
01357 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
01358 {
01359    tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
01360    tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
01361    if (tvdiff->tv_usec < 0) {
01362       tvdiff->tv_sec --;
01363       tvdiff->tv_usec += 1000000;
01364    }
01365 
01366 }
01367 #endif
01368 
01369 /*! \brief Waits for activity on a group of channels 
01370  * \param nfds the maximum number of file descriptors in the sets
01371  * \param rfds file descriptors to check for read availability
01372  * \param wfds file descriptors to check for write availability
01373  * \param efds file descriptors to check for exceptions (OOB data)
01374  * \param tvp timeout while waiting for events
01375  * This is the same as a standard select(), except it guarantees the
01376  * behaviour where the passed struct timeval is updated with how much
01377  * time was not slept while waiting for the specified events
01378  */
01379 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
01380 {
01381 #ifdef __linux__
01382    return select(nfds, rfds, wfds, efds, tvp);
01383 #else
01384    if (tvp) {
01385       struct timeval tv, tvstart, tvend, tvlen;
01386       int res;
01387 
01388       tv = *tvp;
01389       gettimeofday(&tvstart, NULL);
01390       res = select(nfds, rfds, wfds, efds, tvp);
01391       gettimeofday(&tvend, NULL);
01392       timersub(&tvend, &tvstart, &tvlen);
01393       timersub(&tv, &tvlen, tvp);
01394       if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
01395          tvp->tv_sec = 0;
01396          tvp->tv_usec = 0;
01397       }
01398       return res;
01399    }
01400    else
01401       return select(nfds, rfds, wfds, efds, NULL);
01402 #endif
01403 }
01404 
01405 #define CHECK_BLOCKING(c) do {    \
01406    if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
01407       if (option_debug) \
01408          ast_log(LOG_DEBUG, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
01409    } else { \
01410       (c)->blocker = pthread_self(); \
01411       (c)->blockproc = __PRETTY_FUNCTION__; \
01412       ast_set_flag(c, AST_FLAG_BLOCKING); \
01413    } } while (0)
01414 
01415 ast_group_t ast_get_group(const char *s);
01416 
01417 /*! \brief print call- and pickup groups into buffer */
01418 char *ast_print_group(char *buf, int buflen, ast_group_t group);
01419 
01420 /*! \brief Convert enum channelreloadreason to text string for manager event
01421    \param reason  Enum channelreloadreason - reason for reload (manager, cli, start etc)
01422 */
01423 const char *channelreloadreason2txt(enum channelreloadreason reason);
01424 
01425 /*! \brief return an ast_variable list of channeltypes */
01426 struct ast_variable *ast_channeltype_list(void);
01427 
01428 /*!
01429   \brief Begin 'whispering' onto a channel
01430   \param chan The channel to whisper onto
01431   \return 0 for success, non-zero for failure
01432 
01433   This function will add a whisper buffer onto a channel and set a flag
01434   causing writes to the channel to reduce the volume level of the written
01435   audio samples, and then to mix in audio from the whisper buffer if it
01436   is available.
01437 
01438   Note: This function performs no locking; you must hold the channel's lock before
01439   calling this function.
01440  */
01441 int ast_channel_whisper_start(struct ast_channel *chan);
01442 
01443 /*!
01444   \brief Feed an audio frame into the whisper buffer on a channel
01445   \param chan The channel to whisper onto
01446   \param f The frame to to whisper onto chan
01447   \return 0 for success, non-zero for failure
01448  */
01449 int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f);
01450 
01451 /*!
01452   \brief Stop 'whispering' onto a channel
01453   \param chan The channel to whisper onto
01454   \return 0 for success, non-zero for failure
01455 
01456   Note: This function performs no locking; you must hold the channel's lock before
01457   calling this function.
01458  */
01459 void ast_channel_whisper_stop(struct ast_channel *chan);
01460 
01461 
01462 
01463 /*!
01464   \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
01465   \param reason  The integer argument, usually taken from AST_CONTROL_ macros
01466   \return char pointer explaining the code
01467  */
01468 char *ast_channel_reason2str(int reason);
01469 
01470 
01471 #if defined(__cplusplus) || defined(c_plusplus)
01472 }
01473 #endif
01474 
01475 #endif /* _ASTERISK_CHANNEL_H */

Generated on Fri Jan 29 14:25:14 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7