changeset 9416:f63abdb00499

[gaim-migrate @ 10231] Advertise the sha hash of our icon. Thanks to proton for telling all kinds of neat stuff about the hash. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 27 Jun 2004 20:28:17 +0000
parents 1c4092217e4a
children 9f6a28af7164
files src/protocols/rendezvous/mdns.c src/protocols/rendezvous/rendezvous.c
diffstat 2 files changed, 49 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/rendezvous/mdns.c	Sun Jun 27 18:19:09 2004 +0000
+++ b/src/protocols/rendezvous/mdns.c	Sun Jun 27 20:28:17 2004 +0000
@@ -1390,6 +1390,7 @@
 	DNSPacket *dns = NULL;
 	int offset; /* Current position in datagram */
 	/* XXX - Find out what to use as a maximum incoming UDP packet size */
+	/* XXX - Would making this static increase performance? */
 	/* char data[512]; */
 	char data[10096];
 	unsigned int datalen;
--- a/src/protocols/rendezvous/rendezvous.c	Sun Jun 27 18:19:09 2004 +0000
+++ b/src/protocols/rendezvous/rendezvous.c	Sun Jun 27 20:28:17 2004 +0000
@@ -28,6 +28,7 @@
 #include "debug.h"
 #include "network.h"
 #include "prpl.h"
+#include "sha.h"
 
 #include "mdns.h"
 #include "util.h"
@@ -451,13 +452,56 @@
 	rd->mytxtdata = g_slist_append(rd->mytxtdata, node);
 }
 
+static guchar *rendezvous_read_icon_data(const char *filename, unsigned short *length)
+{
+	struct stat st;
+	FILE *file;
+	guchar *data;
+
+	*length = 0;
+
+	g_return_val_if_fail(filename != NULL, NULL);
+
+	if (stat(filename, &st))
+		return NULL;
+
+	if (!(file = fopen(filename, "rb")))
+		return NULL;
+
+	*length = st.st_size;
+	data = g_malloc(*length);
+	fread(data, 1, *length, file);
+	fclose(file);
+
+	return data;
+}
+
+static void rendezvous_add_to_txt_iconhash(RendezvousData *rd, const char *iconfile)
+{
+	guchar *icondata;
+	unsigned short iconlength;
+	unsigned char hash[20];
+	gchar *base16;
+
+	g_return_if_fail(rd != NULL);
+
+	if (iconfile == NULL)
+		return;
+
+	icondata = rendezvous_read_icon_data(iconfile, &iconlength);
+	shaBlock((unsigned char *)icondata, iconlength, hash);
+	g_free(icondata);
+
+	base16 = gaim_base16_encode(hash, 20);
+	rendezvous_add_to_txt(rd, "phsh", base16);
+	g_free(base16);
+}
+
 static void rendezvous_send_icon(GaimConnection *gc)
 {
 	RendezvousData *rd = gc->proto_data;
 	GaimAccount *account = gaim_connection_get_account(gc);
 	const char *iconfile = gaim_account_get_buddy_icon(account);
-	struct stat st;
-	FILE *file;
 	unsigned char *rdata;
 	unsigned short rdlength;
 	gchar *myname;
@@ -465,16 +509,7 @@
 	if (iconfile == NULL)
 		return;
 
-	if (stat(iconfile, &st))
-		return;
-
-	if (!(file = fopen(iconfile, "rb")))
-		return;
-
-	rdlength = st.st_size;
-	rdata = g_malloc(rdlength);
-	fread(rdata, 1, rdlength, file);
-	fclose(file);
+	rdata = rendezvous_read_icon_data(iconfile, &rdlength);
 
 	myname = g_strdup_printf("%s._presence._tcp.local", gaim_account_get_username(account));
 	mdns_advertise_null(rd->fd, myname, rdata, rdlength);
@@ -507,7 +542,7 @@
 	rendezvous_add_to_txt(rd, "txtvers", "1");
 	rendezvous_add_to_txt(rd, "status", "avail");
 	/* rendezvous_add_to_txt(rd, "vc", "A!"); */
-	/* rendezvous_add_to_txt(rd, "phsh", "96f15dec163cf4a8cfa0cf08109cc9766f7bd5a0"); */
+	rendezvous_add_to_txt_iconhash(rd, gaim_account_get_buddy_icon(account));
 	rendezvous_add_to_txt(rd, "1st", gaim_account_get_string(account, "first", "Gaim"));
 	if (gaim_account_get_bool(account, "shareaim", FALSE)) {
 		GList *l;