summaryrefslogtreecommitdiff
path: root/rest/rest-proxy-auth.c
diff options
context:
space:
mode:
Diffstat (limited to 'rest/rest-proxy-auth.c')
-rw-r--r--rest/rest-proxy-auth.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/rest/rest-proxy-auth.c b/rest/rest-proxy-auth.c
new file mode 100644
index 0000000..f336e7f
--- /dev/null
+++ b/rest/rest-proxy-auth.c
@@ -0,0 +1,89 @@
+/*
+ * librest - RESTful web services access
+ * Copyright (c) 2012, Red Hat, Inc.
+ *
+ * Authors: Christophe Fergeau <cfergeau@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <config.h>
+
+#include <rest/rest-proxy-auth.h>
+#include <rest/rest-proxy-auth-private.h>
+
+G_DEFINE_TYPE (RestProxyAuth, rest_proxy_auth, G_TYPE_OBJECT)
+
+#define REST_PROXY_AUTH_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), REST_TYPE_PROXY_AUTH, RestProxyAuthPrivate))
+
+struct _RestProxyAuthPrivate {
+ /* used to hold state during async authentication */
+ RestProxy *proxy;
+ SoupSession *session;
+ SoupMessage *message;
+ SoupAuth *auth;
+ gboolean paused;
+};
+
+static void
+rest_proxy_auth_dispose (GObject *object)
+{
+ RestProxyAuthPrivate *priv = ((RestProxyAuth*)object)->priv;
+
+ g_clear_object (&priv->proxy);
+ g_clear_object (&priv->session);
+ g_clear_object (&priv->message);
+ g_clear_object (&priv->auth);
+
+ G_OBJECT_CLASS (rest_proxy_auth_parent_class)->dispose (object);
+}
+
+static void
+rest_proxy_auth_class_init (RestProxyAuthClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (RestProxyAuthPrivate));
+
+ object_class->dispose = rest_proxy_auth_dispose;
+}
+
+static void
+rest_proxy_auth_init (RestProxyAuth *proxy)
+{
+ proxy->priv = REST_PROXY_AUTH_GET_PRIVATE (proxy);
+}
+
+G_GNUC_INTERNAL RestProxyAuth*
+rest_proxy_auth_new (RestProxy *proxy,
+ SoupSession *session,
+ SoupMessage *message,
+ SoupAuth *soup_auth)
+{
+ RestProxyAuth *rest_auth;
+
+ g_return_val_if_fail (REST_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (SOUP_IS_SESSION (session), NULL);
+ g_return_val_if_fail (SOUP_IS_MESSAGE (message), NULL);
+ g_return_val_if_fail (SOUP_IS_AUTH (soup_auth), NULL);
+
+ rest_auth = REST_PROXY_AUTH (g_object_new (REST_TYPE_PROXY_AUTH, NULL));
+ rest_auth->priv->proxy = g_object_ref(proxy);
+ rest_auth->priv->session = g_object_ref(session);
+ rest_auth->priv->message = g_object_ref(message);
+ rest_auth->priv->auth = g_object_ref(soup_auth);
+
+ return rest_auth;
+}