aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xmltree.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2011-10-20 23:59:14 -0400
committerWilmer van der Gaast <wilmer@gaast.net>2011-10-20 23:59:14 -0400
commite6b41b1db86aded510fa413d3ab1c34e624c9c27 (patch)
treeb5fb06b4885eaaa5c5e4193578b15ece115e5f90 /lib/xmltree.c
parent3864c0814cc3e86a8035d27558f6d66af836a5a3 (diff)
Strip illegal characters in generated XML streams so Jabber servers won't
disconnect people who don't understand how to disable stupid IRC client features. Based very loosely on a patch and discussion submitted by Artem Savkov on bug #552.
Diffstat (limited to 'lib/xmltree.c')
-rw-r--r--lib/xmltree.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/xmltree.c b/lib/xmltree.c
index 54a7dd13..c4f34cd9 100644
--- a/lib/xmltree.c
+++ b/lib/xmltree.c
@@ -556,6 +556,28 @@ char *xt_find_attr( struct xt_node *node, const char *key )
return node->attr[i].value;
}
+/* Strip a few non-printable characters that aren't allowed in XML streams
+ (and upset some XMPP servers for example). */
+void xt_strip_text( char *in )
+{
+ char *out = in;
+ static const char nonprint[32] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0..7 */
+ 0, 1, 1, 0, 0, 1, 0, 0, /* 9 (tab), 10 (\n), 13 (\r) */
+ };
+
+ if( !in )
+ return;
+
+ while( *in )
+ {
+ if( (unsigned int) *in >= ' ' || nonprint[(unsigned int) *in] )
+ *out ++ = *in;
+ in ++;
+ }
+ *out = *in;
+}
+
struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children )
{
struct xt_node *node, *c;
@@ -567,8 +589,9 @@ struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *child
if( text )
{
- node->text_len = strlen( text );
- node->text = g_memdup( text, node->text_len + 1 );
+ node->text = g_strdup( text );
+ xt_strip_text( node->text );
+ node->text_len = strlen( node->text );
}
for( c = children; c; c = c->next )