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