Mercurial > pidgin.yaz
comparison src/protocols/msn/msn.c @ 6859:17514a2f976a
[gaim-migrate @ 7404]
The old MSN Get Info code was messy, and I'm a neat-freak when it comes to
code.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 16 Sep 2003 04:13:59 +0000 |
parents | 885c6528843b |
children | 66dd420d3d23 |
comparison
equal
deleted
inserted
replaced
6858:885c6528843b | 6859:17514a2f976a |
---|---|
1191 } | 1191 } |
1192 | 1192 |
1193 static void | 1193 static void |
1194 msn_got_info(gpointer data, char *url_text, unsigned long len) | 1194 msn_got_info(gpointer data, char *url_text, unsigned long len) |
1195 { | 1195 { |
1196 char *stripped,*p,*q; | 1196 char *stripped, *p, *q; |
1197 char buf[1024]; | 1197 char buf[1024]; |
1198 char *user_url = NULL; | 1198 char *user_url = NULL; |
1199 | 1199 gboolean found; |
1200 if (!url_text || !strcmp(url_text,"")) { | 1200 |
1201 if (url_text == NULL || strcmp(url_text,"") == 0) | |
1202 { | |
1201 g_show_info_text(NULL, NULL, 2, | 1203 g_show_info_text(NULL, NULL, 2, |
1202 _("<html><body><b>Error retrieving profile</b></body></html>"), NULL); | 1204 _("<html><body><b>Error retrieving profile</b></body></html>"), |
1203 return; | 1205 NULL); |
1204 } | 1206 |
1205 | 1207 return; |
1206 /* if they have a homepage link, MSN masks it such that we need to | 1208 } |
1209 | |
1210 /* If they have a homepage link, MSN masks it such that we need to | |
1207 * fetch the url out before strip_html() nukes it */ | 1211 * fetch the url out before strip_html() nukes it */ |
1208 if((p = strstr(url_text, "Take a look at my </font><A class=viewDesc title=\"")) != NULL ) | 1212 if ((p = strstr(url_text, |
1213 "Take a look at my </font><A class=viewDesc title=\"")) != NULL) | |
1209 { | 1214 { |
1210 p += 50; | 1215 p += 50; |
1211 if((q = strchr(p, '"')) != NULL) | 1216 |
1212 user_url = g_strndup(p,q-p); | 1217 if ((q = strchr(p, '"')) != NULL) |
1213 } | 1218 user_url = g_strndup(p, q - p); |
1214 | 1219 } |
1215 /* strip_html() doesn't strip out character entities like and · */ | 1220 |
1216 while ((p = strstr(url_text, " ")) != NULL) { | 1221 /* |
1217 memmove(p, p+6, strlen(p+6)); | 1222 * strip_html() doesn't strip out character entities like |
1218 url_text[strlen(url_text)-6] = '\0'; | 1223 * and · |
1219 } | 1224 */ |
1220 while ((p = strstr(url_text, "·")) != NULL) { | 1225 while ((p = strstr(url_text, " ")) != NULL) |
1221 memmove(p, p+6, strlen(p+6)); | 1226 { |
1222 url_text[strlen(url_text)-6] = '\0'; | 1227 memmove(p, p + 6, strlen(p + 6)); |
1223 } | 1228 url_text[strlen(url_text) - 6] = '\0'; |
1224 | 1229 } |
1225 /* nuke the nasty \r's that just get in the way */ | 1230 |
1226 while ((p = strchr(url_text, '\r')) != NULL) { | 1231 while ((p = strstr(url_text, "·")) != NULL) |
1227 memmove(p, p+1, strlen(p+1)); | 1232 { |
1228 url_text[strlen(url_text)-1] = '\0'; | 1233 memmove(p, p + 6, strlen(p + 6)); |
1234 url_text[strlen(url_text) - 6] = '\0'; | |
1235 } | |
1236 | |
1237 /* Nuke the nasty \r's that just get in the way */ | |
1238 while ((p = strchr(url_text, '\r')) != NULL) | |
1239 { | |
1240 memmove(p, p + 1, strlen(p + 1)); | |
1241 url_text[strlen(url_text) - 1] = '\0'; | |
1229 } | 1242 } |
1230 | 1243 |
1231 /* MSN always puts in ' for apostrophies...replace them */ | 1244 /* MSN always puts in ' for apostrophies...replace them */ |
1232 while ((p = strstr(url_text, "'")) != NULL) { | 1245 while ((p = strstr(url_text, "'")) != NULL) |
1246 { | |
1233 *p = '\''; | 1247 *p = '\''; |
1234 memmove(p+1, p+5, strlen(p+5)); | 1248 memmove(p + 1, p + 5, strlen(p + 5)); |
1235 url_text[strlen(url_text)-4] = '\0'; | 1249 url_text[strlen(url_text) - 4] = '\0'; |
1236 } | 1250 } |
1237 | 1251 |
1238 /* nuke the html, it's easier than trying to parse the horrid stuff */ | 1252 /* Nuke the html, it's easier than trying to parse the horrid stuff */ |
1239 stripped = strip_html(url_text); | 1253 stripped = strip_html(url_text); |
1240 | 1254 |
1241 /* gonna re-use the memory we've already got for url_text */ | 1255 /* Gonna re-use the memory we've already got for url_text */ |
1242 strcpy(url_text, "<html><body>\n"); | 1256 strcpy(url_text, "<html><body>\n"); |
1243 | 1257 |
1244 /* extract their Name and put it in */ | 1258 /* Extract their Name and put it in */ |
1245 info_extract_field(stripped, url_text, "\tName", 0, "\t", '\n', | 1259 info_extract_field(stripped, url_text, "\tName", 0, "\t", '\n', |
1246 "Undisclosed", _("Name"), 0, NULL); | 1260 "Undisclosed", _("Name"), 0, NULL); |
1247 | 1261 |
1248 /* extract their Age and put it in */ | 1262 /* Extract their Age and put it in */ |
1249 info_extract_field(stripped, url_text, "\tAge", 0, "\t", '\n', | 1263 info_extract_field(stripped, url_text, "\tAge", 0, "\t", '\n', |
1250 "Undisclosed", _("Age"), 0, NULL); | 1264 "Undisclosed", _("Age"), 0, NULL); |
1251 | 1265 |
1252 /* extract their Gender and put it in */ | 1266 /* Extract their Gender and put it in */ |
1253 info_extract_field(stripped, url_text, "\tGender", 6, "\t", '\n', | 1267 info_extract_field(stripped, url_text, "\tGender", 6, "\t", '\n', |
1254 "Undisclosed", _("Gender"), 0, NULL); | 1268 "Undisclosed", _("Gender"), 0, NULL); |
1255 | 1269 |
1256 /* extract their MaritalStatus and put it in */ | 1270 /* Extract their MaritalStatus and put it in */ |
1257 info_extract_field(stripped, url_text, "\tMaritalStatus", 0, "\t", '\n', | 1271 info_extract_field(stripped, url_text, "\tMaritalStatus", 0, "\t", '\n', |
1258 "Undisclosed", _("Marital Status"), 0, NULL); | 1272 "Undisclosed", _("Marital Status"), 0, NULL); |
1259 | 1273 |
1260 /* extract their Location and put it in */ | 1274 /* Extract their Location and put it in */ |
1261 info_extract_field(stripped, url_text, "\tLocation", 0, "\t", '\n', | 1275 info_extract_field(stripped, url_text, "\tLocation", 0, "\t", '\n', |
1262 "Undisclosed", _("Location"), 0, NULL); | 1276 "Undisclosed", _("Location"), 0, NULL); |
1263 | 1277 |
1264 /* extract their Occupation and put it in */ | 1278 /* Extract their Occupation and put it in */ |
1265 info_extract_field(stripped, url_text, "\t Occupation", 6, "\t", '\n', | 1279 info_extract_field(stripped, url_text, "\t Occupation", 6, "\t", '\n', |
1266 "Undisclosed", _("Occupation"), 0, NULL); | 1280 "Undisclosed", _("Occupation"), 0, NULL); |
1267 | 1281 |
1268 /* the fields, 'A Little About Me', 'Favorite Things', 'Hobbies and Interests', | 1282 /* |
1269 * 'Favorite Quote', and 'My Homepage' may or may not appear, in any combination. | 1283 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies |
1270 * however, they do appear in certain order, so we can successively search to | 1284 * and Interests', 'Favorite Quote', and 'My Homepage' may or may |
1271 * pin down the distinct values. | 1285 * not appear, in any combination. However, they do appear in |
1286 * certain order, so we can successively search to pin down the | |
1287 * distinct values. | |
1272 */ | 1288 */ |
1273 | 1289 |
1274 /* check if they have A Little About Me */ | 1290 /* Check if they have A Little About Me */ |
1275 if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "Favorite Things", '\n', | 1291 found = info_extract_field(stripped, url_text, "\tA Little About Me", |
1276 NULL, _("A Little About Me"), 0, NULL)) | 1292 1, "Favorite Things", '\n', NULL, |
1277 if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "Hobbies and Interests", '\n', | 1293 _("A Little About Me"), 0, NULL); |
1278 NULL, _("A Little About Me"), 0, NULL)) | 1294 |
1279 if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "Favorite Quote", '\n', | 1295 if (!found) |
1280 NULL, _("A Little About Me"), 0, NULL)) | 1296 { |
1281 if(!info_extract_field(stripped, url_text, "\tA Little About Me", 1, "My Homepage\tTake a look", '\n', | 1297 found = info_extract_field(stripped, url_text, |
1282 NULL, _("A Little About Me"), 0, NULL)) | 1298 "\tA Little About Me", 1, |
1283 info_extract_field(stripped, url_text, "\tA Little About Me", 1, "last updated", '\n', | 1299 "Hobbies and Interests", '\n', NULL, |
1300 _("A Little About Me"), 0, NULL); | |
1301 } | |
1302 | |
1303 if (!found) | |
1304 { | |
1305 found = info_extract_field(stripped, url_text, | |
1306 "\tA Little About Me", 1, | |
1307 "Favorite Quote", '\n', NULL, | |
1308 _("A Little About Me"), 0, NULL); | |
1309 } | |
1310 | |
1311 if (!found) | |
1312 { | |
1313 found = info_extract_field(stripped, url_text, | |
1314 "\tA Little About Me", 1, | |
1315 "My Homepage\tTake a look", '\n', NULL, | |
1316 _("A Little About Me"), 0, NULL); | |
1317 } | |
1318 | |
1319 if (!found) | |
1320 { | |
1321 info_extract_field(stripped, url_text, "\tA Little About Me", 1, | |
1322 "last updated", '\n', | |
1284 NULL, _("A Little About Me"), 0, NULL); | 1323 NULL, _("A Little About Me"), 0, NULL); |
1285 | 1324 } |
1286 /* check if they have Favorite Things */ | 1325 |
1287 if(!info_extract_field(stripped, url_text, "Favorite Things", 1, "Hobbies and Interests", '\n', | 1326 /* Check if they have Favorite Things */ |
1288 NULL, _("Favorite Things"), 0, NULL)) | 1327 found = info_extract_field(stripped, url_text, "Favorite Things", 1, |
1289 if(!info_extract_field(stripped, url_text, "Favorite Things", 1, "Favorite Quote", '\n', | 1328 "Hobbies and Interests", '\n', NULL, |
1290 NULL, "Favorite Things", 0, NULL)) | 1329 _("Favorite Things"), 0, NULL); |
1291 if(info_extract_field(stripped, url_text, "Favorite Things", 1, "My Homepage\tTake a look", '\n', | 1330 |
1292 NULL, _("Favorite Things"), 0, NULL)) | 1331 if (!found) |
1293 info_extract_field(stripped, url_text, "Favorite Things", 1, "last updated", '\n', | 1332 { |
1294 NULL, _("Favorite Things"), 0, NULL); | 1333 found = info_extract_field(stripped, url_text, "Favorite Things", 1, |
1295 | 1334 "Favorite Quote", '\n', NULL, |
1296 /* check if they have Hobbies and Interests */ | 1335 "Favorite Things", 0, NULL); |
1297 if(!info_extract_field(stripped, url_text, "Hobbies and Interests", 1, "Favorite Quote", '\n', | 1336 } |
1298 NULL, _("Hobbies and Interests"), 0, NULL)) | 1337 |
1299 if(info_extract_field(stripped, url_text, "Hobbies and Interests", 1, "My Homepage\tTake a look", '\n', | 1338 if (!found) |
1300 NULL, _("Hobbies and Interests"), 0, NULL)) | 1339 { |
1301 info_extract_field(stripped, url_text, "Hobbies and Interests", 1, "last updated", '\n', | 1340 found = info_extract_field(stripped, url_text, "Favorite Things", 1, |
1302 NULL, _("Hobbies and Interests"), 0, NULL); | 1341 "My Homepage\tTake a look", '\n', NULL, |
1303 | 1342 _("Favorite Things"), 0, NULL); |
1304 /* check if they have Favorite Quote */ | 1343 } |
1305 if(!info_extract_field(stripped, url_text, "Favorite Quote", 1, "My Homepage\tTake a look", '\n', | 1344 |
1306 NULL, _("Favorite Quote"), 0, NULL)) | 1345 if (!found) |
1307 info_extract_field(stripped, url_text, "Favorite Quote", 1, "last updated", '\n', | 1346 { |
1308 NULL, _("Favorite Quote"), 0, NULL); | 1347 info_extract_field(stripped, url_text, "Favorite Things", 1, |
1309 | 1348 "last updated", '\n', NULL, |
1310 /* extract the last updated date and put it in */ | 1349 _("Favorite Things"), 0, NULL); |
1350 } | |
1351 | |
1352 /* Check if they have Hobbies and Interests */ | |
1353 found = info_extract_field(stripped, url_text, "Hobbies and Interests", | |
1354 1, "Favorite Quote", '\n', NULL, | |
1355 _("Hobbies and Interests"), 0, NULL); | |
1356 | |
1357 if (!found) | |
1358 { | |
1359 found = info_extract_field(stripped, url_text, | |
1360 "Hobbies and Interests", 1, | |
1361 "My Homepage\tTake a look", '\n', NULL, | |
1362 _("Hobbies and Interests"), 0, NULL); | |
1363 } | |
1364 | |
1365 if (!found) | |
1366 { | |
1367 info_extract_field(stripped, url_text, "Hobbies and Interests", | |
1368 1, "last updated", '\n', NULL, | |
1369 _("Hobbies and Interests"), 0, NULL); | |
1370 } | |
1371 | |
1372 /* Check if they have Favorite Quote */ | |
1373 found = info_extract_field(stripped, url_text, "Favorite Quote", 1, | |
1374 "My Homepage\tTake a look", '\n', NULL, | |
1375 _("Favorite Quote"), 0, NULL); | |
1376 | |
1377 if (!found) | |
1378 { | |
1379 info_extract_field(stripped, url_text, "Favorite Quote", 1, | |
1380 "last updated", '\n', NULL, | |
1381 _("Favorite Quote"), 0, NULL); | |
1382 } | |
1383 | |
1384 /* Extract the last updated date and put it in */ | |
1311 info_extract_field(stripped, url_text, "\tlast updated:", 1, "\n", '\n', | 1385 info_extract_field(stripped, url_text, "\tlast updated:", 1, "\n", '\n', |
1312 NULL, _("Last Updated"), 0, NULL); | 1386 NULL, _("Last Updated"), 0, NULL); |
1313 | 1387 |
1314 /* if we were able to fetch a homepage url earlier, stick it in there */ | 1388 /* If we were able to fetch a homepage url earlier, stick it in there */ |
1315 if(user_url) | 1389 if (user_url != NULL) |
1316 { | 1390 { |
1317 g_snprintf(buf,sizeof(buf),"<b>%s:</b><br><a href=\"%s\">%s</a><br>\n",_("Homepage"),user_url,user_url); | 1391 g_snprintf(buf, sizeof(buf), |
1318 strcat(url_text,buf); | 1392 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n", |
1319 } | 1393 _("Homepage"), user_url, user_url); |
1320 | 1394 |
1321 /* finish it off, and show it to them */ | 1395 strcat(url_text, buf); |
1396 } | |
1397 | |
1398 /* Finish it off, and show it to them */ | |
1322 strcat(url_text, "</body></html>\n"); | 1399 strcat(url_text, "</body></html>\n"); |
1323 g_show_info_text(NULL, NULL, 2, url_text, NULL); | 1400 g_show_info_text(NULL, NULL, 2, url_text, NULL); |
1324 g_free(stripped); | 1401 g_free(stripped); |
1325 } | 1402 } |
1326 | 1403 |