[libgdata] core: Add a GDataOAuth1Authorizer:proxy-resolver property



commit 3ed33acfa1012f1795907c864d0b3d9a81285140
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Oct 12 09:28:10 2013 +0100

    core: Add a GDataOAuth1Authorizer:proxy-resolver property
    
    Bound to SoupSession’s ‘proxy-resolver’ property. Based on commit
    8f1923fcd9c4203f68ce6a0405526500a77783e5 by Matthew Barnes <mbarnes redhat com>.
    
    This deprecates the following API:
     • GDataOAuth1Authorizer:proxy-uri
     • gdata_oauth1_authorizer_[get|set]_proxy_uri()
    and adds the following new API:
     • GDataOAuth1Authorizer:proxy-resolver
     • gdata_oauth1_authorizer_[get|set]_proxy_resolver()
    
    Closes: https://bugzilla.gnome.org/show_bug.cgi?id=709758

 docs/reference/gdata-sections.txt |    2 +
 gdata/gdata-oauth1-authorizer.c   |  123 ++++++++++++++++++++++++++++++++-----
 gdata/gdata-oauth1-authorizer.h   |    9 ++-
 gdata/gdata.symbols               |    2 +
 gdata/tests/oauth1-authorizer.c   |   66 ++++++++++----------
 5 files changed, 151 insertions(+), 51 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 995fb5e..4c0e264 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -2314,6 +2314,8 @@ gdata_oauth1_authorizer_get_locale
 gdata_oauth1_authorizer_set_locale
 gdata_oauth1_authorizer_get_proxy_uri
 gdata_oauth1_authorizer_set_proxy_uri
+gdata_oauth1_authorizer_get_proxy_resolver
+gdata_oauth1_authorizer_set_proxy_resolver
 gdata_oauth1_authorizer_get_timeout
 gdata_oauth1_authorizer_set_timeout
 <SUBSECTION Standard>
diff --git a/gdata/gdata-oauth1-authorizer.c b/gdata/gdata-oauth1-authorizer.c
index 6cb702c..30ef600 100644
--- a/gdata/gdata-oauth1-authorizer.c
+++ b/gdata/gdata-oauth1-authorizer.c
@@ -162,9 +162,13 @@ static void sign_message (GDataOAuth1Authorizer *self, SoupMessage *message, con
 static void notify_proxy_uri_cb (GObject *object, GParamSpec *pspec, GDataOAuth1Authorizer *self);
 static void notify_timeout_cb (GObject *gobject, GParamSpec *pspec, GObject *self);
 
+static SoupURI *_get_proxy_uri (GDataOAuth1Authorizer *self);
+static void _set_proxy_uri (GDataOAuth1Authorizer *self, SoupURI *proxy_uri);
+
 struct _GDataOAuth1AuthorizerPrivate {
        SoupSession *session;
        SoupURI *proxy_uri; /* cached version only set if gdata_oauth1_authorizer_get_proxy_uri() is called */
+       GProxyResolver *proxy_resolver;
 
        gchar *application_name;
        gchar *locale;
@@ -185,6 +189,7 @@ enum {
        PROP_LOCALE,
        PROP_PROXY_URI,
        PROP_TIMEOUT,
+       PROP_PROXY_RESOLVER,
 };
 
 G_DEFINE_TYPE_WITH_CODE (GDataOAuth1Authorizer, gdata_oauth1_authorizer, G_TYPE_OBJECT,
@@ -244,6 +249,7 @@ gdata_oauth1_authorizer_class_init (GDataOAuth1AuthorizerClass *klass)
         * The proxy URI used internally for all network requests.
         *
         * Since: 0.9.0
+        * Deprecated: Use #GDataClientLoginAuthorizer:proxy-resolver instead, which gives more flexibility 
over the proxy used. (Since: 0.15.0.)
         */
        g_object_class_install_property (gobject_class, PROP_PROXY_URI,
                                         g_param_spec_boxed ("proxy-uri",
@@ -266,6 +272,19 @@ gdata_oauth1_authorizer_class_init (GDataOAuth1AuthorizerClass *klass)
                                                            "Timeout", "A timeout, in seconds, for network 
operations.",
                                                            0, G_MAXUINT, 0,
                                                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GDataOAuth1Authorizer:proxy-resolver:
+        *
+        * The #GProxyResolver used to determine a proxy URI.  Setting this will clear the 
#GDataOAuth1Authorizer:proxy-uri property.
+        *
+        * Since: 0.15.0
+        */
+       g_object_class_install_property (gobject_class, PROP_PROXY_RESOLVER,
+                                        g_param_spec_object ("proxy-resolver",
+                                                             "Proxy Resolver", "A GProxyResolver used to 
determine a proxy URI.",
+                                                             G_TYPE_PROXY_RESOLVER,
+                                                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -290,6 +309,9 @@ gdata_oauth1_authorizer_init (GDataOAuth1Authorizer *self)
        /* Proxy the SoupSession's proxy-uri and timeout properties */
        g_signal_connect (self->priv->session, "notify::proxy-uri", (GCallback) notify_proxy_uri_cb, self);
        g_signal_connect (self->priv->session, "notify::timeout", (GCallback) notify_timeout_cb, self);
+
+       /* Keep our GProxyResolver synchronized with SoupSession's. */
+       g_object_bind_property (self->priv->session, "proxy-resolver", self, "proxy-resolver", 
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 }
 
 static void
@@ -301,6 +323,8 @@ dispose (GObject *object)
                g_object_unref (priv->session);
        priv->session = NULL;
 
+       g_clear_object (&priv->proxy_resolver);
+
        /* Chain up to the parent class */
        G_OBJECT_CLASS (gdata_oauth1_authorizer_parent_class)->dispose (object);
 }
@@ -340,11 +364,14 @@ get_property (GObject *object, guint property_id, GValue *value, GParamSpec *psp
                        g_value_set_string (value, priv->locale);
                        break;
                case PROP_PROXY_URI:
-                       g_value_set_boxed (value, gdata_oauth1_authorizer_get_proxy_uri 
(GDATA_OAUTH1_AUTHORIZER (object)));
+                       g_value_set_boxed (value, _get_proxy_uri (GDATA_OAUTH1_AUTHORIZER (object)));
                        break;
                case PROP_TIMEOUT:
                        g_value_set_uint (value, gdata_oauth1_authorizer_get_timeout (GDATA_OAUTH1_AUTHORIZER 
(object)));
                        break;
+               case PROP_PROXY_RESOLVER:
+                       g_value_set_object (value, gdata_oauth1_authorizer_get_proxy_resolver 
(GDATA_OAUTH1_AUTHORIZER (object)));
+                       break;
                default:
                        /* We don't have any other property... */
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -373,11 +400,14 @@ set_property (GObject *object, guint property_id, const GValue *value, GParamSpe
                        gdata_oauth1_authorizer_set_locale (GDATA_OAUTH1_AUTHORIZER (object), 
g_value_get_string (value));
                        break;
                case PROP_PROXY_URI:
-                       gdata_oauth1_authorizer_set_proxy_uri (GDATA_OAUTH1_AUTHORIZER (object), 
g_value_get_boxed (value));
+                       _set_proxy_uri (GDATA_OAUTH1_AUTHORIZER (object), g_value_get_boxed (value));
                        break;
                case PROP_TIMEOUT:
                        gdata_oauth1_authorizer_set_timeout (GDATA_OAUTH1_AUTHORIZER (object), 
g_value_get_uint (value));
                        break;
+               case PROP_PROXY_RESOLVER:
+                       gdata_oauth1_authorizer_set_proxy_resolver (GDATA_OAUTH1_AUTHORIZER (object), 
g_value_get_object (value));
+                       break;
                default:
                        /* We don't have any other property... */
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -1290,18 +1320,9 @@ notify_proxy_uri_cb (GObject *gobject, GParamSpec *pspec, GDataOAuth1Authorizer
        g_object_notify (G_OBJECT (self), "proxy-uri");
 }
 
-/**
- * gdata_oauth1_authorizer_get_proxy_uri:
- * @self: a #GDataOAuth1Authorizer
- *
- * Gets the proxy URI on the #GDataOAuth1Authorizer's #SoupSession.
- *
- * Return value: (transfer full) (allow-none): the proxy URI, or %NULL; free with soup_uri_free()
- *
- * Since: 0.9.0
- */
-SoupURI *
-gdata_oauth1_authorizer_get_proxy_uri (GDataOAuth1Authorizer *self)
+/* Static function which isn't deprecated so we can continue using it internally. */
+static SoupURI *
+_get_proxy_uri (GDataOAuth1Authorizer *self)
 {
        SoupURI *proxy_uri;
 
@@ -1321,6 +1342,34 @@ gdata_oauth1_authorizer_get_proxy_uri (GDataOAuth1Authorizer *self)
 }
 
 /**
+ * gdata_oauth1_authorizer_get_proxy_uri:
+ * @self: a #GDataOAuth1Authorizer
+ *
+ * Gets the proxy URI on the #GDataOAuth1Authorizer's #SoupSession.
+ *
+ * Return value: (transfer full) (allow-none): the proxy URI, or %NULL; free with soup_uri_free()
+ *
+ * Since: 0.9.0
+ * Deprecated: Use gdata_oauth1_authorizer_get_proxy_resolver() instead, which gives more flexibility over 
the proxy used. (Since: 0.15.0.)
+ */
+SoupURI *
+gdata_oauth1_authorizer_get_proxy_uri (GDataOAuth1Authorizer *self)
+{
+       return _get_proxy_uri (self);
+}
+
+/* Static function which isn't deprecated so we can continue using it internally. */
+static void
+_set_proxy_uri (GDataOAuth1Authorizer *self, SoupURI *proxy_uri)
+{
+       g_return_if_fail (GDATA_IS_OAUTH1_AUTHORIZER (self));
+
+       g_object_set (self->priv->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
+
+       /* Notification is handled in notify_proxy_uri_cb() which is called as a result of setting the 
property on the session */
+}
+
+/**
  * gdata_oauth1_authorizer_set_proxy_uri:
  * @self: a #GDataOAuth1Authorizer
  * @proxy_uri: (allow-none): the proxy URI, or %NULL
@@ -1330,15 +1379,57 @@ gdata_oauth1_authorizer_get_proxy_uri (GDataOAuth1Authorizer *self)
  * If @proxy_uri is %NULL, no proxy will be used.
  *
  * Since: 0.9.0
+ * Deprecated: Use gdata_oauth1_authorizer_set_proxy_resolver() instead, which gives more flexibility over 
the proxy used. (Since: 0.15.0.)
  */
 void
 gdata_oauth1_authorizer_set_proxy_uri (GDataOAuth1Authorizer *self, SoupURI *proxy_uri)
 {
+       _set_proxy_uri (self, proxy_uri);
+}
+
+/**
+ * gdata_oauth1_authorizer_get_proxy_resolver:
+ * @self: a #GDataOAuth1Authorizer
+ *
+ * Gets the #GProxyResolver on the #GDataOAuth1Authorizer's #SoupSession.
+ *
+ * Return value: (transfer none) (allow-none): a #GProxyResolver, or %NULL
+ *
+ * Since: 0.15.0
+ */
+GProxyResolver *
+gdata_oauth1_authorizer_get_proxy_resolver (GDataOAuth1Authorizer *self)
+{
+       g_return_val_if_fail (GDATA_IS_OAUTH1_AUTHORIZER (self), NULL);
+
+       return self->priv->proxy_resolver;
+}
+
+/**
+ * gdata_oauth1_authorizer_set_proxy_resolver:
+ * @self: a #GDataOAuth1Authorizer
+ * @proxy_resolver: (allow-none): a #GProxyResolver, or %NULL
+ *
+ * Sets the #GProxyResolver on the #SoupSession used internally by the given #GDataOAuth1Authorizer.
+ *
+ * Setting this will clear the #GDataOAuth1Authorizer:proxy-uri property.
+ *
+ * Since: 0.15.0
+ */
+void
+gdata_oauth1_authorizer_set_proxy_resolver (GDataOAuth1Authorizer *self, GProxyResolver *proxy_resolver)
+{
        g_return_if_fail (GDATA_IS_OAUTH1_AUTHORIZER (self));
+       g_return_if_fail (proxy_resolver == NULL || G_IS_PROXY_RESOLVER (proxy_resolver));
 
-       g_object_set (self->priv->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
+       if (proxy_resolver != NULL) {
+               g_object_ref (proxy_resolver);
+       }
 
-       /* Notification is handled in notify_proxy_uri_cb() which is called as a result of setting the 
property on the session */
+       g_clear_object (&self->priv->proxy_resolver);
+       self->priv->proxy_resolver = proxy_resolver;
+
+       g_object_notify (G_OBJECT (self), "proxy-resolver");
 }
 
 static void
diff --git a/gdata/gdata-oauth1-authorizer.h b/gdata/gdata-oauth1-authorizer.h
index dd2d4d7..a17f200 100644
--- a/gdata/gdata-oauth1-authorizer.h
+++ b/gdata/gdata-oauth1-authorizer.h
@@ -86,8 +86,13 @@ const gchar *gdata_oauth1_authorizer_get_application_name (GDataOAuth1Authorizer
 const gchar *gdata_oauth1_authorizer_get_locale (GDataOAuth1Authorizer *self) G_GNUC_PURE;
 void gdata_oauth1_authorizer_set_locale (GDataOAuth1Authorizer *self, const gchar *locale);
 
-SoupURI *gdata_oauth1_authorizer_get_proxy_uri (GDataOAuth1Authorizer *self) G_GNUC_PURE;
-void gdata_oauth1_authorizer_set_proxy_uri (GDataOAuth1Authorizer *self, SoupURI *proxy_uri);
+#ifndef LIBGDATA_DISABLE_DEPRECATED
+SoupURI *gdata_oauth1_authorizer_get_proxy_uri (GDataOAuth1Authorizer *self) G_GNUC_PURE 
G_GNUC_DEPRECATED_FOR (gdata_oauth1_authorizer_get_proxy_resolver);
+void gdata_oauth1_authorizer_set_proxy_uri (GDataOAuth1Authorizer *self, SoupURI *proxy_uri) 
G_GNUC_DEPRECATED_FOR (gdata_oauth1_authorizer_set_proxy_resolver);
+#endif /* !LIBGDATA_DISABLE_DEPRECATED */
+
+GProxyResolver *gdata_oauth1_authorizer_get_proxy_resolver (GDataOAuth1Authorizer *self) G_GNUC_PURE;
+void gdata_oauth1_authorizer_set_proxy_resolver (GDataOAuth1Authorizer *self, GProxyResolver 
*proxy_resolver);
 
 guint gdata_oauth1_authorizer_get_timeout (GDataOAuth1Authorizer *self) G_GNUC_PURE;
 void gdata_oauth1_authorizer_set_timeout (GDataOAuth1Authorizer *self, guint timeout);
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 12e0b9e..7c5560d 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -916,6 +916,8 @@ gdata_oauth1_authorizer_get_locale
 gdata_oauth1_authorizer_set_locale
 gdata_oauth1_authorizer_get_proxy_uri
 gdata_oauth1_authorizer_set_proxy_uri
+gdata_oauth1_authorizer_get_proxy_resolver
+gdata_oauth1_authorizer_set_proxy_resolver
 gdata_oauth1_authorizer_get_timeout
 gdata_oauth1_authorizer_set_timeout
 gdata_calendar_query_get_max_attendees
diff --git a/gdata/tests/oauth1-authorizer.c b/gdata/tests/oauth1-authorizer.c
index a8a9b4f..537df1a 100644
--- a/gdata/tests/oauth1-authorizer.c
+++ b/gdata/tests/oauth1-authorizer.c
@@ -80,8 +80,8 @@ typedef struct {
 
        guint locale_notification_count;
        gulong locale_signal_handler;
-       guint proxy_uri_notification_count;
-       gulong proxy_uri_signal_handler;
+       guint proxy_resolver_notification_count;
+       gulong proxy_resolver_signal_handler;
        guint timeout_notification_count;
        gulong timeout_signal_handler;
 } OAuth1AuthorizerData;
@@ -103,8 +103,8 @@ connect_to_oauth1_authorizer (OAuth1AuthorizerData *data)
        /* Connect to notifications from the object to verify they're only emitted the correct number of 
times */
        data->locale_signal_handler = g_signal_connect (data->authorizer, "notify::locale", (GCallback) 
notify_cb,
                                                        &(data->locale_notification_count));
-       data->proxy_uri_signal_handler = g_signal_connect (data->authorizer, "notify::proxy-uri", (GCallback) 
notify_cb,
-                                                          &(data->proxy_uri_notification_count));
+       data->proxy_resolver_signal_handler = g_signal_connect (data->authorizer, "notify::proxy-resolver", 
(GCallback) notify_cb,
+                                                               &(data->proxy_resolver_notification_count));
        data->timeout_signal_handler = g_signal_connect (data->authorizer, "notify::timeout", (GCallback) 
notify_cb,
                                                         &(data->timeout_notification_count));
 }
@@ -206,7 +206,7 @@ tear_down_oauth1_authorizer_data (OAuth1AuthorizerData *data, gconstpointer user
 {
        /* Clean up signal handlers */
        g_signal_handler_disconnect (data->authorizer, data->timeout_signal_handler);
-       g_signal_handler_disconnect (data->authorizer, data->proxy_uri_signal_handler);
+       g_signal_handler_disconnect (data->authorizer, data->proxy_resolver_signal_handler);
        g_signal_handler_disconnect (data->authorizer, data->locale_signal_handler);
 
        g_object_unref (data->authorizer);
@@ -286,52 +286,52 @@ test_oauth1_authorizer_properties_locale (OAuth1AuthorizerData *data, gconstpoin
        g_assert_cmpstr (gdata_oauth1_authorizer_get_locale (data->authorizer), ==, "de");
 }
 
-/* Test getting and setting the proxy-uri property */
+/* Test getting and setting the proxy-resolver property */
 static void
-test_oauth1_authorizer_properties_proxy_uri (OAuth1AuthorizerData *data, gconstpointer user_data)
+test_oauth1_authorizer_properties_proxy_resolver (OAuth1AuthorizerData *data, gconstpointer user_data)
 {
-       SoupURI *proxy_uri, *new_proxy_uri;
+       GProxyResolver *proxy_resolver, *new_proxy_resolver;
 
        /* Verifying the normal state of the property in a newly-constructed instance of 
GDataOAuth1Authorizer */
-       g_assert (gdata_oauth1_authorizer_get_proxy_uri (data->authorizer) == NULL);
+       g_assert (gdata_oauth1_authorizer_get_proxy_resolver (data->authorizer) == NULL);
 
-       g_object_get (data->authorizer, "proxy-uri", &proxy_uri, NULL);
-       g_assert (proxy_uri == NULL);
+       g_object_get (data->authorizer, "proxy-resolver", &proxy_resolver, NULL);
+       g_assert (proxy_resolver == NULL);
 
-       g_assert_cmpuint (data->proxy_uri_notification_count, ==, 0);
+       g_assert_cmpuint (data->proxy_resolver_notification_count, ==, 0);
 
        /* Check setting it works and emits a notification */
-       new_proxy_uri = soup_uri_new ("http://example.com/";);
-       gdata_oauth1_authorizer_set_proxy_uri (data->authorizer, new_proxy_uri);
+       new_proxy_resolver = g_object_ref (g_proxy_resolver_get_default ());
+       gdata_oauth1_authorizer_set_proxy_resolver (data->authorizer, new_proxy_resolver);
 
-       g_assert_cmpuint (data->proxy_uri_notification_count, ==, 1);
+       g_assert_cmpuint (data->proxy_resolver_notification_count, ==, 1);
 
-       g_assert (gdata_oauth1_authorizer_get_proxy_uri (data->authorizer) != NULL);
-       g_assert (soup_uri_equal (gdata_oauth1_authorizer_get_proxy_uri (data->authorizer), new_proxy_uri) == 
TRUE);
+       g_assert (gdata_oauth1_authorizer_get_proxy_resolver (data->authorizer) != NULL);
+       g_assert (gdata_oauth1_authorizer_get_proxy_resolver (data->authorizer) == new_proxy_resolver);
 
-       g_object_get (data->authorizer, "proxy-uri", &proxy_uri, NULL);
-       g_assert (proxy_uri != NULL);
-       g_assert (soup_uri_equal (gdata_oauth1_authorizer_get_proxy_uri (data->authorizer), new_proxy_uri) == 
TRUE);
-       soup_uri_free (proxy_uri);
+       g_object_get (data->authorizer, "proxy-resolver", &proxy_resolver, NULL);
+       g_assert (proxy_resolver != NULL);
+       g_assert (gdata_oauth1_authorizer_get_proxy_resolver (data->authorizer) == new_proxy_resolver);
+       g_object_unref (proxy_resolver);
 
-       soup_uri_free (new_proxy_uri);
+       g_object_unref (new_proxy_resolver);
 
        /* Check setting it back to NULL works */
-       gdata_oauth1_authorizer_set_proxy_uri (data->authorizer, NULL);
+       gdata_oauth1_authorizer_set_proxy_resolver (data->authorizer, NULL);
 
-       g_assert_cmpuint (data->proxy_uri_notification_count, ==, 2);
+       g_assert_cmpuint (data->proxy_resolver_notification_count, ==, 2);
 
-       g_assert (gdata_oauth1_authorizer_get_proxy_uri (data->authorizer) == NULL);
+       g_assert (gdata_oauth1_authorizer_get_proxy_resolver (data->authorizer) == NULL);
 
-       g_object_get (data->authorizer, "proxy-uri", &proxy_uri, NULL);
-       g_assert (proxy_uri == NULL);
+       g_object_get (data->authorizer, "proxy-resolver", &proxy_resolver, NULL);
+       g_assert (proxy_resolver == NULL);
 
        /* Test that setting it using g_object_set() works */
-       new_proxy_uri = soup_uri_new ("http://example.com/";);
-       g_object_set (data->authorizer, "proxy-uri", new_proxy_uri, NULL);
-       soup_uri_free (new_proxy_uri);
+       new_proxy_resolver = g_object_ref (g_proxy_resolver_get_default ());
+       g_object_set (data->authorizer, "proxy-resolver", new_proxy_resolver, NULL);
+       g_object_unref (new_proxy_resolver);
 
-       g_assert (gdata_oauth1_authorizer_get_proxy_uri (data->authorizer) != NULL);
+       g_assert (gdata_oauth1_authorizer_get_proxy_resolver (data->authorizer) != NULL);
 }
 
 /* Test getting and setting the timeout property */
@@ -1048,8 +1048,8 @@ main (int argc, char *argv[])
                    tear_down_oauth1_authorizer_data);
        g_test_add ("/oauth1-authorizer/properties/locale", OAuth1AuthorizerData, NULL, 
set_up_oauth1_authorizer_data,
                    test_oauth1_authorizer_properties_locale, tear_down_oauth1_authorizer_data);
-       g_test_add ("/oauth1-authorizer/properties/proxy-uri", OAuth1AuthorizerData, NULL, 
set_up_oauth1_authorizer_data,
-                   test_oauth1_authorizer_properties_proxy_uri, tear_down_oauth1_authorizer_data);
+       g_test_add ("/oauth1-authorizer/properties/proxy-resolver", OAuth1AuthorizerData, NULL, 
set_up_oauth1_authorizer_data,
+                   test_oauth1_authorizer_properties_proxy_resolver, tear_down_oauth1_authorizer_data);
        g_test_add ("/oauth1-authorizer/properties/timeout", OAuth1AuthorizerData, NULL, 
set_up_oauth1_authorizer_data,
                    test_oauth1_authorizer_properties_timeout, tear_down_oauth1_authorizer_data);
 


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