Wed Mar 2 18:53:24 2011

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, DAHDI, 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    \arg \ref Def_Bridge
00085 
00086 */
00087 /*! \page Def_Bridge Asterisk Channel Bridges
00088 
00089    In Asterisk, there's several media bridges.
00090 
00091    The Core bridge handles two channels (a "phone call") and bridge
00092    them together.
00093 
00094    The conference bridge (meetme) handles several channels simultaneously
00095    with the support of an external timer (DAHDI timer). This is used
00096    not only by the Conference application (meetme) but also by the
00097    page application and the SLA system introduced in 1.4.
00098    The conference bridge does not handle video.
00099 
00100    When two channels of the same type connect, the channel driver
00101    or the media subsystem used by the channel driver (i.e. RTP)
00102    can create a native bridge without sending media through the
00103    core.
00104 
00105    Native briding can be disabled by a number of reasons,
00106    like DTMF being needed by the core or codecs being incompatible
00107    so a transcoding module is needed.
00108 
00109 References:
00110    \li \see ast_channel_early_bridge()
00111    \li \see ast_channel_bridge()
00112    \li \see app_meetme.c
00113    \li \ref AstRTPbridge
00114    \li \see ast_rtp_bridge()
00115    \li \ref Def_Channel
00116 */
00117 
00118 /*! \page AstFileDesc File descriptors
00119    Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
00120    in the \ref ast_channel structure.
00121 */
00122 
00123 #ifndef _ASTERISK_CHANNEL_H
00124 #define _ASTERISK_CHANNEL_H
00125 
00126 #include "asterisk/abstract_jb.h"
00127 
00128 #include "asterisk/poll-compat.h"
00129 
00130 #if defined(__cplusplus) || defined(c_plusplus)
00131 extern "C" {
00132 #endif
00133 
00134 #define AST_MAX_EXTENSION  80 /*!< Max length of an extension */
00135 #define AST_MAX_CONTEXT    80 /*!< Max length of a context */
00136 #define AST_CHANNEL_NAME   80 /*!< Max length of an ast_channel name */
00137 #define MAX_LANGUAGE    20 /*!< Max length of the language setting */
00138 #define MAX_MUSICCLASS     80 /*!< Max length of the music class setting */
00139 
00140 #include "asterisk/frame.h"
00141 #include "asterisk/sched.h"
00142 #include "asterisk/chanvars.h"
00143 #include "asterisk/config.h"
00144 #include "asterisk/lock.h"
00145 #include "asterisk/cdr.h"
00146 #include "asterisk/utils.h"
00147 #include "asterisk/linkedlists.h"
00148 #include "asterisk/stringfields.h"
00149 #include "asterisk/datastore.h"
00150 
00151 #define DATASTORE_INHERIT_FOREVER   INT_MAX
00152 
00153 #define AST_MAX_FDS     10
00154 /*
00155  * We have AST_MAX_FDS file descriptors in a channel.
00156  * Some of them have a fixed use:
00157  */
00158 #define AST_ALERT_FD (AST_MAX_FDS-1)      /*!< used for alertpipe */
00159 #define AST_TIMING_FD   (AST_MAX_FDS-2)      /*!< used for timingfd */
00160 #define AST_AGENT_FD (AST_MAX_FDS-3)      /*!< used by agents for pass through */
00161 #define AST_GENERATOR_FD   (AST_MAX_FDS-4)   /*!< used by generator */
00162 
00163 enum ast_bridge_result {
00164    AST_BRIDGE_COMPLETE = 0,
00165    AST_BRIDGE_FAILED = -1,
00166    AST_BRIDGE_FAILED_NOWARN = -2,
00167    AST_BRIDGE_RETRY = -3,
00168 };
00169 
00170 typedef unsigned long long ast_group_t;
00171 
00172 /*! \todo Add an explanation of an Asterisk generator
00173 */
00174 struct ast_generator {
00175    void *(*alloc)(struct ast_channel *chan, void *params);
00176    void (*release)(struct ast_channel *chan, void *data);
00177    /*! This function gets called with the channel unlocked, but is called in
00178     *  the context of the channel thread so we know the channel is not going
00179     *  to disappear.  This callback is responsible for locking the channel as
00180     *  necessary. */
00181    int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
00182    /*! This gets called when DTMF_END frames are read from the channel */
00183    void (*digit)(struct ast_channel *chan, char digit);
00184 };
00185 
00186 /*! \brief Structure for all kinds of caller ID identifications.
00187  * \note All string fields here are malloc'ed, so they need to be
00188  * freed when the structure is deleted.
00189  * Also, NULL and "" must be considered equivalent.
00190  *
00191  * SIP and IAX2 has utf8 encoded Unicode caller ID names.
00192  * In some cases, we also have an alternative (RPID) E.164 number that can be used
00193  * as caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to pstn gateway).
00194  *
00195  * \todo Implement settings for transliteration between UTF8 caller ID names in
00196  *       to Ascii Caller ID's (DAHDI). Östen Åsklund might be transliterated into
00197  *  Osten Asklund or Oesten Aasklund depending upon language and person...
00198  *  We need automatic routines for incoming calls and static settings for
00199  *     our own accounts.
00200  */
00201 struct ast_callerid {
00202    char *cid_dnid;      /*!< Malloc'd Dialed Number Identifier */
00203    char *cid_num;    /*!< Malloc'd Caller Number */
00204    char *cid_name;      /*!< Malloc'd Caller Name (ASCII) */
00205    char *cid_ani;    /*!< Malloc'd ANI */
00206    char *cid_rdnis;  /*!< Malloc'd RDNIS */
00207    int cid_pres;     /*!< Callerid presentation/screening */
00208    int cid_ani2;     /*!< Callerid ANI 2 (Info digits) */
00209    int cid_ton;      /*!< Callerid Type of Number */
00210    int cid_tns;      /*!< Callerid Transit Network Select */
00211 };
00212 
00213 /*! \brief Typedef for a custom read function */
00214 typedef int (*ast_acf_read_fn_t)(struct ast_channel *, const char *, char *, char *, size_t);
00215 
00216 /*! \brief Typedef for a custom write function */
00217 typedef int (*ast_acf_write_fn_t)(struct ast_channel *, const char *, char *, const char *);
00218 
00219 /*! \brief Structure to handle passing func_channel_write info to channels via setoption */
00220 typedef struct {
00221    /*! \brief ast_chan_write_info_t version. Must be incremented if structure is changed */
00222    #define AST_CHAN_WRITE_INFO_T_VERSION 1
00223    uint32_t version;
00224    ast_acf_write_fn_t write_fn;
00225    struct ast_channel *chan;
00226    const char *function;
00227    char *data;
00228    const char *value;
00229 } ast_chan_write_info_t;
00230 
00231 /*! \brief
00232    Structure to describe a channel "technology", ie a channel driver
00233    See for examples:
00234    \arg chan_iax2.c - The Inter-Asterisk exchange protocol
00235    \arg chan_sip.c - The SIP channel driver
00236    \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
00237 
00238    If you develop your own channel driver, this is where you
00239    tell the PBX at registration of your driver what properties
00240    this driver supports and where different callbacks are
00241    implemented.
00242 */
00243 struct ast_channel_tech {
00244    const char * const type;
00245    const char * const description;
00246 
00247    int capabilities;    /*!< Bitmap of formats this channel can handle */
00248 
00249    int properties;         /*!< Technology Properties */
00250 
00251    /*! \brief Requester - to set up call data structures (pvt's) */
00252    struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
00253 
00254    int (* const devicestate)(void *data); /*!< Devicestate call back */
00255 
00256    /*!
00257     * \brief Start sending a literal DTMF digit
00258     *
00259     * \note The channel is not locked when this function gets called.
00260     */
00261    int (* const send_digit_begin)(struct ast_channel *chan, char digit);
00262 
00263    /*!
00264     * \brief Stop sending a literal DTMF digit
00265     *
00266     * \note The channel is not locked when this function gets called.
00267     */
00268    int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
00269 
00270    /*! \brief Call a given phone number (address, etc), but don't
00271       take longer than timeout seconds to do so.  */
00272    int (* const call)(struct ast_channel *chan, char *addr, int timeout);
00273 
00274    /*! \brief Hangup (and possibly destroy) the channel */
00275    int (* const hangup)(struct ast_channel *chan);
00276 
00277    /*! \brief Answer the channel */
00278    int (* const answer)(struct ast_channel *chan);
00279 
00280    /*! \brief Read a frame, in standard format (see frame.h) */
00281    struct ast_frame * (* const read)(struct ast_channel *chan);
00282 
00283    /*! \brief Write a frame, in standard format (see frame.h) */
00284    int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
00285 
00286    /*! \brief Display or transmit text */
00287    int (* const send_text)(struct ast_channel *chan, const char *text);
00288 
00289    /*! \brief Display or send an image */
00290    int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
00291 
00292    /*! \brief Send HTML data */
00293    int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
00294 
00295    /*! \brief Handle an exception, reading a frame */
00296    struct ast_frame * (* const exception)(struct ast_channel *chan);
00297 
00298    /*! \brief Bridge two channels of the same type together */
00299    enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
00300                   struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00301 
00302    /*! \brief Bridge two channels of the same type together (early) */
00303    enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
00304 
00305    /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
00306    int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
00307 
00308    /*! \brief Fix up a channel:  If a channel is consumed, this is called.  Basically update any ->owner links */
00309    int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
00310 
00311    /*! \brief Set a given option */
00312    int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
00313 
00314    /*! \brief Query a given option */
00315    int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
00316 
00317    /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
00318    int (* const transfer)(struct ast_channel *chan, const char *newdest);
00319 
00320    /*! \brief Write a frame, in standard format */
00321    int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
00322 
00323    /*! \brief Write a text frame, in standard format */
00324    int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
00325 
00326    /*! \brief Find bridged channel */
00327    struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
00328 
00329    /*! \brief Provide additional read items for CHANNEL() dialplan function */
00330    int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
00331 
00332    /*! \brief Provide additional write items for CHANNEL() dialplan function */
00333    int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
00334 
00335    /*! \brief Retrieve base channel (agent and local) */
00336    struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
00337 
00338    /*! \brief Set base channel (agent and local) */
00339    int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
00340 
00341    /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
00342    const char * (* get_pvt_uniqueid)(struct ast_channel *chan);
00343 };
00344 
00345 struct ast_epoll_data;
00346 
00347 /*!
00348  * The high bit of the frame count is used as a debug marker, so
00349  * increments of the counters must be done with care.
00350  * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
00351  */
00352 #define  DEBUGCHAN_FLAG  0x80000000
00353 
00354 /* XXX not ideal to evaluate x twice... */
00355 #define  FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
00356 
00357 /*!
00358  * The current value of the debug flags is stored in the two
00359  * variables global_fin and global_fout (declared in main/channel.c)
00360  */
00361 extern unsigned long global_fin, global_fout;
00362 
00363 enum ast_channel_adsicpe {
00364    AST_ADSI_UNKNOWN,
00365    AST_ADSI_AVAILABLE,
00366    AST_ADSI_UNAVAILABLE,
00367    AST_ADSI_OFFHOOKONLY,
00368 };
00369 
00370 /*!
00371  * \brief ast_channel states
00372  *
00373  * \note Bits 0-15 of state are reserved for the state (up/down) of the line
00374  *       Bits 16-32 of state are reserved for flags
00375  */
00376 enum ast_channel_state {
00377    AST_STATE_DOWN,         /*!< Channel is down and available */
00378    AST_STATE_RESERVED,     /*!< Channel is down, but reserved */
00379    AST_STATE_OFFHOOK,      /*!< Channel is off hook */
00380    AST_STATE_DIALING,      /*!< Digits (or equivalent) have been dialed */
00381    AST_STATE_RING,         /*!< Line is ringing */
00382    AST_STATE_RINGING,      /*!< Remote end is ringing */
00383    AST_STATE_UP,        /*!< Line is up */
00384    AST_STATE_BUSY,         /*!< Line is busy */
00385    AST_STATE_DIALING_OFFHOOK, /*!< Digits (or equivalent) have been dialed while offhook */
00386    AST_STATE_PRERING,      /*!< Channel has detected an incoming call and is waiting for ring */
00387 
00388    AST_STATE_MUTE = (1 << 16),   /*!< Do not transmit voice data */
00389 };
00390 
00391 /*!
00392  * \brief Possible T38 states on channels
00393  */
00394 enum ast_t38_state {
00395    T38_STATE_UNAVAILABLE,  /*!< T38 is unavailable on this channel or disabled by configuration */
00396    T38_STATE_UNKNOWN,   /*!< The channel supports T38 but the current status is unknown */
00397    T38_STATE_NEGOTIATING,  /*!< T38 is being negotiated */
00398    T38_STATE_REJECTED,  /*!< Remote side has rejected our offer */
00399    T38_STATE_NEGOTIATED,   /*!< T38 established */
00400 };
00401 
00402 /*! \brief Main Channel structure associated with a channel.
00403  * This is the side of it mostly used by the pbx and call management.
00404  *
00405  * \note XXX It is important to remember to increment .cleancount each time
00406  *       this structure is changed. XXX
00407  *
00408  * \note When adding fields to this structure, it is important to add the field
00409  *       'in position' with like-aligned fields, so as to keep the compiler from
00410  *       having to add padding to align fields. The structure's fields are sorted
00411  *       in this order: pointers, structures, long, int/enum, short, char. This
00412  *       is especially important on 64-bit architectures, where mixing 4-byte
00413  *       and 8-byte fields causes 4 bytes of padding to be added before many
00414  *       8-byte fields.
00415  */
00416 
00417 struct ast_channel {
00418    const struct ast_channel_tech *tech;      /*!< Technology (point to channel driver) */
00419    void *tech_pvt;               /*!< Private data used by the technology driver */
00420    void *music_state;            /*!< Music State*/
00421    void *generatordata;          /*!< Current generator data if there is any */
00422    struct ast_generator *generator;    /*!< Current active data generator */
00423    struct ast_channel *_bridge;        /*!< Who are we bridged to, if we're bridged.
00424                           Who is proxying for us, if we are proxied (i.e. chan_agent).
00425                           Do not access directly, use ast_bridged_channel(chan) */
00426    struct ast_channel *masq;        /*!< Channel that will masquerade as us */
00427    struct ast_channel *masqr;       /*!< Who we are masquerading as */
00428    const char *blockproc;           /*!< Procedure causing blocking */
00429    const char *appl;          /*!< Current application */
00430    const char *data;          /*!< Data passed to current application */
00431    struct sched_context *sched;        /*!< Schedule context */
00432    struct ast_filestream *stream;         /*!< Stream itself. */
00433    struct ast_filestream *vstream;        /*!< Video Stream itself. */
00434    int (*timingfunc)(const void *data);
00435    void *timingdata;
00436    struct ast_pbx *pbx;          /*!< PBX private structure for this channel */
00437    struct ast_trans_pvt *writetrans;      /*!< Write translation path */
00438    struct ast_trans_pvt *readtrans;    /*!< Read translation path */
00439    struct ast_audiohook_list *audiohooks;
00440    struct ast_cdr *cdr;          /*!< Call Detail Record */
00441    struct ast_tone_zone *zone;         /*!< Tone zone as set in indications.conf or
00442                           in the CHANNEL dialplan function */
00443    struct ast_channel_monitor *monitor;      /*!< Channel monitoring */
00444 #ifdef HAVE_EPOLL
00445    struct ast_epoll_data *epfd_data[AST_MAX_FDS];
00446 #endif
00447 
00448    AST_DECLARE_STRING_FIELDS(
00449       AST_STRING_FIELD(name);       /*!< ASCII unique channel name */
00450       AST_STRING_FIELD(language);      /*!< Language requested for voice prompts */
00451       AST_STRING_FIELD(musicclass);    /*!< Default music class */
00452       AST_STRING_FIELD(accountcode);      /*!< Account code for billing */
00453       AST_STRING_FIELD(call_forward);     /*!< Where to forward to if asked to dial on this interface */
00454       AST_STRING_FIELD(uniqueid);      /*!< Unique Channel Identifier */
00455       AST_STRING_FIELD(parkinglot);    /*! Default parking lot, if empty, default parking lot  */
00456       AST_STRING_FIELD(dialcontext);      /*!< Dial: Extension context that we were called from */
00457    );
00458 
00459    struct timeval whentohangup;              /*!< Non-zero, set to actual time when channel is to be hung up */
00460    pthread_t blocker;            /*!< If anyone is blocking, this is them */
00461    ast_mutex_t lock_dont_use;       /*!< Lock a channel for some operations. See ast_channel_lock() */
00462    struct ast_callerid cid;         /*!< Caller ID, name, presentation etc */
00463    struct ast_frame dtmff;          /*!< DTMF frame */
00464    struct varshead varshead;        /*!< A linked list for channel variables. See \ref AstChanVar */
00465    ast_group_t callgroup;           /*!< Call group for call pickups */
00466    ast_group_t pickupgroup;         /*!< Pickup group - which calls groups can be picked up? */
00467    AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
00468    AST_LIST_ENTRY(ast_channel) chan_list;    /*!< For easy linking */
00469    struct ast_jb jb;          /*!< The jitterbuffer state */
00470    struct timeval dtmf_tv;          /*!< The time that an in process digit began, or the last digit ended */
00471    AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; /*!< Data stores on the channel */
00472 
00473    unsigned long insmpl;            /*!< Track the read/written samples for monitor use */
00474    unsigned long outsmpl;           /*!< Track the read/written samples for monitor use */
00475 
00476    int fds[AST_MAX_FDS];            /*!< File descriptors for channel -- Drivers will poll on
00477                           these file descriptors, so at least one must be non -1.
00478                           See \arg \ref AstFileDesc */
00479    int cdrflags;              /*!< Call Detail Record Flags */
00480    int _softhangup;           /*!< Whether or not we have been hung up...  Do not set this value
00481                           directly, use ast_softhangup() */
00482    int fdno;               /*!< Which fd had an event detected on */
00483    int streamid;              /*!< For streaming playback, the schedule ID */
00484    int vstreamid;             /*!< For streaming video playback, the schedule ID */
00485    int oldwriteformat;           /*!< Original writer format */
00486    int timingfd;              /*!< Timing fd */
00487    enum ast_channel_state _state;         /*!< State of line -- Don't write directly, use ast_setstate() */
00488    int rings;              /*!< Number of rings so far */
00489    int priority;              /*!< Dialplan: Current extension priority */
00490    int macropriority;            /*!< Macro: Current non-macro priority. See app_macro.c */
00491    int amaflags;              /*!< Set BEFORE PBX is started to determine AMA flags */
00492    enum ast_channel_adsicpe adsicpe;      /*!< Whether or not ADSI is detected on CPE */
00493    unsigned int fin;          /*!< Frames in counters. The high bit is a debug mask, so
00494                           the counter is only in the remaining bits */
00495    unsigned int fout;            /*!< Frames out counters. The high bit is a debug mask, so
00496                           the counter is only in the remaining bits */
00497    int hangupcause;           /*!< Why is the channel hanged up. See causes.h */
00498    unsigned int flags;           /*!< channel flags of AST_FLAG_ type */
00499    int alertpipe[2];
00500    int nativeformats;            /*!< Kinds of data this channel can natively handle */
00501    int readformat;               /*!< Requested read format */
00502    int writeformat;           /*!< Requested write format */
00503    int rawreadformat;            /*!< Raw read format */
00504    int rawwriteformat;           /*!< Raw write format */
00505    unsigned int emulate_dtmf_duration;    /*!< Number of ms left to emulate DTMF for */
00506 #ifdef HAVE_EPOLL
00507    int epfd;
00508 #endif
00509    int visible_indication;                         /*!< Indication currently playing on the channel */
00510 
00511    unsigned short transfercapability;     /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
00512 
00513    union {
00514       char unused_old_dtmfq[AST_MAX_EXTENSION];       /*!< (deprecated, use readq instead) Any/all queued DTMF characters */
00515       struct {
00516          struct ast_bridge *bridge;                                      /*!< Bridge this channel is participating in */
00517          struct ast_timer *timer;               /*!< timer object that provided timingfd */
00518       };
00519    };
00520 
00521    char context[AST_MAX_CONTEXT];         /*!< Dialplan: Current extension context */
00522    char exten[AST_MAX_EXTENSION];         /*!< Dialplan: Current extension number */
00523    char macrocontext[AST_MAX_CONTEXT];    /*!< Macro: Current non-macro context. See app_macro.c */
00524    char macroexten[AST_MAX_EXTENSION];    /*!< Macro: Current non-macro extension. See app_macro.c */
00525    char emulate_dtmf_digit;         /*!< Digit being emulated */
00526 };
00527 
00528 /*! \brief ast_channel_tech Properties */
00529 enum {
00530    /*! \brief Channels have this property if they can accept input with jitter;
00531     *         i.e. most VoIP channels */
00532    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00533    /*! \brief Channels have this property if they can create jitter;
00534     *         i.e. most VoIP channels */
00535    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00536 };
00537 
00538 /*! \brief ast_channel flags */
00539 enum {
00540    /*! Queue incoming dtmf, to be released when this flag is turned off */
00541    AST_FLAG_DEFER_DTMF =    (1 << 1),
00542    /*! write should be interrupt generator */
00543    AST_FLAG_WRITE_INT =     (1 << 2),
00544    /*! a thread is blocking on this channel */
00545    AST_FLAG_BLOCKING =      (1 << 3),
00546    /*! This is a zombie channel */
00547    AST_FLAG_ZOMBIE =        (1 << 4),
00548    /*! There is an exception pending */
00549    AST_FLAG_EXCEPTION =     (1 << 5),
00550    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00551    AST_FLAG_MOH =           (1 << 6),
00552    /*! This channel is spying on another channel */
00553    AST_FLAG_SPYING =        (1 << 7),
00554    /*! This channel is in a native bridge */
00555    AST_FLAG_NBRIDGE =       (1 << 8),
00556    /*! the channel is in an auto-incrementing dialplan processor,
00557     *  so when ->priority is set, it will get incremented before
00558     *  finding the next priority to run */
00559    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00560    /*! This is an outgoing call */
00561    AST_FLAG_OUTGOING =      (1 << 10),
00562    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00563    AST_FLAG_IN_DTMF =       (1 << 12),
00564    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
00565     *  currently being emulated */
00566    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00567    /*! This is set to tell the channel not to generate DTMF begin frames, and
00568     *  to instead only generate END frames. */
00569    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00570    /*! Flag to show channels that this call is hangup due to the fact that the call
00571        was indeed anwered, but in another channel */
00572    AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
00573    /*! This flag indicates that on a masquerade, an active stream should not
00574     *  be carried over */
00575    AST_FLAG_MASQ_NOSTREAM = (1 << 16),
00576    /*! This flag indicates that the hangup exten was run when the bridge terminated,
00577     *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
00578     *  level */
00579    AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
00580    /*! This flag indicates that the hangup exten should NOT be run when the
00581     *  bridge terminates, this will allow the hangup in the pbx loop to be run instead.
00582     *  */
00583    AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18),
00584    /*! This flag indicates whether the channel is in the channel list or not. */
00585    AST_FLAG_IN_CHANNEL_LIST = (1 << 19),
00586    /*! Disable certain workarounds.  This reintroduces certain bugs, but allows
00587     *  some non-traditional dialplans (like AGI) to continue to function.
00588     */
00589    AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
00590 };
00591 
00592 /*! \brief ast_bridge_config flags */
00593 enum {
00594    AST_FEATURE_PLAY_WARNING = (1 << 0),
00595    AST_FEATURE_REDIRECT =     (1 << 1),
00596    AST_FEATURE_DISCONNECT =   (1 << 2),
00597    AST_FEATURE_ATXFER =       (1 << 3),
00598    AST_FEATURE_AUTOMON =      (1 << 4),
00599    AST_FEATURE_PARKCALL =     (1 << 5),
00600    AST_FEATURE_AUTOMIXMON =   (1 << 6),
00601    AST_FEATURE_NO_H_EXTEN =   (1 << 7),
00602    AST_FEATURE_WARNING_ACTIVE = (1 << 8),
00603 };
00604 
00605 /*! \brief bridge configuration */
00606 struct ast_bridge_config {
00607    struct ast_flags features_caller;
00608    struct ast_flags features_callee;
00609    struct timeval start_time;
00610    struct timeval nexteventts;
00611    struct timeval partialfeature_timer;
00612    long feature_timer;
00613    long timelimit;
00614    long play_warning;
00615    long warning_freq;
00616    const char *warning_sound;
00617    const char *end_sound;
00618    const char *start_sound;
00619    int firstpass;
00620    unsigned int flags;
00621    void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
00622    void *end_bridge_callback_data;         /*!< Data passed to the callback */
00623    /*! If the end_bridge_callback_data refers to a channel which no longer is going to
00624     * exist when the end_bridge_callback is called, then it needs to be fixed up properly
00625     */
00626    void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
00627 };
00628 
00629 struct chanmon;
00630 
00631 struct outgoing_helper {
00632    const char *context;
00633    const char *exten;
00634    int priority;
00635    const char *cid_num;
00636    const char *cid_name;
00637    const char *account;
00638    struct ast_variable *vars;
00639    struct ast_channel *parent_channel;
00640 };
00641 
00642 enum {
00643    AST_CDR_TRANSFER =   (1 << 0),
00644    AST_CDR_FORWARD =    (1 << 1),
00645    AST_CDR_CALLWAIT =   (1 << 2),
00646    AST_CDR_CONFERENCE = (1 << 3),
00647 };
00648 
00649 enum {
00650    /*!
00651     * Soft hangup requested by device or other internal reason.
00652     * Actual hangup needed.
00653     */
00654    AST_SOFTHANGUP_DEV =       (1 << 0),
00655    /*!
00656     * Used to break the normal frame flow so an async goto can be
00657     * done instead of actually hanging up.
00658     */
00659    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00660    /*!
00661     * Soft hangup requested by system shutdown.  Actual hangup
00662     * needed.
00663     */
00664    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00665    /*!
00666     * Used to break the normal frame flow after a timeout so an
00667     * implicit async goto can be done to the 'T' exten if it exists
00668     * instead of actually hanging up.  If the exten does not exist
00669     * then actually hangup.
00670     */
00671    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00672    /*!
00673     * Soft hangup requested by application/channel-driver being
00674     * unloaded.  Actual hangup needed.
00675     */
00676    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00677    /*!
00678     * Soft hangup requested by non-associated party.  Actual hangup
00679     * needed.
00680     */
00681    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00682    /*!
00683     * Used to break a bridge so the channel can be spied upon
00684     * instead of actually hanging up.
00685     */
00686    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00687 };
00688 
00689 
00690 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
00691 enum channelreloadreason {
00692    CHANNEL_MODULE_LOAD,
00693    CHANNEL_MODULE_RELOAD,
00694    CHANNEL_CLI_RELOAD,
00695    CHANNEL_MANAGER_RELOAD,
00696 };
00697 
00698 /*!
00699  * \note None of the datastore API calls lock the ast_channel they are using.
00700  *       So, the channel should be locked before calling the functions that
00701  *       take a channel argument.
00702  */
00703 
00704 /*!
00705  * \brief Create a channel data store object
00706  * \deprecated You should use the ast_datastore_alloc() generic function instead.
00707  * \version 1.6.1 deprecated
00708  */
00709 struct ast_datastore * attribute_malloc ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
00710    __attribute__((deprecated));
00711 
00712 /*!
00713  * \brief Free a channel data store object
00714  * \deprecated You should use the ast_datastore_free() generic function instead.
00715  * \version 1.6.1 deprecated
00716  */
00717 int ast_channel_datastore_free(struct ast_datastore *datastore)
00718    __attribute__((deprecated));
00719 
00720 /*! \brief Inherit datastores from a parent to a child. */
00721 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
00722 
00723 /*!
00724  * \brief Add a datastore to a channel
00725  *
00726  * \note The channel should be locked before calling this function.
00727  *
00728  * \retval 0 success
00729  * \retval non-zero failure
00730  */
00731 
00732 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
00733 
00734 /*!
00735  * \brief Remove a datastore from a channel
00736  *
00737  * \note The channel should be locked before calling this function.
00738  *
00739  * \retval 0 success
00740  * \retval non-zero failure
00741  */
00742 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
00743 
00744 /*!
00745  * \brief Find a datastore on a channel
00746  *
00747  * \note The channel should be locked before calling this function.
00748  *
00749  * \note The datastore returned from this function must not be used if the
00750  *       reference to the channel is released.
00751  *
00752  * \retval pointer to the datastore if found
00753  * \retval NULL if not found
00754  */
00755 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
00756 
00757 /*! \brief Change the state of a channel */
00758 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
00759 
00760 /*!
00761  * \brief Create a channel structure
00762  *
00763  * \retval NULL failure
00764  * \retval non-NULL successfully allocated channel
00765  *
00766  * \note By default, new channels are set to the "s" extension
00767  *       and "default" context.
00768  */
00769 struct ast_channel * attribute_malloc __attribute__((format(printf, 12, 13)))
00770    __ast_channel_alloc(int needqueue, int state, const char *cid_num,
00771              const char *cid_name, const char *acctcode,
00772              const char *exten, const char *context,
00773              const int amaflag, const char *file, int line,
00774              const char *function, const char *name_fmt, ...);
00775 
00776 #define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, amaflag, ...) \
00777    __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, amaflag, \
00778              __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
00779 
00780 /*!
00781  * \brief Queue one or more frames to a channel's frame queue
00782  *
00783  * \param chan the channel to queue the frame(s) on
00784  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
00785  *        by this function.  It is the responsibility of the caller to handle
00786  *        freeing the memory associated with the frame(s) being passed if
00787  *        necessary.
00788  *
00789  * \retval 0 success
00790  * \retval non-zero failure
00791  */
00792 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
00793 
00794 /*!
00795  * \brief Queue one or more frames to the head of a channel's frame queue
00796  *
00797  * \param chan the channel to queue the frame(s) on
00798  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
00799  *        by this function.  It is the responsibility of the caller to handle
00800  *        freeing the memory associated with the frame(s) being passed if
00801  *        necessary.
00802  *
00803  * \retval 0 success
00804  * \retval non-zero failure
00805  */
00806 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
00807 
00808 /*!
00809  * \brief Queue a hangup frame
00810  *
00811  * \note The channel does not need to be locked before calling this function.
00812  */
00813 int ast_queue_hangup(struct ast_channel *chan);
00814 
00815 /*!
00816  * \brief Queue a hangup frame with hangupcause set
00817  *
00818  * \note The channel does not need to be locked before calling this function.
00819  * \param[in] chan channel to queue frame onto
00820  * \param[in] cause the hangup cause
00821  * \return 0 on success, -1 on error
00822  * \since 1.6.1
00823  */
00824 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
00825 
00826 /*!
00827  * \brief Queue a control frame with payload
00828  *
00829  * \param chan channel to queue frame onto
00830  * \param control type of control frame
00831  *
00832  * \note The channel does not need to be locked before calling this function.
00833  *
00834  * \retval zero on success
00835  * \retval non-zero on failure
00836  */
00837 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
00838 
00839 /*!
00840  * \brief Queue a control frame with payload
00841  *
00842  * \param chan channel to queue frame onto
00843  * \param control type of control frame
00844  * \param data pointer to payload data to be included in frame
00845  * \param datalen number of bytes of payload data
00846  *
00847  * \retval 0 success
00848  * \retval non-zero failure
00849  *
00850  * The supplied payload data is copied into the frame, so the caller's copy
00851  * is not modified nor freed, and the resulting frame will retain a copy of
00852  * the data even if the caller frees their local copy.
00853  *
00854  * \note This method should be treated as a 'network transport'; in other
00855  * words, your frames may be transferred across an IAX2 channel to another
00856  * system, which may be a different endianness than yours. Because of this,
00857  * you should ensure that either your frames will never be expected to work
00858  * across systems, or that you always put your payload data into 'network byte
00859  * order' before calling this function.
00860  *
00861  * \note The channel does not need to be locked before calling this function.
00862  */
00863 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
00864             const void *data, size_t datalen);
00865 
00866 /*!
00867  * \brief Change channel name
00868  *
00869  * \note The channel must be locked before calling this function.
00870  */
00871 void ast_change_name(struct ast_channel *chan, char *newname);
00872 
00873 /*! \brief Free a channel structure */
00874 void  ast_channel_free(struct ast_channel *);
00875 
00876 /*!
00877  * \brief Requests a channel
00878  *
00879  * \param type type of channel to request
00880  * \param format requested channel format (codec)
00881  * \param data data to pass to the channel requester
00882  * \param status status
00883  *
00884  * Request a channel of a given type, with data as optional information used
00885  * by the low level module
00886  *
00887  * \retval NULL failure
00888  * \retval non-NULL channel on success
00889  */
00890 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
00891 
00892 /*!
00893  * \brief Request a channel of a given type, with data as optional information used
00894  *        by the low level module and attempt to place a call on it
00895  *
00896  * \param type type of channel to request
00897  * \param format requested channel format
00898  * \param data data to pass to the channel requester
00899  * \param timeout maximum amount of time to wait for an answer
00900  * \param reason why unsuccessful (if unsuccessful)
00901  * \param cid_num Caller-ID Number
00902  * \param cid_name Caller-ID Name (ascii)
00903  *
00904  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00905  * to know if the call was answered or not.
00906  */
00907 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data,
00908    int timeout, int *reason, const char *cid_num, const char *cid_name);
00909 
00910 /*!
00911  * \brief Request a channel of a given type, with data as optional information used
00912  * by the low level module and attempt to place a call on it
00913  * \param type type of channel to request
00914  * \param format requested channel format
00915  * \param data data to pass to the channel requester
00916  * \param timeout maximum amount of time to wait for an answer
00917  * \param reason why unsuccessful (if unsuccessful)
00918  * \param cid_num Caller-ID Number
00919  * \param cid_name Caller-ID Name (ascii)
00920  * \param oh Outgoing helper
00921  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00922  * to know if the call was answered or not.
00923  */
00924 struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data,
00925    int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
00926 /*!
00927 * \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.
00928 * \param caller in channel that requested orig
00929 * \param orig channel being replaced by the call forward channel
00930 * \param timeout maximum amount of time to wait for setup of new forward channel
00931 * \param format requested channel format
00932 * \param oh outgoing helper used with original channel
00933 * \param outstate reason why unsuccessful (if uncuccessful)
00934 * \return Returns the forwarded call's ast_channel on success or NULL on failure
00935 */
00936 struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, int format, struct outgoing_helper *oh, int *outstate);
00937 
00938 /*!\brief Register a channel technology (a new channel driver)
00939  * Called by a channel module to register the kind of channels it supports.
00940  * \param tech Structure defining channel technology or "type"
00941  * \return Returns 0 on success, -1 on failure.
00942  */
00943 int ast_channel_register(const struct ast_channel_tech *tech);
00944 
00945 /*! \brief Unregister a channel technology
00946  * \param tech Structure defining channel technology or "type" that was previously registered
00947  * \return No return value.
00948  */
00949 void ast_channel_unregister(const struct ast_channel_tech *tech);
00950 
00951 /*! \brief Get a channel technology structure by name
00952  * \param name name of technology to find
00953  * \return a pointer to the structure, or NULL if no matching technology found
00954  */
00955 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
00956 
00957 #ifdef CHANNEL_TRACE
00958 /*! \brief Update the context backtrace if tracing is enabled
00959  * \return Returns 0 on success, -1 on failure
00960  */
00961 int ast_channel_trace_update(struct ast_channel *chan);
00962 
00963 /*! \brief Enable context tracing in the channel
00964  * \return Returns 0 on success, -1 on failure
00965  */
00966 int ast_channel_trace_enable(struct ast_channel *chan);
00967 
00968 /*! \brief Disable context tracing in the channel.
00969  * \note Does not remove current trace entries
00970  * \return Returns 0 on success, -1 on failure
00971  */
00972 int ast_channel_trace_disable(struct ast_channel *chan);
00973 
00974 /*! \brief Whether or not context tracing is enabled
00975  * \return Returns -1 when the trace is enabled. 0 if not.
00976  */
00977 int ast_channel_trace_is_enabled(struct ast_channel *chan);
00978 
00979 /*! \brief Put the channel backtrace in a string
00980  * \return Returns the amount of lines in the backtrace. -1 on error.
00981  */
00982 int ast_channel_trace_serialize(struct ast_channel *chan, struct ast_str **out);
00983 #endif
00984 
00985 /*! \brief Hang up a channel
00986  * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
00987  * performs all stream stopping, etc, on the channel that needs to end.
00988  * chan is no longer valid after this call.
00989  * \param chan channel to hang up
00990  * \return Returns 0 on success, -1 on failure.
00991  */
00992 int ast_hangup(struct ast_channel *chan);
00993 
00994 /*!
00995  * \brief Softly hangup up a channel
00996  *
00997  * \param chan channel to be soft-hung-up
00998  * \param reason an AST_SOFTHANGUP_* reason code
00999  *
01000  * Call the protocol layer, but don't destroy the channel structure
01001  * (use this if you are trying to
01002  * safely hangup a channel managed by another thread.
01003  *
01004  * \note The channel passed to this function does not need to be locked.
01005  *
01006  * \return Returns 0 regardless
01007  */
01008 int ast_softhangup(struct ast_channel *chan, int reason);
01009 
01010 /*! \brief Softly hangup up a channel (no channel lock)
01011  * \param chan channel to be soft-hung-up
01012  * \param reason an AST_SOFTHANGUP_* reason code
01013  */
01014 int ast_softhangup_nolock(struct ast_channel *chan, int reason);
01015 
01016 /*! \brief Check to see if a channel is needing hang up
01017  * \param chan channel on which to check for hang up
01018  * This function determines if the channel is being requested to be hung up.
01019  * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
01020  */
01021 int ast_check_hangup(struct ast_channel *chan);
01022 
01023 /*!
01024  * \brief Compare a offset with the settings of when to hang a channel up
01025  * \param chan channel on which to check for hang up
01026  * \param offset offset in seconds from current time
01027  * \return 1, 0, or -1
01028  * This function compares a offset from current time with the absolute time
01029  * out on a channel (when to hang up). If the absolute time out on a channel
01030  * is earlier than current time plus the offset, it returns 1, if the two
01031  * time values are equal, it return 0, otherwise, it return -1.
01032  * \sa ast_channel_cmpwhentohangup_tv()
01033  * \version 1.6.1 deprecated function (only had seconds precision)
01034  */
01035 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
01036 
01037 /*!
01038  * \brief Compare a offset with the settings of when to hang a channel up
01039  * \param chan channel on which to check for hangup
01040  * \param offset offset in seconds and microseconds from current time
01041  * \return 1, 0, or -1
01042  * This function compares a offset from current time with the absolute time
01043  * out on a channel (when to hang up). If the absolute time out on a channel
01044  * is earlier than current time plus the offset, it returns 1, if the two
01045  * time values are equal, it return 0, otherwise, it return -1.
01046  * \since 1.6.1
01047  */
01048 int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
01049 
01050 /*! \brief Set when to hang a channel up
01051  *
01052  * \param chan channel on which to check for hang up
01053  * \param offset offset in seconds relative to the current time of when to hang up
01054  *
01055  * This function sets the absolute time out on a channel (when to hang up).
01056  *
01057  * \note This function does not require that the channel is locked before
01058  *       calling it.
01059  *
01060  * \return Nothing
01061  * \sa ast_channel_setwhentohangup_tv()
01062  * \version 1.6.1 deprecated function (only had seconds precision)
01063  */
01064 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
01065 
01066 /*! \brief Set when to hang a channel up
01067  *
01068  * \param chan channel on which to check for hang up
01069  * \param offset offset in seconds and useconds relative to the current time of when to hang up
01070  *
01071  * This function sets the absolute time out on a channel (when to hang up).
01072  *
01073  * \note This function does not require that the channel is locked before
01074  * calling it.
01075  *
01076  * \return Nothing
01077  * \since 1.6.1
01078  */
01079 void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
01080 
01081 /*!
01082  * \brief Answer a channel
01083  *
01084  * \param chan channel to answer
01085  *
01086  * This function answers a channel and handles all necessary call
01087  * setup functions.
01088  *
01089  * \note The channel passed does not need to be locked, but is locked
01090  * by the function when needed.
01091  *
01092  * \note This function will wait up to 500 milliseconds for media to
01093  * arrive on the channel before returning to the caller, so that the
01094  * caller can properly assume the channel is 'ready' for media flow.
01095  *
01096  * \retval 0 on success
01097  * \retval non-zero on failure
01098  */
01099 int ast_answer(struct ast_channel *chan);
01100 
01101 /*!
01102  * \brief Answer a channel
01103  *
01104  * \param chan channel to answer
01105  * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
01106  *
01107  * This function answers a channel and handles all necessary call
01108  * setup functions.
01109  *
01110  * \note The channel passed does not need to be locked, but is locked
01111  * by the function when needed.
01112  *
01113  * \note Unlike ast_answer(), this function will not wait for media
01114  * flow to begin. The caller should be careful before sending media
01115  * to the channel before incoming media arrives, as the outgoing
01116  * media may be lost.
01117  *
01118  * \retval 0 on success
01119  * \retval non-zero on failure
01120  */
01121 int ast_raw_answer(struct ast_channel *chan, int cdr_answer);
01122 
01123 /*!
01124  * \brief Answer a channel, with a selectable delay before returning
01125  *
01126  * \param chan channel to answer
01127  * \param delay maximum amount of time to wait for incoming media
01128  * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
01129  *
01130  * This function answers a channel and handles all necessary call
01131  * setup functions.
01132  *
01133  * \note The channel passed does not need to be locked, but is locked
01134  * by the function when needed.
01135  *
01136  * \note This function will wait up to 'delay' milliseconds for media to
01137  * arrive on the channel before returning to the caller, so that the
01138  * caller can properly assume the channel is 'ready' for media flow. If
01139  * 'delay' is less than 500, the function will wait up to 500 milliseconds.
01140  *
01141  * \retval 0 on success
01142  * \retval non-zero on failure
01143  */
01144 int __ast_answer(struct ast_channel *chan, unsigned int delay, int cdr_answer);
01145 
01146 /*! \brief Make a call
01147  * \param chan which channel to make the call on
01148  * \param addr destination of the call
01149  * \param timeout time to wait on for connect
01150  * Place a call, take no longer than timeout ms.
01151    \return Returns -1 on failure, 0 on not enough time
01152    (does not automatically stop ringing), and
01153    the number of seconds the connect took otherwise.
01154    */
01155 int ast_call(struct ast_channel *chan, char *addr, int timeout);
01156 
01157 /*! \brief Indicates condition of channel
01158  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
01159  * \param chan channel to change the indication
01160  * \param condition which condition to indicate on the channel
01161  * \return Returns 0 on success, -1 on failure
01162  */
01163 int ast_indicate(struct ast_channel *chan, int condition);
01164 
01165 /*! \brief Indicates condition of channel, with payload
01166  * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
01167  * \param chan channel to change the indication
01168  * \param condition which condition to indicate on the channel
01169  * \param data pointer to payload data
01170  * \param datalen size of payload data
01171  * \return Returns 0 on success, -1 on failure
01172  */
01173 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
01174 
01175 /* Misc stuff ------------------------------------------------ */
01176 
01177 /*! \brief Wait for input on a channel
01178  * \param chan channel to wait on
01179  * \param ms length of time to wait on the channel
01180  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
01181   \return Returns < 0 on  failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
01182 int ast_waitfor(struct ast_channel *chan, int ms);
01183 
01184 /*!
01185  * \brief Should we keep this frame for later?
01186  *
01187  * There are functions such as ast_safe_sleep which will
01188  * service a channel to ensure that it does not have a
01189  * large backlog of queued frames. When this happens,
01190  * we want to hold on to specific frame types and just drop
01191  * others. This function will tell if the frame we just
01192  * read should be held onto.
01193  *
01194  * \param frame The frame we just read
01195  * \retval 1 frame should be kept
01196  * \retval 0 frame should be dropped
01197  */
01198 int ast_is_deferrable_frame(const struct ast_frame *frame);
01199 
01200 /*!
01201  * \brief Wait for a specified amount of time, looking for hangups
01202  * \param chan channel to wait for
01203  * \param ms length of time in milliseconds to sleep
01204  * Waits for a specified amount of time, servicing the channel as required.
01205  * \return returns -1 on hangup, otherwise 0.
01206  */
01207 int ast_safe_sleep(struct ast_channel *chan, int ms);
01208 
01209 /*! \brief Wait for a specified amount of time, looking for hangups and a condition argument
01210  * \param chan channel to wait for
01211  * \param ms length of time in milliseconds to sleep
01212  * \param cond a function pointer for testing continue condition
01213  * \param data argument to be passed to the condition test function
01214  * \return returns -1 on hangup, otherwise 0.
01215  * Waits for a specified amount of time, servicing the channel as required. If cond
01216  * returns 0, this function returns.
01217  */
01218 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
01219 
01220 /*! \brief Waits for activity on a group of channels
01221  * \param chan an array of pointers to channels
01222  * \param n number of channels that are to be waited upon
01223  * \param fds an array of fds to wait upon
01224  * \param nfds the number of fds to wait upon
01225  * \param exception exception flag
01226  * \param outfd fd that had activity on it
01227  * \param ms how long the wait was
01228  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
01229    file descriptors.
01230    \return Returns the channel with activity, or NULL on error or if an FD
01231    came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
01232    will be -1 */
01233 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
01234    int *fds, int nfds, int *exception, int *outfd, int *ms);
01235 
01236 /*! \brief Waits for input on a group of channels
01237    Wait for input on an array of channels for a given # of milliseconds.
01238    \return Return channel with activity, or NULL if none has activity.
01239    \param chan an array of pointers to channels
01240    \param n number of channels that are to be waited upon
01241    \param ms time "ms" is modified in-place, if applicable */
01242 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
01243 
01244 /*! \brief Waits for input on an fd
01245    This version works on fd's only.  Be careful with it. */
01246 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
01247 
01248 
01249 /*! \brief Reads a frame
01250  * \param chan channel to read a frame from
01251  * \return Returns a frame, or NULL on error.  If it returns NULL, you
01252    best just stop reading frames and assume the channel has been
01253    disconnected. */
01254 struct ast_frame *ast_read(struct ast_channel *chan);
01255 
01256 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
01257    \param chan channel to read a frame from
01258    \return  Returns a frame, or NULL on error.  If it returns NULL, you
01259       best just stop reading frames and assume the channel has been
01260       disconnected.
01261    \note Audio is replaced with AST_FRAME_NULL to avoid
01262    transcode when the resulting audio is not necessary. */
01263 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
01264 
01265 /*! \brief Write a frame to a channel
01266  * This function writes the given frame to the indicated channel.
01267  * \param chan destination channel of the frame
01268  * \param frame frame that will be written
01269  * \return It returns 0 on success, -1 on failure.
01270  */
01271 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
01272 
01273 /*! \brief Write video frame to a channel
01274  * This function writes the given frame to the indicated channel.
01275  * \param chan destination channel of the frame
01276  * \param frame frame that will be written
01277  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
01278  */
01279 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
01280 
01281 /*! \brief Write text frame to a channel
01282  * This function writes the given frame to the indicated channel.
01283  * \param chan destination channel of the frame
01284  * \param frame frame that will be written
01285  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
01286  */
01287 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
01288 
01289 /*! \brief Send empty audio to prime a channel driver */
01290 int ast_prod(struct ast_channel *chan);
01291 
01292 /*! \brief Sets read format on channel chan
01293  * Set read format for channel to whichever component of "format" is best.
01294  * \param chan channel to change
01295  * \param format format to change to
01296  * \return Returns 0 on success, -1 on failure
01297  */
01298 int ast_set_read_format(struct ast_channel *chan, int format);
01299 
01300 /*! \brief Sets write format on channel chan
01301  * Set write format for channel to whichever component of "format" is best.
01302  * \param chan channel to change
01303  * \param format new format for writing
01304  * \return Returns 0 on success, -1 on failure
01305  */
01306 int ast_set_write_format(struct ast_channel *chan, int format);
01307 
01308 /*!
01309  * \brief Sends text to a channel
01310  *
01311  * \param chan channel to act upon
01312  * \param text string of text to send on the channel
01313  *
01314  * Write text to a display on a channel
01315  *
01316  * \note The channel does not need to be locked before calling this function.
01317  *
01318  * \retval 0 on success
01319  * \retval -1 on failure
01320  */
01321 int ast_sendtext(struct ast_channel *chan, const char *text);
01322 
01323 /*! \brief Receives a text character from a channel
01324  * \param chan channel to act upon
01325  * \param timeout timeout in milliseconds (0 for infinite wait)
01326  * Read a char of text from a channel
01327  * Returns 0 on success, -1 on failure
01328  */
01329 int ast_recvchar(struct ast_channel *chan, int timeout);
01330 
01331 /*! \brief Send a DTMF digit to a channel
01332  * Send a DTMF digit to a channel.
01333  * \param chan channel to act upon
01334  * \param digit the DTMF digit to send, encoded in ASCII
01335  * \param duration the duration of the digit ending in ms
01336  * \return Returns 0 on success, -1 on failure
01337  */
01338 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
01339 
01340 /*! \brief Send a DTMF digit to a channel
01341  * Send a DTMF digit to a channel.
01342  * \param chan channel to act upon
01343  * \param digit the DTMF digit to send, encoded in ASCII
01344  * \return Returns 0 on success, -1 on failure
01345  */
01346 int ast_senddigit_begin(struct ast_channel *chan, char digit);
01347 
01348 /*! \brief Send a DTMF digit to a channel
01349 
01350  * Send a DTMF digit to a channel.
01351  * \param chan channel to act upon
01352  * \param digit the DTMF digit to send, encoded in ASCII
01353  * \param duration the duration of the digit ending in ms
01354  * \return Returns 0 on success, -1 on failure
01355  */
01356 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
01357 
01358 /*! \brief Receives a text string from a channel
01359  * Read a string of text from a channel
01360  * \param chan channel to act upon
01361  * \param timeout timeout in milliseconds (0 for infinite wait)
01362  * \return the received text, or NULL to signify failure.
01363  */
01364 char *ast_recvtext(struct ast_channel *chan, int timeout);
01365 
01366 /*! \brief Browse channels in use
01367  * Browse the channels currently in use
01368  * \param prev where you want to start in the channel list
01369  * \return Returns the next channel in the list, NULL on end.
01370  *    If it returns a channel, that channel *has been locked*!
01371  */
01372 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
01373 
01374 /*! \brief Get channel by name or uniqueid (locks channel) */
01375 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
01376 
01377 /*! \brief Get channel by name or uniqueid prefix (locks channel) */
01378 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
01379 
01380 /*! \brief Get channel by name or uniqueid prefix (locks channel) */
01381 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
01382 
01383 /*! \brief Get channel by exten (and optionally context) and lock it */
01384 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
01385 
01386 /*! \brief Get next channel by exten (and optionally context) and lock it */
01387 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
01388                        const char *context);
01389 
01390 /*! \brief Search for a channel based on the passed channel matching callback
01391  * Search for a channel based on the specified is_match callback, and return the
01392  * first channel that we match.  When returned, the channel will be locked.  Note
01393  * that the is_match callback is called with the passed channel locked, and should
01394  * return 0 if there is no match, and non-zero if there is.
01395  * \param is_match callback executed on each channel until non-zero is returned, or we
01396  *        run out of channels to search.
01397  * \param data data passed to the is_match callback during each invocation.
01398  * \return Returns the matched channel, or NULL if no channel was matched.
01399  */
01400 struct ast_channel *ast_channel_search_locked(int (*is_match)(struct ast_channel *, void *), void *data);
01401 
01402 /*! ! \brief Waits for a digit
01403  * \param c channel to wait for a digit on
01404  * \param ms how many milliseconds to wait
01405  * \return Returns <0 on error, 0 on no entry, and the digit on success. */
01406 int ast_waitfordigit(struct ast_channel *c, int ms);
01407 
01408 /*! \brief Wait for a digit
01409  Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
01410  * \param c channel to wait for a digit on
01411  * \param ms how many milliseconds to wait
01412  * \param audiofd audio file descriptor to write to if audio frames are received
01413  * \param ctrlfd control file descriptor to monitor for reading
01414  * \return Returns 1 if ctrlfd becomes available */
01415 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
01416 
01417 /*! Reads multiple digits
01418  * \param c channel to read from
01419  * \param s string to read in to.  Must be at least the size of your length
01420  * \param len how many digits to read (maximum)
01421  * \param timeout how long to timeout between digits
01422  * \param rtimeout timeout to wait on the first digit
01423  * \param enders digits to end the string
01424  * Read in a digit string "s", max length "len", maximum timeout between
01425    digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
01426    for the first digit.  Returns 0 on normal return, or 1 on a timeout.  In the case of
01427    a timeout, any digits that were read before the timeout will still be available in s.
01428    RETURNS 2 in full version when ctrlfd is available, NOT 1*/
01429 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
01430 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
01431 
01432 /*! \brief Report DTMF on channel 0 */
01433 #define AST_BRIDGE_DTMF_CHANNEL_0      (1 << 0)
01434 /*! \brief Report DTMF on channel 1 */
01435 #define AST_BRIDGE_DTMF_CHANNEL_1      (1 << 1)
01436 /*! \brief Return all voice frames on channel 0 */
01437 #define AST_BRIDGE_REC_CHANNEL_0    (1 << 2)
01438 /*! \brief Return all voice frames on channel 1 */
01439 #define AST_BRIDGE_REC_CHANNEL_1    (1 << 3)
01440 /*! \brief Ignore all signal frames except NULL */
01441 #define AST_BRIDGE_IGNORE_SIGS         (1 << 4)
01442 
01443 
01444 /*! \brief Makes two channel formats compatible
01445  * \param c0 first channel to make compatible
01446  * \param c1 other channel to make compatible
01447  * Set two channels to compatible formats -- call before ast_channel_bridge in general .
01448  * \return Returns 0 on success and -1 if it could not be done */
01449 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
01450 
01451 /*! Bridge two channels together (early)
01452  * \param c0 first channel to bridge
01453  * \param c1 second channel to bridge
01454  * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
01455  * \return Returns 0 on success and -1 if it could not be done */
01456 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
01457 
01458 /*! Bridge two channels together
01459  * \param c0 first channel to bridge
01460  * \param c1 second channel to bridge
01461  * \param config config for the channels
01462  * \param fo destination frame(?)
01463  * \param rc destination channel(?)
01464  * Bridge two channels (c0 and c1) together.  If an important frame occurs, we return that frame in
01465    *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
01466 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
01467 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
01468    struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
01469 
01470 /*!
01471  * \brief Weird function made for call transfers
01472  *
01473  * \param original channel to make a copy of
01474  * \param clone copy of the original channel
01475  *
01476  * This is a very strange and freaky function used primarily for transfer.  Suppose that
01477  * "original" and "clone" are two channels in random situations.  This function takes
01478  * the guts out of "clone" and puts them into the "original" channel, then alerts the
01479  * channel driver of the change, asking it to fixup any private information (like the
01480  * p->owner pointer) that is affected by the change.  The physical layer of the original
01481  * channel is hung up.
01482  *
01483  * \note Neither channel passed here needs to be locked before calling this function.
01484  */
01485 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
01486 
01487 /*! Gives the string form of a given cause code */
01488 /*!
01489  * \param state cause to get the description of
01490  * Give a name to a cause code
01491  * Returns the text form of the binary cause code given
01492  */
01493 const char *ast_cause2str(int state) attribute_pure;
01494 
01495 /*! Convert the string form of a cause code to a number */
01496 /*!
01497  * \param name string form of the cause
01498  * Returns the cause code
01499  */
01500 int ast_str2cause(const char *name) attribute_pure;
01501 
01502 /*! Gives the string form of a given channel state */
01503 /*!
01504  * \param ast_channel_state state to get the name of
01505  * Give a name to a state
01506  * Returns the text form of the binary state given
01507  */
01508 const char *ast_state2str(enum ast_channel_state);
01509 
01510 /*! Gives the string form of a given transfer capability */
01511 /*!
01512  * \param transfercapability transfercapabilty to get the name of
01513  * Give a name to a transfercapbility
01514  * See above
01515  * Returns the text form of the binary transfer capability
01516  */
01517 char *ast_transfercapability2str(int transfercapability) attribute_const;
01518 
01519 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
01520    low level channel.  See frame.h for options.  Note that many channel drivers may support
01521    none or a subset of those features, and you should not count on this if you want your
01522    asterisk application to be portable.  They're mainly useful for tweaking performance */
01523 
01524 /*! Sets an option on a channel */
01525 /*!
01526  * \param channel channel to set options on
01527  * \param option option to change
01528  * \param data data specific to option
01529  * \param datalen length of the data
01530  * \param block blocking or not
01531  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
01532  * Returns 0 on success and -1 on failure
01533  */
01534 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
01535 
01536 /*! Pick the best codec  */
01537 /* Choose the best codec...  Uhhh...   Yah. */
01538 int ast_best_codec(int fmts);
01539 
01540 
01541 /*! Checks the value of an option */
01542 /*!
01543  * Query the value of an option
01544  * Works similarly to setoption except only reads the options.
01545  */
01546 int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
01547 
01548 /*! Checks for HTML support on a channel */
01549 /*! Returns 0 if channel does not support HTML or non-zero if it does */
01550 int ast_channel_supports_html(struct ast_channel *channel);
01551 
01552 /*! Sends HTML on given channel */
01553 /*! Send HTML or URL on link.  Returns 0 on success or -1 on failure */
01554 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
01555 
01556 /*! Sends a URL on a given link */
01557 /*! Send URL on link.  Returns 0 on success or -1 on failure */
01558 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
01559 
01560 /*! Defers DTMF */
01561 /*! Defer DTMF so that you only read things like hangups and audio.  Returns
01562    non-zero if channel was already DTMF-deferred or 0 if channel is just now
01563    being DTMF-deferred */
01564 int ast_channel_defer_dtmf(struct ast_channel *chan);
01565 
01566 /*! Undo defer.  ast_read will return any dtmf characters that were queued */
01567 void ast_channel_undefer_dtmf(struct ast_channel *chan);
01568 
01569 /*! Initiate system shutdown -- prevents new channels from being allocated.
01570     If "hangup" is non-zero, all existing channels will receive soft
01571      hangups */
01572 void ast_begin_shutdown(int hangup);
01573 
01574 /*! Cancels an existing shutdown and returns to normal operation */
01575 void ast_cancel_shutdown(void);
01576 
01577 /*! Returns number of active/allocated channels */
01578 int ast_active_channels(void);
01579 
01580 /*! Returns non-zero if Asterisk is being shut down */
01581 int ast_shutting_down(void);
01582 
01583 /*! Activate a given generator */
01584 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
01585 
01586 /*! Deactivate an active generator */
01587 void ast_deactivate_generator(struct ast_channel *chan);
01588 
01589 /*!
01590  * \brief Set caller ID number, name and ANI
01591  *
01592  * \note The channel does not need to be locked before calling this function.
01593  */
01594 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
01595 
01596 /*! Set the file descriptor on the channel */
01597 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
01598 
01599 /*! Add a channel to an optimized waitfor */
01600 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
01601 
01602 /*! Delete a channel from an optimized waitfor */
01603 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
01604 
01605 /*! Start a tone going */
01606 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01607 /*! Stop a tone from playing */
01608 void ast_tonepair_stop(struct ast_channel *chan);
01609 /*! Play a tone pair for a given amount of time */
01610 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01611 
01612 /*!
01613  * \brief Automatically service a channel for us...
01614  *
01615  * \retval 0 success
01616  * \retval -1 failure, or the channel is already being autoserviced
01617  */
01618 int ast_autoservice_start(struct ast_channel *chan);
01619 
01620 /*!
01621  * \brief Stop servicing a channel for us...
01622  *
01623  * \note if chan is locked prior to calling ast_autoservice_stop, it
01624  * is likely that there will be a deadlock between the thread that calls
01625  * ast_autoservice_stop and the autoservice thread. It is important
01626  * that chan is not locked prior to this call
01627  *
01628  * \retval 0 success
01629  * \retval -1 error, or the channel has been hungup
01630  */
01631 int ast_autoservice_stop(struct ast_channel *chan);
01632 
01633 /*!
01634  * \brief Ignore certain frame types
01635  * \note Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames
01636  * while a channel is in autoservice and queue them up when taken out of
01637  * autoservice.  When this is not desireable, this API may be used to
01638  * cause the channel to ignore those frametypes after the channel is put
01639  * into autoservice, but before autoservice is stopped.
01640  * \retval 0 success
01641  * \retval -1 channel is not in autoservice
01642  */
01643 int ast_autoservice_ignore(struct ast_channel *chan, enum ast_frame_type ftype);
01644 
01645 /*!
01646  * \brief Enable or disable timer ticks for a channel
01647  *
01648  * \param rate number of timer ticks per second
01649  *
01650  * If timers are supported, force a scheduled expiration on the
01651  * timer fd, at which point we call the callback function / data
01652  *
01653  * Call this function with a rate of 0 to turn off the timer ticks
01654  *
01655  * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
01656  */
01657 int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
01658 
01659 /*!   \brief Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
01660    and 1 if supported and requested
01661    \param chan current channel
01662    \param dest destination extension for transfer
01663 */
01664 int ast_transfer(struct ast_channel *chan, char *dest);
01665 
01666 /*!   \brief  Start masquerading a channel
01667    XXX This is a seriously whacked out operation.  We're essentially putting the guts of
01668            the clone channel into the original channel.  Start by killing off the original
01669            channel's backend.   I'm not sure we're going to keep this function, because
01670            while the features are nice, the cost is very high in terms of pure nastiness. XXX
01671    \param chan    Channel to masquerade
01672 */
01673 int ast_do_masquerade(struct ast_channel *chan);
01674 
01675 /*!   \brief Find bridged channel
01676    \param chan Current channel
01677 */
01678 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
01679 
01680 /*!
01681   \brief Inherits channel variable from parent to child channel
01682   \param parent Parent channel
01683   \param child Child channel
01684 
01685   Scans all channel variables in the parent channel, looking for those
01686   that should be copied into the child channel.
01687   Variables whose names begin with a single '_' are copied into the
01688   child channel with the prefix removed.
01689   Variables whose names begin with '__' are copied into the child
01690   channel with their names unchanged.
01691 */
01692 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
01693 
01694 /*!
01695   \brief adds a list of channel variables to a channel
01696   \param chan the channel
01697   \param vars a linked list of variables
01698 
01699   Variable names can be for a regular channel variable or a dialplan function
01700   that has the ability to be written to.
01701 */
01702 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
01703 
01704 /*!
01705   \brief An opaque 'object' structure use by silence generators on channels.
01706  */
01707 struct ast_silence_generator;
01708 
01709 /*!
01710   \brief Starts a silence generator on the given channel.
01711   \param chan The channel to generate silence on
01712   \return An ast_silence_generator pointer, or NULL if an error occurs
01713 
01714   This function will cause SLINEAR silence to be generated on the supplied
01715   channel until it is disabled; if the channel cannot be put into SLINEAR
01716   mode then the function will fail.
01717 
01718   The pointer returned by this function must be preserved and passed to
01719   ast_channel_stop_silence_generator when you wish to stop the silence
01720   generation.
01721  */
01722 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
01723 
01724 /*!
01725   \brief Stops a previously-started silence generator on the given channel.
01726   \param chan The channel to operate on
01727   \param state The ast_silence_generator pointer return by a previous call to
01728   ast_channel_start_silence_generator.
01729   \return nothing
01730 
01731   This function will stop the operating silence generator and return the channel
01732   to its previous write format.
01733  */
01734 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
01735 
01736 /*!
01737   \brief Check if the channel can run in internal timing mode.
01738   \param chan The channel to check
01739   \return boolean
01740 
01741   This function will return 1 if internal timing is enabled and the timing
01742   device is available.
01743  */
01744 int ast_internal_timing_enabled(struct ast_channel *chan);
01745 
01746 /* Misc. functions below */
01747 
01748 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
01749  * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
01750  * return value to the index into the array)
01751  */
01752 static inline int ast_add_fd(struct pollfd *pfd, int fd)
01753 {
01754    pfd->fd = fd;
01755    pfd->events = POLLIN | POLLPRI;
01756    return fd >= 0;
01757 }
01758 
01759 /*! \brief Helper function for migrating select to poll */
01760 static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
01761 {
01762    int x;
01763    int dummy = 0;
01764 
01765    if (fd < 0)
01766       return 0;
01767    if (!start)
01768       start = &dummy;
01769    for (x = *start; x < maximum; x++)
01770       if (pfds[x].fd == fd) {
01771          if (x == *start)
01772             (*start)++;
01773          return pfds[x].revents;
01774       }
01775    return 0;
01776 }
01777 
01778 /*! \brief Retrieves the current T38 state of a channel */
01779 static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
01780 {
01781    enum ast_t38_state state = T38_STATE_UNAVAILABLE;
01782    int datalen = sizeof(state);
01783 
01784    ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
01785 
01786    return state;
01787 }
01788 
01789 #define CHECK_BLOCKING(c) do {    \
01790    if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
01791       if (option_debug) \
01792          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); \
01793    } else { \
01794       (c)->blocker = pthread_self(); \
01795       (c)->blockproc = __PRETTY_FUNCTION__; \
01796       ast_set_flag(c, AST_FLAG_BLOCKING); \
01797    } } while (0)
01798 
01799 ast_group_t ast_get_group(const char *s);
01800 
01801 /*! \brief print call- and pickup groups into buffer */
01802 char *ast_print_group(char *buf, int buflen, ast_group_t group);
01803 
01804 /*! \brief Convert enum channelreloadreason to text string for manager event
01805    \param reason  Enum channelreloadreason - reason for reload (manager, cli, start etc)
01806 */
01807 const char *channelreloadreason2txt(enum channelreloadreason reason);
01808 
01809 /*! \brief return an ast_variable list of channeltypes */
01810 struct ast_variable *ast_channeltype_list(void);
01811 
01812 /*!
01813   \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
01814   \param reason  The integer argument, usually taken from AST_CONTROL_ macros
01815   \return char pointer explaining the code
01816  */
01817 const char *ast_channel_reason2str(int reason);
01818 
01819 /*! \brief channel group info
01820  */
01821 struct ast_group_info {
01822    struct ast_channel *chan;
01823    char *category;
01824    char *group;
01825    AST_LIST_ENTRY(ast_group_info) group_list;
01826 };
01827 
01828 
01829 #if defined(__cplusplus) || defined(c_plusplus)
01830 }
01831 #endif
01832 
01833 #endif /* _ASTERISK_CHANNEL_H */

Generated on Wed Mar 2 18:53:24 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.9