More functions made available to the wais tcl extension.
[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.28  1996-02-23 17:31:41  adam
9  * More functions made available to the wais tcl extension.
10  *
11  * Revision 1.27  1996/02/23  13:41:41  adam
12  * Work on public access to simple ir class system.
13  *
14  * Revision 1.26  1996/02/21  10:16:20  adam
15  * Simplified select handling. Only one function ir_tcl_select_set has
16  * to be externally defined.
17  *
18  * Revision 1.25  1996/02/05  17:58:04  adam
19  * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1.
20  *
21  * Revision 1.24  1996/01/29  11:35:27  adam
22  * Bug fix: cs_type member renamed to comstackType to avoid conflict with
23  * cs_type macro defined by YAZ.
24  *
25  * Revision 1.23  1996/01/19  16:22:40  adam
26  * New method: apduDump - returns information about last incoming APDU.
27  *
28  * Revision 1.22  1996/01/10  09:18:44  adam
29  * PDU specific callbacks implemented: initRespnse, searchResponse,
30  *  presentResponse and scanResponse.
31  * Bug fix in the command line shell (tclmain.c) - discovered on OSF/1.
32  *
33  * Revision 1.21  1996/01/04  16:12:14  adam
34  * Setting PDUType renamed to eventType.
35  *
36  * Revision 1.20  1996/01/04  11:05:23  adam
37  * New setting: PDUType - returns type of last PDU returned from the target.
38  * Fixed a bug in configure/Makefile.
39  *
40  * Revision 1.19  1995/11/13  09:55:46  adam
41  * Multiple records at a position in a result-set with differnt
42  * element specs.
43  *
44  * Revision 1.18  1995/10/18  16:42:44  adam
45  * New settings: smallSetElementSetNames and mediumSetElementSetNames.
46  *
47  * Revision 1.17  1995/10/16  17:00:56  adam
48  * New setting: elementSetNames.
49  * Various client improvements. Medium presentation format looks better.
50  *
51  * Revision 1.16  1995/09/20  11:37:01  adam
52  * Configure searches for tk4.1 and tk7.5.
53  * Work on GRS.
54  *
55  * Revision 1.15  1995/08/29  15:30:15  adam
56  * Work on GRS records.
57  *
58  * Revision 1.14  1995/08/04  11:32:40  adam
59  * More work on output queue. Memory related routines moved
60  * to mem.c
61  *
62  * Revision 1.13  1995/08/03  13:23:00  adam
63  * Request queue.
64  *
65  * Revision 1.12  1995/07/28  10:28:38  adam
66  * First work on request queue.
67  *
68  * Revision 1.11  1995/06/20  08:07:35  adam
69  * New setting: failInfo.
70  * Working on better cancel mechanism.
71  *
72  * Revision 1.10  1995/06/16  12:28:20  adam
73  * Implemented preferredRecordSyntax.
74  * Minor changes in diagnostic handling.
75  * Record list deleted when connection closes.
76  *
77  * Revision 1.9  1995/06/14  15:08:01  adam
78  * Bug fix in cascade-target-list. Uses yaz-version.h.
79  *
80  * Revision 1.8  1995/06/14  13:37:18  adam
81  * Setting recordType implemented.
82  * Setting implementationVersion implemented.
83  * Settings implementationId / implementationName edited.
84  *
85  * Revision 1.7  1995/06/01  07:31:28  adam
86  * Rename of many typedefs -> IrTcl_...
87  *
88  * Revision 1.6  1995/05/31  08:36:40  adam
89  * Bug fix in client.tcl: didn't save options on clientrc.tcl.
90  * New method: referenceId. More work on scan.
91  *
92  * Revision 1.5  1995/05/29  08:44:25  adam
93  * Work on delete of objects.
94  *
95  * Revision 1.4  1995/05/26  11:44:10  adam
96  * Bugs fixed. More work on MARC utilities and queries. Test
97  * client is up-to-date again.
98  *
99  * Revision 1.3  1995/05/26  08:54:17  adam
100  * New MARC utilities. Uses prefix query.
101  *
102  * Revision 1.2  1995/05/24  14:10:23  adam
103  * Work on idAuthentication, protocolVersion and options.
104  *
105  * Revision 1.1  1995/05/23  15:34:49  adam
106  * Many new settings, userInformationField, smallSetUpperBound, etc.
107  * A number of settings are inherited when ir-set is executed.
108  * This version is incompatible with the graphical test client (client.tcl).
109  *
110  */
111
112 #ifndef IR_TCLP_H
113 #define IR_TCLP_H
114
115 #include <tcl.h>
116
117 #include <log.h>
118 #include <pquery.h>
119 #if CCL2RPN
120 #include <yaz-ccl.h>
121 #endif
122
123 #include <comstack.h>
124 #include <tcpip.h>
125
126 #if MOSI
127 #include <xmosi.h>
128 #endif
129
130 #include <yaz-version.h>
131 #include <odr.h>
132 #include <proto.h>
133 #include <oid.h>
134 #include <diagbib1.h>
135
136 #include "ir-tcl.h"
137
138 typedef struct {
139     char *name;
140     int (*method) (void *obj, Tcl_Interp *interp, int argc, char **argv);
141     char *desc;
142 } IrTcl_Method;
143
144 typedef struct {
145     void *obj;
146     IrTcl_Method *tab;
147 } IrTcl_Methods;
148
149 typedef struct {
150     char      **databaseNames;
151     int         num_databaseNames;
152     char       *queryType;
153     enum oid_value *preferredRecordSyntax;
154     int         replaceIndicator;
155     char       *referenceId;
156
157     char       *elementSetNames;
158     char       *smallSetElementSetNames;
159     char       *mediumSetElementSetNames;
160
161     int         smallSetUpperBound;
162     int         largeSetLowerBound;
163     int         mediumSetPresentNumber;
164 } IrTcl_SetCObj;
165     
166 typedef struct {
167     int         ref_count;
168
169     char       *comstackType;
170     int         protocol_type;
171     int         failInfo;
172     COMSTACK    cs_link;
173 #if IRTCL_GENERIC_FILES
174     Tcl_File    csFile;
175 #endif
176     
177     int         state;
178
179     int         preferredMessageSize;
180     int         maximumRecordSize;
181     Odr_bitmask options;
182     Odr_bitmask protocolVersion;
183
184     char       *idAuthenticationOpen;
185     char       *idAuthenticationGroupId;
186     char       *idAuthenticationUserId;
187     char       *idAuthenticationPassword;
188
189     char       *implementationName;
190     char       *implementationId;
191     char       *implementationVersion;
192     int        initResult;
193     char       *targetImplementationName;
194     char       *targetImplementationId;
195     char       *targetImplementationVersion;
196     char       *userInformationField;
197
198     char       *hostname;
199     char       *eventType;
200    
201     char       *buf_in;
202     int         len_in;
203     ODR         odr_in;
204     ODR         odr_out;
205     ODR         odr_pr;
206
207     Tcl_Interp *interp;
208     char       *callback;
209     char       *failback;
210     char       *initResponse;
211
212     int        apduLen;
213     int        apduOffset;
214
215 #if CCL2RPN
216     CCL_bibset  bibset;
217 #endif
218     struct IrTcl_Request_ *request_queue;
219
220     IrTcl_SetCObj   set_inher;
221 } IrTcl_Obj;
222
223 typedef struct IrTcl_Request_ {
224     struct IrTcl_Request_ *next; 
225
226     char       *object_name;
227     
228     char       *buf_out;
229     int         len_out;
230
231     char       *callback;
232 } IrTcl_Request;
233
234 typedef struct {
235     int condition;
236     char *addinfo;
237 } IrTcl_Diagnostic;
238
239 struct GRS_Record_entry {
240     int tagType;
241     int tagWhich;
242     union {
243         int num;
244         char *str;
245     } tagVal;
246     int dataWhich;
247     union {
248         struct IrTcl_GRS_Record_ *sub;
249         char *str;
250         struct {
251             int len;
252             char *buf;
253         } octets;
254         int num;
255         int bool;
256     } tagData;
257 };
258
259 typedef struct IrTcl_GRS_Record_ {
260     int noTags;
261     struct GRS_Record_entry *entries;
262 } IrTcl_GRS_Record;
263
264 typedef struct IrTcl_RecordList_ {
265     int no;
266     char *elements;
267     int which;
268     union {
269         struct {
270             char *buf;
271             size_t size;
272             union {
273                 IrTcl_GRS_Record *grs1;
274             } u;
275             enum oid_value type;
276         } dbrec;
277         struct {
278             int num;
279             IrTcl_Diagnostic *list;
280         } surrogateDiagnostics;
281     } u;
282     struct IrTcl_RecordList_ *next;
283 } IrTcl_RecordList;
284
285 typedef struct IrTcl_SetObj_ {
286     IrTcl_Obj  *parent;
287     int         searchStatus;
288     int         presentStatus;
289     int         resultCount;
290     int         nextResultSetPosition;
291     int         start;
292     int         number;
293     int         numberOfRecordsReturned;
294     char       *setName;
295     char       *recordElements;
296     int         recordFlag;
297     int         which;
298     int         nonSurrogateDiagnosticNum;
299     char       *searchResponse;
300     char       *presentResponse;
301     IrTcl_Diagnostic *nonSurrogateDiagnosticList;
302     IrTcl_RecordList *record_list;
303     IrTcl_SetCObj set_inher;
304 } IrTcl_SetObj;
305
306 typedef struct IrTcl_ScanEntry_ {
307     int         which;
308     union {
309         struct {
310             char *buf;
311             int  globalOccurrences;
312         } term;
313         struct {
314             IrTcl_Diagnostic *list;
315             int num;
316         } diag;
317     } u;
318 } IrTcl_ScanEntry;
319
320 typedef struct IrTcl_ScanObj_ {
321     IrTcl_Obj   *parent;
322     int         stepSize;
323     int         numberOfTermsRequested;
324     int         preferredPositionInResponse;
325
326     int         scanStatus;
327     int         numberOfEntriesReturned;
328     int         positionOfTerm;
329
330     int         entries_flag;
331     int         which;
332
333     int         num_entries;
334     int         num_diagRecs;
335
336     char        *scanResponse;
337     IrTcl_ScanEntry *entries;
338     IrTcl_Diagnostic  *nonSurrogateDiagnosticList;
339     int         nonSurrogateDiagnosticNum;
340 } IrTcl_ScanObj;
341
342 struct ir_named_entry {
343     char *name;
344     int  pos;
345 };
346
347 int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf,
348                      int argc, char **argv);
349 int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
350                       const char *msg, const char *object_name);
351 int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rq, const char *msg);
352 void ir_tcl_del_q (IrTcl_Obj *p);
353 int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s);
354 int ir_tcl_strdel (Tcl_Interp *interp, char **p);
355
356 char *ir_tcl_fread_marc (FILE *inf, size_t *size);
357 void ir_tcl_read_grs (Z_GenericRecord *r, IrTcl_GRS_Record **grs_record);
358 int ir_tcl_get_grs (Tcl_Interp *interp, IrTcl_GRS_Record *grs_record, 
359                      int argc, char **argv);
360
361 int ir_tcl_method (Tcl_Interp *interp, int argc, char **argv,
362                    IrTcl_Methods *tab);
363
364 typedef struct {
365     const char *name;
366     int (*ir_init)   (ClientData clientData, Tcl_Interp *interp,
367                       int argc, char **argv, ClientData *subData);
368     int (*ir_method) (ClientData clientData, Tcl_Interp *interp,
369                       int argc, char **argv);
370     void (*ir_delete)(ClientData clientData);
371 } IrTcl_Class;
372
373 extern IrTcl_Class ir_obj_class;
374
375 void ir_select_add (int fd, void *obj);
376 void ir_select_add_write (int fd, void *obj);
377 void ir_select_remove (int fd, void *obj);
378 void ir_select_remove_write (int fd, void *obj);
379
380 int ir_tcl_eval (Tcl_Interp *interp, const char *command);
381
382 #define IR_TCL_FAIL_CONNECT      1
383 #define IR_TCL_FAIL_READ         2
384 #define IR_TCL_FAIL_WRITE        3
385 #define IR_TCL_FAIL_IN_APDU      4
386 #define IR_TCL_FAIL_UNKNOWN_APDU 5
387
388 #define IR_TCL_R_Idle            0
389 #define IR_TCL_R_Writing         1
390 #define IR_TCL_R_Waiting         2
391 #define IR_TCL_R_Reading         3
392 #define IR_TCL_R_Connecting      4
393 #endif