00001 /* 00002 * Asterisk -- A telephony toolkit for Linux. 00003 * 00004 * General Asterisk channel definitions. 00005 * 00006 * Copyright (C) 1999, Mark Spencer 00007 * 00008 * Mark Spencer <markster@linux-support.net> 00009 * 00010 * This program is free software, distributed under the terms of 00011 * the GNU General Public License 00012 */ 00013 00014 #ifndef _ASTERISK_CHANNEL_H 00015 #define _ASTERISK_CHANNEL_H 00016 00017 #include <asterisk/frame.h> 00018 #include <asterisk/sched.h> 00019 #include <asterisk/chanvars.h> 00020 #include <unistd.h> 00021 #include <setjmp.h> 00022 #include <pthread.h> 00023 00024 #if defined(__cplusplus) || defined(c_plusplus) 00025 extern "C" { 00026 #endif 00027 00028 #include <asterisk/lock.h> 00029 00030 //! Max length of an extension 00031 #define AST_MAX_EXTENSION 80 00032 00033 #include <asterisk/cdr.h> 00034 #include <asterisk/monitor.h> 00035 00036 00037 #define AST_CHANNEL_NAME 80 00038 #define AST_CHANNEL_MAX_STACK 32 00039 00040 #define MAX_LANGUAGE 20 00041 00042 00043 #define AST_MAX_FDS 8 00044 00045 struct ast_generator { 00046 void *(*alloc)(struct ast_channel *chan, void *params); 00047 void (*release)(struct ast_channel *chan, void *data); 00048 int (*generate)(struct ast_channel *chan, void *data, int len, int samples); 00049 }; 00050 00051 //! Main Channel structure associated with a channel. 00052 /*! 00053 * This is the side of it mostly used by the pbx and call management. 00054 */ 00055 struct ast_channel { 00056 /*! ASCII Description of channel name */ 00057 char name[AST_CHANNEL_NAME]; 00058 /*! Language requested */ 00059 char language[MAX_LANGUAGE]; 00060 /*! Type of channel */ 00061 char *type; 00062 /*! File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1. */ 00063 int fds[AST_MAX_FDS]; 00064 00065 /*! Default music class */ 00066 char musicclass[MAX_LANGUAGE]; 00067 00068 /*! Current generator data if there is any */ 00069 void *generatordata; 00070 /*! Current active data generator */ 00071 struct ast_generator *generator; 00072 /*! Whether or not the generator should be interrupted by write */ 00073 int writeinterrupt; 00074 00075 /*! Who are we bridged to, if we're bridged */ 00076 struct ast_channel *bridge; 00077 /*! Who did we call? */ 00078 struct ast_channel *dialed; 00079 /*! Who called us? */ 00080 struct ast_channel *dialing; 00081 /*! Reverse the dialed link (0 false, 1 true) */ 00082 int reversedialed; 00083 /*! Channel that will masquerade as us */ 00084 struct ast_channel *masq; 00085 /*! Who we are masquerading as */ 00086 struct ast_channel *masqr; 00087 /*! Call Detail Record Flags */ 00088 int cdrflags; 00089 /*! Whether or not we're blocking */ 00090 int blocking; 00091 /*! Whether or not we have been hung up... Do not set this value 00092 directly, use ast_softhangup */ 00093 int _softhangup; 00094 /*! Non-zero if this is a zombie channel */ 00095 int zombie; 00096 /*! Non-zero, set to actual time when channel is to be hung up */ 00097 time_t whentohangup; 00098 /*! If anyone is blocking, this is them */ 00099 pthread_t blocker; 00100 /*! Lock, can be used to lock a channel for some operations */ 00101 ast_mutex_t lock; 00102 /*! Procedure causing blocking */ 00103 char *blockproc; 00104 00105 /*! Current application */ 00106 char *appl; 00107 /*! Data passed to current application */ 00108 char *data; 00109 00110 /*! Has an exception been detected */ 00111 int exception; 00112 /*! Which fd had an event detected on */ 00113 int fdno; 00114 /*! Schedule context */ 00115 struct sched_context *sched; 00116 /*! For streaming playback, the schedule ID */ 00117 int streamid; 00118 /*! Stream itself. */ 00119 struct ast_filestream *stream; 00120 /*! For streaming playback, the schedule ID */ 00121 int vstreamid; 00122 /*! Stream itself. */ 00123 struct ast_filestream *vstream; 00124 /*! Original writer format */ 00125 int oldwriteformat; 00126 00127 /*! Timing fd */ 00128 int timingfd; 00129 int (*timingfunc)(void *data); 00130 void *timingdata; 00131 00132 /*! State of line -- Don't write directly, use ast_setstate */ 00133 int _state; 00134 /*! Number of rings so far */ 00135 int rings; 00136 /*! Current level of application */ 00137 int stack; 00138 00139 00140 /*! Kinds of data this channel can natively handle */ 00141 int nativeformats; 00142 /*! Requested read format */ 00143 int readformat; 00144 /*! Requested write format */ 00145 int writeformat; 00146 00147 00148 /*! Malloc'd Dialed Number Identifier */ 00149 char *dnid; 00150 /*! Malloc'd Caller ID */ 00151 char *callerid; 00152 /*! Malloc'd ANI */ 00153 char *ani; 00154 /*! Malloc'd RDNIS */ 00155 char *rdnis; 00156 /*! Hide callerid from user */ 00157 int restrictcid; 00158 00159 00160 /*! Current extension context */ 00161 char context[AST_MAX_EXTENSION]; 00162 /*! Current non-macro context */ 00163 char macrocontext[AST_MAX_EXTENSION]; 00164 /*! Current non-macro extension */ 00165 char macroexten[AST_MAX_EXTENSION]; 00166 /*! Current non-macro priority */ 00167 int macropriority; 00168 /*! Current extension number */ 00169 char exten[AST_MAX_EXTENSION]; 00170 /* Current extension priority */ 00171 int priority; 00172 /*! Application information -- see assigned numbers */ 00173 void *app[AST_CHANNEL_MAX_STACK]; 00174 /*! Any/all queued DTMF characters */ 00175 char dtmfq[AST_MAX_EXTENSION]; 00176 /*! Are DTMF digits being deferred */ 00177 int deferdtmf; 00178 /*! DTMF frame */ 00179 struct ast_frame dtmff; 00180 /*! Private channel implementation details */ 00181 struct ast_channel_pvt *pvt; 00182 00183 00184 /*! Jump buffer used for returning from applications */ 00185 jmp_buf jmp[AST_CHANNEL_MAX_STACK]; 00186 00187 struct ast_pbx *pbx; 00188 /*! Set BEFORE PBX is started to determine AMA flags */ 00189 int amaflags; 00190 /*! Account code for billing */ 00191 char accountcode[20]; 00192 /*! Call Detail Record */ 00193 struct ast_cdr *cdr; 00194 /*! Whether or not ADSI is detected on CPE */ 00195 int adsicpe; 00196 /*! Where to forward to if asked to dial on this interface */ 00197 char call_forward[AST_MAX_EXTENSION]; 00198 00199 /*! Tone zone */ 00200 struct tone_zone *zone; 00201 00202 /* Channel monitoring */ 00203 struct ast_channel_monitor *monitor; 00204 00205 /*! Track the read/written samples for monitor use */ 00206 unsigned long insmpl; 00207 unsigned long outsmpl; 00208 00209 /* Frames in/out counters */ 00210 unsigned int fin; 00211 unsigned int fout; 00212 00213 /* Unique Channel Identifier */ 00214 char uniqueid[32]; 00215 00216 /* A linked list for variables */ 00217 struct ast_var_t *vars; 00218 AST_LIST_HEAD(varshead,ast_var_t) varshead; 00219 00220 unsigned int callgroup; 00221 unsigned int pickupgroup; 00222 00223 /*! For easy linking */ 00224 struct ast_channel *next; 00225 00226 }; 00227 00228 struct chanmon; 00229 00230 #define AST_CDR_TRANSFER (1 << 0) 00231 #define AST_CDR_FORWARD (1 << 1) 00232 #define AST_CDR_CALLWAIT (1 << 2) 00233 #define AST_CDR_CONFERENCE (1 << 3) 00234 00235 #define AST_ADSI_UNKNOWN (0) 00236 #define AST_ADSI_AVAILABLE (1) 00237 #define AST_ADSI_UNAVAILABLE (2) 00238 #define AST_ADSI_OFFHOOKONLY (3) 00239 00240 #define AST_SOFTHANGUP_DEV (1 << 0) /* Soft hangup by device */ 00241 #define AST_SOFTHANGUP_ASYNCGOTO (1 << 1) /* Soft hangup for async goto */ 00242 #define AST_SOFTHANGUP_SHUTDOWN (1 << 2) 00243 #define AST_SOFTHANGUP_TIMEOUT (1 << 3) 00244 #define AST_SOFTHANGUP_APPUNLOAD (1 << 4) 00245 #define AST_SOFTHANGUP_EXPLICIT (1 << 5) 00246 00247 /* Bits 0-15 of state are reserved for the state (up/down) of the line */ 00248 /*! Channel is down and available */ 00249 #define AST_STATE_DOWN 0 00250 /*! Channel is down, but reserved */ 00251 #define AST_STATE_RESERVED 1 00252 /*! Channel is off hook */ 00253 #define AST_STATE_OFFHOOK 2 00254 /*! Digits (or equivalent) have been dialed */ 00255 #define AST_STATE_DIALING 3 00256 /*! Line is ringing */ 00257 #define AST_STATE_RING 4 00258 /*! Remote end is ringing */ 00259 #define AST_STATE_RINGING 5 00260 /*! Line is up */ 00261 #define AST_STATE_UP 6 00262 /*! Line is busy */ 00263 #define AST_STATE_BUSY 7 00264 00265 /* Bits 16-32 of state are reserved for flags */ 00266 /*! Do not transmit voice data */ 00267 #define AST_STATE_MUTE (1 << 16) 00268 00269 /*! Device is valid but channel didn't know state */ 00270 #define AST_DEVICE_UNKNOWN 0 00271 /*! Device is not used */ 00272 #define AST_DEVICE_NOT_INUSE 1 00273 /*! Device is in use */ 00274 #define AST_DEVICE_INUSE 2 00275 /*! Device is busy */ 00276 #define AST_DEVICE_BUSY 3 00277 /*! Device is invalid */ 00278 #define AST_DEVICE_INVALID 4 00279 /*! Device is unavailable */ 00280 #define AST_DEVICE_UNAVAILABLE 5 00281 00282 //! Requests a channel 00283 /*! 00284 * \param type type of channel to request 00285 * \param format requested channel format 00286 * \param data data to pass to the channel requester 00287 * Request a channel of a given type, with data as optional information used 00288 * by the low level module 00289 * Returns an ast_channel on success, NULL on failure. 00290 */ 00291 struct ast_channel *ast_request(char *type, int format, void *data); 00292 00293 //! Search the Channels by Name 00294 /*! 00295 * \param device like a dialstring 00296 * Search the Device in active channels by compare the channelname against 00297 * the devicename. Compared are only the first chars to the first '-' char. 00298 * Returns an AST_DEVICE_UNKNOWN if no channel found or 00299 * AST_DEVICE_INUSE if a channel is found 00300 */ 00301 int ast_parse_device_state(char *device); 00302 00303 //! Asks a channel for device state 00304 /*! 00305 * \param device like a dialstring 00306 * Asks a channel for device state, data is normaly a number from dialstring 00307 * used by the low level module 00308 * Trys the channel devicestate callback if not supported search in the 00309 * active channels list for the device. 00310 * Returns an AST_DEVICE_??? state -1 on failure 00311 */ 00312 int ast_device_state(char *device); 00313 00314 /*! 00315 * \param type type of channel to request 00316 * \param format requested channel format 00317 * \param data data to pass to the channel requester 00318 * \param timeout maximum amount of time to wait for an answer 00319 * \param why unsuccessful (if unsuceessful) 00320 * Request a channel of a given type, with data as optional information used 00321 * by the low level module and attempt to place a call on it 00322 * Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state 00323 * to know if the call was answered or not. 00324 */ 00325 struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int timeout, int *reason, char *callerid); 00326 00327 //! Registers a channel 00328 /*! 00329 * \param type type of channel you are registering 00330 * \param description short description of the channel 00331 * \param capabilities a bit mask of the capabilities of the channel 00332 * \param requester a function pointer that properly responds to a call. See one of the channel drivers for details. 00333 * Called by a channel module to register the kind of channels it supports. 00334 * It supplies a brief type, a longer, but still short description, and a 00335 * routine that creates a channel 00336 * Returns 0 on success, -1 on failure. 00337 */ 00338 int ast_channel_register(char *type, char *description, int capabilities, 00339 struct ast_channel* (*requester)(char *type, int format, void *data)); 00340 00341 /* Same like the upper function but with support for devicestate */ 00342 int ast_channel_register_ex(char *type, char *description, int capabilities, 00343 struct ast_channel *(*requester)(char *type, int format, void *data), 00344 int (*devicestate)(void *data)); 00345 00346 //! Unregister a channel class 00347 /* 00348 * \param type the character string that corresponds to the channel you wish to unregister 00349 * Basically just unregisters the channel with the asterisk channel system 00350 * No return value. 00351 */ 00352 void ast_channel_unregister(char *type); 00353 00354 //! Hang up a channel 00355 /*! 00356 * \param chan channel to hang up 00357 * This function performs a hard hangup on a channel. Unlike the soft-hangup, this function 00358 * performs all stream stopping, etc, on the channel that needs to end. 00359 * chan is no longer valid after this call. 00360 * Returns 0 on success, -1 on failure. 00361 */ 00362 int ast_hangup(struct ast_channel *chan); 00363 00364 //! Softly hangup up a channel 00365 /*! 00366 * \param chan channel to be soft-hung-up 00367 * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to 00368 * safely hangup a channel managed by another thread. 00369 * Returns 0 regardless 00370 */ 00371 int ast_softhangup(struct ast_channel *chan, int cause); 00372 int ast_softhangup_nolock(struct ast_channel *chan, int cause); 00373 00374 //! Check to see if a channel is needing hang up 00375 /*! 00376 * \param chan channel on which to check for hang up 00377 * This function determines if the channel is being requested to be hung up. 00378 * Returns 0 if not, or 1 if hang up is requested (including time-out). 00379 */ 00380 int ast_check_hangup(struct ast_channel *chan); 00381 00382 //! Set when to hang a channel up 00383 /*! 00384 * \param chan channel on which to check for hang up 00385 * \param offset offset in seconds from current time of when to hang up 00386 * This function sets the absolute time out on a channel (when to hang up). 00387 */ 00388 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset); 00389 00390 //! Answer a ringing call 00391 /*! 00392 * \param chan channel to answer 00393 * This function answers a channel and handles all necessary call 00394 * setup functions. 00395 * Returns 0 on success, -1 on failure 00396 */ 00397 int ast_answer(struct ast_channel *chan); 00398 00399 //! Make a call 00400 /*! 00401 * \param chan which channel to make the call on 00402 * \param addr destination of the call 00403 * \param timeout time to wait on for connect 00404 * Place a call, take no longer than timeout ms. Returns -1 on failure, 00405 0 on not enough time (does not auto matically stop ringing), and 00406 the number of seconds the connect took otherwise. 00407 Returns 0 on success, -1 on failure 00408 */ 00409 int ast_call(struct ast_channel *chan, char *addr, int timeout); 00410 00411 //! Indicates condition of channel 00412 /*! 00413 * \param chan channel to change the indication 00414 * \param condition which condition to indicate on the channel 00415 * Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel 00416 * Returns 0 on success, -1 on failure 00417 */ 00418 int ast_indicate(struct ast_channel *chan, int condition); 00419 00420 /* Misc stuff */ 00421 00422 //! Wait for input on a channel 00423 /*! 00424 * \param chan channel to wait on 00425 * \param ms length of time to wait on the channel 00426 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 00427 Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */ 00428 int ast_waitfor(struct ast_channel *chan, int ms); 00429 00430 //! Wait for a specied amount of time, looking for hangups 00431 /*! 00432 * \param chan channel to wait for 00433 * \param ms length of time in milliseconds to sleep 00434 * Waits for a specified amount of time, servicing the channel as required. 00435 * returns -1 on hangup, otherwise 0. 00436 */ 00437 int ast_safe_sleep(struct ast_channel *chan, int ms); 00438 00439 //! Wait for a specied amount of time, looking for hangups and a condition argument 00440 /*! 00441 * \param chan channel to wait for 00442 * \param ms length of time in milliseconds to sleep 00443 * \param cond a function pointer for testing continue condition 00444 * \param data argument to be passed to the condition test function 00445 * Waits for a specified amount of time, servicing the channel as required. If cond 00446 * returns 0, this function returns. 00447 * returns -1 on hangup, otherwise 0. 00448 */ 00449 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data ); 00450 00451 //! Waits for activity on a group of channels 00452 /*! 00453 * \param chan an array of pointers to channels 00454 * \param n number of channels that are to be waited upon 00455 * \param fds an array of fds to wait upon 00456 * \param nfds the number of fds to wait upon 00457 * \param exception exception flag 00458 * \param outfd fd that had activity on it 00459 * \param ms how long the wait was 00460 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds 00461 file descriptors. Returns the channel with activity, or NULL on error or if an FD 00462 came first. If the FD came first, it will be returned in outfd, otherwise, outfd 00463 will be -1 */ 00464 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms); 00465 00466 //! Waits for input on a group of channels 00467 /*! Wait for input on an array of channels for a given # of milliseconds. Return channel 00468 with activity, or NULL if none has activity. time "ms" is modified in-place, if applicable */ 00469 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms); 00470 00471 //! Waits for input on an fd 00472 /*! This version works on fd's only. Be careful with it. */ 00473 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception); 00474 00475 00476 //! Reads a frame 00477 /*! 00478 * \param chan channel to read a frame from 00479 * Read a frame. Returns a frame, or NULL on error. If it returns NULL, you 00480 best just stop reading frames and assume the channel has been 00481 disconnected. */ 00482 struct ast_frame *ast_read(struct ast_channel *chan); 00483 00484 //! Write a frame to a channel 00485 /*! 00486 * \param chan destination channel of the frame 00487 * \param frame frame that will be written 00488 * This function writes the given frame to the indicated channel. 00489 * It returns 0 on success, -1 on failure. 00490 */ 00491 int ast_write(struct ast_channel *chan, struct ast_frame *frame); 00492 00493 //! Write video frame to a channel 00494 /*! 00495 * \param chan destination channel of the frame 00496 * \param frame frame that will be written 00497 * This function writes the given frame to the indicated channel. 00498 * It returns 1 on success, 0 if not implemented, and -1 on failure. 00499 */ 00500 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame); 00501 00502 /* Send empty audio to prime a channel driver */ 00503 int ast_prod(struct ast_channel *chan); 00504 00505 //! Sets read format on channel chan 00506 /*! 00507 * \param chan channel to change 00508 * \param format format to change to 00509 * Set read format for channel to whichever component of "format" is best. 00510 * Returns 0 on success, -1 on failure 00511 */ 00512 int ast_set_read_format(struct ast_channel *chan, int format); 00513 00514 //! Sets write format on channel chan 00515 /*! 00516 * \param chan channel to change 00517 * \param format new format for writing 00518 * Set write format for channel to whichever compoent of "format" is best. 00519 * Returns 0 on success, -1 on failure 00520 */ 00521 int ast_set_write_format(struct ast_channel *chan, int format); 00522 00523 //! Sends text to a channel 00524 /*! 00525 * \param chan channel to act upon 00526 * \param text string of text to send on the channel 00527 * Write text to a display on a channel 00528 * Returns 0 on success, -1 on failure 00529 */ 00530 int ast_sendtext(struct ast_channel *chan, char *text); 00531 00532 //! Receives a text character from a channel 00533 /*! 00534 * \param chan channel to act upon 00535 * \param timeout timeout in milliseconds (0 for infinite wait) 00536 * Read a char of text from a channel 00537 * Returns 0 on success, -1 on failure 00538 */ 00539 int ast_recvchar(struct ast_channel *chan, int timeout); 00540 00541 //! Browse channels in use 00542 /*! 00543 * \param prev where you want to start in the channel list 00544 * Browse the channels currently in use 00545 * Returns the next channel in the list, NULL on end. 00546 */ 00547 struct ast_channel *ast_channel_walk(struct ast_channel *prev); 00548 00549 //! Waits for a digit 00550 /*! 00551 * \param c channel to wait for a digit on 00552 * \param ms how many milliseconds to wait 00553 * Wait for a digit. Returns <0 on error, 0 on no entry, and the digit on success. */ 00554 char ast_waitfordigit(struct ast_channel *c, int ms); 00555 00556 /* Same as above with audio fd for outputing read audio and ctrlfd to monitor for 00557 reading. Returns 1 if ctrlfd becomes available */ 00558 char ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd); 00559 00560 //! Reads multiple digits 00561 /*! 00562 * \param c channel to read from 00563 * \param s string to read in to. Must be at least the size of your length 00564 * \param len how many digits to read (maximum) 00565 * \param timeout how long to timeout between digits 00566 * \param rtimeout timeout to wait on the first digit 00567 * \param enders digits to end the string 00568 * Read in a digit string "s", max length "len", maximum timeout between 00569 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout 00570 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of 00571 a timeout, any digits that were read before the timeout will still be available in s. 00572 RETURNS 2 in full version when ctrlfd is available, NOT 1*/ 00573 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders); 00574 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd); 00575 00576 /*! Report DTMF on channel 0 */ 00577 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0) 00578 /*! Report DTMF on channel 1 */ 00579 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1) 00580 /*! Return all voice frames on channel 0 */ 00581 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2) 00582 /*! Return all voice frames on channel 1 */ 00583 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3) 00584 /*! Ignore all signal frames except NULL */ 00585 #define AST_BRIDGE_IGNORE_SIGS (1 << 4) 00586 00587 00588 //! Makes two channel formats compatible 00589 /*! 00590 * \param c0 first channel to make compatible 00591 * \param c1 other channel to make compatible 00592 * Set two channels to compatible formats -- call before ast_channel_bridge in general . Returns 0 on success 00593 and -1 if it could not be done */ 00594 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1); 00595 00596 //! Bridge two channels together 00597 /*! 00598 * \param c0 first channel to bridge 00599 * \param c1 second channel to bridge 00600 * \param flags for the channels 00601 * \param fo destination frame(?) 00602 * \param rc destination channel(?) 00603 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in 00604 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */ 00605 int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); 00606 00607 //! Weird function made for call transfers 00608 /*! 00609 * \param original channel to make a copy of 00610 * \param clone copy of the original channel 00611 * This is a very strange and freaky function used primarily for transfer. Suppose that 00612 "original" and "clone" are two channels in random situations. This function takes 00613 the guts out of "clone" and puts them into the "original" channel, then alerts the 00614 channel driver of the change, asking it to fixup any private information (like the 00615 p->owner pointer) that is affected by the change. The physical layer of the original 00616 channel is hung up. */ 00617 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone); 00618 00619 //! Gives the string form of a given state 00620 /*! 00621 * \param state state to get the name of 00622 * Give a name to a state 00623 * Pretty self explanatory. 00624 * Returns the text form of the binary state given 00625 */ 00626 char *ast_state2str(int state); 00627 00628 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the 00629 low level channel. See frame.h for options. Note that many channel drivers may support 00630 none or a subset of those features, and you should not count on this if you want your 00631 asterisk application to be portable. They're mainly useful for tweaking performance */ 00632 00633 //! Sets an option on a channel 00634 /*! 00635 * \param channel channel to set options on 00636 * \param option option to change 00637 * \param data data specific to option 00638 * \param datalen length of the data 00639 * \param block blocking or not 00640 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 00641 * Returns 0 on success and -1 on failure 00642 */ 00643 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block); 00644 00645 //! Checks the value of an option 00646 /*! 00647 * Query the value of an option, optionally blocking until a reply is received 00648 * Works similarly to setoption except only reads the options. 00649 */ 00650 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block); 00651 00652 //! Checks for HTML support on a channel 00653 /*! Returns 0 if channel does not support HTML or non-zero if it does */ 00654 int ast_channel_supports_html(struct ast_channel *channel); 00655 00656 //! Sends HTML on given channel 00657 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */ 00658 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, char *data, int datalen); 00659 00660 //! Sends a URL on a given link 00661 /*! Send URL on link. Returns 0 on success or -1 on failure */ 00662 int ast_channel_sendurl(struct ast_channel *channel, char *url); 00663 00664 //! Defers DTMF 00665 /*! Defer DTMF so that you only read things like hangups and audio. Returns 00666 non-zero if channel was already DTMF-deferred or 0 if channel is just now 00667 being DTMF-deferred */ 00668 int ast_channel_defer_dtmf(struct ast_channel *chan); 00669 00670 //! Undeos a defer 00671 /*! Undo defer. ast_read will return any dtmf characters that were queued */ 00672 void ast_channel_undefer_dtmf(struct ast_channel *chan); 00673 00674 /*! Initiate system shutdown -- prevents new channels from being allocated. 00675 If "hangup" is non-zero, all existing channels will receive soft 00676 hangups */ 00677 void ast_begin_shutdown(int hangup); 00678 00679 /*! Cancels an existing shutdown and returns to normal operation */ 00680 void ast_cancel_shutdown(void); 00681 00682 /*! Returns number of active/allocated channels */ 00683 int ast_active_channels(void); 00684 00685 /*! Returns non-zero if Asterisk is being shut down */ 00686 int ast_shutting_down(void); 00687 00688 /*! Activate a given generator */ 00689 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params); 00690 00691 /*! Deactive an active generator */ 00692 void ast_deactivate_generator(struct ast_channel *chan); 00693 00694 void ast_set_callerid(struct ast_channel *chan, char *callerid, int anitoo); 00695 00696 /*! Start a tone going */ 00697 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 00698 /*! Stop a tone from playing */ 00699 void ast_tonepair_stop(struct ast_channel *chan); 00700 /*! Play a tone pair for a given amount of time */ 00701 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 00702 00703 /*! Automatically service a channel for us... */ 00704 int ast_autoservice_start(struct ast_channel *chan); 00705 00706 /*! Stop servicing a channel for us... Returns -1 on error or if channel has been hungup */ 00707 int ast_autoservice_stop(struct ast_channel *chan); 00708 00709 /* If built with zaptel optimizations, force a scheduled expiration on the 00710 timer fd, at which point we call the callback function / data */ 00711 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data); 00712 00713 /* Transfer a channel (if supported). Returns -1 on error, 0 if not supported 00714 and 1 if supported and requested */ 00715 int ast_transfer(struct ast_channel *chan, char *dest); 00716 00717 /* Misc. functions below */ 00718 00719 //! Waits for activity on a group of channels 00720 /*! 00721 * \param nfds the maximum number of file descriptors in the sets 00722 * \param rfds file descriptors to check for read availability 00723 * \param wfds file descriptors to check for write availability 00724 * \param efds file descriptors to check for exceptions (OOB data) 00725 * \param tvp timeout while waiting for events 00726 * This is the same as a standard select(), except it guarantees the 00727 * behaviour where the passed struct timeval is updated with how much 00728 * time was not slept while waiting for the specified events 00729 */ 00730 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp) 00731 { 00732 #ifdef __linux__ 00733 return select(nfds, rfds, wfds, efds, tvp); 00734 #else 00735 if (tvp) { 00736 struct timeval tv, tvstart, tvend, tvlen; 00737 int res; 00738 00739 tv = *tvp; 00740 gettimeofday(&tvstart, NULL); 00741 res = select(nfds, rfds, wfds, efds, tvp); 00742 gettimeofday(&tvend, NULL); 00743 timersub(&tvend, &tvstart, &tvlen); 00744 timersub(&tv, &tvlen, tvp); 00745 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) { 00746 tvp->tv_sec = 0; 00747 tvp->tv_usec = 0; 00748 } 00749 return res; 00750 } 00751 else 00752 return select(nfds, rfds, wfds, efds, NULL); 00753 #endif 00754 } 00755 00756 #if !defined(ast_strdupa) && defined(__GNUC__) 00757 # define ast_strdupa(s) \ 00758 (__extension__ \ 00759 ({ \ 00760 __const char *__old = (s); \ 00761 size_t __len = strlen (__old) + 1; \ 00762 char *__new = (char *) __builtin_alloca (__len); \ 00763 (char *) memcpy (__new, __old, __len); \ 00764 })) 00765 #endif 00766 00767 #ifdef DO_CRASH 00768 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0) 00769 #else 00770 #define CRASH do { } while(0) 00771 #endif 00772 00773 #define CHECK_BLOCKING(c) { \ 00774 if ((c)->blocking) {\ 00775 ast_log(LOG_WARNING, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \ 00776 CRASH; \ 00777 } else { \ 00778 (c)->blocker = pthread_self(); \ 00779 (c)->blockproc = __PRETTY_FUNCTION__; \ 00780 c->blocking = -1; \ 00781 } } 00782 00783 #if defined(__cplusplus) || defined(c_plusplus) 00784 } 00785 #endif 00786 00787 00788 #endif