Commit c42c9693 authored by TomekWasilczyk's avatar TomekWasilczyk
Browse files

Implement Fingerprint verification API

parent a78ff5c9
......@@ -32,6 +32,7 @@ EXTRA_DIST = \
Makefile.static \
common.h \
dialogs.h \
fprint-verificator.h \
gtk-dialog.h \
otr-icons.h \
otr-plugin.h \
......
/*
* Fingerprint verification API for Off-the-Record Messaging
* plugin for libpurple 3.
*
* Copyright (C) 2004-2012 Ian Goldberg, Rob Smits,
* Chris Alexander, Willy Lew,
* Nikita Borisov
* <otr@cypherpunks.ca>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* 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 02110-1301 USA
*/
#ifndef __OTRG_FPRINT_VERIFICATOR_H__
#define __OTRG_FPRINT_VERIFICATOR_H__
typedef void (*OtrgFingerprintVerifyBackCb)(ConnContext *context,
gpointer cb_data);
typedef void (*OtrgFingerprintVerifyCb)(ConnContext *context,
OtrgFingerprintVerifyBackCb on_back, gpointer cb_data);
typedef struct
{
gsize struct_size;
const gchar *name;
OtrgFingerprintVerifyCb verify_cb;
} OtrgFingerprintVerificator;
static inline gboolean
otrg_verificator_register(OtrgFingerprintVerificator* verf)
{
PurplePlugin *otrg;
otrg = purple_plugins_find_with_id("otr");
if (otrg == NULL) {
purple_debug_error("otr", "OTR plugin is not present");
return FALSE;
}
return GPOINTER_TO_INT(purple_signal_emit_return_1(otrg,
"otr-verificator-register", verf));
}
static inline void
otrg_verificator_unregister(OtrgFingerprintVerificator* verf)
{
PurplePlugin *otrg;
otrg = purple_plugins_find_with_id("otr");
if (otrg == NULL) {
purple_debug_error("otr", "OTR plugin is not present");
return;
}
purple_signal_emit(otrg, "otr-verificator-unregister", verf);
}
#endif
/* vim: set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
......@@ -74,6 +74,10 @@
#include "dialogs.h"
#include "otr-plugin.h"
#if PURPLE_VERSION_CHECK(3,0,0)
#include "fprint-verificator.h"
#endif
#ifdef USING_GTK
/* purple-otr GTK headers */
#include "gtk-ui.h"
......@@ -134,6 +138,10 @@ PurplePlugin *otrg_plugin_handle;
/* We'll only use the one OtrlUserState. */
OtrlUserState otrg_plugin_userstate = NULL;
#if PURPLE_VERSION_CHECK(3,0,0)
GSList *otrg_fprint_verificators = NULL;
#endif
#if !PURPLE_VERSION_CHECK(3,0,0)
/* GLib HashTable for storing the maximum message size for various
* protocols. */
......@@ -141,6 +149,33 @@ GHashTable* mms_table = NULL;
#endif
#if PURPLE_VERSION_CHECK(3,0,0)
static gboolean
otrg_verificator_register_cb(OtrgFingerprintVerificator *verf)
{
g_return_val_if_fail(verf != NULL, FALSE);
g_return_val_if_fail(OTRG_FPRINT_VERIFICATOR_HAS_FIELD(verf, name), FALSE);
g_return_val_if_fail(
OTRG_FPRINT_VERIFICATOR_HAS_FIELD(verf, verify_cb), FALSE);
g_return_val_if_fail(
g_slist_find(otrg_fprint_verificators, verf) == NULL, FALSE);
otrg_fprint_verificators = g_slist_append(otrg_fprint_verificators, verf);
return TRUE;
}
static void
otrg_verificator_unregister_cb(OtrgFingerprintVerificator *verf)
{
if (verf == NULL)
return;
otrg_fprint_verificators = g_slist_remove(otrg_fprint_verificators, verf);
}
#endif
/* Send an IM from the given account to the given recipient. Display an
* error dialog if that account isn't currently logged in. */
void otrg_plugin_inject_message(PurpleAccount *account, const char *recipient,
......@@ -1526,6 +1561,22 @@ static gboolean otr_plugin_load(PurplePlugin *handle)
otrg_ui_update_fingerprint();
#if PURPLE_VERSION_CHECK(3,0,0)
/* the pointer at the end is a OtrgFingerprintVerificator */
purple_signal_register(handle, "otr-verificator-register",
purple_marshal_BOOLEAN__POINTER,
G_TYPE_BOOLEAN, 1, G_TYPE_POINTER);
/* the same as in otr-verificator-register */
purple_signal_register(handle, "otr-verificator-unregister",
purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
purple_signal_connect(handle, "otr-verificator-register", handle,
PURPLE_CALLBACK(otrg_verificator_register_cb), NULL);
purple_signal_connect(handle, "otr-verificator-unregister", handle,
PURPLE_CALLBACK(otrg_verificator_unregister_cb), NULL);
#endif
purple_signal_connect(core_handle, "quitting", otrg_plugin_handle,
PURPLE_CALLBACK(process_quitting), NULL);
purple_signal_connect(conv_handle, "sending-im-msg", otrg_plugin_handle,
......@@ -1605,6 +1656,11 @@ static gboolean otr_plugin_unload(PurplePlugin *handle)
purple_signal_disconnect(blist_handle, "blist-node-extended-menu",
otrg_plugin_handle, PURPLE_CALLBACK(supply_extended_menu));
#if PURPLE_VERSION_CHECK(3,0,0)
purple_signal_unregister(handle, "otr-verificator-register");
purple_signal_unregister(handle, "otr-verificator-unregister");
#endif
/* Stop the timer, if necessary */
stop_start_timer(0);
......
......@@ -36,6 +36,14 @@ extern PurplePlugin *otrg_plugin_handle;
extern OtrlUserState otrg_plugin_userstate;
#if PURPLE_VERSION_CHECK(3,0,0)
extern GSList *otrg_fprint_verificators;
#define OTRG_FPRINT_VERIFICATOR_HAS_FIELD(verf, member) \
(offsetof(OtrgFingerprintVerificator, member) < (verf)->struct_size && \
(verf)->member != NULL)
#endif
/* Given a PurpleConversation, return the ConnContext corresponding to the
* selected instance tag. */
ConnContext* otrg_plugin_conv_to_selected_context(PurpleConversation *conv,
......
......@@ -4,6 +4,7 @@ common.c
common.h
dialogs.c
dialogs.h
fprint-verificator.h
gtk-dialog.c
gtk-dialog.h
gtk-ui.c
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment