mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-09 11:28:25 +00:00
Add support for globbing (bug #2825)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4426 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
36
config.c
36
config.c
@@ -17,6 +17,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#define AST_INCLUDE_GLOB 1
|
||||||
|
#ifdef AST_INCLUDE_GLOB
|
||||||
|
# include <glob.h>
|
||||||
|
#endif
|
||||||
#include <asterisk/config.h>
|
#include <asterisk/config.h>
|
||||||
#include <asterisk/config_pvt.h>
|
#include <asterisk/config_pvt.h>
|
||||||
#include <asterisk/cli.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) {
|
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");
|
ast_log(LOG_WARNING, "Including files with explicit config engine no longer permitted. Please use extconfig.conf to specify all mappings\n");
|
||||||
} else {
|
} else {
|
||||||
__ast_load(cur, tmp, _tmpc, _last, includelevel + 1);
|
if (!__ast_load(cur, tmp, _tmpc, _last, includelevel + 1))
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", includelevel);
|
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 {
|
} else {
|
||||||
snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, configfile);
|
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) {
|
if ((option_verbose > 1) && !option_debug) {
|
||||||
ast_verbose( VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
|
ast_verbose( VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -569,7 +592,7 @@ static struct ast_config *__ast_load(const char *configfile, struct ast_config *
|
|||||||
new_buf = comment_p + 1;
|
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;
|
tmp = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -588,6 +611,15 @@ static struct ast_config *__ast_load(const char *configfile, struct ast_config *
|
|||||||
if (comment) {
|
if (comment) {
|
||||||
ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[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;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user