GFS: client_query_charset conversion YAZ-777
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 11 Jul 2014 12:23:37 +0000 (14:23 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 11 Jul 2014 12:23:37 +0000 (14:23 +0200)
This is a feature for Z39.50 clients that sends queries that are not
UTF-8 encoded. WIth client_query_charset, GFS will convert from the
encoding given to UTF-8.

doc/gfs-virtual.xml
etc/yazgfs.xml
src/seshigh.c
src/session.h
src/statserv.c

index 11125f3..66f0bd8 100644 (file)
    </listitem>
   </varlistentry>
 
+  <varlistentry><term>element <literal>client_query_charset</literal> (optional)</term>
+   <listitem>
+    <para>
+     If specified, a conversion from the character set given to UTF-8 is
+     performed by the generic frontend server. It is only executed for
+     Z39.50 search requests (SRU/Solr are assumed to be UTF-8 encoded already).
+    </para>
+   </listitem>
+  </varlistentry>
+
   <varlistentry><term>element <literal>docpath</literal> (optional)</term>
    <listitem>
     <para>
index e498549..c3215cd 100644 (file)
@@ -7,6 +7,7 @@
      <config>zebra.cfg</config>
      <cql2rpn>pqf.properties</cql2rpn>
      <docpath>xsl</docpath>
+     <client_query_charset>iso-8859-1</client_query_charset>
      <stylesheet>xsl/default.xsl</stylesheet>
      <maximumrecordsize>2000000</maximumrecordsize>
      <retrievalinfo>
index eb99a79..6e18d01 100644 (file)
@@ -74,7 +74,7 @@
 #include <yaz/yaz-util.h>
 #include <yaz/pquery.h>
 #include <yaz/oid_db.h>
-
+#include <yaz/query-charset.h>
 #include <yaz/srw.h>
 #include <yaz/backend.h>
 #include <yaz/yaz-ccl.h>
@@ -2707,6 +2707,19 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb)
             bsrr->search_input = req->otherInfo;
         bsrr->present_number = *req->mediumSetPresentNumber;
 
+        if (assoc->server && assoc->server->client_query_charset &&
+            req->query->which == Z_Query_type_1)
+        {
+            yaz_iconv_t cd =
+                yaz_iconv_open("UTF-8", assoc->server->client_query_charset);
+            if (cd)
+            {
+                yaz_query_charset_convert_rpnquery(req->query->u.type_1,
+                                                   assoc->decode, cd);
+                yaz_iconv_close(cd);
+            }
+        }
+
         if (assoc->server && assoc->server->cql_transform
             && req->query->which == Z_Query_type_104
             && req->query->u.type_104->which == Z_External_CQL)
index 56b10b4..61bf84d 100644 (file)
@@ -51,6 +51,7 @@ struct gfs_server {
     char *directory;
     char *docpath;
     char *stylesheet;
+    char *client_query_charset;
     yaz_retrieval_t retrieval;
     struct gfs_server *next;
 };
index 59bb868..815b2e9 100644 (file)
@@ -226,6 +226,7 @@ static struct gfs_server * gfs_server_new(const char *id)
     n->directory = 0;
     n->docpath = 0;
     n->stylesheet = 0;
+    n->client_query_charset = 0;
     n->id = nmem_strdup_null(gfs_nmem, id);
     n->retrieval = yaz_retrieval_create();
     return n;
@@ -490,6 +491,12 @@ static void xml_config_read(const char *base_path)
                         nmem_malloc(gfs_nmem, strlen(s) + 2);
                     sprintf(gfs->stylesheet, "/%s", s);
                 }
+                else if (!strcmp((const char *) ptr->name,
+                                 "client_query_charset"))
+                {
+                    gfs->client_query_charset =
+                        nmem_dup_xml_content(gfs_nmem, ptr->children);
+                }
                 else if (!strcmp((const char *) ptr->name, "explain"))
                 {
                     ; /* being processed separately */