[libgovirt] Add OvirtProxy::jsessionid property



commit 73f82d9761c6e2acf70caf939a8b7a5495ddae59
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Wed Dec 11 16:02:53 2013 +0100

    Add OvirtProxy::jsessionid property
    
    This will be useful to get persistent authentication to an oVirt session

 govirt/ovirt-proxy-private.h |    1 +
 govirt/ovirt-proxy.c         |   36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/govirt/ovirt-proxy-private.h b/govirt/ovirt-proxy-private.h
index 0623552..647d235 100644
--- a/govirt/ovirt-proxy-private.h
+++ b/govirt/ovirt-proxy-private.h
@@ -36,6 +36,7 @@ struct _OvirtProxyPrivate {
     char *tmp_ca_file;
     gboolean admin_mode;
     OvirtApi *api;
+    char *jsessionid;
     SoupCookieJar *cookie_jar;
 
     gulong ssl_ca_file_changed_id;
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index ccbee67..babb5ce 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -34,7 +34,7 @@
 #include <errno.h>
 #include <string.h>
 #include <glib/gstdio.h>
-
+#include <libsoup/soup-cookie.h>
 #include <rest/rest-xml-node.h>
 #include <rest/rest-xml-parser.h>
 
@@ -46,6 +46,7 @@ enum {
     PROP_0,
     PROP_CA_CERT,
     PROP_ADMIN,
+    PROP_SESSION_ID
 };
 
 #define CA_CERT_FILENAME "ca.crt"
@@ -689,12 +690,32 @@ static void ovirt_proxy_get_property(GObject *object,
     case PROP_ADMIN:
         g_value_set_boolean(value, proxy->priv->admin_mode);
         break;
+    case PROP_SESSION_ID:
+        g_value_set_string(value, proxy->priv->jsessionid);
+        break;
 
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
 }
 
+
+static void ovirt_proxy_set_session_id(OvirtProxy *proxy, const char *session_id)
+{
+    SoupCookie *cookie;
+    char *url;
+
+    g_object_get(G_OBJECT(proxy), "url-format", &url, NULL);
+    g_return_if_fail(url != NULL);
+
+    g_free(proxy->priv->jsessionid);
+    proxy->priv->jsessionid = g_strdup(session_id);
+    cookie = soup_cookie_new("JSESSIONID", session_id, url, "/api", -1);
+    g_free(url);
+    soup_cookie_jar_add_cookie(proxy->priv->cookie_jar, cookie);
+}
+
+
 static void ovirt_proxy_set_property(GObject *object,
                                      guint prop_id,
                                      const GValue *value,
@@ -714,6 +735,10 @@ static void ovirt_proxy_set_property(GObject *object,
         proxy->priv->admin_mode = g_value_get_boolean(value);
         break;
 
+    case PROP_SESSION_ID:
+        ovirt_proxy_set_session_id(proxy, g_value_get_string(value));
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
@@ -743,6 +768,7 @@ ovirt_proxy_finalize(GObject *obj)
     OvirtProxy *proxy = OVIRT_PROXY(obj);
 
     ovirt_proxy_set_tmp_ca_file(proxy, NULL);
+    g_free(proxy->priv->jsessionid);
 
     G_OBJECT_CLASS(ovirt_proxy_parent_class)->finalize(obj);
 }
@@ -774,6 +800,14 @@ ovirt_proxy_class_init(OvirtProxyClass *klass)
                                                          FALSE,
                                                          G_PARAM_READWRITE |
                                                          G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(oclass,
+                                    PROP_SESSION_ID,
+                                    g_param_spec_string("session-id",
+                                                        "session-id",
+                                                        "oVirt/RHEV JSESSIONID",
+                                                        NULL,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_STATIC_STRINGS));
 
     g_type_class_add_private(klass, sizeof(OvirtProxyPrivate));
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]