2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_expout.c,v $
7 * Revision 1.1 1995-12-14 11:09:51 quinn
21 static int *f_integer(data1_node *c, ODR o)
26 if (!c->child || c->child->which != DATA1N_data ||
27 c->child->u.data.len > 63)
29 r = odr_malloc(o, sizeof(*r));
30 sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
35 static char *f_string(data1_node *c, ODR o)
39 if (!c->child || c->child->which != DATA1N_data)
41 r = odr_malloc(o, c->child->u.data.len+1);
42 memcpy(r, c->child->u.data.data, c->child->u.data.len);
43 r[c->child->u.data.len] = '\0';
47 static bool_t *f_bool(data1_node *c, ODR o)
52 static Z_IntUnit *f_intunit(data1_node *c, ODR o)
57 static Z_HumanString *f_humstring(data1_node *c, ODR o)
62 if (!c->child || c->child->which != DATA1N_data)
64 r = odr_malloc(o, sizeof(*r));
66 r->strings = odr_malloc(o, sizeof(Z_HumanStringUnit*));
67 r->strings[0] = u = odr_malloc(o, sizeof(*u));
69 u->text = odr_malloc(o, c->child->u.data.len+1);
70 memcpy(u->text, c->child->u.data.data, c->child->u.data.len);
71 u->text[c->child->u.data.len] = '\0';
75 static Z_CommonInfo *f_commonInfo(data1_node *n, int select, ODR o)
80 static Z_AccessInfo *f_accessInfo(data1_node *n, int select, ODR o)
85 static Z_ContactInfo *f_contactInfo(data1_node *n, ODR o)
90 static Z_TargetInfo *f_targetInfo(data1_node *n, int select, ODR o)
92 Z_TargetInfo *res = odr_malloc(o, sizeof(*res));
100 res->namedResultSets = &fl;
101 res->multipleDbSearch = &fl;
102 res->maxResultSets = 0;
103 res->maxResultSize = 0;
105 res->timeoutInterval = 0;
106 res->welcomeMessage = 0;
107 res->contactInfo = 0;
108 res->description = 0;
109 res->num_nicknames = 0;
112 res->paymentAddr = 0;
114 res->num_dbCombinations = 0;
115 res->dbCombinations = 0;
116 res->num_addresses = 0;
118 res->commonAccessInfo = 0;
120 for (c = n->child; c; c = c->next)
122 if (c->which != DATA1N_tag || !c->u.tag.element)
124 logf(LOG_WARN, "Malformed explain record");
127 if (select && !c->u.tag.node_selected)
129 switch (c->u.tag.element->tag->value.numeric)
131 case 600: res->commonInfo = f_commonInfo(c, select, o);break;
132 case 102: res->name = f_string(c, o); break;
133 case 103: res->recentNews = f_humstring(c, o); break;
134 case 104: break; /* icon */
135 case 105: res->namedResultSets = f_bool(c, o); break;
136 case 106: res->multipleDbSearch = f_bool(c, o); break;
137 case 107: res->maxResultSets = f_integer(c, o); break;
138 case 108: res->maxResultSize = f_integer(c, o); break;
139 case 109: res->maxTerms = f_integer(c, o); break;
140 case 110: res->timeoutInterval = f_intunit(c, o); break;
141 case 111: res->welcomeMessage = f_humstring(c, o); break;
142 case 112: res->contactInfo = f_contactInfo(c, o); break;
143 case 113: res->description = f_humstring(c, o); break;
144 case 114: break; /* nicknames */
145 case 115: res->usageRest = f_humstring(c, o); break;
146 case 116: res->paymentAddr = f_humstring(c, o); break;
147 case 117: res->hours = f_humstring(c, o); break;
148 case 118: break; /* dbcombinations */
149 case 119: break; /* addresses */
150 case 500: res->commonAccessInfo = f_accessInfo(c, select, o); break;
152 logf(LOG_WARN, "Unknown target-info element");
158 static Z_DatabaseInfo *f_databaseInfo(data1_node *n, int select, ODR o)
163 Z_ExplainRecord *data1_nodetoexplain(data1_node *n, int select, ODR o)
165 Z_ExplainRecord *res = odr_malloc(o, sizeof(*res));
167 assert(n->which == DATA1N_root);
168 if (strcmp(n->u.root.type, "explain"))
170 logf(LOG_WARN, "Attempt to convert a non-Explain record");
173 if (n->num_children != 1 || n->child->which != DATA1N_tag ||
176 logf(LOG_WARN, "Explain record should have one exactly one child");
179 switch (n->child->u.tag.element->tag->value.numeric)
181 case 0: res->which = Z_Explain_targetInfo;
182 if (!(res->u.targetInfo = f_targetInfo(n->child, select, o)))
185 case 1: res->which = Z_Explain_databaseInfo;
186 if (!(res->u.databaseInfo = f_databaseInfo(n->child, select, o)))
190 logf(LOG_WARN, "Unknown explain category");