#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <time.h>#include <asterisk/config.h>#include <asterisk/config_pvt.h>#include <asterisk/cli.h>#include <asterisk/lock.h>#include <asterisk/options.h>#include <asterisk/logger.h>#include <asterisk/utils.h>#include "asterisk.h"#include "astconf.h"Go to the source code of this file.
Functions | |
| AST_MUTEX_DEFINE_STATIC (ast_cust_config_lock) | |
| void | ast_destroy (struct ast_config *ast) |
| Removes a config. | |
| int | ast_true (char *s) |
| Make sure something is true. | |
| int | ast_false (char *s) |
| Make sure something is false. | |
| ast_variable * | ast_variable_browse (struct ast_config *config, char *category) |
| Goes through variables. | |
| char * | ast_variable_retrieve (struct ast_config *config, char *category, char *value) |
| Gets a variable. | |
| int | ast_category_exist (struct ast_config *config, char *category_name) |
| Check for category duplicates. | |
| int | ast_save (char *configfile, struct ast_config *cfg, char *generator) |
| ast_config_reg * | get_ast_cust_config_keyword (char *name) |
| ast_config_reg * | get_ast_cust_config (char *name) |
| void | ast_config_destroy_all (void) |
| ast_config_reg * | get_config_registrations (void) |
| int | ast_config_register (struct ast_config_reg *new) |
| int | ast_config_deregister (struct ast_config_reg *del) |
| int | ast_cust_config_active (void) |
| ast_config * | ast_load (char *configfile) |
| Load a config file. | |
| char * | ast_category_browse (struct ast_config *config, char *prev) |
| Goes through categories. | |
| ast_config * | ast_new_config (void) |
| ast_category * | ast_new_category (char *name) |
| ast_variable * | ast_new_variable (char *name, char *value) |
| int | ast_cust_config_register (struct ast_config_reg *new) |
| int | ast_cust_config_deregister (struct ast_config_reg *new) |
| int | register_config_cli () |
| int | read_ast_cust_config (void) |
Variables | |
| ast_config *(* | global_load_func )(char *, struct ast_config *, struct ast_category **, struct ast_variable **, int) |
|
||||||||||||
|
Goes through categories.
Definition at line 936 of file config.c. References ast_category::name, ast_category::next, and ast_config::root. 00937 {
00938 struct ast_category *cat;
00939 if (!prev) {
00940 if (config->root)
00941 return config->root->name;
00942 else
00943 return NULL;
00944 }
00945 cat = config->root;
00946 while(cat) {
00947 if (cat->name == prev) {
00948 if (cat->next)
00949 return cat->next->name;
00950 else
00951 return NULL;
00952 }
00953 cat = cat->next;
00954 }
00955 cat = config->root;
00956 while(cat) {
00957 if (!strcasecmp(cat->name, prev)) {
00958 if (cat->next)
00959 return cat->next->name;
00960 else
00961 return NULL;
00962 }
00963 cat = cat->next;
00964 }
00965 return NULL;
00966 }
|
|
||||||||||||
|
Check for category duplicates.
Definition at line 399 of file config.c. References ast_category::name, ast_category::next, and ast_category::root. 00400 {
00401 struct ast_category *category = NULL;
00402
00403 category = config->root;
00404
00405 while(category) {
00406 if (!strcasecmp(category->name,category_name))
00407 return 1;
00408 category = category->next;
00409 }
00410
00411 return 0;
00412 }
|
|
|
Definition at line 892 of file config.c. References ast_mutex_lock, ast_mutex_unlock, and ast_config_reg::next. Referenced by ast_config_destroy_all(), and ast_cust_config_deregister(). 00893 {
00894 struct ast_config_reg *ptr=NULL,*last=NULL;
00895 ast_mutex_lock(&ast_cust_config_lock);
00896 for (ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
00897 if (ptr == del) {
00898 if (last && ptr->next) {
00899 last->next = ptr->next;
00900 } else if (last && ! ptr->next) {
00901 last->next = NULL;
00902 } else if (!last && ptr->next) {
00903 ast_cust_config_list = ptr->next;
00904 } else if (!last && !ptr->next) {
00905 ast_cust_config_list = NULL;
00906 }
00907 }
00908 last = ptr;
00909 }
00910 ast_mutex_unlock(&ast_cust_config_lock);
00911 return 0;
00912 }
|
|
|
Definition at line 860 of file config.c. References ast_config_deregister(), ast_mutex_lock, ast_mutex_unlock, key(), and ast_config_reg::next. 00861 {
00862 struct ast_config_reg *key;
00863 ast_mutex_lock(&ast_cust_config_lock);
00864 for (key=ast_cust_config_list;key;key=key->next) {
00865 ast_config_deregister(key);
00866 }
00867 ast_cust_config_list = NULL;
00868 ast_mutex_unlock(&ast_cust_config_lock);
00869 }
|
|
|
Definition at line 876 of file config.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_NOTICE, ast_config_reg::name, and ast_config_reg::next. Referenced by ast_cust_config_register(). 00877 {
00878 struct ast_config_reg *ptr;
00879 ast_mutex_lock(&ast_cust_config_lock);
00880 new->keycount = 0;
00881 if (!ast_cust_config_list) {
00882 ast_cust_config_list = new;
00883 } else {
00884 for(ptr=ast_cust_config_list;ptr->next;ptr=ptr->next);
00885 ptr->next = new;
00886 }
00887 ast_mutex_unlock(&ast_cust_config_lock);
00888 ast_log(LOG_NOTICE,"Registered Config Engine %s\n",new->name);
00889 return 1;
00890 }
|
|
|
Definition at line 914 of file config.c. 00914 {
00915 return (ast_cust_config >0) ? 1 : 0;
00916 }
|
|
|
Definition at line 1024 of file config.c. References ast_config_deregister(), and read_ast_cust_config(). 01025 {
01026 ast_config_deregister(new);
01027 read_ast_cust_config();
01028 return 1;
01029 }
|
|
|
Definition at line 1018 of file config.c. References ast_config_register(), and read_ast_cust_config(). 01019 {
01020 ast_config_register(new);
01021 read_ast_cust_config();
01022 return 1;
01023 }
|
|
|
Removes a config.
Definition at line 67 of file config.c. References free, ast_variable::name, ast_variable::next, ast_category::next, ast_variable::precomments, ast_config::root, ast_category::root, ast_variable::sameline, and ast_variable::value. Referenced by ast_enum_init(), ast_load_resource(), ast_rtp_reload(), init_manager(), load_modules(), and read_ast_cust_config(). 00068 {
00069 struct ast_category *cat, *catn;
00070 struct ast_variable *v, *vn;
00071
00072 if (!ast)
00073 return;
00074
00075 cat = ast->root;
00076 while(cat) {
00077 v = cat->root;
00078 while(v) {
00079 vn = v;
00080 free(v->name);
00081 free(v->value);
00082 #ifdef PRESERVE_COMMENTS
00083 free_comments(v->precomments);
00084 free_comments(v->sameline);
00085 #endif
00086 v = v->next;
00087 free(vn);
00088 }
00089 catn = cat;
00090 #ifdef PRESERVE_COMMENTS
00091 free_comments(cat->precomments);
00092 free_comments(cat->sameline);
00093 #endif
00094 cat = cat->next;
00095 free(catn);
00096 }
00097 #ifdef PRESERVE_COMMENTS
00098 free_comments(ast->trailingcomments);
00099 #endif
00100 free(ast);
00101 }
|
|
|
Make sure something is false. Determine falseness of a boolean value. This function checks to see whether a string passed to it is an indication of a negatirve value. It checks to see if the string is "no", "false", "n", "f", and "0". Returns 0 if the value of s is a NULL pointer, 0 on "truth", and -1 on falsehood. Definition at line 118 of file config.c. 00119 {
00120 if (!s)
00121 return 0;
00122 /* Determine if this is a false value */
00123 if (!strcasecmp(s, "no") ||
00124 !strcasecmp(s, "false") ||
00125 !strcasecmp(s, "n") ||
00126 !strcasecmp(s, "f") ||
00127 !strcasecmp(s, "0") ||
00128 !strcasecmp(s, "off"))
00129 return -1;
00130 return 0;
00131 }
|
|
|
Load a config file.
Definition at line 918 of file config.c. Referenced by ast_enum_init(), ast_load_resource(), ast_rtp_reload(), init_manager(), load_modules(), and read_ast_cust_config(). 00919 {
00920 struct ast_category *tmpc=NULL;
00921 struct ast_variable *last = NULL;
00922
00923
00924 #ifdef PRESERVE_COMMENTS
00925 struct ast_comment_struct acs = { NULL, NULL };
00926 #endif
00927
00928
00929 return __ast_load(configfile, NULL, &tmpc, &last, 0
00930 #ifdef PRESERVE_COMMENTS
00931 ,&acs
00932 #endif
00933 );
00934 }
|
|
|
|
|
|
Definition at line 979 of file config.c. References malloc. 00980 {
00981 struct ast_category *category;
00982 category = malloc(sizeof(struct ast_category));
00983 if (category) {
00984 memset(category,0,sizeof(struct ast_category));
00985 strncpy(category->name,name,sizeof(category->name) - 1);
00986 }
00987 return category;
00988 }
|
|
|
Definition at line 969 of file config.c. References malloc. 00970 {
00971 struct ast_config *config;
00972 config = malloc(sizeof(struct ast_config));
00973 memset(config,0,sizeof(struct ast_config));
00974 return config;
00975 }
|
|
||||||||||||
|
Definition at line 991 of file config.c. References free, malloc, and ast_variable::value. 00992 {
00993 struct ast_variable *variable;
00994 variable = malloc(sizeof(struct ast_variable));
00995 if (variable) {
00996 memset(variable,0,sizeof(struct ast_variable));
00997 variable->object=0;
00998 variable->name = malloc(strlen(name)+1);
00999 if (variable->name) {
01000 strcpy(variable->name,name);
01001 variable->value = malloc(strlen(value)+1);
01002 if (variable->value) {
01003 strcpy(variable->value,value);
01004 } else {
01005 free(variable->name);
01006 variable->name = NULL;
01007 }
01008 }
01009 }
01010 if (!variable->value) {
01011 free(variable);
01012 variable = NULL;
01013 }
01014
01015 return variable;
01016 }
|
|
||||||||||||||||
|
Definition at line 653 of file config.c. References AST_CONFIG_DIR, ast_verbose(), ast_variable::blanklines, ast_comment::cmt, ast_category::name, ast_variable::name, ast_variable::next, ast_category::next, ast_variable::object, option_debug, option_verbose, ast_variable::precomments, ast_config::root, ast_category::root, ast_variable::sameline, ast_variable::value, and VERBOSE_PREFIX_2. 00654 {
00655 FILE *f;
00656 char fn[256];
00657 char date[256]="";
00658 time_t t;
00659 struct ast_variable *var;
00660 struct ast_category *cat;
00661 int blanklines = 0;
00662 if (configfile[0] == '/') {
00663 strncpy(fn, configfile, sizeof(fn)-1);
00664 } else {
00665 snprintf(fn, sizeof(fn), "%s/%s", AST_CONFIG_DIR, configfile);
00666 }
00667 time(&t);
00668 strncpy(date, ctime(&t), sizeof(date) - 1);
00669 if ((f = fopen(fn, "w"))) {
00670 if ((option_verbose > 1) && !option_debug)
00671 ast_verbose( VERBOSE_PREFIX_2 "Saving '%s': ", fn);
00672 fprintf(f, ";!\n");
00673 fprintf(f, ";! Automatically generated configuration file\n");
00674 fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
00675 fprintf(f, ";! Generator: %s\n", generator);
00676 fprintf(f, ";! Creation Date: %s", date);
00677 fprintf(f, ";!\n");
00678 cat = cfg->root;
00679 while(cat) {
00680 #ifdef PRESERVE_COMMENTS
00681 /* Dump any precomments */
00682 dump_comments(f, cat->precomments);
00683 #endif
00684 /* Dump section with any appropriate comment */
00685 #ifdef PRESERVE_COMMENTS
00686 if (cat->sameline)
00687 fprintf(f, "[%s] ; %s\n", cat->name, cat->sameline->cmt);
00688 else
00689 #endif
00690 fprintf(f, "[%s]\n", cat->name);
00691 var = cat->root;
00692 while(var) {
00693 #ifdef PRESERVE_COMMENTS
00694 dump_comments(f, var->precomments);
00695 #endif
00696 if (var->sameline)
00697 fprintf(f, "%s %s %s ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
00698 else
00699 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
00700 if (var->blanklines) {
00701 blanklines = var->blanklines;
00702 while (blanklines) {
00703 fprintf(f, "\n");
00704 blanklines--;
00705 }
00706 }
00707
00708 var = var->next;
00709 }
00710 #if 0
00711 /* Put an empty line */
00712 fprintf(f, "\n");
00713 #endif
00714 cat = cat->next;
00715 }
00716 #ifdef PRESERVE_COMMENTS
00717 dump_comments(f, cfg->trailingcomments);
00718 #endif
00719 } else {
00720 if (option_debug)
00721 printf("Unable to open for writing: %s\n", fn);
00722 else if (option_verbose > 1)
00723 printf( "Unable to write (%s)", strerror(errno));
00724 return -1;
00725 }
00726 fclose(f);
00727 return 0;
00728 }
|
|
|
Make sure something is true. Determine affermativeness of a boolean value. This function checks to see whether a string passed to it is an indication of an affirmitave value. It checks to see if the string is "yes", "true", "y", "t", and "1". Returns 0 if the value of s is a NULL pointer, 0 on "truth", and -1 on falsehood. Definition at line 103 of file config.c. Referenced by ast_load_resource(), ast_rtp_reload(), init_manager(), and load_modules(). 00104 {
00105 if (!s)
00106 return 0;
00107 /* Determine if this is a true value */
00108 if (!strcasecmp(s, "yes") ||
00109 !strcasecmp(s, "true") ||
00110 !strcasecmp(s, "y") ||
00111 !strcasecmp(s, "t") ||
00112 !strcasecmp(s, "1") ||
00113 !strcasecmp(s, "on"))
00114 return -1;
00115 return 0;
00116 }
|
|
||||||||||||
|
Goes through variables. Somewhat similar in intent as the ast_category_browse. The category MUST be an actual pointer to an actual category (such as one obtained by using ast_category_browse()). List variables of config file Returns ast_variable list on success, or NULL on failure Definition at line 133 of file config.c. References ast_category::name, ast_category::next, ast_config::root, and ast_category::root. Referenced by ast_enum_init(), ast_variable_retrieve(), load_modules(), and read_ast_cust_config(). 00134 {
00135 struct ast_category *cat;
00136 cat = config->root;
00137 while(cat) {
00138 if (cat->name == category)
00139 return cat->root;
00140 cat = cat->next;
00141 }
00142 cat = config->root;
00143 while(cat) {
00144 if (!strcasecmp(cat->name, category))
00145 return cat->root;
00146 cat = cat->next;
00147 }
00148 return NULL;
00149 }
|
|
||||||||||||||||
|
Gets a variable.
Definition at line 151 of file config.c. References ast_variable_browse(), ast_variable::name, ast_variable::next, ast_category::next, ast_category::root, and ast_variable::value. Referenced by ast_load_resource(), ast_rtp_reload(), init_manager(), and load_modules(). 00152 {
00153 struct ast_variable *v;
00154 if (category) {
00155 v = ast_variable_browse(config, category);
00156 while (v) {
00157 if (value == v->name)
00158 return v->value;
00159 v=v->next;
00160 }
00161 v = ast_variable_browse(config, category);
00162 while (v) {
00163 if (!strcasecmp(value, v->name))
00164 return v->value;
00165 v=v->next;
00166 }
00167 } else {
00168 struct ast_category *cat;
00169 cat = config->root;
00170 while(cat) {
00171 v = cat->root;
00172 while (v) {
00173 if (!strcasecmp(value, v->name))
00174 return v->value;
00175 v=v->next;
00176 }
00177 cat = cat->next;
00178 }
00179 }
00180 return NULL;
00181 }
|
|
|
Definition at line 848 of file config.c. References ast_mutex_lock, ast_mutex_unlock, ast_config_reg::name, and ast_config_reg::next. Referenced by read_ast_cust_config(). 00849 {
00850 struct ast_config_reg *ptr=NULL;
00851 ast_mutex_lock(&ast_cust_config_lock);
00852 for (ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
00853 if (!strcmp(name,ptr->name))
00854 break;
00855 }
00856 ast_mutex_unlock(&ast_cust_config_lock);
00857 return ptr;
00858 }
|
|
|
Definition at line 833 of file config.c. References ast_mutex_lock, ast_mutex_unlock, ast_config_reg::keycount, ast_config_reg::keywords, and ast_config_reg::next. Referenced by read_ast_cust_config(). 00834 {
00835 struct ast_config_reg *reg,*ret=NULL;
00836 int x=0;
00837 ast_mutex_lock(&ast_cust_config_lock);
00838 for (reg=ast_cust_config_list;reg && !ret;reg=reg->next) {
00839 for (x=0;x<reg->keycount && !ret ;x++) {
00840 if (!strcmp(reg->keywords[x],name))
00841 ret=reg;
00842 }
00843 }
00844 ast_mutex_unlock(&ast_cust_config_lock);
00845 return ret;
00846 }
|
|
|
Definition at line 871 of file config.c. 00872 {
00873 return ast_cust_config_list;
00874 }
|
|
|
Definition at line 1072 of file config.c. References ast_destroy(), ast_load(), ast_log(), ast_variable_browse(), CONFIG_KEYWORD_ARRAYLEN, get_ast_cust_config(), get_ast_cust_config_keyword(), ast_config_reg::keycount, ast_config_reg::keywords, LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, and ast_variable::value. Referenced by ast_cust_config_deregister(), ast_cust_config_register(), ast_module_reload(), and main(). 01073 {
01074 char *cfg = config_conf_file;
01075 struct ast_config *config;
01076 struct ast_variable *v;
01077 struct ast_config_reg *ptr;
01078 struct ast_config_reg *test = NULL;
01079
01080 clear_cust_keywords();
01081 config = ast_load(cfg);
01082 if (config) {
01083 for (v = ast_variable_browse(config,"settings");v;v=v->next) {
01084
01085 ptr = get_ast_cust_config(v->value);
01086 if (ptr) {
01087 if (ptr->keycount >= CONFIG_KEYWORD_ARRAYLEN) {
01088 ast_log(LOG_WARNING,"Max Number of Bindings exceeded for %s->%s %d/%d\n",v->name,v->value,ptr->keycount,CONFIG_KEYWORD_ARRAYLEN);
01089 } else {
01090 if (strcmp(v->name,config_conf_file) && strcmp(v->name,"asterisk.conf")) {
01091 if (!(test = get_ast_cust_config_keyword(v->name))) {
01092 ast_log(LOG_NOTICE,"Binding: %s to %s\n",v->name,v->value);
01093 strncpy(ptr->keywords[ptr->keycount],v->name,sizeof(ptr->keywords[ptr->keycount]) - 1);
01094 ptr->keywords[ptr->keycount][sizeof(ptr->keywords[ptr->keycount])-1] = '\0';
01095 ptr->keycount++;
01096 }
01097 } else {
01098 ast_log(LOG_WARNING,"Cannot bind %s, Permission Denied\n",v->name);
01099 }
01100 }
01101 }
01102 }
01103
01104 ast_destroy(config);
01105 }
01106
01107 return 0;
01108 }
|
|
|
Definition at line 1067 of file config.c. References ast_cli_register(). Referenced by main(). 01068 {
01069 return ast_cli_register(&config_command_struct);
01070 }
|
|
|
|
1.4.2