diff options
-rw-r--r-- | debug.c | 11 | ||||
-rw-r--r-- | libskype.c | 48 | ||||
-rw-r--r-- | skype_events.c | 34 | ||||
-rw-r--r-- | skype_messaging.c | 4 | ||||
-rw-r--r-- | skype_messaging_carbon.c | 438 | ||||
-rw-r--r-- | skype_messaging_dbus.c | 52 | ||||
-rw-r--r-- | skype_messaging_win32.c | 26 | ||||
-rw-r--r-- | skype_messaging_x11.c | 172 |
8 files changed, 394 insertions, 391 deletions
@@ -6,10 +6,13 @@ typedef struct PurpleDebugLevel level;
char *category;
char *message;
-} SkypeDebugWrapper
+} SkypeDebugWrapper;
-void skype_debug(PurpleDebugLevel level, const char *category,
- const char *format, ...);
+void
+skype_debug_vargs(PurpleDebugLevel level, const char *category,
+ const char *format, va_list args);
+void skype_debug(PurpleDebugLevel level, const gchar *category,
+ const gchar *format, ...);
void skype_debug_info(const gchar *category, const gchar *format, ...);
void skype_debug_warning(const gchar *category, const gchar *format, ...);
@@ -78,4 +81,4 @@ skype_debug_cb(SkypeDebugWrapper *wrapper) if (wrapper != NULL)
purple_debug(wrapper->level, wrapper->category, wrapper->message);
return FALSE;
-}
\ No newline at end of file +}
@@ -27,7 +27,6 @@ #include <core.h>
#include <plugin.h>
#include <version.h>
-#include <debug.h> /* for purple_debug_info */
#include <accountopt.h>
#include <blist.h>
#include <request.h>
@@ -37,6 +36,7 @@ PurpleMedia *skype_media_initiate(PurpleConnection *gc, const char *who, PurpleMediaStreamType type);
#endif
+#include "debug.c"
#include "skype_messaging.c"
static void plugin_init(PurplePlugin *plugin);
@@ -402,7 +402,7 @@ skype_plugin_update_callback(PurpleUtilFetchUrlData *url_data, gpointer user_dat {
time_t mtime = ((struct stat *) user_data)->st_mtime;
time_t servertime = atoi(url_text);
- purple_debug_info("skype", "Server filemtime: %d, Local filemtime: %d\n", servertime, mtime);
+ skype_debug_info("skype", "Server filemtime: %d, Local filemtime: %d\n", servertime, mtime);
if (servertime > mtime)
{
purple_notify_info(this_plugin, _("Update available"), _("There is a newer version of the Skype plugin available for download."),
@@ -500,7 +500,7 @@ skype_status_types(PurpleAccount *acct) GList *types;
PurpleStatusType *status;
- purple_debug_info("skype", "returning status types\n");
+ skype_debug_info("skype", "returning status types\n");
types = NULL;
@@ -572,7 +572,7 @@ skype_set_buddies(PurpleAccount *acct) if (strlen(friends[i]) == 0)
continue;
//If already in list, dont recreate, reuse
- purple_debug_info("skype", "Searching for friend %s\n", friends[i]);
+ skype_debug_info("skype", "Searching for friend %s\n", friends[i]);
found_buddy = g_slist_find_custom(existing_friends,
friends[i],
skype_slist_friend_search);
@@ -580,9 +580,9 @@ skype_set_buddies(PurpleAccount *acct) {
//the buddy was already in the list
buddy = (PurpleBuddy *)found_buddy->data;
- purple_debug_info("skype","Buddy already in list: %s (%s)\n", buddy->name, friends[i]);
+ skype_debug_info("skype","Buddy already in list: %s (%s)\n", buddy->name, friends[i]);
} else {
- purple_debug_info("skype","Buddy not in list %s\n", friends[i]);
+ skype_debug_info("skype","Buddy not in list %s\n", friends[i]);
buddy = purple_buddy_new(acct, g_strdup(friends[i]), NULL);
if (friends[i][0] == '+')
purple_blist_add_buddy(buddy, NULL, skypeout_group, NULL);
@@ -606,7 +606,7 @@ skype_set_buddies(PurpleAccount *acct) skype_update_buddy_icon(buddy);
}
- purple_debug_info("skype", "Friends Count: %d\n", i);
+ skype_debug_info("skype", "Friends Count: %d\n", i);
g_strfreev(friends);
return FALSE;
@@ -632,7 +632,7 @@ skype_slist_friend_check(gpointer buddy_pointer, gpointer friends_pointer) if (strcmp(buddy->name, friends[i]) == 0)
return;
}
- purple_debug_info("skype", "removing buddy %d with name %s\n", buddy, buddy->name);
+ skype_debug_info("skype", "removing buddy %d with name %s\n", buddy, buddy->name);
purple_blist_remove_buddy(buddy);
}
@@ -674,7 +674,7 @@ skype_update_buddy_icon(PurpleBuddy *buddy) return;
}
- purple_debug_info("skype", "Updating buddy icon for %s\n", buddy->name);
+ skype_debug_info("skype", "Updating buddy icon for %s\n", buddy->name);
acct = purple_buddy_get_account(buddy);
fh = g_file_open_tmp("skypeXXXXXX", &filename, &error);
@@ -687,7 +687,7 @@ skype_update_buddy_icon(PurpleBuddy *buddy) ret = skype_send_message("GET USER %s AVATAR 1 %s", buddy->name, new_filename);
if (strlen(ret) == 0)
{
- purple_debug_warning("skype", "Error: Protocol doesn't suppot AVATAR\n");
+ skype_debug_warning("skype", "Error: Protocol doesn't suppot AVATAR\n");
api_supports_avatar = FALSE;
} else {
g_file_get_contents(new_filename, &image_data, &image_data_len, NULL);
@@ -696,7 +696,7 @@ skype_update_buddy_icon(PurpleBuddy *buddy) g_free(filename);
g_free(new_filename);
} else {
- purple_debug_warning("skype", "Error making temp file %s\n", error->message);
+ skype_debug_warning("skype", "Error making temp file %s\n", error->message);
g_error_free(error);
}
@@ -742,7 +742,7 @@ skype_update_buddy_status(PurpleBuddy *buddy) purple_prpl_got_user_status(acct, buddy->name, purple_primitive_get_id_from_type(primitive), NULL);
return FALSE;
}
- purple_debug_info("skype", "User %s status is %s\n", buddy->name, status);
+ skype_debug_info("skype", "User %s status is %s\n", buddy->name, status);
if (strcmp(status, "OFFLINE") == 0)
{
@@ -829,10 +829,10 @@ skype_login(PurpleAccount *acct) purple_connection_error(gc, g_strconcat("\n", _("Could not connect to Skype process\nSkype not running?"), NULL));
if (purple_account_get_bool(acct, "skype_autostart", TRUE))
{
- purple_debug_info("skype", "Should I start Skype?\n");
+ skype_debug_info("skype", "Should I start Skype?\n");
if (!is_skype_running())
{
- purple_debug_info("skype", "Yes, start Skype\n");
+ skype_debug_info("skype", "Yes, start Skype\n");
exec_skype();
}
}
@@ -895,7 +895,7 @@ skype_get_account_username(PurpleAccount *acct) if (acct && strcmp(acct->username, username) != 0)
{
- purple_debug_info("skype", "Setting username to %s\n", username);
+ skype_debug_info("skype", "Setting username to %s\n", username);
purple_account_set_username(acct, username);
}
return username;
@@ -927,7 +927,7 @@ skype_close(PurpleConnection *gc) {
GSList *buddies;
- purple_debug_info("skype", "logging out\n");
+ skype_debug_info("skype", "logging out\n");
if (gc && purple_account_get_bool(gc->account, "skype_sync", TRUE))
skype_send_message("SET USERSTATUS OFFLINE");
skype_send_message_nowait("SET SILENT_MODE OFF");
@@ -1008,7 +1008,7 @@ skype_get_info(PurpleConnection *gc, const gchar *username) _SKYPE_USER_INFO("ISBLOCKED", "Blocked");
//_SKYPE_USER_INFO("LASTONLINETIMESTAMP", "Last Online"); //timestamp
time = atoi(skype_get_user_info(username, "LASTONLINETIMESTAMP"));
- purple_debug_info("skype", "time: %d\n", time);
+ skype_debug_info("skype", "time: %d\n", time);
purple_notify_user_info_add_pair(user_info, _("Last Online"),
timestamp_to_datetime((time_t) time));
// g_strdup(purple_date_format_long(localtime((time_t *)(void *)&time))));
@@ -1039,7 +1039,7 @@ skype_get_user_info(const gchar *username, const gchar *property) return outstr;
return_str = g_strdup(&outstr[7+strlen(username)+strlen(property)]);
g_free(outstr);
- /* purple_debug_info("skype", "User %s's %s is %s", username, property, return_str); */
+ /* skype_debug_info("skype", "User %s's %s is %s", username, property, return_str); */
if (return_str == NULL)
return NULL;
return return_str;
@@ -1256,8 +1256,8 @@ skype_initiate_chat(PurpleBlistNode *node, gpointer data) //conv = purple_conversation_new(PURPLE_CONV_TYPE_CHAT, buddy->account, buddy->name);
conv = serv_got_joined_chat(purple_account_get_connection(purple_buddy_get_account(buddy)), chat_number, chat_id);
skype_send_message_nowait("ALTER CHAT %s ADDMEMBERS %s", chat_id, buddy->name);
- purple_debug_info("skype", "Conv Hash Table: %d\n", conv->data);
- purple_debug_info("skype", "chat_id: %s\n", chat_id);
+ skype_debug_info("skype", "Conv Hash Table: %d\n", conv->data);
+ skype_debug_info("skype", "chat_id: %s\n", chat_id);
purple_conversation_set_data(conv, "chat_id", g_strdup(chat_id));
purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv),
skype_get_account_username(buddy->account), NULL, PURPLE_CBFLAGS_NONE, FALSE);
@@ -1301,9 +1301,9 @@ skype_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessage stripped = purple_markup_strip_html(message);
conv = purple_find_chat(gc, id);
- purple_debug_info("skype", "chat_send; conv: %d, conv->data: %d, id: %d\n", conv, conv->data, id);
+ skype_debug_info("skype", "chat_send; conv: %d, conv->data: %d, id: %d\n", conv, conv->data, id);
chat_id = (gchar *)g_hash_table_lookup(conv->data, "chat_id");
- purple_debug_info("skype", "chat_id: %s\n", chat_id);
+ skype_debug_info("skype", "chat_id: %s\n", chat_id);
skype_send_message_nowait("CHATMESSAGE %s %s", chat_id, stripped);
@@ -1512,7 +1512,7 @@ skype_display_skype_credit(PurplePluginAction *action) temp = g_strdup_printf("%s %.2f", currency, balance);
- purple_debug_info("skype", "Balance: '%s'\n", temp);
+ skype_debug_info("skype", "Balance: '%s'\n", temp);
purple_notify_info(this_plugin, _("Skype Balance"), _("Your current Skype credit balance is:"), temp);
g_free(temp);
g_free(currency);
@@ -1560,7 +1560,7 @@ skype_media_initiate(PurpleConnection *gc, const char *who, PurpleMediaStreamTyp //FarsightSession *fs = farsight_session_factory_make("rtp");
//if (!fs) {
- // purple_debug_error("jabber", "Farsight's rtp plugin not installed");
+ // skype_debug_error("jabber", "Farsight's rtp plugin not installed");
// return NULL;
//}
//FarsightStream *audio_stream = farsight_session_create_stream(fs, FARSIGHT_MEDIA_TYPE_AUDIO, FARSIGHT_STREAM_DIRECTION_BOTH);
diff --git a/skype_events.c b/skype_events.c index b312619..96d3fe0 100644 --- a/skype_events.c +++ b/skype_events.c @@ -95,11 +95,11 @@ skype_handle_received_message(char *message) {
if (strcmp(string_parts[3], "3") == 0)
{
- purple_debug_info("skype", "Buddy %s just got added\n", string_parts[1]);
+ skype_debug_info("skype", "Buddy %s just got added\n", string_parts[1]);
//buddy just got added.. handle it
if (purple_find_buddy(this_account, string_parts[1]) == NULL)
{
- purple_debug_info("skype", "Buddy not in list\n");
+ skype_debug_info("skype", "Buddy not in list\n");
buddy = purple_buddy_new(this_account, g_strdup(string_parts[1]), NULL);
if (string_parts[1][0] == '+')
purple_blist_add_buddy(buddy, NULL, purple_group_new("SkypeOut"), NULL);
@@ -117,7 +117,7 @@ skype_handle_received_message(char *message) temp = skype_get_user_info(string_parts[1], "ISAUTHORIZED");
if (strcmp(temp, "TRUE") != 0)
{
- purple_debug_info("skype", "User %s requested authorisation\n", string_parts[1]);
+ skype_debug_info("skype", "User %s requested authorisation\n", string_parts[1]);
purple_account_request_authorization(this_account, string_parts[1], NULL, skype_get_user_info(string_parts[1], "FULLNAME"),
string_parts[3], (purple_find_buddy(this_account, string_parts[1]) != NULL),
skype_auth_allow, skype_auth_deny, (gpointer)g_strdup(string_parts[1]));
@@ -156,7 +156,7 @@ skype_handle_received_message(char *message) temp = skype_send_message("GET CHATMESSAGE %s CHATNAME", msg_num);
chatname = g_strdup(&temp[18+strlen(msg_num)]);
g_free(temp);
- //purple_debug_info("skype", "Chatname: '%s'\n", chatname);
+ //skype_debug_info("skype", "Chatname: '%s'\n", chatname);
chatusers = g_strsplit_set(chatname, "/;", 3);
if (strcmp(&chatusers[0][1], my_username) == 0)
sender = &chatusers[1][1];
@@ -169,7 +169,7 @@ skype_handle_received_message(char *message) }
}/* else if (strcmp(type, "AUTHREQUEST") == 0 && strcmp(sender, my_username) != 0)
{
- purple_debug_info("User %s requested alternate authorisation\n", sender);
+ skype_debug_info("User %s requested alternate authorisation\n", sender);
purple_account_request_authorization(this_account, sender, NULL, skype_get_user_info(sender, "FULLNAME"),
body, (purple_find_buddy(this_account, sender) != NULL),
skype_auth_allow, skype_auth_deny, (gpointer)g_strdup(sender));
@@ -186,7 +186,7 @@ skype_handle_received_message(char *message) }
} else if (strcmp(command, "CHATMESSAGE") == 0)
{
- if ((strcmp(string_parts[3], "RECEIVED") == 0) || + if ((strcmp(string_parts[3], "RECEIVED") == 0) ||
(strcmp(string_parts[3], "SENT") == 0))
{
msg_num = string_parts[1];
@@ -238,7 +238,7 @@ skype_handle_received_message(char *message) body = g_strdup(&temp[12+strlen(chatname)]);
g_free(temp);
purple_conv_chat_set_topic(PURPLE_CONV_CHAT(conv), this_account->username, body);
- purple_debug_info("skype", "set topic to: %s\n", body);
+ skype_debug_info("skype", "set topic to: %s\n", body);
}
purple_conversation_set_data(conv, "chat_id", chatname);
//g_hash_table_insert(conv->data, "chat_id", chatname);
@@ -258,7 +258,7 @@ skype_handle_received_message(char *message) temp = skype_send_message("GET CHATMESSAGE %s BODY", msg_num);
body = g_strdup(&temp[18+strlen(msg_num)]);
g_free(temp);
- purple_debug_info("skype", "Topic changed: %s\n", body);
+ skype_debug_info("skype", "Topic changed: %s\n", body);
purple_conv_chat_set_topic(PURPLE_CONV_CHAT(conv), NULL, body);
temp = skype_send_message("GET CHATMESSAGE %s FROM_HANDLE", msg_num);
sender = g_strdup(&temp[25+strlen(msg_num)]);
@@ -270,7 +270,7 @@ skype_handle_received_message(char *message) temp = skype_send_message("GET CHATMESSAGE %s BODY", msg_num);
body = g_strdup(&temp[18+strlen(msg_num)]);
g_free(temp);
- //purple_debug_info("skype", "Message received: %s\n", body);
+ //skype_debug_info("skype", "Message received: %s\n", body);
temp = skype_send_message("GET CHATMESSAGE %s FROM_HANDLE", msg_num);
sender = g_strdup(&temp[25+strlen(msg_num)]);
g_free(temp);
@@ -281,13 +281,13 @@ skype_handle_received_message(char *message) /* Escape the body to HTML */
body_html = skype_strdup_withhtml(body);
g_free(body);
- if (conv && conv->type == PURPLE_CONV_TYPE_CHAT) - { + if (conv && conv->type == PURPLE_CONV_TYPE_CHAT)
+ {
if (strcmp(string_parts[3], "RECEIVED") == 0)
- serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), sender, PURPLE_MESSAGE_RECV, body_html, mtime); - else + serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), sender, PURPLE_MESSAGE_RECV, body_html, mtime);
+ else
serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), sender, PURPLE_MESSAGE_SEND, body_html, mtime);
- } + }
else
{
if (strcmp(sender, my_username) == 0)
@@ -311,7 +311,7 @@ skype_handle_received_message(char *message) temp = skype_send_message("GET CHATMESSAGE %s USERS", msg_num);
body = g_strdup(&temp[19+strlen(msg_num)]);
g_free(temp);
- purple_debug_info("skype", "Friends added: %s\n", body);
+ skype_debug_info("skype", "Friends added: %s\n", body);
chatusers = g_strsplit(body, " ", 0);
for (i=0; chatusers[i]; i++)
purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv), chatusers[i], NULL, PURPLE_CBFLAGS_NONE, FALSE);
@@ -322,7 +322,7 @@ skype_handle_received_message(char *message) temp = skype_send_message("GET CHATMESSAGE %s USERS", msg_num);
body = g_strdup(&temp[19+strlen(msg_num)]);
g_free(temp);
- purple_debug_info("skype", "Friends left: %s\n", body);
+ skype_debug_info("skype", "Friends left: %s\n", body);
temp = skype_send_message("GET CHATMESSAGE %s LEAVEREASON", msg_num);
purple_conv_chat_remove_user(PURPLE_CONV_CHAT(conv), body, g_strdup(&temp[25+strlen(msg_num)]));
}
@@ -350,7 +350,7 @@ skype_handle_received_message(char *message) purple_xfer_set_init_fnc(transfer, skype_accept_transfer);
purple_xfer_set_request_denied_fnc(transfer, skype_decline_transfer);
temp = skype_send_message("GET FILETRANSFER %s FILENAME", string_parts[1]);
- purple_debug_info("skype", "Filename: '%s'\n", &temp[23+strlen(string_parts[1])]);
+ skype_debug_info("skype", "Filename: '%s'\n", &temp[23+strlen(string_parts[1])]);
purple_xfer_set_filename(transfer, g_strdup(&temp[23+strlen(string_parts[1])]));
g_free(temp);
temp = skype_send_message("GET FILETRANSFER %s FILEPATH", string_parts[1]);
diff --git a/skype_messaging.c b/skype_messaging.c index bd51f10..f449f5a 100644 --- a/skype_messaging.c +++ b/skype_messaging.c @@ -67,7 +67,7 @@ skype_message_received(char *orig_message) message = g_strdup(orig_message);
- purple_debug_info("skype", "Received: %s\n", message);
+ skype_debug_info("skype", "Received: %s\n", message);
if(message[0] == '#')
{
@@ -96,7 +96,7 @@ skype_send_message_nowait(char *message_format, ...) message = g_strdup_vprintf(message_format, args);
va_end(args);
- purple_debug_info("skype", "Sending: '%s'\n", message);
+ skype_debug_info("skype", "Sending: '%s'\n", message);
g_thread_create((GThreadFunc)send_message, message, FALSE, NULL);
}
diff --git a/skype_messaging_carbon.c b/skype_messaging_carbon.c index b88c26f..0d16bea 100644 --- a/skype_messaging_carbon.c +++ b/skype_messaging_carbon.c @@ -1,219 +1,219 @@ -#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; - GError *error = 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, &error); - skype_message_received(output); - if (error) - { - printf("Could not create new thread!!! %s\n", error->message); - g_error_free(error); - } - - 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) -{ - static gboolean started = FALSE; - if (started) - return FALSE; - started = TRUE; - - void *pool = initAutoreleasePool(); - - printf("Start inner event loop\n"); - while(true) - { - //RunApplicationEventLoop(); - RunCurrentEventLoop(1); - } - printf("End of event loop\n"); - started = FALSE; - - destroyAutoreleasePool(pool); - - //don't loop this thread - return FALSE; -}*/ - -static gpointer static_pool; - -static gboolean -skype_connect() -{ - gboolean is_skype_running = FALSE; - - if (!static_pool) - static_pool = initAutoreleasePool(); - - is_skype_running = IsSkypeRunning(); - - printf("Is Skype running? '%s'\n", (is_skype_running?"Yes":"No")); - if (!is_skype_running) - return FALSE; - - if (connected_to_skype) - skype_disconnect(); - - 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); -} - -static void -send_message(char* message) -{ - CFStringRef messageString = CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8); - if (!connected_to_skype) - { - if (message[0] == '#') - { - int message_num; - char error_return[40]; - //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); - } - CFRelease(messageString); - return; - } - - gpointer pool = initAutoreleasePool(); - printf("Skype send message "); -#if SENDSKYPERETURNS - CFStringRef returnString = NULL; - returnString = SendSkypeCommand(messageString); - if (returnString) - SkypeNotificationReceived(returnString); -#else - SendSkypeCommand(messageString); -#endif - destroyAutoreleasePool(pool); - printf("%s\n", message); - CFRelease(messageString); -} - -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; - } - } -} - -static gboolean -exec_skype() -{ - return g_spawn_command_line_async("/Applications/Skype.app/Contents/MacOS/Skype", NULL); -} - -static gboolean -is_skype_running() -{ - return IsSkypeRunning(); -} +#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;
+ GError *error = 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, &error);
+ skype_message_received(output);
+ if (error)
+ {
+ printf("Could not create new thread!!! %s\n", error->message);
+ g_error_free(error);
+ }
+
+ 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)
+{
+ static gboolean started = FALSE;
+ if (started)
+ return FALSE;
+ started = TRUE;
+
+ void *pool = initAutoreleasePool();
+
+ printf("Start inner event loop\n");
+ while(true)
+ {
+ //RunApplicationEventLoop();
+ RunCurrentEventLoop(1);
+ }
+ printf("End of event loop\n");
+ started = FALSE;
+
+ destroyAutoreleasePool(pool);
+
+ //don't loop this thread
+ return FALSE;
+}*/
+
+static gpointer static_pool;
+
+static gboolean
+skype_connect()
+{
+ gboolean is_skype_running = FALSE;
+
+ if (!static_pool)
+ static_pool = initAutoreleasePool();
+
+ is_skype_running = IsSkypeRunning();
+
+ printf("Is Skype running? '%s'\n", (is_skype_running?"Yes":"No"));
+ if (!is_skype_running)
+ return FALSE;
+
+ if (connected_to_skype)
+ skype_disconnect();
+
+ 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);
+}
+
+static void
+send_message(char* message)
+{
+ CFStringRef messageString = CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8);
+ if (!connected_to_skype)
+ {
+ if (message[0] == '#')
+ {
+ int message_num;
+ char error_return[40];
+ //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);
+ }
+ CFRelease(messageString);
+ return;
+ }
+
+ gpointer pool = initAutoreleasePool();
+ printf("Skype send message ");
+#if SENDSKYPERETURNS
+ CFStringRef returnString = NULL;
+ returnString = SendSkypeCommand(messageString);
+ if (returnString)
+ SkypeNotificationReceived(returnString);
+#else
+ SendSkypeCommand(messageString);
+#endif
+ destroyAutoreleasePool(pool);
+ printf("%s\n", message);
+ CFRelease(messageString);
+}
+
+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;
+ }
+ }
+}
+
+static gboolean
+exec_skype()
+{
+ return g_spawn_command_line_async("/Applications/Skype.app/Contents/MacOS/Skype", NULL);
+}
+
+static gboolean
+is_skype_running()
+{
+ return IsSkypeRunning();
+}
diff --git a/skype_messaging_dbus.c b/skype_messaging_dbus.c index 8bbf151..92e1788 100644 --- a/skype_messaging_dbus.c +++ b/skype_messaging_dbus.c @@ -8,20 +8,20 @@ static DBusGConnection *connection = NULL; static DBusGProxy *proxy = NULL;
static DBusGProxy *proxy_receive = NULL;
-static void +static void
notify_handler(DBusGProxy *object, const char *message, gpointer user_data)
{
- purple_debug_info("skype_dbus", "notify_handler called: %s\n", message);
+ skype_debug_info("skype_dbus", "notify_handler called: %s\n", message);
}
-static gboolean +static gboolean
skype_connect()
{
GError *error = NULL;
connection = dbus_g_bus_get (SKYPE_DBUS_BUS, &error);
if (connection == NULL && error != NULL)
{
- purple_debug_info("skype_dbus", "Error: %s\n", error->message);
+ skype_debug_info("skype_dbus", "Error: %s\n", error->message);
g_error_free(error);
return FALSE;
}
@@ -34,50 +34,50 @@ skype_connect() "com.Skype.API",
"/com/Skype/Client",
"com.Skype.API");
- +
dbus_g_proxy_add_signal(proxy_receive, "Notify", G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(proxy_receive, "Notify", G_CALLBACK(notify_handler), NULL, NULL);
return TRUE;
}
-static void +static void
skype_disconnect()
-{ +{
/*if (connection != NULL)
- g_free(connection); + g_free(connection);
if (proxy != NULL)
- g_free(proxy); - if (proxy_receive != NULL) + g_free(proxy);
+ if (proxy_receive != NULL)
g_free(proxy_receive);*/
}
-static void +static void
send_message(char* message)
{
GError *error = NULL;
- gchar *str = NULL; - int message_num; - gchar error_return[30]; - - purple_debug_info("skype_dbus", "con %d, proxy %d, rec %d\n", connection, proxy, proxy_receive);
+ gchar *str = NULL;
+ int message_num;
+ gchar error_return[30];
+
+ skype_debug_info("skype_dbus", "con %d, proxy %d, rec %d\n", connection, proxy, proxy_receive);
if (!dbus_g_proxy_call (proxy, "Invoke", &error, G_TYPE_STRING, message, G_TYPE_INVALID,
G_TYPE_STRING, &str, G_TYPE_INVALID))
{
- if (error && error->message) + if (error && error->message)
{
- purple_debug_info("skype_dbus", "Error: %s\n", error->message); - if (message[0] == '#') - { + skype_debug_info("skype_dbus", "Error: %s\n", error->message);
+ if (message[0] == '#')
+ {
//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); - } - } - else - purple_debug_info("skype_dbus", "no response\n");
- } + g_thread_create((GThreadFunc)skype_message_received, (void *)g_strdup(error_return), FALSE, NULL);
+ }
+ }
+ else
+ skype_debug_info("skype_dbus", "no response\n");
+ }
if (str != NULL)
g_thread_create((GThreadFunc)skype_message_received, (void *)str, FALSE, NULL);
}
diff --git a/skype_messaging_win32.c b/skype_messaging_win32.c index 0e44031..790d1ec 100644 --- a/skype_messaging_win32.c +++ b/skype_messaging_win32.c @@ -28,8 +28,8 @@ skype_connect() if (!hInit_ProcessHandle)
hInit_ProcessHandle = (HINSTANCE)OpenProcess( PROCESS_DUP_HANDLE, FALSE, GetCurrentProcessId());
- purple_debug_info("skype_win32", "ProcessId %d\n", GetCurrentProcessId());
- purple_debug_info("skype_win32", "hInit_ProcessHandle %d\n", hInit_ProcessHandle);
+ skype_debug_info("skype_win32", "ProcessId %d\n", GetCurrentProcessId());
+ skype_debug_info("skype_win32", "hInit_ProcessHandle %d\n", hInit_ProcessHandle);
g_thread_create((GThreadFunc)win32_message_loop, NULL, FALSE, NULL);
while(hInit_MainWindowHandle == NULL)
@@ -37,10 +37,10 @@ skype_connect() Sleep(10);
}
- purple_debug_info("skype_win32", "hInit_MainWindowHandle %d\n", hInit_MainWindowHandle);
- purple_debug_info("skype_win32", "Sending broadcast message\n");
+ skype_debug_info("skype_win32", "hInit_MainWindowHandle %d\n", hInit_MainWindowHandle);
+ skype_debug_info("skype_win32", "Sending broadcast message\n");
SendMessageTimeout( HWND_BROADCAST, uiGlobal_MsgID_SkypeControlAPIDiscover, (WPARAM)hInit_MainWindowHandle, 0, SMTO_NORMAL, 1000, sendMessageResult);
- purple_debug_info("skype_win32", "Broadcast message sent\n");
+ skype_debug_info("skype_win32", "Broadcast message sent\n");
while(hGlobal_SkypeAPIWindowHandle == NULL && i < 100)
{
@@ -88,7 +88,7 @@ win32_message_loop(void) TranslateMessage(&msg);
DispatchMessage(&msg);
}
- purple_debug_info("skype_win32", "Finished message loop\n");
+ skype_debug_info("skype_win32", "Finished message loop\n");
DestroyWindow(hInit_MainWindowHandle);
hInit_MainWindowHandle = NULL;
message_loop_started = FALSE;
@@ -145,17 +145,17 @@ Skype_WindowProc(HWND hWindow, UINT uiMessage, WPARAM uiParam, LPARAM ulParam) return 1;
} else if (uiMessage == uiGlobal_MsgID_SkypeControlAPIAttach) {
hGlobal_SkypeAPIWindowHandle = (HWND)uiParam;
- purple_debug_info("skype_win32", "Attached process %d %d\n", uiParam, ulParam);
+ skype_debug_info("skype_win32", "Attached process %d %d\n", uiParam, ulParam);
if (ulParam == 0)
- purple_debug_info("skype_win32", "Attach success\n");
+ skype_debug_info("skype_win32", "Attach success\n");
else if (ulParam == 1)
- purple_debug_info("skype_win32", "Pending auth\n");
+ skype_debug_info("skype_win32", "Pending auth\n");
else if (ulParam == 2)
- purple_debug_info("skype_win32", "Refused\n");
+ skype_debug_info("skype_win32", "Refused\n");
else if (ulParam == 3)
- purple_debug_info("skype_win32", "Not ready\n");
+ skype_debug_info("skype_win32", "Not ready\n");
else if (ulParam == 0x8001)
- purple_debug_info("skype_win32", "Skype became ready\n");
+ skype_debug_info("skype_win32", "Skype became ready\n");
return 1;
}
return DefWindowProc(hWindow, uiMessage, uiParam, ulParam);
@@ -197,7 +197,7 @@ exec_skype() }
pathtemp = g_strconcat("\"", path, "\" /nosplash /minimized", NULL);
- purple_debug_info("skype_win32", "Path to Skype: %s\n", pathtemp);
+ skype_debug_info("skype_win32", "Path to Skype: %s\n", pathtemp);
g_free(path);
success = g_spawn_command_line_async(pathtemp, NULL);
diff --git a/skype_messaging_x11.c b/skype_messaging_x11.c index 39c1970..bf35137 100644 --- a/skype_messaging_x11.c +++ b/skype_messaging_x11.c @@ -28,7 +28,7 @@ skype_connect() disp = XOpenDisplay(getenv("DISPLAY"));
if (disp == NULL)
{
- purple_debug_info("skype", "Couldn't open display\n");
+ skype_debug_info("skype", "Couldn't open display\n");
return FALSE;
}
message_start = XInternAtom( disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False );
@@ -40,21 +40,21 @@ skype_connect() XFlush(disp);
if (win == -1)
{
- purple_debug_info("skype", "Could not create X11 messaging window\n");
+ skype_debug_info("skype", "Could not create X11 messaging window\n");
return FALSE;
}
- skype_inst = XInternAtom(disp, "_SKYPE_INSTANCE", True); - if (skype_inst == None) - { - skype_win = (Window)-1; - purple_debug_info("skype_x11", "Could not create skype Atom\n"); - return FALSE; + skype_inst = XInternAtom(disp, "_SKYPE_INSTANCE", True);
+ if (skype_inst == None)
+ {
+ skype_win = (Window)-1;
+ skype_debug_info("skype_x11", "Could not create skype Atom\n");
+ return FALSE;
}
status = XGetWindowProperty(disp, root, skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
if(status != Success || format_ret != 32 || nitems_ret != 1)
{
skype_win = (Window)-1;
- purple_debug_info("skype", "Skype instance not found\n");
+ skype_debug_info("skype", "Skype instance not found\n");
return FALSE;
}
skype_win = * (const unsigned long *) prop & 0xffffffff;
@@ -77,10 +77,10 @@ skype_disconnect() e = g_new0(XEvent, 1);
e->xclient.type = DestroyNotify;
- XSendEvent(disp, win, False, 0, e); - - //wait here for the event to be handled - + XSendEvent(disp, win, False, 0, e);
+
+ //wait here for the event to be handled
+
XDestroyWindow(disp, win);
XCloseDisplay(disp);
@@ -105,7 +105,7 @@ send_message(char* message) XEvent e;
int message_num;
char error_return[15];
- unsigned int i; + unsigned int i;
if (skype_win == -1 || win == -1 || disp == NULL)
{
@@ -118,7 +118,7 @@ send_message(char* message) g_thread_create((GThreadFunc)skype_message_received, (void *)g_strdup(error_return), FALSE, NULL);
}
return;
- } + }
memset(&e, 0, sizeof(e));
e.xclient.type = ClientMessage;
@@ -135,9 +135,9 @@ send_message(char* message) e.xclient.message_type = message_continue; /* 2nd or greater message */
pos += i;
- } while( pos <= len ); + } while( pos <= len );
- //XFlush(disp); + //XFlush(disp);
if (x11_error_code == BadWindow)
{
@@ -160,7 +160,7 @@ receive_message_loop(void) XEvent e;
GString *msg = NULL;
char msg_temp[21];
- size_t len; + size_t len;
Bool event_bool;
msg_temp[20] = '\0';
@@ -169,21 +169,21 @@ receive_message_loop(void) //XNextEvent(disp, &e);
//if (e.type != ClientMessage)
//{
- // purple_debug_info("skype_x11", "Unknown event received: %d\n", e.xclient.type);
+ // skype_debug_info("skype_x11", "Unknown event received: %d\n", e.xclient.type);
// XFlush(disp);
// continue;
- //} - if (!disp) - { - purple_debug_error("skype_x11", "display has disappeared\n"); - break; - } - event_bool = XCheckTypedEvent(disp, ClientMessage, &e); - if (!event_bool) - { - usleep(1000); - continue; - } + //}
+ if (!disp)
+ {
+ skype_debug_error("skype_x11", "display has disappeared\n");
+ break;
+ }
+ event_bool = XCheckTypedEvent(disp, ClientMessage, &e);
+ if (!event_bool)
+ {
+ usleep(1000);
+ continue;
+ }
strncpy(msg_temp, e.xclient.data.b, 20);
len = strlen(msg_temp);
@@ -192,16 +192,16 @@ receive_message_loop(void) else if (e.xclient.message_type == message_continue)
msg = g_string_append_len(msg, msg_temp, len);
else
- { - purple_debug_info("skype_x11", "unknown message type: %d\n", e.xclient.message_type);
+ {
+ skype_debug_info("skype_x11", "unknown message type: %d\n", e.xclient.message_type);
XFlush(disp);
continue;
}
if (len < 20)
- { + {
//if (msg->str[0] == '#')
- g_thread_create((GThreadFunc)skype_message_received, (void *)g_string_free(msg, FALSE), FALSE, NULL); + g_thread_create((GThreadFunc)skype_message_received, (void *)g_string_free(msg, FALSE), FALSE, NULL);
//else
// purple_timeout_add(1, (GSourceFunc)skype_handle_received_message, (gpointer)g_string_free(msg, FALSE));
XFlush(disp);
@@ -211,62 +211,62 @@ receive_message_loop(void) static void
hide_skype()
-{ +{
}
static gboolean
exec_skype()
-{ +{
GError *error;
- if (g_spawn_command_line_async("skype", &error)) - { - return TRUE; - } else { - purple_debug_error("skype", "Could not start skype: %s\n", error->message); - return FALSE; + if (g_spawn_command_line_async("skype", &error))
+ {
+ return TRUE;
+ } else {
+ skype_debug_error("skype", "Could not start skype: %s\n", error->message);
+ return FALSE;
}
-} +}
+
+static gboolean
+is_skype_running()
+{
+ const gchar *temp;
+ int pid;
+ gchar* stat_path;
+ FILE *fh;
+ gchar exec_name[15];
+ struct stat *statobj = NULL;
+ //open /proc
+ GDir *procdir = g_dir_open("/proc", 0, NULL);
+ //go through directories that are numbers
+ while((temp = g_dir_read_name(procdir)))
+ {
+ pid = atoi(temp);
+ if (!pid)
+ continue;
+ // /proc/{pid}/stat contains lots of juicy info
+ stat_path = g_strdup_printf("/proc/%d/stat", pid);
+ fh = fopen(stat_path, "r");
+ // fscanf (file, "%*d (%15[^)]"
+ pid = fscanf(fh, "%*d (%15[^)]", exec_name);
+ fclose(fh);
+ if (strcmp(exec_name, "skype") != 0)
+ {
+ g_free(stat_path);
+ continue;
+ }
+ //get uid/owner of stat file by using fstat()
+ g_stat(stat_path, statobj);
+ g_free(stat_path);
+ //compare uid/owner of stat file (in g_stat->st_uid) to getuid();
+ if (statobj->st_uid == getuid())
+ {
+ //this copy of skype was started by us
+ return TRUE;
+ }
+ }
+ g_dir_close(procdir);
+ return FALSE;
+}
-static gboolean -is_skype_running() -{ - const gchar *temp; - int pid; - gchar* stat_path; - FILE *fh; - gchar exec_name[15]; - struct stat *statobj = NULL; - //open /proc - GDir *procdir = g_dir_open("/proc", 0, NULL); - //go through directories that are numbers - while((temp = g_dir_read_name(procdir))) - { - pid = atoi(temp); - if (!pid) - continue; - // /proc/{pid}/stat contains lots of juicy info - stat_path = g_strdup_printf("/proc/%d/stat", pid); - fh = fopen(stat_path, "r"); - // fscanf (file, "%*d (%15[^)]" - pid = fscanf(fh, "%*d (%15[^)]", exec_name); - fclose(fh); - if (strcmp(exec_name, "skype") != 0) - { - g_free(stat_path); - continue; - } - //get uid/owner of stat file by using fstat() - g_stat(stat_path, statobj); - g_free(stat_path); - //compare uid/owner of stat file (in g_stat->st_uid) to getuid(); - if (statobj->st_uid == getuid()) - { - //this copy of skype was started by us - return TRUE; - } - } - g_dir_close(procdir); - return FALSE; -} - |