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
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))
|
||||
|
||||
|
||||
/*
|
||||
* lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" |
|
||||
* "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 ]
|
||||
*/
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* RFC 3986 parser *
|
||||
|
@ -209,8 +207,8 @@ static void uri_clean(URI *uri);
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_scheme(URI *uri, const char **str) {
|
||||
static int rfc3986_parse_scheme(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
if (str == NULL)
|
||||
|
@ -220,8 +218,9 @@ rfc3986_parse_scheme(URI *uri, const char **str) {
|
|||
if (!ISA_ALPHA(cur))
|
||||
return (2);
|
||||
cur++;
|
||||
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) ||
|
||||
(*cur == '+') || (*cur == '-') || (*cur == '.')) cur++;
|
||||
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur == '+') || (*cur == '-') ||
|
||||
(*cur == '.'))
|
||||
cur++;
|
||||
if (uri != NULL) {
|
||||
g_free(uri->scheme);
|
||||
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
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_fragment(URI *uri, const char **str)
|
||||
static int rfc3986_parse_fragment(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
|
@ -281,8 +279,7 @@ rfc3986_parse_fragment(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_query(URI *uri, const char **str)
|
||||
static int rfc3986_parse_query(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
|
@ -314,8 +311,7 @@ rfc3986_parse_query(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_port(URI *uri, const char **str)
|
||||
static int rfc3986_parse_port(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur = *str;
|
||||
int port = 0;
|
||||
|
@ -349,14 +345,13 @@ rfc3986_parse_port(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_user_info(URI *uri, const char **str)
|
||||
static int rfc3986_parse_user_info(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
cur = *str;
|
||||
while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) ||
|
||||
ISA_SUB_DELIM(cur) || (*cur == ':'))
|
||||
while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur) ||
|
||||
(*cur == ':'))
|
||||
NEXT(cur);
|
||||
if (*cur == '@') {
|
||||
if (uri != NULL) {
|
||||
|
@ -386,8 +381,8 @@ rfc3986_parse_user_info(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 if found and skipped, 1 otherwise
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_dec_octet(const char **str) {
|
||||
static int rfc3986_parse_dec_octet(const char **str)
|
||||
{
|
||||
const char *cur = *str;
|
||||
|
||||
if (!(ISA_DIGIT(cur)))
|
||||
|
@ -398,11 +393,11 @@ rfc3986_parse_dec_octet(const char **str) {
|
|||
cur += 2;
|
||||
else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2)))
|
||||
cur += 3;
|
||||
else if ((*cur == '2') && (*(cur + 1) >= '0') &&
|
||||
(*(cur + 1) <= '4') && (ISA_DIGIT(cur + 2)))
|
||||
else if ((*cur == '2') && (*(cur + 1) >= '0') && (*(cur + 1) <= '4') &&
|
||||
(ISA_DIGIT(cur + 2)))
|
||||
cur += 3;
|
||||
else if ((*cur == '2') && (*(cur + 1) == '5') &&
|
||||
(*(cur + 2) >= '0') && (*(cur + 1) <= '5'))
|
||||
else if ((*cur == '2') && (*(cur + 1) == '5') && (*(cur + 2) >= '0') &&
|
||||
(*(cur + 1) <= '5'))
|
||||
cur += 3;
|
||||
else
|
||||
return (1);
|
||||
|
@ -424,8 +419,7 @@ rfc3986_parse_dec_octet(const char **str) {
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_host(URI *uri, const char **str)
|
||||
static int rfc3986_parse_host(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur = *str;
|
||||
const char *host;
|
||||
|
@ -500,8 +494,7 @@ found:
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_authority(URI *uri, const char **str)
|
||||
static int rfc3986_parse_authority(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
int ret;
|
||||
|
@ -516,11 +509,13 @@ rfc3986_parse_authority(URI *uri, const char **str)
|
|||
else
|
||||
cur++;
|
||||
ret = rfc3986_parse_host(uri, &cur);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
if (*cur == ':') {
|
||||
cur++;
|
||||
ret = rfc3986_parse_port(uri, &cur);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
*str = cur;
|
||||
return (0);
|
||||
|
@ -542,8 +537,7 @@ rfc3986_parse_authority(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_segment(const char **str, char forbid, int empty)
|
||||
static int rfc3986_parse_segment(const char **str, char forbid, int empty)
|
||||
{
|
||||
const char *cur;
|
||||
|
||||
|
@ -571,8 +565,7 @@ rfc3986_parse_segment(const char **str, char forbid, int empty)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
||||
static int rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
int ret;
|
||||
|
@ -582,7 +575,8 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
|||
while (*cur == '/') {
|
||||
cur++;
|
||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
if (uri != NULL) {
|
||||
g_free(uri->path);
|
||||
|
@ -611,8 +605,7 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_path_absolute(URI *uri, const char **str)
|
||||
static int rfc3986_parse_path_absolute(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
int ret;
|
||||
|
@ -627,7 +620,8 @@ rfc3986_parse_path_absolute(URI *uri, const char **str)
|
|||
while (*cur == '/') {
|
||||
cur++;
|
||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
if (uri != NULL) {
|
||||
|
@ -657,8 +651,7 @@ rfc3986_parse_path_absolute(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_path_rootless(URI *uri, const char **str)
|
||||
static int rfc3986_parse_path_rootless(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
int ret;
|
||||
|
@ -666,11 +659,13 @@ rfc3986_parse_path_rootless(URI *uri, const char **str)
|
|||
cur = *str;
|
||||
|
||||
ret = rfc3986_parse_segment(&cur, 0, 0);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
while (*cur == '/') {
|
||||
cur++;
|
||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
if (uri != NULL) {
|
||||
g_free(uri->path);
|
||||
|
@ -699,8 +694,7 @@ rfc3986_parse_path_rootless(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
||||
static int rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
int ret;
|
||||
|
@ -708,11 +702,13 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
|||
cur = *str;
|
||||
|
||||
ret = rfc3986_parse_segment(&cur, ':', 0);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
while (*cur == '/') {
|
||||
cur++;
|
||||
ret = rfc3986_parse_segment(&cur, 0, 1);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
if (uri != NULL) {
|
||||
g_free(uri->path);
|
||||
|
@ -744,8 +740,7 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_hier_part(URI *uri, const char **str)
|
||||
static int rfc3986_parse_hier_part(URI *uri, const char **str)
|
||||
{
|
||||
const char *cur;
|
||||
int ret;
|
||||
|
@ -755,17 +750,21 @@ rfc3986_parse_hier_part(URI *uri, const char **str)
|
|||
if ((*cur == '/') && (*(cur + 1) == '/')) {
|
||||
cur += 2;
|
||||
ret = rfc3986_parse_authority(uri, &cur);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = rfc3986_parse_path_ab_empty(uri, &cur);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
*str = cur;
|
||||
return (0);
|
||||
} else if (*cur == '/') {
|
||||
ret = rfc3986_parse_path_absolute(uri, &cur);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
} else if (ISA_PCHAR(cur)) {
|
||||
ret = rfc3986_parse_path_rootless(uri, &cur);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
} else {
|
||||
/* path-empty is effectively empty */
|
||||
if (uri != NULL) {
|
||||
|
@ -793,22 +792,26 @@ rfc3986_parse_hier_part(URI *uri, const char **str)
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_relative_ref(URI *uri, const char *str) {
|
||||
static int rfc3986_parse_relative_ref(URI *uri, const char *str)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((*str == '/') && (*(str + 1) == '/')) {
|
||||
str += 2;
|
||||
ret = rfc3986_parse_authority(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = rfc3986_parse_path_ab_empty(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
} else if (*str == '/') {
|
||||
ret = rfc3986_parse_path_absolute(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
} else if (ISA_PCHAR(str)) {
|
||||
ret = rfc3986_parse_path_no_scheme(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
} else {
|
||||
/* path-empty is effectively empty */
|
||||
if (uri != NULL) {
|
||||
|
@ -820,12 +823,14 @@ rfc3986_parse_relative_ref(URI *uri, const char *str) {
|
|||
if (*str == '?') {
|
||||
str++;
|
||||
ret = rfc3986_parse_query(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
if (*str == '#') {
|
||||
str++;
|
||||
ret = rfc3986_parse_fragment(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
if (*str != 0) {
|
||||
uri_clean(uri);
|
||||
|
@ -834,7 +839,6 @@ rfc3986_parse_relative_ref(URI *uri, const char *str) {
|
|||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* rfc3986_parse:
|
||||
* @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
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse(URI *uri, const char *str) {
|
||||
static int rfc3986_parse(URI *uri, const char *str)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rfc3986_parse_scheme(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
if (*str != ':') {
|
||||
return (1);
|
||||
}
|
||||
str++;
|
||||
ret = rfc3986_parse_hier_part(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
if (*str == '?') {
|
||||
str++;
|
||||
ret = rfc3986_parse_query(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
if (*str == '#') {
|
||||
str++;
|
||||
ret = rfc3986_parse_fragment(uri, &str);
|
||||
if (ret != 0) return(ret);
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
}
|
||||
if (*str != 0) {
|
||||
uri_clean(uri);
|
||||
|
@ -888,8 +896,8 @@ rfc3986_parse(URI *uri, const char *str) {
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
static int
|
||||
rfc3986_parse_uri_reference(URI *uri, const char *str) {
|
||||
static int rfc3986_parse_uri_reference(URI *uri, const char *str)
|
||||
{
|
||||
int ret;
|
||||
|
||||
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
|
||||
*/
|
||||
URI *
|
||||
uri_parse(const char *str) {
|
||||
URI *uri_parse(const char *str)
|
||||
{
|
||||
URI *uri;
|
||||
int ret;
|
||||
|
||||
|
@ -950,8 +958,8 @@ uri_parse(const char *str) {
|
|||
*
|
||||
* Returns 0 or the error code
|
||||
*/
|
||||
int
|
||||
uri_parse_into(URI *uri, const char *str) {
|
||||
int uri_parse_into(URI *uri, const char *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
|
||||
*/
|
||||
URI *
|
||||
uri_parse_raw(const char *str, int raw) {
|
||||
URI *uri_parse_raw(const char *str, int raw)
|
||||
{
|
||||
URI *uri;
|
||||
int ret;
|
||||
|
||||
|
@ -998,8 +1006,8 @@ uri_parse_raw(const char *str, int raw) {
|
|||
*
|
||||
* Returns the new structure or NULL in case of error
|
||||
*/
|
||||
URI *
|
||||
uri_new(void) {
|
||||
URI *uri_new(void)
|
||||
{
|
||||
URI *ret;
|
||||
|
||||
ret = g_new0(URI, 1);
|
||||
|
@ -1012,8 +1020,8 @@ uri_new(void) {
|
|||
* Function to handle properly a reallocation when saving an URI
|
||||
* Also imposes some limit on the length of an URI string output
|
||||
*/
|
||||
static char *
|
||||
realloc2n(char *ret, int *max) {
|
||||
static char *realloc2n(char *ret, int *max)
|
||||
{
|
||||
char *temp;
|
||||
int tmp;
|
||||
|
||||
|
@ -1031,16 +1039,16 @@ realloc2n(char *ret, int *max) {
|
|||
*
|
||||
* Returns a new string (to be deallocated by caller)
|
||||
*/
|
||||
char *
|
||||
uri_to_string(URI *uri) {
|
||||
char *uri_to_string(URI *uri)
|
||||
{
|
||||
char *ret = NULL;
|
||||
char *temp;
|
||||
const char *p;
|
||||
int len;
|
||||
int max;
|
||||
|
||||
if (uri == NULL) return(NULL);
|
||||
|
||||
if (uri == NULL)
|
||||
return (NULL);
|
||||
|
||||
max = 80;
|
||||
ret = g_malloc(max + 1);
|
||||
|
@ -1093,11 +1101,9 @@ uri_to_string(URI *uri) {
|
|||
temp = realloc2n(ret, &max);
|
||||
ret = temp;
|
||||
}
|
||||
if ((IS_UNRESERVED(*(p))) ||
|
||||
((*(p) == ';')) || ((*(p) == ':')) ||
|
||||
((*(p) == '&')) || ((*(p) == '=')) ||
|
||||
((*(p) == '+')) || ((*(p) == '$')) ||
|
||||
((*(p) == ',')))
|
||||
if ((IS_UNRESERVED(*(p))) || ((*(p) == ';')) ||
|
||||
((*(p) == ':')) || ((*(p) == '&')) || ((*(p) == '=')) ||
|
||||
((*(p) == '+')) || ((*(p) == '$')) || ((*(p) == ',')))
|
||||
ret[len++] = *p++;
|
||||
else {
|
||||
int val = *(unsigned char *)p++;
|
||||
|
@ -1141,10 +1147,10 @@ uri_to_string(URI *uri) {
|
|||
temp = realloc2n(ret, &max);
|
||||
ret = temp;
|
||||
}
|
||||
if ((IS_UNRESERVED(*(p))) ||
|
||||
((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
|
||||
((*(p) == ':')) || ((*(p) == '@')) || ((*(p) == '&')) ||
|
||||
((*(p) == '=')) || ((*(p) == '+')))
|
||||
if ((IS_UNRESERVED(*(p))) || ((*(p) == '$')) ||
|
||||
((*(p) == ',')) || ((*(p) == ';')) || ((*(p) == ':')) ||
|
||||
((*(p) == '@')) || ((*(p) == '&')) || ((*(p) == '=')) ||
|
||||
((*(p) == '+')))
|
||||
ret[len++] = *p++;
|
||||
else {
|
||||
int val = *(unsigned char *)p++;
|
||||
|
@ -1168,12 +1174,10 @@ uri_to_string(URI *uri) {
|
|||
* the colon in file:///d: should not be escaped or
|
||||
* Windows accesses fail later.
|
||||
*/
|
||||
if ((uri->scheme != NULL) &&
|
||||
(p[0] == '/') &&
|
||||
if ((uri->scheme != NULL) && (p[0] == '/') &&
|
||||
(((p[1] >= 'a') && (p[1] <= 'z')) ||
|
||||
((p[1] >= 'A') && (p[1] <= 'Z'))) &&
|
||||
(p[2] == ':') &&
|
||||
(!strcmp(uri->scheme, "file"))) {
|
||||
(p[2] == ':') && (!strcmp(uri->scheme, "file"))) {
|
||||
if (len + 3 >= max) {
|
||||
temp = realloc2n(ret, &max);
|
||||
ret = temp;
|
||||
|
@ -1254,9 +1258,10 @@ uri_to_string(URI *uri) {
|
|||
*
|
||||
* Make sure the URI struct is free of content
|
||||
*/
|
||||
static void
|
||||
uri_clean(URI *uri) {
|
||||
if (uri == NULL) return;
|
||||
static void uri_clean(URI *uri)
|
||||
{
|
||||
if (uri == NULL)
|
||||
return;
|
||||
|
||||
g_free(uri->scheme);
|
||||
uri->scheme = NULL;
|
||||
|
@ -1282,8 +1287,8 @@ uri_clean(URI *uri) {
|
|||
*
|
||||
* Free up the URI struct
|
||||
*/
|
||||
void
|
||||
uri_free(URI *uri) {
|
||||
void uri_free(URI *uri)
|
||||
{
|
||||
uri_clean(uri);
|
||||
g_free(uri);
|
||||
}
|
||||
|
@ -1305,8 +1310,8 @@ uri_free(URI *uri) {
|
|||
*
|
||||
* Returns 0 or an error code
|
||||
*/
|
||||
static int
|
||||
normalize_uri_path(char *path) {
|
||||
static int normalize_uri_path(char *path)
|
||||
{
|
||||
char *cur, *out;
|
||||
|
||||
if (path == NULL)
|
||||
|
@ -1409,9 +1414,9 @@ normalize_uri_path(char *path) {
|
|||
* keep this segment and try the next one.
|
||||
*/
|
||||
++segp;
|
||||
if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur+3))
|
||||
|| ((segp[0] != '.') || (segp[1] != '.')
|
||||
|| ((segp[2] != '/') && (segp[2] != '\0')))) {
|
||||
if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur + 3)) ||
|
||||
((segp[0] != '.') || (segp[1] != '.') ||
|
||||
((segp[2] != '/') && (segp[2] != '\0')))) {
|
||||
cur = segp;
|
||||
continue;
|
||||
}
|
||||
|
@ -1468,8 +1473,8 @@ normalize_uri_path(char *path) {
|
|||
*/
|
||||
if (path[0] == '/') {
|
||||
cur = path;
|
||||
while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.')
|
||||
&& ((cur[3] == '/') || (cur[3] == '\0')))
|
||||
while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.') &&
|
||||
((cur[3] == '/') || (cur[3] == '\0')))
|
||||
cur += 3;
|
||||
|
||||
if (cur != path) {
|
||||
|
@ -1483,15 +1488,14 @@ normalize_uri_path(char *path) {
|
|||
return (0);
|
||||
}
|
||||
|
||||
static int is_hex(char c) {
|
||||
if (((c >= '0') && (c <= '9')) ||
|
||||
((c >= 'a') && (c <= 'f')) ||
|
||||
static int is_hex(char c)
|
||||
{
|
||||
if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
|
||||
((c >= 'A') && (c <= 'F')))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* uri_string_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
|
||||
* of error
|
||||
*/
|
||||
char *
|
||||
uri_string_unescape(const char *str, int len, char *target) {
|
||||
char *uri_string_unescape(const char *str, int len, char *target)
|
||||
{
|
||||
char *ret, *out;
|
||||
const char *in;
|
||||
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
if (len <= 0) len = strlen(str);
|
||||
if (len < 0) return(NULL);
|
||||
if (len <= 0)
|
||||
len = strlen(str);
|
||||
if (len < 0)
|
||||
return (NULL);
|
||||
|
||||
if (target == NULL) {
|
||||
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.
|
||||
*/
|
||||
char *
|
||||
uri_string_escape(const char *str, const char *list) {
|
||||
char *uri_string_escape(const char *str, const char *list)
|
||||
{
|
||||
char *ret, ch;
|
||||
char *temp;
|
||||
const char *in;
|
||||
|
@ -1572,7 +1578,8 @@ uri_string_escape(const char *str, const char *list) {
|
|||
if (str[0] == 0)
|
||||
return (g_strdup(str));
|
||||
len = strlen(str);
|
||||
if (!(len > 0)) return(NULL);
|
||||
if (!(len > 0))
|
||||
return (NULL);
|
||||
|
||||
len += 20;
|
||||
ret = g_malloc(len);
|
||||
|
@ -1603,7 +1610,6 @@ uri_string_escape(const char *str, const char *list) {
|
|||
} else {
|
||||
ret[out++] = *in++;
|
||||
}
|
||||
|
||||
}
|
||||
ret[out] = 0;
|
||||
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
|
||||
* of error.
|
||||
*/
|
||||
char *
|
||||
uri_resolve(const char *uri, const char *base) {
|
||||
char *uri_resolve(const char *uri, const char *base)
|
||||
{
|
||||
char *val = NULL;
|
||||
int ret, len, indx, cur, out;
|
||||
URI *ref = NULL;
|
||||
|
@ -1652,8 +1658,7 @@ uri_resolve(const char *uri, const char *base) {
|
|||
if (*uri) {
|
||||
ref = uri_new();
|
||||
ret = uri_parse_into(ref, uri);
|
||||
}
|
||||
else
|
||||
} else
|
||||
ret = 0;
|
||||
}
|
||||
if (ret != 0)
|
||||
|
@ -1769,7 +1774,6 @@ uri_resolve(const char *uri, const char *base) {
|
|||
goto step_7;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 6) If this step is reached, then we are resolving a relative-path
|
||||
* 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
|
||||
* error.
|
||||
*/
|
||||
char *
|
||||
uri_resolve_relative (const char *uri, const char * base)
|
||||
char *uri_resolve_relative(const char *uri, const char *base)
|
||||
{
|
||||
char *val = NULL;
|
||||
int ret;
|
||||
|
@ -1931,8 +1934,7 @@ uri_resolve_relative (const char *uri, const char * base)
|
|||
* just return the URI
|
||||
*/
|
||||
if ((ref->scheme != NULL) &&
|
||||
((bas->scheme == NULL) ||
|
||||
(strcmp (bas->scheme, ref->scheme)) ||
|
||||
((bas->scheme == NULL) || (strcmp(bas->scheme, ref->scheme)) ||
|
||||
(strcmp(bas->server, ref->server)))) {
|
||||
val = g_strdup(uri);
|
||||
goto done;
|
||||
|
@ -2051,8 +2053,8 @@ uri_resolve_relative (const char *uri, const char * base)
|
|||
* Finish up with the end of the URI
|
||||
*/
|
||||
if (uptr != NULL) {
|
||||
if ((vptr > val) && (len > 0) &&
|
||||
(uptr[0] == '/') && (vptr[-1] == '/')) {
|
||||
if ((vptr > val) && (len > 0) && (uptr[0] == '/') &&
|
||||
(vptr[-1] == '/')) {
|
||||
memcpy(vptr, uptr + 1, len - 1);
|
||||
vptr[len - 2] = 0;
|
||||
} else {
|
||||
|
@ -2087,12 +2089,12 @@ done:
|
|||
* Utility functions to help parse and assemble query strings.
|
||||
*/
|
||||
|
||||
struct QueryParams *
|
||||
query_params_new (int init_alloc)
|
||||
struct QueryParams *query_params_new(int init_alloc)
|
||||
{
|
||||
struct QueryParams *ps;
|
||||
|
||||
if (init_alloc <= 0) init_alloc = 1;
|
||||
if (init_alloc <= 0)
|
||||
init_alloc = 1;
|
||||
|
||||
ps = g_new(QueryParams, 1);
|
||||
ps->n = 0;
|
||||
|
@ -2105,9 +2107,8 @@ query_params_new (int init_alloc)
|
|||
/* Ensure there is space to store at least one more parameter
|
||||
* at the end of the set.
|
||||
*/
|
||||
static int
|
||||
query_params_append (struct QueryParams *ps,
|
||||
const char *name, const char *value)
|
||||
static int query_params_append(struct QueryParams *ps, const char *name,
|
||||
const char *value)
|
||||
{
|
||||
if (ps->n >= ps->alloc) {
|
||||
ps->p = g_renew(QueryParam, ps->p, ps->alloc * 2);
|
||||
|
@ -2122,8 +2123,7 @@ query_params_append (struct QueryParams *ps,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
query_params_free (struct QueryParams *ps)
|
||||
void query_params_free(struct QueryParams *ps)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -2135,14 +2135,14 @@ query_params_free (struct QueryParams *ps)
|
|||
g_free(ps);
|
||||
}
|
||||
|
||||
struct QueryParams *
|
||||
query_params_parse (const char *query)
|
||||
struct QueryParams *query_params_parse(const char *query)
|
||||
{
|
||||
struct QueryParams *ps;
|
||||
const char *end, *eq;
|
||||
|
||||
ps = query_params_new(0);
|
||||
if (!query || query[0] == '\0') return ps;
|
||||
if (!query || query[0] == '\0')
|
||||
return ps;
|
||||
|
||||
while (*query) {
|
||||
char *name = NULL, *value = NULL;
|
||||
|
@ -2156,7 +2156,8 @@ query_params_parse (const char *query)
|
|||
|
||||
/* Find the first '=' character between here and end. */
|
||||
eq = strchr(query, '=');
|
||||
if (eq && eq >= end) eq = NULL;
|
||||
if (eq && eq >= end)
|
||||
eq = NULL;
|
||||
|
||||
/* Empty section (eg. "&&"). */
|
||||
if (end == query)
|
||||
|
@ -2195,7 +2196,8 @@ query_params_parse (const char *query)
|
|||
|
||||
next:
|
||||
query = end;
|
||||
if (*query) query ++; /* skip '&' separator */
|
||||
if (*query)
|
||||
query++; /* skip '&' separator */
|
||||
}
|
||||
|
||||
return ps;
|
||||
|
|
Loading…
Reference in New Issue