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>2008-03-03 07:31:05 +0300
committerEion Robb <eion@robbmob.com>2008-03-03 07:31:05 +0300
commitfc04cd61203d524aa04cd89191d2ee6c1906eb70 (patch)
tree172b9c924bd1f49333889cf9707f6d9eaea0f0f5 /skype_messaging_dbus.c
parentdda39ec0a2f93674648b81601fe71ac613681568 (diff)
Fixed dbus interface
Added SKYPE_DBUS #define for toggling dbus at compile time
Diffstat (limited to 'skype_messaging_dbus.c')
-rw-r--r--skype_messaging_dbus.c115
1 files changed, 95 insertions, 20 deletions
diff --git a/skype_messaging_dbus.c b/skype_messaging_dbus.c
index 92e1788..673ad81 100644
--- a/skype_messaging_dbus.c
+++ b/skype_messaging_dbus.c
@@ -1,23 +1,42 @@
#define DBUS_API_SUBJECT_TO_CHANGE
-
-#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
#define SKYPE_DBUS_BUS DBUS_BUS_SESSION
static DBusGConnection *connection = NULL;
-static DBusGProxy *proxy = NULL;
-static DBusGProxy *proxy_receive = NULL;
-
-static void
-notify_handler(DBusGProxy *object, const char *message, gpointer user_data)
-{
- skype_debug_info("skype_dbus", "notify_handler called: %s\n", message);
+static DBusGProxy *proxy = NULL;
+
+static DBusHandlerResult
+skype_notify_handler(DBusConnection *connection, DBusMessage *message, gpointer user_data)
+{
+ DBusMessageIter iterator;
+ gchar *message_temp;
+ DBusMessage *temp_message;
+
+ temp_message = dbus_message_ref(message);
+ dbus_message_iter_init(temp_message, &iterator);
+ if (dbus_message_iter_get_arg_type(&iterator) != DBUS_TYPE_STRING)
+ {
+ return FALSE;
+ }
+
+ do
+ {
+ dbus_message_iter_get_basic(&iterator, &message_temp);
+ g_thread_create((GThreadFunc)skype_message_received, g_strdup(message_temp), FALSE, NULL);
+ } while(dbus_message_iter_has_next(&iterator) && dbus_message_iter_next(&iterator));
+
+ dbus_message_unref(message);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
}
-
+
static gboolean
skype_connect()
{
- GError *error = NULL;
+ GError *error = NULL;
+ DBusObjectPathVTable vtable;
+
connection = dbus_g_bus_get (SKYPE_DBUS_BUS, &error);
if (connection == NULL && error != NULL)
{
@@ -29,14 +48,10 @@ skype_connect()
proxy = dbus_g_proxy_new_for_name (connection,
"com.Skype.API",
"/com/Skype",
- "com.Skype.API");
- proxy_receive = dbus_g_proxy_new_for_name (connection,
- "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);
+ "com.Skype.API");
+
+ vtable.message_function = &skype_notify_handler;
+ dbus_connection_register_object_path(dbus_g_connection_get_connection(connection), "/com/Skype/Client", &vtable, NULL);
return TRUE;
}
@@ -60,7 +75,6 @@ send_message(char* message)
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))
{
@@ -81,4 +95,65 @@ send_message(char* message)
if (str != NULL)
g_thread_create((GThreadFunc)skype_message_received, (void *)str, FALSE, NULL);
}
+ 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 void
+hide_skype()
+{
+
+}
+static gboolean
+exec_skype()
+{
+ GError *error;
+ 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;
+ }
+}
+