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