[libgovirt] OvirtProxy: Add additional-header API
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgovirt] OvirtProxy: Add additional-header API
- Date: Thu, 12 Mar 2015 13:03:33 +0000 (UTC)
commit 674e2583e7fec1613bd2541456a18be635d1260b
Author: Christophe Fergeau <cfergeau redhat com>
Date: Fri Feb 6 16:56:23 2015 +0100
OvirtProxy: Add additional-header API
This will be used to inject headers needed by oVirt for foreign menu
support.
govirt/govirt.sym | 5 +++
govirt/ovirt-proxy-private.h | 1 +
govirt/ovirt-proxy.c | 72 ++++++++++++++++++++++++++++++++++++++++++
govirt/ovirt-proxy.h | 3 ++
4 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/govirt/govirt.sym b/govirt/govirt.sym
index 178ab07..bbe9d53 100644
--- a/govirt/govirt.sym
+++ b/govirt/govirt.sym
@@ -107,4 +107,9 @@ GOVIRT_0.3.2 {
ovirt_resource_delete_finish;
} GOVIRT_0.3.1;
+GOVIRT_0.3.3 {
+ ovirt_proxy_add_header;
+ ovirt_proxy_add_headers;
+ ovirt_proxy_add_headers_from_valist;
+} GOVIRT_0.3.2;
# .... define new API here using predicted next version number ....
diff --git a/govirt/ovirt-proxy-private.h b/govirt/ovirt-proxy-private.h
index b9cc153..18ef6e9 100644
--- a/govirt/ovirt-proxy-private.h
+++ b/govirt/ovirt-proxy-private.h
@@ -38,6 +38,7 @@ struct _OvirtProxyPrivate {
OvirtApi *api;
char *jsessionid;
SoupCookieJar *cookie_jar;
+ GHashTable *additional_headers;
gulong ssl_ca_file_changed_id;
};
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index f1b88cb..85b2038 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -766,6 +766,9 @@ ovirt_proxy_dispose(GObject *obj)
proxy->priv->cookie_jar = NULL;
}
+ g_warn_if_fail(proxy->priv->additional_headers != NULL);
+ g_hash_table_unref(proxy->priv->additional_headers);
+
G_OBJECT_CLASS(ovirt_proxy_parent_class)->dispose(obj);
}
@@ -839,6 +842,10 @@ ovirt_proxy_init(OvirtProxy *self)
self->priv->cookie_jar = soup_cookie_jar_new();
rest_proxy_add_soup_feature(REST_PROXY(self),
SOUP_SESSION_FEATURE(self->priv->cookie_jar));
+ self->priv->additional_headers = g_hash_table_new_full(g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
}
/* FIXME : "uri" should just be a base domain, foo.example.com/some/path
@@ -898,6 +905,71 @@ OvirtProxy *ovirt_proxy_new(const char *hostname)
}
+/**
+ * ovirt_proxy_add_header:
+ * @proxy: a #OvirtProxy
+ * @header: name of the header to add to each request
+ * @value: value of the header to add to each request
+ *
+ * Add a http header called @header with the value @value to each oVirt REST
+ * API call. If a header with this name already exists, the new value will
+ * replace the old.
+ */
+void ovirt_proxy_add_header(OvirtProxy *proxy, const char *header, const char *value)
+{
+ g_return_if_fail(OVIRT_IS_PROXY(proxy));
+
+ g_hash_table_replace(proxy->priv->additional_headers,
+ (char *)g_strdup(header),
+ (char *)g_strdup(value));
+}
+
+
+/**
+ * ovirt_proxy_add_headers:
+ * @proxy: a #OvirtProxy
+ * @...: header name and value pairs, followed by %NULL
+ *
+ * Add the specified http header and value pairs to @proxy. These headers will
+ * be sent with each oVirt REST API call. If a header already exists, the new
+ * value will replace the old.
+ */
+void ovirt_proxy_add_headers(OvirtProxy *proxy, ...)
+{
+ va_list headers;
+
+ g_return_if_fail(OVIRT_IS_PROXY(proxy));
+
+ va_start(headers, proxy);
+ ovirt_proxy_add_headers_from_valist(proxy, headers);
+ va_end(headers);
+}
+
+
+/**
+ * ovirt_proxy_add_headers_from_valist:
+ * @proxy: a #OvirtProxy
+ * @headers: header name and value pairs
+ *
+ * Add the specified http header and value pairs to @proxy. These headers will
+ * be sent with each oVirt REST API call. If a header already exists, the new
+ * value will replace the old.
+ */
+void ovirt_proxy_add_headers_from_valist(OvirtProxy *proxy, va_list headers)
+{
+ const char *header = NULL;
+ const char *value;
+
+ g_return_if_fail(OVIRT_IS_PROXY(proxy));
+
+ header = va_arg(headers, const char *);
+ while (header != NULL) {
+ value = va_arg(headers, const char *);
+ ovirt_proxy_add_header(proxy, header, value);
+ header = va_arg(headers, const char *);
+ }
+}
+
static void ovirt_proxy_set_api_from_xml(OvirtProxy *proxy,
RestXmlNode *node,
GError **error)
diff --git a/govirt/ovirt-proxy.h b/govirt/ovirt-proxy.h
index d011209..71fa4e0 100644
--- a/govirt/ovirt-proxy.h
+++ b/govirt/ovirt-proxy.h
@@ -66,6 +66,9 @@ struct _OvirtProxyClass {
GType ovirt_proxy_get_type(void);
OvirtProxy *ovirt_proxy_new(const char *host);
+void ovirt_proxy_add_header(OvirtProxy *proxy, const char *header, const char *value);
+void ovirt_proxy_add_headers(OvirtProxy *proxy, ...);
+void ovirt_proxy_add_headers_from_valist(OvirtProxy *proxy, va_list headers);
G_DEPRECATED_FOR(ovirt_collection_lookup_resource)
OvirtVm *ovirt_proxy_lookup_vm(OvirtProxy *proxy, const char *vm_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]