Get rid of ast_bridged_channel() and the bridged_channel field on ast_channels.
[asterisk/asterisk.git] / include / asterisk / channel.h
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2006, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
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.
13  *
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.
17  */
18
19 /*! \file
20  * \brief General Asterisk PBX channel definitions.
21  * \par See also:
22  *  \arg \ref Def_Channel
23  *  \arg \ref channel_drivers
24  */
25
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.
32         \par
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
37         channel.c .
38         \par Call scenario
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)
49                    application
50         .
51
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
68            for the call.
69
70
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.
77
78         \par Reference
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
84         \arg \ref Def_Bridge
85
86 */
87 /*! \page Def_Bridge Asterisk Channel Bridges
88
89         In Asterisk, there's several media bridges.
90
91         The Core bridge handles two channels (a "phone call") and bridge
92         them together.
93
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.
99
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
103         core.
104
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.
108
109 References:
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()
115         \li \ref Def_Channel
116 */
117
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.
121 */
122
123 #ifndef _ASTERISK_CHANNEL_H
124 #define _ASTERISK_CHANNEL_H
125
126 #include "asterisk/abstract_jb.h"
127 #include "asterisk/astobj2.h"
128 #include "asterisk/poll-compat.h"
129
130 #if defined(__cplusplus) || defined(c_plusplus)
131 extern "C" {
132 #endif
133
134 #define AST_MAX_EXTENSION       80  /*!< Max length of an extension */
135 #define AST_MAX_CONTEXT         80  /*!< Max length of a context */
136 #define AST_MAX_UNIQUEID       150  /*!< Max length of a channel uniqueid */
137 /*                                   150 = 127 (max systemname) + "-" + 10 (epoch
138  *                                   timestamp) + "." + 10 (monotonically incrementing
139  *                                   integer) + NULL. Note that if this value is ever
140  *                                   changed, MAX_CHANNEL_ID should be updated in
141  *                                   rtp_engine.h */
142 #define AST_MAX_ACCOUNT_CODE    20  /*!< Max length of an account code */
143 #define AST_CHANNEL_NAME        80  /*!< Max length of an ast_channel name */
144 #define MAX_LANGUAGE            40  /*!< Max length of the language setting */
145 #define MAX_MUSICCLASS          80  /*!< Max length of the music class setting */
146 #define AST_MAX_USER_FIELD      256 /*!< Max length of the channel user field */
147
148 #include "asterisk/frame.h"
149 #include "asterisk/chanvars.h"
150 #include "asterisk/config.h"
151 #include "asterisk/lock.h"
152 #include "asterisk/cdr.h"
153 #include "asterisk/utils.h"
154 #include "asterisk/linkedlists.h"
155 #include "asterisk/stringfields.h"
156 #include "asterisk/datastore.h"
157 #include "asterisk/data.h"
158 #include "asterisk/channelstate.h"
159 #include "asterisk/ccss.h"
160 #include "asterisk/framehook.h"
161 #include "asterisk/stasis.h"
162 #include "asterisk/json.h"
163 #include "asterisk/endpoints.h"
164
165 #define DATASTORE_INHERIT_FOREVER       INT_MAX
166
167 #define AST_MAX_FDS             11
168 /*
169  * We have AST_MAX_FDS file descriptors in a channel.
170  * Some of them have a fixed use:
171  */
172 #define AST_ALERT_FD    (AST_MAX_FDS-1)         /*!< used for alertpipe */
173 #define AST_TIMING_FD   (AST_MAX_FDS-2)         /*!< used for timingfd */
174 #define AST_AGENT_FD    (AST_MAX_FDS-3)         /*!< used by agents for pass through */
175 #define AST_GENERATOR_FD        (AST_MAX_FDS-4) /*!< used by generator */
176 #define AST_JITTERBUFFER_FD     (AST_MAX_FDS-5) /*!< used by generator */
177
178 enum ast_bridge_result {
179         AST_BRIDGE_COMPLETE = 0,
180         AST_BRIDGE_FAILED = -1,
181         AST_BRIDGE_FAILED_NOWARN = -2,
182         AST_BRIDGE_RETRY = -3,
183 };
184
185 typedef unsigned long long ast_group_t;
186
187 /*! \todo Add an explanation of an Asterisk generator
188 */
189 struct ast_generator {
190         void *(*alloc)(struct ast_channel *chan, void *params);
191         /*! Channel is locked during this function callback. */
192         void (*release)(struct ast_channel *chan, void *data);
193         /*! This function gets called with the channel unlocked, but is called in
194          *  the context of the channel thread so we know the channel is not going
195          *  to disappear.  This callback is responsible for locking the channel as
196          *  necessary. */
197         int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
198         /*! This gets called when DTMF_END frames are read from the channel */
199         void (*digit)(struct ast_channel *chan, char digit);
200         /*! This gets called when the write format on a channel is changed while
201          * generating. The channel is locked during this callback. */
202         void (*write_format_change)(struct ast_channel *chan, void *data);
203 };
204
205 /*! Party name character set enumeration values (values from Q.SIG) */
206 enum AST_PARTY_CHAR_SET {
207         AST_PARTY_CHAR_SET_UNKNOWN = 0,
208         AST_PARTY_CHAR_SET_ISO8859_1 = 1,
209         AST_PARTY_CHAR_SET_WITHDRAWN = 2,/* ITU withdrew this enum value. */
210         AST_PARTY_CHAR_SET_ISO8859_2 = 3,
211         AST_PARTY_CHAR_SET_ISO8859_3 = 4,
212         AST_PARTY_CHAR_SET_ISO8859_4 = 5,
213         AST_PARTY_CHAR_SET_ISO8859_5 = 6,
214         AST_PARTY_CHAR_SET_ISO8859_7 = 7,
215         AST_PARTY_CHAR_SET_ISO10646_BMPSTRING = 8,
216         AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING = 9,
217 };
218
219 /*!
220  * \since 1.8
221  * \brief Information needed to specify a name in a call.
222  * \note All string fields here are malloc'ed, so they need to be
223  * freed when the structure is deleted.
224  * \note NULL and "" must be considered equivalent.
225  */
226 struct ast_party_name {
227         /*! \brief Subscriber name (Malloced) */
228         char *str;
229         /*!
230          * \brief Character set the name is using.
231          * \see enum AST_PARTY_CHAR_SET
232          * \note
233          * Set to AST_PARTY_CHAR_SET_ISO8859_1 if unsure what to use.
234          * \todo Start using the party name character set value.  Not currently used.
235          */
236         int char_set;
237         /*!
238          * \brief Q.931 encoded presentation-indicator encoded field
239          * \note Must tolerate the Q.931 screening-indicator field values being present.
240          */
241         int presentation;
242         /*! \brief TRUE if the name information is valid/present */
243         unsigned char valid;
244 };
245
246 /*!
247  * \since 1.8
248  * \brief Information needed to specify a number in a call.
249  * \note All string fields here are malloc'ed, so they need to be
250  * freed when the structure is deleted.
251  * \note NULL and "" must be considered equivalent.
252  */
253 struct ast_party_number {
254         /*! \brief Subscriber phone number (Malloced) */
255         char *str;
256         /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
257         int plan;
258         /*! \brief Q.931 presentation-indicator and screening-indicator encoded fields */
259         int presentation;
260         /*! \brief TRUE if the number information is valid/present */
261         unsigned char valid;
262 };
263
264 /*!
265  * \since 1.8
266  * \brief Information needed to specify a subaddress in a call.
267  * \note All string fields here are malloc'ed, so they need to be
268  * freed when the structure is deleted.
269  * \note NULL and "" must be considered equivalent.
270  */
271 struct ast_party_subaddress {
272         /*!
273          * \brief Malloced subaddress string.
274          * \note If the subaddress type is user specified then the subaddress is
275          * a string of ASCII hex because the actual subaddress is likely BCD encoded.
276          */
277         char *str;
278         /*!
279          * \brief Q.931 subaddress type.
280          * \details
281          * nsap(0),
282          * user_specified(2)
283          */
284         int type;
285         /*!
286          * \brief TRUE if odd number of address signals
287          * \note The odd/even indicator is used when the type of subaddress is
288          * user_specified and the coding is BCD.
289          */
290         unsigned char odd_even_indicator;
291         /*! \brief TRUE if the subaddress information is valid/present */
292         unsigned char valid;
293 };
294
295 /*!
296  * \since 1.8
297  * \brief Information needed to identify an endpoint in a call.
298  * \note All string fields here are malloc'ed, so they need to be
299  * freed when the structure is deleted.
300  * \note NULL and "" must be considered equivalent.
301  */
302 struct ast_party_id {
303         /*! \brief Subscriber name */
304         struct ast_party_name name;
305         /*! \brief Subscriber phone number */
306         struct ast_party_number number;
307         /*! \brief Subscriber subaddress. */
308         struct ast_party_subaddress subaddress;
309
310         /*!
311          * \brief User-set "tag"
312          * \details
313          * A user-settable field used to help associate some extrinsic information
314          * about the channel or user of the channel to the party ID.  This information
315          * is normally not transmitted over the wire and so is only useful within an
316          * Asterisk environment.
317          */
318         char *tag;
319 };
320
321 /*!
322  * \since 1.8
323  * \brief Indicate what information in ast_party_id should be set.
324  */
325 struct ast_set_party_id {
326         /*! TRUE if the ast_party_name information should be set. */
327         unsigned char name;
328         /*! TRUE if the ast_party_number information should be set. */
329         unsigned char number;
330         /*! TRUE if the ast_party_subaddress information should be set. */
331         unsigned char subaddress;
332 };
333
334 /*!
335  * \since 1.8
336  * \brief Dialed/Called Party information.
337  * \note Dialed Number Identifier (DNID)
338  * \note All string fields here are malloc'ed, so they need to be
339  * freed when the structure is deleted.
340  * \note NULL and "" must be considered equivalent.
341  */
342 struct ast_party_dialed {
343         /*!
344          * \brief Dialed/Called number
345          * \note Done this way in case we ever really need to use ast_party_number.
346          * We currently do not need all of the ast_party_number fields.
347          */
348         struct {
349                 /*! \brief Subscriber phone number (Malloced) */
350                 char *str;
351                 /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
352                 int plan;
353         } number;
354         /*! \brief Dialed/Called subaddress */
355         struct ast_party_subaddress subaddress;
356         /*!
357          * \brief Transit Network Select
358          * \note Currently this value is just passed around the system.
359          * You can read it and set it but it is never used for anything.
360          */
361         int transit_network_select;
362 };
363
364 /*!
365  * \since 1.8
366  * \brief Caller Party information.
367  * \note All string fields here are malloc'ed, so they need to be
368  * freed when the structure is deleted.
369  * \note NULL and "" must be considered equivalent.
370  *
371  * \note SIP and IAX2 has UTF8 encoded Unicode Caller ID names.
372  * In some cases, we also have an alternative (RPID) E.164 number that can
373  * be used as Caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to
374  * PSTN gateway).
375  *
376  * \todo Implement settings for transliteration between UTF8 Caller ID names in
377  *       to ASCII Caller ID's (DAHDI). Ã–sten Ã…sklund might be transliterated into
378  *       Osten Asklund or Oesten Aasklund depending upon language and person...
379  *       We need automatic routines for incoming calls and static settings for
380  *       our own accounts.
381  */
382 struct ast_party_caller {
383         /*! \brief Caller party ID */
384         struct ast_party_id id;
385
386         /*!
387          * \brief Automatic Number Identification (ANI)
388          * \note The name subcomponent is only likely to be used by SIP.
389          * \note The subaddress subcomponent is not likely to be used.
390          */
391         struct ast_party_id ani;
392
393         /*! \brief Private caller party ID */
394         struct ast_party_id priv;
395
396         /*! \brief Automatic Number Identification 2 (Info Digits) */
397         int ani2;
398 };
399
400 /*!
401  * \since 1.8
402  * \brief Indicate what information in ast_party_caller should be set.
403  */
404 struct ast_set_party_caller {
405         /*! What caller id information to set. */
406         struct ast_set_party_id id;
407         /*! What ANI id information to set. */
408         struct ast_set_party_id ani;
409         /*! What private caller id information to set. */
410         struct ast_set_party_id priv;
411 };
412
413 /*!
414  * \since 1.8
415  * \brief Connected Line/Party information.
416  * \note All string fields here are malloc'ed, so they need to be
417  * freed when the structure is deleted.
418  * \note NULL and "" must be considered equivalent.
419  */
420 struct ast_party_connected_line {
421         /*! \brief Connected party ID */
422         struct ast_party_id id;
423
424         /*!
425          * \brief Automatic Number Identification (ANI)
426          * \note Not really part of connected line data but needed to
427          * save the corresponding caller id value.
428          */
429         struct ast_party_id ani;
430
431         /*! \brief Private connected party ID */
432         struct ast_party_id priv;
433
434         /*!
435          * \brief Automatic Number Identification 2 (Info Digits)
436          * \note Not really part of connected line data but needed to
437          * save the corresponding caller id value.
438          */
439         int ani2;
440
441         /*!
442          * \brief Information about the source of an update.
443          * \note enum AST_CONNECTED_LINE_UPDATE_SOURCE values
444          * for Normal-Answer and Call-transfer.
445          */
446         int source;
447 };
448
449 /*!
450  * \since 1.8
451  * \brief Indicate what information in ast_party_connected_line should be set.
452  */
453 struct ast_set_party_connected_line {
454         /*! What connected line id information to set. */
455         struct ast_set_party_id id;
456         /*! What ANI id information to set. */
457         struct ast_set_party_id ani;
458         /*! What private connected line id information to set. */
459         struct ast_set_party_id priv;
460 };
461
462 /*!
463  * \brief Redirecting reason information
464  */
465 struct ast_party_redirecting_reason {
466         /*! \brief a string value for the redirecting reason
467          *
468          * Useful for cases where an endpoint has specified a redirecting reason
469          * that does not correspond to an enum AST_REDIRECTING_REASON
470          */
471         char *str;
472
473         /*! \brief enum AST_REDIRECTING_REASON value for redirection */
474         int code;
475 };
476
477 /*!
478  * \since 1.8
479  * \brief Redirecting Line information.
480  * RDNIS (Redirecting Directory Number Information Service)
481  * Where a call diversion or transfer was invoked.
482  * \note All string fields here are malloc'ed, so they need to be
483  * freed when the structure is deleted.
484  * \note NULL and "" must be considered equivalent.
485  */
486 struct ast_party_redirecting {
487         /*! \brief Who originally redirected the call (Sent to the party the call is redirected toward) */
488         struct ast_party_id orig;
489
490         /*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) */
491         struct ast_party_id from;
492
493         /*! \brief Call is redirecting to a new party (Sent to the caller) */
494         struct ast_party_id to;
495
496         /*! \brief Who originally redirected the call (Sent to the party the call is redirected toward) - private representation */
497         struct ast_party_id priv_orig;
498
499         /*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) - private representation */
500         struct ast_party_id priv_from;
501
502         /*! \brief Call is redirecting to a new party (Sent to the caller)  - private representation */
503         struct ast_party_id priv_to;
504
505         /*! \brief Reason for the redirection */
506         struct ast_party_redirecting_reason reason;
507
508         /*! \brief Reason for the redirection by the original party */
509         struct ast_party_redirecting_reason orig_reason;
510
511         /*! \brief Number of times the call was redirected */
512         int count;
513 };
514
515 /*!
516  * \since 1.8
517  * \brief Indicate what information in ast_party_redirecting should be set.
518  */
519 struct ast_set_party_redirecting {
520         /*! What redirecting-orig id information to set. */
521         struct ast_set_party_id orig;
522         /*! What redirecting-from id information to set. */
523         struct ast_set_party_id from;
524         /*! What redirecting-to id information to set. */
525         struct ast_set_party_id to;
526         /*! What private redirecting-orig id information to set. */
527         struct ast_set_party_id priv_orig;
528         /*! What private redirecting-from id information to set. */
529         struct ast_set_party_id priv_from;
530         /*! What private redirecting-to id information to set. */
531         struct ast_set_party_id priv_to;
532 };
533
534 /*!
535  * \brief Typedef for a custom read function
536  * \note data should be treated as const char *.
537  */
538 typedef int (*ast_acf_read_fn_t)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
539
540 /*!
541  * \brief Typedef for a custom read2 function
542  * \note data should be treated as const char *.
543  */
544 typedef int (*ast_acf_read2_fn_t)(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len);
545
546 /*!
547  * \brief Typedef for a custom write function
548  * \note data should be treated as const char *.
549  */
550 typedef int (*ast_acf_write_fn_t)(struct ast_channel *chan, const char *function, char *data, const char *value);
551
552 /*! \brief Structure to handle passing func_channel_write info to channels via setoption */
553 typedef struct {
554         /*! \brief ast_chan_write_info_t version. Must be incremented if structure is changed */
555         #define AST_CHAN_WRITE_INFO_T_VERSION 1
556         uint32_t version;
557         ast_acf_write_fn_t write_fn;
558         struct ast_channel *chan;
559         const char *function;
560         char *data;
561         const char *value;
562 } ast_chan_write_info_t;
563
564 /*!
565  * \brief
566  * Structure to describe a channel "technology", ie a channel driver
567  * See for examples:
568  * \arg chan_iax2.c - The Inter-Asterisk exchange protocol
569  * \arg chan_sip.c - The SIP channel driver
570  * \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
571  *
572  * \details
573  * If you develop your own channel driver, this is where you
574  * tell the PBX at registration of your driver what properties
575  * this driver supports and where different callbacks are
576  * implemented.
577  */
578 struct ast_channel_tech {
579         const char * const type;
580         const char * const description;
581
582         struct ast_format_cap *capabilities;  /*!< format capabilities this channel can handle */
583
584         int properties;         /*!< Technology Properties */
585
586         /*!
587          * \brief Requester - to set up call data structures (pvt's)
588          *
589          * \param type type of channel to request
590          * \param cap Format capabilities for requested channel
591          * \param requestor channel asking for data
592          * \param addr destination of the call
593          * \param cause Cause of failure
594          *
595          * \details
596          * Request a channel of a given type, with addr as optional information used
597          * by the low level module
598          *
599          * \retval NULL failure
600          * \retval non-NULL channel on success
601          */
602         struct ast_channel *(* const requester)(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr, int *cause);
603
604         int (* const devicestate)(const char *device_number);   /*!< Devicestate call back */
605
606         /*!
607          * \brief Start sending a literal DTMF digit
608          *
609          * \note The channel is not locked when this function gets called.
610          */
611         int (* const send_digit_begin)(struct ast_channel *chan, char digit);
612
613         /*!
614          * \brief Stop sending a literal DTMF digit
615          *
616          * \note The channel is not locked when this function gets called.
617          */
618         int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
619
620         /*!
621          * \brief Make a call
622          * \note The channel is locked when called.
623          * \param chan which channel to make the call on
624          * \param addr destination of the call
625          * \param timeout time to wait on for connect (Doesn't seem to be used.)
626          * \retval 0 on success
627          * \retval -1 on failure
628          */
629         int (* const call)(struct ast_channel *chan, const char *addr, int timeout);
630
631         /*! \brief Hangup (and possibly destroy) the channel */
632         int (* const hangup)(struct ast_channel *chan);
633
634         /*! \brief Answer the channel */
635         int (* const answer)(struct ast_channel *chan);
636
637         /*! \brief Read a frame, in standard format (see frame.h) */
638         struct ast_frame * (* const read)(struct ast_channel *chan);
639
640         /*! \brief Write a frame, in standard format (see frame.h) */
641         int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
642
643         /*! \brief Display or transmit text */
644         int (* const send_text)(struct ast_channel *chan, const char *text);
645
646         /*! \brief Display or send an image */
647         int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
648
649         /*! \brief Send HTML data */
650         int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
651
652         /*! \brief Handle an exception, reading a frame */
653         struct ast_frame * (* const exception)(struct ast_channel *chan);
654
655 /* BUGBUG this tech callback is to be removed. */
656         /*! \brief Bridge two channels of the same type together */
657         enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
658                                                 struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
659
660         /*! \brief Bridge two channels of the same type together (early) */
661         enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
662
663         /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
664         int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
665
666         /*! \brief Fix up a channel:  If a channel is consumed, this is called.  Basically update any ->owner links */
667         int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
668
669         /*! \brief Set a given option. Called with chan locked */
670         int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
671
672         /*! \brief Query a given option. Called with chan locked */
673         int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
674
675         /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
676         int (* const transfer)(struct ast_channel *chan, const char *newdest);
677
678         /*! \brief Write a frame, in standard format */
679         int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
680
681         /*! \brief Write a text frame, in standard format */
682         int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
683
684 /* BUGBUG this tech callback is to be removed. */
685         /*! \brief Find bridged channel */
686         struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
687
688         /*!
689          * \brief Provide additional read items for CHANNEL() dialplan function
690          * \note data should be treated as a const char *.
691          */
692         int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
693
694         /*!
695          * \brief Provide additional write items for CHANNEL() dialplan function
696          * \note data should be treated as a const char *.
697          */
698         int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
699
700 /* BUGBUG this tech callback is to be removed. */
701         /*! \brief Retrieve base channel (agent and local) */
702         struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
703
704         /*! \brief Set base channel (agent and local) */
705         int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
706
707         /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
708         const char * (* get_pvt_uniqueid)(struct ast_channel *chan);
709
710         /*! \brief Call a function with cc parameters as a function parameter
711          *
712          * \details
713          * This is a highly specialized callback that is not likely to be needed in many
714          * channel drivers. When dealing with a busy channel, for instance, most channel
715          * drivers will successfully return a channel to the requester. Once called, the channel
716          * can then queue a busy frame when it receives an appropriate message from the far end.
717          * In such a case, the channel driver has the opportunity to also queue a CC frame.
718          * The parameters for the CC channel can be retrieved from the channel structure.
719          *
720          * For other channel drivers, notably those that deal with "dumb" phones, the channel
721          * driver will not return a channel when one is requested. In such a scenario, there is never
722          * an opportunity for the channel driver to queue a CC frame since the channel is never
723          * called. Furthermore, it is not possible to retrieve the CC configuration parameters
724          * for the desired channel because no channel is ever allocated or returned to the
725          * requester. In such a case, call completion may still be a viable option. What we do is
726          * pass the same string that the requester used originally to request the channel to the
727          * channel driver. The channel driver can then find any potential channels/devices that
728          * match the input and return call the designated callback with the device's call completion
729          * parameters as a parameter.
730          */
731         int (* cc_callback)(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
732
733         /*!
734          * \brief Execute a Gosub call on the channel in a technology specific way before a call is placed.
735          * \since 11.0
736          *
737          * \param chan Channel to execute Gosub in a tech specific way.
738          * \param sub_args Gosub application parameter string.
739          *
740          * \note The chan is locked before calling.
741          *
742          * \retval 0 on success.
743          * \retval -1 on error.
744          */
745         int (*pre_call)(struct ast_channel *chan, const char *sub_args);
746 };
747
748 /*! Kill the channel channel driver technology descriptor. */
749 extern const struct ast_channel_tech ast_kill_tech;
750
751 struct ast_epoll_data;
752
753 /*!
754  * The high bit of the frame count is used as a debug marker, so
755  * increments of the counters must be done with care.
756  * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
757  */
758 #define DEBUGCHAN_FLAG  0x80000000
759
760 /* XXX not ideal to evaluate x twice... */
761 #define FRAMECOUNT_INC(x)       ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
762
763 /*!
764  * The current value of the debug flags is stored in the two
765  * variables global_fin and global_fout (declared in main/channel.c)
766  */
767 extern unsigned long global_fin, global_fout;
768
769 enum ast_channel_adsicpe {
770         AST_ADSI_UNKNOWN,
771         AST_ADSI_AVAILABLE,
772         AST_ADSI_UNAVAILABLE,
773         AST_ADSI_OFFHOOKONLY,
774 };
775
776 /*!
777  * \brief Possible T38 states on channels
778  */
779 enum ast_t38_state {
780         T38_STATE_UNAVAILABLE,  /*!< T38 is unavailable on this channel or disabled by configuration */
781         T38_STATE_UNKNOWN,      /*!< The channel supports T38 but the current status is unknown */
782         T38_STATE_NEGOTIATING,  /*!< T38 is being negotiated */
783         T38_STATE_REJECTED,     /*!< Remote side has rejected our offer */
784         T38_STATE_NEGOTIATED,   /*!< T38 established */
785 };
786
787 /*! Hangup handler instance node. */
788 struct ast_hangup_handler {
789         /*! Next hangup handler node. */
790         AST_LIST_ENTRY(ast_hangup_handler) node;
791         /*! Hangup handler arg string passed to the Gosub application */
792         char args[0];
793 };
794
795 AST_LIST_HEAD_NOLOCK(ast_hangup_handler_list, ast_hangup_handler);
796 AST_LIST_HEAD_NOLOCK(ast_datastore_list, ast_datastore);
797 AST_LIST_HEAD_NOLOCK(ast_autochan_list, ast_autochan);
798 AST_LIST_HEAD_NOLOCK(ast_readq_list, ast_frame);
799
800 typedef int(*ast_timing_func_t)(const void *data);
801 /*!
802  * \page AstChannel ast_channel locking and reference tracking
803  *
804  * \par Creating Channels
805  * A channel is allocated using the ast_channel_alloc() function.  When created, it is
806  * automatically inserted into the main channels hash table that keeps track of all
807  * active channels in the system.  The hash key is based on the channel name.  Because
808  * of this, if you want to change the name, you _must_ use ast_change_name(), not change
809  * the name field directly.  When ast_channel_alloc() returns a channel pointer, you now
810  * hold a reference to that channel.  In most cases this reference is given to ast_pbx_run().
811  *
812  * \par Channel Locking
813  * There is a lock associated with every ast_channel.  It is allocated internally via astobj2.
814  * To lock or unlock a channel, you must use the ast_channel_lock() wrappers.
815  *
816  * Previously, before ast_channel was converted to astobj2, the channel lock was used in some
817  * additional ways that are no longer necessary.  Before, the only way to ensure that a channel
818  * did not disappear out from under you if you were working with a channel outside of the channel
819  * thread that owns it, was to hold the channel lock.  Now, that is no longer necessary.
820  * You simply must hold a reference to the channel to ensure it does not go away.
821  *
822  * The channel must be locked if you need to ensure that data that you reading from the channel
823  * does not change while you access it.  Further, you must hold the channel lock if you are
824  * making a non-atomic change to channel data.
825  *
826  * \par Channel References
827  * There are multiple ways to get a reference to a channel.  The first is that you hold a reference
828  * to a channel after creating it.  The other ways involve using the channel search or the channel
829  * traversal APIs.  These functions are the ast_channel_get_*() functions or ast_channel_iterator_*()
830  * functions.  Once a reference is retrieved by one of these methods, you know that the channel will
831  * not go away.  So, the channel should only get locked as needed for data access or modification.
832  * But, make sure that the reference gets released when you are done with it!
833  *
834  * There are different things you can do when you are done with a reference to a channel.  The first
835  * is to simply release the reference using ast_channel_unref().  The other option is to call
836  * ast_channel_release().  This function is generally used where ast_channel_free() was used in
837  * the past.  The release function releases a reference as well as ensures that the channel is no
838  * longer in the global channels container.  That way, the channel will get destroyed as soon as any
839  * other pending references get released.
840  *
841  * \par Exceptions to the rules
842  * Even though ast_channel is reference counted, there are some places where pointers to an ast_channel
843  * get stored, but the reference count does not reflect it.  The reason is mostly historical.
844  * The only places where this happens should be places where because of how the code works, we
845  * _know_ that the pointer to the channel will get removed before the channel goes away.  The main
846  * example of this is in channel drivers.  Channel drivers generally store a pointer to their owner
847  * ast_channel in their technology specific pvt struct.  In this case, the channel drivers _know_
848  * that this pointer to the channel will be removed in time, because the channel's hangup callback
849  * gets called before the channel goes away.
850  */
851
852 struct ast_channel;
853
854 /*! \brief ast_channel_tech Properties */
855 enum {
856         /*!
857          * \brief Channels have this property if they can accept input with jitter;
858          * i.e. most VoIP channels
859          */
860         AST_CHAN_TP_WANTSJITTER = (1 << 0),
861         /*!
862          * \brief Channels have this property if they can create jitter;
863          * i.e. most VoIP channels
864          */
865         AST_CHAN_TP_CREATESJITTER = (1 << 1),
866         /*!
867          * \brief Channels have this property if they are an implementation detail
868          * used for announcing messages; i.e. to a bridge
869          */
870         AST_CHAN_TP_ANNOUNCER = (1 << 2),
871         /*!
872          * \brief Channels have this property if they are an implementation detail
873          * used for recording audio; i.e. from a bridge
874          */
875         AST_CHAN_TP_RECORDER = (1 << 3),
876 };
877
878 /*! \brief ast_channel flags */
879 enum {
880         /*! Queue incoming DTMF, to be released when this flag is turned off */
881         AST_FLAG_DEFER_DTMF =    (1 << 1),
882         /*! write should be interrupt generator */
883         AST_FLAG_WRITE_INT =     (1 << 2),
884         /*! a thread is blocking on this channel */
885         AST_FLAG_BLOCKING =      (1 << 3),
886         /*! This is a zombie channel */
887         AST_FLAG_ZOMBIE =        (1 << 4),
888         /*! There is an exception pending */
889         AST_FLAG_EXCEPTION =     (1 << 5),
890         /*! Listening to moh XXX anthm promises me this will disappear XXX */
891         AST_FLAG_MOH =           (1 << 6),
892         /*! This channel is spying on another channel */
893         AST_FLAG_SPYING =        (1 << 7),
894         /*! the channel is in an auto-incrementing dialplan processor,
895          *  so when ->priority is set, it will get incremented before
896          *  finding the next priority to run */
897         AST_FLAG_IN_AUTOLOOP =   (1 << 9),
898         /*! This is an outgoing call */
899         AST_FLAG_OUTGOING =      (1 << 10),
900         /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
901         AST_FLAG_IN_DTMF =       (1 << 12),
902         /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
903          *  currently being emulated */
904         AST_FLAG_EMULATE_DTMF =  (1 << 13),
905         /*! This is set to tell the channel not to generate DTMF begin frames, and
906          *  to instead only generate END frames. */
907         AST_FLAG_END_DTMF_ONLY = (1 << 14),
908         /* OBSOLETED in favor of AST_CAUSE_ANSWERED_ELSEWHERE
909         Flag to show channels that this call is hangup due to the fact that the call
910             was indeed answered, but in another channel */
911         /* AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), */
912         /*! This flag indicates that on a masquerade, an active stream should not
913          *  be carried over */
914         AST_FLAG_MASQ_NOSTREAM = (1 << 16),
915         /*! This flag indicates that the hangup exten was run when the bridge terminated,
916          *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
917          *  level */
918         AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
919         /*! Disable certain workarounds.  This reintroduces certain bugs, but allows
920          *  some non-traditional dialplans (like AGI) to continue to function.
921          */
922         AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
923         /*!
924          * Disable device state event caching.  This allows channel
925          * drivers to selectively prevent device state events from being
926          * cached by certain channels such as anonymous calls which have
927          * no persistent represenatation that can be tracked.
928          */
929         AST_FLAG_DISABLE_DEVSTATE_CACHE = (1 << 21),
930         /*!
931          * This flag indicates that a dual channel redirect is in
932          * progress.  The bridge needs to wait until the flag is cleared
933          * to continue.
934          */
935         AST_FLAG_BRIDGE_DUAL_REDIRECT_WAIT = (1 << 22),
936         /*!
937          * This flag indicates that the channel was originated.
938          */
939         AST_FLAG_ORIGINATED = (1 << 23),
940         /*!
941          * The channel is well and truly dead. Once this is set and published, no further
942          * actions should be taken upon the channel, and no further publications should
943          * occur.
944          */
945         AST_FLAG_DEAD = (1 << 24),
946 };
947
948 /*! \brief ast_bridge_config flags */
949 enum {
950         AST_FEATURE_PLAY_WARNING = (1 << 0),
951         AST_FEATURE_REDIRECT =     (1 << 1),
952         AST_FEATURE_DISCONNECT =   (1 << 2),
953         AST_FEATURE_ATXFER =       (1 << 3),
954         AST_FEATURE_AUTOMON =      (1 << 4),
955         AST_FEATURE_PARKCALL =     (1 << 5),
956         AST_FEATURE_AUTOMIXMON =   (1 << 6),
957 };
958
959 #define AST_FEATURE_DTMF_MASK (AST_FEATURE_REDIRECT | AST_FEATURE_DISCONNECT |\
960         AST_FEATURE_ATXFER | AST_FEATURE_AUTOMON | AST_FEATURE_PARKCALL | AST_FEATURE_AUTOMIXMON)
961
962 /*! \brief bridge configuration */
963 struct ast_bridge_config {
964         struct ast_flags features_caller;
965         struct ast_flags features_callee;
966         struct timeval start_time;
967         struct timeval nexteventts;
968         struct timeval feature_start_time;
969         long feature_timer;
970         long timelimit;
971         long play_warning;
972         long warning_freq;
973         const char *warning_sound;
974         const char *end_sound;
975         const char *start_sound;
976         unsigned int flags;
977         void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
978         void *end_bridge_callback_data;         /*!< Data passed to the callback */
979         /*! If the end_bridge_callback_data refers to a channel which no longer is going to
980          * exist when the end_bridge_callback is called, then it needs to be fixed up properly
981          */
982         void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
983 };
984
985 struct chanmon;
986
987 struct outgoing_helper {
988         const char *context;
989         const char *exten;
990         int priority;
991         int connect_on_early_media;     /* If set, treat session progress as answer */
992         const char *cid_num;
993         const char *cid_name;
994         const char *account;
995         struct ast_variable *vars;
996         struct ast_channel *parent_channel;
997 };
998
999 enum {
1000         /*!
1001          * Soft hangup requested by device or other internal reason.
1002          * Actual hangup needed.
1003          */
1004         AST_SOFTHANGUP_DEV =       (1 << 0),
1005         /*!
1006          * Used to break the normal frame flow so an async goto can be
1007          * done instead of actually hanging up.
1008          */
1009         AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
1010         /*!
1011          * Soft hangup requested by system shutdown.  Actual hangup
1012          * needed.
1013          */
1014         AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
1015         /*!
1016          * Used to break the normal frame flow after a timeout so an
1017          * implicit async goto can be done to the 'T' exten if it exists
1018          * instead of actually hanging up.  If the exten does not exist
1019          * then actually hangup.
1020          */
1021         AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
1022         /*!
1023          * Soft hangup requested by application/channel-driver being
1024          * unloaded.  Actual hangup needed.
1025          */
1026         AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
1027         /*!
1028          * Soft hangup requested by non-associated party.  Actual hangup
1029          * needed.
1030          */
1031         AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
1032         /*!
1033          * Used to break a bridge so the channel can be spied upon
1034          * instead of actually hanging up.
1035          */
1036         AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
1037         /*!
1038          * Used to indicate that the channel is currently executing hangup
1039          * logic in the dialplan. The channel has been hungup when this is
1040          * set.
1041          */
1042         AST_SOFTHANGUP_HANGUP_EXEC = (1 << 7),
1043         /*!
1044          * \brief All softhangup flags.
1045          *
1046          * This can be used as an argument to ast_channel_clear_softhangup()
1047          * to clear all softhangup flags from a channel.
1048          */
1049         AST_SOFTHANGUP_ALL =       (0xFFFFFFFF)
1050 };
1051
1052
1053 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
1054 enum channelreloadreason {
1055         CHANNEL_MODULE_LOAD,
1056         CHANNEL_MODULE_RELOAD,
1057         CHANNEL_CLI_RELOAD,
1058         CHANNEL_MANAGER_RELOAD,
1059         CHANNEL_ACL_RELOAD,
1060 };
1061
1062 /*!
1063  * \brief Channel AMA Flags
1064  */
1065 enum ama_flags {
1066         AST_AMA_NONE = 0,
1067         AST_AMA_OMIT,
1068         AST_AMA_BILLING,
1069         AST_AMA_DOCUMENTATION,
1070 };
1071
1072 /*!
1073  * \note None of the datastore API calls lock the ast_channel they are using.
1074  *       So, the channel should be locked before calling the functions that
1075  *       take a channel argument.
1076  */
1077
1078 /*!
1079  * \brief Create a channel data store object
1080  * \deprecated You should use the ast_datastore_alloc() generic function instead.
1081  * \version 1.6.1 deprecated
1082  */
1083 struct ast_datastore * attribute_malloc ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
1084         __attribute__((deprecated));
1085
1086 /*!
1087  * \brief Free a channel data store object
1088  * \deprecated You should use the ast_datastore_free() generic function instead.
1089  * \version 1.6.1 deprecated
1090  */
1091 int ast_channel_datastore_free(struct ast_datastore *datastore)
1092         __attribute__((deprecated));
1093
1094 /*! \brief Inherit datastores from a parent to a child. */
1095 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
1096
1097 /*!
1098  * \brief Add a datastore to a channel
1099  *
1100  * \note The channel should be locked before calling this function.
1101  *
1102  * \retval 0 success
1103  * \retval non-zero failure
1104  */
1105 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
1106
1107 /*!
1108  * \brief Remove a datastore from a channel
1109  *
1110  * \note The channel should be locked before calling this function.
1111  *
1112  * \retval 0 success
1113  * \retval non-zero failure
1114  */
1115 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
1116
1117 /*!
1118  * \brief Find a datastore on a channel
1119  *
1120  * \note The channel should be locked before calling this function.
1121  *
1122  * \note The datastore returned from this function must not be used if the
1123  *       reference to the channel is released.
1124  *
1125  * \retval pointer to the datastore if found
1126  * \retval NULL if not found
1127  */
1128 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
1129
1130 /*!
1131  * \brief Create a channel structure
1132  * \since 1.8
1133  *
1134  * \retval NULL failure
1135  * \retval non-NULL successfully allocated channel
1136  *
1137  * \note Absolutely _NO_ channel locks should be held before calling this function.
1138  * \note By default, new channels are set to the "s" extension
1139  *       and "default" context.
1140  */
1141 struct ast_channel * attribute_malloc __attribute__((format(printf, 13, 14)))
1142         __ast_channel_alloc(int needqueue, int state, const char *cid_num,
1143                             const char *cid_name, const char *acctcode,
1144                             const char *exten, const char *context,
1145                             const char *linkedid, enum ama_flags amaflag,
1146                             const char *file, int line, const char *function,
1147                             const char *name_fmt, ...);
1148
1149 /*!
1150  * \brief Create a channel structure
1151  *
1152  * \retval NULL failure
1153  * \retval non-NULL successfully allocated channel
1154  *
1155  * \note Absolutely _NO_ channel locks should be held before calling this function.
1156  * \note By default, new channels are set to the "s" extension
1157  *       and "default" context.
1158  */
1159 #define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, ...) \
1160         __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, \
1161                             __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
1162
1163 #if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
1164 /*!
1165  * \brief Create a fake channel structure
1166  *
1167  * \retval NULL failure
1168  * \retval non-NULL successfully allocated channel
1169  *
1170  * \note This function should ONLY be used to create a fake channel
1171  *       that can then be populated with data for use in variable
1172  *       substitution when a real channel does not exist.
1173  *
1174  * \note The created dummy channel should be destroyed by
1175  * ast_channel_unref().  Using ast_channel_release() needlessly
1176  * grabs the channel container lock and can cause a deadlock as
1177  * a result.  Also grabbing the channel container lock reduces
1178  * system performance.
1179  */
1180 #define ast_dummy_channel_alloc()       __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
1181 struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);
1182 #else
1183 /*!
1184  * \brief Create a fake channel structure
1185  *
1186  * \retval NULL failure
1187  * \retval non-NULL successfully allocated channel
1188  *
1189  * \note This function should ONLY be used to create a fake channel
1190  *       that can then be populated with data for use in variable
1191  *       substitution when a real channel does not exist.
1192  *
1193  * \note The created dummy channel should be destroyed by
1194  * ast_channel_unref().  Using ast_channel_release() needlessly
1195  * grabs the channel container lock and can cause a deadlock as
1196  * a result.  Also grabbing the channel container lock reduces
1197  * system performance.
1198  */
1199 struct ast_channel *ast_dummy_channel_alloc(void);
1200 #endif
1201
1202 /*!
1203  * \brief Queue one or more frames to a channel's frame queue
1204  *
1205  * \param chan the channel to queue the frame(s) on
1206  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
1207  *        by this function.  It is the responsibility of the caller to handle
1208  *        freeing the memory associated with the frame(s) being passed if
1209  *        necessary.
1210  *
1211  * \retval 0 success
1212  * \retval non-zero failure
1213  */
1214 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
1215
1216 /*!
1217  * \brief Queue one or more frames to the head of a channel's frame queue
1218  *
1219  * \param chan the channel to queue the frame(s) on
1220  * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
1221  *        by this function.  It is the responsibility of the caller to handle
1222  *        freeing the memory associated with the frame(s) being passed if
1223  *        necessary.
1224  *
1225  * \retval 0 success
1226  * \retval non-zero failure
1227  */
1228 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
1229
1230 /*!
1231  * \brief Queue a hangup frame
1232  *
1233  * \note The channel does not need to be locked before calling this function.
1234  */
1235 int ast_queue_hangup(struct ast_channel *chan);
1236
1237 /*!
1238  * \brief Queue a hangup frame with hangupcause set
1239  *
1240  * \note The channel does not need to be locked before calling this function.
1241  * \param[in] chan channel to queue frame onto
1242  * \param[in] cause the hangup cause
1243  * \return 0 on success, -1 on error
1244  * \since 1.6.1
1245  */
1246 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
1247
1248 /*!
1249  * \brief Queue a hold frame
1250  *
1251  * \param chan channel to queue frame onto
1252  * \param musicclass The suggested musicclass for the other end to use
1253  *
1254  * \note The channel does not need to be locked before calling this function.
1255  *
1256  * \retval zero on success
1257  * \retval non-zero on failure
1258  */
1259 int ast_queue_hold(struct ast_channel *chan, const char *musicclass);
1260
1261 /*!
1262  * \brief Queue an unhold frame
1263  *
1264  * \param chan channel to queue frame onto
1265  *
1266  * \note The channel does not need to be locked before calling this function.
1267  *
1268  * \retval zero on success
1269  * \retval non-zero on failure
1270  */
1271 int ast_queue_unhold(struct ast_channel *chan);
1272
1273 /*!
1274  * \brief Queue a control frame without payload
1275  *
1276  * \param chan channel to queue frame onto
1277  * \param control type of control frame
1278  *
1279  * \note The channel does not need to be locked before calling this function.
1280  *
1281  * \retval zero on success
1282  * \retval non-zero on failure
1283  */
1284 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
1285
1286 /*!
1287  * \brief Queue a control frame with payload
1288  *
1289  * \param chan channel to queue frame onto
1290  * \param control type of control frame
1291  * \param data pointer to payload data to be included in frame
1292  * \param datalen number of bytes of payload data
1293  *
1294  * \retval 0 success
1295  * \retval non-zero failure
1296  *
1297  * \details
1298  * The supplied payload data is copied into the frame, so the caller's copy
1299  * is not modified nor freed, and the resulting frame will retain a copy of
1300  * the data even if the caller frees their local copy.
1301  *
1302  * \note This method should be treated as a 'network transport'; in other
1303  * words, your frames may be transferred across an IAX2 channel to another
1304  * system, which may be a different endianness than yours. Because of this,
1305  * you should ensure that either your frames will never be expected to work
1306  * across systems, or that you always put your payload data into 'network byte
1307  * order' before calling this function.
1308  *
1309  * \note The channel does not need to be locked before calling this function.
1310  */
1311 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
1312                            const void *data, size_t datalen);
1313
1314 /*!
1315  * \brief Change channel name
1316  *
1317  * \pre Absolutely all channels _MUST_ be unlocked before calling this function.
1318  *
1319  * \param chan the channel to change the name of
1320  * \param newname the name to change to
1321  *
1322  * \return nothing
1323  *
1324  * \note this function must _NEVER_ be used when any channels are locked
1325  * regardless if it is the channel who's name is being changed or not because
1326  * it invalidates our channel container locking order... lock container first,
1327  * then the individual channels, never the other way around.
1328  */
1329 void ast_change_name(struct ast_channel *chan, const char *newname);
1330
1331 /*!
1332  * \brief Unlink and release reference to a channel
1333  *
1334  * This function will unlink the channel from the global channels container
1335  * if it is still there and also release the current reference to the channel.
1336  *
1337  * \return NULL, convenient for clearing invalid pointers
1338  * \note Absolutely _NO_ channel locks should be held before calling this function.
1339  *
1340  * \since 1.8
1341  */
1342 struct ast_channel *ast_channel_release(struct ast_channel *chan);
1343
1344 /*!
1345  * \brief Requests a channel
1346  *
1347  * \param type type of channel to request
1348  * \param request_cap Format capabilities for requested channel
1349  * \param requestor channel asking for data
1350  * \param addr destination of the call
1351  * \param cause Cause of failure
1352  *
1353  * \details
1354  * Request a channel of a given type, with addr as optional information used
1355  * by the low level module
1356  *
1357  * \retval NULL failure
1358  * \retval non-NULL channel on success
1359  */
1360 struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_channel *requestor, const char *addr, int *cause);
1361
1362 /*!
1363  * \brief Request a channel of a given type, with data as optional information used
1364  *        by the low level module and attempt to place a call on it
1365  *
1366  * \param type type of channel to request
1367  * \param cap format capabilities for requested channel
1368  * \param requestor channel asking for data
1369  * \param addr destination of the call
1370  * \param timeout maximum amount of time to wait for an answer
1371  * \param reason why unsuccessful (if unsuccessful)
1372  * \param cid_num Caller-ID Number
1373  * \param cid_name Caller-ID Name (ascii)
1374  *
1375  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
1376  * to know if the call was answered or not.
1377  */
1378 struct ast_channel *ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr,
1379         int timeout, int *reason, const char *cid_num, const char *cid_name);
1380
1381 /*!
1382  * \brief Request a channel of a given type, with data as optional information used
1383  * by the low level module and attempt to place a call on it
1384  * \param type type of channel to request
1385  * \param cap format capabilities for requested channel
1386  * \param requestor channel requesting data
1387  * \param addr destination of the call
1388  * \param timeout maximum amount of time to wait for an answer
1389  * \param reason why unsuccessful (if unsuccessful)
1390  * \param cid_num Caller-ID Number
1391  * \param cid_name Caller-ID Name (ascii)
1392  * \param oh Outgoing helper
1393  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
1394  * to know if the call was answered or not.
1395  */
1396 struct ast_channel *__ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *addr,
1397         int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
1398
1399 /*!
1400  * \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.
1401  * \param caller in channel that requested orig
1402  * \param orig channel being replaced by the call forward channel
1403  * \param timeout maximum amount of time to wait for setup of new forward channel
1404  * \param cap format capabilities for requested channel
1405  * \param oh outgoing helper used with original channel
1406  * \param outstate reason why unsuccessful (if uncuccessful)
1407  * \return Returns the forwarded call's ast_channel on success or NULL on failure
1408  */
1409 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);
1410
1411 /*!
1412  * \brief Register a channel technology (a new channel driver)
1413  * Called by a channel module to register the kind of channels it supports.
1414  * \param tech Structure defining channel technology or "type"
1415  * \return Returns 0 on success, -1 on failure.
1416  */
1417 int ast_channel_register(const struct ast_channel_tech *tech);
1418
1419 /*!
1420  * \brief Unregister a channel technology
1421  * \param tech Structure defining channel technology or "type" that was previously registered
1422  * \return No return value.
1423  */
1424 void ast_channel_unregister(const struct ast_channel_tech *tech);
1425
1426 /*!
1427  * \brief Get a channel technology structure by name
1428  * \param name name of technology to find
1429  * \return a pointer to the structure, or NULL if no matching technology found
1430  */
1431 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
1432
1433 /*!
1434  * \brief Hang up a channel
1435  * \note Absolutely _NO_ channel locks should be held before calling this function.
1436  * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
1437  * performs all stream stopping, etc, on the channel that needs to end.
1438  * chan is no longer valid after this call.
1439  * \param chan channel to hang up (NULL tolerant)
1440  * \return Nothing
1441  */
1442 void ast_hangup(struct ast_channel *chan);
1443
1444 /*!
1445  * \brief Softly hangup up a channel
1446  *
1447  * \param chan channel to be soft-hung-up
1448  * \param reason an AST_SOFTHANGUP_* reason code
1449  *
1450  * \details
1451  * Call the protocol layer, but don't destroy the channel structure
1452  * (use this if you are trying to
1453  * safely hangup a channel managed by another thread.
1454  *
1455  * \note The channel passed to this function does not need to be locked.
1456  *
1457  * \return Returns 0 regardless
1458  */
1459 int ast_softhangup(struct ast_channel *chan, int reason);
1460
1461 /*!
1462  * \brief Softly hangup up a channel (no channel lock)
1463  * \param chan channel to be soft-hung-up
1464  * \param reason an AST_SOFTHANGUP_* reason code
1465  */
1466 int ast_softhangup_nolock(struct ast_channel *chan, int reason);
1467
1468 /*!
1469  * \brief Clear a set of softhangup flags from a channel
1470  *
1471  * Never clear a softhangup flag from a channel directly.  Instead,
1472  * use this function.  This ensures that all aspects of the softhangup
1473  * process are aborted.
1474  *
1475  * \param chan the channel to clear the flag on
1476  * \param flag the flag or flags to clear
1477  *
1478  * \return Nothing.
1479  */
1480 void ast_channel_clear_softhangup(struct ast_channel *chan, int flag);
1481
1482 /*!
1483  * \brief Set the source of the hangup in this channel and it's bridge
1484  *
1485  * \param chan channel to set the field on
1486  * \param source a string describing the source of the hangup for this channel
1487  * \param force
1488  *
1489  * \note Absolutely _NO_ channel locks should be held before calling this function.
1490  *
1491  * \since 1.8
1492  *
1493  * Hangupsource is generally the channel name that caused the bridge to be
1494  * hung up, but it can also be other things such as "dialplan/agi"
1495  * This can then be logged in the CDR or CEL
1496  */
1497 void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);
1498
1499 /*! \brief Check to see if a channel is needing hang up
1500  * \param chan channel on which to check for hang up
1501  * This function determines if the channel is being requested to be hung up.
1502  * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
1503  */
1504 int ast_check_hangup(struct ast_channel *chan);
1505
1506 int ast_check_hangup_locked(struct ast_channel *chan);
1507
1508 /*!
1509  * \brief Lock the given channel, then request softhangup on the channel with the given causecode
1510  * \param chan channel on which to hang up
1511  * \param causecode cause code to use (Zero if don't use cause code)
1512  * \return Nothing
1513  */
1514 void ast_channel_softhangup_withcause_locked(struct ast_channel *chan, int causecode);
1515
1516 /*!
1517  * \brief Compare a offset with the settings of when to hang a channel up
1518  * \param chan channel on which to check for hang up
1519  * \param offset offset in seconds from current time
1520  * \return 1, 0, or -1
1521  * \details
1522  * This function compares a offset from current time with the absolute time
1523  * out on a channel (when to hang up). If the absolute time out on a channel
1524  * is earlier than current time plus the offset, it returns 1, if the two
1525  * time values are equal, it return 0, otherwise, it return -1.
1526  * \sa ast_channel_cmpwhentohangup_tv()
1527  * \version 1.6.1 deprecated function (only had seconds precision)
1528  */
1529 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1530
1531 /*!
1532  * \brief Compare a offset with the settings of when to hang a channel up
1533  * \param chan channel on which to check for hangup
1534  * \param offset offset in seconds and microseconds from current time
1535  * \return 1, 0, or -1
1536  * This function compares a offset from current time with the absolute time
1537  * out on a channel (when to hang up). If the absolute time out on a channel
1538  * is earlier than current time plus the offset, it returns 1, if the two
1539  * time values are equal, it return 0, otherwise, it return -1.
1540  * \since 1.6.1
1541  */
1542 int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1543
1544 /*!
1545  * \brief Set when to hang a channel up
1546  *
1547  * \param chan channel on which to check for hang up
1548  * \param offset offset in seconds relative to the current time of when to hang up
1549  *
1550  * \details
1551  * This function sets the absolute time out on a channel (when to hang up).
1552  *
1553  * \note This function does not require that the channel is locked before
1554  *       calling it.
1555  *
1556  * \return Nothing
1557  * \sa ast_channel_setwhentohangup_tv()
1558  * \version 1.6.1 deprecated function (only had seconds precision)
1559  */
1560 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1561
1562 /*!
1563  * \brief Set when to hang a channel up
1564  *
1565  * \param chan channel on which to check for hang up
1566  * \param offset offset in seconds and useconds relative to the current time of when to hang up
1567  *
1568  * This function sets the absolute time out on a channel (when to hang up).
1569  *
1570  * \note This function does not require that the channel is locked before
1571  * calling it.
1572  *
1573  * \return Nothing
1574  * \since 1.6.1
1575  */
1576 void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1577
1578 /*!
1579  * \brief Answer a channel
1580  *
1581  * \param chan channel to answer
1582  *
1583  * \details
1584  * This function answers a channel and handles all necessary call
1585  * setup functions.
1586  *
1587  * \note The channel passed does not need to be locked, but is locked
1588  * by the function when needed.
1589  *
1590  * \note This function will wait up to 500 milliseconds for media to
1591  * arrive on the channel before returning to the caller, so that the
1592  * caller can properly assume the channel is 'ready' for media flow.
1593  *
1594  * \retval 0 on success
1595  * \retval non-zero on failure
1596  */
1597 int ast_answer(struct ast_channel *chan);
1598
1599 /*!
1600  * \brief Answer a channel, if it's not already answered.
1601  *
1602  * \param chan channel to answer
1603  *
1604  * \details See ast_answer()
1605  *
1606  * \retval 0 on success
1607  * \retval non-zero on failure
1608  */
1609 int ast_auto_answer(struct ast_channel *chan);
1610
1611 /*!
1612  * \brief Answer a channel
1613  *
1614  * \param chan channel to answer
1615  *
1616  * This function answers a channel and handles all necessary call
1617  * setup functions.
1618  *
1619  * \note The channel passed does not need to be locked, but is locked
1620  * by the function when needed.
1621  *
1622  * \note Unlike ast_answer(), this function will not wait for media
1623  * flow to begin. The caller should be careful before sending media
1624  * to the channel before incoming media arrives, as the outgoing
1625  * media may be lost.
1626  *
1627  * \retval 0 on success
1628  * \retval non-zero on failure
1629  */
1630 int ast_raw_answer(struct ast_channel *chan);
1631
1632 /*!
1633  * \brief Answer a channel, with a selectable delay before returning
1634  *
1635  * \param chan channel to answer
1636  * \param delay maximum amount of time to wait for incoming media
1637  *
1638  * This function answers a channel and handles all necessary call
1639  * setup functions.
1640  *
1641  * \note The channel passed does not need to be locked, but is locked
1642  * by the function when needed.
1643  *
1644  * \note This function will wait up to 'delay' milliseconds for media to
1645  * arrive on the channel before returning to the caller, so that the
1646  * caller can properly assume the channel is 'ready' for media flow. If
1647  * 'delay' is less than 500, the function will wait up to 500 milliseconds.
1648  *
1649  * \retval 0 on success
1650  * \retval non-zero on failure
1651  */
1652 int __ast_answer(struct ast_channel *chan, unsigned int delay);
1653
1654 /*!
1655  * \brief Execute a Gosub call on the channel before a call is placed.
1656  * \since 11.0
1657  *
1658  * \details
1659  * This is called between ast_request() and ast_call() to
1660  * execute a predial routine on the newly created channel.
1661  *
1662  * \param chan Channel to execute Gosub.
1663  * \param sub_args Gosub application parameter string.
1664  *
1665  * \note Absolutely _NO_ channel locks should be held before calling this function.
1666  *
1667  * \retval 0 on success.
1668  * \retval -1 on error.
1669  */
1670 int ast_pre_call(struct ast_channel *chan, const char *sub_args);
1671
1672 /*!
1673  * \brief Make a call
1674  * \note Absolutely _NO_ channel locks should be held before calling this function.
1675  * \param chan which channel to make the call on
1676  * \param addr destination of the call
1677  * \param timeout time to wait on for connect (Doesn't seem to be used.)
1678  * \details
1679  * Place a call, take no longer than timeout ms.
1680  * \retval 0 on success
1681  * \retval -1 on failure
1682  */
1683 int ast_call(struct ast_channel *chan, const char *addr, int timeout);
1684
1685 /*!
1686  * \brief Indicates condition of channel
1687  * \note Absolutely _NO_ channel locks should be held before calling this function.
1688  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
1689  * \param chan channel to change the indication
1690  * \param condition which condition to indicate on the channel
1691  * \return Returns 0 on success, -1 on failure
1692  */
1693 int ast_indicate(struct ast_channel *chan, int condition);
1694
1695 /*!
1696  * \brief Indicates condition of channel, with payload
1697  * \note Absolutely _NO_ channel locks should be held before calling this function.
1698  * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
1699  * \param chan channel to change the indication
1700  * \param condition which condition to indicate on the channel
1701  * \param data pointer to payload data
1702  * \param datalen size of payload data
1703  * \return Returns 0 on success, -1 on failure
1704  */
1705 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1706
1707 /* Misc stuff ------------------------------------------------ */
1708
1709 /*!
1710  * \brief Wait for input on a channel
1711  * \param chan channel to wait on
1712  * \param ms length of time to wait on the channel
1713  * \details
1714  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
1715  * \retval < 0 on failure
1716  * \retval 0 if nothing ever arrived
1717  * \retval the # of ms remaining otherwise
1718  */
1719 int ast_waitfor(struct ast_channel *chan, int ms);
1720
1721 /*!
1722  * \brief Should we keep this frame for later?
1723  *
1724  * There are functions such as ast_safe_sleep which will
1725  * service a channel to ensure that it does not have a
1726  * large backlog of queued frames. When this happens,
1727  * we want to hold on to specific frame types and just drop
1728  * others. This function will tell if the frame we just
1729  * read should be held onto.
1730  *
1731  * \param frame The frame we just read
1732  * \retval 1 frame should be kept
1733  * \retval 0 frame should be dropped
1734  */
1735 int ast_is_deferrable_frame(const struct ast_frame *frame);
1736
1737 /*!
1738  * \brief Wait for a specified amount of time, looking for hangups
1739  * \param chan channel to wait for
1740  * \param ms length of time in milliseconds to sleep. This should never be less than zero.
1741  * \details
1742  * Waits for a specified amount of time, servicing the channel as required.
1743  * \return returns -1 on hangup, otherwise 0.
1744  */
1745 int ast_safe_sleep(struct ast_channel *chan, int ms);
1746
1747 /*!
1748  * \brief Wait for a specified amount of time, looking for hangups and a condition argument
1749  * \param chan channel to wait for
1750  * \param ms length of time in milliseconds to sleep.
1751  * \param cond a function pointer for testing continue condition
1752  * \param data argument to be passed to the condition test function
1753  * \return returns -1 on hangup, otherwise 0.
1754  * \details
1755  * Waits for a specified amount of time, servicing the channel as required. If cond
1756  * returns 0, this function returns.
1757  */
1758 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
1759
1760 /*!
1761  * \brief Waits for activity on a group of channels
1762  * \param chan an array of pointers to channels
1763  * \param n number of channels that are to be waited upon
1764  * \param fds an array of fds to wait upon
1765  * \param nfds the number of fds to wait upon
1766  * \param exception exception flag
1767  * \param outfd fd that had activity on it
1768  * \param ms how long the wait was
1769  * \details
1770  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
1771  * file descriptors.
1772  * \return Returns the channel with activity, or NULL on error or if an FD
1773  * came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
1774  * will be -1
1775  */
1776 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
1777         int *fds, int nfds, int *exception, int *outfd, int *ms);
1778
1779 /*!
1780  * \brief Waits for input on a group of channels
1781  * Wait for input on an array of channels for a given # of milliseconds.
1782  * \return Return channel with activity, or NULL if none has activity.
1783  * \param chan an array of pointers to channels
1784  * \param n number of channels that are to be waited upon
1785  * \param ms time "ms" is modified in-place, if applicable
1786  */
1787 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
1788
1789 /*!
1790  * \brief Waits for input on an fd
1791  * \note This version works on fd's only.  Be careful with it.
1792  */
1793 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
1794
1795
1796 /*!
1797  * \brief Reads a frame
1798  * \param chan channel to read a frame from
1799  * \return Returns a frame, or NULL on error.  If it returns NULL, you
1800  * best just stop reading frames and assume the channel has been
1801  * disconnected.
1802  */
1803 struct ast_frame *ast_read(struct ast_channel *chan);
1804
1805 /*!
1806  * \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
1807  * \param chan channel to read a frame from
1808  * \return  Returns a frame, or NULL on error.  If it returns NULL, you
1809  * best just stop reading frames and assume the channel has been
1810  * disconnected.
1811  * \note Audio is replaced with AST_FRAME_NULL to avoid
1812  * transcode when the resulting audio is not necessary.
1813  */
1814 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
1815
1816 /*!
1817  * \brief Write a frame to a channel
1818  * This function writes the given frame to the indicated channel.
1819  * \param chan destination channel of the frame
1820  * \param frame frame that will be written
1821  * \return It returns 0 on success, -1 on failure.
1822  */
1823 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
1824
1825 /*!
1826  * \brief Write video frame to a channel
1827  * This function writes the given frame to the indicated channel.
1828  * \param chan destination channel of the frame
1829  * \param frame frame that will be written
1830  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1831  */
1832 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
1833
1834 /*!
1835  * \brief Write text frame to a channel
1836  * This function writes the given frame to the indicated channel.
1837  * \param chan destination channel of the frame
1838  * \param frame frame that will be written
1839  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1840  */
1841 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
1842
1843 /*! \brief Send empty audio to prime a channel driver */
1844 int ast_prod(struct ast_channel *chan);
1845
1846 /*!
1847  * \brief Sets read format on channel chan from capabilities
1848  * Set read format for channel to whichever component of "format" is best.
1849  * \param chan channel to change
1850  * \param formats new formats to pick from for reading
1851  * \return Returns 0 on success, -1 on failure
1852  */
1853 int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
1854
1855 /*!
1856  * \brief Sets read format on channel chan
1857  * \param chan channel to change
1858  * \param format format to set for reading
1859  * \return Returns 0 on success, -1 on failure
1860  */
1861 int ast_set_read_format(struct ast_channel *chan, struct ast_format *format);
1862
1863 /*!
1864  * \brief Sets read format on channel chan by id
1865  * \param chan channel to change
1866  * \param id format id to set for reading, only used for formats without attributes
1867  * \return Returns 0 on success, -1 on failure
1868  */
1869 int ast_set_read_format_by_id(struct ast_channel *chan, enum ast_format_id id);
1870
1871 /*!
1872  * \brief Sets write format on channel chan
1873  * Set write format for channel to whichever component of "format" is best.
1874  * \param chan channel to change
1875  * \param formats new formats to pick from for writing
1876  * \return Returns 0 on success, -1 on failure
1877  */
1878 int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
1879
1880 /*!
1881  * \brief Sets write format on channel chan
1882  * \param chan channel to change
1883  * \param format format to set for writing
1884  * \return Returns 0 on success, -1 on failure
1885  */
1886 int ast_set_write_format(struct ast_channel *chan, struct ast_format *format);
1887
1888 /*!
1889  * \brief Sets write format on channel chan
1890  * \param chan channel to change
1891  * \param id format id to set for writing, only used for formats without attributes
1892  * \return Returns 0 on success, -1 on failure
1893  */
1894 int ast_set_write_format_by_id(struct ast_channel *chan, enum ast_format_id id);
1895
1896 /*!
1897  * \brief Sends text to a channel
1898  *
1899  * \param chan channel to act upon
1900  * \param text string of text to send on the channel
1901  *
1902  * \details
1903  * Write text to a display on a channel
1904  *
1905  * \note The channel does not need to be locked before calling this function.
1906  *
1907  * \retval 0 on success
1908  * \retval -1 on failure
1909  */
1910 int ast_sendtext(struct ast_channel *chan, const char *text);
1911
1912 /*!
1913  * \brief Receives a text character from a channel
1914  * \param chan channel to act upon
1915  * \param timeout timeout in milliseconds (0 for infinite wait)
1916  * \details
1917  * Read a char of text from a channel
1918  * \return 0 on success, -1 on failure
1919  */
1920 int ast_recvchar(struct ast_channel *chan, int timeout);
1921
1922 /*!
1923  * \brief Send a DTMF digit to a channel.
1924  * \param chan channel to act upon
1925  * \param digit the DTMF digit to send, encoded in ASCII
1926  * \param duration the duration of the digit ending in ms
1927  * \return 0 on success, -1 on failure
1928  */
1929 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
1930
1931 /*!
1932  * \brief Send a DTMF digit to a channel.
1933  * \param chan channel to act upon
1934  * \param digit the DTMF digit to send, encoded in ASCII
1935  * \return 0 on success, -1 on failure
1936  */
1937 int ast_senddigit_begin(struct ast_channel *chan, char digit);
1938
1939 /*!
1940  * \brief Send a DTMF digit to a channel.
1941  * \param chan channel to act upon
1942  * \param digit the DTMF digit to send, encoded in ASCII
1943  * \param duration the duration of the digit ending in ms
1944  * \return Returns 0 on success, -1 on failure
1945  */
1946 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
1947
1948 /*!
1949  * \brief Receives a text string from a channel
1950  * Read a string of text from a channel
1951  * \param chan channel to act upon
1952  * \param timeout timeout in milliseconds (0 for infinite wait)
1953  * \return the received text, or NULL to signify failure.
1954  */
1955 char *ast_recvtext(struct ast_channel *chan, int timeout);
1956
1957 /*!
1958  * \brief Waits for a digit
1959  * \param c channel to wait for a digit on
1960  * \param ms how many milliseconds to wait (<0 for indefinite).
1961  * \return Returns <0 on error, 0 on no entry, and the digit on success.
1962  */
1963 int ast_waitfordigit(struct ast_channel *c, int ms);
1964
1965 /*!
1966  * \brief Wait for a digit
1967  * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1968  * \param c channel to wait for a digit on
1969  * \param ms how many milliseconds to wait (<0 for indefinite).
1970  * \param audiofd audio file descriptor to write to if audio frames are received
1971  * \param ctrlfd control file descriptor to monitor for reading
1972  * \return Returns 1 if ctrlfd becomes available
1973  */
1974 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
1975
1976 /*!
1977  * \brief Reads multiple digits
1978  * \param c channel to read from
1979  * \param s string to read in to.  Must be at least the size of your length
1980  * \param len how many digits to read (maximum)
1981  * \param timeout how long to timeout between digits
1982  * \param rtimeout timeout to wait on the first digit
1983  * \param enders digits to end the string
1984  * \details
1985  * Read in a digit string "s", max length "len", maximum timeout between
1986  * digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
1987  * for the first digit.
1988  * \return Returns 0 on normal return, or 1 on a timeout.  In the case of
1989  * a timeout, any digits that were read before the timeout will still be available in s.
1990  * RETURNS 2 in full version when ctrlfd is available, NOT 1
1991  */
1992 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
1993 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
1994
1995 /*! \brief Report DTMF on channel 0 */
1996 #define AST_BRIDGE_DTMF_CHANNEL_0               (1 << 0)
1997 /*! \brief Report DTMF on channel 1 */
1998 #define AST_BRIDGE_DTMF_CHANNEL_1               (1 << 1)
1999 /*! \brief Return all voice frames on channel 0 */
2000 #define AST_BRIDGE_REC_CHANNEL_0                (1 << 2)
2001 /*! \brief Return all voice frames on channel 1 */
2002 #define AST_BRIDGE_REC_CHANNEL_1                (1 << 3)
2003 /*! \brief Ignore all signal frames except NULL */
2004 #define AST_BRIDGE_IGNORE_SIGS                  (1 << 4)
2005
2006
2007 /*!
2008  * \brief Makes two channel formats compatible
2009  * \param c0 first channel to make compatible
2010  * \param c1 other channel to make compatible
2011  * \details
2012  * Set two channels to compatible formats -- call before ast_channel_bridge in general.
2013  * \return Returns 0 on success and -1 if it could not be done
2014  */
2015 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
2016
2017 /*!
2018  * \brief Bridge two channels together (early)
2019  * \param c0 first channel to bridge
2020  * \param c1 second channel to bridge
2021  * \details
2022  * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
2023  * \return Returns 0 on success and -1 if it could not be done
2024  */
2025 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
2026
2027 /*!
2028  * \brief Weird function made for call transfers
2029  *
2030  * \param original channel to make a copy of
2031  * \param clone copy of the original channel
2032  *
2033  * \details
2034  * This is a very strange and freaky function used primarily for transfer.  Suppose that
2035  * "original" and "clone" are two channels in random situations.  This function takes
2036  * the guts out of "clone" and puts them into the "original" channel, then alerts the
2037  * channel driver of the change, asking it to fixup any private information (like the
2038  * p->owner pointer) that is affected by the change.  The physical layer of the original
2039  * channel is hung up.
2040  *
2041  * \note Neither channel passed here should be locked before
2042  * calling this function.  This function performs deadlock
2043  * avoidance involving these two channels.
2044  */
2045 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
2046
2047 /*!
2048  * \brief Gives the string form of a given cause code.
2049  *
2050  * \param state cause to get the description of
2051  * \return the text form of the binary cause code given
2052  */
2053 const char *ast_cause2str(int state) attribute_pure;
2054
2055 /*!
2056  * \brief Convert the string form of a cause code to a number
2057  *
2058  * \param name string form of the cause
2059  * \return the cause code
2060  */
2061 int ast_str2cause(const char *name) attribute_pure;
2062
2063 /*!
2064  * \brief Gives the string form of a given channel state
2065  *
2066  * \param ast_channel_state state to get the name of
2067  * \return the text form of the binary state given
2068  */
2069 const char *ast_state2str(enum ast_channel_state);
2070
2071 /*!
2072  * \brief Gives the string form of a given transfer capability
2073  *
2074  * \param transfercapability transfer capability to get the name of
2075  * \return the text form of the binary transfer capability
2076  */
2077 char *ast_transfercapability2str(int transfercapability) attribute_const;
2078
2079 /*
2080  * Options: Some low-level drivers may implement "options" allowing fine tuning of the
2081  * low level channel.  See frame.h for options.  Note that many channel drivers may support
2082  * none or a subset of those features, and you should not count on this if you want your
2083  * asterisk application to be portable.  They're mainly useful for tweaking performance
2084  */
2085
2086 /*!
2087  * \brief Sets an option on a channel
2088  *
2089  * \param channel channel to set options on
2090  * \param option option to change
2091  * \param data data specific to option
2092  * \param datalen length of the data
2093  * \param block blocking or not
2094  * \details
2095  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
2096  * \return 0 on success and -1 on failure
2097  */
2098 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
2099
2100 /*!
2101  * \brief Pick the best codec
2102  *
2103  * \param cap capabilities to pick best codec out of
2104  * \param result stucture to store the best codec in.
2105  * \retval on success, pointer to result structure
2106  * \retval on failure, NULL
2107  */
2108 struct ast_format *ast_best_codec(struct ast_format_cap *cap, struct ast_format *result);
2109
2110
2111 /*!
2112  * \brief Checks the value of an option
2113  *
2114  * Query the value of an option
2115  * Works similarly to setoption except only reads the options.
2116  */
2117 int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
2118
2119 /*!
2120  * \brief Checks for HTML support on a channel
2121  * \return 0 if channel does not support HTML or non-zero if it does
2122  */
2123 int ast_channel_supports_html(struct ast_channel *channel);
2124
2125 /*!
2126  * \brief Sends HTML on given channel
2127  * Send HTML or URL on link.
2128  * \return 0 on success or -1 on failure
2129  */
2130 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
2131
2132 /*!
2133  * \brief Sends a URL on a given link
2134  * Send URL on link.
2135  * \return 0 on success or -1 on failure
2136  */
2137 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
2138
2139 /*!
2140  * \brief Defers DTMF so that you only read things like hangups and audio.
2141  * \return non-zero if channel was already DTMF-deferred or
2142  * 0 if channel is just now being DTMF-deferred
2143  */
2144 int ast_channel_defer_dtmf(struct ast_channel *chan);
2145
2146 /*! Undo defer.  ast_read will return any DTMF characters that were queued */
2147 void ast_channel_undefer_dtmf(struct ast_channel *chan);
2148
2149 /*! Initiate system shutdown -- prevents new channels from being allocated.
2150  * \param hangup  If "hangup" is non-zero, all existing channels will receive soft
2151  *  hangups */
2152 void ast_begin_shutdown(int hangup);
2153
2154 /*! Cancels an existing shutdown and returns to normal operation */
2155 void ast_cancel_shutdown(void);
2156
2157 /*! \return number of channels available for lookup */
2158 int ast_active_channels(void);
2159
2160 /*! \return the number of channels not yet destroyed */
2161 int ast_undestroyed_channels(void);
2162
2163 /*! \return non-zero if Asterisk is being shut down */
2164 int ast_shutting_down(void);
2165
2166 /*! Activate a given generator */
2167 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
2168
2169 /*! Deactivate an active generator */
2170 void ast_deactivate_generator(struct ast_channel *chan);
2171
2172 /*!
2173  * \since 12
2174  * \brief Obtain how long the channel since the channel was created
2175  *
2176  * \param chan The channel object
2177  *
2178  * \retval 0 if the time value cannot be computed (or you called this really fast)
2179  * \retval The number of seconds the channel has been up
2180  */
2181 int ast_channel_get_duration(struct ast_channel *chan);
2182
2183 /*!
2184  * \since 12
2185  * \brief Obtain how long it has been since the channel was answered
2186  *
2187  * \param chan The channel object
2188  *
2189  * \retval 0 if the channel isn't answered (or you called this really fast)
2190  * \retval The number of seconds the channel has been up
2191  */
2192 int ast_channel_get_up_time(struct ast_channel *chan);
2193
2194 /*!
2195  * \brief Set caller ID number, name and ANI and generate AMI event.
2196  *
2197  * \note Use ast_channel_set_caller() and ast_channel_set_caller_event() instead.
2198  * \note The channel does not need to be locked before calling this function.
2199  */
2200 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
2201
2202 /*!
2203  * \brief Set the caller id information in the Asterisk channel
2204  * \since 1.8
2205  *
2206  * \param chan Asterisk channel to set caller id information
2207  * \param caller Caller id information
2208  * \param update What caller information to update.  NULL if all.
2209  *
2210  * \return Nothing
2211  *
2212  * \note The channel does not need to be locked before calling this function.
2213  */
2214 void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
2215
2216 /*!
2217  * \brief Set the caller id information in the Asterisk channel and generate an AMI event
2218  * if the caller id name or number changed.
2219  * \since 1.8
2220  *
2221  * \param chan Asterisk channel to set caller id information
2222  * \param caller Caller id information
2223  * \param update What caller information to update.  NULL if all.
2224  *
2225  * \return Nothing
2226  *
2227  * \note The channel does not need to be locked before calling this function.
2228  */
2229 void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
2230
2231 /*! Set the file descriptor on the channel */
2232 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
2233
2234 /*! Add a channel to an optimized waitfor */
2235 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
2236
2237 /*! Delete a channel from an optimized waitfor */
2238 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
2239
2240 /*! Start a tone going */
2241 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
2242 /*! Stop a tone from playing */
2243 void ast_tonepair_stop(struct ast_channel *chan);
2244 /*! Play a tone pair for a given amount of time */
2245 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
2246
2247 /*!
2248  * \brief Automatically service a channel for us...
2249  *
2250  * \retval 0 success
2251  * \retval -1 failure, or the channel is already being autoserviced
2252  */
2253 int ast_autoservice_start(struct ast_channel *chan);
2254
2255 /*!
2256  * \brief Stop servicing a channel for us...
2257  *
2258  * \note if chan is locked prior to calling ast_autoservice_stop, it
2259  * is likely that there will be a deadlock between the thread that calls
2260  * ast_autoservice_stop and the autoservice thread. It is important
2261  * that chan is not locked prior to this call
2262  *
2263  * \param chan
2264  * \retval 0 success
2265  * \retval -1 error, or the channel has been hungup
2266  */
2267 int ast_autoservice_stop(struct ast_channel *chan);
2268
2269 /*!
2270  * \brief Put chan into autoservice while hanging up peer.
2271  * \since 11.0
2272  *
2273  * \param chan Chan to put into autoservice.
2274  * \param peer Chan to run hangup handlers and hangup.
2275  *
2276  * \return Nothing
2277  */
2278 void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer);
2279
2280 /*!
2281  * \brief Ignore certain frame types
2282  * \note Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames
2283  * while a channel is in autoservice and queue them up when taken out of
2284  * autoservice.  When this is not desireable, this API may be used to
2285  * cause the channel to ignore those frametypes after the channel is put
2286  * into autoservice, but before autoservice is stopped.
2287  * \retval 0 success
2288  * \retval -1 channel is not in autoservice
2289  */
2290 int ast_autoservice_ignore(struct ast_channel *chan, enum ast_frame_type ftype);
2291
2292 /*!
2293  * \brief Enable or disable timer ticks for a channel
2294  *
2295  * \param c channel
2296  * \param rate number of timer ticks per second
2297  * \param func callback function
2298  * \param data
2299  *
2300  * \details
2301  * If timers are supported, force a scheduled expiration on the
2302  * timer fd, at which point we call the callback function / data
2303  *
2304  * \note Call this function with a rate of 0 to turn off the timer ticks
2305  *
2306  * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
2307  */
2308 int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
2309
2310 /*!
2311  * \brief Transfer a channel (if supported).
2312  * \retval -1 on error
2313  * \retval 0 if not supported
2314  * \retval 1 if supported and requested
2315  * \param chan current channel
2316  * \param dest destination extension for transfer
2317  */
2318 int ast_transfer(struct ast_channel *chan, char *dest);
2319
2320 /*!
2321  * \brief Start masquerading a channel
2322  * \note absolutely _NO_ channel locks should be held before calling this function.
2323  * \details
2324  * XXX This is a seriously whacked out operation.  We're essentially putting the guts of
2325  *     the clone channel into the original channel.  Start by killing off the original
2326  *     channel's backend.   I'm not sure we're going to keep this function, because
2327  *     while the features are nice, the cost is very high in terms of pure nastiness. XXX
2328  * \param chan Channel to masquerade
2329  */
2330 void ast_do_masquerade(struct ast_channel *chan);
2331
2332 /*!
2333  * \brief Inherits channel variable from parent to child channel
2334  * \param parent Parent channel
2335  * \param child Child channel
2336  *
2337  * \details
2338  * Scans all channel variables in the parent channel, looking for those
2339  * that should be copied into the child channel.
2340  * Variables whose names begin with a single '_' are copied into the
2341  * child channel with the prefix removed.
2342  * Variables whose names begin with '__' are copied into the child
2343  * channel with their names unchanged.
2344  */
2345 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
2346
2347 /*!
2348  * \brief adds a list of channel variables to a channel
2349  * \param chan the channel
2350  * \param vars a linked list of variables
2351  *
2352  * \details
2353  * Variable names can be for a regular channel variable or a dialplan function
2354  * that has the ability to be written to.
2355  */
2356 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
2357
2358 /*!
2359  * \brief An opaque 'object' structure use by silence generators on channels.
2360  */
2361 struct ast_silence_generator;
2362
2363 /*!
2364  * \brief Starts a silence generator on the given channel.
2365  * \param chan The channel to generate silence on
2366  * \return An ast_silence_generator pointer, or NULL if an error occurs
2367  *
2368  * \details
2369  * This function will cause SLINEAR silence to be generated on the supplied
2370  * channel until it is disabled; if the channel cannot be put into SLINEAR
2371  * mode then the function will fail.
2372  *
2373  * \note
2374  * The pointer returned by this function must be preserved and passed to
2375  * ast_channel_stop_silence_generator when you wish to stop the silence
2376  * generation.
2377  */
2378 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
2379
2380 /*!
2381  * \brief Stops a previously-started silence generator on the given channel.
2382  * \param chan The channel to operate on
2383  * \param state The ast_silence_generator pointer return by a previous call to
2384  * ast_channel_start_silence_generator.
2385  * \return nothing
2386  *
2387  * \details
2388  * This function will stop the operating silence generator and return the channel
2389  * to its previous write format.
2390  */
2391 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
2392
2393 /*!
2394  * \brief Check if the channel can run in internal timing mode.
2395  * \param chan The channel to check
2396  * \return boolean
2397  *
2398  * \details
2399  * This function will return 1 if internal timing is enabled and the timing
2400  * device is available.
2401  */
2402 int ast_internal_timing_enabled(struct ast_channel *chan);
2403
2404 /* Misc. functions below */
2405
2406 /*!
2407  * \brief if fd is a valid descriptor, set *pfd with the descriptor
2408  * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
2409  * return value to the index into the array)
2410  */
2411 static inline int ast_add_fd(struct pollfd *pfd, int fd)
2412 {
2413         pfd->fd = fd;
2414         pfd->events = POLLIN | POLLPRI;
2415         return fd >= 0;
2416 }
2417
2418 /*! \brief Helper function for migrating select to poll */
2419 static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
2420 {
2421         int x;
2422         int dummy = 0;
2423
2424         if (fd < 0)
2425                 return 0;
2426         if (!start)
2427                 start = &dummy;
2428         for (x = *start; x < maximum; x++)
2429                 if (pfds[x].fd == fd) {
2430                         if (x == *start)
2431                                 (*start)++;
2432                         return pfds[x].revents;
2433                 }
2434         return 0;
2435 }
2436
2437 /*! \brief Retrieves the current T38 state of a channel */
2438 static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
2439 {
2440         enum ast_t38_state state = T38_STATE_UNAVAILABLE;
2441         int datalen = sizeof(state);
2442
2443         ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
2444
2445         return state;
2446 }
2447
2448 #define CHECK_BLOCKING(c) do {   \
2449         if (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING)) {\
2450                 ast_debug(1, "Thread %p is blocking '%s', already blocked by thread %p in procedure %s\n", \
2451                         (void *) pthread_self(), ast_channel_name(c), (void *) ast_channel_blocker(c), ast_channel_blockproc(c)); \
2452         } else { \
2453                 ast_channel_blocker_set((c), pthread_self()); \
2454                 ast_channel_blockproc_set((c), __PRETTY_FUNCTION__); \
2455                 ast_set_flag(ast_channel_flags(c), AST_FLAG_BLOCKING); \
2456         } } while (0)
2457
2458 ast_group_t ast_get_group(const char *s);
2459
2460 /*! \brief Print call and pickup groups into buffer */
2461 char *ast_print_group(char *buf, int buflen, ast_group_t group);
2462
2463 /*! \brief Opaque struct holding a namedgroups set, i.e. a set of group names */
2464 struct ast_namedgroups;
2465
2466 /*! \brief Create an ast_namedgroups set with group names from comma separated string */
2467 struct ast_namedgroups *ast_get_namedgroups(const char *s);
2468 struct ast_namedgroups *ast_unref_namedgroups(struct ast_namedgroups *groups);
2469 struct ast_namedgroups *ast_ref_namedgroups(struct ast_namedgroups *groups);
2470 /*! \brief Return TRUE if group a and b contain at least one common groupname */
2471 int ast_namedgroups_intersect(struct ast_namedgroups *a, struct ast_namedgroups *b);
2472
2473 /*! \brief Print named call groups and named pickup groups */
2474 char *ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *groups);
2475
2476 /*!
2477  * \brief Convert enum channelreloadreason to text string for manager event
2478  * \param reason The reason for reload (manager, cli, start etc)
2479  */
2480 const char *channelreloadreason2txt(enum channelreloadreason reason);
2481
2482 /*! \brief return an ast_variable list of channeltypes */
2483 struct ast_variable *ast_channeltype_list(void);
2484
2485 /*!
2486  * \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
2487  * \param reason  The integer argument, usually taken from AST_CONTROL_ macros
2488  * \return char pointer explaining the code
2489  */
2490 const char *ast_channel_reason2str(int reason);
2491
2492 /*! \brief channel group info */
2493 struct ast_group_info {
2494         struct ast_channel *chan;
2495         char *category;
2496         char *group;
2497         AST_LIST_ENTRY(ast_group_info) group_list;
2498 };
2499
2500 #define ast_channel_lock(chan) ao2_lock(chan)
2501 #define ast_channel_unlock(chan) ao2_unlock(chan)
2502 #define ast_channel_trylock(chan) ao2_trylock(chan)
2503
2504 /*!
2505  * \brief Lock two channels.
2506  */
2507 #define ast_channel_lock_both(chan1, chan2) do { \
2508                 ast_channel_lock(chan1); \
2509                 while (ast_channel_trylock(chan2)) { \
2510                         ast_channel_unlock(chan1); \
2511                         sched_yield(); \
2512                         ast_channel_lock(chan1); \
2513                 } \
2514         } while (0)
2515
2516 /*!
2517  * \brief Increase channel reference count
2518  *
2519  * \param c the channel
2520  *
2521  * \retval c always
2522  *
2523  * \since 1.8
2524  */
2525 #define ast_channel_ref(c) ({ ao2_ref(c, +1); (c); })
2526
2527 /*!
2528  * \brief Decrease channel reference count
2529  *
2530  * \param c the channel
2531  *
2532  * \retval NULL always
2533  *
2534  * \since 1.8
2535  */
2536 #define ast_channel_unref(c) ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })
2537
2538 /*!
2539  * \brief Cleanup a channel reference
2540  *
2541  * \param c the channel (NULL tolerant)
2542  *
2543  * \retval NULL always
2544  *
2545  * \since 12.0.0
2546  */
2547 #define ast_channel_cleanup(c) ({ ao2_cleanup(c); (struct ast_channel *) (NULL); })
2548
2549 /*! Channel Iterating @{ */
2550
2551 /*!
2552  * \brief A channel iterator
2553  *
2554  * This is an opaque type.
2555  */
2556 struct ast_channel_iterator;
2557
2558 /*!
2559  * \brief Destroy a channel iterator
2560  *
2561  * \param i the itereator to destroy
2562  *
2563  * \details
2564  * This function is used to destroy a channel iterator that was retrieved by
2565  * using one of the channel_iterator_xxx_new() functions.
2566  *
2567  * \return NULL, for convenience to clear out the pointer to the iterator that
2568  * was just destroyed.
2569  *
2570  * \since 1.8
2571  */
2572 struct ast_channel_iterator *ast_channel_iterator_destroy(struct ast_channel_iterator *i);
2573
2574 /*!
2575  * \brief Create a new channel iterator based on extension
2576  *
2577  * \param exten The extension that channels must be in
2578  * \param context The context that channels must be in
2579  *
2580  * \details
2581  * After creating an iterator using this function, the ast_channel_iterator_next()
2582  * function can be used to iterate through all channels that are currently
2583  * in the specified context and extension.
2584  *
2585  * \note You must call ast_channel_iterator_destroy() when done.
2586  *
2587  * \retval NULL on failure
2588  * \retval a new channel iterator based on the specified parameters
2589  *
2590  * \since 1.8
2591  */
2592 struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context);
2593
2594 /*!
2595  * \brief Create a new channel iterator based on name
2596  *
2597  * \param name channel name or channel uniqueid to match
2598  * \param name_len number of characters in the channel name to match on.  This
2599  *      would be used to match based on name prefix.  If matching on the full
2600  *      channel name is desired, then this parameter should be 0.
2601  *
2602  * \details
2603  * After creating an iterator using this function, the ast_channel_iterator_next()
2604  * function can be used to iterate through all channels that exist that have
2605  * the specified name or name prefix.
2606  *
2607  * \note You must call ast_channel_iterator_destroy() when done.
2608  *
2609  * \retval NULL on failure
2610  * \retval a new channel iterator based on the specified parameters
2611  *
2612  * \since 1.8
2613  */
2614 struct ast_channel_iterator *ast_channel_iterator_by_name_new(const char *name, size_t name_len);
2615
2616 /*!
2617  * \brief Create a new channel iterator
2618  *
2619  * \details
2620  * After creating an iterator using this function, the ast_channel_iterator_next()
2621  * function can be used to iterate through all channels that exist.
2622  *
2623  * \note You must call ast_channel_iterator_destroy() when done.
2624  *
2625  * \retval NULL on failure
2626  * \retval a new channel iterator
2627  *
2628  * \since 1.8
2629  */
2630 struct ast_channel_iterator *ast_channel_iterator_all_new(void);
2631
2632 /*!
2633  * \brief Get the next channel for a channel iterator
2634  *
2635  * \param i the channel iterator that was created using one of the
2636  *  channel_iterator_xxx_new() functions.
2637  *
2638  * \details
2639  * This function should be used to iterate through all channels that match a
2640  * specified set of parameters that were provided when the iterator was created.
2641  *
2642  * \retval the next channel that matches the parameters used when the iterator
2643  *         was created.
2644  * \retval NULL, if no more channels match the iterator parameters.
2645  *
2646  * \since 1.8
2647  */
2648 struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);
2649
2650 /*! @} End channel iterator definitions. */
2651
2652 /*!
2653  * \brief Call a function with every active channel
2654  *
2655  * \details
2656  * This function executes a callback one time for each active channel on the
2657  * system.  The channel is provided as an argument to the function.
2658  *
2659  * \note Absolutely _NO_ channel locks should be held before calling this function.
2660  * \since 1.8
2661  */
2662 struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
2663                 void *data, int ao2_flags);
2664
2665 /*! @{ Channel search functions */
2666
2667 /*!
2668  * \brief Find a channel by name
2669  *
2670  * \param name the name or uniqueid of the channel to search for
2671  *
2672  * \details
2673  * Find a channel that has the same name as the provided argument.
2674  *
2675  * \retval a channel with the name specified by the argument
2676  * \retval NULL if no channel was found
2677  *
2678  * \since 1.8
2679  */
2680 struct ast_channel *ast_channel_get_by_name(const char *name);
2681
2682 /*!
2683  * \brief Find a channel by a name prefix
2684  *
2685  * \param name The channel name or uniqueid prefix to search for
2686  * \param name_len Only search for up to this many characters from the name
2687  *
2688  * \details
2689  * Find a channel that has the same name prefix as specified by the arguments.
2690  *
2691  * \retval a channel with the name prefix specified by the arguments
2692  * \retval NULL if no channel was found
2693  *
2694  * \since 1.8
2695  */
2696 struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);
2697
2698 /*!
2699  * \brief Find a channel by extension and context
2700  *
2701  * \param exten the extension to search for
2702  * \param context the context to search for
2703  *
2704  * \details
2705  * Return a channel that is currently at the specified extension and context.
2706  *
2707  * \retval a channel that is at the specified extension and context
2708  * \retval NULL if no channel was found
2709  *
2710  * \since 1.8
2711  */
2712 struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);
2713
2714 /*! @} End channel search functions. */
2715
2716 /*!
2717  * \brief Initialize the given name structure.
2718  * \since 1.8
2719  *
2720  * \param init Name structure to initialize.
2721  *
2722  * \return Nothing
2723  */
2724 void ast_party_name_init(struct ast_party_name *init);
2725
2726 /*!
2727  * \brief Copy the source party name information to the destination party name.
2728  * \since 1.8
2729  *
2730  * \param dest Destination party name
2731  * \param src Source party name
2732  *
2733  * \return Nothing
2734  */
2735 void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src);
2736
2737 /*!
2738  * \brief Initialize the given party name structure using the given guide
2739  * for a set update operation.
2740  * \since 1.8
2741  *
2742  * \details
2743  * The initialization is needed to allow a set operation to know if a
2744  * value needs to be updated.  Simple integers need the guide's original
2745  * value in case the set operation is not trying to set a new value.
2746  * String values are simply set to NULL pointers if they are not going
2747  * to be updated.
2748  *
2749  * \param init Party name structure to initialize.
2750  * \param guide Source party name to use as a guide in initializing.
2751  *
2752  * \return Nothing
2753  */
2754 void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide);
2755
2756 /*!
2757  * \brief Set the source party name information into the destination party name.
2758  * \since 1.8
2759  *
2760  * \param dest The name one wishes to update
2761  * \param src The new name values to update the dest
2762  *
2763  * \return Nothing
2764  */
2765 void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src);
2766
2767 /*!
2768  * \brief Destroy the party name contents
2769  * \since 1.8
2770  *
2771  * \param doomed The party name to destroy.
2772  *
2773  * \return Nothing
2774  */
2775 void ast_party_name_free(struct ast_party_name *doomed);
2776
2777 /*!
2778  * \brief Initialize the given number structure.
2779  * \since 1.8
2780  *
2781  * \param init Number structure to initialize.
2782  *
2783  * \return Nothing
2784  */
2785 void ast_party_number_init(struct ast_party_number *init);
2786
2787 /*!
2788  * \brief Copy the source party number information to the destination party number.
2789  * \since 1.8
2790  *
2791  * \param dest Destination party number
2792  * \param src Source party number
2793  *
2794  * \return Nothing
2795  */
2796 void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src);
2797
2798 /*!
2799  * \brief Initialize the given party number structure using the given guide
2800  * for a set update operation.
2801  * \since 1.8
2802  *
2803  * \details
2804  * The initialization is needed to allow a set operation to know if a
2805  * value needs to be updated.  Simple integers need the guide's original
2806  * value in case the set operation is not trying to set a new value.
2807  * String values are simply set to NULL pointers if they are not going
2808  * to be updated.
2809  *
2810  * \param init Party number structure to initialize.
2811  * \param guide Source party number to use as a guide in initializing.
2812  *
2813  * \return Nothing
2814  */
2815 void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide);
2816
2817 /*!
2818  * \brief Set the source party number information into the destination party number.
2819  * \since 1.8
2820  *
2821  * \param dest The number one wishes to update
2822  * \param src The new number values to update the dest
2823  *
2824  * \return Nothing
2825  */
2826 void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src);
2827
2828 /*!
2829  * \brief Destroy the party number contents
2830  * \since 1.8
2831  *
2832  * \param doomed The party number to destroy.
2833  *
2834  * \return Nothing
2835  */
2836 void ast_party_number_free(struct ast_party_number *doomed);
2837
2838 /*!
2839  * \since 1.8
2840  * \brief Initialize the given subaddress structure.
2841  *
2842  * \param init Subaddress structure to initialize.
2843  *
2844  * \return Nothing
2845  */
2846 void ast_party_subaddress_init(struct ast_party_subaddress *init);
2847
2848 /*!
2849  * \since 1.8
2850  * \brief Copy the source party subaddress information to the destination party subaddress.
2851  *
2852  * \param dest Destination party subaddress
2853  * \param src Source party subaddress
2854  *
2855  * \return Nothing
2856  */
2857 void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2858
2859 /*!
2860  * \since 1.8
2861  * \brief Initialize the given party subaddress structure using the given guide
2862  * for a set update operation.
2863  *
2864  * \details
2865  * The initialization is needed to allow a set operation to know if a
2866  * value needs to be updated.  Simple integers need the guide's original
2867  * value in case the set operation is not trying to set a new value.
2868  * String values are simply set to NULL pointers if they are not going
2869  * to be updated.
2870  *
2871  * \param init Party subaddress structure to initialize.
2872  * \param guide Source party subaddress to use as a guide in initializing.
2873  *
2874  * \return Nothing
2875  */
2876 void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide);
2877
2878 /*!
2879  * \since 1.8
2880  * \brief Set the source party subaddress information into the destination party subaddress.
2881  *
2882  * \param dest The subaddress one wishes to update
2883  * \param src The new subaddress values to update the dest
2884  *
2885  * \return Nothing
2886  */
2887 void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2888
2889 /*!
2890  * \since 1.8
2891  * \brief Destroy the party subaddress contents
2892  *
2893  * \param doomed The party subaddress to destroy.
2894  *
2895  * \return Nothing
2896  */
2897 void ast_party_subaddress_free(struct ast_party_subaddress *doomed);
2898
2899 /*!
2900  * \brief Set the update marker to update all information of a corresponding party id.
2901  * \since 11.0
2902  *
2903  * \param update_id The update marker for a corresponding party id.
2904  *
2905  * \return Nothing
2906  */
2907 void ast_set_party_id_all(struct ast_set_party_id *update_id);
2908
2909 /*!
2910  * \brief Initialize the given party id structure.
2911  * \since 1.8
2912  *
2913  * \param init Party id structure to initialize.
2914  *
2915  * \return Nothing
2916  */
2917 void ast_party_id_init(struct ast_party_id *init);
2918
2919 /*!
2920  * \brief Copy the source party id information to the destination party id.
2921  * \since 1.8
2922  *
2923  * \param dest Destination party id
2924  * \param src Source party id
2925  *
2926  * \return Nothing
2927  */
2928 void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src);
2929
2930 /*!
2931  * \brief Initialize the given party id structure using the given guide
2932  * for a set update operation.
2933  * \since 1.8
2934  *
2935  * \details
2936  * The initialization is needed to allow a set operation to know if a
2937  * value needs to be updated.  Simple integers need the guide's original
2938  * value in case the set operation is not trying to set a new value.
2939  * String values are simply set to NULL pointers if they are not going
2940  * to be updated.
2941  *
2942  * \param init Party id structure to initialize.
2943  * \param guide Source party id to use as a guide in initializing.
2944  *
2945  * \return Nothing
2946  */
2947 void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide);
2948
2949 /*!
2950  * \brief Set the source party id information into the destination party id.
2951  * \since 1.8
2952  *
2953  * \param dest The id one wishes to update
2954  * \param src The new id values to update the dest
2955  * \param update What id information to update.  NULL if all.
2956  *
2957  * \return Nothing
2958  */
2959 void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update);
2960
2961 /*!
2962  * \brief Destroy the party id contents
2963  * \since 1.8
2964  *
2965  * \param doomed The party id to destroy.
2966  *
2967  * \return Nothing
2968  */
2969 void ast_party_id_free(struct ast_party_id *doomed);
2970
2971 /*!
2972  * \brief Determine the overall presentation value for the given party.
2973  * \since 1.8
2974  *
2975  * \param id Party to determine the overall presentation value.
2976  *
2977  * \return Overall presentation value for the given party.
2978  */
2979 int ast_party_id_presentation(const struct ast_party_id *id);
2980
2981 /*!
2982  * \brief Invalidate all components of the given party id.
2983  * \since 11.0
2984  *
2985  * \param id The party id to invalidate.
2986  *
2987  * \return Nothing
2988  */
2989 void ast_party_id_invalidate(struct ast_party_id *id);
2990
2991 /*!
2992  * \brief Destroy and initialize the given party id structure.
2993  * \since 11.0
2994  *
2995  * \param id The party id to reset.
2996  *
2997  * \return Nothing
2998  */
2999 void ast_party_id_reset(struct ast_party_id *id);
3000
3001 /*!
3002  * \brief Merge a given party id into another given party id.
3003  * \since 11.0
3004  *
3005  * \details
3006  * This function will generate an effective party id.
3007  *
3008  * Each party id component of the party id 'base' is overwritten
3009  * by components of the party id 'overlay' if the overlay
3010  * component is marked as valid.  However the component 'tag' of
3011  * the base party id remains untouched.
3012  *
3013  * \param base The party id which is merged.
3014  * \param overlay The party id which is used to merge into.
3015  *
3016  * \return The merged party id as a struct, not as a pointer.
3017  * \note The merged party id returned is a shallow copy and must not be freed.
3018  */
3019 struct ast_party_id ast_party_id_merge(struct ast_party_id *base, struct ast_party_id *overlay);
3020
3021 /*!
3022  * \brief Copy a merge of a given party id into another given party id to a given destination party id.
3023  * \since 11.0
3024  *
3025  * \details
3026  * Each party id component of the party id 'base' is overwritten by components
3027  * of the party id 'overlay' if the 'overlay' component is marked as valid.
3028  * However the component 'tag' of the 'base' party id remains untouched.
3029  * The result is copied into the given party id 'dest'.
3030  *
3031  * \note The resulting merged party id is a real copy and has to be freed.
3032  *
3033  * \param dest The resulting merged party id.
3034  * \param base The party id which is merged.
3035  * \param overlay The party id which is used to merge into.
3036  *
3037  * \return Nothing
3038  */
3039 void ast_party_id_merge_copy(struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay);
3040
3041 /*!
3042  * \brief Initialize the given dialed structure.
3043  * \since 1.8
3044  *
3045  * \param init Dialed structure to initialize.
3046  *
3047  * \return Nothing
3048  */
3049 void ast_party_dialed_init(struct ast_party_dialed *init);
3050
3051 /*!
3052  * \brief Copy the source dialed party information to the destination dialed party.
3053  * \since 1.8
3054  *
3055  * \param dest Destination dialed party
3056  * \param src Source dialed party
3057  *
3058  * \return Nothing
3059  */
3060 void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
3061
3062 /*!
3063  * \brief Initialize the given dialed structure using the given
3064  * guide for a set update operation.
3065  * \since 1.8
3066  *
3067  * \details
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
3072  * to be updated.
3073  *
3074  * \param init Caller structure to initialize.
3075  * \param guide Source dialed to use as a guide in initializing.
3076  *
3077  * \return Nothing
3078  */
3079 void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide);
3080
3081 /*!
3082  * \brief Set the dialed information based on another dialed source
3083  * \since 1.8
3084  *
3085  * This is similar to ast_party_dialed_copy, except that NULL values for
3086  * strings in the src parameter indicate not to update the corresponding dest values.
3087  *
3088  * \param dest The dialed one wishes to update
3089  * \param src The new dialed values to update the dest
3090  *
3091  * \return Nada
3092  */
3093 void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
3094
3095 /*!
3096  * \brief Destroy the dialed party contents
3097  * \since 1.8
3098  *
3099  * \param doomed The dialed party to destroy.
3100  *
3101  * \return Nothing
3102  */
3103 void ast_party_dialed_free(struct ast_party_dialed *doomed);
3104
3105 /*!
3106  * \since 1.8
3107  * \brief Initialize the given caller structure.
3108  *
3109  * \param init Caller structure to initialize.
3110  *
3111  * \return Nothing
3112  */
3113 void ast_party_caller_init(struct ast_party_caller *init);
3114
3115 /*!
3116  * \since 1.8
3117  * \brief Copy the source caller information to the destination caller.
3118  *
3119  * \param dest Destination caller
3120  * \param src Source caller
3121  *
3122  * \return Nothing
3123  */
3124 void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src);
3125
3126 /*!
3127  * \brief Initialize the given caller structure using the given
3128  * guide for a set update operation.
3129  * \since 1.8
3130  *
3131  * \details
3132  * The initialization is needed to allow a set operation to know if a
3133  * value needs to be updated.  Simple integers need the guide's original
3134  * value in case the set operation is not trying to set a new value.
3135  * String values are simply set to NULL pointers if they are not going
3136  * to be updated.
3137  *
3138  * \param init Caller structure to initialize.
3139  * \param guide Source caller to use as a guide in initializing.
3140  *
3141  * \return Nothing
3142  */
3143 void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide);
3144
3145 /*!
3146  * \brief Set the caller information based on another caller source
3147  * \since 1.8
3148  *
3149  * This is similar to ast_party_caller_copy, except that NULL values for
3150  * strings in the src parameter indicate not to update the corresponding dest values.
3151  *
3152  * \param dest The caller one wishes to update
3153  * \param src The new caller values to update the dest
3154  * \param update What caller information to update.  NULL if all.
3155  *
3156  * \return Nada
3157  */
3158 void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update);
3159
3160 /*!
3161  * \brief Destroy the caller party contents
3162  * \since 1.8
3163  *
3164  * \param doomed The caller party to destroy.
3165  *
3166  * \return Nothing
3167  */
3168 void ast_party_caller_free(struct ast_party_caller *doomed);
3169
3170 /*!
3171  * \since 1.8
3172  * \brief Initialize the given connected line structure.
3173  *
3174  * \param init Connected line structure to initialize.
3175  *
3176  * \return Nothing
3177  */
3178 void ast_party_connected_line_init(struct ast_party_connected_line *init);
3179
3180 /*!
3181  * \since 1.8
3182  * \brief Copy the source connected line information to the destination connected line.
3183  *
3184  * \param dest Destination connected line
3185  * \param src Source connected line
3186  *
3187  * \return Nothing
3188  */
3189 void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);
3190
3191 /*!
3192  * \since 1.8
3193  * \brief Initialize the given connected line structure using the given
3194  * guide for a set update operation.
3195  *
3196  * \details
3197  * The initialization is needed to allow a set operation to know if a
3198  * value needs to be updated.  Simple integers need the guide's original
3199  * value in case the set operation is not trying to set a new value.
3200  * String values are simply set to NULL pointers if they are not going
3201  * to be updated.
3202  *
3203  * \param init Connected line structure to initialize.
3204  * \param guide Source connected line to use as a guide in initializing.
3205  *
3206  * \return Nothing
3207  */
3208 void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide);
3209
3210 /*!
3211  * \since 1.8
3212  * \brief Set the connected line information based on another connected line source
3213  *
3214  * This is similar to ast_party_connected_line_copy, except that NULL values for
3215  * strings in the src parameter indicate not to update the corresponding dest values.
3216  *
3217  * \param dest The connected line one wishes to update
3218  * \param src The new connected line values to update the dest
3219  * \param update What connected line information to update.  NULL if all.
3220  *
3221  * \return Nothing
3222  */
3223 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);
3224
3225 /*!
3226  * \since 1.8
3227  * \brief Collect the caller party information into a connected line structure.
3228  *
3229  * \param connected Collected caller information for the connected line
3230  * \param caller Caller information.
3231  *
3232  * \return Nothing
3233  *
3234  * \warning This is a shallow copy.
3235  * \warning DO NOT call ast_party_connected_line_free() on the filled in
3236  * connected line structure!
3237  */
3238 void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_party_caller *caller);
3239
3240 /*!
3241  * \since 1.8
3242  * \brief Destroy the connected line information contents
3243  *
3244  * \param doomed The connected line information to destroy.
3245  *
3246  * \return Nothing
3247  */
3248 void ast_party_connected_line_free(struct ast_party_connected_line *doomed);
3249
3250 /*!
3251  * \brief Initialize the given redirecting reason structure
3252  *
3253  * \param init Redirecting reason structure to initialize
3254  *
3255  * \return Nothing
3256  */
3257 void ast_party_redirecting_reason_init(struct ast_party_redirecting_reason *init);
3258
3259 /*!
3260  * \brief Copy the source redirecting reason information to the destination redirecting reason.
3261  *
3262  * \param dest Destination redirecting reason
3263  * \param src Source redirecting reason
3264  *
3265  * \return Nothing
3266  */
3267 void ast_party_redirecting_reason_copy(struct ast_party_redirecting_reason *dest,
3268                 const struct ast_party_redirecting_reason *src);
3269
3270 /*!
3271  * \brief Initialize the given redirecting reason structure using the given guide
3272  * for a set update operation.
3273  *
3274  * \details
3275  * The initialization is needed to allow a set operation to know if a
3276  * value needs to be updated.  Simple integers need the guide's original
3277  * value in case the set operation is not trying to set a new value.
3278  * String values are simply set to NULL pointers if they are not going
3279  * to be updated.
3280  *
3281  * \param init Redirecting reason structure to initialize.
3282  * \param guide Source redirecting reason to use as a guide in initializing.
3283  *
3284  * \return Nothing
3285  */
3286 void ast_party_redirecting_reason_set_init(struct ast_party_redirecting_reason *init,
3287                 const struct ast_party_redirecting_reason *guide);
3288
3289 /*!
3290  * \brief Set the redirecting reason information based on another redirecting reason source
3291  *
3292  * This is similar to ast_party_redirecting_reason_copy, except that NULL values for
3293  * strings in the src parameter indicate not to update the corresponding dest values.
3294  *
3295  * \param dest The redirecting reason one wishes to update
3296  * \param src The new redirecting reason values to update the dest
3297  *
3298  * \return Nothing
3299  */
3300 void ast_party_redirecting_reason_set(struct ast_party_redirecting_reason *dest,
3301                 const struct ast_party_redirecting_reason *src);
3302
3303 /*!
3304  * \brief Destroy the redirecting reason contents
3305  *
3306  * \param doomed The redirecting reason to destroy.
3307  *
3308  * \return Nothing
3309  */
3310 void ast_party_redirecting_reason_free(struct ast_party_redirecting_reason *doomed);
3311
3312 /*!
3313  * \brief Initialize the given redirecting structure.
3314  * \since 1.8
3315  *
3316  * \param init Redirecting structure to initialize.
3317  *
3318  * \return Nothing
3319  */
3320 void ast_party_redirecting_init(struct ast_party_redirecting *init);
3321
3322 /*!
3323  * \since 1.8
3324  * \brief Copy the source redirecting information to the destination redirecting.
3325  *
3326  * \param dest Destination redirecting
3327  * \param src Source redirecting
3328  *
3329  * \return Nothing
3330  */
3331 void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src);
3332
3333 /*!
3334  * \since 1.8
3335  * \brief Initialize the given redirecting id structure using the given guide
3336  * for a set update operation.
3337  *
3338  * \details
3339  * The initialization is needed to allow a set operation to know if a
3340  * value needs to be updated.  Simple integers need the guide's original
3341  * value in case the set operation is not trying to set a new value.
3342  * String values are simply set to NULL pointers if they are not going
3343  * to be updated.
3344  *
3345  * \param init Redirecting id structure to initialize.
3346  * \param guide Source redirecting id to use as a guide in initializing.
3347  *
3348  * \return Nothing
3349  */
3350 void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide);
3351
3352 /*!
3353  * \brief Set the redirecting information based on another redirecting source
3354  * \since 1.8
3355  *
3356  * This is similar to ast_party_redirecting_copy, except that NULL values for
3357  * strings in the src parameter indicate not to update the corresponding dest values.
3358  *
3359  * \param dest The redirecting one wishes to update
3360  * \param src The new redirecting values to update the dest
3361  * \param update What redirecting information to update.  NULL if all.
3362  *
3363  * \return Nothing
3364  */
3365 void ast_party_redirecting_set(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update);
3366
3367 /*!
3368  * \since 1.8
3369  * \brief Destroy the redirecting information contents
3370  *
3371  * \param doomed The redirecting information to destroy.
3372  *
3373  * \return Nothing
3374  */
3375 void ast_party_redirecting_free(struct ast_party_redirecting *doomed);
3376
3377 /*!
3378  * \since 1.8
3379  * \brief Copy the caller information to the connected line information.
3380  *
3381  * \param dest Destination connected line information
3382  * \param src Source caller information
3383  *
3384  * \return Nothing
3385  *
3386  * \note Assumes locks are already acquired
3387  */
3388 void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src);
3389
3390 /*!
3391  * \since 1.8
3392  * \brief Copy the connected line information to the caller information.
3393  *
3394  * \param dest Destination caller information
3395  * \param src Source connected line information
3396  *
3397  * \return Nothing
3398  *
3399  * \note Assumes locks are already acquired
3400  */
3401 void ast_connected_line_copy_to_caller(struct ast_party_caller *dest, const struct ast_party_connected_line *src);
3402
3403 /*!
3404  * \since 1.8
3405  * \brief Set the connected line information in the Asterisk channel
3406  *
3407  * \param chan Asterisk channel to set connected line information
3408  * \param connected Connected line information
3409  * \param update What connected line information to update.  NULL if all.
3410  *
3411  * \return Nothing
3412  *
3413  * \note The channel does not need to be locked before calling this function.
3414  */
3415 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);
3416
3417 /*!
3418  * \since 1.8
3419  * \brief Build the connected line information data frame.
3420  *
3421  * \param data Buffer to fill with the frame data
3422  * \param datalen Size of the buffer to fill
3423  * \param connected Connected line information
3424  * \param update What connected line information to build.  NULL if all.
3425  *
3426  * \retval -1 if error
3427  * \retval Amount of data buffer used
3428  */
3429 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);
3430
3431 /*!
3432  * \since 1.8
3433  * \brief Parse connected line indication frame data
3434  *
3435  * \param data Buffer with the frame data to parse
3436  * \param datalen Size of the buffer
3437  * \param connected Extracted connected line information
3438  *
3439  * \retval 0 on success.
3440  * \retval -1 on error.
3441  *
3442  * \note The filled in connected line structure needs to be initialized by
3443  * ast_party_connected_line_set_init() before calling.  If defaults are not
3444  * required use ast_party_connected_line_init().
3445  * \note The filled in connected line structure needs to be destroyed by
3446  * ast_party_connected_line_free() when it is no longer needed.
3447  */
3448 int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected);
3449
3450 /*!
3451  * \since 1.8
3452  * \brief Indicate that the connected line information has changed
3453  *
3454  * \param chan Asterisk channel to indicate connected line information
3455  * \param connected Connected line information
3456  * \param update What connected line information to update.  NULL if all.
3457  *
3458  * \return Nothing
3459  */
3460 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);
3461
3462 /*!
3463  * \since 1.8
3464  * \brief Queue a connected line update frame on a channel
3465  *
3466  * \param chan Asterisk channel to indicate connected line information
3467  * \param connected Connected line information
3468  * \param update What connected line information to update.  NULL if all.
3469  *
3470  * \return Nothing
<