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