Sun Aug 6 15:02:39 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

channel.h

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

Generated on Sun Aug 6 15:02:39 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.2