summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2019-08-27 00:48:46 +0200
committerSebastian Pipping <sebastian@pipping.org>2019-08-27 16:01:46 +0200
commite7a8cd7e732f065eecc9680d48620f69f815c2cb (patch)
tree40ad6a330802e32b7680a9b1e7c94b6037907d23
parent2323de21da163d9ae6ba50c7b1528d7245eade95 (diff)
downloaduriparser-e7a8cd7e732f065eecc9680d48620f69f815c2cb.tar.gz
UriNormalize.c: Implement new public uriMakeOwner*
-rw-r--r--include/uriparser/Uri.h34
-rw-r--r--src/UriNormalize.c31
2 files changed, 65 insertions, 0 deletions
diff --git a/include/uriparser/Uri.h b/include/uriparser/Uri.h
index 9315a12..8f86f41 100644
--- a/include/uriparser/Uri.h
+++ b/include/uriparser/Uri.h
@@ -1080,6 +1080,40 @@ URI_PUBLIC int URI_FUNC(FreeQueryListMm)(URI_TYPE(QueryList) * queryList,
+/**
+ * Makes the %URI hold copies of strings so that it no longer depends
+ * on the original %URI string. If the %URI is already owner of copies,
+ * this function returns <c>URI_TRUE</c> and does not modify the %URI further.
+ *
+ * Uses default libc-based memory manager.
+ *
+ * @param uri <b>INOUT</b>: %URI to make independent
+ * @return Error code or 0 on success
+ *
+ * @see uriMakeOwnerMmA
+ * @since 0.9.4
+ */
+URI_PUBLIC int URI_FUNC(MakeOwner)(URI_TYPE(Uri) * uri);
+
+
+
+/**
+ * Makes the %URI hold copies of strings so that it no longer depends
+ * on the original %URI string. If the %URI is already owner of copies,
+ * this function returns <c>URI_TRUE</c> and does not modify the %URI further.
+ *
+ * @param uri <b>INOUT</b>: %URI to make independent
+ * @param memory <b>IN</b>: Memory manager to use, NULL for default libc
+ * @return Error code or 0 on success
+ *
+ * @see uriMakeOwnerA
+ * @since 0.9.4
+ */
+URI_PUBLIC int URI_FUNC(MakeOwnerMm)(URI_TYPE(Uri) * uri,
+ UriMemoryManager * memory);
+
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/UriNormalize.c b/src/UriNormalize.c
index efe53af..01f2f9d 100644
--- a/src/UriNormalize.c
+++ b/src/UriNormalize.c
@@ -768,4 +768,35 @@ static URI_INLINE int URI_FUNC(NormalizeSyntaxEngine)(URI_TYPE(Uri) * uri,
+int URI_FUNC(MakeOwnerMm)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) {
+ unsigned int doneMask = URI_NORMALIZED;
+
+ URI_CHECK_MEMORY_MANAGER(memory); /* may return */
+
+ if (uri == NULL) {
+ return URI_ERROR_NULL;
+ }
+
+ if (uri->owner == URI_TRUE) {
+ return URI_SUCCESS;
+ }
+
+ if (! URI_FUNC(MakeOwnerEngine)(uri, &doneMask, memory)) {
+ URI_FUNC(PreventLeakage)(uri, doneMask, memory);
+ return URI_ERROR_MALLOC;
+ }
+
+ uri->owner = URI_TRUE;
+
+ return URI_SUCCESS;
+}
+
+
+
+int URI_FUNC(MakeOwner)(URI_TYPE(Uri) * uri) {
+ return URI_FUNC(MakeOwnerMm)(uri, NULL);
+}
+
+
+
#endif