changeset 27472:f1f901b3d6f2

Save one traversal of the domain for IPv6 validation.
author Paul Aurich <paul@darkrain42.org>
date Sat, 11 Jul 2009 07:55:03 +0000
parents ef48fb87d8d2
children 1d30e9d6de9b
files libpurple/protocols/jabber/jutil.c
diffstat 1 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jutil.c	Sat Jul 11 07:47:45 2009 +0000
+++ b/libpurple/protocols/jabber/jutil.c	Sat Jul 11 07:55:03 2009 +0000
@@ -57,27 +57,28 @@
 gboolean jabber_domain_validate(const char *str)
 {
 	const char *c;
+	size_t len;
 
 	if(!str)
 		return TRUE;
 
-	if(strlen(str) > 1023)
+	len = strlen(str);
+	if (len > 1023)
 		return FALSE;
 
 	c = str;
 
 	if (*c == '[') {
 		/* Check if str is a valid IPv6 identifier */
-		const gchar *end_bracket = strstr(c, "]");
 		gboolean valid = FALSE;
 
-		if (!end_bracket || *(end_bracket + 1) != '\0')
+		if (*(c + len - 1) != ']')
 			return FALSE;
 
 		/* Ugly, but in-place */
-		*(gchar *)end_bracket = '\0';
+		*(gchar *)(c + len - 1) = '\0';
 		valid = purple_ipv6_address_is_valid(c + 1);
-		*(gchar *)end_bracket = ']';
+		*(gchar *)(c + len - 1) = ']';
 
 		return valid;
 	}