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