soc.2009.telepathy: 63537fd4: Connect and disconnect via AccountManage...
sttwister at soc.pidgin.im
sttwister at soc.pidgin.im
Mon Jul 27 19:05:35 EDT 2009
-----------------------------------------------------------------
Revision: 63537fd40400665bf59837acbf0ebc15d6bde305
Ancestor: c9e4e721f0179e2a7066fbcb375360c1a7a3654b
Author: sttwister at soc.pidgin.im
Date: 2009-07-27T23:03:39
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/63537fd40400665bf59837acbf0ebc15d6bde305
Modified files:
libpurple/protocols/telepathy/telepathy.c
libpurple/protocols/telepathy/telepathy_account.c
libpurple/protocols/telepathy/telepathy_account.h
libpurple/protocols/telepathy/telepathy_client.c
libpurple/protocols/telepathy/telepathy_connection.c
libpurple/protocols/telepathy/telepathy_connection.h
libpurple/protocols/telepathy/telepathy_utils.c
libpurple/protocols/telepathy/telepathy_utils.h
ChangeLog:
Connect and disconnect via AccountManager, not directly
-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c 38773de2ee02f0a42dac615ded6d5cb9004a5a41
+++ libpurple/protocols/telepathy/telepathy.c e1553ecfd80c28d49f426c7cc5b88645cc4a5b7b
@@ -211,10 +211,8 @@ telepathy_login(PurpleAccount *acct)
}
- initial_presence = g_value_array_new(3);
- g_value_array_append(initial_presence, tp_g_value_slice_new_uint(2)); /* online */
- g_value_array_append(initial_presence, tp_g_value_slice_new_string("online"));
- g_value_array_append(initial_presence, tp_g_value_slice_new_string("Woot I'm online"));
+ initial_presence = purple_status_to_telepathy_status(
+ purple_account_get_active_status(acct));
tp_cli_dbus_properties_call_set(account_data->tp_account, -1,
TP_IFACE_ACCOUNT, "Enabled", tp_g_value_slice_new_boolean(TRUE),
@@ -230,90 +228,28 @@ static void
}
static void
-telepathy_login_old(PurpleAccount *acct)
+telepathy_close(PurpleConnection *gc)
{
- PurpleConnection *gc = purple_account_get_connection(acct);
+ PurpleAccount *acct = purple_connection_get_account(gc);
- PurplePlugin* plugin = gc->prpl;
- telepathy_data *data = (telepathy_data*)plugin->extra;
- GHashTable *options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free);
- int i;
+ telepathy_account *account_data = (telepathy_account*)purple_account_get_int(
+ acct, "tp_account_data", 0);
- purple_debug_info("telepathy", "Logging in as %s\n", acct->username);
+ purple_debug_info("telepathy", "Disabling account %s\n",
+ purple_account_get_username(acct));
-
- /* fill in the hash table with the other options, considering the right signatures */
- for (i = 0; data->protocol->params[i].name != NULL; ++i)
+ if (account_data == NULL)
{
- gchar *name;
- gchar *signature;
- name = data->protocol->params[i].name;
- signature = data->protocol->params[i].dbus_signature;
-
- /* some protocols might not require username or password, so check them before */
- if (g_strcmp0(name, "account") == 0 && acct->username != NULL)
- tp_asv_set_string(options, "account", acct->username);
- if (g_strcmp0(name, "password") == 0 && acct->password != NULL)
- tp_asv_set_string(options, "password", acct->password);
-
- /* account and password have already been added */
- if (g_strcmp0(name, "account") != 0 && g_strcmp0(name, "password"))
- {
- if (g_strcmp0(signature, "s") == 0)
- {
- if (g_strcmp0(purple_account_get_string(acct, name, ""), ""))
- tp_asv_set_string(options, name, purple_account_get_string(acct, name, ""));
- }
- else if (g_strcmp0(signature, "n") == 0)
- {
- if (purple_account_get_int(acct, name, 0) != 0)
- tp_asv_set_int32(options, name, purple_account_get_int(acct, name, 0));
- }
- else if (g_strcmp0(signature, "i") == 0)
- {
- if (purple_account_get_int(acct, name, 0) != 0)
- tp_asv_set_int32(options, name, purple_account_get_int(acct, name, 0));
- }
- else if (g_strcmp0(signature, "q") == 0)
- {
- if (purple_account_get_int(acct, name, 0) != 0)
- tp_asv_set_uint32(options, name, purple_account_get_int(acct, name, 0));
- }
- else if (g_strcmp0(signature, "b") == 0)
- {
- tp_asv_set_boolean(options, name, purple_account_get_bool(acct, name, FALSE));
- }
- else
- purple_debug_warning("telepathy", "Unknown signature \"%s\" for \"%s\"\n", signature, name);
- }
+ purple_debug_error("telepathy", "Account %s doesn't have tp_account_data\n",
+ purple_account_get_username(acct));
+ return;
}
- /* call RequestConnection with the specified parameters */
- tp_cli_connection_manager_call_request_connection(data->cm, -1, data->protocol->name, options, request_connection_cb, gc, NULL, NULL);
-
- g_hash_table_destroy(options);
+ tp_cli_dbus_properties_call_set(account_data->tp_account, -1,
+ TP_IFACE_ACCOUNT, "Enabled", tp_g_value_slice_new_boolean(FALSE),
+ NULL, NULL, NULL, NULL);
}
-static void
-telepathy_close(PurpleConnection *gc)
-{
- telepathy_connection *data = purple_connection_get_protocol_data(gc);
-
- purple_debug_info("telepathy", "We're closing, sorry :(\n");
-
- if (data)
- {
- /* make sure the connection is closed in dbus-land,
- * or else we won't be able to recreate the connection */
- if (data->connection)
- {
- /* this will call status_changed_cb which will free everything */
- tp_cli_connection_call_disconnect(data->connection, -1, NULL, NULL, NULL, NULL);
- }
-
- }
-}
-
static int
telepathy_send_im (PurpleConnection *gc,
const char *who,
============================================================
--- libpurple/protocols/telepathy/telepathy_account.c 2e7e18119b7a697e152b81044a94cb71f2d10f2e
+++ libpurple/protocols/telepathy/telepathy_account.c cdc7f72ed98b2b6211cd3f651578c4dff6b8fd78
@@ -30,10 +30,50 @@
#include <telepathy-glib/util.h>
#include "account.h"
+#include "core.h"
#include "debug.h"
#include "../../../pidgin/gtkaccount.h"
void
+account_properties_changed (telepathy_account *account_data,
+ GHashTable *properties)
+{
+ GHashTableIter iter;
+ gpointer key, val;
+
+ purple_debug_info("telepathy", "account_properties_changed!\n");
+
+ g_hash_table_iter_init (&iter, properties);
+ while (g_hash_table_iter_next (&iter, &key, &val))
+ {
+ GValue *value = val;
+
+ if (g_strcmp0(key, "Connection") == 0)
+ {
+ gchar *connection_object = g_value_get_boxed(value);
+
+ if (g_strcmp0(connection_object, "/") != 0)
+ got_connection_object(connection_object, account_data);
+ }
+ else if (g_strcmp0(key, "ConnectionStatus") == 0)
+ {
+ guint status = g_value_get_uint(value);
+ guint reason = g_value_get_uint(g_hash_table_lookup(
+ account_data->properties, "ConnectionStatusReason"));
+
+ connection_status_changed(account_data, status, reason);
+ }
+ else if (g_strcmp0(key, "Enabled") == 0)
+ {
+ PurpleAccount *acct = account_data->account;
+
+ purple_account_set_enabled(acct, purple_core_get_ui(),
+ g_value_get_boolean(value));
+ }
+ }
+}
+
+void
update_parameters_cb (TpAccount *proxy,
const gchar **out_Reconnect_Required,
const GError *error,
@@ -308,6 +348,8 @@ get_account_properties_cb (TpProxy *prox
/* Sync the parameters with PurpleAccount's parameters */
set_account_parameters(account, parameters);
+
+ account_properties_changed(account_data, out_Properties);
}
static void
@@ -401,6 +443,8 @@ account_get_all_cb (TpProxy *proxy,
tp_g_hash_table_update(account_data->properties, out_Properties,
(GBoxedCopyFunc)g_strdup, (GBoxedCopyFunc)tp_g_value_slice_dup);
+ account_properties_changed(account_data, out_Properties);
+
}
static void
@@ -425,6 +469,8 @@ account_property_changed_cb (TpAccount *
tp_g_hash_table_update(account_data->properties, arg_Properties,
(GBoxedCopyFunc)g_strdup, (GBoxedCopyFunc)tp_g_value_slice_dup);
+
+ account_properties_changed(account_data, arg_Properties);
}
static void
============================================================
--- libpurple/protocols/telepathy/telepathy_account.h 410ad9d3c0ca1c18cf59c399b49afb98ec9a5da4
+++ libpurple/protocols/telepathy/telepathy_account.h 84770e42ae150b7c6b4f3ee6905cef3968fc910b
@@ -25,11 +25,15 @@
#include "account.h"
+#include "telepathy_connection.h"
+
typedef struct
{
TpAccount *tp_account;
PurpleAccount *account;
+ telepathy_connection *connection_data;
+
gchar *obj_Path;
gchar *cm, *protocol;
@@ -38,6 +42,10 @@ void
} telepathy_account;
void
+account_properties_changed (telepathy_account *account_data,
+ GHashTable *properties);
+
+void
update_parameters_cb (TpAccount *proxy,
const gchar **out_Reconnect_Required,
const GError *error,
============================================================
--- libpurple/protocols/telepathy/telepathy_client.c 75c2f4000e15abd414481203bd4bc3abd6ae7127
+++ libpurple/protocols/telepathy/telepathy_client.c a96bc6e4f3b84ce805708348928d2a2392a527f8
@@ -151,13 +151,13 @@ client_get_property (GObject *object,
GHashTable *filter;
filter = tp_asv_new (
- TP_IFACE_CHANNEL ".Type", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
+ TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
NULL);
g_ptr_array_add (filters, filter);
filter = tp_asv_new (
- TP_IFACE_CHANNEL ".Type", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
+ TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
NULL);
g_ptr_array_add (filters, filter);
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.c b8ddc2df04dd497e1b61250d4702f584e82a5bd0
+++ libpurple/protocols/telepathy/telepathy_connection.c 73bb957cd1d1e5b5e7537e772a372e16c55581df
@@ -27,6 +27,7 @@
#include "connection.h"
#include "debug.h"
+#include "telepathy_account.h"
#include "telepathy_avatar.h"
#include "telepathy_channel.h"
#include "telepathy_channel_text.h"
@@ -34,6 +35,210 @@ void
#include "telepathy_contact.h"
void
+connection_status_changed (gpointer data,
+ guint arg_Status,
+ guint arg_Reason)
+{
+ telepathy_account *account_data = data;
+ telepathy_connection *connection_data = account_data->connection_data;
+ PurpleConnection *gc = purple_account_get_connection(account_data->account);
+
+ if (arg_Status == TP_CONNECTION_STATUS_CONNECTED)
+ {
+ purple_debug_info("telepathy", "Connected!\n");
+
+ purple_connection_update_progress(gc, _("Connected"),
+ 1, /* which connection step this is */
+ 2); /* total number of steps */
+
+ purple_connection_set_state(gc, PURPLE_CONNECTED);
+
+ connection_data->text_Channels = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) destroy_text_channel);
+ connection_data->room_Channels = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+ NULL, (GDestroyNotify) destroy_room_channel);
+ connection_data->contacts = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+ NULL, (GDestroyNotify) destroy_contact);
+ connection_data->groups = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) destroy_group);
+ connection_data->lists = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) destroy_group);
+ connection_data->buddy_to_be_added = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, g_free);
+ }
+ else if (arg_Status == TP_CONNECTION_STATUS_DISCONNECTED)
+ {
+ gchar *reason = NULL;
+ PurpleConnectionError error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
+ purple_debug_info("telepathy", "Disconnected! Reason: %d\n", arg_Reason);
+
+ switch (arg_Reason)
+ {
+ case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
+ reason = "Network error";
+ error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
+ reason = "Authentication failed";
+ error = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
+ reason = "Encryption error";
+ error = PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
+ reason = "Name in use";
+ error = PURPLE_CONNECTION_ERROR_NAME_IN_USE;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
+ reason = "SSL Certificate not provided";
+ error = PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
+ reason = "SSL Certificate is isnged by an untrusted certifying authority";
+ error = PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
+ reason = "SSL Certificate expired";
+ error = PURPLE_CONNECTION_ERROR_CERT_EXPIRED;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
+ reason = "SSL Certificate is not yet valid";
+ error = PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
+ reason = "SSL Certificate hostname mismatch";
+ error = PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
+ reason = "SSL Certificate fingerprint mismatch";
+ error = PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
+ reason = "SSL Certificate is self-signed";
+ error = PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED;
+ break;
+
+ case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
+ reason = "Error while validating the server's SSL Certificate";
+ error = PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR;
+ break;
+ }
+
+ if (reason != NULL && gc)
+ purple_connection_error_reason(gc, error, reason);
+
+ if (connection_data)
+ {
+ purple_connection_set_protocol_data(connection_data->gc, NULL);
+
+ if (connection_data->connection != NULL)
+ {
+ g_object_unref(connection_data->connection);
+ connection_data->connection = NULL;
+ }
+
+ if (connection_data->text_Channels != NULL)
+ {
+ g_hash_table_destroy(connection_data->text_Channels);
+ connection_data->text_Channels = NULL;
+ }
+
+ if (connection_data->contacts != NULL)
+ {
+ g_hash_table_destroy(connection_data->contacts);
+ connection_data->contacts = NULL;
+ }
+
+ if (connection_data->groups != NULL)
+ {
+ g_hash_table_destroy(connection_data->groups);
+ connection_data->groups = NULL;
+ }
+
+ if (connection_data->lists != NULL)
+ {
+ g_hash_table_destroy(connection_data->lists);
+ connection_data->lists = NULL;
+ }
+
+ g_free(connection_data);
+ }
+
+ }
+ else if (arg_Status == TP_CONNECTION_STATUS_CONNECTING)
+ {
+ purple_debug_info("telepathy", "Connecting! Reason: %d\n", arg_Reason);
+ purple_connection_set_state(gc, PURPLE_CONNECTING);
+ purple_connection_update_progress(gc, _("Connecting"),
+ 0, /* which connection step this is */
+ 2); /* total number of steps */
+
+ }
+}
+
+void
+got_connection_object (gchar *connection_object,
+ gpointer data)
+{
+ GError *error = NULL;
+
+ telepathy_connection *connection_data;
+ telepathy_account *account_data = data;
+
+ PurpleAccount *acct = account_data->account;
+ PurpleConnection *gc = purple_account_get_connection(acct);
+
+ TpDBusDaemon *daemon = tp_dbus_daemon_dup(&error);
+
+ if (error != NULL)
+ {
+ purple_debug_error("telepathy", "Error creating dbus daemon: %s\n", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ purple_debug_info("telepathy", "Got connection object!\n");
+
+ connection_data = g_new0(telepathy_connection, 1);
+
+ /* get the connection proxy straight out of the dbus interface */
+ connection_data->connection = tp_connection_new(daemon, NULL, connection_object, &error);
+ connection_data->gc = gc;
+ connection_data->acct = acct;
+
+ account_data->connection_data = connection_data;
+
+ purple_connection_set_protocol_data(gc, connection_data);
+
+ if (error != NULL)
+ {
+ purple_debug_error("telepathy", "Error creating TpConnection object: %s\n", error->message);
+ g_error_free(error);
+
+ g_object_unref(connection_data->connection);
+ connection_data->connection = NULL;
+ g_free(connection_data);
+ return;
+ }
+
+ tp_connection_call_when_ready(connection_data->connection, connection_ready_cb, connection_data);
+
+ if (daemon != NULL)
+ g_object_unref(daemon);
+}
+
+void
status_changed_cb (TpConnection *proxy,
guint arg_Status,
guint arg_Reason,
@@ -320,11 +525,14 @@ connection_ready_cb (TpConnection *conne
purple_debug_info("telepathy", "Self Handle: %u\n", data->self_handle);
- tp_cli_connection_interface_requests_connect_to_new_channels(connection, new_channels_cb, user_data, NULL, NULL, &error);
+ tp_cli_connection_interface_requests_connect_to_new_channels(connection,
+ new_channels_cb, user_data,
+ NULL, NULL, &error);
if (error != NULL)
{
- purple_debug_error("telepathy", "Error while connecting to NewChannels signal: %s\n", error->message);
+ purple_debug_error("telepathy", "Error while connecting to"
+ " NewChannels signal: %s\n", error->message);
g_error_free(error);
error = NULL;
return;
@@ -333,11 +541,19 @@ connection_ready_cb (TpConnection *conne
data->listing_channels = TRUE;
/* query the Channels property of the Requests interface */
- tp_cli_dbus_properties_call_get(connection, -1, TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "Channels", get_channels_cb, user_data, NULL, NULL);
+ tp_cli_dbus_properties_call_get(connection, -1,
+ TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "Channels",
+ get_channels_cb, user_data,
+ NULL, NULL);
/* query supported avatar formats */
- tp_cli_dbus_properties_call_get_all(connection, -1, TP_IFACE_CONNECTION_INTERFACE_AVATARS, get_avatar_properties_cb, user_data, NULL, NULL);
+ /*
+ tp_cli_dbus_properties_call_get_all(connection, -1,
+ TP_IFACE_CONNECTION_INTERFACE_AVATARS,
+ get_avatar_properties_cb, user_data,
+ NULL, NULL);
+ */
/* this will be fired when an avatar for a buddy has been received */
tp_cli_connection_interface_avatars_connect_to_avatar_retrieved(connection,
============================================================
--- libpurple/protocols/telepathy/telepathy_connection.h 8b140f11430d17aae0cb0b556a9be5d56a1a2265
+++ libpurple/protocols/telepathy/telepathy_connection.h 90fd6570845e7df8ed0c820e0a1370c15a9ee905
@@ -64,6 +64,15 @@ void
} telepathy_connection;
void
+connection_status_changed (gpointer account_data,
+ guint status,
+ guint reason);
+
+void
+got_connection_object (gchar *connection_object,
+ gpointer account_data);
+
+void
status_changed_cb (TpConnection *proxy,
guint arg_Status,
guint arg_Reason,
============================================================
--- libpurple/protocols/telepathy/telepathy_utils.c 667ad36eeb59f2f3250820cbd808f503955c55dd
+++ libpurple/protocols/telepathy/telepathy_utils.c 85630e227f8b031be8c79fcbf09c5949ef2e40b7
@@ -20,10 +20,33 @@
#include "telepathy_utils.h"
+#include <telepathy-glib/util.h>
+
#include "internal.h"
#include "debug.h"
+/* TODO: Check for other types of statuses too */
+GValueArray *
+purple_status_to_telepathy_status(PurpleStatus *status)
+{
+ GValueArray *presence = g_value_array_new(3);
+
+ PurpleStatusType *type = purple_status_get_type(status);
+ const gchar *status_id = purple_status_get_id(status);
+ const gchar *presence_message = purple_status_get_attr_string(status, "message");
+
+ if (purple_status_type_get_primitive(type) == PURPLE_STATUS_AVAILABLE)
+ g_value_array_append(presence, tp_g_value_slice_new_uint(2)); /* online */
+ else
+ g_value_array_append(presence, tp_g_value_slice_new_uint(1)); /* offline */
+
+ g_value_array_append(presence, tp_g_value_slice_new_string(status_id));
+ g_value_array_append(presence, tp_g_value_slice_new_string(presence_message));
+
+ return presence;
+}
+
void
set_properties_cb (TpProxy *proxy,
const GError *error,
============================================================
--- libpurple/protocols/telepathy/telepathy_utils.h f54462bcd9efe93ec240c28bc46317fd4dc2f059
+++ libpurple/protocols/telepathy/telepathy_utils.h b6fc9a32cd67622b4e579c3191d2abae89080c55
@@ -56,7 +56,7 @@ static const StatusMapping statuses[] =
static const StatusMapping statuses[] =
{
- { PURPLE_STATUS_AVAILABLE, "available", "Available" },
+ { PURPLE_STATUS_AVAILABLE, "available", N_("Available") },
{ PURPLE_STATUS_AWAY, "away", N_("Away") },
{ PURPLE_STATUS_AWAY, "brb", N_("Be right back") },
{ PURPLE_STATUS_UNAVAILABLE, "dnd", N_("Do not disturb") },
@@ -69,6 +69,9 @@ static const StatusMapping statuses[] =
{ 0, NULL, NULL}
};
+GValueArray *
+purple_status_to_telepathy_status(PurpleStatus *status);
+
void
set_properties_cb (TpProxy *proxy,
const GError *error,
More information about the Commits
mailing list