Commit 3609de86 authored by Max Kellermann's avatar Max Kellermann

http: use libcurl

MPD's HTTP client code has always been broken, no matter how effort was put into fixing it. Replace it with libcurl, which is known to be quite stable. This adds a fat library dependency, but only for people who need streaming.
parent 6b09e4da
......@@ -70,6 +70,10 @@ For Zeroconf support.
libsamplerate - http://www.mega-nerd.com/SRC/
For advanced samplerate conversions.
libcurl - http://curl.haxx.se/
For playing HTTP streams.
Download
--------
......
......@@ -103,6 +103,17 @@ AC_ARG_ENABLE(un,
dnl
dnl input options
dnl
AC_ARG_ENABLE(curl,
AS_HELP_STRING([--disable-curl],
[enable support obtaining song data via HTTP (default: enable)]),
[enable_curl=$enableval],
[enable_curl=yes])
dnl
dnl audio output plugins
dnl
......@@ -316,6 +327,13 @@ case $host in
enable_osx=yes ;;
esac
if test x$enable_curl = xyes; then
PKG_CHECK_MODULES(CURL, [libcurl],
AC_DEFINE(HAVE_CURL, 1, [Define when libcurl is used for HTTP streaming]),
enable_curl=no)
fi
AM_CONDITIONAL(HAVE_CURL, test x$enable_curl = xyes)
if test x$enable_shout_ogg = xyes || x$enable_shout_mp3 = xyes; then
enable_shout=yes
PKG_CHECK_MODULES([SHOUT], [shout],
......
......@@ -49,8 +49,6 @@ mpd_headers = \
decoder/_ogg_common.h \
inputStream.h \
inputStream_file.h \
inputStream_http.h \
inputStream_http_auth.h \
client.h \
list.h \
dlist.h \
......@@ -132,7 +130,6 @@ mpd_SOURCES = \
decoder_list.c \
inputStream.c \
inputStream_file.c \
inputStream_http.c \
client.c \
ioops.c \
list.c \
......@@ -246,8 +243,14 @@ mpd_SOURCES += zeroconf.c
endif
if HAVE_CURL
mpd_SOURCES += input_curl.c
endif
mpd_CFLAGS = $(MPD_CFLAGS)
mpd_CPPFLAGS = \
$(CURL_CFLAGS) \
$(AO_CFLAGS) $(ALSA_CFLAGS) \
$(SHOUT_CFLAGS) \
$(OGGVORBIS_CFLAGS) $(VORBISENC_CFLAGS) \
......@@ -258,6 +261,7 @@ mpd_CPPFLAGS = \
$(FFMPEG_CFLAGS) \
$(GLIB_CFLAGS)
mpd_LDADD = $(MPD_LIBS) \
$(CURL_LIBS) \
$(AO_LIBS) $(ALSA_LIBS) \
$(SHOUT_LIBS) \
$(OGGVORBIS_LIBS) $(VORBISENC_LIBS) $(FLAC_LIBS) \
......
......@@ -17,20 +17,29 @@
*/
#include "inputStream.h"
#include "config.h"
#include "inputStream_file.h"
#include "inputStream_http.h"
#ifdef HAVE_CURL
#include "input_curl.h"
#endif
#include <stdlib.h>
void initInputStream(void)
{
inputStream_initFile();
inputStream_initHttp();
#ifdef HAVE_CURL
input_curl_global_init();
#endif
}
void input_stream_global_finish(void)
{
#ifdef HAVE_CURL
input_curl_global_finish();
#endif
}
int openInputStream(struct input_stream *inStream, char *url)
......@@ -46,8 +55,11 @@ int openInputStream(struct input_stream *inStream, char *url)
if (inputStream_fileOpen(inStream, url) == 0)
return 0;
if (inputStream_httpOpen(inStream, url) == 0)
#ifdef HAVE_CURL
if (input_curl_open(inStream, url))
return 0;
#endif
return -1;
}
......
/* the Music Player Daemon (MPD)
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* This file is only included by inputStream_http.c */
#ifndef INPUT_STREAM_HTTP_AUTH_H
#define INPUT_STREAM_HTTP_AUTH_H
#include "utils.h"
#include <string.h>
/* base64 code taken from xmms */
#define BASE64_LENGTH(len) (4 * (((len) + 2) / 3))
static char *base64dup(char *s)
{
int i;
int len = strlen(s);
char *ret = xcalloc(BASE64_LENGTH(len) + 1, 1);
unsigned char *p = (unsigned char *)ret;
static const char tbl[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
/* Transform the 3x8 bits to 4x6 bits, as required by base64. */
for (i = 0; i < len; i += 3) {
*p++ = tbl[s[0] >> 2];
*p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
*p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
*p++ = tbl[s[2] & 0x3f];
s += 3;
}
/* Pad the result if necessary... */
if (i == len + 1)
*(p - 1) = '=';
else if (i == len + 2)
*(p - 1) = *(p - 2) = '=';
/* ...and zero-terminate it. */
*p = '\0';
return ret;
}
static char *auth_string(const char *header,
const char *user, const char *password)
{
char *ret = NULL;
int templen;
char *temp;
char *temp64;
if (!user || !password)
return NULL;
templen = strlen(user) + strlen(password) + 2;
temp = xmalloc(templen);
strcpy(temp, user);
strcat(temp, ":");
strcat(temp, password);
temp64 = base64dup(temp);
free(temp);
ret = xmalloc(strlen(temp64) + strlen(header) + 3);
strcpy(ret, header);
strcat(ret, temp64);
strcat(ret, "\r\n");
free(temp64);
return ret;
}
#define PROXY_AUTH_HEADER "Proxy-Authorization: Basic "
#define HTTP_AUTH_HEADER "Authorization: Basic "
#define proxy_auth_string(x, y) auth_string(PROXY_AUTH_HEADER, x, y)
#define http_auth_string(x, y) auth_string(HTTP_AUTH_HEADER, x, y)
#endif /* INPUT_STREAM_HTTP_AUTH_H */
/* the Music Player Daemon (MPD)
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
......@@ -16,23 +16,17 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef INPUT_STREAM_HTTP_H
#define INPUT_STREAM_HTTP_H
#ifndef MPD_INPUT_CURL_H
#define MPD_INPUT_CURL_H
#include "inputStream.h"
#include <stdbool.h>
void inputStream_initHttp(void);
struct input_stream;
int inputStream_httpOpen(InputStream * inStream, char *filename);
void input_curl_global_init(void);
int inputStream_httpSeek(InputStream * inStream, long offset, int whence);
void input_curl_global_finish(void);
size_t inputStream_httpRead(InputStream * inStream, void *ptr, size_t size);
int inputStream_httpClose(InputStream * inStream);
int inputStream_httpAtEOF(InputStream * inStream);
int inputStream_httpBuffer(InputStream * inStream);
bool input_curl_open(struct input_stream *is, char *url);
#endif
......@@ -27,7 +27,9 @@
#include "os_compat.h"
static const char *remoteUrlPrefixes[] = {
#ifdef HAVE_CURL
"http://",
#endif
NULL
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment