Added explain facility for frontend server XML config. Renamed
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 3 Mar 2005 23:16:20 +0000 (23:16 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 3 Mar 2005 23:16:20 +0000 (23:16 +0000)
element cql2pqf to cql2rpn.

include/yaz/backend.h
src/seshigh.c
src/session.h
src/statserv.c
ztest/config1.xml
ztest/ztest.c

index c0f75da..e05b8e1 100644 (file)
@@ -23,7 +23,7 @@
  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  * OF THIS SOFTWARE.
  *
- * $Id: backend.h,v 1.29 2005-02-01 14:46:47 adam Exp $
+ * $Id: backend.h,v 1.30 2005-03-03 23:16:20 adam Exp $
  */
 
 /** 
@@ -201,6 +201,7 @@ typedef struct {
     char *explain_buf;
     char *database;
     char *schema;
+    void *server_node_ptr;
 } bend_explain_rr;
 
 typedef struct bend_initrequest
index 4a3766f..c812921 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.48 2005-03-01 20:37:01 adam Exp $
+ * $Id: seshigh.c,v 1.49 2005-03-03 23:16:20 adam Exp $
  */
 /**
  * \file seshigh.c
 #include <unistd.h>
 #endif
 
+#if HAVE_XML2
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#endif
+
 #include <yaz/yconfig.h>
 #include <yaz/xmalloc.h>
 #include <yaz/comstack.h>
@@ -178,6 +183,7 @@ association *create_association(IOCHAN channel, COMSTACK link,
     request_initq(&anew->outgoing);
     anew->proto = cs_getproto(link);
     anew->cql_transform = 0;
+    anew->server_node_ptr = 0;
     return anew;
 }
 
@@ -908,6 +914,39 @@ static void srw_bend_search(association *assoc, request *req,
     }
 }
 
+static char *srw_bend_explain_default(void *handle, bend_explain_rr *rr)
+{
+    xmlNodePtr ptr = rr->server_node_ptr;
+    if (!ptr)
+       return 0;
+    for (ptr = ptr->children; ptr; ptr = ptr->next)
+    {
+       if (ptr->type != XML_ELEMENT_NODE)
+           continue;
+       if (!strcmp((const char *) ptr->name, "explain"))
+       {
+           int len;
+           ptr = xmlCopyNode(ptr, 1);
+
+           xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
+        
+           xmlDocSetRootElement(doc, ptr);
+           
+           xmlChar *buf_out;
+           xmlDocDumpMemory(doc, &buf_out, &len);
+           char *content = (char*) odr_malloc(rr->stream, 1+len);
+           memcpy(content, buf_out, len);
+           content[len] = '\0';
+           
+           xmlFree(buf_out);
+           xmlFreeDoc(doc);
+           rr->explain_buf = content;
+           return 0;
+       }
+    }
+    return 0;
+}
+
 static void srw_bend_explain(association *assoc, request *req,
                              Z_SRW_explainRequest *srw_req,
                              Z_SRW_explainResponse *srw_res,
@@ -916,30 +955,35 @@ static void srw_bend_explain(association *assoc, request *req,
     yaz_log(log_requestdetail, "Got SRW ExplainRequest");
     *http_code = 404;
     srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
-    if (assoc->init && assoc->init->bend_explain)
-    {
-        bend_explain_rr rr;
-
-        rr.stream = assoc->encode;
-        rr.decode = assoc->decode;
-        rr.print = assoc->print;
-        rr.explain_buf = 0;
-        rr.database = srw_req->database;
-        rr.schema = "http://explain.z3950.org/dtd/2.0/";
-        (*assoc->init->bend_explain)(assoc->backend, &rr);
-        if (rr.explain_buf)
-        {
-            int packing = Z_SRW_recordPacking_string;
-            if (srw_req->recordPacking && 
-                !strcmp(srw_req->recordPacking, "xml"))
-                packing = Z_SRW_recordPacking_XML;
-            srw_res->record.recordSchema = rr.schema;
-            srw_res->record.recordPacking = packing;
-            srw_res->record.recordData_buf = rr.explain_buf;
-            srw_res->record.recordData_len = strlen(rr.explain_buf);
-            srw_res->record.recordPosition = 0;
-            *http_code = 200;
-        }
+    if (assoc->init)
+    {
+       bend_explain_rr rr;
+       
+       rr.stream = assoc->encode;
+       rr.decode = assoc->decode;
+       rr.print = assoc->print;
+       rr.explain_buf = 0;
+       rr.database = srw_req->database;
+       rr.server_node_ptr = assoc->server_node_ptr;
+       rr.schema = "http://explain.z3950.org/dtd/2.0/";
+       if (assoc->init->bend_explain)
+           (*assoc->init->bend_explain)(assoc->backend, &rr);
+       else
+           srw_bend_explain_default(assoc->backend, &rr);
+
+       if (rr.explain_buf)
+       {
+           int packing = Z_SRW_recordPacking_string;
+           if (srw_req->recordPacking && 
+               !strcmp(srw_req->recordPacking, "xml"))
+               packing = Z_SRW_recordPacking_XML;
+           srw_res->record.recordSchema = rr.schema;
+           srw_res->record.recordPacking = packing;
+           srw_res->record.recordData_buf = rr.explain_buf;
+           srw_res->record.recordData_len = strlen(rr.explain_buf);
+           srw_res->record.recordPosition = 0;
+           *http_code = 200;
+       }
     }
 }
 
@@ -1712,7 +1756,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.48 $");
+    version = odr_strdup(assoc->encode, "$Revision: 1.49 $");
     if (strlen(version) > 10)   /* check for unexpanded CVS strings */
         version[strlen(version)-2] = '\0';
     resp->implementationVersion = odr_prepend(assoc->encode,
index 96a32e0..69b1add 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: session.h,v 1.6 2005-03-01 20:37:01 adam Exp $
+ * $Id: session.h,v 1.7 2005-03-03 23:16:20 adam Exp $
  */
 /**
  * \file session.h
@@ -24,6 +24,7 @@ struct gfs_server {
     char *host;
     int listen_ref;
     cql_transform_t cql_transform;
+    void *server_node_ptr;
     struct gfs_server *next;
 };
 
@@ -106,6 +107,7 @@ typedef struct association
     struct bend_initrequest *init;
     statserv_options_block *last_control;
     cql_transform_t cql_transform;
+    void *server_node_ptr;
 } association;
 
 association *create_association(IOCHAN channel, COMSTACK link,
index aceecbf..67152e6 100644 (file)
@@ -5,7 +5,7 @@
  * NT threaded server code by
  *   Chas Woodfield, Fretwell Downing Informatics.
  *
- * $Id: statserv.c,v 1.23 2005-03-01 20:37:01 adam Exp $
+ * $Id: statserv.c,v 1.24 2005-03-03 23:16:20 adam Exp $
  */
 
 /**
@@ -212,6 +212,7 @@ static struct gfs_server * gfs_server_new()
     n->host = 0;
     n->listen_ref = 0;
     n->cql_transform = 0;
+    n->server_node_ptr = 0;
     return n;
 }
 
@@ -265,6 +266,7 @@ int control_association(association *assoc, const char *host, int force_open)
                    assoc->init = 0;
                }
                assoc->cql_transform = gfs->cql_transform;
+               assoc->server_node_ptr = gfs->server_node_ptr;
                assoc->last_control = &gfs->cb;
                statserv_setcontrol(&gfs->cb);
                return 1;
@@ -273,6 +275,7 @@ int control_association(association *assoc, const char *host, int force_open)
        statserv_setcontrol(0);
        assoc->last_control = 0;
        assoc->cql_transform = 0;
+       assoc->server_node_ptr = 0;
        return 0;
     }
     else
@@ -280,6 +283,7 @@ int control_association(association *assoc, const char *host, int force_open)
        statserv_setcontrol(&control_block);
        assoc->last_control = &control_block;
        assoc->cql_transform = 0;
+       assoc->server_node_ptr = 0;
        return 1;
     }
 }
@@ -319,7 +323,7 @@ static void xml_config_read()
        }
        else if (!strcmp((const char *) ptr->name, "server"))
        {
-           xmlNodePtr ptr_children = ptr->children;
+           xmlNodePtr ptr_server = ptr;
            xmlNodePtr ptr;
            const char *listenref = 0;
 
@@ -328,6 +332,7 @@ static void xml_config_read()
                    && attr->children && attr->children->type == XML_TEXT_NODE)
                    listenref = nmem_dup_xml_content(gfs_nmem, attr->children);
            *gfsp = gfs_server_new();
+           (*gfsp)->server_node_ptr = ptr_server;
            if (listenref)
            {
                int id_no;
@@ -342,7 +347,7 @@ static void xml_config_read()
                    yaz_log(YLOG_WARN, "Non-existent listenref '%s' in server "
                            "config element", listenref);
            }
-           for (ptr = ptr_children; ptr; ptr = ptr->next)
+           for (ptr = ptr_server->children; ptr; ptr = ptr->next)
            {
                if (ptr->type != XML_ELEMENT_NODE)
                    continue;
@@ -356,7 +361,7 @@ static void xml_config_read()
                    strcpy((*gfsp)->cb.configname,
                           nmem_dup_xml_content(gfs_nmem, ptr->children));
                }
-               if (!strcmp((const char *) ptr->name, "pqf2cql"))
+               if (!strcmp((const char *) ptr->name, "cql2rpn"))
                {
                    (*gfsp)->cql_transform = cql_transform_open_fname(
                        nmem_dup_xml_content(gfs_nmem, ptr->children)
index 262dae6..627eb87 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $Id: config1.xml,v 1.1 2005-03-01 20:37:01 adam Exp $ -->
+<!-- $Id: config1.xml,v 1.2 2005-03-03 23:16:20 adam Exp $ -->
 <yazgfs>
   <listen id="public9900">tcp:@:9900</listen>
   <listen id="public9901">tcp:@:9901</listen>
@@ -15,6 +15,9 @@
   <server listenref="public9901">
     <directory>/var/www/s3</directory>
     <config>zebra3.cfg</config>
-    <pqf2cql>../etc/pqf.properties</pqf2cql>
+    <cql2rpn>../etc/pqf.properties</cql2rpn>
+    <explain>
+      <my>explain</my>
+    </explain>
   </server>
 </yazgfs>
index 5922ef2..2bbc613 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: ztest.c,v 1.73 2005-02-09 12:41:45 adam Exp $
+ * $Id: ztest.c,v 1.74 2005-03-03 23:16:20 adam Exp $
  */
 
 /*
@@ -674,7 +674,9 @@ bend_initresult *bend_init(bend_initrequest *q)
     q->bend_delete = ztest_delete;
     q->bend_fetch = ztest_fetch;
     q->bend_scan = ztest_scan;
+#if 0
     q->bend_explain = ztest_explain;
+#endif
     q->bend_srw_scan = ztest_scan;
 
     return r;