diff mcabber/src/jabglue.c @ 1042:8a395c2cafc4

Initial PGP support (decrypt) This patch initialize the PGP (GPG) sub-system, and adds a few PGP-related options to the configuration file. Encrypted messages can be processed. Presence is signed when the status message is non-empty.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 26 Nov 2006 10:42:25 +0100
parents 94d9a3cbb211
children ebbde723614b
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Sun Nov 26 10:30:52 2006 +0100
+++ b/mcabber/src/jabglue.c	Sun Nov 26 10:42:25 2006 +0100
@@ -32,6 +32,7 @@
 #include "hbuf.h"
 #include "histolog.h"
 #include "commands.h"
+#include "pgp.h"
 
 #define JABBERPORT      5222
 #define JABBERSSLPORT   5223
@@ -429,7 +430,20 @@
   // (But we want to update internal status even when disconnected,
   // in order to avoid some problems during network failures)
   if (online) {
-    x = presnew(st, recipient, (st != invisible ? msg : NULL));
+    const char *s_msg = (st != invisible ? msg : NULL);
+    x = presnew(st, recipient, s_msg);
+#ifdef HAVE_GPGME
+    if (s_msg && *s_msg && gpg_enabled()) {
+      char *signature = gpg_sign(s_msg);
+      if (signature) {
+        xmlnode y;
+        y = xmlnode_insert_tag(x, "x");
+        xmlnode_put_attrib(y, "xmlns", NS_SIGNED);
+        xmlnode_insert_cdata(y, signature, (unsigned) -1);
+        g_free(signature);
+      }
+    }
+#endif
     jab_send(jc, x);
     xmlnode_free(x);
   }
@@ -1393,12 +1407,21 @@
 {
   char *jid;
   const char *rname, *s;
+  char *decrypted = NULL;
 
   jid = jidtodisp(from);
 
   rname = strchr(from, JID_RESOURCE_SEPARATOR);
   if (rname) rname++;
 
+#ifdef HAVE_GPGME
+  if (enc && gpg_enabled()) {
+    decrypted = gpg_decrypt(enc);
+    if (decrypted)
+      body = decrypted;
+  }
+#endif
+
   // Check for unexpected groupchat messages
   // If we receive a groupchat message from a room we're not a member of,
   // this is probably a server issue and the best we can do is to send
@@ -1426,6 +1449,7 @@
     }
 
     g_free(jid);
+    g_free(decrypted);
 
     buddylist_build();
     scr_DrawRoster();
@@ -1444,6 +1468,7 @@
     scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", jid);
   }
   g_free(jid);
+  g_free(decrypted);
 }
 
 static const char *defaulterrormsg(int code)