comparison libpurple/protocols/jabber/buddy.c @ 26485:242a8c97270b

propagate from branch 'im.pidgin.pidgin' (head f144c6bda9daf701aa891c875fce7a4dedd611ae) to branch 'im.pidgin.cpw.darkrain42.xmpp.avatars' (head 94d20f2f1d6e10ad1543c226dc01fb5c518bcea0)
author Paul Aurich <paul@darkrain42.org>
date Sun, 05 Apr 2009 21:49:01 +0000
parents 14e1f9af369f 00870e5f2e90
children d6a31b0ad109
comparison
equal deleted inserted replaced
26278:14e1f9af369f 26485:242a8c97270b
152 if(!jbr) { 152 if(!jbr) {
153 jbr = g_new0(JabberBuddyResource, 1); 153 jbr = g_new0(JabberBuddyResource, 1);
154 jbr->jb = jb; 154 jbr->jb = jb;
155 jbr->name = g_strdup(resource); 155 jbr->name = g_strdup(resource);
156 jbr->capabilities = JABBER_CAP_XHTML; 156 jbr->capabilities = JABBER_CAP_XHTML;
157 jbr->tz_off = PURPLE_NO_TZ_OFF;
157 jb->resources = g_list_append(jb->resources, jbr); 158 jb->resources = g_list_append(jb->resources, jbr);
158 } 159 }
159 jbr->priority = priority; 160 jbr->priority = priority;
160 jbr->state = state; 161 jbr->state = state;
161 g_free(jbr->status); 162 g_free(jbr->status);
686 g_free(tmp); 687 g_free(tmp);
687 688
688 if(jbr->client.os) { 689 if(jbr->client.os) {
689 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); 690 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os);
690 } 691 }
692 }
693 if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) {
694 time_t now_t;
695 struct tm *now;
696 char *timestamp;
697 time(&now_t);
698 now_t += jbr->tz_off;
699 now = gmtime(&now_t);
700
701 timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now),
702 jbr->tz_off < 0 ? '-' : '+',
703 abs(jbr->tz_off / (60*60)),
704 abs((jbr->tz_off % (60*60)) / 60));
705 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp);
706 g_free(timestamp);
691 } 707 }
692 if(jbir) { 708 if(jbir) {
693 if(jbir->idle_seconds > 0) { 709 if(jbir->idle_seconds > 0) {
694 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); 710 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
695 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); 711 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle);
805 feature = _("User Browsing"); 821 feature = _("User Browsing");
806 else if(!strcmp(feature, "http://jabber.org/protocol/gaming")) 822 else if(!strcmp(feature, "http://jabber.org/protocol/gaming"))
807 feature = _("User Gaming"); 823 feature = _("User Gaming");
808 else if(!strcmp(feature, "http://jabber.org/protocol/viewing")) 824 else if(!strcmp(feature, "http://jabber.org/protocol/viewing"))
809 feature = _("User Viewing"); 825 feature = _("User Viewing");
810 else if(!strcmp(feature, "urn:xmpp:ping") || !strcmp(feature, "http://www.xmpp.org/extensions/xep-0199.html#ns")) 826 else if(!strcmp(feature, "urn:xmpp:ping"))
811 feature = _("Ping"); 827 feature = _("Ping");
812 else if(!strcmp(feature, "http://www.xmpp.org/extensions/xep-0200.html#ns")) 828 else if(!strcmp(feature, "http://www.xmpp.org/extensions/xep-0200.html#ns"))
813 feature = _("Stanza Encryption"); 829 feature = _("Stanza Encryption");
814 else if(!strcmp(feature, "urn:xmpp:time")) 830 else if(!strcmp(feature, "urn:xmpp:time"))
815 feature = _("Entity Time"); 831 feature = _("Entity Time");
855 g_free(tmp); 871 g_free(tmp);
856 872
857 if(jbr->client.os) { 873 if(jbr->client.os) {
858 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); 874 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os);
859 } 875 }
876 }
877
878 if (jbr->tz_off != PURPLE_NO_TZ_OFF) {
879 time_t now_t;
880 struct tm *now;
881 char *timestamp;
882 time(&now_t);
883 now_t += jbr->tz_off;
884 now = gmtime(&now_t);
885
886 timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now),
887 jbr->tz_off < 0 ? '-' : '+',
888 abs(jbr->tz_off / (60*60)),
889 abs((jbr->tz_off % (60*60)) / 60));
890 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp);
891 g_free(timestamp);
860 } 892 }
861 893
862 if(jbr->name && (jbir = g_hash_table_lookup(jbi->resources, jbr->name))) { 894 if(jbr->name && (jbir = g_hash_table_lookup(jbi->resources, jbr->name))) {
863 if(jbir->idle_seconds > 0) { 895 if(jbir->idle_seconds > 0) {
864 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); 896 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
975 feature = _("User Browsing"); 1007 feature = _("User Browsing");
976 else if(!strcmp(feature, "http://jabber.org/protocol/gaming")) 1008 else if(!strcmp(feature, "http://jabber.org/protocol/gaming"))
977 feature = _("User Gaming"); 1009 feature = _("User Gaming");
978 else if(!strcmp(feature, "http://jabber.org/protocol/viewing")) 1010 else if(!strcmp(feature, "http://jabber.org/protocol/viewing"))
979 feature = _("User Viewing"); 1011 feature = _("User Viewing");
980 else if(!strcmp(feature, "urn:xmpp:ping") || !strcmp(feature, "http://www.xmpp.org/extensions/xep-0199.html#ns")) 1012 else if(!strcmp(feature, "urn:xmpp:ping"))
981 feature = _("Ping"); 1013 feature = _("Ping");
982 else if(!strcmp(feature, "http://www.xmpp.org/extensions/xep-0200.html#ns")) 1014 else if(!strcmp(feature, "http://www.xmpp.org/extensions/xep-0200.html#ns"))
983 feature = _("Stanza Encryption"); 1015 feature = _("Stanza Encryption");
984 else if(!strcmp(feature, "urn:xmpp:time")) 1016 else if(!strcmp(feature, "urn:xmpp:time"))
985 feature = _("Entity Time"); 1017 feature = _("Entity Time");
1041 } 1073 }
1042 l = l->next; 1074 l = l->next;
1043 } 1075 }
1044 } 1076 }
1045 1077
1046 static void jabber_vcard_save_mine(JabberStream *js, xmlnode *packet, gpointer data) 1078 static void jabber_vcard_save_mine(JabberStream *js, const char *from,
1079 JabberIqType type, const char *id,
1080 xmlnode *packet, gpointer data)
1047 { 1081 {
1048 xmlnode *vcard, *photo, *binval; 1082 xmlnode *vcard, *photo, *binval;
1049 char *txt, *vcard_hash = NULL; 1083 char *txt, *vcard_hash = NULL;
1084 PurpleStoredImage *img;
1085
1086 if (type == JABBER_IQ_ERROR) {
1087 purple_debug_warning("jabber", "Server returned error while retrieving vCard");
1088 return;
1089 }
1050 1090
1051 if((vcard = xmlnode_get_child(packet, "vCard")) || 1091 if((vcard = xmlnode_get_child(packet, "vCard")) ||
1052 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) 1092 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp")))
1053 { 1093 {
1054 txt = xmlnode_to_str(vcard, NULL); 1094 txt = xmlnode_to_str(vcard, NULL);
1096 jabber_iq_set_callback(iq, jabber_vcard_save_mine, NULL); 1136 jabber_iq_set_callback(iq, jabber_vcard_save_mine, NULL);
1097 1137
1098 jabber_iq_send(iq); 1138 jabber_iq_send(iq);
1099 } 1139 }
1100 1140
1101 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) 1141 static void jabber_vcard_parse(JabberStream *js, const char *from,
1102 { 1142 JabberIqType type, const char *id,
1103 const char *id, *from; 1143 xmlnode *packet, gpointer data)
1144 {
1104 char *bare_jid; 1145 char *bare_jid;
1105 char *text; 1146 char *text;
1106 char *serverside_alias = NULL; 1147 char *serverside_alias = NULL;
1107 xmlnode *vcard; 1148 xmlnode *vcard;
1108 PurpleBuddy *b; 1149 PurpleBuddy *b;
1109 JabberBuddyInfo *jbi = data; 1150 JabberBuddyInfo *jbi = data;
1110 PurpleNotifyUserInfo *user_info; 1151 PurpleNotifyUserInfo *user_info;
1111
1112 from = xmlnode_get_attrib(packet, "from");
1113 id = xmlnode_get_attrib(packet, "id");
1114 1152
1115 if(!jbi) 1153 if(!jbi)
1116 return; 1154 return;
1117 1155
1118 jabber_buddy_info_remove_id(jbi, id); 1156 jabber_buddy_info_remove_id(jbi, id);
1338 { 1376 {
1339 JabberBuddyInfoResource *jbri = data; 1377 JabberBuddyInfoResource *jbri = data;
1340 g_free(jbri); 1378 g_free(jbri);
1341 } 1379 }
1342 1380
1343 static void jabber_version_parse(JabberStream *js, xmlnode *packet, gpointer data) 1381 static void jabber_version_parse(JabberStream *js, const char *from,
1382 JabberIqType type, const char *id,
1383 xmlnode *packet, gpointer data)
1344 { 1384 {
1345 JabberBuddyInfo *jbi = data; 1385 JabberBuddyInfo *jbi = data;
1346 const char *type, *id, *from;
1347 xmlnode *query; 1386 xmlnode *query;
1348 char *resource_name; 1387 char *resource_name;
1349 1388
1350 g_return_if_fail(jbi != NULL); 1389 g_return_if_fail(jbi != NULL);
1351 1390
1352 type = xmlnode_get_attrib(packet, "type");
1353 id = xmlnode_get_attrib(packet, "id");
1354 from = xmlnode_get_attrib(packet, "from");
1355
1356 jabber_buddy_info_remove_id(jbi, id); 1391 jabber_buddy_info_remove_id(jbi, id);
1357 1392
1358 if(!from) 1393 if(!from)
1359 return; 1394 return;
1360 1395
1361 resource_name = jabber_get_resource(from); 1396 resource_name = jabber_get_resource(from);
1362 1397
1363 if(resource_name) { 1398 if(resource_name) {
1364 if(type && !strcmp(type, "result")) { 1399 if (type == JABBER_IQ_RESULT) {
1365 if((query = xmlnode_get_child(packet, "query"))) { 1400 if((query = xmlnode_get_child(packet, "query"))) {
1366 JabberBuddyResource *jbr = jabber_buddy_find_resource(jbi->jb, resource_name); 1401 JabberBuddyResource *jbr = jabber_buddy_find_resource(jbi->jb, resource_name);
1367 if(jbr) { 1402 if(jbr) {
1368 xmlnode *node; 1403 xmlnode *node;
1369 if((node = xmlnode_get_child(query, "name"))) { 1404 if((node = xmlnode_get_child(query, "name"))) {
1382 } 1417 }
1383 1418
1384 jabber_buddy_info_show_if_ready(jbi); 1419 jabber_buddy_info_show_if_ready(jbi);
1385 } 1420 }
1386 1421
1387 static void jabber_last_parse(JabberStream *js, xmlnode *packet, gpointer data) 1422 static void jabber_last_parse(JabberStream *js, const char *from,
1423 JabberIqType type, const char *id,
1424 xmlnode *packet, gpointer data)
1388 { 1425 {
1389 JabberBuddyInfo *jbi = data; 1426 JabberBuddyInfo *jbi = data;
1390 xmlnode *query; 1427 xmlnode *query;
1391 char *resource_name; 1428 char *resource_name;
1392 const char *type, *id, *from, *seconds; 1429 const char *seconds;
1393 1430
1394 g_return_if_fail(jbi != NULL); 1431 g_return_if_fail(jbi != NULL);
1395
1396 type = xmlnode_get_attrib(packet, "type");
1397 id = xmlnode_get_attrib(packet, "id");
1398 from = xmlnode_get_attrib(packet, "from");
1399 1432
1400 jabber_buddy_info_remove_id(jbi, id); 1433 jabber_buddy_info_remove_id(jbi, id);
1401 1434
1402 if(!from) 1435 if(!from)
1403 return; 1436 return;
1404 1437
1405 resource_name = jabber_get_resource(from); 1438 resource_name = jabber_get_resource(from);
1406 1439
1407 if(resource_name) { 1440 if(resource_name) {
1408 if(type && !strcmp(type, "result")) { 1441 if (type == JABBER_IQ_RESULT) {
1409 if((query = xmlnode_get_child(packet, "query"))) { 1442 if((query = xmlnode_get_child(packet, "query"))) {
1410 seconds = xmlnode_get_attrib(query, "seconds"); 1443 seconds = xmlnode_get_attrib(query, "seconds");
1411 if(seconds) { 1444 if(seconds) {
1412 char *end = NULL; 1445 char *end = NULL;
1413 long sec = strtol(seconds, &end, 10); 1446 long sec = strtol(seconds, &end, 10);
1424 } 1457 }
1425 1458
1426 jabber_buddy_info_show_if_ready(jbi); 1459 jabber_buddy_info_show_if_ready(jbi);
1427 } 1460 }
1428 1461
1462 static void jabber_time_parse(JabberStream *js, const char *from,
1463 JabberIqType type, const char *id,
1464 xmlnode *packet, gpointer data)
1465 {
1466 JabberBuddyInfo *jbi = data;
1467 JabberBuddyResource *jbr;
1468 char *resource_name;
1469
1470 g_return_if_fail(jbi != NULL);
1471
1472 jabber_buddy_info_remove_id(jbi, id);
1473
1474 if (!from)
1475 return;
1476
1477 resource_name = jabber_get_resource(from);
1478 jbr = resource_name ? jabber_buddy_find_resource(jbi->jb, resource_name) : NULL;
1479 g_free(resource_name);
1480 if (jbr) {
1481 if (type == JABBER_IQ_RESULT) {
1482 xmlnode *time = xmlnode_get_child(packet, "time");
1483 xmlnode *tzo = time ? xmlnode_get_child(time, "tzo") : NULL;
1484 char *tzo_data = tzo ? xmlnode_get_data(tzo) : NULL;
1485 if (tzo_data) {
1486 char *c = tzo_data;
1487 int hours, minutes;
1488 if (tzo_data[0] == 'Z' && tzo_data[1] == '\0') {
1489 jbr->tz_off = 0;
1490 } else {
1491 gboolean offset_positive = (tzo_data[0] == '+');
1492 /* [+-]HH:MM */
1493 if (((*c == '+' || *c == '-') && (c = c + 1)) &&
1494 sscanf(c, "%02d:%02d", &hours, &minutes) == 2) {
1495 jbr->tz_off = 60*60*hours + 60*minutes;
1496 if (!offset_positive)
1497 jbr->tz_off *= -1;
1498 } else {
1499 purple_debug_info("jabber", "Ignoring malformed timezone %s",
1500 tzo_data);
1501 }
1502 }
1503
1504 g_free(tzo_data);
1505 }
1506 }
1507 }
1508
1509 jabber_buddy_info_show_if_ready(jbi);
1510 }
1511
1429 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js) 1512 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js)
1430 { 1513 {
1431 if (js->pending_buddy_info_requests) 1514 if (js->pending_buddy_info_requests)
1432 { 1515 {
1433 JabberBuddyInfo *jbi; 1516 JabberBuddyInfo *jbi;
1551 * office. */ 1634 * office. */
1552 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) { 1635 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) {
1553 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); 1636 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
1554 xmlnode_set_attrib(iq->node, "to", full_jid); 1637 xmlnode_set_attrib(iq->node, "to", full_jid);
1555 jabber_iq_set_callback(iq, jabber_last_parse, jbi); 1638 jabber_iq_set_callback(iq, jabber_last_parse, jbi);
1639 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
1640 jabber_iq_send(iq);
1641 }
1642
1643 if (jbr->tz_off == PURPLE_NO_TZ_OFF &&
1644 (!jbr->caps ||
1645 jabber_resource_has_capability(jbr, "urn:xmpp:time"))) {
1646 xmlnode *child;
1647 iq = jabber_iq_new(js, JABBER_IQ_GET);
1648 xmlnode_set_attrib(iq->node, "to", full_jid);
1649 child = xmlnode_new_child(iq->node, "time");
1650 xmlnode_set_namespace(child, "urn:xmpp:time");
1651 jabber_iq_set_callback(iq, jabber_time_parse, jbi);
1556 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); 1652 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
1557 jabber_iq_send(iq); 1653 jabber_iq_send(iq);
1558 } 1654 }
1559 1655
1560 g_free(full_jid); 1656 g_free(full_jid);
1951 /* XXX find out the jid */ 2047 /* XXX find out the jid */
1952 purple_blist_request_add_buddy(purple_connection_get_account(gc), 2048 purple_blist_request_add_buddy(purple_connection_get_account(gc),
1953 g_list_nth_data(row, 0), NULL, NULL); 2049 g_list_nth_data(row, 0), NULL, NULL);
1954 } 2050 }
1955 2051
1956 static void user_search_result_cb(JabberStream *js, xmlnode *packet, gpointer data) 2052 static void user_search_result_cb(JabberStream *js, const char *from,
2053 JabberIqType type, const char *id,
2054 xmlnode *packet, gpointer data)
1957 { 2055 {
1958 PurpleNotifySearchResults *results; 2056 PurpleNotifySearchResults *results;
1959 PurpleNotifySearchColumn *column; 2057 PurpleNotifySearchColumn *column;
1960 xmlnode *x, *query, *item, *field; 2058 xmlnode *x, *query, *item, *field;
1961 2059
2147 "Note: Each field supports wild card searches (%)"), 2245 "Note: Each field supports wild card searches (%)"),
2148 NULL 2246 NULL
2149 }; 2247 };
2150 #endif 2248 #endif
2151 2249
2152 static void user_search_fields_result_cb(JabberStream *js, xmlnode *packet, gpointer data) 2250 static void user_search_fields_result_cb(JabberStream *js, const char *from,
2251 JabberIqType type, const char *id,
2252 xmlnode *packet, gpointer data)
2153 { 2253 {
2154 xmlnode *query, *x; 2254 xmlnode *query, *x;
2155 const char *from, *type; 2255
2156 2256 if (!from)
2157 if(!(from = xmlnode_get_attrib(packet, "from")))
2158 return; 2257 return;
2159 2258
2160 if(!(type = xmlnode_get_attrib(packet, "type")) || !strcmp(type, "error")) { 2259 if (type == JABBER_IQ_ERROR) {
2161 char *msg = jabber_parse_error(js, packet, NULL); 2260 char *msg = jabber_parse_error(js, packet, NULL);
2162 2261
2163 if(!msg) 2262 if(!msg)
2164 msg = g_strdup(_("Unknown error")); 2263 msg = g_strdup(_("Unknown error"));
2165 2264