glob support in include
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index b5d8b16..59a3db2 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -650,18 +650,52 @@
static char *
ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
- ngx_str_t *value, file;
+ char *rv;
+ ngx_int_t n;
+ ngx_str_t *value, file;
+ ngx_glob_t gl;
value = cf->args->elts;
file = value[1];
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
+
if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
+ ngx_memzero(&gl, sizeof(ngx_glob_t));
- return ngx_conf_parse(cf, &file);
+ gl.pattern = file.data;
+ gl.log = cf->log;
+
+ if (ngx_open_glob(&gl) != NGX_OK) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
+ ngx_open_glob_n " \"%s\" failed", file.data);
+ return NGX_CONF_ERROR;
+ }
+
+ rv = NGX_CONF_OK;
+
+ for ( ;; ) {
+ n = ngx_read_glob(&gl, &file);
+
+ if (n != NGX_OK) {
+ break;
+ }
+
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
+
+ rv = ngx_conf_parse(cf, &file);
+
+ if (rv != NGX_CONF_OK) {
+ break;
+ }
+ }
+
+ ngx_close_glob(&gl);
+
+ return rv;
}
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index baf25ea..4b3b240 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -205,7 +205,7 @@
conf.module_type = NGX_CORE_MODULE;
conf.cmd_type = NGX_MAIN_CONF;
-#if 0
+#if 1
log->log_level = NGX_LOG_DEBUG_ALL;
#endif
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index 1801045..12e595e 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -253,6 +253,40 @@
}
+ngx_int_t
+ngx_open_glob(ngx_glob_t *gl)
+{
+ if (glob((char *) gl->pattern, 0, NULL, &gl->pglob) == 0) {
+ return NGX_OK;
+ }
+
+ return NGX_ERROR;
+}
+
+
+ngx_int_t
+ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
+{
+ if (gl->n < gl->pglob.gl_pathc) {
+
+ name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]);
+ name->data = (u_char *) gl->pglob.gl_pathv[gl->n];
+ gl->n++;
+
+ return NGX_OK;
+ }
+
+ return NGX_DONE;
+}
+
+
+void
+ngx_close_glob(ngx_glob_t *gl)
+{
+ globfree(&gl->pglob);
+}
+
+
ngx_err_t
ngx_trylock_fd(ngx_fd_t fd)
{
diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h
index ff25156..3e1e225 100644
--- a/src/os/unix/ngx_files.h
+++ b/src/os/unix/ngx_files.h
@@ -130,6 +130,20 @@
#define ngx_de_mtime(dir) (dir)->info.st_mtime
+typedef struct {
+ int n;
+ glob_t pglob;
+ u_char *pattern;
+ ngx_log_t *log;
+} ngx_glob_t;
+
+
+ngx_int_t ngx_open_glob(ngx_glob_t *gl);
+#define ngx_open_glob_n "glob()"
+ngx_int_t ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name);
+void ngx_close_glob(ngx_glob_t *gl);
+
+
ngx_err_t ngx_trylock_fd(ngx_fd_t fd);
ngx_err_t ngx_lock_fd(ngx_fd_t fd);
ngx_err_t ngx_unlock_fd(ngx_fd_t fd);
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
index c187191..a4e973d 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -21,6 +21,7 @@
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
+#include <glob.h>
#include <sys/filio.h> /* FIONBIO */
#include <sys/uio.h>
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index 74bbfb1..980e05d 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -27,6 +27,7 @@
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
+#include <glob.h>
#include <sys/uio.h>
#include <sys/stat.h>
diff --git a/src/os/unix/ngx_posix_config.h b/src/os/unix/ngx_posix_config.h
index 984db96..8a95099 100644
--- a/src/os/unix/ngx_posix_config.h
+++ b/src/os/unix/ngx_posix_config.h
@@ -37,6 +37,7 @@
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
+#include <glob.h>
#if (NGX_HAVE_SYS_FILIO_H)
#include <sys/filio.h> /* FIONBIO */
diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h
index c3d8327..666e5ea 100644
--- a/src/os/unix/ngx_solaris_config.h
+++ b/src/os/unix/ngx_solaris_config.h
@@ -25,6 +25,7 @@
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
+#include <glob.h>
#include <sys/filio.h> /* FIONBIO */
#include <sys/uio.h>
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index aee8704..51018a7 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -301,7 +301,7 @@
{
ngx_cpystrn(name->data + name->len, NGX_DIR_MASK, NGX_DIR_MASK_LEN + 1);
- dir->dir = FindFirstFile((const char *) name->data, &dir->fd);
+ dir->dir = FindFirstFile((const char *) name->data, &dir->finddata);
if (dir->dir == INVALID_HANDLE_VALUE) {
return NGX_ERROR;
@@ -322,7 +322,7 @@
return NGX_OK;
}
- if (FindNextFile(dir->dir, &dir->fd) != 0) {
+ if (FindNextFile(dir->dir, &dir->finddata) != 0) {
return NGX_OK;
}
@@ -331,6 +331,64 @@
ngx_int_t
+ngx_open_glob(ngx_glob_t *gl)
+{
+ gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata);
+
+ if (gl->dir == INVALID_HANDLE_VALUE) {
+ return NGX_ERROR;
+ }
+
+ gl->ready = 1;
+
+ return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
+{
+ ngx_err_t err;
+
+ if (gl->ready) {
+ name->len = ngx_strlen(gl->finddata.cFileName);
+ name->data = (u_char *) gl->finddata.cFileName;
+
+ gl->ready = 0;
+ return NGX_OK;
+ }
+
+ if (FindNextFile(gl->dir, &gl->finddata) != 0) {
+ name->len = ngx_strlen(gl->finddata.cFileName);
+ name->data = (u_char *) gl->finddata.cFileName;
+
+ return NGX_OK;
+ }
+
+ err = ngx_errno;
+
+ if (err == NGX_ENOMOREFILES) {
+ return NGX_DONE;
+ }
+
+ ngx_log_error(NGX_LOG_ALERT, gl->log, err,
+ "FindNextFile(%s) failed", gl->pattern);
+
+ return NGX_ERROR;
+}
+
+
+void
+ngx_close_glob(ngx_glob_t *gl)
+{
+ if (FindClose(gl->dir) != 0) {
+ ngx_log_error(NGX_LOG_ALERT, gl->log, ngx_errno,
+ "FindClose(%s) failed", gl->pattern);
+ }
+}
+
+
+ngx_int_t
ngx_de_info(u_char *name, ngx_dir_t *dir)
{
return NGX_OK;
diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h
index c42c055..5a171f5 100644
--- a/src/os/win32/ngx_files.h
+++ b/src/os/win32/ngx_files.h
@@ -141,8 +141,8 @@
#define ngx_delete_dir_n "RemoveDirectory()"
-#define ngx_de_name(dir) ((u_char *) (dir)->fd.cFileName)
-#define ngx_de_namelen(dir) ngx_strlen((dir)->fd.cFileName)
+#define ngx_de_name(dir) ((u_char *) (dir)->finddata.cFileName)
+#define ngx_de_namelen(dir) ngx_strlen((dir)->finddata.cFileName)
ngx_int_t ngx_de_info(u_char *name, ngx_dir_t *dir);
#define ngx_de_info_n "dummy()"
@@ -151,21 +151,35 @@
#define ngx_de_link_info_n "dummy()"
#define ngx_de_is_dir(dir) \
- ((dir)->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ ((dir)->finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
#define ngx_de_is_file(dir) \
- !((dir)->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ !((dir)->finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
#define ngx_de_is_link(dir) 0
#define ngx_de_size(dir) \
- (((off_t) (dir)->fd.nFileSizeHigh << 32) | (dir)->fd.nFileSizeLow)
+ (((off_t) (dir)->finddata.nFileSizeHigh << 32) | (dir)->finddata.nFileSizeLow)
/* 116444736000000000 is commented in src/os/win32/ngx_time.c */
#define ngx_de_mtime(dir) \
(time_t) (((((unsigned __int64) \
- (dir)->fd.ftLastWriteTime.dwHighDateTime << 32) \
- | (dir)->fd.ftLastWriteTime.dwLowDateTime) \
+ (dir)->finddata.ftLastWriteTime.dwHighDateTime << 32) \
+ | (dir)->finddata.ftLastWriteTime.dwLowDateTime) \
- 116444736000000000) / 10000000)
+typedef struct {
+ HANDLE dir;
+ WIN32_FIND_DATA finddata;
+ ngx_int_t ready;
+ u_char *pattern;
+ ngx_log_t *log;
+} ngx_glob_t;
+
+
+ngx_int_t ngx_open_glob(ngx_glob_t *gl);
+#define ngx_open_glob_n "FindFirstFile()"
+
+ngx_int_t ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name);
+void ngx_close_glob(ngx_glob_t *gl);
ssize_t ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset);
diff --git a/src/os/win32/ngx_types.h b/src/os/win32/ngx_types.h
index e7a5151..009ccc9 100644
--- a/src/os/win32/ngx_types.h
+++ b/src/os/win32/ngx_types.h
@@ -18,7 +18,7 @@
typedef struct {
HANDLE dir;
- WIN32_FIND_DATA fd;
+ WIN32_FIND_DATA finddata;
unsigned valid_info:1;
unsigned ready:1;