Make ZOOM C recognize option password
[yaz-moved-to-github.git] / src / initopt.c
1 /*
2  * Copyright (c) 1995-2004, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: initopt.c,v 1.2 2004-01-15 10:16:27 adam Exp $
6  */
7
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <yaz/proto.h>
13
14 static struct {
15     char *name;
16     int opt;
17 } opt_array[] = {
18     {"search", Z_Options_search},
19     {"present", Z_Options_present},
20     {"delSet", Z_Options_delSet},
21     {"resourceReport", Z_Options_resourceReport},
22     {"triggerResourceCtrl", Z_Options_triggerResourceCtrl},
23     {"resourceCtrl", Z_Options_resourceCtrl},
24     {"accessCtrl", Z_Options_accessCtrl},
25     {"scan", Z_Options_scan},
26     {"sort", Z_Options_sort},
27     {"extendedServices", Z_Options_extendedServices},
28     {"level_1Segmentation", Z_Options_level_1Segmentation},
29     {"level_2Segmentation", Z_Options_level_2Segmentation},
30     {"concurrentOperations", Z_Options_concurrentOperations},
31     {"namedResultSets", Z_Options_namedResultSets},
32     {"encapsulation", Z_Options_encapsulation},
33     {"resultCount", Z_Options_resultCount},
34     {"negotiationModel", Z_Options_negotiationModel},
35     {"duplicationDetection", Z_Options_duplicateDetection},
36     {"queryType104", Z_Options_queryType104},
37     {"pQESCorrection", Z_Options_pQESCorrection},
38     {"stringSchema", Z_Options_stringSchema},
39     {0, 0}
40 };
41
42 int yaz_init_opt_encode(Z_Options *opt, const char *opt_str, int *error_pos)
43 {
44     const char *cp = opt_str;
45     
46     ODR_MASK_ZERO(opt);
47     while (*cp)
48     {
49         char this_opt[20];
50         int i, j;
51         if (*cp == ' ' || *cp == ',')
52         {
53             cp++;
54             continue;
55         }
56         for (i = 0; i < (sizeof(this_opt)-1) &&
57                  cp[i] && cp[i] != ' ' && cp[i] != ','; i++)
58             this_opt[i] = cp[i];
59         this_opt[i] = 0;
60         for (j = 0; opt_array[j].name; j++)
61         {
62             if (yaz_matchstr(this_opt, opt_array[j].name) == 0)
63             {
64                 ODR_MASK_SET(opt, opt_array[j].opt);
65                 break;
66             }
67         }
68         if (!opt_array[j].name)
69         {
70             if (error_pos)
71             {
72                 *error_pos = cp - opt_str;
73                 return -1;
74             }
75         }
76         cp += i;
77     }
78     return 0;
79 }
80
81 void yaz_init_opt_decode(Z_Options *opt, void (*pr)(const char *name,
82                                                     void *clientData),
83                          void *clientData)
84 {
85     int i;
86     for (i = 0; opt_array[i].name; i++)
87         if (ODR_MASK_GET(opt, opt_array[i].opt))
88             (*pr)(opt_array[i].name, clientData);
89 }