Port MatrixHTTPAPI to C

This commit is contained in:
Gergely Polonkai 2017-11-28 18:09:55 +01:00
parent b495cdc66a
commit af87f75338
7 changed files with 2932 additions and 1916 deletions

1
.gitignore vendored
View File

@ -48,7 +48,6 @@ Makefile.in
/src/vala-stamp /src/vala-stamp
/src/matrix-glib.h /src/matrix-glib.h
/src/matrix-client.c /src/matrix-client.c
/src/matrix-http-api.c
/src/matrix-http-client.c /src/matrix-http-client.c
/src/namespace-info.vala /src/namespace-info.vala
/src/namespace-info.c /src/namespace-info.c

View File

@ -18,7 +18,6 @@ lib_LTLIBRARIES = libmatrix-glib-0.0.la
libmatrix_glib_0_0_la_VALA_SOURCES = \ libmatrix_glib_0_0_la_VALA_SOURCES = \
namespace-info.vala \ namespace-info.vala \
matrix-client.vala \ matrix-client.vala \
matrix-http-api.vala \
matrix-http-client.vala \ matrix-http-client.vala \
$(NULL) $(NULL)
@ -76,6 +75,7 @@ INST_H_SRC_FILES = \
matrix-types.h \ matrix-types.h \
matrix-compacts.h \ matrix-compacts.h \
matrix-api.h \ matrix-api.h \
matrix-http-api.h \
matrix-event-base.h \ matrix-event-base.h \
matrix-event-call-base.h \ matrix-event-call-base.h \
matrix-event-call-answer.h \ matrix-event-call-answer.h \
@ -134,6 +134,7 @@ libmatrix_glib_0_0_la_SOURCES = \
matrix-event-types.c \ matrix-event-types.c \
matrix-version.c \ matrix-version.c \
matrix-api.c \ matrix-api.c \
matrix-http-api.c \
matrix-types.c \ matrix-types.c \
matrix-compacts.c \ matrix-compacts.c \
matrix-event-base.c \ matrix-event-base.c \

2627
src/matrix-http-api.c Normal file

File diff suppressed because it is too large Load Diff

58
src/matrix-http-api.h Normal file
View File

@ -0,0 +1,58 @@
/*
* This file is part of matrix-glib-sdk
*
* matrix-glib-sdk is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* matrix-glib-sdk is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with matrix-glib-sdk. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef __MATRIX_GLIB_SDK_HTTP_API_H__
# define __MATRIX_GLIB_SDK_HTTP_API_H__
# include <glib-object.h>
# include "matrix-api.h"
G_BEGIN_DECLS
# define MATRIX_TYPE_HTTP_API (matrix_http_api_get_type ())
# define MATRIX_HTTP_API(o) (G_TYPE_CHECK_INSTANCE_CAST((o), MATRIX_TYPE_HTTP_API, MatrixHTTPAPI))
# define MATRIX_HTTP_API_CLASS(c) (G_TYPE_CHECK_CLASS_CAST((c), MATRIX_TYPE_HTTP_API, MatrixHTTPAPIClass))
# define MATRIX_IS_HTTP_API(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), MATRIX_TYPE_HTTP_API))
# define MATRIX_IS_HTTP_API_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE((c), MATRIX_TYPE_HTTP_API))
# define MATRIX_HTTP_API_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), MATRIX_TYPE_HTTP_API, MatrixHTTPAPIClass))
typedef struct _MatrixHTTPAPI MatrixHTTPAPI;
typedef struct _MatrixHTTPAPIClass MatrixHTTPAPIClass;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(MatrixHTTPAPI, g_object_unref)
struct _MatrixHTTPAPI {
GObject parent_instance;
gchar *_homeserver;
gchar *_user_id;
};
struct _MatrixHTTPAPIClass {
GObjectClass parent_class;
};
GType matrix_http_api_get_type(void) G_GNUC_CONST;
MatrixHTTPAPI *matrix_http_api_new(const gchar *base_url, const gchar *token, const gchar *refresh_token);
const gchar *matrix_http_api_get_base_url(MatrixHTTPAPI *http_api);
void matrix_http_api_set_base_url(MatrixHTTPAPI *http_api, const gchar *base_url);
gboolean matrix_http_api_get_validate_certificate(MatrixHTTPAPI *http_api);
void matrix_http_api_set_validate_certificate(MatrixHTTPAPI *http_api, gboolean validate_certificate);
G_END_DECLS
#endif /* __MATRIX_GLIB_SDK_HTTP_API_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@
#include <json-glib/json-glib.h> #include <json-glib/json-glib.h>
#include <libsoup/soup.h> #include <libsoup/soup.h>
#include "matrix-glib.h" #include "matrix-http-api.h"
#define LOG_DOMAIN "Matrix-Test-Client" #define LOG_DOMAIN "Matrix-Test-Client"

View File

@ -704,6 +704,250 @@ namespace Matrix {
throws Matrix.Error; throws Matrix.Error;
} }
[CCode (lower_case_csuffix = "http_api", cheader_filename = "matrix-http-api.h")]
public class HTTPAPI : GLib.Object, API {
public string base_url { get; set; }
public bool validate_certificate { get; set; }
protected string? _user_id;
public string? user_id { get; default = null; }
public string? token { get; set; default = null; }
public string? refresh_token { get; set; default = null; }
protected string? _homeserver;
public string? homeserver { get; default = null; }
protected HTTPAPI(string base_url, string? token = null, string? refresh_token = null);
/* Media */
public void media_download(API.Callback? cb, string server_name, string media_id)
throws Matrix.Error;
public void media_thumbnail(API.Callback? cb, string server_name, string media_id, uint width, uint height, ResizeMethod method)
throws Matrix.Error;
public void media_upload(API.Callback? cb, string? content_type, owned GLib.ByteArray content)
throws Matrix.Error;
/* Presence */
public void get_presence_list(API.Callback? cb, string user_id)
throws Matrix.Error;
public void
update_presence_list(API.Callback? cb, string user_id, string[] drop_ids, string[] invite_ids)
throws Matrix.Error;
public void get_presence(API.Callback? cb, string user_id)
throws Matrix.Error;
public void set_presence(API.Callback? cb, string user_id, Presence presence, string? status_message)
throws Matrix.Error;
/* Push notifications */
public void update_pusher(API.Callback? cb, Matrix.Pusher pusher)
throws Matrix.Error;
public void get_pushers(API.Callback? cb)
throws Matrix.Error;
private void _pusher_modif(API.Callback? cb, string method, string scope, PusherKind kind, string rule_id)
throws Matrix.Error;
public void delete_pushrule(API.Callback? cb, string scope, PusherKind kind, string rule_id)
throws Matrix.Error;
public void get_pushrule(API.Callback? cb, string scope, PusherKind kind, string rule_id)
throws Matrix.Error;
public void add_pushrule(API.Callback? cb, string scope, PusherKind kind, string rule_id, string? before, string? after, string[] actions, PusherConditionKind[] conditions)
throws Matrix.Error;
public void toggle_pushrule(API.Callback? cb, string scope, PusherKind kind, string rule_id, bool enabled)
throws Matrix.Error;
public void get_pushrules(API.Callback? cb)
throws Matrix.Error;
/* Room creation */
public void create_room(API.Callback? cb, RoomPreset preset, string? room_name, string? room_alias, string? topic, RoomVisibility visibility, Json.Node? creation_content, Matrix.Event.State[] initial_state, string[] invitees, 3PidCredential[] invite_3pids)
throws Matrix.Error;
/* Room directory */
public void delete_room_alias(API.Callback? cb, string room_alias)
throws Matrix.Error;
public void get_room_id(API.Callback? cb, string room_alias)
throws Matrix.Error;
public void create_room_alias(API.Callback? cb, string room_id, string room_alias)
throws Matrix.Error;
/* Room discovery */
public void list_public_rooms(API.Callback? cb)
throws Matrix.Error;
/* Room membership */
public void ban_user(API.Callback? cb, string room_id, string user_id, string? reason)
throws Matrix.Error;
public void unban_user(API.Callback? cb, string room_id, string user_id)
throws Matrix.Error;
public void forget_room(API.Callback? cb, string room_id)
throws Matrix.Error;
public void invite_user_3rdparty(API.Callback? cb, string room_id, Matrix.3PidCredential credential)
throws Matrix.Error;
public void invite_user(API.Callback? cb, string room_id, string user_id)
throws Matrix.Error;
public void join_room(API.Callback? cb, string room_id)
throws Matrix.Error;
public void leave_room(API.Callback? cb, string room_id)
throws Matrix.Error;
public void join_room_id_or_alias(API.Callback? cb, string room_id_or_alias)
throws Matrix.Error;
public void kick_user(API.Callback? cb, string room_id, string user_id, string? reason)
throws Matrix.Error;
/* Room participation */
public void event_stream(API.Callback? cb, string? from_token, ulong timeout)
throws Matrix.Error;
public void get_event(API.Callback? cb, string event_id)
throws Matrix.Error;
public void initial_sync(API.Callback? cb, uint limit, bool archived)
throws Matrix.Error;
public void get_event_context(API.Callback? cb, string room_id, string event_id, uint limit)
throws Matrix.Error;
public void initial_sync_room(API.Callback? cb, string room_id)
throws Matrix.Error;
public void list_room_members(API.Callback? cb, string room_id)
throws Matrix.Error;
public void list_room_messages(API.Callback? cb, string room_id, string from_token, EventDirection direction, uint limit)
throws Matrix.Error;
public void send_event_receipt(API.Callback? cb, string room_id, ReceiptType receipt_type, string event_id, Json.Node receipt)
throws Matrix.Error;
public void redact_event(API.Callback? cb, string room_id, string event_id, string txn_id, string? reason)
throws Matrix.Error;
public void send_event(API.Callback? cb, string room_id, string event_type, string txn_id, owned Json.Node content)
throws Matrix.Error;
public void get_room_state(API.Callback? cb, string room_id, string? event_type, string? state_key)
throws Matrix.Error;
public void send_state_event(API.Callback? cb, string room_id, string event_type, string? state_key, owned Json.Node content)
throws Matrix.Error;
public void notify_room_typing(API.Callback? cb, string user_id, string room_id, uint timeout, bool typing)
throws Matrix.Error;
public void sync(API.Callback? cb, string? filter_id, Filter? filter, string? since, bool full_state, bool set_presence, ulong timeout)
throws Matrix.Error;
public void create_filter(API.Callback? cb, string user_id, Filter filter)
throws Matrix.Error;
public void download_filter(API.Callback? cb, string user_id, string filter_id)
throws Matrix.Error;
/* Search */
public void search(Matrix.API.Callback? cb, string? next_batch, SearchCategories search_categories)
throws Matrix.Error;
/* Server administration */
public void whois(API.Callback? cb, string user_id)
throws Matrix.Error;
public void versions(API.Callback? cb)
throws Matrix.Error;
/* Session management */
public void login(API.Callback? cb, string login_type, Json.Node? content)
throws Matrix.Error;
public void token_refresh(API.Callback? cb, string? refresh_token)
throws Matrix.Error;
public void logout(API.Callback? cb)
throws Matrix.Error;
/* User data */
public void get_3pids(API.Callback? cb)
throws Matrix.Error;
public void add_3pid(API.Callback? cb, bool bind_creds, Matrix.3PidCredential creds)
throws Matrix.Error;
public void change_password(API.Callback? cb, string new_password)
throws Matrix.Error;
public void get_profile(API.Callback? cb, string user_id)
throws Matrix.Error;
public void get_avatar_url(API.Callback? cb, string user_id)
throws Matrix.Error;
public void set_avatar_url(API.Callback? cb, string user_id, string avatar_url)
throws Matrix.Error;
public void get_display_name(API.Callback? cb, string user_id)
throws Matrix.Error;
public void set_display_name(API.Callback? cb, string user_name, string display_name)
throws Matrix.Error;
public void register_account(API.Callback? cb, AccountKind account_kind, bool bind_email, string? username, string password)
throws Matrix.Error;
public void set_account_data(API.Callback? cb, string user_id, string? room_id, string event_type, owned Json.Node content)
throws Matrix.Error;
public void get_room_tags(API.Callback? cb, string user_id, string room_id)
throws Matrix.Error;
public void delete_room_tag(API.Callback? cb, string user_id, string room_id, string tag)
throws Matrix.Error;
public void add_room_tag(API.Callback? cb, string user_id, string room_id, string tag, owned Json.Node? content)
throws Matrix.Error;
public void deactivate_account(API.Callback? cb, string? session, string? login_type)
throws Matrix.Error;
/* VoIP */
public void get_turn_server(API.Callback? cb)
throws Matrix.Error;
/* Non-spec methods */
public void abort_pending();
}
/** /**
* The major version number of the Matrix.org GLib SDK. * The major version number of the Matrix.org GLib SDK.
*/ */