diff libpurple/protocols/bonjour/mdns_common.c @ 31018:9c8b28dc6656

The hostname used for a bonjour account should always be the current machine name. This fixes our behavior so the previous statement is always the case. Unfortunately, this means that if the hostname was previously not the current machine name, the bonjour jid ends up looking like "username\40otherhost@hostname". Fixes #12674
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 04 Oct 2010 00:48:25 +0000
parents 9340e1db0f46
children ab8d9cea5a30
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/mdns_common.c	Mon Oct 04 00:35:26 2010 +0000
+++ b/libpurple/protocols/bonjour/mdns_common.c	Mon Oct 04 00:48:25 2010 +0000
@@ -252,3 +252,36 @@
 void bonjour_dns_sd_stop(BonjourDnsSd *data) {
 	_mdns_stop(data);
 }
+
+void
+bonjour_dns_sd_set_jid(PurpleAccount *account, const char *hostname)
+{
+	PurpleConnection *conn = purple_account_get_connection(account);
+	BonjourData *bd = conn->proto_data;
+	const char *tmp, *account_name = purple_account_get_username(account);
+
+	/* Previously we allowed the hostname part of the jid to be set
+	 * explicitly when it should always be the current hostname.
+	 * That is what this is intended to deal with.
+	 */
+	if ((tmp = strchr(account_name, '@'))
+	    && strstr(account_name, hostname) == ++tmp
+	    && *(tmp + strlen(hostname)) == '\0')
+		bd->jid = g_strdup(account_name);
+	else {
+		const char *tmp2;
+		GString *str = g_string_new("");
+		/* Escape an '@' in the account name */
+		tmp = account_name;
+		while ((tmp2 = strchr(tmp, '@')) != NULL) {
+			g_string_append_len(str, tmp, tmp2 - tmp);
+			g_string_append(str, "\\40");
+			tmp = tmp2 + 1;
+		}
+		g_string_append(str, tmp);
+		g_string_append_c(str, '@');
+		g_string_append(str, hostname);
+
+		bd->jid = g_string_free(str, FALSE);
+	}
+}
\ No newline at end of file