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