mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Add net_http_parse
This commit is contained in:
parent
996dbc937a
commit
c739ca016c
2
deps/SPIRV-Cross
vendored
2
deps/SPIRV-Cross
vendored
@ -1 +1 @@
|
||||
Subproject commit cc207e32c8668bfe5a5cc514394e7df8f020ecf6
|
||||
Subproject commit 875c32fd39a06f624814effe5eab691b078429f5
|
2
deps/glslang/glslang
vendored
2
deps/glslang/glslang
vendored
@ -1 +1 @@
|
||||
Subproject commit b56f4ac72c57f5c50f14ddb0bf1f78eaaef21c2b
|
||||
Subproject commit be8462149a3c150fc89db84e57ef06de3ab90d47
|
53
libretro-common/include/net/net_http_parse.h
Normal file
53
libretro-common/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
|
99
libretro-common/net/net_http_parse.c
Normal file
99
libretro-common/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