Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 1299:3b338a5c01fc
OTR support
author | Frank Zschockelt <mcabber_otr[at]freakysoft.de> |
---|---|
date | Thu, 30 Aug 2007 00:52:51 +0200 |
parents | e42f48103609 |
children | 8ada97e5eb75 |
comparison
equal
deleted
inserted
replaced
1298:af035a304bec | 1299:3b338a5c01fc |
---|---|
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 #include "pgp.h" |
36 #include "otr.h" | |
36 | 37 |
37 #define JABBERPORT 5222 | 38 #define JABBERPORT 5222 |
38 #define JABBERSSLPORT 5223 | 39 #define JABBERSSLPORT 5223 |
39 | 40 |
40 #define RECONNECTION_TIMEOUT 60L | 41 #define RECONNECTION_TIMEOUT 60L |
549 srand(now); | 550 srand(now); |
550 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); | 551 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); |
551 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); | 552 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); |
552 } | 553 } |
553 | 554 |
554 // jb_send_msg(jid, test, type, subject, msgid, *encrypted) | 555 // jb_send_msg(jid, text, type, subject, msgid, *encrypted) |
555 // When encrypted is not NULL, the function set *encrypted to 1 if the | 556 // When encrypted is not NULL, the function set *encrypted to 1 if the |
556 // message has been PGP-encrypted. If encryption enforcement is set and | 557 // message has been PGP-encrypted. If encryption enforcement is set and |
557 // encryption fails, *encrypted is set to -1. | 558 // encryption fails, *encrypted is set to -1. |
558 void jb_send_msg(const char *fjid, const char *text, int type, | 559 void jb_send_msg(const char *fjid, const char *text, int type, |
559 const char *subject, const char *msgid, gint *encrypted) | 560 const char *subject, const char *msgid, gint *encrypted) |
560 { | 561 { |
561 xmlnode x; | 562 xmlnode x; |
562 gchar *strtype; | 563 gchar *strtype; |
564 int otr_msg = 0; | |
563 #if defined HAVE_GPGME || defined JEP0022 || defined JEP0085 | 565 #if defined HAVE_GPGME || defined JEP0022 || defined JEP0085 |
564 char *rname, *barejid; | 566 char *rname, *barejid; |
565 GSList *sl_buddy; | 567 GSList *sl_buddy; |
566 #endif | 568 #endif |
567 #if defined JEP0022 || defined JEP0085 | 569 #if defined JEP0022 || defined JEP0085 |
582 if (type == ROSTER_TYPE_ROOM) | 584 if (type == ROSTER_TYPE_ROOM) |
583 strtype = TMSG_GROUPCHAT; | 585 strtype = TMSG_GROUPCHAT; |
584 else | 586 else |
585 strtype = TMSG_CHAT; | 587 strtype = TMSG_CHAT; |
586 | 588 |
587 #if defined HAVE_GPGME || defined JEP0022 || defined JEP0085 | 589 #if defined HAVE_GPGME || defined HAVE_LIBOTR || defined JEP0022 || defined JEP0085 |
588 rname = strchr(fjid, JID_RESOURCE_SEPARATOR); | 590 rname = strchr(fjid, JID_RESOURCE_SEPARATOR); |
589 barejid = jidtodisp(fjid); | 591 barejid = jidtodisp(fjid); |
590 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); | 592 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); |
591 | 593 |
592 // If we can get a resource name, we use it. Else we use NULL, | 594 // If we can get a resource name, we use it. Else we use NULL, |
593 // which hopefully will give us the most likely resource. | 595 // which hopefully will give us the most likely resource. |
594 if (rname) | 596 if (rname) |
595 rname++; | 597 rname++; |
598 | |
599 #ifdef HAVE_LIBOTR | |
600 if (msgid && strcmp(msgid, "otrinject") == 0) | |
601 msgid = NULL; | |
602 else { | |
603 otr_msg = otr_send((char **)&text, barejid); | |
604 if (!text) { | |
605 g_free(barejid); | |
606 if (encrypted) | |
607 *encrypted = -1; | |
608 return; | |
609 } | |
610 } | |
611 if (otr_msg && encrypted) { | |
612 *encrypted = 1; | |
613 } | |
614 #endif | |
596 | 615 |
597 #ifdef HAVE_GPGME | 616 #ifdef HAVE_GPGME |
598 if (type == ROSTER_TYPE_USER && sl_buddy && gpg_enabled()) { | 617 if (type == ROSTER_TYPE_USER && sl_buddy && gpg_enabled()) { |
599 if (!settings_pgp_getdisabled(barejid)) { // not disabled for this contact? | 618 if (!settings_pgp_getdisabled(barejid)) { // not disabled for this contact? |
600 guint force; | 619 guint force; |
1667 xmlnode xmldata_signed) | 1686 xmlnode xmldata_signed) |
1668 { | 1687 { |
1669 char *bjid; | 1688 char *bjid; |
1670 const char *rname, *s; | 1689 const char *rname, *s; |
1671 char *decrypted = NULL; | 1690 char *decrypted = NULL; |
1691 int otr_msg = 0, free_msg = 0; | |
1672 | 1692 |
1673 bjid = jidtodisp(from); | 1693 bjid = jidtodisp(from); |
1674 | 1694 |
1675 rname = strchr(from, JID_RESOURCE_SEPARATOR); | 1695 rname = strchr(from, JID_RESOURCE_SEPARATOR); |
1676 if (rname) rname++; | 1696 if (rname) rname++; |
1683 } | 1703 } |
1684 } | 1704 } |
1685 // Check signature of an unencrypted message | 1705 // Check signature of an unencrypted message |
1686 if (xmldata_signed && gpg_enabled()) | 1706 if (xmldata_signed && gpg_enabled()) |
1687 check_signature(bjid, rname, xmldata_signed, decrypted); | 1707 check_signature(bjid, rname, xmldata_signed, decrypted); |
1708 #endif | |
1709 | |
1710 #ifdef HAVE_LIBOTR | |
1711 otr_msg = otr_receive((char **)&body, bjid, &free_msg); | |
1712 if(!body){ | |
1713 g_free(bjid); | |
1714 return; | |
1715 } | |
1688 #endif | 1716 #endif |
1689 | 1717 |
1690 // Check for unexpected groupchat messages | 1718 // Check for unexpected groupchat messages |
1691 // If we receive a groupchat message from a room we're not a member of, | 1719 // If we receive a groupchat message from a room we're not a member of, |
1692 // this is probably a server issue and the best we can do is to send | 1720 // this is probably a server issue and the best we can do is to send |
1713 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); | 1741 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
1714 } | 1742 } |
1715 | 1743 |
1716 g_free(bjid); | 1744 g_free(bjid); |
1717 g_free(decrypted); | 1745 g_free(decrypted); |
1746 if(free_msg) | |
1747 g_free((char *)body); | |
1718 | 1748 |
1719 buddylist_build(); | 1749 buddylist_build(); |
1720 scr_DrawRoster(); | 1750 scr_DrawRoster(); |
1721 return; | 1751 return; |
1722 } | 1752 } |
1727 if (!settings_opt_get_int("block_unsubscribed") || | 1757 if (!settings_opt_get_int("block_unsubscribed") || |
1728 (roster_getsubscription(bjid) & sub_from) || | 1758 (roster_getsubscription(bjid) & sub_from) || |
1729 (type && strcmp(type, "chat")) || | 1759 (type && strcmp(type, "chat")) || |
1730 ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) { | 1760 ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) { |
1731 hk_message_in(bjid, rname, timestamp, body, type, | 1761 hk_message_in(bjid, rname, timestamp, body, type, |
1732 (decrypted ? TRUE : FALSE)); | 1762 ((decrypted || otr_msg) ? TRUE : FALSE)); |
1733 } else { | 1763 } else { |
1734 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid); | 1764 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid); |
1735 } | 1765 } |
1736 g_free(bjid); | 1766 g_free(bjid); |
1737 g_free(decrypted); | 1767 g_free(decrypted); |
1768 if(free_msg) | |
1769 g_free((char *)body); | |
1738 } | 1770 } |
1739 | 1771 |
1740 static const char *defaulterrormsg(int code) | 1772 static const char *defaulterrormsg(int code) |
1741 { | 1773 { |
1742 const char *desc; | 1774 const char *desc; |