diff options
-rw-r--r-- | matrix-api.c | 46 | ||||
-rw-r--r-- | matrix-api.h | 24 |
2 files changed, 70 insertions, 0 deletions
diff --git a/matrix-api.c b/matrix-api.c index fd18ce9..0d593e1 100644 --- a/matrix-api.c +++ b/matrix-api.c @@ -993,6 +993,52 @@ MatrixApiRequestData *matrix_api_download_thumb(MatrixConnectionData *conn, return fetch_data; } +MatrixApiRequestData *matrix_api_upload_keys(MatrixConnectionData *conn, + JsonObject *device_keys, JsonObject *one_time_keys, + MatrixApiCallback callback, + MatrixApiErrorCallback error_callback, + MatrixApiBadResponseCallback bad_response_callback, + gpointer user_data) +{ + GString *url; + MatrixApiRequestData *fetch_data; + JsonNode *body_node; + JsonObject *top_obj; + JsonGenerator *generator; + gchar *json; + + url = g_string_new(conn->homeserver); + g_string_append(url, "_matrix/client/unstable/keys/upload?access_token="); + g_string_append(url, purple_url_encode(conn->access_token)); + + top_obj = json_object_new(); + if (device_keys) { + json_object_set_object_member(top_obj, "device_keys", device_keys); + } + if (one_time_keys) { + json_object_set_object_member(top_obj, "one_time_keys", one_time_keys); + } + body_node = json_node_new(JSON_NODE_OBJECT); + json_node_set_object(body_node, top_obj); + json_object_unref(top_obj); + + generator = json_generator_new(); + json_generator_set_root(generator, body_node); + json = json_generator_to_data(generator, NULL); + g_object_unref(G_OBJECT(generator)); + json_node_free(body_node); + + fetch_data = matrix_api_start_full(url->str, "POST", + "Content-Type: application/json", json, NULL, 0, + conn, callback, error_callback, bad_response_callback, + user_data, 1024); + g_free(json); + g_string_free(url, TRUE); + + return fetch_data; +} + + #if 0 MatrixApiRequestData *matrix_api_get_room_state(MatrixConnectionData *conn, const gchar *room_id, diff --git a/matrix-api.h b/matrix-api.h index 089b9b3..763f587 100644 --- a/matrix-api.h +++ b/matrix-api.h @@ -362,6 +362,30 @@ MatrixApiRequestData *matrix_api_download_thumb(MatrixConnectionData *conn, MatrixApiBadResponseCallback bad_response_callback, gpointer user_data); +/** + * e2e: Upload keys; one or more of the device keys and the one time keys + * @param conn The connection with which to make the request + * @param device_keys (optional) Json Object with the signed device keys + * device_keys gets unreferenced + * @param one_time_keys (optional) Json Object with one time key set + * one_time_keys gets unreferenced + * @param callback Function to be called when the request completes + * @param error_callback Function to be called if there is an error making + * the request. If NULL, matrix_api_error will be + * used. + * @param bad_response_callback Function to be called if the API gives a non-200 + * response. If NULL, matrix_api_bad_response will be + * used. + * @param user_data Opaque data to be passed to the callbacks + * + */ +MatrixApiRequestData *matrix_api_upload_keys(MatrixConnectionData *conn, + struct _JsonObject *device_keys, struct _JsonObject *one_time_keys, + MatrixApiCallback callback, + MatrixApiErrorCallback error_callback, + MatrixApiBadResponseCallback bad_response_callback, + gpointer user_data); + #if 0 /** * Get the current state of a room |