Added retrieval handling support in Generic Frontend Server to support
authorAdam Dickmeiss <adam@indexdata.dk>
Sun, 7 May 2006 14:48:24 +0000 (14:48 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Sun, 7 May 2006 14:48:24 +0000 (14:48 +0000)
conversion between MARC/XML as well as XSLTtransforms. See
etc/yazgfs.xml for an example.

NEWS
etc/yazgfs.xml
include/yaz/record_conv.h
include/yaz/retrieval.h
src/record_conv.c
src/retrieval.c
src/seshigh.c
src/session.h
src/statserv.c
test/tst_record_conv.c
test/tst_retrieval.c

diff --git a/NEWS b/NEWS
index 84b4304..2ea643a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Added retrieval handling support in Generic Frontend Server to support
+conversion between MARC/XML as well as XSLTtransforms. See
+etc/yazgfs.xml for an example.
+
 Added Authentication support to Generic Frontend Server in SRU
 mode. Authentication using HTTP Basic is supported, as is the use
 of 'x-username' and 'x-password' parameters in the request itself.
index 72f1272..3a14d25 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $Id: yazgfs.xml,v 1.2 2006-03-15 13:32:05 adam Exp $ -->
+<!-- $Id: yazgfs.xml,v 1.3 2006-05-07 14:48:24 adam Exp $ -->
 <!-- sample YAZ GFS config file .. see 
   http://indexdata.dk/yaz/doc/server.vhosts.tkl -->
 <yazgfs>
@@ -9,10 +9,38 @@
      <cql2rpn>pqf.properties</cql2rpn>
      <docpath>xsl</docpath>
      <stylesheet>xsl/default.xsl</stylesheet>
+     <retrievalinfo>
+       <retrieval syntax="usmarc" schema="F"/>
+       <retrieval syntax="usmarc" schema="B"/>
+       <retrieval syntax="xml" schema="marcxml"
+                 identifier="info:srw/schema/1/marcxml-v1.1"
+                 backendsyntax="usmarc" backendschema="F">
+        <convert>
+          <marc inputformat="marc" outputformat="marcxml"
+                inputcharset="marc-8"/>
+        </convert>
+       </retrieval>
+       <retrieval syntax="xml" schema="danmarc"
+                 backendsyntax="usmarc" backendschema="F">
+        <convert>
+          <marc inputformat="marc" outputformat="marcxchange"
+                inputcharset="marc-8"/>
+        </convert>
+       </retrieval>
+       <retrieval syntax="xml" schema="dc"
+                 identifier="info:srw/schema/1/dc-v1.1"
+                 backendsyntax="usmarc" backendschema="F">
+        <convert>
+          <marc inputformat="marc" outputformat="marcxml"
+                inputcharset="marc-8"/>
+          <xslt stylesheet="../etc/MARC21slim2DC.xsl"/>
+        </convert>
+       </retrieval>
+     </retrievalinfo>
      <explain xmlns="http://explain.z3950.org/dtd/2.0/">
         <serverInfo>
            <host>myserver.org</host>
-           <port>9900</port>
+           <port>9000</port>
            <database>Default</database>
         </serverInfo>
     </explain>
index 7595e65..0bbca68 100644 (file)
@@ -23,7 +23,7 @@
  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  * OF THIS SOFTWARE.
  *
- * $Id: record_conv.h,v 1.3 2006-05-04 20:00:45 adam Exp $
+ * $Id: record_conv.h,v 1.4 2006-05-07 14:48:24 adam Exp $
  */
 /**
  * \file record_conv.h
@@ -82,7 +82,8 @@ int yaz_record_conv_configure(yaz_record_conv_t p, const void *node);
 
 /** performs record conversion
     \param p record conversion handle
-    \param input_record record to be converted (0-terminated)
+    \param input_record_buf input record buffer
+    \param input_record_len length of input record buffer
     \param output_record resultint record (WRBUF string)
     \retval 0 success
     \retval -1 failure
@@ -90,7 +91,8 @@ int yaz_record_conv_configure(yaz_record_conv_t p, const void *node);
     On failure, use yaz_record_conv_get_error to get error string.
 */
 YAZ_EXPORT
-int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record,
+int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record_buf,
+                           size_t input_record_len,
                            WRBUF output_record);
 
 /** returns error string (for last error)
index dc4a1fe..9592bc0 100644 (file)
@@ -23,7 +23,7 @@
  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  * OF THIS SOFTWARE.
  *
- * $Id: retrieval.h,v 1.2 2006-05-05 18:37:08 adam Exp $
+ * $Id: retrieval.h,v 1.3 2006-05-07 14:48:24 adam Exp $
  */
 /**
  * \file retrieval.h
@@ -86,15 +86,27 @@ int yaz_retrieval_configure(yaz_retrieval_t p, const void *node);
 
 /** performs retrieval request based on schema and format
     \param p retrieval handle
-    \param schema record schema / element set name (Z39.50)
+    \param schema record schema (SRU) / element set name (Z39.50)
     \param syntax record syntax (format)
-    \param rc record conversion reference (holds conversion upon success)
-    \retval 0 success
-    \retval -1 falure
+    \param match_schema matched schema (if conversion was successful)
+    \param match_syntax matced syntax OID  if conversion was successful)
+    \param rc record conversion reference (if conversion was successful)
+    \param backend_schema backend scchema (if conversion was successful)
+    \param backend_syntax backend syntax (if conversion was successful)
+    \retval 0 success, schema and syntax matches
+    \retval -1 failure, use yaz_retrieval_get_error() for reason
+    \retval 1 schema does not match
+    \retval 2 syntax does not match
+    \retval 3 neither schema, nor syntax matches
+    \retval 4 both match but not together
 */
 YAZ_EXPORT
-int yaz_retrieval_request(yaz_retrieval_t p, const char *schema,
-                          const char *syntax, yaz_record_conv_t *rc);
+int yaz_retrieval_request(yaz_retrieval_t p,
+                          const char *schema, int *syntax,
+                          const char **match_schema, int **match_syntax,
+                          yaz_record_conv_t *rc,
+                          const char **backend_schema,
+                          int **backend_syntax);
 
 /** returns error string (for last error)
     \param p record conversion handle
index 2a60f21..ab530a5 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2005-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: record_conv.c,v 1.4 2006-05-04 20:00:45 adam Exp $
+ * $Id: record_conv.c,v 1.5 2006-05-07 14:48:25 adam Exp $
  */
 /**
  * \file record_conv.c
@@ -336,7 +336,9 @@ int yaz_record_conv_configure(yaz_record_conv_t p, const void *ptr_v)
     return 0;
 }
 
-int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record,
+int yaz_record_conv_record(yaz_record_conv_t p,
+                           const char *input_record_buf,
+                           size_t input_record_len,
                            WRBUF output_record)
 {
     int ret = 0;
@@ -344,7 +346,7 @@ int yaz_record_conv_record(yaz_record_conv_t p, const char *input_record,
     struct yaz_record_conv_rule *r = p->rules;
     wrbuf_rewind(p->wr_error);
     
-    wrbuf_puts(record, input_record);
+    wrbuf_write(record, input_record_buf, input_record_len);
     for (; ret == 0 && r; r = r->next)
     {
         if (r->which == YAZ_RECORD_CONV_RULE_XSLT)
index cc0b09b..4c2ee60 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2005-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: retrieval.c,v 1.2 2006-05-05 18:37:08 adam Exp $
+ * $Id: retrieval.c,v 1.3 2006-05-07 14:48:25 adam Exp $
  */
 /**
  * \file retrieval.c
@@ -19,6 +19,7 @@
 #include <yaz/xmalloc.h>
 #include <yaz/nmem.h>
 #include <yaz/tpath.h>
+#include <yaz/proto.h>
 
 #if HAVE_XSLT
 #include <libxml/parser.h>
 
 /** \brief The internal structure for yaz_retrieval_t */
 struct yaz_retrieval_struct {
-    /** \brief memory for configuration */
+    /** \brief ODR memory for configuration */
+    ODR odr;
+
+    /** \brief odr's NMEM memory (odr->mem) */
     NMEM nmem;
 
     /** \brief string buffer for error messages */
@@ -52,16 +56,16 @@ struct yaz_retrieval_elem {
     /** \brief schema short-hand (such sa "dc") */
     const char *schema;
     /** \brief record syntax */
-    const char *syntax;
+    int *syntax;
     /** \brief backend schema */
     const char *backend_schema;
     /** \brief backend syntax */
-    const char *backend_syntax;
+    int *backend_syntax;
 
     /** \brief record conversion */
     yaz_record_conv_t record_conv;
 
-    /** \breif next element in list */
+    /** \brief next element in list */
     struct yaz_retrieval_elem *next;
 };
 
@@ -70,7 +74,8 @@ static void yaz_retrieval_reset(yaz_retrieval_t p);
 yaz_retrieval_t yaz_retrieval_create()
 {
     yaz_retrieval_t p = xmalloc(sizeof(*p));
-    p->nmem = nmem_create();
+    p->odr = odr_createmem(ODR_ENCODE);
+    p->nmem = p->odr->mem;
     p->wr_error = wrbuf_alloc();
     p->list = 0;
     p->path = 0;
@@ -83,7 +88,7 @@ void yaz_retrieval_destroy(yaz_retrieval_t p)
     if (p)
     {
         yaz_retrieval_reset(p);
-        nmem_destroy(p->nmem);
+        odr_destroy(p->odr);
         wrbuf_free(p->wr_error, 1);
         xfree(p->path);
         xfree(p);
@@ -97,7 +102,7 @@ void yaz_retrieval_reset(yaz_retrieval_t p)
         yaz_record_conv_destroy(el->record_conv);
 
     wrbuf_rewind(p->wr_error);
-    nmem_reset(p->nmem);
+    odr_reset(p->odr);
 
     p->list = 0;
     p->list_p = &p->list;
@@ -122,8 +127,17 @@ static int conf_retrieval(yaz_retrieval_t p, const xmlNode *ptr)
     {
         if (!xmlStrcmp(attr->name, BAD_CAST "syntax") &&
             attr->children && attr->children->type == XML_TEXT_NODE)
-            el->syntax = 
-                nmem_strdup(p->nmem, (const char *) attr->children->content);
+        {
+            el->syntax = yaz_str_to_z3950oid(
+                p->odr, CLASS_RECSYN,
+                (const char *) attr->children->content);
+            if (!el->syntax)
+            {
+                wrbuf_printf(p->wr_error, "Bad syntax '%s'",
+                             (const char *) attr->children->content);
+                return -1;
+            }
+        }
         else if (!xmlStrcmp(attr->name, BAD_CAST "identifier") &&
             attr->children && attr->children->type == XML_TEXT_NODE)
             el->identifier =
@@ -138,25 +152,47 @@ static int conf_retrieval(yaz_retrieval_t p, const xmlNode *ptr)
                 nmem_strdup(p->nmem, (const char *) attr->children->content);
         else if (!xmlStrcmp(attr->name, BAD_CAST "backendsyntax") &&
                  attr->children && attr->children->type == XML_TEXT_NODE)
-            el->backend_syntax = 
-                nmem_strdup(p->nmem, (const char *) attr->children->content);
+        {
+            el->backend_syntax = yaz_str_to_z3950oid(
+                p->odr, CLASS_RECSYN,
+                (const char *) attr->children->content);
+            if (!el->backend_syntax)
+            {
+                wrbuf_printf(p->wr_error, "Bad backendsyntax '%s'",
+                             (const char *) attr->children->content);
+                return -1;
+            }
+        }
         else
         {
             wrbuf_printf(p->wr_error, "Bad attribute '%s'.", attr->name);
             return -1;
         }
     }
-    el->record_conv = yaz_record_conv_create();
-
-    yaz_record_conv_set_path(el->record_conv, p->path);
-    
-    if (yaz_record_conv_configure(el->record_conv, ptr->children))
+    if (!el->syntax)
     {
-        wrbuf_printf(p->wr_error, "%s",
-                     yaz_record_conv_get_error(el->record_conv));
-        yaz_record_conv_destroy(el->record_conv);
+        wrbuf_printf(p->wr_error, "Missing 'syntax' attribute.", attr->name);
         return -1;
     }
+
+    el->record_conv = 0; /* OK to have no 'convert' sub content */
+    for (ptr = ptr->children; ptr; ptr = ptr->next)
+    {
+        if (ptr->type == XML_ELEMENT_NODE)
+        {
+            el->record_conv = yaz_record_conv_create();
+            
+            yaz_record_conv_set_path(el->record_conv, p->path);
+        
+            if (yaz_record_conv_configure(el->record_conv, ptr))
+            {
+                wrbuf_printf(p->wr_error, "%s",
+                             yaz_record_conv_get_error(el->record_conv));
+                yaz_record_conv_destroy(el->record_conv);
+                return -1;
+            }
+        }
+    }
     
     *p->list_p = el;
     p->list_p = &el->next;
@@ -197,12 +233,58 @@ int yaz_retrieval_configure(yaz_retrieval_t p, const void *ptr_v)
     return 0;
 }
 
-int yaz_retrieval_request(yaz_retrieval_t p, const char *schema,
-                          const char *syntax, yaz_record_conv_t *rc)
+int yaz_retrieval_request(yaz_retrieval_t p,
+                          const char *schema, int *syntax,
+                          const char **match_schema, int **match_syntax,
+                          yaz_record_conv_t *rc,
+                          const char **backend_schema,
+                          int **backend_syntax)
 {
-    wrbuf_rewind(p->wr_error);
-    wrbuf_printf(p->wr_error, "yaz_retrieval_request: not implemented");
-    return -1;
+    struct yaz_retrieval_elem *el = p->list;
+
+    int syntax_matches = 0;
+    int schema_matches = 0;
+    for(; el; el = el->next)
+    {
+        int schema_ok = 0;
+        int syntax_ok = 0;
+
+        if (schema && el->schema && !strcmp(schema, el->schema))
+            schema_ok = 1;
+        if (schema && el->identifier && !strcmp(schema, el->identifier))
+            schema_ok = 1;
+        if (!schema)
+            schema_ok = 1;
+        
+        if (syntax && el->syntax && !oid_oidcmp(syntax, el->syntax))
+            syntax_ok = 1;
+        if (!syntax)
+            syntax_ok = 1;
+
+        if (syntax_ok)
+            syntax_matches++;
+        if (schema_ok)
+            schema_matches++;
+        if (syntax_ok && schema_ok)
+        {
+            *match_syntax = el->syntax;
+            *match_schema = el->schema;
+            if (backend_schema)
+                *backend_schema = el->backend_schema;
+            if (backend_syntax)
+                *backend_syntax = el->backend_syntax;
+            if (rc)
+                *rc = el->record_conv;
+            return 0;
+        }
+    }
+    if (syntax_matches && !schema_matches)
+        return 1;
+    if (!syntax_matches && schema_matches)
+        return 2;
+    if (!syntax_matches && !schema_matches)
+        return 3;
+    return 4;
 }
 
 const char *yaz_retrieval_get_error(yaz_retrieval_t p)
index 2c26626..6112316 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.76 2006-05-05 20:02:22 quinn Exp $
+ * $Id: seshigh.c,v 1.77 2006-05-07 14:48:25 adam Exp $
  */
 /**
  * \file seshigh.c
@@ -184,8 +184,7 @@ association *create_association(IOCHAN channel, COMSTACK link,
     request_initq(&anew->incoming);
     request_initq(&anew->outgoing);
     anew->proto = cs_getproto(link);
-    anew->cql_transform = 0;
-    anew->server_node_ptr = 0;
+    anew->server = 0;
     return anew;
 }
 
@@ -549,6 +548,143 @@ static int srw_bend_init(association *assoc, Z_SRW_diagnostic **d, int *num, Z_S
     return 1;
 }
 
+static const char *get_esn(Z_RecordComposition *comp)
+{
+    if (comp && comp->which == Z_RecordComp_complex)
+    {
+        if (comp->u.complex->generic 
+            && comp->u.complex->generic->elementSpec
+            && (comp->u.complex->generic->elementSpec->which == 
+                Z_ElementSpec_elementSetName))
+            return comp->u.complex->generic->elementSpec->u.elementSetName;
+    }
+    else if (comp && comp->which == Z_RecordComp_simple &&
+             comp->u.simple->which == Z_ElementSetNames_generic)
+        return comp->u.simple->u.generic;
+    return 0;
+}
+
+static void set_esn(Z_RecordComposition **comp_p, const char *esn, NMEM nmem)
+{
+    Z_RecordComposition *comp = nmem_malloc(nmem, sizeof(*comp));
+    
+    comp->which = Z_RecordComp_simple;
+    comp->u.simple = nmem_malloc(nmem, sizeof(*comp->u.simple));
+    comp->u.simple->which = Z_ElementSetNames_generic;
+    comp->u.simple->u.generic = nmem_strdup(nmem, esn);
+    *comp_p = comp;
+}
+
+static int retrieve_fetch(association *assoc, bend_fetch_rr *rr)
+{
+#if HAVE_XSLT
+    yaz_record_conv_t rc = 0;
+    const char *match_schema = 0;
+    int *match_syntax = 0;
+
+    if (assoc->server)
+    {
+        int r;
+        const char *input_schema = get_esn(rr->comp);
+        Odr_oid *input_syntax_raw = rr->request_format_raw;
+        
+        const char *backend_schema = 0;
+        Odr_oid *backend_syntax = 0;
+
+        r = yaz_retrieval_request(assoc->server->retrieval,
+                                  input_schema,
+                                  input_syntax_raw,
+                                  &match_schema,
+                                  &match_syntax,
+                                  &rc,
+                                  &backend_schema,
+                                  &backend_syntax);
+        if (r == -1) /* error ? */
+        {
+            const char *details = yaz_retrieval_get_error(
+                assoc->server->retrieval);
+
+            rr->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+            if (details)
+                rr->errstring = odr_strdup(rr->stream, details);
+            return -1;
+        }
+        else if (r == 1)
+        {
+            const char *details = input_schema;
+            rr->errcode =  YAZ_BIB1_ELEMENT_SET_NAMES_UNSUPP;
+            if (details)
+                rr->errstring = odr_strdup(rr->stream, details);
+            return -1;
+        }
+        else if (r == 2)
+        {
+            rr->errcode = YAZ_BIB1_RECORD_SYNTAX_UNSUPP;
+            return -1;
+        }
+        else if (r == 3)
+        {
+            const char *details = input_schema;
+            rr->errcode =  YAZ_BIB1_ELEMENT_SET_NAMES_UNSUPP;
+            if (details)
+                rr->errstring = odr_strdup(rr->stream, details);
+            return -1;
+        }
+        else if (r == 4)
+        {
+            rr->errcode = YAZ_BIB1_RECORD_NOT_AVAILABLE_IN_REQUESTED_SYNTAX; 
+            return -1;
+        }
+        if (backend_schema)
+        {
+            set_esn(&rr->comp, backend_schema, rr->stream->mem);
+        }
+        if (backend_syntax)
+        {
+            oident *oident_syntax = oid_getentbyoid(backend_syntax);
+
+            rr->request_format_raw = backend_syntax;
+            
+            if (oident_syntax)
+                rr->request_format = oident_syntax->value;
+            else
+                rr->request_format = VAL_NONE;
+        }
+    }
+    (*assoc->init->bend_fetch)(assoc->backend, rr);
+    if (rc && rr->record && rr->errcode == 0 && rr->len > 0)
+    {   /* post conversion must take place .. */
+        WRBUF output_record = wrbuf_alloc();
+        int r = yaz_record_conv_record(rc, rr->record, rr->len, output_record);
+        if (r)
+        {
+            const char *details = yaz_record_conv_get_error(rc);
+            rr->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+            if (details)
+                rr->errstring = odr_strdup(rr->stream, details);
+        }
+        else
+        {
+            rr->len = wrbuf_len(output_record);
+            rr->record = odr_malloc(rr->stream, rr->len);
+            memcpy(rr->record, wrbuf_buf(output_record), rr->len);
+        }
+        wrbuf_free(output_record, 1);
+    }
+    if (match_syntax)
+    {
+        struct oident *oi = oid_getentbyoid(match_syntax);
+        rr->output_format = oi ? oi->value : VAL_NONE;
+        rr->output_format_raw = match_syntax;
+    }
+    if (match_schema)
+        rr->schema = odr_strdup(rr->stream, match_schema);
+    return 0;
+#else
+    (*assoc->init->bend_fetch)(assoc->backend, rr);
+#endif
+}
+
 static int srw_bend_fetch(association *assoc, int pos,
                           Z_SRW_searchRetrieveRequest *srw_req,
                           Z_SRW_record *record)
@@ -612,7 +748,7 @@ static int srw_bend_fetch(association *assoc, int pos,
     if (!assoc->init->bend_fetch)
         return 1;
 
-    (*assoc->init->bend_fetch)(assoc->backend, &rr);
+    retrieve_fetch(assoc, &rr);
 
     if (rr.errcode && rr.surrogate_flag)
     {
@@ -756,10 +892,11 @@ static void srw_bend_search(association *assoc, request *req,
         
         if (srw_req->query_type == Z_SRW_query_type_cql)
         {
-            if (assoc->cql_transform)
+            if (assoc->server && assoc->server->cql_transform)
             {
                 int srw_errcode = cql2pqf(assoc->encode, srw_req->query.cql,
-                                          assoc->cql_transform, rr.query);
+                                          assoc->server->cql_transform,
+                                          rr.query);
                 if (srw_errcode)
                 {
                     yaz_add_srw_diagnostic(assoc->encode,
@@ -1015,7 +1152,10 @@ static void srw_bend_explain(association *assoc, request *req,
         rr.print = assoc->print;
         rr.explain_buf = 0;
         rr.database = srw_req->database;
-        rr.server_node_ptr = assoc->server_node_ptr;
+        if (assoc->server)
+            rr.server_node_ptr = assoc->server->server_node_ptr;
+        else
+            rr.server_node_ptr = 0;
         rr.schema = "http://explain.z3950.org/dtd/2.0/";
         if (assoc->init->bend_explain)
             (*assoc->init->bend_explain)(assoc->backend, &rr);
@@ -1113,7 +1253,8 @@ static void srw_bend_scan(association *assoc, request *req,
              (*assoc->init->bend_scan))(assoc->backend, bsrr);
         }
         else if (srw_req->query_type == Z_SRW_query_type_cql
-                 && assoc->init->bend_scan && assoc->cql_transform)
+                 && assoc->init->bend_scan && assoc->server
+                 && assoc->server->cql_transform)
         {
             int srw_error;
             bsrr->scanClause = 0;
@@ -1121,7 +1262,7 @@ static void srw_bend_scan(association *assoc, request *req,
             bsrr->term = odr_malloc(assoc->decode, sizeof(*bsrr->term));
             srw_error = cql2pqf_scan(assoc->encode,
                                      srw_req->scanClause.cql,
-                                     assoc->cql_transform,
+                                     assoc->server->cql_transform,
                                      bsrr->term);
             if (srw_error)
                 yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
@@ -1457,10 +1598,12 @@ static void process_http_request(association *assoc, request *req)
         p = z_get_HTTP_Response(o, 404);
         r = 1;
     }
-    if (r == 2 && assoc->docpath && hreq->path[0] == '/' 
+    if (r == 2 && assoc->server && assoc->server->docpath
+        && hreq->path[0] == '/' 
         && 
         /* check if path is a proper prefix of documentroot */
-        strncmp(hreq->path+1, assoc->docpath, strlen(assoc->docpath))
+        strncmp(hreq->path+1, assoc->server->docpath,
+                strlen(assoc->server->docpath))
         == 0)
     {   
         if (!check_path(hreq->path))
@@ -1617,8 +1760,8 @@ static void process_http_request(association *assoc, request *req)
             p = z_get_HTTP_Response(o, 200);
             hres = p->u.HTTP_Response;
 
-            if (!stylesheet)
-                stylesheet = assoc->stylesheet;
+            if (!stylesheet && assoc->server)
+                stylesheet = assoc->server->stylesheet;
 
             /* empty stylesheet means NO stylesheet */
             if (stylesheet && *stylesheet == '\0')
@@ -2098,7 +2241,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
                 assoc->init->implementation_name,
                 odr_prepend(assoc->encode, "GFS", resp->implementationName));
 
-    version = odr_strdup(assoc->encode, "$Revision: 1.76 $");
+    version = odr_strdup(assoc->encode, "$Revision: 1.77 $");
     if (strlen(version) > 10)   /* check for unexpanded CVS strings */
         version[strlen(version)-2] = '\0';
     resp->implementationVersion = odr_prepend(assoc->encode,
@@ -2262,7 +2405,8 @@ static Z_Records *pack_records(association *a, char *setname, int start,
         freq.print = a->print;
         freq.referenceId = referenceId;
         freq.schema = 0;
-        (*a->init->bend_fetch)(a->backend, &freq);
+
+        retrieve_fetch(a, &freq);
 
         *next = freq.last_in_set ? 0 : recno + 1;
 
@@ -2407,14 +2551,14 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb,
         bsrr->errstring = NULL;
         bsrr->search_info = NULL;
 
-        if (assoc->cql_transform &&
-            req->query->which == Z_Query_type_104 &&
-            req->query->u.type_104->which == Z_External_CQL)
+        if (assoc->server && assoc->server->cql_transform 
+            && req->query->which == Z_Query_type_104
+            && req->query->u.type_104->which == Z_External_CQL)
         {
             /* have a CQL query and a CQL to PQF transform .. */
             int srw_errcode = 
                 cql2pqf(bsrr->stream, req->query->u.type_104->u.cql,
-                        assoc->cql_transform, bsrr->query);
+                        assoc->server->cql_transform, bsrr->query);
             if (srw_errcode)
                 bsrr->errcode = yaz_diag_srw_to_bib1(srw_errcode);
         }
index b3f044a..6ac5299 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Copyright (C) 1995-2005, Index Data ApS
+ * Copyright (C) 1995-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: session.h,v 1.10 2006-03-15 13:32:05 adam Exp $
+ * $Id: session.h,v 1.11 2006-05-07 14:48:25 adam Exp $
  */
 /**
  * \file session.h
@@ -17,6 +17,7 @@
 #include <yaz/oid.h>
 #include <yaz/proto.h>
 #include <yaz/backend.h>
+#include <yaz/retrieval.h>
 #include "eventl.h"
 
 struct gfs_server {
@@ -28,6 +29,7 @@ struct gfs_server {
     char *directory;
     char *docpath;
     char *stylesheet;
+    yaz_retrieval_t retrieval;
     struct gfs_server *next;
 };
 
@@ -109,10 +111,8 @@ typedef struct association
 
     struct bend_initrequest *init;
     statserv_options_block *last_control;
-    cql_transform_t cql_transform;
-    void *server_node_ptr;
-    const char *docpath;
-    const char *stylesheet;
+
+    struct gfs_server *server;
 } association;
 
 association *create_association(IOCHAN channel, COMSTACK link,
index 2ab5b9e..94382c7 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (C) 1995-2005, Index Data ApS
+ * Copyright (C) 1995-2006, Index Data ApS
  * See the file LICENSE for details.
  *
  * NT threaded server code by
  *   Chas Woodfield, Fretwell Downing Informatics.
  *
- * $Id: statserv.c,v 1.36 2006-03-22 17:58:32 mike Exp $
+ * $Id: statserv.c,v 1.37 2006-05-07 14:48:25 adam Exp $
  */
 
 /**
@@ -222,6 +222,9 @@ static struct gfs_server * gfs_server_new()
     n->directory = 0;
     n->docpath = 0;
     n->stylesheet = 0;
+#if HAVE_XSLT
+    n->retrieval = yaz_retrieval_create();
+#endif
     return n;
 }
 
@@ -265,10 +268,7 @@ int control_association(association *assoc, const char *host, int force_open)
             *cp = '\0';
         host = vhost;
     }
-    assoc->cql_transform = 0;
-    assoc->server_node_ptr = 0;
-    assoc->docpath = 0;
-    assoc->stylesheet = 0;
+    assoc->server = 0;
     if (control_block.xml_config[0])
     {
         struct gfs_server *gfs;
@@ -296,10 +296,7 @@ int control_association(association *assoc, const char *host, int force_open)
                     xfree(assoc->init);
                     assoc->init = 0;
                 }
-                assoc->docpath = gfs->docpath;
-                assoc->stylesheet = gfs->stylesheet;
-                assoc->cql_transform = gfs->cql_transform;
-                assoc->server_node_ptr = gfs->server_node_ptr;
+                assoc->server = gfs;
                 assoc->last_control = &gfs->cb;
                 statserv_setcontrol(&gfs->cb);
                 gfs_server_chdir(gfs);
@@ -430,6 +427,16 @@ static void xml_config_read()
                 {
                     ; /* being processed separately */
                 }
+                else if (!strcmp((const char *) ptr->name, "retrievalinfo"))
+                {
+                    if (yaz_retrieval_configure((*gfsp)->retrieval, ptr))
+                    {       
+                        yaz_log(YLOG_FATAL, "%s in config %s",
+                                yaz_retrieval_get_error((*gfsp)->retrieval),
+                                control_block.xml_config);
+                        exit(1);
+                    }
+                }
                 else
                 {
                     yaz_log(YLOG_FATAL, "Unknown element '%s' in config %s",
index c6d9ac0..fbd218a 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2005-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: tst_record_conv.c,v 1.5 2006-05-05 18:37:08 adam Exp $
+ * $Id: tst_record_conv.c,v 1.6 2006-05-07 14:48:25 adam Exp $
  *
  */
 #include <yaz/record_conv.h>
@@ -143,7 +143,8 @@ static int conv_convert_test(yaz_record_conv_t p,
     else
     {
         WRBUF output_record = wrbuf_alloc();
-        int r = yaz_record_conv_record(p, input_record, output_record);
+        int r = yaz_record_conv_record(p, input_record, strlen(input_record),
+                                       output_record);
         if (r)
         {
             if (output_expect_record)
index aecb773..cea9da0 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2005-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: tst_retrieval.c,v 1.2 2006-05-05 18:37:08 adam Exp $
+ * $Id: tst_retrieval.c,v 1.3 2006-05-07 14:48:25 adam Exp $
  *
  */
 #include <yaz/retrieval.h>
@@ -116,8 +116,12 @@ static void tst_configure()
                                   "Bad element 'bad'."
                                   " Expected 'retrieval'", 0));
 
+    YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
+                                  "</retrievalinfo>", 0, 0));
+
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval>"
+                                  "<retrieval>\n"
+                                  "  "
                                   "<convert>"
                                   "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
                                   "<marc"
@@ -156,6 +160,37 @@ static void tst_configure()
                                   "</retrieval>"
                                   "</retrievalinfo>",
                                   0, 0));
+
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " schema=\"marcxml\"" 
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                  ">"
+                                  "<convert/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"unknown_synt\""
+                                  ">"
+                                  "<convert/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Bad syntax 'unknown_synt'", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " backendsyntax=\"unknown_synt\""
+                                  ">"
+                                  "<convert/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Bad backendsyntax 'unknown_synt'", 0));
+
 }
 
 #endif