2 * IR toolkit for tcl/tk
3 * (c) Index Data 1995-1999
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.39 1999-11-30 14:05:58 adam
9 * Updated for new location of YAZ headers.
11 * Revision 1.38 1999/03/22 06:51:34 adam
14 * Revision 1.37 1998/04/02 14:31:08 adam
15 * This version works with compiled ASN.1 code.
17 * Revision 1.36 1997/11/19 11:22:09 adam
18 * Object identifiers can be accessed in GRS-1 records.
20 * Revision 1.35 1997/09/09 10:19:54 adam
21 * New MSV5.0 port with fewer warnings.
23 * Revision 1.34 1996/08/16 15:07:47 adam
24 * First work on Explain.
26 * Revision 1.33 1996/07/03 13:31:13 adam
27 * The xmalloc/xfree functions from YAZ are used to manage memory.
29 * Revision 1.32 1996/03/20 13:54:05 adam
30 * The Tcl_File structure is only manipulated in the Tk-event interface
33 * Revision 1.31 1996/03/05 09:21:19 adam
34 * Bug fix: memory used by GRS records wasn't freed.
35 * Rewrote some of the error handling code - the connection is always
36 * closed before failback is called.
37 * If failback is defined the send APDU methods (init, search, ...) will
38 * return OK but invoke failback (as is the case if the write operation
40 * Bug fix: ref_count in assoc object could grow if fraction of PDU was
43 * Revision 1.30 1996/02/29 15:30:23 adam
44 * Export of IrTcl functionality to extensions.
46 * Revision 1.29 1996/02/26 18:38:33 adam
47 * Work on export of set methods.
49 * Revision 1.28 1996/02/23 17:31:41 adam
50 * More functions made available to the wais tcl extension.
52 * Revision 1.27 1996/02/23 13:41:41 adam
53 * Work on public access to simple ir class system.
55 * Revision 1.26 1996/02/21 10:16:20 adam
56 * Simplified select handling. Only one function ir_tcl_select_set has
57 * to be externally defined.
59 * Revision 1.25 1996/02/05 17:58:04 adam
60 * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1.
62 * Revision 1.24 1996/01/29 11:35:27 adam
63 * Bug fix: cs_type member renamed to comstackType to avoid conflict with
64 * cs_type macro defined by YAZ.
66 * Revision 1.23 1996/01/19 16:22:40 adam
67 * New method: apduDump - returns information about last incoming APDU.
69 * Revision 1.22 1996/01/10 09:18:44 adam
70 * PDU specific callbacks implemented: initRespnse, searchResponse,
71 * presentResponse and scanResponse.
72 * Bug fix in the command line shell (tclmain.c) - discovered on OSF/1.
74 * Revision 1.21 1996/01/04 16:12:14 adam
75 * Setting PDUType renamed to eventType.
77 * Revision 1.20 1996/01/04 11:05:23 adam
78 * New setting: PDUType - returns type of last PDU returned from the target.
79 * Fixed a bug in configure/Makefile.
81 * Revision 1.19 1995/11/13 09:55:46 adam
82 * Multiple records at a position in a result-set with differnt
85 * Revision 1.18 1995/10/18 16:42:44 adam
86 * New settings: smallSetElementSetNames and mediumSetElementSetNames.
88 * Revision 1.17 1995/10/16 17:00:56 adam
89 * New setting: elementSetNames.
90 * Various client improvements. Medium presentation format looks better.
92 * Revision 1.16 1995/09/20 11:37:01 adam
93 * Configure searches for tk4.1 and tk7.5.
96 * Revision 1.15 1995/08/29 15:30:15 adam
97 * Work on GRS records.
99 * Revision 1.14 1995/08/04 11:32:40 adam
100 * More work on output queue. Memory related routines moved
103 * Revision 1.13 1995/08/03 13:23:00 adam
106 * Revision 1.12 1995/07/28 10:28:38 adam
107 * First work on request queue.
109 * Revision 1.11 1995/06/20 08:07:35 adam
110 * New setting: failInfo.
111 * Working on better cancel mechanism.
113 * Revision 1.10 1995/06/16 12:28:20 adam
114 * Implemented preferredRecordSyntax.
115 * Minor changes in diagnostic handling.
116 * Record list deleted when connection closes.
118 * Revision 1.9 1995/06/14 15:08:01 adam
119 * Bug fix in cascade-target-list. Uses yaz-version.h.
121 * Revision 1.8 1995/06/14 13:37:18 adam
122 * Setting recordType implemented.
123 * Setting implementationVersion implemented.
124 * Settings implementationId / implementationName edited.
126 * Revision 1.7 1995/06/01 07:31:28 adam
127 * Rename of many typedefs -> IrTcl_...
129 * Revision 1.6 1995/05/31 08:36:40 adam
130 * Bug fix in client.tcl: didn't save options on clientrc.tcl.
131 * New method: referenceId. More work on scan.
133 * Revision 1.5 1995/05/29 08:44:25 adam
134 * Work on delete of objects.
136 * Revision 1.4 1995/05/26 11:44:10 adam
137 * Bugs fixed. More work on MARC utilities and queries. Test
138 * client is up-to-date again.
140 * Revision 1.3 1995/05/26 08:54:17 adam
141 * New MARC utilities. Uses prefix query.
143 * Revision 1.2 1995/05/24 14:10:23 adam
144 * Work on idAuthentication, protocolVersion and options.
146 * Revision 1.1 1995/05/23 15:34:49 adam
147 * Many new settings, userInformationField, smallSetUpperBound, etc.
148 * A number of settings are inherited when ir-set is executed.
149 * This version is incompatible with the graphical test client (client.tcl).
159 #include <yaz/pquery.h>
161 #include <yaz/yaz-ccl.h>
164 #include <yaz/comstack.h>
165 #include <yaz/tcpip.h>
168 #include <yas/xmosi.h>
171 #include <yaz/yaz-version.h>
173 #include <yaz/proto.h>
175 #include <yaz/diagbib1.h>
176 #include <yaz/xmalloc.h>
182 int (*method) (void *obj, Tcl_Interp *interp, int argc, char **argv);
192 char **databaseNames;
193 int num_databaseNames;
195 enum oid_value *preferredRecordSyntax;
196 int replaceIndicator;
199 char *elementSetNames;
200 char *smallSetElementSetNames;
201 char *mediumSetElementSetNames;
203 int smallSetUpperBound;
204 int largeSetLowerBound;
205 int mediumSetPresentNumber;
218 int preferredMessageSize;
219 int maximumRecordSize;
221 Odr_bitmask protocolVersion;
223 char *idAuthenticationOpen;
224 char *idAuthenticationGroupId;
225 char *idAuthenticationUserId;
226 char *idAuthenticationPassword;
228 char *implementationName;
229 char *implementationId;
230 char *implementationVersion;
232 char *targetImplementationName;
233 char *targetImplementationId;
234 char *targetImplementationVersion;
235 char *userInformationField;
257 struct IrTcl_Request_ *request_queue;
259 IrTcl_SetCObj set_inher;
262 typedef struct IrTcl_Request_ {
263 struct IrTcl_Request_ *next;
278 struct GRS_Record_entry {
287 struct IrTcl_GRS_Record_ *sub;
299 typedef struct IrTcl_GRS_Record_ {
301 struct GRS_Record_entry *entries;
304 typedef struct IrTcl_RecordList_ {
313 IrTcl_GRS_Record *grs1;
322 IrTcl_Diagnostic *list;
323 } surrogateDiagnostics;
325 struct IrTcl_RecordList_ *next;
328 typedef struct IrTcl_SetObj_ {
334 int nextResultSetPosition;
337 int numberOfRecordsReturned;
339 char *recordElements;
342 int nonSurrogateDiagnosticNum;
343 char *searchResponse;
344 char *presentResponse;
346 IrTcl_Diagnostic *nonSurrogateDiagnosticList;
347 IrTcl_RecordList *record_list;
348 IrTcl_SetCObj set_inher;
351 typedef struct IrTcl_ScanEntry_ {
356 int globalOccurrences;
359 IrTcl_Diagnostic *list;
365 typedef struct IrTcl_ScanObj_ {
368 int numberOfTermsRequested;
369 int preferredPositionInResponse;
372 int numberOfEntriesReturned;
384 IrTcl_ScanEntry *entries;
385 IrTcl_Diagnostic *nonSurrogateDiagnosticList;
386 int nonSurrogateDiagnosticNum;
389 struct ir_named_entry {
394 int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf,
395 int argc, char **argv);
396 int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
397 const char *msg, const char *object_name);
398 int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rq, const char *msg);
399 void ir_tcl_del_q (IrTcl_Obj *p);
400 int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s);
401 int ir_tcl_strdel (Tcl_Interp *interp, char **p);
403 char *ir_tcl_fread_marc (FILE *inf, size_t *size);
404 void ir_tcl_grs_mk (Z_GenericRecord *r, IrTcl_GRS_Record **grs_record);
405 void ir_tcl_grs_del (IrTcl_GRS_Record **grs_record);
406 int ir_tcl_get_grs (Tcl_Interp *interp, IrTcl_GRS_Record *grs_record,
407 int argc, char **argv);
409 int ir_tcl_get_explain (Tcl_Interp *interp, Z_ExplainRecord *rec,
410 int argc, char **argv);
412 int ir_tcl_method (Tcl_Interp *interp, int argc, char **argv,
413 IrTcl_Methods *tab, int *ret);
414 int ir_tcl_get_set_int (int *val, Tcl_Interp *interp, int argc, char **argv);
418 int (*ir_init) (ClientData clientData, Tcl_Interp *interp,
419 int argc, char **argv, ClientData *subData,
420 ClientData parentData);
421 int (*ir_method) (ClientData clientData, Tcl_Interp *interp,
422 int argc, char **argv);
423 void (*ir_delete)(ClientData clientData);
426 extern IrTcl_Class ir_obj_class;
427 extern IrTcl_Class ir_set_obj_class;
429 void ir_select_add (int fd, void *obj);
430 void ir_select_add_write (int fd, void *obj);
431 void ir_select_remove (int fd, void *obj);
432 void ir_select_remove_write (int fd, void *obj);
434 int ir_tcl_eval (Tcl_Interp *interp, const char *command);
435 void ir_tcl_disconnect (IrTcl_Obj *p);
437 #define IR_TCL_FAIL_CONNECT 1
438 #define IR_TCL_FAIL_READ 2
439 #define IR_TCL_FAIL_WRITE 3
440 #define IR_TCL_FAIL_IN_APDU 4
441 #define IR_TCL_FAIL_UNKNOWN_APDU 5
443 #define IR_TCL_R_Idle 0
444 #define IR_TCL_R_Writing 1
445 #define IR_TCL_R_Waiting 2
446 #define IR_TCL_R_Reading 3
447 #define IR_TCL_R_Connecting 4