Added Term structure
[yaz-moved-to-github.git] / include / proto.h
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: proto.h,v $
7  * Revision 1.2  1995-03-30 10:26:48  quinn
8  * Added Term structure
9  *
10  * Revision 1.1  1995/03/30  09:39:42  quinn
11  * Moved .h files to include directory
12  *
13  * Revision 1.11  1995/03/30  09:08:44  quinn
14  * Added Resource control protocol
15  *
16  * Revision 1.10  1995/03/29  15:39:39  quinn
17  * Adding some resource control elements, and a null-check to getentbyoid
18  *
19  * Revision 1.9  1995/03/29  08:06:18  quinn
20  * Added a few v3 elements
21  *
22  * Revision 1.8  1995/03/22  10:12:49  quinn
23  * Added Z_PRES constants.
24  *
25  * Revision 1.7  1995/03/20  09:45:12  quinn
26  * Working towards v3
27  *
28  * Revision 1.5  1995/03/07  16:29:34  quinn
29  * Added authentication stuff.
30  *
31  * Revision 1.4  1995/03/07  10:13:00  quinn
32  * Added prototype for z_APDU()
33  *
34  * Revision 1.3  1995/02/14  11:54:23  quinn
35  * Fixing include.
36  *
37  * Revision 1.2  1995/02/09  15:51:40  quinn
38  * Works better now.
39  *
40  * Revision 1.1  1995/02/06  16:44:48  quinn
41  * First hack at Z/SR protocol
42  *
43  */
44
45 #ifndef PROTO_H
46 #define PROTO_H
47
48 #include <odr.h>
49 #include <odr_use.h>
50
51 /* ----------------- GLOBAL AUXILIARY DEFS ----------------*/
52
53 typedef Odr_oct Z_ReferenceId;
54 typedef char Z_DatabaseName;
55 typedef char Z_ResultSetId;
56 typedef Odr_oct Z_ResultsetId;
57 typedef Odr_external Z_UserInformationField;
58
59 /* ----------------- INIT SERVICE  ----------------*/
60
61 typedef struct
62 {
63     char *groupId;       /* OPTIONAL */
64     char *userId;         /* OPTIONAL */
65     char *password;      /* OPTIONAL */
66 } Z_IdPass;
67
68 typedef struct Z_IdAuthentication
69 {
70     enum
71     {
72         Z_IdAuthentication_open,
73         Z_IdAuthentication_idPass,
74         Z_IdAuthentication_anonymous,
75         Z_IdAuthentication_other
76     } which;
77     union
78     {
79         char *open;
80         Z_IdPass *idPass;
81         void *anonymous;         /* NULL */
82         Odr_external *other;
83     } u;
84 } Z_IdAuthentication;
85
86 #define Z_ProtocolVersion_1            0
87 #define Z_ProtocolVersion_2            1
88 #define Z_ProtocolVersion_3            2
89
90 #define Z_Options_search               0
91 #define Z_Options_present              1
92 #define Z_Options_delSet               2
93 #define Z_Options_resourceReport       3
94 #define Z_Options_triggerResourceCtrl  4
95 #define Z_Options_resourceCtrl         5
96 #define Z_Options_accessCtrl           6
97 #define Z_Options_scan                 7
98 #define Z_Options_sort                 8
99 #define Z_Options_reserved             9
100 #define Z_Options_extendedServices    10
101 #define Z_Options_level_1Segmentation 11
102 #define Z_Options_level_2Segmentation 12
103 #define Z_Options_concurrentOperations 13
104 #define Z_Options_namedResultSets     14
105
106 typedef struct Z_InitRequest
107 {
108     Z_ReferenceId *referenceId;                   /* OPTIONAL */
109     Odr_bitmask *options;
110     Odr_bitmask *protocolVersion;
111     int *preferredMessageSize;
112     int *maximumRecordSize;
113     Z_IdAuthentication* idAuthentication;        /* OPTIONAL */
114     char *implementationId;                      /* OPTIONAL */
115     char *implementationName;                    /* OPTIONAL */
116     char *implementationVersion;                 /* OPTIONAL */
117     Z_UserInformationField *userInformationField; /* OPTIONAL */
118 } Z_InitRequest;
119
120 typedef struct Z_InitResponse
121 {
122     Z_ReferenceId *referenceId;    /* OPTIONAL */
123     Odr_bitmask *options;
124     Odr_bitmask *protocolVersion;
125     int *preferredMessageSize;
126     int *maximumRecordSize;
127     bool_t *result;
128     char *implementationId;      /* OPTIONAL */
129     char *implementationName;    /* OPTIONAL */
130     char *implementationVersion; /* OPTIONAL */
131     Z_UserInformationField *userInformationField; /* OPTIONAL */
132 } Z_InitResponse;
133
134 typedef struct Z_NSRAuthentication
135 {
136     char *user;
137     char *password;
138     char *account;
139 } Z_NSRAuthentication;
140
141 int z_NSRAuthentication(ODR o, Z_NSRAuthentication **p, int opt);
142
143 int z_StrAuthentication(ODR o, char **p, int opt);
144
145
146 /* ------------------ RESOURCE CONTROL ----------------*/
147
148 typedef struct Z_TriggerResourceControlRequest
149 {
150     Z_ReferenceId *referenceId;    /* OPTIONAL */
151     int *requestedAction;
152 #define Z_TriggerResourceCtrl_resourceReport  1
153 #define Z_TriggerResourceCtrl_resourceControl 2
154 #define Z_TriggerResourceCtrl_cancel          3
155     Odr_oid *prefResourceReportFormat;  /* OPTIONAL */
156     bool_t *resultSetWanted;            /* OPTIONAL */
157 } Z_TriggerResourceControlRequest;
158
159 typedef struct Z_ResourceControlRequest
160 {
161     Z_ReferenceId *referenceId;    /* OPTIONAL */
162     bool_t *suspendedFlag;         /* OPTIONAL */
163     Odr_external *resourceReport; /* OPTIONAL */
164     int *partialResultsAvailable;  /* OPTIONAL */
165 #define Z_ResourceControlRequest_subset    1
166 #define Z_ResourceControlRequest_interim   2
167 #define Z_ResourceControlRequest_none      3
168     bool_t *responseRequired;
169     bool_t *triggeredRequestFlag;  /* OPTIONAL */
170 } Z_ResourceControlRequest;
171
172 typedef struct Z_ResourceControlResponse
173 {
174     Z_ReferenceId *referenceId;    /* OPTIONAL */
175     bool_t *continueFlag;
176     bool_t *resultSetWanted;       /* OPTIONAL */
177 } Z_ResourceControlResponse;
178
179 /* ------------------ SEARCH SERVICE ----------------*/
180
181 typedef Odr_oid Z_PreferredRecordSyntax;
182
183 typedef struct Z_DatabaseSpecificUnit
184 {
185     char *databaseName;
186     char *elementSetName;
187 } Z_DatabaseSpecificUnit;
188
189 typedef struct Z_DatabaseSpecific
190 {
191     int num_elements;
192     Z_DatabaseSpecificUnit **elements;
193 } Z_DatabaseSpecific;
194
195 typedef struct Z_ElementSetNames
196 {
197     int which;
198 #define Z_ElementSetNames_generic 0
199 #define Z_ElementSetNames_databaseSpecific 1
200     union
201     {
202         char *generic;
203         Z_DatabaseSpecific *databaseSpecific;
204     } u;
205 } Z_ElementSetNames;
206
207 /* ---------------------- RPN QUERY --------------------------- */
208
209 typedef struct Z_AttributeElement
210 {
211     int *attributeType;
212     int *attributeValue;
213 } Z_AttributeElement;
214
215 #define Z_V3
216 #ifdef Z_V3
217
218 typedef struct Z_Term 
219 {
220     enum
221     {
222         Z_Term_general,
223         Z_Term_numeric,
224         Z_Term_characterString,
225         Z_Term_oid,
226         Z_Term_dateTime,
227         Z_Term_external,
228         Z_Term_integerAndUnit,
229         Z_Term_null
230     } which;
231     union
232     {
233         Odr_oct *general; /* this is required for v2 */
234         int *numeric;
235         char *characterString;
236         Odr_oid *oid;
237         char *dateTime;
238         Odr_external *external;
239         /* Z_IntUnit *integerAndUnit; */
240         void *null;
241     } u;
242 } Z_Term;
243
244 #endif
245
246 typedef struct Z_AttributesPlusTerm
247 {
248     int num_attributes;
249     Z_AttributeElement **attributeList;
250 #ifdef Z_V3
251     Z_Term *term;
252 #else
253     Odr_oct *term;
254 #endif
255 } Z_AttributesPlusTerm;
256
257 typedef struct Z_ProximityOperator
258 {
259     bool_t *exclusion;          /* OPTIONAL */
260     int *distance;
261     bool_t *ordered;
262     int *relationType;
263     enum
264     {
265         Z_ProximityOperator_known,
266         Z_ProximityOperator_private
267     } which;
268     union
269     {
270         int *known;
271         int *private;
272     } u;
273 } Z_ProximityOperator;
274
275 typedef struct Z_Operator
276 {
277     enum
278     {
279         Z_Operator_and,
280         Z_Operator_or,
281         Z_Operator_and_not,
282         Z_Operator_proximity
283     } which;
284     union
285     {
286         void *and;          /* these guys are nulls. */
287         void *or;
288         void *and_not;
289         Z_ProximityOperator *proximity;
290     } u;
291 } Z_Operator;
292
293 typedef struct Z_Operand
294 {
295     int which;
296 #define Z_Operand_APT 0
297 #define Z_Operand_resultSetId 1
298     union
299     {
300         Z_AttributesPlusTerm *attributesPlusTerm;
301         Z_ResultSetId *resultSetId;
302     } u;
303 } Z_Operand;
304
305 typedef struct Z_Complex
306 {
307     struct Z_RPNStructure *s1;
308     struct Z_RPNStructure *s2;
309     Z_Operator *operator;
310 } Z_Complex;
311
312 typedef struct Z_RPNStructure
313 {
314     int which;
315 #define Z_RPNStructure_simple 0
316 #define Z_RPNStructure_complex 1
317     union
318     {
319         Z_Operand *simple;
320         Z_Complex *complex;
321     } u;
322 } Z_RPNStructure;
323
324 typedef struct Z_RPNQuery
325 {
326     Odr_oid *attributeSetId;
327     Z_RPNStructure *RPNStructure;
328 } Z_RPNQuery;
329
330 /* -------------------------- SEARCHREQUEST -------------------------- */
331
332 typedef struct Z_Query
333 {
334     int which;
335 #define Z_Query_type_1 1
336 #define Z_Query_type_2 2
337     union
338     {
339         Z_RPNQuery *type_1;
340         Odr_oct *type_2;
341     } u;
342 } Z_Query;
343
344 typedef struct Z_SearchRequest
345 {
346     Z_ReferenceId *referenceId;   /* OPTIONAL */
347     int *smallSetUpperBound;
348     int *largeSetLowerBound;
349     int *mediumSetPresentNumber;
350     bool_t *replaceIndicator;
351     char *resultSetName;
352     int num_databaseNames;
353     char **databaseNames;
354     Z_ElementSetNames *smallSetElementSetNames;    /* OPTIONAL */
355     Z_ElementSetNames *mediumSetElementSetNames;    /* OPTIONAL */
356     Z_PreferredRecordSyntax *preferredRecordSyntax;  /* OPTIONAL */
357     Z_Query *query;
358 } Z_SearchRequest;
359
360 /* ------------------------ RECORD -------------------------- */
361
362 typedef Odr_external Z_DatabaseRecord;
363
364 typedef struct Z_DiagRec
365 {
366     Odr_oid *diagnosticSetId;
367     int *condition;
368     char *addinfo;
369 } Z_DiagRec;
370
371 typedef struct Z_NamePlusRecord
372 {
373     char *databaseName;      /* OPTIONAL */
374     int which;
375 #define Z_NamePlusRecord_databaseRecord 0
376 #define Z_NamePlusRecord_surrogateDiagnostic 1
377     union
378     {
379         Z_DatabaseRecord *databaseRecord;
380         Z_DiagRec *surrogateDiagnostic;
381     } u;
382 } Z_NamePlusRecord;
383
384 typedef struct Z_NamePlusRecordList
385 {
386     int num_records;
387     Z_NamePlusRecord **records;
388 } Z_NamePlusRecordList;
389
390 typedef struct Z_Records
391 {
392     int which;
393 #define Z_Records_DBOSD 0
394 #define Z_Records_NSD 1
395     union
396     {
397         Z_NamePlusRecordList *databaseOrSurDiagnostics;
398         Z_DiagRec *nonSurrogateDiagnostic;
399     } u;
400 } Z_Records;
401
402 /* ------------------------ SEARCHRESPONSE ------------------ */
403
404 typedef struct Z_SearchResponse
405 {
406     Z_ReferenceId *referenceId;       /* OPTIONAL */
407     int *resultCount;
408     int *numberOfRecordsReturned;
409     int *nextResultSetPosition;
410     bool_t *searchStatus;
411     int *resultSetStatus;              /* OPTIONAL */
412     int *presentStatus;                /* OPTIONAL */
413 #define Z_PRES_SUCCESS      0
414 #define Z_PRES_PARTIAL_1    1
415 #define Z_PRES_PARTIAL_2    2
416 #define Z_PRES_PARTIAL_3    3
417 #define Z_PRES_PARTIAL_4    4
418 #define Z_PRES_FAILURE      5
419     Z_Records *records;                  /* OPTIONAL */
420 } Z_SearchResponse;
421
422 /* ------------------------- PRESENT SERVICE -----------------*/
423
424 typedef struct Z_PresentRequest
425 {
426     Z_ReferenceId *referenceId;          /* OPTIONAL */
427     Z_ResultSetId *resultSetId;
428     int *resultSetStartPoint;
429     int *numberOfRecordsRequested;
430     Z_ElementSetNames *elementSetNames;  /* OPTIONAL */
431     Z_PreferredRecordSyntax *preferredRecordSyntax;  /* OPTIONAL */
432 } Z_PresentRequest;
433
434 typedef struct Z_PresentResponse
435 {
436     Z_ReferenceId *referenceId;        /* OPTIONAL */
437     int *numberOfRecordsReturned;
438     int *nextResultSetPosition;
439     int *presentStatus;
440     Z_Records *records;
441 } Z_PresentResponse;
442
443 /* ------------------------ APDU ---------------------------- */
444
445 typedef struct Z_APDU
446 {    
447     int which;
448 #define Z_APDU_initRequest 0
449 #define Z_APDU_initResponse 1
450 #define Z_APDU_searchRequest 2
451 #define Z_APDU_searchResponse 3
452 #define Z_APDU_presentRequest 4
453 #define Z_APDU_presentResponse 5
454     union
455     {
456         Z_InitRequest  *initRequest;
457         Z_InitResponse *initResponse;
458         Z_SearchRequest *searchRequest;
459         Z_SearchResponse *searchResponse;
460         Z_PresentRequest *presentRequest;
461         Z_PresentResponse *presentResponse;
462     } u;
463 } Z_APDU;
464
465 int z_APDU(ODR o, Z_APDU **p, int opt);
466
467 #endif