[librest] oauth: Make sure RestProxyCall::url is set before using it



commit 55f8e9626a50d81fb893508698205057668bf792
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Tue Sep 2 16:23:32 2014 +0200

    oauth: Make sure RestProxyCall::url is set before using it
    
    The oauth "prepare" step needs RestProxyCall::url to be set, but since
    commit c66b6d this is only set after the "prepare" and
    "serialize_headers" methods have been called. As it's
    better if OAuthProxyCall do not directly access RestProxyCall private
    data, this commit adds a getter to RestProxyCall which will be used
    to make sure RestProxyCall::url is set when OAuthProxyCall::prepare
    needs it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=708359

 rest/oauth-proxy-call.c        |    6 ++++--
 rest/rest-proxy-call-private.h |    2 ++
 rest/rest-proxy-call.c         |   11 +++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c
index 63c859f..3056753 100644
--- a/rest/oauth-proxy-call.c
+++ b/rest/oauth-proxy-call.c
@@ -119,6 +119,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
 {
   OAuthProxyPrivate *priv;
   RestProxyCallPrivate *callpriv;
+  const char *url_str;
   char *key, *signature, *ep, *eep;
   const char *content_type;
   GString *text;
@@ -129,6 +130,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
 
   priv = PROXY_GET_PRIVATE (proxy);
   callpriv = call->priv;
+  url_str = rest_proxy_call_get_url (call);
 
   text = g_string_new (NULL);
   g_string_append (text, rest_proxy_call_get_method (REST_PROXY_CALL (call)));
@@ -136,7 +138,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
   if (priv->oauth_echo) {
     g_string_append_uri_escaped (text, priv->service_url, NULL, FALSE);
   } else if (priv->signature_host != NULL) {
-    SoupURI *url = soup_uri_new (callpriv->url);
+    SoupURI *url = soup_uri_new (url_str);
     gchar *signing_url;
 
     soup_uri_set_host (url, priv->signature_host);
@@ -147,7 +149,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
     soup_uri_free (url);
     g_free (signing_url);
   } else {
-    g_string_append_uri_escaped (text, callpriv->url, NULL, FALSE);
+    g_string_append_uri_escaped (text, url_str, NULL, FALSE);
   }
   g_string_append_c (text, '&');
 
diff --git a/rest/rest-proxy-call-private.h b/rest/rest-proxy-call-private.h
index c915691..573794e 100644
--- a/rest/rest-proxy-call-private.h
+++ b/rest/rest-proxy-call-private.h
@@ -55,6 +55,8 @@ struct _RestProxyCallPrivate {
   RestProxyCallAsyncClosure *cur_call_closure;
 };
 
+const char *rest_proxy_call_get_url (RestProxyCall *call);
+
 G_END_DECLS
 
 #endif /* _REST_PROXY_CALL_PRIVATE */
diff --git a/rest/rest-proxy-call.c b/rest/rest-proxy-call.c
index 22de07d..3339d47 100644
--- a/rest/rest-proxy-call.c
+++ b/rest/rest-proxy-call.c
@@ -1607,3 +1607,14 @@ rest_proxy_call_serialize_params (RestProxyCall *call,
 
   return FALSE;
 }
+
+G_GNUC_INTERNAL const char *
+rest_proxy_call_get_url (RestProxyCall *call)
+{
+  /* Ensure priv::url is current before returning it. This method is used
+   * by OAuthProxyCall::_prepare which expects set_url() to have been called,
+   * but this has been changed/broken by c66b6df
+   */
+  set_url(call);
+  return call->priv->url;
+}


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