comparison mcabber/src/jabglue.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 44ff580ee388
children c373ff3fe7e1
comparison
equal deleted inserted replaced
1346:e36b21e11760 1347:07816313073b
602 // which hopefully will give us the most likely resource. 602 // which hopefully will give us the most likely resource.
603 if (rname) 603 if (rname)
604 rname++; 604 rname++;
605 605
606 #ifdef HAVE_LIBOTR 606 #ifdef HAVE_LIBOTR
607 if (msgid && strcmp(msgid, "otrinject") == 0) 607 if (otr_enabled()) {
608 msgid = NULL; 608 if (msgid && strcmp(msgid, "otrinject") == 0)
609 else if (type == ROSTER_TYPE_USER) { 609 msgid = NULL;
610 otr_msg = otr_send((char **)&text, barejid); 610 else if (type == ROSTER_TYPE_USER) {
611 if (!text) { 611 otr_msg = otr_send((char **)&text, barejid);
612 g_free(barejid); 612 if (!text) {
613 if (encrypted) 613 g_free(barejid);
614 *encrypted = -1; 614 if (encrypted)
615 return; 615 *encrypted = -1;
616 } 616 return;
617 } 617 }
618 if (otr_msg && encrypted) { 618 }
619 *encrypted = 1; 619 if (otr_msg && encrypted) {
620 *encrypted = 1;
621 }
620 } 622 }
621 #endif 623 #endif
622 624
623 #ifdef HAVE_GPGME 625 #ifdef HAVE_GPGME
624 if (type == ROSTER_TYPE_USER && sl_buddy && gpg_enabled()) { 626 if (type == ROSTER_TYPE_USER && sl_buddy && gpg_enabled()) {
1690 const char *enc, time_t timestamp, 1692 const char *enc, time_t timestamp,
1691 xmlnode xmldata_signed) 1693 xmlnode xmldata_signed)
1692 { 1694 {
1693 char *bjid; 1695 char *bjid;
1694 const char *rname, *s; 1696 const char *rname, *s;
1695 char *decrypted = NULL; 1697 char *decrypted_pgp = NULL;
1698 char *decrypted_otr = NULL;
1696 int otr_msg = 0, free_msg = 0; 1699 int otr_msg = 0, free_msg = 0;
1697 1700
1698 bjid = jidtodisp(from); 1701 bjid = jidtodisp(from);
1699 1702
1700 rname = strchr(from, JID_RESOURCE_SEPARATOR); 1703 rname = strchr(from, JID_RESOURCE_SEPARATOR);
1701 if (rname) rname++; 1704 if (rname) rname++;
1702 1705
1703 #ifdef HAVE_GPGME 1706 #ifdef HAVE_GPGME
1704 if (enc && gpg_enabled()) { 1707 if (enc && gpg_enabled()) {
1705 decrypted = gpg_decrypt(enc); 1708 decrypted_pgp = gpg_decrypt(enc);
1706 if (decrypted) { 1709 if (decrypted_pgp) {
1707 body = decrypted; 1710 body = decrypted_pgp;
1708 } 1711 }
1709 } 1712 }
1710 // Check signature of an unencrypted message 1713 // Check signature of an unencrypted message
1711 if (xmldata_signed && gpg_enabled()) 1714 if (xmldata_signed && gpg_enabled())
1712 check_signature(bjid, rname, xmldata_signed, decrypted); 1715 check_signature(bjid, rname, xmldata_signed, decrypted_pgp);
1713 #endif 1716 #endif
1714 1717
1715 #ifdef HAVE_LIBOTR 1718 #ifdef HAVE_LIBOTR
1716 otr_msg = otr_receive((char **)&body, bjid, &free_msg); 1719 if (otr_enabled()) {
1717 if (!body) { 1720 decrypted_otr = (char*)body;
1718 g_free(bjid); 1721 otr_msg = otr_receive(&decrypted_otr, bjid, &free_msg);
1719 return; 1722 if (!decrypted_otr) {
1723 goto gotmessage_return;
1724 }
1725 body = decrypted_otr;
1720 } 1726 }
1721 #endif 1727 #endif
1722 1728
1723 // Check for unexpected groupchat messages 1729 // Check for unexpected groupchat messages
1724 // If we receive a groupchat message from a room we're not a member of, 1730 // If we receive a groupchat message from a room we're not a member of,
1744 room_elt = roster_add_user(bjid, NULL, NULL, ROSTER_TYPE_ROOM, sub_none); 1750 room_elt = roster_add_user(bjid, NULL, NULL, ROSTER_TYPE_ROOM, sub_none);
1745 } else { 1751 } else {
1746 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); 1752 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
1747 } 1753 }
1748 1754
1749 g_free(bjid);
1750 g_free(decrypted);
1751 if (free_msg)
1752 g_free((char *)body);
1753
1754 buddylist_build(); 1755 buddylist_build();
1755 scr_DrawRoster(); 1756 scr_DrawRoster();
1756 return; 1757 goto gotmessage_return;
1757 } 1758 }
1758 1759
1759 // We don't call the message_in hook if 'block_unsubscribed' is true and 1760 // We don't call the message_in hook if 'block_unsubscribed' is true and
1760 // this is a regular message from an unsubscribed user. 1761 // this is a regular message from an unsubscribed user.
1761 // System messages (from our server) are allowed. 1762 // System messages (from our server) are allowed.
1762 if (!settings_opt_get_int("block_unsubscribed") || 1763 if (!settings_opt_get_int("block_unsubscribed") ||
1763 (roster_getsubscription(bjid) & sub_from) || 1764 (roster_getsubscription(bjid) & sub_from) ||
1764 (type && strcmp(type, "chat")) || 1765 (type && strcmp(type, "chat")) ||
1765 ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) { 1766 ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) {
1766 hk_message_in(bjid, rname, timestamp, body, type, 1767 hk_message_in(bjid, rname, timestamp, body, type,
1767 ((decrypted || otr_msg) ? TRUE : FALSE)); 1768 ((decrypted_pgp || otr_msg) ? TRUE : FALSE));
1768 } else { 1769 } else {
1769 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid); 1770 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid);
1770 } 1771 }
1772
1773 gotmessage_return:
1774 // Clean up and exit
1771 g_free(bjid); 1775 g_free(bjid);
1772 g_free(decrypted); 1776 g_free(decrypted_pgp);
1773 if (free_msg) 1777 if (free_msg)
1774 g_free((char *)body); 1778 g_free(decrypted_otr);
1775 } 1779 }
1776 1780
1777 static const char *defaulterrormsg(int code) 1781 static const char *defaulterrormsg(int code)
1778 { 1782 {
1779 const char *desc; 1783 const char *desc;