From 7ed72bffc1f41ac1025c980f52dd19fd9b2530c1 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 15 Jan 2016 13:13:38 +0100 Subject: [PATCH] Implement media_download --- src/matrix-http-api.c | 29 ++++++++++++++++++++++++++++- src/test-client.c | 5 +++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index c111ef1..d9877aa 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -1109,11 +1109,38 @@ i_get_user_presence(MatrixAPI *api, _send(MATRIX_HTTP_API(api), callback, user_data, + CALL_API, "GET", path, NULL, NULL, FALSE, error); g_free(path); } +static void +i_media_download(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + const gchar *server_name, + const gchar *media_id, + GError **error) +{ + gchar *encoded_server_name, *encoded_media_id, *path; + + encoded_server_name = soup_uri_encode(server_name, NULL); + encoded_media_id = soup_uri_encode(media_id, NULL); + path = g_strdup_printf("download/%s/%s", + encoded_server_name, + encoded_media_id); + g_free(encoded_server_name); + g_free(encoded_media_id); + + _send(MATRIX_HTTP_API(api), + callback, user_data, + CALL_MEDIA, + "GET", path, NULL, NULL, + TRUE, error); + g_free(path); +} + static void matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) { @@ -1125,7 +1152,7 @@ matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) iface->get_homeserver = i_get_homeserver; /* Media */ - iface->media_download = NULL; + iface->media_download = i_media_download; iface->media_thumbnail = NULL; iface->media_upload = NULL; diff --git a/src/test-client.c b/src/test-client.c index d29b9f7..5a7d410 100644 --- a/src/test-client.c +++ b/src/test-client.c @@ -89,6 +89,11 @@ get_user_presence_finished(MatrixAPI *api, soup_uri_get_scheme(avatar_uri), soup_uri_get_host(avatar_uri), soup_uri_get_path(avatar_uri)); + matrix_api_media_download(api, + NULL, NULL, + soup_uri_get_host(avatar_uri), + soup_uri_get_path(avatar_uri) + 1, + NULL); soup_uri_free(avatar_uri); }