Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/buddy.c @ 19729:1b8af105614d
Data in vCards is supposed to be plain text, not HTML. So escape
vCards when displaying them.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 11 Sep 2007 05:06:18 +0000 |
parents | 36d5d5048b53 |
children | cd067497cbe0 |
comparison
equal
deleted
inserted
replaced
19728:d397000d32fc | 19729:1b8af105614d |
---|---|
1158 jabber_iq_set_callback(iq, jabber_vcard_save_mine, NULL); | 1158 jabber_iq_set_callback(iq, jabber_vcard_save_mine, NULL); |
1159 | 1159 |
1160 jabber_iq_send(iq); | 1160 jabber_iq_send(iq); |
1161 } | 1161 } |
1162 | 1162 |
1163 static void | |
1164 jabber_string_escape_and_append(GString *string, const char *name, const char *value, gboolean indent) | |
1165 { | |
1166 gchar *escaped; | |
1167 | |
1168 escaped = g_markup_escape_text(value, -1); | |
1169 g_string_append_printf(string, "%s<b>%s:</b> %s<br/>", | |
1170 indent ? " " : "", name, escaped); | |
1171 g_free(escaped); | |
1172 } | |
1173 | |
1163 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) | 1174 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) |
1164 { | 1175 { |
1165 const char *id, *from; | 1176 const char *id, *from; |
1166 GString *info_text; | 1177 GString *info_text; |
1167 char *bare_jid; | 1178 char *bare_jid; |
1202 if(child->type != XMLNODE_TYPE_TAG) | 1213 if(child->type != XMLNODE_TYPE_TAG) |
1203 continue; | 1214 continue; |
1204 | 1215 |
1205 text = xmlnode_get_data(child); | 1216 text = xmlnode_get_data(child); |
1206 if(text && !strcmp(child->name, "FN")) { | 1217 if(text && !strcmp(child->name, "FN")) { |
1207 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", | 1218 jabber_string_escape_and_append(info_text, |
1208 _("Full Name"), text); | 1219 _("Full Name"), text, FALSE); |
1209 } else if(!strcmp(child->name, "N")) { | 1220 } else if(!strcmp(child->name, "N")) { |
1210 for(child2 = child->child; child2; child2 = child2->next) | 1221 for(child2 = child->child; child2; child2 = child2->next) |
1211 { | 1222 { |
1212 char *text2; | 1223 char *text2; |
1213 | 1224 |
1214 if(child2->type != XMLNODE_TYPE_TAG) | 1225 if(child2->type != XMLNODE_TYPE_TAG) |
1215 continue; | 1226 continue; |
1216 | 1227 |
1217 text2 = xmlnode_get_data(child2); | 1228 text2 = xmlnode_get_data(child2); |
1218 if(text2 && !strcmp(child2->name, "FAMILY")) { | 1229 if(text2 && !strcmp(child2->name, "FAMILY")) { |
1219 g_string_append_printf(info_text, | 1230 jabber_string_escape_and_append(info_text, |
1220 "<b>%s:</b> %s<br/>", | 1231 _("Family Name"), text2, FALSE); |
1221 _("Family Name"), text2); | |
1222 } else if(text2 && !strcmp(child2->name, "GIVEN")) { | 1232 } else if(text2 && !strcmp(child2->name, "GIVEN")) { |
1223 g_string_append_printf(info_text, | 1233 jabber_string_escape_and_append(info_text, |
1224 "<b>%s:</b> %s<br/>", | 1234 _("Given Name"), text2, FALSE); |
1225 _("Given Name"), text2); | |
1226 } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | 1235 } else if(text2 && !strcmp(child2->name, "MIDDLE")) { |
1227 g_string_append_printf(info_text, | 1236 jabber_string_escape_and_append(info_text, |
1228 "<b>%s:</b> %s<br/>", | 1237 _("Middle Name"), text2, FALSE); |
1229 _("Middle Name"), text2); | |
1230 } | 1238 } |
1231 g_free(text2); | 1239 g_free(text2); |
1232 } | 1240 } |
1233 } else if(text && !strcmp(child->name, "NICKNAME")) { | 1241 } else if(text && !strcmp(child->name, "NICKNAME")) { |
1234 serv_got_alias(js->gc, from, text); | 1242 serv_got_alias(js->gc, from, text); |
1235 if(b) { | 1243 if(b) { |
1236 purple_blist_node_set_string((PurpleBlistNode*)b, "servernick", text); | 1244 purple_blist_node_set_string((PurpleBlistNode*)b, "servernick", text); |
1237 } | 1245 } |
1238 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", | 1246 jabber_string_escape_and_append(info_text, |
1239 _("Nickname"), text); | 1247 _("Nickname"), text, FALSE); |
1240 } else if(text && !strcmp(child->name, "BDAY")) { | 1248 } else if(text && !strcmp(child->name, "BDAY")) { |
1241 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", | 1249 jabber_string_escape_and_append(info_text, |
1242 _("Birthday"), text); | 1250 _("Birthday"), text, FALSE); |
1243 } else if(!strcmp(child->name, "ADR")) { | 1251 } else if(!strcmp(child->name, "ADR")) { |
1244 gboolean address_line_added = FALSE; | 1252 gboolean address_line_added = FALSE; |
1245 | 1253 |
1246 for(child2 = child->child; child2; child2 = child2->next) | 1254 for(child2 = child->child; child2; child2 = child2->next) |
1247 { | 1255 { |
1262 _("Address")); | 1270 _("Address")); |
1263 address_line_added = TRUE; | 1271 address_line_added = TRUE; |
1264 } | 1272 } |
1265 | 1273 |
1266 if(!strcmp(child2->name, "POBOX")) { | 1274 if(!strcmp(child2->name, "POBOX")) { |
1267 g_string_append_printf(info_text, | 1275 jabber_string_escape_and_append(info_text, |
1268 " <b>%s:</b> %s<br/>", | 1276 _("P.O. Box"), text2, TRUE); |
1269 _("P.O. Box"), text2); | |
1270 } else if(!strcmp(child2->name, "EXTADR")) { | 1277 } else if(!strcmp(child2->name, "EXTADR")) { |
1271 g_string_append_printf(info_text, | 1278 jabber_string_escape_and_append(info_text, |
1272 " <b>%s:</b> %s<br/>", | 1279 _("Extended Address"), text2, TRUE); |
1273 _("Extended Address"), text2); | |
1274 } else if(!strcmp(child2->name, "STREET")) { | 1280 } else if(!strcmp(child2->name, "STREET")) { |
1275 g_string_append_printf(info_text, | 1281 jabber_string_escape_and_append(info_text, |
1276 " <b>%s:</b> %s<br/>", | 1282 _("Street Address"), text2, TRUE); |
1277 _("Street Address"), text2); | |
1278 } else if(!strcmp(child2->name, "LOCALITY")) { | 1283 } else if(!strcmp(child2->name, "LOCALITY")) { |
1279 g_string_append_printf(info_text, | 1284 jabber_string_escape_and_append(info_text, |
1280 " <b>%s:</b> %s<br/>", | 1285 _("Locality"), text2, TRUE); |
1281 _("Locality"), text2); | |
1282 } else if(!strcmp(child2->name, "REGION")) { | 1286 } else if(!strcmp(child2->name, "REGION")) { |
1283 g_string_append_printf(info_text, | 1287 jabber_string_escape_and_append(info_text, |
1284 " <b>%s:</b> %s<br/>", | 1288 _("Region"), text2, TRUE); |
1285 _("Region"), text2); | |
1286 } else if(!strcmp(child2->name, "PCODE")) { | 1289 } else if(!strcmp(child2->name, "PCODE")) { |
1287 g_string_append_printf(info_text, | 1290 jabber_string_escape_and_append(info_text, |
1288 " <b>%s:</b> %s<br/>", | 1291 _("Postal Code"), text2, TRUE); |
1289 _("Postal Code"), text2); | |
1290 } else if(!strcmp(child2->name, "CTRY") | 1292 } else if(!strcmp(child2->name, "CTRY") |
1291 || !strcmp(child2->name, "COUNTRY")) { | 1293 || !strcmp(child2->name, "COUNTRY")) { |
1292 g_string_append_printf(info_text, | 1294 jabber_string_escape_and_append(info_text, |
1293 " <b>%s:</b> %s<br/>", | 1295 _("Country"), text2, TRUE); |
1294 _("Country"), text2); | |
1295 } | 1296 } |
1296 g_free(text2); | 1297 g_free(text2); |
1297 } | 1298 } |
1298 } else if(!strcmp(child->name, "TEL")) { | 1299 } else if(!strcmp(child->name, "TEL")) { |
1299 char *number; | 1300 char *number; |
1300 if((child2 = xmlnode_get_child(child, "NUMBER"))) { | 1301 if((child2 = xmlnode_get_child(child, "NUMBER"))) { |
1301 /* show what kind of number it is */ | 1302 /* show what kind of number it is */ |
1302 number = xmlnode_get_data(child2); | 1303 number = xmlnode_get_data(child2); |
1303 if(number) { | 1304 if(number) { |
1304 g_string_append_printf(info_text, | 1305 jabber_string_escape_and_append(info_text, |
1305 "<b>%s:</b> %s<br/>", _("Telephone"), number); | 1306 _("Telephone"), number, FALSE); |
1306 g_free(number); | 1307 g_free(number); |
1307 } | 1308 } |
1308 } else if((number = xmlnode_get_data(child))) { | 1309 } else if((number = xmlnode_get_data(child))) { |
1309 /* lots of clients (including purple) do this, but it's | 1310 /* lots of clients (including purple) do this, but it's |
1310 * out of spec */ | 1311 * out of spec */ |
1311 g_string_append_printf(info_text, | 1312 jabber_string_escape_and_append(info_text, |
1312 "<b>%s:</b> %s<br/>", _("Telephone"), number); | 1313 _("Telephone"), number, FALSE); |
1313 g_free(number); | 1314 g_free(number); |
1314 } | 1315 } |
1315 } else if(!strcmp(child->name, "EMAIL")) { | 1316 } else if(!strcmp(child->name, "EMAIL")) { |
1316 char *userid; | 1317 char *userid, *escaped; |
1317 if((child2 = xmlnode_get_child(child, "USERID"))) { | 1318 if((child2 = xmlnode_get_child(child, "USERID"))) { |
1318 /* show what kind of email it is */ | 1319 /* show what kind of email it is */ |
1319 userid = xmlnode_get_data(child2); | 1320 userid = xmlnode_get_data(child2); |
1320 if(userid) { | 1321 if(userid) { |
1322 escaped = g_markup_escape_text(userid, -1); | |
1321 g_string_append_printf(info_text, | 1323 g_string_append_printf(info_text, |
1322 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", | 1324 "<b>%s:</b> <a href=\"mailto:%s\">%s</a><br/>", |
1323 _("E-Mail"), userid, userid); | 1325 _("E-Mail"), escaped, escaped); |
1326 g_free(escaped); | |
1324 g_free(userid); | 1327 g_free(userid); |
1325 } | 1328 } |
1326 } else if((userid = xmlnode_get_data(child))) { | 1329 } else if((userid = xmlnode_get_data(child))) { |
1327 /* lots of clients (including purple) do this, but it's | 1330 /* lots of clients (including purple) do this, but it's |
1328 * out of spec */ | 1331 * out of spec */ |
1329 g_string_append_printf(info_text, | 1332 escaped = g_markup_escape_text(userid, -1); |
1330 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", | 1333 g_string_append_printf(info_text, |
1331 _("E-Mail"), userid, userid); | 1334 "<b>%s:</b> <a href=\"mailto:%s\">%s</a><br/>", |
1335 _("E-Mail"), escaped, escaped); | |
1336 g_free(escaped); | |
1332 g_free(userid); | 1337 g_free(userid); |
1333 } | 1338 } |
1334 } else if(!strcmp(child->name, "ORG")) { | 1339 } else if(!strcmp(child->name, "ORG")) { |
1335 for(child2 = child->child; child2; child2 = child2->next) | 1340 for(child2 = child->child; child2; child2 = child2->next) |
1336 { | 1341 { |
1339 if(child2->type != XMLNODE_TYPE_TAG) | 1344 if(child2->type != XMLNODE_TYPE_TAG) |
1340 continue; | 1345 continue; |
1341 | 1346 |
1342 text2 = xmlnode_get_data(child2); | 1347 text2 = xmlnode_get_data(child2); |
1343 if(text2 && !strcmp(child2->name, "ORGNAME")) { | 1348 if(text2 && !strcmp(child2->name, "ORGNAME")) { |
1344 g_string_append_printf(info_text, | 1349 jabber_string_escape_and_append(info_text, |
1345 "<b>%s:</b> %s<br/>", | 1350 _("Organization Name"), text2, FALSE); |
1346 _("Organization Name"), text2); | |
1347 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | 1351 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { |
1348 g_string_append_printf(info_text, | 1352 jabber_string_escape_and_append(info_text, |
1349 "<b>%s:</b> %s<br/>", | 1353 _("Organization Unit"), text2, FALSE); |
1350 _("Organization Unit"), text2); | |
1351 } | 1354 } |
1352 g_free(text2); | 1355 g_free(text2); |
1353 } | 1356 } |
1354 } else if(text && !strcmp(child->name, "TITLE")) { | 1357 } else if(text && !strcmp(child->name, "TITLE")) { |
1355 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", | 1358 jabber_string_escape_and_append(info_text, |
1356 _("Title"), text); | 1359 _("Title"), text, FALSE); |
1357 } else if(text && !strcmp(child->name, "ROLE")) { | 1360 } else if(text && !strcmp(child->name, "ROLE")) { |
1358 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", | 1361 jabber_string_escape_and_append(info_text, |
1359 _("Role"), text); | 1362 _("Role"), text, FALSE); |
1360 } else if(text && !strcmp(child->name, "DESC")) { | 1363 } else if(text && !strcmp(child->name, "DESC")) { |
1361 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", | 1364 jabber_string_escape_and_append(info_text, |
1362 _("Description"), text); | 1365 _("Description"), text, FALSE); |
1363 } else if(!strcmp(child->name, "PHOTO") || | 1366 } else if(!strcmp(child->name, "PHOTO") || |
1364 !strcmp(child->name, "LOGO")) { | 1367 !strcmp(child->name, "LOGO")) { |
1365 char *bintext = NULL; | 1368 char *bintext = NULL; |
1366 xmlnode *binval; | 1369 xmlnode *binval; |
1367 | 1370 |