]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Skinny: correct early media and answer
authorMathieu Parent <math.parent@gmail.com>
Thu, 24 Jun 2010 23:05:43 +0000 (01:05 +0200)
committerMathieu Parent <math.parent@gmail.com>
Fri, 25 Jun 2010 16:25:12 +0000 (18:25 +0200)
- SWITCH_MESSAGE_INDICATE_DISPLAY was missing a "break" statement
- handle not responding device (cancels early media or answer)
- don't send messages when listener is not ready (fix rare crashes)

src/mod/endpoints/mod_skinny/mod_skinny.c
src/mod/endpoints/mod_skinny/skinny_protocol.c

index 63900dcc3760833b4b91c49018565213ce41c893..335edaaa6ffc8c526be66a18891708b1cc6ec9bf 100644 (file)
@@ -957,10 +957,16 @@ switch_status_t channel_answer_channel(switch_core_session_t *session)
                switch_channel_get_variable(channel, "skinny_device_name"),
                atoi(switch_channel_get_variable(channel, "skinny_device_instance")), &listener);
        if (listener) {
+               int x = 0;
                skinny_session_start_media(session, listener, atoi(switch_channel_get_variable(channel, "skinny_line_instance")));
                /* Wait for media */
                while(!switch_test_flag(tech_pvt, TFLAG_IO)) {
                        switch_cond_next();
+                       if (++x > 1000) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Wait tooo long to answer %s:%s\n",
+                                       switch_channel_get_variable(channel, "skinny_device_name"), switch_channel_get_variable(channel, "skinny_device_instance"));
+                               return SWITCH_STATUS_FALSE;
+                       }
                }
        } else {
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Unable to find listener to answer %s:%s\n",
@@ -976,28 +982,26 @@ switch_status_t channel_receive_message(switch_core_session_t *session, switch_c
 
        switch (msg->message_id) {
        case SWITCH_MESSAGE_INDICATE_ANSWER:
-               {
-                       switch_clear_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
-                       channel_answer_channel(session);
-               }
-               break;
+               switch_clear_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
+               return channel_answer_channel(session);
+
        case SWITCH_MESSAGE_INDICATE_DISPLAY:
-               {
-                       skinny_session_send_call_info_all(session);
-               }
+               skinny_session_send_call_info_all(session);
+               return SWITCH_STATUS_SUCCESS;
+
        case SWITCH_MESSAGE_INDICATE_PROGRESS:
-               {
-                       if (!switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
-                               /* early media */
-                               switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
-                               channel_answer_channel(session);
-                       }
+               if (!switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
+                       /* early media */
+                       switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
+                       return channel_answer_channel(session);
                }
+               return SWITCH_STATUS_SUCCESS;
+
        default:
-               break;
+               return SWITCH_STATUS_SUCCESS;
+
        }
 
-       return SWITCH_STATUS_SUCCESS;
 }
 
 /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
index c71b7333da877a20c76e48c6e545f0dace573503..9486c5c869796646d17df0f1c1281f999582ad0e 100644 (file)
@@ -914,13 +914,19 @@ switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file
        len = reply->length+8;
        ptr = (char *) reply;
 
-       switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG,
-               "Sending %s (type=%x,length=%d) to %s:%d.\n",
-               skinny_message_type2str(reply->type), reply->type, reply->length,
-               listener->device_name, listener->device_instance);
-       switch_socket_send(listener->sock, ptr, &len);
-
-       return SWITCH_STATUS_SUCCESS;
+       if (listener_is_ready(listener)) {
+               switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG,
+                       "Sending %s (type=%x,length=%d) to %s:%d.\n",
+                       skinny_message_type2str(reply->type), reply->type, reply->length,
+                       listener->device_name, listener->device_instance);
+               return switch_socket_send(listener->sock, ptr, &len);
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_WARNING,
+                       "Not sending %s (type=%x,length=%d) to %s:%d while not ready.\n",
+                       skinny_message_type2str(reply->type), reply->type, reply->length,
+                       listener->device_name, listener->device_instance);
+               return SWITCH_STATUS_FALSE;
+       }
 }
 
 /* For Emacs: