2 * IR toolkit for tcl/tk
3 * (c) Index Data 1995-2002
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.40 2002-03-20 14:48:54 adam
9 * implemented USR.1 SearchResult-1
11 * Revision 1.39 1999/11/30 14:05:58 adam
12 * Updated for new location of YAZ headers.
14 * Revision 1.38 1999/03/22 06:51:34 adam
17 * Revision 1.37 1998/04/02 14:31:08 adam
18 * This version works with compiled ASN.1 code.
20 * Revision 1.36 1997/11/19 11:22:09 adam
21 * Object identifiers can be accessed in GRS-1 records.
23 * Revision 1.35 1997/09/09 10:19:54 adam
24 * New MSV5.0 port with fewer warnings.
26 * Revision 1.34 1996/08/16 15:07:47 adam
27 * First work on Explain.
29 * Revision 1.33 1996/07/03 13:31:13 adam
30 * The xmalloc/xfree functions from YAZ are used to manage memory.
32 * Revision 1.32 1996/03/20 13:54:05 adam
33 * The Tcl_File structure is only manipulated in the Tk-event interface
36 * Revision 1.31 1996/03/05 09:21:19 adam
37 * Bug fix: memory used by GRS records wasn't freed.
38 * Rewrote some of the error handling code - the connection is always
39 * closed before failback is called.
40 * If failback is defined the send APDU methods (init, search, ...) will
41 * return OK but invoke failback (as is the case if the write operation
43 * Bug fix: ref_count in assoc object could grow if fraction of PDU was
46 * Revision 1.30 1996/02/29 15:30:23 adam
47 * Export of IrTcl functionality to extensions.
49 * Revision 1.29 1996/02/26 18:38:33 adam
50 * Work on export of set methods.
52 * Revision 1.28 1996/02/23 17:31:41 adam
53 * More functions made available to the wais tcl extension.
55 * Revision 1.27 1996/02/23 13:41:41 adam
56 * Work on public access to simple ir class system.
58 * Revision 1.26 1996/02/21 10:16:20 adam
59 * Simplified select handling. Only one function ir_tcl_select_set has
60 * to be externally defined.
62 * Revision 1.25 1996/02/05 17:58:04 adam
63 * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1.
65 * Revision 1.24 1996/01/29 11:35:27 adam
66 * Bug fix: cs_type member renamed to comstackType to avoid conflict with
67 * cs_type macro defined by YAZ.
69 * Revision 1.23 1996/01/19 16:22:40 adam
70 * New method: apduDump - returns information about last incoming APDU.
72 * Revision 1.22 1996/01/10 09:18:44 adam
73 * PDU specific callbacks implemented: initRespnse, searchResponse,
74 * presentResponse and scanResponse.
75 * Bug fix in the command line shell (tclmain.c) - discovered on OSF/1.
77 * Revision 1.21 1996/01/04 16:12:14 adam
78 * Setting PDUType renamed to eventType.
80 * Revision 1.20 1996/01/04 11:05:23 adam
81 * New setting: PDUType - returns type of last PDU returned from the target.
82 * Fixed a bug in configure/Makefile.
84 * Revision 1.19 1995/11/13 09:55:46 adam
85 * Multiple records at a position in a result-set with differnt
88 * Revision 1.18 1995/10/18 16:42:44 adam
89 * New settings: smallSetElementSetNames and mediumSetElementSetNames.
91 * Revision 1.17 1995/10/16 17:00:56 adam
92 * New setting: elementSetNames.
93 * Various client improvements. Medium presentation format looks better.
95 * Revision 1.16 1995/09/20 11:37:01 adam
96 * Configure searches for tk4.1 and tk7.5.
99 * Revision 1.15 1995/08/29 15:30:15 adam
100 * Work on GRS records.
102 * Revision 1.14 1995/08/04 11:32:40 adam
103 * More work on output queue. Memory related routines moved
106 * Revision 1.13 1995/08/03 13:23:00 adam
109 * Revision 1.12 1995/07/28 10:28:38 adam
110 * First work on request queue.
112 * Revision 1.11 1995/06/20 08:07:35 adam
113 * New setting: failInfo.
114 * Working on better cancel mechanism.
116 * Revision 1.10 1995/06/16 12:28:20 adam
117 * Implemented preferredRecordSyntax.
118 * Minor changes in diagnostic handling.
119 * Record list deleted when connection closes.
121 * Revision 1.9 1995/06/14 15:08:01 adam
122 * Bug fix in cascade-target-list. Uses yaz-version.h.
124 * Revision 1.8 1995/06/14 13:37:18 adam
125 * Setting recordType implemented.
126 * Setting implementationVersion implemented.
127 * Settings implementationId / implementationName edited.
129 * Revision 1.7 1995/06/01 07:31:28 adam
130 * Rename of many typedefs -> IrTcl_...
132 * Revision 1.6 1995/05/31 08:36:40 adam
133 * Bug fix in client.tcl: didn't save options on clientrc.tcl.
134 * New method: referenceId. More work on scan.
136 * Revision 1.5 1995/05/29 08:44:25 adam
137 * Work on delete of objects.
139 * Revision 1.4 1995/05/26 11:44:10 adam
140 * Bugs fixed. More work on MARC utilities and queries. Test
141 * client is up-to-date again.
143 * Revision 1.3 1995/05/26 08:54:17 adam
144 * New MARC utilities. Uses prefix query.
146 * Revision 1.2 1995/05/24 14:10:23 adam
147 * Work on idAuthentication, protocolVersion and options.
149 * Revision 1.1 1995/05/23 15:34:49 adam
150 * Many new settings, userInformationField, smallSetUpperBound, etc.
151 * A number of settings are inherited when ir-set is executed.
152 * This version is incompatible with the graphical test client (client.tcl).
162 #include <yaz/pquery.h>
164 #include <yaz/yaz-ccl.h>
167 #include <yaz/comstack.h>
168 #include <yaz/tcpip.h>
171 #include <yas/xmosi.h>
174 #include <yaz/yaz-version.h>
176 #include <yaz/proto.h>
178 #include <yaz/diagbib1.h>
179 #include <yaz/xmalloc.h>
185 int (*method) (void *obj, Tcl_Interp *interp, int argc, char **argv);
195 char **databaseNames;
196 int num_databaseNames;
198 enum oid_value *preferredRecordSyntax;
199 int replaceIndicator;
202 char *elementSetNames;
203 char *smallSetElementSetNames;
204 char *mediumSetElementSetNames;
206 int smallSetUpperBound;
207 int largeSetLowerBound;
208 int mediumSetPresentNumber;
221 int preferredMessageSize;
222 int maximumRecordSize;
224 Odr_bitmask protocolVersion;
226 char *idAuthenticationOpen;
227 char *idAuthenticationGroupId;
228 char *idAuthenticationUserId;
229 char *idAuthenticationPassword;
231 char *implementationName;
232 char *implementationId;
233 char *implementationVersion;
235 char *targetImplementationName;
236 char *targetImplementationId;
237 char *targetImplementationVersion;
238 char *userInformationField;
260 struct IrTcl_Request_ *request_queue;
262 IrTcl_SetCObj set_inher;
266 typedef struct IrTcl_Request_ {
267 struct IrTcl_Request_ *next;
282 struct GRS_Record_entry {
291 struct IrTcl_GRS_Record_ *sub;
303 typedef struct IrTcl_GRS_Record_ {
305 struct GRS_Record_entry *entries;
308 typedef struct IrTcl_RecordList_ {
317 IrTcl_GRS_Record *grs1;
326 IrTcl_Diagnostic *list;
327 } surrogateDiagnostics;
329 struct IrTcl_RecordList_ *next;
332 typedef struct IrTcl_SetObj_ {
338 int nextResultSetPosition;
341 int numberOfRecordsReturned;
343 char *recordElements;
346 int nonSurrogateDiagnosticNum;
347 char *searchResponse;
348 char *presentResponse;
350 IrTcl_Diagnostic *nonSurrogateDiagnosticList;
351 IrTcl_RecordList *record_list;
352 IrTcl_SetCObj set_inher;
353 int searchResult_num;
354 char **searchResult_terms;
355 int *searchResult_count;
358 typedef struct IrTcl_ScanEntry_ {
363 int globalOccurrences;
366 IrTcl_Diagnostic *list;
372 typedef struct IrTcl_ScanObj_ {
375 int numberOfTermsRequested;
376 int preferredPositionInResponse;
379 int numberOfEntriesReturned;
391 IrTcl_ScanEntry *entries;
392 IrTcl_Diagnostic *nonSurrogateDiagnosticList;
393 int nonSurrogateDiagnosticNum;
396 struct ir_named_entry {
401 int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf,
402 int argc, char **argv);
403 int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
404 const char *msg, const char *object_name);
405 int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rq, const char *msg);
406 void ir_tcl_del_q (IrTcl_Obj *p);
407 int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s);
408 int ir_tcl_strdel (Tcl_Interp *interp, char **p);
410 char *ir_tcl_fread_marc (FILE *inf, size_t *size);
411 void ir_tcl_grs_mk (Z_GenericRecord *r, IrTcl_GRS_Record **grs_record);
412 void ir_tcl_grs_del (IrTcl_GRS_Record **grs_record);
413 int ir_tcl_get_grs (Tcl_Interp *interp, IrTcl_GRS_Record *grs_record,
414 int argc, char **argv);
416 int ir_tcl_get_explain (Tcl_Interp *interp, Z_ExplainRecord *rec,
417 int argc, char **argv);
419 int ir_tcl_method (Tcl_Interp *interp, int argc, char **argv,
420 IrTcl_Methods *tab, int *ret);
421 int ir_tcl_get_set_int (int *val, Tcl_Interp *interp, int argc, char **argv);
425 int (*ir_init) (ClientData clientData, Tcl_Interp *interp,
426 int argc, char **argv, ClientData *subData,
427 ClientData parentData);
428 int (*ir_method) (ClientData clientData, Tcl_Interp *interp,
429 int argc, char **argv);
430 void (*ir_delete)(ClientData clientData);
433 extern IrTcl_Class ir_obj_class;
434 extern IrTcl_Class ir_set_obj_class;
436 void ir_select_add (int fd, void *obj);
437 void ir_select_add_write (int fd, void *obj);
438 void ir_select_remove (int fd, void *obj);
439 void ir_select_remove_write (int fd, void *obj);
441 int ir_tcl_eval (Tcl_Interp *interp, const char *command);
442 void ir_tcl_disconnect (IrTcl_Obj *p);
444 #define IR_TCL_FAIL_CONNECT 1
445 #define IR_TCL_FAIL_READ 2
446 #define IR_TCL_FAIL_WRITE 3
447 #define IR_TCL_FAIL_IN_APDU 4
448 #define IR_TCL_FAIL_UNKNOWN_APDU 5
450 #define IR_TCL_R_Idle 0
451 #define IR_TCL_R_Writing 1
452 #define IR_TCL_R_Waiting 2
453 #define IR_TCL_R_Reading 3
454 #define IR_TCL_R_Connecting 4