1 /* This file is part of the Zebra server.
2 Copyright (C) 2004-2013 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * This module converts data1 tree to Z39.50 Explain records
32 #include <yaz/proto.h>
33 #include <yaz/oid_db.h>
34 #include <yaz/snprintf.h>
35 #include <idzebra/data1.h>
46 static int is_numeric_tag (ExpHandle *eh, data1_node *c)
48 if (!c || c->which != DATA1N_tag)
50 if (!c->u.tag.element)
52 yaz_log(YLOG_WARN, "Tag %s is local", c->u.tag.tag);
55 if (c->u.tag.element->tag->which != DATA1T_numeric)
57 yaz_log(YLOG_WARN, "Tag %s is not numeric", c->u.tag.tag);
60 if (eh->select && !c->u.tag.node_selected)
62 return c->u.tag.element->tag->value.numeric;
65 static int is_data_tag (ExpHandle *eh, data1_node *c)
67 if (!c || c->which != DATA1N_data)
69 if (eh->select && !c->u.tag.node_selected)
74 static Odr_int *f_integer(ExpHandle *eh, data1_node *c)
79 if (!is_data_tag (eh, c) || c->u.data.len >= sizeof(intbuf))
81 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
82 return odr_intdup(eh->o, atoi(intbuf));
85 static char *f_string(ExpHandle *eh, data1_node *c)
90 if (!is_data_tag (eh, c))
92 r = (char *)odr_malloc(eh->o, c->u.data.len+1);
93 memcpy(r, c->u.data.data, c->u.data.len);
94 r[c->u.data.len] = '\0';
98 static bool_t *f_bool(ExpHandle *eh, data1_node *c)
104 if (!is_data_tag (eh, c) || c->u.data.len > 63)
106 tf = (int *)odr_malloc (eh->o, sizeof(*tf));
107 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
112 static Odr_oid *f_oid(ExpHandle *eh, data1_node *c, oid_class oclass)
117 if (!is_data_tag (eh, c) || c->u.data.len > 63)
119 yaz_snprintf(oidstr, sizeof(oidstr)-1,
120 "%.*s", c->u.data.len, c->u.data.data);
122 return yaz_string_to_oid_odr(yaz_oid_std(),
123 CLASS_GENERAL, oidstr, eh->o);
126 static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c)
132 static Z_HumanString *f_humstring(ExpHandle *eh, data1_node *c)
135 Z_HumanStringUnit *u;
138 if (!is_data_tag (eh, c))
140 r = (Z_HumanString *)odr_malloc(eh->o, sizeof(*r));
142 r->strings = (Z_HumanStringUnit **)odr_malloc(eh->o, sizeof(Z_HumanStringUnit*));
143 r->strings[0] = u = (Z_HumanStringUnit *)odr_malloc(eh->o, sizeof(*u));
145 u->text = (char *)odr_malloc(eh->o, c->u.data.len+1);
146 memcpy(u->text, c->u.data.data, c->u.data.len);
147 u->text[c->u.data.len] = '\0';
151 static Z_CommonInfo *f_commonInfo(ExpHandle *eh, data1_node *n)
153 Z_CommonInfo *res = (Z_CommonInfo *)odr_malloc(eh->o, sizeof(*res));
157 res->dateChanged = 0;
159 res->humanStringLanguage = 0;
162 for (c = n->child; c; c = c->next)
164 switch (is_numeric_tag (eh, c))
166 case 601: res->dateAdded = f_string(eh, c); break;
167 case 602: res->dateChanged = f_string(eh, c); break;
168 case 603: res->expiry = f_string(eh, c); break;
169 case 604: res->humanStringLanguage = f_string(eh, c); break;
175 Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num, oid_class oclass)
182 for (c = n->child ; c; c = c->next)
183 if (is_numeric_tag (eh, c) == 1000)
187 res = (Odr_oid **)odr_malloc (eh->o, sizeof(*res) * (*num));
188 for (c = n->child, i = 0 ; c; c = c->next)
189 if (is_numeric_tag (eh, c) == 1000)
190 res[i++] = f_oid (eh, c, oclass);
194 char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
201 for (c = n->child ; c; c = c->next)
203 if (is_numeric_tag (eh, c) != 1001)
209 res = (char **)odr_malloc (eh->o, sizeof(*res) * (*num));
210 for (c = n->child, i = 0 ; c; c = c->next)
212 if (is_numeric_tag (eh, c) != 1001)
214 res[i++] = f_string (eh, c);
219 Z_ProximitySupport *f_proximitySupport (ExpHandle *eh, data1_node *n)
221 Z_ProximitySupport *res = (Z_ProximitySupport *)
222 odr_malloc (eh->o, sizeof(*res));
223 res->anySupport = eh->false_value;
224 res->num_unitsSupported = 0;
225 res->unitsSupported = 0;
229 Z_RpnCapabilities *f_rpnCapabilities (ExpHandle *eh, data1_node *n)
231 Z_RpnCapabilities *res = (Z_RpnCapabilities *)
232 odr_malloc (eh->o, sizeof(*res));
235 res->num_operators = 0;
236 res->operators = NULL;
237 res->resultSetAsOperandSupported = eh->false_value;
238 res->restrictionOperandSupported = eh->false_value;
239 res->proximity = NULL;
241 for (c = n->child; c; c = c->next)
244 switch (is_numeric_tag(eh, c))
247 for (n = c->child; n; n = n->next)
249 if (is_numeric_tag(eh, n) != 551)
251 (res->num_operators)++;
253 if (res->num_operators)
254 res->operators = (Odr_int **)
255 odr_malloc (eh->o, res->num_operators
256 * sizeof(*res->operators));
257 for (n = c->child; n; n = n->next)
259 if (is_numeric_tag(eh, n) != 551)
261 res->operators[i++] = f_integer (eh, n);
265 res->resultSetAsOperandSupported = f_bool (eh, c);
268 res->restrictionOperandSupported = f_bool (eh, c);
271 res->proximity = f_proximitySupport (eh, c);
278 Z_QueryTypeDetails *f_queryTypeDetails (ExpHandle *eh, data1_node *n)
280 Z_QueryTypeDetails *res = (Z_QueryTypeDetails *)
281 odr_malloc(eh->o, sizeof(*res));
284 res->which = Z_QueryTypeDetails_rpn;
286 for (c = n->child; c; c = c->next)
288 switch (is_numeric_tag(eh, c))
291 res->which = Z_QueryTypeDetails_rpn;
292 res->u.rpn = f_rpnCapabilities (eh, c);
303 static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n)
305 Z_AccessInfo *res = (Z_AccessInfo *)odr_malloc(eh->o, sizeof(*res));
308 res->num_queryTypesSupported = 0;
309 res->queryTypesSupported = 0;
310 res->num_diagnosticsSets = 0;
311 res->diagnosticsSets = 0;
312 res->num_attributeSetIds = 0;
313 res->attributeSetIds = 0;
314 res->num_schemas = 0;
316 res->num_recordSyntaxes = 0;
317 res->recordSyntaxes = 0;
318 res->num_resourceChallenges = 0;
319 res->resourceChallenges = 0;
320 res->restrictedAccess = 0;
322 res->num_variantSets = 0;
323 res->variantSets = 0;
324 res->num_elementSetNames = 0;
325 res->elementSetNames = 0;
326 res->num_unitSystems = 0;
327 res->unitSystems = 0;
329 for (c = n->child; c; c = c->next)
332 switch (is_numeric_tag (eh, c))
335 for (n = c->child; n; n = n->next)
337 if (is_numeric_tag(eh, n) != 518)
339 (res->num_queryTypesSupported)++;
341 if (res->num_queryTypesSupported)
342 res->queryTypesSupported =
343 (Z_QueryTypeDetails **)
344 odr_malloc (eh->o, res->num_queryTypesSupported
345 * sizeof(*res->queryTypesSupported));
346 for (n = c->child; n; n = n->next)
348 if (is_numeric_tag(eh, n) != 518)
350 res->queryTypesSupported[i++] = f_queryTypeDetails (eh, n);
354 res->diagnosticsSets =
355 f_oid_seq(eh, c, &res->num_diagnosticsSets, CLASS_DIAGSET);
358 res->attributeSetIds =
359 f_oid_seq(eh, c, &res->num_attributeSetIds, CLASS_ATTSET);
363 f_oid_seq(eh, c, &res->num_schemas, CLASS_SCHEMA);
366 res->recordSyntaxes =
367 f_oid_seq (eh, c, &res->num_recordSyntaxes, CLASS_RECSYN);
370 res->resourceChallenges =
371 f_oid_seq (eh, c, &res->num_resourceChallenges, CLASS_RESFORM);
373 case 513: res->restrictedAccess = NULL; break; /* fix */
374 case 514: res->costInfo = NULL; break; /* fix */
377 f_oid_seq (eh, c, &res->num_variantSets, CLASS_VARSET);
380 res->elementSetNames =
381 f_string_seq (eh, c, &res->num_elementSetNames);
384 res->unitSystems = f_string_seq (eh, c, &res->num_unitSystems);
391 static Odr_int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
397 if (!is_numeric_tag (eh, c))
399 if (c->u.tag.element->tag->value.numeric == 210)
400 *wp = Z_DatabaseInfo_actualNumber;
401 else if (c->u.tag.element->tag->value.numeric == 211)
402 *wp = Z_DatabaseInfo_approxNumber;
405 if (!c->child || c->child->which != DATA1N_data ||
406 c->child->u.data.len >= sizeof(intbuf))
408 sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
409 return odr_intdup(eh->o, atoi(intbuf));
412 static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
414 Z_ContactInfo *res = (Z_ContactInfo *)
415 odr_malloc (eh->o, sizeof(*res));
419 res->description = 0;
424 for (c = n->child; c; c = c->next)
426 switch (is_numeric_tag (eh, c))
428 case 102: res->name = f_string (eh, c); break;
429 case 113: res->description = f_humstring (eh, c); break;
430 case 127: res->address = f_humstring (eh, c); break;
431 case 128: res->email = f_string (eh, c); break;
432 case 129: res->phone = f_string (eh, c); break;
438 static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n)
444 for (c = n->child; c; c = c->next)
446 if (!is_numeric_tag (eh, c) != 102)
453 res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
455 res->num_databases = i;
456 res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
458 for (c = n->child; c; c = c->next)
460 if (!is_numeric_tag (eh, c) != 102)
462 res->databases[i++] = f_string (eh, c);
467 static Z_NetworkAddressIA *f_networkAddressIA(ExpHandle *eh, data1_node *n)
469 Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
470 odr_malloc (eh->o, sizeof(*res));
473 res->hostAddress = 0;
476 for (c = n->child; c; c = c->next)
478 switch (is_numeric_tag (eh, c))
480 case 121: res->hostAddress = f_string (eh, c); break;
481 case 122: res->port = f_integer (eh, c); break;
487 static Z_NetworkAddressOther *f_networkAddressOther(ExpHandle *eh,
490 Z_NetworkAddressOther *res = (Z_NetworkAddressOther *)
491 odr_malloc (eh->o, sizeof(*res));
497 for (c = n->child; c; c = c->next)
499 switch (is_numeric_tag (eh, c))
501 case 124: res->type = f_string (eh, c); break;
502 case 121: res->address = f_string (eh, c); break;
508 static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
511 Z_NetworkAddress **res = NULL;
516 for (c = n->child; c; c = c->next)
518 switch (is_numeric_tag (eh, c))
528 res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
530 for (c = n->child; c; c = c->next)
532 switch (is_numeric_tag (eh, c))
535 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
536 res[i]->which = Z_NetworkAddress_iA;
537 res[i]->u.internetAddress = f_networkAddressIA(eh, c);
541 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
542 res[i]->which = Z_NetworkAddress_other;
543 res[i]->u.other = f_networkAddressOther(eh, c);
551 static Z_CategoryInfo *f_categoryInfo(ExpHandle *eh, data1_node *n)
553 Z_CategoryInfo *res = (Z_CategoryInfo *)odr_malloc(eh->o, sizeof(*res));
557 res->originalCategory = 0;
558 res->description = 0;
560 for (c = n->child; c; c = c->next)
562 switch (is_numeric_tag (eh, c))
564 case 102: res->category = f_string(eh, c); break;
565 case 302: res->originalCategory = f_string(eh, c); break;
566 case 113: res->description = f_humstring(eh, c); break;
567 case 303: res->asn1Module = f_string (eh, c); break;
573 static Z_CategoryList *f_categoryList(ExpHandle *eh, data1_node *n)
575 Z_CategoryList *res = (Z_CategoryList *)odr_malloc(eh->o, sizeof(*res));
579 res->num_categories = 0;
580 res->categories = NULL;
582 for (c = n->child; c; c = c->next)
586 switch (is_numeric_tag (eh, c))
588 case 600: res->commonInfo = f_commonInfo(eh, c); break;
590 for (n = c->child; n; n = n->next)
592 if (is_numeric_tag(eh, n) != 301)
594 (res->num_categories)++;
596 if (res->num_categories)
598 (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
599 * sizeof(*res->categories));
600 for (n = c->child; n; n = n->next)
602 if (is_numeric_tag(eh, n) != 301)
604 res->categories[i++] = f_categoryInfo (eh, n);
609 assert (res->num_categories && res->categories);
613 static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n)
615 Z_TargetInfo *res = (Z_TargetInfo *)odr_malloc(eh->o, sizeof(*res));
622 res->namedResultSets = 0;
623 res->multipleDBsearch = 0;
624 res->maxResultSets = 0;
625 res->maxResultSize = 0;
627 res->timeoutInterval = 0;
628 res->welcomeMessage = 0;
629 res->contactInfo = 0;
630 res->description = 0;
631 res->num_nicknames = 0;
634 res->paymentAddr = 0;
636 res->num_dbCombinations = 0;
637 res->dbCombinations = 0;
638 res->num_addresses = 0;
640 res->num_languages = 0;
641 res->languages = NULL;
642 res->commonAccessInfo = 0;
644 for (c = n->child; c; c = c->next)
648 switch (is_numeric_tag (eh, c))
650 case 600: res->commonInfo = f_commonInfo(eh, c); break;
651 case 102: res->name = f_string(eh, c); break;
652 case 103: res->recentNews = f_humstring(eh, c); break;
653 case 104: res->icon = NULL; break; /* fix */
654 case 105: res->namedResultSets = f_bool(eh, c); break;
655 case 106: res->multipleDBsearch = f_bool(eh, c); break;
656 case 107: res->maxResultSets = f_integer(eh, c); break;
657 case 108: res->maxResultSize = f_integer(eh, c); break;
658 case 109: res->maxTerms = f_integer(eh, c); break;
659 case 110: res->timeoutInterval = f_intunit(eh, c); break;
660 case 111: res->welcomeMessage = f_humstring(eh, c); break;
661 case 112: res->contactInfo = f_contactInfo(eh, c); break;
662 case 113: res->description = f_humstring(eh, c); break;
664 res->num_nicknames = 0;
665 for (n = c->child; n; n = n->next)
667 if (is_numeric_tag(eh, n) != 102)
669 (res->num_nicknames)++;
671 if (res->num_nicknames)
673 (char **)odr_malloc (eh->o, res->num_nicknames
674 * sizeof(*res->nicknames));
675 for (n = c->child; n; n = n->next)
677 if (is_numeric_tag(eh, n) != 102)
679 res->nicknames[i++] = f_string (eh, n);
682 case 115: res->usageRest = f_humstring(eh, c); break;
683 case 116: res->paymentAddr = f_humstring(eh, c); break;
684 case 117: res->hours = f_humstring(eh, c); break;
686 res->num_dbCombinations = 0;
687 for (n = c->child; n; n = n->next)
689 if (!is_numeric_tag(eh, n) != 605)
691 (res->num_dbCombinations)++;
693 if (res->num_dbCombinations)
694 res->dbCombinations =
695 (Z_DatabaseList **)odr_malloc (eh->o, res->num_dbCombinations
696 * sizeof(*res->dbCombinations));
697 for (n = c->child; n; n = n->next)
699 if (!is_numeric_tag(eh, n) != 605)
701 res->dbCombinations[i++] = f_databaseList (eh, n);
706 f_networkAddresses (eh, c, &res->num_addresses);
709 res->num_languages = 0;
710 for (n = c->child; n; n = n->next)
712 if (!is_numeric_tag(eh, n) != 126)
714 (res->num_languages)++;
716 if (res->num_languages)
717 res->languages = (char **)
718 odr_malloc (eh->o, res->num_languages *
719 sizeof(*res->languages));
720 for (n = c->child; n; n = n->next)
722 if (!is_numeric_tag(eh, n) != 126)
724 res->languages[i++] = f_string (eh, n);
727 case 500: res->commonAccessInfo = f_accessInfo(eh, c); break;
730 if (!res->namedResultSets)
731 res->namedResultSets = eh->false_value;
732 if (!res->multipleDBsearch)
733 res->multipleDBsearch = eh->false_value;
737 static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n)
739 Z_DatabaseInfo *res = (Z_DatabaseInfo *)odr_malloc(eh->o, sizeof(*res));
744 res->explainDatabase = 0;
745 res->num_nicknames = 0;
750 res->titleString = 0;
751 res->num_keywords = 0;
753 res->description = 0;
754 res->associatedDbs = 0;
756 res->disclaimers = 0;
758 res->u.actualNumber = 0;
759 res->defaultOrder = 0;
760 res->avRecordSize = 0;
761 res->maxRecordSize = 0;
765 res->updateInterval = 0;
767 res->proprietary = 0;
768 res->copyrightText = 0;
769 res->copyrightNotice = 0;
770 res->producerContactInfo = 0;
771 res->supplierContactInfo = 0;
772 res->submissionContactInfo = 0;
775 for (c = n->child; c; c = c->next)
779 switch (is_numeric_tag (eh, c))
781 case 600: res->commonInfo = f_commonInfo(eh, c); break;
782 case 102: res->name = f_string(eh, c); break;
783 case 226: res->explainDatabase = odr_nullval(); break;
785 res->num_nicknames = 0;
786 for (n = c->child; n; n = n->next)
788 if (!is_numeric_tag(eh, n) ||
789 n->u.tag.element->tag->value.numeric != 102)
791 (res->num_nicknames)++;
793 if (res->num_nicknames)
795 (char **)odr_malloc (eh->o, res->num_nicknames
796 * sizeof(*res->nicknames));
797 for (n = c->child; n; n = n->next)
799 if (!is_numeric_tag(eh, n) ||
800 n->u.tag.element->tag->value.numeric != 102)
802 res->nicknames[i++] = f_string (eh, n);
805 case 104: res->icon = 0; break; /* fix */
806 case 201: res->userFee = f_bool(eh, c); break;
807 case 202: res->available = f_bool(eh, c); break;
808 case 203: res->titleString = f_humstring(eh, c); break;
810 res->num_keywords = 0;
811 for (n = c->child; n; n = n->next)
813 if (!is_numeric_tag(eh, n) != 1000)
815 (res->num_keywords)++;
817 if (res->num_keywords)
819 (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
820 * sizeof(*res->keywords));
821 for (n = c->child; n; n = n->next)
823 if (!is_numeric_tag(eh, n) != 1000)
825 res->keywords[i++] = f_humstring (eh, n);
828 case 113: res->description = f_humstring(eh, c); break;
830 res->associatedDbs = f_databaseList (eh, c);
833 res->subDbs = f_databaseList (eh, c);
835 case 207: res->disclaimers = f_humstring(eh, c); break;
836 case 103: res->news = f_humstring(eh, c); break;
837 case 209: res->u.actualNumber =
838 f_recordCount(eh, c, &res->which); break;
839 case 212: res->defaultOrder = f_humstring(eh, c); break;
840 case 213: res->avRecordSize = f_integer(eh, c); break;
841 case 214: res->maxRecordSize = f_integer(eh, c); break;
842 case 215: res->hours = f_humstring(eh, c); break;
843 case 216: res->bestTime = f_humstring(eh, c); break;
844 case 217: res->lastUpdate = f_string(eh, c); break;
845 case 218: res->updateInterval = f_intunit(eh, c); break;
846 case 219: res->coverage = f_humstring(eh, c); break;
847 case 220: res->proprietary = f_bool(eh, c); break;
848 case 221: res->copyrightText = f_humstring(eh, c); break;
849 case 222: res->copyrightNotice = f_humstring(eh, c); break;
850 case 223: res->producerContactInfo = f_contactInfo(eh, c); break;
851 case 224: res->supplierContactInfo = f_contactInfo(eh, c); break;
852 case 225: res->submissionContactInfo = f_contactInfo(eh, c); break;
853 case 500: res->accessInfo = f_accessInfo(eh, c); break;
857 res->userFee = eh->false_value;
859 res->available = eh->true_value;
863 Z_StringOrNumeric *f_stringOrNumeric (ExpHandle *eh, data1_node *n)
865 Z_StringOrNumeric *res = (Z_StringOrNumeric *)
866 odr_malloc (eh->o, sizeof(*res));
868 for (c = n->child; c; c = c->next)
870 switch (is_numeric_tag (eh, c))
873 res->which = Z_StringOrNumeric_string;
874 res->u.string = f_string (eh, c);
877 res->which = Z_StringOrNumeric_numeric;
878 res->u.numeric = f_integer (eh, c);
885 Z_AttributeDescription *f_attributeDescription (
886 ExpHandle *eh, data1_node *n)
888 Z_AttributeDescription *res = (Z_AttributeDescription *)
889 odr_malloc(eh->o, sizeof(*res));
894 res->description = 0;
895 res->attributeValue = 0;
896 res->num_equivalentAttributes = 0;
897 res->equivalentAttributes = 0;
899 for (c = n->child; c; c = c->next)
901 switch (is_numeric_tag (eh, c))
903 case 102: res->name = f_string (eh, c); break;
904 case 113: res->description = f_humstring (eh, c); break;
905 case 710: res->attributeValue = f_stringOrNumeric (eh, c); break;
906 case 752: (res->num_equivalentAttributes++); break;
909 if (res->num_equivalentAttributes)
910 res->equivalentAttributes = (Z_StringOrNumeric **)
911 odr_malloc (eh->o, sizeof(*res->equivalentAttributes) *
912 res->num_equivalentAttributes);
913 for (c = n->child; c; c = c->next)
914 if (is_numeric_tag (eh, c) == 752)
915 res->equivalentAttributes[i++] = f_stringOrNumeric (eh, c);
919 Z_AttributeType *f_attributeType (ExpHandle *eh, data1_node *n)
921 Z_AttributeType *res = (Z_AttributeType *)
922 odr_malloc(eh->o, sizeof(*res));
926 res->description = 0;
927 res->attributeType = 0;
928 res->num_attributeValues = 0;
929 res->attributeValues = 0;
931 for (c = n->child; c; c = c->next)
934 switch (is_numeric_tag (eh, c))
936 case 102: res->name = f_string (eh, c); break;
937 case 113: res->description = f_humstring (eh, c); break;
938 case 704: res->attributeType = f_integer (eh, c); break;
940 for (n = c->child; n; n = n->next)
942 if (is_numeric_tag(eh, n) != 709)
944 (res->num_attributeValues)++;
946 if (res->num_attributeValues)
947 res->attributeValues = (Z_AttributeDescription **)
948 odr_malloc (eh->o, res->num_attributeValues
949 * sizeof(*res->attributeValues));
950 for (n = c->child; n; n = n->next)
952 if (is_numeric_tag(eh, n) != 709)
954 res->attributeValues[i++] = f_attributeDescription (eh, n);
962 Z_AttributeSetInfo *f_attributeSetInfo (ExpHandle *eh, data1_node *n)
964 Z_AttributeSetInfo *res = (Z_AttributeSetInfo *)
965 odr_malloc(eh->o, sizeof(*res));
969 res->attributeSet = 0;
971 res->num_attributes = 0;
973 res->description = 0;
974 for (c = n->child; c; c = c->next)
977 switch (is_numeric_tag (eh, c))
979 case 600: res->commonInfo = f_commonInfo (eh, c); break;
980 case 1000: res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
981 case 102: res->name = f_string (eh, c); break;
983 for (n = c->child; n; n = n->next)
985 if (is_numeric_tag(eh, n) != 751)
987 (res->num_attributes)++;
989 if (res->num_attributes)
990 res->attributes = (Z_AttributeType **)
991 odr_malloc (eh->o, res->num_attributes
992 * sizeof(*res->attributes));
993 for (n = c->child; n; n = n->next)
995 if (is_numeric_tag(eh, n) != 751)
997 res->attributes[i++] = f_attributeType (eh, n);
1000 case 113: res->description = f_humstring (eh, c); break;
1006 Z_OmittedAttributeInterpretation *f_omittedAttributeInterpretation (
1007 ExpHandle *eh, data1_node *n)
1009 Z_OmittedAttributeInterpretation *res = (Z_OmittedAttributeInterpretation*)
1010 odr_malloc (eh->o, sizeof(*res));
1013 res->defaultValue = 0;
1014 res->defaultDescription = 0;
1015 for (c = n->child; c; c = c->next)
1017 switch (is_numeric_tag (eh, c))
1020 res->defaultValue = f_stringOrNumeric (eh, c);
1023 res->defaultDescription = f_humstring(eh, c);
1030 Z_AttributeValue *f_attributeValue (ExpHandle *eh, data1_node *n)
1032 Z_AttributeValue *res = (Z_AttributeValue *)
1033 odr_malloc (eh->o, sizeof(*res));
1037 res->description = 0;
1038 res->num_subAttributes = 0;
1039 res->subAttributes = 0;
1040 res->num_superAttributes = 0;
1041 res->superAttributes = 0;
1042 res->partialSupport = 0;
1043 for (c = n->child; c; c = c->next)
1046 switch (is_numeric_tag (eh, c))
1049 res->value = f_stringOrNumeric (eh, c); break;
1051 res->description = f_humstring (eh, c); break;
1053 for (n = c->child; n; n = n->next)
1055 if (is_numeric_tag(eh, n) != 713)
1057 (res->num_subAttributes)++;
1059 if (res->num_subAttributes)
1060 res->subAttributes =
1061 (Z_StringOrNumeric **)
1062 odr_malloc (eh->o, res->num_subAttributes
1063 * sizeof(*res->subAttributes));
1064 for (n = c->child; n; n = n->next)
1066 if (is_numeric_tag(eh, n) != 713)
1068 res->subAttributes[i++] = f_stringOrNumeric (eh, n);
1072 for (n = c->child; n; n = n->next)
1074 if (is_numeric_tag(eh, n) != 715)
1076 (res->num_superAttributes)++;
1078 if (res->num_superAttributes)
1079 res->superAttributes =
1080 (Z_StringOrNumeric **)
1081 odr_malloc (eh->o, res->num_superAttributes
1082 * sizeof(*res->superAttributes));
1083 for (n = c->child; n; n = n->next)
1085 if (is_numeric_tag(eh, n) != 715)
1087 res->superAttributes[i++] = f_stringOrNumeric (eh, n);
1091 res->partialSupport = odr_nullval ();
1098 Z_AttributeTypeDetails *f_attributeTypeDetails (ExpHandle *eh, data1_node *n)
1100 Z_AttributeTypeDetails *res = (Z_AttributeTypeDetails *)
1101 odr_malloc(eh->o, sizeof(*res));
1103 res->attributeType = 0;
1104 res->defaultIfOmitted = 0;
1105 res->num_attributeValues = 0;
1106 res->attributeValues = 0;
1107 for (c = n->child; c; c = c->next)
1110 switch (is_numeric_tag (eh, c))
1112 case 704: res->attributeType = f_integer (eh, c); break;
1114 res->defaultIfOmitted = f_omittedAttributeInterpretation (eh, c);
1117 for (n = c->child; n; n = n->next)
1119 if (is_numeric_tag(eh, n) != 709)
1121 (res->num_attributeValues)++;
1123 if (res->num_attributeValues)
1124 res->attributeValues =
1125 (Z_AttributeValue **)
1126 odr_malloc (eh->o, res->num_attributeValues
1127 * sizeof(*res->attributeValues));
1128 for (n = c->child; n; n = n->next)
1130 if (is_numeric_tag(eh, n) != 709)
1132 res->attributeValues[i++] = f_attributeValue (eh, n);
1140 Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n)
1142 Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
1143 odr_malloc(eh->o, sizeof(*res));
1146 res->attributeSet = 0;
1147 res->num_attributesByType = 0;
1148 res->attributesByType = 0;
1149 for (c = n->child; c; c = c->next)
1152 switch (is_numeric_tag (eh, c))
1154 case 1000: res->attributeSet = f_oid(eh, c, CLASS_ATTSET); break;
1156 for (n = c->child; n; n = n->next)
1158 if (is_numeric_tag(eh, n) != 703)
1160 (res->num_attributesByType)++;
1162 if (res->num_attributesByType)
1163 res->attributesByType =
1164 (Z_AttributeTypeDetails **)
1165 odr_malloc (eh->o, res->num_attributesByType
1166 * sizeof(*res->attributesByType));
1167 for (n = c->child; n; n = n->next)
1169 if (is_numeric_tag(eh, n) != 703)
1171 res->attributesByType[i++] = f_attributeTypeDetails (eh, n);
1179 Z_AttributeValueList *f_attributeValueList (ExpHandle *eh, data1_node *n)
1181 Z_AttributeValueList *res = (Z_AttributeValueList *)
1182 odr_malloc (eh->o, sizeof(*res));
1186 res->num_attributes = 0;
1187 res->attributes = 0;
1188 for (c = n->child; c; c = c->next)
1189 if (is_numeric_tag (eh, c) == 710)
1190 (res->num_attributes)++;
1191 if (res->num_attributes)
1193 res->attributes = (Z_StringOrNumeric **)
1194 odr_malloc (eh->o, res->num_attributes * sizeof(*res->attributes));
1196 for (c = n->child; c; c = c->next)
1197 if (is_numeric_tag(eh, c) == 710)
1198 res->attributes[i++] = f_stringOrNumeric (eh, c);
1202 Z_AttributeOccurrence *f_attributeOccurrence (ExpHandle *eh, data1_node *n)
1204 Z_AttributeOccurrence *res = (Z_AttributeOccurrence *)
1205 odr_malloc (eh->o, sizeof(*res));
1208 res->attributeSet = 0;
1209 res->attributeType = 0;
1210 res->mustBeSupplied = 0;
1211 res->which = Z_AttributeOcc_any_or_none;
1212 res->attributeValues.any_or_none = odr_nullval ();
1214 for (c = n->child; c; c = c->next)
1216 switch (is_numeric_tag (eh, c))
1219 res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
1221 res->attributeType = f_integer (eh, c); break;
1223 res->mustBeSupplied = odr_nullval (); break;
1225 res->which = Z_AttributeOcc_any_or_none;
1226 res->attributeValues.any_or_none = odr_nullval ();
1229 res->which = Z_AttributeOcc_specific;
1230 res->attributeValues.specific = f_attributeValueList (eh, c);
1237 Z_AttributeCombination *f_attributeCombination (ExpHandle *eh, data1_node *n)
1239 Z_AttributeCombination *res = (Z_AttributeCombination *)
1240 odr_malloc (eh->o, sizeof(*res));
1244 res->num_occurrences = 0;
1245 res->occurrences = 0;
1246 for (c = n->child; c; c = c->next)
1247 if (is_numeric_tag (eh, c) == 719)
1248 (res->num_occurrences)++;
1249 if (res->num_occurrences)
1251 res->occurrences = (Z_AttributeOccurrence **)
1252 odr_malloc (eh->o, res->num_occurrences * sizeof(*res->occurrences));
1254 for (c = n->child; c; c = c->next)
1255 if (is_numeric_tag(eh, c) == 719)
1256 res->occurrences[i++] = f_attributeOccurrence (eh, c);
1257 assert (res->num_occurrences);
1261 Z_AttributeCombinations *f_attributeCombinations (ExpHandle *eh, data1_node *n)
1263 Z_AttributeCombinations *res = (Z_AttributeCombinations *)
1264 odr_malloc (eh->o, sizeof(*res));
1266 res->defaultAttributeSet = 0;
1267 res->num_legalCombinations = 0;
1268 res->legalCombinations = 0;
1270 for (c = n->child; c; c = c->next)
1273 switch (is_numeric_tag (eh, c))
1276 res->defaultAttributeSet = f_oid (eh, c, CLASS_ATTSET);
1279 for (n = c->child; n; n = n->next)
1281 if (is_numeric_tag(eh, n) != 718)
1283 (res->num_legalCombinations)++;
1285 if (res->num_legalCombinations)
1286 res->legalCombinations =
1287 (Z_AttributeCombination **)
1288 odr_malloc (eh->o, res->num_legalCombinations
1289 * sizeof(*res->legalCombinations));
1290 for (n = c->child; n; n = n->next)
1292 if (is_numeric_tag(eh, n) != 718)
1294 res->legalCombinations[i++] = f_attributeCombination (eh, n);
1299 assert (res->num_legalCombinations);
1303 Z_AttributeDetails *f_attributeDetails (ExpHandle *eh, data1_node *n)
1305 Z_AttributeDetails *res = (Z_AttributeDetails *)
1306 odr_malloc(eh->o, sizeof(*res));
1309 res->commonInfo = 0;
1310 res->databaseName = 0;
1311 res->num_attributesBySet = 0;
1312 res->attributesBySet = NULL;
1313 res->attributeCombinations = NULL;
1315 for (c = n->child; c; c = c->next)
1318 switch (is_numeric_tag (eh, c))
1320 case 600: res->commonInfo = f_commonInfo(eh, c); break;
1321 case 102: res->databaseName = f_string (eh, c); break;
1323 for (n = c->child; n; n = n->next)
1325 if (is_numeric_tag(eh, n) != 701)
1327 (res->num_attributesBySet)++;
1329 if (res->num_attributesBySet)
1330 res->attributesBySet =
1331 (Z_AttributeSetDetails **)
1332 odr_malloc (eh->o, res->num_attributesBySet
1333 * sizeof(*res->attributesBySet));
1334 for (n = c->child; n; n = n->next)
1336 if (is_numeric_tag(eh, n) != 701)
1338 res->attributesBySet[i++] = f_attributeSetDetails (eh, n);
1342 res->attributeCombinations = f_attributeCombinations (eh, c);
1349 Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
1353 Z_ExplainRecord *res = (Z_ExplainRecord *)odr_malloc(o, sizeof(*res));
1358 eh.false_value = (int *)odr_malloc(eh.o, sizeof(eh.false_value));
1359 *eh.false_value = 0;
1360 eh.true_value = (int *)odr_malloc(eh.o, sizeof(eh.true_value));
1363 assert(n->which == DATA1N_root);
1364 if (strcmp(n->u.root.type, "explain"))
1366 yaz_log(YLOG_WARN, "Attempt to convert a non-Explain record");
1369 for (n = n->child; n; n = n->next)
1371 switch (is_numeric_tag (&eh, n))
1374 res->which = Z_Explain_categoryList;
1375 if (!(res->u.categoryList = f_categoryList(&eh, n)))
1379 res->which = Z_Explain_targetInfo;
1380 if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
1384 res->which = Z_Explain_databaseInfo;
1385 if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
1389 res->which = Z_Explain_attributeSetInfo;
1390 if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
1394 res->which = Z_Explain_attributeDetails;
1395 if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
1400 yaz_log(YLOG_WARN, "No category in Explain record");
1406 * c-file-style: "Stroustrup"
1407 * indent-tabs-mode: nil
1409 * vim: shiftwidth=4 tabstop=8 expandtab