Wed Aug 15 01:24:20 2007

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

Generated on Wed Aug 15 01:24:20 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.3