2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1997-05-14 06:54:02 adam
10 * Revision 1.6 1996/07/06 19:58:34 quinn
11 * System headerfiles gathered in yconfig
13 * Revision 1.5 1996/01/02 08:57:44 quinn
14 * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass
16 * Revision 1.4 1995/12/05 11:16:10 quinn
19 * Revision 1.3 1995/11/13 09:27:34 quinn
20 * Fiddling with the variant stuff.
22 * Revision 1.2 1995/11/01 16:34:56 quinn
23 * Making data1 look for tables in data1_tabpath
25 * Revision 1.1 1995/11/01 11:56:07 quinn
26 * Added Retrieval (data management) functions en masse.
44 static Z_Variant *read_variant(int argc, char **argv, ODR o)
46 Z_Variant *r = odr_malloc(o, sizeof(*r));
50 var1.proto = PROTO_Z3950;
51 var1.oclass = CLASS_VARSET;
52 var1.value = VAL_VAR1;
53 r->globalVariantSetId = odr_oiddup(o, oid_getoidbyent(&var1));
56 r->triples = odr_malloc(o, sizeof(Z_Triple*) * argc);
59 r->num_triples = argc;
60 for (i = 0; i < argc; i++)
66 if (sscanf(argv[i], "(%d,%d,%[^)])", &zclass, &type, value) < 3)
68 logf(LOG_WARN, "Syntax error in variant component '%s'",
72 t = r->triples[i] = odr_malloc(o, sizeof(Z_Triple));
74 t->zclass = odr_malloc(o, sizeof(int));
76 t->type = odr_malloc(o, sizeof(int));
79 * This is wrong.. we gotta look up the correct type for the
80 * variant, I guess... damn this stuff.
84 t->which = Z_Triple_null;
85 t->value.null = ODR_NULLVAL;
87 else if (isdigit(*value))
89 t->which = Z_Triple_integer;
90 t->value.integer = odr_malloc(o, sizeof(*t->value.integer));
91 *t->value.integer = atoi(value);
95 t->which = Z_Triple_internationalString;
96 t->value.internationalString = odr_malloc(o, strlen(value)+1);
97 strcpy(t->value.internationalString, value);
103 static Z_Occurrences *read_occurrences(char *occ, ODR o)
105 Z_Occurrences *op = odr_malloc(o, sizeof(*op));
110 op->which = Z_Occurrences_values;
111 op->u.values = odr_malloc(o, sizeof(Z_OccurValues));
112 op->u.values->start = odr_malloc(o, sizeof(int));
113 *op->u.values->start = 1;
114 op->u.values->howMany = 0;
116 else if (!strcmp(occ, "all"))
118 op->which = Z_Occurrences_all;
119 op->u.all = ODR_NULLVAL;
121 else if (!strcmp(occ, "last"))
123 op->which = Z_Occurrences_last;
124 op->u.all = ODR_NULLVAL;
128 Z_OccurValues *ov = odr_malloc(o, sizeof(*ov));
132 logf(LOG_WARN, "Bad occurrences-spec in %s", occ);
135 op->which = Z_Occurrences_values;
137 ov->start = odr_malloc(o, sizeof(*ov->start));
138 *ov->start = atoi(occ);
139 if ((p = strchr(occ, '+')))
141 ov->howMany = odr_malloc(o, sizeof(*ov->howMany));
142 *ov->howMany = atoi(p + 1);
151 static Z_ETagUnit *read_tagunit(char *buf, ODR o)
153 Z_ETagUnit *u = odr_malloc(o, sizeof(*u));
156 char value[512], occ[512];
160 u->which = Z_ETagUnit_wildPath;
161 u->u.wildPath = ODR_NULLVAL;
163 else if (*buf == '?')
165 u->which = Z_ETagUnit_wildThing;
167 u->u.wildThing = read_occurrences(buf+2, o);
169 u->u.wildThing = read_occurrences(0, o);
171 else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-z0-9+]", &type, value,
177 int force_string = 0;
184 u->which = Z_ETagUnit_specificTag;
185 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
186 t->tagType = odr_malloc(o, sizeof(*t->tagType));
188 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
189 if (!force_string && (numval = atoi(valp)))
191 t->tagValue->which = Z_StringOrNumeric_numeric;
192 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
193 *t->tagValue->u.numeric = numval;
197 t->tagValue->which = Z_StringOrNumeric_string;
198 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
199 strcpy(t->tagValue->u.string, valp);
201 if (terms > 2) /* an occurrences-spec exists */
202 t->occurrences = read_occurrences(occ, o);
210 * Read an element-set specification from a file.
211 * NOTE: If !o, memory is allocated directly from the heap by odr_malloc().
213 Z_Espec1 *data1_read_espec1(char *file, ODR o)
216 int argc, size_esn = 0;
217 char *argv[50], line[512];
218 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
220 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
222 logf(LOG_WARN|LOG_ERRNO, "%s", file);
226 res->num_elementSetNames = 0;
227 res->elementSetNames = 0;
228 res->defaultVariantSetId = 0;
229 res->defaultVariantRequest = 0;
230 res->defaultTagType = 0;
231 res->num_elements = 0;
234 while ((argc = readconf_line(f, line, 512, argv, 50)))
235 if (!strcmp(argv[0], "elementsetnames"))
237 int nnames = argc-1, i;
241 logf(LOG_WARN, "%s: Empty elementsetnames directive",
246 res->elementSetNames = odr_malloc(o, sizeof(char*)*nnames);
247 for (i = 0; i < nnames; i++)
249 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
250 strcpy(res->elementSetNames[i], argv[i+1]);
252 res->num_elementSetNames = nnames;
254 else if (!strcmp(argv[0], "defaultvariantsetid"))
256 if (argc != 2 || !(res->defaultVariantSetId =
257 odr_getoidbystr(o, argv[1])))
259 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
263 else if (!strcmp(argv[0], "defaulttagtype"))
267 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
270 res->defaultTagType = odr_malloc(o, sizeof(int));
271 *res->defaultTagType = atoi(argv[1]);
273 else if (!strcmp(argv[0], "defaultvariantrequest"))
275 if (!(res->defaultVariantRequest = read_variant(argc-1, argv+1, o)))
277 logf(LOG_WARN, "%s: Bad defaultvariantrequest", file);
281 else if (!strcmp(argv[0], "simpleelement"))
283 Z_ElementRequest *er;
286 char *path = argv[1];
291 res->elements = odr_malloc(o, size_esn = 24*sizeof(*er));
292 else if (res->num_elements >= size_esn)
295 res->elements = o ? odr_malloc(o, size_esn) :
296 xrealloc(res->elements, size_esn);
300 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
304 res->elements[res->num_elements++] = er =
305 odr_malloc(o, sizeof(*er));
306 er->which = Z_ERequest_simpleElement;
307 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
308 se->variantRequest = 0;
309 se->path = tp = odr_malloc(o, sizeof(*tp));
312 * Parse the element selector.
314 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++);
315 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
317 for ((ep = strchr(path, '/')) ; path ; (void)((path = ep) &&
318 (ep = strchr(path, '/'))))
324 tp->tags[tp->num_tags++] = read_tagunit(path, o);
327 if (argc > 2 && !strcmp(argv[2], "variant"))
328 se->variantRequest= read_variant(argc-3, argv+3, o);
332 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);