2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * \brief General Asterisk PBX channel definitions.
22 * \arg \ref Def_Channel
23 * \arg \ref channel_drivers
26 /*! \page Def_Channel Asterisk Channels
27 \par What is a Channel?
28 A phone call through Asterisk consists of an incoming
29 connection and an outbound connection. Each call comes
30 in through a channel driver that supports one technology,
31 like SIP, DAHDI, IAX2 etc.
33 Each channel driver, technology, has it's own private
34 channel or dialog structure, that is technology-dependent.
35 Each private structure is "owned" by a generic Asterisk
36 channel structure, defined in channel.h and handled by
39 This happens when an incoming call arrives to Asterisk
40 -# Call arrives on a channel driver interface
41 -# Channel driver creates a PBX channel and starts a
42 pbx thread on the channel
43 -# The dial plan is executed
44 -# At this point at least two things can happen:
45 -# The call is answered by Asterisk and
46 Asterisk plays a media stream or reads media
47 -# The dial plan forces Asterisk to create an outbound
48 call somewhere with the dial (see \ref app_dial.c)
52 \par Bridging channels
53 If Asterisk dials out this happens:
54 -# Dial creates an outbound PBX channel and asks one of the
55 channel drivers to create a call
56 -# When the call is answered, Asterisk bridges the media streams
57 so the caller on the first channel can speak with the callee
58 on the second, outbound channel
59 -# In some cases where we have the same technology on both
60 channels and compatible codecs, a native bridge is used.
61 In a native bridge, the channel driver handles forwarding
62 of incoming audio to the outbound stream internally, without
63 sending audio frames through the PBX.
64 -# In SIP, theres an "external native bridge" where Asterisk
65 redirects the endpoint, so audio flows directly between the
66 caller's phone and the callee's phone. Signalling stays in
67 Asterisk in order to be able to provide a proper CDR record
71 \par Masquerading channels
72 In some cases, a channel can masquerade itself into another
73 channel. This happens frequently in call transfers, where
74 a new channel takes over a channel that is already involved
75 in a call. The new channel sneaks in and takes over the bridge
76 and the old channel, now a zombie, is hung up.
79 \arg channel.c - generic functions
80 \arg channel.h - declarations of functions, flags and structures
81 \arg translate.h - Transcoding support functions
82 \arg \ref channel_drivers - Implemented channel drivers
83 \arg \ref Def_Frame Asterisk Multimedia Frames
87 /*! \page Def_Bridge Asterisk Channel Bridges
89 In Asterisk, there's several media bridges.
91 The Core bridge handles two channels (a "phone call") and bridge
94 The conference bridge (meetme) handles several channels simultaneously
95 with the support of an external timer (DAHDI timer). This is used
96 not only by the Conference application (meetme) but also by the
97 page application and the SLA system introduced in 1.4.
98 The conference bridge does not handle video.
100 When two channels of the same type connect, the channel driver
101 or the media subsystem used by the channel driver (i.e. RTP)
102 can create a native bridge without sending media through the
105 Native bridging can be disabled by a number of reasons,
106 like DTMF being needed by the core or codecs being incompatible
107 so a transcoding module is needed.
110 \li \see ast_channel_early_bridge()
111 \li \see ast_channel_bridge()
112 \li \see app_meetme.c
113 \li \ref AstRTPbridge
114 \li \see ast_rtp_bridge()
118 /*! \page AstFileDesc File descriptors
119 Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
120 in the \ref ast_channel structure.
123 #ifndef _ASTERISK_CHANNEL_H
124 #define _ASTERISK_CHANNEL_H
126 #include "asterisk/abstract_jb.h"
127 #include "asterisk/astobj2.h"
129 #include "asterisk/poll-compat.h"
131 #if defined(__cplusplus) || defined(c_plusplus)
135 #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */
136 #define AST_MAX_CONTEXT 80 /*!< Max length of a context */
137 #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */
138 #define MAX_LANGUAGE 40 /*!< Max length of the language setting */
139 #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */
141 #include "asterisk/frame.h"
142 #include "asterisk/chanvars.h"
143 #include "asterisk/config.h"
144 #include "asterisk/lock.h"
145 #include "asterisk/cdr.h"
146 #include "asterisk/utils.h"
147 #include "asterisk/linkedlists.h"
148 #include "asterisk/stringfields.h"
149 #include "asterisk/datastore.h"
150 #include "asterisk/data.h"
151 #include "asterisk/channelstate.h"
152 #include "asterisk/ccss.h"
153 #include "asterisk/framehook.h"
155 #define DATASTORE_INHERIT_FOREVER INT_MAX
157 #define AST_MAX_FDS 11
159 * We have AST_MAX_FDS file descriptors in a channel.
160 * Some of them have a fixed use:
162 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */
163 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */
164 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */
165 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */
166 #define AST_JITTERBUFFER_FD (AST_MAX_FDS-5) /*!< used by generator */
168 enum ast_bridge_result {
169 AST_BRIDGE_COMPLETE = 0,
170 AST_BRIDGE_FAILED = -1,
171 AST_BRIDGE_FAILED_NOWARN = -2,
172 AST_BRIDGE_RETRY = -3,
175 typedef unsigned long long ast_group_t;
177 /*! \todo Add an explanation of an Asterisk generator
179 struct ast_generator {
180 void *(*alloc)(struct ast_channel *chan, void *params);
181 /*! Channel is locked during this function callback. */
182 void (*release)(struct ast_channel *chan, void *data);
183 /*! This function gets called with the channel unlocked, but is called in
184 * the context of the channel thread so we know the channel is not going
185 * to disappear. This callback is responsible for locking the channel as
187 int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
188 /*! This gets called when DTMF_END frames are read from the channel */
189 void (*digit)(struct ast_channel *chan, char digit);
190 /*! This gets called when the write format on a channel is changed while
191 * generating. The channel is locked during this callback. */
192 void (*write_format_change)(struct ast_channel *chan, void *data);
195 /*! Party name character set enumeration values (values from Q.SIG) */
196 enum AST_PARTY_CHAR_SET {
197 AST_PARTY_CHAR_SET_UNKNOWN = 0,
198 AST_PARTY_CHAR_SET_ISO8859_1 = 1,
199 AST_PARTY_CHAR_SET_WITHDRAWN = 2,/* ITU withdrew this enum value. */
200 AST_PARTY_CHAR_SET_ISO8859_2 = 3,
201 AST_PARTY_CHAR_SET_ISO8859_3 = 4,
202 AST_PARTY_CHAR_SET_ISO8859_4 = 5,
203 AST_PARTY_CHAR_SET_ISO8859_5 = 6,
204 AST_PARTY_CHAR_SET_ISO8859_7 = 7,
205 AST_PARTY_CHAR_SET_ISO10646_BMPSTRING = 8,
206 AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING = 9,
211 * \brief Information needed to specify a name in a call.
212 * \note All string fields here are malloc'ed, so they need to be
213 * freed when the structure is deleted.
214 * \note NULL and "" must be considered equivalent.
216 struct ast_party_name {
217 /*! \brief Subscriber name (Malloced) */
220 * \brief Character set the name is using.
221 * \see enum AST_PARTY_CHAR_SET
223 * Set to AST_PARTY_CHAR_SET_ISO8859_1 if unsure what to use.
224 * \todo Start using the party name character set value. Not currently used.
228 * \brief Q.931 encoded presentation-indicator encoded field
229 * \note Must tolerate the Q.931 screening-indicator field values being present.
232 /*! \brief TRUE if the name information is valid/present */
238 * \brief Information needed to specify a number in a call.
239 * \note All string fields here are malloc'ed, so they need to be
240 * freed when the structure is deleted.
241 * \note NULL and "" must be considered equivalent.
243 struct ast_party_number {
244 /*! \brief Subscriber phone number (Malloced) */
246 /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
248 /*! \brief Q.931 presentation-indicator and screening-indicator encoded fields */
250 /*! \brief TRUE if the number information is valid/present */
256 * \brief Information needed to specify a subaddress in a call.
257 * \note All string fields here are malloc'ed, so they need to be
258 * freed when the structure is deleted.
259 * \note NULL and "" must be considered equivalent.
261 struct ast_party_subaddress {
263 * \brief Malloced subaddress string.
264 * \note If the subaddress type is user specified then the subaddress is
265 * a string of ASCII hex because the actual subaddress is likely BCD encoded.
269 * \brief Q.931 subaddress type.
276 * \brief TRUE if odd number of address signals
277 * \note The odd/even indicator is used when the type of subaddress is
278 * user_specified and the coding is BCD.
280 unsigned char odd_even_indicator;
281 /*! \brief TRUE if the subaddress information is valid/present */
287 * \brief Information needed to identify an endpoint in a call.
288 * \note All string fields here are malloc'ed, so they need to be
289 * freed when the structure is deleted.
290 * \note NULL and "" must be considered equivalent.
292 struct ast_party_id {
293 /*! \brief Subscriber name */
294 struct ast_party_name name;
295 /*! \brief Subscriber phone number */
296 struct ast_party_number number;
297 /*! \brief Subscriber subaddress. */
298 struct ast_party_subaddress subaddress;
301 * \brief User-set "tag"
303 * A user-settable field used to help associate some extrinsic information
304 * about the channel or user of the channel to the party ID. This information
305 * is normally not transmitted over the wire and so is only useful within an
306 * Asterisk environment.
313 * \brief Indicate what information in ast_party_id should be set.
315 struct ast_set_party_id {
316 /*! TRUE if the ast_party_name information should be set. */
318 /*! TRUE if the ast_party_number information should be set. */
319 unsigned char number;
320 /*! TRUE if the ast_party_subaddress information should be set. */
321 unsigned char subaddress;
326 * \brief Dialed/Called Party information.
327 * \note Dialed Number Identifier (DNID)
328 * \note All string fields here are malloc'ed, so they need to be
329 * freed when the structure is deleted.
330 * \note NULL and "" must be considered equivalent.
332 struct ast_party_dialed {
334 * \brief Dialed/Called number
335 * \note Done this way in case we ever really need to use ast_party_number.
336 * We currently do not need all of the ast_party_number fields.
339 /*! \brief Subscriber phone number (Malloced) */
341 /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
344 /*! \brief Dialed/Called subaddress */
345 struct ast_party_subaddress subaddress;
347 * \brief Transit Network Select
348 * \note Currently this value is just passed around the system.
349 * You can read it and set it but it is never used for anything.
351 int transit_network_select;
356 * \brief Caller Party information.
357 * \note All string fields here are malloc'ed, so they need to be
358 * freed when the structure is deleted.
359 * \note NULL and "" must be considered equivalent.
361 * \note SIP and IAX2 has UTF8 encoded Unicode Caller ID names.
362 * In some cases, we also have an alternative (RPID) E.164 number that can
363 * be used as Caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to
366 * \todo Implement settings for transliteration between UTF8 Caller ID names in
367 * to ASCII Caller ID's (DAHDI). Östen Åsklund might be transliterated into
368 * Osten Asklund or Oesten Aasklund depending upon language and person...
369 * We need automatic routines for incoming calls and static settings for
372 struct ast_party_caller {
373 /*! \brief Caller party ID */
374 struct ast_party_id id;
377 * \brief Automatic Number Identification (ANI)
378 * \note The name subcomponent is only likely to be used by SIP.
379 * \note The subaddress subcomponent is not likely to be used.
381 struct ast_party_id ani;
383 /*! \brief Automatic Number Identification 2 (Info Digits) */
389 * \brief Indicate what information in ast_party_caller should be set.
391 struct ast_set_party_caller {
392 /*! What caller id information to set. */
393 struct ast_set_party_id id;
394 /*! What ANI id information to set. */
395 struct ast_set_party_id ani;
400 * \brief Connected Line/Party information.
401 * \note All string fields here are malloc'ed, so they need to be
402 * freed when the structure is deleted.
403 * \note NULL and "" must be considered equivalent.
405 struct ast_party_connected_line {
406 /*! \brief Connected party ID */
407 struct ast_party_id id;
410 * \brief Automatic Number Identification (ANI)
411 * \note Not really part of connected line data but needed to
412 * save the corresponding caller id value.
414 struct ast_party_id ani;
417 * \brief Automatic Number Identification 2 (Info Digits)
418 * \note Not really part of connected line data but needed to
419 * save the corresponding caller id value.
424 * \brief Information about the source of an update.
425 * \note enum AST_CONNECTED_LINE_UPDATE_SOURCE values
426 * for Normal-Answer and Call-transfer.
433 * \brief Indicate what information in ast_party_connected_line should be set.
435 struct ast_set_party_connected_line {
436 /*! What connected line id information to set. */
437 struct ast_set_party_id id;
438 /*! What ANI id information to set. */
439 struct ast_set_party_id ani;
444 * \brief Redirecting Line information.
445 * RDNIS (Redirecting Directory Number Information Service)
446 * Where a call diversion or transfer was invoked.
447 * \note All string fields here are malloc'ed, so they need to be
448 * freed when the structure is deleted.
449 * \note NULL and "" must be considered equivalent.
451 struct ast_party_redirecting {
452 /*! \brief Who originally redirected the call (Sent to the party the call is redirected toward) */
453 struct ast_party_id orig;
455 /*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) */
456 struct ast_party_id from;
458 /*! \brief Call is redirecting to a new party (Sent to the caller) */
459 struct ast_party_id to;
461 /*! \brief Number of times the call was redirected */
464 /*! \brief enum AST_REDIRECTING_REASON value for redirection */
467 /*! \brief enum AST_REDIRECTING_REASON value for redirection by original party */
473 * \brief Indicate what information in ast_party_redirecting should be set.
475 struct ast_set_party_redirecting {
476 /*! What redirecting-orig id information to set. */
477 struct ast_set_party_id orig;
478 /*! What redirecting-from id information to set. */
479 struct ast_set_party_id from;
480 /*! What redirecting-to id information to set. */
481 struct ast_set_party_id to;
485 * \brief Typedef for a custom read function
486 * \note data should be treated as const char *.
488 typedef int (*ast_acf_read_fn_t)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
491 * \brief Typedef for a custom read2 function
492 * \note data should be treated as const char *.
494 typedef int (*ast_acf_read2_fn_t)(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len);
497 * \brief Typedef for a custom write function
498 * \note data should be treated as const char *.
500 typedef int (*ast_acf_write_fn_t)(struct ast_channel *chan, const char *function, char *data, const char *value);
502 /*! \brief Structure to handle passing func_channel_write info to channels via setoption */
504 /*! \brief ast_chan_write_info_t version. Must be incremented if structure is changed */
505 #define AST_CHAN_WRITE_INFO_T_VERSION 1
507 ast_acf_write_fn_t write_fn;
508 struct ast_channel *chan;
509 const char *function;
512 } ast_chan_write_info_t;
516 * Structure to describe a channel "technology", ie a channel driver
518 * \arg chan_iax2.c - The Inter-Asterisk exchange protocol
519 * \arg chan_sip.c - The SIP channel driver
520 * \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
523 * If you develop your own channel driver, this is where you
524 * tell the PBX at registration of your driver what properties
525 * this driver supports and where different callbacks are
528 struct ast_channel_tech {
529 const char * const type;
530 const char * const description;
532 struct ast_format_cap *capabilities; /*!< format capabilities this channel can handle */
534 int properties; /*!< Technology Properties */
537 * \brief Requester - to set up call data structures (pvt's)
539 * \param type type of channel to request
540 * \param cap Format capabilities for requested channel
541 * \param requestor channel asking for data
542 * \param addr destination of the call
543 * \param cause Cause of failure
546 * Request a channel of a given type, with addr as optional information used
547 * by the low level module
549 * \retval NULL failure
550 * \retval non-NULL channel on success
552 struct ast_channel *(* const requester)(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr, int *cause);
554 int (* const devicestate)(const char *device_number); /*!< Devicestate call back */
557 * \brief Start sending a literal DTMF digit
559 * \note The channel is not locked when this function gets called.
561 int (* const send_digit_begin)(struct ast_channel *chan, char digit);
564 * \brief Stop sending a literal DTMF digit
566 * \note The channel is not locked when this function gets called.
568 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
572 * \note The channel is locked when called.
573 * \param chan which channel to make the call on
574 * \param addr destination of the call
575 * \param timeout time to wait on for connect (Doesn't seem to be used.)
576 * \retval 0 on success
577 * \retval -1 on failure
579 int (* const call)(struct ast_channel *chan, const char *addr, int timeout);
581 /*! \brief Hangup (and possibly destroy) the channel */
582 int (* const hangup)(struct ast_channel *chan);
584 /*! \brief Answer the channel */
585 int (* const answer)(struct ast_channel *chan);
587 /*! \brief Read a frame, in standard format (see frame.h) */
588 struct ast_frame * (* const read)(struct ast_channel *chan);
590 /*! \brief Write a frame, in standard format (see frame.h) */
591 int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
593 /*! \brief Display or transmit text */
594 int (* const send_text)(struct ast_channel *chan, const char *text);
596 /*! \brief Display or send an image */
597 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
599 /*! \brief Send HTML data */
600 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
602 /*! \brief Handle an exception, reading a frame */
603 struct ast_frame * (* const exception)(struct ast_channel *chan);
605 /*! \brief Bridge two channels of the same type together */
606 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
607 struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
609 /*! \brief Bridge two channels of the same type together (early) */
610 enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
612 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
613 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
615 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
616 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
618 /*! \brief Set a given option. Called with chan locked */
619 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
621 /*! \brief Query a given option. Called with chan locked */
622 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
624 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
625 int (* const transfer)(struct ast_channel *chan, const char *newdest);
627 /*! \brief Write a frame, in standard format */
628 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
630 /*! \brief Write a text frame, in standard format */
631 int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
633 /*! \brief Find bridged channel */
634 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
637 * \brief Provide additional read items for CHANNEL() dialplan function
638 * \note data should be treated as a const char *.
640 int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
643 * \brief Provide additional write items for CHANNEL() dialplan function
644 * \note data should be treated as a const char *.
646 int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
648 /*! \brief Retrieve base channel (agent and local) */
649 struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
651 /*! \brief Set base channel (agent and local) */
652 int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
654 /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
655 const char * (* get_pvt_uniqueid)(struct ast_channel *chan);
657 /*! \brief Call a function with cc parameters as a function parameter
660 * This is a highly specialized callback that is not likely to be needed in many
661 * channel drivers. When dealing with a busy channel, for instance, most channel
662 * drivers will successfully return a channel to the requester. Once called, the channel
663 * can then queue a busy frame when it receives an appropriate message from the far end.
664 * In such a case, the channel driver has the opportunity to also queue a CC frame.
665 * The parameters for the CC channel can be retrieved from the channel structure.
667 * For other channel drivers, notably those that deal with "dumb" phones, the channel
668 * driver will not return a channel when one is requested. In such a scenario, there is never
669 * an opportunity for the channel driver to queue a CC frame since the channel is never
670 * called. Furthermore, it is not possible to retrieve the CC configuration parameters
671 * for the desired channel because no channel is ever allocated or returned to the
672 * requester. In such a case, call completion may still be a viable option. What we do is
673 * pass the same string that the requester used originally to request the channel to the
674 * channel driver. The channel driver can then find any potential channels/devices that
675 * match the input and return call the designated callback with the device's call completion
676 * parameters as a parameter.
678 int (* cc_callback)(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
681 * \brief Execute a Gosub call on the channel in a technology specific way before a call is placed.
684 * \param chan Channel to execute Gosub in a tech specific way.
685 * \param sub_args Gosub application parameter string.
687 * \note The chan is locked before calling.
689 * \retval 0 on success.
690 * \retval -1 on error.
692 int (*pre_call)(struct ast_channel *chan, const char *sub_args);
695 /*! Kill the channel channel driver technology descriptor. */
696 extern const struct ast_channel_tech ast_kill_tech;
698 struct ast_epoll_data;
701 * The high bit of the frame count is used as a debug marker, so
702 * increments of the counters must be done with care.
703 * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
705 #define DEBUGCHAN_FLAG 0x80000000
707 /* XXX not ideal to evaluate x twice... */
708 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
711 * The current value of the debug flags is stored in the two
712 * variables global_fin and global_fout (declared in main/channel.c)
714 extern unsigned long global_fin, global_fout;
716 enum ast_channel_adsicpe {
719 AST_ADSI_UNAVAILABLE,
720 AST_ADSI_OFFHOOKONLY,
724 * \brief Possible T38 states on channels
727 T38_STATE_UNAVAILABLE, /*!< T38 is unavailable on this channel or disabled by configuration */
728 T38_STATE_UNKNOWN, /*!< The channel supports T38 but the current status is unknown */
729 T38_STATE_NEGOTIATING, /*!< T38 is being negotiated */
730 T38_STATE_REJECTED, /*!< Remote side has rejected our offer */
731 T38_STATE_NEGOTIATED, /*!< T38 established */
734 /*! Hangup handler instance node. */
735 struct ast_hangup_handler {
736 /*! Next hangup handler node. */
737 AST_LIST_ENTRY(ast_hangup_handler) node;
738 /*! Hangup handler arg string passed to the Gosub application */
742 AST_LIST_HEAD_NOLOCK(ast_hangup_handler_list, ast_hangup_handler);
743 AST_LIST_HEAD_NOLOCK(ast_datastore_list, ast_datastore);
744 AST_LIST_HEAD_NOLOCK(ast_autochan_list, ast_autochan);
745 AST_LIST_HEAD_NOLOCK(ast_readq_list, ast_frame);
747 typedef int(*ast_timing_func_t)(const void *data);
749 * \page AstChannel ast_channel locking and reference tracking
751 * \par Creating Channels
752 * A channel is allocated using the ast_channel_alloc() function. When created, it is
753 * automatically inserted into the main channels hash table that keeps track of all
754 * active channels in the system. The hash key is based on the channel name. Because
755 * of this, if you want to change the name, you _must_ use ast_change_name(), not change
756 * the name field directly. When ast_channel_alloc() returns a channel pointer, you now
757 * hold a reference to that channel. In most cases this reference is given to ast_pbx_run().
759 * \par Channel Locking
760 * There is a lock associated with every ast_channel. It is allocated internally via astobj2.
761 * To lock or unlock a channel, you must use the ast_channel_lock() wrappers.
763 * Previously, before ast_channel was converted to astobj2, the channel lock was used in some
764 * additional ways that are no longer necessary. Before, the only way to ensure that a channel
765 * did not disappear out from under you if you were working with a channel outside of the channel
766 * thread that owns it, was to hold the channel lock. Now, that is no longer necessary.
767 * You simply must hold a reference to the channel to ensure it does not go away.
769 * The channel must be locked if you need to ensure that data that you reading from the channel
770 * does not change while you access it. Further, you must hold the channel lock if you are
771 * making a non-atomic change to channel data.
773 * \par Channel References
774 * There are multiple ways to get a reference to a channel. The first is that you hold a reference
775 * to a channel after creating it. The other ways involve using the channel search or the channel
776 * traversal APIs. These functions are the ast_channel_get_*() functions or ast_channel_iterator_*()
777 * functions. Once a reference is retrieved by one of these methods, you know that the channel will
778 * not go away. So, the channel should only get locked as needed for data access or modification.
779 * But, make sure that the reference gets released when you are done with it!
781 * There are different things you can do when you are done with a reference to a channel. The first
782 * is to simply release the reference using ast_channel_unref(). The other option is to call
783 * ast_channel_release(). This function is generally used where ast_channel_free() was used in
784 * the past. The release function releases a reference as well as ensures that the channel is no
785 * longer in the global channels container. That way, the channel will get destroyed as soon as any
786 * other pending references get released.
788 * \par Exceptions to the rules
789 * Even though ast_channel is reference counted, there are some places where pointers to an ast_channel
790 * get stored, but the reference count does not reflect it. The reason is mostly historical.
791 * The only places where this happens should be places where because of how the code works, we
792 * _know_ that the pointer to the channel will get removed before the channel goes away. The main
793 * example of this is in channel drivers. Channel drivers generally store a pointer to their owner
794 * ast_channel in their technology specific pvt struct. In this case, the channel drivers _know_
795 * that this pointer to the channel will be removed in time, because the channel's hangup callback
796 * gets called before the channel goes away.
801 /*! \brief ast_channel_tech Properties */
804 * \brief Channels have this property if they can accept input with jitter;
805 * i.e. most VoIP channels
807 AST_CHAN_TP_WANTSJITTER = (1 << 0),
809 * \brief Channels have this property if they can create jitter;
810 * i.e. most VoIP channels
812 AST_CHAN_TP_CREATESJITTER = (1 << 1),
815 /*! \brief ast_channel flags */
817 /*! Queue incoming DTMF, to be released when this flag is turned off */
818 AST_FLAG_DEFER_DTMF = (1 << 1),
819 /*! write should be interrupt generator */
820 AST_FLAG_WRITE_INT = (1 << 2),
821 /*! a thread is blocking on this channel */
822 AST_FLAG_BLOCKING = (1 << 3),
823 /*! This is a zombie channel */
824 AST_FLAG_ZOMBIE = (1 << 4),
825 /*! There is an exception pending */
826 AST_FLAG_EXCEPTION = (1 << 5),
827 /*! Listening to moh XXX anthm promises me this will disappear XXX */
828 AST_FLAG_MOH = (1 << 6),
829 /*! This channel is spying on another channel */
830 AST_FLAG_SPYING = (1 << 7),
831 /*! This channel is in a native bridge */
832 AST_FLAG_NBRIDGE = (1 << 8),
833 /*! the channel is in an auto-incrementing dialplan processor,
834 * so when ->priority is set, it will get incremented before
835 * finding the next priority to run */
836 AST_FLAG_IN_AUTOLOOP = (1 << 9),
837 /*! This is an outgoing call */
838 AST_FLAG_OUTGOING = (1 << 10),
839 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
840 AST_FLAG_IN_DTMF = (1 << 12),
841 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
842 * currently being emulated */
843 AST_FLAG_EMULATE_DTMF = (1 << 13),
844 /*! This is set to tell the channel not to generate DTMF begin frames, and
845 * to instead only generate END frames. */
846 AST_FLAG_END_DTMF_ONLY = (1 << 14),
847 /* OBSOLETED in favor of AST_CAUSE_ANSWERED_ELSEWHERE
848 Flag to show channels that this call is hangup due to the fact that the call
849 was indeed answered, but in another channel */
850 /* AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), */
851 /*! This flag indicates that on a masquerade, an active stream should not
853 AST_FLAG_MASQ_NOSTREAM = (1 << 16),
854 /*! This flag indicates that the hangup exten was run when the bridge terminated,
855 * a message aimed at preventing a subsequent hangup exten being run at the pbx_run
857 AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
858 /*! This flag indicates that the hangup exten should NOT be run when the
859 * bridge terminates, this will allow the hangup in the pbx loop to be run instead.
861 AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18),
862 /*! Disable certain workarounds. This reintroduces certain bugs, but allows
863 * some non-traditional dialplans (like AGI) to continue to function.
865 AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
868 /*! \brief ast_bridge_config flags */
870 AST_FEATURE_PLAY_WARNING = (1 << 0),
871 AST_FEATURE_REDIRECT = (1 << 1),
872 AST_FEATURE_DISCONNECT = (1 << 2),
873 AST_FEATURE_ATXFER = (1 << 3),
874 AST_FEATURE_AUTOMON = (1 << 4),
875 AST_FEATURE_PARKCALL = (1 << 5),
876 AST_FEATURE_AUTOMIXMON = (1 << 6),
877 AST_FEATURE_NO_H_EXTEN = (1 << 7),
878 AST_FEATURE_WARNING_ACTIVE = (1 << 8),
881 /*! \brief bridge configuration */
882 struct ast_bridge_config {
883 struct ast_flags features_caller;
884 struct ast_flags features_callee;
885 struct timeval start_time;
886 struct timeval nexteventts;
887 struct timeval feature_start_time;
892 const char *warning_sound;
893 const char *end_sound;
894 const char *start_sound;
896 void (* end_bridge_callback)(void *); /*!< A callback that is called after a bridge attempt */
897 void *end_bridge_callback_data; /*!< Data passed to the callback */
898 /*! If the end_bridge_callback_data refers to a channel which no longer is going to
899 * exist when the end_bridge_callback is called, then it needs to be fixed up properly
901 void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
906 struct outgoing_helper {
910 int connect_on_early_media; /* If set, treat session progress as answer */
912 const char *cid_name;
914 struct ast_variable *vars;
915 struct ast_channel *parent_channel;
920 * Soft hangup requested by device or other internal reason.
921 * Actual hangup needed.
923 AST_SOFTHANGUP_DEV = (1 << 0),
925 * Used to break the normal frame flow so an async goto can be
926 * done instead of actually hanging up.
928 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
930 * Soft hangup requested by system shutdown. Actual hangup
933 AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
935 * Used to break the normal frame flow after a timeout so an
936 * implicit async goto can be done to the 'T' exten if it exists
937 * instead of actually hanging up. If the exten does not exist
938 * then actually hangup.
940 AST_SOFTHANGUP_TIMEOUT = (1 << 3),
942 * Soft hangup requested by application/channel-driver being
943 * unloaded. Actual hangup needed.
945 AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
947 * Soft hangup requested by non-associated party. Actual hangup
950 AST_SOFTHANGUP_EXPLICIT = (1 << 5),
952 * Used to break a bridge so the channel can be spied upon
953 * instead of actually hanging up.
955 AST_SOFTHANGUP_UNBRIDGE = (1 << 6),
959 * \brief All softhangup flags.
961 * This can be used as an argument to ast_channel_clear_softhangup()
962 * to clear all softhangup flags from a channel.
964 AST_SOFTHANGUP_ALL = (0xFFFFFFFF)
968 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
969 enum channelreloadreason {
971 CHANNEL_MODULE_RELOAD,
973 CHANNEL_MANAGER_RELOAD,
978 /*! \brief Structure to handle ao2-container for named groups */
979 struct namedgroup_entry {
980 /*! string representation of group */
983 /*! pre-built hash of groupname string */
989 * \note None of the datastore API calls lock the ast_channel they are using.
990 * So, the channel should be locked before calling the functions that
991 * take a channel argument.
995 * \brief Create a channel data store object
996 * \deprecated You should use the ast_datastore_alloc() generic function instead.
997 * \version 1.6.1 deprecated
999 struct ast_datastore * attribute_malloc ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
1000 __attribute__((deprecated));
1003 * \brief Free a channel data store object
1004 * \deprecated You should use the ast_datastore_free() generic function instead.
1005 * \version 1.6.1 deprecated
1007 int ast_channel_datastore_free(struct ast_datastore *datastore)
1008 __attribute__((deprecated));
1010 /*! \brief Inherit datastores from a parent to a child. */
1011 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
1014 * \brief Add a datastore to a channel
1016 * \note The channel should be locked before calling this function.
1019 * \retval non-zero failure
1021 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
1024 * \brief Remove a datastore from a channel
1026 * \note The channel should be locked before calling this function.
1029 * \retval non-zero failure
1031 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
1034 * \brief Find a datastore on a channel
1036 * \note The channel should be locked before calling this function.
1038 * \note The datastore returned from this function must not be used if the
1039 * reference to the channel is released.
1041 * \retval pointer to the datastore if found
1042 * \retval NULL if not found
1044 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
1047 * \brief Create a channel structure
1050 * \retval NULL failure
1051 * \retval non-NULL successfully allocated channel
1053 * \note Absolutely _NO_ channel locks should be held before calling this function.
1054 * \note By default, new channels are set to the "s" extension
1055 * and "default" context.
1057 struct ast_channel * attribute_malloc __attribute__((format(printf, 13, 14)))
1058 __ast_channel_alloc(int needqueue, int state, const char *cid_num,
1059 const char *cid_name, const char *acctcode,
1060 const char *exten, const char *context,
1061 const char *linkedid, const int amaflag,
1062 const char *file, int line, const char *function,
1063 const char *name_fmt, ...);
1066 * \brief Create a channel structure
1068 * \retval NULL failure
1069 * \retval non-NULL successfully allocated channel
1071 * \note Absolutely _NO_ channel locks should be held before calling this function.
1072 * \note By default, new channels are set to the "s" extension
1073 * and "default" context.
1075 #define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, ...) \
1076 __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, \
1077 __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
1079 #if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
1081 * \brief Create a fake channel structure
1083 * \retval NULL failure
1084 * \retval non-NULL successfully allocated channel
1086 * \note This function should ONLY be used to create a fake channel
1087 * that can then be populated with data for use in variable
1088 * substitution when a real channel does not exist.
1090 * \note The created dummy channel should be destroyed by
1091 * ast_channel_unref(). Using ast_channel_release() needlessly
1092 * grabs the channel container lock and can cause a deadlock as
1093 * a result. Also grabbing the channel container lock reduces
1094 * system performance.
1096 #define ast_dummy_channel_alloc() __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
1097 struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);
1100 * \brief Create a fake channel structure
1102 * \retval NULL failure
1103 * \retval non-NULL successfully allocated channel
1105 * \note This function should ONLY be used to create a fake channel
1106 * that can then be populated with data for use in variable
1107 * substitution when a real channel does not exist.
1109 * \note The created dummy channel should be destroyed by
1110 * ast_channel_unref(). Using ast_channel_release() needlessly
1111 * grabs the channel container lock and can cause a deadlock as
1112 * a result. Also grabbing the channel container lock reduces
1113 * system performance.
1115 struct ast_channel *ast_dummy_channel_alloc(void);
1119 * \brief Queue one or more frames to a channel's frame queue
1121 * \param chan the channel to queue the frame(s) on
1122 * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
1123 * by this function. It is the responsibility of the caller to handle
1124 * freeing the memory associated with the frame(s) being passed if
1128 * \retval non-zero failure
1130 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
1133 * \brief Queue one or more frames to the head of a channel's frame queue
1135 * \param chan the channel to queue the frame(s) on
1136 * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
1137 * by this function. It is the responsibility of the caller to handle
1138 * freeing the memory associated with the frame(s) being passed if
1142 * \retval non-zero failure
1144 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
1147 * \brief Queue a hangup frame
1149 * \note The channel does not need to be locked before calling this function.
1151 int ast_queue_hangup(struct ast_channel *chan);
1154 * \brief Queue a hangup frame with hangupcause set
1156 * \note The channel does not need to be locked before calling this function.
1157 * \param[in] chan channel to queue frame onto
1158 * \param[in] cause the hangup cause
1159 * \return 0 on success, -1 on error
1162 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
1165 * \brief Queue a control frame with payload
1167 * \param chan channel to queue frame onto
1168 * \param control type of control frame
1170 * \note The channel does not need to be locked before calling this function.
1172 * \retval zero on success
1173 * \retval non-zero on failure
1175 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
1178 * \brief Queue a control frame with payload
1180 * \param chan channel to queue frame onto
1181 * \param control type of control frame
1182 * \param data pointer to payload data to be included in frame
1183 * \param datalen number of bytes of payload data
1186 * \retval non-zero failure
1189 * The supplied payload data is copied into the frame, so the caller's copy
1190 * is not modified nor freed, and the resulting frame will retain a copy of
1191 * the data even if the caller frees their local copy.
1193 * \note This method should be treated as a 'network transport'; in other
1194 * words, your frames may be transferred across an IAX2 channel to another
1195 * system, which may be a different endianness than yours. Because of this,
1196 * you should ensure that either your frames will never be expected to work
1197 * across systems, or that you always put your payload data into 'network byte
1198 * order' before calling this function.
1200 * \note The channel does not need to be locked before calling this function.
1202 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
1203 const void *data, size_t datalen);
1206 * \brief Change channel name
1208 * \pre Absolutely all channels _MUST_ be unlocked before calling this function.
1210 * \param chan the channel to change the name of
1211 * \param newname the name to change to
1215 * \note this function must _NEVER_ be used when any channels are locked
1216 * regardless if it is the channel who's name is being changed or not because
1217 * it invalidates our channel container locking order... lock container first,
1218 * then the individual channels, never the other way around.
1220 void ast_change_name(struct ast_channel *chan, const char *newname);
1223 * \brief Unlink and release reference to a channel
1225 * This function will unlink the channel from the global channels container
1226 * if it is still there and also release the current reference to the channel.
1228 * \return NULL, convenient for clearing invalid pointers
1229 * \note Absolutely _NO_ channel locks should be held before calling this function.
1233 struct ast_channel *ast_channel_release(struct ast_channel *chan);
1236 * \brief Requests a channel
1238 * \param type type of channel to request
1239 * \param request_cap Format capabilities for requested channel
1240 * \param requestor channel asking for data
1241 * \param addr destination of the call
1242 * \param cause Cause of failure
1245 * Request a channel of a given type, with addr as optional information used
1246 * by the low level module
1248 * \retval NULL failure
1249 * \retval non-NULL channel on success
1251 struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_channel *requestor, const char *addr, int *cause);
1254 * \brief Request a channel of a given type, with data as optional information used
1255 * by the low level module and attempt to place a call on it
1257 * \param type type of channel to request
1258 * \param format capabilities for requested channel
1259 * \param requestor channel asking for data
1260 * \param addr destination of the call
1261 * \param timeout maximum amount of time to wait for an answer
1262 * \param reason why unsuccessful (if unsuccessful)
1263 * \param cid_num Caller-ID Number
1264 * \param cid_name Caller-ID Name (ascii)
1266 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
1267 * to know if the call was answered or not.
1269 struct ast_channel *ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr,
1270 int timeout, int *reason, const char *cid_num, const char *cid_name);
1273 * \brief Request a channel of a given type, with data as optional information used
1274 * by the low level module and attempt to place a call on it
1275 * \param type type of channel to request
1276 * \param format capabilities for requested channel
1277 * \param requestor channel requesting data
1278 * \param addr destination of the call
1279 * \param timeout maximum amount of time to wait for an answer
1280 * \param reason why unsuccessful (if unsuccessful)
1281 * \param cid_num Caller-ID Number
1282 * \param cid_name Caller-ID Name (ascii)
1283 * \param oh Outgoing helper
1284 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
1285 * to know if the call was answered or not.
1287 struct ast_channel *__ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr,
1288 int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
1291 * \brief Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.
1292 * \param caller in channel that requested orig
1293 * \param orig channel being replaced by the call forward channel
1294 * \param timeout maximum amount of time to wait for setup of new forward channel
1295 * \param format capabilities for requested channel
1296 * \param oh outgoing helper used with original channel
1297 * \param outstate reason why unsuccessful (if uncuccessful)
1298 * \return Returns the forwarded call's ast_channel on success or NULL on failure
1300 struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate);
1303 * \brief Register a channel technology (a new channel driver)
1304 * Called by a channel module to register the kind of channels it supports.
1305 * \param tech Structure defining channel technology or "type"
1306 * \return Returns 0 on success, -1 on failure.
1308 int ast_channel_register(const struct ast_channel_tech *tech);
1311 * \brief Unregister a channel technology
1312 * \param tech Structure defining channel technology or "type" that was previously registered
1313 * \return No return value.
1315 void ast_channel_unregister(const struct ast_channel_tech *tech);
1318 * \brief Get a channel technology structure by name
1319 * \param name name of technology to find
1320 * \return a pointer to the structure, or NULL if no matching technology found
1322 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
1324 #ifdef CHANNEL_TRACE
1326 * \brief Update the context backtrace if tracing is enabled
1327 * \return Returns 0 on success, -1 on failure
1329 int ast_channel_trace_update(struct ast_channel *chan);
1332 * \brief Enable context tracing in the channel
1333 * \return Returns 0 on success, -1 on failure
1335 int ast_channel_trace_enable(struct ast_channel *chan);
1338 * \brief Disable context tracing in the channel.
1339 * \note Does not remove current trace entries
1340 * \return Returns 0 on success, -1 on failure
1342 int ast_channel_trace_disable(struct ast_channel *chan);
1345 * \brief Whether or not context tracing is enabled
1346 * \return Returns -1 when the trace is enabled. 0 if not.
1348 int ast_channel_trace_is_enabled(struct ast_channel *chan);
1351 * \brief Put the channel backtrace in a string
1352 * \return Returns the amount of lines in the backtrace. -1 on error.
1354 int ast_channel_trace_serialize(struct ast_channel *chan, struct ast_str **out);
1358 * \brief Hang up a channel
1359 * \note Absolutely _NO_ channel locks should be held before calling this function.
1360 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
1361 * performs all stream stopping, etc, on the channel that needs to end.
1362 * chan is no longer valid after this call.
1363 * \param chan channel to hang up
1364 * \return Returns 0 on success, -1 on failure.
1366 int ast_hangup(struct ast_channel *chan);
1369 * \brief Softly hangup up a channel
1371 * \param chan channel to be soft-hung-up
1372 * \param reason an AST_SOFTHANGUP_* reason code
1375 * Call the protocol layer, but don't destroy the channel structure
1376 * (use this if you are trying to
1377 * safely hangup a channel managed by another thread.
1379 * \note The channel passed to this function does not need to be locked.
1381 * \return Returns 0 regardless
1383 int ast_softhangup(struct ast_channel *chan, int reason);
1386 * \brief Softly hangup up a channel (no channel lock)
1387 * \param chan channel to be soft-hung-up
1388 * \param reason an AST_SOFTHANGUP_* reason code
1390 int ast_softhangup_nolock(struct ast_channel *chan, int reason);
1393 * \brief Clear a set of softhangup flags from a channel
1395 * Never clear a softhangup flag from a channel directly. Instead,
1396 * use this function. This ensures that all aspects of the softhangup
1397 * process are aborted.
1399 * \param chan the channel to clear the flag on
1400 * \param flag the flag or flags to clear
1404 void ast_channel_clear_softhangup(struct ast_channel *chan, int flag);
1407 * \brief Set the source of the hangup in this channel and it's bridge
1409 * \param chan channel to set the field on
1410 * \param source a string describing the source of the hangup for this channel
1413 * \note Absolutely _NO_ channel locks should be held before calling this function.
1417 * Hangupsource is generally the channel name that caused the bridge to be
1418 * hung up, but it can also be other things such as "dialplan/agi"
1419 * This can then be logged in the CDR or CEL
1421 void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);
1423 /*! \brief Check to see if a channel is needing hang up
1424 * \param chan channel on which to check for hang up
1425 * This function determines if the channel is being requested to be hung up.
1426 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
1428 int ast_check_hangup(struct ast_channel *chan);
1430 int ast_check_hangup_locked(struct ast_channel *chan);
1433 * \brief Lock the given channel, then request softhangup on the channel with the given causecode
1434 * \param chan channel on which to hang up
1435 * \param causecode cause code to use (Zero if don't use cause code)
1438 void ast_channel_softhangup_withcause_locked(struct ast_channel *chan, int causecode);
1441 * \brief Compare a offset with the settings of when to hang a channel up
1442 * \param chan channel on which to check for hang up
1443 * \param offset offset in seconds from current time
1444 * \return 1, 0, or -1
1446 * This function compares a offset from current time with the absolute time
1447 * out on a channel (when to hang up). If the absolute time out on a channel
1448 * is earlier than current time plus the offset, it returns 1, if the two
1449 * time values are equal, it return 0, otherwise, it return -1.
1450 * \sa ast_channel_cmpwhentohangup_tv()
1451 * \version 1.6.1 deprecated function (only had seconds precision)
1453 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1456 * \brief Compare a offset with the settings of when to hang a channel up
1457 * \param chan channel on which to check for hangup
1458 * \param offset offset in seconds and microseconds from current time
1459 * \return 1, 0, or -1
1460 * This function compares a offset from current time with the absolute time
1461 * out on a channel (when to hang up). If the absolute time out on a channel
1462 * is earlier than current time plus the offset, it returns 1, if the two
1463 * time values are equal, it return 0, otherwise, it return -1.
1466 int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1469 * \brief Set when to hang a channel up
1471 * \param chan channel on which to check for hang up
1472 * \param offset offset in seconds relative to the current time of when to hang up
1475 * This function sets the absolute time out on a channel (when to hang up).
1477 * \note This function does not require that the channel is locked before
1481 * \sa ast_channel_setwhentohangup_tv()
1482 * \version 1.6.1 deprecated function (only had seconds precision)
1484 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1487 * \brief Set when to hang a channel up
1489 * \param chan channel on which to check for hang up
1490 * \param offset offset in seconds and useconds relative to the current time of when to hang up
1492 * This function sets the absolute time out on a channel (when to hang up).
1494 * \note This function does not require that the channel is locked before
1500 void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1503 * \brief Answer a channel
1505 * \param chan channel to answer
1508 * This function answers a channel and handles all necessary call
1511 * \note The channel passed does not need to be locked, but is locked
1512 * by the function when needed.
1514 * \note This function will wait up to 500 milliseconds for media to
1515 * arrive on the channel before returning to the caller, so that the
1516 * caller can properly assume the channel is 'ready' for media flow.
1518 * \retval 0 on success
1519 * \retval non-zero on failure
1521 int ast_answer(struct ast_channel *chan);
1524 * \brief Answer a channel
1526 * \param chan channel to answer
1527 * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
1529 * This function answers a channel and handles all necessary call
1532 * \note The channel passed does not need to be locked, but is locked
1533 * by the function when needed.
1535 * \note Unlike ast_answer(), this function will not wait for media
1536 * flow to begin. The caller should be careful before sending media
1537 * to the channel before incoming media arrives, as the outgoing
1538 * media may be lost.
1540 * \retval 0 on success
1541 * \retval non-zero on failure
1543 int ast_raw_answer(struct ast_channel *chan, int cdr_answer);
1546 * \brief Answer a channel, with a selectable delay before returning
1548 * \param chan channel to answer
1549 * \param delay maximum amount of time to wait for incoming media
1550 * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
1552 * This function answers a channel and handles all necessary call
1555 * \note The channel passed does not need to be locked, but is locked
1556 * by the function when needed.
1558 * \note This function will wait up to 'delay' milliseconds for media to
1559 * arrive on the channel before returning to the caller, so that the
1560 * caller can properly assume the channel is 'ready' for media flow. If
1561 * 'delay' is less than 500, the function will wait up to 500 milliseconds.
1563 * \retval 0 on success
1564 * \retval non-zero on failure
1566 int __ast_answer(struct ast_channel *chan, unsigned int delay, int cdr_answer);
1569 * \brief Execute a Gosub call on the channel before a call is placed.
1573 * This is called between ast_request() and ast_call() to
1574 * execute a predial routine on the newly created channel.
1576 * \param chan Channel to execute Gosub.
1577 * \param sub_args Gosub application parameter string.
1579 * \note Absolutely _NO_ channel locks should be held before calling this function.
1581 * \retval 0 on success.
1582 * \retval -1 on error.
1584 int ast_pre_call(struct ast_channel *chan, const char *sub_args);
1587 * \brief Make a call
1588 * \note Absolutely _NO_ channel locks should be held before calling this function.
1589 * \param chan which channel to make the call on
1590 * \param addr destination of the call
1591 * \param timeout time to wait on for connect (Doesn't seem to be used.)
1593 * Place a call, take no longer than timeout ms.
1594 * \retval 0 on success
1595 * \retval -1 on failure
1597 int ast_call(struct ast_channel *chan, const char *addr, int timeout);
1600 * \brief Indicates condition of channel
1601 * \note Absolutely _NO_ channel locks should be held before calling this function.
1602 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
1603 * \param chan channel to change the indication
1604 * \param condition which condition to indicate on the channel
1605 * \return Returns 0 on success, -1 on failure
1607 int ast_indicate(struct ast_channel *chan, int condition);
1610 * \brief Indicates condition of channel, with payload
1611 * \note Absolutely _NO_ channel locks should be held before calling this function.
1612 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
1613 * \param chan channel to change the indication
1614 * \param condition which condition to indicate on the channel
1615 * \param data pointer to payload data
1616 * \param datalen size of payload data
1617 * \return Returns 0 on success, -1 on failure
1619 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1621 /* Misc stuff ------------------------------------------------ */
1624 * \brief Wait for input on a channel
1625 * \param chan channel to wait on
1626 * \param ms length of time to wait on the channel
1628 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
1629 * \retval < 0 on failure
1630 * \retval 0 if nothing ever arrived
1631 * \retval the # of ms remaining otherwise
1633 int ast_waitfor(struct ast_channel *chan, int ms);
1636 * \brief Should we keep this frame for later?
1638 * There are functions such as ast_safe_sleep which will
1639 * service a channel to ensure that it does not have a
1640 * large backlog of queued frames. When this happens,
1641 * we want to hold on to specific frame types and just drop
1642 * others. This function will tell if the frame we just
1643 * read should be held onto.
1645 * \param frame The frame we just read
1646 * \retval 1 frame should be kept
1647 * \retval 0 frame should be dropped
1649 int ast_is_deferrable_frame(const struct ast_frame *frame);
1652 * \brief Wait for a specified amount of time, looking for hangups
1653 * \param chan channel to wait for
1654 * \param ms length of time in milliseconds to sleep
1656 * Waits for a specified amount of time, servicing the channel as required.
1657 * \return returns -1 on hangup, otherwise 0.
1659 int ast_safe_sleep(struct ast_channel *chan, int ms);
1662 * \brief Wait for a specified amount of time, looking for hangups and a condition argument
1663 * \param chan channel to wait for
1664 * \param ms length of time in milliseconds to sleep
1665 * \param cond a function pointer for testing continue condition
1666 * \param data argument to be passed to the condition test function
1667 * \return returns -1 on hangup, otherwise 0.
1669 * Waits for a specified amount of time, servicing the channel as required. If cond
1670 * returns 0, this function returns.
1672 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
1675 * \brief Waits for activity on a group of channels
1676 * \param chan an array of pointers to channels
1677 * \param n number of channels that are to be waited upon
1678 * \param fds an array of fds to wait upon
1679 * \param nfds the number of fds to wait upon
1680 * \param exception exception flag
1681 * \param outfd fd that had activity on it
1682 * \param ms how long the wait was
1684 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
1686 * \return Returns the channel with activity, or NULL on error or if an FD
1687 * came first. If the FD came first, it will be returned in outfd, otherwise, outfd
1690 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
1691 int *fds, int nfds, int *exception, int *outfd, int *ms);
1694 * \brief Waits for input on a group of channels
1695 * Wait for input on an array of channels for a given # of milliseconds.
1696 * \return Return channel with activity, or NULL if none has activity.
1697 * \param chan an array of pointers to channels
1698 * \param n number of channels that are to be waited upon
1699 * \param ms time "ms" is modified in-place, if applicable
1701 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
1704 * \brief Waits for input on an fd
1705 * \note This version works on fd's only. Be careful with it.
1707 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
1711 * \brief Reads a frame
1712 * \param chan channel to read a frame from
1713 * \return Returns a frame, or NULL on error. If it returns NULL, you
1714 * best just stop reading frames and assume the channel has been
1717 struct ast_frame *ast_read(struct ast_channel *chan);
1720 * \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
1721 * \param chan channel to read a frame from
1722 * \return Returns a frame, or NULL on error. If it returns NULL, you
1723 * best just stop reading frames and assume the channel has been
1725 * \note Audio is replaced with AST_FRAME_NULL to avoid
1726 * transcode when the resulting audio is not necessary.
1728 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
1731 * \brief Write a frame to a channel
1732 * This function writes the given frame to the indicated channel.
1733 * \param chan destination channel of the frame
1734 * \param frame frame that will be written
1735 * \return It returns 0 on success, -1 on failure.
1737 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
1740 * \brief Write video frame to a channel
1741 * This function writes the given frame to the indicated channel.
1742 * \param chan destination channel of the frame
1743 * \param frame frame that will be written
1744 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1746 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
1749 * \brief Write text frame to a channel
1750 * This function writes the given frame to the indicated channel.
1751 * \param chan destination channel of the frame
1752 * \param frame frame that will be written
1753 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1755 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
1757 /*! \brief Send empty audio to prime a channel driver */
1758 int ast_prod(struct ast_channel *chan);
1761 * \brief Sets read format on channel chan from capabilities
1762 * Set read format for channel to whichever component of "format" is best.
1763 * \param chan channel to change
1764 * \param formats new formats to pick from for reading
1765 * \return Returns 0 on success, -1 on failure
1767 int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
1770 * \brief Sets read format on channel chan
1771 * \param chan channel to change
1772 * \param formats, format to set for reading
1773 * \return Returns 0 on success, -1 on failure
1775 int ast_set_read_format(struct ast_channel *chan, struct ast_format *format);
1778 * \brief Sets read format on channel chan by id
1779 * \param chan channel to change
1780 * \param format id to set for reading, only used for formats without attributes
1781 * \return Returns 0 on success, -1 on failure
1783 int ast_set_read_format_by_id(struct ast_channel *chan, enum ast_format_id id);
1786 * \brief Sets write format on channel chan
1787 * Set write format for channel to whichever component of "format" is best.
1788 * \param chan channel to change
1789 * \param formats new formats to pick from for writing
1790 * \return Returns 0 on success, -1 on failure
1792 int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
1795 * \brief Sets write format on channel chan
1796 * \param chan channel to change
1797 * \param formats, format to set for writing
1798 * \return Returns 0 on success, -1 on failure
1800 int ast_set_write_format(struct ast_channel *chan, struct ast_format *format);
1803 * \brief Sets write format on channel chan
1804 * \param chan channel to change
1805 * \param format id to set for writing, only used for formats without attributes
1806 * \return Returns 0 on success, -1 on failure
1808 int ast_set_write_format_by_id(struct ast_channel *chan, enum ast_format_id id);
1811 * \brief Sends text to a channel
1813 * \param chan channel to act upon
1814 * \param text string of text to send on the channel
1817 * Write text to a display on a channel
1819 * \note The channel does not need to be locked before calling this function.
1821 * \retval 0 on success
1822 * \retval -1 on failure
1824 int ast_sendtext(struct ast_channel *chan, const char *text);
1827 * \brief Receives a text character from a channel
1828 * \param chan channel to act upon
1829 * \param timeout timeout in milliseconds (0 for infinite wait)
1831 * Read a char of text from a channel
1832 * \return 0 on success, -1 on failure
1834 int ast_recvchar(struct ast_channel *chan, int timeout);
1837 * \brief Send a DTMF digit to a channel.
1838 * \param chan channel to act upon
1839 * \param digit the DTMF digit to send, encoded in ASCII
1840 * \param duration the duration of the digit ending in ms
1841 * \return 0 on success, -1 on failure
1843 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
1846 * \brief Send a DTMF digit to a channel.
1847 * \param chan channel to act upon
1848 * \param digit the DTMF digit to send, encoded in ASCII
1849 * \return 0 on success, -1 on failure
1851 int ast_senddigit_begin(struct ast_channel *chan, char digit);
1854 * \brief Send a DTMF digit to a channel.
1855 * \param chan channel to act upon
1856 * \param digit the DTMF digit to send, encoded in ASCII
1857 * \param duration the duration of the digit ending in ms
1858 * \return Returns 0 on success, -1 on failure
1860 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
1863 * \brief Receives a text string from a channel
1864 * Read a string of text from a channel
1865 * \param chan channel to act upon
1866 * \param timeout timeout in milliseconds (0 for infinite wait)
1867 * \return the received text, or NULL to signify failure.
1869 char *ast_recvtext(struct ast_channel *chan, int timeout);
1872 * \brief Waits for a digit
1873 * \param c channel to wait for a digit on
1874 * \param ms how many milliseconds to wait
1875 * \return Returns <0 on error, 0 on no entry, and the digit on success.
1877 int ast_waitfordigit(struct ast_channel *c, int ms);
1880 * \brief Wait for a digit
1881 * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1882 * \param c channel to wait for a digit on
1883 * \param ms how many milliseconds to wait
1884 * \param audiofd audio file descriptor to write to if audio frames are received
1885 * \param ctrlfd control file descriptor to monitor for reading
1886 * \return Returns 1 if ctrlfd becomes available
1888 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
1891 * \brief Reads multiple digits
1892 * \param c channel to read from
1893 * \param s string to read in to. Must be at least the size of your length
1894 * \param len how many digits to read (maximum)
1895 * \param timeout how long to timeout between digits
1896 * \param rtimeout timeout to wait on the first digit
1897 * \param enders digits to end the string
1899 * Read in a digit string "s", max length "len", maximum timeout between
1900 * digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
1901 * for the first digit.
1902 * \return Returns 0 on normal return, or 1 on a timeout. In the case of
1903 * a timeout, any digits that were read before the timeout will still be available in s.
1904 * RETURNS 2 in full version when ctrlfd is available, NOT 1
1906 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
1907 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
1909 /*! \brief Report DTMF on channel 0 */
1910 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
1911 /*! \brief Report DTMF on channel 1 */
1912 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
1913 /*! \brief Return all voice frames on channel 0 */
1914 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
1915 /*! \brief Return all voice frames on channel 1 */
1916 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
1917 /*! \brief Ignore all signal frames except NULL */
1918 #define AST_BRIDGE_IGNORE_SIGS (1 << 4)
1922 * \brief Makes two channel formats compatible
1923 * \param c0 first channel to make compatible
1924 * \param c1 other channel to make compatible
1926 * Set two channels to compatible formats -- call before ast_channel_bridge in general.
1927 * \return Returns 0 on success and -1 if it could not be done
1929 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
1932 * \brief Bridge two channels together (early)
1933 * \param c0 first channel to bridge
1934 * \param c1 second channel to bridge
1936 * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
1937 * \return Returns 0 on success and -1 if it could not be done
1939 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
1942 * \brief Bridge two channels together
1943 * \param c0 first channel to bridge
1944 * \param c1 second channel to bridge
1945 * \param config config for the channels
1946 * \param fo destination frame(?)
1947 * \param rc destination channel(?)
1949 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
1950 * *rf (remember, it could be NULL) and which channel (0 or 1) in rc
1952 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
1953 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
1954 struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
1957 * \brief Weird function made for call transfers
1959 * \param original channel to make a copy of
1960 * \param clone copy of the original channel
1963 * This is a very strange and freaky function used primarily for transfer. Suppose that
1964 * "original" and "clone" are two channels in random situations. This function takes
1965 * the guts out of "clone" and puts them into the "original" channel, then alerts the
1966 * channel driver of the change, asking it to fixup any private information (like the
1967 * p->owner pointer) that is affected by the change. The physical layer of the original
1968 * channel is hung up.
1970 * \note Neither channel passed here should be locked before
1971 * calling this function. This function performs deadlock
1972 * avoidance involving these two channels.
1974 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
1977 * \brief Setup a masquerade to transfer a call.
1980 * \param target_chan Target of the call transfer. (Masquerade original channel)
1981 * \param target_id New connected line information for the target channel.
1982 * \param target_held TRUE if the target call is on hold.
1983 * \param transferee_chan Transferee of the call transfer. (Masquerade clone channel)
1984 * \param transferee_id New connected line information for the transferee channel.
1985 * \param transferee_held TRUE if the transferee call is on hold.
1988 * Party A - Transferee
1989 * Party B - Transferer
1990 * Party C - Target of transfer
1992 * Party B transfers A to C.
1994 * Party A is connected to bridged channel B1.
1995 * Party B is connected to channels C1 and C2.
1996 * Party C is connected to bridged channel B2.
1998 * Party B -- C1 == B1 -- Party A
2001 * Party B -- C2 == B2 -- Party C
2003 * Bridged channel B1 is masqueraded into channel C2. Where B1
2004 * is the masquerade clone channel and C2 is the masquerade
2007 * \see ast_channel_masquerade()
2009 * \note Has the same locking requirements as ast_channel_masquerade().
2011 * \retval 0 on success.
2012 * \retval -1 on error.
2014 int ast_channel_transfer_masquerade(
2015 struct ast_channel *target_chan,
2016 const struct ast_party_connected_line *target_id,
2018 struct ast_channel *transferee_chan,
2019 const struct ast_party_connected_line *transferee_id,
2020 int transferee_held);
2023 * \brief Gives the string form of a given cause code.
2025 * \param state cause to get the description of
2026 * \return the text form of the binary cause code given
2028 const char *ast_cause2str(int state) attribute_pure;
2031 * \brief Convert the string form of a cause code to a number
2033 * \param name string form of the cause
2034 * \return the cause code
2036 int ast_str2cause(const char *name) attribute_pure;
2039 * \brief Gives the string form of a given channel state
2041 * \param ast_channel_state state to get the name of
2042 * \return the text form of the binary state given
2044 const char *ast_state2str(enum ast_channel_state);
2047 * \brief Gives the string form of a given transfer capability
2049 * \param transfercapability transfer capability to get the name of
2050 * \return the text form of the binary transfer capability
2052 char *ast_transfercapability2str(int transfercapability) attribute_const;
2055 * Options: Some low-level drivers may implement "options" allowing fine tuning of the
2056 * low level channel. See frame.h for options. Note that many channel drivers may support
2057 * none or a subset of those features, and you should not count on this if you want your
2058 * asterisk application to be portable. They're mainly useful for tweaking performance
2062 * \brief Sets an option on a channel
2064 * \param channel channel to set options on
2065 * \param option option to change
2066 * \param data data specific to option
2067 * \param datalen length of the data
2068 * \param block blocking or not
2070 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
2071 * \return 0 on success and -1 on failure
2073 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
2076 * \brief Pick the best codec
2078 * \param capabilities to pick best codec out of
2079 * \param result stucture to store the best codec in.
2080 * \retval on success, pointer to result structure
2081 * \retval on failure, NULL
2083 struct ast_format *ast_best_codec(struct ast_format_cap *cap, struct ast_format *result);
2087 * \brief Checks the value of an option
2089 * Query the value of an option
2090 * Works similarly to setoption except only reads the options.
2092 int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
2095 * \brief Checks for HTML support on a channel
2096 * \return 0 if channel does not support HTML or non-zero if it does
2098 int ast_channel_supports_html(struct ast_channel *channel);
2101 * \brief Sends HTML on given channel
2102 * Send HTML or URL on link.
2103 * \return 0 on success or -1 on failure
2105 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
2108 * \brief Sends a URL on a given link
2110 * \return 0 on success or -1 on failure
2112 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
2115 * \brief Defers DTMF so that you only read things like hangups and audio.
2116 * \return non-zero if channel was already DTMF-deferred or
2117 * 0 if channel is just now being DTMF-deferred
2119 int ast_channel_defer_dtmf(struct ast_channel *chan);
2121 /*! Undo defer. ast_read will return any DTMF characters that were queued */
2122 void ast_channel_undefer_dtmf(struct ast_channel *chan);
2124 /*! Initiate system shutdown -- prevents new channels from being allocated.
2125 * \param hangup If "hangup" is non-zero, all existing channels will receive soft
2127 void ast_begin_shutdown(int hangup);
2129 /*! Cancels an existing shutdown and returns to normal operation */
2130 void ast_cancel_shutdown(void);
2132 /*! \return number of channels available for lookup */
2133 int ast_active_channels(void);
2135 /*! \return the number of channels not yet destroyed */
2136 int ast_undestroyed_channels(void);
2138 /*! \return non-zero if Asterisk is being shut down */
2139 int ast_shutting_down(void);
2141 /*! Activate a given generator */
2142 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
2144 /*! Deactivate an active generator */
2145 void ast_deactivate_generator(struct ast_channel *chan);
2148 * \brief Set caller ID number, name and ANI and generate AMI event.
2150 * \note Use ast_channel_set_caller() and ast_channel_set_caller_event() instead.
2151 * \note The channel does not need to be locked before calling this function.
2153 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
2156 * \brief Set the caller id information in the Asterisk channel
2159 * \param chan Asterisk channel to set caller id information
2160 * \param caller Caller id information
2161 * \param update What caller information to update. NULL if all.
2165 * \note The channel does not need to be locked before calling this function.
2167 void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
2170 * \brief Set the caller id information in the Asterisk channel and generate an AMI event
2171 * if the caller id name or number changed.
2174 * \param chan Asterisk channel to set caller id information
2175 * \param caller Caller id information
2176 * \param update What caller information to update. NULL if all.
2180 * \note The channel does not need to be locked before calling this function.
2182 void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
2184 /*! Set the file descriptor on the channel */
2185 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
2187 /*! Add a channel to an optimized waitfor */
2188 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
2190 /*! Delete a channel from an optimized waitfor */
2191 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
2193 /*! Start a tone going */
2194 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
2195 /*! Stop a tone from playing */
2196 void ast_tonepair_stop(struct ast_channel *chan);
2197 /*! Play a tone pair for a given amount of time */
2198 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
2201 * \brief Automatically service a channel for us...
2204 * \retval -1 failure, or the channel is already being autoserviced
2206 int ast_autoservice_start(struct ast_channel *chan);
2209 * \brief Stop servicing a channel for us...
2211 * \note if chan is locked prior to calling ast_autoservice_stop, it
2212 * is likely that there will be a deadlock between the thread that calls
2213 * ast_autoservice_stop and the autoservice thread. It is important
2214 * that chan is not locked prior to this call
2218 * \retval -1 error, or the channel has been hungup
2220 int ast_autoservice_stop(struct ast_channel *chan);
2223 * \brief Put chan into autoservice while hanging up peer.
2226 * \param chan Chan to put into autoservice.
2227 * \param peer Chan to run hangup handlers and hangup.
2231 void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer);
2234 * \brief Ignore certain frame types
2235 * \note Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames
2236 * while a channel is in autoservice and queue them up when taken out of
2237 * autoservice. When this is not desireable, this API may be used to
2238 * cause the channel to ignore those frametypes after the channel is put
2239 * into autoservice, but before autoservice is stopped.
2241 * \retval -1 channel is not in autoservice
2243 int ast_autoservice_ignore(struct ast_channel *chan, enum ast_frame_type ftype);
2246 * \brief Enable or disable timer ticks for a channel
2249 * \param rate number of timer ticks per second
2250 * \param func callback function
2254 * If timers are supported, force a scheduled expiration on the
2255 * timer fd, at which point we call the callback function / data
2257 * \note Call this function with a rate of 0 to turn off the timer ticks
2259 * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
2261 int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
2264 * \brief Transfer a channel (if supported).
2265 * \retval -1 on error
2266 * \retval 0 if not supported
2267 * \retval 1 if supported and requested
2268 * \param chan current channel
2269 * \param dest destination extension for transfer
2271 int ast_transfer(struct ast_channel *chan, char *dest);
2274 * \brief Start masquerading a channel
2275 * \note absolutely _NO_ channel locks should be held before calling this function.
2277 * XXX This is a seriously whacked out operation. We're essentially putting the guts of
2278 * the clone channel into the original channel. Start by killing off the original
2279 * channel's backend. I'm not sure we're going to keep this function, because
2280 * while the features are nice, the cost is very high in terms of pure nastiness. XXX
2281 * \param chan Channel to masquerade
2283 int ast_do_masquerade(struct ast_channel *chan);
2286 * \brief Find bridged channel
2288 * \note This function does _not_ return a reference to the bridged channel.
2289 * The reason for this is mostly historical. It _should_ return a reference,
2290 * but it will take a lot of work to make the code base account for that.
2291 * So, for now, the old rules still apply for how to handle this function.
2292 * If this function is being used from the channel thread that owns the channel,
2293 * then a reference is already held, and channel locking is not required to
2294 * guarantee that the channel will stay around. If this function is used
2295 * outside of the associated channel thread, the channel parameter 'chan'
2296 * MUST be locked before calling this function. Also, 'chan' must remain locked
2297 * for the entire time that the result of this function is being used.
2299 * \param chan Current channel
2301 * \return A pointer to the bridged channel
2303 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
2306 * \brief Inherits channel variable from parent to child channel
2307 * \param parent Parent channel
2308 * \param child Child channel
2311 * Scans all channel variables in the parent channel, looking for those
2312 * that should be copied into the child channel.
2313 * Variables whose names begin with a single '_' are copied into the
2314 * child channel with the prefix removed.
2315 * Variables whose names begin with '__' are copied into the child
2316 * channel with their names unchanged.
2318 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
2321 * \brief adds a list of channel variables to a channel
2322 * \param chan the channel
2323 * \param vars a linked list of variables
2326 * Variable names can be for a regular channel variable or a dialplan function
2327 * that has the ability to be written to.
2329 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
2332 * \brief An opaque 'object' structure use by silence generators on channels.
2334 struct ast_silence_generator;
2337 * \brief Starts a silence generator on the given channel.
2338 * \param chan The channel to generate silence on
2339 * \return An ast_silence_generator pointer, or NULL if an error occurs
2342 * This function will cause SLINEAR silence to be generated on the supplied
2343 * channel until it is disabled; if the channel cannot be put into SLINEAR
2344 * mode then the function will fail.
2347 * The pointer returned by this function must be preserved and passed to
2348 * ast_channel_stop_silence_generator when you wish to stop the silence
2351 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
2354 * \brief Stops a previously-started silence generator on the given channel.
2355 * \param chan The channel to operate on
2356 * \param state The ast_silence_generator pointer return by a previous call to
2357 * ast_channel_start_silence_generator.
2361 * This function will stop the operating silence generator and return the channel
2362 * to its previous write format.
2364 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
2367 * \brief Check if the channel can run in internal timing mode.
2368 * \param chan The channel to check
2372 * This function will return 1 if internal timing is enabled and the timing
2373 * device is available.
2375 int ast_internal_timing_enabled(struct ast_channel *chan);
2377 /* Misc. functions below */
2380 * \brief if fd is a valid descriptor, set *pfd with the descriptor
2381 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
2382 * return value to the index into the array)
2384 static inline int ast_add_fd(struct pollfd *pfd, int fd)
2387 pfd->events = POLLIN | POLLPRI;
2391 /*! \brief Helper function for migrating select to poll */
2392 static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
2401 for (x = *start; x < maximum; x++)
2402 if (pfds[x].fd == fd) {
2405 return pfds[x].revents;
2410 /*! \brief Retrieves the current T38 state of a channel */
2411 static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
2413 enum ast_t38_state state = T38_STATE_UNAVAILABLE;
2414 int datalen = sizeof(state);
2416 ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
2421 #define CHECK_BLOCKING(c) do { \
2422 if (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING)) {\
2423 ast_debug(1, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), ast_channel_name(c), (long) ast_channel_blocker(c), ast_channel_blockproc(c)); \
2425 ast_channel_blocker_set((c), pthread_self()); \
2426 ast_channel_blockproc_set((c), __PRETTY_FUNCTION__); \
2427 ast_set_flag(ast_channel_flags(c), AST_FLAG_BLOCKING); \
2430 ast_group_t ast_get_group(const char *s);
2432 /*! \brief Print call- and pickup groups into buffer */
2433 char *ast_print_group(char *buf, int buflen, ast_group_t group);
2435 /*! \brief Opaque struct holding a namedgroups set, i.e. a set of group names */
2436 struct ast_namedgroups;
2438 /*! \brief Create an ast_namedgroups set with group name from comma separated string s */
2439 struct ast_namedgroups *ast_get_namedgroups(const char *s);
2440 struct ast_namedgroups *ast_unref_namedgroups(struct ast_namedgroups *groups);
2441 struct ast_namedgroups *ast_ref_namedgroups(struct ast_namedgroups *groups);
2442 /*! \brief Return TRUE if group a and b contain at least one common groupname */
2443 int ast_namedgroups_intersect(struct ast_namedgroups *a, struct ast_namedgroups *b);
2445 /*! \brief Print named call groups and named pickup groups ---*/
2446 char *ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *groups);
2449 * \brief Convert enum channelreloadreason to text string for manager event
2450 * \param reason The reason for reload (manager, cli, start etc)
2452 const char *channelreloadreason2txt(enum channelreloadreason reason);
2454 /*! \brief return an ast_variable list of channeltypes */
2455 struct ast_variable *ast_channeltype_list(void);
2458 * \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
2459 * \param reason The integer argument, usually taken from AST_CONTROL_ macros
2460 * \return char pointer explaining the code
2462 const char *ast_channel_reason2str(int reason);
2464 /*! \brief channel group info */
2465 struct ast_group_info {
2466 struct ast_channel *chan;
2469 AST_LIST_ENTRY(ast_group_info) group_list;
2472 #define ast_channel_lock(chan) ao2_lock(chan)
2473 #define ast_channel_unlock(chan) ao2_unlock(chan)
2474 #define ast_channel_trylock(chan) ao2_trylock(chan)
2477 * \brief Lock two channels.
2479 #define ast_channel_lock_both(chan1, chan2) do { \
2480 ast_channel_lock(chan1); \
2481 while (ast_channel_trylock(chan2)) { \
2482 ast_channel_unlock(chan1); \
2484 ast_channel_lock(chan1); \
2489 * \brief Increase channel reference count
2491 * \param c the channel
2497 #define ast_channel_ref(c) ({ ao2_ref(c, +1); (c); })
2500 * \brief Decrease channel reference count
2502 * \param c the channel
2504 * \retval NULL always
2508 #define ast_channel_unref(c) ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })
2510 /*! Channel Iterating @{ */
2513 * \brief A channel iterator
2515 * This is an opaque type.
2517 struct ast_channel_iterator;
2520 * \brief Destroy a channel iterator
2522 * \param i the itereator to destroy
2525 * This function is used to destroy a channel iterator that was retrieved by
2526 * using one of the channel_iterator_xxx_new() functions.
2528 * \return NULL, for convenience to clear out the pointer to the iterator that
2529 * was just destroyed.
2533 struct ast_channel_iterator *ast_channel_iterator_destroy(struct ast_channel_iterator *i);
2536 * \brief Create a new channel iterator based on extension
2538 * \param exten The extension that channels must be in
2539 * \param context The context that channels must be in
2542 * After creating an iterator using this function, the ast_channel_iterator_next()
2543 * function can be used to iterate through all channels that are currently
2544 * in the specified context and extension.
2546 * \note You must call ast_channel_iterator_destroy() when done.
2548 * \retval NULL on failure
2549 * \retval a new channel iterator based on the specified parameters
2553 struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context);
2556 * \brief Create a new channel iterator based on name
2558 * \param name channel name or channel uniqueid to match
2559 * \param name_len number of characters in the channel name to match on. This
2560 * would be used to match based on name prefix. If matching on the full
2561 * channel name is desired, then this parameter should be 0.
2564 * After creating an iterator using this function, the ast_channel_iterator_next()
2565 * function can be used to iterate through all channels that exist that have
2566 * the specified name or name prefix.
2568 * \note You must call ast_channel_iterator_destroy() when done.
2570 * \retval NULL on failure
2571 * \retval a new channel iterator based on the specified parameters
2575 struct ast_channel_iterator *ast_channel_iterator_by_name_new(const char *name, size_t name_len);
2578 * \brief Create a new channel iterator
2581 * After creating an iterator using this function, the ast_channel_iterator_next()
2582 * function can be used to iterate through all channels that exist.
2584 * \note You must call ast_channel_iterator_destroy() when done.
2586 * \retval NULL on failure
2587 * \retval a new channel iterator
2591 struct ast_channel_iterator *ast_channel_iterator_all_new(void);
2594 * \brief Get the next channel for a channel iterator
2596 * \param i the channel iterator that was created using one of the
2597 * channel_iterator_xxx_new() functions.
2600 * This function should be used to iterate through all channels that match a
2601 * specified set of parameters that were provided when the iterator was created.
2603 * \retval the next channel that matches the parameters used when the iterator
2605 * \retval NULL, if no more channels match the iterator parameters.
2609 struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);
2611 /*! @} End channel iterator definitions. */
2614 * \brief Call a function with every active channel
2617 * This function executes a callback one time for each active channel on the
2618 * system. The channel is provided as an argument to the function.
2620 * \note Absolutely _NO_ channel locks should be held before calling this function.
2623 struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
2624 void *data, int ao2_flags);
2626 /*! @{ Channel search functions */
2629 * \brief Find a channel by name
2631 * \param name the name or uniqueid of the channel to search for
2634 * Find a channel that has the same name as the provided argument.
2636 * \retval a channel with the name specified by the argument
2637 * \retval NULL if no channel was found
2641 struct ast_channel *ast_channel_get_by_name(const char *name);
2644 * \brief Find a channel by a name prefix
2646 * \param name The channel name or uniqueid prefix to search for
2647 * \param name_len Only search for up to this many characters from the name
2650 * Find a channel that has the same name prefix as specified by the arguments.
2652 * \retval a channel with the name prefix specified by the arguments
2653 * \retval NULL if no channel was found
2657 struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);
2660 * \brief Find a channel by extension and context
2662 * \param exten the extension to search for
2663 * \param context the context to search for
2666 * Return a channel that is currently at the specified extension and context.
2668 * \retval a channel that is at the specified extension and context
2669 * \retval NULL if no channel was found
2673 struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);
2675 /*! @} End channel search functions. */
2678 \brief propagate the linked id between chan and peer
2680 void ast_channel_set_linkgroup(struct ast_channel *chan, struct ast_channel *peer);
2684 * \brief Initialize the given name structure.
2687 * \param init Name structure to initialize.
2691 void ast_party_name_init(struct ast_party_name *init);
2694 * \brief Copy the source party name information to the destination party name.
2697 * \param dest Destination party name
2698 * \param src Source party name
2702 void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src);
2705 * \brief Initialize the given party name structure using the given guide
2706 * for a set update operation.
2710 * The initialization is needed to allow a set operation to know if a
2711 * value needs to be updated. Simple integers need the guide's original
2712 * value in case the set operation is not trying to set a new value.
2713 * String values are simply set to NULL pointers if they are not going
2716 * \param init Party name structure to initialize.
2717 * \param guide Source party name to use as a guide in initializing.
2721 void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide);
2724 * \brief Set the source party name information into the destination party name.
2727 * \param dest The name one wishes to update
2728 * \param src The new name values to update the dest
2732 void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src);
2735 * \brief Destroy the party name contents
2738 * \param doomed The party name to destroy.
2742 void ast_party_name_free(struct ast_party_name *doomed);
2745 * \brief Initialize the given number structure.
2748 * \param init Number structure to initialize.
2752 void ast_party_number_init(struct ast_party_number *init);
2755 * \brief Copy the source party number information to the destination party number.
2758 * \param dest Destination party number
2759 * \param src Source party number
2763 void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src);
2766 * \brief Initialize the given party number structure using the given guide
2767 * for a set update operation.
2771 * The initialization is needed to allow a set operation to know if a
2772 * value needs to be updated. Simple integers need the guide's original
2773 * value in case the set operation is not trying to set a new value.
2774 * String values are simply set to NULL pointers if they are not going
2777 * \param init Party number structure to initialize.
2778 * \param guide Source party number to use as a guide in initializing.
2782 void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide);
2785 * \brief Set the source party number information into the destination party number.
2788 * \param dest The number one wishes to update
2789 * \param src The new number values to update the dest
2793 void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src);
2796 * \brief Destroy the party number contents
2799 * \param doomed The party number to destroy.
2803 void ast_party_number_free(struct ast_party_number *doomed);
2807 * \brief Initialize the given subaddress structure.
2809 * \param init Subaddress structure to initialize.
2813 void ast_party_subaddress_init(struct ast_party_subaddress *init);
2817 * \brief Copy the source party subaddress information to the destination party subaddress.
2819 * \param dest Destination party subaddress
2820 * \param src Source party subaddress
2824 void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2828 * \brief Initialize the given party subaddress structure using the given guide
2829 * for a set update operation.
2832 * The initialization is needed to allow a set operation to know if a
2833 * value needs to be updated. Simple integers need the guide's original
2834 * value in case the set operation is not trying to set a new value.
2835 * String values are simply set to NULL pointers if they are not going
2838 * \param init Party subaddress structure to initialize.
2839 * \param guide Source party subaddress to use as a guide in initializing.
2843 void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide);
2847 * \brief Set the source party subaddress information into the destination party subaddress.
2849 * \param dest The subaddress one wishes to update
2850 * \param src The new subaddress values to update the dest
2854 void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2858 * \brief Destroy the party subaddress contents
2860 * \param doomed The party subaddress to destroy.
2864 void ast_party_subaddress_free(struct ast_party_subaddress *doomed);
2867 * \brief Initialize the given party id structure.
2870 * \param init Party id structure to initialize.
2874 void ast_party_id_init(struct ast_party_id *init);
2877 * \brief Copy the source party id information to the destination party id.
2880 * \param dest Destination party id
2881 * \param src Source party id
2885 void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src);
2888 * \brief Initialize the given party id structure using the given guide
2889 * for a set update operation.
2893 * The initialization is needed to allow a set operation to know if a
2894 * value needs to be updated. Simple integers need the guide's original
2895 * value in case the set operation is not trying to set a new value.
2896 * String values are simply set to NULL pointers if they are not going
2899 * \param init Party id structure to initialize.
2900 * \param guide Source party id to use as a guide in initializing.
2904 void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide);
2907 * \brief Set the source party id information into the destination party id.
2910 * \param dest The id one wishes to update
2911 * \param src The new id values to update the dest
2912 * \param update What id information to update. NULL if all.
2916 void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update);
2919 * \brief Destroy the party id contents
2922 * \param doomed The party id to destroy.
2926 void ast_party_id_free(struct ast_party_id *doomed);
2929 * \brief Determine the overall presentation value for the given party.
2932 * \param id Party to determine the overall presentation value.
2934 * \return Overall presentation value for the given party.
2936 int ast_party_id_presentation(const struct ast_party_id *id);
2939 * \brief Initialize the given dialed structure.
2942 * \param init Dialed structure to initialize.
2946 void ast_party_dialed_init(struct ast_party_dialed *init);
2949 * \brief Copy the source dialed party information to the destination dialed party.
2952 * \param dest Destination dialed party
2953 * \param src Source dialed party
2957 void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
2960 * \brief Initialize the given dialed structure using the given
2961 * guide for a set update operation.
2965 * The initialization is needed to allow a set operation to know if a
2966 * value needs to be updated. Simple integers need the guide's original
2967 * value in case the set operation is not trying to set a new value.
2968 * String values are simply set to NULL pointers if they are not going
2971 * \param init Caller structure to initialize.
2972 * \param guide Source dialed to use as a guide in initializing.
2976 void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide);
2979 * \brief Set the dialed information based on another dialed source
2982 * This is similar to ast_party_dialed_copy, except that NULL values for
2983 * strings in the src parameter indicate not to update the corresponding dest values.
2985 * \param dest The dialed one wishes to update
2986 * \param src The new dialed values to update the dest
2990 void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
2993 * \brief Destroy the dialed party contents
2996 * \param doomed The dialed party to destroy.
3000 void ast_party_dialed_free(struct ast_party_dialed *doomed);
3004 * \brief Initialize the given caller structure.
3006 * \param init Caller structure to initialize.
3010 void ast_party_caller_init(struct ast_party_caller *init);
3014 * \brief Copy the source caller information to the destination caller.
3016 * \param dest Destination caller
3017 * \param src Source caller
3021 void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src);
3024 * \brief Initialize the given caller structure using the given
3025 * guide for a set update operation.
3029 * The initialization is needed to allow a set operation to know if a
3030 * value needs to be updated. Simple integers need the guide's original
3031 * value in case the set operation is not trying to set a new value.
3032 * String values are simply set to NULL pointers if they are not going
3035 * \param init Caller structure to initialize.
3036 * \param guide Source caller to use as a guide in initializing.
3040 void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide);
3043 * \brief Set the caller information based on another caller source
3046 * This is similar to ast_party_caller_copy, except that NULL values for
3047 * strings in the src parameter indicate not to update the corresponding dest values.
3049 * \param dest The caller one wishes to update
3050 * \param src The new caller values to update the dest
3051 * \param update What caller information to update. NULL if all.
3055 void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update);
3058 * \brief Destroy the caller party contents
3061 * \param doomed The caller party to destroy.
3065 void ast_party_caller_free(struct ast_party_caller *doomed);
3069 * \brief Initialize the given connected line structure.
3071 * \param init Connected line structure to initialize.
3075 void ast_party_connected_line_init(struct ast_party_connected_line *init);
3079 * \brief Copy the source connected line information to the destination connected line.
3081 * \param dest Destination connected line
3082 * \param src Source connected line
3086 void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);
3090 * \brief Initialize the given connected line structure using the given
3091 * guide for a set update operation.
3094 * The initialization is needed to allow a set operation to know if a
3095 * value needs to be updated. Simple integers need the guide's original
3096 * value in case the set operation is not trying to set a new value.
3097 * String values are simply set to NULL pointers if they are not going
3100 * \param init Connected line structure to initialize.
3101 * \param guide Source connected line to use as a guide in initializing.
3105 void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide);
3109 * \brief Set the connected line information based on another connected line source
3111 * This is similar to ast_party_connected_line_copy, except that NULL values for
3112 * strings in the src parameter indicate not to update the corresponding dest values.
3114 * \param dest The connected line one wishes to update
3115 * \param src The new connected line values to update the dest
3116 * \param update What connected line information to update. NULL if all.
3120 void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update);
3124 * \brief Collect the caller party information into a connected line structure.
3126 * \param connected Collected caller information for the connected line
3127 * \param caller Caller information.
3131 * \warning This is a shallow copy.
3132 * \warning DO NOT call ast_party_connected_line_free() on the filled in
3133 * connected line structure!
3135 void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_party_caller *caller);
3139 * \brief Destroy the connected line information contents
3141 * \param doomed The connected line information to destroy.
3145 void ast_party_connected_line_free(struct ast_party_connected_line *doomed);
3148 * \brief Initialize the given redirecting structure.
3151 * \param init Redirecting structure to initialize.
3155 void ast_party_redirecting_init(struct ast_party_redirecting *init);
3159 * \brief Copy the source redirecting information to the destination redirecting.
3161 * \param dest Destination redirecting
3162 * \param src Source redirecting
3166 void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src);
3170 * \brief Initialize the given redirecting id structure using the given guide
3171 * for a set update operation.
3174 * The initialization is needed to allow a set operation to know if a
3175 * value needs to be updated. Simple integers need the guide's original
3176 * value in case the set operation is not trying to set a new value.
3177 * String values are simply set to NULL pointers if they are not going
3180 * \param init Redirecting id structure to initialize.
3181 * \param guide Source redirecting id to use as a guide in initializing.
3185 void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide);
3188 * \brief Set the redirecting information based on another redirecting source
3191 * This is similar to ast_party_redirecting_copy, except that NULL values for
3192 * strings in the src parameter indicate not to update the corresponding dest values.
3194 * \param dest The redirecting one wishes to update
3195 * \param src The new redirecting values to update the dest
3196 * \param update What redirecting information to update. NULL if all.
3200 void ast_party_redirecting_set(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update);
3204 * \brief Destroy the redirecting information contents
3206 * \param doomed The redirecting information to destroy.
3210 void ast_party_redirecting_free(struct ast_party_redirecting *doomed);
3214 * \brief Copy the caller information to the connected line information.
3216 * \param dest Destination connected line information
3217 * \param src Source caller information
3221 * \note Assumes locks are already acquired
3223 void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src);
3227 * \brief Copy the connected line information to the caller information.
3229 * \param dest Destination caller information
3230 * \param src Source connected line information
3234 * \note Assumes locks are already acquired
3236 void ast_connected_line_copy_to_caller(struct ast_party_caller *dest, const struct ast_party_connected_line *src);
3240 * \brief Set the connected line information in the Asterisk channel
3242 * \param chan Asterisk channel to set connected line information
3243 * \param connected Connected line information
3244 * \param update What connected line information to update. NULL if all.
3248 * \note The channel does not need to be locked before calling this function.
3250 void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
3254 * \brief Build the connected line information data frame.
3256 * \param data Buffer to fill with the frame data
3257 * \param datalen Size of the buffer to fill
3258 * \param connected Connected line information
3259 * \param update What connected line information to build. NULL if all.
3261 * \retval -1 if error
3262 * \retval Amount of data buffer used
3264 int ast_connected_line_build_data(unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
3268 * \brief Parse connected line indication frame data
3270 * \param data Buffer with the frame data to parse
3271 * \param datalen Size of the buffer
3272 * \param connected Extracted connected line information
3274 * \retval 0 on success.
3275 * \retval -1 on error.
3277 * \note The filled in connected line structure needs to be initialized by
3278 * ast_party_connected_line_set_init() before calling. If defaults are not
3279 * required use ast_party_connected_line_init().
3280 * \note The filled in connected line structure needs to be destroyed by
3281 * ast_party_connected_line_free() when it is no longer needed.
3283 int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected);
3287 * \brief Indicate that the connected line information has changed
3289 * \param chan Asterisk channel to indicate connected line information
3290 * \param connected Connected line information
3291 * \param update What connected line information to update. NULL if all.
3295 void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
3299 * \brief Queue a connected line update frame on a channel
3301 * \param chan Asterisk channel to indicate connected line information
3302 * \param connected Connected line information
3303 * \param update What connected line information to update. NULL if all.
3307 void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
3311 * \brief Set the redirecting id information in the Asterisk channel
3313 * \param chan Asterisk channel to set redirecting id information
3314 * \param redirecting Redirecting id information
3315 * \param update What redirecting information to update. NULL if all.
3319 * \note The channel does not need to be locked before calling this function.
3321 void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3325 * \brief Build the redirecting id data frame.
3327 * \param data Buffer to fill with the frame data
3328 * \param datalen Size of the buffer to fill
3329 * \param redirecting Redirecting id information
3330 * \param update What redirecting information to build. NULL if all.
3332 * \retval -1 if error
3333 * \retval Amount of data buffer used
3335 int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3339 * \brief Parse redirecting indication frame data
3341 * \param data Buffer with the frame data to parse
3342 * \param datalen Size of the buffer
3343 * \param redirecting Extracted redirecting id information
3345 * \retval 0 on success.
3346 * \retval -1 on error.
3348 * \note The filled in id structure needs to be initialized by
3349 * ast_party_redirecting_set_init() before calling.
3350 * \note The filled in id structure needs to be destroyed by
3351 * ast_party_redirecting_free() when it is no longer needed.
3353 int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting);
3357 * \brief Indicate that the redirecting id has changed
3359 * \param chan Asterisk channel to indicate redirecting id information
3360 * \param redirecting Redirecting id information
3361 * \param update What redirecting information to update. NULL if all.
3365 void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3369 * \brief Queue a redirecting update frame on a channel
3371 * \param chan Asterisk channel to indicate redirecting id information
3372 * \param redirecting Redirecting id information
3373 * \param update What redirecting information to update. NULL if all.
3377 void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3381 * \brief Run a connected line interception macro and update a channel's connected line
3383 * \deprecated You should use the ast_channel_connected_line_sub() function instead.
3385 * Whenever we want to update a channel's connected line information, we may need to run
3386 * a macro so that an administrator can manipulate the information before sending it
3387 * out. This function both runs the macro and sends the update to the channel.
3389 * \param autoservice_chan Channel to place into autoservice while the macro is running.
3390 * It is perfectly safe for this to be NULL
3391 * \param macro_chan The channel to run the macro on. Also the channel from which we
3392 * determine which macro we need to run.
3393 * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
3394 * AST_CONTROL_CONNECTED_LINE
3395 * \param is_caller If true, then run CONNECTED_LINE_CALLER_SEND_MACRO with arguments from
3396 * CONNECTED_LINE_CALLER_SEND_MACRO_ARGS, otherwise run CONNECTED_LINE_CALLEE_SEND_MACRO
3397 * with arguments from CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS
3398 * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
3399 * ast_party_connected_line pointer.
3401 * \retval -1 Either the macro does not exist, or there was an error while attempting to
3404 * \todo Have multiple return codes based on the MACRO_RESULT
3405 * \todo Make constants so that caller and frame can be more expressive than just '1' and
3408 int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int frame);
3412 * \brief Run a connected line interception subroutine and update a channel's connected line
3415 * Whenever we want to update a channel's connected line information, we may need to run
3416 * a subroutine so that an administrator can manipulate the information before sending it
3417 * out. This function both runs the subroutine specified by CONNECTED_LINE_SEND_SUB and
3418 * sends the update to the channel.
3420 * \param autoservice_chan Channel to place into autoservice while the sub is running.
3421 * It is perfectly safe for this to be NULL
3422 * \param sub_chan The channel to run the subroutine on. Also the channel from which we
3423 * determine which subroutine we need to run.
3424 * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
3425 * AST_CONTROL_CONNECTED_LINE
3426 * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
3427 * ast_party_connected_line pointer.
3429 * \retval -1 Either the subroutine does not exist, or there was an error while attempting to
3430 * run the subroutine
3432 int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame);
3435 * \brief Insert into an astdata tree, the channel structure.
3436 * \param[in] tree The ast data tree.
3437 * \param[in] chan The channel structure to add to tree.
3438 * \param[in] add_bridged Add the bridged channel to the structure.
3439 * \retval <0 on error.
3440 * \retval 0 on success.
3442 int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan, int add_bridged);
3445 * \brief Compare to channel structures using the data api.
3446 * \param[in] tree The search tree generated by the data api.
3447 * \param[in] chan The channel to compare.
3448 * \param[in] structure_name The name of the node of the channel structure.
3449 * \retval 0 The structure matches.
3450 * \retval 1 The structure doesn't matches.
3452 int ast_channel_data_cmp_structure(const struct ast_data_search *tree, struct ast_channel *chan,
3453 const char *structure_name);
3457 * \brief Run a redirecting interception macro and update a channel's redirecting information
3458 * \deprecated You should use the ast_channel_redirecting_sub() function instead.
3461 * Whenever we want to update a channel's redirecting information, we may need to run
3462 * a macro so that an administrator can manipulate the information before sending it
3463 * out. This function both runs the macro and sends the update to the channel.
3465 * \param autoservice_chan Channel to place into autoservice while the macro is running.
3466 * It is perfectly safe for this to be NULL
3467 * \param macro_chan The channel to run the macro on. Also the channel from which we
3468 * determine which macro we need to run.