Fri Jan 31 13:16:21 2014

Asterisk developer's documentation


channel.h

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

Generated on 31 Jan 2014 for Asterisk - the Open Source PBX by  doxygen 1.6.1