[libdmapsharing] Start fixing client side of password authenticated connections. Remove DAAPConnection and DPAPConnec



commit a318018005585411c1add3bbf06a793b809e68f5
Author: W. Michael Petullo <mike flyn org>
Date:   Wed Mar 10 23:16:42 2010 -0500

    Start fixing client side of password authenticated connections. Remove
    DAAPConnection and DPAPConnection as they did not add anything to
    DMAPConnection.
    Signed-off-by: W. Michael Petullo <mike flyn org>

 libdmapsharing/Makefile.am               |    4 -
 libdmapsharing/daap-connection.c         |  149 ------------------------------
 libdmapsharing/daap-connection.h         |  102 --------------------
 libdmapsharing/dmap-connection.c         |   90 +++++++++++++++---
 libdmapsharing/dmap-mdns-browser-avahi.c |    4 +-
 libdmapsharing/dmap.h                    |    2 -
 libdmapsharing/dpap-connection.c         |  147 -----------------------------
 libdmapsharing/dpap-connection.h         |  102 --------------------
 8 files changed, 77 insertions(+), 523 deletions(-)
---
diff --git a/libdmapsharing/Makefile.am b/libdmapsharing/Makefile.am
index c65079d..a0fdeea 100644
--- a/libdmapsharing/Makefile.am
+++ b/libdmapsharing/Makefile.am
@@ -4,7 +4,6 @@ BUILT_SOURCES = dmap-marshal.c dmap-marshal.h
 
 libdmapsharing_la_SOURCES = \
 	$(BUILT_SOURCES) \
-	daap-connection.c \
 	daap-record.c \
 	daap-share.c \
 	dmap-connection.c \
@@ -16,7 +15,6 @@ libdmapsharing_la_SOURCES = \
 	dmap-record-factory.c \
 	dmap-share.c \
 	dmap-structure.c \
-	dpap-connection.c \
 	dpap-record.c \
 	dpap-share.c
 
@@ -57,7 +55,6 @@ libdmapsharingincludedir = \
 	$(includedir)/libdmapsharing- LIBDMAPSHARING_MAJORMINOR@/libdmapsharing
 
 libdmapsharinginclude_HEADERS = \
-	daap-connection.h \
 	daap-record.h \
 	daap-share.h \
 	dmap.h \
@@ -70,7 +67,6 @@ libdmapsharinginclude_HEADERS = \
 	dmap-record.h \
 	dmap-record-factory.h \
 	dmap-share.h \
-	dpap-connection.h \
 	dpap-record.h \
 	dpap-share.h
 
diff --git a/libdmapsharing/dmap-connection.c b/libdmapsharing/dmap-connection.c
index 3f05300..e8bc7f1 100644
--- a/libdmapsharing/dmap-connection.c
+++ b/libdmapsharing/dmap-connection.c
@@ -353,19 +353,75 @@ connection_operation_done (DMAPConnection *connection)
 
 SoupMessage *
 dmap_connection_build_message (DMAPConnection *connection,
-	       		       const char       *path,
-	       		       gboolean          need_hash,
-	       		       gdouble           version,
-	       		       gint              req_id,
-	       		       gboolean          send_close)
+	       const char       *path,
+	       gboolean          need_hash,
+	       gdouble           version,
+	       gint              req_id,
+	       gboolean          send_close)
 {
-	return DMAP_CONNECTION_GET_CLASS (connection)->build_message
-								(connection,
-								 path,
-								 need_hash,
-								 version,
-								 req_id,
-								 send_close);
+	SoupMessage *message = NULL;
+	SoupURI *base_uri = NULL;
+	SoupURI *uri = NULL;
+
+	g_object_get (connection, "base-uri", &base_uri, NULL);
+	if (base_uri == NULL) {
+		return NULL;
+	}
+
+	uri = soup_uri_new_with_base (base_uri, path);
+	if (uri == NULL) {
+		return NULL;
+	}
+
+	message = soup_message_new_from_uri (SOUP_METHOD_GET, uri);
+
+	soup_message_headers_append (message->request_headers, "Client-DAAP-Version", 		"3.0");
+	soup_message_headers_append (message->request_headers, "Accept-Language", 		"en-us, en;q=5.0");
+#ifdef HAVE_LIBZ
+	soup_message_headers_append (message->request_headers, "Accept-Encoding",		"gzip");
+#endif
+	soup_message_headers_append (message->request_headers, "Client-DAAP-Access-Index", 	"2");
+
+	if (connection->priv->password_protected == TRUE
+	    && (connection->priv->username == NULL
+	        || connection->priv->password == NULL)) {
+		g_debug ("No username or no password provided");
+	} else {
+
+		char *h;
+		char *user_pass;
+		char *token;
+
+		user_pass = g_strdup_printf ("%s:%s", connection->priv->username, connection->priv->password);
+		token = g_base64_encode ((guchar *)user_pass, strlen (user_pass));
+		h = g_strdup_printf ("Basic %s", token);
+
+		g_free (token);
+		g_free (user_pass);
+
+		soup_message_headers_append (message->request_headers, "Authorization", h);
+		g_free (h);
+	}
+
+	if (need_hash) {
+		gchar hash[33] = {0};
+		gchar *no_daap_path = (gchar *)path;
+
+		if (g_ascii_strncasecmp (path, "daap://", 7) == 0) {
+			no_daap_path = strstr (path, "/data");
+		}
+
+		dmap_hash_generate ((short)floor (version), (const guchar*)no_daap_path, 2, (guchar*)hash, req_id);
+
+		soup_message_headers_append (message->request_headers, "Client-DAAP-Validation", hash);
+	}
+	if (send_close) {
+		soup_message_headers_append (message->request_headers, "Connection", "close");
+	}
+
+	soup_uri_free (uri);
+
+	return message;
 }
 
 #ifdef HAVE_LIBZ
@@ -1613,17 +1669,19 @@ dmap_connection_get_headers (DMAPConnection *connection,
 	soup_message_headers_append (headers, "Connection", "close");
 
 	if (priv->password_protected) {
+		char *h;
 		char *user_pass;
 		char *token;
-		char *value;
 
 		user_pass = g_strdup_printf ("%s:%s", priv->username, priv->password);
 		token = g_base64_encode ((guchar *)user_pass, strlen (user_pass));
-		value = g_strconcat ("Basic ", token, NULL);
-		soup_message_headers_append (headers, "Authentication", value);
-		g_free (value);
+		h = g_strdup_printf ("Basic %s", token);
+
 		g_free (token);
 		g_free (user_pass);
+
+		soup_message_headers_append (headers, "Authentication", h);
+		g_free (h);
 	}
 
 	return headers;
diff --git a/libdmapsharing/dmap-mdns-browser-avahi.c b/libdmapsharing/dmap-mdns-browser-avahi.c
index 992d751..f55efb4 100644
--- a/libdmapsharing/dmap-mdns-browser-avahi.c
+++ b/libdmapsharing/dmap-mdns-browser-avahi.c
@@ -389,7 +389,9 @@ resolve_cb (AvahiServiceResolver *service_resolver,
                 if (strcmp (key, "Password") == 0) {
                     if (size >= 4 && strncmp (value, "true", 4) == 0) {
                         pp = TRUE;
-                    }
+                    } else if (size >= 1 && strncmp (value, "1", 1) == 0) {
+                        pp = TRUE;
+		    }
                 } else if (strcmp (key, "Machine Name") == 0) {
                     name = g_strdup (value);
                 }
diff --git a/libdmapsharing/dmap.h b/libdmapsharing/dmap.h
index 245af44..2ca757e 100644
--- a/libdmapsharing/dmap.h
+++ b/libdmapsharing/dmap.h
@@ -1,7 +1,6 @@
 #ifndef __DMAP_H
 #define __DMAP_H
 
-#include <libdmapsharing/daap-connection.h>
 #include <libdmapsharing/daap-record.h>
 #include <libdmapsharing/daap-share.h>
 #include <libdmapsharing/dmap-connection.h>
@@ -13,7 +12,6 @@
 #include <libdmapsharing/dmap-record.h>
 #include <libdmapsharing/dmap-record-factory.h>
 #include <libdmapsharing/dmap-share.h>
-#include <libdmapsharing/dpap-connection.h>
 #include <libdmapsharing/dpap-record.h>
 #include <libdmapsharing/dpap-share.h>
 



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