diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c index 5a158534e3..f2f5c2ac39 100644 --- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c +++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c @@ -447,9 +447,9 @@ static switch_status_t channel_on_init(switch_core_session_t *session) channel = switch_core_session_get_channel(session); switch_assert(channel != NULL); switch_channel_set_variable(channel, "skype_user", tech_pvt->skype_user); - switch_mutex_lock(tech_pvt->flag_mutex); + switch_mutex_lock(tech_pvt->flag_mutex); switch_set_flag(tech_pvt, TFLAG_IO); - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_mutex_unlock(tech_pvt->flag_mutex); /* Move channel's state machine to ROUTING. This means the call is trying to get from the initial start where the call because, to the point @@ -484,21 +484,21 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) switch_mutex_unlock(tech_pvt->flag_mutex); DEBUGA_SKYPE("audio tcp threads to DIE\n", SKYPOPEN_P_LOG); - conta=0; - while(tech_pvt->tcp_srv_thread){ + conta = 0; + while (tech_pvt->tcp_srv_thread) { switch_sleep(5000); conta++; - if(conta==200){ + if (conta == 200) { ERRORA("tcp_srv_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } } DEBUGA_SKYPE("audio tcp srv thread DEAD %d\n", SKYPOPEN_P_LOG, conta); - conta=0; - while(tech_pvt->tcp_cli_thread){ + conta = 0; + while (tech_pvt->tcp_cli_thread) { switch_sleep(5000); conta++; - if(conta==200){ + if (conta == 200) { ERRORA("tcp_cli_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } @@ -618,7 +618,6 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) if (globals.calls < 0) { globals.calls = 0; } - //DEBUGA_SKYPE("debugging_hangup 9\n", SKYPOPEN_P_LOG); tech_pvt->interface_state = SKYPOPEN_STATE_DOWN; if (tech_pvt->skype_callflow == CALLFLOW_STATUS_FINISHED) { @@ -869,15 +868,15 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt->read_frame.datalen = 640; } - switch_mutex_lock(tech_pvt->flag_mutex); + switch_mutex_lock(tech_pvt->flag_mutex); switch_set_flag(tech_pvt, TFLAG_VOICE); - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_mutex_unlock(tech_pvt->flag_mutex); while (switch_test_flag(tech_pvt, TFLAG_IO)) { if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { - switch_mutex_lock(tech_pvt->flag_mutex); + switch_mutex_lock(tech_pvt->flag_mutex); switch_clear_flag(tech_pvt, TFLAG_BREAK); - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_mutex_unlock(tech_pvt->flag_mutex); DEBUGA_SKYPE("CHANNEL READ FRAME goto CNG\n", SKYPOPEN_P_LOG); goto cng; } @@ -888,9 +887,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) { - switch_mutex_lock(tech_pvt->flag_mutex); + switch_mutex_lock(tech_pvt->flag_mutex); switch_clear_flag(tech_pvt, TFLAG_VOICE); - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_mutex_unlock(tech_pvt->flag_mutex); if (!tech_pvt->read_frame.datalen) { DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPOPEN_P_LOG); continue; @@ -916,7 +915,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch if (digit_str[0]) { switch_time_t new_dtmf_timestamp = switch_time_now(); - if ((new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp) > 350000) { + if ((new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp) > 350000) { char *p = digit_str; switch_channel_t *channel = switch_core_session_get_channel(session); @@ -1024,12 +1023,12 @@ static switch_status_t channel_answer_channel(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - switch_mutex_lock(tech_pvt->flag_mutex); + switch_mutex_lock(tech_pvt->flag_mutex); switch_clear_flag(tech_pvt, TFLAG_IO); - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_mutex_unlock(tech_pvt->flag_mutex); skypopen_answer(tech_pvt); - while (!switch_test_flag(tech_pvt, TFLAG_IO)) { + while (!switch_test_flag(tech_pvt, TFLAG_IO)) { if (switch_channel_get_state(channel) == CS_RESET) { return SWITCH_STATUS_FALSE; } @@ -1069,9 +1068,9 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s case SWITCH_MESSAGE_INDICATE_PROGRESS: { DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_PROGRESS\n", SKYPOPEN_P_LOG, switch_channel_get_name(channel)); - switch_mutex_lock(tech_pvt->flag_mutex); + switch_mutex_lock(tech_pvt->flag_mutex); switch_set_flag(tech_pvt, TFLAG_PROGRESS); - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_mutex_unlock(tech_pvt->flag_mutex); } break; case SWITCH_MESSAGE_INDICATE_CLEAR_PROGRESS: @@ -1406,21 +1405,21 @@ static void *SWITCH_THREAD_FUNC skypopen_signaling_thread_func(switch_thread_t * tech_pvt->interface_state = SKYPOPEN_STATE_DOWN; DEBUGA_SKYPE("audio tcp threads to DIE\n", SKYPOPEN_P_LOG); - conta=0; - while(tech_pvt->tcp_srv_thread){ + conta = 0; + while (tech_pvt->tcp_srv_thread) { switch_sleep(5000); conta++; - if(conta==200){ + if (conta == 200) { ERRORA("tcp_srv_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } } DEBUGA_SKYPE("audio tcp srv thread DEAD %d\n", SKYPOPEN_P_LOG, conta); - conta=0; - while(tech_pvt->tcp_cli_thread){ + conta = 0; + while (tech_pvt->tcp_cli_thread) { switch_sleep(5000); conta++; - if(conta==200){ + if (conta == 200) { ERRORA("tcp_cli_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } @@ -2018,8 +2017,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypopen_shutdown) XEvent e; Atom atom1 = XInternAtom(tech_pvt->SkypopenHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); - switch_sleep(1000); - XFlush(tech_pvt->SkypopenHandles.disp); + switch_sleep(1000); + XFlush(tech_pvt->SkypopenHandles.disp); memset(&e, 0, sizeof(e)); e.xclient.type = ClientMessage; e.xclient.message_type = atom1; /* leading message */ @@ -2028,12 +2027,12 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypopen_shutdown) e.xclient.format = 8; XSendEvent(tech_pvt->SkypopenHandles.disp, tech_pvt->SkypopenHandles.win, False, 0, &e); - XFlush(tech_pvt->SkypopenHandles.disp); + XFlush(tech_pvt->SkypopenHandles.disp); } #endif } x = 10; - while (x) { + while (x) { x--; switch_yield(50000); } @@ -2360,7 +2359,7 @@ private_t *find_available_skypopen_interface_rr(private_t *tech_pvt_calling) tech_pvt = &globals.SKYPOPEN_INTERFACES[interface_id]; skype_state = tech_pvt->interface_state; - if ((tech_pvt_calling ? strcmp(tech_pvt->skype_user, tech_pvt_calling->skype_user) : 1) + if ((tech_pvt_calling ? strcmp(tech_pvt->skype_user, tech_pvt_calling->skype_user) : 1) && (SKYPOPEN_STATE_IDLE == skype_state)) { DEBUGA_SKYPE("returning as available skype interface name: %s, state: %d callflow: %d\n", SKYPOPEN_P_LOG, tech_pvt->name, skype_state, tech_pvt->skype_callflow); @@ -2757,7 +2756,7 @@ int skypopen_transfer(private_t *tech_pvt) giovatech = &globals.SKYPOPEN_INTERFACES[i]; /* let's look for a IDLE one */ - if ((giovatech->interface_state == SKYPOPEN_STATE_IDLE) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user))) { + if ((giovatech->interface_state == SKYPOPEN_STATE_IDLE) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user))) { found = 1; DEBUGA_SKYPE ("FOUND (name=%s, giovatech->interface_state=%d == SKYPOPEN_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n", @@ -3073,7 +3072,7 @@ struct SkypopenHandles *skypopen_list_remove_by_value(struct SkypopenList *list, // CLOUDTREE (THomas Hazel) - is there a capable freeswitch list? struct SkypopenHandles *skypopen_list_remove_by_reference(struct SkypopenList *list, struct SkypopenHandles *handle) { - private_t *tech_pvt=NULL; + private_t *tech_pvt = NULL; switch_mutex_lock(globals.list_mutex); @@ -3081,7 +3080,7 @@ struct SkypopenHandles *skypopen_list_remove_by_reference(struct SkypopenList *l if (handle->managed == SWITCH_FALSE) { // already removed switch_mutex_unlock(globals.list_mutex); - DEBUGA_SKYPE("EXIT REMOVE\n", SKYPOPEN_P_LOG); + DEBUGA_SKYPE("EXIT REMOVE\n", SKYPOPEN_P_LOG); return 0; } diff --git a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c index 96ab542532..bab9d54422 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c +++ b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c @@ -227,27 +227,29 @@ int skypopen_signaling_read(private_t *tech_pvt) } } else if (!strncasecmp(message, "ERROR 36 Not online", 18)) { char msg_to_skype[256]; - ERRORA("Skype client is not online, eg: not connected to Skype network, probably got a temporary net outage: |||%s|||\n", SKYPOPEN_P_LOG, message); - if(strlen(tech_pvt->skype_call_id)){ - sprintf(msg_to_skype, "ALTER CALL %s HANGUP", tech_pvt->skype_call_id); - skypopen_signaling_write(tech_pvt, msg_to_skype); + ERRORA("Skype client is not online, eg: not connected to Skype network, probably got a temporary net outage: |||%s|||\n", + SKYPOPEN_P_LOG, message); + if (strlen(tech_pvt->skype_call_id)) { + sprintf(msg_to_skype, "ALTER CALL %s HANGUP", tech_pvt->skype_call_id); + skypopen_signaling_write(tech_pvt, msg_to_skype); } - if(strlen(tech_pvt->ring_id)){ - sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", tech_pvt->ring_id); - skypopen_signaling_write(tech_pvt, msg_to_skype); + if (strlen(tech_pvt->ring_id)) { + sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", tech_pvt->ring_id); + skypopen_signaling_write(tech_pvt, msg_to_skype); } tech_pvt->interface_state = SKYPOPEN_STATE_DOWN; return CALLFLOW_INCOMING_HANGUP; } else if (!strncasecmp(message, "ERROR 589 ALTER CALL", 19)) { char msg_to_skype[256]; - DEBUGA_SKYPE("Skype client was not able to correctly manage tcp audio sockets, probably got a local or remote hangup: |||%s|||\n", SKYPOPEN_P_LOG, message); - if(strlen(tech_pvt->skype_call_id)){ - sprintf(msg_to_skype, "ALTER CALL %s HANGUP", tech_pvt->skype_call_id); - skypopen_signaling_write(tech_pvt, msg_to_skype); + DEBUGA_SKYPE("Skype client was not able to correctly manage tcp audio sockets, probably got a local or remote hangup: |||%s|||\n", + SKYPOPEN_P_LOG, message); + if (strlen(tech_pvt->skype_call_id)) { + sprintf(msg_to_skype, "ALTER CALL %s HANGUP", tech_pvt->skype_call_id); + skypopen_signaling_write(tech_pvt, msg_to_skype); } - if(strlen(tech_pvt->ring_id)){ - sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", tech_pvt->ring_id); - skypopen_signaling_write(tech_pvt, msg_to_skype); + if (strlen(tech_pvt->ring_id)) { + sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", tech_pvt->ring_id); + skypopen_signaling_write(tech_pvt, msg_to_skype); } tech_pvt->interface_state = SKYPOPEN_STATE_DOWN; return CALLFLOW_INCOMING_HANGUP; @@ -497,7 +499,7 @@ int skypopen_signaling_read(private_t *tech_pvt) //SKYPOPEN_P_LOG, message, obj, id, prop, value, where ? where : "NULL"); if (!strcasecmp(prop, "PARTNER_HANDLE")) { - if (tech_pvt->interface_state == SKYPOPEN_STATE_IDLE){ + if (tech_pvt->interface_state == SKYPOPEN_STATE_IDLE) { /* we are NOT inside an active call */ DEBUGA_SKYPE("Call %s go to skypopen_partner_handle_ring\n", SKYPOPEN_P_LOG, id); skypopen_strncpy(tech_pvt->ring_id, id, sizeof(tech_pvt->ring_id)); @@ -579,7 +581,7 @@ int skypopen_signaling_read(private_t *tech_pvt) if (!strcasecmp(value, "RINGING")) { char msg_to_skype[1024]; - if (tech_pvt->interface_state == SKYPOPEN_STATE_IDLE){ + if (tech_pvt->interface_state == SKYPOPEN_STATE_IDLE) { // CLOUDTREE (Thomas Hazel) skypopen_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1); @@ -604,8 +606,9 @@ int skypopen_signaling_read(private_t *tech_pvt) skypopen_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1); DEBUGA_SKYPE("Our remote party in skype_call %s is RINGING\n", SKYPOPEN_P_LOG, id); if (remote_party_is_ringing(tech_pvt) != SWITCH_STATUS_SUCCESS) { - DEBUGA_SKYPE("We are getting the RINGING from a call we probably canceled, trying to get out hanging up call id: %s.\n", - SKYPOPEN_P_LOG, id); + DEBUGA_SKYPE + ("We are getting the RINGING from a call we probably canceled, trying to get out hanging up call id: %s.\n", + SKYPOPEN_P_LOG, id); sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id); skypopen_signaling_write(tech_pvt, msg_to_skype); sprintf(msg_to_skype, "ALTER CALL %s HANGUP", id); @@ -735,7 +738,7 @@ int skypopen_signaling_read(private_t *tech_pvt) skypopen_signaling_write(tech_pvt, msg_to_skype); } tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS; - if(skypopen_answered(tech_pvt)!= SWITCH_STATUS_SUCCESS){ + if (skypopen_answered(tech_pvt) != SWITCH_STATUS_SUCCESS) { sprintf(msg_to_skype, "ALTER CALL %s HANGUP", id); skypopen_signaling_write(tech_pvt, msg_to_skype); } @@ -866,8 +869,8 @@ void *skypopen_do_tcp_srv_thread_func(void *obj) if (!(running && tech_pvt->running)) break; while (tech_pvt && tech_pvt->interface_state != SKYPOPEN_STATE_DOWN - && tech_pvt->interface_state != SKYPOPEN_STATE_IDLE - && tech_pvt->interface_state != SKYPOPEN_STATE_HANGUP_REQUESTED + && tech_pvt->interface_state != SKYPOPEN_STATE_IDLE + && tech_pvt->interface_state != SKYPOPEN_STATE_HANGUP_REQUESTED && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPOPEN_STATE_UP)) { @@ -1026,8 +1029,8 @@ void *skypopen_do_tcp_cli_thread_func(void *obj) if (!(running && tech_pvt->running)) break; while (tech_pvt && tech_pvt->interface_state != SKYPOPEN_STATE_DOWN - && tech_pvt->interface_state != SKYPOPEN_STATE_IDLE - && tech_pvt->interface_state != SKYPOPEN_STATE_HANGUP_REQUESTED + && tech_pvt->interface_state != SKYPOPEN_STATE_IDLE + && tech_pvt->interface_state != SKYPOPEN_STATE_HANGUP_REQUESTED && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPOPEN_STATE_UP)) { @@ -1536,8 +1539,8 @@ int skypopen_send_message(private_t *tech_pvt, const char *message_P) unsigned int len = strlen(message_P); XEvent e; - skypopen_sleep(1000); - XFlush(disp); + skypopen_sleep(1000); + XFlush(disp); memset(&e, 0, sizeof(e)); e.xclient.type = ClientMessage; @@ -1916,9 +1919,9 @@ int inbound_channel_answered(private_t *tech_pvt) channel = switch_core_session_get_channel(session); if (channel) { - switch_mutex_lock(tech_pvt->flag_mutex); + switch_mutex_lock(tech_pvt->flag_mutex); switch_set_flag(tech_pvt, TFLAG_IO); - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_mutex_unlock(tech_pvt->flag_mutex); } else { ERRORA("no channel\n", SKYPOPEN_P_LOG); } @@ -1938,30 +1941,30 @@ int skypopen_answered(private_t *tech_pvt) switch_core_session_t *session = NULL; switch_channel_t *channel = NULL; - if(strlen(tech_pvt->session_uuid_str)){ - session = switch_core_session_locate(tech_pvt->session_uuid_str); - if (session) { - channel = switch_core_session_get_channel(session); + if (strlen(tech_pvt->session_uuid_str)) { + session = switch_core_session_locate(tech_pvt->session_uuid_str); + if (session) { + channel = switch_core_session_get_channel(session); + + if (channel) { + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + tech_pvt->interface_state = SKYPOPEN_STATE_UP; + DEBUGA_SKYPE("Outbound Channel Answered! session_uuid_str=%s\n", SKYPOPEN_P_LOG, tech_pvt->session_uuid_str); + outbound_channel_answered(tech_pvt); + } else { + DEBUGA_SKYPE("answered Inbound Channel!\n\n\n\n", SKYPOPEN_P_LOG); + inbound_channel_answered(tech_pvt); + } - if (channel) { - if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - tech_pvt->interface_state = SKYPOPEN_STATE_UP; - DEBUGA_SKYPE("Outbound Channel Answered! session_uuid_str=%s\n", SKYPOPEN_P_LOG, tech_pvt->session_uuid_str); - outbound_channel_answered(tech_pvt); } else { - DEBUGA_SKYPE("answered Inbound Channel!\n\n\n\n", SKYPOPEN_P_LOG); - inbound_channel_answered(tech_pvt); + ERRORA("no channel after INPROGRESS?\n", SKYPOPEN_P_LOG); + return SWITCH_STATUS_FALSE; } - + switch_core_session_rwunlock(session); } else { - ERRORA("no channel after INPROGRESS?\n", SKYPOPEN_P_LOG); + WARNINGA("no session after INPROGRESS, let's hangup\n", SKYPOPEN_P_LOG); return SWITCH_STATUS_FALSE; } - switch_core_session_rwunlock(session); - } else { - WARNINGA("no session after INPROGRESS, let's hangup\n", SKYPOPEN_P_LOG); - return SWITCH_STATUS_FALSE; - } } else { WARNINGA("no tech_pvt->session_uuid_str after INPROGRESS, let's hangup\n", SKYPOPEN_P_LOG); return SWITCH_STATUS_FALSE;