/src/uriparser/src/UriShorten.c
Line | Count | Source |
1 | | /* |
2 | | * uriparser - RFC 3986 URI parsing library |
3 | | * |
4 | | * Copyright (C) 2007, Weijia Song <songweijia@gmail.com> |
5 | | * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org> |
6 | | * All rights reserved. |
7 | | * |
8 | | * Redistribution and use in source and binary forms, with or without |
9 | | * modification, are permitted provided that the following conditions |
10 | | * are met: |
11 | | * |
12 | | * 1. Redistributions of source code must retain the above |
13 | | * copyright notice, this list of conditions and the following |
14 | | * disclaimer. |
15 | | * |
16 | | * 2. Redistributions in binary form must reproduce the above |
17 | | * copyright notice, this list of conditions and the following |
18 | | * disclaimer in the documentation and/or other materials |
19 | | * provided with the distribution. |
20 | | * |
21 | | * 3. Neither the name of the copyright holder nor the names of |
22 | | * its contributors may be used to endorse or promote products |
23 | | * derived from this software without specific prior written |
24 | | * permission. |
25 | | * |
26 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
27 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
28 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
29 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
30 | | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
31 | | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
32 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
33 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
34 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
35 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
36 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
37 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | */ |
39 | | |
40 | | /* What encodings are enabled? */ |
41 | | #include <uriparser/UriDefsConfig.h> |
42 | | #if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE)) |
43 | | /* Include SELF twice */ |
44 | | # ifdef URI_ENABLE_ANSI |
45 | | # define URI_PASS_ANSI 1 |
46 | | # include "UriShorten.c" |
47 | | # undef URI_PASS_ANSI |
48 | | # endif |
49 | | # ifdef URI_ENABLE_UNICODE |
50 | | # define URI_PASS_UNICODE 1 |
51 | | # include "UriShorten.c" |
52 | | # undef URI_PASS_UNICODE |
53 | | # endif |
54 | | #else |
55 | | # ifdef URI_PASS_ANSI |
56 | | # include <uriparser/UriDefsAnsi.h> |
57 | | # else |
58 | | # include <uriparser/UriDefsUnicode.h> |
59 | | # include <wchar.h> |
60 | | # endif |
61 | | |
62 | | # ifndef URI_DOXYGEN |
63 | | # include <uriparser/Uri.h> |
64 | | # include "UriCommon.h" |
65 | | # include "UriMemory.h" |
66 | | # endif |
67 | | |
68 | | static URI_INLINE UriBool URI_FUNC(AppendSegment)(URI_TYPE(Uri) * uri, |
69 | 767 | const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) { |
70 | | /* Create segment */ |
71 | 767 | URI_TYPE(PathSegment) * segment = |
72 | 767 | memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment))); |
73 | 767 | if (segment == NULL) { |
74 | 0 | return URI_FALSE; /* Raises malloc error */ |
75 | 0 | } |
76 | 767 | segment->next = NULL; |
77 | 767 | segment->text.first = first; |
78 | 767 | segment->text.afterLast = afterLast; |
79 | | |
80 | | /* Put into chain */ |
81 | 767 | if (uri->pathTail == NULL) { |
82 | 47 | uri->pathHead = segment; |
83 | 720 | } else { |
84 | 720 | uri->pathTail->next = segment; |
85 | 720 | } |
86 | 767 | uri->pathTail = segment; |
87 | | |
88 | 767 | return URI_TRUE; |
89 | 767 | } UriShorten.c:uriAppendSegmentA Line | Count | Source | 69 | 767 | const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) { | 70 | | /* Create segment */ | 71 | 767 | URI_TYPE(PathSegment) * segment = | 72 | 767 | memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment))); | 73 | 767 | if (segment == NULL) { | 74 | 0 | return URI_FALSE; /* Raises malloc error */ | 75 | 0 | } | 76 | 767 | segment->next = NULL; | 77 | 767 | segment->text.first = first; | 78 | 767 | segment->text.afterLast = afterLast; | 79 | | | 80 | | /* Put into chain */ | 81 | 767 | if (uri->pathTail == NULL) { | 82 | 47 | uri->pathHead = segment; | 83 | 720 | } else { | 84 | 720 | uri->pathTail->next = segment; | 85 | 720 | } | 86 | 767 | uri->pathTail = segment; | 87 | | | 88 | 767 | return URI_TRUE; | 89 | 767 | } |
Unexecuted instantiation: UriShorten.c:uriAppendSegmentW |
90 | | |
91 | | static URI_INLINE UriBool URI_FUNC(EqualsAuthority)( |
92 | 123 | const URI_TYPE(Uri) * first, const URI_TYPE(Uri) * second) { |
93 | | /* IPv4 */ |
94 | 123 | if (first->hostData.ip4 != NULL) { |
95 | 2 | return ((second->hostData.ip4 != NULL) |
96 | 1 | && !memcmp( |
97 | 1 | first->hostData.ip4->data, second->hostData.ip4->data, 4)) |
98 | 2 | ? URI_TRUE |
99 | 2 | : URI_FALSE; |
100 | 2 | } |
101 | | |
102 | | /* IPv6 */ |
103 | 121 | if (first->hostData.ip6 != NULL) { |
104 | 16 | return ((second->hostData.ip6 != NULL) |
105 | 15 | && !memcmp( |
106 | 15 | first->hostData.ip6->data, second->hostData.ip6->data, 16)) |
107 | 16 | ? URI_TRUE |
108 | 16 | : URI_FALSE; |
109 | 16 | } |
110 | | |
111 | | /* IPvFuture */ |
112 | 105 | if (first->hostData.ipFuture.first != NULL) { |
113 | 2 | return ((second->hostData.ipFuture.first != NULL) |
114 | 1 | && URI_FUNC(RangeEquals)( |
115 | 1 | &first->hostData.ipFuture, &second->hostData.ipFuture)) |
116 | 2 | ? URI_TRUE |
117 | 2 | : URI_FALSE; |
118 | 2 | } |
119 | | |
120 | 103 | return URI_FUNC(RangeEquals)(&first->hostText, &second->hostText) ? URI_TRUE |
121 | 103 | : URI_FALSE; |
122 | 105 | } UriShorten.c:uriEqualsAuthorityA Line | Count | Source | 92 | 123 | const URI_TYPE(Uri) * first, const URI_TYPE(Uri) * second) { | 93 | | /* IPv4 */ | 94 | 123 | if (first->hostData.ip4 != NULL) { | 95 | 2 | return ((second->hostData.ip4 != NULL) | 96 | 1 | && !memcmp( | 97 | 1 | first->hostData.ip4->data, second->hostData.ip4->data, 4)) | 98 | 2 | ? URI_TRUE | 99 | 2 | : URI_FALSE; | 100 | 2 | } | 101 | | | 102 | | /* IPv6 */ | 103 | 121 | if (first->hostData.ip6 != NULL) { | 104 | 16 | return ((second->hostData.ip6 != NULL) | 105 | 15 | && !memcmp( | 106 | 15 | first->hostData.ip6->data, second->hostData.ip6->data, 16)) | 107 | 16 | ? URI_TRUE | 108 | 16 | : URI_FALSE; | 109 | 16 | } | 110 | | | 111 | | /* IPvFuture */ | 112 | 105 | if (first->hostData.ipFuture.first != NULL) { | 113 | 2 | return ((second->hostData.ipFuture.first != NULL) | 114 | 1 | && URI_FUNC(RangeEquals)( | 115 | 1 | &first->hostData.ipFuture, &second->hostData.ipFuture)) | 116 | 2 | ? URI_TRUE | 117 | 2 | : URI_FALSE; | 118 | 2 | } | 119 | | | 120 | 103 | return URI_FUNC(RangeEquals)(&first->hostText, &second->hostText) ? URI_TRUE | 121 | 103 | : URI_FALSE; | 122 | 105 | } |
Unexecuted instantiation: UriShorten.c:uriEqualsAuthorityW |
123 | | |
124 | | static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest, |
125 | | const URI_TYPE(Uri) * absSource, const URI_TYPE(Uri) * absBase, |
126 | 6.68k | UriBool domainRootMode, UriMemoryManager * memory) { |
127 | 6.68k | if (dest == NULL) { |
128 | 0 | return URI_ERROR_NULL; |
129 | 0 | } |
130 | 6.68k | URI_FUNC(ResetUri)(dest); |
131 | | |
132 | 6.68k | if ((absSource == NULL) || (absBase == NULL)) { |
133 | 0 | return URI_ERROR_NULL; |
134 | 0 | } |
135 | | |
136 | | /* absBase absolute? */ |
137 | 6.68k | if (absBase->scheme.first == NULL) { |
138 | 6.34k | return URI_ERROR_REMOVEBASE_REL_BASE; |
139 | 6.34k | } |
140 | | |
141 | | /* absSource absolute? */ |
142 | 334 | if (absSource->scheme.first == NULL) { |
143 | 150 | return URI_ERROR_REMOVEBASE_REL_SOURCE; |
144 | 150 | } |
145 | | |
146 | | /* NOTE: The curly brackets here force deeper indent (and that's all) */ |
147 | 184 | { |
148 | 184 | { |
149 | 184 | { |
150 | | /* clang-format off */ |
151 | | /* [01/50] if (A.scheme != Base.scheme) then */ |
152 | | /* clang-format on */ |
153 | 184 | if (!URI_FUNC(RangeEquals)(&absSource->scheme, &absBase->scheme)) { |
154 | | /* clang-format off */ |
155 | | /* [02/50] T.scheme = A.scheme; */ |
156 | | /* clang-format on */ |
157 | 61 | dest->scheme = absSource->scheme; |
158 | | /* clang-format off */ |
159 | | /* [03/50] T.authority = A.authority; */ |
160 | | /* clang-format on */ |
161 | 61 | if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) { |
162 | 0 | return URI_ERROR_MALLOC; |
163 | 0 | } |
164 | | /* clang-format off */ |
165 | | /* [04/50] T.path = A.path; */ |
166 | | /* clang-format on */ |
167 | 61 | if (!URI_FUNC(CopyPath)(dest, absSource, memory)) { |
168 | 0 | return URI_ERROR_MALLOC; |
169 | 0 | } |
170 | | /* clang-format off */ |
171 | | /* [05/50] else */ |
172 | | /* clang-format on */ |
173 | 123 | } else { |
174 | | /* clang-format off */ |
175 | | /* [06/50] undef(T.scheme); */ |
176 | | /* clang-format on */ |
177 | | /* NOOP */ |
178 | | /* clang-format off */ |
179 | | /* [07/50] if (A.authority != Base.authority) then */ |
180 | | /* clang-format on */ |
181 | 123 | if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) { |
182 | | /* clang-format off */ |
183 | | /* [08/50] T.authority = A.authority; */ |
184 | | /* clang-format on */ |
185 | 22 | if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) { |
186 | 0 | return URI_ERROR_MALLOC; |
187 | 0 | } |
188 | | /* clang-format off */ |
189 | | /* [09/50] T.path = A.path; */ |
190 | | /* clang-format on */ |
191 | 22 | if (!URI_FUNC(CopyPath)(dest, absSource, memory)) { |
192 | 0 | return URI_ERROR_MALLOC; |
193 | 0 | } |
194 | | /* clang-format off */ |
195 | | /* [10/50] else */ |
196 | | /* clang-format on */ |
197 | 101 | } else { |
198 | | /* clang-format off */ |
199 | | /* [11/50] if domainRootMode then */ |
200 | | /* clang-format on */ |
201 | 101 | if (domainRootMode == URI_TRUE) { |
202 | | /* clang-format off */ |
203 | | /* [12/50] undef(T.authority); */ |
204 | | /* clang-format on */ |
205 | | /* NOOP */ |
206 | | /* clang-format off */ |
207 | | /* [13/50] if (first(A.path) == "") then */ |
208 | | /* clang-format on */ |
209 | | /* GROUPED */ |
210 | | /* clang-format off */ |
211 | | /* [14/50] T.path = "/." + A.path; */ |
212 | | /* clang-format on */ |
213 | | /* GROUPED */ |
214 | | /* clang-format off */ |
215 | | /* [15/50] else */ |
216 | | /* clang-format on */ |
217 | | /* GROUPED */ |
218 | | /* clang-format off */ |
219 | | /* [16/50] T.path = A.path; */ |
220 | | /* clang-format on */ |
221 | | /* GROUPED */ |
222 | | /* clang-format off */ |
223 | | /* [17/50] endif; */ |
224 | | /* clang-format on */ |
225 | 19 | if (!URI_FUNC(CopyPath)(dest, absSource, memory)) { |
226 | 0 | return URI_ERROR_MALLOC; |
227 | 0 | } |
228 | 19 | dest->absolutePath = URI_TRUE; |
229 | | |
230 | 19 | if (!URI_FUNC(FixAmbiguity)(dest, memory)) { |
231 | 0 | return URI_ERROR_MALLOC; |
232 | 0 | } |
233 | | /* clang-format off */ |
234 | | /* [18/50] else */ |
235 | | /* clang-format on */ |
236 | 82 | } else { |
237 | 82 | const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead; |
238 | 82 | const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead; |
239 | | /* clang-format off */ |
240 | | /* [19/50] bool pathNaked = true; */ |
241 | | /* clang-format on */ |
242 | 82 | UriBool pathNaked = URI_TRUE; |
243 | | /* clang-format off */ |
244 | | /* [20/50] undef(last(Base.path)); */ |
245 | | /* clang-format on */ |
246 | | /* NOOP */ |
247 | | /* clang-format off */ |
248 | | /* [21/50] T.path = ""; */ |
249 | | /* clang-format on */ |
250 | 82 | dest->absolutePath = URI_FALSE; |
251 | | /* clang-format off */ |
252 | | /* [22/50] while (first(A.path) == first(Base.path)) do */ |
253 | | /* clang-format on */ |
254 | 755 | while ((sourceSeg != NULL) && (baseSeg != NULL) |
255 | 680 | && URI_FUNC(RangeEquals)( |
256 | 680 | &sourceSeg->text, &baseSeg->text) |
257 | 676 | && !((sourceSeg->text.first |
258 | 676 | == sourceSeg->text.afterLast) |
259 | 380 | && ((sourceSeg->next == NULL) |
260 | 673 | != (baseSeg->next == NULL)))) { |
261 | | /* clang-format off */ |
262 | | /* [23/50] A.path++; */ |
263 | | /* clang-format on */ |
264 | 673 | sourceSeg = sourceSeg->next; |
265 | | /* clang-format off */ |
266 | | /* [24/50] Base.path++; */ |
267 | | /* clang-format on */ |
268 | 673 | baseSeg = baseSeg->next; |
269 | | /* clang-format off */ |
270 | | /* [25/50] endwhile; */ |
271 | | /* clang-format on */ |
272 | 673 | } |
273 | | /* clang-format off */ |
274 | | /* [26/50] while defined(first(Base.path)) do */ |
275 | | /* clang-format on */ |
276 | 512 | while ((baseSeg != NULL) && (baseSeg->next != NULL)) { |
277 | | /* clang-format off */ |
278 | | /* [27/50] Base.path++; */ |
279 | | /* clang-format on */ |
280 | 430 | baseSeg = baseSeg->next; |
281 | | /* clang-format off */ |
282 | | /* [28/50] T.path += "../"; */ |
283 | | /* clang-format on */ |
284 | 430 | if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent), |
285 | 430 | URI_FUNC(ConstParent) + 2, memory)) { |
286 | 0 | return URI_ERROR_MALLOC; |
287 | 0 | } |
288 | | /* clang-format off */ |
289 | | /* [29/50] pathNaked = false; */ |
290 | | /* clang-format on */ |
291 | 430 | pathNaked = URI_FALSE; |
292 | | /* clang-format off */ |
293 | | /* [30/50] endwhile; */ |
294 | | /* clang-format on */ |
295 | 430 | } |
296 | | /* clang-format off */ |
297 | | /* [31/50] while defined(first(A.path)) do */ |
298 | | /* clang-format on */ |
299 | 403 | while (sourceSeg != NULL) { |
300 | | /* clang-format off */ |
301 | | /* [32/50] if pathNaked then */ |
302 | | /* clang-format on */ |
303 | 321 | if (pathNaked == URI_TRUE) { |
304 | | /* clang-format off */ |
305 | | /* [33/50] if (first(A.path) contains ":") then */ |
306 | | /* clang-format on */ |
307 | 31 | UriBool containsColon = URI_FALSE; |
308 | 31 | const URI_CHAR * ch = sourceSeg->text.first; |
309 | 249 | for (; ch < sourceSeg->text.afterLast; ch++) { |
310 | 228 | if (*ch == _UT(':')) { |
311 | 10 | containsColon = URI_TRUE; |
312 | 10 | break; |
313 | 10 | } |
314 | 228 | } |
315 | | |
316 | 31 | if (containsColon) { |
317 | | /* clang-format off */ |
318 | | /* [34/50] T.path += "./"; */ |
319 | | /* clang-format on */ |
320 | 10 | if (!URI_FUNC(AppendSegment)(dest, |
321 | 10 | URI_FUNC(ConstPwd), |
322 | 10 | URI_FUNC(ConstPwd) + 1, memory)) { |
323 | 0 | return URI_ERROR_MALLOC; |
324 | 0 | } |
325 | | /* clang-format off */ |
326 | | /* [35/50] elseif (first(A.path) == "") then */ |
327 | | /* clang-format on */ |
328 | 21 | } else if (sourceSeg->text.first |
329 | 21 | == sourceSeg->text.afterLast) { |
330 | | /* clang-format off */ |
331 | | /* [36/50] T.path += "/."; */ |
332 | | /* clang-format on */ |
333 | 6 | if (!URI_FUNC(AppendSegment)(dest, |
334 | 6 | URI_FUNC(ConstPwd), |
335 | 6 | URI_FUNC(ConstPwd) + 1, memory)) { |
336 | 0 | return URI_ERROR_MALLOC; |
337 | 0 | } |
338 | | /* clang-format off */ |
339 | | /* [37/50] endif; */ |
340 | | /* clang-format on */ |
341 | 6 | } |
342 | | /* clang-format off */ |
343 | | /* [38/50] endif; */ |
344 | | /* clang-format on */ |
345 | 31 | } |
346 | | /* clang-format off */ |
347 | | /* [39/50] T.path += first(A.path); */ |
348 | | /* clang-format on */ |
349 | 321 | if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first, |
350 | 321 | sourceSeg->text.afterLast, memory)) { |
351 | 0 | return URI_ERROR_MALLOC; |
352 | 0 | } |
353 | | /* clang-format off */ |
354 | | /* [40/50] pathNaked = false; */ |
355 | | /* clang-format on */ |
356 | 321 | pathNaked = URI_FALSE; |
357 | | /* clang-format off */ |
358 | | /* [41/50] A.path++; */ |
359 | | /* clang-format on */ |
360 | 321 | sourceSeg = sourceSeg->next; |
361 | | /* clang-format off */ |
362 | | /* [42/50] if defined(first(A.path)) then */ |
363 | | /* clang-format on */ |
364 | | /* NOOP */ |
365 | | /* clang-format off */ |
366 | | /* [43/50] T.path += + "/"; */ |
367 | | /* clang-format on */ |
368 | | /* NOOP */ |
369 | | /* clang-format off */ |
370 | | /* [44/50] endif; */ |
371 | | /* clang-format on */ |
372 | | /* NOOP */ |
373 | | /* clang-format off */ |
374 | | /* [45/50] endwhile; */ |
375 | | /* clang-format on */ |
376 | 321 | } |
377 | | /* clang-format off */ |
378 | | /* [46/50] endif; */ |
379 | | /* clang-format on */ |
380 | 82 | } |
381 | | /* clang-format off */ |
382 | | /* [47/50] endif; */ |
383 | | /* clang-format on */ |
384 | 101 | } |
385 | | /* clang-format off */ |
386 | | /* [48/50] endif; */ |
387 | | /* clang-format on */ |
388 | 123 | } |
389 | | /* clang-format off */ |
390 | | /* [49/50] T.query = A.query; */ |
391 | | /* clang-format on */ |
392 | 184 | dest->query = absSource->query; |
393 | | /* clang-format off */ |
394 | | /* [50/50] T.fragment = A.fragment; */ |
395 | | /* clang-format on */ |
396 | 184 | dest->fragment = absSource->fragment; |
397 | 184 | } |
398 | 184 | } |
399 | 184 | } |
400 | 184 | return URI_SUCCESS; |
401 | 184 | } UriShorten.c:uriRemoveBaseUriImplA Line | Count | Source | 126 | 6.68k | UriBool domainRootMode, UriMemoryManager * memory) { | 127 | 6.68k | if (dest == NULL) { | 128 | 0 | return URI_ERROR_NULL; | 129 | 0 | } | 130 | 6.68k | URI_FUNC(ResetUri)(dest); | 131 | | | 132 | 6.68k | if ((absSource == NULL) || (absBase == NULL)) { | 133 | 0 | return URI_ERROR_NULL; | 134 | 0 | } | 135 | | | 136 | | /* absBase absolute? */ | 137 | 6.68k | if (absBase->scheme.first == NULL) { | 138 | 6.34k | return URI_ERROR_REMOVEBASE_REL_BASE; | 139 | 6.34k | } | 140 | | | 141 | | /* absSource absolute? */ | 142 | 334 | if (absSource->scheme.first == NULL) { | 143 | 150 | return URI_ERROR_REMOVEBASE_REL_SOURCE; | 144 | 150 | } | 145 | | | 146 | | /* NOTE: The curly brackets here force deeper indent (and that's all) */ | 147 | 184 | { | 148 | 184 | { | 149 | 184 | { | 150 | | /* clang-format off */ | 151 | | /* [01/50] if (A.scheme != Base.scheme) then */ | 152 | | /* clang-format on */ | 153 | 184 | if (!URI_FUNC(RangeEquals)(&absSource->scheme, &absBase->scheme)) { | 154 | | /* clang-format off */ | 155 | | /* [02/50] T.scheme = A.scheme; */ | 156 | | /* clang-format on */ | 157 | 61 | dest->scheme = absSource->scheme; | 158 | | /* clang-format off */ | 159 | | /* [03/50] T.authority = A.authority; */ | 160 | | /* clang-format on */ | 161 | 61 | if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) { | 162 | 0 | return URI_ERROR_MALLOC; | 163 | 0 | } | 164 | | /* clang-format off */ | 165 | | /* [04/50] T.path = A.path; */ | 166 | | /* clang-format on */ | 167 | 61 | if (!URI_FUNC(CopyPath)(dest, absSource, memory)) { | 168 | 0 | return URI_ERROR_MALLOC; | 169 | 0 | } | 170 | | /* clang-format off */ | 171 | | /* [05/50] else */ | 172 | | /* clang-format on */ | 173 | 123 | } else { | 174 | | /* clang-format off */ | 175 | | /* [06/50] undef(T.scheme); */ | 176 | | /* clang-format on */ | 177 | | /* NOOP */ | 178 | | /* clang-format off */ | 179 | | /* [07/50] if (A.authority != Base.authority) then */ | 180 | | /* clang-format on */ | 181 | 123 | if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) { | 182 | | /* clang-format off */ | 183 | | /* [08/50] T.authority = A.authority; */ | 184 | | /* clang-format on */ | 185 | 22 | if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) { | 186 | 0 | return URI_ERROR_MALLOC; | 187 | 0 | } | 188 | | /* clang-format off */ | 189 | | /* [09/50] T.path = A.path; */ | 190 | | /* clang-format on */ | 191 | 22 | if (!URI_FUNC(CopyPath)(dest, absSource, memory)) { | 192 | 0 | return URI_ERROR_MALLOC; | 193 | 0 | } | 194 | | /* clang-format off */ | 195 | | /* [10/50] else */ | 196 | | /* clang-format on */ | 197 | 101 | } else { | 198 | | /* clang-format off */ | 199 | | /* [11/50] if domainRootMode then */ | 200 | | /* clang-format on */ | 201 | 101 | if (domainRootMode == URI_TRUE) { | 202 | | /* clang-format off */ | 203 | | /* [12/50] undef(T.authority); */ | 204 | | /* clang-format on */ | 205 | | /* NOOP */ | 206 | | /* clang-format off */ | 207 | | /* [13/50] if (first(A.path) == "") then */ | 208 | | /* clang-format on */ | 209 | | /* GROUPED */ | 210 | | /* clang-format off */ | 211 | | /* [14/50] T.path = "/." + A.path; */ | 212 | | /* clang-format on */ | 213 | | /* GROUPED */ | 214 | | /* clang-format off */ | 215 | | /* [15/50] else */ | 216 | | /* clang-format on */ | 217 | | /* GROUPED */ | 218 | | /* clang-format off */ | 219 | | /* [16/50] T.path = A.path; */ | 220 | | /* clang-format on */ | 221 | | /* GROUPED */ | 222 | | /* clang-format off */ | 223 | | /* [17/50] endif; */ | 224 | | /* clang-format on */ | 225 | 19 | if (!URI_FUNC(CopyPath)(dest, absSource, memory)) { | 226 | 0 | return URI_ERROR_MALLOC; | 227 | 0 | } | 228 | 19 | dest->absolutePath = URI_TRUE; | 229 | | | 230 | 19 | if (!URI_FUNC(FixAmbiguity)(dest, memory)) { | 231 | 0 | return URI_ERROR_MALLOC; | 232 | 0 | } | 233 | | /* clang-format off */ | 234 | | /* [18/50] else */ | 235 | | /* clang-format on */ | 236 | 82 | } else { | 237 | 82 | const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead; | 238 | 82 | const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead; | 239 | | /* clang-format off */ | 240 | | /* [19/50] bool pathNaked = true; */ | 241 | | /* clang-format on */ | 242 | 82 | UriBool pathNaked = URI_TRUE; | 243 | | /* clang-format off */ | 244 | | /* [20/50] undef(last(Base.path)); */ | 245 | | /* clang-format on */ | 246 | | /* NOOP */ | 247 | | /* clang-format off */ | 248 | | /* [21/50] T.path = ""; */ | 249 | | /* clang-format on */ | 250 | 82 | dest->absolutePath = URI_FALSE; | 251 | | /* clang-format off */ | 252 | | /* [22/50] while (first(A.path) == first(Base.path)) do */ | 253 | | /* clang-format on */ | 254 | 755 | while ((sourceSeg != NULL) && (baseSeg != NULL) | 255 | 680 | && URI_FUNC(RangeEquals)( | 256 | 680 | &sourceSeg->text, &baseSeg->text) | 257 | 676 | && !((sourceSeg->text.first | 258 | 676 | == sourceSeg->text.afterLast) | 259 | 380 | && ((sourceSeg->next == NULL) | 260 | 673 | != (baseSeg->next == NULL)))) { | 261 | | /* clang-format off */ | 262 | | /* [23/50] A.path++; */ | 263 | | /* clang-format on */ | 264 | 673 | sourceSeg = sourceSeg->next; | 265 | | /* clang-format off */ | 266 | | /* [24/50] Base.path++; */ | 267 | | /* clang-format on */ | 268 | 673 | baseSeg = baseSeg->next; | 269 | | /* clang-format off */ | 270 | | /* [25/50] endwhile; */ | 271 | | /* clang-format on */ | 272 | 673 | } | 273 | | /* clang-format off */ | 274 | | /* [26/50] while defined(first(Base.path)) do */ | 275 | | /* clang-format on */ | 276 | 512 | while ((baseSeg != NULL) && (baseSeg->next != NULL)) { | 277 | | /* clang-format off */ | 278 | | /* [27/50] Base.path++; */ | 279 | | /* clang-format on */ | 280 | 430 | baseSeg = baseSeg->next; | 281 | | /* clang-format off */ | 282 | | /* [28/50] T.path += "../"; */ | 283 | | /* clang-format on */ | 284 | 430 | if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent), | 285 | 430 | URI_FUNC(ConstParent) + 2, memory)) { | 286 | 0 | return URI_ERROR_MALLOC; | 287 | 0 | } | 288 | | /* clang-format off */ | 289 | | /* [29/50] pathNaked = false; */ | 290 | | /* clang-format on */ | 291 | 430 | pathNaked = URI_FALSE; | 292 | | /* clang-format off */ | 293 | | /* [30/50] endwhile; */ | 294 | | /* clang-format on */ | 295 | 430 | } | 296 | | /* clang-format off */ | 297 | | /* [31/50] while defined(first(A.path)) do */ | 298 | | /* clang-format on */ | 299 | 403 | while (sourceSeg != NULL) { | 300 | | /* clang-format off */ | 301 | | /* [32/50] if pathNaked then */ | 302 | | /* clang-format on */ | 303 | 321 | if (pathNaked == URI_TRUE) { | 304 | | /* clang-format off */ | 305 | | /* [33/50] if (first(A.path) contains ":") then */ | 306 | | /* clang-format on */ | 307 | 31 | UriBool containsColon = URI_FALSE; | 308 | 31 | const URI_CHAR * ch = sourceSeg->text.first; | 309 | 249 | for (; ch < sourceSeg->text.afterLast; ch++) { | 310 | 228 | if (*ch == _UT(':')) { | 311 | 10 | containsColon = URI_TRUE; | 312 | 10 | break; | 313 | 10 | } | 314 | 228 | } | 315 | | | 316 | 31 | if (containsColon) { | 317 | | /* clang-format off */ | 318 | | /* [34/50] T.path += "./"; */ | 319 | | /* clang-format on */ | 320 | 10 | if (!URI_FUNC(AppendSegment)(dest, | 321 | 10 | URI_FUNC(ConstPwd), | 322 | 10 | URI_FUNC(ConstPwd) + 1, memory)) { | 323 | 0 | return URI_ERROR_MALLOC; | 324 | 0 | } | 325 | | /* clang-format off */ | 326 | | /* [35/50] elseif (first(A.path) == "") then */ | 327 | | /* clang-format on */ | 328 | 21 | } else if (sourceSeg->text.first | 329 | 21 | == sourceSeg->text.afterLast) { | 330 | | /* clang-format off */ | 331 | | /* [36/50] T.path += "/."; */ | 332 | | /* clang-format on */ | 333 | 6 | if (!URI_FUNC(AppendSegment)(dest, | 334 | 6 | URI_FUNC(ConstPwd), | 335 | 6 | URI_FUNC(ConstPwd) + 1, memory)) { | 336 | 0 | return URI_ERROR_MALLOC; | 337 | 0 | } | 338 | | /* clang-format off */ | 339 | | /* [37/50] endif; */ | 340 | | /* clang-format on */ | 341 | 6 | } | 342 | | /* clang-format off */ | 343 | | /* [38/50] endif; */ | 344 | | /* clang-format on */ | 345 | 31 | } | 346 | | /* clang-format off */ | 347 | | /* [39/50] T.path += first(A.path); */ | 348 | | /* clang-format on */ | 349 | 321 | if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first, | 350 | 321 | sourceSeg->text.afterLast, memory)) { | 351 | 0 | return URI_ERROR_MALLOC; | 352 | 0 | } | 353 | | /* clang-format off */ | 354 | | /* [40/50] pathNaked = false; */ | 355 | | /* clang-format on */ | 356 | 321 | pathNaked = URI_FALSE; | 357 | | /* clang-format off */ | 358 | | /* [41/50] A.path++; */ | 359 | | /* clang-format on */ | 360 | 321 | sourceSeg = sourceSeg->next; | 361 | | /* clang-format off */ | 362 | | /* [42/50] if defined(first(A.path)) then */ | 363 | | /* clang-format on */ | 364 | | /* NOOP */ | 365 | | /* clang-format off */ | 366 | | /* [43/50] T.path += + "/"; */ | 367 | | /* clang-format on */ | 368 | | /* NOOP */ | 369 | | /* clang-format off */ | 370 | | /* [44/50] endif; */ | 371 | | /* clang-format on */ | 372 | | /* NOOP */ | 373 | | /* clang-format off */ | 374 | | /* [45/50] endwhile; */ | 375 | | /* clang-format on */ | 376 | 321 | } | 377 | | /* clang-format off */ | 378 | | /* [46/50] endif; */ | 379 | | /* clang-format on */ | 380 | 82 | } | 381 | | /* clang-format off */ | 382 | | /* [47/50] endif; */ | 383 | | /* clang-format on */ | 384 | 101 | } | 385 | | /* clang-format off */ | 386 | | /* [48/50] endif; */ | 387 | | /* clang-format on */ | 388 | 123 | } | 389 | | /* clang-format off */ | 390 | | /* [49/50] T.query = A.query; */ | 391 | | /* clang-format on */ | 392 | 184 | dest->query = absSource->query; | 393 | | /* clang-format off */ | 394 | | /* [50/50] T.fragment = A.fragment; */ | 395 | | /* clang-format on */ | 396 | 184 | dest->fragment = absSource->fragment; | 397 | 184 | } | 398 | 184 | } | 399 | 184 | } | 400 | 184 | return URI_SUCCESS; | 401 | 184 | } |
Unexecuted instantiation: UriShorten.c:uriRemoveBaseUriImplW |
402 | | |
403 | | int URI_FUNC(RemoveBaseUri)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * absSource, |
404 | 6.68k | const URI_TYPE(Uri) * absBase, UriBool domainRootMode) { |
405 | 6.68k | return URI_FUNC(RemoveBaseUriMm)(dest, absSource, absBase, domainRootMode, NULL); |
406 | 6.68k | } Line | Count | Source | 404 | 6.68k | const URI_TYPE(Uri) * absBase, UriBool domainRootMode) { | 405 | 6.68k | return URI_FUNC(RemoveBaseUriMm)(dest, absSource, absBase, domainRootMode, NULL); | 406 | 6.68k | } |
Unexecuted instantiation: uriRemoveBaseUriW |
407 | | |
408 | | int URI_FUNC(RemoveBaseUriMm)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * absSource, |
409 | | const URI_TYPE(Uri) * absBase, UriBool domainRootMode, |
410 | 6.68k | UriMemoryManager * memory) { |
411 | 6.68k | int res; |
412 | | |
413 | 6.68k | URI_CHECK_MEMORY_MANAGER(memory); /* may return */ |
414 | | |
415 | 6.68k | res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource, absBase, domainRootMode, memory); |
416 | 6.68k | if ((res != URI_SUCCESS) && (dest != NULL)) { |
417 | 6.49k | URI_FUNC(FreeUriMembersMm)(dest, memory); |
418 | 6.49k | } |
419 | 6.68k | return res; |
420 | 6.68k | } Line | Count | Source | 410 | 6.68k | UriMemoryManager * memory) { | 411 | 6.68k | int res; | 412 | | | 413 | 6.68k | URI_CHECK_MEMORY_MANAGER(memory); /* may return */ | 414 | | | 415 | 6.68k | res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource, absBase, domainRootMode, memory); | 416 | 6.68k | if ((res != URI_SUCCESS) && (dest != NULL)) { | 417 | 6.49k | URI_FUNC(FreeUriMembersMm)(dest, memory); | 418 | 6.49k | } | 419 | 6.68k | return res; | 420 | 6.68k | } |
Unexecuted instantiation: uriRemoveBaseUriMmW |
421 | | |
422 | | #endif |