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

Split ExtractURIValue into a research and an extract function

parent 01b3900b
...@@ -125,8 +125,9 @@ void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value ); ...@@ -125,8 +125,9 @@ void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value );
/** This function extracts the value for a given argument name /** This function extracts the value for a given argument name
* from an HTTP request */ * from an HTTP request */
char *E_(ExtractURIValue)( char *psz_uri, const char *psz_name, char *E_(ExtractURIValue)( char *restrict psz_uri,
char *psz_value, int i_value_max ); const char *restrict psz_name,
char *restrict psz_value, size_t i_value_max );
/** \todo Describe this function */ /** \todo Describe this function */
int E_(TestURIParam)( char *psz_uri, const char *psz_name ); int E_(TestURIParam)( char *psz_uri, const char *psz_name );
......
...@@ -719,10 +719,12 @@ int E_(TestURIParam)( char *psz_uri, const char *psz_name ) ...@@ -719,10 +719,12 @@ int E_(TestURIParam)( char *psz_uri, const char *psz_name )
return VLC_FALSE; return VLC_FALSE;
} }
char *E_(ExtractURIValue)( char *psz_uri, const char *psz_name,
char *psz_value, int i_value_max ) static char *FindURIValue( char *psz_uri, const char *restrict psz_name,
size_t *restrict p_len )
{ {
char *p = psz_uri; char *p = psz_uri, *end;
size_t len;
while( (p = strstr( p, psz_name )) ) while( (p = strstr( p, psz_name )) )
{ {
...@@ -733,48 +735,64 @@ char *E_(ExtractURIValue)( char *psz_uri, const char *psz_name, ...@@ -733,48 +735,64 @@ char *E_(ExtractURIValue)( char *psz_uri, const char *psz_name,
p++; p++;
} }
if( p ) if( p == NULL )
{ {
int i_len; *p_len = 0;
return NULL;
}
p += strlen( psz_name ); p += strlen( psz_name );
if( *p == '=' ) p++; if( *p == '=' ) p++;
if( strchr( p, '&' ) ) if( ( end = strchr( p, '\n' ) ) != NULL )
{
i_len = strchr( p, '&' ) - p;
}
else
{
/* for POST method */
if( strchr( p, '\n' ) )
{ {
i_len = strchr( p, '\n' ) - p; /* POST method */
if( i_len && *(p+i_len-1) == '\r' ) i_len--; if( ( end > p ) && ( end[-1] == '\r' ) )
end--;
len = end - p;
} }
else else
{ {
i_len = strlen( p ); /* GET method */
} if( ( end = strchr( p, '&' ) ) != NULL )
} len = end - p;
i_len = __MIN( i_value_max - 1, i_len );
if( i_len > 0 )
{
strncpy( psz_value, p, i_len );
psz_value[i_len] = '\0';
}
else else
{ len = strlen( p );
strncpy( psz_value, "", i_value_max );
}
p += i_len;
} }
else
*p_len = len;
return p;
}
char *E_(ExtractURIValue)( char *restrict psz_uri,
const char *restrict psz_name,
char *restrict psz_buf, size_t bufsize )
{
size_t len;
char *psz_value = FindURIValue( psz_uri, psz_name, &len );
char *psz_next;
fprintf( stderr, "%s within %s:\n", psz_name, psz_uri );
if( psz_value == NULL )
{ {
strncpy( psz_value, "", i_value_max ); if( bufsize > 0 )
*psz_buf = '\0';
return NULL;
} }
return p; psz_next = psz_value + len;
if( len >= bufsize )
len = bufsize - 1;
if( len > 0 )
strncpy( psz_buf, psz_value, len );
if( bufsize > 0 )
psz_buf[len] = '\0';
fprintf( stderr, "%s next %s\n", psz_buf, psz_next );
return psz_next;
} }
/* Since the resulting string is smaller we can work in place, so it is /* Since the resulting string is smaller we can work in place, so it is
......
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