Directive s=pw sets structure to phrase if term includes blank(s).
[yaz-moved-to-github.git] / asn / prt-exd.c
1 /*
2  * Copyright (c) 1995-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: prt-exd.c,v $
7  * Revision 1.11  1999-11-30 13:47:11  adam
8  * Improved installation. Moved header files to include/yaz.
9  *
10  * Revision 1.10  1999/05/26 13:49:12  adam
11  * DB Update implemented in client (very basic).
12  *
13  * Revision 1.9  1999/04/20 09:56:48  adam
14  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
15  * Modified all encoders/decoders to reflect this change.
16  *
17  * Revision 1.8  1998/02/11 11:53:32  adam
18  * Changed code so that it compiles as C++.
19  *
20  * Revision 1.7  1998/02/10 15:31:46  adam
21  * Implemented date and time structure. Changed the Update Extended
22  * Service.
23  *
24  * Revision 1.6  1998/01/05 09:04:57  adam
25  * Fixed bugs in encoders/decoders - Not operator (!) missing.
26  *
27  * Revision 1.5  1997/04/30 08:52:02  quinn
28  * Null
29  *
30  * Revision 1.4  1996/10/10  12:35:12  quinn
31  * Added Update extended service.
32  *
33  * Revision 1.3  1995/09/29  17:11:54  quinn
34  * Smallish
35  *
36  * Revision 1.2  1995/09/27  15:02:41  quinn
37  * Modified function heads & prototypes.
38  *
39  * Revision 1.1  1995/08/21  09:16:32  quinn
40  * Added Extended services + Item Order
41  *
42  *
43  */
44
45 #include <yaz/proto.h>
46
47 int z_TaskPackage(ODR o, Z_TaskPackage **p, int opt, const char *name)
48 {
49     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
50         return opt && odr_ok(o);
51     return
52         odr_implicit(o, odr_oid, &(*p)->packageType, ODR_CONTEXT, 1, 0) &&
53         odr_implicit(o, z_InternationalString, &(*p)->packageName,
54                      ODR_CONTEXT, 2, 1) &&
55         odr_implicit(o, z_InternationalString, &(*p)->userId,
56                      ODR_CONTEXT, 3, 1) &&
57         odr_implicit(o, z_IntUnit, &(*p)->retentionTime, ODR_CONTEXT, 4, 1) &&
58         odr_implicit(o, z_Permissions, &(*p)->permissions,
59                      ODR_CONTEXT, 5, 1) &&
60         odr_implicit(o, z_InternationalString, &(*p)->description,
61                      ODR_CONTEXT, 6, 1) &&
62         odr_implicit(o, odr_octetstring, &(*p)->targetReference,
63                      ODR_CONTEXT, 7, 0) &&
64         odr_implicit(o, odr_generalizedtime, &(*p)->creationDateTime,
65                      ODR_CONTEXT, 8, 1) &&
66         odr_implicit(o, odr_integer, &(*p)->taskStatus,
67                      ODR_CONTEXT, 9, 0) &&
68         odr_implicit_settag(o, ODR_CONTEXT, 10) &&
69         (odr_sequence_of(o, (Odr_fun)z_DiagRec, &(*p)->packageDiagnostics,
70                          &(*p)->num_packageDiagnostics, 0) || odr_ok(o)) &&
71         odr_implicit(o, z_External, &(*p)->taskSpecificParameters,
72                      ODR_CONTEXT, 11, 0) &&
73         odr_sequence_end(o);
74 }
75
76 /* ----------------------- ITEM ORDER --------------------- */
77
78 int z_IOTargetPart(ODR o, Z_IOTargetPart **p, int opt, const char *name)
79 {
80     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
81         return opt && odr_ok(o);
82     return
83         odr_implicit(o, z_External, &(*p)->itemRequest, ODR_CONTEXT, 1, 1) &&
84         odr_implicit(o, z_External, &(*p)->statusOrErrorReport, ODR_CONTEXT,
85             2, 0) &&
86         odr_implicit(o, odr_integer, &(*p)->auxiliaryStatus, ODR_CONTEXT,
87             3, 1) &&
88         odr_sequence_end(o);
89 }
90
91 int z_IOResultSetItem(ODR o, Z_IOResultSetItem **p, int opt, const char *name)
92 {
93     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
94         return opt && odr_ok(o);
95     return
96         odr_implicit(o, z_InternationalString, &(*p)->resultSetId, ODR_CONTEXT,
97             1, 0) &&
98         odr_implicit(o, odr_integer, &(*p)->item, ODR_CONTEXT, 2, 1) &&
99         odr_sequence_end(o);
100 }
101
102 int z_IOOriginPartNotToKeep(ODR o, Z_IOOriginPartNotToKeep **p, int opt,
103                             const char *name)
104 {
105     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
106         return opt && odr_ok(o);
107     return
108         odr_implicit(o, z_IOResultSetItem, &(*p)->resultSetItem, ODR_CONTEXT,
109             1, 0) &&
110         odr_implicit(o, z_External, &(*p)->itemRequest, ODR_CONTEXT, 2, 1) &&
111         odr_sequence_end(o);
112 }
113
114 int z_IOContact(ODR o, Z_IOContact **p, int opt, const char *name)
115 {
116     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
117         return opt && odr_ok(o);
118     return
119         odr_implicit(o, z_InternationalString, &(*p)->name, ODR_CONTEXT,
120             1, 1) &&
121         odr_implicit(o, z_InternationalString, &(*p)->phone, ODR_CONTEXT,
122             2, 1) &&
123         odr_implicit(o, z_InternationalString, &(*p)->email, ODR_CONTEXT,
124             3, 1) &&
125         odr_sequence_end(o);
126 }
127
128 int z_IOCreditCardInfo(ODR o, Z_IOCreditCardInfo **p, int opt,
129                        const char *name)
130 {
131     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
132         return opt && odr_ok(o);
133     return
134         odr_implicit(o, z_InternationalString, &(*p)->nameOnCard, ODR_CONTEXT,
135             1, 0) &&
136         odr_implicit(o, z_InternationalString, &(*p)->expirationDate,
137             ODR_CONTEXT, 2, 0) &&
138         odr_implicit(o, z_InternationalString, &(*p)->cardNumber, ODR_CONTEXT,
139             3, 0) &&
140         odr_sequence_end(o);
141 }
142
143 int z_IOBilling(ODR o, Z_IOBilling **p, int opt, const char *name)
144 {
145     static Odr_arm arm[] =
146     {
147         {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_IOBilling_billInvoice,
148          (Odr_fun)odr_null, 0},
149         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_IOBilling_prepay,
150          (Odr_fun)odr_null, 0},
151         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_IOBilling_depositAccount,
152          (Odr_fun)odr_null, 0},
153         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_IOBilling_creditCard,
154          (Odr_fun)z_IOCreditCardInfo, 0},
155         {ODR_IMPLICIT, ODR_CONTEXT, 4, Z_IOBilling_cardInfoPreviouslySupplied,
156          (Odr_fun)odr_null, 0},
157         {ODR_IMPLICIT, ODR_CONTEXT, 5, Z_IOBilling_privateKnown,
158          (Odr_fun)odr_null, 0},
159         {ODR_IMPLICIT, ODR_CONTEXT, 6, Z_IOBilling_privateNotKnown,
160          (Odr_fun)z_External, 0},
161         {-1, -1, -1, -1, 0, 0}
162     };
163     
164     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
165         return opt && odr_ok(o);
166     return
167         odr_constructed_begin(o, &(*p)->paymentMethod,
168                               ODR_CONTEXT, 1, 0) &&
169         odr_choice(o, arm, &(*p)->paymentMethod, &(*p)->which, 0) &&
170         odr_constructed_end(o) &&
171         odr_implicit(o, z_InternationalString, &(*p)->customerReference,
172                      ODR_CONTEXT, 2, 1) &&
173         odr_implicit(o, z_InternationalString, &(*p)->customerPONumber,
174                      ODR_CONTEXT, 3, 1) &&
175         odr_sequence_end(o);
176 }
177
178 int z_IOOriginPartToKeep(ODR o, Z_IOOriginPartToKeep **p, int opt,
179                          const char *name)
180 {
181     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
182         return opt && odr_ok(o);
183     return
184         odr_implicit(o, z_External, &(*p)->supplDescription,
185                      ODR_CONTEXT, 1, 1) &&
186         odr_implicit(o, z_IOContact, &(*p)->contact, ODR_CONTEXT, 2, 1) &&
187         odr_implicit(o, z_IOBilling, &(*p)->addlBilling,
188                      ODR_CONTEXT, 3, 1) &&
189         odr_sequence_end(o);
190 }
191
192 int z_IORequest(ODR o, Z_IORequest **p, int opt, const char *name)
193 {
194     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
195         return opt && odr_ok(o);
196     return 
197         odr_implicit(o, z_IOOriginPartToKeep, &(*p)->toKeep,
198                      ODR_CONTEXT, 1, 1) &&
199         odr_implicit(o, z_IOOriginPartNotToKeep, &(*p)->notToKeep,
200                      ODR_CONTEXT, 2, 0) &&
201         odr_sequence_end(o);
202 }
203
204 int z_IOTaskPackage(ODR o, Z_IOTaskPackage **p, int opt, const char *name)
205 {
206     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
207         return opt && odr_ok(o);
208     return
209         odr_implicit(o, z_IOOriginPartToKeep, &(*p)->originPart,
210                      ODR_CONTEXT, 1, 1) &&
211         odr_implicit(o, z_IOTargetPart, &(*p)->targetPart,
212                      ODR_CONTEXT, 2, 0) &&
213         odr_sequence_end(o);
214 }
215
216 int z_ItemOrder(ODR o, Z_ItemOrder **p, int opt, const char *name)
217 {
218     static Odr_arm arm[] =
219     {
220         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ItemOrder_esRequest,
221          (Odr_fun)z_IORequest, 0},
222         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_ItemOrder_taskPackage,
223          (Odr_fun)z_IOTaskPackage, 0},
224         {-1, -1, -1, -1, 0, 0}
225     };
226     
227     if (o->direction == ODR_DECODE)
228         *p = (Z_ItemOrder *)odr_malloc(o, sizeof(**p));
229     else if (!*p)
230         return opt;
231     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
232         return 1;
233     *p = 0;
234     return opt && odr_ok(o);
235 }
236
237 /* ----------------------- ITEM UPDATE -------------------- */
238
239 int z_IUSuppliedRecordsId (ODR o, Z_IUSuppliedRecordsId **p, int opt,
240                            const char *name)
241 {
242     static Odr_arm arm[] = {
243         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_IUSuppliedRecordsId_timeStamp,
244          odr_generalizedtime, 0},
245         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_IUSuppliedRecordsId_versionNumber,
246          z_InternationalString, 0},
247         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_IUSuppliedRecordsId_previousVersion,
248          (Odr_fun)odr_external, 0},
249         {-1, -1, -1, -1, 0, 0}
250     };
251     if (!odr_initmember(o, p, sizeof(**p)))
252         return opt && odr_ok(o);
253     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
254         return 1;
255     *p = 0;
256     return opt && odr_ok(o);
257 }
258
259 int z_IUCorrelationInfo (ODR o, Z_IUCorrelationInfo **p, int opt,
260                          const char *name)
261 {
262     if (!odr_sequence_begin (o, p, sizeof(**p), 0))
263         return opt && odr_ok (o);
264     return
265         odr_implicit (o, z_InternationalString,
266                       &(*p)->note, ODR_CONTEXT, 1, 1) &&
267         odr_implicit (o, odr_integer,
268                       &(*p)->id, ODR_CONTEXT, 2, 1) &&
269         odr_sequence_end (o);
270 }
271
272 int z_IUSuppliedRecords_elem (ODR o, Z_IUSuppliedRecords_elem **p, int opt,
273                               const char *name)
274 {
275     static Odr_arm arm[] = {
276         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_IUSuppliedRecords_number,
277          (Odr_fun)odr_integer, 0},
278         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_IUSuppliedRecords_string,
279          (Odr_fun)z_InternationalString, 0},
280         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_IUSuppliedRecords_opaque,
281          (Odr_fun)odr_octetstring, 0},
282         {-1, -1, -1, -1, 0, 0}
283     };
284     if (!odr_sequence_begin (o, p, sizeof(**p), 0))
285         return opt && odr_ok (o);
286     return
287         ((odr_constructed_begin (o, &(*p)->u, ODR_CONTEXT, 1, 0) &&
288           odr_choice (o, arm, &(*p)->u, &(*p)->which, 0) &&
289           odr_constructed_end (o)) || odr_ok(o)) &&
290         odr_explicit (o, z_IUSuppliedRecordsId,
291                       &(*p)->supplementalId, ODR_CONTEXT, 2, 1) &&
292         odr_implicit (o, z_IUCorrelationInfo,
293                       &(*p)->correlationInfo, ODR_CONTEXT, 3, 1) &&
294         odr_implicit (o, z_External,
295                       &(*p)->record, ODR_CONTEXT, 4, 0) &&
296         odr_sequence_end (o);
297 }
298
299 int z_IUSuppliedRecords (ODR o, Z_IUSuppliedRecords **p, int opt,
300                          const char *name)
301 {
302     if (!odr_initmember (o, p, sizeof(**p)))
303         return opt && odr_ok(o);
304     if (odr_sequence_of (o, (Odr_fun)z_IUSuppliedRecords_elem, &(*p)->elements,
305                          &(*p)->num, 0))
306         return 1;
307     *p = 0;
308     return opt && odr_ok(o);
309 }
310
311 int z_IUTaskPackageRecordStructure (ODR o, Z_IUTaskPackageRecordStructure **p,
312                                     int opt, const char *name)
313 {
314     static Odr_arm arm[] = {
315         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_IUTaskPackageRecordStructure_record,
316          (Odr_fun)odr_external, 0},
317         {ODR_EXPLICIT, ODR_CONTEXT, 2,
318          Z_IUTaskPackageRecordStructure_surrogateDiagnostics,
319          (Odr_fun)z_DiagRecs, 0},
320         {-1, -1, -1, -1, 0, 0}
321     };
322     if (!odr_sequence_begin (o, p, sizeof(**p), 0))
323         return opt && odr_ok (o);
324     return
325         ((odr_constructed_begin (o, &(*p)->u, ODR_CONTEXT, 1, 0) &&
326           odr_choice (o, arm, &(*p)->u, &(*p)->which, 0) &&
327           odr_constructed_end (o)) || odr_ok(o)) &&
328         odr_implicit (o, z_IUCorrelationInfo,
329                       &(*p)->correlationInfo, ODR_CONTEXT, 2, 1) &&
330         odr_implicit (o, odr_integer,
331                       &(*p)->recordStatus, ODR_CONTEXT, 3, 0) &&
332         odr_implicit (o, z_DiagRecs, 
333                       &(*p)->supplementalDiagnostics, ODR_CONTEXT, 4, 1) &&
334         odr_sequence_end (o);
335 }
336
337 int z_IUOriginPartToKeep (ODR o, Z_IUOriginPartToKeep **p, int opt,
338                           const char *name)
339 {
340     if (!odr_sequence_begin (o, p, sizeof(**p), 0))
341         return opt && odr_ok (o);
342     return
343         odr_implicit (o, odr_integer,
344                       &(*p)->action, ODR_CONTEXT, 1, 0) &&
345         odr_implicit (o, z_InternationalString,
346                       &(*p)->databaseName, ODR_CONTEXT, 2, 0) &&
347         odr_implicit (o, odr_oid,
348                       &(*p)->schema, ODR_CONTEXT, 3, 1) &&
349         odr_implicit (o, z_InternationalString,
350                       &(*p)->elementSetName, ODR_CONTEXT, 4, 1) &&
351         odr_implicit (o, odr_external,
352                       &(*p)->actionQualifier, ODR_CONTEXT, 5, 1) &&
353         odr_sequence_end (o);
354 }
355
356 int z_IUTargetPart (ODR o, Z_IUTargetPart **p, int opt, const char *name)
357 {
358     if (!odr_sequence_begin (o, p, sizeof(**p), 0))
359         return opt && odr_ok (o);
360     return
361         odr_implicit (o, odr_integer,
362                       &(*p)->updateStatus, ODR_CONTEXT, 1, 0) &&
363         odr_implicit_settag (o, ODR_CONTEXT, 2) &&
364         (odr_sequence_of(o, (Odr_fun)z_DiagRec, &(*p)->globalDiagnostics,
365                          &(*p)->num_globalDiagnostics, 0) || odr_ok(o)) &&
366         odr_implicit_settag (o, ODR_CONTEXT, 3) &&
367         odr_sequence_of(o, (Odr_fun)z_IUTaskPackageRecordStructure,
368                         &(*p)->taskPackageRecords,
369                         &(*p)->num_taskPackageRecords, 0) &&
370         odr_sequence_end (o);
371 }
372
373 int z_IUUpdateEsRequest (ODR o, Z_IUUpdateEsRequest **p, int opt,
374                          const char *name)
375 {
376     if (!odr_sequence_begin (o, p, sizeof(**p), 0))
377         return opt && odr_ok (o);
378     return
379         odr_explicit (o, z_IUOriginPartToKeep,
380                       &(*p)->toKeep, ODR_CONTEXT, 1, 0) &&
381         odr_explicit (o, z_IUSuppliedRecords,
382                       &(*p)->notToKeep, ODR_CONTEXT, 2, 0) &&
383         odr_sequence_end (o);
384 }
385
386 int z_IUUpdateTaskPackage (ODR o, Z_IUUpdateTaskPackage **p, int opt,
387                            const char *name)
388 {
389     if (!odr_sequence_begin (o, p, sizeof(**p), 0))
390         return opt && odr_ok (o);
391     return
392         odr_explicit (o, z_IUOriginPartToKeep,
393                       &(*p)->originPart, ODR_CONTEXT, 1, 0) &&
394         odr_explicit (o, z_IUTargetPart,
395                       &(*p)->targetPart, ODR_CONTEXT, 2, 0) &&
396         odr_sequence_end (o);
397 }
398
399 int z_IUUpdate (ODR o, Z_IUUpdate **p, int opt, const char *name)
400 {
401     static Odr_arm arm[] = {
402         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_IUUpdate_esRequest,
403          (Odr_fun)z_IUUpdateEsRequest, 0},
404         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_IUUpdate_taskPackage,
405          (Odr_fun)z_IUUpdateTaskPackage, 0},
406         {-1, -1, -1, -1, 0, 0}
407     };
408     if (!odr_initmember(o, p, sizeof(**p)))
409         return opt && odr_ok(o);
410     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
411         return 1;
412     *p = 0;
413     return opt && odr_ok(o);
414 }