diff options
author | Jörg Frings-Fürst <debian@jff-webhsoting.net> | 2018-11-16 07:14:58 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhsoting.net> | 2018-11-16 07:14:58 +0100 |
commit | 37162209a3da8812203022de6b81e4f05015043a (patch) | |
tree | 19d8a4b4a3e6cd31c64c608b46c6fe710f8e6eb8 /src/UriCommon.c | |
parent | 21ce7e27a89c3f9c2fb4bc8bd59877dc2d8cd6b9 (diff) |
New upstream version 0.9.0upstream/0.9.0
Diffstat (limited to 'src/UriCommon.c')
-rw-r--r-- | src/UriCommon.c | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/src/UriCommon.c b/src/UriCommon.c index 571d6d4..039beda 100644 --- a/src/UriCommon.c +++ b/src/UriCommon.c @@ -75,6 +75,9 @@ void URI_FUNC(ResetUri)(URI_TYPE(Uri) * uri) { + if (uri == NULL) { + return; + } memset(uri, 0, sizeof(URI_TYPE(Uri))); } @@ -118,17 +121,17 @@ int URI_FUNC(CompareRange)( /* Properly removes "." and ".." path segments */ UriBool URI_FUNC(RemoveDotSegments)(URI_TYPE(Uri) * uri, - UriBool relative) { + UriBool relative, UriMemoryManager * memory) { if (uri == NULL) { return URI_TRUE; } - return URI_FUNC(RemoveDotSegmentsEx)(uri, relative, uri->owner); + return URI_FUNC(RemoveDotSegmentsEx)(uri, relative, uri->owner, memory); } UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, - UriBool relative, UriBool pathOwned) { + UriBool relative, UriBool pathOwned, UriMemoryManager * memory) { URI_TYPE(PathSegment) * walker; if ((uri == NULL) || (uri->pathHead == NULL)) { return URI_TRUE; @@ -173,13 +176,13 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, } if (pathOwned && (walker->text.first != walker->text.afterLast)) { - free((URI_CHAR *)walker->text.first); + memory->free(memory, (URI_CHAR *)walker->text.first); } - free(walker); + memory->free(memory, walker); } else { /* Last segment */ if (pathOwned && (walker->text.first != walker->text.afterLast)) { - free((URI_CHAR *)walker->text.first); + memory->free(memory, (URI_CHAR *)walker->text.first); } if (prev == NULL) { @@ -189,7 +192,7 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, walker->text.first = URI_FUNC(SafeToPointTo); walker->text.afterLast = URI_FUNC(SafeToPointTo); } else { - free(walker); + memory->free(memory, walker); uri->pathHead = NULL; uri->pathTail = NULL; @@ -237,21 +240,20 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, walker->next->reserved = prevPrev; } else { /* Last segment -> insert "" segment to represent trailing slash, update tail */ - URI_TYPE(PathSegment) * const segment = malloc(1 * sizeof(URI_TYPE(PathSegment))); + URI_TYPE(PathSegment) * const segment = memory->calloc(memory, 1, sizeof(URI_TYPE(PathSegment))); if (segment == NULL) { if (pathOwned && (walker->text.first != walker->text.afterLast)) { - free((URI_CHAR *)walker->text.first); + memory->free(memory, (URI_CHAR *)walker->text.first); } - free(walker); + memory->free(memory, walker); if (pathOwned && (prev->text.first != prev->text.afterLast)) { - free((URI_CHAR *)prev->text.first); + memory->free(memory, (URI_CHAR *)prev->text.first); } - free(prev); + memory->free(memory, prev); return URI_FALSE; /* Raises malloc error */ } - memset(segment, 0, sizeof(URI_TYPE(PathSegment))); segment->text.first = URI_FUNC(SafeToPointTo); segment->text.afterLast = URI_FUNC(SafeToPointTo); prevPrev->next = segment; @@ -259,14 +261,14 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, } if (pathOwned && (walker->text.first != walker->text.afterLast)) { - free((URI_CHAR *)walker->text.first); + memory->free(memory, (URI_CHAR *)walker->text.first); } - free(walker); + memory->free(memory, walker); if (pathOwned && (prev->text.first != prev->text.afterLast)) { - free((URI_CHAR *)prev->text.first); + memory->free(memory, (URI_CHAR *)prev->text.first); } - free(prev); + memory->free(memory, prev); walker = nextBackup; } else { @@ -276,14 +278,14 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, walker->next->reserved = NULL; if (pathOwned && (walker->text.first != walker->text.afterLast)) { - free((URI_CHAR *)walker->text.first); + memory->free(memory, (URI_CHAR *)walker->text.first); } - free(walker); + memory->free(memory, walker); } else { /* Re-use segment for "" path segment to represent trailing slash, update tail */ URI_TYPE(PathSegment) * const segment = walker; if (pathOwned && (segment->text.first != segment->text.afterLast)) { - free((URI_CHAR *)segment->text.first); + memory->free(memory, (URI_CHAR *)segment->text.first); } segment->text.first = URI_FUNC(SafeToPointTo); segment->text.afterLast = URI_FUNC(SafeToPointTo); @@ -292,9 +294,9 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, } if (pathOwned && (prev->text.first != prev->text.afterLast)) { - free((URI_CHAR *)prev->text.first); + memory->free(memory, (URI_CHAR *)prev->text.first); } - free(prev); + memory->free(memory, prev); walker = nextBackup; } @@ -310,9 +312,9 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, } if (pathOwned && (walker->text.first != walker->text.afterLast)) { - free((URI_CHAR *)walker->text.first); + memory->free(memory, (URI_CHAR *)walker->text.first); } - free(walker); + memory->free(memory, walker); walker = anotherNextBackup; } @@ -339,9 +341,10 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, /* Properly removes "." and ".." path segments */ -UriBool URI_FUNC(RemoveDotSegmentsAbsolute)(URI_TYPE(Uri) * uri) { +UriBool URI_FUNC(RemoveDotSegmentsAbsolute)(URI_TYPE(Uri) * uri, + UriMemoryManager * memory) { const UriBool ABSOLUTE = URI_FALSE; - return URI_FUNC(RemoveDotSegments)(uri, ABSOLUTE); + return URI_FUNC(RemoveDotSegments)(uri, ABSOLUTE, memory); } @@ -429,7 +432,7 @@ UriBool URI_FUNC(IsHostSet)(const URI_TYPE(Uri) * uri) { /* Copies the path segment list from one URI to another. */ UriBool URI_FUNC(CopyPath)(URI_TYPE(Uri) * dest, - const URI_TYPE(Uri) * source) { + const URI_TYPE(Uri) * source, UriMemoryManager * memory) { if (source->pathHead == NULL) { /* No path component */ dest->pathHead = NULL; @@ -439,7 +442,7 @@ UriBool URI_FUNC(CopyPath)(URI_TYPE(Uri) * dest, URI_TYPE(PathSegment) * sourceWalker = source->pathHead; URI_TYPE(PathSegment) * destPrev = NULL; do { - URI_TYPE(PathSegment) * cur = malloc(sizeof(URI_TYPE(PathSegment))); + URI_TYPE(PathSegment) * cur = memory->malloc(memory, sizeof(URI_TYPE(PathSegment))); if (cur == NULL) { /* Fix broken list */ if (destPrev != NULL) { @@ -472,10 +475,10 @@ UriBool URI_FUNC(CopyPath)(URI_TYPE(Uri) * dest, /* Copies the authority part of an URI over to another. */ UriBool URI_FUNC(CopyAuthority)(URI_TYPE(Uri) * dest, - const URI_TYPE(Uri) * source) { + const URI_TYPE(Uri) * source, UriMemoryManager * memory) { /* From this functions usage we know that * * the dest URI cannot be uri->owner */ - + /* Copy userInfo */ dest->userInfo = source->userInfo; @@ -484,7 +487,7 @@ UriBool URI_FUNC(CopyAuthority)(URI_TYPE(Uri) * dest, /* Copy hostData */ if (source->hostData.ip4 != NULL) { - dest->hostData.ip4 = malloc(sizeof(UriIp4)); + dest->hostData.ip4 = memory->malloc(memory, sizeof(UriIp4)); if (dest->hostData.ip4 == NULL) { return URI_FALSE; /* Raises malloc error */ } @@ -494,7 +497,7 @@ UriBool URI_FUNC(CopyAuthority)(URI_TYPE(Uri) * dest, dest->hostData.ipFuture.afterLast = NULL; } else if (source->hostData.ip6 != NULL) { dest->hostData.ip4 = NULL; - dest->hostData.ip6 = malloc(sizeof(UriIp6)); + dest->hostData.ip6 = memory->malloc(memory, sizeof(UriIp6)); if (dest->hostData.ip6 == NULL) { return URI_FALSE; /* Raises malloc error */ } @@ -515,7 +518,8 @@ UriBool URI_FUNC(CopyAuthority)(URI_TYPE(Uri) * dest, -UriBool URI_FUNC(FixAmbiguity)(URI_TYPE(Uri) * uri) { +UriBool URI_FUNC(FixAmbiguity)(URI_TYPE(Uri) * uri, + UriMemoryManager * memory) { URI_TYPE(PathSegment) * segment; if ( /* Case 1: absolute path, empty first segment */ @@ -534,7 +538,7 @@ UriBool URI_FUNC(FixAmbiguity)(URI_TYPE(Uri) * uri) { return URI_TRUE; } - segment = malloc(1 * sizeof(URI_TYPE(PathSegment))); + segment = memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment))); if (segment == NULL) { return URI_FALSE; /* Raises malloc error */ } @@ -549,14 +553,15 @@ UriBool URI_FUNC(FixAmbiguity)(URI_TYPE(Uri) * uri) { -void URI_FUNC(FixEmptyTrailSegment)(URI_TYPE(Uri) * uri) { +void URI_FUNC(FixEmptyTrailSegment)(URI_TYPE(Uri) * uri, + UriMemoryManager * memory) { /* Fix path if only one empty segment */ if (!uri->absolutePath && !URI_FUNC(IsHostSet)(uri) && (uri->pathHead != NULL) && (uri->pathHead->next == NULL) && (uri->pathHead->text.first == uri->pathHead->text.afterLast)) { - free(uri->pathHead); + memory->free(memory, uri->pathHead); uri->pathHead = NULL; uri->pathTail = NULL; } |