Added APDU log to client.
[yaz-moved-to-github.git] / client / client.c
index 9b17c9c..5623f46 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
- * Revision 1.83  1999-05-26 15:24:26  adam
+ * Revision 1.85  1999-06-16 11:55:24  adam
+ * Added APDU log to client.
+ *
+ * Revision 1.84  1999/06/01 14:29:11  adam
+ * Work on Extended Services.
+ *
+ * Revision 1.83  1999/05/26 15:24:26  adam
  * Fixed minor bugs regarding DB Update (introduced by previous commit).
  *
  * Revision 1.82  1999/05/26 13:49:12  adam
 
 #include <yaz-util.h>
 
-#include <comstack.h>
 #include <tcpip.h>
 #ifdef USE_XTIMOSI
 #include <xmosi.h>
 #define C_PROMPT "Z> "
 
 static ODR out, in, print;              /* encoding and decoding streams */
+static FILE *apdu_file = 0;
 static COMSTACK conn = 0;               /* our z-association */
 static Z_IdAuthentication *auth = 0;    /* our current auth definition */
 static char *databaseNames[128];
@@ -350,6 +356,11 @@ static void send_apdu(Z_APDU *a)
         odr_perror(out, "Encoding APDU");
         exit(1);
     }
+    if (apdu_file)
+    {
+        z_APDU(print, &a, 0, 0);
+        odr_reset(print);
+    }
     buf = odr_getbuf(out, &len, 0);
     if (cs_put(conn, buf, len) < 0)
     {
@@ -1129,7 +1140,20 @@ static int process_resourceControlRequest (Z_ResourceControlRequest *req)
 
 void process_ESResponse(Z_ExtendedServicesResponse *res)
 {
-    printf("process_ESResponse\n");
+    printf("process_ESResponse status=");
+    switch (*res->operationStatus)
+    {
+    case Z_ExtendedServicesResponse_done:
+       printf ("done\n");
+       break;
+    case Z_ExtendedServicesResponse_accepted:
+       printf ("accepted\n");
+       break;
+    case Z_ExtendedServicesResponse_failure:
+       printf ("failure\n");
+       display_diagrecs(res->diagnostics, res->num_diagnostics);
+       break;
+    }
 }
 
 static Z_External *CreateItemOrderExternal(int itemno)
@@ -1893,6 +1917,8 @@ static void initialize(void)
         exit(1);
     }
     setvbuf(stdout, 0, _IONBF, 0);
+    if (apdu_file)
+        odr_setprint(print, apdu_file);
 
 #if CCL2RPN
     bibset = ccl_qual_mk (); 
@@ -2045,14 +2071,12 @@ static int client(int wait)
                     fprintf(stderr, "---------\n");
                     exit(1);
                 }
-#if 0
-                if (!z_APDU(print, &apdu, 0))
+                if (apdu_file && !z_APDU(print, &apdu, 0, 0))
                 {
                     odr_perror(print, "Failed to print incoming APDU");
                     odr_reset(print);
                     continue;
                 }
-#endif
                 switch(apdu->which)
                 {
                case Z_APDU_initResponse:
@@ -2114,7 +2138,7 @@ int main(int argc, char **argv)
     int ret;
     int opened = 0;
 
-    while ((ret = options("m:v:", argv, argc, &arg)) != -2)
+    while ((ret = options("a:m:v:", argv, argc, &arg)) != -2)
     {
         switch (ret)
         {
@@ -2133,11 +2157,18 @@ int main(int argc, char **argv)
                 exit (1);
             }
             break;
+        case 'a':
+            if (!strcmp(arg, "-"))
+                apdu_file=stderr;
+            else
+                apdu_file=fopen(arg, "a");
+            break;
        case 'v':
            log_init (log_mask_str(arg), "", NULL);
            break;
         default:
-            fprintf (stderr, "Usage: %s [-m <marclog>] [<server-addr>]\n",
+            fprintf (stderr, "Usage: %s [-m <marclog>] [ -m <apdulog>] "
+                             "[<server-addr>]\n",
                      prog);
             exit (1);
         }