pidgin: 3b27bba7: Change jabber_id_new() to iterate byte b...

markdoliner at pidgin.im markdoliner at pidgin.im
Fri Jul 10 14:45:37 EDT 2009


-----------------------------------------------------------------
Revision: 3b27bba79b515334a330931ff490d75e2d3787de
Ancestor: 3f9611885d2286d341ad36a8b0fe8386fc14277b
Author: markdoliner at pidgin.im
Date: 2009-07-10T18:41:56
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3b27bba79b515334a330931ff490d75e2d3787de

Modified files:
        libpurple/protocols/jabber/jutil.c

ChangeLog: 

Change jabber_id_new() to iterate byte by byte instead of character
by character.  This should be safe because the 2nd, 3rd and 4th
bytes of a multibyte utf8 character cannot also be a valid character
in the ASCII alphabet... right?

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jutil.c	4ce516a30bb6a637824dcd737e064448f0edec3f
+++ libpurple/protocols/jabber/jutil.c	d3951d9c48dff5b5c819caba96f63b90f719809a
@@ -105,8 +105,7 @@ jabber_id_new(const char *str)
 {
 	const char *at = NULL;
 	const char *slash = NULL;
-	const char *cur;
-	gunichar c;
+	const char *c;
 	gboolean needs_validation = FALSE;
 #if 0
 	gboolean node_is_required = FALSE;
@@ -118,48 +117,47 @@ jabber_id_new(const char *str)
 	if (!str)
 		return NULL;
 
-	for (cur = str; *cur != '\0'; cur = g_utf8_next_char(cur))
+	for (c = str; *c != '\0'; c++)
 	{
-		c = g_utf8_get_char(cur);
-		switch (c) {
+		switch (*c) {
 			case '@':
 				if (!slash) {
 					if (at) {
 						/* Multiple @'s in the node/domain portion, not a valid JID! */
 						return NULL;
 					}
-					if (cur == str) {
+					if (c == str) {
 						/* JIDs cannot start with @ */
 						return NULL;
 					}
-					if ((g_utf8_next_char(cur))[0] == '\0') {
+					if (c[1] == '\0') {
 						/* JIDs cannot end with @ */
 						return NULL;
 					}
-					at = cur;
+					at = c;
 				}
 				break;
 
 			case '/':
 				if (!slash) {
-					if (cur == str) {
+					if (c == str) {
 						/* JIDs cannot start with / */
 						return NULL;
 					}
-					if ((g_utf8_next_char(cur))[0] == '\0') {
+					if (c[1] == '\0') {
 						/* JIDs cannot end with / */
 						return NULL;
 					}
-					slash = cur;
+					slash = c;
 				}
 				break;
 
 			default:
 				/* characters allowed everywhere */
-				if ((c > 'a' && c < 'z')
-						|| (c > '0' && c < '9')
-						|| (c > 'A' && c < 'Z')
-						|| c == '.' || c == '-')
+				if ((*c > 'a' && *c < 'z')
+						|| (*c > '0' && *c < '9')
+						|| (*c > 'A' && *c < 'Z')
+						|| *c == '.' || *c == '-')
 					/* We're good */
 					break;
 


More information about the Commits mailing list