comparison libpurple/xmlnode.c @ 30957:3cf95447b26c

disapproval of revision '3ac008cdb1707c831737d497562a2751cdff861c'
author Mark Doliner <mark@kingant.net>
date Mon, 22 Nov 2010 10:49:06 +0000
parents 61d160a4689f
children
comparison
equal deleted inserted replaced
30956:61d160a4689f 30957:3cf95447b26c
44 # define NEWLINE_S "\r\n" 44 # define NEWLINE_S "\r\n"
45 #else 45 #else
46 # define NEWLINE_S "\n" 46 # define NEWLINE_S "\n"
47 #endif 47 #endif
48 48
49 #ifdef CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS
50 /*
51 * The purpose of this function is to prevent us from creating XML documents
52 * that contain characters that are not allowed in XML 1.0. However, this
53 * change is unfortunately REALLY slow.
54 */
55 static gboolean is_valid_xml10(const char *str)
56 {
57 gunichar ch;
58
59 for (ch = g_utf8_get_char(str); str[0] != '\0'; str = g_utf8_next_char(str))
60 {
61 /*
62 * Valid characters in XML 1.0 are: #x9 #xA #xD
63 * [#x20-#xD7FF] [#xE000-#xFFFD] [#x10000-#x10FFFF]
64 */
65 if (ch < 0x09 || (ch > 0x0a && ch < 0x0d) || (ch > 0x0d && ch < 0x20))
66 return FALSE;
67 }
68
69 return TRUE;
70 }
71 #endif /* CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS */
72
73 static xmlnode* 49 static xmlnode*
74 new_node(const char *name, XMLNodeType type) 50 new_node(const char *name, XMLNodeType type)
75 { 51 {
76 xmlnode *node = g_new0(xmlnode, 1); 52 xmlnode *node = g_new0(xmlnode, 1);
77 53
130 gsize real_size; 106 gsize real_size;
131 107
132 g_return_if_fail(node != NULL); 108 g_return_if_fail(node != NULL);
133 g_return_if_fail(data != NULL); 109 g_return_if_fail(data != NULL);
134 g_return_if_fail(size != 0); 110 g_return_if_fail(size != 0);
135
136 #ifdef CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS
137 g_return_if_fail(is_valid_xml10(data));
138 #endif /* CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS */
139 111
140 real_size = size == -1 ? strlen(data) : size; 112 real_size = size == -1 ? strlen(data) : size;
141 113
142 child = new_node(NULL, XMLNODE_TYPE_DATA); 114 child = new_node(NULL, XMLNODE_TYPE_DATA);
143 115
212 } 184 }
213 185
214 void 186 void
215 xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value) 187 xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value)
216 { 188 {
217 #ifdef CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS
218 g_return_if_fail(is_valid_xml10(attr));
219 g_return_if_fail(is_valid_xml10(value));
220 #endif /* CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS */
221
222 xmlnode_remove_attrib(node, attr); 189 xmlnode_remove_attrib(node, attr);
223 xmlnode_set_attrib_full(node, attr, NULL, NULL, value); 190 xmlnode_set_attrib_full(node, attr, NULL, NULL, value);
224 } 191 }
225 192
226 void 193 void
241 xmlnode *attrib_node; 208 xmlnode *attrib_node;
242 209
243 g_return_if_fail(node != NULL); 210 g_return_if_fail(node != NULL);
244 g_return_if_fail(attr != NULL); 211 g_return_if_fail(attr != NULL);
245 g_return_if_fail(value != NULL); 212 g_return_if_fail(value != NULL);
246 #ifdef CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS
247 g_return_if_fail(is_valid_xml10(attr));
248 if (xmlns != NULL)
249 g_return_if_fail(is_valid_xml10(xmlns));
250 if (prefix != NULL)
251 g_return_if_fail(is_valid_xml10(prefix));
252 g_return_if_fail(is_valid_xml10(value));
253 #endif /* CHECKING_XML_STRINGS_FOR_VALID_CHARACTERS */
254 213
255 xmlnode_remove_attrib_with_namespace(node, attr, xmlns); 214 xmlnode_remove_attrib_with_namespace(node, attr, xmlns);
256 attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); 215 attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB);
257 216
258 attrib_node->data = g_strdup(value); 217 attrib_node->data = g_strdup(value);