[asterisk-commits] qwell: trunk r76216 - in /trunk: apps/app_playback.c configs/say.conf.sample

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 20 17:25:42 CDT 2007


Author: qwell
Date: Fri Jul 20 17:25:41 2007
New Revision: 76216

URL: http://svn.digium.com/view/asterisk?view=rev&rev=76216
Log:
Add support for default "say mode" (whether to use the "old" method or "new" method.  "new" method being config file)
Add support for autocomplete of "say load" CLI command.

Patch by IgorG
(closes issue #10243)

Modified:
    trunk/apps/app_playback.c
    trunk/configs/say.conf.sample

Modified: trunk/apps/app_playback.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_playback.c?view=diff&rev=76216&r1=76215&r2=76216
==============================================================================
--- trunk/apps/app_playback.c (original)
+++ trunk/apps/app_playback.c Fri Jul 20 17:25:41 2007
@@ -72,9 +72,17 @@
  * otherwise we are sourcing from here.
  * 'say load [new|old]' will enable the new or old method, or report status
  */
-static const void * say_api_buf[40];
+static const void *say_api_buf[40];
 static const char *say_old = "old";
 static const char *say_new = "new";
+static const char say_load_usage[] = 
+"Usage: say load [new|old]\n"
+"       say load\n"
+"	   Report status of current say mode\n"
+"       say load new\n"
+"          Set say method, configured in say.conf\n"
+"       say load old\n"
+"          Set old say metod, coded in asterisk core\n";
 
 static void save_say_mode(const void *arg)
 {
@@ -326,25 +334,12 @@
 /*
  * remap the 'say' functions to use those in this file
  */
-static int __say_init(int fd, int argc, char *argv[])
-{
-	const char *old_mode = say_api_buf[0] ? say_new : say_old;
-	char *mode;
-
-	if (argc == 2) {
-		ast_cli(fd, "say mode is [%s]\n", old_mode);
-		return RESULT_SUCCESS;
-        } else if (argc != 3)
-                return RESULT_SHOWUSAGE;
-        mode = argv[2];
-
-	ast_log(LOG_WARNING, "init say.c from %s to %s\n", old_mode, mode);
-
-	if (!strcmp(mode, old_mode)) {
-		ast_log(LOG_WARNING, "say mode is %s already\n", mode);
-	} else if (!strcmp(mode, say_new)) {
-		if (say_cfg == NULL)
-			say_cfg = ast_config_load("say.conf");
+static int say_init_mode(char *mode) {
+	if (!strcmp(mode, say_new)) {
+		if (say_cfg == NULL) {
+			ast_log(LOG_ERROR,"There is no say.conf file to use new mode\n");
+			return -1;
+		}
 		save_say_mode(say_new);
 		ast_say_number_full = say_number_full;
 
@@ -364,14 +359,49 @@
 		restore_say_mode(NULL);
 	} else {
 		ast_log(LOG_WARNING, "unrecognized mode %s\n", mode);
-	}
+		return -1;
+	}
+	
+	return 0;
+}
+
+
+static int __say_cli_init(int fd, int argc, char *argv[])
+{
+	const char *old_mode = say_api_buf[0] ? say_new : say_old;
+	char *mode;
+
+	if (argc == 2) {
+		ast_cli(fd, "say mode is [%s]\n", old_mode);
+		return RESULT_SUCCESS;
+        } else if (argc != 3)
+                return RESULT_SHOWUSAGE;
+        mode = argv[2];
+	
+	if (!strcmp(mode, old_mode)) {
+		ast_log(LOG_NOTICE, "say mode is %s already\n", mode);
+	} else {
+		if (say_init_mode(mode) == 0) {
+			ast_log(LOG_NOTICE, "init say.c from %s to %s\n", old_mode, mode);
+		}
+	}
+
 	return RESULT_SUCCESS;
 }
+
 
 static struct ast_cli_entry cli_playback[] = {
         { { "say", "load", NULL },
-	__say_init, "set/show the say mode",
-	"say load new|old" },
+	__say_cli_init, "Set or show the say mode",
+	say_load_usage },
+
+        { { "say", "load", "new", NULL },
+	__say_cli_init, "Set the say mode",
+	say_load_usage },
+
+        { { "say", "load", "old", NULL },
+	__say_cli_init, "Set the say mode",
+	say_load_usage },
 };
 
 static int playback_exec(struct ast_channel *chan, void *data)
@@ -439,11 +469,23 @@
 
 static int reload(void)
 {
+	struct ast_variable *v;
+
 	if (say_cfg) {
 		ast_config_destroy(say_cfg);
 		ast_log(LOG_NOTICE, "Reloading say.conf\n");
 	}
 	say_cfg = ast_config_load("say.conf");
+
+	if (say_cfg) {
+		for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
+    			if (ast_extension_match(v->name, "mode")) {
+				say_init_mode(v->value);
+				break;
+			}
+		}
+	}
+	
 	/*
 	 * XXX here we should sort rules according to the same order
 	 * we have in pbx.c so we have the same matching behaviour.
@@ -467,7 +509,18 @@
 
 static int load_module(void)
 {
+	struct ast_variable *v;
+
 	say_cfg = ast_config_load("say.conf");
+	if (say_cfg) {
+		for (v = ast_variable_browse(say_cfg, "general"); v ; v = v->next) {
+    			if (ast_extension_match(v->name, "mode")) {
+				say_init_mode(v->value);
+				break;
+			}
+		}
+	}
+
         ast_cli_register_multiple(cli_playback, sizeof(cli_playback) / sizeof(struct ast_cli_entry));
 	return ast_register_application(app, playback_exec, synopsis, descrip);
 }

Modified: trunk/configs/say.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/say.conf.sample?view=diff&rev=76216&r1=76215&r2=76216
==============================================================================
--- trunk/configs/say.conf.sample (original)
+++ trunk/configs/say.conf.sample Fri Jul 20 17:25:41 2007
@@ -1,7 +1,12 @@
-; say.conf
 ; 
 ; language configuration
 ;
+
+[general]
+mode=old	; method for playing numbers and dates
+		; old - using asterisk core function
+		; new - using this configuration file
+
 ; The new language routines produce strings of the form
 ;	prefix:[format:]data
 ; that are matched against the rules in this file to produce




More information about the asterisk-commits mailing list