Mercurial > pidgin.yaz
comparison src/protocols/msn/msn.c @ 7104:7700a28929bd
[gaim-migrate @ 7669]
When retrieving user info for an MSN user, the prpl checks if the info is
empty. If so, it displays an error dialog indicating so. Otherwise, it
displays the info.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 01 Oct 2003 05:42:40 +0000 |
parents | c8bf2da398e3 |
children | 6faeeecab0dc |
comparison
equal
deleted
inserted
replaced
7103:5dc4ed905a1a | 7104:7700a28929bd |
---|---|
43 GaimConnection *gc; | 43 GaimConnection *gc; |
44 const char *passport; | 44 const char *passport; |
45 | 45 |
46 } MsnMobileData; | 46 } MsnMobileData; |
47 | 47 |
48 typedef struct | |
49 { | |
50 GaimConnection *gc; | |
51 char *name; | |
52 | |
53 } MsnGetInfoData; | |
54 | |
48 static void | 55 static void |
49 msn_act_id(GaimConnection *gc, const char *entry) | 56 msn_act_id(GaimConnection *gc, const char *entry) |
50 { | 57 { |
51 MsnSession *session = gc->proto_data; | 58 MsnSession *session = gc->proto_data; |
52 GaimAccount *account = gaim_connection_get_account(gc); | 59 GaimAccount *account = gaim_connection_get_account(gc); |
1215 } | 1222 } |
1216 | 1223 |
1217 static void | 1224 static void |
1218 msn_got_info(void *data, const char *url_text, size_t len) | 1225 msn_got_info(void *data, const char *url_text, size_t len) |
1219 { | 1226 { |
1220 GaimConnection *gc = (GaimConnection *)data; | 1227 MsnGetInfoData *info_data = (MsnGetInfoData *)data; |
1221 char *stripped, *p, *q; | 1228 char *stripped, *p, *q; |
1222 char buf[1024]; | 1229 char buf[1024]; |
1223 char *user_url = NULL; | 1230 char *user_url = NULL; |
1224 gboolean found; | 1231 gboolean found; |
1232 gboolean has_info = FALSE; | |
1225 char *url_buffer; | 1233 char *url_buffer; |
1226 | 1234 |
1235 gaim_debug_info("msn", "In msn_got_info\n"); | |
1236 | |
1227 if (url_text == NULL || strcmp(url_text, "") == 0) | 1237 if (url_text == NULL || strcmp(url_text, "") == 0) |
1228 { | 1238 { |
1229 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, | 1239 gaim_notify_formatted(info_data->gc, NULL, |
1240 _("Buddy Information"), NULL, | |
1230 _("<html><body><b>Error retrieving profile</b></body></html>"), | 1241 _("<html><body><b>Error retrieving profile</b></body></html>"), |
1231 NULL, NULL); | 1242 NULL, NULL); |
1232 | 1243 |
1233 return; | 1244 return; |
1234 } | 1245 } |
1278 } | 1289 } |
1279 | 1290 |
1280 /* Nuke the html, it's easier than trying to parse the horrid stuff */ | 1291 /* Nuke the html, it's easier than trying to parse the horrid stuff */ |
1281 stripped = gaim_markup_strip_html(url_buffer); | 1292 stripped = gaim_markup_strip_html(url_buffer); |
1282 | 1293 |
1294 gaim_debug_misc("msn", "stripped = %p\n", stripped); | |
1295 gaim_debug_misc("msn", "url_buffer = %p\n", url_buffer); | |
1296 | |
1283 /* Gonna re-use the memory we've already got for url_buffer */ | 1297 /* Gonna re-use the memory we've already got for url_buffer */ |
1284 strcpy(url_buffer, "<html><body>\n"); | 1298 strcpy(url_buffer, "<html><body>\n"); |
1285 | 1299 |
1286 /* Extract their Name and put it in */ | 1300 /* Extract their Name and put it in */ |
1287 gaim_markup_extract_info_field(stripped, url_buffer, "\tName", 0, "\t", | 1301 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1288 '\n', "Undisclosed", _("Name"), 0, NULL); | 1302 "\tName", 0, "\t", '\n', "Undisclosed", _("Name"), 0, NULL); |
1303 | |
1304 if (found) | |
1305 has_info = TRUE; | |
1289 | 1306 |
1290 /* Extract their Age and put it in */ | 1307 /* Extract their Age and put it in */ |
1291 gaim_markup_extract_info_field(stripped, url_buffer, "\tAge", 0, "\t", | 1308 found = gaim_markup_extract_info_field(stripped, url_buffer, "\tAge", |
1292 '\n', "Undisclosed", _("Age"), 0, NULL); | 1309 0, "\t", '\n', "Undisclosed", _("Age"), 0, NULL); |
1310 | |
1311 if (found) | |
1312 has_info = TRUE; | |
1293 | 1313 |
1294 /* Extract their Gender and put it in */ | 1314 /* Extract their Gender and put it in */ |
1295 gaim_markup_extract_info_field(stripped, url_buffer, "\tGender", 6, "\t", | 1315 found = gaim_markup_extract_info_field(stripped, url_buffer, "\tGender", |
1296 '\n', "Undisclosed", _("Gender"), 0, NULL); | 1316 6, "\t", '\n', "Undisclosed", _("Gender"), 0, NULL); |
1317 | |
1318 if (found) | |
1319 has_info = TRUE; | |
1297 | 1320 |
1298 /* Extract their MaritalStatus and put it in */ | 1321 /* Extract their MaritalStatus and put it in */ |
1299 gaim_markup_extract_info_field(stripped, url_buffer, "\tMaritalStatus", | 1322 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1300 0, "\t", '\n', "Undisclosed", | 1323 "\tMaritalStatus", 0, "\t", '\n', "Undisclosed", |
1301 _("Marital Status"), 0, NULL); | 1324 _("Marital Status"), 0, NULL); |
1325 | |
1326 if (found) | |
1327 has_info = TRUE; | |
1302 | 1328 |
1303 /* Extract their Location and put it in */ | 1329 /* Extract their Location and put it in */ |
1304 gaim_markup_extract_info_field(stripped, url_buffer, "\tLocation", 0, | 1330 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1305 "\t", '\n', "Undisclosed", _("Location"), | 1331 "\tLocation", 0, "\t", '\n', "Undisclosed", _("Location"), |
1306 0, NULL); | 1332 0, NULL); |
1333 | |
1334 if (found) | |
1335 has_info = TRUE; | |
1307 | 1336 |
1308 /* Extract their Occupation and put it in */ | 1337 /* Extract their Occupation and put it in */ |
1309 gaim_markup_extract_info_field(stripped, url_buffer, "\t Occupation", 6, | 1338 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1310 "\t", '\n', "Undisclosed", _("Occupation"), | 1339 "\t Occupation", 6, "\t", '\n', "Undisclosed", _("Occupation"), |
1311 0, NULL); | 1340 0, NULL); |
1341 | |
1342 if (found) | |
1343 has_info = TRUE; | |
1312 | 1344 |
1313 /* | 1345 /* |
1314 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies | 1346 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies |
1315 * and Interests', 'Favorite Quote', and 'My Homepage' may or may | 1347 * and Interests', 'Favorite Quote', and 'My Homepage' may or may |
1316 * not appear, in any combination. However, they do appear in | 1348 * not appear, in any combination. However, they do appear in |
1349 gaim_markup_extract_info_field(stripped, url_buffer, | 1381 gaim_markup_extract_info_field(stripped, url_buffer, |
1350 "\tA Little About Me", 1, "last updated", '\n', NULL, | 1382 "\tA Little About Me", 1, "last updated", '\n', NULL, |
1351 _("A Little About Me"), 0, NULL); | 1383 _("A Little About Me"), 0, NULL); |
1352 } | 1384 } |
1353 | 1385 |
1386 if (found) | |
1387 has_info = TRUE; | |
1388 | |
1354 /* Check if they have Favorite Things */ | 1389 /* Check if they have Favorite Things */ |
1355 found = gaim_markup_extract_info_field(stripped, url_buffer, | 1390 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1356 "Favorite Things", 1, "Hobbies and Interests", '\n', NULL, | 1391 "Favorite Things", 1, "Hobbies and Interests", '\n', NULL, |
1357 _("Favorite Things"), 0, NULL); | 1392 _("Favorite Things"), 0, NULL); |
1358 | 1393 |
1375 gaim_markup_extract_info_field(stripped, url_buffer, | 1410 gaim_markup_extract_info_field(stripped, url_buffer, |
1376 "Favorite Things", 1, "last updated", '\n', NULL, | 1411 "Favorite Things", 1, "last updated", '\n', NULL, |
1377 _("Favorite Things"), 0, NULL); | 1412 _("Favorite Things"), 0, NULL); |
1378 } | 1413 } |
1379 | 1414 |
1415 if (found) | |
1416 has_info = TRUE; | |
1417 | |
1380 /* Check if they have Hobbies and Interests */ | 1418 /* Check if they have Hobbies and Interests */ |
1381 found = gaim_markup_extract_info_field(stripped, url_buffer, | 1419 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1382 "Hobbies and Interests", 1, "Favorite Quote", '\n', NULL, | 1420 "Hobbies and Interests", 1, "Favorite Quote", '\n', NULL, |
1383 _("Hobbies and Interests"), 0, NULL); | 1421 _("Hobbies and Interests"), 0, NULL); |
1384 | 1422 |
1394 gaim_markup_extract_info_field(stripped, url_buffer, | 1432 gaim_markup_extract_info_field(stripped, url_buffer, |
1395 "Hobbies and Interests", 1, "last updated", '\n', NULL, | 1433 "Hobbies and Interests", 1, "last updated", '\n', NULL, |
1396 _("Hobbies and Interests"), 0, NULL); | 1434 _("Hobbies and Interests"), 0, NULL); |
1397 } | 1435 } |
1398 | 1436 |
1437 if (found) | |
1438 has_info = TRUE; | |
1439 | |
1399 /* Check if they have Favorite Quote */ | 1440 /* Check if they have Favorite Quote */ |
1400 found = gaim_markup_extract_info_field(stripped, url_buffer, | 1441 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1401 "Favorite Quote", 1, "My Homepage\tTake a look", '\n', NULL, | 1442 "Favorite Quote", 1, "My Homepage\tTake a look", '\n', NULL, |
1402 _("Favorite Quote"), 0, NULL); | 1443 _("Favorite Quote"), 0, NULL); |
1403 | 1444 |
1406 gaim_markup_extract_info_field(stripped, url_buffer, | 1447 gaim_markup_extract_info_field(stripped, url_buffer, |
1407 "Favorite Quote", 1, "last updated", '\n', NULL, | 1448 "Favorite Quote", 1, "last updated", '\n', NULL, |
1408 _("Favorite Quote"), 0, NULL); | 1449 _("Favorite Quote"), 0, NULL); |
1409 } | 1450 } |
1410 | 1451 |
1452 if (found) | |
1453 has_info = TRUE; | |
1454 | |
1411 /* Extract the last updated date and put it in */ | 1455 /* Extract the last updated date and put it in */ |
1412 gaim_markup_extract_info_field(stripped, url_buffer, | 1456 found = gaim_markup_extract_info_field(stripped, url_buffer, |
1413 "\tlast updated:", 1, "\n", '\n', NULL, _("Last Updated"), | 1457 "\tlast updated:", 1, "\n", '\n', NULL, _("Last Updated"), |
1414 0, NULL); | 1458 0, NULL); |
1459 | |
1460 if (found) | |
1461 has_info = TRUE; | |
1415 | 1462 |
1416 /* If we were able to fetch a homepage url earlier, stick it in there */ | 1463 /* If we were able to fetch a homepage url earlier, stick it in there */ |
1417 if (user_url != NULL) | 1464 if (user_url != NULL) |
1418 { | 1465 { |
1419 g_snprintf(buf, sizeof(buf), | 1466 g_snprintf(buf, sizeof(buf), |
1420 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n", | 1467 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n", |
1421 _("Homepage"), user_url, user_url); | 1468 _("Homepage"), user_url, user_url); |
1422 | 1469 |
1423 strcat(url_buffer, buf); | 1470 strcat(url_buffer, buf); |
1471 | |
1472 g_free(user_url); | |
1473 | |
1474 has_info = TRUE; | |
1424 } | 1475 } |
1425 | 1476 |
1426 /* Finish it off, and show it to them */ | 1477 /* Finish it off, and show it to them */ |
1427 strcat(url_buffer, "</body></html>\n"); | 1478 strcat(url_buffer, "</body></html>\n"); |
1428 | 1479 |
1429 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, | 1480 if (has_info) |
1430 url_buffer, NULL, NULL); | 1481 { |
1482 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), | |
1483 NULL, url_buffer, NULL, NULL); | |
1484 } | |
1485 else | |
1486 { | |
1487 char primary[256]; | |
1488 | |
1489 g_snprintf(primary, sizeof(primary), | |
1490 _("User information for %s unavailable"), info_data->name); | |
1491 gaim_notify_error(info_data->gc, NULL, primary, | |
1492 _("The user's profile is empty.")); | |
1493 } | |
1431 | 1494 |
1432 g_free(stripped); | 1495 g_free(stripped); |
1433 g_free(url_buffer); | 1496 g_free(url_buffer); |
1497 | |
1498 g_free(info_data->name); | |
1499 g_free(info_data); | |
1434 } | 1500 } |
1435 | 1501 |
1436 static void | 1502 static void |
1437 msn_get_info(GaimConnection *gc, const char *name) | 1503 msn_get_info(GaimConnection *gc, const char *name) |
1438 { | 1504 { |
1439 char url[256]; | 1505 MsnGetInfoData *data; |
1440 g_snprintf(url, sizeof url, "%s%s", PROFILE_URL, name); | 1506 char *url; |
1507 | |
1508 data = g_new0(MsnGetInfoData, 1); | |
1509 data->gc = gc; | |
1510 data->name = g_strdup(name); | |
1511 | |
1512 url = g_strdup_printf("%s%s", PROFILE_URL, name); | |
1513 | |
1441 gaim_url_fetch(url, FALSE, | 1514 gaim_url_fetch(url, FALSE, |
1442 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", TRUE, | 1515 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", TRUE, |
1443 msn_got_info, gc); | 1516 msn_got_info, data); |
1517 | |
1518 g_free(url); | |
1444 } | 1519 } |
1445 | 1520 |
1446 static GaimPluginProtocolInfo prpl_info = | 1521 static GaimPluginProtocolInfo prpl_info = |
1447 { | 1522 { |
1448 GAIM_PROTO_MSN, | 1523 GAIM_PROTO_MSN, |