From 8292c2472059f33772d4dde3fb0e07884797278c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 19 Dec 2007 01:16:34 +0100 Subject: Rewrite http_plugin_basicauth to use libavutil's base64 encoding. --- src/input/input_http.c | 93 ++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 68 deletions(-) (limited to 'src/input/input_http.c') 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 +#include + #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, -- cgit v1.2.3 From d23cc6dbac6f2b212d99453fddc0f20ccd178ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 19 Dec 2007 01:19:54 +0100 Subject: Only calculate proxyauth and auth when they are going to be used. --- src/input/input_http.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'src/input/input_http.c') diff --git a/src/input/input_http.c b/src/input/input_http.c index bc9a819bd..96841593f 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -620,20 +620,9 @@ static int http_plugin_open (input_plugin_t *this_gen ) { int use_proxy; int proxyport; int mpegurl_redirect = 0; - 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)) { - http_plugin_basicauth (this_class->proxyuser, - this_class->proxypassword, - &proxyauth); - } - } - - if (!_x_parse_url(this->mrl, &this->proto, &this->host, &this->port, &this->user, &this->password, &this->uri)) { _x_message(this->stream, XINE_MSG_GENERAL_WARNING, "malformed url", NULL); @@ -644,10 +633,6 @@ static int http_plugin_open (input_plugin_t *this_gen ) { if (this->port == 0) this->port = DEFAULT_HTTP_PORT; - if (this->user && strlen(this->user)) { - http_plugin_basicauth (this->user, this->password, &auth); - } - if (this_class->proxyport == 0) proxyport = DEFAULT_HTTP_PORT; else @@ -678,8 +663,6 @@ static int http_plugin_open (input_plugin_t *this_gen ) { this->curpos = 0; if (this->fh == -1) { - free(proxyauth); - free(auth); return -2; } @@ -701,8 +684,6 @@ 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; } } @@ -728,17 +709,24 @@ static int http_plugin_open (input_plugin_t *this_gen ) { this->host); buflen = strlen(this->buf); - if (this_class->proxyuser && strlen(this_class->proxyuser)) { + if (use_proxy && this_class->proxyuser && strlen(this_class->proxyuser)) { + char *proxyauth; + http_plugin_basicauth (this_class->proxyuser, this_class->proxypassword, + &proxyauth); + snprintf (this->buf + buflen, BUFSIZE - buflen, "Proxy-Authorization: Basic %s\015\012", proxyauth); buflen = strlen(this->buf); - free(proxyauth); proxyauth = NULL; + free(proxyauth); } if (this->user && strlen(this->user)) { + char *auth; + http_plugin_basicauth (this->user, this->password, &auth); + snprintf (this->buf + buflen, BUFSIZE - buflen, "Authorization: Basic %s\015\012", auth); buflen = strlen(this->buf); - free(auth); auth = NULL; + free(auth); } snprintf(this->buf + buflen, BUFSIZE - buflen, -- cgit v1.2.3 From 19357940a57c565ebe319729bd08d6e4800aff5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 1 Mar 2008 04:00:18 +0100 Subject: Update to the new FFmpeg's include directory. This also allows to remove the comment stating the includes come from libavutil, as it's now explicit. --- src/input/input_http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input/input_http.c') diff --git a/src/input/input_http.c b/src/input/input_http.c index dd9798bb1..a9bca910b 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -40,7 +40,7 @@ #include -#include +#include #define LOG_MODULE "input_http" #define LOG_VERBOSE -- cgit v1.2.3 From 8063ffb8c0b354d54834ba53b22003dac481de2c Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 9 Apr 2008 19:10:58 +0100 Subject: Compilation fixes, mostly ffmpeg-related, and linkage fixes. Tests done on amd64 with ffmpeg 0.svn20080206 from Debian experimental. libavcodec 51.50.0, libavutil 49.6.0, libpostproc 51.1.0 --- src/input/input_http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input/input_http.c') diff --git a/src/input/input_http.c b/src/input/input_http.c index a9bca910b..dd9798bb1 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -40,7 +40,7 @@ #include -#include +#include #define LOG_MODULE "input_http" #define LOG_VERBOSE -- cgit v1.2.3 From f3974e74f2f1548bf07604fddfa60cf75b2fda57 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 20 Jun 2008 15:19:35 +0100 Subject: Off-by-one in the HTTP basic auth encoding function. --- src/input/input_http.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/input/input_http.c') diff --git a/src/input/input_http.c b/src/input/input_http.c index dd9798bb1..a5a25f0af 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -232,9 +232,9 @@ static int _x_use_proxy(http_input_class_t *this, const char *host) { 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]; + char tmp[totlen + 1]; - snprintf(tmp, totlen, "%s:%s", user, password ? : ""); + snprintf(tmp, totlen + 1, "%s:%s", user, password ? : ""); *dest = malloc(enclen); av_base64_encode(*dest, enclen, tmp, totlen); -- cgit v1.2.3