source: trunk/gsdl/packages/yaz/ill/ill-get.c@ 1343

Last change on this file since 1343 was 1343, checked in by johnmcp, 24 years ago

Added the YAZ toolkit source to the packages directory (for z39.50 stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 KB
Line 
1/*
2 * Copyright (c) 1999-2000, Index Data.
3 * See the file LICENSE for details.
4 *
5 * $Log$
6 * Revision 1.1 2000/08/03 03:10:26 johnmcp
7 * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
8 *
9 * Revision 1.5 2000/02/24 08:52:01 adam
10 * Bug fix.
11 *
12 * Revision 1.4 2000/02/04 11:01:15 adam
13 * Added more elements.
14 *
15 * Revision 1.3 2000/01/31 13:15:21 adam
16 * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
17 * that some characters are not surrounded by spaces in resulting term.
18 * ILL-code updates.
19 *
20 * Revision 1.2 2000/01/15 09:38:51 adam
21 * Implemented ill_get_ILLRequest. Added some type mappings for ILL protocol.
22 *
23 * Revision 1.1 1999/12/16 23:36:19 adam
24 * Implemented ILL protocol. Minor updates ASN.1 compiler.
25 *
26 */
27
28#include <yaz/ill.h>
29
30bool_t *ill_get_bool (struct ill_get_ctl *gc, const char *name,
31 const char *sub, int val)
32{
33 ODR o = gc->odr;
34 char element[128];
35 const char *v;
36 bool_t *r = odr_malloc (o, sizeof(*r));
37
38 strcpy(element, name);
39 if (sub)
40 {
41 strcat (element, ",");
42 strcat (element, sub);
43 }
44
45 v = (gc->f)(gc->clientData, element);
46 if (v)
47 val = atoi(v);
48 else if (val < 0)
49 return 0;
50 *r = val;
51 return r;
52}
53
54int *ill_get_int (struct ill_get_ctl *gc, const char *name,
55 const char *sub, int val)
56{
57 ODR o = gc->odr;
58 char element[128];
59 const char *v;
60 int *r = odr_malloc (o, sizeof(*r));
61
62 strcpy(element, name);
63 if (sub)
64 {
65 strcat (element, ",");
66 strcat (element, sub);
67 }
68 v = (gc->f)(gc->clientData, element);
69 if (v)
70 val = atoi(v);
71 *r = val;
72 return r;
73}
74
75int *ill_get_enumerated (struct ill_get_ctl *gc, const char *name,
76 const char *sub, int val)
77{
78 return ill_get_int(gc, name, sub, val);
79}
80
81ILL_String *ill_get_ILL_String (struct ill_get_ctl *gc, const char *name,
82 const char *sub)
83{
84 ILL_String *r = (ILL_String *) odr_malloc (gc->odr, sizeof(*r));
85 char element[128];
86 const char *v;
87
88 strcpy(element, name);
89 if (sub)
90 {
91 strcat (element, ",");
92 strcat (element, sub);
93 }
94 v = (gc->f)(gc->clientData, element);
95 if (!v)
96 return 0;
97 r->which = ILL_String_GeneralString;
98 r->u.GeneralString = odr_strdup (gc->odr, v);
99 return r;
100}
101
102
103ILL_ISO_Date *ill_get_ILL_ISO_Date (struct ill_get_ctl *gc, const char *name,
104 const char *sub, const char *val)
105{
106 char element[128];
107 const char *v;
108
109 strcpy(element, name);
110 if (sub)
111 {
112 strcat (element, ",");
113 strcat (element, sub);
114 }
115 v = (gc->f)(gc->clientData, element);
116 if (!v)
117 v = val;
118 if (!v)
119 return 0;
120 return odr_strdup (gc->odr, v);
121}
122
123ILL_ISO_Time *ill_get_ILL_ISO_Time (struct ill_get_ctl *gc, const char *name,
124 const char *sub, const char *val)
125{
126 char element[128];
127 const char *v;
128
129 strcpy(element, name);
130 if (sub)
131 {
132 strcat (element, ",");
133 strcat (element, sub);
134 }
135 v = (gc->f)(gc->clientData, element);
136 if (!v)
137 v = val;
138 if (!v)
139 return 0;
140 return odr_strdup (gc->odr, v);
141}
142
143ILL_Person_Or_Institution_Symbol *ill_get_Person_Or_Insitution_Symbol (
144 struct ill_get_ctl *gc, const char *name, const char *sub)
145{
146 char element[128];
147 ODR o = gc->odr;
148 ILL_Person_Or_Institution_Symbol *p = odr_malloc (o, sizeof(*p));
149
150 strcpy(element, name);
151 if (sub)
152 {
153 strcat (element, ",");
154 strcat (element, sub);
155 }
156 p->which = ILL_Person_Or_Institution_Symbol_person_symbol;
157 if ((p->u.person_symbol = ill_get_ILL_String (gc, element, "person")))
158 return p;
159
160 p->which = ILL_Person_Or_Institution_Symbol_institution_symbol;
161 if ((p->u.institution_symbol =
162 ill_get_ILL_String (gc, element, "institution")))
163 return p;
164 return 0;
165}
166
167static ILL_Name_Of_Person_Or_Institution *ill_get_Name_Of_Person_Or_Institution(
168 struct ill_get_ctl *gc, const char *name, const char *sub)
169{
170 char element[128];
171 ODR o = gc->odr;
172 ILL_Name_Of_Person_Or_Institution *p = odr_malloc (o, sizeof(*p));
173
174 strcpy(element, name);
175 if (sub)
176 {
177 strcat (element, ",");
178 strcat (element, sub);
179 }
180 p->which = ILL_Name_Of_Person_Or_Institution_name_of_person;
181 if ((p->u.name_of_person =
182 ill_get_ILL_String (gc, element, "name-of-person")))
183 return p;
184
185 p->which = ILL_Name_Of_Person_Or_Institution_name_of_institution;
186 if ((p->u.name_of_institution =
187 ill_get_ILL_String (gc, element, "name-of-institution")))
188 return p;
189 return 0;
190}
191
192ILL_System_Id *ill_get_System_Id(struct ill_get_ctl *gc,
193 const char *name, const char *sub)
194{
195 ODR o = gc->odr;
196 char element[128];
197 ILL_System_Id *p;
198
199 strcpy(element, name);
200 if (sub)
201 {
202 strcat (element, ",");
203 strcat (element, sub);
204 }
205 p = (ILL_System_Id *) odr_malloc (o, sizeof(*p));
206 p->person_or_institution_symbol = ill_get_Person_Or_Insitution_Symbol (
207 gc, element, "person-or-institution-symbol");
208 p->name_of_person_or_institution = ill_get_Name_Of_Person_Or_Institution (
209 gc, element, "name-of-person-or-institution");
210 return p;
211}
212
213ILL_Transaction_Id *ill_get_Transaction_Id (struct ill_get_ctl *gc,
214 const char *name, const char *sub)
215{
216 ODR o = gc->odr;
217 ILL_Transaction_Id *r = (ILL_Transaction_Id *) odr_malloc (o, sizeof(*r));
218 char element[128];
219
220 strcpy(element, name);
221 if (sub)
222 {
223 strcat (element, ",");
224 strcat (element, sub);
225 }
226 r->initial_requester_id =
227 ill_get_System_Id (gc, element, "initial-requester-id");
228 r->transaction_group_qualifier =
229 ill_get_ILL_String (gc, element, "transaction-group-qualifier");
230 r->transaction_qualifier =
231 ill_get_ILL_String (gc, element, "transaction-qualifier");
232 r->sub_transaction_qualifier =
233 ill_get_ILL_String (gc, element, "sub-transaction-qualifier");
234 return r;
235}
236
237
238ILL_Service_Date_this *ill_get_Service_Date_this (
239 struct ill_get_ctl *gc, const char *name, const char *sub)
240{
241 ODR o = gc->odr;
242 ILL_Service_Date_this *r =
243 (ILL_Service_Date_this *) odr_malloc (o, sizeof(*r));
244 char element[128];
245
246 strcpy(element, name);
247 if (sub)
248 {
249 strcat (element, ",");
250 strcat (element, sub);
251 }
252 r->date = ill_get_ILL_ISO_Date (gc, element, "date", "20000101");
253 r->time = ill_get_ILL_ISO_Time (gc, element, "time", 0);
254 return r;
255}
256
257ILL_Service_Date_original *ill_get_Service_Date_original (
258 struct ill_get_ctl *gc, const char *name, const char *sub)
259{
260 ODR o = gc->odr;
261 ILL_Service_Date_original *r =
262 (ILL_Service_Date_original *) odr_malloc (o, sizeof(*r));
263 char element[128];
264
265 strcpy(element, name);
266 if (sub)
267 {
268 strcat (element, ",");
269 strcat (element, sub);
270 }
271 r->date = ill_get_ILL_ISO_Date (gc, element, "date", 0);
272 r->time = ill_get_ILL_ISO_Time (gc, element, "time", 0);
273 if (!r->date && !r->time)
274 return 0;
275 return r;
276}
277
278ILL_Service_Date_Time *ill_get_Service_Date_Time (
279 struct ill_get_ctl *gc, const char *name, const char *sub)
280{
281 ODR o = gc->odr;
282 ILL_Service_Date_Time *r =
283 (ILL_Service_Date_Time *) odr_malloc (o, sizeof(*r));
284 char element[128];
285
286 strcpy(element, name);
287 if (sub)
288 {
289 strcat (element, ",");
290 strcat (element, sub);
291 }
292 r->date_time_of_this_service = ill_get_Service_Date_this (
293 gc, element, "this");
294 r->date_time_of_original_service = ill_get_Service_Date_original (
295 gc, element, "original");
296 return r;
297}
298
299ILL_Requester_Optional_Messages_Type *ill_get_Requester_Optional_Messages_Type (
300 struct ill_get_ctl *gc, const char *name, const char *sub)
301{
302 ODR o = gc->odr;
303 ILL_Requester_Optional_Messages_Type *r =
304 (ILL_Requester_Optional_Messages_Type *) odr_malloc (o, sizeof(*r));
305 char element[128];
306
307 strcpy(element, name);
308 if (sub)
309 {
310 strcat (element, ",");
311 strcat (element, sub);
312 }
313 r->can_send_RECEIVED = ill_get_bool (gc, element, "can-send-RECEIVED", 0);
314 r->can_send_RETURNED = ill_get_bool (gc, element, "can-send-RETURNED", 0);
315 r->requester_SHIPPED =
316 ill_get_enumerated (gc, element, "requester-SHIPPED", 1);
317 r->requester_CHECKED_IN =
318 ill_get_enumerated (gc, element, "requester-CHECKED-IN", 1);
319 return r;
320}
321
322ILL_Item_Id *ill_get_Item_Id (
323 struct ill_get_ctl *gc, const char *name, const char *sub)
324{
325 ODR o = gc->odr;
326 ILL_Item_Id *r = (ILL_Item_Id *) odr_malloc (o, sizeof(*r));
327 char element[128];
328
329 strcpy(element, name);
330 if (sub)
331 {
332 strcat (element, ",");
333 strcat (element, sub);
334 }
335 r->item_type = ill_get_enumerated (gc, element, "item-type",
336 ILL_Item_Id_monograph);
337 r->held_medium_type = 0;
338 r->call_number = ill_get_ILL_String(gc, element, "call-number");
339 r->author = ill_get_ILL_String(gc, element, "author");
340 r->title = ill_get_ILL_String(gc, element, "title");
341 r->sub_title = ill_get_ILL_String(gc, element, "sub-title");
342 r->sponsoring_body = ill_get_ILL_String(gc, element, "sponsoring-body");
343 r->place_of_publication =
344 ill_get_ILL_String(gc, element, "place-of-publication");
345 r->publisher = ill_get_ILL_String(gc, element, "publisher");
346 r->series_title_number =
347 ill_get_ILL_String(gc, element, "series-title-number");
348 r->volume_issue = ill_get_ILL_String(gc, element, "volume-issue");
349 r->edition = ill_get_ILL_String(gc, element, "edition");
350 r->publication_date = ill_get_ILL_String(gc, element, "publication-date");
351 r->publication_date_of_component =
352 ill_get_ILL_String(gc, element, "publication-date-of-component");
353 r->author_of_article = ill_get_ILL_String(gc, element,
354 "author-of-article");
355 r->title_of_article = ill_get_ILL_String(gc, element, "title-or-article");
356 r->pagination = ill_get_ILL_String(gc, element, "pagination");
357 r->national_bibliography_no = 0;
358 r->iSBN = ill_get_ILL_String(gc, element, "ISBN");
359 r->iSSN = ill_get_ILL_String(gc, element, "ISSN");
360 r->system_no = 0;
361 r->additional_no_letters =
362 ill_get_ILL_String(gc, element, "additional-no-letters");
363 r->verification_reference_source =
364 ill_get_ILL_String(gc, element, "verification-reference-source");
365 return r;
366}
367
368ILL_ItemRequest *ill_get_ItemRequest (
369 struct ill_get_ctl *gc, const char *name, const char *sub)
370{
371 ODR o = gc->odr;
372 ILL_ItemRequest *r = (ILL_ItemRequest *)odr_malloc(o, sizeof(*r));
373 return 0;
374}
375
376
377ILL_Client_Id *ill_get_Client_Id (
378 struct ill_get_ctl *gc, const char *name, const char *sub)
379{
380 char element[128];
381 ODR o = gc->odr;
382 ILL_Client_Id *r = (ILL_Client_Id *) odr_malloc(o, sizeof(*r));
383
384 strcpy(element, name);
385 if (sub)
386 {
387 strcat (element, ",");
388 strcat (element, sub);
389 }
390 r->client_name = ill_get_ILL_String (gc, element, "client-name");
391 r->client_status = ill_get_ILL_String (gc, element, "client-status");
392 r->client_identifier = ill_get_ILL_String (gc, element,
393 "client-identifier");
394 return r;
395}
396
397ILL_Postal_Address *ill_get_Postal_Address (
398 struct ill_get_ctl *gc, const char *name, const char *sub)
399{
400 ODR o = gc->odr;
401 ILL_Postal_Address *r =
402 (ILL_Postal_Address *) odr_malloc(o, sizeof(*r));
403 char element[128];
404
405 strcpy(element, name);
406 if (sub)
407 {
408 strcat (element, ",");
409 strcat (element, sub);
410 }
411 r->name_of_person_or_institution =
412 ill_get_Name_Of_Person_Or_Institution (
413 gc, element, "name-of-person-or-institution");
414 r->extended_postal_delivery_address =
415 ill_get_ILL_String (
416 gc, element, "extended-postal-delivery-address");
417 r->street_and_number =
418 ill_get_ILL_String (gc, element, "street-and-number");
419 r->post_office_box =
420 ill_get_ILL_String (gc, element, "post-office-box");
421 r->city = ill_get_ILL_String (gc, element, "city");
422 r->region = ill_get_ILL_String (gc, element, "region");
423 r->country = ill_get_ILL_String (gc, element, "country");
424 r->postal_code = ill_get_ILL_String (gc, element, "postal-code");
425 return r;
426}
427
428ILL_System_Address *ill_get_System_Address (
429 struct ill_get_ctl *gc, const char *name, const char *sub)
430{
431 ODR o = gc->odr;
432 ILL_System_Address *r =
433 (ILL_System_Address *) odr_malloc(o, sizeof(*r));
434 char element[128];
435
436 strcpy(element, name);
437 if (sub)
438 {
439 strcat (element, ",");
440 strcat (element, sub);
441 }
442 r->telecom_service_identifier =
443 ill_get_ILL_String (gc, element, "telecom-service-identifier");
444 r->telecom_service_address =
445 ill_get_ILL_String (gc, element, "telecom-service-addreess");
446 return r;
447}
448
449ILL_Delivery_Address *ill_get_Delivery_Address (
450 struct ill_get_ctl *gc, const char *name, const char *sub)
451{
452 ODR o = gc->odr;
453 ILL_Delivery_Address *r =
454 (ILL_Delivery_Address *) odr_malloc(o, sizeof(*r));
455 char element[128];
456
457 strcpy(element, name);
458 if (sub)
459 {
460 strcat (element, ",");
461 strcat (element, sub);
462 }
463 r->postal_address =
464 ill_get_Postal_Address (gc, element, "postal-address");
465 r->electronic_address =
466 ill_get_System_Address (gc, element, "electronic-address");
467 return r;
468}
469
470ILL_Search_Type *ill_get_Search_Type (
471 struct ill_get_ctl *gc, const char *name, const char *sub)
472{
473 ODR o = gc->odr;
474 ILL_Search_Type *r = (ILL_Search_Type *) odr_malloc(o, sizeof(*r));
475 char element[128];
476
477 strcpy(element, name);
478 if (sub)
479 {
480 strcat (element, ",");
481 strcat (element, sub);
482 }
483 r->level_of_service = ill_get_ILL_String (gc, element, "level-of-service");
484 r->need_before_date = ill_get_ILL_ISO_Date (gc, element,
485 "need-before-date", 0);
486 r->expiry_date = ill_get_ILL_ISO_Date (gc, element, "expiry-date", 0);
487 r->expiry_flag = ill_get_enumerated (gc, element, "expiry-flag", 3);
488
489 return r;
490}
491
492ILL_Request *ill_get_ILLRequest (
493 struct ill_get_ctl *gc, const char *name, const char *sub)
494{
495 ODR o = gc->odr;
496 ILL_Request *r = (ILL_Request *) odr_malloc(o, sizeof(*r));
497 char element[128];
498
499 strcpy(element, name);
500 if (sub)
501 {
502 strcat (element, ",");
503 strcat (element, sub);
504 }
505 r->protocol_version_num =
506 ill_get_enumerated (gc, element, "protocol-version-num",
507 ILL_Request_version_2);
508
509 r->transaction_id = ill_get_Transaction_Id (gc, element, "transaction-id");
510 r->service_date_time =
511 ill_get_Service_Date_Time (gc, element, "service-date-time");
512 r->requester_id = ill_get_System_Id (gc, element, "requester-id");
513 r->responder_id = ill_get_System_Id (gc, element, "responder-id");
514 r->transaction_type =
515 ill_get_enumerated(gc, element, "transaction-type", 1);
516
517 r->delivery_address =
518 ill_get_Delivery_Address (gc, element, "delivery-address");
519 r->delivery_service = 0; /* TODO */
520 /* ill_get_Delivery_Service (gc, element, "delivery-service"); */
521 r->billing_address =
522 ill_get_Delivery_Address (gc, element, "billing-address");
523
524 r->num_iLL_service_type = 1;
525 r->iLL_service_type = (ILL_Service_Type **)
526 odr_malloc (o, sizeof(*r->iLL_service_type));
527 *r->iLL_service_type =
528 ill_get_enumerated (gc, element, "ill-service-type",
529 ILL_Service_Type_copy_non_returnable);
530
531 r->responder_specific_service = 0;
532 r->requester_optional_messages =
533 ill_get_Requester_Optional_Messages_Type (
534 gc, element,"requester-optional-messages");
535 r->search_type = 0; /* TODO */
536 r->num_supply_medium_info_type = 0;
537 r->supply_medium_info_type = 0;
538
539 r->place_on_hold = ill_get_enumerated (
540 gc, element, "place-on-hold",
541 ILL_Place_On_Hold_Type_according_to_responder_policy);
542 r->client_id = ill_get_Client_Id (gc, element, "client-id");
543
544 r->item_id = ill_get_Item_Id (gc, element, "item-id");
545 r->supplemental_item_description = 0;
546 r->cost_info_type = 0;
547 r->copyright_compliance =
548 ill_get_ILL_String(gc, element, "copyright-complicance");
549 r->third_party_info_type = 0;
550 r->retry_flag = ill_get_bool (gc, element, "retry-flag", 0);
551 r->forward_flag = ill_get_bool (gc, element, "forward-flag", 0);
552 r->requester_note = ill_get_ILL_String(gc, element, "requester-note");
553 r->forward_note = ill_get_ILL_String(gc, element, "forward-note");
554 r->num_iLL_request_extensions = 0;
555 r->iLL_request_extensions = 0;
556 return r;
557}
Note: See TracBrowser for help on using the repository browser.