[Freeswitch-branches] [commit] r11890 - in freeswitch/branches/gmaruzz/mod_skypiax: . asterisk
FreeSWITCH SVN
gmaruzz at freeswitch.org
Wed Feb 11 12:24:59 PST 2009
Author: gmaruzz
Date: Wed Feb 11 14:24:59 2009
New Revision: 11890
Log:
skypiax: multiple incoming calls to the same skype_name is working on FS, is working but deadlocks on * ;-) (gotta fix it soon)
Modified:
freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c
freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h
freeswitch/branches/gmaruzz/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/mod_skypiax/skypiax.h
freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c (original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c Wed Feb 11 14:24:59 2009
@@ -2316,6 +2316,41 @@
return RESULT_SUCCESS;
}
+
+private_t *find_available_skypiax_interface(void) {
+ private_t *p;
+ int found = 0;
+
+ /* lock the interfaces' list */
+ LOKKA(&skypiax_iflock);
+ /* make a pointer to the first interface in the interfaces list */
+ p = skypiax_iflist;
+ /* Search for the requested interface and verify if is unowned */
+ while (p) {
+ if (!p->owner) {
+ DEBUGA_PBX("Interface is NOT OWNED by a channel\n", SKYPIAX_P_LOG);
+ found = 1;
+ /* we found the requested interface, bail out from the while loop */
+ break;
+ } else {
+ /* interface owned by a channel */
+ DEBUGA_PBX("Interface is OWNED by a channel\n", SKYPIAX_P_LOG);
+ }
+ /* not yet found, next please */
+ p = p->next;
+ }
+
+ /* lock the interfaces' list */
+ UNLOCKA(&skypiax_iflock);
+
+
+ if(found)
+ return p;
+ else
+ return NULL;
+}
+
+
/************************************************/
#ifdef ASTERISK_VERSION_1_4
#ifndef AST_MODULE
Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h (original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h Wed Feb 11 14:24:59 2009
@@ -415,6 +415,7 @@
int skypiax_pipe_write(int pipe, short *buf, int howmany);
#endif /* WIN32 */
int skypiax_close_socket(unsigned int fd);
+private_t *find_available_skypiax_interface(void);
#define SKYPIAX_STATE_DOWN AST_STATE_DOWN
#define SKYPIAX_STATE_RING AST_STATE_RING
#define SKYPIAX_STATE_DIALING AST_STATE_DIALING
Modified: freeswitch/branches/gmaruzz/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/mod_skypiax.c (original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/mod_skypiax.c Wed Feb 11 14:24:59 2009
@@ -1187,6 +1187,32 @@
return 0;
}
+private_t *find_available_skypiax_interface(void) {
+ private_t *tech_pvt;
+ int found = 0;
+ int i;
+
+ for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+ if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+ int skype_state = 0;
+
+ tech_pvt = &globals.SKYPIAX_INTERFACES[i];
+ skype_state = tech_pvt->interface_state;
+ NOTICA("skype interface: %d, name: %s, state: %d\n",
+ SKYPIAX_P_LOG,
+ i, globals.SKYPIAX_INTERFACES[i].name, skype_state);
+ if (SKYPIAX_STATE_DOWN == skype_state || 0 == skype_state) {
+ found=1;
+ break;
+ }
+ }
+ }
+
+ if(found)
+ return tech_pvt;
+ else
+ return NULL;
+}
/* For Emacs:
* Local Variables:
* mode:c
Modified: freeswitch/branches/gmaruzz/mod_skypiax/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/skypiax.h (original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/skypiax.h Wed Feb 11 14:24:59 2009
@@ -269,3 +269,4 @@
int skypiax_pipe_write(int pipe, short *buf, int howmany);
#endif /* WIN32 */
int skypiax_close_socket(unsigned int fd);
+private_t *find_available_skypiax_interface(void);
Modified: freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c Wed Feb 11 14:24:59 2009
@@ -56,7 +56,7 @@
("If I don't connect immediately, please give the Skype client authorization to be connected by Skypiax (and to not ask you again)\n",
SKYPIAX_P_LOG);
skypiax_sleep(1000000);
- skypiax_skype_write(tech_pvt, "PROTOCOL 6");
+ skypiax_skype_write(tech_pvt, "PROTOCOL 7");
skypiax_sleep(10000);
return 0;
}
@@ -224,17 +224,34 @@
skypiax_sleep(10000);
sprintf(msg_to_skype, "ALTER CALL %s ANSWER", id);
skypiax_skype_write(tech_pvt, msg_to_skype);
- DEBUGA_SKYPE("We answered a Skype RING on skype_call %s\n", SKYPIAX_P_LOG,
+ NOTICA("We answered a Skype RING on skype_call %s\n", SKYPIAX_P_LOG,
id);
strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
} else {
- /* we're owned, we're in a call, let's refuse */
+ /* we're owned, we're in a call, let's try to transfer */
+ /************************** TODO
+ Checking here if it is possible to transfer this call to Test2
+ -> GET CALL 288 CAN_TRANSFER Test2
+ <- CALL 288 CAN_TRANSFER test2 TRUE
+ **********************************/
+
+ private_t *available_skypiax_interface;
+
+ available_skypiax_interface = find_available_skypiax_interface();
+ if(available_skypiax_interface){
+ /* there is a skypiax interface idle, let's transfer the call to it */
+ NOTICA ("Let's transfer the skype_call %s to %s interface, because we are already in a skypiax call(%s)\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id, available_skypiax_interface->name, id);
+ sprintf(msg_to_skype, "ALTER CALL %s TRANSFER %s", id, available_skypiax_interface->name);
+ } else{
+ /* no skypiax interfaces idle, let's refuse the call */
+ NOTICA ("Let's refuse the skype_call %s, because we are already in a skypiax call(%s) and no other skypiax interfaces are available\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id);
+ }
skypiax_skype_write(tech_pvt, msg_to_skype);
skypiax_sleep(10000);
- DEBUGA_SKYPE
- ("We have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n",
- SKYPIAX_P_LOG, id);
+ NOTICA
+ ("We (%s) have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n",
+ SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
}
} else {
/* we are calling out */
@@ -251,16 +268,22 @@
SKYPIAX_P_LOG, id);
} else if (!strcasecmp(value, "MISSED")) {
DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id);
- } else if (!strcasecmp(value, "FINISHED")) {
- DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
- tech_pvt->skype_call_id[0] = '\0';
- if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
- //tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
- return CALLFLOW_INCOMING_HANGUP;
- } else {
- tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
- }
- } else if (!strcasecmp(value, "CANCELLED")) {
+ } else if (!strcasecmp(value, "FINISHED")) {
+ DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
+ if(!strcasecmp(tech_pvt->skype_call_id, id)){
+ NOTICA("skype_call %s is MY call, now I'm going DOWN\n", SKYPIAX_P_LOG, id);
+ tech_pvt->skype_call_id[0] = '\0';
+ if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+ //tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+ return CALLFLOW_INCOMING_HANGUP;
+ } else {
+ tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+ }
+ }else {
+ NOTICA("skype_call %s is NOT MY call, ignoring\n", SKYPIAX_P_LOG, id);
+ }
+
+ } else if (!strcasecmp(value, "CANCELLED")) {
tech_pvt->skype_callflow = CALLFLOW_STATUS_CANCELLED;
DEBUGA_SKYPE
("we tried to call Skype on skype_call %s and Skype has now CANCELLED\n",
@@ -306,28 +329,33 @@
tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
DEBUGA_SKYPE("skype_call: %s is now UNPLACED\n", SKYPIAX_P_LOG, id);
- } else if (!strcasecmp(value, "INPROGRESS")) {
- char msg_to_skype[1024];
- tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
- strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
- tech_pvt->interface_state = SKYPIAX_STATE_UP;
- DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id);
- sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id,
- tech_pvt->tcp_cli_port);
- skypiax_skype_write(tech_pvt, msg_to_skype);
- start_audio_threads(tech_pvt);
- sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id,
- tech_pvt->tcp_srv_port);
- skypiax_skype_write(tech_pvt, msg_to_skype);
- tech_pvt->skype_callflow = SKYPIAX_STATE_UP;
- if (!strlen(tech_pvt->session_uuid_str)) {
- DEBUGA_SKYPE("New Inbound Channel!\n", SKYPIAX_P_LOG);
- new_inbound_channel(tech_pvt);
- } else {
- DEBUGA_SKYPE("Outbound Channel Answered!\n", SKYPIAX_P_LOG);
- outbound_channel_answered(tech_pvt);
- }
- } else {
+ } else if (!strcasecmp(value, "INPROGRESS")) {
+ char msg_to_skype[1024];
+
+ if(!strlen(tech_pvt->session_uuid_str) || !strlen(tech_pvt->skype_call_id) || !strcasecmp(tech_pvt->skype_call_id, id)){
+ tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
+ strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+ tech_pvt->interface_state = SKYPIAX_STATE_UP;
+ DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id);
+ sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id,
+ tech_pvt->tcp_cli_port);
+ skypiax_skype_write(tech_pvt, msg_to_skype);
+ start_audio_threads(tech_pvt);
+ sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id,
+ tech_pvt->tcp_srv_port);
+ skypiax_skype_write(tech_pvt, msg_to_skype);
+ tech_pvt->skype_callflow = SKYPIAX_STATE_UP;
+ if (!strlen(tech_pvt->session_uuid_str)) {
+ DEBUGA_SKYPE("New Inbound Channel!\n", SKYPIAX_P_LOG);
+ new_inbound_channel(tech_pvt);
+ } else {
+ DEBUGA_SKYPE("Outbound Channel Answered!\n", SKYPIAX_P_LOG);
+ outbound_channel_answered(tech_pvt);
+ }
+ }else {
+ NOTICA("I'm on %s, skype_call %s is NOT MY call, ignoring\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
+ }
+ } else {
WARNINGA("skype_call: %s, STATUS: %s is not recognized\n", SKYPIAX_P_LOG, id,
value);
}
@@ -636,7 +664,7 @@
memset(cli_out, 0, sizeof(cli_out));
len = send(fd, (char *) cli_out, sizeof(cli_out), 0);
len = send(fd, (char *) cli_out, sizeof(cli_out)/2, 0);
- DEBUGA_SKYPE("sent %d of zeros to keep the Skype client socket busy\n", SKYPIAX_P_LOG, sizeof(cli_out) + sizeof(cli_out)/2);
+ //DEBUGA_SKYPE("sent %d of zeros to keep the Skype client socket busy\n", SKYPIAX_P_LOG, sizeof(cli_out) + sizeof(cli_out)/2);
}
}
@@ -1286,7 +1314,7 @@
return NULL;
}
- snprintf(buf, 512, "PROTOCOL 6");
+ snprintf(buf, 512, "PROTOCOL 7");
if (!skypiax_skype_send_message(SkypiaxHandles, buf)) {
ERRORA
("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
More information about the Freeswitch-branches
mailing list