Changeset e6b41b1


Ignore:
Timestamp:
2011-10-21T03:59:14Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
de26f3c
Parents:
3864c08
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/xmltree.c

    r3864c08 re6b41b1  
    557557}
    558558
     559/* Strip a few non-printable characters that aren't allowed in XML streams
     560   (and upset some XMPP servers for example). */
     561void xt_strip_text( char *in )
     562{
     563        char *out = in;
     564        static const char nonprint[32] = {
     565                0, 0, 0, 0, 0, 0, 0, 0, /* 0..7 */
     566                0, 1, 1, 0, 0, 1, 0, 0, /* 9 (tab), 10 (\n), 13 (\r) */
     567        };
     568       
     569        if( !in )
     570                return;
     571
     572        while( *in )
     573        {
     574                if( (unsigned int) *in >= ' ' || nonprint[(unsigned int) *in] )
     575                        *out ++ = *in;
     576                in ++;
     577        }
     578        *out = *in;
     579}
     580
    559581struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children )
    560582{
     
    568590        if( text )
    569591        {
    570                 node->text_len = strlen( text );
    571                 node->text = g_memdup( text, node->text_len + 1 );
     592                node->text = g_strdup( text );
     593                xt_strip_text( node->text );
     594                node->text_len = strlen( node->text );
    572595        }
    573596       
Note: See TracChangeset for help on using the changeset viewer.