Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/otr.c @ 1577:e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
author | franky |
---|---|
date | Sun, 12 Apr 2009 20:20:56 +0200 |
parents | 24ff212a1c54 |
children | c8be6c2243d6 |
rev | line source |
---|---|
1299 | 1 /* |
1303
b6fdbfa6b219
Minor whitespace change
Mikael Berthe <mikael@lilotux.net>
parents:
1301
diff
changeset
|
2 * otr.c -- Off-The-Record Messaging for mcabber |
1299 | 3 * |
4 * Copyright (C) 2007 Frank Zschockelt <mcabber_otr@freakysoft.de> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
22 #include <config.h> | |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
23 #include <glib.h> |
1299 | 24 |
25 #ifdef HAVE_LIBOTR | |
26 | |
27 #include "otr.h" | |
28 #include "logprint.h" | |
29 #include "hbuf.h" | |
30 #include "jab_priv.h" | |
31 #include "roster.h" | |
32 #include "utils.h" | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
33 #include "screen.h" |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
34 #include "settings.h" |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
35 #include "nohtml.h" |
1299 | 36 |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
37 #define OTR_PROTOCOL_NAME "jabber" |
1299 | 38 |
39 static OtrlUserState userstate = NULL; | |
40 static char * account = NULL; | |
41 static char * keyfile = NULL; | |
42 static char * fprfile = NULL; | |
43 | |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
44 static int otr_is_enabled = FALSE; |
1299 | 45 |
46 static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx); | |
47 static void cb_create_privkey (void *opdata, | |
48 const char *accountname, | |
49 const char *protocol); | |
50 static int cb_is_logged_in (void *opdata, | |
51 const char *accountname, | |
52 const char *protocol, | |
53 const char *recipient); | |
54 static void cb_inject_message (void *opdata, | |
55 const char *accountname, | |
56 const char *protocol, | |
57 const char *recipient, | |
58 const char *message); | |
59 static void cb_notify (void *opdata, | |
60 OtrlNotifyLevel level, | |
61 const char *accountname, | |
62 const char *protocol, | |
63 const char *username, | |
64 const char *title, | |
65 const char *primary, | |
66 const char *secondary); | |
67 static int cb_display_otr_message(void *opdata, | |
68 const char *accountname, | |
69 const char *protocol, | |
70 const char *username, | |
71 const char *msg); | |
72 static void cb_update_context_list(void *opdata); | |
73 static const char *cb_protocol_name (void *opdata, const char *protocol); | |
74 static void cb_protocol_name_free (void *opdata, | |
75 const char *protocol_name); | |
76 static void cb_new_fingerprint (void *opdata, OtrlUserState us, | |
77 const char *accountname, | |
78 const char *protocol, | |
79 const char *username, | |
80 unsigned char fingerprint[20]); | |
81 static void cb_write_fingerprints (void *opdata); | |
82 static void cb_gone_secure (void *opdata, ConnContext *context); | |
83 static void cb_gone_insecure (void *opdata, ConnContext *context); | |
84 static void cb_still_secure (void *opdata, ConnContext *context, | |
85 int is_reply); | |
86 static void cb_log_message (void *opdata, const char *message); | |
87 static int cb_max_message_size (void *opdata, ConnContext *context); | |
88 | |
89 static OtrlMessageAppOps ops = | |
90 { | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
91 cb_policy, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
92 cb_create_privkey, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
93 cb_is_logged_in, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
94 cb_inject_message, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
95 cb_notify, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
96 cb_display_otr_message, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
97 cb_update_context_list, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
98 cb_protocol_name, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
99 cb_protocol_name_free, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
100 cb_new_fingerprint, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
101 cb_write_fingerprints, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
102 cb_gone_secure, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
103 cb_gone_insecure, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
104 cb_still_secure, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
105 cb_log_message, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
106 cb_max_message_size, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
107 NULL, /*account_name*/ |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
108 NULL /*account_name_free*/ |
1299 | 109 }; |
110 | |
111 static void otr_message_disconnect(ConnContext *ctx); | |
112 static ConnContext * otr_get_context(const char *buddy); | |
113 static void otr_startstop(const char * buddy, int start); | |
114 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx); | |
115 | |
1320 | 116 static char * otr_get_dir(void); |
1299 | 117 |
1420
08f641e91f94
Do not use "jid" as a variable name
Mikael Berthe <mikael@lilotux.net>
parents:
1347
diff
changeset
|
118 void otr_init(const char *fjid) |
1299 | 119 { |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
120 char *root; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
121 |
1501 | 122 if (userstate) //already initialised |
123 return; | |
124 | |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
125 otr_is_enabled = !!settings_opt_get_int("otr"); |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
126 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
127 if (!otr_is_enabled) |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
128 return; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
129 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
130 OTRL_INIT; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
131 |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
132 userstate = otrl_userstate_create(); |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
133 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
134 root = otr_get_dir(); |
1420
08f641e91f94
Do not use "jid" as a variable name
Mikael Berthe <mikael@lilotux.net>
parents:
1347
diff
changeset
|
135 account = jidtodisp(fjid); |
1299 | 136 keyfile = g_strdup_printf("%s%s.key", root, account); |
137 fprfile = g_strdup_printf("%s%s.fpr", root, account); | |
138 g_free(root); | |
139 | |
140 if (otrl_privkey_read(userstate, keyfile)){ | |
141 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile); | |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
142 cb_create_privkey(NULL, account, OTR_PROTOCOL_NAME); |
1299 | 143 } |
144 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){ | |
145 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s", | |
146 fprfile); | |
147 } | |
148 } | |
149 | |
150 void otr_terminate(void) | |
151 { | |
152 ConnContext * ctx; | |
153 | |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
154 if (!otr_is_enabled) |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
155 return; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
156 |
1320 | 157 for (ctx = userstate->context_root; ctx; ctx = ctx->next) |
1299 | 158 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) |
159 otr_message_disconnect(ctx); | |
160 | |
161 g_free(account); | |
162 account = NULL; | |
1307
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
163 |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
164 /* XXX This #ifdef is a quick workaround: when mcabber |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
165 * is linked to both gnutls and libotr, libgcrypt will |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
166 * segfault when we call otrl_userstate_free(). |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
167 * This is reported to be a bug in libgcrypt :-/ |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
168 * Mikael |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
169 */ |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
170 #if defined(HAVE_GNUTLS) && !defined(HAVE_OPENSSL) |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
171 if (!settings_opt_get_int("ssl")) |
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
172 #endif |
1299 | 173 otrl_userstate_free(userstate); |
1307
6c116207ab2e
Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
174 |
1299 | 175 userstate = NULL; |
176 g_free(keyfile); | |
177 keyfile = NULL; | |
178 } | |
179 | |
1320 | 180 static char * otr_get_dir(void) |
181 { | |
1346 | 182 const char *configured_dir = settings_opt_get("otr_dir"); |
1320 | 183 |
1335
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
184 if (configured_dir && *configured_dir) { |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
185 char *xp_conf_dir; |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
186 int l; |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
187 xp_conf_dir = expand_filename(configured_dir); |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
188 // The path must be slash-terminated |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
189 l = strlen(xp_conf_dir); |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
190 if (xp_conf_dir[l-1] != '/') { |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
191 char *xp_conf_dir_tmp = xp_conf_dir; |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
192 xp_conf_dir = g_strdup_printf("%s/", xp_conf_dir_tmp); |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
193 g_free(xp_conf_dir_tmp); |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
194 } |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
195 return xp_conf_dir; |
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
196 } else { |
1320 | 197 return expand_filename("~/.mcabber/otr/"); |
1335
ab1b7f7a682e
Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents:
1320
diff
changeset
|
198 } |
1320 | 199 } |
200 | |
1299 | 201 static ConnContext * otr_get_context(const char *buddy) |
202 { | |
203 int null = 0; | |
1495
6f5754f86fbb
Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1470
diff
changeset
|
204 ConnContext * ctx; |
6f5754f86fbb
Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1470
diff
changeset
|
205 char * lowcasebuddy = g_strdup(buddy); |
6f5754f86fbb
Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1470
diff
changeset
|
206 |
6f5754f86fbb
Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1470
diff
changeset
|
207 mc_strtolower(lowcasebuddy); |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
208 ctx = otrl_context_find(userstate, lowcasebuddy, account, OTR_PROTOCOL_NAME, |
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
209 1, &null, NULL, NULL); |
1495
6f5754f86fbb
Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1470
diff
changeset
|
210 g_free(lowcasebuddy); |
6f5754f86fbb
Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1470
diff
changeset
|
211 return ctx; |
1299 | 212 } |
213 | |
214 static void otr_message_disconnect(ConnContext *ctx) | |
215 { | |
216 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | |
217 cb_gone_insecure(NULL, ctx); | |
218 otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname, | |
219 ctx->protocol, ctx->username); | |
220 } | |
221 | |
222 static void otr_startstop(const char * buddy, int start) | |
223 { | |
224 char * msg = NULL; | |
225 ConnContext *ctx = otr_get_context(buddy); | |
226 | |
227 if (!userstate || !ctx) | |
228 return; | |
229 | |
230 if (start && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | |
231 otr_message_disconnect(ctx); | |
232 | |
233 if (start) { | |
234 OtrlPolicy policy = cb_policy(NULL, ctx); | |
1308
b17754d9221b
Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents:
1307
diff
changeset
|
235 if (policy == plain) { |
b17754d9221b
Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents:
1307
diff
changeset
|
236 scr_LogPrint(LPRINT_LOGNORM, "The OTR policy for this user is set to" |
b17754d9221b
Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents:
1307
diff
changeset
|
237 " plain. You have to change it first."); |
b17754d9221b
Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents:
1307
diff
changeset
|
238 return; |
b17754d9221b
Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents:
1307
diff
changeset
|
239 } |
1299 | 240 msg = otrl_proto_default_query_msg(ctx->accountname, policy); |
241 cb_inject_message(NULL, ctx->accountname, ctx->protocol, ctx->username, | |
242 msg); | |
243 free (msg); | |
244 } | |
245 else | |
246 otr_message_disconnect(ctx); | |
247 } | |
248 | |
249 void otr_establish(const char *buddy) | |
250 { | |
251 otr_startstop(buddy, 1); | |
252 } | |
253 | |
254 void otr_disconnect(const char * buddy) | |
255 { | |
256 otr_startstop(buddy, 0); | |
257 } | |
258 | |
259 void otr_fingerprint(const char * buddy, const char * trust) | |
260 { | |
261 char fpr[45], *tr; | |
262 ConnContext *ctx = otr_get_context(buddy); | |
263 if (!userstate || !ctx) | |
264 return; | |
265 | |
266 if (!ctx->active_fingerprint || !ctx->active_fingerprint->fingerprint) { | |
267 scr_LogPrint(LPRINT_LOGNORM, | |
268 "No active fingerprint - start OTR for this buddy first."); | |
269 return; | |
270 } | |
271 | |
272 otrl_privkey_hash_to_human(fpr, ctx->active_fingerprint->fingerprint); | |
273 if (trust) { | |
274 if (strcmp(fpr, trust) == 0) | |
275 otrl_context_set_trust(ctx->active_fingerprint, "trust"); | |
276 else | |
277 otrl_context_set_trust(ctx->active_fingerprint, NULL); | |
278 } | |
279 | |
280 tr = ctx->active_fingerprint->trust; | |
281 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr, | |
282 tr && *tr ? "trusted" : "untrusted"); | |
283 cb_write_fingerprints(NULL); | |
284 } | |
285 | |
286 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx) | |
287 { | |
288 OtrlTLV *tlv = NULL; | |
289 char *sbuf = NULL; | |
290 NextExpectedSMP nextMsg = ctx->smstate->nextExpected; | |
291 | |
292 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); | |
293 if (tlv) { | |
294 if (nextMsg != OTRL_SMP_EXPECT1) | |
295 otr_smp_abort(ctx->username); | |
296 else { | |
297 sbuf = g_strdup_printf("OTR: Received SMP Initiation. " | |
298 "Answer with /otr smpr %s $secret", | |
299 ctx->username); | |
300 } | |
301 } | |
302 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2); | |
303 if (tlv) { | |
304 if (nextMsg != OTRL_SMP_EXPECT2) | |
305 otr_smp_abort(ctx->username); | |
306 else { | |
307 sbuf = g_strdup("OTR: Received SMP Response."); | |
308 /* If we received TLV2, we will send TLV3 and expect TLV4 */ | |
309 ctx->smstate->nextExpected = OTRL_SMP_EXPECT4; | |
310 } | |
311 } | |
312 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3); | |
313 if (tlv) { | |
314 if (nextMsg != OTRL_SMP_EXPECT3) | |
315 otr_smp_abort(ctx->username); | |
316 else { | |
317 /* If we received TLV3, we will send TLV4 | |
318 * We will not expect more messages, so prepare for next SMP */ | |
319 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1; | |
320 /* Report result to user */ | |
321 if (ctx->active_fingerprint && ctx->active_fingerprint->trust && | |
322 *ctx->active_fingerprint->trust != '\0') | |
323 sbuf = g_strdup("OTR: SMP succeeded"); | |
324 else | |
325 sbuf = g_strdup("OTR: SMP failed"); | |
326 } | |
327 } | |
328 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4); | |
329 if (tlv) { | |
330 if (nextMsg != OTRL_SMP_EXPECT4) | |
331 otr_smp_abort(ctx->username); | |
332 else { | |
333 /* We will not expect more messages, so prepare for next SMP */ | |
334 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1; | |
335 /* Report result to user */ | |
336 if (ctx->active_fingerprint && ctx->active_fingerprint->trust && | |
337 *ctx->active_fingerprint->trust != '\0') | |
338 sbuf = g_strdup("OTR: SMP succeeded"); | |
339 else | |
340 sbuf = g_strdup("OTR: SMP failed"); | |
341 } | |
342 } | |
343 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); | |
344 if (tlv) { | |
345 /* The message we are waiting for will not arrive, so reset | |
346 * and prepare for the next SMP */ | |
347 sbuf = g_strdup("OTR: SMP aborted by your buddy"); | |
348 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1; | |
349 } | |
350 | |
351 if (sbuf) { | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
352 scr_WriteIncomingMessage(ctx->username, sbuf, 0, HBB_PREFIX_INFO, 0); |
1299 | 353 g_free(sbuf); |
354 } | |
355 } | |
356 | |
357 /* | |
358 * returns whether a otr_message was received | |
359 * sets *otr_data to NULL, when it was an internal otr message | |
360 */ | |
361 int otr_receive(char **otr_data, const char * buddy, int * free_msg) | |
362 { | |
363 int ignore_message; | |
364 char *newmessage = NULL; | |
365 OtrlTLV *tlvs = NULL; | |
366 OtrlTLV *tlv = NULL; | |
367 ConnContext * ctx; | |
368 | |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
369 ctx = otr_get_context(buddy); |
1299 | 370 *free_msg = 0; |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
371 ignore_message = otrl_message_receiving(userstate, &ops, NULL, |
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
372 ctx->accountname, ctx->protocol, |
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
373 ctx->username, *otr_data, |
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
374 &newmessage, &tlvs,NULL, NULL); |
1299 | 375 |
376 | |
377 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); | |
378 if (tlv) { | |
379 /* Notify the user that the other side disconnected. */ | |
380 if (ctx) { | |
381 cb_gone_insecure(NULL, ctx); | |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
382 otr_disconnect(ctx->username); |
1299 | 383 } |
384 } | |
385 | |
386 otr_handle_smp_tlvs(tlvs, ctx); | |
387 | |
388 if (tlvs != NULL) | |
389 otrl_tlv_free(tlvs); | |
390 | |
391 if (ignore_message) | |
392 *otr_data = NULL; | |
393 | |
394 if (!ignore_message && newmessage) { | |
395 *free_msg = 1; | |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
396 *otr_data = html_strip(newmessage); |
1299 | 397 otrl_message_free(newmessage); |
398 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | |
399 return 1; | |
400 } | |
401 return 0; | |
402 } | |
403 | |
404 int otr_send(char **msg, const char *buddy) | |
405 { | |
406 gcry_error_t err; | |
407 char *newmessage = NULL; | |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
408 char *htmlmsg; |
1299 | 409 ConnContext * ctx = otr_get_context(buddy); |
410 | |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
411 htmlmsg = html_escape(*msg); |
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
412 |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
413 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, |
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
414 ctx->protocol, ctx->username, htmlmsg, NULL, |
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
415 &newmessage, NULL, NULL); |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
416 |
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
417 g_free(htmlmsg); |
1299 | 418 |
419 if (err) | |
420 *msg = NULL; /*something went wrong, don't send the plain-message! */ | |
421 | |
422 if (!err && newmessage) { | |
423 *msg = g_strdup(newmessage); | |
424 otrl_message_free(newmessage); | |
425 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION || | |
426 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | |
427 return 1; | |
428 } | |
429 return 0; | |
430 } | |
431 | |
432 /* Prints OTR connection state */ | |
433 void otr_print_info(const char * buddy) | |
434 { | |
435 const char *state, *auth, *policy; | |
436 ConnContext * ctx = otr_get_context(buddy); | |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
437 OtrlPolicy p = cb_policy(ctx->app_data, ctx); |
1299 | 438 |
439 if (!userstate || !ctx) | |
440 return; | |
441 | |
442 switch (ctx->msgstate) { | |
443 case OTRL_MSGSTATE_PLAINTEXT: state = "plaintext"; break; | |
444 case OTRL_MSGSTATE_ENCRYPTED: | |
445 switch (ctx->protocol_version) { | |
446 case 1: state = "encrypted V1"; break; | |
447 case 2: state = "encrypted V2"; break; | |
448 default:state = "encrypted"; | |
449 }; | |
450 break; | |
451 case OTRL_MSGSTATE_FINISHED: state = "finished"; break; | |
452 default: state = "unknown state"; | |
453 } | |
454 switch (ctx->auth.authstate) { | |
455 case OTRL_AUTHSTATE_NONE: | |
456 switch (ctx->otr_offer) { | |
457 case OFFER_NOT: auth = "no offer sent"; break; | |
458 case OFFER_SENT: auth = "offer sent"; break; | |
459 case OFFER_ACCEPTED: auth = "offer accepted"; break; | |
460 case OFFER_REJECTED: auth = "offer rejected"; break; | |
461 default: auth = "unknown auth"; | |
462 } | |
463 break; | |
464 case OTRL_AUTHSTATE_AWAITING_DHKEY: | |
465 auth = "awaiting D-H key"; break; | |
466 case OTRL_AUTHSTATE_AWAITING_REVEALSIG: | |
467 auth = "awaiting reveal signature"; break; | |
468 case OTRL_AUTHSTATE_AWAITING_SIG: | |
469 auth = "awaiting signature"; break; | |
470 case OTRL_AUTHSTATE_V1_SETUP: | |
471 auth = "v1 setup"; break; | |
472 default: | |
473 auth = "unknown auth"; | |
474 } | |
475 if (p == OTRL_POLICY_NEVER) | |
476 policy = "plain"; | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
477 else if (p == (OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1)) |
1299 | 478 policy = "opportunistic"; |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
479 else if (p == (OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1)) |
1299 | 480 policy = "manual"; |
481 else if (p == (OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1)) | |
482 policy = "always"; | |
483 else | |
484 policy = "unknown"; | |
485 | |
486 scr_LogPrint(LPRINT_LOGNORM, "%s: %s (%s) [%s]", | |
487 ctx->username, state, auth, policy); | |
488 } | |
489 | |
490 static ConnContext * otr_context_encrypted(const char * buddy) | |
491 { | |
492 ConnContext * ctx = otr_get_context(buddy); | |
493 | |
494 if (!userstate || !ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED){ | |
495 scr_LogPrint(LPRINT_LOGNORM, | |
496 "You have to start an OTR channel with %s before you can " | |
497 "use SMP.", buddy); | |
498 return NULL; | |
499 } | |
500 | |
501 return ctx; | |
502 } | |
503 | |
504 void otr_smp_query(const char * buddy, const char * secret) | |
505 { | |
506 ConnContext * ctx = otr_context_encrypted(buddy); | |
507 | |
508 if (!secret) { | |
509 scr_LogPrint(LPRINT_LOGNORM, | |
510 "Using SMP without a secret isn't a good idea."); | |
511 return; | |
512 } | |
513 | |
514 if (ctx) { | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
515 otrl_message_initiate_smp(userstate, &ops, NULL, ctx, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
516 (const unsigned char *)secret, |
1299 | 517 strlen(secret)); |
518 scr_WriteIncomingMessage(ctx->username, | |
519 "OTR: Socialist Millionaires' Protocol " | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
520 "initiated.", 0, HBB_PREFIX_INFO, 0); |
1299 | 521 } |
522 } | |
523 | |
524 void otr_smp_respond(const char * buddy, const char * secret) | |
525 { | |
526 ConnContext * ctx = otr_context_encrypted(buddy); | |
527 | |
528 if (!secret) { | |
529 scr_LogPrint(LPRINT_LOGNORM, | |
530 "Using SMP without a secret isn't a good idea."); | |
531 return; | |
532 } | |
533 | |
534 if (ctx) { | |
535 if (!ctx->smstate->secret) { | |
536 scr_LogPrint(LPRINT_LOGNORM, | |
537 "Don't call smpr before you haven't received an SMP " | |
538 "Initiation!"); | |
539 return; | |
540 } | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
541 otrl_message_respond_smp(userstate, &ops, NULL, ctx, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
542 (const unsigned char *)secret, |
1299 | 543 strlen(secret)); |
544 scr_WriteIncomingMessage(ctx->username, | |
545 "OTR: Socialist Millionaires' Protocol: " | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
546 "response sent", 0, HBB_PREFIX_INFO, 0); |
1299 | 547 } |
548 } | |
549 | |
550 void otr_smp_abort(const char * buddy) | |
551 { | |
552 ConnContext * ctx = otr_context_encrypted(buddy); | |
553 | |
554 if (ctx) { | |
555 otrl_message_abort_smp(userstate, &ops, NULL, ctx); | |
556 scr_WriteIncomingMessage(ctx->username, | |
557 "OTR: Socialist Millionaires' Protocol aborted.", | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
558 0, HBB_PREFIX_INFO, 0); |
1299 | 559 } |
560 } | |
561 | |
562 void otr_key(void) | |
563 { | |
564 OtrlPrivKey * key; | |
565 char readable[45] = ""; | |
566 | |
567 if(!userstate) | |
568 return; | |
569 for (key = userstate->privkey_root; key; key = key->next) { | |
570 otrl_privkey_fingerprint(userstate, readable, key->accountname, | |
571 key->protocol); | |
572 scr_LogPrint(LPRINT_LOGNORM, "%s: %s", key->accountname, readable); | |
573 } | |
574 } | |
575 | |
576 /* Return the OTR policy for the given context. */ | |
577 static OtrlPolicy cb_policy(void *opdata, ConnContext *ctx) | |
578 { | |
579 enum otr_policy p = settings_otr_getpolicy(NULL); | |
580 | |
581 if(ctx) | |
582 if(settings_otr_getpolicy(ctx->username)) | |
583 p = settings_otr_getpolicy(ctx->username); | |
584 | |
585 switch (p) { | |
586 case plain: | |
587 return OTRL_POLICY_NEVER; | |
588 case opportunistic: | |
589 return OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1; | |
590 case manual: | |
591 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1; | |
592 case always: | |
593 return OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1; | |
594 } | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
595 |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
596 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1; |
1299 | 597 } |
598 | |
599 /* Create a private key for the given accountname/protocol if | |
600 * desired. */ | |
601 static void cb_create_privkey(void *opdata, const char *accountname, | |
602 const char *protocol) | |
603 { | |
604 gcry_error_t e; | |
1320 | 605 char * root; |
1299 | 606 |
607 scr_LogPrint(LPRINT_LOGNORM, | |
608 "Generating new OTR key for %s. This may take a while...", | |
609 accountname); | |
610 scr_DoUpdate(); | |
611 | |
612 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol); | |
613 | |
1320 | 614 if (e) { |
615 root = otr_get_dir(); | |
616 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed! Please mkdir " | |
617 "%s if you want to use otr encryption.", root); | |
618 g_free(root); | |
619 } | |
1299 | 620 else |
621 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated."); | |
622 } | |
623 | |
624 /* Report whether you think the given user is online. Return 1 if | |
625 * you think he is, 0 if you think he isn't, -1 if you're not sure. | |
626 * If you return 1, messages such as heartbeats or other | |
627 * notifications may be sent to the user, which could result in "not | |
628 * logged in" errors if you're wrong. */ | |
629 static int cb_is_logged_in(void *opdata, const char *accountname, | |
630 const char *protocol, const char *recipient) | |
631 { | |
1346 | 632 int ret = (roster_getstatus(recipient, NULL) != offline); |
1299 | 633 return ret; |
634 } | |
635 | |
636 /* Send the given IM to the given recipient from the given | |
637 * accountname/protocol. */ | |
638 static void cb_inject_message(void *opdata, const char *accountname, | |
639 const char *protocol, const char *recipient, | |
640 const char *message) | |
641 { | |
642 char * id = g_strdup("otrinject"); | |
1343 | 643 if (roster_gettype(recipient) == ROSTER_TYPE_USER) |
644 jb_send_msg(recipient, message, ROSTER_TYPE_USER, "", id, NULL, NULL); | |
1299 | 645 g_free(id); |
646 } | |
647 | |
648 /* Display a notification message for a particular | |
649 * accountname / protocol / username conversation. */ | |
650 static void cb_notify(void *opdata, OtrlNotifyLevel level, | |
651 const char *accountname, const char *protocol, | |
652 const char *username, const char *title, | |
653 const char *primary, const char *secondary) | |
654 { | |
655 char * type; | |
656 char *sbuf = NULL; | |
657 switch (level) { | |
658 case OTRL_NOTIFY_ERROR: type = "error"; break; | |
659 case OTRL_NOTIFY_WARNING: type = "warning"; break; | |
660 case OTRL_NOTIFY_INFO: type = "info"; break; | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
661 default: type = "unknown"; |
1299 | 662 } |
663 sbuf = g_strdup_printf("OTR %s:%s\n%s\n%s",type,title, primary, secondary); | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
664 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0); |
1299 | 665 g_free(sbuf); |
666 } | |
667 | |
668 /* Display an OTR control message for a particular | |
669 * accountname / protocol / username conversation. Return 0 if you are able | |
670 * to successfully display it. If you return non-0 (or if this | |
671 * function is NULL), the control message will be displayed inline, | |
672 * as a received message, or else by using the above notify() | |
673 * callback. */ | |
674 static int cb_display_otr_message(void *opdata, const char *accountname, | |
675 const char *protocol, const char *username, | |
676 const char *msg) | |
677 { | |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
678 char *strippedmsg = html_strip(msg); |
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
679 scr_WriteIncomingMessage(username, strippedmsg, 0, HBB_PREFIX_INFO, 0); |
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
680 g_free(strippedmsg); |
1299 | 681 return 0; |
682 } | |
683 | |
684 /* When the list of ConnContexts changes (including a change in | |
685 * state), this is called so the UI can be updated. */ | |
686 static void cb_update_context_list(void *opdata) | |
687 { | |
688 /*maybe introduce new status characters for mcabber, | |
689 * then use this function (?!)*/ | |
690 } | |
691 | |
692 /* Return a newly allocated string containing a human-friendly name | |
693 * for the given protocol id */ | |
694 static const char *cb_protocol_name(void *opdata, const char *protocol) | |
695 { | |
696 return protocol; | |
697 } | |
698 | |
699 /* Deallocate a string allocated by protocol_name */ | |
700 static void cb_protocol_name_free (void *opdata, const char *protocol_name) | |
701 { | |
702 /* We didn't allocated memory, so we don't have to free anything :p */ | |
703 } | |
704 | |
705 /* A new fingerprint for the given user has been received. */ | |
706 static void cb_new_fingerprint(void *opdata, OtrlUserState us, | |
707 const char *accountname, const char *protocol, | |
708 const char *username, | |
709 unsigned char fingerprint[20]) | |
710 { | |
711 char *sbuf = NULL; | |
712 char readable[45]; | |
713 | |
714 otrl_privkey_hash_to_human(readable, fingerprint); | |
715 sbuf = g_strdup_printf("OTR: new fingerprint: %s", readable); | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
716 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0); |
1299 | 717 g_free(sbuf); |
718 } | |
719 | |
720 /* The list of known fingerprints has changed. Write them to disk. */ | |
721 static void cb_write_fingerprints(void *opdata) | |
722 { | |
723 otrl_privkey_write_fingerprints(userstate, fprfile); | |
724 } | |
725 | |
726 /* A ConnContext has entered a secure state. */ | |
727 static void cb_gone_secure(void *opdata, ConnContext *context) | |
728 { | |
729 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0, | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
730 HBB_PREFIX_INFO, 0); |
1299 | 731 } |
732 | |
733 /* A ConnContext has left a secure state. */ | |
734 static void cb_gone_insecure(void *opdata, ConnContext *context) | |
735 { | |
736 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0, | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
737 HBB_PREFIX_INFO, 0); |
1299 | 738 } |
739 | |
740 /* We have completed an authentication, using the D-H keys we | |
741 * already knew. is_reply indicates whether we initiated the AKE. */ | |
742 static void cb_still_secure(void *opdata, ConnContext *context, int is_reply) | |
743 { | |
744 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0, | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
745 HBB_PREFIX_INFO, 0); |
1299 | 746 } |
747 | |
748 /* Log a message. The passed message will end in "\n". */ | |
749 static void cb_log_message(void *opdata, const char *message) | |
750 { | |
751 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message); | |
752 } | |
753 | |
754 /* Find the maximum message size supported by this protocol. */ | |
755 static int cb_max_message_size(void *opdata, ConnContext *context) | |
756 { | |
757 return 8192; | |
758 } | |
759 | |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
760 int otr_enabled(void) |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
761 { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
762 return otr_is_enabled; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
763 } |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
764 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
765 #else /* !HAVE_LIBOTR */ |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
766 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
767 int otr_enabled(void) |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
768 { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
769 return FALSE; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
770 } |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
771 |
1299 | 772 #endif /* HAVE_LIBOTR */ |
773 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |