#include <string.h>
#include <stdlib.h>
#include "glib.h"
+#include <curl/curl.h>
#include "download-agent-debug.h"
#include "download-agent-encoding.h"
void decode_url_encoded_str(const char *in_encoded_str, char **out_str)
{
- char *in = NULL;
- char *out = NULL;
- *out_str = calloc(1, strlen(in_encoded_str) + 1);
- if (*out_str == NULL)
+ CURL* curl = curl_easy_init();
+
+ *out_str = curl_easy_unescape(curl, in_encoded_str, strlen(in_encoded_str), NULL);
+
+ if(!*out_str){
+ DA_LOGE("CURLE_OUT_OF_MEMORY");
return;
- out = *out_str;
- in = (char *)in_encoded_str;
- while (*in)
- {
- if (*in == '%') {
- int hex = 0;
- in++;
- if (sscanf(in, "%2x", &hex) <= 0) {
- return;
- } else {
- *out = hex;
- in++;
- }
- } else if (*in == '+') {
- *out = ' ';
- } else {
- *out = *in;
- }
- in++;
- out++;
}
+
+ curl_easy_cleanup(curl);
}