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