Mercurial > ~mikael > mcabber > hg
annotate mcabber/mcabber/otr.c @ 2220:79e12dacbccd
Fix a 1-byte memory leak in caps_generate()
The caps value is correctly stolen and reinserted but the previous
hash key should be freed. This is a special key "" of 1 byte.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 06 Nov 2015 13:43:15 +0100 |
parents | 3958793d0d03 |
children | f3bd1564fa70 |
rev | line source |
---|---|
1299 | 1 /* |
1303
b6fdbfa6b219
Minor whitespace change
Mikael Berthe <mikael@lilotux.net>
parents:
1301
diff
changeset
|
2 * otr.c -- Off-The-Record Messaging for mcabber |
1299 | 3 * |
1599 | 4 * Copyright (C) 2007-2009 Frank Zschockelt <mcabber_otr@freakysoft.de> |
1299 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
22 #include <config.h> | |
1470
a8b924b5474c
The OTR protocol expects (X)HTML messsages
Mikael Berthe <mikael@lilotux.net>
parents:
1420
diff
changeset
|
23 #include <glib.h> |
1299 | 24 |
25 #ifdef HAVE_LIBOTR | |
26 | |
1598 | 27 #include "hbuf.h" |
1299 | 28 #include "logprint.h" |
1598 | 29 #include "nohtml.h" |
30 #include "otr.h" | |
1299 | 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 | 34 #include "utils.h" |
35 #include "xmpp.h" | |
1299 | 36 |
1577
e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
franky
parents:
1501
diff
changeset
|
37 #define OTR_PROTOCOL_NAME "jabber" |
1299 | 38 |
39 static OtrlUserState userstate = NULL; | |
1598 | 40 static char *account = NULL; |
41 static char *keyfile = NULL; | |
42 static char *fprfile = NULL; | |
1299 | 43 |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
44 static int otr_is_enabled = FALSE; |
1299 | 45 |
46 static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx); | |
47 static void cb_create_privkey (void *opdata, | |
48 const char *accountname, | |
49 const char *protocol); | |
50 static int cb_is_logged_in (void *opdata, | |
51 const char *accountname, | |
52 const char *protocol, | |
53 const char *recipient); | |
54 static void cb_inject_message (void *opdata, | |
55 const char *accountname, | |
56 const char *protocol, | |
57 const char *recipient, | |
58 const char *message); | |
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 | 73 static void cb_notify (void *opdata, |
74 OtrlNotifyLevel level, | |
75 const char *accountname, | |
76 const char *protocol, | |
77 const char *username, | |
78 const char *title, | |
79 const char *primary, | |
80 const char *secondary); | |
81 static int cb_display_otr_message(void *opdata, | |
82 const char *accountname, | |
83 const char *protocol, | |
84 const char *username, | |
85 const char *msg); | |
86 static const char *cb_protocol_name (void *opdata, const char *protocol); | |
87 static void cb_protocol_name_free (void *opdata, | |
88 const char *protocol_name); | |
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 | 106 |
107 static OtrlMessageAppOps ops = | |
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 | 146 }; |
147 | |
148 static void otr_message_disconnect(ConnContext *ctx); | |
1598 | 149 static ConnContext *otr_get_context(const char *buddy); |
150 static void otr_startstop(const char *buddy, int start); | |
1299 | 151 |
1598 | 152 static char *otr_get_dir(void); |
1299 | 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 | 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 | 159 return; |
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 | 172 keyfile = g_strdup_printf("%s%s.key", root, account); |
173 fprfile = g_strdup_printf("%s%s.fpr", root, account); | |
174 | |
175 if (otrl_privkey_read(userstate, keyfile)){ | |
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 | 178 } |
179 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){ | |
180 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s", | |
181 fprfile); | |
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 | 191 } |
192 | |
193 void otr_terminate(void) | |
194 { | |
1598 | 195 ConnContext *ctx; |
1299 | 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 | 207 for (ctx = userstate->context_root; ctx; ctx = ctx->next) |
1299 | 208 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) |
209 otr_message_disconnect(ctx); | |
210 | |
211 g_free(account); | |
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 | 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 | 225 userstate = NULL; |
226 g_free(keyfile); | |
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 | 234 } |
235 | |
1598 | 236 static char *otr_get_dir(void) |
1320 | 237 { |
1346 | 238 const char *configured_dir = settings_opt_get("otr_dir"); |
1320 | 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 | 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 | 255 } |
256 | |
1598 | 257 static ConnContext *otr_get_context(const char *buddy) |
1299 | 258 { |
259 int null = 0; | |
1598 | 260 ConnContext *ctx; |
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 | 273 } |
274 | |
275 static void otr_message_disconnect(ConnContext *ctx) | |
276 { | |
277 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | |
278 cb_gone_insecure(NULL, ctx); | |
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 | 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 | 286 } |
287 | |
1598 | 288 static void otr_startstop(const char *buddy, int start) |
1299 | 289 { |
1598 | 290 char *msg = NULL; |
1299 | 291 ConnContext *ctx = otr_get_context(buddy); |
292 | |
293 if (!userstate || !ctx) | |
294 return; | |
295 | |
296 if (start && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | |
297 otr_message_disconnect(ctx); | |
298 | |
299 if (start) { | |
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 | 306 msg = otrl_proto_default_query_msg(ctx->accountname, policy); |
307 cb_inject_message(NULL, ctx->accountname, ctx->protocol, ctx->username, | |
308 msg); | |
309 free (msg); | |
310 } | |
311 else | |
312 otr_message_disconnect(ctx); | |
313 } | |
314 | |
315 void otr_establish(const char *buddy) | |
316 { | |
317 otr_startstop(buddy, 1); | |
318 } | |
319 | |
1598 | 320 void otr_disconnect(const char *buddy) |
1299 | 321 { |
322 otr_startstop(buddy, 0); | |
323 } | |
324 | |
1598 | 325 void otr_fingerprint(const char *buddy, const char *trust) |
1299 | 326 { |
327 char fpr[45], *tr; | |
328 ConnContext *ctx = otr_get_context(buddy); | |
329 if (!userstate || !ctx) | |
330 return; | |
331 | |
332 if (!ctx->active_fingerprint || !ctx->active_fingerprint->fingerprint) { | |
333 scr_LogPrint(LPRINT_LOGNORM, | |
334 "No active fingerprint - start OTR for this buddy first."); | |
335 return; | |
336 } | |
337 | |
338 otrl_privkey_hash_to_human(fpr, ctx->active_fingerprint->fingerprint); | |
339 if (trust) { | |
340 if (strcmp(fpr, trust) == 0) | |
341 otrl_context_set_trust(ctx->active_fingerprint, "trust"); | |
342 else | |
343 otrl_context_set_trust(ctx->active_fingerprint, NULL); | |
344 } | |
345 | |
346 tr = ctx->active_fingerprint->trust; | |
347 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr, | |
348 tr && *tr ? "trusted" : "untrusted"); | |
349 cb_write_fingerprints(NULL); | |
350 } | |
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 | 354 static void otr_handle_smp_tlvs(OtrlTLV *tlvs, ConnContext *ctx) |
1299 | 355 { |
356 OtrlTLV *tlv = NULL; | |
357 char *sbuf = NULL; | |
358 NextExpectedSMP nextMsg = ctx->smstate->nextExpected; | |
359 | |
360 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1); | |
361 if (tlv) { | |
362 if (nextMsg != OTRL_SMP_EXPECT1) | |
363 otr_smp_abort(ctx->username); | |
364 else { | |
365 sbuf = g_strdup_printf("OTR: Received SMP Initiation. " | |
366 "Answer with /otr smpr %s $secret", | |
367 ctx->username); | |
368 } | |
369 } | |
370 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2); | |
371 if (tlv) { | |
372 if (nextMsg != OTRL_SMP_EXPECT2) | |
373 otr_smp_abort(ctx->username); | |
374 else { | |
375 sbuf = g_strdup("OTR: Received SMP Response."); | |
376 /* If we received TLV2, we will send TLV3 and expect TLV4 */ | |
377 ctx->smstate->nextExpected = OTRL_SMP_EXPECT4; | |
378 } | |
379 } | |
380 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3); | |
381 if (tlv) { | |
382 if (nextMsg != OTRL_SMP_EXPECT3) | |
383 otr_smp_abort(ctx->username); | |
384 else { | |
385 /* If we received TLV3, we will send TLV4 | |
386 * We will not expect more messages, so prepare for next SMP */ | |
387 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1; | |
388 /* Report result to user */ | |
389 if (ctx->active_fingerprint && ctx->active_fingerprint->trust && | |
390 *ctx->active_fingerprint->trust != '\0') | |
391 sbuf = g_strdup("OTR: SMP succeeded"); | |
392 else | |
393 sbuf = g_strdup("OTR: SMP failed"); | |
394 } | |
395 } | |
396 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4); | |
397 if (tlv) { | |
398 if (nextMsg != OTRL_SMP_EXPECT4) | |
399 otr_smp_abort(ctx->username); | |
400 else { | |
401 /* We will not expect more messages, so prepare for next SMP */ | |
402 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1; | |
403 /* Report result to user */ | |
404 if (ctx->active_fingerprint && ctx->active_fingerprint->trust && | |
405 *ctx->active_fingerprint->trust != '\0') | |
406 sbuf = g_strdup("OTR: SMP succeeded"); | |
407 else | |
408 sbuf = g_strdup("OTR: SMP failed"); | |
409 } | |
410 } | |
411 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); | |
412 if (tlv) { | |
413 /* The message we are waiting for will not arrive, so reset | |
414 * and prepare for the next SMP */ | |
415 sbuf = g_strdup("OTR: SMP aborted by your buddy"); | |
416 ctx->smstate->nextExpected = OTRL_SMP_EXPECT1; | |
417 } | |
418 | |
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 | 421 g_free(sbuf); |
422 } | |
423 } | |
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 |
2218 | 549 /* otr_receive |
550 * Returns whether a otr_message was received. | |
551 * Sets *otr_data to NULL, when it was an internal otr message. | |
1299 | 552 */ |
1598 | 553 int otr_receive(char **otr_data, const char *buddy, int *free_msg) |
1299 | 554 { |
555 int ignore_message; | |
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 | 558 OtrlTLV *tlvs = NULL; |
559 OtrlTLV *tlv = NULL; | |
2076
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
560 #endif |
1598 | 561 ConnContext *ctx; |
1299 | 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 | 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 | 570 |
571 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); | |
572 if (tlv) { | |
573 /* Notify the user that the other side disconnected. */ | |
574 if (ctx) { | |
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 | 577 } |
578 } | |
579 | |
580 otr_handle_smp_tlvs(tlvs, ctx); | |
581 | |
582 if (tlvs != NULL) | |
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 | 587 |
588 if (ignore_message) | |
589 *otr_data = NULL; | |
590 | |
591 if (!ignore_message && newmessage) { | |
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 | 594 otrl_message_free(newmessage); |
595 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | |
596 return 1; | |
597 } | |
598 return 0; | |
599 } | |
600 | |
2218 | 601 /* otr_send |
602 * Returns a newly allocated string, or NULL if no message should be sent. | |
603 * Sets *encryption_status to 1 if "the otr context is encrypted or otr tries | |
604 * to establish a session before the message is sent". | |
605 * (If the session isn't established, but the user choose "otr required", then | |
606 * the string just contains the "initiate session" message, not the message of | |
607 * the user.) | |
608 */ | |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
609 char *otr_send(const char *msg, const char *buddy, int *encryption_status) |
1299 | 610 { |
611 gcry_error_t err; | |
612 char *newmessage = NULL; | |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
613 char *htmlmsg, *rmsg; |
1598 | 614 ConnContext *ctx = otr_get_context(buddy); |
1299 | 615 |
2219
3958793d0d03
otr_send: Fix my previous fix and abort if the initial message is empty
Mikael Berthe <mikael@lilotux.net>
parents:
2218
diff
changeset
|
616 if (!encryption_status) |
3958793d0d03
otr_send: Fix my previous fix and abort if the initial message is empty
Mikael Berthe <mikael@lilotux.net>
parents:
2218
diff
changeset
|
617 return NULL; |
3958793d0d03
otr_send: Fix my previous fix and abort if the initial message is empty
Mikael Berthe <mikael@lilotux.net>
parents:
2218
diff
changeset
|
618 |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
619 *encryption_status = 0; |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
620 |
2219
3958793d0d03
otr_send: Fix my previous fix and abort if the initial message is empty
Mikael Berthe <mikael@lilotux.net>
parents:
2218
diff
changeset
|
621 if (!buddy || !msg || !msg[0]) |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
622 return NULL; |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
623 |
1580
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
624 if (ctx->msgstate == OTRL_MSGSTATE_PLAINTEXT) |
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
625 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
|
626 #ifdef HAVE_LIBOTR3 |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
627 ctx->protocol, ctx->username, msg, NULL, |
1580
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
628 &newmessage, NULL, NULL); |
2076
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
629 #else |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
630 // INSTAG XXX |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
631 ctx->protocol, ctx->username, OTRL_INSTAG_BEST, |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
632 msg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, |
2076
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
633 NULL, NULL, NULL); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
634 #endif |
1580
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
635 else { |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
636 htmlmsg = html_escape(msg); |
1580
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
637 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
|
638 #ifdef HAVE_LIBOTR3 |
1580
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
639 ctx->protocol, ctx->username, htmlmsg, NULL, |
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
640 &newmessage, NULL, NULL); |
2076
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
641 #else |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
642 // INSTAG XXX |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
643 ctx->protocol, ctx->username, OTRL_INSTAG_BEST, |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
644 htmlmsg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
645 NULL, NULL, NULL); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
646 #endif |
1580
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
647 g_free(htmlmsg); |
c8be6c2243d6
Only html escape messages when otr session is established
franky
parents:
1577
diff
changeset
|
648 } |
1299 | 649 |
2215
ba1a770dd632
Fix changeset 0c78d31c753d
Mikael Berthe <mikael@lilotux.net>
parents:
2213
diff
changeset
|
650 if (err) |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
651 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
|
652 |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
653 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION || |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
654 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
655 *encryption_status = 1; |
1299 | 656 |
2215
ba1a770dd632
Fix changeset 0c78d31c753d
Mikael Berthe <mikael@lilotux.net>
parents:
2213
diff
changeset
|
657 if (!newmessage) { |
ba1a770dd632
Fix changeset 0c78d31c753d
Mikael Berthe <mikael@lilotux.net>
parents:
2213
diff
changeset
|
658 if (*encryption_status == 1) |
2218 | 659 return NULL; /* This message should have been encrypted */ |
2215
ba1a770dd632
Fix changeset 0c78d31c753d
Mikael Berthe <mikael@lilotux.net>
parents:
2213
diff
changeset
|
660 |
2218 | 661 /* If not, the encryption was not required - send the original message */ |
2215
ba1a770dd632
Fix changeset 0c78d31c753d
Mikael Berthe <mikael@lilotux.net>
parents:
2213
diff
changeset
|
662 return g_strdup(msg); |
ba1a770dd632
Fix changeset 0c78d31c753d
Mikael Berthe <mikael@lilotux.net>
parents:
2213
diff
changeset
|
663 } |
ba1a770dd632
Fix changeset 0c78d31c753d
Mikael Berthe <mikael@lilotux.net>
parents:
2213
diff
changeset
|
664 |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
665 /* Check the new message is not empty */ |
2219
3958793d0d03
otr_send: Fix my previous fix and abort if the initial message is empty
Mikael Berthe <mikael@lilotux.net>
parents:
2218
diff
changeset
|
666 if (newmessage[0]) { |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
667 rmsg = g_strdup(newmessage); |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
668 } else { |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
669 rmsg = NULL; |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
670 *encryption_status = 0; |
1299 | 671 } |
2213
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
672 |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
673 otrl_message_free(newmessage); |
0c78d31c753d
Change otr_send() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
2076
diff
changeset
|
674 return rmsg; |
1299 | 675 } |
676 | |
677 /* Prints OTR connection state */ | |
1598 | 678 void otr_print_info(const char *buddy) |
1299 | 679 { |
680 const char *state, *auth, *policy; | |
1598 | 681 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
|
682 OtrlPolicy p = cb_policy(ctx->app_data, ctx); |
1299 | 683 |
684 if (!userstate || !ctx) | |
685 return; | |
686 | |
687 switch (ctx->msgstate) { | |
688 case OTRL_MSGSTATE_PLAINTEXT: state = "plaintext"; break; | |
689 case OTRL_MSGSTATE_ENCRYPTED: | |
690 switch (ctx->protocol_version) { | |
691 case 1: state = "encrypted V1"; break; | |
692 case 2: state = "encrypted V2"; break; | |
693 default:state = "encrypted"; | |
694 }; | |
695 break; | |
696 case OTRL_MSGSTATE_FINISHED: state = "finished"; break; | |
697 default: state = "unknown state"; | |
698 } | |
699 switch (ctx->auth.authstate) { | |
700 case OTRL_AUTHSTATE_NONE: | |
701 switch (ctx->otr_offer) { | |
702 case OFFER_NOT: auth = "no offer sent"; break; | |
703 case OFFER_SENT: auth = "offer sent"; break; | |
704 case OFFER_ACCEPTED: auth = "offer accepted"; break; | |
705 case OFFER_REJECTED: auth = "offer rejected"; break; | |
706 default: auth = "unknown auth"; | |
707 } | |
708 break; | |
709 case OTRL_AUTHSTATE_AWAITING_DHKEY: | |
710 auth = "awaiting D-H key"; break; | |
711 case OTRL_AUTHSTATE_AWAITING_REVEALSIG: | |
712 auth = "awaiting reveal signature"; break; | |
713 case OTRL_AUTHSTATE_AWAITING_SIG: | |
714 auth = "awaiting signature"; break; | |
715 case OTRL_AUTHSTATE_V1_SETUP: | |
716 auth = "v1 setup"; break; | |
717 default: | |
718 auth = "unknown auth"; | |
719 } | |
720 if (p == OTRL_POLICY_NEVER) | |
721 policy = "plain"; | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
722 else if (p == (OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1)) |
1299 | 723 policy = "opportunistic"; |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
724 else if (p == (OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1)) |
1299 | 725 policy = "manual"; |
726 else if (p == (OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1)) | |
727 policy = "always"; | |
728 else | |
729 policy = "unknown"; | |
730 | |
731 scr_LogPrint(LPRINT_LOGNORM, "%s: %s (%s) [%s]", | |
732 ctx->username, state, auth, policy); | |
733 } | |
734 | |
1598 | 735 static ConnContext *otr_context_encrypted(const char *buddy) |
1299 | 736 { |
1598 | 737 ConnContext *ctx = otr_get_context(buddy); |
1299 | 738 |
739 if (!userstate || !ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED){ | |
740 scr_LogPrint(LPRINT_LOGNORM, | |
741 "You have to start an OTR channel with %s before you can " | |
742 "use SMP.", buddy); | |
743 return NULL; | |
744 } | |
745 | |
746 return ctx; | |
747 } | |
748 | |
1598 | 749 void otr_smp_query(const char *buddy, const char *secret) |
1299 | 750 { |
1598 | 751 ConnContext *ctx = otr_context_encrypted(buddy); |
1299 | 752 |
753 if (!secret) { | |
754 scr_LogPrint(LPRINT_LOGNORM, | |
755 "Using SMP without a secret isn't a good idea."); | |
756 return; | |
757 } | |
758 | |
759 if (ctx) { | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
760 otrl_message_initiate_smp(userstate, &ops, NULL, ctx, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
761 (const unsigned char *)secret, |
1299 | 762 strlen(secret)); |
763 scr_WriteIncomingMessage(ctx->username, | |
764 "OTR: Socialist Millionaires' Protocol " | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
765 "initiated.", 0, HBB_PREFIX_INFO, 0); |
1299 | 766 } |
767 } | |
768 | |
1598 | 769 void otr_smp_respond(const char *buddy, const char *secret) |
1299 | 770 { |
1598 | 771 ConnContext *ctx = otr_context_encrypted(buddy); |
1299 | 772 |
773 if (!secret) { | |
774 scr_LogPrint(LPRINT_LOGNORM, | |
775 "Using SMP without a secret isn't a good idea."); | |
776 return; | |
777 } | |
778 | |
779 if (ctx) { | |
780 if (!ctx->smstate->secret) { | |
781 scr_LogPrint(LPRINT_LOGNORM, | |
1584
18069a9dca4a
Fix typo in OTR messages (Anne)
Mikael Berthe <mikael@lilotux.net>
parents:
1580
diff
changeset
|
782 "Don't call smpr until you have received an SMP " |
1299 | 783 "Initiation!"); |
784 return; | |
785 } | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
786 otrl_message_respond_smp(userstate, &ops, NULL, ctx, |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
787 (const unsigned char *)secret, |
1299 | 788 strlen(secret)); |
789 scr_WriteIncomingMessage(ctx->username, | |
790 "OTR: Socialist Millionaires' Protocol: " | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
791 "response sent", 0, HBB_PREFIX_INFO, 0); |
1299 | 792 } |
793 } | |
794 | |
1598 | 795 void otr_smp_abort(const char *buddy) |
1299 | 796 { |
1598 | 797 ConnContext *ctx = otr_context_encrypted(buddy); |
1299 | 798 |
799 if (ctx) { | |
800 otrl_message_abort_smp(userstate, &ops, NULL, ctx); | |
801 scr_WriteIncomingMessage(ctx->username, | |
802 "OTR: Socialist Millionaires' Protocol aborted.", | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
803 0, HBB_PREFIX_INFO, 0); |
1299 | 804 } |
805 } | |
806 | |
807 void otr_key(void) | |
808 { | |
1598 | 809 OtrlPrivKey *key; |
1299 | 810 char readable[45] = ""; |
811 | |
812 if(!userstate) | |
813 return; | |
814 for (key = userstate->privkey_root; key; key = key->next) { | |
815 otrl_privkey_fingerprint(userstate, readable, key->accountname, | |
816 key->protocol); | |
817 scr_LogPrint(LPRINT_LOGNORM, "%s: %s", key->accountname, readable); | |
818 } | |
819 } | |
820 | |
821 /* Return the OTR policy for the given context. */ | |
822 static OtrlPolicy cb_policy(void *opdata, ConnContext *ctx) | |
823 { | |
824 enum otr_policy p = settings_otr_getpolicy(NULL); | |
825 | |
826 if(ctx) | |
827 if(settings_otr_getpolicy(ctx->username)) | |
828 p = settings_otr_getpolicy(ctx->username); | |
829 | |
830 switch (p) { | |
831 case plain: | |
832 return OTRL_POLICY_NEVER; | |
833 case opportunistic: | |
834 return OTRL_POLICY_OPPORTUNISTIC & ~OTRL_POLICY_ALLOW_V1; | |
835 case manual: | |
836 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1; | |
837 case always: | |
838 return OTRL_POLICY_ALWAYS & ~OTRL_POLICY_ALLOW_V1; | |
839 } | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
840 |
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
841 return OTRL_POLICY_MANUAL & ~OTRL_POLICY_ALLOW_V1; |
1299 | 842 } |
843 | |
844 /* Create a private key for the given accountname/protocol if | |
845 * desired. */ | |
846 static void cb_create_privkey(void *opdata, const char *accountname, | |
847 const char *protocol) | |
848 { | |
849 gcry_error_t e; | |
1598 | 850 char *root; |
1299 | 851 |
852 scr_LogPrint(LPRINT_LOGNORM, | |
853 "Generating new OTR key for %s. This may take a while...", | |
854 accountname); | |
1780
e4378fbab5d7
Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
855 scr_do_update(); |
1299 | 856 |
857 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol); | |
858 | |
1320 | 859 if (e) { |
860 root = otr_get_dir(); | |
861 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed! Please mkdir " | |
862 "%s if you want to use otr encryption.", root); | |
863 g_free(root); | |
864 } | |
1299 | 865 else |
866 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated."); | |
867 } | |
868 | |
869 /* Report whether you think the given user is online. Return 1 if | |
870 * you think he is, 0 if you think he isn't, -1 if you're not sure. | |
871 * If you return 1, messages such as heartbeats or other | |
872 * notifications may be sent to the user, which could result in "not | |
873 * logged in" errors if you're wrong. */ | |
874 static int cb_is_logged_in(void *opdata, const char *accountname, | |
875 const char *protocol, const char *recipient) | |
876 { | |
1346 | 877 int ret = (roster_getstatus(recipient, NULL) != offline); |
1299 | 878 return ret; |
879 } | |
880 | |
881 /* Send the given IM to the given recipient from the given | |
882 * accountname/protocol. */ | |
883 static void cb_inject_message(void *opdata, const char *accountname, | |
884 const char *protocol, const char *recipient, | |
885 const char *message) | |
886 { | |
1343 | 887 if (roster_gettype(recipient) == ROSTER_TYPE_USER) |
1598 | 888 xmpp_send_msg(recipient, message, ROSTER_TYPE_USER, "", TRUE, NULL, |
1602 | 889 LM_MESSAGE_SUB_TYPE_NOT_SET, NULL); |
1299 | 890 } |
891 | |
892 /* When the list of ConnContexts changes (including a change in | |
893 * state), this is called so the UI can be updated. */ | |
894 static void cb_update_context_list(void *opdata) | |
895 { | |
896 /*maybe introduce new status characters for mcabber, | |
897 * then use this function (?!)*/ | |
898 } | |
899 | |
900 /* A new fingerprint for the given user has been received. */ | |
901 static void cb_new_fingerprint(void *opdata, OtrlUserState us, | |
902 const char *accountname, const char *protocol, | |
903 const char *username, | |
904 unsigned char fingerprint[20]) | |
905 { | |
906 char *sbuf = NULL; | |
907 char readable[45]; | |
908 | |
909 otrl_privkey_hash_to_human(readable, fingerprint); | |
910 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
|
911 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0); |
1299 | 912 g_free(sbuf); |
913 } | |
914 | |
915 /* The list of known fingerprints has changed. Write them to disk. */ | |
916 static void cb_write_fingerprints(void *opdata) | |
917 { | |
918 otrl_privkey_write_fingerprints(userstate, fprfile); | |
919 } | |
920 | |
921 /* A ConnContext has entered a secure state. */ | |
922 static void cb_gone_secure(void *opdata, ConnContext *context) | |
923 { | |
924 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0, | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
925 HBB_PREFIX_INFO, 0); |
1299 | 926 } |
927 | |
928 /* A ConnContext has left a secure state. */ | |
929 static void cb_gone_insecure(void *opdata, ConnContext *context) | |
930 { | |
931 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0, | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
932 HBB_PREFIX_INFO, 0); |
1299 | 933 } |
934 | |
935 /* We have completed an authentication, using the D-H keys we | |
936 * already knew. is_reply indicates whether we initiated the AKE. */ | |
937 static void cb_still_secure(void *opdata, ConnContext *context, int is_reply) | |
938 { | |
939 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0, | |
1301
37b41ed9ed35
Fixed compiler warnings
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1299
diff
changeset
|
940 HBB_PREFIX_INFO, 0); |
1299 | 941 } |
942 | |
2076
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
943 #ifdef HAVE_LIBOTR3 |
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 /* Display a notification message for a particular |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
946 * accountname / protocol / username conversation. */ |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
947 static void cb_notify(void *opdata, OtrlNotifyLevel level, |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
948 const char *accountname, const char *protocol, |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
949 const char *username, const char *title, |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
950 const char *primary, const char *secondary) |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
951 { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
952 char *type; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
953 char *sbuf = NULL; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
954 switch (level) { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
955 case OTRL_NOTIFY_ERROR: type = "error"; break; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
956 case OTRL_NOTIFY_WARNING: type = "warning"; break; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
957 case OTRL_NOTIFY_INFO: type = "info"; break; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
958 default: type = "unknown"; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
959 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
960 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
|
961 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
962 g_free(sbuf); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
963 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
964 |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
965 /* Display an OTR control message for a particular |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
966 * 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
|
967 * 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
|
968 * 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
|
969 * 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
|
970 * callback. */ |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
971 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
|
972 const char *protocol, const char *username, |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
973 const char *msg) |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
974 { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
975 char *strippedmsg = html_strip(msg); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
976 scr_WriteIncomingMessage(username, strippedmsg, 0, HBB_PREFIX_INFO, 0); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
977 g_free(strippedmsg); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
978 return 0; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
979 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
980 |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
981 /* 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
|
982 * for the given protocol id */ |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
983 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
|
984 { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
985 return 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 |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
988 /* Deallocate a string allocated by protocol_name */ |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
989 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
|
990 { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
991 /* 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
|
992 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
993 |
1299 | 994 /* Log a message. The passed message will end in "\n". */ |
995 static void cb_log_message(void *opdata, const char *message) | |
996 { | |
997 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message); | |
998 } | |
999 | |
2076
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1000 #else /* HAVE_LIBOTR3 */ |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1001 |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1002 /* Generate unique instance tag for account. */ |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1003 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
|
1004 const char *protocol) |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1005 { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1006 if (otrl_instag_generate(userstate, tagfile, accountname, protocol)) { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1007 scr_LogPrint(LPRINT_LOGNORM, "OTR instance tag generation failed!"); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1008 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1009 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1010 |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1011 static gboolean otr_timer_cb(gpointer userdata) |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1012 { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1013 otrl_message_poll(userstate, &ops, userdata); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1014 return TRUE; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1015 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1016 |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1017 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
|
1018 { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1019 if (otr_timer_source > 0) { |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1020 g_source_remove(otr_timer_source); |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1021 otr_timer_source = 0; |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1022 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1023 if (interval > 0) |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1024 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
|
1025 } |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1026 |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1027 #endif /* HAVE_LIBOTR3 */ |
9fb1ccf291cc
Switch to libotr v4 API
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1811
diff
changeset
|
1028 |
1299 | 1029 /* Find the maximum message size supported by this protocol. */ |
1030 static int cb_max_message_size(void *opdata, ConnContext *context) | |
1031 { | |
1032 return 8192; | |
1033 } | |
1034 | |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1035 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
|
1036 { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1037 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
|
1038 } |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1039 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1040 #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
|
1041 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1042 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
|
1043 { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1044 return FALSE; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1045 } |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1346
diff
changeset
|
1046 |
1299 | 1047 #endif /* HAVE_LIBOTR */ |
1599 | 1048 |
1811 | 1049 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ |