summaryrefslogtreecommitdiff
path: root/main/channel_internal_api.c
blob: 0a7060e29e919de9e16097d1111dc36643bf3c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 2012, Digium, Inc.
 *
 * Mark Spencer <markster@digium.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

/*! \file
 *
 * \brief Channel Accessor API
 *
 * This file is intended to be the only file that ever accesses the
 * internals of an ast_channel. All other files should use the
 * accessor functions defined here.
 *
 * \author Terry Wilson
 */

#include "asterisk.h"

ASTERISK_FILE_VERSION(__FILE__, "$Revision$")

#include <unistd.h>
#include <fcntl.h>

#include "asterisk/channel.h"
#include "asterisk/stringfields.h"
#include "asterisk/data.h"
#include "asterisk/indications.h"

/* AST_DATA definitions, which will probably have to be re-thought since the channel will be opaque */

#if 0	/* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
#define DATA_EXPORT_CALLERID(MEMBER)				\
	MEMBER(ast_callerid, cid_dnid, AST_DATA_STRING)		\
	MEMBER(ast_callerid, cid_num, AST_DATA_STRING)		\
	MEMBER(ast_callerid, cid_name, AST_DATA_STRING)		\
	MEMBER(ast_callerid, cid_ani, AST_DATA_STRING)		\
	MEMBER(ast_callerid, cid_pres, AST_DATA_INTEGER)	\
	MEMBER(ast_callerid, cid_ani2, AST_DATA_INTEGER)	\
	MEMBER(ast_callerid, cid_tag, AST_DATA_STRING)

AST_DATA_STRUCTURE(ast_callerid, DATA_EXPORT_CALLERID);
#endif

#define DATA_EXPORT_CHANNEL(MEMBER)						\
	MEMBER(ast_channel, __do_not_use_blockproc, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_appl, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_data, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_name, AST_DATA_STRING) \
	MEMBER(ast_channel, __do_not_use_language, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_musicclass, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_accountcode, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_peeraccount, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_userfield, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_call_forward, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_uniqueid, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_linkedid, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_parkinglot, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_hangupsource, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_dialcontext, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_rings, AST_DATA_INTEGER)				\
	MEMBER(ast_channel, __do_not_use_priority, AST_DATA_INTEGER)				\
	MEMBER(ast_channel, __do_not_use_macropriority, AST_DATA_INTEGER)			\
	MEMBER(ast_channel, __do_not_use_adsicpe, AST_DATA_INTEGER)				\
	MEMBER(ast_channel, __do_not_use_fin, AST_DATA_UNSIGNED_INTEGER)			\
	MEMBER(ast_channel, __do_not_use_fout, AST_DATA_UNSIGNED_INTEGER)			\
	MEMBER(ast_channel, __do_not_use_emulate_dtmf_duration, AST_DATA_UNSIGNED_INTEGER)	\
	MEMBER(ast_channel, __do_not_use_visible_indication, AST_DATA_INTEGER)		\
	MEMBER(ast_channel, __do_not_use_context, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_exten, AST_DATA_STRING)				\
	MEMBER(ast_channel, __do_not_use_macrocontext, AST_DATA_STRING)			\
	MEMBER(ast_channel, __do_not_use_macroexten, AST_DATA_STRING)

AST_DATA_STRUCTURE(ast_channel, DATA_EXPORT_CHANNEL);

static void channel_data_add_flags(struct ast_data *tree,
	struct ast_channel *chan)
{
	ast_data_add_bool(tree, "DEFER_DTMF", ast_test_flag(chan, AST_FLAG_DEFER_DTMF));
	ast_data_add_bool(tree, "WRITE_INT", ast_test_flag(chan, AST_FLAG_WRITE_INT));
	ast_data_add_bool(tree, "BLOCKING", ast_test_flag(chan, AST_FLAG_BLOCKING));
	ast_data_add_bool(tree, "ZOMBIE", ast_test_flag(chan, AST_FLAG_ZOMBIE));
	ast_data_add_bool(tree, "EXCEPTION", ast_test_flag(chan, AST_FLAG_EXCEPTION));
	ast_data_add_bool(tree, "MOH", ast_test_flag(chan, AST_FLAG_MOH));
	ast_data_add_bool(tree, "SPYING", ast_test_flag(chan, AST_FLAG_SPYING));
	ast_data_add_bool(tree, "NBRIDGE", ast_test_flag(chan, AST_FLAG_NBRIDGE));
	ast_data_add_bool(tree, "IN_AUTOLOOP", ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP));
	ast_data_add_bool(tree, "OUTGOING", ast_test_flag(chan, AST_FLAG_OUTGOING));
	ast_data_add_bool(tree, "IN_DTMF", ast_test_flag(chan, AST_FLAG_IN_DTMF));
	ast_data_add_bool(tree, "EMULATE_DTMF", ast_test_flag(chan, AST_FLAG_EMULATE_DTMF));
	ast_data_add_bool(tree, "END_DTMF_ONLY", ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY));
	ast_data_add_bool(tree, "ANSWERED_ELSEWHERE", ast_test_flag(chan, AST_FLAG_ANSWERED_ELSEWHERE));
	ast_data_add_bool(tree, "MASQ_NOSTREAM", ast_test_flag(chan, AST_FLAG_MASQ_NOSTREAM));
	ast_data_add_bool(tree, "BRIDGE_HANGUP_RUN", ast_test_flag(chan, AST_FLAG_BRIDGE_HANGUP_RUN));
	ast_data_add_bool(tree, "BRIDGE_HANGUP_DONT", ast_test_flag(chan, AST_FLAG_BRIDGE_HANGUP_DONT));
	ast_data_add_bool(tree, "DISABLE_WORKAROUNDS", ast_test_flag(chan, AST_FLAG_DISABLE_WORKAROUNDS));
}

int ast_channel_data_add_structure(struct ast_data *tree,
	struct ast_channel *chan, int add_bridged)
{
	struct ast_channel *bc;
	struct ast_data *data_bridged;
	struct ast_data *data_cdr;
	struct ast_data *data_flags;
	struct ast_data *data_zones;
	struct ast_data *enum_node;
	struct ast_data *data_softhangup;
#if 0	/* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
	struct ast_data *data_callerid;
	char value_str[100];
#endif

	if (!tree) {
		return -1;
	}

	ast_data_add_structure(ast_channel, tree, chan);

	if (add_bridged) {
		bc = ast_bridged_channel(chan);
		if (bc) {
			data_bridged = ast_data_add_node(tree, "bridged");
			if (!data_bridged) {
				return -1;
			}
			ast_channel_data_add_structure(data_bridged, bc, 0);
		}
	}

	ast_data_add_codec(tree, "oldwriteformat", ast_channel_oldwriteformat(chan));
	ast_data_add_codec(tree, "readformat", ast_channel_readformat(chan));
	ast_data_add_codec(tree, "writeformat", ast_channel_writeformat(chan));
	ast_data_add_codec(tree, "rawreadformat", ast_channel_rawreadformat(chan));
	ast_data_add_codec(tree, "rawwriteformat", ast_channel_rawwriteformat(chan));
	ast_data_add_codecs(tree, "nativeformats", ast_channel_nativeformats(chan));

	/* state */
	enum_node = ast_data_add_node(tree, "state");
	if (!enum_node) {
		return -1;
	}
	ast_data_add_str(enum_node, "text", ast_state2str(ast_channel_state(chan)));
	ast_data_add_int(enum_node, "value", ast_channel_state(chan));

	/* hangupcause */
	enum_node = ast_data_add_node(tree, "hangupcause");
	if (!enum_node) {
		return -1;
	}
	ast_data_add_str(enum_node, "text", ast_cause2str(ast_channel_hangupcause(chan)));
	ast_data_add_int(enum_node, "value", ast_channel_hangupcause(chan));

	/* amaflags */
	enum_node = ast_data_add_node(tree, "amaflags");
	if (!enum_node) {
		return -1;
	}
	ast_data_add_str(enum_node, "text", ast_cdr_flags2str(ast_channel_amaflags(chan)));
	ast_data_add_int(enum_node, "value", ast_channel_amaflags(chan));

	/* transfercapability */
	enum_node = ast_data_add_node(tree, "transfercapability");
	if (!enum_node) {
		return -1;
	}
	ast_data_add_str(enum_node, "text", ast_transfercapability2str(ast_channel_transfercapability(chan)));
	ast_data_add_int(enum_node, "value", ast_channel_transfercapability(chan));

	/* _softphangup */
	data_softhangup = ast_data_add_node(tree, "softhangup");
	if (!data_softhangup) {
		return -1;
	}
	ast_data_add_bool(data_softhangup, "dev", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_DEV);
	ast_data_add_bool(data_softhangup, "asyncgoto", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO);
	ast_data_add_bool(data_softhangup, "shutdown", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_SHUTDOWN);
	ast_data_add_bool(data_softhangup, "timeout", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_TIMEOUT);
	ast_data_add_bool(data_softhangup, "appunload", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_APPUNLOAD);
	ast_data_add_bool(data_softhangup, "explicit", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_EXPLICIT);
	ast_data_add_bool(data_softhangup, "unbridge", ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_UNBRIDGE);

	/* channel flags */
	data_flags = ast_data_add_node(tree, "flags");
	if (!data_flags) {
		return -1;
	}
	channel_data_add_flags(data_flags, chan);

	ast_data_add_uint(tree, "timetohangup", ast_channel_whentohangup(chan)->tv_sec);

#if 0	/* XXX AstData: ast_callerid no longer exists. (Equivalent code not readily apparent.) */
	/* callerid */
	data_callerid = ast_data_add_node(tree, "callerid");
	if (!data_callerid) {
		return -1;
	}
	ast_data_add_structure(ast_callerid, data_callerid, &(chan->cid));
	/* insert the callerid ton */
	enum_node = ast_data_add_node(data_callerid, "cid_ton");
	if (!enum_node) {
		return -1;
	}
	ast_data_add_int(enum_node, "value", chan->cid.cid_ton);
	snprintf(value_str, sizeof(value_str), "TON: %s/Plan: %s",
		party_number_ton2str(chan->cid.cid_ton),
		party_number_plan2str(chan->cid.cid_ton));
	ast_data_add_str(enum_node, "text", value_str);
#endif

	/* tone zone */
	if (ast_channel_zone(chan)) {
		data_zones = ast_data_add_node(tree, "zone");
		if (!data_zones) {
			return -1;
		}
		ast_tone_zone_data_add_structure(data_zones, ast_channel_zone(chan));
	}

	/* insert cdr */
	data_cdr = ast_data_add_node(tree, "cdr");
	if (!data_cdr) {
		return -1;
	}

	ast_cdr_data_add_structure(data_cdr, ast_channel_cdr(chan), 1);

	return 0;
}

int ast_channel_data_cmp_structure(const struct ast_data_search *tree,
	struct ast_channel *chan, const char *structure_name)
{
	return ast_data_search_cmp_structure(tree, ast_channel, chan, structure_name);
}

/* ACCESSORS */

#define DEFINE_STRINGFIELD_SETTERS_FOR(field) \
void ast_channel_##field##_set(struct ast_channel *chan, const char *value) \
{ \
	ast_string_field_set(chan, __do_not_use_##field, value); \
} \
  \
void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) \
{ \
	ast_string_field_build_va(chan, __do_not_use_##field, fmt, ap); \
} \
void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) \
{ \
	va_list ap; \
	va_start(ap, fmt); \
	ast_channel_##field##_build_va(chan, fmt, ap); \
	va_end(ap); \
}

DEFINE_STRINGFIELD_SETTERS_FOR(name)
DEFINE_STRINGFIELD_SETTERS_FOR(language)
DEFINE_STRINGFIELD_SETTERS_FOR(musicclass)
DEFINE_STRINGFIELD_SETTERS_FOR(accountcode)
DEFINE_STRINGFIELD_SETTERS_FOR(peeraccount)
DEFINE_STRINGFIELD_SETTERS_FOR(userfield)
DEFINE_STRINGFIELD_SETTERS_FOR(call_forward)
DEFINE_STRINGFIELD_SETTERS_FOR(uniqueid)
DEFINE_STRINGFIELD_SETTERS_FOR(linkedid)
DEFINE_STRINGFIELD_SETTERS_FOR(parkinglot)
DEFINE_STRINGFIELD_SETTERS_FOR(hangupsource)
DEFINE_STRINGFIELD_SETTERS_FOR(dialcontext)

#define DEFINE_STRINGFIELD_GETTER_FOR(field) const char *ast_channel_##field(const struct ast_channel *chan) \
{ \
	return chan->__do_not_use_##field; \
}

DEFINE_STRINGFIELD_GETTER_FOR(name)
DEFINE_STRINGFIELD_GETTER_FOR(language)
DEFINE_STRINGFIELD_GETTER_FOR(musicclass)
DEFINE_STRINGFIELD_GETTER_FOR(accountcode)
DEFINE_STRINGFIELD_GETTER_FOR(peeraccount)
DEFINE_STRINGFIELD_GETTER_FOR(userfield)
DEFINE_STRINGFIELD_GETTER_FOR(call_forward)
DEFINE_STRINGFIELD_GETTER_FOR(uniqueid)
DEFINE_STRINGFIELD_GETTER_FOR(linkedid)
DEFINE_STRINGFIELD_GETTER_FOR(parkinglot)
DEFINE_STRINGFIELD_GETTER_FOR(hangupsource)
DEFINE_STRINGFIELD_GETTER_FOR(dialcontext)

const char *ast_channel_appl(const struct ast_channel *chan)
{
	return chan->__do_not_use_appl;
}
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
{
	chan->__do_not_use_appl = value;
}
const char *ast_channel_blockproc(const struct ast_channel *chan)
{
	return chan->__do_not_use_blockproc;
}
void ast_channel_blockproc_set(struct ast_channel *chan, const char *value)
{
	chan->__do_not_use_blockproc = value;
}
const char *ast_channel_data(const struct ast_channel *chan)
{
	return chan->__do_not_use_data;
}
void ast_channel_data_set(struct ast_channel *chan, const char *value)
{
	chan->__do_not_use_data = value;
}


const char *ast_channel_context(const struct ast_channel *chan)
{
	return chan->__do_not_use_context;
}
void ast_channel_context_set(struct ast_channel *chan, const char *value)
{
	ast_copy_string(chan->__do_not_use_context, value, sizeof(chan->__do_not_use_context));
}
const char *ast_channel_exten(const struct ast_channel *chan)
{
	return chan->__do_not_use_exten;
}
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
{
	ast_copy_string(chan->__do_not_use_exten, value, sizeof(chan->__do_not_use_exten));
}
const char *ast_channel_macrocontext(const struct ast_channel *chan)
{
	return chan->__do_not_use_macrocontext;
}
void ast_channel_macrocontext_set(struct ast_channel *chan, const char *value)
{
	ast_copy_string(chan->__do_not_use_macrocontext, value, sizeof(chan->__do_not_use_macrocontext));
}
const char *ast_channel_macroexten(const struct ast_channel *chan)
{
	return chan->__do_not_use_macroexten;
}
void ast_channel_macroexten_set(struct ast_channel *chan, const char *value)
{
	ast_copy_string(chan->__do_not_use_macroexten, value, sizeof(chan->__do_not_use_macroexten));
}


char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan)
{
	return chan->__do_not_use_dtmf_digit_to_emulate;
}
void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value)
{
	chan->__do_not_use_dtmf_digit_to_emulate = value;
}
int ast_channel_amaflags(const struct ast_channel *chan)
{
	return chan->__do_not_use_amaflags;
}
void ast_channel_amaflags_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_amaflags = value;
}
#ifdef HAVE_EPOLL
int ast_channel_epfd(const struct ast_channel *chan)
{
	return chan->__do_not_use_epfd;
}
void ast_channel_epfd_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_epfd = value;
}
#endif
int ast_channel_fdno(const struct ast_channel *chan)
{
	return chan->__do_not_use_fdno;
}
void ast_channel_fdno_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_fdno = value;
}
int ast_channel_hangupcause(const struct ast_channel *chan)
{
	return chan->__do_not_use_hangupcause;
}
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_hangupcause = value;
}
int ast_channel_macropriority(const struct ast_channel *chan)
{
	return chan->__do_not_use_macropriority;
}
void ast_channel_macropriority_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_macropriority = value;
}
int ast_channel_priority(const struct ast_channel *chan)
{
	return chan->__do_not_use_priority;
}
void ast_channel_priority_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_priority = value;
}
int ast_channel_rings(const struct ast_channel *chan)
{
	return chan->__do_not_use_rings;
}
void ast_channel_rings_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_rings = value;
}
int ast_channel_streamid(const struct ast_channel *chan)
{
	return chan->__do_not_use_streamid;
}
void ast_channel_streamid_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_streamid = value;
}
int ast_channel_timingfd(const struct ast_channel *chan)
{
	return chan->__do_not_use_timingfd;
}
void ast_channel_timingfd_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_timingfd = value;
}
int ast_channel_visible_indication(const struct ast_channel *chan)
{
	return chan->__do_not_use_visible_indication;
}
void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_visible_indication = value;
}
int ast_channel_vstreamid(const struct ast_channel *chan)
{
	return chan->__do_not_use_vstreamid;
}
void ast_channel_vstreamid_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_vstreamid = value;
}
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
{
	return chan->__do_not_use_transfercapability;
}
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
{
	chan->__do_not_use_transfercapability = value;
}
unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan)
{
	return chan->__do_not_use_emulate_dtmf_duration;
}
void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value)
{
	chan->__do_not_use_emulate_dtmf_duration = value;
}
unsigned int ast_channel_fin(const struct ast_channel *chan)
{
	return chan->__do_not_use_fin;
}
void ast_channel_fin_set(struct ast_channel *chan, unsigned int value)
{
	chan->__do_not_use_fin = value;
}
unsigned int ast_channel_fout(const struct ast_channel *chan)
{
	return chan->__do_not_use_fout;
}
void ast_channel_fout_set(struct ast_channel *chan, unsigned int value)
{
	chan->__do_not_use_fout = value;
}
unsigned long ast_channel_insmpl(const struct ast_channel *chan)
{
	return chan->__do_not_use_insmpl;
}
void ast_channel_insmpl_set(struct ast_channel *chan, unsigned long value)
{
	chan->__do_not_use_insmpl = value;
}
unsigned long ast_channel_outsmpl(const struct ast_channel *chan)
{
	return chan->__do_not_use_outsmpl;
}
void ast_channel_outsmpl_set(struct ast_channel *chan, unsigned long value)
{
	chan->__do_not_use_outsmpl = value;
}
void *ast_channel_generatordata(const struct ast_channel *chan)
{
	return chan->__do_not_use_generatordata;
}
void ast_channel_generatordata_set(struct ast_channel *chan, void *value)
{
	chan->__do_not_use_generatordata = value;
}
void *ast_channel_music_state(const struct ast_channel *chan)
{
	return chan->__do_not_use_music_state;
}
void ast_channel_music_state_set(struct ast_channel *chan, void *value)
{
	chan->__do_not_use_music_state = value;
}
void *ast_channel_tech_pvt(const struct ast_channel *chan)
{
	return chan->__do_not_use_tech_pvt;
}
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
{
	chan->__do_not_use_tech_pvt = value;
}
void *ast_channel_timingdata(const struct ast_channel *chan)
{
	return chan->__do_not_use_timingdata;
}
void ast_channel_timingdata_set(struct ast_channel *chan, void *value)
{
	chan->__do_not_use_timingdata = value;
}
struct ast_audiohook_list *ast_channel_audiohooks(const struct ast_channel *chan)
{
	return chan->__do_not_use_audiohooks;
}
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
{
	chan->__do_not_use_audiohooks = value;
}
struct ast_cdr *ast_channel_cdr(const struct ast_channel *chan)
{
	return chan->__do_not_use_cdr;
}
void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value)
{
	chan->__do_not_use_cdr = value;
}
struct ast_channel *ast_channel_masq(const struct ast_channel *chan)
{
	return chan->__do_not_use_masq;
}
void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value)
{
	chan->__do_not_use_masq = value;
}
struct ast_channel *ast_channel_masqr(const struct ast_channel *chan)
{
	return chan->__do_not_use_masqr;
}
void ast_channel_masqr_set(struct ast_channel *chan, struct ast_channel *value)
{
	chan->__do_not_use_masqr = value;
}
struct ast_channel_monitor *ast_channel_monitor(const struct ast_channel *chan)
{
	return chan->__do_not_use_monitor;
}
void ast_channel_monitor_set(struct ast_channel *chan, struct ast_channel_monitor *value)
{
	chan->__do_not_use_monitor = value;
}
struct ast_filestream *ast_channel_stream(const struct ast_channel *chan)
{
	return chan->__do_not_use_stream;
}
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
{
	chan->__do_not_use_stream = value;
}
struct ast_filestream *ast_channel_vstream(const struct ast_channel *chan)
{
	return chan->__do_not_use_vstream;
}
void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value)
{
	chan->__do_not_use_vstream = value;
}
struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan)
{
	return chan->__do_not_use_nativeformats;
}
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
{
	chan->__do_not_use_nativeformats = value;
}
struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan)
{
	return chan->__do_not_use_framehooks;
}
void ast_channel_framehooks_set(struct ast_channel *chan, struct ast_framehook_list *value)
{
	chan->__do_not_use_framehooks = value;
}
struct ast_generator *ast_channel_generator(const struct ast_channel *chan)
{
	return chan->__do_not_use_generator;
}
void ast_channel_generator_set(struct ast_channel *chan, struct ast_generator *value)
{
	chan->__do_not_use_generator = value;
}
struct ast_pbx *ast_channel_pbx(const struct ast_channel *chan)
{
	return chan->__do_not_use_pbx;
}
void ast_channel_pbx_set(struct ast_channel *chan, struct ast_pbx *value)
{
	chan->__do_not_use_pbx = value;
}
struct ast_sched_context *ast_channel_sched(const struct ast_channel *chan)
{
	return chan->__do_not_use_sched;
}
void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value)
{
	chan->__do_not_use_sched = value;
}
struct ast_timer *ast_channel_timer(const struct ast_channel *chan)
{
	return chan->__do_not_use_timer;
}
void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value)
{
	chan->__do_not_use_timer = value;
}
struct ast_tone_zone *ast_channel_zone(const struct ast_channel *chan)
{
	return chan->__do_not_use_zone;
}
void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
{
	chan->__do_not_use_zone = value;
}
struct ast_trans_pvt *ast_channel_readtrans(const struct ast_channel *chan)
{
	return chan->__do_not_use_readtrans;
}
void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
{
	chan->__do_not_use_readtrans = value;
}
struct ast_trans_pvt *ast_channel_writetrans(const struct ast_channel *chan)
{
	return chan->__do_not_use_writetrans;
}
void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value)
{
	chan->__do_not_use_writetrans = value;
}
const struct ast_channel_tech *ast_channel_tech(const struct ast_channel *chan)
{
	return chan->__do_not_use_tech;
}
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
{
	chan->__do_not_use_tech = value;
}
enum ast_channel_adsicpe ast_channel_adsicpe(const struct ast_channel *chan)
{
	return chan->__do_not_use_adsicpe;
}
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
{
	chan->__do_not_use_adsicpe = value;
}
enum ast_channel_state ast_channel_state(const struct ast_channel *chan)
{
	return chan->__do_not_use_state;
}
void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state value)
{
	chan->__do_not_use_state = value;
}
struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan)
{
	return &chan->__do_not_use_oldwriteformat;
}
struct ast_format *ast_channel_rawreadformat(struct ast_channel *chan)
{
	return &chan->__do_not_use_rawreadformat;
}
struct ast_format *ast_channel_rawwriteformat(struct ast_channel *chan)
{
	return &chan->__do_not_use_rawwriteformat;
}
struct ast_format *ast_channel_readformat(struct ast_channel *chan)
{
	return &chan->__do_not_use_readformat;
}
struct ast_format *ast_channel_writeformat(struct ast_channel *chan)
{
	return &chan->__do_not_use_writeformat;
}
struct ast_datastore_list *ast_channel_datastores(struct ast_channel *chan)
{
	return &chan->__do_not_use_datastores;
}
struct ast_autochan_list *ast_channel_autochans(struct ast_channel *chan)
{
	return &chan->__do_not_use_autochans;
}
struct ast_readq_list *ast_channel_readq(struct ast_channel *chan)
{
	return &chan->__do_not_use_readq;
}
struct ast_frame *ast_channel_dtmff(struct ast_channel *chan)
{
	return &chan->__do_not_use_dtmff;
}
struct ast_jb *ast_channel_jb(struct ast_channel *chan)
{
	return &chan->__do_not_use_jb;
}
struct ast_party_caller *ast_channel_caller(struct ast_channel *chan)
{
	return &chan->__do_not_use_caller;
}
struct ast_party_connected_line *ast_channel_connected(struct ast_channel *chan)
{
	return &chan->__do_not_use_connected;
}
struct ast_party_dialed *ast_channel_dialed(struct ast_channel *chan)
{
	return &chan->__do_not_use_dialed;
}
struct ast_party_redirecting *ast_channel_redirecting(struct ast_channel *chan)
{
	return &chan->__do_not_use_redirecting;
}
struct timeval *ast_channel_dtmf_tv(struct ast_channel *chan)
{
	return &chan->__do_not_use_dtmf_tv;
}
struct timeval *ast_channel_whentohangup(struct ast_channel *chan)
{
	return &chan->__do_not_use_whentohangup;
}
struct varshead *ast_channel_varshead(struct ast_channel *chan)
{
	return &chan->__do_not_use_varshead;
}
void ast_channel_dtmff_set(struct ast_channel *chan, struct ast_frame *value)
{
	memcpy(&chan->__do_not_use_dtmff, value, sizeof(chan->__do_not_use_dtmff));
}
void ast_channel_jb_set(struct ast_channel *chan, struct ast_jb *value)
{
	memcpy(&chan->__do_not_use_jb, value, sizeof(chan->__do_not_use_jb));
}
void ast_channel_caller_set(struct ast_channel *chan, struct ast_party_caller *value)
{
	memcpy(&chan->__do_not_use_caller, value, sizeof(chan->__do_not_use_caller));
}
void ast_channel_connected_set(struct ast_channel *chan, struct ast_party_connected_line *value)
{
	memcpy(&chan->__do_not_use_connected, value, sizeof(chan->__do_not_use_connected));
}
void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value)
{
	memcpy(&chan->__do_not_use_dialed, value, sizeof(chan->__do_not_use_dialed));
}
void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value)
{
	memcpy(&chan->__do_not_use_redirecting, value, sizeof(chan->__do_not_use_redirecting));
}
void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value)
{
	memcpy(&chan->__do_not_use_dtmf_tv, value, sizeof(chan->__do_not_use_dtmf_tv));
}
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
{
	memcpy(&chan->__do_not_use_whentohangup, value, sizeof(chan->__do_not_use_whentohangup));
}
void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value)
{
	memcpy(&chan->__do_not_use_varshead, value, sizeof(chan->__do_not_use_varshead));
}

/* Evil softhangup accessors */
int ast_channel_softhangup_internal_flag(struct ast_channel * chan)
{
	return chan->__do_not_use_softhangup;
}
void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value)
{
	chan->__do_not_use_softhangup = value;
}
void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value)
{
	chan->__do_not_use_softhangup |= value;
}
void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int value)
{
	chan ->__do_not_use_softhangup &= ~value;
}

/* Typedef accessors */
ast_group_t ast_channel_callgroup(const struct ast_channel *chan)
{
	return chan->__do_not_use_callgroup;
}
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
{
	chan->__do_not_use_callgroup = value;
}
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan)
{
	return chan->__do_not_use_pickupgroup;
}
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
{
	chan->__do_not_use_pickupgroup = value;
}

/* Alertpipe functions */
int ast_channel_alert_write(struct ast_channel *chan)
{
	char blah = 0x7F;
	return ast_channel_alert_writable(chan) && write(chan->__do_not_use_alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
}

ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
{
	int flags;
	char blah;

	if (!ast_channel_internal_alert_readable(chan)) {
		return AST_ALERT_NOT_READABLE;
	}

	flags = fcntl(chan->__do_not_use_alertpipe[0], F_GETFL);
	/* For some odd reason, the alertpipe occasionally loses nonblocking status,
	 * which immediately causes a deadlock scenario.  Detect and prevent this. */
	if ((flags & O_NONBLOCK) == 0) {
		ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", ast_channel_name(chan));
		if (fcntl(chan->__do_not_use_alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
			ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
			return AST_ALERT_READ_FATAL;
		}
	}
	if (read(chan->__do_not_use_alertpipe[0], &blah, sizeof(blah)) < 0) {
		if (errno != EINTR && errno != EAGAIN) {
			ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
			return AST_ALERT_READ_FAIL;
		}
	}

	return AST_ALERT_READ_SUCCESS;
}

int ast_channel_alert_writable(struct ast_channel *chan)
{
	return chan->__do_not_use_alertpipe[1] > -1;
}

int ast_channel_internal_alert_readable(struct ast_channel *chan)
{
	return chan->__do_not_use_alertpipe[0] > -1;
}

void ast_channel_internal_alertpipe_clear(struct ast_channel *chan)
{
	chan->__do_not_use_alertpipe[0] = chan->__do_not_use_alertpipe[1] = -1;
}

void ast_channel_internal_alertpipe_close(struct ast_channel *chan)
{
	if (ast_channel_internal_alert_readable(chan)) {
		close(chan->__do_not_use_alertpipe[0]);
	}
	if (ast_channel_alert_writable(chan)) {
		close(chan->__do_not_use_alertpipe[1]);
	}
}

int ast_channel_internal_alertpipe_init(struct ast_channel *chan)
{
	if (pipe(chan->__do_not_use_alertpipe)) {
		ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n");
		return -1;
	} else {
		int flags = fcntl(chan->__do_not_use_alertpipe[0], F_GETFL);
		if (fcntl(chan->__do_not_use_alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
			ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
			return -1;
		}
		flags = fcntl(chan->__do_not_use_alertpipe[1], F_GETFL);
		if (fcntl(chan->__do_not_use_alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
			ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno));
			return -1;
		}
	}
	return 0;
}

int ast_channel_internal_alert_readfd(struct ast_channel *chan)
{
	return chan->__do_not_use_alertpipe[0];
}

void ast_channel_internal_alertpipe_swap(struct ast_channel *chan1, struct ast_channel *chan2)
{
	int i;
	for (i = 0; i < ARRAY_LEN(chan1->__do_not_use_alertpipe); i++) {
		SWAP(chan1->__do_not_use_alertpipe[i], chan2->__do_not_use_alertpipe[i]);
	}
}

/* file descriptor array accessors */
void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value)
{
	chan->__do_not_use_fds[which] = value;
}
void ast_channel_internal_fd_clear(struct ast_channel *chan, int which)
{
	ast_channel_internal_fd_set(chan, which, -1);
}
void ast_channel_internal_fd_clear_all(struct ast_channel *chan)
{
	int i;
	for (i = 0; i < AST_MAX_FDS; i++) {
		ast_channel_internal_fd_clear(chan, i);
	}
}
int ast_channel_fd(const struct ast_channel *chan, int which)
{
	return chan->__do_not_use_fds[which];
}
int ast_channel_fd_isset(const struct ast_channel *chan, int which)
{
	return ast_channel_fd(chan, which) > -1;
}

#ifdef HAVE_EPOLL
struct ast_epoll_data *ast_channel_internal_epfd_data(const struct ast_channel *chan, int which)
{
	return chan->__do_not_use_epfd_data[which];
}
void ast_channel_internal_epfd_data_set(struct ast_channel *chan, int which , struct ast_epoll_data *value)
{
	chan->__do_not_use_epfd_data[which] = value;
}
#endif