/* * 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) { RestParams *params; RestParamsIter iter; const char *name; RestParam *param; GList *to_remove = NULL; params = rest_proxy_call_get_params (call); rest_params_iter_init (&iter, params); while (rest_params_iter_next (&iter, &name, ¶m)) { if (rest_param_is_string (param) && g_str_has_prefix (name, "oauth_")) { g_hash_table_insert (oauth_params, g_strdup (name), g_strdup (rest_param_get_content (param))); to_remove = g_list_prepend (to_remove, g_strdup (name)); } } while (to_remove) { rest_params_remove (params, to_remove->data); to_remove = g_list_delete_link (to_remove, to_remove); } }
static gboolean ovirt_action_rest_call_class_serialize_params(RestProxyCall *call, gchar **content_type, gchar **content, gsize *content_len, GError **error) { RestParams *params; RestParamsIter it; GString *body; const char *name; RestParam *param; g_return_val_if_fail(OVIRT_IS_ACTION_REST_CALL(call), FALSE); g_return_val_if_fail(content_type != NULL, FALSE); g_return_val_if_fail(content != NULL, FALSE); g_return_val_if_fail(content_len != NULL, FALSE); params = rest_proxy_call_get_params(call); if (!rest_params_are_strings(params)) { g_set_error(error, OVIRT_REST_CALL_ERROR, 0, _("Unexpected parameter type in REST call")); return FALSE; } body = g_string_new("<action>"); rest_params_iter_init(&it, params); while (rest_params_iter_next(&it, &name, ¶m)) { const char *val = rest_param_get_content(param); g_string_append_printf(body, "<%s>%s</%s>", name, val, name); } g_string_append(body, "</action>"); *content_type = g_strdup("application/xml"); *content = body->str; *content_len = body->len; g_string_free(body, FALSE); return TRUE; }
static void verify_user (SwService *service) { SwServiceLastfm *lastfm = SW_SERVICE_LASTFM (service); SwServiceLastfmPrivate *priv = lastfm->priv; char *hash_pw, *user_pass, *auth_token; RestProxyCall *call; RestParams *params; GHashTable *params_t; char *api_sig; hash_pw = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->password, -1); user_pass = g_strconcat(priv->username, hash_pw, NULL); auth_token = g_compute_checksum_for_string (G_CHECKSUM_MD5, user_pass, -1); call = rest_proxy_new_call (priv->proxy); rest_proxy_call_add_params (call, "api_key", priv->api_key, "username", priv->username, "authToken", auth_token, "method", "auth.getMobileSession", NULL); params = rest_proxy_call_get_params (call); params_t = rest_params_as_string_hash_table (params); api_sig = build_call_sig (params_t, priv->api_secret); rest_proxy_call_add_params (call, "api_sig", api_sig, NULL); rest_proxy_call_async (call, _mobile_session_cb, (GObject*)lastfm, NULL, NULL); g_hash_table_unref (params_t); g_free (api_sig); g_free (hash_pw); g_free (user_pass); g_free (auth_token); }