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 int *f_integer(ExpHandle *eh, data1_node *c)
77 if (!is_data_tag (eh, c) || c->u.data.len > 63)
79 r = (int *)odr_malloc(eh->o, sizeof(*r));
80 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
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 = (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 int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
393 int *r= (int *)odr_malloc(eh->o, sizeof(*r));
398 if (!is_numeric_tag (eh, c))
400 if (c->u.tag.element->tag->value.numeric == 210)
401 *wp = Z_DatabaseInfo_actualNumber;
402 else if (c->u.tag.element->tag->value.numeric == 211)
403 *wp = Z_DatabaseInfo_approxNumber;
406 if (!c->child || c->child->which != DATA1N_data)
408 sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
413 static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
415 Z_ContactInfo *res = (Z_ContactInfo *)
416 odr_malloc (eh->o, sizeof(*res));
420 res->description = 0;
425 for (c = n->child; c; c = c->next)
427 switch (is_numeric_tag (eh, c))
429 case 102: res->name = f_string (eh, c); break;
430 case 113: res->description = f_humstring (eh, c); break;
431 case 127: res->address = f_humstring (eh, c); break;
432 case 128: res->email = f_string (eh, c); break;
433 case 129: res->phone = f_string (eh, c); break;
439 static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n)
445 for (c = n->child; c; c = c->next)
447 if (!is_numeric_tag (eh, c) != 102)
454 res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
456 res->num_databases = i;
457 res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
459 for (c = n->child; c; c = c->next)
461 if (!is_numeric_tag (eh, c) != 102)
463 res->databases[i++] = f_string (eh, c);
468 static Z_NetworkAddressIA *f_networkAddressIA(ExpHandle *eh, data1_node *n)
470 Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
471 odr_malloc (eh->o, sizeof(*res));
474 res->hostAddress = 0;
477 for (c = n->child; c; c = c->next)
479 switch (is_numeric_tag (eh, c))
481 case 121: res->hostAddress = f_string (eh, c); break;
482 case 122: res->port = f_integer (eh, c); break;
488 static Z_NetworkAddressOther *f_networkAddressOther(ExpHandle *eh,
491 Z_NetworkAddressOther *res = (Z_NetworkAddressOther *)
492 odr_malloc (eh->o, sizeof(*res));
498 for (c = n->child; c; c = c->next)
500 switch (is_numeric_tag (eh, c))
502 case 124: res->type = f_string (eh, c); break;
503 case 121: res->address = f_string (eh, c); break;
509 static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
512 Z_NetworkAddress **res = NULL;
517 for (c = n->child; c; c = c->next)
519 switch (is_numeric_tag (eh, c))
529 res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
531 for (c = n->child; c; c = c->next)
533 switch (is_numeric_tag (eh, c))
536 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
537 res[i]->which = Z_NetworkAddress_iA;
538 res[i]->u.internetAddress = f_networkAddressIA(eh, c);
542 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
543 res[i]->which = Z_NetworkAddress_other;
544 res[i]->u.other = f_networkAddressOther(eh, c);
552 static Z_CategoryInfo *f_categoryInfo(ExpHandle *eh, data1_node *n)
554 Z_CategoryInfo *res = (Z_CategoryInfo *)odr_malloc(eh->o, sizeof(*res));
558 res->originalCategory = 0;
559 res->description = 0;
561 for (c = n->child; c; c = c->next)
563 switch (is_numeric_tag (eh, c))
565 case 102: res->category = f_string(eh, c); break;
566 case 302: res->originalCategory = f_string(eh, c); break;
567 case 113: res->description = f_humstring(eh, c); break;
568 case 303: res->asn1Module = f_string (eh, c); break;
574 static Z_CategoryList *f_categoryList(ExpHandle *eh, data1_node *n)
576 Z_CategoryList *res = (Z_CategoryList *)odr_malloc(eh->o, sizeof(*res));
580 res->num_categories = 0;
581 res->categories = NULL;
583 for (c = n->child; c; c = c->next)
587 switch (is_numeric_tag (eh, c))
589 case 600: res->commonInfo = f_commonInfo(eh, c); break;
591 for (n = c->child; n; n = n->next)
593 if (is_numeric_tag(eh, n) != 301)
595 (res->num_categories)++;
597 if (res->num_categories)
599 (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
600 * sizeof(*res->categories));
601 for (n = c->child; n; n = n->next)
603 if (is_numeric_tag(eh, n) != 301)
605 res->categories[i++] = f_categoryInfo (eh, n);
610 assert (res->num_categories && res->categories);
614 static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n)
616 Z_TargetInfo *res = (Z_TargetInfo *)odr_malloc(eh->o, sizeof(*res));
623 res->namedResultSets = 0;
624 res->multipleDBsearch = 0;
625 res->maxResultSets = 0;
626 res->maxResultSize = 0;
628 res->timeoutInterval = 0;
629 res->welcomeMessage = 0;
630 res->contactInfo = 0;
631 res->description = 0;
632 res->num_nicknames = 0;
635 res->paymentAddr = 0;
637 res->num_dbCombinations = 0;
638 res->dbCombinations = 0;
639 res->num_addresses = 0;
641 res->num_languages = 0;
642 res->languages = NULL;
643 res->commonAccessInfo = 0;
645 for (c = n->child; c; c = c->next)
649 switch (is_numeric_tag (eh, c))
651 case 600: res->commonInfo = f_commonInfo(eh, c); break;
652 case 102: res->name = f_string(eh, c); break;
653 case 103: res->recentNews = f_humstring(eh, c); break;
654 case 104: res->icon = NULL; break; /* fix */
655 case 105: res->namedResultSets = f_bool(eh, c); break;
656 case 106: res->multipleDBsearch = f_bool(eh, c); break;
657 case 107: res->maxResultSets = f_integer(eh, c); break;
658 case 108: res->maxResultSize = f_integer(eh, c); break;
659 case 109: res->maxTerms = f_integer(eh, c); break;
660 case 110: res->timeoutInterval = f_intunit(eh, c); break;
661 case 111: res->welcomeMessage = f_humstring(eh, c); break;
662 case 112: res->contactInfo = f_contactInfo(eh, c); break;
663 case 113: res->description = f_humstring(eh, c); break;
665 res->num_nicknames = 0;
666 for (n = c->child; n; n = n->next)
668 if (is_numeric_tag(eh, n) != 102)
670 (res->num_nicknames)++;
672 if (res->num_nicknames)
674 (char **)odr_malloc (eh->o, res->num_nicknames
675 * sizeof(*res->nicknames));
676 for (n = c->child; n; n = n->next)
678 if (is_numeric_tag(eh, n) != 102)
680 res->nicknames[i++] = f_string (eh, n);
683 case 115: res->usageRest = f_humstring(eh, c); break;
684 case 116: res->paymentAddr = f_humstring(eh, c); break;
685 case 117: res->hours = f_humstring(eh, c); break;
687 res->num_dbCombinations = 0;
688 for (n = c->child; n; n = n->next)
690 if (!is_numeric_tag(eh, n) != 605)
692 (res->num_dbCombinations)++;
694 if (res->num_dbCombinations)
695 res->dbCombinations =
696 (Z_DatabaseList **)odr_malloc (eh->o, res->num_dbCombinations
697 * sizeof(*res->dbCombinations));
698 for (n = c->child; n; n = n->next)
700 if (!is_numeric_tag(eh, n) != 605)
702 res->dbCombinations[i++] = f_databaseList (eh, n);
707 f_networkAddresses (eh, c, &res->num_addresses);
710 res->num_languages = 0;
711 for (n = c->child; n; n = n->next)
713 if (!is_numeric_tag(eh, n) != 126)
715 (res->num_languages)++;
717 if (res->num_languages)
718 res->languages = (char **)
719 odr_malloc (eh->o, res->num_languages *
720 sizeof(*res->languages));
721 for (n = c->child; n; n = n->next)
723 if (!is_numeric_tag(eh, n) != 126)
725 res->languages[i++] = f_string (eh, n);
728 case 500: res->commonAccessInfo = f_accessInfo(eh, c); break;
731 if (!res->namedResultSets)
732 res->namedResultSets = eh->false_value;
733 if (!res->multipleDBsearch)
734 res->multipleDBsearch = eh->false_value;
738 static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n)
740 Z_DatabaseInfo *res = (Z_DatabaseInfo *)odr_malloc(eh->o, sizeof(*res));
745 res->explainDatabase = 0;
746 res->num_nicknames = 0;
751 res->titleString = 0;
752 res->num_keywords = 0;
754 res->description = 0;
755 res->associatedDbs = 0;
757 res->disclaimers = 0;
759 res->u.actualNumber = 0;
760 res->defaultOrder = 0;
761 res->avRecordSize = 0;
762 res->maxRecordSize = 0;
766 res->updateInterval = 0;
768 res->proprietary = 0;
769 res->copyrightText = 0;
770 res->copyrightNotice = 0;
771 res->producerContactInfo = 0;
772 res->supplierContactInfo = 0;
773 res->submissionContactInfo = 0;
776 for (c = n->child; c; c = c->next)
780 switch (is_numeric_tag (eh, c))
782 case 600: res->commonInfo = f_commonInfo(eh, c); break;
783 case 102: res->name = f_string(eh, c); break;
784 case 226: res->explainDatabase = odr_nullval(); break;
786 res->num_nicknames = 0;
787 for (n = c->child; n; n = n->next)
789 if (!is_numeric_tag(eh, n) ||
790 n->u.tag.element->tag->value.numeric != 102)
792 (res->num_nicknames)++;
794 if (res->num_nicknames)
796 (char **)odr_malloc (eh->o, res->num_nicknames
797 * sizeof(*res->nicknames));
798 for (n = c->child; n; n = n->next)
800 if (!is_numeric_tag(eh, n) ||
801 n->u.tag.element->tag->value.numeric != 102)
803 res->nicknames[i++] = f_string (eh, n);
806 case 104: res->icon = 0; break; /* fix */
807 case 201: res->userFee = f_bool(eh, c); break;
808 case 202: res->available = f_bool(eh, c); break;
809 case 203: res->titleString = f_humstring(eh, c); break;
811 res->num_keywords = 0;
812 for (n = c->child; n; n = n->next)
814 if (!is_numeric_tag(eh, n) != 1000)
816 (res->num_keywords)++;
818 if (res->num_keywords)
820 (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
821 * sizeof(*res->keywords));
822 for (n = c->child; n; n = n->next)
824 if (!is_numeric_tag(eh, n) != 1000)
826 res->keywords[i++] = f_humstring (eh, n);
829 case 113: res->description = f_humstring(eh, c); break;
831 res->associatedDbs = f_databaseList (eh, c);
834 res->subDbs = f_databaseList (eh, c);
836 case 207: res->disclaimers = f_humstring(eh, c); break;
837 case 103: res->news = f_humstring(eh, c); break;
838 case 209: res->u.actualNumber =
839 f_recordCount(eh, c, &res->which); break;
840 case 212: res->defaultOrder = f_humstring(eh, c); break;
841 case 213: res->avRecordSize = f_integer(eh, c); break;
842 case 214: res->maxRecordSize = f_integer(eh, c); break;
843 case 215: res->hours = f_humstring(eh, c); break;
844 case 216: res->bestTime = f_humstring(eh, c); break;
845 case 217: res->lastUpdate = f_string(eh, c); break;
846 case 218: res->updateInterval = f_intunit(eh, c); break;
847 case 219: res->coverage = f_humstring(eh, c); break;
848 case 220: res->proprietary = f_bool(eh, c); break;
849 case 221: res->copyrightText = f_humstring(eh, c); break;
850 case 222: res->copyrightNotice = f_humstring(eh, c); break;
851 case 223: res->producerContactInfo = f_contactInfo(eh, c); break;
852 case 224: res->supplierContactInfo = f_contactInfo(eh, c); break;
853 case 225: res->submissionContactInfo = f_contactInfo(eh, c); break;
854 case 500: res->accessInfo = f_accessInfo(eh, c); break;
858 res->userFee = eh->false_value;
860 res->available = eh->true_value;
864 Z_StringOrNumeric *f_stringOrNumeric (ExpHandle *eh, data1_node *n)
866 Z_StringOrNumeric *res = (Z_StringOrNumeric *)
867 odr_malloc (eh->o, sizeof(*res));
869 for (c = n->child; c; c = c->next)
871 switch (is_numeric_tag (eh, c))
874 res->which = Z_StringOrNumeric_string;
875 res->u.string = f_string (eh, c);
878 res->which = Z_StringOrNumeric_numeric;
879 res->u.numeric = f_integer (eh, c);
886 Z_AttributeDescription *f_attributeDescription (
887 ExpHandle *eh, data1_node *n)
889 Z_AttributeDescription *res = (Z_AttributeDescription *)
890 odr_malloc(eh->o, sizeof(*res));
895 res->description = 0;
896 res->attributeValue = 0;
897 res->num_equivalentAttributes = 0;
898 res->equivalentAttributes = 0;
900 for (c = n->child; c; c = c->next)
902 switch (is_numeric_tag (eh, c))
904 case 102: res->name = f_string (eh, c); break;
905 case 113: res->description = f_humstring (eh, c); break;
906 case 710: res->attributeValue = f_stringOrNumeric (eh, c); break;
907 case 752: (res->num_equivalentAttributes++); break;
910 if (res->num_equivalentAttributes)
911 res->equivalentAttributes = (Z_StringOrNumeric **)
912 odr_malloc (eh->o, sizeof(*res->equivalentAttributes) *
913 res->num_equivalentAttributes);
914 for (c = n->child; c; c = c->next)
915 if (is_numeric_tag (eh, c) == 752)
916 res->equivalentAttributes[i++] = f_stringOrNumeric (eh, c);
920 Z_AttributeType *f_attributeType (ExpHandle *eh, data1_node *n)
922 Z_AttributeType *res = (Z_AttributeType *)
923 odr_malloc(eh->o, sizeof(*res));
927 res->description = 0;
928 res->attributeType = 0;
929 res->num_attributeValues = 0;
930 res->attributeValues = 0;
932 for (c = n->child; c; c = c->next)
935 switch (is_numeric_tag (eh, c))
937 case 102: res->name = f_string (eh, c); break;
938 case 113: res->description = f_humstring (eh, c); break;
939 case 704: res->attributeType = f_integer (eh, c); break;
941 for (n = c->child; n; n = n->next)
943 if (is_numeric_tag(eh, n) != 709)
945 (res->num_attributeValues)++;
947 if (res->num_attributeValues)
948 res->attributeValues = (Z_AttributeDescription **)
949 odr_malloc (eh->o, res->num_attributeValues
950 * sizeof(*res->attributeValues));
951 for (n = c->child; n; n = n->next)
953 if (is_numeric_tag(eh, n) != 709)
955 res->attributeValues[i++] = f_attributeDescription (eh, n);
963 Z_AttributeSetInfo *f_attributeSetInfo (ExpHandle *eh, data1_node *n)
965 Z_AttributeSetInfo *res = (Z_AttributeSetInfo *)
966 odr_malloc(eh->o, sizeof(*res));
970 res->attributeSet = 0;
972 res->num_attributes = 0;
974 res->description = 0;
975 for (c = n->child; c; c = c->next)
978 switch (is_numeric_tag (eh, c))
980 case 600: res->commonInfo = f_commonInfo (eh, c); break;
981 case 1000: res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
982 case 102: res->name = f_string (eh, c); break;
984 for (n = c->child; n; n = n->next)
986 if (is_numeric_tag(eh, n) != 751)
988 (res->num_attributes)++;
990 if (res->num_attributes)
991 res->attributes = (Z_AttributeType **)
992 odr_malloc (eh->o, res->num_attributes
993 * sizeof(*res->attributes));
994 for (n = c->child; n; n = n->next)
996 if (is_numeric_tag(eh, n) != 751)
998 res->attributes[i++] = f_attributeType (eh, n);
1001 case 113: res->description = f_humstring (eh, c); break;
1007 Z_OmittedAttributeInterpretation *f_omittedAttributeInterpretation (
1008 ExpHandle *eh, data1_node *n)
1010 Z_OmittedAttributeInterpretation *res = (Z_OmittedAttributeInterpretation*)
1011 odr_malloc (eh->o, sizeof(*res));
1014 res->defaultValue = 0;
1015 res->defaultDescription = 0;
1016 for (c = n->child; c; c = c->next)
1018 switch (is_numeric_tag (eh, c))
1021 res->defaultValue = f_stringOrNumeric (eh, c);
1024 res->defaultDescription = f_humstring(eh, c);
1031 Z_AttributeValue *f_attributeValue (ExpHandle *eh, data1_node *n)
1033 Z_AttributeValue *res = (Z_AttributeValue *)
1034 odr_malloc (eh->o, sizeof(*res));
1038 res->description = 0;
1039 res->num_subAttributes = 0;
1040 res->subAttributes = 0;
1041 res->num_superAttributes = 0;
1042 res->superAttributes = 0;
1043 res->partialSupport = 0;
1044 for (c = n->child; c; c = c->next)
1047 switch (is_numeric_tag (eh, c))
1050 res->value = f_stringOrNumeric (eh, c); break;
1052 res->description = f_humstring (eh, c); break;
1054 for (n = c->child; n; n = n->next)
1056 if (is_numeric_tag(eh, n) != 713)
1058 (res->num_subAttributes)++;
1060 if (res->num_subAttributes)
1061 res->subAttributes =
1062 (Z_StringOrNumeric **)
1063 odr_malloc (eh->o, res->num_subAttributes
1064 * sizeof(*res->subAttributes));
1065 for (n = c->child; n; n = n->next)
1067 if (is_numeric_tag(eh, n) != 713)
1069 res->subAttributes[i++] = f_stringOrNumeric (eh, n);
1073 for (n = c->child; n; n = n->next)
1075 if (is_numeric_tag(eh, n) != 715)
1077 (res->num_superAttributes)++;
1079 if (res->num_superAttributes)
1080 res->superAttributes =
1081 (Z_StringOrNumeric **)
1082 odr_malloc (eh->o, res->num_superAttributes
1083 * sizeof(*res->superAttributes));
1084 for (n = c->child; n; n = n->next)
1086 if (is_numeric_tag(eh, n) != 715)
1088 res->superAttributes[i++] = f_stringOrNumeric (eh, n);
1092 res->partialSupport = odr_nullval ();
1099 Z_AttributeTypeDetails *f_attributeTypeDetails (ExpHandle *eh, data1_node *n)
1101 Z_AttributeTypeDetails *res = (Z_AttributeTypeDetails *)
1102 odr_malloc(eh->o, sizeof(*res));
1104 res->attributeType = 0;
1105 res->defaultIfOmitted = 0;
1106 res->num_attributeValues = 0;
1107 res->attributeValues = 0;
1108 for (c = n->child; c; c = c->next)
1111 switch (is_numeric_tag (eh, c))
1113 case 704: res->attributeType = f_integer (eh, c); break;
1115 res->defaultIfOmitted = f_omittedAttributeInterpretation (eh, c);
1118 for (n = c->child; n; n = n->next)
1120 if (is_numeric_tag(eh, n) != 709)
1122 (res->num_attributeValues)++;
1124 if (res->num_attributeValues)
1125 res->attributeValues =
1126 (Z_AttributeValue **)
1127 odr_malloc (eh->o, res->num_attributeValues
1128 * sizeof(*res->attributeValues));
1129 for (n = c->child; n; n = n->next)
1131 if (is_numeric_tag(eh, n) != 709)
1133 res->attributeValues[i++] = f_attributeValue (eh, n);
1141 Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n)
1143 Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
1144 odr_malloc(eh->o, sizeof(*res));
1147 res->attributeSet = 0;
1148 res->num_attributesByType = 0;
1149 res->attributesByType = 0;
1150 for (c = n->child; c; c = c->next)
1153 switch (is_numeric_tag (eh, c))
1155 case 1000: res->attributeSet = f_oid(eh, c, CLASS_ATTSET); break;
1157 for (n = c->child; n; n = n->next)
1159 if (is_numeric_tag(eh, n) != 703)
1161 (res->num_attributesByType)++;
1163 if (res->num_attributesByType)
1164 res->attributesByType =
1165 (Z_AttributeTypeDetails **)
1166 odr_malloc (eh->o, res->num_attributesByType
1167 * sizeof(*res->attributesByType));
1168 for (n = c->child; n; n = n->next)
1170 if (is_numeric_tag(eh, n) != 703)
1172 res->attributesByType[i++] = f_attributeTypeDetails (eh, n);
1180 Z_AttributeValueList *f_attributeValueList (ExpHandle *eh, data1_node *n)
1182 Z_AttributeValueList *res = (Z_AttributeValueList *)
1183 odr_malloc (eh->o, sizeof(*res));
1187 res->num_attributes = 0;
1188 res->attributes = 0;
1189 for (c = n->child; c; c = c->next)
1190 if (is_numeric_tag (eh, c) == 710)
1191 (res->num_attributes)++;
1192 if (res->num_attributes)
1194 res->attributes = (Z_StringOrNumeric **)
1195 odr_malloc (eh->o, res->num_attributes * sizeof(*res->attributes));
1197 for (c = n->child; c; c = c->next)
1198 if (is_numeric_tag(eh, c) == 710)
1199 res->attributes[i++] = f_stringOrNumeric (eh, c);
1203 Z_AttributeOccurrence *f_attributeOccurrence (ExpHandle *eh, data1_node *n)
1205 Z_AttributeOccurrence *res = (Z_AttributeOccurrence *)
1206 odr_malloc (eh->o, sizeof(*res));
1209 res->attributeSet = 0;
1210 res->attributeType = 0;
1211 res->mustBeSupplied = 0;
1212 res->which = Z_AttributeOcc_any_or_none;
1213 res->attributeValues.any_or_none = odr_nullval ();
1215 for (c = n->child; c; c = c->next)
1217 switch (is_numeric_tag (eh, c))
1220 res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
1222 res->attributeType = f_integer (eh, c); break;
1224 res->mustBeSupplied = odr_nullval (); break;
1226 res->which = Z_AttributeOcc_any_or_none;
1227 res->attributeValues.any_or_none = odr_nullval ();
1230 res->which = Z_AttributeOcc_specific;
1231 res->attributeValues.specific = f_attributeValueList (eh, c);
1238 Z_AttributeCombination *f_attributeCombination (ExpHandle *eh, data1_node *n)
1240 Z_AttributeCombination *res = (Z_AttributeCombination *)
1241 odr_malloc (eh->o, sizeof(*res));
1245 res->num_occurrences = 0;
1246 res->occurrences = 0;
1247 for (c = n->child; c; c = c->next)
1248 if (is_numeric_tag (eh, c) == 719)
1249 (res->num_occurrences)++;
1250 if (res->num_occurrences)
1252 res->occurrences = (Z_AttributeOccurrence **)
1253 odr_malloc (eh->o, res->num_occurrences * sizeof(*res->occurrences));
1255 for (c = n->child; c; c = c->next)
1256 if (is_numeric_tag(eh, c) == 719)
1257 res->occurrences[i++] = f_attributeOccurrence (eh, c);
1258 assert (res->num_occurrences);
1262 Z_AttributeCombinations *f_attributeCombinations (ExpHandle *eh, data1_node *n)
1264 Z_AttributeCombinations *res = (Z_AttributeCombinations *)
1265 odr_malloc (eh->o, sizeof(*res));
1267 res->defaultAttributeSet = 0;
1268 res->num_legalCombinations = 0;
1269 res->legalCombinations = 0;
1271 for (c = n->child; c; c = c->next)
1274 switch (is_numeric_tag (eh, c))
1277 res->defaultAttributeSet = f_oid (eh, c, CLASS_ATTSET);
1280 for (n = c->child; n; n = n->next)
1282 if (is_numeric_tag(eh, n) != 718)
1284 (res->num_legalCombinations)++;
1286 if (res->num_legalCombinations)
1287 res->legalCombinations =
1288 (Z_AttributeCombination **)
1289 odr_malloc (eh->o, res->num_legalCombinations
1290 * sizeof(*res->legalCombinations));
1291 for (n = c->child; n; n = n->next)
1293 if (is_numeric_tag(eh, n) != 718)
1295 res->legalCombinations[i++] = f_attributeCombination (eh, n);
1300 assert (res->num_legalCombinations);
1304 Z_AttributeDetails *f_attributeDetails (ExpHandle *eh, data1_node *n)
1306 Z_AttributeDetails *res = (Z_AttributeDetails *)
1307 odr_malloc(eh->o, sizeof(*res));
1310 res->commonInfo = 0;
1311 res->databaseName = 0;
1312 res->num_attributesBySet = 0;
1313 res->attributesBySet = NULL;
1314 res->attributeCombinations = NULL;
1316 for (c = n->child; c; c = c->next)
1319 switch (is_numeric_tag (eh, c))
1321 case 600: res->commonInfo = f_commonInfo(eh, c); break;
1322 case 102: res->databaseName = f_string (eh, c); break;
1324 for (n = c->child; n; n = n->next)
1326 if (is_numeric_tag(eh, n) != 701)
1328 (res->num_attributesBySet)++;
1330 if (res->num_attributesBySet)
1331 res->attributesBySet =
1332 (Z_AttributeSetDetails **)
1333 odr_malloc (eh->o, res->num_attributesBySet
1334 * sizeof(*res->attributesBySet));
1335 for (n = c->child; n; n = n->next)
1337 if (is_numeric_tag(eh, n) != 701)
1339 res->attributesBySet[i++] = f_attributeSetDetails (eh, n);
1343 res->attributeCombinations = f_attributeCombinations (eh, c);
1350 Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
1354 Z_ExplainRecord *res = (Z_ExplainRecord *)odr_malloc(o, sizeof(*res));
1359 eh.false_value = (int *)odr_malloc(eh.o, sizeof(eh.false_value));
1360 *eh.false_value = 0;
1361 eh.true_value = (int *)odr_malloc(eh.o, sizeof(eh.true_value));
1364 assert(n->which == DATA1N_root);
1365 if (strcmp(n->u.root.type, "explain"))
1367 yaz_log(YLOG_WARN, "Attempt to convert a non-Explain record");
1370 for (n = n->child; n; n = n->next)
1372 switch (is_numeric_tag (&eh, n))
1375 res->which = Z_Explain_categoryList;
1376 if (!(res->u.categoryList = f_categoryList(&eh, n)))
1380 res->which = Z_Explain_targetInfo;
1381 if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
1385 res->which = Z_Explain_databaseInfo;
1386 if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
1390 res->which = Z_Explain_attributeSetInfo;
1391 if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
1395 res->which = Z_Explain_attributeDetails;
1396 if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
1401 yaz_log(YLOG_WARN, "No category in Explain record");
1407 * c-file-style: "Stroustrup"
1408 * indent-tabs-mode: nil
1410 * vim: shiftwidth=4 tabstop=8 expandtab