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