Move xml_add utilities to xml_add.c source
[yaz-moved-to-github.git] / src / initopt.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2013 Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file initopt.c
8  * \brief Implements Z39.50 Init Options Utility
9  */
10
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include <yaz/proto.h>
16
17 static struct {
18     char *name;
19     int opt;
20 } opt_array[] = {
21     {"search", Z_Options_search},
22     {"present", Z_Options_present},
23     {"delSet", Z_Options_delSet},
24     {"resourceReport", Z_Options_resourceReport},
25     {"triggerResourceCtrl", Z_Options_triggerResourceCtrl},
26     {"resourceCtrl", Z_Options_resourceCtrl},
27     {"accessCtrl", Z_Options_accessCtrl},
28     {"scan", Z_Options_scan},
29     {"sort", Z_Options_sort},
30     {"extendedServices", Z_Options_extendedServices},
31     {"level_1Segmentation", Z_Options_level_1Segmentation},
32     {"level_2Segmentation", Z_Options_level_2Segmentation},
33     {"concurrentOperations", Z_Options_concurrentOperations},
34     {"namedResultSets", Z_Options_namedResultSets},
35     {"encapsulation", Z_Options_encapsulation},
36     {"resultCount", Z_Options_resultCount},
37     {"negotiationModel", Z_Options_negotiationModel},
38     {"duplicationDetection", Z_Options_duplicateDetection},
39     {"queryType104", Z_Options_queryType104},
40     {"pQESCorrection", Z_Options_pQESCorrection},
41     {"stringSchema", Z_Options_stringSchema},
42     {0, 0}
43 };
44
45 int yaz_init_opt_encode(Z_Options *opt, const char *opt_str, int *error_pos)
46 {
47     const char *cp = opt_str;
48
49     ODR_MASK_ZERO(opt);
50     while (*cp)
51     {
52         char this_opt[42];
53         size_t i, j;
54         if (*cp == ' ' || *cp == ',')
55         {
56             cp++;
57             continue;
58         }
59         for (i = 0; i < (sizeof(this_opt)-1) &&
60                  cp[i] && cp[i] != ' ' && cp[i] != ','; i++)
61             this_opt[i] = cp[i];
62         this_opt[i] = 0;
63         for (j = 0; opt_array[j].name; j++)
64         {
65             if (yaz_matchstr(this_opt, opt_array[j].name) == 0)
66             {
67                 ODR_MASK_SET(opt, opt_array[j].opt);
68                 break;
69             }
70         }
71         if (!opt_array[j].name)
72         {
73             if (error_pos)
74             {
75                 *error_pos = cp - opt_str;
76                 return -1;
77             }
78         }
79         cp += i;
80     }
81     return 0;
82 }
83
84 void yaz_init_opt_decode(Z_Options *opt, void (*pr)(const char *name,
85                                                     void *clientData),
86                          void *clientData)
87 {
88     int i;
89     for (i = 0; opt_array[i].name; i++)
90         if (ODR_MASK_GET(opt, opt_array[i].opt))
91             (*pr)(opt_array[i].name, clientData);
92 }
93 /*
94  * Local variables:
95  * c-basic-offset: 4
96  * c-file-style: "Stroustrup"
97  * indent-tabs-mode: nil
98  * End:
99  * vim: shiftwidth=4 tabstop=8 expandtab
100  */
101