1 /* $Id: d1_expout.c,v 1.11 2007-05-08 12:50:03 adam Exp $
2 Copyright (C) 1995-2007
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 * 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 int *f_integer(ExpHandle *eh, data1_node *c)
80 if (!is_data_tag (eh, c) || c->u.data.len > 63)
82 r = (int *)odr_malloc(eh->o, sizeof(*r));
83 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
88 static char *f_string(ExpHandle *eh, data1_node *c)
93 if (!is_data_tag (eh, c))
95 r = (char *)odr_malloc(eh->o, c->u.data.len+1);
96 memcpy(r, c->u.data.data, c->u.data.len);
97 r[c->u.data.len] = '\0';
101 static bool_t *f_bool(ExpHandle *eh, data1_node *c)
107 if (!is_data_tag (eh, c) || c->u.data.len > 63)
109 tf = (int *)odr_malloc (eh->o, sizeof(*tf));
110 sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
115 static Odr_oid *f_oid(ExpHandle *eh, data1_node *c, oid_class oclass)
120 if (!is_data_tag (eh, c) || c->u.data.len > 63)
122 yaz_snprintf(oidstr, sizeof(oidstr)-1,
123 "%.*s", c->u.data.len, c->u.data.data);
125 return yaz_string_to_oid_odr(yaz_oid_std(),
126 CLASS_GENERAL, oidstr, eh->o);
129 static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c)
135 static Z_HumanString *f_humstring(ExpHandle *eh, data1_node *c)
138 Z_HumanStringUnit *u;
141 if (!is_data_tag (eh, c))
143 r = (Z_HumanString *)odr_malloc(eh->o, sizeof(*r));
145 r->strings = (Z_HumanStringUnit **)odr_malloc(eh->o, sizeof(Z_HumanStringUnit*));
146 r->strings[0] = u = (Z_HumanStringUnit *)odr_malloc(eh->o, sizeof(*u));
148 u->text = (char *)odr_malloc(eh->o, c->u.data.len+1);
149 memcpy(u->text, c->u.data.data, c->u.data.len);
150 u->text[c->u.data.len] = '\0';
154 static Z_CommonInfo *f_commonInfo(ExpHandle *eh, data1_node *n)
156 Z_CommonInfo *res = (Z_CommonInfo *)odr_malloc(eh->o, sizeof(*res));
160 res->dateChanged = 0;
162 res->humanStringLanguage = 0;
165 for (c = n->child; c; c = c->next)
167 switch (is_numeric_tag (eh, c))
169 case 601: res->dateAdded = f_string(eh, c); break;
170 case 602: res->dateChanged = f_string(eh, c); break;
171 case 603: res->expiry = f_string(eh, c); break;
172 case 604: res->humanStringLanguage = f_string(eh, c); break;
178 Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num, oid_class oclass)
185 for (c = n->child ; c; c = c->next)
186 if (is_numeric_tag (eh, c) == 1000)
190 res = (Odr_oid **)odr_malloc (eh->o, sizeof(*res) * (*num));
191 for (c = n->child, i = 0 ; c; c = c->next)
192 if (is_numeric_tag (eh, c) == 1000)
193 res[i++] = f_oid (eh, c, oclass);
197 char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
204 for (c = n->child ; c; c = c->next)
206 if (is_numeric_tag (eh, c) != 1001)
212 res = (char **)odr_malloc (eh->o, sizeof(*res) * (*num));
213 for (c = n->child, i = 0 ; c; c = c->next)
215 if (is_numeric_tag (eh, c) != 1001)
217 res[i++] = f_string (eh, c);
222 Z_ProximitySupport *f_proximitySupport (ExpHandle *eh, data1_node *n)
224 Z_ProximitySupport *res = (Z_ProximitySupport *)
225 odr_malloc (eh->o, sizeof(*res));
226 res->anySupport = eh->false_value;
227 res->num_unitsSupported = 0;
228 res->unitsSupported = 0;
232 Z_RpnCapabilities *f_rpnCapabilities (ExpHandle *eh, data1_node *n)
234 Z_RpnCapabilities *res = (Z_RpnCapabilities *)
235 odr_malloc (eh->o, sizeof(*res));
238 res->num_operators = 0;
239 res->operators = NULL;
240 res->resultSetAsOperandSupported = eh->false_value;
241 res->restrictionOperandSupported = eh->false_value;
242 res->proximity = NULL;
244 for (c = n->child; c; c = c->next)
247 switch (is_numeric_tag(eh, c))
250 for (n = c->child; n; n = n->next)
252 if (is_numeric_tag(eh, n) != 551)
254 (res->num_operators)++;
256 if (res->num_operators)
257 res->operators = (int **)
258 odr_malloc (eh->o, res->num_operators
259 * sizeof(*res->operators));
260 for (n = c->child; n; n = n->next)
262 if (is_numeric_tag(eh, n) != 551)
264 res->operators[i++] = f_integer (eh, n);
268 res->resultSetAsOperandSupported = f_bool (eh, c);
271 res->restrictionOperandSupported = f_bool (eh, c);
274 res->proximity = f_proximitySupport (eh, c);
281 Z_QueryTypeDetails *f_queryTypeDetails (ExpHandle *eh, data1_node *n)
283 Z_QueryTypeDetails *res = (Z_QueryTypeDetails *)
284 odr_malloc(eh->o, sizeof(*res));
287 res->which = Z_QueryTypeDetails_rpn;
289 for (c = n->child; c; c = c->next)
291 switch (is_numeric_tag(eh, c))
294 res->which = Z_QueryTypeDetails_rpn;
295 res->u.rpn = f_rpnCapabilities (eh, c);
306 static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n)
308 Z_AccessInfo *res = (Z_AccessInfo *)odr_malloc(eh->o, sizeof(*res));
311 res->num_queryTypesSupported = 0;
312 res->queryTypesSupported = 0;
313 res->num_diagnosticsSets = 0;
314 res->diagnosticsSets = 0;
315 res->num_attributeSetIds = 0;
316 res->attributeSetIds = 0;
317 res->num_schemas = 0;
319 res->num_recordSyntaxes = 0;
320 res->recordSyntaxes = 0;
321 res->num_resourceChallenges = 0;
322 res->resourceChallenges = 0;
323 res->restrictedAccess = 0;
325 res->num_variantSets = 0;
326 res->variantSets = 0;
327 res->num_elementSetNames = 0;
328 res->elementSetNames = 0;
329 res->num_unitSystems = 0;
330 res->unitSystems = 0;
332 for (c = n->child; c; c = c->next)
335 switch (is_numeric_tag (eh, c))
338 for (n = c->child; n; n = n->next)
340 if (is_numeric_tag(eh, n) != 518)
342 (res->num_queryTypesSupported)++;
344 if (res->num_queryTypesSupported)
345 res->queryTypesSupported =
346 (Z_QueryTypeDetails **)
347 odr_malloc (eh->o, res->num_queryTypesSupported
348 * sizeof(*res->queryTypesSupported));
349 for (n = c->child; n; n = n->next)
351 if (is_numeric_tag(eh, n) != 518)
353 res->queryTypesSupported[i++] = f_queryTypeDetails (eh, n);
357 res->diagnosticsSets =
358 f_oid_seq(eh, c, &res->num_diagnosticsSets, CLASS_DIAGSET);
361 res->attributeSetIds =
362 f_oid_seq(eh, c, &res->num_attributeSetIds, CLASS_ATTSET);
366 f_oid_seq(eh, c, &res->num_schemas, CLASS_SCHEMA);
369 res->recordSyntaxes =
370 f_oid_seq (eh, c, &res->num_recordSyntaxes, CLASS_RECSYN);
373 res->resourceChallenges =
374 f_oid_seq (eh, c, &res->num_resourceChallenges, CLASS_RESFORM);
376 case 513: res->restrictedAccess = NULL; break; /* fix */
377 case 514: res->costInfo = NULL; break; /* fix */
380 f_oid_seq (eh, c, &res->num_variantSets, CLASS_VARSET);
383 res->elementSetNames =
384 f_string_seq (eh, c, &res->num_elementSetNames);
387 res->unitSystems = f_string_seq (eh, c, &res->num_unitSystems);
394 static int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
396 int *r= (int *)odr_malloc(eh->o, sizeof(*r));
401 if (!is_numeric_tag (eh, c))
403 if (c->u.tag.element->tag->value.numeric == 210)
404 *wp = Z_DatabaseInfo_actualNumber;
405 else if (c->u.tag.element->tag->value.numeric == 211)
406 *wp = Z_DatabaseInfo_approxNumber;
409 if (!c->child || c->child->which != DATA1N_data)
411 sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
416 static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
418 Z_ContactInfo *res = (Z_ContactInfo *)
419 odr_malloc (eh->o, sizeof(*res));
423 res->description = 0;
428 for (c = n->child; c; c = c->next)
430 switch (is_numeric_tag (eh, c))
432 case 102: res->name = f_string (eh, c); break;
433 case 113: res->description = f_humstring (eh, c); break;
434 case 127: res->address = f_humstring (eh, c); break;
435 case 128: res->email = f_string (eh, c); break;
436 case 129: res->phone = f_string (eh, c); break;
442 static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n)
448 for (c = n->child; c; c = c->next)
450 if (!is_numeric_tag (eh, c) != 102)
457 res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
459 res->num_databases = i;
460 res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
462 for (c = n->child; c; c = c->next)
464 if (!is_numeric_tag (eh, c) != 102)
466 res->databases[i++] = f_string (eh, c);
471 static Z_NetworkAddressIA *f_networkAddressIA(ExpHandle *eh, data1_node *n)
473 Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
474 odr_malloc (eh->o, sizeof(*res));
477 res->hostAddress = 0;
480 for (c = n->child; c; c = c->next)
482 switch (is_numeric_tag (eh, c))
484 case 121: res->hostAddress = f_string (eh, c); break;
485 case 122: res->port = f_integer (eh, c); break;
491 static Z_NetworkAddressOther *f_networkAddressOther(ExpHandle *eh,
494 Z_NetworkAddressOther *res = (Z_NetworkAddressOther *)
495 odr_malloc (eh->o, sizeof(*res));
501 for (c = n->child; c; c = c->next)
503 switch (is_numeric_tag (eh, c))
505 case 124: res->type = f_string (eh, c); break;
506 case 121: res->address = f_string (eh, c); break;
512 static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
515 Z_NetworkAddress **res = NULL;
520 for (c = n->child; c; c = c->next)
522 switch (is_numeric_tag (eh, c))
532 res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
534 for (c = n->child; c; c = c->next)
536 switch (is_numeric_tag (eh, c))
539 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
540 res[i]->which = Z_NetworkAddress_iA;
541 res[i]->u.internetAddress = f_networkAddressIA(eh, c);
545 res[i] = (Z_NetworkAddress *) odr_malloc (eh->o, sizeof(**res));
546 res[i]->which = Z_NetworkAddress_other;
547 res[i]->u.other = f_networkAddressOther(eh, c);
555 static Z_CategoryInfo *f_categoryInfo(ExpHandle *eh, data1_node *n)
557 Z_CategoryInfo *res = (Z_CategoryInfo *)odr_malloc(eh->o, sizeof(*res));
561 res->originalCategory = 0;
562 res->description = 0;
564 for (c = n->child; c; c = c->next)
566 switch (is_numeric_tag (eh, c))
568 case 102: res->category = f_string(eh, c); break;
569 case 302: res->originalCategory = f_string(eh, c); break;
570 case 113: res->description = f_humstring(eh, c); break;
571 case 303: res->asn1Module = f_string (eh, c); break;
577 static Z_CategoryList *f_categoryList(ExpHandle *eh, data1_node *n)
579 Z_CategoryList *res = (Z_CategoryList *)odr_malloc(eh->o, sizeof(*res));
583 res->num_categories = 0;
584 res->categories = NULL;
586 for (c = n->child; c; c = c->next)
590 switch (is_numeric_tag (eh, c))
592 case 600: res->commonInfo = f_commonInfo(eh, c); break;
594 for (n = c->child; n; n = n->next)
596 if (is_numeric_tag(eh, n) != 301)
598 (res->num_categories)++;
600 if (res->num_categories)
602 (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
603 * sizeof(*res->categories));
604 for (n = c->child; n; n = n->next)
606 if (is_numeric_tag(eh, n) != 301)
608 res->categories[i++] = f_categoryInfo (eh, n);
613 assert (res->num_categories && res->categories);
617 static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n)
619 Z_TargetInfo *res = (Z_TargetInfo *)odr_malloc(eh->o, sizeof(*res));
626 res->namedResultSets = 0;
627 res->multipleDBsearch = 0;
628 res->maxResultSets = 0;
629 res->maxResultSize = 0;
631 res->timeoutInterval = 0;
632 res->welcomeMessage = 0;
633 res->contactInfo = 0;
634 res->description = 0;
635 res->num_nicknames = 0;
638 res->paymentAddr = 0;
640 res->num_dbCombinations = 0;
641 res->dbCombinations = 0;
642 res->num_addresses = 0;
644 res->num_languages = 0;
645 res->languages = NULL;
646 res->commonAccessInfo = 0;
648 for (c = n->child; c; c = c->next)
652 switch (is_numeric_tag (eh, c))
654 case 600: res->commonInfo = f_commonInfo(eh, c); break;
655 case 102: res->name = f_string(eh, c); break;
656 case 103: res->recentNews = f_humstring(eh, c); break;
657 case 104: res->icon = NULL; break; /* fix */
658 case 105: res->namedResultSets = f_bool(eh, c); break;
659 case 106: res->multipleDBsearch = f_bool(eh, c); break;
660 case 107: res->maxResultSets = f_integer(eh, c); break;
661 case 108: res->maxResultSize = f_integer(eh, c); break;
662 case 109: res->maxTerms = f_integer(eh, c); break;
663 case 110: res->timeoutInterval = f_intunit(eh, c); break;
664 case 111: res->welcomeMessage = f_humstring(eh, c); break;
665 case 112: res->contactInfo = f_contactInfo(eh, c); break;
666 case 113: res->description = f_humstring(eh, c); break;
668 res->num_nicknames = 0;
669 for (n = c->child; n; n = n->next)
671 if (is_numeric_tag(eh, n) != 102)
673 (res->num_nicknames)++;
675 if (res->num_nicknames)
677 (char **)odr_malloc (eh->o, res->num_nicknames
678 * sizeof(*res->nicknames));
679 for (n = c->child; n; n = n->next)
681 if (is_numeric_tag(eh, n) != 102)
683 res->nicknames[i++] = f_string (eh, n);
686 case 115: res->usageRest = f_humstring(eh, c); break;
687 case 116: res->paymentAddr = f_humstring(eh, c); break;
688 case 117: res->hours = f_humstring(eh, c); break;
690 res->num_dbCombinations = 0;
691 for (n = c->child; n; n = n->next)
693 if (!is_numeric_tag(eh, n) != 605)
695 (res->num_dbCombinations)++;
697 if (res->num_dbCombinations)
698 res->dbCombinations =
699 (Z_DatabaseList **)odr_malloc (eh->o, res->num_dbCombinations
700 * sizeof(*res->dbCombinations));
701 for (n = c->child; n; n = n->next)
703 if (!is_numeric_tag(eh, n) != 605)
705 res->dbCombinations[i++] = f_databaseList (eh, n);
710 f_networkAddresses (eh, c, &res->num_addresses);
713 res->num_languages = 0;
714 for (n = c->child; n; n = n->next)
716 if (!is_numeric_tag(eh, n) != 126)
718 (res->num_languages)++;
720 if (res->num_languages)
721 res->languages = (char **)
722 odr_malloc (eh->o, res->num_languages *
723 sizeof(*res->languages));
724 for (n = c->child; n; n = n->next)
726 if (!is_numeric_tag(eh, n) != 126)
728 res->languages[i++] = f_string (eh, n);
731 case 500: res->commonAccessInfo = f_accessInfo(eh, c); break;
734 if (!res->namedResultSets)
735 res->namedResultSets = eh->false_value;
736 if (!res->multipleDBsearch)
737 res->multipleDBsearch = eh->false_value;
741 static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n)
743 Z_DatabaseInfo *res = (Z_DatabaseInfo *)odr_malloc(eh->o, sizeof(*res));
748 res->explainDatabase = 0;
749 res->num_nicknames = 0;
754 res->titleString = 0;
755 res->num_keywords = 0;
757 res->description = 0;
758 res->associatedDbs = 0;
760 res->disclaimers = 0;
762 res->u.actualNumber = 0;
763 res->defaultOrder = 0;
764 res->avRecordSize = 0;
765 res->maxRecordSize = 0;
769 res->updateInterval = 0;
771 res->proprietary = 0;
772 res->copyrightText = 0;
773 res->copyrightNotice = 0;
774 res->producerContactInfo = 0;
775 res->supplierContactInfo = 0;
776 res->submissionContactInfo = 0;
779 for (c = n->child; c; c = c->next)
783 switch (is_numeric_tag (eh, c))
785 case 600: res->commonInfo = f_commonInfo(eh, c); break;
786 case 102: res->name = f_string(eh, c); break;
787 case 226: res->explainDatabase = odr_nullval(); break;
789 res->num_nicknames = 0;
790 for (n = c->child; n; n = n->next)
792 if (!is_numeric_tag(eh, n) ||
793 n->u.tag.element->tag->value.numeric != 102)
795 (res->num_nicknames)++;
797 if (res->num_nicknames)
799 (char **)odr_malloc (eh->o, res->num_nicknames
800 * sizeof(*res->nicknames));
801 for (n = c->child; n; n = n->next)
803 if (!is_numeric_tag(eh, n) ||
804 n->u.tag.element->tag->value.numeric != 102)
806 res->nicknames[i++] = f_string (eh, n);
809 case 104: res->icon = 0; break; /* fix */
810 case 201: res->userFee = f_bool(eh, c); break;
811 case 202: res->available = f_bool(eh, c); break;
812 case 203: res->titleString = f_humstring(eh, c); break;
814 res->num_keywords = 0;
815 for (n = c->child; n; n = n->next)
817 if (!is_numeric_tag(eh, n) != 1000)
819 (res->num_keywords)++;
821 if (res->num_keywords)
823 (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
824 * sizeof(*res->keywords));
825 for (n = c->child; n; n = n->next)
827 if (!is_numeric_tag(eh, n) != 1000)
829 res->keywords[i++] = f_humstring (eh, n);
832 case 113: res->description = f_humstring(eh, c); break;
834 res->associatedDbs = f_databaseList (eh, c);
837 res->subDbs = f_databaseList (eh, c);
839 case 207: res->disclaimers = f_humstring(eh, c); break;
840 case 103: res->news = f_humstring(eh, c); break;
841 case 209: res->u.actualNumber =
842 f_recordCount(eh, c, &res->which); break;
843 case 212: res->defaultOrder = f_humstring(eh, c); break;
844 case 213: res->avRecordSize = f_integer(eh, c); break;
845 case 214: res->maxRecordSize = f_integer(eh, c); break;
846 case 215: res->hours = f_humstring(eh, c); break;
847 case 216: res->bestTime = f_humstring(eh, c); break;
848 case 217: res->lastUpdate = f_string(eh, c); break;
849 case 218: res->updateInterval = f_intunit(eh, c); break;
850 case 219: res->coverage = f_humstring(eh, c); break;
851 case 220: res->proprietary = f_bool(eh, c); break;
852 case 221: res->copyrightText = f_humstring(eh, c); break;
853 case 222: res->copyrightNotice = f_humstring(eh, c); break;
854 case 223: res->producerContactInfo = f_contactInfo(eh, c); break;
855 case 224: res->supplierContactInfo = f_contactInfo(eh, c); break;
856 case 225: res->submissionContactInfo = f_contactInfo(eh, c); break;
857 case 500: res->accessInfo = f_accessInfo(eh, c); break;
861 res->userFee = eh->false_value;
863 res->available = eh->true_value;
867 Z_StringOrNumeric *f_stringOrNumeric (ExpHandle *eh, data1_node *n)
869 Z_StringOrNumeric *res = (Z_StringOrNumeric *)
870 odr_malloc (eh->o, sizeof(*res));
872 for (c = n->child; c; c = c->next)
874 switch (is_numeric_tag (eh, c))
877 res->which = Z_StringOrNumeric_string;
878 res->u.string = f_string (eh, c);
881 res->which = Z_StringOrNumeric_numeric;
882 res->u.numeric = f_integer (eh, c);
889 Z_AttributeDescription *f_attributeDescription (
890 ExpHandle *eh, data1_node *n)
892 Z_AttributeDescription *res = (Z_AttributeDescription *)
893 odr_malloc(eh->o, sizeof(*res));
898 res->description = 0;
899 res->attributeValue = 0;
900 res->num_equivalentAttributes = 0;
901 res->equivalentAttributes = 0;
903 for (c = n->child; c; c = c->next)
905 switch (is_numeric_tag (eh, c))
907 case 102: res->name = f_string (eh, c); break;
908 case 113: res->description = f_humstring (eh, c); break;
909 case 710: res->attributeValue = f_stringOrNumeric (eh, c); break;
910 case 752: (res->num_equivalentAttributes++); break;
913 if (res->num_equivalentAttributes)
914 res->equivalentAttributes = (Z_StringOrNumeric **)
915 odr_malloc (eh->o, sizeof(*res->equivalentAttributes) *
916 res->num_equivalentAttributes);
917 for (c = n->child; c; c = c->next)
918 if (is_numeric_tag (eh, c) == 752)
919 res->equivalentAttributes[i++] = f_stringOrNumeric (eh, c);
923 Z_AttributeType *f_attributeType (ExpHandle *eh, data1_node *n)
925 Z_AttributeType *res = (Z_AttributeType *)
926 odr_malloc(eh->o, sizeof(*res));
930 res->description = 0;
931 res->attributeType = 0;
932 res->num_attributeValues = 0;
933 res->attributeValues = 0;
935 for (c = n->child; c; c = c->next)
938 switch (is_numeric_tag (eh, c))
940 case 102: res->name = f_string (eh, c); break;
941 case 113: res->description = f_humstring (eh, c); break;
942 case 704: res->attributeType = f_integer (eh, c); break;
944 for (n = c->child; n; n = n->next)
946 if (is_numeric_tag(eh, n) != 709)
948 (res->num_attributeValues)++;
950 if (res->num_attributeValues)
951 res->attributeValues = (Z_AttributeDescription **)
952 odr_malloc (eh->o, res->num_attributeValues
953 * sizeof(*res->attributeValues));
954 for (n = c->child; n; n = n->next)
956 if (is_numeric_tag(eh, n) != 709)
958 res->attributeValues[i++] = f_attributeDescription (eh, n);
966 Z_AttributeSetInfo *f_attributeSetInfo (ExpHandle *eh, data1_node *n)
968 Z_AttributeSetInfo *res = (Z_AttributeSetInfo *)
969 odr_malloc(eh->o, sizeof(*res));
973 res->attributeSet = 0;
975 res->num_attributes = 0;
977 res->description = 0;
978 for (c = n->child; c; c = c->next)
981 switch (is_numeric_tag (eh, c))
983 case 600: res->commonInfo = f_commonInfo (eh, c); break;
984 case 1000: res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
985 case 102: res->name = f_string (eh, c); break;
987 for (n = c->child; n; n = n->next)
989 if (is_numeric_tag(eh, n) != 751)
991 (res->num_attributes)++;
993 if (res->num_attributes)
994 res->attributes = (Z_AttributeType **)
995 odr_malloc (eh->o, res->num_attributes
996 * sizeof(*res->attributes));
997 for (n = c->child; n; n = n->next)
999 if (is_numeric_tag(eh, n) != 751)
1001 res->attributes[i++] = f_attributeType (eh, n);
1004 case 113: res->description = f_humstring (eh, c); break;
1010 Z_OmittedAttributeInterpretation *f_omittedAttributeInterpretation (
1011 ExpHandle *eh, data1_node *n)
1013 Z_OmittedAttributeInterpretation *res = (Z_OmittedAttributeInterpretation*)
1014 odr_malloc (eh->o, sizeof(*res));
1017 res->defaultValue = 0;
1018 res->defaultDescription = 0;
1019 for (c = n->child; c; c = c->next)
1021 switch (is_numeric_tag (eh, c))
1024 res->defaultValue = f_stringOrNumeric (eh, c);
1027 res->defaultDescription = f_humstring(eh, c);
1034 Z_AttributeValue *f_attributeValue (ExpHandle *eh, data1_node *n)
1036 Z_AttributeValue *res = (Z_AttributeValue *)
1037 odr_malloc (eh->o, sizeof(*res));
1041 res->description = 0;
1042 res->num_subAttributes = 0;
1043 res->subAttributes = 0;
1044 res->num_superAttributes = 0;
1045 res->superAttributes = 0;
1046 res->partialSupport = 0;
1047 for (c = n->child; c; c = c->next)
1050 switch (is_numeric_tag (eh, c))
1053 res->value = f_stringOrNumeric (eh, c); break;
1055 res->description = f_humstring (eh, c); break;
1057 for (n = c->child; n; n = n->next)
1059 if (is_numeric_tag(eh, n) != 713)
1061 (res->num_subAttributes)++;
1063 if (res->num_subAttributes)
1064 res->subAttributes =
1065 (Z_StringOrNumeric **)
1066 odr_malloc (eh->o, res->num_subAttributes
1067 * sizeof(*res->subAttributes));
1068 for (n = c->child; n; n = n->next)
1070 if (is_numeric_tag(eh, n) != 713)
1072 res->subAttributes[i++] = f_stringOrNumeric (eh, n);
1076 for (n = c->child; n; n = n->next)
1078 if (is_numeric_tag(eh, n) != 715)
1080 (res->num_superAttributes)++;
1082 if (res->num_superAttributes)
1083 res->superAttributes =
1084 (Z_StringOrNumeric **)
1085 odr_malloc (eh->o, res->num_superAttributes
1086 * sizeof(*res->superAttributes));
1087 for (n = c->child; n; n = n->next)
1089 if (is_numeric_tag(eh, n) != 715)
1091 res->superAttributes[i++] = f_stringOrNumeric (eh, n);
1095 res->partialSupport = odr_nullval ();
1102 Z_AttributeTypeDetails *f_attributeTypeDetails (ExpHandle *eh, data1_node *n)
1104 Z_AttributeTypeDetails *res = (Z_AttributeTypeDetails *)
1105 odr_malloc(eh->o, sizeof(*res));
1107 res->attributeType = 0;
1108 res->defaultIfOmitted = 0;
1109 res->num_attributeValues = 0;
1110 res->attributeValues = 0;
1111 for (c = n->child; c; c = c->next)
1114 switch (is_numeric_tag (eh, c))
1116 case 704: res->attributeType = f_integer (eh, c); break;
1118 res->defaultIfOmitted = f_omittedAttributeInterpretation (eh, c);
1121 for (n = c->child; n; n = n->next)
1123 if (is_numeric_tag(eh, n) != 709)
1125 (res->num_attributeValues)++;
1127 if (res->num_attributeValues)
1128 res->attributeValues =
1129 (Z_AttributeValue **)
1130 odr_malloc (eh->o, res->num_attributeValues
1131 * sizeof(*res->attributeValues));
1132 for (n = c->child; n; n = n->next)
1134 if (is_numeric_tag(eh, n) != 709)
1136 res->attributeValues[i++] = f_attributeValue (eh, n);
1144 Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n)
1146 Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
1147 odr_malloc(eh->o, sizeof(*res));
1150 res->attributeSet = 0;
1151 res->num_attributesByType = 0;
1152 res->attributesByType = 0;
1153 for (c = n->child; c; c = c->next)
1156 switch (is_numeric_tag (eh, c))
1158 case 1000: res->attributeSet = f_oid(eh, c, CLASS_ATTSET); break;
1160 for (n = c->child; n; n = n->next)
1162 if (is_numeric_tag(eh, n) != 703)
1164 (res->num_attributesByType)++;
1166 if (res->num_attributesByType)
1167 res->attributesByType =
1168 (Z_AttributeTypeDetails **)
1169 odr_malloc (eh->o, res->num_attributesByType
1170 * sizeof(*res->attributesByType));
1171 for (n = c->child; n; n = n->next)
1173 if (is_numeric_tag(eh, n) != 703)
1175 res->attributesByType[i++] = f_attributeTypeDetails (eh, n);
1183 Z_AttributeValueList *f_attributeValueList (ExpHandle *eh, data1_node *n)
1185 Z_AttributeValueList *res = (Z_AttributeValueList *)
1186 odr_malloc (eh->o, sizeof(*res));
1190 res->num_attributes = 0;
1191 res->attributes = 0;
1192 for (c = n->child; c; c = c->next)
1193 if (is_numeric_tag (eh, c) == 710)
1194 (res->num_attributes)++;
1195 if (res->num_attributes)
1197 res->attributes = (Z_StringOrNumeric **)
1198 odr_malloc (eh->o, res->num_attributes * sizeof(*res->attributes));
1200 for (c = n->child; c; c = c->next)
1201 if (is_numeric_tag(eh, c) == 710)
1202 res->attributes[i++] = f_stringOrNumeric (eh, c);
1206 Z_AttributeOccurrence *f_attributeOccurrence (ExpHandle *eh, data1_node *n)
1208 Z_AttributeOccurrence *res = (Z_AttributeOccurrence *)
1209 odr_malloc (eh->o, sizeof(*res));
1212 res->attributeSet = 0;
1213 res->attributeType = 0;
1214 res->mustBeSupplied = 0;
1215 res->which = Z_AttributeOcc_any_or_none;
1216 res->attributeValues.any_or_none = odr_nullval ();
1218 for (c = n->child; c; c = c->next)
1220 switch (is_numeric_tag (eh, c))
1223 res->attributeSet = f_oid (eh, c, CLASS_ATTSET); break;
1225 res->attributeType = f_integer (eh, c); break;
1227 res->mustBeSupplied = odr_nullval (); break;
1229 res->which = Z_AttributeOcc_any_or_none;
1230 res->attributeValues.any_or_none = odr_nullval ();
1233 res->which = Z_AttributeOcc_specific;
1234 res->attributeValues.specific = f_attributeValueList (eh, c);
1241 Z_AttributeCombination *f_attributeCombination (ExpHandle *eh, data1_node *n)
1243 Z_AttributeCombination *res = (Z_AttributeCombination *)
1244 odr_malloc (eh->o, sizeof(*res));
1248 res->num_occurrences = 0;
1249 res->occurrences = 0;
1250 for (c = n->child; c; c = c->next)
1251 if (is_numeric_tag (eh, c) == 719)
1252 (res->num_occurrences)++;
1253 if (res->num_occurrences)
1255 res->occurrences = (Z_AttributeOccurrence **)
1256 odr_malloc (eh->o, res->num_occurrences * sizeof(*res->occurrences));
1258 for (c = n->child; c; c = c->next)
1259 if (is_numeric_tag(eh, c) == 719)
1260 res->occurrences[i++] = f_attributeOccurrence (eh, c);
1261 assert (res->num_occurrences);
1265 Z_AttributeCombinations *f_attributeCombinations (ExpHandle *eh, data1_node *n)
1267 Z_AttributeCombinations *res = (Z_AttributeCombinations *)
1268 odr_malloc (eh->o, sizeof(*res));
1270 res->defaultAttributeSet = 0;
1271 res->num_legalCombinations = 0;
1272 res->legalCombinations = 0;
1274 for (c = n->child; c; c = c->next)
1277 switch (is_numeric_tag (eh, c))
1280 res->defaultAttributeSet = f_oid (eh, c, CLASS_ATTSET);
1283 for (n = c->child; n; n = n->next)
1285 if (is_numeric_tag(eh, n) != 718)
1287 (res->num_legalCombinations)++;
1289 if (res->num_legalCombinations)
1290 res->legalCombinations =
1291 (Z_AttributeCombination **)
1292 odr_malloc (eh->o, res->num_legalCombinations
1293 * sizeof(*res->legalCombinations));
1294 for (n = c->child; n; n = n->next)
1296 if (is_numeric_tag(eh, n) != 718)
1298 res->legalCombinations[i++] = f_attributeCombination (eh, n);
1303 assert (res->num_legalCombinations);
1307 Z_AttributeDetails *f_attributeDetails (ExpHandle *eh, data1_node *n)
1309 Z_AttributeDetails *res = (Z_AttributeDetails *)
1310 odr_malloc(eh->o, sizeof(*res));
1313 res->commonInfo = 0;
1314 res->databaseName = 0;
1315 res->num_attributesBySet = 0;
1316 res->attributesBySet = NULL;
1317 res->attributeCombinations = NULL;
1319 for (c = n->child; c; c = c->next)
1322 switch (is_numeric_tag (eh, c))
1324 case 600: res->commonInfo = f_commonInfo(eh, c); break;
1325 case 102: res->databaseName = f_string (eh, c); break;
1327 for (n = c->child; n; n = n->next)
1329 if (is_numeric_tag(eh, n) != 701)
1331 (res->num_attributesBySet)++;
1333 if (res->num_attributesBySet)
1334 res->attributesBySet =
1335 (Z_AttributeSetDetails **)
1336 odr_malloc (eh->o, res->num_attributesBySet
1337 * sizeof(*res->attributesBySet));
1338 for (n = c->child; n; n = n->next)
1340 if (is_numeric_tag(eh, n) != 701)
1342 res->attributesBySet[i++] = f_attributeSetDetails (eh, n);
1346 res->attributeCombinations = f_attributeCombinations (eh, c);
1353 Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n,
1357 Z_ExplainRecord *res = (Z_ExplainRecord *)odr_malloc(o, sizeof(*res));
1362 eh.false_value = (int *)odr_malloc(eh.o, sizeof(eh.false_value));
1363 *eh.false_value = 0;
1364 eh.true_value = (int *)odr_malloc(eh.o, sizeof(eh.true_value));
1367 assert(n->which == DATA1N_root);
1368 if (strcmp(n->u.root.type, "explain"))
1370 yaz_log(YLOG_WARN, "Attempt to convert a non-Explain record");
1373 for (n = n->child; n; n = n->next)
1375 switch (is_numeric_tag (&eh, n))
1378 res->which = Z_Explain_categoryList;
1379 if (!(res->u.categoryList = f_categoryList(&eh, n)))
1383 res->which = Z_Explain_targetInfo;
1384 if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
1388 res->which = Z_Explain_databaseInfo;
1389 if (!(res->u.databaseInfo = f_databaseInfo(&eh, n)))
1393 res->which = Z_Explain_attributeSetInfo;
1394 if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
1398 res->which = Z_Explain_attributeDetails;
1399 if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
1404 yaz_log(YLOG_WARN, "No category in Explain record");
1410 * indent-tabs-mode: nil
1412 * vim: shiftwidth=4 tabstop=8 expandtab