comparison libpurple/protocols/jabber/jabber.c @ 25980:13541e130064

propagate from branch 'im.pidgin.pidgin' (head 431618de0f30a6938f7e14d2d61ee5d7738acd59) to branch 'im.pidgin.cpw.malu.xmpp.idle' (head f8e9aac4fdd81fdf8e998b2ea726f2b97c06fc84)
author Marcus Lundblad <ml@update.uu.se>
date Mon, 02 Mar 2009 21:25:31 +0000
parents 5f9a24d1c25e 754d7d478066
children 12c2f11bb113
comparison
equal deleted inserted replaced
25446:52fbda23e398 25980:13541e130064
34 #include "privacy.h" 34 #include "privacy.h"
35 #include "proxy.h" 35 #include "proxy.h"
36 #include "prpl.h" 36 #include "prpl.h"
37 #include "request.h" 37 #include "request.h"
38 #include "server.h" 38 #include "server.h"
39 #include "status.h"
39 #include "util.h" 40 #include "util.h"
40 #include "version.h" 41 #include "version.h"
41 #include "xmlnode.h" 42 #include "xmlnode.h"
42 43
43 #include "auth.h" 44 #include "auth.h"
706 { 707 {
707 PurpleConnection *gc = purple_account_get_connection(account); 708 PurpleConnection *gc = purple_account_get_connection(account);
708 const char *connect_server = purple_account_get_string(account, 709 const char *connect_server = purple_account_get_string(account,
709 "connect_server", ""); 710 "connect_server", "");
710 JabberStream *js; 711 JabberStream *js;
712 PurplePresence *presence;
711 JabberBuddy *my_jb = NULL; 713 JabberBuddy *my_jb = NULL;
712 714
713 gc->flags |= PURPLE_CONNECTION_HTML | 715 gc->flags |= PURPLE_CONNECTION_HTML |
714 PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY; 716 PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
715 js = gc->proto_data = g_new0(JabberStream, 1); 717 js = gc->proto_data = g_new0(JabberStream, 1);
727 js->next_id = g_random_int(); 729 js->next_id = g_random_int();
728 js->write_buffer = purple_circ_buffer_new(512); 730 js->write_buffer = purple_circ_buffer_new(512);
729 js->old_length = 0; 731 js->old_length = 0;
730 js->keepalive_timeout = -1; 732 js->keepalive_timeout = -1;
731 js->certificate_CN = g_strdup(connect_server[0] ? connect_server : js->user ? js->user->domain : NULL); 733 js->certificate_CN = g_strdup(connect_server[0] ? connect_server : js->user ? js->user->domain : NULL);
734
735 /* if we are idle, set idle-ness on the stream (this could happen if we get
736 disconnected and the reconnects while being idle. I don't think it makes
737 sense to do this when registering a new account... */
738 presence = purple_account_get_presence(account);
739 if (purple_presence_is_idle(presence))
740 js->idle = purple_presence_get_idle_time(presence);
732 741
733 if(!js->user) { 742 if(!js->user) {
734 purple_connection_error_reason (gc, 743 purple_connection_error_reason (gc,
735 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 744 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
736 _("Invalid XMPP ID")); 745 _("Invalid XMPP ID"));
1486 1495
1487 1496
1488 void jabber_idle_set(PurpleConnection *gc, int idle) 1497 void jabber_idle_set(PurpleConnection *gc, int idle)
1489 { 1498 {
1490 JabberStream *js = gc->proto_data; 1499 JabberStream *js = gc->proto_data;
1491 1500 PurpleAccount *account = purple_connection_get_account(gc);
1501 PurpleStatus *status = purple_account_get_active_status(account);
1502
1492 js->idle = idle ? time(NULL) - idle : idle; 1503 js->idle = idle ? time(NULL) - idle : idle;
1504
1505 /* send out an updated prescence */
1506 purple_debug_info("jabber", "sending updated presence for idle\n");
1507 jabber_presence_send(account, status);
1493 } 1508 }
1494 1509
1495 static void jabber_blocklist_parse(JabberStream *js, xmlnode *packet, gpointer data) 1510 static void jabber_blocklist_parse(JabberStream *js, xmlnode *packet, gpointer data)
1496 { 1511 {
1497 xmlnode *blocklist, *item; 1512 xmlnode *blocklist, *item;
1682 } 1697 }
1683 1698
1684 return ret; 1699 return ret;
1685 } 1700 }
1686 1701
1702 static void
1703 jabber_tooltip_add_resource_text(JabberBuddyResource *jbr,
1704 PurpleNotifyUserInfo *user_info, gboolean multiple_resources)
1705 {
1706 char *text = NULL;
1707 char *res = NULL;
1708 char *label, *value;
1709 const char *state;
1710
1711 if(jbr->status) {
1712 char *tmp;
1713 text = purple_strreplace(jbr->status, "\n", "<br />\n");
1714 tmp = purple_markup_strip_html(text);
1715 g_free(text);
1716 text = g_markup_escape_text(tmp, -1);
1717 g_free(tmp);
1718 }
1719
1720 if(jbr->name)
1721 res = g_strdup_printf(" (%s)", jbr->name);
1722
1723 state = jabber_buddy_state_get_name(jbr->state);
1724 if (text != NULL && !purple_utf8_strcasecmp(state, text)) {
1725 g_free(text);
1726 text = NULL;
1727 }
1728
1729 label = g_strdup_printf("%s%s", _("Status"), (res ? res : ""));
1730 value = g_strdup_printf("%s%s%s", state, (text ? ": " : ""), (text ? text : ""));
1731
1732 purple_notify_user_info_add_pair(user_info, label, value);
1733 g_free(label);
1734 g_free(value);
1735 g_free(text);
1736
1737 /* if the resource is idle, show that */
1738 /* only show it if there is more than one resource available for
1739 the buddy, since the "general" idleness will be shown anyway,
1740 this way we can see see the idleness of lower-priority resources */
1741 if (jbr->idle && multiple_resources) {
1742 gchar *idle_str =
1743 purple_str_seconds_to_string(time(NULL) - jbr->idle);
1744 label = g_strdup_printf("%s%s", _("Idle"), (res ? res : ""));
1745 purple_notify_user_info_add_pair(user_info, label, idle_str);
1746 g_free(idle_str);
1747 g_free(label);
1748 }
1749 g_free(res);
1750 }
1751
1687 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full) 1752 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full)
1688 { 1753 {
1689 JabberBuddy *jb; 1754 JabberBuddy *jb;
1690 PurpleAccount *account; 1755 PurpleAccount *account;
1691 PurpleConnection *gc; 1756 PurpleConnection *gc;
1692 1757
1693 g_return_if_fail(b != NULL); 1758 g_return_if_fail(b != NULL);
1694 1759
1695 account = purple_buddy_get_account(b); 1760 account = purple_buddy_get_account(b);
1696 g_return_if_fail(account != NULL); 1761 g_return_if_fail(account != NULL);
1697 1762
1705 JabberBuddyResource *jbr = NULL; 1770 JabberBuddyResource *jbr = NULL;
1706 PurplePresence *presence = purple_buddy_get_presence(b); 1771 PurplePresence *presence = purple_buddy_get_presence(b);
1707 const char *sub; 1772 const char *sub;
1708 GList *l; 1773 GList *l;
1709 const char *mood; 1774 const char *mood;
1710 1775 gboolean multiple_resources =
1776 jb->resources && g_list_next(jb->resources);
1777 JabberBuddyResource *top_jbr = jabber_buddy_find_resource(jb, NULL);
1778
1779 /* resource-specific info for the top resource */
1780 if (top_jbr) {
1781 jabber_tooltip_add_resource_text(top_jbr, user_info,
1782 multiple_resources);
1783 }
1784
1785 for(l=jb->resources; l; l = l->next) {
1786 jbr = l->data;
1787 /* the remaining resources */
1788 if (jbr != top_jbr) {
1789 jabber_tooltip_add_resource_text(jbr, user_info,
1790 multiple_resources);
1791 }
1792 }
1793
1711 if (full) { 1794 if (full) {
1712 PurpleStatus *status; 1795 PurpleStatus *status;
1713
1714 if(jb->subscription & JABBER_SUB_FROM) {
1715 if(jb->subscription & JABBER_SUB_TO)
1716 sub = _("Both");
1717 else if(jb->subscription & JABBER_SUB_PENDING)
1718 sub = _("From (To pending)");
1719 else
1720 sub = _("From");
1721 } else {
1722 if(jb->subscription & JABBER_SUB_TO)
1723 sub = _("To");
1724 else if(jb->subscription & JABBER_SUB_PENDING)
1725 sub = _("None (To pending)");
1726 else
1727 sub = _("None");
1728 }
1729
1730 purple_notify_user_info_add_pair(user_info, _("Subscription"), sub);
1731 1796
1732 status = purple_presence_get_active_status(presence); 1797 status = purple_presence_get_active_status(presence);
1733 mood = purple_status_get_attr_string(status, "mood"); 1798 mood = purple_status_get_attr_string(status, "mood");
1734 if(mood != NULL) { 1799 if(mood != NULL) {
1735 const char *moodtext; 1800 const char *moodtext;
1751 if (playing) { 1816 if (playing) {
1752 purple_notify_user_info_add_pair(user_info, _("Now Listening"), playing); 1817 purple_notify_user_info_add_pair(user_info, _("Now Listening"), playing);
1753 g_free(playing); 1818 g_free(playing);
1754 } 1819 }
1755 } 1820 }
1756 } 1821
1757 1822 if(jb->subscription & JABBER_SUB_FROM) {
1758 for(l=jb->resources; l; l = l->next) { 1823 if(jb->subscription & JABBER_SUB_TO)
1759 char *text = NULL; 1824 sub = _("Both");
1760 char *res = NULL; 1825 else if(jb->subscription & JABBER_SUB_PENDING)
1761 char *label, *value; 1826 sub = _("From (To pending)");
1762 const char *state; 1827 else
1763 1828 sub = _("From");
1764 jbr = l->data; 1829 } else {
1765 1830 if(jb->subscription & JABBER_SUB_TO)
1766 if(jbr->status) { 1831 sub = _("To");
1767 char *tmp; 1832 else if(jb->subscription & JABBER_SUB_PENDING)
1768 text = purple_strreplace(jbr->status, "\n", "<br />\n"); 1833 sub = _("None (To pending)");
1769 tmp = purple_markup_strip_html(text); 1834 else
1770 g_free(text); 1835 sub = _("None");
1771 text = g_markup_escape_text(tmp, -1);
1772 g_free(tmp);
1773 } 1836 }
1774 1837
1775 if(jbr->name) 1838 purple_notify_user_info_add_pair(user_info, _("Subscription"), sub);
1776 res = g_strdup_printf(" (%s)", jbr->name); 1839
1777 1840 }
1778 state = jabber_buddy_state_get_name(jbr->state); 1841
1779 if (text != NULL && !purple_utf8_strcasecmp(state, text)) {
1780 g_free(text);
1781 text = NULL;
1782 }
1783
1784 label = g_strdup_printf("%s%s",
1785 _("Status"), (res ? res : ""));
1786 value = g_strdup_printf("%s%s%s",
1787 state,
1788 (text ? ": " : ""),
1789 (text ? text : ""));
1790
1791 purple_notify_user_info_add_pair(user_info, label, value);
1792
1793 g_free(label);
1794 g_free(value);
1795 g_free(text);
1796 g_free(res);
1797 }
1798
1799 if(!PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) { 1842 if(!PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) {
1800 purple_notify_user_info_add_pair(user_info, _("Error"), jb->error_msg); 1843 purple_notify_user_info_add_pair(user_info, _("Error"), jb->error_msg);
1801 } 1844 }
1802 } 1845 }
1803 } 1846 }