changeset 18830:2ae9b483c4db

Avahi bonjour implementation of receiving buddy icons.
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 08 Aug 2007 01:57:08 +0000
parents 952c01c26d67
children a53992a4437a
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	Tue Aug 07 06:45:23 2007 +0000
+++ b/libpurple/protocols/bonjour/mdns_avahi.c	Wed Aug 08 01:57:08 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 *
  ****************************/
@@ -340,10 +364,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 bonjour_dns_sd_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)));
+	}
+
 }
+