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

Remove totally useless transcoding from UTF-8 in HTTP interface,

heavy simplification, and fix(/remove) piles of error cases.
Server gets to choose the charset anyway.
parent 1828f4b9
......@@ -39,9 +39,6 @@ static void Close( vlc_object_t * );
"machine, enter 127.0.0.1" )
#define SRC_TEXT N_( "Source directory" )
#define SRC_LONGTEXT N_( "Source directory" )
#define CHARSET_TEXT N_( "Charset" )
#define CHARSET_LONGTEXT N_( \
"Charset declared in Content-Type header (default UTF-8)." )
#define HANDLERS_TEXT N_( "Handlers" )
#define HANDLERS_LONGTEXT N_( \
"List of handler extensions and executable paths (for instance: " \
......@@ -68,7 +65,7 @@ vlc_module_begin();
set_subcategory( SUBCAT_INTERFACE_MAIN );
add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, VLC_TRUE );
add_string ( "http-charset", "UTF-8", NULL, CHARSET_TEXT, CHARSET_LONGTEXT, VLC_TRUE );
add_obsolete_string ( "http-charset" );
#if defined( HAVE_FORK ) || defined( WIN32 )
add_string ( "http-handlers", NULL, NULL, HANDLERS_TEXT, HANDLERS_LONGTEXT, VLC_TRUE );
#endif
......@@ -133,7 +130,7 @@ static int Open( vlc_object_t *p_this )
const char *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
*psz_crl = NULL;
int i_port = 0;
char *psz_src;
char *psz_src = NULL;
psz_address = var_GetNonEmptyString(p_intf->p_libvlc, "http-host");
if( psz_address != NULL )
......@@ -161,52 +158,6 @@ static int Open( vlc_object_t *p_this )
p_sys->i_port = i_port;
p_sys->p_art_handler = NULL;
/* determine Content-Type value for HTML pages */
psz_src = config_GetPsz( p_intf, "http-charset" );
if( psz_src == NULL || !*psz_src )
{
if( psz_src != NULL ) free( psz_src );
psz_src = strdup("UTF-8");
}
p_sys->psz_html_type = malloc( 20 + strlen( psz_src ) );
if( p_sys->psz_html_type == NULL )
{
pl_Release( p_this );
free( p_sys->psz_address );
free( p_sys );
free( psz_src );
return VLC_ENOMEM ;
}
sprintf( p_sys->psz_html_type, "text/html; charset=%s", psz_src );
msg_Dbg( p_intf, "using charset=%s", psz_src );
if( strcmp( psz_src, "UTF-8" ) )
{
char psz_encoding[strlen( psz_src ) + sizeof( "//translit")];
sprintf( psz_encoding, "%s//translit", psz_src);
p_sys->iconv_from_utf8 = vlc_iconv_open( psz_encoding, "UTF-8" );
if( p_sys->iconv_from_utf8 == (vlc_iconv_t)-1 )
msg_Warn( p_intf, "unable to perform charset conversion to %s",
psz_encoding );
else
{
p_sys->iconv_to_utf8 = vlc_iconv_open( "UTF-8", psz_src );
if( p_sys->iconv_to_utf8 == (vlc_iconv_t)-1 )
msg_Warn( p_intf,
"unable to perform charset conversion from %s",
psz_src );
}
}
else
{
p_sys->iconv_from_utf8 = p_sys->iconv_to_utf8 = (vlc_iconv_t)-1;
}
p_sys->psz_charset = psz_src;
psz_src = NULL;
/* determine file handler associations */
p_sys->i_handlers = 0;
p_sys->pp_handlers = NULL;
......@@ -279,7 +230,6 @@ static int Open( vlc_object_t *p_this )
{
msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
pl_Release( p_this );
free( p_sys->psz_html_type );
free( p_sys->psz_address );
free( p_sys );
return VLC_EGENERIC;
......@@ -381,11 +331,6 @@ failed:
free( p_sys->pp_files );
httpd_HostDelete( p_sys->p_httpd_host );
free( p_sys->psz_address );
free( p_sys->psz_html_type );
if( p_sys->iconv_from_utf8 != (vlc_iconv_t)-1 )
vlc_iconv_close( p_sys->iconv_from_utf8 );
if( p_sys->iconv_to_utf8 != (vlc_iconv_t)-1 )
vlc_iconv_close( p_sys->iconv_to_utf8 );
free( p_sys );
pl_Release( p_this );
return VLC_EGENERIC;
......@@ -441,12 +386,6 @@ static void Close ( vlc_object_t *p_this )
httpd_HandlerDelete( p_sys->p_art_handler );
httpd_HostDelete( p_sys->p_httpd_host );
free( p_sys->psz_address );
free( p_sys->psz_html_type );
if( p_sys->iconv_from_utf8 != (vlc_iconv_t)-1 )
vlc_iconv_close( p_sys->iconv_from_utf8 );
if( p_sys->iconv_to_utf8 != (vlc_iconv_t)-1 )
vlc_iconv_close( p_sys->iconv_to_utf8 );
free( p_sys );
pl_Release( p_this );
}
......@@ -558,7 +497,7 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer,
E_(mvar_AppendNewVar)( p_args->vars, "stream_length", length );
E_(mvar_AppendNewVar)( p_args->vars, "volume", volume );
E_(mvar_AppendNewVar)( p_args->vars, "stream_state", state );
E_(mvar_AppendNewVar)( p_args->vars, "charset", p_sys->psz_charset );
E_(mvar_AppendNewVar)( p_args->vars, "charset", "UTF-8" );
/* Stats */
if( p_sys->p_input )
......
......@@ -110,13 +110,6 @@ char *E_(FileToUrl)( char *name, vlc_bool_t *pb_index );
/** This function returns the real path of a file or directory */
char *E_(RealPath)( intf_thread_t *p_intf, const char *psz_src );
/* Locale handling functions */
/** This fuction converts a locale string to UTF-8 */
char *E_(FromUTF8)( intf_thread_t *p_intf, char *psz_utf8 );
/** This function converts an UTF-8 to locale */
char *E_(ToUTF8)( intf_thread_t *p_intf, char *psz_local );
/** This command parses the "seek" command for the HTTP interface
* and performs the requested action */
void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value );
......@@ -371,9 +364,6 @@ struct intf_sys_t
playlist_t *p_playlist;
input_thread_t *p_input;
vlm_t *p_vlm;
char *psz_html_type;
char *psz_charset;
vlc_iconv_t iconv_from_utf8, iconv_to_utf8;
char *psz_address;
unsigned short i_port;
......
......@@ -303,29 +303,22 @@ mvar_t *E_(mvar_InfoSetNew)( intf_thread_t *p_intf, char *name,
for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
{
info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
char *psz;
mvar_t *cat = E_(mvar_New)( name, "set" );
mvar_t *iset = E_(mvar_New)( "info", "set" );
psz = E_(FromUTF8)( p_intf, p_category->psz_name );
E_(mvar_AppendNewVar)( cat, "name", psz );
free( psz );
E_(mvar_AppendNewVar)( cat, "name", p_category->psz_name );
E_(mvar_AppendVar)( cat, iset );
for ( j = 0; j < p_category->i_infos; j++ )
{
info_t *p_info = p_category->pp_infos[j];
mvar_t *info = E_(mvar_New)( "info", "" );
char *psz_name = E_(FromUTF8)( p_intf, p_info->psz_name );
char *psz_value = E_(FromUTF8)( p_intf, p_info->psz_value );
/* msg_Dbg( p_input, "adding info name=%s value=%s",
psz_name, psz_value ); */
E_(mvar_AppendNewVar)( info, "name", psz_name );
E_(mvar_AppendNewVar)( info, "value", psz_value );
free( psz_name );
free( psz_value );
E_(mvar_AppendNewVar)( info, "name", p_info->psz_name );
E_(mvar_AppendNewVar)( info, "value", p_info->psz_value );
E_(mvar_AppendVar)( iset, info );
}
E_(mvar_AppendVar)( s, cat );
......@@ -425,11 +418,10 @@ mvar_t *E_(mvar_InputVarSetNew)( intf_thread_t *p_intf, char *name,
{
case VLC_VAR_STRING:
itm = E_(mvar_New)( name, "set" );
psz = E_(FromUTF8)( p_intf, text_list.p_list->p_values[i].psz_string );
/* FIXME: Memory leak here?? (remove strdup?) */
psz = strdup( text_list.p_list->p_values[i].psz_string );
E_(mvar_AppendNewVar)( itm, "name", psz );
psz = E_(FromUTF8)( p_intf, val_list.p_list->p_values[i].psz_string );
E_(mvar_AppendNewVar)( itm, "id", psz );
free( psz );
E_(mvar_AppendNewVar)( itm, "id", val_list.p_list->p_values[i].psz_string );
snprintf( psz_int, sizeof(psz_int), "%d",
( !strcmp( val.psz_string,
val_list.p_list->p_values[i].psz_string )
......@@ -440,7 +432,7 @@ mvar_t *E_(mvar_InputVarSetNew)( intf_thread_t *p_intf, char *name,
case VLC_VAR_INTEGER:
itm = E_(mvar_New)( name, "set" );
psz = E_(FromUTF8)( p_intf, text_list.p_list->p_values[i].psz_string );
psz = strdup( text_list.p_list->p_values[i].psz_string );
E_(mvar_AppendNewVar)( itm, "name", psz );
snprintf( psz_int, sizeof(psz_int), "%d",
val_list.p_list->p_values[i].i_int );
......@@ -540,33 +532,30 @@ mvar_t *E_(mvar_FileSetNew)( intf_thread_t *p_intf, char *name,
for( i = 0; i < i_dir_content; i++ )
{
char *psz_dir_content = ppsz_dir_content[i];
char psz_tmp[strlen( psz_dir ) + 1 + strlen( psz_dir_content ) + 1];
char *psz_name = ppsz_dir_content[i], *psz_ext, *psz_dummy;
char psz_tmp[strlen( psz_dir ) + 1 + strlen( psz_name ) + 1];
mvar_t *f;
char *psz_name, *psz_ext, *psz_dummy;
#if defined( WIN32 )
if( psz_dir[0] == '\0' || (psz_dir[0] == '\\' && psz_dir[1] == '\0') )
{
strcpy( psz_tmp, psz_dir_content );
strcpy( psz_tmp, psz_name );
}
else
#endif
{
sprintf( psz_tmp, "%s"DIR_SEP"%s", psz_dir, psz_dir_content );
sprintf( psz_tmp, "%s"DIR_SEP"%s", psz_dir, psz_name );
#ifdef HAVE_SYS_STAT_H
if( utf8_stat( psz_tmp, &stat_info ) == -1 )
{
free( psz_dir_content );
free( psz_name );
continue;
}
#endif
}
f = E_(mvar_New)( name, "set" );
psz_name = E_(FromUTF8)( p_intf, psz_dir_content );
/* put lower-case file extension in 'ext' */
psz_ext = strrchr( psz_name, '.' );
psz_ext = strdup( psz_ext != NULL ? psz_ext + 1 : "" );
......@@ -632,7 +621,6 @@ mvar_t *E_(mvar_FileSetNew)( intf_thread_t *p_intf, char *name,
E_(mvar_AppendVar)( s, f );
free( psz_name );
free( psz_dir_content );
}
free( psz_dir );
......
......@@ -352,11 +352,8 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t *vars,
char *value = E_(ExtractURIString)( url, name );
if( value != NULL )
{
char *tmp;
decode_URI( value );
tmp = E_(FromUTF8)( p_intf, value );
E_(SSPush)( st, tmp );
free( tmp );
E_(SSPush)( st, value );
free( value );
}
else
......@@ -367,12 +364,7 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t *vars,
else if( !strcmp( s, "url_encode" ) )
{
char *url = E_(SSPop)( st );
char *value;
value = E_(ToUTF8)( p_intf, url );
free( url );
url = value;
value = vlc_UrlEncode( url );
char *value = vlc_UrlEncode( url );
free( url );
E_(SSPush)( st, value );
free( value );
......@@ -836,17 +828,9 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t *vars,
{
char *psz_name = E_(SSPop)( st );
char *mrl = E_(SSPop)( st );
char *tmp;
input_item_t *p_input;
int i_ret;
tmp = E_(ToUTF8)( p_intf, psz_name );
free( psz_name );
psz_name = tmp;
tmp = E_(ToUTF8)( p_intf, mrl );
free( mrl );
mrl = tmp;
p_input = E_(MRLParse)( p_intf, mrl, psz_name );
char *psz_uri = input_item_GetURI( p_input );
......
......@@ -260,7 +260,7 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
if( !f->b_handler )
{
char *psz_type = strdup( p_sys->psz_html_type );
char *psz_type = strdup( "text/html; charset=UTF-8" );
if( strstr( &dir[strlen( psz_root )], ".xml" ) )
{
char *psz = strstr( psz_type, "html;" );
......@@ -340,77 +340,6 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
}
/**************************************************************************
* Locale functions
**************************************************************************/
char *E_(FromUTF8)( intf_thread_t *p_intf, char *psz_utf8 )
{
intf_sys_t *p_sys = p_intf->p_sys;
if( psz_utf8 == NULL )
return NULL;
if ( p_sys->iconv_from_utf8 != (vlc_iconv_t)-1 )
{
size_t i_in = strlen(psz_utf8);
size_t i_out = i_in * 2;
char *psz_local = malloc(i_out + 1);
char *psz_out = psz_local;
size_t i_ret;
char psz_tmp[i_in + 1];
const char *psz_in = psz_tmp;
strcpy( psz_tmp, psz_utf8 );
i_in = strlen( psz_tmp );
i_ret = vlc_iconv( p_sys->iconv_from_utf8, &psz_in, &i_in,
&psz_out, &i_out );
if( i_ret == (size_t)-1 || i_in )
{
msg_Warn( p_intf,
"failed to convert \"%s\" to desired charset (%m)",
psz_utf8 );
free( psz_local );
return strdup( psz_utf8 );
}
*psz_out = '\0';
return psz_local;
}
else
return strdup( psz_utf8 );
}
char *E_(ToUTF8)( intf_thread_t *p_intf, char *psz_local )
{
intf_sys_t *p_sys = p_intf->p_sys;
if ( p_sys->iconv_to_utf8 != (vlc_iconv_t)-1 )
{
const char *psz_in = psz_local;
size_t i_in = strlen(psz_in);
size_t i_out = i_in * 6;
char *psz_utf8 = malloc(i_out + 1);
char *psz_out = psz_utf8;
size_t i_ret = vlc_iconv( p_sys->iconv_to_utf8, &psz_in, &i_in,
&psz_out, &i_out );
if( i_ret == (size_t)-1 || i_in )
{
msg_Warn( p_intf,
"failed to convert \"%s\" to desired charset (%m)",
psz_local );
free( psz_utf8 );
return strdup( psz_local );
}
*psz_out = '\0';
return psz_utf8;
}
else
return strdup( psz_local );
}
/*************************************************************************
* Playlist stuff
*************************************************************************/
......@@ -423,7 +352,7 @@ void E_(PlaylistListNode)( intf_thread_t *p_intf, playlist_t *p_pl,
if( p_node->i_children == -1 )
{
char value[512];
char *psz, *psz_utf8;
char *psz;
mvar_t *itm = E_(mvar_New)( name, "set" );
if( p_pl->status.p_item && p_node &&
......@@ -440,16 +369,12 @@ void E_(PlaylistListNode)( intf_thread_t *p_intf, playlist_t *p_pl,
sprintf( value, "%d", p_node->i_id );
E_(mvar_AppendNewVar)( itm, "index", value );
psz_utf8 = input_item_GetName( p_node->p_input );
psz = E_(FromUTF8)( p_intf, psz_utf8 );
psz = input_item_GetName( p_node->p_input );
E_(mvar_AppendNewVar)( itm, "name", psz );
free( psz_utf8 );
free( psz );
psz_utf8 = input_item_GetURI( p_node->p_input );
psz = E_(FromUTF8)( p_intf, psz_utf8 );
psz = input_item_GetURI( p_node->p_input );
E_(mvar_AppendNewVar)( itm, "uri", psz );
free( psz_utf8 );
free( psz );
sprintf( value, "Item");
......@@ -476,14 +401,11 @@ void E_(PlaylistListNode)( intf_thread_t *p_intf, playlist_t *p_pl,
else
{
char value[512];
char *psz;
int i_child;
mvar_t *itm = E_(mvar_New)( name, "set" );
psz = E_(FromUTF8)( p_intf, p_node->p_input->psz_name );
E_(mvar_AppendNewVar)( itm, "name", psz );
E_(mvar_AppendNewVar)( itm, "uri", psz );
free( psz );
E_(mvar_AppendNewVar)( itm, "name", p_node->p_input->psz_name );
E_(mvar_AppendNewVar)( itm, "uri", p_node->p_input->psz_name );
sprintf( value, "Node" );
E_(mvar_AppendNewVar)( itm, "type", value );
......
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