Finalize ast_channel opaquification
[asterisk/asterisk.git] / main / channel_internal_api.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012, 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  *
21  * \brief Channel Accessor API
22  *
23  * This file is intended to be the only file that ever accesses the
24  * internals of an ast_channel. All other files should use the
25  * accessor functions defined here.
26  *
27  * \author Terry Wilson
28  */
29
30 #include "asterisk.h"
31
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33
34 #include <unistd.h>
35 #include <fcntl.h>
36
37 #include "asterisk/channel.h"
38 #include "asterisk/stringfields.h"
39 #include "asterisk/data.h"
40 #include "asterisk/indications.h"
41 #include "asterisk/channel_internal.h"
42
43 /*!
44  * \brief Main Channel structure associated with a channel.
45  *
46  * \note XXX It is important to remember to increment .cleancount each time
47  *       this structure is changed. XXX
48  *
49  * \note When adding fields to this structure, it is important to add the field
50  *       'in position' with like-aligned fields, so as to keep the compiler from
51  *       having to add padding to align fields. The structure's fields are sorted
52  *       in this order: pointers, structures, long, int/enum, short, char. This
53  *       is especially important on 64-bit architectures, where mixing 4-byte
54  *       and 8-byte fields causes 4 bytes of padding to be added before many
55  *       8-byte fields.
56  */
57 struct ast_channel {
58         const struct ast_channel_tech *tech;            /*!< Technology (point to channel driver) */
59         void *tech_pvt;                                 /*!< Private data used by the technology driver */
60         void *music_state;                              /*!< Music State*/
61         void *generatordata;                            /*!< Current generator data if there is any */
62         struct ast_generator *generator;                /*!< Current active data generator */
63         struct ast_channel * bridged_channel;                   /*!< Who are we bridged to, if we're bridged.
64                                                          *   Who is proxying for us, if we are proxied (i.e. chan_agent).
65                                                          *   Do not access directly, use ast_bridged_channel(chan) */
66         struct ast_channel *masq;                       /*!< Channel that will masquerade as us */
67         struct ast_channel *masqr;                      /*!< Who we are masquerading as */
68         const char *blockproc;                          /*!< Procedure causing blocking */
69         const char *appl;                               /*!< Current application */
70         const char *data;                               /*!< Data passed to current application */
71         struct ast_sched_context *sched;                /*!< Schedule context */
72         struct ast_filestream *stream;                  /*!< Stream itself. */
73         struct ast_filestream *vstream;                 /*!< Video Stream itself. */
74         ast_timing_func_t timingfunc;
75         void *timingdata;
76         struct ast_pbx *pbx;                            /*!< PBX private structure for this channel */
77         struct ast_trans_pvt *writetrans;               /*!< Write translation path */
78         struct ast_trans_pvt *readtrans;                /*!< Read translation path */
79         struct ast_audiohook_list *audiohooks;
80         struct ast_framehook_list *framehooks;
81         struct ast_cdr *cdr;                            /*!< Call Detail Record */
82         struct ast_tone_zone *zone;                     /*!< Tone zone as set in indications.conf or
83                                                          *   in the CHANNEL dialplan function */
84         struct ast_channel_monitor *monitor;            /*!< Channel monitoring */
85 #ifdef HAVE_EPOLL
86         struct ast_epoll_data *epfd_data[AST_MAX_FDS];
87 #endif
88
89         AST_DECLARE_STRING_FIELDS(
90                 AST_STRING_FIELD(name);         /*!< ASCII unique channel name */
91                 AST_STRING_FIELD(language);     /*!< Language requested for voice prompts */
92                 AST_STRING_FIELD(musicclass);   /*!< Default music class */
93                 AST_STRING_FIELD(accountcode);  /*!< Account code for billing */
94                 AST_STRING_FIELD(peeraccount);  /*!< Peer account code for billing */
95                 AST_STRING_FIELD(userfield);    /*!< Userfield for CEL billing */
96                 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */
97                 AST_STRING_FIELD(uniqueid);     /*!< Unique Channel Identifier */
98                 AST_STRING_FIELD(linkedid);     /*!< Linked Channel Identifier -- gets propagated by linkage */
99                 AST_STRING_FIELD(parkinglot);   /*! Default parking lot, if empty, default parking lot  */
100                 AST_STRING_FIELD(hangupsource); /*! Who is responsible for hanging up this channel */
101                 AST_STRING_FIELD(dialcontext);  /*!< Dial: Extension context that we were called from */
102         );
103
104         struct timeval whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */
105         pthread_t blocker;           /*!< If anyone is blocking, this is them */
106
107         /*!
108          * \brief Dialed/Called information.
109          * \note Set on incoming channels to indicate the originally dialed party.
110          * \note Dialed Number Identifier (DNID)
111          */
112         struct ast_party_dialed dialed;
113
114         /*!
115          * \brief Channel Caller ID information.
116          * \note The caller id information is the caller id of this
117          * channel when it is used to initiate a call.
118          */
119         struct ast_party_caller caller;
120
121         /*!
122          * \brief Channel Connected Line ID information.
123          * \note The connected line information identifies the channel
124          * connected/bridged to this channel.
125          */
126         struct ast_party_connected_line connected;
127
128         /*! \brief Redirecting/Diversion information */
129         struct ast_party_redirecting redirecting;
130
131         struct ast_frame dtmff;                         /*!< DTMF frame */
132         struct varshead varshead;                       /*!< A linked list for channel variables. See \ref AstChanVar */
133         ast_group_t callgroup;                          /*!< Call group for call pickups */
134         ast_group_t pickupgroup;                        /*!< Pickup group - which calls groups can be picked up? */
135         struct ast_readq_list readq;
136         struct ast_jb jb;                               /*!< The jitterbuffer state */
137         struct timeval dtmf_tv;                         /*!< The time that an in process digit began, or the last digit ended */
138         struct ast_datastore_list datastores; /*!< Data stores on the channel */
139         struct ast_autochan_list autochans; /*!< Autochans on the channel */
140         unsigned long insmpl;                           /*!< Track the read/written samples for monitor use */
141         unsigned long outsmpl;                          /*!< Track the read/written samples for monitor use */
142
143         int fds[AST_MAX_FDS];                           /*!< File descriptors for channel -- Drivers will poll on
144                                                          *   these file descriptors, so at least one must be non -1.
145                                                          *   See \arg \ref AstFileDesc */
146         int softhangup;                         /*!< Whether or not we have been hung up...  Do not set this value
147                                                          *   directly, use ast_softhangup() */
148         int fdno;                                       /*!< Which fd had an event detected on */
149         int streamid;                                   /*!< For streaming playback, the schedule ID */
150         int vstreamid;                                  /*!< For streaming video playback, the schedule ID */
151         struct ast_format oldwriteformat;  /*!< Original writer format */
152         int timingfd;                                   /*!< Timing fd */
153         enum ast_channel_state state;                   /*!< State of line -- Don't write directly, use ast_setstate() */
154         int rings;                                      /*!< Number of rings so far */
155         int priority;                                   /*!< Dialplan: Current extension priority */
156         int macropriority;                              /*!< Macro: Current non-macro priority. See app_macro.c */
157         int amaflags;                                   /*!< Set BEFORE PBX is started to determine AMA flags */
158         enum ast_channel_adsicpe adsicpe;               /*!< Whether or not ADSI is detected on CPE */
159         unsigned int fin;                               /*!< Frames in counters. The high bit is a debug mask, so
160                                                          *   the counter is only in the remaining bits */
161         unsigned int fout;                              /*!< Frames out counters. The high bit is a debug mask, so
162                                                          *   the counter is only in the remaining bits */
163         int hangupcause;                                /*!< Why is the channel hanged up. See causes.h */
164         unsigned int finalized:1;       /*!< Whether or not the channel has been successfully allocated */
165         struct ast_flags flags;                         /*!< channel flags of AST_FLAG_ type */
166         int alertpipe[2];
167         struct ast_format_cap *nativeformats;         /*!< Kinds of data this channel can natively handle */
168         struct ast_format readformat;            /*!< Requested read format (after translation) */
169         struct ast_format writeformat;           /*!< Requested write format (after translation) */
170         struct ast_format rawreadformat;         /*!< Raw read format (before translation) */
171         struct ast_format rawwriteformat;        /*!< Raw write format (before translation) */
172         unsigned int emulate_dtmf_duration;             /*!< Number of ms left to emulate DTMF for */
173 #ifdef HAVE_EPOLL
174         int epfd;
175 #endif
176         int visible_indication;                         /*!< Indication currently playing on the channel */
177
178         unsigned short transfercapability;              /*!< ISDN Transfer Capability - AST_FLAG_DIGITAL is not enough */
179
180         struct ast_bridge *bridge;                      /*!< Bridge this channel is participating in */
181         struct ast_timer *timer;                        /*!< timer object that provided timingfd */
182
183         char context[AST_MAX_CONTEXT];                  /*!< Dialplan: Current extension context */
184         char exten[AST_MAX_EXTENSION];                  /*!< Dialplan: Current extension number */
185         char macrocontext[AST_MAX_CONTEXT];             /*!< Macro: Current non-macro context. See app_macro.c */
186         char macroexten[AST_MAX_EXTENSION];             /*!< Macro: Current non-macro extension. See app_macro.c */
187         char dtmf_digit_to_emulate;                     /*!< Digit being emulated */
188 };
189
190 /* AST_DATA definitions, which will probably have to be re-thought since the channel will be opaque */
191
192 #if 0   /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
193 #define DATA_EXPORT_CALLERID(MEMBER)                            \
194         MEMBER(ast_callerid, cid_dnid, AST_DATA_STRING)         \
195         MEMBER(ast_callerid, cid_num, AST_DATA_STRING)          \
196         MEMBER(ast_callerid, cid_name, AST_DATA_STRING)         \
197         MEMBER(ast_callerid, cid_ani, AST_DATA_STRING)          \
198         MEMBER(ast_callerid, cid_pres, AST_DATA_INTEGER)        \
199         MEMBER(ast_callerid, cid_ani2, AST_DATA_INTEGER)        \
200         MEMBER(ast_callerid, cid_tag, AST_DATA_STRING)
201
202 AST_DATA_STRUCTURE(ast_callerid, DATA_EXPORT_CALLERID);
203 #endif
204
205 #define DATA_EXPORT_CHANNEL(MEMBER)                                             \
206         MEMBER(ast_channel, blockproc, AST_DATA_STRING)                         \
207         MEMBER(ast_channel, appl, AST_DATA_STRING)                              \
208         MEMBER(ast_channel, data, AST_DATA_STRING)                              \
209         MEMBER(ast_channel, name, AST_DATA_STRING) \
210         MEMBER(ast_channel, language, AST_DATA_STRING)                          \
211         MEMBER(ast_channel, musicclass, AST_DATA_STRING)                        \
212         MEMBER(ast_channel, accountcode, AST_DATA_STRING)                       \
213         MEMBER(ast_channel, peeraccount, AST_DATA_STRING)                       \
214         MEMBER(ast_channel, userfield, AST_DATA_STRING)                         \
215         MEMBER(ast_channel, call_forward, AST_DATA_STRING)                      \
216         MEMBER(ast_channel, uniqueid, AST_DATA_STRING)                          \
217         MEMBER(ast_channel, linkedid, AST_DATA_STRING)                          \
218         MEMBER(ast_channel, parkinglot, AST_DATA_STRING)                        \
219         MEMBER(ast_channel, hangupsource, AST_DATA_STRING)                      \
220         MEMBER(ast_channel, dialcontext, AST_DATA_STRING)                       \
221         MEMBER(ast_channel, rings, AST_DATA_INTEGER)                            \
222         MEMBER(ast_channel, priority, AST_DATA_INTEGER)                         \
223         MEMBER(ast_channel, macropriority, AST_DATA_INTEGER)                    \
224         MEMBER(ast_channel, adsicpe, AST_DATA_INTEGER)                          \
225         MEMBER(ast_channel, fin, AST_DATA_UNSIGNED_INTEGER)                     \
226         MEMBER(ast_channel, fout, AST_DATA_UNSIGNED_INTEGER)                    \
227         MEMBER(ast_channel, emulate_dtmf_duration, AST_DATA_UNSIGNED_INTEGER)   \
228         MEMBER(ast_channel, visible_indication, AST_DATA_INTEGER)               \
229         MEMBER(ast_channel, context, AST_DATA_STRING)                           \
230         MEMBER(ast_channel, exten, AST_DATA_STRING)                             \
231         MEMBER(ast_channel, macrocontext, AST_DATA_STRING)                      \
232         MEMBER(ast_channel, macroexten, AST_DATA_STRING)
233
234 AST_DATA_STRUCTURE(ast_channel, DATA_EXPORT_CHANNEL);
235
236 static void channel_data_add_flags(struct ast_data *tree,
237         struct ast_channel *chan)
238 {
239         ast_data_add_bool(tree, "DEFER_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF));
240         ast_data_add_bool(tree, "WRITE_INT", ast_test_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT));
241         ast_data_add_bool(tree, "BLOCKING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING));
242         ast_data_add_bool(tree, "ZOMBIE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE));
243         ast_data_add_bool(tree, "EXCEPTION", ast_test_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION));
244         ast_data_add_bool(tree, "MOH", ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH));
245         ast_data_add_bool(tree, "SPYING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_SPYING));
246         ast_data_add_bool(tree, "NBRIDGE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_NBRIDGE));
247         ast_data_add_bool(tree, "IN_AUTOLOOP", ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP));
248         ast_data_add_bool(tree, "OUTGOING", ast_test_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING));
249         ast_data_add_bool(tree, "IN_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_DTMF));
250         ast_data_add_bool(tree, "EMULATE_DTMF", ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF));
251         ast_data_add_bool(tree, "END_DTMF_ONLY", ast_test_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY));
252         ast_data_add_bool(tree, "ANSWERED_ELSEWHERE", ast_test_flag(ast_channel_flags(chan), AST_FLAG_ANSWERED_ELSEWHERE));
253         ast_data_add_bool(tree, "MASQ_NOSTREAM", ast_test_flag(ast_channel_flags(chan), AST_FLAG_MASQ_NOSTREAM));
254         ast_data_add_bool(tree, "BRIDGE_HANGUP_RUN", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_RUN));
255         ast_data_add_bool(tree, "BRIDGE_HANGUP_DONT", ast_test_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_DONT));
256         ast_data_add_bool(tree, "DISABLE_WORKAROUNDS", ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS));
257 }
258
259 int ast_channel_data_add_structure(struct ast_data *tree,
260         struct ast_channel *chan, int add_bridged)
261 {
262         struct ast_channel *bc;
263         struct ast_data *data_bridged;
264         struct ast_data *data_cdr;
265         struct ast_data *data_flags;
266         struct ast_data *data_zones;
267         struct ast_data *enum_node;
268         struct ast_data *data_softhangup;
269 #if 0   /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
270         struct ast_data *data_callerid;
271         char value_str[100];
272 #endif
273
274         if (!tree) {
275                 return -1;
276         }
277
278         ast_data_add_structure(ast_channel, tree, chan);
279
280         if (add_bridged) {
281                 bc = ast_bridged_channel(chan);
282                 if (bc) {
283                         data_bridged = ast_data_add_node(tree, "bridged");
284                         if (!data_bridged) {
285                                 return -1;
286                         }
287                         ast_channel_data_add_structure(data_bridged, bc, 0);
288                 }
289         }
290
291         ast_data_add_codec(tree, "oldwriteformat", ast_channel_oldwriteformat(chan));
292         ast_data_add_codec(tree, "readformat", ast_channel_readformat(chan));
293         ast_data_add_codec(tree, "writeformat", ast_channel_writeformat(chan));
294         ast_data_add_codec(tree, "rawreadformat", ast_channel_rawreadformat(chan));
295         ast_data_add_codec(tree, "rawwriteformat", ast_channel_rawwriteformat(chan));
296         ast_data_add_codecs(tree, "nativeformats", ast_channel_nativeformats(chan));
297
298         /* state */
299         enum_node = ast_data_add_node(tree, "state");
300         if (!enum_node) {
301                 return -1;
302         }
303         ast_data_add_str(enum_node, "text", ast_state2str(ast_channel_state(chan)));
304         ast_data_add_int(enum_node, "value", ast_channel_state(chan));
305
306         /* hangupcause */
307         enum_node = ast_data_add_node(tree, "hangupcause");
308         if (!enum_node) {
309                 return -1;
310         }
311         ast_data_add_str(enum_node, "text", ast_cause2str(ast_channel_hangupcause(chan)));
312         ast_data_add_int(enum_node, "value", ast_channel_hangupcause(chan));
313
314         /* amaflags */
315         enum_node = ast_data_add_node(tree, "amaflags");
316         if (!enum_node) {
317                 return -1;
318         }
319         ast_data_add_str(enum_node, "text", ast_cdr_flags2str(ast_channel_amaflags(chan)));
320         ast_data_add_int(enum_node, "value", ast_channel_amaflags(chan));
321
322         /* transfercapability */
323         enum_node = ast_data_add_node(tree, "transfercapability");
324         if (!enum_node) {
325                 return -1;
326         }
327         ast_data_add_str(enum_node, "text", ast_transfercapability2str(ast_channel_transfercapability(chan)));
328         ast_data_add_int(enum_node, "value", ast_channel_transfercapability(chan));
329
330         /* _softphangup */
331         data_softhangup = ast_data_add_node(tree, "softhangup");
332         if (!data_softhangup) {
333                 return -1;
334         }
335         ast_data_add_bool(data_softhangup, "dev", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_DEV);
336         ast_data_add_bool(data_softhangup, "asyncgoto", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO);
337         ast_data_add_bool(data_softhangup, "shutdown", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_SHUTDOWN);
338         ast_data_add_bool(data_softhangup, "timeout", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_TIMEOUT);
339         ast_data_add_bool(data_softhangup, "appunload", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_APPUNLOAD);
340         ast_data_add_bool(data_softhangup, "explicit", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_EXPLICIT);
341         ast_data_add_bool(data_softhangup, "unbridge", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_UNBRIDGE);
342
343         /* channel flags */
344         data_flags = ast_data_add_node(tree, "flags");
345         if (!data_flags) {
346                 return -1;
347         }
348         channel_data_add_flags(data_flags, chan);
349
350         ast_data_add_uint(tree, "timetohangup", ast_channel_whentohangup(chan)->tv_sec);
351
352 #if 0   /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
353         /* callerid */
354         data_callerid = ast_data_add_node(tree, "callerid");
355         if (!data_callerid) {
356                 return -1;
357         }
358         ast_data_add_structure(ast_callerid, data_callerid, &(chan->cid));
359         /* insert the callerid ton */
360         enum_node = ast_data_add_node(data_callerid, "cid_ton");
361         if (!enum_node) {
362                 return -1;
363         }
364         ast_data_add_int(enum_node, "value", chan->cid.cid_ton);
365         snprintf(value_str, sizeof(value_str), "TON: %s/Plan: %s",
366                 party_number_ton2str(chan->cid.cid_ton),
367                 party_number_plan2str(chan->cid.cid_ton));
368         ast_data_add_str(enum_node, "text", value_str);
369 #endif
370
371         /* tone zone */
372         if (ast_channel_zone(chan)) {
373                 data_zones = ast_data_add_node(tree, "zone");
374                 if (!data_zones) {
375                         return -1;
376                 }
377                 ast_tone_zone_data_add_structure(data_zones, ast_channel_zone(chan));
378         }
379
380         /* insert cdr */
381         data_cdr = ast_data_add_node(tree, "cdr");
382         if (!data_cdr) {
383                 return -1;
384         }
385
386         ast_cdr_data_add_structure(data_cdr, ast_channel_cdr(chan), 1);
387
388         return 0;
389 }
390
391 int ast_channel_data_cmp_structure(const struct ast_data_search *tree,
392         struct ast_channel *chan, const char *structure_name)
393 {
394         return ast_data_search_cmp_structure(tree, ast_channel, chan, structure_name);
395 }
396
397 /* ACCESSORS */
398
399 #define DEFINE_STRINGFIELD_SETTERS_FOR(field) \
400 void ast_channel_##field##_set(struct ast_channel *chan, const char *value) \
401 { \
402         ast_string_field_set(chan, field, value); \
403 } \
404   \
405 void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) \
406 { \
407         ast_string_field_build_va(chan, field, fmt, ap); \
408 } \
409 void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) \
410 { \
411         va_list ap; \
412         va_start(ap, fmt); \
413         ast_channel_##field##_build_va(chan, fmt, ap); \
414         va_end(ap); \
415 }
416
417 DEFINE_STRINGFIELD_SETTERS_FOR(name);
418 DEFINE_STRINGFIELD_SETTERS_FOR(language);
419 DEFINE_STRINGFIELD_SETTERS_FOR(musicclass);
420 DEFINE_STRINGFIELD_SETTERS_FOR(accountcode);
421 DEFINE_STRINGFIELD_SETTERS_FOR(peeraccount);
422 DEFINE_STRINGFIELD_SETTERS_FOR(userfield);
423 DEFINE_STRINGFIELD_SETTERS_FOR(call_forward);
424 DEFINE_STRINGFIELD_SETTERS_FOR(uniqueid);
425 DEFINE_STRINGFIELD_SETTERS_FOR(linkedid);
426 DEFINE_STRINGFIELD_SETTERS_FOR(parkinglot);
427 DEFINE_STRINGFIELD_SETTERS_FOR(hangupsource);
428 DEFINE_STRINGFIELD_SETTERS_FOR(dialcontext);
429
430 #define DEFINE_STRINGFIELD_GETTER_FOR(field) const char *ast_channel_##field(const struct ast_channel *chan) \
431 { \
432         return chan->field; \
433 }
434
435 DEFINE_STRINGFIELD_GETTER_FOR(name);
436 DEFINE_STRINGFIELD_GETTER_FOR(language);
437 DEFINE_STRINGFIELD_GETTER_FOR(musicclass);
438 DEFINE_STRINGFIELD_GETTER_FOR(accountcode);
439 DEFINE_STRINGFIELD_GETTER_FOR(peeraccount);
440 DEFINE_STRINGFIELD_GETTER_FOR(userfield);
441 DEFINE_STRINGFIELD_GETTER_FOR(call_forward);
442 DEFINE_STRINGFIELD_GETTER_FOR(uniqueid);
443 DEFINE_STRINGFIELD_GETTER_FOR(linkedid);
444 DEFINE_STRINGFIELD_GETTER_FOR(parkinglot);
445 DEFINE_STRINGFIELD_GETTER_FOR(hangupsource);
446 DEFINE_STRINGFIELD_GETTER_FOR(dialcontext);
447
448 const char *ast_channel_appl(const struct ast_channel *chan)
449 {
450         return chan->appl;
451 }
452 void ast_channel_appl_set(struct ast_channel *chan, const char *value)
453 {
454         chan->appl = value;
455 }
456 const char *ast_channel_blockproc(const struct ast_channel *chan)
457 {
458         return chan->blockproc;
459 }
460 void ast_channel_blockproc_set(struct ast_channel *chan, const char *value)
461 {
462         chan->blockproc = value;
463 }
464 const char *ast_channel_data(const struct ast_channel *chan)
465 {
466         return chan->data;
467 }
468 void ast_channel_data_set(struct ast_channel *chan, const char *value)
469 {
470         chan->data = value;
471 }
472
473 const char *ast_channel_context(const struct ast_channel *chan)
474 {
475         return chan->context;
476 }
477 void ast_channel_context_set(struct ast_channel *chan, const char *value)
478 {
479         ast_copy_string(chan->context, value, sizeof(chan->context));
480 }
481 const char *ast_channel_exten(const struct ast_channel *chan)
482 {
483         return chan->exten;
484 }
485 void ast_channel_exten_set(struct ast_channel *chan, const char *value)
486 {
487         ast_copy_string(chan->exten, value, sizeof(chan->exten));
488 }
489 const char *ast_channel_macrocontext(const struct ast_channel *chan)
490 {
491         return chan->macrocontext;
492 }
493 void ast_channel_macrocontext_set(struct ast_channel *chan, const char *value)
494 {
495         ast_copy_string(chan->macrocontext, value, sizeof(chan->macrocontext));
496 }
497 const char *ast_channel_macroexten(const struct ast_channel *chan)
498 {
499         return chan->macroexten;
500 }
501 void ast_channel_macroexten_set(struct ast_channel *chan, const char *value)
502 {
503         ast_copy_string(chan->macroexten, value, sizeof(chan->macroexten));
504 }
505
506 char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan)
507 {
508         return chan->dtmf_digit_to_emulate;
509 }
510 void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value)
511 {
512         chan->dtmf_digit_to_emulate = value;
513 }
514 int ast_channel_amaflags(const struct ast_channel *chan)
515 {
516         return chan->amaflags;
517 }
518 void ast_channel_amaflags_set(struct ast_channel *chan, int value)
519 {
520         chan->amaflags = value;
521 }
522 #ifdef HAVE_EPOLL
523 int ast_channel_epfd(const struct ast_channel *chan)
524 {
525         return chan->epfd;
526 }
527 void ast_channel_epfd_set(struct ast_channel *chan, int value)
528 {
529         chan->epfd = value;
530 }
531 #endif
532 int ast_channel_fdno(const struct ast_channel *chan)
533 {
534         return chan->fdno;
535 }
536 void ast_channel_fdno_set(struct ast_channel *chan, int value)
537 {
538         chan->fdno = value;
539 }
540 int ast_channel_hangupcause(const struct ast_channel *chan)
541 {
542         return chan->hangupcause;
543 }
544 void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
545 {
546         chan->hangupcause = value;
547 }
548 int ast_channel_macropriority(const struct ast_channel *chan)
549 {
550         return chan->macropriority;
551 }
552 void ast_channel_macropriority_set(struct ast_channel *chan, int value)
553 {
554         chan->macropriority = value;
555 }
556 int ast_channel_priority(const struct ast_channel *chan)
557 {
558         return chan->priority;
559 }
560 void ast_channel_priority_set(struct ast_channel *chan, int value)
561 {
562         chan->priority = value;
563 }
564 int ast_channel_rings(const struct ast_channel *chan)
565 {
566         return chan->rings;
567 }
568 void ast_channel_rings_set(struct ast_channel *chan, int value)
569 {
570         chan->rings = value;
571 }
572 int ast_channel_streamid(const struct ast_channel *chan)
573 {
574         return chan->streamid;
575 }
576 void ast_channel_streamid_set(struct ast_channel *chan, int value)
577 {
578         chan->streamid = value;
579 }
580 int ast_channel_timingfd(const struct ast_channel *chan)
581 {
582         return chan->timingfd;
583 }
584 void ast_channel_timingfd_set(struct ast_channel *chan, int value)
585 {
586         chan->timingfd = value;
587 }
588 int ast_channel_visible_indication(const struct ast_channel *chan)
589 {
590         return chan->visible_indication;
591 }
592 void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
593 {
594         chan->visible_indication = value;
595 }
596 int ast_channel_vstreamid(const struct ast_channel *chan)
597 {
598         return chan->vstreamid;
599 }
600 void ast_channel_vstreamid_set(struct ast_channel *chan, int value)
601 {
602         chan->vstreamid = value;
603 }
604 unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
605 {
606         return chan->transfercapability;
607 }
608 void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
609 {
610         chan->transfercapability = value;
611 }
612 unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan)
613 {
614         return chan->emulate_dtmf_duration;
615 }
616 void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value)
617 {
618         chan->emulate_dtmf_duration = value;
619 }
620 unsigned int ast_channel_fin(const struct ast_channel *chan)
621 {
622         return chan->fin;
623 }
624 void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
625 {
626         chan->fin = value;
627 }
628 unsigned int ast_channel_fout(const struct ast_channel *chan)
629 {
630         return chan->fout;
631 }
632 void ast_channel_fout_set(struct ast_channel *chan, unsigned int value)
633 {
634         chan->fout = value;
635 }
636 unsigned long ast_channel_insmpl(const struct ast_channel *chan)
637 {
638         return chan->insmpl;
639 }
640 void ast_channel_insmpl_set(struct ast_channel *chan, unsigned long value)
641 {
642         chan->insmpl = value;
643 }
644 unsigned long ast_channel_outsmpl(const struct ast_channel *chan)
645 {
646         return chan->outsmpl;
647 }
648 void ast_channel_outsmpl_set(struct ast_channel *chan, unsigned long value)
649 {
650         chan->outsmpl = value;
651 }
652 void *ast_channel_generatordata(const struct ast_channel *chan)
653 {
654         return chan->generatordata;
655 }
656 void ast_channel_generatordata_set(struct ast_channel *chan, void *value)
657 {
658         chan->generatordata = value;
659 }
660 void *ast_channel_music_state(const struct ast_channel *chan)
661 {
662         return chan->music_state;
663 }
664 void ast_channel_music_state_set(struct ast_channel *chan, void *value)
665 {
666         chan->music_state = value;
667 }
668 void *ast_channel_tech_pvt(const struct ast_channel *chan)
669 {
670         return chan->tech_pvt;
671 }
672 void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
673 {
674         chan->tech_pvt = value;
675 }
676 void *ast_channel_timingdata(const struct ast_channel *chan)
677 {
678         return chan->timingdata;
679 }
680 void ast_channel_timingdata_set(struct ast_channel *chan, void *value)
681 {
682         chan->timingdata = value;
683 }
684 struct ast_audiohook_list *ast_channel_audiohooks(const struct ast_channel *chan)
685 {
686         return chan->audiohooks;
687 }
688 void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
689 {
690         chan->audiohooks = value;
691 }
692 struct ast_cdr *ast_channel_cdr(const struct ast_channel *chan)
693 {
694         return chan->cdr;
695 }
696 void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value)
697 {
698         chan->cdr = value;
699 }
700 struct ast_channel *ast_channel_masq(const struct ast_channel *chan)
701 {
702         return chan->masq;
703 }
704 void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value)
705 {
706         chan->masq = value;
707 }
708 struct ast_channel *ast_channel_masqr(const struct ast_channel *chan)
709 {
710         return chan->masqr;
711 }
712 void ast_channel_masqr_set(struct ast_channel *chan, struct ast_channel *value)
713 {
714         chan->masqr = value;
715 }
716 struct ast_channel_monitor *ast_channel_monitor(const struct ast_channel *chan)
717 {
718         return chan->monitor;
719 }
720 void ast_channel_monitor_set(struct ast_channel *chan, struct ast_channel_monitor *value)
721 {
722         chan->monitor = value;
723 }
724 struct ast_filestream *ast_channel_stream(const struct ast_channel *chan)
725 {
726         return chan->stream;
727 }
728 void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
729 {
730         chan->stream = value;
731 }
732 struct ast_filestream *ast_channel_vstream(const struct ast_channel *chan)
733 {
734         return chan->vstream;
735 }
736 void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
737 {
738         chan->vstream = value;
739 }
740 struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan)
741 {
742         return chan->nativeformats;
743 }
744 void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
745 {
746         chan->nativeformats = value;
747 }
748 struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan)
749 {
750         return chan->framehooks;
751 }
752 void ast_channel_framehooks_set(struct ast_channel *chan, struct ast_framehook_list *value)
753 {
754         chan->framehooks = value;
755 }
756 struct ast_generator *ast_channel_generator(const struct ast_channel *chan)
757 {
758         return chan->generator;
759 }
760 void ast_channel_generator_set(struct ast_channel *chan, struct ast_generator *value)
761 {
762         chan->generator = value;
763 }
764 struct ast_pbx *ast_channel_pbx(const struct ast_channel *chan)
765 {
766         return chan->pbx;
767 }
768 void ast_channel_pbx_set(struct ast_channel *chan, struct ast_pbx *value)
769 {
770         chan->pbx = value;
771 }
772 struct ast_sched_context *ast_channel_sched(const struct ast_channel *chan)
773 {
774         return chan->sched;
775 }
776 void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value)
777 {
778         chan->sched = value;
779 }
780 struct ast_timer *ast_channel_timer(const struct ast_channel *chan)
781 {
782         return chan->timer;
783 }
784 void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value)
785 {
786         chan->timer = value;
787 }
788 struct ast_tone_zone *ast_channel_zone(const struct ast_channel *chan)
789 {
790         return chan->zone;
791 }
792 void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
793 {
794         chan->zone = value;
795 }
796 struct ast_trans_pvt *ast_channel_readtrans(const struct ast_channel *chan)
797 {
798         return chan->readtrans;
799 }
800 void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
801 {
802         chan->readtrans = value;
803 }
804 struct ast_trans_pvt *ast_channel_writetrans(const struct ast_channel *chan)
805 {
806         return chan->writetrans;
807 }
808 void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
809 {
810         chan->writetrans = value;
811 }
812 const struct ast_channel_tech *ast_channel_tech(const struct ast_channel *chan)
813 {
814         return chan->tech;
815 }
816 void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
817 {
818         chan->tech = value;
819 }
820 enum ast_channel_adsicpe ast_channel_adsicpe(const struct ast_channel *chan)
821 {
822         return chan->adsicpe;
823 }
824 void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
825 {
826         chan->adsicpe = value;
827 }
828 enum ast_channel_state ast_channel_state(const struct ast_channel *chan)
829 {
830         return chan->state;
831 }
832 void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state value)
833 {
834         chan->state = value;
835 }
836 struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan)
837 {
838         return &chan->oldwriteformat;
839 }
840 struct ast_format *ast_channel_rawreadformat(struct ast_channel *chan)
841 {
842         return &chan->rawreadformat;
843 }
844 struct ast_format *ast_channel_rawwriteformat(struct ast_channel *chan)
845 {
846         return &chan->rawwriteformat;
847 }
848 struct ast_format *ast_channel_readformat(struct ast_channel *chan)
849 {
850         return &chan->readformat;
851 }
852 struct ast_format *ast_channel_writeformat(struct ast_channel *chan)
853 {
854         return &chan->writeformat;
855 }
856 struct ast_datastore_list *ast_channel_datastores(struct ast_channel *chan)
857 {
858         return &chan->datastores;
859 }
860 struct ast_autochan_list *ast_channel_autochans(struct ast_channel *chan)
861 {
862         return &chan->autochans;
863 }
864 struct ast_readq_list *ast_channel_readq(struct ast_channel *chan)
865 {
866         return &chan->readq;
867 }
868 struct ast_frame *ast_channel_dtmff(struct ast_channel *chan)
869 {
870         return &chan->dtmff;
871 }
872 struct ast_jb *ast_channel_jb(struct ast_channel *chan)
873 {
874         return &chan->jb;
875 }
876 struct ast_party_caller *ast_channel_caller(struct ast_channel *chan)
877 {
878         return &chan->caller;
879 }
880 struct ast_party_connected_line *ast_channel_connected(struct ast_channel *chan)
881 {
882         return &chan->connected;
883 }
884 struct ast_party_dialed *ast_channel_dialed(struct ast_channel *chan)
885 {
886         return &chan->dialed;
887 }
888 struct ast_party_redirecting *ast_channel_redirecting(struct ast_channel *chan)
889 {
890         return &chan->redirecting;
891 }
892 struct timeval *ast_channel_dtmf_tv(struct ast_channel *chan)
893 {
894         return &chan->dtmf_tv;
895 }
896 struct timeval *ast_channel_whentohangup(struct ast_channel *chan)
897 {
898         return &chan->whentohangup;
899 }
900 struct varshead *ast_channel_varshead(struct ast_channel *chan)
901 {
902         return &chan->varshead;
903 }
904 void ast_channel_dtmff_set(struct ast_channel *chan, struct ast_frame *value)
905 {
906         chan->dtmff = *value;
907 }
908 void ast_channel_jb_set(struct ast_channel *chan, struct ast_jb *value)
909 {
910         chan->jb = *value;
911 }
912 void ast_channel_caller_set(struct ast_channel *chan, struct ast_party_caller *value)
913 {
914         chan->caller = *value;
915 }
916 void ast_channel_connected_set(struct ast_channel *chan, struct ast_party_connected_line *value)
917 {
918         chan->connected = *value;
919 }
920 void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value)
921 {
922         chan->dialed = *value;
923 }
924 void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value)
925 {
926         chan->redirecting = *value;
927 }
928 void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value)
929 {
930         chan->dtmf_tv = *value;
931 }
932 void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
933 {
934         chan->whentohangup = *value;
935 }
936 void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value)
937 {
938         chan->varshead = *value;
939 }
940
941 /* Evil softhangup accessors */
942 int ast_channel_softhangup_internal_flag(struct ast_channel *chan)
943 {
944         return chan->softhangup;
945 }
946 void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value)
947 {
948         chan->softhangup = value;
949 }
950 void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
951 {
952         chan->softhangup |= value;
953 }
954 void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int value)
955 {
956         chan ->softhangup &= ~value;
957 }
958
959 /* Typedef accessors */
960 ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
961 {
962         return chan->callgroup;
963 }
964 void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
965 {
966         chan->callgroup = value;
967 }
968 ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
969 {
970         return chan->pickupgroup;
971 }
972 void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
973 {
974         chan->pickupgroup = value;
975 }
976
977 /* Alertpipe functions */
978 int ast_channel_alert_write(struct ast_channel *chan)
979 {
980         char blah = 0x7F;
981         return ast_channel_alert_writable(chan) && write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
982 }
983
984 ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
985 {
986         int flags;
987         char blah;
988
989         if (!ast_channel_internal_alert_readable(chan)) {
990                 return AST_ALERT_NOT_READABLE;
991         }
992
993         flags = fcntl(chan->alertpipe[0], F_GETFL);
994         /* For some odd reason, the alertpipe occasionally loses nonblocking status,
995          * which immediately causes a deadlock scenario.  Detect and prevent this. */
996         if ((flags & O_NONBLOCK) == 0) {
997                 ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", ast_channel_name(chan));
998                 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
999                         ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
1000                         return AST_ALERT_READ_FATAL;
1001                 }
1002         }
1003         if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) {
1004                 if (errno != EINTR && errno != EAGAIN) {
1005                         ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
1006                         return AST_ALERT_READ_FAIL;
1007                 }
1008         }
1009
1010         return AST_ALERT_READ_SUCCESS;
1011 }
1012
1013 int ast_channel_alert_writable(struct ast_channel *chan)
1014 {
1015         return chan->alertpipe[1] > -1;
1016 }
1017
1018 int ast_channel_internal_alert_readable(struct ast_channel *chan)
1019 {
1020         return chan->alertpipe[0] > -1;
1021 }
1022
1023 void ast_channel_internal_alertpipe_clear(struct ast_channel *chan)
1024 {
1025         chan->alertpipe[0] = chan->alertpipe[1] = -1;
1026 }
1027
1028 void ast_channel_internal_alertpipe_close(struct ast_channel *chan)
1029 {
1030         if (ast_channel_internal_alert_readable(chan)) {
1031                 close(chan->alertpipe[0]);
1032         }
1033         if (ast_channel_alert_writable(chan)) {
1034                 close(chan->alertpipe[1]);
1035         }
1036 }
1037
1038 int ast_channel_internal_alertpipe_init(struct ast_channel *chan)
1039 {
1040         if (pipe(chan->alertpipe)) {
1041                 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n");
1042                 return -1;
1043         } else {
1044                 int flags = fcntl(chan->alertpipe[0], F_GETFL);
1045                 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
1046                         ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
1047                         return -1;
1048                 }
1049                 flags = fcntl(chan->alertpipe[1], F_GETFL);
1050                 if (fcntl(chan->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
1051                         ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
1052                         return -1;
1053                 }
1054         }
1055         return 0;
1056 }
1057
1058 int ast_channel_internal_alert_readfd(struct ast_channel *chan)
1059 {
1060         return chan->alertpipe[0];
1061 }
1062
1063 void ast_channel_internal_alertpipe_swap(struct ast_channel *chan1, struct ast_channel *chan2)
1064 {
1065         int i;
1066         for (i = 0; i < ARRAY_LEN(chan1->alertpipe); i++) {
1067                 SWAP(chan1->alertpipe[i], chan2->alertpipe[i]);
1068         }
1069 }
1070
1071 /* file descriptor array accessors */
1072 void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
1073 {
1074         chan->fds[which] = value;
1075 }
1076 void ast_channel_internal_fd_clear(struct ast_channel *chan, int which)
1077 {
1078         ast_channel_internal_fd_set(chan, which, -1);
1079 }
1080 void ast_channel_internal_fd_clear_all(struct ast_channel *chan)
1081 {
1082         int i;
1083         for (i = 0; i < AST_MAX_FDS; i++) {
1084                 ast_channel_internal_fd_clear(chan, i);
1085         }
1086 }
1087 int ast_channel_fd(const struct ast_channel *chan, int which)
1088 {
1089         return chan->fds[which];
1090 }
1091 int ast_channel_fd_isset(const struct ast_channel *chan, int which)
1092 {
1093         return ast_channel_fd(chan, which) > -1;
1094 }
1095
1096 #ifdef HAVE_EPOLL
1097 struct ast_epoll_data *ast_channel_internal_epfd_data(const struct ast_channel *chan, int which)
1098 {
1099         return chan->epfd_data[which];
1100 }
1101 void ast_channel_internal_epfd_data_set(struct ast_channel *chan, int which , struct ast_epoll_data *value)
1102 {
1103         chan->epfd_data[which] = value;
1104 }
1105 #endif
1106
1107 pthread_t ast_channel_blocker(const struct ast_channel *chan)
1108 {
1109         return chan->blocker;
1110 }
1111 void ast_channel_blocker_set(struct ast_channel *chan, pthread_t value)
1112 {
1113         chan->blocker = value;
1114 }
1115
1116 ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
1117 {
1118         return chan->timingfunc;
1119 }
1120 void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value)
1121 {
1122         chan->timingfunc = value;
1123 }
1124
1125 struct ast_bridge *ast_channel_internal_bridge(const struct ast_channel *chan)
1126 {
1127         return chan->bridge;
1128 }
1129 void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value)
1130 {
1131         chan->bridge = value;
1132 }
1133
1134 struct ast_channel *ast_channel_internal_bridged_channel(const struct ast_channel *chan)
1135 {
1136         return chan->bridged_channel;
1137 }
1138 void ast_channel_internal_bridged_channel_set(struct ast_channel *chan, struct ast_channel *value)
1139 {
1140         chan->bridged_channel = value;
1141 }
1142
1143 struct ast_flags *ast_channel_flags(struct ast_channel *chan)
1144 {
1145         return &chan->flags;
1146 }
1147
1148 struct ast_channel *__ast_channel_internal_alloc(void (*destructor)(void *obj), const char *file, int line, const char *function)
1149 {
1150         struct ast_channel *tmp;
1151 #if defined(REF_DEBUG)
1152         tmp = __ao2_alloc_debug(sizeof(*tmp), destructor,
1153                 AO2_ALLOC_OPT_LOCK_MUTEX, "", file, line, function, 1);
1154 #elif defined(__AST_DEBUG_MALLOC)
1155         tmp = __ao2_alloc_debug(sizeof(*tmp), destructor,
1156                 AO2_ALLOC_OPT_LOCK_MUTEX, "", file, line, function, 0);
1157 #else
1158         tmp = ao2_alloc(sizeof(*tmp), destructor);
1159 #endif
1160
1161         if ((ast_string_field_init(tmp, 128))) {
1162                 return ast_channel_unref(tmp);
1163         }
1164
1165         return tmp;
1166 }
1167
1168 void ast_channel_internal_cleanup(struct ast_channel *chan)
1169 {
1170         ast_string_field_free_memory(chan);
1171 }
1172
1173 void ast_channel_internal_finalize(struct ast_channel *chan)
1174 {
1175         chan->finalized = 1;
1176 }
1177
1178 int ast_channel_internal_is_finalized(struct ast_channel *chan)
1179 {
1180         return chan->finalized;
1181 }