Commit a3180180 authored by W. Michael Petullo's avatar W. Michael Petullo
Browse files

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's avatarW. Michael Petullo <mike@flyn.org>
parent 6b84b6ed
......@@ -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
......
/*
* Copyright (C) 2004,2005 Charles Schmidt <cschmidt2@emich.edu>
* Copyright (C) 2006 INDT
* Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <libdmapsharing/dmap-priv.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <math.h>
#include <string.h>
#include <libsoup/soup.h>
#include <libdmapsharing/dmap.h>
#include <libdmapsharing/dmap-md5.h>
#define DAAP_USER_AGENT "iTunes/4.6 (Macintosh; PPC)"
static SoupMessage *
daap_connection_build_message (DMAPConnection *connection,
const char *path,
gboolean need_hash,
gdouble version,
gint req_id,
gboolean send_close);
G_DEFINE_TYPE (DAAPConnection, daap_connection, TYPE_DMAP_CONNECTION)
static void
daap_connection_class_init (DAAPConnectionClass *klass)
{
DMAPConnectionClass *dmap_connection_class = (DMAPConnectionClass *) klass;
dmap_connection_class->build_message = daap_connection_build_message;
}
static void
daap_connection_init (DAAPConnection *self)
{
}
DAAPConnection *
daap_connection_new (const gchar *name,
const gchar *host,
gint port,
gboolean password_protected,
DMAPDb *db,
DMAPRecordFactory *factory)
{
return DAAP_CONNECTION (g_object_new (TYPE_DAAP_CONNECTION,
"name", name,
"host", host,
"port", port,
"password-protected", password_protected,
"db", db,
"factory", factory,
"need-revision-number", TRUE,
NULL));
}
static SoupMessage *
daap_connection_build_message (DMAPConnection *connection,
const char *path,
gboolean need_hash,
gdouble version,
gint req_id,
gboolean send_close)
{
/* FIXME:
DMAPConnectionPrivate *priv = connection->priv;
*/
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");
/* FIXME:
if (priv->password_protected) {
char *h;
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);
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;
}
/*
* Copyright (C) 2004,2005 Charles Schmidt <cschmidt2@emich.edu>
* Copyright (C) 2006 INDT
* Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*
*/
#ifndef __DAAP_CONNECTION_H__
#define __DAAP_CONNECTION_H__
#include <glib.h>
#include <glib-object.h>
#include <libdmapsharing/dmap-connection.h>
G_BEGIN_DECLS
/**
* TYPE_DAAP_CONNECTION:
*
* The type for #DAAPConnection.
*/
#define TYPE_DAAP_CONNECTION (daap_connection_get_type ())
/**
* DAAP_CONNECTION:
* @o: Object which is subject to casting.
*
* Casts a #DAAPConnection or derived pointer into a (DAAPConnection *) pointer.
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*/
#define DAAP_CONNECTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_DAAP_CONNECTION, DAAPConnection))
/**
* DAAP_CONNECTION_CLASS:
* @k: a valid #DAAPConnectionClass
*
* Casts a derived #DAAPConnectionClass structure into a #DAAPConnectionClass
* structure.
*/
#define DAAP_CONNECTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TYPE_DAAP_CONNECTION, DAAPConnectionClass))
/**
* IS_DAAP_CONNECTION:
* @o: Instance to check for being a %TYPE_DAAP_CONNECTION.
*
* Checks whether a valid #GTypeInstance pointer is of type %TYPE_DAAP_CONNECTION.
*/
#define IS_DAAP_CONNECTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_DAAP_CONNECTION))
/**
* IS_DAAP_CONNECTION_CLASS:
* @k: a #DAAPConnectionClass
*
* Checks whether @k "is a" valid #DAAPConnectionClass structure of type
* %DAAP_CONNECTION or derived.
*/
#define IS_DAAP_CONNECTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_DAAP_CONNECTION))
/**
* DAAP_CONNECTION_GET_CLASS:
* @o: a #DAAPConnection instance.
*
* Get the class structure associated to a #DAAPConnection instance.
*
* Returns: pointer to object class structure.
*/
#define DAAP_CONNECTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_DAAP_CONNECTION, DAAPConnectionClass))
typedef struct _DAAPConnection DAAPConnection;
typedef struct _DAAPConnectionClass DAAPConnectionClass;
typedef struct _DAAPConnectionPrivate DAAPConnectionPrivate;
struct _DAAPConnectionClass {
DMAPConnectionClass parent;
};
struct _DAAPConnection {
DMAPConnection parent;
};
GType daap_connection_get_type (void);
DAAPConnection *daap_connection_new (const gchar *name,
const gchar *host,
gint port,
gboolean password_protected,
DMAPDb *db,
DMAPRecordFactory *factory);
G_END_DECLS
#endif
......@@ -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;
......
......@@ -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);
}
......
#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>
......
/*
* Copyright (C) 2004,2005 Charles Schmidt <cschmidt2@emich.edu>
* Copyright (C) 2006 INDT
* Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <math.h>
#include <string.h>
#include <libsoup/soup.h>
#include "dpap-connection.h"
#include "dmap-md5.h"
#include "dmap-structure.h"
#define DPAP_USER_AGENT "iPhoto/4.01 (Macintosh; PPC)"
static SoupMessage *
dpap_connection_build_message (DMAPConnection *connection,
const char *path,
gboolean need_hash,
gdouble version,
gint req_id,
gboolean send_close);
G_DEFINE_TYPE (DPAPConnection, dpap_connection, TYPE_DMAP_CONNECTION)
static void
dpap_connection_class_init (DPAPConnectionClass *klass)
{
DMAPConnectionClass *dmap_connection_class = (DMAPConnectionClass *) klass;
dmap_connection_class->build_message = dpap_connection_build_message;
}
static void
dpap_connection_init (DPAPConnection *self)
{
}
DPAPConnection *
dpap_connection_new (const gchar *name,
const gchar *host,
gint port,
gboolean password_protected,
DMAPDb *db,
DMAPRecordFactory *factory)
{
return DPAP_CONNECTION (g_object_new (TYPE_DPAP_CONNECTION,
"name", name,
"host", host,
"port", port,
"password-protected", password_protected,
"db", db,
"factory", factory,
"need-revision-number", FALSE,
NULL));
}
static SoupMessage *
dpap_connection_build_message (DMAPConnection *connection,
const char *path,
gboolean need_hash,
gdouble version,
gint req_id,
gboolean 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) {
soup_uri_free (base_uri);
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");
/* FIXME:
if (priv->password_protected) {
char *h;
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);
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 (base_uri);
soup_uri_free (uri);
return message;
}
/*
* Copyright (C) 2004,2005 Charles Schmidt <cschmidt2@emich.edu>
* Copyright (C) 2006 INDT
* Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*
*/
#ifndef __DPAP_CONNECTION_H__
#define __DPAP_CONNECTION_H__
#include <glib.h>
#include <glib-object.h>
#include <libdmapsharing/dmap-connection.h>
G_BEGIN_DECLS
/**
* TYPE_DPAP_CONNECTION:
*
* The type for #DPAPConnection.
*/
#define TYPE_DPAP_CONNECTION (dpap_connection_get_type ())
/**
* DPAP_CONNECTION:
* @o: Object which is subject to casting.
*
* Casts a #DPAPConnection or derived pointer into a (DPAPConnection*) pointer.
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*/
#define DPAP_CONNECTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_DPAP_CONNECTION, DPAPConnection))
/**
* DPAP_CONNECTION_CLASS:
* @k: a valid #DPAPConnectionClass
*
* Casts a derived #DPAPConnectionClass structure into a #DPAPConnectionClass
* structure.
*/
#define DPAP_CONNECTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TYPE_DPAP_CONNECTION, DPAPConnectionClass))
/**
* IS_DPAP_CONNECTION: