diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2019-08-27 00:48:46 +0200 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2019-08-27 16:01:46 +0200 |
commit | e7a8cd7e732f065eecc9680d48620f69f815c2cb (patch) | |
tree | 40ad6a330802e32b7680a9b1e7c94b6037907d23 | |
parent | 2323de21da163d9ae6ba50c7b1528d7245eade95 (diff) | |
download | uriparser-e7a8cd7e732f065eecc9680d48620f69f815c2cb.tar.gz |
UriNormalize.c: Implement new public uriMakeOwner*
-rw-r--r-- | include/uriparser/Uri.h | 34 | ||||
-rw-r--r-- | src/UriNormalize.c | 31 |
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 |