summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/UriCommon.c23
-rw-r--r--src/UriCommon.h4
-rw-r--r--src/UriCompare.c27
-rw-r--r--src/UriResolve.c31
4 files changed, 55 insertions, 30 deletions
diff --git a/src/UriCommon.c b/src/UriCommon.c
index c33a4ca..c50d89b 100644
--- a/src/UriCommon.c
+++ b/src/UriCommon.c
@@ -80,6 +80,29 @@ void URI_FUNC(ResetUri)(URI_TYPE(Uri) * uri) {
+/* Compares two text ranges for equal text content */
+int URI_FUNC(CompareRange)(
+ const URI_TYPE(TextRange) * a,
+ const URI_TYPE(TextRange) * b) {
+ int diff;
+
+ /* NOTE: Both NULL means equal! */
+ if ((a == NULL) || (b == NULL)) {
+ return ((a == NULL) ? 0 : 1) - ((b == NULL) ? 0 : 1);
+ }
+
+ diff = ((int)(a->afterLast - a->first) - (int)(b->afterLast - b->first));
+ if (diff > 0) {
+ return 1;
+ } else if (diff < 0) {
+ return -1;
+ }
+
+ return URI_STRNCMP(a->first, b->first, (a->afterLast - a->first));
+}
+
+
+
/* Properly removes "." and ".." path segments */
UriBool URI_FUNC(RemoveDotSegments)(URI_TYPE(Uri) * uri,
UriBool relative) {
diff --git a/src/UriCommon.h b/src/UriCommon.h
index 85266bf..f6bc2cc 100644
--- a/src/UriCommon.h
+++ b/src/UriCommon.h
@@ -78,6 +78,10 @@ extern const URI_CHAR * const URI_FUNC(ConstParent);
void URI_FUNC(ResetUri)(URI_TYPE(Uri) * uri);
+int URI_FUNC(CompareRange)(
+ const URI_TYPE(TextRange) * a,
+ const URI_TYPE(TextRange) * b);
+
UriBool URI_FUNC(RemoveDotSegmentsAbsolute)(URI_TYPE(Uri) * uri);
UriBool URI_FUNC(RemoveDotSegments)(URI_TYPE(Uri) * uri, UriBool relative);
UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri,
diff --git a/src/UriCompare.c b/src/UriCompare.c
index 81c53ca..6896f64 100644
--- a/src/UriCompare.c
+++ b/src/UriCompare.c
@@ -69,33 +69,6 @@
-static int URI_FUNC(CompareRange)(const URI_TYPE(TextRange) * a,
- const URI_TYPE(TextRange) * b);
-
-
-
-/* Compares two text ranges for equal text content */
-static URI_INLINE int URI_FUNC(CompareRange)(const URI_TYPE(TextRange) * a,
- const URI_TYPE(TextRange) * b) {
- int diff;
-
- /* NOTE: Both NULL means equal! */
- if ((a == NULL) || (b == NULL)) {
- return ((a == NULL) && (b == NULL)) ? URI_TRUE : URI_FALSE;
- }
-
- diff = ((int)(a->afterLast - a->first) - (int)(b->afterLast - b->first));
- if (diff > 0) {
- return 1;
- } else if (diff < 0) {
- return -1;
- }
-
- return URI_STRNCMP(a->first, b->first, (a->afterLast - a->first));
-}
-
-
-
UriBool URI_FUNC(EqualsUri)(const URI_TYPE(Uri) * a,
const URI_TYPE(Uri) * b) {
/* NOTE: Both NULL means equal! */
diff --git a/src/UriResolve.c b/src/UriResolve.c
index 2873060..4af5b19 100644
--- a/src/UriResolve.c
+++ b/src/UriResolve.c
@@ -150,7 +150,8 @@ static int URI_FUNC(ResolveAbsolutePathFlag)(URI_TYPE(Uri) * absWork) {
static int URI_FUNC(AddBaseUriImpl)(URI_TYPE(Uri) * absDest,
const URI_TYPE(Uri) * relSource,
- const URI_TYPE(Uri) * absBase) {
+ const URI_TYPE(Uri) * absBase,
+ UriResolutionOptions options) {
if (absDest == NULL) {
return URI_ERROR_NULL;
}
@@ -165,8 +166,20 @@ static int URI_FUNC(AddBaseUriImpl)(URI_TYPE(Uri) * absDest,
return URI_ERROR_ADDBASE_REL_BASE;
}
+ /* [00/32] -- A non-strict parser may ignore a scheme in the reference */
+ /* [00/32] -- if it is identical to the base URI's scheme. */
+ /* [00/32] if ((not strict) and (R.scheme == Base.scheme)) then */
+ UriBool relSourceHasScheme = (relSource->scheme.first != NULL) ? URI_TRUE : URI_FALSE;
+ if ((options & URI_RESOLVE_IDENTICAL_SCHEME_COMPAT)
+ && (absBase->scheme.first != NULL)
+ && (0 == URI_FUNC(CompareRange)(&(absBase->scheme), &(relSource->scheme)))) {
+ /* [00/32] undefine(R.scheme); */
+ relSourceHasScheme = URI_FALSE;
+ /* [00/32] endif; */
+ }
+
/* [01/32] if defined(R.scheme) then */
- if (relSource->scheme.first != NULL) {
+ if (relSourceHasScheme) {
/* [02/32] T.scheme = R.scheme; */
absDest->scheme = relSource->scheme;
/* [03/32] T.authority = R.authority; */
@@ -278,7 +291,19 @@ static int URI_FUNC(AddBaseUriImpl)(URI_TYPE(Uri) * absDest,
int URI_FUNC(AddBaseUri)(URI_TYPE(Uri) * absDest,
const URI_TYPE(Uri) * relSource, const URI_TYPE(Uri) * absBase) {
- const int res = URI_FUNC(AddBaseUriImpl)(absDest, relSource, absBase);
+ const int res = URI_FUNC(AddBaseUriImpl)(absDest, relSource, absBase, URI_RESOLVE_STRICTLY);
+ if ((res != URI_SUCCESS) && (absDest != NULL)) {
+ URI_FUNC(FreeUriMembers)(absDest);
+ }
+ return res;
+}
+
+
+
+int URI_FUNC(AddBaseUriEx)(URI_TYPE(Uri) * absDest,
+ const URI_TYPE(Uri) * relSource, const URI_TYPE(Uri) * absBase,
+ UriResolutionOptions options) {
+ const int res = URI_FUNC(AddBaseUriImpl)(absDest, relSource, absBase, options);
if ((res != URI_SUCCESS) && (absDest != NULL)) {
URI_FUNC(FreeUriMembers)(absDest);
}