Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/EionRobb/skype4pidgin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEion Robb <eion@robbmob.com>2007-11-20 22:12:37 +0300
committerEion Robb <eion@robbmob.com>2007-11-20 22:12:37 +0300
commit5c3a9bdff0e263c7b1974586d42355b4e01ac1b8 (patch)
tree526a7abb2a420a1bc2b3662d087b084e218c82cb /skype_messaging_carbon.c
parent7021a6dc7feb8d27199275f742aad115cd4c3bb8 (diff)
Better handling for messages sent when not connected
Diffstat (limited to 'skype_messaging_carbon.c')
-rw-r--r--skype_messaging_carbon.c353
1 files changed, 183 insertions, 170 deletions
diff --git a/skype_messaging_carbon.c b/skype_messaging_carbon.c
index 696b14b..a883a3f 100644
--- a/skype_messaging_carbon.c
+++ b/skype_messaging_carbon.c
@@ -1,170 +1,183 @@
-#include <Carbon/Carbon.h>
-//#include <Skype/Skype.h>
-#include <glib.h>
-#include <CoreFoundation/CoreFoundation.h>
-
-#include "AutoreleasePoolInit.h"
-
-//change this to 0 if using an old version of the Skype.framework
-#define SENDSKYPERETURNS 0
-
-#include "skype_messaging_carbon2.c"
-
-static gboolean connected_to_skype = FALSE;
-
-void
-SkypeNotificationReceived(CFStringRef input)
-{
- char *output = NULL;
- void *pool = initAutoreleasePool();
- int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8);
-
- printf("Message received");
- output = (char *)CFStringGetCStringPtr(input, kCFStringEncodingUTF8);
- if (!output)
- {
- output = NewPtr(strlen+1);
- CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
- }
- printf(" %s\n", output);
- g_thread_create((GThreadFunc)skype_message_received, (void *)output, FALSE, NULL);
-
- destroyAutoreleasePool(pool);
-}
-
-void
-SkypeAttachResponse(unsigned int aAttachResponseCode)
-{
- if (aAttachResponseCode)
- {
- printf("Skype attached successfully :)\n");
- connected_to_skype = TRUE;
- }
- else
- {
- printf("Skype couldn't connect :(\n");
- connected_to_skype = FALSE;
- }
-}
-
-void
-SkypeBecameAvailable(CFPropertyListRef aNotification)
-{
- printf("Skype became available\n");
- connected_to_skype = TRUE;
-}
-
-void
-SkypeBecameUnavailable(CFPropertyListRef aNotification)
-{
- printf("Skype became unavailable\n");
- connected_to_skype = FALSE;
-}
-
-static struct SkypeDelegate skypeDelegate = {
- CFSTR("Adium"), /* clientAppName */
- SkypeNotificationReceived,
- SkypeAttachResponse,
- SkypeBecameAvailable,
- SkypeBecameUnavailable
-};
-
-static gboolean
-skype_connect_thread(gpointer data)
-{
- void *pool = initAutoreleasePool();
-
- printf("Start inner event loop\n");
- RunApplicationEventLoop();
- printf("End of event loop\n");
-
- destroyAutoreleasePool(pool);
-
- //don't loop this thread
- return FALSE;
-}
-
-static gpointer static_pool;
-
-static gboolean
-skype_connect()
-{
- gboolean is_skype_running = FALSE;
-
- static_pool = initAutoreleasePool();
-
- is_skype_running = IsSkypeRunning();
-
- printf("Is Skype running? '%s'\n", (is_skype_running?"Yes":"No"));
- if (!is_skype_running)
- return FALSE;
-
- SetSkypeDelegate(&skypeDelegate);
- ConnectToSkype();
-
- g_thread_create((GThreadFunc)skype_connect_thread, NULL, FALSE, NULL);
- while(connected_to_skype == FALSE)
- {
- RunCurrentEventLoop(1);
- }
- printf("Connected to skype\n");
- return TRUE;
-}
-
-static void
-skype_disconnect()
-{
- connected_to_skype = FALSE;
- DisconnectFromSkype();
- RemoveSkypeDelegate();
- RunCurrentEventLoop(1);
-
- destroyAutoreleasePool(static_pool);
-}
-
-static void
-send_message(char* message)
-{
- gpointer pool = initAutoreleasePool();
- printf("Skype send message\n");
-#if SENDSKYPERETURNS
- CFStringRef returnString = NULL;
- returnString = SendSkypeCommand(CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8));
- if (returnString)
- SkypeNotificationReceived(returnString);
-#else
- SendSkypeCommand(CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8));
-#endif
- destroyAutoreleasePool(pool);
-}
-
-static void
-hide_skype()
-{
- OSStatus status = noErr;
- ProcessSerialNumber psn = {kNoProcess, kNoProcess};
- unsigned int procNameLength = 32;
- unsigned char procName[procNameLength];
- unsigned int i = 0;
- ProcessInfoRec info;
- info.processInfoLength = sizeof(ProcessInfoRec);
- info.processName = procName;
- info.processAppSpec = NULL;
-
- while(status == noErr)
- {
- for(i = 0; i < procNameLength; i++)
- procName[i] = '\0';
-
- status = GetNextProcess(&psn);
- if (status == noErr)
- if (GetProcessInformation(&psn, &info) == noErr)
- //for some reason first character is poisioned
- if (strcmp((char *)&procName[1], "Skype") == 0)
- {
- ShowHideProcess(&psn, FALSE);
- return;
- }
- }
-}
-
+#include <Carbon/Carbon.h>
+//#include <Skype/Skype.h>
+#include <glib.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+#include "AutoreleasePoolInit.h"
+
+//change this to 0 if using an old version of the Skype.framework
+#define SENDSKYPERETURNS 0
+
+#include "skype_messaging_carbon2.c"
+
+static gboolean connected_to_skype = FALSE;
+
+void
+SkypeNotificationReceived(CFStringRef input)
+{
+ char *output = NULL;
+ void *pool = initAutoreleasePool();
+ int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8);
+
+ printf("Message received");
+ output = (char *)CFStringGetCStringPtr(input, kCFStringEncodingUTF8);
+ if (!output)
+ {
+ output = NewPtr(strlen+1);
+ CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
+ }
+ printf(" %s\n", output);
+ g_thread_create((GThreadFunc)skype_message_received, (void *)output, FALSE, NULL);
+
+ destroyAutoreleasePool(pool);
+}
+
+void
+SkypeAttachResponse(unsigned int aAttachResponseCode)
+{
+ if (aAttachResponseCode)
+ {
+ printf("Skype attached successfully :)\n");
+ connected_to_skype = TRUE;
+ }
+ else
+ {
+ printf("Skype couldn't connect :(\n");
+ connected_to_skype = FALSE;
+ }
+}
+
+void
+SkypeBecameAvailable(CFPropertyListRef aNotification)
+{
+ printf("Skype became available\n");
+ connected_to_skype = TRUE;
+}
+
+void
+SkypeBecameUnavailable(CFPropertyListRef aNotification)
+{
+ printf("Skype became unavailable\n");
+ connected_to_skype = FALSE;
+ g_thread_create((GThreadFunc)skype_message_received, "CONNSTATUS LOGGEDOUT", FALSE, NULL);
+}
+
+static struct SkypeDelegate skypeDelegate = {
+ CFSTR("Adium"), /* clientAppName */
+ SkypeNotificationReceived,
+ SkypeAttachResponse,
+ SkypeBecameAvailable,
+ SkypeBecameUnavailable
+};
+
+static gboolean
+skype_connect_thread(gpointer data)
+{
+ void *pool = initAutoreleasePool();
+
+ printf("Start inner event loop\n");
+ RunApplicationEventLoop();
+ printf("End of event loop\n");
+
+ destroyAutoreleasePool(pool);
+
+ //don't loop this thread
+ return FALSE;
+}
+
+static gpointer static_pool;
+
+static gboolean
+skype_connect()
+{
+ gboolean is_skype_running = FALSE;
+
+ static_pool = initAutoreleasePool();
+
+ is_skype_running = IsSkypeRunning();
+
+ printf("Is Skype running? '%s'\n", (is_skype_running?"Yes":"No"));
+ if (!is_skype_running)
+ return FALSE;
+
+ SetSkypeDelegate(&skypeDelegate);
+ ConnectToSkype();
+
+ g_thread_create((GThreadFunc)skype_connect_thread, NULL, FALSE, NULL);
+ while(connected_to_skype == FALSE)
+ {
+ RunCurrentEventLoop(1);
+ }
+ printf("Connected to skype\n");
+ return TRUE;
+}
+
+static void
+skype_disconnect()
+{
+ connected_to_skype = FALSE;
+ DisconnectFromSkype();
+ RemoveSkypeDelegate();
+ RunCurrentEventLoop(1);
+
+ destroyAutoreleasePool(static_pool);
+}
+
+static void
+send_message(char* message)
+{
+ if (!connected_to_skype)
+ {
+ if (message[0] == '#')
+ {
+ //And we're expecting a response
+ sscanf(message, "#%d ", &message_num);
+ sprintf(error_return, "#%d ERROR", message_num);
+ g_thread_create((GThreadFunc)skype_message_received, (void *)g_strdup(error_return), FALSE, NULL);
+ }
+ return;
+ }
+
+ gpointer pool = initAutoreleasePool();
+ printf("Skype send message\n");
+#if SENDSKYPERETURNS
+ CFStringRef returnString = NULL;
+ returnString = SendSkypeCommand(CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8));
+ if (returnString)
+ SkypeNotificationReceived(returnString);
+#else
+ SendSkypeCommand(CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8));
+#endif
+ destroyAutoreleasePool(pool);
+}
+
+static void
+hide_skype()
+{
+ OSStatus status = noErr;
+ ProcessSerialNumber psn = {kNoProcess, kNoProcess};
+ unsigned int procNameLength = 32;
+ unsigned char procName[procNameLength];
+ unsigned int i = 0;
+ ProcessInfoRec info;
+ info.processInfoLength = sizeof(ProcessInfoRec);
+ info.processName = procName;
+ info.processAppSpec = NULL;
+
+ while(status == noErr)
+ {
+ for(i = 0; i < procNameLength; i++)
+ procName[i] = '\0';
+
+ status = GetNextProcess(&psn);
+ if (status == noErr)
+ if (GetProcessInformation(&psn, &info) == noErr)
+ //for some reason first character is poisioned
+ if (strcmp((char *)&procName[1], "Skype") == 0)
+ {
+ ShowHideProcess(&psn, FALSE);
+ return;
+ }
+ }
+}
+