libpurple/protocols/gg/html.c

Tue, 04 Feb 2014 14:30:03 +0530

author
Ankit Vani <a@nevitus.org>
date
Tue, 04 Feb 2014 14:30:03 +0530
branch
soc.2013.gobjectification.plugins
changeset 37065
3546d731987e
parent 35360
29d788c72350
child 40358
e6fe6fc1f516
permissions
-rw-r--r--

Merge gtkdoc-conversion

35358
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
1 /* purple
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
2 *
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
5 * source distribution.
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
6 *
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
7 * Component written by Tomek Wasilczyk (http://www.wasilczyk.pl).
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
8 *
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
9 * This file is dual-licensed under the GPL2+ and the X11 (MIT) licences.
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
10 * As a recipient of this file you may choose, which license to receive the
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
11 * code under. As a contributor, you have to ensure the new code is
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
12 * compatible with both.
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
13 *
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
14 * This program is free software; you can redistribute it and/or modify
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
15 * it under the terms of the GNU General Public License as published by
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
16 * the Free Software Foundation; either version 2 of the License, or
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
17 * (at your option) any later version.
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
18 *
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
19 * This program is distributed in the hope that it will be useful,
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
22 * GNU General Public License for more details.
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
23 *
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
24 * You should have received a copy of the GNU General Public License
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
25 * along with this program; if not, write to the Free Software
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
7beae478c905 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34413
diff changeset
27 */
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
28 #include "html.h"
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
29
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
30 #include <debug.h>
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
34359
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
32 typedef struct
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
33 {
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
34 GRegex *re_html_attr;
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
35 GRegex *re_css_attr;
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
36 GRegex *re_color_hex;
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
37 GRegex *re_color_rgb;
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
38 } ggp_html_global_data;
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
39
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
40 static ggp_html_global_data global_data;
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
41
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
42 void ggp_html_setup(void)
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
43 {
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
44 global_data.re_html_attr = g_regex_new(
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
45 "([a-z-]+)=\"([^\"]+)\"",
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
46 G_REGEX_OPTIMIZE, 0, NULL);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
47 global_data.re_css_attr = g_regex_new(
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
48 "([a-z-]+): *([^;]+)",
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
49 G_REGEX_OPTIMIZE, 0, NULL);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
50 global_data.re_color_hex = g_regex_new(
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
51 "^#([0-9a-fA-F]+){6}$",
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
52 G_REGEX_OPTIMIZE, 0, NULL);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
53 global_data.re_color_rgb = g_regex_new(
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
54 "^rgb\\(([0-9]+), *([0-9]+), *([0-9]+)\\)$",
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
55 G_REGEX_OPTIMIZE, 0, NULL);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
56 }
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
57
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
58 void ggp_html_cleanup(void)
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
59 {
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
60 g_regex_unref(global_data.re_html_attr);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
61 g_regex_unref(global_data.re_css_attr);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
62 g_regex_unref(global_data.re_color_hex);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
63 g_regex_unref(global_data.re_color_rgb);
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
64 }
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
65
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
66 GHashTable * ggp_html_tag_attribs(const gchar *attribs_str)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67 {
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
68 GMatchInfo *match;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
69 GHashTable *attribs = g_hash_table_new_full(g_str_hash, g_str_equal,
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
70 g_free, g_free);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
71
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
72 if (attribs_str == NULL)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
73 return attribs;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
74
34359
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
75 g_regex_match(global_data.re_html_attr, attribs_str, 0, &match);
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35358
diff changeset
76 while (g_match_info_matches(match)) {
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
77 g_hash_table_insert(attribs,
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
78 g_match_info_fetch(match, 1),
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
79 g_match_info_fetch(match, 2));
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
81 g_match_info_next(match, NULL);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
82 }
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
83 g_match_info_free(match);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
84
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
85 return attribs;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
86 }
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
87
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
88 GHashTable * ggp_html_css_attribs(const gchar *attribs_str)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
89 {
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
90 GMatchInfo *match;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
91 GHashTable *attribs = g_hash_table_new_full(g_str_hash, g_str_equal,
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
92 g_free, g_free);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
93
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
94 if (attribs_str == NULL)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
95 return attribs;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
96
34359
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
97 g_regex_match(global_data.re_css_attr, attribs_str, 0, &match);
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35358
diff changeset
98 while (g_match_info_matches(match)) {
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
99 g_hash_table_insert(attribs,
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
100 g_match_info_fetch(match, 1),
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
101 g_match_info_fetch(match, 2));
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
102
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
103 g_match_info_next(match, NULL);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
104 }
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
105 g_match_info_free(match);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
106
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
107 return attribs;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
108 }
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
109
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
110 int ggp_html_decode_color(const gchar *str)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
111 {
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
112 GMatchInfo *match;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
113 int color = -1;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
114
34359
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
115 g_regex_match(global_data.re_color_hex, str, 0, &match);
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35358
diff changeset
116 if (g_match_info_matches(match)) {
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
117 if (sscanf(str + 1, "%x", &color) != 1)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
118 color = -1;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
119 }
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
120 g_match_info_free(match);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
121 if (color >= 0)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
122 return color;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
123
34359
7cf367cc1141 Gadu-Gadu: compile regular expressions only once per plugin load
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34358
diff changeset
124 g_regex_match(global_data.re_color_rgb, str, 0, &match);
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35358
diff changeset
125 if (g_match_info_matches(match)) {
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
126 int r = -1, g = -1, b = -1;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
127 gchar *c_str;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
128
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
129 c_str = g_match_info_fetch(match, 1);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
130 if (c_str)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
131 r = atoi(c_str);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
132 g_free(c_str);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
133
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
134 c_str = g_match_info_fetch(match, 2);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
135 if (c_str)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
136 g = atoi(c_str);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
137 g_free(c_str);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
138
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
139 c_str = g_match_info_fetch(match, 3);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
140 if (c_str)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
141 b = atoi(c_str);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
142 g_free(c_str);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
143
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
144 if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
145 color = (r << 16) | (g << 8) | b;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
146 }
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
147 g_match_info_free(match);
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
148 if (color >= 0)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
149 return color;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
150
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
151 return -1;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
152 }
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
153
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
154 ggp_html_tag ggp_html_parse_tag(const gchar *tag_str)
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
155 {
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
156 if (0 == g_ascii_strcasecmp(tag_str, "eom"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
157 return GGP_HTML_TAG_EOM;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
158 if (0 == g_ascii_strcasecmp(tag_str, "span"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
159 return GGP_HTML_TAG_SPAN;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
160 if (0 == g_ascii_strcasecmp(tag_str, "div"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
161 return GGP_HTML_TAG_DIV;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
162 if (0 == g_ascii_strcasecmp(tag_str, "br"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
163 return GGP_HTML_TAG_BR;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
164 if (0 == g_ascii_strcasecmp(tag_str, "a"))
34360
c6bd55f526f9 Gadu-Gadu: code polishing for messages
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34359
diff changeset
165 return GGP_HTML_TAG_A;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
166 if (0 == g_ascii_strcasecmp(tag_str, "b"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
167 return GGP_HTML_TAG_B;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
168 if (0 == g_ascii_strcasecmp(tag_str, "i"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
169 return GGP_HTML_TAG_I;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
170 if (0 == g_ascii_strcasecmp(tag_str, "u"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
171 return GGP_HTML_TAG_U;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
172 if (0 == g_ascii_strcasecmp(tag_str, "s"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
173 return GGP_HTML_TAG_S;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
174 if (0 == g_ascii_strcasecmp(tag_str, "img"))
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34360
diff changeset
175 return GGP_HTML_TAG_IMG;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
176 if (0 == g_ascii_strcasecmp(tag_str, "font"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
177 return GGP_HTML_TAG_FONT;
34413
a578366cd35e Gadu-Gadu: fix sending links
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
178 if (0 == g_ascii_strcasecmp(tag_str, "hr"))
34358
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
179 return GGP_HTML_TAG_HR;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
180 return GGP_HTML_TAG_UNKNOWN;
845e66c9a20d Gadu-Gadu: sent messages reformatting, as in GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
181 }

mercurial