changeset 16318:1560f28cb854

Add the iTunes Music Store url to the GaimPresence for buddies onyour list who are advertising a URL (currently only iChat and Adium users, I think). Someone could write a neat plugin for Windows that sets your itms:// URL using the status API.
author Mark Doliner <mark@kingant.net>
date Mon, 23 Apr 2007 07:42:57 +0000
parents cb1ea9f878f5
children bfa7bc0e7b21 6349d702bab6
files libpurple/protocols/oscar/family_locate.c libpurple/protocols/oscar/oscar.c libpurple/protocols/oscar/oscar.h
diffstat 3 files changed, 76 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/family_locate.c	Mon Apr 23 06:43:49 2007 +0000
+++ b/libpurple/protocols/oscar/family_locate.c	Mon Apr 23 07:42:57 2007 +0000
@@ -294,6 +294,21 @@
 		cur->status_len = userinfo->status_len;
 	}
 
+	if (userinfo->itmsurl != NULL) {
+		free(cur->itmsurl);
+		free(cur->itmsurl_encoding);
+		if (userinfo->itmsurl_len > 0) {
+			cur->itmsurl = (char *)malloc(userinfo->itmsurl_len);
+			memcpy(cur->itmsurl, userinfo->itmsurl, userinfo->itmsurl_len);
+		} else
+			cur->itmsurl = NULL;
+		if (userinfo->itmsurl_encoding != NULL)
+			cur->itmsurl_encoding = strdup(userinfo->itmsurl_encoding);
+		else
+			cur->itmsurl_encoding = NULL;
+		cur->itmsurl_len = userinfo->itmsurl_len;
+	}
+
 	if (userinfo->away != NULL) {
 		free(cur->away);
 		free(cur->away_encoding);
@@ -577,6 +592,8 @@
 	free(info->info_encoding);
 	free(info->status);
 	free(info->status_encoding);
+	free(info->itmsurl);
+	free(info->itmsurl_encoding);
 	free(info->away);
 	free(info->away_encoding);
 }
@@ -841,6 +858,28 @@
 						}
 					} break;
 
+					case 0x0009: { /* An iTunes Music Store link */
+						free(outinfo->itmsurl);
+						free(outinfo->itmsurl_encoding);
+						if (length2 >= 4) {
+							outinfo->itmsurl_len = byte_stream_get16(bs);
+							outinfo->itmsurl = byte_stream_getstr(bs, outinfo->itmsurl_len);
+							if (byte_stream_get16(bs) == 0x0001) {
+								/* We have an encoding */
+								byte_stream_get16(bs);
+								outinfo->itmsurl_encoding = byte_stream_getstr(bs, byte_stream_get16(bs));
+							} else {
+								/* No explicit encoding, client should use UTF-8 */
+								outinfo->itmsurl_encoding = NULL;
+							}
+						} else {
+							byte_stream_advance(bs, length2);
+							outinfo->itmsurl_len = 0;
+							outinfo->itmsurl = g_strdup("");
+							outinfo->itmsurl_encoding = NULL;
+						}
+					} break;
+
 					default: {
 						byte_stream_advance(bs, length2);
 					} break;
--- a/libpurple/protocols/oscar/oscar.c	Mon Apr 23 06:43:49 2007 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Mon Apr 23 07:42:57 2007 +0000
@@ -1778,8 +1778,20 @@
 
 	if (have_status_message)
 	{
-		purple_prpl_got_user_status(account, info->sn, status_id,
-								  "message", message, NULL);
+		if ((status_id == OSCAR_STATUS_ID_AVAILABLE) && (info->itmsurl != NULL))
+		{
+			char *itmsurl;
+			itmsurl = oscar_encoding_to_utf8(info->itmsurl_encoding,
+					info->itmsurl, info->itmsurl_len);
+			purple_prpl_got_user_status(account, info->sn, status_id,
+					"message", message, "itmsurl", itmsurl, NULL);
+			g_free(itmsurl);
+		}
+		else
+		{
+			purple_prpl_got_user_status(account, info->sn, status_id,
+					"message", message, NULL);
+		}
 		g_free(message);
 	}
 	else
@@ -2890,6 +2902,25 @@
 		g_free(tmp);
 	}
 
+#if 0
+	/*
+	 * TODO: This code is disabled because it's kind of stupid.  iTunes
+	 *       doesn't run in Linux.  It'd be cool if we surfaced this URL
+	 *       to Windows users, but it would be better to just linkify
+	 *       the available message, above.
+	 */
+
+	/* iTunes Music Store link */
+	if (userinfo->itmsurl != NULL)
+	{
+		if (userinfo->itmsurl[0] != '\0')
+			tmp = oscar_encoding_to_utf8(userinfo->itmsurl_encoding,
+											 userinfo->itmsurl, userinfo->itmsurl_len);
+		oscar_user_info_add_pair(user_info, _("iTunes Music Store Link"), tmp);
+		g_free(tmp);
+	}
+#endif
+
 	/* Away message */
 	if ((userinfo->flags & AIM_FLAG_AWAY) && (userinfo->away_len > 0) && (userinfo->away != NULL) && (userinfo->away_encoding != NULL)) {
 		tmp = oscar_encoding_extract(userinfo->away_encoding);
--- a/libpurple/protocols/oscar/oscar.h	Mon Apr 23 06:43:49 2007 +0000
+++ b/libpurple/protocols/oscar/oscar.h	Mon Apr 23 07:42:57 2007 +0000
@@ -1001,6 +1001,10 @@
 	char *status_encoding;
 	guint16 status_len;
 
+	char *itmsurl;
+	char *itmsurl_encoding;
+	guint16 itmsurl_len;
+
 	char *away;
 	char *away_encoding;
 	guint16 away_len;