2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1996-01-02 08:57:44 quinn
8 * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass
10 * Revision 1.4 1995/12/05 11:16:10 quinn
13 * Revision 1.3 1995/11/13 09:27:34 quinn
14 * Fiddling with the variant stuff.
16 * Revision 1.2 1995/11/01 16:34:56 quinn
17 * Making data1 look for tables in data1_tabpath
19 * Revision 1.1 1995/11/01 11:56:07 quinn
20 * Added Retrieval (data management) functions en masse.
38 static Z_Variant *read_variant(int argc, char **argv, ODR o)
40 Z_Variant *r = odr_malloc(o, sizeof(*r));
44 var1.proto = PROTO_Z3950;
45 var1.oclass = CLASS_VARSET;
46 var1.value = VAL_VAR1;
47 r->globalVariantSetId = odr_oiddup(o, oid_getoidbyent(&var1));
50 r->triples = odr_malloc(o, sizeof(Z_Triple*) * argc);
53 r->num_triples = argc;
54 for (i = 0; i < argc; i++)
60 if (sscanf(argv[i], "(%d,%d,%[^)])", &class, &type, value) < 3)
62 logf(LOG_WARN, "Syntax error in variant component '%s'",
66 t = r->triples[i] = odr_malloc(o, sizeof(Z_Triple));
68 t->class = odr_malloc(o, sizeof(int));
70 t->type = odr_malloc(o, sizeof(int));
73 * This is wrong.. we gotta look up the correct type for the
74 * variant, I guess... damn this stuff.
78 t->which = Z_Triple_null;
79 t->value.null = ODR_NULLVAL;
83 t->which = Z_Triple_internationalString;
84 t->value.internationalString = odr_malloc(o, strlen(value)+1);
85 strcpy(t->value.internationalString, value);
91 static Z_Occurrences *read_occurrences(char *occ, ODR o)
93 Z_Occurrences *op = odr_malloc(o, sizeof(*op));
98 op->which = Z_Occurrences_values;
99 op->u.values = odr_malloc(o, sizeof(Z_OccurValues));
100 op->u.values->start = odr_malloc(o, sizeof(int));
101 *op->u.values->start = 1;
102 op->u.values->howMany = 0;
104 else if (!strcmp(occ, "all"))
106 op->which = Z_Occurrences_all;
107 op->u.all = ODR_NULLVAL;
109 else if (!strcmp(occ, "last"))
111 op->which = Z_Occurrences_last;
112 op->u.all = ODR_NULLVAL;
116 Z_OccurValues *ov = odr_malloc(o, sizeof(*ov));
120 logf(LOG_WARN, "Bad occurrences-spec in %s", occ);
123 op->which = Z_Occurrences_values;
125 ov->start = odr_malloc(o, sizeof(*ov->start));
126 *ov->start = atoi(occ);
127 if ((p = strchr(occ, '+')))
129 ov->howMany = odr_malloc(o, sizeof(*ov->howMany));
130 *ov->howMany = atoi(p + 1);
139 static Z_ETagUnit *read_tagunit(char *buf, ODR o)
141 Z_ETagUnit *u = odr_malloc(o, sizeof(*u));
144 char value[512], occ[512];
148 u->which = Z_ETagUnit_wildPath;
149 u->u.wildPath = ODR_NULLVAL;
151 else if (*buf == '?')
153 u->which = Z_ETagUnit_wildThing;
155 u->u.wildThing = read_occurrences(buf+2, o);
157 u->u.wildThing = read_occurrences(0, o);
159 else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-z0-9+]", &type, value,
165 int force_string = 0;
172 u->which = Z_ETagUnit_specificTag;
173 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
174 t->tagType = odr_malloc(o, sizeof(*t->tagType));
176 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
177 if (!force_string && (numval = atoi(valp)))
179 t->tagValue->which = Z_StringOrNumeric_numeric;
180 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
181 *t->tagValue->u.numeric = numval;
185 t->tagValue->which = Z_StringOrNumeric_string;
186 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
187 strcpy(t->tagValue->u.string, valp);
189 if (terms > 2) /* an occurrences-spec exists */
190 t->occurrences = read_occurrences(occ, o);
198 * Read an element-set specification from a file.
199 * NOTE: If !o, memory is allocated directly from the heap by odr_malloc().
201 Z_Espec1 *data1_read_espec1(char *file, ODR o)
204 int argc, size_esn = 0;
205 char *argv[50], line[512];
206 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
208 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
210 logf(LOG_WARN|LOG_ERRNO, "%s", file);
214 res->num_elementSetNames = 0;
215 res->elementSetNames = 0;
216 res->defaultVariantSetId = 0;
217 res->defaultVariantRequest = 0;
218 res->defaultTagType = 0;
219 res->num_elements = 0;
222 while ((argc = readconf_line(f, line, 512, argv, 50)))
223 if (!strcmp(argv[0], "elementsetnames"))
225 int nnames = argc-1, i;
229 logf(LOG_WARN, "%s: Empty elementsetnames directive",
234 res->elementSetNames = odr_malloc(o, sizeof(char*)*nnames);
235 for (i = 0; i < nnames; i++)
237 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
238 strcpy(res->elementSetNames[i], argv[i+1]);
240 res->num_elementSetNames = nnames;
242 else if (!strcmp(argv[0], "defaultvariantsetid"))
244 if (argc != 2 || !(res->defaultVariantSetId =
245 odr_getoidbystr(o, argv[1])))
247 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
251 else if (!strcmp(argv[0], "defaulttagtype"))
255 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
258 res->defaultTagType = odr_malloc(o, sizeof(int));
259 *res->defaultTagType = atoi(argv[1]);
261 else if (!strcmp(argv[0], "defaultvariantrequest"))
263 if (!(res->defaultVariantRequest = read_variant(argc-1, argv+1, o)))
265 logf(LOG_WARN, "%s: Bad defaultvariantrequest", file);
269 else if (!strcmp(argv[0], "simpleelement"))
271 Z_ElementRequest *er;
274 char *path = argv[1];
279 res->elements = odr_malloc(o, size_esn = 24*sizeof(*er));
280 else if (res->num_elements >= size_esn)
283 res->elements = o ? odr_malloc(o, size_esn) :
284 xrealloc(res->elements, size_esn);
288 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
292 res->elements[res->num_elements++] = er =
293 odr_malloc(o, sizeof(*er));
294 er->which = Z_ERequest_simpleElement;
295 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
296 se->variantRequest = 0;
297 se->path = tp = odr_malloc(o, sizeof(*tp));
300 * Parse the element selector.
302 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++);
303 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
305 for ((ep = strchr(path, '/')) ; path ; (void)((path = ep) &&
306 (ep = strchr(path, '/'))))
312 tp->tags[tp->num_tags++] = read_tagunit(path, o);
315 if (argc > 2 && !strcmp(argv[2], "variant"))
316 se->variantRequest= read_variant(argc-3, argv+3, o);
320 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);