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