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