changeset 17503:ba71c53186e9

merge of '80f65d9d59e0da8c62c56e2afe1f41f1059c8215' and 'a894b0b73a06efd4e7f99fd6f068288bb5267a47'
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 05 Jun 2007 22:13:23 +0000
parents f0784efe2791 (current diff) c96b085ddf5c (diff)
children c921f901c7ea
files
diffstat 5 files changed, 98 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/bonjour.c	Tue Jun 05 21:46:27 2007 +0000
+++ b/libpurple/protocols/bonjour/bonjour.c	Tue Jun 05 22:13:23 2007 +0000
@@ -120,17 +120,11 @@
 
 	/* Connect to the mDNS daemon looking for buddies in the LAN */
 	bd->dns_sd_data = bonjour_dns_sd_new();
-	bd->dns_sd_data->name = purple_account_get_username(account);
-	bd->dns_sd_data->txtvers = g_strdup("1");
-	bd->dns_sd_data->version = g_strdup("1");
 	bd->dns_sd_data->first = g_strdup(purple_account_get_string(account, "first", default_firstname));
 	bd->dns_sd_data->last = g_strdup(purple_account_get_string(account, "last", default_lastname));
 	bd->dns_sd_data->port_p2pj = bd->jabber_data->port;
-	bd->dns_sd_data->phsh = g_strdup("");
-	bd->dns_sd_data->email = g_strdup(purple_account_get_string(account, "email", ""));
-	bd->dns_sd_data->vc = g_strdup("");
-	bd->dns_sd_data->jid = g_strdup(purple_account_get_string(account, "jid", ""));
-	bd->dns_sd_data->AIM = g_strdup(purple_account_get_string(account, "AIM", ""));
+	/* Not engaged in AV conference */
+	bd->dns_sd_data->vc = g_strdup("!");
 
 	status = purple_account_get_active_status(account);
 	presence = purple_account_get_presence(account);
--- a/libpurple/protocols/bonjour/mdns_common.c	Tue Jun 05 21:46:27 2007 +0000
+++ b/libpurple/protocols/bonjour/mdns_common.c	Tue Jun 05 22:13:23 2007 +0000
@@ -42,7 +42,10 @@
 {
 	g_free(data->first);
 	g_free(data->last);
-	g_free(data->email);
+	g_free(data->phsh);
+	g_free(data->status);
+	g_free(data->vc);
+	g_free(data->msg);
 	g_free(data);
 }
 
@@ -82,8 +85,7 @@
 	gc = purple_account_get_connection(account);
 
 	/* Initialize the dns-sd data and session */
-	
-#ifndef USE_BONJOUR_APPLE 
+#ifndef USE_BONJOUR_APPLE
 	if (sw_discovery_init(&data->session) != SW_OKAY)
 	{
 		purple_debug_error("bonjour", "Unable to initialize an mDNS session.\n");
@@ -105,7 +107,6 @@
 	/* Advise the daemon that we are waiting for connections */
 	
 #ifdef USE_BONJOUR_APPLE
-	printf("account pointer here is %x\n,", account);
 	if (DNSServiceBrowse(&data->browser, 0, 0, ICHAT_SERVICE, NULL, _mdns_service_browse_callback, account) 
 			!= kDNSServiceErr_NoError)
 #else /* USE_BONJOUR_HOWL */
@@ -120,16 +121,16 @@
 	/* Get the socket that communicates with the mDNS daemon and bind it to a */
 	/* callback that will handle the dns_sd packets */
 
-#ifdef USE_BONJOUR_APPLE 
+#ifdef USE_BONJOUR_APPLE
 	dns_sd_socket = DNSServiceRefSockFD(data->browser);
 	opaque_data = data->browser;
 #else /* USE_BONJOUR_HOWL */
 	dns_sd_socket = sw_discovery_socket(data->session);
 	opaque_data = data->session;
 #endif
-	
+
 	gc->inpa = purple_input_add(dns_sd_socket, PURPLE_INPUT_READ,
-								_mdns_handle_event,	opaque_data);
+				    _mdns_handle_event, opaque_data);
 
 	return TRUE;
 }
@@ -144,14 +145,14 @@
 	PurpleAccount *account;
 	PurpleConnection *gc;
 
-#ifdef USE_BONJOUR_APPLE 
-	if (NULL == data->advertisement || NULL == data->browser)
+#ifdef USE_BONJOUR_APPLE
+	if (data->advertisement == NULL || data->browser == NULL)
 #else /* USE_BONJOUR_HOWL */
 	if (data->session == NULL)
 #endif
 		return;
 
-#ifdef USE_BONJOUR_HOWL 
+#ifdef USE_BONJOUR_HOWL
 	sw_discovery_cancel(data->session, data->session_id);
 #endif
 
@@ -159,7 +160,7 @@
 	gc = purple_account_get_connection(account);
 	purple_input_remove(gc->inpa);
 
-#ifdef USE_BONJOUR_APPLE 
+#ifdef USE_BONJOUR_APPLE
 	/* hack: for win32, we need to stop listening to the advertisement pipe too */
 	purple_input_remove(data->advertisement_fd);
 
--- a/libpurple/protocols/bonjour/mdns_howl.c	Tue Jun 05 21:46:27 2007 +0000
+++ b/libpurple/protocols/bonjour/mdns_howl.c	Tue Jun 05 22:13:23 2007 +0000
@@ -113,7 +113,7 @@
 			} else if (strcmp(key, "msg") == 0) {
 				g_free(buddy->msg);
 				buddy->msg = g_strdup(value);
-			}
+	}
 		}
 	}
 
@@ -198,6 +198,7 @@
 	sw_text_record dns_data;
 	sw_result publish_result = SW_OKAY;
 	char portstring[6];
+	const char *jid, *aim, *email;
 
 	/* Fill the data for the service */
 	if (sw_text_record_init(&dns_data) != SW_OKAY)
@@ -209,34 +210,46 @@
 	/* Convert the port to a string */
 	snprintf(portstring, sizeof(portstring), "%d", data->port_p2pj);
 
-	/* Publish standard records */
-	sw_text_record_add_key_and_string_value(dns_data, "txtvers", data->txtvers);
-	sw_text_record_add_key_and_string_value(dns_data, "version", data->version);
-	sw_text_record_add_key_and_string_value(dns_data, "1st", data->first);
-	sw_text_record_add_key_and_string_value(dns_data, "last", data->last);
-	sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", portstring);
-	sw_text_record_add_key_and_string_value(dns_data, "phsh", data->phsh);
-	sw_text_record_add_key_and_string_value(dns_data, "status", data->status);
-	sw_text_record_add_key_and_string_value(dns_data, "vc", data->vc);
+	jid = purple_account_get_string(data->account, "jid", NULL);
+	aim = purple_account_get_string(data->account, "AIM", NULL);
+	email = purple_account_get_string(data->account, "email", NULL);
+
+	/* We should try to follow XEP-0174, but some clients have "issues", so we humor them.
+	 * See http://telepathy.freedesktop.org/wiki/SalutInteroperability
+	 */
 
-	/* Publish extra records */
-	if ((data->email != NULL) && (*data->email != '\0'))
-		sw_text_record_add_key_and_string_value(dns_data, "email", data->email);
+	/* Needed by iChat */
+	sw_text_record_add_key_and_string_value(dns_data, "txtvers", "1");
+	/* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */
+	sw_text_record_add_key_and_string_value(dns_data, "1st", data->first);
+	/* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */
+	sw_text_record_add_key_and_string_value(dns_data, "last", data->last);
+	/* Needed by Adium */
+	sw_text_record_add_key_and_string_value(dns_data, "port.p2pj", portstring);
+	/* Needed by iChat, Gaim/Pidgin <= 2.0.1 */
+	sw_text_record_add_key_and_string_value(dns_data, "status", data->status);
+	/* Currently always set to "!" since we don't support AV and wont ever be in a conference */
+	sw_text_record_add_key_and_string_value(dns_data, "vc", data->vc);
+	sw_text_record_add_key_and_string_value(dns_data, "ver", VERSION);
+	if (email != NULL && *email != '\0')
+		sw_text_record_add_key_and_string_value(dns_data, "email", email);
+	if (jid != NULL && *jid != '\0')
+		sw_text_record_add_key_and_string_value(dns_data, "jid", jid);
+	/* Nonstandard, but used by iChat */
+	if (aim != NULL && *aim != '\0')
+		sw_text_record_add_key_and_string_value(dns_data, "AIM", aim);
+	if (data->msg != NULL && *data->msg != '\0')
+		sw_text_record_add_key_and_string_value(dns_data, "msg", data->msg);
+	if (data->phsh != NULL && *data->phsh != '\0')
+		sw_text_record_add_key_and_string_value(dns_data, "phsh", data->phsh);
 
-	if ((data->jid != NULL) && (*data->jid != '\0'))
-		sw_text_record_add_key_and_string_value(dns_data, "jid", data->jid);
-
-	if ((data->AIM != NULL) && (*data->AIM != '\0'))
-		sw_text_record_add_key_and_string_value(dns_data, "AIM", data->AIM);
-
-	if ((data->msg != NULL) && (*data->msg != '\0'))
-		sw_text_record_add_key_and_string_value(dns_data, "msg", data->msg);
+	/* TODO: ext, nick, node */
 
 	/* Publish the service */
 	switch (type)
 	{
 		case PUBLISH_START:
-			publish_result = sw_discovery_publish(data->session, 0, data->name, ICHAT_SERVICE, NULL,
+			publish_result = sw_discovery_publish(data->session, 0, purple_account_get_username(data->account), ICHAT_SERVICE, NULL,
 								NULL, data->port_p2pj, sw_text_record_bytes(dns_data), sw_text_record_len(dns_data),
 								_publish_reply, NULL, &data->session_id);
 			break;
--- a/libpurple/protocols/bonjour/mdns_types.h	Tue Jun 05 21:46:27 2007 +0000
+++ b/libpurple/protocols/bonjour/mdns_types.h	Tue Jun 05 22:13:23 2007 +0000
@@ -21,7 +21,7 @@
 #include "account.h"
 #include "config.h"
 
-#ifdef USE_BONJOUR_APPLE 
+#ifdef USE_BONJOUR_APPLE
 #include "dns_sd_proxy.h"
 #else /* USE_BONJOUR_HOWL */
 #include <howl.h>
@@ -34,10 +34,10 @@
  */
 typedef struct _BonjourDnsSd
 {
-#ifdef USE_BONJOUR_APPLE 
+#ifdef USE_BONJOUR_APPLE
 	DNSServiceRef advertisement;
 	DNSServiceRef browser;
-	
+
 	int advertisement_fd; /* hack... windows bonjour is broken, so we have to have this */
 #else /* USE_BONJOUR_HOWL */
 	sw_discovery session;
@@ -45,20 +45,13 @@
 #endif
 
 	PurpleAccount *account;
-	const char *name;
-	gchar *txtvers;
-	gchar *version;
 	gchar *first;
 	gchar *last;
 	gint port_p2pj;
 	gchar *phsh;
 	gchar *status;
-	gchar *email;
 	gchar *vc;
-	gchar *jid;
-	gchar *AIM;
 	gchar *msg;
-	GHashTable *buddies;
 } BonjourDnsSd;
 
 typedef enum _PublishType {
--- a/libpurple/protocols/bonjour/mdns_win32.c	Tue Jun 05 21:46:27 2007 +0000
+++ b/libpurple/protocols/bonjour/mdns_win32.c	Tue Jun 05 22:13:23 2007 +0000
@@ -235,46 +235,56 @@
 	TXTRecordRef dns_data;
 	char portstring[6];
 	int ret = 0;
-	
+	const char *jid, *aim, *email;
+	DNSServiceErrorType set_ret;
+
 	TXTRecordCreate(&dns_data, 256, NULL);
 
 	/* Convert the port to a string */
 	snprintf(portstring, sizeof(portstring), "%d", data->port_p2pj);
-	
-	/* Publish standard records */
+
+	jid = purple_account_get_string(data->account, "jid", NULL);
+	aim = purple_account_get_string(data->account, "AIM", NULL);
+	email = purple_account_get_string(data->account, "email", NULL);
+
+	/* We should try to follow XEP-0174, but some clients have "issues", so we humor them.
+	 * See http://telepathy.freedesktop.org/wiki/SalutInteroperability
+	 */
 
-	if (kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "txtvers", strlen(data->txtvers), data->txtvers) ||
-			kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "version", strlen(data->version), data->version) ||
-			kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "1st", strlen(data->first), data->first) ||
-			kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "last", strlen(data->last), data->last) ||
-			kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "port", strlen(portstring), portstring) ||
-			kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "phsh", strlen(data->phsh), data->phsh) ||
-			kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "status", strlen(data->status), data->status) ||
-			kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "vc", strlen(data->vc), data->vc))
-	{
-		purple_debug_error("bonjour", "Unable to allocate memory for text record.\n");
-		ret = -1;
-	}
-	else if ((data->email != NULL) && (*data->email != '\0') &&
-		kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "email", strlen(data->email), data->email))
-	{
-		purple_debug_error("bonjour", "Unable to allocate memory for text record.\n");
-		ret = -1;
-	}
-	else if ((data->jid != NULL) && (*data->jid != '\0') &&
-		kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "email", strlen(data->jid), data->jid))
-	{
-		purple_debug_error("bonjour", "Unable to allocate memory for text record.\n");
-		ret = -1;
-	}
-	else if ((data->AIM != NULL) && (*data->AIM != '\0') &&
-		kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "AIM", strlen(data->AIM), data->AIM))
-	{
-		purple_debug_error("bonjour", "Unable to allocate memory for text record.\n");
-		ret = -1;
-	}
-	else if ((data->msg != NULL) && (*data->msg != '\0') &&
-		kDNSServiceErr_NoError != TXTRecordSetValue(&dns_data, "msg", strlen(data->msg), data->msg))
+	/* Needed by iChat */
+	set_ret = TXTRecordSetValue(&dns_data, "txtvers", 1, "1");
+	/* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */
+	if (set_ret == kDNSServiceErr_NoError)
+		set_ret = TXTRecordSetValue(&dns_data, "1st", strlen(data->first), data->first);
+	/* Needed by Gaim/Pidgin <= 2.0.1 (remove at some point) */
+	if (set_ret == kDNSServiceErr_NoError)
+		set_ret = TXTRecordSetValue(&dns_data, "last", strlen(data->last), data->last);
+	/* Needed by Adium */
+	if (set_ret == kDNSServiceErr_NoError)
+		set_ret = TXTRecordSetValue(&dns_data, "port.p2pj", strlen(portstring), portstring);
+	/* Needed by iChat, Gaim/Pidgin <= 2.0.1 */
+	if (set_ret == kDNSServiceErr_NoError)
+		set_ret = TXTRecordSetValue(&dns_data, "status", strlen(data->status), data->status);
+	if (set_ret == kDNSServiceErr_NoError)
+		set_ret = TXTRecordSetValue(&dns_data, "ver", strlen(VERSION), VERSION);
+	/* Currently always set to "!" since we don't support AV and wont ever be in a conference */
+	if (set_ret == kDNSServiceErr_NoError)
+		set_ret = TXTRecordSetValue(&dns_data, "vc", strlen(data->vc), data->vc);
+	if (set_ret == kDNSServiceErr_NoError && email != NULL && *email != '\0')
+		set_ret = TXTRecordSetValue(&dns_data, "email", strlen(email), email);
+	if (set_ret == kDNSServiceErr_NoError && jid != NULL && *jid != '\0')
+		set_ret = TXTRecordSetValue(&dns_data, "jid", strlen(jid), jid);
+	/* Nonstandard, but used by iChat */
+	if (set_ret == kDNSServiceErr_NoError && aim != NULL && *aim != '\0')
+		set_ret = TXTRecordSetValue(&dns_data, "AIM", strlen(aim), aim);
+	if (set_ret == kDNSServiceErr_NoError && data->msg != NULL && *data->msg != '\0')
+		set_ret = TXTRecordSetValue(&dns_data, "msg", strlen(data->msg), data->msg);
+	if (set_ret == kDNSServiceErr_NoError && data->phsh != NULL && *data->phsh != '\0')
+		set_ret = TXTRecordSetValue(&dns_data, "phsh", strlen(data->phsh), data->phsh);
+
+	/* TODO: ext, nick, node */
+
+	if (set_ret != kDNSServiceErr_NoError)
 	{
 		purple_debug_error("bonjour", "Unable to allocate memory for text record.\n");
 		ret = -1;
@@ -288,7 +298,7 @@
 		switch (type)
 		{
 			case PUBLISH_START:
-				err = DNSServiceRegister(&data->advertisement, 0, 0, data->name, ICHAT_SERVICE,
+				err = DNSServiceRegister(&data->advertisement, 0, 0, purple_account_get_username(data->account), ICHAT_SERVICE,
 					NULL, NULL, data->port_p2pj, TXTRecordGetLength(&dns_data), TXTRecordGetBytesPtr(&dns_data),
 					_mdns_service_register_callback, NULL);
 				break;