comparison src/protocols/msn/msn.c @ 7094:2343c3aa1dec

[gaim-migrate @ 7659] grab_url() and parse_url() are gone, replaced with gaim_url_fetch() and gaim_url_parse(). They were also moved to util.[ch]. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 01 Oct 2003 03:01:25 +0000
parents 86ed8b2aa665
children c8bf2da398e3
comparison
equal deleted inserted replaced
7093:3650612c7daa 7094:2343c3aa1dec
1213 } 1213 }
1214 } 1214 }
1215 } 1215 }
1216 1216
1217 static void 1217 static void
1218 msn_got_info(gpointer data, char *url_text, unsigned long len) 1218 msn_got_info(void *data, const char *url_text, size_t len)
1219 { 1219 {
1220 GaimConnection *gc = (GaimConnection *)data; 1220 GaimConnection *gc = (GaimConnection *)data;
1221 char *stripped, *p, *q; 1221 char *stripped, *p, *q;
1222 char buf[1024]; 1222 char buf[1024];
1223 char *user_url = NULL; 1223 char *user_url = NULL;
1224 gboolean found; 1224 gboolean found;
1225 1225 char *url_buffer;
1226 if (url_text == NULL || strcmp(url_text,"") == 0) 1226
1227 if (url_text == NULL || strcmp(url_text, "") == 0)
1227 { 1228 {
1228 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, 1229 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL,
1229 _("<html><body><b>Error retrieving profile</b></body></html>"), 1230 _("<html><body><b>Error retrieving profile</b></body></html>"),
1230 NULL, NULL); 1231 NULL, NULL);
1231 1232
1232 return; 1233 return;
1233 } 1234 }
1235
1236 url_buffer = g_strdup(url_text);
1234 1237
1235 /* If they have a homepage link, MSN masks it such that we need to 1238 /* If they have a homepage link, MSN masks it such that we need to
1236 * fetch the url out before strip_html() nukes it */ 1239 * fetch the url out before strip_html() nukes it */
1237 if ((p = strstr(url_text, 1240 if ((p = strstr(url_text,
1238 "Take a look at my </font><A class=viewDesc title=\"")) != NULL) 1241 "Take a look at my </font><A class=viewDesc title=\"")) != NULL)
1245 1248
1246 /* 1249 /*
1247 * strip_html() doesn't strip out character entities like &nbsp; 1250 * strip_html() doesn't strip out character entities like &nbsp;
1248 * and &#183; 1251 * and &#183;
1249 */ 1252 */
1250 while ((p = strstr(url_text, "&nbsp;")) != NULL) 1253 while ((p = strstr(url_buffer, "&nbsp;")) != NULL)
1251 { 1254 {
1252 memmove(p, p + 6, strlen(p + 6)); 1255 memmove(p, p + 6, strlen(p + 6));
1253 url_text[strlen(url_text) - 6] = '\0'; 1256 url_buffer[strlen(url_text) - 6] = '\0';
1254 } 1257 }
1255 1258
1256 while ((p = strstr(url_text, "&#183;")) != NULL) 1259 while ((p = strstr(url_buffer, "&#183;")) != NULL)
1257 { 1260 {
1258 memmove(p, p + 6, strlen(p + 6)); 1261 memmove(p, p + 6, strlen(p + 6));
1259 url_text[strlen(url_text) - 6] = '\0'; 1262 url_buffer[strlen(url_buffer) - 6] = '\0';
1260 } 1263 }
1261 1264
1262 /* Nuke the nasty \r's that just get in the way */ 1265 /* Nuke the nasty \r's that just get in the way */
1263 while ((p = strchr(url_text, '\r')) != NULL) 1266 while ((p = strchr(url_buffer, '\r')) != NULL)
1264 { 1267 {
1265 memmove(p, p + 1, strlen(p + 1)); 1268 memmove(p, p + 1, strlen(p + 1));
1266 url_text[strlen(url_text) - 1] = '\0'; 1269 url_buffer[strlen(url_buffer) - 1] = '\0';
1267 } 1270 }
1268 1271
1269 /* MSN always puts in &#39; for apostrophies...replace them */ 1272 /* MSN always puts in &#39; for apostrophies...replace them */
1270 while ((p = strstr(url_text, "&#39;")) != NULL) 1273 while ((p = strstr(url_buffer, "&#39;")) != NULL)
1271 { 1274 {
1272 *p = '\''; 1275 *p = '\'';
1273 memmove(p + 1, p + 5, strlen(p + 5)); 1276 memmove(p + 1, p + 5, strlen(p + 5));
1274 url_text[strlen(url_text) - 4] = '\0'; 1277 url_buffer[strlen(url_buffer) - 4] = '\0';
1275 } 1278 }
1276 1279
1277 /* Nuke the html, it's easier than trying to parse the horrid stuff */ 1280 /* Nuke the html, it's easier than trying to parse the horrid stuff */
1278 stripped = strip_html(url_text); 1281 stripped = strip_html(url_buffer);
1279 1282
1280 /* Gonna re-use the memory we've already got for url_text */ 1283 /* Gonna re-use the memory we've already got for url_buffer */
1281 strcpy(url_text, "<html><body>\n"); 1284 strcpy(url_buffer, "<html><body>\n");
1282 1285
1283 /* Extract their Name and put it in */ 1286 /* Extract their Name and put it in */
1284 info_extract_field(stripped, url_text, "\tName", 0, "\t", '\n', 1287 info_extract_field(stripped, url_buffer, "\tName", 0, "\t", '\n',
1285 "Undisclosed", _("Name"), 0, NULL); 1288 "Undisclosed", _("Name"), 0, NULL);
1286 1289
1287 /* Extract their Age and put it in */ 1290 /* Extract their Age and put it in */
1288 info_extract_field(stripped, url_text, "\tAge", 0, "\t", '\n', 1291 info_extract_field(stripped, url_buffer, "\tAge", 0, "\t", '\n',
1289 "Undisclosed", _("Age"), 0, NULL); 1292 "Undisclosed", _("Age"), 0, NULL);
1290 1293
1291 /* Extract their Gender and put it in */ 1294 /* Extract their Gender and put it in */
1292 info_extract_field(stripped, url_text, "\tGender", 6, "\t", '\n', 1295 info_extract_field(stripped, url_buffer, "\tGender", 6, "\t", '\n',
1293 "Undisclosed", _("Gender"), 0, NULL); 1296 "Undisclosed", _("Gender"), 0, NULL);
1294 1297
1295 /* Extract their MaritalStatus and put it in */ 1298 /* Extract their MaritalStatus and put it in */
1296 info_extract_field(stripped, url_text, "\tMaritalStatus", 0, "\t", '\n', 1299 info_extract_field(stripped, url_buffer, "\tMaritalStatus", 0, "\t", '\n',
1297 "Undisclosed", _("Marital Status"), 0, NULL); 1300 "Undisclosed", _("Marital Status"), 0, NULL);
1298 1301
1299 /* Extract their Location and put it in */ 1302 /* Extract their Location and put it in */
1300 info_extract_field(stripped, url_text, "\tLocation", 0, "\t", '\n', 1303 info_extract_field(stripped, url_buffer, "\tLocation", 0, "\t", '\n',
1301 "Undisclosed", _("Location"), 0, NULL); 1304 "Undisclosed", _("Location"), 0, NULL);
1302 1305
1303 /* Extract their Occupation and put it in */ 1306 /* Extract their Occupation and put it in */
1304 info_extract_field(stripped, url_text, "\t Occupation", 6, "\t", '\n', 1307 info_extract_field(stripped, url_buffer, "\t Occupation", 6, "\t", '\n',
1305 "Undisclosed", _("Occupation"), 0, NULL); 1308 "Undisclosed", _("Occupation"), 0, NULL);
1306 1309
1307 /* 1310 /*
1308 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies 1311 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies
1309 * and Interests', 'Favorite Quote', and 'My Homepage' may or may 1312 * and Interests', 'Favorite Quote', and 'My Homepage' may or may
1311 * certain order, so we can successively search to pin down the 1314 * certain order, so we can successively search to pin down the
1312 * distinct values. 1315 * distinct values.
1313 */ 1316 */
1314 1317
1315 /* Check if they have A Little About Me */ 1318 /* Check if they have A Little About Me */
1316 found = info_extract_field(stripped, url_text, "\tA Little About Me", 1319 found = info_extract_field(stripped, url_buffer, "\tA Little About Me",
1317 1, "Favorite Things", '\n', NULL, 1320 1, "Favorite Things", '\n', NULL,
1318 _("A Little About Me"), 0, NULL); 1321 _("A Little About Me"), 0, NULL);
1319 1322
1320 if (!found) 1323 if (!found)
1321 { 1324 {
1322 found = info_extract_field(stripped, url_text, 1325 found = info_extract_field(stripped, url_buffer,
1323 "\tA Little About Me", 1, 1326 "\tA Little About Me", 1,
1324 "Hobbies and Interests", '\n', NULL, 1327 "Hobbies and Interests", '\n', NULL,
1325 _("A Little About Me"), 0, NULL); 1328 _("A Little About Me"), 0, NULL);
1326 } 1329 }
1327 1330
1328 if (!found) 1331 if (!found)
1329 { 1332 {
1330 found = info_extract_field(stripped, url_text, 1333 found = info_extract_field(stripped, url_buffer,
1331 "\tA Little About Me", 1, 1334 "\tA Little About Me", 1,
1332 "Favorite Quote", '\n', NULL, 1335 "Favorite Quote", '\n', NULL,
1333 _("A Little About Me"), 0, NULL); 1336 _("A Little About Me"), 0, NULL);
1334 } 1337 }
1335 1338
1336 if (!found) 1339 if (!found)
1337 { 1340 {
1338 found = info_extract_field(stripped, url_text, 1341 found = info_extract_field(stripped, url_buffer,
1339 "\tA Little About Me", 1, 1342 "\tA Little About Me", 1,
1340 "My Homepage\tTake a look", '\n', NULL, 1343 "My Homepage\tTake a look", '\n', NULL,
1341 _("A Little About Me"), 0, NULL); 1344 _("A Little About Me"), 0, NULL);
1342 } 1345 }
1343 1346
1344 if (!found) 1347 if (!found)
1345 { 1348 {
1346 info_extract_field(stripped, url_text, "\tA Little About Me", 1, 1349 info_extract_field(stripped, url_buffer, "\tA Little About Me", 1,
1347 "last updated", '\n', 1350 "last updated", '\n',
1348 NULL, _("A Little About Me"), 0, NULL); 1351 NULL, _("A Little About Me"), 0, NULL);
1349 } 1352 }
1350 1353
1351 /* Check if they have Favorite Things */ 1354 /* Check if they have Favorite Things */
1352 found = info_extract_field(stripped, url_text, "Favorite Things", 1, 1355 found = info_extract_field(stripped, url_buffer, "Favorite Things", 1,
1353 "Hobbies and Interests", '\n', NULL, 1356 "Hobbies and Interests", '\n', NULL,
1354 _("Favorite Things"), 0, NULL); 1357 _("Favorite Things"), 0, NULL);
1355 1358
1356 if (!found) 1359 if (!found)
1357 { 1360 {
1358 found = info_extract_field(stripped, url_text, "Favorite Things", 1, 1361 found = info_extract_field(stripped, url_buffer, "Favorite Things", 1,
1359 "Favorite Quote", '\n', NULL, 1362 "Favorite Quote", '\n', NULL,
1360 "Favorite Things", 0, NULL); 1363 "Favorite Things", 0, NULL);
1361 } 1364 }
1362 1365
1363 if (!found) 1366 if (!found)
1364 { 1367 {
1365 found = info_extract_field(stripped, url_text, "Favorite Things", 1, 1368 found = info_extract_field(stripped, url_buffer, "Favorite Things", 1,
1366 "My Homepage\tTake a look", '\n', NULL, 1369 "My Homepage\tTake a look", '\n', NULL,
1367 _("Favorite Things"), 0, NULL); 1370 _("Favorite Things"), 0, NULL);
1368 } 1371 }
1369 1372
1370 if (!found) 1373 if (!found)
1371 { 1374 {
1372 info_extract_field(stripped, url_text, "Favorite Things", 1, 1375 info_extract_field(stripped, url_buffer, "Favorite Things", 1,
1373 "last updated", '\n', NULL, 1376 "last updated", '\n', NULL,
1374 _("Favorite Things"), 0, NULL); 1377 _("Favorite Things"), 0, NULL);
1375 } 1378 }
1376 1379
1377 /* Check if they have Hobbies and Interests */ 1380 /* Check if they have Hobbies and Interests */
1378 found = info_extract_field(stripped, url_text, "Hobbies and Interests", 1381 found = info_extract_field(stripped, url_buffer, "Hobbies and Interests",
1379 1, "Favorite Quote", '\n', NULL, 1382 1, "Favorite Quote", '\n', NULL,
1380 _("Hobbies and Interests"), 0, NULL); 1383 _("Hobbies and Interests"), 0, NULL);
1381 1384
1382 if (!found) 1385 if (!found)
1383 { 1386 {
1384 found = info_extract_field(stripped, url_text, 1387 found = info_extract_field(stripped, url_buffer,
1385 "Hobbies and Interests", 1, 1388 "Hobbies and Interests", 1,
1386 "My Homepage\tTake a look", '\n', NULL, 1389 "My Homepage\tTake a look", '\n', NULL,
1387 _("Hobbies and Interests"), 0, NULL); 1390 _("Hobbies and Interests"), 0, NULL);
1388 } 1391 }
1389 1392
1390 if (!found) 1393 if (!found)
1391 { 1394 {
1392 info_extract_field(stripped, url_text, "Hobbies and Interests", 1395 info_extract_field(stripped, url_buffer, "Hobbies and Interests",
1393 1, "last updated", '\n', NULL, 1396 1, "last updated", '\n', NULL,
1394 _("Hobbies and Interests"), 0, NULL); 1397 _("Hobbies and Interests"), 0, NULL);
1395 } 1398 }
1396 1399
1397 /* Check if they have Favorite Quote */ 1400 /* Check if they have Favorite Quote */
1398 found = info_extract_field(stripped, url_text, "Favorite Quote", 1, 1401 found = info_extract_field(stripped, url_buffer, "Favorite Quote", 1,
1399 "My Homepage\tTake a look", '\n', NULL, 1402 "My Homepage\tTake a look", '\n', NULL,
1400 _("Favorite Quote"), 0, NULL); 1403 _("Favorite Quote"), 0, NULL);
1401 1404
1402 if (!found) 1405 if (!found)
1403 { 1406 {
1404 info_extract_field(stripped, url_text, "Favorite Quote", 1, 1407 info_extract_field(stripped, url_buffer, "Favorite Quote", 1,
1405 "last updated", '\n', NULL, 1408 "last updated", '\n', NULL,
1406 _("Favorite Quote"), 0, NULL); 1409 _("Favorite Quote"), 0, NULL);
1407 } 1410 }
1408 1411
1409 /* Extract the last updated date and put it in */ 1412 /* Extract the last updated date and put it in */
1410 info_extract_field(stripped, url_text, "\tlast updated:", 1, "\n", '\n', 1413 info_extract_field(stripped, url_buffer, "\tlast updated:", 1, "\n", '\n',
1411 NULL, _("Last Updated"), 0, NULL); 1414 NULL, _("Last Updated"), 0, NULL);
1412 1415
1413 /* If we were able to fetch a homepage url earlier, stick it in there */ 1416 /* If we were able to fetch a homepage url earlier, stick it in there */
1414 if (user_url != NULL) 1417 if (user_url != NULL)
1415 { 1418 {
1416 g_snprintf(buf, sizeof(buf), 1419 g_snprintf(buf, sizeof(buf),
1417 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n", 1420 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n",
1418 _("Homepage"), user_url, user_url); 1421 _("Homepage"), user_url, user_url);
1419 1422
1420 strcat(url_text, buf); 1423 strcat(url_buffer, buf);
1421 } 1424 }
1422 1425
1423 /* Finish it off, and show it to them */ 1426 /* Finish it off, and show it to them */
1424 strcat(url_text, "</body></html>\n"); 1427 strcat(url_buffer, "</body></html>\n");
1425 1428
1426 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, 1429 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL,
1427 url_text, NULL, NULL); 1430 url_buffer, NULL, NULL);
1428 1431
1429 g_free(stripped); 1432 g_free(stripped);
1433 g_free(url_buffer);
1430 } 1434 }
1431 1435
1432 static void 1436 static void
1433 msn_get_info(GaimConnection *gc, const char *name) 1437 msn_get_info(GaimConnection *gc, const char *name)
1434 { 1438 {
1435 char url[256]; 1439 char url[256];
1436 g_snprintf(url, sizeof url, "%s%s", PROFILE_URL, name); 1440 g_snprintf(url, sizeof url, "%s%s", PROFILE_URL, name);
1437 grab_url(url, FALSE, msn_got_info, gc, 1441 gaim_url_fetch(url, FALSE,
1438 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",1); 1442 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", TRUE,
1443 msn_got_info, gc);
1439 } 1444 }
1440 1445
1441 static GaimPluginProtocolInfo prpl_info = 1446 static GaimPluginProtocolInfo prpl_info =
1442 { 1447 {
1443 GAIM_PROTO_MSN, 1448 GAIM_PROTO_MSN,