+static int do_referenceId (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IrTcl_SetCObj *p = obj;
+
+ if (argc == 0)
+ {
+ p->referenceId = NULL;
+ return TCL_OK;
+ }
+ else if (argc == -1)
+ return ir_tcl_strdel (interp, &p->referenceId);
+ if (argc == 3)
+ {
+ free (p->referenceId);
+ if (ir_tcl_strdup (interp, &p->referenceId, argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult (interp, p->referenceId, NULL);
+ return TCL_OK;
+}
+
+/*
+ * do_preferredRecordSyntax: Set/get preferred record syntax
+ */
+static int do_preferredRecordSyntax (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IrTcl_SetCObj *p = obj;
+
+ if (argc == 0)
+ {
+ p->preferredRecordSyntax = NULL;
+ return TCL_OK;
+ }
+ else if (argc == -1)
+ {
+ free (p->preferredRecordSyntax);
+ p->preferredRecordSyntax = NULL;
+ return TCL_OK;
+ }
+ if (argc == 3)
+ {
+ free (p->preferredRecordSyntax);
+ p->preferredRecordSyntax = NULL;
+ if (argv[2][0] && (p->preferredRecordSyntax =
+ ir_tcl_malloc (sizeof(*p->preferredRecordSyntax))))
+ *p->preferredRecordSyntax = IrTcl_getRecordSyntaxVal (argv[2]);
+ }
+ else if (argc == 2)
+ {
+ Tcl_AppendElement (interp, IrTcl_getRecordSyntaxStr
+ (*p->preferredRecordSyntax));
+ }
+ return TCL_OK;
+
+}
+
+/*
+ * do_elementSetNames: Set/Get element Set Names
+ */
+static int do_elementSetNames (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IrTcl_SetCObj *p = obj;
+
+ if (argc == 0)
+ {
+ p->elementSetNames = NULL;
+ return TCL_OK;
+ }
+ else if (argc == -1)
+ return ir_tcl_strdel (interp, &p->elementSetNames);
+ if (argc == 3)
+ {
+ free (p->elementSetNames);
+ if (ir_tcl_strdup (interp, &p->elementSetNames, argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult (interp, p->elementSetNames, NULL);
+ return TCL_OK;
+}
+
+/*
+ * do_smallSetElementSetNames: Set/Get small Set Element Set Names
+ */
+static int do_smallSetElementSetNames (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IrTcl_SetCObj *p = obj;
+
+ if (argc == 0)
+ {
+ p->smallSetElementSetNames = NULL;
+ return TCL_OK;
+ }
+ else if (argc == -1)
+ return ir_tcl_strdel (interp, &p->smallSetElementSetNames);
+ if (argc == 3)
+ {
+ free (p->smallSetElementSetNames);
+ if (ir_tcl_strdup (interp, &p->smallSetElementSetNames,
+ argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult (interp, p->smallSetElementSetNames, NULL);
+ return TCL_OK;
+}
+
+/*
+ * do_mediumSetElementSetNames: Set/Get medium Set Element Set Names
+ */
+static int do_mediumSetElementSetNames (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IrTcl_SetCObj *p = obj;
+
+ if (argc == 0)
+ {
+ p->mediumSetElementSetNames = NULL;
+ return TCL_OK;
+ }
+ else if (argc == -1)
+ return ir_tcl_strdel (interp, &p->mediumSetElementSetNames);
+ if (argc == 3)
+ {
+ free (p->mediumSetElementSetNames);
+ if (ir_tcl_strdup (interp, &p->mediumSetElementSetNames,
+ argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult (interp, p->mediumSetElementSetNames, NULL);
+ return TCL_OK;
+}
+
+static IrTcl_Method ir_method_tab[] = {
+{ "comstack", do_comstack, NULL },
+{ "protocol", do_protocol, NULL },
+{ "failback", do_failback, NULL },
+{ "failInfo", do_failInfo, NULL },
+{ "apduInfo", do_apduInfo, NULL },
+{ "logLevel", do_logLevel, NULL },
+
+{ "eventType", do_eventType, NULL },
+{ "connect", do_connect, NULL },
+{ "protocolVersion", do_protocolVersion, NULL },
+{ "preferredMessageSize", do_preferredMessageSize, NULL },
+{ "maximumRecordSize", do_maximumRecordSize, NULL },
+{ "implementationName", do_implementationName, NULL },
+{ "implementationId", do_implementationId, NULL },
+{ "implementationVersion", do_implementationVersion, NULL },
+{ "targetImplementationName", do_targetImplementationName, NULL },
+{ "targetImplementationId", do_targetImplementationId, NULL },
+{ "targetImplementationVersion", do_targetImplementationVersion, NULL},
+{ "userInformationField", do_userInformationField, NULL},
+{ "idAuthentication", do_idAuthentication, NULL},
+{ "options", do_options, NULL},
+{ "init", do_init_request, NULL},
+{ "initResult", do_initResult, NULL},
+{ "disconnect", do_disconnect, NULL},
+{ "callback", do_callback, NULL},
+{ "initResponse", do_initResponse, NULL},
+{ "triggerResourceControl", do_triggerResourceControl, NULL},
+{ "initResponse", do_initResponse, NULL},
+{ NULL, NULL}
+};
+
+static IrTcl_Method ir_set_c_method_tab[] = {
+{ "databaseNames", do_databaseNames, NULL},
+{ "replaceIndicator", do_replaceIndicator, NULL},
+{ "queryType", do_queryType, NULL},
+{ "preferredRecordSyntax", do_preferredRecordSyntax, NULL},
+{ "smallSetUpperBound", do_smallSetUpperBound, NULL},
+{ "largeSetLowerBound", do_largeSetLowerBound, NULL},
+{ "mediumSetPresentNumber", do_mediumSetPresentNumber, NULL},
+{ "referenceId", do_referenceId, NULL},
+{ "elementSetNames", do_elementSetNames, NULL},
+{ "smallSetElementSetNames", do_smallSetElementSetNames, NULL},
+{ "mediumSetElementSetNames", do_mediumSetElementSetNames, NULL},
+{ NULL, NULL}
+};
+
+/*
+ * ir_obj_method: IR Object methods
+ */
+static int ir_obj_method (ClientData clientData, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IrTcl_Methods tab[3];
+ IrTcl_Obj *p = clientData;
+
+ if (argc < 2)
+ return TCL_ERROR;
+
+ tab[0].tab = ir_method_tab;
+ tab[0].obj = p;
+ tab[1].tab = ir_set_c_method_tab;
+ tab[1].obj = &p->set_inher;
+ tab[2].tab = NULL;
+
+ return ir_tcl_method (interp, argc, argv, tab);
+}
+
+/*
+ * ir_obj_delete: IR Object disposal
+ */
+static void ir_obj_delete (ClientData clientData)
+{
+ IrTcl_Obj *obj = clientData;
+ IrTcl_Methods tab[3];
+
+ --(obj->ref_count);
+ if (obj->ref_count > 0)
+ return;
+ assert (obj->ref_count == 0);
+
+ logf (LOG_DEBUG, "ir object delete");
+ tab[0].tab = ir_method_tab;
+ tab[0].obj = obj;
+ tab[1].tab = ir_set_c_method_tab;
+ tab[1].obj = &obj->set_inher;
+ tab[2].tab = NULL;
+
+ ir_tcl_method (NULL, -1, NULL, tab);
+
+ ir_tcl_del_q (obj);
+ odr_destroy (obj->odr_in);
+ odr_destroy (obj->odr_out);
+ odr_destroy (obj->odr_pr);
+ free (obj);
+}
+
+/*
+ * ir_obj_init: IR Object initialization
+ */
+int ir_obj_init (ClientData clientData, Tcl_Interp *interp,
+ int argc, char **argv, ClientData *subData)
+{
+ IrTcl_Methods tab[3];
+ IrTcl_Obj *obj;
+#if CCL2RPN
+ FILE *inf;
+#endif
+
+ if (argc != 2)
+ {
+ interp->result = "wrong # args";
+ return TCL_ERROR;
+ }
+ obj = ir_tcl_malloc (sizeof(*obj));
+ obj->ref_count = 1;
+#if CCL2RPN
+ obj->bibset = ccl_qual_mk ();
+ if ((inf = fopen ("default.bib", "r")))
+ {
+ ccl_qual_file (obj->bibset, inf);
+ fclose (inf);
+ }
+#endif
+
+ logf (LOG_DEBUG, "ir object create %s", argv[1]);
+ obj->odr_in = odr_createmem (ODR_DECODE);
+ obj->odr_out = odr_createmem (ODR_ENCODE);
+ obj->odr_pr = odr_createmem (ODR_PRINT);
+ obj->state = IR_TCL_R_Idle;
+ obj->interp = interp;
+
+ obj->len_in = 0;
+ obj->buf_in = NULL;
+ obj->request_queue = NULL;
+
+ tab[0].tab = ir_method_tab;
+ tab[0].obj = obj;
+ tab[1].tab = ir_set_c_method_tab;
+ tab[1].obj = &obj->set_inher;
+ tab[2].tab = NULL;
+
+ if (ir_tcl_method (interp, 0, NULL, tab) == TCL_ERROR)
+ {
+ Tcl_AppendResult (interp, "Failed to initialize ", argv[1], NULL);
+ return TCL_ERROR;
+ }
+ *subData = obj;
+ return TCL_OK;
+}
+
+
+/*
+ * ir_obj_mk: IR Object creation
+ */
+static int ir_obj_mk (ClientData clientData, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ ClientData subData;
+ int r = ir_obj_init (clientData, interp, argc, argv, &subData);
+
+ if (r == TCL_ERROR)
+ return TCL_ERROR;
+ Tcl_CreateCommand (interp, argv[1], ir_obj_method,
+ subData, ir_obj_delete);
+ return TCL_OK;
+}
+
+IrTcl_Class ir_obj_class = {
+ "ir",
+ ir_obj_init,
+ ir_obj_method,
+ ir_obj_delete
+};
+
+
+/* ------------------------------------------------------- */
+/*
+ * do_search: Do search request
+ */
+static int do_search (void *o, Tcl_Interp *interp, int argc, char **argv)