Fixed for new version of automake.
[yaz-moved-to-github.git] / client / client.c
index a440165..d7e71f8 100644 (file)
@@ -4,7 +4,20 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
- * Revision 1.101  2000-04-05 07:39:54  adam
+ * Revision 1.105  2000-10-02 11:07:44  adam
+ * Added peer_name member for bend_init handler. Changed the YAZ
+ * client so that tcp: can be avoided in target spec.
+ *
+ * Revision 1.104  2000/09/04 08:58:15  adam
+ * Added prefix yaz_ for most logging utility functions.
+ *
+ * Revision 1.103  2000/08/10 08:41:26  adam
+ * Fixes for ILL.
+ *
+ * Revision 1.102  2000/05/18 11:57:04  adam
+ * Client display time elapsed.
+ *
+ * Revision 1.101  2000/04/05 07:39:54  adam
  * Added shared library support (libtool).
  *
  * Revision 1.100  2000/03/20 19:29:59  adam
@@ -551,7 +564,8 @@ static int cmd_base(char *arg)
 int cmd_open(char *arg)
 {
     void *add;
-    char type[100], addr[100], base[100];
+    char type_and_host[101], base[101];
+    char *host = 0;
     CS_TYPE t;
 
     if (conn)
@@ -567,37 +581,23 @@ int cmd_open(char *arg)
        }
     }
     base[0] = '\0';
-    if (!*arg || sscanf(arg, "%[^:]:%[^/]/%s", type, addr, base) < 2)
-    {
-        fprintf(stderr, "Usage: open (osi|tcp) ':' [tsel '/']host[':'port]\n");
-        return 0;
-    }
+    if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1)
+       return 0;
+    if (strncmp (type_and_host, "tcp:", 4) == 0)
+       host = type_and_host + 4;
+    else
+       host = type_and_host;
     if (*base)
         cmd_base (base);
-    if (!strcmp(type, "tcp"))
-    {
-       t = tcpip_type;
-       protocol = PROTO_Z3950;
-    }
-    else
-#ifdef USE_XTIMOSI
-    if (!strcmp(type, "osi"))
-    {
-        t = mosi_type;
-        protocol = PROTO_SR;
-    }
-    else
-#endif
-    {
-       fprintf(stderr, "Bad type: %s\n", type);
-       return 0;
-    }
+    t = tcpip_type;
+    protocol = PROTO_Z3950;
+
     if (!(conn = cs_create(t, 1, protocol)))
     {
         perror("cs_create");
         return 0;
     }
-    if (!(add = cs_straddr(conn, addr)))
+    if (!(add = cs_straddr(conn, host)))
     {
        perror(arg);
        return 0;
@@ -1259,11 +1259,7 @@ void process_ESResponse(Z_ExtendedServicesResponse *res)
 
 const char *get_ill_element (void *clientData, const char *element)
 {
-    /* printf ("asking for %s\n", element); */
-    if (!strcmp (element, "ill,transaction-id,transaction-group-qualifier"))
-       return "1";
-    if (!strcmp (element, "ill,transaction-id,transaction-qualifier"))
-       return "1";
+    printf ("%s\n", element);
     return 0;
 }
 
@@ -1280,7 +1276,9 @@ static Z_External *create_external_itemRequest()
     ctl.f = get_ill_element;
 
     req = ill_get_ItemRequest(&ctl, "ill", 0);
-
+    if (!req)
+        printf ("ill_get_ItemRequest failed\n");
+       
     if (!ill_ItemRequest (out, &req, 0, 0))
     {
        if (apdu_file)
@@ -1437,21 +1435,20 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno)
        (int *) odr_malloc(out, sizeof(int));
     *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
 
-    switch (*type)
+    if (!strcmp (type, "item") || !strcmp(type, "2"))
     {
-    case '2':
        printf ("using item-request\n");
        r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 
            create_external_itemRequest();
-       break;
-    case '1':
+    }
+    else if (!strcmp(type, "ill") || !strcmp(type, "1"))
+    {
        printf ("using ILL-request\n");
        r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 
            create_external_ILLRequest();
-       break;
-    default:
-       r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
     }
+    else
+       r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
     return r;
 }
 
@@ -2275,7 +2272,7 @@ static int client(int wait)
        {"attributeset", cmd_attributeset, "<attrset>"},
         {"querytype", cmd_querytype, "<type>"},
        {"refid", cmd_refid, "<id>"},
-       {"itemorder", cmd_itemorder, "1|2 <item>"},
+       {"itemorder", cmd_itemorder, "ill|item <itemno>"},
        {"update", cmd_update, "<item>"},
 #ifdef ASN_COMPILED
        /* Server Admin Functions */
@@ -2295,6 +2292,10 @@ static int client(int wait)
     int netbufferlen = 0;
     int i;
     Z_APDU *apdu;
+#if HAVE_GETTIMEOFDAY
+    struct timeval tv_start, tv_end;
+    gettimeofday (&tv_start, 0);
+#endif
 
     while (1)
     {
@@ -2341,6 +2342,10 @@ static int client(int wait)
            if ((end_p = strchr (line, '\n')))
                *end_p = '\0';
 #endif 
+#if HAVE_GETTIMEOFDAY
+           gettimeofday (&tv_start, 0);
+#endif
+
             if ((res = sscanf(line, "%s %[^;]", word, arg)) <= 0)
             {
                 strcpy(word, last_cmd);
@@ -2455,6 +2460,15 @@ static int client(int wait)
                 }
             }
             while (conn && cs_more(conn));
+#if HAVE_GETTIMEOFDAY
+           gettimeofday (&tv_end, 0);
+           if (1)
+           {
+               printf ("Elapsed: %.6f\n", (double) tv_end.tv_usec /
+                                                1e6 + tv_end.tv_sec -
+                  ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
+           }
+#endif
         }
     }
     return 0;
@@ -2493,10 +2507,10 @@ int main(int argc, char **argv)
                 apdu_file=fopen(arg, "a");
             break;
        case 'v':
-           log_init (log_mask_str(arg), "", NULL);
+           yaz_log_init (yaz_log_mask_str(arg), "", NULL);
            break;
         default:
-            fprintf (stderr, "Usage: %s [-m <marclog>] [ -m <apdulog>] "
+            fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
                              "[<server-addr>]\n",
                      prog);
             exit (1);