aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2007-04-03 19:46:50 +0000
committerAndreas Steffen <andreas.steffen@strongswan.org>2007-04-03 19:46:50 +0000
commitf166af2c0a6503a1304e79d8c169ade35e9ebfb6 (patch)
tree8324e878f966662fd9272e3065e4c8085c97c015
parent3b4f7d922afdfe18a2d9a2c70ebe7073981b7224 (diff)
downloadstrongswan-f166af2c0a6503a1304e79d8c169ade35e9ebfb6.tar.bz2
strongswan-f166af2c0a6503a1304e79d8c169ade35e9ebfb6.tar.xz
implemented http get method
-rw-r--r--src/libstrongswan/utils/fetcher.c41
-rw-r--r--src/libstrongswan/utils/fetcher.h2
2 files changed, 39 insertions, 4 deletions
diff --git a/src/libstrongswan/utils/fetcher.c b/src/libstrongswan/utils/fetcher.c
index f43a9fa28..cf83adbdc 100644
--- a/src/libstrongswan/utils/fetcher.c
+++ b/src/libstrongswan/utils/fetcher.c
@@ -74,9 +74,44 @@ size_t curl_write_buffer(void *ptr, size_t size, size_t nmemb, void *data)
/**
* Implements fetcher_t.get
*/
-static chunk_t get(private_fetcher_t *this, const char *uri)
+static chunk_t get(private_fetcher_t *this)
{
- return chunk_empty;
+ chunk_t response = chunk_empty;
+
+#ifdef LIBCURL
+ if (this->curl)
+ {
+ CURLcode res;
+ chunk_t curl_response = chunk_empty;
+ char curl_error_buffer[CURL_ERROR_SIZE];
+
+ curl_easy_setopt(this->curl, CURLOPT_URL, this->uri);
+ curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, curl_write_buffer);
+ curl_easy_setopt(this->curl, CURLOPT_WRITEDATA, (void *)&curl_response);
+ curl_easy_setopt(this->curl, CURLOPT_ERRORBUFFER, &curl_error_buffer);
+ curl_easy_setopt(this->curl, CURLOPT_FAILONERROR, TRUE);
+ curl_easy_setopt(this->curl, CURLOPT_CONNECTTIMEOUT, FETCHER_TIMEOUT);
+ curl_easy_setopt(this->curl, CURLOPT_NOSIGNAL, TRUE);
+
+ DBG1("sending http get request to '%s'...", this->uri);
+ res = curl_easy_perform(this->curl);
+
+ if (res == CURLE_OK)
+ {
+ DBG1("received valid http response");
+ response = chunk_clone(curl_response);
+ }
+ else
+ {
+ DBG1("http get request to '%s' using libcurl failed: %s",
+ this->uri, curl_error_buffer);
+ }
+ curl_free(curl_response.ptr);
+ }
+#else
+ DBG1("warning: libcurl fetching not compiled in");
+#endif /* LIBCURL */
+ return response;
}
/**
@@ -162,7 +197,7 @@ fetcher_t *fetcher_create(const char *uri)
#endif /* LIBCURL */
/* public functions */
- this->public.get = (chunk_t (*) (fetcher_t*,const char*))get;
+ this->public.get = (chunk_t (*) (fetcher_t*))get;
this->public.post = (chunk_t (*) (fetcher_t*,const char*,chunk_t))post;
this->public.destroy = (void (*) (fetcher_t*))destroy;
diff --git a/src/libstrongswan/utils/fetcher.h b/src/libstrongswan/utils/fetcher.h
index ea7dd22b8..47b43a0b7 100644
--- a/src/libstrongswan/utils/fetcher.h
+++ b/src/libstrongswan/utils/fetcher.h
@@ -43,7 +43,7 @@ struct fetcher_t {
* @param uri uri specifying the information source
* @return chunk_t containing the information
*/
- chunk_t (*get) (fetcher_t *this, const char *uri);
+ chunk_t (*get) (fetcher_t *this);
/**
* @brief Get information via a get request.