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