Mercurial > mplayer.hg
changeset 32585:be61988fb5c4
Drop MPlayer base64_encode for av_base64_encode.
author | cboesch |
---|---|
date | Fri, 03 Dec 2010 19:52:10 +0000 |
parents | bec4b99cda2a |
children | 31a65f4ca3bb |
files | stream/http.c stream/http.h stream/realrtsp/real.c |
diffstat | 3 files changed, 13 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/stream/http.c Fri Dec 03 17:50:26 2010 +0000 +++ b/stream/http.c Fri Dec 03 19:52:10 2010 +0000 @@ -42,6 +42,7 @@ #include "network.h" #include "help_mp.h" +#include "libavutil/base64.h" typedef struct { unsigned metaint; @@ -605,8 +606,8 @@ static int 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; - int encoded_len, pass_len=0, out_len; - size_t auth_len; + int encoded_len, pass_len=0; + size_t auth_len, usr_pass_len; int res = -1; if( http_hdr==NULL || username==NULL ) return -1; @@ -614,7 +615,8 @@ 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 ) { mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); goto out; @@ -622,21 +624,13 @@ sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password ); - // Base 64 encode with at least 33% more data than the original size - encoded_len = strlen(usr_pass)*2; + encoded_len = AV_BASE64_SIZE(usr_pass_len); b64_usr_pass = malloc(encoded_len); if( b64_usr_pass==NULL ) { mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); goto out; } - - 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'; + av_base64_encode(b64_usr_pass, encoded_len, usr_pass, usr_pass_len); auth_len = encoded_len + 100; auth = malloc(auth_len); @@ -691,57 +685,6 @@ 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) { const char *field_data; // note: I skip icy-notice1 and 2, as they contain html <BR>
--- a/stream/http.h Fri Dec 03 17:50:26 2010 +0000 +++ b/stream/http.h Fri Dec 03 19:52:10 2010 +0000 @@ -67,5 +67,4 @@ 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 */
--- a/stream/realrtsp/real.c Fri Dec 03 17:50:26 2010 +0000 +++ b/stream/realrtsp/real.c Fri Dec 03 19:52:10 2010 +0000 @@ -38,6 +38,7 @@ #include "xbuffer.h" #include "libavutil/md5.h" #include "libavutil/intreadwrite.h" +#include "libavutil/base64.h" #include "stream/http.h" #include "mp_msg.h" @@ -491,18 +492,14 @@ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: authenticator not supported (%s)\n", authreq); goto autherr; } - authlen = strlen(username) + (password ? strlen(password) : 0) + 2; - authstr = malloc(authlen); + authlen = strlen(username) + 1 + (password ? strlen(password) : 0); + authstr = malloc(authlen + 1); 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 "); - b64_authlen = base64_encode(authstr, authlen, authfield+21, authlen*2); + av_base64_encode(authfield + 21, b64_authlen, authstr, authlen); 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; } autherr: