2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_expout.c,v $
7 * Revision 1.6 1997-11-24 11:33:56 adam
8 * Using function odr_nullval() instead of global ODR_NULLVAL when
11 * Revision 1.5 1997/11/19 10:30:06 adam
14 * Revision 1.4 1997/11/18 09:51:08 adam
15 * Removed element num_children from data1_node. Minor changes in
18 * Revision 1.3 1997/09/17 12:10:36 adam
21 * Revision 1.2 1995/12/14 16:28:30 quinn
24 * Revision 1.1 1995/12/14 11:09:51 quinn
44 static int is_numeric_tag (ExpHandle *eh, data1_node *c)
46 if (!c || c->which != DATA1N_tag)
48 if (!c->u.tag.element)
50 logf(LOG_WARN, "Tag %s is local", c->u.tag.tag);
53 if (c->u.tag.element->tag->which != DATA1T_numeric)
55 logf(LOG_WARN, "Tag %s is not numeric", c->u.tag.tag);
58 if (eh->select && !c->u.tag.node_selected)
63 static int is_data_tag (ExpHandle *eh, data1_node *c)
65 if (!c || c->which != DATA1N_data)
67 if (select && !c->u.tag.node_selected)
72 static int *f_integer(ExpHandle *eh, data1_node *c)
78 if (!is_data_tag (eh, c) || c->u.data.len > 63)
80 r = odr_malloc(eh->o, sizeof(*r));
81 sprintf(intbuf, "%.*s", 63, c->u.data.data);
86 static char *f_string(ExpHandle *eh, data1_node *c)
91 if (!is_data_tag (eh, c))
93 r = odr_malloc(eh->o, c->u.data.len+1);
94 memcpy(r, c->u.data.data, c->u.data.len);
95 r[c->u.data.len] = '\0';
99 static bool_t *f_bool(ExpHandle *eh, data1_node *c)
105 if (!is_data_tag (eh, c) || c->u.data.len > 63)
107 tf = odr_malloc (eh->o, sizeof(*tf));
108 sprintf(intbuf, "%.*s", 63, c->u.data.data);
113 static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c)
119 static Z_HumanString *f_humstring(ExpHandle *eh, data1_node *c)
122 Z_HumanStringUnit *u;
125 if (!is_data_tag (eh, c))
127 r = odr_malloc(eh->o, sizeof(*r));
129 r->strings = odr_malloc(eh->o, sizeof(Z_HumanStringUnit*));
130 r->strings[0] = u = odr_malloc(eh->o, sizeof(*u));
132 u->text = odr_malloc(eh->o, c->u.data.len+1);
133 memcpy(u->text, c->u.data.data, c->u.data.len);
134 u->text[c->u.data.len] = '\0';
138 static Z_CommonInfo *f_commonInfo(ExpHandle *eh, data1_node *n)
140 Z_CommonInfo *res = odr_malloc(eh->o, sizeof(*res));
144 res->dateChanged = 0;
146 res->humanStringLanguage = 0;
149 for (c = n->child; c; c = c->next)
151 if (!is_numeric_tag (eh, c))
153 switch (c->u.tag.element->tag->value.numeric)
155 case 601: res->dateAdded = f_string(eh, c); break;
156 case 602: res->dateChanged = f_string(eh, c); break;
157 case 603: res->expiry = f_string(eh, c); break;
158 case 604: res->humanStringLanguage = f_string(eh, c); break;
161 logf(LOG_WARN, "Bad child in commonInfo");
168 Z_QueryTypeDetails *f_queryTypeDetails (ExpHandle *eh, data1_node *n)
174 Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num)
180 char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
187 for (c = n->child ; c; c = c->next)
189 if (!is_numeric_tag (eh, c))
191 if (n->u.tag.element->tag->value.numeric != 1001)
196 res = odr_malloc (eh->o, sizeof(*res) * (*num));
197 for (c = n->child, i = 0 ; i < *num; c = c->next, i++)
198 res[i] = f_string (eh, c);
202 char **f_humstring_seq (ExpHandle *eh, data1_node *n, int *num)
208 static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n)
210 Z_AccessInfo *res = odr_malloc(eh->o, sizeof(*res));
213 res->num_queryTypesSupported = 0;
214 res->queryTypesSupported = 0;
215 res->num_diagnosticsSets = 0;
216 res->diagnosticsSets = 0;
217 res->num_attributeSetIds = 0;
218 res->attributeSetIds = 0;
219 res->num_schemas = 0;
221 res->num_recordSyntaxes = 0;
222 res->recordSyntaxes = 0;
223 res->num_resourceChallenges = 0;
224 res->resourceChallenges = 0;
225 res->restrictedAccess = 0;
227 res->num_variantSets = 0;
228 res->variantSets = 0;
229 res->num_elementSetNames = 0;
230 res->elementSetNames = 0;
231 res->num_unitSystems = 0;
232 res->unitSystems = 0;
234 for (c = n->child; c; c = c->next)
237 if (!is_numeric_tag (eh, c))
239 switch (c->u.tag.element->tag->value.numeric)
242 res->num_queryTypesSupported = 0;
243 for (n = c->child; n; n = n->next)
245 if (!is_numeric_tag(eh, n))
247 (res->num_queryTypesSupported)++;
249 if (res->num_queryTypesSupported)
250 res->queryTypesSupported =
251 odr_malloc (eh->o, res->num_queryTypesSupported
252 * sizeof(*res->queryTypesSupported));
254 for (n = c->child; i < res->num_queryTypesSupported; n = n->next)
255 res->queryTypesSupported[i++] = f_queryTypeDetails (eh, n);
258 res->diagnosticsSets = f_oid_seq(eh, c, &res->num_diagnosticsSets);
261 res->attributeSetIds = f_oid_seq(eh, c, &res->num_attributeSetIds);
264 res->schemas = f_oid_seq(eh, c, &res->num_schemas);
267 res->recordSyntaxes = f_oid_seq (eh, c, &res->num_recordSyntaxes);
270 res->resourceChallenges = f_oid_seq (eh, c,
271 &res->num_resourceChallenges);
273 case 513: res->restrictedAccess = NULL; break; /* fix */
274 case 514: res->costInfo = NULL; break; /* fix */
276 res->variantSets = f_oid_seq (eh, c,
277 &res->num_variantSets);
280 res->elementSetNames =
281 f_string_seq (eh, c, &res->num_elementSetNames);
284 res->unitSystems = f_string_seq (eh, c, &res->num_unitSystems);
287 logf(LOG_WARN, "Bad child in accessInfo");
294 static int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
296 int *r= odr_malloc(eh->o, sizeof(*r));
301 if (!is_numeric_tag (eh, c))
303 if (c->u.tag.element->tag->value.numeric == 210)
304 *wp = Z_Exp_RecordCount_actualNumber;
305 else if (c->u.tag.element->tag->value.numeric == 211)
306 *wp = Z_Exp_RecordCount_approxNumber;
309 if (!c->child || c->child->which != DATA1N_data)
311 sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
316 static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
322 static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n)
325 Z_DatabaseList *res = odr_malloc (eh->o, sizeof(*res));
328 res->num_databases = 0;
329 res->databases = NULL;
330 for (c = n->child ; c; c = c->next)
332 if (!is_numeric_tag (eh, c))
334 if (n->u.tag.element->tag->value.numeric != 102)
336 ++(res->num_databases);
338 if (res->num_databases)
340 odr_malloc (eh->o, sizeof(*res->databases)*res->num_databases);
341 for (c = n->child, i = 0 ; i < res->num_databases; c = c->next, i++)
342 res->databases[i] = f_string (eh, c);
346 static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n)
348 Z_TargetInfo *res = odr_malloc(eh->o, sizeof(*res));
350 bool_t *fl = odr_malloc(eh->o,sizeof(*fl));
358 res->namedResultSets = 0;
359 res->multipleDbSearch = 0;
360 res->maxResultSets = 0;
361 res->maxResultSize = 0;
363 res->timeoutInterval = 0;
364 res->welcomeMessage = 0;
365 res->contactInfo = 0;
366 res->description = 0;
367 res->num_nicknames = 0;
370 res->paymentAddr = 0;
372 res->num_dbCombinations = 0;
373 res->dbCombinations = 0;
374 res->num_addresses = 0;
376 res->commonAccessInfo = 0;
378 for (c = n->child; c; c = c->next)
380 if (!is_numeric_tag (eh, c))
382 switch (c->u.tag.element->tag->value.numeric)
384 case 600: res->commonInfo = f_commonInfo(eh, c); break;
385 case 102: res->name = f_string(eh, c); break;
386 case 103: res->recentNews = f_humstring(eh, c); break;
387 case 104: res->icon = NULL; break; /* fix */
388 case 105: res->namedResultSets = f_bool(eh, c); break;
389 case 106: res->multipleDbSearch = f_bool(eh, c); break;
390 case 107: res->maxResultSets = f_integer(eh, c); break;
391 case 108: res->maxResultSize = f_integer(eh, c); break;
392 case 109: res->maxTerms = f_integer(eh, c); break;
393 case 110: res->timeoutInterval = f_intunit(eh, c); break;
394 case 111: res->welcomeMessage = f_humstring(eh, c); break;
395 case 112: res->contactInfo = f_contactInfo(eh, c); break;
396 case 113: res->description = f_humstring(eh, c); break;
398 res->num_nicknames = 0;
399 for (n = c->child; n; n = n->next)
401 if (!is_numeric_tag(eh, n))
403 if (n->u.tag.element->tag->value.numeric != 102)
405 (res->num_nicknames)++;
407 if (res->num_nicknames)
409 odr_malloc (eh->o, res->num_nicknames
410 * sizeof(*res->nicknames));
412 for (n = c->child; i < res->num_nicknames; n = n->next)
413 res->nicknames[i++] = f_string (eh, n);
415 case 115: res->usageRest = f_humstring(eh, c); break;
416 case 116: res->paymentAddr = f_humstring(eh, c); break;
417 case 117: res->hours = f_humstring(eh, c); break;
419 res->num_dbCombinations = 0;
420 for (n = c->child; n; n = n->next)
422 if (!is_numeric_tag(eh, n))
424 if (n->u.tag.element->tag->value.numeric != 605)
426 (res->num_dbCombinations)++;
428 if (res->num_dbCombinations)
429 res->dbCombinations =
430 odr_malloc (eh->o, res->num_dbCombinations
431 * sizeof(*res->dbCombinations));
433 for (n = c->child; i < res->num_dbCombinations; n = n->next)
434 res->dbCombinations[i++] = f_databaseList (eh, n);
436 case 119: break; /* addresses */
437 case 500: res->commonAccessInfo = f_accessInfo(eh, c); break;
439 logf(LOG_WARN, "Unknown target-info element");
442 if (!res->namedResultSets)
443 res->namedResultSets = fl;
444 if (!res->multipleDbSearch)
445 res->multipleDbSearch = fl;
449 static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n)
451 Z_DatabaseInfo *res = odr_malloc(eh->o, sizeof(*res));
453 bool_t *fl = odr_malloc(eh->o,sizeof(*fl));
454 bool_t *tr = odr_malloc(eh->o,sizeof(*tr));
461 res->explainDatabase = 0;
462 res->num_nicknames = 0;
467 res->titleString = 0;
468 res->num_keywords = 0;
470 res->description = 0;
471 res->associatedDbs = 0;
473 res->disclaimers = 0;
475 res->recordCount = 0;
476 res->defaultOrder = 0;
477 res->avRecordSize = 0;
478 res->maxRecordSize = 0;
482 res->updateInterval = 0;
484 res->proprietary = 0;
485 res->copyrightText = 0;
486 res->copyrightNotice = 0;
487 res->producerContactInfo = 0;
488 res->supplierContactInfo = 0;
489 res->submissionContactInfo = 0;
492 for (c = n->child; c; c = c->next)
496 if (!is_numeric_tag (eh, c))
498 switch (c->u.tag.element->tag->value.numeric)
500 case 600: res->commonInfo = f_commonInfo(eh, c); break;
501 case 102: res->name = f_string(eh, c); break;
502 case 226: res->explainDatabase = odr_nullval(); break;
504 res->num_nicknames = 0;
505 for (n = c->child; n; n = n->next)
507 if (!is_numeric_tag(eh, n))
509 if (n->u.tag.element->tag->value.numeric != 102)
511 (res->num_nicknames)++;
513 if (res->num_nicknames)
515 odr_malloc (eh->o, res->num_nicknames
516 * sizeof(*res->nicknames));
518 for (n = c->child; i < res->num_nicknames; n = n->next)
519 res->nicknames[i++] = f_string (eh, n);
521 case 104: res->icon = 0; break; /* fix */
522 case 201: res->userFee = f_bool(eh, c); break;
523 case 202: res->available = f_bool(eh, c); break;
524 case 203: res->titleString = f_humstring(eh, c); break;
526 res->num_keywords = 0;
527 for (n = c->child; n; n = n->next)
529 if (!is_numeric_tag(eh, n))
531 if (n->u.tag.element->tag->value.numeric != 1000)
533 (res->num_keywords)++;
535 if (res->num_keywords)
537 odr_malloc (eh->o, res->num_keywords
538 * sizeof(*res->keywords));
540 for (n = c->child; i < res->num_keywords; n = n->next)
541 res->keywords[i++] = f_humstring (eh, n);
543 case 113: res->description = f_humstring(eh, c); break;
545 res->associatedDbs = f_databaseList (eh, c);
548 res->subDbs = f_databaseList (eh, c);
550 case 207: res->disclaimers = f_humstring(eh, c); break;
551 case 103: res->news = f_humstring(eh, c); break;
552 case 209: res->recordCount =
553 f_recordCount(eh, c, &res->recordCount_which); break;
554 case 212: res->defaultOrder = f_humstring(eh, c); break;
555 case 213: res->avRecordSize = f_integer(eh, c); break;
556 case 214: res->maxRecordSize = f_integer(eh, c); break;
557 case 215: res->hours = f_humstring(eh, c); break;
558 case 216: res->bestTime = f_humstring(eh, c); break;
559 case 217: res->lastUpdate = f_string(eh, c); break;
560 case 218: res->updateInterval = f_intunit(eh, c); break;
561 case 219: res->coverage = f_humstring(eh, c); break;
562 case 220: res->proprietary = f_bool(eh, c); break;
563 case 221: res->copyrightText = f_humstring(eh, c); break;
564 case 222: res->copyrightNotice = f_humstring(eh, c); break;
565 case 223: res->producerContactInfo = f_contactInfo(eh, c); break;
566 case 224: res->supplierContactInfo = f_contactInfo(eh, c); break;
567 case 225: res->submissionContactInfo = f_contactInfo(eh, c); break;
568 case 500: res->accessInfo = f_accessInfo(eh, c); break;
570 logf(LOG_WARN, "Unknown element in databaseInfo");
580 Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
584 Z_ExplainRecord *res = odr_malloc(o, sizeof(*res));
590 assert(n->which == DATA1N_root);
591 if (strcmp(n->u.root.type, "explain"))
593 logf(LOG_WARN, "Attempt to convert a non-Explain record");
599 logf(LOG_WARN, "Explain record should have one exactly one child");
602 if (!is_numeric_tag (&eh, n))
604 switch (n->u.tag.element->tag->value.numeric)
607 res->which = Z_Explain_targetInfo;
608 if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
612 res->which = Z_Explain_databaseInfo;
613 if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
617 logf(LOG_WARN, "Unknown explain category");