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