summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/input/Makefile.am3
-rw-r--r--src/input/input_http.c93
2 files changed, 27 insertions, 69 deletions
diff --git a/src/input/Makefile.am b/src/input/Makefile.am
index 0abeaaeae..5de15d5c7 100644
--- a/src/input/Makefile.am
+++ b/src/input/Makefile.am
@@ -100,7 +100,8 @@ xineplug_inp_rtp_la_SOURCES = input_rtp.c net_buf_ctrl.c
xineplug_inp_rtp_la_LIBADD = $(XINE_LIB) $(NET_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL)
xineplug_inp_http_la_SOURCES = input_http.c net_buf_ctrl.c http_helper.c
-xineplug_inp_http_la_LIBADD = $(XINE_LIB) $(NET_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL)
+xineplug_inp_http_la_LIBADD = $(XINE_LIB) $(NET_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) $(AVUTIL_LIBS)
+xineplug_inp_http_la_CPPFLAGS = $(AM_CPPFLAGS) $(AVUTIL_CFLAGS)
xineplug_inp_pnm_la_SOURCES = input_pnm.c net_buf_ctrl.c pnm.c
xineplug_inp_pnm_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL)
diff --git a/src/input/input_http.c b/src/input/input_http.c
index f2e91c226..bc9a819bd 100644
--- a/src/input/input_http.c
+++ b/src/input/input_http.c
@@ -40,6 +40,8 @@
#include <sys/time.h>
+#include <base64.h>
+
#define LOG_MODULE "input_http"
#define LOG_VERBOSE
/*
@@ -228,61 +230,15 @@ static int _x_use_proxy(http_input_class_t *this, const char *host) {
return 1;
}
-static int http_plugin_basicauth (const char *user, const char *password, char* dest, int len) {
- static const char enctable[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
- char *tmp;
- char *sptr;
- char *dptr;
- int totlen;
- int enclen;
- int count;
-
- totlen = strlen (user) + 1;
- if(password != NULL)
- totlen += strlen (password);
-
- enclen = ((totlen + 2) / 3 ) * 4 + 1;
-
- if (len < enclen)
- return -1;
-
- tmp = malloc (totlen + 1);
- strcpy (tmp, user);
- strcat (tmp, ":");
- if (password != NULL)
- strcat (tmp, password);
-
- count = strlen(tmp);
- sptr = tmp;
- dptr = dest;
- while (count >= 3) {
- dptr[0] = enctable[(sptr[0] & 0xFC) >> 2];
- dptr[1] = enctable[((sptr[0] & 0x3) << 4) | ((sptr[1] & 0xF0) >> 4)];
- dptr[2] = enctable[((sptr[1] & 0x0F) << 2) | ((sptr[2] & 0xC0) >> 6)];
- dptr[3] = enctable[sptr[2] & 0x3F];
- count -= 3;
- sptr += 3;
- dptr += 4;
- }
-
- if (count > 0) {
- dptr[0] = enctable[(sptr[0] & 0xFC) >> 2];
- dptr[1] = enctable[(sptr[0] & 0x3) << 4];
- dptr[2] = '=';
-
- if (count > 1) {
- dptr[1] = enctable[((sptr[0] & 0x3) << 4) | ((sptr[1] & 0xF0) >> 4)];
- dptr[2] = enctable[(sptr[1] & 0x0F) << 2];
- }
-
- dptr[3] = '=';
- dptr += 4;
- }
-
- dptr[0] = '\0';
-
- free(tmp);
- return 0;
+static void http_plugin_basicauth (const char *user, const char *password, char** dest) {
+ const size_t totlen = strlen(user) + (password ? strlen(password) : 0) + 1;
+ const size_t enclen = ((totlen + 2) * 4 ) / 3 + 12;
+ char tmp[totlen];
+
+ snprintf(tmp, totlen, "%s:%s", user, password ? : "");
+
+ *dest = malloc(enclen);
+ av_base64_encode(*dest, enclen, tmp, totlen);
}
static int http_plugin_read_metainf (http_input_plugin_t *this) {
@@ -664,19 +620,16 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
int use_proxy;
int proxyport;
int mpegurl_redirect = 0;
- char auth[BUFSIZE];
- char proxyauth[BUFSIZE];
+ char *auth = NULL;
+ char *proxyauth = NULL;
use_proxy = this_class->proxyhost && strlen(this_class->proxyhost);
if (use_proxy) {
if (this_class->proxyuser && strlen(this_class->proxyuser)) {
- if (http_plugin_basicauth (this_class->proxyuser,
- this_class->proxypassword,
- proxyauth, BUFSIZE)) {
- _x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "proxy error", NULL);
- return 0;
- }
+ http_plugin_basicauth (this_class->proxyuser,
+ this_class->proxypassword,
+ &proxyauth);
}
}
@@ -692,10 +645,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
this->port = DEFAULT_HTTP_PORT;
if (this->user && strlen(this->user)) {
- if (http_plugin_basicauth (this->user, this->password, auth, BUFSIZE)) {
- _x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "basic auth error", NULL);
- return -1;
- }
+ http_plugin_basicauth (this->user, this->password, &auth);
}
if (this_class->proxyport == 0)
@@ -727,8 +677,11 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
this->curpos = 0;
- if (this->fh == -1)
+ if (this->fh == -1) {
+ free(proxyauth);
+ free(auth);
return -2;
+ }
{
uint32_t timeout, progress;
@@ -748,6 +701,8 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
if (res != XIO_READY) {
_x_message(this->stream, XINE_MSG_NETWORK_UNREACHABLE, this->mrl, NULL);
+ free(proxyauth);
+ free(auth);
return -3;
}
}
@@ -777,11 +732,13 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
snprintf (this->buf + buflen, BUFSIZE - buflen,
"Proxy-Authorization: Basic %s\015\012", proxyauth);
buflen = strlen(this->buf);
+ free(proxyauth); proxyauth = NULL;
}
if (this->user && strlen(this->user)) {
snprintf (this->buf + buflen, BUFSIZE - buflen,
"Authorization: Basic %s\015\012", auth);
buflen = strlen(this->buf);
+ free(auth); auth = NULL;
}
snprintf(this->buf + buflen, BUFSIZE - buflen,