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