Setting PDUType renamed to eventType.
[ir-tcl-moved-to-github.git] / ir-tclp.h
1 /*
2  * IR toolkit for tcl/tk
3  * (c) Index Data 1995
4  * See the file LICENSE for details.
5  * Sebastian Hammer, Adam Dickmeiss
6  *
7  * $Log: ir-tclp.h,v $
8  * Revision 1.21  1996-01-04 16:12:14  adam
9  * Setting PDUType renamed to eventType.
10  *
11  * Revision 1.20  1996/01/04  11:05:23  adam
12  * New setting: PDUType - returns type of last PDU returned from the target.
13  * Fixed a bug in configure/Makefile.
14  *
15  * Revision 1.19  1995/11/13  09:55:46  adam
16  * Multiple records at a position in a result-set with differnt
17  * element specs.
18  *
19  * Revision 1.18  1995/10/18  16:42:44  adam
20  * New settings: smallSetElementSetNames and mediumSetElementSetNames.
21  *
22  * Revision 1.17  1995/10/16  17:00:56  adam
23  * New setting: elementSetNames.
24  * Various client improvements. Medium presentation format looks better.
25  *
26  * Revision 1.16  1995/09/20  11:37:01  adam
27  * Configure searches for tk4.1 and tk7.5.
28  * Work on GRS.
29  *
30  * Revision 1.15  1995/08/29  15:30:15  adam
31  * Work on GRS records.
32  *
33  * Revision 1.14  1995/08/04  11:32:40  adam
34  * More work on output queue. Memory related routines moved
35  * to mem.c
36  *
37  * Revision 1.13  1995/08/03  13:23:00  adam
38  * Request queue.
39  *
40  * Revision 1.12  1995/07/28  10:28:38  adam
41  * First work on request queue.
42  *
43  * Revision 1.11  1995/06/20  08:07:35  adam
44  * New setting: failInfo.
45  * Working on better cancel mechanism.
46  *
47  * Revision 1.10  1995/06/16  12:28:20  adam
48  * Implemented preferredRecordSyntax.
49  * Minor changes in diagnostic handling.
50  * Record list deleted when connection closes.
51  *
52  * Revision 1.9  1995/06/14  15:08:01  adam
53  * Bug fix in cascade-target-list. Uses yaz-version.h.
54  *
55  * Revision 1.8  1995/06/14  13:37:18  adam
56  * Setting recordType implemented.
57  * Setting implementationVersion implemented.
58  * Settings implementationId / implementationName edited.
59  *
60  * Revision 1.7  1995/06/01  07:31:28  adam
61  * Rename of many typedefs -> IrTcl_...
62  *
63  * Revision 1.6  1995/05/31  08:36:40  adam
64  * Bug fix in client.tcl: didn't save options on clientrc.tcl.
65  * New method: referenceId. More work on scan.
66  *
67  * Revision 1.5  1995/05/29  08:44:25  adam
68  * Work on delete of objects.
69  *
70  * Revision 1.4  1995/05/26  11:44:10  adam
71  * Bugs fixed. More work on MARC utilities and queries. Test
72  * client is up-to-date again.
73  *
74  * Revision 1.3  1995/05/26  08:54:17  adam
75  * New MARC utilities. Uses prefix query.
76  *
77  * Revision 1.2  1995/05/24  14:10:23  adam
78  * Work on idAuthentication, protocolVersion and options.
79  *
80  * Revision 1.1  1995/05/23  15:34:49  adam
81  * Many new settings, userInformationField, smallSetUpperBound, etc.
82  * A number of settings are inherited when ir-set is executed.
83  * This version is incompatible with the graphical test client (client.tcl).
84  *
85  */
86
87 #ifndef IR_TCLP_H
88 #define IR_TCLP_H
89
90 #include <tcl.h>
91
92 #include <log.h>
93 #include <pquery.h>
94 #if CCL2RPN
95 #include <yaz-ccl.h>
96 #endif
97
98 #include <comstack.h>
99 #include <tcpip.h>
100
101 #if MOSI
102 #include <xmosi.h>
103 #endif
104
105 #include <yaz-version.h>
106 #include <odr.h>
107 #include <proto.h>
108 #include <oid.h>
109 #include <diagbib1.h>
110
111 #include "ir-tcl.h"
112
113 typedef struct {
114     char      **databaseNames;
115     int         num_databaseNames;
116     char       *queryType;
117     enum oid_value *preferredRecordSyntax;
118     int         replaceIndicator;
119     char       *referenceId;
120
121     char       *elementSetNames;
122     char       *smallSetElementSetNames;
123     char       *mediumSetElementSetNames;
124
125     int         smallSetUpperBound;
126     int         largeSetLowerBound;
127     int         mediumSetPresentNumber;
128 } IrTcl_SetCObj;
129     
130 typedef struct {
131     int         ref_count;
132
133     char       *cs_type;
134     int         protocol_type;
135     int         failInfo;
136     COMSTACK    cs_link;
137     
138     int         state;
139
140     int         preferredMessageSize;
141     int         maximumRecordSize;
142     Odr_bitmask options;
143     Odr_bitmask protocolVersion;
144
145     char       *idAuthenticationOpen;
146     char       *idAuthenticationGroupId;
147     char       *idAuthenticationUserId;
148     char       *idAuthenticationPassword;
149
150     char       *implementationName;
151     char       *implementationId;
152     char       *implementationVersion;
153     int        initResult;
154     char       *targetImplementationName;
155     char       *targetImplementationId;
156     char       *targetImplementationVersion;
157     char       *userInformationField;
158
159     char       *hostname;
160     char       *eventType;
161    
162     char       *buf_in;
163     int         len_in;
164     ODR         odr_in;
165     ODR         odr_out;
166     ODR         odr_pr;
167
168     Tcl_Interp *interp;
169     char       *callback;
170     char       *failback;
171
172 #if CCL2RPN
173     CCL_bibset  bibset;
174 #endif
175     struct IrTcl_Request_ *request_queue;
176
177     IrTcl_SetCObj   set_inher;
178 } IrTcl_Obj;
179
180 typedef struct IrTcl_Request_ {
181     struct IrTcl_Request_ *next; 
182
183     char       *object_name;
184     
185     char       *buf_out;
186     int         len_out;
187
188     char       *callback;
189 } IrTcl_Request;
190
191 typedef struct {
192     int condition;
193     char *addinfo;
194 } IrTcl_Diagnostic;
195
196 struct GRS_Record_entry {
197     int tagType;
198     int tagWhich;
199     union {
200         int num;
201         char *str;
202     } tagVal;
203     int dataWhich;
204     union {
205         struct IrTcl_GRS_Record_ *sub;
206         char *str;
207         struct {
208             int len;
209             char *buf;
210         } octets;
211         int num;
212         int bool;
213     } tagData;
214 };
215
216 typedef struct IrTcl_GRS_Record_ {
217     int noTags;
218     struct GRS_Record_entry *entries;
219 } IrTcl_GRS_Record;
220
221 typedef struct IrTcl_RecordList_ {
222     int no;
223     char *elements;
224     int which;
225     union {
226         struct {
227             char *buf;
228             size_t size;
229             union {
230                 IrTcl_GRS_Record *grs1;
231             } u;
232             enum oid_value type;
233         } dbrec;
234         struct {
235             int num;
236             IrTcl_Diagnostic *list;
237         } surrogateDiagnostics;
238     } u;
239     struct IrTcl_RecordList_ *next;
240 } IrTcl_RecordList;
241
242 typedef struct IrTcl_SetObj_ {
243     IrTcl_Obj  *parent;
244     int         searchStatus;
245     int         presentStatus;
246     int         resultCount;
247     int         nextResultSetPosition;
248     int         start;
249     int         number;
250     int         numberOfRecordsReturned;
251     char       *setName;
252     char       *recordElements;
253     int         recordFlag;
254     int         which;
255     int         nonSurrogateDiagnosticNum;
256     IrTcl_Diagnostic *nonSurrogateDiagnosticList;
257     IrTcl_RecordList *record_list;
258     IrTcl_SetCObj set_inher;
259 } IrTcl_SetObj;
260
261 typedef struct IrTcl_ScanEntry_ {
262     int         which;
263     union {
264         struct {
265             char *buf;
266             int  globalOccurrences;
267         } term;
268         struct {
269             IrTcl_Diagnostic *list;
270             int num;
271         } diag;
272     } u;
273 } IrTcl_ScanEntry;
274
275 typedef struct IrTcl_ScanObj_ {
276     IrTcl_Obj   *parent;
277     int         stepSize;
278     int         numberOfTermsRequested;
279     int         preferredPositionInResponse;
280
281     int         scanStatus;
282     int         numberOfEntriesReturned;
283     int         positionOfTerm;
284
285     int         entries_flag;
286     int         which;
287
288     int         num_entries;
289     int         num_diagRecs;
290
291     IrTcl_ScanEntry *entries;
292     IrTcl_Diagnostic  *nonSurrogateDiagnosticList;
293     int         nonSurrogateDiagnosticNum;
294 } IrTcl_ScanObj;
295
296 struct ir_named_entry {
297     char *name;
298     int  pos;
299 };
300
301 int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf,
302                      int argc, char **argv);
303 int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
304                       const char *msg, const char *object_name);
305 int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rq, const char *msg);
306 void ir_tcl_del_q (IrTcl_Obj *p);
307 void *ir_tcl_malloc (size_t size);
308 int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s);
309 int ir_tcl_strdel (Tcl_Interp *interp, char **p);
310
311 char *ir_tcl_fread_marc (FILE *inf, size_t *size);
312 void ir_tcl_read_grs (Z_GenericRecord *r, IrTcl_GRS_Record **grs_record);
313 int ir_tcl_get_grs (Tcl_Interp *interp, IrTcl_GRS_Record *grs_record, 
314                      int argc, char **argv);
315
316 #define IR_TCL_FAIL_CONNECT      1
317 #define IR_TCL_FAIL_READ         2
318 #define IR_TCL_FAIL_WRITE        3
319 #define IR_TCL_FAIL_IN_APDU      4
320 #define IR_TCL_FAIL_UNKNOWN_APDU 5
321
322 #define IR_TCL_R_Idle            0
323 #define IR_TCL_R_Writing         1
324 #define IR_TCL_R_Waiting         2
325 #define IR_TCL_R_Reading         3
326 #define IR_TCL_R_Connecting      4
327 #endif