Commit e30ee3d5 authored by Rémi Duraffort's avatar Rémi Duraffort

Cleaning xurl code (CID 193 and CID 51 are now fixed)

parent 3e0219e0
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
***************************************************************************** *****************************************************************************
* Copyright (C) 2003-2004 Commonwealth Scientific and Industrial Research * Copyright (C) 2003-2004 Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) Australia * Organisation (CSIRO) Australia
* Copyright (C) 2004 the VideoLAN team * Copyright (C) 2004-2008 the VideoLAN team
* *
* $Id$ * $Id$
* *
...@@ -55,7 +55,7 @@ char *XURL_Concat( char *psz_url, char *psz_append ) ...@@ -55,7 +55,7 @@ char *XURL_Concat( char *psz_url, char *psz_append )
{ {
char *psz_return_value = NULL; char *psz_return_value = NULL;
if( XURL_IsAbsolute( psz_append ) == XURL_TRUE ) if( XURL_IsAbsolute( psz_append ) )
return strdup( psz_append ); return strdup( psz_append );
if( XURL_IsAbsolute( psz_url ) ) if( XURL_IsAbsolute( psz_url ) )
...@@ -88,7 +88,7 @@ char *XURL_Concat( char *psz_url, char *psz_append ) ...@@ -88,7 +88,7 @@ char *XURL_Concat( char *psz_url, char *psz_append )
else else
{ {
/* not an absolute URL */ /* not an absolute URL */
if( XURL_HasAbsolutePath( psz_append ) == XURL_FALSE ) if( XURL_HasAbsolutePath( psz_append ) == false )
{ {
char *psz_new_url = XURL_GetHead( psz_url ); char *psz_new_url = XURL_GetHead( psz_url );
...@@ -106,31 +106,31 @@ char *XURL_Concat( char *psz_url, char *psz_append ) ...@@ -106,31 +106,31 @@ char *XURL_Concat( char *psz_url, char *psz_append )
} }
XURL_Bool XURL_IsAbsolute( char *psz_url ) bool XURL_IsAbsolute( char *psz_url )
{ {
if( XURL_FindHostname( psz_url ) == NULL ) if( XURL_FindHostname( psz_url ) == NULL )
{ {
#ifdef XURL_DEBUG #ifdef XURL_DEBUG
fprintf( stderr, "XURL_IsAbsolute(%s) returning false\n", psz_url ); fprintf( stderr, "XURL_IsAbsolute(%s) returning false\n", psz_url );
#endif #endif
return XURL_FALSE; return false;
} }
else else
{ {
#ifdef XURL_DEBUG #ifdef XURL_DEBUG
fprintf( stderr, "XURL_IsAbsolute(%s) returning true\n", psz_url ); fprintf( stderr, "XURL_IsAbsolute(%s) returning true\n", psz_url );
#endif #endif
return XURL_TRUE; return true;
} }
} }
XURL_Bool XURL_HasFragment( char *psz_url ) bool XURL_HasFragment( char *psz_url )
{ {
if( XURL_FindFragment( psz_url ) == NULL ) if( XURL_FindFragment( psz_url ) == NULL )
return XURL_FALSE; return false;
else else
return XURL_TRUE; return true;
} }
...@@ -142,7 +142,8 @@ char *XURL_FindHostname( char *psz_url ) ...@@ -142,7 +142,8 @@ char *XURL_FindHostname( char *psz_url )
if( psz_scheme_separator != NULL) if( psz_scheme_separator != NULL)
{ {
char *psz_hostname = psz_scheme_separator + strlen( "://" ); char *psz_hostname = psz_scheme_separator + strlen( "://" );
if( *psz_hostname != '\0') psz_return_value = psz_hostname; if( *psz_hostname != '\0')
psz_return_value = psz_hostname;
#ifdef XURL_DEBUG #ifdef XURL_DEBUG
fprintf( stderr, "XURL_FindHostname(%s): returning \"%s\"\n", fprintf( stderr, "XURL_FindHostname(%s): returning \"%s\"\n",
...@@ -154,16 +155,16 @@ char *XURL_FindHostname( char *psz_url ) ...@@ -154,16 +155,16 @@ char *XURL_FindHostname( char *psz_url )
} }
XURL_Bool XURL_HasAbsolutePath( char *psz_url ) bool XURL_HasAbsolutePath( char *psz_url )
{ {
#ifdef XURL_WIN32_PATHING #ifdef XURL_WIN32_PATHING
if( psz_url[0] == '/' || psz_url[0] == '\\' ) if( psz_url[0] == '/' || psz_url[0] == '\\' )
#else #else
if( psz_url[0] == '/' ) if( psz_url[0] == '/' )
#endif #endif
return XURL_TRUE; return true;
else else
return XURL_FALSE; return false;
} }
...@@ -194,7 +195,8 @@ char *XURL_GetHostname( char *psz_url ) ...@@ -194,7 +195,8 @@ char *XURL_GetHostname( char *psz_url )
/* Copy hostname to a new string */ /* Copy hostname to a new string */
psz_new_hostname = malloc( i_hostname_length ); psz_new_hostname = malloc( i_hostname_length );
if (psz_new_hostname == NULL) return NULL; if( psz_new_hostname == NULL )
return NULL;
strncpy( psz_new_hostname, psz_hostname, i_hostname_length ); strncpy( psz_new_hostname, psz_hostname, i_hostname_length );
#ifdef XURL_DEBUG #ifdef XURL_DEBUG
...@@ -232,17 +234,14 @@ char *XURL_GetSchemeAndHostname( char *psz_url ) ...@@ -232,17 +234,14 @@ char *XURL_GetSchemeAndHostname( char *psz_url )
return psz_scheme_and_hostname; return psz_scheme_and_hostname;
} }
static static char *XURL_FindFragment( char *psz_url )
char *XURL_FindFragment( char *psz_url )
{ {
char *pc_hash = NULL; char *pc_hash = NULL;
char *pc_return_value = NULL; char *pc_return_value = NULL;
pc_hash = strchr( psz_url, '#' ); pc_hash = strchr( psz_url, '#' );
if( pc_hash != NULL ) if( pc_hash != NULL )
{
pc_return_value = pc_hash; pc_return_value = pc_hash;
}
return pc_return_value; return pc_return_value;
} }
...@@ -254,9 +253,7 @@ char *XURL_FindQuery( char *psz_url ) ...@@ -254,9 +253,7 @@ char *XURL_FindQuery( char *psz_url )
pc_question_mark = strchr( psz_url, '?' ); pc_question_mark = strchr( psz_url, '?' );
if( pc_question_mark != NULL ) if( pc_question_mark != NULL )
{
pc_return_value = pc_question_mark; pc_return_value = pc_question_mark;
}
return pc_return_value; return pc_return_value;
} }
...@@ -268,7 +265,7 @@ char *XURL_GetScheme( char *psz_url ) ...@@ -268,7 +265,7 @@ char *XURL_GetScheme( char *psz_url )
size_t i_scheme_length; size_t i_scheme_length;
char *new_scheme; char *new_scheme;
if( XURL_IsAbsolute( psz_url ) == XURL_FALSE ) if( XURL_IsAbsolute( psz_url ) == false )
return strdup( "file" ); return strdup( "file" );
/* this strchr will always succeed since we have an absolute URL, and thus /* this strchr will always succeed since we have an absolute URL, and thus
...@@ -286,15 +283,15 @@ char *XURL_GetScheme( char *psz_url ) ...@@ -286,15 +283,15 @@ char *XURL_GetScheme( char *psz_url )
} }
XURL_Bool XURL_IsFileURL( char *psz_url ) bool XURL_IsFileURL( char *psz_url )
{ {
XURL_Bool b_return_value; bool b_return_value;
char *psz_scheme = XURL_GetScheme( psz_url ); char *psz_scheme = XURL_GetScheme( psz_url );
if( strcasecmp( psz_scheme, "file" ) == 0 ) if( strcasecmp( psz_scheme, "file" ) == 0 )
b_return_value = XURL_TRUE; b_return_value = true;
else else
b_return_value = XURL_FALSE; b_return_value = false;
free( psz_scheme ); free( psz_scheme );
...@@ -302,33 +299,23 @@ XURL_Bool XURL_IsFileURL( char *psz_url ) ...@@ -302,33 +299,23 @@ XURL_Bool XURL_IsFileURL( char *psz_url )
} }
static static char *XURL_FindPath( char *psz_url )
char *XURL_FindPath( char *psz_url )
{ {
char *psz_return_value = NULL; if( XURL_IsAbsolute( psz_url ) )
if( XURL_IsAbsolute( psz_url ) == XURL_TRUE )
{ {
char *psz_start_of_hostname = XURL_FindHostname( psz_url ); char *psz_start_of_hostname = XURL_FindHostname( psz_url );
if( psz_start_of_hostname != NULL ) if( psz_start_of_hostname != NULL )
{ return strchr( psz_start_of_hostname, '/' );
char *psz_start_of_path = strchr( psz_start_of_hostname, '/' ); else
psz_return_value = psz_start_of_path; return NULL;
}
} }
else else
{ {
if( XURL_HasAbsolutePath( psz_url ) == XURL_TRUE ) if( XURL_HasAbsolutePath( psz_url ) == true )
{ return psz_url;
psz_return_value = psz_url;
}
else else
{
return strdup ("."); return strdup (".");
}
} }
return psz_return_value;
} }
...@@ -397,8 +384,7 @@ char *XURL_GetHead( const char *psz_path ) ...@@ -397,8 +384,7 @@ char *XURL_GetHead( const char *psz_path )
i_characters_until_last_slash = pc_last_slash - psz_path; i_characters_until_last_slash = pc_last_slash - psz_path;
psz_path_head = malloc( psz_path_head = malloc(
( i_characters_until_last_slash + 1 ) * sizeof(char) ); ( i_characters_until_last_slash + 1 ) * sizeof(char) );
(void) strncpy( psz_path_head, psz_path, strncpy( psz_path_head, psz_path, i_characters_until_last_slash + 1 );
i_characters_until_last_slash + 1 );
/* terminate the resulting string with '\0' */ /* terminate the resulting string with '\0' */
*(psz_path_head + *(psz_path_head +
...@@ -445,8 +431,7 @@ char *XURL_GetWithoutFragment( char *psz_url ) ...@@ -445,8 +431,7 @@ char *XURL_GetWithoutFragment( char *psz_url )
return psz_return_value; return psz_return_value;
} }
static static char *streallocat( char *psz_string, const char *psz_to_append )
char *streallocat( char *psz_string, const char *psz_to_append )
{ {
size_t i_new_string_length = strlen( psz_string ) + size_t i_new_string_length = strlen( psz_string ) +
strlen( psz_to_append ) + 1; strlen( psz_to_append ) + 1;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
***************************************************************************** *****************************************************************************
* Copyright (C) 2003-2004 Commonwealth Scientific and Industrial Research * Copyright (C) 2003-2004 Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) Australia * Organisation (CSIRO) Australia
* Copyright (C) 2004 the VideoLAN team * Copyright (C) 2004-2008 the VideoLAN team
* *
* $Id$ * $Id$
* *
...@@ -29,11 +29,6 @@ ...@@ -29,11 +29,6 @@
#include <vlc_common.h> #include <vlc_common.h>
/* Specialise boolean definitions to VLC's boolean types */
typedef bool XURL_Bool;
#define XURL_FALSE false
#define XURL_TRUE true
/* Use DOS/Windows path separators? */ /* Use DOS/Windows path separators? */
#ifdef WIN32 #ifdef WIN32
# define XURL_WIN32_PATHING # define XURL_WIN32_PATHING
...@@ -44,21 +39,21 @@ typedef bool XURL_Bool; ...@@ -44,21 +39,21 @@ typedef bool XURL_Bool;
/* Debugging */ /* Debugging */
#undef XURL_DEBUG #undef XURL_DEBUG
char * XURL_Join ( char *psz_url1, char *psz_url2 ); char* XURL_Join ( char *psz_url1, char *psz_url2 );
char * XURL_Concat ( char *psz_url, char *psz_append ); char* XURL_Concat ( char *psz_url, char *psz_append );
XURL_Bool XURL_IsAbsolute ( char *psz_url ); bool XURL_IsAbsolute ( char *psz_url );
XURL_Bool XURL_HasAbsolutePath ( char *psz_url ); bool XURL_HasAbsolutePath ( char *psz_url );
XURL_Bool XURL_IsFileURL ( char *psz_url ); bool XURL_IsFileURL ( char *psz_url );
XURL_Bool XURL_HasFragment ( char *psz_url ); bool XURL_HasFragment ( char *psz_url );
char * XURL_GetHostname ( char *psz_url ); char* XURL_GetHostname ( char *psz_url );
char * XURL_GetSchemeAndHostname ( char *psz_url ); char* XURL_GetSchemeAndHostname ( char *psz_url );
char * XURL_GetScheme ( char *psz_url ); char* XURL_GetScheme ( char *psz_url );
char * XURL_GetPath ( char *psz_url ); char* XURL_GetPath ( char *psz_url );
char * XURL_GetWithoutFragment ( char *psz_url ); char* XURL_GetWithoutFragment ( char *psz_url );
char * XURL_GetHead ( const char *psz_path ); char* XURL_GetHead ( const char *psz_path );
#endif /* __XURL_H__ */ #endif /* __XURL_H__ */
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