[asterisk-commits] jpeeler: branch jpeeler/manager-configactions r102963 - /team/jpeeler/manager...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 7 17:18:29 CST 2008
Author: jpeeler
Date: Thu Feb 7 17:18:28 2008
New Revision: 102963
URL: http://svn.digium.com/view/asterisk?view=rev&rev=102963
Log:
fixed syntax errors, stupid mistakes, and used more efficient coding
Modified:
team/jpeeler/manager-configactions/main/config.c
team/jpeeler/manager-configactions/main/manager.c
Modified: team/jpeeler/manager-configactions/main/config.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/manager-configactions/main/config.c?view=diff&rev=102963&r1=102962&r2=102963
==============================================================================
--- team/jpeeler/manager-configactions/main/config.c (original)
+++ team/jpeeler/manager-configactions/main/config.c Thu Feb 7 17:18:28 2008
@@ -358,16 +358,17 @@
{
struct ast_variable *cur = category->root;
int lineno;
-
- if (!variable)
+ int insertline;
+
+ if (!variable || !sscanf(line, "%d", &insertline))
return;
if (atoi(line) == 0) {
variable->next = category->root;
category->root = variable;
} else {
- for(lineno = 1; lineno < atoi(line); lineno++) {
+ for (lineno = 1; lineno < insertline; lineno++) {
cur = cur->next;
- if (cur->next == NULL)
+ if (!cur->next)
break;
}
variable->next = cur->next;
@@ -788,12 +789,12 @@
struct ast_category *cat;
for (cat = cfg->root; cat; cat = cat->next) {
- if (!strcasecmp(cat->name, category)) {
- ast_variables_destroy(cat->root);
- cat->root = NULL;
- cat->last = NULL;
- return 0;
- }
+ if (!strcasecmp(cat->name, category))
+ continue;
+ ast_variables_destroy(cat->root);
+ cat->root = NULL;
+ cat->last = NULL;
+ return 0;
}
return -1;
Modified: team/jpeeler/manager-configactions/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/manager-configactions/main/manager.c?view=diff&rev=102963&r1=102962&r2=102963
==============================================================================
--- team/jpeeler/manager-configactions/main/manager.c (original)
+++ team/jpeeler/manager-configactions/main/manager.c Thu Feb 7 17:18:28 2008
@@ -51,8 +51,6 @@
#include <sys/time.h>
#include <signal.h>
#include <sys/mman.h>
-#include <stdio.h>
-#include <unistd.h>
#include "asterisk/channel.h"
#include "asterisk/file.h"
@@ -76,9 +74,8 @@
#include "asterisk/term.h"
#include "asterisk/astobj2.h"
-enum
-{
- UNKNOWN_ACTION,
+enum error_type {
+ UNKNOWN_ACTION = 1,
UNKNOWN_CATEGORY,
UNSPECIFIED_CATEGORY,
UNSPECIFIED_ARGUMENT,
@@ -1082,7 +1079,7 @@
const char *category = astman_get_header(m, "Category");
int catcount = 0;
int lineno = 0;
- char *cur_category=NULL;
+ char *cur_category = NULL;
struct ast_variable *v;
struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
@@ -1114,8 +1111,8 @@
}
static char mandescr_listcategories[] =
-"Description: A 'ListCategories' action will dump the contents of a category\n"
-"in a given file.\n"
+"Description: A 'ListCategories' action will dump the categories in\n"
+"a given file.\n"
"Variables:\n"
" Filename: Configuration filename (e.g. foo.conf)\n";
@@ -1123,7 +1120,7 @@
{
struct ast_config *cfg;
const char *fn = astman_get_header(m, "Filename");
- char *category=NULL;
+ char *category = NULL;
struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
int catcount = 0;
@@ -1132,7 +1129,7 @@
return 0;
}
if (!(cfg = ast_config_load(fn, config_flags))) {
- astman_send_error(s, m, "Config file not found");
+ astman_send_error(s, m, "Config file not found or file has invalid syntax");
return 0;
}
astman_start_ack(s, m);
@@ -1233,7 +1230,7 @@
}
/* helper function for action_updateconfig */
-static int handle_updates(struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn)
+static enum error_type handle_updates(struct mansession *s, const struct message *m, struct ast_config *cfg, const char *dfn)
{
int x;
char hdr[40];
@@ -1347,7 +1344,7 @@
int res;
const char *rld = astman_get_header(m, "Reload");
struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS | CONFIG_FLAG_NOCACHE };
- int result;
+ enum error_type result;
if (ast_strlen_zero(sfn) || ast_strlen_zero(dfn)) {
astman_send_error(s, m, "Filename not specified");
@@ -1373,6 +1370,7 @@
ast_module_reload(rld);
}
} else {
+ ast_config_destroy(cfg);
switch(result) {
case UNKNOWN_ACTION:
astman_send_error(s, m, "Unknown action command");
@@ -1418,18 +1416,17 @@
static int action_createconfig(struct mansession *s, const struct message *m)
{
+ int fd;
const char *fn = astman_get_header(m, "Filename");
struct ast_str *filepath = ast_str_alloca(PATH_MAX);
ast_str_set(&filepath, 0, "%s/", ast_config_AST_CONFIG_DIR);
ast_str_append(&filepath, 0, "%s", fn);
- if (access(filepath->str, F_OK)) {
- FILE *fp = fopen(filepath->str, "w");
- fclose(fp);
+ if ((fd = open(filepath->str, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH)) > 0) {
+ close(fd);
astman_send_ack(s, m, "New configuration file created successfully");
- } else {
+ } else
astman_send_error(s, m, "Configuration file already exists");
- }
return 0;
}
More information about the asterisk-commits
mailing list