skypiax: added FS timers, allow for better Virtual Machine (xen, ec2) conference behavior, to be polished

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16521 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Giovanni Maruzzelli 2010-01-27 13:30:07 +00:00
parent 677246547b
commit 7323745f0a
3 changed files with 323 additions and 266 deletions

View File

@ -36,6 +36,7 @@
#include "skypiax.h" #include "skypiax.h"
#define MDL_CHAT_PROTO "skype" #define MDL_CHAT_PROTO "skype"
#define TIMER_WRITE
#ifdef WIN32 #ifdef WIN32
/***************/ /***************/
@ -193,7 +194,8 @@ static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause); switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
switch_call_cause_t *cancel_cause);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@ -255,7 +257,26 @@ switch_status_t skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *s
ERRORA("skypiax_codec FAILED\n", SKYPIAX_P_LOG); ERRORA("skypiax_codec FAILED\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
DEBUGA_SKYPE("skypiax_codec SUCCESS\n", SKYPIAX_P_LOG);
if (switch_core_timer_init(&tech_pvt->timer_read, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, skypiax_module_pool) !=
SWITCH_STATUS_SUCCESS) {
ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_FALSE;
}
switch_core_timer_sync(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
if (switch_core_timer_init(&tech_pvt->timer_write, "soft", 20, tech_pvt->write_codec.implementation->samples_per_packet, skypiax_module_pool) !=
SWITCH_STATUS_SUCCESS) {
ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_FALSE;
}
switch_core_timer_sync(&tech_pvt->timer_write);
#endif// TIMER_WRITE
DEBUGA_SKYPE("skypiax_tech_init SUCCESS\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -362,7 +383,7 @@ static switch_status_t remove_interface(char *the_interface)
globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL; globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
} }
#else #else
if(tech_pvt->running && tech_pvt->SkypiaxHandles.disp){ if (tech_pvt->running && tech_pvt->SkypiaxHandles.disp) {
XEvent e; XEvent e;
Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
memset(&e, 0, sizeof(e)); memset(&e, 0, sizeof(e));
@ -460,6 +481,14 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session)
if (switch_core_codec_ready(&tech_pvt->write_codec)) { if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec); switch_core_codec_destroy(&tech_pvt->write_codec);
} }
switch_core_timer_destroy(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
switch_core_timer_destroy(&tech_pvt->timer_write);
#endif// TIMER_WRITE
*tech_pvt->session_uuid_str = '\0'; *tech_pvt->session_uuid_str = '\0';
tech_pvt->interface_state = SKYPIAX_STATE_IDLE; tech_pvt->interface_state = SKYPIAX_STATE_IDLE;
if (tech_pvt->skype_callflow == CALLFLOW_STATUS_FINISHED) { if (tech_pvt->skype_callflow == CALLFLOW_STATUS_FINISHED) {
@ -582,7 +611,7 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
ERRORA("FYI %s CHANNEL in CS_NEW state got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel)); ERRORA("FYI %s CHANNEL in CS_NEW state got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
channel_on_hangup(session); channel_on_hangup(session);
} }
if ( switch_channel_get_state(channel) != CS_NEW && switch_channel_get_state(channel) < CS_EXECUTE) { if (switch_channel_get_state(channel) != CS_NEW && switch_channel_get_state(channel) < CS_EXECUTE) {
ERRORA("FYI %s CHANNEL in %d state got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel), switch_channel_get_state(channel)); ERRORA("FYI %s CHANNEL in %d state got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel), switch_channel_get_state(channel));
channel_on_hangup(session); channel_on_hangup(session);
} }
@ -662,6 +691,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
tech_pvt->read_frame.flags = SFF_NONE; tech_pvt->read_frame.flags = SFF_NONE;
*frame = NULL; *frame = NULL;
switch_core_timer_next(&tech_pvt->timer_read);
if (!skypiax_audio_read(tech_pvt)) { if (!skypiax_audio_read(tech_pvt)) {
ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG); ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG);
@ -745,21 +776,20 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
#else /* WIN32 */ #else /* WIN32 */
//sent = write(tech_pvt->audiopipe_cli[1], frame->data, sent); //sent = write(tech_pvt->audiopipe_cli[1], frame->data, sent);
#endif /* WIN32 */ #endif /* WIN32 */
//FIXME while(tech_pvt->flag_audio_cli == 1){
//FIXME switch_sleep(100); //1 millisec
//NOTICA("write now is 1\n", SKYPIAX_P_LOG);
//FIXME }
//WARNINGA("write is now 0\n", SKYPIAX_P_LOG);
//memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen); //memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
if(tech_pvt->flag_audio_cli == 1){ if (tech_pvt->flag_audio_cli == 1) {
switch_sleep(1000); //1 millisec switch_sleep(1000); //1 millisec
} }
if(tech_pvt->flag_audio_cli == 0){ if (tech_pvt->flag_audio_cli == 0) {
memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen); #ifdef TIMER_WRITE
tech_pvt->flag_audio_cli = 1;
} switch_core_timer_next(&tech_pvt->timer_write);
#endif// TIMER_WRITE
memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
tech_pvt->flag_audio_cli = 1;
}
//NOTICA("write \n", SKYPIAX_P_LOG); //NOTICA("write \n", SKYPIAX_P_LOG);
if (sent != frame->datalen && sent != -1) { if (sent != frame->datalen && sent != -1) {
@ -798,29 +828,38 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
switch_assert(tech_pvt != NULL); switch_assert(tech_pvt != NULL);
switch (msg->message_id) { switch (msg->message_id) {
case SWITCH_MESSAGE_INDICATE_ANSWER: case SWITCH_MESSAGE_INDICATE_ANSWER:
{ {
DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id); DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id);
channel_answer_channel(session);
} switch_core_timer_sync(&tech_pvt->timer_read);
break; #ifdef TIMER_WRITE
case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC: switch_core_timer_sync(&tech_pvt->timer_write);
#endif// TIMER_WRITE
channel_answer_channel(session);
}
break;
case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC:
DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n", SKYPIAX_P_LOG, switch_channel_get_name(channel)); DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
//for (i=0; i<50; i++) { switch_core_timer_sync(&tech_pvt->timer_read);
//skypiax_audio_read(tech_pvt); #ifdef TIMER_WRITE
//WARNINGA("read samples\n", SKYPIAX_P_LOG); switch_core_timer_sync(&tech_pvt->timer_write);
//} #endif// TIMER_WRITE
//switch_core_timer_sync(&tech_pvt->timer_read); break;
//switch_core_timer_sync(&tech_pvt->timer_write); default:
{
switch_core_timer_sync(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
break; switch_core_timer_sync(&tech_pvt->timer_write);
default: #endif// TIMER_WRITE
{
DEBUGA_SKYPE("MSG_ID=%d\n", SKYPIAX_P_LOG, msg->message_id); DEBUGA_SKYPE("MSG_ID=%d\n", SKYPIAX_P_LOG, msg->message_id);
} }
break; break;
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -869,7 +908,8 @@ switch_io_routines_t skypiax_io_routines = {
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause) switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
switch_call_cause_t *cancel_cause)
{ {
private_t *tech_pvt = NULL; private_t *tech_pvt = NULL;
if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) { if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
@ -961,10 +1001,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
if (outbound_profile) { if (outbound_profile) {
char name[128]; char name[128];
if (strncmp("ANY", outbound_profile->destination_number, 3 ) == 0) { if (strncmp("ANY", outbound_profile->destination_number, 3) == 0) {
snprintf(name, sizeof(name), "skypiax/ANY/%s%s", tech_pvt->name, outbound_profile->destination_number+3); snprintf(name, sizeof(name), "skypiax/ANY/%s%s", tech_pvt->name, outbound_profile->destination_number + 3);
} else if (strncmp("RR", outbound_profile->destination_number, 2) == 0) { } else if (strncmp("RR", outbound_profile->destination_number, 2) == 0) {
snprintf(name, sizeof(name), "skypiax/RR/%s%s", tech_pvt->name, outbound_profile->destination_number+2); snprintf(name, sizeof(name), "skypiax/RR/%s%s", tech_pvt->name, outbound_profile->destination_number + 2);
} else { } else {
snprintf(name, sizeof(name), "skypiax/%s", outbound_profile->destination_number); snprintf(name, sizeof(name), "skypiax/%s", outbound_profile->destination_number);
} }
@ -1261,7 +1301,7 @@ static switch_status_t load_config(int reload_type)
} else { } else {
DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG); DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
} }
switch_sleep(100); switch_sleep(1000);
#endif /* WIN32 */ #endif /* WIN32 */
if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) { if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) {
@ -1297,10 +1337,10 @@ static switch_status_t load_config(int reload_type)
switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].destination, destination); switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].destination, destination);
switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context); switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
if(!strcmp(report_incoming_chatmessages, "true") || !strcmp(report_incoming_chatmessages, "1")){ if (!strcmp(report_incoming_chatmessages, "true") || !strcmp(report_incoming_chatmessages, "1")) {
globals.SKYPIAX_INTERFACES[interface_id].report_incoming_chatmessages = 1; globals.SKYPIAX_INTERFACES[interface_id].report_incoming_chatmessages = 1;
}else { } else {
globals.SKYPIAX_INTERFACES[interface_id].report_incoming_chatmessages = 0; //redundant, just in case globals.SKYPIAX_INTERFACES[interface_id].report_incoming_chatmessages = 0; //redundant, just in case
} }
@ -1424,7 +1464,8 @@ static switch_status_t load_config(int reload_type)
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].dialplan=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].dialplan); DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].dialplan=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].dialplan);
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].destination=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].destination); DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].destination=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].destination);
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].context); DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].context);
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].report_incoming_chatmessages=%d\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].report_incoming_chatmessages); DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].report_incoming_chatmessages=%d\n", SKYPIAX_P_LOG, i, i,
globals.SKYPIAX_INTERFACES[i].report_incoming_chatmessages);
} }
} }
} }
@ -1434,25 +1475,27 @@ static switch_status_t load_config(int reload_type)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint) static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type,
const char *hint)
{ {
//char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL; //char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL;
char *user=NULL, *host, *f_user = NULL, *f_host = NULL, *f_resource = NULL; char *user = NULL, *host, *f_user = NULL, *f_host = NULL, *f_resource = NULL;
//mdl_profile_t *profile = NULL; //mdl_profile_t *profile = NULL;
private_t * tech_pvt=NULL; private_t *tech_pvt = NULL;
int i=0, found=0, tried=0; int i = 0, found = 0, tried = 0;
char skype_msg[1024]; char skype_msg[1024];
switch_assert(proto != NULL); switch_assert(proto != NULL);
DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL"); DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type,
hint ? hint : "NULL");
if (!to || !strlen(to)) { if (!to || !strlen(to)) {
ERRORA("Missing To: header.\n", SKYPIAX_P_LOG); ERRORA("Missing To: header.\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if ((!from && !hint) || (!strlen(from) && !strlen(hint)) ) { if ((!from && !hint) || (!strlen(from) && !strlen(hint))) {
ERRORA("Missing From: AND Hint: headers.\n", SKYPIAX_P_LOG); ERRORA("Missing From: AND Hint: headers.\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -1470,70 +1513,71 @@ static switch_status_t chat_send(const char *proto, const char *from, const char
if ((host = strchr(user, '@'))) { if ((host = strchr(user, '@'))) {
*host++ = '\0'; *host++ = '\0';
} }
//if (!strcmp(proto, MDL_CHAT_PROTO)) { //if (!strcmp(proto, MDL_CHAT_PROTO)) {
DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL"); DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type,
if (hint && strlen(hint)) { hint ? hint : "NULL");
//in hint we receive the interface name to use if (hint && strlen(hint)) {
for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) { //in hint we receive the interface name to use
if (strlen(globals.SKYPIAX_INTERFACES[i].name) for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
&& (strncmp(globals.SKYPIAX_INTERFACES[i].name, hint, strlen(hint)) == 0)) { if (strlen(globals.SKYPIAX_INTERFACES[i].name)
tech_pvt = &globals.SKYPIAX_INTERFACES[i]; && (strncmp(globals.SKYPIAX_INTERFACES[i].name, hint, strlen(hint)) == 0)) {
DEBUGA_SKYPE("Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name); tech_pvt = &globals.SKYPIAX_INTERFACES[i];
found = 1; DEBUGA_SKYPE("Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name);
break; found = 1;
}
}
} else {
//we have no a predefined interface name to use (hint is NULL), so let's choose an interface from the username (from)
for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
if (strlen(globals.SKYPIAX_INTERFACES[i].name)
&& (strncmp(globals.SKYPIAX_INTERFACES[i].skype_user, from, strlen(from)) == 0)) {
tech_pvt = &globals.SKYPIAX_INTERFACES[i];
DEBUGA_SKYPE("Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name);
found = 1;
break;
}
}
}
if (!found) {
ERRORA("ERROR: A Skypiax interface with name='%s' or one with skypeuser='%s' was not found\n", SKYPIAX_P_LOG, hint?hint:"NULL", from?from:"NULL");
goto end;
} else {
snprintf(skype_msg, sizeof(skype_msg), "CHAT CREATE %s", to);
skypiax_signaling_write(tech_pvt, skype_msg);
switch_sleep(100);
}
//} else {
//FIXME don't know how to do here, let's hope this is correct
//char *p;
//ffrom = switch_mprintf("%s+%s", proto, from);
//from = ffrom;
//if ((p = strchr(from, '/'))) {
//*p = '\0';
//}
//NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL");
//switch_core_chat_send(proto, proto, from, to, subject, body, type, hint);
//return SWITCH_STATUS_SUCCESS;
//}
found=0;
while(!found){
for(i=0; i<MAX_CHATS; i++){
if(!strcmp(tech_pvt->chats[i].dialog_partner, to) ){
snprintf(skype_msg, sizeof(skype_msg), "CHATMESSAGE %s %s", tech_pvt->chats[i].chatname, body);
skypiax_signaling_write(tech_pvt, skype_msg);
found=1;
break; break;
} }
} }
if(found){ } else {
//we have no a predefined interface name to use (hint is NULL), so let's choose an interface from the username (from)
for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
if (strlen(globals.SKYPIAX_INTERFACES[i].name)
&& (strncmp(globals.SKYPIAX_INTERFACES[i].skype_user, from, strlen(from)) == 0)) {
tech_pvt = &globals.SKYPIAX_INTERFACES[i];
DEBUGA_SKYPE("Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name);
found = 1;
break;
}
}
}
if (!found) {
ERRORA("ERROR: A Skypiax interface with name='%s' or one with skypeuser='%s' was not found\n", SKYPIAX_P_LOG, hint ? hint : "NULL",
from ? from : "NULL");
goto end;
} else {
snprintf(skype_msg, sizeof(skype_msg), "CHAT CREATE %s", to);
skypiax_signaling_write(tech_pvt, skype_msg);
switch_sleep(1000);
}
//} else {
//FIXME don't know how to do here, let's hope this is correct
//char *p;
//ffrom = switch_mprintf("%s+%s", proto, from);
//from = ffrom;
//if ((p = strchr(from, '/'))) {
//*p = '\0';
//}
//NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL");
//switch_core_chat_send(proto, proto, from, to, subject, body, type, hint);
//return SWITCH_STATUS_SUCCESS;
//}
found = 0;
while (!found) {
for (i = 0; i < MAX_CHATS; i++) {
if (!strcmp(tech_pvt->chats[i].dialog_partner, to)) {
snprintf(skype_msg, sizeof(skype_msg), "CHATMESSAGE %s %s", tech_pvt->chats[i].chatname, body);
skypiax_signaling_write(tech_pvt, skype_msg);
found = 1;
break;
}
}
if (found) {
break; break;
} }
if(tried > 1000){ if (tried > 1000) {
ERRORA("No chat with dialog_partner='%s' was found\n", SKYPIAX_P_LOG, to); ERRORA("No chat with dialog_partner='%s' was found\n", SKYPIAX_P_LOG, to);
break; break;
} }
@ -1541,7 +1585,7 @@ static switch_status_t chat_send(const char *proto, const char *from, const char
} }
} }
end: end:
switch_safe_free(user); switch_safe_free(user);
switch_safe_free(f_user); switch_safe_free(f_user);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -1563,10 +1607,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (switch_event_reserve_subclass(MY_EVENT_INCOMING_CHATMESSAGE) != SWITCH_STATUS_SUCCESS) { if (switch_event_reserve_subclass(MY_EVENT_INCOMING_CHATMESSAGE) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
@ -1617,10 +1661,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown)
globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL; globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
} }
#else #else
if(tech_pvt->SkypiaxHandles.disp){ if (tech_pvt->SkypiaxHandles.disp) {
XEvent e; XEvent e;
Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN",
False); False);
memset(&e, 0, sizeof(e)); memset(&e, 0, sizeof(e));
e.xclient.type = ClientMessage; e.xclient.type = ClientMessage;
e.xclient.message_type = atom1; /* leading message */ e.xclient.message_type = atom1; /* leading message */
@ -1662,7 +1706,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown)
} }
} }
switch_event_free_subclass(MY_EVENT_INCOMING_CHATMESSAGE); switch_event_free_subclass(MY_EVENT_INCOMING_CHATMESSAGE);
switch_safe_free(globals.dialplan); switch_safe_free(globals.dialplan);
switch_safe_free(globals.context); switch_safe_free(globals.context);
@ -1997,7 +2041,7 @@ SWITCH_STANDARD_API(sk_function)
} }
stream->write_function(stream, "\nTotal Interfaces: %d IB Calls(Failed/Total): %ld/%ld OB Calls(Failed/Total): %ld/%ld\n", stream->write_function(stream, "\nTotal Interfaces: %d IB Calls(Failed/Total): %ld/%ld OB Calls(Failed/Total): %ld/%ld\n",
globals.real_interfaces > 0 ? globals.real_interfaces - 1 : 0, ib_failed, ib, ob_failed, ob); globals.real_interfaces > 0 ? globals.real_interfaces - 1 : 0, ib_failed, ib, ob_failed, ob);
} else if (!strcasecmp(argv[0], "console")) { } else if (!strcasecmp(argv[0], "console")) {
int i; int i;
@ -2316,7 +2360,7 @@ int incoming_chatmessage(private_t * tech_pvt, int which)
DEBUGA_SKYPE("received CHATMESSAGE on interface %s\n", SKYPIAX_P_LOG, tech_pvt->name); DEBUGA_SKYPE("received CHATMESSAGE on interface %s\n", SKYPIAX_P_LOG, tech_pvt->name);
if(!tech_pvt->report_incoming_chatmessages){ if (!tech_pvt->report_incoming_chatmessages) {
DEBUGA_SKYPE("I will not generate an Event, report_incoming_chatmessages is %d\n", SKYPIAX_P_LOG, tech_pvt->report_incoming_chatmessages); DEBUGA_SKYPE("I will not generate an Event, report_incoming_chatmessages is %d\n", SKYPIAX_P_LOG, tech_pvt->report_incoming_chatmessages);
return 0; return 0;
} }
@ -2333,23 +2377,23 @@ int incoming_chatmessage(private_t * tech_pvt, int which)
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id);
switch_event_add_body(event, "%s", tech_pvt->chatmessages[which].body); switch_event_add_body(event, "%s", tech_pvt->chatmessages[which].body);
if(session){ if (session) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "true"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "true");
if (switch_core_session_queue_event(session, &event) != SWITCH_STATUS_SUCCESS) { if (switch_core_session_queue_event(session, &event) != SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
switch_event_fire(&event); switch_event_fire(&event);
} }
} else { //no session } else { //no session
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "false"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "false");
switch_event_fire(&event); switch_event_fire(&event);
event_sent_to_esl=1; event_sent_to_esl = 1;
} }
}else{ } else {
ERRORA("cannot create event on interface %s. WHY?????\n", SKYPIAX_P_LOG, tech_pvt->name); ERRORA("cannot create event on interface %s. WHY?????\n", SKYPIAX_P_LOG, tech_pvt->name);
} }
if(!event_sent_to_esl){ if (!event_sent_to_esl) {
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
@ -2360,21 +2404,21 @@ int incoming_chatmessage(private_t * tech_pvt, int which)
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id);
switch_event_add_body(event, "%s", tech_pvt->chatmessages[which].body); switch_event_add_body(event, "%s", tech_pvt->chatmessages[which].body);
if(session){ if (session) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "true"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "true");
} else { //no session } else { //no session
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "false"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "false");
} }
switch_event_fire(&event); switch_event_fire(&event);
} else{ } else {
ERRORA("cannot create event on interface %s. WHY?????\n", SKYPIAX_P_LOG, tech_pvt->name); ERRORA("cannot create event on interface %s. WHY?????\n", SKYPIAX_P_LOG, tech_pvt->name);
} }
} }
if(session){ if (session) {
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
} }
memset(&tech_pvt->chatmessages[which], '\0', sizeof(&tech_pvt->chatmessages[which]) ); memset(&tech_pvt->chatmessages[which], '\0', sizeof(&tech_pvt->chatmessages[which]));
return 0; return 0;
} }
@ -2407,7 +2451,7 @@ SWITCH_STANDARD_API(skypiax_chat_function)
for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) { for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
/* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */ /* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
if (strlen(globals.SKYPIAX_INTERFACES[i].name) if (strlen(globals.SKYPIAX_INTERFACES[i].name)
&& (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[0], strlen(argv[0])) == 0)) { && (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[0], strlen(argv[0])) == 0)) {
tech_pvt = &globals.SKYPIAX_INTERFACES[i]; tech_pvt = &globals.SKYPIAX_INTERFACES[i];
stream->write_function(stream, "Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", i, globals.SKYPIAX_INTERFACES[i].name); stream->write_function(stream, "Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", i, globals.SKYPIAX_INTERFACES[i].name);
found = 1; found = 1;
@ -2424,9 +2468,11 @@ SWITCH_STANDARD_API(skypiax_chat_function)
//chat_send(p*roto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint); //chat_send(p*roto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint);
//chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, hint); //chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, hint);
NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=NULL, hint=%s)\n", SKYPIAX_P_LOG, MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), tech_pvt->name); NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=NULL, hint=%s)\n", SKYPIAX_P_LOG, MDL_CHAT_PROTO, tech_pvt->skype_user,
argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), tech_pvt->name);
chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, tech_pvt->name); chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE",
switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, tech_pvt->name);
//NOTICA("TEXT is: %s\n", SKYPIAX_P_LOG, (char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1] ); //NOTICA("TEXT is: %s\n", SKYPIAX_P_LOG, (char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1] );
//snprintf(skype_msg, sizeof(skype_msg), "CHAT CREATE %s", argv[1]); //snprintf(skype_msg, sizeof(skype_msg), "CHAT CREATE %s", argv[1]);
@ -2440,21 +2486,22 @@ SWITCH_STANDARD_API(skypiax_chat_function)
#ifdef NOTDEF #ifdef NOTDEF
found=0; found = 0;
while(!found){ while (!found) {
for(i=0; i<MAX_CHATS; i++){ for (i = 0; i < MAX_CHATS; i++) {
if(!strcmp(tech_pvt->chats[i].dialog_partner, argv[1]) ){ if (!strcmp(tech_pvt->chats[i].dialog_partner, argv[1])) {
snprintf(skype_msg, sizeof(skype_msg), "CHATMESSAGE %s %s", tech_pvt->chats[i].chatname, (char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]); snprintf(skype_msg, sizeof(skype_msg), "CHATMESSAGE %s %s", tech_pvt->chats[i].chatname,
(char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]);
skypiax_signaling_write(tech_pvt, skype_msg); skypiax_signaling_write(tech_pvt, skype_msg);
found=1; found = 1;
break; break;
} }
} }
if(found){ if (found) {
break; break;
} }
if(tried > 1000){ if (tried > 1000) {
stream->write_function(stream, "ERROR: no chat with dialog_partner='%s' was found\n", argv[1]); stream->write_function(stream, "ERROR: no chat with dialog_partner='%s' was found\n", argv[1]);
break; break;
} }
@ -2462,7 +2509,7 @@ SWITCH_STANDARD_API(skypiax_chat_function)
} }
#endif //NOTDEF #endif //NOTDEF
end: end:
switch_safe_free(mycmd); switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;

View File

@ -277,6 +277,8 @@ struct private_object {
chatmessage_t chatmessages[MAX_CHATMESSAGES]; chatmessage_t chatmessages[MAX_CHATMESSAGES];
chat_t chats[MAX_CHATS]; chat_t chats[MAX_CHATS];
uint32_t report_incoming_chatmessages; uint32_t report_incoming_chatmessages;
switch_timer_t timer_read;
switch_timer_t timer_write;
}; };
typedef struct private_object private_t; typedef struct private_object private_t;

View File

@ -29,16 +29,16 @@ int xerror = 0;
int skypiax_socket_create_and_bind(private_t * tech_pvt, int *which_port) int skypiax_socket_create_and_bind(private_t * tech_pvt, int *which_port)
#else #else
int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_port) int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_port)
#endif //WIN32 #endif //WIN32
{ {
int s = -1; int s = -1;
struct sockaddr_in my_addr; struct sockaddr_in my_addr;
#ifndef WIN32 #ifndef WIN32
int start_port = 6001; int start_port = 6001;
#else #else
unsigned short start_port = 6001; unsigned short start_port = 6001;
#endif //WIN32 #endif //WIN32
int sockbufsize=0; int sockbufsize = 0;
unsigned int size = sizeof(int); unsigned int size = sizeof(int);
@ -78,13 +78,13 @@ unsigned short start_port = 6001;
DEBUGA_SKYPE("SUCCESS! *which_port=%d, tech_pvt->tcp_cli_port=%d, tech_pvt->tcp_srv_port=%d\n", SKYPIAX_P_LOG, *which_port, tech_pvt->tcp_cli_port, DEBUGA_SKYPE("SUCCESS! *which_port=%d, tech_pvt->tcp_cli_port=%d, tech_pvt->tcp_srv_port=%d\n", SKYPIAX_P_LOG, *which_port, tech_pvt->tcp_cli_port,
tech_pvt->tcp_srv_port); tech_pvt->tcp_srv_port);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("1 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("1 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("1 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("1 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
@ -94,16 +94,16 @@ unsigned short start_port = 6001;
* sockbufsize=SAMPLES_PER_FRAME * 8; * sockbufsize=SAMPLES_PER_FRAME * 8;
*/ */
#ifdef WIN32 #ifdef WIN32
sockbufsize=SAMPLES_PER_FRAME * 8 * 3; sockbufsize = SAMPLES_PER_FRAME * 8 * 3;
#else #else
sockbufsize=SAMPLES_PER_FRAME * 8; sockbufsize = SAMPLES_PER_FRAME * 8;
#endif //WIN32 #endif //WIN32
size = sizeof(int); size = sizeof(int);
setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, size); setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, size);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("2 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("2 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
/* for virtual machines, eg: Linux domU-12-31-39-02-68-28 2.6.18-xenU-ec2-v1.0 #2 SMP Tue Feb 19 10:51:53 EST 2008 i686 athlon i386 GNU/Linux /* for virtual machines, eg: Linux domU-12-31-39-02-68-28 2.6.18-xenU-ec2-v1.0 #2 SMP Tue Feb 19 10:51:53 EST 2008 i686 athlon i386 GNU/Linux
@ -111,17 +111,17 @@ unsigned short start_port = 6001;
* sockbufsize=SAMPLES_PER_FRAME * 8; * sockbufsize=SAMPLES_PER_FRAME * 8;
*/ */
#ifdef WIN32 #ifdef WIN32
sockbufsize=SAMPLES_PER_FRAME * 8 * 3; sockbufsize = SAMPLES_PER_FRAME * 8 * 3;
#else #else
sockbufsize=SAMPLES_PER_FRAME * 8; sockbufsize = SAMPLES_PER_FRAME * 8;
#endif //WIN32 #endif //WIN32
size = sizeof(int); size = sizeof(int);
setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsize, size); setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("2 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("2 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
@ -295,20 +295,21 @@ int skypiax_signaling_read(private_t * tech_pvt)
if (!strcasecmp(prop, "DIALOG_PARTNER")) { if (!strcasecmp(prop, "DIALOG_PARTNER")) {
DEBUGA_SKYPE("CHAT %s has DIALOG_PARTNER %s\n", SKYPIAX_P_LOG, id, value); DEBUGA_SKYPE("CHAT %s has DIALOG_PARTNER %s\n", SKYPIAX_P_LOG, id, value);
found=0; found = 0;
for(i=0; i<MAX_CHATS; i++){ for (i = 0; i < MAX_CHATS; i++) {
if(strlen(tech_pvt->chats[i].chatname) == 0 || !strcmp(tech_pvt->chats[i].chatname, id) ){ if (strlen(tech_pvt->chats[i].chatname) == 0 || !strcmp(tech_pvt->chats[i].chatname, id)) {
strncpy(tech_pvt->chats[i].chatname, id, sizeof(tech_pvt->chats[i].chatname)); strncpy(tech_pvt->chats[i].chatname, id, sizeof(tech_pvt->chats[i].chatname));
strncpy(tech_pvt->chats[i].dialog_partner, value, sizeof(tech_pvt->chats[i].dialog_partner)); strncpy(tech_pvt->chats[i].dialog_partner, value, sizeof(tech_pvt->chats[i].dialog_partner));
found=1; found = 1;
break; break;
} }
} }
if(!found){ if (!found) {
DEBUGA_SKYPE("why we do not have a chats slot free? we have more than %d chats in parallel?\n", SKYPIAX_P_LOG, MAX_CHATS); DEBUGA_SKYPE("why we do not have a chats slot free? we have more than %d chats in parallel?\n", SKYPIAX_P_LOG, MAX_CHATS);
} }
DEBUGA_SKYPE("CHAT %s is in position %d in the chats array, chatname=%s, dialog_partner=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chats[i].chatname, tech_pvt->chats[i].dialog_partner); DEBUGA_SKYPE("CHAT %s is in position %d in the chats array, chatname=%s, dialog_partner=%s\n", SKYPIAX_P_LOG, id, i,
tech_pvt->chats[i].chatname, tech_pvt->chats[i].dialog_partner);
} }
} }
@ -334,28 +335,30 @@ int skypiax_signaling_read(private_t * tech_pvt)
if (!strcasecmp(prop, "TYPE") && !strcasecmp(value, "SAID")) { if (!strcasecmp(prop, "TYPE") && !strcasecmp(value, "SAID")) {
DEBUGA_SKYPE("CHATMESSAGE %s is of type SAID, let's get the other infos\n", SKYPIAX_P_LOG, id); DEBUGA_SKYPE("CHATMESSAGE %s is of type SAID, let's get the other infos\n", SKYPIAX_P_LOG, id);
found=0; found = 0;
for(i=0; i<MAX_CHATMESSAGES; i++){ for (i = 0; i < MAX_CHATMESSAGES; i++) {
if(strlen(tech_pvt->chatmessages[i].id) == 0){ if (strlen(tech_pvt->chatmessages[i].id) == 0) {
strncpy(tech_pvt->chatmessages[i].id, id, sizeof(tech_pvt->chatmessages[i].id)); strncpy(tech_pvt->chatmessages[i].id, id, sizeof(tech_pvt->chatmessages[i].id));
strncpy(tech_pvt->chatmessages[i].type, value, sizeof(tech_pvt->chatmessages[i].type)); strncpy(tech_pvt->chatmessages[i].type, value, sizeof(tech_pvt->chatmessages[i].type));
found=1; found = 1;
break; break;
} }
} }
if(!found){ if (!found) {
DEBUGA_SKYPE("why we do not have a chatmessages slot free? we have more than %d chatmessages in parallel?\n", SKYPIAX_P_LOG, MAX_CHATMESSAGES); DEBUGA_SKYPE("why we do not have a chatmessages slot free? we have more than %d chatmessages in parallel?\n", SKYPIAX_P_LOG,
MAX_CHATMESSAGES);
} else { } else {
DEBUGA_SKYPE("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id); DEBUGA_SKYPE("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s\n", SKYPIAX_P_LOG, id, i,
tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id);
sprintf(msg_to_skype, "GET CHATMESSAGE %s CHATNAME", id); sprintf(msg_to_skype, "GET CHATMESSAGE %s CHATNAME", id);
skypiax_signaling_write(tech_pvt, msg_to_skype); skypiax_signaling_write(tech_pvt, msg_to_skype);
skypiax_sleep(100); skypiax_sleep(1000);
sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_HANDLE", id); sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_HANDLE", id);
skypiax_signaling_write(tech_pvt, msg_to_skype); skypiax_signaling_write(tech_pvt, msg_to_skype);
skypiax_sleep(100); skypiax_sleep(1000);
sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_DISPNAME", id); sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_DISPNAME", id);
skypiax_signaling_write(tech_pvt, msg_to_skype); skypiax_signaling_write(tech_pvt, msg_to_skype);
skypiax_sleep(100); skypiax_sleep(1000);
sprintf(msg_to_skype, "GET CHATMESSAGE %s BODY", id); sprintf(msg_to_skype, "GET CHATMESSAGE %s BODY", id);
skypiax_signaling_write(tech_pvt, msg_to_skype); skypiax_signaling_write(tech_pvt, msg_to_skype);
} }
@ -363,63 +366,66 @@ int skypiax_signaling_read(private_t * tech_pvt)
if (!strcasecmp(prop, "CHATNAME")) { if (!strcasecmp(prop, "CHATNAME")) {
DEBUGA_SKYPE("CHATMESSAGE %s belongs to the CHAT %s\n", SKYPIAX_P_LOG, id, value); DEBUGA_SKYPE("CHATMESSAGE %s belongs to the CHAT %s\n", SKYPIAX_P_LOG, id, value);
found=0; found = 0;
for(i=0; i<MAX_CHATMESSAGES; i++){ for (i = 0; i < MAX_CHATMESSAGES; i++) {
if(!strcmp(tech_pvt->chatmessages[i].id, id)){ if (!strcmp(tech_pvt->chatmessages[i].id, id)) {
strncpy(tech_pvt->chatmessages[i].chatname, value, sizeof(tech_pvt->chatmessages[i].chatname)); strncpy(tech_pvt->chatmessages[i].chatname, value, sizeof(tech_pvt->chatmessages[i].chatname));
found=1; found = 1;
break; break;
} }
} }
if(!found){ if (!found) {
DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id); DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
} }
} }
if (!strcasecmp(prop, "FROM_HANDLE")) { if (!strcasecmp(prop, "FROM_HANDLE")) {
DEBUGA_SKYPE("CHATMESSAGE %s was sent by FROM_HANDLE %s\n", SKYPIAX_P_LOG, id, value); DEBUGA_SKYPE("CHATMESSAGE %s was sent by FROM_HANDLE %s\n", SKYPIAX_P_LOG, id, value);
found=0; found = 0;
for(i=0; i<MAX_CHATMESSAGES; i++){ for (i = 0; i < MAX_CHATMESSAGES; i++) {
if(!strcmp(tech_pvt->chatmessages[i].id, id)){ if (!strcmp(tech_pvt->chatmessages[i].id, id)) {
strncpy(tech_pvt->chatmessages[i].from_handle, value, sizeof(tech_pvt->chatmessages[i].from_handle)); strncpy(tech_pvt->chatmessages[i].from_handle, value, sizeof(tech_pvt->chatmessages[i].from_handle));
found=1; found = 1;
break; break;
} }
} }
if(!found){ if (!found) {
DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id); DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
} }
} }
if (!strcasecmp(prop, "FROM_DISPNAME")) { if (!strcasecmp(prop, "FROM_DISPNAME")) {
DEBUGA_SKYPE("CHATMESSAGE %s was sent by FROM_DISPNAME %s\n", SKYPIAX_P_LOG, id, value); DEBUGA_SKYPE("CHATMESSAGE %s was sent by FROM_DISPNAME %s\n", SKYPIAX_P_LOG, id, value);
found=0; found = 0;
for(i=0; i<MAX_CHATMESSAGES; i++){ for (i = 0; i < MAX_CHATMESSAGES; i++) {
if(!strcmp(tech_pvt->chatmessages[i].id, id)){ if (!strcmp(tech_pvt->chatmessages[i].id, id)) {
strncpy(tech_pvt->chatmessages[i].from_dispname, value, sizeof(tech_pvt->chatmessages[i].from_dispname)); strncpy(tech_pvt->chatmessages[i].from_dispname, value, sizeof(tech_pvt->chatmessages[i].from_dispname));
found=1; found = 1;
break; break;
} }
} }
if(!found){ if (!found) {
DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id); DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
} }
} }
if (!strcasecmp(prop, "BODY")) { if (!strcasecmp(prop, "BODY")) {
DEBUGA_SKYPE("CHATMESSAGE %s has BODY %s\n", SKYPIAX_P_LOG, id, value); DEBUGA_SKYPE("CHATMESSAGE %s has BODY %s\n", SKYPIAX_P_LOG, id, value);
found=0; found = 0;
for(i=0; i<MAX_CHATMESSAGES; i++){ for (i = 0; i < MAX_CHATMESSAGES; i++) {
if(!strcmp(tech_pvt->chatmessages[i].id, id)){ if (!strcmp(tech_pvt->chatmessages[i].id, id)) {
strncpy(tech_pvt->chatmessages[i].body, value, sizeof(tech_pvt->chatmessages[i].body)); strncpy(tech_pvt->chatmessages[i].body, value, sizeof(tech_pvt->chatmessages[i].body));
found=1; found = 1;
break; break;
} }
} }
if(!found){ if (!found) {
DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id); DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
}else { } else {
DEBUGA_SKYPE("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s, chatname=%s, from_handle=%s, from_dispname=%s, body=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id, tech_pvt->chatmessages[i].chatname, tech_pvt->chatmessages[i].from_handle, tech_pvt->chatmessages[i].from_dispname, tech_pvt->chatmessages[i].body); DEBUGA_SKYPE
if(strcmp(tech_pvt->chatmessages[i].from_handle, tech_pvt->skype_user)){ //if the message was not sent by myself ("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s, chatname=%s, from_handle=%s, from_dispname=%s, body=%s\n",
SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id, tech_pvt->chatmessages[i].chatname,
tech_pvt->chatmessages[i].from_handle, tech_pvt->chatmessages[i].from_dispname, tech_pvt->chatmessages[i].body);
if (strcmp(tech_pvt->chatmessages[i].from_handle, tech_pvt->skype_user)) { //if the message was not sent by myself
incoming_chatmessage(tech_pvt, i); incoming_chatmessage(tech_pvt, i);
} }
} }
@ -535,7 +541,7 @@ int skypiax_signaling_read(private_t * tech_pvt)
tech_pvt->skype_callflow = CALLFLOW_STATUS_EARLYMEDIA; tech_pvt->skype_callflow = CALLFLOW_STATUS_EARLYMEDIA;
tech_pvt->interface_state = SKYPIAX_STATE_DIALING; tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
DEBUGA_SKYPE("Our remote party in skype_call %s is EARLYMEDIA\n", SKYPIAX_P_LOG, id); DEBUGA_SKYPE("Our remote party in skype_call %s is EARLYMEDIA\n", SKYPIAX_P_LOG, id);
if(tech_pvt->tcp_cli_thread == NULL){ if (tech_pvt->tcp_cli_thread == NULL) {
DEBUGA_SKYPE("START start_audio_threads\n", SKYPIAX_P_LOG); DEBUGA_SKYPE("START start_audio_threads\n", SKYPIAX_P_LOG);
if (start_audio_threads(tech_pvt)) { if (start_audio_threads(tech_pvt)) {
ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG); ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG);
@ -627,7 +633,7 @@ int skypiax_signaling_read(private_t * tech_pvt)
tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS; tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
tech_pvt->interface_state = SKYPIAX_STATE_UP; tech_pvt->interface_state = SKYPIAX_STATE_UP;
if(tech_pvt->tcp_cli_thread == NULL){ if (tech_pvt->tcp_cli_thread == NULL) {
DEBUGA_SKYPE("START start_audio_threads\n", SKYPIAX_P_LOG); DEBUGA_SKYPE("START start_audio_threads\n", SKYPIAX_P_LOG);
if (start_audio_threads(tech_pvt)) { if (start_audio_threads(tech_pvt)) {
ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG); ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG);
@ -733,7 +739,7 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
unsigned int kill_cli_size; unsigned int kill_cli_size;
short kill_cli_buff[SAMPLES_PER_FRAME]; short kill_cli_buff[SAMPLES_PER_FRAME];
short totalbuf[SAMPLES_PER_FRAME]; short totalbuf[SAMPLES_PER_FRAME];
int sockbufsize=0; int sockbufsize = 0;
unsigned int size = sizeof(int); unsigned int size = sizeof(int);
s = skypiax_socket_create_and_bind(tech_pvt, &tech_pvt->tcp_srv_port); s = skypiax_socket_create_and_bind(tech_pvt, &tech_pvt->tcp_srv_port);
@ -775,14 +781,14 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
while (s > 0 && (fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) { while (s > 0 && (fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
DEBUGA_SKYPE("ACCEPTED here I send you %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_srv_port); DEBUGA_SKYPE("ACCEPTED here I send you %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_srv_port);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("3 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("3 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("3 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("3 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
if (!(running && tech_pvt->running)) if (!(running && tech_pvt->running))
@ -853,20 +859,20 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
} }
/* send the complete frame through the pipe to our code waiting for incoming audio */ /* send the complete frame through the pipe to our code waiting for incoming audio */
//howmany = skypiax_pipe_write(tech_pvt->audiopipe_srv[1], totalbuf, SAMPLES_PER_FRAME * sizeof(short)); //howmany = skypiax_pipe_write(tech_pvt->audiopipe_srv[1], totalbuf, SAMPLES_PER_FRAME * sizeof(short));
//FIXME while(tech_pvt->flag_audio_srv == 1){ //FIXME while(tech_pvt->flag_audio_srv == 1){
//FIXME switch_sleep(100); //1 millisec //FIXME switch_sleep(100); //1 millisec
//NOTICA("read now is 1\n", SKYPIAX_P_LOG); //NOTICA("read now is 1\n", SKYPIAX_P_LOG);
//FIXME } //FIXME }
//WARNINGA("read is now 0\n", SKYPIAX_P_LOG); //WARNINGA("read is now 0\n", SKYPIAX_P_LOG);
howmany = SAMPLES_PER_FRAME * sizeof(short); howmany = SAMPLES_PER_FRAME * sizeof(short);
if(tech_pvt->flag_audio_srv == 1){ if (tech_pvt->flag_audio_srv == 1) {
switch_sleep(1000); //1 millisec switch_sleep(1000); //1 millisec
} }
if(tech_pvt->flag_audio_srv == 0){ if (tech_pvt->flag_audio_srv == 0) {
memcpy(tech_pvt->audiobuf_srv, totalbuf, SAMPLES_PER_FRAME * sizeof(short)); memcpy(tech_pvt->audiobuf_srv, totalbuf, SAMPLES_PER_FRAME * sizeof(short));
tech_pvt->flag_audio_srv = 1; tech_pvt->flag_audio_srv = 1;
} }
//NOTICA("read \n", SKYPIAX_P_LOG); //NOTICA("read \n", SKYPIAX_P_LOG);
if (howmany != SAMPLES_PER_FRAME * sizeof(short)) { if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
@ -902,14 +908,14 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
kill_cli_size = SAMPLES_PER_FRAME * sizeof(short); kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
len = skypiax_pipe_write(tech_pvt->audiopipe_cli[1], kill_cli_buff, kill_cli_size); len = skypiax_pipe_write(tech_pvt->audiopipe_cli[1], kill_cli_buff, kill_cli_size);
tech_pvt->flag_audio_cli = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die tech_pvt->flag_audio_cli = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
skypiax_sleep(200); skypiax_sleep(200);
tech_pvt->flag_audio_srv = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die tech_pvt->flag_audio_srv = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
skypiax_sleep(200); skypiax_sleep(200);
tech_pvt->interface_state = SKYPIAX_STATE_DOWN; tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
tech_pvt->flag_audio_cli = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die tech_pvt->flag_audio_cli = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
skypiax_sleep(200); skypiax_sleep(200);
tech_pvt->flag_audio_srv = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die tech_pvt->flag_audio_srv = 1; //let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die
skypiax_sleep(200); skypiax_sleep(200);
DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG); DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
skypiax_close_socket(fd); skypiax_close_socket(fd);
@ -919,7 +925,7 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
DEBUGA_SKYPE("incoming audio server (I am it) EXITING\n", SKYPIAX_P_LOG); DEBUGA_SKYPE("incoming audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
skypiax_close_socket(s); skypiax_close_socket(s);
s=-1; s = -1;
return NULL; return NULL;
} }
@ -941,7 +947,7 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
#else #else
unsigned int sin_size; unsigned int sin_size;
#endif /* WIN32 */ #endif /* WIN32 */
int sockbufsize=0; int sockbufsize = 0;
unsigned int size = sizeof(int); unsigned int size = sizeof(int);
s = skypiax_socket_create_and_bind(tech_pvt, &tech_pvt->tcp_cli_port); s = skypiax_socket_create_and_bind(tech_pvt, &tech_pvt->tcp_cli_port);
@ -986,14 +992,14 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
while (s > 0 && (fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) { while (s > 0 && (fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
DEBUGA_SKYPE("ACCEPTED here you send me %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_cli_port); DEBUGA_SKYPE("ACCEPTED here you send me %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_cli_port);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("4 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("4 SO_RCVBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
sockbufsize=0; sockbufsize = 0;
size = sizeof(int); size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsize, &size); getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &size);
DEBUGA_SKYPE("4 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size); DEBUGA_SKYPE("4 SO_SNDBUF is %d, size is %d\n", SKYPIAX_P_LOG, sockbufsize, size);
@ -1035,15 +1041,15 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
FD_SET(fdselect, &fs); FD_SET(fdselect, &fs);
//FIXME rt = select(fdselect + 1, NULL, &fs, NULL, &to); //FIXME rt = select(fdselect + 1, NULL, &fs, NULL, &to);
while(tech_pvt->flag_audio_cli == 0){ while (tech_pvt->flag_audio_cli == 0) {
#ifdef WIN32 #ifdef WIN32
skypiax_sleep(100); //0.1 millisec skypiax_sleep(100); //0.1 millisec
#else #else
skypiax_sleep(1000); //1 millisec skypiax_sleep(1000); //1 millisec
#endif //WIN32 #endif //WIN32
//WARNINGA("write now is 0\n", SKYPIAX_P_LOG); //WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
} }
//ERRORA("write is now 1\n", SKYPIAX_P_LOG); //ERRORA("write is now 1\n", SKYPIAX_P_LOG);
rt = 1; rt = 1;
@ -1137,7 +1143,7 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
DEBUGA_SKYPE("outbound audio server (I am it) EXITING\n", SKYPIAX_P_LOG); DEBUGA_SKYPE("outbound audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
skypiax_close_socket(s); skypiax_close_socket(s);
s=-1; s = -1;
return NULL; return NULL;
} }
@ -1145,16 +1151,16 @@ int skypiax_audio_read(private_t * tech_pvt)
{ {
unsigned int samples; unsigned int samples;
while(tech_pvt->flag_audio_srv == 0){ while (tech_pvt->flag_audio_srv == 0) {
#ifdef WIN32 #ifdef WIN32
skypiax_sleep(100); //0.1 millisec skypiax_sleep(100); //0.1 millisec
#else #else
skypiax_sleep(1000); //1 millisec skypiax_sleep(1000); //1 millisec
#endif //WIN32 #endif //WIN32
//WARNINGA("read now is 0\n", SKYPIAX_P_LOG); //WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
} }
//ERRORA("read is now 1\n", SKYPIAX_P_LOG); //ERRORA("read is now 1\n", SKYPIAX_P_LOG);
//samples = skypiax_pipe_read(tech_pvt->audiopipe_srv[0], tech_pvt->read_frame.data, SAMPLES_PER_FRAME * sizeof(short)); //samples = skypiax_pipe_read(tech_pvt->audiopipe_srv[0], tech_pvt->read_frame.data, SAMPLES_PER_FRAME * sizeof(short));
samples = SAMPLES_PER_FRAME * sizeof(short); samples = SAMPLES_PER_FRAME * sizeof(short);
memcpy(tech_pvt->read_frame.data, tech_pvt->audiobuf_srv, SAMPLES_PER_FRAME * sizeof(short)); memcpy(tech_pvt->read_frame.data, tech_pvt->audiobuf_srv, SAMPLES_PER_FRAME * sizeof(short));
@ -1256,7 +1262,7 @@ int skypiax_pipe_read(int pipe, short *buf, int howmany)
int skypiax_pipe_write(int pipe, short *buf, int howmany) int skypiax_pipe_write(int pipe, short *buf, int howmany)
{ {
if(buf){ if (buf) {
howmany = write(pipe, buf, howmany); howmany = write(pipe, buf, howmany);
return howmany; return howmany;
} else { } else {
@ -1628,7 +1634,7 @@ int skypiax_send_message(private_t * tech_pvt, const char *message_P)
XSync(disp, False); XSync(disp, False);
ok = X11_errors_untrap(); ok = X11_errors_untrap();
if (!ok){ if (!ok) {
ERRORA("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror); ERRORA("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror);
tech_pvt->running = 0; tech_pvt->running = 0;
return 0; return 0;
@ -1754,7 +1760,7 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
root = DefaultRootWindow(disp); root = DefaultRootWindow(disp);
win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp))); win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp)));
SkypiaxHandles->win = win; SkypiaxHandles->win = win;
snprintf(buf, 512, "NAME skypiax"); snprintf(buf, 512, "NAME skypiax");
@ -1762,7 +1768,7 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG); ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
running = 0; running = 0;
//if(disp) //if(disp)
//XCloseDisplay(disp); //XCloseDisplay(disp);
return NULL; return NULL;
} }
@ -1771,14 +1777,14 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG); ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
running = 0; running = 0;
//if(disp) //if(disp)
//XCloseDisplay(disp); //XCloseDisplay(disp);
return NULL; return NULL;
} }
{ {
/* perform an events loop */ /* perform an events loop */
XEvent an_event; XEvent an_event;
char buf[21]; /* can't be longer */ char buf[21]; /* can't be longer */
char buffer[17000]; char buffer[17000];
char continuebuffer[17000]; char continuebuffer[17000];
char *b; char *b;
@ -1799,8 +1805,8 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
switch (an_event.type) { switch (an_event.type) {
case ClientMessage: case ClientMessage:
if (an_event.xclient.format != 8){ if (an_event.xclient.format != 8) {
skypiax_sleep(100); //0.1 msec skypiax_sleep(1000); //0.1 msec
break; break;
} }
@ -1818,11 +1824,13 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
unsigned int howmany; unsigned int howmany;
howmany = strlen(b) + 1; howmany = strlen(b) + 1;
howmany = write(SkypiaxHandles->fdesc[1], b, howmany); howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
WARNINGA("A begin atom while the previous message is not closed???? value of previous message (between vertical bars) is=|||%s|||, will be lost\n", SKYPIAX_P_LOG, buffer); WARNINGA
("A begin atom while the previous message is not closed???? value of previous message (between vertical bars) is=|||%s|||, will be lost\n",
SKYPIAX_P_LOG, buffer);
memset(buffer, '\0', 17000); memset(buffer, '\0', 17000);
} }
if(continue_is_broken){ if (continue_is_broken) {
continue_is_broken=0; continue_is_broken = 0;
there_were_continues = 1; there_were_continues = 1;
} }
} }
@ -1831,7 +1839,8 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
if (!strlen(buffer)) { if (!strlen(buffer)) {
DEBUGA_SKYPE DEBUGA_SKYPE
("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||, let's store it and hope next 'begin' will be the good one\n", SKYPIAX_P_LOG, buf); ("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||, let's store it and hope next 'begin' will be the good one\n",
SKYPIAX_P_LOG, buf);
strcat(continuebuffer, buf); strcat(continuebuffer, buf);
continue_is_broken = 1; continue_is_broken = 1;
if (!strncmp(buf, "ognised identity", 15)) { if (!strncmp(buf, "ognised identity", 15)) {
@ -1840,16 +1849,15 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
SKYPIAX_P_LOG, buf); SKYPIAX_P_LOG, buf);
skypiax_sleep(1000000); //1 sec skypiax_sleep(1000000); //1 sec
} }
skypiax_sleep(100); //0.1 msec skypiax_sleep(1000); //0.1 msec
break; break;
} }
} }
if(continue_is_broken){ if (continue_is_broken) {
XFlush(disp); XFlush(disp);
skypiax_sleep(100); //0.1 msec skypiax_sleep(1000); //0.1 msec
continue; continue;
} }
//DEBUGA_SKYPE ("i=%d, buffer=|||%s|||\n", SKYPIAX_P_LOG, i, buffer); //DEBUGA_SKYPE ("i=%d, buffer=|||%s|||\n", SKYPIAX_P_LOG, i, buffer);
strcat(buffer, buf); strcat(buffer, buf);
//DEBUGA_SKYPE ("i=%d, buffer=|||%s|||\n", SKYPIAX_P_LOG, i, buffer); //DEBUGA_SKYPE ("i=%d, buffer=|||%s|||\n", SKYPIAX_P_LOG, i, buffer);
@ -1869,10 +1877,10 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
there_were_continues = 0; there_were_continues = 0;
} }
skypiax_sleep(100); //0.1 msec skypiax_sleep(1000); //0.1 msec
break; break;
default: default:
skypiax_sleep(100); //0.1 msec skypiax_sleep(1000); //0.1 msec
break; break;
} }
} }
@ -1881,12 +1889,12 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n", SKYPIAX_P_LOG); ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n", SKYPIAX_P_LOG);
running = 0; running = 0;
//if(disp) //if(disp)
//XCloseDisplay(disp); //XCloseDisplay(disp);
return NULL; return NULL;
} }
//running = 0; //running = 0;
//if(disp) //if(disp)
//XCloseDisplay(disp); //XCloseDisplay(disp);
return NULL; return NULL;
} }