File: ui.c

package info (click to toggle)
pidgin-otr 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,408 kB
  • ctags: 565
  • sloc: sh: 11,542; ansic: 5,487; makefile: 35
file content (190 lines) | stat: -rw-r--r-- 4,903 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 *  Off-the-Record Messaging plugin for pidgin
 *  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
 */

/* config.h */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

/* system headers */
#include <stdlib.h>

/* purple headers */
#include "util.h"
#include "account.h"

#ifdef ENABLE_NLS
/* internationalisation header */
#include <glib/gi18n-lib.h>
#else
#define _(x) (x)
#define N_(x) (x)
#endif

/* libotr headers */
#include <libotr/privkey.h>
#include <libotr/proto.h>
#include <libotr/message.h>

/* purple-otr headers */
#include "ui.h"
#include "dialogs.h"
#include "otr-plugin.h"

static const OtrgUiUiOps *ui_ops = NULL;

/* Set the UI ops */
void otrg_ui_set_ui_ops(const OtrgUiUiOps *ops)
{
    ui_ops = ops;
}

/* Get the UI ops */
const OtrgUiUiOps *otrg_ui_get_ui_ops(void)
{
    return ui_ops;
}

/* Initialize the OTR UI subsystem */
void otrg_ui_init(void)
{
    if (ui_ops != NULL) {
	ui_ops->init();
    }
}

/* Deinitialize the OTR UI subsystem */
void otrg_ui_cleanup(void)
{
    if (ui_ops != NULL) {
	ui_ops->cleanup();
    }
}

/* Call this function when the DSA key is updated; it will redraw the
 * UI, if visible. */
void otrg_ui_update_fingerprint(void)
{
    if (ui_ops != NULL) {
	ui_ops->update_fingerprint();
    }
}

/* Update the keylist, if it's visible */
void otrg_ui_update_keylist(void)
{
    if (ui_ops != NULL) {
	ui_ops->update_keylist();
    }
}

/* Send an OTR Query Message to attempt to start a connection */
void otrg_ui_connect_connection(ConnContext *context)
{
    /* Send an OTR Query to the other side. */
    PurpleAccount *account;
    char *msg;

    /* Don't do this if we're already ENCRYPTED */
    if (context == NULL || context->msgstate == OTRL_MSGSTATE_ENCRYPTED)
	return;

    account = purple_accounts_find(context->accountname, context->protocol);
    if (!account) {
	PurplePlugin *p = purple_find_prpl(context->protocol);
	msg = g_strdup_printf(_("Account %s (%s) could not be found"),
		context->accountname,
		(p && p->info->name) ? p->info->name : _("Unknown"));
	otrg_dialog_notify_error(context->accountname, context->protocol,
		context->username, _("Account not found"), msg, NULL);
	g_free(msg);
	return;
    }
    otrg_plugin_send_default_query(context, account);
}

/* Drop a context to PLAINTEXT state */
void otrg_ui_disconnect_connection(ConnContext *context)
{

    if (context == NULL)
	return;

    otrg_plugin_disconnect(context);
    otrg_dialog_disconnected(context);
}

/* Forget a fingerprint */
void otrg_ui_forget_fingerprint(Fingerprint *fingerprint)
{
    ConnContext *context;
    ConnContext *context_iter;

    if (fingerprint == NULL) return;

    /* Don't do anything with the active fingerprint if we're in the
     * ENCRYPTED state. */
    context = fingerprint->context;

    for (context_iter = context->m_context;
	    context_iter && context_iter->m_context == context->m_context;
	    context_iter = context_iter->next) {

	if (context_iter->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
		context_iter->active_fingerprint == fingerprint) return;
    }

    otrl_context_forget_fingerprint(fingerprint, 1);
    otrg_plugin_write_fingerprints();

    otrg_ui_update_keylist();
}

/* Configure OTR for a particular buddy */
void otrg_ui_config_buddy(PurpleBuddy *buddy)
{
    if (ui_ops != NULL) {
	ui_ops->config_buddy(buddy);
    }
}

/* Load the preferences for a particular account / username */
void otrg_ui_get_prefs(OtrgUiPrefs *prefsp, PurpleAccount *account,
	const char *name)
{
    /* Check to see if the protocol for this account supports OTR at all. */
    const char *proto = purple_account_get_protocol_id(account);
    if (!otrg_plugin_proto_supports_otr(proto)) {
	prefsp->policy = OTRL_POLICY_NEVER;
	prefsp->avoid_logging_otr = TRUE;
	prefsp->show_otr_button = FALSE;
	return;
    }

    if (ui_ops != NULL) {
	ui_ops->get_prefs(prefsp, account, name);
	return;
    }
    /* If we've got no other way to get the prefs, use sensible defaults */
    prefsp->policy = OTRL_POLICY_DEFAULT;
    prefsp->avoid_logging_otr = TRUE;
    prefsp->show_otr_button = FALSE;
}