1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 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
29 #include <yaz/proto.h>
30 #include <yaz/oid_db.h>
31 #include <yaz/snprintf.h>
32 #include <idzebra/data1.h>
43 static int is_numeric_tag (ExpHandle *eh, data1_node *c)
45 if (!c || c->which != DATA1N_tag)
47 if (!c->u.tag.element)
49 yaz_log(YLOG_WARN, "Tag %s is local", c->u.tag.tag);
52 if (c->u.tag.element->tag->which != DATA1T_numeric)
54 yaz_log(YLOG_WARN, "Tag %s is not numeric", c->u.tag.tag);
57 if (eh->select && !c->u.tag.node_selected)
59 return c->u.tag.element->tag->value.numeric;
62 static int is_data_tag (ExpHandle *eh, data1_node *c)
64 if (!c || c->which != DATA1N_data)
66 if (eh->select && !c->u.tag.node_selected)
71 static Odr_int *f_integer(ExpHandle *eh, data1_node *c)
76 if (!is_data_tag (eh, c) || c->u.data.len >= sizeof(intbuf))
78 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
79 return odr_intdup(eh->o, atoi(intbuf));
82 static char *f_string(ExpHandle *eh, data1_node *c)
87 if (!is_data_tag (eh, c))
89 r = (char *)odr_malloc(eh->o, c->u.data.len+1);
90 memcpy(r, c->u.data.data, c->u.data.len);
91 r[c->u.data.len] = '\0';
95 static bool_t *f_bool(ExpHandle *eh, data1_node *c)
101 if (!is_data_tag (eh, c) || c->u.data.len > 63)
103 tf = (int *)odr_malloc (eh->o, sizeof(*tf));
104 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
109 static Odr_oid *f_oid(ExpHandle *eh, data1_node *c, oid_class oclass)
114 if (!is_data_tag (eh, c) || c->u.data.len > 63)
116 yaz_snprintf(oidstr, sizeof(oidstr)-1,
117 "%.*s", c->u.data.len, c->u.data.data);
119 return yaz_string_to_oid_odr(yaz_oid_std(),
120 CLASS_GENERAL, oidstr, eh->o);
123 static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c)
129 static Z_HumanString *f_humstring(ExpHandle *eh, data1_node *c)
132 Z_HumanStringUnit *u;
135 if (!is_data_tag (eh, c))
137 r = (Z_HumanString *)odr_malloc(eh->o, sizeof(*r));
139 r->strings = (Z_HumanStringUnit **)odr_malloc(eh->o, sizeof(Z_HumanStringUnit*));
140 r->strings[0] = u = (Z_HumanStringUnit *)odr_malloc(eh->o, sizeof(*u));
142 u->text = (char *)odr_malloc(eh->o, c->u.data.len+1);
143 memcpy(u->text, c->u.data.data, c->u.data.len);
144 u->text[c->u.data.len] = '\0';
148 static Z_CommonInfo *f_commonInfo(ExpHandle *eh, data1_node *n)
150 Z_CommonInfo *res = (Z_CommonInfo *)odr_malloc(eh->o, sizeof(*res));
154 res->dateChanged = 0;
156 res->humanStringLanguage = 0;
159 for (c = n->child; c; c = c->next)
161 switch (is_numeric_tag (eh, c))
163 case 601: res->dateAdded = f_string(eh, c); break;
164 case 602: res->dateChanged = f_string(eh, c); break;
165 case 603: res->expiry = f_string(eh, c); break;
166 case 604: res->humanStringLanguage = f_string(eh, c); break;
172 Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num, oid_class oclass)
179 for (c = n->child ; c; c = c->next)
180 if (is_numeric_tag (eh, c) == 1000)
184 res = (Odr_oid **)odr_malloc (eh->o, sizeof(*res) * (*num));
185 for (c = n->child, i = 0 ; c; c = c->next)
186 if (is_numeric_tag (eh, c) == 1000)
187 res[i++] = f_oid (eh, c, oclass);
191 char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
198 for (c = n->child ; c; c = c->next)
200 if (is_numeric_tag (eh, c) != 1001)
206 res = (char **)odr_malloc (eh->o, sizeof(*res) * (*num));
207 for (c = n->child, i = 0 ; c; c = c->next)
209 if (is_numeric_tag (eh, c) != 1001)
211 res[i++] = f_string (eh, c);
216 Z_ProximitySupport *f_proximitySupport (ExpHandle *eh, data1_node *n)
218 Z_ProximitySupport *res = (Z_ProximitySupport *)
219 odr_malloc (eh->o, sizeof(*res));
220 res->anySupport = eh->false_value;
221 res->num_unitsSupported = 0;
222 res->unitsSupported = 0;
226 Z_RpnCapabilities *f_rpnCapabilities (ExpHandle *eh, data1_node *n)
228 Z_RpnCapabilities *res = (Z_RpnCapabilities *)
229 odr_malloc (eh->o, sizeof(*res));
232 res->num_operators = 0;
233 res->operators = NULL;
234 res->resultSetAsOperandSupported = eh->false_value;
235 res->restrictionOperandSupported = eh->false_value;
236 res->proximity = NULL;
238 for (c = n->child; c; c = c->next)
241 switch (is_numeric_tag(eh, c))
244 for (n = c->child; n; n = n->next)
246 if (is_numeric_tag(eh, n) != 551)
248 (res->num_operators)++;
250 if (res->num_operators)
251 res->operators = (Odr_int **)
252 odr_malloc (eh->o, res->num_operators
253 * sizeof(*res->operators));
254 for (n = c->child; n; n = n->next)
256 if (is_numeric_tag(eh, n) != 551)
258 res->operators[i++] = f_integer (eh, n);
262 res->resultSetAsOperandSupported = f_bool (eh, c);
265 res->restrictionOperandSupported = f_bool (eh, c);
268 res->proximity = f_proximitySupport (eh, c);
275 Z_QueryTypeDetails *f_queryTypeDetails (ExpHandle *eh, data1_node *n)
277 Z_QueryTypeDetails *res = (Z_QueryTypeDetails *)
278 odr_malloc(eh->o, sizeof(*res));
281 res->which = Z_QueryTypeDetails_rpn;
283 for (c = n->child; c; c = c->next)
285 switch (is_numeric_tag(eh, c))
288 res->which = Z_QueryTypeDetails_rpn;
289 res->u.rpn = f_rpnCapabilities (eh, c);
300 static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n)
302 Z_AccessInfo *res = (Z_AccessInfo *)odr_malloc(eh->o, sizeof(*res));
305 res->num_queryTypesSupported = 0;
306 res->queryTypesSupported = 0;
307 res->num_diagnosticsSets = 0;
308 res->diagnosticsSets = 0;
309 res->num_attributeSetIds = 0;
310 res->attributeSetIds = 0;
311 res->num_schemas = 0;
313 res->num_recordSyntaxes = 0;
314 res->recordSyntaxes = 0;
315 res->num_resourceChallenges = 0;
316 res->resourceChallenges = 0;
317 res->restrictedAccess = 0;
319 res->num_variantSets = 0;
320 res->variantSets = 0;
321 res->num_elementSetNames = 0;
322 res->elementSetNames = 0;
323 res->num_unitSystems = 0;
324 res->unitSystems = 0;
326 for (c = n->child; c; c = c->next)
329 switch (is_numeric_tag (eh, c))
332 for (n = c->child; n; n = n->next)
334 if (is_numeric_tag(eh, n) != 518)
336 (res->num_queryTypesSupported)++;
338 if (res->num_queryTypesSupported)
339 res->queryTypesSupported =
340 (Z_QueryTypeDetails **)
341 odr_malloc (eh->o, res->num_queryTypesSupported
342 * sizeof(*res->queryTypesSupported));
343 for (n = c->child; n; n = n->next)
345 if (is_numeric_tag(eh, n) != 518)
347 res->queryTypesSupported[i++] = f_queryTypeDetails (eh, n);
351 res->diagnosticsSets =
352 f_oid_seq(eh, c, &res->num_diagnosticsSets, CLASS_DIAGSET);
355 res->attributeSetIds =
356 f_oid_seq(eh, c, &res->num_attributeSetIds, CLASS_ATTSET);
360 f_oid_seq(eh, c, &res->num_schemas, CLASS_SCHEMA);
363 res->recordSyntaxes =
364 f_oid_seq (eh, c, &res->num_recordSyntaxes, CLASS_RECSYN);
367 res->resourceChallenges =
368 f_oid_seq (eh, c, &res->num_resourceChallenges, CLASS_RESFORM);
370 case 513: res->restrictedAccess = NULL; break; /* fix */
371 case 514: res->costInfo = NULL; break; /* fix */
374 f_oid_seq (eh, c, &res->num_variantSets, CLASS_VARSET);
377 res->elementSetNames =
378 f_string_seq (eh, c, &res->num_elementSetNames);
381 res->unitSystems = f_string_seq (eh, c, &res->num_unitSystems);
388 static Odr_int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
394 if (!is_numeric_tag (eh, c))
396 if (c->u.tag.element->tag->value.numeric == 210)
397 *wp = Z_DatabaseInfo_actualNumber;
398 else if (c->u.tag.element->tag->value.numeric == 211)
399 *wp = Z_DatabaseInfo_approxNumber;
402 if (!c->child || c->child->which != DATA1N_data ||
403 c->child->u.data.len >= sizeof(intbuf))
405 sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
406 return odr_intdup(eh->o, atoi(intbuf));
409 static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
411 Z_ContactInfo *res = (Z_ContactInfo *)
412 odr_malloc (eh->o, sizeof(*res));
416 res->description = 0;
421 for (c = n->child; c; c = c->next)
423 switch (is_numeric_tag (eh, c))
425 case 102: res->name = f_string (eh, c); break;
426 case 113: res->description = f_humstring (eh, c); break;
427 case 127: res->address = f_humstring (eh, c); break;
428 case 128: res->email = f_string (eh, c); break;
429 case 129: res->phone = f_string (eh, c); break;
435 static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n)
441 for (c = n->child; c; c = c->next)
443 if (!is_numeric_tag (eh, c) != 102)
450 res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
452 res->num_databases = i;
453 res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
455 for (c = n->child; c; c = c->next)
457 if (!is_numeric_tag (eh, c) != 102)
459 res->databases[i++] = f_string (eh, c);
464 static Z_NetworkAddressIA *f_networkAddressIA(ExpHandle *eh, data1_node *n)
466 Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
467 odr_malloc (eh->o, sizeof(*res));
470 res->hostAddress = 0;
473 for (c = n->child; c; c = c->next)
475 switch (is_numeric_tag (eh, c))
477 case 121: res->hostAddress = f_string (eh, c); break;
478 case 122: res->port = f_integer (eh, c); break;
484 static Z_NetworkAddressOther *f_networkAddressOther(ExpHandle *eh,
487 Z_NetworkAddressOther *res = (Z_NetworkAddressOther *)
488 odr_malloc (eh->o, sizeof(*res));
494 for (c = n->child; c; c = c->next)
496 switch (is_numeric_tag (eh, c))
498 case 124: res->type = f_string (eh, c); break;
499 case 121: res->address = f_string (eh, c); break;
505 static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
508 Z_NetworkAddress **res = NULL;
513 for (c = n->child; c; c = c->next)
515 switch (is_numeric_tag (eh, c))
525 res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
527 for (c = n->child; c; c = c->next)
529 switch (is_numeric_tag (eh, c))
532 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
533 res[i]->which = Z_NetworkAddress_iA;
534 res[i]->u.internetAddress = f_networkAddressIA(eh, c);
538 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
539 res[i]->which = Z_NetworkAddress_other;
540 res[i]->u.other = f_networkAddressOther(eh, c);
548 static Z_CategoryInfo *f_categoryInfo(ExpHandle *eh, data1_node *n)
550 Z_CategoryInfo *res = (Z_CategoryInfo *)odr_malloc(eh->o, sizeof(*res));
554 res->originalCategory = 0;
555 res->description = 0;
557 for (c = n->child; c; c = c->next)
559 switch (is_numeric_tag (eh, c))
561 case 102: res->category = f_string(eh, c); break;
562 case 302: res->originalCategory = f_string(eh, c); break;
563 case 113: res->description = f_humstring(eh, c); break;
564 case 303: res->asn1Module = f_string (eh, c); break;
570 static Z_CategoryList *f_categoryList(ExpHandle *eh, data1_node *n)
572 Z_CategoryList *res = (Z_CategoryList *)odr_malloc(eh->o, sizeof(*res));
576 res->num_categories = 0;
577 res->categories = NULL;
579 for (c = n->child; c; c = c->next)
583 switch (is_numeric_tag (eh, c))
585 case 600: res->commonInfo = f_commonInfo(eh, c); break;
587 for (n = c->child; n; n = n->next)
589 if (is_numeric_tag(eh, n) != 301)
591 (res->num_categories)++;
593 if (res->num_categories)
595 (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
596 * sizeof(*res->categories));
597 for (n = c->child; n; n = n->next)
599 if (is_numeric_tag(eh, n) != 301)
601 res->categories[i++] = f_categoryInfo (eh, n);
606 assert (res->num_categories && res->categories);
610 static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n)
612 Z_TargetInfo *res = (Z_TargetInfo *)odr_malloc(eh->o, sizeof(*res));
619 res->namedResultSets = 0;
620 res->multipleDBsearch = 0;
621 res->maxResultSets = 0;
622 res->maxResultSize = 0;
624 res->timeoutInterval = 0;
625 res->welcomeMessage = 0;
626 res->contactInfo = 0;
627 res->description = 0;
628 res->num_nicknames = 0;
631 res->paymentAddr = 0;
633 res->num_dbCombinations = 0;
634 res->dbCombinations = 0;
635 res->num_addresses = 0;
637 res->num_languages = 0;
638 res->languages = NULL;
639 res->commonAccessInfo = 0;
641 for (c = n->child; c; c = c->next)
645 switch (is_numeric_tag (eh, c))
647 case 600: res->commonInfo = f_commonInfo(eh, c); break;
648 case 102: res->name = f_string(eh, c); break;
649 case 103: res->recentNews = f_humstring(eh, c); break;
650 case 104: res->icon = NULL; break; /* fix */
651 case 105: res->namedResultSets = f_bool(eh, c); break;
652 case 106: res->multipleDBsearch = f_bool(eh, c); break;
653 case 107: res->maxResultSets = f_integer(eh, c); break;
654 case 108: res->maxResultSize = f_integer(eh, c); break;
655 case 109: res->maxTerms = f_integer(eh, c); break;
656 case 110: res->timeoutInterval = f_intunit(eh, c); break;
657 case 111: res->welcomeMessage = f_humstring(eh, c); break;
658 case 112: res->contactInfo = f_contactInfo(eh, c); break;
659 case 113: res->description = f_humstring(eh, c); break;
661 res->num_nicknames = 0;
662 for (n = c->child; n; n = n->next)
664 if (is_numeric_tag(eh, n) != 102)
666 (res->num_nicknames)++;
668 if (res->num_nicknames)
670 (char **)odr_malloc (eh->o, res->num_nicknames
671 * sizeof(*res->nicknames));
672 for (n = c->child; n; n = n->next)
674 if (is_numeric_tag(eh, n) != 102)
676 res->nicknames[i++] = f_string (eh, n);
679 case 115: res->usageRest = f_humstring(eh, c); break;
680 case 116: res->paymentAddr = f_humstring(eh, c); break;
681 case 117: res->hours = f_humstring(eh, c); break;
683 res->num_dbCombinations = 0;
684 for (n = c->child; n; n = n->next)
686 if (!is_numeric_tag(eh, n) != 605)
688 (res->num_dbCombinations)++;
690 if (res->num_dbCombinations)
691 res->dbCombinations =
692 (Z_DatabaseList **)odr_malloc (eh->o, res->num_dbCombinations
693 * sizeof(*res->dbCombinations));
694 for (n = c->child; n; n = n->next)
696 if (!is_numeric_tag(eh, n) != 605)
698 res->dbCombinations[i++] = f_databaseList (eh, n);
703 f_networkAddresses (eh, c, &res->num_addresses);
706 res->num_languages = 0;
707 for (n = c->child; n; n = n->next)
709 if (!is_numeric_tag(eh, n) != 126)
711 (res->num_languages)++;
713 if (res->num_languages)
714 res->languages = (char **)
715 odr_malloc (eh->o, res->num_languages *
716 sizeof(*res->languages));
717 for (n = c->child; n; n = n->next)
719 if (!is_numeric_tag(eh, n) != 126)
721 res->languages[i++] = f_string (eh, n);
724 case 500: res->commonAccessInfo = f_accessInfo(eh, c); break;
727 if (!res->namedResultSets)
728 res->namedResultSets = eh->false_value;
729 if (!res->multipleDBsearch)
730 res->multipleDBsearch = eh->false_value;
734 static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n)
736 Z_DatabaseInfo *res = (Z_DatabaseInfo *)odr_malloc(eh->o, sizeof(*res));
741 res->explainDatabase = 0;
742 res->num_nicknames = 0;
747 res->titleString = 0;
748 res->num_keywords = 0;
750 res->description = 0;
751 res->associatedDbs = 0;
753 res->disclaimers = 0;
755 res->u.actualNumber = 0;
756 res->defaultOrder = 0;
757 res->avRecordSize = 0;
758 res->maxRecordSize = 0;
762 res->updateInterval = 0;
764 res->proprietary = 0;
765 res->copyrightText = 0;
766 res->copyrightNotice = 0;
767 res->producerContactInfo = 0;
768 res->supplierContactInfo = 0;
769 res->submissionContactInfo = 0;
772 for (c = n->child; c; c = c->next)
776 switch (is_numeric_tag (eh, c))
778 case 600: res->commonInfo = f_commonInfo(eh, c); break;
779 case 102: res->name = f_string(eh, c); break;
780 case 226: res->explainDatabase = odr_nullval(); break;
782 res->num_nicknames = 0;
783 for (n = c->child; n; n = n->next)
785 if (!is_numeric_tag(eh, n) ||
786 n->u.tag.element->tag->value.numeric != 102)
788 (res->num_nicknames)++;
790 if (res->num_nicknames)
792 (char **)odr_malloc (eh->o, res->num_nicknames
793 * sizeof(*res->nicknames));
794 for (n = c->child; n; n = n->next)
796 if (!is_numeric_tag(eh, n) ||
797 n->u.tag.element->tag->value.numeric != 102)
799 res->nicknames[i++] = f_string (eh, n);
802 case 104: res->icon = 0; break; /* fix */
803 case 201: res->userFee = f_bool(eh, c); break;
804 case 202: res->available = f_bool(eh, c); break;
805 case 203: res->titleString = f_humstring(eh, c); break;
807 res->num_keywords = 0;
808 for (n = c->child; n; n = n->next)
810 if (!is_numeric_tag(eh, n) != 1000)
812 (res->num_keywords)++;
814 if (res->num_keywords)
816 (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
817 * sizeof(*res->keywords));
818 for (n = c->child; n; n = n->next)
820 if (!is_numeric_tag(eh, n) != 1000)
822 res->keywords[i++] = f_humstring (eh, n);
825 case 113: res->description = f_humstring(eh, c); break;
827 res->associatedDbs = f_databaseList (eh, c);
830 res->subDbs = f_databaseList (eh, c);
832 case 207: res->disclaimers = f_humstring(eh, c); break;
833 case 103: res->news = f_humstring(eh, c); break;
834 case 209: res->u.actualNumber =
835 f_recordCount(eh, c, &res->which); break;
836 case 212: res->defaultOrder = f_humstring(eh, c); break;
837 case 213: res->avRecordSize = f_integer(eh, c); break;
838 case 214: res->maxRecordSize = f_integer(eh, c); break;
839 case 215: res->hours = f_humstring(eh, c); break;
840 case 216: res->bestTime = f_humstring(eh, c); break;
841 case 217: res->lastUpdate = f_string(eh, c); break;
842 case 218: res->updateInterval = f_intunit(eh, c); break;
843 case 219: res->coverage = f_humstring(eh, c); break;
844 case 220: res->proprietary = f_bool(eh, c); break;
845 case 221: res->copyrightText = f_humstring(eh, c); break;
846 case 222: res->copyrightNotice = f_humstring(eh, c); break;
847 case 223: res->producerContactInfo = f_contactInfo(eh, c); break;
848 case 224: res->supplierContactInfo = f_contactInfo(eh, c); break;
849 case 225: res->submissionContactInfo = f_contactInfo(eh, c); break;
850 case 500: res->accessInfo = f_accessInfo(eh, c); break;
854 res->userFee = eh->false_value;
856 res->available = eh->true_value;
860 Z_StringOrNumeric *f_stringOrNumeric (ExpHandle *eh, data1_node *n)
862 Z_StringOrNumeric *res = (Z_StringOrNumeric *)
863 odr_malloc (eh->o, sizeof(*res));
865 for (c = n->child; c; c = c->next)
867 switch (is_numeric_tag (eh, c))
870 res->which = Z_StringOrNumeric_string;
871 res->u.string = f_string (eh, c);
874 res->which = Z_StringOrNumeric_numeric;
875 res->u.numeric = f_integer (eh, c);
882 Z_AttributeDescription *f_attributeDescription (
883 ExpHandle *eh, data1_node *n)
885 Z_AttributeDescription *res = (Z_AttributeDescription *)
886 odr_malloc(eh->o, sizeof(*res));
891 res->description = 0;
892 res->attributeValue = 0;
893 res->num_equivalentAttributes = 0;
894 res->equivalentAttributes = 0;
896 for (c = n->child; c; c = c->next)
898 switch (is_numeric_tag (eh, c))
900 case 102: res->name = f_string (eh, c); break;
901 case 113: res->description = f_humstring (eh, c); break;
902 case 710: res->attributeValue = f_stringOrNumeric (eh, c); break;
903 case 752: (res->num_equivalentAttributes++); break;
906 if (res->num_equivalentAttributes)
907 res->equivalentAttributes = (Z_StringOrNumeric **)
908 odr_malloc (eh->o, sizeof(*res->equivalentAttributes) *
909 res->num_equivalentAttributes);
910 for (c = n->child; c; c = c->next)
911 if (is_numeric_tag (eh, c) == 752)
912 res->equivalentAttributes[i++] = f_stringOrNumeric (eh, c);
916 Z_AttributeType *f_attributeType (ExpHandle *eh, data1_node *n)
918 Z_AttributeType *res = (Z_AttributeType *)
919 odr_malloc(eh->o, sizeof(*res));
923 res->description = 0;
924 res->attributeType = 0;
925 res->num_attributeValues = 0;
926 res->attributeValues = 0;
928 for (c = n->child; c; c = c->next)
931 switch (is_numeric_tag (eh, c))
933 case 102: res->name = f_string (eh, c); break;
934 case 113: res->description = f_humstring (eh, c); break;
935 case 704: res->attributeType = f_integer (eh, c); break;
937 for (n = c->child; n; n = n->next)
939 if (is_numeric_tag(eh, n) != 709)
941 (res->num_attributeValues)++;
943 if (res->num_attributeValues)
944 res->attributeValues = (Z_AttributeDescription **)
945 odr_malloc (eh->o, res->num_attributeValues
946 * sizeof(*res->attributeValues));
947 for (n = c->child; n; n = n->next)
949 if (is_numeric_tag(eh, n) != 709)
951 res->attributeValues[i++] = f_attributeDescription (eh, n);
959 Z_AttributeSetInfo *f_attributeSetInfo (ExpHandle *eh, data1_node *n)
961 Z_AttributeSetInfo *res = (Z_AttributeSetInfo *)
962 odr_malloc(eh->o, sizeof(*res));
966 res->attributeSet = 0;
968 res->num_attributes = 0;
970 res->description = 0;
971 for (c = n->child; c; c = c->next)
974 switch (is_numeric_tag (eh, c))
976 case 600: res->commonInfo = f_commonInfo (eh, c); break;
977 case 1000: res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
978 case 102: res->name = f_string (eh, c); break;
980 for (n = c->child; n; n = n->next)
982 if (is_numeric_tag(eh, n) != 751)
984 (res->num_attributes)++;
986 if (res->num_attributes)
987 res->attributes = (Z_AttributeType **)
988 odr_malloc (eh->o, res->num_attributes
989 * sizeof(*res->attributes));
990 for (n = c->child; n; n = n->next)
992 if (is_numeric_tag(eh, n) != 751)
994 res->attributes[i++] = f_attributeType (eh, n);
997 case 113: res->description = f_humstring (eh, c); break;
1003 Z_OmittedAttributeInterpretation *f_omittedAttributeInterpretation (
1004 ExpHandle *eh, data1_node *n)
1006 Z_OmittedAttributeInterpretation *res = (Z_OmittedAttributeInterpretation*)
1007 odr_malloc (eh->o, sizeof(*res));
1010 res->defaultValue = 0;
1011 res->defaultDescription = 0;
1012 for (c = n->child; c; c = c->next)
1014 switch (is_numeric_tag (eh, c))
1017 res->defaultValue = f_stringOrNumeric (eh, c);
1020 res->defaultDescription = f_humstring(eh, c);
1027 Z_AttributeValue *f_attributeValue (ExpHandle *eh, data1_node *n)
1029 Z_AttributeValue *res = (Z_AttributeValue *)
1030 odr_malloc (eh->o, sizeof(*res));
1034 res->description = 0;
1035 res->num_subAttributes = 0;
1036 res->subAttributes = 0;
1037 res->num_superAttributes = 0;
1038 res->superAttributes = 0;
1039 res->partialSupport = 0;
1040 for (c = n->child; c; c = c->next)
1043 switch (is_numeric_tag (eh, c))
1046 res->value = f_stringOrNumeric (eh, c); break;
1048 res->description = f_humstring (eh, c); break;
1050 for (n = c->child; n; n = n->next)
1052 if (is_numeric_tag(eh, n) != 713)
1054 (res->num_subAttributes)++;
1056 if (res->num_subAttributes)
1057 res->subAttributes =
1058 (Z_StringOrNumeric **)
1059 odr_malloc (eh->o, res->num_subAttributes
1060 * sizeof(*res->subAttributes));
1061 for (n = c->child; n; n = n->next)
1063 if (is_numeric_tag(eh, n) != 713)
1065 res->subAttributes[i++] = f_stringOrNumeric (eh, n);
1069 for (n = c->child; n; n = n->next)
1071 if (is_numeric_tag(eh, n) != 715)
1073 (res->num_superAttributes)++;
1075 if (res->num_superAttributes)
1076 res->superAttributes =
1077 (Z_StringOrNumeric **)
1078 odr_malloc (eh->o, res->num_superAttributes
1079 * sizeof(*res->superAttributes));
1080 for (n = c->child; n; n = n->next)
1082 if (is_numeric_tag(eh, n) != 715)
1084 res->superAttributes[i++] = f_stringOrNumeric (eh, n);
1088 res->partialSupport = odr_nullval ();
1095 Z_AttributeTypeDetails *f_attributeTypeDetails (ExpHandle *eh, data1_node *n)
1097 Z_AttributeTypeDetails *res = (Z_AttributeTypeDetails *)
1098 odr_malloc(eh->o, sizeof(*res));
1100 res->attributeType = 0;
1101 res->defaultIfOmitted = 0;
1102 res->num_attributeValues = 0;
1103 res->attributeValues = 0;
1104 for (c = n->child; c; c = c->next)
1107 switch (is_numeric_tag (eh, c))
1109 case 704: res->attributeType = f_integer (eh, c); break;
1111 res->defaultIfOmitted = f_omittedAttributeInterpretation (eh, c);
1114 for (n = c->child; n; n = n->next)
1116 if (is_numeric_tag(eh, n) != 709)
1118 (res->num_attributeValues)++;
1120 if (res->num_attributeValues)
1121 res->attributeValues =
1122 (Z_AttributeValue **)
1123 odr_malloc (eh->o, res->num_attributeValues
1124 * sizeof(*res->attributeValues));
1125 for (n = c->child; n; n = n->next)
1127 if (is_numeric_tag(eh, n) != 709)
1129 res->attributeValues[i++] = f_attributeValue (eh, n);
1137 Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n)
1139 Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
1140 odr_malloc(eh->o, sizeof(*res));
1143 res->attributeSet = 0;
1144 res->num_attributesByType = 0;
1145 res->attributesByType = 0;
1146 for (c = n->child; c; c = c->next)
1149 switch (is_numeric_tag (eh, c))
1151 case 1000: res->attributeSet = f_oid(eh, c, CLASS_ATTSET); break;
1153 for (n = c->child; n; n = n->next)
1155 if (is_numeric_tag(eh, n) != 703)
1157 (res->num_attributesByType)++;
1159 if (res->num_attributesByType)
1160 res->attributesByType =
1161 (Z_AttributeTypeDetails **)
1162 odr_malloc (eh->o, res->num_attributesByType
1163 * sizeof(*res->attributesByType));
1164 for (n = c->child; n; n = n->next)
1166 if (is_numeric_tag(eh, n) != 703)
1168 res->attributesByType[i++] = f_attributeTypeDetails (eh, n);
1176 Z_AttributeValueList *f_attributeValueList (ExpHandle *eh, data1_node *n)
1178 Z_AttributeValueList *res = (Z_AttributeValueList *)
1179 odr_malloc (eh->o, sizeof(*res));
1183 res->num_attributes = 0;
1184 res->attributes = 0;
1185 for (c = n->child; c; c = c->next)
1186 if (is_numeric_tag (eh, c) == 710)
1187 (res->num_attributes)++;
1188 if (res->num_attributes)
1190 res->attributes = (Z_StringOrNumeric **)
1191 odr_malloc (eh->o, res->num_attributes * sizeof(*res->attributes));
1193 for (c = n->child; c; c = c->next)
1194 if (is_numeric_tag(eh, c) == 710)
1195 res->attributes[i++] = f_stringOrNumeric (eh, c);
1199 Z_AttributeOccurrence *f_attributeOccurrence (ExpHandle *eh, data1_node *n)
1201 Z_AttributeOccurrence *res = (Z_AttributeOccurrence *)
1202 odr_malloc (eh->o, sizeof(*res));
1205 res->attributeSet = 0;
1206 res->attributeType = 0;
1207 res->mustBeSupplied = 0;
1208 res->which = Z_AttributeOcc_any_or_none;
1209 res->attributeValues.any_or_none = odr_nullval ();
1211 for (c = n->child; c; c = c->next)
1213 switch (is_numeric_tag (eh, c))
1216 res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
1218 res->attributeType = f_integer (eh, c); break;
1220 res->mustBeSupplied = odr_nullval (); break;
1222 res->which = Z_AttributeOcc_any_or_none;
1223 res->attributeValues.any_or_none = odr_nullval ();
1226 res->which = Z_AttributeOcc_specific;
1227 res->attributeValues.specific = f_attributeValueList (eh, c);
1234 Z_AttributeCombination *f_attributeCombination (ExpHandle *eh, data1_node *n)
1236 Z_AttributeCombination *res = (Z_AttributeCombination *)
1237 odr_malloc (eh->o, sizeof(*res));
1241 res->num_occurrences = 0;
1242 res->occurrences = 0;
1243 for (c = n->child; c; c = c->next)
1244 if (is_numeric_tag (eh, c) == 719)
1245 (res->num_occurrences)++;
1246 if (res->num_occurrences)
1248 res->occurrences = (Z_AttributeOccurrence **)
1249 odr_malloc (eh->o, res->num_occurrences * sizeof(*res->occurrences));
1251 for (c = n->child; c; c = c->next)
1252 if (is_numeric_tag(eh, c) == 719)
1253 res->occurrences[i++] = f_attributeOccurrence (eh, c);
1254 assert (res->num_occurrences);
1258 Z_AttributeCombinations *f_attributeCombinations (ExpHandle *eh, data1_node *n)
1260 Z_AttributeCombinations *res = (Z_AttributeCombinations *)
1261 odr_malloc (eh->o, sizeof(*res));
1263 res->defaultAttributeSet = 0;
1264 res->num_legalCombinations = 0;
1265 res->legalCombinations = 0;
1267 for (c = n->child; c; c = c->next)
1270 switch (is_numeric_tag (eh, c))
1273 res->defaultAttributeSet = f_oid (eh, c, CLASS_ATTSET);
1276 for (n = c->child; n; n = n->next)
1278 if (is_numeric_tag(eh, n) != 718)
1280 (res->num_legalCombinations)++;
1282 if (res->num_legalCombinations)
1283 res->legalCombinations =
1284 (Z_AttributeCombination **)
1285 odr_malloc (eh->o, res->num_legalCombinations
1286 * sizeof(*res->legalCombinations));
1287 for (n = c->child; n; n = n->next)
1289 if (is_numeric_tag(eh, n) != 718)
1291 res->legalCombinations[i++] = f_attributeCombination (eh, n);
1296 assert (res->num_legalCombinations);
1300 Z_AttributeDetails *f_attributeDetails (ExpHandle *eh, data1_node *n)
1302 Z_AttributeDetails *res = (Z_AttributeDetails *)
1303 odr_malloc(eh->o, sizeof(*res));
1306 res->commonInfo = 0;
1307 res->databaseName = 0;
1308 res->num_attributesBySet = 0;
1309 res->attributesBySet = NULL;
1310 res->attributeCombinations = NULL;
1312 for (c = n->child; c; c = c->next)
1315 switch (is_numeric_tag (eh, c))
1317 case 600: res->commonInfo = f_commonInfo(eh, c); break;
1318 case 102: res->databaseName = f_string (eh, c); break;
1320 for (n = c->child; n; n = n->next)
1322 if (is_numeric_tag(eh, n) != 701)
1324 (res->num_attributesBySet)++;
1326 if (res->num_attributesBySet)
1327 res->attributesBySet =
1328 (Z_AttributeSetDetails **)
1329 odr_malloc (eh->o, res->num_attributesBySet
1330 * sizeof(*res->attributesBySet));
1331 for (n = c->child; n; n = n->next)
1333 if (is_numeric_tag(eh, n) != 701)
1335 res->attributesBySet[i++] = f_attributeSetDetails (eh, n);
1339 res->attributeCombinations = f_attributeCombinations (eh, c);
1346 Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
1350 Z_ExplainRecord *res = (Z_ExplainRecord *)odr_malloc(o, sizeof(*res));
1355 eh.false_value = (int *)odr_malloc(eh.o, sizeof(eh.false_value));
1356 *eh.false_value = 0;
1357 eh.true_value = (int *)odr_malloc(eh.o, sizeof(eh.true_value));
1360 assert(n->which == DATA1N_root);
1361 if (strcmp(n->u.root.type, "explain"))
1363 yaz_log(YLOG_WARN, "Attempt to convert a non-Explain record");
1366 for (n = n->child; n; n = n->next)
1368 switch (is_numeric_tag (&eh, n))
1371 res->which = Z_Explain_categoryList;
1372 if (!(res->u.categoryList = f_categoryList(&eh, n)))
1376 res->which = Z_Explain_targetInfo;
1377 if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
1381 res->which = Z_Explain_databaseInfo;
1382 if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
1386 res->which = Z_Explain_attributeSetInfo;
1387 if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
1391 res->which = Z_Explain_attributeDetails;
1392 if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
1397 yaz_log(YLOG_WARN, "No category in Explain record");
1403 * c-file-style: "Stroustrup"
1404 * indent-tabs-mode: nil
1406 * vim: shiftwidth=4 tabstop=8 expandtab