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