[asterisk-commits] rizzo: trunk r91983 - /trunk/main/config.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Dec 8 13:06:02 CST 2007
Author: rizzo
Date: Sat Dec 8 13:06:01 2007
New Revision: 91983
URL: http://svn.digium.com/view/asterisk?view=rev&rev=91983
Log:
remove unused code, and simplify the logic for #include/#exec
(still a lot of cleanup needed here).
Modified:
trunk/main/config.c
Modified: trunk/main/config.c
URL: http://svn.digium.com/view/asterisk/trunk/main/config.c?view=diff&rev=91983&r1=91982&r2=91983
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Sat Dec 8 13:06:01 2007
@@ -937,7 +937,10 @@
if (newcat)
ast_category_append(cfg, *cat);
} else if (cur[0] == '#') { /* A directive - #include or #exec */
- int do_exec, do_include;
+ char *cur2;
+ char real_inclusion_name[256];
+ struct ast_config_include *inclu;
+ int do_include = 0; /* otherwise, it is exec */
cur++;
c = cur;
@@ -950,21 +953,27 @@
c = NULL;
} else
c = NULL;
- do_include = !strcasecmp(cur, "include");
- if (!do_include)
- do_exec = !strcasecmp(cur, "exec");
- else
- do_exec = 0;
- if (do_exec && !ast_opt_exec_includes) {
- ast_log(LOG_WARNING, "Cannot perform #exec unless execincludes option is enabled in asterisk.conf (options section)!\n");
- do_exec = 0;
- }
- if (do_include || do_exec) {
- if (c) {
- char *cur2;
- char real_inclusion_name[256];
- struct ast_config_include *inclu;
-
+ if (!strcasecmp(cur, "include")) {
+ do_include = 1;
+ } else if (!strcasecmp(cur, "exec")) {
+ if (!ast_opt_exec_includes) {
+ ast_log(LOG_WARNING, "Cannot perform #exec unless execincludes option is enabled in asterisk.conf (options section)!\n");
+ return 0; /* XXX is this correct ? or we should return -1 ? */
+ }
+ } else {
+ ast_log(LOG_WARNING, "Unknown directive '%s' at line %d of %s\n", cur, lineno, configfile);
+ return 0; /* XXX is this correct ? or we should return -1 ? */
+ }
+
+ if (c == NULL) {
+ ast_log(LOG_WARNING, "Directive '#%s' needs an argument (%s) at line %d of %s\n",
+ do_include ? "include" : "exec",
+ do_include ? "filename" : "/path/to/executable",
+ lineno,
+ configfile);
+ return 0; /* XXX is this correct ? or we should return -1 ? */
+ }
+
/* Strip off leading and trailing "'s and <>'s */
while ((*c == '<') || (*c == '>') || (*c == '\"')) c++;
/* Get rid of leading mess */
@@ -979,7 +988,7 @@
}
/* #exec </path/to/executable>
We create a tmp file, then we #include it, then we delete it. */
- if (do_exec) {
+ if (!do_include) {
if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE))
config_cache_attribute(configfile, ATTRIBUTE_EXEC, NULL);
snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d.%ld", (int)time(NULL), (long)pthread_self());
@@ -993,24 +1002,15 @@
}
/* A #include */
/* record this inclusion */
- inclu = ast_include_new(cfg, configfile, cur, do_exec, cur2, lineno, real_inclusion_name, sizeof(real_inclusion_name));
+ inclu = ast_include_new(cfg, configfile, cur, !do_include, cur2, lineno, real_inclusion_name, sizeof(real_inclusion_name));
do_include = ast_config_internal_load(cur, cfg, flags, real_inclusion_name) ? 1 : 0;
if (!ast_strlen_zero(exec_file))
unlink(exec_file);
if (!do_include)
return 0;
-
- } else {
- ast_log(LOG_WARNING, "Directive '#%s' needs an argument (%s) at line %d of %s\n",
- do_exec ? "exec" : "include",
- do_exec ? "/path/to/executable" : "filename",
- lineno,
- configfile);
- }
- }
- else
- ast_log(LOG_WARNING, "Unknown directive '%s' at line %d of %s\n", cur, lineno, configfile);
+ /* XXX otherwise what ? the default return is 0 anyways */
+
} else {
/* Just a line (variable = value) */
if (!(*cat)) {
@@ -1071,14 +1071,8 @@
struct ast_variable *last_var = 0;
struct ast_category *last_cat = 0;
/*! Growable string buffer */
- struct ast_str *comment_buffer = NULL, *lline_buffer = NULL;
-#if 0
- char *comment_buffer=0; /*!< this will be a comment collector.*/
- int comment_buffer_size=0; /*!< the amount of storage so far alloc'd for the comment_buffer */
-
- char *lline_buffer=0; /*!< A buffer for stuff behind the ; */
- int lline_buffer_size=0;
-#endif
+ struct ast_str *comment_buffer = NULL; /*!< this will be a comment collector.*/
+ struct ast_str *lline_buffer = NULL; /*!< A buffer for stuff behind the ; */
if (cfg)
cat = ast_config_get_current_category(cfg);
More information about the asterisk-commits
mailing list