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