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