X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fmod_dom.c;h=8aeb416d98f2b48363e118b5052ee971ba2ded3b;hb=6b22ee11c602f66f94cef22bdf8077002e8d844a;hp=1c44a72cf297171c90ef173aef4b8f8f3cebb8cc;hpb=7729ad61cb420817f12337ccfc4f9fb1c67222a3;p=idzebra-moved-to-github.git diff --git a/index/mod_dom.c b/index/mod_dom.c index 1c44a72..8aeb416 100644 --- a/index/mod_dom.c +++ b/index/mod_dom.c @@ -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 ", 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")) { /*