Opaquify ast_channel typedefs, fd arrays, and softhangup flag
[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
42 /* AST_DATA definitions, which will probably have to be re-thought since the channel will be opaque */
43
44 #if 0   /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
45 #define DATA_EXPORT_CALLERID(MEMBER)                            \
46         MEMBER(ast_callerid, cid_dnid, AST_DATA_STRING)         \
47         MEMBER(ast_callerid, cid_num, AST_DATA_STRING)          \
48         MEMBER(ast_callerid, cid_name, AST_DATA_STRING)         \
49         MEMBER(ast_callerid, cid_ani, AST_DATA_STRING)          \
50         MEMBER(ast_callerid, cid_pres, AST_DATA_INTEGER)        \
51         MEMBER(ast_callerid, cid_ani2, AST_DATA_INTEGER)        \
52         MEMBER(ast_callerid, cid_tag, AST_DATA_STRING)
53
54 AST_DATA_STRUCTURE(ast_callerid, DATA_EXPORT_CALLERID);
55 #endif
56
57 #define DATA_EXPORT_CHANNEL(MEMBER)                                             \
58         MEMBER(ast_channel, __do_not_use_blockproc, AST_DATA_STRING)                            \
59         MEMBER(ast_channel, __do_not_use_appl, AST_DATA_STRING)                         \
60         MEMBER(ast_channel, __do_not_use_data, AST_DATA_STRING)                         \
61         MEMBER(ast_channel, __do_not_use_name, AST_DATA_STRING) \
62         MEMBER(ast_channel, __do_not_use_language, AST_DATA_STRING)                             \
63         MEMBER(ast_channel, __do_not_use_musicclass, AST_DATA_STRING)                   \
64         MEMBER(ast_channel, __do_not_use_accountcode, AST_DATA_STRING)                  \
65         MEMBER(ast_channel, __do_not_use_peeraccount, AST_DATA_STRING)                  \
66         MEMBER(ast_channel, __do_not_use_userfield, AST_DATA_STRING)                            \
67         MEMBER(ast_channel, __do_not_use_call_forward, AST_DATA_STRING)                 \
68         MEMBER(ast_channel, __do_not_use_uniqueid, AST_DATA_STRING)                             \
69         MEMBER(ast_channel, __do_not_use_linkedid, AST_DATA_STRING)                             \
70         MEMBER(ast_channel, __do_not_use_parkinglot, AST_DATA_STRING)                   \
71         MEMBER(ast_channel, __do_not_use_hangupsource, AST_DATA_STRING)                 \
72         MEMBER(ast_channel, __do_not_use_dialcontext, AST_DATA_STRING)                  \
73         MEMBER(ast_channel, __do_not_use_rings, AST_DATA_INTEGER)                               \
74         MEMBER(ast_channel, __do_not_use_priority, AST_DATA_INTEGER)                            \
75         MEMBER(ast_channel, __do_not_use_macropriority, AST_DATA_INTEGER)                       \
76         MEMBER(ast_channel, __do_not_use_adsicpe, AST_DATA_INTEGER)                             \
77         MEMBER(ast_channel, __do_not_use_fin, AST_DATA_UNSIGNED_INTEGER)                        \
78         MEMBER(ast_channel, __do_not_use_fout, AST_DATA_UNSIGNED_INTEGER)                       \
79         MEMBER(ast_channel, __do_not_use_emulate_dtmf_duration, AST_DATA_UNSIGNED_INTEGER)      \
80         MEMBER(ast_channel, __do_not_use_visible_indication, AST_DATA_INTEGER)          \
81         MEMBER(ast_channel, __do_not_use_context, AST_DATA_STRING)                              \
82         MEMBER(ast_channel, __do_not_use_exten, AST_DATA_STRING)                                \
83         MEMBER(ast_channel, __do_not_use_macrocontext, AST_DATA_STRING)                 \
84         MEMBER(ast_channel, __do_not_use_macroexten, AST_DATA_STRING)
85
86 AST_DATA_STRUCTURE(ast_channel, DATA_EXPORT_CHANNEL);
87
88 static void channel_data_add_flags(struct ast_data *tree,
89         struct ast_channel *chan)
90 {
91         ast_data_add_bool(tree, "DEFER_DTMF", ast_test_flag(chan, AST_FLAG_DEFER_DTMF));
92         ast_data_add_bool(tree, "WRITE_INT", ast_test_flag(chan, AST_FLAG_WRITE_INT));
93         ast_data_add_bool(tree, "BLOCKING", ast_test_flag(chan, AST_FLAG_BLOCKING));
94         ast_data_add_bool(tree, "ZOMBIE", ast_test_flag(chan, AST_FLAG_ZOMBIE));
95         ast_data_add_bool(tree, "EXCEPTION", ast_test_flag(chan, AST_FLAG_EXCEPTION));
96         ast_data_add_bool(tree, "MOH", ast_test_flag(chan, AST_FLAG_MOH));
97         ast_data_add_bool(tree, "SPYING", ast_test_flag(chan, AST_FLAG_SPYING));
98         ast_data_add_bool(tree, "NBRIDGE", ast_test_flag(chan, AST_FLAG_NBRIDGE));
99         ast_data_add_bool(tree, "IN_AUTOLOOP", ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP));
100         ast_data_add_bool(tree, "OUTGOING", ast_test_flag(chan, AST_FLAG_OUTGOING));
101         ast_data_add_bool(tree, "IN_DTMF", ast_test_flag(chan, AST_FLAG_IN_DTMF));
102         ast_data_add_bool(tree, "EMULATE_DTMF", ast_test_flag(chan, AST_FLAG_EMULATE_DTMF));
103         ast_data_add_bool(tree, "END_DTMF_ONLY", ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY));
104         ast_data_add_bool(tree, "ANSWERED_ELSEWHERE", ast_test_flag(chan, AST_FLAG_ANSWERED_ELSEWHERE));
105         ast_data_add_bool(tree, "MASQ_NOSTREAM", ast_test_flag(chan, AST_FLAG_MASQ_NOSTREAM));
106         ast_data_add_bool(tree, "BRIDGE_HANGUP_RUN", ast_test_flag(chan, AST_FLAG_BRIDGE_HANGUP_RUN));
107         ast_data_add_bool(tree, "BRIDGE_HANGUP_DONT", ast_test_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT));
108         ast_data_add_bool(tree, "DISABLE_WORKAROUNDS", ast_test_flag(chan, AST_FLAG_DISABLE_WORKAROUNDS));
109 }
110
111 int ast_channel_data_add_structure(struct ast_data *tree,
112         struct ast_channel *chan, int add_bridged)
113 {
114         struct ast_channel *bc;
115         struct ast_data *data_bridged;
116         struct ast_data *data_cdr;
117         struct ast_data *data_flags;
118         struct ast_data *data_zones;
119         struct ast_data *enum_node;
120         struct ast_data *data_softhangup;
121 #if 0   /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
122         struct ast_data *data_callerid;
123         char value_str[100];
124 #endif
125
126         if (!tree) {
127                 return -1;
128         }
129
130         ast_data_add_structure(ast_channel, tree, chan);
131
132         if (add_bridged) {
133                 bc = ast_bridged_channel(chan);
134                 if (bc) {
135                         data_bridged = ast_data_add_node(tree, "bridged");
136                         if (!data_bridged) {
137                                 return -1;
138                         }
139                         ast_channel_data_add_structure(data_bridged, bc, 0);
140                 }
141         }
142
143         ast_data_add_codec(tree, "oldwriteformat", ast_channel_oldwriteformat(chan));
144         ast_data_add_codec(tree, "readformat", ast_channel_readformat(chan));
145         ast_data_add_codec(tree, "writeformat", ast_channel_writeformat(chan));
146         ast_data_add_codec(tree, "rawreadformat", ast_channel_rawreadformat(chan));
147         ast_data_add_codec(tree, "rawwriteformat", ast_channel_rawwriteformat(chan));
148         ast_data_add_codecs(tree, "nativeformats", ast_channel_nativeformats(chan));
149
150         /* state */
151         enum_node = ast_data_add_node(tree, "state");
152         if (!enum_node) {
153                 return -1;
154         }
155         ast_data_add_str(enum_node, "text", ast_state2str(ast_channel_state(chan)));
156         ast_data_add_int(enum_node, "value", ast_channel_state(chan));
157
158         /* hangupcause */
159         enum_node = ast_data_add_node(tree, "hangupcause");
160         if (!enum_node) {
161                 return -1;
162         }
163         ast_data_add_str(enum_node, "text", ast_cause2str(ast_channel_hangupcause(chan)));
164         ast_data_add_int(enum_node, "value", ast_channel_hangupcause(chan));
165
166         /* amaflags */
167         enum_node = ast_data_add_node(tree, "amaflags");
168         if (!enum_node) {
169                 return -1;
170         }
171         ast_data_add_str(enum_node, "text", ast_cdr_flags2str(ast_channel_amaflags(chan)));
172         ast_data_add_int(enum_node, "value", ast_channel_amaflags(chan));
173
174         /* transfercapability */
175         enum_node = ast_data_add_node(tree, "transfercapability");
176         if (!enum_node) {
177                 return -1;
178         }
179         ast_data_add_str(enum_node, "text", ast_transfercapability2str(ast_channel_transfercapability(chan)));
180         ast_data_add_int(enum_node, "value", ast_channel_transfercapability(chan));
181
182         /* _softphangup */
183         data_softhangup = ast_data_add_node(tree, "softhangup");
184         if (!data_softhangup) {
185                 return -1;
186         }
187         ast_data_add_bool(data_softhangup, "dev", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_DEV);
188         ast_data_add_bool(data_softhangup, "asyncgoto", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO);
189         ast_data_add_bool(data_softhangup, "shutdown", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_SHUTDOWN);
190         ast_data_add_bool(data_softhangup, "timeout", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_TIMEOUT);
191         ast_data_add_bool(data_softhangup, "appunload", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_APPUNLOAD);
192         ast_data_add_bool(data_softhangup, "explicit", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_EXPLICIT);
193         ast_data_add_bool(data_softhangup, "unbridge", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_UNBRIDGE);
194
195         /* channel flags */
196         data_flags = ast_data_add_node(tree, "flags");
197         if (!data_flags) {
198                 return -1;
199         }
200         channel_data_add_flags(data_flags, chan);
201
202         ast_data_add_uint(tree, "timetohangup", ast_channel_whentohangup(chan)->tv_sec);
203
204 #if 0   /* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
205         /* callerid */
206         data_callerid = ast_data_add_node(tree, "callerid");
207         if (!data_callerid) {
208                 return -1;
209         }
210         ast_data_add_structure(ast_callerid, data_callerid, &(chan->cid));
211         /* insert the callerid ton */
212         enum_node = ast_data_add_node(data_callerid, "cid_ton");
213         if (!enum_node) {
214                 return -1;
215         }
216         ast_data_add_int(enum_node, "value", chan->cid.cid_ton);
217         snprintf(value_str, sizeof(value_str), "TON: %s/Plan: %s",
218                 party_number_ton2str(chan->cid.cid_ton),
219                 party_number_plan2str(chan->cid.cid_ton));
220         ast_data_add_str(enum_node, "text", value_str);
221 #endif
222
223         /* tone zone */
224         if (ast_channel_zone(chan)) {
225                 data_zones = ast_data_add_node(tree, "zone");
226                 if (!data_zones) {
227                         return -1;
228                 }
229                 ast_tone_zone_data_add_structure(data_zones, ast_channel_zone(chan));
230         }
231
232         /* insert cdr */
233         data_cdr = ast_data_add_node(tree, "cdr");
234         if (!data_cdr) {
235                 return -1;
236         }
237
238         ast_cdr_data_add_structure(data_cdr, ast_channel_cdr(chan), 1);
239
240         return 0;
241 }
242
243 int ast_channel_data_cmp_structure(const struct ast_data_search *tree,
244         struct ast_channel *chan, const char *structure_name)
245 {
246         return ast_data_search_cmp_structure(tree, ast_channel, chan, structure_name);
247 }
248
249 /* ACCESSORS */
250
251 #define DEFINE_STRINGFIELD_SETTERS_FOR(field) \
252 void ast_channel_##field##_set(struct ast_channel *chan, const char *value) \
253 { \
254         ast_string_field_set(chan, __do_not_use_##field, value); \
255 } \
256   \
257 void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) \
258 { \
259         ast_string_field_build_va(chan, __do_not_use_##field, fmt, ap); \
260 } \
261 void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) \
262 { \
263         va_list ap; \
264         va_start(ap, fmt); \
265         ast_channel_##field##_build_va(chan, fmt, ap); \
266         va_end(ap); \
267 }
268
269 DEFINE_STRINGFIELD_SETTERS_FOR(name)
270 DEFINE_STRINGFIELD_SETTERS_FOR(language)
271 DEFINE_STRINGFIELD_SETTERS_FOR(musicclass)
272 DEFINE_STRINGFIELD_SETTERS_FOR(accountcode)
273 DEFINE_STRINGFIELD_SETTERS_FOR(peeraccount)
274 DEFINE_STRINGFIELD_SETTERS_FOR(userfield)
275 DEFINE_STRINGFIELD_SETTERS_FOR(call_forward)
276 DEFINE_STRINGFIELD_SETTERS_FOR(uniqueid)
277 DEFINE_STRINGFIELD_SETTERS_FOR(linkedid)
278 DEFINE_STRINGFIELD_SETTERS_FOR(parkinglot)
279 DEFINE_STRINGFIELD_SETTERS_FOR(hangupsource)
280 DEFINE_STRINGFIELD_SETTERS_FOR(dialcontext)
281
282 #define DEFINE_STRINGFIELD_GETTER_FOR(field) const char *ast_channel_##field(const struct ast_channel *chan) \
283 { \
284         return chan->__do_not_use_##field; \
285 }
286
287 DEFINE_STRINGFIELD_GETTER_FOR(name)
288 DEFINE_STRINGFIELD_GETTER_FOR(language)
289 DEFINE_STRINGFIELD_GETTER_FOR(musicclass)
290 DEFINE_STRINGFIELD_GETTER_FOR(accountcode)
291 DEFINE_STRINGFIELD_GETTER_FOR(peeraccount)
292 DEFINE_STRINGFIELD_GETTER_FOR(userfield)
293 DEFINE_STRINGFIELD_GETTER_FOR(call_forward)
294 DEFINE_STRINGFIELD_GETTER_FOR(uniqueid)
295 DEFINE_STRINGFIELD_GETTER_FOR(linkedid)
296 DEFINE_STRINGFIELD_GETTER_FOR(parkinglot)
297 DEFINE_STRINGFIELD_GETTER_FOR(hangupsource)
298 DEFINE_STRINGFIELD_GETTER_FOR(dialcontext)
299
300 const char *ast_channel_appl(const struct ast_channel *chan)
301 {
302         return chan->__do_not_use_appl;
303 }
304 void ast_channel_appl_set(struct ast_channel *chan, const char *value)
305 {
306         chan->__do_not_use_appl = value;
307 }
308 const char *ast_channel_blockproc(const struct ast_channel *chan)
309 {
310         return chan->__do_not_use_blockproc;
311 }
312 void ast_channel_blockproc_set(struct ast_channel *chan, const char *value)
313 {
314         chan->__do_not_use_blockproc = value;
315 }
316 const char *ast_channel_data(const struct ast_channel *chan)
317 {
318         return chan->__do_not_use_data;
319 }
320 void ast_channel_data_set(struct ast_channel *chan, const char *value)
321 {
322         chan->__do_not_use_data = value;
323 }
324
325
326 const char *ast_channel_context(const struct ast_channel *chan)
327 {
328         return chan->__do_not_use_context;
329 }
330 void ast_channel_context_set(struct ast_channel *chan, const char *value)
331 {
332         ast_copy_string(chan->__do_not_use_context, value, sizeof(chan->__do_not_use_context));
333 }
334 const char *ast_channel_exten(const struct ast_channel *chan)
335 {
336         return chan->__do_not_use_exten;
337 }
338 void ast_channel_exten_set(struct ast_channel *chan, const char *value)
339 {
340         ast_copy_string(chan->__do_not_use_exten, value, sizeof(chan->__do_not_use_exten));
341 }
342 const char *ast_channel_macrocontext(const struct ast_channel *chan)
343 {
344         return chan->__do_not_use_macrocontext;
345 }
346 void ast_channel_macrocontext_set(struct ast_channel *chan, const char *value)
347 {
348         ast_copy_string(chan->__do_not_use_macrocontext, value, sizeof(chan->__do_not_use_macrocontext));
349 }
350 const char *ast_channel_macroexten(const struct ast_channel *chan)
351 {
352         return chan->__do_not_use_macroexten;
353 }
354 void ast_channel_macroexten_set(struct ast_channel *chan, const char *value)
355 {
356         ast_copy_string(chan->__do_not_use_macroexten, value, sizeof(chan->__do_not_use_macroexten));
357 }
358
359
360 char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan)
361 {
362         return chan->__do_not_use_dtmf_digit_to_emulate;
363 }
364 void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value)
365 {
366         chan->__do_not_use_dtmf_digit_to_emulate = value;
367 }
368 int ast_channel_amaflags(const struct ast_channel *chan)
369 {
370         return chan->__do_not_use_amaflags;
371 }
372 void ast_channel_amaflags_set(struct ast_channel *chan, int value)
373 {
374         chan->__do_not_use_amaflags = value;
375 }
376 #ifdef HAVE_EPOLL
377 int ast_channel_epfd(const struct ast_channel *chan)
378 {
379         return chan->__do_not_use_epfd;
380 }
381 void ast_channel_epfd_set(struct ast_channel *chan, int value)
382 {
383         chan->__do_not_use_epfd = value;
384 }
385 #endif
386 int ast_channel_fdno(const struct ast_channel *chan)
387 {
388         return chan->__do_not_use_fdno;
389 }
390 void ast_channel_fdno_set(struct ast_channel *chan, int value)
391 {
392         chan->__do_not_use_fdno = value;
393 }
394 int ast_channel_hangupcause(const struct ast_channel *chan)
395 {
396         return chan->__do_not_use_hangupcause;
397 }
398 void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
399 {
400         chan->__do_not_use_hangupcause = value;
401 }
402 int ast_channel_macropriority(const struct ast_channel *chan)
403 {
404         return chan->__do_not_use_macropriority;
405 }
406 void ast_channel_macropriority_set(struct ast_channel *chan, int value)
407 {
408         chan->__do_not_use_macropriority = value;
409 }
410 int ast_channel_priority(const struct ast_channel *chan)
411 {
412         return chan->__do_not_use_priority;
413 }
414 void ast_channel_priority_set(struct ast_channel *chan, int value)
415 {
416         chan->__do_not_use_priority = value;
417 }
418 int ast_channel_rings(const struct ast_channel *chan)
419 {
420         return chan->__do_not_use_rings;
421 }
422 void ast_channel_rings_set(struct ast_channel *chan, int value)
423 {
424         chan->__do_not_use_rings = value;
425 }
426 int ast_channel_streamid(const struct ast_channel *chan)
427 {
428         return chan->__do_not_use_streamid;
429 }
430 void ast_channel_streamid_set(struct ast_channel *chan, int value)
431 {
432         chan->__do_not_use_streamid = value;
433 }
434 int ast_channel_timingfd(const struct ast_channel *chan)
435 {
436         return chan->__do_not_use_timingfd;
437 }
438 void ast_channel_timingfd_set(struct ast_channel *chan, int value)
439 {
440         chan->__do_not_use_timingfd = value;
441 }
442 int ast_channel_visible_indication(const struct ast_channel *chan)
443 {
444         return chan->__do_not_use_visible_indication;
445 }
446 void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
447 {
448         chan->__do_not_use_visible_indication = value;
449 }
450 int ast_channel_vstreamid(const struct ast_channel *chan)
451 {
452         return chan->__do_not_use_vstreamid;
453 }
454 void ast_channel_vstreamid_set(struct ast_channel *chan, int value)
455 {
456         chan->__do_not_use_vstreamid = value;
457 }
458 unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
459 {
460         return chan->__do_not_use_transfercapability;
461 }
462 void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
463 {
464         chan->__do_not_use_transfercapability = value;
465 }
466 unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan)
467 {
468         return chan->__do_not_use_emulate_dtmf_duration;
469 }
470 void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value)
471 {
472         chan->__do_not_use_emulate_dtmf_duration = value;
473 }
474 unsigned int ast_channel_fin(const struct ast_channel *chan)
475 {
476         return chan->__do_not_use_fin;
477 }
478 void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
479 {
480         chan->__do_not_use_fin = value;
481 }
482 unsigned int ast_channel_fout(const struct ast_channel *chan)
483 {
484         return chan->__do_not_use_fout;
485 }
486 void ast_channel_fout_set(struct ast_channel *chan, unsigned int value)
487 {
488         chan->__do_not_use_fout = value;
489 }
490 unsigned long ast_channel_insmpl(const struct ast_channel *chan)
491 {
492         return chan->__do_not_use_insmpl;
493 }
494 void ast_channel_insmpl_set(struct ast_channel *chan, unsigned long value)
495 {
496         chan->__do_not_use_insmpl = value;
497 }
498 unsigned long ast_channel_outsmpl(const struct ast_channel *chan)
499 {
500         return chan->__do_not_use_outsmpl;
501 }
502 void ast_channel_outsmpl_set(struct ast_channel *chan, unsigned long value)
503 {
504         chan->__do_not_use_outsmpl = value;
505 }
506 void *ast_channel_generatordata(const struct ast_channel *chan)
507 {
508         return chan->__do_not_use_generatordata;
509 }
510 void ast_channel_generatordata_set(struct ast_channel *chan, void *value)
511 {
512         chan->__do_not_use_generatordata = value;
513 }
514 void *ast_channel_music_state(const struct ast_channel *chan)
515 {
516         return chan->__do_not_use_music_state;
517 }
518 void ast_channel_music_state_set(struct ast_channel *chan, void *value)
519 {
520         chan->__do_not_use_music_state = value;
521 }
522 void *ast_channel_tech_pvt(const struct ast_channel *chan)
523 {
524         return chan->__do_not_use_tech_pvt;
525 }
526 void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
527 {
528         chan->__do_not_use_tech_pvt = value;
529 }
530 void *ast_channel_timingdata(const struct ast_channel *chan)
531 {
532         return chan->__do_not_use_timingdata;
533 }
534 void ast_channel_timingdata_set(struct ast_channel *chan, void *value)
535 {
536         chan->__do_not_use_timingdata = value;
537 }
538 struct ast_audiohook_list *ast_channel_audiohooks(const struct ast_channel *chan)
539 {
540         return chan->__do_not_use_audiohooks;
541 }
542 void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
543 {
544         chan->__do_not_use_audiohooks = value;
545 }
546 struct ast_cdr *ast_channel_cdr(const struct ast_channel *chan)
547 {
548         return chan->__do_not_use_cdr;
549 }
550 void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value)
551 {
552         chan->__do_not_use_cdr = value;
553 }
554 struct ast_channel *ast_channel_masq(const struct ast_channel *chan)
555 {
556         return chan->__do_not_use_masq;
557 }
558 void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value)
559 {
560         chan->__do_not_use_masq = value;
561 }
562 struct ast_channel *ast_channel_masqr(const struct ast_channel *chan)
563 {
564         return chan->__do_not_use_masqr;
565 }
566 void ast_channel_masqr_set(struct ast_channel *chan, struct ast_channel *value)
567 {
568         chan->__do_not_use_masqr = value;
569 }
570 struct ast_channel_monitor *ast_channel_monitor(const struct ast_channel *chan)
571 {
572         return chan->__do_not_use_monitor;
573 }
574 void ast_channel_monitor_set(struct ast_channel *chan, struct ast_channel_monitor *value)
575 {
576         chan->__do_not_use_monitor = value;
577 }
578 struct ast_filestream *ast_channel_stream(const struct ast_channel *chan)
579 {
580         return chan->__do_not_use_stream;
581 }
582 void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
583 {
584         chan->__do_not_use_stream = value;
585 }
586 struct ast_filestream *ast_channel_vstream(const struct ast_channel *chan)
587 {
588         return chan->__do_not_use_vstream;
589 }
590 void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
591 {
592         chan->__do_not_use_vstream = value;
593 }
594 struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan)
595 {
596         return chan->__do_not_use_nativeformats;
597 }
598 void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
599 {
600         chan->__do_not_use_nativeformats = value;
601 }
602 struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan)
603 {
604         return chan->__do_not_use_framehooks;
605 }
606 void ast_channel_framehooks_set(struct ast_channel *chan, struct ast_framehook_list *value)
607 {
608         chan->__do_not_use_framehooks = value;
609 }
610 struct ast_generator *ast_channel_generator(const struct ast_channel *chan)
611 {
612         return chan->__do_not_use_generator;
613 }
614 void ast_channel_generator_set(struct ast_channel *chan, struct ast_generator *value)
615 {
616         chan->__do_not_use_generator = value;
617 }
618 struct ast_pbx *ast_channel_pbx(const struct ast_channel *chan)
619 {
620         return chan->__do_not_use_pbx;
621 }
622 void ast_channel_pbx_set(struct ast_channel *chan, struct ast_pbx *value)
623 {
624         chan->__do_not_use_pbx = value;
625 }
626 struct ast_sched_context *ast_channel_sched(const struct ast_channel *chan)
627 {
628         return chan->__do_not_use_sched;
629 }
630 void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value)
631 {
632         chan->__do_not_use_sched = value;
633 }
634 struct ast_timer *ast_channel_timer(const struct ast_channel *chan)
635 {
636         return chan->__do_not_use_timer;
637 }
638 void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value)
639 {
640         chan->__do_not_use_timer = value;
641 }
642 struct ast_tone_zone *ast_channel_zone(const struct ast_channel *chan)
643 {
644         return chan->__do_not_use_zone;
645 }
646 void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
647 {
648         chan->__do_not_use_zone = value;
649 }
650 struct ast_trans_pvt *ast_channel_readtrans(const struct ast_channel *chan)
651 {
652         return chan->__do_not_use_readtrans;
653 }
654 void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
655 {
656         chan->__do_not_use_readtrans = value;
657 }
658 struct ast_trans_pvt *ast_channel_writetrans(const struct ast_channel *chan)
659 {
660         return chan->__do_not_use_writetrans;
661 }
662 void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
663 {
664         chan->__do_not_use_writetrans = value;
665 }
666 const struct ast_channel_tech *ast_channel_tech(const struct ast_channel *chan)
667 {
668         return chan->__do_not_use_tech;
669 }
670 void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
671 {
672         chan->__do_not_use_tech = value;
673 }
674 enum ast_channel_adsicpe ast_channel_adsicpe(const struct ast_channel *chan)
675 {
676         return chan->__do_not_use_adsicpe;
677 }
678 void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
679 {
680         chan->__do_not_use_adsicpe = value;
681 }
682 enum ast_channel_state ast_channel_state(const struct ast_channel *chan)
683 {
684         return chan->__do_not_use_state;
685 }
686 void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state value)
687 {
688         chan->__do_not_use_state = value;
689 }
690 struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan)
691 {
692         return &chan->__do_not_use_oldwriteformat;
693 }
694 struct ast_format *ast_channel_rawreadformat(struct ast_channel *chan)
695 {
696         return &chan->__do_not_use_rawreadformat;
697 }
698 struct ast_format *ast_channel_rawwriteformat(struct ast_channel *chan)
699 {
700         return &chan->__do_not_use_rawwriteformat;
701 }
702 struct ast_format *ast_channel_readformat(struct ast_channel *chan)
703 {
704         return &chan->__do_not_use_readformat;
705 }
706 struct ast_format *ast_channel_writeformat(struct ast_channel *chan)
707 {
708         return &chan->__do_not_use_writeformat;
709 }
710 struct ast_datastore_list *ast_channel_datastores(struct ast_channel *chan)
711 {
712         return &chan->__do_not_use_datastores;
713 }
714 struct ast_autochan_list *ast_channel_autochans(struct ast_channel *chan)
715 {
716         return &chan->__do_not_use_autochans;
717 }
718 struct ast_readq_list *ast_channel_readq(struct ast_channel *chan)
719 {
720         return &chan->__do_not_use_readq;
721 }
722 struct ast_frame *ast_channel_dtmff(struct ast_channel *chan)
723 {
724         return &chan->__do_not_use_dtmff;
725 }
726 struct ast_jb *ast_channel_jb(struct ast_channel *chan)
727 {
728         return &chan->__do_not_use_jb;
729 }
730 struct ast_party_caller *ast_channel_caller(struct ast_channel *chan)
731 {
732         return &chan->__do_not_use_caller;
733 }
734 struct ast_party_connected_line *ast_channel_connected(struct ast_channel *chan)
735 {
736         return &chan->__do_not_use_connected;
737 }
738 struct ast_party_dialed *ast_channel_dialed(struct ast_channel *chan)
739 {
740         return &chan->__do_not_use_dialed;
741 }
742 struct ast_party_redirecting *ast_channel_redirecting(struct ast_channel *chan)
743 {
744         return &chan->__do_not_use_redirecting;
745 }
746 struct timeval *ast_channel_dtmf_tv(struct ast_channel *chan)
747 {
748         return &chan->__do_not_use_dtmf_tv;
749 }
750 struct timeval *ast_channel_whentohangup(struct ast_channel *chan)
751 {
752         return &chan->__do_not_use_whentohangup;
753 }
754 struct varshead *ast_channel_varshead(struct ast_channel *chan)
755 {
756         return &chan->__do_not_use_varshead;
757 }
758 void ast_channel_dtmff_set(struct ast_channel *chan, struct ast_frame *value)
759 {
760         memcpy(&chan->__do_not_use_dtmff, value, sizeof(chan->__do_not_use_dtmff));
761 }
762 void ast_channel_jb_set(struct ast_channel *chan, struct ast_jb *value)
763 {
764         memcpy(&chan->__do_not_use_jb, value, sizeof(chan->__do_not_use_jb));
765 }
766 void ast_channel_caller_set(struct ast_channel *chan, struct ast_party_caller *value)
767 {
768         memcpy(&chan->__do_not_use_caller, value, sizeof(chan->__do_not_use_caller));
769 }
770 void ast_channel_connected_set(struct ast_channel *chan, struct ast_party_connected_line *value)
771 {
772         memcpy(&chan->__do_not_use_connected, value, sizeof(chan->__do_not_use_connected));
773 }
774 void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value)
775 {
776         memcpy(&chan->__do_not_use_dialed, value, sizeof(chan->__do_not_use_dialed));
777 }
778 void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value)
779 {
780         memcpy(&chan->__do_not_use_redirecting, value, sizeof(chan->__do_not_use_redirecting));
781 }
782 void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value)
783 {
784         memcpy(&chan->__do_not_use_dtmf_tv, value, sizeof(chan->__do_not_use_dtmf_tv));
785 }
786 void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
787 {
788         memcpy(&chan->__do_not_use_whentohangup, value, sizeof(chan->__do_not_use_whentohangup));
789 }
790 void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value)
791 {
792         memcpy(&chan->__do_not_use_varshead, value, sizeof(chan->__do_not_use_varshead));
793 }
794
795 /* Evil softhangup accessors */
796 int ast_channel_softhangup_internal_flag(struct ast_channel * chan)
797 {
798         return chan->__do_not_use_softhangup;
799 }
800 void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value)
801 {
802         chan->__do_not_use_softhangup = value;
803 }
804 void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
805 {
806         chan->__do_not_use_softhangup |= value;
807 }
808 void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int value)
809 {
810         chan ->__do_not_use_softhangup &= ~value;
811 }
812
813 /* Typedef accessors */
814 ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
815 {
816         return chan->__do_not_use_callgroup;
817 }
818 void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
819 {
820         chan->__do_not_use_callgroup = value;
821 }
822 ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
823 {
824         return chan->__do_not_use_pickupgroup;
825 }
826 void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
827 {
828         chan->__do_not_use_pickupgroup = value;
829 }
830
831 /* Alertpipe functions */
832 int ast_channel_alert_write(struct ast_channel *chan)
833 {
834         char blah = 0x7F;
835         return ast_channel_alert_writable(chan) && write(chan->__do_not_use_alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
836 }
837
838 ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
839 {
840         int flags;
841         char blah;
842
843         if (!ast_channel_internal_alert_readable(chan)) {
844                 return AST_ALERT_NOT_READABLE;
845         }
846
847         flags = fcntl(chan->__do_not_use_alertpipe[0], F_GETFL);
848         /* For some odd reason, the alertpipe occasionally loses nonblocking status,
849          * which immediately causes a deadlock scenario.  Detect and prevent this. */
850         if ((flags & O_NONBLOCK) == 0) {
851                 ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", ast_channel_name(chan));
852                 if (fcntl(chan->__do_not_use_alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
853                         ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
854                         return AST_ALERT_READ_FATAL;
855                 }
856         }
857         if (read(chan->__do_not_use_alertpipe[0], &blah, sizeof(blah)) < 0) {
858                 if (errno != EINTR && errno != EAGAIN) {
859                         ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
860                         return AST_ALERT_READ_FAIL;
861                 }
862         }
863
864         return AST_ALERT_READ_SUCCESS;
865 }
866
867 int ast_channel_alert_writable(struct ast_channel *chan)
868 {
869         return chan->__do_not_use_alertpipe[1] > -1;
870 }
871
872 int ast_channel_internal_alert_readable(struct ast_channel *chan)
873 {
874         return chan->__do_not_use_alertpipe[0] > -1;
875 }
876
877 void ast_channel_internal_alertpipe_clear(struct ast_channel *chan)
878 {
879         chan->__do_not_use_alertpipe[0] = chan->__do_not_use_alertpipe[1] = -1;
880 }
881
882 void ast_channel_internal_alertpipe_close(struct ast_channel *chan)
883 {
884         if (ast_channel_internal_alert_readable(chan)) {
885                 close(chan->__do_not_use_alertpipe[0]);
886         }
887         if (ast_channel_alert_writable(chan)) {
888                 close(chan->__do_not_use_alertpipe[1]);
889         }
890 }
891
892 int ast_channel_internal_alertpipe_init(struct ast_channel *chan)
893 {
894         if (pipe(chan->__do_not_use_alertpipe)) {
895                 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n");
896                 return -1;
897         } else {
898                 int flags = fcntl(chan->__do_not_use_alertpipe[0], F_GETFL);
899                 if (fcntl(chan->__do_not_use_alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
900                         ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
901                         return -1;
902                 }
903                 flags = fcntl(chan->__do_not_use_alertpipe[1], F_GETFL);
904                 if (fcntl(chan->__do_not_use_alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
905                         ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
906                         return -1;
907                 }
908         }
909         return 0;
910 }
911
912 int ast_channel_internal_alert_readfd(struct ast_channel *chan)
913 {
914         return chan->__do_not_use_alertpipe[0];
915 }
916
917 void ast_channel_internal_alertpipe_swap(struct ast_channel *chan1, struct ast_channel *chan2)
918 {
919         int i;
920         for (i = 0; i < ARRAY_LEN(chan1->__do_not_use_alertpipe); i++) {
921                 SWAP(chan1->__do_not_use_alertpipe[i], chan2->__do_not_use_alertpipe[i]);
922         }
923 }
924
925 /* file descriptor array accessors */
926 void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
927 {
928         chan->__do_not_use_fds[which] = value;
929 }
930 void ast_channel_internal_fd_clear(struct ast_channel *chan, int which)
931 {
932         ast_channel_internal_fd_set(chan, which, -1);
933 }
934 void ast_channel_internal_fd_clear_all(struct ast_channel *chan)
935 {
936         int i;
937         for (i = 0; i < AST_MAX_FDS; i++) {
938                 ast_channel_internal_fd_clear(chan, i);
939         }
940 }
941 int ast_channel_fd(const struct ast_channel *chan, int which)
942 {
943         return chan->__do_not_use_fds[which];
944 }
945 int ast_channel_fd_isset(const struct ast_channel *chan, int which)
946 {
947         return ast_channel_fd(chan, which) > -1;
948 }
949
950 #ifdef HAVE_EPOLL
951 struct ast_epoll_data *ast_channel_internal_epfd_data(const struct ast_channel *chan, int which)
952 {
953         return chan->__do_not_use_epfd_data[which];
954 }
955 void ast_channel_internal_epfd_data_set(struct ast_channel *chan, int which , struct ast_epoll_data *value)
956 {
957         chan->__do_not_use_epfd_data[which] = value;
958 }
959 #endif