summaryrefslogtreecommitdiff
path: root/src/UriShorten.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhsoting.net>2026-05-08 11:53:45 +0200
committerJörg Frings-Fürst <debian@jff-webhsoting.net>2026-05-08 11:53:45 +0200
commitc3dce46c5f7cad6bc3cc91cc2c711ac089f25923 (patch)
treeabaac2b003b368aa5bde30a5b898a3f51e85db43 /src/UriShorten.c
parentbc983f30186f3c204b1daea57b0057f93b74dde1 (diff)
New upstream version 1.0.1+dfsgupstream/1.0.1+dfsgupstream
Diffstat (limited to 'src/UriShorten.c')
-rw-r--r--src/UriShorten.c628
1 files changed, 365 insertions, 263 deletions
diff --git a/src/UriShorten.c b/src/UriShorten.c
index d2f8935..548b0b4 100644
--- a/src/UriShorten.c
+++ b/src/UriShorten.c
@@ -41,284 +41,386 @@
#include <uriparser/UriDefsConfig.h>
#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE))
/* Include SELF twice */
-# ifdef URI_ENABLE_ANSI
-# define URI_PASS_ANSI 1
-# include "UriShorten.c"
-# undef URI_PASS_ANSI
-# endif
-# ifdef URI_ENABLE_UNICODE
-# define URI_PASS_UNICODE 1
-# include "UriShorten.c"
-# undef URI_PASS_UNICODE
-# endif
+# ifdef URI_ENABLE_ANSI
+# define URI_PASS_ANSI 1
+# include "UriShorten.c"
+# undef URI_PASS_ANSI
+# endif
+# ifdef URI_ENABLE_UNICODE
+# define URI_PASS_UNICODE 1
+# include "UriShorten.c"
+# undef URI_PASS_UNICODE
+# endif
#else
-# ifdef URI_PASS_ANSI
-# include <uriparser/UriDefsAnsi.h>
-# else
-# include <uriparser/UriDefsUnicode.h>
-# include <wchar.h>
-# endif
-
-
-
-#ifndef URI_DOXYGEN
-# include <uriparser/Uri.h>
-# include "UriCommon.h"
-# include "UriMemory.h"
-#endif
-
-
+# ifdef URI_PASS_ANSI
+# include <uriparser/UriDefsAnsi.h>
+# else
+# include <uriparser/UriDefsUnicode.h>
+# include <wchar.h>
+# endif
+
+# 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,
- UriMemoryManager * memory) {
- /* Create segment */
- URI_TYPE(PathSegment) * segment = memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment)));
- if (segment == NULL) {
- return URI_FALSE; /* Raises malloc error */
- }
- segment->next = NULL;
- segment->text.first = first;
- segment->text.afterLast = afterLast;
-
- /* Put into chain */
- if (uri->pathTail == NULL) {
- uri->pathHead = segment;
- } else {
- uri->pathTail->next = segment;
- }
- uri->pathTail = segment;
-
- return URI_TRUE;
+ const URI_CHAR * first,
+ const URI_CHAR * afterLast,
+ UriMemoryManager * memory) {
+ /* Create segment */
+ URI_TYPE(PathSegment) * segment =
+ memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment)));
+ if (segment == NULL) {
+ return URI_FALSE; /* Raises malloc error */
+ }
+ segment->next = NULL;
+ segment->text.first = first;
+ segment->text.afterLast = afterLast;
+
+ /* Put into chain */
+ if (uri->pathTail == NULL) {
+ uri->pathHead = segment;
+ } else {
+ uri->pathTail->next = segment;
+ }
+ uri->pathTail = segment;
+
+ return URI_TRUE;
}
-
-
static URI_INLINE UriBool URI_FUNC(EqualsAuthority)(const URI_TYPE(Uri) * first,
- const URI_TYPE(Uri) * second) {
- /* IPv4 */
- if (first->hostData.ip4 != NULL) {
- return ((second->hostData.ip4 != NULL)
- && !memcmp(first->hostData.ip4->data,
- second->hostData.ip4->data, 4)) ? URI_TRUE : URI_FALSE;
- }
-
- /* IPv6 */
- if (first->hostData.ip6 != NULL) {
- return ((second->hostData.ip6 != NULL)
- && !memcmp(first->hostData.ip6->data,
- second->hostData.ip6->data, 16)) ? URI_TRUE : URI_FALSE;
- }
-
- /* IPvFuture */
- if (first->hostData.ipFuture.first != NULL) {
- return ((second->hostData.ipFuture.first != NULL)
- && !URI_FUNC(CompareRange)(&first->hostData.ipFuture,
- &second->hostData.ipFuture)) ? URI_TRUE : URI_FALSE;
- }
-
- return !URI_FUNC(CompareRange)(&first->hostText, &second->hostText)
- ? URI_TRUE : URI_FALSE;
+ const URI_TYPE(Uri) * second) {
+ /* IPv4 */
+ if (first->hostData.ip4 != NULL) {
+ return ((second->hostData.ip4 != NULL)
+ && !memcmp(first->hostData.ip4->data, second->hostData.ip4->data, 4))
+ ? URI_TRUE
+ : URI_FALSE;
+ }
+
+ /* IPv6 */
+ if (first->hostData.ip6 != NULL) {
+ return ((second->hostData.ip6 != NULL)
+ && !memcmp(first->hostData.ip6->data, second->hostData.ip6->data, 16))
+ ? URI_TRUE
+ : URI_FALSE;
+ }
+
+ /* IPvFuture */
+ if (first->hostData.ipFuture.first != NULL) {
+ return ((second->hostData.ipFuture.first != NULL)
+ && !URI_FUNC(CompareRange)(&first->hostData.ipFuture,
+ &second->hostData.ipFuture))
+ ? URI_TRUE
+ : URI_FALSE;
+ }
+
+ return !URI_FUNC(CompareRange)(&first->hostText, &second->hostText) ? URI_TRUE
+ : URI_FALSE;
}
-
-
static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
- const URI_TYPE(Uri) * absSource,
- const URI_TYPE(Uri) * absBase,
- UriBool domainRootMode, UriMemoryManager * memory) {
- if (dest == NULL) {
- return URI_ERROR_NULL;
- }
- URI_FUNC(ResetUri)(dest);
-
- if ((absSource == NULL) || (absBase == NULL)) {
- return URI_ERROR_NULL;
- }
-
- /* absBase absolute? */
- if (absBase->scheme.first == NULL) {
- return URI_ERROR_REMOVEBASE_REL_BASE;
- }
-
- /* absSource absolute? */
- if (absSource->scheme.first == NULL) {
- return URI_ERROR_REMOVEBASE_REL_SOURCE;
- }
-
- /* [01/50] if (A.scheme != Base.scheme) then */
- if (URI_FUNC(CompareRange)(&absSource->scheme, &absBase->scheme)) {
- /* [02/50] T.scheme = A.scheme; */
- dest->scheme = absSource->scheme;
- /* [03/50] T.authority = A.authority; */
- if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [04/50] T.path = A.path; */
- if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [05/50] else */
- } else {
- /* [06/50] undef(T.scheme); */
- /* NOOP */
- /* [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, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [09/50] T.path = A.path; */
- if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [10/50] else */
- } else {
- /* [11/50] if domainRootMode then */
- if (domainRootMode == URI_TRUE) {
- /* [12/50] undef(T.authority); */
- /* NOOP */
- /* [13/50] if (first(A.path) == "") then */
- /* GROUPED */
- /* [14/50] T.path = "/." + A.path; */
- /* GROUPED */
- /* [15/50] else */
- /* GROUPED */
- /* [16/50] T.path = A.path; */
- /* GROUPED */
- /* [17/50] endif; */
- if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
- return URI_ERROR_MALLOC;
- }
- dest->absolutePath = URI_TRUE;
-
- if (!URI_FUNC(FixAmbiguity)(dest, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [18/50] else */
- } else {
- const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead;
- const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead;
- /* [19/50] bool pathNaked = true; */
- UriBool pathNaked = URI_TRUE;
- /* [20/50] undef(last(Base.path)); */
- /* NOOP */
- /* [21/50] T.path = ""; */
- dest->absolutePath = URI_FALSE;
- /* [22/50] while (first(A.path) == first(Base.path)) do */
- while ((sourceSeg != NULL) && (baseSeg != NULL)
- && !URI_FUNC(CompareRange)(&sourceSeg->text, &baseSeg->text)
- && !((sourceSeg->text.first == sourceSeg->text.afterLast)
- && ((sourceSeg->next == NULL) != (baseSeg->next == NULL)))) {
- /* [23/50] A.path++; */
- sourceSeg = sourceSeg->next;
- /* [24/50] Base.path++; */
- baseSeg = baseSeg->next;
- /* [25/50] endwhile; */
- }
- /* [26/50] while defined(first(Base.path)) do */
- while ((baseSeg != NULL) && (baseSeg->next != NULL)) {
- /* [27/50] Base.path++; */
- baseSeg = baseSeg->next;
- /* [28/50] T.path += "../"; */
- if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent),
- URI_FUNC(ConstParent) + 2, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [29/50] pathNaked = false; */
- pathNaked = URI_FALSE;
- /* [30/50] endwhile; */
- }
- /* [31/50] while defined(first(A.path)) do */
- while (sourceSeg != NULL) {
- /* [32/50] if pathNaked then */
- if (pathNaked == URI_TRUE) {
- /* [33/50] if (first(A.path) contains ":") then */
- UriBool containsColon = URI_FALSE;
- const URI_CHAR * ch = sourceSeg->text.first;
- for (; ch < sourceSeg->text.afterLast; ch++) {
- if (*ch == _UT(':')) {
- containsColon = URI_TRUE;
- break;
- }
- }
-
- if (containsColon) {
- /* [34/50] T.path += "./"; */
- if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstPwd),
- 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, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [37/50] endif; */
- }
- /* [38/50] endif; */
- }
- /* [39/50] T.path += first(A.path); */
- if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first,
- sourceSeg->text.afterLast, memory)) {
- return URI_ERROR_MALLOC;
- }
- /* [40/50] pathNaked = false; */
- pathNaked = URI_FALSE;
- /* [41/50] A.path++; */
- sourceSeg = sourceSeg->next;
- /* [42/50] if defined(first(A.path)) then */
- /* NOOP */
- /* [43/50] T.path += + "/"; */
- /* NOOP */
- /* [44/50] endif; */
- /* NOOP */
- /* [45/50] endwhile; */
- }
- /* [46/50] endif; */
- }
- /* [47/50] endif; */
- }
- /* [48/50] endif; */
- }
- /* [49/50] T.query = A.query; */
- dest->query = absSource->query;
- /* [50/50] T.fragment = A.fragment; */
- dest->fragment = absSource->fragment;
-
- return URI_SUCCESS;
+ const URI_TYPE(Uri) * absSource,
+ const URI_TYPE(Uri) * absBase,
+ UriBool domainRootMode,
+ UriMemoryManager * memory) {
+ if (dest == NULL) {
+ return URI_ERROR_NULL;
+ }
+ URI_FUNC(ResetUri)(dest);
+
+ if ((absSource == NULL) || (absBase == NULL)) {
+ return URI_ERROR_NULL;
+ }
+
+ /* absBase absolute? */
+ if (absBase->scheme.first == NULL) {
+ return URI_ERROR_REMOVEBASE_REL_BASE;
+ }
+
+ /* absSource absolute? */
+ if (absSource->scheme.first == NULL) {
+ return URI_ERROR_REMOVEBASE_REL_SOURCE;
+ }
+
+ /* NOTE: The curly brackets here force deeper indent (and that's all) */
+ {
+ {
+ {
+ /* clang-format off */
+ /* [01/50] if (A.scheme != Base.scheme) then */
+ /* clang-format on */
+ if (URI_FUNC(CompareRange)(&absSource->scheme, &absBase->scheme)) {
+ /* clang-format off */
+ /* [02/50] T.scheme = A.scheme; */
+ /* clang-format on */
+ dest->scheme = absSource->scheme;
+ /* clang-format off */
+ /* [03/50] T.authority = A.authority; */
+ /* clang-format on */
+ if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [04/50] T.path = A.path; */
+ /* clang-format on */
+ if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [05/50] else */
+ /* clang-format on */
+ } else {
+ /* clang-format off */
+ /* [06/50] undef(T.scheme); */
+ /* clang-format on */
+ /* NOOP */
+ /* clang-format off */
+ /* [07/50] if (A.authority != Base.authority) then */
+ /* clang-format on */
+ if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) {
+ /* clang-format off */
+ /* [08/50] T.authority = A.authority; */
+ /* clang-format on */
+ if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [09/50] T.path = A.path; */
+ /* clang-format on */
+ if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [10/50] else */
+ /* clang-format on */
+ } else {
+ /* clang-format off */
+ /* [11/50] if domainRootMode then */
+ /* clang-format on */
+ if (domainRootMode == URI_TRUE) {
+ /* clang-format off */
+ /* [12/50] undef(T.authority); */
+ /* clang-format on */
+ /* NOOP */
+ /* clang-format off */
+ /* [13/50] if (first(A.path) == "") then */
+ /* clang-format on */
+ /* GROUPED */
+ /* clang-format off */
+ /* [14/50] T.path = "/." + A.path; */
+ /* clang-format on */
+ /* GROUPED */
+ /* clang-format off */
+ /* [15/50] else */
+ /* clang-format on */
+ /* GROUPED */
+ /* clang-format off */
+ /* [16/50] T.path = A.path; */
+ /* clang-format on */
+ /* GROUPED */
+ /* clang-format off */
+ /* [17/50] endif; */
+ /* clang-format on */
+ if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ dest->absolutePath = URI_TRUE;
+
+ if (!URI_FUNC(FixAmbiguity)(dest, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [18/50] else */
+ /* clang-format on */
+ } else {
+ const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead;
+ const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead;
+ /* clang-format off */
+ /* [19/50] bool pathNaked = true; */
+ /* clang-format on */
+ UriBool pathNaked = URI_TRUE;
+ /* clang-format off */
+ /* [20/50] undef(last(Base.path)); */
+ /* clang-format on */
+ /* NOOP */
+ /* clang-format off */
+ /* [21/50] T.path = ""; */
+ /* clang-format on */
+ dest->absolutePath = URI_FALSE;
+ /* clang-format off */
+ /* [22/50] while (first(A.path) == first(Base.path)) do */
+ /* clang-format on */
+ while (
+ (sourceSeg != NULL) && (baseSeg != NULL)
+ && !URI_FUNC(CompareRange)(&sourceSeg->text,
+ &baseSeg->text)
+ && !((sourceSeg->text.first == sourceSeg->text.afterLast)
+ && ((sourceSeg->next == NULL)
+ != (baseSeg->next == NULL)))) {
+ /* clang-format off */
+ /* [23/50] A.path++; */
+ /* clang-format on */
+ sourceSeg = sourceSeg->next;
+ /* clang-format off */
+ /* [24/50] Base.path++; */
+ /* clang-format on */
+ baseSeg = baseSeg->next;
+ /* clang-format off */
+ /* [25/50] endwhile; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [26/50] while defined(first(Base.path)) do */
+ /* clang-format on */
+ while ((baseSeg != NULL) && (baseSeg->next != NULL)) {
+ /* clang-format off */
+ /* [27/50] Base.path++; */
+ /* clang-format on */
+ baseSeg = baseSeg->next;
+ /* clang-format off */
+ /* [28/50] T.path += "../"; */
+ /* clang-format on */
+ if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent),
+ URI_FUNC(ConstParent) + 2,
+ memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [29/50] pathNaked = false; */
+ /* clang-format on */
+ pathNaked = URI_FALSE;
+ /* clang-format off */
+ /* [30/50] endwhile; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [31/50] while defined(first(A.path)) do */
+ /* clang-format on */
+ while (sourceSeg != NULL) {
+ /* clang-format off */
+ /* [32/50] if pathNaked then */
+ /* clang-format on */
+ if (pathNaked == URI_TRUE) {
+ /* clang-format off */
+ /* [33/50] if (first(A.path) contains ":") then */
+ /* clang-format on */
+ UriBool containsColon = URI_FALSE;
+ const URI_CHAR * ch = sourceSeg->text.first;
+ for (; ch < sourceSeg->text.afterLast; ch++) {
+ if (*ch == _UT(':')) {
+ containsColon = URI_TRUE;
+ break;
+ }
+ }
+
+ if (containsColon) {
+ /* clang-format off */
+ /* [34/50] T.path += "./"; */
+ /* clang-format on */
+ if (!URI_FUNC(AppendSegment)(
+ dest, URI_FUNC(ConstPwd),
+ URI_FUNC(ConstPwd) + 1, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [35/50] elseif (first(A.path) == "") then */
+ /* clang-format on */
+ } else if (sourceSeg->text.first
+ == sourceSeg->text.afterLast) {
+ /* clang-format off */
+ /* [36/50] T.path += "/."; */
+ /* clang-format on */
+ if (!URI_FUNC(AppendSegment)(
+ dest, URI_FUNC(ConstPwd),
+ URI_FUNC(ConstPwd) + 1, memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [37/50] endif; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [38/50] endif; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [39/50] T.path += first(A.path); */
+ /* clang-format on */
+ if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first,
+ sourceSeg->text.afterLast,
+ memory)) {
+ return URI_ERROR_MALLOC;
+ }
+ /* clang-format off */
+ /* [40/50] pathNaked = false; */
+ /* clang-format on */
+ pathNaked = URI_FALSE;
+ /* clang-format off */
+ /* [41/50] A.path++; */
+ /* clang-format on */
+ sourceSeg = sourceSeg->next;
+ /* clang-format off */
+ /* [42/50] if defined(first(A.path)) then */
+ /* clang-format on */
+ /* NOOP */
+ /* clang-format off */
+ /* [43/50] T.path += + "/"; */
+ /* clang-format on */
+ /* NOOP */
+ /* clang-format off */
+ /* [44/50] endif; */
+ /* clang-format on */
+ /* NOOP */
+ /* clang-format off */
+ /* [45/50] endwhile; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [46/50] endif; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [47/50] endif; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [48/50] endif; */
+ /* clang-format on */
+ }
+ /* clang-format off */
+ /* [49/50] T.query = A.query; */
+ /* clang-format on */
+ dest->query = absSource->query;
+ /* clang-format off */
+ /* [50/50] T.fragment = A.fragment; */
+ /* clang-format on */
+ dest->fragment = absSource->fragment;
+ }
+ }
+ }
+ return URI_SUCCESS;
}
-
-
-int URI_FUNC(RemoveBaseUri)(URI_TYPE(Uri) * dest,
- const URI_TYPE(Uri) * absSource,
- const URI_TYPE(Uri) * absBase,
- UriBool domainRootMode) {
- return URI_FUNC(RemoveBaseUriMm)(dest, absSource, absBase,
- domainRootMode, NULL);
+int URI_FUNC(RemoveBaseUri)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * absSource,
+ const URI_TYPE(Uri) * absBase, UriBool 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 */
-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(FreeUriMembersMm)(dest, memory);
- }
- return res;
+ res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource, absBase, domainRootMode, memory);
+ if ((res != URI_SUCCESS) && (dest != NULL)) {
+ URI_FUNC(FreeUriMembersMm)(dest, memory);
+ }
+ return res;
}
-
-
#endif