diff mcabber/src/otr.c @ 1347:07816313073b

Add an option 'otr' to enable OTR support in the configuration file
author Mikael Berthe <mikael@lilotux.net>
date Fri, 09 Nov 2007 23:14:03 +0100
parents e36b21e11760
children 08f641e91f94
line wrap: on
line diff
--- 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... */