From 1834d8ada954ee9864f52e838ee94552803c3f9b Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 15 Dec 2015 17:37:34 +0100 Subject: [PATCH] Make HTTP API to send the access token automatically --- src/matrix-http-api.c | 15 +++++++++++++++ src/test-client.c | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 4a21041..80d491e 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -430,6 +430,12 @@ response_callback(SoupSession *session, } } +static void +update_query_params(gchar *key, gchar *value, SoupURI *uri) +{ + soup_uri_set_query_from_fields(uri, key, value, NULL); +} + static void matrix_http_api_send(MatrixHTTPAPI *api, MatrixAPICallback callback, @@ -472,6 +478,15 @@ matrix_http_api_send(MatrixHTTPAPI *api, } uri = soup_uri_new_with_base(priv->uri, path); + + if (params) { + g_hash_table_foreach(params, (GHFunc)update_query_params, uri); + } + + if (priv->token) { + update_query_params("access_token", priv->token, uri); + } + url = soup_uri_to_string(uri, FALSE); soup_uri_free(uri); g_debug("Sending %s to %s", method, url); diff --git a/src/test-client.c b/src/test-client.c index 3ad7bdd..5c2bc2d 100644 --- a/src/test-client.c +++ b/src/test-client.c @@ -95,6 +95,12 @@ main(int argc, char *argv[]) g_info("Starting up: %s with %s:%s", url, user, password); + /* + * [ ] register + * [X] login + * [ ] create_room + * [ ] join_room + */ api = matrix_http_api_new(url, NULL); params = matrix_http_api_gen_parameters( "user", user,