1 /* $Id: d1_expout.c,v 1.3 2004-09-28 10:15:03 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 * This module converts data1 tree to Z39.50 Explain records
32 #include <yaz/proto.h>
33 #include <idzebra/data1.h>
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 yaz_log(LOG_WARN, "Tag %s is local", c->u.tag.tag);
53 if (c->u.tag.element->tag->which != DATA1T_numeric)
55 yaz_log(LOG_WARN, "Tag %s is not numeric", c->u.tag.tag);
58 if (eh->select && !c->u.tag.node_selected)
60 return c->u.tag.element->tag->value.numeric;
63 static int is_data_tag (ExpHandle *eh, data1_node *c)
65 if (!c || c->which != DATA1N_data)
67 if (eh->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 = (int *)odr_malloc(eh->o, sizeof(*r));
81 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
86 static char *f_string(ExpHandle *eh, data1_node *c)
91 if (!is_data_tag (eh, c))
93 r = (char *)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 = (int *)odr_malloc (eh->o, sizeof(*tf));
108 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
113 static Odr_oid *f_oid(ExpHandle *eh, data1_node *c, oid_class oclass)
117 oid_value value_for_this;
120 if (!is_data_tag (eh, c) || c->u.data.len > 63)
122 sprintf(oidstr, "%.*s", c->u.data.len, c->u.data.data);
123 value_for_this = oid_getvalbyname(oidstr);
124 if (value_for_this == VAL_NONE)
126 Odr_oid *oid = odr_getoidbystr(eh->o, oidstr);
134 ident.oclass = oclass;
135 ident.proto = PROTO_Z3950;
136 ident.value = value_for_this;
138 oid_ent_to_oid (&ident, oid_this);
140 return odr_oiddup (eh->o, oid_this);
143 static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c)
149 static Z_HumanString *f_humstring(ExpHandle *eh, data1_node *c)
152 Z_HumanStringUnit *u;
155 if (!is_data_tag (eh, c))
157 r = (Z_HumanString *)odr_malloc(eh->o, sizeof(*r));
159 r->strings = (Z_HumanStringUnit **)odr_malloc(eh->o, sizeof(Z_HumanStringUnit*));
160 r->strings[0] = u = (Z_HumanStringUnit *)odr_malloc(eh->o, sizeof(*u));
162 u->text = (char *)odr_malloc(eh->o, c->u.data.len+1);
163 memcpy(u->text, c->u.data.data, c->u.data.len);
164 u->text[c->u.data.len] = '\0';
168 static Z_CommonInfo *f_commonInfo(ExpHandle *eh, data1_node *n)
170 Z_CommonInfo *res = (Z_CommonInfo *)odr_malloc(eh->o, sizeof(*res));
174 res->dateChanged = 0;
176 res->humanStringLanguage = 0;
179 for (c = n->child; c; c = c->next)
181 switch (is_numeric_tag (eh, c))
183 case 601: res->dateAdded = f_string(eh, c); break;
184 case 602: res->dateChanged = f_string(eh, c); break;
185 case 603: res->expiry = f_string(eh, c); break;
186 case 604: res->humanStringLanguage = f_string(eh, c); break;
192 Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num, oid_class oclass)
199 for (c = n->child ; c; c = c->next)
200 if (is_numeric_tag (eh, c) == 1000)
204 res = (int **)odr_malloc (eh->o, sizeof(*res) * (*num));
205 for (c = n->child, i = 0 ; c; c = c->next)
206 if (is_numeric_tag (eh, c) == 1000)
207 res[i++] = f_oid (eh, c, oclass);
211 char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
218 for (c = n->child ; c; c = c->next)
220 if (is_numeric_tag (eh, c) != 1001)
226 res = (char **)odr_malloc (eh->o, sizeof(*res) * (*num));
227 for (c = n->child, i = 0 ; c; c = c->next)
229 if (is_numeric_tag (eh, c) != 1001)
231 res[i++] = f_string (eh, c);
236 Z_ProximitySupport *f_proximitySupport (ExpHandle *eh, data1_node *n)
238 Z_ProximitySupport *res = (Z_ProximitySupport *)
239 odr_malloc (eh->o, sizeof(*res));
240 res->anySupport = eh->false_value;
241 res->num_unitsSupported = 0;
242 res->unitsSupported = 0;
246 Z_RpnCapabilities *f_rpnCapabilities (ExpHandle *eh, data1_node *n)
248 Z_RpnCapabilities *res = (Z_RpnCapabilities *)
249 odr_malloc (eh->o, sizeof(*res));
252 res->num_operators = 0;
253 res->operators = NULL;
254 res->resultSetAsOperandSupported = eh->false_value;
255 res->restrictionOperandSupported = eh->false_value;
256 res->proximity = NULL;
258 for (c = n->child; c; c = c->next)
261 switch (is_numeric_tag(eh, c))
264 for (n = c->child; n; n = n->next)
266 if (is_numeric_tag(eh, n) != 551)
268 (res->num_operators)++;
270 if (res->num_operators)
271 res->operators = (int **)
272 odr_malloc (eh->o, res->num_operators
273 * sizeof(*res->operators));
274 for (n = c->child; n; n = n->next)
276 if (is_numeric_tag(eh, n) != 551)
278 res->operators[i++] = f_integer (eh, n);
282 res->resultSetAsOperandSupported = f_bool (eh, c);
285 res->restrictionOperandSupported = f_bool (eh, c);
288 res->proximity = f_proximitySupport (eh, c);
295 Z_QueryTypeDetails *f_queryTypeDetails (ExpHandle *eh, data1_node *n)
297 Z_QueryTypeDetails *res = (Z_QueryTypeDetails *)
298 odr_malloc(eh->o, sizeof(*res));
301 res->which = Z_QueryTypeDetails_rpn;
303 for (c = n->child; c; c = c->next)
305 switch (is_numeric_tag(eh, c))
308 res->which = Z_QueryTypeDetails_rpn;
309 res->u.rpn = f_rpnCapabilities (eh, c);
320 static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n)
322 Z_AccessInfo *res = (Z_AccessInfo *)odr_malloc(eh->o, sizeof(*res));
325 res->num_queryTypesSupported = 0;
326 res->queryTypesSupported = 0;
327 res->num_diagnosticsSets = 0;
328 res->diagnosticsSets = 0;
329 res->num_attributeSetIds = 0;
330 res->attributeSetIds = 0;
331 res->num_schemas = 0;
333 res->num_recordSyntaxes = 0;
334 res->recordSyntaxes = 0;
335 res->num_resourceChallenges = 0;
336 res->resourceChallenges = 0;
337 res->restrictedAccess = 0;
339 res->num_variantSets = 0;
340 res->variantSets = 0;
341 res->num_elementSetNames = 0;
342 res->elementSetNames = 0;
343 res->num_unitSystems = 0;
344 res->unitSystems = 0;
346 for (c = n->child; c; c = c->next)
349 switch (is_numeric_tag (eh, c))
352 for (n = c->child; n; n = n->next)
354 if (is_numeric_tag(eh, n) != 518)
356 (res->num_queryTypesSupported)++;
358 if (res->num_queryTypesSupported)
359 res->queryTypesSupported =
360 (Z_QueryTypeDetails **)
361 odr_malloc (eh->o, res->num_queryTypesSupported
362 * sizeof(*res->queryTypesSupported));
363 for (n = c->child; n; n = n->next)
365 if (is_numeric_tag(eh, n) != 518)
367 res->queryTypesSupported[i++] = f_queryTypeDetails (eh, n);
371 res->diagnosticsSets =
372 f_oid_seq(eh, c, &res->num_diagnosticsSets, CLASS_DIAGSET);
375 res->attributeSetIds =
376 f_oid_seq(eh, c, &res->num_attributeSetIds, CLASS_ATTSET);
380 f_oid_seq(eh, c, &res->num_schemas, CLASS_SCHEMA);
383 res->recordSyntaxes =
384 f_oid_seq (eh, c, &res->num_recordSyntaxes, CLASS_RECSYN);
387 res->resourceChallenges =
388 f_oid_seq (eh, c, &res->num_resourceChallenges, CLASS_RESFORM);
390 case 513: res->restrictedAccess = NULL; break; /* fix */
391 case 514: res->costInfo = NULL; break; /* fix */
394 f_oid_seq (eh, c, &res->num_variantSets, CLASS_VARSET);
397 res->elementSetNames =
398 f_string_seq (eh, c, &res->num_elementSetNames);
401 res->unitSystems = f_string_seq (eh, c, &res->num_unitSystems);
408 static int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
410 int *r= (int *)odr_malloc(eh->o, sizeof(*r));
415 if (!is_numeric_tag (eh, c))
417 if (c->u.tag.element->tag->value.numeric == 210)
418 *wp = Z_DatabaseInfo_actualNumber;
419 else if (c->u.tag.element->tag->value.numeric == 211)
420 *wp = Z_DatabaseInfo_approxNumber;
423 if (!c->child || c->child->which != DATA1N_data)
425 sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
430 static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
432 Z_ContactInfo *res = (Z_ContactInfo *)
433 odr_malloc (eh->o, sizeof(*res));
437 res->description = 0;
442 for (c = n->child; c; c = c->next)
444 switch (is_numeric_tag (eh, c))
446 case 102: res->name = f_string (eh, c); break;
447 case 113: res->description = f_humstring (eh, c); break;
448 case 127: res->address = f_humstring (eh, c); break;
449 case 128: res->email = f_string (eh, c); break;
450 case 129: res->phone = f_string (eh, c); break;
456 static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n)
462 for (c = n->child; c; c = c->next)
464 if (!is_numeric_tag (eh, c) != 102)
471 res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
473 res->num_databases = i;
474 res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
476 for (c = n->child; c; c = c->next)
478 if (!is_numeric_tag (eh, c) != 102)
480 res->databases[i++] = f_string (eh, c);
485 static Z_NetworkAddressIA *f_networkAddressIA(ExpHandle *eh, data1_node *n)
487 Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
488 odr_malloc (eh->o, sizeof(*res));
491 res->hostAddress = 0;
494 for (c = n->child; c; c = c->next)
496 switch (is_numeric_tag (eh, c))
498 case 121: res->hostAddress = f_string (eh, c); break;
499 case 122: res->port = f_integer (eh, c); break;
505 static Z_NetworkAddressOther *f_networkAddressOther(ExpHandle *eh,
508 Z_NetworkAddressOther *res = (Z_NetworkAddressOther *)
509 odr_malloc (eh->o, sizeof(*res));
515 for (c = n->child; c; c = c->next)
517 switch (is_numeric_tag (eh, c))
519 case 124: res->type = f_string (eh, c); break;
520 case 121: res->address = f_string (eh, c); break;
526 static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
529 Z_NetworkAddress **res = NULL;
534 for (c = n->child; c; c = c->next)
536 switch (is_numeric_tag (eh, c))
546 res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
548 for (c = n->child; c; c = c->next)
550 switch (is_numeric_tag (eh, c))
553 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
554 res[i]->which = Z_NetworkAddress_iA;
555 res[i]->u.internetAddress = f_networkAddressIA(eh, c);
559 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
560 res[i]->which = Z_NetworkAddress_other;
561 res[i]->u.other = f_networkAddressOther(eh, c);
569 static Z_CategoryInfo *f_categoryInfo(ExpHandle *eh, data1_node *n)
571 Z_CategoryInfo *res = (Z_CategoryInfo *)odr_malloc(eh->o, sizeof(*res));
575 res->originalCategory = 0;
576 res->description = 0;
578 for (c = n->child; c; c = c->next)
580 switch (is_numeric_tag (eh, c))
582 case 102: res->category = f_string(eh, c); break;
583 case 302: res->originalCategory = f_string(eh, c); break;
584 case 113: res->description = f_humstring(eh, c); break;
585 case 303: res->asn1Module = f_string (eh, c); break;
591 static Z_CategoryList *f_categoryList(ExpHandle *eh, data1_node *n)
593 Z_CategoryList *res = (Z_CategoryList *)odr_malloc(eh->o, sizeof(*res));
597 res->num_categories = 0;
598 res->categories = NULL;
600 for (c = n->child; c; c = c->next)
604 switch (is_numeric_tag (eh, c))
606 case 600: res->commonInfo = f_commonInfo(eh, c); break;
608 for (n = c->child; n; n = n->next)
610 if (is_numeric_tag(eh, n) != 301)
612 (res->num_categories)++;
614 if (res->num_categories)
616 (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
617 * sizeof(*res->categories));
618 for (n = c->child; n; n = n->next)
620 if (is_numeric_tag(eh, n) != 301)
622 res->categories[i++] = f_categoryInfo (eh, n);
627 assert (res->num_categories && res->categories);
631 static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n)
633 Z_TargetInfo *res = (Z_TargetInfo *)odr_malloc(eh->o, sizeof(*res));
640 res->namedResultSets = 0;
641 res->multipleDBsearch = 0;
642 res->maxResultSets = 0;
643 res->maxResultSize = 0;
645 res->timeoutInterval = 0;
646 res->welcomeMessage = 0;
647 res->contactInfo = 0;
648 res->description = 0;
649 res->num_nicknames = 0;
652 res->paymentAddr = 0;
654 res->num_dbCombinations = 0;
655 res->dbCombinations = 0;
656 res->num_addresses = 0;
658 res->num_languages = 0;
659 res->languages = NULL;
660 res->commonAccessInfo = 0;
662 for (c = n->child; c; c = c->next)
666 switch (is_numeric_tag (eh, c))
668 case 600: res->commonInfo = f_commonInfo(eh, c); break;
669 case 102: res->name = f_string(eh, c); break;
670 case 103: res->recentNews = f_humstring(eh, c); break;
671 case 104: res->icon = NULL; break; /* fix */
672 case 105: res->namedResultSets = f_bool(eh, c); break;
673 case 106: res->multipleDBsearch = f_bool(eh, c); break;
674 case 107: res->maxResultSets = f_integer(eh, c); break;
675 case 108: res->maxResultSize = f_integer(eh, c); break;
676 case 109: res->maxTerms = f_integer(eh, c); break;
677 case 110: res->timeoutInterval = f_intunit(eh, c); break;
678 case 111: res->welcomeMessage = f_humstring(eh, c); break;
679 case 112: res->contactInfo = f_contactInfo(eh, c); break;
680 case 113: res->description = f_humstring(eh, c); break;
682 res->num_nicknames = 0;
683 for (n = c->child; n; n = n->next)
685 if (is_numeric_tag(eh, n) != 102)
687 (res->num_nicknames)++;
689 if (res->num_nicknames)
691 (char **)odr_malloc (eh->o, res->num_nicknames
692 * sizeof(*res->nicknames));
693 for (n = c->child; n; n = n->next)
695 if (is_numeric_tag(eh, n) != 102)
697 res->nicknames[i++] = f_string (eh, n);
700 case 115: res->usageRest = f_humstring(eh, c); break;
701 case 116: res->paymentAddr = f_humstring(eh, c); break;
702 case 117: res->hours = f_humstring(eh, c); break;
704 res->num_dbCombinations = 0;
705 for (n = c->child; n; n = n->next)
707 if (!is_numeric_tag(eh, n) != 605)
709 (res->num_dbCombinations)++;
711 if (res->num_dbCombinations)
712 res->dbCombinations =
713 (Z_DatabaseList **)odr_malloc (eh->o, res->num_dbCombinations
714 * sizeof(*res->dbCombinations));
715 for (n = c->child; n; n = n->next)
717 if (!is_numeric_tag(eh, n) != 605)
719 res->dbCombinations[i++] = f_databaseList (eh, n);
724 f_networkAddresses (eh, c, &res->num_addresses);
727 res->num_languages = 0;
728 for (n = c->child; n; n = n->next)
730 if (!is_numeric_tag(eh, n) != 126)
732 (res->num_languages)++;
734 if (res->num_languages)
735 res->languages = (char **)
736 odr_malloc (eh->o, res->num_languages *
737 sizeof(*res->languages));
738 for (n = c->child; n; n = n->next)
740 if (!is_numeric_tag(eh, n) != 126)
742 res->languages[i++] = f_string (eh, n);
745 case 500: res->commonAccessInfo = f_accessInfo(eh, c); break;
748 if (!res->namedResultSets)
749 res->namedResultSets = eh->false_value;
750 if (!res->multipleDBsearch)
751 res->multipleDBsearch = eh->false_value;
755 static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n)
757 Z_DatabaseInfo *res = (Z_DatabaseInfo *)odr_malloc(eh->o, sizeof(*res));
762 res->explainDatabase = 0;
763 res->num_nicknames = 0;
768 res->titleString = 0;
769 res->num_keywords = 0;
771 res->description = 0;
772 res->associatedDbs = 0;
774 res->disclaimers = 0;
776 res->u.actualNumber = 0;
777 res->defaultOrder = 0;
778 res->avRecordSize = 0;
779 res->maxRecordSize = 0;
783 res->updateInterval = 0;
785 res->proprietary = 0;
786 res->copyrightText = 0;
787 res->copyrightNotice = 0;
788 res->producerContactInfo = 0;
789 res->supplierContactInfo = 0;
790 res->submissionContactInfo = 0;
793 for (c = n->child; c; c = c->next)
797 switch (is_numeric_tag (eh, c))
799 case 600: res->commonInfo = f_commonInfo(eh, c); break;
800 case 102: res->name = f_string(eh, c); break;
801 case 226: res->explainDatabase = odr_nullval(); break;
803 res->num_nicknames = 0;
804 for (n = c->child; n; n = n->next)
806 if (!is_numeric_tag(eh, n) ||
807 n->u.tag.element->tag->value.numeric != 102)
809 (res->num_nicknames)++;
811 if (res->num_nicknames)
813 (char **)odr_malloc (eh->o, res->num_nicknames
814 * sizeof(*res->nicknames));
815 for (n = c->child; n; n = n->next)
817 if (!is_numeric_tag(eh, n) ||
818 n->u.tag.element->tag->value.numeric != 102)
820 res->nicknames[i++] = f_string (eh, n);
823 case 104: res->icon = 0; break; /* fix */
824 case 201: res->userFee = f_bool(eh, c); break;
825 case 202: res->available = f_bool(eh, c); break;
826 case 203: res->titleString = f_humstring(eh, c); break;
828 res->num_keywords = 0;
829 for (n = c->child; n; n = n->next)
831 if (!is_numeric_tag(eh, n) != 1000)
833 (res->num_keywords)++;
835 if (res->num_keywords)
837 (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
838 * sizeof(*res->keywords));
839 for (n = c->child; n; n = n->next)
841 if (!is_numeric_tag(eh, n) != 1000)
843 res->keywords[i++] = f_humstring (eh, n);
846 case 113: res->description = f_humstring(eh, c); break;
848 res->associatedDbs = f_databaseList (eh, c);
851 res->subDbs = f_databaseList (eh, c);
853 case 207: res->disclaimers = f_humstring(eh, c); break;
854 case 103: res->news = f_humstring(eh, c); break;
855 case 209: res->u.actualNumber =
856 f_recordCount(eh, c, &res->which); break;
857 case 212: res->defaultOrder = f_humstring(eh, c); break;
858 case 213: res->avRecordSize = f_integer(eh, c); break;
859 case 214: res->maxRecordSize = f_integer(eh, c); break;
860 case 215: res->hours = f_humstring(eh, c); break;
861 case 216: res->bestTime = f_humstring(eh, c); break;
862 case 217: res->lastUpdate = f_string(eh, c); break;
863 case 218: res->updateInterval = f_intunit(eh, c); break;
864 case 219: res->coverage = f_humstring(eh, c); break;
865 case 220: res->proprietary = f_bool(eh, c); break;
866 case 221: res->copyrightText = f_humstring(eh, c); break;
867 case 222: res->copyrightNotice = f_humstring(eh, c); break;
868 case 223: res->producerContactInfo = f_contactInfo(eh, c); break;
869 case 224: res->supplierContactInfo = f_contactInfo(eh, c); break;
870 case 225: res->submissionContactInfo = f_contactInfo(eh, c); break;
871 case 500: res->accessInfo = f_accessInfo(eh, c); break;
875 res->userFee = eh->false_value;
877 res->available = eh->true_value;
881 Z_StringOrNumeric *f_stringOrNumeric (ExpHandle *eh, data1_node *n)
883 Z_StringOrNumeric *res = (Z_StringOrNumeric *)
884 odr_malloc (eh->o, sizeof(*res));
886 for (c = n->child; c; c = c->next)
888 switch (is_numeric_tag (eh, c))
891 res->which = Z_StringOrNumeric_string;
892 res->u.string = f_string (eh, c);
895 res->which = Z_StringOrNumeric_numeric;
896 res->u.numeric = f_integer (eh, c);
903 Z_AttributeDescription *f_attributeDescription (
904 ExpHandle *eh, data1_node *n)
906 Z_AttributeDescription *res = (Z_AttributeDescription *)
907 odr_malloc(eh->o, sizeof(*res));
912 res->description = 0;
913 res->attributeValue = 0;
914 res->num_equivalentAttributes = 0;
915 res->equivalentAttributes = 0;
917 for (c = n->child; c; c = c->next)
919 switch (is_numeric_tag (eh, c))
921 case 102: res->name = f_string (eh, c); break;
922 case 113: res->description = f_humstring (eh, c); break;
923 case 710: res->attributeValue = f_stringOrNumeric (eh, c); break;
924 case 752: (res->num_equivalentAttributes++); break;
927 if (res->num_equivalentAttributes)
928 res->equivalentAttributes = (Z_StringOrNumeric **)
929 odr_malloc (eh->o, sizeof(*res->equivalentAttributes) *
930 res->num_equivalentAttributes);
931 for (c = n->child; c; c = c->next)
932 if (is_numeric_tag (eh, c) == 752)
933 res->equivalentAttributes[i++] = f_stringOrNumeric (eh, c);
937 Z_AttributeType *f_attributeType (ExpHandle *eh, data1_node *n)
939 Z_AttributeType *res = (Z_AttributeType *)
940 odr_malloc(eh->o, sizeof(*res));
944 res->description = 0;
945 res->attributeType = 0;
946 res->num_attributeValues = 0;
947 res->attributeValues = 0;
949 for (c = n->child; c; c = c->next)
952 switch (is_numeric_tag (eh, c))
954 case 102: res->name = f_string (eh, c); break;
955 case 113: res->description = f_humstring (eh, c); break;
956 case 704: res->attributeType = f_integer (eh, c); break;
958 for (n = c->child; n; n = n->next)
960 if (is_numeric_tag(eh, n) != 709)
962 (res->num_attributeValues)++;
964 if (res->num_attributeValues)
965 res->attributeValues = (Z_AttributeDescription **)
966 odr_malloc (eh->o, res->num_attributeValues
967 * sizeof(*res->attributeValues));
968 for (n = c->child; n; n = n->next)
970 if (is_numeric_tag(eh, n) != 709)
972 res->attributeValues[i++] = f_attributeDescription (eh, n);
980 Z_AttributeSetInfo *f_attributeSetInfo (ExpHandle *eh, data1_node *n)
982 Z_AttributeSetInfo *res = (Z_AttributeSetInfo *)
983 odr_malloc(eh->o, sizeof(*res));
987 res->attributeSet = 0;
989 res->num_attributes = 0;
991 res->description = 0;
992 for (c = n->child; c; c = c->next)
995 switch (is_numeric_tag (eh, c))
997 case 600: res->commonInfo = f_commonInfo (eh, c); break;
998 case 1000: res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
999 case 102: res->name = f_string (eh, c); break;
1001 for (n = c->child; n; n = n->next)
1003 if (is_numeric_tag(eh, n) != 751)
1005 (res->num_attributes)++;
1007 if (res->num_attributes)
1008 res->attributes = (Z_AttributeType **)
1009 odr_malloc (eh->o, res->num_attributes
1010 * sizeof(*res->attributes));
1011 for (n = c->child; n; n = n->next)
1013 if (is_numeric_tag(eh, n) != 751)
1015 res->attributes[i++] = f_attributeType (eh, n);
1018 case 113: res->description = f_humstring (eh, c); break;
1024 Z_OmittedAttributeInterpretation *f_omittedAttributeInterpretation (
1025 ExpHandle *eh, data1_node *n)
1027 Z_OmittedAttributeInterpretation *res = (Z_OmittedAttributeInterpretation*)
1028 odr_malloc (eh->o, sizeof(*res));
1031 res->defaultValue = 0;
1032 res->defaultDescription = 0;
1033 for (c = n->child; c; c = c->next)
1035 switch (is_numeric_tag (eh, c))
1038 res->defaultValue = f_stringOrNumeric (eh, c);
1041 res->defaultDescription = f_humstring(eh, c);
1048 Z_AttributeValue *f_attributeValue (ExpHandle *eh, data1_node *n)
1050 Z_AttributeValue *res = (Z_AttributeValue *)
1051 odr_malloc (eh->o, sizeof(*res));
1055 res->description = 0;
1056 res->num_subAttributes = 0;
1057 res->subAttributes = 0;
1058 res->num_superAttributes = 0;
1059 res->superAttributes = 0;
1060 res->partialSupport = 0;
1061 for (c = n->child; c; c = c->next)
1064 switch (is_numeric_tag (eh, c))
1067 res->value = f_stringOrNumeric (eh, c); break;
1069 res->description = f_humstring (eh, c); break;
1071 for (n = c->child; n; n = n->next)
1073 if (is_numeric_tag(eh, n) != 713)
1075 (res->num_subAttributes)++;
1077 if (res->num_subAttributes)
1078 res->subAttributes =
1079 (Z_StringOrNumeric **)
1080 odr_malloc (eh->o, res->num_subAttributes
1081 * sizeof(*res->subAttributes));
1082 for (n = c->child; n; n = n->next)
1084 if (is_numeric_tag(eh, n) != 713)
1086 res->subAttributes[i++] = f_stringOrNumeric (eh, n);
1090 for (n = c->child; n; n = n->next)
1092 if (is_numeric_tag(eh, n) != 715)
1094 (res->num_superAttributes)++;
1096 if (res->num_superAttributes)
1097 res->superAttributes =
1098 (Z_StringOrNumeric **)
1099 odr_malloc (eh->o, res->num_superAttributes
1100 * sizeof(*res->superAttributes));
1101 for (n = c->child; n; n = n->next)
1103 if (is_numeric_tag(eh, n) != 715)
1105 res->superAttributes[i++] = f_stringOrNumeric (eh, n);
1109 res->partialSupport = odr_nullval ();
1116 Z_AttributeTypeDetails *f_attributeTypeDetails (ExpHandle *eh, data1_node *n)
1118 Z_AttributeTypeDetails *res = (Z_AttributeTypeDetails *)
1119 odr_malloc(eh->o, sizeof(*res));
1121 res->attributeType = 0;
1122 res->defaultIfOmitted = 0;
1123 res->num_attributeValues = 0;
1124 res->attributeValues = 0;
1125 for (c = n->child; c; c = c->next)
1128 switch (is_numeric_tag (eh, c))
1130 case 704: res->attributeType = f_integer (eh, c); break;
1132 res->defaultIfOmitted = f_omittedAttributeInterpretation (eh, c);
1135 for (n = c->child; n; n = n->next)
1137 if (is_numeric_tag(eh, n) != 709)
1139 (res->num_attributeValues)++;
1141 if (res->num_attributeValues)
1142 res->attributeValues =
1143 (Z_AttributeValue **)
1144 odr_malloc (eh->o, res->num_attributeValues
1145 * sizeof(*res->attributeValues));
1146 for (n = c->child; n; n = n->next)
1148 if (is_numeric_tag(eh, n) != 709)
1150 res->attributeValues[i++] = f_attributeValue (eh, n);
1158 Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n)
1160 Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
1161 odr_malloc(eh->o, sizeof(*res));
1164 res->attributeSet = 0;
1165 res->num_attributesByType = 0;
1166 res->attributesByType = 0;
1167 for (c = n->child; c; c = c->next)
1170 switch (is_numeric_tag (eh, c))
1172 case 1000: res->attributeSet = f_oid(eh, c, CLASS_ATTSET); break;
1174 for (n = c->child; n; n = n->next)
1176 if (is_numeric_tag(eh, n) != 703)
1178 (res->num_attributesByType)++;
1180 if (res->num_attributesByType)
1181 res->attributesByType =
1182 (Z_AttributeTypeDetails **)
1183 odr_malloc (eh->o, res->num_attributesByType
1184 * sizeof(*res->attributesByType));
1185 for (n = c->child; n; n = n->next)
1187 if (is_numeric_tag(eh, n) != 703)
1189 res->attributesByType[i++] = f_attributeTypeDetails (eh, n);
1197 Z_AttributeValueList *f_attributeValueList (ExpHandle *eh, data1_node *n)
1199 Z_AttributeValueList *res = (Z_AttributeValueList *)
1200 odr_malloc (eh->o, sizeof(*res));
1204 res->num_attributes = 0;
1205 res->attributes = 0;
1206 for (c = n->child; c; c = c->next)
1207 if (is_numeric_tag (eh, c) == 710)
1208 (res->num_attributes)++;
1209 if (res->num_attributes)
1211 res->attributes = (Z_StringOrNumeric **)
1212 odr_malloc (eh->o, res->num_attributes * sizeof(*res->attributes));
1214 for (c = n->child; c; c = c->next)
1215 if (is_numeric_tag(eh, c) == 710)
1216 res->attributes[i++] = f_stringOrNumeric (eh, c);
1220 Z_AttributeOccurrence *f_attributeOccurrence (ExpHandle *eh, data1_node *n)
1222 Z_AttributeOccurrence *res = (Z_AttributeOccurrence *)
1223 odr_malloc (eh->o, sizeof(*res));
1226 res->attributeSet = 0;
1227 res->attributeType = 0;
1228 res->mustBeSupplied = 0;
1229 res->which = Z_AttributeOcc_any_or_none;
1230 res->attributeValues.any_or_none = odr_nullval ();
1232 for (c = n->child; c; c = c->next)
1234 switch (is_numeric_tag (eh, c))
1237 res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
1239 res->attributeType = f_integer (eh, c); break;
1241 res->mustBeSupplied = odr_nullval (); break;
1243 res->which = Z_AttributeOcc_any_or_none;
1244 res->attributeValues.any_or_none = odr_nullval ();
1247 res->which = Z_AttributeOcc_specific;
1248 res->attributeValues.specific = f_attributeValueList (eh, c);
1255 Z_AttributeCombination *f_attributeCombination (ExpHandle *eh, data1_node *n)
1257 Z_AttributeCombination *res = (Z_AttributeCombination *)
1258 odr_malloc (eh->o, sizeof(*res));
1262 res->num_occurrences = 0;
1263 res->occurrences = 0;
1264 for (c = n->child; c; c = c->next)
1265 if (is_numeric_tag (eh, c) == 719)
1266 (res->num_occurrences)++;
1267 if (res->num_occurrences)
1269 res->occurrences = (Z_AttributeOccurrence **)
1270 odr_malloc (eh->o, res->num_occurrences * sizeof(*res->occurrences));
1272 for (c = n->child; c; c = c->next)
1273 if (is_numeric_tag(eh, c) == 719)
1274 res->occurrences[i++] = f_attributeOccurrence (eh, c);
1275 assert (res->num_occurrences);
1279 Z_AttributeCombinations *f_attributeCombinations (ExpHandle *eh, data1_node *n)
1281 Z_AttributeCombinations *res = (Z_AttributeCombinations *)
1282 odr_malloc (eh->o, sizeof(*res));
1284 res->defaultAttributeSet = 0;
1285 res->num_legalCombinations = 0;
1286 res->legalCombinations = 0;
1288 for (c = n->child; c; c = c->next)
1291 switch (is_numeric_tag (eh, c))
1294 res->defaultAttributeSet = f_oid (eh, c, CLASS_ATTSET);
1297 for (n = c->child; n; n = n->next)
1299 if (is_numeric_tag(eh, n) != 718)
1301 (res->num_legalCombinations)++;
1303 if (res->num_legalCombinations)
1304 res->legalCombinations =
1305 (Z_AttributeCombination **)
1306 odr_malloc (eh->o, res->num_legalCombinations
1307 * sizeof(*res->legalCombinations));
1308 for (n = c->child; n; n = n->next)
1310 if (is_numeric_tag(eh, n) != 718)
1312 res->legalCombinations[i++] = f_attributeCombination (eh, n);
1317 assert (res->num_legalCombinations);
1321 Z_AttributeDetails *f_attributeDetails (ExpHandle *eh, data1_node *n)
1323 Z_AttributeDetails *res = (Z_AttributeDetails *)
1324 odr_malloc(eh->o, sizeof(*res));
1327 res->commonInfo = 0;
1328 res->databaseName = 0;
1329 res->num_attributesBySet = 0;
1330 res->attributesBySet = NULL;
1331 res->attributeCombinations = NULL;
1333 for (c = n->child; c; c = c->next)
1336 switch (is_numeric_tag (eh, c))
1338 case 600: res->commonInfo = f_commonInfo(eh, c); break;
1339 case 102: res->databaseName = f_string (eh, c); break;
1341 for (n = c->child; n; n = n->next)
1343 if (is_numeric_tag(eh, n) != 701)
1345 (res->num_attributesBySet)++;
1347 if (res->num_attributesBySet)
1348 res->attributesBySet =
1349 (Z_AttributeSetDetails **)
1350 odr_malloc (eh->o, res->num_attributesBySet
1351 * sizeof(*res->attributesBySet));
1352 for (n = c->child; n; n = n->next)
1354 if (is_numeric_tag(eh, n) != 701)
1356 res->attributesBySet[i++] = f_attributeSetDetails (eh, n);
1360 res->attributeCombinations = f_attributeCombinations (eh, c);
1367 Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
1371 Z_ExplainRecord *res = (Z_ExplainRecord *)odr_malloc(o, sizeof(*res));
1376 eh.false_value = (int *)odr_malloc(eh.o, sizeof(eh.false_value));
1377 *eh.false_value = 0;
1378 eh.true_value = (int *)odr_malloc(eh.o, sizeof(eh.true_value));
1381 assert(n->which == DATA1N_root);
1382 if (strcmp(n->u.root.type, "explain"))
1384 yaz_log(LOG_WARN, "Attempt to convert a non-Explain record");
1387 for (n = n->child; n; n = n->next)
1389 switch (is_numeric_tag (&eh, n))
1392 res->which = Z_Explain_categoryList;
1393 if (!(res->u.categoryList = f_categoryList(&eh, n)))
1397 res->which = Z_Explain_targetInfo;
1398 if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
1402 res->which = Z_Explain_databaseInfo;
1403 if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
1407 res->which = Z_Explain_attributeSetInfo;
1408 if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
1412 res->which = Z_Explain_attributeDetails;
1413 if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
1418 yaz_log(LOG_WARN, "No category in Explain record");