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 {
911 const char *cid_name;
913 struct ast_variable *vars;
914 struct ast_channel *parent_channel;
919 * Soft hangup requested by device or other internal reason.
920 * Actual hangup needed.
922 AST_SOFTHANGUP_DEV = (1 << 0),
924 * Used to break the normal frame flow so an async goto can be
925 * done instead of actually hanging up.
927 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
929 * Soft hangup requested by system shutdown. Actual hangup
932 AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
934 * Used to break the normal frame flow after a timeout so an
935 * implicit async goto can be done to the 'T' exten if it exists
936 * instead of actually hanging up. If the exten does not exist
937 * then actually hangup.
939 AST_SOFTHANGUP_TIMEOUT = (1 << 3),
941 * Soft hangup requested by application/channel-driver being
942 * unloaded. Actual hangup needed.
944 AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
946 * Soft hangup requested by non-associated party. Actual hangup
949 AST_SOFTHANGUP_EXPLICIT = (1 << 5),
951 * Used to break a bridge so the channel can be spied upon
952 * instead of actually hanging up.
954 AST_SOFTHANGUP_UNBRIDGE = (1 << 6),
958 * \brief All softhangup flags.
960 * This can be used as an argument to ast_channel_clear_softhangup()
961 * to clear all softhangup flags from a channel.
963 AST_SOFTHANGUP_ALL = (0xFFFFFFFF)
967 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
968 enum channelreloadreason {
970 CHANNEL_MODULE_RELOAD,
972 CHANNEL_MANAGER_RELOAD,
976 * \note None of the datastore API calls lock the ast_channel they are using.
977 * So, the channel should be locked before calling the functions that
978 * take a channel argument.
982 * \brief Create a channel data store object
983 * \deprecated You should use the ast_datastore_alloc() generic function instead.
984 * \version 1.6.1 deprecated
986 struct ast_datastore * attribute_malloc ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
987 __attribute__((deprecated));
990 * \brief Free a channel data store object
991 * \deprecated You should use the ast_datastore_free() generic function instead.
992 * \version 1.6.1 deprecated
994 int ast_channel_datastore_free(struct ast_datastore *datastore)
995 __attribute__((deprecated));
997 /*! \brief Inherit datastores from a parent to a child. */
998 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
1001 * \brief Add a datastore to a channel
1003 * \note The channel should be locked before calling this function.
1006 * \retval non-zero failure
1008 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
1011 * \brief Remove a datastore from a channel
1013 * \note The channel should be locked before calling this function.
1016 * \retval non-zero failure
1018 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
1021 * \brief Find a datastore on a channel
1023 * \note The channel should be locked before calling this function.
1025 * \note The datastore returned from this function must not be used if the
1026 * reference to the channel is released.
1028 * \retval pointer to the datastore if found
1029 * \retval NULL if not found
1031 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
1034 * \brief Create a channel structure
1037 * \retval NULL failure
1038 * \retval non-NULL successfully allocated channel
1040 * \note Absolutely _NO_ channel locks should be held before calling this function.
1041 * \note By default, new channels are set to the "s" extension
1042 * and "default" context.
1044 struct ast_channel * attribute_malloc __attribute__((format(printf, 13, 14)))
1045 __ast_channel_alloc(int needqueue, int state, const char *cid_num,
1046 const char *cid_name, const char *acctcode,
1047 const char *exten, const char *context,
1048 const char *linkedid, const int amaflag,
1049 const char *file, int line, const char *function,
1050 const char *name_fmt, ...);
1053 * \brief Create a channel structure
1055 * \retval NULL failure
1056 * \retval non-NULL successfully allocated channel
1058 * \note Absolutely _NO_ channel locks should be held before calling this function.
1059 * \note By default, new channels are set to the "s" extension
1060 * and "default" context.
1062 #define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, ...) \
1063 __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, \
1064 __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
1066 #if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
1068 * \brief Create a fake channel structure
1070 * \retval NULL failure
1071 * \retval non-NULL successfully allocated channel
1073 * \note This function should ONLY be used to create a fake channel
1074 * that can then be populated with data for use in variable
1075 * substitution when a real channel does not exist.
1077 * \note The created dummy channel should be destroyed by
1078 * ast_channel_unref(). Using ast_channel_release() needlessly
1079 * grabs the channel container lock and can cause a deadlock as
1080 * a result. Also grabbing the channel container lock reduces
1081 * system performance.
1083 #define ast_dummy_channel_alloc() __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
1084 struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);
1087 * \brief Create a fake channel structure
1089 * \retval NULL failure
1090 * \retval non-NULL successfully allocated channel
1092 * \note This function should ONLY be used to create a fake channel
1093 * that can then be populated with data for use in variable
1094 * substitution when a real channel does not exist.
1096 * \note The created dummy channel should be destroyed by
1097 * ast_channel_unref(). Using ast_channel_release() needlessly
1098 * grabs the channel container lock and can cause a deadlock as
1099 * a result. Also grabbing the channel container lock reduces
1100 * system performance.
1102 struct ast_channel *ast_dummy_channel_alloc(void);
1106 * \brief Queue one or more frames to a channel's frame queue
1108 * \param chan the channel to queue the frame(s) on
1109 * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
1110 * by this function. It is the responsibility of the caller to handle
1111 * freeing the memory associated with the frame(s) being passed if
1115 * \retval non-zero failure
1117 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
1120 * \brief Queue one or more frames to the head of a channel's frame queue
1122 * \param chan the channel to queue the frame(s) on
1123 * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
1124 * by this function. It is the responsibility of the caller to handle
1125 * freeing the memory associated with the frame(s) being passed if
1129 * \retval non-zero failure
1131 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
1134 * \brief Queue a hangup frame
1136 * \note The channel does not need to be locked before calling this function.
1138 int ast_queue_hangup(struct ast_channel *chan);
1141 * \brief Queue a hangup frame with hangupcause set
1143 * \note The channel does not need to be locked before calling this function.
1144 * \param[in] chan channel to queue frame onto
1145 * \param[in] cause the hangup cause
1146 * \return 0 on success, -1 on error
1149 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
1152 * \brief Queue a control frame with payload
1154 * \param chan channel to queue frame onto
1155 * \param control type of control frame
1157 * \note The channel does not need to be locked before calling this function.
1159 * \retval zero on success
1160 * \retval non-zero on failure
1162 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
1165 * \brief Queue a control frame with payload
1167 * \param chan channel to queue frame onto
1168 * \param control type of control frame
1169 * \param data pointer to payload data to be included in frame
1170 * \param datalen number of bytes of payload data
1173 * \retval non-zero failure
1176 * The supplied payload data is copied into the frame, so the caller's copy
1177 * is not modified nor freed, and the resulting frame will retain a copy of
1178 * the data even if the caller frees their local copy.
1180 * \note This method should be treated as a 'network transport'; in other
1181 * words, your frames may be transferred across an IAX2 channel to another
1182 * system, which may be a different endianness than yours. Because of this,
1183 * you should ensure that either your frames will never be expected to work
1184 * across systems, or that you always put your payload data into 'network byte
1185 * order' before calling this function.
1187 * \note The channel does not need to be locked before calling this function.
1189 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
1190 const void *data, size_t datalen);
1193 * \brief Change channel name
1195 * \pre Absolutely all channels _MUST_ be unlocked before calling this function.
1197 * \param chan the channel to change the name of
1198 * \param newname the name to change to
1202 * \note this function must _NEVER_ be used when any channels are locked
1203 * regardless if it is the channel who's name is being changed or not because
1204 * it invalidates our channel container locking order... lock container first,
1205 * then the individual channels, never the other way around.
1207 void ast_change_name(struct ast_channel *chan, const char *newname);
1210 * \brief Unlink and release reference to a channel
1212 * This function will unlink the channel from the global channels container
1213 * if it is still there and also release the current reference to the channel.
1215 * \return NULL, convenient for clearing invalid pointers
1216 * \note Absolutely _NO_ channel locks should be held before calling this function.
1220 struct ast_channel *ast_channel_release(struct ast_channel *chan);
1223 * \brief Requests a channel
1225 * \param type type of channel to request
1226 * \param request_cap Format capabilities for requested channel
1227 * \param requestor channel asking for data
1228 * \param addr destination of the call
1229 * \param cause Cause of failure
1232 * Request a channel of a given type, with addr as optional information used
1233 * by the low level module
1235 * \retval NULL failure
1236 * \retval non-NULL channel on success
1238 struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_channel *requestor, const char *addr, int *cause);
1241 * \brief Request a channel of a given type, with data as optional information used
1242 * by the low level module and attempt to place a call on it
1244 * \param type type of channel to request
1245 * \param format capabilities for requested channel
1246 * \param requestor channel asking for data
1247 * \param addr destination of the call
1248 * \param timeout maximum amount of time to wait for an answer
1249 * \param reason why unsuccessful (if unsuccessful)
1250 * \param cid_num Caller-ID Number
1251 * \param cid_name Caller-ID Name (ascii)
1253 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
1254 * to know if the call was answered or not.
1256 struct ast_channel *ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr,
1257 int timeout, int *reason, const char *cid_num, const char *cid_name);
1260 * \brief Request a channel of a given type, with data as optional information used
1261 * by the low level module and attempt to place a call on it
1262 * \param type type of channel to request
1263 * \param format capabilities for requested channel
1264 * \param requestor channel requesting data
1265 * \param addr destination of the call
1266 * \param timeout maximum amount of time to wait for an answer
1267 * \param reason why unsuccessful (if unsuccessful)
1268 * \param cid_num Caller-ID Number
1269 * \param cid_name Caller-ID Name (ascii)
1270 * \param oh Outgoing helper
1271 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
1272 * to know if the call was answered or not.
1274 struct ast_channel *__ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr,
1275 int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
1278 * \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.
1279 * \param caller in channel that requested orig
1280 * \param orig channel being replaced by the call forward channel
1281 * \param timeout maximum amount of time to wait for setup of new forward channel
1282 * \param format capabilities for requested channel
1283 * \param oh outgoing helper used with original channel
1284 * \param outstate reason why unsuccessful (if uncuccessful)
1285 * \return Returns the forwarded call's ast_channel on success or NULL on failure
1287 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);
1290 * \brief Register a channel technology (a new channel driver)
1291 * Called by a channel module to register the kind of channels it supports.
1292 * \param tech Structure defining channel technology or "type"
1293 * \return Returns 0 on success, -1 on failure.
1295 int ast_channel_register(const struct ast_channel_tech *tech);
1298 * \brief Unregister a channel technology
1299 * \param tech Structure defining channel technology or "type" that was previously registered
1300 * \return No return value.
1302 void ast_channel_unregister(const struct ast_channel_tech *tech);
1305 * \brief Get a channel technology structure by name
1306 * \param name name of technology to find
1307 * \return a pointer to the structure, or NULL if no matching technology found
1309 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
1311 #ifdef CHANNEL_TRACE
1313 * \brief Update the context backtrace if tracing is enabled
1314 * \return Returns 0 on success, -1 on failure
1316 int ast_channel_trace_update(struct ast_channel *chan);
1319 * \brief Enable context tracing in the channel
1320 * \return Returns 0 on success, -1 on failure
1322 int ast_channel_trace_enable(struct ast_channel *chan);
1325 * \brief Disable context tracing in the channel.
1326 * \note Does not remove current trace entries
1327 * \return Returns 0 on success, -1 on failure
1329 int ast_channel_trace_disable(struct ast_channel *chan);
1332 * \brief Whether or not context tracing is enabled
1333 * \return Returns -1 when the trace is enabled. 0 if not.
1335 int ast_channel_trace_is_enabled(struct ast_channel *chan);
1338 * \brief Put the channel backtrace in a string
1339 * \return Returns the amount of lines in the backtrace. -1 on error.
1341 int ast_channel_trace_serialize(struct ast_channel *chan, struct ast_str **out);
1345 * \brief Hang up a channel
1346 * \note Absolutely _NO_ channel locks should be held before calling this function.
1347 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
1348 * performs all stream stopping, etc, on the channel that needs to end.
1349 * chan is no longer valid after this call.
1350 * \param chan channel to hang up
1351 * \return Returns 0 on success, -1 on failure.
1353 int ast_hangup(struct ast_channel *chan);
1356 * \brief Softly hangup up a channel
1358 * \param chan channel to be soft-hung-up
1359 * \param reason an AST_SOFTHANGUP_* reason code
1362 * Call the protocol layer, but don't destroy the channel structure
1363 * (use this if you are trying to
1364 * safely hangup a channel managed by another thread.
1366 * \note The channel passed to this function does not need to be locked.
1368 * \return Returns 0 regardless
1370 int ast_softhangup(struct ast_channel *chan, int reason);
1373 * \brief Softly hangup up a channel (no channel lock)
1374 * \param chan channel to be soft-hung-up
1375 * \param reason an AST_SOFTHANGUP_* reason code
1377 int ast_softhangup_nolock(struct ast_channel *chan, int reason);
1380 * \brief Clear a set of softhangup flags from a channel
1382 * Never clear a softhangup flag from a channel directly. Instead,
1383 * use this function. This ensures that all aspects of the softhangup
1384 * process are aborted.
1386 * \param chan the channel to clear the flag on
1387 * \param flag the flag or flags to clear
1391 void ast_channel_clear_softhangup(struct ast_channel *chan, int flag);
1394 * \brief Set the source of the hangup in this channel and it's bridge
1396 * \param chan channel to set the field on
1397 * \param source a string describing the source of the hangup for this channel
1400 * \note Absolutely _NO_ channel locks should be held before calling this function.
1404 * Hangupsource is generally the channel name that caused the bridge to be
1405 * hung up, but it can also be other things such as "dialplan/agi"
1406 * This can then be logged in the CDR or CEL
1408 void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);
1410 /*! \brief Check to see if a channel is needing hang up
1411 * \param chan channel on which to check for hang up
1412 * This function determines if the channel is being requested to be hung up.
1413 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
1415 int ast_check_hangup(struct ast_channel *chan);
1417 int ast_check_hangup_locked(struct ast_channel *chan);
1420 * \brief Lock the given channel, then request softhangup on the channel with the given causecode
1421 * \param chan channel on which to hang up
1422 * \param causecode cause code to use (Zero if don't use cause code)
1425 void ast_channel_softhangup_withcause_locked(struct ast_channel *chan, int causecode);
1428 * \brief Compare a offset with the settings of when to hang a channel up
1429 * \param chan channel on which to check for hang up
1430 * \param offset offset in seconds from current time
1431 * \return 1, 0, or -1
1433 * This function compares a offset from current time with the absolute time
1434 * out on a channel (when to hang up). If the absolute time out on a channel
1435 * is earlier than current time plus the offset, it returns 1, if the two
1436 * time values are equal, it return 0, otherwise, it return -1.
1437 * \sa ast_channel_cmpwhentohangup_tv()
1438 * \version 1.6.1 deprecated function (only had seconds precision)
1440 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1443 * \brief Compare a offset with the settings of when to hang a channel up
1444 * \param chan channel on which to check for hangup
1445 * \param offset offset in seconds and microseconds from current time
1446 * \return 1, 0, or -1
1447 * This function compares a offset from current time with the absolute time
1448 * out on a channel (when to hang up). If the absolute time out on a channel
1449 * is earlier than current time plus the offset, it returns 1, if the two
1450 * time values are equal, it return 0, otherwise, it return -1.
1453 int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1456 * \brief Set when to hang a channel up
1458 * \param chan channel on which to check for hang up
1459 * \param offset offset in seconds relative to the current time of when to hang up
1462 * This function sets the absolute time out on a channel (when to hang up).
1464 * \note This function does not require that the channel is locked before
1468 * \sa ast_channel_setwhentohangup_tv()
1469 * \version 1.6.1 deprecated function (only had seconds precision)
1471 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1474 * \brief Set when to hang a channel up
1476 * \param chan channel on which to check for hang up
1477 * \param offset offset in seconds and useconds relative to the current time of when to hang up
1479 * This function sets the absolute time out on a channel (when to hang up).
1481 * \note This function does not require that the channel is locked before
1487 void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1490 * \brief Answer a channel
1492 * \param chan channel to answer
1495 * This function answers a channel and handles all necessary call
1498 * \note The channel passed does not need to be locked, but is locked
1499 * by the function when needed.
1501 * \note This function will wait up to 500 milliseconds for media to
1502 * arrive on the channel before returning to the caller, so that the
1503 * caller can properly assume the channel is 'ready' for media flow.
1505 * \retval 0 on success
1506 * \retval non-zero on failure
1508 int ast_answer(struct ast_channel *chan);
1511 * \brief Answer a channel
1513 * \param chan channel to answer
1514 * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
1516 * This function answers a channel and handles all necessary call
1519 * \note The channel passed does not need to be locked, but is locked
1520 * by the function when needed.
1522 * \note Unlike ast_answer(), this function will not wait for media
1523 * flow to begin. The caller should be careful before sending media
1524 * to the channel before incoming media arrives, as the outgoing
1525 * media may be lost.
1527 * \retval 0 on success
1528 * \retval non-zero on failure
1530 int ast_raw_answer(struct ast_channel *chan, int cdr_answer);
1533 * \brief Answer a channel, with a selectable delay before returning
1535 * \param chan channel to answer
1536 * \param delay maximum amount of time to wait for incoming media
1537 * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
1539 * This function answers a channel and handles all necessary call
1542 * \note The channel passed does not need to be locked, but is locked
1543 * by the function when needed.
1545 * \note This function will wait up to 'delay' milliseconds for media to
1546 * arrive on the channel before returning to the caller, so that the
1547 * caller can properly assume the channel is 'ready' for media flow. If
1548 * 'delay' is less than 500, the function will wait up to 500 milliseconds.
1550 * \retval 0 on success
1551 * \retval non-zero on failure
1553 int __ast_answer(struct ast_channel *chan, unsigned int delay, int cdr_answer);
1556 * \brief Execute a Gosub call on the channel before a call is placed.
1560 * This is called between ast_request() and ast_call() to
1561 * execute a predial routine on the newly created channel.
1563 * \param chan Channel to execute Gosub.
1564 * \param sub_args Gosub application parameter string.
1566 * \note Absolutely _NO_ channel locks should be held before calling this function.
1568 * \retval 0 on success.
1569 * \retval -1 on error.
1571 int ast_pre_call(struct ast_channel *chan, const char *sub_args);
1574 * \brief Make a call
1575 * \note Absolutely _NO_ channel locks should be held before calling this function.
1576 * \param chan which channel to make the call on
1577 * \param addr destination of the call
1578 * \param timeout time to wait on for connect (Doesn't seem to be used.)
1580 * Place a call, take no longer than timeout ms.
1581 * \retval 0 on success
1582 * \retval -1 on failure
1584 int ast_call(struct ast_channel *chan, const char *addr, int timeout);
1587 * \brief Indicates condition of channel
1588 * \note Absolutely _NO_ channel locks should be held before calling this function.
1589 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
1590 * \param chan channel to change the indication
1591 * \param condition which condition to indicate on the channel
1592 * \return Returns 0 on success, -1 on failure
1594 int ast_indicate(struct ast_channel *chan, int condition);
1597 * \brief Indicates condition of channel, with payload
1598 * \note Absolutely _NO_ channel locks should be held before calling this function.
1599 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
1600 * \param chan channel to change the indication
1601 * \param condition which condition to indicate on the channel
1602 * \param data pointer to payload data
1603 * \param datalen size of payload data
1604 * \return Returns 0 on success, -1 on failure
1606 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1608 /* Misc stuff ------------------------------------------------ */
1611 * \brief Wait for input on a channel
1612 * \param chan channel to wait on
1613 * \param ms length of time to wait on the channel
1615 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
1616 * \retval < 0 on failure
1617 * \retval 0 if nothing ever arrived
1618 * \retval the # of ms remaining otherwise
1620 int ast_waitfor(struct ast_channel *chan, int ms);
1623 * \brief Should we keep this frame for later?
1625 * There are functions such as ast_safe_sleep which will
1626 * service a channel to ensure that it does not have a
1627 * large backlog of queued frames. When this happens,
1628 * we want to hold on to specific frame types and just drop
1629 * others. This function will tell if the frame we just
1630 * read should be held onto.
1632 * \param frame The frame we just read
1633 * \retval 1 frame should be kept
1634 * \retval 0 frame should be dropped
1636 int ast_is_deferrable_frame(const struct ast_frame *frame);
1639 * \brief Wait for a specified amount of time, looking for hangups
1640 * \param chan channel to wait for
1641 * \param ms length of time in milliseconds to sleep
1643 * Waits for a specified amount of time, servicing the channel as required.
1644 * \return returns -1 on hangup, otherwise 0.
1646 int ast_safe_sleep(struct ast_channel *chan, int ms);
1649 * \brief Wait for a specified amount of time, looking for hangups and a condition argument
1650 * \param chan channel to wait for
1651 * \param ms length of time in milliseconds to sleep
1652 * \param cond a function pointer for testing continue condition
1653 * \param data argument to be passed to the condition test function
1654 * \return returns -1 on hangup, otherwise 0.
1656 * Waits for a specified amount of time, servicing the channel as required. If cond
1657 * returns 0, this function returns.
1659 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
1662 * \brief Waits for activity on a group of channels
1663 * \param chan an array of pointers to channels
1664 * \param n number of channels that are to be waited upon
1665 * \param fds an array of fds to wait upon
1666 * \param nfds the number of fds to wait upon
1667 * \param exception exception flag
1668 * \param outfd fd that had activity on it
1669 * \param ms how long the wait was
1671 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
1673 * \return Returns the channel with activity, or NULL on error or if an FD
1674 * came first. If the FD came first, it will be returned in outfd, otherwise, outfd
1677 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
1678 int *fds, int nfds, int *exception, int *outfd, int *ms);
1681 * \brief Waits for input on a group of channels
1682 * Wait for input on an array of channels for a given # of milliseconds.
1683 * \return Return channel with activity, or NULL if none has activity.
1684 * \param chan an array of pointers to channels
1685 * \param n number of channels that are to be waited upon
1686 * \param ms time "ms" is modified in-place, if applicable
1688 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
1691 * \brief Waits for input on an fd
1692 * \note This version works on fd's only. Be careful with it.
1694 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
1698 * \brief Reads a frame
1699 * \param chan channel to read a frame from
1700 * \return Returns a frame, or NULL on error. If it returns NULL, you
1701 * best just stop reading frames and assume the channel has been
1704 struct ast_frame *ast_read(struct ast_channel *chan);
1707 * \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
1708 * \param chan channel to read a frame from
1709 * \return Returns a frame, or NULL on error. If it returns NULL, you
1710 * best just stop reading frames and assume the channel has been
1712 * \note Audio is replaced with AST_FRAME_NULL to avoid
1713 * transcode when the resulting audio is not necessary.
1715 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
1718 * \brief Write a frame to a channel
1719 * This function writes the given frame to the indicated channel.
1720 * \param chan destination channel of the frame
1721 * \param frame frame that will be written
1722 * \return It returns 0 on success, -1 on failure.
1724 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
1727 * \brief Write video frame to a channel
1728 * This function writes the given frame to the indicated channel.
1729 * \param chan destination channel of the frame
1730 * \param frame frame that will be written
1731 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1733 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
1736 * \brief Write text frame to a channel
1737 * This function writes the given frame to the indicated channel.
1738 * \param chan destination channel of the frame
1739 * \param frame frame that will be written
1740 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1742 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
1744 /*! \brief Send empty audio to prime a channel driver */
1745 int ast_prod(struct ast_channel *chan);
1748 * \brief Sets read format on channel chan from capabilities
1749 * Set read format for channel to whichever component of "format" is best.
1750 * \param chan channel to change
1751 * \param formats new formats to pick from for reading
1752 * \return Returns 0 on success, -1 on failure
1754 int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
1757 * \brief Sets read format on channel chan
1758 * \param chan channel to change
1759 * \param formats, format to set for reading
1760 * \return Returns 0 on success, -1 on failure
1762 int ast_set_read_format(struct ast_channel *chan, struct ast_format *format);
1765 * \brief Sets read format on channel chan by id
1766 * \param chan channel to change
1767 * \param format id to set for reading, only used for formats without attributes
1768 * \return Returns 0 on success, -1 on failure
1770 int ast_set_read_format_by_id(struct ast_channel *chan, enum ast_format_id id);
1773 * \brief Sets write format on channel chan
1774 * Set write format for channel to whichever component of "format" is best.
1775 * \param chan channel to change
1776 * \param formats new formats to pick from for writing
1777 * \return Returns 0 on success, -1 on failure
1779 int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
1782 * \brief Sets write format on channel chan
1783 * \param chan channel to change
1784 * \param formats, format to set for writing
1785 * \return Returns 0 on success, -1 on failure
1787 int ast_set_write_format(struct ast_channel *chan, struct ast_format *format);
1790 * \brief Sets write format on channel chan
1791 * \param chan channel to change
1792 * \param format id to set for writing, only used for formats without attributes
1793 * \return Returns 0 on success, -1 on failure
1795 int ast_set_write_format_by_id(struct ast_channel *chan, enum ast_format_id id);
1798 * \brief Sends text to a channel
1800 * \param chan channel to act upon
1801 * \param text string of text to send on the channel
1804 * Write text to a display on a channel
1806 * \note The channel does not need to be locked before calling this function.
1808 * \retval 0 on success
1809 * \retval -1 on failure
1811 int ast_sendtext(struct ast_channel *chan, const char *text);
1814 * \brief Receives a text character from a channel
1815 * \param chan channel to act upon
1816 * \param timeout timeout in milliseconds (0 for infinite wait)
1818 * Read a char of text from a channel
1819 * \return 0 on success, -1 on failure
1821 int ast_recvchar(struct ast_channel *chan, int timeout);
1824 * \brief Send a DTMF digit to a channel.
1825 * \param chan channel to act upon
1826 * \param digit the DTMF digit to send, encoded in ASCII
1827 * \param duration the duration of the digit ending in ms
1828 * \return 0 on success, -1 on failure
1830 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
1833 * \brief Send a DTMF digit to a channel.
1834 * \param chan channel to act upon
1835 * \param digit the DTMF digit to send, encoded in ASCII
1836 * \return 0 on success, -1 on failure
1838 int ast_senddigit_begin(struct ast_channel *chan, char digit);
1841 * \brief Send a DTMF digit to a channel.
1842 * \param chan channel to act upon
1843 * \param digit the DTMF digit to send, encoded in ASCII
1844 * \param duration the duration of the digit ending in ms
1845 * \return Returns 0 on success, -1 on failure
1847 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
1850 * \brief Receives a text string from a channel
1851 * Read a string of text from a channel
1852 * \param chan channel to act upon
1853 * \param timeout timeout in milliseconds (0 for infinite wait)
1854 * \return the received text, or NULL to signify failure.
1856 char *ast_recvtext(struct ast_channel *chan, int timeout);
1859 * \brief Waits for a digit
1860 * \param c channel to wait for a digit on
1861 * \param ms how many milliseconds to wait
1862 * \return Returns <0 on error, 0 on no entry, and the digit on success.
1864 int ast_waitfordigit(struct ast_channel *c, int ms);
1867 * \brief Wait for a digit
1868 * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1869 * \param c channel to wait for a digit on
1870 * \param ms how many milliseconds to wait
1871 * \param audiofd audio file descriptor to write to if audio frames are received
1872 * \param ctrlfd control file descriptor to monitor for reading
1873 * \return Returns 1 if ctrlfd becomes available
1875 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
1878 * \brief Reads multiple digits
1879 * \param c channel to read from
1880 * \param s string to read in to. Must be at least the size of your length
1881 * \param len how many digits to read (maximum)
1882 * \param timeout how long to timeout between digits
1883 * \param rtimeout timeout to wait on the first digit
1884 * \param enders digits to end the string
1886 * Read in a digit string "s", max length "len", maximum timeout between
1887 * digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
1888 * for the first digit.
1889 * \return Returns 0 on normal return, or 1 on a timeout. In the case of
1890 * a timeout, any digits that were read before the timeout will still be available in s.
1891 * RETURNS 2 in full version when ctrlfd is available, NOT 1
1893 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
1894 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
1896 /*! \brief Report DTMF on channel 0 */
1897 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
1898 /*! \brief Report DTMF on channel 1 */
1899 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
1900 /*! \brief Return all voice frames on channel 0 */
1901 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
1902 /*! \brief Return all voice frames on channel 1 */
1903 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
1904 /*! \brief Ignore all signal frames except NULL */
1905 #define AST_BRIDGE_IGNORE_SIGS (1 << 4)
1909 * \brief Makes two channel formats compatible
1910 * \param c0 first channel to make compatible
1911 * \param c1 other channel to make compatible
1913 * Set two channels to compatible formats -- call before ast_channel_bridge in general.
1914 * \return Returns 0 on success and -1 if it could not be done
1916 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
1919 * \brief Bridge two channels together (early)
1920 * \param c0 first channel to bridge
1921 * \param c1 second channel to bridge
1923 * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
1924 * \return Returns 0 on success and -1 if it could not be done
1926 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
1929 * \brief Bridge two channels together
1930 * \param c0 first channel to bridge
1931 * \param c1 second channel to bridge
1932 * \param config config for the channels
1933 * \param fo destination frame(?)
1934 * \param rc destination channel(?)
1936 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
1937 * *rf (remember, it could be NULL) and which channel (0 or 1) in rc
1939 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
1940 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
1941 struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
1944 * \brief Weird function made for call transfers
1946 * \param original channel to make a copy of
1947 * \param clone copy of the original channel
1950 * This is a very strange and freaky function used primarily for transfer. Suppose that
1951 * "original" and "clone" are two channels in random situations. This function takes
1952 * the guts out of "clone" and puts them into the "original" channel, then alerts the
1953 * channel driver of the change, asking it to fixup any private information (like the
1954 * p->owner pointer) that is affected by the change. The physical layer of the original
1955 * channel is hung up.
1957 * \note Neither channel passed here should be locked before
1958 * calling this function. This function performs deadlock
1959 * avoidance involving these two channels.
1961 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
1964 * \brief Setup a masquerade to transfer a call.
1967 * \param target_chan Target of the call transfer. (Masquerade original channel)
1968 * \param target_id New connected line information for the target channel.
1969 * \param target_held TRUE if the target call is on hold.
1970 * \param transferee_chan Transferee of the call transfer. (Masquerade clone channel)
1971 * \param transferee_id New connected line information for the transferee channel.
1972 * \param transferee_held TRUE if the transferee call is on hold.
1975 * Party A - Transferee
1976 * Party B - Transferer
1977 * Party C - Target of transfer
1979 * Party B transfers A to C.
1981 * Party A is connected to bridged channel B1.
1982 * Party B is connected to channels C1 and C2.
1983 * Party C is connected to bridged channel B2.
1985 * Party B -- C1 == B1 -- Party A
1988 * Party B -- C2 == B2 -- Party C
1990 * Bridged channel B1 is masqueraded into channel C2. Where B1
1991 * is the masquerade clone channel and C2 is the masquerade
1994 * \see ast_channel_masquerade()
1996 * \note Has the same locking requirements as ast_channel_masquerade().
1998 * \retval 0 on success.
1999 * \retval -1 on error.
2001 int ast_channel_transfer_masquerade(
2002 struct ast_channel *target_chan,
2003 const struct ast_party_connected_line *target_id,
2005 struct ast_channel *transferee_chan,
2006 const struct ast_party_connected_line *transferee_id,
2007 int transferee_held);
2010 * \brief Gives the string form of a given cause code.
2012 * \param state cause to get the description of
2013 * \return the text form of the binary cause code given
2015 const char *ast_cause2str(int state) attribute_pure;
2018 * \brief Convert the string form of a cause code to a number
2020 * \param name string form of the cause
2021 * \return the cause code
2023 int ast_str2cause(const char *name) attribute_pure;
2026 * \brief Gives the string form of a given channel state
2028 * \param ast_channel_state state to get the name of
2029 * \return the text form of the binary state given
2031 const char *ast_state2str(enum ast_channel_state);
2034 * \brief Gives the string form of a given transfer capability
2036 * \param transfercapability transfer capability to get the name of
2037 * \return the text form of the binary transfer capability
2039 char *ast_transfercapability2str(int transfercapability) attribute_const;
2042 * Options: Some low-level drivers may implement "options" allowing fine tuning of the
2043 * low level channel. See frame.h for options. Note that many channel drivers may support
2044 * none or a subset of those features, and you should not count on this if you want your
2045 * asterisk application to be portable. They're mainly useful for tweaking performance
2049 * \brief Sets an option on a channel
2051 * \param channel channel to set options on
2052 * \param option option to change
2053 * \param data data specific to option
2054 * \param datalen length of the data
2055 * \param block blocking or not
2057 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
2058 * \return 0 on success and -1 on failure
2060 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
2063 * \brief Pick the best codec
2065 * \param capabilities to pick best codec out of
2066 * \param result stucture to store the best codec in.
2067 * \retval on success, pointer to result structure
2068 * \retval on failure, NULL
2070 struct ast_format *ast_best_codec(struct ast_format_cap *cap, struct ast_format *result);
2074 * \brief Checks the value of an option
2076 * Query the value of an option
2077 * Works similarly to setoption except only reads the options.
2079 int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
2082 * \brief Checks for HTML support on a channel
2083 * \return 0 if channel does not support HTML or non-zero if it does
2085 int ast_channel_supports_html(struct ast_channel *channel);
2088 * \brief Sends HTML on given channel
2089 * Send HTML or URL on link.
2090 * \return 0 on success or -1 on failure
2092 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
2095 * \brief Sends a URL on a given link
2097 * \return 0 on success or -1 on failure
2099 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
2102 * \brief Defers DTMF so that you only read things like hangups and audio.
2103 * \return non-zero if channel was already DTMF-deferred or
2104 * 0 if channel is just now being DTMF-deferred
2106 int ast_channel_defer_dtmf(struct ast_channel *chan);
2108 /*! Undo defer. ast_read will return any DTMF characters that were queued */
2109 void ast_channel_undefer_dtmf(struct ast_channel *chan);
2111 /*! Initiate system shutdown -- prevents new channels from being allocated.
2112 * \param hangup If "hangup" is non-zero, all existing channels will receive soft
2114 void ast_begin_shutdown(int hangup);
2116 /*! Cancels an existing shutdown and returns to normal operation */
2117 void ast_cancel_shutdown(void);
2119 /*! \return number of channels available for lookup */
2120 int ast_active_channels(void);
2122 /*! \return the number of channels not yet destroyed */
2123 int ast_undestroyed_channels(void);
2125 /*! \return non-zero if Asterisk is being shut down */
2126 int ast_shutting_down(void);
2128 /*! Activate a given generator */
2129 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
2131 /*! Deactivate an active generator */
2132 void ast_deactivate_generator(struct ast_channel *chan);
2135 * \brief Set caller ID number, name and ANI and generate AMI event.
2137 * \note Use ast_channel_set_caller() and ast_channel_set_caller_event() instead.
2138 * \note The channel does not need to be locked before calling this function.
2140 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
2143 * \brief Set the caller id information in the Asterisk channel
2146 * \param chan Asterisk channel to set caller id information
2147 * \param caller Caller id information
2148 * \param update What caller information to update. NULL if all.
2152 * \note The channel does not need to be locked before calling this function.
2154 void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
2157 * \brief Set the caller id information in the Asterisk channel and generate an AMI event
2158 * if the caller id name or number changed.
2161 * \param chan Asterisk channel to set caller id information
2162 * \param caller Caller id information
2163 * \param update What caller information to update. NULL if all.
2167 * \note The channel does not need to be locked before calling this function.
2169 void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
2171 /*! Set the file descriptor on the channel */
2172 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
2174 /*! Add a channel to an optimized waitfor */
2175 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
2177 /*! Delete a channel from an optimized waitfor */
2178 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
2180 /*! Start a tone going */
2181 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
2182 /*! Stop a tone from playing */
2183 void ast_tonepair_stop(struct ast_channel *chan);
2184 /*! Play a tone pair for a given amount of time */
2185 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
2188 * \brief Automatically service a channel for us...
2191 * \retval -1 failure, or the channel is already being autoserviced
2193 int ast_autoservice_start(struct ast_channel *chan);
2196 * \brief Stop servicing a channel for us...
2198 * \note if chan is locked prior to calling ast_autoservice_stop, it
2199 * is likely that there will be a deadlock between the thread that calls
2200 * ast_autoservice_stop and the autoservice thread. It is important
2201 * that chan is not locked prior to this call
2205 * \retval -1 error, or the channel has been hungup
2207 int ast_autoservice_stop(struct ast_channel *chan);
2210 * \brief Put chan into autoservice while hanging up peer.
2213 * \param chan Chan to put into autoservice.
2214 * \param peer Chan to run hangup handlers and hangup.
2218 void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer);
2221 * \brief Ignore certain frame types
2222 * \note Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames
2223 * while a channel is in autoservice and queue them up when taken out of
2224 * autoservice. When this is not desireable, this API may be used to
2225 * cause the channel to ignore those frametypes after the channel is put
2226 * into autoservice, but before autoservice is stopped.
2228 * \retval -1 channel is not in autoservice
2230 int ast_autoservice_ignore(struct ast_channel *chan, enum ast_frame_type ftype);
2233 * \brief Enable or disable timer ticks for a channel
2236 * \param rate number of timer ticks per second
2237 * \param func callback function
2241 * If timers are supported, force a scheduled expiration on the
2242 * timer fd, at which point we call the callback function / data
2244 * \note Call this function with a rate of 0 to turn off the timer ticks
2246 * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
2248 int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
2251 * \brief Transfer a channel (if supported).
2252 * \retval -1 on error
2253 * \retval 0 if not supported
2254 * \retval 1 if supported and requested
2255 * \param chan current channel
2256 * \param dest destination extension for transfer
2258 int ast_transfer(struct ast_channel *chan, char *dest);
2261 * \brief Start masquerading a channel
2262 * \note absolutely _NO_ channel locks should be held before calling this function.
2264 * XXX This is a seriously whacked out operation. We're essentially putting the guts of
2265 * the clone channel into the original channel. Start by killing off the original
2266 * channel's backend. I'm not sure we're going to keep this function, because
2267 * while the features are nice, the cost is very high in terms of pure nastiness. XXX
2268 * \param chan Channel to masquerade
2270 int ast_do_masquerade(struct ast_channel *chan);
2273 * \brief Find bridged channel
2275 * \note This function does _not_ return a reference to the bridged channel.
2276 * The reason for this is mostly historical. It _should_ return a reference,
2277 * but it will take a lot of work to make the code base account for that.
2278 * So, for now, the old rules still apply for how to handle this function.
2279 * If this function is being used from the channel thread that owns the channel,
2280 * then a reference is already held, and channel locking is not required to
2281 * guarantee that the channel will stay around. If this function is used
2282 * outside of the associated channel thread, the channel parameter 'chan'
2283 * MUST be locked before calling this function. Also, 'chan' must remain locked
2284 * for the entire time that the result of this function is being used.
2286 * \param chan Current channel
2288 * \return A pointer to the bridged channel
2290 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
2293 * \brief Inherits channel variable from parent to child channel
2294 * \param parent Parent channel
2295 * \param child Child channel
2298 * Scans all channel variables in the parent channel, looking for those
2299 * that should be copied into the child channel.
2300 * Variables whose names begin with a single '_' are copied into the
2301 * child channel with the prefix removed.
2302 * Variables whose names begin with '__' are copied into the child
2303 * channel with their names unchanged.
2305 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
2308 * \brief adds a list of channel variables to a channel
2309 * \param chan the channel
2310 * \param vars a linked list of variables
2313 * Variable names can be for a regular channel variable or a dialplan function
2314 * that has the ability to be written to.
2316 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
2319 * \brief An opaque 'object' structure use by silence generators on channels.
2321 struct ast_silence_generator;
2324 * \brief Starts a silence generator on the given channel.
2325 * \param chan The channel to generate silence on
2326 * \return An ast_silence_generator pointer, or NULL if an error occurs
2329 * This function will cause SLINEAR silence to be generated on the supplied
2330 * channel until it is disabled; if the channel cannot be put into SLINEAR
2331 * mode then the function will fail.
2334 * The pointer returned by this function must be preserved and passed to
2335 * ast_channel_stop_silence_generator when you wish to stop the silence
2338 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
2341 * \brief Stops a previously-started silence generator on the given channel.
2342 * \param chan The channel to operate on
2343 * \param state The ast_silence_generator pointer return by a previous call to
2344 * ast_channel_start_silence_generator.
2348 * This function will stop the operating silence generator and return the channel
2349 * to its previous write format.
2351 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
2354 * \brief Check if the channel can run in internal timing mode.
2355 * \param chan The channel to check
2359 * This function will return 1 if internal timing is enabled and the timing
2360 * device is available.
2362 int ast_internal_timing_enabled(struct ast_channel *chan);
2364 /* Misc. functions below */
2367 * \brief if fd is a valid descriptor, set *pfd with the descriptor
2368 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
2369 * return value to the index into the array)
2371 static inline int ast_add_fd(struct pollfd *pfd, int fd)
2374 pfd->events = POLLIN | POLLPRI;
2378 /*! \brief Helper function for migrating select to poll */
2379 static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
2388 for (x = *start; x < maximum; x++)
2389 if (pfds[x].fd == fd) {
2392 return pfds[x].revents;
2397 /*! \brief Retrieves the current T38 state of a channel */
2398 static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
2400 enum ast_t38_state state = T38_STATE_UNAVAILABLE;
2401 int datalen = sizeof(state);
2403 ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
2408 #define CHECK_BLOCKING(c) do { \
2409 if (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING)) {\
2410 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)); \
2412 ast_channel_blocker_set((c), pthread_self()); \
2413 ast_channel_blockproc_set((c), __PRETTY_FUNCTION__); \
2414 ast_set_flag(ast_channel_flags(c), AST_FLAG_BLOCKING); \
2417 ast_group_t ast_get_group(const char *s);
2419 /*! \brief print call- and pickup groups into buffer */
2420 char *ast_print_group(char *buf, int buflen, ast_group_t group);
2423 * \brief Convert enum channelreloadreason to text string for manager event
2424 * \param reason The reason for reload (manager, cli, start etc)
2426 const char *channelreloadreason2txt(enum channelreloadreason reason);
2428 /*! \brief return an ast_variable list of channeltypes */
2429 struct ast_variable *ast_channeltype_list(void);
2432 * \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
2433 * \param reason The integer argument, usually taken from AST_CONTROL_ macros
2434 * \return char pointer explaining the code
2436 const char *ast_channel_reason2str(int reason);
2438 /*! \brief channel group info */
2439 struct ast_group_info {
2440 struct ast_channel *chan;
2443 AST_LIST_ENTRY(ast_group_info) group_list;
2446 #define ast_channel_lock(chan) ao2_lock(chan)
2447 #define ast_channel_unlock(chan) ao2_unlock(chan)
2448 #define ast_channel_trylock(chan) ao2_trylock(chan)
2451 * \brief Lock two channels.
2453 #define ast_channel_lock_both(chan1, chan2) do { \
2454 ast_channel_lock(chan1); \
2455 while (ast_channel_trylock(chan2)) { \
2456 ast_channel_unlock(chan1); \
2458 ast_channel_lock(chan1); \
2463 * \brief Increase channel reference count
2465 * \param c the channel
2471 #define ast_channel_ref(c) ({ ao2_ref(c, +1); (c); })
2474 * \brief Decrease channel reference count
2476 * \param c the channel
2478 * \retval NULL always
2482 #define ast_channel_unref(c) ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })
2484 /*! Channel Iterating @{ */
2487 * \brief A channel iterator
2489 * This is an opaque type.
2491 struct ast_channel_iterator;
2494 * \brief Destroy a channel iterator
2496 * \param i the itereator to destroy
2499 * This function is used to destroy a channel iterator that was retrieved by
2500 * using one of the channel_iterator_xxx_new() functions.
2502 * \return NULL, for convenience to clear out the pointer to the iterator that
2503 * was just destroyed.
2507 struct ast_channel_iterator *ast_channel_iterator_destroy(struct ast_channel_iterator *i);
2510 * \brief Create a new channel iterator based on extension
2512 * \param exten The extension that channels must be in
2513 * \param context The context that channels must be in
2516 * After creating an iterator using this function, the ast_channel_iterator_next()
2517 * function can be used to iterate through all channels that are currently
2518 * in the specified context and extension.
2520 * \note You must call ast_channel_iterator_destroy() when done.
2522 * \retval NULL on failure
2523 * \retval a new channel iterator based on the specified parameters
2527 struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context);
2530 * \brief Create a new channel iterator based on name
2532 * \param name channel name or channel uniqueid to match
2533 * \param name_len number of characters in the channel name to match on. This
2534 * would be used to match based on name prefix. If matching on the full
2535 * channel name is desired, then this parameter should be 0.
2538 * After creating an iterator using this function, the ast_channel_iterator_next()
2539 * function can be used to iterate through all channels that exist that have
2540 * the specified name or name prefix.
2542 * \note You must call ast_channel_iterator_destroy() when done.
2544 * \retval NULL on failure
2545 * \retval a new channel iterator based on the specified parameters
2549 struct ast_channel_iterator *ast_channel_iterator_by_name_new(const char *name, size_t name_len);
2552 * \brief Create a new channel iterator
2555 * After creating an iterator using this function, the ast_channel_iterator_next()
2556 * function can be used to iterate through all channels that exist.
2558 * \note You must call ast_channel_iterator_destroy() when done.
2560 * \retval NULL on failure
2561 * \retval a new channel iterator
2565 struct ast_channel_iterator *ast_channel_iterator_all_new(void);
2568 * \brief Get the next channel for a channel iterator
2570 * \param i the channel iterator that was created using one of the
2571 * channel_iterator_xxx_new() functions.
2574 * This function should be used to iterate through all channels that match a
2575 * specified set of parameters that were provided when the iterator was created.
2577 * \retval the next channel that matches the parameters used when the iterator
2579 * \retval NULL, if no more channels match the iterator parameters.
2583 struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);
2585 /*! @} End channel iterator definitions. */
2588 * \brief Call a function with every active channel
2591 * This function executes a callback one time for each active channel on the
2592 * system. The channel is provided as an argument to the function.
2594 * \note Absolutely _NO_ channel locks should be held before calling this function.
2597 struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
2598 void *data, int ao2_flags);
2600 /*! @{ Channel search functions */
2603 * \brief Find a channel by name
2605 * \param name the name or uniqueid of the channel to search for
2608 * Find a channel that has the same name as the provided argument.
2610 * \retval a channel with the name specified by the argument
2611 * \retval NULL if no channel was found
2615 struct ast_channel *ast_channel_get_by_name(const char *name);
2618 * \brief Find a channel by a name prefix
2620 * \param name The channel name or uniqueid prefix to search for
2621 * \param name_len Only search for up to this many characters from the name
2624 * Find a channel that has the same name prefix as specified by the arguments.
2626 * \retval a channel with the name prefix specified by the arguments
2627 * \retval NULL if no channel was found
2631 struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);
2634 * \brief Find a channel by extension and context
2636 * \param exten the extension to search for
2637 * \param context the context to search for
2640 * Return a channel that is currently at the specified extension and context.
2642 * \retval a channel that is at the specified extension and context
2643 * \retval NULL if no channel was found
2647 struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);
2649 /*! @} End channel search functions. */
2652 \brief propagate the linked id between chan and peer
2654 void ast_channel_set_linkgroup(struct ast_channel *chan, struct ast_channel *peer);
2658 * \brief Initialize the given name structure.
2661 * \param init Name structure to initialize.
2665 void ast_party_name_init(struct ast_party_name *init);
2668 * \brief Copy the source party name information to the destination party name.
2671 * \param dest Destination party name
2672 * \param src Source party name
2676 void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src);
2679 * \brief Initialize the given party name structure using the given guide
2680 * for a set update operation.
2684 * The initialization is needed to allow a set operation to know if a
2685 * value needs to be updated. Simple integers need the guide's original
2686 * value in case the set operation is not trying to set a new value.
2687 * String values are simply set to NULL pointers if they are not going
2690 * \param init Party name structure to initialize.
2691 * \param guide Source party name to use as a guide in initializing.
2695 void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide);
2698 * \brief Set the source party name information into the destination party name.
2701 * \param dest The name one wishes to update
2702 * \param src The new name values to update the dest
2706 void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src);
2709 * \brief Destroy the party name contents
2712 * \param doomed The party name to destroy.
2716 void ast_party_name_free(struct ast_party_name *doomed);
2719 * \brief Initialize the given number structure.
2722 * \param init Number structure to initialize.
2726 void ast_party_number_init(struct ast_party_number *init);
2729 * \brief Copy the source party number information to the destination party number.
2732 * \param dest Destination party number
2733 * \param src Source party number
2737 void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src);
2740 * \brief Initialize the given party number structure using the given guide
2741 * for a set update operation.
2745 * The initialization is needed to allow a set operation to know if a
2746 * value needs to be updated. Simple integers need the guide's original
2747 * value in case the set operation is not trying to set a new value.
2748 * String values are simply set to NULL pointers if they are not going
2751 * \param init Party number structure to initialize.
2752 * \param guide Source party number to use as a guide in initializing.
2756 void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide);
2759 * \brief Set the source party number information into the destination party number.
2762 * \param dest The number one wishes to update
2763 * \param src The new number values to update the dest
2767 void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src);
2770 * \brief Destroy the party number contents
2773 * \param doomed The party number to destroy.
2777 void ast_party_number_free(struct ast_party_number *doomed);
2781 * \brief Initialize the given subaddress structure.
2783 * \param init Subaddress structure to initialize.
2787 void ast_party_subaddress_init(struct ast_party_subaddress *init);
2791 * \brief Copy the source party subaddress information to the destination party subaddress.
2793 * \param dest Destination party subaddress
2794 * \param src Source party subaddress
2798 void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2802 * \brief Initialize the given party subaddress structure using the given guide
2803 * for a set update operation.
2806 * The initialization is needed to allow a set operation to know if a
2807 * value needs to be updated. Simple integers need the guide's original
2808 * value in case the set operation is not trying to set a new value.
2809 * String values are simply set to NULL pointers if they are not going
2812 * \param init Party subaddress structure to initialize.
2813 * \param guide Source party subaddress to use as a guide in initializing.
2817 void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide);
2821 * \brief Set the source party subaddress information into the destination party subaddress.
2823 * \param dest The subaddress one wishes to update
2824 * \param src The new subaddress values to update the dest
2828 void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2832 * \brief Destroy the party subaddress contents
2834 * \param doomed The party subaddress to destroy.
2838 void ast_party_subaddress_free(struct ast_party_subaddress *doomed);
2841 * \brief Initialize the given party id structure.
2844 * \param init Party id structure to initialize.
2848 void ast_party_id_init(struct ast_party_id *init);
2851 * \brief Copy the source party id information to the destination party id.
2854 * \param dest Destination party id
2855 * \param src Source party id
2859 void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src);
2862 * \brief Initialize the given party id structure using the given guide
2863 * for a set update operation.
2867 * The initialization is needed to allow a set operation to know if a
2868 * value needs to be updated. Simple integers need the guide's original
2869 * value in case the set operation is not trying to set a new value.
2870 * String values are simply set to NULL pointers if they are not going
2873 * \param init Party id structure to initialize.
2874 * \param guide Source party id to use as a guide in initializing.
2878 void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide);
2881 * \brief Set the source party id information into the destination party id.
2884 * \param dest The id one wishes to update
2885 * \param src The new id values to update the dest
2886 * \param update What id information to update. NULL if all.
2890 void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update);
2893 * \brief Destroy the party id contents
2896 * \param doomed The party id to destroy.
2900 void ast_party_id_free(struct ast_party_id *doomed);
2903 * \brief Determine the overall presentation value for the given party.
2906 * \param id Party to determine the overall presentation value.
2908 * \return Overall presentation value for the given party.
2910 int ast_party_id_presentation(const struct ast_party_id *id);
2913 * \brief Initialize the given dialed structure.
2916 * \param init Dialed structure to initialize.
2920 void ast_party_dialed_init(struct ast_party_dialed *init);
2923 * \brief Copy the source dialed party information to the destination dialed party.
2926 * \param dest Destination dialed party
2927 * \param src Source dialed party
2931 void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
2934 * \brief Initialize the given dialed structure using the given
2935 * guide for a set update operation.
2939 * The initialization is needed to allow a set operation to know if a
2940 * value needs to be updated. Simple integers need the guide's original
2941 * value in case the set operation is not trying to set a new value.
2942 * String values are simply set to NULL pointers if they are not going
2945 * \param init Caller structure to initialize.
2946 * \param guide Source dialed to use as a guide in initializing.
2950 void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide);
2953 * \brief Set the dialed information based on another dialed source
2956 * This is similar to ast_party_dialed_copy, except that NULL values for
2957 * strings in the src parameter indicate not to update the corresponding dest values.
2959 * \param dest The dialed one wishes to update
2960 * \param src The new dialed values to update the dest
2964 void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
2967 * \brief Destroy the dialed party contents
2970 * \param doomed The dialed party to destroy.
2974 void ast_party_dialed_free(struct ast_party_dialed *doomed);
2978 * \brief Initialize the given caller structure.
2980 * \param init Caller structure to initialize.
2984 void ast_party_caller_init(struct ast_party_caller *init);
2988 * \brief Copy the source caller information to the destination caller.
2990 * \param dest Destination caller
2991 * \param src Source caller
2995 void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src);
2998 * \brief Initialize the given caller structure using the given
2999 * guide for a set update operation.
3003 * The initialization is needed to allow a set operation to know if a
3004 * value needs to be updated. Simple integers need the guide's original
3005 * value in case the set operation is not trying to set a new value.
3006 * String values are simply set to NULL pointers if they are not going
3009 * \param init Caller structure to initialize.
3010 * \param guide Source caller to use as a guide in initializing.
3014 void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide);
3017 * \brief Set the caller information based on another caller source
3020 * This is similar to ast_party_caller_copy, except that NULL values for
3021 * strings in the src parameter indicate not to update the corresponding dest values.
3023 * \param dest The caller one wishes to update
3024 * \param src The new caller values to update the dest
3025 * \param update What caller information to update. NULL if all.
3029 void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update);
3032 * \brief Destroy the caller party contents
3035 * \param doomed The caller party to destroy.
3039 void ast_party_caller_free(struct ast_party_caller *doomed);
3043 * \brief Initialize the given connected line structure.
3045 * \param init Connected line structure to initialize.
3049 void ast_party_connected_line_init(struct ast_party_connected_line *init);
3053 * \brief Copy the source connected line information to the destination connected line.
3055 * \param dest Destination connected line
3056 * \param src Source connected line
3060 void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);
3064 * \brief Initialize the given connected line structure using the given
3065 * guide for a set update operation.
3068 * The initialization is needed to allow a set operation to know if a
3069 * value needs to be updated. Simple integers need the guide's original
3070 * value in case the set operation is not trying to set a new value.
3071 * String values are simply set to NULL pointers if they are not going
3074 * \param init Connected line structure to initialize.
3075 * \param guide Source connected line to use as a guide in initializing.
3079 void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide);
3083 * \brief Set the connected line information based on another connected line source
3085 * This is similar to ast_party_connected_line_copy, except that NULL values for
3086 * strings in the src parameter indicate not to update the corresponding dest values.
3088 * \param dest The connected line one wishes to update
3089 * \param src The new connected line values to update the dest
3090 * \param update What connected line information to update. NULL if all.
3094 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);
3098 * \brief Collect the caller party information into a connected line structure.
3100 * \param connected Collected caller information for the connected line
3101 * \param caller Caller information.
3105 * \warning This is a shallow copy.
3106 * \warning DO NOT call ast_party_connected_line_free() on the filled in
3107 * connected line structure!
3109 void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_party_caller *caller);
3113 * \brief Destroy the connected line information contents
3115 * \param doomed The connected line information to destroy.
3119 void ast_party_connected_line_free(struct ast_party_connected_line *doomed);
3122 * \brief Initialize the given redirecting structure.
3125 * \param init Redirecting structure to initialize.
3129 void ast_party_redirecting_init(struct ast_party_redirecting *init);
3133 * \brief Copy the source redirecting information to the destination redirecting.
3135 * \param dest Destination redirecting
3136 * \param src Source redirecting
3140 void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src);
3144 * \brief Initialize the given redirecting id structure using the given guide
3145 * for a set update operation.
3148 * The initialization is needed to allow a set operation to know if a
3149 * value needs to be updated. Simple integers need the guide's original
3150 * value in case the set operation is not trying to set a new value.
3151 * String values are simply set to NULL pointers if they are not going
3154 * \param init Redirecting id structure to initialize.
3155 * \param guide Source redirecting id to use as a guide in initializing.
3159 void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide);
3162 * \brief Set the redirecting information based on another redirecting source
3165 * This is similar to ast_party_redirecting_copy, except that NULL values for
3166 * strings in the src parameter indicate not to update the corresponding dest values.
3168 * \param dest The redirecting one wishes to update
3169 * \param src The new redirecting values to update the dest
3170 * \param update What redirecting information to update. NULL if all.
3174 void ast_party_redirecting_set(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update);
3178 * \brief Destroy the redirecting information contents
3180 * \param doomed The redirecting information to destroy.
3184 void ast_party_redirecting_free(struct ast_party_redirecting *doomed);
3188 * \brief Copy the caller information to the connected line information.
3190 * \param dest Destination connected line information
3191 * \param src Source caller information
3195 * \note Assumes locks are already acquired
3197 void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src);
3201 * \brief Copy the connected line information to the caller information.
3203 * \param dest Destination caller information
3204 * \param src Source connected line information
3208 * \note Assumes locks are already acquired
3210 void ast_connected_line_copy_to_caller(struct ast_party_caller *dest, const struct ast_party_connected_line *src);
3214 * \brief Set the connected line information in the Asterisk channel
3216 * \param chan Asterisk channel to set connected line information
3217 * \param connected Connected line information
3218 * \param update What connected line information to update. NULL if all.
3222 * \note The channel does not need to be locked before calling this function.
3224 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);
3228 * \brief Build the connected line information data frame.
3230 * \param data Buffer to fill with the frame data
3231 * \param datalen Size of the buffer to fill
3232 * \param connected Connected line information
3233 * \param update What connected line information to build. NULL if all.
3235 * \retval -1 if error
3236 * \retval Amount of data buffer used
3238 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);
3242 * \brief Parse connected line indication frame data
3244 * \param data Buffer with the frame data to parse
3245 * \param datalen Size of the buffer
3246 * \param connected Extracted connected line information
3248 * \retval 0 on success.
3249 * \retval -1 on error.
3251 * \note The filled in connected line structure needs to be initialized by
3252 * ast_party_connected_line_set_init() before calling. If defaults are not
3253 * required use ast_party_connected_line_init().
3254 * \note The filled in connected line structure needs to be destroyed by
3255 * ast_party_connected_line_free() when it is no longer needed.
3257 int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected);
3261 * \brief Indicate that the connected line information has changed
3263 * \param chan Asterisk channel to indicate connected line information
3264 * \param connected Connected line information
3265 * \param update What connected line information to update. NULL if all.
3269 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);
3273 * \brief Queue a connected line update frame on a channel
3275 * \param chan Asterisk channel to indicate connected line information
3276 * \param connected Connected line information
3277 * \param update What connected line information to update. NULL if all.
3281 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);
3285 * \brief Set the redirecting id information in the Asterisk channel
3287 * \param chan Asterisk channel to set redirecting id information
3288 * \param redirecting Redirecting id information
3289 * \param update What redirecting information to update. NULL if all.
3293 * \note The channel does not need to be locked before calling this function.
3295 void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3299 * \brief Build the redirecting id data frame.
3301 * \param data Buffer to fill with the frame data
3302 * \param datalen Size of the buffer to fill
3303 * \param redirecting Redirecting id information
3304 * \param update What redirecting information to build. NULL if all.
3306 * \retval -1 if error
3307 * \retval Amount of data buffer used
3309 int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3313 * \brief Parse redirecting indication frame data
3315 * \param data Buffer with the frame data to parse
3316 * \param datalen Size of the buffer
3317 * \param redirecting Extracted redirecting id information
3319 * \retval 0 on success.
3320 * \retval -1 on error.
3322 * \note The filled in id structure needs to be initialized by
3323 * ast_party_redirecting_set_init() before calling.
3324 * \note The filled in id structure needs to be destroyed by
3325 * ast_party_redirecting_free() when it is no longer needed.
3327 int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting);
3331 * \brief Indicate that the redirecting id has changed
3333 * \param chan Asterisk channel to indicate redirecting id information
3334 * \param redirecting Redirecting id information
3335 * \param update What redirecting information to update. NULL if all.
3339 void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3343 * \brief Queue a redirecting update frame on a channel
3345 * \param chan Asterisk channel to indicate redirecting id information
3346 * \param redirecting Redirecting id information
3347 * \param update What redirecting information to update. NULL if all.
3351 void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
3355 * \brief Run a connected line interception macro and update a channel's connected line
3357 * \deprecated You should use the ast_channel_connected_line_sub() function instead.
3359 * Whenever we want to update a channel's connected line information, we may need to run
3360 * a macro so that an administrator can manipulate the information before sending it
3361 * out. This function both runs the macro and sends the update to the channel.
3363 * \param autoservice_chan Channel to place into autoservice while the macro is running.
3364 * It is perfectly safe for this to be NULL
3365 * \param macro_chan The channel to run the macro on. Also the channel from which we
3366 * determine which macro we need to run.
3367 * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
3368 * AST_CONTROL_CONNECTED_LINE
3369 * \param is_caller If true, then run CONNECTED_LINE_CALLER_SEND_MACRO with arguments from
3370 * CONNECTED_LINE_CALLER_SEND_MACRO_ARGS, otherwise run CONNECTED_LINE_CALLEE_SEND_MACRO
3371 * with arguments from CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS
3372 * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
3373 * ast_party_connected_line pointer.
3375 * \retval -1 Either the macro does not exist, or there was an error while attempting to
3378 * \todo Have multiple return codes based on the MACRO_RESULT
3379 * \todo Make constants so that caller and frame can be more expressive than just '1' and
3382 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);
3386 * \brief Run a connected line interception subroutine and update a channel's connected line
3389 * Whenever we want to update a channel's connected line information, we may need to run
3390 * a subroutine so that an administrator can manipulate the information before sending it
3391 * out. This function both runs the subroutine specified by CONNECTED_LINE_SEND_SUB and
3392 * sends the update to the channel.
3394 * \param autoservice_chan Channel to place into autoservice while the sub is running.
3395 * It is perfectly safe for this to be NULL
3396 * \param sub_chan The channel to run the subroutine on. Also the channel from which we
3397 * determine which subroutine we need to run.
3398 * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
3399 * AST_CONTROL_CONNECTED_LINE
3400 * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
3401 * ast_party_connected_line pointer.
3403 * \retval -1 Either the subroutine does not exist, or there was an error while attempting to
3404 * run the subroutine
3406 int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame);
3409 * \brief Insert into an astdata tree, the channel structure.
3410 * \param[in] tree The ast data tree.
3411 * \param[in] chan The channel structure to add to tree.
3412 * \param[in] add_bridged Add the bridged channel to the structure.
3413 * \retval <0 on error.
3414 * \retval 0 on success.
3416 int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan, int add_bridged);
3419 * \brief Compare to channel structures using the data api.
3420 * \param[in] tree The search tree generated by the data api.
3421 * \param[in] chan The channel to compare.
3422 * \param[in] structure_name The name of the node of the channel structure.
3423 * \retval 0 The structure matches.
3424 * \retval 1 The structure doesn't matches.
3426 int ast_channel_data_cmp_structure(const struct ast_data_search *tree, struct ast_channel *chan,
3427 const char *structure_name);
3431 * \brief Run a redirecting interception macro and update a channel's redirecting information
3432 * \deprecated You should use the ast_channel_redirecting_sub() function instead.
3435 * Whenever we want to update a channel's redirecting information, we may need to run
3436 * a macro so that an administrator can manipulate the information before sending it
3437 * out. This function both runs the macro and sends the update to the channel.
3439 * \param autoservice_chan Channel to place into autoservice while the macro is running.
3440 * It is perfectly safe for this to be NULL
3441 * \param macro_chan The channel to run the macro on. Also the channel from which we
3442 * determine which macro we need to run.
3443 * \param redirecting_info Either an ast_party_redirecting or ast_frame pointer of type
3444 * AST_CONTROL_REDIRECTING
3445 * \param is_caller If true, then run REDIRECTING_CALLER_SEND_MACRO with arguments from
3446 * REDIRECTING_CALLER_SEND_MACRO_ARGS, otherwise run REDIRECTING_CALLEE_SEND_MACRO with
3447 * arguments from REDIRECTING_CALLEE_SEND_MACRO_ARGS
3448 * \param is_frame If true, then redirecting_info is an ast_frame pointer, otherwise it is an
3449 * ast_party_redirecting pointer.
3452 * \retval -1 Either the macro does not exist, or there was an error while attempting to
3455 * \todo Have multiple return codes based on the MACRO_RESULT
3456 * \todo Make constants so that caller and frame can be more expressive than just '1' and
3459 int ast_channel_redirecting_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame);
3463 * \brief Run a redirecting interception subroutine and update a channel's redirecting information
3466 * Whenever we want to update a channel's redirecting information, we may need to run
3467 * a subroutine so that an administrator can manipulate the information before sending it