comparison src/protocols/msn/msn.c @ 7675:66d9440db6ec

[gaim-migrate @ 8319] marv writes: "This fixes some crashes on unusual long profile fields for yahoo, and probably msn. One test case is the yahoo [l]user "kent_nwo4life", which crashes without this patch." committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 30 Nov 2003 23:49:45 +0000
parents 3a48ade4f510
children 99ffabc6ce73
comparison
equal deleted inserted replaced
7674:3d49c33db741 7675:66d9440db6ec
1271 char buf[1024]; 1271 char buf[1024];
1272 char *user_url = NULL; 1272 char *user_url = NULL;
1273 gboolean found; 1273 gboolean found;
1274 gboolean has_info = FALSE; 1274 gboolean has_info = FALSE;
1275 char *url_buffer; 1275 char *url_buffer;
1276 GString *s;
1277 int stripped_len;
1276 1278
1277 gaim_debug_info("msn", "In msn_got_info\n"); 1279 gaim_debug_info("msn", "In msn_got_info\n");
1278 1280
1279 if (url_text == NULL || strcmp(url_text, "") == 0) 1281 if (url_text == NULL || strcmp(url_text, "") == 0)
1280 { 1282 {
1330 url_buffer[strlen(url_buffer) - 4] = '\0'; 1332 url_buffer[strlen(url_buffer) - 4] = '\0';
1331 } 1333 }
1332 1334
1333 /* Nuke the html, it's easier than trying to parse the horrid stuff */ 1335 /* Nuke the html, it's easier than trying to parse the horrid stuff */
1334 stripped = gaim_markup_strip_html(url_buffer); 1336 stripped = gaim_markup_strip_html(url_buffer);
1337 stripped_len = strlen(stripped);
1335 1338
1336 gaim_debug_misc("msn", "stripped = %p\n", stripped); 1339 gaim_debug_misc("msn", "stripped = %p\n", stripped);
1337 gaim_debug_misc("msn", "url_buffer = %p\n", url_buffer); 1340 gaim_debug_misc("msn", "url_buffer = %p\n", url_buffer);
1338 1341
1339 /* Gonna re-use the memory we've already got for url_buffer */ 1342 /* Gonna re-use the memory we've already got for url_buffer */
1340 strcpy(url_buffer, "<html><body>\n"); 1343 /* No we're not. */
1344 s = g_string_sized_new(strlen(url_buffer));
1341 1345
1342 /* Extract their Name and put it in */ 1346 /* Extract their Name and put it in */
1343 found = gaim_markup_extract_info_field(stripped, url_buffer, 1347 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1344 "\tName", 0, "\t", '\n', "Undisclosed", _("Name"), 0, NULL); 1348 "\tName", 0, "\t", '\n', "Undisclosed", _("Name"), 0, NULL);
1345 1349
1346 if (found) 1350 if (found)
1347 has_info = TRUE; 1351 has_info = TRUE;
1348 1352
1349 /* Extract their Age and put it in */ 1353 /* Extract their Age and put it in */
1350 found = gaim_markup_extract_info_field(stripped, url_buffer, "\tAge", 1354 found = gaim_markup_extract_info_field(stripped, stripped_len, s,"\tAge",
1351 0, "\t", '\n', "Undisclosed", _("Age"), 0, NULL); 1355 0, "\t", '\n', "Undisclosed", _("Age"), 0, NULL);
1352 1356
1353 if (found) 1357 if (found)
1354 has_info = TRUE; 1358 has_info = TRUE;
1355 1359
1356 /* Extract their Gender and put it in */ 1360 /* Extract their Gender and put it in */
1357 found = gaim_markup_extract_info_field(stripped, url_buffer, "\tGender", 1361 found = gaim_markup_extract_info_field(stripped, stripped_len, s,"\tGender",
1358 6, "\t", '\n', "Undisclosed", _("Gender"), 0, NULL); 1362 6, "\t", '\n', "Undisclosed", _("Gender"), 0, NULL);
1359 1363
1360 if (found) 1364 if (found)
1361 has_info = TRUE; 1365 has_info = TRUE;
1362 1366
1363 /* Extract their MaritalStatus and put it in */ 1367 /* Extract their MaritalStatus and put it in */
1364 found = gaim_markup_extract_info_field(stripped, url_buffer, 1368 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1365 "\tMaritalStatus", 0, "\t", '\n', "Undisclosed", 1369 "\tMaritalStatus", 0, "\t", '\n', "Undisclosed",
1366 _("Marital Status"), 0, NULL); 1370 _("Marital Status"), 0, NULL);
1367 1371
1368 if (found) 1372 if (found)
1369 has_info = TRUE; 1373 has_info = TRUE;
1370 1374
1371 /* Extract their Location and put it in */ 1375 /* Extract their Location and put it in */
1372 found = gaim_markup_extract_info_field(stripped, url_buffer, 1376 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1373 "\tLocation", 0, "\t", '\n', "Undisclosed", _("Location"), 1377 "\tLocation", 0, "\t", '\n', "Undisclosed", _("Location"),
1374 0, NULL); 1378 0, NULL);
1375 1379
1376 if (found) 1380 if (found)
1377 has_info = TRUE; 1381 has_info = TRUE;
1378 1382
1379 /* Extract their Occupation and put it in */ 1383 /* Extract their Occupation and put it in */
1380 found = gaim_markup_extract_info_field(stripped, url_buffer, 1384 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1381 "\t Occupation", 6, "\t", '\n', "Undisclosed", _("Occupation"), 1385 "\t Occupation", 6, "\t", '\n', "Undisclosed", _("Occupation"),
1382 0, NULL); 1386 0, NULL);
1383 1387
1384 if (found) 1388 if (found)
1385 has_info = TRUE; 1389 has_info = TRUE;
1391 * certain order, so we can successively search to pin down the 1395 * certain order, so we can successively search to pin down the
1392 * distinct values. 1396 * distinct values.
1393 */ 1397 */
1394 1398
1395 /* Check if they have A Little About Me */ 1399 /* Check if they have A Little About Me */
1396 found = gaim_markup_extract_info_field(stripped, url_buffer, 1400 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1397 "\tA Little About Me", 1, "Favorite Things", '\n', NULL, 1401 "\tA Little About Me", 1, "Favorite Things", '\n', NULL,
1398 _("A Little About Me"), 0, NULL); 1402 _("A Little About Me"), 0, NULL);
1399 1403
1400 if (!found) 1404 if (!found)
1401 { 1405 {
1402 found = gaim_markup_extract_info_field(stripped, url_buffer, 1406 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1403 "\tA Little About Me", 1, "Hobbies and Interests", '\n', 1407 "\tA Little About Me", 1, "Hobbies and Interests", '\n',
1404 NULL, _("A Little About Me"), 0, NULL); 1408 NULL, _("A Little About Me"), 0, NULL);
1405 } 1409 }
1406 1410
1407 if (!found) 1411 if (!found)
1408 { 1412 {
1409 found = gaim_markup_extract_info_field(stripped, url_buffer, 1413 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1410 "\tA Little About Me", 1, "Favorite Quote", '\n', NULL, 1414 "\tA Little About Me", 1, "Favorite Quote", '\n', NULL,
1411 _("A Little About Me"), 0, NULL); 1415 _("A Little About Me"), 0, NULL);
1412 } 1416 }
1413 1417
1414 if (!found) 1418 if (!found)
1415 { 1419 {
1416 found = gaim_markup_extract_info_field(stripped, url_buffer, 1420 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1417 "\tA Little About Me", 1, "My Homepage\tTake a look", '\n', 1421 "\tA Little About Me", 1, "My Homepage\tTake a look", '\n',
1418 NULL, _("A Little About Me"), 0, NULL); 1422 NULL, _("A Little About Me"), 0, NULL);
1419 } 1423 }
1420 1424
1421 if (!found) 1425 if (!found)
1422 { 1426 {
1423 gaim_markup_extract_info_field(stripped, url_buffer, 1427 gaim_markup_extract_info_field(stripped, stripped_len, s,
1424 "\tA Little About Me", 1, "last updated", '\n', NULL, 1428 "\tA Little About Me", 1, "last updated", '\n', NULL,
1425 _("A Little About Me"), 0, NULL); 1429 _("A Little About Me"), 0, NULL);
1426 } 1430 }
1427 1431
1428 if (found) 1432 if (found)
1429 has_info = TRUE; 1433 has_info = TRUE;
1430 1434
1431 /* Check if they have Favorite Things */ 1435 /* Check if they have Favorite Things */
1432 found = gaim_markup_extract_info_field(stripped, url_buffer, 1436 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1433 "Favorite Things", 1, "Hobbies and Interests", '\n', NULL, 1437 "Favorite Things", 1, "Hobbies and Interests", '\n', NULL,
1434 _("Favorite Things"), 0, NULL); 1438 _("Favorite Things"), 0, NULL);
1435 1439
1436 if (!found) 1440 if (!found)
1437 { 1441 {
1438 found = gaim_markup_extract_info_field(stripped, url_buffer, 1442 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1439 "Favorite Things", 1, "Favorite Quote", '\n', NULL, 1443 "Favorite Things", 1, "Favorite Quote", '\n', NULL,
1440 "Favorite Things", 0, NULL); 1444 "Favorite Things", 0, NULL);
1441 } 1445 }
1442 1446
1443 if (!found) 1447 if (!found)
1444 { 1448 {
1445 found = gaim_markup_extract_info_field(stripped, url_buffer, 1449 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1446 "Favorite Things", 1, "My Homepage\tTake a look", '\n', NULL, 1450 "Favorite Things", 1, "My Homepage\tTake a look", '\n', NULL,
1447 _("Favorite Things"), 0, NULL); 1451 _("Favorite Things"), 0, NULL);
1448 } 1452 }
1449 1453
1450 if (!found) 1454 if (!found)
1451 { 1455 {
1452 gaim_markup_extract_info_field(stripped, url_buffer, 1456 gaim_markup_extract_info_field(stripped, stripped_len, s,
1453 "Favorite Things", 1, "last updated", '\n', NULL, 1457 "Favorite Things", 1, "last updated", '\n', NULL,
1454 _("Favorite Things"), 0, NULL); 1458 _("Favorite Things"), 0, NULL);
1455 } 1459 }
1456 1460
1457 if (found) 1461 if (found)
1458 has_info = TRUE; 1462 has_info = TRUE;
1459 1463
1460 /* Check if they have Hobbies and Interests */ 1464 /* Check if they have Hobbies and Interests */
1461 found = gaim_markup_extract_info_field(stripped, url_buffer, 1465 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1462 "Hobbies and Interests", 1, "Favorite Quote", '\n', NULL, 1466 "Hobbies and Interests", 1, "Favorite Quote", '\n', NULL,
1463 _("Hobbies and Interests"), 0, NULL); 1467 _("Hobbies and Interests"), 0, NULL);
1464 1468
1465 if (!found) 1469 if (!found)
1466 { 1470 {
1467 found = gaim_markup_extract_info_field(stripped, url_buffer, 1471 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1468 "Hobbies and Interests", 1, "My Homepage\tTake a look", 1472 "Hobbies and Interests", 1, "My Homepage\tTake a look",
1469 '\n', NULL, _("Hobbies and Interests"), 0, NULL); 1473 '\n', NULL, _("Hobbies and Interests"), 0, NULL);
1470 } 1474 }
1471 1475
1472 if (!found) 1476 if (!found)
1473 { 1477 {
1474 gaim_markup_extract_info_field(stripped, url_buffer, 1478 gaim_markup_extract_info_field(stripped, stripped_len, s,
1475 "Hobbies and Interests", 1, "last updated", '\n', NULL, 1479 "Hobbies and Interests", 1, "last updated", '\n', NULL,
1476 _("Hobbies and Interests"), 0, NULL); 1480 _("Hobbies and Interests"), 0, NULL);
1477 } 1481 }
1478 1482
1479 if (found) 1483 if (found)
1480 has_info = TRUE; 1484 has_info = TRUE;
1481 1485
1482 /* Check if they have Favorite Quote */ 1486 /* Check if they have Favorite Quote */
1483 found = gaim_markup_extract_info_field(stripped, url_buffer, 1487 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1484 "Favorite Quote", 1, "My Homepage\tTake a look", '\n', NULL, 1488 "Favorite Quote", 1, "My Homepage\tTake a look", '\n', NULL,
1485 _("Favorite Quote"), 0, NULL); 1489 _("Favorite Quote"), 0, NULL);
1486 1490
1487 if (!found) 1491 if (!found)
1488 { 1492 {
1489 gaim_markup_extract_info_field(stripped, url_buffer, 1493 gaim_markup_extract_info_field(stripped, stripped_len, s,
1490 "Favorite Quote", 1, "last updated", '\n', NULL, 1494 "Favorite Quote", 1, "last updated", '\n', NULL,
1491 _("Favorite Quote"), 0, NULL); 1495 _("Favorite Quote"), 0, NULL);
1492 } 1496 }
1493 1497
1494 if (found) 1498 if (found)
1495 has_info = TRUE; 1499 has_info = TRUE;
1496 1500
1497 /* Extract the last updated date and put it in */ 1501 /* Extract the last updated date and put it in */
1498 found = gaim_markup_extract_info_field(stripped, url_buffer, 1502 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1499 "\tlast updated:", 1, "\n", '\n', NULL, _("Last Updated"), 1503 "\tlast updated:", 1, "\n", '\n', NULL, _("Last Updated"),
1500 0, NULL); 1504 0, NULL);
1501 1505
1502 if (found) 1506 if (found)
1503 has_info = TRUE; 1507 has_info = TRUE;
1507 { 1511 {
1508 g_snprintf(buf, sizeof(buf), 1512 g_snprintf(buf, sizeof(buf),
1509 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n", 1513 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n",
1510 _("Homepage"), user_url, user_url); 1514 _("Homepage"), user_url, user_url);
1511 1515
1512 strcat(url_buffer, buf); 1516 g_string_append(s, buf);
1513 1517
1514 g_free(user_url); 1518 g_free(user_url);
1515 1519
1516 has_info = TRUE; 1520 has_info = TRUE;
1517 } 1521 }
1518 1522
1519 /* Finish it off, and show it to them */ 1523 /* Finish it off, and show it to them */
1520 strcat(url_buffer, "</body></html>\n"); 1524 g_string_append(s, "</body></html>\n");
1521 1525
1522 if (has_info) 1526 if (has_info)
1523 { 1527 {
1524 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"), 1528 gaim_notify_formatted(info_data->gc, NULL, _("Buddy Information"),
1525 NULL, url_buffer, NULL, NULL); 1529 NULL, s->str, NULL, NULL);
1526 } 1530 }
1527 else 1531 else
1528 { 1532 {
1529 char primary[256]; 1533 char primary[256];
1530 1534
1534 _("The user's profile is empty.")); 1538 _("The user's profile is empty."));
1535 } 1539 }
1536 1540
1537 g_free(stripped); 1541 g_free(stripped);
1538 g_free(url_buffer); 1542 g_free(url_buffer);
1539 1543 g_string_free(s, TRUE);
1540 g_free(info_data->name); 1544 g_free(info_data->name);
1541 g_free(info_data); 1545 g_free(info_data);
1542 } 1546 }
1543 1547
1544 static void 1548 static void