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