Mercurial > pidgin
comparison src/protocols/msn/msn.c @ 10044:86a6d78b070b
[gaim-migrate @ 11003]
this is the msn buddy list sync code from the 1.0.0 tree, also from shx. in
this patch, i changed one instance of "b" to "buddy" to make it compile.
this introduces code to ask the user about discrepances between the local
and server lists on msn.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 19 Sep 2004 03:02:28 +0000 |
parents | 2f153f8cdf81 |
children | 2ef4b5121efc |
comparison
equal
deleted
inserted
replaced
10043:700f8fb9e581 | 10044:86a6d78b070b |
---|---|
421 } | 421 } |
422 | 422 |
423 static char * | 423 static char * |
424 msn_status_text(GaimBuddy *buddy) | 424 msn_status_text(GaimBuddy *buddy) |
425 { | 425 { |
426 GaimPresence *presence = gaim_buddy_get_presence(buddy); | 426 GString *s; |
427 GaimStatus *status = gaim_presence_get_active_status(presence); | 427 GaimPresence *presence; |
428 GaimStatus *status; | |
429 MsnUser *user; | |
430 | |
431 s = g_string_new(""); | |
432 user = buddy->proto_data; | |
433 presence = gaim_buddy_get_presence(buddy); | |
434 status = gaim_presence_get_active_status(presence); | |
428 | 435 |
429 if (!gaim_status_is_available(status)) | 436 if (!gaim_status_is_available(status)) |
430 return g_strdup(gaim_status_get_name(status)); | 437 { |
431 | 438 g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Status"), |
432 return NULL; | 439 gaim_status_get_name(status)); |
440 } | |
441 | |
442 g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Has you"), | |
443 (user->list_op & (1 << MSN_LIST_RL)) ? | |
444 _("Yes") : _("No")); | |
445 | |
446 return g_string_free(s, FALSE); | |
433 } | 447 } |
434 | 448 |
435 static char * | 449 static char * |
436 msn_tooltip_text(GaimBuddy *buddy) | 450 msn_tooltip_text(GaimBuddy *buddy) |
437 { | 451 { |
609 http_method = TRUE; | 623 http_method = TRUE; |
610 | 624 |
611 gaim_debug_info("msn", "using http method\n"); | 625 gaim_debug_info("msn", "using http method\n"); |
612 | 626 |
613 host = "gateway.messenger.hotmail.com"; | 627 host = "gateway.messenger.hotmail.com"; |
614 port = 80; | 628 port = 80; |
615 } | 629 } |
616 else | 630 else |
617 { | 631 { |
618 host = gaim_account_get_string(account, "server", MSN_SERVER); | 632 host = gaim_account_get_string(account, "server", MSN_SERVER); |
619 port = gaim_account_get_int(account, "port", MSN_PORT); | 633 port = gaim_account_get_int(account, "port", MSN_PORT); |
799 | 813 |
800 msn_change_status(session, (idle ? MSN_IDLE : MSN_ONLINE)); | 814 msn_change_status(session, (idle ? MSN_IDLE : MSN_ONLINE)); |
801 } | 815 } |
802 | 816 |
803 static void | 817 static void |
818 fake_userlist_add_buddy(MsnUserList *userlist, | |
819 const char *who, int list_id, | |
820 const char *group_name) | |
821 { | |
822 MsnUser *user; | |
823 static int group_id_c = 1; | |
824 int group_id; | |
825 | |
826 group_id = -1; | |
827 | |
828 if (group_name != NULL) | |
829 { | |
830 MsnGroup *group; | |
831 group = msn_group_new(userlist, group_id_c, group_name); | |
832 group_id = group_id_c++; | |
833 } | |
834 | |
835 user = msn_userlist_find_user(userlist, who); | |
836 | |
837 if (user == NULL) | |
838 { | |
839 user = msn_user_new(userlist, who, NULL); | |
840 msn_userlist_add_user(userlist, user); | |
841 } | |
842 else | |
843 if (user->list_op & (1 << list_id)) | |
844 { | |
845 if (list_id == MSN_LIST_FL) | |
846 { | |
847 if (group_id >= 0) | |
848 if (g_list_find(user->group_ids, | |
849 GINT_TO_POINTER(group_id))) | |
850 return; | |
851 } | |
852 else | |
853 return; | |
854 } | |
855 | |
856 if (group_id >= 0) | |
857 { | |
858 user->group_ids = g_list_append(user->group_ids, | |
859 GINT_TO_POINTER(group_id)); | |
860 } | |
861 | |
862 user->list_op |= (1 << list_id); | |
863 } | |
864 | |
865 static void | |
804 msn_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | 866 msn_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
805 { | 867 { |
806 MsnSession *session; | 868 MsnSession *session; |
807 MsnUserList *userlist; | 869 MsnUserList *userlist; |
808 const char *who; | 870 const char *who; |
810 session = gc->proto_data; | 872 session = gc->proto_data; |
811 userlist = session->userlist; | 873 userlist = session->userlist; |
812 who = msn_normalize(gc->account, buddy->name); | 874 who = msn_normalize(gc->account, buddy->name); |
813 | 875 |
814 if (!session->logged_in) | 876 if (!session->logged_in) |
877 { | |
878 fake_userlist_add_buddy(session->sync_userlist, who, MSN_LIST_FL, | |
879 group ? group->name : NULL); | |
880 | |
815 return; | 881 return; |
816 | 882 } |
883 | |
884 #if 0 | |
817 if (group != NULL && group->name != NULL) | 885 if (group != NULL && group->name != NULL) |
818 gaim_debug_info("msn", "msn_add_buddy: %s, %s\n", who, group->name); | 886 gaim_debug_info("msn", "msn_add_buddy: %s, %s\n", who, group->name); |
819 else | 887 else |
820 gaim_debug_info("msn", "msn_add_buddy: %s\n", who); | 888 gaim_debug_info("msn", "msn_add_buddy: %s\n", who); |
889 #endif | |
821 | 890 |
822 #if 0 | 891 #if 0 |
823 /* Which is the max? */ | 892 /* Which is the max? */ |
824 if (session->fl_users_count >= 150) | 893 if (session->fl_users_count >= 150) |
825 { | 894 { |
828 /* TODO: gaim should be notified of this */ | 897 /* TODO: gaim should be notified of this */ |
829 return; | 898 return; |
830 } | 899 } |
831 #endif | 900 #endif |
832 | 901 |
833 /* XXX - Would group ever be NULL here? I don't think so... */ | 902 /* XXX - Would group ever be NULL here? I don't think so... |
903 * shx: Yes it should; MSN handles non-grouped buddies, and this is only | |
904 * internal. */ | |
834 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, | 905 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, |
835 group ? group->name : NULL); | 906 group ? group->name : NULL); |
836 } | 907 } |
837 | 908 |
838 static void | 909 static void |
1145 msn_cmdproc_send(cmdproc, "RMG", "%d", group_id); | 1216 msn_cmdproc_send(cmdproc, "RMG", "%d", group_id); |
1146 } | 1217 } |
1147 } | 1218 } |
1148 | 1219 |
1149 static char * | 1220 static char * |
1150 msn_tooltip_info_text(MsnGetInfoData *info_data) { | 1221 msn_tooltip_info_text(MsnGetInfoData *info_data) |
1151 GString *s = g_string_sized_new(80); /* wild guess */ | 1222 { |
1223 GString *s; | |
1152 GString *name; | 1224 GString *name; |
1153 GaimBuddy *b; | 1225 GaimBuddy *b; |
1154 const char *p; | 1226 const char *p; |
1155 | 1227 |
1228 s = g_string_sized_new(80); /* wild guess */ | |
1229 | |
1156 /* Try to not display the MSN screen name as an email address */ | 1230 /* Try to not display the MSN screen name as an email address */ |
1157 p = strrchr(info_data->name, '@'); | 1231 p = strrchr(info_data->name, '@'); |
1158 if (p) { | 1232 if (p) |
1233 { | |
1159 name = g_string_new_len(info_data->name, p - info_data->name); | 1234 name = g_string_new_len(info_data->name, p - info_data->name); |
1160 g_string_append_printf(name, "@%s", p + 1); | 1235 g_string_append_printf(name, "@%s", p + 1); |
1161 } else { /* This should never happen */ | 1236 } |
1237 else | |
1238 { | |
1239 /* This should never happen */ | |
1162 name = g_string_new(info_data->name); | 1240 name = g_string_new(info_data->name); |
1163 } | 1241 } |
1242 | |
1164 g_string_printf(s, "<span style=\"font-size: larger\"><b>%s</b></span><br>", | 1243 g_string_printf(s, "<span style=\"font-size: larger\"><b>%s</b></span><br>", |
1165 name->str); | 1244 name->str); |
1166 g_string_free(name, TRUE); | 1245 g_string_free(name, TRUE); |
1167 b = gaim_find_buddy(gaim_connection_get_account(info_data->gc), | 1246 b = gaim_find_buddy(gaim_connection_get_account(info_data->gc), |
1168 info_data->name); | 1247 info_data->name); |
1169 | 1248 |
1170 if (b) { | 1249 if (b) |
1250 { | |
1251 MsnUser *user; | |
1171 GaimPresence *presence; | 1252 GaimPresence *presence; |
1172 char *statustext = msn_tooltip_text(b); | 1253 char *statustext = msn_tooltip_text(b); |
1254 | |
1173 presence = gaim_buddy_get_presence(b); | 1255 presence = gaim_buddy_get_presence(b); |
1174 if(b->alias && b->alias[0]) { | 1256 |
1257 if (b->alias && b->alias[0]) | |
1258 { | |
1175 char *aliastext = g_markup_escape_text(b->alias, -1); | 1259 char *aliastext = g_markup_escape_text(b->alias, -1); |
1176 g_string_append_printf(s, _("<b>Alias:</b> %s<br>"), aliastext); | 1260 g_string_append_printf(s, _("<b>Alias:</b> %s<br>"), aliastext); |
1177 g_free(aliastext); | 1261 g_free(aliastext); |
1178 } | 1262 } |
1179 if(b->server_alias) { | 1263 |
1264 if (b->server_alias) | |
1265 { | |
1180 char *nicktext = g_markup_escape_text(b->server_alias, -1); | 1266 char *nicktext = g_markup_escape_text(b->server_alias, -1); |
1181 g_string_append_printf(s, _("<b>%s:</b> "), _("Nickname")); | 1267 g_string_append_printf(s, _("<b>%s:</b> "), _("Nickname")); |
1182 g_string_append_printf(s, "<font sml=\"msn\">%s</font><br>", | 1268 g_string_append_printf(s, "<font sml=\"msn\">%s</font><br>", |
1183 nicktext); | 1269 nicktext); |
1184 g_free(nicktext); | 1270 g_free(nicktext); |
1185 } | 1271 } |
1186 if (gaim_presence_is_idle(presence)) { | 1272 |
1273 if (gaim_presence_is_idle(presence)) | |
1274 { | |
1187 char *idletime = gaim_str_seconds_to_string(time(NULL) - | 1275 char *idletime = gaim_str_seconds_to_string(time(NULL) - |
1188 gaim_presence_get_idle_time(presence)); | 1276 gaim_presence_get_idle_time(presence)); |
1189 g_string_append_printf(s, _("<b>%s:</b> %s<br>"), _("Idle"), | 1277 g_string_append_printf(s, _("<b>%s:</b> %s<br>"), _("Idle"), |
1190 idletime); | 1278 idletime); |
1191 g_free(idletime); | 1279 g_free(idletime); |
1192 } | 1280 } |
1193 if (statustext) { | 1281 |
1282 if (statustext) | |
1283 { | |
1194 g_string_append_printf(s, "%s<br>", statustext); | 1284 g_string_append_printf(s, "%s<br>", statustext); |
1195 g_free(statustext); | 1285 g_free(statustext); |
1196 } | 1286 } |
1287 | |
1288 user = b->proto_data; | |
1289 | |
1290 g_string_append_printf(s, _("<b>%s:</b> %s<br>"), _("Has you"), | |
1291 (user->list_op & (1 << MSN_LIST_RL)) ? | |
1292 _("yes") : _("no")); | |
1197 } | 1293 } |
1198 | 1294 |
1199 return g_string_free(s, FALSE); | 1295 return g_string_free(s, FALSE); |
1200 } | 1296 } |
1201 | 1297 |
1202 #if PHOTO_SUPPORT | 1298 #if PHOTO_SUPPORT |
1203 | 1299 |
1204 static char *msn_get_photo_url(const char *url_text) { | 1300 static char * |
1301 msn_get_photo_url(const char *url_text) | |
1302 { | |
1205 char *p; | 1303 char *p; |
1206 char *it = NULL; | 1304 char *it = NULL; |
1207 | 1305 |
1208 p = strstr(url_text, " title=\"Click to see the full-size photo.\">"); | 1306 p = strstr(url_text, " title=\"Click to see the full-size photo.\">"); |
1209 | 1307 |
1210 if (p) { | 1308 if (p) |
1309 { | |
1211 /* Search backwards for "http://". This is stupid, but it works. */ | 1310 /* Search backwards for "http://". This is stupid, but it works. */ |
1212 for (; !it && p > url_text; p -= 1) { | 1311 for (; !it && p > url_text; p -= 1) |
1213 if (strncmp(p, "\"http://", 8) == 0) { | 1312 { |
1313 if (strncmp(p, "\"http://", 8) == 0) | |
1314 { | |
1214 char *q; | 1315 char *q; |
1215 p += 1; /* skip only the " */ | 1316 p += 1; /* skip only the " */ |
1216 q = strchr(p, '"'); | 1317 q = strchr(p, '"'); |
1217 if (q) { | 1318 if (q) |
1319 { | |
1218 it = g_strndup(p, q - p); | 1320 it = g_strndup(p, q - p); |
1219 } | 1321 } |
1220 } | 1322 } |
1221 } | 1323 } |
1222 } | 1324 } |
1325 | |
1223 return it; | 1326 return it; |
1224 } | 1327 } |
1225 | 1328 |
1226 static void msn_got_photo(void *data, const char *url_text, size_t len); | 1329 static void msn_got_photo(void *data, const char *url_text, size_t len); |
1227 | 1330 |
1539 info2_data->photo_url_text = photo_url_text; | 1642 info2_data->photo_url_text = photo_url_text; |
1540 info2_data->tooltip_text = tooltip_text; | 1643 info2_data->tooltip_text = tooltip_text; |
1541 info2_data->title = title; | 1644 info2_data->title = title; |
1542 | 1645 |
1543 /* Try to put the photo in there too, if there's one */ | 1646 /* Try to put the photo in there too, if there's one */ |
1544 if (photo_url_text) { | 1647 if (photo_url_text) |
1648 { | |
1545 gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, msn_got_photo, | 1649 gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, msn_got_photo, |
1546 info2_data); | 1650 info2_data); |
1547 } else { | 1651 } |
1652 else | |
1653 { | |
1548 /* Emulate a callback */ | 1654 /* Emulate a callback */ |
1549 msn_got_photo(info2_data, NULL, 0); | 1655 msn_got_photo(info2_data, NULL, 0); |
1550 } | 1656 } |
1551 } | 1657 } |
1552 | 1658 |
1553 static void msn_got_photo(void *data, const char *url_text, size_t len) | 1659 static void |
1660 msn_got_photo(void *data, const char *url_text, size_t len) | |
1554 { | 1661 { |
1555 MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)data; | 1662 MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)data; |
1556 int id = -1; | 1663 int id = -1; |
1557 | 1664 |
1558 /* Unmarshall the saved state */ | 1665 /* Unmarshall the saved state */ |
1563 char *photo_url_text = info2_data->photo_url_text; | 1670 char *photo_url_text = info2_data->photo_url_text; |
1564 char *tooltip_text = info2_data->tooltip_text; | 1671 char *tooltip_text = info2_data->tooltip_text; |
1565 const char *title = info2_data->title; | 1672 const char *title = info2_data->title; |
1566 | 1673 |
1567 /* Try to put the photo in there too, if there's one and is readable */ | 1674 /* Try to put the photo in there too, if there's one and is readable */ |
1568 if (data && url_text && len != 0) { | 1675 if (data && url_text && len != 0) |
1676 { | |
1569 if (strstr(url_text, "400 Bad Request") | 1677 if (strstr(url_text, "400 Bad Request") |
1570 || strstr(url_text, "403 Forbidden") | 1678 || strstr(url_text, "403 Forbidden") |
1571 || strstr(url_text, "404 Not Found")) { | 1679 || strstr(url_text, "404 Not Found")) |
1680 { | |
1572 | 1681 |
1573 gaim_debug_info("msn", "Error getting %s: %s\n", | 1682 gaim_debug_info("msn", "Error getting %s: %s\n", |
1574 photo_url_text, url_text); | 1683 photo_url_text, url_text); |
1575 } else { | 1684 } |
1685 else | |
1686 { | |
1576 char buf[1024]; | 1687 char buf[1024]; |
1577 gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len); | 1688 gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len); |
1578 id = gaim_imgstore_add(url_text, len, NULL); | 1689 id = gaim_imgstore_add(url_text, len, NULL); |
1579 g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id); | 1690 g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id); |
1580 g_string_prepend(s, buf); | 1691 g_string_prepend(s, buf); |
1638 | 1749 |
1639 return TRUE; | 1750 return TRUE; |
1640 } | 1751 } |
1641 | 1752 |
1642 static GaimPluginPrefFrame * | 1753 static GaimPluginPrefFrame * |
1643 get_plugin_pref_frame(GaimPlugin *plugin) { | 1754 get_plugin_pref_frame(GaimPlugin *plugin) |
1755 { | |
1644 GaimPluginPrefFrame *frame; | 1756 GaimPluginPrefFrame *frame; |
1645 GaimPluginPref *ppref; | 1757 GaimPluginPref *ppref; |
1646 | 1758 |
1647 frame = gaim_plugin_pref_frame_new(); | 1759 frame = gaim_plugin_pref_frame_new(); |
1648 | 1760 |