Mercurial > ~mikael > mcabber > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
1041:d4b97a2423eb | 1042:8a395c2cafc4 |
---|---|
30 #include "utils.h" | 30 #include "utils.h" |
31 #include "settings.h" | 31 #include "settings.h" |
32 #include "hbuf.h" | 32 #include "hbuf.h" |
33 #include "histolog.h" | 33 #include "histolog.h" |
34 #include "commands.h" | 34 #include "commands.h" |
35 #include "pgp.h" | |
35 | 36 |
36 #define JABBERPORT 5222 | 37 #define JABBERPORT 5222 |
37 #define JABBERSSLPORT 5223 | 38 #define JABBERSSLPORT 5223 |
38 | 39 |
39 #define RECONNECTION_TIMEOUT 60L | 40 #define RECONNECTION_TIMEOUT 60L |
427 | 428 |
428 // Only send the packet if we're online. | 429 // Only send the packet if we're online. |
429 // (But we want to update internal status even when disconnected, | 430 // (But we want to update internal status even when disconnected, |
430 // in order to avoid some problems during network failures) | 431 // in order to avoid some problems during network failures) |
431 if (online) { | 432 if (online) { |
432 x = presnew(st, recipient, (st != invisible ? msg : NULL)); | 433 const char *s_msg = (st != invisible ? msg : NULL); |
434 x = presnew(st, recipient, s_msg); | |
435 #ifdef HAVE_GPGME | |
436 if (s_msg && *s_msg && gpg_enabled()) { | |
437 char *signature = gpg_sign(s_msg); | |
438 if (signature) { | |
439 xmlnode y; | |
440 y = xmlnode_insert_tag(x, "x"); | |
441 xmlnode_put_attrib(y, "xmlns", NS_SIGNED); | |
442 xmlnode_insert_cdata(y, signature, (unsigned) -1); | |
443 g_free(signature); | |
444 } | |
445 } | |
446 #endif | |
433 jab_send(jc, x); | 447 jab_send(jc, x); |
434 xmlnode_free(x); | 448 xmlnode_free(x); |
435 } | 449 } |
436 | 450 |
437 // If we didn't change our _global_ status, we are done | 451 // If we didn't change our _global_ status, we are done |
1391 static void gotmessage(char *type, const char *from, const char *body, | 1405 static void gotmessage(char *type, const char *from, const char *body, |
1392 const char *enc, time_t timestamp) | 1406 const char *enc, time_t timestamp) |
1393 { | 1407 { |
1394 char *jid; | 1408 char *jid; |
1395 const char *rname, *s; | 1409 const char *rname, *s; |
1410 char *decrypted = NULL; | |
1396 | 1411 |
1397 jid = jidtodisp(from); | 1412 jid = jidtodisp(from); |
1398 | 1413 |
1399 rname = strchr(from, JID_RESOURCE_SEPARATOR); | 1414 rname = strchr(from, JID_RESOURCE_SEPARATOR); |
1400 if (rname) rname++; | 1415 if (rname) rname++; |
1416 | |
1417 #ifdef HAVE_GPGME | |
1418 if (enc && gpg_enabled()) { | |
1419 decrypted = gpg_decrypt(enc); | |
1420 if (decrypted) | |
1421 body = decrypted; | |
1422 } | |
1423 #endif | |
1401 | 1424 |
1402 // Check for unexpected groupchat messages | 1425 // Check for unexpected groupchat messages |
1403 // If we receive a groupchat message from a room we're not a member of, | 1426 // If we receive a groupchat message from a room we're not a member of, |
1404 // this is probably a server issue and the best we can do is to send | 1427 // this is probably a server issue and the best we can do is to send |
1405 // a type unavailable. | 1428 // a type unavailable. |
1424 } else { | 1447 } else { |
1425 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); | 1448 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
1426 } | 1449 } |
1427 | 1450 |
1428 g_free(jid); | 1451 g_free(jid); |
1452 g_free(decrypted); | |
1429 | 1453 |
1430 buddylist_build(); | 1454 buddylist_build(); |
1431 scr_DrawRoster(); | 1455 scr_DrawRoster(); |
1432 return; | 1456 return; |
1433 } | 1457 } |
1442 hk_message_in(jid, rname, timestamp, body, type); | 1466 hk_message_in(jid, rname, timestamp, body, type); |
1443 } else { | 1467 } else { |
1444 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", jid); | 1468 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", jid); |
1445 } | 1469 } |
1446 g_free(jid); | 1470 g_free(jid); |
1471 g_free(decrypted); | |
1447 } | 1472 } |
1448 | 1473 |
1449 static const char *defaulterrormsg(int code) | 1474 static const char *defaulterrormsg(int code) |
1450 { | 1475 { |
1451 const char *desc; | 1476 const char *desc; |