Remove yaz_log request
[yaz-moved-to-github.git] / src / xml_include.c
index db5f13e..0bd732d 100644 (file)
@@ -1,25 +1,15 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 
-/** \file 
+/** \file
     \brief XML Include (not to be confused with W3C XInclude)
 */
 #if HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#if HAVE_GLOB_H
-#define USE_POSIX_GLOB 1
-#else
-#define USE_POSIX_GLOB 0
-#endif
-
-#if USE_POSIX_GLOB
-#include <glob.h>
-#endif
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
@@ -37,6 +27,7 @@
 
 struct yaz_xml_include_s {
     const char *confdir;
+    unsigned glob_flags;
 };
 
 typedef struct yaz_xml_include_s *yaz_xml_include_t;
@@ -105,27 +96,25 @@ static int config_include_src(yaz_xml_include_t config, xmlNode **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++)
+        int glob_ret;
+        yaz_glob_res_t glob_res;
+
+        glob_ret = yaz_file_glob2(wrbuf_cstr(w), &glob_res, config->glob_flags);
+        if (glob_ret == 0)
         {
-            const char *path = glob_res.gl_pathv[i];
-            ret = config_include_one(config, &sib, path);
+            size_t i;
+            const char *path;
+            for (i = 0; (path = yaz_file_glob_get_file(glob_res, i)); i++)
+                ret = config_include_one(config, &sib, path);
+            yaz_file_globfree(&glob_res);
         }
-        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;
@@ -133,7 +122,7 @@ static int config_include_src(yaz_xml_include_t config, xmlNode **np,
 
 static int process_config_includes(yaz_xml_include_t config, xmlNode *n)
 {
-    for (; n; n = n->next)
+    for (n = n->children; n; n = n->next)
     {
         if (n->type == XML_ELEMENT_NODE)
         {
@@ -147,12 +136,12 @@ static int process_config_includes(yaz_xml_include_t config, xmlNode *n)
                     xmlFree(src);
                     if (ret)
                         return ret;
-                        
+
                 }
             }
             else
             {
-                if (process_config_includes(config, n->children))
+                if (process_config_includes(config, n))
                     return -1;
             }
         }
@@ -160,15 +149,22 @@ static int process_config_includes(yaz_xml_include_t config, xmlNode *n)
     return 0;
 }
 
-int yaz_xml_include_simple(xmlNode *n, const char *base_path)
+int yaz_xml_include_glob(xmlNode *n, const char *base_path,
+                         unsigned glob_flags)
 {
     struct yaz_xml_include_s s;
 
     s.confdir = base_path;
-    process_config_includes(&s, n);
-    return 0;
+    s.glob_flags = glob_flags;
+    return process_config_includes(&s, n);
 }
 
+int yaz_xml_include_simple(xmlNode *n, const char *base_path)
+{
+    return yaz_xml_include_glob(n, base_path, 0);
+}
+
+
 /* YAZ_HAVE_XML2 */
 #endif