mirror of
https://github.com/libretro/libretro-common.git
synced 2025-03-03 13:59:11 +00:00
Updates
This commit is contained in:
parent
96c8d42f76
commit
2ed101396e
@ -575,13 +575,6 @@ struct string_list *file_archive_get_file_list(const char *path,
|
||||
{
|
||||
struct archive_extract_userdata userdata = {{0}};
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
if (!path_is_compressed_file(path))
|
||||
return NULL;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
userdata.list_only = true;
|
||||
strlcpy(userdata.archive_path, path, sizeof(userdata.archive_path));
|
||||
|
||||
|
@ -98,11 +98,9 @@ end:
|
||||
*/
|
||||
const char *path_get_archive_delim(const char *path)
|
||||
{
|
||||
#ifdef HAVE_COMPRESSION
|
||||
const char *last = find_last_slash(path);
|
||||
const char *delim = NULL;
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
if (last)
|
||||
{
|
||||
delim = strcasestr(last, ".zip#");
|
||||
@ -113,17 +111,12 @@ const char *path_get_archive_delim(const char *path)
|
||||
|
||||
if (delim)
|
||||
return delim + 4;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_7ZIP
|
||||
if (last)
|
||||
delim = strcasestr(last, ".7z#");
|
||||
|
||||
if (delim)
|
||||
return delim + 3;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -165,26 +158,6 @@ char *path_remove_extension(char *path)
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* path_contains_compressed_file:
|
||||
* @path : path
|
||||
*
|
||||
* Checks if path contains a compressed file.
|
||||
*
|
||||
* Currently we only check for a hash symbol (#) inside the pathname
|
||||
* that is preceded by an archive extension. If path is ever expanded
|
||||
* to a general URI, we should check for that here.
|
||||
*
|
||||
* Example: Somewhere in the path there might be a compressed file
|
||||
* E.g.: /path/to/file.7z#mygame.img
|
||||
*
|
||||
* Returns: true (1) if path contains compressed file, otherwise false (0).
|
||||
**/
|
||||
bool path_contains_compressed_file(const char *path)
|
||||
{
|
||||
return path_get_archive_delim(path) != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* path_is_compressed_file:
|
||||
* @path : path
|
||||
@ -195,21 +168,12 @@ bool path_contains_compressed_file(const char *path)
|
||||
**/
|
||||
bool path_is_compressed_file(const char* path)
|
||||
{
|
||||
#ifdef HAVE_COMPRESSION
|
||||
const char *ext = path_get_extension(path);
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
if (string_is_equal_noncase(ext, "zip") ||
|
||||
string_is_equal_noncase(ext, "apk"))
|
||||
if ( string_is_equal_noncase(ext, "zip")
|
||||
|| string_is_equal_noncase(ext, "apk")
|
||||
|| string_is_equal_noncase(ext, "7z"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_7ZIP
|
||||
if (string_is_equal_noncase(ext, "7z"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -321,6 +285,9 @@ void fill_pathname_slash(char *path, size_t size)
|
||||
if (last_slash && (last_slash != (path + path_len - 1)))
|
||||
{
|
||||
char join_str[2];
|
||||
|
||||
join_str[0] = '\0';
|
||||
|
||||
strlcpy(join_str, last_slash, sizeof(join_str));
|
||||
retro_assert(strlcat(path, join_str, size) < size);
|
||||
}
|
||||
@ -491,13 +458,6 @@ void path_basedir(char *path)
|
||||
if (strlen(path) < 2)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
/* We want to find the directory with the archive in basedir. */
|
||||
last = (char*)path_get_archive_delim(path);
|
||||
if (last)
|
||||
*last = '\0';
|
||||
#endif
|
||||
|
||||
last = find_last_slash(path);
|
||||
|
||||
if (last)
|
||||
@ -531,15 +491,13 @@ void path_parent_dir(char *path)
|
||||
**/
|
||||
const char *path_basename(const char *path)
|
||||
{
|
||||
/* We cut either at the first compression-related hash or the last slash; whichever comes last */
|
||||
const char *last = find_last_slash(path);
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
/* We cut either at the first compression-related hash
|
||||
* or the last slash; whichever comes last */
|
||||
const char *last = find_last_slash(path);
|
||||
const char *delim = path_get_archive_delim(path);
|
||||
|
||||
if (delim)
|
||||
return delim + 1;
|
||||
#endif
|
||||
|
||||
if (last)
|
||||
return last + 1;
|
||||
@ -561,8 +519,10 @@ bool path_is_absolute(const char *path)
|
||||
return true;
|
||||
#ifdef _WIN32
|
||||
/* Many roads lead to Rome ... */
|
||||
if ((strstr(path, "\\\\") == path)
|
||||
|| strstr(path, ":/") || strstr(path, ":\\") || strstr(path, ":\\\\"))
|
||||
if (( strstr(path, "\\\\") == path)
|
||||
|| strstr(path, ":/")
|
||||
|| strstr(path, ":\\")
|
||||
|| strstr(path, ":\\\\"))
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
@ -735,32 +695,13 @@ void fill_short_pathname_representation(char* out_rep,
|
||||
const char *in_path, size_t size)
|
||||
{
|
||||
char path_short[PATH_MAX_LENGTH];
|
||||
#ifdef HAVE_COMPRESSION
|
||||
char *last_slash = NULL;
|
||||
#endif
|
||||
|
||||
path_short[0] = '\0';
|
||||
|
||||
fill_pathname(path_short, path_basename(in_path), "",
|
||||
sizeof(path_short));
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
last_slash = find_last_slash(path_short);
|
||||
if (last_slash != NULL)
|
||||
{
|
||||
/* We handle paths like:
|
||||
* /path/to/file.7z#mygame.img
|
||||
* short_name: mygame.img:
|
||||
*
|
||||
* We check whether something is actually
|
||||
* after the hash to avoid going over the buffer.
|
||||
*/
|
||||
retro_assert(strlen(last_slash) > 1);
|
||||
strlcpy(out_rep, last_slash + 1, size);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
strlcpy(out_rep, path_short, size);
|
||||
strlcpy(out_rep, path_short, size);
|
||||
}
|
||||
|
||||
void fill_short_pathname_representation_noext(char* out_rep,
|
||||
|
@ -72,7 +72,7 @@ bool path_is_compressed_file(const char *path);
|
||||
*
|
||||
* Returns: true (1) if path contains compressed file, otherwise false (0).
|
||||
**/
|
||||
bool path_contains_compressed_file(const char *path);
|
||||
#define path_contains_compressed_file(path) (path_get_archive_delim((path)) != NULL)
|
||||
|
||||
/**
|
||||
* path_file_exists:
|
||||
|
53
include/net/net_http_parse.h
Normal file
53
include/net/net_http_parse.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Copyright (C) 2010-2016 The RetroArch team
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
* The following license statement only applies to this file (net_http.h).
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge,
|
||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _LIBRETRO_SDK_NET_HTTP_PARSE_H
|
||||
#define _LIBRETRO_SDK_NET_HTTP_PARSE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <boolean.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <retro_common_api.h>
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* string_parse_html_anchor:
|
||||
* @line : Buffer where the <a> tag is stored
|
||||
* @link : Buffer to store the link URL in
|
||||
* @name : Buffer to store the link URL in
|
||||
* @link_size : Size of the link buffer including the NUL-terminator
|
||||
* @name_size : Size of the name buffer including the NUL-terminator
|
||||
*
|
||||
* Parses an HTML anchor link stored in @line in the form of: <a href="/path/to/url">Title</a>
|
||||
* The buffer pointed to by @link is filled with the URL path the link points to,
|
||||
* and @name is filled with the title portion of the link.
|
||||
*
|
||||
* Returns: 0 if URL was parsed completely, otherwise 1.
|
||||
**/
|
||||
int string_parse_html_anchor(const char *line, char *link, char *name,
|
||||
size_t link_size, size_t name_size);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
@ -167,7 +167,9 @@ static int parse_dir_entry(const char *name, char *file_path,
|
||||
* NULL in case of error. Has to be freed manually.
|
||||
**/
|
||||
struct string_list *dir_list_new(const char *dir,
|
||||
const char *ext, bool include_dirs, bool include_hidden, bool include_compressed, bool recursive)
|
||||
const char *ext, bool include_dirs,
|
||||
bool include_hidden, bool include_compressed,
|
||||
bool recursive)
|
||||
{
|
||||
struct string_list *ext_list = NULL;
|
||||
struct string_list *list = NULL;
|
||||
@ -178,7 +180,9 @@ struct string_list *dir_list_new(const char *dir,
|
||||
if (ext)
|
||||
ext_list = string_split(ext, "|");
|
||||
|
||||
if(dir_list_read(dir, list, ext_list, include_dirs, include_hidden, include_compressed, recursive) == -1) {
|
||||
if(dir_list_read(dir, list, ext_list, include_dirs,
|
||||
include_hidden, include_compressed, recursive) == -1)
|
||||
{
|
||||
string_list_free(list);
|
||||
string_list_free(ext_list);
|
||||
return NULL;
|
||||
@ -202,7 +206,10 @@ struct string_list *dir_list_new(const char *dir,
|
||||
*
|
||||
* Returns: -1 on error, 0 on success.
|
||||
**/
|
||||
int dir_list_read(const char *dir, struct string_list *list, struct string_list *ext_list, bool include_dirs, bool include_hidden, bool include_compressed, bool recursive)
|
||||
int dir_list_read(const char *dir,
|
||||
struct string_list *list, struct string_list *ext_list,
|
||||
bool include_dirs, bool include_hidden,
|
||||
bool include_compressed, bool recursive)
|
||||
{
|
||||
struct RDIR *entry = retro_opendir(dir);
|
||||
|
||||
@ -241,11 +248,13 @@ int dir_list_read(const char *dir, struct string_list *list, struct string_list
|
||||
continue;
|
||||
}
|
||||
|
||||
if(is_dir && recursive) {
|
||||
if(is_dir && recursive)
|
||||
{
|
||||
if(strstr(name, ".") || strstr(name, ".."))
|
||||
continue;
|
||||
|
||||
dir_list_read(file_path, list, ext_list, include_dirs, include_hidden, include_compressed, recursive);
|
||||
dir_list_read(file_path, list, ext_list, include_dirs,
|
||||
include_hidden, include_compressed, recursive);
|
||||
}
|
||||
|
||||
ret = parse_dir_entry(name, file_path, is_dir,
|
||||
|
99
net/net_http_parse.c
Normal file
99
net/net_http_parse.c
Normal file
@ -0,0 +1,99 @@
|
||||
/* Copyright (C) 2010-2016 The RetroArch team
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
* The following license statement only applies to this file (net_http_parse.c).
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge,
|
||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <compat/strcasestr.h>
|
||||
|
||||
/**
|
||||
* string_parse_html_anchor:
|
||||
* @line : Buffer where the <a> tag is stored
|
||||
* @link : Buffer to store the link URL in
|
||||
* @name : Buffer to store the link URL in
|
||||
* @link_size : Size of the link buffer including the NUL-terminator
|
||||
* @name_size : Size of the name buffer including the NUL-terminator
|
||||
*
|
||||
* Parses an HTML anchor link stored in @line in the form of: <a href="/path/to/url">Title</a>
|
||||
* The buffer pointed to by @link is filled with the URL path the link points to,
|
||||
* and @name is filled with the title portion of the link.
|
||||
*
|
||||
* Returns: 0 if URL was parsed completely, otherwise 1.
|
||||
**/
|
||||
int string_parse_html_anchor(const char *line, char *link, char *name,
|
||||
size_t link_size, size_t name_size)
|
||||
{
|
||||
if (!line || !link || !name)
|
||||
return 1;
|
||||
|
||||
memset(link, 0, link_size);
|
||||
memset(name, 0, name_size);
|
||||
|
||||
if(!(line = strcasestr(line, "<a href=\"")))
|
||||
return 1;
|
||||
else
|
||||
line += 9;
|
||||
|
||||
if (line && *line)
|
||||
{
|
||||
if (!*link)
|
||||
{
|
||||
char *end = strstr(line, "\"");
|
||||
|
||||
if (!end)
|
||||
return 1;
|
||||
|
||||
memcpy(link, line, end - line);
|
||||
|
||||
*(link + (end - line)) = '\0';
|
||||
line += end - line;
|
||||
}
|
||||
|
||||
if (!*name)
|
||||
{
|
||||
char *start = strstr(line, "\">");
|
||||
char *end = strstr(start, "</a>");
|
||||
|
||||
if (!start || !end)
|
||||
return 1;
|
||||
|
||||
memcpy(name, start + 2, end - start - 2);
|
||||
|
||||
*(name + (end - start - 2)) = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef RARCH_INTERNAL
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *line = "<a href=\"http://www.test.com/somefile.zip\">Test</a>\n";
|
||||
char link[1024] = {0};
|
||||
char name[1024] = {0};
|
||||
|
||||
string_parse_html_anchor(line, link, name, sizeof(link), sizeof(name));
|
||||
|
||||
printf("link: %s\nname: %s\n", link, name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user