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 ast_group_t callgroup; 00393 ast_group_t 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 #define AST_FLAG_NOTNEW (1 << 10) /*!< see bug:7855 incorrect Newchannel event generation */ 00439 /* @} */ 00440 00441 #define AST_FEATURE_PLAY_WARNING (1 << 0) 00442 #define AST_FEATURE_REDIRECT (1 << 1) 00443 #define AST_FEATURE_DISCONNECT (1 << 2) 00444 #define AST_FEATURE_ATXFER (1 << 3) 00445 #define AST_FEATURE_AUTOMON (1 << 4) 00446 00447 #define AST_FEATURE_FLAG_NEEDSDTMF (1 << 0) 00448 #define AST_FEATURE_FLAG_CALLEE (1 << 1) 00449 #define AST_FEATURE_FLAG_CALLER (1 << 2) 00450 00451 struct ast_bridge_config { 00452 struct ast_flags features_caller; 00453 struct ast_flags features_callee; 00454 struct timeval start_time; 00455 long feature_timer; 00456 long timelimit; 00457 long play_warning; 00458 long warning_freq; 00459 char *warning_sound; 00460 char *end_sound; 00461 char *start_sound; 00462 int firstpass; 00463 unsigned int flags; 00464 }; 00465 00466 struct chanmon; 00467 00468 #define LOAD_OH(oh) { \ 00469 oh.context = context; \ 00470 oh.exten = exten; \ 00471 oh.priority = priority; \ 00472 oh.cid_num = cid_num; \ 00473 oh.cid_name = cid_name; \ 00474 oh.account = account; \ 00475 oh.vars = vars; \ 00476 oh.parent_channel = NULL; \ 00477 } 00478 00479 struct outgoing_helper { 00480 const char *context; 00481 const char *exten; 00482 int priority; 00483 const char *cid_num; 00484 const char *cid_name; 00485 const char *account; 00486 struct ast_variable *vars; 00487 struct ast_channel *parent_channel; 00488 }; 00489 00490 #define AST_CDR_TRANSFER (1 << 0) 00491 #define AST_CDR_FORWARD (1 << 1) 00492 #define AST_CDR_CALLWAIT (1 << 2) 00493 #define AST_CDR_CONFERENCE (1 << 3) 00494 00495 #define AST_ADSI_UNKNOWN (0) 00496 #define AST_ADSI_AVAILABLE (1) 00497 #define AST_ADSI_UNAVAILABLE (2) 00498 #define AST_ADSI_OFFHOOKONLY (3) 00499 00500 #define AST_SOFTHANGUP_DEV (1 << 0) /*!< Soft hangup by device */ 00501 #define AST_SOFTHANGUP_ASYNCGOTO (1 << 1) /*!< Soft hangup for async goto */ 00502 #define AST_SOFTHANGUP_SHUTDOWN (1 << 2) 00503 #define AST_SOFTHANGUP_TIMEOUT (1 << 3) 00504 #define AST_SOFTHANGUP_APPUNLOAD (1 << 4) 00505 #define AST_SOFTHANGUP_EXPLICIT (1 << 5) 00506 #define AST_SOFTHANGUP_UNBRIDGE (1 << 6) 00507 00508 00509 /*! \defgroup ChanState Channel states 00510 \brief Bits 0-15 of state are reserved for the state (up/down) of the line */ 00511 /*! @{ */ 00512 /*! Channel is down and available */ 00513 #define AST_STATE_DOWN 0 00514 /*! Channel is down, but reserved */ 00515 #define AST_STATE_RESERVED 1 00516 /*! Channel is off hook */ 00517 #define AST_STATE_OFFHOOK 2 00518 /*! Digits (or equivalent) have been dialed */ 00519 #define AST_STATE_DIALING 3 00520 /*! Line is ringing */ 00521 #define AST_STATE_RING 4 00522 /*! Remote end is ringing */ 00523 #define AST_STATE_RINGING 5 00524 /*! Line is up */ 00525 #define AST_STATE_UP 6 00526 /*! Line is busy */ 00527 #define AST_STATE_BUSY 7 00528 /*! Digits (or equivalent) have been dialed while offhook */ 00529 #define AST_STATE_DIALING_OFFHOOK 8 00530 /*! Channel has detected an incoming call and is waiting for ring */ 00531 #define AST_STATE_PRERING 9 00532 00533 /* Bits 16-32 of state are reserved for flags (See \ref ChanState ) */ 00534 /*! Do not transmit voice data */ 00535 #define AST_STATE_MUTE (1 << 16) 00536 /*! @} */ 00537 00538 /*! \brief Change the state of a channel */ 00539 int ast_setstate(struct ast_channel *chan, int state); 00540 00541 /*! \brief Create a channel structure 00542 \return Returns NULL on failure to allocate. 00543 \note New channels are 00544 by default set to the "default" context and 00545 extension "s" 00546 */ 00547 struct ast_channel *ast_channel_alloc(int needalertpipe); 00548 00549 /*! \brief Queue an outgoing frame */ 00550 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f); 00551 00552 /*! \brief Queue a hangup frame */ 00553 int ast_queue_hangup(struct ast_channel *chan); 00554 00555 /*! \brief Queue a control frame */ 00556 int ast_queue_control(struct ast_channel *chan, int control); 00557 00558 00559 /*! \brief Change channel name */ 00560 void ast_change_name(struct ast_channel *chan, char *newname); 00561 00562 /*! \brief Free a channel structure */ 00563 void ast_channel_free(struct ast_channel *); 00564 00565 /*! \brief Requests a channel 00566 * \param type type of channel to request 00567 * \param format requested channel format 00568 * \param data data to pass to the channel requester 00569 * \param status status 00570 * Request a channel of a given type, with data as optional information used 00571 * by the low level module 00572 * \return Returns an ast_channel on success, NULL on failure. 00573 */ 00574 struct ast_channel *ast_request(const char *type, int format, void *data, int *status); 00575 00576 /*! 00577 * \brief Request a channel of a given type, with data as optional information used 00578 * by the low level module and attempt to place a call on it 00579 * \param type type of channel to request 00580 * \param format requested channel format 00581 * \param data data to pass to the channel requester 00582 * \param timeout maximum amount of time to wait for an answer 00583 * \param reason why unsuccessful (if unsuceessful) 00584 * \param cidnum Caller-ID Number 00585 * \param cidname Caller-ID Name 00586 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state 00587 * to know if the call was answered or not. 00588 */ 00589 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname); 00590 00591 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); 00592 00593 /*!\brief Register a channel technology (a new channel driver) 00594 * Called by a channel module to register the kind of channels it supports. 00595 * \param tech Structure defining channel technology or "type" 00596 * \return Returns 0 on success, -1 on failure. 00597 */ 00598 int ast_channel_register(const struct ast_channel_tech *tech); 00599 00600 /*! \brief Unregister a channel technology 00601 * \param tech Structure defining channel technology or "type" that was previously registered 00602 * \return No return value. 00603 */ 00604 void ast_channel_unregister(const struct ast_channel_tech *tech); 00605 00606 /*! \brief Get a channel technology structure by name 00607 * \param name name of technology to find 00608 * \return a pointer to the structure, or NULL if no matching technology found 00609 */ 00610 const struct ast_channel_tech *ast_get_channel_tech(const char *name); 00611 00612 /*! \brief Hang up a channel 00613 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function 00614 * performs all stream stopping, etc, on the channel that needs to end. 00615 * chan is no longer valid after this call. 00616 * \param chan channel to hang up 00617 * \return Returns 0 on success, -1 on failure. 00618 */ 00619 int ast_hangup(struct ast_channel *chan); 00620 00621 /*! \brief Softly hangup up a channel 00622 * \param chan channel to be soft-hung-up 00623 * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to 00624 * safely hangup a channel managed by another thread. 00625 * \param cause Ast hangupcause for hangup 00626 * \return Returns 0 regardless 00627 */ 00628 int ast_softhangup(struct ast_channel *chan, int cause); 00629 00630 /*! \brief Softly hangup up a channel (no channel lock) 00631 * \param chan channel to be soft-hung-up 00632 * \param cause Ast hangupcause for hangup (see cause.h) */ 00633 int ast_softhangup_nolock(struct ast_channel *chan, int cause); 00634 00635 /*! \brief Check to see if a channel is needing hang up 00636 * \param chan channel on which to check for hang up 00637 * This function determines if the channel is being requested to be hung up. 00638 * \return Returns 0 if not, or 1 if hang up is requested (including time-out). 00639 */ 00640 int ast_check_hangup(struct ast_channel *chan); 00641 00642 /*! \brief Compare a offset with the settings of when to hang a channel up 00643 * \param chan channel on which to check for hang up 00644 * \param offset offset in seconds from current time 00645 * \return 1, 0, or -1 00646 * This function compares a offset from current time with the absolute time 00647 * out on a channel (when to hang up). If the absolute time out on a channel 00648 * is earlier than current time plus the offset, it returns 1, if the two 00649 * time values are equal, it return 0, otherwise, it retturn -1. 00650 */ 00651 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset); 00652 00653 /*! \brief Set when to hang a channel up 00654 * \param chan channel on which to check for hang up 00655 * \param offset offset in seconds from current time of when to hang up 00656 * This function sets the absolute time out on a channel (when to hang up). 00657 */ 00658 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset); 00659 00660 /*! \brief Answer a ringing call 00661 * \param chan channel to answer 00662 * This function answers a channel and handles all necessary call 00663 * setup functions. 00664 * \return Returns 0 on success, -1 on failure 00665 */ 00666 int ast_answer(struct ast_channel *chan); 00667 00668 /*! \brief Make a call 00669 * \param chan which channel to make the call on 00670 * \param addr destination of the call 00671 * \param timeout time to wait on for connect 00672 * Place a call, take no longer than timeout ms. 00673 \return Returns -1 on failure, 0 on not enough time 00674 (does not automatically stop ringing), and 00675 the number of seconds the connect took otherwise. 00676 */ 00677 int ast_call(struct ast_channel *chan, char *addr, int timeout); 00678 00679 /*! \brief Indicates condition of channel 00680 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel 00681 * \param chan channel to change the indication 00682 * \param condition which condition to indicate on the channel 00683 * \return Returns 0 on success, -1 on failure 00684 */ 00685 int ast_indicate(struct ast_channel *chan, int condition); 00686 00687 /* Misc stuff ------------------------------------------------ */ 00688 00689 /*! \brief Wait for input on a channel 00690 * \param chan channel to wait on 00691 * \param ms length of time to wait on the channel 00692 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 00693 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */ 00694 int ast_waitfor(struct ast_channel *chan, int ms); 00695 00696 /*! \brief Wait for a specied amount of time, looking for hangups 00697 * \param chan channel to wait for 00698 * \param ms length of time in milliseconds to sleep 00699 * Waits for a specified amount of time, servicing the channel as required. 00700 * \return returns -1 on hangup, otherwise 0. 00701 */ 00702 int ast_safe_sleep(struct ast_channel *chan, int ms); 00703 00704 /*! \brief Wait for a specied amount of time, looking for hangups and a condition argument 00705 * \param chan channel to wait for 00706 * \param ms length of time in milliseconds to sleep 00707 * \param cond a function pointer for testing continue condition 00708 * \param data argument to be passed to the condition test function 00709 * \return returns -1 on hangup, otherwise 0. 00710 * Waits for a specified amount of time, servicing the channel as required. If cond 00711 * returns 0, this function returns. 00712 */ 00713 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data ); 00714 00715 /*! \brief Waits for activity on a group of channels 00716 * \param chan an array of pointers to channels 00717 * \param n number of channels that are to be waited upon 00718 * \param fds an array of fds to wait upon 00719 * \param nfds the number of fds to wait upon 00720 * \param exception exception flag 00721 * \param outfd fd that had activity on it 00722 * \param ms how long the wait was 00723 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds 00724 file descriptors. 00725 \return Returns the channel with activity, or NULL on error or if an FD 00726 came first. If the FD came first, it will be returned in outfd, otherwise, outfd 00727 will be -1 */ 00728 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms); 00729 00730 /*! Waits for input on a group of channels */ 00731 /*! Wait for input on an array of channels for a given # of milliseconds. Return channel 00732 with activity, or NULL if none has activity. time "ms" is modified in-place, if applicable */ 00733 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms); 00734 00735 /*! Waits for input on an fd */ 00736 /*! This version works on fd's only. Be careful with it. */ 00737 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception); 00738 00739 00740 /*! Reads a frame */ 00741 /*! 00742 * \param chan channel to read a frame from 00743 * Read a frame. Returns a frame, or NULL on error. If it returns NULL, you 00744 best just stop reading frames and assume the channel has been 00745 disconnected. */ 00746 struct ast_frame *ast_read(struct ast_channel *chan); 00747 00748 /*! Write a frame to a channel */ 00749 /*! 00750 * \param chan destination channel of the frame 00751 * \param frame frame that will be written 00752 * This function writes the given frame to the indicated channel. 00753 * It returns 0 on success, -1 on failure. 00754 */ 00755 int ast_write(struct ast_channel *chan, struct ast_frame *frame); 00756 00757 /*! Write video frame to a channel */ 00758 /*! 00759 * \param chan destination channel of the frame 00760 * \param frame frame that will be written 00761 * This function writes the given frame to the indicated channel. 00762 * It returns 1 on success, 0 if not implemented, and -1 on failure. 00763 */ 00764 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame); 00765 00766 /* Send empty audio to prime a channel driver */ 00767 int ast_prod(struct ast_channel *chan); 00768 00769 /*! Sets read format on channel chan */ 00770 /*! 00771 * \param chan channel to change 00772 * \param format format to change to 00773 * Set read format for channel to whichever component of "format" is best. 00774 * Returns 0 on success, -1 on failure 00775 */ 00776 int ast_set_read_format(struct ast_channel *chan, int format); 00777 00778 /*! Sets write format on channel chan */ 00779 /*! 00780 * \param chan channel to change 00781 * \param format new format for writing 00782 * Set write format for channel to whichever compoent of "format" is best. 00783 * Returns 0 on success, -1 on failure 00784 */ 00785 int ast_set_write_format(struct ast_channel *chan, int format); 00786 00787 /*! Sends text to a channel */ 00788 /*! 00789 * \param chan channel to act upon 00790 * \param text string of text to send on the channel 00791 * Write text to a display on a channel 00792 * Returns 0 on success, -1 on failure 00793 */ 00794 int ast_sendtext(struct ast_channel *chan, const char *text); 00795 00796 /*! Receives a text character from a channel */ 00797 /*! 00798 * \param chan channel to act upon 00799 * \param timeout timeout in milliseconds (0 for infinite wait) 00800 * Read a char of text from a channel 00801 * Returns 0 on success, -1 on failure 00802 */ 00803 int ast_recvchar(struct ast_channel *chan, int timeout); 00804 00805 /*! Send a DTMF digit to a channel */ 00806 /*! 00807 * \param chan channel to act upon 00808 * \param digit the DTMF digit to send, encoded in ASCII 00809 * Send a DTMF digit to a channel. 00810 * Returns 0 on success, -1 on failure 00811 */ 00812 int ast_senddigit(struct ast_channel *chan, char digit); 00813 00814 /*! Receives a text string from a channel */ 00815 /*! 00816 * \param chan channel to act upon 00817 * \param timeout timeout in milliseconds (0 for infinite wait) 00818 * \return the received text, or NULL to signify failure. 00819 * Read a string of text from a channel 00820 */ 00821 char *ast_recvtext(struct ast_channel *chan, int timeout); 00822 00823 /*! Browse channels in use */ 00824 /*! 00825 * \param prev where you want to start in the channel list 00826 * Browse the channels currently in use 00827 * Returns the next channel in the list, NULL on end. 00828 * If it returns a channel, that channel *has been locked*! 00829 */ 00830 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev); 00831 00832 /*! Get channel by name (locks channel) */ 00833 struct ast_channel *ast_get_channel_by_name_locked(const char *chan); 00834 00835 /*! Get channel by name prefix (locks channel) */ 00836 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen); 00837 00838 /*! Get channel by name prefix (locks channel) */ 00839 struct ast_channel *ast_walk_channel_by_name_prefix_locked(struct ast_channel *chan, const char *name, const int namelen); 00840 00841 /*--- ast_get_channel_by_exten_locked: Get channel by exten (and optionally context) and lock it */ 00842 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context); 00843 00844 /*! Waits for a digit */ 00845 /*! 00846 * \param c channel to wait for a digit on 00847 * \param ms how many milliseconds to wait 00848 * Wait for a digit. Returns <0 on error, 0 on no entry, and the digit on success. */ 00849 int ast_waitfordigit(struct ast_channel *c, int ms); 00850 00851 /* Same as above with audio fd for outputing read audio and ctrlfd to monitor for 00852 reading. Returns 1 if ctrlfd becomes available */ 00853 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd); 00854 00855 /*! Reads multiple digits */ 00856 /*! 00857 * \param c channel to read from 00858 * \param s string to read in to. Must be at least the size of your length 00859 * \param len how many digits to read (maximum) 00860 * \param timeout how long to timeout between digits 00861 * \param rtimeout timeout to wait on the first digit 00862 * \param enders digits to end the string 00863 * Read in a digit string "s", max length "len", maximum timeout between 00864 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout 00865 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of 00866 a timeout, any digits that were read before the timeout will still be available in s. 00867 RETURNS 2 in full version when ctrlfd is available, NOT 1*/ 00868 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders); 00869 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd); 00870 00871 /*! Report DTMF on channel 0 */ 00872 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0) 00873 /*! Report DTMF on channel 1 */ 00874 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1) 00875 /*! Return all voice frames on channel 0 */ 00876 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2) 00877 /*! Return all voice frames on channel 1 */ 00878 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3) 00879 /*! Ignore all signal frames except NULL */ 00880 #define AST_BRIDGE_IGNORE_SIGS (1 << 4) 00881 00882 00883 /*! Makes two channel formats compatible */ 00884 /*! 00885 * \param c0 first channel to make compatible 00886 * \param c1 other channel to make compatible 00887 * Set two channels to compatible formats -- call before ast_channel_bridge in general . Returns 0 on success 00888 and -1 if it could not be done */ 00889 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1); 00890 00891 /*! Bridge two channels together */ 00892 /*! 00893 * \param c0 first channel to bridge 00894 * \param c1 second channel to bridge 00895 * \param config config for the channels 00896 * \param fo destination frame(?) 00897 * \param rc destination channel(?) 00898 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in 00899 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */ 00900 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */ 00901 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); 00902 00903 /*! Weird function made for call transfers */ 00904 /*! 00905 * \param original channel to make a copy of 00906 * \param clone copy of the original channel 00907 * This is a very strange and freaky function used primarily for transfer. Suppose that 00908 "original" and "clone" are two channels in random situations. This function takes 00909 the guts out of "clone" and puts them into the "original" channel, then alerts the 00910 channel driver of the change, asking it to fixup any private information (like the 00911 p->owner pointer) that is affected by the change. The physical layer of the original 00912 channel is hung up. */ 00913 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone); 00914 00915 /*! Gives the string form of a given cause code */ 00916 /*! 00917 * \param state cause to get the description of 00918 * Give a name to a cause code 00919 * Returns the text form of the binary cause code given 00920 */ 00921 const char *ast_cause2str(int state); 00922 00923 /*! Gives the string form of a given channel state */ 00924 /*! 00925 * \param state state to get the name of 00926 * Give a name to a state 00927 * Returns the text form of the binary state given 00928 */ 00929 char *ast_state2str(int state); 00930 00931 /*! Gives the string form of a given transfer capability */ 00932 /*! 00933 * \param transfercapability transfercapabilty to get the name of 00934 * Give a name to a transfercapbility 00935 * See above 00936 * Returns the text form of the binary transfer capbility 00937 */ 00938 char *ast_transfercapability2str(int transfercapability); 00939 00940 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the 00941 low level channel. See frame.h for options. Note that many channel drivers may support 00942 none or a subset of those features, and you should not count on this if you want your 00943 asterisk application to be portable. They're mainly useful for tweaking performance */ 00944 00945 /*! Sets an option on a channel */ 00946 /*! 00947 * \param channel channel to set options on 00948 * \param option option to change 00949 * \param data data specific to option 00950 * \param datalen length of the data 00951 * \param block blocking or not 00952 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 00953 * Returns 0 on success and -1 on failure 00954 */ 00955 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block); 00956 00957 /*! Pick the best codec */ 00958 /* Choose the best codec... Uhhh... Yah. */ 00959 extern int ast_best_codec(int fmts); 00960 00961 00962 /*! Checks the value of an option */ 00963 /*! 00964 * Query the value of an option, optionally blocking until a reply is received 00965 * Works similarly to setoption except only reads the options. 00966 */ 00967 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block); 00968 00969 /*! Checks for HTML support on a channel */ 00970 /*! Returns 0 if channel does not support HTML or non-zero if it does */ 00971 int ast_channel_supports_html(struct ast_channel *channel); 00972 00973 /*! Sends HTML on given channel */ 00974 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */ 00975 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen); 00976 00977 /*! Sends a URL on a given link */ 00978 /*! Send URL on link. Returns 0 on success or -1 on failure */ 00979 int ast_channel_sendurl(struct ast_channel *channel, const char *url); 00980 00981 /*! Defers DTMF */ 00982 /*! Defer DTMF so that you only read things like hangups and audio. Returns 00983 non-zero if channel was already DTMF-deferred or 0 if channel is just now 00984 being DTMF-deferred */ 00985 int ast_channel_defer_dtmf(struct ast_channel *chan); 00986 00987 /*! Undeos a defer */ 00988 /*! Undo defer. ast_read will return any dtmf characters that were queued */ 00989 void ast_channel_undefer_dtmf(struct ast_channel *chan); 00990 00991 /*! Initiate system shutdown -- prevents new channels from being allocated. 00992 If "hangup" is non-zero, all existing channels will receive soft 00993 hangups */ 00994 void ast_begin_shutdown(int hangup); 00995 00996 /*! Cancels an existing shutdown and returns to normal operation */ 00997 void ast_cancel_shutdown(void); 00998 00999 /*! Returns number of active/allocated channels */ 01000 int ast_active_channels(void); 01001 01002 /*! Returns non-zero if Asterisk is being shut down */ 01003 int ast_shutting_down(void); 01004 01005 /*! Activate a given generator */ 01006 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params); 01007 01008 /*! Deactive an active generator */ 01009 void ast_deactivate_generator(struct ast_channel *chan); 01010 01011 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani); 01012 01013 /*! Start a tone going */ 01014 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 01015 /*! Stop a tone from playing */ 01016 void ast_tonepair_stop(struct ast_channel *chan); 01017 /*! Play a tone pair for a given amount of time */ 01018 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 01019 01020 /*! Automatically service a channel for us... */ 01021 int ast_autoservice_start(struct ast_channel *chan); 01022 01023 /*! Stop servicing a channel for us... Returns -1 on error or if channel has been hungup */ 01024 int ast_autoservice_stop(struct ast_channel *chan); 01025 01026 /* If built with zaptel optimizations, force a scheduled expiration on the 01027 timer fd, at which point we call the callback function / data */ 01028 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data); 01029 01030 /*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported 01031 and 1 if supported and requested 01032 \param chan current channel 01033 \param dest destination extension for transfer 01034 */ 01035 int ast_transfer(struct ast_channel *chan, char *dest); 01036 01037 /*! \brief Start masquerading a channel 01038 XXX This is a seriously wacked out operation. We're essentially putting the guts of 01039 the clone channel into the original channel. Start by killing off the original 01040 channel's backend. I'm not sure we're going to keep this function, because 01041 while the features are nice, the cost is very high in terms of pure nastiness. XXX 01042 \param chan Channel to masquerade 01043 */ 01044 int ast_do_masquerade(struct ast_channel *chan); 01045 01046 /*! \brief Find bridged channel 01047 \param chan Current channel 01048 */ 01049 struct ast_channel *ast_bridged_channel(struct ast_channel *chan); 01050 01051 /*! 01052 \brief Inherits channel variable from parent to child channel 01053 \param parent Parent channel 01054 \param child Child channel 01055 01056 Scans all channel variables in the parent channel, looking for those 01057 that should be copied into the child channel. 01058 Variables whose names begin with a single '_' are copied into the 01059 child channel with the prefix removed. 01060 Variables whose names begin with '__' are copied into the child 01061 channel with their names unchanged. 01062 */ 01063 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child); 01064 01065 /*! 01066 \brief adds a list of channel variables to a channel 01067 \param chan the channel 01068 \param vars a linked list of variables 01069 01070 Variable names can be for a regular channel variable or a dialplan function 01071 that has the ability to be written to. 01072 */ 01073 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars); 01074 01075 /*! 01076 \brief An opaque 'object' structure use by silence generators on channels. 01077 */ 01078 struct ast_silence_generator; 01079 01080 /*! 01081 \brief Starts a silence generator on the given channel. 01082 \param chan The channel to generate silence on 01083 \return An ast_silence_generator pointer, or NULL if an error occurs 01084 01085 This function will cause SLINEAR silence to be generated on the supplied 01086 channel until it is disabled; if the channel cannot be put into SLINEAR 01087 mode then the function will fail. 01088 01089 The pointer returned by this function must be preserved and passed to 01090 ast_channel_stop_silence_generator when you wish to stop the silence 01091 generation. 01092 */ 01093 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan); 01094 01095 /*! 01096 \brief Stops a previously-started silence generator on the given channel. 01097 \param chan The channel to operate on 01098 \param state The ast_silence_generator pointer return by a previous call to 01099 ast_channel_start_silence_generator. 01100 \return nothing 01101 01102 This function will stop the operating silence generator and return the channel 01103 to its previous write format. 01104 */ 01105 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state); 01106 01107 /* Misc. functions below */ 01108 01109 /* Helper function for migrating select to poll */ 01110 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start) 01111 { 01112 int x; 01113 for (x=start ? *start : 0;x<max;x++) 01114 if (pfds[x].fd == fd) { 01115 if (start) { 01116 if (x==*start) 01117 (*start)++; 01118 } 01119 return pfds[x].revents; 01120 } 01121 return 0; 01122 } 01123 01124 #ifdef SOLARIS 01125 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff) 01126 { 01127 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec; 01128 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec; 01129 if (tvdiff->tv_usec < 0) { 01130 tvdiff->tv_sec --; 01131 tvdiff->tv_usec += 1000000; 01132 } 01133 01134 } 01135 #endif 01136 01137 /*! \brief Waits for activity on a group of channels 01138 * \param nfds the maximum number of file descriptors in the sets 01139 * \param rfds file descriptors to check for read availability 01140 * \param wfds file descriptors to check for write availability 01141 * \param efds file descriptors to check for exceptions (OOB data) 01142 * \param tvp timeout while waiting for events 01143 * This is the same as a standard select(), except it guarantees the 01144 * behaviour where the passed struct timeval is updated with how much 01145 * time was not slept while waiting for the specified events 01146 */ 01147 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp) 01148 { 01149 #ifdef __linux__ 01150 return select(nfds, rfds, wfds, efds, tvp); 01151 #else 01152 if (tvp) { 01153 struct timeval tv, tvstart, tvend, tvlen; 01154 int res; 01155 01156 tv = *tvp; 01157 gettimeofday(&tvstart, NULL); 01158 res = select(nfds, rfds, wfds, efds, tvp); 01159 gettimeofday(&tvend, NULL); 01160 timersub(&tvend, &tvstart, &tvlen); 01161 timersub(&tv, &tvlen, tvp); 01162 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) { 01163 tvp->tv_sec = 0; 01164 tvp->tv_usec = 0; 01165 } 01166 return res; 01167 } 01168 else 01169 return select(nfds, rfds, wfds, efds, NULL); 01170 #endif 01171 } 01172 01173 #if !defined(ast_strdupa) && defined(__GNUC__) 01174 # define ast_strdupa(s) \ 01175 (__extension__ \ 01176 ({ \ 01177 __const char *__old = (s); \ 01178 size_t __len = strlen (__old) + 1; \ 01179 char *__new = (char *) __builtin_alloca (__len); \ 01180 (char *) memcpy (__new, __old, __len); \ 01181 })) 01182 #endif 01183 01184 #ifdef DO_CRASH 01185 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0) 01186 #else 01187 #define CRASH do { } while(0) 01188 #endif 01189 01190 #define CHECK_BLOCKING(c) { \ 01191 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\ 01192 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); \ 01193 CRASH; \ 01194 } else { \ 01195 (c)->blocker = pthread_self(); \ 01196 (c)->blockproc = __PRETTY_FUNCTION__; \ 01197 ast_set_flag(c, AST_FLAG_BLOCKING); \ 01198 } } 01199 01200 extern ast_group_t ast_get_group(char *s); 01201 /* print call- and pickup groups into buffer */ 01202 extern char *ast_print_group(char *buf, int buflen, ast_group_t group); 01203 01204 01205 #if defined(__cplusplus) || defined(c_plusplus) 01206 } 01207 #endif 01208 01209 #endif /* _ASTERISK_CHANNEL_H */