libidav/utils.c

changeset 861
879d4bf93ef4
parent 857
03982275f29b
child 862
e58dd7fb1a97
equal deleted inserted replaced
860:f6a274beeb95 861:879d4bf93ef4
346 } 346 }
347 } 347 }
348 return path; 348 return path;
349 } 349 }
350 350
351 char* util_url_encode(DavSession *sn, const char *url) {
352 CURL *handle = sn ? sn->handle : NULL;
353 #if LIBCURL_VERSION_NUM < 0x075200
354 int cleanup_handle = 0;
355 if(!handle) {
356 handle = curl_easy_init();
357 cleanup_handle = 1;
358 }
359 #endif
360
361 char *esc = curl_easy_escape(handle, url, strlen(url));
362 char *ret = esc ? strdup(esc) : NULL;
363 curl_free(esc);
364
365 #if LIBCURL_VERSION_NUM < 0x075200
366 if(cleanup_handle) {
367 curl_easy_cleanup(handle);
368 }
369 #endif
370
371 return ret;
372 }
373
351 char* util_url_decode(DavSession *sn, const char *url) { 374 char* util_url_decode(DavSession *sn, const char *url) {
352 char *unesc = curl_easy_unescape(sn->handle, url, strlen(url), NULL); 375 CURL *handle = sn ? sn->handle : NULL;
353 char *ret = strdup(unesc); 376 #if LIBCURL_VERSION_NUM < 0x075200
377 int cleanup_handle = 0;
378 if(!handle) {
379 handle = curl_easy_init();
380 cleanup_handle = 1;
381 }
382 #endif
383
384 char *unesc = curl_easy_unescape(handle, url, strlen(url), NULL);
385 char *ret = unesc ? strdup(unesc) : NULL;
354 curl_free(unesc); 386 curl_free(unesc);
387
388 #if LIBCURL_VERSION_NUM < 0x075200
389 if(cleanup_handle) {
390 curl_easy_cleanup(handle);
391 }
392 #endif
393
355 return ret; 394 return ret;
356 } 395 }
357 396
358 static size_t util_header_callback(char *buffer, size_t size, 397 static size_t util_header_callback(char *buffer, size_t size,
359 size_t nitems, void *data) { 398 size_t nitems, void *data) {

mercurial