mirror of
https://github.com/mpv-player/mpv
synced 2025-05-13 08:49:55 +02:00
stream/: delete base64_encode(), use libavutil av_base64_encode()
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32672 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
4f1b2d9b18
commit
db522b94e0
@ -41,6 +41,7 @@
|
|||||||
#include "libmpdemux/demuxer.h"
|
#include "libmpdemux/demuxer.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
|
#include "libavutil/base64.h"
|
||||||
|
|
||||||
extern int stream_cache_size;
|
extern int stream_cache_size;
|
||||||
extern int network_bandwidth;
|
extern int network_bandwidth;
|
||||||
@ -607,8 +608,8 @@ http_set_uri( HTTP_header_t *http_hdr, const char *uri ) {
|
|||||||
static int
|
static int
|
||||||
http_add_authentication( HTTP_header_t *http_hdr, const char *username, const char *password, const char *auth_str ) {
|
http_add_authentication( HTTP_header_t *http_hdr, const char *username, const char *password, const char *auth_str ) {
|
||||||
char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL;
|
char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL;
|
||||||
int encoded_len, pass_len=0, out_len;
|
int encoded_len, pass_len=0;
|
||||||
size_t auth_len;
|
size_t auth_len, usr_pass_len;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
if( http_hdr==NULL || username==NULL ) return -1;
|
if( http_hdr==NULL || username==NULL ) return -1;
|
||||||
|
|
||||||
@ -616,7 +617,8 @@ http_add_authentication( HTTP_header_t *http_hdr, const char *username, const ch
|
|||||||
pass_len = strlen(password);
|
pass_len = strlen(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
usr_pass = malloc(strlen(username)+pass_len+2);
|
usr_pass_len = strlen(username) + 1 + pass_len;
|
||||||
|
usr_pass = malloc(usr_pass_len + 1);
|
||||||
if( usr_pass==NULL ) {
|
if( usr_pass==NULL ) {
|
||||||
mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
|
mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
|
||||||
goto out;
|
goto out;
|
||||||
@ -624,21 +626,13 @@ http_add_authentication( HTTP_header_t *http_hdr, const char *username, const ch
|
|||||||
|
|
||||||
sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password );
|
sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password );
|
||||||
|
|
||||||
// Base 64 encode with at least 33% more data than the original size
|
encoded_len = AV_BASE64_SIZE(usr_pass_len);
|
||||||
encoded_len = strlen(usr_pass)*2;
|
|
||||||
b64_usr_pass = malloc(encoded_len);
|
b64_usr_pass = malloc(encoded_len);
|
||||||
if( b64_usr_pass==NULL ) {
|
if( b64_usr_pass==NULL ) {
|
||||||
mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
|
mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
av_base64_encode(b64_usr_pass, encoded_len, usr_pass, usr_pass_len);
|
||||||
out_len = base64_encode( usr_pass, strlen(usr_pass), b64_usr_pass, encoded_len);
|
|
||||||
if( out_len<0 ) {
|
|
||||||
mp_msg(MSGT_NETWORK,MSGL_FATAL,"Base64 out overflow\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
b64_usr_pass[out_len]='\0';
|
|
||||||
|
|
||||||
auth_len = encoded_len + 100;
|
auth_len = encoded_len + 100;
|
||||||
auth = malloc(auth_len);
|
auth = malloc(auth_len);
|
||||||
@ -693,57 +687,6 @@ http_debug_hdr( HTTP_header_t *http_hdr ) {
|
|||||||
mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- END ---\n");
|
mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- END ---\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
base64_encode(const void *enc, int encLen, char *out, int outMax) {
|
|
||||||
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
||||||
|
|
||||||
unsigned char *encBuf;
|
|
||||||
int outLen;
|
|
||||||
unsigned int bits;
|
|
||||||
unsigned int shift;
|
|
||||||
|
|
||||||
encBuf = (unsigned char*)enc;
|
|
||||||
outLen = 0;
|
|
||||||
bits = 0;
|
|
||||||
shift = 0;
|
|
||||||
outMax &= ~3;
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
if( encLen>0 ) {
|
|
||||||
// Shift in byte
|
|
||||||
bits <<= 8;
|
|
||||||
bits |= *encBuf;
|
|
||||||
shift += 8;
|
|
||||||
// Next byte
|
|
||||||
encBuf++;
|
|
||||||
encLen--;
|
|
||||||
} else if( shift>0 ) {
|
|
||||||
// Pad last bits to 6 bits - will end next loop
|
|
||||||
bits <<= 6 - shift;
|
|
||||||
shift = 6;
|
|
||||||
} else {
|
|
||||||
// As per RFC 2045, section 6.8,
|
|
||||||
// pad output as necessary: 0 to 2 '=' chars.
|
|
||||||
while( outLen & 3 ){
|
|
||||||
*out++ = '=';
|
|
||||||
outLen++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return outLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode 6 bit segments
|
|
||||||
while( shift>=6 ) {
|
|
||||||
if (outLen >= outMax)
|
|
||||||
return -1;
|
|
||||||
shift -= 6;
|
|
||||||
*out = b64[ (bits >> shift) & 0x3F ];
|
|
||||||
out++;
|
|
||||||
outLen++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_icy_metadata(HTTP_header_t *http_hdr) {
|
static void print_icy_metadata(HTTP_header_t *http_hdr) {
|
||||||
const char *field_data;
|
const char *field_data;
|
||||||
// note: I skip icy-notice1 and 2, as they contain html <BR>
|
// note: I skip icy-notice1 and 2, as they contain html <BR>
|
||||||
|
@ -67,5 +67,4 @@ int http_add_basic_proxy_authentication( HTTP_header_t *http_hdr, const char *u
|
|||||||
|
|
||||||
void http_debug_hdr( HTTP_header_t *http_hdr );
|
void http_debug_hdr( HTTP_header_t *http_hdr );
|
||||||
|
|
||||||
int base64_encode(const void *enc, int encLen, char *out, int outMax);
|
|
||||||
#endif /* MPLAYER_HTTP_H */
|
#endif /* MPLAYER_HTTP_H */
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "xbuffer.h"
|
#include "xbuffer.h"
|
||||||
#include "libavutil/md5.h"
|
#include "libavutil/md5.h"
|
||||||
#include "ffmpeg_files/intreadwrite.h"
|
#include "ffmpeg_files/intreadwrite.h"
|
||||||
|
#include "libavutil/base64.h"
|
||||||
#include "stream/http.h"
|
#include "stream/http.h"
|
||||||
#include "mp_msg.h"
|
#include "mp_msg.h"
|
||||||
|
|
||||||
@ -491,18 +492,14 @@ rtsp_send_describe:
|
|||||||
mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: authenticator not supported (%s)\n", authreq);
|
mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: authenticator not supported (%s)\n", authreq);
|
||||||
goto autherr;
|
goto autherr;
|
||||||
}
|
}
|
||||||
authlen = strlen(username) + (password ? strlen(password) : 0) + 2;
|
authlen = strlen(username) + 1 + (password ? strlen(password) : 0);
|
||||||
authstr = malloc(authlen);
|
authstr = malloc(authlen + 1);
|
||||||
sprintf(authstr, "%s:%s", username, password ? password : "");
|
sprintf(authstr, "%s:%s", username, password ? password : "");
|
||||||
authfield = malloc(authlen*2+22);
|
b64_authlen = AV_BASE64_SIZE(authlen);
|
||||||
|
authfield = malloc(21 + b64_authlen);
|
||||||
strcpy(authfield, "Authorization: Basic ");
|
strcpy(authfield, "Authorization: Basic ");
|
||||||
b64_authlen = base64_encode(authstr, authlen, authfield+21, authlen*2);
|
av_base64_encode(authfield + 21, b64_authlen, authstr, authlen);
|
||||||
free(authstr);
|
free(authstr);
|
||||||
if (b64_authlen < 0) {
|
|
||||||
mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: base64 output overflow, this should never happen\n");
|
|
||||||
goto autherr;
|
|
||||||
}
|
|
||||||
authfield[b64_authlen+21] = 0;
|
|
||||||
goto rtsp_send_describe;
|
goto rtsp_send_describe;
|
||||||
}
|
}
|
||||||
autherr:
|
autherr:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user