Fix problem with print ODR/HTTP/odr_reset
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 31 Dec 2003 00:14:00 +0000 (00:14 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 31 Dec 2003 00:14:00 +0000 (00:14 +0000)
client/client.c
src/seshigh.c
src/zgdu.c

index 9bbeb1d..daee888 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: client.c,v 1.218 2003-12-30 00:22:11 adam Exp $
+ * $Id: client.c,v 1.219 2003-12-31 00:14:00 adam Exp $
  */
 
 #include <stdio.h>
@@ -1197,8 +1197,12 @@ static int send_srw(Z_SRW_PDU *sr)
         char *buf_out;
         int len_out;
         int r;
-       if (apdu_file && !z_GDU(print, &gdu, 0, 0))
-            printf ("Failed to print outgoing APDU\n");
+       if (apdu_file)
+       {
+           if (!z_GDU(print, &gdu, 0, 0))
+               printf ("Failed to print outgoing APDU\n");
+           odr_reset(print);
+       }
         buf_out = odr_getbuf(out, &len_out, 0);
         
         /* we don't odr_reset(out), since we may need the buffer again */
@@ -3446,7 +3450,10 @@ void wait_and_handle_response()
             odr_dumpBER(f, netbuffer, res);
             fprintf(f, "---------\n");
             if (apdu_file)
+           {
                 z_GDU(print, &gdu, 0, 0);
+               odr_reset(print);
+           }
             if (conn && cs_more(conn))
                 continue;
            break;
index 8dd5782..533ab9a 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.11 2003-12-30 00:29:53 adam Exp $
+ * $Id: seshigh.c,v 1.12 2003-12-31 00:14:01 adam Exp $
  */
 
 /*
@@ -353,10 +353,11 @@ void ir_session(IOCHAN h, int event)
                return;
            }
            req->request_mem = odr_extract_mem(assoc->decode);
-           if (assoc->print && !z_GDU(assoc->print, &req->gdu_request, 0, 0))
-           {
-               yaz_log(LOG_WARN, "ODR print error: %s", 
-                   odr_errmsg(odr_geterror(assoc->print)));
+           if (assoc->print) 
+            {
+               if (!z_GDU(assoc->print, &req->gdu_request, 0, 0))
+                   yaz_log(LOG_WARN, "ODR print error: %s", 
+                      odr_errmsg(odr_geterror(assoc->print)));
                odr_reset(assoc->print);
            }
            request_enq(&assoc->incoming, req);
@@ -1354,10 +1355,11 @@ static int process_gdu_response(association *assoc, request *req, Z_GDU *res)
 {
     odr_setbuf(assoc->encode, req->response, req->size_response, 1);
 
-    if (assoc->print && !z_GDU(assoc->print, &res, 0, 0))
+    if (assoc->print)
     {
-       yaz_log(LOG_WARN, "ODR print error: %s", 
-           odr_errmsg(odr_geterror(assoc->print)));
+       if (!z_GDU(assoc->print, &res, 0, 0))
+           yaz_log(LOG_WARN, "ODR print error: %s", 
+               odr_errmsg(odr_geterror(assoc->print)));
        odr_reset(assoc->print);
     }
     if (!z_GDU(assoc->encode, &res, 0, 0))
@@ -1561,7 +1563,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
                assoc->init->implementation_name,
                odr_prepend(assoc->encode, "GFS", resp->implementationName));
 
-    version = odr_strdup(assoc->encode, "$Revision: 1.11 $");
+    version = odr_strdup(assoc->encode, "$Revision: 1.12 $");
     if (strlen(version) > 10)  /* check for unexpanded CVS strings */
        version[strlen(version)-2] = '\0';
     resp->implementationVersion = odr_prepend(assoc->encode,
index 692ccf0..543eda6 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2003, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: zgdu.c,v 1.4 2003-12-30 15:18:53 adam Exp $
+ * $Id: zgdu.c,v 1.5 2003-12-31 00:14:01 adam Exp $
  */
 
 #include <yaz/odr.h>
@@ -294,11 +294,10 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name)
             if (!z_HTTP_header_lookup((*p)->u.HTTP_Response->headers,
                                       "Content-Length"))
             {
-                char lstr[20];
-                sprintf(lstr, "%d", (*p)->u.HTTP_Response->content_len);
-                z_HTTP_header_add(o,
-                                  &(*p)->u.HTTP_Response->headers,
-                                  "Content-Length", lstr);
+                char lstr[60];
+                sprintf(lstr, "Content-Length: %d\r\n",
+                       (*p)->u.HTTP_Response->content_len);
+                odr_write(o, (unsigned char *) lstr, strlen(lstr));
             }
             for (h = (*p)->u.HTTP_Response->headers; h; h = h->next)
             {
@@ -333,11 +332,10 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name)
                 !z_HTTP_header_lookup((*p)->u.HTTP_Request->headers,
                                       "Content-Length"))
             {
-                char lstr[20];
-                sprintf(lstr, "%d", (*p)->u.HTTP_Request->content_len);
-                z_HTTP_header_add(o,
-                                  &(*p)->u.HTTP_Request->headers,
-                                  "Content-Length", lstr);
+                char lstr[60];
+                sprintf(lstr, "Content-Length: %d\r\n",
+                       (*p)->u.HTTP_Request->content_len);
+                odr_write(o, (unsigned char *) lstr, strlen(lstr));
             }
             for (h = (*p)->u.HTTP_Request->headers; h; h = h->next)
             {