From 384d5cac78251cf68841040384ca0fa8912178c7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 26 Jan 2010 15:50:56 +0100 Subject: [PATCH] Using yaz_xml_include --- configure.ac | 2 +- src/pazpar2_config.c | 121 +------------------------------------------------- 2 files changed, 3 insertions(+), 120 deletions(-) diff --git a/configure.ac b/configure.ac index 3a0e67a..6817819 100644 --- a/configure.ac +++ b/configure.ac @@ -27,7 +27,7 @@ if test -z "$YAZLIB"; then fi YAZ_DOC -AC_CHECK_HEADERS([sys/time.h sys/socket.h unistd.h netinet/in.h netdb.h arpa/inet.h glob.h]) +AC_CHECK_HEADERS([sys/time.h sys/socket.h unistd.h netinet/in.h netdb.h arpa/inet.h]) checkBoth=0 AC_CHECK_FUNC([connect]) if test "$ac_cv_func_connect" = "no"; then diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index 3b8a72e..86f401a 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -31,17 +31,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include -#if HAVE_GLOB_H -#define USE_POSIX_GLOB 1 -#else -#define USE_POSIX_GLOB 0 -#endif - - -#if USE_POSIX_GLOB -#include -#endif #include #include #if HAVE_UNISTD_H @@ -927,114 +918,6 @@ static int parse_config(struct conf_config *config, xmlNode *root) return 0; } -static int process_config_includes(struct conf_config *config, xmlNode *n); - -static int config_include_one(struct conf_config *config, xmlNode **sib, - const char *path) -{ - struct stat st; - if (stat(path, &st) < 0) - { - yaz_log(YLOG_FATAL|YLOG_ERRNO, "stat %s", path); - return -1; - } - else - { - if ((st.st_mode & S_IFMT) == S_IFREG) - { - xmlDoc *doc = xmlParseFile(path); - if (doc) - { - xmlNodePtr t = xmlDocGetRootElement(doc); - int ret = process_config_includes(config, t); - *sib = xmlAddNextSibling(*sib, xmlCopyNode(t, 1)); - xmlFreeDoc(doc); - if (ret) - return -1; - } - else - { - yaz_log(YLOG_FATAL, "Could not parse %s", path); - return -1; - } - } - } - return 0; -} - -static int config_include_src(struct conf_config *config, xmlNode **np, - const char *src) -{ - int ret = 0; /* return code. OK so far */ - WRBUF w = wrbuf_alloc(); - xmlNodePtr sib; /* our sibling that we append */ - xmlNodePtr c; /* tmp node */ - - wrbuf_printf(w, " begin include src=\"%s\" ", src); - - /* replace include element with a 'begin' comment */ - sib = xmlNewComment((const xmlChar *) wrbuf_cstr(w)); - xmlReplaceNode(*np, sib); - - xmlFreeNode(*np); - - wrbuf_rewind(w); - conf_dir_path(config, w, src); -#if USE_POSIX_GLOB - { - size_t i; - glob_t glob_res; - glob(wrbuf_cstr(w), 0 /* flags */, 0 /* errfunc */, &glob_res); - - for (i = 0; ret == 0 && i < glob_res.gl_pathc; i++) - { - const char *path = glob_res.gl_pathv[i]; - ret = config_include_one(config, &sib, path); - } - globfree(&glob_res); - } -#else - ret = config_include_one(config, &sib, wrbuf_cstr(w)); -#endif - wrbuf_rewind(w); - wrbuf_printf(w, " end include src=\"%s\" ", src); - c = xmlNewComment((const xmlChar *) wrbuf_cstr(w)); - sib = xmlAddNextSibling(sib, c); - - *np = sib; - wrbuf_destroy(w); - return ret; -} - -static int process_config_includes(struct conf_config *config, xmlNode *n) -{ - for (; n; n = n->next) - { - if (n->type == XML_ELEMENT_NODE) - { - if (!strcmp((const char *) n->name, "include")) - { - xmlChar *src = xmlGetProp(n, (xmlChar *) "src"); - if (src) - { - int ret = config_include_src(config, &n, - (const char *) src); - xmlFree(src); - if (ret) - return ret; - - } - } - else - { - if (process_config_includes(config, n->children)) - return -1; - } - } - } - return 0; -} - struct conf_config *config_create(const char *fname, int verbose) { xmlDoc *doc = xmlParseFile(fname); @@ -1071,7 +954,7 @@ struct conf_config *config_create(const char *fname, int verbose) wrbuf_puts(config->confdir, ""); n = xmlDocGetRootElement(doc); - r = process_config_includes(config, n); + r = yaz_xml_include_simple(n, wrbuf_cstr(config->confdir)); if (r == 0) /* OK */ { if (verbose) -- 1.7.10.4