changeset 27430:1c61906755fe

I accidentally checked this in as 4fcb9258ad826a7ff163b0f374e70b4b556ef25c
author Mark Doliner <mark@kingant.net>
date Wed, 08 Jul 2009 20:47:08 +0000
parents 74e487f82f39
children 9c413bda20be b118127843cc
files libpurple/protocols/jabber/jutil.c libpurple/server.c
diffstat 2 files changed, 13 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jutil.c	Wed Jul 08 20:44:16 2009 +0000
+++ b/libpurple/protocols/jabber/jutil.c	Wed Jul 08 20:47:08 2009 +0000
@@ -103,86 +103,20 @@
 JabberID*
 jabber_id_new(const char *str)
 {
-	const char *at = NULL;
-	const char *slash = NULL;
-	const char *c;
-	gboolean needs_validation = FALSE;
+	char *at;
+	char *slash;
 	char *node = NULL;
 	char *domain;
 	JabberID *jid;
 
-	if (!str)
-		return NULL;
-
-	for (c = str; *c != '\0'; c++) {
-		switch (*c) {
-			case '@':
-				if (!slash) {
-					if (at) {
-						/* Multiple @'s in the node/domain portion, not a valid JID! */
-						return NULL;
-					}
-					at = c;
-				}
-				break;
-
-			case '/':
-				if (!slash)
-					slash = c;
-				break;
-
-			default:
-				/* make sure this character falls within the allowed ascii characters
-				 * specified in the nodeprep RFC.  If it's outside of this range,
-				 * the character is probably unicode and will be validated using the
-				 * more expensive UTF-8 compliant nodeprep functions
-				 */
-				if ( !(	('a' <= *c && *c <= '~') ||  /*a-z{|}~*/
-						('.' <= *c && *c <= '9') ||  /*./0123456789*/
-						('A' <= *c && *c <= '_') ||  /*A-Z[\]^_*/
-						(*c == ';')  ))              /*;*/
-				{
-					needs_validation = TRUE;
-				}
-				break;
-		}
-	}
-
-	if (!needs_validation) {
-		/* JID is made of only ASCII characters--just lowercase and return */
-		jid = g_new0(JabberID, 1);
-
-		if (at) {
-			jid->node = g_ascii_strdown(str, at - str);
-			if (slash) {
-				jid->domain = g_ascii_strdown(at + 1, slash - (at + 1));
-				jid->resource = g_strdup(slash + 1);
-			} else {
-				jid->domain = g_ascii_strdown(at + 1, -1);
-			}
-		} else {
-			if (slash) {
-				jid->domain = g_ascii_strdown(str, slash - str);
-				jid->resource = g_strdup(slash + 1);
-			} else {
-				jid->domain = g_ascii_strdown(str, -1);
-			}
-		}
-		return jid;
-	}
-
-	/*
-	 * If we get here, there are some non-ASCII chars in the string, so
-	 * we'll need to validate it, normalize, and finally do a full jabber
-	 * nodeprep on the jid.
-	 */
-
-	if (!g_utf8_validate(str, -1, NULL))
+	if(!str || !g_utf8_validate(str, -1, NULL))
 		return NULL;
 
 	jid = g_new0(JabberID, 1);
 
-	/* normalization */
+	at = g_utf8_strchr(str, -1, '@');
+	slash = g_utf8_strchr(str, -1, '/');
+
 	if(at) {
 		node = g_utf8_normalize(str, at-str, G_NORMALIZE_NFKC);
 		if(slash) {
@@ -210,7 +144,6 @@
 		g_free(domain);
 	}
 
-	/* and finally the jabber nodeprep */
 	if(!jabber_nodeprep_validate(jid->node) ||
 			!jabber_nameprep_validate(jid->domain) ||
 			!jabber_resourceprep_validate(jid->resource)) {
--- a/libpurple/server.c	Wed Jul 08 20:44:16 2009 +0000
+++ b/libpurple/server.c	Wed Jul 08 20:47:08 2009 +0000
@@ -592,10 +592,13 @@
 	 */
 	flags |= PURPLE_MESSAGE_RECV;
 
-	if (!purple_privacy_check(account, who)) {
-		purple_signal_emit(purple_conversations_get_handle(), "blocked-im-msg",
-				account, who, msg, flags, (unsigned int)mtime);
-		return;
+	if (PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc))->set_permit_deny == NULL) {
+		/* protocol does not support privacy, handle it ourselves */
+		if (!purple_privacy_check(account, who)) {
+			purple_signal_emit(purple_conversations_get_handle(), "blocked-im-msg",
+					account, who, msg, flags, (unsigned int)mtime);
+			return;
+		}
 	}
 
 	/*