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