Update for YAZ 3s new OID system
[idzebra-moved-to-github.git] / index / alvis.c
index da5817b..77efef6 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: alvis.c,v 1.7 2006-12-05 09:26:04 adam Exp $
-   Copyright (C) 1995-2006
+/* $Id: alvis.c,v 1.16 2007-04-16 08:44:31 adam Exp $
+   Copyright (C) 1995-2007
    Index Data ApS
 
 This file is part of the Zebra server.
@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <yaz/diagbib1.h>
 #include <yaz/tpath.h>
+#include <yaz/oid_db.h>
 
 #include <libxml/xmlversion.h>
 #include <libxml/parser.h>
@@ -345,6 +346,7 @@ static void filter_destroy(void *clientData)
 {
     struct filter_info *tinfo = clientData;
     destroy_schemas(tinfo);
+    xfree(tinfo->full_name);
     if (tinfo->reader)
        xmlFreeTextReader(tinfo->reader);
     odr_destroy(tinfo->odr);
@@ -434,8 +436,7 @@ static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl,
            sscanf(id_str, "%255s", ctrl->match_criteria);
 
        if (rank_str)
-           ctrl->staticrank = atoi(rank_str);
-       
+           ctrl->staticrank = atozint(rank_str);
        ptr = ptr->children;
     }
 
@@ -508,7 +509,9 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p)
                                       p /* I/O handler */,
                                       0 /* URL */, 
                                       0 /* encoding */,
-                                      XML_PARSE_XINCLUDE);
+                                      XML_PARSE_XINCLUDE
+                                       | XML_PARSE_NOENT
+                                       | XML_PARSE_NONET);
     }
     if (!tinfo->reader)
        return RECCTRL_EXTRACT_ERROR_GENERIC;
@@ -518,9 +521,7 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p)
     {
        int type = xmlTextReaderNodeType(tinfo->reader);
        int depth = xmlTextReaderDepth(tinfo->reader);
-       if (tinfo->split_level == 0 ||
-           (tinfo->split_level > 0 &&
-            type == XML_READER_TYPE_ELEMENT && tinfo->split_level == depth))
+       if (type == XML_READER_TYPE_ELEMENT && tinfo->split_level == depth)
        {
            xmlNodePtr ptr = xmlTextReaderExpand(tinfo->reader);
             if (ptr)
@@ -546,13 +547,39 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p)
     return RECCTRL_EXTRACT_EOF;
 }
 
+static int extract_full(struct filter_info *tinfo, struct recExtractCtrl *p)
+{
+    if (p->first_record) /* only one record per stream */
+    {
+       xmlDocPtr doc = xmlReadIO(ioread_ex, ioclose_ex, p /* I/O handler */,
+                                 0 /* URL */,
+                                 0 /* encoding */,
+                                 XML_PARSE_XINCLUDE
+                                 | XML_PARSE_NOENT
+                                 | XML_PARSE_NONET);
+       if (!doc)
+           return RECCTRL_EXTRACT_ERROR_GENERIC;
+       /* else {
+           xmlNodePtr root = xmlDocGetRootElement(doc);
+            if (!root)
+                return RECCTRL_EXTRACT_ERROR_GENERIC;
+                } */
+       
+       return extract_doc(tinfo, p, doc);
+    }
+    else
+       return RECCTRL_EXTRACT_EOF;
+}
+
 static int filter_extract(void *clientData, struct recExtractCtrl *p)
 {
     struct filter_info *tinfo = clientData;
 
     odr_reset(tinfo->odr);
-
-    return extract_split(tinfo, p);
+    if (tinfo->split_level == 0)
+        return extract_full(tinfo, p);
+    else
+        return extract_split(tinfo, p);
 }
 
 static int ioread_ret(void *context, char *buffer, int len)
@@ -606,10 +633,10 @@ static const char *snippet_doc(struct recRetrieveCtrl *p, int text_mode,
     else
        wrbuf_printf(wrbuf, "</snippet>\n");
 
-    xml_doc_str = odr_strdup(p->odr, wrbuf_buf(wrbuf));
+    xml_doc_str = odr_strdup(p->odr, wrbuf_cstr(wrbuf));
 
     zebra_snippets_destroy(res);
-    wrbuf_free(wrbuf, 1);
+    wrbuf_destroy(wrbuf);
     return xml_doc_str;
 }
 
@@ -677,7 +704,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
     doc = xmlReadIO(ioread_ret, ioclose_ret, p /* I/O handler */,
                    0 /* URL */,
                    0 /* encoding */,
-                   XML_PARSE_XINCLUDE);
+                   XML_PARSE_XINCLUDE | XML_PARSE_NOENT | XML_PARSE_NONET);
     if (!doc)
     {
        p->diagnostic = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
@@ -703,7 +730,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
     {
        p->diagnostic = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
     }
-    else if (p->input_format == VAL_NONE || p->input_format == VAL_TEXT_XML)
+    else if (!p->input_format || !oid_oidcmp(p->input_format, yaz_oid_xml()))
     {
        xmlChar *buf_out;
        int len_out;
@@ -714,13 +741,13 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
         else
            xmlDocDumpMemory(resDoc, &buf_out, &len_out);            
 
-       p->output_format = VAL_TEXT_XML;
+       p->output_format = yaz_oid_xml();
        p->rec_len = len_out;
        p->rec_buf = odr_malloc(p->odr, p->rec_len);
        memcpy(p->rec_buf, buf_out, p->rec_len);
        xmlFree(buf_out);
     }
-    else if (p->output_format == VAL_SUTRS)
+    else if (!oid_oidcmp(p->output_format, yaz_oid_sutrs()))
     {
        xmlChar *buf_out;
        int len_out;
@@ -731,7 +758,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p)
         else
            xmlDocDumpMemory(resDoc, &buf_out, &len_out);            
 
-       p->output_format = VAL_SUTRS;
+       p->output_format = yaz_oid_sutrs();
        p->rec_len = len_out;
        p->rec_buf = odr_malloc(p->odr, p->rec_len);
        memcpy(p->rec_buf, buf_out, p->rec_len);