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