comparison src/html.c @ 5176:6911a84cbab1

[gaim-migrate @ 5540] chip reminded me that attributes can't contain &, <, etc. this function will become sentient soon, if we're not careful. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 19 Apr 2003 17:00:40 +0000
parents 376349b04123
children 0241d6b6702d
comparison
equal deleted inserted replaced
5175:591e8d9a4697 5176:6911a84cbab1
1 /* 1 /*
2 * gaim 2 * gaim
3 * 3 *
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> 4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
5 * 2003, Nathan Walp <faceprint@faceprint.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 10 * (at your option) any later version.
327 char *src_tag; 328 char *src_tag;
328 char *dest_tag; 329 char *dest_tag;
329 }; 330 };
330 331
331 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ 332 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \
332 const char *o = c + 1; \ 333 const char *o = c + strlen("<" x); \
333 const char *p = NULL, *q = NULL, *r = NULL; \ 334 const char *p = NULL, *q = NULL, *r = NULL; \
334 while(*o) { \ 335 GString *innards = g_string_new(""); \
336 while(o && *o) { \
335 if(!q && (*o == '\"' || *o == '\'') ) { \ 337 if(!q && (*o == '\"' || *o == '\'') ) { \
336 q = o; \ 338 q = o; \
337 } else if(q) { \ 339 } else if(q) { \
338 if(*o == *q) { \ 340 if(*o == *q) { \
341 char *unescaped = g_strndup(q+1, o-q-1); \
342 char *escaped = g_markup_escape_text(unescaped, -1); \
343 g_string_append_printf(innards, "%c%s%c", *q, escaped, *q); \
339 q = NULL; \ 344 q = NULL; \
340 } else if(*c == '\\') { \ 345 } else if(*c == '\\') { \
341 o++; \ 346 o++; \
342 } \ 347 } \
343 } else if(*o == '<') { \ 348 } else if(*o == '<') { \
344 r = o; \ 349 r = o; \
345 } else if(*o == '>') { \ 350 } else if(*o == '>') { \
346 p = o; \ 351 p = o; \
347 break; \ 352 break; \
353 } else { \
354 innards = g_string_append_c(innards, *o); \
348 } \ 355 } \
349 o++; \ 356 o++; \
350 } \ 357 } \
351 if(p && !r) { \ 358 if(p && !r) { \
352 if(*(p-1) != '/') { \ 359 if(*(p-1) != '/') { \
355 pt->dest_tag = y; \ 362 pt->dest_tag = y; \
356 tags = g_list_prepend(tags, pt); \ 363 tags = g_list_prepend(tags, pt); \
357 } \ 364 } \
358 xhtml = g_string_append(xhtml, "<" y); \ 365 xhtml = g_string_append(xhtml, "<" y); \
359 c += strlen("<" x ); \ 366 c += strlen("<" x ); \
360 xhtml = g_string_append_len(xhtml, c, (p - c) + 1); \ 367 xhtml = g_string_append(xhtml, innards->str); \
368 xhtml = g_string_append_c(xhtml, '>'); \
361 c = p + 1; \ 369 c = p + 1; \
362 } else { \ 370 } else { \
363 xhtml = g_string_append(xhtml, "&lt;"); \ 371 xhtml = g_string_append(xhtml, "&lt;"); \
364 plain = g_string_append_c(plain, '<'); \ 372 plain = g_string_append_c(plain, '<'); \
373 c++; \
365 } \ 374 } \
375 g_string_free(innards, TRUE); \
366 continue; \ 376 continue; \
367 } \ 377 } \
368 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \ 378 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \
369 (*(c+strlen("<" x)) == '>' || \ 379 (*(c+strlen("<" x)) == '>' || \
370 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \ 380 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \
387 void html_to_xhtml(const char *html, char **xhtml_out, char **plain_out) { 397 void html_to_xhtml(const char *html, char **xhtml_out, char **plain_out) {
388 GString *xhtml = g_string_new(""); 398 GString *xhtml = g_string_new("");
389 GString *plain = g_string_new(""); 399 GString *plain = g_string_new("");
390 GList *tags = NULL, *tag; 400 GList *tags = NULL, *tag;
391 const char *c = html; 401 const char *c = html;
392 while(*c) { 402
403 while(c && *c) {
393 if(*c == '<') { 404 if(*c == '<') {
394 if(*(c+1) == '/') { /* closing tag */ 405 if(*(c+1) == '/') { /* closing tag */
395 tag = tags; 406 tag = tags;
396 while(tag) { 407 while(tag) {
397 struct gaim_parse_tag *pt = tag->data; 408 struct gaim_parse_tag *pt = tag->data;