Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c (14473 => 14474)
--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c 2009-08-09 21:04:36 UTC (rev 14473)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c 2009-08-10 00:36:22 UTC (rev 14474)
@@ -300,7 +300,8 @@
if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) { // let's the skypiax_api_thread_func die
DEBUGA_SKYPE("got FALSE here, thread probably was already dead. GetLastError returned: %d\n", SKYPIAX_P_LOG, GetLastError());
globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
- }
+ }
+#elif MACOSX
#else
XEvent e;
Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
@@ -1061,8 +1062,11 @@
if (name) {
DEBUGA_SKYPE("name=%s\n", SKYPIAX_P_LOG, name);
- }
-#ifndef WIN32
+ }
+
+#ifdef WIN32
+#elif MACOSX
+#else
if (!XInitThreads()) {
ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
} else {
@@ -1166,9 +1170,13 @@
("Failed to connect to a SKYPE API for interface_id=%d, no SKYPE client running, please (re)start Skype client. Skypiax exiting\n",
SKYPIAX_P_LOG, interface_id);
running = 0;
+ /* Seven added this here to load the module anyway, just for debugging purpose*/
+ running = 1;
+ /* end changed */
switch_mutex_unlock(globals.mutex);
switch_xml_free(xml);
- return SWITCH_STATUS_FALSE;
+ return SWITCH_STATUS_SUCCESS;
+ // return SWITCH_STATUS_FALSE;
}
i = 0;
@@ -1282,7 +1290,8 @@
if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) { // let's the skypiax_api_thread_func die
DEBUGA_SKYPE("got FALSE here, thread probably was already dead. GetLastError returned: %d\n", SKYPIAX_P_LOG, GetLastError());
globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
- }
+ }
+#elif MACOSX
#else
XEvent e;
Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN",
Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h (14473 => 14474)
--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h 2009-08-09 21:04:36 UTC (rev 14473)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h 2009-08-10 00:36:22 UTC (rev 14474)
@@ -39,9 +39,11 @@
#ifndef WIN32
#include <sys/time.h>
+#ifndef __APPLE__
#include <X11/Xlib.h>
#include <X11/Xlibint.h>
#include <X11/Xatom.h>
+#endif //__APPLE__
#endif //WIN32
#ifdef _MSC_VER
@@ -80,6 +82,8 @@
#define WARNINGA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][WARNINGA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
#define NOTICA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][NOTICA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
+#define D7(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, __VA_ARGS__ );
+
#define SKYPIAX_P_LOG NULL, (unsigned long)55, __LINE__, tech_pvt ? tech_pvt->name ? tech_pvt->name : "none" : "none", -1, tech_pvt ? tech_pvt->interface_state : -1, tech_pvt ? tech_pvt->skype_callflow : -1
/*********************************/
@@ -133,18 +137,8 @@
#define SKYPIAX_MAX_INTERFACES 64
-#ifndef WIN32
+#ifdef WIN32
struct SkypiaxHandles {
- Window skype_win;
- Display *disp;
- Window win;
- int currentuserhandle;
- int api_connected;
- int fdesc[2];
-};
-#else //WIN32
-
-struct SkypiaxHandles {
HWND win32_hInit_MainWindowHandle;
HWND win32_hGlobal_SkypeAPIWindowHandle;
HINSTANCE win32_hInit_ProcessHandle;
@@ -155,7 +149,21 @@
int api_connected;
switch_file_t *fdesc[2];
};
-
+#elif __APPLE__
+struct SkypiaxHandles {
+ int currentuserhandle;
+ int api_connected;
+ int fdesc[2];
+};
+#else
+struct SkypiaxHandles {
+ Window skype_win;
+ Display *disp;
+ Window win;
+ int currentuserhandle;
+ int api_connected;
+ int fdesc[2];
+};
#endif //WIN32
struct private_object {
Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (14473 => 14474)
--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c 2009-08-09 21:04:36 UTC (rev 14473)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c 2009-08-10 00:36:22 UTC (rev 14474)
@@ -19,11 +19,24 @@
/*************************************/
/* suspicious globals FIXME */
#ifdef WIN32
-DWORD win32_dwThreadId;
+DWORD win32_dwThreadId;
+#elif __APPLE__
+struct SkypiaxHandles *global_skypiax_handles;
#else
XErrorHandler old_handler = 0;
int xerror = 0;
-#endif /* WIN32 */
+#endif /* WIN32 */
+
+#ifdef __APPLE__
+// #import <Cocoa/Cocoa.h>
+#include <Skype/Skype.h>
+// #import <CoreFoundation/CoreFoundation.h>
+// #import <Foundation/NSAutoreleasePool.h>
+#include "AutoreleasePool.h"
+typedef struct SkypeDelegate SkypeDelegate;
+int skype_attach_response = 0;
+
+#endif
/*************************************/
int skypiax_signaling_read(private_t * tech_pvt)
{
@@ -78,7 +91,7 @@
skypiax_strncpy(message_2, message, sizeof(message) - 1);
buf = message;
stringp = &buf;
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
if (!where) {
WARNINGA("Skype MSG without spaces: %s\n", SKYPIAX_P_LOG, message);
}
@@ -101,7 +114,7 @@
}
if (!strcasecmp(message, "CURRENTUSERHANDLE")) {
skypiax_strncpy(obj, where, sizeof(obj) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(id, where, sizeof(id) - 1);
if (!strcasecmp(id, tech_pvt->skype_user)) {
tech_pvt->SkypiaxHandles.currentuserhandle = 1;
@@ -112,9 +125,9 @@
}
if (!strcasecmp(message, "USER")) {
skypiax_strncpy(obj, where, sizeof(obj) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(id, where, sizeof(id) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(prop, where, sizeof(prop) - 1);
if (!strcasecmp(prop, "RECEIVEDAUTHREQUEST")) {
char msg_to_skype[256];
@@ -126,12 +139,12 @@
}
if (!strcasecmp(message, "MESSAGE")) {
skypiax_strncpy(obj, where, sizeof(obj) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(id, where, sizeof(id) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(prop, where, sizeof(prop) - 1);
if (!strcasecmp(prop, "STATUS")) {
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(value, where, sizeof(value) - 1);
if (!strcasecmp(value, "RECEIVED")) {
char msg_to_skype[256];
@@ -150,13 +163,13 @@
}
if (!strcasecmp(message, "CALL")) {
skypiax_strncpy(obj, where, sizeof(obj) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(id, where, sizeof(id) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(prop, where, sizeof(prop) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
skypiax_strncpy(value, where, sizeof(value) - 1);
- where = strsep(stringp, " ");
+ where = (char *)strsep(stringp, " ");
//DEBUGA_SKYPE
//("Skype MSG: message: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n",
@@ -924,9 +937,9 @@
SKYPECONTROLAPI_ATTACH_API_AVAILABLE = 0x8001
};
-/* Visual C do not have strsep? */
+/* Visual C do not have (char *)strsep? */
char
- *strsep(char **stringp, const char *delim)
+ *(char *)strsep(char **stringp, const char *delim)
{
char *res;
@@ -1174,8 +1187,181 @@
return NULL;
}
+#elif defined(__APPLE__)
+void SkypeAttachResponse(unsigned int aAttachResponseCode){
+ skype_attach_response = aAttachResponseCode;
+ D7("--------------Response %d--------\n", aAttachResponseCode);
+}
-#else /* NOT WIN32 */
+void SkypeNotificationReceived(CFStringRef aNotificationString){
+ CFStringRef input = aNotificationString;
+ char *output = NULL;
+
+ struct SkypiaxHandles *SkypiaxHandles = global_skypiax_handles;
+
+ if (!SkypiaxHandles) {
+ D7("No skypiax handles!");
+ return;
+ }
+ int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8);
+
+ output = (char *)CFStringGetCStringPtr(input, kCFStringEncodingUTF8);
+ if (!output)
+ {
+ output = NewPtr(strlen+1);
+ CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
+ }
+ D7("Message received %s\n", output);
+ write(SkypiaxHandles->fdesc[1], output, strlen+1);
+
+}
+void SkypeBecameAvailable(CFPropertyListRef aNotification){
+ D7("---Skype Avalible\n");
+}
+void SkypeBecameUnavailable(CFPropertyListRef aNotification){
+ D7("---Skype Unavailable\n");
+}
+
+int skypiax_send_message(struct SkypiaxHandles *SkypiaxHandles, const char *message_P)
+{
+
+ CFStringRef messageString = CFStringCreateWithCString(NULL, message_P, kCFStringEncodingUTF8);
+#if SENDSKYPERETURNS
+ CFStringRef returnString = NULL;
+ returnString = SendSkypeCommand(messageString);
+ if (returnString)
+ SkypeNotificationReceived(returnString);
+#else
+ SendSkypeCommand(messageString);
+#endif
+ //printf("Skype send message %s\n", message);
+ CFRelease(messageString);
+
+ return 1;
+}
+
+int skypiax_signaling_write(private_t * tech_pvt, char *msg_to_skype)
+{
+ struct SkypiaxHandles *SkypiaxHandles;
+
+ DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype);
+
+ SkypiaxHandles = &tech_pvt->SkypiaxHandles;
+
+ if (!skypiax_send_message(SkypiaxHandles, msg_to_skype)) {
+ ERRORA
+ ("Sending message failed - probably Skype crashed.\n\nPlease shutdown Skypiax, then restart Skype, then launch Skypiax and try again.\n",
+ SKYPIAX_P_LOG);
+ return -1;
+ }
+
+ return 0;
+
+}
+
+void RunThread()
+{
+ RunApplicationEventLoop();
+}
+
+void *skypiax_do_skypeapi_thread_func(void *obj)
+{
+
+ private_t *tech_pvt = obj;
+ struct SkypiaxHandles *SkypiaxHandles;
+ char buf[512];
+ SkypeDelegate skype_delegate;
+ skype_delegate.clientApplicationName = CFSTR("skypiax");
+ skype_delegate.SkypeNotificationReceived = SkypeNotificationReceived;
+ skype_delegate.SkypeAttachResponse = SkypeAttachResponse;
+ skype_delegate.SkypeBecameAvailable = SkypeBecameAvailable;
+ skype_delegate.SkypeBecameUnavailable = SkypeBecameUnavailable;
+ int c = 0; //sleep
+ // pthread_t tid;
+ //
+ // pthread_create(&tid, NULL, (void *)RunThread, NULL);
+
+
+ // NSAutoreleasePool *pool = NewAutoreleasePool();
+ InitAutoreleasePool();
+ // NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ SetSkypeDelegate(&skype_delegate);
+
+ if (!IsSkypeRunning()) {
+ D7("-------skype not running?\n");
+ goto end;
+ }
+
+ RunCurrentEventLoop(1);
+ D7("------connecting-----------?\n");
+
+ ConnectToSkype();
+ D7("------connecting---2--------?\n");
+
+ while(skype_attach_response == 0 && c++ < 10) {
+ // sleep(1) ;
+ D7("--------------sleep---------\n")
+ RunCurrentEventLoop(0.5);
+ }
+
+ //let's assume it returned 1 for debug purpose
+ //skype_attach_response = 1;
+
+ if (!skype_attach_response) {
+ D7("------------No response-----------\n");
+ goto end;
+ }
+
+ if (!tech_pvt->tcp_srv_port)
+ tech_pvt->tcp_srv_port = 10160;
+
+ if (!tech_pvt->tcp_cli_port)
+ tech_pvt->tcp_cli_port = 10161;
+
+ if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
+ fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
+ fcntl(tech_pvt->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
+ }
+ SkypiaxHandles = &tech_pvt->SkypiaxHandles;
+ SkypiaxHandles->api_connected = skype_attach_response;
+ D7("--api_connected: %d\n", SkypiaxHandles->api_connected);
+
+ if (SkypiaxHandles->api_connected) {
+
+ snprintf(buf, 512, "NAME skypiax");
+
+ if (!skypiax_send_message(SkypiaxHandles, buf)) {
+ ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
+ running = 0;
+ return NULL;
+ }
+
+ snprintf(buf, 512, "PROTOCOL 7");
+ if (!skypiax_send_message(SkypiaxHandles, buf)) {
+ ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
+ running = 0;
+ return NULL;
+ }
+
+ }
+ running = 1;
+
+ while (running) {
+ RunCurrentEventLoop(0.1);
+ }
+
+end:
+ DisconnectFromSkype();
+ RemoveSkypeDelegate();
+ ReleaseAutoreleasePool();
+ //DestroyAutoreleasePool(pool);
+ //[pool release];
+ return NULL;
+
+}
+
+#else /* NOT WIN32 AND MAC*/
int X11_errors_handler(Display * dpy, XErrorEvent * err)
{
(void) dpy;
@@ -1464,5 +1650,5 @@
//running = 0;
return NULL;
-}
+}
#endif // WIN32