summaryrefslogtreecommitdiff
path: root/doc/ICElib.xml
blob: 5837e897c10b545c74c64b4a00abee5de414d98d (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
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
                   "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
[
<!ENTITY % defs SYSTEM "defs.ent"> %defs;
]>


<book id="ICElib">

<bookinfo>
   <title>Inter-Client Exchange Library</title>
   <subtitle>X Consortium Standard</subtitle>
   <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo>
   <releaseinfo>Version 1.0</releaseinfo>
   <authorgroup>
     <author>
       <firstname>Ralph</firstname><surname>Mor</surname>
       <affiliation><orgname>X Consortium</orgname></affiliation>
     </author>
   </authorgroup>
   <copyright>
     <year>1993</year><year>1994</year><year>1996</year>
     <holder>X Consortium</holder>
   </copyright>

<legalnotice>
<para>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the
"Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to
the following conditions:
</para>

<para>The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
</para>

<para>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</para>

<para>
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
</para>

</legalnotice>
</bookinfo>

<chapter id='Overview_of_ICE'>
<title>Overview of ICE</title>

<para>
There are numerous possible inter-client protocols, with many similarities
and common needs - authentication, version negotiation, byte
order negotiation, and so on.
The Inter-Client Exchange (ICE) protocol is intended to provide a framework
for building such protocols, allowing them to make use of common negotiation
mechanisms and to be multiplexed over a single transport connection.
</para>
</chapter>

<chapter id='The_ICE_Library___C_Language_Interface_to_ICE'>
<title>The ICE Library - C Language Interface to ICE</title>

<para>
A client that wishes to utilize ICE must first register the protocols it
understands with the ICE library.  Each protocol is dynamically assigned
a major opcode ranging from 1-255 (two clients can use different
major opcodes for the same protocol).  The next step for the client is either
to open a connection with another client or to wait for connections made
by other clients.  Authentication may be required.  A client can both
initiate connections with other clients and be
waiting for clients to connect to itself (a nested session manager is an
example).  Once an ICE connection is established between the two clients, one
of the clients needs to initiate a
<function>ProtocolSetup</function>
in order to
"activate" a given protocol.  Once the other client accepts the
<function>ProtocolSetup</function>
(once again, authentication may be required), the
two clients are ready to start passing messages specific to that protocol to
each other.  Multiple protocols may be active on a single ICE connection.
Clients are responsible for notifying the ICE library when a protocol is no
longer active on an ICE connection, although ICE does not define how each
subprotocol triggers a protocol shutdown.
</para>

<para>
The ICE library utilizes callbacks to process incoming messages.  Using
callbacks allows
<function>ProtocolSetup</function>
messages and authentication to happen
behind the scenes.  An additional benefit is that messages never need
to be buffered up by the library when the client blocks waiting for a
particular message.
</para>
</chapter>

<chapter id='Intended_Audience'>
<title>Intended Audience</title>

<para>This document is intended primarily for implementors of protocol libraries
layered on top of ICE.  Typically, applications that wish to utilize ICE
will make calls into individual protocol libraries rather than directly
make calls into the ICE library.  However, some applications will have to
make some initial calls into the ICE library in order to accept ICE
connections (for example, a session manager accepting connections from
clients).  But in general, protocol libraries should be designed to hide
the inner details of ICE from applications.</para>
</chapter>

<chapter id='Header_Files_and_Library_Name'>
<title>Header Files and Library Name</title>


<para>The header file
&lt;<symbol role='Pn'>X11/ICE/ICElib.h</symbol>&gt;
defines all of the ICElib data structures and function prototypes.
<function>ICElib.h</function>
includes the header file
&lt;<symbol role='Pn'>X11/ICE/ICE.h</symbol>&gt;,
which defines all of the ICElib constants.
Protocol libraries that need to read and write messages should include
the header file
&lt;<symbol role='Pn'>X11/ICE/ICEmsg.h</symbol>&gt;.</para>

<para>Applications should link against ICElib using -lICE.</para>
</chapter>

<chapter id='Note_on_Prefixes'>
<title>Note on Prefixes</title>


<para>The following name prefixes are used in the library to distinguish between
a client that initiates a
<function>ProtocolSetup</function>
and a client that
responds with a
<function>ProtocolReply</function></para>

<itemizedlist>
  <listitem>
<para><function>IcePo</function>
- Ice Protocol Originator</para>
  </listitem>
  <listitem>
<para><function>IcePa</function>
- Ice Protocol Acceptor</para>
  </listitem>
</itemizedlist>
</chapter>

<chapter id='Protocol_Registration'>
<title>Protocol Registration</title>

<para>
In order for two clients to exchange messages for a given protocol, each
side must register the protocol with the ICE library.  The purpose of
registration is for each side to obtain a major opcode for the protocol
and to provide callbacks for processing messages and handling authentication.
There are two separate registration functions:
</para>

<itemizedlist>
  <listitem>
    <para>
One to handle the side that does a
<function>ProtocolSetup</function>
    </para>
  </listitem>
  <listitem>
    <para>
One to handle the side that responds with a
<function>ProtocolReply</function>
    </para>
  </listitem>
</itemizedlist>

<para>
It is recommended that protocol registration occur before the two clients
establish an ICE connection.  If protocol registration occurs after an
ICE connection is created, there can be a brief interval of time in which a
<function>ProtocolSetup</function>
is received, but the protocol is not registered.
If it is not possible to register a protocol before the creation of an
ICE connection, proper precautions should be taken to avoid the above race
condition.
</para>


<para>
The <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
function should be called for the client that initiates a
<function>ProtocolSetup</function>
</para>

<funcsynopsis id='IceRegisterForProtocolSetup'>
<funcprototype>
  <funcdef>int <function>IceRegisterForProtocolSetup</function></funcdef>
    <paramdef>const char<parameter> *protocol_name</parameter></paramdef>
    <paramdef>const char<parameter> *vendor</parameter></paramdef>
    <paramdef>const char<parameter> *release</parameter></paramdef>
    <paramdef>int<parameter> version_count</parameter></paramdef>
    <paramdef>IcePoVersionRec<parameter> *version_recs</parameter></paramdef>
    <paramdef>int<parameter> auth_count</parameter></paramdef>
    <paramdef>char<parameter> **auth_names</parameter></paramdef>
    <paramdef>IcePoAuthProc<parameter> *auth_procs</parameter></paramdef>
    <paramdef>IceIOErrorProc<parameter> io_error_proc</parameter></paramdef>
</funcprototype>
</funcsynopsis>


<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>protocol_name</emphasis></term>
    <listitem>
      <para>
A string specifying the name of the protocol to register.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>vendor</emphasis></term>
    <listitem>
      <para>A vendor string with semantics specified by the protocol.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>release</emphasis></term>
    <listitem>
      <para>A release string with semantics specified by the protocol.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>version_count</emphasis></term>
    <listitem>
      <para>The number of different versions of the protocol supported.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>version_recs</emphasis></term>
    <listitem>
      <para>List of versions and associated callbacks.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>auth_count</emphasis></term>
    <listitem>
      <para>The number of authentication methods supported.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>auth_names</emphasis></term>
    <listitem>
      <para>The list of authentication methods supported.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>auth_procs</emphasis></term>
    <listitem>
      <para>
The list of authentication callbacks, one for each authentication method.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>io_error_proc</emphasis></term>
    <listitem>
      <para>IO error handler, or NULL.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
<xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/> returns the major
opcode reserved or -1 if an error occurred.  In order to actually activate
the protocol, the <xref linkend='IceProtocolSetup' xrefstyle='select: title'/>
function needs to be called with this major opcode.  Once the protocol is
activated, all messages for the protocol should be sent using this major
opcode.
</para>

<para>
A protocol library may support multiple versions of the same protocol.
The version_recs argument specifies a list of supported versions of the
protocol, which are prioritized in decreasing order of preference.
Each version record consists of a major and minor version of the protocol
as well as a callback to be used for processing incoming messages.
</para>


<literallayout remap='Ds'>
typedef struct {
	int major_version;
	int minor_version;
	IcePoProcessMsgProc process_msg_proc;
} IcePoVersionRec;
</literallayout>

<para>The
<function>IcePoProcessMsgProc</function>
callback is responsible for processing the set of messages that can be
received by the client that initiated the
<function>ProtocolSetup</function>
For further information,
see
<xref linkend='Callbacks_for_Processing_Messages' xrefstyle='select: title'/>
</para>

<para>Authentication may be required before the protocol can become active.
The protocol library must register the authentication methods that it
supports with the ICE library.
The auth_names and auth_procs arguments are a list of authentication names
and callbacks that are  prioritized in decreasing order of preference.
For information on the
<function>IcePoAuthProc</function>
callback, see
<xref linkend='Authentication_Methods' xrefstyle='select: title'/>
</para>

<para>The
<xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
callback is invoked if the ICE connection unexpectedly breaks.
You should pass NULL for io_error_proc if not interested in being notified.
For further information,
<xref linkend='Error_Handling' xrefstyle='select: title'/>
</para>


<para>The
<xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
function should be called for the client that responds to a
<function>ProtocolSetup</function>
with a
<function>ProtocolReply</function></para>


<funcsynopsis id='IceRegisterForProtocolReply'>
<funcprototype>
  <funcdef>Bool <function>IceRegisterForProtocolReply</function></funcdef>
    <paramdef>const char<parameter> *protocol_name</parameter></paramdef>
    <paramdef>const char<parameter> *vendor</parameter></paramdef>
    <paramdef>const char<parameter> *release</parameter></paramdef>
    <paramdef>int<parameter> version_count</parameter></paramdef>
    <paramdef>IcePoVersionRec<parameter> *version_recs</parameter></paramdef>
    <paramdef>int<parameter> auth_count</parameter></paramdef>
    <paramdef>const char<parameter> **auth_names</parameter></paramdef>
    <paramdef>IcePoAuthProc<parameter> *auth_procs</parameter></paramdef>
    <paramdef>IceHostBasedAuthProc<parameter> host_based_auth_proc</parameter></paramdef>
    <paramdef>IceProtocolSetupProc<parameter> protocol_setup_proc</parameter></paramdef>
    <paramdef>IceProtocolActivateProc<parameter> protocol_activate_proc</parameter></paramdef>
    <paramdef>IceIOErrorProc<parameter> io_error_proc</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>protocol_name</emphasis></term>
    <listitem><para>A string specifying the name of the protocol to register.</para></listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>vendor</emphasis></term>
  <listitem>
<para>A vendor string with semantics specified by the protocol.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>release</emphasis></term>
  <listitem>
<para>A release string with semantics specified by the protocol.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>version_count</emphasis></term>
  <listitem>
<para>The number of different versions of the protocol supported.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>version_recs</emphasis></term>
  <listitem>
<para>List of versions and associated callbacks.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>auth_count</emphasis></term>
  <listitem>
<para>The number of authentication methods supported.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>auth_names</emphasis></term>
  <listitem>
<para>The list of authentication methods supported.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>auth_procs</emphasis></term>
  <listitem>
<para>The list of authentication callbacks, one for each authentication method.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>host_based_auth_proc</emphasis></term>
  <listitem>
<para>Host based authentication callback.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>protocol_setup_proc</emphasis></term>
  <listitem>
<para>A callback to be invoked when authentication has succeeded for a
<function>ProtocolSetup</function>
but before the
<function>ProtocolReply</function>
is sent.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>protocol_activate_proc</emphasis></term>
  <listitem>
<para>A callback to be invoked after the
<function>ProtocolReply</function>
is sent.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>io_error_proc</emphasis></term>
  <listitem>
<para>IO error handler, or NULL.</para>
  </listitem>
  </varlistentry>
</variablelist>


<para><xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
returns the major opcode reserved or -1 if an error occurred.  The major
opcode should be used in all subsequent messages sent for this protocol.</para>

<para>A protocol library may support multiple versions of the same protocol.
The version_recs argument specifies a list of supported versions of the protocol,
which are prioritized in decreasing order of preference.
Each version record consists of a major and minor version of the protocol
as well as a callback to be used for processing incoming messages.</para>


<literallayout remap='Ds'>
typedef struct {
	int major_version;
	int minor_version;
	IcePaProcessMsgProc process_msg_proc;
} IcePaVersionRec;
</literallayout>


<para>The
<xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
callback is responsible for processing the set of messages that can be
received by the client that accepted the
<function>ProtocolSetup</function>
For further information,
see
<xref linkend='Callbacks_for_Processing_Messages' xrefstyle='select: title'/>
</para>

<para>Authentication may be required before the protocol can become active.
The protocol library must register the authentication methods that it
supports with the ICE library.
The auth_names and auth_procs arguments are a list of authentication names
and callbacks that are prioritized in decreasing order of preference.
For information on the
<function>IcePaAuthProc</function>,
See
<xref linkend='Authentication_Methods' xrefstyle='select: title'/>

</para>

<para>If authentication fails and the client attempting to initiate
the
<function>ProtocolSetup</function>
has not required authentication, the
<function>IceHostBasedAuthProc</function>
callback is invoked with the host name of the originating client.
If the callback returns
<function>True</function>
the
<function>ProtocolSetup</function>
will succeed, even though the original
authentication failed.
Note that authentication can effectively be disabled by registering an
<function>IceHostBasedAuthProc</function>
which always returns
<function>True</function>
If no host based
authentication is allowed, you should pass NULL for host_based_auth_proc.</para>

<funcsynopsis>
<funcprototype>
  <funcdef>Bool <function>HostBasedAuthProc</function></funcdef>
    <paramdef>char<parameter> *host_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>protocol_name</emphasis></term>
    <listitem><para>The host name of the client that sent the <function>ProtocolSetup</function></para></listitem>
  </varlistentry>
</variablelist>


<para>The host_name argument is a string of the form <emphasis remap='I'>protocol</emphasis>/<emphasis remap='I'>hostname</emphasis>,
where <emphasis remap='I'>protocol</emphasis> is one of {tcp, decnet, local}.</para>

<para>Because
<function>ProtocolSetup</function>
messages and authentication happen behind the scenes
via callbacks, the protocol library needs some way of being notified when the
<function>ProtocolSetup</function>
has completed.
This occurs in two phases.
In the first phase, the
<function>IceProtocolSetupProc</function>
callback is invoked after authentication has
successfully completed but before the ICE library sends a
<function>ProtocolReply</function>
Any resources required for this protocol should be allocated at this time.
If the
<function>IceProtocolSetupProc</function>
returns a successful status, the ICE library will
send the
<function>ProtocolReply</function>
and then invoke the
<function>IceProtocolActivateProc</function>
callback.  Otherwise, an error will be sent to the
other client in response to the
<function>ProtocolSetup</function></para>

<para>The
<function>IceProtocolActivateProc</function>
is an optional callback and should be registered only if the protocol
library intends to generate a message immediately following the
<function>ProtocolReply</function>
You should pass NULL for protocol_activate_proc if not interested
in this callback.</para>

<funcsynopsis id='ProtocolSetupProc'>
<funcprototype>
  <funcdef>Status <function>ProtocolSetupProc</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> major_version</parameter></paramdef>
    <paramdef>int<parameter> minor_version</parameter></paramdef>
    <paramdef>char<parameter> *vendor</parameter></paramdef>
    <paramdef>char<parameter> *release</parameter></paramdef>
    <paramdef>IcePointer<parameter> *client_data_ret</parameter></paramdef>
    <paramdef>char<parameter> **failure_reason_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>protocol_name</emphasis></term>
    <listitem>
<para>The ICE connection object.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>major_version</emphasis></term>
  <listitem>
<para>The major version of the protocol.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>minor_version</emphasis></term>
  <listitem>
<para>The minor version of the protocol.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>vendor</emphasis></term>
  <listitem>
<para>The vendor string registered by the protocol originator.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>release</emphasis></term>
  <listitem>
<para>The release string registered by the protocol originator.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>client_data_ret</emphasis></term>
  <listitem>
<para>Client data to be set by callback.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>failure_reason_ret</emphasis></term>
  <listitem>
<para>Failure reason returned.</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>The pointer stored in the client_data_ret argument will be passed
to the
<xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
callback whenever a message has arrived for this protocol on the
ICE connection.</para>

<para>The vendor and release strings should be freed with
<function>free</function>
when they are no longer needed.</para>

<para>If a failure occurs, the
<function>IceProtocolSetupProc</function>
should return a zero status as well as allocate and return a failure
reason string in failure_reason_ret.
The ICE library will be responsible for freeing this memory.</para>

<para>The
<function>IceProtocolActivateProc</function>
callback is defined as follows:</para>

<funcsynopsis id='ProtocolActivateProc'>
<funcprototype>
  <funcdef>void <function>ProtocolActivateProc</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem>
    <para>
The client data set in the <function>IceProtocolSetupProc</function> callback.
    </para>
    </listitem>
  </varlistentry>
</variablelist>


<para>The
<xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
callback is invoked if the ICE connection unexpectedly breaks.
You should pass NULL for io_error_proc if not interested in being notified.
For further information,
see
<xref linkend='Error_Handling' xrefstyle='select: title'/>
</para>

<sect1 id='Callbacks_for_Processing_Messages'>
<title>Callbacks for Processing Messages</title>

<para>When an application detects that there is new data to read on an ICE
connection (via
<function>select</function>
it calls the
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
function
<xref linkend='Processing_Messages' xrefstyle='select: title'/>

When
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
reads an ICE message header with a major opcode other than
zero (reserved for the ICE protocol), it needs to call a function that will
read the rest of the message, unpack it, and process it accordingly.</para>

<para>If the message arrives at the client that initiated the
<function>ProtocolSetup</function>
the
<function>IcePoProcessMsgProc</function>
callback is invoked.</para>

<funcsynopsis id='PoProcessMsgProc'>
<funcprototype>
  <funcdef>void <function>PoProcessMsgProc</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
    <paramdef>int<parameter> opcode</parameter></paramdef>
    <paramdef>unsigned long<parameter> length</parameter></paramdef>
    <paramdef>Bool<parameter> swap</parameter></paramdef>
    <paramdef>IceReplyWaitInfo<parameter> *reply_wait</parameter></paramdef>
    <paramdef>Bool<parameter> *reply_ready_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>client_data</emphasis></term>
  <listitem>
<para>Client data associated with this protocol on the ICE connection.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>opcode</emphasis></term>
  <listitem>
<para>The minor opcode of the message.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>length</emphasis></term>
  <listitem>
<para>The length (in 8-byte units) of the message beyond the ICE header.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>swap</emphasis></term>
  <listitem>
<para>A flag that indicates if byte swapping is necessary.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>reply_wait</emphasis></term>
  <listitem>
<para>Indicates if the invoking client is waiting for a reply.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>reply_ready_ret</emphasis></term>
  <listitem>
<para>If set to
<function>True</function>
a reply is ready.</para>
  </listitem>
  </varlistentry>
</variablelist>


<para>If the message arrives at the client that accepted the
<function>ProtocolSetup</function>
the
<xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
callback is invoked.</para>


<funcsynopsis id='IcePaProcessMsgProc'>
<funcprototype>
  <funcdef>void <function>IcePaProcessMsgProc</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
    <paramdef>int<parameter> opcode</parameter></paramdef>
    <paramdef>unsigned long<parameter> length</parameter></paramdef>
    <paramdef>Bool<parameter> swap</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>client_data</emphasis></term>
  <listitem>
<para>Client data associated with this protocol on the ICE connection.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>opcode</emphasis></term>
  <listitem>
<para>The minor opcode of the message.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>length</emphasis></term>
  <listitem>
<para>The length (in 8-byte units) of the message beyond the ICE header.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>swap</emphasis></term>
  <listitem>
<para>A flag that indicates if byte swapping is necessary.</para>
  </listitem>
  </varlistentry>
</variablelist>


<para>In order to read the message, both of these callbacks should use the
macros defined for this purpose (see
<xref linkend='Reading_ICE_Messages' xrefstyle='select: title'/>.).
Note that byte swapping may be necessary.
As a convenience, the length field in the ICE header will be swapped by ICElib
if necessary.</para>

<para>In both of these callbacks, the client_data argument is a pointer to client
data that was registered at
<function>ProtocolSetup</function>
time.
In the case of
<function>IcePoProcessMsgProc</function>
the client data was set in the call to
<xref linkend='IceProtocolSetup' xrefstyle='select: title'/>
In the case of
<xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
the client data was set in the
<function>IceProtocolSetupProc</function>
callback.</para>

<para>The
<function>IcePoProcessMsgProc</function>
callback needs to check the reply_wait argument.
If reply_wait is NULL ,
the ICE library expects the function to
pass the message to the client via a callback.
For example, if this is a Session Management "Save Yourself" message,
this function should notify the client of the "Save Yourself" via a callback.
The details of how such a callback would be defined
are implementation-dependent.</para>

<para>However, if reply_wait is not NULL ,
then the client is waiting for
a reply or an error for a message it previously sent.
The reply_wait is of type
<function>IceReplyWaitInfo</function></para>


<literallayout remap='Ds'>
typedef struct {
	unsigned long sequence_of_request;
	int major_opcode_of_request;
	int minor_opcode_of_request;
	IcePointer reply;
} IceReplyWaitInfo;
</literallayout>

<para><function>IceReplyWaitInfo</function>
contains the major/minor opcodes and sequence number of
the message for which a reply is being awaited.
It also contains a pointer to the reply message to be filled in
(the protocol library should cast this
<function>IcePointer</function>
to the appropriate reply type).
In most cases, the reply will have some fixed-size part, and the client waiting
for the reply will have provided a pointer to a structure to hold
this fixed-size data.  If there is variable-length data, it would be
expected that the
<function>IcePoProcessMsgProc</function>
callback will have to allocate additional
memory and store pointer(s) to that memory in the fixed-size
structure.  If the entire data is variable length (for example., a single
variable-length string), then the client waiting for the reply would probably
just pass a pointer to fixed-size space to hold a pointer, and the
<function>IcePoProcessMsgProc</function>
callback would allocate the storage and store the pointer.
It is the responsibility of the client receiving the reply to
free any memory allocated on its behalf.</para>

<para>If reply_wait is not NULL and
<function>IcePoProcessMsgProc</function>
has a reply or error to return in response to this reply_wait
(that is, no callback was generated), then the reply_ready_ret argument
should be set to
<function>True</function>
Note that an error should only be returned
if it corresponds to the reply being waited for.  Otherwise, the
<function>IcePoProcessMsgProc</function>
should either handle the error internally or invoke an error handler
for its library.</para>

<para>If reply_wait is NULL,
then care must be taken not to store any value in reply_ready_ret,
because this pointer may also be NULL.</para>

<para>The
<xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
callback, on the other hand, should always pass
the message to the client via a callback.  For example, if this is a Session
Management "Interact Request" message, this function should notify the
client of the "Interact Request" via a callback.</para>

<para>The reason the
<xref linkend='IcePaProcessMsgProc' xrefstyle='select: title'/>
callback does not have a reply_wait, like
<function>IcePoProcessMsgProc</function>
does, is because a process that is acting as
a server should never block for a reply (infinite blocking can
occur if the connecting client does not act properly, denying access
to other clients).</para>
</sect1>

<sect1 id='Authentication_Methods'>
<title>Authentication Methods</title>

<para>As already stated, a protocol library must register the authentication
methods that it supports with the ICE library.  For each authentication
method, there are two callbacks that may be registered:</para>
<itemizedlist>
  <listitem>
    <para>
One to handle the side that initiates a <function>ProtocolSetup</function>
    </para>
  </listitem>
  <listitem>
    <para>
One to handle the side that accepts or rejects this request
    </para>
  </listitem>
</itemizedlist>

<para><function>IcePoAuthProc</function>
is the callback invoked for the client that initiated the
<function>ProtocolSetup</function>
This callback must be able to respond
to the initial "Authentication Required" message or subsequent
"Authentication Next Phase" messages sent by the other client.</para>


<funcsynopsis id='IcePoAuthStatus'>
<funcprototype>
  <funcdef>IcePoAuthStatus <function>IcePoAuthStatus </function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
    <paramdef>int<parameter> opcode</parameter></paramdef>
</funcprototype>
</funcsynopsis>


<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>auth_state_ptr</emphasis></term>
  <listitem>
<para>A pointer to state for use by the authentication callback procedure.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>clean_up</emphasis></term>
  <listitem>
<para>If
<function>True</function>
authentication is over, and the function
should clean up any state it was maintaining.  The
last 6 arguments should be ignored.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>swap</emphasis></term>
  <listitem>
<para>If
<function>True</function>
the auth_data may have to be byte swapped
(depending on its contents).</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>auth_datalen</emphasis></term>
  <listitem>
<para>The length (in bytes) of the authenticator data.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>auth_data</emphasis></term>
  <listitem>
<para>The data from the authenticator.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>reply_datalen_ret</emphasis></term>
  <listitem>
<para>The length (in bytes) of the reply data returned.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>reply_data_ret</emphasis></term>
  <listitem>
<para>The reply data returned.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>error_string_ret</emphasis></term>
  <listitem>
<para>If the authentication procedure encounters an error during
authentication, it should allocate and return
an error string.</para>
  </listitem>
  </varlistentry>
</variablelist>


<para>Authentication may require several phases, depending on the authentication
method.  As a result, the
<function>IcePoAuthProc</function>
may be called more than once when authenticating a client, and
some state will have to be maintained between each invocation.
At the start of each
<function>ProtocolSetup</function>
*auth_state_ptr is NULL,
and the function should initialize its state and set
this pointer.  In subsequent invocations of the callback, the pointer
should be used to get at any state previously stored by the callback.</para>

<para>If needed, the network ID of the client accepting the
<function>ProtocolSetup</function>
can be obtained by calling the
<function>IceConnectionString</function>
function.</para>

<para>ICElib will be responsible for freeing the reply_data_ret and
error_string_ret pointers with
<function>free</function></para>

<para>The auth_data pointer may point to a volatile block of memory.
If the data must be kept beyond this invocation of the callback, be sure
to make a copy of it.</para>

<para>The
<function>IcePoAuthProc</function>
should return one of four values:</para>
<itemizedlist>
  <listitem>
<para><function>IcePoAuthHaveReply</function>
- a reply is available.</para>
  </listitem>
  <listitem>
<para><function>IcePoAuthRejected</function>
- authentication rejected.</para>
  </listitem>
  <listitem>
<para><function>IcePoAuthFailed</function>
- authentication failed.</para>
  </listitem>
  <listitem>
<para><function>IcePoAuthDoneCleanup</function>
- done cleaning up.</para>
  </listitem>
</itemizedlist>

<para><function>IcePaAuthProc</function>
is the callback invoked for the client that received the
<function>ProtocolSetup</function></para>

<funcsynopsis id='PoAuthStatus'>
<funcprototype>
  <funcdef>IcePoAuthStatus <function>PoAuthStatus </function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePointer<parameter> *auth_state_ptr</parameter></paramdef>
    <paramdef>Bool<parameter> swap</parameter></paramdef>
    <paramdef>int<parameter> auth_datalen</parameter></paramdef>
    <paramdef>IcePointer<parameter> auth_data</parameter></paramdef>
    <paramdef>int<parameter> *reply_datalen_ret</parameter></paramdef>
    <paramdef>IcePointer<parameter> *reply_data_ret</parameter></paramdef>
    <paramdef>char<parameter> **error_string_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>auth_state_ptr</emphasis></term>
    <listitem>
<para>A pointer to state for use by the authentication callback procedure.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>swap</emphasis></term>
    <listitem>
<para>If
<function>True</function>
auth_data may have to be byte swapped
(depending on its contents).</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>auth_datalen</emphasis></term>
    <listitem>
<para>The length (in bytes) of the protocol originator authentication data.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>auth_data</emphasis></term>
    <listitem>
<para>The authentication data from the protocol originator.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>reply_datalen_ret</emphasis></term>
    <listitem>
<para>The length of the authentication data returned.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>reply_data_ret</emphasis></term>
    <listitem>
<para>The authentication data returned.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_string_ret</emphasis></term>
    <listitem>
<para>If authentication is rejected or fails, an error
string is returned.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>Authentication may require several phases, depending on the authentication
method.  As a result, the
<function>IcePaAuthProc</function>
may be called more than once when authenticating a client, and
some state will have to be maintained between each invocation.
At the start of each
<function>ProtocolSetup</function>
auth_datalen is zero,
*auth_state_ptr is NULL,
and the function should initialize its state and set
this pointer.  In subsequent invocations of the callback, the pointer
should be used to get at any state previously stored by the callback.</para>

<para>If needed, the network ID of the client accepting the
<function>ProtocolSetup</function>
can be obtained by calling the
<function>IceConnectionString</function>
function.</para>

<para>The auth_data pointer may point to a volatile block of memory.
If the data must be kept beyond this invocation of the callback, be sure
to make a copy of it.</para>

<para>ICElib will be responsible for transmitting and freeing the reply_data_ret and
error_string_ret pointers with
<function>free</function></para>

<para>
The <function>IcePaAuthProc</function> should return one of four values:
</para>


<itemizedlist>
  <listitem>
    <para>
<function>IcePaAuthContinue</function> - continue (or start) authentication.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IcePaAuthAccepted</function> - authentication accepted.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IcePaAuthRejected</function> - authentication rejected.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IcePaAuthFailed</function> - authentication failed.
    </para>
  </listitem>
</itemizedlist>
</sect1>

</chapter>

<chapter id='ICE_Connections'>
<title>ICE Connections</title>

<para>
In order for two clients to establish an ICE connection, one client has to be
waiting for connections, and the other client has to initiate the connection.
Most clients will initiate connections, so we discuss that first.
</para>

<sect1 id='Opening_an_ICE_Connection'>
<title>Opening an ICE Connection</title>


<para>
To open an ICE connection with another client (that is, waiting
for connections), use <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceOpenConnection'>
<funcprototype>
  <funcdef>IceConn <function>IceOpenConnection</function></funcdef>
    <paramdef>char<parameter> *network_ids_list</parameter></paramdef>
    <paramdef>IcePointer<parameter> context</parameter></paramdef>
    <paramdef>Bool<parameter> must_authenticate</parameter></paramdef>
    <paramdef>int<parameter> major_opcode_check</parameter></paramdef>
    <paramdef>int<parameter> error_length</parameter></paramdef>
    <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>network_ids_list</emphasis></term>
    <listitem>
      <para>
Specifies the network ID(s) of the other client.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>context</emphasis></term>
    <listitem>
      <para>
A pointer to an opaque object or NULL.  Used to determine if an
ICE connection can be shared (see below).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>must_authenticate</emphasis></term>
    <listitem>
      <para>
If <function>True</function> the other client may not bypass authentication.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>major_opcode_check</emphasis></term>
    <listitem>
      <para>
Used to force a new ICE connection to be created (see below).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_length</emphasis></term>
    <listitem>
      <para>Length of the error_string_ret argument passed in.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_string_ret</emphasis></term>
    <listitem>
      <para>
Returns a null-terminated error message, if any.  The error_string_ret
argument points to user supplied memory.  No more than error_length bytes
are used.
      </para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
returns an opaque ICE connection object if it succeeds;
otherwise, it returns NULL.
</para>

<para>
The network_ids_list argument contains a list of network IDs separated
by commas.  An attempt will be made to use the first network ID.  If
that fails, an attempt will be made using the second network ID, and so on.
Each network ID has the following format:
</para>

<informaltable frame='none'>
  <?dbfo keep-together="always" ?>
  <tgroup cols='2' align='left' colsep='0' rowsep='0'>
    <colspec colname='c1' colwidth='1.0*'/>
    <colspec colname='c2' colwidth='2.0*'/>
    <tbody>
      <row>
        <entry>tcp/&lt;hostname&gt;:&lt;portnumber&gt;</entry>
        <entry>or</entry>
      </row>
      <row>
        <entry>decnet/&lt;hostname&gt;::&lt;objname&gt;</entry>
        <entry>or</entry>
      </row>
      <row>
        <entry>local/&lt;hostname&gt;:&lt;path&gt;</entry>
        <entry></entry>
      </row>
    </tbody>
  </tgroup>
</informaltable>


<para>Most protocol libraries will have some sort of open function that should
internally make a call into
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
When
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
is called, it may be possible to use a previously opened ICE connection (if
the target client is the same).  However, there are cases in which shared
ICE connections are not desired.</para>

<para>The context argument is used to determine if an ICE connection can
be shared.
If context is NULL,
then the caller is always willing to share the connection.
If context is not NULL,
then the caller is not willing to use a previously opened ICE connection
that has a different non-NULL context associated with it.</para>

<para>In addition, if major_opcode_check contains a nonzero major opcode value,
a previously created ICE connection will be used only if the major opcode
is not active on the connection.  This can be used to force multiple ICE
connections between two clients for the same protocol.</para>

<para>Any authentication requirements are handled internally by the ICE library.
The method by which the authentication data is obtained
is implementation-dependent.
  <footnote remap='FS'>
<para>The X Consortium's ICElib implementation uses an .ICEauthority file (see
Appendix A).
  </para></footnote> </para>

<para>After
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
is called, the client is ready to send a
<function>ProtocolSetup</function>
(provided that
<xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
was called) or receive a
<function>ProtocolSetup</function>
(provided that
<xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
was called).</para>
</sect1>

<sect1 id='Listening_for_ICE_Connections'>
<title>Listening for ICE Connections</title>

<para>Clients wishing to accept ICE connections must first call
<xref linkend='IceListenForConnections' xrefstyle='select: title'/>
or
<xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
so that they can listen for connections.  A list of opaque "listen" objects are
returned, one for each type of transport method that is available
(for example, Unix Domain, TCP, DECnet, and so on).</para>

<para>Normally clients will let ICElib allocate an available name in each
transport and return listen objects.  Such a client will then use
<xref linkend='IceComposeNetworkIdList' xrefstyle='select: title'/>
to extract the chosen names and make them
available to other clients for opening the connection.  In certain
cases it may be necessary for a client to listen for connections
on pre-arranged transport object names.  Such a client may use
<xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
to specify the names for the listen objects.</para>

<funcsynopsis id='IceListenForConnections'>
<funcprototype>
  <funcdef>Status <function>IceListenForConnections</function></funcdef>
    <paramdef>int<parameter> *count_ret</parameter></paramdef>
    <paramdef>IceListenObj<parameter> **listen_objs_ret</parameter></paramdef>
    <paramdef>int<parameter> error_length</parameter></paramdef>
    <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>count_ret</emphasis></term>
    <listitem><para>Returns the number of listen objects created.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>listen_objs_ret</emphasis></term>
    <listitem><para>Returns a list of pointers to opaque listen objects.</para></listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>error_length</emphasis></term>
  <listitem>
<para>The length of the error_string_ret argument passed in.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>error_string_ret</emphasis></term>
  <listitem>
<para>Returns a null-terminated error message, if any.
The error_string_ret points to user supplied memory.
No more than error_length bytes are used.</para>
  </listitem>
  </varlistentry>
</variablelist>


<para>The return value of
<xref linkend='IceListenForConnections' xrefstyle='select: title'/>
is zero for failure and a positive value for success.</para>

<funcsynopsis id='IceListenForWellKnownConnections'>
<funcprototype>
  <funcdef>Status <function>IceListenForWellKnownConnections</function></funcdef>
    <paramdef>char<parameter> *port_id</parameter></paramdef>
    <paramdef>int<parameter> *count_ret</parameter></paramdef>
    <paramdef>IceListenObj<parameter> **listen_objs_ret</parameter></paramdef>
    <paramdef>int<parameter> error_length</parameter></paramdef>
    <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>port_id</emphasis></term>
    <listitem>
      <para>
Specifies the port identification for the address(es) to be opened.  The
value must not contain the slash ("/"> or comma (".") character; thse are
reserved for future use.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>count_ret</emphasis></term>
    <listitem>
      <para>Returns the number of listen objects created.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>listen_objs_ret</emphasis></term>
    <listitem>
      <para>
Returns a list of pointers to opaque listen objects.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>listen_objs_ret</emphasis></term>
    <listitem>
      <para>
Returns a list of pointers to opaque listen objects.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_length</emphasis></term>
    <listitem>
      <para>
The length of the error_string_ret argument passed in.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_string_ret</emphasis></term>
    <listitem>
      <para>
Returns a null-terminated error message, if any.  The error_string_ret
points to user supplied memory.  No more than error_length bytes are used.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/> constructs a list
of network IDs by prepending each known transport to port_id and then
attempts to create listen objects for the result.  Port_id is the portnumber,
objname, or path portion of the ICE network ID. If a listen object for
a particular network ID cannot be created the network ID is ignored.
If no listen objects are created
<xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
returns failure.
</para>

<para>
The return value of <xref linkend='IceListenForWellKnownConnections' xrefstyle='select: title'/>
is zero for failure and a positive value for success.
</para>

<para>
To close and free the listen objects, use
<xref linkend='IceFreeListenObjs' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceFreeListenObjs'>
<funcprototype>
  <funcdef>void <function>IceFreeListenObjs</function></funcdef>
    <paramdef>int<parameter> count</parameter></paramdef>
    <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>count</emphasis></term>
    <listitem>
      <para>The number of listen objects.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>listen_objs</emphasis></term>
    <listitem>
      <para>The listen objects.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
To detect a new connection on a listen object, use
<function>select</function> on the descriptor associated with
the listen object.
</para>

<para>
To obtain the descriptor, use
<xref linkend='IceGetListenConnectionNumber' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceGetListenConnectionNumber'>
<funcprototype>
  <funcdef>int <function>IceGetListenConnectionNumber</function></funcdef>
    <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>listen_obj</emphasis></term>
    <listitem>
      <para>The listen objects.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
To obtain the network ID string associated with a listen object, use
<xref linkend='IceGetListenConnectionString' xrefstyle='select: title'/>
</para>


<funcsynopsis id='IceGetListenConnectionString'>
<funcprototype>
  <funcdef>char <function>IceGetListenConnectionString</function></funcdef>
    <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>listen_obj</emphasis></term>
    <listitem>
      <para>The listen objects.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>A network ID has the following format:</para>

<informaltable frame='none'>
  <?dbfo keep-together="always" ?>
  <tgroup cols='2' align='left' colsep='0' rowsep='0'>
    <colspec colname='c1' colwidth='1.0*'/>
    <colspec colname='c2' colwidth='2.0*'/>
    <tbody>
      <row>
        <entry>tcp/&lt;hostname&gt;:&lt;portnumber&gt;</entry>
        <entry>or</entry>
      </row>
      <row>
        <entry>decnet/&lt;hostname&gt;::&lt;objname&gt;</entry>
        <entry>or</entry>
      </row>
      <row>
        <entry>local/&lt;hostname&gt;:&lt;path&gt;</entry>
        <entry></entry>
      </row>
    </tbody>
  </tgroup>
</informaltable>

<para>
To compose a string containing a list of network IDs separated by commas
(the format recognized by <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
use <xref linkend='IceComposeNetworkIdList' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceComposeNetworkIdList'>
<funcprototype>
  <funcdef>char <function>IceComposeNetworkIdList</function></funcdef>
    <paramdef>int<parameter> count</parameter></paramdef>
    <paramdef>IceListenObj<parameter> *listen_objs</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>count</emphasis></term>
    <listitem>
      <para>The number of listen objects.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>listen_objs</emphasis></term>
    <listitem>
      <para>The listen objects.</para>
    </listitem>
  </varlistentry>
</variablelist>

</sect1>

<sect1 id='Host_Based_Authentication_for_ICE_Connections'>
<title>Host Based Authentication for ICE Connections</title>

<para>
If authentication fails when a client attempts to open an
ICE connection and the initiating client has not required authentication,
a host based authentication procedure may be invoked to provide
a last chance for the client to connect.  Each listen object has such a
callback associated with it, and this callback is set using the
<xref linkend='IceSetHostBasedAuthProc' xrefstyle='select: title'/>
function.
</para>

<funcsynopsis id='IceSetHostBasedAuthProc'>
<funcprototype>
  <funcdef>void <function>IceSetHostBasedAuthProc</function></funcdef>
    <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef>
    <paramdef>IceHostBasedAuthProc<parameter> host_based_auth_proc</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>IceListenObj</emphasis></term>
    <listitem>
      <para>The listen object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>host_based_auth_proc</emphasis></term>
    <listitem>
      <para>The host based authentication procedure.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
By default, each listen object has no host based authentication procedure
associated with it.  Passing NULL for host_based_auth_proc turns off
host based authentication if it was previously set.
</para>


<funcsynopsis id='HostBasedAuthProc'>
<funcprototype>
  <funcdef>Bool <function>HostBasedAuthProc</function></funcdef>
    <paramdef>char<parameter> *host_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>host_name</emphasis></term>
    <listitem>
      <para>
The host name of the client that tried to open an ICE connection.
      </para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
The host_name argument is a string in the form
<emphasis remap='I'>protocol</emphasis>/
<emphasis remap='I'>hostname</emphasis>,
where <emphasis remap='I'>protocol</emphasis> is one of
{tcp, decnet, local}.
</para>

<para>
If <function>IceHostBasedAuthProc</function> returns
<function>True</function>
access will be granted, even though the original authentication failed.
Note that authentication can effectively be disabled by registering an
<function>IceHostBasedAuthProc</function>
which always returns <function>True</function>
</para>

<para>
Host based authentication is also allowed at
<function>ProtocolSetup</function> time.
The callback is specified in the
<xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
function (see
<xref linkend='Protocol_Registration' xrefstyle='select: title'/>).
</para>
</sect1>

<sect1 id='Accepting_ICE_Connections'>
<title>Accepting ICE Connections</title>


<para>
After a connection attempt is detected on a listen object returned by
<xref linkend='IceListenForConnections' xrefstyle='select: title'/>
you should call <xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
This returns a new opaque ICE connection object.
</para>

<funcsynopsis id='IceAcceptConnection'>
<funcprototype>
  <funcdef>IceConn <function>IceAcceptConnection</function></funcdef>
    <paramdef>IceListenObj<parameter> listen_obj</parameter></paramdef>
    <paramdef>IceAcceptStatus<parameter> *status_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>


<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>listen_obj</emphasis></term>
  <listitem>
<para>The listen object on which a new connection was detected.</para>
  </listitem>
  </varlistentry>
  </variablelist>
  <variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>status_ret</emphasis></term>
  <listitem>
<para>Return status information.</para>
  </listitem>
  </varlistentry>
</variablelist>


<para>The status_ret argument is set to one of the following values:</para>
<itemizedlist>
  <listitem>
<para><function>IceAcceptSuccess</function>
- the accept operation succeeded,
and the function returns a new connection object.</para>
  </listitem>
  <listitem>
<para><function>IceAcceptFailure</function>
- the accept operation failed, and the function returns NULL.</para>
  </listitem>
  <listitem>
<para><function>IceAcceptBadMalloc</function>
- a memory allocation failed, and the function returns NULL.</para>
  </listitem>
</itemizedlist>

<para>In general, to detect new connections, you should call
<function>select</function>
on the file descriptors associated with the listen objects.
When a new connection is detected, the
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
function should be called.
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
may return a new ICE connection that is in a pending state.  This is because
before the connection can become valid, authentication may be necessary.
Because the ICE library cannot block and wait for the connection to
become valid (infinite blocking can occur if the connecting client
does not act properly), the application must wait for the connection status
to become valid.</para>

<para>The following pseudo-code demonstrates how connections are accepted:</para>

<literallayout class="monospaced">
new_ice_conn = IceAcceptConnection (listen_obj, &amp;accept_status);
if (accept_status != IceAcceptSuccess)
{
     close the file descriptor and return
}

status = IceConnectionStatus (new_ice_conn);
time_start = time_now;

while (status == IceConnectPending)
{
     select() on {new_ice_conn, all open connections}

     for (each ice_conn in the list of open connections)
          if (data ready on ice_conn)
          {
               status = IceProcessMessages (ice_conn, NULL, NULL);
               if (status == IceProcessMessagesIOError)
                    IceCloseConnection(ice_conn);
          }
     if data ready on new_ice_conn
     {
          /*
          * IceProcessMessages is called until the connection
          * is non-pending.  Doing so handles the connection
          * setup request and any authentication requirements.
          */

          IceProcessMessages ( new_ice_conn, NULL, NULL);
          status = IceConnectionStatus (new_ice_conn);
     }
     else
     {
          if (time_now - time_start &gt; MAX_WAIT_TIME)
               status = IceConnectRejected;
     }
}

if (status == IceConnectAccepted)
{
     Add new_ice_conn to the list of open connections
}
else
{
     IceCloseConnection
     new_ice_conn
}
</literallayout>

<para>After
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
is called and the connection has been
validated, the client is ready to receive a
<function>ProtocolSetup</function>
(provided
that
<xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
was called) or send a
<function>ProtocolSetup</function>
(provided that
<xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
was called).</para>
</sect1>

<sect1 id='Closing_ICE_Connections'>
<title>Closing ICE Connections</title>

<para>To close an ICE connection created with
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
or
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
use
<xref linkend='IceCloseConnection' xrefstyle='select: title'/></para>

<funcsynopsis id='IceCloseConnection'>
<funcprototype>
  <funcdef>IceCloseStatus <function>IceCloseConnection</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>ice_conn</emphasis></term>
  <listitem>
  <para>The ICE connection to close.</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>To actually close an ICE connection, the following conditions
must be met:</para>

<itemizedlist>
  <listitem>
<para>The <emphasis remap='I'>open reference count</emphasis> must have reached zero on this ICE connection.
When
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
is called, it tries to use a previously opened
ICE connection.  If it is able to use an existing connection, it increments
the open reference count on the connection by one.
So, to close an ICE connection, each call to
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
must be matched with a call to
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
The connection can be closed only
on the last call to
<xref linkend='IceCloseConnection' xrefstyle='select: title'/></para>
  </listitem>
  <listitem>
<para>The <emphasis remap='I'>active protocol count</emphasis> must have reached zero.  Each time a
<function>ProtocolSetup</function>
succeeds on the connection, the active protocol count
is incremented by one.  When the client no longer expects to use the
protocol on the connection, the
<xref linkend='IceProtocolShutdown' xrefstyle='select: title'/>
function should be called, which decrements the active protocol count
by one (see
<xref linkend='Protocol_Setup_and_Shutdown' xrefstyle='select: title'/>).
</para>
  </listitem>
  <listitem>
<para>If shutdown negotiation is enabled on the connection, the client on the other
side of the ICE connection must agree to have the connection closed.</para>

<para><xref linkend='IceCloseConnection' xrefstyle='select: title'/>
returns one of the following values:</para>
  </listitem>
  <listitem>
<para><function>IceClosedNow</function>
- the ICE connection was closed at this time.  The watch procedures were
invoked and the connection was freed.</para>
  </listitem>
  <listitem>
<para><function>IceClosedASAP</function>
- an IO error had occurred on the connection, but
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
is being called within a nested
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
The watch procedures have been invoked at this time, but the connection
will be freed as soon as possible (when the nesting level reaches zero and
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
returns a status of
<function>IceProcessMessagesConnectionClosed</function></para>
  </listitem>
  <listitem>
<para><function>IceConnectionInUse</function>
- the connection was not closed at this time, because it is being used by
other active protocols.</para>
  </listitem>
  <listitem>
<para><function>IceStartedShutdownNegotiation</function>
- the connection was not closed at this time and shutdown negotiation started
with the client on the other side of the ICE connection.  When the connection
is actually closed,
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
will return a status of
<function>IceProcessMessagesConnectionClosed</function></para>
  </listitem>
</itemizedlist>

<para>When it is known that the client on the other side of the ICE connection
has terminated the connection without initiating shutdown negotiation, the
<xref linkend='IceSetShutdownNegotiation' xrefstyle='select: title'/>
function should be called to turn off shutdown negotiation.  This will prevent
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
from writing to a broken connection.</para>

<funcsynopsis id='IceSetShutdownNegotiation'>
<funcprototype>
  <funcdef>void <function>IceSetShutdownNegotiation</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>Bool<parameter> negotiate</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>ice_conn</emphasis></term>
  <listitem>
  <para>A valid ICE connection object.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>negotiate</emphasis></term>
  <listitem>
<para>If
<function>False</function>
shutdown negotiating will be turned off.</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>To check the shutdown negotiation status of an ICE connection, use
<xref linkend='IceCheckShutdownNegotiation' xrefstyle='select: title'/></para>

<funcsynopsis id='IceCheckShutdownNegotiation'>
<funcprototype>
  <funcdef>Bool <function>IceCheckShutdownNegotiation</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>ice_conn</emphasis></term>
  <listitem>
  <para>A valid ICE connection object.</para>
  </listitem>
  </varlistentry>
</variablelist>


<para><xref linkend='IceCheckShutdownNegotiation' xrefstyle='select: title'/>
returns
<function>True</function>
if shutdown negotiation will take place on the connection;
otherwise, it returns
<function>False</function>
Negotiation is on by default for a connection.  It
can only be changed with the
<xref linkend='IceSetShutdownNegotiation' xrefstyle='select: title'/>
function.</para>
</sect1>

<sect1 id='Connection_Watch_Procedures'>
<title>Connection Watch Procedures</title>

<para>To add a watch procedure that will be called
each time ICElib opens a new connection via
<xref linkend='IceOpenConnection' xrefstyle='select: title'/>
or
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/>
or closes a connection via
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
use
<xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/></para>

<funcsynopsis id='IceAddConnectionWatch'>
<funcprototype>
  <funcdef>Status <function>IceAddConnectionWatch</function></funcdef>
    <paramdef>IceWatchProc<parameter> watch_proc</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>watch_proc</emphasis></term>
    <listitem>
      <para>
The watch procedure to invoke when ICElib opens or closes a connection.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem>
      <para>This pointer will be passed to the watch procedure.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
The return value of <xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
is zero for failure, and a positive value for success.
</para>

<para>
Note that several calls to <xref linkend='IceOpenConnection' xrefstyle='select: title'/>
might share the same ICE connection.  In such a case, the watch procedure
is only invoked when the connection is first created (after authentication
succeeds).  Similarly, because connections might be shared, the
watch procedure is called only if <xref linkend='IceCloseConnection' xrefstyle='select: title'/>
actually closes the connection (right before the IceConn is freed).
</para>

<para>
The watch procedures are very useful for applications that
need to add a file descriptor to a select mask when a new connection
is created and remove the file descriptor when the connection is destroyed.
Because connections are shared, knowing when to add and remove the file
descriptor from the select mask would be difficult without the watch
procedures.
</para>

<para>
Multiple watch procedures may be registered with the ICE library.
No assumptions should be made about their order of invocation.
</para>

<para>
If one or more ICE connections were already created by the ICE library at the
time the watch procedure is registered, the watch procedure will instantly
be invoked for each of these ICE connections (with the opening argument
set to <function>True</function>
</para>

<para>
The watch procedure is of type <function>IceWatchProc</function>
</para>

<funcsynopsis id='WatchProc'>
<funcprototype>
  <funcdef>void <function>WatchProc</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
    <paramdef>Bool<parameter> opening</parameter></paramdef>
    <paramdef>IcePointer<parameter> *watch_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>
The opened or closed ICE connection.  Call
<function>IceConnectionNumber</function>
to get the file descriptor associated with this connection.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem>
      <para>
Client data specified in the call to
<xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>opening</emphasis></term>
    <listitem>
      <para>
If <function>True</function> the connection is being opened.  If
<function>False</function> the connection is being closed.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>watch_data</emphasis></term>
    <listitem>
      <para>Can be used to save a pointer to client data.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
If opening is <function>True</function> the client should set the
*watch_data pointer to any data it may need to save until the connection
is closed and the watch procedure is invoked again with opening set to
<function>False</function>
</para>

<para>
To remove a watch procedure, use
<xref linkend='IceRemoveConnectionWatch' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceRemoveConnectionWatch'>
<funcprototype>
  <funcdef>void <function>IceRemoveConnectionWatch</function></funcdef>
    <paramdef>IceWatchProc<parameter> watch_proc</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>watch_proc</emphasis></term>
    <listitem>
      <para>
The watch procedure that was passed to
<xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem>
      <para>
The client_data pointer that was passed to
<xref linkend='IceAddConnectionWatch' xrefstyle='select: title'/>
      </para>
    </listitem>
  </varlistentry>
</variablelist>

</sect1>
</chapter>

<chapter id='Protocol_Setup_and_Shutdown'>
<title>Protocol Setup and Shutdown</title>

<para>
To activate a protocol on a given ICE connection, use
<xref linkend='IceProtocolSetup' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceProtocolSetup'>
<funcprototype>
  <funcdef>IceProtocolSetupStatus <function>IceProtocolSetup</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> my_opcode</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
    <paramdef>Bool<parameter> must_authenticate</parameter></paramdef>
    <paramdef>int<parameter> *major_version_ret</parameter></paramdef>
    <paramdef>int<parameter> *minor_version_ret</parameter></paramdef>
    <paramdef>char<parameter> **vendor_ret</parameter></paramdef>
    <paramdef>char<parameter> **release_ret</parameter></paramdef>
    <paramdef>int<parameter> error_length</parameter></paramdef>
    <paramdef>char<parameter> *error_string_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>my_opcode</emphasis></term>
    <listitem>
      <para>
The major opcode of the protocol to be set up, as returned by
<xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/>
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem>
      <para>
The client data stored in this pointer will be passed to the
<function>IcePoProcessMsgProc</function> callback.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>must_authenticate</emphasis></term>
    <listitem>
      <para>
If <function>True</function> the other client may
not bypass authentication.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>major_version_ret</emphasis></term>
    <listitem>
      <para>The major version of the protocol to be used is returned.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>minor_version_ret</emphasis></term>
    <listitem>
      <para>The minor version of the protocol to be used is returned.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>vendor_ret</emphasis></term>
    <listitem>
      <para>The vendor string specified by the protocol acceptor.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>release_ret</emphasis></term>
    <listitem>
      <para>The release string specified by the protocol acceptor.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_length</emphasis></term>
    <listitem>
      <para>
Specifies the length of the error_string_ret argument passed in.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_string_ret</emphasis></term>
    <listitem>
      <para>
Returns a null-terminated error message, if any.
The error_string_ret argument points to user supplied memory.
No more than error_length bytes are used.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
The vendor_ret and release_ret strings should be freed with
<function>free</function> when no longer needed.
</para>

<para>
<xref linkend='IceProtocolSetup' xrefstyle='select: title'/> returns one of the following values:
</para>

<itemizedlist>
  <listitem>
    <para>
<function>IceProtocolSetupSuccess</function> - the major_version_ret,
minor_version_ret, vendor_ret, release_ret are set.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IceProtocolSetupFailure</function> or
<function>IceProtocolSetupIOError</function>
- check error_string_ret for failure reason.  The major_version_ret,
minor_version_ret, vendor_ret, release_ret are not set.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IceProtocolAlreadyActive</function>
- this protocol is already active on this connection.
The major_version_ret, minor_version_ret, vendor_ret, release_ret
are not set.
    </para>
  </listitem>
</itemizedlist>

<para>
To notify the ICE library when a given protocol will no longer be used
on an ICE connection, use <xref linkend='IceProtocolShutdown' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceProtocolShutdown'>
<funcprototype>
  <funcdef>Status <function>IceProtocolShutdown</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> major_opcode</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>major_opcode</emphasis></term>
    <listitem>
      <para>The major opcode of the protocol to shut down.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
The return value of <xref linkend='IceProtocolShutdown' xrefstyle='select: title'/>
is zero for failure and a positive value for success.
</para>

<para>
Failure will occur if the major opcode was never registered OR the protocol
of the major opcode was never activated on the connection.  By activated,
we mean that a <function>ProtocolSetup</function> succeeded on the connection.
Note that ICE does not define how each sub-protocol triggers a
protocol shutdown.
</para>
</chapter>

<chapter id='Processing_Messages'>
<title>Processing Messages</title>


<para>To process incoming messages on an ICE connection, use
<xref linkend='IceProcessMessages' xrefstyle='select: title'/></para>

<funcsynopsis id='IceProcessMessages'>
<funcprototype>
  <funcdef>IceProcessMessagesStatus <function>IceProcessMessages</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IceReplyWaitInfo<parameter> *reply_wait</parameter></paramdef>
    <paramdef>Bool<parameter> *reply_ready_ret</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>reply_wait</emphasis></term>
    <listitem>
      <para>Indicates if a reply is being waited for.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>reply_ready_ret</emphasis></term>
    <listitem>
      <para>
If set to <function>True</function> on return, a reply is ready.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceProcessMessages' xrefstyle='select: title'/> is used in two ways:
</para>

<itemizedlist>
  <listitem>
    <para>
In the first, a client may generate a message and block by calling
<xref linkend='IceProcessMessages' xrefstyle='select: title'/> repeatedly until it gets its reply.
    </para>
  </listitem>
  <listitem>
    <para>
In the second, a client calls <xref linkend='IceProcessMessages' xrefstyle='select: title'/>
with reply_wait set to NULL in response to <function>select</function>
showing that there is data to read on the ICE connection.
The ICE library may process zero or more complete messages.
Note that messages that are not blocked for are always processed by
invoking callbacks.
    </para>
  </listitem>
</itemizedlist>

<para>
<function>IceReplyWaitInfo</function> contains the major/minor opcodes
and sequence number of the message for which a reply is being awaited.
It also contains a pointer to the reply message to be filled in (the
protocol library should cast this <function>IcePointer</function>
to the appropriate reply type).  In most
cases, the reply will have some fixed-size part, and the client waiting
for the reply will have provided a pointer to a structure to hold
this fixed-size data.  If there is variable-length data, it would be
expected that the
<function>IcePoProcessMsgProc</function>
callback will have to allocate additional
memory and store pointer(s) to that memory in the fixed-size
structure.  If the entire data is variable length (for example, a single
variable-length string), then the client waiting for the reply would probably
just pass a pointer to fixed-size space to hold a pointer, and the
<function>IcePoProcessMsgProc</function>
callback would allocate the storage and store the pointer.
It is the responsibility of the client receiving the reply to
free up any memory allocated on its behalf.
</para>

<literallayout class="monospaced">
typedef struct {
     unsigned long sequence_of_request;
     int major_opcode_of_request;
     int minor_opcode_of_request;
     IcePointer reply;
} IceReplyWaitInfo;
</literallayout>

<para>
If reply_wait is not NULL and
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
has a reply or error to return in response to this reply_wait
(that is, no callback was generated), then the reply_ready_ret argument
will be set to <function>True</function>
</para>

<para>
If reply_wait is NULL, then the caller may also pass NULL for
reply_ready_ret and be guaranteed that no value will be stored in
this pointer.
</para>

<para>
<xref linkend='IceProcessMessages' xrefstyle='select: title'/> returns one of the following values:
</para>

<itemizedlist>
  <listitem>
    <para>
<function>IceProcessMessagesSuccess</function> - no error occurred.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IceProcessMessagesIOError</function> - an IO error occurred,
and the caller must explicitly close the connection by calling
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
    </para>
  </listitem>
  <listitem>
    <para>
<function>IceProcessMessagesConnectionClosed</function>
- the ICE connection has been closed (closing of the connection was deferred
because of shutdown negotiation, or because the
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
nesting level was not zero).  Do not attempt
to access the ICE connection at this point, since it has been freed.
    </para>
  </listitem>
</itemizedlist>

</chapter>

<chapter id='Ping'>
<title>Ping</title>

<para>
To send a "Ping" message to the client on the other side of the
ICE connection, use <xref linkend='IcePing' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IcePing'>
<funcprototype>
  <funcdef>Status <function>IcePing</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePingReplyProc<parameter> ping_reply_proc</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>ping_reply_proc</emphasis></term>
    <listitem>
      <para>The callback to invoke when the Ping reply arrives.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>client_data</emphasis></term>
    <listitem>
      <para>
This pointer will be passed to the <olink targetdoc='SMlib' targetptr='IcePingReplyProc'><function>IcePingReplyProc</function></olink>
callback.
      </para>
    </listitem>
  </varlistentry>
</variablelist>


<para><xref linkend='IcePing' xrefstyle='select: title'/>
returns zero for failure and a positive value for success.</para>

<para>When
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
processes the Ping reply, it will invoke the
<olink targetdoc='SMlib' targetptr='IcePingReplyProc'><function>IcePingReplyProc</function></olink>
callback.</para>

<funcsynopsis id='PingReplyProc'>
<funcprototype>
  <funcdef>void <function>PingReplyProc</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>IcePointer<parameter> client_data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>ice_conn</emphasis></term>
  <listitem>
<para>A valid ICE connection object.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>client_data</emphasis></term>
  <listitem>
<para>The client data specified in the call to
<xref linkend='IcePing' xrefstyle='select: title'/></para>
  </listitem>
  </varlistentry>
</variablelist>

</chapter>

<chapter id='Using_ICElib_Informational_Functions'>
<title>Using ICElib Informational Functions</title>

<funcsynopsis id='IceConnectionStatus'>
<funcprototype>
  <funcdef>IceConnectStatus <function>IceConnectionStatus</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<para><xref linkend='IceConnectionStatus' xrefstyle='select: title'/>
returns the status of an ICE connection.  The possible return values are:</para>

<itemizedlist>
  <listitem>
<para><function>IceConnectPending</function>
- the connection is not valid yet (that is, authentication is taking place).
This is only relevant to connections created by
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/></para>
  </listitem>
  <listitem>
<para><function>IceConnectAccepted</function>
- the connection has been accepted.
This is only relevant to connections created by
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/></para>
  </listitem>
  <listitem>
<para><function>IceConnectRejected</function>
- the connection had been rejected  (that is, authentication failed).
This is only relevant to connections created by
<xref linkend='IceAcceptConnection' xrefstyle='select: title'/></para>
  </listitem>
  <listitem>
<para><function>IceConnectIOError</function>
- an IO error has occurred on the connection.</para>
  </listitem>
</itemizedlist>

<funcsynopsis id='IceVendor'>
<funcprototype>
  <funcdef>char <function> *IceVendor</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<para><function>IceVendor</function>
returns the ICE library vendor identification
for the other side of the connection.
The string should be freed with a call to
<function>free</function>
when no longer needed.</para>

<funcsynopsis id='IceRelease'>
<funcprototype>
  <funcdef>char <function> *IceRelease</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<para><function>IceRelease</function>
returns the release identification of the ICE library
on the other side of the connection.
The string should be freed with a call to
<function>free</function>
when no longer needed.</para>

<funcsynopsis id='IceProtocolVersion'>
<funcprototype>
  <funcdef>int <function> IceProtocolVersion</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<para><xref linkend='IceProtocolVersion' xrefstyle='select: title'/>
returns the major version of the ICE protocol on this connection.</para>

<funcsynopsis id='IceProtocolRevision'>
<funcprototype>
  <funcdef>int <function> IceProtocolRevision</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>


<para><xref linkend='IceProtocolRevision' xrefstyle='select: title'/>
returns the minor version of the ICE protocol on this connection.</para>

<funcsynopsis>
<funcprototype>
  <funcdef>int <function> IceConnectionNumber</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>


<para><function>IceConnectionNumber</function>
returns the file descriptor of this ICE connection.</para>

<funcsynopsis id='IceConnectionString'>
<funcprototype>
  <funcdef>char <function> *IceConnectionString</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<para><function>IceConnectionString</function>
returns the network ID of the client that
accepted this connection.  The string should be freed with a call to
<function>free</function>
when no longer needed.</para>

<funcsynopsis id='IceLastSentSequenceNumber'>
<funcprototype>
  <funcdef>unsigned long <function> IceLastSentSequenceNumber</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>


<para><xref linkend='IceLastSentSequenceNumber' xrefstyle='select: title'/>
returns the sequence number of the last message sent on this ICE connection.</para>

<funcsynopsis>
<funcprototype>
  <funcdef>unsigned long <function> IceLastReceivedSequenceNumber</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<para><function>IceLastReceivedSequenceNumber</function>
returns the sequence number of the last message received on this
ICE connection.</para>

<funcsynopsis id='IceSwapping'>
<funcprototype>
  <funcdef>Bool <function> IceSwapping</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>


<para><xref linkend='IceSwapping' xrefstyle='select: title'/>
returns
<function>True</function>
if byte swapping is necessary when reading messages on the ICE connection.</para>

<funcsynopsis id='IceGetContext'>
<funcprototype>
  <funcdef>IcePointer <function> IceGetContext</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<para><xref linkend='IceGetContext' xrefstyle='select: title'/>
returns the context associated with a connection created by
<xref linkend='IceOpenConnection' xrefstyle='select: title'/></para>
</chapter>

<chapter id='ICE_Messages'>
<title>ICE Messages</title>

<para>
All ICE messages have a standard 8-byte header.  The ICElib macros that
read and write messages rely on the following naming convention for message
headers:
</para>

<literallayout class='monospaced'>
     CARD8	major_opcode;
     CARD8	minor_opcode;
     CARD8	data[2];
     CARD32	length B32;
</literallayout>

<para>
The 3rd and 4th bytes of the message header can be used as needed.
The length field is specified in units of 8 bytes.
</para>

<sect1 id='Sending_ICE_Messages'>
<title>Sending ICE Messages</title>

<para>
The ICE library maintains an output buffer used for generating messages.
Protocol libraries layered on top of ICE may choose to batch messages
together and flush the output buffer at appropriate times.
</para>

<para>
If an IO error has occurred on an ICE connection, all write operations
will be ignored.  For further information, see
<xref linkend='Error_Handling' xrefstyle='select: title'/>.
</para>


<para>
To get the size of the ICE output buffer, use
<xref linkend='IceGetOutBufSize' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceGetOutBufSize'>
<funcprototype>
  <funcdef>int <function> IceGetOutBufSize</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
To flush the ICE output buffer, use <xref linkend='IceFlush' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceFlush'>
<funcprototype>
  <funcdef>int <function> IceFlush</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
Note that the output buffer may be implicitly flushed if there is
insufficient space to generate a message.
</para>

<para>The following macros can be used to generate ICE messages:</para>

<funcsynopsis id='IceGetHeader'>
<funcprototype>
  <funcdef><function> IceGetHeader</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> major_opcode</parameter></paramdef>
    <paramdef>int<parameter> minor_opcode</parameter></paramdef>
    <paramdef>int<parameter> header_size</parameter></paramdef>
    <paramdef>&lt;C_data_type&gt;<parameter> *pmsg</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>major_opcode</emphasis></term>
    <listitem>
      <para>The major opcode of the message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>minor_opcode</emphasis></term>
    <listitem>
      <para>The minor opcode of the message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>header_size</emphasis></term>
    <listitem>
      <para>The size of the message header (in bytes).</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>&lt;C_data_type&gt;</emphasis></term>
    <listitem>
      <para>The actual C data type of the message header.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pmsg</emphasis></term>
    <listitem>
      <para>
The message header pointer.  After this macro is called, the
library can store data in the message header.
      </para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
<xref linkend='IceGetHeader' xrefstyle='select: title'/>
is used to set up a message header on an ICE connection.
It sets the major and minor opcodes of the message, and initializes
the message's length to the length of the header.  If additional
variable length data follows, the message's length field should be
updated.
</para>


<funcsynopsis id='IceGetHeaderExtra'>
<funcprototype>
  <funcdef><function> IceGetHeaderExtra</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> major_opcode</parameter></paramdef>
    <paramdef>int<parameter> minor_opcode</parameter></paramdef>
    <paramdef>int<parameter> header_size</parameter></paramdef>
    <paramdef>int<parameter> extra</parameter></paramdef>
    <paramdef>&lt;C_data_type&gt;<parameter> *pmsg</parameter></paramdef>
    <paramdef>char<parameter> *pdata</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>major_opcode</emphasis></term>
    <listitem>
      <para>The major opcode of the message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>minor_opcode</emphasis></term>
    <listitem>
      <para>The minor opcode of the message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>header_size</emphasis></term>
    <listitem>
      <para>The size of the message header (in bytes).</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>extra</emphasis></term>
    <listitem>
      <para>
The size of the extra data beyond the header (in 8-byte units).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>&lt;C_data_type&gt;</emphasis></term>
    <listitem>
      <para>The actual C data type of the message header.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pmsg</emphasis></term>
    <listitem>
      <para>
The message header pointer.  After this macro is called, the
library can store data in the message header.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pdata</emphasis></term>
    <listitem>
      <para>
Returns a pointer to the ICE output buffer that points
immediately after the message header.  The variable length
data should be stored here.  If there was not enough room
in the ICE output buffer, pdata is set to NULL.
      </para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
<xref linkend='IceGetHeaderExtra' xrefstyle='select: title'/>
is used to generate a message with a fixed (and relatively small) amount
of variable length data.  The complete message must fit in the ICE output
buffer.
</para>

<funcsynopsis id='IceSimpleMessage'>
<funcprototype>
  <funcdef><function> IceSimpleMessage</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> major_opcode</parameter></paramdef>
    <paramdef>int<parameter> minor_opcode</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>major_opcode</emphasis></term>
    <listitem>
      <para>The major opcode of the message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>minor_opcode</emphasis></term>
    <listitem>
      <para>The minor opcode of the message.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceSimpleMessage' xrefstyle='select: title'/>
is used to generate a message that is identical
in size to the ICE header message, and has no additional data.
</para>

<funcsynopsis id='IceErrorHeader'>
<funcprototype>
  <funcdef><function> IceErrorHeader</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> offending_major_opcode</parameter></paramdef>
    <paramdef>int<parameter> offending_minor_opcode</parameter></paramdef>
    <paramdef>int<parameter> offending_sequence_num</parameter></paramdef>
    <paramdef>int<parameter> severity</parameter></paramdef>
    <paramdef>int<parameter> error_class</parameter></paramdef>
    <paramdef>int<parameter> data_length</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>offending_major_opcode</emphasis></term>
    <listitem>
      <para>
The major opcode of the protocol in which an error was detected.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>offending_minor_opcode</emphasis></term>
    <listitem>
      <para>
The minor opcode of the protocol in which an error was detected.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>offending_sequence_num</emphasis></term>
    <listitem>
      <para>The sequence number of the message that caused the error.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>severity</emphasis></term>
    <listitem>
      <para>
<function>IceCanContinue</function>
<function>IceFatalToProtocol</function>
or
<function>IceFatalToConnection</function>
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_class</emphasis></term>
    <listitem>
      <para>The error class.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>data_length</emphasis></term>
    <listitem>
      <para>
Length of data (in 8-byte units) to be written after the header.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceErrorHeader' xrefstyle='select: title'/> sets up an error message header.
</para>

<para>
Note that the two clients connected by ICE may be using different
major opcodes for a given protocol.  The offending_major_opcode passed
to this macro is the major opcode of the protocol for the client
sending the error message.
</para>

<para>
Generic errors, which are common to all protocols, have classes
in the range 0x8000..0xFFFF.
See the <emphasis remap='I'>Inter-Client Exchange Protocol</emphasis>
standard for more details.
</para>

<informaltable frame='none'>
  <?dbfo keep-together="always" ?>
  <tgroup cols='2' align='left' colsep='0' rowsep='0'>
    <colspec colname='c1' colwidth='1.0*'/>
    <colspec colname='c2' colwidth='2.0*'/>
    <tbody>
      <row>
        <entry>IceBadMinor</entry>
        <entry>0x8000</entry>
      </row>
      <row>
        <entry>IceBadState</entry>
        <entry>0x8001</entry>
      </row>
      <row>
        <entry>IceBadLength</entry>
        <entry>0x8002</entry>
      </row>
      <row>
        <entry>IceBadValue</entry>
        <entry>0x8003</entry>
      </row>
    </tbody>
  </tgroup>
</informaltable>

<para>Per-protocol errors have classes in the range 0x0000-0x7fff.</para>

<para>
To write data to an ICE connection, use the
<xref linkend='IceWriteData' xrefstyle='select: title'/> macro.  If the data fits into the
ICE output buffer, it is copied there.  Otherwise, the ICE output buffer
is flushed and the data is directly sent.
</para>

<para>
This macro is used in conjunction with
<xref linkend='IceGetHeader' xrefstyle='select: title'/> and
<xref linkend='IceErrorHeader' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceWriteData'>
<funcprototype>
  <funcdef><function> IceWriteData</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to write.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>data</emphasis></term>
    <listitem>
      <para>The data to write.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
To write data as 16-bit quantities, use <xref linkend='IceWriteData16' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceWriteData16'>
<funcprototype>
  <funcdef><function> IceWriteData16</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to write.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>data</emphasis></term>
    <listitem>
      <para>The data to write.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
To write data as 32-bit quantities, use <xref linkend='IceWriteData32' xrefstyle='select: title'/>
</para>


<funcsynopsis id='IceWriteData32'>
<funcprototype>
  <funcdef><function> IceWriteData32</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to write.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>data</emphasis></term>
    <listitem>
      <para>The data to write.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
To write data as 32-bit quantities, use <xref linkend='IceWriteData32' xrefstyle='select: title'/>
</para>

<para>
To bypass copying data to the ICE output buffer, use
<xref linkend='IceSendData' xrefstyle='select: title'/> to directly send data over the network
connection.  If necessary, the ICE output buffer is first flushed.
</para>

<funcsynopsis id='IceSendData'>
<funcprototype>
  <funcdef><function> IceSendData</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to send.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>data</emphasis></term>
    <listitem>
      <para>The data to send.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
To force 32-bit or 64-bit alignment, use <xref linkend='IceWritePad' xrefstyle='select: title'/>
A maximum of 7 pad bytes can be specified.
</para>

<funcsynopsis id='IceWritePad'>
<funcprototype>
  <funcdef><function> IceWritePad</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *data</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to write.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>data</emphasis></term>
    <listitem>
      <para>The number of pad bytes to write.</para>
    </listitem>
  </varlistentry>
</variablelist>

</sect1>

<sect1 id='Reading_ICE_Messages'>
<title>Reading ICE Messages</title>


<para>
The ICE library maintains an input buffer used for reading messages.
If the ICE library chooses to perform nonblocking reads (this is
implementation-dependent), then for every read operation that it makes,
zero or more complete messages may be read into the input buffer.  As
a result, for all of the macros described in this section that read
messages, an actual read operation will occur on the connection only if
the data is not already present in the input buffer.
</para>


<para>
To get the size of the ICE input buffer, use
<xref linkend='IceGetInBufSize' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceGetInBufSize'>
<funcprototype>
  <funcdef>int<function> IceGetInBufSize</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
When reading messages, care must be taken to check for IO errors.  If
any IO error occurs in reading any part of a message, the message should
be thrown out.  After using any of the macros described below for reading
messages, the <xref linkend='IceValidIO' xrefstyle='select: title'/>
macro can be used to check if an IO error occurred on the
connection.  After an IO error has occurred on an ICE connection, all
read operations will be ignored.  For further information, see
<xref linkend='Error_Handling' xrefstyle='select: title'/>.
</para>


<funcsynopsis id='IceValidIO'>
<funcprototype>
  <funcdef>Bool<function> IceValidIO</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>The following macros can be used to read ICE messages.</para>

<funcsynopsis id='IceReadSimpleMessage'>
<funcprototype>
  <funcdef><function> IceReadSimpleMessage</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>&lt;C_data_type&gt;<parameter> *pmsg</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>&lt;C_data_type&gt;</emphasis></term>
    <listitem>
      <para>The actual C data type of the message header.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pmsg</emphasis></term>
    <listitem>
      <para>This pointer is set to the message header.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceReadSimpleMessage' xrefstyle='select: title'/>
is used for messages that are identical in size to the 8-byte ICE header, but
use the spare 2 bytes in the header to encode additional data.  Note that the
ICE library always reads in these first 8 bytes, so it can obtain the major
opcode of the message.  <xref linkend='IceReadSimpleMessage' xrefstyle='select: title'/>
simply returns a pointer to these 8 bytes; it does not actually read any data
into the input buffer.
</para>

<para>
For a message with variable length data, there are two ways of reading
the message.  One method involves reading the complete message in one
pass using <xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
The second method involves reading the message header (note that this may
be larger than the 8-byte ICE header), then reading
the variable length data in chunks (see
<xref linkend='IceReadMessageHeader' xrefstyle='select: title'/> and
<xref linkend='IceReadData' xrefstyle='select: title'/>
</para>


<funcsynopsis id='IceReadCompleteMessage'>
<funcprototype>
  <funcdef><function> IceReadCompleteMessage</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> header_size</parameter></paramdef>
    <paramdef>&lt;C_data_type&gt;<parameter> *pmsg</parameter></paramdef>
    <paramdef>char<parameter> *pdata</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>header_size</emphasis></term>
    <listitem>
      <para>The size of the message header (in bytes).</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>&lt;C_data_type&gt;</emphasis></term>
    <listitem>
      <para>The actual C data type of the message header.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pmsg</emphasis></term>
    <listitem>
      <para>This pointer is set to the message header.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pdata</emphasis></term>
    <listitem>
      <para>
This pointer is set to the variable length data of the message.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
If the ICE input buffer has sufficient space,
<xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
will read the complete message into the
ICE input buffer.  Otherwise, a buffer will be allocated to hold the
variable length data.  After the call, the pdata argument should
be checked against NULL to make sure that there was sufficient memory
to allocate the buffer.
</para>

<para>
After calling <xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
and processing the message, <xref linkend='IceDisposeCompleteMessage' xrefstyle='select: title'/>
should be called.
</para>


<funcsynopsis id='IceDisposeCompleteMessage'>
<funcprototype>
  <funcdef><function> IceDisposeCompleteMessage</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>char<parameter> *pdata</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pdata</emphasis></term>
    <listitem>
      <para>
The pointer to the variable length data returned in
<xref linkend='IceReadCompleteMessage' xrefstyle='select: title'/>
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
If a buffer had to be allocated to hold the variable length data (because
it did not fit in the ICE input buffer), it is freed here by ICElib.
</para>


<funcsynopsis id='IceReadMessageHeader'>
<funcprototype>
  <funcdef><function> IceReadMessageHeader</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> header_size</parameter></paramdef>
    <paramdef>&lt;C_data_type&gt;<parameter> *pmsg</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>header_size</emphasis></term>
    <listitem>
      <para>The size of the message header (in bytes).</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>&lt;C_data_type&gt;</emphasis></term>
    <listitem>
      <para>The actual C data type of the message header.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pmsg</emphasis></term>
    <listitem>
      <para>This pointer is set to the message header.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceReadMessageHeader' xrefstyle='select: title'/> reads just the message header.
The rest of the data should be read with the
<xref linkend='IceReadData' xrefstyle='select: title'/>
family of macros.  This method of reading a message should be used when the
variable length data must be read in chunks.
</para>


<para>
To read data directly into a user supplied buffer, use
<xref linkend='IceReadData' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceReadData'>
<funcprototype>
  <funcdef><function> IceReadData</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *pdata</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to read.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pdata</emphasis></term>
    <listitem>
      <para>The data is read into this user supplied buffer.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
To read data as 16-bit quantities, use <xref linkend='IceReadData16' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceReadData16'>
<funcprototype>
  <funcdef><function> IceReadData16</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>Bool<parameter> swap</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *pdata</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>swap</emphasis></term>
    <listitem>
      <para>
If <function>True,</function> the values will be byte swapped.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to read.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pdata</emphasis></term>
    <listitem>
      <para>The data is read into this user supplied buffer.</para>
    </listitem>
  </varlistentry>
</variablelist>


<para>
To read data as 32-bit quantities, use <xref linkend='IceReadData32' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceReadData32'>
<funcprototype>
  <funcdef><function> IceReadData32</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>Bool<parameter> swap</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
    <paramdef>char<parameter> *pdata</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>swap</emphasis></term>
    <listitem>
      <para>
If <function>True,</function> the values will be byte swapped.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of bytes to read.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>pdata</emphasis></term>
    <listitem>
      <para>The data is read into this user supplied buffer.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>To force 32-bit or 64-bit alignment, use
<xref linkend='IceReadPad' xrefstyle='select: title'/>
A maximum of 7 pad bytes can be specified.</para>

<funcsynopsis id='IceReadPad'>
<funcprototype>
  <funcdef><function> IceReadPad</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem>
      <para>A valid ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>bytes</emphasis></term>
    <listitem>
      <para>The number of pad bytes.</para>
    </listitem>
  </varlistentry>
</variablelist>

</sect1>
</chapter>

<chapter id='Error_Handling'>
<title>Error Handling</title>


<para>There are two default error handlers in ICElib:</para>

<itemizedlist>
  <listitem>
    <para>
One to handle typically fatal conditions (for example,
a connection dying because a machine crashed)
    </para>
  </listitem>
  <listitem>
    <para>One to handle ICE-specific protocol errors</para>
  </listitem>
</itemizedlist>

<para>
These error handlers can be changed to user-supplied routines if you
prefer your own error handling and can be changed as often as you like.
</para>


<para>
To set the ICE error handler, use <xref linkend='IceSetErrorHandler' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceSetErrorHandler'>
<funcprototype>
  <funcdef><function> IceSetErrorHandler</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>int<parameter> bytes</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>handler</emphasis></term>
    <listitem>
      <para>
The ICE error handler.  You should pass NULL to restore the default handler.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceSetErrorHandler' xrefstyle='select: title'/> returns the previous error handler.
</para>

<para>
The ICE error handler is invoked when an unexpected ICE protocol
error (major opcode 0) is encountered.  The action of the default
handler is to print an explanatory message to
<function>stderr</function>
and if the severity is fatal, call
<function>exit</function>
with a nonzero value.  If exiting
is undesirable, the application should register its own error handler.
</para>

<para>
Note that errors in other protocol
domains should be handled by their respective libraries (these libraries
should have their own error handlers).
</para>

<para>
An ICE error handler has the type of <xref linkend='IceErrorHandler' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceErrorHandler'>
<funcprototype>
  <funcdef>void<function> IceErrorHandler</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>Bool<parameter> swap</parameter></paramdef>
    <paramdef>int<parameter> offending_minor_opcode</parameter></paramdef>
    <paramdef>unsigned long<parameter> offending_sequence_num</parameter></paramdef>
    <paramdef>int<parameter> error_class</parameter></paramdef>
    <paramdef>int<parameter> severity</parameter></paramdef>
    <paramdef>IcePointer<parameter> values</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>handler</emphasis></term>
    <listitem>
      <para>The ICE connection object.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>swap</emphasis></term>
    <listitem>
      <para>A flag that indicates if the values need byte swapping.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>offending_minor_opcode</emphasis></term>
    <listitem>
      <para>The ICE minor opcode of the offending message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>offending_sequence_num</emphasis></term>
    <listitem>
      <para>The sequence number of the offending message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>error_class</emphasis></term>
    <listitem>
      <para>The error class of the offending message.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>severity</emphasis></term>
    <listitem>
      <para>
<function>IceCanContinue</function>
<function>IceFatalToProtocol</function>
or
<function>IceFatalToConnection</function>
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>values</emphasis></term>
    <listitem>
      <para>
Any additional error values specific to the minor opcode and class.
      </para>
    </listitem>
  </varlistentry>
</variablelist>


<para>The following error classes are defined at the ICE level:</para>

<literallayout remap='Ds'>
<function>IceBadMinor</function>
<function>IceBadState</function>
<function>IceBadLength</function>
<function>IceBadValue</function>
<function>IceBadMajor</function>
<function>IceNoAuth</function>
<function>IceNoVersion</function>
<function>IceSetupFailed</function>
<function>IceAuthRejected</function>
<function>IceAuthFailed</function>
<function>IceProtocolDuplicate</function>
<function>IceMajorOpcodeDuplicate</function>
<function>IceUnknownProtocol</function>
</literallayout>

<para>
For further information, see
the <emphasis remap='I'>Inter-Client Exchange Protocol</emphasis> standard.
</para>


<para>
To handle fatal I/O errors, use <xref linkend='IceSetIOErrorHandler' xrefstyle='select: title'/>
</para>


<funcsynopsis id='IceSetIOErrorHandler'>
<funcprototype>
  <funcdef>IceIOErrorHandler<function> IceSetIOErrorHandler</function></funcdef>
    <paramdef>IceIOErrorHandler<parameter> handler</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>handler</emphasis></term>
    <listitem>
      <para>
The I/O error handler.  You should pass NULL to restore the default handler.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
<xref linkend='IceSetIOErrorHandler' xrefstyle='select: title'/> returns the previous
IO error handler.
</para>

<para>
An ICE I/O error handler has the type of
<xref linkend='IceIOErrorHandler' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceIOErrorHandler'>
<funcprototype>
  <funcdef>void<function> IceIOErrorHandler</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
</variablelist>


<para> There are two ways of handling IO errors in ICElib:</para>

<itemizedlist>
  <listitem>
    <para>
In the first, the IO error handler does whatever is necessary
to respond to the IO error and then returns, but it does not call
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
The ICE connection is given a "bad IO" status, and all future reads
and writes to the connection are ignored.  The next time
<xref linkend='IceProcessMessages' xrefstyle='select: title'/>
is called it will return a status of
<function>IceProcessMessagesIOError</function>
At that time, the application should call
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
    </para>
  </listitem>
  <listitem>
    <para>
In the second, the IO error handler does call
<xref linkend='IceCloseConnection' xrefstyle='select: title'/>
and then uses the <function>longjmp</function>
call to get back to the application's main event loop.  The
<function>setjmp</function> and
<function>longjmp</function>
calls may not work properly on all platforms,
and special care must be taken to avoid memory leaks.
Therefore, this second model is less desirable.
    </para>
  </listitem>
</itemizedlist>

<para>
Before the application I/O error handler is invoked, protocol libraries
that were interested in being notified of I/O errors will have their
<xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
handlers invoked.  This handler is set up in the protocol registration
functions (see <xref linkend='IceRegisterForProtocolSetup' xrefstyle='select: title'/> and
<xref linkend='IceRegisterForProtocolReply' xrefstyle='select: title'/>
and could be used to clean up state specific to the protocol.
</para>


<funcsynopsis id='IceIOErrorProc'>
<funcprototype>
  <funcdef>void<function> IceIOErrorProc</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>
Note that every <xref linkend='IceIOErrorProc' xrefstyle='select: title'/>
callback must return.  This is required
because each active protocol must be notified of the broken connection,
and the application IO error handler must be invoked afterwards.
</para>
</chapter>

<chapter id='Multi_Threading_Support'>
<title>Multi-Threading Support</title>


<para>To declare that multiple threads in an application will be using the ICE
library, use
<function>IceInitThreads</function></para>

<literallayout remap='FD'>
Status IceInitThreads()
</literallayout>


<para>The
<function>IceInitThreads</function>
function must be the first ICElib function a
multi-threaded program calls.  It must complete before any other ICElib
call is made.
<function>IceInitThreads</function>
returns a nonzero status if and only if it was able
to initialize the threads package successfully.
It is safe to call
<function>IceInitThreads</function>
more than once, although the threads package will only be initialized once.</para>

<para>Protocol libraries layered on top of ICElib will have to lock critical
sections of code that access an ICE connection (for example, when
generating messages).  Two calls, which are generally implemented as
macros, are provided:</para>

<funcsynopsis id='IceLockConn'>
<funcprototype>
  <funcdef>void<function> IceLockConn</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<funcsynopsis id='IceUnlockConn'>
<funcprototype>
  <funcdef>void<function> IceUnlockConn</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>To keep an ICE connection locked across several ICElib calls, applications use
<xref linkend='IceAppLockConn' xrefstyle='select: title'/>
and
<xref linkend='IceAppUnlockConn' xrefstyle='select: title'/></para>

<funcsynopsis id='IceAppLockConn'>
<funcprototype>
  <funcdef>void<function> IceAppLockConn</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
</variablelist>


<para>The
<xref linkend='IceAppLockConn' xrefstyle='select: title'/>
function completely locks out other threads using the connection
until
<xref linkend='IceAppUnlockConn' xrefstyle='select: title'/>
is called.  Other threads attempting to use ICElib
calls on the connection will block.
If the program has not previously called
<function>IceInitThreads</function>
<xref linkend='IceAppLockConn' xrefstyle='select: title'/>
has no effect.</para>

<funcsynopsis id='IceAppUnlockConn'>
<funcprototype>
  <funcdef>void<function> IceAppUnlockConn</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
</variablelist>

<para>The
<xref linkend='IceAppUnlockConn' xrefstyle='select: title'/>
function allows other threads to complete ICElib
calls on the connection that were blocked by a previous call to
<xref linkend='IceAppLockConn' xrefstyle='select: title'/>
from this thread.  If the program has not previously called
<function>IceInitThreads</function>
<xref linkend='IceAppUnlockConn' xrefstyle='select: title'/>
has no effect.</para>
</chapter>

<chapter id='Miscellaneous_Functions'>
<title>Miscellaneous Functions</title>




<para>To allocate scratch space (for example, when generating
messages with variable data), use
<function>IceAllocScratch</function>
Each ICE connection has one scratch space associated with it.
The scratch space starts off as empty and grows as needed.
The contents of the scratch space is not guaranteed to be preserved
after any ICElib function is called.</para>


<funcsynopsis id='IceAllocScratch'>
<funcprototype>
  <funcdef>char<function> *IceAllocScratch</function></funcdef>
    <paramdef>IceConn<parameter> ice_conn</parameter></paramdef>
    <paramdef>unsigned long<parameter> size</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>ice_conn</emphasis></term>
    <listitem><para>The ICE connection object.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>size</emphasis></term>
    <listitem><para>The number of bytes required.</para></listitem>
  </varlistentry>
</variablelist>

<para>Note that the memory returned by
<function>IceAllocScratch</function>
should not be freed by the caller.
The ICE library will free the memory when the ICE connection is closed.</para>
</chapter>

<chapter id='Acknowledgements'>
<title>Acknowledgements</title>


<para>
Thanks to Bob Scheifler for his thoughtful input on the design
of the ICE library.  Thanks also to Jordan Brown, Larry Cable, Donna Converse,
Clive Feather, Stephen Gildea, Vania Joloboff, Kaleb Keithley,
Stuart Marks, Hiro Miyamoto, Ralph Swick, Jim VanGilder, and Mike Wexler.
</para>
</chapter>

<appendix id="authentication_utility_functions">
<title>Authentication Utility Functions</title>


<para>
As discussed in this document, the means by which authentication data
is obtained by the ICE library (for
<function>ConnectionSetup</function>
messages or
<function>ProtocolSetup</function>
messages) is implementation-dependent.&dagger;
<footnote remap='FS'>
<para>The X Consortium's ICElib implementation assumes the presence of an
ICE authority file.
</para></footnote>
</para>

<para>
This appendix describes some utility functions that manipulate an
ICE authority file.  The authority file can be used to pass authentication
data between clients.
</para>

<para>The basic operations on the .ICEauthority file are:</para>

<itemizedlist>
  <listitem>
    <para>Get file name</para>
  </listitem>
  <listitem>
    <para>Lock</para>
  </listitem>
  <listitem>
    <para>Unlock</para>
  </listitem>
  <listitem>
    <para>Read entry</para>
  </listitem>
  <listitem>
    <para>Write entry</para>
  </listitem>
  <listitem>
    <para>Search for entry</para>
  </listitem>
</itemizedlist>

<para>
These are fairly low-level operations, and it is expected that a program,
like "iceauth", would exist to add, remove, and display entries in the file.
</para>

<para>
In order to use these utility functions, the
&lt;<symbol role='Pn'>X11/ICE/ICEutil.h</symbol>&gt;
header file must be included.
</para>

<para>
An entry in the .ICEauthority file is defined by the following data structure:
</para>


<literallayout class="monospaced">
typedef struct {
     char *protocol_name;
     unsigned short protocol_data_length;
     char *protocol_data;
     char *network_id;
     char *auth_name;
     unsigned short auth_data_length;
     char *auth_data;
} IceAuthFileEntry;
</literallayout>


<para>
The protocol_name member is either "ICE" for connection setup authentication
or the subprotocol name, such as "XSMP".  For each entry, protocol specific
data can be specified in the protocol_data member.  This can be used
to search for old entries that need to be removed from the file.
</para>

<para>
The network_id member is the network ID of the client accepting
authentication (for example, the network ID of a session manager).
A network ID has the following form:
</para>

<informaltable frame='none'>
  <?dbfo keep-together="always" ?>
  <tgroup cols='2' align='left' colsep='0' rowsep='0'>
    <colspec colname='c1' colwidth='1.0*'/>
    <colspec colname='c2' colwidth='2.0*'/>
    <tbody>
      <row>
        <entry>tcp/&lt;hostname&gt;:&lt;portnumber&gt;</entry>
        <entry>or</entry>
      </row>
      <row>
        <entry>decnet/&lt;hostname&gt;::&lt;objname&gt;</entry>
        <entry>or</entry>
      </row>
      <row>
        <entry>local/&lt;hostname&gt;:&lt;path&gt;</entry>
        <entry></entry>
      </row>
    </tbody>
  </tgroup>
</informaltable>

<para>
The auth_name member is the name of the authentication method.
The auth_data member is the actual authentication data,
and the auth_data_length member is the number of bytes in the data.
</para>

<para>
To obtain the default authorization file name, use
<function>IceAuthFileName</function>
</para>

<literallayout remap='FD'>
char *IceAuthFileName()
</literallayout>

<para>
If the ICEAUTHORITY environment variable if set, this value is returned.
Otherwise, the default authorization file name is $HOME/.ICEauthority.
This name is statically allocated and should not be freed.
</para>

<para>
To synchronously update the authorization file, the file must
be locked with a call to
<xref linkend='IceLockAuthFile' xrefstyle='select: title'/>
This function takes advantage of the fact that the
<function>link</function>
system call will fail if the name of the new link already exists.
</para>

<funcsynopsis id='IceLockAuthFile'>
<funcprototype>
  <funcdef>int<function> IceLockAuthFile</function></funcdef>
    <paramdef>char<parameter> *file_name</parameter></paramdef>
    <paramdef>int<parameter> retries</parameter></paramdef>
    <paramdef>int<parameter> timeout</parameter></paramdef>
    <paramdef>long<parameter> dead</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>file_name</emphasis></term>
    <listitem><para>The authorization file to lock.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>retries</emphasis></term>
    <listitem>
      <para>The number of retries.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>timeout</emphasis></term>
    <listitem>
      <para>The number of seconds before each retry.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>dead</emphasis></term>
    <listitem>
      <para>
If a lock already exists that is the specified dead seconds old,
it is broken.
A value of zero is used to unconditionally break an old lock.
      </para>
    </listitem>
  </varlistentry>
</variablelist>

<para>One of three values is returned:</para>

<itemizedlist>
  <listitem>
    <para>
<function>IceAuthLockSuccess</function> - the lock succeeded.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IceAuthLockError</function> - a system error occurred, and
<function>errno</function> may prove useful.
    </para>
  </listitem>
  <listitem>
    <para>
<function>IceAuthLockTimeout</function> - the specified number of
retries failed.
    </para>
  </listitem>
</itemizedlist>

<para>
To unlock an authorization file, use <xref linkend='IceUnlockAuthFile' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceUnlockAuthFile'>
<funcprototype>
  <funcdef>int<function> IceUnlockAuthFile</function></funcdef>
    <paramdef>char<parameter> *file_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>file_name</emphasis></term>
    <listitem><para>The authorization file to unlock.</para></listitem>
  </varlistentry>
</variablelist>

<para>
To read the next entry in an authorization file, use
<function>IceReadAuthFileEntry</function>
</para>

<funcsynopsis id='IceReadAuthFileEntry'>
<funcprototype>
  <funcdef>IceAuthFileEntry<function> *IceReadAuthFileEntry</function></funcdef>
    <paramdef>FILE<parameter> *auth_file</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>auth_file</emphasis></term>
    <listitem><para>The authorization file.</para></listitem>
  </varlistentry>
</variablelist>

<para>
Note that it is the responsibility of the application to open the file
for reading before calling this function.  If an error is encountered,
or there are no more entries to read, NULL is returned.
</para>

<para>
Entries should be free with a call to
<xref linkend='IceFreeAuthFileEntry' xrefstyle='select: title'/>
</para>

<para>
To write an entry in an authorization file, use
<xref linkend='IceWriteAuthFileEntry' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceWriteAuthFileEntry'>
<funcprototype>
  <funcdef>Status<function> IceWriteAuthFileEntry</function></funcdef>
    <paramdef>FILE<parameter> *auth_file</parameter></paramdef>
    <paramdef>IceAuthFileEntry<parameter> *entry</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>auth_file</emphasis></term>
    <listitem><para>The authorization file.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>entry</emphasis></term>
    <listitem><para>The entry to write.</para></listitem>
  </varlistentry>
</variablelist>

<para>
Note that it is the responsibility of the application to open the file
for writing before calling this function.  The function returns a nonzero
status if the operation was successful.
</para>


<para>
To search the default authorization file for an entry that matches a given
protocol_name/network_id/auth_name tuple, use
<function>IceGetAuthFileEntry</function>
</para>

<funcsynopsis id='IceGetAuthFileEntry'>
<funcprototype>
  <funcdef>IceAuthFileEntry<function> *IceGetAuthFileEntry</function></funcdef>
    <paramdef>const char *<parameter>protocol_name</parameter></paramdef>
    <paramdef>const char *<parameter>network_id</parameter></paramdef>
    <paramdef>const char *<parameter>auth_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>auth_file</emphasis></term>
    <listitem><para>The name of the protocol to search on.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>network_id</emphasis></term>
    <listitem>
      <para>The network ID to search on.</para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>auth_name</emphasis></term>
    <listitem>
      <para>The authentication method to search on.</para>
    </listitem>
  </varlistentry>
</variablelist>

<para>
If <function>IceGetAuthFileEntry</function>
fails to find such an entry, NULL is returned.
</para>


<para>
To free an entry returned by
<function>IceReadAuthFileEntry</function> or
<function>IceGetAuthFileEntry</function> use
<xref linkend='IceFreeAuthFileEntry' xrefstyle='select: title'/>
</para>

<funcsynopsis id='IceFreeAuthFileEntry'>
<funcprototype>
  <funcdef>void<function> IceFreeAuthFileEntry</function></funcdef>
    <paramdef>IceAuthFileEntry<parameter> *entry</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>entry</emphasis></term>
    <listitem><para>The entry to free.</para></listitem>
  </varlistentry>
</variablelist>

</appendix>

<appendix id="mit_magic_cookie_1_authentication">
<title>MIT-MAGIC-COOKIE-1 Authentication</title>


<para>The X Consortium's ICElib implementation supports a simple
MIT-MAGIC-COOKIE-1 authentication scheme using the authority file utilities
described in Appendix A.</para>

<para>In this model, an application, such as a session manager, obtains a
magic cookie by calling
<function>IceGenerateMagicCookie</function>
and then stores it in the user's local .ICEauthority file
so that local clients can connect.  In order to allow remote clients to
connect, some remote execution mechanism should be used to store the
magic cookie in the user's .ICEauthority file on a remote machine.</para>

<para>In addition to storing the magic cookie in the .ICEauthority file, the
application needs to call the
<xref linkend='IceSetPaAuthData' xrefstyle='select: title'/>
function in order to store the magic cookie in memory.  When it comes time
for the MIT-MAGIC-COOKIE-1 authentication procedure to accept or reject the
connection, it will compare the magic cookie presented by the requestor to
the magic cookie in memory.</para>

<funcsynopsis id='IceGenerateMagicCookie'>
<funcprototype>
  <funcdef>char<function> *IceGenerateMagicCookie</function></funcdef>
    <paramdef>int<parameter> length</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>length</emphasis></term>
    <listitem><para>The desired length of the magic cookie.</para></listitem>
  </varlistentry>
</variablelist>


<para>The magic cookie returned will be null-terminated.  If memory can not be
allocated for the magic cookie, the function will return NULL.
Otherwise, the magic cookie should be freed with a call to
<function>free</function></para>


<para>To store the authentication data in memory, use
<xref linkend='IceSetPaAuthData' xrefstyle='select: title'/>
Currently, this function is only used for MIT-MAGIC-COOKIE-1
authentication, but it may be used for additional authentication
methods in the future.</para>

<funcsynopsis id='IceSetPaAuthData'>
<funcprototype>
  <funcdef>void<function> IceSetPaAuthData</function></funcdef>
    <paramdef>int<parameter> num_entries</parameter></paramdef>
    <paramdef>IceAuthDataEntry<parameter> *entries</parameter></paramdef>
</funcprototype>
</funcsynopsis>

<variablelist remap='IP'>
  <varlistentry>
    <term><emphasis remap='I'>num_entries</emphasis></term>
    <listitem><para>The number of authentication data entries.</para></listitem>
  </varlistentry>
  <varlistentry>
    <term><emphasis remap='I'>entries</emphasis></term>
    <listitem><para>The list of authentication data entries.</para></listitem>
  </varlistentry>
</variablelist>

<para>Each entry has associated with it a protocol name
(for example, "ICE" for ICE connection setup authentication,
"XSMP" for session management authentication), a network ID for the
"accepting" client, an authentication name (for example, MIT-MAGIC-COOKIE-1),
and authentication data.  The ICE library
will merge these entries with previously set entries, based on the
(protocol_name, network_id, auth_name) tuple.</para>



<literallayout class="monospaced">
typedef struct {
	char *protocol_name;
	char *network_id;
	char *auth_name;
	unsigned short auth_data_length;
	char *auth_data;
} IceAuthDataEntry;
</literallayout>

</appendix>
</book>