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