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/options.h" 00120 #include "asterisk/strings.h" 00121 #include "asterisk/compiler.h" 00122 00123 #define DATASTORE_INHERIT_FOREVER INT_MAX 00124 00125 #define AST_MAX_FDS 8 00126 /* 00127 * We have AST_MAX_FDS file descriptors in a channel. 00128 * Some of them have a fixed use: 00129 */ 00130 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */ 00131 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */ 00132 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */ 00133 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */ 00134 00135 enum ast_bridge_result { 00136 AST_BRIDGE_COMPLETE = 0, 00137 AST_BRIDGE_FAILED = -1, 00138 AST_BRIDGE_FAILED_NOWARN = -2, 00139 AST_BRIDGE_RETRY = -3, 00140 }; 00141 00142 typedef unsigned long long ast_group_t; 00143 00144 struct ast_generator { 00145 void *(*alloc)(struct ast_channel *chan, void *params); 00146 void (*release)(struct ast_channel *chan, void *data); 00147 /*! This function gets called with the channel unlocked, but is called in 00148 * the context of the channel thread so we know the channel is not going 00149 * to disappear. This callback is responsible for locking the channel as 00150 * necessary. */ 00151 int (*generate)(struct ast_channel *chan, void *data, int len, int samples); 00152 }; 00153 00154 /*! \brief Structure for a data store type */ 00155 struct ast_datastore_info { 00156 const char *type; /*!< Type of data store */ 00157 void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */ 00158 void (*destroy)(void *data); /*!< Destroy function */ 00159 /*! 00160 * \brief Fix up channel references 00161 * 00162 * \arg data The datastore data 00163 * \arg old_chan The old channel owning the datastore 00164 * \arg new_chan The new channel owning the datastore 00165 * 00166 * This is exactly like the fixup callback of the channel technology interface. 00167 * It allows a datastore to fix any pointers it saved to the owning channel 00168 * in case that the owning channel has changed. Generally, this would happen 00169 * when the datastore is set to be inherited, and a masquerade occurs. 00170 * 00171 * \return nothing. 00172 */ 00173 void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan); 00174 }; 00175 00176 /*! \brief Structure for a channel data store */ 00177 struct ast_datastore { 00178 char *uid; /*!< Unique data store identifier */ 00179 void *data; /*!< Contained data */ 00180 const struct ast_datastore_info *info; /*!< Data store type information */ 00181 unsigned int inheritance; /*!Number of levels this item will continue to be inherited */ 00182 AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */ 00183 }; 00184 00185 /*! \brief Structure for all kinds of caller ID identifications. 00186 * \note All string fields here are malloc'ed, so they need to be 00187 * freed when the structure is deleted. 00188 * Also, NULL and "" must be considered equivalent. 00189 */ 00190 struct ast_callerid { 00191 char *cid_dnid; /*!< Malloc'd Dialed Number Identifier */ 00192 char *cid_num; /*!< Malloc'd Caller Number */ 00193 char *cid_name; /*!< Malloc'd Caller Name */ 00194 char *cid_ani; /*!< Malloc'd ANI */ 00195 char *cid_rdnis; /*!< Malloc'd RDNIS */ 00196 int cid_pres; /*!< Callerid presentation/screening */ 00197 int cid_ani2; /*!< Callerid ANI 2 (Info digits) */ 00198 int cid_ton; /*!< Callerid Type of Number */ 00199 int cid_tns; /*!< Callerid Transit Network Select */ 00200 }; 00201 00202 /*! \brief 00203 Structure to describe a channel "technology", ie a channel driver 00204 See for examples: 00205 \arg chan_iax2.c - The Inter-Asterisk exchange protocol 00206 \arg chan_sip.c - The SIP channel driver 00207 \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS) 00208 00209 If you develop your own channel driver, this is where you 00210 tell the PBX at registration of your driver what properties 00211 this driver supports and where different callbacks are 00212 implemented. 00213 */ 00214 struct ast_channel_tech { 00215 const char * const type; 00216 const char * const description; 00217 00218 int capabilities; /*!< Bitmap of formats this channel can handle */ 00219 00220 int properties; /*!< Technology Properties */ 00221 00222 /*! \brief Requester - to set up call data structures (pvt's) */ 00223 struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause); 00224 00225 int (* const devicestate)(void *data); /*!< Devicestate call back */ 00226 00227 /*! \brief Start sending a literal DTMF digit */ 00228 int (* const send_digit_begin)(struct ast_channel *chan, char digit); 00229 00230 /*! \brief Stop sending a literal DTMF digit */ 00231 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration); 00232 00233 /*! \brief Call a given phone number (address, etc), but don't 00234 take longer than timeout seconds to do so. */ 00235 int (* const call)(struct ast_channel *chan, char *addr, int timeout); 00236 00237 /*! \brief Hangup (and possibly destroy) the channel */ 00238 int (* const hangup)(struct ast_channel *chan); 00239 00240 /*! \brief Answer the channel */ 00241 int (* const answer)(struct ast_channel *chan); 00242 00243 /*! \brief Read a frame, in standard format (see frame.h) */ 00244 struct ast_frame * (* const read)(struct ast_channel *chan); 00245 00246 /*! \brief Write a frame, in standard format (see frame.h) */ 00247 int (* const write)(struct ast_channel *chan, struct ast_frame *frame); 00248 00249 /*! \brief Display or transmit text */ 00250 int (* const send_text)(struct ast_channel *chan, const char *text); 00251 00252 /*! \brief Display or send an image */ 00253 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame); 00254 00255 /*! \brief Send HTML data */ 00256 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len); 00257 00258 /*! \brief Handle an exception, reading a frame */ 00259 struct ast_frame * (* const exception)(struct ast_channel *chan); 00260 00261 /*! \brief Bridge two channels of the same type together */ 00262 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags, 00263 struct ast_frame **fo, struct ast_channel **rc, int timeoutms); 00264 00265 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */ 00266 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen); 00267 00268 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */ 00269 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan); 00270 00271 /*! \brief Set a given option */ 00272 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen); 00273 00274 /*! \brief Query a given option */ 00275 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen); 00276 00277 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */ 00278 int (* const transfer)(struct ast_channel *chan, const char *newdest); 00279 00280 /*! \brief Write a frame, in standard format */ 00281 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame); 00282 00283 /*! \brief Find bridged channel */ 00284 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge); 00285 00286 /*! \brief Provide additional read items for CHANNEL() dialplan function */ 00287 int (* func_channel_read)(struct ast_channel *chan, char *function, char *data, char *buf, size_t len); 00288 00289 /*! \brief Provide additional write items for CHANNEL() dialplan function */ 00290 int (* func_channel_write)(struct ast_channel *chan, char *function, char *data, const char *value); 00291 00292 /*! \brief Retrieve base channel (agent and local) */ 00293 struct ast_channel* (* get_base_channel)(struct ast_channel *chan); 00294 00295 /*! \brief Set base channel (agent and local) */ 00296 int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base); 00297 }; 00298 00299 #define DEBUGCHAN_FLAG 0x80000000 00300 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) ) 00301 00302 enum ast_channel_adsicpe { 00303 AST_ADSI_UNKNOWN, 00304 AST_ADSI_AVAILABLE, 00305 AST_ADSI_UNAVAILABLE, 00306 AST_ADSI_OFFHOOKONLY, 00307 }; 00308 00309 /*! 00310 * \brief ast_channel states 00311 * 00312 * \note Bits 0-15 of state are reserved for the state (up/down) of the line 00313 * Bits 16-32 of state are reserved for flags 00314 */ 00315 enum ast_channel_state { 00316 /*! Channel is down and available */ 00317 AST_STATE_DOWN, 00318 /*! Channel is down, but reserved */ 00319 AST_STATE_RESERVED, 00320 /*! Channel is off hook */ 00321 AST_STATE_OFFHOOK, 00322 /*! Digits (or equivalent) have been dialed */ 00323 AST_STATE_DIALING, 00324 /*! Line is ringing */ 00325 AST_STATE_RING, 00326 /*! Remote end is ringing */ 00327 AST_STATE_RINGING, 00328 /*! Line is up */ 00329 AST_STATE_UP, 00330 /*! Line is busy */ 00331 AST_STATE_BUSY, 00332 /*! Digits (or equivalent) have been dialed while offhook */ 00333 AST_STATE_DIALING_OFFHOOK, 00334 /*! Channel has detected an incoming call and is waiting for ring */ 00335 AST_STATE_PRERING, 00336 00337 /*! Do not transmit voice data */ 00338 AST_STATE_MUTE = (1 << 16), 00339 }; 00340 00341 /*! \brief Main Channel structure associated with a channel. 00342 * This is the side of it mostly used by the pbx and call management. 00343 * 00344 * \note XXX It is important to remember to increment .cleancount each time 00345 * this structure is changed. XXX 00346 */ 00347 struct ast_channel { 00348 /*! \brief Technology (point to channel driver) */ 00349 const struct ast_channel_tech *tech; 00350 00351 /*! \brief Private data used by the technology driver */ 00352 void *tech_pvt; 00353 00354 AST_DECLARE_STRING_FIELDS( 00355 AST_STRING_FIELD(name); /*!< ASCII unique channel name */ 00356 AST_STRING_FIELD(language); /*!< Language requested for voice prompts */ 00357 AST_STRING_FIELD(musicclass); /*!< Default music class */ 00358 AST_STRING_FIELD(accountcode); /*!< Account code for billing */ 00359 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */ 00360 AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */ 00361 ); 00362 00363 /*! \brief File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1. */ 00364 int fds[AST_MAX_FDS]; 00365 00366 void *music_state; /*!< Music State*/ 00367 void *generatordata; /*!< Current generator data if there is any */ 00368 struct ast_generator *generator; /*!< Current active data generator */ 00369 00370 /*! \brief Who are we bridged to, if we're bridged. Who is proxying for us, 00371 if we are proxied (i.e. chan_agent). 00372 Do not access directly, use ast_bridged_channel(chan) */ 00373 struct ast_channel *_bridge; 00374 struct ast_channel *masq; /*!< Channel that will masquerade as us */ 00375 struct ast_channel *masqr; /*!< Who we are masquerading as */ 00376 int cdrflags; /*!< Call Detail Record Flags */ 00377 00378 /*! \brief Whether or not we have been hung up... Do not set this value 00379 directly, use ast_softhangup */ 00380 int _softhangup; 00381 time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */ 00382 pthread_t blocker; /*!< If anyone is blocking, this is them */ 00383 ast_mutex_t lock; /*!< Lock, can be used to lock a channel for some operations */ 00384 const char *blockproc; /*!< Procedure causing blocking */ 00385 00386 const char *appl; /*!< Current application */ 00387 const char *data; /*!< Data passed to current application */ 00388 int fdno; /*!< Which fd had an event detected on */ 00389 struct sched_context *sched; /*!< Schedule context */ 00390 int streamid; /*!< For streaming playback, the schedule ID */ 00391 struct ast_filestream *stream; /*!< Stream itself. */ 00392 int vstreamid; /*!< For streaming video playback, the schedule ID */ 00393 struct ast_filestream *vstream; /*!< Video Stream itself. */ 00394 int oldwriteformat; /*!< Original writer format */ 00395 00396 int timingfd; /*!< Timing fd */ 00397 int (*timingfunc)(const void *data); 00398 void *timingdata; 00399 00400 enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate */ 00401 int rings; /*!< Number of rings so far */ 00402 struct ast_callerid cid; /*!< Caller ID, name, presentation etc */ 00403 char unused_old_dtmfq[AST_MAX_EXTENSION]; /*!< The DTMFQ is deprecated. All frames should go to the readq. */ 00404 struct ast_frame dtmff; /*!< DTMF frame */ 00405 00406 char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */ 00407 char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */ 00408 int priority; /*!< Dialplan: Current extension priority */ 00409 char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */ 00410 char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */ 00411 int macropriority; /*!< Macro: Current non-macro priority. See app_macro.c */ 00412 char dialcontext[AST_MAX_CONTEXT]; /*!< Dial: Extension context that we were called from */ 00413 00414 struct ast_pbx *pbx; /*!< PBX private structure for this channel */ 00415 int amaflags; /*!< Set BEFORE PBX is started to determine AMA flags */ 00416 struct ast_cdr *cdr; /*!< Call Detail Record */ 00417 enum ast_channel_adsicpe adsicpe; /*!< Whether or not ADSI is detected on CPE */ 00418 00419 struct ind_tone_zone *zone; /*!< Tone zone as set in indications.conf or 00420 in the CHANNEL dialplan function */ 00421 00422 struct ast_channel_monitor *monitor; /*!< Channel monitoring */ 00423 00424 /*! Track the read/written samples for monitor use */ 00425 unsigned long insmpl; 00426 unsigned long outsmpl; 00427 00428 /* Frames in/out counters. The high bit is a debug mask, so 00429 * the counter is only in the remaining bits 00430 */ 00431 unsigned int fin; 00432 unsigned int fout; 00433 int hangupcause; /*!< Why is the channel hanged up. See causes.h */ 00434 struct varshead varshead; /*!< A linked list for channel variables */ 00435 ast_group_t callgroup; /*!< Call group for call pickups */ 00436 ast_group_t pickupgroup; /*!< Pickup group - which calls groups can be picked up? */ 00437 unsigned int flags; /*!< channel flags of AST_FLAG_ type */ 00438 unsigned short transfercapability; /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */ 00439 AST_LIST_HEAD_NOLOCK(, ast_frame) readq; 00440 int alertpipe[2]; 00441 00442 int nativeformats; /*!< Kinds of data this channel can natively handle */ 00443 int readformat; /*!< Requested read format */ 00444 int writeformat; /*!< Requested write format */ 00445 struct ast_trans_pvt *writetrans; /*!< Write translation path */ 00446 struct ast_trans_pvt *readtrans; /*!< Read translation path */ 00447 int rawreadformat; /*!< Raw read format */ 00448 int rawwriteformat; /*!< Raw write format */ 00449 00450 struct ast_audiohook_list *audiohooks; 00451 void *unused; /*! This pointer should stay for Asterisk 1.4. It just keeps the struct size the same 00452 * for the sake of ABI compatability. */ 00453 00454 AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */ 00455 00456 struct ast_jb jb; /*!< The jitterbuffer state */ 00457 00458 char emulate_dtmf_digit; /*!< Digit being emulated */ 00459 unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */ 00460 struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */ 00461 00462 int visible_indication; /*!< Indication currently playing on the channel */ 00463 00464 /*! \brief Data stores on the channel */ 00465 AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; 00466 }; 00467 00468 /*! \brief ast_channel_tech Properties */ 00469 enum { 00470 /*! \brief Channels have this property if they can accept input with jitter; 00471 * i.e. most VoIP channels */ 00472 AST_CHAN_TP_WANTSJITTER = (1 << 0), 00473 /*! \brief Channels have this property if they can create jitter; 00474 * i.e. most VoIP channels */ 00475 AST_CHAN_TP_CREATESJITTER = (1 << 1), 00476 }; 00477 00478 /*! \brief ast_channel flags */ 00479 enum { 00480 /*! Queue incoming dtmf, to be released when this flag is turned off */ 00481 AST_FLAG_DEFER_DTMF = (1 << 1), 00482 /*! write should be interrupt generator */ 00483 AST_FLAG_WRITE_INT = (1 << 2), 00484 /*! a thread is blocking on this channel */ 00485 AST_FLAG_BLOCKING = (1 << 3), 00486 /*! This is a zombie channel */ 00487 AST_FLAG_ZOMBIE = (1 << 4), 00488 /*! There is an exception pending */ 00489 AST_FLAG_EXCEPTION = (1 << 5), 00490 /*! Listening to moh XXX anthm promises me this will disappear XXX */ 00491 AST_FLAG_MOH = (1 << 6), 00492 /*! This channel is spying on another channel */ 00493 AST_FLAG_SPYING = (1 << 7), 00494 /*! This channel is in a native bridge */ 00495 AST_FLAG_NBRIDGE = (1 << 8), 00496 /*! the channel is in an auto-incrementing dialplan processor, 00497 * so when ->priority is set, it will get incremented before 00498 * finding the next priority to run */ 00499 AST_FLAG_IN_AUTOLOOP = (1 << 9), 00500 /*! This is an outgoing call */ 00501 AST_FLAG_OUTGOING = (1 << 10), 00502 /*! This channel is being whispered on */ 00503 AST_FLAG_WHISPER = (1 << 11), 00504 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */ 00505 AST_FLAG_IN_DTMF = (1 << 12), 00506 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is 00507 * currently being emulated */ 00508 AST_FLAG_EMULATE_DTMF = (1 << 13), 00509 /*! This is set to tell the channel not to generate DTMF begin frames, and 00510 * to instead only generate END frames. */ 00511 AST_FLAG_END_DTMF_ONLY = (1 << 14), 00512 /*! This flag indicates that on a masquerade, an active stream should not 00513 * be carried over */ 00514 AST_FLAG_MASQ_NOSTREAM = (1 << 15), 00515 /*! This flag indicates that the hangup exten was run when the bridge terminated, 00516 * a message aimed at preventing a subsequent hangup exten being run at the pbx_run 00517 * level */ 00518 AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 16), 00519 }; 00520 00521 /*! \brief ast_bridge_config flags */ 00522 enum { 00523 AST_FEATURE_PLAY_WARNING = (1 << 0), 00524 AST_FEATURE_REDIRECT = (1 << 1), 00525 AST_FEATURE_DISCONNECT = (1 << 2), 00526 AST_FEATURE_ATXFER = (1 << 3), 00527 AST_FEATURE_AUTOMON = (1 << 4), 00528 AST_FEATURE_PARKCALL = (1 << 5), 00529 AST_FEATURE_NO_H_EXTEN = (1 << 6), 00530 }; 00531 00532 struct ast_bridge_config { 00533 struct ast_flags features_caller; 00534 struct ast_flags features_callee; 00535 struct timeval start_time; 00536 long feature_timer; 00537 long timelimit; 00538 long play_warning; 00539 long warning_freq; 00540 const char *warning_sound; 00541 const char *end_sound; 00542 const char *start_sound; 00543 int firstpass; 00544 unsigned int flags; 00545 void (* end_bridge_callback)(void *); /*!< A callback that is called after a bridge attempt */ 00546 void *end_bridge_callback_data; /*!< Data passed to the callback */ 00547 /*! If the end_bridge_callback_data refers to a channel which no longer is going to 00548 * exist when the end_bridge_callback is called, then it needs to be fixed up properly 00549 */ 00550 void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator); 00551 }; 00552 00553 struct chanmon; 00554 00555 #define LOAD_OH(oh) { \ 00556 oh.context = context; \ 00557 oh.exten = exten; \ 00558 oh.priority = priority; \ 00559 oh.cid_num = cid_num; \ 00560 oh.cid_name = cid_name; \ 00561 oh.account = account; \ 00562 oh.vars = vars; \ 00563 oh.parent_channel = NULL; \ 00564 } 00565 00566 struct outgoing_helper { 00567 const char *context; 00568 const char *exten; 00569 int priority; 00570 const char *cid_num; 00571 const char *cid_name; 00572 const char *account; 00573 struct ast_variable *vars; 00574 struct ast_channel *parent_channel; 00575 }; 00576 00577 enum { 00578 AST_CDR_TRANSFER = (1 << 0), 00579 AST_CDR_FORWARD = (1 << 1), 00580 AST_CDR_CALLWAIT = (1 << 2), 00581 AST_CDR_CONFERENCE = (1 << 3), 00582 }; 00583 00584 enum { 00585 /*! Soft hangup by device */ 00586 AST_SOFTHANGUP_DEV = (1 << 0), 00587 /*! Soft hangup for async goto */ 00588 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), 00589 AST_SOFTHANGUP_SHUTDOWN = (1 << 2), 00590 AST_SOFTHANGUP_TIMEOUT = (1 << 3), 00591 AST_SOFTHANGUP_APPUNLOAD = (1 << 4), 00592 AST_SOFTHANGUP_EXPLICIT = (1 << 5), 00593 AST_SOFTHANGUP_UNBRIDGE = (1 << 6), 00594 }; 00595 00596 00597 /*! \brief Channel reload reasons for manager events at load or reload of configuration */ 00598 enum channelreloadreason { 00599 CHANNEL_MODULE_LOAD, 00600 CHANNEL_MODULE_RELOAD, 00601 CHANNEL_CLI_RELOAD, 00602 CHANNEL_MANAGER_RELOAD, 00603 }; 00604 00605 /*! \brief Create a channel datastore structure */ 00606 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, char *uid); 00607 00608 /*! \brief Free a channel datastore structure */ 00609 int ast_channel_datastore_free(struct ast_datastore *datastore); 00610 00611 /*! \brief Inherit datastores from a parent to a child. */ 00612 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to); 00613 00614 /*! \brief Add a datastore to a channel */ 00615 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore); 00616 00617 /*! \brief Remove a datastore from a channel */ 00618 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore); 00619 00620 /*! \brief Find a datastore on a channel */ 00621 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, char *uid); 00622 00623 /*! \brief Change the state of a channel */ 00624 int ast_setstate(struct ast_channel *chan, enum ast_channel_state); 00625 00626 /*! \brief Create a channel structure 00627 \return Returns NULL on failure to allocate. 00628 \note New channels are 00629 by default set to the "default" context and 00630 extension "s" 00631 */ 00632 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, ...) __attribute__((format(printf, 9, 10))); 00633 00634 /*! \brief Queue an outgoing frame */ 00635 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f); 00636 00637 /*! 00638 * \brief Queue an outgoing frame to the head of the frame queue 00639 * 00640 * \param chan the channel to queue the frame on 00641 * \param f the frame to queue. Note that this frame will be duplicated by 00642 * this function. It is the responsibility of the caller to handle 00643 * freeing the memory associated with the frame being passed if 00644 * necessary. 00645 * 00646 * \retval 0 success 00647 * \retval non-zero failure 00648 */ 00649 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f); 00650 00651 /*! \brief Queue a hangup frame */ 00652 int ast_queue_hangup(struct ast_channel *chan); 00653 00654 /*! 00655 \brief Queue a control frame with payload 00656 \param chan channel to queue frame onto 00657 \param control type of control frame 00658 \return zero on success, non-zero on failure 00659 */ 00660 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control); 00661 00662 /*! 00663 \brief Queue a control frame with payload 00664 \param chan channel to queue frame onto 00665 \param control type of control frame 00666 \param data pointer to payload data to be included in frame 00667 \param datalen number of bytes of payload data 00668 \return zero on success, non-zero on failure 00669 00670 The supplied payload data is copied into the frame, so the caller's copy 00671 is not modified nor freed, and the resulting frame will retain a copy of 00672 the data even if the caller frees their local copy. 00673 00674 \note This method should be treated as a 'network transport'; in other 00675 words, your frames may be transferred across an IAX2 channel to another 00676 system, which may be a different endianness than yours. Because of this, 00677 you should ensure that either your frames will never be expected to work 00678 across systems, or that you always put your payload data into 'network byte 00679 order' before calling this function. 00680 */ 00681 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, 00682 const void *data, size_t datalen); 00683 00684 /*! \brief Change channel name */ 00685 void ast_change_name(struct ast_channel *chan, char *newname); 00686 00687 /*! \brief Free a channel structure */ 00688 void ast_channel_free(struct ast_channel *); 00689 00690 /*! \brief Requests a channel 00691 * \param type type of channel to request 00692 * \param format requested channel format (codec) 00693 * \param data data to pass to the channel requester 00694 * \param status status 00695 * Request a channel of a given type, with data as optional information used 00696 * by the low level module 00697 * \return Returns an ast_channel on success, NULL on failure. 00698 */ 00699 struct ast_channel *ast_request(const char *type, int format, void *data, int *status); 00700 00701 00702 /*! \brief call ast_request with format/type of parent channel 00703 */ 00704 static inline struct ast_channel *ast_request_inherit(struct ast_channel *chan, const char *type, void *data, int *status) 00705 { 00706 return ast_request(S_OR(type, chan->tech->type), chan->nativeformats, data, status); 00707 } 00708 00709 /*! 00710 * \brief Request a channel of a given type, with data as optional information used 00711 * by the low level module and attempt to place a call on it 00712 * \param type type of channel to request 00713 * \param format requested channel format 00714 * \param data data to pass to the channel requester 00715 * \param timeout maximum amount of time to wait for an answer 00716 * \param reason why unsuccessful (if unsuceessful) 00717 * \param cidnum Caller-ID Number 00718 * \param cidname Caller-ID Name 00719 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state 00720 * to know if the call was answered or not. 00721 */ 00722 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname); 00723 00724 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); 00725 00726 /*!\brief Register a channel technology (a new channel driver) 00727 * Called by a channel module to register the kind of channels it supports. 00728 * \param tech Structure defining channel technology or "type" 00729 * \return Returns 0 on success, -1 on failure. 00730 */ 00731 int ast_channel_register(const struct ast_channel_tech *tech); 00732 00733 /*! \brief Unregister a channel technology 00734 * \param tech Structure defining channel technology or "type" that was previously registered 00735 * \return No return value. 00736 */ 00737 void ast_channel_unregister(const struct ast_channel_tech *tech); 00738 00739 /*! \brief Get a channel technology structure by name 00740 * \param name name of technology to find 00741 * \return a pointer to the structure, or NULL if no matching technology found 00742 */ 00743 const struct ast_channel_tech *ast_get_channel_tech(const char *name); 00744 00745 /*! \brief Hang up a channel 00746 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function 00747 * performs all stream stopping, etc, on the channel that needs to end. 00748 * chan is no longer valid after this call. 00749 * \param chan channel to hang up 00750 * \return Returns 0 on success, -1 on failure. 00751 */ 00752 int ast_hangup(struct ast_channel *chan); 00753 00754 /*! \brief Softly hangup up a channel 00755 * \param chan channel to be soft-hung-up 00756 * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to 00757 * safely hangup a channel managed by another thread. 00758 * \param cause Ast hangupcause for hangup 00759 * \return Returns 0 regardless 00760 */ 00761 int ast_softhangup(struct ast_channel *chan, int cause); 00762 00763 /*! \brief Softly hangup up a channel (no channel lock) 00764 * \param chan channel to be soft-hung-up 00765 * \param cause Ast hangupcause for hangup (see cause.h) */ 00766 int ast_softhangup_nolock(struct ast_channel *chan, int cause); 00767 00768 /*! \brief Check to see if a channel is needing hang up 00769 * \param chan channel on which to check for hang up 00770 * This function determines if the channel is being requested to be hung up. 00771 * \return Returns 0 if not, or 1 if hang up is requested (including time-out). 00772 */ 00773 int ast_check_hangup(struct ast_channel *chan); 00774 00775 /*! \brief Compare a offset with the settings of when to hang a channel up 00776 * \param chan channel on which to check for hang up 00777 * \param offset offset in seconds from current time 00778 * \return 1, 0, or -1 00779 * This function compares a offset from current time with the absolute time 00780 * out on a channel (when to hang up). If the absolute time out on a channel 00781 * is earlier than current time plus the offset, it returns 1, if the two 00782 * time values are equal, it return 0, otherwise, it retturn -1. 00783 */ 00784 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset); 00785 00786 /*! \brief Set when to hang a channel up 00787 * \param chan channel on which to check for hang up 00788 * \param offset offset in seconds from current time of when to hang up 00789 * This function sets the absolute time out on a channel (when to hang up). 00790 */ 00791 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset); 00792 00793 /*! \brief Answer a ringing call 00794 * \param chan channel to answer 00795 * This function answers a channel and handles all necessary call 00796 * setup functions. 00797 * \return Returns 0 on success, -1 on failure 00798 */ 00799 int ast_answer(struct ast_channel *chan); 00800 00801 /*! \brief Make a call 00802 * \param chan which channel to make the call on 00803 * \param addr destination of the call 00804 * \param timeout time to wait on for connect 00805 * Place a call, take no longer than timeout ms. 00806 \return Returns -1 on failure, 0 on not enough time 00807 (does not automatically stop ringing), and 00808 the number of seconds the connect took otherwise. 00809 */ 00810 int ast_call(struct ast_channel *chan, char *addr, int timeout); 00811 00812 /*! \brief Indicates condition of channel 00813 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel 00814 * \param chan channel to change the indication 00815 * \param condition which condition to indicate on the channel 00816 * \return Returns 0 on success, -1 on failure 00817 */ 00818 int ast_indicate(struct ast_channel *chan, int condition); 00819 00820 /*! \brief Indicates condition of channel, with payload 00821 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel 00822 * \param chan channel to change the indication 00823 * \param condition which condition to indicate on the channel 00824 * \param data pointer to payload data 00825 * \param datalen size of payload data 00826 * \return Returns 0 on success, -1 on failure 00827 */ 00828 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen); 00829 00830 /* Misc stuff ------------------------------------------------ */ 00831 00832 /*! \brief Wait for input on a channel 00833 * \param chan channel to wait on 00834 * \param ms length of time to wait on the channel 00835 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 00836 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */ 00837 int ast_waitfor(struct ast_channel *chan, int ms); 00838 00839 /*! \brief Wait for a specied amount of time, looking for hangups 00840 * \param chan channel to wait for 00841 * \param ms length of time in milliseconds to sleep 00842 * Waits for a specified amount of time, servicing the channel as required. 00843 * \return returns -1 on hangup, otherwise 0. 00844 */ 00845 int ast_safe_sleep(struct ast_channel *chan, int ms); 00846 00847 /*! \brief Wait for a specied amount of time, looking for hangups and a condition argument 00848 * \param chan channel to wait for 00849 * \param ms length of time in milliseconds to sleep 00850 * \param cond a function pointer for testing continue condition 00851 * \param data argument to be passed to the condition test function 00852 * \return returns -1 on hangup, otherwise 0. 00853 * Waits for a specified amount of time, servicing the channel as required. If cond 00854 * returns 0, this function returns. 00855 */ 00856 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data ); 00857 00858 /*! \brief Waits for activity on a group of channels 00859 * \param chan an array of pointers to channels 00860 * \param n number of channels that are to be waited upon 00861 * \param fds an array of fds to wait upon 00862 * \param nfds the number of fds to wait upon 00863 * \param exception exception flag 00864 * \param outfd fd that had activity on it 00865 * \param ms how long the wait was 00866 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds 00867 file descriptors. 00868 \return Returns the channel with activity, or NULL on error or if an FD 00869 came first. If the FD came first, it will be returned in outfd, otherwise, outfd 00870 will be -1 */ 00871 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms); 00872 00873 /*! \brief Waits for input on a group of channels 00874 Wait for input on an array of channels for a given # of milliseconds. 00875 \return Return channel with activity, or NULL if none has activity. 00876 \param chan an array of pointers to channels 00877 \param n number of channels that are to be waited upon 00878 \param ms time "ms" is modified in-place, if applicable */ 00879 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms); 00880 00881 /*! \brief Waits for input on an fd 00882 This version works on fd's only. Be careful with it. */ 00883 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception); 00884 00885 00886 /*! \brief Reads a frame 00887 * \param chan channel to read a frame from 00888 Read a frame. 00889 \return Returns a frame, or NULL on error. If it returns NULL, you 00890 best just stop reading frames and assume the channel has been 00891 disconnected. */ 00892 struct ast_frame *ast_read(struct ast_channel *chan); 00893 00894 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio. 00895 * Read a frame. 00896 \param chan channel to read a frame from 00897 \return Returns a frame, or NULL on error. If it returns NULL, you 00898 best just stop reading frames and assume the channel has been 00899 disconnected. 00900 \note Audio is replaced with AST_FRAME_NULL to avoid 00901 transcode when the resulting audio is not necessary. */ 00902 struct ast_frame *ast_read_noaudio(struct ast_channel *chan); 00903 00904 /*! \brief Write a frame to a channel 00905 * This function writes the given frame to the indicated channel. 00906 * \param chan destination channel of the frame 00907 * \param frame frame that will be written 00908 * \return It returns 0 on success, -1 on failure. 00909 */ 00910 int ast_write(struct ast_channel *chan, struct ast_frame *frame); 00911 00912 /*! \brief Write video frame to a channel 00913 * This function writes the given frame to the indicated channel. 00914 * \param chan destination channel of the frame 00915 * \param frame frame that will be written 00916 * \return It returns 1 on success, 0 if not implemented, and -1 on failure. 00917 */ 00918 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame); 00919 00920 /*! \brief Send empty audio to prime a channel driver */ 00921 int ast_prod(struct ast_channel *chan); 00922 00923 /*! \brief Sets read format on channel chan 00924 * Set read format for channel to whichever component of "format" is best. 00925 * \param chan channel to change 00926 * \param format format to change to 00927 * \return Returns 0 on success, -1 on failure 00928 */ 00929 int ast_set_read_format(struct ast_channel *chan, int format); 00930 00931 /*! \brief Gets read format from channel chan 00932 * \param chan channel to get info 00933 * Get read format for channel 00934 * Returns read format 00935 */ 00936 static inline int ast_get_read_format(struct ast_channel *chan) 00937 { 00938 return chan->readformat; 00939 } 00940 00941 /*! Gets write format from channel chan */ 00942 /*! 00943 * \param chan channel to get info 00944 * Get write format for channel 00945 * Returns write format 00946 */ 00947 static inline int ast_get_write_format(struct ast_channel *chan) 00948 { 00949 return chan->writeformat; 00950 } 00951 00952 00953 /*! \brief Sets write format on channel chan 00954 * Set write format for channel to whichever compoent of "format" is best. 00955 * \param chan channel to change 00956 * \param format new format for writing 00957 * \return Returns 0 on success, -1 on failure 00958 */ 00959 int ast_set_write_format(struct ast_channel *chan, int format); 00960 00961 /*! \brief Sends text to a channel 00962 * Write text to a display on a channel 00963 * \param chan channel to act upon 00964 * \param text string of text to send on the channel 00965 * \return Returns 0 on success, -1 on failure 00966 */ 00967 int ast_sendtext(struct ast_channel *chan, const char *text); 00968 00969 /*! \brief Receives a text character from a channel 00970 * \param chan channel to act upon 00971 * \param timeout timeout in milliseconds (0 for infinite wait) 00972 * Read a char of text from a channel 00973 * Returns 0 on success, -1 on failure 00974 */ 00975 int ast_recvchar(struct ast_channel *chan, int timeout); 00976 00977 /*! \brief Send a DTMF digit to a channel 00978 * Send a DTMF digit to a channel. 00979 * \param chan channel to act upon 00980 * \param digit the DTMF digit to send, encoded in ASCII 00981 * \return Returns 0 on success, -1 on failure 00982 */ 00983 int ast_senddigit(struct ast_channel *chan, char digit); 00984 00985 int ast_senddigit_begin(struct ast_channel *chan, char digit); 00986 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration); 00987 00988 /*! \brief Receives a text string from a channel 00989 * Read a string of text from a channel 00990 * \param chan channel to act upon 00991 * \param timeout timeout in milliseconds (0 for infinite wait) 00992 * \return the received text, or NULL to signify failure. 00993 */ 00994 char *ast_recvtext(struct ast_channel *chan, int timeout); 00995 00996 /*! \brief Browse channels in use 00997 * Browse the channels currently in use 00998 * \param prev where you want to start in the channel list 00999 * \return Returns the next channel in the list, NULL on end. 01000 * If it returns a channel, that channel *has been locked*! 01001 */ 01002 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev); 01003 01004 /*! \brief Get channel by name (locks channel) */ 01005 struct ast_channel *ast_get_channel_by_name_locked(const char *chan); 01006 01007 /*! \brief Get channel by name prefix (locks channel) */ 01008 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen); 01009 01010 /*! \brief Get channel by name prefix (locks channel) */ 01011 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen); 01012 01013 /*! \brief Get channel by exten (and optionally context) and lock it */ 01014 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context); 01015 01016 /*! \brief Get next channel by exten (and optionally context) and lock it */ 01017 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten, 01018 const char *context); 01019 01020 /*! ! \brief Waits for a digit 01021 * \param c channel to wait for a digit on 01022 * \param ms how many milliseconds to wait 01023 * \return Returns <0 on error, 0 on no entry, and the digit on success. */ 01024 int ast_waitfordigit(struct ast_channel *c, int ms); 01025 01026 /*! \brief Wait for a digit 01027 Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. 01028 * \param c channel to wait for a digit on 01029 * \param ms how many milliseconds to wait 01030 * \param audiofd audio file descriptor to write to if audio frames are received 01031 * \param ctrlfd control file descriptor to monitor for reading 01032 * \return Returns 1 if ctrlfd becomes available */ 01033 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd); 01034 01035 /*! Reads multiple digits 01036 * \param c channel to read from 01037 * \param s string to read in to. Must be at least the size of your length 01038 * \param len how many digits to read (maximum) 01039 * \param timeout how long to timeout between digits 01040 * \param rtimeout timeout to wait on the first digit 01041 * \param enders digits to end the string 01042 * Read in a digit string "s", max length "len", maximum timeout between 01043 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout 01044 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of 01045 a timeout, any digits that were read before the timeout will still be available in s. 01046 RETURNS 2 in full version when ctrlfd is available, NOT 1*/ 01047 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders); 01048 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd); 01049 01050 /*! \brief Report DTMF on channel 0 */ 01051 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0) 01052 /*! \brief Report DTMF on channel 1 */ 01053 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1) 01054 /*! \brief Return all voice frames on channel 0 */ 01055 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2) 01056 /*! \brief Return all voice frames on channel 1 */ 01057 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3) 01058 /*! \brief Ignore all signal frames except NULL */ 01059 #define AST_BRIDGE_IGNORE_SIGS (1 << 4) 01060 01061 01062 /*! \brief Makes two channel formats compatible 01063 * \param c0 first channel to make compatible 01064 * \param c1 other channel to make compatible 01065 * Set two channels to compatible formats -- call before ast_channel_bridge in general . 01066 * \return Returns 0 on success and -1 if it could not be done */ 01067 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1); 01068 01069 /*! Bridge two channels together 01070 * \param c0 first channel to bridge 01071 * \param c1 second channel to bridge 01072 * \param config config for the channels 01073 * \param fo destination frame(?) 01074 * \param rc destination channel(?) 01075 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in 01076 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */ 01077 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */ 01078 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc); 01079 01080 /*! \brief Weird function made for call transfers 01081 * \param original channel to make a copy of 01082 * \param clone copy of the original channel 01083 * This is a very strange and freaky function used primarily for transfer. Suppose that 01084 "original" and "clone" are two channels in random situations. This function takes 01085 the guts out of "clone" and puts them into the "original" channel, then alerts the 01086 channel driver of the change, asking it to fixup any private information (like the 01087 p->owner pointer) that is affected by the change. The physical layer of the original 01088 channel is hung up. */ 01089 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone); 01090 01091 /*! Gives the string form of a given cause code */ 01092 /*! 01093 * \param state cause to get the description of 01094 * Give a name to a cause code 01095 * Returns the text form of the binary cause code given 01096 */ 01097 const char *ast_cause2str(int state) attribute_pure; 01098 01099 /*! Convert the string form of a cause code to a number */ 01100 /*! 01101 * \param name string form of the cause 01102 * Returns the cause code 01103 */ 01104 int ast_str2cause(const char *name) attribute_pure; 01105 01106 /*! Gives the string form of a given channel state */ 01107 /*! 01108 * \param ast_channel_state state to get the name of 01109 * Give a name to a state 01110 * Returns the text form of the binary state given 01111 */ 01112 char *ast_state2str(enum ast_channel_state); 01113 01114 /*! Gives the string form of a given transfer capability */ 01115 /*! 01116 * \param transfercapability transfercapabilty to get the name of 01117 * Give a name to a transfercapbility 01118 * See above 01119 * Returns the text form of the binary transfer capbility 01120 */ 01121 char *ast_transfercapability2str(int transfercapability) attribute_const; 01122 01123 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the 01124 low level channel. See frame.h for options. Note that many channel drivers may support 01125 none or a subset of those features, and you should not count on this if you want your 01126 asterisk application to be portable. They're mainly useful for tweaking performance */ 01127 01128 /*! Sets an option on a channel */ 01129 /*! 01130 * \param channel channel to set options on 01131 * \param option option to change 01132 * \param data data specific to option 01133 * \param datalen length of the data 01134 * \param block blocking or not 01135 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 01136 * Returns 0 on success and -1 on failure 01137 */ 01138 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block); 01139 01140 /*! Pick the best codec */ 01141 /* Choose the best codec... Uhhh... Yah. */ 01142 int ast_best_codec(int fmts); 01143 01144 /*! 01145 * \brief Pick the best codec from channel nativeformats 01146 * \param channel channel, from that nativeformats used 01147 */ 01148 static inline int ast_channel_best_codec(struct ast_channel *channel) 01149 { 01150 #ifndef BUG_4825 01151 return ast_best_codec(channel->nativeformats); 01152 #else 01153 return ast_best_codec(channel->nativeformats.audio_bits); 01154 #endif 01155 } 01156 /*! \brief Get the names of a set of formats 01157 * \param buf a buffer for the output string 01158 * \param size size of buf (bytes) 01159 * \param channel the channel 01160 * Prints a list of readable codec names corresponding to "format". 01161 * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)" 01162 * \return The return value is buf. 01163 */ 01164 inline static char * ast_channel_getformatname_multiple(char *buf, size_t size, struct ast_channel *chan) 01165 { 01166 return ast_getformatname_multiple(buf, size, chan->nativeformats); 01167 } 01168 01169 01170 static inline const char * ast_channel_getformatname(struct ast_channel *chan) 01171 { 01172 #ifndef BUG_4825 01173 return chan ? ast_getformatname(chan->nativeformats) : "undefined"; 01174 #else 01175 return chan ? ast_getformatname(chan->nativeformats.audio_bits) : "undefined"; 01176 #endif 01177 } 01178 01179 static inline void ast_channel_formats_reset(struct ast_channel *channel) 01180 { 01181 int r, w; 01182 r = ast_get_read_format(channel); 01183 w = ast_get_write_format(channel); 01184 01185 if (option_debug) 01186 ast_log(LOG_DEBUG, "Resetting read to %d and write to %d on channel %s\n", r, w, channel->name); 01187 if (r) 01188 ast_set_read_format(channel, r); 01189 if (w) 01190 ast_set_write_format(channel, w); 01191 } 01192 01193 /*! 01194 * \brief Set best format, identical to read/write 01195 * \param channel channel, from that nativeformats used and formats set 01196 */ 01197 static inline void ast_set_best_format(struct ast_channel *channel) 01198 { 01199 int format = ast_channel_best_codec(channel); 01200 ast_set_read_format(channel, format); 01201 ast_set_write_format(channel, format); 01202 } 01203 01204 /*! Checks the value of an option */ 01205 /*! 01206 * Query the value of an option, optionally blocking until a reply is received 01207 * Works similarly to setoption except only reads the options. 01208 */ 01209 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block); 01210 01211 /*! Checks for HTML support on a channel */ 01212 /*! Returns 0 if channel does not support HTML or non-zero if it does */ 01213 int ast_channel_supports_html(struct ast_channel *channel); 01214 01215 /*! Sends HTML on given channel */ 01216 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */ 01217 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen); 01218 01219 /*! Sends a URL on a given link */ 01220 /*! Send URL on link. Returns 0 on success or -1 on failure */ 01221 int ast_channel_sendurl(struct ast_channel *channel, const char *url); 01222 01223 /*! Defers DTMF */ 01224 /*! Defer DTMF so that you only read things like hangups and audio. Returns 01225 non-zero if channel was already DTMF-deferred or 0 if channel is just now 01226 being DTMF-deferred */ 01227 int ast_channel_defer_dtmf(struct ast_channel *chan); 01228 01229 /*! Undeos a defer */ 01230 /*! Undo defer. ast_read will return any dtmf characters that were queued */ 01231 void ast_channel_undefer_dtmf(struct ast_channel *chan); 01232 01233 /*! Initiate system shutdown -- prevents new channels from being allocated. 01234 If "hangup" is non-zero, all existing channels will receive soft 01235 hangups */ 01236 void ast_begin_shutdown(int hangup); 01237 01238 /*! Cancels an existing shutdown and returns to normal operation */ 01239 void ast_cancel_shutdown(void); 01240 01241 /*! Returns number of active/allocated channels */ 01242 int ast_active_channels(void); 01243 01244 /*! Returns non-zero if Asterisk is being shut down */ 01245 int ast_shutting_down(void); 01246 01247 /*! Activate a given generator */ 01248 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params); 01249 01250 /*! Deactive an active generator */ 01251 void ast_deactivate_generator(struct ast_channel *chan); 01252 01253 /*! 01254 * \note The channel does not need to be locked before calling this function. 01255 */ 01256 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani); 01257 01258 01259 /*! return a mallocd string with the result of sprintf of the fmt and following args */ 01260 char __attribute__((format(printf, 1, 2))) *ast_safe_string_alloc(const char *fmt, ...); 01261 01262 01263 /*! Start a tone going */ 01264 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 01265 /*! Stop a tone from playing */ 01266 void ast_tonepair_stop(struct ast_channel *chan); 01267 /*! Play a tone pair for a given amount of time */ 01268 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 01269 01270 /*! 01271 * \brief Automatically service a channel for us... 01272 * 01273 * \retval 0 success 01274 * \retval -1 failure, or the channel is already being autoserviced 01275 */ 01276 int ast_autoservice_start(struct ast_channel *chan); 01277 01278 /*! 01279 * \brief Stop servicing a channel for us... 01280 * 01281 * \note if chan is locked prior to calling ast_autoservice_stop, it 01282 * is likely that there will be a deadlock between the thread that calls 01283 * ast_autoservice_stop and the autoservice thread. It is important 01284 * that chan is not locked prior to this call 01285 * 01286 * \retval 0 success 01287 * \retval -1 error, or the channel has been hungup 01288 */ 01289 int ast_autoservice_stop(struct ast_channel *chan); 01290 01291 /* If built with DAHDI optimizations, force a scheduled expiration on the 01292 timer fd, at which point we call the callback function / data */ 01293 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data); 01294 01295 /*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported 01296 and 1 if supported and requested 01297 \param chan current channel 01298 \param dest destination extension for transfer 01299 */ 01300 int ast_transfer(struct ast_channel *chan, char *dest); 01301 01302 /*! \brief Start masquerading a channel 01303 XXX This is a seriously wacked out operation. We're essentially putting the guts of 01304 the clone channel into the original channel. Start by killing off the original 01305 channel's backend. I'm not sure we're going to keep this function, because 01306 while the features are nice, the cost is very high in terms of pure nastiness. XXX 01307 \param chan Channel to masquerade 01308 */ 01309 int ast_do_masquerade(struct ast_channel *chan); 01310 01311 /*! \brief Find bridged channel 01312 \param chan Current channel 01313 */ 01314 struct ast_channel *ast_bridged_channel(struct ast_channel *chan); 01315 01316 /*! 01317 \brief Inherits channel variable from parent to child channel 01318 \param parent Parent channel 01319 \param child Child channel 01320 01321 Scans all channel variables in the parent channel, looking for those 01322 that should be copied into the child channel. 01323 Variables whose names begin with a single '_' are copied into the 01324 child channel with the prefix removed. 01325 Variables whose names begin with '__' are copied into the child 01326 channel with their names unchanged. 01327 */ 01328 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child); 01329 01330 /*! 01331 \brief adds a list of channel variables to a channel 01332 \param chan the channel 01333 \param vars a linked list of variables 01334 01335 Variable names can be for a regular channel variable or a dialplan function 01336 that has the ability to be written to. 01337 */ 01338 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars); 01339 01340 /*! 01341 \brief An opaque 'object' structure use by silence generators on channels. 01342 */ 01343 struct ast_silence_generator; 01344 01345 /*! 01346 \brief Starts a silence generator on the given channel. 01347 \param chan The channel to generate silence on 01348 \return An ast_silence_generator pointer, or NULL if an error occurs 01349 01350 This function will cause SLINEAR silence to be generated on the supplied 01351 channel until it is disabled; if the channel cannot be put into SLINEAR 01352 mode then the function will fail. 01353 01354 The pointer returned by this function must be preserved and passed to 01355 ast_channel_stop_silence_generator when you wish to stop the silence 01356 generation. 01357 */ 01358 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan); 01359 01360 /*! 01361 \brief Stops a previously-started silence generator on the given channel. 01362 \param chan The channel to operate on 01363 \param state The ast_silence_generator pointer return by a previous call to 01364 ast_channel_start_silence_generator. 01365 \return nothing 01366 01367 This function will stop the operating silence generator and return the channel 01368 to its previous write format. 01369 */ 01370 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state); 01371 01372 /*! 01373 \brief Check if the channel can run in internal timing mode. 01374 \param chan The channel to check 01375 \return boolean 01376 01377 This function will return 1 if internal timing is enabled and the timing 01378 device is available. 01379 */ 01380 int ast_internal_timing_enabled(struct ast_channel *chan); 01381 01382 /* Misc. functions below */ 01383 01384 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor 01385 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the 01386 * return value to the index into the array) 01387 */ 01388 static inline int ast_add_fd(struct pollfd *pfd, int fd) 01389 { 01390 pfd->fd = fd; 01391 pfd->events = POLLIN | POLLPRI; 01392 return fd >= 0; 01393 } 01394 01395 /*! \brief Helper function for migrating select to poll */ 01396 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start) 01397 { 01398 int x; 01399 int dummy=0; 01400 01401 if (fd < 0) 01402 return 0; 01403 if (!start) 01404 start = &dummy; 01405 for (x = *start; x<max; x++) 01406 if (pfds[x].fd == fd) { 01407 if (x == *start) 01408 (*start)++; 01409 return pfds[x].revents; 01410 } 01411 return 0; 01412 } 01413 01414 #ifndef HAVE_TIMERSUB 01415 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff) 01416 { 01417 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec; 01418 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec; 01419 if (tvdiff->tv_usec < 0) { 01420 tvdiff->tv_sec --; 01421 tvdiff->tv_usec += 1000000; 01422 } 01423 01424 } 01425 #endif 01426 01427 /*! \brief Waits for activity on a group of channels 01428 * \param nfds the maximum number of file descriptors in the sets 01429 * \param rfds file descriptors to check for read availability 01430 * \param wfds file descriptors to check for write availability 01431 * \param efds file descriptors to check for exceptions (OOB data) 01432 * \param tvp timeout while waiting for events 01433 * This is the same as a standard select(), except it guarantees the 01434 * behaviour where the passed struct timeval is updated with how much 01435 * time was not slept while waiting for the specified events 01436 */ 01437 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp) 01438 { 01439 #ifdef __linux__ 01440 return select(nfds, rfds, wfds, efds, tvp); 01441 #else 01442 if (tvp) { 01443 struct timeval tv, tvstart, tvend, tvlen; 01444 int res; 01445 01446 tv = *tvp; 01447 gettimeofday(&tvstart, NULL); 01448 res = select(nfds, rfds, wfds, efds, tvp); 01449 gettimeofday(&tvend, NULL); 01450 timersub(&tvend, &tvstart, &tvlen); 01451 timersub(&tv, &tvlen, tvp); 01452 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) { 01453 tvp->tv_sec = 0; 01454 tvp->tv_usec = 0; 01455 } 01456 return res; 01457 } 01458 else 01459 return select(nfds, rfds, wfds, efds, NULL); 01460 #endif 01461 } 01462 01463 #define CHECK_BLOCKING(c) do { \ 01464 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\ 01465 if (option_debug) \ 01466 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); \ 01467 } else { \ 01468 (c)->blocker = pthread_self(); \ 01469 (c)->blockproc = __PRETTY_FUNCTION__; \ 01470 ast_set_flag(c, AST_FLAG_BLOCKING); \ 01471 } } while (0) 01472 01473 ast_group_t ast_get_group(const char *s); 01474 01475 /*! \brief print call- and pickup groups into buffer */ 01476 char *ast_print_group(char *buf, int buflen, ast_group_t group); 01477 01478 /*! \brief Convert enum channelreloadreason to text string for manager event 01479 \param reason Enum channelreloadreason - reason for reload (manager, cli, start etc) 01480 */ 01481 const char *channelreloadreason2txt(enum channelreloadreason reason); 01482 01483 /*! \brief return an ast_variable list of channeltypes */ 01484 struct ast_variable *ast_channeltype_list(void); 01485 01486 /*! 01487 \brief Begin 'whispering' onto a channel 01488 \param chan The channel to whisper onto 01489 \return 0 for success, non-zero for failure 01490 01491 This function will add a whisper buffer onto a channel and set a flag 01492 causing writes to the channel to reduce the volume level of the written 01493 audio samples, and then to mix in audio from the whisper buffer if it 01494 is available. 01495 01496 Note: This function performs no locking; you must hold the channel's lock before 01497 calling this function. 01498 */ 01499 int ast_channel_whisper_start(struct ast_channel *chan); 01500 01501 /*! 01502 \brief Feed an audio frame into the whisper buffer on a channel 01503 \param chan The channel to whisper onto 01504 \param f The frame to to whisper onto chan 01505 \return 0 for success, non-zero for failure 01506 */ 01507 int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f); 01508 01509 /*! 01510 \brief Stop 'whispering' onto a channel 01511 \param chan The channel to whisper onto 01512 \return 0 for success, non-zero for failure 01513 01514 Note: This function performs no locking; you must hold the channel's lock before 01515 calling this function. 01516 */ 01517 void ast_channel_whisper_stop(struct ast_channel *chan); 01518 01519 01520 01521 /*! 01522 \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument 01523 \param reason The integer argument, usually taken from AST_CONTROL_ macros 01524 \return char pointer explaining the code 01525 */ 01526 char *ast_channel_reason2str(int reason); 01527 01528 01529 #if defined(__cplusplus) || defined(c_plusplus) 01530 } 01531 #endif 01532 01533 #endif /* _ASTERISK_CHANNEL_H */
1.5.9