2 * IR toolkit for tcl/tk
3 * (c) Index Data 1995-2000
4 * See the file LICENSE for details.
7 * Revision 1.115 2000-09-13 12:18:49 adam
8 * Logging utility patch (YAZ version 1.7).
10 * Revision 1.114 1999/05/17 20:37:41 adam
11 * Fixed problem with ASN code.
13 * Revision 1.113 1999/04/20 10:01:46 adam
14 * Modified calls to ODR encoders/decoders (name argument).
16 * Revision 1.112 1999/03/22 06:51:34 adam
19 * Revision 1.111 1999/02/11 11:30:09 adam
22 * Revision 1.110 1998/10/20 15:15:31 adam
23 * Changed scan response handler.
25 * Revision 1.109 1998/10/13 21:23:26 adam
26 * Fixed searchStatus method.
28 * Revision 1.108 1998/10/12 11:48:08 adam
29 * Removed printf call.
31 * Revision 1.107 1998/06/10 13:00:46 adam
32 * Added ir-version command.
34 * Revision 1.106 1998/05/20 12:25:35 adam
35 * Fixed bug that occurred in rare cases when encoding of incoming
38 * Revision 1.105 1998/04/02 14:31:08 adam
39 * This version works with compiled ASN.1 code.
41 * Revision 1.104 1998/02/27 14:26:07 adam
42 * Changed client so that it still works if target sets numberOfRecords
43 * in response to an illegal value.
45 * Revision 1.103 1997/11/19 11:22:10 adam
46 * Object identifiers can be accessed in GRS-1 records.
48 * Revision 1.102 1997/09/17 12:22:40 adam
49 * Changed to use YAZ version 1.4. The new comstack utility, cs_straddr,
52 * Revision 1.101 1997/09/09 10:19:53 adam
53 * New MSV5.0 port with fewer warnings.
55 * Revision 1.100 1997/05/01 15:04:05 adam
56 * Added ir-log command.
58 * Revision 1.99 1997/04/30 07:24:47 adam
59 * Spell fix of an error message.
61 * Revision 1.98 1997/04/13 18:57:20 adam
62 * Better error reporting and aligned with Tcl/Tk style.
63 * Rework of notifier code with Tcl_File handles.
65 * Revision 1.97 1996/11/14 17:11:07 adam
66 * Added Explain documentaion.
68 * Revision 1.96 1996/10/08 13:02:50 adam
69 * When dealing with records, odr_choice_enable_bias function is used to
70 * prevent decoding of externals.
72 * Revision 1.95 1996/09/13 10:51:49 adam
73 * Bug fix: ir_tcl_select_set called Tcl_GetFile at disconnect.
75 * Revision 1.94 1996/08/21 13:32:53 adam
76 * Implemented saveFile method and extended loadFile method to work with it.
78 * Revision 1.93 1996/08/16 15:07:45 adam
79 * First work on Explain.
81 * Revision 1.92 1996/08/09 15:33:07 adam
82 * Modified the code to use tk4.1/tcl7.5 patch level 1. The time-driven
83 * polling is no longer activated on Windows since asynchrounous I/O works
86 * Revision 1.91 1996/07/03 13:31:11 adam
87 * The xmalloc/xfree functions from YAZ are used to manage memory.
89 * Revision 1.90 1996/06/27 14:21:00 adam
90 * Yet another Windows port.
92 * Revision 1.89 1996/06/11 15:27:15 adam
93 * Event type set to connect a little earlier in the do_connect function.
95 * Revision 1.88 1996/06/03 09:04:22 adam
96 * Changed a few logf calls.
98 * Revision 1.87 1996/05/29 06:37:51 adam
99 * Function ir_tcl_get_grs_r enhanced so that specific elements can be
102 * Revision 1.86 1996/03/20 13:54:04 adam
103 * The Tcl_File structure is only manipulated in the Tk-event interface
106 * Revision 1.85 1996/03/15 11:15:48 adam
107 * Modified to use new prototypes for p_query_rpn and p_query_scan.
109 * Revision 1.84 1996/03/07 12:42:49 adam
110 * Better logging when callback is invoked.
112 * Revision 1.83 1996/03/05 09:21:09 adam
113 * Bug fix: memory used by GRS records wasn't freed.
114 * Rewrote some of the error handling code - the connection is always
115 * closed before failback is called.
116 * If failback is defined the send APDU methods (init, search, ...) will
117 * return OK but invoke failback (as is the case if the write operation
119 * Bug fix: ref_count in assoc object could grow if fraction of PDU was
122 * Revision 1.82 1996/02/29 15:30:21 adam
123 * Export of IrTcl functionality to extensions.
125 * Revision 1.81 1996/02/26 18:38:32 adam
126 * Work on export of set methods.
128 * Revision 1.80 1996/02/23 17:31:39 adam
129 * More functions made available to the wais tcl extension.
131 * Revision 1.79 1996/02/23 13:41:38 adam
132 * Work on public access to simple ir class system.
134 * Revision 1.78 1996/02/21 10:16:08 adam
135 * Simplified select handling. Only one function ir_tcl_select_set has
136 * to be externally defined.
138 * Revision 1.77 1996/02/20 17:52:58 adam
139 * Uses the YAZ oid system to name record syntax object identifiers.
141 * Revision 1.76 1996/02/20 16:09:51 adam
142 * Bug fix: didn't set element set names stamp correctly on result
143 * set records when element set names were set to the empty string.
145 * Revision 1.75 1996/02/19 15:41:53 adam
146 * Better log messages.
147 * Minor improvement of connect method.
149 * Revision 1.74 1996/02/05 17:58:03 adam
150 * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1.
152 * Revision 1.73 1996/01/29 11:35:19 adam
153 * Bug fix: cs_type member renamed to comstackType to avoid conflict with
154 * cs_type macro defined by YAZ.
156 * Revision 1.72 1996/01/19 17:45:34 quinn
157 * Added debugging output
159 * Revision 1.71 1996/01/19 16:22:38 adam
160 * New method: apduDump - returns information about last incoming APDU.
162 * Revision 1.70 1996/01/10 09:18:34 adam
163 * PDU specific callbacks implemented: initRespnse, searchResponse,
164 * presentResponse and scanResponse.
165 * Bug fix in the command line shell (tclmain.c) - discovered on OSF/1.
167 * Revision 1.69 1996/01/04 16:12:12 adam
168 * Setting PDUType renamed to eventType.
170 * Revision 1.68 1996/01/04 11:05:22 adam
171 * New setting: PDUType - returns type of last PDU returned from the target.
172 * Fixed a bug in configure/Makefile.
174 * Revision 1.67 1996/01/03 09:00:51 adam
175 * Updated to use new version of Yaz (names changed to avoid C++ conflict).
177 * Revision 1.66 1995/11/28 17:26:39 adam
178 * Removed Carriage return from ir-tcl.c!
179 * Removed misc. debug logs.
181 * Revision 1.65 1995/11/28 13:53:00 quinn
184 * Revision 1.64 1995/11/13 15:39:18 adam
185 * Bug fix: {small,medium}SetElementSetNames weren't set correctly.
186 * Bug fix: idAuthentication weren't set correctly.
188 * Revision 1.63 1995/11/13 09:55:39 adam
189 * Multiple records at a position in a result-set with differnt
192 * Revision 1.62 1995/10/18 17:20:33 adam
193 * Work on target setup in client.tcl.
195 * Revision 1.61 1995/10/18 16:42:42 adam
196 * New settings: smallSetElementSetNames and mediumSetElementSetNames.
198 * Revision 1.60 1995/10/18 15:43:31 adam
199 * In search: mediumSetElementSetNames and smallSetElementSetNames are
200 * set to elementSetNames.
202 * Revision 1.59 1995/10/17 12:18:58 adam
203 * Bug fix: when target connection closed, the connection was not
204 * properly reestablished.
206 * Revision 1.58 1995/10/16 17:00:55 adam
207 * New setting: elementSetNames.
208 * Various client improvements. Medium presentation format looks better.
210 * Revision 1.57 1995/09/21 13:11:51 adam
211 * Support of dynamic loading.
212 * Test script uses load command if necessary.
214 * Revision 1.56 1995/08/29 15:30:14 adam
215 * Work on GRS records.
217 * Revision 1.55 1995/08/28 09:43:25 adam
218 * Minor changes. configure only searches for yaz beta 3 and versions after
221 * Revision 1.54 1995/08/24 12:25:16 adam
222 * Modified to work with yaz 1.0b3.
224 * Revision 1.53 1995/08/04 12:49:26 adam
225 * Bug fix: reading uninitialized variable p.
227 * Revision 1.52 1995/08/04 11:32:38 adam
228 * More work on output queue. Memory related routines moved
231 * Revision 1.51 1995/08/03 13:22:54 adam
234 * Revision 1.50 1995/07/20 08:09:49 adam
235 * client.tcl: Targets removed from hotTargets list when targets
236 * are removed/modified.
237 * ir-tcl.c: More work on triggerResourceControl.
239 * Revision 1.49 1995/06/30 12:39:21 adam
240 * Bug fix: loadFile didn't set record type.
241 * The MARC routines are a little less strict in the interpretation.
242 * Script display.tcl replaces the old marc.tcl.
243 * New interactive script: shell.tcl.
245 * Revision 1.48 1995/06/27 19:03:50 adam
246 * Bug fix in do_present in ir-tcl.c: p->set_child member weren't set.
247 * nextResultSetPosition used instead of setOffset.
249 * Revision 1.47 1995/06/25 10:25:04 adam
250 * Working on triggerResourceControl. Description of compile/install
251 * procedure moved to ir-tcl.sgml.
253 * Revision 1.46 1995/06/22 13:15:06 adam
254 * Feature: SUTRS. Setting getSutrs implemented.
255 * Work on display formats.
256 * Preferred record syntax can be set by the user.
258 * Revision 1.45 1995/06/20 08:07:30 adam
259 * New setting: failInfo.
260 * Working on better cancel mechanism.
262 * Revision 1.44 1995/06/19 17:01:20 adam
265 * Revision 1.43 1995/06/19 13:06:08 adam
266 * New define: IR_TCL_VERSION.
268 * Revision 1.42 1995/06/19 08:08:52 adam
269 * client.tcl: hotTargets now contain both database and target name.
270 * ir-tcl.c: setting protocol edited. Errors in callbacks are logged
271 * by logf(LOG_WARN, ...) calls.
273 * Revision 1.41 1995/06/16 12:28:16 adam
274 * Implemented preferredRecordSyntax.
275 * Minor changes in diagnostic handling.
276 * Record list deleted when connection closes.
278 * Revision 1.40 1995/06/14 13:37:18 adam
279 * Setting recordType implemented.
280 * Setting implementationVersion implemented.
281 * Settings implementationId / implementationName edited.
283 * Revision 1.39 1995/06/08 10:26:32 adam
284 * Bug fix in ir_strdup.
286 * Revision 1.38 1995/06/01 16:36:47 adam
287 * About buttons. Minor bug fixes.
289 * Revision 1.37 1995/06/01 07:31:20 adam
290 * Rename of many typedefs -> IrTcl_...
292 * Revision 1.36 1995/05/31 13:09:59 adam
293 * Client searches/presents may be interrupted.
294 * New moving book-logo.
296 * Revision 1.35 1995/05/31 08:36:33 adam
297 * Bug fix in client.tcl: didn't save options on clientrc.tcl.
298 * New method: referenceId. More work on scan.
300 * Revision 1.34 1995/05/29 10:33:42 adam
301 * README and rename of startup script.
303 * Revision 1.33 1995/05/29 09:15:11 quinn
304 * Changed CS_SR to PROTO_SR, etc.
306 * Revision 1.32 1995/05/29 08:44:16 adam
307 * Work on delete of objects.
309 * Revision 1.31 1995/05/26 11:44:10 adam
310 * Bugs fixed. More work on MARC utilities and queries. Test
311 * client is up-to-date again.
313 * Revision 1.30 1995/05/26 08:54:11 adam
314 * New MARC utilities. Uses prefix query.
316 * Revision 1.29 1995/05/24 14:10:22 adam
317 * Work on idAuthentication, protocolVersion and options.
319 * Revision 1.28 1995/05/23 15:34:48 adam
320 * Many new settings, userInformationField, smallSetUpperBound, etc.
321 * A number of settings are inherited when ir-set is executed.
322 * This version is incompatible with the graphical test client (client.tcl).
324 * Revision 1.27 1995/05/11 15:34:47 adam
325 * Scan request changed a bit. This version works with RLG.
327 * Revision 1.26 1995/04/18 16:11:51 adam
328 * First version of graphical Scan. Some work on query-by-form.
330 * Revision 1.25 1995/04/17 09:37:17 adam
331 * Further development of scan.
333 * Revision 1.24 1995/04/11 14:16:42 adam
334 * Further work on scan. Response works. Entries aren't saved yet.
336 * Revision 1.23 1995/04/10 10:50:27 adam
337 * Result-set name defaults to suffix of ir-set name.
338 * Started working on scan. Not finished at this point.
340 * Revision 1.22 1995/03/31 10:43:03 adam
341 * More robust when getting bad MARC records.
343 * Revision 1.21 1995/03/31 08:56:37 adam
344 * New button "Search".
346 * Revision 1.20 1995/03/29 16:07:09 adam
347 * Bug fix: Didn't use setName in present request.
349 * Revision 1.19 1995/03/28 12:45:23 adam
350 * New ir method failback: called on disconnect/protocol error.
351 * New ir set/get method: protocol: SR / Z3950.
352 * Simple popup and disconnect when failback is invoked.
354 * Revision 1.18 1995/03/21 15:50:12 adam
357 * Revision 1.17 1995/03/21 13:41:03 adam
358 * Comstack cs_create not used too often. Non-blocking connect.
360 * Revision 1.16 1995/03/21 08:26:06 adam
361 * New method, setName, to specify the result set name (other than Default).
362 * New method, responseStatus, which returns diagnostic info, if any, after
363 * present response / search response.
365 * Revision 1.15 1995/03/20 15:24:07 adam
366 * Diagnostic records saved on searchResponse.
368 * Revision 1.14 1995/03/20 08:53:22 adam
369 * Event loop in tclmain.c rewritten. New method searchStatus.
371 * Revision 1.13 1995/03/17 18:26:17 adam
372 * Non-blocking i/o used now. Database names popup as cascade items.
374 * Revision 1.12 1995/03/17 15:45:00 adam
375 * Improved target/database setup.
377 * Revision 1.11 1995/03/16 17:54:03 adam
378 * Minor changes really.
380 * Revision 1.10 1995/03/15 16:14:50 adam
381 * Blocking arg in cs_create changed.
383 * Revision 1.9 1995/03/15 13:59:24 adam
386 * Revision 1.8 1995/03/15 08:25:16 adam
387 * New method presentStatus to check for error on present. Misc. cleanup
388 * of IrTcl_RecordList manipulations. Full MARC record presentation in
391 * Revision 1.7 1995/03/14 17:32:29 adam
392 * Presentation of full Marc record in popup window.
394 * Revision 1.6 1995/03/12 19:31:55 adam
395 * Pattern matching implemented when retrieving MARC records. More
396 * diagnostic functions.
398 * Revision 1.5 1995/03/10 18:00:15 adam
399 * Actual presentation in line-by-line format. RPN query support.
401 * Revision 1.4 1995/03/09 16:15:08 adam
402 * First presentRequest attempts. Hot-target list.
420 #if defined(__WIN32__)
421 # define WIN32_LEAN_AND_MEAN
422 # include <windows.h>
423 # undef WIN32_LEAN_AND_MEAN
426 * VC++ has an alternate entry point called DllMain, so we need to rename
430 # if defined(_MSC_VER)
431 # define EXPORT(a,b) __declspec(dllexport) a b
432 # define DllEntryPoint DllMain
434 # if defined(__BORLANDC__)
435 # define EXPORT(a,b) a _export b
437 # define EXPORT(a,b) a b
441 # define EXPORT(a,b) a b
444 static char *wrongArgs = "wrong # args: should be \"";
446 static int ir_tcl_error_exec (Tcl_Interp *interp, int argc, char **argv)
449 Tcl_AppendResult (interp, " while executing ", NULL);
450 for (i = 0; i<argc; i++)
451 Tcl_AppendResult (interp, (i ? " " : "\""), argv[i], NULL);
452 Tcl_AppendResult (interp, "\"", NULL);
457 static void ir_deleteDiags (IrTcl_Diagnostic **dst_list, int *dst_num);
459 static void ir_select_notify (ClientData clientData, int r, int w, int e);
461 void ir_select_add (int fd, void *obj)
463 ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0);
466 void ir_select_add_write (int fd, void *obj)
468 ir_tcl_select_set (ir_select_notify, fd, obj, 1, 1, 0);
471 void ir_select_remove (int fd, void *obj)
473 ir_tcl_select_set (NULL, fd, obj, 0, 0, 0);
476 void ir_select_remove_write (int fd, void *obj)
478 ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0);
481 static void delete_IR_record (IrTcl_RecordList *rl)
485 case Z_NamePlusRecord_databaseRecord:
486 switch (rl->u.dbrec.type)
489 ir_tcl_grs_del (&rl->u.dbrec.u.grs1);
494 xfree (rl->u.dbrec.buf);
495 rl->u.dbrec.buf = NULL;
497 case Z_NamePlusRecord_surrogateDiagnostic:
498 ir_deleteDiags (&rl->u.surrogateDiagnostics.list,
499 &rl->u.surrogateDiagnostics.num);
502 xfree (rl->elements);
505 static void purge_IR_records (IrTcl_SetObj *setobj)
507 IrTcl_RecordList *rl;
508 while ((rl = setobj->record_list))
510 setobj->record_list = rl->next;
511 delete_IR_record (rl);
516 static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj,
518 const char *elements)
520 IrTcl_RecordList *rl;
522 if (elements && !*elements)
524 for (rl = setobj->record_list; rl; rl = rl->next)
526 if (no == rl->no && (!rl->elements || !elements ||
527 !strcmp(elements, rl->elements)))
529 delete_IR_record (rl);
535 rl = ir_tcl_malloc (sizeof(*rl));
536 rl->next = setobj->record_list;
538 setobj->record_list = rl;
541 ir_tcl_strdup (NULL, &rl->elements, elements);
548 int ir_tcl_eval (Tcl_Interp *interp, const char *command)
550 char *tmp = ir_tcl_malloc (strlen(command)+1);
553 logf (LOG_DEBUG, "Invoking %.23s ...", command);
554 strcpy (tmp, command);
555 r = Tcl_Eval (interp, tmp);
558 const char *errorInfo = Tcl_GetVar (interp, "errorInfo", 0);
559 logf (LOG_WARN, "Tcl error in line %d: %s\n%s", interp->errorLine,
560 interp->result, errorInfo ? errorInfo : "<null>");
562 Tcl_FreeResult (interp);
568 * IrTcl_getRecordSyntaxStr: Return record syntax name of object id
570 static char *IrTcl_getRecordSyntaxStr (enum oid_value value)
573 struct oident ent, *entp;
575 ent.proto = PROTO_Z3950;
576 ent.oclass = CLASS_RECSYN;
579 o = oid_getoidbyent (&ent);
580 entp = oid_getentbyoid (o);
588 * IrTcl_getRecordSyntaxVal: Return record syntax value of string
590 static enum oid_value IrTcl_getRecordSyntaxVal (const char *name)
592 return oid_getvalbyname (name);
595 static IrTcl_RecordList *find_IR_record (IrTcl_SetObj *setobj, int no)
597 IrTcl_RecordList *rl;
599 for (rl = setobj->record_list; rl; rl = rl->next)
601 (!setobj->recordElements || !rl->elements ||
602 !strcmp (setobj->recordElements, rl->elements)))
607 static void delete_IR_records (IrTcl_SetObj *setobj)
609 IrTcl_RecordList *rl, *rl1;
611 for (rl = setobj->record_list; rl; rl = rl1)
613 delete_IR_record (rl);
617 setobj->record_list = NULL;
621 * ir_tcl_get_set_int: Set/get integer value
623 int ir_tcl_get_set_int (int *val, Tcl_Interp *interp, int argc, char **argv)
629 if (Tcl_GetInt (interp, argv[2], val)==TCL_ERROR)
632 sprintf (buf, "%d", *val);
633 Tcl_AppendResult (interp, buf, NULL);
639 * ir_tcl_method_error
641 int ir_tcl_method_error (Tcl_Interp *interp, int argc, char **argv,
644 IrTcl_Methods *tab_i = tab;
647 Tcl_AppendResult (interp, "bad method: \"", *argv, " ", argv[1],
648 "\"\nmethod should be of:", NULL);
649 for (tab_i = tab; tab_i->tab; tab_i++)
650 for (t = tab_i->tab; t->name; t++)
651 Tcl_AppendResult (interp, " ", t->name, NULL);
656 * ir_tcl_method: Search for method in table and invoke method handler
658 int ir_tcl_method (Tcl_Interp *interp, int argc, char **argv,
659 IrTcl_Methods *tab, int *ret)
661 IrTcl_Methods *tab_i = tab;
664 for (tab_i = tab; tab_i->tab; tab_i++)
665 for (t = tab_i->tab; t->name; t++)
668 if ((*t->method)(tab_i->obj, interp, argc, argv) == TCL_ERROR)
672 if (!strcmp (t->name, argv[1]))
674 *ret = (*t->method)(tab_i->obj, interp, argc, argv);
685 * ir_tcl_named_bits: get/set named bits
687 int ir_tcl_named_bits (struct ir_named_entry *tab, Odr_bitmask *ob,
688 Tcl_Interp *interp, int argc, char **argv)
690 struct ir_named_entry *ti;
695 for (no = 0; no < argc; no++)
698 for (ti = tab; ti->name; ti++)
699 if (!strcmp(argv[no], "@all") || !strcmp (argv[no], ti->name))
701 ODR_MASK_SET (ob, ti->pos);
706 Tcl_AppendResult (interp, "bad bit mask ", argv[no], NULL);
707 return ir_tcl_error_exec (interp, argc, argv);
712 for (ti = tab; ti->name; ti++)
713 if (ODR_MASK_GET (ob, ti->pos))
714 Tcl_AppendElement (interp, ti->name);
718 static void set_referenceId (ODR o, Z_ReferenceId **dst, const char *src)
724 *dst = odr_malloc (o, sizeof(**dst));
725 (*dst)->size = (*dst)->len = strlen(src);
726 (*dst)->buf = odr_malloc (o, (*dst)->len);
727 memcpy ((*dst)->buf, src, (*dst)->len);
731 static void get_referenceId (char **dst, Z_ReferenceId *src)
739 *dst = ir_tcl_malloc (src->len+1);
740 memcpy (*dst, src->buf, src->len);
741 (*dst)[src->len] = '\0';
744 /* ------------------------------------------------------- */
747 * do_init_request: init method on IR object
749 static int do_init_request (void *obj, Tcl_Interp *interp,
750 int argc, char **argv)
758 logf (LOG_DEBUG, "init %s", *argv);
761 Tcl_AppendResult (interp, "not connected", NULL);
762 return ir_tcl_error_exec (interp, argc, argv);
764 apdu = zget_APDU (p->odr_out, Z_APDU_initRequest);
765 req = apdu->u.initRequest;
767 set_referenceId (p->odr_out, &req->referenceId, p->set_inher.referenceId);
768 req->options = &p->options;
769 req->protocolVersion = &p->protocolVersion;
770 req->preferredMessageSize = &p->preferredMessageSize;
771 req->maximumRecordSize = &p->maximumRecordSize;
773 if (p->idAuthenticationGroupId)
775 Z_IdPass *pass = odr_malloc (p->odr_out, sizeof(*pass));
776 Z_IdAuthentication *auth = odr_malloc (p->odr_out, sizeof(*auth));
778 logf (LOG_DEBUG, "using pass authentication");
780 auth->which = Z_IdAuthentication_idPass;
781 auth->u.idPass = pass;
782 if (p->idAuthenticationGroupId && *p->idAuthenticationGroupId)
783 pass->groupId = p->idAuthenticationGroupId;
785 pass->groupId = NULL;
786 if (p->idAuthenticationUserId && *p->idAuthenticationUserId)
787 pass->userId = p->idAuthenticationUserId;
790 if (p->idAuthenticationPassword && *p->idAuthenticationPassword)
791 pass->password = p->idAuthenticationPassword;
793 pass->password = NULL;
794 req->idAuthentication = auth;
796 else if (!p->idAuthenticationOpen || !*p->idAuthenticationOpen)
797 req->idAuthentication = NULL;
800 Z_IdAuthentication *auth = odr_malloc (p->odr_out, sizeof(*auth));
802 logf (LOG_DEBUG, "using open authentication");
803 auth->which = Z_IdAuthentication_open;
804 auth->u.open = p->idAuthenticationOpen;
805 req->idAuthentication = auth;
807 req->implementationId = p->implementationId;
808 req->implementationName = p->implementationName;
809 req->implementationVersion = p->implementationVersion;
810 req->userInformationField = 0;
812 return ir_tcl_send_APDU (interp, p, apdu, "init", *argv);
816 * do_protocolVersion: Set protocol Version
818 static int do_protocolVersion (void *obj, Tcl_Interp *interp,
819 int argc, char **argv)
827 ODR_MASK_ZERO (&p->protocolVersion);
828 ODR_MASK_SET (&p->protocolVersion, 0);
829 ODR_MASK_SET (&p->protocolVersion, 1);
834 if (Tcl_GetInt (interp, argv[2], &version)==TCL_ERROR)
836 ODR_MASK_ZERO (&p->protocolVersion);
837 for (i = 0; i<version; i++)
838 ODR_MASK_SET (&p->protocolVersion, i);
840 for (i = 4; --i >= 0; )
841 if (ODR_MASK_GET (&p->protocolVersion, i))
843 sprintf (buf, "%d", i+1);
844 interp->result = buf;
849 * do_options: Set options
851 static int do_options (void *obj, Tcl_Interp *interp,
852 int argc, char **argv)
854 static struct ir_named_entry options_tab[] = {
858 { "resourceReport", 3 },
859 { "triggerResourceCtrl", 4},
860 { "resourceCtrl", 5},
864 { "extendedServices", 10},
865 { "level-1Segmentation", 11},
866 { "level-2Segmentation", 12},
867 { "concurrentOperations", 13},
868 { "namedResultSets", 14},
875 ODR_MASK_ZERO (&p->options);
876 ODR_MASK_SET (&p->options, 0);
877 ODR_MASK_SET (&p->options, 1);
878 ODR_MASK_SET (&p->options, 4);
879 ODR_MASK_SET (&p->options, 7);
880 ODR_MASK_SET (&p->options, 14);
883 return ir_tcl_named_bits (options_tab, &p->options, interp, argc-2, argv+2);
887 * do_apduInfo: Get APDU information
889 static int do_apduInfo (void *obj, Tcl_Interp *interp, int argc, char **argv)
897 sprintf (buf, "%d", p->apduLen);
898 Tcl_AppendElement (interp, buf);
899 sprintf (buf, "%d", p->apduOffset);
900 Tcl_AppendElement (interp, buf);
903 Tcl_AppendElement (interp, "");
906 apduf = fopen ("apdu.tmp", "w");
909 Tcl_AppendElement (interp, "");
912 odr_dumpBER (apduf, p->buf_in, p->apduLen);
914 if (!(apduf = fopen ("apdu.tmp", "r")))
915 Tcl_AppendElement (interp, "");
920 Tcl_AppendResult (interp, " {", NULL);
921 while ((c = getc (apduf)) != EOF)
925 Tcl_AppendResult (interp, buf, NULL);
928 Tcl_AppendResult (interp, "}", NULL);
935 * do_failInfo: Get fail information
937 static int do_failInfo (void *obj, Tcl_Interp *interp, int argc, char **argv)
947 sprintf (buf, "%d", p->failInfo);
953 case IR_TCL_FAIL_CONNECT:
954 cp = "connect failed";
956 case IR_TCL_FAIL_READ:
957 cp = "connection closed";
959 case IR_TCL_FAIL_WRITE:
960 cp = "connection closed";
962 case IR_TCL_FAIL_IN_APDU:
963 cp = "failed to decode incoming APDU";
965 case IR_TCL_FAIL_UNKNOWN_APDU:
971 Tcl_AppendElement (interp, buf);
972 Tcl_AppendElement (interp, cp);
977 * do_preferredMessageSize: Set/get preferred message size
979 static int do_preferredMessageSize (void *obj, Tcl_Interp *interp,
980 int argc, char **argv)
986 p->preferredMessageSize = 30000;
989 return ir_tcl_get_set_int (&p->preferredMessageSize, interp, argc, argv);
993 * do_maximumRecordSize: Set/get maximum record size
995 static int do_maximumRecordSize (void *obj, Tcl_Interp *interp,
996 int argc, char **argv)
1002 p->maximumRecordSize = 30000;
1005 return ir_tcl_get_set_int (&p->maximumRecordSize, interp, argc, argv);
1009 * do_initResult: Get init result
1011 static int do_initResult (void *obj, Tcl_Interp *interp,
1012 int argc, char **argv)
1018 return ir_tcl_get_set_int (&p->initResult, interp, argc, argv);
1023 * do_implementationName: Set/get Implementation Name.
1025 static int do_implementationName (void *obj, Tcl_Interp *interp,
1026 int argc, char **argv)
1031 return ir_tcl_strdup (interp, &p->implementationName,
1032 "Index Data/IrTcl on YAZ");
1033 else if (argc == -1)
1034 return ir_tcl_strdel (interp, &p->implementationName);
1037 xfree (p->implementationName);
1038 if (ir_tcl_strdup (interp, &p->implementationName, argv[2])
1042 Tcl_AppendResult (interp, p->implementationName, (char*) NULL);
1047 * do_implementationId: Get Implementation Id.
1049 static int do_implementationId (void *obj, Tcl_Interp *interp,
1050 int argc, char **argv)
1055 return ir_tcl_strdup (interp, &p->implementationId, "YAZ (id=81)");
1056 else if (argc == -1)
1057 return ir_tcl_strdel (interp, &p->implementationId);
1058 Tcl_AppendResult (interp, p->implementationId, (char*) NULL);
1063 * do_implementationVersion: get Implementation Version.
1065 static int do_implementationVersion (void *obj, Tcl_Interp *interp,
1066 int argc, char **argv)
1071 return ir_tcl_strdup (interp, &p->implementationVersion,
1073 #ifdef IR_TCL_VERSION
1074 " / Irtcl: " IR_TCL_VERSION
1077 else if (argc == -1)
1078 return ir_tcl_strdel (interp, &p->implementationVersion);
1079 Tcl_AppendResult (interp, p->implementationVersion, (char*) NULL);
1084 * do_targetImplementationName: Get Implementation Name of target.
1086 static int do_targetImplementationName (void *obj, Tcl_Interp *interp,
1087 int argc, char **argv)
1093 p->targetImplementationName = NULL;
1096 else if (argc == -1)
1097 return ir_tcl_strdel (interp, &p->targetImplementationName);
1098 Tcl_AppendResult (interp, p->targetImplementationName, (char*) NULL);
1103 * do_targetImplementationId: Get Implementation Id of target
1105 static int do_targetImplementationId (void *obj, Tcl_Interp *interp,
1106 int argc, char **argv)
1112 p->targetImplementationId = NULL;
1115 else if (argc == -1)
1116 return ir_tcl_strdel (interp, &p->targetImplementationId);
1117 Tcl_AppendResult (interp, p->targetImplementationId, (char*) NULL);
1122 * do_targetImplementationVersion: Get Implementation Version of target
1124 static int do_targetImplementationVersion (void *obj, Tcl_Interp *interp,
1125 int argc, char **argv)
1131 p->targetImplementationVersion = NULL;
1134 else if (argc == -1)
1135 return ir_tcl_strdel (interp, &p->targetImplementationVersion);
1136 Tcl_AppendResult (interp, p->targetImplementationVersion, (char*) NULL);
1141 * do_idAuthentication: Set/get id Authentication
1143 static int do_idAuthentication (void *obj, Tcl_Interp *interp,
1144 int argc, char **argv)
1148 if (argc >= 3 || argc == -1)
1150 xfree (p->idAuthenticationOpen);
1151 xfree (p->idAuthenticationGroupId);
1152 xfree (p->idAuthenticationUserId);
1153 xfree (p->idAuthenticationPassword);
1155 if (argc >= 3 || argc <= 0)
1157 p->idAuthenticationOpen = NULL;
1158 p->idAuthenticationGroupId = NULL;
1159 p->idAuthenticationUserId = NULL;
1160 p->idAuthenticationPassword = NULL;
1169 ir_tcl_strdup (interp, &p->idAuthenticationOpen, argv[2])
1176 ir_tcl_strdup (interp, &p->idAuthenticationGroupId, argv[2])
1180 ir_tcl_strdup (interp, &p->idAuthenticationUserId, argv[3])
1184 ir_tcl_strdup (interp, &p->idAuthenticationPassword, argv[4])
1189 if (p->idAuthenticationOpen)
1190 Tcl_AppendElement (interp, p->idAuthenticationOpen);
1191 else if (p->idAuthenticationGroupId)
1193 Tcl_AppendElement (interp, p->idAuthenticationGroupId);
1194 Tcl_AppendElement (interp, p->idAuthenticationUserId);
1195 Tcl_AppendElement (interp, p->idAuthenticationPassword);
1201 * do_connect: connect method on IR object
1203 static int do_connect (void *obj, Tcl_Interp *interp,
1204 int argc, char **argv)
1214 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
1215 " ?hostname?\"", NULL);
1220 Tcl_AppendResult (interp, p->hostname, NULL);
1224 logf (LOG_DEBUG, "connect %s %s", *argv, argv[2]);
1227 Tcl_AppendResult (interp, "already connected", NULL);
1228 return ir_tcl_error_exec (interp, argc, argv);
1230 if (!strcmp (p->comstackType, "tcpip"))
1232 p->cs_link = cs_create (tcpip_type, CS_BLOCK, p->protocol_type);
1233 logf (LOG_DEBUG, "tcp/ip connect %s", argv[2]);
1235 else if (!strcmp (p->comstackType, "mosi"))
1238 p->cs_link = cs_create (mosi_type, CS_BLOCK, p->protocol_type);
1239 logf (LOG_DEBUG, "mosi connect %s", argv[2]);
1241 Tcl_AppendResult (interp, "mosi not supported", NULL);
1242 return ir_tcl_error_exec (interp, argc, argv);
1247 Tcl_AppendResult (interp, "bad comstack type ",
1248 p->comstackType, NULL);
1249 return ir_tcl_error_exec (interp, argc, argv);
1251 if (ir_tcl_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR)
1253 p->eventType = "connect";
1254 addr = cs_straddr (p->cs_link, argv[2]);
1257 ir_tcl_disconnect (p);
1258 Tcl_AppendResult (interp, "cs_straddr fail", NULL);
1259 return ir_tcl_error_exec (interp, argc, argv);
1261 if ((r=cs_connect (p->cs_link, addr)) < 0)
1263 ir_tcl_disconnect (p);
1264 Tcl_AppendResult (interp, "connect fail", NULL);
1265 return ir_tcl_error_exec (interp, argc, argv);
1267 ir_select_add (cs_fileno (p->cs_link), p);
1270 logf (LOG_DEBUG, "connect pending fd=%d", cs_fileno(p->cs_link));
1271 ir_select_add_write (cs_fileno (p->cs_link), p);
1272 p->state = IR_TCL_R_Connecting;
1276 logf (LOG_DEBUG, "connect ok fd=%d", cs_fileno(p->cs_link));
1277 p->state = IR_TCL_R_Idle;
1279 ir_tcl_eval (p->interp, p->callback);
1286 * ir_tcl_disconnect: close connection
1288 void ir_tcl_disconnect (IrTcl_Obj *p)
1292 logf(LOG_DEBUG, "Closing connection to %s", p->hostname);
1293 xfree (p->hostname);
1295 assert (p->cs_link);
1296 ir_select_remove (cs_fileno (p->cs_link), p);
1298 odr_reset (p->odr_in);
1300 #if TCL_MAJOR_VERSION == 8
1301 cs_fileno(p->cs_link) = -1;
1303 cs_close (p->cs_link);
1306 ODR_MASK_ZERO (&p->options);
1307 ODR_MASK_SET (&p->options, 0);
1308 ODR_MASK_SET (&p->options, 1);
1309 ODR_MASK_SET (&p->options, 4);
1310 ODR_MASK_SET (&p->options, 7);
1311 ODR_MASK_SET (&p->options, 14);
1313 ODR_MASK_ZERO (&p->protocolVersion);
1314 ODR_MASK_SET (&p->protocolVersion, 0);
1315 ODR_MASK_SET (&p->protocolVersion, 1);
1318 assert (!p->cs_link);
1322 * do_disconnect: disconnect method on IR object
1324 static int do_disconnect (void *obj, Tcl_Interp *interp,
1325 int argc, char **argv)
1331 p->state = IR_TCL_R_Idle;
1332 p->eventType = NULL;
1337 ir_tcl_disconnect (p);
1342 * do_comstack: Set/get comstack method on IR object
1344 static int do_comstack (void *o, Tcl_Interp *interp,
1345 int argc, char **argv)
1350 return ir_tcl_strdup (interp, &obj->comstackType, "tcpip");
1351 else if (argc == -1)
1352 return ir_tcl_strdel (interp, &obj->comstackType);
1355 xfree (obj->comstackType);
1356 if (ir_tcl_strdup (interp, &obj->comstackType, argv[2]) == TCL_ERROR)
1359 Tcl_AppendElement (interp, obj->comstackType);
1364 * do_logLevel: Set log level
1366 static int do_logLevel (void *o, Tcl_Interp *interp,
1367 int argc, char **argv)
1372 yaz_log_init (yaz_log_mask_str (argv[2]), "", NULL);
1374 yaz_log_init (yaz_log_mask_str (argv[2]), argv[3], NULL);
1376 yaz_log_init (yaz_log_mask_str (argv[2]), argv[3], argv[4]);
1382 * do_eventType: Return type of last event
1384 static int do_eventType (void *obj, Tcl_Interp *interp,
1385 int argc, char **argv)
1391 p->eventType = NULL;
1394 Tcl_AppendElement (interp, p->eventType ? p->eventType : "");
1400 * do_callback: add callback
1402 static int do_callback (void *obj, Tcl_Interp *interp,
1403 int argc, char **argv)
1412 else if (argc == -1)
1413 return ir_tcl_strdel (interp, &p->callback);
1416 xfree (p->callback);
1419 if (ir_tcl_strdup (interp, &p->callback, argv[2]) == TCL_ERROR)
1429 * do_failback: add error handle callback
1431 static int do_failback (void *obj, Tcl_Interp *interp,
1432 int argc, char **argv)
1441 else if (argc == -1)
1442 return ir_tcl_strdel (interp, &p->failback);
1445 xfree (p->failback);
1448 if (ir_tcl_strdup (interp, &p->failback, argv[2]) == TCL_ERROR)
1458 * do_initResponse: add init response handler
1460 static int do_initResponse (void *obj, Tcl_Interp *interp,
1461 int argc, char **argv)
1467 p->initResponse = NULL;
1470 else if (argc == -1)
1471 return ir_tcl_strdel (interp, &p->initResponse);
1474 xfree (p->initResponse);
1477 if (ir_tcl_strdup (interp, &p->initResponse, argv[2]) == TCL_ERROR)
1481 p->initResponse = NULL;
1486 * do_protocol: Set/get protocol method on IR object
1488 static int do_protocol (void *o, Tcl_Interp *interp, int argc, char **argv)
1494 p->protocol_type = PROTO_Z3950;
1499 if (!strcmp (argv[2], "Z39"))
1500 p->protocol_type = PROTO_Z3950;
1501 else if (!strcmp (argv[2], "SR"))
1502 p->protocol_type = PROTO_SR;
1505 Tcl_AppendResult (interp, "bad protocol ", argv[2], NULL);
1506 return ir_tcl_error_exec (interp, argc, argv);
1510 switch (p->protocol_type)
1513 Tcl_AppendElement (interp, "Z39");
1516 Tcl_AppendElement (interp, "SR");
1523 * do_triggerResourceControl:
1525 static int do_triggerResourceControl (void *obj, Tcl_Interp *interp,
1526 int argc, char **argv)
1530 Z_TriggerResourceControlRequest *req;
1531 bool_t is_false = 0;
1537 Tcl_AppendResult (interp, "not connected", NULL);
1538 return ir_tcl_error_exec (interp, argc, argv);
1540 apdu = zget_APDU (p->odr_out, Z_APDU_triggerResourceControlRequest);
1541 req = apdu->u.triggerResourceControlRequest;
1542 *req->requestedAction = Z_TriggerResourceCtrl_cancel;
1543 req->resultSetWanted = &is_false;
1545 return ir_tcl_send_APDU (interp, p, apdu, "triggerResourceControl",
1550 * do_databaseNames: specify database names
1552 static int do_databaseNames (void *obj, Tcl_Interp *interp,
1553 int argc, char **argv)
1556 IrTcl_SetCObj *p = obj;
1560 for (i=0; i<p->num_databaseNames; i++)
1561 xfree (p->databaseNames[i]);
1562 xfree (p->databaseNames);
1566 p->num_databaseNames = 0;
1567 p->databaseNames = NULL;
1572 for (i=0; i<p->num_databaseNames; i++)
1573 Tcl_AppendElement (interp, p->databaseNames[i]);
1576 if (p->databaseNames)
1578 for (i=0; i<p->num_databaseNames; i++)
1579 xfree (p->databaseNames[i]);
1580 xfree (p->databaseNames);
1582 p->num_databaseNames = argc - 2;
1584 ir_tcl_malloc (sizeof(*p->databaseNames) * (1+p->num_databaseNames));
1585 for (i=0; i<p->num_databaseNames; i++)
1587 if (ir_tcl_strdup (interp, &p->databaseNames[i], argv[2+i])
1591 p->databaseNames[i] = NULL;
1596 * do_replaceIndicator: Set/get replace Set indicator
1598 static int do_replaceIndicator (void *obj, Tcl_Interp *interp,
1599 int argc, char **argv)
1601 IrTcl_SetCObj *p = obj;
1605 p->replaceIndicator = 1;
1608 return ir_tcl_get_set_int (&p->replaceIndicator, interp, argc, argv);
1612 * do_queryType: Set/Get query method
1614 static int do_queryType (void *obj, Tcl_Interp *interp,
1615 int argc, char **argv)
1617 IrTcl_SetCObj *p = obj;
1620 return ir_tcl_strdup (interp, &p->queryType, "rpn");
1621 else if (argc == -1)
1622 return ir_tcl_strdel (interp, &p->queryType);
1625 xfree (p->queryType);
1626 if (ir_tcl_strdup (interp, &p->queryType, argv[2]) == TCL_ERROR)
1629 Tcl_AppendResult (interp, p->queryType, NULL);
1634 * do_userInformationField: Get User information field
1636 static int do_userInformationField (void *obj, Tcl_Interp *interp,
1637 int argc, char **argv)
1643 p->userInformationField = NULL;
1646 else if (argc == -1)
1647 return ir_tcl_strdel (interp, &p->userInformationField);
1648 Tcl_AppendResult (interp, p->userInformationField, NULL);
1653 * do_smallSetUpperBound: Set/get small set upper bound
1655 static int do_smallSetUpperBound (void *o, Tcl_Interp *interp,
1656 int argc, char **argv)
1658 IrTcl_SetCObj *p = o;
1662 p->smallSetUpperBound = 0;
1665 return ir_tcl_get_set_int (&p->smallSetUpperBound, interp, argc, argv);
1669 * do_largeSetLowerBound: Set/get large set lower bound
1671 static int do_largeSetLowerBound (void *o, Tcl_Interp *interp,
1672 int argc, char **argv)
1674 IrTcl_SetCObj *p = o;
1678 p->largeSetLowerBound = 2;
1681 return ir_tcl_get_set_int (&p->largeSetLowerBound, interp, argc, argv);
1685 * do_mediumSetPresentNumber: Set/get large set lower bound
1687 static int do_mediumSetPresentNumber (void *o, Tcl_Interp *interp,
1688 int argc, char **argv)
1690 IrTcl_SetCObj *p = o;
1694 p->mediumSetPresentNumber = 0;
1697 return ir_tcl_get_set_int (&p->mediumSetPresentNumber, interp, argc, argv);
1701 * do_referenceId: Set/Get referenceId
1703 static int do_referenceId (void *obj, Tcl_Interp *interp,
1704 int argc, char **argv)
1706 IrTcl_SetCObj *p = obj;
1710 p->referenceId = NULL;
1713 else if (argc == -1)
1714 return ir_tcl_strdel (interp, &p->referenceId);
1717 xfree (p->referenceId);
1718 if (ir_tcl_strdup (interp, &p->referenceId, argv[2]) == TCL_ERROR)
1721 Tcl_AppendResult (interp, p->referenceId, NULL);
1726 * do_preferredRecordSyntax: Set/get preferred record syntax
1728 static int do_preferredRecordSyntax (void *obj, Tcl_Interp *interp,
1729 int argc, char **argv)
1731 IrTcl_SetCObj *p = obj;
1735 p->preferredRecordSyntax = NULL;
1738 else if (argc == -1)
1740 xfree (p->preferredRecordSyntax);
1741 p->preferredRecordSyntax = NULL;
1746 xfree (p->preferredRecordSyntax);
1747 p->preferredRecordSyntax = NULL;
1748 if (argv[2][0] && (p->preferredRecordSyntax =
1749 ir_tcl_malloc (sizeof(*p->preferredRecordSyntax))))
1750 *p->preferredRecordSyntax = IrTcl_getRecordSyntaxVal (argv[2]);
1755 (interp,!p->preferredRecordSyntax ? "" :
1756 IrTcl_getRecordSyntaxStr(*p->preferredRecordSyntax));
1763 * do_elementSetNames: Set/Get element Set Names
1765 static int do_elementSetNames (void *obj, Tcl_Interp *interp,
1766 int argc, char **argv)
1768 IrTcl_SetCObj *p = obj;
1772 p->elementSetNames = NULL;
1775 else if (argc == -1)
1776 return ir_tcl_strdel (interp, &p->elementSetNames);
1779 xfree (p->elementSetNames);
1780 if (ir_tcl_strdup (interp, &p->elementSetNames, argv[2]) == TCL_ERROR)
1783 Tcl_AppendResult (interp, p->elementSetNames, NULL);
1788 * do_smallSetElementSetNames: Set/Get small Set Element Set Names
1790 static int do_smallSetElementSetNames (void *obj, Tcl_Interp *interp,
1791 int argc, char **argv)
1793 IrTcl_SetCObj *p = obj;
1797 p->smallSetElementSetNames = NULL;
1800 else if (argc == -1)
1801 return ir_tcl_strdel (interp, &p->smallSetElementSetNames);
1804 xfree (p->smallSetElementSetNames);
1805 if (ir_tcl_strdup (interp, &p->smallSetElementSetNames,
1806 argv[2]) == TCL_ERROR)
1809 Tcl_AppendResult (interp, p->smallSetElementSetNames, NULL);
1814 * do_mediumSetElementSetNames: Set/Get medium Set Element Set Names
1816 static int do_mediumSetElementSetNames (void *obj, Tcl_Interp *interp,
1817 int argc, char **argv)
1819 IrTcl_SetCObj *p = obj;
1823 p->mediumSetElementSetNames = NULL;
1826 else if (argc == -1)
1827 return ir_tcl_strdel (interp, &p->mediumSetElementSetNames);
1830 xfree (p->mediumSetElementSetNames);
1831 if (ir_tcl_strdup (interp, &p->mediumSetElementSetNames,
1832 argv[2]) == TCL_ERROR)
1835 Tcl_AppendResult (interp, p->mediumSetElementSetNames, NULL);
1839 static IrTcl_Method ir_method_tab[] = {
1840 { "comstack", do_comstack, NULL },
1841 { "protocol", do_protocol, NULL },
1842 { "failback", do_failback, NULL },
1843 { "failInfo", do_failInfo, NULL },
1844 { "apduInfo", do_apduInfo, NULL },
1845 { "logLevel", do_logLevel, NULL },
1847 { "eventType", do_eventType, NULL },
1848 { "connect", do_connect, NULL },
1849 { "protocolVersion", do_protocolVersion, NULL },
1850 { "preferredMessageSize", do_preferredMessageSize, NULL },
1851 { "maximumRecordSize", do_maximumRecordSize, NULL },
1852 { "implementationName", do_implementationName, NULL },
1853 { "implementationId", do_implementationId, NULL },
1854 { "implementationVersion", do_implementationVersion, NULL },
1855 { "targetImplementationName", do_targetImplementationName, NULL },
1856 { "targetImplementationId", do_targetImplementationId, NULL },
1857 { "targetImplementationVersion", do_targetImplementationVersion, NULL},
1858 { "userInformationField", do_userInformationField, NULL},
1859 { "idAuthentication", do_idAuthentication, NULL},
1860 { "options", do_options, NULL},
1861 { "init", do_init_request, NULL},
1862 { "initResult", do_initResult, NULL},
1863 { "disconnect", do_disconnect, NULL},
1864 { "callback", do_callback, NULL},
1865 { "initResponse", do_initResponse, NULL},
1866 { "triggerResourceControl", do_triggerResourceControl, NULL},
1867 { "initResponse", do_initResponse, NULL},
1871 static IrTcl_Method ir_set_c_method_tab[] = {
1872 { "databaseNames", do_databaseNames, NULL},
1873 { "replaceIndicator", do_replaceIndicator, NULL},
1874 { "queryType", do_queryType, NULL},
1875 { "preferredRecordSyntax", do_preferredRecordSyntax, NULL},
1876 { "smallSetUpperBound", do_smallSetUpperBound, NULL},
1877 { "largeSetLowerBound", do_largeSetLowerBound, NULL},
1878 { "mediumSetPresentNumber", do_mediumSetPresentNumber, NULL},
1879 { "referenceId", do_referenceId, NULL},
1880 { "elementSetNames", do_elementSetNames, NULL},
1881 { "smallSetElementSetNames", do_smallSetElementSetNames, NULL},
1882 { "mediumSetElementSetNames", do_mediumSetElementSetNames, NULL},
1887 * ir_obj_method: IR Object methods
1889 static int ir_obj_method (ClientData clientData, Tcl_Interp *interp,
1890 int argc, char **argv)
1892 IrTcl_Methods tab[3];
1893 IrTcl_Obj *p = (IrTcl_Obj *) clientData;
1898 Tcl_AppendResult (interp, wrongArgs, *argv, "method args...\"", NULL);
1902 tab[0].tab = ir_method_tab;
1904 tab[1].tab = ir_set_c_method_tab;
1905 tab[1].obj = &p->set_inher;
1908 if (ir_tcl_method (interp, argc, argv, tab, &r) == TCL_ERROR)
1909 return ir_tcl_method_error (interp, argc, argv, tab);
1914 * ir_obj_delete: IR Object disposal
1916 static void ir_obj_delete (ClientData clientData)
1918 IrTcl_Obj *obj = (IrTcl_Obj *) clientData;
1919 IrTcl_Methods tab[3];
1922 if (obj->ref_count > 0)
1924 assert (obj->ref_count == 0);
1926 logf (LOG_DEBUG, "ir object delete");
1927 tab[0].tab = ir_method_tab;
1929 tab[1].tab = ir_set_c_method_tab;
1930 tab[1].obj = &obj->set_inher;
1933 ir_tcl_method (NULL, -1, NULL, tab, NULL);
1936 odr_destroy (obj->odr_in);
1937 odr_destroy (obj->odr_out);
1938 odr_destroy (obj->odr_pr);
1943 * ir_obj_init: IR Object initialization
1945 int ir_obj_init (ClientData clientData, Tcl_Interp *interp,
1946 int argc, char **argv, ClientData *subData,
1947 ClientData parentData)
1949 IrTcl_Methods tab[3];
1957 Tcl_AppendResult (interp, wrongArgs, *argv, " objName\"", NULL);
1960 obj = ir_tcl_malloc (sizeof(*obj));
1963 obj->bibset = ccl_qual_mk ();
1964 if ((inf = fopen ("default.bib", "r")))
1966 ccl_qual_file (obj->bibset, inf);
1971 logf (LOG_DEBUG, "ir object create %s", argv[1]);
1972 obj->odr_in = odr_createmem (ODR_DECODE);
1973 odr_choice_enable_bias (obj->odr_in, 0);
1974 obj->odr_out = odr_createmem (ODR_ENCODE);
1975 obj->odr_pr = odr_createmem (ODR_PRINT);
1976 obj->state = IR_TCL_R_Idle;
1977 obj->interp = interp;
1981 obj->request_queue = NULL;
1983 tab[0].tab = ir_method_tab;
1985 tab[1].tab = ir_set_c_method_tab;
1986 tab[1].obj = &obj->set_inher;
1989 if (ir_tcl_method (interp, 0, NULL, tab, NULL) == TCL_ERROR)
1991 Tcl_AppendResult (interp, "Failed to initialize ", argv[1], NULL);
1994 *subData = (ClientData) obj;
2000 * ir_obj_mk: IR Object creation
2002 static int ir_obj_mk (ClientData clientData, Tcl_Interp *interp,
2003 int argc, char **argv)
2006 int r = ir_obj_init (clientData, interp, argc, argv, &subData, 0);
2010 Tcl_CreateCommand (interp, argv[1], ir_obj_method,
2011 subData, ir_obj_delete);
2015 IrTcl_Class ir_obj_class = {
2023 /* ------------------------------------------------------- */
2025 * do_search: Do search request
2027 static int do_search (void *o, Tcl_Interp *interp, int argc, char **argv)
2029 Z_SearchRequest *req;
2033 IrTcl_SetObj *obj = o;
2044 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1], "query\"",
2048 logf (LOG_DEBUG, "search %s %s", *argv, argv[2]);
2049 if (!obj->set_inher.num_databaseNames)
2051 Tcl_AppendResult (interp, "no databaseNames", NULL);
2052 return ir_tcl_error_exec (interp, argc, argv);
2056 Tcl_AppendResult (interp, "not connected", NULL);
2057 return ir_tcl_error_exec (interp, argc, argv);
2059 apdu = zget_APDU (p->odr_out, Z_APDU_searchRequest);
2060 req = apdu->u.searchRequest;
2064 set_referenceId (p->odr_out, &req->referenceId,
2065 obj->set_inher.referenceId);
2067 req->smallSetUpperBound = &obj->set_inher.smallSetUpperBound;
2068 req->largeSetLowerBound = &obj->set_inher.largeSetLowerBound;
2069 req->mediumSetPresentNumber = &obj->set_inher.mediumSetPresentNumber;
2070 req->replaceIndicator = &obj->set_inher.replaceIndicator;
2071 req->resultSetName = obj->setName ? obj->setName : "default";
2072 logf (LOG_DEBUG, "Search, resultSetName %s", req->resultSetName);
2073 req->num_databaseNames = obj->set_inher.num_databaseNames;
2074 req->databaseNames = obj->set_inher.databaseNames;
2075 for (r=0; r < obj->set_inher.num_databaseNames; r++)
2076 logf (LOG_DEBUG, " Database %s", obj->set_inher.databaseNames[r]);
2077 if (obj->set_inher.preferredRecordSyntax)
2079 struct oident ident;
2081 ident.proto = p->protocol_type;
2082 ident.oclass = CLASS_RECSYN;
2083 ident.value = *obj->set_inher.preferredRecordSyntax;
2084 logf (LOG_DEBUG, "Preferred record syntax is %d", ident.value);
2085 req->preferredRecordSyntax = odr_oiddup (p->odr_out,
2086 oid_getoidbyent (&ident));
2089 req->preferredRecordSyntax = 0;
2091 if (obj->set_inher.smallSetElementSetNames &&
2092 *obj->set_inher.smallSetElementSetNames)
2094 Z_ElementSetNames *esn = odr_malloc (p->odr_out, sizeof(*esn));
2096 esn->which = Z_ElementSetNames_generic;
2097 esn->u.generic = obj->set_inher.smallSetElementSetNames;
2098 req->smallSetElementSetNames = esn;
2101 req->smallSetElementSetNames = NULL;
2103 if (obj->set_inher.mediumSetElementSetNames &&
2104 *obj->set_inher.mediumSetElementSetNames)
2106 Z_ElementSetNames *esn = odr_malloc (p->odr_out, sizeof(*esn));
2108 esn->which = Z_ElementSetNames_generic;
2109 esn->u.generic = obj->set_inher.mediumSetElementSetNames;
2110 req->mediumSetElementSetNames = esn;
2113 req->mediumSetElementSetNames = NULL;
2115 req->query = &query;
2117 logf (LOG_DEBUG, "queryType %s", obj->set_inher.queryType);
2118 if (!strcmp (obj->set_inher.queryType, "rpn"))
2120 Z_RPNQuery *RPNquery;
2122 RPNquery = p_query_rpn (p->odr_out, p->protocol_type, argv[2]);
2125 Tcl_AppendResult (interp, "query syntax error", NULL);
2126 return ir_tcl_error_exec (interp, argc, argv);
2128 query.which = Z_Query_type_1;
2129 query.u.type_1 = RPNquery;
2132 else if (!strcmp (obj->set_inher.queryType, "cclrpn"))
2136 struct ccl_rpn_node *rpn;
2137 Z_RPNQuery *RPNquery;
2140 bib1.proto = p->protocol_type;
2141 bib1.oclass = CLASS_ATTSET;
2142 bib1.value = VAL_BIB1;
2144 rpn = ccl_find_str(p->bibset, argv[2], &error, &pos);
2147 Tcl_AppendResult (interp, "ccl syntax error ", ccl_err_msg(error),
2149 return ir_tcl_error_exec (interp, argc, argv);
2152 ccl_pr_tree (rpn, stderr);
2153 fprintf (stderr, "\n");
2155 assert((RPNquery = ccl_rpn_query(rpn)));
2156 RPNquery->attributeSetId = oid_getoidbyent (&bib1);
2157 query.which = Z_Query_type_1;
2158 query.u.type_1 = RPNquery;
2161 else if (!strcmp (obj->set_inher.queryType, "ccl"))
2163 query.which = Z_Query_type_2;
2164 query.u.type_2 = &ccl_query;
2165 ccl_query.buf = (unsigned char *) argv[2];
2166 ccl_query.len = strlen (argv[2]);
2170 Tcl_AppendResult (interp, "invalid query method ",
2171 obj->set_inher.queryType, NULL);
2172 return ir_tcl_error_exec (interp, argc, argv);
2174 return ir_tcl_send_APDU (interp, p, apdu, "search", *argv);
2178 * do_searchResponse: add search response handler
2180 static int do_searchResponse (void *o, Tcl_Interp *interp,
2181 int argc, char **argv)
2183 IrTcl_SetObj *obj = o;
2187 obj->searchResponse = NULL;
2190 else if (argc == -1)
2191 return ir_tcl_strdel (interp, &obj->searchResponse);
2194 xfree (obj->searchResponse);
2197 if (ir_tcl_strdup (interp, &obj->searchResponse, argv[2])
2202 obj->searchResponse = NULL;
2208 * do_presentResponse: add present response handler
2210 static int do_presentResponse (void *o, Tcl_Interp *interp,
2211 int argc, char **argv)
2213 IrTcl_SetObj *obj = o;
2217 obj->presentResponse = NULL;
2220 else if (argc == -1)
2221 return ir_tcl_strdel (interp, &obj->presentResponse);
2224 xfree (obj->presentResponse);
2227 if (ir_tcl_strdup (interp, &obj->presentResponse, argv[2])
2232 obj->presentResponse = NULL;
2238 * do_sortResponse: add sort response handler
2240 static int do_sortResponse (void *o, Tcl_Interp *interp,
2241 int argc, char **argv)
2243 IrTcl_SetObj *obj = o;
2247 obj->sortResponse = NULL;
2250 else if (argc == -1)
2251 return ir_tcl_strdel (interp, &obj->sortResponse);
2254 xfree (obj->sortResponse);
2257 if (ir_tcl_strdup (interp, &obj->sortResponse, argv[2])
2262 obj->sortResponse = NULL;
2268 * do_resultCount: Get number of hits
2270 static int do_resultCount (void *o, Tcl_Interp *interp,
2271 int argc, char **argv)
2273 IrTcl_SetObj *obj = o;
2277 obj->resultCount = 0;
2280 return ir_tcl_get_set_int (&obj->resultCount, interp, argc, argv);
2284 * do_searchStatus: Get search status (after search response)
2286 static int do_searchStatus (void *o, Tcl_Interp *interp,
2287 int argc, char **argv)
2289 IrTcl_SetObj *obj = o;
2293 return ir_tcl_get_set_int (&obj->searchStatus, interp, argc, argv);
2297 * do_presentStatus: Get search status (after search/present response)
2299 static int do_presentStatus (void *o, Tcl_Interp *interp,
2300 int argc, char **argv)
2302 IrTcl_SetObj *obj = o;
2306 return ir_tcl_get_set_int (&obj->presentStatus, interp, argc, argv);
2310 * do_sortStatus: Get sort status (after sort response)
2312 static int do_sortStatus (void *o, Tcl_Interp *interp,
2313 int argc, char **argv)
2315 IrTcl_SetObj *obj = o;
2320 obj->sortStatus = Z_SortStatus_failure;
2323 switch (obj->sortStatus)
2325 case Z_SortStatus_success:
2326 res = "success"; break;
2327 case Z_SortStatus_partial_1:
2328 res = "partial"; break;
2329 case Z_SortStatus_failure:
2330 res = "failure"; break;
2332 res = "unknown"; break;
2334 Tcl_AppendElement (interp, res);
2339 * do_nextResultSetPosition: Get next result set position
2340 * (after search/present response)
2342 static int do_nextResultSetPosition (void *o, Tcl_Interp *interp,
2343 int argc, char **argv)
2345 IrTcl_SetObj *obj = o;
2349 obj->nextResultSetPosition = 0;
2352 return ir_tcl_get_set_int (&obj->nextResultSetPosition, interp,
2357 * do_setName: Set result Set name
2359 static int do_setName (void *o, Tcl_Interp *interp,
2360 int argc, char **argv)
2362 IrTcl_SetObj *obj = o;
2365 return ir_tcl_strdup (interp, &obj->setName, "Default");
2366 else if (argc == -1)
2367 return ir_tcl_strdel (interp, &obj->setName);
2370 xfree (obj->setName);
2371 if (ir_tcl_strdup (interp, &obj->setName, argv[2])
2375 Tcl_AppendElement (interp, obj->setName);
2380 * do_numberOfRecordsReturned: Get number of records returned
2382 static int do_numberOfRecordsReturned (void *o, Tcl_Interp *interp,
2383 int argc, char **argv)
2385 IrTcl_SetObj *obj = o;
2389 obj->numberOfRecordsReturned = 0;
2392 return ir_tcl_get_set_int (&obj->numberOfRecordsReturned, interp,
2397 * do_type: Return type (if any) at position.
2399 static int do_type (void *o, Tcl_Interp *interp, int argc, char **argv)
2401 IrTcl_SetObj *obj = o;
2403 IrTcl_RecordList *rl;
2407 obj->record_list = NULL;
2410 else if (argc == -1)
2412 delete_IR_records (obj);
2417 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2418 " position\"", NULL);
2421 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2423 rl = find_IR_record (obj, offset);
2426 logf (LOG_DEBUG, "%s %s %s: no record", argv[0], argv[1], argv[2]);
2431 case Z_NamePlusRecord_databaseRecord:
2432 interp->result = "DB";
2434 case Z_NamePlusRecord_surrogateDiagnostic:
2435 interp->result = "SD";
2443 * do_recordType: Return record type (if any) at position.
2445 static int do_recordType (void *o, Tcl_Interp *interp, int argc, char **argv)
2447 IrTcl_SetObj *obj = o;
2449 IrTcl_RecordList *rl;
2455 else if (argc == -1)
2461 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2462 " position\"", NULL);
2465 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2467 rl = find_IR_record (obj, offset);
2470 logf (LOG_DEBUG, "%s %s %s: no record", argv[0], argv[1], argv[2]);
2473 if (rl->which != Z_NamePlusRecord_databaseRecord)
2475 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2478 Tcl_AppendElement (interp, (char*)
2479 IrTcl_getRecordSyntaxStr (rl->u.dbrec.type));
2484 * set record elements (for record extraction)
2486 static int do_recordElements (void *o, Tcl_Interp *interp,
2487 int argc, char **argv)
2489 IrTcl_SetObj *obj = o;
2493 obj->recordElements = NULL;
2496 else if (argc == -1)
2497 return ir_tcl_strdel (NULL, &obj->recordElements);
2500 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2501 " ?position?\"", NULL);
2506 xfree (obj->recordElements);
2507 return ir_tcl_strdup (NULL, &obj->recordElements,
2508 (*argv[2] ? argv[2] : NULL));
2510 Tcl_AppendResult (interp, obj->recordElements, NULL);
2517 static int ir_diagResult (Tcl_Interp *interp, IrTcl_Diagnostic *list, int num)
2523 for (i = 0; i<num; i++)
2525 sprintf (buf, "%d", list[i].condition);
2526 Tcl_AppendElement (interp, buf);
2527 cp = diagbib1_str (list[i].condition);
2529 Tcl_AppendElement (interp, (char*) cp);
2531 Tcl_AppendElement (interp, "");
2532 if (list[i].addinfo)
2533 Tcl_AppendElement (interp, (char*) list[i].addinfo);
2535 Tcl_AppendElement (interp, "");
2541 * do_diag: Return diagnostic record info
2543 static int do_diag (void *o, Tcl_Interp *interp, int argc, char **argv)
2545 IrTcl_SetObj *obj = o;
2547 IrTcl_RecordList *rl;
2553 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2554 " position\"", NULL);
2557 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2559 rl = find_IR_record (obj, offset);
2562 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2565 if (rl->which != Z_NamePlusRecord_surrogateDiagnostic)
2567 Tcl_AppendResult (interp, "No Diagnostic record at #", argv[2], NULL);
2570 return ir_diagResult (interp, rl->u.surrogateDiagnostics.list,
2571 rl->u.surrogateDiagnostics.num);
2575 * do_getMarc: Get ISO2709 Record lines/fields
2577 static int do_getMarc (void *o, Tcl_Interp *interp, int argc, char **argv)
2579 IrTcl_SetObj *obj = o;
2581 IrTcl_RecordList *rl;
2587 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2588 " position line|field tag ind field\"", NULL);
2591 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2593 rl = find_IR_record (obj, offset);
2596 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2599 if (rl->which != Z_NamePlusRecord_databaseRecord)
2601 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2604 return ir_tcl_get_marc (interp, rl->u.dbrec.buf, argc, argv);
2608 * do_getSutrs: Get SUTRS Record
2610 static int do_getSutrs (void *o, Tcl_Interp *interp, int argc, char **argv)
2612 IrTcl_SetObj *obj = o;
2614 IrTcl_RecordList *rl;
2620 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2621 " position\"", NULL);
2624 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2626 rl = find_IR_record (obj, offset);
2629 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2632 if (rl->which != Z_NamePlusRecord_databaseRecord)
2634 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2637 if (!rl->u.dbrec.buf || rl->u.dbrec.type != VAL_SUTRS)
2639 Tcl_AppendElement (interp, rl->u.dbrec.buf);
2645 * do_getGrs: Get a GRS-1 Record
2647 static int do_getGrs (void *o, Tcl_Interp *interp, int argc, char **argv)
2649 IrTcl_SetObj *obj = o;
2651 IrTcl_RecordList *rl;
2657 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2658 " position ?(set,tag) (set,tag) ...?\"", NULL);
2661 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2663 rl = find_IR_record (obj, offset);
2666 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2669 if (rl->which != Z_NamePlusRecord_databaseRecord)
2671 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2674 if (rl->u.dbrec.type != VAL_GRS1)
2676 return ir_tcl_get_grs (interp, rl->u.dbrec.u.grs1, argc, argv);
2681 * do_getExplain: Get an Explain Record
2683 static int do_getExplain (void *o, Tcl_Interp *interp, int argc, char **argv)
2685 IrTcl_SetObj *obj = o;
2686 IrTcl_Obj *p = obj->parent;
2688 Z_ext_typeent *etype;
2690 IrTcl_RecordList *rl;
2696 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2697 " position ?mask? ...\"", NULL);
2700 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2702 rl = find_IR_record (obj, offset);
2705 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2708 if (rl->which != Z_NamePlusRecord_databaseRecord)
2710 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2713 if (!rl->u.dbrec.buf || rl->u.dbrec.type != VAL_EXPLAIN)
2716 if (!(etype = z_ext_getentbyref (VAL_EXPLAIN)))
2718 assert (rl->u.dbrec.buf);
2719 odr_setbuf (p->odr_in, rl->u.dbrec.buf, rl->u.dbrec.size, 0);
2720 if (!(*etype->fun)(p->odr_in, (char **) &rr, 0, 0))
2723 if (etype->what != Z_External_explainRecord)
2726 return ir_tcl_get_explain (interp, rr, argc, argv);
2730 * do_responseStatus: Return response status (present or search)
2732 static int do_responseStatus (void *o, Tcl_Interp *interp,
2733 int argc, char **argv)
2735 IrTcl_SetObj *obj = o;
2739 obj->recordFlag = 0;
2740 obj->nonSurrogateDiagnosticNum = 0;
2741 obj->nonSurrogateDiagnosticList = NULL;
2744 else if (argc == -1)
2746 ir_deleteDiags (&obj->nonSurrogateDiagnosticList,
2747 &obj->nonSurrogateDiagnosticNum);
2750 if (!obj->recordFlag)
2752 Tcl_AppendElement (interp, "OK");
2757 case Z_Records_DBOSD:
2758 Tcl_AppendElement (interp, "DBOSD");
2761 Tcl_AppendElement (interp, "NSD");
2762 return ir_diagResult (interp, obj->nonSurrogateDiagnosticList,
2763 obj->nonSurrogateDiagnosticNum);
2769 * do_present: Perform Present Request
2772 static int do_present (void *o, Tcl_Interp *interp, int argc, char **argv)
2774 IrTcl_SetObj *obj = o;
2777 Z_PresentRequest *req;
2785 if (Tcl_GetInt (interp, argv[2], &start) == TCL_ERROR)
2792 if (Tcl_GetInt (interp, argv[3], &number) == TCL_ERROR)
2797 logf (LOG_DEBUG, "present %s %d %d", *argv, start, number);
2801 Tcl_AppendResult (interp, "not connected", NULL);
2802 return ir_tcl_error_exec (interp, argc, argv);
2805 obj->number = number;
2807 apdu = zget_APDU (p->odr_out, Z_APDU_presentRequest);
2808 req = apdu->u.presentRequest;
2810 set_referenceId (p->odr_out, &req->referenceId,
2811 obj->set_inher.referenceId);
2813 req->resultSetId = obj->setName ? obj->setName : "Default";
2815 req->resultSetStartPoint = &start;
2816 req->numberOfRecordsRequested = &number;
2817 if (obj->set_inher.preferredRecordSyntax)
2819 struct oident ident;
2821 ident.proto = p->protocol_type;
2822 ident.oclass = CLASS_RECSYN;
2823 ident.value = *obj->set_inher.preferredRecordSyntax;
2824 logf (LOG_DEBUG, "Preferred record syntax is %d", ident.value);
2825 req->preferredRecordSyntax = odr_oiddup (p->odr_out,
2826 oid_getoidbyent (&ident));
2829 req->preferredRecordSyntax = 0;
2831 if (obj->set_inher.elementSetNames && *obj->set_inher.elementSetNames)
2833 Z_ElementSetNames *esn = odr_malloc (p->odr_out, sizeof(*esn));
2834 Z_RecordComposition *compo = odr_malloc (p->odr_out, sizeof(*compo));
2836 esn->which = Z_ElementSetNames_generic;
2837 esn->u.generic = obj->set_inher.elementSetNames;
2839 req->recordComposition = compo;
2840 compo->which = Z_RecordComp_simple;
2841 compo->u.simple = esn;
2844 req->recordComposition = NULL;
2845 return ir_tcl_send_APDU (interp, p, apdu, "present", *argv);
2848 #define IR_TCL_RECORD_ENCODING_ISO2709 1
2849 #define IR_TCL_RECORD_ENCODING_RAW 2
2855 } IrTcl_FileRecordHead;
2858 * do_loadFile: Load result set from file
2860 static int do_loadFile (void *o, Tcl_Interp *interp,
2861 int argc, char **argv)
2863 IrTcl_SetObj *setobj = o;
2875 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2876 " filename ?start? ?number?\"", NULL);
2880 start = atoi (argv[3]);
2882 number = atoi (argv[4]);
2885 inf = fopen (argv[2], "r");
2888 Tcl_AppendResult (interp, "Cannot open ", argv[2], NULL);
2889 return ir_tcl_error_exec (interp, argc, argv);
2891 while (offset < (start+number))
2893 IrTcl_FileRecordHead head;
2894 IrTcl_RecordList *rl;
2896 if (fread (&head, sizeof(head), 1, inf) < 1)
2898 rl = new_IR_record (setobj, offset,
2899 Z_NamePlusRecord_databaseRecord,
2900 (argc > 5) ? argv[5] : NULL);
2901 rl->u.dbrec.type = head.syntax;
2902 if (head.encoding == IR_TCL_RECORD_ENCODING_ISO2709)
2904 if (!(buf = ir_tcl_fread_marc (inf, &size)))
2906 rl->u.dbrec.buf = buf;
2907 rl->u.dbrec.size = size;
2908 if (size != head.size)
2911 Tcl_AppendResult (interp, "bad ISO2709 encoding", NULL);
2912 return ir_tcl_error_exec (interp, argc, argv);
2915 else if (head.encoding == IR_TCL_RECORD_ENCODING_RAW)
2917 rl->u.dbrec.size = head.size;
2918 rl->u.dbrec.buf = ir_tcl_malloc (head.size + 1);
2919 if (fread (rl->u.dbrec.buf, rl->u.dbrec.size, 1, inf) < 1)
2922 Tcl_AppendResult (interp, "bad raw encoding", NULL);
2923 return ir_tcl_error_exec (interp, argc, argv);
2925 rl->u.dbrec.buf[rl->u.dbrec.size] = '\0';
2929 rl->u.dbrec.buf = NULL;
2930 rl->u.dbrec.size = 0;
2932 Tcl_AppendResult (interp, "bad encoding", NULL);
2933 return ir_tcl_error_exec (interp, argc, argv);
2937 setobj->numberOfRecordsReturned = offset - start;
2943 * do_saveFile: Save result set on file
2945 static int do_saveFile (void *o, Tcl_Interp *interp,
2946 int argc, char **argv)
2948 IrTcl_SetObj *setobj = o;
2953 IrTcl_RecordList *rl;
2959 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2960 " filename ?start? ?number?\"", NULL);
2964 start = atoi (argv[3]);
2966 number = atoi (argv[4]);
2969 outf = fopen (argv[2], "w");
2972 Tcl_AppendResult (interp, "cannot open file", NULL);
2973 return ir_tcl_error_exec (interp, argc, argv);
2975 while (offset < (start+number) && (rl = find_IR_record (setobj, offset)))
2977 if (rl->which == Z_NamePlusRecord_databaseRecord &&
2978 rl->u.dbrec.buf && rl->u.dbrec.size)
2980 IrTcl_FileRecordHead head;
2982 head.encoding = IR_TCL_RECORD_ENCODING_RAW;
2983 head.syntax = rl->u.dbrec.type;
2984 head.size = rl->u.dbrec.size;
2985 if (fwrite (&head, sizeof(head), 1, outf) < 1)
2987 Tcl_AppendResult (interp, "cannot write", NULL);
2988 return ir_tcl_error_exec (interp, argc, argv);
2990 if (fwrite (rl->u.dbrec.buf, rl->u.dbrec.size, 1, outf) < 1)
2992 Tcl_AppendResult (interp, "cannot write", NULL);
2993 return ir_tcl_error_exec (interp, argc, argv);
3000 Tcl_AppendResult (interp, "cannot write ", NULL);
3001 return ir_tcl_error_exec (interp, argc, argv);
3007 /* ------------------------------------------------------- */
3009 * do_sort: Do sort request
3011 static int do_sort (void *o, Tcl_Interp *interp, int argc, char **argv)
3015 IrTcl_SetObj *obj = o;
3017 char sort_string[64], sort_flags[64];
3020 Z_SortKeySpecList *sksl;
3031 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1], "query\"",
3035 logf (LOG_DEBUG, "sort %s %s", *argv, argv[2]);
3038 Tcl_AppendResult (interp, "not connected", NULL);
3039 return ir_tcl_error_exec (interp, argc, argv);
3041 apdu = zget_APDU (p->odr_out, Z_APDU_sortRequest);
3042 sksl = (Z_SortKeySpecList *) odr_malloc (p->odr_out, sizeof(*sksl));
3043 req = apdu->u.sortRequest;
3045 set_referenceId (p->odr_out, &req->referenceId,
3046 obj->set_inher.referenceId);
3049 req->num_inputResultSetNames = 1;
3050 req->inputResultSetNames = (Z_InternationalString **)
3051 odr_malloc (p->odr_out, sizeof(*req->inputResultSetNames));
3052 req->inputResultSetNames[0] = obj->setName;
3054 req->inputResultSetNames =
3055 (Z_StringList *)odr_malloc (p->odr_out,
3056 sizeof(*req->inputResultSetNames));
3057 req->inputResultSetNames->num_strings = 1;
3058 req->inputResultSetNames->strings =
3059 (char **)odr_malloc (p->odr_out,
3060 sizeof(*req->inputResultSetNames->strings));
3061 req->inputResultSetNames->strings[0] = obj->setName;
3064 req->sortedResultSetName = (char *) obj->setName;
3067 req->sortSequence = sksl;
3068 sksl->num_specs = 0;
3069 sksl->specs = (Z_SortKeySpec **)
3070 odr_malloc (p->odr_out, sizeof(sksl->specs) * 20);
3072 bib1.proto = PROTO_Z3950;
3073 bib1.oclass = CLASS_ATTSET;
3074 bib1.value = VAL_BIB1;
3076 while ((sscanf (arg, "%63s %63s%n", sort_string, sort_flags, &off)) == 2
3080 char *sort_string_sep;
3081 Z_SortKeySpec *sks = (Z_SortKeySpec *)
3082 odr_malloc (p->odr_out, sizeof(*sks));
3083 Z_SortKey *sk = (Z_SortKey *)
3084 odr_malloc (p->odr_out, sizeof(*sk));
3087 sksl->specs[sksl->num_specs++] = sks;
3088 sks->sortElement = (Z_SortElement *)
3089 odr_malloc (p->odr_out, sizeof(*sks->sortElement));
3090 sks->sortElement->which = Z_SortElement_generic;
3091 sks->sortElement->u.generic = sk;
3093 if ((sort_string_sep = strchr (sort_string, '=')))
3095 Z_AttributeElement *el = (Z_AttributeElement *)
3096 odr_malloc (p->odr_out, sizeof(*el));
3097 sk->which = Z_SortKey_sortAttributes;
3098 sk->u.sortAttributes =
3099 (Z_SortAttributes *)
3100 odr_malloc (p->odr_out, sizeof(*sk->u.sortAttributes));
3101 sk->u.sortAttributes->id = oid_ent_to_oid(&bib1, oid);
3102 sk->u.sortAttributes->list =
3104 odr_malloc (p->odr_out, sizeof(*sk->u.sortAttributes->list));
3105 sk->u.sortAttributes->list->num_attributes = 1;
3106 sk->u.sortAttributes->list->attributes =
3107 (Z_AttributeElement **)odr_malloc (p->odr_out,
3108 sizeof(*sk->u.sortAttributes->list->attributes));
3109 sk->u.sortAttributes->list->attributes[0] = el;
3110 el->attributeSet = 0;
3111 el->attributeType = (int *)
3112 odr_malloc (p->odr_out, sizeof(*el->attributeType));
3113 *el->attributeType = atoi (sort_string);
3114 el->which = Z_AttributeValue_numeric;
3115 el->value.numeric = (int *)
3116 odr_malloc (p->odr_out, sizeof(*el->value.numeric));
3117 *el->value.numeric = atoi (sort_string_sep + 1);
3121 sk->which = Z_SortKey_sortField;
3122 sk->u.sortField = (char *)odr_malloc (p->odr_out, strlen(sort_string)+1);
3123 strcpy (sk->u.sortField, sort_string);
3125 sks->sortRelation = (int *)
3126 odr_malloc (p->odr_out, sizeof(*sks->sortRelation));
3127 *sks->sortRelation = Z_SortRelation_ascending;
3128 sks->caseSensitivity = (int *)
3129 odr_malloc (p->odr_out, sizeof(*sks->caseSensitivity));
3130 *sks->caseSensitivity = Z_SortCase_caseSensitive;
3133 sks->which = Z_SortKeySpec_null;
3134 sks->u.null = odr_nullval ();
3136 sks->missingValueAction = NULL;
3139 for (i = 0; sort_flags[i]; i++)
3141 switch (sort_flags[i])
3146 *sks->sortRelation = Z_SortRelation_descending;
3151 *sks->sortRelation = Z_SortRelation_ascending;
3155 *sks->caseSensitivity = Z_SortCase_caseInsensitive;
3159 *sks->caseSensitivity = Z_SortCase_caseSensitive;
3164 if (!sksl->num_specs)
3166 printf ("Missing sort specifications\n");
3169 return ir_tcl_send_APDU (interp, p, apdu, "sort", *argv);
3172 static IrTcl_Method ir_set_method_tab[] = {
3173 { "search", do_search, NULL},
3174 { "searchResponse", do_searchResponse, NULL},
3175 { "presentResponse", do_presentResponse, NULL},
3176 { "searchStatus", do_searchStatus, NULL},
3177 { "presentStatus", do_presentStatus, NULL},
3178 { "nextResultSetPosition", do_nextResultSetPosition, NULL},
3179 { "setName", do_setName, NULL},
3180 { "resultCount", do_resultCount, NULL},
3181 { "numberOfRecordsReturned", do_numberOfRecordsReturned, NULL},
3182 { "present", do_present, NULL},
3183 { "type", do_type, NULL},
3184 { "getMarc", do_getMarc, NULL},
3185 { "getSutrs", do_getSutrs, NULL},
3186 { "getGrs", do_getGrs, NULL},
3187 { "getExplain", do_getExplain, NULL},
3188 { "recordType", do_recordType, NULL},
3189 { "recordElements", do_recordElements, NULL},
3190 { "diag", do_diag, NULL},
3191 { "responseStatus", do_responseStatus, NULL},
3192 { "loadFile", do_loadFile, NULL},
3193 { "saveFile", do_saveFile, NULL},
3194 { "sort", do_sort, NULL },
3195 { "sortResponse", do_sortResponse, NULL},
3196 { "sortStatus", do_sortStatus, NULL},
3201 * ir_set_obj_method: IR Set Object methods
3203 static int ir_set_obj_method (ClientData clientData, Tcl_Interp *interp,
3204 int argc, char **argv)
3206 IrTcl_Methods tabs[3];
3207 IrTcl_SetObj *p = (IrTcl_SetObj *) clientData;
3212 Tcl_AppendResult (interp, wrongArgs, *argv, " method args...\"", NULL);
3215 tabs[0].tab = ir_set_method_tab;
3217 tabs[1].tab = ir_set_c_method_tab;
3218 tabs[1].obj = &p->set_inher;
3221 if (ir_tcl_method (interp, argc, argv, tabs, &r) == TCL_ERROR)
3222 return ir_tcl_method_error (interp, argc, argv, tabs);
3227 * ir_set_obj_delete: IR Set Object disposal
3229 static void ir_set_obj_delete (ClientData clientData)
3231 IrTcl_Methods tabs[3];
3232 IrTcl_SetObj *p = (IrTcl_SetObj *) clientData;
3234 logf (LOG_DEBUG, "ir set delete");
3236 tabs[0].tab = ir_set_method_tab;
3238 tabs[1].tab = ir_set_c_method_tab;
3239 tabs[1].obj = &p->set_inher;
3242 ir_tcl_method (NULL, -1, NULL, tabs, NULL);
3248 * ir_set_obj_init: IR Set Object initialization
3250 static int ir_set_obj_init (ClientData clientData, Tcl_Interp *interp,
3251 int argc, char **argv, ClientData *subData,
3252 ClientData parentData)
3254 IrTcl_Methods tabs[3];
3257 if (argc < 2 || argc > 3)
3259 Tcl_AppendResult (interp, wrongArgs, *argv,
3260 " objSetName ?objParent?\"", NULL);
3263 obj = ir_tcl_malloc (sizeof(*obj));
3264 logf (LOG_DEBUG, "ir set create %s", argv[1]);
3271 obj->parent = (IrTcl_Obj *) parentData;
3273 dst = &obj->set_inher;
3274 src = &obj->parent->set_inher;
3276 if ((dst->num_databaseNames = src->num_databaseNames))
3278 dst->databaseNames =
3279 ir_tcl_malloc (sizeof (*dst->databaseNames)
3280 * (1+dst->num_databaseNames));
3281 for (i = 0; i < dst->num_databaseNames; i++)
3282 if (ir_tcl_strdup (interp, &dst->databaseNames[i],
3283 src->databaseNames[i]) == TCL_ERROR)
3285 dst->databaseNames[i] = NULL;
3288 dst->databaseNames = NULL;
3289 if (ir_tcl_strdup (interp, &dst->queryType, src->queryType)
3293 if (ir_tcl_strdup (interp, &dst->referenceId, src->referenceId)
3297 if (ir_tcl_strdup (interp, &dst->elementSetNames, src->elementSetNames)
3301 if (ir_tcl_strdup (interp, &dst->smallSetElementSetNames,
3302 src->smallSetElementSetNames)
3306 if (ir_tcl_strdup (interp, &dst->mediumSetElementSetNames,
3307 src->mediumSetElementSetNames)
3311 if (src->preferredRecordSyntax &&
3312 (dst->preferredRecordSyntax
3313 = ir_tcl_malloc (sizeof(*dst->preferredRecordSyntax))))
3314 *dst->preferredRecordSyntax = *src->preferredRecordSyntax;
3316 dst->preferredRecordSyntax = NULL;
3317 dst->replaceIndicator = src->replaceIndicator;
3318 dst->smallSetUpperBound = src->smallSetUpperBound;
3319 dst->largeSetLowerBound = src->largeSetLowerBound;
3320 dst->mediumSetPresentNumber = src->mediumSetPresentNumber;
3325 tabs[0].tab = ir_set_method_tab;
3329 if (ir_tcl_method (interp, 0, NULL, tabs, NULL) == TCL_ERROR)
3332 *subData = (ClientData) obj;
3337 * ir_set_obj_mk: IR Set Object creation
3339 static int ir_set_obj_mk (ClientData clientData, Tcl_Interp *interp,
3340 int argc, char **argv)
3343 ClientData parentData = 0;
3348 Tcl_CmdInfo parent_info;
3349 if (!Tcl_GetCommandInfo (interp, argv[2], &parent_info))
3351 Tcl_AppendResult (interp, "no object parent", NULL);
3352 return ir_tcl_error_exec (interp, argc, argv);
3354 parentData = parent_info.clientData;
3356 r = ir_set_obj_init (clientData, interp, argc, argv, &subData, parentData);
3359 Tcl_CreateCommand (interp, argv[1], ir_set_obj_method,
3360 subData, ir_set_obj_delete);
3364 IrTcl_Class ir_set_obj_class = {
3371 /* ------------------------------------------------------- */
3374 * do_scan: Perform scan
3376 static int do_scan (void *o, Tcl_Interp *interp, int argc, char **argv)
3380 IrTcl_ScanObj *obj = o;
3381 IrTcl_Obj *p = obj->parent;
3384 struct ccl_rpn_node *rpn;
3392 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
3393 " scanQuery\"", NULL);
3396 logf (LOG_DEBUG, "scan %s %s", *argv, argv[2]);
3397 if (!p->set_inher.num_databaseNames)
3399 Tcl_AppendResult (interp, "no databaseNames", NULL);
3400 return ir_tcl_error_exec (interp, argc, argv);
3404 Tcl_AppendResult (interp, "not connected", NULL);
3405 return ir_tcl_error_exec (interp, argc, argv);
3408 apdu = zget_APDU (p->odr_out, Z_APDU_scanRequest);
3409 req = apdu->u.scanRequest;
3411 set_referenceId (p->odr_out, &req->referenceId, p->set_inher.referenceId);
3412 req->num_databaseNames = p->set_inher.num_databaseNames;
3413 req->databaseNames = p->set_inher.databaseNames;
3416 if (!(req->termListAndStartPoint =
3417 p_query_scan (p->odr_out, p->protocol_type,
3418 &req->attributeSet, argv[2])))
3420 Tcl_AppendResult (interp, "query syntax error", NULL);
3421 return ir_tcl_error_exec (interp, argc, argv);
3424 rpn = ccl_find_str(p->bibset, argv[2], &r, &pos);
3427 Tcl_AppendResult (interp, "ccl syntax error ", ccl_err_msg(r), NULL);
3428 return ir_tcl_error_exec (interp, argc, argv);
3430 bib1.proto = p->protocol_type;
3431 bib1.oclass = CLASS_ATTSET;
3432 bib1.value = VAL_BIB1;
3434 req->attributeSet = oid_getoidbyent (&bib1);
3435 if (!(req->termListAndStartPoint = ccl_scan_query (rpn)))
3438 req->stepSize = &obj->stepSize;
3439 req->numberOfTermsRequested = &obj->numberOfTermsRequested;
3440 req->preferredPositionInResponse = &obj->preferredPositionInResponse;
3441 logf (LOG_DEBUG, "stepSize=%d", *req->stepSize);
3442 logf (LOG_DEBUG, "numberOfTermsRequested=%d",
3443 *req->numberOfTermsRequested);
3444 logf (LOG_DEBUG, "preferredPositionInResponse=%d",
3445 *req->preferredPositionInResponse);
3447 return ir_tcl_send_APDU (interp, p, apdu, "scan", *argv);
3451 * do_scanResponse: add scan response handler
3453 static int do_scanResponse (void *o, Tcl_Interp *interp,
3454 int argc, char **argv)
3456 IrTcl_ScanObj *obj = o;
3460 obj->scanResponse = NULL;
3463 else if (argc == -1)
3464 return ir_tcl_strdel (interp, &obj->scanResponse);
3467 xfree (obj->scanResponse);
3470 if (ir_tcl_strdup (interp, &obj->scanResponse, argv[2])
3475 obj->scanResponse = NULL;
3481 * do_stepSize: Set/get replace Step Size
3483 static int do_stepSize (void *obj, Tcl_Interp *interp,
3484 int argc, char **argv)
3486 IrTcl_ScanObj *p = obj;
3492 return ir_tcl_get_set_int (&p->stepSize, interp, argc, argv);
3496 * do_numberOfTermsRequested: Set/get Number of Terms requested
3498 static int do_numberOfTermsRequested (void *obj, Tcl_Interp *interp,
3499 int argc, char **argv)
3501 IrTcl_ScanObj *p = obj;
3505 p->numberOfTermsRequested = 20;
3508 return ir_tcl_get_set_int (&p->numberOfTermsRequested, interp, argc, argv);
3513 * do_preferredPositionInResponse: Set/get preferred Position
3515 static int do_preferredPositionInResponse (void *obj, Tcl_Interp *interp,
3516 int argc, char **argv)
3518 IrTcl_ScanObj *p = obj;
3522 p->preferredPositionInResponse = 1;
3525 return ir_tcl_get_set_int (&p->preferredPositionInResponse, interp,
3530 * do_scanStatus: Get scan status
3532 static int do_scanStatus (void *obj, Tcl_Interp *interp,
3533 int argc, char **argv)
3535 IrTcl_ScanObj *p = obj;
3539 return ir_tcl_get_set_int (&p->scanStatus, interp, argc, argv);
3543 * do_numberOfEntriesReturned: Get number of Entries returned
3545 static int do_numberOfEntriesReturned (void *obj, Tcl_Interp *interp,
3546 int argc, char **argv)
3548 IrTcl_ScanObj *p = obj;
3552 return ir_tcl_get_set_int (&p->numberOfEntriesReturned, interp,
3557 * do_positionOfTerm: Get position of Term
3559 static int do_positionOfTerm (void *obj, Tcl_Interp *interp,
3560 int argc, char **argv)
3562 IrTcl_ScanObj *p = obj;
3566 return ir_tcl_get_set_int (&p->positionOfTerm, interp, argc, argv);
3570 * do_scanLine: get Scan Line (surrogate or normal) after response
3572 static int do_scanLine (void *obj, Tcl_Interp *interp, int argc, char **argv)
3574 IrTcl_ScanObj *p = obj;
3580 p->entries_flag = 0;
3582 p->nonSurrogateDiagnosticNum = 0;
3583 p->nonSurrogateDiagnosticList = 0;
3586 else if (argc == -1)
3588 p->entries_flag = 0;
3589 /* release entries */
3592 ir_deleteDiags (&p->nonSurrogateDiagnosticList,
3593 &p->nonSurrogateDiagnosticNum);
3598 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
3599 " position\"", NULL);
3602 if (Tcl_GetInt (interp, argv[2], &i) == TCL_ERROR)
3604 if (!p->entries_flag || !p->entries || i >= p->num_entries || i < 0)
3606 switch (p->entries[i].which)
3608 case Z_Entry_termInfo:
3609 Tcl_AppendElement (interp, "T");
3610 if (p->entries[i].u.term.buf)
3611 Tcl_AppendElement (interp, p->entries[i].u.term.buf);
3613 Tcl_AppendElement (interp, "");
3614 sprintf (numstr, "%d", p->entries[i].u.term.globalOccurrences);
3615 Tcl_AppendElement (interp, numstr);
3617 case Z_Entry_surrogateDiagnostic:
3618 Tcl_AppendElement (interp, "SD");
3619 return ir_diagResult (interp, p->entries[i].u.diag.list,
3620 p->entries[i].u.diag.num);
3626 static IrTcl_Method ir_scan_method_tab[] = {
3627 { "scan", do_scan, NULL},
3628 { "scanResponse", do_scanResponse, NULL},
3629 { "stepSize", do_stepSize, NULL},
3630 { "numberOfTermsRequested", do_numberOfTermsRequested, NULL},
3631 { "preferredPositionInResponse", do_preferredPositionInResponse, NULL},
3632 { "scanStatus", do_scanStatus, NULL},
3633 { "numberOfEntriesReturned", do_numberOfEntriesReturned, NULL},
3634 { "positionOfTerm", do_positionOfTerm, NULL},
3635 { "scanLine", do_scanLine, NULL},
3640 * ir_scan_obj_method: IR Scan Object methods
3642 static int ir_scan_obj_method (ClientData clientData, Tcl_Interp *interp,
3643 int argc, char **argv)
3645 IrTcl_Methods tabs[2];
3650 Tcl_AppendResult (interp, wrongArgs, *argv, " method args...\"", NULL);
3653 tabs[0].tab = ir_scan_method_tab;
3654 tabs[0].obj = clientData;
3657 if (ir_tcl_method (interp, argc, argv, tabs, &r) == TCL_ERROR)
3658 return ir_tcl_method_error (interp, argc, argv, tabs);
3663 * ir_scan_obj_delete: IR Scan Object disposal
3665 static void ir_scan_obj_delete (ClientData clientData)
3667 IrTcl_Methods tabs[2];
3668 IrTcl_ScanObj *obj = (IrTcl_ScanObj *) clientData;
3670 tabs[0].tab = ir_scan_method_tab;
3674 ir_tcl_method (NULL, -1, NULL, tabs, NULL);
3679 * ir_scan_obj_mk: IR Scan Object creation
3681 static int ir_scan_obj_mk (ClientData clientData, Tcl_Interp *interp,
3682 int argc, char **argv)
3684 Tcl_CmdInfo parent_info;
3686 IrTcl_Methods tabs[2];
3690 Tcl_AppendResult (interp, wrongArgs, *argv,
3691 "objScanName objParentName\"", NULL);
3694 logf (LOG_DEBUG, "ir scan create %s", argv[1]);
3695 if (!Tcl_GetCommandInfo (interp, argv[2], &parent_info))
3697 Tcl_AppendResult (interp, "no object parent", NULL);
3698 return ir_tcl_error_exec (interp, argc, argv);
3700 obj = ir_tcl_malloc (sizeof(*obj));
3701 obj->parent = (IrTcl_Obj *) parent_info.clientData;
3703 tabs[0].tab = ir_scan_method_tab;
3707 if (ir_tcl_method (interp, 0, NULL, tabs, NULL) == TCL_ERROR)
3709 Tcl_CreateCommand (interp, argv[1], ir_scan_obj_method,
3710 (ClientData) obj, ir_scan_obj_delete);
3714 /* ------------------------------------------------------- */
3717 * ir_log_init_proc: set yaz log level
3719 static int ir_log_init_proc (ClientData clientData, Tcl_Interp *interp,
3720 int argc, char **argv)
3722 if (argc <= 1 || argc > 4)
3724 Tcl_AppendResult (interp, wrongArgs, *argv,
3725 " ?level ?prefix ?filename\"", NULL);
3729 yaz_log_init (yaz_log_mask_str (argv[1]), "", NULL);
3731 yaz_log_init (yaz_log_mask_str (argv[1]), argv[2], NULL);
3733 yaz_log_init (yaz_log_mask_str (argv[1]), argv[2], argv[3]);
3738 * ir_log_proc: log yaz message
3740 static int ir_log_proc (ClientData clientData, Tcl_Interp *interp,
3741 int argc, char **argv)
3746 Tcl_AppendResult (interp, wrongArgs, *argv,
3747 " level string\"", NULL);
3750 mask = yaz_log_mask_str_x (argv[1], 0);
3751 logf (LOG_DEBUG, "%s", argv[2]);
3757 * ir_version: log ir version
3759 static int ir_version (ClientData clientData, Tcl_Interp *interp,
3760 int argc, char **argv)
3762 Tcl_AppendElement (interp, IR_TCL_VERSION);
3763 Tcl_AppendElement (interp, YAZ_VERSION);
3768 /* ------------------------------------------------------- */
3769 static void ir_initResponse (void *obj, Z_InitResponse *initrs)
3773 p->initResult = *initrs->result ? 1 : 0;
3774 if (!*initrs->result)
3775 logf (LOG_DEBUG, "Connection rejected by target");
3777 logf (LOG_DEBUG, "Connection accepted by target");
3779 get_referenceId (&p->set_inher.referenceId, initrs->referenceId);
3781 xfree (p->targetImplementationId);
3782 ir_tcl_strdup (p->interp, &p->targetImplementationId,
3783 initrs->implementationId);
3784 xfree (p->targetImplementationName);
3785 ir_tcl_strdup (p->interp, &p->targetImplementationName,
3786 initrs->implementationName);
3787 xfree (p->targetImplementationVersion);
3788 ir_tcl_strdup (p->interp, &p->targetImplementationVersion,
3789 initrs->implementationVersion);
3791 p->maximumRecordSize = *initrs->maximumRecordSize;
3792 p->preferredMessageSize = *initrs->preferredMessageSize;
3794 memcpy (&p->options, initrs->options, sizeof(initrs->options));
3795 memcpy (&p->protocolVersion, initrs->protocolVersion,
3796 sizeof(initrs->protocolVersion));
3797 xfree (p->userInformationField);
3798 p->userInformationField = NULL;
3799 if (initrs->userInformationField)
3803 if (initrs->userInformationField->which == ODR_EXTERNAL_octet &&
3804 (p->userInformationField =
3805 ir_tcl_malloc ((len =
3806 initrs->userInformationField->
3807 u.octet_aligned->len) +1)))
3809 memcpy (p->userInformationField,
3810 initrs->userInformationField->u.octet_aligned->buf,
3812 (p->userInformationField)[len] = '\0';
3817 static void ir_deleteDiags (IrTcl_Diagnostic **dst_list, int *dst_num)
3820 for (i = 0; i<*dst_num; i++)
3821 xfree (dst_list[i]->addinfo);
3827 static void ir_handleDiags (IrTcl_Diagnostic **dst_list, int *dst_num,
3828 Z_DiagRec **list, int num)
3831 char *addinfo = NULL;
3834 *dst_list = ir_tcl_malloc (sizeof(**dst_list) * num);
3835 for (i = 0; i<num; i++)
3838 switch (list[i]->which)
3840 case Z_DiagRec_defaultFormat:
3841 (*dst_list)[i].condition = *list[i]->u.defaultFormat->condition;
3843 switch (list[i]->u.defaultFormat->which)
3845 case Z_DefaultDiagFormat_v2Addinfo:
3846 addinfo = list[i]->u.defaultFormat->u.v2Addinfo;
3848 case Z_DefaultDiagFormat_v3Addinfo:
3849 addinfo = list[i]->u.defaultFormat->u.v3Addinfo;
3853 addinfo = list[i]->u.defaultFormat->addinfo;
3856 ((*dst_list)[i].addinfo = ir_tcl_malloc (strlen(addinfo)+1)))
3857 strcpy ((*dst_list)[i].addinfo, addinfo);
3858 cp = diagbib1_str ((*dst_list)[i].condition);
3859 logf (LOG_DEBUG, "Diag %d %s %s", (*dst_list)[i].condition,
3860 cp ? cp : "", addinfo ? addinfo : "");
3863 (*dst_list)[i].addinfo = NULL;
3864 (*dst_list)[i].condition = 0;
3869 static void ir_handleDBRecord (IrTcl_Obj *p, IrTcl_RecordList *rl,
3872 struct oident *ident;
3873 Z_ext_typeent *etype;
3875 logf (LOG_DEBUG, "handleDBRecord size=%d", oe->u.octet_aligned->len);
3876 rl->u.dbrec.size = oe->u.octet_aligned->len;
3877 rl->u.dbrec.buf = NULL;
3879 if ((ident = oid_getentbyoid (oe->direct_reference)))
3880 rl->u.dbrec.type = ident->value;
3882 rl->u.dbrec.type = VAL_USMARC;
3884 if (ident && (oe->which == Z_External_single ||
3885 oe->which == Z_External_octet)
3886 && (etype = z_ext_getentbyref (ident->value)))
3890 odr_setbuf (p->odr_in, (char*) oe->u.octet_aligned->buf,
3891 oe->u.octet_aligned->len, 0);
3892 if (!(*etype->fun)(p->odr_in, (char **) &rr, 0, 0))
3894 rl->u.dbrec.type = VAL_NONE;
3897 switch (etype->what)
3899 case Z_External_sutrs:
3900 logf (LOG_DEBUG, "Z_External_sutrs");
3902 if ((rl->u.dbrec.buf = ir_tcl_malloc (oe->u.sutrs->len+1)))
3904 memcpy (rl->u.dbrec.buf, oe->u.sutrs->buf,
3906 rl->u.dbrec.buf[oe->u.sutrs->len] = '\0';
3908 rl->u.dbrec.size = oe->u.sutrs->len;
3910 case Z_External_grs1:
3911 logf (LOG_DEBUG, "Z_External_grs1");
3913 ir_tcl_grs_mk (oe->u.grs1, &rl->u.dbrec.u.grs1);
3915 case Z_External_explainRecord:
3916 logf (LOG_DEBUG, "Z_External_explainRecord");
3917 if ((rl->u.dbrec.buf = ir_tcl_malloc (rl->u.dbrec.size)))
3919 memcpy (rl->u.dbrec.buf, oe->u.octet_aligned->buf,
3927 if (oe->which == Z_External_octet && rl->u.dbrec.size > 0)
3929 char *buf = (char*) oe->u.octet_aligned->buf;
3930 if ((rl->u.dbrec.buf = ir_tcl_malloc (rl->u.dbrec.size)))
3931 memcpy (rl->u.dbrec.buf, buf, rl->u.dbrec.size);
3933 else if (rl->u.dbrec.type == VAL_SUTRS &&
3934 oe->which == Z_External_sutrs)
3936 if ((rl->u.dbrec.buf = ir_tcl_malloc (oe->u.sutrs->len+1)))
3938 memcpy (rl->u.dbrec.buf, oe->u.sutrs->buf,
3940 rl->u.dbrec.buf[oe->u.sutrs->len] = '\0';
3942 rl->u.dbrec.size = oe->u.sutrs->len;
3944 else if (rl->u.dbrec.type == VAL_GRS1 &&
3945 oe->which == Z_External_grs1)
3947 ir_tcl_grs_mk (oe->u.grs1, &rl->u.dbrec.u.grs1);
3952 static void ir_handleZRecords (void *o, Z_Records *zrs, IrTcl_SetObj *setobj,
3953 const char *elements)
3958 IrTcl_RecordList *rl;
3960 setobj->which = zrs->which;
3961 setobj->recordFlag = 1;
3963 ir_deleteDiags (&setobj->nonSurrogateDiagnosticList,
3964 &setobj->nonSurrogateDiagnosticNum);
3965 if (zrs->which == Z_Records_DBOSD)
3967 int num_rec = zrs->u.databaseOrSurDiagnostics->num_records;
3969 if (num_rec != setobj->numberOfRecordsReturned)
3971 logf (LOG_WARN, "numberOfRecordsReturned=%d but num records=%d",
3972 setobj->numberOfRecordsReturned, num_rec);
3973 setobj->numberOfRecordsReturned = num_rec;
3976 for (offset = 0; offset < num_rec; offset++)
3978 Z_NamePlusRecord *znpr = zrs->u.databaseOrSurDiagnostics->
3981 rl = new_IR_record (setobj, setobj->start + offset, znpr->which,
3983 if (rl->which == Z_NamePlusRecord_surrogateDiagnostic)
3984 ir_handleDiags (&rl->u.surrogateDiagnostics.list,
3985 &rl->u.surrogateDiagnostics.num,
3986 &znpr->u.surrogateDiagnostic,
3989 ir_handleDBRecord (p, rl,
3990 (Z_External*) (znpr->u.databaseRecord));
3993 else if (zrs->which == Z_Records_multipleNSD)
3995 logf (LOG_DEBUG, "multipleNonSurrogateDiagnostic %d",
3996 zrs->u.multipleNonSurDiagnostics->num_diagRecs);
3997 setobj->numberOfRecordsReturned = 0;
3998 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
3999 &setobj->nonSurrogateDiagnosticNum,
4000 zrs->u.multipleNonSurDiagnostics->diagRecs,
4001 zrs->u.multipleNonSurDiagnostics->num_diagRecs);
4006 Z_DiagRec dr, *dr_p = &dr;
4007 dr.which = Z_DiagRec_defaultFormat;
4008 dr.u.defaultFormat = zrs->u.nonSurrogateDiagnostic;
4010 Z_DiagRec *dr_p = zrs->u.nonSurrogateDiagnostic;
4012 logf (LOG_DEBUG, "NonSurrogateDiagnostic");
4014 setobj->numberOfRecordsReturned = 0;
4015 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
4016 &setobj->nonSurrogateDiagnosticNum,
4021 static void ir_searchResponse (void *o, Z_SearchResponse *searchrs,
4022 IrTcl_SetObj *setobj)
4024 Z_Records *zrs = searchrs->records;
4026 logf (LOG_DEBUG, "Received search response");
4029 logf (LOG_DEBUG, "Search response, no object!");
4032 setobj->searchStatus = *searchrs->searchStatus;
4033 get_referenceId (&setobj->set_inher.referenceId, searchrs->referenceId);
4034 setobj->resultCount = *searchrs->resultCount;
4035 if (searchrs->presentStatus)
4036 setobj->presentStatus = *searchrs->presentStatus;
4038 setobj->presentStatus = Z_RES_NONE;
4039 if (searchrs->nextResultSetPosition)
4040 setobj->nextResultSetPosition = *searchrs->nextResultSetPosition;
4042 logf (LOG_DEBUG, "status %d hits %d",
4043 setobj->searchStatus, setobj->resultCount);
4047 if (setobj->resultCount <= setobj->set_inher.smallSetUpperBound)
4048 es = setobj->set_inher.smallSetElementSetNames;
4050 es = setobj->set_inher.mediumSetElementSetNames;
4051 setobj->numberOfRecordsReturned = *searchrs->numberOfRecordsReturned;
4052 ir_handleZRecords (o, zrs, setobj, es);
4056 setobj->numberOfRecordsReturned = 0;
4057 setobj->recordFlag = 0;
4062 static void ir_presentResponse (void *o, Z_PresentResponse *presrs,
4063 IrTcl_SetObj *setobj)
4065 Z_Records *zrs = presrs->records;
4067 logf (LOG_DEBUG, "Received present response");
4070 logf (LOG_DEBUG, "Present response, no object!");
4073 setobj->presentStatus = *presrs->presentStatus;
4074 get_referenceId (&setobj->set_inher.referenceId, presrs->referenceId);
4075 setobj->nextResultSetPosition = *presrs->nextResultSetPosition;
4078 setobj->numberOfRecordsReturned = *presrs->numberOfRecordsReturned;
4079 ir_handleZRecords (o, zrs, setobj, setobj->set_inher.elementSetNames);
4083 setobj->numberOfRecordsReturned = 0;
4084 setobj->recordFlag = 0;
4085 logf (LOG_DEBUG, "No records!");
4089 static void ir_scanResponse (void *o, Z_ScanResponse *scanrs,
4090 IrTcl_ScanObj *scanobj)
4094 logf (LOG_DEBUG, "Received scanResponse");
4096 get_referenceId (&p->set_inher.referenceId, scanrs->referenceId);
4097 scanobj->scanStatus = *scanrs->scanStatus;
4098 logf (LOG_DEBUG, "scanStatus=%d", scanobj->scanStatus);
4100 if (scanrs->stepSize)
4101 scanobj->stepSize = *scanrs->stepSize;
4102 logf (LOG_DEBUG, "stepSize=%d", scanobj->stepSize);
4104 scanobj->numberOfEntriesReturned = *scanrs->numberOfEntriesReturned;
4105 logf (LOG_DEBUG, "numberOfEntriesReturned=%d",
4106 scanobj->numberOfEntriesReturned);
4108 if (scanrs->positionOfTerm)
4109 scanobj->positionOfTerm = *scanrs->positionOfTerm;
4111 scanobj->positionOfTerm = -1;
4112 logf (LOG_DEBUG, "positionOfTerm=%d", scanobj->positionOfTerm);
4114 xfree (scanobj->entries);
4115 scanobj->entries = NULL;
4116 scanobj->num_entries = 0;
4117 scanobj->entries_flag = 0;
4119 ir_deleteDiags (&scanobj->nonSurrogateDiagnosticList,
4120 &scanobj->nonSurrogateDiagnosticNum);
4121 if (scanrs->entries)
4126 scanobj->entries_flag = 1;
4127 if (scanrs->entries)
4129 scanobj->num_entries = scanrs->entries->num_entries;
4130 scanobj->entries = ir_tcl_malloc (scanobj->num_entries *
4131 sizeof(*scanobj->entries));
4132 ze = scanrs->entries->entries;
4134 for (i=0; i<scanobj->num_entries; i++, ze++)
4136 scanobj->entries[i].which = (*ze)->which;
4137 switch ((*ze)->which)
4139 case Z_Entry_termInfo:
4140 if ((*ze)->u.termInfo->term->which == Z_Term_general)
4142 int l = (*ze)->u.termInfo->term->u.general->len;
4143 scanobj->entries[i].u.term.buf = ir_tcl_malloc (1+l);
4144 memcpy (scanobj->entries[i].u.term.buf,
4145 (*ze)->u.termInfo->term->u.general->buf,
4147 scanobj->entries[i].u.term.buf[l] = '\0';
4150 scanobj->entries[i].u.term.buf = NULL;
4151 if ((*ze)->u.termInfo->globalOccurrences)
4152 scanobj->entries[i].u.term.globalOccurrences =
4153 *(*ze)->u.termInfo->globalOccurrences;
4155 scanobj->entries[i].u.term.globalOccurrences = 0;
4157 case Z_Entry_surrogateDiagnostic:
4158 ir_handleDiags (&scanobj->entries[i].u.diag.list,
4159 &scanobj->entries[i].u.diag.num,
4160 &(*ze)->u.surrogateDiagnostic,
4165 if (scanrs->entries->nonsurrogateDiagnostics)
4166 ir_handleDiags (&scanobj->nonSurrogateDiagnosticList,
4167 &scanobj->nonSurrogateDiagnosticNum,
4168 scanrs->entries->nonsurrogateDiagnostics,
4169 scanrs->entries->num_nonsurrogateDiagnostics);
4174 static void ir_sortResponse (void *o, Z_SortResponse *sortrs,
4175 IrTcl_SetObj *setobj)
4179 logf (LOG_DEBUG, "Received sortResponse");
4184 purge_IR_records (setobj);
4186 get_referenceId (&p->set_inher.referenceId, sortrs->referenceId);
4188 setobj->sortStatus = *sortrs->sortStatus;
4190 ir_deleteDiags (&setobj->nonSurrogateDiagnosticList,
4191 &setobj->nonSurrogateDiagnosticNum);
4193 if (sortrs->diagnostics)
4194 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
4195 &setobj->nonSurrogateDiagnosticNum,
4196 sortrs->diagnostics,
4197 sortrs->num_diagnostics);
4199 if (sortrs->diagnostics)
4200 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
4201 &setobj->nonSurrogateDiagnosticNum,
4202 sortrs->diagnostics->diagRecs,
4203 sortrs->diagnostics->num_diagRecs);
4208 * ir_select_read: handle incoming packages
4210 static void ir_select_read (ClientData clientData)
4212 IrTcl_Obj *p = (IrTcl_Obj *) clientData;
4217 Tcl_CmdInfo cmd_info;
4218 const char *apdu_call;
4220 logf(LOG_DEBUG, "Read handler fd=%d", cs_fileno(p->cs_link));
4221 if (p->state == IR_TCL_R_Connecting)
4223 logf(LOG_DEBUG, "read: connect");
4224 r = cs_rcvconnect (p->cs_link);
4227 logf (LOG_WARN, "cs_rcvconnect returned 1");
4230 p->state = IR_TCL_R_Idle;
4232 ir_select_remove_write (cs_fileno (p->cs_link), p);
4235 logf (LOG_DEBUG, "cs_rcvconnect error");
4236 ir_tcl_disconnect (p);
4239 p->failInfo = IR_TCL_FAIL_CONNECT;
4240 ir_tcl_eval (p->interp, p->failback);
4242 ir_obj_delete ((ClientData) p);
4246 ir_tcl_eval (p->interp, p->callback);
4247 if (p->ref_count == 2 && p->cs_link && p->request_queue
4248 && p->state == IR_TCL_R_Idle)
4249 ir_tcl_send_q (p, p->request_queue, "x");
4250 ir_obj_delete ((ClientData) p);
4255 p->state = IR_TCL_R_Reading;
4257 /* read incoming APDU */
4258 if ((r=cs_get (p->cs_link, &p->buf_in, &p->len_in)) == 1)
4260 logf(LOG_DEBUG, "PDU Fraction read");
4263 /* signal one more use of ir object - callbacks must not
4264 release the ir memory (p pointer) */
4268 logf (LOG_DEBUG, "cs_get failed, code %d", r);
4269 ir_tcl_disconnect (p);
4272 p->failInfo = IR_TCL_FAIL_READ;
4273 ir_tcl_eval (p->interp, p->failback);
4275 /* release ir object now if callback deleted it */
4276 ir_obj_delete ((ClientData) p);
4279 /* got complete APDU. Now decode */
4282 odr_setbuf (p->odr_in, p->buf_in, r, 0);
4283 logf (LOG_DEBUG, "cs_get ok, total size %d", r);
4284 if (!z_APDU (p->odr_in, &apdu, 0, 0))
4286 logf (LOG_DEBUG, "cs_get failed: %s",
4287 odr_errmsg (odr_geterror (p->odr_in)));
4288 ir_tcl_disconnect (p);
4291 p->failInfo = IR_TCL_FAIL_IN_APDU;
4292 p->apduOffset = odr_offset (p->odr_in);
4293 ir_tcl_eval (p->interp, p->failback);
4295 /* release ir object now if failback deleted it */
4296 ir_obj_delete ((ClientData) p);
4299 /* handle APDU and invoke callback */
4300 rq = p->request_queue;
4303 logf (LOG_FATAL, "Internal error. No queue entry");
4306 object_name = rq->object_name;
4307 logf (LOG_DEBUG, "Object %s", object_name);
4309 if (Tcl_GetCommandInfo (p->interp, object_name, &cmd_info))
4313 case Z_APDU_initResponse:
4314 p->eventType = "init";
4315 ir_initResponse (p, apdu->u.initResponse);
4316 apdu_call = p->initResponse;
4318 case Z_APDU_searchResponse:
4319 p->eventType = "search";
4320 ir_searchResponse (p, apdu->u.searchResponse,
4321 (IrTcl_SetObj *) cmd_info.clientData);
4322 apdu_call = ((IrTcl_SetObj *)
4323 cmd_info.clientData)->searchResponse;
4325 case Z_APDU_presentResponse:
4326 p->eventType = "present";
4327 ir_presentResponse (p, apdu->u.presentResponse,
4328 (IrTcl_SetObj *) cmd_info.clientData);
4329 apdu_call = ((IrTcl_SetObj *)
4330 cmd_info.clientData)->presentResponse;
4332 case Z_APDU_scanResponse:
4333 p->eventType = "scan";
4334 ir_scanResponse (p, apdu->u.scanResponse,
4335 (IrTcl_ScanObj *) cmd_info.clientData);
4336 apdu_call = ((IrTcl_ScanObj *)
4337 cmd_info.clientData)->scanResponse;
4339 case Z_APDU_sortResponse:
4340 p->eventType = "sort";
4341 ir_sortResponse (p, apdu->u.sortResponse,
4342 (IrTcl_SetObj *) cmd_info.clientData);
4343 apdu_call = ((IrTcl_SetObj *)
4344 cmd_info.clientData)->sortResponse;
4347 logf (LOG_WARN, "Received unknown APDU type (%d)",
4349 ir_tcl_disconnect (p);
4352 p->failInfo = IR_TCL_FAIL_UNKNOWN_APDU;
4353 ir_tcl_eval (p->interp, p->failback);
4358 p->request_queue = rq->next;
4359 p->state = IR_TCL_R_Idle;
4362 ir_tcl_eval (p->interp, apdu_call);
4363 else if (rq->callback)
4364 ir_tcl_eval (p->interp, rq->callback);
4365 xfree (rq->buf_out);
4366 xfree (rq->callback);
4367 xfree (rq->object_name);
4369 odr_reset (p->odr_in);
4370 if (p->ref_count == 1)
4372 ir_obj_delete ((ClientData) p);
4375 ir_obj_delete ((ClientData) p);
4376 } while (p->cs_link && cs_more (p->cs_link));
4377 if (p->cs_link && p->request_queue && p->state == IR_TCL_R_Idle)
4378 ir_tcl_send_q (p, p->request_queue, "x");
4382 * ir_select_write: handle outgoing packages - not yet written.
4384 static int ir_select_write (ClientData clientData)
4386 IrTcl_Obj *p = (IrTcl_Obj *) clientData;
4390 logf (LOG_DEBUG, "Write handler fd=%d", cs_fileno(p->cs_link));
4391 if (p->state == IR_TCL_R_Connecting)
4393 logf(LOG_DEBUG, "write: connect");
4394 r = cs_rcvconnect (p->cs_link);
4397 logf (LOG_DEBUG, "cs_rcvconnect returned 1");
4400 p->state = IR_TCL_R_Idle;
4402 ir_select_remove_write (cs_fileno (p->cs_link), p);
4405 logf (LOG_DEBUG, "cs_rcvconnect error");
4406 ir_tcl_disconnect (p);
4409 p->failInfo = IR_TCL_FAIL_CONNECT;
4410 ir_tcl_eval (p->interp, p->failback);
4412 ir_obj_delete ((ClientData) p);
4416 ir_tcl_eval (p->interp, p->callback);
4417 ir_obj_delete ((ClientData) p);
4420 rq = p->request_queue;
4421 if (!rq || !rq->buf_out)
4424 if ((r=cs_put (p->cs_link, rq->buf_out, rq->len_out)) < 0)
4426 logf (LOG_DEBUG, "cs_put write fail");
4428 xfree (rq->buf_out);
4430 ir_tcl_disconnect (p);
4433 p->failInfo = IR_TCL_FAIL_WRITE;
4434 ir_tcl_eval (p->interp, p->failback);
4436 ir_obj_delete ((ClientData) p);
4438 else if (r == 0) /* remove select bit */
4440 logf (LOG_DEBUG, "Write completed");
4441 p->state = IR_TCL_R_Waiting;
4442 ir_select_remove_write (cs_fileno (p->cs_link), p);
4443 xfree (rq->buf_out);
4449 static void ir_select_notify (ClientData clientData, int r, int w, int e)
4453 if (!ir_select_write (clientData) && r)
4454 ir_select_read (clientData);
4458 ir_select_read (clientData);
4462 /*----------------------------------------------------------- */
4466 * This wrapper function is used by Windows to invoke the
4467 * initialization code for the DLL. If we are compiling
4468 * with Visual C++, this routine will be renamed to DllMain.
4480 DllEntryPoint(hInst, reason, reserved)
4481 HINSTANCE hInst; /* Library instance handle. */
4482 DWORD reason; /* Reason this function is being called. */
4483 LPVOID reserved; /* Not used. */
4489 /* ------------------------------------------------------- */
4491 * Irtcl_init: Registration of TCL commands.
4493 EXPORT (int,Irtcl_Init) (Tcl_Interp *interp)
4495 Tcl_CreateCommand (interp, "ir", ir_obj_mk, (ClientData) NULL,
4496 (Tcl_CmdDeleteProc *) NULL);
4497 Tcl_CreateCommand (interp, "ir-set", ir_set_obj_mk,
4498 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4499 Tcl_CreateCommand (interp, "ir-scan", ir_scan_obj_mk,
4500 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4501 Tcl_CreateCommand (interp, "ir-log-init", ir_log_init_proc,
4502 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4503 Tcl_CreateCommand (interp, "ir-log", ir_log_proc,
4504 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4505 Tcl_CreateCommand (interp, "ir-version", ir_version, (ClientData) NULL,
4506 (Tcl_CmdDeleteProc *) NULL);