summaryrefslogtreecommitdiff
path: root/rest/oauth-proxy-call.c
diff options
context:
space:
mode:
authorRoss Burton <ross@linux.intel.com>2010-07-06 11:24:52 +0100
committerRoss Burton <ross@linux.intel.com>2010-07-08 21:17:06 +0100
commit77903df0256907073e0d8cadd9bd6acf4ff3d2d4 (patch)
tree824a0efa1885b538c374cdb31c0e0b5d3a63b7f5 /rest/oauth-proxy-call.c
parent23de181bdb4eae9fe769a8f20d5359cbf443e52a (diff)
Port the proxies to use RestParam
Diffstat (limited to 'rest/oauth-proxy-call.c')
-rw-r--r--rest/oauth-proxy-call.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c
index 4d824c6..ab2ba5d 100644
--- a/rest/oauth-proxy-call.c
+++ b/rest/oauth-proxy-call.c
@@ -96,7 +96,21 @@ merge_hashes (GHashTable *hash, GHashTable *from)
g_hash_table_iter_init (&iter, from);
while (g_hash_table_iter_next (&iter, &key, &value)) {
- g_hash_table_insert (hash, key, g_strdup (value));
+ g_hash_table_insert (hash, key, value);
+ }
+}
+
+static void
+merge_params (GHashTable *hash, RestParams *params)
+{
+ RestParamsIter iter;
+ const char *name;
+ RestParam *param;
+
+ rest_params_iter_init (&iter, params);
+ while (rest_params_iter_next (&iter, &name, &param)) {
+ if (rest_param_is_string (param))
+ g_hash_table_insert (hash, (gpointer)name, (gpointer)rest_param_get_content (param));
}
}
@@ -119,9 +133,9 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
g_string_append_c (text, '&');
/* Merge the OAuth parameters with the query parameters */
- all_params = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+ all_params = g_hash_table_new (g_str_hash, g_str_equal);
merge_hashes (all_params, oauth_params);
- merge_hashes (all_params, callpriv->params);
+ merge_params (all_params, callpriv->params);
ep = encode_params (all_params);
eep = OAUTH_ENCODE_STRING (ep);
@@ -167,31 +181,33 @@ make_authorized_header (GHashTable *oauth_params)
return g_string_free (auth, FALSE);
}
+/*
+ * Remove any OAuth parameters from the @call parameters and add them to
+ * @oauth_params for building an Authorized header with.
+ */
static void
steal_oauth_params (RestProxyCall *call, GHashTable *oauth_params)
{
- GHashTable *params;
- GHashTableIter iter;
- char *key, *value;
+ RestParams *params;
+ RestParamsIter iter;
+ const char *name;
+ RestParam *param;
GList *to_remove = NULL;
params = rest_proxy_call_get_params (call);
- g_hash_table_iter_init (&iter, params);
- while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value)) {
- if (g_str_has_prefix (key, "oauth_")) {
- g_hash_table_insert (oauth_params, key, value);
- to_remove = g_list_prepend (to_remove, key);
- /* TODO: key will be leaked */
+ rest_params_iter_init (&iter, params);
+ while (rest_params_iter_next (&iter, &name, &param)) {
+ if (rest_param_is_string (param) && g_str_has_prefix (name, "oauth_")) {
+ g_hash_table_insert (oauth_params, g_strdup (name), (gpointer)rest_param_get_content (param));
+ to_remove = g_list_prepend (to_remove, g_strdup (name));
}
}
while (to_remove) {
- g_hash_table_steal (params, to_remove->data);
+ rest_params_remove (params, to_remove->data);
to_remove = g_list_delete_link (to_remove, to_remove);
}
-
- g_hash_table_unref (params);
}
static gboolean