Added support for SRW scan in yaz-client
authorAdam Dickmeiss <adam@indexdata.dk>
Sat, 8 Jan 2005 01:20:18 +0000 (01:20 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Sat, 8 Jan 2005 01:20:18 +0000 (01:20 +0000)
NEWS
client/client.c
configure.in
include/yaz/srw.h
src/srw.c
src/srwutil.c

diff --git a/NEWS b/NEWS
index 7e753de..e06f81e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 Possible compatibility problems with earlier versions marked with '*'.
 
---- IN PROGRESS
+Added support for SRW scan in yaz-client.
+
+* Changed Z_SRW_scanRequest to be able to carry both CCL and PQF.
 
 Fixed NMEM system to return aligned blocks on the smallest boundaries
 that are suitably aligned for all possible types on the particular
index a79c51c..b925810 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: client.c,v 1.264 2005-01-02 20:31:39 adam Exp $
+ * $Id: client.c,v 1.265 2005-01-08 01:20:18 adam Exp $
  */
 
 #include <stdio.h>
@@ -1253,6 +1253,32 @@ static int send_srw(Z_SRW_PDU *sr)
 #endif
 
 #if HAVE_XML2
+static int send_SRW_scanRequest(const char *arg, int num, int pos)
+{
+    Z_SRW_PDU *sr = 0;
+    
+    /* regular request .. */
+    sr = yaz_srw_get(out, Z_SRW_scan_request);
+
+    switch(queryType)
+    {
+    case QueryType_CQL:
+       sr->u.scan_request->query_type = Z_SRW_query_type_cql;
+       sr->u.scan_request->scanClause.cql = odr_strdup(out, arg);
+       break;
+    case QueryType_Prefix:
+       sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
+       sr->u.scan_request->scanClause.pqf = odr_strdup(out, arg);
+       break;
+    default:
+       printf ("Only CQL and PQF supported in SRW\n");
+       return 0;
+    }
+    sr->u.scan_request->responsePosition = odr_intdup(out, pos);
+    sr->u.scan_request->maximumTerms = odr_intdup(out, num);
+    return send_srw(sr);
+}
+
 static int send_SRW_searchRequest(const char *arg)
 {
     Z_SRW_PDU *sr = 0;
@@ -2823,34 +2849,49 @@ int cmd_scanpos(const char *arg)
 
 int cmd_scan(const char *arg)
 {
-    if (only_z3950())
-       return 0;
-    if (!conn)
+    if (protocol == PROTO_HTTP)
     {
-        try_reconnect();
-        
-        if (!conn) {                                                           
-            printf("Session not initialized yet\n");
+#if HAVE_XML2
+        if (!conn)
+            cmd_open(0);
+       if (!conn)
+           return 0;
+        if (send_SRW_scanRequest(arg, 20, 0) < 0)
             return 0;
-        }
-    }
-    if (!ODR_MASK_GET(session->options, Z_Options_scan))
-    {
-        printf("Target doesn't support scan\n");
+       return 2;
+#else
         return 0;
-    }
-    if (*arg)
-    {
-        strcpy (last_scan_query, arg);
-        if (send_scanrequest(arg, scan_position, 20, 0) < 0)
-            return 0;
+#endif
     }
     else
     {
-        if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0)
-            return 0;
+       if (!conn)
+       {
+           try_reconnect();
+           
+           if (!conn) {                                                                
+               printf("Session not initialized yet\n");
+               return 0;
+           }
+       }
+       if (!ODR_MASK_GET(session->options, Z_Options_scan))
+       {
+           printf("Target doesn't support scan\n");
+           return 0;
+       }
+       if (*arg)
+       {
+           strcpy (last_scan_query, arg);
+           if (send_scanrequest(arg, scan_position, 20, 0) < 0)
+               return 0;
+       }
+       else
+       {
+           if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0)
+               return 0;
+       }
+       return 2;
     }
-    return 2;
 }
 
 int cmd_schema(const char *arg)
@@ -3476,6 +3517,40 @@ static void handle_srw_response(Z_SRW_searchRetrieveResponse *res)
        handle_srw_record(res->records + i);
 }
 
+static void handle_srw_scan_term(Z_SRW_scanTerm *term)
+{
+    if (term->displayTerm)
+       printf ("%s: ", term->displayTerm);
+    if (term->value)
+       printf ("%s: ", term->value);
+    if (term->numberOfRecords)
+       printf ("%d", *term->numberOfRecords);
+    printf("\n");
+}
+
+static void handle_srw_scan_response(Z_SRW_scanResponse *res)
+{
+    int i;
+
+    printf ("Received SRW Scan Response\n");
+    
+    for (i = 0; i<res->num_diagnostics; i++)
+    {
+       if (res->diagnostics[i].uri)
+           printf ("SRW diagnostic %s\n",
+                   res->diagnostics[i].uri);
+       else
+           printf ("SRW diagnostic missing or could not be decoded\n");
+       if (res->diagnostics[i].message)
+            printf ("Message: %s\n", res->diagnostics[i].message);
+       if (res->diagnostics[i].details)
+            printf ("Details: %s\n", res->diagnostics[i].details);
+    }
+    if (res->terms)
+       for (i = 0; i<res->num_terms; i++)
+           handle_srw_scan_term(res->terms + i);
+}
+
 static void http_response(Z_HTTP_Response *hres)
 {
     int ret = -1;
@@ -3503,6 +3578,8 @@ static void http_response(Z_HTTP_Response *hres)
                 handle_srw_response(sr->u.response);
             else if (sr->which == Z_SRW_explain_response)
                 handle_srw_explain_response(sr->u.explain_response);
+            else if (sr->which == Z_SRW_scan_response)
+                handle_srw_scan_response(sr->u.scan_response);
             else
                 ret = -1;
         }
index 8e0cc7d..d22d952 100644 (file)
@@ -1,6 +1,6 @@
 dnl YAZ Toolkit, Index Data 1994-2004
 dnl See the file LICENSE for details.
-dnl $Id: configure.in,v 1.165 2005-01-05 10:23:41 adam Exp $
+dnl $Id: configure.in,v 1.166 2005-01-08 01:20:18 adam Exp $
 AC_INIT(include/yaz/yaz-version.h)
 AM_INIT_AUTOMAKE(yaz, 2.0.31)
 AM_MAINTAINER_MODE
@@ -19,6 +19,13 @@ AC_PATH_PROG(pkgconfigpath, pkg-config, NONE)
 dnl
 YAZ_DOC
 dnl 
+dnl
+dnl ------ Headers
+AC_CHECK_HEADERS(fnmatch.h wchar.h locale.h langinfo.h)
+AC_HEADER_STDC
+if test "$ac_cv_header_stdc" = "no"; then
+       AC_MSG_WARN(Your system doesn't seem to support ANSI C)
+fi
 dnl ----- Types
 AC_CHECK_TYPES([long long])
 dnl
@@ -237,13 +244,6 @@ if test "$enable_tcpd" -a "$enable_tcpd" != "no"; then
        fi
 fi
 dnl
-dnl ------ Headers
-AC_CHECK_HEADERS(fnmatch.h wchar.h locale.h langinfo.h)
-AC_STDC_HEADERS
-if test "$ac_cv_header_stdc" = "no"; then
-       AC_MSG_WARN(Your system doesn't seem to support ANSI C)
-fi
-dnl
 AC_SUBST(LIBTHREAD)
 AC_SUBST(CFLAGSTHREADS)
 HAVETHREADS=0
index 36f08b3..df27631 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.h,v 1.17 2004-10-15 00:18:59 adam Exp $
+ * $Id: srw.h,v 1.18 2005-01-08 01:20:18 adam Exp $
  */
 /**
  * \file srw.h
@@ -90,7 +90,12 @@ typedef struct {
 } Z_SRW_explainResponse;
     
 typedef struct {
-    char *scanClause;
+    int query_type;
+    union {
+        char *cql;
+        char *xcql;
+        char *pqf;
+    } scanClause;
     int *responsePosition;
     int *maximumTerms;
     char *stylesheet;
index 07ecccf..0461f2f 100644 (file)
--- a/src/srw.c
+++ b/src/srw.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.c,v 1.28 2004-10-31 19:23:22 adam Exp $
+ * $Id: srw.c,v 1.29 2005-01-08 01:20:19 adam Exp $
  */
 /**
  * \file srw.c
@@ -605,11 +605,12 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
             (*p)->which = Z_SRW_scan_request;
             req = (*p)->u.scan_request = (Z_SRW_scanRequest *)
                odr_malloc(o, sizeof(*req));
-           req->database = 0;
-           req->scanClause = 0;
-           req->stylesheet = 0;
+           req->query_type = Z_SRW_query_type_cql;
+           req->scanClause.cql = 0;
            req->responsePosition = 0;
            req->maximumTerms = 0;
+           req->stylesheet = 0;
+           req->database = 0;
            
            for (; ptr; ptr = ptr->next)
            {
@@ -617,7 +618,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                                     &(*p)->srw_version))
                    ;
                else if (match_xsd_string(ptr, "scanClause", o,
-                                    &req->scanClause))
+                                    &req->scanClause.cql))
                    ;
                else if (match_xsd_integer(ptr, "responsePosition", o,
                                           &req->responsePosition))
@@ -782,7 +783,15 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
            xmlSetNs(ptr, ns_srw);
 
            add_xsd_string(ptr, "version", (*p)->srw_version);
-           add_xsd_string(ptr, "scanClause", req->scanClause);
+           switch(req->query_type)
+           {
+           case Z_SRW_query_type_cql:
+               add_xsd_string(ptr, "scanClause", req->scanClause.cql);
+               break;
+           case Z_SRW_query_type_pqf:
+               add_xsd_string(ptr, "pScanClause", req->scanClause.pqf);
+               break;
+           }
            add_xsd_integer(ptr, "responsePosition", req->responsePosition);
            add_xsd_integer(ptr, "maximumTerms", req->maximumTerms);
            add_xsd_string(ptr, "stylesheet", req->stylesheet);
index 6976bfc..d34f6de 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srwutil.c,v 1.19 2004-11-21 21:56:28 adam Exp $
+ * $Id: srwutil.c,v 1.20 2005-01-08 01:20:19 adam Exp $
  */
 /**
  * \file srwutil.c
@@ -256,6 +256,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
        char *sortKeys = 0;
        char *stylesheet = 0;
        char *scanClause = 0;
+       char *pScanClause = 0;
        char *recordXPath = 0;
        char *recordSchema = 0;
        char *recordPacking = "xml";  /* xml packing is default for SRU */
@@ -306,6 +307,8 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                    version = v;
                else if (!strcmp(n, "scanClause"))
                    scanClause = v;
+               else if (!strcmp(n, "x-ScanClause"))
+                   pScanClause = v;
                else if (!strcmp(n, "maximumRecords"))
                    maximumRecords = v;
                else if (!strcmp(n, "startRecord"))
@@ -409,12 +412,21 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
        {
             Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_scan_request);
 
-           if (!scanClause)
+            if (scanClause)
+            {
+                sr->u.scan_request->query_type = Z_SRW_query_type_cql;
+               sr->u.scan_request->scanClause.cql = scanClause;
+            }
+            else if (pScanClause)
+            {
+                sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
+                sr->u.scan_request->scanClause.pqf = pScanClause;
+            }
+           else
                yaz_add_srw_diagnostic(decode, diag, num_diag, 7,
                                       "scanClause");
            sr->srw_version = version;
            *srw_pdu = sr;
-            sr->u.scan_request->scanClause = scanClause;
            sr->u.scan_request->database = db;
             sr->u.scan_request->stylesheet = stylesheet;
 
@@ -529,7 +541,8 @@ Z_SRW_PDU *yaz_srw_get(ODR o, int which)
        sr->u.scan_request->stylesheet = 0;
        sr->u.scan_request->maximumTerms = 0;
        sr->u.scan_request->responsePosition = 0;
-       sr->u.scan_request->scanClause = 0;
+       sr->u.scan_request->query_type = Z_SRW_query_type_cql;
+       sr->u.scan_request->scanClause.cql = 0;
         break;
     case Z_SRW_scan_response:
         sr->u.scan_response = (Z_SRW_scanResponse *)