mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
util/uri.c: Coding style check, Only whitespace involved
Using `clang-format -i util/uri.c` first, then change back few code manually, to make sure only whitespace involved. Signed-off-by: Su Hang <suhang16@mails.ucas.ac.cn> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-id: 1519533358-13759-2-git-send-email-suhang16@mails.ucas.ac.cn Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
136c67e078
commit
be95adaf2b
1 changed files with 726 additions and 724 deletions
286
util/uri.c
286
util/uri.c
|
@ -63,7 +63,6 @@ static void uri_clean(URI *uri);
|
||||||
*/
|
*/
|
||||||
#define IS_ALPHA(x) (IS_LOWALPHA(x) || IS_UPALPHA(x))
|
#define IS_ALPHA(x) (IS_LOWALPHA(x) || IS_UPALPHA(x))
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" |
|
* lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" |
|
||||||
* "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" |
|
* "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" |
|
||||||
|
@ -141,7 +140,6 @@ static void uri_clean(URI *uri);
|
||||||
* path = [ abs_path | opaque_part ]
|
* path = [ abs_path | opaque_part ]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
* RFC 3986 parser *
|
* RFC 3986 parser *
|
||||||
|
@ -209,8 +207,8 @@ static void uri_clean(URI *uri);
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_scheme(URI *uri, const char **str)
|
||||||
rfc3986_parse_scheme(URI *uri, const char **str) {
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
|
@ -220,8 +218,9 @@ rfc3986_parse_scheme(URI *uri, const char **str) {
|
||||||
if (!ISA_ALPHA(cur))
|
if (!ISA_ALPHA(cur))
|
||||||
return (2);
|
return (2);
|
||||||
cur++;
|
cur++;
|
||||||
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) ||
|
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur == '+') || (*cur == '-') ||
|
||||||
(*cur == '+') || (*cur == '-') || (*cur == '.')) cur++;
|
(*cur == '.'))
|
||||||
|
cur++;
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
g_free(uri->scheme);
|
g_free(uri->scheme);
|
||||||
uri->scheme = g_strndup(*str, cur - *str);
|
uri->scheme = g_strndup(*str, cur - *str);
|
||||||
|
@ -245,8 +244,7 @@ rfc3986_parse_scheme(URI *uri, const char **str) {
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_fragment(URI *uri, const char **str)
|
||||||
rfc3986_parse_fragment(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
|
@ -281,8 +279,7 @@ rfc3986_parse_fragment(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_query(URI *uri, const char **str)
|
||||||
rfc3986_parse_query(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
|
@ -314,8 +311,7 @@ rfc3986_parse_query(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_port(URI *uri, const char **str)
|
||||||
rfc3986_parse_port(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur = *str;
|
const char *cur = *str;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
@ -349,14 +345,13 @@ rfc3986_parse_port(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_user_info(URI *uri, const char **str)
|
||||||
rfc3986_parse_user_info(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
cur = *str;
|
cur = *str;
|
||||||
while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) ||
|
while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur) ||
|
||||||
ISA_SUB_DELIM(cur) || (*cur == ':'))
|
(*cur == ':'))
|
||||||
NEXT(cur);
|
NEXT(cur);
|
||||||
if (*cur == '@') {
|
if (*cur == '@') {
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
|
@ -386,8 +381,8 @@ rfc3986_parse_user_info(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 if found and skipped, 1 otherwise
|
* Returns 0 if found and skipped, 1 otherwise
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_dec_octet(const char **str)
|
||||||
rfc3986_parse_dec_octet(const char **str) {
|
{
|
||||||
const char *cur = *str;
|
const char *cur = *str;
|
||||||
|
|
||||||
if (!(ISA_DIGIT(cur)))
|
if (!(ISA_DIGIT(cur)))
|
||||||
|
@ -398,11 +393,11 @@ rfc3986_parse_dec_octet(const char **str) {
|
||||||
cur += 2;
|
cur += 2;
|
||||||
else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2)))
|
else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2)))
|
||||||
cur += 3;
|
cur += 3;
|
||||||
else if ((*cur == '2') && (*(cur + 1) >= '0') &&
|
else if ((*cur == '2') && (*(cur + 1) >= '0') && (*(cur + 1) <= '4') &&
|
||||||
(*(cur + 1) <= '4') && (ISA_DIGIT(cur + 2)))
|
(ISA_DIGIT(cur + 2)))
|
||||||
cur += 3;
|
cur += 3;
|
||||||
else if ((*cur == '2') && (*(cur + 1) == '5') &&
|
else if ((*cur == '2') && (*(cur + 1) == '5') && (*(cur + 2) >= '0') &&
|
||||||
(*(cur + 2) >= '0') && (*(cur + 1) <= '5'))
|
(*(cur + 1) <= '5'))
|
||||||
cur += 3;
|
cur += 3;
|
||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
|
@ -424,8 +419,7 @@ rfc3986_parse_dec_octet(const char **str) {
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_host(URI *uri, const char **str)
|
||||||
rfc3986_parse_host(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur = *str;
|
const char *cur = *str;
|
||||||
const char *host;
|
const char *host;
|
||||||
|
@ -500,8 +494,7 @@ found:
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_authority(URI *uri, const char **str)
|
||||||
rfc3986_parse_authority(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -516,11 +509,13 @@ rfc3986_parse_authority(URI *uri, const char **str)
|
||||||
else
|
else
|
||||||
cur++;
|
cur++;
|
||||||
ret = rfc3986_parse_host(uri, &cur);
|
ret = rfc3986_parse_host(uri, &cur);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
if (*cur == ':') {
|
if (*cur == ':') {
|
||||||
cur++;
|
cur++;
|
||||||
ret = rfc3986_parse_port(uri, &cur);
|
ret = rfc3986_parse_port(uri, &cur);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -542,8 +537,7 @@ rfc3986_parse_authority(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_segment(const char **str, char forbid, int empty)
|
||||||
rfc3986_parse_segment(const char **str, char forbid, int empty)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
|
@ -571,8 +565,7 @@ rfc3986_parse_segment(const char **str, char forbid, int empty)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
||||||
rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -582,7 +575,8 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
||||||
while (*cur == '/') {
|
while (*cur == '/') {
|
||||||
cur++;
|
cur++;
|
||||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
g_free(uri->path);
|
g_free(uri->path);
|
||||||
|
@ -611,8 +605,7 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_path_absolute(URI *uri, const char **str)
|
||||||
rfc3986_parse_path_absolute(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -627,7 +620,8 @@ rfc3986_parse_path_absolute(URI *uri, const char **str)
|
||||||
while (*cur == '/') {
|
while (*cur == '/') {
|
||||||
cur++;
|
cur++;
|
||||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
|
@ -657,8 +651,7 @@ rfc3986_parse_path_absolute(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_path_rootless(URI *uri, const char **str)
|
||||||
rfc3986_parse_path_rootless(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -666,11 +659,13 @@ rfc3986_parse_path_rootless(URI *uri, const char **str)
|
||||||
cur = *str;
|
cur = *str;
|
||||||
|
|
||||||
ret = rfc3986_parse_segment(&cur, 0, 0);
|
ret = rfc3986_parse_segment(&cur, 0, 0);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
while (*cur == '/') {
|
while (*cur == '/') {
|
||||||
cur++;
|
cur++;
|
||||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
g_free(uri->path);
|
g_free(uri->path);
|
||||||
|
@ -699,8 +694,7 @@ rfc3986_parse_path_rootless(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
||||||
rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -708,11 +702,13 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
||||||
cur = *str;
|
cur = *str;
|
||||||
|
|
||||||
ret = rfc3986_parse_segment(&cur, ':', 0);
|
ret = rfc3986_parse_segment(&cur, ':', 0);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
while (*cur == '/') {
|
while (*cur == '/') {
|
||||||
cur++;
|
cur++;
|
||||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
g_free(uri->path);
|
g_free(uri->path);
|
||||||
|
@ -744,8 +740,7 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_hier_part(URI *uri, const char **str)
|
||||||
rfc3986_parse_hier_part(URI *uri, const char **str)
|
|
||||||
{
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -755,17 +750,21 @@ rfc3986_parse_hier_part(URI *uri, const char **str)
|
||||||
if ((*cur == '/') && (*(cur + 1) == '/')) {
|
if ((*cur == '/') && (*(cur + 1) == '/')) {
|
||||||
cur += 2;
|
cur += 2;
|
||||||
ret = rfc3986_parse_authority(uri, &cur);
|
ret = rfc3986_parse_authority(uri, &cur);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
ret = rfc3986_parse_path_ab_empty(uri, &cur);
|
ret = rfc3986_parse_path_ab_empty(uri, &cur);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return (0);
|
return (0);
|
||||||
} else if (*cur == '/') {
|
} else if (*cur == '/') {
|
||||||
ret = rfc3986_parse_path_absolute(uri, &cur);
|
ret = rfc3986_parse_path_absolute(uri, &cur);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
} else if (ISA_PCHAR(cur)) {
|
} else if (ISA_PCHAR(cur)) {
|
||||||
ret = rfc3986_parse_path_rootless(uri, &cur);
|
ret = rfc3986_parse_path_rootless(uri, &cur);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
} else {
|
} else {
|
||||||
/* path-empty is effectively empty */
|
/* path-empty is effectively empty */
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
|
@ -793,22 +792,26 @@ rfc3986_parse_hier_part(URI *uri, const char **str)
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_relative_ref(URI *uri, const char *str)
|
||||||
rfc3986_parse_relative_ref(URI *uri, const char *str) {
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((*str == '/') && (*(str + 1) == '/')) {
|
if ((*str == '/') && (*(str + 1) == '/')) {
|
||||||
str += 2;
|
str += 2;
|
||||||
ret = rfc3986_parse_authority(uri, &str);
|
ret = rfc3986_parse_authority(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
ret = rfc3986_parse_path_ab_empty(uri, &str);
|
ret = rfc3986_parse_path_ab_empty(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
} else if (*str == '/') {
|
} else if (*str == '/') {
|
||||||
ret = rfc3986_parse_path_absolute(uri, &str);
|
ret = rfc3986_parse_path_absolute(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
} else if (ISA_PCHAR(str)) {
|
} else if (ISA_PCHAR(str)) {
|
||||||
ret = rfc3986_parse_path_no_scheme(uri, &str);
|
ret = rfc3986_parse_path_no_scheme(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
} else {
|
} else {
|
||||||
/* path-empty is effectively empty */
|
/* path-empty is effectively empty */
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
|
@ -820,12 +823,14 @@ rfc3986_parse_relative_ref(URI *uri, const char *str) {
|
||||||
if (*str == '?') {
|
if (*str == '?') {
|
||||||
str++;
|
str++;
|
||||||
ret = rfc3986_parse_query(uri, &str);
|
ret = rfc3986_parse_query(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
if (*str == '#') {
|
if (*str == '#') {
|
||||||
str++;
|
str++;
|
||||||
ret = rfc3986_parse_fragment(uri, &str);
|
ret = rfc3986_parse_fragment(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
if (*str != 0) {
|
if (*str != 0) {
|
||||||
uri_clean(uri);
|
uri_clean(uri);
|
||||||
|
@ -834,7 +839,6 @@ rfc3986_parse_relative_ref(URI *uri, const char *str) {
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rfc3986_parse:
|
* rfc3986_parse:
|
||||||
* @uri: pointer to an URI structure
|
* @uri: pointer to an URI structure
|
||||||
|
@ -847,27 +851,31 @@ rfc3986_parse_relative_ref(URI *uri, const char *str) {
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse(URI *uri, const char *str)
|
||||||
rfc3986_parse(URI *uri, const char *str) {
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = rfc3986_parse_scheme(uri, &str);
|
ret = rfc3986_parse_scheme(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
if (*str != ':') {
|
if (*str != ':') {
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
str++;
|
str++;
|
||||||
ret = rfc3986_parse_hier_part(uri, &str);
|
ret = rfc3986_parse_hier_part(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
if (*str == '?') {
|
if (*str == '?') {
|
||||||
str++;
|
str++;
|
||||||
ret = rfc3986_parse_query(uri, &str);
|
ret = rfc3986_parse_query(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
if (*str == '#') {
|
if (*str == '#') {
|
||||||
str++;
|
str++;
|
||||||
ret = rfc3986_parse_fragment(uri, &str);
|
ret = rfc3986_parse_fragment(uri, &str);
|
||||||
if (ret != 0) return(ret);
|
if (ret != 0)
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
if (*str != 0) {
|
if (*str != 0) {
|
||||||
uri_clean(uri);
|
uri_clean(uri);
|
||||||
|
@ -888,8 +896,8 @@ rfc3986_parse(URI *uri, const char *str) {
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int rfc3986_parse_uri_reference(URI *uri, const char *str)
|
||||||
rfc3986_parse_uri_reference(URI *uri, const char *str) {
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
|
@ -922,8 +930,8 @@ rfc3986_parse_uri_reference(URI *uri, const char *str) {
|
||||||
*
|
*
|
||||||
* Returns a newly built URI or NULL in case of error
|
* Returns a newly built URI or NULL in case of error
|
||||||
*/
|
*/
|
||||||
URI *
|
URI *uri_parse(const char *str)
|
||||||
uri_parse(const char *str) {
|
{
|
||||||
URI *uri;
|
URI *uri;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -950,8 +958,8 @@ uri_parse(const char *str) {
|
||||||
*
|
*
|
||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
int
|
int uri_parse_into(URI *uri, const char *str)
|
||||||
uri_parse_into(URI *uri, const char *str) {
|
{
|
||||||
return (rfc3986_parse_uri_reference(uri, str));
|
return (rfc3986_parse_uri_reference(uri, str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -966,8 +974,8 @@ uri_parse_into(URI *uri, const char *str) {
|
||||||
*
|
*
|
||||||
* Returns a newly built URI or NULL in case of error
|
* Returns a newly built URI or NULL in case of error
|
||||||
*/
|
*/
|
||||||
URI *
|
URI *uri_parse_raw(const char *str, int raw)
|
||||||
uri_parse_raw(const char *str, int raw) {
|
{
|
||||||
URI *uri;
|
URI *uri;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -998,8 +1006,8 @@ uri_parse_raw(const char *str, int raw) {
|
||||||
*
|
*
|
||||||
* Returns the new structure or NULL in case of error
|
* Returns the new structure or NULL in case of error
|
||||||
*/
|
*/
|
||||||
URI *
|
URI *uri_new(void)
|
||||||
uri_new(void) {
|
{
|
||||||
URI *ret;
|
URI *ret;
|
||||||
|
|
||||||
ret = g_new0(URI, 1);
|
ret = g_new0(URI, 1);
|
||||||
|
@ -1012,8 +1020,8 @@ uri_new(void) {
|
||||||
* Function to handle properly a reallocation when saving an URI
|
* Function to handle properly a reallocation when saving an URI
|
||||||
* Also imposes some limit on the length of an URI string output
|
* Also imposes some limit on the length of an URI string output
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *realloc2n(char *ret, int *max)
|
||||||
realloc2n(char *ret, int *max) {
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
|
@ -1031,16 +1039,16 @@ realloc2n(char *ret, int *max) {
|
||||||
*
|
*
|
||||||
* Returns a new string (to be deallocated by caller)
|
* Returns a new string (to be deallocated by caller)
|
||||||
*/
|
*/
|
||||||
char *
|
char *uri_to_string(URI *uri)
|
||||||
uri_to_string(URI *uri) {
|
{
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
char *temp;
|
char *temp;
|
||||||
const char *p;
|
const char *p;
|
||||||
int len;
|
int len;
|
||||||
int max;
|
int max;
|
||||||
|
|
||||||
if (uri == NULL) return(NULL);
|
if (uri == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
max = 80;
|
max = 80;
|
||||||
ret = g_malloc(max + 1);
|
ret = g_malloc(max + 1);
|
||||||
|
@ -1093,11 +1101,9 @@ uri_to_string(URI *uri) {
|
||||||
temp = realloc2n(ret, &max);
|
temp = realloc2n(ret, &max);
|
||||||
ret = temp;
|
ret = temp;
|
||||||
}
|
}
|
||||||
if ((IS_UNRESERVED(*(p))) ||
|
if ((IS_UNRESERVED(*(p))) || ((*(p) == ';')) ||
|
||||||
((*(p) == ';')) || ((*(p) == ':')) ||
|
((*(p) == ':')) || ((*(p) == '&')) || ((*(p) == '=')) ||
|
||||||
((*(p) == '&')) || ((*(p) == '=')) ||
|
((*(p) == '+')) || ((*(p) == '$')) || ((*(p) == ',')))
|
||||||
((*(p) == '+')) || ((*(p) == '$')) ||
|
|
||||||
((*(p) == ',')))
|
|
||||||
ret[len++] = *p++;
|
ret[len++] = *p++;
|
||||||
else {
|
else {
|
||||||
int val = *(unsigned char *)p++;
|
int val = *(unsigned char *)p++;
|
||||||
|
@ -1141,10 +1147,10 @@ uri_to_string(URI *uri) {
|
||||||
temp = realloc2n(ret, &max);
|
temp = realloc2n(ret, &max);
|
||||||
ret = temp;
|
ret = temp;
|
||||||
}
|
}
|
||||||
if ((IS_UNRESERVED(*(p))) ||
|
if ((IS_UNRESERVED(*(p))) || ((*(p) == '$')) ||
|
||||||
((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
|
((*(p) == ',')) || ((*(p) == ';')) || ((*(p) == ':')) ||
|
||||||
((*(p) == ':')) || ((*(p) == '@')) || ((*(p) == '&')) ||
|
((*(p) == '@')) || ((*(p) == '&')) || ((*(p) == '=')) ||
|
||||||
((*(p) == '=')) || ((*(p) == '+')))
|
((*(p) == '+')))
|
||||||
ret[len++] = *p++;
|
ret[len++] = *p++;
|
||||||
else {
|
else {
|
||||||
int val = *(unsigned char *)p++;
|
int val = *(unsigned char *)p++;
|
||||||
|
@ -1168,12 +1174,10 @@ uri_to_string(URI *uri) {
|
||||||
* the colon in file:///d: should not be escaped or
|
* the colon in file:///d: should not be escaped or
|
||||||
* Windows accesses fail later.
|
* Windows accesses fail later.
|
||||||
*/
|
*/
|
||||||
if ((uri->scheme != NULL) &&
|
if ((uri->scheme != NULL) && (p[0] == '/') &&
|
||||||
(p[0] == '/') &&
|
|
||||||
(((p[1] >= 'a') && (p[1] <= 'z')) ||
|
(((p[1] >= 'a') && (p[1] <= 'z')) ||
|
||||||
((p[1] >= 'A') && (p[1] <= 'Z'))) &&
|
((p[1] >= 'A') && (p[1] <= 'Z'))) &&
|
||||||
(p[2] == ':') &&
|
(p[2] == ':') && (!strcmp(uri->scheme, "file"))) {
|
||||||
(!strcmp(uri->scheme, "file"))) {
|
|
||||||
if (len + 3 >= max) {
|
if (len + 3 >= max) {
|
||||||
temp = realloc2n(ret, &max);
|
temp = realloc2n(ret, &max);
|
||||||
ret = temp;
|
ret = temp;
|
||||||
|
@ -1254,9 +1258,10 @@ uri_to_string(URI *uri) {
|
||||||
*
|
*
|
||||||
* Make sure the URI struct is free of content
|
* Make sure the URI struct is free of content
|
||||||
*/
|
*/
|
||||||
static void
|
static void uri_clean(URI *uri)
|
||||||
uri_clean(URI *uri) {
|
{
|
||||||
if (uri == NULL) return;
|
if (uri == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
g_free(uri->scheme);
|
g_free(uri->scheme);
|
||||||
uri->scheme = NULL;
|
uri->scheme = NULL;
|
||||||
|
@ -1282,8 +1287,8 @@ uri_clean(URI *uri) {
|
||||||
*
|
*
|
||||||
* Free up the URI struct
|
* Free up the URI struct
|
||||||
*/
|
*/
|
||||||
void
|
void uri_free(URI *uri)
|
||||||
uri_free(URI *uri) {
|
{
|
||||||
uri_clean(uri);
|
uri_clean(uri);
|
||||||
g_free(uri);
|
g_free(uri);
|
||||||
}
|
}
|
||||||
|
@ -1305,8 +1310,8 @@ uri_free(URI *uri) {
|
||||||
*
|
*
|
||||||
* Returns 0 or an error code
|
* Returns 0 or an error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int normalize_uri_path(char *path)
|
||||||
normalize_uri_path(char *path) {
|
{
|
||||||
char *cur, *out;
|
char *cur, *out;
|
||||||
|
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
|
@ -1409,9 +1414,9 @@ normalize_uri_path(char *path) {
|
||||||
* keep this segment and try the next one.
|
* keep this segment and try the next one.
|
||||||
*/
|
*/
|
||||||
++segp;
|
++segp;
|
||||||
if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur+3))
|
if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur + 3)) ||
|
||||||
|| ((segp[0] != '.') || (segp[1] != '.')
|
((segp[0] != '.') || (segp[1] != '.') ||
|
||||||
|| ((segp[2] != '/') && (segp[2] != '\0')))) {
|
((segp[2] != '/') && (segp[2] != '\0')))) {
|
||||||
cur = segp;
|
cur = segp;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1468,8 +1473,8 @@ normalize_uri_path(char *path) {
|
||||||
*/
|
*/
|
||||||
if (path[0] == '/') {
|
if (path[0] == '/') {
|
||||||
cur = path;
|
cur = path;
|
||||||
while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.')
|
while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.') &&
|
||||||
&& ((cur[3] == '/') || (cur[3] == '\0')))
|
((cur[3] == '/') || (cur[3] == '\0')))
|
||||||
cur += 3;
|
cur += 3;
|
||||||
|
|
||||||
if (cur != path) {
|
if (cur != path) {
|
||||||
|
@ -1483,15 +1488,14 @@ normalize_uri_path(char *path) {
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_hex(char c) {
|
static int is_hex(char c)
|
||||||
if (((c >= '0') && (c <= '9')) ||
|
{
|
||||||
((c >= 'a') && (c <= 'f')) ||
|
if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
|
||||||
((c >= 'A') && (c <= 'F')))
|
((c >= 'A') && (c <= 'F')))
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uri_string_unescape:
|
* uri_string_unescape:
|
||||||
* @str: the string to unescape
|
* @str: the string to unescape
|
||||||
|
@ -1506,15 +1510,17 @@ static int is_hex(char c) {
|
||||||
* Returns a copy of the string, but unescaped, will return NULL only in case
|
* Returns a copy of the string, but unescaped, will return NULL only in case
|
||||||
* of error
|
* of error
|
||||||
*/
|
*/
|
||||||
char *
|
char *uri_string_unescape(const char *str, int len, char *target)
|
||||||
uri_string_unescape(const char *str, int len, char *target) {
|
{
|
||||||
char *ret, *out;
|
char *ret, *out;
|
||||||
const char *in;
|
const char *in;
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (len <= 0) len = strlen(str);
|
if (len <= 0)
|
||||||
if (len < 0) return(NULL);
|
len = strlen(str);
|
||||||
|
if (len < 0)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
if (target == NULL) {
|
if (target == NULL) {
|
||||||
ret = g_malloc(len + 1);
|
ret = g_malloc(len + 1);
|
||||||
|
@ -1560,8 +1566,8 @@ uri_string_unescape(const char *str, int len, char *target) {
|
||||||
*
|
*
|
||||||
* Returns a new escaped string or NULL in case of error.
|
* Returns a new escaped string or NULL in case of error.
|
||||||
*/
|
*/
|
||||||
char *
|
char *uri_string_escape(const char *str, const char *list)
|
||||||
uri_string_escape(const char *str, const char *list) {
|
{
|
||||||
char *ret, ch;
|
char *ret, ch;
|
||||||
char *temp;
|
char *temp;
|
||||||
const char *in;
|
const char *in;
|
||||||
|
@ -1572,7 +1578,8 @@ uri_string_escape(const char *str, const char *list) {
|
||||||
if (str[0] == 0)
|
if (str[0] == 0)
|
||||||
return (g_strdup(str));
|
return (g_strdup(str));
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
if (!(len > 0)) return(NULL);
|
if (!(len > 0))
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
len += 20;
|
len += 20;
|
||||||
ret = g_malloc(len);
|
ret = g_malloc(len);
|
||||||
|
@ -1603,7 +1610,6 @@ uri_string_escape(const char *str, const char *list) {
|
||||||
} else {
|
} else {
|
||||||
ret[out++] = *in++;
|
ret[out++] = *in++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
ret[out] = 0;
|
ret[out] = 0;
|
||||||
return (ret);
|
return (ret);
|
||||||
|
@ -1630,8 +1636,8 @@ uri_string_escape(const char *str, const char *list) {
|
||||||
* Returns a new URI string (to be freed by the caller) or NULL in case
|
* Returns a new URI string (to be freed by the caller) or NULL in case
|
||||||
* of error.
|
* of error.
|
||||||
*/
|
*/
|
||||||
char *
|
char *uri_resolve(const char *uri, const char *base)
|
||||||
uri_resolve(const char *uri, const char *base) {
|
{
|
||||||
char *val = NULL;
|
char *val = NULL;
|
||||||
int ret, len, indx, cur, out;
|
int ret, len, indx, cur, out;
|
||||||
URI *ref = NULL;
|
URI *ref = NULL;
|
||||||
|
@ -1652,8 +1658,7 @@ uri_resolve(const char *uri, const char *base) {
|
||||||
if (*uri) {
|
if (*uri) {
|
||||||
ref = uri_new();
|
ref = uri_new();
|
||||||
ret = uri_parse_into(ref, uri);
|
ret = uri_parse_into(ref, uri);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
|
@ -1769,7 +1774,6 @@ uri_resolve(const char *uri, const char *base) {
|
||||||
goto step_7;
|
goto step_7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 6) If this step is reached, then we are resolving a relative-path
|
* 6) If this step is reached, then we are resolving a relative-path
|
||||||
* reference. The relative path needs to be merged with the base
|
* reference. The relative path needs to be merged with the base
|
||||||
|
@ -1882,8 +1886,7 @@ done:
|
||||||
* Returns a new URI string (to be freed by the caller) or NULL in case
|
* Returns a new URI string (to be freed by the caller) or NULL in case
|
||||||
* error.
|
* error.
|
||||||
*/
|
*/
|
||||||
char *
|
char *uri_resolve_relative(const char *uri, const char *base)
|
||||||
uri_resolve_relative (const char *uri, const char * base)
|
|
||||||
{
|
{
|
||||||
char *val = NULL;
|
char *val = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -1931,8 +1934,7 @@ uri_resolve_relative (const char *uri, const char * base)
|
||||||
* just return the URI
|
* just return the URI
|
||||||
*/
|
*/
|
||||||
if ((ref->scheme != NULL) &&
|
if ((ref->scheme != NULL) &&
|
||||||
((bas->scheme == NULL) ||
|
((bas->scheme == NULL) || (strcmp(bas->scheme, ref->scheme)) ||
|
||||||
(strcmp (bas->scheme, ref->scheme)) ||
|
|
||||||
(strcmp(bas->server, ref->server)))) {
|
(strcmp(bas->server, ref->server)))) {
|
||||||
val = g_strdup(uri);
|
val = g_strdup(uri);
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -2051,8 +2053,8 @@ uri_resolve_relative (const char *uri, const char * base)
|
||||||
* Finish up with the end of the URI
|
* Finish up with the end of the URI
|
||||||
*/
|
*/
|
||||||
if (uptr != NULL) {
|
if (uptr != NULL) {
|
||||||
if ((vptr > val) && (len > 0) &&
|
if ((vptr > val) && (len > 0) && (uptr[0] == '/') &&
|
||||||
(uptr[0] == '/') && (vptr[-1] == '/')) {
|
(vptr[-1] == '/')) {
|
||||||
memcpy(vptr, uptr + 1, len - 1);
|
memcpy(vptr, uptr + 1, len - 1);
|
||||||
vptr[len - 2] = 0;
|
vptr[len - 2] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2087,12 +2089,12 @@ done:
|
||||||
* Utility functions to help parse and assemble query strings.
|
* Utility functions to help parse and assemble query strings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct QueryParams *
|
struct QueryParams *query_params_new(int init_alloc)
|
||||||
query_params_new (int init_alloc)
|
|
||||||
{
|
{
|
||||||
struct QueryParams *ps;
|
struct QueryParams *ps;
|
||||||
|
|
||||||
if (init_alloc <= 0) init_alloc = 1;
|
if (init_alloc <= 0)
|
||||||
|
init_alloc = 1;
|
||||||
|
|
||||||
ps = g_new(QueryParams, 1);
|
ps = g_new(QueryParams, 1);
|
||||||
ps->n = 0;
|
ps->n = 0;
|
||||||
|
@ -2105,9 +2107,8 @@ query_params_new (int init_alloc)
|
||||||
/* Ensure there is space to store at least one more parameter
|
/* Ensure there is space to store at least one more parameter
|
||||||
* at the end of the set.
|
* at the end of the set.
|
||||||
*/
|
*/
|
||||||
static int
|
static int query_params_append(struct QueryParams *ps, const char *name,
|
||||||
query_params_append (struct QueryParams *ps,
|
const char *value)
|
||||||
const char *name, const char *value)
|
|
||||||
{
|
{
|
||||||
if (ps->n >= ps->alloc) {
|
if (ps->n >= ps->alloc) {
|
||||||
ps->p = g_renew(QueryParam, ps->p, ps->alloc * 2);
|
ps->p = g_renew(QueryParam, ps->p, ps->alloc * 2);
|
||||||
|
@ -2122,8 +2123,7 @@ query_params_append (struct QueryParams *ps,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void query_params_free(struct QueryParams *ps)
|
||||||
query_params_free (struct QueryParams *ps)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -2135,14 +2135,14 @@ query_params_free (struct QueryParams *ps)
|
||||||
g_free(ps);
|
g_free(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct QueryParams *
|
struct QueryParams *query_params_parse(const char *query)
|
||||||
query_params_parse (const char *query)
|
|
||||||
{
|
{
|
||||||
struct QueryParams *ps;
|
struct QueryParams *ps;
|
||||||
const char *end, *eq;
|
const char *end, *eq;
|
||||||
|
|
||||||
ps = query_params_new(0);
|
ps = query_params_new(0);
|
||||||
if (!query || query[0] == '\0') return ps;
|
if (!query || query[0] == '\0')
|
||||||
|
return ps;
|
||||||
|
|
||||||
while (*query) {
|
while (*query) {
|
||||||
char *name = NULL, *value = NULL;
|
char *name = NULL, *value = NULL;
|
||||||
|
@ -2156,7 +2156,8 @@ query_params_parse (const char *query)
|
||||||
|
|
||||||
/* Find the first '=' character between here and end. */
|
/* Find the first '=' character between here and end. */
|
||||||
eq = strchr(query, '=');
|
eq = strchr(query, '=');
|
||||||
if (eq && eq >= end) eq = NULL;
|
if (eq && eq >= end)
|
||||||
|
eq = NULL;
|
||||||
|
|
||||||
/* Empty section (eg. "&&"). */
|
/* Empty section (eg. "&&"). */
|
||||||
if (end == query)
|
if (end == query)
|
||||||
|
@ -2195,7 +2196,8 @@ query_params_parse (const char *query)
|
||||||
|
|
||||||
next:
|
next:
|
||||||
query = end;
|
query = end;
|
||||||
if (*query) query ++; /* skip '&' separator */
|
if (*query)
|
||||||
|
query++; /* skip '&' separator */
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue