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