pluto and scepclient use the curl and ldap fetcher plugins

This commit is contained in:
Andreas Steffen
2009-04-29 08:09:35 +00:00
parent 82f0707fa3
commit e67197a7f9
11 changed files with 246 additions and 622 deletions
+12
View File
@@ -45,6 +45,18 @@ enum fetcher_option_t {
*/
FETCH_REQUEST_TYPE,
/**
* HTTP header to be sent with with the fetch request.
* Additional argument is a char*.
*/
FETCH_REQUEST_HEADER,
/**
* Use HTTP Version 1.0 instead of 1.1.
* No additional argument is needed.
*/
FETCH_HTTP_VERSION_1_0,
/**
* Timeout to use for fetch, in seconds.
* Additional argument is u_int
@@ -101,8 +101,12 @@ static status_t fetch(private_fetcher_manager_t *this,
good = fetcher->set_option(fetcher, opt, va_arg(args, chunk_t));
continue;
case FETCH_REQUEST_TYPE:
case FETCH_REQUEST_HEADER:
good = fetcher->set_option(fetcher, opt, va_arg(args, char*));
continue;
case FETCH_HTTP_VERSION_1_0:
good = fetcher->set_option(fetcher, opt);
continue;
case FETCH_TIMEOUT:
good = fetcher->set_option(fetcher, opt, va_arg(args, u_int));
continue;
+27 -12
View File
@@ -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;