summaryrefslogtreecommitdiff
path: root/include/asterisk/channel.h
blob: 16f9aa8aef930b466e80fe221f326187a84bcd46 (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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 1999 - 2006, 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 General Asterisk PBX channel definitions.
 * \par See also:
 *  \arg \ref Def_Channel
 *  \arg \ref channel_drivers
 */

/*! \page Def_Channel Asterisk Channels
	\par What is a Channel?
	A phone call through Asterisk consists of an incoming
	connection and an outbound connection. Each call comes
	in through a channel driver that supports one technology,
	like SIP, DAHDI, IAX2 etc.
	\par
	Each channel driver, technology, has it's own private
	channel or dialog structure, that is technology-dependent.
	Each private structure is "owned" by a generic Asterisk
	channel structure, defined in channel.h and handled by
	channel.c .
	\par Call scenario
	This happens when an incoming call arrives to Asterisk
	-# Call arrives on a channel driver interface
	-# Channel driver creates a PBX channel and starts a
	   pbx thread on the channel
	-# The dial plan is executed
	-# At this point at least two things can happen:
		-# The call is answered by Asterisk and
		   Asterisk plays a media stream or reads media
		-# The dial plan forces Asterisk to create an outbound
		   call somewhere with the dial (see \ref app_dial.c)
		   application
	.

	\par Bridging channels
	If Asterisk dials out this happens:
	-# Dial creates an outbound PBX channel and asks one of the
	   channel drivers to create a call
	-# When the call is answered, Asterisk bridges the media streams
	   so the caller on the first channel can speak with the callee
	   on the second, outbound channel
	-# In some cases where we have the same technology on both
	   channels and compatible codecs, a native bridge is used.
	   In a native bridge, the channel driver handles forwarding
	   of incoming audio to the outbound stream internally, without
	   sending audio frames through the PBX.
	-# In SIP, theres an "external native bridge" where Asterisk
	   redirects the endpoint, so audio flows directly between the
	   caller's phone and the callee's phone. Signalling stays in
	   Asterisk in order to be able to provide a proper CDR record
	   for the call.


	\par Masquerading channels
	In some cases, a channel can masquerade itself into another
	channel. This happens frequently in call transfers, where
	a new channel takes over a channel that is already involved
	in a call. The new channel sneaks in and takes over the bridge
	and the old channel, now a zombie, is hung up.

	\par Reference
	\arg channel.c - generic functions
	\arg channel.h - declarations of functions, flags and structures
	\arg translate.h - Transcoding support functions
	\arg \ref channel_drivers - Implemented channel drivers
	\arg \ref Def_Frame Asterisk Multimedia Frames
	\arg \ref Def_Bridge

*/
/*! \page Def_Bridge Asterisk Channel Bridges

	In Asterisk, there's several media bridges.

	The Core bridge handles two channels (a "phone call") and bridge
	them together.

	The conference bridge (meetme) handles several channels simultaneously
	with the support of an external timer (DAHDI timer). This is used
	not only by the Conference application (meetme) but also by the
	page application and the SLA system introduced in 1.4.
	The conference bridge does not handle video.

	When two channels of the same type connect, the channel driver
	or the media subsystem used by the channel driver (i.e. RTP)
	can create a native bridge without sending media through the
	core.

	Native bridging can be disabled by a number of reasons,
	like DTMF being needed by the core or codecs being incompatible
	so a transcoding module is needed.

References:
	\li \see ast_channel_early_bridge()
	\li \see ast_channel_bridge()
	\li \see app_meetme.c
	\li \ref AstRTPbridge
	\li \see ast_rtp_bridge()
	\li \ref Def_Channel
*/

/*! \page AstFileDesc File descriptors
	Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
	in the \ref ast_channel structure.
*/

#ifndef _ASTERISK_CHANNEL_H
#define _ASTERISK_CHANNEL_H

#include "asterisk/alertpipe.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/astobj2.h"
#include "asterisk/poll-compat.h"

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

#define AST_MAX_EXTENSION       80  /*!< Max length of an extension */
#define AST_MAX_CONTEXT         80  /*!< Max length of a context */

/*!
 * Max length of a channel uniqueid reported to the outside world.
 *
 * \details
 * 149 = 127 (max systemname) + "-" + 10 (epoch timestamp)
 *     + "." + 10 (monotonically incrementing integer).
 *
 * \note If this value is ever changed, MAX_CHANNEL_ID should
 * be updated in rtp_engine.h.
 */
#define AST_MAX_PUBLIC_UNIQUEID 149

/*!
 * Maximum size of an internal Asterisk channel unique ID.
 *
 * \details
 * Add two for the Local;2 channel to append a ';2' if needed
 * plus nul terminator.
 *
 * \note If this value is ever changed, MAX_CHANNEL_ID should
 * be updated in rtp_engine.h.
 */
#define AST_MAX_UNIQUEID        (AST_MAX_PUBLIC_UNIQUEID + 2 + 1)

#define AST_MAX_ACCOUNT_CODE    80  /*!< Max length of an account code */
#define AST_CHANNEL_NAME        80  /*!< Max length of an ast_channel name */
#define MAX_LANGUAGE            40  /*!< Max length of the language setting */
#define MAX_MUSICCLASS          80  /*!< Max length of the music class setting */
#define AST_MAX_USER_FIELD      256 /*!< Max length of the channel user field */

#include "asterisk/frame.h"
#include "asterisk/chanvars.h"
#include "asterisk/config.h"
#include "asterisk/lock.h"
#include "asterisk/cdr.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/datastore.h"
#include "asterisk/format_cap.h"
#include "asterisk/channelstate.h"
#include "asterisk/ccss.h"
#include "asterisk/framehook.h"
#include "asterisk/stasis.h"
#include "asterisk/endpoints.h"

#define DATASTORE_INHERIT_FOREVER	INT_MAX

#define AST_MAX_FDS		11	/*!< original maximum number of file descriptors */
#define AST_EXTENDED_FDS	12	/*!< the start of extended file descriptor positions */
/*
 * We have AST_MAX_FDS file descriptors in a channel.
 * Some of them have a fixed use:
 */
#define AST_ALERT_FD	(AST_MAX_FDS-1)		/*!< used for alertpipe */
#define AST_TIMING_FD	(AST_MAX_FDS-2)		/*!< used for timingfd */
#define AST_AGENT_FD	(AST_MAX_FDS-3)		/*!< used by agents for pass through */
#define AST_GENERATOR_FD	(AST_MAX_FDS-4)	/*!< used by generator */
#define AST_JITTERBUFFER_FD	(AST_MAX_FDS-5)	/*!< used by generator */

enum ast_bridge_result {
	AST_BRIDGE_COMPLETE = 0,
	AST_BRIDGE_FAILED = -1,
	AST_BRIDGE_FAILED_NOWARN = -2,
	AST_BRIDGE_RETRY = -3,
};

typedef unsigned long long ast_group_t;

struct ast_stream_topology;

/*! \todo Add an explanation of an Asterisk generator
*/
struct ast_generator {
	void *(*alloc)(struct ast_channel *chan, void *params);
	/*! Channel is locked during this function callback. */
	void (*release)(struct ast_channel *chan, void *data);
	/*! This function gets called with the channel unlocked, but is called in
	 *  the context of the channel thread so we know the channel is not going
	 *  to disappear.  This callback is responsible for locking the channel as
	 *  necessary. */
	int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
	/*! This gets called when DTMF_END frames are read from the channel */
	void (*digit)(struct ast_channel *chan, char digit);
	/*! This gets called when the write format on a channel is changed while
	 * generating. The channel is locked during this callback. */
	void (*write_format_change)(struct ast_channel *chan, void *data);
};

/*! Party name character set enumeration values (values from Q.SIG) */
enum AST_PARTY_CHAR_SET {
	AST_PARTY_CHAR_SET_UNKNOWN = 0,
	AST_PARTY_CHAR_SET_ISO8859_1 = 1,
	AST_PARTY_CHAR_SET_WITHDRAWN = 2,/* ITU withdrew this enum value. */
	AST_PARTY_CHAR_SET_ISO8859_2 = 3,
	AST_PARTY_CHAR_SET_ISO8859_3 = 4,
	AST_PARTY_CHAR_SET_ISO8859_4 = 5,
	AST_PARTY_CHAR_SET_ISO8859_5 = 6,
	AST_PARTY_CHAR_SET_ISO8859_7 = 7,
	AST_PARTY_CHAR_SET_ISO10646_BMPSTRING = 8,
	AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING = 9,
};

/*!
 * \since 1.8
 * \brief Information needed to specify a name in a call.
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 */
struct ast_party_name {
	/*! \brief Subscriber name (Malloced) */
	char *str;
	/*!
	 * \brief Character set the name is using.
	 * \see enum AST_PARTY_CHAR_SET
	 * \note
	 * Set to AST_PARTY_CHAR_SET_ISO8859_1 if unsure what to use.
	 * \todo Start using the party name character set value.  Not currently used.
	 */
	int char_set;
	/*!
	 * \brief Q.931 encoded presentation-indicator encoded field
	 * \note Must tolerate the Q.931 screening-indicator field values being present.
	 */
	int presentation;
	/*! \brief TRUE if the name information is valid/present */
	unsigned char valid;
};

/*!
 * \since 1.8
 * \brief Information needed to specify a number in a call.
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 */
struct ast_party_number {
	/*! \brief Subscriber phone number (Malloced) */
	char *str;
	/*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
	int plan;
	/*! \brief Q.931 presentation-indicator and screening-indicator encoded fields */
	int presentation;
	/*! \brief TRUE if the number information is valid/present */
	unsigned char valid;
};

/*!
 * \since 1.8
 * \brief Information needed to specify a subaddress in a call.
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 */
struct ast_party_subaddress {
	/*!
	 * \brief Malloced subaddress string.
	 * \note If the subaddress type is user specified then the subaddress is
	 * a string of ASCII hex because the actual subaddress is likely BCD encoded.
	 */
	char *str;
	/*!
	 * \brief Q.931 subaddress type.
	 * \details
	 * nsap(0),
	 * user_specified(2)
	 */
	int type;
	/*!
	 * \brief TRUE if odd number of address signals
	 * \note The odd/even indicator is used when the type of subaddress is
	 * user_specified and the coding is BCD.
	 */
	unsigned char odd_even_indicator;
	/*! \brief TRUE if the subaddress information is valid/present */
	unsigned char valid;
};

/*!
 * \since 1.8
 * \brief Information needed to identify an endpoint in a call.
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 */
struct ast_party_id {
	/*! \brief Subscriber name */
	struct ast_party_name name;
	/*! \brief Subscriber phone number */
	struct ast_party_number number;
	/*! \brief Subscriber subaddress. */
	struct ast_party_subaddress subaddress;

	/*!
	 * \brief User-set "tag"
	 * \details
	 * A user-settable field used to help associate some extrinsic information
	 * about the channel or user of the channel to the party ID.  This information
	 * is normally not transmitted over the wire and so is only useful within an
	 * Asterisk environment.
	 */
	char *tag;
};

/*!
 * \since 1.8
 * \brief Indicate what information in ast_party_id should be set.
 */
struct ast_set_party_id {
	/*! TRUE if the ast_party_name information should be set. */
	unsigned char name;
	/*! TRUE if the ast_party_number information should be set. */
	unsigned char number;
	/*! TRUE if the ast_party_subaddress information should be set. */
	unsigned char subaddress;
};

/*!
 * \since 1.8
 * \brief Dialed/Called Party information.
 * \note Dialed Number Identifier (DNID)
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 */
struct ast_party_dialed {
	/*!
	 * \brief Dialed/Called number
	 * \note Done this way in case we ever really need to use ast_party_number.
	 * We currently do not need all of the ast_party_number fields.
	 */
	struct {
		/*! \brief Subscriber phone number (Malloced) */
		char *str;
		/*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
		int plan;
	} number;
	/*! \brief Dialed/Called subaddress */
	struct ast_party_subaddress subaddress;
	/*!
	 * \brief Transit Network Select
	 * \note Currently this value is just passed around the system.
	 * You can read it and set it but it is never used for anything.
	 */
	int transit_network_select;
};

/*!
 * \since 1.8
 * \brief Caller Party information.
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 *
 * \note SIP and IAX2 has UTF8 encoded Unicode Caller ID names.
 * In some cases, we also have an alternative (RPID) E.164 number that can
 * be used as Caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to
 * PSTN gateway).
 *
 * \todo Implement settings for transliteration between UTF8 Caller ID names in
 *       to ASCII Caller ID's (DAHDI). Östen Åsklund might be transliterated into
 *       Osten Asklund or Oesten Aasklund depending upon language and person...
 *       We need automatic routines for incoming calls and static settings for
 *       our own accounts.
 */
struct ast_party_caller {
	/*! \brief Caller party ID */
	struct ast_party_id id;

	/*!
	 * \brief Automatic Number Identification (ANI)
	 * \note The name subcomponent is only likely to be used by SIP.
	 * \note The subaddress subcomponent is not likely to be used.
	 */
	struct ast_party_id ani;

	/*! \brief Private caller party ID */
	struct ast_party_id priv;

	/*! \brief Automatic Number Identification 2 (Info Digits) */
	int ani2;
};

/*!
 * \since 1.8
 * \brief Indicate what information in ast_party_caller should be set.
 */
struct ast_set_party_caller {
	/*! What caller id information to set. */
	struct ast_set_party_id id;
	/*! What ANI id information to set. */
	struct ast_set_party_id ani;
	/*! What private caller id information to set. */
	struct ast_set_party_id priv;
};

/*!
 * \since 1.8
 * \brief Connected Line/Party information.
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 */
struct ast_party_connected_line {
	/*! \brief Connected party ID */
	struct ast_party_id id;

	/*!
	 * \brief Automatic Number Identification (ANI)
	 * \note Not really part of connected line data but needed to
	 * save the corresponding caller id value.
	 */
	struct ast_party_id ani;

	/*! \brief Private connected party ID */
	struct ast_party_id priv;

	/*!
	 * \brief Automatic Number Identification 2 (Info Digits)
	 * \note Not really part of connected line data but needed to
	 * save the corresponding caller id value.
	 */
	int ani2;

	/*!
	 * \brief Information about the source of an update.
	 * \note enum AST_CONNECTED_LINE_UPDATE_SOURCE values
	 * for Normal-Answer and Call-transfer.
	 */
	int source;
};

/*!
 * \since 1.8
 * \brief Indicate what information in ast_party_connected_line should be set.
 */
struct ast_set_party_connected_line {
	/*! What connected line id information to set. */
	struct ast_set_party_id id;
	/*! What ANI id information to set. */
	struct ast_set_party_id ani;
	/*! What private connected line id information to set. */
	struct ast_set_party_id priv;
};

/*!
 * \brief Redirecting reason information
 */
struct ast_party_redirecting_reason {
	/*! \brief a string value for the redirecting reason
	 *
	 * Useful for cases where an endpoint has specified a redirecting reason
	 * that does not correspond to an enum AST_REDIRECTING_REASON
	 */
	char *str;

	/*! \brief enum AST_REDIRECTING_REASON value for redirection */
	int code;
};

/*!
 * \since 1.8
 * \brief Redirecting Line information.
 * RDNIS (Redirecting Directory Number Information Service)
 * Where a call diversion or transfer was invoked.
 * \note All string fields here are malloc'ed, so they need to be
 * freed when the structure is deleted.
 * \note NULL and "" must be considered equivalent.
 */
struct ast_party_redirecting {
	/*! \brief Who originally redirected the call (Sent to the party the call is redirected toward) */
	struct ast_party_id orig;

	/*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) */
	struct ast_party_id from;

	/*! \brief Call is redirecting to a new party (Sent to the caller) */
	struct ast_party_id to;

	/*! \brief Who originally redirected the call (Sent to the party the call is redirected toward) - private representation */
	struct ast_party_id priv_orig;

	/*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) - private representation */
	struct ast_party_id priv_from;

	/*! \brief Call is redirecting to a new party (Sent to the caller)  - private representation */
	struct ast_party_id priv_to;

	/*! \brief Reason for the redirection */
	struct ast_party_redirecting_reason reason;

	/*! \brief Reason for the redirection by the original party */
	struct ast_party_redirecting_reason orig_reason;

	/*! \brief Number of times the call was redirected */
	int count;
};

/*!
 * \since 1.8
 * \brief Indicate what information in ast_party_redirecting should be set.
 */
struct ast_set_party_redirecting {
	/*! What redirecting-orig id information to set. */
	struct ast_set_party_id orig;
	/*! What redirecting-from id information to set. */
	struct ast_set_party_id from;
	/*! What redirecting-to id information to set. */
	struct ast_set_party_id to;
	/*! What private redirecting-orig id information to set. */
	struct ast_set_party_id priv_orig;
	/*! What private redirecting-from id information to set. */
	struct ast_set_party_id priv_from;
	/*! What private redirecting-to id information to set. */
	struct ast_set_party_id priv_to;
};

/*!
 * \brief Typedef for a custom read function
 * \note data should be treated as const char *.
 */
typedef int (*ast_acf_read_fn_t)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);

/*!
 * \brief Typedef for a custom read2 function
 * \note data should be treated as const char *.
 */
typedef int (*ast_acf_read2_fn_t)(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len);

/*!
 * \brief Typedef for a custom write function
 * \note data should be treated as const char *.
 */
typedef int (*ast_acf_write_fn_t)(struct ast_channel *chan, const char *function, char *data, const char *value);

/*! \brief Structure to handle passing func_channel_write info to channels via setoption */
typedef struct {
	/*! \brief ast_chan_write_info_t version. Must be incremented if structure is changed */
	#define AST_CHAN_WRITE_INFO_T_VERSION 1
	uint32_t version;
	ast_acf_write_fn_t write_fn;
	struct ast_channel *chan;
	const char *function;
	char *data;
	const char *value;
} ast_chan_write_info_t;

/*!
 * \brief Structure to pass both assignedid values to channel drivers
 * \note The second value is used only by core_unreal (LOCAL)
 */
struct ast_assigned_ids {
	const char *uniqueid;
	const char *uniqueid2;
};

/*!
 * \brief
 * Structure to describe a channel "technology", ie a channel driver
 * See for examples:
 * \arg chan_iax2.c - The Inter-Asterisk exchange protocol
 * \arg chan_sip.c - The SIP channel driver
 * \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
 *
 * \details
 * If you develop your own channel driver, this is where you
 * tell the PBX at registration of your driver what properties
 * this driver supports and where different callbacks are
 * implemented.
 */
struct ast_channel_tech {
	const char * const type;
	const char * const description;

	struct ast_format_cap *capabilities;  /*!< format capabilities this channel can handle */

	int properties;         /*!< Technology Properties */

	/*!
	 * \brief Requester - to set up call data structures (pvt's)
	 *
	 * \param type type of channel to request
	 * \param cap Format capabilities for requested channel
	 * \param assignedid Unique ID string to assign to channel
	 * \param requestor channel asking for data
	 * \param addr destination of the call
	 * \param cause Cause of failure
	 *
	 * \details
	 * Request a channel of a given type, with addr as optional information used
	 * by the low level module
	 *
	 * \retval NULL failure
	 * \retval non-NULL channel on success
	 */
	struct ast_channel *(* const requester)(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);

	/*!
	 * \brief Requester - to set up call data structures (pvt's) with stream topology
	 *
	 * \param type type of channel to request
	 * \param topology Stream topology for requested channel
	 * \param assignedid Unique ID string to assign to channel
	 * \param requestor channel asking for data
	 * \param addr destination of the call
	 * \param cause Cause of failure
	 *
	 * \details
	 * Request a channel of a given type, with addr as optional information used
	 * by the low level module
	 *
	 * \retval NULL failure
	 * \retval non-NULL channel on success
	 */
	struct ast_channel *(* const requester_with_stream_topology)(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);


	int (* const devicestate)(const char *device_number);	/*!< Devicestate call back */
	int (* const presencestate)(const char *presence_provider, char **subtype, char **message); /*!< Presencestate callback */

	/*!
	 * \brief Start sending a literal DTMF digit
	 *
	 * \note The channel is not locked when this function gets called.
	 */
	int (* const send_digit_begin)(struct ast_channel *chan, char digit);

	/*!
	 * \brief Stop sending a literal DTMF digit
	 *
	 * \note The channel is not locked when this function gets called.
	 */
	int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);

	/*!
	 * \brief Make a call
	 * \note The channel is locked when called.
	 * \param chan which channel to make the call on
	 * \param addr destination of the call
	 * \param timeout time to wait on for connect (Doesn't seem to be used.)
	 * \retval 0 on success
	 * \retval -1 on failure
	 */
	int (* const call)(struct ast_channel *chan, const char *addr, int timeout);

	/*! \brief Hangup (and possibly destroy) the channel */
	int (* const hangup)(struct ast_channel *chan);

	/*! \brief Answer the channel */
	int (* const answer)(struct ast_channel *chan);

	/*!
	 * \brief Read a frame (or chain of frames from the same stream), in standard format (see frame.h)
	 *
	 * \param chan channel to read frames from
	 *
	 * \retval non-NULL on success
	 * \retval NULL on failure
	 *
	 * \note Each media frame from this callback will have the stream_num of it changed to the default
	 *       stream num based on the type of media returned. As a result a multistream capable channel
	 *       should not implement this callback.
	 */
	struct ast_frame * (* const read)(struct ast_channel *chan);

	/*!
	 * \brief Read a frame (or chain of frames from the same stream), in standard format (see frame.h), with stream num
	 *
	 * \param chan channel to read frames from
	 *
	 * \retval non-NULL on success
	 * \retval NULL on failure
	 *
	 * \note Each media frame from this callback should contain a stream_num value which is set to the
	 *       stream that the media frame originated from.
	 */
	struct ast_frame * (* const read_stream)(struct ast_channel *chan);

	/*! \brief Write a frame, in standard format (see frame.h) */
	int (* const write)(struct ast_channel *chan, struct ast_frame *frame);

	/*! \brief Write a frame on a specific stream, in standard format (see frame.h) */
	int (* const write_stream)(struct ast_channel *chan, int stream_num, struct ast_frame *frame);

	/*! \brief Display or transmit text */
	int (* const send_text)(struct ast_channel *chan, const char *text);

	/*! \brief Display or send an image */
	int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);

	/*! \brief Send HTML data */
	int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);

	/*! \brief Handle an exception, reading a frame */
	struct ast_frame * (* const exception)(struct ast_channel *chan);

	/*! \brief Bridge two channels of the same type together (early) */
	enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);

	/*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
	int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);

	/*! \brief Fix up a channel:  If a channel is consumed, this is called.  Basically update any ->owner links */
	int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);

	/*! \brief Set a given option. Called with chan locked */
	int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);

	/*! \brief Query a given option. Called with chan locked */
	int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);

	/*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
	int (* const transfer)(struct ast_channel *chan, const char *newdest);

	/*! \brief Write a frame, in standard format */
	int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);

	/*! \brief Write a text frame, in standard format */
	int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);

	/*!
	 * \brief Provide additional read items for CHANNEL() dialplan function
	 * \note data should be treated as a const char *.
	 */
	int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);

	/*!
	 * \brief Provide additional write items for CHANNEL() dialplan function
	 * \note data should be treated as a const char *.
	 */
	int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);

	/*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
	const char * (* get_pvt_uniqueid)(struct ast_channel *chan);

	/*! \brief Call a function with cc parameters as a function parameter
	 *
	 * \details
	 * This is a highly specialized callback that is not likely to be needed in many
	 * channel drivers. When dealing with a busy channel, for instance, most channel
	 * drivers will successfully return a channel to the requester. Once called, the channel
	 * can then queue a busy frame when it receives an appropriate message from the far end.
	 * In such a case, the channel driver has the opportunity to also queue a CC frame.
	 * The parameters for the CC channel can be retrieved from the channel structure.
	 *
	 * For other channel drivers, notably those that deal with "dumb" phones, the channel
	 * driver will not return a channel when one is requested. In such a scenario, there is never
	 * an opportunity for the channel driver to queue a CC frame since the channel is never
	 * called. Furthermore, it is not possible to retrieve the CC configuration parameters
	 * for the desired channel because no channel is ever allocated or returned to the
	 * requester. In such a case, call completion may still be a viable option. What we do is
	 * pass the same string that the requester used originally to request the channel to the
	 * channel driver. The channel driver can then find any potential channels/devices that
	 * match the input and return call the designated callback with the device's call completion
	 * parameters as a parameter.
	 */
	int (* cc_callback)(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);

	/*!
	 * \brief Execute a Gosub call on the channel in a technology specific way before a call is placed.
	 * \since 11.0
	 *
	 * \param chan Channel to execute Gosub in a tech specific way.
	 * \param sub_args Gosub application parameter string.
	 *
	 * \note The chan is locked before calling.
	 *
	 * \retval 0 on success.
	 * \retval -1 on error.
	 */
	int (*pre_call)(struct ast_channel *chan, const char *sub_args);
};

/*! Kill the channel channel driver technology descriptor. */
extern const struct ast_channel_tech ast_kill_tech;

struct ast_epoll_data;

/*!
 * The high bit of the frame count is used as a debug marker, so
 * increments of the counters must be done with care.
 * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
 */
#define	DEBUGCHAN_FLAG  0x80000000

/* XXX not ideal to evaluate x twice... */
#define	FRAMECOUNT_INC(x)	( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )

/*!
 * The current value of the debug flags is stored in the two
 * variables global_fin and global_fout (declared in main/channel.c)
 */
extern unsigned long global_fin, global_fout;

enum ast_channel_adsicpe {
	AST_ADSI_UNKNOWN,
	AST_ADSI_AVAILABLE,
	AST_ADSI_UNAVAILABLE,
	AST_ADSI_OFFHOOKONLY,
};

/*!
 * \brief Possible T38 states on channels
 */
enum ast_t38_state {
	T38_STATE_UNAVAILABLE,	/*!< T38 is unavailable on this channel or disabled by configuration */
	T38_STATE_UNKNOWN,	/*!< The channel supports T38 but the current status is unknown */
	T38_STATE_NEGOTIATING,	/*!< T38 is being negotiated */
	T38_STATE_REJECTED,	/*!< Remote side has rejected our offer */
	T38_STATE_NEGOTIATED,	/*!< T38 established */
};

/*! Hangup handler instance node. */
struct ast_hangup_handler {
	/*! Next hangup handler node. */
	AST_LIST_ENTRY(ast_hangup_handler) node;
	/*! Hangup handler arg string passed to the Gosub application */
	char args[0];
};

AST_LIST_HEAD_NOLOCK(ast_hangup_handler_list, ast_hangup_handler);
AST_LIST_HEAD_NOLOCK(ast_datastore_list, ast_datastore);
AST_LIST_HEAD_NOLOCK(ast_autochan_list, ast_autochan);
AST_LIST_HEAD_NOLOCK(ast_readq_list, ast_frame);

typedef int(*ast_timing_func_t)(const void *data);
/*!
 * \page AstChannel ast_channel locking and reference tracking
 *
 * \par Creating Channels
 * A channel is allocated using the ast_channel_alloc() function.  When created, it is
 * automatically inserted into the main channels hash table that keeps track of all
 * active channels in the system.  The hash key is based on the channel name.  Because
 * of this, if you want to change the name, you _must_ use ast_change_name(), not change
 * the name field directly.  When ast_channel_alloc() returns a channel pointer, you now
 * hold both a reference to that channel and a lock on the channel. Once the channel has
 * been set up the lock can be released. In most cases the reference is given to ast_pbx_run().
 *
 * \par Channel Locking
 * There is a lock associated with every ast_channel.  It is allocated internally via astobj2.
 * To lock or unlock a channel, you must use the ast_channel_lock() wrappers.
 *
 * Previously, before ast_channel was converted to astobj2, the channel lock was used in some
 * additional ways that are no longer necessary.  Before, the only way to ensure that a channel
 * did not disappear out from under you if you were working with a channel outside of the channel
 * thread that owns it, was to hold the channel lock.  Now, that is no longer necessary.
 * You simply must hold a reference to the channel to ensure it does not go away.
 *
 * The channel must be locked if you need to ensure that data that you reading from the channel
 * does not change while you access it.  Further, you must hold the channel lock if you are
 * making a non-atomic change to channel data.
 *
 * \par Channel References
 * There are multiple ways to get a reference to a channel.  The first is that you hold a reference
 * to a channel after creating it.  The other ways involve using the channel search or the channel
 * traversal APIs.  These functions are the ast_channel_get_*() functions or ast_channel_iterator_*()
 * functions.  Once a reference is retrieved by one of these methods, you know that the channel will
 * not go away.  So, the channel should only get locked as needed for data access or modification.
 * But, make sure that the reference gets released when you are done with it!
 *
 * There are different things you can do when you are done with a reference to a channel.  The first
 * is to simply release the reference using ast_channel_unref().  The other option is to call
 * ast_channel_release().  This function is generally used where ast_channel_free() was used in
 * the past.  The release function releases a reference as well as ensures that the channel is no
 * longer in the global channels container.  That way, the channel will get destroyed as soon as any
 * other pending references get released.
 *
 * \par Exceptions to the rules
 * Even though ast_channel is reference counted, there are some places where pointers to an ast_channel
 * get stored, but the reference count does not reflect it.  The reason is mostly historical.
 * The only places where this happens should be places where because of how the code works, we
 * _know_ that the pointer to the channel will get removed before the channel goes away.  The main
 * example of this is in channel drivers.  Channel drivers generally store a pointer to their owner
 * ast_channel in their technology specific pvt struct.  In this case, the channel drivers _know_
 * that this pointer to the channel will be removed in time, because the channel's hangup callback
 * gets called before the channel goes away.
 */

struct ast_channel;

/*! \brief ast_channel_tech Properties */
enum {
	/*!
	 * \brief Channels have this property if they can accept input with jitter;
	 * i.e. most VoIP channels
	 */
	AST_CHAN_TP_WANTSJITTER = (1 << 0),
	/*!
	 * \brief Channels have this property if they can create jitter;
	 * i.e. most VoIP channels
	 */
	AST_CHAN_TP_CREATESJITTER = (1 << 1),
	/*!
	 * \brief Channels with this particular technology are an implementation detail of
	 * Asterisk and should generally not be exposed or manipulated by the outside
	 * world
	 */
	AST_CHAN_TP_INTERNAL = (1 << 2),
};

/*! \brief ast_channel flags */
enum {
	/*! Queue incoming DTMF, to be released when this flag is turned off */
	AST_FLAG_DEFER_DTMF =    (1 << 1),
	/*! write should be interrupt generator */
	AST_FLAG_WRITE_INT =     (1 << 2),
	/*! a thread is blocking on this channel */
	AST_FLAG_BLOCKING =      (1 << 3),
	/*! This is a zombie channel */
	AST_FLAG_ZOMBIE =        (1 << 4),
	/*! There is an exception pending */
	AST_FLAG_EXCEPTION =     (1 << 5),
	/*! Listening to moh XXX anthm promises me this will disappear XXX */
	AST_FLAG_MOH =           (1 << 6),
	/*! This channel is spying on another channel */
	AST_FLAG_SPYING =        (1 << 7),
	/*! the channel is in an auto-incrementing dialplan processor,
	 *  so when ->priority is set, it will get incremented before
	 *  finding the next priority to run */
	AST_FLAG_IN_AUTOLOOP =   (1 << 9),
	/*! This is an outgoing call */
	AST_FLAG_OUTGOING =      (1 << 10),
	/*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
	AST_FLAG_IN_DTMF =       (1 << 12),
	/*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
	 *  currently being emulated */
	AST_FLAG_EMULATE_DTMF =  (1 << 13),
	/*! This is set to tell the channel not to generate DTMF begin frames, and
	 *  to instead only generate END frames. */
	AST_FLAG_END_DTMF_ONLY = (1 << 14),
	/* OBSOLETED in favor of AST_CAUSE_ANSWERED_ELSEWHERE
	 * Flag to show channels that this call is hangup due to the fact that the call
	 * was indeed answered, but in another channel */
	/* AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), */
	/*! This flag indicates that on a masquerade, an active stream should not
	 *  be carried over */
	AST_FLAG_MASQ_NOSTREAM = (1 << 16),
	/*! This flag indicates that the hangup exten was run when the bridge terminated,
	 *  a message aimed at preventing a subsequent hangup exten being run at the pbx_run
	 *  level */
	AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
	/*! Disable certain workarounds.  This reintroduces certain bugs, but allows
	 *  some non-traditional dialplans (like AGI) to continue to function.
	 */
	AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
	/*!
	 * Disable device state event caching.  This allows channel
	 * drivers to selectively prevent device state events from being
	 * cached by certain channels such as anonymous calls which have
	 * no persistent represenatation that can be tracked.
	 */
	AST_FLAG_DISABLE_DEVSTATE_CACHE = (1 << 21),
	/*!
	 * This flag indicates that a dual channel redirect is in
	 * progress.  The bridge needs to wait until the flag is cleared
	 * to continue.
	 */
	AST_FLAG_BRIDGE_DUAL_REDIRECT_WAIT = (1 << 22),
	/*!
	 * This flag indicates that the channel was originated.
	 */
	AST_FLAG_ORIGINATED = (1 << 23),
	/*!
	 * The channel is well and truly dead. Once this is set and published, no further
	 * actions should be taken upon the channel, and no further publications should
	 * occur.
	 */
	AST_FLAG_DEAD = (1 << 24),
	/*!
	 * Channel snapshot should not be published, it is being staged for an explicit
	 * publish.
	 */
	AST_FLAG_SNAPSHOT_STAGE = (1 << 25),
	/*!
	 * The data on chan->timingdata is an astobj2 object.
	 */
	AST_FLAG_TIMINGDATA_IS_AO2_OBJ = (1 << 26),
	/*!
	 * The channel is executing a subroutine or macro
	 */
	AST_FLAG_SUBROUTINE_EXEC = (1 << 27),
};

/*! \brief ast_bridge_config flags */
enum {
	AST_FEATURE_PLAY_WARNING = (1 << 0),
	AST_FEATURE_REDIRECT =     (1 << 1),
	AST_FEATURE_DISCONNECT =   (1 << 2),
	AST_FEATURE_ATXFER =       (1 << 3),
	AST_FEATURE_AUTOMON =      (1 << 4),
	AST_FEATURE_PARKCALL =     (1 << 5),
	AST_FEATURE_AUTOMIXMON =   (1 << 6),
};

#define AST_FEATURE_DTMF_MASK (AST_FEATURE_REDIRECT | AST_FEATURE_DISCONNECT |\
	AST_FEATURE_ATXFER | AST_FEATURE_AUTOMON | AST_FEATURE_PARKCALL | AST_FEATURE_AUTOMIXMON)

/*! \brief bridge configuration */
struct ast_bridge_config {
	struct ast_flags features_caller;
	struct ast_flags features_callee;
	struct timeval start_time;
	struct timeval nexteventts;
	struct timeval feature_start_time;
	long feature_timer;
	long timelimit;
	long play_warning;
	long warning_freq;
	const char *warning_sound;
	const char *end_sound;
	const char *start_sound;
	unsigned int flags;
	void (* end_bridge_callback)(void *);   /*!< A callback that is called after a bridge attempt */
	void *end_bridge_callback_data;         /*!< Data passed to the callback */
	/*! If the end_bridge_callback_data refers to a channel which no longer is going to
	 * exist when the end_bridge_callback is called, then it needs to be fixed up properly
	 */
	void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
};

struct chanmon;

struct outgoing_helper {
	const char *context;
	const char *exten;
	int priority;
	int connect_on_early_media;	/* If set, treat session progress as answer */
	const char *cid_num;
	const char *cid_name;
	const char *account;
	struct ast_variable *vars;
	struct ast_channel *parent_channel;
};

enum {
	/*!
	 * Soft hangup requested by device or other internal reason.
	 * Actual hangup needed.
	 */
	AST_SOFTHANGUP_DEV =       (1 << 0),
	/*!
	 * Used to break the normal frame flow so an async goto can be
	 * done instead of actually hanging up.
	 */
	AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
	/*!
	 * Soft hangup requested by system shutdown.  Actual hangup
	 * needed.
	 */
	AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
	/*!
	 * Used to break the normal frame flow after a timeout so an
	 * implicit async goto can be done to the 'T' exten if it exists
	 * instead of actually hanging up.  If the exten does not exist
	 * then actually hangup.
	 */
	AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
	/*!
	 * Soft hangup requested by application/channel-driver being
	 * unloaded.  Actual hangup needed.
	 */
	AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
	/*!
	 * Soft hangup requested by non-associated party.  Actual hangup
	 * needed.
	 */
	AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
	/*!
	 * Used to indicate that the channel is currently executing hangup
	 * logic in the dialplan. The channel has been hungup when this is
	 * set.
	 */
	AST_SOFTHANGUP_HANGUP_EXEC = (1 << 7),
	/*!
	 * \brief All softhangup flags.
	 *
	 * This can be used as an argument to ast_channel_clear_softhangup()
	 * to clear all softhangup flags from a channel.
	 */
	AST_SOFTHANGUP_ALL =       (0xFFFFFFFF)
};


/*! \brief Channel reload reasons for manager events at load or reload of configuration */
enum channelreloadreason {
	CHANNEL_MODULE_LOAD,
	CHANNEL_MODULE_RELOAD,
	CHANNEL_CLI_RELOAD,
	CHANNEL_MANAGER_RELOAD,
	CHANNEL_ACL_RELOAD,
};

/*!
 * \brief Channel AMA Flags
 */
enum ama_flags {
	AST_AMA_NONE = 0,
	AST_AMA_OMIT,
	AST_AMA_BILLING,
	AST_AMA_DOCUMENTATION,
};

/*!
 * \note None of the datastore API calls lock the ast_channel they are using.
 *       So, the channel should be locked before calling the functions that
 *       take a channel argument.
 */

/*! \brief Inherit datastores from a parent to a child. */
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);

/*!
 * \brief Add a datastore to a channel
 *
 * \note The channel should be locked before calling this function.
 *
 * \retval 0 success
 * \retval non-zero failure
 */
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);

/*!
 * \brief Remove a datastore from a channel
 *
 * \note The channel should be locked before calling this function.
 *
 * \retval 0 success
 * \retval non-zero failure
 */
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);

/*!
 * \brief Find a datastore on a channel
 *
 * \note The channel should be locked before calling this function.
 *
 * \note The datastore returned from this function must not be used if the
 *       reference to the channel is released.
 *
 * \retval pointer to the datastore if found
 * \retval NULL if not found
 */
struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);

/*!
 * \brief Create a channel structure
 * \since 1.8
 *
 * \retval NULL failure
 * \retval non-NULL successfully allocated channel
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 * \note By default, new channels are set to the "s" extension
 *       and "default" context.
 * \note Since 12.0.0 this function returns with the newly created channel locked.
 */
struct ast_channel * __attribute__((format(printf, 15, 16)))
	__ast_channel_alloc(int needqueue, int state, const char *cid_num,
		const char *cid_name, const char *acctcode,
		const char *exten, const char *context, const struct ast_assigned_ids *assignedids,
		const struct ast_channel *requestor, enum ama_flags amaflag,
		struct ast_endpoint *endpoint,
		const char *file, int line, const char *function,
		const char *name_fmt, ...);

/*!
 * \brief Create a channel structure
 *
 * \retval NULL failure
 * \retval non-NULL successfully allocated channel
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 * \note By default, new channels are set to the "s" extension
 *       and "default" context.
 * \note Since 12.0.0 this function returns with the newly created channel locked.
 */
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag, ...) \
	__ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag, NULL, \
		__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)

#define ast_channel_alloc_with_endpoint(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag, endpoint, ...) \
	__ast_channel_alloc((needqueue), (state), (cid_num), (cid_name), (acctcode), (exten), (context), (assignedids), (requestor), (amaflag), (endpoint), \
		__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)

/*!
 * \brief Create a fake channel structure
 *
 * \retval NULL failure
 * \retval non-NULL successfully allocated channel
 *
 * \note This function should ONLY be used to create a fake channel
 *       that can then be populated with data for use in variable
 *       substitution when a real channel does not exist.
 *
 * \note The created dummy channel should be destroyed by
 * ast_channel_unref().  Using ast_channel_release() needlessly
 * grabs the channel container lock and can cause a deadlock as
 * a result.  Also grabbing the channel container lock reduces
 * system performance.
 */
#define ast_dummy_channel_alloc()	__ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);

/*!
 * \brief Queue one or more frames to a channel's frame queue
 *
 * \param chan the channel to queue the frame(s) on
 * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
 *        by this function.  It is the responsibility of the caller to handle
 *        freeing the memory associated with the frame(s) being passed if
 *        necessary.
 *
 * \retval 0 success
 * \retval non-zero failure
 */
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);

/*!
 * \brief Queue one or more frames to the head of a channel's frame queue
 *
 * \param chan the channel to queue the frame(s) on
 * \param f the frame(s) to queue.  Note that the frame(s) will be duplicated
 *        by this function.  It is the responsibility of the caller to handle
 *        freeing the memory associated with the frame(s) being passed if
 *        necessary.
 *
 * \retval 0 success
 * \retval non-zero failure
 */
int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);

/*!
 * \brief Queue a hangup frame
 *
 * \note The channel does not need to be locked before calling this function.
 */
int ast_queue_hangup(struct ast_channel *chan);

/*!
 * \brief Queue a hangup frame with hangupcause set
 *
 * \note The channel does not need to be locked before calling this function.
 * \param[in] chan channel to queue frame onto
 * \param[in] cause the hangup cause
 * \return 0 on success, -1 on error
 * \since 1.6.1
 */
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);

/*!
 * \brief Queue a hold frame
 *
 * \param chan channel to queue frame onto
 * \param musicclass The suggested musicclass for the other end to use
 *
 * \note The channel does not need to be locked before calling this function.
 *
 * \retval zero on success
 * \retval non-zero on failure
 */
int ast_queue_hold(struct ast_channel *chan, const char *musicclass);

/*!
 * \brief Queue an unhold frame
 *
 * \param chan channel to queue frame onto
 *
 * \note The channel does not need to be locked before calling this function.
 *
 * \retval zero on success
 * \retval non-zero on failure
 */
int ast_queue_unhold(struct ast_channel *chan);

/*!
 * \brief Queue a control frame without payload
 *
 * \param chan channel to queue frame onto
 * \param control type of control frame
 *
 * \note The channel does not need to be locked before calling this function.
 *
 * \retval zero on success
 * \retval non-zero on failure
 */
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);

/*!
 * \brief Queue a control frame with payload
 *
 * \param chan channel to queue frame onto
 * \param control type of control frame
 * \param data pointer to payload data to be included in frame
 * \param datalen number of bytes of payload data
 *
 * \retval 0 success
 * \retval non-zero failure
 *
 * \details
 * The supplied payload data is copied into the frame, so the caller's copy
 * is not modified nor freed, and the resulting frame will retain a copy of
 * the data even if the caller frees their local copy.
 *
 * \note This method should be treated as a 'network transport'; in other
 * words, your frames may be transferred across an IAX2 channel to another
 * system, which may be a different endianness than yours. Because of this,
 * you should ensure that either your frames will never be expected to work
 * across systems, or that you always put your payload data into 'network byte
 * order' before calling this function.
 *
 * \note The channel does not need to be locked before calling this function.
 */
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
			   const void *data, size_t datalen);

/*!
 * \brief Change channel name
 *
 * \pre Absolutely all channels _MUST_ be unlocked before calling this function.
 *
 * \param chan the channel to change the name of
 * \param newname the name to change to
 *
 * \return nothing
 *
 * \note this function must _NEVER_ be used when any channels are locked
 * regardless if it is the channel who's name is being changed or not because
 * it invalidates our channel container locking order... lock container first,
 * then the individual channels, never the other way around.
 */
void ast_change_name(struct ast_channel *chan, const char *newname);

/*!
 * \brief Unlink and release reference to a channel
 *
 * This function will unlink the channel from the global channels container
 * if it is still there and also release the current reference to the channel.
 *
 * \return NULL, convenient for clearing invalid pointers
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 *
 * \since 1.8
 */
struct ast_channel *ast_channel_release(struct ast_channel *chan);

/*!
 * \brief Requests a channel
 *
 * \param type type of channel to request
 * \param request_cap Format capabilities for requested channel
 * \param assignedids Unique ID to create channel with
 * \param requestor channel asking for data
 * \param addr destination of the call
 * \param cause Cause of failure
 *
 * \details
 * Request a channel of a given type, with addr as optional information used
 * by the low level module
 *
 * \retval NULL failure
 * \retval non-NULL channel on success
 */
struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);

/*!
 * \brief Requests a channel (specifying stream topology)
 *
 * \param type type of channel to request
 * \param topology Stream topology for requested channel
 * \param assignedids Unique ID to create channel with
 * \param requestor channel asking for data
 * \param addr destination of the call
 * \param cause Cause of failure
 *
 * \details
 * Request a channel of a given type, with addr as optional information used
 * by the low level module
 *
 * \retval NULL failure
 * \retval non-NULL channel on success
 */
struct ast_channel *ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);

enum ast_channel_requestor_relationship {
	/*! The requestor is the future bridge peer of the channel. */
	AST_CHANNEL_REQUESTOR_BRIDGE_PEER,
	/*! The requestor is to be replaced by the channel. */
	AST_CHANNEL_REQUESTOR_REPLACEMENT,
};

/*!
 * \brief Setup new channel accountcodes from the requestor channel after ast_request().
 * \since 13.0.0
 *
 * \param chan New channel to get accountcodes setup.
 * \param requestor Requesting channel to get accountcodes from.
 * \param relationship What the new channel was created for.
 *
 * \pre The chan and requestor channels are already locked.
 *
 * \note Pre-existing accountcodes on chan will be overwritten.
 *
 * \return Nothing
 */
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship);

/*!
 * \brief Setup new channel accountcodes from the requestor channel after ast_request().
 * \since 13.0.0
 *
 * \param chan New channel to get accountcodes setup.
 * \param requestor Requesting channel to get accountcodes from.
 * \param relationship What the new channel was created for.
 *
 * \pre The chan and requestor channels are already locked.
 *
 * \note Pre-existing accountcodes on chan will not be overwritten.
 *
 * \return Nothing
 */
void ast_channel_req_accountcodes_precious(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship);

/*!
 * \brief Request a channel of a given type, with data as optional information used
 *        by the low level module and attempt to place a call on it
 *
 * \param type type of channel to request
 * \param cap format capabilities for requested channel
 * \param assignedids Unique Id to assign to channel
 * \param requestor channel asking for data
 * \param addr destination of the call
 * \param timeout maximum amount of time to wait for an answer
 * \param reason why unsuccessful (if unsuccessful)
 * \param cid_num Caller-ID Number
 * \param cid_name Caller-ID Name (ascii)
 *
 * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
 * to know if the call was answered or not.
 */
struct ast_channel *ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr,
	int timeout, int *reason, const char *cid_num, const char *cid_name);

/*!
 * \brief Request a channel of a given type, with data as optional information used
 * by the low level module and attempt to place a call on it
 * \param type type of channel to request
 * \param cap format capabilities for requested channel
 * \param assignedids Unique Id to assign to channel
 * \param requestor channel requesting data
 * \param addr destination of the call
 * \param timeout maximum amount of time to wait for an answer
 * \param reason why unsuccessful (if unsuccessful)
 * \param cid_num Caller-ID Number
 * \param cid_name Caller-ID Name (ascii)
 * \param oh Outgoing helper
 * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
 * to know if the call was answered or not.
 */
struct ast_channel *__ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr,
	int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);

/*!
 * \brief Forwards a call to a new channel specified by the original channel's call_forward str.  If possible, the new forwarded channel is created and returned while the original one is terminated.
 * \param caller in channel that requested orig
 * \param orig channel being replaced by the call forward channel
 * \param timeout maximum amount of time to wait for setup of new forward channel
 * \param cap format capabilities for requested channel
 * \param oh outgoing helper used with original channel
 * \param outstate reason why unsuccessful (if uncuccessful)
 * \return Returns the forwarded call's ast_channel on success or NULL on failure
 */
struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate);

/*!
 * \brief Register a channel technology (a new channel driver)
 * Called by a channel module to register the kind of channels it supports.
 * \param tech Structure defining channel technology or "type"
 * \return Returns 0 on success, -1 on failure.
 */
int ast_channel_register(const struct ast_channel_tech *tech);

/*!
 * \brief Unregister a channel technology
 * \param tech Structure defining channel technology or "type" that was previously registered
 * \return No return value.
 */
void ast_channel_unregister(const struct ast_channel_tech *tech);

/*!
 * \brief Get a channel technology structure by name
 * \param name name of technology to find
 * \return a pointer to the structure, or NULL if no matching technology found
 */
const struct ast_channel_tech *ast_get_channel_tech(const char *name);

/*!
 * \brief Hang up a channel
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
 * performs all stream stopping, etc, on the channel that needs to end.
 * chan is no longer valid after this call.
 * \param chan channel to hang up (NULL tolerant)
 * \return Nothing
 */
void ast_hangup(struct ast_channel *chan);

/*!
 * \brief Soft hangup all active channels.
 * \since 13.3.0
 *
 * \return Nothing
 */
void ast_softhangup_all(void);

/*!
 * \brief Softly hangup up a channel
 *
 * \param chan channel to be soft-hung-up
 * \param reason an AST_SOFTHANGUP_* reason code
 *
 * \details
 * Call the protocol layer, but don't destroy the channel structure
 * (use this if you are trying to
 * safely hangup a channel managed by another thread.
 *
 * \note The channel passed to this function does not need to be locked.
 *
 * \return Returns 0 regardless
 */
int ast_softhangup(struct ast_channel *chan, int reason);

/*!
 * \brief Softly hangup up a channel (no channel lock)
 * \param chan channel to be soft-hung-up
 * \param reason an AST_SOFTHANGUP_* reason code
 */
int ast_softhangup_nolock(struct ast_channel *chan, int reason);

/*!
 * \brief Clear a set of softhangup flags from a channel
 *
 * Never clear a softhangup flag from a channel directly.  Instead,
 * use this function.  This ensures that all aspects of the softhangup
 * process are aborted.
 *
 * \param chan the channel to clear the flag on
 * \param flag the flag or flags to clear
 *
 * \return Nothing.
 */
void ast_channel_clear_softhangup(struct ast_channel *chan, int flag);

/*!
 * \brief Set the source of the hangup in this channel and it's bridge
 *
 * \param chan channel to set the field on
 * \param source a string describing the source of the hangup for this channel
 * \param force
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 *
 * \since 1.8
 *
 * Hangupsource is generally the channel name that caused the bridge to be
 * hung up, but it can also be other things such as "dialplan/agi"
 * This can then be logged in the CDR or CEL
 */
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);

/*! \brief Check to see if a channel is needing hang up
 * \param chan channel on which to check for hang up
 * This function determines if the channel is being requested to be hung up.
 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
 */
int ast_check_hangup(struct ast_channel *chan);

int ast_check_hangup_locked(struct ast_channel *chan);

/*! \brief This function will check if the bridge needs to be re-evaluated due to
 *         external changes.
 *
 *  \param chan Channel on which to check the unbridge_eval flag
 *
 *  \return Returns 0 if the flag is down or 1 if the flag is up.
 */
int ast_channel_unbridged(struct ast_channel *chan);

/*! \brief ast_channel_unbridged variant. Use this if the channel
 *         is already locked prior to calling.
 *
 *  \param chan Channel on which to check the unbridge flag
 *
 *  \return Returns 0 if the flag is down or 1 if the flag is up.
 */
int ast_channel_unbridged_nolock(struct ast_channel *chan);

/*! \brief Sets the unbridged flag and queues a NULL frame on the channel to trigger
 *         a check by bridge_channel_wait
 *
 *  \param chan Which channel is having its unbridged value set
 *  \param value What the unbridge value is being set to
 */
void ast_channel_set_unbridged(struct ast_channel *chan, int value);

/*! \brief Variant of ast_channel_set_unbridged. Use this if the channel
 *         is already locked prior to calling.
 *
 *  \param chan Which channel is having its unbridged value set
 *  \param value What the unbridge value is being set to
 */
void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value);

/*!
 * \brief This function will check if T.38 is active on the channel.
 *
 * \param chan Channel on which to check the unbridge_eval flag
 *
 * \return Returns 0 if the flag is down or 1 if the flag is up.
 */
int ast_channel_is_t38_active(struct ast_channel *chan);

/*!
 * \brief ast_channel_is_t38_active variant. Use this if the channel
 *         is already locked prior to calling.
 *
 * \param chan Channel on which to check the is_t38_active flag
 *
 * \return Returns 0 if the flag is down or 1 if the flag is up.
 */
int ast_channel_is_t38_active_nolock(struct ast_channel *chan);

/*!
 * \brief Sets the is_t38_active flag
 *
 * \param chan Which channel is having its is_t38_active value set
 * \param is_t38_active Non-zero if T.38 is active
 */
void ast_channel_set_is_t38_active(struct ast_channel *chan, int is_t38_active);

/*!
 * \brief Variant of ast_channel_set_is_t38_active. Use this if the channel
 *         is already locked prior to calling.
 *
 * \param chan Which channel is having its is_t38_active value set
 * \param is_t38_active Non-zero if T.38 is active
 */
void ast_channel_set_is_t38_active_nolock(struct ast_channel *chan, int is_t38_active);

/*!
 * \brief Lock the given channel, then request softhangup on the channel with the given causecode
 * \param chan channel on which to hang up
 * \param causecode cause code to use (Zero if don't use cause code)
 * \return Nothing
 */
void ast_channel_softhangup_withcause_locked(struct ast_channel *chan, int causecode);

/*!
 * \brief Compare a offset with the settings of when to hang a channel up
 * \param chan channel on which to check for hangup
 * \param offset offset in seconds and microseconds from current time
 * \return 1, 0, or -1
 * This function compares a offset from current time with the absolute time
 * out on a channel (when to hang up). If the absolute time out on a channel
 * is earlier than current time plus the offset, it returns 1, if the two
 * time values are equal, it return 0, otherwise, it return -1.
 * \since 1.6.1
 */
int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);

/*!
 * \brief Set when to hang a channel up
 *
 * \param chan channel on which to check for hang up
 * \param offset offset in seconds and useconds relative to the current time of when to hang up
 *
 * This function sets the absolute time out on a channel (when to hang up).
 *
 * \pre chan is locked
 *
 * \return Nothing
 * \since 1.6.1
 */
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);

/*!
 * \brief Answer a channel
 *
 * \param chan channel to answer
 *
 * \details
 * This function answers a channel and handles all necessary call
 * setup functions.
 *
 * \note The channel passed does not need to be locked, but is locked
 * by the function when needed.
 *
 * \note This function will wait up to 500 milliseconds for media to
 * arrive on the channel before returning to the caller, so that the
 * caller can properly assume the channel is 'ready' for media flow.
 *
 * \retval 0 on success
 * \retval non-zero on failure
 */
int ast_answer(struct ast_channel *chan);

/*!
 * \brief Answer a channel, if it's not already answered.
 *
 * \param chan channel to answer
 *
 * \details See ast_answer()
 *
 * \retval 0 on success
 * \retval non-zero on failure
 */
int ast_auto_answer(struct ast_channel *chan);

/*!
 * \brief Answer a channel
 *
 * \param chan channel to answer
 *
 * This function answers a channel and handles all necessary call
 * setup functions.
 *
 * \note The channel passed does not need to be locked, but is locked
 * by the function when needed.
 *
 * \note Unlike ast_answer(), this function will not wait for media
 * flow to begin. The caller should be careful before sending media
 * to the channel before incoming media arrives, as the outgoing
 * media may be lost.
 *
 * \retval 0 on success
 * \retval non-zero on failure
 */
int ast_raw_answer(struct ast_channel *chan);

/*!
 * \brief Answer a channel, with a selectable delay before returning
 *
 * \param chan channel to answer
 * \param delay maximum amount of time to wait for incoming media
 *
 * This function answers a channel and handles all necessary call
 * setup functions.
 *
 * \note The channel passed does not need to be locked, but is locked
 * by the function when needed.
 *
 * \note This function will wait up to 'delay' milliseconds for media to
 * arrive on the channel before returning to the caller, so that the
 * caller can properly assume the channel is 'ready' for media flow. If
 * 'delay' is less than 500, the function will wait up to 500 milliseconds.
 *
 * \retval 0 on success
 * \retval non-zero on failure
 */
int __ast_answer(struct ast_channel *chan, unsigned int delay);

/*!
 * \brief Execute a Gosub call on the channel before a call is placed.
 * \since 11.0
 *
 * \details
 * This is called between ast_request() and ast_call() to
 * execute a predial routine on the newly created channel.
 *
 * \param chan Channel to execute Gosub.
 * \param sub_args Gosub application parameter string.
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 *
 * \retval 0 on success.
 * \retval -1 on error.
 */
int ast_pre_call(struct ast_channel *chan, const char *sub_args);

/*!
 * \brief Make a call
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 * \param chan which channel to make the call on
 * \param addr destination of the call
 * \param timeout time to wait on for connect (Doesn't seem to be used.)
 * \details
 * Place a call, take no longer than timeout ms.
 * \retval 0 on success
 * \retval -1 on failure
 */
int ast_call(struct ast_channel *chan, const char *addr, int timeout);

/*!
 * \brief Indicates condition of channel
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
 * \param chan channel to change the indication
 * \param condition which condition to indicate on the channel
 * \return Returns 0 on success, -1 on failure
 */
int ast_indicate(struct ast_channel *chan, int condition);

/*!
 * \brief Indicates condition of channel, with payload
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
 * \param chan channel to change the indication
 * \param condition which condition to indicate on the channel
 * \param data pointer to payload data
 * \param datalen size of payload data
 * \return Returns 0 on success, -1 on failure
 */
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);

/* Misc stuff ------------------------------------------------ */

/*!
 * \brief Wait for input on a channel
 * \param chan channel to wait on
 * \param ms length of time to wait on the channel
 * \details
 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
 * \retval < 0 on failure
 * \retval 0 if nothing ever arrived
 * \retval the # of ms remaining otherwise
 */
int ast_waitfor(struct ast_channel *chan, int ms);

/*!
 * \brief Should we keep this frame for later?
 *
 * There are functions such as ast_safe_sleep which will
 * service a channel to ensure that it does not have a
 * large backlog of queued frames. When this happens,
 * we want to hold on to specific frame types and just drop
 * others. This function will tell if the frame we just
 * read should be held onto.
 *
 * \param frame The frame we just read
 * \retval 1 frame should be kept
 * \retval 0 frame should be dropped
 */
int ast_is_deferrable_frame(const struct ast_frame *frame);

/*!
 * \brief Wait for a specified amount of time, looking for hangups
 * \param chan channel to wait for
 * \param ms length of time in milliseconds to sleep. This should never be less than zero.
 * \details
 * Waits for a specified amount of time, servicing the channel as required.
 * \return returns -1 on hangup, otherwise 0.
 */
int ast_safe_sleep(struct ast_channel *chan, int ms);

/*!
 * \brief Wait for a specified amount of time, looking for hangups and a condition argument
 * \param chan channel to wait for
 * \param ms length of time in milliseconds to sleep.
 * \param cond a function pointer for testing continue condition
 * \param data argument to be passed to the condition test function
 * \return returns -1 on hangup, otherwise 0.
 * \details
 * Waits for a specified amount of time, servicing the channel as required. If cond
 * returns 0, this function returns.
 */
int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );

/*!
 * \brief Waits for activity on a group of channels
 * \param chan an array of pointers to channels
 * \param n number of channels that are to be waited upon
 * \param fds an array of fds to wait upon
 * \param nfds the number of fds to wait upon
 * \param exception exception flag
 * \param outfd fd that had activity on it
 * \param ms how long the wait was
 * \details
 * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
 * file descriptors.
 * \return Returns the channel with activity, or NULL on error or if an FD
 * came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
 * will be -1
 */
struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
	int *fds, int nfds, int *exception, int *outfd, int *ms);

/*!
 * \brief Waits for input on a group of channels
 * Wait for input on an array of channels for a given # of milliseconds.
 * \return Return channel with activity, or NULL if none has activity.
 * \param chan an array of pointers to channels
 * \param n number of channels that are to be waited upon
 * \param ms time "ms" is modified in-place, if applicable
 */
struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);

/*!
 * \brief Waits for input on an fd
 * \note This version works on fd's only.  Be careful with it.
 */
int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);


/*!
 * \brief Reads a frame
 *
 * \param chan channel to read a frame from
 *
 * \return Returns a frame, or NULL on error.  If it returns NULL, you
 * best just stop reading frames and assume the channel has been
 * disconnected.
 *
 * \note This function will filter frames received from the channel so
 *       that only frames from the default stream for each media type
 *       are returned. All other media frames from other streams will
 *       be absorbed internally and a NULL frame returned instead.
 */
struct ast_frame *ast_read(struct ast_channel *chan);

/*!
 * \brief Reads a frame, but does not filter to just the default streams
 *
 * \param chan channel to read a frame from
 *
 * \return Returns a frame, or NULL on error.  If it returns NULL, you
 * best just stop reading frames and assume the channel has been
 * disconnected.
 *
 * \note This function will not perform any filtering and will return
 *       media frames from all streams on the channel. To determine which
 *       stream a frame originated from the stream_num on it can be
 *       examined.
 */
struct ast_frame *ast_read_stream(struct ast_channel *chan);

/*!
 * \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
 * \param chan channel to read a frame from
 * \return  Returns a frame, or NULL on error.  If it returns NULL, you
 * best just stop reading frames and assume the channel has been
 * disconnected.
 * \note Audio is replaced with AST_FRAME_NULL to avoid
 * transcode when the resulting audio is not necessary.
 */
struct ast_frame *ast_read_noaudio(struct ast_channel *chan);

/*!
 * \brief Reads a frame, but does not filter to just the default streams,
 * returning AST_FRAME_NULL frame if audio.
 *
 * \param chan channel to read a frame from
 *
 * \return Returns a frame, or NULL on error.  If it returns NULL, you
 * best just stop reading frames and assume the channel has been
 * disconnected.
 *
 * \note This function will not perform any filtering and will return
 *       media frames from all streams on the channel. To determine which
 *       stream a frame originated from the stream_num on it can be
 *       examined.
 *
 * \note Audio is replaced with AST_FRAME_NULL to avoid
 * transcode when the resulting audio is not necessary.
 */
struct ast_frame *ast_read_stream_noaudio(struct ast_channel *chan);

/*!
 * \brief Write a frame to a channel
 * This function writes the given frame to the indicated channel.
 * \param chan destination channel of the frame
 * \param frame frame that will be written
 * \return It returns 0 on success, -1 on failure.
 */
int ast_write(struct ast_channel *chan, struct ast_frame *frame);

/*!
 * \brief Write video frame to a channel
 * This function writes the given frame to the indicated channel.
 * \param chan destination channel of the frame
 * \param frame frame that will be written
 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
 */
int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);

/*!
 * \brief Write text frame to a channel
 * This function writes the given frame to the indicated channel.
 * \param chan destination channel of the frame
 * \param frame frame that will be written
 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
 */
int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);

/*!
 * \brief Write a frame to a stream
 * This function writes the given frame to the indicated stream on the channel.
 * \param chan destination channel of the frame
 * \param stream_num destination stream on the channel
 * \param frame frame that will be written
 * \return It returns 0 on success, -1 on failure.
 * \note If -1 is provided as the stream number and a media frame is provided the
 *       function will write to the default stream of the type of media.
 */
int ast_write_stream(struct ast_channel *chan, int stream_num, struct ast_frame *frame);

/*! \brief Send empty audio to prime a channel driver */
int ast_prod(struct ast_channel *chan);

/*!
 * \brief Set specific read path on channel.
 * \since 13.4.0
 *
 * \param chan Channel to setup read path.
 * \param raw_format Format to expect from the channel driver.
 * \param core_format What the core wants to read.
 *
 * \pre chan is locked
 *
 * \retval 0 on success.
 * \retval -1 on error.
 */
int ast_set_read_format_path(struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format);

/*!
 * \brief Set specific write path on channel.
 * \since 13.13.0
 *
 * \param chan Channel to setup write path.
 * \param core_format What the core wants to write.
 * \param raw_format Raw write format.
 *
 * \pre chan is locked
 *
 * \retval 0 on success.
 * \retval -1 on error.
 */
int ast_set_write_format_path(struct ast_channel *chan, struct ast_format *core_format, struct ast_format *raw_format);

/*!
 * \brief Sets read format on channel chan from capabilities
 * Set read format for channel to whichever component of "format" is best.
 * \param chan channel to change
 * \param formats new formats to pick from for reading
 * \return Returns 0 on success, -1 on failure
 */
int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);

/*!
 * \brief Sets read format on channel chan
 * \param chan channel to change
 * \param format format to set for reading
 * \return Returns 0 on success, -1 on failure
 */
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format);

/*!
 * \brief Sets write format on channel chan
 * Set write format for channel to whichever component of "format" is best.
 * \param chan channel to change
 * \param formats new formats to pick from for writing
 * \return Returns 0 on success, -1 on failure
 */
int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);

/*!
 * \brief Sets write format on channel chan
 * \param chan channel to change
 * \param format format to set for writing
 * \return Returns 0 on success, -1 on failure
 */
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format);

/*!
 * \brief Sets write format for a channel.
 * All internal data will than be handled in an interleaved format. (needed by binaural opus)
 *
 * \param chan channel to change
 * \param format format to set for writing
 * \return Returns 0 on success, -1 on failure
 */
int ast_set_write_format_interleaved_stereo(struct ast_channel *chan, struct ast_format *format);

/*!
 * \brief Sends text to a channel
 *
 * \param chan channel to act upon
 * \param text string of text to send on the channel
 *
 * \details
 * Write text to a display on a channel
 *
 * \note The channel does not need to be locked before calling this function.
 *
 * \retval 0 on success
 * \retval -1 on failure
 */
int ast_sendtext(struct ast_channel *chan, const char *text);

/*!
 * \brief Receives a text character from a channel
 * \param chan channel to act upon
 * \param timeout timeout in milliseconds (0 for infinite wait)
 * \details
 * Read a char of text from a channel
 * \return 0 on success, -1 on failure
 */
int ast_recvchar(struct ast_channel *chan, int timeout);

/*!
 * \brief Send a DTMF digit to a channel.
 * \param chan channel to act upon
 * \param digit the DTMF digit to send, encoded in ASCII
 * \param duration the duration of the digit ending in ms
 * \return 0 on success, -1 on failure
 */
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);

/*!
 * \brief Send a DTMF digit to a channel.
 * \param chan channel to act upon
 * \param digit the DTMF digit to send, encoded in ASCII
 * \return 0 on success, -1 on failure
 */
int ast_senddigit_begin(struct ast_channel *chan, char digit);

/*!
 * \brief Send a DTMF digit to a channel.
 * \param chan channel to act upon
 * \param digit the DTMF digit to send, encoded in ASCII
 * \param duration the duration of the digit ending in ms
 * \return Returns 0 on success, -1 on failure
 */
int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);

/*!
 * \brief Receives a text string from a channel
 * Read a string of text from a channel
 * \param chan channel to act upon
 * \param timeout timeout in milliseconds (0 for infinite wait)
 * \return the received text, or NULL to signify failure.
 */
char *ast_recvtext(struct ast_channel *chan, int timeout);

/*!
 * \brief Waits for a digit
 * \param c channel to wait for a digit on
 * \param ms how many milliseconds to wait (<0 for indefinite).
 * \return Returns <0 on error, 0 on no entry, and the digit on success.
 */
int ast_waitfordigit(struct ast_channel *c, int ms);

/*!
 * \brief Wait for a digit
 * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
 * \param c channel to wait for a digit on
 * \param ms how many milliseconds to wait (<0 for indefinite).
 * \param breakon string of DTMF digits to break upon or NULL for any.
 * \param audiofd audio file descriptor to write to if audio frames are received
 * \param ctrlfd control file descriptor to monitor for reading
 * \return Returns 1 if ctrlfd becomes available
 */
int ast_waitfordigit_full(struct ast_channel *c, int ms, const char *breakon, int audiofd, int ctrlfd);

/*!
 * \brief Reads multiple digits
 * \param c channel to read from
 * \param s string to read in to.  Must be at least the size of your length
 * \param len how many digits to read (maximum)
 * \param timeout how long to timeout between digits
 * \param rtimeout timeout to wait on the first digit
 * \param enders digits to end the string
 * \details
 * Read in a digit string "s", max length "len", maximum timeout between
 * digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
 * for the first digit.
 * \return Returns 0 on normal return, or 1 on a timeout.  In the case of
 * a timeout, any digits that were read before the timeout will still be available in s.
 * RETURNS 2 in full version when ctrlfd is available, NOT 1
 */
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);

/*! \brief Report DTMF on channel 0 */
#define AST_BRIDGE_DTMF_CHANNEL_0		(1 << 0)
/*! \brief Report DTMF on channel 1 */
#define AST_BRIDGE_DTMF_CHANNEL_1		(1 << 1)


/*!
 * \brief Make the frame formats of two channels compatible.
 *
 * \param chan First channel to make compatible.  Should be the calling party.
 * \param peer Other channel to make compatible.  Should be the called party.
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 *
 * \details
 * Set two channels to compatible frame formats in both
 * directions.  The path from peer to chan is made compatible
 * first to allow for in-band audio in case the other direction
 * cannot be made compatible.
 *
 * \retval 0 on success.
 * \retval -1 on error.
 */
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer);

/*!
 * \brief Bridge two channels together (early)
 * \param c0 first channel to bridge
 * \param c1 second channel to bridge
 * \details
 * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
 * \return Returns 0 on success and -1 if it could not be done
 */
int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);

/*!
 * \brief Gives the string form of a given cause code.
 *
 * \param state cause to get the description of
 * \return the text form of the binary cause code given
 */
const char *ast_cause2str(int state) attribute_pure;

/*!
 * \brief Convert the string form of a cause code to a number
 *
 * \param name string form of the cause
 * \return the cause code
 */
int ast_str2cause(const char *name) attribute_pure;

/*!
 * \brief Gives the string form of a given channel state
 *
 * \param ast_channel_state state to get the name of
 * \return the text form of the binary state given
 */
const char *ast_state2str(enum ast_channel_state);

/*!
 * \brief Gives the string form of a given transfer capability
 *
 * \param transfercapability transfer capability to get the name of
 * \return the text form of the binary transfer capability
 */
char *ast_transfercapability2str(int transfercapability) attribute_const;

/*
 * Options: Some low-level drivers may implement "options" allowing fine tuning of the
 * low level channel.  See frame.h for options.  Note that many channel drivers may support
 * none or a subset of those features, and you should not count on this if you want your
 * asterisk application to be portable.  They're mainly useful for tweaking performance
 */

/*!
 * \brief Sets an option on a channel
 *
 * \param channel channel to set options on
 * \param option option to change
 * \param data data specific to option
 * \param datalen length of the data
 * \param block blocking or not
 * \details
 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
 * \return 0 on success and -1 on failure
 */
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);

/*!
 * \brief Checks the value of an option
 *
 * Query the value of an option
 * Works similarly to setoption except only reads the options.
 */
int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);

/*!
 * \brief Checks for HTML support on a channel
 * \return 0 if channel does not support HTML or non-zero if it does
 */
int ast_channel_supports_html(struct ast_channel *channel);

/*!
 * \brief Sends HTML on given channel
 * Send HTML or URL on link.
 * \return 0 on success or -1 on failure
 */
int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);

/*!
 * \brief Sends a URL on a given link
 * Send URL on link.
 * \return 0 on success or -1 on failure
 */
int ast_channel_sendurl(struct ast_channel *channel, const char *url);

/*!
 * \brief Defers DTMF so that you only read things like hangups and audio.
 * \return non-zero if channel was already DTMF-deferred or
 * 0 if channel is just now being DTMF-deferred
 */
int ast_channel_defer_dtmf(struct ast_channel *chan);

/*! Undo defer.  ast_read will return any DTMF characters that were queued */
void ast_channel_undefer_dtmf(struct ast_channel *chan);

/*! \return number of channels available for lookup */
int ast_active_channels(void);

/*! \return the number of channels not yet destroyed */
int ast_undestroyed_channels(void);

/*! Activate a given generator */
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);

/*! Deactivate an active generator */
void ast_deactivate_generator(struct ast_channel *chan);

/*!
 * \since 12
 * \brief Obtain how long the channel since the channel was created
 *
 * \param chan The channel object
 *
 * \retval 0 if the time value cannot be computed (or you called this really fast)
 * \retval The number of seconds the channel has been up
 */
int ast_channel_get_duration(struct ast_channel *chan);

/*!
 * \since 12
 * \brief Obtain how long it has been since the channel was answered
 *
 * \param chan The channel object
 *
 * \retval 0 if the channel isn't answered (or you called this really fast)
 * \retval The number of seconds the channel has been up
 */
int ast_channel_get_up_time(struct ast_channel *chan);

/*!
 * \brief Set caller ID number, name and ANI and generate AMI event.
 *
 * \note Use ast_channel_set_caller() and ast_channel_set_caller_event() instead.
 * \note The channel does not need to be locked before calling this function.
 */
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);

/*!
 * \brief Set the caller id information in the Asterisk channel
 * \since 1.8
 *
 * \param chan Asterisk channel to set caller id information
 * \param caller Caller id information
 * \param update What caller information to update.  NULL if all.
 *
 * \return Nothing
 *
 * \note The channel does not need to be locked before calling this function.
 */
void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);

/*!
 * \brief Set the caller id information in the Asterisk channel and generate an AMI event
 * if the caller id name or number changed.
 * \since 1.8
 *
 * \param chan Asterisk channel to set caller id information
 * \param caller Caller id information
 * \param update What caller information to update.  NULL if all.
 *
 * \return Nothing
 *
 * \note The channel does not need to be locked before calling this function.
 */
void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);

/*! Set the file descriptor on the channel */
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);

/*! Start a tone going */
int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
/*! Stop a tone from playing */
void ast_tonepair_stop(struct ast_channel *chan);
/*! Play a tone pair for a given amount of time */
int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);

/*!
 * \brief Automatically service a channel for us...
 *
 * \retval 0 success
 * \retval -1 failure, or the channel is already being autoserviced
 */
int ast_autoservice_start(struct ast_channel *chan);

/*!
 * \brief Stop servicing a channel for us...
 *
 * \note if chan is locked prior to calling ast_autoservice_stop, it
 * is likely that there will be a deadlock between the thread that calls
 * ast_autoservice_stop and the autoservice thread. It is important
 * that chan is not locked prior to this call
 *
 * \param chan
 * \retval 0 success
 * \retval -1 error, or the channel has been hungup
 */
int ast_autoservice_stop(struct ast_channel *chan);

/*!
 * \brief Put chan into autoservice while hanging up peer.
 * \since 11.0
 *
 * \param chan Chan to put into autoservice.
 * \param peer Chan to run hangup handlers and hangup.
 *
 * \return Nothing
 */
void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer);

/*!
 * \brief Ignore certain frame types
 * \note Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames
 * while a channel is in autoservice and queue them up when taken out of
 * autoservice.  When this is not desireable, this API may be used to
 * cause the channel to ignore those frametypes after the channel is put
 * into autoservice, but before autoservice is stopped.
 * \retval 0 success
 * \retval -1 channel is not in autoservice
 */
int ast_autoservice_ignore(struct ast_channel *chan, enum ast_frame_type ftype);

/*!
 * \brief Enable or disable timer ticks for a channel
 *
 * \param c channel
 * \param rate number of timer ticks per second
 * \param func callback function
 * \param data
 *
 * \details
 * If timers are supported, force a scheduled expiration on the
 * timer fd, at which point we call the callback function / data
 *
 * \note Call this function with a rate of 0 to turn off the timer ticks
 *
 * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
 */
int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data, unsigned int is_ao2_obj);

/*!
 * \brief Transfer a channel (if supported).
 * \retval -1 on error
 * \retval 0 if not supported
 * \retval 1 if supported and requested
 * \param chan current channel
 * \param dest destination extension for transfer
 */
int ast_transfer(struct ast_channel *chan, char *dest);

/*!
 * \brief Inherits channel variable from parent to child channel
 * \param parent Parent channel
 * \param child Child channel
 *
 * \details
 * Scans all channel variables in the parent channel, looking for those
 * that should be copied into the child channel.
 * Variables whose names begin with a single '_' are copied into the
 * child channel with the prefix removed.
 * Variables whose names begin with '__' are copied into the child
 * channel with their names unchanged.
 */
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);

/*!
 * \brief adds a list of channel variables to a channel
 * \param chan the channel
 * \param vars a linked list of variables
 *
 * \pre chan is locked
 *
 * \details
 * Variable names can be for a regular channel variable or a dialplan function
 * that has the ability to be written to.
 */
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);

/*!
 * \brief An opaque 'object' structure use by silence generators on channels.
 */
struct ast_silence_generator;

/*!
 * \brief Starts a silence generator on the given channel.
 * \param chan The channel to generate silence on
 * \return An ast_silence_generator pointer, or NULL if an error occurs
 *
 * \details
 * This function will cause SLINEAR silence to be generated on the supplied
 * channel until it is disabled; if the channel cannot be put into SLINEAR
 * mode then the function will fail.
 *
 * \note
 * The pointer returned by this function must be preserved and passed to
 * ast_channel_stop_silence_generator when you wish to stop the silence
 * generation.
 */
struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);

/*!
 * \brief Stops a previously-started silence generator on the given channel.
 * \param chan The channel to operate on
 * \param state The ast_silence_generator pointer return by a previous call to
 * ast_channel_start_silence_generator.
 * \return nothing
 *
 * \details
 * This function will stop the operating silence generator and return the channel
 * to its previous write format.
 */
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);

/*!
 * \brief Determine which channel has an older linkedid
 * \param a First channel
 * \param b Second channel
 * \return Returns an ast_channel structure that has oldest linkedid
 */
struct ast_channel *ast_channel_internal_oldest_linkedid(struct ast_channel *a, struct ast_channel *b);

/*!
 * \brief Copy the full linkedid channel id structure from one channel to another
 * \param dest Destination to copy linkedid to
 * \param source Source channel to copy linkedid from
 * \return void
 */
void ast_channel_internal_copy_linkedid(struct ast_channel *dest, struct ast_channel *source);

/*!
 * \brief Swap uniqueid and linkedid beteween two channels
 * \param a First channel
 * \param b Second channel
 * \return void
 *
 * \note
 * This is used in masquerade to exchange identities
 */
void ast_channel_internal_swap_uniqueid_and_linkedid(struct ast_channel *a, struct ast_channel *b);

/*!
 * \brief Swap topics beteween two channels
 * \param a First channel
 * \param b Second channel
 * \return void
 *
 * \note
 * This is used in masquerade to exchange topics for message routing
 */
void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b);

/*!
 * \brief Set uniqueid and linkedid string value only (not time)
 * \param chan The channel to set the uniqueid to
 * \param uniqueid The uniqueid to set
 * \param linkedid The linkedid to set
 * \return void
 *
 * \note
 * This is used only by ast_cel_fabricate_channel_from_event()
 * to create a temporary fake channel - time values are invalid
 */
void ast_channel_internal_set_fake_ids(struct ast_channel *chan, const char *uniqueid, const char *linkedid);

/* Misc. functions below */

/*!
 * \brief if fd is a valid descriptor, set *pfd with the descriptor
 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
 * return value to the index into the array)
 */
static inline int ast_add_fd(struct pollfd *pfd, int fd)
{
	pfd->fd = fd;
	pfd->events = POLLIN | POLLPRI;
	return fd >= 0;
}

/*! \brief Helper function for migrating select to poll */
static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
{
	int x;
	int dummy = 0;

	if (fd < 0)
		return 0;
	if (!start)
		start = &dummy;
	for (x = *start; x < maximum; x++)
		if (pfds[x].fd == fd) {
			if (x == *start)
				(*start)++;
			return pfds[x].revents;
		}
	return 0;
}

/*!
 * \brief Retrieves the current T38 state of a channel
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 */
static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
{
	enum ast_t38_state state = T38_STATE_UNAVAILABLE;
	int datalen = sizeof(state);

	ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);

	return state;
}

#define CHECK_BLOCKING(c) do { 	 \
	if (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING)) {\
		ast_debug(1, "Thread %p is blocking '%s', already blocked by thread %p in procedure %s\n", \
			(void *) pthread_self(), ast_channel_name(c), (void *) ast_channel_blocker(c), ast_channel_blockproc(c)); \
	} else { \
		ast_channel_blocker_set((c), pthread_self()); \
		ast_channel_blockproc_set((c), __PRETTY_FUNCTION__); \
		ast_set_flag(ast_channel_flags(c), AST_FLAG_BLOCKING); \
	} } while (0)

ast_group_t ast_get_group(const char *s);

/*! \brief Print call and pickup groups into buffer */
char *ast_print_group(char *buf, int buflen, ast_group_t group);

/*! \brief Opaque struct holding a namedgroups set, i.e. a set of group names */
struct ast_namedgroups;

/*! \brief Create an ast_namedgroups set with group names from comma separated string */
struct ast_namedgroups *ast_get_namedgroups(const char *s);
struct ast_namedgroups *ast_unref_namedgroups(struct ast_namedgroups *groups);
struct ast_namedgroups *ast_ref_namedgroups(struct ast_namedgroups *groups);
/*! \brief Return TRUE if group a and b contain at least one common groupname */
int ast_namedgroups_intersect(struct ast_namedgroups *a, struct ast_namedgroups *b);

/*! \brief Print named call groups and named pickup groups */
char *ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *groups);

/*! \brief return an ast_variable list of channeltypes */
struct ast_variable *ast_channeltype_list(void);

/*!
 * \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
 * \param reason  The integer argument, usually taken from AST_CONTROL_ macros
 * \return char pointer explaining the code
 */
const char *ast_channel_reason2str(int reason);

/*! \brief channel group info */
struct ast_group_info {
	struct ast_channel *chan;
	char *category;
	char *group;
	AST_LIST_ENTRY(ast_group_info) group_list;
};

#define ast_channel_lock(chan) ao2_lock(chan)
#define ast_channel_unlock(chan) ao2_unlock(chan)
#define ast_channel_trylock(chan) ao2_trylock(chan)

/*!
 * \brief Lock two channels.
 */
#define ast_channel_lock_both(chan1, chan2) do { \
		ast_channel_lock(chan1); \
		while (ast_channel_trylock(chan2)) { \
			ast_channel_unlock(chan1); \
			sched_yield(); \
			ast_channel_lock(chan1); \
		} \
	} while (0)

/*!
 * \brief Increase channel reference count
 *
 * \param c the channel
 *
 * \retval c always
 *
 * \since 1.8
 */
#define ast_channel_ref(c) ({ ao2_ref(c, +1); (c); })

/*!
 * \brief Decrease channel reference count
 *
 * \param c the channel
 *
 * \retval NULL always
 *
 * \since 1.8
 */
#define ast_channel_unref(c) ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })

/*!
 * \brief Cleanup a channel reference
 *
 * \param c the channel (NULL tolerant)
 *
 * \retval NULL always
 *
 * \since 12.0.0
 */
#define ast_channel_cleanup(c) ({ ao2_cleanup(c); (struct ast_channel *) (NULL); })

/*! Channel Iterating @{ */

/*!
 * \brief A channel iterator
 *
 * This is an opaque type.
 */
struct ast_channel_iterator;

/*!
 * \brief Destroy a channel iterator
 *
 * \param i the itereator to destroy
 *
 * \details
 * This function is used to destroy a channel iterator that was retrieved by
 * using one of the channel_iterator_xxx_new() functions.
 *
 * \return NULL, for convenience to clear out the pointer to the iterator that
 * was just destroyed.
 *
 * \since 1.8
 */
struct ast_channel_iterator *ast_channel_iterator_destroy(struct ast_channel_iterator *i);

/*!
 * \brief Create a new channel iterator based on extension
 *
 * \param exten The extension that channels must be in
 * \param context The context that channels must be in
 *
 * \details
 * After creating an iterator using this function, the ast_channel_iterator_next()
 * function can be used to iterate through all channels that are currently
 * in the specified context and extension.
 *
 * \note You must call ast_channel_iterator_destroy() when done.
 *
 * \retval NULL on failure
 * \retval a new channel iterator based on the specified parameters
 *
 * \since 1.8
 */
struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context);

/*!
 * \brief Create a new channel iterator based on name
 *
 * \param name channel name or channel uniqueid to match
 * \param name_len number of characters in the channel name to match on.  This
 *      would be used to match based on name prefix.  If matching on the full
 *      channel name is desired, then this parameter should be 0.
 *
 * \details
 * After creating an iterator using this function, the ast_channel_iterator_next()
 * function can be used to iterate through all channels that exist that have
 * the specified name or name prefix.
 *
 * \note You must call ast_channel_iterator_destroy() when done.
 *
 * \retval NULL on failure
 * \retval a new channel iterator based on the specified parameters
 *
 * \since 1.8
 */
struct ast_channel_iterator *ast_channel_iterator_by_name_new(const char *name,	size_t name_len);

/*!
 * \brief Create a new channel iterator
 *
 * \details
 * After creating an iterator using this function, the ast_channel_iterator_next()
 * function can be used to iterate through all channels that exist.
 *
 * \note You must call ast_channel_iterator_destroy() when done.
 *
 * \retval NULL on failure
 * \retval a new channel iterator
 *
 * \since 1.8
 */
struct ast_channel_iterator *ast_channel_iterator_all_new(void);

/*!
 * \brief Get the next channel for a channel iterator
 *
 * \param i the channel iterator that was created using one of the
 *  channel_iterator_xxx_new() functions.
 *
 * \details
 * This function should be used to iterate through all channels that match a
 * specified set of parameters that were provided when the iterator was created.
 *
 * \retval the next channel that matches the parameters used when the iterator
 *         was created.
 * \retval NULL, if no more channels match the iterator parameters.
 *
 * \since 1.8
 */
struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);

/*! @} End channel iterator definitions. */

/*!
 * \brief Call a function with every active channel
 *
 * \details
 * This function executes a callback one time for each active channel on the
 * system.  The channel is provided as an argument to the function.
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 * \since 1.8
 */
struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
		void *data, int ao2_flags);

/*! @{ Channel search functions */

/*!
 * \brief Find a channel by name
 *
 * \param name the name or uniqueid of the channel to search for
 *
 * \details
 * Find a channel that has the same name as the provided argument.
 *
 * \retval a channel with the name specified by the argument
 * \retval NULL if no channel was found
 *
 * \since 1.8
 */
struct ast_channel *ast_channel_get_by_name(const char *name);

/*!
 * \brief Find a channel by a name prefix
 *
 * \param name The channel name or uniqueid prefix to search for
 * \param name_len Only search for up to this many characters from the name
 *
 * \details
 * Find a channel that has the same name prefix as specified by the arguments.
 *
 * \retval a channel with the name prefix specified by the arguments
 * \retval NULL if no channel was found
 *
 * \since 1.8
 */
struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);

/*!
 * \brief Find a channel by extension and context
 *
 * \param exten the extension to search for
 * \param context the context to search for
 *
 * \details
 * Return a channel that is currently at the specified extension and context.
 *
 * \retval a channel that is at the specified extension and context
 * \retval NULL if no channel was found
 *
 * \since 1.8
 */
struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);

/*! @} End channel search functions. */

/*!
 * \brief Initialize the given name structure.
 * \since 1.8
 *
 * \param init Name structure to initialize.
 *
 * \return Nothing
 */
void ast_party_name_init(struct ast_party_name *init);

/*!
 * \brief Copy the source party name information to the destination party name.
 * \since 1.8
 *
 * \param dest Destination party name
 * \param src Source party name
 *
 * \return Nothing
 */
void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src);

/*!
 * \brief Initialize the given party name structure using the given guide
 * for a set update operation.
 * \since 1.8
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Party name structure to initialize.
 * \param guide Source party name to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide);

/*!
 * \brief Set the source party name information into the destination party name.
 * \since 1.8
 *
 * \param dest The name one wishes to update
 * \param src The new name values to update the dest
 *
 * \return Nothing
 */
void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src);

/*!
 * \brief Destroy the party name contents
 * \since 1.8
 *
 * \param doomed The party name to destroy.
 *
 * \return Nothing
 */
void ast_party_name_free(struct ast_party_name *doomed);

/*!
 * \brief Initialize the given number structure.
 * \since 1.8
 *
 * \param init Number structure to initialize.
 *
 * \return Nothing
 */
void ast_party_number_init(struct ast_party_number *init);

/*!
 * \brief Copy the source party number information to the destination party number.
 * \since 1.8
 *
 * \param dest Destination party number
 * \param src Source party number
 *
 * \return Nothing
 */
void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src);

/*!
 * \brief Initialize the given party number structure using the given guide
 * for a set update operation.
 * \since 1.8
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Party number structure to initialize.
 * \param guide Source party number to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide);

/*!
 * \brief Set the source party number information into the destination party number.
 * \since 1.8
 *
 * \param dest The number one wishes to update
 * \param src The new number values to update the dest
 *
 * \return Nothing
 */
void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src);

/*!
 * \brief Destroy the party number contents
 * \since 1.8
 *
 * \param doomed The party number to destroy.
 *
 * \return Nothing
 */
void ast_party_number_free(struct ast_party_number *doomed);

/*!
 * \since 1.8
 * \brief Initialize the given subaddress structure.
 *
 * \param init Subaddress structure to initialize.
 *
 * \return Nothing
 */
void ast_party_subaddress_init(struct ast_party_subaddress *init);

/*!
 * \since 1.8
 * \brief Copy the source party subaddress information to the destination party subaddress.
 *
 * \param dest Destination party subaddress
 * \param src Source party subaddress
 *
 * \return Nothing
 */
void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);

/*!
 * \since 1.8
 * \brief Initialize the given party subaddress structure using the given guide
 * for a set update operation.
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Party subaddress structure to initialize.
 * \param guide Source party subaddress to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide);

/*!
 * \since 1.8
 * \brief Set the source party subaddress information into the destination party subaddress.
 *
 * \param dest The subaddress one wishes to update
 * \param src The new subaddress values to update the dest
 *
 * \return Nothing
 */
void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);

/*!
 * \since 1.8
 * \brief Destroy the party subaddress contents
 *
 * \param doomed The party subaddress to destroy.
 *
 * \return Nothing
 */
void ast_party_subaddress_free(struct ast_party_subaddress *doomed);

/*!
 * \brief Set the update marker to update all information of a corresponding party id.
 * \since 11.0
 *
 * \param update_id The update marker for a corresponding party id.
 *
 * \return Nothing
 */
void ast_set_party_id_all(struct ast_set_party_id *update_id);

/*!
 * \brief Initialize the given party id structure.
 * \since 1.8
 *
 * \param init Party id structure to initialize.
 *
 * \return Nothing
 */
void ast_party_id_init(struct ast_party_id *init);

/*!
 * \brief Copy the source party id information to the destination party id.
 * \since 1.8
 *
 * \param dest Destination party id
 * \param src Source party id
 *
 * \return Nothing
 */
void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src);

/*!
 * \brief Initialize the given party id structure using the given guide
 * for a set update operation.
 * \since 1.8
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Party id structure to initialize.
 * \param guide Source party id to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide);

/*!
 * \brief Set the source party id information into the destination party id.
 * \since 1.8
 *
 * \param dest The id one wishes to update
 * \param src The new id values to update the dest
 * \param update What id information to update.  NULL if all.
 *
 * \return Nothing
 */
void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update);

/*!
 * \brief Destroy the party id contents
 * \since 1.8
 *
 * \param doomed The party id to destroy.
 *
 * \return Nothing
 */
void ast_party_id_free(struct ast_party_id *doomed);

/*!
 * \brief Determine the overall presentation value for the given party.
 * \since 1.8
 *
 * \param id Party to determine the overall presentation value.
 *
 * \return Overall presentation value for the given party.
 */
int ast_party_id_presentation(const struct ast_party_id *id);

/*!
 * \brief Invalidate all components of the given party id.
 * \since 11.0
 *
 * \param id The party id to invalidate.
 *
 * \return Nothing
 */
void ast_party_id_invalidate(struct ast_party_id *id);

/*!
 * \brief Destroy and initialize the given party id structure.
 * \since 11.0
 *
 * \param id The party id to reset.
 *
 * \return Nothing
 */
void ast_party_id_reset(struct ast_party_id *id);

/*!
 * \brief Merge a given party id into another given party id.
 * \since 11.0
 *
 * \details
 * This function will generate an effective party id.
 *
 * Each party id component of the party id 'base' is overwritten
 * by components of the party id 'overlay' if the overlay
 * component is marked as valid.  However the component 'tag' of
 * the base party id remains untouched.
 *
 * \param base The party id which is merged.
 * \param overlay The party id which is used to merge into.
 *
 * \return The merged party id as a struct, not as a pointer.
 * \note The merged party id returned is a shallow copy and must not be freed.
 */
struct ast_party_id ast_party_id_merge(struct ast_party_id *base, struct ast_party_id *overlay);

/*!
 * \brief Copy a merge of a given party id into another given party id to a given destination party id.
 * \since 11.0
 *
 * \details
 * Each party id component of the party id 'base' is overwritten by components
 * of the party id 'overlay' if the 'overlay' component is marked as valid.
 * However the component 'tag' of the 'base' party id remains untouched.
 * The result is copied into the given party id 'dest'.
 *
 * \note The resulting merged party id is a real copy and has to be freed.
 *
 * \param dest The resulting merged party id.
 * \param base The party id which is merged.
 * \param overlay The party id which is used to merge into.
 *
 * \return Nothing
 */
void ast_party_id_merge_copy(struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay);

/*!
 * \brief Initialize the given dialed structure.
 * \since 1.8
 *
 * \param init Dialed structure to initialize.
 *
 * \return Nothing
 */
void ast_party_dialed_init(struct ast_party_dialed *init);

/*!
 * \brief Copy the source dialed party information to the destination dialed party.
 * \since 1.8
 *
 * \param dest Destination dialed party
 * \param src Source dialed party
 *
 * \return Nothing
 */
void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src);

/*!
 * \brief Initialize the given dialed structure using the given
 * guide for a set update operation.
 * \since 1.8
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Caller structure to initialize.
 * \param guide Source dialed to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide);

/*!
 * \brief Set the dialed information based on another dialed source
 * \since 1.8
 *
 * This is similar to ast_party_dialed_copy, except that NULL values for
 * strings in the src parameter indicate not to update the corresponding dest values.
 *
 * \param dest The dialed one wishes to update
 * \param src The new dialed values to update the dest
 *
 * \return Nada
 */
void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src);

/*!
 * \brief Destroy the dialed party contents
 * \since 1.8
 *
 * \param doomed The dialed party to destroy.
 *
 * \return Nothing
 */
void ast_party_dialed_free(struct ast_party_dialed *doomed);

/*!
 * \since 1.8
 * \brief Initialize the given caller structure.
 *
 * \param init Caller structure to initialize.
 *
 * \return Nothing
 */
void ast_party_caller_init(struct ast_party_caller *init);

/*!
 * \since 1.8
 * \brief Copy the source caller information to the destination caller.
 *
 * \param dest Destination caller
 * \param src Source caller
 *
 * \return Nothing
 */
void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src);

/*!
 * \brief Initialize the given caller structure using the given
 * guide for a set update operation.
 * \since 1.8
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Caller structure to initialize.
 * \param guide Source caller to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide);

/*!
 * \brief Set the caller information based on another caller source
 * \since 1.8
 *
 * This is similar to ast_party_caller_copy, except that NULL values for
 * strings in the src parameter indicate not to update the corresponding dest values.
 *
 * \param dest The caller one wishes to update
 * \param src The new caller values to update the dest
 * \param update What caller information to update.  NULL if all.
 *
 * \return Nada
 */
void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update);

/*!
 * \brief Destroy the caller party contents
 * \since 1.8
 *
 * \param doomed The caller party to destroy.
 *
 * \return Nothing
 */
void ast_party_caller_free(struct ast_party_caller *doomed);

/*!
 * \since 1.8
 * \brief Initialize the given connected line structure.
 *
 * \param init Connected line structure to initialize.
 *
 * \return Nothing
 */
void ast_party_connected_line_init(struct ast_party_connected_line *init);

/*!
 * \since 1.8
 * \brief Copy the source connected line information to the destination connected line.
 *
 * \param dest Destination connected line
 * \param src Source connected line
 *
 * \return Nothing
 */
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);

/*!
 * \since 1.8
 * \brief Initialize the given connected line structure using the given
 * guide for a set update operation.
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Connected line structure to initialize.
 * \param guide Source connected line to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide);

/*!
 * \since 1.8
 * \brief Set the connected line information based on another connected line source
 *
 * This is similar to ast_party_connected_line_copy, except that NULL values for
 * strings in the src parameter indicate not to update the corresponding dest values.
 *
 * \param dest The connected line one wishes to update
 * \param src The new connected line values to update the dest
 * \param update What connected line information to update.  NULL if all.
 *
 * \return Nothing
 */
void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update);

/*!
 * \since 1.8
 * \brief Collect the caller party information into a connected line structure.
 *
 * \param connected Collected caller information for the connected line
 * \param caller Caller information.
 *
 * \return Nothing
 *
 * \warning This is a shallow copy.
 * \warning DO NOT call ast_party_connected_line_free() on the filled in
 * connected line structure!
 */
void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_party_caller *caller);

/*!
 * \since 1.8
 * \brief Destroy the connected line information contents
 *
 * \param doomed The connected line information to destroy.
 *
 * \return Nothing
 */
void ast_party_connected_line_free(struct ast_party_connected_line *doomed);

/*!
 * \brief Initialize the given redirecting reason structure
 *
 * \param init Redirecting reason structure to initialize
 *
 * \return Nothing
 */
void ast_party_redirecting_reason_init(struct ast_party_redirecting_reason *init);

/*!
 * \brief Copy the source redirecting reason information to the destination redirecting reason.
 *
 * \param dest Destination redirecting reason
 * \param src Source redirecting reason
 *
 * \return Nothing
 */
void ast_party_redirecting_reason_copy(struct ast_party_redirecting_reason *dest,
		const struct ast_party_redirecting_reason *src);

/*!
 * \brief Initialize the given redirecting reason structure using the given guide
 * for a set update operation.
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Redirecting reason structure to initialize.
 * \param guide Source redirecting reason to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_redirecting_reason_set_init(struct ast_party_redirecting_reason *init,
		const struct ast_party_redirecting_reason *guide);

/*!
 * \brief Set the redirecting reason information based on another redirecting reason source
 *
 * This is similar to ast_party_redirecting_reason_copy, except that NULL values for
 * strings in the src parameter indicate not to update the corresponding dest values.
 *
 * \param dest The redirecting reason one wishes to update
 * \param src The new redirecting reason values to update the dest
 *
 * \return Nothing
 */
void ast_party_redirecting_reason_set(struct ast_party_redirecting_reason *dest,
		const struct ast_party_redirecting_reason *src);

/*!
 * \brief Destroy the redirecting reason contents
 *
 * \param doomed The redirecting reason to destroy.
 *
 * \return Nothing
 */
void ast_party_redirecting_reason_free(struct ast_party_redirecting_reason *doomed);

/*!
 * \brief Initialize the given redirecting structure.
 * \since 1.8
 *
 * \param init Redirecting structure to initialize.
 *
 * \return Nothing
 */
void ast_party_redirecting_init(struct ast_party_redirecting *init);

/*!
 * \since 1.8
 * \brief Copy the source redirecting information to the destination redirecting.
 *
 * \param dest Destination redirecting
 * \param src Source redirecting
 *
 * \return Nothing
 */
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src);

/*!
 * \since 1.8
 * \brief Initialize the given redirecting id structure using the given guide
 * for a set update operation.
 *
 * \details
 * The initialization is needed to allow a set operation to know if a
 * value needs to be updated.  Simple integers need the guide's original
 * value in case the set operation is not trying to set a new value.
 * String values are simply set to NULL pointers if they are not going
 * to be updated.
 *
 * \param init Redirecting id structure to initialize.
 * \param guide Source redirecting id to use as a guide in initializing.
 *
 * \return Nothing
 */
void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide);

/*!
 * \brief Set the redirecting information based on another redirecting source
 * \since 1.8
 *
 * This is similar to ast_party_redirecting_copy, except that NULL values for
 * strings in the src parameter indicate not to update the corresponding dest values.
 *
 * \param dest The redirecting one wishes to update
 * \param src The new redirecting values to update the dest
 * \param update What redirecting information to update.  NULL if all.
 *
 * \return Nothing
 */
void ast_party_redirecting_set(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update);

/*!
 * \since 1.8
 * \brief Destroy the redirecting information contents
 *
 * \param doomed The redirecting information to destroy.
 *
 * \return Nothing
 */
void ast_party_redirecting_free(struct ast_party_redirecting *doomed);

/*!
 * \since 1.8
 * \brief Copy the caller information to the connected line information.
 *
 * \param dest Destination connected line information
 * \param src Source caller information
 *
 * \return Nothing
 *
 * \note Assumes locks are already acquired
 */
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src);

/*!
 * \since 1.8
 * \brief Copy the connected line information to the caller information.
 *
 * \param dest Destination caller information
 * \param src Source connected line information
 *
 * \return Nothing
 *
 * \note Assumes locks are already acquired
 */
void ast_connected_line_copy_to_caller(struct ast_party_caller *dest, const struct ast_party_connected_line *src);

/*!
 * \since 1.8
 * \brief Set the connected line information in the Asterisk channel
 *
 * \param chan Asterisk channel to set connected line information
 * \param connected Connected line information
 * \param update What connected line information to update.  NULL if all.
 *
 * \return Nothing
 *
 * \note The channel does not need to be locked before calling this function.
 */
void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);

/*!
 * \since 1.8
 * \brief Build the connected line information data frame.
 *
 * \param data Buffer to fill with the frame data
 * \param datalen Size of the buffer to fill
 * \param connected Connected line information
 * \param update What connected line information to build.  NULL if all.
 *
 * \retval -1 if error
 * \retval Amount of data buffer used
 */
int ast_connected_line_build_data(unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);

/*!
 * \since 1.8
 * \brief Parse connected line indication frame data
 *
 * \param data Buffer with the frame data to parse
 * \param datalen Size of the buffer
 * \param connected Extracted connected line information
 *
 * \retval 0 on success.
 * \retval -1 on error.
 *
 * \note The filled in connected line structure needs to be initialized by
 * ast_party_connected_line_set_init() before calling.  If defaults are not
 * required use ast_party_connected_line_init().
 * \note The filled in connected line structure needs to be destroyed by
 * ast_party_connected_line_free() when it is no longer needed.
 */
int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected);

/*!
 * \since 1.8
 * \brief Indicate that the connected line information has changed
 *
 * \param chan Asterisk channel to indicate connected line information
 * \param connected Connected line information
 * \param update What connected line information to update.  NULL if all.
 *
 * \return Nothing
 */
void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);

/*!
 * \since 1.8
 * \brief Queue a connected line update frame on a channel
 *
 * \param chan Asterisk channel to indicate connected line information
 * \param connected Connected line information
 * \param update What connected line information to update.  NULL if all.
 *
 * \return Nothing
 */
void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);

/*!
 * \since 1.8
 * \brief Set the redirecting id information in the Asterisk channel
 *
 * \param chan Asterisk channel to set redirecting id information
 * \param redirecting Redirecting id information
 * \param update What redirecting information to update.  NULL if all.
 *
 * \return Nothing
 *
 * \note The channel does not need to be locked before calling this function.
 */
void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);

/*!
 * \since 1.8
 * \brief Build the redirecting id data frame.
 *
 * \param data Buffer to fill with the frame data
 * \param datalen Size of the buffer to fill
 * \param redirecting Redirecting id information
 * \param update What redirecting information to build.  NULL if all.
 *
 * \retval -1 if error
 * \retval Amount of data buffer used
 */
int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);

/*!
 * \since 1.8
 * \brief Parse redirecting indication frame data
 *
 * \param data Buffer with the frame data to parse
 * \param datalen Size of the buffer
 * \param redirecting Extracted redirecting id information
 *
 * \retval 0 on success.
 * \retval -1 on error.
 *
 * \note The filled in id structure needs to be initialized by
 * ast_party_redirecting_set_init() before calling.
 * \note The filled in id structure needs to be destroyed by
 * ast_party_redirecting_free() when it is no longer needed.
 */
int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting);

/*!
 * \since 1.8
 * \brief Indicate that the redirecting id has changed
 *
 * \param chan Asterisk channel to indicate redirecting id information
 * \param redirecting Redirecting id information
 * \param update What redirecting information to update.  NULL if all.
 *
 * \return Nothing
 */
void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);

/*!
 * \since 1.8
 * \brief Queue a redirecting update frame on a channel
 *
 * \param chan Asterisk channel to indicate redirecting id information
 * \param redirecting Redirecting id information
 * \param update What redirecting information to update.  NULL if all.
 *
 * \return Nothing
 */
void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);

/*!
 * \since 1.8
 * \brief Run a connected line interception macro and update a channel's connected line
 * information
 * \deprecated You should use the ast_channel_connected_line_sub() function instead.
 *
 * Whenever we want to update a channel's connected line information, we may need to run
 * a macro so that an administrator can manipulate the information before sending it
 * out. This function both runs the macro and sends the update to the channel.
 *
 * \param autoservice_chan Channel to place into autoservice while the macro is running.
 * It is perfectly safe for this to be NULL
 * \param macro_chan The channel to run the macro on. Also the channel from which we
 * determine which macro we need to run.
 * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
 * AST_CONTROL_CONNECTED_LINE
 * \param is_caller If true, then run CONNECTED_LINE_CALLER_SEND_MACRO with arguments from
 * CONNECTED_LINE_CALLER_SEND_MACRO_ARGS, otherwise run CONNECTED_LINE_CALLEE_SEND_MACRO
 * with arguments from CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS
 * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
 * ast_party_connected_line pointer.
 * \retval 0 Success
 * \retval -1 Either the macro does not exist, or there was an error while attempting to
 * run the macro
 *
 * \todo Have multiple return codes based on the MACRO_RESULT
 * \todo Make constants so that caller and frame can be more expressive than just '1' and
 * '0'
 */
int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int frame);

/*!
 * \since 11
 * \brief Run a connected line interception subroutine and update a channel's connected line
 * information
 *
 * Whenever we want to update a channel's connected line information, we may need to run
 * a subroutine so that an administrator can manipulate the information before sending it
 * out. This function both runs the subroutine specified by CONNECTED_LINE_SEND_SUB and
 * sends the update to the channel.
 *
 * \param autoservice_chan Channel to place into autoservice while the sub is running.
 * It is perfectly safe for this to be NULL
 * \param sub_chan The channel to run the subroutine on. Also the channel from which we
 * determine which subroutine we need to run.
 * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
 * AST_CONTROL_CONNECTED_LINE
 * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
 * ast_party_connected_line pointer.
 * \retval 0 Success
 * \retval -1 Either the subroutine does not exist, or there was an error while attempting to
 * run the subroutine
 */
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame);

/*!
 * \since 1.8
 * \brief Run a redirecting interception macro and update a channel's redirecting information
 * \deprecated You should use the ast_channel_redirecting_sub() function instead.
 *
 * \details
 * Whenever we want to update a channel's redirecting information, we may need to run
 * a macro so that an administrator can manipulate the information before sending it
 * out. This function both runs the macro and sends the update to the channel.
 *
 * \param autoservice_chan Channel to place into autoservice while the macro is running.
 * It is perfectly safe for this to be NULL
 * \param macro_chan The channel to run the macro on. Also the channel from which we
 * determine which macro we need to run.
 * \param redirecting_info Either an ast_party_redirecting or ast_frame pointer of type
 * AST_CONTROL_REDIRECTING
 * \param is_caller If true, then run REDIRECTING_CALLER_SEND_MACRO with arguments from
 * REDIRECTING_CALLER_SEND_MACRO_ARGS, otherwise run REDIRECTING_CALLEE_SEND_MACRO with
 * arguments from REDIRECTING_CALLEE_SEND_MACRO_ARGS
 * \param is_frame If true, then redirecting_info is an ast_frame pointer, otherwise it is an
 * ast_party_redirecting pointer.
 *
 * \retval 0 Success
 * \retval -1 Either the macro does not exist, or there was an error while attempting to
 * run the macro
 *
 * \todo Have multiple return codes based on the MACRO_RESULT
 * \todo Make constants so that caller and frame can be more expressive than just '1' and
 * '0'
 */
int ast_channel_redirecting_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame);

/*!
 * \since 11
 * \brief Run a redirecting interception subroutine and update a channel's redirecting information
 *
 * \details
 * Whenever we want to update a channel's redirecting information, we may need to run
 * a subroutine so that an administrator can manipulate the information before sending it
 * out. This function both runs the subroutine specified by REDIRECTING_SEND_SUB and
 * sends the update to the channel.
 *
 * \param autoservice_chan Channel to place into autoservice while the subroutine is running.
 * It is perfectly safe for this to be NULL
 * \param sub_chan The channel to run the subroutine on. Also the channel from which we
 * determine which subroutine we need to run.
 * \param redirecting_info Either an ast_party_redirecting or ast_frame pointer of type
 * AST_CONTROL_REDIRECTING
 * \param is_frame If true, then redirecting_info is an ast_frame pointer, otherwise it is an
 * ast_party_redirecting pointer.
 *
 * \retval 0 Success
 * \retval -1 Either the subroutine does not exist, or there was an error while attempting to
 * run the subroutine
 */
int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame);

#include "asterisk/ccss.h"

/*!
 * \since 1.8
 * \brief Set up datastore with CCSS parameters for a channel
 *
 * \note
 * If base_params is NULL, the channel will get the default
 * values for all CCSS parameters.
 *
 * \details
 * This function makes use of datastore operations on the channel, so
 * it is important to lock the channel before calling this function.
 *
 * \param chan The channel to create the datastore on
 * \param base_params CCSS parameters we wish to copy into the channel
 * \retval 0 Success
 * \retval -1 Failure
 */
int ast_channel_cc_params_init(struct ast_channel *chan,
		const struct ast_cc_config_params *base_params);

/*!
 * \since 1.8
 * \brief Get the CCSS parameters from a channel
 *
 * \details
 * This function makes use of datastore operations on the channel, so
 * it is important to lock the channel before calling this function.
 *
 * \param chan Channel to retrieve parameters from
 * \retval NULL Failure
 * \retval non-NULL The parameters desired
 */
struct ast_cc_config_params *ast_channel_get_cc_config_params(struct ast_channel *chan);


/*!
 * \since 1.8
 * \brief Get a device name given its channel structure
 *
 * \details
 * A common practice in Asterisk is to determine the device being talked
 * to by dissecting the channel name. For certain channel types, this is not
 * accurate. For instance, an ISDN channel is named based on what B channel is
 * used, not the device being communicated with.
 *
 * This function interfaces with a channel tech's queryoption callback to
 * retrieve the name of the device being communicated with. If the channel does not
 * implement this specific option, then the traditional method of using the channel
 * name is used instead.
 *
 * \param chan The channel to retrieve the information from
 * \param[out] device_name The buffer to place the device's name into
 * \param name_buffer_length The allocated space for the device_name
 * \return 0 always
 */
int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length);

/*!
 * \since 1.8
 * \brief Find the appropriate CC agent type to use given a channel
 *
 * \details
 * During call completion, we will need to create a call completion agent structure. To
 * figure out the type of agent to construct, we need to ask the channel driver for the
 * appropriate type.
 *
 * Prior to adding this function, the call completion core attempted to figure this
 * out for itself by stripping the technology off the channel's name. However, in the
 * case of chan_dahdi, there are multiple agent types registered, and so simply searching
 * for an agent type called "DAHDI" is not possible. In a case where multiple agent types
 * are defined, the channel driver must have a queryoption callback defined in its
 * channel_tech, and the queryoption callback must handle AST_OPTION_CC_AGENT_TYPE
 *
 * If a channel driver does not have a queryoption callback or if the queryoption callback
 * does not handle AST_OPTION_CC_AGENT_TYPE, then the old behavior of using the technology
 * portion of the channel name is used instead. This is perfectly suitable for channel drivers
 * whose channel technologies are a one-to-one match with the agent types defined within.
 *
 * Note that this function is only called when the agent policy on a given channel is set
 * to "native." Generic agents' type can be determined automatically by the core.
 *
 * \param chan The channel for which we wish to retrieve the agent type
 * \param[out] agent_type The type of agent the channel driver wants us to use
 * \param size The size of the buffer to write to
 */
int ast_channel_get_cc_agent_type(struct ast_channel *chan, char *agent_type, size_t size);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

/*!
 * \brief Remove a channel from the global channels container
 *
 * \param chan channel to remove
 *
 * In a case where it is desired that a channel not be available in any lookups
 * in the global channels conatiner, use this function.
 */
void ast_channel_unlink(struct ast_channel *chan);

/*!
 * \brief Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash
 * on the given channel
 *
 * \param chan channel on which to set the cause information
 * \param cause_code ast_control_pvt_cause_code structure containing cause information
 * \param datalen total length of the structure since it may vary
 */
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen);

/*!
 * \since 12
 * \brief Convert a string to a detail record AMA flag
 *
 * \param flag string form of flag
 *
 * \retval the enum (integer) form of the flag
 */
enum ama_flags ast_channel_string2amaflag(const char *flag);

/*!
 * \since 12
 * \brief Convert the enum representation of an AMA flag to a string representation
 *
 * \param flags integer flag
 *
 * \retval A string representation of the flag
 */
const char *ast_channel_amaflags2string(enum ama_flags flags);

enum AST_MONITORING_STATE {
	AST_MONITOR_RUNNING,
	AST_MONITOR_PAUSED
};

/*! Responsible for channel monitoring data */
struct ast_channel_monitor {
	struct ast_filestream *read_stream;
	struct ast_filestream *write_stream;
	char read_filename[FILENAME_MAX];
	char write_filename[FILENAME_MAX];
	char filename_base[FILENAME_MAX];
	char beep_id[64];
	int filename_changed;
	char *format;
	int joinfiles;
	enum AST_MONITORING_STATE state;
	int (*stop)(struct ast_channel *chan, int need_lock);
};

/* ACCESSOR FUNTIONS */
/*! \brief Set the channel name */
void ast_channel_name_set(struct ast_channel *chan, const char *name);

#define DECLARE_STRINGFIELD_SETTERS_FOR(field)	\
	void ast_channel_##field##_set(struct ast_channel *chan, const char *field); \
	void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) __attribute__((format(printf, 2, 0))); \
	void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) __attribute__((format(printf, 2, 3)))

/*!
 * The following string fields result in channel snapshot creation and
 * should have the channel locked when called:
 *
 * \li language
 * \li accountcode
 * \li peeraccount
 * \li linkedid
 */
DECLARE_STRINGFIELD_SETTERS_FOR(name);
DECLARE_STRINGFIELD_SETTERS_FOR(language);
DECLARE_STRINGFIELD_SETTERS_FOR(musicclass);
DECLARE_STRINGFIELD_SETTERS_FOR(latest_musicclass);
DECLARE_STRINGFIELD_SETTERS_FOR(accountcode);
DECLARE_STRINGFIELD_SETTERS_FOR(peeraccount);
DECLARE_STRINGFIELD_SETTERS_FOR(userfield);
DECLARE_STRINGFIELD_SETTERS_FOR(call_forward);
DECLARE_STRINGFIELD_SETTERS_FOR(uniqueid);
DECLARE_STRINGFIELD_SETTERS_FOR(linkedid);
DECLARE_STRINGFIELD_SETTERS_FOR(parkinglot);
DECLARE_STRINGFIELD_SETTERS_FOR(hangupsource);
DECLARE_STRINGFIELD_SETTERS_FOR(dialcontext);

const char *ast_channel_name(const struct ast_channel *chan);
const char *ast_channel_language(const struct ast_channel *chan);
const char *ast_channel_musicclass(const struct ast_channel *chan);
const char *ast_channel_latest_musicclass(const struct ast_channel *chan);
const char *ast_channel_accountcode(const struct ast_channel *chan);
const char *ast_channel_peeraccount(const struct ast_channel *chan);
const char *ast_channel_userfield(const struct ast_channel *chan);
const char *ast_channel_call_forward(const struct ast_channel *chan);
const char *ast_channel_uniqueid(const struct ast_channel *chan);
const char *ast_channel_linkedid(const struct ast_channel *chan);
const char *ast_channel_parkinglot(const struct ast_channel *chan);
const char *ast_channel_hangupsource(const struct ast_channel *chan);
const char *ast_channel_dialcontext(const struct ast_channel *chan);

const char *ast_channel_appl(const struct ast_channel *chan);
void ast_channel_appl_set(struct ast_channel *chan, const char *value);
const char *ast_channel_blockproc(const struct ast_channel *chan);
void ast_channel_blockproc_set(struct ast_channel *chan, const char *value);
const char *ast_channel_data(const struct ast_channel *chan);
void ast_channel_data_set(struct ast_channel *chan, const char *value);

const char *ast_channel_context(const struct ast_channel *chan);
void ast_channel_context_set(struct ast_channel *chan, const char *value);
const char *ast_channel_exten(const struct ast_channel *chan);
void ast_channel_exten_set(struct ast_channel *chan, const char *value);
const char *ast_channel_macrocontext(const struct ast_channel *chan);
void ast_channel_macrocontext_set(struct ast_channel *chan, const char *value);
const char *ast_channel_macroexten(const struct ast_channel *chan);
void ast_channel_macroexten_set(struct ast_channel *chan, const char *value);

char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan);
void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value);
char ast_channel_sending_dtmf_digit(const struct ast_channel *chan);
void ast_channel_sending_dtmf_digit_set(struct ast_channel *chan, char value);
struct timeval ast_channel_sending_dtmf_tv(const struct ast_channel *chan);
void ast_channel_sending_dtmf_tv_set(struct ast_channel *chan, struct timeval value);
enum ama_flags ast_channel_amaflags(const struct ast_channel *chan);

/*!
 * \pre chan is locked
 */
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value);
int ast_channel_epfd(const struct ast_channel *chan);
void ast_channel_epfd_set(struct ast_channel *chan, int value);
int ast_channel_fdno(const struct ast_channel *chan);
void ast_channel_fdno_set(struct ast_channel *chan, int value);
int ast_channel_hangupcause(const struct ast_channel *chan);
void ast_channel_hangupcause_set(struct ast_channel *chan, int value);
int ast_channel_macropriority(const struct ast_channel *chan);
void ast_channel_macropriority_set(struct ast_channel *chan, int value);
int ast_channel_priority(const struct ast_channel *chan);
void ast_channel_priority_set(struct ast_channel *chan, int value);
int ast_channel_rings(const struct ast_channel *chan);
void ast_channel_rings_set(struct ast_channel *chan, int value);
int ast_channel_streamid(const struct ast_channel *chan);
void ast_channel_streamid_set(struct ast_channel *chan, int value);
int ast_channel_timingfd(const struct ast_channel *chan);
void ast_channel_timingfd_set(struct ast_channel *chan, int value);
int ast_channel_visible_indication(const struct ast_channel *chan);
void ast_channel_visible_indication_set(struct ast_channel *chan, int value);
int ast_channel_hold_state(const struct ast_channel *chan);
void ast_channel_hold_state_set(struct ast_channel *chan, int value);
int ast_channel_vstreamid(const struct ast_channel *chan);
void ast_channel_vstreamid_set(struct ast_channel *chan, int value);
unsigned short ast_channel_transfercapability(const struct ast_channel *chan);
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value);
unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan);
void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value);
unsigned int ast_channel_fin(const struct ast_channel *chan);
void ast_channel_fin_set(struct ast_channel *chan, unsigned int value);
unsigned int ast_channel_fout(const struct ast_channel *chan);
void ast_channel_fout_set(struct ast_channel *chan, unsigned int value);
unsigned long ast_channel_insmpl(const struct ast_channel *chan);
void ast_channel_insmpl_set(struct ast_channel *chan, unsigned long value);
unsigned long ast_channel_outsmpl(const struct ast_channel *chan);
void ast_channel_outsmpl_set(struct ast_channel *chan, unsigned long value);
void *ast_channel_generatordata(const struct ast_channel *chan);
void ast_channel_generatordata_set(struct ast_channel *chan, void *value);
void *ast_channel_music_state(const struct ast_channel *chan);
void ast_channel_music_state_set(struct ast_channel *chan, void *value);
void *ast_channel_tech_pvt(const struct ast_channel *chan);
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value);
void *ast_channel_timingdata(const struct ast_channel *chan);
void ast_channel_timingdata_set(struct ast_channel *chan, void *value);
struct ast_audiohook_list *ast_channel_audiohooks(const struct ast_channel *chan);
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value);
struct ast_cdr *ast_channel_cdr(const struct ast_channel *chan);
void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value);
struct ast_channel *ast_channel__bridge(const struct ast_channel *chan);
void ast_channel__bridge_set(struct ast_channel *chan, struct ast_channel *value);
struct ast_channel *ast_channel_masq(const struct ast_channel *chan);
void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value);
struct ast_channel *ast_channel_masqr(const struct ast_channel *chan);
void ast_channel_masqr_set(struct ast_channel *chan, struct ast_channel *value);
struct ast_channel_monitor *ast_channel_monitor(const struct ast_channel *chan);
void ast_channel_monitor_set(struct ast_channel *chan, struct ast_channel_monitor *value);
struct ast_filestream *ast_channel_stream(const struct ast_channel *chan);
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value);
struct ast_filestream *ast_channel_vstream(const struct ast_channel *chan);
void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value);
struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan);
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value);
struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan);
void ast_channel_framehooks_set(struct ast_channel *chan, struct ast_framehook_list *value);
struct ast_generator *ast_channel_generator(const struct ast_channel *chan);
void ast_channel_generator_set(struct ast_channel *chan, struct ast_generator *value);
struct ast_pbx *ast_channel_pbx(const struct ast_channel *chan);
void ast_channel_pbx_set(struct ast_channel *chan, struct ast_pbx *value);
struct ast_sched_context *ast_channel_sched(const struct ast_channel *chan);
void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value);
struct ast_timer *ast_channel_timer(const struct ast_channel *chan);
void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value);
struct ast_tone_zone *ast_channel_zone(const struct ast_channel *chan);
void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value);
struct ast_trans_pvt *ast_channel_readtrans(const struct ast_channel *chan);
void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value);
struct ast_trans_pvt *ast_channel_writetrans(const struct ast_channel *chan);
void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value);
const struct ast_channel_tech *ast_channel_tech(const struct ast_channel *chan);
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value);
enum ast_channel_adsicpe ast_channel_adsicpe(const struct ast_channel *chan);
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value);
enum ast_channel_state ast_channel_state(const struct ast_channel *chan);
ast_callid ast_channel_callid(const struct ast_channel *chan);

/*!
 * \pre chan is locked
 */
void ast_channel_callid_set(struct ast_channel *chan, ast_callid value);

/* XXX Internal use only, make sure to move later */
void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state);
void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value);
void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value);
void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int value);
void ast_channel_callid_cleanup(struct ast_channel *chan);
int ast_channel_softhangup_internal_flag(struct ast_channel *chan);

/* Format getters */
struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan);
struct ast_format *ast_channel_rawreadformat(struct ast_channel *chan);
struct ast_format *ast_channel_rawwriteformat(struct ast_channel *chan);
struct ast_format *ast_channel_readformat(struct ast_channel *chan);
struct ast_format *ast_channel_writeformat(struct ast_channel *chan);

/* Format setters - all of these functions will increment the reference count of the format passed in */
void ast_channel_set_oldwriteformat(struct ast_channel *chan, struct ast_format *format);
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format);
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format);
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format);
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format);

/* Other struct getters */
struct ast_frame *ast_channel_dtmff(struct ast_channel *chan);
struct ast_jb *ast_channel_jb(struct ast_channel *chan);
struct ast_party_caller *ast_channel_caller(struct ast_channel *chan);
struct ast_party_connected_line *ast_channel_connected(struct ast_channel *chan);
struct ast_party_connected_line *ast_channel_connected_indicated(struct ast_channel *chan);
struct ast_party_id ast_channel_connected_effective_id(struct ast_channel *chan);
struct ast_party_dialed *ast_channel_dialed(struct ast_channel *chan);
struct ast_party_redirecting *ast_channel_redirecting(struct ast_channel *chan);
struct ast_party_id ast_channel_redirecting_effective_orig(struct ast_channel *chan);
struct ast_party_id ast_channel_redirecting_effective_from(struct ast_channel *chan);
struct ast_party_id ast_channel_redirecting_effective_to(struct ast_channel *chan);
struct timeval *ast_channel_dtmf_tv(struct ast_channel *chan);
struct timeval *ast_channel_whentohangup(struct ast_channel *chan);
struct varshead *ast_channel_varshead(struct ast_channel *chan);

void ast_channel_dtmff_set(struct ast_channel *chan, struct ast_frame *value);
void ast_channel_jb_set(struct ast_channel *chan, struct ast_jb *value);
void ast_channel_caller_set(struct ast_channel *chan, struct ast_party_caller *value);
void ast_channel_connected_set(struct ast_channel *chan, struct ast_party_connected_line *value);
void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value);
void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value);
void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value);

/*!
 * \pre chan is locked
 */
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value);
void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value);
struct timeval ast_channel_creationtime(struct ast_channel *chan);
void ast_channel_creationtime_set(struct ast_channel *chan, struct timeval *value);
struct timeval ast_channel_answertime(struct ast_channel *chan);
void ast_channel_answertime_set(struct ast_channel *chan, struct timeval *value);

/* List getters */
struct ast_hangup_handler_list *ast_channel_hangup_handlers(struct ast_channel *chan);
struct ast_datastore_list *ast_channel_datastores(struct ast_channel *chan);
struct ast_autochan_list *ast_channel_autochans(struct ast_channel *chan);
struct ast_readq_list *ast_channel_readq(struct ast_channel *chan);

/* Typedef accessors */
ast_group_t ast_channel_callgroup(const struct ast_channel *chan);
/*!
 * \pre chan is locked
 */
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value);
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan);
/*!
 * \pre chan is locked
 */
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value);
struct ast_namedgroups *ast_channel_named_callgroups(const struct ast_channel *chan);
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value);
struct ast_namedgroups *ast_channel_named_pickupgroups(const struct ast_channel *chan);
void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_namedgroups *value);

/* Alertpipe accessors--the "internal" functions for channel.c use only */
int ast_channel_alert_write(struct ast_channel *chan);
int ast_channel_alert_writable(struct ast_channel *chan);
ast_alert_status_t ast_channel_internal_alert_flush(struct ast_channel *chan);
ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan);
int ast_channel_internal_alert_readable(struct ast_channel *chan);
void ast_channel_internal_alertpipe_clear(struct ast_channel *chan);
void ast_channel_internal_alertpipe_close(struct ast_channel *chan);
int ast_channel_internal_alert_readfd(struct ast_channel *chan);
int ast_channel_internal_alertpipe_init(struct ast_channel *chan);
/*! \brief Swap the interal alertpipe between two channels
 * \note Handle all of the necessary locking before calling this
 */
void ast_channel_internal_alertpipe_swap(struct ast_channel *chan1, struct ast_channel *chan2);

/* file descriptor array accessors */
void ast_channel_internal_fd_clear(struct ast_channel *chan, int which);
void ast_channel_internal_fd_clear_all(struct ast_channel *chan);
void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value);
int ast_channel_fd(const struct ast_channel *chan, int which);
int ast_channel_fd_isset(const struct ast_channel *chan, int which);

/*!
 * \since 15
 * \brief Retrieve the number of file decriptor positions present on the channel
 *
 * \param chan The channel to get the count of
 *
 * \pre chan is locked
 *
 * \return The number of file descriptor positions
 */
int ast_channel_fd_count(const struct ast_channel *chan);

/*!
 * \since 15
 * \brief Add a file descriptor to the channel without a fixed position
 *
 * \param chan The channel to add the file descriptor to
 * \param value The file descriptor
 *
 * \pre chan is locked
 *
 * \return The position of the file descriptor
 */
int ast_channel_fd_add(struct ast_channel *chan, int value);

pthread_t ast_channel_blocker(const struct ast_channel *chan);
void ast_channel_blocker_set(struct ast_channel *chan, pthread_t value);

ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan);
void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value);

struct ast_bridge *ast_channel_internal_bridge(const struct ast_channel *chan);
/*!
 * \pre chan is locked
 */
void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value);

struct ast_bridge_channel *ast_channel_internal_bridge_channel(const struct ast_channel *chan);
void ast_channel_internal_bridge_channel_set(struct ast_channel *chan, struct ast_bridge_channel *value);

struct ast_channel *ast_channel_internal_bridged_channel(const struct ast_channel *chan);
void ast_channel_internal_bridged_channel_set(struct ast_channel *chan, struct ast_channel *value);

/*!
 * \since 11
 * \brief Retrieve a comma-separated list of channels for which dialed cause information is available
 *
 * \details
 * This function makes use of datastore operations on the channel, so
 * it is important to lock the channel before calling this function.
 *
 * \param chan The channel from which to retrieve information
 * \retval NULL on allocation failure
 * \retval Pointer to an ast_str object containing the desired information which must be freed
 */
struct ast_str *ast_channel_dialed_causes_channels(const struct ast_channel *chan);

/*!
 * \since 11
 * \brief Retrieve a ref-counted cause code information structure
 *
 * \details
 * This function makes use of datastore operations on the channel, so
 * it is important to lock the channel before calling this function.
 * This function increases the ref count of the returned object, so the
 * calling function must decrease the reference count when it is finished
 * with the object.
 *
 * \param chan The channel from which to retrieve information
 * \param chan_name The name of the channel about which to retrieve information
 * \retval NULL on search failure
 * \retval Pointer to a ref-counted ast_control_pvt_cause_code object containing the desired information
 */
struct ast_control_pvt_cause_code *ast_channel_dialed_causes_find(const struct ast_channel *chan, const char *chan_name);

/*!
 * \since 11
 * \brief Add cause code information to the channel
 *
 * \details
 * This function makes use of datastore operations on the channel, so
 * it is important to lock the channel before calling this function.
 * The passed in data is copied and so is still owned by the caller.
 *
 * \param chan The channel on which to add information
 * \param cause_code The cause information to be added to the channel
 * \param datalen The total length of the structure since its length is variable
 * \retval 0 on success
 * \retval -1 on error
 */
int ast_channel_dialed_causes_add(const struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen);

/*!
 * \since 11
 * \brief Clear all cause information from the channel
 *
 * \details
 * This function makes use of datastore operations on the channel, so
 * it is important to lock the channel before calling this function.
 *
 * \param chan The channel from which to clear information
 */
void ast_channel_dialed_causes_clear(const struct ast_channel *chan);

struct ast_flags *ast_channel_flags(struct ast_channel *chan);

/*!
 * \since 13.17.0
 * \brief Set a flag on a channel
 *
 * \param chan The channel to set the flag on
 * \param flag The flag to set
 *
 * \note This will lock the channel internally. If the channel is already
 * locked it is still safe to call.
 */

void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag);

/*!
 * \since 13.17.0
 * \param Clear a flag on a channel
 *
 * \param chan The channel to clear the flag from
 * \param flag The flag to clear
 *
 * \note This will lock the channel internally. If the channel is already
 * locked it is still safe to call.
 */
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag);

/*!
 * \since 12.4.0
 * \brief Return whether or not any manager variables have been set
 *
 * \retval 0 if no manager variables are expected
 * \retval 1 if manager variables are expected
 */
int ast_channel_has_manager_vars(void);

/*!
 * \since 12
 * \brief Sets the variables to be stored in the \a manager_vars field of all
 * snapshots.
 * \param varc Number of variable names.
 * \param vars Array of variable names.
 */
void ast_channel_set_manager_vars(size_t varc, char **vars);

/*!
 * \since 12
 * \brief Gets the variables for a given channel, as specified by ast_channel_set_manager_vars().
 *
 * The returned variable list is an AO2 object, so ao2_cleanup() to free it.
 *
 * \param chan Channel to get variables for.
 * \return List of channel variables.
 * \return \c NULL on error
 */
struct varshead *ast_channel_get_manager_vars(struct ast_channel *chan);

/*!
 * \since 14.2.0
 * \brief Return whether or not any ARI variables have been set
 *
 * \retval 0 if no ARI variables are expected
 * \retval 1 if ARI variables are expected
 */
int ast_channel_has_ari_vars(void);

/*!
 * \since 14.2.0
 * \brief Sets the variables to be stored in the \a ari_vars field of all
 * snapshots.
 * \param varc Number of variable names.
 * \param vars Array of variable names.
 */
void ast_channel_set_ari_vars(size_t varc, char **vars);

/*!
 * \since 14.2.0
 * \brief Gets the variables for a given channel, as specified by ast_channel_set_ari_vars().
 *
 * The returned variable list is an AO2 object, so ao2_cleanup() to free it.
 *
 * \param chan Channel to get variables for.
 * \return List of channel variables.
 * \return \c NULL on error
 */
struct varshead *ast_channel_get_ari_vars(struct ast_channel *chan);

/*!
 * \since 12
 * \brief Gets the variables for a given channel, as set using pbx_builtin_setvar_helper().
 *
 * The returned variable list is an AO2 object, so ao2_cleanup() to free it.
 *
 * \param chan Channel to get variables for
 * \return List of channel variables.
 * \return \c NULL on error
 */
struct varshead *ast_channel_get_vars(struct ast_channel *chan);

/*!
 * \since 12
 * \brief A topic which publishes the events for a particular channel.
 *
 * If the given \a chan is \c NULL, ast_channel_topic_all() is returned.
 *
 * \param chan Channel, or \c NULL.
 *
 * \retval Topic for channel's events.
 * \retval ast_channel_topic_all() if \a chan is \c NULL.
 */
struct stasis_topic *ast_channel_topic(struct ast_channel *chan);

/*!
 * \since 12
 * \brief A topic which publishes the events for a particular channel.
 *
 * \ref ast_channel_snapshot messages are replaced with \ref stasis_cache_update
 *
 * If the given \a chan is \c NULL, ast_channel_topic_all_cached() is returned.
 *
 * \param chan Channel, or \c NULL.
 *
 * \retval Topic for channel's events.
 * \retval ast_channel_topic_all() if \a chan is \c NULL.
 */
struct stasis_topic *ast_channel_topic_cached(struct ast_channel *chan);

/*!
 * \brief Get the bridge associated with a channel
 * \since 12.0.0
 *
 * \param chan The channel whose bridge we want
 *
 * \details
 * The bridge returned has its reference count incremented.  Use
 * ao2_cleanup() or ao2_ref() in order to decrement the
 * reference count when you are finished with the bridge.
 *
 * \note This function expects the channel to be locked prior to
 * being called and will not grab the channel lock.
 *
 * \retval NULL No bridge present on the channel
 * \retval non-NULL The bridge the channel is in
 */
struct ast_bridge *ast_channel_get_bridge(const struct ast_channel *chan);

/*!
 * \brief Determine if a channel is in a bridge
 * \since 12.0.0
 *
 * \param chan The channel to test
 *
 * \note This function expects the channel to be locked prior to
 * being called and will not grab the channel lock.
 *
 * \retval 0 The channel is not bridged
 * \retval non-zero The channel is bridged
 */
int ast_channel_is_bridged(const struct ast_channel *chan);

/*!
 * \brief Determine if a channel is leaving a bridge, but \em not hung up
 * \since 12.4.0
 *
 * \param chan The channel to test
 *
 * \note If a channel is hung up, it is implicitly leaving any bridge it
 * may be in. This function is used to test if a channel is leaving a bridge
 * but may survive the experience, if it has a place to go to (dialplan or
 * otherwise)
 *
 * \retval 0 The channel is not leaving the bridge or is hung up
 * \retval non-zero The channel is leaving the bridge
 */
int ast_channel_is_leaving_bridge(struct ast_channel *chan);

/*!
 * \brief Get the channel's bridge peer only if the bridge is two-party.
 * \since 12.0.0
 *
 * \param chan Channel desiring the bridge peer channel.
 *
 * \note The returned peer channel is the current peer in the
 * bridge when called.
 *
 * \note Absolutely _NO_ channel locks should be held when calling this function.
 *
 * \retval NULL Channel not in a bridge or the bridge is not two-party.
 * \retval non-NULL Reffed peer channel at time of calling.
 */
struct ast_channel *ast_channel_bridge_peer(struct ast_channel *chan);

/*!
 * \brief Get a reference to the channel's bridge pointer.
 * \since 12.0.0
 *
 * \param chan The channel whose bridge channel is desired
 *
 * \note This increases the reference count of the bridge_channel.
 * Use ao2_ref() or ao2_cleanup() to decrement the refcount when
 * you are finished with it.
 *
 * \note It is expected that the channel is locked prior to
 * placing this call.
 *
 * \retval NULL The channel has no bridge_channel
 * \retval non-NULL A reference to the bridge_channel
 */
struct ast_bridge_channel *ast_channel_get_bridge_channel(struct ast_channel *chan);

/*!
 * \since 12
 * \brief Gain control of a channel in the system
 *
 * The intention of this function is to take a channel that currently
 * is running in one thread and gain control of it in the current thread.
 * This can be used to redirect a channel to a different place in the dialplan,
 * for instance.
 *
 * \note This function is NOT intended to be used on bridged channels. If you
 * need to control a bridged channel, you can set a callback to be called
 * once the channel exits the bridge, and run your controlling logic in that
 * callback
 *
 * XXX Put name of callback-setting function in above paragraph once it is written
 *
 * \note When this function returns successfully, the yankee channel is in a state where
 * it cannot be used any further. Always use the returned channel instead.
 *
 * \note absolutely _NO_ channel locks should be held before calling this function.
 *
 * \note The dialplan location on the returned channel is where the channel
 * should be started in the dialplan if it is returned to it.
 *
 * \param yankee The channel to gain control of
 * \retval NULL Could not gain control of the channel
 * \retval non-NULL The channel
 */
struct ast_channel *ast_channel_yank(struct ast_channel *yankee);

/*!
 * \since 12
 * \brief Move a channel from its current location to a new location
 *
 * The intention of this function is to have the destination channel
 * take on the identity of the source channel.
 *
 * \note This function is NOT intended to be used on bridged channels. If you
 * wish to move an unbridged channel into the place of a bridged channel, then
 * use ast_bridge_join() or ast_bridge_impart(). If you wish to move a bridged
 * channel into the place of another bridged channel, then use ast_bridge_move().
 *
 * \note When this function returns succesfully, the source channel is in a
 * state where its continued use is unreliable.
 *
 * \note absolutely _NO_ channel locks should be held before calling this function.
 *
 * \param dest The place to move the source channel
 * \param source The channel to move
 * \retval 0 Success
 * \retval non-zero Failure
 */
int ast_channel_move(struct ast_channel *dest, struct ast_channel *source);

/*!
 * \since 12
 * \brief Forward channel stasis messages to the given endpoint
 *
 * \param chan The channel to forward from
 * \param endpoint The endpoint to forward to
 *
 * \retval 0 Success
 * \retval non-zero Failure
 */
int ast_channel_forward_endpoint(struct ast_channel *chan, struct ast_endpoint *endpoint);

/*!
 * \brief Return the oldest linkedid between two channels.
 *
 * A channel linkedid is derived from the channel uniqueid which is formed like this:
 * [systemname-]ctime.seq
 *
 * The systemname, and the dash are optional, followed by the epoch time followed by an
 * integer sequence.  Note that this is not a decimal number, since 1.2 is less than 1.11
 * in uniqueid land.
 *
 * To compare two uniqueids, we parse out the integer values of the time and the sequence
 * numbers and compare them, with time trumping sequence.
 *
 * \param a The linkedid value of the first channel to compare
 * \param b The linkedid value of the second channel to compare
 *
 * \retval NULL on failure
 * \retval The oldest linkedid value
 * \since 12.0.0
*/
const char *ast_channel_oldest_linkedid(const char *a, const char *b);

/*!
 * \brief Check if the channel has active audiohooks, active framehooks, or a monitor.
 * \since 12.0.0
 *
 * \param chan The channel to check.
 *
 * \retval non-zero if channel has active audiohooks, framehooks, or monitor.
 */
int ast_channel_has_audio_frame_or_monitor(struct ast_channel *chan);

/*!
 * \brief Check if the channel has any active hooks that require audio.
 * \since 12.3.0
 *
 * \param chan The channel to check.
 *
 * \retval non-zero if channel has active audiohooks, audio framehooks, or monitor.
 */
int ast_channel_has_hook_requiring_audio(struct ast_channel *chan);

/*!
 * \brief Removes the trailing identifiers from a channel name string
 * \since 12.0.0
 *
 * \param channel_name string that you wish to turn into a dial string.
 *                     This string will be edited in place.
 */
void ast_channel_name_to_dial_string(char *channel_name);

#define AST_MUTE_DIRECTION_READ (1 << 0)
#define AST_MUTE_DIRECTION_WRITE (1 << 1)

/*!
 * \brief Suppress passing of a frame type on a channel
 *
 * \note The channel should be locked before calling this function.
 *
 * \param chan The channel to suppress
 * \param direction The direction in which to suppress
 * \param frametype The type of frame (AST_FRAME_VOICE, etc) to suppress
 *
 * \retval 0 Success
 * \retval -1 Failure
 */
int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype);

/*!
 * \brief Stop suppressing of a frame type on a channel
 *
 * \note The channel should be locked before calling this function.
 *
 * \param chan The channel to stop suppressing
 * \param direction The direction in which to stop suppressing
 * \param frametype The type of frame (AST_FRAME_VOICE, etc) to stop suppressing
 *
 * \retval 0 Success
 * \retval -1 Failure
 */
int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype);

/*!
 * \brief Simulate a DTMF end on a broken bridge channel.
 *
 * \param chan Channel sending DTMF that has not ended.
 * \param digit DTMF digit to stop.
 * \param start DTMF digit start time.
 * \param why Reason bridge broken.
 *
 * \return Nothing
 */
void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why);

struct ast_bridge_features;

/*!
 * \brief Gets the channel-attached features a channel has access to upon being bridged.
 *
 * \note The channel must be locked when calling this function.
 *
 * \param chan Which channel to get features for
 *
 * \retval non-NULL The features currently set for this channel
 * \retval NULL if the features have not been set
 */
struct ast_bridge_features *ast_channel_feature_hooks_get(struct ast_channel *chan);

/*!
 * \brief Appends to the channel-attached features a channel has access to upon being bridged.
 *
 * \note The channel must be locked when calling this function.
 *
 * \param chan Which channel to set features for
 * \param features The feature set to append to the channel's features
 *
 * \retval 0 on success
 * \retval -1 on failure
 */
int ast_channel_feature_hooks_append(struct ast_channel *chan, struct ast_bridge_features *features);

/*!
 * \brief Sets the channel-attached features a channel has access to upon being bridged.
 *
 * \note The channel must be locked when calling this function.
 *
 * \param chan Which channel to set features for
 * \param features The feature set with which to replace the channel's features
 *
 * \retval 0 on success
 * \retval -1 on failure
 */
int ast_channel_feature_hooks_replace(struct ast_channel *chan, struct ast_bridge_features *features);

enum ast_channel_error {
	/* Unable to determine what error occurred. */
	AST_CHANNEL_ERROR_UNKNOWN,
	/* Channel with this ID already exists */
	AST_CHANNEL_ERROR_ID_EXISTS,
};

/*!
 * \brief Get error code for latest channel operation.
 */
enum ast_channel_error ast_channel_errno(void);

/*!
 * \brief Am I currently running an intercept dialplan routine.
 * \since 13.14.0
 *
 * \details
 * A dialplan intercept routine is equivalent to an interrupt
 * routine.  As such, the routine must be done quickly and you
 * do not have access to the media stream.  These restrictions
 * are necessary because the media stream is the responsibility
 * of some other code and interfering with or delaying that
 * processing is bad.
 *
 * \retval 0 Not in an intercept routine.
 * \retval 1 In an intercept routine.
 */
int ast_channel_get_intercept_mode(void);

/*!
 * \brief Retrieve the topology of streams on a channel
 *
 * \param chan The channel to get the stream topology of
 *
 * \pre chan is locked
 *
 * \retval non-NULL success
 * \retval NULL failure
 */
struct ast_stream_topology *ast_channel_get_stream_topology(
	const struct ast_channel *chan);

/*!
 * \brief Set the topology of streams on a channel
 *
 * \param chan The channel to set the stream topology on
 * \param topology The stream topology to set
 *
 * \pre chan is locked
 *
 * \note If topology is NULL a new empty topology will be created
 * and returned.
 *
 * \retval non-NULL Success
 * \retval NULL failure
 */
struct ast_stream_topology *ast_channel_set_stream_topology(
	struct ast_channel *chan, struct ast_stream_topology *topology);

/*!
 * \brief Retrieve the default stream of a specific media type on a channel
 *
 * \param channel The channel to get the stream from
 * \param type The media type of the default stream
 *
 * \pre chan is locked
 *
 * \retval non-NULL success
 * \retval NULL failure
 */
struct ast_stream *ast_channel_get_default_stream(struct ast_channel *chan, enum ast_media_type type);

/*!
 * \brief Determine if a channel is multi-stream capable
 *
 * \param channel The channel to test
 *
 * \pre chan is locked
 *
 * \return Returns true if the channel is multi-stream capable.
 */
int ast_channel_is_multistream(struct ast_channel *chan);

/*!
 * \brief Request that the stream topology of a channel change
 *
 * \param chan The channel to change
 * \param topology The new stream topology
 * \param change_source The source that initiated the change
 *
 * \note Absolutely _NO_ channel locks should be held before calling this function.
 *
 * \retval 0 request has been accepted to be attempted
 * \retval -1 request could not be attempted
 *
 * \note This function initiates an asynchronous request to change the stream topology. It is not
 *       guaranteed that the topology will change and until an AST_CONTROL_STREAM_TOPOLOGY_CHANGED
 *       frame is received from the channel the current handler of the channel must tolerate the
 *       stream topology as it currently exists.
 *
 * \note This interface is provided for applications and resources to request that the topology change.
 *       It is not for use by the channel driver itself.
 */
int ast_channel_request_stream_topology_change(struct ast_channel *chan,
	struct ast_stream_topology *topology, void *change_source);

/*!
 * \brief Provide notice to a channel that the stream topology has changed
 *
 * \param chan The channel to provide notice to
 * \param topology The new stream topology
 *
 * \pre chan is locked  Absolutely _NO_ other channels can be locked.
 *
 * \retval 0 success
 * \retval -1 failure
 *
 * \note This interface is provided for applications and resources to accept a topology change.
 *       It is not for use by the channel driver itself.
 */
int ast_channel_stream_topology_changed(struct ast_channel *chan, struct ast_stream_topology *topology);

/*!
 * \brief Retrieve the source that initiated the last stream topology change
 *
 * \param chan The channel
 *
 * \retval The channel's stream topology change source
 */
void *ast_channel_get_stream_topology_change_source(struct ast_channel *chan);

#endif /* _ASTERISK_CHANNEL_H */