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