00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2006, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! \file 00020 * \brief General Asterisk PBX channel definitions. 00021 * \par See also: 00022 * \arg \ref Def_Channel 00023 * \arg \ref channel_drivers 00024 */ 00025 00026 /*! \page Def_Channel Asterisk Channels 00027 \par What is a Channel? 00028 A phone call through Asterisk consists of an incoming 00029 connection and an outbound connection. Each call comes 00030 in through a channel driver that supports one technology, 00031 like SIP, ZAP, IAX2 etc. 00032 \par 00033 Each channel driver, technology, has it's own private 00034 channel or dialog structure, that is technology-dependent. 00035 Each private structure is "owned" by a generic Asterisk 00036 channel structure, defined in channel.h and handled by 00037 channel.c . 00038 \par Call scenario 00039 This happens when an incoming call arrives to Asterisk 00040 -# Call arrives on a channel driver interface 00041 -# Channel driver creates a PBX channel and starts a 00042 pbx thread on the channel 00043 -# The dial plan is executed 00044 -# At this point at least two things can happen: 00045 -# The call is answered by Asterisk and 00046 Asterisk plays a media stream or reads media 00047 -# The dial plan forces Asterisk to create an outbound 00048 call somewhere with the dial (see \ref app_dial.c) 00049 application 00050 . 00051 00052 \par Bridging channels 00053 If Asterisk dials out this happens: 00054 -# Dial creates an outbound PBX channel and asks one of the 00055 channel drivers to create a call 00056 -# When the call is answered, Asterisk bridges the media streams 00057 so the caller on the first channel can speak with the callee 00058 on the second, outbound channel 00059 -# In some cases where we have the same technology on both 00060 channels and compatible codecs, a native bridge is used. 00061 In a native bridge, the channel driver handles forwarding 00062 of incoming audio to the outbound stream internally, without 00063 sending audio frames through the PBX. 00064 -# In SIP, theres an "external native bridge" where Asterisk 00065 redirects the endpoint, so audio flows directly between the 00066 caller's phone and the callee's phone. Signalling stays in 00067 Asterisk in order to be able to provide a proper CDR record 00068 for the call. 00069 00070 00071 \par Masquerading channels 00072 In some cases, a channel can masquerade itself into another 00073 channel. This happens frequently in call transfers, where 00074 a new channel takes over a channel that is already involved 00075 in a call. The new channel sneaks in and takes over the bridge 00076 and the old channel, now a zombie, is hung up. 00077 00078 \par Reference 00079 \arg channel.c - generic functions 00080 \arg channel.h - declarations of functions, flags and structures 00081 \arg translate.h - Transcoding support functions 00082 \arg \ref channel_drivers - Implemented channel drivers 00083 \arg \ref Def_Frame Asterisk Multimedia Frames 00084 00085 */ 00086 00087 #ifndef _ASTERISK_CHANNEL_H 00088 #define _ASTERISK_CHANNEL_H 00089 00090 #include "asterisk/abstract_jb.h" 00091 00092 #include <unistd.h> 00093 #ifdef POLLCOMPAT 00094 #include "asterisk/poll-compat.h" 00095 #else 00096 #include <sys/poll.h> 00097 #endif 00098 00099 #if defined(__cplusplus) || defined(c_plusplus) 00100 extern "C" { 00101 #endif 00102 00103 #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */ 00104 #define AST_MAX_CONTEXT 80 /*!< Max length of a context */ 00105 #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */ 00106 #define MAX_LANGUAGE 20 /*!< Max length of the language setting */ 00107 #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */ 00108 00109 #include "asterisk/compat.h" 00110 #include "asterisk/frame.h" 00111 #include "asterisk/sched.h" 00112 #include "asterisk/chanvars.h" 00113 #include "asterisk/config.h" 00114 #include "asterisk/lock.h" 00115 #include "asterisk/cdr.h" 00116 #include "asterisk/utils.h" 00117 #include "asterisk/linkedlists.h" 00118 #include "asterisk/stringfields.h" 00119 #include "asterisk/compiler.h" 00120 00121 #define DATASTORE_INHERIT_FOREVER INT_MAX 00122 00123 #define AST_MAX_FDS 8 00124 /* 00125 * We have AST_MAX_FDS file descriptors in a channel. 00126 * Some of them have a fixed use: 00127 */ 00128 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */ 00129 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */ 00130 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */ 00131 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */ 00132 00133 enum ast_bridge_result { 00134 AST_BRIDGE_COMPLETE = 0, 00135 AST_BRIDGE_FAILED = -1, 00136 AST_BRIDGE_FAILED_NOWARN = -2, 00137 AST_BRIDGE_RETRY = -3, 00138 }; 00139 00140 typedef unsigned long long ast_group_t; 00141 00142 struct ast_generator { 00143 void *(*alloc)(struct ast_channel *chan, void *params); 00144 void (*release)(struct ast_channel *chan, void *data); 00145 /*! This function gets called with the channel unlocked, but is called in 00146 * the context of the channel thread so we know the channel is not going 00147 * to disappear. This callback is responsible for locking the channel as 00148 * necessary. */ 00149 int (*generate)(struct ast_channel *chan, void *data, int len, int samples); 00150 }; 00151 00152 /*! \brief Structure for a data store type */ 00153 struct ast_datastore_info { 00154 const char *type; /*!< Type of data store */ 00155 void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */ 00156 void (*destroy)(void *data); /*!< Destroy function */ 00157 /*! 00158 * \brief Fix up channel references 00159 * 00160 * \arg data The datastore data 00161 * \arg old_chan The old channel owning the datastore 00162 * \arg new_chan The new channel owning the datastore 00163 * 00164 * This is exactly like the fixup callback of the channel technology interface. 00165 * It allows a datastore to fix any pointers it saved to the owning channel 00166 * in case that the owning channel has changed. Generally, this would happen 00167 * when the datastore is set to be inherited, and a masquerade occurs. 00168 * 00169 * \return nothing. 00170 */ 00171 void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan); 00172 }; 00173 00174 /*! \brief Structure for a channel data store */ 00175 struct ast_datastore { 00176 char *uid; /*!< Unique data store identifier */ 00177 void *data; /*!< Contained data */ 00178 const struct ast_datastore_info *info; /*!< Data store type information */ 00179 unsigned int inheritance; /*!Number of levels this item will continue to be inherited */ 00180 AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */ 00181 }; 00182 00183 /*! \brief Structure for all kinds of caller ID identifications. 00184 * \note All string fields here are malloc'ed, so they need to be 00185 * freed when the structure is deleted. 00186 * Also, NULL and "" must be considered equivalent. 00187 */ 00188 struct ast_callerid { 00189 char *cid_dnid; /*!< Malloc'd Dialed Number Identifier */ 00190 char *cid_num; /*!< Malloc'd Caller Number */ 00191 char *cid_name; /*!< Malloc'd Caller Name */ 00192 char *cid_ani; /*!< Malloc'd ANI */ 00193 char *cid_rdnis; /*!< Malloc'd RDNIS */ 00194 int cid_pres; /*!< Callerid presentation/screening */ 00195 int cid_ani2; /*!< Callerid ANI 2 (Info digits) */ 00196 int cid_ton; /*!< Callerid Type of Number */ 00197 int cid_tns; /*!< Callerid Transit Network Select */ 00198 }; 00199 00200 /*! \brief 00201 Structure to describe a channel "technology", ie a channel driver 00202 See for examples: 00203 \arg chan_iax2.c - The Inter-Asterisk exchange protocol 00204 \arg chan_sip.c - The SIP channel driver 00205 \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS) 00206 00207 If you develop your own channel driver, this is where you 00208 tell the PBX at registration of your driver what properties 00209 this driver supports and where different callbacks are 00210 implemented. 00211 */ 00212 struct ast_channel_tech { 00213 const char * const type; 00214 const char * const description; 00215 00216 int capabilities; /*!< Bitmap of formats this channel can handle */ 00217 00218 int properties; /*!< Technology Properties */ 00219 00220 /*! \brief Requester - to set up call data structures (pvt's) */ 00221 struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause); 00222 00223 int (* const devicestate)(void *data); /*!< Devicestate call back */ 00224 00225 /*! \brief Start sending a literal DTMF digit */ 00226 int (* const send_digit_begin)(struct ast_channel *chan, char digit); 00227 00228 /*! \brief Stop sending a literal DTMF digit */ 00229 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration); 00230 00231 /*! \brief Call a given phone number (address, etc), but don't 00232 take longer than timeout seconds to do so. */ 00233 int (* const call)(struct ast_channel *chan, char *addr, int timeout); 00234 00235 /*! \brief Hangup (and possibly destroy) the channel */ 00236 int (* const hangup)(struct ast_channel *chan); 00237 00238 /*! \brief Answer the channel */ 00239 int (* const answer)(struct ast_channel *chan); 00240 00241 /*! \brief Read a frame, in standard format (see frame.h) */ 00242 struct ast_frame * (* const read)(struct ast_channel *chan); 00243 00244 /*! \brief Write a frame, in standard format (see frame.h) */ 00245 int (* const write)(struct ast_channel *chan, struct ast_frame *frame); 00246 00247 /*! \brief Display or transmit text */ 00248 int (* const send_text)(struct ast_channel *chan, const char *text); 00249 00250 /*! \brief Display or send an image */ 00251 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame); 00252 00253 /*! \brief Send HTML data */ 00254 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len); 00255 00256 /*! \brief Handle an exception, reading a frame */ 00257 struct ast_frame * (* const exception)(struct ast_channel *chan); 00258 00259 /*! \brief Bridge two channels of the same type together */ 00260 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags, 00261 struct ast_frame **fo, struct ast_channel **rc, int timeoutms); 00262 00263 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */ 00264 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen); 00265 00266 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */ 00267 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan); 00268 00269 /*! \brief Set a given option */ 00270 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen); 00271 00272 /*! \brief Query a given option */ 00273 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen); 00274 00275 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */ 00276 int (* const transfer)(struct ast_channel *chan, const char *newdest); 00277 00278 /*! \brief Write a frame, in standard format */ 00279 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame); 00280 00281 /*! \brief Find bridged channel */ 00282 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge); 00283 00284 /*! \brief Provide additional read items for CHANNEL() dialplan function */ 00285 int (* func_channel_read)(struct ast_channel *chan, char *function, char *data, char *buf, size_t len); 00286 00287 /*! \brief Provide additional write items for CHANNEL() dialplan function */ 00288 int (* func_channel_write)(struct ast_channel *chan, char *function, char *data, const char *value); 00289 00290 /*! \brief Retrieve base channel (agent and local) */ 00291 struct ast_channel* (* get_base_channel)(struct ast_channel *chan); 00292 00293 /*! \brief Set base channel (agent and local) */ 00294 int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base); 00295 }; 00296 00297 #define DEBUGCHAN_FLAG 0x80000000 00298 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) ) 00299 00300 enum ast_channel_adsicpe { 00301 AST_ADSI_UNKNOWN, 00302 AST_ADSI_AVAILABLE, 00303 AST_ADSI_UNAVAILABLE, 00304 AST_ADSI_OFFHOOKONLY, 00305 }; 00306 00307 /*! 00308 * \brief ast_channel states 00309 * 00310 * \note Bits 0-15 of state are reserved for the state (up/down) of the line 00311 * Bits 16-32 of state are reserved for flags 00312 */ 00313 enum ast_channel_state { 00314 /*! Channel is down and available */ 00315 AST_STATE_DOWN, 00316 /*! Channel is down, but reserved */ 00317 AST_STATE_RESERVED, 00318 /*! Channel is off hook */ 00319 AST_STATE_OFFHOOK, 00320 /*! Digits (or equivalent) have been dialed */ 00321 AST_STATE_DIALING, 00322 /*! Line is ringing */ 00323 AST_STATE_RING, 00324 /*! Remote end is ringing */ 00325 AST_STATE_RINGING, 00326 /*! Line is up */ 00327 AST_STATE_UP, 00328 /*! Line is busy */ 00329 AST_STATE_BUSY, 00330 /*! Digits (or equivalent) have been dialed while offhook */ 00331 AST_STATE_DIALING_OFFHOOK, 00332 /*! Channel has detected an incoming call and is waiting for ring */ 00333 AST_STATE_PRERING, 00334 00335 /*! Do not transmit voice data */ 00336 AST_STATE_MUTE = (1 << 16), 00337 }; 00338 00339 /*! \brief Main Channel structure associated with a channel. 00340 * This is the side of it mostly used by the pbx and call management. 00341 * 00342 * \note XXX It is important to remember to increment .cleancount each time 00343 * this structure is changed. XXX 00344 */ 00345 struct ast_channel { 00346 /*! \brief Technology (point to channel driver) */ 00347 const struct ast_channel_tech *tech; 00348 00349 /*! \brief Private data used by the technology driver */ 00350 void *tech_pvt; 00351 00352 AST_DECLARE_STRING_FIELDS( 00353 AST_STRING_FIELD(name); /*!< ASCII unique channel name */ 00354 AST_STRING_FIELD(language); /*!< Language requested for voice prompts */ 00355 AST_STRING_FIELD(musicclass); /*!< Default music class */ 00356 AST_STRING_FIELD(accountcode); /*!< Account code for billing */ 00357 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */ 00358 AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */ 00359 ); 00360 00361 /*! \brief File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1. */ 00362 int fds[AST_MAX_FDS]; 00363 00364 void *music_state; /*!< Music State*/ 00365 void *generatordata; /*!< Current generator data if there is any */ 00366 struct ast_generator *generator; /*!< Current active data generator */ 00367 00368 /*! \brief Who are we bridged to, if we're bridged. Who is proxying for us, 00369 if we are proxied (i.e. chan_agent). 00370 Do not access directly, use ast_bridged_channel(chan) */ 00371 struct ast_channel *_bridge; 00372 struct ast_channel *masq; /*!< Channel that will masquerade as us */ 00373 struct ast_channel *masqr; /*!< Who we are masquerading as */ 00374 int cdrflags; /*!< Call Detail Record Flags */ 00375 00376 /*! \brief Whether or not we have been hung up... Do not set this value 00377 directly, use ast_softhangup */ 00378 int _softhangup; 00379 time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */ 00380 pthread_t blocker; /*!< If anyone is blocking, this is them */ 00381 ast_mutex_t lock; /*!< Lock, can be used to lock a channel for some operations */ 00382 const char *blockproc; /*!< Procedure causing blocking */ 00383 00384 const char *appl; /*!< Current application */ 00385 const char *data; /*!< Data passed to current application */ 00386 int fdno; /*!< Which fd had an event detected on */ 00387 struct sched_context *sched; /*!< Schedule context */ 00388 int streamid; /*!< For streaming playback, the schedule ID */ 00389 struct ast_filestream *stream; /*!< Stream itself. */ 00390 int vstreamid; /*!< For streaming video playback, the schedule ID */ 00391 struct ast_filestream *vstream; /*!< Video Stream itself. */ 00392 int oldwriteformat; /*!< Original writer format */ 00393 00394 int timingfd; /*!< Timing fd */ 00395 int (*timingfunc)(const void *data); 00396 void *timingdata; 00397 00398 enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate */ 00399 int rings; /*!< Number of rings so far */ 00400 struct ast_callerid cid; /*!< Caller ID, name, presentation etc */ 00401 char dtmfq[AST_MAX_EXTENSION]; /*!< Any/all queued DTMF characters */ 00402 struct ast_frame dtmff; /*!< DTMF frame */ 00403 00404 char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */ 00405 char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */ 00406 int priority; /*!< Dialplan: Current extension priority */ 00407 char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */ 00408 char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */ 00409 int macropriority; /*!< Macro: Current non-macro priority. See app_macro.c */ 00410 char dialcontext[AST_MAX_CONTEXT]; /*!< Dial: Extension context that we were called from */ 00411 00412 struct ast_pbx *pbx; /*!< PBX private structure for this channel */ 00413 int amaflags; /*!< Set BEFORE PBX is started to determine AMA flags */ 00414 struct ast_cdr *cdr; /*!< Call Detail Record */ 00415 enum ast_channel_adsicpe adsicpe; /*!< Whether or not ADSI is detected on CPE */ 00416 00417 struct ind_tone_zone *zone; /*!< Tone zone as set in indications.conf or 00418 in the CHANNEL dialplan function */ 00419 00420 struct ast_channel_monitor *monitor; /*!< Channel monitoring */ 00421 00422 /*! Track the read/written samples for monitor use */ 00423 unsigned long insmpl; 00424 unsigned long outsmpl; 00425 00426 /* Frames in/out counters. The high bit is a debug mask, so 00427 * the counter is only in the remaining bits 00428 */ 00429 unsigned int fin; 00430 unsigned int fout; 00431 int hangupcause; /*!< Why is the channel hanged up. See causes.h */ 00432 struct varshead varshead; /*!< A linked list for channel variables */ 00433 ast_group_t callgroup; /*!< Call group for call pickups */ 00434 ast_group_t pickupgroup; /*!< Pickup group - which calls groups can be picked up? */ 00435 unsigned int flags; /*!< channel flags of AST_FLAG_ type */ 00436 unsigned short transfercapability; /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */ 00437 AST_LIST_HEAD_NOLOCK(, ast_frame) readq; 00438 int alertpipe[2]; 00439 00440 int nativeformats; /*!< Kinds of data this channel can natively handle */ 00441 int readformat; /*!< Requested read format */ 00442 int writeformat; /*!< Requested write format */ 00443 struct ast_trans_pvt *writetrans; /*!< Write translation path */ 00444 struct ast_trans_pvt *readtrans; /*!< Read translation path */ 00445 int rawreadformat; /*!< Raw read format */ 00446 int rawwriteformat; /*!< Raw write format */ 00447 00448 struct ast_audiohook_list *audiohooks; 00449 void *unused; /*! This pointer should stay for Asterisk 1.4. It just keeps the struct size the same 00450 * for the sake of ABI compatability. */ 00451 00452 AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */ 00453 00454 struct ast_jb jb; /*!< The jitterbuffer state */ 00455 00456 char emulate_dtmf_digit; /*!< Digit being emulated */ 00457 unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */ 00458 struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */ 00459 00460 int visible_indication; /*!< Indication currently playing on the channel */ 00461 00462 /*! \brief Data stores on the channel */ 00463 AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; 00464 }; 00465 00466 /*! \brief ast_channel_tech Properties */ 00467 enum { 00468 /*! \brief Channels have this property if they can accept input with jitter; 00469 * i.e. most VoIP channels */ 00470 AST_CHAN_TP_WANTSJITTER = (1 << 0), 00471 /*! \brief Channels have this property if they can create jitter; 00472 * i.e. most VoIP channels */ 00473 AST_CHAN_TP_CREATESJITTER = (1 << 1), 00474 }; 00475 00476 /*! \brief ast_channel flags */ 00477 enum { 00478 /*! Queue incoming dtmf, to be released when this flag is turned off */ 00479 AST_FLAG_DEFER_DTMF = (1 << 1), 00480 /*! write should be interrupt generator */ 00481 AST_FLAG_WRITE_INT = (1 << 2), 00482 /*! a thread is blocking on this channel */ 00483 AST_FLAG_BLOCKING = (1 << 3), 00484 /*! This is a zombie channel */ 00485 AST_FLAG_ZOMBIE = (1 << 4), 00486 /*! There is an exception pending */ 00487 AST_FLAG_EXCEPTION = (1 << 5), 00488 /*! Listening to moh XXX anthm promises me this will disappear XXX */ 00489 AST_FLAG_MOH = (1 << 6), 00490 /*! This channel is spying on another channel */ 00491 AST_FLAG_SPYING = (1 << 7), 00492 /*! This channel is in a native bridge */ 00493 AST_FLAG_NBRIDGE = (1 << 8), 00494 /*! the channel is in an auto-incrementing dialplan processor, 00495 * so when ->priority is set, it will get incremented before 00496 * finding the next priority to run */ 00497 AST_FLAG_IN_AUTOLOOP = (1 << 9), 00498 /*! This is an outgoing call */ 00499 AST_FLAG_OUTGOING = (1 << 10), 00500 /*! This channel is being whispered on */ 00501 AST_FLAG_WHISPER = (1 << 11), 00502 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */ 00503 AST_FLAG_IN_DTMF = (1 << 12), 00504 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is 00505 * currently being emulated */ 00506 AST_FLAG_EMULATE_DTMF = (1 << 13), 00507 /*! This is set to tell the channel not to generate DTMF begin frames, and 00508 * to instead only generate END frames. */ 00509 AST_FLAG_END_DTMF_ONLY = (1 << 14), 00510 /*! This flag indicates that on a masquerade, an active stream should not 00511 * be carried over */ 00512 AST_FLAG_MASQ_NOSTREAM = (1 << 15), 00513 /*! This flag indicates that the hangup exten was run when the bridge terminated, 00514 * a message aimed at preventing a subsequent hangup exten being run at the pbx_run 00515 * level */ 00516 AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 16), 00517 }; 00518 00519 /*! \brief ast_bridge_config flags */ 00520 enum { 00521 AST_FEATURE_PLAY_WARNING = (1 << 0), 00522 AST_FEATURE_REDIRECT = (1 << 1), 00523 AST_FEATURE_DISCONNECT = (1 << 2), 00524 AST_FEATURE_ATXFER = (1 << 3), 00525 AST_FEATURE_AUTOMON = (1 << 4), 00526 AST_FEATURE_PARKCALL = (1 << 5), 00527 AST_FEATURE_NO_H_EXTEN = (1 << 6), 00528 }; 00529 00530 struct ast_bridge_config { 00531 struct ast_flags features_caller; 00532 struct ast_flags features_callee; 00533 struct timeval start_time; 00534 long feature_timer; 00535 long timelimit; 00536 long play_warning; 00537 long warning_freq; 00538 const char *warning_sound; 00539 const char *end_sound; 00540 const char *start_sound; 00541 int firstpass; 00542 unsigned int flags; 00543 void (* end_bridge_callback)(void); /*!< A callback that is called after a bridge attempt */ 00544 }; 00545 00546 struct chanmon; 00547 00548 #define LOAD_OH(oh) { \ 00549 oh.context = context; \ 00550 oh.exten = exten; \ 00551 oh.priority = priority; \ 00552 oh.cid_num = cid_num; \ 00553 oh.cid_name = cid_name; \ 00554 oh.account = account; \ 00555 oh.vars = vars; \ 00556 oh.parent_channel = NULL; \ 00557 } 00558 00559 struct outgoing_helper { 00560 const char *context; 00561 const char *exten; 00562 int priority; 00563 const char *cid_num; 00564 const char *cid_name; 00565 const char *account; 00566 struct ast_variable *vars; 00567 struct ast_channel *parent_channel; 00568 }; 00569 00570 enum { 00571 AST_CDR_TRANSFER = (1 << 0), 00572 AST_CDR_FORWARD = (1 << 1), 00573 AST_CDR_CALLWAIT = (1 << 2), 00574 AST_CDR_CONFERENCE = (1 << 3), 00575 }; 00576 00577 enum { 00578 /*! Soft hangup by device */ 00579 AST_SOFTHANGUP_DEV = (1 << 0), 00580 /*! Soft hangup for async goto */ 00581 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), 00582 AST_SOFTHANGUP_SHUTDOWN = (1 << 2), 00583 AST_SOFTHANGUP_TIMEOUT = (1 << 3), 00584 AST_SOFTHANGUP_APPUNLOAD = (1 << 4), 00585 AST_SOFTHANGUP_EXPLICIT = (1 << 5), 00586 AST_SOFTHANGUP_UNBRIDGE = (1 << 6), 00587 }; 00588 00589 00590 /*! \brief Channel reload reasons for manager events at load or reload of configuration */ 00591 enum channelreloadreason { 00592 CHANNEL_MODULE_LOAD, 00593 CHANNEL_MODULE_RELOAD, 00594 CHANNEL_CLI_RELOAD, 00595 CHANNEL_MANAGER_RELOAD, 00596 }; 00597 00598 /*! \brief Create a channel datastore structure */ 00599 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, char *uid); 00600 00601 /*! \brief Free a channel datastore structure */ 00602 int ast_channel_datastore_free(struct ast_datastore *datastore); 00603 00604 /*! \brief Inherit datastores from a parent to a child. */ 00605 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to); 00606 00607 /*! \brief Add a datastore to a channel */ 00608 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore); 00609 00610 /*! \brief Remove a datastore from a channel */ 00611 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore); 00612 00613 /*! \brief Find a datastore on a channel */ 00614 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, char *uid); 00615 00616 /*! \brief Change the state of a channel */ 00617 int ast_setstate(struct ast_channel *chan, enum ast_channel_state); 00618 00619 /*! \brief Create a channel structure 00620 \return Returns NULL on failure to allocate. 00621 \note New channels are 00622 by default set to the "default" context and 00623 extension "s" 00624 */ 00625 struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt, ...); 00626 00627 /*! \brief Queue an outgoing frame */ 00628 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f); 00629 00630 /*! \brief Queue a hangup frame */ 00631 int ast_queue_hangup(struct ast_channel *chan); 00632 00633 /*! 00634 \brief Queue a control frame with payload 00635 \param chan channel to queue frame onto 00636 \param control type of control frame 00637 \return zero on success, non-zero on failure 00638 */ 00639 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control); 00640 00641 /*! 00642 \brief Queue a control frame with payload 00643 \param chan channel to queue frame onto 00644 \param control type of control frame 00645 \param data pointer to payload data to be included in frame 00646 \param datalen number of bytes of payload data 00647 \return zero on success, non-zero on failure 00648 00649 The supplied payload data is copied into the frame, so the caller's copy 00650 is not modified nor freed, and the resulting frame will retain a copy of 00651 the data even if the caller frees their local copy. 00652 00653 \note This method should be treated as a 'network transport'; in other 00654 words, your frames may be transferred across an IAX2 channel to another 00655 system, which may be a different endianness than yours. Because of this, 00656 you should ensure that either your frames will never be expected to work 00657 across systems, or that you always put your payload data into 'network byte 00658 order' before calling this function. 00659 */ 00660 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, 00661 const void *data, size_t datalen); 00662 00663 /*! \brief Change channel name */ 00664 void ast_change_name(struct ast_channel *chan, char *newname); 00665 00666 /*! \brief Free a channel structure */ 00667 void ast_channel_free(struct ast_channel *); 00668 00669 /*! \brief Requests a channel 00670 * \param type type of channel to request 00671 * \param format requested channel format (codec) 00672 * \param data data to pass to the channel requester 00673 * \param status status 00674 * Request a channel of a given type, with data as optional information used 00675 * by the low level module 00676 * \return Returns an ast_channel on success, NULL on failure. 00677 */ 00678 struct ast_channel *ast_request(const char *type, int format, void *data, int *status); 00679 00680 /*! 00681 * \brief Request a channel of a given type, with data as optional information used 00682 * by the low level module and attempt to place a call on it 00683 * \param type type of channel to request 00684 * \param format requested channel format 00685 * \param data data to pass to the channel requester 00686 * \param timeout maximum amount of time to wait for an answer 00687 * \param reason why unsuccessful (if unsuceessful) 00688 * \param cidnum Caller-ID Number 00689 * \param cidname Caller-ID Name 00690 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state 00691 * to know if the call was answered or not. 00692 */ 00693 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname); 00694 00695 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); 00696 00697 /*!\brief Register a channel technology (a new channel driver) 00698 * Called by a channel module to register the kind of channels it supports. 00699 * \param tech Structure defining channel technology or "type" 00700 * \return Returns 0 on success, -1 on failure. 00701 */ 00702 int ast_channel_register(const struct ast_channel_tech *tech); 00703 00704 /*! \brief Unregister a channel technology 00705 * \param tech Structure defining channel technology or "type" that was previously registered 00706 * \return No return value. 00707 */ 00708 void ast_channel_unregister(const struct ast_channel_tech *tech); 00709 00710 /*! \brief Get a channel technology structure by name 00711 * \param name name of technology to find 00712 * \return a pointer to the structure, or NULL if no matching technology found 00713 */ 00714 const struct ast_channel_tech *ast_get_channel_tech(const char *name); 00715 00716 /*! \brief Hang up a channel 00717 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function 00718 * performs all stream stopping, etc, on the channel that needs to end. 00719 * chan is no longer valid after this call. 00720 * \param chan channel to hang up 00721 * \return Returns 0 on success, -1 on failure. 00722 */ 00723 int ast_hangup(struct ast_channel *chan); 00724 00725 /*! \brief Softly hangup up a channel 00726 * \param chan channel to be soft-hung-up 00727 * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to 00728 * safely hangup a channel managed by another thread. 00729 * \param cause Ast hangupcause for hangup 00730 * \return Returns 0 regardless 00731 */ 00732 int ast_softhangup(struct ast_channel *chan, int cause); 00733 00734 /*! \brief Softly hangup up a channel (no channel lock) 00735 * \param chan channel to be soft-hung-up 00736 * \param cause Ast hangupcause for hangup (see cause.h) */ 00737 int ast_softhangup_nolock(struct ast_channel *chan, int cause); 00738 00739 /*! \brief Check to see if a channel is needing hang up 00740 * \param chan channel on which to check for hang up 00741 * This function determines if the channel is being requested to be hung up. 00742 * \return Returns 0 if not, or 1 if hang up is requested (including time-out). 00743 */ 00744 int ast_check_hangup(struct ast_channel *chan); 00745 00746 /*! \brief Compare a offset with the settings of when to hang a channel up 00747 * \param chan channel on which to check for hang up 00748 * \param offset offset in seconds from current time 00749 * \return 1, 0, or -1 00750 * This function compares a offset from current time with the absolute time 00751 * out on a channel (when to hang up). If the absolute time out on a channel 00752 * is earlier than current time plus the offset, it returns 1, if the two 00753 * time values are equal, it return 0, otherwise, it retturn -1. 00754 */ 00755 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset); 00756 00757 /*! \brief Set when to hang a channel up 00758 * \param chan channel on which to check for hang up 00759 * \param offset offset in seconds from current time of when to hang up 00760 * This function sets the absolute time out on a channel (when to hang up). 00761 */ 00762 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset); 00763 00764 /*! \brief Answer a ringing call 00765 * \param chan channel to answer 00766 * This function answers a channel and handles all necessary call 00767 * setup functions. 00768 * \return Returns 0 on success, -1 on failure 00769 */ 00770 int ast_answer(struct ast_channel *chan); 00771 00772 /*! \brief Make a call 00773 * \param chan which channel to make the call on 00774 * \param addr destination of the call 00775 * \param timeout time to wait on for connect 00776 * Place a call, take no longer than timeout ms. 00777 \return Returns -1 on failure, 0 on not enough time 00778 (does not automatically stop ringing), and 00779 the number of seconds the connect took otherwise. 00780 */ 00781 int ast_call(struct ast_channel *chan, char *addr, int timeout); 00782 00783 /*! \brief Indicates condition of channel 00784 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel 00785 * \param chan channel to change the indication 00786 * \param condition which condition to indicate on the channel 00787 * \return Returns 0 on success, -1 on failure 00788 */ 00789 int ast_indicate(struct ast_channel *chan, int condition); 00790 00791 /*! \brief Indicates condition of channel, with payload 00792 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel 00793 * \param chan channel to change the indication 00794 * \param condition which condition to indicate on the channel 00795 * \param data pointer to payload data 00796 * \param datalen size of payload data 00797 * \return Returns 0 on success, -1 on failure 00798 */ 00799 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen); 00800 00801 /* Misc stuff ------------------------------------------------ */ 00802 00803 /*! \brief Wait for input on a channel 00804 * \param chan channel to wait on 00805 * \param ms length of time to wait on the channel 00806 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 00807 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */ 00808 int ast_waitfor(struct ast_channel *chan, int ms); 00809 00810 /*! \brief Wait for a specied amount of time, looking for hangups 00811 * \param chan channel to wait for 00812 * \param ms length of time in milliseconds to sleep 00813 * Waits for a specified amount of time, servicing the channel as required. 00814 * \return returns -1 on hangup, otherwise 0. 00815 */ 00816 int ast_safe_sleep(struct ast_channel *chan, int ms); 00817 00818 /*! \brief Wait for a specied amount of time, looking for hangups and a condition argument 00819 * \param chan channel to wait for 00820 * \param ms length of time in milliseconds to sleep 00821 * \param cond a function pointer for testing continue condition 00822 * \param data argument to be passed to the condition test function 00823 * \return returns -1 on hangup, otherwise 0. 00824 * Waits for a specified amount of time, servicing the channel as required. If cond 00825 * returns 0, this function returns. 00826 */ 00827 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data ); 00828 00829 /*! \brief Waits for activity on a group of channels 00830 * \param chan an array of pointers to channels 00831 * \param n number of channels that are to be waited upon 00832 * \param fds an array of fds to wait upon 00833 * \param nfds the number of fds to wait upon 00834 * \param exception exception flag 00835 * \param outfd fd that had activity on it 00836 * \param ms how long the wait was 00837 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds 00838 file descriptors. 00839 \return Returns the channel with activity, or NULL on error or if an FD 00840 came first. If the FD came first, it will be returned in outfd, otherwise, outfd 00841 will be -1 */ 00842 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms); 00843 00844 /*! \brief Waits for input on a group of channels 00845 Wait for input on an array of channels for a given # of milliseconds. 00846 \return Return channel with activity, or NULL if none has activity. 00847 \param chan an array of pointers to channels 00848 \param n number of channels that are to be waited upon 00849 \param ms time "ms" is modified in-place, if applicable */ 00850 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms); 00851 00852 /*! \brief Waits for input on an fd 00853 This version works on fd's only. Be careful with it. */ 00854 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception); 00855 00856 00857 /*! \brief Reads a frame 00858 * \param chan channel to read a frame from 00859 Read a frame. 00860 \return Returns a frame, or NULL on error. If it returns NULL, you 00861 best just stop reading frames and assume the channel has been 00862 disconnected. */ 00863 struct ast_frame *ast_read(struct ast_channel *chan); 00864 00865 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio. 00866 * Read a frame. 00867 \param chan channel to read a frame from 00868 \return Returns a frame, or NULL on error. If it returns NULL, you 00869 best just stop reading frames and assume the channel has been 00870 disconnected. 00871 \note Audio is replaced with AST_FRAME_NULL to avoid 00872 transcode when the resulting audio is not necessary. */ 00873 struct ast_frame *ast_read_noaudio(struct ast_channel *chan); 00874 00875 /*! \brief Write a frame to a channel 00876 * This function writes the given fram