soc.2009.telepathy: a89bb829: Listen for authorization requests from r...

sttwister at soc.pidgin.im sttwister at soc.pidgin.im
Tue Jul 7 15:40:44 EDT 2009


-----------------------------------------------------------------
Revision: a89bb829c6a66711ca7031eab32d8b7fa214753b
Ancestor: 9ad163e1b7292856abe4cafa0672f9d1e29dfd17
Author: sttwister at soc.pidgin.im
Date: 2009-07-07T19:34:14
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/a89bb829c6a66711ca7031eab32d8b7fa214753b

Modified files:
        libpurple/protocols/telepathy/telepathy_channel_list.c
        libpurple/protocols/telepathy/telepathy_channel_list.h
        libpurple/protocols/telepathy/telepathy_contact.c

ChangeLog: 

Listen for authorization requests from remote buddies

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_list.c	815a9403a11248b09337c06dcca5e002938d75dd
+++ libpurple/protocols/telepathy/telepathy_channel_list.c	be454069410216fcc209663e13732ef90adc5c5b
@@ -51,6 +51,184 @@ create_group_channel_cb (TpConnection *p
 	purple_debug_info("telepathy", "Group channel created: %s\n", out_Channel);
 }
 
+static void
+add_members_cb (TpChannel *proxy,
+                const GError *error,
+                gpointer user_data,
+                GObject *weak_object)
+{
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "AddMembers error: %s\n", error->message);
+		return;
+	}
+	
+	purple_debug_warning("telepathy", "AddMembers succeeded!\n");
+}
+
+static void
+request_authorization_auth_cb (gpointer user_data)
+{
+	telepathy_authorization_request *request = user_data;
+	GArray *arr = g_array_new(FALSE, FALSE, sizeof(guint));
+
+	purple_debug_info("telepathy", "Accepting request from %u\n", request->handle);
+
+	/* We must add the contact to the publish list */
+
+	g_array_append_val(arr, request->handle);
+
+	tp_cli_channel_interface_group_call_add_members(request->channel, -1,
+			arr, NULL,
+			add_members_cb, user_data,
+			NULL, NULL);
+
+	g_free(request);	
+}
+
+static void
+remove_members_cb (TpChannel *proxy,
+                   const GError *error,
+                   gpointer user_data,
+                   GObject *weak_object)
+{
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "RemoveMembers error: %s\n", error->message);
+		return;
+	}
+	
+	purple_debug_warning("telepathy", "RemoveMembers succeeded!\n");
+}
+
+static void
+request_authorization_deny_cb (gpointer user_data)
+{
+	telepathy_authorization_request *request = user_data;
+	GArray *arr = g_array_new(FALSE, FALSE, sizeof(guint));
+
+	purple_debug_info("telepathy", "Denying request from %u\n", request->handle);
+
+	/* By removing the handle from the channel's local-pending,
+	 * we're actually denying the request.
+	 */
+
+	g_array_append_val(arr, request->handle);
+
+	tp_cli_channel_interface_group_call_remove_members(request->channel, -1,
+			arr, NULL,
+			remove_members_cb, user_data,
+			NULL, NULL);
+
+	g_free(request);	
+}
+
+static void
+request_authorization_cb (TpConnection *connection,
+                          guint n_contacts,
+                          TpContact * const *contacts,
+                          guint n_failed,
+                          const TpHandle *failed,
+                          const GError *error,
+                          gpointer user_data,
+                          GObject *weak_object)
+{
+	telepathy_authorization_request *data = user_data;
+	int i;
+
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "Error geting contact for"
+				"authorization request:%s\n", error->message);
+	}
+
+	if (n_failed > 0)
+	{
+		purple_debug_error("telepathy", "Failed getting TpContact for %u contacts\n",
+				n_failed);
+	}
+
+	/* Prompt the user for authorisation for each contact */
+	for (i = 0; i<n_contacts; ++i)
+	{
+		telepathy_authorization_request *request = g_new0(
+				telepathy_authorization_request, 1);
+
+		*request = *data;
+		request->handle = tp_contact_get_handle(contacts[i]);
+
+		purple_account_request_authorization(data->connection_data->acct,
+				tp_contact_get_identifier(contacts[i]), NULL,
+				tp_contact_get_alias(contacts[i]), NULL,
+				FALSE, 
+				request_authorization_auth_cb,
+				request_authorization_deny_cb,
+				request);
+	}
+}
+
+static void
+members_changed_cb (TpChannel *proxy,
+                    const gchar *arg_Message,
+                    const GArray *arg_Added,
+                    const GArray *arg_Removed,
+                    const GArray *arg_Local_Pending,
+                    const GArray *arg_Remote_Pending,
+                    guint arg_Actor,
+                    guint arg_Reason,
+                    gpointer user_data,
+                    GObject *weak_object)
+{
+	purple_debug_info("telepathy", "Members changed for %s! (Reason: %u) (Message: %s)\n",
+			tp_channel_get_identifier(proxy), arg_Reason, arg_Message);
+
+	if (arg_Added->len > 0)
+	{
+		purple_debug_info("telepathy", "  %u added\n",
+				arg_Added->len);
+	}
+
+	if (arg_Removed->len > 0)
+	{
+		purple_debug_info("telepathy", "  %u removed\n",
+				arg_Removed->len);
+	}
+
+	if (arg_Remote_Pending->len > 0)
+	{
+		purple_debug_info("telepathy", "  %u remote pending\n",
+				arg_Remote_Pending->len);
+	}
+
+	if (arg_Local_Pending->len > 0)
+	{
+		telepathy_connection *data = user_data;
+		telepathy_authorization_request *request;
+
+		const TpContactFeature features[] = {
+			TP_CONTACT_FEATURE_ALIAS,
+			TP_CONTACT_FEATURE_PRESENCE
+		};
+
+		purple_debug_info("telepathy", "  %u local pending\n",
+				arg_Local_Pending->len);
+
+		/* We've got some buddies pending local acception.
+		 * First, we request a TpContact for that handle and the promp the user.
+		 */
+
+		request = g_new0(telepathy_authorization_request, 1);
+
+		request->connection_data = data;
+		request->channel = proxy;
+
+		tp_connection_get_contacts_by_handle(data->connection,
+				arg_Local_Pending->len, (const TpHandle*)arg_Local_Pending->data,
+				G_N_ELEMENTS (features), features,
+				request_authorization_cb, request, g_free, NULL);
+	}
+}
+
 void
 handle_list_channel (TpChannel *channel,
                      telepathy_connection *data)
@@ -72,6 +250,8 @@ handle_list_channel (TpChannel *channel,
 	gchar *buddy_name;
 	const gchar *group_name;
 
+	GError *error = NULL;
+
 	handle = tp_channel_get_handle(channel, &handle_type);
 
 	members = tp_channel_group_get_members(channel);
@@ -151,5 +331,16 @@ handle_list_channel (TpChannel *channel,
 
 	g_array_free (handles, TRUE);
 
+	tp_cli_channel_interface_group_connect_to_members_changed(channel, 
+			members_changed_cb, data,
+			NULL, NULL,
+			&error);
+
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "Error connecting to MembersChanged: %s\n",
+				error->message);
+		g_error_free(error);
+	}
 }
 
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_list.h	a427580edb95a22cd97ba505f29ba9dd1980b1d8
+++ libpurple/protocols/telepathy/telepathy_channel_list.h	a771a4511c83f7e26e67f230da34cbd58491beaa
@@ -29,7 +29,15 @@ typedef struct
 {
 	telepathy_connection *connection_data;
 	TpChannel *channel;
+	TpHandle handle;
 
+} telepathy_authorization_request;
+
+typedef struct
+{
+	telepathy_connection *connection_data;
+	TpChannel *channel;
+
 } telepathy_group;
 
 void
============================================================
--- libpurple/protocols/telepathy/telepathy_contact.c	b056e86ca773a8546ab511a0a7476f833b2a9a9f
+++ libpurple/protocols/telepathy/telepathy_contact.c	fb8d9df512702440bc7f1793d8aafae811548369
@@ -77,7 +77,8 @@ add_contact_to_group_cb (TpConnection *c
 		int i;
 		GArray *arr = g_array_new(0, 0, sizeof(TpHandle));
 
-		purple_debug_info("telepathy", "Got handle for adding buddy!\n");
+		purple_debug_info("telepathy", "Got handle for adding buddy (%u)!\n",
+				handles[0]);
 
 		for (i = 0; i<n_handles; ++i)
 		{


More information about the Commits mailing list