pluto and scepclient use the curl and ldap fetcher plugins
This commit is contained in:
@@ -42,9 +42,9 @@ struct private_curl_fetcher_t {
|
||||
CURL* curl;
|
||||
|
||||
/**
|
||||
* request type, as set with FETCH_REQUEST_TYPE
|
||||
* Optional HTTP headers
|
||||
*/
|
||||
char *request_type;
|
||||
struct curl_slist *headers;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -68,9 +68,8 @@ static size_t append(void *ptr, size_t size, size_t nmemb, chunk_t *data)
|
||||
*/
|
||||
static status_t fetch(private_curl_fetcher_t *this, char *uri, chunk_t *result)
|
||||
{
|
||||
struct curl_slist *headers = NULL;
|
||||
char error[CURL_ERROR_SIZE];
|
||||
char buf[256];;
|
||||
char buf[256];
|
||||
status_t status;
|
||||
|
||||
*result = chunk_empty;
|
||||
@@ -85,14 +84,12 @@ static status_t fetch(private_curl_fetcher_t *this, char *uri, chunk_t *result)
|
||||
curl_easy_setopt(this->curl, CURLOPT_CONNECTTIMEOUT, DEFAULT_TIMEOUT);
|
||||
curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, (void*)append);
|
||||
curl_easy_setopt(this->curl, CURLOPT_WRITEDATA, (void*)result);
|
||||
if (this->request_type)
|
||||
if (this->headers)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "Content-Type: %s", this->request_type);
|
||||
headers = curl_slist_append(headers, buf);
|
||||
curl_easy_setopt(this->curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(this->curl, CURLOPT_HTTPHEADER, this->headers);
|
||||
}
|
||||
|
||||
DBG2("sending http request to '%s'...", uri);
|
||||
DBG2(" sending http request to '%s'...", uri);
|
||||
switch (curl_easy_perform(this->curl))
|
||||
{
|
||||
case CURLE_UNSUPPORTED_PROTOCOL:
|
||||
@@ -106,7 +103,6 @@ static status_t fetch(private_curl_fetcher_t *this, char *uri, chunk_t *result)
|
||||
status = FAILED;
|
||||
break;
|
||||
}
|
||||
curl_slist_free_all(headers);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -123,13 +119,31 @@ static bool set_option(private_curl_fetcher_t *this, fetcher_option_t option, ..
|
||||
case FETCH_REQUEST_DATA:
|
||||
{
|
||||
chunk_t data = va_arg(args, chunk_t);
|
||||
|
||||
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, (char*)data.ptr);
|
||||
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDSIZE, data.len);
|
||||
return TRUE;
|
||||
}
|
||||
case FETCH_REQUEST_TYPE:
|
||||
{
|
||||
this->request_type = va_arg(args, char*);
|
||||
char header[BUF_LEN];
|
||||
char *request_type = va_arg(args, char*);
|
||||
|
||||
snprintf(header, BUF_LEN, "Content-Type: %s", request_type);
|
||||
this->headers = curl_slist_append(this->headers, header);
|
||||
return TRUE;
|
||||
}
|
||||
case FETCH_REQUEST_HEADER:
|
||||
{
|
||||
char *header = va_arg(args, char*);
|
||||
|
||||
this->headers = curl_slist_append(this->headers, header);
|
||||
return TRUE;
|
||||
}
|
||||
case FETCH_HTTP_VERSION_1_0:
|
||||
{
|
||||
curl_easy_setopt(this->curl, CURLOPT_HTTP_VERSION,
|
||||
CURL_HTTP_VERSION_1_0);
|
||||
return TRUE;
|
||||
}
|
||||
case FETCH_TIMEOUT:
|
||||
@@ -148,6 +162,7 @@ static bool set_option(private_curl_fetcher_t *this, fetcher_option_t option, ..
|
||||
*/
|
||||
static void destroy(private_curl_fetcher_t *this)
|
||||
{
|
||||
curl_slist_free_all(this->headers);
|
||||
curl_easy_cleanup(this->curl);
|
||||
free(this);
|
||||
}
|
||||
@@ -165,7 +180,7 @@ curl_fetcher_t *curl_fetcher_create()
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->request_type = NULL;
|
||||
this->headers = NULL;
|
||||
|
||||
this->public.interface.fetch = (status_t(*)(fetcher_t*,char*,chunk_t*))fetch;
|
||||
this->public.interface.set_option = (bool(*)(fetcher_t*, fetcher_option_t option, ...))set_option;
|
||||
|
||||
Reference in New Issue
Block a user