Allow YAZ 2 series only
[ir-tcl-moved-to-github.git] / queue.c
diff --git a/queue.c b/queue.c
index 8baebe9..8ced170 100644 (file)
--- a/queue.c
+++ b/queue.c
@@ -1,12 +1,27 @@
-
 /*
  * IR toolkit for tcl/tk
- * (c) Index Data 1995
+ * (c) Index Data 1995-1999
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: queue.c,v $
- * Revision 1.8  1996-03-05 09:21:20  adam
+ * Revision 1.13  2003-03-05 21:21:42  adam
+ * APDU log. default largeSetLowerBound changed from 2 to 1
+ *
+ * Revision 1.12  1999/04/20 10:01:46  adam
+ * Modified calls to ODR encoders/decoders (name argument).
+ *
+ * Revision 1.11  1996/07/03 13:31:14  adam
+ * The xmalloc/xfree functions from YAZ are used to manage memory.
+ *
+ * Revision 1.10  1996/06/03  09:04:24  adam
+ * Changed a few logf calls.
+ *
+ * Revision 1.9  1996/03/20  13:54:05  adam
+ * The Tcl_File structure is only manipulated in the Tk-event interface
+ * in tkinit.c.
+ *
+ * Revision 1.8  1996/03/05  09:21:20  adam
  * Bug fix: memory used by GRS records wasn't freed.
  * Rewrote some of the error handling code - the connection is always
  * closed before failback is called.
@@ -54,13 +69,15 @@ int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
 {
     IrTcl_Request **rp;
 
-    if (!z_APDU (p->odr_out, &apdu, 0))
+    if (!z_APDU (p->odr_out, &apdu, 0, 0))
     {
         Tcl_AppendResult (interp, odr_errmsg (odr_geterror (p->odr_out)),
                           NULL);
         odr_reset (p->odr_out);
         return TCL_ERROR;
     }
+    if (p->odr_pr)
+        z_APDU (p->odr_pr, &apdu, 0, 0);
     rp = &p->request_queue;
     while (*rp)
         rp = &(*rp)->next;
@@ -77,7 +94,7 @@ int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
     odr_reset (p->odr_out);
     if (p->state == IR_TCL_R_Idle)
     {
-        logf (LOG_DEBUG, "send_apdu. Sending %s", msg);
+        logf (LOG_DEBUG, "APDU send %s", msg);
         if (ir_tcl_send_q (p, p->request_queue, msg) == TCL_ERROR)
         {
             if (p->failback)
@@ -95,7 +112,7 @@ int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu,
         } 
     }
     else
-        logf (LOG_DEBUG, "send_apdu. Not idle (%s)", msg);
+        logf (LOG_DEBUG, "APDU pending %s", msg);
     return TCL_OK;
 }
 
@@ -109,11 +126,7 @@ int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rp, const char *msg)
         return TCL_ERROR;
     else if (r == 1)
     {
-#if IRTCL_GENERIC_FILES
-        ir_select_add_write (p->csFile, p);
-#else
         ir_select_add_write (cs_fileno (p->cs_link), p);
-#endif
         logf (LOG_DEBUG, "Send part of %s", msg);
         p->state = IR_TCL_R_Writing;
     }
@@ -122,7 +135,7 @@ int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rp, const char *msg)
         logf (LOG_DEBUG, "Send %s (%d bytes) fd=%d", msg, rp->len_out,
               cs_fileno(p->cs_link));
         p->state = IR_TCL_R_Waiting;
-        free (rp->buf_out);
+        xfree (rp->buf_out);
         rp->buf_out = NULL;
     }
     return TCL_OK;
@@ -135,11 +148,11 @@ void ir_tcl_del_q (IrTcl_Obj *p)
     p->state = IR_TCL_R_Idle;
     for (rp = p->request_queue; rp; rp = rp1)
     {
-        free (rp->object_name);
-        free (rp->callback);
-        free (rp->buf_out);
+        xfree (rp->object_name);
+        xfree (rp->callback);
+        xfree (rp->buf_out);
         rp1 = rp->next;
-        free (rp);
+        xfree (rp);
     }
     p->request_queue = NULL;
 }