diff libpurple/protocols/bonjour/buddy.c @ 17495:d7b50cac1c7a

This is a patch from Chris Davies to make Bonjour work on Windows using the Apple Bonjour framework. It turns out that the actual DNS-SD library is (3 clause) BSD licensed, so we can use it. There are a few changes by me, mainly to fix the howl implementation. Fixes #1117 . There appear to be a few bugs, but I believe that they were also present previously. I'm hoping to do some more tweaking before the next release. The howl implementation will eventually be supersceded by a native avahi implementation, so I opted for a somewhat dirty hack to enable it instead of doing something with config.h.
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 05 Jun 2007 03:38:22 +0000
parents 32c366eeeb99
children e165d1ba8844
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/buddy.c	Tue Jun 05 03:13:02 2007 +0000
+++ b/libpurple/protocols/bonjour/buddy.c	Tue Jun 05 03:38:22 2007 +0000
@@ -27,49 +27,109 @@
  * Creates a new buddy.
  */
 BonjourBuddy *
-bonjour_buddy_new(const gchar *name, const gchar *first, gint port_p2pj,
-	const gchar *phsh, const gchar *status, const gchar *email,
-	const gchar *last, const gchar *jid, const gchar *AIM,
-	const gchar *vc, const gchar *ip, const gchar *msg)
+bonjour_buddy_new(const gchar *name, PurpleAccount* account)
 {
 	BonjourBuddy *buddy = malloc(sizeof(BonjourBuddy));
 
+	buddy->account = account;
 	buddy->name = g_strdup(name);
-	buddy->first = g_strdup(first);
-	buddy->port_p2pj = port_p2pj;
-	buddy->phsh = g_strdup(phsh);
-	buddy->status = g_strdup(status);
-	buddy->email = g_strdup(email);
-	buddy->last = g_strdup(last);
-	buddy->jid = g_strdup(jid);
-	buddy->AIM = g_strdup(AIM);
-	buddy->vc = g_strdup(vc);
-	buddy->ip = g_strdup(ip);
-	buddy->msg = g_strdup(msg);
+	buddy->first = NULL;
+	buddy->port_p2pj = 0;
+	buddy->phsh = NULL;
+	buddy->status = NULL;
+	buddy->email = NULL;
+	buddy->last = NULL;
+	buddy->jid = NULL;
+	buddy->AIM = NULL;
+	buddy->vc = NULL;
+	buddy->ip = NULL;
+	buddy->msg = NULL;
 	buddy->conversation = NULL;
+	
+#ifdef USE_BONJOUR_APPLE
+	buddy->txt_query = NULL;
+	buddy->txt_query_fd = 0;
+#endif
 
 	return buddy;
 }
 
+void 
+set_bonjour_buddy_value(BonjourBuddy* buddy, bonjour_buddy_member member, const char* value, uint32_t len)
+{
+	gchar **key = NULL;
+	switch (member)
+	{
+		case E_BUDDY_FIRST:
+			key = &buddy->first;
+			break;
+			
+		case E_BUDDY_LAST:
+			key = &buddy->last;
+			break;
+			
+		case E_BUDDY_STATUS:
+			key = &buddy->status;
+			break;
+			
+		case E_BUDDY_EMAIL:
+			key = &buddy->email;
+			break;
+			
+		case E_BUDDY_PHSH:
+			key = &buddy->phsh;
+			break;
+	
+		case E_BUDDY_JID:
+			key = &buddy->jid;
+			break;
+			
+		case E_BUDDY_AIM:
+			key = &buddy->AIM;
+			break;
+			
+		case E_BUDDY_VC:
+			key = &buddy->vc;
+			break;
+			
+		case E_BUDDY_MSG:
+			key = &buddy->msg;
+			break;
+	}
+	
+	g_free(*key);
+	*key = NULL;
+	*key = g_strndup(value, len);
+}
+
 /**
  * Check if all the compulsory buddy data is present.
  */
 gboolean
 bonjour_buddy_check(BonjourBuddy *buddy)
 {
-	if (buddy->name == NULL) {
+	if (buddy->account == NULL)
+	{
+		return FALSE;
+	}
+	
+	if (buddy->name == NULL)
+	{
+		return FALSE;
+	}
+	
+	if (buddy->first == NULL)
+	{
 		return FALSE;
 	}
 
-	if (buddy->first == NULL) {
+	if (buddy->last == NULL)
+	{
 		return FALSE;
 	}
 
-	if (buddy->last == NULL) {
-		return FALSE;
-	}
-
-	if (buddy->status == NULL) {
+	if (buddy->status == NULL)
+	{
 		return FALSE;
 	}
 
@@ -82,13 +142,13 @@
  * the buddy.
  */
 void
-bonjour_buddy_add_to_purple(PurpleAccount *account, BonjourBuddy *bonjour_buddy)
+bonjour_buddy_add_to_purple(BonjourBuddy *bonjour_buddy)
 {
 	PurpleBuddy *buddy;
 	PurpleGroup *group;
 	const char *status_id, *first, *last;
 	char *alias;
-
+	
 	/* Translate between the Bonjour status and the Purple status */
 	if (g_ascii_strcasecmp("dnd", bonjour_buddy->status) == 0)
 		status_id = BONJOUR_STATUS_ID_AWAY;
@@ -108,6 +168,7 @@
 							(first && *first && last && *last ? " " : ""),
 							(last && *last ? last : ""));
 
+
 	/* Make sure the Bonjour group exists in our buddy list */
 	group = purple_find_group(BONJOUR_GROUP_NAME); /* Use the buddy's domain, instead? */
 	if (group == NULL)
@@ -117,10 +178,11 @@
 	}
 
 	/* Make sure the buddy exists in our buddy list */
-	buddy = purple_find_buddy(account, bonjour_buddy->name);
+	buddy = purple_find_buddy(bonjour_buddy->account, bonjour_buddy->name);
+	
 	if (buddy == NULL)
 	{
-		buddy = purple_buddy_new(account, bonjour_buddy->name, alias);
+		buddy = purple_buddy_new(bonjour_buddy->account, bonjour_buddy->name, alias);
 		buddy->proto_data = bonjour_buddy;
 		purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE);
 		purple_blist_add_buddy(buddy, NULL, group, NULL);
@@ -128,13 +190,14 @@
 
 	/* Set the user's status */
 	if (bonjour_buddy->msg != NULL)
-		purple_prpl_got_user_status(account, buddy->name, status_id,
+		purple_prpl_got_user_status(bonjour_buddy->account, buddy->name, status_id,
 								  "message", bonjour_buddy->msg,
 								  NULL);
 	else
-		purple_prpl_got_user_status(account, buddy->name, status_id,
+		purple_prpl_got_user_status(bonjour_buddy->account, buddy->name, status_id,
 								  NULL);
-	purple_prpl_got_user_idle(account, buddy->name, FALSE, 0);
+	purple_prpl_got_user_idle(bonjour_buddy->account, buddy->name, FALSE, 0);
+
 
 	g_free(alias);
 }
@@ -162,6 +225,14 @@
 		g_free(buddy->conversation->buddy_name);
 		g_free(buddy->conversation);
 	}
+	
+#ifdef USE_BONJOUR_APPLE
+	if (NULL != buddy->txt_query)
+		{
+		purple_input_remove(buddy->txt_query_fd);
+		DNSServiceRefDeallocate(buddy->txt_query);
+		}
+#endif
 
 	free(buddy);
 }