mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
config: Fix indentation and missing curlies in config_text_file_load().
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@415288 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1687,9 +1687,14 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
/*! Growable string buffer */
|
/*! Growable string buffer */
|
||||||
struct ast_str *comment_buffer = NULL; /*!< this will be a comment collector.*/
|
struct ast_str *comment_buffer = NULL; /*!< this will be a comment collector.*/
|
||||||
struct ast_str *lline_buffer = NULL; /*!< A buffer for stuff behind the ; */
|
struct ast_str *lline_buffer = NULL; /*!< A buffer for stuff behind the ; */
|
||||||
|
#ifdef AST_INCLUDE_GLOB
|
||||||
|
int glob_ret;
|
||||||
|
glob_t globbuf;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (cfg)
|
if (cfg) {
|
||||||
cat = ast_config_get_current_category(cfg);
|
cat = ast_config_get_current_category(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
if (filename[0] == '/') {
|
if (filename[0] == '/') {
|
||||||
ast_copy_string(fn, filename, sizeof(fn));
|
ast_copy_string(fn, filename, sizeof(fn));
|
||||||
@@ -1699,8 +1704,9 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
|
|
||||||
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
|
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
|
||||||
comment_buffer = ast_str_create(CB_SIZE);
|
comment_buffer = ast_str_create(CB_SIZE);
|
||||||
if (comment_buffer)
|
if (comment_buffer) {
|
||||||
lline_buffer = ast_str_create(CB_SIZE);
|
lline_buffer = ast_str_create(CB_SIZE);
|
||||||
|
}
|
||||||
if (!lline_buffer) {
|
if (!lline_buffer) {
|
||||||
ast_free(comment_buffer);
|
ast_free(comment_buffer);
|
||||||
ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
|
ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
|
||||||
@@ -1708,10 +1714,6 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef AST_INCLUDE_GLOB
|
#ifdef AST_INCLUDE_GLOB
|
||||||
{
|
|
||||||
int glob_ret;
|
|
||||||
glob_t globbuf;
|
|
||||||
|
|
||||||
globbuf.gl_offs = 0; /* initialize it to silence gcc */
|
globbuf.gl_offs = 0; /* initialize it to silence gcc */
|
||||||
glob_ret = glob(fn, MY_GLOB_FLAGS, NULL, &globbuf);
|
glob_ret = glob(fn, MY_GLOB_FLAGS, NULL, &globbuf);
|
||||||
if (glob_ret == GLOB_NOSPACE) {
|
if (glob_ret == GLOB_NOSPACE) {
|
||||||
@@ -1765,9 +1767,10 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
/* Find our cached entry for this configuration file */
|
/* Find our cached entry for this configuration file */
|
||||||
AST_LIST_LOCK(&cfmtime_head);
|
AST_LIST_LOCK(&cfmtime_head);
|
||||||
AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
|
AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
|
||||||
if (!strcmp(cfmtime->filename, fn) && !strcmp(cfmtime->who_asked, who_asked))
|
if (!strcmp(cfmtime->filename, fn) && !strcmp(cfmtime->who_asked, who_asked)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!cfmtime) {
|
if (!cfmtime) {
|
||||||
cfmtime = cfmtime_new(fn, who_asked);
|
cfmtime = cfmtime_new(fn, who_asked);
|
||||||
if (!cfmtime) {
|
if (!cfmtime) {
|
||||||
@@ -1847,18 +1850,24 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && lline_buffer && ast_str_strlen(lline_buffer)) {
|
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)
|
||||||
|
&& lline_buffer
|
||||||
|
&& ast_str_strlen(lline_buffer)) {
|
||||||
CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer)); /* add the current lline buffer to the comment buffer */
|
CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer)); /* add the current lline buffer to the comment buffer */
|
||||||
ast_str_reset(lline_buffer); /* erase the lline buffer */
|
ast_str_reset(lline_buffer); /* erase the lline buffer */
|
||||||
}
|
}
|
||||||
|
|
||||||
new_buf = buf;
|
new_buf = buf;
|
||||||
if (comment)
|
if (comment) {
|
||||||
process_buf = NULL;
|
process_buf = NULL;
|
||||||
else
|
} else {
|
||||||
process_buf = buf;
|
process_buf = buf;
|
||||||
|
}
|
||||||
|
|
||||||
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && ast_str_strlen(comment_buffer) && (ast_strlen_zero(buf) || strlen(buf) == strspn(buf," \t\n\r"))) {
|
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)
|
||||||
|
&& comment_buffer
|
||||||
|
&& ast_str_strlen(comment_buffer)
|
||||||
|
&& (ast_strlen_zero(buf) || strlen(buf) == strspn(buf," \t\n\r"))) {
|
||||||
/* blank line? really? Can we add it to an existing comment and maybe preserve inter- and post- comment spacing? */
|
/* blank line? really? Can we add it to an existing comment and maybe preserve inter- and post- comment spacing? */
|
||||||
CB_ADD(&comment_buffer, "\n"); /* add a newline to the comment buffer */
|
CB_ADD(&comment_buffer, "\n"); /* add a newline to the comment buffer */
|
||||||
continue; /* go get a new line, then */
|
continue; /* go get a new line, then */
|
||||||
@@ -1891,6 +1900,7 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
if (process_buf) {
|
if (process_buf) {
|
||||||
/* Actually have to move what's left over the top, then continue */
|
/* Actually have to move what's left over the top, then continue */
|
||||||
char *oldptr;
|
char *oldptr;
|
||||||
|
|
||||||
oldptr = process_buf + strlen(process_buf);
|
oldptr = process_buf + strlen(process_buf);
|
||||||
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
|
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
|
||||||
CB_ADD(&comment_buffer, ";");
|
CB_ADD(&comment_buffer, ";");
|
||||||
@@ -1899,9 +1909,10 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
|
|
||||||
memmove(oldptr, new_buf, strlen(new_buf) + 1);
|
memmove(oldptr, new_buf, strlen(new_buf) + 1);
|
||||||
new_buf = oldptr;
|
new_buf = oldptr;
|
||||||
} else
|
} else {
|
||||||
process_buf = new_buf;
|
process_buf = new_buf;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!comment) {
|
if (!comment) {
|
||||||
/* If ; is found, and we are not nested in a comment,
|
/* If ; is found, and we are not nested in a comment,
|
||||||
@@ -1911,18 +1922,23 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
}
|
}
|
||||||
*comment_p = '\0';
|
*comment_p = '\0';
|
||||||
new_buf = comment_p;
|
new_buf = comment_p;
|
||||||
} else
|
} else {
|
||||||
new_buf = comment_p + 1;
|
new_buf = comment_p + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment && !process_buf ) {
|
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment && !process_buf ) {
|
||||||
CB_ADD(&comment_buffer, buf); /* the whole line is a comment, store it */
|
CB_ADD(&comment_buffer, buf); /* the whole line is a comment, store it */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process_buf) {
|
if (process_buf) {
|
||||||
char *buffer = ast_strip(process_buf);
|
char *buffer = ast_strip(process_buf);
|
||||||
|
|
||||||
if (!ast_strlen_zero(buffer)) {
|
if (!ast_strlen_zero(buffer)) {
|
||||||
if (process_text_line(cfg, &cat, buffer, lineno, fn, flags, comment_buffer, lline_buffer, suggested_include_file, &last_cat, &last_var, who_asked)) {
|
if (process_text_line(cfg, &cat, buffer, lineno, fn,
|
||||||
|
flags, comment_buffer, lline_buffer,
|
||||||
|
suggested_include_file, &last_cat, &last_var,
|
||||||
|
who_asked)) {
|
||||||
cfg = CONFIG_STATUS_FILEINVALID;
|
cfg = CONFIG_STATUS_FILEINVALID;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1952,8 +1968,9 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
ast_debug(1, "Nothing to attach comments to, discarded: %s\n", ast_str_buffer(comment_buffer));
|
ast_debug(1, "Nothing to attach comments to, discarded: %s\n", ast_str_buffer(comment_buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS))
|
if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
|
||||||
CB_RESET(comment_buffer, lline_buffer);
|
CB_RESET(comment_buffer, lline_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
} while (0);
|
} while (0);
|
||||||
@@ -1967,14 +1984,14 @@ static struct ast_config *config_text_file_load(const char *database, const char
|
|||||||
}
|
}
|
||||||
globfree(&globbuf);
|
globfree(&globbuf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ast_free(comment_buffer);
|
ast_free(comment_buffer);
|
||||||
ast_free(lline_buffer);
|
ast_free(lline_buffer);
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user