| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#include <uriparser/UriDefsConfig.h> |
| 42 |
#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE)) |
| 43 |
|
| 44 |
# ifdef URI_ENABLE_ANSI |
| 45 |
# define URI_PASS_ANSI 1 |
| 46 |
# include "UriCommon.c" |
| 47 |
# undef URI_PASS_ANSI |
| 48 |
# endif |
| 49 |
# ifdef URI_ENABLE_UNICODE |
| 50 |
# define URI_PASS_UNICODE 1 |
| 51 |
# include "UriCommon.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 "UriSets.h" |
| 66 |
# endif |
| 67 |
|
| 68 |
# include <assert.h> |
| 69 |
|
| 70 |
const URI_CHAR * const URI_FUNC(SafeToPointTo) = _UT("X"); |
| 71 |
const URI_CHAR * const URI_FUNC(ConstPwd) = _UT("."); |
| 72 |
const URI_CHAR * const URI_FUNC(ConstParent) = _UT(".."); |
| 73 |
|
| 74 |
void URI_FUNC(ResetUri)(URI_TYPE(Uri) * uri) { |
| 75 |
if (uri == NULL) { |
| 76 |
return; |
| 77 |
} |
| 78 |
memset(uri, 0, sizeof(URI_TYPE(Uri))); |
| 79 |
} |
| 80 |
|
| 81 |
int URI_FUNC(FreeUriPath)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) { |
| 82 |
assert(uri != NULL); |
| 83 |
assert(memory != NULL); |
| 84 |
|
| 85 |
if (uri->pathHead != NULL) { |
| 86 |
URI_TYPE(PathSegment) * segWalk = uri->pathHead; |
| 87 |
while (segWalk != NULL) { |
| 88 |
URI_TYPE(PathSegment) * const next = segWalk->next; |
| 89 |
if ((uri->owner == URI_TRUE) |
| 90 |
&& (segWalk->text.first != segWalk->text.afterLast)) { |
| 91 |
memory->free(memory, (URI_CHAR *)segWalk->text.first); |
| 92 |
} |
| 93 |
segWalk->text.first = NULL; |
| 94 |
segWalk->text.afterLast = NULL; |
| 95 |
segWalk->next = NULL; |
| 96 |
memory->free(memory, segWalk); |
| 97 |
segWalk = next; |
| 98 |
} |
| 99 |
uri->pathHead = NULL; |
| 100 |
uri->pathTail = NULL; |
| 101 |
} |
| 102 |
|
| 103 |
return URI_SUCCESS; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
int URI_FUNC(CompareRange)(const URI_TYPE(TextRange) * a, const URI_TYPE(TextRange) * b) { |
| 108 |
int diff; |
| 109 |
|
| 110 |
|
| 111 |
if ((a == NULL) || (b == NULL)) { |
| 112 |
return ((a == NULL) ? 0 : 1) - ((b == NULL) ? 0 : 1); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
if ((a->first == NULL) || (b->first == NULL)) { |
| 117 |
return ((a->first == NULL) ? 0 : 1) - ((b->first == NULL) ? 0 : 1); |
| 118 |
} |
| 119 |
|
| 120 |
diff = ((int)(a->afterLast - a->first) - (int)(b->afterLast - b->first)); |
| 121 |
if (diff > 0) { |
| 122 |
return 1; |
| 123 |
} else if (diff < 0) { |
| 124 |
return -1; |
| 125 |
} |
| 126 |
|
| 127 |
diff = URI_STRNCMP(a->first, b->first, (a->afterLast - a->first)); |
| 128 |
|
| 129 |
if (diff > 0) { |
| 130 |
return 1; |
| 131 |
} else if (diff < 0) { |
| 132 |
return -1; |
| 133 |
} |
| 134 |
|
| 135 |
return diff; |
| 136 |
} |
| 137 |
|
| 138 |
UriBool URI_FUNC(CopyRange)(URI_TYPE(TextRange) * destRange, |
| 139 |
const URI_TYPE(TextRange) * sourceRange, |
| 140 |
UriMemoryManager * memory) { |
| 141 |
const int lenInChars = (int)(sourceRange->afterLast - sourceRange->first); |
| 142 |
const int lenInBytes = lenInChars * sizeof(URI_CHAR); |
| 143 |
URI_CHAR * dup = memory->malloc(memory, lenInBytes); |
| 144 |
if (dup == NULL) { |
| 145 |
return URI_FALSE; |
| 146 |
} |
| 147 |
memcpy(dup, sourceRange->first, lenInBytes); |
| 148 |
destRange->first = dup; |
| 149 |
destRange->afterLast = dup + lenInChars; |
| 150 |
|
| 151 |
return URI_TRUE; |
| 152 |
} |
| 153 |
|
| 154 |
UriBool URI_FUNC(CopyRangeAsNeeded)(URI_TYPE(TextRange) * destRange, |
| 155 |
const URI_TYPE(TextRange) * sourceRange, |
| 156 |
UriMemoryManager * memory) { |
| 157 |
if (sourceRange->first == NULL) { |
| 158 |
destRange->first = NULL; |
| 159 |
destRange->afterLast = NULL; |
| 160 |
} else if (sourceRange->first == sourceRange->afterLast) { |
| 161 |
destRange->first = URI_FUNC(SafeToPointTo); |
| 162 |
destRange->afterLast = URI_FUNC(SafeToPointTo); |
| 163 |
} else { |
| 164 |
return URI_FUNC(CopyRange)(destRange, sourceRange, memory); |
| 165 |
} |
| 166 |
|
| 167 |
return URI_TRUE; |
| 168 |
} |
| 169 |
|
| 170 |
UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, UriBool relative, |
| 171 |
UriBool pathOwned, UriMemoryManager * memory) { |
| 172 |
URI_TYPE(PathSegment) * walker; |
| 173 |
if ((uri == NULL) || (uri->pathHead == NULL)) { |
| 174 |
return URI_TRUE; |
| 175 |
} |
| 176 |
|
| 177 |
walker = uri->pathHead; |
| 178 |
walker->reserved = NULL; |
| 179 |
do { |
| 180 |
UriBool removeSegment = URI_FALSE; |
| 181 |
int len = (int)(walker->text.afterLast - walker->text.first); |
| 182 |
switch (len) { |
| 183 |
case 1: |
| 184 |
if ((walker->text.first)[0] == _UT('.')) { |
| 185 |
|
| 186 |
URI_TYPE(PathSegment) * const prev = walker->reserved; |
| 187 |
URI_TYPE(PathSegment) * const nextBackup = walker->next; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
removeSegment = URI_TRUE; |
| 203 |
if ((walker == uri->pathHead) && (walker->next != NULL)) { |
| 204 |
|
| 205 |
if ((walker->next->text.first == walker->next->text.afterLast) |
| 206 |
&& (URI_FUNC(HasHost)(uri) == URI_FALSE)) { |
| 207 |
removeSegment = URI_FALSE; |
| 208 |
|
| 209 |
} else if (relative) { |
| 210 |
const URI_CHAR * ch = walker->next->text.first; |
| 211 |
for (; ch < walker->next->text.afterLast; ch++) { |
| 212 |
if (*ch == _UT(':')) { |
| 213 |
removeSegment = URI_FALSE; |
| 214 |
break; |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
if (removeSegment) { |
| 221 |
|
| 222 |
|
| 223 |
if (walker->next != NULL) { |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
walker->next->reserved = prev; |
| 228 |
|
| 229 |
if (prev == NULL) { |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
uri->pathHead = walker->next; |
| 234 |
} else { |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
prev->next = walker->next; |
| 239 |
} |
| 240 |
|
| 241 |
if (pathOwned && (walker->text.first != walker->text.afterLast)) { |
| 242 |
memory->free(memory, (URI_CHAR *)walker->text.first); |
| 243 |
} |
| 244 |
memory->free(memory, walker); |
| 245 |
} else { |
| 246 |
|
| 247 |
if (pathOwned && (walker->text.first != walker->text.afterLast)) { |
| 248 |
memory->free(memory, (URI_CHAR *)walker->text.first); |
| 249 |
} |
| 250 |
|
| 251 |
if (prev == NULL) { |
| 252 |
|
| 253 |
if (URI_FUNC(HasHost)(uri)) { |
| 254 |
|
| 255 |
|
| 256 |
walker->text.first = URI_FUNC(SafeToPointTo); |
| 257 |
walker->text.afterLast = URI_FUNC(SafeToPointTo); |
| 258 |
} else { |
| 259 |
memory->free(memory, walker); |
| 260 |
|
| 261 |
uri->pathHead = NULL; |
| 262 |
uri->pathTail = NULL; |
| 263 |
} |
| 264 |
} else { |
| 265 |
|
| 266 |
|
| 267 |
walker->text.first = URI_FUNC(SafeToPointTo); |
| 268 |
walker->text.afterLast = URI_FUNC(SafeToPointTo); |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
walker = nextBackup; |
| 273 |
} |
| 274 |
} |
| 275 |
break; |
| 276 |
|
| 277 |
case 2: |
| 278 |
if (((walker->text.first)[0] == _UT('.')) |
| 279 |
&& ((walker->text.first)[1] == _UT('.'))) { |
| 280 |
|
| 281 |
URI_TYPE(PathSegment) * const prev = walker->reserved; |
| 282 |
URI_TYPE(PathSegment) * prevPrev; |
| 283 |
URI_TYPE(PathSegment) * const nextBackup = walker->next; |
| 284 |
|
| 285 |
removeSegment = URI_TRUE; |
| 286 |
if (relative) { |
| 287 |
if (prev == NULL) { |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
removeSegment = URI_FALSE; |
| 294 |
} else if ((prev != NULL) |
| 295 |
&& ((prev->text.afterLast - prev->text.first) == 2) |
| 296 |
&& ((prev->text.first)[0] == _UT('.')) |
| 297 |
&& ((prev->text.first)[1] == _UT('.'))) { |
| 298 |
|
| 299 |
|
| 300 |
removeSegment = URI_FALSE; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
if (removeSegment) { |
| 305 |
if (prev != NULL) { |
| 306 |
|
| 307 |
prevPrev = prev->reserved; |
| 308 |
if (prevPrev != NULL) { |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
prevPrev->next = walker->next; |
| 313 |
if (walker->next != NULL) { |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
walker->next->reserved = prevPrev; |
| 318 |
} else { |
| 319 |
|
| 320 |
|
| 321 |
URI_TYPE(PathSegment) * const segment = memory->calloc( |
| 322 |
memory, 1, sizeof(URI_TYPE(PathSegment))); |
| 323 |
if (segment == NULL) { |
| 324 |
if (pathOwned |
| 325 |
&& (walker->text.first |
| 326 |
!= walker->text.afterLast)) { |
| 327 |
memory->free(memory, |
| 328 |
(URI_CHAR *)walker->text.first); |
| 329 |
} |
| 330 |
memory->free(memory, walker); |
| 331 |
|
| 332 |
if (pathOwned |
| 333 |
&& (prev->text.first != prev->text.afterLast)) { |
| 334 |
memory->free(memory, |
| 335 |
(URI_CHAR *)prev->text.first); |
| 336 |
} |
| 337 |
memory->free(memory, prev); |
| 338 |
|
| 339 |
return URI_FALSE; |
| 340 |
} |
| 341 |
segment->text.first = URI_FUNC(SafeToPointTo); |
| 342 |
segment->text.afterLast = URI_FUNC(SafeToPointTo); |
| 343 |
prevPrev->next = segment; |
| 344 |
uri->pathTail = segment; |
| 345 |
} |
| 346 |
|
| 347 |
if (pathOwned |
| 348 |
&& (walker->text.first != walker->text.afterLast)) { |
| 349 |
memory->free(memory, (URI_CHAR *)walker->text.first); |
| 350 |
} |
| 351 |
memory->free(memory, walker); |
| 352 |
|
| 353 |
if (pathOwned && (prev->text.first != prev->text.afterLast)) { |
| 354 |
memory->free(memory, (URI_CHAR *)prev->text.first); |
| 355 |
} |
| 356 |
memory->free(memory, prev); |
| 357 |
|
| 358 |
walker = nextBackup; |
| 359 |
} else { |
| 360 |
|
| 361 |
if (walker->next != NULL) { |
| 362 |
uri->pathHead = walker->next; |
| 363 |
walker->next->reserved = NULL; |
| 364 |
|
| 365 |
if (pathOwned |
| 366 |
&& (walker->text.first != walker->text.afterLast)) { |
| 367 |
memory->free(memory, (URI_CHAR *)walker->text.first); |
| 368 |
} |
| 369 |
memory->free(memory, walker); |
| 370 |
} else { |
| 371 |
|
| 372 |
|
| 373 |
URI_TYPE(PathSegment) * const segment = walker; |
| 374 |
if (pathOwned |
| 375 |
&& (segment->text.first != segment->text.afterLast)) { |
| 376 |
memory->free(memory, (URI_CHAR *)segment->text.first); |
| 377 |
} |
| 378 |
segment->text.first = URI_FUNC(SafeToPointTo); |
| 379 |
segment->text.afterLast = URI_FUNC(SafeToPointTo); |
| 380 |
uri->pathHead = segment; |
| 381 |
uri->pathTail = segment; |
| 382 |
} |
| 383 |
|
| 384 |
if (pathOwned && (prev->text.first != prev->text.afterLast)) { |
| 385 |
memory->free(memory, (URI_CHAR *)prev->text.first); |
| 386 |
} |
| 387 |
memory->free(memory, prev); |
| 388 |
|
| 389 |
walker = nextBackup; |
| 390 |
} |
| 391 |
} else { |
| 392 |
URI_TYPE(PathSegment) * const anotherNextBackup = walker->next; |
| 393 |
int freeWalker = URI_TRUE; |
| 394 |
|
| 395 |
|
| 396 |
if (walker->next != NULL) { |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
uri->pathHead = walker->next; |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
walker->next->reserved = NULL; |
| 406 |
} else { |
| 407 |
if (uri->absolutePath) { |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
uri->pathHead = NULL; |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
uri->pathTail = NULL; |
| 417 |
} else { |
| 418 |
|
| 419 |
|
| 420 |
if (pathOwned |
| 421 |
&& (walker->text.first != walker->text.afterLast)) { |
| 422 |
memory->free(memory, (URI_CHAR *)walker->text.first); |
| 423 |
} |
| 424 |
walker->text.first = URI_FUNC(SafeToPointTo); |
| 425 |
walker->text.afterLast = URI_FUNC(SafeToPointTo); |
| 426 |
freeWalker = URI_FALSE; |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
if (freeWalker) { |
| 431 |
if (pathOwned |
| 432 |
&& (walker->text.first != walker->text.afterLast)) { |
| 433 |
memory->free(memory, (URI_CHAR *)walker->text.first); |
| 434 |
} |
| 435 |
memory->free(memory, walker); |
| 436 |
} |
| 437 |
|
| 438 |
walker = anotherNextBackup; |
| 439 |
} |
| 440 |
} |
| 441 |
} |
| 442 |
break; |
| 443 |
} |
| 444 |
|
| 445 |
if (!removeSegment) { |
| 446 |
|
| 447 |
if (walker->next != NULL) { |
| 448 |
walker->next->reserved = walker; |
| 449 |
} else { |
| 450 |
|
| 451 |
uri->pathTail = walker; |
| 452 |
} |
| 453 |
walker = walker->next; |
| 454 |
} |
| 455 |
} while (walker != NULL); |
| 456 |
|
| 457 |
return URI_TRUE; |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
UriBool URI_FUNC(RemoveDotSegmentsAbsolute)(URI_TYPE(Uri) * uri, |
| 462 |
UriMemoryManager * memory) { |
| 463 |
const UriBool ABSOLUTE = URI_FALSE; |
| 464 |
if (uri == NULL) { |
| 465 |
return URI_TRUE; |
| 466 |
} |
| 467 |
return URI_FUNC(RemoveDotSegmentsEx)(uri, ABSOLUTE, uri->owner, memory); |
| 468 |
} |
| 469 |
|
| 470 |
unsigned char URI_FUNC(HexdigToInt)(URI_CHAR hexdig) { |
| 471 |
switch (hexdig) { |
| 472 |
case URI_SET_DIGIT(_UT): |
| 473 |
return (unsigned char)(9 + hexdig - _UT('9')); |
| 474 |
case URI_SET_HEX_LETTER_LOWER(_UT): |
| 475 |
return (unsigned char)(15 + hexdig - _UT('f')); |
| 476 |
case URI_SET_HEX_LETTER_UPPER(_UT): |
| 477 |
return (unsigned char)(15 + hexdig - _UT('F')); |
| 478 |
|
| 479 |
default: |
| 480 |
return 0; |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
URI_CHAR URI_FUNC(HexToLetterEx)(unsigned int value, UriBool uppercase) { |
| 485 |
switch (value) { |
| 486 |
case 0: |
| 487 |
return _UT('0'); |
| 488 |
case 1: |
| 489 |
return _UT('1'); |
| 490 |
case 2: |
| 491 |
return _UT('2'); |
| 492 |
case 3: |
| 493 |
return _UT('3'); |
| 494 |
case 4: |
| 495 |
return _UT('4'); |
| 496 |
case 5: |
| 497 |
return _UT('5'); |
| 498 |
case 6: |
| 499 |
return _UT('6'); |
| 500 |
case 7: |
| 501 |
return _UT('7'); |
| 502 |
case 8: |
| 503 |
return _UT('8'); |
| 504 |
case 9: |
| 505 |
return _UT('9'); |
| 506 |
|
| 507 |
case 10: |
| 508 |
return (uppercase == URI_TRUE) ? _UT('A') : _UT('a'); |
| 509 |
case 11: |
| 510 |
return (uppercase == URI_TRUE) ? _UT('B') : _UT('b'); |
| 511 |
case 12: |
| 512 |
return (uppercase == URI_TRUE) ? _UT('C') : _UT('c'); |
| 513 |
case 13: |
| 514 |
return (uppercase == URI_TRUE) ? _UT('D') : _UT('d'); |
| 515 |
case 14: |
| 516 |
return (uppercase == URI_TRUE) ? _UT('E') : _UT('e'); |
| 517 |
default: |
| 518 |
return (uppercase == URI_TRUE) ? _UT('F') : _UT('f'); |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
UriBool URI_FUNC(HasHost)(const URI_TYPE(Uri) * uri) { |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
return (uri != NULL) |
| 530 |
&& ((uri->hostText.first != NULL) || (uri->hostData.ip4 != NULL) |
| 531 |
|| (uri->hostData.ip6 != NULL)); |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
UriBool URI_FUNC(CopyPath)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * source, |
| 536 |
UriMemoryManager * memory) { |
| 537 |
if (source->pathHead == NULL) { |
| 538 |
|
| 539 |
dest->pathHead = NULL; |
| 540 |
dest->pathTail = NULL; |
| 541 |
} else { |
| 542 |
|
| 543 |
URI_TYPE(PathSegment) * sourceWalker = source->pathHead; |
| 544 |
URI_TYPE(PathSegment) * destPrev = NULL; |
| 545 |
do { |
| 546 |
URI_TYPE(PathSegment) * cur = |
| 547 |
memory->malloc(memory, sizeof(URI_TYPE(PathSegment))); |
| 548 |
if (cur == NULL) { |
| 549 |
|
| 550 |
if (destPrev != NULL) { |
| 551 |
destPrev->next = NULL; |
| 552 |
} |
| 553 |
return URI_FALSE; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
cur->text = sourceWalker->text; |
| 559 |
if (destPrev == NULL) { |
| 560 |
|
| 561 |
dest->pathHead = cur; |
| 562 |
} else { |
| 563 |
destPrev->next = cur; |
| 564 |
} |
| 565 |
destPrev = cur; |
| 566 |
sourceWalker = sourceWalker->next; |
| 567 |
} while (sourceWalker != NULL); |
| 568 |
dest->pathTail = destPrev; |
| 569 |
dest->pathTail->next = NULL; |
| 570 |
} |
| 571 |
|
| 572 |
dest->absolutePath = source->absolutePath; |
| 573 |
return URI_TRUE; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
UriBool URI_FUNC(CopyAuthority)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * source, |
| 578 |
UriMemoryManager * memory) { |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
dest->userInfo = source->userInfo; |
| 584 |
|
| 585 |
|
| 586 |
dest->hostText = source->hostText; |
| 587 |
|
| 588 |
|
| 589 |
if (source->hostData.ip4 != NULL) { |
| 590 |
dest->hostData.ip4 = memory->malloc(memory, sizeof(UriIp4)); |
| 591 |
if (dest->hostData.ip4 == NULL) { |
| 592 |
return URI_FALSE; |
| 593 |
} |
| 594 |
*(dest->hostData.ip4) = *(source->hostData.ip4); |
| 595 |
dest->hostData.ip6 = NULL; |
| 596 |
dest->hostData.ipFuture.first = NULL; |
| 597 |
dest->hostData.ipFuture.afterLast = NULL; |
| 598 |
} else if (source->hostData.ip6 != NULL) { |
| 599 |
dest->hostData.ip4 = NULL; |
| 600 |
dest->hostData.ip6 = memory->malloc(memory, sizeof(UriIp6)); |
| 601 |
if (dest->hostData.ip6 == NULL) { |
| 602 |
return URI_FALSE; |
| 603 |
} |
| 604 |
*(dest->hostData.ip6) = *(source->hostData.ip6); |
| 605 |
dest->hostData.ipFuture.first = NULL; |
| 606 |
dest->hostData.ipFuture.afterLast = NULL; |
| 607 |
} else { |
| 608 |
dest->hostData.ip4 = NULL; |
| 609 |
dest->hostData.ip6 = NULL; |
| 610 |
dest->hostData.ipFuture = source->hostData.ipFuture; |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
dest->portText = source->portText; |
| 615 |
|
| 616 |
return URI_TRUE; |
| 617 |
} |
| 618 |
|
| 619 |
UriBool URI_FUNC(FixAmbiguity)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) { |
| 620 |
URI_TYPE(PathSegment) * segment; |
| 621 |
|
| 622 |
if ( |
| 623 |
(uri->absolutePath && (uri->pathHead != NULL) |
| 624 |
&& (uri->pathHead->text.afterLast == uri->pathHead->text.first)) |
| 625 |
|
| 626 |
|
| 627 |
|| (!uri->absolutePath && (uri->pathHead != NULL) && (uri->pathHead->next != NULL) |
| 628 |
&& (uri->pathHead->text.afterLast == uri->pathHead->text.first) |
| 629 |
&& (uri->pathHead->next->text.afterLast |
| 630 |
== uri->pathHead->next->text.first))) { |
| 631 |
|
| 632 |
} else { |
| 633 |
return URI_TRUE; |
| 634 |
} |
| 635 |
|
| 636 |
segment = memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment))); |
| 637 |
if (segment == NULL) { |
| 638 |
return URI_FALSE; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
segment->next = uri->pathHead; |
| 643 |
segment->text.first = URI_FUNC(ConstPwd); |
| 644 |
segment->text.afterLast = URI_FUNC(ConstPwd) + 1; |
| 645 |
uri->pathHead = segment; |
| 646 |
return URI_TRUE; |
| 647 |
} |
| 648 |
|
| 649 |
static UriBool URI_FUNC(PrependNewDotSegment)(URI_TYPE(Uri) * uri, |
| 650 |
UriMemoryManager * memory) { |
| 651 |
assert(uri != NULL); |
| 652 |
assert(memory != NULL); |
| 653 |
|
| 654 |
URI_TYPE(PathSegment) * const segment = |
| 655 |
memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment))); |
| 656 |
|
| 657 |
if (segment == NULL) { |
| 658 |
return URI_FALSE; |
| 659 |
} |
| 660 |
|
| 661 |
segment->next = uri->pathHead; |
| 662 |
|
| 663 |
URI_TYPE(TextRange) dotRange; |
| 664 |
dotRange.first = URI_FUNC(ConstPwd); |
| 665 |
dotRange.afterLast = URI_FUNC(ConstPwd) + 1; |
| 666 |
|
| 667 |
if (uri->owner == URI_TRUE) { |
| 668 |
if (URI_FUNC(CopyRange)(&(segment->text), &dotRange, memory) == URI_FALSE) { |
| 669 |
memory->free(memory, segment); |
| 670 |
return URI_FALSE; |
| 671 |
} |
| 672 |
} else { |
| 673 |
segment->text = dotRange; |
| 674 |
} |
| 675 |
|
| 676 |
uri->pathHead = segment; |
| 677 |
|
| 678 |
return URI_TRUE; |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
UriBool URI_FUNC(FixPathNoScheme)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) { |
| 699 |
assert(uri != NULL); |
| 700 |
assert(memory != NULL); |
| 701 |
|
| 702 |
if ((uri->absolutePath == URI_TRUE) || (uri->pathHead == NULL) |
| 703 |
|| (uri->scheme.first != NULL) || URI_FUNC(HasHost)(uri)) { |
| 704 |
return URI_TRUE; |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
UriBool colonFound = URI_FALSE; |
| 709 |
const URI_CHAR * walker = uri->pathHead->text.first; |
| 710 |
|
| 711 |
while (walker < uri->pathHead->text.afterLast) { |
| 712 |
if (walker[0] == _UT(':')) { |
| 713 |
colonFound = URI_TRUE; |
| 714 |
break; |
| 715 |
} |
| 716 |
walker++; |
| 717 |
} |
| 718 |
|
| 719 |
assert((walker == uri->pathHead->text.afterLast) || (colonFound == URI_TRUE)); |
| 720 |
|
| 721 |
if (colonFound == URI_FALSE) { |
| 722 |
return URI_TRUE; |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
return URI_FUNC(PrependNewDotSegment)(uri, memory); |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
UriBool URI_FUNC(EnsureThatPathIsNotMistakenForHost)(URI_TYPE(Uri) * uri, |
| 744 |
UriMemoryManager * memory) { |
| 745 |
assert(uri != NULL); |
| 746 |
assert(memory != NULL); |
| 747 |
|
| 748 |
if ((URI_FUNC(HasHost)(uri) == URI_TRUE) || (uri->absolutePath == URI_FALSE) |
| 749 |
|| (uri->pathHead == NULL) |
| 750 |
|| (uri->pathHead == uri->pathTail) |
| 751 |
|| (uri->pathHead->text.first != uri->pathHead->text.afterLast)) { |
| 752 |
return URI_TRUE; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
return URI_FUNC(PrependNewDotSegment)(uri, memory); |
| 757 |
} |
| 758 |
|
| 759 |
void URI_FUNC(FixEmptyTrailSegment)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) { |
| 760 |
|
| 761 |
if (!uri->absolutePath && !URI_FUNC(HasHost)(uri) && (uri->pathHead != NULL) |
| 762 |
&& (uri->pathHead->next == NULL) |
| 763 |
&& (uri->pathHead->text.first == uri->pathHead->text.afterLast)) { |
| 764 |
memory->free(memory, uri->pathHead); |
| 765 |
uri->pathHead = NULL; |
| 766 |
uri->pathTail = NULL; |
| 767 |
} |
| 768 |
} |
| 769 |
|
| 770 |
#endif |