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