--- a/mcabber/mcabberrc.example Fri Nov 09 20:09:47 2007 +0100
+++ b/mcabber/mcabberrc.example Fri Nov 09 23:14:03 2007 +0100
@@ -362,9 +362,15 @@
#pgp disable foo@bar.org
#pgp setkey bar@foo.net C9940A9BB0B92210
+# OTR (Off-The-Record messaging) support
+# (Only available if mcabber is built with OTR support)
+# Set otr to 1 to enable OTR support.
+# You cannot change this option once mcabber is running.
+#set otr = 0
+#
# OTR directory
-# If mcabber is built with OTR (Off-The-Record) support, you can specify
-# the OTR directory with the otr_dir option (default = ~/.mcabber/otr/).
+# You can specify the OTR directory with the otr_dir option
+# (default = ~/.mcabber/otr/).
#set otr_dir = "~/.mcabber/otr/"
# Aliases
--- a/mcabber/src/commands.c Fri Nov 09 20:09:47 2007 +0100
+++ b/mcabber/src/commands.c Fri Nov 09 23:14:03 2007 +0100
@@ -2973,6 +2973,12 @@
otr_info
} op = 0;
+ if (!otr_enabled()) {
+ scr_LogPrint(LPRINT_LOGNORM,
+ "Warning: OTR hasn't been enabled -- command ignored.");
+ return;
+ }
+
paramlst = split_arg(arg, 3, 0); // subcmd, jid, [key]
subcmd = *paramlst;
fjid = *(paramlst+1);
@@ -3097,6 +3103,12 @@
char *fjid, *policy;
enum otr_policy p;
+ if (!otr_enabled()) {
+ scr_LogPrint(LPRINT_LOGNORM,
+ "Warning: OTR hasn't been enabled -- command ignored.");
+ return;
+ }
+
paramlst = split_arg(arg, 2, 0); // [jid|default] policy
fjid = *paramlst;
policy = *(paramlst+1);
--- a/mcabber/src/jabglue.c Fri Nov 09 20:09:47 2007 +0100
+++ b/mcabber/src/jabglue.c Fri Nov 09 23:14:03 2007 +0100
@@ -604,19 +604,21 @@
rname++;
#ifdef HAVE_LIBOTR
- if (msgid && strcmp(msgid, "otrinject") == 0)
- msgid = NULL;
- else if (type == ROSTER_TYPE_USER) {
- otr_msg = otr_send((char **)&text, barejid);
- if (!text) {
- g_free(barejid);
- if (encrypted)
- *encrypted = -1;
- return;
+ if (otr_enabled()) {
+ if (msgid && strcmp(msgid, "otrinject") == 0)
+ msgid = NULL;
+ else if (type == ROSTER_TYPE_USER) {
+ otr_msg = otr_send((char **)&text, barejid);
+ if (!text) {
+ g_free(barejid);
+ if (encrypted)
+ *encrypted = -1;
+ return;
+ }
}
- }
- if (otr_msg && encrypted) {
- *encrypted = 1;
+ if (otr_msg && encrypted) {
+ *encrypted = 1;
+ }
}
#endif
@@ -1692,7 +1694,8 @@
{
char *bjid;
const char *rname, *s;
- char *decrypted = NULL;
+ char *decrypted_pgp = NULL;
+ char *decrypted_otr = NULL;
int otr_msg = 0, free_msg = 0;
bjid = jidtodisp(from);
@@ -1702,21 +1705,24 @@
#ifdef HAVE_GPGME
if (enc && gpg_enabled()) {
- decrypted = gpg_decrypt(enc);
- if (decrypted) {
- body = decrypted;
+ decrypted_pgp = gpg_decrypt(enc);
+ if (decrypted_pgp) {
+ body = decrypted_pgp;
}
}
// Check signature of an unencrypted message
if (xmldata_signed && gpg_enabled())
- check_signature(bjid, rname, xmldata_signed, decrypted);
+ check_signature(bjid, rname, xmldata_signed, decrypted_pgp);
#endif
#ifdef HAVE_LIBOTR
- otr_msg = otr_receive((char **)&body, bjid, &free_msg);
- if (!body) {
- g_free(bjid);
- return;
+ if (otr_enabled()) {
+ decrypted_otr = (char*)body;
+ otr_msg = otr_receive(&decrypted_otr, bjid, &free_msg);
+ if (!decrypted_otr) {
+ goto gotmessage_return;
+ }
+ body = decrypted_otr;
}
#endif
@@ -1746,14 +1752,9 @@
buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
}
- g_free(bjid);
- g_free(decrypted);
- if (free_msg)
- g_free((char *)body);
-
buddylist_build();
scr_DrawRoster();
- return;
+ goto gotmessage_return;
}
// We don't call the message_in hook if 'block_unsubscribed' is true and
@@ -1764,14 +1765,17 @@
(type && strcmp(type, "chat")) ||
((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) {
hk_message_in(bjid, rname, timestamp, body, type,
- ((decrypted || otr_msg) ? TRUE : FALSE));
+ ((decrypted_pgp || otr_msg) ? TRUE : FALSE));
} else {
scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid);
}
+
+gotmessage_return:
+ // Clean up and exit
g_free(bjid);
- g_free(decrypted);
+ g_free(decrypted_pgp);
if (free_msg)
- g_free((char *)body);
+ g_free(decrypted_otr);
}
static const char *defaulterrormsg(int code)
--- a/mcabber/src/otr.c Fri Nov 09 20:09:47 2007 +0100
+++ b/mcabber/src/otr.c Fri Nov 09 23:14:03 2007 +0100
@@ -38,6 +38,7 @@
static char * keyfile = NULL;
static char * fprfile = NULL;
+static int otr_is_enabled = FALSE;
static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx);
static void cb_create_privkey (void *opdata,
@@ -113,15 +114,23 @@
void otr_init(const char *jid)
{
- char * root = otr_get_dir();
+ char *root;
+
+ otr_is_enabled = !!settings_opt_get_int("otr");
+
+ if (!otr_is_enabled)
+ return;
+
+ OTRL_INIT;
+
+ userstate = otrl_userstate_create ();
+
+ root = otr_get_dir();
account = jidtodisp(jid);
keyfile = g_strdup_printf("%s%s.key", root, account);
fprfile = g_strdup_printf("%s%s.fpr", root, account);
g_free(root);
- OTRL_INIT;
-
- userstate = otrl_userstate_create ();
if (otrl_privkey_read(userstate, keyfile)){
scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile);
cb_create_privkey(NULL, account, "jabber");
@@ -136,6 +145,9 @@
{
ConnContext * ctx;
+ if (!otr_is_enabled)
+ return;
+
for (ctx = userstate->context_root; ctx; ctx = ctx->next)
if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
otr_message_disconnect(ctx);
@@ -723,5 +735,17 @@
return 8192;
}
+int otr_enabled(void)
+{
+ return otr_is_enabled;
+}
+
+#else /* !HAVE_LIBOTR */
+
+int otr_enabled(void)
+{
+ return FALSE;
+}
+
#endif /* HAVE_LIBOTR */
/* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */