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

- include/network.h: new vlc_UrlEncode and vlc_UrlIsNotEncoded helpers function

- modules/access/http.c: do not choke when there's a space in a URL
  (should probably be done for some others)
parent 626630b5
/***************************************************************************** /*****************************************************************************
* network.h: interface to communicate with network plug-ins * network.h: interface to communicate with network plug-ins
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002-2005 VideoLAN
* $Id$ * $Id$
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
* Rémi Denis-Courmont <courmisch # via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -166,6 +167,71 @@ static inline void vlc_UrlClean( vlc_url_t *url ) ...@@ -166,6 +167,71 @@ static inline void vlc_UrlClean( vlc_url_t *url )
url->psz_path = NULL; url->psz_path = NULL;
url->psz_option = NULL; url->psz_option = NULL;
} }
/*****************************************************************************
* vlc_UrlEncode:
*****************************************************************************
* perform URL encoding
* (you do NOT want to do URL decoding - it is not reversible - do NOT do it)
*****************************************************************************/
static inline char *vlc_UrlEncode( const char *psz_url )
{
char *psz_enc, *out;
const char *in;
psz_enc = (char *)malloc( 3 * strlen( psz_url ) + 1 );
if( psz_enc == NULL )
return NULL;
out = psz_enc;
for( in = psz_url; *in; in++ )
{
char c = *in;
if( ( c <= 32 ) || ( c == '%' ) || ( c == '?' ) || ( c == '&' )
|| ( c == '+' ) )
{
*out++ = '%';
*out++ = ( ( c >> 4 ) >= 0xA ) ? 'A' + ( c >> 4 ) - 0xA
: '0' + ( c >> 4 );
*out++ = ( ( c & 0xf ) >= 0xA ) ? 'A' + ( c & 0xf ) - 0xA
: '0' + ( c & 0xf );
}
else
*out++ = c;
}
*out++ = '\0';
return (char *)realloc( psz_enc, out - psz_enc );
}
/*****************************************************************************
* vlc_UrlIsNotEncoded:
*****************************************************************************
* check if given string is not a valid URL and must hence be encoded
*****************************************************************************/
#include <ctype.h>
static inline int vlc_UrlIsNotEncoded( const char *psz_url )
{
const char *ptr;
for( ptr = psz_url; *ptr; ptr++ )
{
char c = *ptr;
if( c == '%' )
{
if( !isxdigit( ptr[1] ) || !isxdigit( ptr[2] ) )
return 1; /* not encoded */
ptr += 2;
}
else
if( c == ' ' )
return 1;
}
return 0; /* looks fine - but maybe it is not encoded */
}
/***************************************************************************** /*****************************************************************************
* vlc_b64_encode: * vlc_b64_encode:
......
...@@ -227,7 +227,21 @@ static int Open( vlc_object_t *p_this ) ...@@ -227,7 +227,21 @@ static int Open( vlc_object_t *p_this )
p_sys->i_remaining = 0; p_sys->i_remaining = 0;
/* Parse URI */ /* Parse URI */
ParseURL( p_sys, p_access->psz_path ); if( vlc_UrlIsNotEncoded( p_access->psz_path ) )
{
psz = vlc_UrlEncode( p_access->psz_path );
if( psz == NULL )
{
free( p_sys );
return VLC_ENOMEM;
}
ParseURL( p_sys, psz );
free( psz );
}
else
ParseURL( p_sys, p_access->psz_path );
if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' ) if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )
{ {
msg_Warn( p_access, "invalid host" ); msg_Warn( p_access, "invalid host" );
......
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