changeset 18848:32a44f7e9c52

merge of '27e06af9a3657aa4d9664c8f17f3aee8ebc41e65' and '7a479398307e3af8d16c684697d3ec93cd8e491c'
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 09 Aug 2007 02:30:03 +0000
parents a53992a4437a (diff) 2bf2bd713955 (current diff)
children 1787e601aafc
files libpurple/protocols/bonjour/mdns_avahi.c
diffstat 1 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/mdns_avahi.c	Thu Aug 09 02:17:18 2007 +0000
+++ b/libpurple/protocols/bonjour/mdns_avahi.c	Thu Aug 09 02:30:03 2007 +0000
@@ -19,6 +19,7 @@
 #include "mdns_interface.h"
 #include "debug.h"
 #include "buddy.h"
+#include "bonjour.h"
 
 #include <avahi-client/client.h>
 #include <avahi-client/lookup.h>
@@ -32,6 +33,11 @@
 #include <avahi-glib/glib-malloc.h>
 #include <avahi-glib/glib-watch.h>
 
+/* For some reason, this is missing from the Avahi type defines */
+#ifndef AVAHI_DNS_TYPE_NULL
+#define AVAHI_DNS_TYPE_NULL 0x0A
+#endif
+
 /* data used by avahi bonjour implementation */
 typedef struct _avahi_session_impl_data {
 	AvahiClient *client;
@@ -40,6 +46,10 @@
 	AvahiEntryGroup *group;
 } AvahiSessionImplData;
 
+typedef struct _avahi_buddy_impl_data {
+	AvahiRecordBrowser *record_browser;
+} AvahiBuddyImplData;
+
 static void
 _resolver_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol,
 		  AvahiResolverEvent event, const char *name, const char *type, const char *domain,
@@ -170,6 +180,20 @@
 
 }
 
+static void
+_buddy_icon_record_cb(AvahiRecordBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol,
+		      AvahiBrowserEvent event, const char *name, uint16_t clazz, uint16_t type,
+		      const void *rdata, size_t size, AvahiLookupResultFlags flags, void *userdata) {
+	BonjourBuddy *buddy = userdata;
+	AvahiBuddyImplData *idata = buddy->mdns_impl_data;
+
+	purple_buddy_icons_set_for_user(buddy->account, buddy->name,
+					g_memdup(rdata, size), size, buddy->phsh);
+
+	avahi_record_browser_free(idata->record_browser);
+	idata->record_browser = NULL;
+}
+
 /****************************
  * mdns_interface functions *
  ****************************/
@@ -339,10 +363,45 @@
 }
 
 void _mdns_init_buddy(BonjourBuddy *buddy) {
+	buddy->mdns_impl_data = g_new0(AvahiBuddyImplData, 1);
 }
 
 void _mdns_delete_buddy(BonjourBuddy *buddy) {
+	AvahiBuddyImplData *idata = buddy->mdns_impl_data;
+
+	g_return_if_fail(idata != NULL);
+
+	if (idata->record_browser != NULL)
+		avahi_record_browser_free(idata->record_browser);
+
+	g_free(idata);
+
+	buddy->mdns_impl_data = NULL;
 }
 
 void _mdns_retrieve_retrieve_buddy_icon(BonjourBuddy* buddy) {
+	PurpleConnection *conn = purple_account_get_connection(buddy->account);
+	BonjourData *bd = conn->proto_data;
+	AvahiSessionImplData *session_idata = bd->dns_sd_data->mdns_impl_data;
+	AvahiBuddyImplData *idata = buddy->mdns_impl_data;
+	gchar *name;
+
+	g_return_if_fail(idata != NULL);
+
+	if (idata->record_browser != NULL)
+		avahi_record_browser_free(idata->record_browser);
+
+	name = g_strdup_printf("%s." ICHAT_SERVICE "local", buddy->name);
+	idata->record_browser = avahi_record_browser_new(session_idata->client, AVAHI_IF_UNSPEC,
+		AVAHI_PROTO_UNSPEC, name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_NULL, 0,
+		_buddy_icon_record_cb, buddy);
+	g_free(name);
+
+	if (!idata->record_browser) {
+		purple_debug_error("bonjour",
+			"Unable to initialize record browser.  Error: %s\n.",
+			avahi_strerror(avahi_client_errno(session_idata->client)));
 }
+
+}
+