aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2015-01-16 16:50:24 -0300
committerdequis <dx@dxzone.com.ar>2015-01-16 16:50:24 -0300
commit4cff28fdfca2eaf71a13715b0fda114796091065 (patch)
treeff36c6a03e7c609f1c33a6e88f4ad9feb1eee37d
parent840394e847eb4f72443facf8b923741698c3e9a6 (diff)
Add jabber_normalize_ext() to fix case sensitivity issues with ext jids
Also refactor jabber_normalize() to be UTF8 aware. See trac ticket 1106 for more details
-rw-r--r--protocols/jabber/jabber_util.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c
index 9d8011f8..d6396802 100644
--- a/protocols/jabber/jabber_util.c
+++ b/protocols/jabber/jabber_util.c
@@ -329,23 +329,37 @@ int jabber_compare_jid( const char *jid1, const char *jid2 )
return TRUE;
}
-/* Returns a new string. Don't leak it! */
+/* The /resource part is case sensitive. This stops once we see a slash.
+ Returns a new string. Don't leak it! */
char *jabber_normalize( const char *orig )
{
- int len, i;
- char *new;
-
- len = strlen( orig );
- new = g_new( char, len + 1 );
-
- /* So it turns out the /resource part is case sensitive. Yeah, and
- it's Unicode but feck Unicode. :-P So stop once we see a slash. */
- for( i = 0; i < len && orig[i] != '/' ; i ++ )
- new[i] = g_ascii_tolower( orig[i] );
- for( ; orig[i]; i ++ )
- new[i] = orig[i];
-
- new[i] = 0;
+ char *lower, *new, *s;
+
+ if ( ! ( s = strchr( orig, '/' ) ) )
+ return g_utf8_strdown( orig, -1 );
+
+ lower = g_utf8_strdown( orig, (s - orig) ); /* stop in s */
+ new = g_strconcat( lower, s, NULL );
+ g_free( lower );
+ return new;
+}
+
+/* Similar to jabber_normalize, but works with addresses in the form
+ * resource=chatroom@example.com */
+char *jabber_normalize_ext( const char *orig )
+{
+ char *lower, *new, *s;
+
+ if ( ! ( s = strchr( orig, '=' ) ) )
+ return g_utf8_strdown( orig, -1 );
+
+ lower = g_utf8_strdown( s, -1 ); /* start in s */
+
+ *s = 0;
+ new = g_strconcat( orig, lower, NULL );
+ *s = '=';
+
+ g_free( lower );
return new;
}
@@ -555,7 +569,7 @@ struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *ji
struct jabber_buddy *bud;
char *s, *jid;
- jid = jabber_normalize( jid_ );
+ jid = jabber_normalize_ext( jid_ );
if( ( s = strchr( jid, '=' ) ) == NULL )
return NULL;