Refactor and rewind fix
[idzebra-moved-to-github.git] / index / mod_dom.c
index 9758cbe..ad97171 100644 (file)
@@ -218,18 +218,6 @@ static int attr_content(struct _xmlAttr *attr, const char *name,
     return 0;
 }
 
-static int attr_content_xml(struct _xmlAttr *attr, const char *name,
-                            const char **dst_content)
-{
-    if (0 == XML_STRCMP(attr->name, name) && attr->children 
-        && attr->children->type == XML_TEXT_NODE)
-    {
-        *dst_content = (const char *) (attr->children->content);
-        return 1;
-    }
-    return 0;
-}
-
 static void destroy_xsp(struct convert_s *c)
 {
     while (c)
@@ -350,7 +338,7 @@ static ZEBRA_RES parse_convert(struct filter_info *tinfo, xmlNodePtr ptr,
             *l = p;
             l = &p->next;
         }
-        else if (!XML_STRCMP(ptr->name, "meta"))
+        else if (!XML_STRCMP(ptr->name, "process-meta"))
         {
             struct _xmlAttr *attr;
             struct convert_s *p = nmem_malloc(tinfo->nmem_config, sizeof(*p));
@@ -388,13 +376,12 @@ static int process_meta(struct filter_info *tinfo, xmlDocPtr doc, xmlNodePtr nod
             struct _xmlAttr *attr;      
             for (attr = node->properties; attr; attr = attr->next)
             {
-                if (attr_content_xml(attr, "element_set_name", &element_set_name))
+                if (attr_content(attr, "name", &element_set_name))
                     ;
                 else
                 {
                     dom_log(YLOG_WARN, tinfo, node,
-                            "bad attribute @%s, expected @element_set_name",
-                            attr->name);
+                            "bad attribute @%s, expected @name", attr->name);
                 }
             }
             if (element_set_name)
@@ -412,11 +399,11 @@ static int process_meta(struct filter_info *tinfo, xmlDocPtr doc, xmlNodePtr nod
                 if (ret == 0)
                 {
                     xmlDocPtr sub_doc = 
-                        xmlParseMemory(    wrbuf_buf(result), wrbuf_len(result));
+                        xmlParseMemory(wrbuf_buf(result), wrbuf_len(result));
                     if (sub_doc)
                     {
                         xmlNodePtr t = xmlDocGetRootElement(sub_doc);
-                        xmlAddChild(node, xmlCopyNode(t, 1));
+                        xmlReplaceNode(node, xmlCopyNode(t, 1));
                         xmlFreeDoc(sub_doc);
                     }
                 }
@@ -968,7 +955,7 @@ static void process_xml_element_zebra_node(struct filter_info *tinfo,
             struct _xmlAttr *attr;      
             for (attr = node->properties; attr; attr = attr->next)
             {
-                if (attr_content_xml(attr, "name", &index_p))
+                if (attr_content(attr, "name", &index_p))
                 {
                     index_value_of(tinfo, extctr, recword, node, index_p);
                 }  
@@ -989,11 +976,11 @@ static void process_xml_element_zebra_node(struct filter_info *tinfo,
             struct _xmlAttr *attr;
             for (attr = node->properties; attr; attr = attr->next)
             {
-                if (attr_content_xml(attr, "id", &id_p))
+                if (attr_content(attr, "id", &id_p))
                     ;
-                else if (attr_content_xml(attr, "rank", &rank_p))
+                else if (attr_content(attr, "rank", &rank_p))
                     ;
-                else if (attr_content_xml(attr, "type", &type_p))
+                else if (attr_content(attr, "type", &type_p))
                     ;
                 else
                 {
@@ -1163,7 +1150,6 @@ static int convert_extract_doc(struct filter_info *tinfo,
     int len_out;
     const char *params[10];
     xsltStylesheetPtr last_xsp = 0;
-    xmlDocPtr store_doc = 0;
 
     /* per default do not ingest record */
     tinfo->record_info_invoked = 0;
@@ -1191,30 +1177,35 @@ static int convert_extract_doc(struct filter_info *tinfo,
 #endif
     }
 
-    /* input conversion */
-    perform_convert(tinfo, p, 0, input->convert, params, &doc, 0);
-
-    if (tinfo->store)
+    if (p->setStoreData)
     {
-        /* store conversion */
-        store_doc = xmlCopyDoc(doc, 1);
-        perform_convert(tinfo, p, 0, tinfo->store->convert,
-                        params, &store_doc, &last_xsp);
-    }
-    
-    /* saving either store doc or original doc in case no store doc exists */
-    if (last_xsp)
-        xsltSaveResultToString(&buf_out, &len_out, 
-                               store_doc ? store_doc : doc, last_xsp);
-    else
-        xmlDocDumpMemory(store_doc ? store_doc : doc, &buf_out, &len_out);
+        xmlDocPtr store_doc = 0;
 
-    if (p->setStoreData)
-        (*p->setStoreData)(p, buf_out, len_out);
-    xmlFree(buf_out);
+        /* input conversion */
+        perform_convert(tinfo, p, 0, input->convert, params, &doc, 0);
+        
+        if (tinfo->store)
+        {
+            /* store conversion */
+            store_doc = xmlCopyDoc(doc, 1);
+            perform_convert(tinfo, p, 0, tinfo->store->convert,
+                            params, &store_doc, &last_xsp);
+        }
+        
+        /* saving either store doc or original doc in case no store doc exists */
+        if (last_xsp)
+            xsltSaveResultToString(&buf_out, &len_out, 
+                                   store_doc ? store_doc : doc, last_xsp);
+        else
+            xmlDocDumpMemory(store_doc ? store_doc : doc, &buf_out, &len_out);
+        
+        if (p->setStoreData)
+            (*p->setStoreData)(p, buf_out, len_out);
+        xmlFree(buf_out);
+        if (store_doc)
+            xmlFreeDoc(store_doc);
+    }
 
-    if (store_doc)
-        xmlFreeDoc(store_doc);
 
     /* extract conversion */
     perform_convert(tinfo, p, 0, tinfo->extract->convert, params, &doc, 0);
@@ -1270,7 +1261,7 @@ static int extract_xml_split(struct filter_info *tinfo,
             
             ptr = xmlTextReaderExpand(input->u.xmlreader.reader);
             if (ptr)
-                {
+            {
                 /* we have a new document */
 
                 xmlNodePtr ptr2 = xmlCopyNode(ptr, 1);