[svn-commits] jpeeler: branch jpeeler/manager-configactions r102036 - /team/jpeeler/manager...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Feb 1 19:07:08 CST 2008


Author: jpeeler
Date: Fri Feb  1 19:07:08 2008
New Revision: 102036

URL: http://svn.digium.com/view/asterisk?view=rev&rev=102036
Log:
added new manager action createconfig to create an empty file in the config dir

Modified:
    team/jpeeler/manager-configactions/main/manager.c

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=102036&r1=102035&r2=102036
==============================================================================
--- team/jpeeler/manager-configactions/main/manager.c (original)
+++ team/jpeeler/manager-configactions/main/manager.c Fri Feb  1 19:07:08 2008
@@ -1326,11 +1326,10 @@
 		astman_send_error(s, m, "Filename not specified");
 		return 0;
 	}
-	if (access(sfn, F_OK)) {
-		FILE *fp = fopen(sfn, "w");
-		fclose(fp);
-	}
-	cfg = ast_config_load(sfn, config_flags);
+ 	if (!(cfg = ast_config_load(sfn, config_flags))) {
+        astman_send_error(s, m, "Config file not found");
+        return 0;
+    }
 	result = handle_updates(s, m, cfg, dfn);
 	if (!result) {
 		ast_include_rename(cfg, sfn, dfn); /* change the include references from dfn to sfn, so things match up */
@@ -1356,6 +1355,31 @@
 			break;
 		}
 	}
+	return 0;
+}
+
+static char mandescr_createconfig[] =
+"Description: A 'CreateConfig' action will create an empty file in the\n"
+"configuration directory. This action is intended to be used before an\n"
+"UpdateConfig action.\n"
+"Variables\n"
+"   Filename:   The configuration filename to create (e.g. foo.conf)\n";
+
+static int action_createconfig(struct mansession *s, const struct message *m)
+{
+	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);
+		astman_send_ack(s, m, "New configuration file created successfully");
+	} else {
+		astman_send_error(s, m, "Configuration file already exists");
+	}
+
 	return 0;
 }
 
@@ -3555,6 +3579,7 @@
 		ast_manager_register2("GetConfig", EVENT_FLAG_SYSTEM | EVENT_FLAG_CONFIG, action_getconfig, "Retrieve configuration", mandescr_getconfig);
 		ast_manager_register2("GetConfigJSON", EVENT_FLAG_SYSTEM | EVENT_FLAG_CONFIG, action_getconfigjson, "Retrieve configuration (JSON format)", mandescr_getconfigjson);
 		ast_manager_register2("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig, "Update basic configuration", mandescr_updateconfig);
+		ast_manager_register2("CreateConfig", EVENT_FLAG_CONFIG, action_createconfig, "Creates an empty file in the configuration directory", mandescr_createconfig);
 		ast_manager_register2("ListCategories", EVENT_FLAG_CONFIG, action_listcategories, "List categories in configuration file", mandescr_listcategories);
 		ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect );
 		ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate);




More information about the svn-commits mailing list