Commit c978f72d authored by Christophe Massiot's avatar Christophe Massiot

* modules/control/http.c:

 - Add a basename field to the file entry when doing a foreach on directory.
 - Add a url_encode function to url-encode the current string. This
   is necessary to safely pass strings as arguments in a URL.
Patch courtesy of Clement Vasseur for Freebox SA.
parent 9502edb7
......@@ -31,6 +31,7 @@
*/
#include <stdlib.h>
#include <ctype.h>
#include <vlc/vlc.h>
#include <vlc/intf.h>
......@@ -1211,6 +1212,7 @@ static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
#endif
f = mvar_New( name, "set" );
mvar_AppendNewVar( f, "name", tmp );
mvar_AppendNewVar( f, "basename", p_dir_content->d_name );
#ifdef HAVE_SYS_STAT_H
if( S_ISDIR( stat_info.st_mode ) )
......@@ -2847,10 +2849,57 @@ static void uri_decode_url_encoded( char *psz )
*psz++ = *p++;
}
}
*psz++ ='\0';
*psz++ = '\0';
free( dup );
}
static int char_in_str( char c, const char *str )
{
while( *str )
{
if( c == *str )
return 1;
str++;
}
return 0;
}
static void uri_encode( const char *from, char *to, size_t to_len )
{
static const char hex[] = "0123456789abcdef";
while( *from && to_len > 1 )
{
if( *from == ' ' )
{
*to++ = '+';
}
else if( isalnum( *from ) || char_in_str( *from, "$-_.+!*'(),/" ) )
{
*to++ = *from;
}
else
{
*to++ = '%';
if ( --to_len <= 1 )
break;
*to++ = hex[( *from >> 4 ) & 0x0f];
if ( --to_len <= 1 )
break;
*to++ = hex[*from & 0x0f];
}
to_len--;
from++;
}
if ( to_len > 0 )
*to = '\0';
}
/****************************************************************************
* Light RPN evaluator
****************************************************************************/
......@@ -3173,6 +3222,14 @@ static void EvaluateRPN( mvar_t *vars, rpn_stack_t *st, char *exp )
uri_decode_url_encoded( value );
SSPush( st, value );
}
else if( !strcmp( s, "url_encode" ) )
{
char *url = SSPop( st );
char value[512];
uri_encode( url, value, 512 );
SSPush( st, value );
}
else
{
SSPush( st, s );
......
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