changeset 9281:adde46ad65e9

[gaim-migrate @ 10084] This keeps track of IP addresses that other clients send us, and displays them in the Get Info dialog. Eventually we'll want to do other stuff with them, probably. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Mon, 14 Jun 2004 07:05:10 +0000
parents 2104c1039626
children fe7db2ea4a1e
files src/protocols/yahoo/yahoo.c src/protocols/yahoo/yahoo_friend.c src/protocols/yahoo/yahoo_friend.h src/protocols/yahoo/yahoo_profile.c
diffstat 4 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/yahoo/yahoo.c	Mon Jun 14 06:09:26 2004 +0000
+++ b/src/protocols/yahoo/yahoo.c	Mon Jun 14 07:05:10 2004 +0000
@@ -1828,13 +1828,27 @@
 	}
 
 	if (base64) {
+		guint32 ip;
+		char *tmp2;
+		YahooFriend *f;
+
 		gaim_base64_decode(base64, &decoded, &len);
 		if (len) {
 			char *tmp = gaim_str_binary_to_ascii(decoded, len);
 			gaim_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, tmp);
 			g_free(tmp);
 		}
+
+		tmp2 = g_strndup(decoded, len); /* so its \0 terminated...*/
+		ip = strtol(tmp2, NULL, 10);
+		g_free(tmp2);
 		g_free(decoded);
+		tmp2 = g_strdup_printf("%u.%u.%u.%u", ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff,
+		                       (ip >> 24) & 0xff);
+		f = yahoo_friend_find(gc, who);
+		if (f)
+			yahoo_friend_set_ip(f, tmp2);
+		g_free(tmp2);
 	}
 }
 
--- a/src/protocols/yahoo/yahoo_friend.c	Mon Jun 14 06:09:26 2004 +0000
+++ b/src/protocols/yahoo/yahoo_friend.c	Mon Jun 14 07:05:10 2004 +0000
@@ -71,6 +71,18 @@
 	return f;
 }
 
+void yahoo_friend_set_ip(YahooFriend *f, const char *ip)
+{
+	if (f->ip)
+		g_free(f->ip);
+	f->ip = g_strdup(ip);
+}
+
+const char *yahoo_friend_get_ip(YahooFriend *f)
+{
+	return f->ip;
+}
+
 void yahoo_friend_free(gpointer p)
 {
 	YahooFriend *f = p;
--- a/src/protocols/yahoo/yahoo_friend.h	Mon Jun 14 06:09:26 2004 +0000
+++ b/src/protocols/yahoo/yahoo_friend.h	Mon Jun 14 07:05:10 2004 +0000
@@ -45,6 +45,10 @@
 YahooFriend *yahoo_friend_new(void);
 YahooFriend *yahoo_friend_find(GaimConnection *gc, const char *name);
 YahooFriend *yahoo_friend_find_or_new(GaimConnection *gc, const char *name);
+
+void yahoo_friend_set_ip(YahooFriend *f, const char *ip);
+const char *yahoo_friend_get_ip(YahooFriend *f);
+
 void yahoo_friend_free(gpointer p);
 
 #endif /* _YAHOO_FRIEND_H_ */
--- a/src/protocols/yahoo/yahoo_profile.c	Mon Jun 14 06:09:26 2004 +0000
+++ b/src/protocols/yahoo/yahoo_profile.c	Mon Jun 14 07:05:10 2004 +0000
@@ -32,6 +32,7 @@
 #endif
 
 #include "yahoo.h"
+#include "yahoo_friend.h"
 
 typedef struct {
 	GaimConnection *gc;
@@ -634,6 +635,7 @@
 static char *yahoo_tooltip_info_text(YahooGetInfoData *info_data) {
 	GString *s = g_string_sized_new(80); /* wild guess */
 	GaimBuddy *b;
+	YahooFriend *f;
 
 	g_string_printf(s, _("<b>%s:</b> %s<br>"), _("Yahoo! ID"), info_data->name);
 	b = gaim_find_buddy(gaim_connection_get_account(info_data->gc),
@@ -656,6 +658,12 @@
 			g_string_append_printf(s, "%s<br>", statustext);
 			g_free(statustext);
 		}
+		if ((f = yahoo_friend_find(info_data->gc, b->name))) {
+			const char *ip;
+			if ((ip = yahoo_friend_get_ip(f)))
+				g_string_append_printf(s, _("<b>IP Address:</b> %s<br>"), ip);
+		}
+
 	}
 
 	return g_string_free(s, FALSE);