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