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

Generated on Thu Oct 8 21:56:00 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6