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