Commit dfb78a8b authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

De-inline base64 decoder

parent 6be4bda5
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
VLC_EXPORT( void, resolve_xml_special_chars, ( char *psz_value ) ); VLC_EXPORT( void, resolve_xml_special_chars, ( char *psz_value ) );
VLC_EXPORT( char *, convert_xml_special_chars, ( const char *psz_content ) ); VLC_EXPORT( char *, convert_xml_special_chars, ( const char *psz_content ) );
VLC_EXPORT( char *, vlc_b64_encode, ( const char * ) );
VLC_EXPORT( char *, str_format_time, ( const char * ) ); VLC_EXPORT( char *, str_format_time, ( const char * ) );
#define str_format_meta( a, b ) __str_format_meta( VLC_OBJECT( a ), b ) #define str_format_meta( a, b ) __str_format_meta( VLC_OBJECT( a ), b )
VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, const char * ) ); VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, const char * ) );
......
...@@ -211,51 +211,5 @@ static inline int vlc_UrlIsNotEncoded( const char *psz_url ) ...@@ -211,51 +211,5 @@ static inline int vlc_UrlIsNotEncoded( const char *psz_url )
return 0; /* looks fine - but maybe it is not encoded */ return 0; /* looks fine - but maybe it is not encoded */
} }
/* Base64 encoding */
static inline char *vlc_b64_encode( const char *src )
{
static const char b64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
size_t len = strlen( src );
const uint8_t *in = (const uint8_t *)src;
char *ret;
char *dst = (char *)malloc( ( len + 4 ) * 4 / 3 );
if( dst == NULL )
return NULL;
ret = dst;
while( len > 0 )
{
/* pops (up to) 3 bytes of input, push 4 bytes */
uint32_t v = *in++ << 24; // 1/3
*dst++ = b64[v >> 26]; // 1/4
v = v << 6;
if( len >= 2 )
v |= *in++ << 22; // 2/3
*dst++ = b64[v >> 26]; // 2/4
v = v << 6;
if( len >= 3 )
v |= *in++ << 20; // 3/3
*dst++ = ( len >= 2 ) ? b64[v >> 26] : '='; // 3/4
v = v << 6;
*dst++ = ( len >= 3 ) ? b64[v >> 26] : '='; // 4/4
len--;
if( len > 0 )
{
len--;
if( len > 0 )
len--;
}
}
*dst = '\0';
return ret;
}
#endif #endif
...@@ -328,6 +328,54 @@ char *convert_xml_special_chars( const char *psz_content ) ...@@ -328,6 +328,54 @@ char *convert_xml_special_chars( const char *psz_content )
return psz_temp; return psz_temp;
} }
/* Base64 encoding */
char *vlc_b64_encode( const char *src )
{
static const char b64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
size_t len = strlen( src );
const uint8_t *in = (const uint8_t *)src;
char *ret;
char *dst = (char *)malloc( ( len + 4 ) * 4 / 3 );
if( dst == NULL )
return NULL;
ret = dst;
while( len > 0 )
{
/* pops (up to) 3 bytes of input, push 4 bytes */
uint32_t v = *in++ << 24; // 1/3
*dst++ = b64[v >> 26]; // 1/4
v = v << 6;
if( len >= 2 )
v |= *in++ << 22; // 2/3
*dst++ = b64[v >> 26]; // 2/4
v = v << 6;
if( len >= 3 )
v |= *in++ << 20; // 3/3
*dst++ = ( len >= 2 ) ? b64[v >> 26] : '='; // 3/4
v = v << 6;
*dst++ = ( len >= 3 ) ? b64[v >> 26] : '='; // 4/4
len--;
if( len > 0 )
{
len--;
if( len > 0 )
len--;
}
}
*dst = '\0';
return ret;
}
/**************************************************************************** /****************************************************************************
* String formating functions * String formating functions
****************************************************************************/ ****************************************************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment