pidgin: 4fcb9258: Use the ui_info hash table instead of pr...

markdoliner at pidgin.im markdoliner at pidgin.im
Wed Jul 8 16:15:39 EDT 2009


-----------------------------------------------------------------
Revision: 4fcb9258ad826a7ff163b0f374e70b4b556ef25c
Ancestor: a6fa365dead8e84c4173c08c7450e8edaf1adcd3
Author: markdoliner at pidgin.im
Date: 2009-07-08T20:11:07
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/4fcb9258ad826a7ff163b0f374e70b4b556ef25c

Modified files:
        libpurple/protocols/jabber/jutil.c
        libpurple/protocols/oscar/family_auth.c
        libpurple/protocols/oscar/flap_connection.c
        libpurple/protocols/oscar/oscar.c
        libpurple/protocols/oscar/oscar.h
        libpurple/protocols/oscar/util.c libpurple/server.c

ChangeLog: 

Use the ui_info hash table instead of prefs when passing the clientstring
and distid from the UIs to the oscar prpl.  I realized that using a pref
wasn't great because it's persistent, and if you switch from a UI that
sets one of those strings to a UI that doesn't hen we'll keep using the
old value.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jutil.c	912799b76983833354a4420afc830bbb9b370f21
+++ libpurple/protocols/jabber/jutil.c	2bfbca92715a1c75c94ed703a7ff01499a4a7789
@@ -103,20 +103,86 @@ jabber_id_new(const char *str)
 JabberID*
 jabber_id_new(const char *str)
 {
-	char *at;
-	char *slash;
+	const char *at = NULL;
+	const char *slash = NULL;
+	const char *c;
+	gboolean needs_validation = FALSE;
 	char *node = NULL;
 	char *domain;
 	JabberID *jid;
 
-	if(!str || !g_utf8_validate(str, -1, NULL))
+	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))
+		return NULL;
+
 	jid = g_new0(JabberID, 1);
 
-	at = g_utf8_strchr(str, -1, '@');
-	slash = g_utf8_strchr(str, -1, '/');
-
+	/* normalization */
 	if(at) {
 		node = g_utf8_normalize(str, at-str, G_NORMALIZE_NFKC);
 		if(slash) {
@@ -144,6 +210,7 @@ jabber_id_new(const char *str)
 		g_free(domain);
 	}
 
+	/* and finally the jabber nodeprep */
 	if(!jabber_nodeprep_validate(jid->node) ||
 			!jabber_nameprep_validate(jid->domain) ||
 			!jabber_resourceprep_validate(jid->resource)) {
============================================================
--- libpurple/protocols/oscar/family_auth.c	049df0b27de66dc4b6971c9e06bd159abfed5609
+++ libpurple/protocols/oscar/family_auth.c	4e1ea4a17d86e68b9fd0ec40b6e935a852e7c934
@@ -141,12 +141,12 @@ goddamnicq2(OscarData *od, FlapConnectio
 
 	aim_encode_password(password, password_encoded);
 
-	clientstring = purple_prefs_get_string("/plugins/prpl/oscar/clientstring");
-	if (clientstring == NULL)
-		clientstring = ci->clientstring;
-	distrib = purple_prefs_get_int("/plugins/prpl/oscar/distid");
-	if ((gint32)distrib == -1)
-		distrib = ci->distrib;
+	clientstring = oscar_get_ui_info_string(
+			od->icq ? "prpl-icq-clientstring" : "prpl-aim-clientstring",
+			ci->clientstring);
+	distrib = oscar_get_ui_info_int(
+			od->icq ? "prpl-icq-distid" : "prpl-aim-distid",
+			ci->distrib);
 
 	byte_stream_put32(&frame->data, 0x00000001); /* FLAP Version */
 	aim_tlvlist_add_str(&tlvlist, 0x0001, sn);
@@ -247,12 +247,12 @@ aim_send_login(OscarData *od, FlapConnec
 
 	aim_encode_password_md5(password, password_len, key, digest);
 
-	clientstring = purple_prefs_get_string("/plugins/prpl/oscar/clientstring");
-	if (clientstring == NULL)
-		clientstring = ci->clientstring;
-	distrib = purple_prefs_get_int("/plugins/prpl/oscar/distid");
-	if ((gint32)distrib == -1)
-		distrib = ci->distrib;
+	clientstring = oscar_get_ui_info_string(
+			od->icq ? "prpl-icq-clientstring" : "prpl-aim-clientstring",
+			ci->clientstring);
+	distrib = oscar_get_ui_info_int(
+			od->icq ? "prpl-icq-distid" : "prpl-aim-distid",
+			ci->distrib);
 
 	aim_tlvlist_add_raw(&tlvlist, 0x0025, 16, digest);
 
============================================================
--- libpurple/protocols/oscar/flap_connection.c	318e6616a1f7ef23b5764674a6dd94954035e8ca
+++ libpurple/protocols/oscar/flap_connection.c	6956076133bd4cd188d52b77c5100ca74b548ddf
@@ -77,14 +77,19 @@ flap_connection_send_version_with_cookie
 {
 	FlapFrame *frame;
 	GSList *tlvlist = NULL;
+	const char *clientstring;
 
 	frame = flap_frame_new(od, 0x01, 1152 + length);
 
 	byte_stream_put32(&frame->data, 0x00000001); /* FLAP Version */
 	aim_tlvlist_add_raw(&tlvlist, 0x0006, length, chipsahoy);
 
-	if (ci->clientstring)
-		aim_tlvlist_add_str(&tlvlist, 0x0003, ci->clientstring);
+	clientstring = oscar_get_ui_info_string(
+			od->icq ? "prpl-icq-clientstring" : "prpl-aim-clientstring",
+			ci->clientstring);
+
+	if (clientstring != NULL)
+		aim_tlvlist_add_str(&tlvlist, 0x0003, clientstring);
 	aim_tlvlist_add_16(&tlvlist, 0x0017, (guint16)ci->major);
 	aim_tlvlist_add_16(&tlvlist, 0x0018, (guint16)ci->minor);
 	aim_tlvlist_add_16(&tlvlist, 0x0019, (guint16)ci->point);
============================================================
--- libpurple/protocols/oscar/oscar.c	cef8df6975a84f3ca838dde404b4ca047900a374
+++ libpurple/protocols/oscar/oscar.c	d159f2ff3548e56990252f1a86a3a7ead79d3b62
@@ -7102,18 +7102,6 @@ void oscar_init(PurplePluginProtocolInfo
 	purple_prefs_add_none("/plugins/prpl/oscar");
 	purple_prefs_add_bool("/plugins/prpl/oscar/recent_buddies", FALSE);
 
-	/*
-	 * These two preferences will normally not be changed.  UIs can optionally
-	 * use them to override these two version fields which are sent to the
-	 * server when logging in.  AOL requested this change to allow clients to
-	 * use custom values.
-	 *
-	 * TODO: It would be more appropriate for UIs to put these in the hash
-	 * table returned by purple_core_get_ui_info().
-	 */
-	purple_prefs_add_string("/plugins/prpl/oscar/clientstring", NULL);
-	purple_prefs_add_int("/plugins/prpl/oscar/distid", -1);
-
 	purple_prefs_remove("/plugins/prpl/oscar/show_idle");
 	purple_prefs_remove("/plugins/prpl/oscar/always_use_rv_proxy");
 
============================================================
--- libpurple/protocols/oscar/oscar.h	5a3e5c12cb9f4107cf5ded533b78fc6e77b662f9
+++ libpurple/protocols/oscar/oscar.h	20e5cdd3ae57ee664624ab3dfc458c812b07c451
@@ -1527,6 +1527,7 @@ void aim_tlvlist_remove(GSList **list, c
 		(((*((buf)+2)) << 16) & 0x00ff0000) + \
 		(((*((buf)+3)) << 24) & 0xff000000))
 
+int oscar_get_ui_info_int(const char *str, int default_value);
 const char *oscar_get_ui_info_string(const char *str, const char *default_value);
 
 guint16 aimutil_iconsum(const guint8 *buf, int buflen);
============================================================
--- libpurple/protocols/oscar/util.c	b1392178e8bd4b440d80a44a91f17a0f3acd0e0b
+++ libpurple/protocols/oscar/util.c	0a84360371e188b68854794730c144b73066a070
@@ -35,6 +35,20 @@
 #include "win32dep.h"
 #endif
 
+int oscar_get_ui_info_int(const char *str, int default_value)
+{
+	GHashTable *ui_info;
+
+	ui_info = purple_core_get_ui_info();
+	if (ui_info != NULL) {
+		gpointer value;
+		if (g_hash_table_lookup_extended(ui_info, str, NULL, value))
+			return GPOINTER_TO_INT(value);
+	}
+
+	return default_value;
+}
+
 const char *oscar_get_ui_info_string(const char *str, const char *default_value)
 {
 	GHashTable *ui_info;
============================================================
--- libpurple/server.c	8730c7801e191207259746e59cbe9f4618e20f6b
+++ libpurple/server.c	2575dbcc3ca722651a05796798edc8923025168a
@@ -592,13 +592,10 @@ void serv_got_im(PurpleConnection *gc, c
 	 */
 	flags |= PURPLE_MESSAGE_RECV;
 
-	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;
-		}
+	if (!purple_privacy_check(account, who)) {
+		purple_signal_emit(purple_conversations_get_handle(), "blocked-im-msg",
+				account, who, msg, flags, (unsigned int)mtime);
+		return;
 	}
 
 	/*


More information about the Commits mailing list