* 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>
request_initq(&anew->outgoing);
anew->proto = cs_getproto(link);
anew->cql_transform = 0;
+ anew->server_node_ptr = 0;
return anew;
}
}
}
+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,
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;
+ }
}
}
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,
* 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 $
*/
/**
n->host = 0;
n->listen_ref = 0;
n->cql_transform = 0;
+ n->server_node_ptr = 0;
return n;
}
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;
statserv_setcontrol(0);
assoc->last_control = 0;
assoc->cql_transform = 0;
+ assoc->server_node_ptr = 0;
return 0;
}
else
statserv_setcontrol(&control_block);
assoc->last_control = &control_block;
assoc->cql_transform = 0;
+ assoc->server_node_ptr = 0;
return 1;
}
}
}
else if (!strcmp((const char *) ptr->name, "server"))
{
- xmlNodePtr ptr_children = ptr->children;
+ xmlNodePtr ptr_server = ptr;
xmlNodePtr ptr;
const char *listenref = 0;
&& 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;
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;
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)