[banshee] Added the Amazon MP3 server proxy implementation



commit 8b526782f8e3c04bc948b4a2ad94ad9eb92022e8
Author: Aaron Bockover <abockover novell com>
Date:   Mon Aug 2 14:02:19 2010 -0400

    Added the Amazon MP3 server proxy implementation
    
    For the sake of transparency and version control, now that we are using
    the Amazon Afilliate ID to generate revenue for the GNOME Foundation.
    
    Read the README for details.

 .../Banshee.AmazonMp3.Store/server/Makefile        |   15 +++
 .../Banshee.AmazonMp3.Store/server/README          |   38 +++++++
 .../Banshee.AmazonMp3.Store/server/amz-fixups.js   |   17 +++
 .../Banshee.AmazonMp3.Store/server/redirect.c      |  108 ++++++++++++++++++++
 4 files changed, 178 insertions(+), 0 deletions(-)
---
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/server/Makefile b/src/Extensions/Banshee.AmazonMp3.Store/server/Makefile
new file mode 100644
index 0000000..8b920fb
--- /dev/null
+++ b/src/Extensions/Banshee.AmazonMp3.Store/server/Makefile
@@ -0,0 +1,15 @@
+CFLAGS_AND_LIBS := $(shell pkg-config --cflags --libs glib-2.0) -lGeoIP
+
+all: redirect.do
+
+check-deps:
+	@test -f /usr/include/GeoIP.h || \
+			{ echo "You must provide /usr/include/GeoIP.h"; exit 1; }
+	@pkg-config --exists glib-2.0 || \
+			{ echo "You must provide pkgconfig(glib-2.0)"; exit 1; }
+
+redirect.do: check-deps redirect.c
+	$(CC) -Wall -o $@ $(CFLAGS_AND_LIBS) redirect.c
+
+clean:
+	rm -f redirect.do
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/server/README b/src/Extensions/Banshee.AmazonMp3.Store/server/README
new file mode 100644
index 0000000..35d1fc8
--- /dev/null
+++ b/src/Extensions/Banshee.AmazonMp3.Store/server/README
@@ -0,0 +1,38 @@
+This is a tiny C-based CGI proxy that accomplishes a few things. When a user
+accesses the Amazon MP3 Store through Banshee, the initial home request and
+any integrated search queries are sent through this proxy.
+
+The following is accomplished by the proxy:
+
+  - Use libGeoIP to quickly look up the country associated by the user's
+    IP address; if the user is in a country with a dedicated Amazon MP3
+	store, the user is sent automatically to that store; otherwise, the
+	user is sent to the .com (US) store.
+
+  - Set the Amazon Affiliate ID on the requests - the Affiliate ID is
+    'banshee-20' and this ID is controlled/owned by the GNOME Foundation,
+	a not-for-profit organization. 100% of all affiliate revenue generated
+	by Banshee/this proxy is sent to the GNOME Foundation.
+
+  - Generally provides a level of indirection over directly accessing any
+    of the Amazon web sites explicitly in the client.
+
+The default implementation of this proxy is currently hosted by the Banshee
+Project at:
+
+  http://integrated-services.banshee.fm/amz/redirect.do
+
+If a distribution or other entity has a desire to modify the source code
+of the Banshee client to access a proxy (this one or an alternate
+implementation) hosted elsewhere, we request that the functionality and the
+Affiliate ID 'banshee-20' be retained. Again, all generated revenue is sent
+directly to the GNOME Foundation, which directly helps foster development
+and awareness of Free/Open Source Software and surrounding communities.
+
+Contributions to this proxy can be made directly against Banshee git, just
+like normal. Checked in code will be pushed to the server above. The redirect.c
+file is licensed under the AGPL:
+
+  http://www.gnu.org/licenses/agpl-3.0.html
+
+Thank you for supporting the GNOME Foundation!
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/server/amz-fixups.js b/src/Extensions/Banshee.AmazonMp3.Store/server/amz-fixups.js
new file mode 100644
index 0000000..76cdb73
--- /dev/null
+++ b/src/Extensions/Banshee.AmazonMp3.Store/server/amz-fixups.js
@@ -0,0 +1,17 @@
+// Copyright 2010 Novell, Inc.
+// Written by Aaron Bockover
+// Made available under the MIT license:
+// http://www.opensource.org/licenses/mit-license.php
+
+var e = document.getElementById ('a2z_1p_flash_not_installed');
+while (e) {
+    if (e.tagName == 'TABLE' && e.className == 'playerRow') {
+        e.style.display = 'none';
+    }
+    e = e.parentElement;
+}
+
+for (var l = document.getElementsByClassName ('flashWarning'), i = 0;
+    l && i < l.length; i++) {
+    l[i].style.display = 'none';
+}
diff --git a/src/Extensions/Banshee.AmazonMp3.Store/server/redirect.c b/src/Extensions/Banshee.AmazonMp3.Store/server/redirect.c
new file mode 100644
index 0000000..594d995
--- /dev/null
+++ b/src/Extensions/Banshee.AmazonMp3.Store/server/redirect.c
@@ -0,0 +1,108 @@
+// redirect.c - a CGI proxy to the Amazon MP3 store
+//
+// Authors:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright 2010 Novell, Inc.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+// ------------------------------------------------------------------------
+//
+// Provides IP-based geolocation to an appropriate Amazon MP3 storefront,
+// supporting the home and search functions. Injects the Banshee Project's
+// Amazon Affiliate ID into the redirected URLs. 100% of all revenue
+// generated by this affiliate ID goes to the GNOME Foundation.
+//
+// The proxy itself is very simple and lame. It's written to be fast and
+// short lived (memory is not explicitly released).
+
+#include <GeoIP.h>
+#include <glib.h>
+#include <stdlib.h>
+
+// We ask that no one change this. ALL (100%) revenue generated by this
+// affiliate ID is sent directly to the GNOME Foundation. The GNOME
+// Foundation controls/owns this affiliate ID. Please help support Free
+// Software through the GNOME Foundation!
+#define AMAZON_AFFILIATE_ID "banshee-20"
+
+gint
+main (gint argc, gchar **argv)
+{
+    GeoIP *geoip;
+    const gchar *remote_addr;
+    const gchar *path_info;
+    gchar **path_parts;
+    const gchar *country;
+    gchar *action;
+    gchar *input;
+    gchar *domain;
+    gchar *p;
+    gchar *dest_url;
+
+    remote_addr = g_getenv ("REMOTE_ADDR");
+
+    path_parts = g_strsplit (path_info = g_getenv ("PATH_INFO"), "/", 4);
+    if (path_parts == NULL ||
+        path_parts[0] == NULL ||
+        (country = path_parts[1]) == NULL) {
+        return 1;
+    }
+
+    input = NULL;
+    action = NULL;
+    if ((action = path_parts[2]) != NULL) {
+        input = path_parts[3];
+    }
+    
+    if ((p = strrchr (remote_addr, ':')) != NULL) {
+        remote_addr = p + 1;
+    }
+
+    if (strcmp (country, "geo") == 0) {
+        geoip = GeoIP_new (GEOIP_STANDARD);
+        country = GeoIP_country_code_by_name (geoip, remote_addr);
+    }
+
+    if (country == NULL || strcmp (country, "US") == 0) {
+        domain = "com";
+    } else if (strcmp (country, "FR") == 0) {
+        domain = "fr";
+    } else if (strcmp (country, "UK") == 0) {
+        domain = "co.uk";
+    } else if (strcmp (country, "DE") == 0 ||
+        strcmp (country, "CH") == 0 ||
+        strcmp (country, "AT") == 0) {
+        domain = "de";
+    } else if (strcmp (country, "JP") == 0) {
+        domain = "co.jp";
+    } else {
+        domain = "com";
+    } 
+
+    if (input == NULL || action == NULL || strcmp (action, "home") == 0) {
+        dest_url = g_strdup_printf ("http://www.amazon.%s/mp3/";, domain);
+    } else if (strcmp (action, "search") == 0) {
+        dest_url = g_strdup_printf ("http://www.amazon.%s/s/ref=nb_sb_noss?url=search-alias%%3Ddigital-music&field-keywords=%s";, domain, input);
+    } else {
+        return 1;
+    }
+
+    printf ("Location: http://www.amazon.com/gp/redirect.html?ie=UTF8&location=%s&tag=";
+        AMAZON_AFFILIATE_ID "\n\n",
+        g_uri_escape_string (dest_url, NULL, TRUE));
+
+    return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]