annotate mcabber/mcabber/otr.c @ 2213:0c78d31c753d

Change otr_send() prototype This patch updates otr_send() in order to differenciate original and encrypted messages. It should also fix a memory leak of OTR-encrypted messages.
author Mikael Berthe <mikael@lilotux.net>
date Thu, 05 Nov 2015 19:46:09 +0100
parents 9fb1ccf291cc
children ba1a770dd632
rev   line source
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
3 *
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
4 * Copyright (C) 2007-2009 Frank Zschockelt <mcabber_otr@freakysoft.de>
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
5 *
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
9 * your option) any later version.
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
10 *
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
14 * General Public License for more details.
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
15 *
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
19 * USA
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
20 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
21
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
24
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
25 #ifdef HAVE_LIBOTR
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
26
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
27 #include "hbuf.h"
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
28 #include "logprint.h"
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
29 #include "nohtml.h"
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
30 #include "otr.h"
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
31 #include "roster.h"
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
32 #include "screen.h"
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
33 #include "settings.h"
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
34 #include "utils.h"
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
35 #include "xmpp.h"
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
38
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
39 static OtrlUserState userstate = NULL;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
40 static char *account = NULL;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
41 static char *keyfile = NULL;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
42 static char *fprfile = NULL;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
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
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
45
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
46 static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
47 static void cb_create_privkey (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
48 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
49 const char *protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
50 static int cb_is_logged_in (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
51 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
52 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
53 const char *recipient);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
54 static void cb_inject_message (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
55 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
56 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
57 const char *recipient,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
58 const char *message);
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
59 static void cb_update_context_list(void *opdata);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
60 static void cb_new_fingerprint (void *opdata, OtrlUserState us,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
61 const char *accountname,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
62 const char *protocol,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
63 const char *username,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
64 unsigned char fingerprint[20]);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
65 static void cb_write_fingerprints (void *opdata);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
66 static void cb_gone_secure (void *opdata, ConnContext *context);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
67 static void cb_gone_insecure (void *opdata, ConnContext *context);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
68 static void cb_still_secure (void *opdata, ConnContext *context,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
69 int is_reply);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
70 static int cb_max_message_size (void *opdata, ConnContext *context);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
71
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
72 #ifdef HAVE_LIBOTR3
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
73 static void cb_notify (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
74 OtrlNotifyLevel level,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
75 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
76 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
77 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
78 const char *title,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
79 const char *primary,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
80 const char *secondary);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
81 static int cb_display_otr_message(void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
82 const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
83 const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
84 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
85 const char *msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
86 static const char *cb_protocol_name (void *opdata, const char *protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
87 static void cb_protocol_name_free (void *opdata,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
88 const char *protocol_name);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
89 static void cb_log_message (void *opdata, const char *message);
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
90
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
91 static void otr_handle_smp_tlvs (OtrlTLV *tlvs, ConnContext *ctx);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
92 #else /* HAVE_LIBOTR3 */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
93 static char *tagfile = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
94 static guint otr_timer_source = 0;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
95
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
96 static void cb_handle_smp_event (void *opdata, OtrlSMPEvent event,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
97 ConnContext *context, unsigned short percent,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
98 char *question);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
99 static void cb_handle_msg_event (void *opdata, OtrlMessageEvent event,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
100 ConnContext *context, const char *message,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
101 gcry_error_t err);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
102 static void cb_create_instag (void *opdata, const char *accountname,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
103 const char *protocol);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
104 static void cb_timer_control (void *opdata, unsigned int interval);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
105 #endif /* HAVE_LIBOTR3 */
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
106
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
107 static OtrlMessageAppOps ops =
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
108 {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
109 cb_policy,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
110 cb_create_privkey,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
111 cb_is_logged_in,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
112 cb_inject_message,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
113 #ifdef HAVE_LIBOTR3
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
114 cb_notify,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
115 cb_display_otr_message,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
116 #endif
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
117 cb_update_context_list,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
118 #ifdef HAVE_LIBOTR3
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
119 cb_protocol_name,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
120 cb_protocol_name_free,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
121 #endif
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
122 cb_new_fingerprint,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
123 cb_write_fingerprints,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
124 cb_gone_secure,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
125 cb_gone_insecure,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
126 cb_still_secure,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
127 #ifdef HAVE_LIBOTR3
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
128 cb_log_message,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
129 #endif
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
130 cb_max_message_size,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
131 NULL, /* account_name */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
132 NULL, /* account_name_free */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
133 #ifndef HAVE_LIBOTR3
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
134 NULL, /* received_symkey */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
135 NULL, /* otr_error_message */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
136 NULL, /* otr_error_message_free */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
137 NULL, /* resent_msg_prefix */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
138 NULL, /* resent_msg_prefix_free */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
139 cb_handle_smp_event,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
140 cb_handle_msg_event,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
141 cb_create_instag,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
142 NULL, /* convert_msg */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
143 NULL, /* convert_free */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
144 cb_timer_control,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
145 #endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
146 };
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
147
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
148 static void otr_message_disconnect(ConnContext *ctx);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
149 static ConnContext *otr_get_context(const char *buddy);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
150 static void otr_startstop(const char *buddy, int start);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
151
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
152 static char *otr_get_dir(void);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
153
1420
08f641e91f94 Do not use "jid" as a variable name
Mikael Berthe <mikael@lilotux.net>
parents: 1347
diff changeset
154 void otr_init(const char *fjid)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
155 {
1347
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
156 char *root;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
157
1729
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1668
diff changeset
158 if (userstate) // already initialised
1501
24ff212a1c54 Fixed a memleak in otr
franky@veqlargh.fs
parents: 1495
diff changeset
159 return;
24ff212a1c54 Fixed a memleak in otr
franky@veqlargh.fs
parents: 1495
diff changeset
160
1347
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
161 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
162
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
163 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
164 return;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
165
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
166 OTRL_INIT;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
167
1577
e1a642472f4e Use otr context where possible, saves one mc_strtolower() per received message
franky
parents: 1501
diff changeset
168 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
169
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
170 root = otr_get_dir();
1420
08f641e91f94 Do not use "jid" as a variable name
Mikael Berthe <mikael@lilotux.net>
parents: 1347
diff changeset
171 account = jidtodisp(fjid);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
172 keyfile = g_strdup_printf("%s%s.key", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
173 fprfile = g_strdup_printf("%s%s.fpr", root, account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
174
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
175 if (otrl_privkey_read(userstate, keyfile)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
176 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
177 cb_create_privkey(NULL, account, OTR_PROTOCOL_NAME);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
178 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
179 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
180 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
181 fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
182 }
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
183 #ifndef HAVE_LIBOTR3
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
184 tagfile = g_strdup_printf("%s%s.tag", root, account);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
185 if (otrl_instag_read(userstate, tagfile)) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
186 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR instance tag from %s", tagfile);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
187 cb_create_instag(NULL, account, OTR_PROTOCOL_NAME);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
188 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
189 #endif
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
190 g_free(root);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
191 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
192
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
193 void otr_terminate(void)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
194 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
195 ConnContext *ctx;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
196
1347
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
197 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
198 return;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
199
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
200 #ifndef HAVE_LIBOTR3
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
201 if (otr_timer_source > 0) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
202 g_source_remove (otr_timer_source);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
203 otr_timer_source = 0;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
204 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
205 #endif
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
206
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
207 for (ctx = userstate->context_root; ctx; ctx = ctx->next)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
208 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
209 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
210
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
211 g_free(account);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
212 account = NULL;
1307
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
213
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
214 /* 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
215 * 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
216 * segfault when we call otrl_userstate_free().
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
217 * 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
218 * Mikael
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
219 */
1729
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1668
diff changeset
220 #if defined(HAVE_GNUTLS) && !defined(HAVE_OPENSSL) // TODO: broken now
1307
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
221 if (!settings_opt_get_int("ssl"))
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
222 #endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
223 otrl_userstate_free(userstate);
1307
6c116207ab2e Work around segfault in otrl_userstate_free()
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
224
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
225 userstate = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
226 g_free(keyfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
227 keyfile = NULL;
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
228 g_free(fprfile);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
229 fprfile = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
230 #ifndef HAVE_LIBOTR3
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
231 g_free(tagfile);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
232 tagfile = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
233 #endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
234 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
235
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
236 static char *otr_get_dir(void)
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
237 {
1346
e36b21e11760 Remove useless casts
Mikael Berthe <mikael@lilotux.net>
parents: 1343
diff changeset
238 const char *configured_dir = settings_opt_get("otr_dir");
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
239
1335
ab1b7f7a682e Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents: 1320
diff changeset
240 if (configured_dir && *configured_dir) {
ab1b7f7a682e Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents: 1320
diff changeset
241 char *xp_conf_dir;
ab1b7f7a682e Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents: 1320
diff changeset
242 int l;
ab1b7f7a682e Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents: 1320
diff changeset
243 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
244 // 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
245 l = strlen(xp_conf_dir);
ab1b7f7a682e Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents: 1320
diff changeset
246 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
247 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
248 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
249 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
250 }
ab1b7f7a682e Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents: 1320
diff changeset
251 return xp_conf_dir;
ab1b7f7a682e Make sure the otr_dir is always slash-terminated
Mikael Berthe <mikael@lilotux.net>
parents: 1320
diff changeset
252 } else {
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
253 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
254 }
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
255 }
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
256
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
257 static ConnContext *otr_get_context(const char *buddy)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
258 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
259 int null = 0;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
260 ConnContext *ctx;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
261 char *lowcasebuddy = g_strdup(buddy);
1495
6f5754f86fbb Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents: 1470
diff changeset
262
6f5754f86fbb Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents: 1470
diff changeset
263 mc_strtolower(lowcasebuddy);
1577
e1a642472f4e Use otr context where possible, saves one mc_strtolower() per received message
franky
parents: 1501
diff changeset
264 ctx = otrl_context_find(userstate, lowcasebuddy, account, OTR_PROTOCOL_NAME,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
265 #ifdef HAVE_LIBOTR3
1577
e1a642472f4e Use otr context where possible, saves one mc_strtolower() per received message
franky
parents: 1501
diff changeset
266 1, &null, NULL, NULL);
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
267 #else
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
268 // INSTAG XXX
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
269 OTRL_INSTAG_BEST, 1, &null, NULL, NULL);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
270 #endif
1495
6f5754f86fbb Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents: 1470
diff changeset
271 g_free(lowcasebuddy);
6f5754f86fbb Fix JID case issue with OTR, v2 (franky)
Mikael Berthe <mikael@lilotux.net>
parents: 1470
diff changeset
272 return ctx;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
273 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
274
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
275 static void otr_message_disconnect(ConnContext *ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
276 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
277 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
278 cb_gone_insecure(NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
279 otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
280 #ifdef HAVE_LIBOTR3
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
281 ctx->protocol, ctx->username);
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
282 #else
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
283 // INSTAG XXX
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
284 ctx->protocol, ctx->username, OTRL_INSTAG_BEST);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
285 #endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
286 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
287
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
288 static void otr_startstop(const char *buddy, int start)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
289 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
290 char *msg = NULL;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
291 ConnContext *ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
292
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
293 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
294 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
295
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
296 if (start && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
297 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
298
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
299 if (start) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
300 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
301 if (policy == plain) {
b17754d9221b Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents: 1307
diff changeset
302 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
303 " 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
304 return;
b17754d9221b Show a warning for /otr start|stop, if policy == plain
franky@veqlargh.fs
parents: 1307
diff changeset
305 }
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
306 msg = otrl_proto_default_query_msg(ctx->accountname, policy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
307 cb_inject_message(NULL, ctx->accountname, ctx->protocol, ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
308 msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
309 free (msg);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
310 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
311 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
312 otr_message_disconnect(ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
313 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
314
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
315 void otr_establish(const char *buddy)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
316 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
317 otr_startstop(buddy, 1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
318 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
319
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
320 void otr_disconnect(const char *buddy)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
321 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
322 otr_startstop(buddy, 0);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
323 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
324
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
325 void otr_fingerprint(const char *buddy, const char *trust)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
326 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
327 char fpr[45], *tr;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
328 ConnContext *ctx = otr_get_context(buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
329 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
330 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
331
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
332 if (!ctx->active_fingerprint || !ctx->active_fingerprint->fingerprint) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
333 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
334 "No active fingerprint - start OTR for this buddy first.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
335 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
336 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
337
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
338 otrl_privkey_hash_to_human(fpr, ctx->active_fingerprint->fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
339 if (trust) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
340 if (strcmp(fpr, trust) == 0)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
341 otrl_context_set_trust(ctx->active_fingerprint, "trust");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
342 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
343 otrl_context_set_trust(ctx->active_fingerprint, NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
344 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
345
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
346 tr = ctx->active_fingerprint->trust;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
347 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
348 tr && *tr ? "trusted" : "untrusted");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
349 cb_write_fingerprints(NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
350 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
351
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
352 #ifdef HAVE_LIBOTR3
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
353
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
354 static void otr_handle_smp_tlvs(OtrlTLV *tlvs, ConnContext *ctx)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
355 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
356 OtrlTLV *tlv = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
357 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
358 NextExpectedSMP nextMsg = ctx->smstate->nextExpected;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
359
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
360 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
361 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
362 if (nextMsg != OTRL_SMP_EXPECT1)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
363 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
364 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
365 sbuf = g_strdup_printf("OTR: Received SMP Initiation. "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
366 "Answer with /otr smpr %s $secret",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
367 ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
368 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
369 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
370 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
371 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
372 if (nextMsg != OTRL_SMP_EXPECT2)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
373 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
374 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
375 sbuf = g_strdup("OTR: Received SMP Response.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
376 /* If we received TLV2, we will send TLV3 and expect TLV4 */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
377 ctx->smstate->nextExpected = OTRL_SMP_EXPECT4;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
378 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
379 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
380 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
381 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
382 if (nextMsg != OTRL_SMP_EXPECT3)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
383 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
384 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
385 /* If we received TLV3, we will send TLV4
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
386 * We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
387 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
388 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
389 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
390 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
391 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
392 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
393 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
394 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
395 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
396 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
397 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
398 if (nextMsg != OTRL_SMP_EXPECT4)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
399 otr_smp_abort(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
400 else {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
401 /* We will not expect more messages, so prepare for next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
402 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
403 /* Report result to user */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
404 if (ctx->active_fingerprint && ctx->active_fingerprint->trust &&
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
405 *ctx->active_fingerprint->trust != '\0')
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
406 sbuf = g_strdup("OTR: SMP succeeded");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
407 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
408 sbuf = g_strdup("OTR: SMP failed");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
409 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
410 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
411 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
412 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
413 /* The message we are waiting for will not arrive, so reset
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
414 * and prepare for the next SMP */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
415 sbuf = g_strdup("OTR: SMP aborted by your buddy");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
416 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
417 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
418
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
419 if (sbuf) {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
420 scr_WriteIncomingMessage(ctx->username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
421 g_free(sbuf);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
422 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
423 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
424
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
425 #else /* HAVE_LIBOTR3 */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
426
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
427 static void cb_handle_smp_event(void *opdata, OtrlSMPEvent event,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
428 ConnContext *context, unsigned short percent,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
429 char *question)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
430 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
431 const char *msg = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
432 char *freeme = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
433 switch (event) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
434 case OTRL_SMPEVENT_ASK_FOR_SECRET:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
435 msg = freeme = g_strdup_printf("OTR: Socialist Millionaires' Protocol: "
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
436 "Received SMP Initiation.\n"
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
437 "Answer with /otr smpr %s $secret",
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
438 context->username);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
439 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
440 case OTRL_SMPEVENT_ASK_FOR_ANSWER:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
441 msg = freeme = g_strdup_printf("OTR: Socialist Millionaires' Protocol: "
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
442 "Received SMP Initiation.\n"
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
443 "Answer with /otr smpr %s $secret\n"
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
444 "Question: %s", context->username,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
445 question);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
446 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
447 case OTRL_SMPEVENT_CHEATED:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
448 msg = "OTR: Socialist Millionaires' Protocol: Correspondent cancelled negotiation!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
449 otrl_message_abort_smp(userstate, &ops, opdata, context);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
450 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
451 case OTRL_SMPEVENT_IN_PROGRESS:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
452 scr_log_print(LPRINT_DEBUG, "OTR: Socialist Millionaires' Protocol: "
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
453 "Negotiation is in pogress...");
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
454 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
455 case OTRL_SMPEVENT_SUCCESS:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
456 msg = "OTR: Socialist Millionaires' Protocol: Success!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
457 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
458 case OTRL_SMPEVENT_FAILURE:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
459 msg = "OTR: Socialist Millionaires' Protocol: Failure.";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
460 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
461 case OTRL_SMPEVENT_ABORT:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
462 msg = "OTR: Socialist Millionaires' Protocol: Aborted.";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
463 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
464 case OTRL_SMPEVENT_ERROR:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
465 msg = "OTR: Socialist Millionaires' Protocol: Error occured, aborting negotiations!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
466 otrl_message_abort_smp(userstate, &ops, opdata, context);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
467 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
468 default:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
469 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
470 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
471
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
472 if (msg) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
473 scr_WriteIncomingMessage(context->username, msg, 0, HBB_PREFIX_INFO, 0);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
474 g_free(freeme);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
475 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
476 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
477
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
478 static void cb_handle_msg_event(void *opdata, OtrlMessageEvent event,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
479 ConnContext *context, const char *message,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
480 gcry_error_t err)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
481 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
482 const char *msg = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
483 char *freeme = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
484 switch (event) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
485 case OTRL_MSGEVENT_ENCRYPTION_REQUIRED:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
486 msg = "OTR: Policy requires encryption on message!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
487 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
488 case OTRL_MSGEVENT_ENCRYPTION_ERROR:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
489 msg = "OTR: Encryption error! Message not sent.";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
490 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
491 case OTRL_MSGEVENT_CONNECTION_ENDED:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
492 msg = "OTR: Connection closed by remote end, message lost. "
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
493 "Close or refresh connection.";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
494 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
495 case OTRL_MSGEVENT_SETUP_ERROR:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
496 // FIXME
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
497 msg = freeme = g_strdup_printf("OTR: Error setting up private conversation: %u",
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
498 err);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
499 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
500 case OTRL_MSGEVENT_MSG_REFLECTED:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
501 msg = "OTR: Received own OTR message!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
502 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
503 case OTRL_MSGEVENT_MSG_RESENT:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
504 msg = "OTR: Previous message was resent.";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
505 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
506 case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
507 msg = "OTR: Received encrypted message, but connection is not established " \
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
508 "yet! Message lost.";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
509 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
510 case OTRL_MSGEVENT_RCVDMSG_UNREADABLE:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
511 msg = "OTR: Unable to read incoming message!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
512 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
513 case OTRL_MSGEVENT_RCVDMSG_MALFORMED:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
514 msg = "OTR: Malformed incoming message!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
515 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
516 case OTRL_MSGEVENT_LOG_HEARTBEAT_RCVD:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
517 scr_log_print(LPRINT_DEBUG, "OTR: Received heartbeat.");
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
518 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
519 case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
520 scr_log_print(LPRINT_DEBUG, "OTR: Sent heartbeat.");
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
521 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
522 case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
523 msg = freeme = g_strdup_printf("OTR: Received general otr error: %s",
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
524 message);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
525 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
526 case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
527 msg = freeme = g_strdup_printf("OTR: Received unencrypted message: %s",
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
528 message);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
529 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
530 case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
531 msg = "OTR: Unable to determine type of received OTR message!";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
532 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
533 case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
534 // XXX
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
535 scr_log_print(LPRINT_DEBUG, "OTR: Received message for other instance.");
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
536 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
537 default:
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
538 break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
539 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
540
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
541 if (msg) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
542 scr_WriteIncomingMessage(context->username, msg, 0, HBB_PREFIX_INFO, 0);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
543 g_free(freeme);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
544 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
545 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
546
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
547 #endif /* HAVE_LIBOTR3 */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
548
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
549 /*
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
550 * returns whether a otr_message was received
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
551 * sets *otr_data to NULL, when it was an internal otr message
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
552 */
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
553 int otr_receive(char **otr_data, const char *buddy, int *free_msg)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
554 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
555 int ignore_message;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
556 char *newmessage = NULL;
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
557 #ifdef HAVE_LIBOTR3
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
558 OtrlTLV *tlvs = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
559 OtrlTLV *tlv = NULL;
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
560 #endif
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
561 ConnContext *ctx;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
562
1577
e1a642472f4e Use otr context where possible, saves one mc_strtolower() per received message
franky
parents: 1501
diff changeset
563 ctx = otr_get_context(buddy);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
564 *free_msg = 0;
1577
e1a642472f4e Use otr context where possible, saves one mc_strtolower() per received message
franky
parents: 1501
diff changeset
565 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
566 ctx->accountname, ctx->protocol,
e1a642472f4e Use otr context where possible, saves one mc_strtolower() per received message
franky
parents: 1501
diff changeset
567 ctx->username, *otr_data,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
568 #ifdef HAVE_LIBOTR3
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
569 &newmessage, &tlvs, NULL, NULL);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
570
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
571 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
572 if (tlv) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
573 /* Notify the user that the other side disconnected. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
574 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
575 cb_gone_insecure(NULL, ctx);
1577
e1a642472f4e Use otr context where possible, saves one mc_strtolower() per received message
franky
parents: 1501
diff changeset
576 otr_disconnect(ctx->username);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
577 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
578 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
579
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
580 otr_handle_smp_tlvs(tlvs, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
581
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
582 if (tlvs != NULL)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
583 otrl_tlv_free(tlvs);
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
584 #else
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
585 &newmessage, NULL, NULL, NULL, NULL);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
586 #endif
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
587
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
588 if (ignore_message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
589 *otr_data = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
590
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
591 if (!ignore_message && newmessage) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
592 *free_msg = 1;
1470
a8b924b5474c The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents: 1420
diff changeset
593 *otr_data = html_strip(newmessage);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
594 otrl_message_free(newmessage);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
595 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
596 return 1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
597 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
598 return 0;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
599 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
600
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
601 char *otr_send(const char *msg, const char *buddy, int *encryption_status)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
602 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
603 gcry_error_t err;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
604 char *newmessage = NULL;
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
605 char *htmlmsg, *rmsg;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
606 ConnContext *ctx = otr_get_context(buddy);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
607
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
608 *encryption_status = 0;
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
609
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
610 if (!msg || !buddy || !encryption_status)
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
611 return NULL;
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
612
1580
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
613 if (ctx->msgstate == OTRL_MSGSTATE_PLAINTEXT)
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
614 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
615 #ifdef HAVE_LIBOTR3
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
616 ctx->protocol, ctx->username, msg, NULL,
1580
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
617 &newmessage, NULL, NULL);
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
618 #else
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
619 // INSTAG XXX
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
620 ctx->protocol, ctx->username, OTRL_INSTAG_BEST,
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
621 msg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
622 NULL, NULL, NULL);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
623 #endif
1580
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
624 else {
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
625 htmlmsg = html_escape(msg);
1580
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
626 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname,
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
627 #ifdef HAVE_LIBOTR3
1580
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
628 ctx->protocol, ctx->username, htmlmsg, NULL,
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
629 &newmessage, NULL, NULL);
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
630 #else
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
631 // INSTAG XXX
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
632 ctx->protocol, ctx->username, OTRL_INSTAG_BEST,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
633 htmlmsg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
634 NULL, NULL, NULL);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
635 #endif
1580
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
636 g_free(htmlmsg);
c8be6c2243d6 Only html escape messages when otr session is established
franky
parents: 1577
diff changeset
637 }
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
638
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
639 if (err || !newmessage)
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
640 return NULL; /* something went wrong, don't send the plain-message! */
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
641
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
642 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION ||
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
643 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
644 *encryption_status = 1;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
645
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
646 /* Check the new message is not empty */
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
647 if (newmessage[0] || !msg[0]) {
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
648 rmsg = g_strdup(newmessage);
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
649 } else {
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
650 rmsg = NULL;
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
651 *encryption_status = 0;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
652 }
2213
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
653
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
654 otrl_message_free(newmessage);
0c78d31c753d Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents: 2076
diff changeset
655 return rmsg;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
656 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
657
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
658 /* Prints OTR connection state */
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
659 void otr_print_info(const char *buddy)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
660 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
661 const char *state, *auth, *policy;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
662 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
663 OtrlPolicy p = cb_policy(ctx->app_data, ctx);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
664
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
665 if (!userstate || !ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
666 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
667
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
668 switch (ctx->msgstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
669 case OTRL_MSGSTATE_PLAINTEXT: state = "plaintext"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
670 case OTRL_MSGSTATE_ENCRYPTED:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
671 switch (ctx->protocol_version) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
672 case 1: state = "encrypted V1"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
673 case 2: state = "encrypted V2"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
674 default:state = "encrypted";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
675 };
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
676 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
677 case OTRL_MSGSTATE_FINISHED: state = "finished"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
678 default: state = "unknown state";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
679 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
680 switch (ctx->auth.authstate) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
681 case OTRL_AUTHSTATE_NONE:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
682 switch (ctx->otr_offer) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
683 case OFFER_NOT: auth = "no offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
684 case OFFER_SENT: auth = "offer sent"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
685 case OFFER_ACCEPTED: auth = "offer accepted"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
686 case OFFER_REJECTED: auth = "offer rejected"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
687 default: auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
688 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
689 break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
690 case OTRL_AUTHSTATE_AWAITING_DHKEY:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
691 auth = "awaiting D-H key"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
692 case OTRL_AUTHSTATE_AWAITING_REVEALSIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
693 auth = "awaiting reveal signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
694 case OTRL_AUTHSTATE_AWAITING_SIG:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
695 auth = "awaiting signature"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
696 case OTRL_AUTHSTATE_V1_SETUP:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
697 auth = "v1 setup"; break;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
698 default:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
699 auth = "unknown auth";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
700 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
701 if (p == OTRL_POLICY_NEVER)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
702 policy = "plain";
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
703 else if (p == (OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1))
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
704 policy = "opportunistic";
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
705 else if (p == (OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1))
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
706 policy = "manual";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
707 else if (p == (OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
708 policy = "always";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
709 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
710 policy = "unknown";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
711
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
712 scr_LogPrint(LPRINT_LOGNORM, "%s: %s (%s) [%s]",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
713 ctx->username, state, auth, policy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
714 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
715
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
716 static ConnContext *otr_context_encrypted(const char *buddy)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
717 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
718 ConnContext *ctx = otr_get_context(buddy);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
719
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
720 if (!userstate || !ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED){
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
721 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
722 "You have to start an OTR channel with %s before you can "
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
723 "use SMP.", buddy);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
724 return NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
725 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
726
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
727 return ctx;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
728 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
729
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
730 void otr_smp_query(const char *buddy, const char *secret)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
731 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
732 ConnContext *ctx = otr_context_encrypted(buddy);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
733
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
734 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
735 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
736 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
737 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
738 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
739
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
740 if (ctx) {
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
741 otrl_message_initiate_smp(userstate, &ops, NULL, ctx,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
742 (const unsigned char *)secret,
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
743 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
744 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
745 "OTR: Socialist Millionaires' Protocol "
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
746 "initiated.", 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
747 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
748 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
749
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
750 void otr_smp_respond(const char *buddy, const char *secret)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
751 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
752 ConnContext *ctx = otr_context_encrypted(buddy);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
753
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
754 if (!secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
755 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
756 "Using SMP without a secret isn't a good idea.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
757 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
758 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
759
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
760 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
761 if (!ctx->smstate->secret) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
762 scr_LogPrint(LPRINT_LOGNORM,
1584
18069a9dca4a Fix typo in OTR messages (Anne)
Mikael Berthe <mikael@lilotux.net>
parents: 1580
diff changeset
763 "Don't call smpr until you have received an SMP "
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
764 "Initiation!");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
765 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
766 }
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
767 otrl_message_respond_smp(userstate, &ops, NULL, ctx,
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
768 (const unsigned char *)secret,
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
769 strlen(secret));
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
770 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
771 "OTR: Socialist Millionaires' Protocol: "
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
772 "response sent", 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
773 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
774 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
775
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
776 void otr_smp_abort(const char *buddy)
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
777 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
778 ConnContext *ctx = otr_context_encrypted(buddy);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
779
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
780 if (ctx) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
781 otrl_message_abort_smp(userstate, &ops, NULL, ctx);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
782 scr_WriteIncomingMessage(ctx->username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
783 "OTR: Socialist Millionaires' Protocol aborted.",
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
784 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
785 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
786 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
787
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
788 void otr_key(void)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
789 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
790 OtrlPrivKey *key;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
791 char readable[45] = "";
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
792
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
793 if(!userstate)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
794 return;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
795 for (key = userstate->privkey_root; key; key = key->next) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
796 otrl_privkey_fingerprint(userstate, readable, key->accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
797 key->protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
798 scr_LogPrint(LPRINT_LOGNORM, "%s: %s", key->accountname, readable);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
799 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
800 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
801
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
802 /* Return the OTR policy for the given context. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
803 static OtrlPolicy cb_policy(void *opdata, ConnContext *ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
804 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
805 enum otr_policy p = settings_otr_getpolicy(NULL);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
806
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
807 if(ctx)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
808 if(settings_otr_getpolicy(ctx->username))
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
809 p = settings_otr_getpolicy(ctx->username);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
810
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
811 switch (p) {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
812 case plain:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
813 return OTRL_POLICY_NEVER;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
814 case opportunistic:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
815 return OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
816 case manual:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
817 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
818 case always:
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
819 return OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
820 }
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
821
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
822 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
823 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
824
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
825 /* Create a private key for the given accountname/protocol if
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
826 * desired. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
827 static void cb_create_privkey(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
828 const char *protocol)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
829 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
830 gcry_error_t e;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
831 char *root;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
832
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
833 scr_LogPrint(LPRINT_LOGNORM,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
834 "Generating new OTR key for %s. This may take a while...",
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
835 accountname);
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
836 scr_do_update();
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
837
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
838 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
839
1320
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
840 if (e) {
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
841 root = otr_get_dir();
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
842 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed! Please mkdir "
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
843 "%s if you want to use otr encryption.", root);
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
844 g_free(root);
cb400799db8f Configurable OTR directory
franky@veqlargh.fs
parents: 1308
diff changeset
845 }
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
846 else
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
847 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated.");
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
848 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
849
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
850 /* Report whether you think the given user is online. Return 1 if
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
851 * you think he is, 0 if you think he isn't, -1 if you're not sure.
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
852 * If you return 1, messages such as heartbeats or other
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
853 * notifications may be sent to the user, which could result in "not
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
854 * logged in" errors if you're wrong. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
855 static int cb_is_logged_in(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
856 const char *protocol, const char *recipient)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
857 {
1346
e36b21e11760 Remove useless casts
Mikael Berthe <mikael@lilotux.net>
parents: 1343
diff changeset
858 int ret = (roster_getstatus(recipient, NULL) != offline);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
859 return ret;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
860 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
861
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
862 /* Send the given IM to the given recipient from the given
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
863 * accountname/protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
864 static void cb_inject_message(void *opdata, const char *accountname,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
865 const char *protocol, const char *recipient,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
866 const char *message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
867 {
1343
8a05feb23c5a Only use OTR encryption on other users
franky@veqlargh.fs
parents: 1335
diff changeset
868 if (roster_gettype(recipient) == ROSTER_TYPE_USER)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1584
diff changeset
869 xmpp_send_msg(recipient, message, ROSTER_TYPE_USER, "", TRUE, NULL,
1602
f4a2c6f767d1 Message Receipts support (XEP-0184)
franky
parents: 1599
diff changeset
870 LM_MESSAGE_SUB_TYPE_NOT_SET, NULL);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
871 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
872
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
873 /* When the list of ConnContexts changes (including a change in
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
874 * state), this is called so the UI can be updated. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
875 static void cb_update_context_list(void *opdata)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
876 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
877 /*maybe introduce new status characters for mcabber,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
878 * then use this function (?!)*/
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
879 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
880
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
881 /* A new fingerprint for the given user has been received. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
882 static void cb_new_fingerprint(void *opdata, OtrlUserState us,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
883 const char *accountname, const char *protocol,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
884 const char *username,
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
885 unsigned char fingerprint[20])
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
886 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
887 char *sbuf = NULL;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
888 char readable[45];
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
889
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
890 otrl_privkey_hash_to_human(readable, fingerprint);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
891 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
892 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
893 g_free(sbuf);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
894 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
895
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
896 /* The list of known fingerprints has changed. Write them to disk. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
897 static void cb_write_fingerprints(void *opdata)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
898 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
899 otrl_privkey_write_fingerprints(userstate, fprfile);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
900 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
901
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
902 /* A ConnContext has entered a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
903 static void cb_gone_secure(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
904 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
905 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
906 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
907 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
908
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
909 /* A ConnContext has left a secure state. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
910 static void cb_gone_insecure(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
911 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
912 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
913 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
914 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
915
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
916 /* We have completed an authentication, using the D-H keys we
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
917 * already knew. is_reply indicates whether we initiated the AKE. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
918 static void cb_still_secure(void *opdata, ConnContext *context, int is_reply)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
919 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
920 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0,
1301
37b41ed9ed35 Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1299
diff changeset
921 HBB_PREFIX_INFO, 0);
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
922 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
923
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
924 #ifdef HAVE_LIBOTR3
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
925
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
926 /* Display a notification message for a particular
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
927 * accountname / protocol / username conversation. */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
928 static void cb_notify(void *opdata, OtrlNotifyLevel level,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
929 const char *accountname, const char *protocol,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
930 const char *username, const char *title,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
931 const char *primary, const char *secondary)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
932 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
933 char *type;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
934 char *sbuf = NULL;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
935 switch (level) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
936 case OTRL_NOTIFY_ERROR: type = "error"; break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
937 case OTRL_NOTIFY_WARNING: type = "warning"; break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
938 case OTRL_NOTIFY_INFO: type = "info"; break;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
939 default: type = "unknown";
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
940 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
941 sbuf = g_strdup_printf("OTR %s:%s\n%s\n%s",type,title, primary, secondary);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
942 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
943 g_free(sbuf);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
944 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
945
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
946 /* Display an OTR control message for a particular
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
947 * accountname / protocol / username conversation. Return 0 if you are able
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
948 * to successfully display it. If you return non-0 (or if this
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
949 * function is NULL), the control message will be displayed inline,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
950 * as a received message, or else by using the above notify()
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
951 * callback. */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
952 static int cb_display_otr_message(void *opdata, const char *accountname,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
953 const char *protocol, const char *username,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
954 const char *msg)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
955 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
956 char *strippedmsg = html_strip(msg);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
957 scr_WriteIncomingMessage(username, strippedmsg, 0, HBB_PREFIX_INFO, 0);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
958 g_free(strippedmsg);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
959 return 0;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
960 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
961
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
962 /* Return a newly allocated string containing a human-friendly name
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
963 * for the given protocol id */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
964 static const char *cb_protocol_name(void *opdata, const char *protocol)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
965 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
966 return protocol;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
967 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
968
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
969 /* Deallocate a string allocated by protocol_name */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
970 static void cb_protocol_name_free (void *opdata, const char *protocol_name)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
971 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
972 /* We didn't allocated memory, so we don't have to free anything :p */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
973 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
974
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
975 /* Log a message. The passed message will end in "\n". */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
976 static void cb_log_message(void *opdata, const char *message)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
977 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
978 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message);
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
979 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
980
2076
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
981 #else /* HAVE_LIBOTR3 */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
982
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
983 /* Generate unique instance tag for account. */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
984 static void cb_create_instag(void *opdata, const char *accountname,
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
985 const char *protocol)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
986 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
987 if (otrl_instag_generate(userstate, tagfile, accountname, protocol)) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
988 scr_LogPrint(LPRINT_LOGNORM, "OTR instance tag generation failed!");
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
989 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
990 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
991
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
992 static gboolean otr_timer_cb(gpointer userdata)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
993 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
994 otrl_message_poll(userstate, &ops, userdata);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
995 return TRUE;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
996 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
997
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
998 static void cb_timer_control(void *opdata, unsigned int interval)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
999 {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1000 if (otr_timer_source > 0) {
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1001 g_source_remove(otr_timer_source);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1002 otr_timer_source = 0;
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1003 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1004 if (interval > 0)
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1005 otr_timer_source = g_timeout_add_seconds(interval, otr_timer_cb, opdata);
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1006 }
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1007
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1008 #endif /* HAVE_LIBOTR3 */
9fb1ccf291cc Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1811
diff changeset
1009
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1010 /* Find the maximum message size supported by this protocol. */
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1011 static int cb_max_message_size(void *opdata, ConnContext *context)
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1012 {
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1013 return 8192;
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1014 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1015
1347
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1016 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
1017 {
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1018 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
1019 }
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1020
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1021 #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
1022
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1023 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
1024 {
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1025 return FALSE;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1026 }
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1346
diff changeset
1027
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
diff changeset
1028 #endif /* HAVE_LIBOTR */
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
1029
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1780
diff changeset
1030 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */