METHOD(fetcher_t, fetch, status_t,
private_curl_fetcher_t *this, char *uri, void *userdata)
{
- char error[CURL_ERROR_SIZE];
+ char error[CURL_ERROR_SIZE], *enc_uri;
status_t status;
cb_data_t data = {
.cb = this->cb,
*(chunk_t*)userdata = chunk_empty;
}
- if (curl_easy_setopt(this->curl, CURLOPT_URL, uri) != CURLE_OK)
+ /* the URI has to be URL-encoded, we only replace spaces as replacing other
+ * characters (e.g. '/' or ':') would render the URI invalid */
+ enc_uri = strreplace(uri, " ", "%20");
+
+ if (curl_easy_setopt(this->curl, CURLOPT_URL, enc_uri) != CURLE_OK)
{ /* URL type not supported by curl */
- return NOT_SUPPORTED;
+ status = NOT_SUPPORTED;
+ goto out;
}
curl_easy_setopt(this->curl, CURLOPT_ERRORBUFFER, error);
curl_easy_setopt(this->curl, CURLOPT_FAILONERROR, TRUE);
status = FAILED;
break;
}
+
+out:
+ if (enc_uri != uri)
+ {
+ free(enc_uri);
+ }
return status;
}