Commit 45483011 authored by Rafaël Carré's avatar Rafaël Carré

HLS: resolve relative URLs (/a/b/../c -> /a/c)

parent 04632cc8
......@@ -542,28 +542,49 @@ static int string_to_IV(char *string_hexa, uint8_t iv[AES_BLOCK_SIZE])
static char *relative_URI(const char *psz_url, const char *psz_path)
{
char *ret = NULL;
assert(psz_url != NULL && psz_path != NULL);
//If the path is actually an absolute URL, don't do anything.
if (strncmp(psz_path, "http", 4) == 0)
return NULL;
char *path_separator=NULL;
size_t len = strlen(psz_path);
char *new_url = strdup(psz_url);
if (unlikely(!new_url))
return NULL;
if( psz_path[0] == '/' ) //Relative URL with absolute path
{
//Try to find separator for name and path, try to skip
//access and first ://
path_separator = strchr( &psz_url[8], '/');
char *slash = strchr(&new_url[8], '/');
if (unlikely(slash == NULL))
goto end;
*slash = '\0';
} else {
path_separator = strrchr(psz_url, '/');
int levels = 0;
while(len >= 3 && !strncmp(psz_path, "../", 3)) {
psz_path += 3;
len -= 3;
levels++;
}
if ( unlikely( path_separator == NULL ) )
return NULL;
const size_t url_length = path_separator - psz_url + 1;
char *psz_res = malloc(url_length + strlen(psz_path) + 1);
strncpy(psz_res, psz_url, url_length);
psz_res[url_length] = 0;
strcat(psz_res, psz_path);
return psz_res;
do {
char *slash = strrchr(new_url, '/');
if (unlikely(slash == NULL))
goto end;
*slash = '\0';
} while (levels--);
}
if (asprintf(&ret, "%s/%s", new_url, psz_path) < 0)
ret = NULL;
end:
free(new_url);
return ret;
}
static int parse_SegmentInformation(hls_stream_t *hls, char *p_read, int *duration)
......
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