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