#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <asterisk/config.h>
#include <asterisk/options.h>
#include <asterisk/logger.h>
#include "asterisk.h"
#include "astconf.h"
Go to the source code of this file.
Data Structures | |
struct | ast_category |
struct | ast_config |
Defines | |
#define | MAX_INCLUDE_LEVEL 10 |
Functions | |
void | ast_destroy (struct ast_config *ast) |
Removes a config. | |
int | ast_true (char *s) |
Make sure something is true. | |
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 * | ast_load (char *configfile) |
Load a config file. | |
char * | ast_category_browse (struct ast_config *config, char *prev) |
Goes through categories. |
|
|
|
Goes through categories.
Definition at line 773 of file config.c. References ast_category::name, ast_category::next, and ast_config::root.
00774 { 00775 struct ast_category *cat; 00776 if (!prev) { 00777 if (config->root) 00778 return config->root->name; 00779 else 00780 return NULL; 00781 } 00782 cat = config->root; 00783 while(cat) { 00784 if (cat->name == prev) { 00785 if (cat->next) 00786 return cat->next->name; 00787 else 00788 return NULL; 00789 } 00790 cat = cat->next; 00791 } 00792 cat = config->root; 00793 while(cat) { 00794 if (!strcasecmp(cat->name, prev)) { 00795 if (cat->next) 00796 return cat->next->name; 00797 else 00798 return NULL; 00799 } 00800 cat = cat->next; 00801 } 00802 return NULL; 00803 } |
|
Check for category duplicates.
Definition at line 397 of file config.c. References ast_category::next, and ast_config::root.
00398 { 00399 struct ast_category *category = NULL; 00400 00401 category = config->root; 00402 00403 while(category) { 00404 if (!strcasecmp(category->name,category_name)) 00405 return 1; 00406 category = category->next; 00407 } 00408 00409 return 0; 00410 } |
|
Removes a config.
Definition at line 81 of file config.c. References free, ast_config::root, and ast_category::root. Referenced by ast_enum_init(), ast_load_resource(), ast_rtp_reload(), init_manager(), and load_modules().
00082 { 00083 struct ast_category *cat, *catn; 00084 struct ast_variable *v, *vn; 00085 00086 if (!ast) 00087 return; 00088 00089 cat = ast->root; 00090 while(cat) { 00091 v = cat->root; 00092 while(v) { 00093 vn = v; 00094 free(v->name); 00095 free(v->value); 00096 #ifdef PRESERVE_COMMENTS 00097 free_comments(v->precomments); 00098 free_comments(v->sameline); 00099 #endif 00100 v = v->next; 00101 free(vn); 00102 } 00103 catn = cat; 00104 #ifdef PRESERVE_COMMENTS 00105 free_comments(cat->precomments); 00106 free_comments(cat->sameline); 00107 #endif 00108 cat = cat->next; 00109 free(catn); 00110 } 00111 #ifdef PRESERVE_COMMENTS 00112 free_comments(ast->trailingcomments); 00113 #endif 00114 free(ast); 00115 } |
|
Load a config file.
Definition at line 759 of file config.c. Referenced by ast_enum_init(), ast_load_resource(), ast_rtp_reload(), init_manager(), and load_modules().
00760 { 00761 struct ast_category *tmpc=NULL; 00762 struct ast_variable *last = NULL; 00763 #ifdef PRESERVE_COMMENTS 00764 struct ast_comment_struct acs = { NULL, NULL }; 00765 #endif 00766 return __ast_load(configfile, NULL, &tmpc, &last, 0 00767 #ifdef PRESERVE_COMMENTS 00768 ,&acs 00769 #endif 00770 ); 00771 } |
|
Definition at line 612 of file config.c. References AST_CONFIG_DIR, ast_verbose(), option_debug, option_verbose, ast_config::root, and VERBOSE_PREFIX_2.
00613 { 00614 FILE *f; 00615 char fn[256]; 00616 char date[256]; 00617 time_t t; 00618 struct ast_variable *var; 00619 struct ast_category *cat; 00620 int blanklines = 0; 00621 if (configfile[0] == '/') { 00622 strncpy(fn, configfile, sizeof(fn)-1); 00623 } else { 00624 snprintf(fn, sizeof(fn), "%s/%s", AST_CONFIG_DIR, configfile); 00625 } 00626 time(&t); 00627 strncpy(date, ctime(&t), sizeof(date)); 00628 if ((f = fopen(fn, "w"))) { 00629 if ((option_verbose > 1) && !option_debug) 00630 ast_verbose( VERBOSE_PREFIX_2 "Saving '%s': ", fn); 00631 fprintf(f, ";!\n"); 00632 fprintf(f, ";! Automatically generated configuration file\n"); 00633 fprintf(f, ";! Filename: %s (%s)\n", configfile, fn); 00634 fprintf(f, ";! Generator: %s\n", generator); 00635 fprintf(f, ";! Creation Date: %s", date); 00636 fprintf(f, ";!\n"); 00637 cat = cfg->root; 00638 while(cat) { 00639 #ifdef PRESERVE_COMMENTS 00640 /* Dump any precomments */ 00641 dump_comments(f, cat->precomments); 00642 #endif 00643 /* Dump section with any appropriate comment */ 00644 #ifdef PRESERVE_COMMENTS 00645 if (cat->sameline) 00646 fprintf(f, "[%s] ; %s\n", cat->name, cat->sameline->cmt); 00647 else 00648 #endif 00649 fprintf(f, "[%s]\n", cat->name); 00650 var = cat->root; 00651 while(var) { 00652 #ifdef PRESERVE_COMMENTS 00653 dump_comments(f, var->precomments); 00654 #endif 00655 if (var->sameline) 00656 fprintf(f, "%s %s %s ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt); 00657 else 00658 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value); 00659 if (var->blanklines) { 00660 blanklines = var->blanklines; 00661 while (blanklines) { 00662 fprintf(f, "\n"); 00663 blanklines--; 00664 } 00665 } 00666 00667 var = var->next; 00668 } 00669 #if 0 00670 /* Put an empty line */ 00671 fprintf(f, "\n"); 00672 #endif 00673 cat = cat->next; 00674 } 00675 #ifdef PRESERVE_COMMENTS 00676 dump_comments(f, cfg->trailingcomments); 00677 #endif 00678 } else { 00679 if (option_debug) 00680 printf("Unable to open for writing: %s\n", fn); 00681 else if (option_verbose > 1) 00682 printf( "Unable to write (%s)", strerror(errno)); 00683 return -1; 00684 } 00685 fclose(f); 00686 return 0; 00687 } |
|
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 117 of file config.c. References s. Referenced by ast_load_resource(), init_manager(), and load_modules().
00118 { 00119 if (!s) 00120 return 0; 00121 /* Determine if this is a true value */ 00122 if (!strcasecmp(s, "yes") || 00123 !strcasecmp(s, "true") || 00124 !strcasecmp(s, "y") || 00125 !strcasecmp(s, "t") || 00126 !strcasecmp(s, "1")) 00127 return -1; 00128 return 0; 00129 } |
|
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 131 of file config.c. References ast_variable::next, ast_config::root, and ast_category::root. Referenced by ast_enum_init(), ast_variable_retrieve(), and load_modules().
00132 { 00133 struct ast_category *cat; 00134 cat = config->root; 00135 while(cat) { 00136 if (cat->name == category) 00137 return cat->root; 00138 cat = cat->next; 00139 } 00140 cat = config->root; 00141 while(cat) { 00142 if (!strcasecmp(cat->name, category)) 00143 return cat->root; 00144 cat = cat->next; 00145 } 00146 return NULL; 00147 } |
|
Gets a variable.
Definition at line 149 of file config.c. References ast_variable_browse(), ast_config::root, ast_category::root, and ast_variable::value. Referenced by ast_load_resource(), ast_rtp_reload(), init_manager(), and load_modules().
00150 { 00151 struct ast_variable *v; 00152 if (category) { 00153 v = ast_variable_browse(config, category); 00154 while (v) { 00155 if (value == v->name) 00156 return v->value; 00157 v=v->next; 00158 } 00159 v = ast_variable_browse(config, category); 00160 while (v) { 00161 if (!strcasecmp(value, v->name)) 00162 return v->value; 00163 v=v->next; 00164 } 00165 } else { 00166 struct ast_category *cat; 00167 cat = config->root; 00168 while(cat) { 00169 v = cat->root; 00170 while (v) { 00171 if (!strcasecmp(value, v->name)) 00172 return v->value; 00173 v=v->next; 00174 } 00175 cat = cat->next; 00176 } 00177 } 00178 return NULL; 00179 } |