diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-08-25 14:34:36 +0200 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-08-25 14:34:36 +0200 |
commit | 54794b8e01b5cce0675e9cfbd7282d011ebcb99e (patch) | |
tree | 9303652695925852ee897b54c90c59e0ca24fc78 | |
parent | a36b030d747a39fed8224e6350d56d55b2aec4e2 (diff) |
Added msn_http_encode() so it can be used in msn_buddy_list_add() too.
Most likely fixes #198.
-rw-r--r-- | protocols/msn/msn.c | 20 | ||||
-rw-r--r-- | protocols/msn/msn.h | 1 | ||||
-rw-r--r-- | protocols/msn/msn_util.c | 30 |
3 files changed, 30 insertions, 21 deletions
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index a8d85a66..0d2d7283 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -211,8 +211,7 @@ static void msn_set_away( struct gaim_connection *gc, char *state, char *message static void msn_set_info( struct gaim_connection *gc, char *info ) { - int i; - char buf[1024], *fn, *s; + char buf[1024], *fn; struct msn_data *md = gc->proto_data; if( strlen( info ) > 129 ) @@ -221,22 +220,7 @@ static void msn_set_info( struct gaim_connection *gc, char *info ) return; } - /* Of course we could use http_encode() here, but when we encode - every character, the server is less likely to complain about the - chosen name. However, the MSN server doesn't seem to like escaped - non-ASCII chars, so we keep those unescaped. */ - s = fn = g_new0( char, strlen( info ) * 3 + 1 ); - for( i = 0; info[i]; i ++ ) - if( info[i] & 128 ) - { - *s = info[i]; - s ++; - } - else - { - g_snprintf( s, 4, "%%%02X", info[i] ); - s += 3; - } + fn = msn_http_encode( info ); g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn ); msn_write( gc, buf, strlen( buf ) ); diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index dbbb6aa0..b4777d41 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -156,6 +156,7 @@ void msn_buddy_ask( struct gaim_connection *gc, char *handle, char *realname ); char *msn_findheader( char *text, char *header, int len ); char **msn_linesplit( char *line ); int msn_handler( struct msn_handler_data *h ); +char *msn_http_encode( const char *input ); /* tables.c */ const struct msn_away_state *msn_away_state_by_number( int number ); diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 4e748099..ff4c148c 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -55,9 +55,7 @@ int msn_buddy_list_add( struct gaim_connection *gc, char *list, char *who, char struct msn_data *md = gc->proto_data; char buf[1024], *realname; - realname = g_new0( char, strlen( realname_ ) * 3 + 1 ); - strcpy( realname, realname_ ); - http_encode( realname ); + realname = msn_http_encode( realname_ ); g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s\r\n", ++md->trId, list, who, realname ); if( msn_write( gc, buf, strlen( buf ) ) ) @@ -314,3 +312,29 @@ int msn_handler( struct msn_handler_data *h ) return( 1 ); } + +/* The difference between this function and the normal http_encode() function + is that this one escapes every 7-bit ASCII character because this is said + to avoid some lame server-side checks when setting a real-name. Also, + non-ASCII characters are not escaped because MSN servers don't seem to + appreciate that! */ +char *msn_http_encode( const char *input ) +{ + char *ret, *s; + int i; + + ret = s = g_new0( char, strlen( input ) * 3 + 1 ); + for( i = 0; input[i]; i ++ ) + if( input[i] & 128 ) + { + *s = input[i]; + s ++; + } + else + { + g_snprintf( s, 4, "%%%02X", input[i] ); + s += 3; + } + + return ret; +} |