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