Mercurial > pidgin
comparison libpurple/protocols/jabber/jabber.c @ 25700:754d7d478066
propagate from branch 'im.pidgin.pidgin' (head 53ec2e73334e6dc99c29f0f13b5ebf4700f5a92c)
to branch 'im.pidgin.cpw.malu.xmpp.idle' (head 998ac348cf55dd61a2a703da36be37389b50a764)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Tue, 24 Feb 2009 20:26:02 +0000 |
parents | b90c26f391b0 a2388ce30772 |
children | 13541e130064 |
comparison
equal
deleted
inserted
replaced
25520:7c21fb8132f7 | 25700:754d7d478066 |
---|---|
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; |
1679 } | 1694 } |
1680 | 1695 |
1681 return ret; | 1696 return ret; |
1682 } | 1697 } |
1683 | 1698 |
1699 static void | |
1700 jabber_tooltip_add_resource_text(JabberBuddyResource *jbr, | |
1701 PurpleNotifyUserInfo *user_info, gboolean multiple_resources) | |
1702 { | |
1703 char *text = NULL; | |
1704 char *res = NULL; | |
1705 char *label, *value; | |
1706 const char *state; | |
1707 | |
1708 if(jbr->status) { | |
1709 char *tmp; | |
1710 text = purple_strreplace(jbr->status, "\n", "<br />\n"); | |
1711 tmp = purple_markup_strip_html(text); | |
1712 g_free(text); | |
1713 text = g_markup_escape_text(tmp, -1); | |
1714 g_free(tmp); | |
1715 } | |
1716 | |
1717 if(jbr->name) | |
1718 res = g_strdup_printf(" (%s)", jbr->name); | |
1719 | |
1720 state = jabber_buddy_state_get_name(jbr->state); | |
1721 if (text != NULL && !purple_utf8_strcasecmp(state, text)) { | |
1722 g_free(text); | |
1723 text = NULL; | |
1724 } | |
1725 | |
1726 label = g_strdup_printf("%s%s", _("Status"), (res ? res : "")); | |
1727 value = g_strdup_printf("%s%s%s", state, (text ? ": " : ""), (text ? text : "")); | |
1728 | |
1729 purple_notify_user_info_add_pair(user_info, label, value); | |
1730 g_free(label); | |
1731 g_free(value); | |
1732 g_free(text); | |
1733 | |
1734 /* if the resource is idle, show that */ | |
1735 /* only show it if there is more than one resource available for | |
1736 the buddy, since the "general" idleness will be shown anyway, | |
1737 this way we can see see the idleness of lower-priority resources */ | |
1738 if (jbr->idle && multiple_resources) { | |
1739 gchar *idle_str = | |
1740 purple_str_seconds_to_string(time(NULL) - jbr->idle); | |
1741 label = g_strdup_printf("%s%s", _("Idle"), (res ? res : "")); | |
1742 purple_notify_user_info_add_pair(user_info, label, idle_str); | |
1743 g_free(idle_str); | |
1744 g_free(label); | |
1745 } | |
1746 g_free(res); | |
1747 } | |
1748 | |
1684 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full) | 1749 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full) |
1685 { | 1750 { |
1686 JabberBuddy *jb; | 1751 JabberBuddy *jb; |
1687 | 1752 |
1688 g_return_if_fail(b != NULL); | 1753 g_return_if_fail(b != NULL); |
1689 g_return_if_fail(b->account != NULL); | 1754 g_return_if_fail(b->account != NULL); |
1690 g_return_if_fail(b->account->gc != NULL); | 1755 g_return_if_fail(b->account->gc != NULL); |
1691 g_return_if_fail(b->account->gc->proto_data != NULL); | 1756 g_return_if_fail(b->account->gc->proto_data != NULL); |
1692 | 1757 |
1697 JabberBuddyResource *jbr = NULL; | 1762 JabberBuddyResource *jbr = NULL; |
1698 PurplePresence *presence = purple_buddy_get_presence(b); | 1763 PurplePresence *presence = purple_buddy_get_presence(b); |
1699 const char *sub; | 1764 const char *sub; |
1700 GList *l; | 1765 GList *l; |
1701 const char *mood; | 1766 const char *mood; |
1702 | 1767 gboolean multiple_resources = |
1768 jb->resources && g_list_next(jb->resources); | |
1769 JabberBuddyResource *top_jbr = jabber_buddy_find_resource(jb, NULL); | |
1770 | |
1771 /* resource-specific info for the top resource */ | |
1772 if (top_jbr) { | |
1773 jabber_tooltip_add_resource_text(top_jbr, user_info, | |
1774 multiple_resources); | |
1775 } | |
1776 | |
1777 for(l=jb->resources; l; l = l->next) { | |
1778 jbr = l->data; | |
1779 /* the remaining resources */ | |
1780 if (jbr != top_jbr) { | |
1781 jabber_tooltip_add_resource_text(jbr, user_info, | |
1782 multiple_resources); | |
1783 } | |
1784 } | |
1785 | |
1703 if (full) { | 1786 if (full) { |
1704 PurpleStatus *status; | 1787 PurpleStatus *status; |
1705 | |
1706 if(jb->subscription & JABBER_SUB_FROM) { | |
1707 if(jb->subscription & JABBER_SUB_TO) | |
1708 sub = _("Both"); | |
1709 else if(jb->subscription & JABBER_SUB_PENDING) | |
1710 sub = _("From (To pending)"); | |
1711 else | |
1712 sub = _("From"); | |
1713 } else { | |
1714 if(jb->subscription & JABBER_SUB_TO) | |
1715 sub = _("To"); | |
1716 else if(jb->subscription & JABBER_SUB_PENDING) | |
1717 sub = _("None (To pending)"); | |
1718 else | |
1719 sub = _("None"); | |
1720 } | |
1721 | |
1722 purple_notify_user_info_add_pair(user_info, _("Subscription"), sub); | |
1723 | 1788 |
1724 status = purple_presence_get_active_status(presence); | 1789 status = purple_presence_get_active_status(presence); |
1725 mood = purple_status_get_attr_string(status, "mood"); | 1790 mood = purple_status_get_attr_string(status, "mood"); |
1726 if(mood != NULL) { | 1791 if(mood != NULL) { |
1727 const char *moodtext; | 1792 const char *moodtext; |
1743 if (playing) { | 1808 if (playing) { |
1744 purple_notify_user_info_add_pair(user_info, _("Now Listening"), playing); | 1809 purple_notify_user_info_add_pair(user_info, _("Now Listening"), playing); |
1745 g_free(playing); | 1810 g_free(playing); |
1746 } | 1811 } |
1747 } | 1812 } |
1748 } | 1813 |
1749 | 1814 if(jb->subscription & JABBER_SUB_FROM) { |
1750 for(l=jb->resources; l; l = l->next) { | 1815 if(jb->subscription & JABBER_SUB_TO) |
1751 char *text = NULL; | 1816 sub = _("Both"); |
1752 char *res = NULL; | 1817 else if(jb->subscription & JABBER_SUB_PENDING) |
1753 char *label, *value; | 1818 sub = _("From (To pending)"); |
1754 const char *state; | 1819 else |
1755 | 1820 sub = _("From"); |
1756 jbr = l->data; | 1821 } else { |
1757 | 1822 if(jb->subscription & JABBER_SUB_TO) |
1758 if(jbr->status) { | 1823 sub = _("To"); |
1759 char *tmp; | 1824 else if(jb->subscription & JABBER_SUB_PENDING) |
1760 text = purple_strreplace(jbr->status, "\n", "<br />\n"); | 1825 sub = _("None (To pending)"); |
1761 tmp = purple_markup_strip_html(text); | 1826 else |
1762 g_free(text); | 1827 sub = _("None"); |
1763 text = g_markup_escape_text(tmp, -1); | |
1764 g_free(tmp); | |
1765 } | 1828 } |
1766 | 1829 |
1767 if(jbr->name) | 1830 purple_notify_user_info_add_pair(user_info, _("Subscription"), sub); |
1768 res = g_strdup_printf(" (%s)", jbr->name); | 1831 |
1769 | 1832 } |
1770 state = jabber_buddy_state_get_name(jbr->state); | 1833 |
1771 if (text != NULL && !purple_utf8_strcasecmp(state, text)) { | |
1772 g_free(text); | |
1773 text = NULL; | |
1774 } | |
1775 | |
1776 label = g_strdup_printf("%s%s", | |
1777 _("Status"), (res ? res : "")); | |
1778 value = g_strdup_printf("%s%s%s", | |
1779 state, | |
1780 (text ? ": " : ""), | |
1781 (text ? text : "")); | |
1782 | |
1783 purple_notify_user_info_add_pair(user_info, label, value); | |
1784 | |
1785 g_free(label); | |
1786 g_free(value); | |
1787 g_free(text); | |
1788 g_free(res); | |
1789 } | |
1790 | |
1791 if(!PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) { | 1834 if(!PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) { |
1792 purple_notify_user_info_add_pair(user_info, _("Error"), jb->error_msg); | 1835 purple_notify_user_info_add_pair(user_info, _("Error"), jb->error_msg); |
1793 } | 1836 } |
1794 } | 1837 } |
1795 } | 1838 } |