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

HTTP: use DIR_SEP(_CHAR)

parent 7a0efcc7
...@@ -555,18 +555,11 @@ int HandlerCallback( httpd_handler_sys_t *p_args, ...@@ -555,18 +555,11 @@ int HandlerCallback( httpd_handler_sys_t *p_args,
int i_env = 0; int i_env = 0;
char **ppsz_env = NULL; char **ppsz_env = NULL;
char *psz_tmp; char *psz_tmp;
char sep;
size_t i_buffer; size_t i_buffer;
char *p_buffer; char *p_buffer;
char *psz_cwd, *psz_file = NULL; char *psz_cwd, *psz_file = NULL;
int i_ret; int i_ret;
#ifdef WIN32
sep = '\\';
#else
sep = '/';
#endif
/* Create environment for the CGI */ /* Create environment for the CGI */
TAB_APPEND( i_env, ppsz_env, strdup("GATEWAY_INTERFACE=CGI/1.1") ); TAB_APPEND( i_env, ppsz_env, strdup("GATEWAY_INTERFACE=CGI/1.1") );
TAB_APPEND( i_env, ppsz_env, strdup("SERVER_PROTOCOL=HTTP/1.1") ); TAB_APPEND( i_env, ppsz_env, strdup("SERVER_PROTOCOL=HTTP/1.1") );
...@@ -677,7 +670,7 @@ int HandlerCallback( httpd_handler_sys_t *p_args, ...@@ -677,7 +670,7 @@ int HandlerCallback( httpd_handler_sys_t *p_args,
} }
} }
psz_file = strrchr( p_args->file.file, sep ); psz_file = strrchr( p_args->file.file, DIR_SEP_CHAR );
if( psz_file != NULL ) if( psz_file != NULL )
{ {
psz_file++; psz_file++;
...@@ -694,7 +687,7 @@ int HandlerCallback( httpd_handler_sys_t *p_args, ...@@ -694,7 +687,7 @@ int HandlerCallback( httpd_handler_sys_t *p_args,
NULL ); NULL );
psz_tmp = strdup( p_args->file.file ); psz_tmp = strdup( p_args->file.file );
p = strrchr( psz_tmp, sep ); p = strrchr( psz_tmp, DIR_SEP_CHAR );
if( p != NULL ) if( p != NULL )
{ {
*p = '\0'; *p = '\0';
......
...@@ -120,14 +120,6 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, ...@@ -120,14 +120,6 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
int i_dirlen; int i_dirlen;
char sep;
#if defined( WIN32 )
sep = '\\';
#else
sep = '/';
#endif
if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL ) if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL )
{ {
if( errno != ENOENT && errno != ENOTDIR ) if( errno != ENOENT && errno != ENOTDIR )
...@@ -145,7 +137,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, ...@@ -145,7 +137,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
msg_Dbg( p_intf, "dir=%s", psz_dir ); msg_Dbg( p_intf, "dir=%s", psz_dir );
snprintf( dir, sizeof( dir ), "%s%c.access", psz_dir, sep ); snprintf( dir, sizeof( dir ), "%s"DIR_SEP".access", psz_dir );
if( ( file = utf8_fopen( dir, "r" ) ) != NULL ) if( ( file = utf8_fopen( dir, "r" ) ) != NULL )
{ {
char line[1024]; char line[1024];
...@@ -179,7 +171,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, ...@@ -179,7 +171,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
fclose( file ); fclose( file );
} }
snprintf( dir, sizeof( dir ), "%s%c.hosts", psz_dir, sep ); snprintf( dir, sizeof( dir ), "%s"DIR_SEP".hosts", psz_dir );
p_acl = ACL_Create( p_intf, false ); p_acl = ACL_Create( p_intf, false );
if( ACL_LoadFile( p_acl, dir ) ) if( ACL_LoadFile( p_acl, dir ) )
{ {
...@@ -210,7 +202,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root, ...@@ -210,7 +202,7 @@ int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
continue; continue;
} }
snprintf( dir, sizeof( dir ), "%s%c%s", psz_dir, sep, psz_filename ); snprintf( dir, sizeof( dir ), "%s"DIR_SEP"%s", psz_dir, psz_filename );
free( psz_filename ); free( psz_filename );
if( ParseDirectory( p_intf, psz_root, dir ) ) if( ParseDirectory( p_intf, psz_root, dir ) )
...@@ -912,13 +904,12 @@ char *RealPath( const char *psz_src ) ...@@ -912,13 +904,12 @@ char *RealPath( const char *psz_src )
char *psz_dir; char *psz_dir;
char *p; char *p;
int i_len = strlen(psz_src); int i_len = strlen(psz_src);
const char sep = DIR_SEP_CHAR;
psz_dir = malloc( i_len + 2 ); psz_dir = malloc( i_len + 2 );
strcpy( psz_dir, psz_src ); strcpy( psz_dir, psz_src );
/* Add a trailing sep to ease the .. step */ /* Add a trailing sep to ease the .. step */
psz_dir[i_len] = sep; psz_dir[i_len] = DIR_SEP_CHAR;
psz_dir[i_len + 1] = '\0'; psz_dir[i_len + 1] = '\0';
#if (DIR_SEP_CHAR != '/') #if (DIR_SEP_CHAR != '/')
...@@ -926,18 +917,18 @@ char *RealPath( const char *psz_src ) ...@@ -926,18 +917,18 @@ char *RealPath( const char *psz_src )
p = psz_dir; p = psz_dir;
while( (p = strchr( p, '/' )) != NULL ) while( (p = strchr( p, '/' )) != NULL )
{ {
*p = sep; *p = DIR_SEP_CHAR;
} }
#endif #endif
/* FIXME: this could be O(N) rather than O(N²)... */ /* FIXME: this could be O(N) rather than O(N²)... */
/* Remove multiple separators and /./ */ /* Remove multiple separators and /./ */
p = psz_dir; p = psz_dir;
while( (p = strchr( p, sep )) != NULL ) while( (p = strchr( p, DIR_SEP_CHAR )) != NULL )
{ {
if( p[1] == sep ) if( p[1] == DIR_SEP_CHAR )
memmove( &p[1], &p[2], strlen(&p[2]) + 1 ); memmove( &p[1], &p[2], strlen(&p[2]) + 1 );
else if( p[1] == '.' && p[2] == sep ) else if( p[1] == '.' && p[2] == DIR_SEP_CHAR )
memmove( &p[1], &p[3], strlen(&p[3]) + 1 ); memmove( &p[1], &p[3], strlen(&p[3]) + 1 );
else else
p++; p++;
...@@ -955,13 +946,13 @@ char *RealPath( const char *psz_src ) ...@@ -955,13 +946,13 @@ char *RealPath( const char *psz_src )
{ {
/* Fix all .. dir */ /* Fix all .. dir */
p = psz_dir + 3; p = psz_dir + 3;
while( (p = strchr( p, sep )) != NULL ) while( (p = strchr( p, DIR_SEP_CHAR )) != NULL )
{ {
if( p[-1] == '.' && p[-2] == '.' && p[-3] == sep ) if( p[-1] == '.' && p[-2] == '.' && p[-3] == DIR_SEP_CHAR )
{ {
char *q; char *q;
p[-3] = '\0'; p[-3] = '\0';
if( (q = strrchr( psz_dir, sep )) != NULL ) if( (q = strrchr( psz_dir, DIR_SEP_CHAR )) != NULL )
{ {
memmove( q + 1, p + 1, strlen(p + 1) + 1 ); memmove( q + 1, p + 1, strlen(p + 1) + 1 );
p = q + 1; p = q + 1;
...@@ -979,8 +970,8 @@ char *RealPath( const char *psz_src ) ...@@ -979,8 +970,8 @@ char *RealPath( const char *psz_src )
/* Remove trailing sep if there are at least 2 sep in the string /* Remove trailing sep if there are at least 2 sep in the string
* (handles the C:\ stuff) */ * (handles the C:\ stuff) */
p = strrchr( psz_dir, sep ); p = strrchr( psz_dir, DIR_SEP_CHAR );
if( p != NULL && p[1] == '\0' && p != strchr( psz_dir, sep ) ) if( p != NULL && p[1] == '\0' && p != strchr( psz_dir, DIR_SEP_CHAR ) )
*p = '\0'; *p = '\0';
return psz_dir; return psz_dir;
......
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