--- a/libidav/utils.c Sun Oct 19 21:20:08 2025 +0200 +++ b/libidav/utils.c Mon Nov 10 21:52:51 2025 +0100 @@ -34,7 +34,6 @@ #include <ctype.h> #include <cx/string.h> #include <cx/buffer.h> -#include <cx/utils.h> #include <cx/printf.h> #include <libxml/tree.h> #include <curl/curl.h> @@ -348,10 +347,81 @@ return path; } +char* util_url_encode(DavSession *sn, const char *url) { + CURL *handle = sn ? sn->handle : NULL; +#if LIBCURL_VERSION_NUM < 0x075200 + int cleanup_handle = 0; + if(!handle) { + handle = curl_easy_init(); + cleanup_handle = 1; + } +#endif + + char *esc = curl_easy_escape(handle, url, strlen(url)); + char *ret = esc ? strdup(esc) : NULL; + curl_free(esc); + +#if LIBCURL_VERSION_NUM < 0x075200 + if(cleanup_handle) { + curl_easy_cleanup(handle); + } +#endif + + return ret; +} + char* util_url_decode(DavSession *sn, const char *url) { - char *unesc = curl_easy_unescape(sn->handle, url, strlen(url), NULL); - char *ret = strdup(unesc); + CURL *handle = sn ? sn->handle : NULL; +#if LIBCURL_VERSION_NUM < 0x075200 + int cleanup_handle = 0; + if(!handle) { + handle = curl_easy_init(); + cleanup_handle = 1; + } +#endif + + char *unesc = curl_easy_unescape(handle, url, strlen(url), NULL); + char *ret = unesc ? strdup(unesc) : NULL; curl_free(unesc); + +#if LIBCURL_VERSION_NUM < 0x075200 + if(cleanup_handle) { + curl_easy_cleanup(handle); + } +#endif + + return ret; +} + +cxmutstr util_url_encode_s(const CxAllocator *a, cxstring url) { + CURL *handle = NULL; +#if LIBCURL_VERSION_NUM < 0x075200 + handle = curl_easy_init(); +#endif + + char *esc = curl_easy_escape(handle, url.ptr, url.length); + cxmutstr ret = esc ? cx_strdup_a(a, cx_str(esc)) : (cxmutstr){NULL, 0}; + curl_free(esc); + +#if LIBCURL_VERSION_NUM < 0x075200 + curl_easy_cleanup(handle); +#endif + return ret; +} + +cxmutstr util_url_decode_s(const CxAllocator *a, cxstring url) { + CURL *handle = NULL; +#if LIBCURL_VERSION_NUM < 0x075200 + handle = curl_easy_init(); +#endif + + char *unesc = curl_easy_unescape(handle, url.ptr, url.length, NULL); + cxmutstr ret = unesc ? cx_strdup_a(a, cx_str(unesc)) : (cxmutstr){NULL, 0}; + curl_free(unesc); + +#if LIBCURL_VERSION_NUM < 0x075200 + curl_easy_cleanup(handle); +#endif return ret; }