Happy new year
[yaz-moved-to-github.git] / client / client.c
index d4bd50e..e8a3289 100644 (file)
@@ -1,10 +1,13 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
+ * Copyright (C) 1995-2011 Index Data
  * See the file LICENSE for details.
  */
 /** \file client.c
  *  \brief yaz-client program
  */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -284,7 +287,7 @@ int send_apdu(Z_APDU *a)
     do_hex_dump(buf, len);
     if (cs_put(conn, buf, len) < 0)
     {
-        fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn)));
+        fprintf(stderr, "cs_put: %s\n", cs_errmsg(cs_errno(conn)));
         close_session();
         return 0;
     }
@@ -1284,7 +1287,7 @@ static int send_srw_host_path(Z_SRW_PDU *sr, const char *host_port,
     }
     else if (!yaz_matchstr(sru_method, "solr"))
     {
-        yaz_solr_encode(gdu->u.HTTP_Request, sr, out, charset);
+        yaz_solr_encode_request(gdu->u.HTTP_Request, sr, out, charset);
     }
 
     return send_gdu(gdu);
@@ -1455,7 +1458,7 @@ static int send_SRW_searchRequest(const char *arg)
         return 0;
     }
     sr->u.request->maximumRecords = odr_intdup(out, 0);
-
+    sr->u.request->facetList = facet_list;
     if (record_schema)
         sr->u.request->recordSchema = record_schema;
     if (recordsyntax_size == 1 && !yaz_matchstr(recordsyntax_list[0], "xml"))
@@ -2280,6 +2283,22 @@ static int only_z3950(void)
     return 0;
 }
 
+static int is_SRW(void)
+{
+    if (!conn)
+    {
+        printf("Not connected yet\n");
+        return 1;
+    }
+    if (protocol == PROTO_HTTP && yaz_matchstr(sru_method, "solr"))
+    {
+        printf("Not supported by SRW\n");
+        return 1;
+    }
+    return 0;
+}
+
+
 static int cmd_update_common(const char *arg, int version);
 
 static int cmd_update(const char *arg)
@@ -2887,6 +2906,8 @@ static int cmd_find(const char *arg)
 
 static int cmd_facets(const char *arg)
 {
+    /* TODO Wrong odr. Loosing memory */
+    ODR odr = odr_createmem(ODR_ENCODE);
     int size = 0;
     if (!*arg)
     {
@@ -2895,25 +2916,17 @@ static int cmd_facets(const char *arg)
         return 0;
     }
     size = strlen(arg);
-    if (only_z3950())
-    {
-        printf("Currently only supported for Z39.50.\n");
-        return 0;
+    if (is_SRW()) {
+        printf("WARN: No supported for SRW/SRU.\n");
     }
-    else
-    {
-        /* TODO Wrong odr. Loosing memory */
-        ODR odr = odr_createmem(ODR_ENCODE);
-        facet_list = yaz_pqf_parse_facet_list(odr, arg);
+    facet_list = yaz_pqf_parse_facet_list(odr, arg);
 
-        if (!facet_list)
-        {
-            printf("Invalid facet list: %s", arg);
-            return 0;
-        }
-        return 1;
+    if (!facet_list)
+    {
+        printf("Invalid facet list: %s", arg);
+        return 0;
     }
-    return 2;
+    return 1;
 }
 
 
@@ -4305,6 +4318,9 @@ static void handle_srw_response(Z_SRW_searchRetrieveResponse *res)
     }
     if (res->numberOfRecords)
         printf("Number of hits: " ODR_INT_PRINTF "\n", *res->numberOfRecords);
+    if (res->facetList) {
+        display_facets(res->facetList);
+    }
     for (i = 0; i<res->num_records; i++)
         handle_srw_record(res->records + i);
 }