Fixed bug in Generic Frontend Server that could cause a server to stop
[yaz-moved-to-github.git] / src / xmlquery.c
index 9574be4..62ebd7f 100644 (file)
@@ -1,20 +1,19 @@
 /*
- * Copyright (C) 1995-2005, Index Data ApS
+ * Copyright (C) 1995-2006, Index Data ApS
  * All rights reserved.
  *
- * $Id: xmlquery.c,v 1.6 2006-02-23 13:09:54 adam Exp $
+ * $Id: xmlquery.c,v 1.10 2006-07-06 10:17:54 adam Exp $
  */
 
-/**
- * \file querytostr.c
- * \brief Query / XML conversions
- */
+/** \file xmlquery.c
+    \brief Query / XML conversions
+*/
 
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
 
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
@@ -249,18 +248,17 @@ xmlNodePtr yaz_query2xml_cql(const char *cql, xmlNodePtr node)
     return 0;
 }
 
-void yaz_rpnquery2xml(const Z_RPNQuery *rpn, void *docp_void)
+void yaz_rpnquery2xml(const Z_RPNQuery *rpn, xmlDocPtr *docp)
 {
     Z_Query query;
 
     query.which = Z_Query_type_1;
     query.u.type_1 = (Z_RPNQuery *) rpn;
-    yaz_query2xml(&query, docp_void);
+    yaz_query2xml(&query, docp);
 }
 
-void yaz_query2xml(const Z_Query *q, void *docp_void)
+void yaz_query2xml(const Z_Query *q, xmlDocPtr *docp)
 {
-    xmlDocPtr *docp = (xmlDocPtr *) docp_void;
     xmlNodePtr top_node, q_node = 0, child_node = 0;
 
     assert(q);
@@ -501,19 +499,7 @@ void yaz_xml2query_attribute_element(const xmlNode *ptr,
 
 char *strVal(const xmlNode *ptr_cdata, ODR odr)
 {
-    char *cdata;
-    int len = 0;
-    const xmlNode *ptr;
-
-    for (ptr = ptr_cdata; ptr; ptr = ptr->next)
-        if (ptr->type == XML_TEXT_NODE)
-            len += xmlStrlen(ptr->content);
-    cdata = (char *) odr_malloc(odr, len+1);
-    *cdata = '\0';
-    for (ptr = ptr_cdata; ptr; ptr = ptr->next)
-        if (ptr->type == XML_TEXT_NODE)
-            strcat(cdata, (const char *) ptr->content);
-    return cdata;
+    return nmem_text_node_cdata(ptr_cdata, odr->mem);
 }
 
 void yaz_xml2query_term(const xmlNode *ptr,
@@ -790,7 +776,7 @@ void yaz_xml2query(const void *xmlnodep, Z_Query **query, ODR odr,
     yaz_xml2query_(xmlnodep, query, odr, error_code, addinfo);
 }
 
-/* HAVE_XML2 */
+/* YAZ_HAVE_XML2 */
 #endif
 
 /*