qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging

Pull request

Mostly patches that are only indirectly related to the block layer, but I've
reviewed them and there is no maintainer.

# gpg: Signature made Mon 05 Mar 2018 09:39:50 GMT
# gpg: using RSA key 9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>"
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8

* remotes/stefanha/tags/block-pull-request:
README: Document 'git-publish' workflow
Add a git-publish configuration file
tests/libqos: Check for valid dev pointer when looking for PCI devices
util/uri.c: wrap single statement blocks with braces {}
util/uri.c: remove brackets that wrap `return` statement's content.
util/uri.c: Coding style check, Only whitespace involved

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+1014 -805
+51
.gitpublish
··· 1 + # 2 + # Common git-publish profiles that can be used to send patches to QEMU upstream. 3 + # 4 + # See https://github.com/stefanha/git-publish for more information 5 + # 6 + [gitpublishprofile "default"] 7 + base = master 8 + to = qemu-devel@nongnu.org 9 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null 10 + 11 + [gitpublishprofile "rfc"] 12 + base = master 13 + prefix = RFC PATCH 14 + to = qemu-devel@nongnu.org 15 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null 16 + 17 + [gitpublishprofile "stable"] 18 + base = master 19 + to = qemu-devel@nongnu.org 20 + cc = qemu-stable@nongnu.org 21 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null 22 + 23 + [gitpublishprofile "trivial"] 24 + base = master 25 + to = qemu-devel@nongnu.org 26 + cc = qemu-trivial@nongnu.org 27 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null 28 + 29 + [gitpublishprofile "block"] 30 + base = master 31 + to = qemu-devel@nongnu.org 32 + cc = qemu-block@nongnu.org 33 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null 34 + 35 + [gitpublishprofile "arm"] 36 + base = master 37 + to = qemu-devel@nongnu.org 38 + cc = qemu-arm@nongnu.org 39 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null 40 + 41 + [gitpublishprofile "s390"] 42 + base = master 43 + to = qemu-devel@nongnu.org 44 + cc = qemu-s390@nongnu.org 45 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null 46 + 47 + [gitpublishprofile "ppc"] 48 + base = master 49 + to = qemu-devel@nongnu.org 50 + cc = qemu-ppc@nongnu.org 51 + cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
+30 -1
README
··· 56 56 57 57 git clone git://git.qemu.org/qemu.git 58 58 59 - When submitting patches, the preferred approach is to use 'git 59 + When submitting patches, one common approach is to use 'git 60 60 format-patch' and/or 'git send-email' to format & send the mail to the 61 61 qemu-devel@nongnu.org mailing list. All patches submitted must contain 62 62 a 'Signed-off-by' line from the author. Patches should follow the ··· 72 72 73 73 git clone git://git.qemu.org/qemu-web.git 74 74 https://www.qemu.org/2017/02/04/the-new-qemu-website-is-up/ 75 + 76 + A 'git-profile' utility was created to make above process less 77 + cumbersome, and is highly recommended for making regular contributions, 78 + or even just for sending consecutive patch series revisions. It also 79 + requires a working 'git send-email' setup, and by default doesn't 80 + automate everything, so you may want to go through the above steps 81 + manually for once. 82 + 83 + For installation instructions, please go to 84 + 85 + https://github.com/stefanha/git-publish 86 + 87 + The workflow with 'git-publish' is: 88 + 89 + $ git checkout master -b my-feature 90 + $ # work on new commits, add your 'Signed-off-by' lines to each 91 + $ git publish 92 + 93 + Your patch series will be sent and tagged as my-feature-v1 if you need to refer 94 + back to it in the future. 95 + 96 + Sending v2: 97 + 98 + $ git checkout my-feature # same topic branch 99 + $ # making changes to the commits (using 'git rebase', for example) 100 + $ git publish 101 + 102 + Your patch series will be sent with 'v2' tag in the subject and the git tip 103 + will be tagged as my-feature-v2. 75 104 76 105 Bug reporting 77 106 =============
+3 -1
tests/libqos/virtio-pci.c
··· 315 315 qvirtio_pci_foreach(bus, device_type, false, 0, 316 316 qvirtio_pci_assign_device, &dev); 317 317 318 - dev->vdev.bus = &qvirtio_pci; 318 + if (dev) { 319 + dev->vdev.bus = &qvirtio_pci; 320 + } 319 321 320 322 return dev; 321 323 }
+930 -803
util/uri.c
··· 63 63 */ 64 64 #define IS_ALPHA(x) (IS_LOWALPHA(x) || IS_UPALPHA(x)) 65 65 66 - 67 66 /* 68 67 * lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | 69 68 * "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | ··· 97 96 * mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" 98 97 */ 99 98 100 - #define IS_MARK(x) (((x) == '-') || ((x) == '_') || ((x) == '.') || \ 101 - ((x) == '!') || ((x) == '~') || ((x) == '*') || ((x) == '\'') || \ 99 + #define IS_MARK(x) (((x) == '-') || ((x) == '_') || ((x) == '.') || \ 100 + ((x) == '!') || ((x) == '~') || ((x) == '*') || ((x) == '\'') || \ 102 101 ((x) == '(') || ((x) == ')')) 103 102 104 103 /* 105 104 * unwise = "{" | "}" | "|" | "\" | "^" | "`" 106 105 */ 107 106 108 - #define IS_UNWISE(p) \ 109 - (((*(p) == '{')) || ((*(p) == '}')) || ((*(p) == '|')) || \ 110 - ((*(p) == '\\')) || ((*(p) == '^')) || ((*(p) == '[')) || \ 111 - ((*(p) == ']')) || ((*(p) == '`'))) 107 + #define IS_UNWISE(p) \ 108 + (((*(p) == '{')) || ((*(p) == '}')) || ((*(p) == '|')) || \ 109 + ((*(p) == '\\')) || ((*(p) == '^')) || ((*(p) == '[')) || \ 110 + ((*(p) == ']')) || ((*(p) == '`'))) 112 111 /* 113 112 * reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," | 114 113 * "[" | "]" 115 114 */ 116 115 117 - #define IS_RESERVED(x) (((x) == ';') || ((x) == '/') || ((x) == '?') || \ 118 - ((x) == ':') || ((x) == '@') || ((x) == '&') || ((x) == '=') || \ 119 - ((x) == '+') || ((x) == '$') || ((x) == ',') || ((x) == '[') || \ 120 - ((x) == ']')) 116 + #define IS_RESERVED(x) (((x) == ';') || ((x) == '/') || ((x) == '?') || \ 117 + ((x) == ':') || ((x) == '@') || ((x) == '&') || ((x) == '=') || \ 118 + ((x) == '+') || ((x) == '$') || ((x) == ',') || ((x) == '[') || \ 119 + ((x) == ']')) 121 120 122 121 /* 123 122 * unreserved = alphanum | mark ··· 129 128 * Skip to next pointer char, handle escaped sequences 130 129 */ 131 130 132 - #define NEXT(p) ((*p == '%')? p += 3 : p++) 131 + #define NEXT(p) ((*p == '%') ? p += 3 : p++) 133 132 134 133 /* 135 134 * Productions from the spec. ··· 141 140 * path = [ abs_path | opaque_part ] 142 141 */ 143 142 144 - 145 143 /************************************************************************ 146 - * * 147 - * RFC 3986 parser * 148 - * * 144 + * * 145 + * RFC 3986 parser * 146 + * * 149 147 ************************************************************************/ 150 148 151 149 #define ISA_DIGIT(p) ((*(p) >= '0') && (*(p) <= '9')) 152 - #define ISA_ALPHA(p) (((*(p) >= 'a') && (*(p) <= 'z')) || \ 150 + #define ISA_ALPHA(p) (((*(p) >= 'a') && (*(p) <= 'z')) || \ 153 151 ((*(p) >= 'A') && (*(p) <= 'Z'))) 154 - #define ISA_HEXDIG(p) \ 155 - (ISA_DIGIT(p) || ((*(p) >= 'a') && (*(p) <= 'f')) || \ 156 - ((*(p) >= 'A') && (*(p) <= 'F'))) 152 + #define ISA_HEXDIG(p) \ 153 + (ISA_DIGIT(p) || ((*(p) >= 'a') && (*(p) <= 'f')) || \ 154 + ((*(p) >= 'A') && (*(p) <= 'F'))) 157 155 158 156 /* 159 157 * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" 160 158 * / "*" / "+" / "," / ";" / "=" 161 159 */ 162 - #define ISA_SUB_DELIM(p) \ 163 - (((*(p) == '!')) || ((*(p) == '$')) || ((*(p) == '&')) || \ 164 - ((*(p) == '(')) || ((*(p) == ')')) || ((*(p) == '*')) || \ 165 - ((*(p) == '+')) || ((*(p) == ',')) || ((*(p) == ';')) || \ 166 - ((*(p) == '=')) || ((*(p) == '\''))) 160 + #define ISA_SUB_DELIM(p) \ 161 + (((*(p) == '!')) || ((*(p) == '$')) || ((*(p) == '&')) || \ 162 + ((*(p) == '(')) || ((*(p) == ')')) || ((*(p) == '*')) || \ 163 + ((*(p) == '+')) || ((*(p) == ',')) || ((*(p) == ';')) || \ 164 + ((*(p) == '=')) || ((*(p) == '\''))) 167 165 168 166 /* 169 167 * gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" 170 168 */ 171 - #define ISA_GEN_DELIM(p) \ 172 - (((*(p) == ':')) || ((*(p) == '/')) || ((*(p) == '?')) || \ 173 - ((*(p) == '#')) || ((*(p) == '[')) || ((*(p) == ']')) || \ 174 - ((*(p) == '@'))) 169 + #define ISA_GEN_DELIM(p) \ 170 + (((*(p) == ':')) || ((*(p) == '/')) || ((*(p) == '?')) || \ 171 + ((*(p) == '#')) || ((*(p) == '[')) || ((*(p) == ']')) || \ 172 + ((*(p) == '@'))) 175 173 176 174 /* 177 175 * reserved = gen-delims / sub-delims ··· 181 179 /* 182 180 * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" 183 181 */ 184 - #define ISA_UNRESERVED(p) \ 185 - ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) == '-')) || \ 186 - ((*(p) == '.')) || ((*(p) == '_')) || ((*(p) == '~'))) 182 + #define ISA_UNRESERVED(p) \ 183 + ((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) == '-')) || \ 184 + ((*(p) == '.')) || ((*(p) == '_')) || ((*(p) == '~'))) 187 185 188 186 /* 189 187 * pct-encoded = "%" HEXDIG HEXDIG 190 188 */ 191 - #define ISA_PCT_ENCODED(p) \ 192 - ((*(p) == '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2))) 189 + #define ISA_PCT_ENCODED(p) \ 190 + ((*(p) == '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2))) 193 191 194 192 /* 195 193 * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" 196 194 */ 197 - #define ISA_PCHAR(p) \ 198 - (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) || \ 199 - ((*(p) == ':')) || ((*(p) == '@'))) 195 + #define ISA_PCHAR(p) \ 196 + (ISA_UNRESERVED(p) || ISA_PCT_ENCODED(p) || ISA_SUB_DELIM(p) || \ 197 + ((*(p) == ':')) || ((*(p) == '@'))) 200 198 201 199 /** 202 200 * rfc3986_parse_scheme: ··· 209 207 * 210 208 * Returns 0 or the error code 211 209 */ 212 - static int 213 - rfc3986_parse_scheme(URI *uri, const char **str) { 210 + static int rfc3986_parse_scheme(URI *uri, const char **str) 211 + { 214 212 const char *cur; 215 213 216 - if (str == NULL) 217 - return(-1); 214 + if (str == NULL) { 215 + return -1; 216 + } 218 217 219 218 cur = *str; 220 - if (!ISA_ALPHA(cur)) 221 - return(2); 219 + if (!ISA_ALPHA(cur)) { 220 + return 2; 221 + } 222 222 cur++; 223 - while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || 224 - (*cur == '+') || (*cur == '-') || (*cur == '.')) cur++; 223 + while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur == '+') || (*cur == '-') || 224 + (*cur == '.')) { 225 + cur++; 226 + } 225 227 if (uri != NULL) { 226 228 g_free(uri->scheme); 227 - uri->scheme = g_strndup(*str, cur - *str); 229 + uri->scheme = g_strndup(*str, cur - *str); 228 230 } 229 231 *str = cur; 230 - return(0); 232 + return 0; 231 233 } 232 234 233 235 /** ··· 245 247 * 246 248 * Returns 0 or the error code 247 249 */ 248 - static int 249 - rfc3986_parse_fragment(URI *uri, const char **str) 250 + static int rfc3986_parse_fragment(URI *uri, const char **str) 250 251 { 251 252 const char *cur; 252 253 253 - if (str == NULL) 254 - return (-1); 254 + if (str == NULL) { 255 + return -1; 256 + } 255 257 256 258 cur = *str; 257 259 258 260 while ((ISA_PCHAR(cur)) || (*cur == '/') || (*cur == '?') || 259 261 (*cur == '[') || (*cur == ']') || 260 - ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) 262 + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) { 261 263 NEXT(cur); 264 + } 262 265 if (uri != NULL) { 263 266 g_free(uri->fragment); 264 - if (uri->cleanup & 2) 265 - uri->fragment = g_strndup(*str, cur - *str); 266 - else 267 - uri->fragment = uri_string_unescape(*str, cur - *str, NULL); 267 + if (uri->cleanup & 2) { 268 + uri->fragment = g_strndup(*str, cur - *str); 269 + } else { 270 + uri->fragment = uri_string_unescape(*str, cur - *str, NULL); 271 + } 268 272 } 269 273 *str = cur; 270 - return (0); 274 + return 0; 271 275 } 272 276 273 277 /** ··· 281 285 * 282 286 * Returns 0 or the error code 283 287 */ 284 - static int 285 - rfc3986_parse_query(URI *uri, const char **str) 288 + static int rfc3986_parse_query(URI *uri, const char **str) 286 289 { 287 290 const char *cur; 288 291 289 - if (str == NULL) 290 - return (-1); 292 + if (str == NULL) { 293 + return -1; 294 + } 291 295 292 296 cur = *str; 293 297 294 298 while ((ISA_PCHAR(cur)) || (*cur == '/') || (*cur == '?') || 295 - ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) 299 + ((uri != NULL) && (uri->cleanup & 1) && (IS_UNWISE(cur)))) { 296 300 NEXT(cur); 301 + } 297 302 if (uri != NULL) { 298 303 g_free(uri->query); 299 - uri->query = g_strndup (*str, cur - *str); 304 + uri->query = g_strndup(*str, cur - *str); 300 305 } 301 306 *str = cur; 302 - return (0); 307 + return 0; 303 308 } 304 309 305 310 /** ··· 314 319 * 315 320 * Returns 0 or the error code 316 321 */ 317 - static int 318 - rfc3986_parse_port(URI *uri, const char **str) 322 + static int rfc3986_parse_port(URI *uri, const char **str) 319 323 { 320 324 const char *cur = *str; 321 325 int port = 0; ··· 349 353 * 350 354 * Returns 0 or the error code 351 355 */ 352 - static int 353 - rfc3986_parse_user_info(URI *uri, const char **str) 356 + static int rfc3986_parse_user_info(URI *uri, const char **str) 354 357 { 355 358 const char *cur; 356 359 357 360 cur = *str; 358 - while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || 359 - ISA_SUB_DELIM(cur) || (*cur == ':')) 360 - NEXT(cur); 361 + while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur) || 362 + (*cur == ':')) { 363 + NEXT(cur); 364 + } 361 365 if (*cur == '@') { 362 - if (uri != NULL) { 366 + if (uri != NULL) { 363 367 g_free(uri->user); 364 - if (uri->cleanup & 2) 365 - uri->user = g_strndup(*str, cur - *str); 366 - else 367 - uri->user = uri_string_unescape(*str, cur - *str, NULL); 368 - } 369 - *str = cur; 370 - return(0); 368 + if (uri->cleanup & 2) { 369 + uri->user = g_strndup(*str, cur - *str); 370 + } else { 371 + uri->user = uri_string_unescape(*str, cur - *str, NULL); 372 + } 373 + } 374 + *str = cur; 375 + return 0; 371 376 } 372 - return(1); 377 + return 1; 373 378 } 374 379 375 380 /** ··· 386 391 * 387 392 * Returns 0 if found and skipped, 1 otherwise 388 393 */ 389 - static int 390 - rfc3986_parse_dec_octet(const char **str) { 394 + static int rfc3986_parse_dec_octet(const char **str) 395 + { 391 396 const char *cur = *str; 392 397 393 - if (!(ISA_DIGIT(cur))) 394 - return(1); 395 - if (!ISA_DIGIT(cur+1)) 396 - cur++; 397 - else if ((*cur != '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur+2))) 398 - cur += 2; 399 - else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2))) 400 - cur += 3; 401 - else if ((*cur == '2') && (*(cur + 1) >= '0') && 402 - (*(cur + 1) <= '4') && (ISA_DIGIT(cur + 2))) 403 - cur += 3; 404 - else if ((*cur == '2') && (*(cur + 1) == '5') && 405 - (*(cur + 2) >= '0') && (*(cur + 1) <= '5')) 406 - cur += 3; 407 - else 408 - return(1); 398 + if (!(ISA_DIGIT(cur))) { 399 + return 1; 400 + } 401 + if (!ISA_DIGIT(cur + 1)) { 402 + cur++; 403 + } else if ((*cur != '0') && (ISA_DIGIT(cur + 1)) && (!ISA_DIGIT(cur + 2))) { 404 + cur += 2; 405 + } else if ((*cur == '1') && (ISA_DIGIT(cur + 1)) && (ISA_DIGIT(cur + 2))) { 406 + cur += 3; 407 + } else if ((*cur == '2') && (*(cur + 1) >= '0') && (*(cur + 1) <= '4') && 408 + (ISA_DIGIT(cur + 2))) { 409 + cur += 3; 410 + } else if ((*cur == '2') && (*(cur + 1) == '5') && (*(cur + 2) >= '0') && 411 + (*(cur + 1) <= '5')) { 412 + cur += 3; 413 + } else { 414 + return 1; 415 + } 409 416 *str = cur; 410 - return(0); 417 + return 0; 411 418 } 412 419 /** 413 420 * rfc3986_parse_host: ··· 424 431 * 425 432 * Returns 0 or the error code 426 433 */ 427 - static int 428 - rfc3986_parse_host(URI *uri, const char **str) 434 + static int rfc3986_parse_host(URI *uri, const char **str) 429 435 { 430 436 const char *cur = *str; 431 437 const char *host; ··· 436 442 */ 437 443 if (*cur == '[') { 438 444 cur++; 439 - while ((*cur != ']') && (*cur != 0)) 440 - cur++; 441 - if (*cur != ']') 442 - return(1); 443 - cur++; 444 - goto found; 445 + while ((*cur != ']') && (*cur != 0)) { 446 + cur++; 447 + } 448 + if (*cur != ']') { 449 + return 1; 450 + } 451 + cur++; 452 + goto found; 445 453 } 446 454 /* 447 455 * try to parse an IPv4 448 456 */ 449 457 if (ISA_DIGIT(cur)) { 450 - if (rfc3986_parse_dec_octet(&cur) != 0) 451 - goto not_ipv4; 452 - if (*cur != '.') 453 - goto not_ipv4; 454 - cur++; 455 - if (rfc3986_parse_dec_octet(&cur) != 0) 456 - goto not_ipv4; 457 - if (*cur != '.') 458 - goto not_ipv4; 459 - if (rfc3986_parse_dec_octet(&cur) != 0) 460 - goto not_ipv4; 461 - if (*cur != '.') 462 - goto not_ipv4; 463 - if (rfc3986_parse_dec_octet(&cur) != 0) 464 - goto not_ipv4; 465 - goto found; 466 - not_ipv4: 458 + if (rfc3986_parse_dec_octet(&cur) != 0) { 459 + goto not_ipv4; 460 + } 461 + if (*cur != '.') { 462 + goto not_ipv4; 463 + } 464 + cur++; 465 + if (rfc3986_parse_dec_octet(&cur) != 0) { 466 + goto not_ipv4; 467 + } 468 + if (*cur != '.') { 469 + goto not_ipv4; 470 + } 471 + if (rfc3986_parse_dec_octet(&cur) != 0) { 472 + goto not_ipv4; 473 + } 474 + if (*cur != '.') { 475 + goto not_ipv4; 476 + } 477 + if (rfc3986_parse_dec_octet(&cur) != 0) { 478 + goto not_ipv4; 479 + } 480 + goto found; 481 + not_ipv4: 467 482 cur = *str; 468 483 } 469 484 /* 470 485 * then this should be a hostname which can be empty 471 486 */ 472 - while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur)) 487 + while (ISA_UNRESERVED(cur) || ISA_PCT_ENCODED(cur) || ISA_SUB_DELIM(cur)) { 473 488 NEXT(cur); 489 + } 474 490 found: 475 491 if (uri != NULL) { 476 492 g_free(uri->authority); 477 - uri->authority = NULL; 493 + uri->authority = NULL; 478 494 g_free(uri->server); 479 - if (cur != host) { 480 - if (uri->cleanup & 2) 481 - uri->server = g_strndup(host, cur - host); 482 - else 483 - uri->server = uri_string_unescape(host, cur - host, NULL); 484 - } else 485 - uri->server = NULL; 495 + if (cur != host) { 496 + if (uri->cleanup & 2) { 497 + uri->server = g_strndup(host, cur - host); 498 + } else { 499 + uri->server = uri_string_unescape(host, cur - host, NULL); 500 + } 501 + } else { 502 + uri->server = NULL; 503 + } 486 504 } 487 505 *str = cur; 488 - return(0); 506 + return 0; 489 507 } 490 508 491 509 /** ··· 500 518 * 501 519 * Returns 0 or the error code 502 520 */ 503 - static int 504 - rfc3986_parse_authority(URI *uri, const char **str) 521 + static int rfc3986_parse_authority(URI *uri, const char **str) 505 522 { 506 523 const char *cur; 507 524 int ret; ··· 511 528 * try to parse a userinfo and check for the trailing @ 512 529 */ 513 530 ret = rfc3986_parse_user_info(uri, &cur); 514 - if ((ret != 0) || (*cur != '@')) 531 + if ((ret != 0) || (*cur != '@')) { 515 532 cur = *str; 516 - else 533 + } else { 517 534 cur++; 535 + } 518 536 ret = rfc3986_parse_host(uri, &cur); 519 - if (ret != 0) return(ret); 537 + if (ret != 0) { 538 + return ret; 539 + } 520 540 if (*cur == ':') { 521 541 cur++; 522 542 ret = rfc3986_parse_port(uri, &cur); 523 - if (ret != 0) return(ret); 543 + if (ret != 0) { 544 + return ret; 545 + } 524 546 } 525 547 *str = cur; 526 - return(0); 548 + return 0; 527 549 } 528 550 529 551 /** ··· 542 564 * 543 565 * Returns 0 or the error code 544 566 */ 545 - static int 546 - rfc3986_parse_segment(const char **str, char forbid, int empty) 567 + static int rfc3986_parse_segment(const char **str, char forbid, int empty) 547 568 { 548 569 const char *cur; 549 570 550 571 cur = *str; 551 572 if (!ISA_PCHAR(cur)) { 552 - if (empty) 553 - return(0); 554 - return(1); 573 + if (empty) { 574 + return 0; 575 + } 576 + return 1; 555 577 } 556 - while (ISA_PCHAR(cur) && (*cur != forbid)) 578 + while (ISA_PCHAR(cur) && (*cur != forbid)) { 557 579 NEXT(cur); 580 + } 558 581 *str = cur; 559 - return (0); 582 + return 0; 560 583 } 561 584 562 585 /** ··· 571 594 * 572 595 * Returns 0 or the error code 573 596 */ 574 - static int 575 - rfc3986_parse_path_ab_empty(URI *uri, const char **str) 597 + static int rfc3986_parse_path_ab_empty(URI *uri, const char **str) 576 598 { 577 599 const char *cur; 578 600 int ret; ··· 581 603 582 604 while (*cur == '/') { 583 605 cur++; 584 - ret = rfc3986_parse_segment(&cur, 0, 1); 585 - if (ret != 0) return(ret); 606 + ret = rfc3986_parse_segment(&cur, 0, 1); 607 + if (ret != 0) { 608 + return ret; 609 + } 586 610 } 587 611 if (uri != NULL) { 588 612 g_free(uri->path); 589 613 if (*str != cur) { 590 - if (uri->cleanup & 2) 614 + if (uri->cleanup & 2) { 591 615 uri->path = g_strndup(*str, cur - *str); 592 - else 616 + } else { 593 617 uri->path = uri_string_unescape(*str, cur - *str, NULL); 618 + } 594 619 } else { 595 620 uri->path = NULL; 596 621 } 597 622 } 598 623 *str = cur; 599 - return (0); 624 + return 0; 600 625 } 601 626 602 627 /** ··· 611 636 * 612 637 * Returns 0 or the error code 613 638 */ 614 - static int 615 - rfc3986_parse_path_absolute(URI *uri, const char **str) 639 + static int rfc3986_parse_path_absolute(URI *uri, const char **str) 616 640 { 617 641 const char *cur; 618 642 int ret; 619 643 620 644 cur = *str; 621 645 622 - if (*cur != '/') 623 - return(1); 646 + if (*cur != '/') { 647 + return 1; 648 + } 624 649 cur++; 625 650 ret = rfc3986_parse_segment(&cur, 0, 0); 626 651 if (ret == 0) { 627 - while (*cur == '/') { 628 - cur++; 629 - ret = rfc3986_parse_segment(&cur, 0, 1); 630 - if (ret != 0) return(ret); 631 - } 652 + while (*cur == '/') { 653 + cur++; 654 + ret = rfc3986_parse_segment(&cur, 0, 1); 655 + if (ret != 0) { 656 + return ret; 657 + } 658 + } 632 659 } 633 660 if (uri != NULL) { 634 661 g_free(uri->path); 635 662 if (cur != *str) { 636 - if (uri->cleanup & 2) 663 + if (uri->cleanup & 2) { 637 664 uri->path = g_strndup(*str, cur - *str); 638 - else 665 + } else { 639 666 uri->path = uri_string_unescape(*str, cur - *str, NULL); 667 + } 640 668 } else { 641 669 uri->path = NULL; 642 670 } 643 671 } 644 672 *str = cur; 645 - return (0); 673 + return 0; 646 674 } 647 675 648 676 /** ··· 657 685 * 658 686 * Returns 0 or the error code 659 687 */ 660 - static int 661 - rfc3986_parse_path_rootless(URI *uri, const char **str) 688 + static int rfc3986_parse_path_rootless(URI *uri, const char **str) 662 689 { 663 690 const char *cur; 664 691 int ret; ··· 666 693 cur = *str; 667 694 668 695 ret = rfc3986_parse_segment(&cur, 0, 0); 669 - if (ret != 0) return(ret); 696 + if (ret != 0) { 697 + return ret; 698 + } 670 699 while (*cur == '/') { 671 700 cur++; 672 - ret = rfc3986_parse_segment(&cur, 0, 1); 673 - if (ret != 0) return(ret); 701 + ret = rfc3986_parse_segment(&cur, 0, 1); 702 + if (ret != 0) { 703 + return ret; 704 + } 674 705 } 675 706 if (uri != NULL) { 676 707 g_free(uri->path); 677 708 if (cur != *str) { 678 - if (uri->cleanup & 2) 709 + if (uri->cleanup & 2) { 679 710 uri->path = g_strndup(*str, cur - *str); 680 - else 711 + } else { 681 712 uri->path = uri_string_unescape(*str, cur - *str, NULL); 713 + } 682 714 } else { 683 715 uri->path = NULL; 684 716 } 685 717 } 686 718 *str = cur; 687 - return (0); 719 + return 0; 688 720 } 689 721 690 722 /** ··· 699 731 * 700 732 * Returns 0 or the error code 701 733 */ 702 - static int 703 - rfc3986_parse_path_no_scheme(URI *uri, const char **str) 734 + static int rfc3986_parse_path_no_scheme(URI *uri, const char **str) 704 735 { 705 736 const char *cur; 706 737 int ret; ··· 708 739 cur = *str; 709 740 710 741 ret = rfc3986_parse_segment(&cur, ':', 0); 711 - if (ret != 0) return(ret); 742 + if (ret != 0) { 743 + return ret; 744 + } 712 745 while (*cur == '/') { 713 746 cur++; 714 - ret = rfc3986_parse_segment(&cur, 0, 1); 715 - if (ret != 0) return(ret); 747 + ret = rfc3986_parse_segment(&cur, 0, 1); 748 + if (ret != 0) { 749 + return ret; 750 + } 716 751 } 717 752 if (uri != NULL) { 718 753 g_free(uri->path); 719 754 if (cur != *str) { 720 - if (uri->cleanup & 2) 755 + if (uri->cleanup & 2) { 721 756 uri->path = g_strndup(*str, cur - *str); 722 - else 757 + } else { 723 758 uri->path = uri_string_unescape(*str, cur - *str, NULL); 759 + } 724 760 } else { 725 761 uri->path = NULL; 726 762 } 727 763 } 728 764 *str = cur; 729 - return (0); 765 + return 0; 730 766 } 731 767 732 768 /** ··· 744 780 * 745 781 * Returns 0 or the error code 746 782 */ 747 - static int 748 - rfc3986_parse_hier_part(URI *uri, const char **str) 783 + static int rfc3986_parse_hier_part(URI *uri, const char **str) 749 784 { 750 785 const char *cur; 751 786 int ret; ··· 754 789 755 790 if ((*cur == '/') && (*(cur + 1) == '/')) { 756 791 cur += 2; 757 - ret = rfc3986_parse_authority(uri, &cur); 758 - if (ret != 0) return(ret); 759 - ret = rfc3986_parse_path_ab_empty(uri, &cur); 760 - if (ret != 0) return(ret); 761 - *str = cur; 762 - return(0); 792 + ret = rfc3986_parse_authority(uri, &cur); 793 + if (ret != 0) { 794 + return ret; 795 + } 796 + ret = rfc3986_parse_path_ab_empty(uri, &cur); 797 + if (ret != 0) { 798 + return ret; 799 + } 800 + *str = cur; 801 + return 0; 763 802 } else if (*cur == '/') { 764 803 ret = rfc3986_parse_path_absolute(uri, &cur); 765 - if (ret != 0) return(ret); 804 + if (ret != 0) { 805 + return ret; 806 + } 766 807 } else if (ISA_PCHAR(cur)) { 767 808 ret = rfc3986_parse_path_rootless(uri, &cur); 768 - if (ret != 0) return(ret); 809 + if (ret != 0) { 810 + return ret; 811 + } 769 812 } else { 770 - /* path-empty is effectively empty */ 771 - if (uri != NULL) { 813 + /* path-empty is effectively empty */ 814 + if (uri != NULL) { 772 815 g_free(uri->path); 773 - uri->path = NULL; 774 - } 816 + uri->path = NULL; 817 + } 775 818 } 776 819 *str = cur; 777 - return (0); 820 + return 0; 778 821 } 779 822 780 823 /** ··· 793 836 * 794 837 * Returns 0 or the error code 795 838 */ 796 - static int 797 - rfc3986_parse_relative_ref(URI *uri, const char *str) { 839 + static int rfc3986_parse_relative_ref(URI *uri, const char *str) 840 + { 798 841 int ret; 799 842 800 843 if ((*str == '/') && (*(str + 1) == '/')) { 801 844 str += 2; 802 - ret = rfc3986_parse_authority(uri, &str); 803 - if (ret != 0) return(ret); 804 - ret = rfc3986_parse_path_ab_empty(uri, &str); 805 - if (ret != 0) return(ret); 845 + ret = rfc3986_parse_authority(uri, &str); 846 + if (ret != 0) { 847 + return ret; 848 + } 849 + ret = rfc3986_parse_path_ab_empty(uri, &str); 850 + if (ret != 0) { 851 + return ret; 852 + } 806 853 } else if (*str == '/') { 807 - ret = rfc3986_parse_path_absolute(uri, &str); 808 - if (ret != 0) return(ret); 854 + ret = rfc3986_parse_path_absolute(uri, &str); 855 + if (ret != 0) { 856 + return ret; 857 + } 809 858 } else if (ISA_PCHAR(str)) { 810 859 ret = rfc3986_parse_path_no_scheme(uri, &str); 811 - if (ret != 0) return(ret); 860 + if (ret != 0) { 861 + return ret; 862 + } 812 863 } else { 813 - /* path-empty is effectively empty */ 814 - if (uri != NULL) { 864 + /* path-empty is effectively empty */ 865 + if (uri != NULL) { 815 866 g_free(uri->path); 816 - uri->path = NULL; 817 - } 867 + uri->path = NULL; 868 + } 818 869 } 819 870 820 871 if (*str == '?') { 821 - str++; 822 - ret = rfc3986_parse_query(uri, &str); 823 - if (ret != 0) return(ret); 872 + str++; 873 + ret = rfc3986_parse_query(uri, &str); 874 + if (ret != 0) { 875 + return ret; 876 + } 824 877 } 825 878 if (*str == '#') { 826 - str++; 827 - ret = rfc3986_parse_fragment(uri, &str); 828 - if (ret != 0) return(ret); 879 + str++; 880 + ret = rfc3986_parse_fragment(uri, &str); 881 + if (ret != 0) { 882 + return ret; 883 + } 829 884 } 830 885 if (*str != 0) { 831 - uri_clean(uri); 832 - return(1); 886 + uri_clean(uri); 887 + return 1; 833 888 } 834 - return(0); 889 + return 0; 835 890 } 836 - 837 891 838 892 /** 839 893 * rfc3986_parse: ··· 847 901 * 848 902 * Returns 0 or the error code 849 903 */ 850 - static int 851 - rfc3986_parse(URI *uri, const char *str) { 904 + static int rfc3986_parse(URI *uri, const char *str) 905 + { 852 906 int ret; 853 907 854 908 ret = rfc3986_parse_scheme(uri, &str); 855 - if (ret != 0) return(ret); 909 + if (ret != 0) { 910 + return ret; 911 + } 856 912 if (*str != ':') { 857 - return(1); 913 + return 1; 858 914 } 859 915 str++; 860 916 ret = rfc3986_parse_hier_part(uri, &str); 861 - if (ret != 0) return(ret); 917 + if (ret != 0) { 918 + return ret; 919 + } 862 920 if (*str == '?') { 863 - str++; 864 - ret = rfc3986_parse_query(uri, &str); 865 - if (ret != 0) return(ret); 921 + str++; 922 + ret = rfc3986_parse_query(uri, &str); 923 + if (ret != 0) { 924 + return ret; 925 + } 866 926 } 867 927 if (*str == '#') { 868 - str++; 869 - ret = rfc3986_parse_fragment(uri, &str); 870 - if (ret != 0) return(ret); 928 + str++; 929 + ret = rfc3986_parse_fragment(uri, &str); 930 + if (ret != 0) { 931 + return ret; 932 + } 871 933 } 872 934 if (*str != 0) { 873 - uri_clean(uri); 874 - return(1); 935 + uri_clean(uri); 936 + return 1; 875 937 } 876 - return(0); 938 + return 0; 877 939 } 878 940 879 941 /** ··· 888 950 * 889 951 * Returns 0 or the error code 890 952 */ 891 - static int 892 - rfc3986_parse_uri_reference(URI *uri, const char *str) { 953 + static int rfc3986_parse_uri_reference(URI *uri, const char *str) 954 + { 893 955 int ret; 894 956 895 - if (str == NULL) 896 - return(-1); 957 + if (str == NULL) { 958 + return -1; 959 + } 897 960 uri_clean(uri); 898 961 899 962 /* ··· 902 965 */ 903 966 ret = rfc3986_parse(uri, str); 904 967 if (ret != 0) { 905 - uri_clean(uri); 968 + uri_clean(uri); 906 969 ret = rfc3986_parse_relative_ref(uri, str); 907 - if (ret != 0) { 908 - uri_clean(uri); 909 - return(ret); 910 - } 970 + if (ret != 0) { 971 + uri_clean(uri); 972 + return ret; 973 + } 911 974 } 912 - return(0); 975 + return 0; 913 976 } 914 977 915 978 /** ··· 922 985 * 923 986 * Returns a newly built URI or NULL in case of error 924 987 */ 925 - URI * 926 - uri_parse(const char *str) { 988 + URI *uri_parse(const char *str) 989 + { 927 990 URI *uri; 928 991 int ret; 929 992 930 - if (str == NULL) 931 - return(NULL); 993 + if (str == NULL) { 994 + return NULL; 995 + } 932 996 uri = uri_new(); 933 997 ret = rfc3986_parse_uri_reference(uri, str); 934 998 if (ret) { 935 999 uri_free(uri); 936 - return(NULL); 1000 + return NULL; 937 1001 } 938 - return(uri); 1002 + return uri; 939 1003 } 940 1004 941 1005 /** ··· 950 1014 * 951 1015 * Returns 0 or the error code 952 1016 */ 953 - int 954 - uri_parse_into(URI *uri, const char *str) { 955 - return(rfc3986_parse_uri_reference(uri, str)); 1017 + int uri_parse_into(URI *uri, const char *str) 1018 + { 1019 + return rfc3986_parse_uri_reference(uri, str); 956 1020 } 957 1021 958 1022 /** ··· 966 1030 * 967 1031 * Returns a newly built URI or NULL in case of error 968 1032 */ 969 - URI * 970 - uri_parse_raw(const char *str, int raw) { 1033 + URI *uri_parse_raw(const char *str, int raw) 1034 + { 971 1035 URI *uri; 972 1036 int ret; 973 1037 974 - if (str == NULL) 975 - return(NULL); 1038 + if (str == NULL) { 1039 + return NULL; 1040 + } 976 1041 uri = uri_new(); 977 1042 if (raw) { 978 1043 uri->cleanup |= 2; ··· 980 1045 ret = uri_parse_into(uri, str); 981 1046 if (ret) { 982 1047 uri_free(uri); 983 - return(NULL); 1048 + return NULL; 984 1049 } 985 - return(uri); 1050 + return uri; 986 1051 } 987 1052 988 1053 /************************************************************************ 989 - * * 990 - * Generic URI structure functions * 991 - * * 1054 + * * 1055 + * Generic URI structure functions * 1056 + * * 992 1057 ************************************************************************/ 993 1058 994 1059 /** ··· 998 1063 * 999 1064 * Returns the new structure or NULL in case of error 1000 1065 */ 1001 - URI * 1002 - uri_new(void) { 1066 + URI *uri_new(void) 1067 + { 1003 1068 URI *ret; 1004 1069 1005 1070 ret = g_new0(URI, 1); 1006 - return(ret); 1071 + return ret; 1007 1072 } 1008 1073 1009 1074 /** ··· 1012 1077 * Function to handle properly a reallocation when saving an URI 1013 1078 * Also imposes some limit on the length of an URI string output 1014 1079 */ 1015 - static char * 1016 - realloc2n(char *ret, int *max) { 1080 + static char *realloc2n(char *ret, int *max) 1081 + { 1017 1082 char *temp; 1018 1083 int tmp; 1019 1084 1020 1085 tmp = *max * 2; 1021 1086 temp = g_realloc(ret, (tmp + 1)); 1022 1087 *max = tmp; 1023 - return(temp); 1088 + return temp; 1024 1089 } 1025 1090 1026 1091 /** ··· 1031 1096 * 1032 1097 * Returns a new string (to be deallocated by caller) 1033 1098 */ 1034 - char * 1035 - uri_to_string(URI *uri) { 1099 + char *uri_to_string(URI *uri) 1100 + { 1036 1101 char *ret = NULL; 1037 1102 char *temp; 1038 1103 const char *p; 1039 1104 int len; 1040 1105 int max; 1041 1106 1042 - if (uri == NULL) return(NULL); 1043 - 1107 + if (uri == NULL) { 1108 + return NULL; 1109 + } 1044 1110 1045 1111 max = 80; 1046 1112 ret = g_malloc(max + 1); 1047 1113 len = 0; 1048 1114 1049 1115 if (uri->scheme != NULL) { 1050 - p = uri->scheme; 1051 - while (*p != 0) { 1052 - if (len >= max) { 1116 + p = uri->scheme; 1117 + while (*p != 0) { 1118 + if (len >= max) { 1053 1119 temp = realloc2n(ret, &max); 1054 - ret = temp; 1055 - } 1056 - ret[len++] = *p++; 1057 - } 1058 - if (len >= max) { 1120 + ret = temp; 1121 + } 1122 + ret[len++] = *p++; 1123 + } 1124 + if (len >= max) { 1059 1125 temp = realloc2n(ret, &max); 1060 1126 ret = temp; 1061 - } 1062 - ret[len++] = ':'; 1127 + } 1128 + ret[len++] = ':'; 1063 1129 } 1064 1130 if (uri->opaque != NULL) { 1065 - p = uri->opaque; 1066 - while (*p != 0) { 1067 - if (len + 3 >= max) { 1131 + p = uri->opaque; 1132 + while (*p != 0) { 1133 + if (len + 3 >= max) { 1068 1134 temp = realloc2n(ret, &max); 1069 1135 ret = temp; 1070 - } 1071 - if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) 1072 - ret[len++] = *p++; 1073 - else { 1074 - int val = *(unsigned char *)p++; 1075 - int hi = val / 0x10, lo = val % 0x10; 1076 - ret[len++] = '%'; 1077 - ret[len++] = hi + (hi > 9? 'A'-10 : '0'); 1078 - ret[len++] = lo + (lo > 9? 'A'-10 : '0'); 1079 - } 1080 - } 1136 + } 1137 + if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p))) { 1138 + ret[len++] = *p++; 1139 + } else { 1140 + int val = *(unsigned char *)p++; 1141 + int hi = val / 0x10, lo = val % 0x10; 1142 + ret[len++] = '%'; 1143 + ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0'); 1144 + ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0'); 1145 + } 1146 + } 1081 1147 } else { 1082 - if (uri->server != NULL) { 1083 - if (len + 3 >= max) { 1148 + if (uri->server != NULL) { 1149 + if (len + 3 >= max) { 1084 1150 temp = realloc2n(ret, &max); 1085 1151 ret = temp; 1086 - } 1087 - ret[len++] = '/'; 1088 - ret[len++] = '/'; 1089 - if (uri->user != NULL) { 1090 - p = uri->user; 1091 - while (*p != 0) { 1092 - if (len + 3 >= max) { 1152 + } 1153 + ret[len++] = '/'; 1154 + ret[len++] = '/'; 1155 + if (uri->user != NULL) { 1156 + p = uri->user; 1157 + while (*p != 0) { 1158 + if (len + 3 >= max) { 1093 1159 temp = realloc2n(ret, &max); 1094 1160 ret = temp; 1095 - } 1096 - if ((IS_UNRESERVED(*(p))) || 1097 - ((*(p) == ';')) || ((*(p) == ':')) || 1098 - ((*(p) == '&')) || ((*(p) == '=')) || 1099 - ((*(p) == '+')) || ((*(p) == '$')) || 1100 - ((*(p) == ','))) 1101 - ret[len++] = *p++; 1102 - else { 1103 - int val = *(unsigned char *)p++; 1104 - int hi = val / 0x10, lo = val % 0x10; 1105 - ret[len++] = '%'; 1106 - ret[len++] = hi + (hi > 9? 'A'-10 : '0'); 1107 - ret[len++] = lo + (lo > 9? 'A'-10 : '0'); 1108 - } 1109 - } 1110 - if (len + 3 >= max) { 1161 + } 1162 + if ((IS_UNRESERVED(*(p))) || ((*(p) == ';')) || 1163 + ((*(p) == ':')) || ((*(p) == '&')) || ((*(p) == '=')) || 1164 + ((*(p) == '+')) || ((*(p) == '$')) || ((*(p) == ','))) { 1165 + ret[len++] = *p++; 1166 + } else { 1167 + int val = *(unsigned char *)p++; 1168 + int hi = val / 0x10, lo = val % 0x10; 1169 + ret[len++] = '%'; 1170 + ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0'); 1171 + ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0'); 1172 + } 1173 + } 1174 + if (len + 3 >= max) { 1111 1175 temp = realloc2n(ret, &max); 1112 1176 ret = temp; 1113 - } 1114 - ret[len++] = '@'; 1115 - } 1116 - p = uri->server; 1117 - while (*p != 0) { 1118 - if (len >= max) { 1177 + } 1178 + ret[len++] = '@'; 1179 + } 1180 + p = uri->server; 1181 + while (*p != 0) { 1182 + if (len >= max) { 1119 1183 temp = realloc2n(ret, &max); 1120 1184 ret = temp; 1121 - } 1122 - ret[len++] = *p++; 1123 - } 1124 - if (uri->port > 0) { 1125 - if (len + 10 >= max) { 1185 + } 1186 + ret[len++] = *p++; 1187 + } 1188 + if (uri->port > 0) { 1189 + if (len + 10 >= max) { 1126 1190 temp = realloc2n(ret, &max); 1127 1191 ret = temp; 1128 - } 1129 - len += snprintf(&ret[len], max - len, ":%d", uri->port); 1130 - } 1131 - } else if (uri->authority != NULL) { 1132 - if (len + 3 >= max) { 1192 + } 1193 + len += snprintf(&ret[len], max - len, ":%d", uri->port); 1194 + } 1195 + } else if (uri->authority != NULL) { 1196 + if (len + 3 >= max) { 1133 1197 temp = realloc2n(ret, &max); 1134 1198 ret = temp; 1135 - } 1136 - ret[len++] = '/'; 1137 - ret[len++] = '/'; 1138 - p = uri->authority; 1139 - while (*p != 0) { 1140 - if (len + 3 >= max) { 1199 + } 1200 + ret[len++] = '/'; 1201 + ret[len++] = '/'; 1202 + p = uri->authority; 1203 + while (*p != 0) { 1204 + if (len + 3 >= max) { 1141 1205 temp = realloc2n(ret, &max); 1142 1206 ret = temp; 1143 - } 1144 - if ((IS_UNRESERVED(*(p))) || 1145 - ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) || 1146 - ((*(p) == ':')) || ((*(p) == '@')) || ((*(p) == '&')) || 1147 - ((*(p) == '=')) || ((*(p) == '+'))) 1148 - ret[len++] = *p++; 1149 - else { 1150 - int val = *(unsigned char *)p++; 1151 - int hi = val / 0x10, lo = val % 0x10; 1152 - ret[len++] = '%'; 1153 - ret[len++] = hi + (hi > 9? 'A'-10 : '0'); 1154 - ret[len++] = lo + (lo > 9? 'A'-10 : '0'); 1155 - } 1156 - } 1157 - } else if (uri->scheme != NULL) { 1158 - if (len + 3 >= max) { 1207 + } 1208 + if ((IS_UNRESERVED(*(p))) || ((*(p) == '$')) || 1209 + ((*(p) == ',')) || ((*(p) == ';')) || ((*(p) == ':')) || 1210 + ((*(p) == '@')) || ((*(p) == '&')) || ((*(p) == '=')) || 1211 + ((*(p) == '+'))) { 1212 + ret[len++] = *p++; 1213 + } else { 1214 + int val = *(unsigned char *)p++; 1215 + int hi = val / 0x10, lo = val % 0x10; 1216 + ret[len++] = '%'; 1217 + ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0'); 1218 + ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0'); 1219 + } 1220 + } 1221 + } else if (uri->scheme != NULL) { 1222 + if (len + 3 >= max) { 1159 1223 temp = realloc2n(ret, &max); 1160 1224 ret = temp; 1161 - } 1162 - ret[len++] = '/'; 1163 - ret[len++] = '/'; 1164 - } 1165 - if (uri->path != NULL) { 1166 - p = uri->path; 1167 - /* 1168 - * the colon in file:///d: should not be escaped or 1169 - * Windows accesses fail later. 1170 - */ 1171 - if ((uri->scheme != NULL) && 1172 - (p[0] == '/') && 1173 - (((p[1] >= 'a') && (p[1] <= 'z')) || 1174 - ((p[1] >= 'A') && (p[1] <= 'Z'))) && 1175 - (p[2] == ':') && 1176 - (!strcmp(uri->scheme, "file"))) { 1177 - if (len + 3 >= max) { 1225 + } 1226 + ret[len++] = '/'; 1227 + ret[len++] = '/'; 1228 + } 1229 + if (uri->path != NULL) { 1230 + p = uri->path; 1231 + /* 1232 + * the colon in file:///d: should not be escaped or 1233 + * Windows accesses fail later. 1234 + */ 1235 + if ((uri->scheme != NULL) && (p[0] == '/') && 1236 + (((p[1] >= 'a') && (p[1] <= 'z')) || 1237 + ((p[1] >= 'A') && (p[1] <= 'Z'))) && 1238 + (p[2] == ':') && (!strcmp(uri->scheme, "file"))) { 1239 + if (len + 3 >= max) { 1178 1240 temp = realloc2n(ret, &max); 1179 1241 ret = temp; 1180 - } 1181 - ret[len++] = *p++; 1182 - ret[len++] = *p++; 1183 - ret[len++] = *p++; 1184 - } 1185 - while (*p != 0) { 1186 - if (len + 3 >= max) { 1242 + } 1243 + ret[len++] = *p++; 1244 + ret[len++] = *p++; 1245 + ret[len++] = *p++; 1246 + } 1247 + while (*p != 0) { 1248 + if (len + 3 >= max) { 1187 1249 temp = realloc2n(ret, &max); 1188 1250 ret = temp; 1189 - } 1190 - if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) || 1251 + } 1252 + if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) || 1191 1253 ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) || 1192 - ((*(p) == '=')) || ((*(p) == '+')) || ((*(p) == '$')) || 1193 - ((*(p) == ','))) 1194 - ret[len++] = *p++; 1195 - else { 1196 - int val = *(unsigned char *)p++; 1197 - int hi = val / 0x10, lo = val % 0x10; 1198 - ret[len++] = '%'; 1199 - ret[len++] = hi + (hi > 9? 'A'-10 : '0'); 1200 - ret[len++] = lo + (lo > 9? 'A'-10 : '0'); 1201 - } 1202 - } 1203 - } 1204 - if (uri->query != NULL) { 1205 - if (len + 1 >= max) { 1254 + ((*(p) == '=')) || ((*(p) == '+')) || ((*(p) == '$')) || 1255 + ((*(p) == ','))) { 1256 + ret[len++] = *p++; 1257 + } else { 1258 + int val = *(unsigned char *)p++; 1259 + int hi = val / 0x10, lo = val % 0x10; 1260 + ret[len++] = '%'; 1261 + ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0'); 1262 + ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0'); 1263 + } 1264 + } 1265 + } 1266 + if (uri->query != NULL) { 1267 + if (len + 1 >= max) { 1206 1268 temp = realloc2n(ret, &max); 1207 1269 ret = temp; 1208 - } 1209 - ret[len++] = '?'; 1210 - p = uri->query; 1211 - while (*p != 0) { 1212 - if (len + 1 >= max) { 1270 + } 1271 + ret[len++] = '?'; 1272 + p = uri->query; 1273 + while (*p != 0) { 1274 + if (len + 1 >= max) { 1213 1275 temp = realloc2n(ret, &max); 1214 1276 ret = temp; 1215 - } 1216 - ret[len++] = *p++; 1217 - } 1218 - } 1277 + } 1278 + ret[len++] = *p++; 1279 + } 1280 + } 1219 1281 } 1220 1282 if (uri->fragment != NULL) { 1221 - if (len + 3 >= max) { 1283 + if (len + 3 >= max) { 1222 1284 temp = realloc2n(ret, &max); 1223 1285 ret = temp; 1224 - } 1225 - ret[len++] = '#'; 1226 - p = uri->fragment; 1227 - while (*p != 0) { 1228 - if (len + 3 >= max) { 1286 + } 1287 + ret[len++] = '#'; 1288 + p = uri->fragment; 1289 + while (*p != 0) { 1290 + if (len + 3 >= max) { 1229 1291 temp = realloc2n(ret, &max); 1230 1292 ret = temp; 1231 - } 1232 - if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) 1233 - ret[len++] = *p++; 1234 - else { 1235 - int val = *(unsigned char *)p++; 1236 - int hi = val / 0x10, lo = val % 0x10; 1237 - ret[len++] = '%'; 1238 - ret[len++] = hi + (hi > 9? 'A'-10 : '0'); 1239 - ret[len++] = lo + (lo > 9? 'A'-10 : '0'); 1240 - } 1241 - } 1293 + } 1294 + if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) { 1295 + ret[len++] = *p++; 1296 + } else { 1297 + int val = *(unsigned char *)p++; 1298 + int hi = val / 0x10, lo = val % 0x10; 1299 + ret[len++] = '%'; 1300 + ret[len++] = hi + (hi > 9 ? 'A' - 10 : '0'); 1301 + ret[len++] = lo + (lo > 9 ? 'A' - 10 : '0'); 1302 + } 1303 + } 1242 1304 } 1243 1305 if (len >= max) { 1244 1306 temp = realloc2n(ret, &max); 1245 1307 ret = temp; 1246 1308 } 1247 1309 ret[len] = 0; 1248 - return(ret); 1310 + return ret; 1249 1311 } 1250 1312 1251 1313 /** ··· 1254 1316 * 1255 1317 * Make sure the URI struct is free of content 1256 1318 */ 1257 - static void 1258 - uri_clean(URI *uri) { 1259 - if (uri == NULL) return; 1319 + static void uri_clean(URI *uri) 1320 + { 1321 + if (uri == NULL) { 1322 + return; 1323 + } 1260 1324 1261 1325 g_free(uri->scheme); 1262 1326 uri->scheme = NULL; ··· 1282 1346 * 1283 1347 * Free up the URI struct 1284 1348 */ 1285 - void 1286 - uri_free(URI *uri) { 1349 + void uri_free(URI *uri) 1350 + { 1287 1351 uri_clean(uri); 1288 1352 g_free(uri); 1289 1353 } 1290 1354 1291 1355 /************************************************************************ 1292 - * * 1293 - * Helper functions * 1294 - * * 1356 + * * 1357 + * Helper functions * 1358 + * * 1295 1359 ************************************************************************/ 1296 1360 1297 1361 /** ··· 1305 1369 * 1306 1370 * Returns 0 or an error code 1307 1371 */ 1308 - static int 1309 - normalize_uri_path(char *path) { 1372 + static int normalize_uri_path(char *path) 1373 + { 1310 1374 char *cur, *out; 1311 1375 1312 - if (path == NULL) 1313 - return(-1); 1376 + if (path == NULL) { 1377 + return -1; 1378 + } 1314 1379 1315 1380 /* Skip all initial "/" chars. We want to get to the beginning of the 1316 1381 * first non-empty segment. 1317 1382 */ 1318 1383 cur = path; 1319 - while (cur[0] == '/') 1320 - ++cur; 1321 - if (cur[0] == '\0') 1322 - return(0); 1384 + while (cur[0] == '/') { 1385 + ++cur; 1386 + } 1387 + if (cur[0] == '\0') { 1388 + return 0; 1389 + } 1323 1390 1324 1391 /* Keep everything we've seen so far. */ 1325 1392 out = cur; ··· 1328 1395 * Analyze each segment in sequence for cases (c) and (d). 1329 1396 */ 1330 1397 while (cur[0] != '\0') { 1331 - /* 1332 - * c) All occurrences of "./", where "." is a complete path segment, 1333 - * are removed from the buffer string. 1334 - */ 1335 - if ((cur[0] == '.') && (cur[1] == '/')) { 1336 - cur += 2; 1337 - /* '//' normalization should be done at this point too */ 1338 - while (cur[0] == '/') 1339 - cur++; 1340 - continue; 1341 - } 1398 + /* 1399 + * c) All occurrences of "./", where "." is a complete path segment, 1400 + * are removed from the buffer string. 1401 + */ 1402 + if ((cur[0] == '.') && (cur[1] == '/')) { 1403 + cur += 2; 1404 + /* '//' normalization should be done at this point too */ 1405 + while (cur[0] == '/') { 1406 + cur++; 1407 + } 1408 + continue; 1409 + } 1342 1410 1343 - /* 1344 - * d) If the buffer string ends with "." as a complete path segment, 1345 - * that "." is removed. 1346 - */ 1347 - if ((cur[0] == '.') && (cur[1] == '\0')) 1348 - break; 1411 + /* 1412 + * d) If the buffer string ends with "." as a complete path segment, 1413 + * that "." is removed. 1414 + */ 1415 + if ((cur[0] == '.') && (cur[1] == '\0')) { 1416 + break; 1417 + } 1349 1418 1350 - /* Otherwise keep the segment. */ 1351 - while (cur[0] != '/') { 1352 - if (cur[0] == '\0') 1353 - goto done_cd; 1354 - (out++)[0] = (cur++)[0]; 1355 - } 1356 - /* nomalize // */ 1357 - while ((cur[0] == '/') && (cur[1] == '/')) 1358 - cur++; 1419 + /* Otherwise keep the segment. */ 1420 + while (cur[0] != '/') { 1421 + if (cur[0] == '\0') { 1422 + goto done_cd; 1423 + } 1424 + (out++)[0] = (cur++)[0]; 1425 + } 1426 + /* nomalize // */ 1427 + while ((cur[0] == '/') && (cur[1] == '/')) { 1428 + cur++; 1429 + } 1359 1430 1360 1431 (out++)[0] = (cur++)[0]; 1361 1432 } 1362 - done_cd: 1433 + done_cd: 1363 1434 out[0] = '\0'; 1364 1435 1365 1436 /* Reset to the beginning of the first segment for the next sequence. */ 1366 1437 cur = path; 1367 - while (cur[0] == '/') 1368 - ++cur; 1369 - if (cur[0] == '\0') 1370 - return(0); 1438 + while (cur[0] == '/') { 1439 + ++cur; 1440 + } 1441 + if (cur[0] == '\0') { 1442 + return 0; 1443 + } 1371 1444 1372 1445 /* 1373 1446 * Analyze each segment in sequence for cases (e) and (f). ··· 1396 1469 1397 1470 /* Find the end of the current segment. */ 1398 1471 segp = cur; 1399 - while ((segp[0] != '/') && (segp[0] != '\0')) 1400 - ++segp; 1472 + while ((segp[0] != '/') && (segp[0] != '\0')) { 1473 + ++segp; 1474 + } 1401 1475 1402 1476 /* If this is the last segment, we're done (we need at least two 1403 1477 * segments to meet the criteria for the (e) and (f) cases). 1404 1478 */ 1405 - if (segp[0] == '\0') 1406 - break; 1479 + if (segp[0] == '\0') { 1480 + break; 1481 + } 1407 1482 1408 1483 /* If the first segment is "..", or if the next segment _isn't_ "..", 1409 1484 * keep this segment and try the next one. 1410 1485 */ 1411 1486 ++segp; 1412 - if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur+3)) 1413 - || ((segp[0] != '.') || (segp[1] != '.') 1414 - || ((segp[2] != '/') && (segp[2] != '\0')))) { 1415 - cur = segp; 1416 - continue; 1487 + if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur + 3)) || 1488 + ((segp[0] != '.') || (segp[1] != '.') || 1489 + ((segp[2] != '/') && (segp[2] != '\0')))) { 1490 + cur = segp; 1491 + continue; 1417 1492 } 1418 1493 1419 1494 /* If we get here, remove this segment and the next one and back up ··· 1425 1500 1426 1501 /* If this is the end of the buffer, we're done. */ 1427 1502 if (segp[2] == '\0') { 1428 - cur[0] = '\0'; 1429 - break; 1503 + cur[0] = '\0'; 1504 + break; 1430 1505 } 1431 1506 /* Valgrind complained, strcpy(cur, segp + 3); */ 1432 1507 /* string will overlap, do not use strcpy */ 1433 1508 tmp = cur; 1434 1509 segp += 3; 1435 - while ((*tmp++ = *segp++) != 0) 1436 - ; 1510 + while ((*tmp++ = *segp++) != 0) { 1511 + /* No further work */ 1512 + } 1437 1513 1438 1514 /* If there are no previous segments, then keep going from here. */ 1439 1515 segp = cur; 1440 - while ((segp > path) && ((--segp)[0] == '/')) 1441 - ; 1442 - if (segp == path) 1443 - continue; 1516 + while ((segp > path) && ((--segp)[0] == '/')) { 1517 + /* No further work */ 1518 + } 1519 + if (segp == path) { 1520 + continue; 1521 + } 1444 1522 1445 1523 /* "segp" is pointing to the end of a previous segment; find it's 1446 1524 * start. We need to back up to the previous segment and start ··· 1450 1528 * remove the "foo/..". 1451 1529 */ 1452 1530 cur = segp; 1453 - while ((cur > path) && (cur[-1] != '/')) 1454 - --cur; 1531 + while ((cur > path) && (cur[-1] != '/')) { 1532 + --cur; 1533 + } 1455 1534 } 1456 1535 out[0] = '\0'; 1457 1536 ··· 1467 1546 * We discard them from the final path. 1468 1547 */ 1469 1548 if (path[0] == '/') { 1470 - cur = path; 1471 - while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.') 1472 - && ((cur[3] == '/') || (cur[3] == '\0'))) 1473 - cur += 3; 1549 + cur = path; 1550 + while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.') && 1551 + ((cur[3] == '/') || (cur[3] == '\0'))) { 1552 + cur += 3; 1553 + } 1474 1554 1475 - if (cur != path) { 1476 - out = path; 1477 - while (cur[0] != '\0') 1478 - (out++)[0] = (cur++)[0]; 1479 - out[0] = 0; 1480 - } 1555 + if (cur != path) { 1556 + out = path; 1557 + while (cur[0] != '\0') { 1558 + (out++)[0] = (cur++)[0]; 1559 + } 1560 + out[0] = 0; 1561 + } 1481 1562 } 1482 1563 1483 - return(0); 1564 + return 0; 1484 1565 } 1485 1566 1486 - static int is_hex(char c) { 1487 - if (((c >= '0') && (c <= '9')) || 1488 - ((c >= 'a') && (c <= 'f')) || 1489 - ((c >= 'A') && (c <= 'F'))) 1490 - return(1); 1491 - return(0); 1567 + static int is_hex(char c) 1568 + { 1569 + if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) || 1570 + ((c >= 'A') && (c <= 'F'))) { 1571 + return 1; 1572 + } 1573 + return 0; 1492 1574 } 1493 - 1494 1575 1495 1576 /** 1496 1577 * uri_string_unescape: ··· 1506 1587 * Returns a copy of the string, but unescaped, will return NULL only in case 1507 1588 * of error 1508 1589 */ 1509 - char * 1510 - uri_string_unescape(const char *str, int len, char *target) { 1590 + char *uri_string_unescape(const char *str, int len, char *target) 1591 + { 1511 1592 char *ret, *out; 1512 1593 const char *in; 1513 1594 1514 - if (str == NULL) 1515 - return(NULL); 1516 - if (len <= 0) len = strlen(str); 1517 - if (len < 0) return(NULL); 1595 + if (str == NULL) { 1596 + return NULL; 1597 + } 1598 + if (len <= 0) { 1599 + len = strlen(str); 1600 + } 1601 + if (len < 0) { 1602 + return NULL; 1603 + } 1518 1604 1519 1605 if (target == NULL) { 1520 - ret = g_malloc(len + 1); 1521 - } else 1522 - ret = target; 1606 + ret = g_malloc(len + 1); 1607 + } else { 1608 + ret = target; 1609 + } 1523 1610 in = str; 1524 1611 out = ret; 1525 - while(len > 0) { 1526 - if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) { 1527 - in++; 1528 - if ((*in >= '0') && (*in <= '9')) 1529 - *out = (*in - '0'); 1530 - else if ((*in >= 'a') && (*in <= 'f')) 1531 - *out = (*in - 'a') + 10; 1532 - else if ((*in >= 'A') && (*in <= 'F')) 1533 - *out = (*in - 'A') + 10; 1534 - in++; 1535 - if ((*in >= '0') && (*in <= '9')) 1536 - *out = *out * 16 + (*in - '0'); 1537 - else if ((*in >= 'a') && (*in <= 'f')) 1538 - *out = *out * 16 + (*in - 'a') + 10; 1539 - else if ((*in >= 'A') && (*in <= 'F')) 1540 - *out = *out * 16 + (*in - 'A') + 10; 1541 - in++; 1542 - len -= 3; 1543 - out++; 1544 - } else { 1545 - *out++ = *in++; 1546 - len--; 1547 - } 1612 + while (len > 0) { 1613 + if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) { 1614 + in++; 1615 + if ((*in >= '0') && (*in <= '9')) { 1616 + *out = (*in - '0'); 1617 + } else if ((*in >= 'a') && (*in <= 'f')) { 1618 + *out = (*in - 'a') + 10; 1619 + } else if ((*in >= 'A') && (*in <= 'F')) { 1620 + *out = (*in - 'A') + 10; 1621 + } 1622 + in++; 1623 + if ((*in >= '0') && (*in <= '9')) { 1624 + *out = *out * 16 + (*in - '0'); 1625 + } else if ((*in >= 'a') && (*in <= 'f')) { 1626 + *out = *out * 16 + (*in - 'a') + 10; 1627 + } else if ((*in >= 'A') && (*in <= 'F')) { 1628 + *out = *out * 16 + (*in - 'A') + 10; 1629 + } 1630 + in++; 1631 + len -= 3; 1632 + out++; 1633 + } else { 1634 + *out++ = *in++; 1635 + len--; 1636 + } 1548 1637 } 1549 1638 *out = 0; 1550 - return(ret); 1639 + return ret; 1551 1640 } 1552 1641 1553 1642 /** ··· 1560 1649 * 1561 1650 * Returns a new escaped string or NULL in case of error. 1562 1651 */ 1563 - char * 1564 - uri_string_escape(const char *str, const char *list) { 1652 + char *uri_string_escape(const char *str, const char *list) 1653 + { 1565 1654 char *ret, ch; 1566 1655 char *temp; 1567 1656 const char *in; 1568 1657 int len, out; 1569 1658 1570 - if (str == NULL) 1571 - return(NULL); 1572 - if (str[0] == 0) 1573 - return(g_strdup(str)); 1659 + if (str == NULL) { 1660 + return NULL; 1661 + } 1662 + if (str[0] == 0) { 1663 + return g_strdup(str); 1664 + } 1574 1665 len = strlen(str); 1575 - if (!(len > 0)) return(NULL); 1666 + if (!(len > 0)) { 1667 + return NULL; 1668 + } 1576 1669 1577 1670 len += 20; 1578 1671 ret = g_malloc(len); 1579 1672 in = str; 1580 1673 out = 0; 1581 - while(*in != 0) { 1582 - if (len - out <= 3) { 1674 + while (*in != 0) { 1675 + if (len - out <= 3) { 1583 1676 temp = realloc2n(ret, &len); 1584 - ret = temp; 1585 - } 1677 + ret = temp; 1678 + } 1586 1679 1587 - ch = *in; 1588 - 1589 - if ((ch != '@') && (!IS_UNRESERVED(ch)) && (!strchr(list, ch))) { 1590 - unsigned char val; 1591 - ret[out++] = '%'; 1592 - val = ch >> 4; 1593 - if (val <= 9) 1594 - ret[out++] = '0' + val; 1595 - else 1596 - ret[out++] = 'A' + val - 0xA; 1597 - val = ch & 0xF; 1598 - if (val <= 9) 1599 - ret[out++] = '0' + val; 1600 - else 1601 - ret[out++] = 'A' + val - 0xA; 1602 - in++; 1603 - } else { 1604 - ret[out++] = *in++; 1605 - } 1680 + ch = *in; 1606 1681 1682 + if ((ch != '@') && (!IS_UNRESERVED(ch)) && (!strchr(list, ch))) { 1683 + unsigned char val; 1684 + ret[out++] = '%'; 1685 + val = ch >> 4; 1686 + if (val <= 9) { 1687 + ret[out++] = '0' + val; 1688 + } else { 1689 + ret[out++] = 'A' + val - 0xA; 1690 + } 1691 + val = ch & 0xF; 1692 + if (val <= 9) { 1693 + ret[out++] = '0' + val; 1694 + } else { 1695 + ret[out++] = 'A' + val - 0xA; 1696 + } 1697 + in++; 1698 + } else { 1699 + ret[out++] = *in++; 1700 + } 1607 1701 } 1608 1702 ret[out] = 0; 1609 - return(ret); 1703 + return ret; 1610 1704 } 1611 1705 1612 1706 /************************************************************************ 1613 - * * 1614 - * Public functions * 1615 - * * 1707 + * * 1708 + * Public functions * 1709 + * * 1616 1710 ************************************************************************/ 1617 1711 1618 1712 /** ··· 1630 1724 * Returns a new URI string (to be freed by the caller) or NULL in case 1631 1725 * of error. 1632 1726 */ 1633 - char * 1634 - uri_resolve(const char *uri, const char *base) { 1727 + char *uri_resolve(const char *uri, const char *base) 1728 + { 1635 1729 char *val = NULL; 1636 1730 int ret, len, indx, cur, out; 1637 1731 URI *ref = NULL; ··· 1646 1740 * as a reference to "." rather than as a synonym for the current 1647 1741 * URI. Should we do that here? 1648 1742 */ 1649 - if (uri == NULL) 1650 - ret = -1; 1651 - else { 1652 - if (*uri) { 1653 - ref = uri_new(); 1654 - ret = uri_parse_into(ref, uri); 1655 - } 1656 - else 1657 - ret = 0; 1743 + if (uri == NULL) { 1744 + ret = -1; 1745 + } else { 1746 + if (*uri) { 1747 + ref = uri_new(); 1748 + ret = uri_parse_into(ref, uri); 1749 + } else { 1750 + ret = 0; 1751 + } 1658 1752 } 1659 - if (ret != 0) 1660 - goto done; 1753 + if (ret != 0) { 1754 + goto done; 1755 + } 1661 1756 if ((ref != NULL) && (ref->scheme != NULL)) { 1662 - /* 1663 - * The URI is absolute don't modify. 1664 - */ 1665 - val = g_strdup(uri); 1666 - goto done; 1757 + /* 1758 + * The URI is absolute don't modify. 1759 + */ 1760 + val = g_strdup(uri); 1761 + goto done; 1667 1762 } 1668 - if (base == NULL) 1669 - ret = -1; 1670 - else { 1671 - bas = uri_new(); 1672 - ret = uri_parse_into(bas, base); 1763 + if (base == NULL) { 1764 + ret = -1; 1765 + } else { 1766 + bas = uri_new(); 1767 + ret = uri_parse_into(bas, base); 1673 1768 } 1674 1769 if (ret != 0) { 1675 - if (ref) 1676 - val = uri_to_string(ref); 1677 - goto done; 1770 + if (ref) { 1771 + val = uri_to_string(ref); 1772 + } 1773 + goto done; 1678 1774 } 1679 1775 if (ref == NULL) { 1680 - /* 1681 - * the base fragment must be ignored 1682 - */ 1776 + /* 1777 + * the base fragment must be ignored 1778 + */ 1683 1779 g_free(bas->fragment); 1684 1780 bas->fragment = NULL; 1685 - val = uri_to_string(bas); 1686 - goto done; 1781 + val = uri_to_string(bas); 1782 + goto done; 1687 1783 } 1688 1784 1689 1785 /* ··· 1700 1796 */ 1701 1797 res = uri_new(); 1702 1798 if ((ref->scheme == NULL) && (ref->path == NULL) && 1703 - ((ref->authority == NULL) && (ref->server == NULL))) { 1799 + ((ref->authority == NULL) && (ref->server == NULL))) { 1704 1800 res->scheme = g_strdup(bas->scheme); 1705 - if (bas->authority != NULL) 1706 - res->authority = g_strdup(bas->authority); 1707 - else if (bas->server != NULL) { 1801 + if (bas->authority != NULL) { 1802 + res->authority = g_strdup(bas->authority); 1803 + } else if (bas->server != NULL) { 1708 1804 res->server = g_strdup(bas->server); 1709 1805 res->user = g_strdup(bas->user); 1710 1806 res->port = bas->port; 1711 - } 1807 + } 1712 1808 res->path = g_strdup(bas->path); 1713 1809 if (ref->query != NULL) { 1714 - res->query = g_strdup (ref->query); 1810 + res->query = g_strdup(ref->query); 1715 1811 } else { 1716 1812 res->query = g_strdup(bas->query); 1717 1813 } 1718 1814 res->fragment = g_strdup(ref->fragment); 1719 - goto step_7; 1815 + goto step_7; 1720 1816 } 1721 1817 1722 1818 /* ··· 1726 1822 * scheme is inherited from the base URI's scheme component. 1727 1823 */ 1728 1824 if (ref->scheme != NULL) { 1729 - val = uri_to_string(ref); 1730 - goto done; 1825 + val = uri_to_string(ref); 1826 + goto done; 1731 1827 } 1732 1828 res->scheme = g_strdup(bas->scheme); 1733 1829 ··· 1742 1838 * use an authority component. 1743 1839 */ 1744 1840 if ((ref->authority != NULL) || (ref->server != NULL)) { 1745 - if (ref->authority != NULL) 1746 - res->authority = g_strdup(ref->authority); 1747 - else { 1748 - res->server = g_strdup(ref->server); 1841 + if (ref->authority != NULL) { 1842 + res->authority = g_strdup(ref->authority); 1843 + } else { 1844 + res->server = g_strdup(ref->server); 1749 1845 res->user = g_strdup(ref->user); 1750 1846 res->port = ref->port; 1751 - } 1847 + } 1752 1848 res->path = g_strdup(ref->path); 1753 - goto step_7; 1849 + goto step_7; 1754 1850 } 1755 - if (bas->authority != NULL) 1756 - res->authority = g_strdup(bas->authority); 1757 - else if (bas->server != NULL) { 1851 + if (bas->authority != NULL) { 1852 + res->authority = g_strdup(bas->authority); 1853 + } else if (bas->server != NULL) { 1758 1854 res->server = g_strdup(bas->server); 1759 1855 res->user = g_strdup(bas->user); 1760 - res->port = bas->port; 1856 + res->port = bas->port; 1761 1857 } 1762 1858 1763 1859 /* ··· 1765 1861 * the reference is an absolute-path and we skip to step 7. 1766 1862 */ 1767 1863 if ((ref->path != NULL) && (ref->path[0] == '/')) { 1768 - res->path = g_strdup(ref->path); 1769 - goto step_7; 1864 + res->path = g_strdup(ref->path); 1865 + goto step_7; 1770 1866 } 1771 - 1772 1867 1773 1868 /* 1774 1869 * 6) If this step is reached, then we are resolving a relative-path ··· 1779 1874 * Allocate a buffer large enough for the result string. 1780 1875 */ 1781 1876 len = 2; /* extra / and 0 */ 1782 - if (ref->path != NULL) 1783 - len += strlen(ref->path); 1784 - if (bas->path != NULL) 1785 - len += strlen(bas->path); 1877 + if (ref->path != NULL) { 1878 + len += strlen(ref->path); 1879 + } 1880 + if (bas->path != NULL) { 1881 + len += strlen(bas->path); 1882 + } 1786 1883 res->path = g_malloc(len); 1787 1884 res->path[0] = 0; 1788 1885 ··· 1794 1891 cur = 0; 1795 1892 out = 0; 1796 1893 if (bas->path != NULL) { 1797 - while (bas->path[cur] != 0) { 1798 - while ((bas->path[cur] != 0) && (bas->path[cur] != '/')) 1799 - cur++; 1800 - if (bas->path[cur] == 0) 1801 - break; 1894 + while (bas->path[cur] != 0) { 1895 + while ((bas->path[cur] != 0) && (bas->path[cur] != '/')) { 1896 + cur++; 1897 + } 1898 + if (bas->path[cur] == 0) { 1899 + break; 1900 + } 1802 1901 1803 - cur++; 1804 - while (out < cur) { 1805 - res->path[out] = bas->path[out]; 1806 - out++; 1807 - } 1808 - } 1902 + cur++; 1903 + while (out < cur) { 1904 + res->path[out] = bas->path[out]; 1905 + out++; 1906 + } 1907 + } 1809 1908 } 1810 1909 res->path[out] = 0; 1811 1910 ··· 1814 1913 * string. 1815 1914 */ 1816 1915 if (ref->path != NULL && ref->path[0] != 0) { 1817 - indx = 0; 1818 - /* 1819 - * Ensure the path includes a '/' 1820 - */ 1821 - if ((out == 0) && (bas->server != NULL)) 1822 - res->path[out++] = '/'; 1823 - while (ref->path[indx] != 0) { 1824 - res->path[out++] = ref->path[indx++]; 1825 - } 1916 + indx = 0; 1917 + /* 1918 + * Ensure the path includes a '/' 1919 + */ 1920 + if ((out == 0) && (bas->server != NULL)) { 1921 + res->path[out++] = '/'; 1922 + } 1923 + while (ref->path[indx] != 0) { 1924 + res->path[out++] = ref->path[indx++]; 1925 + } 1826 1926 } 1827 1927 res->path[out] = 0; 1828 1928 ··· 1841 1941 val = uri_to_string(res); 1842 1942 1843 1943 done: 1844 - if (ref != NULL) 1845 - uri_free(ref); 1846 - if (bas != NULL) 1847 - uri_free(bas); 1848 - if (res != NULL) 1849 - uri_free(res); 1850 - return(val); 1944 + if (ref != NULL) { 1945 + uri_free(ref); 1946 + } 1947 + if (bas != NULL) { 1948 + uri_free(bas); 1949 + } 1950 + if (res != NULL) { 1951 + uri_free(res); 1952 + } 1953 + return val; 1851 1954 } 1852 1955 1853 1956 /** ··· 1882 1985 * Returns a new URI string (to be freed by the caller) or NULL in case 1883 1986 * error. 1884 1987 */ 1885 - char * 1886 - uri_resolve_relative (const char *uri, const char * base) 1988 + char *uri_resolve_relative(const char *uri, const char *base) 1887 1989 { 1888 1990 char *val = NULL; 1889 1991 int ret; ··· 1896 1998 char *bptr, *uptr, *vptr; 1897 1999 int remove_path = 0; 1898 2000 1899 - if ((uri == NULL) || (*uri == 0)) 1900 - return NULL; 2001 + if ((uri == NULL) || (*uri == 0)) { 2002 + return NULL; 2003 + } 1901 2004 1902 2005 /* 1903 2006 * First parse URI into a standard form 1904 2007 */ 1905 - ref = uri_new (); 2008 + ref = uri_new(); 1906 2009 /* If URI not already in "relative" form */ 1907 2010 if (uri[0] != '.') { 1908 - ret = uri_parse_into (ref, uri); 1909 - if (ret != 0) 1910 - goto done; /* Error in URI, return NULL */ 1911 - } else 1912 - ref->path = g_strdup(uri); 2011 + ret = uri_parse_into(ref, uri); 2012 + if (ret != 0) { 2013 + goto done; /* Error in URI, return NULL */ 2014 + } 2015 + } else { 2016 + ref->path = g_strdup(uri); 2017 + } 1913 2018 1914 2019 /* 1915 2020 * Next parse base into the same standard form 1916 2021 */ 1917 2022 if ((base == NULL) || (*base == 0)) { 1918 - val = g_strdup (uri); 1919 - goto done; 2023 + val = g_strdup(uri); 2024 + goto done; 1920 2025 } 1921 - bas = uri_new (); 2026 + bas = uri_new(); 1922 2027 if (base[0] != '.') { 1923 - ret = uri_parse_into (bas, base); 1924 - if (ret != 0) 1925 - goto done; /* Error in base, return NULL */ 1926 - } else 1927 - bas->path = g_strdup(base); 2028 + ret = uri_parse_into(bas, base); 2029 + if (ret != 0) { 2030 + goto done; /* Error in base, return NULL */ 2031 + } 2032 + } else { 2033 + bas->path = g_strdup(base); 2034 + } 1928 2035 1929 2036 /* 1930 2037 * If the scheme / server on the URI differs from the base, 1931 2038 * just return the URI 1932 2039 */ 1933 2040 if ((ref->scheme != NULL) && 1934 - ((bas->scheme == NULL) || 1935 - (strcmp (bas->scheme, ref->scheme)) || 1936 - (strcmp (bas->server, ref->server)))) { 1937 - val = g_strdup (uri); 1938 - goto done; 2041 + ((bas->scheme == NULL) || (strcmp(bas->scheme, ref->scheme)) || 2042 + (strcmp(bas->server, ref->server)))) { 2043 + val = g_strdup(uri); 2044 + goto done; 1939 2045 } 1940 2046 if (bas->path == ref->path || 1941 2047 (bas->path && ref->path && !strcmp(bas->path, ref->path))) { 1942 - val = g_strdup(""); 1943 - goto done; 2048 + val = g_strdup(""); 2049 + goto done; 1944 2050 } 1945 2051 if (bas->path == NULL) { 1946 - val = g_strdup(ref->path); 1947 - goto done; 2052 + val = g_strdup(ref->path); 2053 + goto done; 1948 2054 } 1949 2055 if (ref->path == NULL) { 1950 - ref->path = (char *) "/"; 1951 - remove_path = 1; 2056 + ref->path = (char *)"/"; 2057 + remove_path = 1; 1952 2058 } 1953 2059 1954 2060 /* ··· 1958 2064 * two path components may be missing (bug 316224) 1959 2065 */ 1960 2066 if (bas->path == NULL) { 1961 - if (ref->path != NULL) { 1962 - uptr = ref->path; 1963 - if (*uptr == '/') 1964 - uptr++; 1965 - /* exception characters from uri_to_string */ 1966 - val = uri_string_escape(uptr, "/;&=+$,"); 1967 - } 1968 - goto done; 2067 + if (ref->path != NULL) { 2068 + uptr = ref->path; 2069 + if (*uptr == '/') { 2070 + uptr++; 2071 + } 2072 + /* exception characters from uri_to_string */ 2073 + val = uri_string_escape(uptr, "/;&=+$,"); 2074 + } 2075 + goto done; 1969 2076 } 1970 2077 bptr = bas->path; 1971 2078 if (ref->path == NULL) { 1972 - for (ix = 0; bptr[ix] != 0; ix++) { 1973 - if (bptr[ix] == '/') 1974 - nbslash++; 1975 - } 1976 - uptr = NULL; 1977 - len = 1; /* this is for a string terminator only */ 2079 + for (ix = 0; bptr[ix] != 0; ix++) { 2080 + if (bptr[ix] == '/') { 2081 + nbslash++; 2082 + } 2083 + } 2084 + uptr = NULL; 2085 + len = 1; /* this is for a string terminator only */ 1978 2086 } else { 1979 - /* 1980 - * Next we compare the two strings and find where they first differ 1981 - */ 1982 - if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/')) 2087 + /* 2088 + * Next we compare the two strings and find where they first differ 2089 + */ 2090 + if ((ref->path[pos] == '.') && (ref->path[pos + 1] == '/')) { 1983 2091 pos += 2; 1984 - if ((*bptr == '.') && (bptr[1] == '/')) 2092 + } 2093 + if ((*bptr == '.') && (bptr[1] == '/')) { 1985 2094 bptr += 2; 1986 - else if ((*bptr == '/') && (ref->path[pos] != '/')) 1987 - bptr++; 1988 - while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0)) 1989 - pos++; 2095 + } else if ((*bptr == '/') && (ref->path[pos] != '/')) { 2096 + bptr++; 2097 + } 2098 + while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0)) { 2099 + pos++; 2100 + } 1990 2101 1991 - if (bptr[pos] == ref->path[pos]) { 1992 - val = g_strdup(""); 1993 - goto done; /* (I can't imagine why anyone would do this) */ 1994 - } 2102 + if (bptr[pos] == ref->path[pos]) { 2103 + val = g_strdup(""); 2104 + goto done; /* (I can't imagine why anyone would do this) */ 2105 + } 1995 2106 1996 - /* 1997 - * In URI, "back up" to the last '/' encountered. This will be the 1998 - * beginning of the "unique" suffix of URI 1999 - */ 2000 - ix = pos; 2001 - if ((ref->path[ix] == '/') && (ix > 0)) 2002 - ix--; 2003 - else if ((ref->path[ix] == 0) && (ix > 1) && (ref->path[ix - 1] == '/')) 2004 - ix -= 2; 2005 - for (; ix > 0; ix--) { 2006 - if (ref->path[ix] == '/') 2007 - break; 2008 - } 2009 - if (ix == 0) { 2010 - uptr = ref->path; 2011 - } else { 2012 - ix++; 2013 - uptr = &ref->path[ix]; 2014 - } 2107 + /* 2108 + * In URI, "back up" to the last '/' encountered. This will be the 2109 + * beginning of the "unique" suffix of URI 2110 + */ 2111 + ix = pos; 2112 + if ((ref->path[ix] == '/') && (ix > 0)) { 2113 + ix--; 2114 + } else if ((ref->path[ix] == 0) && (ix > 1) 2115 + && (ref->path[ix - 1] == '/')) { 2116 + ix -= 2; 2117 + } 2118 + for (; ix > 0; ix--) { 2119 + if (ref->path[ix] == '/') { 2120 + break; 2121 + } 2122 + } 2123 + if (ix == 0) { 2124 + uptr = ref->path; 2125 + } else { 2126 + ix++; 2127 + uptr = &ref->path[ix]; 2128 + } 2015 2129 2016 - /* 2017 - * In base, count the number of '/' from the differing point 2018 - */ 2019 - if (bptr[pos] != ref->path[pos]) {/* check for trivial URI == base */ 2020 - for (; bptr[ix] != 0; ix++) { 2021 - if (bptr[ix] == '/') 2022 - nbslash++; 2023 - } 2024 - } 2025 - len = strlen (uptr) + 1; 2130 + /* 2131 + * In base, count the number of '/' from the differing point 2132 + */ 2133 + if (bptr[pos] != ref->path[pos]) { /* check for trivial URI == base */ 2134 + for (; bptr[ix] != 0; ix++) { 2135 + if (bptr[ix] == '/') { 2136 + nbslash++; 2137 + } 2138 + } 2139 + } 2140 + len = strlen(uptr) + 1; 2026 2141 } 2027 2142 2028 2143 if (nbslash == 0) { 2029 - if (uptr != NULL) 2030 - /* exception characters from uri_to_string */ 2031 - val = uri_string_escape(uptr, "/;&=+$,"); 2032 - goto done; 2144 + if (uptr != NULL) { 2145 + /* exception characters from uri_to_string */ 2146 + val = uri_string_escape(uptr, "/;&=+$,"); 2147 + } 2148 + goto done; 2033 2149 } 2034 2150 2035 2151 /* ··· 2037 2153 * length of the remainder of the URI, plus enough space 2038 2154 * for the "../" groups, plus one for the terminator 2039 2155 */ 2040 - val = g_malloc (len + 3 * nbslash); 2156 + val = g_malloc(len + 3 * nbslash); 2041 2157 vptr = val; 2042 2158 /* 2043 2159 * Put in as many "../" as needed 2044 2160 */ 2045 - for (; nbslash>0; nbslash--) { 2046 - *vptr++ = '.'; 2047 - *vptr++ = '.'; 2048 - *vptr++ = '/'; 2161 + for (; nbslash > 0; nbslash--) { 2162 + *vptr++ = '.'; 2163 + *vptr++ = '.'; 2164 + *vptr++ = '/'; 2049 2165 } 2050 2166 /* 2051 2167 * Finish up with the end of the URI 2052 2168 */ 2053 2169 if (uptr != NULL) { 2054 - if ((vptr > val) && (len > 0) && 2055 - (uptr[0] == '/') && (vptr[-1] == '/')) { 2056 - memcpy (vptr, uptr + 1, len - 1); 2057 - vptr[len - 2] = 0; 2058 - } else { 2059 - memcpy (vptr, uptr, len); 2060 - vptr[len - 1] = 0; 2061 - } 2170 + if ((vptr > val) && (len > 0) && (uptr[0] == '/') && 2171 + (vptr[-1] == '/')) { 2172 + memcpy(vptr, uptr + 1, len - 1); 2173 + vptr[len - 2] = 0; 2174 + } else { 2175 + memcpy(vptr, uptr, len); 2176 + vptr[len - 1] = 0; 2177 + } 2062 2178 } else { 2063 - vptr[len - 1] = 0; 2179 + vptr[len - 1] = 0; 2064 2180 } 2065 2181 2066 2182 /* escape the freshly-built path */ 2067 2183 vptr = val; 2068 - /* exception characters from uri_to_string */ 2184 + /* exception characters from uri_to_string */ 2069 2185 val = uri_string_escape(vptr, "/;&=+$,"); 2070 2186 g_free(vptr); 2071 2187 ··· 2073 2189 /* 2074 2190 * Free the working variables 2075 2191 */ 2076 - if (remove_path != 0) 2192 + if (remove_path != 0) { 2077 2193 ref->path = NULL; 2078 - if (ref != NULL) 2079 - uri_free (ref); 2080 - if (bas != NULL) 2081 - uri_free (bas); 2194 + } 2195 + if (ref != NULL) { 2196 + uri_free(ref); 2197 + } 2198 + if (bas != NULL) { 2199 + uri_free(bas); 2200 + } 2082 2201 2083 2202 return val; 2084 2203 } ··· 2087 2206 * Utility functions to help parse and assemble query strings. 2088 2207 */ 2089 2208 2090 - struct QueryParams * 2091 - query_params_new (int init_alloc) 2209 + struct QueryParams *query_params_new(int init_alloc) 2092 2210 { 2093 2211 struct QueryParams *ps; 2094 2212 2095 - if (init_alloc <= 0) init_alloc = 1; 2213 + if (init_alloc <= 0) { 2214 + init_alloc = 1; 2215 + } 2096 2216 2097 2217 ps = g_new(QueryParams, 1); 2098 2218 ps->n = 0; ··· 2105 2225 /* Ensure there is space to store at least one more parameter 2106 2226 * at the end of the set. 2107 2227 */ 2108 - static int 2109 - query_params_append (struct QueryParams *ps, 2110 - const char *name, const char *value) 2228 + static int query_params_append(struct QueryParams *ps, const char *name, 2229 + const char *value) 2111 2230 { 2112 2231 if (ps->n >= ps->alloc) { 2113 2232 ps->p = g_renew(QueryParam, ps->p, ps->alloc * 2); ··· 2122 2241 return 0; 2123 2242 } 2124 2243 2125 - void 2126 - query_params_free (struct QueryParams *ps) 2244 + void query_params_free(struct QueryParams *ps) 2127 2245 { 2128 2246 int i; 2129 2247 2130 2248 for (i = 0; i < ps->n; ++i) { 2131 - g_free (ps->p[i].name); 2132 - g_free (ps->p[i].value); 2249 + g_free(ps->p[i].name); 2250 + g_free(ps->p[i].value); 2133 2251 } 2134 - g_free (ps->p); 2135 - g_free (ps); 2252 + g_free(ps->p); 2253 + g_free(ps); 2136 2254 } 2137 2255 2138 - struct QueryParams * 2139 - query_params_parse (const char *query) 2256 + struct QueryParams *query_params_parse(const char *query) 2140 2257 { 2141 2258 struct QueryParams *ps; 2142 2259 const char *end, *eq; 2143 2260 2144 - ps = query_params_new (0); 2145 - if (!query || query[0] == '\0') return ps; 2261 + ps = query_params_new(0); 2262 + if (!query || query[0] == '\0') { 2263 + return ps; 2264 + } 2146 2265 2147 2266 while (*query) { 2148 2267 char *name = NULL, *value = NULL; 2149 2268 2150 2269 /* Find the next separator, or end of the string. */ 2151 - end = strchr (query, '&'); 2152 - if (!end) 2153 - end = strchr (query, ';'); 2154 - if (!end) 2155 - end = query + strlen (query); 2270 + end = strchr(query, '&'); 2271 + if (!end) { 2272 + end = strchr(query, ';'); 2273 + } 2274 + if (!end) { 2275 + end = query + strlen(query); 2276 + } 2156 2277 2157 2278 /* Find the first '=' character between here and end. */ 2158 - eq = strchr (query, '='); 2159 - if (eq && eq >= end) eq = NULL; 2279 + eq = strchr(query, '='); 2280 + if (eq && eq >= end) { 2281 + eq = NULL; 2282 + } 2160 2283 2161 2284 /* Empty section (eg. "&&"). */ 2162 - if (end == query) 2285 + if (end == query) { 2163 2286 goto next; 2287 + } 2164 2288 2165 2289 /* If there is no '=' character, then we have just "name" 2166 2290 * and consistent with CGI.pm we assume value is "". 2167 2291 */ 2168 2292 else if (!eq) { 2169 - name = uri_string_unescape (query, end - query, NULL); 2293 + name = uri_string_unescape(query, end - query, NULL); 2170 2294 value = NULL; 2171 2295 } 2172 2296 /* Or if we have "name=" here (works around annoying 2173 2297 * problem when calling uri_string_unescape with len = 0). 2174 2298 */ 2175 - else if (eq+1 == end) { 2176 - name = uri_string_unescape (query, eq - query, NULL); 2299 + else if (eq + 1 == end) { 2300 + name = uri_string_unescape(query, eq - query, NULL); 2177 2301 value = g_new0(char, 1); 2178 2302 } 2179 2303 /* If the '=' character is at the beginning then we have 2180 2304 * "=value" and consistent with CGI.pm we _ignore_ this. 2181 2305 */ 2182 - else if (query == eq) 2306 + else if (query == eq) { 2183 2307 goto next; 2308 + } 2184 2309 2185 2310 /* Otherwise it's "name=value". */ 2186 2311 else { 2187 - name = uri_string_unescape (query, eq - query, NULL); 2188 - value = uri_string_unescape (eq+1, end - (eq+1), NULL); 2312 + name = uri_string_unescape(query, eq - query, NULL); 2313 + value = uri_string_unescape(eq + 1, end - (eq + 1), NULL); 2189 2314 } 2190 2315 2191 2316 /* Append to the parameter set. */ 2192 - query_params_append (ps, name, value); 2317 + query_params_append(ps, name, value); 2193 2318 g_free(name); 2194 2319 g_free(value); 2195 2320 2196 2321 next: 2197 2322 query = end; 2198 - if (*query) query ++; /* skip '&' separator */ 2323 + if (*query) { 2324 + query++; /* skip '&' separator */ 2325 + } 2199 2326 } 2200 2327 2201 2328 return ps;