]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
--resolve FS-3922
authorKen Rice <krice@freeswitch.org>
Wed, 3 Jul 2013 21:07:15 +0000 (16:07 -0500)
committerKen Rice <krice@freeswitch.org>
Fri, 5 Jul 2013 02:18:20 +0000 (21:18 -0500)
src/include/switch_core.h
src/switch_xml.c

index 416ed185de48cface80cc4415e2d01e31d8bde83..c3583e95556d9c27ac8d15b62cf1c831eb73847d 100644 (file)
@@ -2557,6 +2557,11 @@ SWITCH_DECLARE(int) switch_core_cert_expand_fingerprint(dtls_fingerprint_t *fp,
 SWITCH_DECLARE(int) switch_core_cert_verify(dtls_fingerprint_t *fp);
 SWITCH_DECLARE(switch_status_t) switch_core_session_refresh_video(switch_core_session_t *session);
 
+SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait);
+SWITCH_DECLARE(int) switch_stream_system_fork(const char *cmd, switch_stream_handle_t *stream);
+SWITCH_DECLARE(int) switch_stream_system(const char *cmd, switch_stream_handle_t *stream);
+
+
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:
index 018c01dd472f5a240e426a9666198ea337063563..c13e33bea473563de3a129445847182253b28cfb 100644 (file)
@@ -105,6 +105,42 @@ void globfree(glob_t *);
 /* Use UTF-8 as the general encoding */
 static switch_bool_t USE_UTF_8_ENCODING = SWITCH_TRUE;
 
+static void preprocess_exec_set(char *keyval)
+{
+       char *key = keyval;
+       char *val = strchr(key, '=');
+
+       if (val) {
+               char *ve = val++;
+               while (*val && *val == ' ') {
+                       val++;
+               }
+               *ve-- = '\0';
+               while (*ve && *ve == ' ') {
+                       *ve-- = '\0';
+               }
+       }
+
+       if (key && val) {
+               switch_stream_handle_t exec_result = { 0 };
+               SWITCH_STANDARD_STREAM(exec_result);
+               if (switch_stream_system_fork(val, &exec_result) == 0) {
+                       if (!zstr(exec_result.data)) {
+                               char *tmp = (char *) exec_result.data;
+                               tmp = &tmp[strlen(tmp)-1];
+                               while (tmp >= (char *) exec_result.data && ( tmp[0] == ' ' || tmp[0] == '\n') ) {
+                                       tmp[0] = '\0'; /* remove trailing spaces and newlines */
+                                       tmp--;
+                               }
+                               switch_core_set_variable(key, exec_result.data);
+                       }
+               } else {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error while executing command: %s\n", val);
+               }
+               switch_safe_free(exec_result.data);
+       }
+}
+
 static int preprocess(const char *cwd, const char *file, FILE *write_fd, int rlevel);
 
 typedef struct switch_xml_root *switch_xml_root_t;
@@ -1457,6 +1493,8 @@ static int preprocess(const char *cwd, const char *file, FILE *write_fd, int rle
                                        switch_core_set_variable(name, val);
                                }
 
+                       } else if (!strcasecmp(tcmd, "exec-set")) {
+                               preprocess_exec_set(targ);
                        } else if (!strcasecmp(tcmd, "include")) {
                                preprocess_glob(cwd, targ, write_fd, rlevel + 1);
                        } else if (!strcasecmp(tcmd, "exec")) {
@@ -1515,6 +1553,8 @@ static int preprocess(const char *cwd, const char *file, FILE *write_fd, int rle
                                                switch_core_set_variable(name, val);
                                        }
 
+                               } else if (!strcasecmp(cmd, "exec-set")) {
+                                       preprocess_exec_set(arg);
                                } else if (!strcasecmp(cmd, "include")) {
                                        preprocess_glob(cwd, arg, write_fd, rlevel + 1);
                                } else if (!strcasecmp(cmd, "exec")) {