libidav/utils.c

changeset 862
e58dd7fb1a97
parent 861
879d4bf93ef4
child 886
da79af4baec8
equal deleted inserted replaced
861:879d4bf93ef4 862:e58dd7fb1a97
389 if(cleanup_handle) { 389 if(cleanup_handle) {
390 curl_easy_cleanup(handle); 390 curl_easy_cleanup(handle);
391 } 391 }
392 #endif 392 #endif
393 393
394 return ret;
395 }
396
397 cxmutstr util_url_encode_s(const CxAllocator *a, cxstring url) {
398 CURL *handle = NULL;
399 #if LIBCURL_VERSION_NUM < 0x075200
400 handle = curl_easy_init();
401 #endif
402
403 char *esc = curl_easy_escape(handle, url.ptr, url.length);
404 cxmutstr ret = esc ? cx_strdup_a(a, cx_str(esc)) : (cxmutstr){NULL, 0};
405 curl_free(esc);
406
407 #if LIBCURL_VERSION_NUM < 0x075200
408 curl_easy_cleanup(handle);
409 #endif
410 return ret;
411 }
412
413 cxmutstr util_url_decode_s(const CxAllocator *a, cxstring url) {
414 CURL *handle = NULL;
415 #if LIBCURL_VERSION_NUM < 0x075200
416 handle = curl_easy_init();
417 #endif
418
419 char *unesc = curl_easy_unescape(handle, url.ptr, url.length, NULL);
420 cxmutstr ret = unesc ? cx_strdup_a(a, cx_str(unesc)) : (cxmutstr){NULL, 0};
421 curl_free(unesc);
422
423 #if LIBCURL_VERSION_NUM < 0x075200
424 curl_easy_cleanup(handle);
425 #endif
394 return ret; 426 return ret;
395 } 427 }
396 428
397 static size_t util_header_callback(char *buffer, size_t size, 429 static size_t util_header_callback(char *buffer, size_t size,
398 size_t nitems, void *data) { 430 size_t nitems, void *data) {

mercurial