From nobody Fri Oct 24 09:56:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519113848103725.7839553032405; Tue, 20 Feb 2018 00:04:08 -0800 (PST) Received: from localhost ([::1]:54040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eo2u9-0006JX-HV for importer@patchew.org; Tue, 20 Feb 2018 03:04:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eo2tA-0005xO-KK for qemu-devel@nongnu.org; Tue, 20 Feb 2018 03:03:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eo2t5-0000ft-KT for qemu-devel@nongnu.org; Tue, 20 Feb 2018 03:03:00 -0500 Received: from smtp15.cstnet.cn ([159.226.251.15]:45272 helo=cstnet.cn) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eo2t4-0000d6-BL for qemu-devel@nongnu.org; Tue, 20 Feb 2018 03:02:55 -0500 Received: from localhost.localdomain (unknown [27.26.22.65]) by APP-06 (Coremail) with SMTP id zgCowABXNwwn1otabDXqDA--.54S3; Tue, 20 Feb 2018 16:02:47 +0800 (CST) From: Su Hang To: thuth@redhat.com, stefanha@redhat.com Date: Tue, 20 Feb 2018 16:02:40 +0800 Message-Id: <1519113760-4474-1-git-send-email-suhang16@mails.ucas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: zgCowABXNwwn1otabDXqDA--.54S3 X-Coremail-Antispam: 1UD129KBjvAXoWfury7WFy5Aw17AF4xAF45GFg_yoWrJw1xCo W8twn8Xwn8Gwnagr1F9ryvgFWDXa109w1DAa1Sgryjka40vrn8XrWkuw4xXayqgw18X3y7 Wr18W34IgrW7ZrWxn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUY57k0a2IF6w4kM7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0 x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj4 1l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0 I7IYx2IY6xkF7I0E14v26r1j6r4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwV C2z280aVCY1x0267AKxVWxJr0_GcWlnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8I j28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF 1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxG rwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr 0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6Fyj6rWUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI 42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07bYMKtUUUUU= X-CM-SenderInfo: pvxkt0rjrwqzpdlo2hpxfd2hldfou0/ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 159.226.251.15 Subject: [Qemu-devel] [PATCH v2] util/uri.c formating X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Formating the code with `clang-format -i util/uri.c`. My .clang-format file content is: ''' IndentWidth: 4 BreakBeforeBraces: Linux ''' Then use `perl -pi -e "s/return \((.*?)\);/return \1;/g" util/uri.c` to remove pattern like this: "return (1);" checkpatch.pl still rise these two kinds of "ERROR", I'm not sure whether I should also suppress these, so I left it. ''' ERROR: braces {} are necessary even for single statement blocks #1803: FILE: uri.c:1803: + while ((bas->path[cur] !=3D 0) && (bas->path[cur] !=3D '/')) + cur++; ERROR: braces {} are necessary for all arms of this statement #1805: FILE: uri.c:1805: + if (bas->path[cur] =3D=3D 0) [...] ''' Signed-off-by: Su Hang --- util/uri.c | 611 +++++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 307 insertions(+), 304 deletions(-) diff --git a/util/uri.c b/util/uri.c index aa1c2da00c17..b01ae0ccb075 100644 --- a/util/uri.c +++ b/util/uri.c @@ -63,7 +63,6 @@ static void uri_clean(URI *uri); */ #define IS_ALPHA(x) (IS_LOWALPHA(x) || IS_UPALPHA(x)) - /* * lowalpha =3D "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | * "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | @@ -97,27 +96,28 @@ static void uri_clean(URI *uri); * mark =3D "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" */ -#define IS_MARK(x) (((x) =3D=3D '-') || ((x) =3D=3D '_') || ((x) =3D=3D '.= ') || \ - ((x) =3D=3D '!') || ((x) =3D=3D '~') || ((x) =3D=3D '*') || ((x) = =3D=3D '\'') || \ - ((x) =3D=3D '(') || ((x) =3D=3D ')')) +#define IS_MARK(x) = \ + (((x) =3D=3D '-') || ((x) =3D=3D '_') || ((x) =3D=3D '.') || ((x) =3D= =3D '!') || \ + ((x) =3D=3D '~') || ((x) =3D=3D '*') || ((x) =3D=3D '\'') || ((x) =3D= =3D '(') || \ + ((x) =3D=3D ')')) /* * unwise =3D "{" | "}" | "|" | "\" | "^" | "`" */ -#define IS_UNWISE(p) \ - (((*(p) =3D=3D '{')) || ((*(p) =3D=3D '}')) || ((*(p) =3D=3D '|')) || = \ - ((*(p) =3D=3D '\\')) || ((*(p) =3D=3D '^')) || ((*(p) =3D=3D '[')) ||= \ +#define IS_UNWISE(p) = \ + (((*(p) =3D=3D '{')) || ((*(p) =3D=3D '}')) || ((*(p) =3D=3D '|')) || = \ + ((*(p) =3D=3D '\\')) || ((*(p) =3D=3D '^')) || ((*(p) =3D=3D '[')) ||= \ ((*(p) =3D=3D ']')) || ((*(p) =3D=3D '`'))) /* * reserved =3D ";" | "/" | "?" | ":" | "@" | "&" | "=3D" | "+" | "$" | ",= " | * "[" | "]" */ -#define IS_RESERVED(x) (((x) =3D=3D ';') || ((x) =3D=3D '/') || ((x) =3D= =3D '?') || \ - ((x) =3D=3D ':') || ((x) =3D=3D '@') || ((x) =3D=3D '&') || ((x) = =3D=3D '=3D') || \ - ((x) =3D=3D '+') || ((x) =3D=3D '$') || ((x) =3D=3D ',') || ((x) = =3D=3D '[') || \ - ((x) =3D=3D ']')) +#define IS_RESERVED(x) = \ + (((x) =3D=3D ';') || ((x) =3D=3D '/') || ((x) =3D=3D '?') || ((x) =3D= =3D ':') || \ + ((x) =3D=3D '@') || ((x) =3D=3D '&') || ((x) =3D=3D '=3D') || ((x) = =3D=3D '+') || \ + ((x) =3D=3D '$') || ((x) =3D=3D ',') || ((x) =3D=3D '[') || ((x) =3D= =3D ']')) /* * unreserved =3D alphanum | mark @@ -129,7 +129,7 @@ static void uri_clean(URI *uri); * Skip to next pointer char, handle escaped sequences */ -#define NEXT(p) ((*p =3D=3D '%')? p +=3D 3 : p++) +#define NEXT(p) ((*p =3D=3D '%') ? p +=3D 3 : p++) /* * Productions from the spec. @@ -141,37 +141,35 @@ static void uri_clean(URI *uri); * path =3D [ abs_path | opaque_part ] */ - /************************************************************************ - * * - * RFC 3986 parser * - * * + * * + * RFC 3986 parser * + * * ************************************************************************/ #define ISA_DIGIT(p) ((*(p) >=3D '0') && (*(p) <=3D '9')) -#define ISA_ALPHA(p) (((*(p) >=3D 'a') && (*(p) <=3D 'z')) || \ - ((*(p) >=3D 'A') && (*(p) <=3D 'Z'))) -#define ISA_HEXDIG(p) \ - (ISA_DIGIT(p) || ((*(p) >=3D 'a') && (*(p) <=3D 'f')) || \ +#define ISA_ALPHA(p) = \ + (((*(p) >=3D 'a') && (*(p) <=3D 'z')) || ((*(p) >=3D 'A') && (*(p) <= =3D 'Z'))) +#define ISA_HEXDIG(p) = \ + (ISA_DIGIT(p) || ((*(p) >=3D 'a') && (*(p) <=3D 'f')) || = \ ((*(p) >=3D 'A') && (*(p) <=3D 'F'))) /* * sub-delims =3D "!" / "$" / "&" / "'" / "(" / ")" * / "*" / "+" / "," / ";" / "=3D" */ -#define ISA_SUB_DELIM(p) \ - (((*(p) =3D=3D '!')) || ((*(p) =3D=3D '$')) || ((*(p) =3D=3D '&')) || = \ - ((*(p) =3D=3D '(')) || ((*(p) =3D=3D ')')) || ((*(p) =3D=3D '*')) || = \ - ((*(p) =3D=3D '+')) || ((*(p) =3D=3D ',')) || ((*(p) =3D=3D ';')) || = \ +#define ISA_SUB_DELIM(p) = \ + (((*(p) =3D=3D '!')) || ((*(p) =3D=3D '$')) || ((*(p) =3D=3D '&')) || = \ + ((*(p) =3D=3D '(')) || ((*(p) =3D=3D ')')) || ((*(p) =3D=3D '*')) || = \ + ((*(p) =3D=3D '+')) || ((*(p) =3D=3D ',')) || ((*(p) =3D=3D ';')) || = \ ((*(p) =3D=3D '=3D')) || ((*(p) =3D=3D '\''))) /* * gen-delims =3D ":" / "/" / "?" / "#" / "[" / "]" / "@" */ -#define ISA_GEN_DELIM(p) \ - (((*(p) =3D=3D ':')) || ((*(p) =3D=3D '/')) || ((*(p) =3D=3D '?')) || = \ - ((*(p) =3D=3D '#')) || ((*(p) =3D=3D '[')) || ((*(p) =3D=3D ']')) || = \ - ((*(p) =3D=3D '@'))) +#define ISA_GEN_DELIM(p) = \ + (((*(p) =3D=3D ':')) || ((*(p) =3D=3D '/')) || ((*(p) =3D=3D '?')) || = \ + ((*(p) =3D=3D '#')) || ((*(p) =3D=3D '[')) || ((*(p) =3D=3D ']')) || = ((*(p) =3D=3D '@'))) /* * reserved =3D gen-delims / sub-delims @@ -181,21 +179,21 @@ static void uri_clean(URI *uri); /* * unreserved =3D ALPHA / DIGIT / "-" / "." / "_" / "~" */ -#define ISA_UNRESERVED(p) \ - ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) =3D=3D '-')) || \ - ((*(p) =3D=3D '.')) || ((*(p) =3D=3D '_')) || ((*(p) =3D=3D '~'))) +#define ISA_UNRESERVED(p) = \ + ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) =3D=3D '-')) || ((*(p) =3D= =3D '.')) || \ + ((*(p) =3D=3D '_')) || ((*(p) =3D=3D '~'))) /* * pct-encoded =3D "%" HEXDIG HEXDIG */ -#define ISA_PCT_ENCODED(p) \ +#define ISA_PCT_ENCODED(p) = \ ((*(p) =3D=3D '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2))) /* * pchar =3D unreserved / pct-encoded / sub-delims / ":" / "@" */ -#define ISA_PCHAR(p) \ - (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) || \ +#define ISA_PCHAR(p) = \ + (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) || = \ ((*(p) =3D=3D ':')) || ((*(p) =3D=3D '@'))) /** @@ -209,25 +207,27 @@ 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 =3D=3D NULL) - return(-1); + if (str =3D=3D NULL) { + return -1; + } cur =3D *str; if (!ISA_ALPHA(cur)) - return(2); + return 2; cur++; - while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || - (*cur =3D=3D '+') || (*cur =3D=3D '-') || (*cur =3D=3D '.')) c= ur++; + while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur =3D=3D '+') || (*cur = =3D=3D '-') || + (*cur =3D=3D '.')) + cur++; if (uri !=3D NULL) { g_free(uri->scheme); uri->scheme =3D g_strndup(*str, cur - *str); } *str =3D cur; - return(0); + return 0; } /** @@ -245,19 +245,18 @@ 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; if (str =3D=3D NULL) - return (-1); + return -1; cur =3D *str; while ((ISA_PCHAR(cur)) || (*cur =3D=3D '/') || (*cur =3D=3D '?') || - (*cur =3D=3D '[') || (*cur =3D=3D ']') || - ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) + (*cur =3D=3D '[') || (*cur =3D=3D ']') || + ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) NEXT(cur); if (uri !=3D NULL) { g_free(uri->fragment); @@ -267,7 +266,7 @@ rfc3986_parse_fragment(URI *uri, const char **str) uri->fragment =3D uri_string_unescape(*str, cur - *str, NULL); } *str =3D cur; - return (0); + return 0; } /** @@ -281,25 +280,24 @@ 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; if (str =3D=3D NULL) - return (-1); + return -1; cur =3D *str; while ((ISA_PCHAR(cur)) || (*cur =3D=3D '/') || (*cur =3D=3D '?') || - ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) + ((uri !=3D NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) NEXT(cur); if (uri !=3D NULL) { g_free(uri->query); - uri->query =3D g_strndup (*str, cur - *str); + uri->query =3D g_strndup(*str, cur - *str); } *str =3D cur; - return (0); + return 0; } /** @@ -314,8 +312,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 =3D *str; int port =3D 0; @@ -349,14 +346,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 =3D *str; - while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || - ISA_SUB_DELIM(cur) || (*cur =3D=3D ':')) + while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cu= r) || + (*cur =3D=3D ':')) NEXT(cur); if (*cur =3D=3D '@') { if (uri !=3D NULL) { @@ -367,9 +363,9 @@ rfc3986_parse_user_info(URI *uri, const char **str) uri->user =3D uri_string_unescape(*str, cur - *str, NULL); } *str =3D cur; - return(0); + return 0; } - return(1); + return 1; } /** @@ -386,28 +382,28 @@ 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 =3D *str; if (!(ISA_DIGIT(cur))) - return(1); - if (!ISA_DIGIT(cur+1)) + return 1; + if (!ISA_DIGIT(cur + 1)) cur++; - else if ((*cur !=3D '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur+2)= )) + else if ((*cur !=3D '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + = 2))) cur +=3D 2; else if ((*cur =3D=3D '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur += 2))) cur +=3D 3; - else if ((*cur =3D=3D '2') && (*(cur + 1) >=3D '0') && - (*(cur + 1) <=3D '4') && (ISA_DIGIT(cur + 2))) + else if ((*cur =3D=3D '2') && (*(cur + 1) >=3D '0') && (*(cur + 1) <= =3D '4') && + (ISA_DIGIT(cur + 2))) cur +=3D 3; - else if ((*cur =3D=3D '2') && (*(cur + 1) =3D=3D '5') && - (*(cur + 2) >=3D '0') && (*(cur + 1) <=3D '5')) + else if ((*cur =3D=3D '2') && (*(cur + 1) =3D=3D '5') && (*(cur + 2) >= =3D '0') && + (*(cur + 1) <=3D '5')) cur +=3D 3; else - return(1); + return 1; *str =3D cur; - return(0); + return 0; } /** * rfc3986_parse_host: @@ -424,8 +420,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 =3D *str; const char *host; @@ -439,7 +434,7 @@ rfc3986_parse_host(URI *uri, const char **str) while ((*cur !=3D ']') && (*cur !=3D 0)) cur++; if (*cur !=3D ']') - return(1); + return 1; cur++; goto found; } @@ -463,7 +458,7 @@ rfc3986_parse_host(URI *uri, const char **str) if (rfc3986_parse_dec_octet(&cur) !=3D 0) goto not_ipv4; goto found; -not_ipv4: + not_ipv4: cur =3D *str; } /* @@ -485,7 +480,7 @@ found: uri->server =3D NULL; } *str =3D cur; - return(0); + return 0; } /** @@ -500,8 +495,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,14 +510,16 @@ rfc3986_parse_authority(URI *uri, const char **str) else cur++; ret =3D rfc3986_parse_host(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; if (*cur =3D=3D ':') { cur++; ret =3D rfc3986_parse_port(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } *str =3D cur; - return(0); + return 0; } /** @@ -542,21 +538,20 @@ 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; cur =3D *str; if (!ISA_PCHAR(cur)) { if (empty) - return(0); - return(1); + return 0; + return 1; } while (ISA_PCHAR(cur) && (*cur !=3D forbid)) NEXT(cur); *str =3D cur; - return (0); + return 0; } /** @@ -571,8 +566,7 @@ rfc3986_parse_segment(const char **str, char forbid, in= t 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 +576,8 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str) while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } if (uri !=3D NULL) { g_free(uri->path); @@ -596,7 +591,7 @@ rfc3986_parse_path_ab_empty(URI *uri, const char **str) } } *str =3D cur; - return (0); + return 0; } /** @@ -611,8 +606,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; @@ -620,14 +614,15 @@ rfc3986_parse_path_absolute(URI *uri, const char **st= r) cur =3D *str; if (*cur !=3D '/') - return(1); + return 1; cur++; ret =3D rfc3986_parse_segment(&cur, 0, 0); if (ret =3D=3D 0) { while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } } if (uri !=3D NULL) { @@ -642,7 +637,7 @@ rfc3986_parse_path_absolute(URI *uri, const char **str) } } *str =3D cur; - return (0); + return 0; } /** @@ -657,8 +652,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 +660,13 @@ rfc3986_parse_path_rootless(URI *uri, const char **st= r) cur =3D *str; ret =3D rfc3986_parse_segment(&cur, 0, 0); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } if (uri !=3D NULL) { g_free(uri->path); @@ -684,7 +680,7 @@ rfc3986_parse_path_rootless(URI *uri, const char **str) } } *str =3D cur; - return (0); + return 0; } /** @@ -699,8 +695,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 +703,13 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **s= tr) cur =3D *str; ret =3D rfc3986_parse_segment(&cur, ':', 0); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; while (*cur =3D=3D '/') { cur++; ret =3D rfc3986_parse_segment(&cur, 0, 1); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } if (uri !=3D NULL) { g_free(uri->path); @@ -726,7 +723,7 @@ rfc3986_parse_path_no_scheme(URI *uri, const char **str) } } *str =3D cur; - return (0); + return 0; } /** @@ -744,8 +741,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 +751,21 @@ rfc3986_parse_hier_part(URI *uri, const char **str) if ((*cur =3D=3D '/') && (*(cur + 1) =3D=3D '/')) { cur +=3D 2; ret =3D rfc3986_parse_authority(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; ret =3D rfc3986_parse_path_ab_empty(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; *str =3D cur; - return(0); + return 0; } else if (*cur =3D=3D '/') { ret =3D rfc3986_parse_path_absolute(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } else if (ISA_PCHAR(cur)) { ret =3D rfc3986_parse_path_rootless(uri, &cur); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } else { /* path-empty is effectively empty */ if (uri !=3D NULL) { @@ -774,7 +774,7 @@ rfc3986_parse_hier_part(URI *uri, const char **str) } } *str =3D cur; - return (0); + return 0; } /** @@ -793,22 +793,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 =3D=3D '/') && (*(str + 1) =3D=3D '/')) { str +=3D 2; ret =3D rfc3986_parse_authority(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; ret =3D rfc3986_parse_path_ab_empty(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } else if (*str =3D=3D '/') { ret =3D rfc3986_parse_path_absolute(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } else if (ISA_PCHAR(str)) { ret =3D rfc3986_parse_path_no_scheme(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } else { /* path-empty is effectively empty */ if (uri !=3D NULL) { @@ -820,21 +824,22 @@ rfc3986_parse_relative_ref(URI *uri, const char *str)= { if (*str =3D=3D '?') { str++; ret =3D rfc3986_parse_query(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } if (*str =3D=3D '#') { str++; ret =3D rfc3986_parse_fragment(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } if (*str !=3D 0) { uri_clean(uri); - return(1); + return 1; } - return(0); + return 0; } - /** * rfc3986_parse: * @uri: pointer to an URI structure @@ -847,33 +852,37 @@ 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 =3D rfc3986_parse_scheme(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; if (*str !=3D ':') { - return(1); + return 1; } str++; ret =3D rfc3986_parse_hier_part(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; if (*str =3D=3D '?') { str++; ret =3D rfc3986_parse_query(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } if (*str =3D=3D '#') { str++; ret =3D rfc3986_parse_fragment(uri, &str); - if (ret !=3D 0) return(ret); + if (ret !=3D 0) + return ret; } if (*str !=3D 0) { uri_clean(uri); - return(1); + return 1; } - return(0); + return 0; } /** @@ -888,12 +897,12 @@ 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 =3D=3D NULL) - return(-1); + return -1; uri_clean(uri); /* @@ -906,10 +915,10 @@ rfc3986_parse_uri_reference(URI *uri, const char *str= ) { ret =3D rfc3986_parse_relative_ref(uri, str); if (ret !=3D 0) { uri_clean(uri); - return(ret); + return ret; } } - return(0); + return 0; } /** @@ -922,20 +931,20 @@ 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; if (str =3D=3D NULL) - return(NULL); + return NULL; uri =3D uri_new(); ret =3D rfc3986_parse_uri_reference(uri, str); if (ret) { uri_free(uri); - return(NULL); + return NULL; } - return(uri); + return uri; } /** @@ -950,9 +959,9 @@ uri_parse(const char *str) { * * Returns 0 or the error code */ -int -uri_parse_into(URI *uri, const char *str) { - return(rfc3986_parse_uri_reference(uri, str)); +int uri_parse_into(URI *uri, const char *str) +{ + return rfc3986_parse_uri_reference(uri, str); } /** @@ -966,13 +975,13 @@ 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; if (str =3D=3D NULL) - return(NULL); + return NULL; uri =3D uri_new(); if (raw) { uri->cleanup |=3D 2; @@ -980,15 +989,15 @@ uri_parse_raw(const char *str, int raw) { ret =3D uri_parse_into(uri, str); if (ret) { uri_free(uri); - return(NULL); + return NULL; } - return(uri); + return uri; } /************************************************************************ - * * - * Generic URI structure functions * - * * + * * + * Generic URI structure functions * + * * ************************************************************************/ /** @@ -998,12 +1007,12 @@ 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 =3D g_new0(URI, 1); - return(ret); + return ret; } /** @@ -1012,15 +1021,15 @@ 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; tmp =3D *max * 2; temp =3D g_realloc(ret, (tmp + 1)); *max =3D tmp; - return(temp); + return temp; } /** @@ -1031,16 +1040,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 =3D NULL; char *temp; const char *p; int len; int max; - if (uri =3D=3D NULL) return(NULL); - + if (uri =3D=3D NULL) + return NULL; max =3D 80; ret =3D g_malloc(max + 1); @@ -1074,8 +1083,8 @@ uri_to_string(URI *uri) { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); } } } else { @@ -1093,18 +1102,16 @@ uri_to_string(URI *uri) { temp =3D realloc2n(ret, &max); ret =3D temp; } - if ((IS_UNRESERVED(*(p))) || - ((*(p) =3D=3D ';')) || ((*(p) =3D=3D ':')) || - ((*(p) =3D=3D '&')) || ((*(p) =3D=3D '=3D')) || - ((*(p) =3D=3D '+')) || ((*(p) =3D=3D '$')) || - ((*(p) =3D=3D ','))) + if ((IS_UNRESERVED(*(p))) || ((*(p) =3D=3D ';')) || + ((*(p) =3D=3D ':')) || ((*(p) =3D=3D '&')) || ((*(= p) =3D=3D '=3D')) || + ((*(p) =3D=3D '+')) || ((*(p) =3D=3D '$')) || ((*(= p) =3D=3D ','))) ret[len++] =3D *p++; else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); } } if (len + 3 >=3D max) { @@ -1141,17 +1148,17 @@ uri_to_string(URI *uri) { temp =3D realloc2n(ret, &max); ret =3D temp; } - if ((IS_UNRESERVED(*(p))) || - ((*(p) =3D=3D '$')) || ((*(p) =3D=3D ',')) || ((*(= p) =3D=3D ';')) || - ((*(p) =3D=3D ':')) || ((*(p) =3D=3D '@')) || ((*(= p) =3D=3D '&')) || - ((*(p) =3D=3D '=3D')) || ((*(p) =3D=3D '+'))) + if ((IS_UNRESERVED(*(p))) || ((*(p) =3D=3D '$')) || + ((*(p) =3D=3D ',')) || ((*(p) =3D=3D ';')) || ((*(p) = =3D=3D ':')) || + ((*(p) =3D=3D '@')) || ((*(p) =3D=3D '&')) || ((*(p) = =3D=3D '=3D')) || + ((*(p) =3D=3D '+'))) ret[len++] =3D *p++; else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); } } } else if (uri->scheme !=3D NULL) { @@ -1168,12 +1175,10 @@ uri_to_string(URI *uri) { * the colon in file:///d: should not be escaped or * Windows accesses fail later. */ - if ((uri->scheme !=3D NULL) && - (p[0] =3D=3D '/') && - (((p[1] >=3D 'a') && (p[1] <=3D 'z')) || - ((p[1] >=3D 'A') && (p[1] <=3D 'Z'))) && - (p[2] =3D=3D ':') && - (!strcmp(uri->scheme, "file"))) { + if ((uri->scheme !=3D NULL) && (p[0] =3D=3D '/') && + (((p[1] >=3D 'a') && (p[1] <=3D 'z')) || + ((p[1] >=3D 'A') && (p[1] <=3D 'Z'))) && + (p[2] =3D=3D ':') && (!strcmp(uri->scheme, "file"))) { if (len + 3 >=3D max) { temp =3D realloc2n(ret, &max); ret =3D temp; @@ -1188,16 +1193,16 @@ uri_to_string(URI *uri) { ret =3D temp; } if ((IS_UNRESERVED(*(p))) || ((*(p) =3D=3D '/')) || - ((*(p) =3D=3D ';')) || ((*(p) =3D=3D '@')) || ((*(= p) =3D=3D '&')) || - ((*(p) =3D=3D '=3D')) || ((*(p) =3D=3D '+')) || ((= *(p) =3D=3D '$')) || - ((*(p) =3D=3D ','))) + ((*(p) =3D=3D ';')) || ((*(p) =3D=3D '@')) || ((*(p) = =3D=3D '&')) || + ((*(p) =3D=3D '=3D')) || ((*(p) =3D=3D '+')) || ((*(p)= =3D=3D '$')) || + ((*(p) =3D=3D ','))) ret[len++] =3D *p++; else { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); } } } @@ -1235,8 +1240,8 @@ uri_to_string(URI *uri) { int val =3D *(unsigned char *)p++; int hi =3D val / 0x10, lo =3D val % 0x10; ret[len++] =3D '%'; - ret[len++] =3D hi + (hi > 9? 'A'-10 : '0'); - ret[len++] =3D lo + (lo > 9? 'A'-10 : '0'); + ret[len++] =3D hi + (hi > 9 ? 'A' - 10 : '0'); + ret[len++] =3D lo + (lo > 9 ? 'A' - 10 : '0'); } } } @@ -1245,7 +1250,7 @@ uri_to_string(URI *uri) { ret =3D temp; } ret[len] =3D 0; - return(ret); + return ret; } /** @@ -1254,9 +1259,10 @@ uri_to_string(URI *uri) { * * Make sure the URI struct is free of content */ -static void -uri_clean(URI *uri) { - if (uri =3D=3D NULL) return; +static void uri_clean(URI *uri) +{ + if (uri =3D=3D NULL) + return; g_free(uri->scheme); uri->scheme =3D NULL; @@ -1282,16 +1288,16 @@ 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); } /************************************************************************ - * * - * Helper functions * - * * + * * + * Helper functions * + * * ************************************************************************/ /** @@ -1305,12 +1311,12 @@ 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 =3D=3D NULL) - return(-1); + return -1; /* Skip all initial "/" chars. We want to get to the beginning of the * first non-empty segment. @@ -1319,7 +1325,7 @@ normalize_uri_path(char *path) { while (cur[0] =3D=3D '/') ++cur; if (cur[0] =3D=3D '\0') - return(0); + return 0; /* Keep everything we've seen so far. */ out =3D cur; @@ -1367,7 +1373,7 @@ done_cd: while (cur[0] =3D=3D '/') ++cur; if (cur[0] =3D=3D '\0') - return(0); + return 0; /* * Analyze each segment in sequence for cases (e) and (f). @@ -1409,9 +1415,9 @@ done_cd: * keep this segment and try the next one. */ ++segp; - if (((cur[0] =3D=3D '.') && (cur[1] =3D=3D '.') && (segp =3D=3D cu= r+3)) - || ((segp[0] !=3D '.') || (segp[1] !=3D '.') - || ((segp[2] !=3D '/') && (segp[2] !=3D '\0')))) { + if (((cur[0] =3D=3D '.') && (cur[1] =3D=3D '.') && (segp =3D=3D cu= r + 3)) || + ((segp[0] !=3D '.') || (segp[1] !=3D '.') || + ((segp[2] !=3D '/') && (segp[2] !=3D '\0')))) { cur =3D segp; continue; } @@ -1468,8 +1474,8 @@ done_cd: */ if (path[0] =3D=3D '/') { cur =3D path; - while ((cur[0] =3D=3D '/') && (cur[1] =3D=3D '.') && (cur[2] =3D= =3D '.') - && ((cur[3] =3D=3D '/') || (cur[3] =3D=3D '\0'))) + while ((cur[0] =3D=3D '/') && (cur[1] =3D=3D '.') && (cur[2] =3D= =3D '.') && + ((cur[3] =3D=3D '/') || (cur[3] =3D=3D '\0'))) cur +=3D 3; if (cur !=3D path) { @@ -1480,18 +1486,17 @@ done_cd: } } - return(0); + return 0; } -static int is_hex(char c) { - if (((c >=3D '0') && (c <=3D '9')) || - ((c >=3D 'a') && (c <=3D 'f')) || - ((c >=3D 'A') && (c <=3D 'F'))) - return(1); - return(0); +static int is_hex(char c) +{ + if (((c >=3D '0') && (c <=3D '9')) || ((c >=3D 'a') && (c <=3D 'f')) || + ((c >=3D 'A') && (c <=3D 'F'))) + return 1; + return 0; } - /** * uri_string_unescape: * @str: the string to unescape @@ -1506,15 +1511,17 @@ static int is_hex(char c) { * Returns a copy of the string, but unescaped, will return NULL only in c= ase * 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 =3D=3D NULL) - return(NULL); - if (len <=3D 0) len =3D strlen(str); - if (len < 0) return(NULL); + return NULL; + if (len <=3D 0) + len =3D strlen(str); + if (len < 0) + return NULL; if (target =3D=3D NULL) { ret =3D g_malloc(len + 1); @@ -1522,7 +1529,7 @@ uri_string_unescape(const char *str, int len, char *t= arget) { ret =3D target; in =3D str; out =3D ret; - while(len > 0) { + while (len > 0) { if ((len > 2) && (*in =3D=3D '%') && (is_hex(in[1])) && (is_hex(in= [2]))) { in++; if ((*in >=3D '0') && (*in <=3D '9')) @@ -1547,7 +1554,7 @@ uri_string_unescape(const char *str, int len, char *t= arget) { } } *out =3D 0; - return(ret); + return ret; } /** @@ -1560,25 +1567,26 @@ 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; int len, out; if (str =3D=3D NULL) - return(NULL); + return NULL; if (str[0] =3D=3D 0) - return(g_strdup(str)); + return g_strdup(str); len =3D strlen(str); - if (!(len > 0)) return(NULL); + if (!(len > 0)) + return NULL; len +=3D 20; ret =3D g_malloc(len); in =3D str; out =3D 0; - while(*in !=3D 0) { + while (*in !=3D 0) { if (len - out <=3D 3) { temp =3D realloc2n(ret, &len); ret =3D temp; @@ -1603,16 +1611,15 @@ uri_string_escape(const char *str, const char *list= ) { } else { ret[out++] =3D *in++; } - } ret[out] =3D 0; - return(ret); + return ret; } /************************************************************************ - * * - * Public functions * - * * + * * + * Public functions * + * * ************************************************************************/ /** @@ -1630,8 +1637,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 =3D NULL; int ret, len, indx, cur, out; URI *ref =3D NULL; @@ -1652,8 +1659,7 @@ uri_resolve(const char *uri, const char *base) { if (*uri) { ref =3D uri_new(); ret =3D uri_parse_into(ref, uri); - } - else + } else ret =3D 0; } if (ret !=3D 0) @@ -1700,7 +1706,7 @@ uri_resolve(const char *uri, const char *base) { */ res =3D uri_new(); if ((ref->scheme =3D=3D NULL) && (ref->path =3D=3D NULL) && - ((ref->authority =3D=3D NULL) && (ref->server =3D=3D NULL))) { + ((ref->authority =3D=3D NULL) && (ref->server =3D=3D NULL))) { res->scheme =3D g_strdup(bas->scheme); if (bas->authority !=3D NULL) res->authority =3D g_strdup(bas->authority); @@ -1711,7 +1717,7 @@ uri_resolve(const char *uri, const char *base) { } res->path =3D g_strdup(bas->path); if (ref->query !=3D NULL) { - res->query =3D g_strdup (ref->query); + res->query =3D g_strdup(ref->query); } else { res->query =3D g_strdup(bas->query); } @@ -1769,7 +1775,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 @@ -1847,7 +1852,7 @@ done: uri_free(bas); if (res !=3D NULL) uri_free(res); - return(val); + return val; } /** @@ -1882,8 +1887,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 =3D NULL; int ret; @@ -1902,12 +1906,12 @@ uri_resolve_relative (const char *uri, const char *= base) /* * First parse URI into a standard form */ - ref =3D uri_new (); + ref =3D uri_new(); /* If URI not already in "relative" form */ if (uri[0] !=3D '.') { - ret =3D uri_parse_into (ref, uri); + ret =3D uri_parse_into(ref, uri); if (ret !=3D 0) - goto done; /* Error in URI, return NULL */ + goto done; /* Error in URI, return NULL */ } else ref->path =3D g_strdup(uri); @@ -1915,14 +1919,14 @@ uri_resolve_relative (const char *uri, const char *= base) * Next parse base into the same standard form */ if ((base =3D=3D NULL) || (*base =3D=3D 0)) { - val =3D g_strdup (uri); + val =3D g_strdup(uri); goto done; } - bas =3D uri_new (); + bas =3D uri_new(); if (base[0] !=3D '.') { - ret =3D uri_parse_into (bas, base); + ret =3D uri_parse_into(bas, base); if (ret !=3D 0) - goto done; /* Error in base, return NULL */ + goto done; /* Error in base, return NULL */ } else bas->path =3D g_strdup(base); @@ -1931,14 +1935,13 @@ uri_resolve_relative (const char *uri, const char *= base) * just return the URI */ if ((ref->scheme !=3D NULL) && - ((bas->scheme =3D=3D NULL) || - (strcmp (bas->scheme, ref->scheme)) || - (strcmp (bas->server, ref->server)))) { - val =3D g_strdup (uri); + ((bas->scheme =3D=3D NULL) || (strcmp(bas->scheme, ref->scheme)) || + (strcmp(bas->server, ref->server)))) { + val =3D g_strdup(uri); goto done; } if (bas->path =3D=3D ref->path || - (bas->path && ref->path && !strcmp(bas->path, ref->path))) { + (bas->path && ref->path && !strcmp(bas->path, ref->path))) { val =3D g_strdup(""); goto done; } @@ -1947,7 +1950,7 @@ uri_resolve_relative (const char *uri, const char * b= ase) goto done; } if (ref->path =3D=3D NULL) { - ref->path =3D (char *) "/"; + ref->path =3D (char *)"/"; remove_path =3D 1; } @@ -1974,12 +1977,12 @@ uri_resolve_relative (const char *uri, const char *= base) nbslash++; } uptr =3D NULL; - len =3D 1; /* this is for a string terminator only */ + len =3D 1; /* this is for a string terminator only */ } else { /* * Next we compare the two strings and find where they first differ */ - if ((ref->path[pos] =3D=3D '.') && (ref->path[pos+1] =3D=3D '/')) + if ((ref->path[pos] =3D=3D '.') && (ref->path[pos + 1] =3D=3D '/')) pos +=3D 2; if ((*bptr =3D=3D '.') && (bptr[1] =3D=3D '/')) bptr +=3D 2; @@ -1990,7 +1993,7 @@ uri_resolve_relative (const char *uri, const char * b= ase) if (bptr[pos] =3D=3D ref->path[pos]) { val =3D g_strdup(""); - goto done; /* (I can't imagine why anyone would do this) */ + goto done; /* (I can't imagine why anyone would do this) */ } /* @@ -2016,13 +2019,13 @@ uri_resolve_relative (const char *uri, const char *= base) /* * In base, count the number of '/' from the differing point */ - if (bptr[pos] !=3D ref->path[pos]) {/* check for trivial URI =3D= =3D base */ + if (bptr[pos] !=3D ref->path[pos]) { /* check for trivial URI =3D= =3D base */ for (; bptr[ix] !=3D 0; ix++) { if (bptr[ix] =3D=3D '/') nbslash++; } } - len =3D strlen (uptr) + 1; + len =3D strlen(uptr) + 1; } if (nbslash =3D=3D 0) { @@ -2037,12 +2040,12 @@ uri_resolve_relative (const char *uri, const char *= base) * length of the remainder of the URI, plus enough space * for the "../" groups, plus one for the terminator */ - val =3D g_malloc (len + 3 * nbslash); + val =3D g_malloc(len + 3 * nbslash); vptr =3D val; /* * Put in as many "../" as needed */ - for (; nbslash>0; nbslash--) { + for (; nbslash > 0; nbslash--) { *vptr++ =3D '.'; *vptr++ =3D '.'; *vptr++ =3D '/'; @@ -2051,12 +2054,12 @@ uri_resolve_relative (const char *uri, const char *= base) * Finish up with the end of the URI */ if (uptr !=3D NULL) { - if ((vptr > val) && (len > 0) && - (uptr[0] =3D=3D '/') && (vptr[-1] =3D=3D '/')) { - memcpy (vptr, uptr + 1, len - 1); + if ((vptr > val) && (len > 0) && (uptr[0] =3D=3D '/') && + (vptr[-1] =3D=3D '/')) { + memcpy(vptr, uptr + 1, len - 1); vptr[len - 2] =3D 0; } else { - memcpy (vptr, uptr, len); + memcpy(vptr, uptr, len); vptr[len - 1] =3D 0; } } else { @@ -2076,9 +2079,9 @@ done: if (remove_path !=3D 0) ref->path =3D NULL; if (ref !=3D NULL) - uri_free (ref); + uri_free(ref); if (bas !=3D NULL) - uri_free (bas); + uri_free(bas); return val; } @@ -2087,12 +2090,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 <=3D 0) init_alloc =3D 1; + if (init_alloc <=3D 0) + init_alloc =3D 1; ps =3D g_new(QueryParams, 1); ps->n =3D 0; @@ -2105,9 +2108,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 >=3D ps->alloc) { ps->p =3D g_renew(QueryParam, ps->p, ps->alloc * 2); @@ -2122,41 +2124,41 @@ query_params_append (struct QueryParams *ps, return 0; } - void -query_params_free (struct QueryParams *ps) +void query_params_free(struct QueryParams *ps) { int i; for (i =3D 0; i < ps->n; ++i) { - g_free (ps->p[i].name); - g_free (ps->p[i].value); + g_free(ps->p[i].name); + g_free(ps->p[i].value); } - g_free (ps->p); - g_free (ps); + g_free(ps->p); + 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 =3D query_params_new (0); - if (!query || query[0] =3D=3D '\0') return ps; + ps =3D query_params_new(0); + if (!query || query[0] =3D=3D '\0') + return ps; while (*query) { char *name =3D NULL, *value =3D NULL; /* Find the next separator, or end of the string. */ - end =3D strchr (query, '&'); + end =3D strchr(query, '&'); if (!end) - end =3D strchr (query, ';'); + end =3D strchr(query, ';'); if (!end) - end =3D query + strlen (query); + end =3D query + strlen(query); /* Find the first '=3D' character between here and end. */ - eq =3D strchr (query, '=3D'); - if (eq && eq >=3D end) eq =3D NULL; + eq =3D strchr(query, '=3D'); + if (eq && eq >=3D end) + eq =3D NULL; /* Empty section (eg. "&&"). */ if (end =3D=3D query) @@ -2166,14 +2168,14 @@ query_params_parse (const char *query) * and consistent with CGI.pm we assume value is "". */ else if (!eq) { - name =3D uri_string_unescape (query, end - query, NULL); + name =3D uri_string_unescape(query, end - query, NULL); value =3D NULL; } /* Or if we have "name=3D" here (works around annoying * problem when calling uri_string_unescape with len =3D 0). */ - else if (eq+1 =3D=3D end) { - name =3D uri_string_unescape (query, eq - query, NULL); + else if (eq + 1 =3D=3D end) { + name =3D uri_string_unescape(query, eq - query, NULL); value =3D g_new0(char, 1); } /* If the '=3D' character is at the beginning then we have @@ -2184,18 +2186,19 @@ query_params_parse (const char *query) /* Otherwise it's "name=3Dvalue". */ else { - name =3D uri_string_unescape (query, eq - query, NULL); - value =3D uri_string_unescape (eq+1, end - (eq+1), NULL); + name =3D uri_string_unescape(query, eq - query, NULL); + value =3D uri_string_unescape(eq + 1, end - (eq + 1), NULL); } /* Append to the parameter set. */ - query_params_append (ps, name, value); + query_params_append(ps, name, value); g_free(name); g_free(value); -next: + next: query =3D end; - if (*query) query ++; /* skip '&' separator */ + if (*query) + query++; /* skip '&' separator */ } return ps; -- 2.7.4