libidav/utils.c

changeset 862
e58dd7fb1a97
parent 861
879d4bf93ef4
child 886
da79af4baec8
--- a/libidav/utils.c	Sun Apr 20 13:09:03 2025 +0200
+++ b/libidav/utils.c	Sun Apr 20 13:17:14 2025 +0200
@@ -394,6 +394,38 @@
     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;
+}
+
 static size_t util_header_callback(char *buffer, size_t size,
         size_t nitems, void *data) {
     

mercurial