Revision
14730
Author
seven
Date
2009-09-02 08:22:44 -0500 (Wed, 02 Sep 2009)

Log Message

ugly MACOSX support

Modified Paths

Added Paths

Removed Paths

Diff

Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/Makefile (14729 => 14730)


--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/Makefile	2009-09-02 00:52:35 UTC (rev 14729)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/Makefile	2009-09-02 13:22:44 UTC (rev 14730)
@@ -5,11 +5,19 @@
 # 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" ; \
+    if test $$osarch = "Darwin" ; then echo "" ; \
     else echo "-lX11" ; \
     fi;
 
+LOCAL_OBJS=skypiax_protocol.o
+include ../../../../build/modmake.rules   
 
-# LOCAL_LDFLAGS=-ObjC
-LOCAL_OBJS=AutoreleasePool.o skypiax_protocol.o
-include ../../../../build/modmake.rules
+libs: AutoreleasePool.m
+	gcc -c -o AutoreleasePool.o AutoreleasePool.m
+	
+skypiax_proxy: libs skypiax_proxy.c
+	gcc -g -fPIC -Wall -o skypiax_proxy -ObjC -framework Skype skypiax_proxy.c  -framework Carbon -framework Foundation -lpthread AutoreleasePool.o
+
+mac_client: libs
+	gcc -g -fPIC -Wall -o mac_client -ObjC -framework Skype mac_client.c  -framework Carbon -framework Foundation -lpthread AutoreleasePool.o
+	

Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mac_client.c (14729 => 14730)


--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mac_client.c	2009-09-02 00:52:35 UTC (rev 14729)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mac_client.c	2009-09-02 13:22:44 UTC (rev 14730)
@@ -3,11 +3,9 @@
 #include <pthread.h>
 #import <Skype/Skype.h>                  
 // #import <CoreFoundation/CoreFoundation.h>
-// #import <Cocoa/Cocoa.h>  
-// #include <Foundation/NSAutoreleasePool.h>
+// #import <Foundation/NSAutoreleasePool.h>
 #include "AutoreleasePool.h"
 	
-// #include <glibc.h>
 typedef struct SkypeDelegate SkypeDelegate;
                                     
 int r = 0;
@@ -24,7 +22,7 @@
 		CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
 	}
 	printf("Message received  %s\n", output);
-	
+
 }
 void SkypeAttachResponse(unsigned int aAttachResponseCode){
 	r = aAttachResponseCode;
@@ -33,12 +31,12 @@
 void SkypeBecameAvailable(CFPropertyListRef aNotification){}
 void SkypeBecameUnavailable(CFPropertyListRef aNotification){}
 
-void
-RunThread()
+void RunThread()
 {
     RunApplicationEventLoop(); 
 }
-int main(int arcg, char **argv)
+
+void skype_thread()
 {
 	SkypeDelegate skype_delegate;
 	skype_delegate.clientApplicationName = CFSTR("skypiax");
@@ -46,17 +44,8 @@
    	skype_delegate.SkypeAttachResponse = SkypeAttachResponse;
 	skype_delegate.SkypeBecameAvailable = SkypeBecameAvailable;
 	skype_delegate.SkypeBecameUnavailable = SkypeBecameUnavailable; 
-	
-	pthread_t tid;
-    CFStringRef cmd, resp;
-    char c;    
-	char *tmp = (char *)malloc(sizeof(char) * 1024);
-
-
-    tmp[0] = '\0';
-    
-	                                
-	
+	    
+	OSStatus status;
 	// NSAutoreleasePool * pool = 
 	InitAutoreleasePool();
     
@@ -64,22 +53,55 @@
 
 	SetSkypeDelegate(&skype_delegate); 
 	
-	printf("is: %d\n", IsSkypeRunning());
-	RunCurrentEventLoop(1);
+	printf("IsSkypeRunning: %d\n", IsSkypeRunning());
+	// RunCurrentEventLoop(1);
 
 	ConnectToSkype();
 	
 	
-	
 	while(r == 0) {
 		printf("sleep 1\n");
-		RunCurrentEventLoop(1);
+		// status = RunCurrentEventLoop(1);
+		// printf("Event loop status: %d\n", (int)status);
+		sleep(1);
 	}       	
 	
-	// SendSkypeCommand(CFSTR("CALL echo123"));
+	// RunApplicationEventLoop();
+	                
+	while(r) {
+		status = RunCurrentEventLoop(1);
+		printf("Event loop status: %d\n", (int)status);
+		sleep(1);
+	}
 	
-	pthread_create(&tid, NULL, (void *) RunThread, NULL);
+	DisconnectFromSkype();     
+	RemoveSkypeDelegate();
+	
+	ReleaseAutoreleasePool();
+	// [pool release];
+	
+}
+int main(int arcg, char **argv)
+{
+	pthread_t tid;                               
+	// pthread_t tid2;
+    CFStringRef cmd, resp;
+    char c;    
+	char *tmp = (char *)malloc(sizeof(char) * 1024);
+
+
+    tmp[0] = '\0';
+    
+	                	
+	// pthread_create(&tid2, NULL, (void *) RunThread, NULL);
+	pthread_create(&tid, NULL, (void *) skype_thread, NULL);
+	
+	
+	RunApplicationEventLoop();
+	
     while(c != EOF) {
+		// RunCurrentEventLoop(1);
+	
         c = getchar();
         switch(c) {
             case '\n': /* parse and execute. */
@@ -87,7 +109,7 @@
                     //cmd = CFStringCreateWithCString(kCFAllocatorDefault, tmp, kCFStringEncodingMacRoman);
                     cmd = CFStringCreateWithCString(kCFAllocatorDefault, tmp, kCFStringEncodingASCII);
 					if (!strcmp("exit", tmp)) {
-						goto end;
+						exit(0);
 					}
                     fprintf(stdout, "=>%s\n", CFStringGetCStringPtr(cmd, 0));
                     resp = SendSkypeCommand(cmd);
@@ -102,15 +124,5 @@
                 break;
         }
     }
-                           
-	
-end:	                               
-	RunCurrentEventLoop(1);
-	DisconnectFromSkype();     
-	RemoveSkypeDelegate();
-	// release_pool();
-	
-	ReleaseAutoreleasePool();
-	// [pool release];
-	return 0;
+	return 0;                       	
 }
\ No newline at end of file

Deleted: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mac_client2.c

Deleted: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mfile

Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c (14729 => 14730)


--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2009-09-02 00:52:35 UTC (rev 14729)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2009-09-02 13:22:44 UTC (rev 14730)
@@ -1291,7 +1291,8 @@
 					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
+#elif __APPLE__
+				proxy_socket_disconnect();
 #else
 				XEvent e;
 				Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN",

Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h (14729 => 14730)


--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h	2009-09-02 00:52:35 UTC (rev 14729)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax.h	2009-09-02 13:22:44 UTC (rev 14730)
@@ -154,7 +154,9 @@
 	int currentuserhandle;
 	int api_connected;
 	int fdesc[2];
-};            
+};
+int proxy_socket;
+void proxy_socket_disconnect(void);           
 #else
 struct SkypiaxHandles {
 	Window skype_win;

Modified: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (14729 => 14730)


--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2009-09-02 00:52:35 UTC (rev 14729)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2009-09-02 13:22:44 UTC (rev 14730)
@@ -27,16 +27,6 @@
 int xerror = 0;
 #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)
 {
@@ -1188,179 +1178,9 @@
 	return NULL;
 }
 #elif defined(__APPLE__)
-void SkypeAttachResponse(unsigned int aAttachResponseCode){
-	skype_attach_response = aAttachResponseCode;
-	D7("--------------Response %d--------\n", aAttachResponseCode);
-}  
+     
+#include "skypiax_protocol_mac.c"
 
-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)
 {

Added: freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_proxy.c (0 => 14730)


--- freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_proxy.c	                        (rev 0)
+++ freeswitch/branches/seven/src/mod/endpoints/mod_skypiax/skypiax_proxy.c	2009-09-02 13:22:44 UTC (rev 14730)
@@ -0,0 +1,303 @@
+/* a mac proxy bridge FreeSWITCH to skype, must run before load mod_skypiax */
+
+#include <stdio.h>
+#include <stdlib.h>  
+#include <pthread.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <time.h>
+
+// You must have Skype.framework inplace like /Library/Frameworks/Skype.framework
+#import <Skype/Skype.h>
+
+// #import <CoreFoundation/CoreFoundation.h>
+// #import <Cocoa/Cocoa.h>  
+// #include <Foundation/NSAutoreleasePool.h>
+#include "AutoreleasePool.h"       
+#define INVALID_SOCKET -1
+#define MAX_MESSAGE_LEN 512
+
+
+
+typedef struct SkypeDelegate SkypeDelegate;
+
+int attached = 0;
+int client_socket = INVALID_SOCKET; 
+int server_socket = INVALID_SOCKET;
+
+char current_user_handle[MAX_MESSAGE_LEN];
+
+void close_socket(int *sock) {
+	if (*sock != INVALID_SOCKET) {
+		close(*sock);
+		*sock = INVALID_SOCKET;
+	}
+}                   
+
+void SkypeNotificationReceived(CFStringRef n_string){
+	char *c_string = NULL;
+
+	int length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(n_string), kCFStringEncodingUTF8);
+
+	c_string = (char *)CFStringGetCStringPtr(n_string, kCFStringEncodingUTF8);
+	if (!c_string)
+	{
+		c_string = NewPtr(length + 1);
+		CFStringGetCString(n_string, c_string, length + 1, kCFStringEncodingUTF8);
+	}
+	printf("Message received  %s\n", c_string);
+
+	if (!strncmp(c_string, "CURRENTUSERHANDLE", 17)) {
+		strncpy(current_user_handle, c_string, strlen(c_string));
+	}                                 
+
+	if (client_socket != INVALID_SOCKET) {
+		int len = 0; 
+		int sent = 0;
+		while(*(c_string + len)) len++;
+
+		len = len > MAX_MESSAGE_LEN ? MAX_MESSAGE_LEN : len;
+
+		sent = send(client_socket, c_string, strlen(c_string), 0);     
+		printf("Sent %d bytes to FreeSWITCH\n", sent);
+	}
+
+}       
+
+void SkypeAttachResponse(unsigned int aAttachResponseCode){
+	attached = aAttachResponseCode;
+	printf("Got %d, Skype instance Attached\n", attached);
+}                                          
+
+void SkypeBecameAvailable(CFPropertyListRef aNotification){}
+void SkypeBecameUnavailable(CFPropertyListRef aNotification){}
+
+#define SERVER_PORT 23456 // Waiting for FreeSWITCH to connect
+#define LENGTH_OF_LISTEN_QUEUE 10 //length of listen queue in server
+#define BUFFER_SIZE 255
+#define WELCOME_MESSAGE "SKYPIAX PROXY 0.1 "
+
+int server_port = 0;                   
+
+
+void send_skype_command(char *command) {
+	CFStringRef cmd, resp;  
+
+	InitAutoreleasePool();
+
+	cmd = CFStringCreateWithCString(kCFAllocatorDefault, command, kCFStringEncodingASCII);
+	printf("Send to skype: %s\n", CFStringGetCStringPtr(cmd, 0));
+	resp = SendSkypeCommand(cmd);
+	CFRelease(cmd);
+	if (resp != NULL) {
+		printf("Respond: %s\n", CFStringGetCStringPtr(resp, 0));
+	}                     
+
+	ReleaseAutoreleasePool();
+
+}
+
+void socket_thread() {
+
+	struct sockaddr_in server_addr,client_addr;
+
+	if ((server_socket = socket(AF_INET,SOCK_STREAM,0)) < 0)
+	{
+		printf("SOCKET error!\n");
+		exit(1);
+	}
+
+	bzero(&server_addr,sizeof(server_addr));
+	server_addr.sin_family = AF_INET;
+
+	if (server_port > 0) {
+		server_addr.sin_port = htons(server_port);
+	} else {
+		server_addr.sin_port = htons(SERVER_PORT);
+	}                                   
+
+	server_addr.sin_addr.s_addr = htons(INADDR_ANY);
+
+	if (bind(server_socket, (struct sockaddr*)&server_addr,sizeof(server_addr))<0)
+	{
+		printf("Bind port %d failure!\n",SERVER_PORT);
+		exit(1);
+	}
+
+	if (listen(server_socket, LENGTH_OF_LISTEN_QUEUE) < 0)
+	{
+		printf("Listen failure!\n");
+		exit(1);
+	}
+
+	printf("Socket server started. Socket %d waiting for connect\n", server_socket) ;
+
+	while (1)
+	{
+
+		char buf[BUFFER_SIZE];
+		long timestamp;
+		socklen_t length = sizeof(client_addr);
+
+		client_socket = accept(server_socket, (struct sockaddr*)&client_addr, &length);
+
+		if (client_socket < 0)
+		{
+			printf("ACCEPT error!\n");
+			break;
+		}
+
+		strcpy(buf,WELCOME_MESSAGE);
+
+		//inet_ntop(INET_ADDRSTRLEN,cliaddr.sin_addr,buf,BUFFER_SIZE);
+
+		printf("New connection from %s:%d\n", 
+			(char *)inet_ntoa(client_addr.sin_addr), (int)ntohs(client_addr.sin_port) );
+
+		timestamp = time(NULL);
+		strcat(buf,ctime(&timestamp));
+		send(client_socket, buf, BUFFER_SIZE, 0);      
+
+		fd_set sockset;
+		FD_ZERO(&sockset);
+		FD_SET(client_socket, &sockset);           
+
+		while(1) {
+
+			if (select(client_socket + 1, &sockset, &sockset, NULL, NULL) > 0) {
+				length = recv(client_socket, buf, BUFFER_SIZE, 0);          
+				
+				if (length <= 0 ) {
+					break;
+				}         
+				
+				length = length >= BUFFER_SIZE ? BUFFER_SIZE - 1 : length;
+				buf[length] = '\0';       
+				printf("Sending to skype: %s\n", buf);
+				send_skype_command(buf);
+
+				if (!strncmp(buf, "NAME skypiax", 5)) { 
+					printf("current_user_handle: %s\n", current_user_handle);
+					send(client_socket, current_user_handle, strlen(current_user_handle), 0);
+				}                           
+
+				if (!strncmp(buf, "/close", 6)) { 
+
+					close_socket(&client_socket);
+					printf("client disconnected\n");
+					break;
+				}    
+			}
+
+		}
+
+		send(client_socket, "ERR", 3, 0);
+		close_socket(&client_socket);  
+
+	}//exit
+
+	close_socket(&server_socket);
+	attached = 0;
+
+}
+
+void console_thread() {
+	char c = 'A';
+	char buffer[1024];                                 
+	char *tmp = buffer;
+
+	bzero(tmp, 1024);
+
+	InitAutoreleasePool();
+	printf("Console started:\n");
+	while(c != EOF) {       
+		c = getchar();
+		switch(c) {
+			case '\n': /* parse and execute. */
+			if (tmp[0] != '\0') {
+				if (!strcmp("exit", tmp)) {
+					close_socket(&client_socket);
+					close_socket(&server_socket);
+					goto end;
+				}
+
+				if (*tmp == '/') {
+					tmp++;                
+					send(client_socket, tmp, strlen(tmp), 0);
+					bzero(tmp, strlen(tmp));
+					continue;
+				}
+
+				send_skype_command(tmp);
+				bzero(tmp, sizeof(tmp));
+			} 
+			printf(">>> \n");      
+			break;
+			default: strncat(tmp, &c, 1);
+			break;
+		}
+	}
+	end:	                                                       
+	DisconnectFromSkype();     
+	RemoveSkypeDelegate();
+	ReleaseAutoreleasePool();
+	attached = 0;
+
+}                          
+
+int main(int argc, char **argv)
+{
+
+	SkypeDelegate skype_delegate;
+	skype_delegate.clientApplicationName = CFSTR("skypiax");
+	skype_delegate.SkypeNotificationReceived = SkypeNotificationReceived;
+	skype_delegate.SkypeAttachResponse = SkypeAttachResponse;
+	skype_delegate.SkypeBecameAvailable = SkypeBecameAvailable;
+	skype_delegate.SkypeBecameUnavailable = SkypeBecameUnavailable; 
+
+	pthread_t console_tid, socket_tid;
+
+	if (argc > 1 && atoi(argv[1]) > 1024) {
+		server_port = atoi(argv[1]);
+	}               
+
+	// InitAutoreleasePool();
+
+	NSAutoreleasePool* pool	= [[NSAutoreleasePool alloc] init];
+
+	SetSkypeDelegate(&skype_delegate); 
+
+	if (! IsSkypeRunning()) {
+		printf("Please start skype first\n");
+		exit(1);
+	};
+
+	ConnectToSkype();
+
+	while(!attached) {
+		printf("Waiting for skype response...");
+		RunCurrentEventLoop(1);
+
+	}       	
+
+	pthread_create(&console_tid, NULL, (void *) console_thread, NULL);
+	pthread_create(&socket_tid, NULL, (void *) socket_thread, NULL);
+
+	printf("Run application event loop\n");
+	while (attached) {
+		RunCurrentEventLoop(0.5);
+		// printf("sleep 0.5\n");
+	}
+
+	// DisconnectFromSkype();     
+	// RemoveSkypeDelegate();
+	// ReleaseAutoreleasePool();
+	[pool release]; 
+
+	close_socket(&server_socket);
+	// pthread_join(console_tid, NULL);
+	// pthread_join(socket_tid, NULL);     
+	return 0;
+}
\ No newline at end of file