File: book.xml

package info (click to toggle)
yaz 5.37.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,568 kB
  • sloc: xml: 124,223; ansic: 73,221; sh: 5,738; tcl: 2,189; makefile: 1,274; yacc: 382
file content (10189 lines) | stat: -rw-r--r-- 381,663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
<?xml version="1.0" standalone="no"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
    "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
[
     <!ENTITY % local SYSTEM "local.ent">
     %local;
     <!ENTITY % entities SYSTEM "entities.ent">
     %entities;
     <!ENTITY % idcommon SYSTEM "common/common.ent">
     %idcommon;
]>
<book>
 <bookinfo>
  <title>YAZ User&apos;s Guide and Reference</title>
  <authorgroup>
   <author><firstname>Sebastian</firstname><surname>Hammer</surname></author>
   <author><firstname>Adam</firstname><surname>Dickmeiss</surname></author>
   <author><firstname>Mike</firstname><surname>Taylor</surname></author>
   <author><firstname>Heikki</firstname><surname>Levanto</surname></author>
   <author><firstname>Dennis</firstname><surname>Schafroth</surname></author>
   <author><firstname>Jakub</firstname><surname>Skoczen</surname></author>
  </authorgroup>
  <releaseinfo>&version;</releaseinfo>
  <copyright>
   <year>&copyright-year;</year>
   <holder>Index Data</holder>
  </copyright>
  <abstract>
   <simpara>
    This document is the programmer's guide and reference to the &yaz;
    package version &version;. &yaz; is a compact toolkit that provides
    access to the Z39.50 and SRU/Solr protocols, as well as a set of
    higher-level tools for implementing the server and client
    roles, respectively.
    The documentation can be used on its own, or as a reference when
    looking at the example applications provided with the package.
   </simpara>
   <simpara>
    <inlinemediaobject>
     <imageobject>
      <imagedata fileref="common/id.png" format="PNG"/>
     </imageobject>
     <imageobject>
      <imagedata fileref="common/id.eps" format="EPS"/>
     </imageobject>
    </inlinemediaobject>
   </simpara></abstract>
 </bookinfo>
 <chapter id="introduction">
  <title>Introduction</title>
  <para>
   &yaz; is a C/C++ library for information retrieval applications
   using the Z39.50/SRU/Solr protocols for information retrieval.
  </para>
  <para>
   Properties of &yaz;:
   <itemizedlist>
    <listitem>
     <para>
      Complete
      <ulink url="&url.z39.50;">Z39.50</ulink> version 3 support.
      Amendments and Z39.50-2002 revision is supported.
    </para>
    </listitem>
    <listitem>
     <para>
      Supports
      <ulink url="&url.sru;">SRU GET/POST/SOAP</ulink>
      version 1.1, 1.2 and 2.0 (over HTTP and HTTPS).
    </para>
    </listitem>
    <listitem>
     <para>
      Includes BER encoders/decoders for the
      <ulink url="&url.ill;">ISO ILL</ulink>
      protocol.
    </para>
    </listitem>
    <listitem>
     <para>
      Supports
      <ulink url="&url.solr;">Apache Solr</ulink> Web Service version 1.4.x
      (client side only)
     </para>
    </listitem>
    <listitem>
     <para>
      Supports the following transports: BER over TCP/IP
      (<ulink url="&url.ber.over.tcpip;">RFC1729</ulink>),
      BER over Unix local socket, and
      <ulink url="&url.http.1.1;">HTTP 1.1</ulink>.
    </para>
    </listitem>
    <listitem>
     <para>
      Secure Socket Layer support using
      <ulink url="&url.gnutls;">GnuTLS</ulink>.
      If enabled, &yaz; uses HTTPS transport (for SOAP) or
      "Secure BER" (for Z39.50).
     </para>
    </listitem>
    <listitem>
     <para>
      Offers
      <ulink url="&url.zoom;">ZOOM</ulink> C API implementing
      Z39.50, SRU and Solr Web Service.
    </para>
    </listitem>
    <listitem>
     <para>
      The &yaz; library offers a set of useful utilities
      related to the protocols, such as MARC (ISO2709) parser,
      CCL (ISO8777) parser,
      <ulink url="&url.cql;">CQL</ulink>
      parser, memory management routines, character set conversion.
     </para>
    </listitem>
    <listitem>
     <para>
      Portable code. &yaz; compiles out-of-the box on most Unixes and
      on Windows using Microsoft Visual C++.
     </para>
    </listitem>
    <listitem>
     <para>
      Fast operation. The C based BER encoders/decoders as well
      as the server component of &yaz; is very fast.
    </para>
    </listitem>
    <listitem>
     <para>
      Liberal license that allows for commercial use of &yaz;.
     </para>
    </listitem>
   </itemizedlist>
  </para>

  <sect1 id="introduction.reading">
   <title>Reading this Manual</title>
   <para>
    Most implementors only need to read a fraction of the
    material in this manual, so a quick walk-through of the chapters
    is in order.
   </para>
   <itemizedlist>
    <listitem>
     <para>
      <xref linkend="installation"/> contains installation
      instructions for &yaz;. You don't need to read this
      if you expect to download &yaz; binaries.
      However, the chapter contains information about how
      to make <emphasis>your</emphasis> application link
      with &yaz;.
     </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="zoom"/> describes the ZOOM API of &yaz;.
      This is definitely worth reading if you wish to develop a Z39.50/SRU
      client.
     </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="server"/> describes the generic front-end server
      and explains how to develop server Z39.50/SRU applications for &yaz;.
      Obviously worth reading if you're to develop a server.
    </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="yaz-client"/> describes how to use the &yaz; Z39.50
      client. If you're a developer and wish to test your server
      or a server from another party, you might find this chapter
      useful.
    </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="asn"/> documents the most commonly used Z39.50
      C data structures offered by the &yaz; API. Client
      developers using ZOOM and non-Z39.50 implementors may skip this.
     </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="soap"/> describes how SRU and SOAP is used
      in &yaz;. Only if you're developing SRU applications
      this section is a must.
     </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="tools"/> contains sections for the various
      tools offered by &yaz;. Scan through the material quickly
      and see what's relevant to you! SRU implementors
      might find the <link linkend="cql">CQL</link> section
      particularly useful.
     </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="odr"/> goes through the details of the
      ODR module which is the work horse that encodes and decodes
      BER packages. Implementors using ZOOM only, do <emphasis>not</emphasis>
      need to read this.
      Most other Z39.50 implementors only need to read the first two
      sections (<xref linkend="odr.introduction"/> and
      <xref linkend="odr.use"/>).
     </para>
    </listitem>
    <listitem>
     <para>
      <xref linkend="comstack"/> describes the network layer module
      COMSTACK. Implementors using ZOOM or the generic front-end server
      may skip this. Others, presumably, handling client/server
     communication on their own should read this.
     </para>
    </listitem>
   </itemizedlist>
  </sect1>
  <sect1 id="introduction.api">
   <title>The API</title>
   <para>
    The <ulink url="&url.yaz;">&yaz;</ulink>
    toolkit offers several different levels of access to the
    <ulink url="&url.z39.50;">ISO23950/Z39.50</ulink>,
    <ulink url="&url.ill;">ILL</ulink> and
    <ulink url="&url.sru;">SRU</ulink>
    protocols.
    The level that you need to use depends on your requirements, and
    the role (server or client) that you want to implement.
    If you're developing a client application you should consider the
    <link linkend="zoom">ZOOM</link> API.
    It is, by far, the easiest way to develop clients in C.
    Server implementors should consider the
    <link linkend="server">generic front-end server</link>.
    None of those high-level APIs support the whole protocol, but
    they do include most facilities used in existing Z39.50 applications.
   </para>
   <para>
    If you're using 'exotic' functionality (meaning anything not included in
    the high-level APIs), developing non-standard extensions to Z39.50 or
    you're going to develop an ILL application, you'll have to learn the lower
    level APIs of &yaz;.
   </para>
   <para>
    The YAZ toolkit modules are shown in figure <xref linkend="yaz.layer"/>.
   </para>
   <figure id="yaz.layer">
    <title>YAZ layers</title>
    <mediaobject>
     <imageobject>
      <imagedata fileref="apilayer.png" format="PNG"/>
     </imageobject>
     <imageobject>
      <imagedata fileref="apilayer.eps" format="EPS"/>
     </imageobject>
    </mediaobject>
   </figure>
   <para>
    There are four layers.
    <itemizedlist>
     <listitem>
      <para>A client or server application (or both).
       This layer includes ZOOM and the generic front-end server.
      </para>
     </listitem>
     <listitem>
      <para>
       The second layer provides a C representation of the
       protocol units (packages) for Z39.50 ASN.1, ILL ASN.1,
       SRU.
      </para>
     </listitem>
     <listitem>
      <para>
       The third layer encodes and decodes protocol data units to
       simple packages (buffer with certain length). The &odr; module
       encodes and decodes BER whereas the HTTP modules encodes and
       decodes HTTP requests/responses.
      </para>
     </listitem>
     <listitem>
      <para>
       The lowest layer is &comstack; which exchanges the encoded packages
       with a peer process over a network.
      </para>
     </listitem>
    </itemizedlist>
   </para>
   <para>
    The &asn; module represents the ASN.1 definition of
    the Z39.50 protocol. It establishes a set of type and
    structure definitions, with one structure for each of the top-level
    PDUs, and one structure or type for each of the contained ASN.1 types.
    For primitive types, or other types that are defined by the ASN.1
    standard itself (such as the EXTERNAL type), the C representation is
    provided by the &odr; (Open Data Representation) subsystem.
  </para>
   <para>
     &odr; is a basic mechanism for representing an
    ASN.1 type in the C programming language, and for implementing BER
    encoders and decoders for values of that type. The types defined in
    the &asn; module generally have the prefix <literal>Z_</literal>, and
    a suffix corresponding to the name of the type in the ASN.1
    specification of the protocol (generally Z39.50-1995). In the case of
    base types (those originating in the ASN.1 standard itself), the prefix
    <literal>Odr_</literal> is sometimes seen. Either way, look for
    the actual definition in either <filename>z-core.h</filename> (for the types
    from the protocol), <filename>odr.h</filename> (for the primitive ASN.1
    types).
    The &asn; library also provides functions (which are, in turn,
    defined using &odr; primitives) for encoding and decoding data values.
    Their general form is
    <funcsynopsis>
     <funcprototype><funcdef>int <function>z_<replaceable>xxx</replaceable></function></funcdef>
      <paramdef>ODR <parameter>o</parameter></paramdef>
      <paramdef>Z_<replaceable>xxx</replaceable> **<parameter>p</parameter></paramdef>
      <paramdef>int <parameter>optional</parameter></paramdef>
      <paramdef>const char *<parameter>name</parameter></paramdef>
     </funcprototype>
    </funcsynopsis>
    (note the lower-case &quot;z&quot; in the function name)
   </para>
   <note>
    <para>
     If you are using the premade definitions of the &asn; module, and you
     are not adding a new protocol of your own, the only parts of &odr; that you
     need to worry about are documented in
     <xref linkend="odr.use"/>.
    </para>
   </note>
   <para>
    When you have created a BER-encoded buffer, you can use the &comstack;
    subsystem to transmit (or receive) data over the network. The &comstack;
    module provides simple functions for establishing a connection
    (passively or actively, depending on the role of your application),
    and for exchanging BER-encoded PDUs over that connection. When you
    create a connection endpoint, you need to specify what transport to
    use (TCP/IP, SSL or UNIX sockets).
    For the remainder of the connection's lifetime, you don't have
    to worry about the underlying transport protocol at all - the &comstack;
    will ensure that the correct mechanism is used.
   </para>
   <para>
    We call the combined interfaces to &odr;, &asn;, and &comstack; the service
    level API. It's the API that most closely models the Z39.50
    service/protocol definition, and it provides unlimited access to all
    fields and facilities of the protocol definitions.
   </para>
   <para>
    The reason that the &yaz; service-level API is a conglomerate of the
    APIs from three different sub-modules is twofold. First, we wanted to allow
    the user a choice of different options for each major task. For instance,
    if you don't like the protocol API provided by &odr;/&asn;, you
    can use SNACC or BERUtils instead, and still have the benefits of the
    transparent transport approach of the &comstack; module. Secondly,
    we realize that you may have to fit the toolkit into an existing
    event-processing structure, in a way that is incompatible with
    the &comstack; interface or some other part of &yaz;.
   </para>
  </sect1>
 </chapter>
 <chapter id="installation">
  <title>Compilation and Installation</title>
  <sect1 id="installation-introduction">
   <title>Introduction</title>
   <para>
    The latest version of the software will generally be found at:
   </para>
   <para>
    <ulink url="&url.yaz.download;"/>
   </para>
   <para>
    We have tried our best to keep the software portable, and on many
    platforms, you should be able to compile everything with little or
    no changes.
   </para>
   <para>
    The software is regularly tested on
    <ulink url="&url.debian;">Debian GNU/Linux</ulink>,
    <ulink url="&url.centos;">CentOS</ulink>,
    <ulink url="&url.ubuntu;">Ubuntu Linux</ulink>,
    <ulink url="&url.freebsd;">FreeBSD (i386)</ulink>,
    <ulink url="&url.macosx;">MAC OSX</ulink>,
    Windows 10.
   </para>
   <para>
    Some versions have be known to work on Windows XP, Solaris, HP/UX,
    DEC Unix, <ulink url="&url.netbsd;">NetBSD</ulink>,
    <ulink url="&url.openbsd;">OpenBSD</ulink>,
    IBM AIX,
    Data General DG/UX (with some CFLAGS tinkering),
    SGI/IRIX, DDE Supermax, Apple Macintosh (using the Codewarrior programming
    environment and the GUSI socket libraries),
    IBM AS/400 .
   </para>
   <para>
    If you move the software to other platforms, we'd be grateful if you'd
    let us know about it. If you run into difficulties, we will try to help
    if we can, and if you solve the problems, we would be happy to include
    your fixes in the next release. So far, we have mostly avoided
    <literal>#ifdefs</literal> for individual platforms, and we'd
    like to keep it that way as far as it makes sense.
   </para>
   <para>
    Use <ulink url="https://github.com/indexdata/yaz/discussions">
    GitHub Discussions</ulink> for questions and discussions about &yaz;.
    General questions and problems can be directed to
    <ulink url="&url.yaz.mail;"/>.
   </para>
  </sect1>
  <sect1 id="installation.unix"><title>UNIX/macOS</title>
   <para>
    We provide
    <ulink url="&url.debian;">Debian GNU/Linux</ulink> (i386 and amd64),
    <ulink url="&url.ubuntu;">Ubuntu</ulink> (i386 and amd64)
    and
    <ulink url="&url.centos;">CentOS</ulink> (amd64 only) packages for &yaz;.
    You should be able to create packages for other CPUs by building
    them from the source package.
   </para>
   <para>
    YAZ is also part of several packages repositories. Some of them are
   </para>
   <itemizedlist>
    <listitem>
     <para>
      Solaris CSW: <ulink url="http://www.opencsw.org/packages/yaz/"/>
     </para>
    </listitem>
    <listitem>
     <para>
      Solaris: <ulink url="http://unixpackages.com"/>
     </para>
    </listitem>
    <listitem>
     <para>
      FreeBSD: <ulink url="http://www.freshports.org/net/yaz"/>
     </para>
    </listitem>
    <listitem>
     <para>
      Debian: <ulink url="http://packages.debian.org/search?keywords=yaz"/>
     </para>
    </listitem>
    <listitem>
     <para>
      Ubuntu: <ulink url="https://launchpad.net/ubuntu/+source/yaz"/>
     </para>
    </listitem>
    <listitem>
     <para>
      NetBSD:
      <ulink url="http://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/net/yaz/README.html"/>
     </para>
    </listitem>
   </itemizedlist>
   <sect2 id="installation.source.unix">
    <title>Compiling from source on Unix</title>
    <para>
     You can choose to compile YAZ from official tar releases from
     <ulink url="&url.yaz.download;"/>
     or clone it via GitHub
     <ulink url="https://github.com/indexdata/yaz.git"/>.
    </para>
    <para>
     If you wish to use character set conversion facilities in &yaz; or if you
     are compiling &yaz; for use with Zebra, it is a good idea to ensure that
     the iconv library is installed. Some Unixes today already have it
     - if not, we suggest
     <ulink url="&url.libiconv;">GNU libiconv</ulink>.
    </para>
    <para>
     YAZ 3.0.16 and later includes a wrapper for the
     <ulink url="&url.icu;">ICU</ulink>
     (International Components for Unicode).
     In order to use this, the developer version of the ICU library
     must be available. ICU support is recommended for applications
     such as Pazpar2 and Zebra.
    </para>
    <para>
     The <ulink url="&url.libxslt;">libxslt</ulink>,
     <ulink url="&url.libxml2;">libxml2</ulink> libraries are required
     if &yaz; is to support SRU/Solr.
     These libraries are very portable and should compile out-of-the
     box on virtually all Unix platforms. It is available in binary
     forms for Linux and others.
    </para>
    <para>
     The GNU tools
     <ulink url="&url.autoconf;">Autoconf</ulink>,
     <ulink url="&url.automake;">Automake</ulink> and
     <ulink url="&url.libtool;">Libtool</ulink>
     are used to generate Makefiles and configure &yaz; for the system.
     You do <emphasis>not</emphasis> need these tools unless you're using the
     Git version of &yaz;.
    </para>
    <para>
     The CQL parser for &yaz; is built using
     GNU <ulink url="&url.bison;">Bison</ulink>.
     This tool is only needed if you're using the Git version of &yaz;.
    </para>
    <para>
     &yaz; includes a tiny ASN.1 compiler. This compiler is
     written in <ulink url="&url.tcl;">Tcl</ulink>.
     But as for Bison you do not need it unless you're using Git
     version of &yaz; or you're using the compiler to build your own codecs
     for private ASN.1.
    </para>
    <para>
     If you are checking out from Git, run:
     <screen>
      ./buildconf.sh
     </screen>
     This will create the <filename>configure</filename> script and Makefiles.
    </para>
    <para>
     The next step is always:
    </para>
    <screen>
     ./configure
    </screen>
    <para>
     The configure script attempts to use use the C compiler specified by
     the <literal>CC</literal> environment variable. If not set, GNU C will be
     used if it is available. The <literal>CFLAGS</literal> environment
     variable holds options to be passed to the C compiler. If you're using
     Bourne-compatible shell, you may pass something like this to use a
     particular C compiler with optimization enabled:
    </para>
    <screen>
     CC=/opt/ccs/bin/cc CFLAGS=-O ./configure
    </screen>
    <para>
     To customize &yaz;, the configure script also accepts a set of options.
     The most important are:
     <variablelist>
      <varlistentry>
       <term>
	<literal>--prefix</literal>=<replaceable>prefix</replaceable>
       </term>
       <listitem>
	<para>Specifies installation prefix for &yaz;. This is
	only needed if you run <literal>make install</literal> later to
	perform a "system" installation. The prefix is
	<literal>/usr/local</literal> if not specified.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
	<literal>--enable-tcpd</literal>
       </term>
       <listitem>
	<para>The front end server will be built using Wietse's
	<ulink url="&url.tcpwrapper;">TCP wrapper library</ulink>.
	It allows you to allow/deny clients depending on IP number.
	The TCP wrapper library is often used in GNU/Linux and
	BSD distributions.
	See
	<citerefentry>
	 <refentrytitle>hosts_access</refentrytitle>
	 <manvolnum>5</manvolnum>
	</citerefentry>
	and
	<citerefentry>
	 <refentrytitle>tcpd</refentrytitle>
	 <manvolnum>8</manvolnum>
	 </citerefentry>.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
	<literal>--enable-threads</literal>
       </term>
       <listitem>
	<para>&yaz; will be built using POSIX threads.
	Specifically, <constant>_REENTRANT</constant> will be defined during
	compilation.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
	<literal>--disable-shared</literal>
       </term>
       <listitem>
	<para>The make process will not create shared
	libraries (also known as shared objects <filename>.so</filename>).
	By default, shared libraries are created -
	equivalent to <literal>--enable-shared</literal>.
       </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
	<literal>--disable-shared</literal>
       </term>
       <listitem>
	<para>The make process will not create
	static libraries (<filename>.a</filename>).
	By default, static libraries are created -
	equivalent to <literal>--enable-static</literal>.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
        <literal>--with-iconv</literal>[=<replaceable>prefix</replaceable>]
       </term>
       <listitem>
	<para>Compile &yaz; with iconv library in directory
	<replaceable>prefix</replaceable>. By default configure will
	search for iconv on the system. Use this option if it
	doesn't find iconv. Alternatively,
	<literal>--without-iconv</literal>, can be used to force &yaz;
	not to use iconv.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
        <literal>--with-xslt</literal>[=<replaceable>prefix</replaceable>]
       </term>
       <listitem>
	<para>Compile &yaz; with
	<ulink url="&url.libxslt;">libxslt</ulink> in directory
	<replaceable>prefix</replaceable>.
	Use this option if you want XSLT and XML support.
	By default, configure will
	search for libxslt on the system. Use this option if
	libxslt is not found automatically. Alternatively,
	<literal>--without-xslt</literal>, can be used to force &yaz;
	not to use libxslt.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
        <literal>--with-xml2</literal>[=<replaceable>prefix</replaceable>]
       </term>
       <listitem>
	<para>Compile &yaz; with
	<ulink url="&url.libxml2;">libxml2</ulink> in directory
	<replaceable>prefix</replaceable>.
	Use this option if you want &yaz; to use XML and support SRU/Solr.
	By default, configure will
	search for libxml2 on the system. Use this option if
	libxml2 is not found automatically. Alternatively,
	<literal>--without-xml2</literal>, can be used to force &yaz;
	not to use libxml2.
	</para>
	<para>
	 Note that option <literal>--with-xslt</literal>
	 also enables libxml2.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
	<literal>--with-gnutls</literal>[=<replaceable>prefix</replaceable>]
       </term>
       <listitem>
	<para>&yaz; will be linked with the GNU TLS libraries and
	an SSL COMSTACK will be provided. By default configure enables
	SSL support for YAZ if the GNU TLS development libraries are found
	on the system.
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
        <literal>--with-icu</literal>[=<replaceable>prefix</replaceable>]
       </term>
       <listitem>
	<para>&yaz; will be linked the
	<ulink url="&url.icu;">ICU</ulink> library in the prefix if given.
	If prefix is not given, the libraries exposed by the script
	<application>icu-config</application> will be used if found.
	</para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term>
        <literal>--with-memcached</literal>
       </term>
       <listitem>
	<para>&yaz; will be linked with
	<ulink url="&url.libmemcached;">libMemcached</ulink> to allow
	for result-set caching for ZOOM.
	The prefix can not be given.
	Note that 0.40 of libmemcached is required.
       </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term>
        <literal>--with-redis</literal>
       </term>
       <listitem>
	<para>&yaz; will be linked with the hiredis C library
	to allow for result-set caching for ZOOM on a
	<ulink url="&url.redis;">redis</ulink> server.
	The prefix can not be given.
       </para>
       </listitem>
      </varlistentry>

     </variablelist>
    </para>
    <para>
     When configured, build the software by typing:
     <screen>
      make
     </screen>
    </para>
    <para>
     The following files are generated by the make process:
     <variablelist>
      <varlistentry>
       <term><filename>src/libyaz.la</filename></term>
       <listitem><para>
	Main &yaz; library. This is no ordinary library. It's
	a Libtool archive.
	By default, &yaz; creates a static library in
	<filename>lib/.libs/libyaz.a</filename>.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>src/libyaz_server.la</filename></term>
       <listitem><para>
         Generic Frontend server. This is an add-on for libyaz.la.
         Code in this library uses POSIX threads functions - if POSIX
         threads are available on the platform.
        </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>src/libyaz_icu.la</filename></term>
       <listitem><para>
	Functions that wrap the ICU library.
        </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>ztest/yaz-ztest</filename></term>
       <listitem><para>Test Z39.50 server.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>client/yaz-client</filename></term>
       <listitem><para>Z39.50 client for testing the protocol.
       See chapter <link linkend="yaz-client">
       YAZ client</link> for more information.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>util/yaz-config</filename></term>
       <listitem><para>A Bourne-shell script, generated by configure, that
       specifies how external applications should compile - and link with
       &yaz;.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>util/yaz-asncomp</filename></term>
       <listitem><para>The ASN.1 compiler for &yaz;. Requires the
       Tcl Shell, <application>tclsh</application>, in
       <literal>PATH</literal> to operate.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>util/yaz-iconv</filename></term>
       <listitem><para>This program converts data in one character set to
       another. This command exercises the YAZ character set
       conversion API.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>util/yaz-marcdump</filename></term>
       <listitem><para>This program parses ISO2709 encoded MARC records
       and prints them in line-format or XML.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>util/yaz-icu</filename></term>
       <listitem><para>This program exposes the ICU wrapper library if that
       is enabled for YAZ. Only if ICU is available this program is
       useful.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>util/yaz-url</filename></term>
       <listitem><para>This program is a simple HTTP page fetcher ala
       wget or curl.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>zoom/zoomsh</filename></term>
       <listitem><para>
	A simple shell implemented on top of the
	<link linkend="zoom">ZOOM</link> functions.
	The shell is a command line application that allows you to enter
	simple commands to perform ZOOM operations.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>zoom/zoomtst1</filename>,
       <filename>zoom/zoomtst2</filename>, ..</term>
       <listitem><para>
	Several small applications that demonstrate the ZOOM API.
       </para></listitem>
      </varlistentry>
     </variablelist>
    </para>
    <para>
     If you wish to install &yaz; in system directories
     <filename>/usr/local/bin</filename>,
     <filename>/usr/local/lib</filename> .. etc, you can type:
    </para>
    <screen>
     make install
    </screen>
    <para>
     You probably need to have root access in order to perform this.
     You must specify the <literal>--prefix</literal> option for configure if
     you wish to install &yaz; in other directories than the default
     <filename>/usr/local/</filename>.
    </para>
    <para>
     If you wish to perform an un-installation of &yaz;, use:
    </para>
    <screen>
     make uninstall
    </screen>
    <para>
     This will only work if you haven't reconfigured &yaz; (and therefore
     changed installation prefix). Note that uninstall will not
     remove directories created by make install, e.g.
     <filename>/usr/local/include/yaz</filename>.
    </para>
   </sect2>
   <sect2 id="installation.source.macos">
     <title>Compiling from source on macOS</title>
     <para>
       Install Apple's Xcode Command Line Tools (XCLT) package from <ulink url="https://developer.apple.com/">Apple Developer</ulink>
       which provides necessary tools for building C/C++ programs on macOS. You can also try to install it from the command line with:
       <screen>
         xcode-select --install
       </screen>
       Out of the box, XCLT is sufficient for compiling basic &yaz; from the source distribution tarball
       with XML support as it includes libxml2 and libxslt development headers.
     </para>
     <para>
       For ICU support, you can fetch Apple's source distribution from GitHub:
       <screen>
         git clone https://github.com/apple-oss-distributions/ICU.git
       </screen>
       and compile &yaz; with:
       <screen>
         export ICU_CPPFLAGS="-DYAZ_HAVE_ICU=1 -I../../ICU/icu/icu4c/source/common -I../../ICU/icu/icu4c/source/i18n"
         export ICU_LIBS=" -licucore"
         ./configure
         make
       </screen>
       For SSL support, &yaz; requires GnuTLS and cannot be compiled with LibreSSL/OpenSSL shipped with macOS (see below).
     </para>
     <para>
       If you are compiling &yaz; from a Git checkout, at the time of writing XCLT includes GNU Bison v2.3 which is too old
       to generate &yaz; sources. You can use e.g. <ulink url="https://brew.sh">Homebrew</ulink> to install a more recent version:
       <screen>
         brew install bison
       </screen>
       After installation make sure to put it on the path:
       <screen>
         export PATH="/opt/homebrew/opt/bison/bin:$PATH"
       </screen>
       Note: XCLT 15.4 fails to make  <code>gm4</code> available as <code>m4</code> which can cause a silent Bison failure, one
       way to fix it is:
       <screen>
         sudo ln -s /Library/Developer/CommandLineTools/usr/bin/gm4 \
           /Library/Developer/CommandLineTools/usr/bin/m4
       </screen>
       Additionally, you will need to install DocBook stylesheets to generate documentation:
       <screen>
         brew install docbook docbook-xsl
       </screen>
       per the caveats section (<code>brew info docbook</code>), for the compilation to find them, add:
       <screen>
         export XML_CATALOG_FILES="/opt/homebrew/etc/xml/catalog"
       </screen>
       To compile &yaz; with SSL support, install GnuTLS with:
       <screen>
         brew install gnutls
       </screen>
       Homebrew makes GnuTLS discoverable by pkg-config, so no additional flags are needed when configuring &yaz;.
       You may also want to compile &yaz; with Homebrew's ICU:
       <screen>
         brew install icu4c
       </screen>
       but make sure to add compiler flags before the configure stage, per the caveats section (<code>brew info icu4c</code>):
       <screen>
         export LDFLAGS="-L/opt/homebrew/opt/icu4c/lib"
         export CPPFLAGS="-I/opt/homebrew/opt/icu4c/include"
         export PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig"
       </screen>
       Additionally, if you want to compile &yaz; with a more recent version of libxml2 and libxslt,
       you can install them with Homebrew:
       <screen>
         brew install libxml2 libxslt
       </screen>
       and, again, make sure to add compiler flags, per the caveats section (<code>brew info libxml2</code>):
       <screen>
         export PATH="/opt/homebrew/opt/bison/bin:\
         /opt/homebrew/opt/libxml2/bin:\
         /opt/homebrew/opt/libxslt/bin:\
         $PATH"
         export LDFLAGS="-L/opt/homebrew/opt/libxml2/lib \
         -L/opt/homebrew/opt/libxslt/lib \
         -L/opt/homebrew/opt/icu4c/lib"
         export CPPFLAGS="-I/opt/homebrew/opt/libxml2/include \
         -I/opt/homebrew/opt/libxslt/include \
         -I/opt/homebrew/opt/icu4c/include"
         export PKG_CONFIG_PATH="/opt/homebrew/opt/libxml2/lib/pkgconfig:\
         /opt/homebrew/opt/libxslt/lib/pkgconfig:\
         /opt/homebrew/opt/icu4c/lib/pkgconfig"
       </screen>
       Then configure and conpile with:
       <screen>
         ./configure
         make
       </screen>
     </para>
   </sect2>
    <sect2 id="installation-linking-yaz-unix">
    <title>How to make apps using YAZ on UNIX</title>
    <para>
     This section describes how to compile - and link your own
     applications using the &yaz; toolkit.
     If you're used to Makefiles this shouldn't be hard. As for
     other libraries you have used before, you need to set a proper include
     path for your C/C++ compiler and specify the location of
     &yaz; libraries. You can do it by hand, but generally we suggest
     you use the <filename>yaz-config</filename> that is generated
     by <filename>configure</filename>. This is especially
     important if you're using the threaded version of &yaz; which
     require you to pass more options to your linker/compiler.
    </para>
    <para>
     The <filename>yaz-config</filename> script accepts command line
     options that makes the <filename>yaz-config</filename> script print
     options that you should use in your make process.
     The most important ones are:
     <literal>--cflags</literal>, <literal>--libs</literal>
     which prints C compiler flags, and linker flags respectively.
    </para>
    <para>
     A small and complete <literal>Makefile</literal> for a C
     application consisting of one source file,
     <filename>myprog.c</filename>, may look like this:
     <screen>
      YAZCONFIG=/usr/local/bin/yaz-config
      CFLAGS=`$(YAZCONFIG) --cflags`
      LIBS=`$(YAZCONFIG) --libs`
      myprog: myprog.o
         $(CC) $(CFLAGS) -o myprog myprog.o $(LIBS)
      </screen>
    </para>
    <para>
     The CFLAGS variable consists of a C compiler directive that will set
     the include path to the <emphasis>parent</emphasis> directory
     of <filename>yaz</filename>. That is, if &yaz; header files were
     installed in <filename>/usr/local/include/yaz</filename>,
     then include path is set to <filename>/usr/local/include</filename>.
     Therefore, in your applications you should use
     <screen>
      #include &lt;yaz/proto.h>
     </screen>
     and <emphasis>not</emphasis>
     <screen>
      #include &lt;proto.h>
     </screen>
    </para>
    <para>
     For Libtool users, the <filename>yaz-config</filename> script provides
     a different variant of option <literal>--libs</literal>, called
     <literal>--lalibs</literal> that returns the name of the
     Libtool archive(s) for &yaz; rather than the ordinary ones.
    </para>
    <para>
     For applications using the threaded version of &yaz;,
     specify <literal>threads</literal> after the
     other options. When <literal>threads</literal> is given,
     more flags and linker flags will be printed by
     <filename>yaz-config</filename>. If our previous example was
      using threads, you'd have to modify the lines that set
     <literal>CFLAGS</literal> and <literal>LIBS</literal> as
     follows:
     <screen>
      CFLAGS=`$(YAZCONFIG) --cflags threads`
      LIBS=`$(YAZCONFIG) --libs threads`
     </screen>
     There is no need specify POSIX thread libraries in your Makefile.
     The <literal>LIBS</literal> variable includes that as well.
    </para>
   </sect2>
  </sect1>
  <sect1 id="installation.win32">
   <title>Windows</title>
   <para>The easiest way to install YAZ on Windows is by downloading
   an installer from
   <ulink url="&url.yaz.download.win32;">
    Index Data's Windows support area
   </ulink>.
   The installer comes with source too - in case you wish to
   compile YAZ with different compiler options, etc.
   </para>

   <sect2 id="installation.win32.source">
    <title>Compiling from Source on Windows</title>
    <para>
     &yaz; is shipped with "makefiles" for the NMAKE tool that comes
     with <ulink url="&url.vstudio;">
     Microsoft Visual Studio</ulink>. It has been tested with
     Microsoft Visual Studio 2019 and 2022.
    </para>
    <para>
     Start a command prompt and switch the sub directory
     <filename>WIN</filename> where the file <filename>makefile</filename>
     is located. Customize the installation by editing the
     <filename>makefile</filename> file (for example by using notepad).
     The following summarizes the most important settings in that file:
     <variablelist>
      <varlistentry>
       <term><literal>DEBUG</literal></term>
       <listitem><para>
	If set to 1, the software is
	compiled with debugging libraries (code generation is
	multi-threaded debug DLL).
	If set to 0, the software is compiled with release libraries
	(code generation is multi-threaded DLL).
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>HAVE_TCL</literal>, <literal>TCL</literal></term>
       <listitem><para>
	If <literal>HAVE_TCL</literal> is set to 1, nmake will
	use the ASN.1 compiler (<ulink url="&url.tcl;">Tcl</ulink> based).
	You must set <literal>TCL</literal> to the full path of the Tcl
	interpreter. A Windows version of Tcl is part of
	<ulink url="&url.gitwindows;">Git for Windows</ulink>.
       </para>
       <para>
	If you do not have Tcl installed, set
	<literal>HAVE_TCL</literal> to 0.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>HAVE_BISON</literal>,
       <literal>BISON</literal></term>
       <listitem><para>
	If GNU Bison is present, you might set <literal>HAVE_BISON</literal>
	to 1 and specify the Bison executable in <literal>BISON</literal>.
	Bison is only required if you use the Git version of
	YAZ or if you modify the grammar for CQL
	(<filename>cql.y</filename>).
       </para>
       <para>
	A Windows version of GNU Bison can be fetched from here:
	<ulink
          url="&url.indexdata.support.windows;bison-2.4.1-setup.exe">
          Index Data's Windows support area
        </ulink>.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>HAVE_ICONV</literal>,
       <literal>ICONV_DIR</literal></term>
       <listitem><para>
	If <literal>HAVE_ICONV</literal> is set to 1, YAZ is compiled
	with iconv support. In this configuration, set
	<literal>ICONV_DIR</literal> to the iconv source directory.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>HAVE_LIBXML2</literal>,
       <literal>LIBXML2_DIR</literal></term>
       <listitem>
        <para>
         If <literal>HAVE_LIBXML2</literal> is set to 1, YAZ is compiled
         with SRU support. In this configuration, set
         <literal>LIBXML2_DIR</literal> to the
         <ulink url="&url.libxml2;">libxml2</ulink> source directory.
	</para>
	<para>
	 You can get pre-compiled Libxml2+Libxslt DLLs and headers from
	 <ulink url="&url.libxml2.download.windows;">here</ulink>.
	 Should you with to compile those libraries yourself, refer to
	 to <xref linkend="installation.windows.libxml2"/>
	</para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>HAVE_LIBXSLT</literal>,
       <literal>LIBXSLT_DIR</literal></term>
       <listitem>
        <para>
         If <literal>HAVE_LIBXSLT</literal> is set to 1, YAZ is compiled
         with XSLT support. In this configuration, set
         <literal>LIBXSLT_DIR</literal> to the
         <ulink url="&url.libxslt;">libxslt</ulink> source directory.
        </para>
	<note>
	 <para>
	  libxslt depends on libxml2.
	 </para>
	</note>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>HAVE_ICU</literal>,
       <literal>ICU_DIR</literal></term>
       <listitem>
        <para>
         If <literal>HAVE_ICU</literal> is set to 1, YAZ is compiled
         with <ulink url="&url.icu;">ICU</ulink> support.
	 In this configuration, set
         <literal>ICU_DIR</literal> to the
         <ulink url="&url.icu;">ICU</ulink> source directory.
        </para>
        <para>
         Pre-compiled ICU libraries for various versions of Visual Studio
         can be found
         <ulink url="http://www.npcglib.org/~stathis/blog/precompiled-icu/">
          here
         </ulink> or from Index Data's <ulink
          url="&url.indexdata.support.windows;">Windows support site</ulink>.
        </para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
    <para>
     When satisfied with the settings in the makefile, type
     <screen>
      nmake
     </screen>
    </para>
    <note>
     <para>
      If the <filename>nmake</filename> command is not found on your system
      you probably haven't defined the environment variables required to
      use that tool. To fix that, find and run the batch file
      <filename>vcvarsall.bat</filename>. You need to run it from within
      the command prompt or set the environment variables "globally";
      otherwise it doesn't work.
     </para>
    </note>
    <para>
     If you wish to recompile &yaz; - for example if you modify
     settings in the <filename>makefile</filename> you can delete
     object files, etc by running.
     <screen>
      nmake clean
     </screen>
    </para>
    <para>
     The following files are generated upon successful compilation:
     <variablelist>
      <varlistentry>
       <term><filename>bin/yaz&soversion;.dll</filename> /
       <filename>bin/yaz&soversion;d.dll</filename></term>
       <listitem><para>
	&yaz; Release/Debug DLL.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>lib/yaz&soversion;.lib</filename> /
       <filename>lib/yaz&soversion;d.lib</filename></term>
       <listitem><para>
	Import library for <filename>yaz&soversion;.dll</filename> /
	<filename>yaz&soversion;d.dll</filename>.
      </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>bin/yaz_cond&soversion;.dll</filename> /
       <filename>bin/yaz_cond&soversion;d.dll</filename></term>
       <listitem><para>
	Release/Debug DLL for condition variable utilities (condvar.c).
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>lib/yaz_cond&soversion;.lib</filename> /
       <filename>lib/yaz_cond&soversion;d.lib</filename></term>
       <listitem><para>
	Import library for <filename>yaz_cond&soversion;.dll</filename> /
	<filename>yaz_cond&soversion;d.dll</filename>.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>bin/yaz_icu&soversion;.dll</filename> /
       <filename>bin/yaz_icu&soversion;d.dll</filename></term>
       <listitem><para>
	Release/Debug DLL for the ICU wrapper utility.
	Only build if HAVE_ICU is 1.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>lib/yaz_icu&soversion;.lib</filename> /
       <filename>lib/yaz_icu&soversion;d.lib</filename></term>
       <listitem><para>
	Import library for <filename>yaz_icu&soversion;.dll</filename> /
	<filename>yaz_icu&soversion;d.dll</filename>.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>bin/yaz-ztest.exe</filename></term>
       <listitem><para>
	Z39.50 multi-threaded test/example server. It's a WIN32
	console application.
      </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>bin/yaz-client.exe</filename></term>
       <listitem><para>
	&yaz; Z39.50 client application. It's a WIN32 console application.
	See chapter <link linkend="yaz-client">YAZ client</link> for more
	information.
      </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>bin/yaz-icu.exe</filename></term>
       <listitem><para>This program exposes the ICU wrapper library if that
       is enabled for YAZ. Only if ICU is available this program is
       built.
      </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>bin/zoomsh.exe</filename></term>
       <listitem><para>
	Simple console application implemented on top of the
	<link linkend="zoom">ZOOM</link> functions.
	The application is a command line shell that allows you to enter
	simple commands to perform ZOOM operations.
      </para></listitem>
      </varlistentry>
      <varlistentry>
       <term><filename>bin/zoomtst1.exe</filename>,
       <filename>bin/zoomtst2.exe</filename>, ..</term>
       <listitem><para>
	Several small applications that demonstrate the ZOOM API.
      </para></listitem>
      </varlistentry>
     </variablelist>
    </para>
   </sect2>

   <sect2 id="installation-linking-yaz-win32">
    <title>How to make apps using YAZ on Windows</title>
    <para>
     This section will go though the process of linking your Windows
     applications with &yaz;.
    </para>
    <para>
     Some people are confused by the fact that we use the nmake
     tool to build &yaz;. They think they have to do that too - in order
     to make their Windows applications work with &yaz;. The good news is that
     you don't have to. You can use the integrated environment of
     Visual Studio if desired for your own application.
    </para>
    <para>
     When setting up a project or Makefile you have to set the following:
     <variablelist>
      <varlistentry>
       <term>include path</term>
       <listitem><para>
	Set it to the <filename>include</filename> directory of &yaz;.
        </para></listitem>
      </varlistentry>
      <varlistentry>
       <term>import library <filename>yaz&soversion;.lib</filename></term>
       <listitem><para>
	You must link with this library. It's located in the
	sub directory <filename>lib</filename> of &yaz;.
	If you want to link with the debug version of &yaz;, you must
	link against <filename>yaz&soversion;d.lib</filename> instead.
       </para></listitem>
      </varlistentry>
      <varlistentry>
       <term>dynamic link library
       <filename>yaz&soversion;.dll</filename>
       </term>
       <listitem><para>
	This DLL must be in your execution path when you invoke
	your application. Specifically, you should distribute this
	DLL with your application.
       </para></listitem>
      </varlistentry>
     </variablelist>
    </para>
   </sect2>

   <sect2 id="installation.windows.libxml2">
    <title>Compiling Libxml2 and Libxslt on windows</title>
    <para>
     Download libxml2 and Libxslt source and unpack it.
     In the example below we install  Libxml2 2.9.2 and Libxslt 1.1.28
     for 32-bit, so we  use the destination directories
     libxml2.2.9.2.win32 and libxslt-1.1.28.win32 to reflect both
     version and architecture.
     <screen>
      cd win32
      cscript configure.js prefix=c:\libxml2-2.9.2.win32 iconv=no
      nmake
      nmake install
     </screen>
    </para>
    <note>
     <para>
      There's an error in <filename>configure.js</filename> for Libxml2 2.9.2.
      Line 17 should be assigned to <filename>configure.ac</filename>
      rather than <filename>configure.in</filename>.
     </para>
    </note>
    <para>
     For Libxslt it is similar. We must ensure that compilation of
     Libxslt links against the already installed libxml2.
     <screen>
      cd win32
      cscript configure.js prefix=c:\libxslt-1.1.28.win32 iconv=no \
          lib=c:\libxml2-2.9.2.win32\lib \
	  include=c:\libxml2-2.9.2.win32\include\libxml2
      nmake
      nmake install
     </screen>
    </para>
   </sect2>

  </sect1>
 </chapter>
 <!--
     ### Still to document:
     ZOOM_connection_errcode(c)
     ZOOM_connection_errmsg(c)
     ZOOM_connection_addinfo(c)
     ZOOM_connection_addinfo(c)
     ZOOM_connection_diagset(c);
     ZOOM_connection_save_apdu_wrbuf
     ZOOM_diag_str(error)
     ZOOM_resultset_record_immediate(s, pos)
     ZOOM_resultset_cache_reset(r)
     ZOOM_options_set_callback(opt, function, handle)
     ZOOM_options_create_with_parent2(parent1, parent2)
     ZOOM_options_getl(opt, name, len)
     ZOOM_options_setl(opt, name, value, len)
     ZOOM_options_get_bool(opt, name, defa)
     ZOOM_options_get_int(opt, name, defa)
     ZOOM_options_set_int(opt, name, value)
 -->
 <chapter id="zoom">
  <title>ZOOM</title>
  <para>
   &zoom; is an acronym for 'Z39.50 Object-Orientation Model' and is
   an initiative started by Mike Taylor (Mike is from the UK, which
   explains the peculiar name of the model). The goal of &zoom; is to
   provide a common Z39.50 client API not bound to a particular
   programming language or toolkit.
  </para>
  <para>
   From YAZ version 2.1.12, <ulink url="&url.sru;">SRU</ulink> is supported.
   You can make SRU ZOOM connections by specifying scheme
   <literal>http://</literal> for the hostname for a connection.
   The dialect of SRU used is specified by the value of the
   connection's <literal>sru</literal> option, which may be SRU over
   HTTP GET (<literal>get</literal>),
   SRU over HTTP POST (<literal>post</literal>), (SRU over
   SOAP) (<literal>soap</literal>) or <literal>solr</literal>
   (<ulink url="&url.solr;">Solr</ulink> Web Service).
   Using the facility for embedding options in target strings, a
   connection can be forced to use SRU rather the SRW (the default) by
   prefixing the target string with <literal>sru=get,</literal>, like this:
   <literal>sru=get,http://sru.miketaylor.org.uk:80/sru.pl</literal>
  </para>
  <para>
   <ulink url="&url.solr;">Solr</ulink>  protocol support was added to
   YAZ in version 4.1.0, as a dialect of a SRU protocol, since both are
   HTTP based protocols.
  </para>
  <para>
   The lack of a simple Z39.50 client API for &yaz; has become more
   and more apparent over time. So when the first &zoom; specification
   became available,
   an implementation for &yaz; was quickly developed. For the first time, it is
   now as easy (or easier!) to develop clients as it is to develop
   servers with &yaz;. This
   chapter describes the &zoom; C binding. Before going further, please
   reconsider whether C is the right programming language for the job.
   There are other language bindings available for &yaz;, and still
   more
   are in active development. See the
   <ulink url="&url.zoom;">ZOOM web-site</ulink> for
   more information.
  </para>
  <para>
   In order to fully understand this chapter you should read and
   try the example programs <literal>zoomtst1.c</literal>,
   <literal>zoomtst2.c</literal>, .. in the <literal>zoom</literal>
   directory.
  </para>
  <para>
   The C language misses features found in object oriented languages
   such as C++, Java, etc. For example, you'll have to manually,
   destroy all objects you create, even though you may think of them as
   temporary. Most objects have a <literal>_create</literal> - and a
   <literal>_destroy</literal> variant.
   All objects are in fact pointers to internal stuff, but you don't see
   that because of typedefs. All destroy methods should gracefully ignore a
   <literal>NULL</literal> pointer.
  </para>
  <para>
   In each of the sections below you'll find a sub section called
   protocol behavior, that describes how the API maps to the Z39.50
   protocol.
  </para>
  <sect1 id="zoom-connections">
   <title>Connections</title>
   <para>The Connection object is a session with a target.
   </para>
   <synopsis>
    #include &lt;yaz/zoom.h>

    ZOOM_connection ZOOM_connection_new(const char *host, int portnum);

    ZOOM_connection ZOOM_connection_create(ZOOM_options options);

    void ZOOM_connection_connect(ZOOM_connection c, const char *host,
                                 int portnum);
    void ZOOM_connection_destroy(ZOOM_connection c);
   </synopsis>
   <para>
    Connection objects are created with either function
    <function>ZOOM_connection_new</function> or
    <function>ZOOM_connection_create</function>.
    The former creates and automatically attempts to establish a network
    connection with the target. The latter doesn't establish
    a connection immediately, thus allowing you to specify options
    before establishing network connection using the function
    <function>ZOOM_connection_connect</function>.
    If the port number, <literal>portnum</literal>, is zero, the
    <literal>host</literal> is consulted for a port specification.
    If no port is given, 210 is used. A colon denotes the beginning of
    a port number in the host string. If the host string includes a
    slash, the following part specifies a database for the connection.
   </para>
   <para>
    You can prefix the host with a scheme followed by colon. The
    default scheme is <literal>tcp</literal> (Z39.50 protocol).
    The scheme <literal>http</literal> selects SRU/SOAP over HTTP by default,
    but can be changed with option <link linkend="sru-option">sru</link>.
   </para>
   <para>
    You can prefix the scheme-qualified host-string with one or more
    comma-separated
    <literal><parameter>key</parameter>=<parameter>value</parameter></literal>
    sequences, each of which represents an option to be set into the
    connection structure <emphasis>before</emphasis> the
    protocol-level connection is forged and the initialization
    handshake takes place.  This facility can be used to provide
    authentication credentials, as in host-strings such as:
    <literal>user=admin,password=halfAm4n,tcp:localhost:8017/db</literal>
   </para>
   <para>
    Connection objects should be destroyed using the function
    <function>ZOOM_connection_destroy</function>.
   </para>
   <synopsis>
    void ZOOM_connection_option_set(ZOOM_connection c,
                                    const char *key, const char *val);

    void ZOOM_connection_option_setl(ZOOM_connection c,
                                     const char *key,
                                     const char *val, int len);

    const char *ZOOM_connection_option_get(ZOOM_connection c,
                                           const char *key);
    const char *ZOOM_connection_option_getl(ZOOM_connection c,
                                            const char *key,
                                            int *lenp);
   </synopsis>
   <para>
    The functions <function>ZOOM_connection_option_set</function> and
    <function>ZOOM_connection_option_setl</function> allows you to
    set an option given by <parameter>key</parameter> to the value
    <parameter>value</parameter> for the connection.
    For <function>ZOOM_connection_option_set</function>, the
    value is assumed to be a 0-terminated string. Function
    <function>ZOOM_connection_option_setl</function> specifies a
    value of a certain size (len).
   </para>
   <para>
    Functions <function>ZOOM_connection_option_get</function> and
    <function>ZOOM_connection_option_getl</function> returns
    the value for an option given by <parameter>key</parameter>.
   </para>
   <table id="zoom-connection-options" frame="top">
    <title>ZOOM Connection Options</title>
    <tgroup cols="3">
     <colspec colwidth="4*" colname="name"></colspec>
     <colspec colwidth="7*" colname="description"></colspec>
     <colspec colwidth="3*" colname="default"></colspec>
     <thead>
      <row>
       <entry>Option</entry>
       <entry>Description</entry>
       <entry>Default</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
       implementationName</entry><entry>Name of your client
      </entry><entry>none</entry></row>
      <row><entry>
       user</entry><entry>Authentication user name
      </entry><entry>none</entry></row>
      <row><entry>
       group</entry><entry>Authentication group name
      </entry><entry>none</entry></row>
      <row><entry>
       password</entry><entry>Authentication password.
      </entry><entry>none</entry></row>
      <row><entry>
       authenticationMode</entry><entry>How authentication is encoded.
      </entry><entry>basic</entry></row>
      <row><entry>
       host</entry><entry>Target host. This setting is "read-only".
       It's automatically set internally when connecting to a target.
      </entry><entry>none</entry></row>
      <row><entry>
       proxy</entry><entry>Proxy host. If set, the logical host
       is encoded in the otherInfo area of the Z39.50 Init PDU
       with OID 1.2.840.10003.10.1000.81.1.
      </entry><entry>none</entry></row>
      <row><entry>
       clientIP</entry><entry>Client IP. If set, is
       encoded in the otherInfo area of a Z39.50 PDU with OID
       1.2.840.10003.10.1000.81.3. Holds the original IP addresses
       of a client. Is used if ZOOM is used in a gateway of some sort.
      </entry><entry>none</entry></row>
      <row><entry>
       timeout</entry><entry>Idle timeout which specifies how long
       ZOOM will wait for network I/O before giving up. Thus, the actual
       waiting time might be longer than this value if the target makes
       a chunked response and the time between each chunk arrive is
       less this value. For the connect+init, this is the time
       ZOOM will wait until receiving first byte from Init response.
      </entry><entry>30</entry></row>
      <row><entry>
       async</entry><entry>If true (1) the connection operates in
       asynchronous operation which means that all calls are non-blocking
       except
       <link linkend="zoom.events"><function>ZOOM_event</function></link>.
      </entry><entry>0</entry></row>
      <row><entry>
       maximumRecordSize</entry><entry> Maximum size of single record.
      </entry><entry>1 MB</entry></row>
      <row><entry>
       preferredMessageSize</entry><entry> Maximum size of multiple records.
      </entry><entry>1 MB</entry></row>
      <row><entry>
       lang</entry><entry> Language for negotiation.
      </entry><entry>none</entry></row>
      <row><entry>
       charset</entry><entry> Character set for negotiation.
      </entry><entry>none</entry></row>
      <row><entry>rpnCharset</entry><entry> Client-side character conversion for RPN queries and scan terms.
      The input terms are converted from UTF-8 to the character set of rpnCharset.
      </entry><entry>none (no conversion)</entry></row>
      <row><entry>
       serverImplementationId</entry><entry>
       Implementation ID of server.  (The old targetImplementationId
       option is also supported for the benefit of old applications.)
      </entry><entry>none</entry></row>
      <row><entry>
       targetImplementationName</entry><entry>
       Implementation Name of server.  (The old
       targetImplementationName option is also supported for the
       benefit of old applications.)
      </entry><entry>none</entry></row>
      <row><entry>
       serverImplementationVersion</entry><entry>
       Implementation Version of server.  (The old
       targetImplementationVersion option is also supported for the
       benefit of old applications.)
      </entry><entry>none</entry></row>
      <row><entry>
       databaseName</entry><entry>One or more database names
       separated by character plus (<literal>+</literal>), which is to
       be used by subsequent search requests on this Connection.
      </entry><entry>Default</entry></row>
      <row><entry>
       piggyback</entry><entry>True (1) if piggyback should be
       used in searches; false (0) if not.
      </entry><entry>1</entry></row>
      <row><entry>
       smallSetUpperBound</entry><entry>If hits is less than or equal to this
       value, then target will return all records using small element set name
      </entry><entry>0</entry></row>
      <row><entry>
       largeSetLowerBound</entry><entry>If hits is greater than this
       value, the target will return no records.
      </entry><entry>1</entry></row>
      <row><entry>
       mediumSetPresentNumber</entry><entry>This value represents
       the number of records to be returned as part of a search when
       hits is less than or equal to large set lower bound and if hits
       is greater than small set upper bound.
      </entry><entry>0</entry></row>
      <row><entry>
       smallSetElementSetName</entry><entry>
       The element set name to be used for small result sets.
      </entry><entry>none</entry></row>
      <row><entry>
       mediumSetElementSetName</entry><entry>
       The element set name to be used for medium-sized result sets.
      </entry><entry>none</entry></row>
      <row><entry>
       init_opt_search, init_opt_present, init_opt_delSet, etc.</entry><entry>
       After a successful Init, these options may be interrogated to
       discover whether the server claims to support the specified
       operations.
       </entry><entry>none</entry>
      </row>
      <row>
       <entry id="sru-option">sru</entry><entry> SRU/Solr transport
       type. Must be either <literal>soap</literal>,
       <literal>get</literal>, <literal>post</literal>, or
       <literal>solr</literal>.
       </entry><entry><literal>soap</literal> if scheme is already
       <literal>http</literal>; ignored otherwise</entry>
      </row>
      <row><entry>
       sru_version</entry><entry>
       SRU/SRW version. Should be <literal>1.1</literal>, or
       <literal>1.2</literal>. This is, prior to connect, the version
       to offer (highest version). And following connect (in fact
       first operation), holds the negotiated version with the server
       (same or lower version).
      </entry><entry>1.2</entry></row>
      <row id="zoom.extraArgs.option"><entry>
       extraArgs</entry><entry>
       Extra arguments for SRU/Solr URLs. The value must be
       URL encoded already.
       </entry><entry></entry>
      </row>
      <row id="zoom.facets.option"><entry>
       facets</entry><entry>
       Requested or recommended facets may be given before a search is sent.
       The value of this setting is described in <xref linkend="facets"/>
       For inspection of the facets returned, refer to the functions
       described in <xref linkend="zoom.facets"/>.
       </entry><entry>none</entry>
      </row>
      <row><entry>
       apdulog</entry><entry>
       If set to a true value such as "1", a log of low-level
       protocol packets is emitted on standard error stream.  This
       can be very useful for debugging.
      </entry><entry>0</entry></row>
      <row><entry>
       saveAPDU</entry><entry>
       If set to a true value such as "1", a log of low-level
       protocol packets is saved. The log can be retrieved by reading
       option APDU. Setting saveAPDU always has the side effect of
       resetting the currently saved log. This setting is
       <emphasis>write-only</emphasis>. If read, NULL will be returned.
       It is only recognized in
       <function>ZOOM_connection_option_set</function>.
       </entry><entry>0</entry>
      </row>
      <row><entry>
       APDU</entry><entry>
       Returns the log of protocol packets. Will be empty if logging
       is not enabled (see saveAPDU above). This setting is
       <emphasis>read-only</emphasis>. It is only recognized if used
       in call to <function>ZOOM_connection_option_get</function> or
       <function>ZOOM_connection_option_getl</function>.
       </entry><entry></entry>
      </row>
      <row><entry>
       memcached</entry><entry>
       If given and non-empty,
       <ulink url="&url.libmemcached;">libMemcached</ulink>
       will be configured for the connection.
       This option is inspected by ZOOM when a connection is established.
       If the <literal>memcached</literal> option is given
       and YAZ is compiled without libMemcached support, an internal
       diagnostic (10018) will be thrown.
       libMemcached support is available for YAZ 5.0.13 or later. If this
       option is supplied for an earlier version of YAZ, it is
       <emphasis>ignored</emphasis>.
       The value of this option is a list options - each is of the
       form <literal>--name=value</literal>.
       Option <literal>--server=</literal>host[:port] specifies a memcached
       server. It may be repeated for multiple memcached servers.
       Option <literal>--expire=</literal>seconds sets expiry time in seconds
       for how long result sets are to be cached.
       </entry><entry>none</entry>
      </row>
      <row><entry>
       redis</entry><entry>
       If given and non-empty,
       a <ulink url="&url.redis;">redis</ulink> context will be created
       for the connection.
       This option is inspected by ZOOM when a connection is established.
       If the <literal>redis</literal> option is given
       and YAZ is compiled without redis support, an internal
       diagnostic (10018) will be thrown.
       redis support is available for YAZ 5.2.0 or later. If this
       option is supplied for an earlier version of YAZ, it is
       <emphasis>ignored</emphasis>.
       The value of this option is a set of options, similar to that
       of the memcached setting. At this stage only --server=host[:port]
       and --expire=seconds are supported.
       </entry><entry>none</entry>
      </row>
     </tbody>
    </tgroup>
   </table>
   <para>
    If either option <literal>lang</literal> or <literal>charset</literal>
    is set, then
    <ulink url="&url.z39.50.charneg;">
     Character Set and Language Negotiation</ulink> is in effect.
   </para>
   <synopsis>
     int ZOOM_connection_error(ZOOM_connection c, const char **cp,
                               const char **addinfo);
     int ZOOM_connection_error_x(ZOOM_connection c, const char **cp,
                                 const char **addinfo, const char **dset);
   </synopsis>
   <para>
    Function <function>ZOOM_connection_error</function> checks for
    errors for the last operation(s) performed. The function returns
    zero if no errors occurred; non-zero otherwise indicating the error.
    Pointers <parameter>cp</parameter> and <parameter>addinfo</parameter>
    holds messages for the error and additional-info if passed as
    non-<literal>NULL</literal>. Function
    <function>ZOOM_connection_error_x</function> is an extended version
    of <function>ZOOM_connection_error</function> that is capable of
    returning name of diagnostic set in <parameter>dset</parameter>.
   </para>
   <sect2 id="zoom-connection-z39.50">
    <title>Z39.50 Protocol behavior</title>
    <para>
     The calls <function>ZOOM_connection_new</function> and
     <function>ZOOM_connection_connect</function> establishes a TCP/IP
     connection and sends an Initialize Request to the target if
     possible. In addition, the calls wait for an Initialize Response
     from the target and the result is inspected (OK or rejected).
    </para>
    <para>
     If <literal>proxy</literal> is set then the client will establish
     a TCP/IP connection with the peer as specified by the
     <literal>proxy</literal> host and the hostname as part of the
     connect calls will be set as part of the Initialize Request.
     The proxy server will then "forward" the PDUs transparently
     to the target behind the proxy.
    </para>
    <para>
     For the authentication parameters, if option <literal>user</literal>
     is set and both options <literal>group</literal> and
     <literal>pass</literal> are unset, then Open style
     authentication is used (Version 2/3) in which case the username
     is usually followed by a slash, then by a password.
     If either <literal>group</literal>
     or <literal>pass</literal> is set then idPass authentication
     (Version 3 only) is used. If none of the options are set, no
     authentication parameters are set as part of the Initialize Request
     (obviously).
    </para>
    <para>
     When option <literal>async</literal> is 1, it really means that
     all network operations are postponed (and queued) until the
     function <literal>ZOOM_event</literal> is invoked. When doing so
     it doesn't make sense to check for errors after
     <literal>ZOOM_connection_new</literal> is called since that
     operation "connecting - and init" is still incomplete and the
     API cannot tell the outcome (yet).
    </para>
    </sect2>
   <sect2 id="zoom.sru.init.behavior">
    <title>SRU/Solr Protocol behavior</title>
    <para>
     The HTTP based protocols (SRU, SRW, Solr) do not feature an
     Inititialize Request, so  the connection phase merely establishes a
     TCP/IP connection with the HTTP server.
    </para>
    <para>Most of the ZOOM connection options do not
     affect SRU/Solr and they are ignored. However, future versions
     of &yaz; might honor <literal>implementationName</literal> and
     put that as part of User-Agent header for HTTP requests.
     </para>
    <para>
     The <literal>charset</literal> is used in the Content-Type header
     of HTTP requests.
    </para>
    <para>
     Setting <literal>authentcationMode</literal> specifies how
     authentication parameters are encoded for HTTP. The default is
     "<literal>basic</literal>" where <literal>user</literal> and
     <literal>password</literal> are encoded by using HTTP basic
     authentication.
     </para>
    <para>
     If <literal>authentcationMode</literal> is "<literal>url</literal>", then
     user and password are encoded in the URL by parameters
     <literal>x-username</literal> and <literal>x-password</literal> as
     given by the SRU standard.
    </para>
   </sect2>
  </sect1>
  <sect1 id="zoom.query">
   <title>Queries</title>
   <para>
    Query objects represents queries.
   </para>
   <synopsis>
     ZOOM_query ZOOM_query_create(void);

     void ZOOM_query_destroy(ZOOM_query q);

     int ZOOM_query_prefix(ZOOM_query q, const char *str);

     int ZOOM_query_cql(ZOOM_query s, const char *str);

     int ZOOM_query_sortby(ZOOM_query q, const char *criteria);

     int ZOOM_query_sortby2(ZOOM_query q, const char *strategy,
                            const char *criteria);
   </synopsis>
   <para>
    Create query objects using <function>ZOOM_query_create</function>
    and destroy them by calling <function>ZOOM_query_destroy</function>.
    RPN-queries can be specified in <link linkend="PQF">PQF</link>
    notation by using the
    function <function>ZOOM_query_prefix</function>.
    The <function>ZOOM_query_cql</function> specifies a CQL
    query to be sent to the server/target.
    More query types will be added in future versions of &yaz;, such as
    <link linkend="CCL">CCL</link> to RPN-mapping, native CCL query,
    etc. In addition to a search, a sort criteria may be set. Function
    <function>ZOOM_query_sortby</function> enables Z39.50 sorting and
    it takes sort criteria using the same string notation as
    yaz-client's <link linkend="sortspec">sort command</link>.
   </para>
   <para id="zoom.query.sortby2">
    <function>ZOOM_query_sortby2</function> is similar to
    <function>ZOOM_query_sortby</function> but allows a strategy for
    sorting. The reason for the strategy parameter is that some
    protocols offer multiple ways of performing sorting.
    For example, Z39.50 has the standard sort, which is performed after
    search on an existing result set.
    It's also possible to use CQL in Z39.50 as the query type and use
    CQL's SORTBY keyword. Finally, Index Data's
    Zebra server also allows sorting to be specified as part of RPN (Type 7).
   </para>
   <table id="zoom-sort-strategy" frame="top">
    <title>ZOOM sort strategy</title>
    <tgroup cols="2">
     <colspec colwidth="2*" colname="name"/>
     <colspec colwidth="5*" colname="description"/>
     <thead>
      <row>
       <entry>Name</entry>
       <entry>Description</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>z39.50</entry><entry>Z39.50 resultset sort</entry>
      </row>
      <row>
       <entry>type7</entry><entry>Sorting embedded in RPN(Type-7)</entry>
      </row>
      <row>
       <entry>cql</entry><entry>CQL SORTBY</entry>
      </row>
      <row>
       <entry>sru11</entry><entry>SRU sortKeys parameter</entry>
      </row>
      <row>
       <entry>solr</entry><entry>Solr sort</entry>
      </row>
      <row>
       <entry>embed</entry><entry>type7 for Z39.50, cql for SRU,
	solr for Solr protocol</entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </sect1>
  <sect1 id="zoom.resultsets"><title>Result sets</title>
   <para>
    The result set object is a container for records returned from
    a target.
   </para>
   <synopsis>
     ZOOM_resultset ZOOM_connection_search(ZOOM_connection, ZOOM_query q);

     ZOOM_resultset ZOOM_connection_search_pqf(ZOOM_connection c,
                                               const char *q);
     void ZOOM_resultset_destroy(ZOOM_resultset r);
   </synopsis>
   <para>
    Function <function>ZOOM_connection_search</function> creates
    a result set, given a connection and query.
    Destroy a result set by calling
    <function>ZOOM_resultset_destroy</function>.
    Simple clients using PQF only, may use the function
    <function>ZOOM_connection_search_pqf</function> in which case
    creating query objects is not necessary.
   </para>
   <synopsis>
     void ZOOM_resultset_option_set(ZOOM_resultset r,
                                    const char *key, const char *val);

     const char *ZOOM_resultset_option_get(ZOOM_resultset r, const char *key);

     size_t ZOOM_resultset_size(ZOOM_resultset r);
   </synopsis>
   <para>
    Functions <function>ZOOM_resultset_options_set</function> and
    <function>ZOOM_resultset_get</function> sets and gets an option
    for a result set similar to <function>ZOOM_connection_option_get</function>
    and <function>ZOOM_connection_option_set</function>.
   </para>
   <para>
    The number of hits, also called result-count, is returned by
    function <function>ZOOM_resultset_size</function>.
   </para>
   <table id="zoom.resultset.options"
    frame="top"><title>ZOOM Result set Options</title>
    <tgroup cols="3">
     <colspec colwidth="4*" colname="name"></colspec>
     <colspec colwidth="7*" colname="description"></colspec>
     <colspec colwidth="2*" colname="default"></colspec>
     <thead>
      <row>
       <entry>Option</entry>
       <entry>Description</entry>
       <entry>Default</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
        start</entry><entry>Offset of first record to be
        retrieved from target. First record has offset 0 unlike the
        protocol specifications where first record has position 1.
	This option affects ZOOM_resultset_search and
	ZOOM_resultset_search_pqf and must be set before any of
	these functions are invoked. If a range of
	records must be fetched manually after search,
	function ZOOM_resultset_records should be used.
       </entry><entry>0</entry></row>
      <row><entry>
        count</entry><entry>Number of records to be retrieved.
	This option affects ZOOM_resultset_search and
	ZOOM_resultset_search_pqf and must be set before any of
	these functions are invoked.
       </entry><entry>0</entry></row>
      <row><entry>
	presentChunk</entry><entry>The number of records to be
	requested from the server in each chunk (present request). The
	value 0 means to request all the records in a single chunk.
	(The old <literal>step</literal>
	option is also supported for the benefit of old applications.)
       </entry><entry>0</entry></row>
      <row><entry>
        elementSetName</entry><entry>Element-Set name of records.
        Most targets should honor element set name <literal>B</literal>
        and <literal>F</literal> for brief and full respectively.
       </entry><entry>none</entry></row>
      <row><entry>
        preferredRecordSyntax</entry><entry>Preferred Syntax, such as
        <literal>USMARC</literal>, <literal>SUTRS</literal>, etc.
       </entry><entry>none</entry></row>
      <row><entry>
        schema</entry><entry>Schema for retrieval, such as
        <literal>Gils-schema</literal>, <literal>Geo-schema</literal>, etc.
       </entry><entry>none</entry></row>
      <row><entry>
        setname</entry><entry>Name of Result Set (Result Set ID).
        If this option isn't set, the ZOOM module will automatically
        allocate a result set name.
       </entry><entry>default</entry></row>
      <row><entry>
        rpnCharset</entry><entry>Character set for RPN terms.
        If this is set, ZOOM C will assume that the ZOOM application is
        running UTF-8. Terms in RPN queries are then converted to the
        rpnCharset. If this is unset, ZOOM C will not assume any encoding
        of RPN terms and no conversion is performed.
       </entry><entry>none</entry></row>
     </tbody>
    </tgroup>
   </table>
   <para>
    For servers that support Search Info report, the following
    options may be read using <function>ZOOM_resultset_get</function>.
    This detailed information is read after a successful search has
    completed.
   </para>
   <para>
    This information is a list of of items, where each item is
    information about a term or subquery. All items in the list
    are prefixed by
    <literal>SearchResult.</literal><replaceable>no</replaceable>
    where no presents the item number (0=first, 1=second).
    Read <literal>searchresult.size</literal> to determine the
    number of items.
   </para>
   <table id="zoom.search.info.report.options"
    frame="top"><title>Search Info Report Options</title>
    <tgroup cols="2">
     <colspec colwidth="4*" colname="name"></colspec>
     <colspec colwidth="7*" colname="description"></colspec>
     <thead>
      <row>
       <entry>Option</entry>
       <entry>Description</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>searchresult.size</entry>
       <entry>
	number of search result entries. This option is non-existent
	if no entries are returned by the server.
       </entry>
      </row>
      <row>
       <entry>searchresult.<replaceable>no</replaceable>.id</entry>
       <entry>sub query ID</entry>
      </row>
      <row>
       <entry>searchresult.<replaceable>no</replaceable>.count</entry>
       <entry>result count for item (number of hits)</entry>
      </row>
      <row>
       <entry>searchresult.<replaceable>no</replaceable>.subquery.term</entry>
       <entry>subquery term</entry>
      </row>
      <row>
       <entry>
	searchresult.<replaceable>no</replaceable>.interpretation.term
       </entry>
       <entry>interpretation term</entry>
      </row>
      <row>
       <entry>
	searchresult.<replaceable>no</replaceable>.recommendation.term
       </entry>
       <entry>recommendation term</entry>
      </row>
     </tbody>
    </tgroup>
   </table>
   <sect2 id="zoom.z3950.resultset.sort">
    <title>Z39.50 Result-set Sort</title>
    <synopsis>
     void ZOOM_resultset_sort(ZOOM_resultset r,
                              const char *sort_type, const char *sort_spec);

     int ZOOM_resultset_sort1(ZOOM_resultset r,
                              const char *sort_type, const char *sort_spec);
    </synopsis>
    <para>
     <function>ZOOM_resultset_sort</function> and
     <function>ZOOM_resultset_sort1</function> both sort an existing
     result-set. The sort_type parameter is not used. Set it to "yaz".
     The sort_spec is same notation as ZOOM_query_sortby and identical
     to that offered by yaz-client's
     <link linkend="sortspec">sort command</link>.
    </para>
    <para>
     These functions only work for Z39.50. Use the more generic utility
     <link linkend="zoom.query.sortby2">
      <function>ZOOM_query_sortby2</function></link>
     for other protocols (and even Z39.50).
    </para>
   </sect2>
   <sect2 id="zoom.z3950.resultset.behavior">
    <title>Z39.50 Protocol behavior</title>
    <para>
     The creation of a result set involves at least a SearchRequest
     - SearchResponse protocol handshake. Following that, if a sort
     criteria was specified as part of the query, a SortRequest -
     SortResponse handshake takes place. Note that it is necessary to
     perform sorting before any retrieval takes place, so no records will
     be returned from the target as part of the SearchResponse because these
     would be unsorted. Hence, piggyback is disabled when sort criteria
     are set. Following Search - and a possible sort - Retrieval takes
     place - as one or more Present Requests/Response pairs being
     transferred.
     </para>
    <para>
     The API allows for two different modes for retrieval. A high level
     mode which is somewhat more powerful and a low level one.
     The low level is enabled when searching on a Connection object
     for which the settings
     <literal>smallSetUpperBound</literal>,
     <literal>mediumSetPresentNumber</literal> and
     <literal>largeSetLowerBound</literal> are set. The low level mode
     thus allows you to precisely set how records are returned as part
     of a search response as offered by the Z39.50 protocol.
     Since the client may be retrieving records as part of the
     search response, this mode doesn't work well if sorting is used.
     </para>
    <para>
     The high-level mode allows you to fetch a range of records from
     the result set with a given start offset. When you use this mode
     the client will automatically use piggyback if that is possible
     with the target, and perform one or more present requests as needed.
     Even if the target returns fewer records as part of a present response
     because of a record size limit, etc. the client will repeat sending
     present requests. As an example, if option <literal>start</literal>
     is 0 (default) and <literal>count</literal> is 4, and
     <literal>piggyback</literal> is 1 (default) and no sorting criteria
     is specified, then the client will attempt to retrieve the 4
     records as part the search response (using piggyback). On the other
     hand, if either <literal>start</literal> is positive or if
     a sorting criteria is set, or if <literal>piggyback</literal>
     is 0, then the client will not perform piggyback but send Present
     Requests instead.
    </para>
    <para>
     If either of the options <literal>mediumSetElementSetName</literal> and
     <literal>smallSetElementSetName</literal> are unset, the value
     of option <literal>elementSetName</literal> is used for piggyback
     searches. This means that for the high-level mode you only have
     to specify one elementSetName option rather than three.
     </para>
   </sect2>
   <sect2 id="zoom.sru.resultset.behavior">
    <title>SRU Protocol behavior</title>
    <para>
     Current version of &yaz; does not take advantage of a result set id
     returned by the SRU server. Future versions might do, however.
     Since the ZOOM driver does not save result set IDs, any
     present (retrieval) is transformed to a SRU SearchRetrieveRequest
     with same query but, possibly, different offsets.
    </para>
    <para>
     Option <literal>schema</literal> specifies SRU schema
     for retrieval. However, options <literal>elementSetName</literal> and
     <literal>preferredRecordSyntax</literal> are ignored.
    </para>
    <para>
     Options <literal>start</literal> and <literal>count</literal>
     are supported by SRU.
     The remaining options
     <literal>piggyback</literal>,
     <literal>smallSetUpperBound</literal>,
     <literal>largeSetLowerBound</literal>,
     <literal>mediumSetPresentNumber</literal>,
     <literal>mediumSetElementSetName</literal>,
      <literal>smallSetElementSetName</literal> are
     unsupported.
    </para>
    <para>
     SRU supports CQL queries, <emphasis>not</emphasis> PQF.
     If PQF is used, however, the PQF query is transferred anyway
     using non-standard element <literal>pQuery</literal> in
     SRU SearchRetrieveRequest.
    </para>
    <para>
     Solr queries need to be done in Solr query format.
    </para>
    <para>
     Unfortunately, SRU and Solr do not define a database setting. Hence,
     <literal>databaseName</literal> is unsupported and ignored.
     However, the path part in host parameter for functions
     <function>ZOOM_connecton_new</function> and
     <function>ZOOM_connection_connect</function> acts as a
     database (at least for the &yaz; SRU server).
    </para>
   </sect2>
  </sect1>
  <sect1 id="zoom.records">
   <title>Records</title>
   <para>
    A record object is a retrieval record on the client side -
    created from result sets.
   </para>
   <synopsis>
     void ZOOM_resultset_records(ZOOM_resultset r,
                                 ZOOM_record *recs,
                                 size_t start, size_t count);
     ZOOM_record ZOOM_resultset_record(ZOOM_resultset s, size_t pos);

     const char *ZOOM_record_get(ZOOM_record rec, const char *type,
                                 size_t *len);

     int ZOOM_record_error(ZOOM_record rec, const char **msg,
                           const char **addinfo, const char **diagset);

     ZOOM_record ZOOM_record_clone(ZOOM_record rec);

     void ZOOM_record_destroy(ZOOM_record rec);
   </synopsis>
   <para>
    References to temporary records are returned by functions
    <function>ZOOM_resultset_records</function> or
    <function>ZOOM_resultset_record</function>.
    </para>
   <para>
    If a persistent reference to a record is desired
    <function>ZOOM_record_clone</function> should be used.
    It returns a record reference that should be destroyed
    by a call to <function>ZOOM_record_destroy</function>.
   </para>
   <para>
    A single record is returned by function
    <function>ZOOM_resultset_record</function> that takes a
    position as argument. First record has position zero.
    If no record could be obtained <literal>NULL</literal> is returned.
   </para>
   <para>
    Error information for a record can be checked with
    <function>ZOOM_record_error</function> which returns non-zero
    (error code) if record is in error, called <emphasis>Surrogate
     Diagnostics</emphasis> in Z39.50.
   </para>
   <para>
    Function <function>ZOOM_resultset_records</function> retrieves
    a number of records from a result set. Parameter <literal>start</literal>
    and <literal>count</literal> specifies the range of records to
    be returned. Upon completion, the array
    <literal>recs[0], ..recs[count-1]</literal>
    holds record objects for the records. The array of records
     <literal>recs</literal> should be allocated prior the call
    <function>ZOOM_resultset_records</function>. Note that for those
    records that couldn't be retrieved from the target,
    <literal>recs[ ..]</literal> is set to <literal>NULL</literal>.
   </para>
   <para id="zoom.record.get">
    In order to extract information about a single record,
    <function>ZOOM_record_get</function> is provided. The
    function returns a pointer to certain record information. The
    nature (type) of the pointer depends on the parameter,
    <parameter>type</parameter>.
   </para>
   <para>
    The <parameter>type</parameter> is a string of the format:
   </para>
   <para>
    <replaceable>format</replaceable>[;charset=<replaceable>from</replaceable>[/<replaceable>opacfrom</replaceable>][,<replaceable>to</replaceable>]][;format=<replaceable>v</replaceable>][;base64=<replaceable>xpath</replaceable>]
   </para>
   <para>
    If <literal>charset</literal> is given, then <replaceable>from</replaceable>
    specifies the character set of the record in its original form
    (as returned by the server), <replaceable>to</replaceable> specifies
    the output (returned) character set encoding.
    If <replaceable>to</replaceable> is omitted, then UTF-8 is assumed.
    If charset is not given, then no character set conversion takes place.
    OPAC records may be returned in a different
    set from the bibliographic MARC record. If this is this the case,
    <replaceable>opacfrom</replaceable> should be set to the character set
    of the OPAC record part.
   </para>

   <para>
    The <literal>format</literal> is generic but can only be used to
    specify XML indentation when the value <replaceable>v</replaceable>
    is 1 (<literal>format=1</literal>).
   </para>
   <para>
    The <literal>base64</literal> allows a full record to be extracted
    from base64-encoded string in an XML document.
   </para>
   <note>
     <para>
       Specifying the OPAC record character set requires YAZ 4.1.5 or later.
     </para>
     <para>
       Specifying the base64 parameter requires YAZ 4.2.35 or later.
     </para>
   </note>
   <para>
    The format argument controls whether record data should be XML
    pretty-printed (post process operation).
    It is enabled only if format value <replaceable>v</replaceable> is
    <literal>1</literal> and the record content is XML well-formed.
   </para>
   <para>
    In addition, for certain types, the length
    <literal>len</literal> passed will be set to the size in bytes of
    the returned information.
    </para>
   <para>
    The following are the supported values for <replaceable>form</replaceable>.
    <variablelist>
     <varlistentry><term><literal>database</literal></term>
      <listitem><para>The Database of the record is returned
        as a C null-terminated string. Return type
        <literal>const char *</literal>.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>syntax</literal></term>
      <listitem><para>The transfer syntax of the record is returned
        as a C null-terminated string containing the symbolic name of
	the record syntax, e.g. <literal>Usmarc</literal>. Return type
	is
        <literal>const char *</literal>.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>schema</literal></term>
      <listitem><para>The schema of the record is returned
        as a C null-terminated string. Return type is
        <literal>const char *</literal>.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>render</literal></term>
      <listitem><para>The record is returned in a display friendly
        format. Upon completion, buffer is returned
        (type <literal>const char *</literal>) and length is stored in
        <literal>*len</literal>.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>raw</literal></term>
      <listitem><para>The record is returned in the internal
        YAZ specific format. For GRS-1, Explain, and others, the
        raw data is returned as type
        <literal>Z_External *</literal> which is just the type for
        the member <literal>retrievalRecord</literal> in
        type <literal>NamePlusRecord</literal>.
        For SUTRS and octet aligned record (including all MARCs) the
        octet buffer is returned and the length of the buffer.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>xml</literal></term>
      <listitem><para>The record is returned in XML if possible.
	SRU, Solr and Z39.50 records with transfer syntax XML are
	returned verbatim. MARC records are returned in
	<ulink url="&url.marcxml;">
	 MARCXML
	 </ulink>
	(converted from ISO2709 to MARCXML by YAZ).
	OPAC records are also converted to XML and the
	bibliographic record is converted to MARCXML (when possible).
	GRS-1 records are not supported for this form.
        Upon completion, the XML buffer is returned
	(type <literal>const char *</literal>) and length is stored in
        <literal>*len</literal>.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>opac</literal></term>
      <listitem><para>OPAC information for record is returned in XML
	if an OPAC record is present at the position given. If no
	OPAC record is present, a NULL pointer is returned.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>txml</literal></term>
      <listitem><para>The record is returned in TurboMARC if possible.
	SRU and Z39.50 records with transfer syntax XML are
	returned verbatim. MARC records are returned in
	<link linkend="tools.turbomarc">
	 TurboMARC
	</link>
	(converted from ISO2709 to TurboMARC by YAZ).
	Upon completion, the XML buffer is returned
	(type <literal>const char *</literal>) and length is stored in
        <literal>*len</literal>.
       </para></listitem>
     </varlistentry>
     <varlistentry><term><literal>json</literal></term>
      <listitem><para>Like xml, but MARC records are converted to
	<ulink url="&url.marc_in_json;">MARC-in-JSON</ulink>.
       </para></listitem>
     </varlistentry>

    </variablelist>
   </para>
   <para>
    Most
    <ulink url="&url.marc21;">MARC21</ulink>
    records uses the
    <ulink url="&url.marc8;">MARC-8</ulink>
    character set encoding.
    An application that wishes to display in Latin-1 would use
    <screen>
     render; charset=marc8,iso-8859-1
    </screen>
   </para>
   <sect2 id="zoom.z3950.record.behavior">
    <title>Z39.50 Protocol behavior</title>
    <para>
     The functions <function>ZOOM_resultset_record</function> and
     <function>ZOOM_resultset_records</function> inspects the client-side
     record cache. Records not found in cache are fetched using
     Present.
     The functions may block (and perform network I/O)  - even though option
     <literal>async</literal> is 1, because they return records objects.
     (And there's no way to return records objects without retrieving them!)
     </para>
    <para>
     There is a trick, however, in the usage of function
     <function>ZOOM_resultset_records</function> that allows for
     delayed retrieval (and makes it non-blocking). By using
     a null pointer for <parameter>recs</parameter> you're indicating
     you're not interested in getting records objects
     <emphasis>now</emphasis>.
    </para>
   </sect2>
   <sect2 id="zoom.sru.record.behavior">
    <title>SRU/Solr Protocol behavior</title>
    <para>
     The ZOOM driver for SRU/Solr treats records returned by a SRU/Solr server
     as if they where Z39.50 records with transfer syntax XML and
     no element set name or database name.
    </para>
   </sect2>
  </sect1>
  <sect1 id="zoom.facets"><title>ZOOM Facets</title>
   <para>
    Facets are only supported for a few Z39.50 targets. It is a relatively
    new non-standard Z39.50 extension (see facets.asn in the YAZ source).
    However, facets are usually supported for
    <ulink url="&url.solr;">Solr</ulink> and SRU 2.0 targets.
   </para>
   <para>
    Facets may be specified by the
     <link linkend="zoom.facets.option">facets</link> option before a
    search is sent. See <xref linkend="facets"/> for the notation.
    For inspection of the returned facets, the following functions are
    available:
   </para>
   <synopsis>
    ZOOM_facet_field *ZOOM_resultset_facets(ZOOM_resultset r);

    size_t ZOOM_resultset_facets_size(ZOOM_resultset r);

    ZOOM_facet_field ZOOM_resultset_get_facet_field(ZOOM_resultset r,
                                                    const char *facet_name);

    ZOOM_facet_field ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r,
                                                             int pos);

    const char *ZOOM_facet_field_name(ZOOM_facet_field facet_field);

    size_t ZOOM_facet_field_term_count(ZOOM_facet_field facet_field);

    const char *ZOOM_facet_field_get_term(ZOOM_facet_field facet_field,
                                          size_t idx, int *freq);
   </synopsis>
   <para>
    References to temporary structures are returned by all functions.
    They are only valid as long the Result set is valid.
   </para>
   <para id="zoom.resultset.facets">
    All facet fields may be returned by a call to
    <function>ZOOM_resultset_facets</function>. The length of the array is
    given by <function>ZOOM_resultset_facets_size</function>. The array is
    zero-based and the last entry will be at
    <function>ZOOM_resultset_facets_size(result_set)</function>-1.
   </para>
   <para id="zoom.resultset.get_facet_field">
    Facet fields can also be fetched via its name using
    <function>ZOOM_resultset_get_facet_field</function>.
    Or by its index (starting from 0) by a call to
    <function>ZOOM_resultset_get_facet_field_by_index</function>.
    Both of these functions return NULL if name is not found or index is
    out of bounds.
   </para>
   <para>
   Function <function>ZOOM_facet_field_name</function> gets the request
    facet name from a returned facet field.
   </para>
   <para>
    Function <function>ZOOM_facet_field_get_term</function> returns the
    idx'th term and term count for a facet field.
    Idx must between 0 and
    <function>ZOOM_facet_field_term_count</function>-1, otherwise the
    returned reference will be <literal>NULL</literal>. On a valid idx, the
    value of the freq reference will be the term count.
    The <literal>freq</literal> parameter must be valid pointer to integer.
   </para>
   </sect1>
  <sect1 id="zoom.scan"><title>Scan</title>
   <para>
    This section describes an interface for Scan. Scan is not an
    official part of the ZOOM model yet. The result of a scan operation
    is the <literal>ZOOM_scanset</literal> which is a set of terms
    returned by a target.
   </para>

   <para>
    The Scan interface is supported for both Z39.50, SRU and Solr.
   </para>

   <synopsis>
    ZOOM_scanset ZOOM_connection_scan(ZOOM_connection c,
                                      const char *startpqf);

    ZOOM_scanset ZOOM_connection_scan1(ZOOM_connection c,
                                       ZOOM_query q);

    size_t ZOOM_scanset_size(ZOOM_scanset scan);

    const char *ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
                                  size_t *occ, size_t *len);

    const char *ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
                                          size_t *occ, size_t *len);

    void ZOOM_scanset_destroy(ZOOM_scanset scan);

    const char *ZOOM_scanset_option_get(ZOOM_scanset scan,
                                        const char *key);

    void ZOOM_scanset_option_set(ZOOM_scanset scan, const char *key,
                                 const char *val);
    </synopsis>
   <para>
    The scan set is created by function
    <function>ZOOM_connection_scan</function> which performs a scan
    operation on the connection using the specified
    <parameter>startpqf</parameter>.
    If the operation was successful, the size of the scan set can be
    retrieved by a call to <function>ZOOM_scanset_size</function>.
    Like result sets, the items are numbered 0..size-1.
    To obtain information about a particular scan term, call function
    <function>ZOOM_scanset_term</function>. This function takes
    a scan set offset <literal>pos</literal> and returns a pointer
    to a <emphasis>raw term</emphasis> or <literal>NULL</literal> if
    non-present.
    If present, the <literal>occ</literal> and <literal>len</literal>
    are set to the number of occurrences and the length
    of the actual term respectively.
    <function>ZOOM_scanset_display_term</function> is similar to
    <function>ZOOM_scanset_term</function> except that it returns
    the <emphasis>display term</emphasis> rather than the raw term.
    In a few cases, the term is different from display term. Always
    use the display term for display and the raw term for subsequent
    scan operations (to get more terms, next scan result, etc).
   </para>
   <para>
    A scan set may be freed by a call to function
    <function>ZOOM_scanset_destroy</function>.
    Functions <function>ZOOM_scanset_option_get</function> and
    <function>ZOOM_scanset_option_set</function> retrieves and sets
    an option respectively.
   </para>
   <para>
    The <parameter>startpqf</parameter> is a subset of PQF, namely
    the Attributes+Term part. Multiple <literal>@attr</literal> can
    be used. For example to scan in title (complete) phrases:
    <literallayout>
     @attr 1=4 @attr 6=2 "science o"
    </literallayout>
   </para>
   <para>
    The <function>ZOOM_connecton_scan1</function> is a newer and
    more generic alternative to <function>ZOOM_connection_scan</function>
    which allows to use both CQL and PQF for Scan.
   </para>
   <table frame="top" id="zoom.scanset.options">
    <title>ZOOM Scan Set Options</title>
    <tgroup cols="3">
     <colspec colwidth="4*" colname="name"></colspec>
     <colspec colwidth="7*" colname="description"></colspec>
     <colspec colwidth="2*" colname="default"></colspec>
     <thead>
      <row>
       <entry>Option</entry>
       <entry>Description</entry>
       <entry>Default</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
        number</entry><entry>Number of Scan Terms requested in next scan.
        After scan it holds the actual number of terms returned.
       </entry><entry>20</entry></row>
      <row><entry>
        position</entry><entry>Preferred Position of term in response
        in next scan; actual position after completion of scan.
       </entry><entry>1</entry></row>
      <row><entry>
        stepSize</entry><entry>Step Size
       </entry><entry>0</entry></row>
      <row><entry>
        scanStatus</entry><entry>An integer indicating the Scan Status
        of last scan.
       </entry><entry>0</entry></row>
      <row><entry>
        rpnCharset</entry><entry>Character set for RPN terms.
        If this is set, ZOOM C will assume that the ZOOM application is
        running UTF-8. Terms in RPN queries are then converted to the
        rpnCharset. If this is unset, ZOOM C will not assume any encoding
        of RPN terms and no conversion is performed.
       </entry><entry>none</entry></row>
     </tbody>
    </tgroup>
   </table>
  </sect1>
  <sect1 id="zoom.extendedservices">
   <title>Extended Services</title>
   <para>
    ZOOM offers an interface to a subset of the Z39.50 extended services
    as well as a few privately defined ones:
   </para>
   <itemizedlist>
    <listitem>
     <para>
      Z39.50 Item Order (ILL).
      See <xref linkend="zoom.item.order"/>.
     </para>
    </listitem>
    <listitem>
     <para>
      Record Update. This allows a client to insert, modify or delete
      records.
      See <xref linkend="zoom.record.update"/>.
     </para>
    </listitem>
    <listitem>
     <para>
      Database Create. This a non-standard feature. Allows a client
      to create a database.
      See <xref linkend="zoom.database.create"/>.
     </para>
    </listitem>
    <listitem>
     <para>
      Database Drop. This a non-standard feature. Allows a client
      to delete/drop a database.
      See <xref linkend="zoom.database.drop"/>.
     </para>
     </listitem>
    <listitem>
     <para>
      Commit operation. This a non-standard feature. Allows a client
      to commit operations.
      See <xref linkend="zoom.commit"/>.
     </para>
    </listitem>
    <!-- all the ILL PDU options should go here too -->
   </itemizedlist>
   <para>
    To create an extended service operation, a <literal>ZOOM_package</literal>
    must be created. The operation is a five step operation. The
    package is created, package is configured by means of options,
    the package is sent, result is inspected (by means of options),
    the package is destroyed.
   </para>
   <synopsis>
    ZOOM_package ZOOM_connection_package(ZOOM_connection c,
                                         ZOOM_options options);

    const char *ZOOM_package_option_get(ZOOM_package p,
                                        const char *key);
    void ZOOM_package_option_set(ZOOM_package p, const char *key,
                                 const char *val);
    void ZOOM_package_send(ZOOM_package p, const char *type);

    void ZOOM_package_destroy(ZOOM_package p);
   </synopsis>
   <para>
    The <function>ZOOM_connection_package</function> creates a
    package for the connection given using the options specified.
   </para>
   <para>
    Functions <function>ZOOM_package_option_get</function> and
    <function>ZOOM_package_option_set</function> gets and sets
    options.
   </para>
   <para>
    <function>ZOOM_package_send</function> sends
    the package the via connection specified in
    <function>ZOOM_connection_package</function>.
    The <parameter>type</parameter> specifies the actual extended service
    package type to be sent.
   </para>
   <table frame="top" id="zoom.extendedservices.type">
    <title>Extended Service Type</title>
    <tgroup cols="2">
     <colspec colwidth="3*" colname="value"></colspec>
     <colspec colwidth="7*" colname="description"></colspec>
     <thead>
      <row>
       <entry>Type</entry>
       <entry>Description</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>itemorder</entry><entry>Item Order</entry>
      </row>
      <row>
       <entry>update</entry><entry>Record Update</entry>
      </row>
      <row>
       <entry>create</entry><entry>Database Create</entry>
      </row>
      <row>
       <entry>drop</entry><entry>Database Drop</entry>
      </row>
      <row>
       <entry>commit</entry><entry>Commit Operation</entry>
      </row>
     </tbody>
    </tgroup>
   </table>

   <table frame="top" id="zoom.extendedservices.options">
    <title>Extended Service Common Options</title>
    <tgroup cols="3">
     <colspec colwidth="4*" colname="name"></colspec>
     <colspec colwidth="7*" colname="description"></colspec>
     <colspec colwidth="3*" colname="default"></colspec>
     <thead>
      <row>
       <entry>Option</entry>
       <entry>Description</entry>
       <entry>Default</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>package-name</entry>
       <entry>Extended Service Request package name. Must be specified
       as part of a request.</entry>
       <entry>none</entry>
      </row>
      <row>
       <entry>user-id</entry>
       <entry>User ID of Extended Service Package. Is a request option.</entry>
       <entry>none</entry>
      </row>
      <row>
       <entry>function</entry>
       <entry>
	Function of package - one of <literal>create</literal>,
	<literal>delete</literal>, <literal>modify</literal>. Is
	a request option.
       </entry>
       <entry><literal>create</literal></entry>
      </row>
      <row>
       <entry>waitAction</entry>
       <entry>
	Wait action for package. Possible values:
	<literal>wait</literal>, <literal>waitIfPossible</literal>,
	<literal>dontWait</literal> or <literal>dontReturnPackage</literal>.
       </entry>
       <entry><literal>waitIfPossible</literal></entry>
      </row>
      <row>
       <entry>operationStatus</entry>
       <entry>
	Read after response. One of: done, accepted or failure.
	Inspect with <function>ZOOM_pacakage_option_get</function>.
       </entry>
       <entry>none</entry>
      </row>
      <row>
       <entry>targetReference</entry>
       <entry>
	Target Reference. This is part of the response as returned
	by the target. Read it after a successful operation.
	Inspect with <function>ZOOM_pacakage_option_get</function>.
       </entry>
       <entry>none</entry>
      </row>
      <row>
       <entry>taskStatus</entry>
       <entry>
	Read after response: One of: pending, active, complete, aborted.
       </entry>
       <entry>none</entry>
      </row>
      <row>
       <entry>esError</entry>
       <entry>
	Read after response: is set to diagnostic code for response.
       </entry>
       <entry>none</entry>
      </row>
      <row>
       <entry>esAddinfo</entry>
       <entry>
	Read after response: is set to additional info for response.
       </entry>
       <entry>none</entry>
      </row>
     </tbody>
    </tgroup>
   </table>

   <sect2 id="zoom.item.order">
    <title>Item Order</title>
    <para>
     For Item Order, <literal>type</literal> must be set to
     <literal>itemorder</literal> in
     <function>ZOOM_package_send</function>.
    </para>

    <table frame="top" id="zoom.item.order.options">
     <title>Item Order Options</title>
     <tgroup cols="3">
      <colspec colwidth="4*" colname="name"></colspec>
      <colspec colwidth="7*" colname="description"></colspec>
      <colspec colwidth="3*" colname="default"></colspec>
      <thead>
       <row>
	<entry>Option</entry>
	<entry>Description</entry>
	<entry>Default</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>contact-name</entry>
	<entry>ILL contact name</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>contact-phone</entry>
	<entry>ILL contact phone</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>contact-email</entry>
	<entry>ILL contact email</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>itemorder-setname</entry>
	<entry>Name of result set for record</entry>
	<entry>default</entry>
       </row>
       <row>
	<entry>itemorder-item</entry>
	<entry>Position for item (record) requested. An integer</entry>
	<entry>1</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
    <para>
     There are two variants of item order: ILL-variant and
     XML document variant. In order to use the XML variant the setting
     <literal>doc</literal> must hold the XML item order document. If that
     setting is unset, the ILL-variant is used.
    </para>

    <table frame="top" id="zoom.illrequest.options">
     <title>ILL Request Options</title>
     <tgroup cols="1">
      <colspec colwidth="4*" colname="name"></colspec>
      <thead>
       <row>
	<entry>Option</entry>
       </row>
      </thead>
      <tbody>
       <row><entry>protocol-version-num</entry></row>
       <row><entry>transaction-id,initial-requester-id,person-or-institution-symbol,person</entry></row>
       <row><entry>transaction-id,initial-requester-id,person-or-institution-symbol,institution</entry></row>
       <row><entry>transaction-id,initial-requester-id,name-of-person-or-institution,name-of-person</entry></row>
       <row><entry>transaction-id,initial-requester-id,name-of-person-or-institution,name-of-institution</entry></row>
       <row><entry>transaction-id,transaction-group-qualifier</entry></row>
       <row><entry>transaction-id,transaction-qualifier</entry></row>
       <row><entry>transaction-id,sub-transaction-qualifier</entry></row>
       <row><entry>service-date-time,this,date</entry></row>
       <row><entry>service-date-time,this,time</entry></row>
       <row><entry>service-date-time,original,date</entry></row>
       <row><entry>service-date-time,original,time</entry></row>
       <row><entry>requester-id,person-or-institution-symbol,person</entry></row>
       <row><entry>requester-id,person-or-institution-symbol,institution</entry></row>
       <row><entry>requester-id,name-of-person-or-institution,name-of-person</entry></row>
       <row><entry>requester-id,name-of-person-or-institution,name-of-institution</entry></row>
       <row><entry>responder-id,person-or-institution-symbol,person</entry></row>
       <row><entry>responder-id,person-or-institution-symbol,institution</entry></row>
       <row><entry>responder-id,name-of-person-or-institution,name-of-person</entry></row>
       <row><entry>responder-id,name-of-person-or-institution,name-of-institution</entry></row>
       <row><entry>transaction-type</entry></row>
       <row><entry>delivery-address,postal-address,name-of-person-or-institution,name-of-person</entry></row>
       <row><entry>delivery-address,postal-address,name-of-person-or-institution,name-of-institution</entry></row>
       <row><entry>delivery-address,postal-address,extended-postal-delivery-address</entry></row>
       <row><entry>delivery-address,postal-address,street-and-number</entry></row>
       <row><entry>delivery-address,postal-address,post-office-box</entry></row>
       <row><entry>delivery-address,postal-address,city</entry></row>
       <row><entry>delivery-address,postal-address,region</entry></row>
       <row><entry>delivery-address,postal-address,country</entry></row>
       <row><entry>delivery-address,postal-address,postal-code</entry></row>
       <row><entry>delivery-address,electronic-address,telecom-service-identifier</entry></row>
       <row><entry>delivery-address,electronic-address,telecom-service-addreess</entry></row>
       <row><entry>billing-address,postal-address,name-of-person-or-institution,name-of-person</entry></row>
       <row><entry>billing-address,postal-address,name-of-person-or-institution,name-of-institution</entry></row>
       <row><entry>billing-address,postal-address,extended-postal-delivery-address</entry></row>
       <row><entry>billing-address,postal-address,street-and-number</entry></row>
       <row><entry>billing-address,postal-address,post-office-box</entry></row>
       <row><entry>billing-address,postal-address,city</entry></row>
       <row><entry>billing-address,postal-address,region</entry></row>
       <row><entry>billing-address,postal-address,country</entry></row>
       <row><entry>billing-address,postal-address,postal-code</entry></row>
       <row><entry>billing-address,electronic-address,telecom-service-identifier</entry></row>
       <row><entry>billing-address,electronic-address,telecom-service-addreess</entry></row>
       <row><entry>ill-service-type</entry></row>
       <row><entry>requester-optional-messages,can-send-RECEIVED</entry></row>
       <row><entry>requester-optional-messages,can-send-RETURNED</entry></row>
       <row><entry>requester-optional-messages,requester-SHIPPED</entry></row>
       <row><entry>requester-optional-messages,requester-CHECKED-IN</entry></row>
       <row><entry>search-type,level-of-service</entry></row>
       <row><entry>search-type,need-before-date</entry></row>
       <row><entry>search-type,expiry-date</entry></row>
       <row><entry>search-type,expiry-flag</entry></row>
       <row><entry>place-on-hold</entry></row>
       <row><entry>client-id,client-name</entry></row>
       <row><entry>client-id,client-status</entry></row>
       <row><entry>client-id,client-identifier</entry></row>
       <row><entry>item-id,item-type</entry></row>
       <row><entry>item-id,call-number</entry></row>
       <row><entry>item-id,author</entry></row>
       <row><entry>item-id,title</entry></row>
       <row><entry>item-id,sub-title</entry></row>
       <row><entry>item-id,sponsoring-body</entry></row>
       <row><entry>item-id,place-of-publication</entry></row>
       <row><entry>item-id,publisher</entry></row>
       <row><entry>item-id,series-title-number</entry></row>
       <row><entry>item-id,volume-issue</entry></row>
       <row><entry>item-id,edition</entry></row>
       <row><entry>item-id,publication-date</entry></row>
       <row><entry>item-id,publication-date-of-component</entry></row>
       <row><entry>item-id,author-of-article</entry></row>
       <row><entry>item-id,title-of-article</entry></row>
       <row><entry>item-id,pagination</entry></row>
       <row><entry>item-id,ISBN</entry></row>
       <row><entry>item-id,ISSN</entry></row>
       <row><entry>item-id,additional-no-letters</entry></row>
       <row><entry>item-id,verification-reference-source</entry></row>
       <row><entry>copyright-complicance</entry></row>
       <row><entry>retry-flag</entry></row>
       <row><entry>forward-flag</entry></row>
       <row><entry>requester-note</entry></row>
       <row><entry>forward-note</entry></row>
      </tbody>
     </tgroup>
    </table>
   </sect2>
   <sect2 id="zoom.record.update">
    <title>Record Update</title>
    <para>
     For Record Update, <literal>type</literal> must be set to
     <literal>update</literal> in
     <function>ZOOM_package_send</function>.
    </para>
    <table frame="top" id="zoom.record.update.options">
     <title>Record Update Options</title>
     <tgroup cols="3">
      <colspec colwidth="4*" colname="name"></colspec>
      <colspec colwidth="7*" colname="description"></colspec>
      <colspec colwidth="3*" colname="default"></colspec>
      <thead>
       <row>
	<entry>Option</entry>
	<entry>Description</entry>
	<entry>Default</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>action</entry>
	<entry>
	 The update action. One of
	 <literal>specialUpdate</literal>,
	 <literal>recordInsert</literal>,
	 <literal>recordReplace</literal>,
	 <literal>recordDelete</literal>,
	 <literal>elementUpdate</literal>.
	</entry>
	<entry><literal>specialUpdate (recordInsert for updateVersion=1 which does not support specialUpdate)</literal></entry>
       </row>
       <row>
	<entry>recordIdOpaque</entry>
	<entry>Opaque Record ID</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>recordIdNumber</entry>
	<entry>Record ID number</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>recordIdString</entry>
	<entry>Record ID string</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>record</entry>
	<entry>The record itself</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>recordOpaque</entry>
	<entry>Specifies an opaque record which is
	  encoded as an ASN.1 ANY type with the OID as given by option
	  <literal>syntax</literal> (see below).
	  Option <literal>recordOpaque</literal> is an alternative
	  to record - and <literal>record</literal> option (above) is
	  ignored if recordOpaque is set. This option is only available in
	  YAZ 3.0.35 and later, and is meant to facilitate Updates with
	  servers from OCLC.
	</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>syntax</entry>
	<entry>The record syntax (transfer syntax). Is a string that
	 is a known record syntax.
	</entry>
	<entry>no syntax</entry>
       </row>
       <row>
	<entry>databaseName</entry>
	<entry>Database from connection object</entry>
	<entry>Default</entry>
       </row>
       <row>
	<entry>correlationInfo.note</entry>
	<entry>Correlation Info Note (string)</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>correlationInfo.id</entry>
	<entry>Correlation Info ID (integer)</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>elementSetName</entry>
	<entry>Element Set for Record</entry>
	<entry>none</entry>
       </row>
       <row>
	<entry>updateVersion</entry>
	<entry>Record Update version which holds one of the values
	 1, 2 or 3. Each version has a distinct OID:
	 1.2.840.10003.9.5
	 (<ulink url="&url.z39.50.extupdate1;">first version</ulink>) ,
	 1.2.840.10003.9.5.1
	 (second version) and
	 1.2.840.10003.9.5.1.1
	 (<ulink url="&url.z39.50.extupdate3;">third and
	  newest version</ulink>).
	</entry>
	<entry>3</entry>
       </row>
      </tbody>
     </tgroup>
    </table>

   </sect2>

   <sect2 id="zoom.database.create"><title>Database Create</title>
    <para>
     For Database Create, <literal>type</literal> must be set to
     <literal>create</literal> in
     <function>ZOOM_package_send</function>.
    </para>

    <table frame="top" id="zoom.database.create.options">
     <title>Database Create Options</title>
     <tgroup cols="3">
      <colspec colwidth="4*" colname="name"></colspec>
      <colspec colwidth="7*" colname="description"></colspec>
      <colspec colwidth="3*" colname="default"></colspec>
      <thead>
       <row>
	<entry>Option</entry>
	<entry>Description</entry>
	<entry>Default</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>databaseName</entry>
	<entry>Database from connection object</entry>
	<entry>Default</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </sect2>
   <sect2 id="zoom.database.drop">
    <title>Database Drop</title>
    <para>
     For Database Drop, <literal>type</literal> must be set to
     <literal>drop</literal> in
     <function>ZOOM_package_send</function>.
    </para>
    <table frame="top" id="zoom.database.drop.options">
     <title>Database Drop Options</title>
     <tgroup cols="3">
      <colspec colwidth="4*" colname="name"></colspec>
      <colspec colwidth="7*" colname="description"></colspec>
      <colspec colwidth="3*" colname="default"></colspec>
      <thead>
       <row>
	<entry>Option</entry>
	<entry>Description</entry>
	<entry>Default</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>databaseName</entry>
	<entry>Database from connection object</entry>
	<entry>Default</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </sect2>
   <sect2 id="zoom.commit">
    <title>Commit Operation</title>
    <para>
     For Commit, <literal>type</literal> must be set to
     <literal>commit</literal> in
     <function>ZOOM_package_send</function>.
    </para>
   </sect2>
   <sect2 id="zoom.extended.services.behavior">
    <title>Protocol behavior</title>
    <para>
     All the extended services are Z39.50-only.
    </para>
    <note>
     <para>
      The database create, drop, and commit services are privately defined
      operations.
      Refer to <filename>esadmin.asn</filename> in YAZ for the ASN.1
      definitions.
     </para>
    </note>
   </sect2>
  </sect1>
  <sect1 id="zoom.options">
   <title>Options</title>
   <para>
    Most &zoom; objects provide a way to specify options to change behavior.
    From an implementation point of view, a set of options is just like
    an associative array / hash.
   </para>
   <synopsis>
     ZOOM_options ZOOM_options_create(void);

     ZOOM_options ZOOM_options_create_with_parent(ZOOM_options parent);

     void ZOOM_options_destroy(ZOOM_options opt);
   </synopsis>
   <synopsis>
     const char *ZOOM_options_get(ZOOM_options opt, const char *name);

     void ZOOM_options_set(ZOOM_options opt, const char *name,
                           const char *v);
   </synopsis>
   <synopsis>
     typedef const char *(*ZOOM_options_callback)
                            (void *handle, const char *name);

     ZOOM_options_callback
             ZOOM_options_set_callback(ZOOM_options opt,
                                       ZOOM_options_callback c,
                                       void *handle);
   </synopsis>
  </sect1>
  <sect1 id="zoom.queryconversions">
   <title>Query conversions</title>
   <synopsis>
    int ZOOM_query_cql2rpn(ZOOM_query s, const char *cql_str,
                           ZOOM_connection conn);

    int ZOOM_query_ccl2rpn(ZOOM_query s, const char *ccl_str,
                           const char *config,
                           int *ccl_error, const char **error_string,
                           int *error_pos);
   </synopsis>
   <para>
    <function>ZOOM_query_cql2rpn</function> translates the CQL string,
    client-side, into RPN which may be passed to the server.
    This is useful for servers that don't themselves
    support CQL, for which <function>ZOOM_query_cql</function> is useless.
    'conn' is used  only as a place to stash diagnostics if compilation
    fails; if this information is not needed, a null pointer may be used.
    The CQL conversion is driven by option <literal>cqlfile</literal> from
    connection conn. This specifies a conversion file (e.g. pqf.properties)
    which <emphasis>must</emphasis> be present.
   </para>
   <para>
    <function>ZOOM_query_ccl2rpn</function> translates the CCL string,
    client-side, into RPN which may be passed to the server.
    The conversion is driven by the specification given by
    <literal>config</literal>. Upon completion 0 is returned on success; -1
    is returned on failure. On failure <literal>error_string</literal> and
    <literal>error_pos</literal> hold the error message and position of
    first error in original CCL string.
   </para>
  </sect1>
  <sect1 id="zoom.events"><title>Events</title>
   <para>
    If you're developing non-blocking applications, you have to deal
    with events.
   </para>
   <synopsis>
    int ZOOM_event(int no, ZOOM_connection *cs);
   </synopsis>
   <para>
    The <function>ZOOM_event</function> executes pending events for
    a number of connections. Supply the number of connections in
    <literal>no</literal> and an array of connections in
    <literal>cs</literal> (<literal>cs[0] ... cs[no-1]</literal>).
    A pending event could be sending a search, receiving a response,
    etc.
    When an event has occurred for one of the connections, this function
    returns a positive integer <literal>n</literal> denoting that an event
    occurred for connection <literal>cs[n-1]</literal>.
    When no events are pending for the connections, a value of zero is
    returned.
    To ensure that all outstanding requests are performed, call this function
    repeatedly until zero is returned.
   </para>
   <para>
    If <function>ZOOM_event</function> returns, and returns non-zero, the
    last event that occurred can be expected.
   </para>
   <synopsis>
    int ZOOM_connection_last_event(ZOOM_connection cs);
   </synopsis>
   <para>
    <function>ZOOM_connection_last_event</function> returns an event type
    (integer) for the last event.
   </para>

   <table frame="top" id="zoom.event.ids">
    <title>ZOOM Event IDs</title>
    <tgroup cols="2">
     <colspec colwidth="4*" colname="name"></colspec>
     <colspec colwidth="7*" colname="description"></colspec>
     <thead>
      <row>
       <entry>Event</entry>
       <entry>Description</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>ZOOM_EVENT_NONE</entry>
       <entry>No event has occurred</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_CONNECT</entry>
       <entry>TCP/IP connect has initiated</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_SEND_DATA</entry>
       <entry>Data has been transmitted (sending)</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_RECV_DATA</entry>
       <entry>Data has been received</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_TIMEOUT</entry>
       <entry>Timeout</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_UNKNOWN</entry>
       <entry>Unknown event</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_SEND_APDU</entry>
       <entry>An APDU has been transmitted (sending)</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_RECV_APDU</entry>
       <entry>An APDU has been received</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_RECV_RECORD</entry>
       <entry>A result-set record has been received</entry>
      </row>
      <row>
       <entry>ZOOM_EVENT_RECV_SEARCH</entry>
       <entry>A search result has been received</entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </sect1>
 </chapter>
 <chapter id="server">
  <title>Generic server</title>
  <sect1 id="server.introduction"><title>Introduction</title>
   <para>
    If you aren't into documentation, a good way to learn how the
    back end interface works is to look at the <filename>backend.h</filename>
    file. Then, look at the small dummy-server in
    <filename>ztest/ztest.c</filename>. The <filename>backend.h</filename>
    file also makes a good reference, once you've chewed your way through
    the prose of this file.
   </para>
   <para>
    If you have a database system that you would like to make available by
    means of Z39.50 or SRU, &yaz; basically offers two options. You
    can use the APIs provided by the &asn;, &odr;, and &comstack;
    modules to
    create and decode PDUs, and exchange them with a client.
    Using this low-level interface gives you access to all fields and
    options of the protocol, and you can construct your server as close
    to your existing database as you like.
    It is also a fairly involved process, requiring
    you to set up an event-handling mechanism, protocol state machine,
    etc. To simplify server implementation, we have implemented a compact
    and simple, but reasonably full-functioned server-frontend that will
    handle most of the protocol mechanics, while leaving you to
    concentrate on your database interface.
   </para>
   <note>
    <para>
     The backend interface was designed in anticipation of a specific
     integration task, while still attempting to achieve some degree of
     generality. We realize fully that there are points where the
     interface can be improved significantly. If you have specific
     functions or parameters that you think could be useful, send us a
     mail (or better, sign on to the mailing list referred to in the
     top-level README file). We will try to fit good suggestions into future
     releases, to the extent that it can be done without requiring
     too many structural changes in existing applications.
    </para>
   </note>
   <note>
    <para>
     The &yaz; server does not support XCQL.
     </para>
   </note>
  </sect1>
  <sect1 id="server.frontend">
   <title>The Database Frontend</title>
   <para>
    We refer to this software as a generic database frontend. Your
    database system is the <emphasis>backend database</emphasis>, and the
    interface between the two is called the <emphasis>backend API</emphasis>.
    The backend API consists of a small number of function handlers and
    structure definitions. You are required to provide the
    <function>main()</function> routine for the server (which can be
    quite simple), as well as a set of handlers to match each of the
    prototypes.
    The interface functions that you write can use any mechanism you like
    to communicate with your database system: You might link the whole
    thing together with your database application and access it by
    function calls; you might use IPC to talk to a database server
    somewhere; or you might link with third-party software that handles
    the communication for you (like a commercial database client library).
    At any rate, the handlers will perform the tasks of:
   </para>
   <itemizedlist>
    <listitem><para>
     Initialization.
    </para></listitem>
    <listitem><para>
     Searching.
    </para></listitem>
    <listitem><para>
     Fetching records.
    </para></listitem>
    <listitem><para>
     Scanning the database index (optional - if you wish to implement SCAN).
    </para></listitem>
    <listitem><para>
     Extended Services (optional).
    </para></listitem>
    <listitem><para>
     Result-Set Delete (optional).
    </para></listitem>
    <listitem><para>
     Result-Set Sort (optional).
    </para></listitem>
    <listitem><para>
     Return Explain for SRU (optional).
    </para></listitem>
   </itemizedlist>
   <para>
    (more functions will be added in time to support as much of
    Z39.50-1995 as possible).
   </para>
  </sect1>
  <sect1 id="server.backend">
   <title>The Backend API</title>
   <para>
    The header file that you need to use the interface are in the
    <filename>include/yaz</filename> directory. It's called
    <filename>backend.h</filename>. It will include other files from
    the <filename>include/yaz</filename> directory, so you'll
    probably want to use the -I option of your compiler to tell it
    where to find the files. When you run
    <literal>make</literal> in the top-level &yaz; directory,
    everything you need to create your server is to link with the
    <filename>lib/libyaz.la</filename> library.
   </para>
  </sect1>
  <sect1 id="server.main">
   <title>Your main() Routine</title>
   <para>
    As mentioned, your <function>main()</function> routine can be quite brief.
    If you want to initialize global parameters, or read global configuration
    tables, this is the place to do it. At the end of the routine, you should
    call the function
   </para>
   <synopsis>
int statserv_main(int argc, char **argv,
                  bend_initresult *(*bend_init)(bend_initrequest *r),
                  void (*bend_close)(void *handle));
   </synopsis>
   <para>
    The third and fourth arguments are pointers to handlers. Handler
    <function>bend_init</function> is called whenever the server receives
    an Initialize Request, so it serves as a Z39.50 session initializer. The
    <function>bend_close</function> handler is called when the session is
    closed.
   </para>
   <para>
    <function>statserv_main</function> will establish listening sockets
    according to the parameters given. When connection requests are received,
    the event handler will typically <function>fork()</function> and
    create a sub-process to handle a new connection.
    Alternatively the server may be setup to create threads for each
    connection.
    If you do use global variables and forking, you should be aware, then,
    that these cannot be shared between associations, unless you explicitly
    disable forking by command line parameters.
   </para>
   <para>
    The server provides a mechanism for controlling some of its behavior
    without using command-line options. The function
   </para>
   <synopsis>
    statserv_options_block *statserv_getcontrol(void);
   </synopsis>
   <para>
    will return a pointer to a <literal>struct statserv_options_block</literal>
    describing the current default settings of the server. The structure
    contains these elements:
    <variablelist>
     <varlistentry>
      <term><literal>int dynamic</literal></term>
      <listitem><para>
       A boolean value, which determines whether the server
       will fork on each incoming request (TRUE), or not (FALSE). Default is
       TRUE. This flag is only read by UNIX-based servers (WIN32-based servers
       do not fork).
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>int threads</literal></term>
      <listitem><para>
       A boolean value, which determines whether the server
       will create a thread on each incoming request (TRUE), or not (FALSE).
       Default is FALSE. This flag is only read by UNIX-based servers
       that offer POSIX Threads support.
       WIN32-based servers always operate in threaded mode.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>int inetd</literal></term>
      <listitem><para>
       A boolean value, which determines whether the server
       will operate under a UNIX INET daemon (inetd). Default is FALSE.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>char logfile[ODR_MAXNAME+1]</literal></term>
      <listitem><para>File for diagnostic output (&quot;&quot;: stderr).
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>char apdufile[ODR_MAXNAME+1]</literal></term>
      <listitem><para>
       Name of file for logging incoming and outgoing APDUs
       (&quot;&quot;: don't log APDUs, &quot;-&quot;:
       <literal>stderr</literal>).
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>char default_listen[1024]</literal></term>
      <listitem><para>Same form as the command-line specification of
      listener address. &quot;&quot;: no default listener address.
      Default is to listen at &quot;tcp:@:9999&quot;. You can only
      specify one default listener address in this fashion.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>enum oid_proto default_proto;</literal></term>
      <listitem><para>Either <literal>PROTO_Z3950</literal> or
      <literal>PROTO_SR</literal>.
      Default is <literal>PROTO_Z39_50</literal>.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>int idle_timeout;</literal></term>
      <listitem><para>Maximum session idle-time, in minutes. Zero indicates
      no (infinite) timeout. Default is 15 minutes.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>int maxrecordsize;</literal></term>
      <listitem><para>Maximum permissible record (message) size. Default
      is 64 MB. This amount of memory will only be allocated if a
      client requests a very large amount of records in one operation
      (or a big record).
      Set it to a lower number if you are worried about resource
      consumption on your host system.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>char configname[ODR_MAXNAME+1]</literal></term>
      <listitem><para>Passed to the backend when a new connection is received.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>char setuid[ODR_MAXNAME+1]</literal></term>
      <listitem><para>Set user id to the user specified, after binding
      the listener addresses.
     </para></listitem>
     </varlistentry>
     <varlistentry>
      <term>
       <literal>void (*bend_start)(struct statserv_options_block *p)</literal>
      </term>
      <listitem><para>Pointer to function which is called after the
      command line options have been parsed - but before the server
      starts listening.
      For forked UNIX servers, this handler is called in the mother
      process; for threaded servers, this handler is called in the
      main thread.
      The default value of this pointer is NULL in which case it
      isn't invoked by the frontend server.
      When the server operates as an NT service, this handler is called
      whenever the service is started.
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term>
       <literal>void (*bend_stop)(struct statserv_options_block *p)</literal>
      </term>
      <listitem><para>Pointer to function which is called whenever the server
      has stopped listening for incoming connections. This function pointer
      has a default value of NULL in which case it isn't called.
      When the server operates as an NT service, this handler is called
      whenever the service is stopped.
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>void *handle</literal></term>
      <listitem><para>User defined pointer (default value NULL).
      This is a per-server handle that can be used to specify "user-data".
      Do not confuse this with the session-handle as returned by bend_init.
      </para></listitem>
     </varlistentry>
    </variablelist>
   </para>
   <para>
    The pointer returned by <literal>statserv_getcontrol</literal> points to
    a static area. You are allowed to change the contents of the structure,
    but the changes will not take effect until you call
   </para>
   <synopsis>
void statserv_setcontrol(statserv_options_block *block);
   </synopsis>
   <note>
    <para>
     You should generally update this structure before calling
     <function>statserv_main()</function>.
    </para>
   </note>
  </sect1>
  <sect1 id="server.backendfunctions">
   <title>The Backend Functions</title>
   <para>
    For each service of the protocol, the backend interface declares one or
    two functions. You are required to provide implementations of the
    functions representing the services that you wish to implement.
   </para>
   <sect2 id="server.init">
    <title>Init</title>
    <synopsis>
bend_initresult (*bend_init)(bend_initrequest *r);
    </synopsis>
    <para>
     This handler is called once for each new connection request, after
     a new process/thread has been created, and an Initialize Request has
     been received from the client. The pointer to the
     <function>bend_init</function> handler is passed in the call to
     <function>statserv_start</function>.
    </para>
    <para>
     This handler is also called when operating in SRU mode - when
     a connection has been made (even though SRU does not offer
     this service).
    </para>
    <para>
     Unlike previous versions of YAZ, the <function>bend_init</function> also
     serves as a handler that defines the Z39.50 services that the backend
     intends to support. Pointers to <emphasis>all</emphasis> service handlers,
     including search - and fetch must be specified here in this handler.
    </para>
    <para>
     The request - and result structures are defined as
    </para>
    <synopsis>
typedef struct bend_initrequest
{
    /** \brief user/name/password to be read */
    Z_IdAuthentication *auth;
    /** \brief encoding stream (for results) */
    ODR stream;
    /** \brief printing stream */
    ODR print;
    /** \brief decoding stream (use stream for results) */
    ODR decode;
    /** \brief reference ID */
    Z_ReferenceId *referenceId;
    /** \brief peer address of client */
    char *peer_name;

    /** \brief character set and language negotiation

    see include/yaz/z-charneg.h
    */
    Z_CharSetandLanguageNegotiation *charneg_request;

    /** \brief character negotiation response */
    Z_External *charneg_response;

    /** \brief character set (encoding) for query terms

    This is NULL by default. It should be set to the native character
    set that the backend assumes for query terms */
    char *query_charset;

    /** \brief whether query_charset also applies to records

    Is 0 (No) by default. Set to 1 (yes) if records is in the same
    character set as queries. If in doubt, use 0 (No).
    */
    int records_in_same_charset;

    char *implementation_id;
    char *implementation_name;
    char *implementation_version;

    /** \brief Z39.50 sort handler */
    int (*bend_sort)(void *handle, bend_sort_rr *rr);
    /** \brief SRU/Z39.50 search handler */
    int (*bend_search)(void *handle, bend_search_rr *rr);
    /** \brief SRU/Z39.50 fetch handler */
    int (*bend_fetch)(void *handle, bend_fetch_rr *rr);
    /** \brief SRU/Z39.50 present handler */
    int (*bend_present)(void *handle, bend_present_rr *rr);
    /** \brief Z39.50 extended services handler */
    int (*bend_esrequest) (void *handle, bend_esrequest_rr *rr);
    /** \brief Z39.50 delete result set handler */
    int (*bend_delete)(void *handle, bend_delete_rr *rr);
    /** \brief Z39.50 scan handler */
    int (*bend_scan)(void *handle, bend_scan_rr *rr);
    /** \brief Z39.50 segment facility handler */
    int (*bend_segment)(void *handle, bend_segment_rr *rr);
    /** \brief SRU explain handler */
    int (*bend_explain)(void *handle, bend_explain_rr *rr);
    /** \brief SRU scan handler */
    int (*bend_srw_scan)(void *handle, bend_scan_rr *rr);
    /** \brief SRU record update handler */
    int (*bend_srw_update)(void *handle, bend_update_rr *rr);

    /** \brief whether named result sets are supported (0=disable, 1=enable) */
    int named_result_sets;
} bend_initrequest;

typedef struct bend_initresult
{
    int errcode;               /* 0==OK */
    char *errstring;           /* system error string or NULL */
    void *handle;              /* private handle to the backend module */
} bend_initresult;
    </synopsis>
    <para>
     In general, the server frontend expects that the
     <literal>bend_*result</literal> pointer that you return is valid at
     least until the next call to a <literal>bend_* function</literal>.
     This applies to all of the functions described herein. The parameter
     structure passed to you in the call belongs to the server frontend, and
     you should not make assumptions about its contents after the current
     function call has completed. In other words, if you want to retain any
     of the contents of a request structure, you should copy them.
    </para>
    <para>
     The <literal>errcode</literal> should be zero if the initialization of
     the backend went well. Any other value will be interpreted as an error.
     The <literal>errstring</literal> isn't used in the current version, but
     one option would be to stick it in the initResponse as a VisibleString.
     The <literal>handle</literal> is the most important parameter. It should
     be set to some value that uniquely identifies the current session to
     the backend implementation. It is used by the frontend server in any
     future calls to a backend function.
     The typical use is to set it to point to a dynamically allocated state
     structure that is private to your backend module.
    </para>
    <para>
     The <literal>auth</literal> member holds the authentication information
     part of the Z39.50 Initialize Request. Interpret this if your server
     requires authentication.
    </para>
    <para>
     The members <literal>peer_name</literal>,
     <literal>implementation_id</literal>,
     <literal>implementation_name</literal> and
     <literal>implementation_version</literal> holds
     DNS of client, ID of implementor, name
     of client (Z39.50) implementation - and version.
    </para>
    <para>
     The <literal>bend_</literal> - members are set to NULL when
     <function>bend_init</function> is called. Modify the pointers by
     setting them to point to backend functions.
    </para>
   </sect2>
   <sect2 id="server.search.retrieve">
    <title>Search and Retrieve</title>
    <para>
     We now describe the handlers that are required to support search -
     and retrieve. You must support two functions - one for search - and one
     for fetch (retrieval of one record). If desirable you can provide a
     third handler which is called when a present request is received which
     allows you to optimize retrieval of multiple-records.
    </para>
    <synopsis>
int (*bend_search) (void *handle, bend_search_rr *rr);

typedef struct {
    char *setname;             /* name to give to this set */
    int replace_set;           /* replace set, if it already exists */
    int num_bases;             /* number of databases in list */
    char **basenames;          /* databases to search */
    Z_ReferenceId *referenceId;/* reference ID */
    Z_Query *query;            /* query structure */
    ODR stream;                /* encode stream */
    ODR decode;                /* decode stream */
    ODR print;                 /* print stream */

    bend_request request;
    bend_association association;
    int *fd;
    int hits;                  /* number of hits */
    int errcode;               /* 0==OK */
    char *errstring;           /* system error string or NULL */
    Z_OtherInformation *search_info; /* additional search info */
    char *srw_sortKeys;        /* holds SRU/SRW sortKeys info */
    char *srw_setname;         /* holds SRU/SRW generated resultsetID */
    int *srw_setnameIdleTime;  /* holds SRU/SRW life-time */
    int estimated_hit_count;   /* if hit count is estimated */
    int partial_resultset;     /* if result set is partial */
} bend_search_rr;
    </synopsis>
    <para>
     The <function>bend_search</function> handler is a fairly close
     approximation of a protocol Z39.50 Search Request - and Response PDUs.
     The <literal>setname</literal> is the resultSetName from the protocol.
     You are required to establish a mapping between the set name and whatever
     your backend database likes to use.
     Similarly, the <literal>replace_set</literal> is a boolean value
     corresponding to the resultSetIndicator field in the protocol.
     <literal>num_bases/basenames</literal> is a length of/array of character
     pointers to the database names provided by the client.
     The <literal>query</literal> is the full query structure as defined in
     the protocol ASN.1 specification.
     It can be either of the possible query types, and it's up to you to
     determine if you can handle the provided query type.
     Rather than reproduce the C interface here, we'll refer you to the
     structure definitions in the file
     <filename>include/yaz/z-core.h</filename>. If you want to look at the
     attributeSetId OID of the RPN query, you can either match it against
     your own internal tables, or you can use the <link linkend="tools.oid">
     OID tools</link>.
    </para>
    <para>
     The structure contains a number of hits, and an
     <literal>errcode/errstring</literal> pair. If an error occurs
     during the search, or if you're unhappy with the request, you should
     set the errcode to a value from the BIB-1 diagnostic set. The value
     will then be returned to the user in a nonsurrogate diagnostic record
     in the response. The <literal>errstring</literal>, if provided, will
     go in the addinfo field. Look at the protocol definition for the
     defined error codes, and the suggested uses of the addinfo field.
    </para>
    <para>
     The <function>bend_search</function> handler is also called when
     the frontend server receives a SRU SearchRetrieveRequest.
     For SRU, a CQL query is usually provided by the client.
     The CQL query is available as part of <literal>Z_Query</literal>
     structure (note that CQL is now part of Z39.50 via an external).
     To support CQL in existing implementations that only do Type-1,
     we refer to the CQL-to-PQF tool described
     <link linkend="cql.to.pqf">here</link>.
    </para>
    <para>
     To maintain backwards compatibility, the frontend server
     of yaz always assume that error codes are BIB-1 diagnostics.
     For SRU operation, a Bib-1 diagnostic code is mapped to
     SRU diagnostic.
    </para>
    <synopsis>
int (*bend_fetch) (void *handle, bend_fetch_rr *rr);

typedef struct bend_fetch_rr {
    char *setname;             /* set name */
    int number;                /* record number */
    Z_ReferenceId *referenceId;/* reference ID */
    Odr_oid *request_format;   /* format, transfer syntax (OID) */
    Z_RecordComposition *comp; /* Formatting instructions */
    ODR stream;                /* encoding stream - memory source if req */
    ODR print;                 /* printing stream */

    char *basename;            /* name of database that provided record */
    int len;                   /* length of record or -1 if structured */
    char *record;              /* record */
    int last_in_set;           /* is it?  */
    Odr_oid *output_format;    /* response format/syntax (OID) */
    int errcode;               /* 0==success */
    char *errstring;           /* system error string or NULL */
    int surrogate_flag;        /* surrogate diagnostic */
    char *schema;              /* string record schema input/output */
} bend_fetch_rr;
    </synopsis>
    <para>
     The frontend server calls the <function>bend_fetch</function> handler
     when it needs database records to fulfill a Z39.50 Search Request, a
     Z39.50 Present Request or a SRU SearchRetrieveRequest.
     The <literal>setname</literal> is simply the name of the result set
     that holds the reference to the desired record.
     The <literal>number</literal> is the offset into the set (with 1
     being the first record in the set). The <literal>format</literal> field
     is the record format requested by the client (See
     <xref linkend="tools.oid"/>).
     A value of NULL for <literal>format</literal> indicates that the
     client did not request a specific format.
     The <literal>stream</literal> argument is an &odr; stream which
     should be used for allocating space for structured data records.
     The stream will be reset when all records have been assembled, and
     the response package has been transmitted.
     For unstructured data, the backend is responsible for maintaining a
     static or dynamic buffer for the record between calls.
    </para>
    <para>
     If a SRU SearchRetrieveRequest is received by the frontend server,
     the <literal>referenceId</literal> is NULL and the
     <literal>format</literal> (transfer syntax) is the OID for XML.
     The schema for SRU is stored in both the
     <literal>Z_RecordComposition</literal>
     structure and <literal>schema</literal> (simple string).
    </para>
    <para>
     In the structure, the <literal>basename</literal> is the name of the
     database that holds the
     record. <literal>len</literal> is the length of the record returned, in
     bytes, and <literal>record</literal> is a pointer to the record.
     <literal>last_in_set</literal> should be nonzero only if the record
     returned is the last one in the given result set.
     <literal>errcode</literal> and <literal>errstring</literal>, if
     given, will be interpreted as a global error pertaining to the
     set, and will be returned in a non-surrogate-diagnostic.
     If you wish to return the error as a surrogate-diagnostic
     (local error) you can do this by setting
     <literal>surrogate_flag</literal> to 1 also.
    </para>
    <para>
     If the <literal>len</literal> field has the value -1, then
     <literal>record</literal> is assumed to point to a constructed data
     type. The <literal>format</literal> field will be used to determine
     which encoder should be used to serialize the data.
    </para>
    <note>
     <para>
      If your backend generates structured records, it should use
      <function>odr_malloc()</function> on the provided stream for allocating
      data: This allows the frontend server to keep track of the record sizes.
     </para>
    </note>
    <para>
     The <literal>format</literal> field is mapped to an object identifier
     in the direct reference of the resulting EXTERNAL representation
     of the record.
    </para>
    <note>
     <para>
      The current version of &yaz; only supports the direct reference mode.
     </para>
    </note>
    <synopsis>
int (*bend_present) (void *handle, bend_present_rr *rr);

typedef struct {
    char *setname;             /* set name */
    int start;
    int number;                /* record number */
    Odr_oid *format;           /* format, transfer syntax (OID) */
    Z_ReferenceId *referenceId;/* reference ID */
    Z_RecordComposition *comp; /* Formatting instructions */
    ODR stream;                /* encoding stream - memory source if required */
    ODR print;                 /* printing stream */
    bend_request request;
    bend_association association;

    int hits;                  /* number of hits */
    int errcode;               /* 0==OK */
    char *errstring;           /* system error string or NULL */
} bend_present_rr;
    </synopsis>
    <para>
     The <function>bend_present</function> handler is called when
     the server receives a Z39.50 Present Request.
     The <literal>setname</literal>,
     <literal>start</literal> and <literal>number</literal> is the
     name of the result set - start position - and number of records to
     be retrieved respectively. <literal>format</literal> and
     <literal>comp</literal> is the preferred transfer syntax and element
     specifications of the present request.
    </para>
    <para>
     Note that this is handler serves as a supplement for
     <function>bend_fetch</function> and need not to be defined in order to
     support search - and retrieve.
    </para>
   </sect2>
   <sect2 id="server.delete">
    <title>Delete</title>
    <para>
     For back-ends that supports delete of a result set, only one handler
     must be defined.
    </para>
    <synopsis>
int (*bend_delete)(void *handle, bend_delete_rr *rr);

typedef struct bend_delete_rr {
    int function;
    int num_setnames;
    char **setnames;
    Z_ReferenceId *referenceId;
    int delete_status;      /* status for the whole operation */
    int *statuses;          /* status each set - indexed as setnames */
    ODR stream;
    ODR print;
} bend_delete_rr;
    </synopsis>
    <note>
     <para>
      The delete set function definition is rather primitive, mostly because
      we have had no practical need for it as of yet. If someone wants
      to provide a full delete service, we'd be happy to add the
      extra parameters that are required. Are there clients out there
      that will actually delete sets they no longer need?
     </para>
    </note>
   </sect2>
   <sect2 id="server.scan">
    <title>Scan</title>
    <para>
     For servers that wish to offer the scan service one handler
     must be defined.
    </para>
    <synopsis>
int (*bend_scan)(void *handle, bend_scan_rr *rr);

typedef enum {
    BEND_SCAN_SUCCESS,  /* ok */
    BEND_SCAN_PARTIAL   /* not all entries could be found */
} bend_scan_status;

typedef struct bend_scan_rr {
    int num_bases;      /* number of elements in databaselist */
    char **basenames;   /* databases to search */
    Odr_oid *attributeset;
    Z_ReferenceId *referenceId; /* reference ID */
    Z_AttributesPlusTerm *term;
    ODR stream;         /* encoding stream - memory source if required */
    ODR print;          /* printing stream */

    int *step_size;     /* step size */
    int term_position;  /* desired index of term in result list/returned */
    int num_entries;    /* number of entries requested/returned */

    /* scan term entries. The called handler does not have
       to allocate this. Size of entries is num_entries (see above) */
    struct scan_entry *entries;
    bend_scan_status status;
    int errcode;
    char *errstring;
    char *scanClause;   /* CQL scan clause */
    char *setname;      /* Scan in result set (NULL if omitted) */
} bend_scan_rr;
    </synopsis>
   <para>
    This backend server handles both Z39.50 scan
    and SRU scan. In order for a handler to distinguish between SRU (CQL) scan
    Z39.50 Scan, it must check for a non-NULL value of
    <literal>scanClause</literal>.
   </para>
   <note>
    <para>
     If designed today, it would be a choice using a union or similar,
     but that would break binary compatibility with existing servers.
    </para>
    </note>
   </sect2>
  </sect1>
  <sect1 id="server.invocation">
   <title>Application Invocation</title>
   <para>
    The finished application has the following
    invocation syntax (by way of <function>statserv_main()</function>):
   </para>
   &gfs-synopsis;
   <para>
    The options are:
    &gfs-options;
   </para>
   <para>
    A listener specification consists of a transport mode followed by a
    colon (:) followed by a listener address. The transport mode is
    either <literal>tcp</literal>, <literal>unix:</literal> or
    <literal>ssl</literal>.
   </para>
   <para>
    For TCP and SSL, an address has the form
   </para>
   <synopsis>
    hostname | IP-number [: portnumber]
   </synopsis>
   <para>
    The port number defaults to 210 (standard Z39.50 port).
   </para>
   <para>
    For UNIX, the address is the filename of socket.
   </para>
   <para>
    For TCP/IP and SSL, the special hostnames <literal>@</literal>,
    maps to <literal>IN6ADDR_ANY_INIT</literal> with
    IPV4 binding as well (bindv6only=0),
    The special hostname <literal>@4</literal> binds to
    <literal>INADDR_ANY</literal> (IPV4 only listener).
    The special hostname <literal>@6</literal> binds to
    <literal>IN6ADDR_ANY_INIT</literal> with bindv6only=1 (IPV6 only listener).
   </para>
   <example id="server.example.running.unix">
    <title>Running the GFS on Unix</title>
    <para>
     Assuming the server application <replaceable>appname</replaceable> is
     started as root, the following will make it listen on port 210.
     The server will change identity to <literal>nobody</literal>
     and write its log to <filename>/var/log/app.log</filename>.
     <screen>
      application -l /var/log/app.log -u nobody tcp:@:210
     </screen>
    </para>
    <para>
     The server will accept Z39.50 requests and offer SRU service on port 210.
    </para>
   </example>
   <example id="server.example.apache.sru">
    <title>Setting up Apache as SRU Frontend</title>
    <para>
     If you use <ulink url="&url.apache;">Apache</ulink>
     as your public web server and want to offer HTTP port 80
     access to the YAZ server on 210, you can use the
     <ulink url="&url.apache.directive.proxypass;">
      <literal>ProxyPass</literal></ulink>
     directive.
     If you have virtual host
     <literal>srw.mydomain</literal> you can use the following directives
     in Apache's httpd.conf:
     <screen>
      &lt;VirtualHost *>
       ErrorLog /home/srw/logs/error_log
       TransferLog /home/srw/logs/access_log
       ProxyPass / http://srw.mydomain:210/
      &lt;/VirtualHost>
     </screen>
    </para>
    <para>
     The above is for the Apache 1.3 series.
    </para>
   </example>
   <example id="server.example.local.access">
    <title>Running a server with local access only</title>
    <para>
     A server that is only being accessed from the local host should listen
     on UNIX file socket rather than an Internet socket. To listen on
     <filename>/tmp/mysocket</filename> start the server as follows:
     <screen>
      application unix:/tmp/mysocket
     </screen>
    </para>
   </example>
  </sect1>
  <sect1 id="server.vhosts">
   <title>GFS Configuration and Virtual Hosts</title>
   &gfs-virtual;
  </sect1>
 </chapter>
 <chapter id="asn">
  <title>The Z39.50 ASN.1 Module</title>
  <sect1 id="asn.introduction">
   <title>Introduction</title>
   <para>
    The &asn; module provides you with a set of C struct definitions for the
    various PDUs of the Z39.50 protocol, as well as for the complex types
    appearing within the PDUs. For the primitive data types, the C
    representation often takes the form of an ordinary C language type,
    such as <literal>Odr_int</literal> which is equivalent to an integral
    C integer. For ASN.1 constructs that have no direct
    representation in C, such as general octet strings and bit strings,
    the &odr; module (see section <link linkend="odr">The ODR Module</link>)
    provides auxiliary definitions.
   </para>
   <para>
    The &asn; module is located in sub directory <filename>z39.50</filename>.
    There you'll find C files that implement encoders and decoders for the
    Z39.50 types. You'll also find the protocol definitions:
    <filename>z3950v3.asn</filename>, <filename>esupdate.asn</filename>,
    and others.
   </para>
  </sect1>
  <sect1 id="asn.preparing">
   <title>Preparing PDUs</title>
   <para>
    A structure representing a complex ASN.1 type doesn't in itself contain the
    members of that type. Instead, the structure contains
    <emphasis>pointers</emphasis> to the members of the type.
    This is necessary, in part, to allow a mechanism for specifying which
    of the optional structure (SEQUENCE) members are present, and which
    are not. It follows that you will need to somehow provide space for
    the individual members of the structure, and set the pointers to
    refer to the members.
   </para>
   <para>
    The conversion routines don't care how you allocate and maintain your
    C structures - they just follow the pointers that you provide.
    Depending on the complexity of your application, and your personal
    taste, there are at least three different approaches that you may take
    when you allocate the structures.
   </para>
   <para>
    You can use static or automatic local variables in the function that
    prepares the PDU. This is a simple approach, and it provides the most
    efficient form of memory management. While it works well for flat
    PDUs like the InitRequest, it will generally not be sufficient for say,
    the generation of an arbitrarily complex RPN query structure.
   </para>
   <para>
    You can individually create the structure and its members using the
    <function>malloc(2)</function> function. If you want to ensure that
    the data is freed when it is no longer needed, you will have to
    define a function that individually releases each member of a
    structure before freeing the structure itself.
   </para>
   <para>
    You can use the <function>odr_malloc()</function> function (see
    <xref linkend="odr.use"/> for details). When you use
    <function>odr_malloc()</function>, you can release all of the
    allocated data in a single operation, independent of any pointers and
    relations between the data. The <function>odr_malloc()</function> function
    is based on a &quot;nibble-memory&quot;
    scheme, in which large portions of memory are allocated, and then
    gradually handed out with each call to <function>odr_malloc()</function>.
    The next time you call <function>odr_reset()</function>, all of the
    memory allocated since the last call is recycled for future use (actually,
    it is placed on a free-list).
   </para>
   <para>
    You can combine all of the methods described here. This will often be
    the most practical approach. For instance, you might use
    <function>odr_malloc()</function> to allocate an entire structure and
    some of its elements, while you leave other elements pointing to global
    or per-session default variables.
   </para>
   <para>
    The &asn; module provides an important aid in creating new PDUs. For
    each of the PDU types (say, <function>Z_InitRequest</function>), a
    function is provided that allocates and initializes an instance of
    that PDU type for you. In the case of the InitRequest, the function is
    simply named <function>zget_InitRequest()</function>, and it sets up
    reasonable default value for all of the mandatory members. The optional
    members are generally initialized to null pointers. This last aspect
    is very important: it ensures that if the PDU definitions are
    extended after you finish your implementation (to accommodate
    new versions of the protocol, say), you won't get into trouble with
    uninitialized pointers in your structures. The functions use
    <function>odr_malloc()</function> to
    allocate the PDUs and its members, so you can free everything again with a
    single call to <function>odr_reset()</function>. We strongly recommend
    that you use the <literal>zget_*</literal>
    functions whenever you are preparing a PDU (in a C++ API, the
    <literal>zget_</literal>
    functions would probably be promoted to constructors for the
    individual types).
   </para>
   <para>
   The prototype for the individual PDU types generally look like this:
   </para>
   <synopsis>
    Z_&lt;type> *zget_&lt;type>(ODR o);
   </synopsis>
   <para>
    e.g.:
   </para>
   <synopsis>
    Z_InitRequest *zget_InitRequest(ODR o);
   </synopsis>
   <para>
   The &odr; handle should generally be your encoding stream, but it
    needn't be.
   </para>
   <para>
    As well as the individual PDU functions, a function
    <function>zget_APDU()</function> is provided, which allocates
    a top-level Z-APDU of the type requested:
   </para>
   <synopsis>
    Z_APDU *zget_APDU(ODR o, int which);
   </synopsis>
   <para>
    The <varname>which</varname> parameter is (of course) the discriminator
    belonging to the <varname>Z_APDU</varname> <literal>CHOICE</literal> type.
    All of the interface described here is provided by the &asn; module, and
    you access it through the <filename>proto.h</filename> header file.
   </para>
  </sect1>
  <sect1 id="asn.external">
   <title>EXTERNAL Data</title>
   <para>
    In order to achieve extensibility and adaptability to different
    application domains, the new version of the protocol defines many
    structures outside of the main ASN.1 specification, referencing them
    through ASN.1 EXTERNAL constructs. To simplify the construction and
    access to the externally referenced data, the &asn; module defines a
    specialized version of the EXTERNAL construct, called
    <literal>Z_External</literal>.It is defined thus:
   </para>
   <screen>
typedef struct Z_External
{
    Odr_oid *direct_reference;
    int *indirect_reference;
    char *descriptor;
    enum
    {
        /* Generic types */
        Z_External_single = 0,
        Z_External_octet,
        Z_External_arbitrary,

        /* Specific types */
        Z_External_SUTRS,
        Z_External_explainRecord,
        Z_External_resourceReport1,
        Z_External_resourceReport2

    ...

    } which;
    union
    {
        /* Generic types */
        Odr_any *single_ASN1_type;
        Odr_oct *octet_aligned;
        Odr_bitmask *arbitrary;

        /* Specific types */
        Z_SUTRS *sutrs;
        Z_ExplainRecord *explainRecord;
        Z_ResourceReport1 *resourceReport1;
        Z_ResourceReport2 *resourceReport2;

        ...

    } u;
} Z_External;
   </screen>
   <para>
    When decoding, the &asn; module will attempt to determine which
    syntax describes the data by looking at the reference fields
    (currently only the direct-reference). For ASN.1 structured data, you
    need only consult the <literal>which</literal> field to determine the
    type of data. You can the access  the data directly through the union.
    When constructing data for encoding, you set the union pointer to point
    to the data, and set the <literal>which</literal> field accordingly.
    Remember also to set the direct (or indirect) reference to the correct
    OID for the data type.
    For non-ASN.1 data such as MARC records, use the
    <literal>octet_aligned</literal> arm of the union.
   </para>
   <para>
    Some servers return ASN.1 structured data values (e.g. database
    records) as BER-encoded records placed in the
    <literal>octet-aligned</literal> branch of the EXTERNAL CHOICE.
    The ASN-module will <emphasis>not</emphasis> automatically decode
    these records. To help you decode the records in the application, the
    function
   </para>
   <screen>
   Z_ext_typeent *z_ext_gettypebyref(const oid *oid);
   </screen>
   <para>
    can be used to retrieve information about the known, external data
    types. The function returns a pointer to a static area, or NULL, if no
    match for the given direct reference is found. The
    <literal>Z_ext_typeent</literal>
    is defined as:
   </para>
   <screen>
typedef struct Z_ext_typeent
{
    int oid[OID_SIZE]; /* the direct-reference OID. */
    int what;          /* discriminator value for the external CHOICE */
    Odr_fun fun;       /* decoder function */
} Z_ext_typeent;
   </screen>
   <para>
    The <literal>what</literal> member contains the
    <literal>Z_External</literal> union discriminator value for the
    given type: For the SUTRS record syntax, the value would be
    <literal>Z_External_sutrs</literal>.
    The <literal>fun</literal> member contains a pointer to the
    function which encodes/decodes the given type. Again, for the SUTRS
    record syntax, the value of <literal>fun</literal> would be
    <literal>z_SUTRS</literal> (a function pointer).
   </para>
   <para>
    If you receive an EXTERNAL which contains an octet-string value that
    you suspect of being an ASN.1-structured data value, you can use
    <literal>z_ext_gettypebyref</literal> to look for the provided
    direct-reference.
    If the return value is different from NULL, you can use the provided
    function to decode the BER string (see <xref linkend="odr.use"/>
    ).
   </para>
   <para>
    If you want to <emphasis>send</emphasis> EXTERNALs containing
    ASN.1-structured values in the octet-aligned branch of the CHOICE, this
    is possible too. However, on the encoding phase, it requires a somewhat
    involved juggling around of the various buffers involved.
   </para>
   <para>
    If you need to add new, externally defined data types, you must update
    the struct above, in the source file <filename>prt-ext.h</filename>, as
    well as the encoder/decoder in the file <filename>prt-ext.c</filename>.
    When changing the latter, remember to update both the
    <literal>arm</literal> array and the list
    <literal>type_table</literal>, which drives the CHOICE biasing that
    is necessary to tell the different, structured types apart
    on decoding.
   </para>
   <note>
    <para>
     Eventually, the EXTERNAL processing will most likely
     automatically insert the correct OIDs or indirect-refs. First,
     however, we need to determine how application-context management
     (specifically the presentation-context-list) should fit into the
     various modules.
    </para>
   </note>
  </sect1>
  <sect1 id="asn.pdu">
   <title>PDU Contents Table</title>
   <para>
    We include, for reference, a listing of the fields of each top-level
    PDU, as well as their default settings.
   </para>
   <table frame="top" id="asn.default.initialize.request">
    <title>Default settings for PDU Initialize Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
    <thead>
     <row>
      <entry>Field</entry>
      <entry>Type</entry>
      <entry>Default Value</entry>
     </row>
    </thead>
    <tbody>
     <row><entry>
      referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
     </entry></row>
     <row><entry>
      protocolVersion</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
     </entry></row>
     <row><entry>
      options</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
     </entry></row>
     <row><entry>
      preferredMessageSize</entry><entry>Odr_int</entry><entry>30*1024
     </entry></row>
     <row><entry>
      maximumRecordSize</entry><entry>Odr_int</entry><entry>30*1024
     </entry></row>
     <row><entry>
      idAuthentication</entry><entry>Z_IdAuthentication</entry><entry>NULL
     </entry></row>
     <row><entry>
      implementationId</entry><entry>char*</entry><entry>"81"
     </entry></row>
     <row><entry>
      implementationName</entry><entry>char*</entry><entry>"YAZ"
     </entry></row>
     <row><entry>
      implementationVersion</entry><entry>char*</entry><entry>YAZ_VERSION
     </entry></row>
     <row><entry>
      userInformationField</entry><entry>Z_UserInformation</entry><entry>NULL
     </entry></row>
     <row><entry>
      otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
     </entry></row>
    </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.initialize.response">
    <title>Default settings for PDU Initialize Response</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
       referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
      </entry></row>
      <row><entry>
       protocolVersion</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
      </entry></row>
      <row><entry>
       options</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
      </entry></row>
      <row><entry>
       preferredMessageSize</entry><entry>Odr_int</entry><entry>30*1024
      </entry></row>
      <row><entry>
       maximumRecordSize</entry><entry>Odr_int</entry><entry>30*1024
      </entry></row>
      <row><entry>
       result</entry><entry>Odr_bool</entry><entry>TRUE
      </entry></row>
      <row><entry>
       implementationId</entry><entry>char*</entry><entry>"id)"
      </entry></row>
      <row><entry>
       implementationName</entry><entry>char*</entry><entry>"YAZ"
      </entry></row>
      <row><entry>
       implementationVersion</entry><entry>char*</entry><entry>YAZ_VERSION
      </entry></row>
      <row><entry>
       userInformationField</entry><entry>Z_UserInformation</entry><entry>NULL
      </entry></row>
      <row><entry>
       otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
      </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.search.request">
    <title>Default settings for PDU Search Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	smallSetUpperBound</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	largeSetLowerBound</entry><entry>Odr_int</entry><entry>1
       </entry></row>
      <row><entry>
	mediumSetPresentNumber</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	replaceIndicator</entry><entry>Odr_bool</entry><entry>TRUE
       </entry></row>
      <row><entry>
	resultSetName</entry><entry>char *</entry><entry>"default"
       </entry></row>
      <row><entry>
	num_databaseNames</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	databaseNames</entry><entry>char **</entry><entry>NULL
       </entry></row>
      <row><entry>
	smallSetElementSetNames</entry><entry>Z_ElementSetNames
       </entry><entry>NULL
       </entry></row>
      <row><entry>
	mediumSetElementSetNames</entry><entry>Z_ElementSetNames
       </entry><entry>NULL
       </entry></row>
      <row><entry>
	preferredRecordSyntax</entry><entry>Odr_oid</entry><entry>NULL
       </entry></row>
      <row><entry>
	query</entry><entry>Z_Query</entry><entry>NULL
       </entry></row>
      <row><entry>
	additionalSearchInfo</entry><entry>Z_OtherInformation
       </entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.search.response">
    <title>Default settings for PDU Search Response</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
       referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
      </entry></row>
      <row><entry>
       resultCount</entry><entry>Odr_int</entry><entry>0
      </entry></row>
      <row><entry>
       numberOfRecordsReturned</entry><entry>Odr_int</entry><entry>0
      </entry></row>
      <row><entry>
       nextResultSetPosition</entry><entry>Odr_int</entry><entry>0
      </entry></row>
      <row><entry>
       searchStatus</entry><entry>Odr_bool</entry><entry>TRUE
      </entry></row>
      <row><entry>
       resultSetStatus</entry><entry>Odr_int</entry><entry>NULL
      </entry></row>
      <row><entry>
       presentStatus</entry><entry>Odr_int</entry><entry>NULL
      </entry></row>
      <row><entry>
       records</entry><entry>Z_Records</entry><entry>NULL
      </entry></row>
      <row><entry>
       additionalSearchInfo</entry>
       <entry>Z_OtherInformation</entry><entry>NULL
      </entry></row>
      <row><entry>
       otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
      </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.present.request">
    <title>Default settings for PDU Present Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	resultSetId</entry><entry>char*</entry><entry>"default"
       </entry></row>
      <row><entry>
	resultSetStartPoint</entry><entry>Odr_int</entry><entry>1
       </entry></row>
      <row><entry>
	numberOfRecordsRequested</entry><entry>Odr_int</entry><entry>10
       </entry></row>
      <row><entry>
	num_ranges</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	additionalRanges</entry><entry>Z_Range</entry><entry>NULL
       </entry></row>
      <row><entry>
	recordComposition</entry><entry>Z_RecordComposition</entry><entry>NULL
       </entry></row>
      <row><entry>
	preferredRecordSyntax</entry><entry>Odr_oid</entry><entry>NULL
       </entry></row>
      <row><entry>
	maxSegmentCount</entry><entry>Odr_int</entry><entry>NULL
       </entry></row>
      <row><entry>
	maxRecordSize</entry><entry>Odr_int</entry><entry>NULL
       </entry></row>
      <row><entry>
	maxSegmentSize</entry><entry>Odr_int</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.present.response">
    <title>Default settings for PDU Present Response</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	numberOfRecordsReturned</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	nextResultSetPosition</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	presentStatus</entry><entry>Odr_int</entry><entry>Z_PresentStatus_success
       </entry></row>
      <row><entry>
	records</entry><entry>Z_Records</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.delete.result.set.request">
    <title>Default settings for Delete Result Set Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>referenceId
       </entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	deleteFunction</entry><entry>Odr_int</entry><entry>Z_DeleteResultSetRequest_list
       </entry></row>
      <row><entry>
	num_ids</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	resultSetList</entry><entry>char**</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.delete.result.set.response">
    <title>Default settings for Delete Result Set Response</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	deleteOperationStatus</entry><entry>Odr_int</entry>
       <entry>Z_DeleteStatus_success</entry></row>
      <row><entry>
	num_statuses</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	deleteListStatuses</entry><entry>Z_ListStatus**</entry><entry>NULL
       </entry></row>
      <row><entry>
	numberNotDeleted</entry><entry>Odr_int</entry><entry>NULL
       </entry></row>
      <row><entry>
	num_bulkStatuses</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	bulkStatuses</entry><entry>Z_ListStatus</entry><entry>NULL
	</entry></row>
      <row><entry>
	deleteMessage</entry><entry>char*</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.scan.request">
    <title>Default settings for Scan Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	num_databaseNames</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	databaseNames</entry><entry>char**</entry><entry>NULL
       </entry></row>
      <row><entry>
	attributeSet</entry><entry>Odr_oid</entry><entry>NULL
       </entry></row>
      <row><entry>
	termListAndStartPoint</entry><entry>Z_AttributesPlus...
       </entry><entry>NULL</entry></row>
      <row><entry>
	stepSize</entry><entry>Odr_int</entry><entry>NULL
       </entry></row>
      <row><entry>
	numberOfTermsRequested</entry><entry>Odr_int</entry><entry>20
       </entry></row>
      <row><entry>
	preferredPositionInResponse</entry><entry>Odr_int</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.scan.response">
    <title>Default settings for Scan Response</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
       referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
      </entry></row>
      <row><entry>
       stepSize</entry><entry>Odr_int</entry><entry>NULL
      </entry></row>
      <row><entry>
       scanStatus</entry><entry>Odr_int</entry><entry>Z_Scan_success
      </entry></row>
      <row><entry>
       numberOfEntriesReturned</entry><entry>Odr_int</entry><entry>0
      </entry></row>
      <row><entry>
       positionOfTerm</entry><entry>Odr_int</entry><entry>NULL
      </entry></row>
      <row><entry>
       entries</entry><entry>Z_ListEntries</entry><entry>NULL
      </entry></row>
      <row><entry>
       attributeSet</entry><entry>Odr_oid</entry><entry>NULL
      </entry></row>
      <row><entry>
       otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
      </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.trigger.resource.control.request">
    <title>Default settings for Trigger Resource Control Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	requestedAction</entry><entry>Odr_int</entry><entry>
	Z_TriggerResourceCtrl_resou..
       </entry></row>
      <row><entry>
	prefResourceReportFormat</entry><entry>Odr_oid</entry><entry>NULL
       </entry></row>
      <row><entry>
	resultSetWanted</entry><entry>Odr_bool</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.resource.control.request">
    <title>Default settings for Resource Control Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	suspendedFlag</entry><entry>Odr_bool</entry><entry>NULL
       </entry></row>
      <row><entry>
	resourceReport</entry><entry>Z_External</entry><entry>NULL
       </entry></row>
      <row><entry>
	partialResultsAvailable</entry><entry>Odr_int</entry><entry>NULL
       </entry></row>
      <row><entry>
	responseRequired</entry><entry>Odr_bool</entry><entry>FALSE
       </entry></row>
      <row><entry>
	triggeredRequestFlag</entry><entry>Odr_bool</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.resource.control.response">
    <title>Default settings for Resource Control Response</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	continueFlag</entry><entry>bool_t</entry><entry>TRUE
       </entry></row>
      <row><entry>
	resultSetWanted</entry><entry>bool_t</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.access.control.request">
    <title>Default settings for Access Control Request</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	which</entry><entry>enum</entry><entry>Z_AccessRequest_simpleForm;
       </entry></row>
      <row><entry>
	u</entry><entry>union</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.access.control.response">
    <title>Default settings for Access Control Response</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	which</entry><entry>enum</entry><entry>Z_AccessResponse_simpleForm
       </entry></row>
      <row><entry>
	u</entry><entry>union</entry><entry>NULL
       </entry></row>
      <row><entry>
	diagnostic</entry><entry>Z_DiagRec</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.segment">
    <title>Default settings for Segment</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	numberOfRecordsReturned</entry><entry>Odr_int</entry><entry>value=0
       </entry></row>
      <row><entry>
	num_segmentRecords</entry><entry>Odr_int</entry><entry>0
       </entry></row>
      <row><entry>
	segmentRecords</entry><entry>Z_NamePlusRecord</entry><entry>NULL
       </entry></row>
      <row><entry>otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
   <table frame="top" id="asn.default.close">
    <title>Default settings for Close</title>
    <tgroup cols="3">
     <colspec colwidth="7*" colname="field"></colspec>
     <colspec colwidth="5*" colname="type"></colspec>
     <colspec colwidth="7*" colname="value"></colspec>
     <thead>
      <row>
       <entry>Field</entry>
       <entry>Type</entry>
       <entry>Default Value</entry>
      </row>
     </thead>
     <tbody>
      <row><entry>
	referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
       </entry></row>
      <row><entry>
	closeReason</entry><entry>Odr_int</entry><entry>Z_Close_finished
       </entry></row>
      <row><entry>
	diagnosticInformation</entry><entry>char*</entry><entry>NULL
       </entry></row>
      <row><entry>
	resourceReportFormat</entry><entry>Odr_oid</entry><entry>NULL
       </entry></row>
      <row><entry>
	resourceFormat</entry><entry>Z_External</entry><entry>NULL
       </entry></row>
      <row><entry>
	otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
       </entry></row>
     </tbody>
    </tgroup>
   </table>
  </sect1>
 </chapter>
 <chapter id="soap">
  <title>SOAP and SRU</title>
  <sect1 id="soap.introduction">
   <title>Introduction</title>
   <para>
    &yaz; uses a very simple implementation of
    <ulink url="&url.soap;">SOAP</ulink> that only
    (currently) supports what is sufficient to offer SRU SOAP functionality.
    The implementation uses the
    <ulink url="&url.libxml2.api.tree;">tree API</ulink> of
    libxml2 to encode and decode SOAP packages.
   </para>
   <para>
    Like the Z39.50 ASN.1 module, the &yaz; SRU implementation uses
    simple C structs to represent SOAP packages as well as
    HTTP packages.
   </para>
  </sect1>
  <sect1 id="soap.http">
   <title>HTTP</title>
   <para>
    &yaz; only offers HTTP as transport carrier for SOAP, but it is
    relatively easy to change that.
   </para>
   <para>
    The following definition of <literal>Z_GDU</literal> (Generic Data
    Unit) allows for both HTTP and Z39.50 in one packet.
   </para>
   <synopsis>
#include &lt;yaz/zgdu.h&gt;

#define Z_GDU_Z3950         1
#define Z_GDU_HTTP_Request  2
#define Z_GDU_HTTP_Response 3
typedef struct {
  int which;
  union {
    Z_APDU *z3950;
    Z_HTTP_Request *HTTP_Request;
    Z_HTTP_Response *HTTP_Response;
  } u;
} Z_GDU ;
   </synopsis>
   <para>
    The corresponding Z_GDU encoder/decoder is <function>z_GDU</function>.
    The <literal>z3950</literal> is any of the known BER encoded Z39.50
    APDUs.
    <literal>HTTP_Request</literal> and <literal>HTTP_Response</literal>
    is the HTTP Request and Response respectively.
   </para>
  </sect1>
  <sect1 id="soap.xml">
   <title>SOAP Packages</title>
   <para>
    Every SOAP package in &yaz; is represented as follows:
    <synopsis>
#include &lt;yaz/soap.h&gt;

typedef struct {
    char *fault_code;
    char *fault_string;
    char *details;
} Z_SOAP_Fault;

typedef struct {
    int no;
    char *ns;
    void *p;
} Z_SOAP_Generic;

#define Z_SOAP_fault 1
#define Z_SOAP_generic 2
#define Z_SOAP_error 3
typedef struct {
    int which;
    union {
        Z_SOAP_Fault   *fault;
        Z_SOAP_Generic *generic;
        Z_SOAP_Fault   *soap_error;
    } u;
    const char *ns;
} Z_SOAP;
    </synopsis>
   </para>
   <para>
    The <literal>fault</literal> and <literal>soap_error</literal>
    arms both represent a SOAP fault - struct
    <literal>Z_SOAP_Fault</literal>. Any other generic
    (valid) package is represented by <literal>Z_SOAP_Generic</literal>.
   </para>
   <para>
    The <literal>ns</literal> as part of <literal>Z_SOAP</literal>
    is the namespace for SOAP itself and reflects the SOAP
    version. For version 1.1 it is
    <literal>http://schemas.xmlsoap.org/soap/envelope/</literal>,
    for version 1.2 it is
    <literal>http://www.w3.org/2001/06/soap-envelope</literal>.
   </para>
   <synopsis>
int z_soap_codec(ODR o, Z_SOAP **pp,
                 char **content_buf, int *content_len,
                 Z_SOAP_Handler *handlers);
   </synopsis>
   <para>
    The <literal>content_buf</literal> and <literal>content_len</literal>
    is XML buffer and length of buffer respectively.
   </para>
   <para>
    The <literal>handlers</literal> is a list of SOAP codec
    handlers - one handler for each service namespace. For SRU SOAP, the
    namespace would be <literal>http://www.loc.gov/zing/srw/v1.0/</literal>.
   </para>
   <para>
    When decoding, the <function>z_soap_codec</function>
    inspects the XML content
    and tries to match one of the services namespaces of the
    supplied handlers. If there is a match. a handler function
    is invoked which decodes that particular SOAP package.
    If successful, the returned <literal>Z_SOAP</literal> package will be
    of type <literal>Z_SOAP_Generic</literal>.
    Member <literal>no</literal> is
    set the offset of the handler that matched; <literal>ns</literal>
    is set to namespace of the matching handler; the void pointer
    <literal>p</literal> is set to the C data structure associated
    with the handler.
   </para>
   <para>
    When a NULL namespace is met (member <literal>ns</literal> below),
    that specifies end-of-list.
   </para>
   <para>
    Each handler is defined as follows:
    <synopsis>
typedef struct {
    char *ns;
    void *client_data;
    Z_SOAP_fun f;
} Z_SOAP_Handler;
    </synopsis>
    The <literal>ns</literal> is the namespace of the service associated with
    handler <literal>f</literal>. The <literal>client_data</literal>
    is user-defined data which is passed to the handler.
   </para>
   <para>
    The prototype for a SOAP service handler is:
    <synopsis>
int handler(ODR o, void * ptr, void **handler_data,
            void *client_data, const char *ns);
    </synopsis>
    The <parameter>o</parameter> specifies the mode (decode/encode)
    as usual. The second argument, <parameter>ptr</parameter>,
    is a libxml2 tree node pointer (<literal>xmlNodePtr</literal>)
    and is a pointer to the <literal>Body</literal> element
    of the SOAP package. The <parameter>handler_data</parameter>
    is an opaque pointer to C definitions associated with the
    SOAP service. The <parameter>client_data</parameter> is the pointer
    which was set as part of the <literal>Z_SOAP_handler</literal>.
    Finally, <parameter>ns</parameter> is the service namespace.
   </para>
  </sect1>
  <sect1 id="soap.srw">
   <title>SRU</title>
   <para>
    SRU SOAP is just one implementation of a SOAP handler as described
    in the previous section.
    The encoder/decoder handler for SRU is defined as
    follows:
    <synopsis>
#include &lt;yaz/srw.h&gt;

int yaz_srw_codec(ODR o, void * pptr,
                  Z_SRW_GDU **handler_data,
                  void *client_data, const char *ns);
    </synopsis>
    Here, <literal>Z_SRW_GDU</literal> is either
    searchRetrieveRequest or a searchRetrieveResponse.
   </para>
   <note>
    <para>
     The xQuery and xSortKeys are not handled yet by
     the SRW implementation of &yaz;. Explain is also missing.
     Future versions of &yaz; will include these features.
    </para>
   </note>
   <para>
    The definition of searchRetrieveRequest is:
    <synopsis>
typedef struct {

#define Z_SRW_query_type_cql  1
#define Z_SRW_query_type_xcql 2
#define Z_SRW_query_type_pqf  3
    int query_type;
    union {
        char *cql;
        char *xcql;
        char *pqf;
    } query;

#define Z_SRW_sort_type_none 1
#define Z_SRW_sort_type_sort 2
#define Z_SRW_sort_type_xSort 3
    int sort_type;
    union {
        char *none;
        char *sortKeys;
        char *xSortKeys;
    } sort;
    int  *startRecord;
    int  *maximumRecords;
    char *recordSchema;
    char *recordPacking;
    char *database;
} Z_SRW_searchRetrieveRequest;
    </synopsis>
    Please observe that data of type xsd:string is represented
    as a char pointer (<literal>char *</literal>). A null pointer
    means that the element is absent.
    Data of type xsd:integer is represented as a pointer to
    an int (<literal>int *</literal>). Again, a null pointer
    is used for absent elements.
   </para>
   <para>
    The SearchRetrieveResponse has the following definition.
    <synopsis>
typedef struct {
    int * numberOfRecords;
    char * resultSetId;
    int * resultSetIdleTime;

    Z_SRW_record *records;
    int num_records;

    Z_SRW_diagnostic *diagnostics;
    int num_diagnostics;
    int *nextRecordPosition;
} Z_SRW_searchRetrieveResponse;
    </synopsis>
    The <literal>num_records</literal> and <literal>num_diagnostics</literal>
    is number of returned records and diagnostics respectively, and also
    correspond to the "size of" arrays <literal>records</literal>
    and <literal>diagnostics</literal>.
   </para>
   <para>
    A retrieval record is defined as follows:
    <synopsis>
typedef struct {
    char *recordSchema;
    char *recordData_buf;
    int recordData_len;
    int *recordPosition;
} Z_SRW_record;
    </synopsis>
    The record data is defined as a buffer of some length so that
    data can be of any type. SRW 1.0 currently doesn't allow for this
    (only XML), but future versions might do.
   </para>
   <para>
    And, a diagnostic as:
    <synopsis>
typedef struct {
    int  *code;
    char *details;
} Z_SRW_diagnostic;
    </synopsis>
   </para>
  </sect1>
 </chapter>
 <chapter id="tools">
  <title>Supporting Tools</title>
  <para>
   In support of the service API - primarily the ASN module, which
   provides the programmatic interface to the Z39.50 APDUs, &yaz; contains
   a collection of tools that support the development of applications.
  </para>
  <sect1 id="tools.query">
   <title>Query Syntax Parsers</title>
   <para>
    Since the type-1 (RPN) query structure has no direct, useful string
    representation, every origin application needs to provide some form of
    mapping from a local query notation or representation to a
    <token>Z_RPNQuery</token> structure. Some programmers will prefer to
    construct the query manually, perhaps using
    <function>odr_malloc()</function> to simplify memory management.
    The &yaz; distribution includes three separate, query-generating tools
    that may be of use to you.
   </para>
   <sect2 id="PQF">
    <title>Prefix Query Format</title>
    <para>
     Since RPN or reverse polish notation is really just a fancy way of
     describing a suffix notation format (operator follows operands), it
     would seem that the confusion is total when we now introduce a prefix
     notation for RPN. The reason is one of simple laziness - it's somewhat
     simpler to interpret a prefix format, and this utility was designed
     for maximum simplicity, to provide a baseline representation for use
     in simple test applications and scripting environments (like Tcl). The
     demonstration client included with YAZ uses the PQF.
    </para>
    <note>
     <para>
      The PQF has been adopted by other parties developing Z39.50
      software. It is often referred to as Prefix Query Notation
      - PQN.
     </para>
    </note>
    <para>
     The PQF is defined by the pquery module in the YAZ library.
     There are two sets of functions that have similar behavior. First
     set operates on a PQF parser handle, second set doesn't. First set
     of functions are more flexible than the second set. Second set
     is obsolete and is only provided to ensure backwards compatibility.
    </para>
    <para>
     First set of functions all operate on a PQF parser handle:
    </para>
    <synopsis>
     #include &lt;yaz/pquery.h&gt;

     YAZ_PQF_Parser yaz_pqf_create(void);

     void yaz_pqf_destroy(YAZ_PQF_Parser p);

     Z_RPNQuery *yaz_pqf_parse(YAZ_PQF_Parser p, ODR o, const char *qbuf);

     Z_AttributesPlusTerm *yaz_pqf_scan(YAZ_PQF_Parser p, ODR o,
                          Odr_oid **attributeSetId, const char *qbuf);

     int yaz_pqf_error(YAZ_PQF_Parser p, const char **msg, size_t *off);
    </synopsis>
    <para>
     A PQF parser is created and destructed by functions
     <function>yaz_pqf_create</function> and
     <function>yaz_pqf_destroy</function> respectively.
     Function <function>yaz_pqf_parse</function> parses the query given
     by string <literal>qbuf</literal>. If parsing was successful,
     a Z39.50 RPN Query is returned which is created using ODR stream
     <literal>o</literal>. If parsing failed, a NULL pointer is
     returned.
     Function <function>yaz_pqf_scan</function> takes a scan query in
     <literal>qbuf</literal>. If parsing was successful, the function
     returns attributes plus term pointer and modifies
     <literal>attributeSetId</literal> to hold attribute set for the
     scan request - both allocated using ODR stream <literal>o</literal>.
     If parsing failed, yaz_pqf_scan returns a NULL pointer.
     Error information for bad queries can be obtained by a call to
     <function>yaz_pqf_error</function> which returns an error code and
     modifies <literal>*msg</literal> to point to an error description,
     and modifies <literal>*off</literal> to the offset within the last
     query where parsing failed.
    </para>
    <para>
     The second set of functions are declared as follows:
    </para>
    <synopsis>
     #include &lt;yaz/pquery.h&gt;

     Z_RPNQuery *p_query_rpn(ODR o, oid_proto proto, const char *qbuf);

     Z_AttributesPlusTerm *p_query_scan(ODR o, oid_proto proto,
                             Odr_oid **attributeSetP, const char *qbuf);

     int p_query_attset(const char *arg);
    </synopsis>
    <para>
     The function <function>p_query_rpn()</function> takes as arguments an
     &odr; stream (see section <link linkend="odr">The ODR Module</link>)
     to provide a memory source (the structure created is released on
     the next call to <function>odr_reset()</function> on the stream), a
     protocol identifier (one of the constants <token>PROTO_Z3950</token> and
     <token>PROTO_SR</token>), an attribute set reference, and
     finally a null-terminated string holding the query string.
    </para>
    <para>
     If the parse went well, <function>p_query_rpn()</function> returns a
     pointer to a <literal>Z_RPNQuery</literal> structure which can be
     placed directly into a <literal>Z_SearchRequest</literal>.
     If parsing failed, due to syntax error, a NULL pointer is returned.
    </para>
    <para>
     The <literal>p_query_attset</literal> specifies which attribute set
     to use if the query doesn't specify one by the
     <literal>@attrset</literal> operator.
     The <literal>p_query_attset</literal> returns 0 if the argument is a
     valid attribute set specifier; otherwise the function returns -1.
    </para>
    <para>
     The grammar of the PQF is as follows:
    </para>
    <literallayout>
     query ::= top-set query-struct.

     top-set ::= [ '@attrset' string ]

     query-struct ::= attr-spec | simple | complex | '@term' term-type query

     attr-spec ::= '@attr' [ string ] string query-struct

     complex ::= operator query-struct query-struct.

     operator ::= '@and' | '@or' | '@not' | '@prox' proximity.

     simple ::= result-set | term.

     result-set ::= '@set' string.

     term ::= string.

     proximity ::= exclusion distance ordered relation which-code unit-code.

     exclusion ::= '1' | '0' | 'void'.

     distance ::= integer.

     ordered ::= '1' | '0'.

     relation ::= integer.

     which-code ::= 'known' | 'private' | integer.

     unit-code ::= integer.

     term-type ::= 'general' | 'numeric' | 'string' | 'oid' | 'datetime' | 'null'.
    </literallayout>
    <para>
     You will note that the syntax above is a fairly faithful
     representation of RPN, except for the Attribute, which has been
     moved a step away from the term, allowing you to associate one or more
     attributes with an entire query structure. The parser will
     automatically apply the given attributes to each term as required.
    </para>
    <para>
     The @attr operator is followed by an attribute specification
     (<literal>attr-spec</literal> above). The specification consists
     of an optional attribute set, an attribute type-value pair and
     a sub-query. The attribute type-value pair is packed in one string:
     an attribute type, an equals sign, and an attribute value, like this:
     <literal>@attr 1=1003</literal>.
     The type is always an integer, but the value may be either an
     integer or a string (if it doesn't start with a digit character).
     A string attribute-value is encoded as a Type-1 "complex"
     attribute with the list of values containing the single string
     specified, and including no semantic indicators.
    </para>
    <para>
     Version 3 of the Z39.50 specification defines various encoding of terms.
     Use <literal>@term </literal> <replaceable>type</replaceable>
     <replaceable>string</replaceable>,
     where type is one of: <literal>general</literal>,
     <literal>numeric</literal> or <literal>string</literal>
     (for InternationalString).
     If no term type has been given, the <literal>general</literal> form
     is used.  This is the only encoding allowed in both versions 2 and 3
     of the Z39.50 standard.
    </para>
    <sect3 id="PQF-prox">
     <title>Using Proximity Operators with PQF</title>
     <note>
      <para>
       This is an advanced topic, describing how to construct
       queries that make very specific requirements on the
       relative location of their operands.
       You may wish to skip this section and go straight to
       <link linkend="pqf-examples">the example PQF queries</link>.
      </para>
      <para>
       <warning>
	<para>
	 Most Z39.50 servers do not support proximity searching, or
	 support only a small subset of the full functionality that
	 can be expressed using the PQF proximity operator.  Be
	 aware that the ability to <emphasis>express</emphasis> a
	 query in PQF is no guarantee that any given server will
	 be able to <emphasis>execute</emphasis> it.
	</para>
       </warning>
      </para>
     </note>
     <para>
      The proximity operator <literal>@prox</literal> is a special
      and more restrictive version of the conjunction operator
      <literal>@and</literal>.  Its semantics are described in
      section 3.7.2 (Proximity) of Z39.50 the standard itself, which
      can be read on-line at
      <ulink url="&url.z39.50.proximity;"/>
     </para>
     <para>
      In PQF, the proximity operation is represented by a sequence
      of the form
      <screen>
       @prox <replaceable>exclusion</replaceable> <replaceable>distance</replaceable> <replaceable>ordered</replaceable> <replaceable>relation</replaceable> <replaceable>which-code</replaceable> <replaceable>unit-code</replaceable>
      </screen>
      in which the meanings of the parameters are as described in
      the standard, and they can take the following values:
      <itemizedlist>
       <listitem>
	<formalpara><title>exclusion</title>
	<para>
	 0 = false (i.e. the proximity condition specified by the
	 remaining parameters must be satisfied) or
	 1 = true (the proximity condition specified by the
	 remaining parameters must <emphasis>not</emphasis> be
	 satisfied).
	</para>
       </formalpara>
       </listitem>
       <listitem>
	<formalpara><title>distance</title><para>
	An integer specifying the difference between the locations
	of the operands: e.g. two adjacent words would have
	distance=1 since their locations differ by one unit.
       </para>
       </formalpara></listitem>
       <listitem>
	<formalpara><title>ordered</title><para>
	1 = ordered (the operands must occur in the order the
	query specifies them) or
	0 = unordered (they may appear in either order).
       </para>
       </formalpara>
       </listitem>
       <listitem>
	<formalpara><title>relation</title><para>
	Recognised values are
	1 (lessThan),
	2 (lessThanOrEqual),
	3 (equal),
	4 (greaterThanOrEqual),
	5 (greaterThan) and
	6 (notEqual).
       </para>
       </formalpara>
       </listitem>
       <listitem>
	<formalpara><title>which-code</title><para>
	<literal>known</literal>
	or
	<literal>k</literal>
	(the unit-code parameter is taken from the well-known list
	of alternatives described below) or
	<literal>private</literal>
	or
	<literal>p</literal>
	(the unit-code parameter has semantics specific to an
	out-of-band agreement such as a profile).
       </para>
       </formalpara>
       </listitem>
       <listitem>
	<formalpara><title>unit-code</title><para>
	If the which-code parameter is <literal>known</literal>
	then the recognised values are
	1 (character),
	2 (word),
	3 (sentence),
	4 (paragraph),
	5 (section),
	6 (chapter),
	7 (document),
	8 (element),
	9 (subelement),
	10 (elementType) and
	11 (byte).
	If which-code is <literal>private</literal> then the
	acceptable values are determined by the profile.
       </para>
	</formalpara>
       </listitem>
      </itemizedlist>
      (The numeric values of the relation and well-known unit-code
      parameters are taken straight from
      <ulink url="&url.z39.50.proximity.asn1;"
	     >the ASN.1</ulink> of the proximity structure in the standard.)
     </para>
    </sect3>
    <sect3 id="pqf-examples">
     <title>PQF queries</title>
     <example id="example.pqf.simple.terms">
      <title>PQF queries using simple terms</title>
      <para>
       <screen>
	dylan

	"bob dylan"
       </screen>
      </para>
     </example>
     <example id="pqf.example.pqf.boolean.operators">
      <title>PQF boolean operators</title>
      <para>
       <screen>
	@or "dylan" "zimmerman"

	@and @or dylan zimmerman when

	@and when @or dylan zimmerman
       </screen>
      </para>
     </example>
     <example id="example.pqf.result.sets">
      <title>PQF references to result sets</title>
      <para>
       <screen>
	@set Result-1

	@and @set seta @set setb
       </screen>
      </para>
     </example>
     <example id="example.pqf.attributes">
      <title>Attributes for terms</title>
      <para>
       <screen>
	@attr 1=4 computer

	@attr 1=4 @attr 4=1 "self portrait"

	@attrset exp1 @attr 1=1 CategoryList

	@attr gils 1=2008 Copenhagen

	@attr 1=/book/title computer
       </screen>
      </para>
     </example>
     <example id="example.pqf.proximity">
      <title>PQF Proximity queries</title>
      <para>
       <screen>
	@prox 0 3 1 2 k 2 dylan zimmerman
       </screen>
       Here the parameters 0, 3, 1, 2, k and 2 represent exclusion,
       distance, ordered, relation, which-code and unit-code, in that
       order.  So:
       <itemizedlist>
	<listitem>
	 <para>exclusion = 0: the proximity condition must hold</para>
	</listitem>
	<listitem>
	 <para>distance = 3: the terms must be three units apart</para>
	</listitem>
	<listitem>
	 <para>
	  ordered = 1: they must occur in the order they are specified
	</para>
	</listitem>
	<listitem>
	 <para>
	relation = 2: lessThanOrEqual (to the distance of 3 units)
	</para>
	</listitem>
	<listitem>
	 <para>
	  which-code is "known", so the standard unit-codes are used
	 </para>
	</listitem>
	<listitem>
	 <para>unit-code = 2: word.</para>
	</listitem>
       </itemizedlist>
       So the whole proximity query means that the words
       <literal>dylan</literal> and <literal>zimmerman</literal> must
       both occur in the record, in that order, differing in position
       by three or fewer words (i.e. with two or fewer words between
       them.)  The query would find "Bob Dylan, aka. Robert
       Zimmerman", but not "Bob Dylan, born as Robert Zimmerman"
       since the distance in this case is four.
      </para>
     </example>
     <example id="example.pqf.search.term.type">
      <title>PQF specification of search term type</title>
      <para>
       <screen>
	@term string "a UTF-8 string, maybe?"
       </screen>
      </para>
     </example>
     <example id="example.pqf.mixed.queries">
      <title>PQF mixed queries</title>
      <para>
       <screen>
	@or @and bob dylan @set Result-1

	@attr 4=1 @and @attr 1=1 "bob dylan" @attr 1=4 "slow train coming"

	@and @attr 2=4 @attr gils 1=2038 -114 @attr 2=2 @attr gils 1=2039 -109
       </screen>
       The last of these examples is a spatial search: in
       <ulink url="http://www.gils.net/prof_v2.html#sec_7_4"
	      >the GILS attribute set</ulink>,
       access point
       2038 indicates West Bounding Coordinate and
       2030 indicates East Bounding Coordinate,
       so the query is for areas extending from -114 degrees longitude
       to no more than -109 degrees longitude.
      </para>
     </example>
    </sect3>
   </sect2>
   <sect2 id="CCL"><title>CCL</title>
    <para>
     Not all users enjoy typing in prefix query structures and numerical
     attribute values, even in a minimalistic test client. In the library
     world, the more intuitive Common Command Language - CCL (ISO 8777)
     has enjoyed some popularity - especially before the widespread
     availability of graphical interfaces. It is still useful in
     applications where you for some reason or other need to provide a
     symbolic language for expressing boolean query structures.
    </para>
    <sect3 id="ccl.syntax">
     <title>CCL Syntax</title>
     <para>
      The CCL parser obeys the following grammar for the FIND argument.
      The syntax is annotated using lines prefixed by
      <literal>--</literal>.
     </para>
     <screen>
      CCL-Find ::= CCL-Find Op Elements
                | Elements.

      Op ::= "and" | "or" | "not"
      -- The above means that Elements are separated by boolean operators.

      Elements ::= '(' CCL-Find ')'
                | Set
                | Terms
                | Qualifiers Relation Terms
                | Qualifiers Relation '(' CCL-Find ')'
                | Qualifiers '=' string '-' string
      -- Elements is either a recursive definition, a result set reference, a
      -- list of terms, qualifiers followed by terms, qualifiers followed
      -- by a recursive definition or qualifiers in a range (lower - upper).

      Set ::= 'set' = string
      -- Reference to a result set

      Terms ::= Terms Prox Term
             | Term
      -- Proximity of terms.

      Term ::= Term string
            | string
      -- This basically means that a term may include a blank

      Qualifiers ::= Qualifiers ',' string
                  | string
      -- Qualifiers is a list of strings separated by comma

      Relation ::= '=' | '>=' | '&lt;=' | '&lt;>' | '>' | '&lt;'
      -- Relational operators. This really doesn't follow the ISO8777
      -- standard.

      Prox ::= '%' | '!'
      -- Proximity operator

     </screen>
     <example id="example.ccl.queries">
      <title>CCL queries</title>
      <para>
       The following queries are all valid:
      </para>
      <screen>
       dylan

       "bob dylan"

       dylan or zimmerman

       set=1

       (dylan and bob) or set=1

       righttrunc?

       "notrunc?"

       singlechar#mask
      </screen>
      <para>
       Assuming that the qualifiers <literal>ti</literal>
       and <literal>au</literal>
       and <literal>date</literal> are defined, we may use:
      </para>
      <screen>
       ti=self portrait

       au=(bob dylan and slow train coming)

       date>1980 and (ti=((self portrait)))
      </screen>
     </example>
    </sect3>
    <sect3 id="ccl.qualifiers">
     <title>CCL Qualifiers</title>
     <para>
      Qualifiers are used to direct the search to a particular searchable
      index, such as title (ti) and author indexes (au). The CCL standard
      itself doesn't specify a particular set of qualifiers, but it does
      suggest a few short-hand notations. You can customize the CCL parser
      to support a particular set of qualifiers to reflect the current target
      profile. Traditionally, a qualifier would map to a particular
      use-attribute within the BIB-1 attribute set. It is also
      possible to set other attributes, such as the structure
      attribute.
     </para>
     <para>
      A  CCL profile is a set of predefined CCL qualifiers that may be
      read from a file or set in the CCL API.
      The YAZ client reads its CCL qualifiers from a file named
      <filename>default.bib</filename>. There are four types of
      lines in a CCL profile: qualifier specification,
      qualifier alias, comments and directives.
     </para>
     <sect4 id="ccl.qualifier.specification">
      <title>Qualifier specification</title>
      <para>
       A qualifier specification is of the form:
      </para>
      <para>
       <replaceable>qualifier-name</replaceable>
       [<replaceable>attributeset</replaceable><literal>,</literal>]<replaceable>type</replaceable><literal>=</literal><replaceable>val</replaceable>
       [<replaceable>attributeset</replaceable><literal>,</literal>]<replaceable>type</replaceable><literal>=</literal><replaceable>val</replaceable> ...
      </para>
      <para>
       where <replaceable>qualifier-name</replaceable> is the name of the
       qualifier to be used (e.g. <literal>ti</literal>),
       <replaceable>type</replaceable> is attribute type in the attribute
       set (Bib-1 is used if no attribute set is given) and
       <replaceable>val</replaceable> is attribute value.
       The <replaceable>type</replaceable> can be specified as an
       integer, or as a single-letter:
       <literal>u</literal> for use,
       <literal>r</literal> for relation, <literal>p</literal> for position,
       <literal>s</literal> for structure,<literal>t</literal> for truncation,
       or <literal>c</literal> for completeness.
       The attributes for the special qualifier name <literal>term</literal>
       are used when no CCL qualifier is given in a query.
       <table id="ccl.common.bib1.attributes">
	<title>Common Bib-1 attributes</title>
	<tgroup cols="2">
	 <colspec colwidth="2*" colname="type"></colspec>
	 <colspec colwidth="9*" colname="description"></colspec>
	 <thead>
	  <row>
	   <entry>Type</entry>
	   <entry>Description</entry>
	  </row>
	 </thead>
	 <tbody>
	  <row>
	   <entry><literal>u=</literal><replaceable>value</replaceable></entry>
	   <entry>
	    Use attribute (1). Common use attributes are
	    1 Personal-name, 4 Title, 7 ISBN, 8 ISSN, 30 Date,
	    62 Subject, 1003 Author, 1016 Any. Specify value
	    as an integer.
	   </entry>
	  </row>
	  <row>
	   <entry><literal>r=</literal><replaceable>value</replaceable></entry>
	   <entry>
	    Relation attribute (2). Common values are
	    1 &lt;, 2 &lt;=, 3 =, 4 &gt;=, 5 &gt;, 6 &lt;&gt;,
	    100 phonetic, 101 stem, 102 relevance, 103 always matches.
	   </entry>
	  </row>
	  <row>
	   <entry><literal>p=</literal><replaceable>value</replaceable></entry>
	   <entry>
	    Position attribute (3). Values: 1 first in field, 2
	    first in any subfield, 3 any position in field.
	   </entry>
	  </row>
	  <row>
	   <entry><literal>s=</literal><replaceable>value</replaceable></entry>
	   <entry>
	    Structure attribute (4). Values: 1 phrase, 2 word,
	    3 key, 4 year, 5 date, 6 word list, 100 date (un),
	    101 name (norm), 102 name (un), 103 structure, 104 urx,
	    105 free-form-text, 106 document-text, 107 local-number,
	    108 string, 109 numeric string.
	   </entry>
	  </row>
	  <row>
	   <entry><literal>t=</literal><replaceable>value</replaceable></entry>
	   <entry>
	    Truncation attribute (5). Values: 1 right, 2 left,
	    3 left and right, 100 none, 101 process #, 102 regular-1,
	    103 regular-2, 104 CCL.
	   </entry>
	  </row>
	  <row>
	   <entry><literal>c=</literal><replaceable>value</replaceable></entry>
	   <entry>
	    Completeness attribute (6). Values: 1 incomplete subfield,
	    2 complete subfield, 3 complete field.
	   </entry>
	  </row>
	 </tbody>
	</tgroup>
       </table>
      </para>
      <para>
       Refer to <xref linkend="bib1"/> or the complete
       <ulink url="&url.z39.50.attset.bib1;">list of Bib-1 attributes</ulink>
      </para>
      <para>
       It is also possible to specify non-numeric attribute values,
       which are used in combination with certain types.
       The special combinations are:
       <table id="ccl.special.attribute.combos">
	<title>Special attribute combos</title>
	<tgroup cols="2">
	 <colspec colwidth="2*" colname="name"></colspec>
	 <colspec colwidth="9*" colname="description"></colspec>
	 <thead>
	  <row>
	   <entry>Name</entry>
	   <entry>Description</entry>
	  </row>
	 </thead>
	 <tbody>
	  <row>
	   <entry><literal>s=pw</literal></entry>
	   <entry>
	    The structure is set to either word or phrase depending
	    on the number of tokens in a term (phrase-word).
	   </entry>
	  </row>
	  <row>
	   <entry><literal>s=al</literal></entry>
	   <entry>
	    Each token in the term is ANDed (and-list).
	    This does not set the structure at all.
	   </entry>
	  </row>
	  <row><entry><literal>s=ol</literal></entry>
	  <entry>
	   Each token in the term is ORed (or-list).
	   This does not set the structure at all.
	  </entry>
	  </row>
	  <row><entry><literal>s=ag</literal></entry>
	  <entry>
	   Tokens that appears as phrases (with blank in them) gets
	   structure phrase attached (4=1). Tokens that appear to be words
	   gets structure word attached (4=2). Phrases and words are
	   ANDed. This is a variant of s=al and s=pw, with the main
	   difference that words are not split (with operator AND)
	   but instead kept in one RPN token. This facility appeared
	   in YAZ 4.2.38.
	  </entry>
	  </row>
	  <row><entry><literal>s=sl</literal></entry>
	  <entry>
           Tokens are split into sub-phrases of all combinations - in order.
	   This facility appeared in YAZ 5.14.0.
	  </entry>
	  </row>
	  <row><entry><literal>r=o</literal></entry>
	  <entry>
	   Allows ranges and the operators greater-than, less-than, ...
	   equals.
	   This sets Bib-1 relation attribute accordingly (relation
	   ordered). A query construct is only treated as a range if
	   dash is used and that is surrounded by white-space. So
	   <literal>-1980</literal> is treated as term
	   <literal>"-1980"</literal> not <literal>&lt;= 1980</literal>.
	   If <literal>- 1980</literal> is used, however, that is
	   treated as a range.
	  </entry>
	  </row>
	  <row><entry><literal>r=r</literal></entry>
	  <entry>
	   Similar to <literal>r=o</literal> but assumes that terms
	   are non-negative (not prefixed with <literal>-</literal>).
	   Thus, a dash will always be treated as a range.
	   The construct <literal>1980-1990</literal> is
	   treated as a range with <literal>r=r</literal> but as a
	   single term <literal>"1980-1990"</literal> with
	   <literal>r=o</literal>. The special attribute
	   <literal>r=r</literal> is available in YAZ 2.0.24 or later.
	  </entry>
	  </row>
	  <row><entry><literal>r=omiteq</literal></entry>
	  <entry>
	   This will omit relation=equals (@attr 2=3) when r=o / r=r
	   is used. This is useful for servers that somehow break
	   when an explicit relation=equals is used. Omitting the
	   relation is usually safe because "equals" is the default
	   behavior. This tweak was added in YAZ version 5.1.2.
	  </entry>
	  </row>
	  <row><entry><literal>t=l</literal></entry>
	  <entry>
	   Allows term to be left-truncated.
	   If term is of the form <literal>?x</literal>, the resulting
	   Type-1 term is <literal>x</literal> and truncation is left.
	  </entry>
	  </row>
	  <row><entry><literal>t=r</literal></entry>
	  <entry>
	   Allows term to be right-truncated.
	   If term is of the form <literal>x?</literal>, the resulting
	   Type-1 term is <literal>x</literal> and truncation is right.
	  </entry>
	  </row>
	  <row><entry><literal>t=n</literal></entry>
	  <entry>
	   If term is does not include <literal>?</literal>, the
	   truncation attribute is set to none (100).
	  </entry>
	  </row>
	  <row><entry><literal>t=b</literal></entry>
	  <entry>
	   Allows term to be both left-and-right truncated.
	   If term is of the form <literal>?x?</literal>, the
	   resulting term is <literal>x</literal> and truncation is
	   set to both left and right.
	  </entry>
	  </row>
	  <row><entry><literal>t=x</literal></entry>
	  <entry>
	   Allows masking anywhere in a term, thus fully supporting
	   # (mask one character) and ? (zero or more of any).
	   If masking is used, truncation is set to 102 (regexp-1 in term)
	   and the term is converted accordingly to a regular expression.
	  </entry>
	  </row>
	  <row><entry><literal>t=z</literal></entry>
	  <entry>
	   Allows masking anywhere in a term, thus fully supporting
	   # (mask one character) and ? (zero or more of any).
	   If masking is used, truncation is set to 104 (Z39.58 in term)
	   and the term is converted accordingly to Z39.58 masking term -
	   actually the same truncation as CCL itself.
	  </entry>
	  </row>
	 </tbody>
	</tgroup>
       </table>
      </para>
      <example id="example.ccl.profile">
       <title>CCL profile</title>
       <para>
	Consider the following definition:
       </para>
       <screen>
	ti       u=4 s=1
	au       u=1 s=1
	term     s=105
	ranked   r=102
	date     u=30 r=o
       </screen>
       <para>
	<literal>ti</literal> and <literal>au</literal> both set
	structure attribute to phrase (s=1).
	<literal>ti</literal>
	sets the use-attribute to 4. <literal>au</literal> sets the
	use-attribute to 1.
	When no qualifiers are used in the query, the structure-attribute is
	set to free-form-text (105) (rule for <literal>term</literal>).
	The <literal>date</literal> sets the relation attribute to
	the relation used in the CCL query and sets the use attribute
	to 30 (Bib-1 Date).
       </para>
       <para>
	You can combine attributes. To Search for "ranked title" you
	can do
	<screen>
	 ti,ranked=knuth computer
	</screen>
	which will set relation=ranked, use=title, structure=phrase.
       </para>
       <para>
	Query
	<screen>
	 date > 1980
	</screen>
	is a valid query. But
	<screen>
	 ti > 1980
	</screen>
	is invalid.
       </para>
      </example>
     </sect4>
     <sect4 id="ccl.qualifier.alias">
      <title>Qualifier alias</title>
      <para>
       A qualifier alias is of the form:
      </para>
      <para>
       <replaceable>q</replaceable>
       <replaceable>q1</replaceable> <replaceable>q2</replaceable> ..
      </para>
      <para>
       which declares <replaceable>q</replaceable> to
       be an alias for <replaceable>q1</replaceable>,
       <replaceable>q2</replaceable>... such that the CCL
       query <replaceable>q=x</replaceable> is equivalent to
       <replaceable>q1=x or q2=x or ...</replaceable>.
      </para>
     </sect4>
     <sect4 id="ccl.comments">
      <title>Comments</title>
      <para>
       Lines with white space or lines that begin with
       character <literal>#</literal> are treated as comments.
      </para>
     </sect4>
     <sect4 id="ccl.directives">
      <title>Directives</title>
      <para>
       Directive specifications takes the form
      </para>
      <para><literal>@</literal><replaceable>directive</replaceable> <replaceable>value</replaceable>
      </para>
      <table id="ccl.directives.table">
       <title>CCL directives</title>
       <tgroup cols="3">
	<colspec colwidth="2*" colname="name"></colspec>
	<colspec colwidth="8*" colname="description"></colspec>
	<colspec colwidth="1*" colname="default"></colspec>
	<thead>
	 <row>
	  <entry>Name</entry>
	  <entry>Description</entry>
	  <entry>Default</entry>
	 </row>
	</thead>
	<tbody>
	 <row>
	  <entry>truncation</entry>
	  <entry>Truncation character</entry>
	  <entry><literal>?</literal></entry>
	 </row>
	 <row>
	  <entry>mask</entry>
	  <entry>Masking character. Requires YAZ 4.2.58 or later</entry>
	  <entry><literal>#</literal></entry>
	 </row>
	 <row>
	  <entry>field</entry>
	  <entry>Specifies how multiple fields are to be
	   combined. There are two modes: <literal>or</literal>:
	   multiple qualifier fields are ORed,
	   <literal>merge</literal>: attributes for the qualifier
	   fields are merged and assigned to one term.
	   </entry>
	  <entry><literal>merge</literal></entry>
	 </row>
	 <row>
	  <entry>case</entry>
	  <entry>Specifies if CCL operators and qualifiers should be
	   compared with case sensitivity or not. Specify 1 for
	   case sensitive; 0 for case insensitive.</entry>
	  <entry><literal>1</literal></entry>
	 </row>
	 <row>
	  <entry>and</entry>
	  <entry>Specifies token for CCL operator AND.</entry>
	  <entry><literal>and</literal></entry>
	 </row>
	 <row>
	  <entry>or</entry>
	  <entry>Specifies token for CCL operator OR.</entry>
	  <entry><literal>or</literal></entry>
	 </row>
	 <row>
	  <entry>not</entry>
	  <entry>Specifies token for CCL operator NOT.</entry>
	  <entry><literal>not</literal></entry>
	 </row>
	 <row>
	  <entry>set</entry>
	  <entry>Specifies token for CCL operator SET.</entry>
	  <entry><literal>set</literal></entry>
	 </row>
	</tbody>
       </tgroup>
      </table>
     </sect4>
    </sect3>
    <sect3 id="ccl.api">
     <title>CCL API</title>
     <para>
      All public definitions can be found in the header file
      <filename>ccl.h</filename>. A profile identifier is of type
      <literal>CCL_bibset</literal>. A profile must be created with the call
      to the function <function>ccl_qual_mk</function> which returns a profile
      handle of type <literal>CCL_bibset</literal>.
     </para>
     <para>
      To read a file containing qualifier definitions the function
      <function>ccl_qual_file</function> may be convenient. This function
      takes an already opened <literal>FILE</literal> handle pointer as
      argument along with a <literal>CCL_bibset</literal> handle.
     </para>
     <para>
      To parse a simple string with a FIND query use the function
     </para>
     <screen>
struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset, const char *str,
                                  int *error, int *pos);
     </screen>
     <para>
      which takes the CCL profile (<literal>bibset</literal>) and query
      (<literal>str</literal>) as input. Upon successful completion the RPN
      tree is returned. If an error occurs, such as a syntax error, the integer
      pointed to by <literal>error</literal> holds the error code and
      <literal>pos</literal> holds the offset inside query string in which
      the parsing failed.
     </para>
     <para>
      An English representation of the error may be obtained by calling
      the <literal>ccl_err_msg</literal> function. The error codes are
      listed in <filename>ccl.h</filename>.
     </para>
     <para>
      To convert the CCL RPN tree (type
      <literal>struct ccl_rpn_node *</literal>)
      to the Z_RPNQuery of YAZ the function <function>ccl_rpn_query</function>
      must be used. This function which is part of YAZ is implemented in
      <filename>yaz-ccl.c</filename>.
      After calling this function the CCL RPN tree is probably no longer
      needed. The <literal>ccl_rpn_delete</literal> destroys the CCL RPN tree.
     </para>
     <para>
      A CCL profile may be destroyed by calling the
      <function>ccl_qual_rm</function> function.
     </para>
     <para>
      The token names for the CCL operators may be changed by setting the
      globals (all type <literal>char *</literal>)
      <literal>ccl_token_and</literal>, <literal>ccl_token_or</literal>,
      <literal>ccl_token_not</literal> and <literal>ccl_token_set</literal>.
      An operator may have aliases, i.e. there may be more than one name for
      the operator. To do this, separate each alias with a space character.
     </para>
    </sect3>
   </sect2>
   <sect2 id="cql">
    <title>CQL</title>
    <para>
     <ulink url="&url.cql;">CQL</ulink>
     - Common Query Language - was defined for the
     <ulink url="&url.sru;">SRU</ulink> protocol.
     In many ways CQL has a similar syntax to CCL.
     The objective of CQL is different. Where CCL aims to be
     an end-user language, CQL is <emphasis>the</emphasis> protocol
     query language for SRU.
    </para>
    <tip>
     <para>
      If you are new to CQL, read the
      <ulink url="&url.cql.intro;">Gentle Introduction</ulink>.
     </para>
    </tip>
    <para>
     The CQL parser in &yaz; provides the following:
     <itemizedlist>
      <listitem>
       <para>
        It parses and validates a CQL query.
       </para>
      </listitem>
      <listitem>
       <para>
        It generates a C structure that allows you to convert
        a CQL query to some other query language, such as SQL.
       </para>
      </listitem>
      <listitem>
       <para>
        The parser converts a valid CQL query to PQF, thus providing a
        way to use CQL for both SRU servers and Z39.50 targets at the
        same time.
       </para>
      </listitem>
      <listitem>
       <para>
        The parser converts CQL to XCQL.
        XCQL is an XML representation of CQL.
        XCQL is part of the SRU specification. However, since SRU
        supports CQL only, we don't expect XCQL to be widely used.
        Furthermore, CQL has the advantage over XCQL that it is
        easy to read.
       </para>
      </listitem>
     </itemizedlist>
    </para>
    <sect3 id="cql.parsing">
     <title>CQL parsing</title>
     <para>
      A CQL parser is represented by the <literal>CQL_parser</literal>
      handle. Its contents should be considered &yaz; internal (private).
      <synopsis>
#include &lt;yaz/cql.h&gt;

typedef struct cql_parser *CQL_parser;

CQL_parser cql_parser_create(void);
void cql_parser_destroy(CQL_parser cp);
      </synopsis>
     A parser is created by <function>cql_parser_create</function> and
     is destroyed by <function>cql_parser_destroy</function>.
     </para>
     <para>
      To parse a CQL query string, the following function
      is provided:
      <synopsis>
int cql_parser_string(CQL_parser cp, const char *str);
      </synopsis>
      A CQL query is parsed by the <function>cql_parser_string</function>
      which takes a query <parameter>str</parameter>.
      If the query was valid (no syntax errors), then zero is returned;
      otherwise -1 is returned to indicate a syntax error.
     </para>
     <para>
      <synopsis>
int cql_parser_stream(CQL_parser cp,
                      int (*getbyte)(void *client_data),
                      void (*ungetbyte)(int b, void *client_data),
                      void *client_data);

int cql_parser_stdio(CQL_parser cp, FILE *f);
      </synopsis>
      The functions <function>cql_parser_stream</function> and
      <function>cql_parser_stdio</function> parse a CQL query
      - just like <function>cql_parser_string</function>.
      The only difference is that the CQL query can be
      fed to the parser in different ways.
      The <function>cql_parser_stream</function> uses a generic
      byte stream as input. The <function>cql_parser_stdio</function>
      uses a <literal>FILE</literal> handle which is opened for reading.
     </para>
    </sect3>
    <sect3 id="cql.tree">
     <title>CQL tree</title>
     <para>
      If the query string is valid, the CQL parser
      generates a tree representing the structure of the
      CQL query.
     </para>
     <para>
      <synopsis>
struct cql_node *cql_parser_result(CQL_parser cp);
      </synopsis>
      <function>cql_parser_result</function> returns
      a pointer to the root node of the resulting tree.
     </para>
     <para>
      Each node in a CQL tree is represented by a
      <literal>struct cql_node</literal>.
      It is defined as follows:
      <synopsis>
#define CQL_NODE_ST 1
#define CQL_NODE_BOOL 2
#define CQL_NODE_SORT 3
struct cql_node {
    int which;
    union {
        struct {
            char *index;
	    char *index_uri;
            char *term;
            char *relation;
	    char *relation_uri;
            struct cql_node *modifiers;
        } st;
        struct {
            char *value;
            struct cql_node *left;
            struct cql_node *right;
            struct cql_node *modifiers;
        } boolean;
        struct {
            char *index;
            struct cql_node *next;
            struct cql_node *modifiers;
            struct cql_node *search;
        } sort;
    } u;
};
      </synopsis>
      There are three node types: search term (ST), boolean (BOOL)
      and sortby (SORT).
      A modifier is treated as a search term too.
     </para>
     <para>
      The search term node has five members:
      <itemizedlist>
       <listitem>
        <para>
         <literal>index</literal>: index for search term.
         If an index is unspecified for a search term,
         <literal>index</literal> will be NULL.
        </para>
       </listitem>
       <listitem>
        <para>
         <literal>index_uri</literal>: index URI for search term
	 or NULL if none could be resolved for the index.
        </para>
       </listitem>
       <listitem>
        <para>
         <literal>term</literal>: the search term itself.
        </para>
       </listitem>
       <listitem>
        <para>
         <literal>relation</literal>: relation for search term.
        </para>
       </listitem>
       <listitem>
        <para>
         <literal>relation_uri</literal>: relation URI for search term.
        </para>
       </listitem>
       <listitem>
        <para>
         <literal>modifiers</literal>: relation modifiers for search
         term. The <literal>modifiers</literal> list itself of cql_nodes
	 each of type <literal>ST</literal>.
        </para>
       </listitem>
      </itemizedlist>
     </para>
     <para>
      The boolean node represents <literal>and</literal>,
      <literal>or</literal>, <literal>not</literal> +
      proximity.
      <itemizedlist>
       <listitem>
        <para>
         <literal>left</literal> and <literal>right</literal>: left
         - and right operand respectively.
        </para>
       </listitem>
       <listitem>
        <para>
         <literal>modifiers</literal>: proximity arguments.
        </para>
       </listitem>
      </itemizedlist>
     </para>
     <para>
      The sort node represents both the SORTBY clause.
     </para>
    </sect3>
    <sect3 id="cql.to.pqf">
     <title>CQL to PQF conversion</title>
     <para>
      Conversion to PQF (and Z39.50 RPN) is tricky by the fact
      that the resulting RPN depends on the Z39.50 target
      capabilities (combinations of supported attributes).
      In addition, the CQL and SRU operates on index prefixes
      (URI or strings), whereas the RPN uses Object Identifiers
      for attribute sets.
     </para>
     <para>
      The CQL library of &yaz; defines a <literal>cql_transform_t</literal>
      handle. It represents a particular mapping between CQL and RPN.
      This handle is created and destroyed by the functions:
     </para>
     <synopsis>
cql_transform_t cql_transform_create(void);
int cql_transform_define_fname(cql_transform_t *ct, const char *fname);
int cql_transform_define_FILE(cql_trasnform_t *ct, FILE *f);
void cql_transform_close(cql_transform_t ct);
     </synopsis>
     <para>
      The first method constructs a handle. The second and third functon extends
      the configuration by reading from a file or an open FILE handle.
      The transform handle is destroyed by <function>cql_transform_close</function>
      in which case no further reference of the handle is allowed.
     </para>
     <para>
      There are also two methods which creates and reads configuration
      from a file combined:
     </para>
     <synopsis>
cql_transform_t cql_transform_open_FILE (FILE *f);
cql_transform_t cql_transform_open_fname(const char *fname);
     </synopsis>
     <para>
      When a <literal>cql_transform_t</literal> handle has been created
      you can convert to RPN.
      <synopsis>
int cql_transform_buf(cql_transform_t ct,
                      struct cql_node *cn, char *out, int max);
      </synopsis>
      This function converts the CQL tree <literal>cn</literal>
      using handle <literal>ct</literal>.
      For the resulting PQF, you supply a buffer <literal>out</literal>
      which must be able to hold at at least <literal>max</literal>
      characters.
     </para>
     <para>
      If conversion failed, <function>cql_transform_buf</function>
      returns a non-zero SRU error code; otherwise zero is returned
      (conversion successful).  The meanings of the numeric error
      codes are listed in the SRU specification somewhere (no
      direct link anymore).
     </para>
     <para>
      If conversion fails, more information can be obtained by calling
      <synopsis>
int cql_transform_error(cql_transform_t ct, char **addinfop);
      </synopsis>
      This function returns the most recently returned numeric
      error-code and sets the string-pointer at
      <literal>*addinfop</literal> to point to a string containing
      additional information about the error that occurred: for
      example, if the error code is 15 ("Illegal or unsupported context
      set"), the additional information is the name of the requested
      context set that was not recognised.
     </para>
     <para>
      The SRU error-codes may be translated into brief human-readable
      error messages using
      <synopsis>
const char *cql_strerror(int code);
      </synopsis>
     </para>
     <para>
      If you wish to be able to produce a PQF result in a different
      way, there are two alternatives.
      <synopsis>
void cql_transform_pr(cql_transform_t ct,
                      struct cql_node *cn,
                      void (*pr)(const char *buf, void *client_data),
                      void *client_data);

int cql_transform_FILE(cql_transform_t ct,
                       struct cql_node *cn, FILE *f);
      </synopsis>
      The former function produces output to a user-defined
      output stream. The latter writes the result to an already
      open <literal>FILE</literal>.
     </para>
    </sect3>
    <sect3 id="cql.to.rpn">
     <title>Specification of CQL to RPN mappings</title>
     <para>
      The file supplied to functions
      <function>cql_transform_open_FILE</function>,
      <function>cql_transform_open_fname</function> follows
      a structure found in many Unix utilities.
      It consists of mapping specifications - one per line.
      Lines starting with <literal>#</literal> are ignored (comments).
     </para>
     <para>
      Each line is of the form
      <literallayout>
       <replaceable>CQL pattern</replaceable><literal> = </literal> <replaceable> RPN equivalent</replaceable>
      </literallayout>
     </para>
     <para>
      An RPN pattern is a simple attribute list. Each attribute pair
      takes the form:
      <literallayout>
       [<replaceable>set</replaceable>] <replaceable>type</replaceable><literal>=</literal><replaceable>value</replaceable>
      </literallayout>
      The attribute <replaceable>set</replaceable> is optional.
      The <replaceable>type</replaceable> is the attribute type,
      <replaceable>value</replaceable> the attribute value.
     </para>
     <para>
      The character <literal>*</literal> (asterisk) has special meaning
      when used in the RPN pattern.
      Each occurrence of <literal>*</literal> is substituted with the
      CQL matching name (index, relation, qualifier etc).
      This facility can be used to copy a CQL name verbatim to the RPN result.
     </para>
     <para>
      The following CQL patterns are recognized:
      <variablelist>
       <varlistentry>
	<term>
	 <literal>index.</literal><replaceable>set</replaceable><literal>.</literal><replaceable>name</replaceable>
	</term>
	<listitem>
         <para>
          This pattern is invoked when a CQL index, such as
          dc.title is converted. <replaceable>set</replaceable>
          and <replaceable>name</replaceable> are the context set and index
          name respectively.
          Typically, the RPN specifies an equivalent use attribute.
         </para>
         <para>
          For terms not bound by an index, the pattern
          <literal>index.cql.serverChoice</literal> is used.
          Here, the prefix <literal>cql</literal> is defined as
          <literal>http://www.loc.gov/zing/cql/cql-indexes/v1.0/</literal>.
          If this pattern is not defined, the mapping will fail.
         </para>
         <para>
          The pattern,
          <literal>index.</literal><replaceable>set</replaceable><literal>.*</literal>
          is used when no other index pattern is matched.
	 </para>
        </listitem>
       </varlistentry>
       <varlistentry>
	<term>
         <literal>qualifier.</literal><replaceable>set</replaceable><literal>.</literal><replaceable>name</replaceable>
	 (DEPRECATED)
        </term>
        <listitem>
         <para>
	  For backwards compatibility, this is recognised as a synonym of
          <literal>index.</literal><replaceable>set</replaceable><literal>.</literal><replaceable>name</replaceable>
         </para>
        </listitem>
       </varlistentry>
       <varlistentry>
	<term>
         <literal>relation.</literal><replaceable>relation</replaceable>
        </term>
        <listitem>
         <para>
          This pattern specifies how a CQL relation is mapped to RPN.
          The <replaceable>pattern</replaceable> is name of relation
          operator. Since <literal>=</literal> is used as
          separator between CQL pattern and RPN, CQL relations
          including <literal>=</literal> cannot be
          used directly. To avoid a conflict, the names
          <literal>ge</literal>,
          <literal>eq</literal>,
          <literal>le</literal>,
          must be used for CQL operators, greater-than-or-equal,
          equal, less-than-or-equal respectively.
          The RPN pattern is supposed to include a relation attribute.
         </para>
         <para>
          For terms not bound by a relation, the pattern
          <literal>relation.scr</literal> is used. If the pattern
          is not defined, the mapping will fail.
         </para>
         <para>
          The special pattern, <literal>relation.*</literal> is used
          when no other relation pattern is matched.
         </para>
        </listitem>
       </varlistentry>
       <varlistentry>
	<term>
         <literal>relationModifier.</literal><replaceable>mod</replaceable>
        </term>
        <listitem>
         <para>
          This pattern specifies how a CQL relation modifier is mapped to RPN.
          The RPN pattern is usually a relation attribute.
         </para>
        </listitem>
       </varlistentry>
       <varlistentry>
	<term>
         <literal>structure.</literal><replaceable>type</replaceable>
        </term>
        <listitem>
         <para>
          This pattern specifies how a CQL structure is mapped to RPN.
          Note that this CQL pattern is somewhat similar to
          CQL pattern <literal>relation</literal>.
          The <replaceable>type</replaceable> is a CQL relation.
         </para>
         <para>
          The pattern, <literal>structure.*</literal> is used
          when no other structure pattern is matched.
          Usually, the RPN equivalent specifies a structure attribute.
         </para>
        </listitem>
       </varlistentry>
       <varlistentry>
	<term>
         <literal>position.</literal><replaceable>type</replaceable>
        </term>
        <listitem>
         <para>
          This pattern specifies how the anchor (position) of
          CQL is mapped to RPN.
          The <replaceable>type</replaceable> is one
          of <literal>first</literal>, <literal>any</literal>,
          <literal>last</literal>, <literal>firstAndLast</literal>.
         </para>
         <para>
          The pattern, <literal>position.*</literal> is used
          when no other position pattern is matched.
         </para>
        </listitem>
       </varlistentry>
       <varlistentry>
	<term>
         <literal>set.</literal><replaceable>prefix</replaceable>
        </term>
        <listitem>
         <para>
          This specification defines a CQL context set for a given prefix.
          The value on the right hand side is the URI for the set -
          <emphasis>not</emphasis> RPN. All prefixes used in
          index patterns must be defined this way.
         </para>
        </listitem>
       </varlistentry>
       <varlistentry>
	<term>
	 <literal>set</literal>
	</term>
	<listitem>
	 <para>
          This specification defines a default CQL context set for index names.
          The value on the right hand side is the URI for the set.
         </para>
        </listitem>
       </varlistentry>
      </variablelist>
     </para>
     <example id="example.cql.to.rpn.mapping">
      <title>CQL to RPN mapping file</title>
      <para>
       This simple file defines two context sets, three indexes and three
       relations, a position pattern and a default structure.
      </para>
      <programlisting><![CDATA[
       set.cql  = http://www.loc.gov/zing/cql/context-sets/cql/v1.1/
       set.dc   = http://www.loc.gov/zing/cql/dc-indexes/v1.0/

       index.cql.serverChoice = 1=1016
       index.dc.title         = 1=4
       index.dc.subject       = 1=21

       relation.<             = 2=1
       relation.eq            = 2=3
       relation.scr           = 2=3

       position.any           = 3=3 6=1

       structure.*            = 4=1
]]>
      </programlisting>
      <para>
       With the mappings above, the CQL query
       <screen>
        computer
       </screen>
       is converted to the PQF:
       <screen>
        @attr 1=1016 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 "computer"
       </screen>
       by rules <literal>index.cql.serverChoice</literal>,
       <literal>relation.scr</literal>, <literal>structure.*</literal>,
       <literal>position.any</literal>.
      </para>
      <para>
       CQL query
       <screen>
        computer^
       </screen>
       is rejected, since <literal>position.right</literal> is
       undefined.
      </para>
      <para>
       CQL query
       <screen>
        >my = "http://www.loc.gov/zing/cql/dc-indexes/v1.0/" my.title = x
       </screen>
       is converted to
       <screen>
        @attr 1=4 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 "x"
       </screen>
      </para>
     </example>
     <example id="example.cql.to.rpn.string">
      <title>CQL to RPN string attributes</title>
      <para>
       In this example we allow any index to be passed to RPN as
       a use attribute.
      </para>
      <programlisting><![CDATA[
       # Identifiers for prefixes used in this file. (index.*)
       set.cql  = info:srw/cql-context-set/1/cql-v1.1
       set.rpn  = http://bogus/rpn
       set      = http://bogus/rpn

       # The default index when none is specified by the query
       index.cql.serverChoice     = 1=any

       index.rpn.*                = 1=*
       relation.eq                = 2=3
       structure.*                = 4=1
       position.any               = 3=3
]]>
      </programlisting>
      <para>
       The <literal>http://bogus/rpn</literal> context set is also the default
       so we can make queries such as
       <screen>
        title = a
       </screen>
       which is converted to
       <screen>
        @attr 2=3 @attr 4=1 @attr 3=3 @attr 1=title "a"
       </screen>
      </para>
     </example>
     <example id="example.cql.to.rpn.bathprofile">
      <title>CQL to RPN using Bath Profile</title>
      <para>
       The file <filename>etc/pqf.properties</filename> has mappings from
       the Bath Profile and Dublin Core to RPN.
       If YAZ is installed as a package it's usually located
       in <filename>/usr/share/yaz/etc</filename> and part of the
       development package, such as <literal>libyaz-dev</literal>.
      </para>
     </example>
    </sect3>
    <sect3 id="cql.xcql">
     <title>CQL to XCQL conversion</title>
     <para>
      Conversion from CQL to XCQL is trivial and does not
      require a mapping to be defined.
      There are three functions to choose from depending on the
      way you wish to store the resulting output (XML buffer
      containing XCQL).
      <synopsis>
int cql_to_xml_buf(struct cql_node *cn, char *out, int max);
void cql_to_xml(struct cql_node *cn,
                void (*pr)(const char *buf, void *client_data),
                void *client_data);
void cql_to_xml_stdio(struct cql_node *cn, FILE *f);
      </synopsis>
      Function <function>cql_to_xml_buf</function> converts
      to XCQL and stores the result in a user-supplied buffer of a given
      max size.
     </para>
     <para>
      <function>cql_to_xml</function> writes the result in
      a user-defined output stream.
      <function>cql_to_xml_stdio</function> writes to a
      a file.
     </para>
    </sect3>
    <sect3 id="rpn.to.cql">
     <title>PQF to CQL conversion</title>
     <para>
      Conversion from PQF to CQL is offered by the two functions shown
      below. The former uses a generic stream for result. The latter
      puts result in a WRBUF (string container).
      <synopsis>
#include &lt;yaz/rpn2cql.h>

int cql_transform_rpn2cql_stream(cql_transform_t ct,
                                 void (*pr)(const char *buf, void *client_data),
                                 void *client_data,
                                 Z_RPNQuery *q);

int cql_transform_rpn2cql_wrbuf(cql_transform_t ct,
                                WRBUF w,
                                Z_RPNQuery *q);
      </synopsis>
      The configuration is the same as used in CQL to PQF conversions.
     </para>
    </sect3>
   </sect2>
  </sect1>
  <sect1 id="tools.oid">
   <title>Object Identifiers</title>
   <para>
    The basic YAZ representation of an OID is an array of integers,
    terminated with the value -1. This integer is of type
    <literal>Odr_oid</literal>.
   </para>
   <para>
    Fundamental OID operations and the type <literal>Odr_oid</literal>
    are defined in <filename>yaz/oid_util.h</filename>.
   </para>
   <para>
    An OID can either be declared as a automatic variable or it can
    be allocated using the memory utilities or ODR/NMEM. It's
    guaranteed that an OID can fit in <literal>OID_SIZE</literal> integers.
   </para>
   <example id="tools.oid.bib1.1"><title>Create OID on stack</title>
    <para>
     We can create an OID for the Bib-1 attribute set with:
     <screen>
      Odr_oid bib1[OID_SIZE];
      bib1[0] = 1;
      bib1[1] = 2;
      bib1[2] = 840;
      bib1[3] = 10003;
      bib1[4] = 3;
      bib1[5] = 1;
      bib1[6] = -1;
     </screen>
    </para>
   </example>
   <para>
    And OID may also be filled from a string-based representation using
    dots (.). This is achieved by the function
    <screen>
     int oid_dotstring_to_oid(const char *name, Odr_oid *oid);
    </screen>
    This functions returns 0 if name could be converted; -1 otherwise.
   </para>
   <example id="tools.oid.bib1.2"><title>Using oid_oiddotstring_to_oid</title>
    <para>
     We can fill the Bib-1 attribute set OID more easily with:
     <screen>
      Odr_oid bib1[OID_SIZE];
      oid_oiddotstring_to_oid("1.2.840.10003.3.1", bib1);
     </screen>
   </para>
   </example>
   <para>
    We can also allocate an OID dynamically on an ODR stream with:
    <screen>
    Odr_oid *odr_getoidbystr(ODR o, const char *str);
    </screen>
    This creates an OID from a string-based representation using dots.
    This function take an &odr; stream as parameter. This stream is used to
    allocate memory for the data elements, which is released on a
    subsequent call to <function>odr_reset()</function> on that stream.
   </para>
   <example id="tools.oid.bib1.3">
    <title>Using odr_getoidbystr</title>
    <para>
     We can create an OID for the Bib-1 attribute set with:
     <screen>
      Odr_oid *bib1 = odr_getoidbystr(odr, "1.2.840.10003.3.1");
     </screen>
    </para>
   </example>
   <para>
    The function
    <screen>
     char *oid_oid_to_dotstring(const Odr_oid *oid, char *oidbuf)
    </screen>
    does the reverse of <function>oid_oiddotstring_to_oid</function>. It
    converts an OID to the string-based representation using dots.
    The supplied char buffer <literal>oidbuf</literal> holds the resulting
    string and must be at least <literal>OID_STR_MAX</literal> in size.
   </para>
   <para>
    OIDs can be copied with <function>oid_oidcpy</function> which takes
    two OID lists as arguments. Alternatively, an OID copy can be allocated
    on an ODR stream with:
    <screen>
     Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o);
    </screen>
   </para>
   <para>
    OIDs can be compared with <function>oid_oidcmp</function> which returns
    zero if the two OIDs provided are identical; non-zero otherwise.
   </para>
   <sect2 id="tools.oid.database">
    <title>OID database</title>
    <para>
     From YAZ version 3 and later, the oident system has been replaced
     by an OID database. OID database is a misnomer .. the old odient
     system was also a database.
    </para>
    <para>
     The OID database is really just a map between named Object Identifiers
     (string) and their OID raw equivalents. Most operations either
     convert from string to OID or other way around.
    </para>
    <para>
     Unfortunately, whenever we supply a string we must also specify the
     <emphasis>OID class</emphasis>. The class is necessary because some
     strings correspond to multiple OIDs. An example of such a string is
     <literal>Bib-1</literal> which may either be an attribute-set
     or a diagnostic-set.
    </para>
    <para>
     Applications using the YAZ database should include
     <filename>yaz/oid_db.h</filename>.
    </para>
    <para>
     A YAZ database handle is of type <literal>yaz_oid_db_t</literal>.
     Actually that's a pointer. You need not deal with that.
     YAZ has a built-in database which can be considered "constant" for
     most purposes.
     We can get hold of that by using function <function>yaz_oid_std</function>.
    </para>
    <para>
     All functions with prefix <function>yaz_string_to_oid</function>
     converts from class + string to OID. We have variants of this
     operation due to different memory allocation strategies.
    </para>
    <para>
     All functions with prefix
     <function>yaz_oid_to_string</function> converts from OID to string
     + class.
    </para>
    <example id="tools.oid.bib1.4">
     <title>Create OID with YAZ DB</title>
     <para>
      We can create an OID for the Bib-1 attribute set on the ODR stream
      odr with:
      <screen>
        Odr_oid *bib1 =
	yaz_string_to_oid_odr(yaz_oid_std(), CLASS_ATTSET, "Bib-1", odr);
      </screen>
      This is more complex than using <function>odr_getoidbystr</function>.
      You would only use <function>yaz_string_to_oid_odr</function> when the
      string (here Bib-1) is supplied by a user or configuration.
     </para>
    </example>
   </sect2>
   <sect2 id="tools.oid.std">
    <title>Standard OIDs</title>
    <para>
     All the object identifiers in the standard OID database as returned
     by <function>yaz_oid_std</function> can be referenced directly in a
     program as a constant OID.
     Each constant OID is prefixed with <literal>yaz_oid_</literal> -
     followed by OID class (lowercase) - then by OID name (normalized and
     lowercase).
    </para>
    <para>
     See <xref linkend="list-oids"/> for list of all object identifiers
     built into YAZ.
     These are declared in <filename>yaz/oid_std.h</filename> but are
     included by <filename>yaz/oid_db.h</filename> as well.
    </para>
    <example id="tools.oid.bib1.5">
     <title>Use a built-in OID</title>
     <para>
      We can allocate our own OID filled with the constant OID for
      Bib-1 with:
      <screen>
       Odr_oid *bib1 = odr_oiddup(o, yaz_oid_attset_bib1);
      </screen>
     </para>
    </example>
   </sect2>
  </sect1>
  <sect1 id="tools.nmem">
   <title>Nibble Memory</title>
   <para>
    Sometimes when you need to allocate and construct a large,
    interconnected complex of structures, it can be a bit of a pain to
    release the associated memory again. For the structures describing the
    Z39.50 PDUs and related structures, it is convenient to use the
    memory-management system of the &odr; subsystem (see
    <xref linkend="odr.use"/>). However, in some circumstances
    where you might otherwise benefit from using a simple nibble-memory
    management system, it may be impractical to use
    <function>odr_malloc()</function> and <function>odr_reset()</function>.
    For this purpose, the memory manager which also supports the &odr;
    streams is made available in the NMEM module. The external interface
    to this module is given in the <filename>nmem.h</filename> file.
   </para>
   <para>
    The following prototypes are given:
   </para>
   <screen>
    NMEM nmem_create(void);
    void nmem_destroy(NMEM n);
    void *nmem_malloc(NMEM n, size_t size);
    void nmem_reset(NMEM n);
    size_t nmem_total(NMEM n);
    void nmem_init(void);
    void nmem_exit(void);
   </screen>
   <para>
    The <function>nmem_create()</function> function returns a pointer to a
    memory control handle, which can be released again by
    <function>nmem_destroy()</function> when no longer needed.
    The function <function>nmem_malloc()</function> allocates a block of
    memory of the requested size. A call to <function>nmem_reset()</function>
    or <function>nmem_destroy()</function> will release all memory allocated
    on the handle since it was created (or since the last call to
    <function>nmem_reset()</function>. The function
    <function>nmem_total()</function> returns the number of bytes currently
    allocated on the handle.
   </para>
   <para>
    The nibble-memory pool is shared amongst threads. POSIX
    mutexes and WIN32 Critical sections are introduced to keep the
    module thread safe. Function <function>nmem_init()</function>
    initializes the nibble-memory library and it is called automatically
    the first time the <literal>YAZ.DLL</literal> is loaded. &yaz; uses
    function <function>DllMain</function> to achieve this. You should
    <emphasis>not</emphasis> call <function>nmem_init</function> or
    <function>nmem_exit</function> unless you're absolute sure what
    you're doing. Note that in previous &yaz; versions you'd have to call
    <function>nmem_init</function> yourself.
   </para>
  </sect1>
  <sect1 id="tools.log">
   <title>Log</title>
   <para>
    &yaz; has evolved a fairly complex log system which should be useful both
    for debugging &yaz; itself, debugging applications that use &yaz;, and for
    production use of those applications.
   </para>
   <para>
    The log functions are declared in header <filename>yaz/log.h</filename>
    and implemented in <filename>src/log.c</filename>.
    Due to name clash with syslog and some math utilities the logging
    interface has been modified as of YAZ 2.0.29. The obsolete interface
    is still available in header file <filename>yaz/log.h</filename>.
    The key points of the interface are:
   </para>
   <screen>
    void yaz_log(int level, const char *fmt, ...)
    void yaz_log_init(int level, const char *prefix, const char *name);
    void yaz_log_init_file(const char *fname);
    void yaz_log_init_level(int level);
    void yaz_log_init_prefix(const char *prefix);
    void yaz_log_time_format(const char *fmt);
    void yaz_log_init_max_size(int mx);

    int yaz_log_mask_str(const char *str);
    int yaz_log_module_level(const char *name);
   </screen>
   <para>
    The reason for the whole log module is the <function>yaz_log</function>
    function. It takes a bitmask indicating the log levels, a
    <literal>printf</literal>-like format string, and a variable number of
    arguments to log.
   </para>
   <para>
    The <literal>log level</literal> is a bit mask, that says on which level(s)
    the log entry should be made, and optionally set some behaviour of the
    logging. In the most simple cases, it can be one of <literal>YLOG_FATAL,
    YLOG_DEBUG, YLOG_WARN, YLOG_LOG</literal>. Those can be combined with bits
    that modify the way the log entry is written:<literal>YLOG_ERRNO,
    YLOG_NOTIME, YLOG_FLUSH</literal>.
    Most of the rest of the bits are deprecated, and should not be used. Use
    the dynamic log levels instead.
   </para>
   <para>
    Applications that use &yaz;, should not use the LOG_LOG for ordinary
    messages, but should make use of the dynamic loglevel system. This consists
    of two parts, defining the loglevel and checking it.
   </para>
   <para>
    To define the log levels, the (main) program should pass a string to
    <function>yaz_log_mask_str</function> to define which log levels are to be
    logged. This string should be a comma-separated list of log level names,
    and can contain both hard-coded names and dynamic ones. The log level
    calculation starts with <literal>YLOG_DEFAULT_LEVEL</literal> and adds a bit
    for each word it meets, unless the word starts with a '-', in which case it
    clears the bit. If the string <literal>'none'</literal> is found,
    all bits are cleared. Typically this string comes from the command-line,
    often identified by <literal>-v</literal>. The
    <function>yaz_log_mask_str</function> returns a log level that should be
    passed to <function>yaz_log_init_level</function> for it to take effect.
   </para>
   <para>
    Each module should check what log bits should be used, by calling
    <function>yaz_log_module_level</function> with a suitable name for the
    module. The name is cleared of a preceding path and an extension, if any,
    so it is quite possible to use <literal>__FILE__</literal> for it. If the
    name has been passed to <function>yaz_log_mask_str</function>, the routine
    returns a non-zero bitmask, which should then be used in consequent calls
    to yaz_log. (It can also be tested, so as to avoid unnecessary calls to
    yaz_log, in time-critical places, or when the log entry would take time
    to construct.)
   </para>
   <para>
    Yaz uses the following dynamic log levels:
    <literal>server, session, request, requestdetail</literal> for the server
    functionality.
    <literal>zoom</literal> for the zoom client API.
    <literal>ztest</literal> for the simple test server.
    <literal>malloc, nmem, odr, eventl</literal> for internal
    debugging of yaz itself.
    Of course, any program using yaz is welcome to define as many new
    ones as it needs.
   </para>
   <para>
    By default the log is written to stderr, but this can be changed by a call
    to <function>yaz_log_init_file</function> or
    <function>yaz_log_init</function>. If the log is directed to a file, the
    file size is checked at every write, and if it exceeds the limit given in
    <function>yaz_log_init_max_size</function>, the log is rotated. The
    rotation keeps one old version (with a <literal>.1</literal> appended to
    the name). The size defaults to 1GB. Setting it to zero will disable the
    rotation feature.
   </para>
   <screen>
    A typical yaz-log looks like this
  13:23:14-23/11 yaz-ztest(1) [session] Starting session from tcp:127.0.0.1 (pid=30968)
  13:23:14-23/11 yaz-ztest(1) [request] Init from 'YAZ' (81) (ver 2.0.28) OK
  13:23:17-23/11 yaz-ztest(1) [request] Search Z: @attrset Bib-1 foo  OK:7 hits
  13:23:22-23/11 yaz-ztest(1) [request] Present: [1] 2+2  OK 2 records returned
  13:24:13-23/11 yaz-ztest(1) [request] Close OK
   </screen>
   <para>
    The log entries start with a time stamp. This can be omitted by setting the
    <literal>YLOG_NOTIME</literal> bit in the loglevel. This way automatic tests
    can be hoped to produce identical log files, that are easy to diff. The
    format of the time stamp can be set with
    <function>yaz_log_time_format</function>, which takes a format string just
    like <function>strftime</function>.
   </para>
   <para>
    Next in a log line comes the prefix, often the name of the program. For
    yaz-based servers, it can also contain the session number. Then
    comes one or more logbits in square brackets, depending on the logging
    level set by <function>yaz_log_init_level</function> and the loglevel
    passed to <function>yaz_log_init_level</function>. Finally comes the format
    string and additional values passed to <function>yaz_log</function>
   </para>
   <para>
    The log level <literal>YLOG_LOGLVL</literal>, enabled by the string
    <literal>loglevel</literal>, will log all the log-level affecting
    operations. This can come in handy if you need to know what other log
    levels would be useful. Grep the logfile for <literal>[loglevel]</literal>.
   </para>
   <para>
    The log system is almost independent of the rest of &yaz;, the only
    important dependence is of <filename>nmem</filename>, and that only for
    using the semaphore definition there.
   </para>
   <para>
    The dynamic log levels and log rotation were introduced in &yaz; 2.0.28. At
    the same time, the log bit names were changed from
    <literal>LOG_something</literal> to <literal>YLOG_something</literal>,
    to avoid collision with <filename>syslog.h</filename>.
   </para>
  </sect1>
  <sect1 id="marc">
   <title>MARC</title>
   <para>
    YAZ provides a fast utility for working with MARC records.
    Early versions of the MARC utility only allowed decoding of ISO2709.
    Today the utility may both encode - and decode to a variety of formats.
   </para>
   <synopsis><![CDATA[
    #include <yaz/marcdisp.h>

    /* create handler */
    yaz_marc_t yaz_marc_create(void);
    /* destroy */
    void yaz_marc_destroy(yaz_marc_t mt);

    /* set XML mode YAZ_MARC_LINE, YAZ_MARC_SIMPLEXML, ... */
    void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
    #define YAZ_MARC_LINE      0
    #define YAZ_MARC_SIMPLEXML 1
    #define YAZ_MARC_OAIMARC   2
    #define YAZ_MARC_MARCXML   3
    #define YAZ_MARC_ISO2709   4
    #define YAZ_MARC_XCHANGE   5
    #define YAZ_MARC_CHECK     6
    #define YAZ_MARC_TURBOMARC 7
    #define YAZ_MARC_JSON      8

    /* supply iconv handle for character set conversion .. */
    void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);

    /* set debug level, 0=none, 1=more, 2=even more, .. */
    void yaz_marc_debug(yaz_marc_t mt, int level);

    /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
    On success, result in *result with size *rsize. */
    int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize,
                            const char **result, size_t *rsize);

    /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
       On success, result in WRBUF */
    int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf,
                              int bsize, WRBUF wrbuf);
]]>
   </synopsis>
   <note>
    <para>
     The synopsis is just a basic subset of all functionality. Refer
     to the actual header file <filename>marcdisp.h</filename> for
     details.
    </para>
   </note>
   <para>
    A MARC conversion handle must be created by using
    <function>yaz_marc_create</function> and destroyed
    by calling <function>yaz_marc_destroy</function>.
   </para>
   <para>
    All other functions operate on a <literal>yaz_marc_t</literal> handle.
    The output is specified by a call to <function>yaz_marc_xml</function>.
    The <literal>xmlmode</literal> must be one of
    <variablelist>
     <varlistentry>
      <term>YAZ_MARC_LINE</term>
      <listitem>
       <para>
	A simple line-by-line format suitable for display but not
	recommended for further (machine) processing.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>YAZ_MARC_MARCXML</term>
      <listitem>
       <para>
	<ulink url="&url.marcxml;">MARCXML</ulink>.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>YAZ_MARC_ISO2709</term>
      <listitem>
       <para>
	ISO2709 (sometimes just referred to as "MARC").
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>YAZ_MARC_XCHANGE</term>
      <listitem>
       <para>
	<ulink url="&url.marcxchange;">MarcXchange</ulink>.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>YAZ_MARC_CHECK</term>
      <listitem>
       <para>
	Pseudo format for validation only. Does not generate
	any real output except diagnostics.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>YAZ_MARC_TURBOMARC</term>
      <listitem>
       <para>
	XML format with same semantics as MARCXML but more compact
	and geared towards fast processing with XSLT. Refer to
	<xref linkend="tools.turbomarc"/> for more information.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>YAZ_MARC_JSON</term>
      <listitem>
       <para>
        <ulink url="&url.marc_in_json;">MARC-in-JSON</ulink> format.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
   <para>
    The actual conversion functions are
    <function>yaz_marc_decode_buf</function> and
    <function>yaz_marc_decode_wrbuf</function> which decodes and encodes
    a MARC record. The former function operates on simple buffers, and
    stores the resulting record in a WRBUF handle (WRBUF is a simple string
    type).
   </para>
   <example id="example.marc.display">
    <title>Display of MARC record</title>
    <para>
     The following program snippet illustrates how the MARC API may
     be used to convert a MARC record to the line-by-line format:
     <programlisting><![CDATA[
      void print_marc(const char *marc_buf, int marc_buf_size)
      {
         char *result;      /* for result buf */
         size_t result_len;    /* for size of result */
         yaz_marc_t mt = yaz_marc_create();
         yaz_marc_xml(mt, YAZ_MARC_LINE);
         yaz_marc_decode_buf(mt, marc_buf, marc_buf_size,
                             &result, &result_len);
         fwrite(result, result_len, 1, stdout);
         yaz_marc_destroy(mt);  /* note that result is now freed... */
      }
]]>
     </programlisting>
    </para>
   </example>
   <sect2 id="tools.turbomarc">
    <title>TurboMARC</title>
    <para>
     TurboMARC is yet another XML encoding of a MARC record. The format
     was designed for fast processing with XSLT.
    </para>
    <para>
     Applications like
     Pazpar2 uses XSLT to convert an XML encoded MARC record to an internal
     representation. This conversion mostly checks the tag of a MARC field
     to determine the basic rules in the conversion. This check is
     costly when that tag is encoded as an attribute in MARCXML.
     By having the tag value as the element instead, makes processing
     many times faster (at least for Libxslt).
    </para>
    <para>
     TurboMARC is encoded as follows:
     <itemizedlist>
      <listitem>
       <para>
	Record elements is part of namespace
	"<literal>http://www.indexdata.com/turbomarc</literal>".
      </para>
      </listitem>
      <listitem>
       <para>
	A record is enclosed in element <literal>r</literal>.
      </para>
      </listitem>
      <listitem>
       <para>
	A collection of records is enclosed in element
	<literal>collection</literal>.
       </para>
      </listitem>
      <listitem>
       <para>
	The leader is encoded as element <literal>l</literal> with the
	leader content as its (text) value.
      </para>
      </listitem>
      <listitem>
       <para>
	A control field is encoded as element <literal>c</literal> concatenated
	with the tag value of the control field if the tag value
	matches the regular expression <literal>[a-zA-Z0-9]*</literal>.
	If the tag value does not match the regular expression
	<literal>[a-zA-Z0-9]*</literal> the control field is encoded
	as element <literal>c</literal> and attribute <literal>code</literal>
	will hold the tag value.
	This rule ensures that in the rare cases where a tag value might
	result in a non-well-formed XML, then YAZ will encode it as a coded attribute
	(as in MARCXML).
       </para>
       <para>
	The control field content is the text value of this element.
	Indicators are encoded as attribute names
	<literal>i1</literal>, <literal>i2</literal>, etc. and
	corresponding values for each indicator.
       </para>
      </listitem>
      <listitem>
       <para>
	A data field is encoded as element <literal>d</literal> concatenated
	with the tag value of the data field or using the attribute
	<literal>code</literal> as described in the rules for control fields.
	The children of the data field element are subfield elements.
	Each subfield element is encoded as <literal>s</literal>
	concatenated with the sub field code.
	The text of the subfield element is the contents of the subfield.
	Indicators are encoded as attributes for the data field element, similar
	to the encoding for control fields.
      </para>
      </listitem>
     </itemizedlist>
    </para>
   </sect2>
  </sect1>
  <sect1 id="tools.retrieval">
   <title>Retrieval Facility</title>
   <para>
    YAZ version 2.1.20 or later includes a Retrieval facility tool
    which allows a SRU/Z39.50 to describe itself and perform record
    conversions. The idea is the following:
    <itemizedlist>
     <listitem>
      <para>
       An SRU/Z39.50 client sends a retrieval request which includes
       a combination of the following parameters: syntax (format),
       schema (or element set name).
      </para>
     </listitem>
     <listitem>
      <para>
       The retrieval facility is invoked with parameters in a
       server/proxy. The retrieval facility matches the parameters a set of
       "supported" retrieval types.
       If there is no match, the retrieval signals an error
       (syntax and / or schema not supported).
      </para>
     </listitem>
     <listitem>
      <para>
       For a successful match, the backend is invoked with the same
       or altered retrieval parameters (syntax, schema). If
       a record is received from the backend, it is converted to the
       frontend name / syntax.
      </para>
     </listitem>
     <listitem>
      <para>
       The resulting record is sent back the client and tagged with
       the frontend syntax / schema.
      </para>
     </listitem>
    </itemizedlist>
   </para>
   <para>
    The Retrieval facility is driven by an XML configuration. The
    configuration is neither Z39.50 ZeeRex or SRU ZeeRex. But it
    should be easy to generate both of them from the XML configuration.
    (Unfortunately the two versions
    of ZeeRex differ substantially in this regard.)
   </para>
   <sect2 id="tools.retrieval.format">
    <title>Retrieval XML format</title>
    <para>
     All elements should be covered by namespace
     <literal>http://indexdata.com/yaz</literal> .
     The root element node must be <literal>retrievalinfo</literal>.
    </para>
    <para>
     The <literal>retrievalinfo</literal> must include one or
     more <literal>retrieval</literal> elements. Each
    <literal>retrieval</literal> defines specific combination of
     syntax, name and identifier supported by this retrieval service.
    </para>
    <para>
     The <literal>retrieval</literal> element may include any of the
     following attributes:
     <variablelist>
      <varlistentry><term><literal>syntax</literal> (REQUIRED)</term>
       <listitem>
        <para>
         Defines the record syntax. Possible values is any
         of the names defined in YAZ' OID database or a raw
         OID in (n.n ... n).
        </para>
       </listitem>
      </varlistentry>
      <varlistentry><term><literal>name</literal> (OPTIONAL)</term>
       <listitem>
        <para>
         Defines the name of the retrieval format. This can be
         any string. For SRU, the value is equivalent to schema (short-hand);
         for Z39.50 it's equivalent to simple element set name.
         For YAZ 3.0.24 and later this name may be specified as a glob
         expression with operators
         <literal>*</literal> and <literal>?</literal>.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry><term><literal>identifier</literal> (OPTIONAL)</term>
       <listitem>
        <para>
         Defines the URI schema name of the retrieval format. This can be
         any string. For SRU, the value is equivalent to URI schema.
         For Z39.50, there is no equivalent.
        </para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
    <para>
     The <literal>retrieval</literal> may include one
     <literal>backend</literal> element. If a <literal>backend</literal>
     element is given, it specifies how the records are retrieved by
     some backend and how the records are converted from the backend to
     the "frontend".
    </para>
    <para>
     The attributes, <literal>name</literal> and <literal>syntax</literal>
     may be specified for the <literal>backend</literal> element. The
     semantics of these attributes is equivalent to those for the
     <literal>retrieval</literal>. However, these values are passed to
     the "backend".
    </para>
    <para>
     The <literal>backend</literal> element may include one or more
     conversion instructions (as children elements). The supported
     conversions are:
     <variablelist>
      <varlistentry><term><literal>marc</literal></term>
       <listitem>
        <para>
         The <literal>marc</literal> element specifies a conversion
         to - and from ISO2709 encoded MARC and
         <ulink url="&url.marcxml;">&acro.marcxml;</ulink>/MarcXchange.
         The following attributes may be specified:
         <variablelist>
          <varlistentry>
	   <term><literal>inputformat</literal> (REQUIRED)</term>
	   <listitem>
	    <para>
	     Format of input. Supported values are
	     <literal>marc</literal> (for ISO2709), <literal>xml</literal>
	     (MARCXML/MarcXchange) and <literal>json</literal>
             (<ulink url="&url.marc_in_json;">MARC-in-JSON</ulink>).
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
	   <term><literal>outputformat</literal> (REQUIRED)</term>
           <listitem>
            <para>
             Format of output. Supported values are
             <literal>line</literal> (MARC line format);
             <literal>marcxml</literal> (for MARCXML),
             <literal>marc</literal> (ISO2709),
             <literal>turbomarc</literal>,
             <literal>marcxchange</literal> (for MarcXchange),
             or <literal>json</literal>
             (<ulink url="&url.marc_in_json;">MARC-in-JSON </ulink>).
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
	   <term><literal>inputcharset</literal> (OPTIONAL)</term>
           <listitem>
            <para>
             Encoding of input. For XML input formats, this need not
             be given, but for ISO2709 based input formats, this should
             be set to the encoding used. For MARC21 records, a common
             inputcharset value would be <literal>marc-8</literal>.
            </para>
            <note>
             <para>
              If inputformat is <literal>marc</literal> and inputcharset
              is <literal>marc-8</literal>, then effective inputcharset is
              UTF-8 if leader position has value 'a' (MARC21 rule).
             </para>
            </note>
           </listitem>
          </varlistentry>
          <varlistentry>
	   <term><literal>outputcharset</literal> (OPTIONAL)</term>
           <listitem>
            <para>
             Encoding of output. If outputformat is XML based, it is
             strongly recommended to use <literal>utf-8</literal>.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry>
	   <term><literal>leaderspec</literal> (OPTIONAL)</term>
           <listitem>
            <para>
             Specifies a modification to the leader for the resulting output
             record. The <replaceable>leaderspec</replaceable> is a comma
             separated list of pos=value pairs, where pos is an integer offset
             (0 - 23) for leader. Value is either a quoted string or an integer
             (character value in decimal).
             For example, to set leader at offset 9 to a,
             use <literal>9='a'</literal>.
             This has same effect as <literal>-l</literal> for
             <xref linkend="yaz-marcdump"/>.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>select</literal></term>
       <listitem>
        <para>
         The <literal>select</literal> selects one or more text nodes
	 and decodes them as XML.
	 The following attributes may be specified:
         <variablelist>
          <varlistentry><term><literal>path</literal> (REQUIRED)</term>
           <listitem>
            <para>
             X-Path expression for selecting text nodes.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
        <para>
         This conversion is available in YAZ 5.8.0 and later.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>solrmarc</literal></term>
       <listitem>
        <para>
         The <literal>solrmarc</literal> decodes solrmarc records.
         It assumes that the input is pure solrmarc text (no escaping)
         and will convert all sequences of the form #XX; to a single
         character of the hexadecimal value as given by XX. The output,
         presumably, is a valid ISO2709 buffer.
        </para>
        <para>
         This conversion is available in YAZ 5.0.21 and later.
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>xslt</literal></term>
       <listitem>
        <para>
         The <literal>xslt</literal> element specifies a conversion
         via &acro.xslt;. The following attributes may be specified:
         <variablelist>
          <varlistentry><term><literal>stylesheet</literal> (REQUIRED)</term>
           <listitem>
            <para>
             Stylesheet file.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
        <para>
         In addition, the element can be configured as follows:
         <variablelist>
          <varlistentry><term><literal>param</literal> (OPTIONAL)</term>
           <listitem>
            <para>
             A <literal>param</literal> tag configures a parameter to be passed
             to the &acro.xslt; stylesheet. Multiple <literal>param</literal>
             tags may be defined.
            </para>
           </listitem>
          </varlistentry>
         </variablelist>
        </para>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><literal>rdf-lookup</literal></term>
       <listitem>
        <para>
         The <literal>rdf-lookup</literal> element looks up BIBFRAME elements
         in some suitable service, for example http://id.loc.gov/authorities/names
         and replaces the URIs for specified elements with URIs it finds at that
         service. Its configuration consists of
         <variablelist>
          <varlistentry><term><literal>debug</literal> (OPTIONAL)</term>
           <listitem>
            <para>
             Attribute to the <literal>rdf-lookup</literal> tag to enable debug
             output. A value of "1" makes the filter to add a XML comment
             next to each key it tried to look up, showing the URL, the result,
             and timing. This is useful for debugging the configuration. The
             default is not to add any comments.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry><term><literal>timeout</literal> (OPTIONAL)</term>
           <listitem>
            <para>
	      Attribute of the <literal>rdf-lookup</literal> tag which
	      defines timeout in seconds for the HTTP based rdf-lookup.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry><term><literal>namespace</literal> (OPTIONAL)</term>
           <listitem>
            <para>
             A <literal>namespace</literal> tag declares a namespace to be
             used in the <literal>xpath</literal> below. The tag requires
             two attributes: <literal>prefix</literal> and
             <literal>href</literal>.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry><term><literal>lookup</literal> (REQUIRED)</term>
           <listitem>
            <para>
              A section that defines one tag to be looked up, for example
              an author.The <literal>
              xpath</literal> attribute (REQUIRED) specifies the path to
              the element(s).
            </para>
           </listitem>
          </varlistentry>

          <varlistentry><term><literal>key</literal> (REQUIRED)</term>
           <listitem>
            <para>
              A tag withing the <literal>lookup</literal> tag specifies the
              value to be used in the lookup, for example a name or an ID. It
              is a relative Xpath starting from the tag specified in the
              <literal>lookup</literal>.
            </para>
           </listitem>
          </varlistentry>
          <varlistentry><term><literal>server</literal> (OPTIONAL)</term>
           <listitem>
            <para>
             Specifies the URL for server to use for the lookup.
             A <literal>%s</literal> is replaced by the key value to be looked
             up. If not specified, defaults to the same as the previous
             <literal>lookup</literal> section, or lacking one, to
             <ulink url="http://id.loc.gov/authorities/names/label/%s"/> .
             The <literal>method</literal> attribute can be used to specify
             the HTTP method to be used in this lookup. The default is GET,
             and the useful alternative is HEAD.
            </para>
           </listitem>
          </varlistentry>
          </variablelist>
        </para>
        <para>
         See the example below.
        </para>
        <para>
         This conversion is available in YAZ 5.19.0 and later.
        </para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </sect2>
   <sect2 id="tools.retrieval.examples">
    <title>Retrieval Facility Examples</title>
    <example id="tools.retrieval.marc21">
     <title>MARC21 backend</title>
     <para>
      A typical way to use the retrieval facility is to enable XML
      for servers that only supports ISO2709 encoded MARC21 records.
     </para>
     <programlisting><![CDATA[
     <retrievalinfo>
       <retrieval syntax="usmarc" name="F"/>
       <retrieval syntax="usmarc" name="B"/>
       <retrieval syntax="xml" name="marcxml"
		  identifier="info:srw/schema/1/marcxml-v1.1">
         <backend syntax="usmarc" name="F">
	   <marc inputformat="marc" outputformat="marcxml"
		 inputcharset="marc-8"/>
	 </backend>
       </retrieval>
       <retrieval syntax="xml" name="dc">
         <backend syntax="usmarc" name="F">
	   <marc inputformat="marc" outputformat="marcxml"
		 inputcharset="marc-8"/>
           <xslt stylesheet="MARC21slim2DC.xsl"/>
	 </backend>
       </retrieval>
     </retrievalinfo>
]]>
     </programlisting>
     <para>
      This means that our frontend supports:
      <itemizedlist>
       <listitem>
        <para>
         MARC21 F(ull) records.
        </para>
       </listitem>
       <listitem>
        <para>
         MARC21 B(rief) records.
        </para>
       </listitem>
       <listitem>
        <para>
         MARCXML records.
        </para>
       </listitem>
       <listitem>
        <para>
         Dublin core records.
        </para>
       </listitem>
      </itemizedlist>
     </para>
    </example>
    <example id="tools.retrieval.marcxml">
     <title>MARCXML backend</title>
     <para>
      SRW/SRU and Solr backends return records in XML.
      If they return MARCXML or MarcXchange, the retrieval module
      can convert those into ISO2709 formats, most commonly USMARC
      (AKA MARC21).
      In this example, the backend returns MARCXML for schema="marcxml".
     </para>
     <programlisting><![CDATA[
     <retrievalinfo>
       <retrieval syntax="usmarc">
         <backend syntax="xml" name="marcxml">
	   <marc inputformat="xml" outputformat="marc"
		 outputcharset="marc-8"/>
	 </backend>
       </retrieval>
       <retrieval syntax="xml" name="marcxml"
		  identifier="info:srw/schema/1/marcxml-v1.1"/>
       <retrieval syntax="xml" name="dc">
         <backend syntax="xml" name="marcxml">
           <xslt stylesheet="MARC21slim2DC.xsl"/>
	 </backend>
       </retrieval>
     </retrievalinfo>
]]>
     </programlisting>
     <para>
      This means that our frontend supports:
      <itemizedlist>
       <listitem>
        <para>
         MARC21 records (any element set name) in MARC-8 encoding.
        </para>
       </listitem>
       <listitem>
        <para>
         MARCXML records for element-set=marcxml
        </para>
       </listitem>
       <listitem>
        <para>
         Dublin core records for element-set=dc.
        </para>
       </listitem>
      </itemizedlist>
     </para>
    </example>
    <example id="tools.retrieval.rdf-lookup">
     <title>RDF-lookup backend</title>
     <para>
       This is a minimal example of the <literal>backend</literal> configuration
       for the rdf-lookup. It could well be used with some heavy xslt transforms
       that make BIBFRAME records out of MarxXml.
     </para>
     <programlisting><![CDATA[
        <backend syntax="xml" name="rdf-lookup">
          <rdf-lookup debug="1" timeout="10">
            <namespace prefix="bf" href="http://id.loc.gov/ontologies/bibframe/" />
            <namespace prefix="bflc" href="http://id.loc.gov/ontologies/bibframe/lc-extensions/"/>
            <lookup xpath="//bf:contribution/bf:Contribution/bf:agent/bf:Agent">
              <key field="bflc:name00MatchKey"/>
              <key field="bflc:name01MatchKey"/>
              <key field="bflc:name11MatchKey"/>
              <server url="http://id.loc.gov/authorities/names/label/%s" method="HEAD"/>
            </lookup>
          </rdf-lookup>
        </backend>
]]>
     </programlisting>
     <para>
       The <literal>debug=1</literal> attribute tells the filter to add XML
       comments to the key nodes that indicate what lookup it tried to do,
       how it went, and how long it took.
     </para>
     <para>
      The namespace prefix <literal>bf:</literal> is defined in the
      <literal>namespace</literal> tags. These namespaces are used in the
      xpath expressions in the lookup sections.
     </para>
     <para>
      The <literal>lookup</literal> tag specifies one tag to be looked up.
      The <literal>xpath</literal> attribute defines which node to modify. It
      may make use of the <literal>namespace</literal> definitions above.
     </para>
     <para>
      The <literal>server</literal> tag gives the URL to be used for the lookup.
      A <literal>%s</literal> in the string will get replaced by the key value.
      If there is no <literal>server</literal> tag, the one from the preceding
      <literal>lookup</literal> section is used, and if there is no previous
      section, the id.loc.gov address is used as a default. The default is to
      make a GET request, this example uses HEAD
     </para>
    </example>
   </sect2>
   <sect2 id="tools.retrieval.api">
    <title>API</title>
    <para>
     It should be easy to use the retrieval systems from applications. Refer
     to the headers
     <filename>yaz/retrieval.h</filename> and
     <filename>yaz/record_conv.h</filename>.
    </para>
   </sect2>
  </sect1>
  <sect1 id="sorting">
   <title>Sorting</title>
   <para>
    This chapter describes sorting and how it is supported in YAZ.
    Sorting applies to a result-set.
    The
    <ulink url="http://www.loc.gov/z3950/agency/markup/05.html#3.2.7">
     Z39.50 sorting facility
    </ulink>
    takes one or more input result-sets
    and one result-set as output. The most simple case is that
    the input-set is the same as the output-set.
   </para>
   <para>
    Z39.50 sorting has a separate APDU (service) that is, thus, performed
    following a search (two phases).
   </para>
   <para>
    In SRU/Solr, however, the model is different. Here, sorting is specified
    during the search operation. Note, however, that SRU might
    perform sort as separate search, by referring to an existing result-set
    in the query (result-set reference).
   </para>
   <sect2>
    <title>Using the Z39.50 sort service</title>
    <para>
     yaz-client and the ZOOM API support the Z39.50 sort facility. In any
     case the sort sequence or sort criteria is using a string notation.
     This notation is a one-line notation suitable for being manually
     entered or generated, and allows for easy logging (one liner).
     For the ZOOM API, the sort is specified in the call to ZOOM_query_sortby
     function. For yaz-client the sort is performed and specified using
     the sort and sort+ commands. For description of the sort criteria notation
     refer to the <link linkend="sortspec">sort command</link> in the
     yaz-client manual.
    </para>
    <para>
     The ZOOM API might choose one of several sort strategies for
     sorting. Refer to <xref linkend="zoom-sort-strategy"/>.
    </para>
   </sect2>
   <sect2>
    <title>Type-7 sort</title>
    <para>
     Type-7 sort is an extension to the Bib-1 based RPN query where the
     sort specification is embedded as an Attribute-Plus-Term.
    </para>
    <para>
     The objectives for introducing Type-7 sorting is that it allows
     a client to perform sorting even if it does not implement/support
     Z39.50 sort. Virtually all Z39.50 client software supports
     RPN queries. It also may improve performance because the sort
     criteria is specified along with the search query.
    </para>
    <para>
     The sort is triggered by the presence of type 7, and the value of type 7
     specifies the
     <ulink url="http://www.loc.gov/z3950/agency/asn1.html#SortKeySpec">
      sortRelation
     </ulink>.
     The value for type 7 is 1 for ascending and 2 for descending.
     For the
     <ulink url="http://www.loc.gov/z3950/agency/asn1.html#SortElement">
      sortElement
     </ulink>
     only the generic part is handled. If generic sortKey is of type
     sortField, then attribute type 1 is present and the value is
     sortField (InternationalString). If generic sortKey is of type
     sortAttributes, then the attributes in the list are used. Generic sortKey
     of type elementSpec is not supported.
    </para>
    <para>
     The term in the sorting Attribute-Plus-Term combo should hold
     an integer. The value is 0 for primary sorting criteria, 1 for second
     criteria, etc.
    </para>
   </sect2>
  </sect1>
  <sect1 id="facets">
   <title>Facets</title>
   <para>
    YAZ supports facets in the Solr, SRU 2.0 and Z39.50 protocols.
   </para>
   <para>
    Like Type-1/RPN, YAZ supports a string notation for specifying
    facets. This notataion maps straight to facets.asn.
    The notation is parsed by function
    <function>yaz_pqf_parse_facet_list</function> defined in header
    <filename>yaz/pquery.h</filename>.
   </para>
   <para>
    For ZOOM C the facets are specified by option "facets".
    For yaz-client, the 'facets' command is used.
   </para>
   <para>
    The grammar of this specification is as follows:
    <literallayout>
   facet-spec ::= facet-list

   facet-list ::= facet-list ',' attr-spec | attr-spec

   attr-spec ::= attr-spec '@attr' string | '@attr' string

    </literallayout>
    The notation is inspired by PQF. The string following '@attr'
    must not include blanks and is of the form
    <replaceable>type</replaceable><literal>=</literal><replaceable>value</replaceable>,
    where <replaceable>type</replaceable> is an integer and
    <replaceable>value</replaceable> is a string or an integer.
   </para>
   <para>
    There is no formal facets attribute set (it is not given in the
    protocol by the facets, although it could). The following types apply:
   </para>
   <table id="facet.attributes">
    <title>Facet attributes</title>
    <tgroup cols="2">
     <colspec colwidth="2*" colname="type"></colspec>
     <colspec colwidth="9*" colname="description"></colspec>
     <thead>
      <row>
       <entry>Type</entry>
       <entry>Description</entry>
      </row> </thead>
     <tbody>
      <row>
       <entry>1</entry>
       <entry>
	Field-name. This is often a string, e.g. "Author", "Year", etc.
       </entry>
      </row>
      <row>
       <entry>2</entry>
       <entry>
	Sort order. Value should be an integer.
	Value 0: count descending (frequency). Value 1: alpha ascending.
       </entry>
      </row>
      <row>
       <entry>3</entry>
       <entry>
	Number of terms requested.
       </entry>
      </row>
      <row>
       <entry>4</entry>
       <entry>
	Start offset (starting from 1)
       </entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </sect1>
 </chapter>
 <chapter id="odr">
  <title>The ODR Module</title>
  <sect1 id="odr.introduction">
   <title>Introduction</title>
   <para>
    &odr; is the BER-encoding/decoding subsystem of &yaz;. Care has been taken
    to isolate &odr; from the rest of the package - specifically from the
    transport interface. &odr; may be used in any context where basic
    ASN.1/BER representations are used.
   </para>
   <para>
    If you are only interested in writing a Z39.50 implementation based on
    the PDUs that are already provided with &yaz;, you only need to concern
    yourself with the section on managing ODR streams
    (<xref linkend="odr.use"/>). Only if you need to
    implement ASN.1 beyond that which has been provided, should you
    worry about the second half of the documentation
    (<xref linkend="odr.programming"/>).
    If you use one of the higher-level interfaces, you can skip this
    section entirely.
   </para>
   <para>
    This is important, so we'll repeat it for emphasis: <emphasis>You do
    not need to read <xref linkend="odr.programming"/>
    to implement Z39.50 with &yaz;.</emphasis>
   </para>
   <para>
    If you need a part of the protocol that isn't already in &yaz;, you
    should contact the authors before going to work on it yourself: We
    might already be working on it. Conversely, if you implement a useful
    part of the protocol before us, we'd be happy to include it in a
    future release.
   </para>
  </sect1>
  <sect1 id="odr.use">
   <title>Using ODR</title>
   <sect2 id="odr.streams">
    <title>ODR Streams</title>
    <para>
     Conceptually, the ODR stream is the source of encoded data in the
     decoding mode; when encoding, it is the receptacle for the encoded
     data. Before you can use an ODR stream it must be allocated. This is
     done with the function
    </para>
    <synopsis>
     ODR odr_createmem(int direction);
    </synopsis>
    <para>
     The <function>odr_createmem()</function> function takes as argument one
     of three manifest constants: <literal>ODR_ENCODE</literal>,
     <literal>ODR_DECODE</literal>, or <literal>ODR_PRINT</literal>.
     An &odr; stream can be in only one mode - it is not possible to change
     its mode once it's selected. Typically, your program will allocate
     at least two ODR streams - one for decoding, and one for encoding.
    </para>
    <para>
     When you're done with the stream, you can use
    </para>
    <synopsis>
     void odr_destroy(ODR o);
    </synopsis>
    <para>
     to release the resources allocated for the stream.
    </para>
   </sect2>
   <sect2 id="odr.memory.management">
    <title id="memory">Memory Management</title>
    <para>
     Two forms of memory management take place in the &odr; system. The first
     one, which has to do with allocating little bits of memory (sometimes
     quite large bits of memory, actually) when a protocol package is
     decoded, and turned into a complex of interlinked structures. This
     section deals with this system, and how you can use it for your own
     purposes. The next section deals with the memory management which is
     required when encoding data - to make sure that a large enough buffer is
     available to hold the fully encoded PDU.
    </para>
    <para>
     The &odr; module has its own memory management system, which is
     used whenever memory is required. Specifically, it is used to allocate
     space for data when decoding incoming PDUs. You can use the memory
     system for your own purposes, by using the function
    </para>
    <synopsis>
     void *odr_malloc(ODR o, size_t size);
    </synopsis>
    <para>
     You can't use the normal <function>free(2)</function> routine to free
     memory allocated by this function, and &odr; doesn't provide a parallel
     function. Instead, you can call
    </para>
    <synopsis>
     void odr_reset(ODR o);
    </synopsis>
    <para>
     when you are done with the
     memory: Everything allocated since the last call to
     <function>odr_reset()</function> is released.
     The <function>odr_reset()</function> call is also required to clear
     up an error condition on a stream.
    </para>
    <para>
     The function
    </para>
    <synopsis>
     size_t odr_total(ODR o);
    </synopsis>
    <para>
     returns the number of bytes allocated on the stream since the last call to
     <function>odr_reset()</function>.
    </para>
    <para>
     The memory subsystem of &odr; is fairly efficient at allocating and
     releasing little bits of memory. Rather than managing the individual,
     small bits of space, the system maintains a free-list of larger chunks
     of memory, which are handed out in small bits. This scheme is
     generally known as a <emphasis>nibble-memory</emphasis> system.
     It is very useful for maintaining short-lived constructions such
     as protocol PDUs.
    </para>
    <para>
     If you want to retain a bit of memory beyond the next call to
     <function>odr_reset()</function>, you can use the function
    </para>
    <synopsis>
     ODR_MEM odr_extract_mem(ODR o);
    </synopsis>
    <para>
     This function will give you control of the memory recently allocated
     on the ODR stream. The memory will live (past calls to
     <function>odr_reset()</function>), until you call the function
    </para>
    <synopsis>
     void odr_release_mem(ODR_MEM p);
    </synopsis>
    <para>
     The opaque <literal>ODR_MEM</literal> handle has no other purpose than
     referencing the memory block for you until you want to release it.
    </para>
    <para>
     You can use <function>odr_extract_mem()</function> repeatedly between
     allocating data, to retain individual control of separate chunks of data.
    </para>
   </sect2>
   <sect2 id="odr.encoding.and.decoding">
    <title>Encoding and Decoding Data</title>
    <para>
     When encoding data, the ODR stream will write the encoded octet string
     in an internal buffer. To retrieve the data, use the function
    </para>
    <synopsis>
     char *odr_getbuf(ODR o, int *len, int *size);
    </synopsis>
    <para>
     The integer pointed to by len is set to the length of the encoded
     data, and a pointer to that data is returned. <literal>*size</literal>
     is set to the size of the buffer (unless <literal>size</literal> is null,
     signaling that you are not interested in the size). The next call to
     a primitive function using the same &odr; stream will overwrite the
     data, unless a different buffer has been supplied using the call
    </para>
    <synopsis>
     void odr_setbuf(ODR o, char *buf, int len, int can_grow);
    </synopsis>
    <para>
     which sets the encoding (or decoding) buffer used by
     <literal>o</literal> to <literal>buf</literal>, using the length
     <literal>len</literal>.
     Before a call to an encoding function, you can use
     <function>odr_setbuf()</function> to provide the stream with an encoding
     buffer of sufficient size (length). The <literal>can_grow</literal>
     parameter tells the encoding &odr; stream whether it is allowed to use
     <function>realloc(2)</function> to increase the size of the buffer when
     necessary. The default condition of a new encoding stream is equivalent
     to the results of calling
    </para>
    <synopsis>
     odr_setbuf(stream, 0, 0, 1);
    </synopsis>
    <para>
     In this case, the stream will allocate and reallocate memory as
     necessary. The stream reallocates memory by repeatedly doubling the
     size of the buffer - the result is that the buffer will typically
     reach its maximum, working size with only a small number of reallocation
     operations. The memory is freed by the stream when the latter is destroyed,
     unless it was assigned by the user with the <literal>can_grow</literal>
     parameter set to zero (in this case, you are expected to retain
     control of the memory yourself).
    </para>
    <para>
     To assume full control of an encoded buffer, you must first call
     <function>odr_getbuf()</function> to fetch the buffer and its length.
     Next, you should call <function>odr_setbuf()</function> to provide a
     different buffer (or a null pointer) to the stream. In the simplest
     case, you will reuse the same buffer over and over again, and you
     will just need to call <function>odr_getbuf()</function> after each
     encoding operation to get the length and address of the buffer.
     Note that the stream may reallocate the buffer during an encoding
     operation, so it is necessary to retrieve the correct address after
     each encoding operation.
    </para>
    <para>
     It is important to realize that the ODR stream will not release this
     memory when you call <function>odr_reset()</function>: It will
     merely update its internal pointers to prepare for the encoding of a
     new data value.
     When the stream is released by the <function>odr_destroy()</function>
     function, the memory given to it by <function>odr_setbuf</function> will
     be released <emphasis>only</emphasis> if the <literal>can_grow</literal>
     parameter to <function>odr_setbuf()</function> was nonzero. The
     <literal>can_grow</literal> parameter, in other words, is a way of
     signaling who is to own the buffer, you or the ODR stream. If you never call
     <function>odr_setbuf()</function> on your encoding stream, which is
     typically the case, the buffer allocated by the stream will belong to
     the stream by default.
    </para>
    <para>
     When you wish to decode data, you should first call
     <function>odr_setbuf()</function>, to tell the decoding stream
     where to find the encoded data, and how long the buffer is
     (the <literal>can_grow</literal> parameter is ignored by a decoding
     stream). After this, you can call the function corresponding to the
     data you wish to decode (e.g. <function>odr_integer()</function> odr
     <function>z_APDU()</function>).
    </para>
    <example id="example.odr.encoding.and.decoding.functions">
     <title>Encoding and decoding functions</title>
     <synopsis>
      int odr_integer(ODR o, Odr_int **p, int optional, const char *name);

      int z_APDU(ODR o, Z_APDU **p, int optional, const char *name);
     </synopsis>
    </example>
    <para>
     If the data is absent (or doesn't match the tag corresponding to
     the type), the return value will be either 0 or 1 depending on the
     <literal>optional</literal> flag. If <literal>optional</literal>
     is 0 and the data is absent, an error flag will be raised in the
     stream, and you'll need to call <function>odr_reset()</function> before
     you can use the stream again. If <literal>optional</literal> is
     nonzero, the pointer <emphasis>pointed</emphasis> to/ by
     <literal>p</literal> will be set to the null value, and the function
     will return 1.
     The <literal>name</literal> argument is used to pretty-print the
     tag in question. It may be set to <literal>NULL</literal> if
     pretty-printing is not desired.
    </para>
    <para>
     If the data value is found where it's expected, the pointer
     <emphasis>pointed to</emphasis> by the <literal>p</literal> argument
     will be set to point to the decoded type.
     The space for the type will be allocated and owned by the &odr;
     stream, and it will live until you call
     <function>odr_reset()</function> on the stream. You cannot use
     <function>free(2)</function> to release the memory.
     You can decode several data elements (by repeated calls to
     <function>odr_setbuf()</function> and your decoding function), and
     new memory will be allocated each time. When you do call
     <function>odr_reset()</function>, everything decoded since the
     last call to <function>odr_reset()</function> will be released.
    </para>
    <example id="example.odr.encoding.of.integer">
     <title>Encoding and decoding of an integer</title>
     <para>
      The use of the double indirection can be a little confusing at first
      (its purpose will become clear later on, hopefully),
      so an example is in order. We'll encode an integer value, and
      immediately decode it again using a different stream. A useless, but
      informative operation.
     </para>
     <programlisting><![CDATA[
void do_nothing_useful(Odr_int value)
{
    ODR encode, decode;
    Odr_int *valp, *resvalp;
    char *bufferp;
    int len;

    /* allocate streams */
    if (!(encode = odr_createmem(ODR_ENCODE)))
        return;
    if (!(decode = odr_createmem(ODR_DECODE)))
        return;

    valp = &value;
    if (odr_integer(encode, &valp, 0, 0) == 0)
    {
        printf("encoding went bad\n");
        return;
    }
    bufferp = odr_getbuf(encode, &len, 0);
    printf("length of encoded data is %d\n", len);

    /* now let's decode the thing again */
    odr_setbuf(decode, bufferp, len, 0);
    if (odr_integer(decode, &resvalp, 0, 0) == 0)
    {
        printf("decoding went bad\n");
        return;
    }
    /* ODR_INT_PRINTF format for printf (such as %d) */
    printf("the value is " ODR_INT_PRINTF "\n", *resvalp);

    /* clean up */
    odr_destroy(encode);
    odr_destroy(decode);
}
]]>
     </programlisting>
     <para>
      This looks like a lot of work, offhand. In practice, the &odr; streams
      will typically be allocated once, in the beginning of your program
      (or at the beginning of a new network session), and the encoding
      and decoding will only take place in a few, isolated places in your
      program, so the overhead is quite manageable.
     </para>
    </example>
   </sect2>
   <sect2 id="odr.printing">
    <title>Printing</title>
    <para>
     When an ODR stream is created of type <literal>ODR_PRINT</literal>
     the ODR module will print the contents of a PDU in a readable format.
     By default output is written to the <literal>stderr</literal> stream.
     This behavior can be changed, however, by calling the function
     <synopsis>
      odr_setprint(ODR o, FILE *file);
     </synopsis>
     before encoders or decoders are being invoked.
     It is also possible to direct the output to a buffer (or indeed
     another file), by using the more generic mechanism:
     <synopsis>
      void odr_set_stream(ODR o, void *handle,
                         void (*stream_write)(ODR o, void *handle, int type,
                                              const char *buf, int len),
                         void (*stream_close)(void *handle));
     </synopsis>
     Here the user provides an opaque handle and two handlers,
     <replaceable>stream_write</replaceable> for writing,
     and <replaceable>stream_close</replaceable> which is supposed
     to close/free resources associated with handle.
     The <replaceable>stream_close</replaceable> handler is optional and
     if NULL for the function is provided, it will not be invoked.
     The <replaceable>stream_write</replaceable> takes the ODR handle
     as parameter, the user-defined handle, a type
     <literal>ODR_OCTETSTRING</literal>, <literal>ODR_VISIBLESTRING</literal>
     which indicates the type of contents being written.
    </para>
    <para>
     Another utility useful for diagnostics (error handling) or as
     part of the printing facilities is:
     <synopsis>
      const char **odr_get_element_path(ODR o);
     </synopsis>
     which returns a list of current elements that ODR deals with at the
     moment. For the returned array, say <literal>ar</literal>,
     then <literal>ar[0]</literal> is the top level element,
     <literal>ar[n]</literal> is the last. The last element has the
     property that <literal>ar[n+1] == NULL</literal>.
    </para>
    <example id="example.odr.element.path.record">
     <title>Element Path for record</title>
     <para>
      For a database record part of a PresentResponse the
      array returned by <function>odr_get_element</function>
      is <literal>presentResponse</literal>, <literal>databaseOrSurDiagnostics</literal>, <literal>?</literal>, <literal>record</literal>, <literal>?</literal>, <literal>databaseRecord</literal> . The question mark appears due to
      unnamed constructions.
     </para>
    </example>
   </sect2>
   <sect2 id="odr.diagnostics">
    <title>Diagnostics</title>
    <para>
     The encoding/decoding functions all return 0 when an error occurs.
     Until you call <function>odr_reset()</function>, you cannot use the
     stream again, and any function called will immediately return 0.
    </para>
    <para>
     To provide information to the programmer or administrator, the function
    </para>
    <synopsis>
     void odr_perror(ODR o, char *message);
    </synopsis>
    <para>
     is provided, which prints the <literal>message</literal> argument to
     <literal>stderr</literal> along with an error message from the stream.
    </para>
    <para>
     You can also use the function
    </para>
    <synopsis>
     int odr_geterror(ODR o);
    </synopsis>
    <para>
     to get the current error number from the screen. The number will be
     one of these constants:
    </para>
    <table frame="top" id="odr.error.codes">
     <title>ODR Error codes</title>
     <tgroup cols="2">
      <thead>
       <row>
	<entry>code</entry>
	<entry>Description</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>OMEMORY</entry><entry>Memory allocation failed.</entry>
       </row>
       <row>
	<entry>OSYSERR</entry><entry>A system- or library call has failed.
	 The standard diagnostic variable <literal>errno</literal> should be
	 examined to determine the actual error.</entry>
       </row>
       <row>
	<entry>OSPACE</entry><entry>No more space for encoding.
	 This will only occur when the user has explicitly provided a
	 buffer for an encoding stream without allowing the system to
	 allocate more space.</entry>
       </row>
       <row>
	<entry>OREQUIRED</entry><entry>This is a common protocol error; A
	 required data element was missing during encoding or decoding.</entry>
       </row>
       <row>
	<entry>OUNEXPECTED</entry><entry>An unexpected data element was
	found during decoding.</entry>
       </row>
       <row>
	<entry>OOTHER</entry><entry>Other error. This is typically an
	indication of misuse of the &odr; system by the programmer, and also
	that the diagnostic system isn't as good as it should be, yet.</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
    <para>
     The character string array
    </para>
    <synopsis>
     char *odr_errlist[]
    </synopsis>
    <para>
     can be indexed by the error code to obtain a human-readable
     representation of the problem.
    </para>
   </sect2>
   <sect2 id="odr.summary.and.synopsis">
    <title>Summary and Synopsis</title>
    <synopsis>
     #include &lt;yaz/odr.h>

     ODR odr_createmem(int direction);

     void odr_destroy(ODR o);

     void odr_reset(ODR o);

     char *odr_getbuf(ODR o, int *len, int *size);

     void odr_setbuf(ODR o, char *buf, int len, int can_grow);

     void *odr_malloc(ODR o, int size);

     NMEM odr_extract_mem(ODR o);

     int odr_geterror(ODR o);

     void odr_perror(ODR o, const char *message);

     extern char *odr_errlist[];
    </synopsis>
   </sect2>
  </sect1>
  <sect1 id="odr.programming">
   <title>Programming with ODR</title>
   <para>
    The API of &odr; is designed to reflect the structure of ASN.1, rather
    than BER itself. Future releases may be able to represent data in
    other external forms.
   </para>
   <tip>
    <para>
     There is an ASN.1 tutorial available at
     <ulink url="&url.asn.1.tutorial;">this site</ulink>.
     This site also has standards for ASN.1 (X.680) and BER (X.690)
     <ulink url="&url.asn.1.standards;">online</ulink>.
    </para>
   </tip>
   <para>
    The ODR interface is based loosely on that of the Sun Microsystems
    XDR routines.
    Specifically, each function which corresponds to an ASN.1 primitive
    type has a dual function. Depending on the settings of the ODR
    stream which is supplied as a parameter, the function may be used
    either to encode or decode data. The functions that can be built
    using these primitive functions, to represent more complex data types,
    share this quality. The result is that you only have to enter the
    definition for a type once - and you have the functionality of encoding,
    decoding (and pretty-printing) all in one unit.
    The resulting C source code is quite compact, and is a pretty
    straightforward representation of the source ASN.1 specification.
   </para>
   <para>
    In many cases, the model of the XDR functions works quite well in this
    role.
    In others, it is less elegant. Most of the hassle comes from the optional
    SEQUENCE members which don't exist in XDR.
   </para>
   <sect2 id="odr.primitive.asn1.types">
    <title>The Primitive ASN.1 Types</title>
    <para>
     ASN.1 defines a number of primitive types (many of which correspond
     roughly to primitive types in structured programming languages, such as C).
    </para>
    <sect3 id="odr.integer">
     <title>INTEGER</title>
     <para>
      The &odr; function for encoding or decoding (or printing) the ASN.1
      INTEGER type looks like this:
     </para>
     <synopsis>
      int odr_integer(ODR o, Odr_int **p, int optional, const char *name);
     </synopsis>
     <para>
      The <literal>Odr_int</literal> is just a simple integer.
     </para>
     <para>
      This form is typical of the primitive &odr; functions. They are named
      after the type of data that they encode or decode. They take an &odr;
      stream, an indirect reference to the type in question, and an
      <literal>optional</literal> flag (corresponding to the OPTIONAL keyword
      of ASN.1) as parameters. They all return an integer value of either one
      or zero.
      When you use the primitive functions to construct encoders for complex
      types of your own, you should follow this model as well. This
      ensures that your new types can be reused as elements in yet more
      complex types.
     </para>
     <para>
      The <literal>o</literal> parameter should obviously refer to a properly
      initialized &odr; stream of the right type (encoding/decoding/printing)
      for the operation that you wish to perform.
     </para>
     <para>
      When encoding or printing, the function first looks at
      <literal>* p</literal>. If <literal>* p</literal> (the pointer pointed
      to by <literal>p</literal>) is a null pointer, this is taken to mean that
      the data element is absent. If the <literal>optional</literal> parameter
      is nonzero, the function will return one (signifying success) without
      any further processing. If the <literal>optional</literal> is zero, an
      internal error flag is set in the &odr; stream, and the function will
      return 0. No further operations can be carried out on the stream without
      a call to the function <function>odr_reset()</function>.
     </para>
     <para>
      If <literal>*p</literal> is not a null pointer, it is expected to
      point to an instance of the data type. The data will be subjected to
      the encoding rules, and the result will be placed in the buffer held
      by the &odr; stream.
     </para>
     <para>
      The other ASN.1 primitives have similar functions that operate in
      similar manners:
     </para>
    </sect3>
    <sect3 id="odr.boolean">
     <title>BOOLEAN</title>
     <synopsis>
int odr_bool(ODR o, Odr_bool **p, int optional, const char *name);
     </synopsis>
    </sect3>
    <sect3 id="odr.real">
     <title>REAL</title>
     <para>
      Not defined.
     </para>
    </sect3>
    <sect3 id="odr.null">
     <title>NULL</title>
     <synopsis>
int odr_null(ODR o, Odr_null **p, int optional, const char *name);
     </synopsis>
     <para>
      In this case, the value of **p is not important. If <literal>*p</literal>
      is different from the null pointer, the null value is present, otherwise
      it's absent.
     </para>
    </sect3>
    <sect3 id="odr.octet.string">
     <title>OCTET STRING</title>
     <synopsis>
typedef struct odr_oct
{
    unsigned char *buf;
    int len;
} Odr_oct;

int odr_octetstring(ODR o, Odr_oct **p, int optional,
                    const char *name);
     </synopsis>
     <para>
      The <literal>buf</literal> field should point to the character array
      that holds the octetstring. The <literal>len</literal> field holds the
      actual length.
      The character array need not be null-terminated.
     </para>
     <para>
      To make things a little easier, an alternative is given for string
      types that are not expected to contain embedded NULL characters (e.g.
      VisibleString):
     </para>
     <synopsis>
      int odr_cstring(ODR o, char **p, int optional, const char *name);
     </synopsis>
     <para>
      which encodes or decodes between OCTETSTRING representations and
      null-terminated C strings.
     </para>
     <para>
      Functions are provided for the derived string types, e.g.:
     </para>
     <synopsis>
int odr_visiblestring(ODR o, char **p, int optional,
                      const char *name);
     </synopsis>
    </sect3>
    <sect3 id="odr.bit.string">
     <title>BIT STRING</title>
     <synopsis>
int odr_bitstring(ODR o, Odr_bitmask **p, int optional,
                  const char *name);
     </synopsis>
     <para>
      The opaque type <literal>Odr_bitmask</literal> is only suitable for
      holding relatively brief bit strings, e.g. for options fields, etc.
      The constant <literal>ODR_BITMASK_SIZE</literal> multiplied by 8
      gives the maximum possible number of bits.
     </para>
     <para>
      A set of macros are provided for manipulating the
      <literal>Odr_bitmask</literal> type:
     </para>
     <synopsis>
void ODR_MASK_ZERO(Odr_bitmask *b);

void ODR_MASK_SET(Odr_bitmask *b, int bitno);

void ODR_MASK_CLEAR(Odr_bitmask *b, int bitno);

int ODR_MASK_GET(Odr_bitmask *b, int bitno);
     </synopsis>
     <para>
      The functions are modeled after the manipulation functions that
      accompany the <literal>fd_set</literal> type used by the
      <function>select(2)</function> call.
      <literal>ODR_MASK_ZERO</literal> should always be called first on a
      new bitmask, to initialize the bits to zero.
     </para>
    </sect3>
    <sect3 id="odr.object.identifier">
     <title>OBJECT IDENTIFIER</title>
     <synopsis>
int odr_oid(ODR o, Odr_oid **p, int optional, const char *name);
     </synopsis>
     <para>
      The C OID representation is simply an array of integers, terminated by
      the value -1 (the <literal>Odr_oid</literal> type is synonymous with
      the <literal>short</literal> type).
      We suggest that you use the OID database module (see
      <xref linkend="tools.oid.database"/>) to handle object identifiers
      in your application.
     </para>
    </sect3>
   </sect2>
   <sect2 id="odr.tagging.primitive.types">
    <title>Tagging Primitive Types</title>
    <para>
     The simplest way of tagging a type is to use the
     <function>odr_implicit_tag()</function> or
     <function>odr_explicit_tag()</function> macros:
    </para>
    <synopsis>
int odr_implicit_tag(ODR o, Odr_fun fun, int class, int tag,
                     int optional, const char *name);

int odr_explicit_tag(ODR o, Odr_fun fun, int class, int tag,
                     int optional, const char *name);
    </synopsis>
    <para>
     To create a type derived from the integer type by implicit tagging, you
     might write:
    </para>
    <screen>
     MyInt ::= [210] IMPLICIT INTEGER
    </screen>
    <para>
     In the &odr; system, this would be written like:
    </para>
    <screen>
int myInt(ODR o, Odr_int **p, int optional, const char *name)
{
    return odr_implicit_tag(o, odr_integer, p,
			    ODR_CONTEXT, 210, optional, name);
}
    </screen>
    <para>
     The function <function>myInt()</function> can then be used like any of
     the primitive functions provided by &odr;. Note that the behavior of
     <function>odr_explicit_tag()</function>
     and <function>odr_implicit_tag()</function> macros
     act exactly the same as the functions they are applied to - they
     respond to error conditions, etc, in the same manner - they
     simply have three extra parameters. The class parameter may
     take one of the values: <literal>ODR_CONTEXT</literal>,
     <literal>ODR_PRIVATE</literal>, <literal>ODR_UNIVERSAL</literal>, or
     <literal>/ODR_APPLICATION</literal>.
    </para>
   </sect2>
   <sect2 id="odr.constructed.types">
    <title>Constructed Types</title>
    <para>
     Constructed types are created by combining primitive types. The
      &odr; system only implements the SEQUENCE and SEQUENCE OF constructions
     (although adding the rest of the container types should be simple
     enough, if the need arises).
    </para>
    <para>
     For implementing SEQUENCEs, the functions
    </para>
    <synopsis>
int odr_sequence_begin(ODR o, void *p, int size, const char *name);
int odr_sequence_end(ODR o);
    </synopsis>
    <para>
     are provided.
    </para>
    <para>
     The <function>odr_sequence_begin()</function> function should be
     called in the beginning of a function that implements a SEQUENCE type.
     Its parameters are the &odr; stream, a pointer (to a pointer to the type
     you're implementing), and the <literal>size</literal> of the type
     (typically a C structure). On encoding, it returns 1 if
     <literal>* p</literal> is a null pointer. The <literal>size</literal>
     parameter is ignored. On decoding, it returns 1 if the type is found in
     the data stream. <literal>size</literal> bytes of memory are allocated,
     and <literal>*p</literal> is set to point to this space.
     The <function>odr_sequence_end()</function> is called at the end of the
     complex function. Assume that a type is defined like this:
    </para>
    <screen>
MySequence ::= SEQUENCE {
     intval INTEGER,
     boolval BOOLEAN OPTIONAL
}
    </screen>
    <para>
     The corresponding &odr; encoder/decoder function and the associated data
     structures could be written like this:
    </para>
    <screen>
typedef struct MySequence
{
    Odr_int *intval;
    Odr_bool *boolval;
} MySequence;

int mySequence(ODR o, MySequence **p, int optional, const char *name)
{
    if (odr_sequence_begin(o, p, sizeof(**p), name) == 0)
        return optional &amp;&amp; odr_ok(o);
    return
        odr_integer(o, &amp;(*p)->intval, 0, "intval") &amp;&amp;
        odr_bool(o, &amp;(*p)->boolval, 1, "boolval") &amp;&amp;
        odr_sequence_end(o);
}
    </screen>
    <para>
     Note the 1 in the call to <function>odr_bool()</function>, to mark
     that the sequence member is optional.
     If either of the member types had been tagged, the macros
     <function>odr_implicit_tag()</function> or
     <function>odr_explicit_tag()</function>
     could have been used.
     The new function can be used exactly like the standard functions provided
     with &odr;. It will encode, decode or pretty-print a data value of the
     <literal>MySequence</literal> type. We like to name types with an
     initial capital, as done in ASN.1 definitions, and to name the
     corresponding function with the first character of the name in lower case.
     You could, of course, name your structures, types, and functions any way
     you please - as long as you're consistent, and your code is easily readable.
     <literal>odr_ok</literal> is just that - a predicate that returns the
     state of the stream. It is used to ensure that the behavior of the new
     type is compatible with the interface of the primitive types.
    </para>
   </sect2>
   <sect2 id="odr.tagging.constructed.types">
    <title>Tagging Constructed Types</title>
    <note>
     <para>
      See <xref linkend="odr.tagging.primitive.types"/> for information
      on how to tag the primitive types, as well as types that are
      already defined.
     </para>
    </note>
    <sect3 id="odr.implicit.tagging">
     <title>Implicit Tagging</title>
     <para>
      Assume the type above had been defined as
     </para>
     <screen>
MySequence ::= [10] IMPLICIT SEQUENCE {
      intval INTEGER,
      boolval BOOLEAN OPTIONAL
}
     </screen>
     <para>
      You would implement this in &odr; by calling the function
     </para>
     <synopsis>
int odr_implicit_settag(ODR o, int class, int tag);
     </synopsis>
     <para>
      which overrides the tag of the type immediately following it. The
      macro <function>odr_implicit_tag()</function> works by calling
      <function>odr_implicit_settag()</function> immediately
      before calling the function pointer argument.
      Your type function could look like this:
     </para>
     <screen>
int mySequence(ODR o, MySequence **p, int optional, const char *name)
{
    if (odr_implicit_settag(o, ODR_CONTEXT, 10) == 0 ||
        odr_sequence_begin(o, p, sizeof(**p), name) == 0)
        return optional &amp;&amp; odr_ok(o);
    return
        odr_integer(o, &amp;(*p)->intval, 0, "intval") &amp;&amp;
        odr_bool(o, &amp;(*p)->boolval, 1, "boolval") &amp;&amp;
        odr_sequence_end(o);
}
     </screen>
     <para>
      The definition of the structure <literal>MySequence</literal> would be
      the same.
     </para>
    </sect3>
    <sect3 id="odr.explicit.tagging">
     <title>Explicit Tagging</title>
     <para>
      Explicit tagging of constructed types is a little more complicated,
      since you are in effect adding a level of construction to the data.
     </para>
     <para>
      Assume the definition:
     </para>
     <screen>
MySequence ::= [10] IMPLICIT SEQUENCE {
   intval INTEGER,
   boolval BOOLEAN OPTIONAL
}
     </screen>
     <para>
      Since the new type has an extra level of construction, two new functions
      are needed to encapsulate the base type:
     </para>
     <synopsis>
int odr_constructed_begin(ODR o, void *p, int class, int tag,
                          const char *name);

int odr_constructed_end(ODR o);
     </synopsis>
     <para>
      Assume that the IMPLICIT in the type definition above were replaced
      with EXPLICIT (or that the IMPLICIT keyword was simply deleted, which
      would be equivalent). The structure definition would look the same,
      but the function would look like this:
     </para>
     <screen>
int mySequence(ODR o, MySequence **p, int optional, const char *name)
{
    if (odr_constructed_begin(o, p, ODR_CONTEXT, 10, name) == 0)
        return optional &amp;&amp; odr_ok(o);
    if (o->direction == ODR_DECODE)
        *p = odr_malloc(o, sizeof(**p));
    if (odr_sequence_begin(o, p, sizeof(**p), 0) == 0)
    {
        *p = 0; /* this is almost certainly a protocol error */
        return 0;
    }
    return
        odr_integer(o, &amp;(*p)->intval, 0, "intval") &amp;&amp;
        odr_bool(o, &amp;(*p)->boolval, 1, "boolval") &amp;&amp;
        odr_sequence_end(o) &amp;&amp;
        odr_constructed_end(o);
}
     </screen>
     <para>
      Notice that the interface here gets kind of nasty. The reason is
      simple: Explicitly tagged, constructed types are fairly rare in
      the protocols that we care about, so the
      aesthetic annoyance (not to mention the dangers of a cluttered
      interface) is less than the time that would be required to develop a
      better interface. Nevertheless, it is far from satisfying, and it's a
      point that will be worked on in the future. One option for you would
      be to simply apply the <function>odr_explicit_tag()</function> macro to
      the first function, and not
      have to worry about <function>odr_constructed_*</function> yourself.
      Incidentally, as you might have guessed, the
      <function>odr_sequence_</function> functions are themselves
      implemented using the <function>/odr_constructed_</function> functions.
     </para>
    </sect3>
   </sect2>
   <sect2 id="odr.sequence.of">
    <title>SEQUENCE OF</title>
    <para>
     To handle sequences (arrays) of a specific type, the function
    </para>
    <synopsis>
int odr_sequence_of(ODR o, int (*fun)(ODR o, void *p, int optional),
                    void *p, int *num, const char *name);
    </synopsis>
    <para>
     The <literal>fun</literal> parameter is a pointer to the decoder/encoder
     function of the type. <literal>p</literal> is a pointer to an array of
     pointers to your type. <literal>num</literal> is the number of elements
     in the array.
    </para>
    <para>
     Assume a type
    </para>
    <screen>
MyArray ::= SEQUENCE OF INTEGER
    </screen>
    <para>
     The C representation might be
    </para>
    <screen>
typedef struct MyArray
{
    int num_elements;
    Odr_int **elements;
} MyArray;
    </screen>
    <para>
     And the function might look like
    </para>
    <screen>
int myArray(ODR o, MyArray **p, int optional, const char *name)
{
    if (o->direction == ODR_DECODE)
        *p = odr_malloc(o, sizeof(**p));
    if (odr_sequence_of(o, odr_integer, &amp;(*p)->elements,
        &amp;(*p)->num_elements, name))
        return 1;
    *p = 0;
        return optional &amp;&amp; odr_ok(o);
}
    </screen>
   </sect2>
   <sect2 id="odr.choice.types">
    <title>CHOICE Types</title>
    <para>
     The choice type is used fairly often in some ASN.1 definitions, so
     some work has gone into streamlining its interface.
    </para>
    <para>
     CHOICE types are handled by the function:
    </para>
    <synopsis>
int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp,
               const char *name);
    </synopsis>
    <para>
     The <literal>arm</literal> array is used to describe each of the possible
     types that the CHOICE type may assume. Internally in your application,
     the CHOICE type is represented as a discriminated union. That is, a
     C union accompanied by an integer (or enum) identifying the active
     'arm' of the union.
     <literal>whichp</literal> is a pointer to the union discriminator.
     When encoding, it is examined to determine the current type.
     When decoding, it is set to reference the type that was found in
     the input stream.
    </para>
    <para>
     The Odr_arm type is defined thus:
    </para>
    <screen>
typedef struct odr_arm
{
    int tagmode;
    int class;
    int tag;
    int which;
    Odr_fun fun;
    char *name;
} Odr_arm;
    </screen>
    <para>
     The interpretation of the fields are:
    </para>
    <variablelist>
     <varlistentry>
      <term>tagmode</term>
      <listitem><para>Either <literal>ODR_IMPLICIT</literal>,
      <literal>ODR_EXPLICIT</literal>, or <literal>ODR_NONE</literal> (-1)
      to mark	no tagging.</para></listitem>
     </varlistentry>
     <varlistentry>
      <term>which</term>
      <listitem><para>The value of the discriminator that corresponds to
      this CHOICE element. Typically, it will be a #defined constant, or
      an enum member.</para></listitem>
     </varlistentry>
     <varlistentry>
      <term>fun</term>
      <listitem><para>A pointer to a function that implements the type of
      the CHOICE member. It may be either a standard &odr; type or a type
      defined by yourself.</para></listitem>
     </varlistentry>
     <varlistentry>
      <term>name</term>
      <listitem><para>Name of tag.</para></listitem>
     </varlistentry>
    </variablelist>
    <para>
     A handy way to prepare the array for use by the
     <function>odr_choice()</function> function is to
     define it as a static, initialized array in the beginning of your
     decoding/encoding function. Assume the type definition:
    </para>
    <screen>
MyChoice ::= CHOICE {
    untagged INTEGER,
    tagged   [99] IMPLICIT INTEGER,
    other    BOOLEAN
}
    </screen>
    <para>
     Your C type might look like
    </para>
    <screen>
typedef struct MyChoice
{
    enum
    {
        MyChoice_untagged,
        MyChoice_tagged,
        MyChoice_other
    } which;
    union
    {
        Odr_int *untagged;
        Odr_int *tagged;
        Odr_bool *other;
    } u;
};
    </screen>
    <para>
     And your function could look like this:
    </para>
    <screen>
int myChoice(ODR o, MyChoice **p, int optional, const char *name)
{
    static Odr_arm arm[] =
    {
      {-1, -1, -1, MyChoice_untagged, odr_integer, "untagged"},
      {ODR_IMPLICIT, ODR_CONTEXT, 99, MyChoice_tagged, odr_integer,
      "tagged"},
      {-1, -1, -1, MyChoice_other, odr_boolean, "other"},
      {-1, -1, -1, -1, 0}
    };

    if (o->direction == ODR_DECODE)
        *p = odr_malloc(o, sizeof(**p);
    else if (!*p)
        return optional &amp;&amp; odr_ok(o);

    if (odr_choice(o, arm, &amp;(*p)->u, &amp;(*p)->which), name)
        return 1;
    *p = 0;
        return optional &amp;&amp; odr_ok(o);
}
    </screen>
    <para>
     In some cases (say, a non-optional choice which is a member of a
     sequence), you can "embed" the union and its discriminator in the
     structure belonging to the enclosing type, and you won't need to
     fiddle with memory allocation to create a separate structure to
     wrap the discriminator and union.
    </para>
    <para>
     The corresponding function is somewhat nicer in the Sun XDR interface.
     Most of the complexity of this interface comes from the possibility of
     declaring sequence elements (including CHOICEs) optional.
    </para>
    <para>
     The ASN.1 specifications naturally require that each member of a
     CHOICE have a distinct tag, so they can be told apart on decoding.
     Sometimes it can be useful to define a CHOICE that has multiple types
     that share the same tag. You'll need some other mechanism, perhaps
     keyed to the context of the CHOICE type. In effect, we would like to
     introduce a level of context-sensitiveness to our ASN.1 specification.
     When encoding an internal representation, we have no problem, as long
     as each CHOICE member has a distinct discriminator value. For
     decoding, we need a way to tell the choice function to look for a
     specific arm of the table. The function
    </para>
    <synopsis>
void odr_choice_bias(ODR o, int what);
    </synopsis>
    <para>
     provides this functionality. When called, it leaves a notice for the next
     call to <function>odr_choice()</function> to be called on the decoding
     stream <literal>o</literal>, that only the <literal>arm</literal> entry with
     a <literal>which</literal> field equal to <literal>what</literal>
     should be tried.
    </para>
    <para>
     The most important application (perhaps the only one, really) is in
     the definition of application-specific EXTERNAL encoders/decoders
     which will automatically decode an ANY member given the direct or
     indirect reference.
    </para>
   </sect2>
  </sect1>
  <sect1 id="odr.debugging">
   <title>Debugging</title>
   <para>
    The protocol modules are suffering somewhat from a lack of diagnostic
    tools at the moment. Specifically ways to pretty-print PDUs that
    aren't recognized by the system. We'll include something to this end
    in a not-too-distant release. In the meantime, what we do when we get
    packages we don't understand is to compile the ODR module with
    <literal>ODR_DEBUG</literal> defined. This causes the module to dump tracing
    information as it processes data units. With this output and the
    protocol specification (Z39.50), it is generally fairly easy to see
    what goes wrong.
   </para>
  </sect1>
 </chapter>
 <chapter id="comstack">
  <title>The COMSTACK Module</title>
  <sect1 id="comstack.synopsis">
   <title>Synopsis (blocking mode)</title>
   <programlisting><![CDATA[
    COMSTACK stack;
    char *buf = 0;
    int size = 0, length_incoming;
    char server_address_str[] = "localhost:9999";
    void *server_address_ip;
    int status;

    char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
    int protocol_package_length = strlen(protocol_package);

    stack = cs_create(tcpip_type, 1, PROTO_HTTP);
    if (!stack) {
        perror("cs_create");  /* use perror() here since we have no stack yet */
        return -1;
    }

    server_address_ip = cs_straddr(stack, server_address_str);
    if (!server_address_ip) {
        fprintf(stderr, "cs_straddr: address could not be resolved\n");
        return -1;
    }

    status = cs_connect(stack, server_address_ip);
    if (status) {
        fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
        return -1;
    }

    status = cs_rcvconnect(stack);
    if (status) {
        fprintf(stderr, "cs_rcvconnect: %s\n", cs_strerror(stack));
        return -1;
    }

    status = cs_put(stack, protocol_package, protocol_package_length);
    if (status) {
        fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
        return -1;
    }

    /* Now get a response */
    length_incoming = cs_get(stack, &buf, &size);
    if (!length_incoming) {
        fprintf(stderr, "Connection closed\n");
        return -1;
    } else if (length_incoming < 0) {
        fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
        return -1;
    }

    /* Print result */
    fwrite(buf, length_incoming, 1, stdout);

    /* clean up */
    cs_close(stack);
    if (buf)
        xfree(buf);
    return 0;
]]>
   </programlisting>

  </sect1>
  <sect1 id="comstack.introduction">
   <title>Introduction</title>
   <para>
    The &comstack;
    subsystem provides a transparent interface to different types of transport
    stacks for the exchange of BER-encoded data and HTTP packets.
    At present, the RFC1729 method (BER over TCP/IP), local UNIX socket and an
    experimental SSL stack are supported, but others may be added in time.
    The philosophy of the
    module is to provide a simple interface by hiding unused options and
    facilities of the underlying libraries. This is always done at the risk
    of losing generality, and it may prove that the interface will need
    extension later on.
   </para>
   <note>
    <para>
     There hasn't been interest in the XTImOSI stack for some years.
     Therefore, it is no longer supported.
     </para>
   </note>
   <para>
    The interface is implemented in such a fashion that only the
    sub-layers constructed to the transport methods that you wish to
    use in your application are linked in.
   </para>
   <para>
    You will note that even though simplicity was a goal in the design,
    the interface is still orders of magnitudes more complex than the
    transport systems found in many other packages. One reason is that
    the interface needs to support the somewhat different requirements of
    the different lower-layer communications stacks; another important
    reason is that the interface seeks to provide a more or less
    industrial-strength approach to asynchronous event-handling.
    When no function is allowed to block, things get more complex -
    particularly on the server side.
    We urge you to have a look at the demonstration client and server
    provided with the package. They are meant to be easily readable and
    instructive, while still being at least moderately useful.
   </para>
  </sect1>
  <sect1 id="comstack.common">
   <title>Common Functions</title>
   <sect2 id="comstack.managing.endpoints">
    <title>Managing Endpoints</title>
    <synopsis>
     COMSTACK cs_create(CS_TYPE type, int blocking, int protocol);
    </synopsis>
    <para>
     Creates an instance of the protocol stack - a communications endpoint.
     The <literal>type</literal> parameter determines the mode
     of communication. At present the following values are supported:
    </para>
    <variablelist>
     <varlistentry>
      <term><literal>tcpip_type</literal></term>
      <listitem><para>TCP/IP (BER over TCP/IP or HTTP over TCP/IP)
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>ssl_type</literal></term>
      <listitem><para>Secure Socket Layer (SSL). This COMSTACK
      is experimental and is not fully implemented. If
      HTTP is used, this effectively is HTTPS.
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term><literal>unix_type</literal></term>
      <listitem><para>Unix socket (unix only). Local Transfer via
      file socket. See <citerefentry><refentrytitle>unix</refentrytitle>
      <manvolnum>7</manvolnum></citerefentry>.
      </para></listitem>
     </varlistentry>
    </variablelist>
    <para>
     The <function>cs_create</function> function returns a null-pointer
     if a system error occurs.
     The <literal>blocking</literal> parameter should be '1' if
     you wish the association to operate in blocking mode, and '0' otherwise.
     The <literal>protocol</literal> field should be
     <literal>PROTO_Z3950</literal> or <literal>PROTO_HTTP</literal>.
     Protocol <literal>PROTO_SR</literal> is no longer supported.
    </para>
    <synopsis>
     void cs_close(COMSTACK handle);
    </synopsis>
    <para>
     Closes the connection (as elegantly as the lower layers will permit),
     and releases the resources pointed to by the
     <literal>handle</literal>
     parameter. The
     <literal>handle</literal>
     should not be referenced again after this call.
    </para>
    <note>
     <para>
      We really need a soft disconnect, don't we?
     </para>
    </note>
   </sect2>
   <sect2 id="comstack.data.exchange">
    <title>Data Exchange</title>
    <synopsis>
     int cs_put(COMSTACK handle, char *buf, int len);
    </synopsis>
    <para>
     Sends <literal>buf</literal> down the wire.
     In blocking mode, this function will return only when a full buffer has
     been written, or an error has occurred. In nonblocking mode, it's
     possible that the function will be unable to send the full buffer
     at once, which will be indicated by a return value of 1.
     The function will keep track of the number of octets already written; you
     should call it repeatedly with the same values of <literal>buf</literal>
     and <literal>len</literal>, until the buffer has been transmitted.
     When a full buffer has been sent, the function will return 0 for
     success. The return value -1 indicates an error condition (see below).
    </para>
    <synopsis>
     int cs_get(COMSTACK handle, char **buf, int *size);
    </synopsis>
    <para>
     Receives a PDU or HTTP Response from the peer. Returns the number of
     bytes read.
     In nonblocking mode, it is possible that not all of the packet can be
     read at once. In this case, the function returns 1. To simplify the
     interface, the function is
     responsible for managing the size of the buffer. It will be reallocated
     if necessary to contain large packages, and will sometimes be moved
     around internally by the subsystem when partial packages are read. Before
     calling
     <function>cs_get</function>
     for the first time, the buffer can be initialized to the null pointer,
     and the length should also be set to 0 (cs_get will perform a
     <function>malloc(2)</function>
     on the buffer for you). When a full buffer has been read, the size of
     the package is returned (which will always be greater than 1).
     The return value -1 indicates an error condition.
    </para>
    <para>
     See also the <function>cs_more()</function> function below.
    </para>
    <synopsis>
     int cs_more(COMSTACK handle);
    </synopsis>
    <para>
     The <function>cs_more()</function> function should be used in conjunction
     with <function>cs_get</function> and
     <function>select(2)</function>.
     The <function>cs_get()</function> function will sometimes
     (notably in the TCP/IP mode) read more than a single protocol package
     off the network. When this happens, the extra package is stored
     by the subsystem. After calling <function>cs_get()</function>, and before
     waiting for more input, You should always call
     <function>cs_more()</function>
     to check if there's a full protocol package already read. If
     <function>cs_more()</function>
     returns 1,
     <function>cs_get()</function>
     can be used to immediately fetch the new package. For the
     mOSI
     subsystem, the function should always return 0, but if you want your
     stuff to be protocol independent, you should use it.
    </para>
    <note>
     <para>
      The <function>cs_more()</function>
      function is required because the RFC1729-method
      does not provide a way of separating individual PDUs, short of
      partially decoding the BER. Some other implementations will carefully
      nibble at the packet by calling
      <function>read(2)</function>
      several times. This was felt to be too inefficient (or at least
      clumsy) - hence the call for this extra function.
     </para>
    </note>
    <synopsis>
     int cs_look(COMSTACK handle);
    </synopsis>
    <para>
     This function is useful when you're operating in nonblocking
     mode. Call it when
     <function>select(2)</function>
     tells you there's something happening on the line. It returns one of
     the following values:
    </para>
    <variablelist>
     <varlistentry>
      <term>CS_NONE</term>
      <listitem><para>
       No event is pending. The data found on the line was not a
       complete package.
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term>CS_CONNECT</term>
      <listitem><para>
       A response to your connect request has been received. Call
       <function>cs_rcvconnect</function>
       to process the event and to finalize the connection establishment.
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term>CS_DISCON</term>
      <listitem><para>
       The other side has closed the connection (or maybe sent a disconnect
       request - but do we care? Maybe later). Call
       <function>cs_close</function> to close your end of the association
       as well.
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term>CS_LISTEN</term>
      <listitem><para>
       A connect request has been received.
       Call <function>cs_listen</function> to process the event.
      </para></listitem>
     </varlistentry>
     <varlistentry>
      <term>CS_DATA</term>
      <listitem><para>
       There's data to be found on the line.
       Call <function>cs_get</function> to get it.
      </para></listitem>
     </varlistentry>
    </variablelist>
    <note>
     <para>
      You should be aware that even if
      <function>cs_look()</function>
      tells you that there's an event event pending, the corresponding
      function may still return and tell you there was nothing to be found.
      This means that only part of a package was available for reading. The
      same event will show up again, when more data has arrived.
     </para>
    </note>
    <synopsis>
     int cs_fileno(COMSTACK h);
    </synopsis>
    <para>
     returns the file descriptor of the association. Use this when
     file-level operations on the endpoint are required
     (<function>select(2)</function> operations, specifically).
    </para>
   </sect2>
  </sect1>
  <sect1 id="comstack.client">
   <title>Client Side</title>
   <synopsis>
    int cs_connect(COMSTACK handle, void *address);
   </synopsis>
   <para>
    Initiate a connection with the target at <literal>address</literal>
    (more on addresses below). The function will return 0 on success, and 1 if
    the operation does not complete immediately (this will only
    happen on a nonblocking endpoint). In this case, use
    <function>cs_rcvconnect</function> to complete the operation,
    when <function>select(2)</function> or <function>poll(2)</function>
    reports input pending on the association.
   </para>
   <synopsis>
    int cs_rcvconnect(COMSTACK handle);
   </synopsis>
   <para>
    Complete a connect operation initiated by <function>cs_connect()</function>.
    It will return 0 on success; 1 if the operation has not yet completed (in
    this case, call the function again later); -1 if an error has occurred.
   </para>
  </sect1>
  <sect1 id="comstack.server">
   <title>Server Side</title>
   <para>
    To establish a server under the <application>inetd</application>
    server, you can use
   </para>
   <synopsis>
    COMSTACK cs_createbysocket(int socket, CS_TYPE type, int blocking,
                               int protocol);
   </synopsis>
   <para>
    The <literal>socket</literal> parameter is an established socket (when
    your application is invoked from <application>inetd</application>, the
    socket will typically be 0.
    The following parameters are identical to the ones for
    <function>cs_create</function>.
   </para>
   <synopsis>
    int cs_bind(COMSTACK handle, void *address, int mode)
   </synopsis>
   <para>
    Binds a local address to the endpoint. Read about addresses below. The
    <literal>mode</literal> parameter should be either
    <literal>CS_CLIENT</literal> or <literal>CS_SERVER</literal>.
   </para>
   <synopsis>
    int cs_listen(COMSTACK handle, char *addr, int *addrlen);
   </synopsis>
   <para>
    Call this to process incoming events on an endpoint that has been
    bound in listening mode. It will return 0 to indicate that the connect
    request has been received, 1 to signal a partial reception, and -1 to
    indicate an error condition.
   </para>
   <synopsis>
    COMSTACK cs_accept(COMSTACK handle);
   </synopsis>
   <para>
    This finalizes the server-side association establishment, after
    cs_listen has completed successfully. It returns a new connection
    endpoint, which represents the new association. The application will
    typically wish to fork off a process to handle the association at this
    point, and continue listen for new connections on the old
    <literal>handle</literal>.
   </para>
   <para>
    You can use the call
   </para>
   <synopsis>
    const char *cs_addrstr(COMSTACK);
   </synopsis>
   <para>
    on an established connection to retrieve the host-name of the remote host.
   </para>
   <note>
    <para>
     You may need to use this function with some care if your
     name server service is slow or unreliable.
    </para>
   </note>
  </sect1>
  <sect1 id="comstack.addresses">
   <title>Addresses</title>
   <para>
    The low-level format of the addresses are different depending on the
    mode of communication you have chosen. A function is provided by each
    of the lower layers to map a user-friendly string-form address to the
    binary form required by the lower layers.
   </para>
   <synopsis>
    void *cs_straddr(COMSTACK handle, const char *str);
   </synopsis>
   <para>
    The format for TCP/IP and SSL addresses is:
   </para>
   <synopsis>
    &lt;host> [ ':' &lt;portnum> ]
   </synopsis>
   <para>
    The <literal>hostname</literal> can be either a domain name or an
    IP address. The port number, if omitted, defaults to 210.
   </para>
   <para>
    For TCP/IP and SSL, the special hostnames <literal>@</literal>,
    maps to <literal>IN6ADDR_ANY_INIT</literal> with
    IPV4 binding as well (bindv6only=0),
    The special hostname <literal>@4</literal> binds to
    <literal>INADDR_ANY</literal> (IPV4 only listener).
    The special hostname <literal>@6</literal> binds to
    <literal>IN6ADDR_ANY_INIT</literal> with bindv6only=1 (IPV6 only listener).
   </para>
   <para>
    For UNIX sockets, the format of an address is the socket filename.
   </para>
   <para>
    When a connection has been established, you can use
   </para>
   <synopsis>
    const char *cs_addrstr(COMSTACK h);
   </synopsis>
   <para>
    to retrieve the host name of the peer system. The function returns
    a pointer to a static area, which is overwritten on the next call
    to the function.
   </para>
   <para>
    A fairly recent addition to the &comstack; module is the utility
    function
   </para>
   <synopsis>
    COMSTACK cs_create_host (const char *str, int blocking, void **vp);
   </synopsis>
   <para>
    which is just a wrapper for <function>cs_create</function> and
    <function>cs_straddr</function>. The <parameter>str</parameter>
    is similar to that described for <function>cs_straddr</function>
    but with a prefix denoting the &comstack; type. Prefixes supported
    are <literal>tcp:</literal> and <literal>unix:</literal> and
    <literal>ssl:</literal> for TCP/IP and UNIX and SSL respectively.
    If no prefix is given, then TCP/IP is used.
    The <parameter>blocking</parameter> is passed to
    function <function>cs_create</function>. The third parameter
    <parameter>vp</parameter> is a pointer to &comstack; stack type
    specific values.
    Parameter <parameter>vp</parameter> is reserved for future use.
    Set it to <literal>NULL</literal>.
   </para>
  </sect1>
  <sect1 id="comstack.ssl">
   <title>SSL</title>
   <para>
    <synopsis>
     void *cs_get_ssl(COMSTACK cs);
    </synopsis>
    Returns the SSL handle, <literal>SSL *</literal> for comstack. If comstack
    is not of type SSL, then NULL is returned.
   </para>
   <para>
    <synopsis>
     int cs_set_ssl_ctx(COMSTACK cs, void *ctx);
    </synopsis>
    Sets SSL context for comstack. The parameter is expected to be of type
    <literal>SSL_CTX *</literal>. This function should be called just
    after comstack has been created (before connect, bind, etc).
    This function returns 1 for success; 0 for failure.
   </para>
   <para>
    <synopsis>
     int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname);
    </synopsis>
    Sets SSL certificate for comstack as a PEM file. This function
    returns 1 for success; 0 for failure.
   </para>
   <para>
    <synopsis>
     int cs_get_ssl_peer_certificate_x509(COMSTACK cs, char **buf, int *len);
    </synopsis>
    This function returns the peer certificate. If successful,
    <literal>*buf</literal> and <literal>*len</literal> holds
    X509 buffer and length respectively. Buffer should be freed
    with <literal>xfree</literal>. This function returns 1 for success;
    0 for failure.
   </para>
  </sect1>
  <sect1 id="comstack.diagnostics">
   <title>Diagnostics</title>
   <para>
    All functions return -1 if an error occurs. Typically, the functions
    will return 0 on success, but the data exchange functions
    (<function>cs_get</function>, <function>cs_put</function>,
    <function>cs_more</function>) follow special rules. Consult their
    descriptions.
   </para>
   <para>
    The error code for the COMSTACK can be retrieved using C macro
    <function>cs_errno</function> which will return one
    of the error codes <literal>CSYSERR</literal>,
    <literal>CSOUTSTATE</literal>,
    <literal>CSNODATA</literal>, ...
   </para>
   <synopsis>
    int cs_errno(COMSTACK handle);
   </synopsis>
   <para>
    You can the textual representation of the error code
    by using <function>cs_errmsg</function>, which
    works like <function>strerror(3)</function>.
   </para>
   <synopsis>
    const char *cs_errmsg(int n);
   </synopsis>
   <para>
    It is also possible to get straight to the textual representation
    without the error code, by using
    <function>cs_strerror</function>.
   </para>
   <synopsis>
    const char *cs_strerror(COMSTACK h);
   </synopsis>
  </sect1>
  <sect1 id="comstack.summary">
   <title>Summary and Synopsis</title>
   <synopsis><![CDATA[
    #include <yaz/comstack.h>

    #include <yaz/tcpip.h>  /* this is for TCP/IP and SSL support */
    #include <yaz/unix.h>   /* this is for UNIX socket support */

    COMSTACK cs_create(CS_TYPE type, int blocking, int protocol);

    COMSTACK cs_createbysocket(int s, CS_TYPE type, int blocking,
                               int protocol);
    COMSTACK cs_create_host(const char *str, int blocking,
                            void **vp);

    int cs_bind(COMSTACK handle, int mode);

    int cs_connect(COMSTACK handle, void *address);

    int cs_rcvconnect(COMSTACK handle);

    int cs_listen(COMSTACK handle);

    COMSTACK cs_accept(COMSTACK handle);

    int cs_put(COMSTACK handle, char *buf, int len);

    int cs_get(COMSTACK handle, char **buf, int *size);

    int cs_more(COMSTACK handle);

    void cs_close(COMSTACK handle);

    int cs_look(COMSTACK handle);

    void *cs_straddr(COMSTACK handle, const char *str);

    const char *cs_addrstr(COMSTACK h);
]]>
   </synopsis>
  </sect1>
 </chapter>
 <chapter id="future">
  <title>Future Directions</title>
  <para>
   We have a new and better version of the front-end server on the drawing
   board. Resources and external commitments will govern when we'll be
   able to do something real with it. Features should include greater
   flexibility, greater support for access/resource control, and easy
   support for Explain (possibly with Zebra as an extra database engine).
  </para>
  <para>
   &yaz; is a BER toolkit and as such should support all protocols
   out there based on that. We'd like to see running ILL applications.
   It shouldn't be that hard. Another thing that would be interesting is
   LDAP. Maybe a generic framework for doing IR using both LDAP and
   Z39.50 transparently.
  </para>
  <para>
   The SOAP implementation is incomplete. In the future we hope
   to add more features to it. Perhaps make a WSDL/XML Schema compiler.
   The authors of libxml2 are already working on XML Schema and RELAX NG
   compilers so this may not be too hard.
  </para>
  <para>
   It would be neat to have a proper module mechanism for the Generic
   Frontend Server so that backend would be dynamically
   loaded (as shared objects / DLLs).
  </para>
  <para>
   Other than that, &yaz; generally moves in the directions which appear to
   make the most people happy (including ourselves, as prime users of the
   software). If there's something you'd like to see in here, then drop
   us a note and let's see what we can come up with.
  </para>
 </chapter>
 <reference id="reference">
  <title>Reference</title>
   <partintro id="reference-introduction">
    <para>
     The material in this chapter is drawn directly from the individual
     manual entries.
    </para>
   </partintro>
   &manref;
 </reference>
 <appendix id="list-oids">
  <title>List of Object Identifiers</title>
  <para>
   These is a list of object identifiers that are built into YAZ.
  </para>
  &std-oid-table;
 </appendix>
 <appendix id="bib1-diagnostics">
  <title>Bib-1 diagnostics</title>
  <para>
   List of Bib-1 diagnostics that are known to YAZ.
  </para>
  &bib1-diag-table;
 </appendix>
 <appendix id="sru-diagnostics">
  <title>SRU diagnostics</title>
  <para>
   List of SRU diagnostics that are known to YAZ.
  </para>
  &srw-diag-table;
 </appendix>
 <appendix id="license">
  <title>License</title>
  <sect1 id="license.indexdata">
   <title>Index Data Copyright</title>
   <para>
    Copyright &#xa9; &copyright-year; Index Data.
   </para>
   <para>
    All rights reserved.
   </para>
   <para>
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
   </para>
   <itemizedlist>
    <listitem>
     <para>
      Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
     </para>
    </listitem>
    <listitem>
     <para>
      Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
     </para>
    </listitem>
    <listitem>
     <para>
      Neither the name of Index Data nor the names of its contributors
      may be used to endorse or promote products derived from this
      software without specific prior written permission.
      </para>
    </listitem>
   </itemizedlist>
   <para>
    THIS SOFTWARE IS PROVIDED BY INDEX DATA ``AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL INDEX DATA BE LIABLE FOR
    ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    SUCH DAMAGE.
   </para>
  </sect1>
 </appendix>
 <appendix id="indexdata">
  <title>About Index Data</title>
  <para>
   Index Data is a consulting and software-development enterprise that
   specializes in library and information management systems. Our
   interests and expertise span a broad range of related fields, and one
   of our primary, long-term objectives is the development of a powerful
   information management
   system with open network interfaces and hyper-media capabilities.
  </para><para>
   We make this software available free of charge, on a fairly unrestrictive
   license; as a service to the networking community, and to further the
   development of quality software for open network communication.
  </para><para>
   We'll be happy to answer questions about the software, and about ourselves
   in general.
  </para>
  <para>
   The Hacker's Jargon File has the following to say about the
   use of the
   prefix &quot;YA&quot; in the name of a software product.
  </para>
  <para>
   <citation>
    Yet Another. adj. 1. Of your own work: A
    humorous allusion often used in titles to acknowledge that the
    topic is not original, though the content is.  As in &quot;Yet Another
    AI Group&quot; or &quot;Yet Another Simulated Annealing Algorithm&quot;.
    2. Of
    others' work: Describes something of which there are already far
    too many.
   </citation>
  </para>
 </appendix>
 <appendix id="credits">
  <title>Credits</title>
  <para>
   This appendix lists individuals that have contributed in the development
   of &yaz;. Some have contributed with code, while others have provided bug
   fixes or suggestions. If we're missing somebody, of if you, for
   whatever reason, don't like to be listed here, let us know.
  </para>
  <itemizedlist>
   <listitem><para>
    Gary Anderson
   </para></listitem>
   <listitem><para>
    Dimitrios Andreadis
    </para></listitem>
   <listitem><para>
    Morten B&#xf8;geskov
   </para></listitem>
   <listitem><para>
    Rocco Carbone
   </para></listitem>
   <listitem><para>
    Matthew Carey
   </para></listitem>
   <listitem><para>
    Hans van Dalen
   </para></listitem>
   <listitem><para>
    Irina Dijour
   </para></listitem>
   <listitem><para>
    Larry E. Dixson
   </para></listitem>
   <listitem><para>
    Hans van den Dool
   </para></listitem>
   <listitem><para>
    Mads Bondo Dydensborg
   </para></listitem>
   <listitem><para>
    Franck Falcoz
   </para></listitem>
   <listitem><para>
    Kevin Gamiel
   </para></listitem>
   <listitem><para>
    Morten Garkier Hendriksen
   </para></listitem>
   <listitem><para>
    Morten Holmqvist
   </para></listitem>
   <listitem><para>
    Ian Ibbotson
   </para></listitem>
   <listitem><para>
    Shigeru Ishida
   </para></listitem>
   <listitem><para>
    Heiko Jansen
   </para></listitem>
   <listitem><para>
    David Johnson
   </para></listitem>
   <listitem><para>
    Oleg Kolobov
   </para></listitem>
   <listitem><para>
    Giannis Kosmas
   </para></listitem>
   <listitem><para>
    Kang-Jin Lee
   </para></listitem>
   <listitem><para>
    Pieter Van Lierop
   </para></listitem>
   <listitem><para>
    Stefan Lohrum
   </para></listitem>
   <listitem><para>
    Ronald van der Meer
   </para></listitem>
   <listitem><para>
    Thomas W. Place
   </para></listitem>
   <listitem><para>
    Peter Popovics
   </para></listitem>
   <listitem><para>
    Jacob Chr. Poulsen
   </para></listitem>
   <listitem><para>
    Ko van der Sloot
   </para></listitem>
   <listitem><para>
    Mike Taylor
   </para></listitem>
   <listitem><para>
    Rustam T. Usmanov
   </para></listitem>
   <listitem><para>
    Charles Woodfield
   </para></listitem>
   <listitem><para>
    Tom Andr&#xe9; &#xd8;verland
   </para></listitem>
   <listitem><para>
    Hugh McMaster
   </para></listitem>
   <listitem><para>
    Guillaume Jactat
   </para></listitem>
  </itemizedlist>
 </appendix>
</book>

<!-- Keep this comment at the end of the file
Local variables:
mode: nxml
nxml-child-indent: 1
End:
-->