comparison libpurple/protocols/jabber/buddy.c @ 25983:439f07ce4c8a

propagate from branch 'im.pidgin.pidgin' (head 303af74a38e7b313d4fb0be4d4054a16cb13d819) to branch 'im.pidgin.cpw.darkrain42.xmpp.iq-handlers' (head b04e8bdc99bebce19e9d8a5df5d7397cffcf2988)
author Paul Aurich <paul@darkrain42.org>
date Sat, 07 Mar 2009 02:14:34 +0000
parents 5f9a24d1c25e 751df82b78e7
children ae41d8e827e3
comparison
equal deleted inserted replaced
25464:0e93bbb7f5ca 25983:439f07ce4c8a
153 if(!jbr) { 153 if(!jbr) {
154 jbr = g_new0(JabberBuddyResource, 1); 154 jbr = g_new0(JabberBuddyResource, 1);
155 jbr->jb = jb; 155 jbr->jb = jb;
156 jbr->name = g_strdup(resource); 156 jbr->name = g_strdup(resource);
157 jbr->capabilities = JABBER_CAP_XHTML; 157 jbr->capabilities = JABBER_CAP_XHTML;
158 jbr->tz_off = PURPLE_NO_TZ_OFF;
158 jb->resources = g_list_append(jb->resources, jbr); 159 jb->resources = g_list_append(jb->resources, jbr);
159 } 160 }
160 jbr->priority = priority; 161 jbr->priority = priority;
161 jbr->state = state; 162 jbr->state = state;
162 g_free(jbr->status); 163 g_free(jbr->status);
798 g_free(tmp); 799 g_free(tmp);
799 800
800 if(jbr->client.os) { 801 if(jbr->client.os) {
801 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); 802 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os);
802 } 803 }
804 }
805 if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) {
806 time_t now_t;
807 struct tm *now;
808 char *timestamp;
809 time(&now_t);
810 now_t += jbr->tz_off;
811 now = gmtime(&now_t);
812
813 timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now),
814 jbr->tz_off < 0 ? '-' : '+',
815 abs(jbr->tz_off / (60*60)),
816 abs((jbr->tz_off % (60*60)) / 60));
817 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp);
818 g_free(timestamp);
803 } 819 }
804 if(jbir) { 820 if(jbir) {
805 if(jbir->idle_seconds > 0) { 821 if(jbir->idle_seconds > 0) {
806 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); 822 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
807 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); 823 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle);
969 if(jbr->client.os) { 985 if(jbr->client.os) {
970 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); 986 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os);
971 } 987 }
972 } 988 }
973 989
990 if (jbr->tz_off != PURPLE_NO_TZ_OFF) {
991 time_t now_t;
992 struct tm *now;
993 char *timestamp;
994 time(&now_t);
995 now_t += jbr->tz_off;
996 now = gmtime(&now_t);
997
998 timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now),
999 jbr->tz_off < 0 ? '-' : '+',
1000 abs(jbr->tz_off / (60*60)),
1001 abs((jbr->tz_off % (60*60)) / 60));
1002 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp);
1003 g_free(timestamp);
1004 }
1005
974 if(jbr->name && (jbir = g_hash_table_lookup(jbi->resources, jbr->name))) { 1006 if(jbr->name && (jbir = g_hash_table_lookup(jbi->resources, jbr->name))) {
975 if(jbir->idle_seconds > 0) { 1007 if(jbir->idle_seconds > 0) {
976 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); 1008 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
977 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); 1009 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle);
978 g_free(idle); 1010 g_free(idle);
1638 } 1670 }
1639 1671
1640 jabber_buddy_info_show_if_ready(jbi); 1672 jabber_buddy_info_show_if_ready(jbi);
1641 } 1673 }
1642 1674
1675 static void jabber_time_parse(JabberStream *js, xmlnode *packet, gpointer data)
1676 {
1677 JabberBuddyInfo *jbi = data;
1678 JabberBuddyResource *jbr;
1679 char *resource_name;
1680 const char *type, *id, *from;
1681
1682 g_return_if_fail(jbi != NULL);
1683
1684 id = xmlnode_get_attrib(packet, "id");
1685 type = xmlnode_get_attrib(packet, "type");
1686 from = xmlnode_get_attrib(packet, "from");
1687
1688 jabber_buddy_info_remove_id(jbi, id);
1689
1690 if (!from)
1691 return;
1692
1693 resource_name = jabber_get_resource(from);
1694 jbr = resource_name ? jabber_buddy_find_resource(jbi->jb, resource_name) : NULL;
1695 g_free(resource_name);
1696 if (jbr) {
1697 if (type && !strcmp(type, "result")) {
1698 xmlnode *time = xmlnode_get_child(packet, "time");
1699 xmlnode *tzo = time ? xmlnode_get_child(time, "tzo") : NULL;
1700 char *tzo_data = tzo ? xmlnode_get_data(tzo) : NULL;
1701 if (tzo_data) {
1702 char *c = tzo_data;
1703 int hours, minutes;
1704 if (tzo_data[0] == 'Z' && tzo_data[1] == '\0') {
1705 jbr->tz_off = 0;
1706 } else {
1707 gboolean offset_positive = (tzo_data[0] == '+');
1708 /* [+-]HH:MM */
1709 if (((*c == '+' || *c == '-') && (c = c + 1)) &&
1710 sscanf(c, "%02d:%02d", &hours, &minutes) == 2) {
1711 jbr->tz_off = 60*60*hours + 60*minutes;
1712 if (!offset_positive)
1713 jbr->tz_off *= -1;
1714 } else {
1715 purple_debug_info("jabber", "Ignoring malformed timezone %s",
1716 tzo_data);
1717 }
1718 }
1719
1720 g_free(tzo_data);
1721 }
1722 }
1723 }
1724
1725 jabber_buddy_info_show_if_ready(jbi);
1726 }
1727
1643 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js) 1728 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js)
1644 { 1729 {
1645 if (js->pending_buddy_info_requests) 1730 if (js->pending_buddy_info_requests)
1646 { 1731 {
1647 JabberBuddyInfo *jbi; 1732 JabberBuddyInfo *jbi;
1765 * office. */ 1850 * office. */
1766 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) { 1851 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) {
1767 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); 1852 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
1768 xmlnode_set_attrib(iq->node, "to", full_jid); 1853 xmlnode_set_attrib(iq->node, "to", full_jid);
1769 jabber_iq_set_callback(iq, jabber_last_parse, jbi); 1854 jabber_iq_set_callback(iq, jabber_last_parse, jbi);
1855 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
1856 jabber_iq_send(iq);
1857 }
1858
1859 if (jbr->tz_off == PURPLE_NO_TZ_OFF &&
1860 (!jbr->caps ||
1861 jabber_resource_has_capability(jbr, "urn:xmpp:time"))) {
1862 xmlnode *child;
1863 iq = jabber_iq_new(js, JABBER_IQ_GET);
1864 xmlnode_set_attrib(iq->node, "to", full_jid);
1865 child = xmlnode_new_child(iq->node, "time");
1866 xmlnode_set_namespace(child, "urn:xmpp:time");
1867 jabber_iq_set_callback(iq, jabber_time_parse, jbi);
1770 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); 1868 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
1771 jabber_iq_send(iq); 1869 jabber_iq_send(iq);
1772 } 1870 }
1773 1871
1774 g_free(full_jid); 1872 g_free(full_jid);