]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix mutex to work better
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 13 Nov 2012 23:56:27 +0000 (17:56 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 13 Nov 2012 23:56:31 +0000 (17:56 -0600)
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_event.c

index 834fe69e9a43638bb7031ffacf19b0dcb7a128a5..eefd4aad4b62a5cd58adbf254bd8d7ce9d7e61dd 100755 (executable)
@@ -4814,10 +4814,6 @@ static switch_bool_t do_mutex(switch_core_session_t *session, const char *key, s
        struct read_frame_data rf = { 0 };
        long to_val = 0;
 
-       if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
-               return SWITCH_FALSE;
-       }
-
        switch_mutex_lock(globals.mutex_mutex);
        used = switch_channel_test_app_flag_key(key, channel, MUTEX_FLAG_WAIT) || switch_channel_test_app_flag_key(key, channel, MUTEX_FLAG_SET);
 
@@ -4877,19 +4873,12 @@ static switch_bool_t do_mutex(switch_core_session_t *session, const char *key, s
        
        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s mutex %s is busy, waiting...\n", switch_channel_get_name(channel), key);
 
-       if (!(feedback = switch_channel_get_variable(channel, "mutex_feedback"))) {
-               if ((var = switch_channel_get_variable(channel, "ringback"))) {
-                       feedback = switch_core_session_sprintf(session, "tone_stream://%s;loops=-1", var);
-               } else {
-                       feedback = switch_channel_get_hold_music(channel);
+       if ((feedback = switch_channel_get_variable(channel, "mutex_feedback"))) {
+               if (!strcasecmp(feedback, "silence")) {
+                       feedback = "silence_stream://-1";
                }
        }
 
-       if (zstr(feedback) || !strcasecmp(feedback, "silence")) {
-               feedback = "silence_stream://-1";
-       }
-
-
        if ((rf.exten = switch_channel_get_variable(channel, "mutex_orbit_exten"))) {
                to_val = 60;
        }
@@ -4917,7 +4906,16 @@ static switch_bool_t do_mutex(switch_core_session_t *session, const char *key, s
        args.user_data = &rf;
 
        while(switch_channel_ready(channel) && switch_channel_test_app_flag_key(key, channel, MUTEX_FLAG_WAIT)) {
-               switch_status_t st = switch_ivr_play_file(session, NULL, feedback, &args);
+               switch_status_t st;
+
+               if (feedback) {
+                       switch_channel_pre_answer(channel);
+                       st = switch_ivr_play_file(session, NULL, feedback, &args);
+               } else {
+                       if ((st = switch_ivr_sleep(session, 20, SWITCH_FALSE, NULL)) == SWITCH_STATUS_SUCCESS) {
+                               st = read_frame_callback(session, NULL, &rf);
+                       }
+               }
 
                if (st != SWITCH_STATUS_SUCCESS) {
                        break;
@@ -5519,7 +5517,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
        SWITCH_ADD_APP(app_interface, "flush_dtmf", "flush any queued dtmf", "flush any queued dtmf", flush_dtmf_function, "", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "hold", "Send a hold message", "Send a hold message", hold_function, HOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "unhold", "Send a un-hold message", "Send a un-hold message", unhold_function, UNHOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
-       SWITCH_ADD_APP(app_interface, "mutex", "block on a call flow only allowing one at a time", "", mutex_function, MUTEX_SYNTAX, SAF_NONE);
+       SWITCH_ADD_APP(app_interface, "mutex", "block on a call flow only allowing one at a time", "", mutex_function, MUTEX_SYNTAX, SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "page", "", "", page_function, PAGE_SYNTAX, SAF_NONE);
        SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]",
                                   SAF_SUPPORT_NOMEDIA);
index e589e02f43a72f27dacbf9cf19807030552a5010..7a965d4dcd037186b07515958dc0d33ad1b24fcb 100644 (file)
@@ -1138,17 +1138,21 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event)
                for (hp = ep->headers; hp;) {
                        this = hp;
                        hp = hp->next;
-                       FREE(this->name);
 
                        if (this->idx) {
-                               int i = 0;
+                               if (!this->array) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "INDEX WITH NO ARRAY WTF?? [%s][%s]\n", this->name, this->value);
+                               } else {
+                                       int i = 0;
 
-                               for (i = 0; i < this->idx; i++) {
-                                       FREE(this->array[i]);
+                                       for (i = 0; i < this->idx; i++) {
+                                               FREE(this->array[i]);
+                                       }
+                                       FREE(this->array);
                                }
-                               FREE(this->array);
                        }
 
+                       FREE(this->name);
                        FREE(this->value);