2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1996-07-06 19:58:34 quinn
8 * System headerfiles gathered in yconfig
10 * Revision 1.5 1996/01/02 08:57:44 quinn
11 * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass
13 * Revision 1.4 1995/12/05 11:16:10 quinn
16 * Revision 1.3 1995/11/13 09:27:34 quinn
17 * Fiddling with the variant stuff.
19 * Revision 1.2 1995/11/01 16:34:56 quinn
20 * Making data1 look for tables in data1_tabpath
22 * Revision 1.1 1995/11/01 11:56:07 quinn
23 * Added Retrieval (data management) functions en masse.
41 static Z_Variant *read_variant(int argc, char **argv, ODR o)
43 Z_Variant *r = odr_malloc(o, sizeof(*r));
47 var1.proto = PROTO_Z3950;
48 var1.oclass = CLASS_VARSET;
49 var1.value = VAL_VAR1;
50 r->globalVariantSetId = odr_oiddup(o, oid_getoidbyent(&var1));
53 r->triples = odr_malloc(o, sizeof(Z_Triple*) * argc);
56 r->num_triples = argc;
57 for (i = 0; i < argc; i++)
63 if (sscanf(argv[i], "(%d,%d,%[^)])", &class, &type, value) < 3)
65 logf(LOG_WARN, "Syntax error in variant component '%s'",
69 t = r->triples[i] = odr_malloc(o, sizeof(Z_Triple));
71 t->class = odr_malloc(o, sizeof(int));
73 t->type = odr_malloc(o, sizeof(int));
76 * This is wrong.. we gotta look up the correct type for the
77 * variant, I guess... damn this stuff.
81 t->which = Z_Triple_null;
82 t->value.null = ODR_NULLVAL;
84 else if (isdigit(*value))
86 t->which = Z_Triple_integer;
87 t->value.integer = odr_malloc(o, sizeof(*t->value.integer));
88 *t->value.integer = atoi(value);
92 t->which = Z_Triple_internationalString;
93 t->value.internationalString = odr_malloc(o, strlen(value)+1);
94 strcpy(t->value.internationalString, value);
100 static Z_Occurrences *read_occurrences(char *occ, ODR o)
102 Z_Occurrences *op = odr_malloc(o, sizeof(*op));
107 op->which = Z_Occurrences_values;
108 op->u.values = odr_malloc(o, sizeof(Z_OccurValues));
109 op->u.values->start = odr_malloc(o, sizeof(int));
110 *op->u.values->start = 1;
111 op->u.values->howMany = 0;
113 else if (!strcmp(occ, "all"))
115 op->which = Z_Occurrences_all;
116 op->u.all = ODR_NULLVAL;
118 else if (!strcmp(occ, "last"))
120 op->which = Z_Occurrences_last;
121 op->u.all = ODR_NULLVAL;
125 Z_OccurValues *ov = odr_malloc(o, sizeof(*ov));
129 logf(LOG_WARN, "Bad occurrences-spec in %s", occ);
132 op->which = Z_Occurrences_values;
134 ov->start = odr_malloc(o, sizeof(*ov->start));
135 *ov->start = atoi(occ);
136 if ((p = strchr(occ, '+')))
138 ov->howMany = odr_malloc(o, sizeof(*ov->howMany));
139 *ov->howMany = atoi(p + 1);
148 static Z_ETagUnit *read_tagunit(char *buf, ODR o)
150 Z_ETagUnit *u = odr_malloc(o, sizeof(*u));
153 char value[512], occ[512];
157 u->which = Z_ETagUnit_wildPath;
158 u->u.wildPath = ODR_NULLVAL;
160 else if (*buf == '?')
162 u->which = Z_ETagUnit_wildThing;
164 u->u.wildThing = read_occurrences(buf+2, o);
166 u->u.wildThing = read_occurrences(0, o);
168 else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-z0-9+]", &type, value,
174 int force_string = 0;
181 u->which = Z_ETagUnit_specificTag;
182 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
183 t->tagType = odr_malloc(o, sizeof(*t->tagType));
185 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
186 if (!force_string && (numval = atoi(valp)))
188 t->tagValue->which = Z_StringOrNumeric_numeric;
189 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
190 *t->tagValue->u.numeric = numval;
194 t->tagValue->which = Z_StringOrNumeric_string;
195 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
196 strcpy(t->tagValue->u.string, valp);
198 if (terms > 2) /* an occurrences-spec exists */
199 t->occurrences = read_occurrences(occ, o);
207 * Read an element-set specification from a file.
208 * NOTE: If !o, memory is allocated directly from the heap by odr_malloc().
210 Z_Espec1 *data1_read_espec1(char *file, ODR o)
213 int argc, size_esn = 0;
214 char *argv[50], line[512];
215 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
217 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
219 logf(LOG_WARN|LOG_ERRNO, "%s", file);
223 res->num_elementSetNames = 0;
224 res->elementSetNames = 0;
225 res->defaultVariantSetId = 0;
226 res->defaultVariantRequest = 0;
227 res->defaultTagType = 0;
228 res->num_elements = 0;
231 while ((argc = readconf_line(f, line, 512, argv, 50)))
232 if (!strcmp(argv[0], "elementsetnames"))
234 int nnames = argc-1, i;
238 logf(LOG_WARN, "%s: Empty elementsetnames directive",
243 res->elementSetNames = odr_malloc(o, sizeof(char*)*nnames);
244 for (i = 0; i < nnames; i++)
246 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
247 strcpy(res->elementSetNames[i], argv[i+1]);
249 res->num_elementSetNames = nnames;
251 else if (!strcmp(argv[0], "defaultvariantsetid"))
253 if (argc != 2 || !(res->defaultVariantSetId =
254 odr_getoidbystr(o, argv[1])))
256 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
260 else if (!strcmp(argv[0], "defaulttagtype"))
264 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
267 res->defaultTagType = odr_malloc(o, sizeof(int));
268 *res->defaultTagType = atoi(argv[1]);
270 else if (!strcmp(argv[0], "defaultvariantrequest"))
272 if (!(res->defaultVariantRequest = read_variant(argc-1, argv+1, o)))
274 logf(LOG_WARN, "%s: Bad defaultvariantrequest", file);
278 else if (!strcmp(argv[0], "simpleelement"))
280 Z_ElementRequest *er;
283 char *path = argv[1];
288 res->elements = odr_malloc(o, size_esn = 24*sizeof(*er));
289 else if (res->num_elements >= size_esn)
292 res->elements = o ? odr_malloc(o, size_esn) :
293 xrealloc(res->elements, size_esn);
297 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
301 res->elements[res->num_elements++] = er =
302 odr_malloc(o, sizeof(*er));
303 er->which = Z_ERequest_simpleElement;
304 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
305 se->variantRequest = 0;
306 se->path = tp = odr_malloc(o, sizeof(*tp));
309 * Parse the element selector.
311 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++);
312 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
314 for ((ep = strchr(path, '/')) ; path ; (void)((path = ep) &&
315 (ep = strchr(path, '/'))))
321 tp->tags[tp->num_tags++] = read_tagunit(path, o);
324 if (argc > 2 && !strcmp(argv[2], "variant"))
325 se->variantRequest= read_variant(argc-3, argv+3, o);
329 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);