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