[MPlayer-cvslog] r32672 - in trunk/stream: http.c http.h realrtsp/real.c

cboesch subversion at mplayerhq.hu
Fri Dec 3 20:52:11 CET 2010


Author: cboesch
Date: Fri Dec  3 20:52:10 2010
New Revision: 32672

Log:
Drop MPlayer base64_encode for av_base64_encode.

Modified:
   trunk/stream/http.c
   trunk/stream/http.h
   trunk/stream/realrtsp/real.c

Modified: trunk/stream/http.c
==============================================================================
--- trunk/stream/http.c	Fri Dec  3 18:50:26 2010	(r32671)
+++ trunk/stream/http.c	Fri Dec  3 20:52:10 2010	(r32672)
@@ -42,6 +42,7 @@
 #include "network.h"
 #include "help_mp.h"
 
+#include "libavutil/base64.h"
 
 typedef struct {
   unsigned metaint;
@@ -605,8 +606,8 @@ http_set_uri( HTTP_header_t *http_hdr, c
 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 @@ http_add_authentication( HTTP_header_t *
 		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 @@ http_add_authentication( HTTP_header_t *
 
 	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 @@ http_debug_hdr( HTTP_header_t *http_hdr 
 	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>

Modified: trunk/stream/http.h
==============================================================================
--- trunk/stream/http.h	Fri Dec  3 18:50:26 2010	(r32671)
+++ trunk/stream/http.h	Fri Dec  3 20:52:10 2010	(r32672)
@@ -67,5 +67,4 @@ int		http_add_basic_proxy_authentication
 
 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 */

Modified: trunk/stream/realrtsp/real.c
==============================================================================
--- trunk/stream/realrtsp/real.c	Fri Dec  3 18:50:26 2010	(r32671)
+++ trunk/stream/realrtsp/real.c	Fri Dec  3 20:52:10 2010	(r32672)
@@ -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 @@ rtsp_send_describe:
       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:


More information about the MPlayer-cvslog mailing list