mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-14 05:18:31 +00:00
skypopen: now answer a call only when directed to do it (before was trying to answer any incoming call). Lot of changes to a messy part, so maybe some problem will come out...
Signed-off-by: Giovanni Maruzzelli <gmaruzz@gmail.com>
This commit is contained in:
1 parent
4861e34bd2
commit
45c6c4d3e4
3 files changed
+256
-30
No files matched your search
@@ -179,6 +179,7 @@ static switch_status_t remove_interface(char *the_interface);
|
||||
|
||||
static switch_status_t channel_on_init(switch_core_session_t *session);
|
||||
static switch_status_t channel_on_hangup(switch_core_session_t *session);
|
||||
static switch_status_t channel_on_reset(switch_core_session_t *session);
|
||||
static switch_status_t channel_on_destroy(switch_core_session_t *session);
|
||||
static switch_status_t channel_on_routing(switch_core_session_t *session);
|
||||
static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
|
||||
@@ -434,10 +435,6 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
|
||||
where a destination has been identified. If the channel is simply
|
||||
left in the initial state, nothing will happen. */
|
||||
switch_channel_set_state(channel, CS_ROUTING);
|
||||
switch_mutex_lock(globals.mutex);
|
||||
globals.calls++;
|
||||
|
||||
switch_mutex_unlock(globals.mutex);
|
||||
DEBUGA_SKYPE("%s CHANNEL INIT %s\n", SKYPOPEN_P_LOG, tech_pvt->name, switch_core_session_get_uuid(session));
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -645,6 +642,29 @@ static switch_status_t channel_on_soft_execute(switch_core_session_t *session)
|
||||
DEBUGA_SKYPE("%s CHANNEL SOFT_EXECUTE\n", SKYPOPEN_P_LOG, tech_pvt->name);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
static switch_status_t channel_on_reset(switch_core_session_t *session)
|
||||
{
|
||||
private_t *tech_pvt = NULL;
|
||||
switch_channel_t *channel = NULL;
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
DEBUGA_SKYPE("%s CHANNEL RESET\n", SKYPOPEN_P_LOG, tech_pvt->name);
|
||||
|
||||
|
||||
if (session) {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
} else {
|
||||
ERRORA("No session???\n", SKYPOPEN_P_LOG);
|
||||
}
|
||||
if (channel) {
|
||||
switch_channel_set_state(channel, CS_HANGUP);
|
||||
} else {
|
||||
ERRORA("No channel???\n", SKYPOPEN_P_LOG);
|
||||
}
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
|
||||
{
|
||||
@@ -824,10 +844,14 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
switch_assert(tech_pvt != NULL);
|
||||
|
||||
if (!switch_channel_ready(channel) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
|
||||
if (!switch_channel_ready(channel)) {
|
||||
ERRORA("channel not ready \n", SKYPOPEN_P_LOG);
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
|
||||
DEBUGA_SKYPE("channel not in TFLAG_IO \n", SKYPOPEN_P_LOG);
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
|
||||
if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
|
||||
switch_swap_linear(frame->data, (int) frame->datalen / 2);
|
||||
@@ -865,6 +889,24 @@ 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_clear_flag(tech_pvt, TFLAG_IO);
|
||||
skypopen_answer(tech_pvt);
|
||||
|
||||
while(!switch_test_flag(tech_pvt, TFLAG_IO)){ //FIXME that would be better with a timeout
|
||||
if(switch_channel_get_state(channel) == CS_RESET){
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
switch_sleep(5000);
|
||||
}
|
||||
switch_mutex_lock(globals.mutex);
|
||||
globals.calls++;
|
||||
|
||||
switch_mutex_unlock(globals.mutex);
|
||||
DEBUGA_SKYPE("%s CHANNEL ANSWER %s\n", SKYPOPEN_P_LOG, tech_pvt->name, switch_core_session_get_uuid(session));
|
||||
|
||||
|
||||
|
||||
|
||||
DEBUGA_SKYPE("ANSWERED! \n", SKYPOPEN_P_LOG);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -991,7 +1033,7 @@ switch_state_handler_table_t skypopen_state_handlers = {
|
||||
/*.on_soft_execute */ channel_on_soft_execute,
|
||||
/*.on_consume_media */ channel_on_consume_media,
|
||||
/*.on_hibernate */ NULL,
|
||||
/*.on_reset */ NULL,
|
||||
/*.on_reset */ channel_on_reset,
|
||||
/*.on_park */ NULL,
|
||||
/*.on_reporting */ NULL,
|
||||
/*.on_destroy */ channel_on_destroy
|
||||
@@ -1184,6 +1226,12 @@ static void *SWITCH_THREAD_FUNC skypopen_signaling_thread_func(switch_thread_t *
|
||||
*tech_pvt->session_uuid_str = '\0';
|
||||
*tech_pvt->skype_call_id = '\0';
|
||||
*tech_pvt->initial_skype_user = '\0';
|
||||
*tech_pvt->answer_id = '\0';
|
||||
*tech_pvt->answer_value = '\0';
|
||||
*tech_pvt->ring_id = '\0';
|
||||
*tech_pvt->ring_value = '\0';
|
||||
*tech_pvt->callid_number = '\0';
|
||||
*tech_pvt->callid_name = '\0';
|
||||
switch_mutex_unlock(globals.mutex);
|
||||
|
||||
switch_sleep(300000); //0.3 sec
|
||||
@@ -1949,7 +1997,6 @@ int new_inbound_channel(private_t * tech_pvt)
|
||||
}
|
||||
}
|
||||
if (channel) {
|
||||
switch_channel_mark_answered(channel);
|
||||
switch_channel_set_variable(channel, "skype_user", tech_pvt->skype_user);
|
||||
switch_channel_set_variable(channel, "initial_skype_user", tech_pvt->initial_skype_user);
|
||||
}
|
||||
@@ -2261,34 +2308,149 @@ SWITCH_STANDARD_API(skypopen_function)
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int skypopen_answer(private_t * tech_pvt, char *id, char *value)
|
||||
|
||||
int skypopen_partner_handle_ring(private_t * tech_pvt)
|
||||
{
|
||||
char msg_to_skype[1024];
|
||||
int i;
|
||||
int found = 0;
|
||||
private_t *giovatech;
|
||||
struct timeval timenow;
|
||||
char *id = tech_pvt->ring_id;
|
||||
char *value = tech_pvt->ring_value;
|
||||
switch_core_session_t *session = NULL;
|
||||
switch_channel_t *channel = NULL;
|
||||
|
||||
switch_mutex_lock(globals.mutex);
|
||||
|
||||
//WARNINGA("PARTNER_HANDLE tech_pvt->skype_call_id=%s, tech_pvt->skype_callflow=%d, tech_pvt->interface_state=%d, tech_pvt->skype_user=%s, tech_pvt->callid_number=%s, tech_pvt->ring_value=%s, tech_pvt->ring_id=%s, tech_pvt->answer_value=%s, tech_pvt->answer_id=%s\n", SKYPOPEN_P_LOG, tech_pvt->skype_call_id, tech_pvt->skype_callflow, tech_pvt->interface_state, tech_pvt->skype_user, tech_pvt->callid_number, tech_pvt->ring_value, tech_pvt->ring_id, tech_pvt->answer_value, tech_pvt->answer_id);
|
||||
|
||||
gettimeofday(&timenow, NULL);
|
||||
for (i = 0; !found && i < SKYPOPEN_MAX_INTERFACES; i++) {
|
||||
if (strlen(globals.SKYPOPEN_INTERFACES[i].name)) {
|
||||
|
||||
giovatech = &globals.SKYPOPEN_INTERFACES[i];
|
||||
if (strlen(giovatech->skype_call_id) && (giovatech->interface_state != SKYPOPEN_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->callid_number, value)) && ((((timenow.tv_sec - giovatech->answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->answer_time.tv_usec)) < 1000000)) { //XXX 1.5sec - can have a max of 1 call coming from the same skypename to the same skypename each 1.5 seconds
|
||||
if ((giovatech->interface_state != SKYPOPEN_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->ring_value, value)) && ((((timenow.tv_sec - giovatech->ring_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->ring_time.tv_usec)) < 1000000)) { //XXX 1.0sec - can have a max of 1 call coming from the same skypename to the same skypename each 1.0 seconds
|
||||
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",
|
||||
SKYPOPEN_P_LOG, giovatech->name, giovatech->interface_state,
|
||||
giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
|
||||
if (tech_pvt->interface_state == SKYPOPEN_STATE_PRERING) {
|
||||
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", SKYPOPEN_P_LOG, giovatech->name, giovatech->interface_state, giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value);
|
||||
if (tech_pvt->interface_state == SKYPOPEN_STATE_PRERING) {
|
||||
tech_pvt->interface_state = SKYPOPEN_STATE_DOWN;
|
||||
} else if (tech_pvt->interface_state != 0 && tech_pvt->interface_state != SKYPOPEN_STATE_DOWN) {
|
||||
WARNINGA("Why an interface_state %d HERE?\n", SKYPOPEN_P_LOG, tech_pvt->interface_state);
|
||||
tech_pvt->interface_state = SKYPOPEN_STATE_DOWN;
|
||||
}
|
||||
|
||||
*tech_pvt->answer_id = '\0';
|
||||
*tech_pvt->answer_value = '\0';
|
||||
*tech_pvt->ring_id = '\0';
|
||||
*tech_pvt->ring_value = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
switch_mutex_unlock(globals.mutex);
|
||||
return 0;
|
||||
}
|
||||
DEBUGA_SKYPE("NOT FOUND\n", SKYPOPEN_P_LOG);
|
||||
|
||||
if (tech_pvt && tech_pvt->skype_call_id && !strlen(tech_pvt->skype_call_id)) {
|
||||
/* we are not inside an active call */
|
||||
|
||||
tech_pvt->interface_state = SKYPOPEN_STATE_PRERING;
|
||||
gettimeofday(&tech_pvt->ring_time, NULL);
|
||||
switch_copy_string(tech_pvt->callid_number, value, sizeof(tech_pvt->callid_number) - 1);
|
||||
|
||||
|
||||
//WARNINGA("PARTNER_HANDLE_RING tech_pvt->skype_call_id=%s, tech_pvt->skype_callflow=%d, tech_pvt->interface_state=%d, tech_pvt->skype_user=%s, tech_pvt->callid_number=%s, tech_pvt->ring_value=%s, tech_pvt->ring_id=%s, tech_pvt->answer_value=%s, tech_pvt->answer_id=%s\n", SKYPOPEN_P_LOG, tech_pvt->skype_call_id, tech_pvt->skype_callflow, tech_pvt->interface_state, tech_pvt->skype_user, tech_pvt->callid_number, tech_pvt->ring_value, tech_pvt->ring_id, tech_pvt->answer_value, tech_pvt->answer_id);
|
||||
|
||||
session = switch_core_session_locate(tech_pvt->session_uuid_str);
|
||||
if (session) {
|
||||
switch_core_session_rwunlock(session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
new_inbound_channel(tech_pvt);
|
||||
|
||||
session = switch_core_session_locate(tech_pvt->session_uuid_str);
|
||||
if (session) {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
|
||||
switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
|
||||
if (channel) {
|
||||
switch_channel_mark_ring_ready(channel);
|
||||
} else {
|
||||
ERRORA("no channel\n", SKYPOPEN_P_LOG);
|
||||
}
|
||||
switch_core_session_rwunlock(session);
|
||||
} else {
|
||||
ERRORA("no session\n", SKYPOPEN_P_LOG);
|
||||
|
||||
}
|
||||
|
||||
} else if (!tech_pvt || !tech_pvt->skype_call_id) {
|
||||
ERRORA("No Call ID?\n", SKYPOPEN_P_LOG);
|
||||
} else {
|
||||
DEBUGA_SKYPE("We're in a call now (%s), let's refuse this one (%s)\n", SKYPOPEN_P_LOG, tech_pvt->skype_call_id, id);
|
||||
sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id);
|
||||
skypopen_signaling_write(tech_pvt, msg_to_skype);
|
||||
}
|
||||
|
||||
switch_mutex_unlock(globals.mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int skypopen_answer(private_t * tech_pvt)
|
||||
{
|
||||
char msg_to_skype[1024];
|
||||
int i;
|
||||
int found = 0;
|
||||
private_t *giovatech;
|
||||
struct timeval timenow;
|
||||
char *id = tech_pvt->answer_id;
|
||||
char *value = tech_pvt->answer_value;
|
||||
switch_core_session_t *session = NULL;
|
||||
switch_channel_t *channel = NULL;
|
||||
|
||||
switch_mutex_lock(globals.mutex);
|
||||
|
||||
//WARNINGA("ANSWER tech_pvt->skype_call_id=%s, tech_pvt->skype_callflow=%d, tech_pvt->interface_state=%d, tech_pvt->skype_user=%s, tech_pvt->callid_number=%s, tech_pvt->ring_value=%s, tech_pvt->ring_id=%s, tech_pvt->answer_value=%s, tech_pvt->answer_id=%s\n", SKYPOPEN_P_LOG, tech_pvt->skype_call_id, tech_pvt->skype_callflow, tech_pvt->interface_state, tech_pvt->skype_user, tech_pvt->callid_number, tech_pvt->ring_value, tech_pvt->ring_id, tech_pvt->answer_value, tech_pvt->answer_id);
|
||||
|
||||
gettimeofday(&timenow, NULL);
|
||||
for (i = 0; !found && i < SKYPOPEN_MAX_INTERFACES; i++) {
|
||||
if (strlen(globals.SKYPOPEN_INTERFACES[i].name)) {
|
||||
|
||||
giovatech = &globals.SKYPOPEN_INTERFACES[i];
|
||||
if (strlen(giovatech->skype_call_id) && (giovatech->interface_state != SKYPOPEN_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->callid_number, value)) && ((((timenow.tv_sec - giovatech->answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->answer_time.tv_usec)) < 1000000)) { //XXX 1.0sec - can have a max of 1 call coming from the same skypename to the same skypename each 1.0 seconds
|
||||
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", SKYPOPEN_P_LOG, giovatech->name, giovatech->interface_state, giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value);
|
||||
if (tech_pvt->interface_state == SKYPOPEN_STATE_PRERING) {
|
||||
tech_pvt->interface_state = SKYPOPEN_STATE_DOWN;
|
||||
} else if (tech_pvt->interface_state != 0 && tech_pvt->interface_state != SKYPOPEN_STATE_DOWN) {
|
||||
WARNINGA("Why an interface_state %d HERE?\n", SKYPOPEN_P_LOG, tech_pvt->interface_state);
|
||||
tech_pvt->interface_state = SKYPOPEN_STATE_DOWN;
|
||||
}
|
||||
|
||||
|
||||
if (!zstr(tech_pvt->session_uuid_str)) {
|
||||
session = switch_core_session_locate(tech_pvt->session_uuid_str);
|
||||
} else {
|
||||
ERRORA("No session???\n", SKYPOPEN_P_LOG);
|
||||
}
|
||||
if (session) {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
} else {
|
||||
ERRORA("No session???\n", SKYPOPEN_P_LOG);
|
||||
}
|
||||
if (channel) {
|
||||
switch_channel_set_state(channel, CS_RESET);
|
||||
} else {
|
||||
ERRORA("No channel???\n", SKYPOPEN_P_LOG);
|
||||
}
|
||||
|
||||
switch_core_session_rwunlock(session);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2305,9 +2467,6 @@ int skypopen_answer(private_t * tech_pvt, char *id, char *value)
|
||||
|
||||
tech_pvt->ib_calls++;
|
||||
|
||||
sprintf(msg_to_skype, "GET CALL %s PARTNER_DISPNAME", id);
|
||||
skypopen_signaling_write(tech_pvt, msg_to_skype);
|
||||
switch_sleep(10000);
|
||||
tech_pvt->interface_state = SKYPOPEN_STATE_PREANSWER;
|
||||
sprintf(msg_to_skype, "ALTER CALL %s ANSWER", id);
|
||||
skypopen_signaling_write(tech_pvt, msg_to_skype);
|
||||
|
||||
Reference in new issue
Block a user