diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-12-11 05:16:30 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-12-11 05:16:30 +0000 |
commit | 4f625334197f4d73780689d0b2a0e9d171a6a035 (patch) | |
tree | 496aee7f8e09f07f4a56593840b2a9fb27c14d14 /config.c | |
parent | f975cf1ad60aad9f51c1bfaa6e15762d36579be1 (diff) |
Add support for globbing (bug #2825)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4426 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'config.c')
-rwxr-xr-x | config.c | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -17,6 +17,10 @@ #include <string.h> #include <errno.h> #include <time.h> +#define AST_INCLUDE_GLOB 1 +#ifdef AST_INCLUDE_GLOB +# include <glob.h> +#endif #include <asterisk/config.h> #include <asterisk/config_pvt.h> #include <asterisk/cli.h> @@ -299,7 +303,8 @@ static int cfg_process(struct ast_config *tmp, struct ast_category **_tmpc, stru if(arg && cur) { ast_log(LOG_WARNING, "Including files with explicit config engine no longer permitted. Please use extconfig.conf to specify all mappings\n"); } else { - __ast_load(cur, tmp, _tmpc, _last, includelevel + 1); + if (!__ast_load(cur, tmp, _tmpc, _last, includelevel + 1)) + return -1; } } else ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", includelevel); @@ -503,6 +508,24 @@ static struct ast_config *__ast_load(const char *configfile, struct ast_config * } else { snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, configfile); } +#ifdef AST_INCLUDE_GLOB + { + int glob_ret; + glob_t globbuf; + globbuf.gl_offs = 0; /* initialize it to silence gcc */ + glob_ret = glob(fn, GLOB_NOMATCH|GLOB_BRACE, NULL, &globbuf); + if (glob_ret == GLOB_NOSPACE) + ast_log(LOG_WARNING, + "Glob Expansion of pattern '%s' failed: Not enough memory\n", fn); + else if (glob_ret == GLOB_ABORTED) + ast_log(LOG_WARNING, + "Glob Expansion of pattern '%s' failed: Read error\n", fn); + else { + /* loop over expanded files */ + int i; + for (i=0; i<globbuf.gl_pathc; i++) { + strncpy(fn, globbuf.gl_pathv[i], sizeof(fn)-1); +#endif if ((option_verbose > 1) && !option_debug) { ast_verbose( VERBOSE_PREFIX_2 "Parsing '%s': ", fn); fflush(stdout); @@ -569,7 +592,7 @@ static struct ast_config *__ast_load(const char *configfile, struct ast_config * new_buf = comment_p + 1; } } - if (process_buf && cfg_process(tmp, _tmpc, _last, process_buf, lineno, configfile, includelevel)) { + if (process_buf && cfg_process(tmp, _tmpc, _last, process_buf, lineno, fn, includelevel)) { tmp = NULL; break; } @@ -588,6 +611,15 @@ static struct ast_config *__ast_load(const char *configfile, struct ast_config * if (comment) { ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment]); } +#ifdef AST_INCLUDE_GLOB + if (!tmp) + break; + } + globfree(&globbuf); + } + } +#endif + return tmp; } |