Proper cleanup (isamb_close) for bad headers
[idzebra-moved-to-github.git] / index / mod_dom.c
index 1c44a72..8aeb416 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mod_dom.c,v 1.17 2007-02-23 11:10:37 adam Exp $
+/* $Id: mod_dom.c,v 1.20 2007-02-23 14:59:12 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -115,6 +115,9 @@ struct filter_info {
 #define XML_STRCMP(a,b)   strcmp((char*)a, b)
 #define XML_STRLEN(a) strlen((char*)a)
 
+
+#define FOR_EACH_ELEMENT(ptr) for (; ptr; ptr = ptr->next) if (ptr->type == XML_ELEMENT_NODE)
+
 static void dom_log(int level, struct filter_info *tinfo, xmlNodePtr ptr,
                     const char *fmt, ...)
 #ifdef __GNUC__
@@ -127,20 +130,18 @@ static void dom_log(int level, struct filter_info *tinfo, xmlNodePtr ptr,
 {
     va_list ap;
     char buf[4096];
-    xmlChar *node_path = 0;
-
-    if (ptr)
-        node_path = xmlGetNodePath(ptr);
 
     va_start(ap, fmt);
     yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap);
-    yaz_log(level, "%s: dom filter %s%s: %s",
-            tinfo->fname ? tinfo->fname : "none", 
-            node_path ? "in " : "", 
-            node_path ? (const char *) node_path : "", buf);
-
-    if (node_path)
-        xmlFree(node_path);
+    if (ptr)
+    {
+        yaz_log(level, "%s:%ld: %s", tinfo->fname ? tinfo->fname : "none", 
+                xmlGetLineNo(ptr), buf);
+    }
+    else
+    {
+        yaz_log(level, "%s: %s", tinfo->fname ? tinfo->fname : "none", buf);
+    }
     va_end(ap);
 }
 
@@ -264,10 +265,7 @@ static ZEBRA_RES parse_convert(struct filter_info *tinfo, xmlNodePtr ptr,
                                struct convert_s **l)
 {
     *l = 0;
-    for(; ptr; ptr = ptr->next)
-    {
-        if (ptr->type != XML_ELEMENT_NODE)
-            continue;
+    FOR_EACH_ELEMENT(ptr) {
         if (!XML_STRCMP(ptr->name, "xslt"))
         {
             struct _xmlAttr *attr;
@@ -312,20 +310,20 @@ static ZEBRA_RES parse_convert(struct filter_info *tinfo, xmlNodePtr ptr,
                             tmp_xslt_full_name);
                     return ZEBRA_FAIL;
                 }
-            }
-            else
-            {
-                dom_log(YLOG_WARN, tinfo, ptr,
-                        "missing attribute 'stylesheet' ");
-                return ZEBRA_FAIL;
-            }
-            *l = p;
-            l = &p->next;
+                }
+                else
+                {
+                    dom_log(YLOG_WARN, tinfo, ptr,
+                            "missing attribute 'stylesheet' ");
+                    return ZEBRA_FAIL;
+                }
+                *l = p;
+                l = &p->next;
         }
         else
         {
             dom_log(YLOG_WARN, tinfo, ptr,
-                    "bad node '%s'", ptr->name);
+                    "bad element '%s', expected <xslt>", ptr->name);
             return ZEBRA_FAIL;
         }
     }
@@ -368,10 +366,7 @@ static struct filter_input *new_input(struct filter_info *tinfo, int type)
 static ZEBRA_RES parse_input(struct filter_info *tinfo, xmlNodePtr ptr,
                              const char *syntax, const char *name)
 {
-    for (; ptr; ptr = ptr->next)
-    {
-        if (ptr->type != XML_ELEMENT_NODE)
-            continue;
+    FOR_EACH_ELEMENT(ptr) {
         if (!XML_STRCMP(ptr->name, "marc"))
         {
             yaz_iconv_t iconv = 0;
@@ -380,12 +375,12 @@ static ZEBRA_RES parse_input(struct filter_info *tinfo, xmlNodePtr ptr,
             
             for (attr = ptr->properties; attr; attr = attr->next)
             {
-                if (attr_content(attr, "charset", &input_charset))
+                if (attr_content(attr, "inputcharset", &input_charset))
                     ;
                 else
                 {
                     dom_log(YLOG_WARN, tinfo, ptr,
-                            "bad attribute @%s, expected @charset",
+                            "bad attribute @%s, expected @inputcharset",
                             attr->name);
                 }
             }
@@ -468,7 +463,7 @@ static ZEBRA_RES parse_dom(struct filter_info *tinfo, const char *fname)
     
     yaz_log(YLOG_LOG, "%s dom filter: "
             "loading config file %s", tinfo->fname, tinfo->full_name);
-    
+
     doc = xmlParseFile(tinfo->full_name);
     if (!doc)
     {
@@ -490,10 +485,8 @@ static ZEBRA_RES parse_dom(struct filter_info *tinfo, const char *fname)
         return ZEBRA_FAIL;
     }
 
-    for (ptr = ptr->children; ptr; ptr = ptr->next)
-    {
-        if (ptr->type != XML_ELEMENT_NODE)
-            continue;
+    ptr = ptr->children;
+    FOR_EACH_ELEMENT(ptr) {
         if (!XML_STRCMP(ptr->name, "extract"))
         {
             /*