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