Removed uses of assert(3). Cleanup of ODR. CCL parser update so
[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.3  2000-01-31 13:15:21  adam
7  * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
8  * that some characters are not surrounded by spaces in resulting term.
9  * ILL-code updates.
10  *
11  * Revision 1.2  2000/01/15 09:38:51  adam
12  * Implemented ill_get_ILLRequest. Added some type mappings for ILL protocol.
13  *
14  * Revision 1.1  1999/12/16 23:36:19  adam
15  * Implemented ILL protocol. Minor updates ASN.1 compiler.
16  *
17  */
18
19 #include <yaz/ill.h>
20
21 bool_t *ill_get_bool (struct ill_get_ctl *gc, const char *name,
22                       const char *sub, int val)
23 {
24     ODR o = gc->odr;
25     char element[128];
26     const char *v;
27     bool_t *r = odr_malloc (o, sizeof(*r));
28     
29     strcpy(element, name);
30     if (sub)
31     {
32         strcat (element, ",");
33         strcat (element, sub);
34     }    
35
36     v = (gc->f)(gc->clientData, element);
37     if (v)
38         val = atoi(v);
39     else if (val < 0)
40         return 0;
41     *r = val;
42     return r;
43 }
44
45 int *ill_get_int (struct ill_get_ctl *gc, const char *name,
46                   const char *sub, int val)
47 {
48     ODR o = gc->odr;
49     char element[128];
50     const char *v;
51     int *r = odr_malloc (o, sizeof(*r));
52     
53     strcpy(element, name);
54     if (sub)
55     {
56         strcat (element, ",");
57         strcat (element, sub);
58     }    
59     v = (gc->f)(gc->clientData, element);
60     if (v)
61         val = atoi(v);
62     *r = val;
63     return r;
64 }
65
66 int *ill_get_enumerated (struct ill_get_ctl *gc, const char *name,
67                          const char *sub, int val)
68 {
69     return ill_get_int(gc, name, sub, val);
70 }
71
72 ILL_String *ill_get_ILL_String (struct ill_get_ctl *gc, const char *name,
73                                 const char *sub)
74 {
75     ILL_String *r = (ILL_String *) odr_malloc (gc->odr, sizeof(*r));
76     char element[128];
77     const char *v;
78
79     strcpy(element, name);
80     if (sub)
81     {
82         strcat (element, ",");
83         strcat (element, sub);
84     }
85     v = (gc->f)(gc->clientData, element);
86     if (!v)
87         return 0;
88     r->which = ILL_String_GeneralString;
89     r->u.GeneralString = odr_strdup (gc->odr, v);
90     return r;
91 }
92
93 ILL_Person_Or_Institution_Symbol *ill_get_Person_Or_Insitution_Symbol (
94     struct ill_get_ctl *gc, const char *name, const char *sub)
95 {
96     char element[128];
97     ODR o = gc->odr;
98     ILL_Person_Or_Institution_Symbol *p = odr_malloc (o, sizeof(*p));
99     
100     strcpy(element, name);
101     if (sub)
102     {
103         strcat (element, ",");
104         strcat (element, sub);
105     }
106     p->which = ILL_Person_Or_Institution_Symbol_person_symbol;
107     if ((p->u.person_symbol = ill_get_ILL_String (gc, element, "person")))
108         return p;
109
110     p->which = ILL_Person_Or_Institution_Symbol_institution_symbol;
111     if ((p->u.institution_symbol =
112          ill_get_ILL_String (gc, element, "institution")))
113         return p;
114     return 0;
115 }
116
117 static ILL_Name_Of_Person_Or_Institution *ill_get_Name_Of_Person_Or_Institution(
118     struct ill_get_ctl *gc, const char *name, const char *sub)
119 {
120     char element[128];
121     ODR o = gc->odr;
122     ILL_Name_Of_Person_Or_Institution *p = odr_malloc (o, sizeof(*p));
123     
124     strcpy(element, name);
125     if (sub)
126     {
127         strcat (element, ",");
128         strcat (element, sub);
129     }
130     p->which = ILL_Name_Of_Person_Or_Institution_name_of_person;
131     if ((p->u.name_of_person =
132          ill_get_ILL_String (gc, element, "name-of-person")))
133         return p;
134
135     p->which = ILL_Name_Of_Person_Or_Institution_name_of_institution;
136     if ((p->u.name_of_institution =
137          ill_get_ILL_String (gc, element, "name-of-institution")))
138         return p;
139     return 0;
140 }
141     
142 ILL_System_Id *ill_get_System_Id(struct ill_get_ctl *gc,
143                                  const char *name, const char *sub)
144 {
145     ODR o = gc->odr;
146     char element[128];
147     ILL_System_Id *p;
148     
149     strcpy(element, name);
150     if (sub)
151     {
152         strcat (element, ",");
153         strcat (element, sub);
154     }
155     p = (ILL_System_Id *) odr_malloc (o, sizeof(*p));
156     p->person_or_institution_symbol =
157         ill_get_Person_Or_Insitution_Symbol (gc, element,
158                                              "person-or-institution-symbol");
159     p->name_of_person_or_institution =
160         ill_get_Name_Of_Person_Or_Institution (gc, element,
161                                                "name-of-person-or-institution");
162     return p;
163 }
164
165 ILL_Transaction_Id *ill_get_Transaction_Id (struct ill_get_ctl *gc,
166                                             const char *name, const char *sub)
167 {
168     ODR o = gc->odr;
169     ILL_Transaction_Id *r = (ILL_Transaction_Id *) odr_malloc (o, sizeof(*r));
170     char element[128];
171     
172     strcpy(element, name);
173     if (sub)
174     {
175         strcat (element, ",");
176         strcat (element, sub);
177     }    
178     r->initial_requester_id =
179         ill_get_System_Id (gc, element, "initial-requester-id");
180     r->transaction_group_qualifier =
181         ill_get_ILL_String (gc, element, "transaction-group-qualifier");
182     r->transaction_qualifier =
183         ill_get_ILL_String (gc, element, "transaction-qualifier");
184     r->sub_transaction_qualifier =
185         ill_get_ILL_String (gc, element, "sub-transaction-qualifier");
186     return r;
187 }
188
189
190 ILL_Service_Date_this *ill_get_Service_Date_this (
191     struct ill_get_ctl *gc, const char *name, const char *sub)
192 {
193     ODR o = gc->odr;
194     ILL_Service_Date_this *r =
195         (ILL_Service_Date_this *) odr_malloc (o, sizeof(*r));
196     char element[128];
197     
198     strcpy(element, name);
199     if (sub)
200     {
201         strcat (element, ",");
202         strcat (element, sub);
203     }
204     r->date = odr_strdup (o, "14012000");
205     r->time = 0;
206     return r;
207 }
208
209 ILL_Service_Date_Time *ill_get_Service_Date_Time (
210     struct ill_get_ctl *gc, const char *name, const char *sub)
211 {
212     ODR o = gc->odr;
213     ILL_Service_Date_Time *r =
214         (ILL_Service_Date_Time *) odr_malloc (o, sizeof(*r));
215     char element[128];
216     
217     strcpy(element, name);
218     if (sub)
219     {
220         strcat (element, ",");
221         strcat (element, sub);
222     }    
223     r->date_time_of_this_service = ill_get_Service_Date_this (gc, element, 
224                                                               "this");
225     r->date_time_of_original_service = 0;
226     return r;
227 }
228
229 ILL_Requester_Optional_Messages_Type *ill_get_Requester_Optional_Messages_Type (
230     struct ill_get_ctl *gc, const char *name, const char *sub)
231 {
232     ODR o = gc->odr;
233     ILL_Requester_Optional_Messages_Type *r =
234         (ILL_Requester_Optional_Messages_Type *) odr_malloc (o, sizeof(*r));
235     char element[128];
236     
237     strcpy(element, name);
238     if (sub)
239     {
240         strcat (element, ",");
241         strcat (element, sub);
242     }
243     r->can_send_RECEIVED = ill_get_bool (gc, element, "can-send-RECEIVED", 0);
244     r->can_send_RETURNED = ill_get_bool (gc, element, "can-send-RETURNED", 0);
245     r->requester_SHIPPED =
246         ill_get_enumerated (gc, element, "requester-SHIPPED", 1);
247     r->requester_CHECKED_IN =
248         ill_get_enumerated (gc, element, "requester-CHECKED-IN", 1);
249     return r;
250 }
251
252 ILL_Item_Id *ill_get_Item_Id (
253     struct ill_get_ctl *gc, const char *name, const char *sub)   
254 {
255     ODR o = gc->odr;
256     ILL_Item_Id *r = (ILL_Item_Id *) 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->item_type = ill_get_enumerated (gc, element, "item-type",
266                                        ILL_Item_Id_monograph);
267     r->held_medium_type = 0;
268     r->call_number = ill_get_ILL_String(gc, element, "call-number");
269     r->author = ill_get_ILL_String(gc, element, "author");
270     r->title = ill_get_ILL_String(gc, element, "title");
271     r->sub_title = ill_get_ILL_String(gc, element, "sub-title");
272     r->sponsoring_body = ill_get_ILL_String(gc, element, "sponsoring-body");
273     r->place_of_publication =
274         ill_get_ILL_String(gc, element, "place-of-publication");
275     r->publisher = ill_get_ILL_String(gc, element, "publisher");
276     r->series_title_number =
277         ill_get_ILL_String(gc, element, "series-title-number");
278     r->volume_issue = ill_get_ILL_String(gc, element, "volume-issue");
279     r->edition = ill_get_ILL_String(gc, element, "edition");
280     r->publication_date = ill_get_ILL_String(gc, element, "publication-date");
281     r->publication_date_of_component =
282         ill_get_ILL_String(gc, element, "publication-date-of-component");
283     r->author_of_article = ill_get_ILL_String(gc, element,
284                                               "author-of-article");
285     r->title_of_article = ill_get_ILL_String(gc, element, "title-or-article");
286     r->pagination = ill_get_ILL_String(gc, element, "pagination");
287     r->national_bibliography_no = 0;
288     r->iSBN = ill_get_ILL_String(gc, element, "ISBN");
289     r->iSSN = ill_get_ILL_String(gc, element, "ISSN");
290     r->system_no = 0;
291     r->additional_no_letters =
292         ill_get_ILL_String(gc, element, "additional-no-letters");
293     r->verification_reference_source = 
294         ill_get_ILL_String(gc, element, "verification-reference-source");
295     return r;
296 }
297
298 ILL_ItemRequest *ill_get_ItemRequest (
299     struct ill_get_ctl *gc, const char *name, const char *sub)
300 {
301     ODR o = gc->odr;
302     ILL_ItemRequest *r = (ILL_ItemRequest *)odr_malloc(o, sizeof(*r));
303     return 0;
304 }
305
306 ILL_Request *ill_get_ILLRequest (
307     struct ill_get_ctl *gc, const char *name, const char *sub)
308 {
309     ODR o = gc->odr;
310     ILL_Request *r = (ILL_Request *) odr_malloc(o, sizeof(*r));
311     char element[128];
312     
313     strcpy(element, name);
314     if (sub)
315     {
316         strcat (element, ",");
317         strcat (element, sub);
318     }
319     r->protocol_version_num =
320         ill_get_enumerated (gc, element, "protocol-version-num", 
321                             ILL_Request_version_2);
322     
323     r->transaction_id = ill_get_Transaction_Id (gc, element, "transaction-id");
324     r->service_date_time =
325         ill_get_Service_Date_Time (gc, element, "service-date-time");
326     r->requester_id = ill_get_System_Id (gc, element, "requester-id");
327     r->responder_id = ill_get_System_Id (gc, element, "responder-id");
328     r->transaction_type =
329         ill_get_enumerated(gc, element, "transaction-type", 1);
330     r->delivery_address = 0;     /* TODO */
331     r->delivery_service = 0;     /* TODO */
332     r->billing_address = 0;      /* TODO */
333
334     r->num_iLL_service_type = 1;
335     r->iLL_service_type = (ILL_Service_Type **)
336         odr_malloc (o, sizeof(*r->iLL_service_type));
337     *r->iLL_service_type =
338         ill_get_enumerated (gc, element, "ill-service-type",
339                             ILL_Service_Type_copy_non_returnable);
340
341     r->responder_specific_service = 0;
342     r->requester_optional_messages =
343         ill_get_Requester_Optional_Messages_Type (
344             gc, element,"requester-optional-messages");
345     r->search_type = 0;            /* TODO */
346     r->num_supply_medium_info_type = 0;
347     r->supply_medium_info_type = 0;
348
349     r->place_on_hold =
350         ill_get_enumerated (gc, element, "place-on-hold", 
351                             ILL_Place_On_Hold_Type_according_to_responder_policy);
352     r->client_id = 0;             /* TODO */
353     r->item_id = ill_get_Item_Id (gc, element, "item-id");
354     r->supplemental_item_description = 0;
355     r->cost_info_type = 0;
356     r->copyright_compliance =
357         ill_get_ILL_String(gc, element, "copyright-complicance");
358     r->third_party_info_type = 0;
359     r->retry_flag = ill_get_bool (gc, element, "retry-flag", 0);
360     r->forward_flag = ill_get_bool (gc, element, "forward-flag", 0);
361     r->requester_note = ill_get_ILL_String(gc, element, "requester-note");
362     r->forward_note = ill_get_ILL_String(gc, element, "forward-note");
363     r->num_iLL_request_extensions = 0;
364     r->iLL_request_extensions = 0;
365     return r;
366 }