Update for YAZ 3s new OID system
[idzebra-moved-to-github.git] / index / alvis.c
index 851064f..77efef6 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: alvis.c,v 1.9 2006-12-22 12:13:40 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,13 +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 = 
-#if HAVE_ATOLL
-                atoll(rank_str);
-#else
-                atoi(rank_str);
-#endif
-       
+           ctrl->staticrank = atozint(rank_str);
        ptr = ptr->children;
     }
 
@@ -513,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;
@@ -556,11 +554,17 @@ static int extract_full(struct filter_info *tinfo, struct recExtractCtrl *p)
        xmlDocPtr doc = xmlReadIO(ioread_ex, ioclose_ex, p /* I/O handler */,
                                  0 /* URL */,
                                  0 /* encoding */,
-                                 XML_PARSE_XINCLUDE);
+                                 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
@@ -629,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;
 }
 
@@ -700,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;
@@ -726,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;
@@ -737,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;
@@ -754,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);