]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCORE-446
authorBrian West <brian@freeswitch.org>
Wed, 23 Sep 2009 17:32:01 +0000 (17:32 +0000)
committerBrian West <brian@freeswitch.org>
Wed, 23 Sep 2009 17:32:01 +0000 (17:32 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14958 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_utils.h
src/mod/asr_tts/mod_tts_commandline/mod_tts_commandline.c
src/switch_utils.c

index dbf3bb56f5593f488f7a885a82d0be134525607e..5bbb5c4f8ea3ee624ec36b2a545470fa66ddfaf8 100644 (file)
@@ -545,6 +545,13 @@ SWITCH_DECLARE(const char *) switch_cut_path(const char *in);
 SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *search, const char *replace);
 SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len);
 
+/*!
+  \brief Quote shell argument
+  \param string the string to quote (example: a ' b"' c)
+  \return the quoted string (gives: 'a '\'' b"'\'' c' for unices, "a ' b ' c" for MS Windows)
+*/
+SWITCH_DECLARE(char *) switch_util_quote_shell_arg(const char *string);
+
 #define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
 SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len);
 SWITCH_DECLARE(char *) switch_url_decode(char *s);
index 44bb2714ae21255f3016cbc70a3c4e09c1fdda3f..28e14333535d3d8f5822632cdd4735ef965ba254 100644 (file)
@@ -32,8 +32,6 @@
 #include <unistd.h>
 #include <switch.h>
 
-SWITCH_DECLARE(char *) switch_escape_shell_arg(char *string);
-
 SWITCH_MODULE_LOAD_FUNCTION(mod_tts_commandline_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_tts_commandline_shutdown);
 SWITCH_MODULE_DEFINITION(mod_tts_commandline, mod_tts_commandline_load, mod_tts_commandline_shutdown, NULL);
@@ -56,62 +54,6 @@ struct tts_commandline_data {
 typedef struct tts_commandline_data tts_commandline_t;
 
 
-SWITCH_DECLARE(char *) switch_quote_shell_arg(char *string)
-{
-       size_t string_len = strlen(string);
-       size_t i;
-       size_t n = 0;
-       size_t dest_len = string_len + 1; /* +1 for the opening quote  */
-       char *dest, *tmp;
-
-       dest = (char *) malloc(sizeof(char) * dest_len);
-       switch_assert(dest);
-
-#ifdef WIN32
-       dest[n++] = '"';
-#else
-       dest[n++] = '\'';
-#endif
-
-       for (i = 0; i < string_len; i++) {
-               switch (string[i]) {
-#ifdef WIN32
-               case '"':
-               case '%':
-                       dest[n++] = ' ';
-                       break;
-#else
-               case '\'':
-                       /* We replace ' by '\'' */
-                       dest_len+=3;
-                       tmp = (char *) realloc(dest, sizeof(char) * (dest_len));
-                       switch_assert(tmp);
-                       dest = tmp;
-                       dest[n++] = '\'';
-                       dest[n++] = '\\';
-                       dest[n++] = '\'';
-                       dest[n++] = '\'';
-                       break;
-#endif
-               default:
-                       dest[n++] = string[i];
-               }
-  }
-  
-       dest_len += 2; /* +2 for the closing quote and the null character */
-       tmp = (char *) realloc(dest, sizeof(char) * (dest_len));
-       switch_assert(tmp);
-       dest = tmp;
-#ifdef WIN32
-       dest[n++] = '"';
-#else
-       dest[n++] = '\'';
-#endif
-       dest[n++] = 0;
-       switch_assert(n == dest_len);
-       return dest;
-}
-
 static int load_tts_commandline_config(void)
 {
        char *cf = "tts_commandline.conf";
@@ -190,16 +132,16 @@ static switch_status_t tts_commandline_speech_feed_tts(switch_speech_handle_t *s
        
        message = switch_core_strdup(sh->memory_pool, globals.command);
        
-       tmp = switch_quote_shell_arg(text);
+       tmp = switch_util_quote_shell_arg(text);
        message = switch_string_replace(message, "${text}", tmp);
        
-       tmp = switch_quote_shell_arg(info->voice_name);
+       tmp = switch_util_quote_shell_arg(info->voice_name);
        message = switch_string_replace(message, "${voice}", tmp);
        
        rate = switch_core_sprintf(sh->memory_pool, "%d", info->rate);
        message = switch_string_replace(message, "${rate}", rate);
        
-       tmp = switch_quote_shell_arg(info->file);
+       tmp = switch_util_quote_shell_arg(info->file);
        message = switch_string_replace(message, "${file}", tmp);
        
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing: %s\n", message);
index 525d4efb022436056fa9a02f9c60199f45232ef9..9337a71feb74504386eb9203cf6533740b75ea1a 100644 (file)
@@ -1661,6 +1661,62 @@ SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *sea
        return dest;
 }
 
+SWITCH_DECLARE(char *) switch_util_quote_shell_arg(const char *string)
+{
+       size_t string_len = strlen(string);
+       size_t i;
+       size_t n = 0;
+       size_t dest_len = string_len + 1; /* +1 for the opening quote  */
+       char *dest, *tmp;
+
+       dest = (char *) malloc(sizeof(char) * dest_len);
+       switch_assert(dest);
+
+#ifdef WIN32
+       dest[n++] = '"';
+#else
+       dest[n++] = '\'';
+#endif
+
+       for (i = 0; i < string_len; i++) {
+               switch (string[i]) {
+#ifdef WIN32
+               case '"':
+               case '%':
+                       dest[n++] = ' ';
+                       break;
+#else
+               case '\'':
+                       /* We replace ' by '\'' */
+                       dest_len+=3;
+                       tmp = (char *) realloc(dest, sizeof(char) * (dest_len));
+                       switch_assert(tmp);
+                       dest = tmp;
+                       dest[n++] = '\'';
+                       dest[n++] = '\\';
+                       dest[n++] = '\'';
+                       dest[n++] = '\'';
+                       break;
+#endif
+               default:
+                       dest[n++] = string[i];
+               }
+  }
+  
+       dest_len += 2; /* +2 for the closing quote and the null character */
+       tmp = (char *) realloc(dest, sizeof(char) * (dest_len));
+       switch_assert(tmp);
+       dest = tmp;
+#ifdef WIN32
+       dest[n++] = '"';
+#else
+       dest[n++] = '\'';
+#endif
+       dest[n++] = 0;
+       switch_assert(n == dest_len);
+       return dest;
+}
+
 SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
 {
        int nsds = 0;