[MPlayer-dev-eng] http stream basic auth base64_encode() fix

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Tue Feb 28 22:13:28 CET 2006


Hi,
On Tue, Feb 28, 2006 at 12:15:30PM -0500, Jeff D'Angelo wrote:
> So that it conforms to RFC 2045:
> 
> <http://jeffdangelo.org/patches/>
> MPlayer-1.0pre7try2.http_basic_auth_base64_encode.patch
> MPlayer-cvs-main-20060228.http_basic_auth_base64_encode.patch

I would prefer this way of fixing it (see attached patch).

> Tested successfully against an Icecast 2.2.0 server (Otto Audio Jukebox).
> 
> Let me know if you need anything else.

Yes, could you test the empty password case? You never know what the
server might expect in that case *g*

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/http.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/http.c,v
retrieving revision 1.34
diff -u -r1.34 http.c
--- libmpdemux/http.c	9 Feb 2006 14:07:57 -0000	1.34
+++ libmpdemux/http.c	28 Feb 2006 21:08:16 -0000
@@ -659,7 +659,7 @@
 
 int 
 base64_encode(const void *enc, int encLen, char *out, int outMax) {
-	static const char	b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+	static const char	b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 	unsigned char		*encBuf;
 	int			outLen;
@@ -670,6 +670,9 @@
 	outLen = 0;
 	bits = 0;
 	shift = 0;
+	outMax &= ~3;
+	// do padding here for simplicity
+	memset(out, '=', outMax);
 
 	while( outLen<outMax ) {
 		if( encLen>0 ) {
@@ -685,11 +688,7 @@
 			bits <<= 6 - shift;
 			shift = 6;
 		} else {
-			// Terminate with Mime style '='
-			*out = '=';
-			outLen++;
-
-			return outLen;
+			return (outLen + 3) & ~3;
 		}
 
 		// Encode 6 bit segments


More information about the MPlayer-dev-eng mailing list