aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputStream_http.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-07-17 13:41:31 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-07-17 13:41:31 +0000
commit3edf33154308eafe212a0d536612b030e95ffc70 (patch)
tree1e251fc63842bef425c69f6b3ef852f1afe7b27d /src/inputStream_http.c
parenta0227e806216f6e6795155b6e00ecc40bb82809e (diff)
downloadmpd-3edf33154308eafe212a0d536612b030e95ffc70.tar.gz
mpd-3edf33154308eafe212a0d536612b030e95ffc70.tar.xz
mpd-3edf33154308eafe212a0d536612b030e95ffc70.zip
added http authentication: http://user:passwd@host/music
git-svn-id: https://svn.musicpd.org/mpd/trunk@1872 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/inputStream_http.c')
-rw-r--r--src/inputStream_http.c61
1 files changed, 54 insertions, 7 deletions
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index fc274800b..5330dfe62 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -63,6 +63,7 @@ typedef struct _InputStreemHTTPData {
char * proxyHost;
int proxyPort;
char * proxyAuth;
+ char * httpAuth;
} InputStreamHTTPData;
void inputStream_initHttp() {
@@ -154,9 +155,7 @@ static char * base64Dup(char * s) {
return ret;
}
-#define PROXY_AUTH_HEADER "Proxy-Authorization: Basic "
-
-static char * proxyAuthString(char * user, char * password) {
+static char * authString(char * header, char * user, char * password) {
char * ret = NULL;
int templen;
char * temp;
@@ -172,8 +171,8 @@ static char * proxyAuthString(char * user, char * password) {
temp64 = base64Dup(temp);
free(temp);
- ret = malloc(strlen(temp64)+strlen(PROXY_AUTH_HEADER)+3);
- strcpy(ret, PROXY_AUTH_HEADER);
+ ret = malloc(strlen(temp64)+strlen(header)+3);
+ strcpy(ret, header);
strcat(ret, temp64);
strcat(ret, "\r\n");
free(temp64);
@@ -181,6 +180,12 @@ static char * proxyAuthString(char * user, char * password) {
return ret;
}
+#define PROXY_AUTH_HEADER "Proxy-Authorization: Basic "
+#define HTTP_AUTH_HEADER "Authorization: Basic "
+
+#define proxyAuthString(x, y) authString(PROXY_AUTH_HEADER, x, y)
+#define httpAuthString(x, y) authString(HTTP_AUTH_HEADER, x, y)
+
static InputStreamHTTPData * newInputStreamHTTPData() {
InputStreamHTTPData * ret = malloc(sizeof(InputStreamHTTPData));
@@ -198,6 +203,7 @@ static InputStreamHTTPData * newInputStreamHTTPData() {
ret->proxyAuth = NULL;
}
+ ret->httpAuth = NULL;
ret->host = NULL;
ret->path = NULL;
ret->port = 80;
@@ -214,6 +220,7 @@ static void freeInputStreamHTTPData(InputStreamHTTPData * data) {
if(data->host) free(data->host);
if(data->path) free(data->path);
if(data->proxyAuth) free(data->proxyAuth);
+ if(data->httpAuth) free(data->httpAuth);
free(data);
}
@@ -222,14 +229,52 @@ static int parseUrl(InputStreamHTTPData * data, char * url) {
char * temp;
char * colon;
char * slash;
+ char * at;
int len;
if(strncmp("http://",url,strlen("http://"))!=0) return -1;
temp = url+strlen("http://");
- slash = strchr(temp, '/');
colon = strchr(temp, ':');
+ at = strchr(temp, '@');
+
+ if(data->httpAuth) {
+ free(data->httpAuth);
+ data->httpAuth = NULL;
+ }
+
+ if(at) {
+ char * user;
+ char * passwd;
+
+ if(colon && colon < at) {
+ user = malloc(colon-temp+1);
+ strncpy(user, temp, colon-temp);
+ user[colon-temp] = '\0';
+
+ passwd = malloc(at-colon);
+ strncpy(passwd, colon+1, at-colon-1);
+ passwd[at-colon-1] = '\0';
+ }
+ else {
+ user = malloc(at-temp+1);
+ strncpy(user, temp, colon-temp);
+ user[colon-temp] = '\0';
+
+ passwd = strdup("");
+ }
+
+ data->httpAuth = httpAuthString(user, passwd);
+
+ free(user);
+ free(passwd);
+
+ temp = at+1;
+ colon = strchr(temp, ':');
+ }
+
+ slash = strchr(temp, '/');
if(slash && colon && slash <= colon) return -1;
@@ -390,7 +435,9 @@ static int finishHTTPInit(InputStream * inStream) {
data->path, data->host, "httpTest", "0.0.0",
/*inStream->offset,*/
- data->proxyAuth ? data->proxyAuth : "" );
+ data->proxyAuth ? data->proxyAuth :
+ (data->httpAuth ? data->httpAuth : "")
+ );
ret = write(data->sock, request, strlen(request));
if(ret!=strlen(request)) {