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