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