]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add execute_on function so you can have execute_on_answer_1 execute_on_answer_2 execu...
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 1 Apr 2011 22:39:20 +0000 (17:39 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 1 Apr 2011 22:39:27 +0000 (17:39 -0500)
src/include/switch_channel.h
src/switch_channel.c
src/switch_ivr_originate.c

index fdbbc9ab91e786913ecaee2f2b20f80e92e1728f..febaf40f75f5a4bf185fc6986d6e50625091f40c 100644 (file)
@@ -615,6 +615,9 @@ SWITCH_DECLARE(void) switch_channel_mark_hold(switch_channel_t *channel, switch_
 
 /** @} */
 
+SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix);
+
+
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:
index 0476981331a59489201ee409227b7f0896553285..19eb92ad8d4545624effe7cfbe12a2810164ddd6 100644 (file)
@@ -2588,8 +2588,6 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready_value(swi
                                                                                                                                                         switch_ring_ready_t rv,
                                                                                                                                                         const char *file, const char *func, int line)
 {
-       const char *var;
-       char *app;
        switch_event_t *event;
 
        if (!switch_channel_test_flag(channel, CF_RING_READY) && 
@@ -2619,21 +2617,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_ring_ready_value(swi
                        switch_event_fire(&event);
                }
 
-               var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE);
-               if (var) {
-                       char *arg = NULL;
-                       app = switch_core_session_strdup(channel->session, var);
-
-                       if (strstr(app, "::")) {
-                               switch_core_session_execute_application_async(channel->session, app, arg);
-                       } else {
-                               if ((arg = strchr(app, ' '))) {
-                                       *arg++ = '\0';
-                               }
-                               
-                               switch_core_session_execute_application(channel->session, app, arg);
-                       }
-               }
+               switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE);
 
                return SWITCH_STATUS_SUCCESS;
        }
@@ -2645,7 +2629,6 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_
 {
        switch_event_t *event;
        const char *var = NULL;
-       char *app;
 
        if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) {
                const char *uuid;
@@ -2678,20 +2661,9 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_
                        switch_mutex_unlock(channel->profile_mutex);
                }
 
-               if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE)) ||
-                        (var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE))) && !zstr(var)) {
-                       char *arg = NULL;
-                       app = switch_core_session_strdup(channel->session, var);
-
-
-                       if (strstr(app, "::")) {
-                               switch_core_session_execute_application_async(channel->session, app, arg);
-                       } else {
-                               if ((arg = strchr(app, ' '))) {
-                                       *arg++ = '\0';
-                               }
-                               
-                               switch_core_session_execute_application(channel->session, app, arg);
+               if (switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE) != SWITCH_STATUS_SUCCESS) {
+                       if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
+                               switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE);
                        }
                }
 
@@ -2785,6 +2757,40 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_ring_ready_value(switch_c
        return status;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_channel_execute_on(switch_channel_t *channel, const char *variable_prefix)
+{
+       switch_event_header_t *hi;
+       int x = 0;
+       
+       if ((hi = switch_channel_variable_first(channel))) {
+               for (; hi; hi = hi->next) {
+                       char *var = hi->name;
+                       char *val = hi->value;
+                       char *app;
+                       
+                       if (!strncasecmp(var, variable_prefix, strlen(variable_prefix))) {
+                               char *arg = NULL;
+                               x++;
+
+                               app = switch_core_session_strdup(channel->session, val);
+                               
+                               if (strstr(app, "::")) {
+                                       switch_core_session_execute_application_async(channel->session, app, arg);
+                               } else {
+                                       if ((arg = strchr(app, ' '))) {
+                                               *arg++ = '\0';
+                                       }
+                                       
+                                       switch_core_session_execute_application(channel->session, app, arg);
+                               }
+                       }
+               }
+               switch_channel_variable_last(channel);
+       }
+
+       return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel, const char *file, const char *func, int line)
 {
        switch_event_t *event;
@@ -2852,21 +2858,10 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n",
                                          channel->name);
 
-       if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE)) ||
-                (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && (var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE))))
-               && !zstr(var)) {
-               char *arg = NULL;
-
-               app = switch_core_session_strdup(channel->session, var);
 
-               if (strstr(app, "::")) {
-                       switch_core_session_execute_application_async(channel->session, app, arg);
-               } else {
-                       if ((arg = strchr(app, ' '))) {
-                               *arg++ = '\0';
-                       }
-                       
-                       switch_core_session_execute_application(channel->session, app, arg);
+       if (switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE) != SWITCH_STATUS_SUCCESS) {
+               if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
+                       switch_channel_execute_on(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE);
                }
        }
 
index 33e9d9a0bca815d12f9f3a44161620ea9094de1e..0c4c336e51f37bbe1ea9f1132c65cf9b8cae65d7 100644 (file)
@@ -2762,23 +2762,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                                                switch_channel_set_variable(originate_status[i].peer_channel, "originating_leg_uuid", switch_core_session_get_uuid(session));
                                        }
 
-                                       if ((vvar = switch_channel_get_variable_dup(originate_status[i].peer_channel, "execute_on_originate", SWITCH_FALSE))) {
-                                               char *app = switch_core_session_strdup(originate_status[i].peer_session, vvar);
-                                               char *arg = NULL;
-
-                                               if (strstr(app, "::")) {
-                                                       switch_core_session_execute_application_async(originate_status[i].peer_session, app, arg);
-                                               } else {
-                                                       if ((arg = strchr(app, ' '))) {
-                                                               *arg++ = '\0';
-                                                       }
-                                                       
-                                                       switch_core_session_execute_application(originate_status[i].peer_session, app, arg);
-                                               }
-                                               
-                                       }
+                                       switch_channel_execute_on(originate_status[i].peer_channel, "execute_on_originate");
                                }
-
+                               
                                if (table) {
                                        switch_channel_add_state_handler(originate_status[i].peer_channel, table);
                                }