2
* Off-the-Record Messaging plugin for pidgin
3
* Copyright (C) 2004-2005 Nikita Borisov and Ian Goldberg
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of version 2 of the GNU General Public License as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
#include <libotr/privkey.h>
29
#include <libotr/proto.h>
30
#include <libotr/message.h>
32
/* purple-otr headers */
35
#include "otr-plugin.h"
37
static const OtrgUiUiOps *ui_ops = NULL;
40
void otrg_ui_set_ui_ops(const OtrgUiUiOps *ops)
46
const OtrgUiUiOps *otrg_ui_get_ui_ops(void)
51
/* Call this function when the DSA key is updated; it will redraw the
53
void otrg_ui_update_fingerprint(void)
56
ui_ops->update_fingerprint();
60
/* Update the keylist, if it's visible */
61
void otrg_ui_update_keylist(void)
64
ui_ops->update_keylist();
68
/* Send an OTR Query Message to attempt to start a connection */
69
void otrg_ui_connect_connection(ConnContext *context)
71
/* Send an OTR Query to the other side. */
72
PurpleAccount *account;
75
/* Don't do this if we're already ENCRYPTED */
76
if (context == NULL || context->msgstate == OTRL_MSGSTATE_ENCRYPTED)
79
account = purple_accounts_find(context->accountname, context->protocol);
81
PurplePlugin *p = purple_find_prpl(context->protocol);
82
msg = g_strdup_printf("Account %s (%s) could not be found",
84
(p && p->info->name) ? p->info->name : "Unknown");
85
otrg_dialog_notify_error(context->accountname, context->protocol,
86
context->username, "Account not found", msg, NULL);
90
otrg_plugin_send_default_query(context, account);
93
/* Drop a context to PLAINTEXT state */
94
void otrg_ui_disconnect_connection(ConnContext *context)
96
/* Don't do anything with PLAINTEXT fingerprints */
97
if (context == NULL || context->msgstate == OTRL_MSGSTATE_PLAINTEXT)
100
otrg_plugin_disconnect(context);
101
otrg_dialog_disconnected(context);
104
/* Forget a fingerprint */
105
void otrg_ui_forget_fingerprint(Fingerprint *fingerprint)
107
ConnContext *context;
109
if (fingerprint == NULL) return;
111
/* Don't do anything with the active fingerprint if we're in the
112
* ENCRYPTED state. */
113
context = fingerprint->context;
114
if (context->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
115
context->active_fingerprint == fingerprint) return;
117
otrl_context_forget_fingerprint(fingerprint, 1);
118
otrg_plugin_write_fingerprints();
120
otrg_ui_update_keylist();
123
/* Configure OTR for a particular buddy */
124
void otrg_ui_config_buddy(PurpleBuddy *buddy)
126
if (ui_ops != NULL) {
127
ui_ops->config_buddy(buddy);
131
/* Calculate the policy for a particular account / username */
132
OtrlPolicy otrg_ui_find_policy(PurpleAccount *account, const char *name)
134
/* Check to see if the protocol for this account supports OTR at all. */
135
const char *proto = purple_account_get_protocol_id(account);
136
if (!otrg_plugin_proto_supports_otr(proto)) {
137
return OTRL_POLICY_NEVER;
140
if (ui_ops != NULL) {
141
return ui_ops->find_policy(account, name);
143
return OTRL_POLICY_DEFAULT;