* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ir-tcl.c,v $
- * Revision 1.47 1995-06-25 10:25:04 adam
+ * Revision 1.51 1995-08-03 13:22:54 adam
+ * Request queue.
+ *
+ * Revision 1.50 1995/07/20 08:09:49 adam
+ * client.tcl: Targets removed from hotTargets list when targets
+ * are removed/modified.
+ * ir-tcl.c: More work on triggerResourceControl.
+ *
+ * Revision 1.49 1995/06/30 12:39:21 adam
+ * Bug fix: loadFile didn't set record type.
+ * The MARC routines are a little less strict in the interpretation.
+ * Script display.tcl replaces the old marc.tcl.
+ * New interactive script: shell.tcl.
+ *
+ * Revision 1.48 1995/06/27 19:03:50 adam
+ * Bug fix in do_present in ir-tcl.c: p->set_child member weren't set.
+ * nextResultSetPosition used instead of setOffset.
+ *
+ * Revision 1.47 1995/06/25 10:25:04 adam
* Working on triggerResourceControl. Description of compile/install
* procedure moved to ir-tcl.sgml.
*
if (argc <= 0)
return TCL_OK;
- Tcl_AppendResult (interp, "Bad method. Possible methods:", NULL);
+ Tcl_AppendResult (interp, "Bad method: ", argv[1],
+ ". Possible methods:", NULL);
for (tab_i = tab; tab_i->tab; tab_i++)
for (t = tab_i->tab; t->name; t++)
Tcl_AppendResult (interp, " ", t->name, NULL);
/* ------------------------------------------------------- */
+#if 0
+/*
+ * ir-tcl_send_APDU: send APDU
+ */
+static int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
+ const char *msg)
+{
+ int r;
+
+ if (!z_APDU (p->odr_out, &apdu, 0))
+ {
+ Tcl_AppendResult (interp, odr_errlist [odr_geterror (p->odr_out)],
+ NULL);
+ odr_reset (p->odr_out);
+ return TCL_ERROR;
+ }
+ p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
+ odr_reset (p->odr_out);
+ if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
+ {
+ sprintf (interp->result, "cs_put failed in %s", msg);
+ do_disconnect (p, NULL, 2, NULL);
+ return TCL_ERROR;
+ }
+ else if (r == 1)
+ {
+ ir_select_add_write (cs_fileno(p->cs_link), p);
+ logf (LOG_DEBUG, "Sent part of %s (%d bytes)", msg, p->slen);
+ }
+ else
+ logf (LOG_DEBUG, "Sent whole %s (%d bytes)", msg, p->slen);
+ return TCL_OK;
+}
+#endif
+
/*
* do_init_request: init method on IR object
*/
Z_APDU *apdu;
IrTcl_Obj *p = obj;
Z_InitRequest *req;
- int r;
if (argc <= 0)
return TCL_OK;
interp->result = "not connected";
return TCL_ERROR;
}
- odr_reset (p->odr_out);
apdu = zget_APDU (p->odr_out, Z_APDU_initRequest);
req = apdu->u.initRequest;
req->implementationVersion = p->implementationVersion;
req->userInformationField = 0;
- if (!z_APDU (p->odr_out, &apdu, 0))
- {
- Tcl_AppendResult (interp, odr_errlist [odr_geterror (p->odr_out)],
- NULL);
- odr_reset (p->odr_out);
- return TCL_ERROR;
- }
- p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
- if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
- {
- interp->result = "cs_put failed in init";
- do_disconnect (p, NULL, 2, NULL);
- return TCL_ERROR;
- }
- else if (r == 1)
- {
- ir_select_add_write (cs_fileno(p->cs_link), p);
- logf (LOG_DEBUG, "Sent part of initializeRequest (%d bytes)", p->slen);
- }
- else
- logf (LOG_DEBUG, "Sent whole initializeRequest (%d bytes)", p->slen);
- return TCL_OK;
+ return ir_tcl_send_APDU (interp, p, apdu, "init");
}
/*
ODR_MASK_ZERO (&p->options);
ODR_MASK_SET (&p->options, 0);
ODR_MASK_SET (&p->options, 1);
+ ODR_MASK_SET (&p->options, 4);
ODR_MASK_SET (&p->options, 7);
ODR_MASK_SET (&p->options, 14);
return TCL_OK;
if (r == 1)
{
ir_select_add_write (cs_fileno (p->cs_link), p);
- p->connectFlag = 1;
+ p->state = IR_TCL_R_Connecting;
}
else
{
- p->connectFlag = 0;
+ p->state = IR_TCL_R_Idle;
if (p->callback)
IrTcl_eval (p->interp, p->callback);
}
}
- if (p->hostname)
- Tcl_AppendElement (interp, p->hostname);
return TCL_OK;
}
if (argc == 0)
{
- p->connectFlag = 0;
+ p->state = IR_TCL_R_Idle;
p->hostname = NULL;
p->cs_link = NULL;
return TCL_OK;
ODR_MASK_ZERO (&p->options);
ODR_MASK_SET (&p->options, 0);
ODR_MASK_SET (&p->options, 1);
+ ODR_MASK_SET (&p->options, 4);
ODR_MASK_SET (&p->options, 7);
ODR_MASK_SET (&p->options, 14);
IrTcl_Obj *p = obj;
Z_APDU *apdu;
Z_TriggerResourceControlRequest *req;
- int r;
+ bool_t is_false = 0;
if (argc <= 0)
return TCL_OK;
}
apdu = zget_APDU (p->odr_out, Z_APDU_triggerResourceControlRequest);
req = apdu->u.triggerResourceControlRequest;
+ *req->requestedAction = Z_TriggerResourceCtrl_cancel;
+ req->resultSetWanted = &is_false;
- if (!z_APDU (p->odr_out, &apdu, 0))
- {
- Tcl_AppendResult (interp, odr_errlist [odr_geterror (p->odr_out)],
- NULL);
- odr_reset (p->odr_out);
- return TCL_ERROR;
- }
- p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
- if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
- {
- interp->result = "cs_put failed in triggerResourceControl";
- do_disconnect (p, NULL, 2, NULL);
- return TCL_ERROR;
- }
- else if (r == 1)
- {
- ir_select_add_write (cs_fileno(p->cs_link), p);
- logf (LOG_DEBUG, "Sent part of triggerResourceControl (%d bytes)",
- p->slen);
- }
- else
- logf (LOG_DEBUG, "Sent whole of triggerResourceControl (%d bytes)",
- p->slen);
- return TCL_OK;
+ return ir_tcl_send_APDU (interp, p, apdu, "triggerResourceControl");
}
/*
odr_destroy (obj->odr_in);
odr_destroy (obj->odr_out);
odr_destroy (obj->odr_pr);
- free (obj->buf_out);
- free (obj->buf_in);
free (obj);
}
obj->odr_in = odr_createmem (ODR_DECODE);
obj->odr_out = odr_createmem (ODR_ENCODE);
obj->odr_pr = odr_createmem (ODR_PRINT);
-
- obj->len_out = 10000;
- if (!(obj->buf_out = ir_malloc (interp, obj->len_out)))
- return TCL_ERROR;
- odr_setbuf (obj->odr_out, obj->buf_out, obj->len_out, 0);
+ obj->state = IR_TCL_R_Idle;
obj->len_in = 0;
obj->buf_in = NULL;
+ obj->request_queue = NULL;
tab[0].tab = ir_method_tab;
tab[0].obj = obj;
Z_APDU *apdu;
Odr_oct ccl_query;
IrTcl_SetObj *obj = o;
- IrTcl_Obj *p = obj->parent;
+ IrTcl_Obj *p;
int r;
oident bib1;
if (argc <= 0)
return TCL_OK;
+ p = obj->parent;
p->set_child = o;
if (argc != 3)
{
interp->result = "not connected";
return TCL_ERROR;
}
- odr_reset (p->odr_out);
apdu = zget_APDU (p->odr_out, Z_APDU_searchRequest);
req = apdu->u.searchRequest;
interp->result = "unknown query method";
return TCL_ERROR;
}
- if (!z_APDU (p->odr_out, &apdu, 0))
- {
- interp->result = odr_errlist [odr_geterror (p->odr_out)];
- odr_reset (p->odr_out);
- return TCL_ERROR;
- }
- p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
- if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
- {
- interp->result = "cs_put failed in search";
- return TCL_ERROR;
- }
- else if (r == 1)
- {
- ir_select_add_write (cs_fileno(p->cs_link), p);
- logf (LOG_DEBUG, "Sent part of searchRequest (%d bytes)", p->slen);
- }
- else
- {
- logf (LOG_DEBUG, "Whole search request (%d bytes)", p->slen);
- }
- return TCL_OK;
+ return ir_tcl_send_APDU (interp, p, apdu, "search");
}
/*
IrTcl_SetObj *obj = o;
if (argc <= 0)
+ {
+ obj->nextResultSetPosition = 0;
return TCL_OK;
+ }
return get_set_int (&obj->nextResultSetPosition, interp, argc, argv);
}
int argc, char **argv)
{
IrTcl_SetObj *obj = o;
- IrTcl_Obj *p = obj->parent;
+ IrTcl_Obj *p;
Z_APDU *apdu;
Z_PresentRequest *req;
int start;
int number;
- int r;
if (argc <= 0)
return TCL_OK;
interp->result = "not connected";
return TCL_ERROR;
}
- odr_reset (p->odr_out);
+ p = obj->parent;
+ p->set_child = obj;
+
obj->start = start;
obj->number = number;
}
else
req->preferredRecordSyntax = 0;
-
- if (!z_APDU (p->odr_out, &apdu, 0))
- {
- interp->result = odr_errlist [odr_geterror (p->odr_out)];
- odr_reset (p->odr_out);
- return TCL_ERROR;
- }
- p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
- if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
- {
- interp->result = "cs_put failed in present";
- return TCL_ERROR;
- }
- else if (r == 1)
- {
- ir_select_add_write (cs_fileno(p->cs_link), p);
- logf (LOG_DEBUG, "Part of present request, start=%d, num=%d"
- " (%d bytes)", start, number, p->slen);
- }
- else
- {
- logf (LOG_DEBUG, "Whole present request, start=%d, num=%d"
- " (%d bytes)", start, number, p->slen);
- }
- return TCL_OK;
+
+ return ir_tcl_send_APDU (interp, p, apdu, "present");
}
/*
IrTcl_RecordList *rl;
rl = new_IR_record (setobj, no, Z_NamePlusRecord_databaseRecord);
+ rl->u.dbrec.type = VAL_USMARC;
rl->u.dbrec.buf = buf;
rl->u.dbrec.size = size;
no++;
Z_APDU *apdu;
IrTcl_ScanObj *obj = o;
IrTcl_Obj *p = obj->parent;
- int r;
oident bib1;
#if CCL2RPN
struct ccl_rpn_node *rpn;
interp->result = "not connected";
return TCL_ERROR;
}
- odr_reset (p->odr_out);
bib1.proto = p->protocol_type;
bib1.class = CLASS_ATTSET;
*req->numberOfTermsRequested);
logf (LOG_DEBUG, "preferredPositionInResponse=%d",
*req->preferredPositionInResponse);
-
- if (!z_APDU (p->odr_out, &apdu, 0))
- {
- interp->result = odr_errlist [odr_geterror (p->odr_out)];
- odr_reset (p->odr_out);
- return TCL_ERROR;
- }
- p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
- if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
- {
- interp->result = "cs_put failed in scan";
- return TCL_ERROR;
- }
- else if (r == 1)
- {
- ir_select_add_write (cs_fileno(p->cs_link), p);
- logf (LOG_DEBUG, "Sent part of scanRequest (%d bytes)", p->slen);
- }
- else
- {
- logf (LOG_DEBUG, "Whole scan request (%d bytes)", p->slen);
- }
- return TCL_OK;
+
+ return ir_tcl_send_APDU (interp, p, apdu, "scan");
}
/*
rl->u.dbrec.size = zr->u.octet_aligned->len;
rl->u.dbrec.type = VAL_USMARC;
- ident = oid_getentbyoid (oe->direct_reference);
- rl->u.dbrec.type = ident->value;
-
+ if ((ident = oid_getentbyoid (oe->direct_reference)))
+ rl->u.dbrec.type = ident->value;
if (oe->which == ODR_EXTERNAL_octet && rl->u.dbrec.size > 0)
{
char *buf = (char*) zr->u.octet_aligned->buf;
Z_APDU *apdu;
int r;
- if (p->connectFlag)
+ if (p->state == IR_TCL_R_Connecting)
{
r = cs_rcvconnect (p->cs_link);
if (r == 1)
logf (LOG_WARN, "cs_rcvconnect returned 1");
return;
}
- p->connectFlag = 0;
+ p->state = IR_TCL_R_Idle;
ir_select_remove_write (cs_fileno (p->cs_link), p);
if (r < 0)
{
}
if (p->callback)
IrTcl_eval (p->interp, p->callback);
+ if (p->cs_link && p->request_queue)
+ ir_tcl_send_q (p, p->request_queue, "x");
return;
}
do
{
/* signal one more use of ir object - callbacks must not
release the ir memory (p pointer) */
+ p->state = IR_TCL_R_Reading;
++(p->ref_count);
if ((r=cs_get (p->cs_link, &p->buf_in, &p->len_in)) <= 0)
{
}
do_disconnect (p, NULL, 2, NULL);
- /* relase ir object now if callback deleted it */
+ /* release ir object now if callback deleted it */
ir_obj_delete (p);
return;
}
do_disconnect (p, NULL, 2, NULL);
}
odr_reset (p->odr_in);
+ if (p->request_queue) /* remove queue entry */
+ {
+ IrTcl_Request *rq;
+ rq = p->request_queue;
+ p->request_queue = rq->next;
+ free (rq->buf_out);
+ free (rq);
+ if (!p->request_queue)
+ p->state = IR_TCL_R_Idle;
+ }
+ else
+ {
+ logf (LOG_FATAL, "Internal error. No queue entry");
+ exit (1);
+ }
if (p->callback)
IrTcl_eval (p->interp, p->callback);
if (p->ref_count == 1)
return;
}
--(p->ref_count);
- } while (p->cs_link && cs_more (p->cs_link));
+ } while (p->cs_link && cs_more (p->cs_link));
+ if (p->cs_link && p->request_queue)
+ ir_tcl_send_q (p, p->request_queue, "x");
}
/*
{
IrTcl_Obj *p = clientData;
int r;
+ IrTcl_Request *rq;
logf (LOG_DEBUG, "In write handler");
- if (p->connectFlag)
+ if (p->state == IR_TCL_R_Connecting)
{
r = cs_rcvconnect (p->cs_link);
if (r == 1)
return;
- p->connectFlag = 0;
+ p->state = IR_TCL_R_Idle;
if (r < 0)
{
logf (LOG_DEBUG, "cs_rcvconnect error");
IrTcl_eval (p->interp, p->callback);
return;
}
+#if 0
if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
{
logf (LOG_DEBUG, "select write fail");
}
do_disconnect (p, NULL, 2, NULL);
}
+#else
+ rq = p->request_queue;
+ assert (rq);
+ if ((r=cs_put (p->cs_link, rq->buf_out, rq->len_out)) < 0)
+ {
+ logf (LOG_DEBUG, "select write fail");
+ if (p->failback)
+ {
+ p->failInfo = IR_TCL_FAIL_WRITE;
+ IrTcl_eval (p->interp, p->failback);
+ }
+ free (rq->buf_out);
+ rq->buf_out = NULL;
+ do_disconnect (p, NULL, 2, NULL);
+ }
+#endif
else if (r == 0) /* remove select bit */
{
+ p->state = IR_TCL_R_Waiting;
ir_select_remove_write (cs_fileno (p->cs_link), p);
+ free (rq->buf_out);
+ rq->buf_out = NULL;
}
}