/dev/tomkiewicz/e2ee: 25c373adf8de: E2EE: initial implementation

Tomasz Wasilczyk twasilczyk at pidgin.im
Thu Oct 3 18:27:28 EDT 2013


Changeset: 25c373adf8dec0b8e07fdf5c903fd60f64c245ce
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-10-04 00:27 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/e2ee/rev/25c373adf8de

Description:

E2EE: initial implementation

diffstat:

 libpurple/Makefile.am                         |    2 +
 libpurple/conversation.c                      |   65 +++++++
 libpurple/conversation.h                      |    8 +
 libpurple/e2ee.c                              |  216 ++++++++++++++++++++++++++
 libpurple/e2ee.h                              |  111 +++++++++++++
 pidgin/pixmaps/Makefile.am                    |    7 +
 pidgin/pixmaps/e2ee-states/16/finished.png    |  Bin 
 pidgin/pixmaps/e2ee-states/16/not-private.png |  Bin 
 pidgin/pixmaps/e2ee-states/16/private.png     |  Bin 
 pidgin/pixmaps/e2ee-states/16/unverified.png  |  Bin 
 10 files changed, 409 insertions(+), 0 deletions(-)

diffs (truncated from 577 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -50,6 +50,7 @@ purple_coresources = \
 	core.c \
 	debug.c \
 	desktopitem.c \
+	e2ee.c \
 	eventloop.c \
 	ft.c \
 	http.c \
@@ -120,6 +121,7 @@ purple_coreheaders = \
 	dbus-maybe.h \
 	debug.h \
 	desktopitem.h \
+	e2ee.h \
 	eventloop.h \
 	ft.h \
 	http.h \
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -144,6 +144,8 @@ struct _PurpleConversation
 
 	PurpleConnectionFlags features; /**< The supported features */
 	GList *message_history;         /**< Message history, as a GList of PurpleConvMessage's */
+
+	PurpleE2eeState *e2ee_state;
 };
 
 /**
@@ -929,6 +931,64 @@ purple_conversation_get_name(const Purpl
 }
 
 void
+purple_conversation_set_e2ee_state(PurpleConversation *conv,
+	PurpleE2eeState *state)
+{
+	g_return_if_fail(conv != NULL);
+
+	if (state != NULL && purple_e2ee_state_get_provider(state) !=
+		purple_e2ee_provider_get_main())
+	{
+		purple_debug_error("conversation",
+			"This is not the main e2ee provider");
+
+		return;
+	}
+
+	/* don't emit a signal if it doesn't differ */
+	if (conv->e2ee_state == state)
+		return;
+
+	purple_e2ee_state_ref(state);
+	purple_e2ee_state_unref(conv->e2ee_state);
+	conv->e2ee_state = state;
+
+	purple_signal_emit(purple_conversations_get_handle(),
+		"conversation-e2ee-state-changed", conv);
+}
+
+PurpleE2eeState *
+purple_conversation_get_e2ee_state(PurpleConversation *conv)
+{
+	PurpleE2eeProvider *provider;
+	PurpleE2eeFeatures features;
+
+	g_return_val_if_fail(conv != NULL, NULL);
+
+	provider = purple_e2ee_provider_get_main();
+	if (provider == NULL)
+		return NULL;
+
+	features = purple_e2ee_provider_get_features(provider);
+	if (conv->type == PURPLE_CONV_TYPE_IM) {
+		if (!(features & PURPLE_E2EE_FEATURE_IM))
+			return NULL;
+	} else if (conv->type == PURPLE_CONV_TYPE_CHAT) {
+		if (!(features & PURPLE_E2EE_FEATURE_CHAT))
+			return NULL;
+	} else
+		return NULL;
+
+	if (purple_e2ee_state_get_provider(conv->e2ee_state) != provider) {
+		purple_debug_warning("conversation",
+			"e2ee state has invalid provider set");
+		return NULL;
+	}
+
+	return conv->e2ee_state;
+}
+
+void
 purple_conversation_set_logging(PurpleConversation *conv, gboolean log)
 {
 	g_return_if_fail(conv != NULL);
@@ -2866,6 +2926,11 @@ purple_conversations_init(void)
 			     purple_value_new(PURPLE_TYPE_SUBTYPE,
 					    PURPLE_SUBTYPE_CONVERSATION),
 			     purple_value_new(PURPLE_TYPE_BOXED, "GList **"));
+
+	purple_signal_register(handle, "conversation-e2ee-state-changed",
+		purple_marshal_VOID__POINTER, NULL, 1,
+		purple_value_new(PURPLE_TYPE_SUBTYPE,
+			PURPLE_SUBTYPE_CONVERSATION));
 }
 
 void
diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -146,6 +146,7 @@ typedef enum
 
 #include "account.h"
 #include "buddyicon.h"
+#include "e2ee.h"
 #include "log.h"
 #include "server.h"
 
@@ -404,6 +405,13 @@ void purple_conversation_set_name(Purple
  */
 const char *purple_conversation_get_name(const PurpleConversation *conv);
 
+void
+purple_conversation_set_e2ee_state(PurpleConversation *conv,
+	PurpleE2eeState *state);
+
+PurpleE2eeState *
+purple_conversation_get_e2ee_state(PurpleConversation *conv);
+
 /**
  * Get an attribute of a chat buddy
  *
diff --git a/libpurple/e2ee.c b/libpurple/e2ee.c
new file mode 100644
--- /dev/null
+++ b/libpurple/e2ee.c
@@ -0,0 +1,216 @@
+/**
+ * @file e2ee.c End-to-end encryption API
+ * @ingroup core
+ */
+
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include "e2ee.h"
+
+#include "debug.h"
+
+struct _PurpleE2eeState
+{
+	PurpleE2eeProvider *provider;
+
+	gchar *name;
+	gchar *stock_icon;
+
+	guint ref_count;
+};
+
+struct _PurpleE2eeProvider
+{
+	PurpleE2eeFeatures features;
+	PurpleE2eeState *default_state;
+};
+
+static PurpleE2eeProvider *main_provider = NULL;
+
+/*** Encryption states for conversations. *************************************/
+
+PurpleE2eeState *
+purple_e2ee_state_new(PurpleE2eeProvider *provider)
+{
+	PurpleE2eeState *state;
+
+	g_return_val_if_fail(provider != NULL, NULL);
+
+	state = g_new0(PurpleE2eeState, 1);
+	state->provider = provider;
+	state->ref_count = 1;
+
+	return state;
+}
+
+void
+purple_e2ee_state_ref(PurpleE2eeState *state)
+{
+	g_return_if_fail(state != NULL);
+
+	state->ref_count++;
+}
+
+PurpleE2eeState *
+purple_e2ee_state_unref(PurpleE2eeState *state)
+{
+	if (state == NULL)
+		return NULL;
+
+	state->ref_count--;
+	if (state->ref_count > 0)
+		return state;
+
+	g_free(state->name);
+	g_free(state->stock_icon);
+	g_free(state);
+
+	return NULL;
+}
+
+PurpleE2eeProvider *
+purple_e2ee_state_get_provider(PurpleE2eeState *state)
+{
+	g_return_val_if_fail(state != NULL, NULL);
+
+	return state->provider;
+}
+
+void
+purple_e2ee_state_set_name(PurpleE2eeState *state, const gchar *name)
+{
+	g_return_if_fail(state != NULL);
+	g_return_if_fail(name != NULL);
+
+	g_free(state->name);
+	state->name = g_strdup(name);
+}
+
+const gchar *
+purple_e2ee_state_get_name(PurpleE2eeState *state)
+{
+	g_return_val_if_fail(state, NULL);
+
+	return state->name;
+}
+
+void
+purple_e2ee_state_set_stock_icon(PurpleE2eeState *state,
+	const gchar *stock_icon)
+{
+	g_return_if_fail(state != NULL);
+	g_return_if_fail(stock_icon != NULL);
+
+	g_free(state->stock_icon);
+	state->stock_icon = g_strdup(stock_icon);
+}
+
+const gchar *
+purple_e2ee_state_get_stock_icon(PurpleE2eeState *state)
+{
+	g_return_val_if_fail(state, NULL);
+
+	return state->stock_icon;
+}
+
+/*** Encryption providers API. ************************************************/
+
+PurpleE2eeProvider *
+purple_e2ee_provider_new(PurpleE2eeFeatures features)
+{
+	PurpleE2eeProvider *provider;
+
+	provider = g_new0(PurpleE2eeProvider, 1);
+	provider->features = features;
+
+	return provider;
+}
+
+void
+purple_e2ee_provider_free(PurpleE2eeProvider *provider)
+{
+	g_return_if_fail(provider != NULL);
+
+	if (provider == main_provider) {
+		purple_debug_error("e2ee", "This provider is still registered");
+		return;
+	}
+
+	g_free(provider);
+}
+
+gboolean
+purple_e2ee_provider_register(PurpleE2eeProvider *provider)



More information about the Commits mailing list