1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * soup-proxy-resolver-static.c: Static proxy "resolution"
5 * Copyright (C) 2008 Red Hat, Inc.
12 #include "soup-proxy-resolver-static.h"
18 } SoupProxyResolverStaticPrivate;
19 #define SOUP_PROXY_RESOLVER_STATIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_PROXY_RESOLVER_STATIC, SoupProxyResolverStaticPrivate))
21 static void soup_proxy_resolver_static_interface_init (SoupProxyURIResolverInterface *proxy_resolver_interface);
23 G_DEFINE_TYPE_EXTENDED (SoupProxyResolverStatic, soup_proxy_resolver_static, G_TYPE_OBJECT, 0,
24 G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, NULL)
25 G_IMPLEMENT_INTERFACE (SOUP_TYPE_PROXY_URI_RESOLVER, soup_proxy_resolver_static_interface_init))
36 soup_proxy_resolver_static_init (SoupProxyResolverStatic *resolver_static)
41 soup_proxy_resolver_static_finalize (GObject *object)
43 SoupProxyResolverStaticPrivate *priv =
44 SOUP_PROXY_RESOLVER_STATIC_GET_PRIVATE (object);
46 g_clear_pointer (&priv->proxy_uri, soup_uri_free);
48 G_OBJECT_CLASS (soup_proxy_resolver_static_parent_class)->finalize (object);
52 soup_proxy_resolver_static_set_property (GObject *object, guint prop_id,
53 const GValue *value, GParamSpec *pspec)
55 SoupProxyResolverStaticPrivate *priv =
56 SOUP_PROXY_RESOLVER_STATIC_GET_PRIVATE (object);
61 uri = g_value_get_boxed (value);
63 soup_uri_free (priv->proxy_uri);
65 priv->proxy_uri = uri ? soup_uri_copy (uri) : NULL;
68 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
74 soup_proxy_resolver_static_get_property (GObject *object, guint prop_id,
75 GValue *value, GParamSpec *pspec)
77 SoupProxyResolverStaticPrivate *priv =
78 SOUP_PROXY_RESOLVER_STATIC_GET_PRIVATE (object);
82 g_value_set_boxed (value, priv->proxy_uri);
85 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
91 SoupProxyURIResolver *proxy_resolver;
92 SoupProxyURIResolverCallback callback;
94 } SoupStaticAsyncData;
97 idle_return_proxy_uri (gpointer data)
99 SoupStaticAsyncData *ssad = data;
100 SoupProxyResolverStaticPrivate *priv =
101 SOUP_PROXY_RESOLVER_STATIC_GET_PRIVATE (ssad->proxy_resolver);
103 ssad->callback (ssad->proxy_resolver,
104 SOUP_STATUS_OK, priv->proxy_uri,
106 g_object_unref (ssad->proxy_resolver);
107 g_slice_free (SoupStaticAsyncData, ssad);
113 soup_proxy_resolver_static_get_proxy_uri_async (SoupProxyURIResolver *proxy_resolver,
115 GMainContext *async_context,
116 GCancellable *cancellable,
117 SoupProxyURIResolverCallback callback,
120 SoupStaticAsyncData *ssad;
122 ssad = g_slice_new0 (SoupStaticAsyncData);
123 ssad->proxy_resolver = g_object_ref (proxy_resolver);
124 ssad->callback = callback;
125 ssad->user_data = user_data;
126 soup_add_completion (async_context, idle_return_proxy_uri, ssad);
130 soup_proxy_resolver_static_get_proxy_uri_sync (SoupProxyURIResolver *proxy_resolver,
132 GCancellable *cancellable,
135 SoupProxyResolverStaticPrivate *priv =
136 SOUP_PROXY_RESOLVER_STATIC_GET_PRIVATE (proxy_resolver);
138 *proxy_uri = soup_uri_copy (priv->proxy_uri);
139 return SOUP_STATUS_OK;
143 soup_proxy_resolver_static_class_init (SoupProxyResolverStaticClass *static_class)
145 GObjectClass *object_class = G_OBJECT_CLASS (static_class);
147 g_type_class_add_private (static_class, sizeof (SoupProxyResolverStaticPrivate));
149 object_class->set_property = soup_proxy_resolver_static_set_property;
150 object_class->get_property = soup_proxy_resolver_static_get_property;
151 object_class->finalize = soup_proxy_resolver_static_finalize;
153 g_object_class_install_property (
154 object_class, PROP_PROXY_URI,
155 g_param_spec_boxed (SOUP_PROXY_RESOLVER_STATIC_PROXY_URI,
157 "The HTTP Proxy to use",
163 soup_proxy_resolver_static_interface_init (SoupProxyURIResolverInterface *proxy_uri_resolver_interface)
165 proxy_uri_resolver_interface->get_proxy_uri_async =
166 soup_proxy_resolver_static_get_proxy_uri_async;
167 proxy_uri_resolver_interface->get_proxy_uri_sync =
168 soup_proxy_resolver_static_get_proxy_uri_sync;
171 SoupProxyURIResolver *
172 soup_proxy_resolver_static_new (SoupURI *proxy_uri)
174 return g_object_new (SOUP_TYPE_PROXY_RESOLVER_STATIC,
175 SOUP_PROXY_RESOLVER_STATIC_PROXY_URI, proxy_uri,