changeset 1577:e1a642472f4e

Use otr context where possible, saves one mc_strtolower() per received message
author franky
date Sun, 12 Apr 2009 20:20:56 +0200
parents 72fef01d9061
children 5bb4b580f229
files mcabber/src/jabglue.c mcabber/src/otr.c
diffstat 2 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Tue Jan 27 22:24:02 2009 +0100
+++ b/mcabber/src/jabglue.c	Sun Apr 12 20:20:56 2009 +0200
@@ -1811,7 +1811,6 @@
 #ifdef HAVE_LIBOTR
   if (otr_enabled()) {
     decrypted_otr = (char*)body;
-    mc_strtolower(bjid);
     otr_msg = otr_receive(&decrypted_otr, bjid, &free_msg);
     if (!decrypted_otr) {
       goto gotmessage_return;
--- a/mcabber/src/otr.c	Tue Jan 27 22:24:02 2009 +0100
+++ b/mcabber/src/otr.c	Sun Apr 12 20:20:56 2009 +0200
@@ -34,6 +34,7 @@
 #include "settings.h"
 #include "nohtml.h"
 
+#define OTR_PROTOCOL_NAME "jabber"
 
 static OtrlUserState userstate = NULL;
 static char * account = NULL;
@@ -128,7 +129,7 @@
 
   OTRL_INIT;
 
-  userstate = otrl_userstate_create ();
+  userstate = otrl_userstate_create();
 
   root = otr_get_dir();
   account = jidtodisp(fjid);
@@ -138,7 +139,7 @@
 
   if (otrl_privkey_read(userstate, keyfile)){
     scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile);
-    cb_create_privkey(NULL, account, "jabber");
+    cb_create_privkey(NULL, account, OTR_PROTOCOL_NAME);
   }
   if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){
     scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s",
@@ -204,8 +205,8 @@
   char * lowcasebuddy = g_strdup(buddy);
 
   mc_strtolower(lowcasebuddy);
-  ctx = otrl_context_find(userstate, lowcasebuddy, account, "jabber", 1, &null,
-                          NULL, NULL);
+  ctx = otrl_context_find(userstate, lowcasebuddy, account, OTR_PROTOCOL_NAME,
+                          1, &null, NULL, NULL);
   g_free(lowcasebuddy);
   return ctx;
 }
@@ -365,18 +366,20 @@
   OtrlTLV *tlv = NULL;
   ConnContext * ctx;
 
+  ctx = otr_get_context(buddy);
   *free_msg = 0;
-  ignore_message = otrl_message_receiving(userstate, &ops, NULL, account,
-    "jabber", buddy, *otr_data, &newmessage, &tlvs, NULL, NULL);
+  ignore_message = otrl_message_receiving(userstate, &ops, NULL,
+                                          ctx->accountname, ctx->protocol,
+                                          ctx->username, *otr_data,
+                                          &newmessage, &tlvs,NULL, NULL);
 
-  ctx = otr_get_context(buddy);
 
   tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
   if (tlv) {
     /* Notify the user that the other side disconnected. */
     if (ctx) {
       cb_gone_insecure(NULL, ctx);
-      otr_disconnect(buddy);
+      otr_disconnect(ctx->username);
     }
   }
 
@@ -407,8 +410,9 @@
 
   htmlmsg = html_escape(*msg);
 
-  err = otrl_message_sending(userstate, &ops, NULL, account, "jabber", buddy,
-                             htmlmsg, NULL, &newmessage, NULL, NULL);
+  err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname,
+                             ctx->protocol, ctx->username, htmlmsg, NULL,
+                             &newmessage, NULL, NULL);
 
   g_free(htmlmsg);
 
@@ -430,7 +434,7 @@
 {
   const char *state, *auth, *policy;
   ConnContext * ctx = otr_get_context(buddy);
-  OtrlPolicy p = cb_policy (ctx->app_data, ctx);
+  OtrlPolicy p = cb_policy(ctx->app_data, ctx);
 
   if (!userstate || !ctx)
     return;