summaryrefslogtreecommitdiff
path: root/src/UriShorten.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/UriShorten.c')
-rw-r--r--src/UriShorten.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/UriShorten.c b/src/UriShorten.c
index e7f6df4..7b0bc97 100644
--- a/src/UriShorten.c
+++ b/src/UriShorten.c
@@ -64,14 +64,16 @@
#ifndef URI_DOXYGEN
# include <uriparser/Uri.h>
# include "UriCommon.h"
+# include "UriMemory.h"
#endif
static URI_INLINE UriBool URI_FUNC(AppendSegment)(URI_TYPE(Uri) * uri,
- const URI_CHAR * first, const URI_CHAR * afterLast) {
+ const URI_CHAR * first, const URI_CHAR * afterLast,
+ UriMemoryManager * memory) {
/* Create segment */
- URI_TYPE(PathSegment) * segment = malloc(1 * sizeof(URI_TYPE(PathSegment)));
+ URI_TYPE(PathSegment) * segment = memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment)));
if (segment == NULL) {
return URI_FALSE; /* Raises malloc error */
}
@@ -124,7 +126,7 @@ static URI_INLINE UriBool URI_FUNC(EqualsAuthority)(const URI_TYPE(Uri) * first,
static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
const URI_TYPE(Uri) * absSource,
const URI_TYPE(Uri) * absBase,
- UriBool domainRootMode) {
+ UriBool domainRootMode, UriMemoryManager * memory) {
if (dest == NULL) {
return URI_ERROR_NULL;
}
@@ -149,11 +151,11 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
/* [02/50] T.scheme = A.scheme; */
dest->scheme = absSource->scheme;
/* [03/50] T.authority = A.authority; */
- if (!URI_FUNC(CopyAuthority)(dest, absSource)) {
+ if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
return URI_ERROR_MALLOC;
}
/* [04/50] T.path = A.path; */
- if (!URI_FUNC(CopyPath)(dest, absSource)) {
+ if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
return URI_ERROR_MALLOC;
}
/* [05/50] else */
@@ -163,11 +165,11 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
/* [07/50] if (A.authority != Base.authority) then */
if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) {
/* [08/50] T.authority = A.authority; */
- if (!URI_FUNC(CopyAuthority)(dest, absSource)) {
+ if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
return URI_ERROR_MALLOC;
}
/* [09/50] T.path = A.path; */
- if (!URI_FUNC(CopyPath)(dest, absSource)) {
+ if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
return URI_ERROR_MALLOC;
}
/* [10/50] else */
@@ -185,12 +187,12 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
/* [16/50] T.path = A.path; */
/* GROUPED */
/* [17/50] endif; */
- if (!URI_FUNC(CopyPath)(dest, absSource)) {
+ if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
return URI_ERROR_MALLOC;
}
dest->absolutePath = URI_TRUE;
- if (!URI_FUNC(FixAmbiguity)(dest)) {
+ if (!URI_FUNC(FixAmbiguity)(dest, memory)) {
return URI_ERROR_MALLOC;
}
/* [18/50] else */
@@ -220,7 +222,7 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
baseSeg = baseSeg->next;
/* [28/50] T.path += "../"; */
if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent),
- URI_FUNC(ConstParent) + 2)) {
+ URI_FUNC(ConstParent) + 2, memory)) {
return URI_ERROR_MALLOC;
}
/* [29/50] pathNaked = false; */
@@ -244,14 +246,14 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
if (containsColon) {
/* [34/50] T.path += "./"; */
if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstPwd),
- URI_FUNC(ConstPwd) + 1)) {
+ URI_FUNC(ConstPwd) + 1, memory)) {
return URI_ERROR_MALLOC;
}
/* [35/50] elseif (first(A.path) == "") then */
} else if (sourceSeg->text.first == sourceSeg->text.afterLast) {
/* [36/50] T.path += "/."; */
if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstPwd),
- URI_FUNC(ConstPwd) + 1)) {
+ URI_FUNC(ConstPwd) + 1, memory)) {
return URI_ERROR_MALLOC;
}
/* [37/50] endif; */
@@ -260,7 +262,7 @@ static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
}
/* [39/50] T.path += first(A.path); */
if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first,
- sourceSeg->text.afterLast)) {
+ sourceSeg->text.afterLast, memory)) {
return URI_ERROR_MALLOC;
}
/* [40/50] pathNaked = false; */
@@ -295,10 +297,24 @@ int URI_FUNC(RemoveBaseUri)(URI_TYPE(Uri) * dest,
const URI_TYPE(Uri) * absSource,
const URI_TYPE(Uri) * absBase,
UriBool domainRootMode) {
- const int res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource,
- absBase, domainRootMode);
+ return URI_FUNC(RemoveBaseUriMm)(dest, absSource, absBase,
+ domainRootMode, NULL);
+}
+
+
+
+int URI_FUNC(RemoveBaseUriMm)(URI_TYPE(Uri) * dest,
+ const URI_TYPE(Uri) * absSource,
+ const URI_TYPE(Uri) * absBase,
+ UriBool domainRootMode, UriMemoryManager * memory) {
+ int res;
+
+ URI_CHECK_MEMORY_MANAGER(memory); /* may return */
+
+ res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource,
+ absBase, domainRootMode, memory);
if ((res != URI_SUCCESS) && (dest != NULL)) {
- URI_FUNC(FreeUriMembers)(dest);
+ URI_FUNC(FreeUriMembersMm)(dest, memory);
}
return res;
}