提交 5081d1fe authored 作者: Anthony Minessale's avatar Anthony Minessale

globs on #includes

no leading seperator indicates realitive
to the default conf dir.

examples:
<!--#include "profiles/*"-->
<!--#include "profiles/a*.xml"-->
<!--#include "/tmp/somedir/*"-->




git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5745 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 020fc7df
...@@ -742,6 +742,20 @@ SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_ ...@@ -742,6 +742,20 @@ SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_
typedef struct switch_dir switch_dir_t; typedef struct switch_dir switch_dir_t;
struct switch_array_header_t {
/** The pool the array is allocated out of */
switch_memory_pool_t *pool;
/** The amount of memory allocated for each element of the array */
int elt_size;
/** The number of active elements in the array */
int nelts;
/** The number of elements allocated in the array */
int nalloc;
/** The elements in the array */
char *elts;
};
typedef struct switch_array_header_t switch_array_header_t;
SWITCH_DECLARE(switch_status_t) switch_dir_open(switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool); SWITCH_DECLARE(switch_status_t) switch_dir_open(switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_dir_close(switch_dir_t *thedir); SWITCH_DECLARE(switch_status_t) switch_dir_close(switch_dir_t *thedir);
SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len); SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len);
...@@ -1143,6 +1157,8 @@ SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t * aprset, int32_t nu ...@@ -1143,6 +1157,8 @@ SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t * aprset, int32_t nu
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t ** poll, switch_socket_t * sock, int16_t flags, switch_memory_pool_t *pool); SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t ** poll, switch_socket_t * sock, int16_t flags, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_match_glob(const char *pattern, switch_array_header_t **result, switch_memory_pool_t *p);
/** @} */ /** @} */
......
...@@ -53,6 +53,9 @@ ...@@ -53,6 +53,9 @@
#define APR_WANT_STDIO #define APR_WANT_STDIO
#define APR_WANT_STRFUNC #define APR_WANT_STRFUNC
#include <apr_want.h> #include <apr_want.h>
#include <apr_file_info.h>
#include <apr_fnmatch.h>
#include <apr_tables.h>
/* apr_vformatter_buff_t definition*/ /* apr_vformatter_buff_t definition*/
#include <apr_lib.h> #include <apr_lib.h>
...@@ -714,7 +717,12 @@ SWITCH_DECLARE(int) switch_vasprintf(char **ret, const char *fmt, va_list ap) ...@@ -714,7 +717,12 @@ SWITCH_DECLARE(int) switch_vasprintf(char **ret, const char *fmt, va_list ap)
#endif #endif
} }
SWITCH_DECLARE(switch_status_t) switch_match_glob(const char *pattern, switch_array_header_t **result, switch_memory_pool_t *p)
{
return apr_match_glob(pattern, (apr_array_header_t **)result, p);
}
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c
......
...@@ -68,6 +68,8 @@ extern int madvise(caddr_t, size_t, int); ...@@ -68,6 +68,8 @@ extern int madvise(caddr_t, size_t, int);
#define SWITCH_XML_WS "\t\r\n " // whitespace #define SWITCH_XML_WS "\t\r\n " // whitespace
#define SWITCH_XML_ERRL 128 // maximum error string length #define SWITCH_XML_ERRL 128 // maximum error string length
static int preprocess(const char *file, int write_fd, int rlevel);
typedef struct switch_xml_root *switch_xml_root_t; typedef struct switch_xml_root *switch_xml_root_t;
struct switch_xml_root { // additional data for the root tag struct switch_xml_root { // additional data for the root tag
struct switch_xml xml; // is a super-struct built on top of switch_xml struct struct switch_xml xml; // is a super-struct built on top of switch_xml struct
...@@ -933,6 +935,57 @@ static char *expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_ ...@@ -933,6 +935,57 @@ static char *expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_
} }
/* for apr file and directory handling */
#include <apr_file_io.h>
static int preprocess_glob(const char *pattern, int write_fd, int rlevel)
{
switch_array_header_t *result;
switch_memory_pool_t *pool;
char **list;
int i;
char *p, *dir_path = NULL;
switch_core_new_memory_pool(&pool);
assert(pool != NULL);
if (switch_is_file_path(pattern)) {
dir_path = switch_core_strdup(pool, pattern);
if ((p = strrchr(dir_path, *SWITCH_PATH_SEPARATOR))) {
*p = '\0';
}
} else {
dir_path = SWITCH_GLOBAL_dirs.conf_dir;
p = switch_core_sprintf(pool, "%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, pattern);
pattern = p;
}
switch_match_glob(pattern, &result, pool);
list = (char **)result->elts;
for (i = 0; i < result->nelts; i++) {
char *path = list[i];
if (strcmp(path, ".") && strcmp(path, "..")) {
p = switch_core_sprintf(pool, "%s%s%s", dir_path, SWITCH_PATH_SEPARATOR, path);
if (preprocess(p, write_fd, rlevel) < 0) {
const char *reason = strerror(errno);
if (rlevel > 100) {
reason = "Maximum recursion limit reached";
}
fprintf(stderr, "Error including %s (%s)\n", p, reason);
}
}
}
switch_core_destroy_memory_pool(&pool);
return write_fd;
}
static int preprocess(const char *file, int write_fd, int rlevel) static int preprocess(const char *file, int write_fd, int rlevel)
{ {
int read_fd = -1; int read_fd = -1;
...@@ -1016,17 +1069,8 @@ static int preprocess(const char *file, int write_fd, int rlevel) ...@@ -1016,17 +1069,8 @@ static int preprocess(const char *file, int write_fd, int rlevel)
} }
} else if (!strcasecmp(cmd, "include")) { } else if (!strcasecmp(cmd, "include")) {
char *fme = NULL, *ifile = arg; preprocess_glob(arg, write_fd, rlevel + 1);
}
if (!switch_is_file_path(ifile)) {
fme = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, arg);
ifile = fme;
}
if (preprocess(ifile, write_fd, rlevel + 1) < 0) {
fprintf(stderr, "Error including %s (%s)\n", ifile, strerror(errno));
}
switch_safe_free(fme);
} /* else NO OP */
} }
continue; continue;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论