Mercurial > pidgin
comparison libpurple/util.c @ 29297:338d6a211055
propagate from branch 'im.pidgin.pidgin' (head 46ae10a850bb3c3ce9a3bb47a7de9edd4becdb93)
to branch 'im.pidgin.cpw.attention_ui' (head 35fb2ab19ffca9636faa388b208d31fe7f70caa3)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Tue, 28 Jul 2009 20:52:33 +0000 |
parents | 577bf7ea0395 |
children | da22b6d0151e |
comparison
equal
deleted
inserted
replaced
29296:15cde23b43bc | 29297:338d6a211055 |
---|---|
1407 char *src_tag; | 1407 char *src_tag; |
1408 char *dest_tag; | 1408 char *dest_tag; |
1409 gboolean ignore; | 1409 gboolean ignore; |
1410 }; | 1410 }; |
1411 | 1411 |
1412 /* NOTE: Do not put `do {} while(0)` around this macro (as this is the method | |
1413 recommended in the GCC docs). It contains 'continue's that should | |
1414 affect the while-loop in purple_markup_html_to_xhtml and doing the | |
1415 above would break that. | |
1416 Also, remember to put braces in constructs that require them for | |
1417 multiple statements when using this macro. */ | |
1412 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ | 1418 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ |
1413 const char *o = c + strlen("<" x); \ | 1419 const char *o = c + strlen("<" x); \ |
1414 const char *p = NULL, *q = NULL, *r = NULL; \ | 1420 const char *p = NULL, *q = NULL, *r = NULL; \ |
1415 GString *innards = g_string_new(""); \ | 1421 GString *innards = g_string_new(""); \ |
1416 while(o && *o) { \ | 1422 while(o && *o) { \ |
1458 c++; \ | 1464 c++; \ |
1459 } \ | 1465 } \ |
1460 g_string_free(innards, TRUE); \ | 1466 g_string_free(innards, TRUE); \ |
1461 continue; \ | 1467 continue; \ |
1462 } \ | 1468 } \ |
1463 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \ | 1469 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \ |
1464 (*(c+strlen("<" x)) == '>' || \ | 1470 (*(c+strlen("<" x)) == '>' || \ |
1465 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \ | 1471 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \ |
1472 if(xhtml) \ | |
1473 xhtml = g_string_append(xhtml, "<" y); \ | |
1474 c += strlen("<" x); \ | |
1475 if(*c != '/') { \ | |
1476 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1); \ | |
1477 pt->src_tag = x; \ | |
1478 pt->dest_tag = y; \ | |
1479 tags = g_list_prepend(tags, pt); \ | |
1466 if(xhtml) \ | 1480 if(xhtml) \ |
1467 xhtml = g_string_append(xhtml, "<" y); \ | 1481 xhtml = g_string_append_c(xhtml, '>'); \ |
1468 c += strlen("<" x); \ | 1482 } else { \ |
1469 if(*c != '/') { \ | 1483 if(xhtml) \ |
1470 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1); \ | 1484 xhtml = g_string_append(xhtml, "/>");\ |
1471 pt->src_tag = x; \ | 1485 } \ |
1472 pt->dest_tag = y; \ | 1486 c = strchr(c, '>') + 1; \ |
1473 tags = g_list_prepend(tags, pt); \ | 1487 continue; \ |
1474 if(xhtml) \ | 1488 } |
1475 xhtml = g_string_append_c(xhtml, '>'); \ | 1489 /* Don't forget to check the note above for ALLOW_TAG_ALT. */ |
1476 } else { \ | |
1477 if(xhtml) \ | |
1478 xhtml = g_string_append(xhtml, "/>");\ | |
1479 } \ | |
1480 c = strchr(c, '>') + 1; \ | |
1481 continue; \ | |
1482 } | |
1483 #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) | 1490 #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) |
1484 void | 1491 void |
1485 purple_markup_html_to_xhtml(const char *html, char **xhtml_out, | 1492 purple_markup_html_to_xhtml(const char *html, char **xhtml_out, |
1486 char **plain_out) | 1493 char **plain_out) |
1487 { | 1494 { |
1570 ALLOW_TAG("h3"); | 1577 ALLOW_TAG("h3"); |
1571 ALLOW_TAG("h4"); | 1578 ALLOW_TAG("h4"); |
1572 ALLOW_TAG("h5"); | 1579 ALLOW_TAG("h5"); |
1573 ALLOW_TAG("h6"); | 1580 ALLOW_TAG("h6"); |
1574 /* we only allow html to start the message */ | 1581 /* we only allow html to start the message */ |
1575 if(c == html) | 1582 if(c == html) { |
1576 ALLOW_TAG("html"); | 1583 ALLOW_TAG("html"); |
1584 } | |
1577 ALLOW_TAG_ALT("i", "em"); | 1585 ALLOW_TAG_ALT("i", "em"); |
1578 ALLOW_TAG_ALT("italic", "em"); | 1586 ALLOW_TAG_ALT("italic", "em"); |
1579 ALLOW_TAG("li"); | 1587 ALLOW_TAG("li"); |
1580 ALLOW_TAG("ol"); | 1588 ALLOW_TAG("ol"); |
1581 ALLOW_TAG("p"); | 1589 ALLOW_TAG("p"); |