Tue Jul 14 23:09:48 2009

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 };
00519 
00520 /*! \brief ast_bridge_config flags */
00521 enum {
00522    AST_FEATURE_PLAY_WARNING = (1 << 0),
00523    AST_FEATURE_REDIRECT =     (1 << 1),
00524    AST_FEATURE_DISCONNECT =   (1 << 2),
00525    AST_FEATURE_ATXFER =       (1 << 3),
00526    AST_FEATURE_AUTOMON =      (1 << 4),
00527    AST_FEATURE_PARKCALL =     (1 << 5),
00528    AST_FEATURE_NO_H_EXTEN =   (1 << 6),
00529    AST_FEATURE_WARNING_ACTIVE = (1 << 7),
00530 };
00531 
00532 struct ast_bridge_config {
00533    struct ast_flags features_caller;
00534    struct ast_flags features_callee;
00535    struct timeval start_time;
00536    struct timeval nexteventts;
00537    struct timeval partialfeature_timer;
00538    long feature_timer;
00539    long timelimit;
00540    long play_warning;
00541    long warning_freq;
00542    const char *warning_sound;
00543    const char *end_sound;
00544    const char *start_sound;
00545    int firstpass;
00546    unsigned int flags;
00547    void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
00548    void *end_bridge_callback_data;         /*!< Data passed to the callback */
00549    /*! If the end_bridge_callback_data refers to a channel which no longer is going to
00550     * exist when the end_bridge_callback is called, then it needs to be fixed up properly
00551     */
00552    void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
00553 };
00554 
00555 struct chanmon;
00556 
00557 #define LOAD_OH(oh) {   \
00558    oh.context = context; \
00559    oh.exten = exten; \
00560    oh.priority = priority; \
00561    oh.cid_num = cid_num; \
00562    oh.cid_name = cid_name; \
00563    oh.account = account; \
00564    oh.vars = vars; \
00565    oh.parent_channel = NULL; \
00566 } 
00567 
00568 struct outgoing_helper {
00569    const char *context;
00570    const char *exten;
00571    int priority;
00572    const char *cid_num;
00573    const char *cid_name;
00574    const char *account;
00575    struct ast_variable *vars;
00576    struct ast_channel *parent_channel;
00577 };
00578 
00579 enum {
00580    AST_CDR_TRANSFER =   (1 << 0),
00581    AST_CDR_FORWARD =    (1 << 1),
00582    AST_CDR_CALLWAIT =   (1 << 2),
00583    AST_CDR_CONFERENCE = (1 << 3),
00584 };
00585 
00586 enum {
00587    /*! Soft hangup by device */
00588    AST_SOFTHANGUP_DEV =       (1 << 0),
00589    /*! Soft hangup for async goto */
00590    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00591    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00592    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00593    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00594    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00595    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00596 };
00597 
00598 
00599 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
00600 enum channelreloadreason {
00601    CHANNEL_MODULE_LOAD,
00602    CHANNEL_MODULE_RELOAD,
00603    CHANNEL_CLI_RELOAD,
00604    CHANNEL_MANAGER_RELOAD,
00605 };
00606 
00607 /*! \brief Create a channel datastore structure */
00608 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, char *uid);
00609 
00610 /*! \brief Free a channel datastore structure */
00611 int ast_channel_datastore_free(struct ast_datastore *datastore);
00612 
00613 /*! \brief Inherit datastores from a parent to a child. */
00614 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
00615 
00616 /*! \brief Add a datastore to a channel */
00617 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
00618 
00619 /*! \brief Remove a datastore from a channel */
00620 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
00621 
00622 /*! \brief Find a datastore on a channel */
00623 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, char *uid);
00624 
00625 /*! \brief Change the state of a channel */
00626 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
00627 
00628 /*! \brief Create a channel structure 
00629     \return Returns NULL on failure to allocate.
00630    \note New channels are 
00631    by default set to the "default" context and
00632    extension "s"
00633  */
00634 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)));
00635 
00636 /*!
00637  * \brief Queue one or more frames to a channel's frame queue
00638  *
00639  * \param chan the channel to queue the frame(s) on
00640  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
00641  *        by this function.  It is the responsibility of the caller to handle
00642  *        freeing the memory associated with the frame(s) being passed if
00643  *        necessary.
00644  *
00645  * \retval 0 success
00646  * \retval non-zero failure
00647  */
00648 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
00649 
00650 /*!
00651  * \brief Queue one or more frames to the head of a channel's frame queue
00652  *
00653  * \param chan the channel to queue the frame(s) on
00654  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
00655  *        by this function.  It is the responsibility of the caller to handle
00656  *        freeing the memory associated with the frame(s) being passed if
00657  *        necessary.
00658  *
00659  * \retval 0 success
00660  * \retval non-zero failure
00661  */
00662 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
00663 
00664 /*! \brief Queue a hangup frame */
00665 int ast_queue_hangup(struct ast_channel *chan);
00666 
00667 /*!
00668   \brief Queue a control frame with payload
00669   \param chan channel to queue frame onto
00670   \param control type of control frame
00671   \return zero on success, non-zero on failure
00672 */
00673 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
00674 
00675 /*!
00676   \brief Queue a control frame with payload
00677   \param chan channel to queue frame onto
00678   \param control type of control frame
00679   \param data pointer to payload data to be included in frame
00680   \param datalen number of bytes of payload data
00681   \return zero on success, non-zero on failure
00682 
00683   The supplied payload data is copied into the frame, so the caller's copy
00684   is not modified nor freed, and the resulting frame will retain a copy of
00685   the data even if the caller frees their local copy.
00686 
00687   \note This method should be treated as a 'network transport'; in other
00688   words, your frames may be transferred across an IAX2 channel to another
00689   system, which may be a different endianness than yours. Because of this,
00690   you should ensure that either your frames will never be expected to work
00691   across systems, or that you always put your payload data into 'network byte
00692   order' before calling this function.
00693 */
00694 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
00695             const void *data, size_t datalen);
00696 
00697 /*! \brief Change channel name */
00698 void ast_change_name(struct ast_channel *chan, char *newname);
00699 
00700 /*! \brief Free a channel structure */
00701 void  ast_channel_free(struct ast_channel *);
00702 
00703 /*! \brief Requests a channel 
00704  * \param type type of channel to request
00705  * \param format requested channel format (codec)
00706  * \param data data to pass to the channel requester
00707  * \param status status
00708  * Request a channel of a given type, with data as optional information used 
00709  * by the low level module
00710  * \return Returns an ast_channel on success, NULL on failure.
00711  */
00712 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
00713 
00714 /*!
00715  * \brief Request a channel of a given type, with data as optional information used 
00716  * by the low level module and attempt to place a call on it
00717  * \param type type of channel to request
00718  * \param format requested channel format
00719  * \param data data to pass to the channel requester
00720  * \param timeout maximum amount of time to wait for an answer
00721  * \param reason why unsuccessful (if unsuceessful)
00722  * \param cidnum Caller-ID Number
00723  * \param cidname Caller-ID Name
00724  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00725  * to know if the call was answered or not.
00726  */
00727 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname);
00728 
00729 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);
00730 
00731 /*!
00732 * \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.
00733 * \param caller in channel that requested orig
00734 * \param orig channel being replaced by the call forward channel
00735 * \param timeout maximum amount of time to wait for setup of new forward channel
00736 * \param format requested channel format
00737 * \param oh outgoing helper used with original channel
00738 * \param outstate reason why unsuccessful (if uncuccessful)
00739 * \return Returns the forwarded call's ast_channel on success or NULL on failure
00740 */
00741 struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, int format, struct outgoing_helper *oh, int *outstate);
00742 
00743 /*!\brief Register a channel technology (a new channel driver)
00744  * Called by a channel module to register the kind of channels it supports.
00745  * \param tech Structure defining channel technology or "type"
00746  * \return Returns 0 on success, -1 on failure.
00747  */
00748 int ast_channel_register(const struct ast_channel_tech *tech);
00749 
00750 /*! \brief Unregister a channel technology 
00751  * \param tech Structure defining channel technology or "type" that was previously registered
00752  * \return No return value.
00753  */
00754 void ast_channel_unregister(const struct ast_channel_tech *tech);
00755 
00756 /*! \brief Get a channel technology structure by name
00757  * \param name name of technology to find
00758  * \return a pointer to the structure, or NULL if no matching technology found
00759  */
00760 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
00761 
00762 /*! \brief Hang up a channel  
00763  * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
00764  * performs all stream stopping, etc, on the channel that needs to end.
00765  * chan is no longer valid after this call.
00766  * \param chan channel to hang up
00767  * \return Returns 0 on success, -1 on failure.
00768  */
00769 int ast_hangup(struct ast_channel *chan);
00770 
00771 /*! \brief Softly hangup up a channel 
00772  * \param chan channel to be soft-hung-up
00773  * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to
00774  * safely hangup a channel managed by another thread.
00775  * \param cause   Ast hangupcause for hangup
00776  * \return Returns 0 regardless
00777  */
00778 int ast_softhangup(struct ast_channel *chan, int cause);
00779 
00780 /*! \brief Softly hangup up a channel (no channel lock) 
00781  * \param chan channel to be soft-hung-up
00782  * \param cause   Ast hangupcause for hangup (see cause.h) */
00783 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
00784 
00785 /*! \brief Check to see if a channel is needing hang up 
00786  * \param chan channel on which to check for hang up
00787  * This function determines if the channel is being requested to be hung up.
00788  * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
00789  */
00790 int ast_check_hangup(struct ast_channel *chan);
00791 
00792 /*! \brief Compare a offset with the settings of when to hang a channel up 
00793  * \param chan channel on which to check for hang up
00794  * \param offset offset in seconds from current time
00795  * \return 1, 0, or -1
00796  * This function compares a offset from current time with the absolute time 
00797  * out on a channel (when to hang up). If the absolute time out on a channel
00798  * is earlier than current time plus the offset, it returns 1, if the two
00799  * time values are equal, it return 0, otherwise, it retturn -1.
00800  */
00801 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset);
00802 
00803 /*! \brief Set when to hang a channel up 
00804  * \param chan channel on which to check for hang up
00805  * \param offset offset in seconds from current time of when to hang up
00806  * This function sets the absolute time out on a channel (when to hang up).
00807  */
00808 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
00809 
00810 /*! \brief Answer a ringing call 
00811  * \param chan channel to answer
00812  * This function answers a channel and handles all necessary call
00813  * setup functions.
00814  * \return Returns 0 on success, -1 on failure
00815  */
00816 int ast_answer(struct ast_channel *chan);
00817 
00818 /*! \brief Make a call 
00819  * \param chan which channel to make the call on
00820  * \param addr destination of the call
00821  * \param timeout time to wait on for connect
00822  * Place a call, take no longer than timeout ms. 
00823    \return Returns -1 on failure, 0 on not enough time 
00824    (does not automatically stop ringing), and  
00825    the number of seconds the connect took otherwise.
00826    */
00827 int ast_call(struct ast_channel *chan, char *addr, int timeout);
00828 
00829 /*! \brief Indicates condition of channel 
00830  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
00831  * \param chan channel to change the indication
00832  * \param condition which condition to indicate on the channel
00833  * \return Returns 0 on success, -1 on failure
00834  */
00835 int ast_indicate(struct ast_channel *chan, int condition);
00836 
00837 /*! \brief Indicates condition of channel, with payload
00838  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
00839  * \param chan channel to change the indication
00840  * \param condition which condition to indicate on the channel
00841  * \param data pointer to payload data
00842  * \param datalen size of payload data
00843  * \return Returns 0 on success, -1 on failure
00844  */
00845 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
00846 
00847 /* Misc stuff ------------------------------------------------ */
00848 
00849 /*! \brief Wait for input on a channel 
00850  * \param chan channel to wait on
00851  * \param ms length of time to wait on the channel
00852  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 
00853   \return Returns < 0 on  failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
00854 int ast_waitfor(struct ast_channel *chan, int ms);
00855 
00856 /*! \brief Wait for a specied amount of time, looking for hangups 
00857  * \param chan channel to wait for
00858  * \param ms length of time in milliseconds to sleep
00859  * Waits for a specified amount of time, servicing the channel as required.
00860  * \return returns -1 on hangup, otherwise 0.
00861  */
00862 int ast_safe_sleep(struct ast_channel *chan, int ms);
00863 
00864 /*! \brief Wait for a specied amount of time, looking for hangups and a condition argument 
00865  * \param chan channel to wait for
00866  * \param ms length of time in milliseconds to sleep
00867  * \param cond a function pointer for testing continue condition
00868  * \param data argument to be passed to the condition test function
00869  * \return returns -1 on hangup, otherwise 0.
00870  * Waits for a specified amount of time, servicing the channel as required. If cond
00871  * returns 0, this function returns.
00872  */
00873 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
00874 
00875 /*! \brief Waits for activity on a group of channels 
00876  * \param chan an array of pointers to channels
00877  * \param n number of channels that are to be waited upon
00878  * \param fds an array of fds to wait upon
00879  * \param nfds the number of fds to wait upon
00880  * \param exception exception flag
00881  * \param outfd fd that had activity on it
00882  * \param ms how long the wait was
00883  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
00884    file descriptors.
00885    \return Returns the channel with activity, or NULL on error or if an FD
00886    came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
00887    will be -1 */
00888 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms);
00889 
00890 /*! \brief Waits for input on a group of channels
00891    Wait for input on an array of channels for a given # of milliseconds. 
00892    \return Return channel with activity, or NULL if none has activity.  
00893    \param chan an array of pointers to channels
00894    \param n number of channels that are to be waited upon
00895    \param ms time "ms" is modified in-place, if applicable */
00896 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
00897 
00898 /*! \brief Waits for input on an fd
00899    This version works on fd's only.  Be careful with it. */
00900 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
00901 
00902 
00903 /*! \brief Reads a frame
00904  * \param chan channel to read a frame from
00905    Read a frame.  
00906    \return Returns a frame, or NULL on error.  If it returns NULL, you
00907       best just stop reading frames and assume the channel has been
00908       disconnected. */
00909 struct ast_frame *ast_read(struct ast_channel *chan);
00910 
00911 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio. 
00912  * Read a frame. 
00913    \param chan channel to read a frame from
00914    \return  Returns a frame, or NULL on error.  If it returns NULL, you
00915       best just stop reading frames and assume the channel has been
00916       disconnected.  
00917    \note Audio is replaced with AST_FRAME_NULL to avoid 
00918    transcode when the resulting audio is not necessary. */
00919 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
00920 
00921 /*! \brief Write a frame to a channel 
00922  * This function writes the given frame to the indicated channel.
00923  * \param chan destination channel of the frame
00924  * \param frame frame that will be written
00925  * \return It returns 0 on success, -1 on failure.
00926  */
00927 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
00928 
00929 /*! \brief Write video frame to a channel 
00930  * This function writes the given frame to the indicated channel.
00931  * \param chan destination channel of the frame
00932  * \param frame frame that will be written
00933  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
00934  */
00935 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
00936 
00937 /*! \brief Send empty audio to prime a channel driver */
00938 int ast_prod(struct ast_channel *chan);
00939 
00940 /*! \brief Sets read format on channel chan
00941  * Set read format for channel to whichever component of "format" is best. 
00942  * \param chan channel to change
00943  * \param format format to change to
00944  * \return Returns 0 on success, -1 on failure
00945  */
00946 int ast_set_read_format(struct ast_channel *chan, int format);
00947 
00948 /*! \brief Sets write format on channel chan
00949  * Set write format for channel to whichever compoent of "format" is best. 
00950  * \param chan channel to change
00951  * \param format new format for writing
00952  * \return Returns 0 on success, -1 on failure
00953  */
00954 int ast_set_write_format(struct ast_channel *chan, int format);
00955 
00956 /*! \brief Sends text to a channel 
00957  * Write text to a display on a channel
00958  * \param chan channel to act upon
00959  * \param text string of text to send on the channel
00960  * \return Returns 0 on success, -1 on failure
00961  */
00962 int ast_sendtext(struct ast_channel *chan, const char *text);
00963 
00964 /*! \brief Receives a text character from a channel
00965  * \param chan channel to act upon
00966  * \param timeout timeout in milliseconds (0 for infinite wait)
00967  * Read a char of text from a channel
00968  * Returns 0 on success, -1 on failure
00969  */
00970 int ast_recvchar(struct ast_channel *chan, int timeout);
00971 
00972 /*! \brief Send a DTMF digit to a channel
00973  * Send a DTMF digit to a channel.
00974  * \param chan channel to act upon
00975  * \param digit the DTMF digit to send, encoded in ASCII
00976  * \return Returns 0 on success, -1 on failure
00977  */
00978 int ast_senddigit(struct ast_channel *chan, char digit);
00979 
00980 int ast_senddigit_begin(struct ast_channel *chan, char digit);
00981 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
00982 
00983 /*! \brief Receives a text string from a channel
00984  * Read a string of text from a channel
00985  * \param chan channel to act upon
00986  * \param timeout timeout in milliseconds (0 for infinite wait)
00987  * \return the received text, or NULL to signify failure.
00988  */
00989 char *ast_recvtext(struct ast_channel *chan, int timeout);
00990 
00991 /*! \brief Browse channels in use
00992  * Browse the channels currently in use 
00993  * \param prev where you want to start in the channel list
00994  * \return Returns the next channel in the list, NULL on end.
00995  *    If it returns a channel, that channel *has been locked*!
00996  */
00997 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
00998 
00999 /*! \brief Get channel by name (locks channel) */
01000 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
01001 
01002 /*! \brief Get channel by name prefix (locks channel) */
01003 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
01004 
01005 /*! \brief Get channel by name prefix (locks channel) */
01006 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
01007 
01008 /*! \brief Get channel by exten (and optionally context) and lock it */
01009 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
01010 
01011 /*! \brief Get next channel by exten (and optionally context) and lock it */
01012 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
01013                        const char *context);
01014 
01015 /*! ! \brief Waits for a digit
01016  * \param c channel to wait for a digit on
01017  * \param ms how many milliseconds to wait
01018  * \return Returns <0 on error, 0 on no entry, and the digit on success. */
01019 int ast_waitfordigit(struct ast_channel *c, int ms);
01020 
01021 /*! \brief Wait for a digit
01022  Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. 
01023  * \param c channel to wait for a digit on
01024  * \param ms how many milliseconds to wait
01025  * \param audiofd audio file descriptor to write to if audio frames are received
01026  * \param ctrlfd control file descriptor to monitor for reading
01027  * \return Returns 1 if ctrlfd becomes available */
01028 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
01029 
01030 /*! Reads multiple digits 
01031  * \param c channel to read from
01032  * \param s string to read in to.  Must be at least the size of your length
01033  * \param len how many digits to read (maximum)
01034  * \param timeout how long to timeout between digits
01035  * \param rtimeout timeout to wait on the first digit
01036  * \param enders digits to end the string
01037  * Read in a digit string "s", max length "len", maximum timeout between 
01038    digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
01039    for the first digit.  Returns 0 on normal return, or 1 on a timeout.  In the case of
01040    a timeout, any digits that were read before the timeout will still be available in s.  
01041    RETURNS 2 in full version when ctrlfd is available, NOT 1*/
01042 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
01043 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
01044 
01045 /*! \brief Report DTMF on channel 0 */
01046 #define AST_BRIDGE_DTMF_CHANNEL_0      (1 << 0)    
01047 /*! \brief Report DTMF on channel 1 */
01048 #define AST_BRIDGE_DTMF_CHANNEL_1      (1 << 1)    
01049 /*! \brief Return all voice frames on channel 0 */
01050 #define AST_BRIDGE_REC_CHANNEL_0    (1 << 2)    
01051 /*! \brief Return all voice frames on channel 1 */
01052 #define AST_BRIDGE_REC_CHANNEL_1    (1 << 3)    
01053 /*! \brief Ignore all signal frames except NULL */
01054 #define AST_BRIDGE_IGNORE_SIGS         (1 << 4)    
01055 
01056 
01057 /*! \brief Makes two channel formats compatible 
01058  * \param c0 first channel to make compatible
01059  * \param c1 other channel to make compatible
01060  * Set two channels to compatible formats -- call before ast_channel_bridge in general .  
01061  * \return Returns 0 on success and -1 if it could not be done */
01062 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
01063 
01064 /*! Bridge two channels together 
01065  * \param c0 first channel to bridge
01066  * \param c1 second channel to bridge
01067  * \param config config for the channels
01068  * \param fo destination frame(?)
01069  * \param rc destination channel(?)
01070  * Bridge two channels (c0 and c1) together.  If an important frame occurs, we return that frame in
01071    *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
01072 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
01073 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);
01074 
01075 /*! \brief Weird function made for call transfers
01076  * \param original channel to make a copy of
01077  * \param clone copy of the original channel
01078  * This is a very strange and freaky function used primarily for transfer.  Suppose that
01079    "original" and "clone" are two channels in random situations.  This function takes
01080    the guts out of "clone" and puts them into the "original" channel, then alerts the
01081    channel driver of the change, asking it to fixup any private information (like the
01082    p->owner pointer) that is affected by the change.  The physical layer of the original
01083    channel is hung up.  */
01084 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
01085 
01086 /*! Gives the string form of a given cause code */
01087 /*! 
01088  * \param state cause to get the description of
01089  * Give a name to a cause code
01090  * Returns the text form of the binary cause code given
01091  */
01092 const char *ast_cause2str(int state) attribute_pure;
01093 
01094 /*! Convert the string form of a cause code to a number */
01095 /*! 
01096  * \param name string form of the cause
01097  * Returns the cause code
01098  */
01099 int ast_str2cause(const char *name) attribute_pure;
01100 
01101 /*! Gives the string form of a given channel state */
01102 /*! 
01103  * \param ast_channel_state state to get the name of
01104  * Give a name to a state 
01105  * Returns the text form of the binary state given
01106  */
01107 char *ast_state2str(enum ast_channel_state);
01108 
01109 /*! Gives the string form of a given transfer capability */
01110 /*!
01111  * \param transfercapability transfercapabilty to get the name of
01112  * Give a name to a transfercapbility
01113  * See above
01114  * Returns the text form of the binary transfer capbility
01115  */
01116 char *ast_transfercapability2str(int transfercapability) attribute_const;
01117 
01118 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
01119    low level channel.  See frame.h for options.  Note that many channel drivers may support
01120    none or a subset of those features, and you should not count on this if you want your
01121    asterisk application to be portable.  They're mainly useful for tweaking performance */
01122 
01123 /*! Sets an option on a channel */
01124 /*! 
01125  * \param channel channel to set options on
01126  * \param option option to change
01127  * \param data data specific to option
01128  * \param datalen length of the data
01129  * \param block blocking or not
01130  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 
01131  * Returns 0 on success and -1 on failure
01132  */
01133 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
01134 
01135 /*! Pick the best codec  */
01136 /* Choose the best codec...  Uhhh...   Yah. */
01137 int ast_best_codec(int fmts);
01138 
01139 
01140 /*! Checks the value of an option */
01141 /*! 
01142  * Query the value of an option, optionally blocking until a reply is received
01143  * Works similarly to setoption except only reads the options.
01144  */
01145 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
01146 
01147 /*! Checks for HTML support on a channel */
01148 /*! Returns 0 if channel does not support HTML or non-zero if it does */
01149 int ast_channel_supports_html(struct ast_channel *channel);
01150 
01151 /*! Sends HTML on given channel */
01152 /*! Send HTML or URL on link.  Returns 0 on success or -1 on failure */
01153 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
01154 
01155 /*! Sends a URL on a given link */
01156 /*! Send URL on link.  Returns 0 on success or -1 on failure */
01157 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
01158 
01159 /*! Defers DTMF */
01160 /*! Defer DTMF so that you only read things like hangups and audio.  Returns
01161    non-zero if channel was already DTMF-deferred or 0 if channel is just now
01162    being DTMF-deferred */
01163 int ast_channel_defer_dtmf(struct ast_channel *chan);
01164 
01165 /*! Undeos a defer */
01166 /*! Undo defer.  ast_read will return any dtmf characters that were queued */
01167 void ast_channel_undefer_dtmf(struct ast_channel *chan);
01168 
01169 /*! Initiate system shutdown -- prevents new channels from being allocated.
01170     If "hangup" is non-zero, all existing channels will receive soft
01171      hangups */
01172 void ast_begin_shutdown(int hangup);
01173 
01174 /*! Cancels an existing shutdown and returns to normal operation */
01175 void ast_cancel_shutdown(void);
01176 
01177 /*! Returns number of active/allocated channels */
01178 int ast_active_channels(void);
01179 
01180 /*! Returns non-zero if Asterisk is being shut down */
01181 int ast_shutting_down(void);
01182 
01183 /*! Activate a given generator */
01184 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
01185 
01186 /*! Deactive an active generator */
01187 void ast_deactivate_generator(struct ast_channel *chan);
01188 
01189 /*!
01190  * \note The channel does not need to be locked before calling this function.
01191  */
01192 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani);
01193 
01194 
01195 /*! return a mallocd string with the result of sprintf of the fmt and following args */
01196 char __attribute__((format(printf, 1, 2))) *ast_safe_string_alloc(const char *fmt, ...);
01197 
01198 
01199 /*! Start a tone going */
01200 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01201 /*! Stop a tone from playing */
01202 void ast_tonepair_stop(struct ast_channel *chan);
01203 /*! Play a tone pair for a given amount of time */
01204 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01205 
01206 /*!
01207  * \brief Automatically service a channel for us... 
01208  *
01209  * \retval 0 success
01210  * \retval -1 failure, or the channel is already being autoserviced
01211  */
01212 int ast_autoservice_start(struct ast_channel *chan);
01213 
01214 /*! 
01215  * \brief Stop servicing a channel for us...  
01216  *
01217  * \note if chan is locked prior to calling ast_autoservice_stop, it
01218  * is likely that there will be a deadlock between the thread that calls
01219  * ast_autoservice_stop and the autoservice thread. It is important
01220  * that chan is not locked prior to this call
01221  *
01222  * \retval 0 success
01223  * \retval -1 error, or the channel has been hungup 
01224  */
01225 int ast_autoservice_stop(struct ast_channel *chan);
01226 
01227 /* If built with DAHDI optimizations, force a scheduled expiration on the
01228    timer fd, at which point we call the callback function / data */
01229 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data);
01230 
01231 /*!   \brief Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
01232    and 1 if supported and requested 
01233    \param chan current channel
01234    \param dest destination extension for transfer
01235 */
01236 int ast_transfer(struct ast_channel *chan, char *dest);
01237 
01238 /*!   \brief  Start masquerading a channel
01239    XXX This is a seriously wacked out operation.  We're essentially putting the guts of
01240            the clone channel into the original channel.  Start by killing off the original
01241            channel's backend.   I'm not sure we're going to keep this function, because
01242            while the features are nice, the cost is very high in terms of pure nastiness. XXX
01243    \param chan    Channel to masquerade
01244 */
01245 int ast_do_masquerade(struct ast_channel *chan);
01246 
01247 /*!   \brief Find bridged channel 
01248    \param chan Current channel
01249 */
01250 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
01251 
01252 /*!
01253   \brief Inherits channel variable from parent to child channel
01254   \param parent Parent channel
01255   \param child Child channel
01256 
01257   Scans all channel variables in the parent channel, looking for those
01258   that should be copied into the child channel.
01259   Variables whose names begin with a single '_' are copied into the
01260   child channel with the prefix removed.
01261   Variables whose names begin with '__' are copied into the child
01262   channel with their names unchanged.
01263 */
01264 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
01265 
01266 /*!
01267   \brief adds a list of channel variables to a channel
01268   \param chan the channel
01269   \param vars a linked list of variables
01270 
01271   Variable names can be for a regular channel variable or a dialplan function
01272   that has the ability to be written to.
01273 */
01274 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
01275 
01276 /*!
01277   \brief An opaque 'object' structure use by silence generators on channels.
01278  */
01279 struct ast_silence_generator;
01280 
01281 /*!
01282   \brief Starts a silence generator on the given channel.
01283   \param chan The channel to generate silence on
01284   \return An ast_silence_generator pointer, or NULL if an error occurs
01285 
01286   This function will cause SLINEAR silence to be generated on the supplied
01287   channel until it is disabled; if the channel cannot be put into SLINEAR
01288   mode then the function will fail.
01289 
01290   The pointer returned by this function must be preserved and passed to
01291   ast_channel_stop_silence_generator when you wish to stop the silence
01292   generation.
01293  */
01294 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
01295 
01296 /*!
01297   \brief Stops a previously-started silence generator on the given channel.
01298   \param chan The channel to operate on
01299   \param state The ast_silence_generator pointer return by a previous call to
01300   ast_channel_start_silence_generator.
01301   \return nothing
01302 
01303   This function will stop the operating silence generator and return the channel
01304   to its previous write format.
01305  */
01306 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
01307 
01308 /*!
01309   \brief Check if the channel can run in internal timing mode.
01310   \param chan The channel to check
01311   \return boolean
01312 
01313   This function will return 1 if internal timing is enabled and the timing
01314   device is available.
01315  */
01316 int ast_internal_timing_enabled(struct ast_channel *chan);
01317 
01318 /* Misc. functions below */
01319 
01320 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
01321  * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
01322  * return value to the index into the array)
01323  */
01324 static inline int ast_add_fd(struct pollfd *pfd, int fd)
01325 {
01326    pfd->fd = fd;
01327    pfd->events = POLLIN | POLLPRI;
01328    return fd >= 0;
01329 }
01330 
01331 /*! \brief Helper function for migrating select to poll */
01332 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
01333 {
01334    int x;
01335    int dummy=0;
01336 
01337    if (fd < 0)
01338       return 0;
01339    if (!start)
01340       start = &dummy;
01341    for (x = *start; x<max; x++)
01342       if (pfds[x].fd == fd) {
01343          if (x == *start)
01344             (*start)++;
01345          return pfds[x].revents;
01346       }
01347    return 0;
01348 }
01349 
01350 #ifndef HAVE_TIMERSUB
01351 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
01352 {
01353    tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
01354    tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
01355    if (tvdiff->tv_usec < 0) {
01356       tvdiff->tv_sec --;
01357       tvdiff->tv_usec += 1000000;
01358    }
01359 
01360 }
01361 #endif
01362 
01363 /*! \brief Waits for activity on a group of channels 
01364  * \param nfds the maximum number of file descriptors in the sets
01365  * \param rfds file descriptors to check for read availability
01366  * \param wfds file descriptors to check for write availability
01367  * \param efds file descriptors to check for exceptions (OOB data)
01368  * \param tvp timeout while waiting for events
01369  * This is the same as a standard select(), except it guarantees the
01370  * behaviour where the passed struct timeval is updated with how much
01371  * time was not slept while waiting for the specified events
01372  */
01373 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
01374 {
01375 #ifdef __linux__
01376    return select(nfds, rfds, wfds, efds, tvp);
01377 #else
01378    if (tvp) {
01379       struct timeval tv, tvstart, tvend, tvlen;
01380       int res;
01381 
01382       tv = *tvp;
01383       gettimeofday(&tvstart, NULL);
01384       res = select(nfds, rfds, wfds, efds, tvp);
01385       gettimeofday(&tvend, NULL);
01386       timersub(&tvend, &tvstart, &tvlen);
01387       timersub(&tv, &tvlen, tvp);
01388       if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
01389          tvp->tv_sec = 0;
01390          tvp->tv_usec = 0;
01391       }
01392       return res;
01393    }
01394    else
01395       return select(nfds, rfds, wfds, efds, NULL);
01396 #endif
01397 }
01398 
01399 #define CHECK_BLOCKING(c) do {    \
01400    if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
01401       if (option_debug) \
01402          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); \
01403    } else { \
01404       (c)->blocker = pthread_self(); \
01405       (c)->blockproc = __PRETTY_FUNCTION__; \
01406       ast_set_flag(c, AST_FLAG_BLOCKING); \
01407    } } while (0)
01408 
01409 ast_group_t ast_get_group(const char *s);
01410 
01411 /*! \brief print call- and pickup groups into buffer */
01412 char *ast_print_group(char *buf, int buflen, ast_group_t group);
01413 
01414 /*! \brief Convert enum channelreloadreason to text string for manager event
01415    \param reason  Enum channelreloadreason - reason for reload (manager, cli, start etc)
01416 */
01417 const char *channelreloadreason2txt(enum channelreloadreason reason);
01418 
01419 /*! \brief return an ast_variable list of channeltypes */
01420 struct ast_variable *ast_channeltype_list(void);
01421 
01422 /*!
01423   \brief Begin 'whispering' onto a channel
01424   \param chan The channel to whisper onto
01425   \return 0 for success, non-zero for failure
01426 
01427   This function will add a whisper buffer onto a channel and set a flag
01428   causing writes to the channel to reduce the volume level of the written
01429   audio samples, and then to mix in audio from the whisper buffer if it
01430   is available.
01431 
01432   Note: This function performs no locking; you must hold the channel's lock before
01433   calling this function.
01434  */
01435 int ast_channel_whisper_start(struct ast_channel *chan);
01436 
01437 /*!
01438   \brief Feed an audio frame into the whisper buffer on a channel
01439   \param chan The channel to whisper onto
01440   \param f The frame to to whisper onto chan
01441   \return 0 for success, non-zero for failure
01442  */
01443 int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f);
01444 
01445 /*!
01446   \brief Stop 'whispering' onto a channel
01447   \param chan The channel to whisper onto
01448   \return 0 for success, non-zero for failure
01449 
01450   Note: This function performs no locking; you must hold the channel's lock before
01451   calling this function.
01452  */
01453 void ast_channel_whisper_stop(struct ast_channel *chan);
01454 
01455 
01456 
01457 /*!
01458   \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
01459   \param reason  The integer argument, usually taken from AST_CONTROL_ macros
01460   \return char pointer explaining the code
01461  */
01462 char *ast_channel_reason2str(int reason);
01463 
01464 
01465 #if defined(__cplusplus) || defined(c_plusplus)
01466 }
01467 #endif
01468 
01469 #endif /* _ASTERISK_CHANNEL_H */

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