Cleanup formatting in config.c

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3235 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
James Golovich 21 years ago
parent 4f72a1da77
commit e5629ea138

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

Loading…
Cancel
Save