<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14474] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14474">14474</a></dd>
<dt>Author</dt> <dd>seven</dd>
<dt>Date</dt> <dd>2009-08-09 19:36:22 -0500 (Sun, 09 Aug 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>initial skypiax support on mac, not working yet.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchbranchessevensrcmodendpointsmod_skypiaxMakefile">freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/Makefile</a></li>
<li><a href="#freeswitchbranchessevensrcmodendpointsmod_skypiaxmod_skypiaxc">freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c</a></li>
<li><a href="#freeswitchbranchessevensrcmodendpointsmod_skypiaxskypiaxh">freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h</a></li>
<li><a href="#freeswitchbranchessevensrcmodendpointsmod_skypiaxskypiax_protocolc">freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchbranchessevensrcmodendpointsmod_skypiaxMakefile"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/Makefile (14473 => 14474)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/Makefile        2009-08-09 21:04:36 UTC (rev 14473)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/Makefile        2009-08-10 00:36:22 UTC (rev 14474)
</span><span class="lines">@@ -1,6 +1,15 @@
</span><span class="cx"> MODNAME=mod_skypiax
</span><span class="cx"> SVNDEF := -D'SKYPIAX_SVN_VERSION="$(shell svnversion -n .)"'
</span><span class="cx"> LOCAL_CFLAGS += $(SVNDEF)
</span><del>-LOCAL_LDFLAGS=-lX11
-LOCAL_OBJS=skypiax_protocol.o
</del><ins>+# LOCAL_LDFLAGS=-lX11
+# LOCAL_LDFLAGS=-framework Skype -framework Cocoa -framework Foundation -framework CoreFoundation
+
+LOCAL_INSERT_LDFLAGS=\
+ if test $$osarch = "Darwin" ; then echo "-framework Carbon -framework Skype -framework Foundation" ; \
+ else echo "-lX11" ; \
+ fi;
+
+
+# LOCAL_LDFLAGS=-ObjC
+LOCAL_OBJS=AutoreleasePool.o skypiax_protocol.o
</ins><span class="cx"> include ../../../../build/modmake.rules
</span></span></pre></div>
<a id="freeswitchbranchessevensrcmodendpointsmod_skypiaxmod_skypiaxc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c (14473 => 14474)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -300,7 +300,8 @@
</span><span class="cx">                 if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {        // let's the skypiax_api_thread_func die
</span><span class="cx">                         DEBUGA_SKYPE("got FALSE here, thread probably was already dead. GetLastError returned: %d\n", SKYPIAX_P_LOG, GetLastError());
</span><span class="cx">                         globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
</span><del>-                }
</del><ins>+                }
+#elif MACOSX                
</ins><span class="cx"> #else
</span><span class="cx">                 XEvent e;
</span><span class="cx">                 Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
</span><span class="lines">@@ -1061,8 +1062,11 @@
</span><span class="cx">
</span><span class="cx">                         if (name) {
</span><span class="cx">                                 DEBUGA_SKYPE("name=%s\n", SKYPIAX_P_LOG, name);
</span><del>-                        }
-#ifndef WIN32
</del><ins>+                        }
+                        
+#ifdef WIN32
+#elif MACOSX
+#else
</ins><span class="cx">                         if (!XInitThreads()) {
</span><span class="cx">                                 ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
</span><span class="cx">                         } else {
</span><span class="lines">@@ -1166,9 +1170,13 @@
</span><span class="cx">                                                 ("Failed to connect to a SKYPE API for interface_id=%d, no SKYPE client running, please (re)start Skype client. Skypiax exiting\n",
</span><span class="cx">                                                  SKYPIAX_P_LOG, interface_id);
</span><span class="cx">                                         running = 0;
</span><ins>+                                        /* Seven added this here to load the module anyway, just for debugging purpose*/
+                                        running = 1;
+                                        /* end changed */
</ins><span class="cx">                                         switch_mutex_unlock(globals.mutex);
</span><span class="cx">                                         switch_xml_free(xml);
</span><del>-                                        return SWITCH_STATUS_FALSE;
</del><ins>+                                        return SWITCH_STATUS_SUCCESS;
+                                        // return SWITCH_STATUS_FALSE;
</ins><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 i = 0;
</span><span class="lines">@@ -1282,7 +1290,8 @@
</span><span class="cx">                                 if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {        // let's the skypiax_api_thread_func die
</span><span class="cx">                                         DEBUGA_SKYPE("got FALSE here, thread probably was already dead. GetLastError returned: %d\n", SKYPIAX_P_LOG, GetLastError());
</span><span class="cx">                                         globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
</span><del>-                                }
</del><ins>+                                }
+#elif MACOSX
</ins><span class="cx"> #else
</span><span class="cx">                                 XEvent e;
</span><span class="cx">                                 Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN",
</span></span></pre></div>
<a id="freeswitchbranchessevensrcmodendpointsmod_skypiaxskypiaxh"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h (14473 => 14474)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -39,9 +39,11 @@
</span><span class="cx">
</span><span class="cx"> #ifndef WIN32
</span><span class="cx"> #include <sys/time.h>
</span><ins>+#ifndef __APPLE__
</ins><span class="cx"> #include <X11/Xlib.h>
</span><span class="cx"> #include <X11/Xlibint.h>
</span><span class="cx"> #include <X11/Xatom.h>
</span><ins>+#endif //__APPLE__
</ins><span class="cx"> #endif //WIN32
</span><span class="cx">
</span><span class="cx"> #ifdef _MSC_VER
</span><span class="lines">@@ -80,6 +82,8 @@
</span><span class="cx"> #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__ );
</span><span class="cx"> #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__ );
</span><span class="cx">
</span><ins>+#define D7(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, __VA_ARGS__ );
+
</ins><span class="cx"> #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
</span><span class="cx">
</span><span class="cx"> /*********************************/
</span><span class="lines">@@ -133,18 +137,8 @@
</span><span class="cx">
</span><span class="cx"> #define SKYPIAX_MAX_INTERFACES 64
</span><span class="cx">
</span><del>-#ifndef WIN32
</del><ins>+#ifdef WIN32
</ins><span class="cx"> struct SkypiaxHandles {
</span><del>-        Window skype_win;
-        Display *disp;
-        Window win;
-        int currentuserhandle;
-        int api_connected;
-        int fdesc[2];
-};
-#else //WIN32
-
-struct SkypiaxHandles {
</del><span class="cx">         HWND win32_hInit_MainWindowHandle;
</span><span class="cx">         HWND win32_hGlobal_SkypeAPIWindowHandle;
</span><span class="cx">         HINSTANCE win32_hInit_ProcessHandle;
</span><span class="lines">@@ -155,7 +149,21 @@
</span><span class="cx">         int api_connected;
</span><span class="cx">         switch_file_t *fdesc[2];
</span><span class="cx"> };
</span><del>-
</del><ins>+#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];
+};
</ins><span class="cx"> #endif //WIN32
</span><span class="cx">
</span><span class="cx"> struct private_object {
</span></span></pre></div>
<a id="freeswitchbranchessevensrcmodendpointsmod_skypiaxskypiax_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (14473 => 14474)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -19,11 +19,24 @@
</span><span class="cx"> /*************************************/
</span><span class="cx"> /* suspicious globals FIXME */
</span><span class="cx"> #ifdef WIN32
</span><del>-DWORD win32_dwThreadId;
</del><ins>+DWORD win32_dwThreadId;
+#elif __APPLE__
+struct SkypiaxHandles *global_skypiax_handles;
</ins><span class="cx"> #else
</span><span class="cx"> XErrorHandler old_handler = 0;
</span><span class="cx"> int xerror = 0;
</span><del>-#endif /* WIN32 */
</del><ins>+#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
</ins><span class="cx"> /*************************************/
</span><span class="cx"> int skypiax_signaling_read(private_t * tech_pvt)
</span><span class="cx"> {
</span><span class="lines">@@ -78,7 +91,7 @@
</span><span class="cx">                         skypiax_strncpy(message_2, message, sizeof(message) - 1);
</span><span class="cx">                         buf = message;
</span><span class="cx">                         stringp = &buf;
</span><del>-                        where = strsep(stringp, " ");
</del><ins>+                        where = (char *)strsep(stringp, " ");
</ins><span class="cx">                         if (!where) {
</span><span class="cx">                                 WARNINGA("Skype MSG without spaces: %s\n", SKYPIAX_P_LOG, message);
</span><span class="cx">                         }
</span><span class="lines">@@ -101,7 +114,7 @@
</span><span class="cx">                         }
</span><span class="cx">                         if (!strcasecmp(message, "CURRENTUSERHANDLE")) {
</span><span class="cx">                                 skypiax_strncpy(obj, where, sizeof(obj) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(id, where, sizeof(id) - 1);
</span><span class="cx">                                 if (!strcasecmp(id, tech_pvt->skype_user)) {
</span><span class="cx">                                         tech_pvt->SkypiaxHandles.currentuserhandle = 1;
</span><span class="lines">@@ -112,9 +125,9 @@
</span><span class="cx">                         }
</span><span class="cx">                         if (!strcasecmp(message, "USER")) {
</span><span class="cx">                                 skypiax_strncpy(obj, where, sizeof(obj) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(id, where, sizeof(id) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(prop, where, sizeof(prop) - 1);
</span><span class="cx">                                 if (!strcasecmp(prop, "RECEIVEDAUTHREQUEST")) {
</span><span class="cx">                                         char msg_to_skype[256];
</span><span class="lines">@@ -126,12 +139,12 @@
</span><span class="cx">                         }
</span><span class="cx">                         if (!strcasecmp(message, "MESSAGE")) {
</span><span class="cx">                                 skypiax_strncpy(obj, where, sizeof(obj) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(id, where, sizeof(id) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(prop, where, sizeof(prop) - 1);
</span><span class="cx">                                 if (!strcasecmp(prop, "STATUS")) {
</span><del>-                                        where = strsep(stringp, " ");
</del><ins>+                                        where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                         skypiax_strncpy(value, where, sizeof(value) - 1);
</span><span class="cx">                                         if (!strcasecmp(value, "RECEIVED")) {
</span><span class="cx">                                                 char msg_to_skype[256];
</span><span class="lines">@@ -150,13 +163,13 @@
</span><span class="cx">                         }
</span><span class="cx">                         if (!strcasecmp(message, "CALL")) {
</span><span class="cx">                                 skypiax_strncpy(obj, where, sizeof(obj) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(id, where, sizeof(id) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(prop, where, sizeof(prop) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">                                 skypiax_strncpy(value, where, sizeof(value) - 1);
</span><del>-                                where = strsep(stringp, " ");
</del><ins>+                                where = (char *)strsep(stringp, " ");
</ins><span class="cx">
</span><span class="cx">                                 //DEBUGA_SKYPE
</span><span class="cx">                                 //("Skype MSG: message: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n",
</span><span class="lines">@@ -924,9 +937,9 @@
</span><span class="cx">         SKYPECONTROLAPI_ATTACH_API_AVAILABLE = 0x8001
</span><span class="cx"> };
</span><span class="cx">
</span><del>-/* Visual C do not have strsep? */
</del><ins>+/* Visual C do not have (char *)strsep? */
</ins><span class="cx"> char
</span><del>- *strsep(char **stringp, const char *delim)
</del><ins>+ *(char *)strsep(char **stringp, const char *delim)
</ins><span class="cx"> {
</span><span class="cx">         char *res;
</span><span class="cx">
</span><span class="lines">@@ -1174,8 +1187,181 @@
</span><span class="cx">
</span><span class="cx">         return NULL;
</span><span class="cx"> }
</span><ins>+#elif defined(__APPLE__)
+void SkypeAttachResponse(unsigned int aAttachResponseCode){
+        skype_attach_response = aAttachResponseCode;
+        D7("--------------Response %d--------\n", aAttachResponseCode);
+}
</ins><span class="cx">
</span><del>-#else /* NOT WIN32 */
</del><ins>+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*/
</ins><span class="cx"> int X11_errors_handler(Display * dpy, XErrorEvent * err)
</span><span class="cx"> {
</span><span class="cx">         (void) dpy;
</span><span class="lines">@@ -1464,5 +1650,5 @@
</span><span class="cx">         //running = 0;
</span><span class="cx">         return NULL;
</span><span class="cx">
</span><del>-}
</del><ins>+}
</ins><span class="cx"> #endif // WIN32
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>