[libdmapsharing] Remove redundant code



commit 25b902c4bd2a7921d5b24ec05bf54f2db3a32b08
Author: W. Michael Petullo <mike flyn org>
Date:   Thu Jul 22 11:39:22 2010 -0500

    Remove redundant code
    
    Remove redundancy between dmap_connection_build_message() and
    dmap_connection_build_message().
    Signed-off-by: W. Michael Petullo <mike flyn org>

 ChangeLog                        |    5 +++
 distro/libdmapsharing.spec       |    2 +-
 libdmapsharing/dmap-connection.c |   70 ++++++++++---------------------------
 3 files changed, 25 insertions(+), 52 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b950dcb..3d65083 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+22 July 2010 W. Michael Petullo <mike flyn org>
+
+	* Remove redundancy between dmap_connection_build_message()
+	and dmap_connection_build_message().
+
 04 June 2010 W. Michael Petullo <mike flyn org>
 
 	* Add dmap_db_add_with_id() to DMAPDb interface.
diff --git a/distro/libdmapsharing.spec b/distro/libdmapsharing.spec
index c485450..c5cb79f 100644
--- a/distro/libdmapsharing.spec
+++ b/distro/libdmapsharing.spec
@@ -1,5 +1,5 @@
 Name: libdmapsharing
-Version: 1.9.0.19
+Version: 2.0.0
 Release: 1%{?dist}
 License: LGPLv2+
 Source: http://downloads.sourceforge.net/%name/%{name}-%{version}.tar.gz
diff --git a/libdmapsharing/dmap-connection.c b/libdmapsharing/dmap-connection.c
index 34e43be..2017716 100644
--- a/libdmapsharing/dmap-connection.c
+++ b/libdmapsharing/dmap-connection.c
@@ -362,6 +362,7 @@ dmap_connection_build_message (DMAPConnection *connection,
 	SoupMessage *message = NULL;
 	SoupURI *base_uri = NULL;
 	SoupURI *uri = NULL;
+	char *uri_str = NULL;
 
 	g_object_get (connection, "base-uri", &base_uri, NULL);
 	if (base_uri == NULL) {
@@ -375,52 +376,14 @@ dmap_connection_build_message (DMAPConnection *connection,
 
 	message = soup_message_new_from_uri (SOUP_METHOD_GET, uri);
 
-	soup_message_headers_append (message->request_headers, "User-Agent", DMAP_USER_AGENT);
-	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");
-	}
+	/* FIXME: only set Client-DAAP-Validation if need_hash? */
+	/* FIXME: only set Connection if send_close? */
+	uri_str = soup_uri_to_string (uri, FALSE);
+	message->request_headers =
+		dmap_connection_get_headers (connection, uri_str);
 
 	soup_uri_free (uri);
+	g_free (uri_str);
 
 	return message;
 }
@@ -1685,15 +1648,20 @@ dmap_connection_get_headers (DMAPConnection *connection,
 		char *user_pass;
 		char *token;
 
-		user_pass = g_strdup_printf ("%s:%s", priv->username, priv->password);
-		token = g_base64_encode ((guchar *)user_pass, strlen (user_pass));
-		h = g_strdup_printf ("Basic %s", token);
+		if (priv->username == NULL || priv->password == NULL) {
+			g_debug ("No username or no password provided");
+		} else {
 
-		g_free (token);
-		g_free (user_pass);
+			user_pass = g_strdup_printf ("%s:%s", priv->username, priv->password);
+			token = g_base64_encode ((guchar *)user_pass, strlen (user_pass));
+			h = g_strdup_printf ("Basic %s", token);
 
-		soup_message_headers_append (headers, "Authentication", h);
-		g_free (h);
+			g_free (token);
+			g_free (user_pass);
+
+			soup_message_headers_append (headers, "Authentication", h);
+			g_free (h);
+		}
 	}
 
 	return headers;



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