diff options
author | Günther Wagner <info@gunibert.de> | 2021-12-22 22:59:00 +0100 |
---|---|---|
committer | Günther Wagner <info@gunibert.de> | 2022-01-12 19:42:31 +0100 |
commit | 7c014077756c364537d41588578b49a1de9885cb (patch) | |
tree | 19fe0f2349af6653d3603b28d7a320467ea71641 /rest | |
parent | 548083cc8083e1de7b230fde68b4daa8097637c3 (diff) | |
download | librest-7c014077756c364537d41588578b49a1de9885cb.tar.gz |
oauth_proxy_call: remove private usage
Instead use public API of OAuthProxy
Diffstat (limited to 'rest')
-rw-r--r-- | rest/oauth-proxy-call.c | 49 | ||||
-rw-r--r-- | rest/oauth-proxy-private.h | 45 |
2 files changed, 20 insertions, 74 deletions
diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c index b292cad..560e928 100644 --- a/rest/oauth-proxy-call.c +++ b/rest/oauth-proxy-call.c @@ -24,7 +24,7 @@ #include <libsoup/soup.h> #include <rest/rest-proxy-call.h> #include "oauth-proxy-call.h" -#include "oauth-proxy-private.h" +#include "oauth-proxy.h" #include "rest-proxy-call-private.h" #include "sha1.h" @@ -33,14 +33,14 @@ G_DEFINE_TYPE (OAuthProxyCall, oauth_proxy_call, REST_TYPE_PROXY_CALL) #define OAUTH_ENCODE_STRING(x_) (x_ ? g_uri_escape_string( (x_), NULL, TRUE) : g_strdup ("")) static char * -sign_plaintext (OAuthProxyPrivate *priv) +sign_plaintext (OAuthProxy *proxy) { char *cs; char *ts; char *rv; - cs = OAUTH_ENCODE_STRING (priv->consumer_secret); - ts = OAUTH_ENCODE_STRING (priv->token_secret); + cs = OAUTH_ENCODE_STRING (oauth_proxy_get_consumer_secret (proxy)); + ts = OAUTH_ENCODE_STRING (oauth_proxy_get_token_secret (proxy)); rv = g_strconcat (cs, "&", ts, NULL); g_free (cs); @@ -117,7 +117,6 @@ merge_params (GHashTable *hash, RestParams *params) static char * sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params) { - OAuthProxyPrivate *priv; const char *url_str; char *key, *signature, *ep, *eep; const char *content_type; @@ -127,15 +126,14 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params) RestParam *param; gboolean encode_query_params = TRUE; - priv = PROXY_GET_PRIVATE (proxy); url_str = rest_proxy_call_get_url (call); text = g_string_new (NULL); g_string_append (text, rest_proxy_call_get_method (call)); g_string_append_c (text, '&'); - if (priv->oauth_echo) { - g_string_append_uri_escaped (text, priv->service_url, NULL, FALSE); - } else if (priv->signature_host != NULL) { + if (oauth_proxy_is_echo (proxy)) + g_string_append_uri_escaped (text, oauth_proxy_get_service_url (proxy), NULL, FALSE); + else if (oauth_proxy_get_signature_host (proxy) != NULL) { GUri *url = g_uri_parse (url_str, G_URI_FLAGS_ENCODED, NULL); GUri *new_url; gchar *signing_url; @@ -143,7 +141,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params) new_url = g_uri_build (g_uri_get_flags (url), g_uri_get_scheme (url), g_uri_get_userinfo (url), - priv->signature_host, + oauth_proxy_get_signature_host (proxy), g_uri_get_port (url), g_uri_get_path (url), g_uri_get_query (url), @@ -178,7 +176,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params) /* Merge the OAuth parameters with the query parameters */ all_params = g_hash_table_new (g_str_hash, g_str_equal); merge_hashes (all_params, oauth_params); - if (encode_query_params && !priv->oauth_echo) { + if (encode_query_params && !oauth_proxy_is_echo (proxy)) { merge_params (all_params, rest_proxy_call_get_params (call)); } @@ -191,7 +189,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params) g_hash_table_destroy (all_params); /* PLAINTEXT signature value is the HMAC-SHA1 key value */ - key = sign_plaintext (priv); + key = sign_plaintext (proxy); signature = hmac_sha1 (key, text->str); @@ -263,12 +261,10 @@ static gboolean _prepare (RestProxyCall *call, GError **error) { OAuthProxy *proxy = NULL; - OAuthProxyPrivate *priv; char *s; GHashTable *oauth_params; g_object_get (call, "proxy", &proxy, NULL); - priv = PROXY_GET_PRIVATE (proxy); /* We have to make this hash free the strings and thus duplicate when we put * them in since when we call call steal_oauth_params that has to duplicate @@ -288,15 +284,15 @@ _prepare (RestProxyCall *call, GError **error) g_hash_table_insert (oauth_params, g_strdup ("oauth_nonce"), s); g_hash_table_insert (oauth_params, g_strdup ("oauth_consumer_key"), - g_strdup (priv->consumer_key)); + g_strdup (oauth_proxy_get_consumer_key (proxy))); - if (priv->token) - g_hash_table_insert (oauth_params, g_strdup ("oauth_token"), g_strdup (priv->token)); + if (oauth_proxy_get_token (proxy)) + g_hash_table_insert (oauth_params, g_strdup ("oauth_token"), g_strdup (oauth_proxy_get_token (proxy))); - switch (priv->method) { + switch (oauth_proxy_get_sign_method (proxy)) { case PLAINTEXT: g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("PLAINTEXT")); - s = sign_plaintext (priv); + s = sign_plaintext (proxy); break; case HMAC_SHA1: g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("HMAC-SHA1")); @@ -306,9 +302,9 @@ _prepare (RestProxyCall *call, GError **error) g_hash_table_insert (oauth_params, g_strdup ("oauth_signature"), s); s = make_authorized_header (oauth_params); - if (priv->oauth_echo) { + if (oauth_proxy_is_echo (proxy)) { rest_proxy_call_add_header (call, "X-Verify-Credentials-Authorization", s); - rest_proxy_call_add_param (call, "X-Auth-Service-Provider", priv->service_url); + rest_proxy_call_add_param (call, "X-Auth-Service-Provider", oauth_proxy_get_service_url (proxy)); } else { rest_proxy_call_add_header (call, "Authorization", s); } @@ -336,7 +332,6 @@ oauth_proxy_call_init (OAuthProxyCall *self) void oauth_proxy_call_parse_token_response (OAuthProxyCall *call) { - OAuthProxyPrivate *priv; GHashTable *form; OAuthProxy *proxy; g_autofree gchar *formstr = NULL; @@ -346,19 +341,15 @@ oauth_proxy_call_parse_token_response (OAuthProxyCall *call) g_return_if_fail (OAUTH_IS_PROXY_CALL (call)); g_object_get (call, "proxy", &proxy, NULL); - priv = PROXY_GET_PRIVATE (proxy); g_object_unref (proxy); - g_assert (priv); formstr = g_strndup (rest_proxy_call_get_payload (REST_PROXY_CALL (call)), rest_proxy_call_get_payload_length (REST_PROXY_CALL (call))); form = soup_form_decode (formstr); - g_free (priv->token); - g_free (priv->token_secret); - priv->token = g_strdup (g_hash_table_lookup (form, "oauth_token")); - priv->token_secret = g_strdup (g_hash_table_lookup (form, "oauth_token_secret")); + oauth_proxy_set_token (proxy, g_hash_table_lookup (form, "oauth_token")); + oauth_proxy_set_token_secret (proxy, g_hash_table_lookup (form, "oauth_token_secret")); /* This header should only exist for request_token replies, but its easier just to always check it */ - priv->oauth_10a = g_hash_table_lookup (form, "oauth_callback_confirmed") != NULL; + oauth_proxy_set_oauth10a (proxy, g_hash_table_lookup (form, "oauth_callback_confirmed") != NULL); g_hash_table_destroy (form); } diff --git a/rest/oauth-proxy-private.h b/rest/oauth-proxy-private.h deleted file mode 100644 index 2d178a5..0000000 --- a/rest/oauth-proxy-private.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * librest - RESTful web services access - * Copyright (c) 2008, 2009, Intel Corporation. - * - * Authors: Rob Bradford <rob@linux.intel.com> - * Ross Burton <ross@linux.intel.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 "oauth-proxy.h" - -#define PROXY_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), OAUTH_TYPE_PROXY, OAuthProxyPrivate)) - -typedef struct { - /* Application "consumer" keys */ - char *consumer_key; - char *consumer_secret; - /* Authorisation "user" tokens */ - char *token; - char *token_secret; - /* How we're signing */ - OAuthSignatureMethod method; - /* OAuth 1.0a */ - gboolean oauth_10a; - char *verifier; - /* OAuth Echo */ - gboolean oauth_echo; - char *service_url; - /* URL to use for signatures */ - char *signature_host; -} OAuthProxyPrivate; |