|
|
|
@ -43,11 +43,11 @@ static char *strip(char *buf)
|
|
|
|
|
{
|
|
|
|
|
char *start;
|
|
|
|
|
/* Strip off trailing whitespace, returns, etc */
|
|
|
|
|
while(!ast_strlen_zero(buf) && (buf[strlen(buf)-1]<33))
|
|
|
|
|
while (!ast_strlen_zero(buf) && (buf[strlen(buf)-1]<33))
|
|
|
|
|
buf[strlen(buf)-1] = '\0';
|
|
|
|
|
start = buf;
|
|
|
|
|
/* Strip off leading whitespace, returns, etc */
|
|
|
|
|
while(*start && (*start < 33))
|
|
|
|
|
while (*start && (*start < 33))
|
|
|
|
|
*start++ = '\0';
|
|
|
|
|
return start;
|
|
|
|
|
}
|
|
|
|
@ -519,7 +519,7 @@ static int cfg_process(struct ast_config *tmp, struct ast_category **_tmpc, stru
|
|
|
|
|
while((*c == '<') || (*c == '>') || (*c == '\"')) c++;
|
|
|
|
|
/* Get rid of leading mess */
|
|
|
|
|
cur = c;
|
|
|
|
|
while(!ast_strlen_zero(cur)) {
|
|
|
|
|
while (!ast_strlen_zero(cur)) {
|
|
|
|
|
c = cur + strlen(cur) - 1;
|
|
|
|
|
if ((*c == '>') || (*c == '<') || (*c == '\"'))
|
|
|
|
|
*c = '\0';
|
|
|
|
@ -625,9 +625,8 @@ static int cfg_process(struct ast_config *tmp, struct ast_category **_tmpc, stru
|
|
|
|
|
acs->root = com;
|
|
|
|
|
acs->prev = com;
|
|
|
|
|
} else {
|
|
|
|
|
if (*_last)
|
|
|
|
|
(*_last)->blanklines++;
|
|
|
|
|
|
|
|
|
|
if (*_last)
|
|
|
|
|
(*_last)->blanklines++;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
@ -739,38 +738,34 @@ static struct ast_config *__ast_load(char *configfile, struct ast_config *tmp, s
|
|
|
|
|
#endif
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
load_func=NULL;
|
|
|
|
|
if(strcmp(configfile,config_conf_file) && strcmp(configfile,"asterisk.conf") && ast_cust_config_list) {
|
|
|
|
|
if(global_load_func)
|
|
|
|
|
load_func = global_load_func;
|
|
|
|
|
else {
|
|
|
|
|
reg = get_ast_cust_config_keyword(configfile);
|
|
|
|
|
if(reg && reg->func)
|
|
|
|
|
load_func = reg->func;
|
|
|
|
|
else {
|
|
|
|
|
reg = get_ast_cust_config_keyword("global");
|
|
|
|
|
if(reg && reg->func)
|
|
|
|
|
global_load_func = load_func = reg->func;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(load_func) {
|
|
|
|
|
ast_log(LOG_NOTICE,"Loading Config %s via %s engine\n",configfile,reg && reg->name ? reg->name : "global");
|
|
|
|
|
tmp = load_func(configfile,tmp, _tmpc, _last, includelevel
|
|
|
|
|
if (strcmp(configfile,config_conf_file) && strcmp(configfile,"asterisk.conf") && ast_cust_config_list) {
|
|
|
|
|
if (global_load_func) {
|
|
|
|
|
load_func = global_load_func;
|
|
|
|
|
} else {
|
|
|
|
|
reg = get_ast_cust_config_keyword(configfile);
|
|
|
|
|
if (reg && reg->func) {
|
|
|
|
|
load_func = reg->func;
|
|
|
|
|
} else {
|
|
|
|
|
reg = get_ast_cust_config_keyword("global");
|
|
|
|
|
if (reg && reg->func)
|
|
|
|
|
global_load_func = load_func = reg->func;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (load_func) {
|
|
|
|
|
ast_log(LOG_NOTICE,"Loading Config %s via %s engine\n",configfile,reg && reg->name ? reg->name : "global");
|
|
|
|
|
tmp = load_func(configfile,tmp, _tmpc, _last, includelevel
|
|
|
|
|
#ifdef PRESERVE_COMMENTS
|
|
|
|
|
,&acs
|
|
|
|
|
#endif
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if(tmp)
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
if (tmp)
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (configfile[0] == '/') {
|
|
|
|
|
strncpy(fn, configfile, sizeof(fn)-1);
|
|
|
|
|
} else {
|
|
|
|
@ -828,80 +823,85 @@ static struct ast_config *__ast_load(char *configfile, struct ast_config *tmp, s
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ast_config_reg *get_ast_cust_config_keyword(char *name) {
|
|
|
|
|
struct ast_config_reg *get_ast_cust_config_keyword(char *name)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config_reg *reg,*ret=NULL;
|
|
|
|
|
int x=0;
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
for(reg=ast_cust_config_list;reg && !ret;reg=reg->next)
|
|
|
|
|
for(x=0;x<reg->keycount && !ret ;x++)
|
|
|
|
|
if(!strcmp(reg->keywords[x],name))
|
|
|
|
|
for (reg=ast_cust_config_list;reg && !ret;reg=reg->next) {
|
|
|
|
|
for (x=0;x<reg->keycount && !ret ;x++) {
|
|
|
|
|
if (!strcmp(reg->keywords[x],name))
|
|
|
|
|
ret=reg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ast_config_reg *get_ast_cust_config(char *name) {
|
|
|
|
|
struct ast_config_reg *get_ast_cust_config(char *name)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config_reg *ptr=NULL;
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
for(ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
|
|
|
|
|
if(!strcmp(name,ptr->name))
|
|
|
|
|
for (ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
|
|
|
|
|
if (!strcmp(name,ptr->name))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ast_config_destroy_all(void) {
|
|
|
|
|
void ast_config_destroy_all(void)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config_reg *key;
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
for(key=ast_cust_config_list;key;key=key->next) {
|
|
|
|
|
for (key=ast_cust_config_list;key;key=key->next) {
|
|
|
|
|
ast_config_deregister(key);
|
|
|
|
|
}
|
|
|
|
|
ast_cust_config_list = NULL;
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ast_config_reg *get_config_registrations(void) {
|
|
|
|
|
struct ast_config_reg *get_config_registrations(void)
|
|
|
|
|
{
|
|
|
|
|
return ast_cust_config_list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ast_config_register(struct ast_config_reg *new) {
|
|
|
|
|
int ast_config_register(struct ast_config_reg *new)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config_reg *ptr;
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
new->keycount = 0;
|
|
|
|
|
if(!ast_cust_config_list)
|
|
|
|
|
if (!ast_cust_config_list) {
|
|
|
|
|
ast_cust_config_list = new;
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
for(ptr=ast_cust_config_list;ptr->next;ptr=ptr->next);
|
|
|
|
|
ptr->next = new;
|
|
|
|
|
ptr->next = new;
|
|
|
|
|
}
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
ast_log(LOG_NOTICE,"Registered Config Engine %s\n",new->name);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ast_config_deregister(struct ast_config_reg *del) {
|
|
|
|
|
struct ast_config_reg *ptr=NULL,*last=NULL;
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
for(ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
|
|
|
|
|
if(ptr == del) {
|
|
|
|
|
if(last && ptr->next) {
|
|
|
|
|
last->next = ptr->next;
|
|
|
|
|
}
|
|
|
|
|
else if(last && ! ptr->next) {
|
|
|
|
|
last->next = NULL;
|
|
|
|
|
}
|
|
|
|
|
else if(! last && ptr->next) {
|
|
|
|
|
ast_cust_config_list = ptr->next;
|
|
|
|
|
}
|
|
|
|
|
else if(! last && ! ptr->next) {
|
|
|
|
|
ast_cust_config_list = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
last = ptr;
|
|
|
|
|
}
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
return 0;
|
|
|
|
|
int ast_config_deregister(struct ast_config_reg *del)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config_reg *ptr=NULL,*last=NULL;
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
for (ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
|
|
|
|
|
if (ptr == del) {
|
|
|
|
|
if (last && ptr->next) {
|
|
|
|
|
last->next = ptr->next;
|
|
|
|
|
} else if (last && ! ptr->next) {
|
|
|
|
|
last->next = NULL;
|
|
|
|
|
} else if (!last && ptr->next) {
|
|
|
|
|
ast_cust_config_list = ptr->next;
|
|
|
|
|
} else if (!last && !ptr->next) {
|
|
|
|
|
ast_cust_config_list = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
last = ptr;
|
|
|
|
|
}
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ast_cust_config_active(void) {
|
|
|
|
@ -959,7 +959,8 @@ char *ast_category_browse(struct ast_config *config, char *prev)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ast_config *ast_new_config(void) {
|
|
|
|
|
struct ast_config *ast_new_config(void)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config *config;
|
|
|
|
|
config = malloc(sizeof(struct ast_config));
|
|
|
|
|
memset(config,0,sizeof(struct ast_config));
|
|
|
|
@ -968,10 +969,11 @@ struct ast_config *ast_new_config(void) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ast_category *ast_new_category(char *name) {
|
|
|
|
|
struct ast_category *ast_new_category(char *name)
|
|
|
|
|
{
|
|
|
|
|
struct ast_category *category;
|
|
|
|
|
category = malloc(sizeof(struct ast_category));
|
|
|
|
|
if(category) {
|
|
|
|
|
if (category) {
|
|
|
|
|
memset(category,0,sizeof(struct ast_category));
|
|
|
|
|
strncpy(category->name,name,sizeof(category->name));
|
|
|
|
|
}
|
|
|
|
@ -979,26 +981,26 @@ struct ast_category *ast_new_category(char *name) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ast_variable *ast_new_variable(char *name,char *value) {
|
|
|
|
|
struct ast_variable *ast_new_variable(char *name, char *value)
|
|
|
|
|
{
|
|
|
|
|
struct ast_variable *variable;
|
|
|
|
|
variable = malloc(sizeof(struct ast_variable));
|
|
|
|
|
if(variable) {
|
|
|
|
|
if (variable) {
|
|
|
|
|
memset(variable,0,sizeof(struct ast_variable));
|
|
|
|
|
variable->object=0;
|
|
|
|
|
variable->name = malloc(strlen(name)+1);
|
|
|
|
|
if(variable->name) {
|
|
|
|
|
if (variable->name) {
|
|
|
|
|
strcpy(variable->name,name);
|
|
|
|
|
variable->value = malloc(strlen(value)+1);
|
|
|
|
|
if(variable->value) {
|
|
|
|
|
if (variable->value) {
|
|
|
|
|
strcpy(variable->value,value);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
free(variable->name);
|
|
|
|
|
variable->name = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!variable->value) {
|
|
|
|
|
if (!variable->value) {
|
|
|
|
|
free(variable);
|
|
|
|
|
variable = NULL;
|
|
|
|
|
}
|
|
|
|
@ -1006,23 +1008,26 @@ struct ast_variable *ast_new_variable(char *name,char *value) {
|
|
|
|
|
return variable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ast_cust_config_register(struct ast_config_reg *new) {
|
|
|
|
|
int ast_cust_config_register(struct ast_config_reg *new)
|
|
|
|
|
{
|
|
|
|
|
ast_config_register(new);
|
|
|
|
|
read_ast_cust_config();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
int ast_cust_config_deregister(struct ast_config_reg *new) {
|
|
|
|
|
int ast_cust_config_deregister(struct ast_config_reg *new)
|
|
|
|
|
{
|
|
|
|
|
ast_config_deregister(new);
|
|
|
|
|
read_ast_cust_config();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void clear_cust_keywords(void) {
|
|
|
|
|
static void clear_cust_keywords(void)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config_reg *key;
|
|
|
|
|
int x;
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
for(key=get_config_registrations();key;key=key->next) {
|
|
|
|
|
for(x=0;x<key->keycount;x++) {
|
|
|
|
|
for (key=get_config_registrations();key;key=key->next) {
|
|
|
|
|
for (x=0;x<key->keycount;x++) {
|
|
|
|
|
key->keywords[x][0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
key->keycount=0;
|
|
|
|
@ -1030,56 +1035,58 @@ static void clear_cust_keywords(void) {
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int config_command(int fd, int argc, char **argv) {
|
|
|
|
|
static int config_command(int fd, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
struct ast_config_reg *key;
|
|
|
|
|
int x;
|
|
|
|
|
|
|
|
|
|
ast_cli(fd,"\n\n");
|
|
|
|
|
ast_mutex_lock(&ast_cust_config_lock);
|
|
|
|
|
for(key=get_config_registrations();key;key=key->next) {
|
|
|
|
|
for (key=get_config_registrations();key;key=key->next) {
|
|
|
|
|
ast_cli(fd,"\nConfig Engine: %s\n",key->name);
|
|
|
|
|
for(x=0;x<key->keycount;x++)
|
|
|
|
|
for (x=0;x<key->keycount;x++)
|
|
|
|
|
ast_cli(fd,"===>%s\n",key->keywords[x]);
|
|
|
|
|
}
|
|
|
|
|
ast_mutex_unlock(&ast_cust_config_lock);
|
|
|
|
|
ast_cli(fd,"\n\n");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct ast_cli_entry config_command_struct = {
|
|
|
|
|
{ "show","config","handles", NULL }, config_command,
|
|
|
|
|
"Show Config Handles", NULL };
|
|
|
|
|
|
|
|
|
|
int register_config_cli() {
|
|
|
|
|
int register_config_cli()
|
|
|
|
|
{
|
|
|
|
|
return ast_cli_register(&config_command_struct);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int read_ast_cust_config(void) {
|
|
|
|
|
int read_ast_cust_config(void)
|
|
|
|
|
{
|
|
|
|
|
char *cfg = config_conf_file;
|
|
|
|
|
struct ast_config *config;
|
|
|
|
|
struct ast_variable *v;
|
|
|
|
|
struct ast_config_reg *ptr;
|
|
|
|
|
struct ast_config_reg *test = NULL;
|
|
|
|
|
|
|
|
|
|
clear_cust_keywords();
|
|
|
|
|
config = ast_load(cfg);
|
|
|
|
|
if(config) {
|
|
|
|
|
for(v = ast_variable_browse(config,"settings");v;v=v->next) {
|
|
|
|
|
if (config) {
|
|
|
|
|
for (v = ast_variable_browse(config,"settings");v;v=v->next) {
|
|
|
|
|
|
|
|
|
|
ptr = get_ast_cust_config(v->value);
|
|
|
|
|
if(ptr) {
|
|
|
|
|
if(ptr->keycount >= CONFIG_KEYWORD_ARRAYLEN) {
|
|
|
|
|
if (ptr) {
|
|
|
|
|
if (ptr->keycount >= CONFIG_KEYWORD_ARRAYLEN) {
|
|
|
|
|
ast_log(LOG_WARNING,"Max Number of Bindings exceeded for %s->%s %d/%d\n",v->name,v->value,ptr->keycount,CONFIG_KEYWORD_ARRAYLEN);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(strcmp(v->name,config_conf_file) && strcmp(v->name,"asterisk.conf")) {
|
|
|
|
|
if(!(test = get_ast_cust_config_keyword(v->name))) {
|
|
|
|
|
} else {
|
|
|
|
|
if (strcmp(v->name,config_conf_file) && strcmp(v->name,"asterisk.conf")) {
|
|
|
|
|
if (!(test = get_ast_cust_config_keyword(v->name))) {
|
|
|
|
|
ast_log(LOG_NOTICE,"Binding: %s to %s\n",v->name,v->value);
|
|
|
|
|
strncpy(ptr->keywords[ptr->keycount],v->name,sizeof(ptr->keywords[ptr->keycount]));
|
|
|
|
|
ptr->keycount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
ast_log(LOG_WARNING,"Cannot bind %s, Permission Denied\n",v->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1088,8 +1095,6 @@ int read_ast_cust_config(void) {
|
|
|
|
|
|
|
|
|
|
ast_destroy(config);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ast_log(LOG_WARNING,"config loader has no config file so nevermind.\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|