summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/soup
diff options
context:
space:
mode:
authorRené Mayrhofer <rene@mayrhofer.eu.org>2011-05-19 13:37:29 +0200
committerRené Mayrhofer <rene@mayrhofer.eu.org>2011-05-19 13:37:29 +0200
commit0a9d51a49042a68daa15b0c74a2b7f152f52606b (patch)
tree451888dcb17d00e52114f734e846821373fbbd44 /src/libstrongswan/plugins/soup
parent568905f488e63e28778f87ac0e38d845f45bae79 (diff)
downloadvyos-strongswan-0a9d51a49042a68daa15b0c74a2b7f152f52606b.tar.gz
vyos-strongswan-0a9d51a49042a68daa15b0c74a2b7f152f52606b.zip
Imported Upstream version 4.5.2
Diffstat (limited to 'src/libstrongswan/plugins/soup')
-rw-r--r--src/libstrongswan/plugins/soup/Makefile.in3
-rw-r--r--src/libstrongswan/plugins/soup/soup_fetcher.c55
-rw-r--r--src/libstrongswan/plugins/soup/soup_plugin.c8
3 files changed, 57 insertions, 9 deletions
diff --git a/src/libstrongswan/plugins/soup/Makefile.in b/src/libstrongswan/plugins/soup/Makefile.in
index 35d175f95..ec370d38c 100644
--- a/src/libstrongswan/plugins/soup/Makefile.in
+++ b/src/libstrongswan/plugins/soup/Makefile.in
@@ -241,6 +241,8 @@ nm_ca_dir = @nm_ca_dir@
oldincludedir = @oldincludedir@
openac_plugins = @openac_plugins@
p_plugins = @p_plugins@
+pcsclite_CFLAGS = @pcsclite_CFLAGS@
+pcsclite_LIBS = @pcsclite_LIBS@
pdfdir = @pdfdir@
piddir = @piddir@
pki_plugins = @pki_plugins@
@@ -264,6 +266,7 @@ soup_LIBS = @soup_LIBS@
srcdir = @srcdir@
strongswan_conf = @strongswan_conf@
sysconfdir = @sysconfdir@
+systemdsystemunitdir = @systemdsystemunitdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
diff --git a/src/libstrongswan/plugins/soup/soup_fetcher.c b/src/libstrongswan/plugins/soup/soup_fetcher.c
index fd97631bd..3e5786b12 100644
--- a/src/libstrongswan/plugins/soup/soup_fetcher.c
+++ b/src/libstrongswan/plugins/soup/soup_fetcher.c
@@ -58,44 +58,77 @@ struct private_soup_fetcher_t {
* HTTP request version
*/
SoupHTTPVersion version;
+
+ /**
+ * Fetcher callback function
+ */
+ fetcher_callback_t cb;
};
+/**
+ * Data to pass to soup callback
+ */
+typedef struct {
+ fetcher_callback_t cb;
+ void *user;
+ SoupSession *session;
+} cb_data_t;
+
+/**
+ * Soup callback invoking our callback
+ */
+static void soup_cb(SoupMessage *message, SoupBuffer *chunk, cb_data_t *data)
+{
+ if (!data->cb(data->user, chunk_create((u_char*)chunk->data, chunk->length)))
+ {
+ soup_session_cancel_message(data->session, message,
+ SOUP_STATUS_CANCELLED);
+ }
+}
+
METHOD(fetcher_t, fetch, status_t,
- private_soup_fetcher_t *this, char *uri, chunk_t *result)
+ private_soup_fetcher_t *this, char *uri, void *userdata)
{
- SoupSession *session;
SoupMessage *message;
status_t status = FAILED;
+ cb_data_t data = {
+ .cb = this->cb,
+ .user = userdata,
+ };
message = soup_message_new(this->method, uri);
if (!message)
{
return NOT_SUPPORTED;
}
+ if (this->cb == fetcher_default_callback)
+ {
+ *(chunk_t*)userdata = chunk_empty;
+ }
if (this->type)
{
soup_message_set_request(message, this->type, SOUP_MEMORY_STATIC,
this->data.ptr, this->data.len);
}
soup_message_set_http_version(message, this->version);
- session = soup_session_sync_new();
- g_object_set(G_OBJECT(session),
+ soup_message_body_set_accumulate(message->response_body, FALSE);
+ g_signal_connect(message, "got-chunk", G_CALLBACK(soup_cb), &data);
+ data.session = soup_session_sync_new();
+ g_object_set(G_OBJECT(data.session),
SOUP_SESSION_TIMEOUT, (guint)this->timeout, NULL);
DBG2(DBG_LIB, "sending http request to '%s'...", uri);
- soup_session_send_message(session, message);
+ soup_session_send_message(data.session, message);
if (SOUP_STATUS_IS_SUCCESSFUL(message->status_code))
{
- *result = chunk_clone(chunk_create((u_char*)message->response_body->data,
- message->response_body->length));
status = SUCCESS;
}
else
{
- DBG1(DBG_LIB, "HTTP request failed, code %d", message->status_code);
+ DBG1(DBG_LIB, "HTTP request failed: %s", message->reason_phrase);
}
g_object_unref(G_OBJECT(message));
- g_object_unref(G_OBJECT(session));
+ g_object_unref(G_OBJECT(data.session));
return status;
}
@@ -121,6 +154,9 @@ METHOD(fetcher_t, set_option, bool,
case FETCH_TIMEOUT:
this->timeout = va_arg(args, u_int);
break;
+ case FETCH_CALLBACK:
+ this->cb = va_arg(args, fetcher_callback_t);
+ break;
default:
supported = FALSE;
break;
@@ -153,6 +189,7 @@ soup_fetcher_t *soup_fetcher_create()
.method = SOUP_METHOD_GET,
.version = SOUP_HTTP_1_1,
.timeout = DEFAULT_TIMEOUT,
+ .cb = fetcher_default_callback,
);
return &this->public;
diff --git a/src/libstrongswan/plugins/soup/soup_plugin.c b/src/libstrongswan/plugins/soup/soup_plugin.c
index 970e32472..22c8762e0 100644
--- a/src/libstrongswan/plugins/soup/soup_plugin.c
+++ b/src/libstrongswan/plugins/soup/soup_plugin.c
@@ -34,6 +34,12 @@ struct private_soup_plugin_t {
soup_plugin_t public;
};
+METHOD(plugin_t, get_name, char*,
+ private_soup_plugin_t *this)
+{
+ return "soup";
+}
+
METHOD(plugin_t, destroy, void,
private_soup_plugin_t *this)
{
@@ -58,6 +64,8 @@ plugin_t *soup_plugin_create()
INIT(this,
.public = {
.plugin = {
+ .get_name = _get_name,
+ .reload = (void*)return_false,
.destroy = _destroy,
},
},