22 Commits

Author SHA1 Message Date
dd6fd39ae3 First attempt to implement JsonSerializable 2018-05-10 14:17:09 +02:00
42d9ab7716 tmp 2018-05-10 14:17:09 +02:00
22fcbe1e31 Port _matrix_json_node_deep_copy() to C 2018-05-10 13:35:50 +02:00
da6e3f8b7b Port MatrixSearchCategories to C 2018-05-10 13:35:50 +02:00
3ffd5a5b38 Port MatrixSearchRoomEvents to C 2018-05-10 13:35:50 +02:00
01603d50e0 Upgrade _matrix_g_enum_to_string() so it can convert dashes to any character 2018-05-10 13:35:50 +02:00
5d0a0886e6 Port MatrixSearchGroupings to C 2018-05-10 13:35:50 +02:00
aeecc7a03d Upgrade free_str_array() so it can free any type of arrays 2018-05-10 13:35:50 +02:00
03625e8a8f Port MatrixSearchGrouping to C 2018-05-10 13:35:50 +02:00
1c14ad77ff Port MatrixEventContext to C 2018-05-10 13:35:50 +02:00
8f0f60e372 Port MatrixPusher to C 2018-05-10 13:35:50 +02:00
f4a8b47aa6 Port Matrix3PidCredential to C 2018-05-10 13:35:50 +02:00
80dad1b03a Port MatrixFilter to C 2018-05-10 13:35:50 +02:00
96e36f49e1 Port MatrixRoomFilter to C 2018-05-10 13:35:50 +02:00
2966b926c1 Port MatrixFilterRules to C 2018-05-10 13:35:50 +02:00
45066ff67e Port MatrixJsonCompact to C 2018-05-10 13:35:50 +02:00
b804d2d1c9 Port MatrixProfile to C 2018-05-10 13:35:50 +02:00
8fe499e967 Port MatrixVideoInfo to C 2018-05-10 13:35:50 +02:00
01a596a8c3 Port MatrixAudioInfo to C 2018-05-10 13:35:50 +02:00
d6ea38832f Port MatrixImageInfo to C 2018-05-10 13:35:50 +02:00
49a6d84a74 Port MatrixFileInfo to C 2018-05-10 13:35:50 +02:00
86147377d0 Port _g_enum_nick_to_value() to C 2018-05-10 13:35:49 +02:00
24 changed files with 5735 additions and 1453 deletions

3
.gitignore vendored
View File

@@ -49,10 +49,8 @@ Makefile.in
/src/matrix-glib.h /src/matrix-glib.h
/src/matrix-api.c /src/matrix-api.c
/src/matrix-client.c /src/matrix-client.c
/src/matrix-types.c
/src/matrix-http-api.c /src/matrix-http-api.c
/src/matrix-http-client.c /src/matrix-http-client.c
/src/matrix-compacts.c
/src/matrix-event-base.c /src/matrix-event-base.c
/src/matrix-event-presence.c /src/matrix-event-presence.c
/src/matrix-event-room-base.c /src/matrix-event-room-base.c
@@ -92,5 +90,4 @@ Makefile.in
/src/matrix-message-audio.c /src/matrix-message-audio.c
/src/matrix-message-video.c /src/matrix-message-video.c
/src/matrix-message-location.c /src/matrix-message-location.c
/src/matrix-profile.c
/src/matrix-room.c /src/matrix-room.c

View File

@@ -19,10 +19,8 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
namespace-info.vala \ namespace-info.vala \
matrix-api.vala \ matrix-api.vala \
matrix-client.vala \ matrix-client.vala \
matrix-types.vala \
matrix-http-api.vala \ matrix-http-api.vala \
matrix-http-client.vala \ matrix-http-client.vala \
matrix-compacts.vala \
matrix-event-base.vala \ matrix-event-base.vala \
matrix-event-room-base.vala \ matrix-event-room-base.vala \
matrix-event-state-base.vala \ matrix-event-state-base.vala \
@@ -59,7 +57,6 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
matrix-message-audio.vala \ matrix-message-audio.vala \
matrix-message-video.vala \ matrix-message-video.vala \
matrix-message-location.vala \ matrix-message-location.vala \
matrix-profile.vala \
matrix-room.vala \ matrix-room.vala \
$(NULL) $(NULL)
@@ -114,8 +111,10 @@ $(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c): vala-stamp
bin_PROGRAMS = test-api-client test-client bin_PROGRAMS = test-api-client test-client
INST_H_SRC_FILES = \ INST_H_SRC_FILES = \
matrix-c-types.h \ matrix-types.h \
matrix-compacts.h \
utils.h \ utils.h \
matrix-profile.h \
$(NULL) $(NULL)
INST_H_BUILT_FILES = \ INST_H_BUILT_FILES = \
@@ -125,7 +124,7 @@ INST_H_BUILT_FILES = \
$(NULL) $(NULL)
matrix_enum_headers = \ matrix_enum_headers = \
matrix-c-types.h \ matrix-types.h \
$(NULL) $(NULL)
libmatrix_glib_0_0_la_SOURCES = \ libmatrix_glib_0_0_la_SOURCES = \
@@ -134,7 +133,9 @@ libmatrix_glib_0_0_la_SOURCES = \
$(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c) \ $(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c) \
matrix-event-types.c \ matrix-event-types.c \
matrix-version.c \ matrix-version.c \
matrix-c-types.c \ matrix-types.c \
matrix-compacts.c \
matrix-profile.c \
utils.c \ utils.c \
matrix-enumtypes.c \ matrix-enumtypes.c \
$(INST_H_SRC_FILES) \ $(INST_H_SRC_FILES) \

View File

@@ -1,294 +0,0 @@
/*
* 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/>.
*/
#include "matrix-c-types.h"
/**
* SECTION:matrix-types
* @title: Generic types
* @short_description: Generic types for Matrix GLib SDK calls
*
* These are the generic types used by many SDK calls for communication with the homeserver.
*/
/**
* MatrixError:
* @MATRIX_ERROR_NONE: no error. You should never see this.
* @MATRIX_ERROR_COMMUNICATION_ERROR: there was a problem in communication (e.g. connection error)
* @MATRIX_ERROR_INCOMPLETE: the passed/generated data is incomplete
* @MATRIX_ERROR_BAD_REQUEST: the request is invalid
* @MATRIX_ERROR_BAD_RESPONSE: malformed response, or the response is not a JSON object
* @MATRIX_ERROR_INVALID_ROOM_ID: the provided string doesnt contain a valid room ID
* @MATRIX_ERROR_UNKNOWN_VALUE: the response from the Matrix.org server contains a value unknown
* to this library. These should be reported to the Matrix GLib SDK developers
* @MATRIX_ERROR_INVALID_TYPE: the provided type is invalid
* @MATRIX_ERROR_UNSUPPORTED: the operation is unsupported
* @MATRIX_ERROR_INVALID_FORMAT: the format of the JSON node is invalid (e.g. it is an array instead of an object)
* @MATRIX_ERROR_UNAVAILABLE: the requested data is not cached yet. Clients getting this message
* may go online by some means to get the data
* @MATRIX_ERROR_NOT_FOUND: the requested data (e.g. member of a room) can not be found
* @MATRIX_ERROR_ALREADY_EXISTS: the data to create (e.g. when adding a new member to a Room
* object) already exists
* @MATRIX_ERROR_M_MISSING_TOKEN: authorization token is missing from the request
* @MATRIX_ERROR_M_FORBIDDEN: access was forbidden (e.g. due to a missing/invalid token, or using
* a bad password during login)
* @MATRIX_ERROR_M_UNKNOWN: an error unknown to the Matrix homeserver
* @MATRIX_ERROR_M_UNKNOWN_TOKEN: the token provided is not known for the homeserver
* @MATRIX_ERROR_M_NOT_JSON: illegal request, the content is not valid JSON
* @MATRIX_ERROR_M_UNRECOGNIZED: the homeserver didn't understand the request
* @MATRIX_ERROR_M_UNAUTHORIZED: the request is unauthorized
* @MATRIX_ERROR_M_BAD_JSON: the JSON data is not in the required format
* @MATRIX_ERROR_M_USER_IN_USE: the specified username is in use
* @MATRIX_ERROR_M_ROOM_IN_USE: the specified room is in use
* @MATRIX_ERROR_M_BAD_PAGINATION: invalid pagination parameters
* @MATRIX_ERROR_M_BAD_STATE: invalid state event
* @MATRIX_ERROR_M_NOT_FOUND: the requested resource is not found
* @MATRIX_ERROR_M_GUEST_ACCESS_FORBIDDEN: guest access was requested, but ( it is forbidden
* @MATRIX_ERROR_M_LIMIT_EXCEEDED: the request was rate limited
* @MATRIX_ERROR_M_CAPTCHA_NEEDED: a captcha is needed to continue
* @MATRIX_ERROR_M_CAPTCHA_INVALID: the provided captcha is invalid
* @MATRIX_ERROR_M_MISSING_PARAM: a parameter is missing from the request
* @MATRIX_ERROR_M_TOO_LARGE: the request data is too large
* @MATRIX_ERROR_M_EXCLUSIVE: the desired user ID is in an exclusive namespace claimed by an
* application server
* @MATRIX_ERROR_M_THREEPID_AUTH_FAILED: 3rd party authentication failed
* @MATRIX_ERROR_M_THREEPID_IN_USE: the provided 3rd party ID is already in use
* @MATRIX_ERROR_M_INVALID_USERNAME: the given username is invalid
* @MATRIX_ERROR_UNSPECIFIED: no error code was sent by the homeserver. If you see this error,
* that usually indicates a homeserver bug
* @MATRIX_ERROR_UNKNOWN_ERROR: an error unknown to this library
*
* Matrix SDK error codes. The SDK maps most known error codes from homeservers, too; these are
* the MATRIX_ERROR_M_* codes.
*/
/**
* MATRIX_ERROR:
*
* Error domain for Matrix GLib SDK. See #GError for more information on error domains.
*/
/**
* matrix_error_quark:
*
* Gets the Matrix error #GQuark
*/
G_DEFINE_QUARK(matrix-error-quark, matrix_error);
/**
* MatrixAccountKind:
* @MATRIX_ACCOUNT_KIND_DEFAULT: use the server default (usually #MATRIX_ACCOUNT_KIND_USER)
* @MATRIX_ACCOUNT_KIND_USER: normal user
* @MATRIX_ACCOUNT_KIND_GUEST: guest user
*
* User account types.
*/
/**
* MatrixEventDirection:
* @MATRIX_EVENT_DIRECTION_FORWARD: list events after the specified one
* @MATRIX_EVENT_DIRECTION_BACKWARD: list events before the specified one
*
* Direction of events when requesting an event context.
*/
/**
* MatrixEventFormat:
* @MATRIX_EVENT_FORMAT_DEFAULT: event format will be omitted from the filter, so the server
* will use its default (usually #MATRIX_EVENT_FORMAT_FEDERATION)
* @MATRIX_EVENT_FORMAT_CLIENT: return the events in a format suitable for clients
* @MATRIX_EVENT_FORMAT_FEDERATION: return the raw event as receieved over federation
*
* Event format received when synchronizing.
*/
/**
* MatrixPresence:
* @MATRIX_PRESENCE_UNKNOWN: user's presence is unknown
* @MATRIX_PRESENCE_ONLINE: user is online
* @MATRIX_PRESENCE_OFFLINE: user is offline
* @MATRIX_PRESENCE_UNAVAILABLE: user is unavailable (i.e. busy)
* @MATRIX_PRESENCE_FREE_FOR_CHAT: user is free for chat
*
* Presence values for matrix_api_set_presence() and other presence related queries.
*/
/**
* MatrixPusherConditionKind:
* @MATRIX_PUSHER_CONDITION_KIND_EVENT_MATCH: glob pattern match on a field of the event.
* Requires a `key` and a `pattern` parameter
* @MATRIX_PUSHER_CONDITION_KIND_PROFILE_TAG: matches the profile tag of the device that the
* notification would be delivered to. Requires a `profile_tag` parameter
* @MATRIX_PUSHER_CONDITION_KIND_CONTAINS_DISPLAY_NAME: matches unencrypted messages where the
* content's body contains the owner's display name in that room.
* @MATRIX_PUSHER_CONDITION_KIND_ROOM_MEMBER_COUNT: matches the current number of members in the
* room. Requires an `is` parameter, which must be an integer, optionally prefixed by `==`,
* `<`, `>`, `<=` or `>=`. If the prefix is omitted, it defaults to `==`
*
* Condition types for pushers.
*/
/**
* MatrixPusherKind:
* @MATRIX_PUSHER_KIND_OVERRIDE: highest priority rules
* @MATRIX_PUSHER_KIND_SENDER: for (unencrypted) messages that match certain patterns
* @MATRIX_PUSHER_KIND_ROOM: for all messages for a given room. The rule ID of a room rule is
* always the ID of the room that it affects
* @MATRIX_PUSHER_KIND_CONTENT: for messages from a specific Matrix user ID. The rule ID of such
* rules is always the Matrix ID of the user whose messages they'd apply to
* @MATRIX_PUSHER_KIND_UNDERRIDE: lowest priority rules
*
* Pusher types.
*/
/**
* MatrixReceiptType:
* @MATRIX_RECEIPT_TYPE_READ: indicate that the message has been read
*
* Receipt types of acknowledgment.
*/
/**
* MatrixResizeMethod:
* @MATRIX_RESIZE_METHOD_DEFAULT: use the server default value
* @MATRIX_RESIZE_METHOD_CROP: crop thumbnail to the requested size
* @MATRIX_RESIZE_METHOD_SCALE: scale thumbnail to the requested size
*
* Resizing methods for matrix_api_media_thumbnail().
*/
/**
* MatrixRoomMembership:
* @MATRIX_ROOM_MEMBERSHIP_UNKNOWN: the membership sent by the server is unknown to this SDK
* @MATRIX_ROOM_MEMBERSHIP_INVITE: the user has been invited to join a room, but has not yet
* joined it. They may not participate in the room until they join
* @MATRIX_ROOM_MEMBERSHIP_JOIN: the user has joined the room (possibly after accepting an invite),
* and may participate in it
* @MATRIX_ROOM_MEMBERSHIP_LEAVE: the user was once joined to the room, but has since left
* (possibly by choice, or possibly by being kicked)
* @MATRIX_ROOM_MEMBERSHIP_BAN: the user has been banned from the room, and is no longer allowed
* to join it until they are un-banned from the room (by having their membership state set
* to a value other than MATRIX_ROOM_MEMBERSHIP_BAN)
* @MATRIX_ROOM_MEMBERSHIP_KNOCK: this is a reserved word, which currently has no meaning
*
* Room membership types.
*/
/**
* MatrixRoomPreset:
* @MATRIX_ROOM_PRESET_NONE: no preset
* @MATRIX_ROOM_PRESET_PRIVATE: preset for private rooms
* @MATRIX_ROOM_PRESET_TRUSTED_PRIVATE: same as private rooms, but all users get the same power
* level as the room creator
* @MATRIX_ROOM_PRESET_PUBLIC: preset for public rooms
*
* Preset values for matrix_api_create_room() calls.
*/
/**
* MatrixRoomVisibility:
* @MATRIX_ROOM_VISIBILITY_DEFAULT: use a server-assigned value (usually
* #MATRIX_ROOM_VISIBILITY_PRIVATE)
* @MATRIX_ROOM_VISIBILITY_PUBLIC: make the room visible in the public room list
* @MATRIX_ROOM_VISIBILITY_PRIVATE: hide the room from the public room list
*
* Visibility values for room creation. Not to be confused with join rules.
*/
/**
* MatrixJoinRules:
* @MATRIX_JOIN_RULES_UNKNOWN: a value unknown to this library
* @MATRIX_JOIN_RULES_PUBLIC: anyone can join
* @MATRIX_JOIN_RULES_INVITE: users may join upon invite
* @MATRIX_JOIN_RULES_PRIVATE: reserved word, not usable yet
* @MATRIX_JOIN_RULES_KNOCK: reserved word, not usable yet
*
* Room join rules.
*/
/**
* MatrixSearchOrder:
* @MATRIX_SEARCH_ORDER_RECENT: order messages as they arrived
* @MATRIX_SEARCH_ORDER_RANK: order messages by relevance
*
* Search ordering.
*/
/**
* MatrixSearchKey:
* @MATRIX_SEARCH_KEY_CONTENT_BODY: search in the body of a message
* @MATRIX_SEARCH_KEY_CONTENT_NAME: search in the name of rooms
* @MATRIX_SEARCH_KEY_CONTENT_TOPIC: search in the topic of rooms
*
* Search keys.
*/
/**
* MatrixSearchGroupBy:
* @MATRIX_SEARCH_GROUP_BY_NONE: no grouping
* @MATRIX_SEARCH_GROUP_BY_ROOM_ID: group by room ID
* @MATRIX_SEARCH_GROUP_BY_SENDER: group by sender
*
* Search grouping
*
* The client can request that the results are returned along with
* grouping information, e.g. grouped by room_id. In this case the
* response will contain a group entry for each distinct value of
* room_id. Each group entry contains at least a list of the
* event_ids that are in that group, as well as potentially other
* metadata about the group.
*/
/**
* MatrixHistoryVisibility:
* @MATRIX_HISTORY_VISIBILITY_UNKNOWN: represents a value unknown to this library
* @MATRIX_HISTORY_VISIBILITY_INVITED: only room members can see the room history, and only what
* happened after they got an invitation
* @MATRIX_HISTORY_VISIBILITY_JOINED: only room members can see the room history, and only what
* happened after they joined
* @MATRIX_HISTORY_VISIBILITY_SHARED: only room members can see the room history, but they see all
* of it
* @MATRIX_HISTORY_VISIBILITY_WORLD_READABLE: anyone can see the room history
*
* Room history visibility
*/
/**
* MatrixGuestAccess:
* @MATRIX_GUEST_ACCESS_UNKNOWN: represents a value unknown to this library
* @MATRIX_GUEST_ACCESS_CAN_JOIN: guest users are allowed to access the room
* @MATRIX_GUEST_ACCESS_FORBIDDEN: guest users are not allowed to access the room
*
* Room guest access
*/
/**
* MatrixCallOfferType:
* @MATRIX_CALL_OFFER_TYPE_UNKNOWN: represents a value unknown to this library
* @MATRIX_CALL_OFFER_TYPE_OFFER: call offer
*
* Call offer types
*/
/**
* MatrixCallAnswerType:
* @MATRIX_CALL_ANSWER_TYPE_UNKNOWN: represents a value unknown to this library
* @MATRIX_CALL_ANSWER_TYPE_ANSWER: call answer
*
* Call answer types
*/

3093
src/matrix-compacts.c Normal file

File diff suppressed because it is too large Load Diff

236
src/matrix-compacts.h Normal file
View File

@@ -0,0 +1,236 @@
/*
* 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_COMPACTS_H__
# define __MATRIX_GLIB_SDK_COMPACTS_H__
# include <glib-object.h>
# include <json-glib/json-glib.h>
# include "matrix-types.h"
G_BEGIN_DECLS
# define MATRIX_TYPE_JSON_COMPACT matrix_json_compact_get_type()
# define MATRIX_JSON_COMPACT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), MATRIX_TYPE_JSON_COMPACT, MatrixJsonCompact))
# define MATRIX_JSON_COMPACT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST((c), MATRIX_TYPE_JSON_COMPACT, MatrixJsonCompactClass))
# define MATRIX_IS_JSON_COMPACT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), MATRIX_TYPE_JSON_COMPACT))
# define MATRIX_IS_JSON_COMPACT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE((c), MATRIX_TYPE_JSON_COMPACT))
# define MATRIX_JSON_COMPACT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), MATRIX_TYPE_JSON_COMPACT, MatrixJsonCompactClass))
typedef struct _MatrixJsonCompactClass MatrixJsonCompactClass;
typedef struct _MatrixJsonCompact MatrixJsonCompact;
void matrix_json_compact_unref(MatrixJsonCompact *json_compact);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(MatrixJsonCompact, matrix_json_compact_unref)
struct _MatrixJsonCompact {
GTypeInstance parent_instance;
/* < private > */
volatile int refcount;
};
struct _MatrixJsonCompactClass {
GTypeClass parent_class;
void (*finalize)(MatrixJsonCompact *json_compact);
JsonNode *(*get_json_node)(MatrixJsonCompact *json_compact, GError **error);
};
GType matrix_json_compact_get_type(void) G_GNUC_CONST;
MatrixJsonCompact *matrix_json_compact_construct(GType object_type);
MatrixJsonCompact *matrix_json_compact_ref(MatrixJsonCompact *json_compact);
JsonNode *matrix_json_compact_get_json_node(MatrixJsonCompact *json_compact, GError **error);
gchar *matrix_json_compact_get_json_data(MatrixJsonCompact *json_compact, gsize *datalen, GError **error);
#define MATRIX_TYPE_FILTER_RULES matrix_filter_rules_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixFilterRules, matrix_filter_rules, MATRIX, FILTER_RULES, MatrixJsonCompact)
struct _MatrixFilterRulesClass {
MatrixJsonCompactClass parent_class;
};
MatrixFilterRules *matrix_filter_rules_new(void);
MatrixFilterRules *matrix_filter_rules_construct(GType object_type);
void matrix_filter_rules_set_limit(MatrixFilterRules *filter_rules, guint limit);
guint matrix_filter_rules_get_limit(MatrixFilterRules *filter_rules);
void matrix_filter_rules_set_types(MatrixFilterRules *filter_rules, gchar **types, int n_types);
gchar **matrix_filter_rules_get_types(MatrixFilterRules *filter_rules, int *n_types);
void matrix_filter_rules_set_excluded_types(MatrixFilterRules *filter_rules, gchar **excluded_types, int n_excluded_types);
gchar **matrix_filter_rules_get_excluded_types(MatrixFilterRules *filter_rules, int *n_excluded_types);
void matrix_filter_rules_set_senders(MatrixFilterRules *filter_rules, gchar **senders, int n_senders);
gchar **matrix_filter_rules_get_senders(MatrixFilterRules *filter_rules, int *n_senders);
void matrix_filter_rules_set_excluded_senders(MatrixFilterRules *filter_rules, gchar **excluded_senders, int n_excluded_senders);
gchar **matrix_filter_rules_get_excluded_senders(MatrixFilterRules *filter_rules, int *n_excluded_senders);
void matrix_filter_rules_set_rooms(MatrixFilterRules *filter_rules, gchar **rooms, int n_rooms);
gchar **matrix_filter_rules_get_rooms(MatrixFilterRules *filter_rules, int *n_rooms);
void matrix_filter_rules_set_excluded_rooms(MatrixFilterRules *filter_rules, gchar **excluded_rooms, int n_excluded_rooms);
gchar **matrix_filter_rules_get_excluded_rooms(MatrixFilterRules *filter_rules, int *n_excluded_rooms);
# define MATRIX_TYPE_ROOM_FILTER matrix_room_filter_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixRoomFilter, matrix_room_filter, MATRIX, ROOM_FILTER, MatrixJsonCompact)
struct _MatrixRoomFilterClass {
MatrixJsonCompactClass parent_class;
};
MatrixRoomFilter *matrix_room_filter_new(void);
gboolean matrix_room_filter_get_include_leave(MatrixRoomFilter *room_filter);
void matrix_room_filter_set_include_leave(MatrixRoomFilter *room_filter, gboolean include_leave);
MatrixFilterRules *matrix_room_filter_get_ephemeral(MatrixRoomFilter *room_filter);
void matrix_room_filter_set_ephemeral(MatrixRoomFilter *room_filter, MatrixFilterRules *ephemeral_rules);
MatrixFilterRules *matrix_room_filter_get_state(MatrixRoomFilter *room_filter);
void matrix_room_filter_set_state(MatrixRoomFilter *room_filter, MatrixFilterRules *state_rules);
MatrixFilterRules *matrix_room_filter_get_timeline(MatrixRoomFilter *room_filter);
void matrix_room_filter_set_timeline(MatrixRoomFilter *room_filter, MatrixFilterRules *timeline_rules);
# define MATRIX_TYPE_FILTER matrix_filter_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixFilter, matrix_filter, MATRIX, FILTER, MatrixJsonCompact)
struct _MatrixFilterClass {
MatrixJsonCompactClass parent_class;
};
MatrixFilter *matrix_filter_new(void);
gchar **matrix_filter_get_event_fields(MatrixFilter *filter, int *n_event_fields);
void matrix_filter_set_event_fields(MatrixFilter *filter, gchar **event_fields, int n_event_fields);
MatrixEventFormat matrix_filter_get_event_format(MatrixFilter *filter);
void matrix_filter_set_event_format(MatrixFilter *filter, MatrixEventFormat event_format);
MatrixFilterRules *matrix_filter_get_presence_filter(MatrixFilter *filter);
void matrix_filter_set_presence_filter(MatrixFilter *filter, MatrixFilterRules *presence_filter);
MatrixRoomFilter *matrix_filter_get_room_filter(MatrixFilter *filter);
void matrix_filter_set_room_filter(MatrixFilter *filter, MatrixRoomFilter *room_filter);
# define MATRIX_TYPE_3PID_CREDENTIAL matrix_3pid_credential_get_type()
G_DECLARE_DERIVABLE_TYPE(Matrix3PidCredential, matrix_3pid_credential, MATRIX, 3PID_CREDENTIAL, MatrixJsonCompact)
struct _Matrix3PidCredentialClass {
MatrixJsonCompactClass parent_class;
};
Matrix3PidCredential *matrix_3pid_credential_new(void);
const gchar *matrix_3pid_credential_get_id_server(Matrix3PidCredential *credential);
void matrix_3pid_credential_set_id_server(Matrix3PidCredential *credential, const gchar *id_server);
const gchar *matrix_3pid_credential_get_session_id(Matrix3PidCredential *credential);
void matrix_3pid_credential_set_session_id(Matrix3PidCredential *credential, const gchar *session_id);
const gchar *matrix_3pid_credential_get_client_secret(Matrix3PidCredential *credential);
void matrix_3pid_credential_set_client_secret(Matrix3PidCredential *credential, const gchar *client_secret);
# define MATRIX_TYPE_PUSHER matrix_pusher_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixPusher, matrix_pusher, MATRIX, PUSHER, MatrixJsonCompact)
struct _MatrixPusherClass {
MatrixJsonCompactClass parent_class;
};
MatrixPusher *matrix_pusher_new(void);
const gchar *matrix_pusher_get_device_display_name(MatrixPusher *pusher);
void matrix_pusher_set_device_display_name(MatrixPusher *pusher, const gchar *device_display_name);
const gchar *matrix_pusher_get_app_display_name(MatrixPusher *pusher);
void matrix_pusher_set_app_display_name(MatrixPusher *pusher, const gchar *app_display_name);
const gchar *matrix_pusher_get_app_id(MatrixPusher *pusher);
void matrix_pusher_set_app_id(MatrixPusher *pusher, const gchar *app_id);
gboolean matrix_pusher_get_append(MatrixPusher *pusher);
void matrix_pusher_set_append(MatrixPusher *pusher, gboolean append);
const gchar *matrix_pusher_get_kind(MatrixPusher *pusher);
void matrix_pusher_set_kind(MatrixPusher *pusher, const gchar *kind);
const gchar *matrix_pusher_get_lang(MatrixPusher *pusher);
void matrix_pusher_set_lang(MatrixPusher *pusher, const gchar *lang);
const gchar *matrix_pusher_get_profile_tag(MatrixPusher *pusher);
void matrix_pusher_set_profile_tag(MatrixPusher *pusher, const gchar *profile_tag);
const gchar *matrix_pusher_get_pushkey(MatrixPusher *pusher);
void matrix_pusher_set_pushkey(MatrixPusher *pusher, const gchar *pushkey);
JsonNode *matrix_pusher_get_data(MatrixPusher *pusher);
void matrix_pusher_set_data(MatrixPusher *pusher, JsonNode *data);
# define MATRIX_TYPE_EVENT_CONTEXT matrix_event_context_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixEventContext, matrix_event_context, MATRIX, EVENT_CONTEXT, MatrixJsonCompact)
struct _MatrixEventContextClass {
MatrixJsonCompactClass parent_class;
};
MatrixEventContext *matrix_event_context_new (void);
gint matrix_event_context_get_before_limit (MatrixEventContext *event_context);
void matrix_event_context_set_before_limit (MatrixEventContext *event_context, gint before_limit);
gint matrix_event_context_get_after_limit (MatrixEventContext *event_context);
void matrix_event_context_set_after_limit (MatrixEventContext *event_context, gint after_limit);
gboolean matrix_event_context_get_include_profile (MatrixEventContext *event_context);
void matrix_event_context_set_include_profile (MatrixEventContext *event_context, gboolean include_profile);
# define MATRIX_TYPE_SEARCH_GROUPING matrix_search_grouping_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixSearchGrouping, matrix_search_grouping, MATRIX, SEARCH_GROUPING, MatrixJsonCompact)
struct _MatrixSearchGroupingClass {
MatrixJsonCompactClass parent_class;
};
MatrixSearchGrouping *matrix_search_grouping_new(void);
MatrixSearchGroupBy matrix_search_grouping_get_key(MatrixSearchGrouping *search_grouping);
void matrix_search_grouping_set_key(MatrixSearchGrouping *search_grouping, MatrixSearchGroupBy key);
# define MATRIX_TYPE_SEARCH_GROUPINGS matrix_search_groupings_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixSearchGroupings, matrix_search_groupings, MATRIX, SEARCH_GROUPINGS, MatrixJsonCompact)
struct _MatrixSearchGroupingsClass {
MatrixJsonCompactClass parent_class;
};
MatrixSearchGroupings *matrix_search_groupings_new(void);
MatrixSearchGrouping **matrix_search_groupings_get_group_by(MatrixSearchGroupings *search_groupings, int *n_group_by);
void matrix_search_groupings_set_group_by(MatrixSearchGroupings *search_groupings, MatrixSearchGrouping **group_by, int n_group_by);
# define MATRIX_TYPE_SEARCH_ROOM_EVENTS matrix_search_room_events_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixSearchRoomEvents, matrix_search_room_events, MATRIX, SEARCH_ROOM_EVENTS, MatrixJsonCompact)
struct _MatrixSearchRoomEventsClass {
MatrixJsonCompactClass parent_class;
};
MatrixSearchRoomEvents *matrix_search_room_events_new(void);
MatrixSearchOrder matrix_search_room_events_get_order_by(MatrixSearchRoomEvents *search_room_events);
void matrix_search_room_events_set_order_by(MatrixSearchRoomEvents *search_room_events, MatrixSearchOrder order_by);
MatrixSearchKey *matrix_search_room_events_get_keys(MatrixSearchRoomEvents *search_room_events, guint *n_keys);
void matrix_search_room_events_set_keys(MatrixSearchRoomEvents *search_room_events, MatrixSearchKey *keys, guint n_keys);
MatrixEventContext *matrix_search_room_events_get_event_context(MatrixSearchRoomEvents *search_room_events);
void matrix_search_room_events_set_event_context(MatrixSearchRoomEvents *search_room_events, MatrixEventContext *event_context);
gboolean matrix_search_room_events_get_include_state(MatrixSearchRoomEvents *search_room_events);
void matrix_search_room_events_set_include_state(MatrixSearchRoomEvents *search_room_events, gboolean include_state);
const gchar *matrix_search_room_events_get_filter_id(MatrixSearchRoomEvents *search_room_events);
void matrix_search_room_events_set_filter_id(MatrixSearchRoomEvents *search_room_events, const gchar *filter_id);
MatrixFilter *matrix_search_room_events_get_filter(MatrixSearchRoomEvents *search_room_events);
void matrix_search_room_events_set_filter(MatrixSearchRoomEvents *search_room_events, MatrixFilter *filter);
const gchar *matrix_search_room_events_get_search_term(MatrixSearchRoomEvents *search_room_events);
void matrix_search_room_events_set_search_term(MatrixSearchRoomEvents *search_room_events, const gchar *search_term);
MatrixSearchGroupings *matrix_search_room_events_get_groupings(MatrixSearchRoomEvents *search_room_events);
void matrix_search_room_events_set_groupings(MatrixSearchRoomEvents *search_room_events, MatrixSearchGroupings *groupings);
# define MATRIX_TYPE_SEARCH_CATEGORIES matrix_search_categories_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixSearchCategories, matrix_search_categories, MATRIX, SEARCH_CATEGORIES, MatrixJsonCompact)
struct _MatrixSearchCategoriesClass {
MatrixJsonCompactClass parent_class;
};
MatrixSearchCategories *matrix_search_categories_new(void);
MatrixSearchRoomEvents *matrix_search_categories_get_room_events(MatrixSearchCategories *search_categories);
void matrix_search_categories_set_room_events(MatrixSearchCategories *search_categories, MatrixSearchRoomEvents *room_events);
G_END_DECLS
#endif /* __MATRIX_GLIB_SDK_COMPACTS_H__ */

View File

@@ -1,725 +0,0 @@
/*
* 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/>.
*/
namespace Matrix {
/**
* Abstract parent class for classes that can be saved to JSON.
*/
public abstract class JsonCompact {
public abstract Json.Node?
get_json_node()
throws Matrix.Error;
public string
get_json_data(out size_t datalen)
throws Matrix.Error
{
var generator = new Json.Generator();
generator.set_root(get_json_node());
return generator.to_data(out datalen);
}
}
/**
* Class to hold a filter.
*/
public class Filter : JsonCompact {
/**
* The event fields to include in the filtered events.
*/
public string[] event_fields { get; set; }
/**
* The desired event format for the filtered events (e.g. for
* matrix_api_sync())
*/
public EventFormat event_format {
get; set;
default = Matrix.EventFormat.CLIENT;
}
/**
* A filtering ruleset for presence events.
*/
public FilterRules? presence_filter { get; set; default = null; }
/**
* A filtering ruleset for room events.
*/
public RoomFilter? room_filter { get; set; default = null; }
/**
* Get the filter as a JSON node.
*/
public override Json.Node?
get_json_node()
throws Matrix.Error
{
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("event_fields");
builder.begin_array();
foreach (var entry in event_fields) {
builder.add_string_value(entry);
}
builder.end_array();
builder.set_member_name("event_format");
builder.add_string_value(
_g_enum_value_to_nick(typeof(EventFormat), event_format));
builder.set_member_name("presence");
builder.add_value(presence_filter.get_json_node());
builder.set_member_name("room");
builder.add_value(room_filter.get_json_node());
builder.end_object();
return builder.get_root();
}
}
/**
* Class to hold room filters.
*/
public class RoomFilter : JsonCompact {
/**
* If {{{true}}}, events for rooms that the user has left will
* be included in the filtered event list.
*/
public bool include_leave { get; set; default=true; }
/**
* Filtering rules for ephemeral events, i.e. events that are
* not recorded in the room history (typing notifications,
* receipts, etc.)
*/
public FilterRules? ephemeral { get; set; default = null; }
/**
* Filtering rules for state events.
*/
public FilterRules? state { get; set; default = null; }
/**
* Filtering rules for timeline events.
*/
public FilterRules? timeline { get; set; default = null; }
/**
* Get the room filters as a JSON node.
*/
public override Json.Node?
get_json_node()
throws Matrix.Error
{
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("include_leave");
builder.add_boolean_value(include_leave);
if (ephemeral != null) {
builder.set_member_name("ephemeral");
builder.add_value(ephemeral.get_json_node());
}
if (state != null) {
builder.set_member_name("state");
builder.add_value(state.get_json_node());
}
if (timeline != null) {
builder.set_member_name("timeline");
builder.add_value(timeline.get_json_node());
}
builder.end_object();
return builder.get_root();
}
}
/**
* Class to hold filtering rules.
*/
public class FilterRules : JsonCompact {
/**
* The limit of the count of returned events.
*/
public uint limit { get; set; }
/**
* List of message types to include in the filtered result.
*/
public string[] types { get; set; }
/**
* List of message types to exclude from the filtered
* result. A matching type will be excluded from the result
* even if it is listed in the types to include.
*/
public string[] excluded_types { get; set; }
/**
* List of senders to include in the filtered results.
*/
public string[] senders { get; set; }
/**
* List of senders to exclude from the filtered result. A
* matching sender will be excluded from the result even if it
* is listed in the senders to include.
*/
public string[] excluded_senders { get; set; }
/**
* List of rooms to include in the filtered results.
*/
public string[] rooms { get; set; }
/**
* List of rooms to exclude from the filtered result. A
* matching room will be excluded from the result even if it
* is listed in the rooms to include.
*/
public string[] excluded_rooms { get; set; }
/**
* Get the filtering rules as a JSON node.
*/
public override Json.Node?
get_json_node()
throws Matrix.Error
{
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("limit");
builder.add_int_value(limit);
if (rooms != null) {
builder.set_member_name("rooms");
builder.begin_array();
foreach (var entry in rooms) {
builder.add_string_value(entry);
}
builder.end_array();
}
if (excluded_rooms != null) {
builder.set_member_name("not_rooms");
builder.begin_array();
foreach (var entry in excluded_rooms) {
builder.add_string_value(entry);
}
builder.end_array();
}
if (senders != null) {
builder.set_member_name("senders");
builder.begin_array();
foreach (var entry in senders) {
builder.add_string_value(entry);
}
builder.end_array();
}
if (excluded_senders != null) {
builder.set_member_name("not_senders");
builder.begin_array();
foreach (var entry in excluded_senders) {
builder.add_string_value(entry);
}
builder.end_array();
}
if (types != null) {
builder.set_member_name("types");
builder.begin_array();
foreach (var entry in types) {
builder.add_string_value(entry);
}
builder.end_array();
}
if (excluded_types != null) {
builder.set_member_name("not_types");
builder.begin_array();
foreach(var entry in types) {
builder.add_string_value(entry);
}
builder.end_array();
}
builder.end_object();
return builder.get_root();
}
}
/**
* Class to hold 3rd party credential related data.
*/
public class @3PidCredential : JsonCompact {
/**
* The Identity Server used for this credential.
*/
public string? id_server { get; set; default = null; }
/**
* The session identifier got from the Identity Server.
*/
public string? session_id { get; set; default = null; }
/**
* The client secret that was used in the session with the
* Identity Server.
*/
public string? client_secret { get; set; default = null; }
/**
* Get 3rd party credential related data as a JSON node.
*/
public override Json.Node?
get_json_node()
throws Matrix.Error
{
if ((id_server == null)
|| (session_id == null)
|| (client_secret == null))
{
throw new Matrix.Error.INCOMPLETE(
"All fields of a 3PID credential must be filled!");
}
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("id_server");
builder.add_string_value(id_server);
builder.set_member_name("session_id");
builder.add_string_value(session_id);
builder.set_member_name("client_secret");
builder.add_string_value(client_secret);
builder.end_object();
return builder.get_root();
}
}
/**
* Class to hold pusher related data.
*/
public class Pusher : JsonCompact {
/**
* A device display name.
*/
public string? device_display_name { get; set; default = null; }
/**
* An application display name.
*/
public string? app_display_name { get; set; default = null; }
/**
* An application ID.
*/
public string? app_id { get; set; default = null; }
/**
* If {{{true}}}, the homeserver should add another pusher
* with the given push key and app ID in addition to any
* others with different user IDs. Otherwise, the homeserver
* must remove any other pushers with the same App ID and
* pushkey for different users.
*/
public bool append { get; set; default = true; }
/**
* The kind of the pusher. {{{http}}} makes a pusher that
* sends HTTP pokes. {{{null}}} deletes the pusher.
*/
public string? kind { get; set; default = null; }
/**
* The preferred language for receiving notifications,
* e.g. {{{en}}} or {{{en-US}}}.
*/
public string? lang { get; set; default = null; }
/**
* A string that determines what set of device rules will be
* matched when evaluating push rules for this pusher. It is
* an arbitrary string. Multiple devices may use the same
* profile tag. It is advised that when an app's data is
* copied or restored to a different device, this value remain
* the same. Client apps should offer ways to change the
* profile tag, optionally copying rules from the old profile
* tag. Maximum length is 32 bytes. If the profile tag is
* longer than this, it will be truncated
*/
public string? profile_tag { get; set; default = null; }
/**
* A unique identifier for this pusher. The value you should
* use for this is the routing or destination address
* information for the notification, for example, the APNS
* token for APNS or the Registration ID for GCM. If your
* notification client has no such concept, use any unique
* identifier. Maximum length is 512 bytes. If pushkey is
* longer than this, it will be truncated
*/
public string? pushkey { get; set; default = null; }
/**
* a dictionary of information for the pusher implementation
* itself. For example, if kind is {{{http}}}, this should
* contain an {{{url}}} member, which is the URL to use to
* send notifications to. This function creates a deep copy of
* the data, so it can be freed after this call.
*/
public Json.Node? data { get; set; default = null; }
/**
* Get the pusher data as a JSON node.
*/
public override Json.Node?
get_json_node()
throws Matrix.Error
{
if ((device_display_name == null)
|| (app_display_name == null)
|| (app_id == null)
|| (data == null)
|| (kind == null)
|| (lang == null)
|| (profile_tag == null)
|| (pushkey == null)) {
throw new Matrix.Error.INCOMPLETE("Pusher data incomplete");
}
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("device_display_name");
builder.add_string_value(device_display_name);
builder.set_member_name("app_display_name");
builder.add_string_value(app_display_name);
builder.set_member_name("app_id");
builder.add_string_value(app_id);
builder.set_member_name("append");
builder.add_boolean_value(append);
builder.set_member_name("kind");
builder.add_string_value(kind);
builder.set_member_name("lang");
builder.add_string_value(lang);
builder.set_member_name("profile_tag");
builder.add_string_value(profile_tag);
builder.set_member_name("pushkey");
builder.add_string_value(pushkey);
builder.set_member_name("data");
builder.add_value(data);
builder.end_object();
return builder.get_root();
}
}
public class EventContext : JsonCompact {
public int before_limit { get; set; default = -1; }
public int after_limit { get; set; default = -1; }
public bool include_profile { get; set; default = false; }
public override Json.Node?
get_json_node()
throws Matrix.Error
{
var builder = new Json.Builder();
builder.begin_object();
if (before_limit >= 0) {
builder.set_member_name("before_limit");
builder.add_int_value(before_limit);
}
if (after_limit >= 0) {
builder.set_member_name("after_limit");
builder.add_int_value(after_limit);
}
builder.set_member_name("include_profile");
builder.add_boolean_value(include_profile);
builder.end_object();
return builder.get_root();
}
}
public class SearchGrouping : JsonCompact {
public SearchGroupBy key { get; set; default = SearchGroupBy.NONE; }
public override Json.Node?
get_json_node()
throws Matrix.Error
{
if (key == SearchGroupBy.NONE) {
return null;
}
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("key");
builder.add_string_value(
_g_enum_value_to_nick(typeof(SearchGroupBy), key, true));
builder.end_object();
return builder.get_root();
}
}
public class SearchGroupings : JsonCompact {
public SearchGrouping[] group_by { get; set; }
public override Json.Node?
get_json_node()
throws Matrix.Error
{
if (group_by == null) {
return null;
}
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("group_by");
builder.begin_array();
int count = 0;
foreach (var entry in group_by) {
var node = entry.get_json_node();
if (node != null) {
count++;
builder.add_value(node);
}
}
if (count == 0) {
return null;
}
builder.end_array();
builder.end_object();
return builder.get_root();
}
}
public class SearchRoomEvents : JsonCompact {
public SearchOrder order_by { get; set; default = SearchOrder.RECENT; }
public SearchKey[] keys { get; set; }
public EventContext? event_context { get; set; default = null; }
public bool include_state { get; set; default = false; }
public string? filter_id { get; set; default = null; }
public Filter? filter { get; set; default = null; }
public string search_term { get; set; }
public SearchGroupings? groupings { get; set; default = null; }
public override Json.Node?
get_json_node()
throws Matrix.Error
{
Json.Node? node = null;
var builder = new Json.Builder();
if ((filter_id != null) && (filter != null)) {
throw new Matrix.Error.INCOMPLETE(
"filter and filter_id is exclusive to each other");
}
builder.begin_object();
builder.set_member_name("order_by");
builder.add_string_value(
_g_enum_value_to_nick(typeof(SearchOrder), order_by));
if (keys.length > 0) {
EnumClass key_class = (EnumClass)(typeof(SearchKey).class_ref());
var key_array = new Json.Array();
foreach (var entry in keys) {
unowned EnumValue? key_value = key_class.get_value(entry);
if (key_value != null) {
key_array.add_string_element(
key_value.value_nick.replace("-", "."));
}
}
if (key_array.get_length() > 0) {
node = new Json.Node(Json.NodeType.ARRAY);
node.set_array(key_array);
builder.set_member_name("keys");
builder.add_value(node);
}
}
if ((event_context != null)
&& ((node = event_context.get_json_node()) != null)) {
builder.set_member_name("event_context");
builder.add_value(node);
}
builder.set_member_name("include_state");
builder.add_boolean_value(include_state);
if ((filter != null)
&& ((node = filter.get_json_node()) != null)) {
builder.set_member_name("filter");
builder.add_value(node);
}
if (filter_id != null) {
builder.set_member_name("filter");
builder.add_string_value(filter_id);
}
builder.set_member_name("search_term");
builder.add_string_value(search_term);
if ((groupings != null)
&& ((node = groupings.get_json_node()) != null)) {
builder.set_member_name("groupings");
builder.add_value(node);
}
builder.end_object();
return builder.get_root();
}
}
public class SearchCategories : JsonCompact {
public SearchRoomEvents? room_events { get; set; default = null; }
public override Json.Node?
get_json_node()
throws Matrix.Error
{
Json.Node? node = null;
if ((room_events == null)
&& ((node = room_events.get_json_node()) != null)) {
return null;
}
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("room_events");
builder.add_value(node);
builder.end_object();
return builder.get_root();
}
}
public Json.Node?
_json_node_deep_copy(Json.Node? node)
{
Json.Node ret;
if (node == null) {
return null;
}
ret = new Json.Node(node.get_node_type());
switch (node.get_node_type()) {
case Json.NodeType.OBJECT:
var new_obj = new Json.Object();
node.get_object().foreach_member(
(old_obj, member_name, member_node) => {
new_obj.set_member(
member_name,
_json_node_deep_copy(member_node));
});
ret.set_object(new_obj);
break;
case Json.NodeType.ARRAY:
var new_ary = new Json.Array();
node.get_array().foreach_element(
(old_ary, idx, element_node) => {
new_ary.add_element(
_json_node_deep_copy(element_node));
});
break;
case Json.NodeType.VALUE:
ret.set_value(node.get_value());
break;
case Json.NodeType.NULL:
break;
}
return ret;
}
}

View File

@@ -19,7 +19,9 @@
/** /**
* Base class for Matrix events. * Base class for Matrix events.
*/ */
public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable { public abstract class Matrix.Event.Base : GLib.Object,
GLib.Initable,
Json.Serializable {
private Error? _construct_error = null; private Error? _construct_error = null;
private bool _inited = false; private bool _inited = false;
private Json.Node? _json; private Json.Node? _json;
@@ -77,6 +79,8 @@ public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable {
} }
} }
// Implementation of GLib.Initable
public bool public bool
init(GLib.Cancellable? cancellable = null) init(GLib.Cancellable? cancellable = null)
throws Error, Matrix.Error throws Error, Matrix.Error
@@ -95,6 +99,39 @@ public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable {
return true; return true;
} }
// Implementation of Json.Serializable
public unowned ParamSpec
find_property(string name)
{
return get_class().find_property(name);
}
public Json.Node
serialize_property(string property_name,
Value value,
ParamSpec pspec)
{
return default_serialize_property(property_name, value, pspec);
}
public bool
deserialize_property(string property_name,
out Value value,
ParamSpec pspec,
Json.Node property_node)
{
value = Value(pspec.value_type);
return default_deserialize_property(property_name,
value,
pspec,
property_node);
}
// Own methods
private void private void
initialize_from_json(Json.Node json_data) initialize_from_json(Json.Node json_data)
throws Matrix.Error throws Matrix.Error

View File

@@ -42,12 +42,10 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Call {
var answer_root = node.get_object(); var answer_root = node.get_object();
if ((node = answer_root.get_member("type")) != null) { if ((node = answer_root.get_member("type")) != null) {
CallAnswerType? typ = (CallAnswerType?)_g_enum_nick_to_value( try {
_answer_type = (CallAnswerType)_g_enum_nick_to_value(
typeof(CallAnswerType), node.get_string()); typeof(CallAnswerType), node.get_string());
} catch (Matrix.Error e) {
if (typ != null) {
_answer_type = typ;
} else {
_answer_type = CallAnswerType.UNKNOWN; _answer_type = CallAnswerType.UNKNOWN;
if (Config.DEBUG) { if (Config.DEBUG) {

View File

@@ -50,12 +50,10 @@ public class Matrix.Event.CallInvite : Matrix.Event.Call {
var offer_node = node.get_object(); var offer_node = node.get_object();
if ((node = offer_node.get_member("type")) != null) { if ((node = offer_node.get_member("type")) != null) {
CallOfferType? typ = (CallOfferType?)_g_enum_nick_to_value( try {
_offer_type = (CallOfferType)_g_enum_nick_to_value(
typeof(CallOfferType), node.get_string()); typeof(CallOfferType), node.get_string());
} catch (Matrix.Error e) {
if (typ != null) {
_offer_type = typ;
} else {
_offer_type = CallOfferType.UNKNOWN; _offer_type = CallOfferType.UNKNOWN;
if (Config.DEBUG) { if (Config.DEBUG) {

View File

@@ -95,12 +95,10 @@ public class Matrix.Event.Presence : Matrix.Event.Base {
} }
if ((node = content_root.get_member("presence")) != null) { if ((node = content_root.get_member("presence")) != null) {
Matrix.Presence? pres = (Matrix.Presence?)_g_enum_nick_to_value( try {
_presence = (Matrix.Presence)_g_enum_nick_to_value(
typeof(Matrix.Presence), node.get_string()); typeof(Matrix.Presence), node.get_string());
} catch (Matrix.Error e) {
if (pres != null) {
_presence = pres;
} else {
_presence = Matrix.Presence.UNKNOWN; _presence = Matrix.Presence.UNKNOWN;
if (Config.DEBUG) { if (Config.DEBUG) {

View File

@@ -48,12 +48,10 @@ public class Matrix.Event.RoomGuestAccess : Matrix.Event.State {
} }
if ((node = content_root.get_member("guest_access")) != null) { if ((node = content_root.get_member("guest_access")) != null) {
GuestAccess? rules = (GuestAccess?)_g_enum_nick_to_value( try {
_guest_access = (GuestAccess)_g_enum_nick_to_value(
typeof(GuestAccess), node.get_string()); typeof(GuestAccess), node.get_string());
} catch (Matrix.Error e) {
if (rules != null) {
_guest_access = rules;
} else {
_guest_access = GuestAccess.UNKNOWN; _guest_access = GuestAccess.UNKNOWN;
if (Config.DEBUG) { if (Config.DEBUG) {

View File

@@ -47,13 +47,10 @@ public class Matrix.Event.RoomHistoryVisibility : Matrix.Event.State {
} }
if ((node = content_root.get_member("history_visibility")) != null) { if ((node = content_root.get_member("history_visibility")) != null) {
Matrix.HistoryVisibility? vis = (Matrix.HistoryVisibility?)_g_enum_nick_to_value( try {
typeof(Matrix.HistoryVisibility), _visibility = (Matrix.HistoryVisibility)_g_enum_nick_to_value(
node.get_string()); typeof(Matrix.HistoryVisibility), node.get_string());
} catch (Matrix.Error e) {
if (vis != null) {
_visibility = vis;
} else {
_visibility = Matrix.HistoryVisibility.UNKNOWN; _visibility = Matrix.HistoryVisibility.UNKNOWN;
if (Config.DEBUG) { if (Config.DEBUG) {

View File

@@ -43,12 +43,10 @@ public class Matrix.Event.RoomJoinRules : Matrix.Event.State {
} }
if ((node = content_root.get_member("join_rule")) != null) { if ((node = content_root.get_member("join_rule")) != null) {
Matrix.JoinRules? rules = (Matrix.JoinRules)_g_enum_nick_to_value( try {
typeof(Matrix.JoinRules), node.get_string()); _join_rules = (JoinRules)_g_enum_nick_to_value(
typeof(JoinRules), node.get_string());
if (rules != null) { } catch (Matrix.Error e) {
_join_rules = rules;
} else {
_join_rules = Matrix.JoinRules.UNKNOWN; _join_rules = Matrix.JoinRules.UNKNOWN;
if (Config.DEBUG) { if (Config.DEBUG) {

View File

@@ -138,12 +138,15 @@ public class Matrix.Event.RoomMember : Matrix.Event.State {
} }
if ((node = content_root.get_member("membership")) != null) { if ((node = content_root.get_member("membership")) != null) {
Matrix.RoomMembership? mship = (Matrix.RoomMembership?)_g_enum_nick_to_value( try {
typeof(Matrix.RoomMembership), _membership = (Matrix.RoomMembership)_g_enum_nick_to_value(
node.get_string()); typeof(Matrix.RoomMembership), node.get_string());
} catch (Matrix.Error e) {
_membership = Matrix.RoomMembership.UNKNOWN;
if (mship != null) { if (Config.DEBUG) {
_membership = mship; warning("Unknown membership value %s", node.get_string());
}
} }
} else if (Config.DEBUG) { } else if (Config.DEBUG) {
warning("membership key is missing from the m.room.member event"); warning("membership key is missing from the m.room.member event");

315
src/matrix-profile.c Normal file
View File

@@ -0,0 +1,315 @@
/*
* 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/>.
*/
#include "matrix-profile.h"
#include <stdlib.h>
#include <string.h>
// List of object properties
enum {
PROP_NONE,
PROP_AGE,
PROP_DISPLAY_NAME,
PROP_AVATAR_URL,
NUM_PROPERTIES
};
typedef struct {
GDateTime* last_update;
gchar* display_name;
gchar* _avatar_url;
} MatrixProfilePrivate;
G_DEFINE_TYPE(MatrixProfile, matrix_profile, G_TYPE_OBJECT);
static GParamSpec* matrix_profile_properties[NUM_PROPERTIES];
/**
* matrix_profile_new:
*
* Create a new #MatrixProfile object.
*
* Returns: (transfer full): a new #MatrixProfile object
*/
MatrixProfile *
matrix_profile_new (void)
{
return (MatrixProfile *)g_object_new(MATRIX_TYPE_PROFILE, NULL);
}
/**
* matrix_profile_get_age:
* @profile: a #MatrixProfile
*
* Get the age of the profile.
*
* Returns: the profile age, in seconds
*/
GTimeSpan
matrix_profile_get_age (MatrixProfile *matrix_profile)
{
GTimeSpan result;
GDateTime* utcnow;
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
if (G_UNLIKELY(matrix_profile == NULL)) {
return (GTimeSpan)0;
}
utcnow = g_date_time_new_now_utc ();
result = g_date_time_difference (utcnow, priv->last_update);
g_date_time_unref(utcnow);
return result;
}
/**
* matrix_profile_get_display_name:
* @profile: a #MatrixProfile
*
* Get the display name from @profile.
*
* The returned value is owned by @profile and should not be modified.
*
* Returns: (transfer none) (nullable): a display name
*/
const gchar*
matrix_profile_get_display_name (MatrixProfile *matrix_profile)
{
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
if (G_UNLIKELY(matrix_profile == NULL)) {
return NULL;
}
return priv->display_name;
}
/**
* matrix_profile_set_display_name:
* @profile: a #MatrixProfile
* @display_name: (transfer none) (nullable): a display name
*
* Set the display name in @profile.
*/
void
matrix_profile_set_display_name (MatrixProfile *matrix_profile, const gchar* display_name)
{
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
if (G_UNLIKELY(matrix_profile == NULL)) {
return;
}
g_free(priv->display_name);
priv->display_name = g_strdup (display_name);
g_date_time_unref(priv->last_update);
priv->last_update = g_date_time_new_now_utc ();
g_object_notify_by_pspec((GObject *)matrix_profile,
matrix_profile_properties[PROP_DISPLAY_NAME]);
}
/**
* matrix_profile_get_avatar_url:
* @profile: a #MatrixProfile
*
* Get the avatar URL from @profile.
*
* The returned value is owned by @profile and should not be freed.
*
* Returns: (transfer none) (nullable): an avatar URL
*/
const gchar *
matrix_profile_get_avatar_url (MatrixProfile *matrix_profile)
{
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
if (G_UNLIKELY(matrix_profile == NULL)) {
return NULL;
}
return priv->_avatar_url;
}
/**
* matrix_profile_set_avatar_url:
* @profile: a #MatrixProfile
* @avatar_url: (transfer none) (nullable): the URL to the avatar
*
* Set the avatar URL in @profile.
*/
void
matrix_profile_set_avatar_url (MatrixProfile *matrix_profile, const gchar* avatar_url)
{
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
if (G_UNLIKELY(matrix_profile == NULL)) {
return;
}
g_free(priv->_avatar_url);
priv->_avatar_url = g_strdup (avatar_url);
g_date_time_unref(priv->last_update);
priv->last_update = g_date_time_new_now_utc ();
g_object_notify_by_pspec ((GObject *)matrix_profile,
matrix_profile_properties[PROP_AVATAR_URL]);
}
static void
matrix_profile_finalize(GObject *gobject)
{
MatrixProfile *matrix_profile;
MatrixProfilePrivate *priv;
matrix_profile = G_TYPE_CHECK_INSTANCE_CAST(gobject, MATRIX_TYPE_PROFILE, MatrixProfile);
priv = matrix_profile_get_instance_private(matrix_profile);
g_date_time_unref(priv->last_update);
g_free(priv->display_name);
g_free(priv->_avatar_url);
priv->last_update = NULL;
priv->display_name = NULL;
priv->_avatar_url = NULL;
G_OBJECT_CLASS (matrix_profile_parent_class)->finalize(gobject);
}
static void
matrix_profile_get_property (GObject *gobject, guint property_id, GValue *value, GParamSpec *pspec)
{
MatrixProfile *matrix_profile;
matrix_profile = G_TYPE_CHECK_INSTANCE_CAST(gobject, MATRIX_TYPE_PROFILE, MatrixProfile);
switch (property_id) {
case PROP_AGE:
g_value_set_int64 (value, matrix_profile_get_age (matrix_profile));
break;
case PROP_DISPLAY_NAME:
g_value_set_string (value, matrix_profile_get_display_name (matrix_profile));
break;
case PROP_AVATAR_URL:
g_value_set_string(value, matrix_profile_get_avatar_url (matrix_profile));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
break;
}
}
static void
matrix_profile_set_property(GObject *gobject,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
MatrixProfile *matrix_profile;
matrix_profile = G_TYPE_CHECK_INSTANCE_CAST(gobject, MATRIX_TYPE_PROFILE, MatrixProfile);
switch (property_id) {
case PROP_DISPLAY_NAME:
matrix_profile_set_display_name(matrix_profile, g_value_get_string(value));
break;
case PROP_AVATAR_URL:
matrix_profile_set_avatar_url(matrix_profile, g_value_get_string(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
break;
}
}
static void
matrix_profile_class_init(MatrixProfileClass *klass)
{
matrix_profile_parent_class = g_type_class_peek_parent(klass);
G_OBJECT_CLASS(klass)->get_property = matrix_profile_get_property;
G_OBJECT_CLASS(klass)->set_property = matrix_profile_set_property;
G_OBJECT_CLASS(klass)->finalize = matrix_profile_finalize;
/**
* MatrixProfile:age:
*
* The age of the profile, in seconds.
*/
matrix_profile_properties[PROP_AGE] = g_param_spec_int64(
"age", "Age",
"Age of the profile",
0, G_MAXINT64, 0,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
g_object_class_install_property(
G_OBJECT_CLASS (klass),
PROP_AGE,
matrix_profile_properties[PROP_AGE]);
/**
* MatrixProfile:display-name:
*
* The display name of the user in this profile.
*/
matrix_profile_properties[PROP_DISPLAY_NAME] = g_param_spec_string(
"display-name", "display-name",
"The human readable name of the usser",
NULL,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
g_object_class_install_property(
G_OBJECT_CLASS(klass),
PROP_DISPLAY_NAME,
matrix_profile_properties[PROP_DISPLAY_NAME]);
/**
* MatrixProfile:avatar-url:
*
* The avatar URL in this profile.
*/
matrix_profile_properties[PROP_AVATAR_URL] = g_param_spec_string (
"avatar-url", "avatar-url",
"The URL of the user's avatar",
NULL,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
g_object_class_install_property(
G_OBJECT_CLASS (klass),
PROP_AVATAR_URL,
matrix_profile_properties[PROP_AVATAR_URL]);
}
static void
matrix_profile_init(MatrixProfile *matrix_profile)
{
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
priv->display_name = NULL;
priv->_avatar_url = NULL;
matrix_profile_set_display_name(matrix_profile, NULL);
matrix_profile_set_avatar_url(matrix_profile, NULL);
}

45
src/matrix-profile.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* 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_PROFILE_H__
# define __MATRIX_GLIB_SDK_PROFILE_H__
# include <glib-object.h>
G_BEGIN_DECLS
# define MATRIX_TYPE_PROFILE matrix_profile_get_type()
G_DECLARE_DERIVABLE_TYPE(MatrixProfile, matrix_profile, MATRIX, PROFILE, GObject)
struct _MatrixProfileClass {
GObjectClass parent_class;
/* < private > */
gpointer padding[12];
};
MatrixProfile *matrix_profile_new(void);
GTimeSpan matrix_profile_get_age (MatrixProfile *profile);
const gchar *matrix_profile_get_avatar_url(MatrixProfile *profile);
void matrix_profile_set_avatar_url(MatrixProfile *profile, const gchar *avatar_url);
const gchar *matrix_profile_get_display_name(MatrixProfile *profile);
void matrix_profile_set_display_name(MatrixProfile *profile, const gchar *display_name);
G_END_DECLS
#endif /* __MATRIX_GLIB_SDK_PROFILE_H__ */

View File

@@ -1,65 +0,0 @@
/*
* 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/>.
*/
/**
* Object to hold a user's profile
*
* This object is used for both global and room specific profiles.
*/
public class Matrix.Profile : Object {
public TimeSpan age {
get {
return new DateTime.now_utc().difference(_last_update);
}
}
/**
* The human readable name of the user.
*/
public string? display_name {
get {
return _display_name;
}
set {
_display_name = value;
_last_update = new DateTime.now_utc();
}
default = null;
}
/**
* The URL of the user's avatar.
*/
public string? avatar_url {
get {
return _avatar_url;
}
set {
_avatar_url = value;
_last_update = new DateTime.now_utc();
}
default = null;
}
private DateTime _last_update;
private string? _display_name = null;
private string? _avatar_url = null;
}

View File

@@ -25,8 +25,12 @@
public class Matrix.Room : GLib.Object { public class Matrix.Room : GLib.Object {
/** /**
* The ID of the room this object belongs to. * The ID of the room this object belongs to.
*
* If this property is null, then this object is acting as a
* temporary stash for another room object, which is used when
* calculating state events to be sent by apply_changes().
*/ */
public string room_id { get; construct; } public string? room_id { get; construct; }
/** /**
* All the known room aliases. * All the known room aliases.
@@ -155,13 +159,22 @@ public class Matrix.Room : GLib.Object {
private HashTable<string, MemberData?> _members = private HashTable<string, MemberData?> _members =
new HashTable<string, MemberData?>(str_hash, str_equal); new HashTable<string, MemberData?>(str_hash, str_equal);
private Room _stash = null;
/** /**
* Create a new Room object. * Create a new Room object.
*
* @param room_id the ID of the room this object belongs to. For
* null values, see remark at the room_id property.
*/ */
public public
Room(string room_id) Room(string? room_id)
{ {
Object(room_id : room_id); Object(room_id : room_id);
if (room_id != null) {
_stash = new Room(null);
}
} }
/** /**
@@ -344,4 +357,26 @@ public class Matrix.Room : GLib.Object {
{ {
return _event_levels[event_type]; return _event_levels[event_type];
} }
/**
* Generate a set of events that can change the room state on the
* home server similar to what this object shows.
*/
public void
apply_changes()
{
Matrix.Event.Base[] ret = {};
foreach (var to_add in _aliases) {
if (!(to_add in _stash._aliases)) {
// add alias
}
}
foreach (var to_remove in _stash._aliases) {
if (!(to_remove in _aliases)) {
// remove alias
}
}
}
} }

1514
src/matrix-types.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,7 @@
# define __MATRIX_TYPE_H__ # define __MATRIX_TYPE_H__
# include <glib-object.h> # include <glib-object.h>
# include <json-glib/json-glib.h>
typedef enum { typedef enum {
MATRIX_ERROR_NONE, MATRIX_ERROR_NONE,
@@ -195,4 +196,81 @@ typedef enum {
MATRIX_CALL_ANSWER_TYPE_ANSWER MATRIX_CALL_ANSWER_TYPE_ANSWER
} MatrixCallAnswerType; } MatrixCallAnswerType;
typedef struct _MatrixFileInfo MatrixFileInfo;
GType matrix_file_info_get_type(void);
# define MATRIX_TYPE_FILE_INFO matrix_file_info_get_type()
MatrixFileInfo *matrix_file_info_new(void);
MatrixFileInfo *matrix_file_info_ref(MatrixFileInfo *file_info);
void matrix_file_info_unref(MatrixFileInfo *file_info);
void matrix_file_info_set_size(MatrixFileInfo *file_info, gssize size);
gssize matrix_file_info_get_size(MatrixFileInfo *file_info);
void matrix_file_info_set_mimetype(MatrixFileInfo *file_info, const gchar *mimetype);
const gchar *matrix_file_info_get_mimetype(MatrixFileInfo *file_info);
void matrix_file_info_set_from_json(MatrixFileInfo *file_info, JsonNode *json_data);
JsonNode *matrix_file_info_get_json_node(MatrixFileInfo *file_info, GError **error);
typedef struct _MatrixAudioInfo MatrixAudioInfo;
GType matrix_audio_info_get_type(void);
# define MATRIX_TYPE_AUDIO_INFO matrix_audio_info_get_type()
MatrixAudioInfo *matrix_audio_info_new(void);
MatrixAudioInfo *matrix_audio_info_ref(MatrixAudioInfo *audio_info);
void matrix_audio_info_unref(MatrixAudioInfo *audio_info);
void matrix_audio_info_set_size(MatrixAudioInfo *audio_info, gssize size);
gssize matrix_audio_info_get_size(MatrixAudioInfo *audio_info);
void matrix_audio_info_set_mimetype(MatrixAudioInfo *audio_info, const gchar *mimetype);
const gchar *matrix_audio_info_get_mimetype(MatrixAudioInfo *audio_info);
void matrix_audio_info_set_duration(MatrixAudioInfo *audio_info, gint duration);
gint matrix_audio_info_get_duration(MatrixAudioInfo *audio_info);
void matrix_audio_info_set_from_json(MatrixAudioInfo *audio_info, JsonNode *json_data);
JsonNode *matrix_audio_info_get_json_node(MatrixAudioInfo *audio_info, GError **error);
typedef struct _MatrixImageInfo MatrixImageInfo;
GType matrix_image_info_get_type(void);
# define MATRIX_TYPE_IMAGE_INFO matrix_image_info_get_type()
MatrixImageInfo *matrix_image_info_new(void);
MatrixImageInfo *matrix_image_info_ref(MatrixImageInfo *image_info);
void matrix_image_info_unref(MatrixImageInfo *image_info);
void matrix_image_info_set_size(MatrixImageInfo *image_info, gssize size);
gssize matrix_image_info_get_size(MatrixImageInfo *image_info);
void matrix_image_info_set_height(MatrixImageInfo *image_info, gint height);
gint matrix_image_info_get_height(MatrixImageInfo *image_info);
void matrix_image_info_set_width(MatrixImageInfo *image_info, gint width);
gint matrix_image_info_get_width(MatrixImageInfo *image_info);
void matrix_image_info_set_mimetype(MatrixImageInfo *image_info, const gchar *mimetype);
const gchar *matrix_image_info_get_mimetype(MatrixImageInfo *image_info);
void matrix_image_info_set_from_json(MatrixImageInfo *image_info, JsonNode *json_data);
JsonNode *matrix_image_info_get_json_node(MatrixImageInfo *image_info, GError **error);
gboolean matrix_image_info_differs(MatrixImageInfo *image_info, MatrixImageInfo *other);
typedef struct _MatrixVideoInfo MatrixVideoInfo;
GType matrix_video_info_get_type(void) G_GNUC_CONST;
# define MATRIX_TYPE_VIDEO_INFO matrix_video_info_get_type()
MatrixVideoInfo *matrix_video_info_new(void);
MatrixVideoInfo *matrix_video_info_ref(MatrixVideoInfo *video_info);
void matrix_video_info_unref(MatrixVideoInfo *video_info);
void matrix_video_info_set_size(MatrixVideoInfo *video_info, gsize size);
gsize matrix_video_info_get_size(MatrixVideoInfo *video_info);
void matrix_video_info_set_mimetype(MatrixVideoInfo *video_info, const gchar *mimetype);
const gchar *matrix_video_info_get_mimetype(MatrixVideoInfo *video_info);
void matrix_video_info_set_duration(MatrixVideoInfo *video_info, gint duration);
gint matrix_video_info_get_duration(MatrixVideoInfo *video_info);
void matrix_video_info_set_width(MatrixVideoInfo *video_info, gint width);
gint matrix_video_info_get_width(MatrixVideoInfo *video_info);
void matrix_video_info_set_height(MatrixVideoInfo *video_info, gint height);
gint matrix_video_info_get_height(MatrixVideoInfo *video_info);
void matrix_video_info_set_thumbnail_url(MatrixVideoInfo *video_info, const gchar *thumbnail_url);
const gchar *matrix_video_info_get_thumbnail_url(MatrixVideoInfo *video_info);
void matrix_video_info_set_thumbnail_info(MatrixVideoInfo *video_info, const MatrixImageInfo *thumbnail_info);
const MatrixImageInfo *matrix_video_info_get_thumbnail_info(MatrixVideoInfo *video_info);
void matrix_video_info_set_from_json(MatrixVideoInfo *video_info, JsonNode *json_data);
JsonNode *matrix_video_info_get_json_node(MatrixVideoInfo *video_info, GError **error);
#endif /* __MATRIX_TYPE_H__ */ #endif /* __MATRIX_TYPE_H__ */

View File

@@ -1,311 +0,0 @@
/*
* 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/>.
*/
namespace Matrix {
/**
* Information about the file referred to in a URL.
*/
public struct FileInfo {
int? size;
string? mimetype;
public void
set_from_json(Json.Node json_data)
{
size = null;
mimetype = null;
var root = json_data.get_object();
Json.Node? node;
if ((node = root.get_member("size")) != null) {
size = (int)node.get_int();
} else if (Config.DEBUG) {
warning("size is missing from a FileInfo");
}
if ((node = root.get_member("mimetype")) != null) {
mimetype = node.get_string();
} else if (Config.DEBUG) {
warning("mimetype is missing from a FileInfo");
}
}
public Json.Node
get_json_node()
throws Matrix.Error
{
if ((size == null)
|| (mimetype == null)) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate a FileInfo without all fields set.");
}
var node = new Json.Node(Json.NodeType.OBJECT);
var obj = new Json.Object();
node.set_object(obj);
obj.set_int_member("size", size);
obj.set_string_member("mimetype", mimetype);
return node;
}
}
public struct ImageInfo {
int? size;
int? height;
int? width;
string? mimetype;
public void
set_from_json(Json.Node json_data)
{
size = null;
mimetype = null;
height = null;
width = null;
var root = json_data.get_object();
Json.Node? node;
if ((node = root.get_member("w")) != null) {
width = (int)node.get_int();
} else if (Config.DEBUG) {
warning("w is missing from an ImageInfo");
}
if ((node = root.get_member("h")) != null) {
height = (int)node.get_int();
} else if (Config.DEBUG) {
warning("h is missing from an ImageInfo");
}
if ((node = root.get_member("size")) != null) {
size = (int)node.get_int();
} else if (Config.DEBUG) {
warning("size is missing from an ImageInfo");
}
if ((node = root.get_member("mimetype")) != null) {
mimetype = node.get_string();
} else if (Config.DEBUG) {
warning("mimetype is missing from an ImageInfo");
}
}
public Json.Node
get_json_node()
throws Matrix.Error
{
if ((size == null)
|| (height == null)
|| (width == null)
|| (mimetype == null)) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate an ImageInfo without all fields set.");
}
var node = new Json.Node(Json.NodeType.OBJECT);
var obj = new Json.Object();
node.set_object(obj);
obj.set_int_member("size", size);
obj.set_int_member("h", height);
obj.set_int_member("w", width);
obj.set_string_member("mimetype", mimetype);
return node;
}
/**
* Check if two ImageInfo objects are identical.
*
* @param other the ImageInfo object to compare with
* @return true if the two objects hold different values
*/
public bool
differs(ImageInfo other)
{
return ((size != other.size)
|| (height != other.height)
|| (width != other.width)
|| (mimetype != other.mimetype));
}
}
public struct AudioInfo {
int? size;
string? mimetype;
int? duration;
public void
set_from_json(Json.Node json_data)
{
size = null;
mimetype = null;
duration = null;
var root = json_data.get_object();
Json.Node? node;
if ((node = root.get_member("size")) != null) {
size = (int)node.get_int();
} else if (Config.DEBUG) {
warning("size is missing from an ImageInfo");
}
if ((node = root.get_member("mimetype")) != null) {
mimetype = node.get_string();
} else if (Config.DEBUG) {
warning("mimetype is missing from an ImageInfo");
}
if ((node = root.get_member("duration")) != null) {
duration = (int)node.get_int();
} else if (Config.DEBUG) {
warning("duration is missing from an ImageInfo");
}
}
public Json.Node
get_json_node()
throws Matrix.Error
{
if ((size == null)
|| (mimetype == null)
|| (duration == null)) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate an ImageInfo without all fields set.");
}
var node = new Json.Node(Json.NodeType.OBJECT);
var obj = new Json.Object();
node.set_object(obj);
obj.set_int_member("size", size);
obj.set_string_member("mimetype", mimetype);
obj.set_int_member("duration", duration);
return node;
}
}
public struct VideoInfo {
int? size;
string? mimetype;
int? duration;
int? width;
int? height;
string? thumbnail_url;
ImageInfo? thumbnail_info;
public void
set_from_json(Json.Node json_data)
{
size = null;
mimetype = null;
duration = null;
var root = json_data.get_object();
Json.Node? node;
if ((node = root.get_member("size")) != null) {
size = (int)node.get_int();
} else if (Config.DEBUG) {
warning("size is missing from an VideoInfo");
}
if ((node = root.get_member("mimetype")) != null) {
mimetype = node.get_string();
} else if (Config.DEBUG) {
warning("mimetype is missing from an VideoInfo");
}
if ((node = root.get_member("duration")) != null) {
duration = (int)node.get_int();
} else if (Config.DEBUG) {
warning("duration is missing from an VideoInfo");
}
if ((node = root.get_member("w")) != null) {
width = (int)node.get_int();
} else if (Config.DEBUG) {
warning("w is missing from a VideoInfo");
}
if ((node = root.get_member("h")) != null) {
height = (int)node.get_int();
} else if (Config.DEBUG) {
warning("h is missing from a VideoInfo");
}
if ((node = root.get_member("thumbnail_url")) != null) {
thumbnail_url = node.get_string();
}
if ((node = root.get_member("thumbnail_info")) != null) {
thumbnail_info = ImageInfo();
thumbnail_info.set_from_json(node);
}
}
public Json.Node
get_json_node()
throws Matrix.Error
{
if ((size == null)
|| (mimetype == null)
|| (duration == null)
|| (width == null)
|| (height == null)
|| (thumbnail_url == null)
|| (thumbnail_info == null)) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate an ImageInfo without all fields set.");
}
var node = new Json.Node(Json.NodeType.OBJECT);
var obj = new Json.Object();
node.set_object(obj);
obj.set_int_member("size", size);
obj.set_string_member("mimetype", mimetype);
obj.set_int_member("duration", duration);
obj.set_int_member("w", width);
obj.set_int_member("h", height);
obj.set_string_member("thumbnail_url", thumbnail_url);
obj.set_member("thumbnail_info", thumbnail_info.get_json_node());
return node;
}
}
private int?
_g_enum_nick_to_value(Type enum_type, string nick)
{
EnumClass enum_class = (EnumClass)enum_type.class_ref();
unowned EnumValue? enum_val = enum_class.get_value_by_nick(nick);
if (enum_val != null) {
return enum_val.value;
} else {
return null;
}
}
}

View File

@@ -17,6 +17,7 @@
*/ */
#include "utils.h" #include "utils.h"
#include "matrix-types.h"
// GTK-Doc looking comments in this file intentionally do not begin with a double star, as the // GTK-Doc looking comments in this file intentionally do not begin with a double star, as the
// functions here are internal // functions here are internal
@@ -34,7 +35,7 @@
* Returns: (transfer full) the converted enum name, which must be freed * Returns: (transfer full) the converted enum name, which must be freed
*/ */
gchar * gchar *
_matrix_g_enum_to_string(GType enum_type, gint value, gboolean convert_dashes) _matrix_g_enum_to_string(GType enum_type, gint value, gchar convert_dashes)
{ {
GEnumClass *enum_class = g_type_class_ref(enum_type); GEnumClass *enum_class = g_type_class_ref(enum_type);
GEnumValue *enum_value = g_enum_get_value(enum_class, value); GEnumValue *enum_value = g_enum_get_value(enum_class, value);
@@ -48,7 +49,7 @@ _matrix_g_enum_to_string(GType enum_type, gint value, gboolean convert_dashes)
for (a = nick; *a; a++) { for (a = nick; *a; a++) {
if (*a == '-') { if (*a == '-') {
*a = '_'; *a = convert_dashes;
} }
} }
} }
@@ -58,3 +59,118 @@ _matrix_g_enum_to_string(GType enum_type, gint value, gboolean convert_dashes)
return nick; return nick;
} }
/*
* _matrix_g_enum_nick_to_value:
*
* @enum_type: a #GEnumType
* @nick: a value nick registered in @enum_type
* @error: a #GError, or NULL to ignore errors
*
* Get the integer value of the enum nick @nick from @enum_type. If the nick contains underscores
* (`_`), they will be converted to dashes (`-`) first.
*
* If @nick cannot be found in @enum_type, this function returns NULL, and sets @error to
* #MATRIX_ERROR_UNKNOWN_VALUE.
*
* Returns: the integer value of @nick, or 0 if not found
*/
gint
_matrix_g_enum_nick_to_value(GType enum_type, const gchar *nick, GError **error)
{
GEnumClass *enum_class = g_type_class_ref(enum_type);
GEnumValue *enum_value;
gchar *nick_c = NULL;
gchar *a;
gint ret = 0;
nick_c = g_strdup(nick);
for (a = nick_c; *a; a++) {
if (*a == '_') {
*a = '-';
}
}
enum_value = g_enum_get_value_by_nick(enum_class, nick_c);
g_free(nick_c);
if (enum_value) {
ret = enum_value->value;
} else {
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_UNKNOWN_VALUE,
"Value %s is unknown", nick);
}
g_type_class_unref(enum_class);
return ret;
}
static void
_copy_obj_member(JsonObject *old_obj, const gchar *member_name, JsonNode *member_node, gpointer user_data)
{
JsonObject *new_obj = user_data;
json_object_set_member(new_obj, member_name, _matrix_json_node_deep_copy(member_node));
}
static void
_copy_ary_member(JsonArray *old_ary, guint idx, JsonNode *element_node, gpointer user_data)
{
JsonArray *new_ary = user_data;
json_array_add_element(new_ary, _matrix_json_node_deep_copy(element_node));
}
JsonNode *
_matrix_json_node_deep_copy(JsonNode *node)
{
JsonNode *ret;
JsonNodeType node_type;
g_return_val_if_fail(node != NULL, NULL);
node_type = json_node_get_node_type(node);
ret = json_node_new(node_type);
switch (node_type) {
case JSON_NODE_OBJECT:
{
JsonObject *new_obj = json_object_new();
JsonObject *old_obj = json_node_get_object(node);
json_object_foreach_member(old_obj, _copy_obj_member, new_obj);
json_node_set_object(ret, new_obj);
break;
}
case JSON_NODE_ARRAY:
{
JsonArray *new_ary = json_array_new();
JsonArray *old_ary = json_node_get_array(node);
json_array_foreach_element(old_ary, _copy_ary_member, new_ary);
json_node_set_array(ret, new_ary);
break;
}
case JSON_NODE_VALUE:
{
GValue node_value = G_VALUE_INIT;
json_node_get_value(node, &node_value);
json_node_set_value(ret, &node_value);
g_value_unset(&node_value);
break;
}
case JSON_NODE_NULL:
break;
}
return ret;
}

View File

@@ -20,10 +20,13 @@
# define __MATRIX_GLIB_SDK_UTILS_H__ # define __MATRIX_GLIB_SDK_UTILS_H__
# include <glib-object.h> # include <glib-object.h>
# include <json-glib/json-glib.h>
G_BEGIN_DECLS G_BEGIN_DECLS
gchar *_matrix_g_enum_to_string(GType enum_type, gint value, gboolean convert_dashes); gchar *_matrix_g_enum_to_string(GType enum_type, gint value, gchar convert_dashes);
gint _matrix_g_enum_nick_to_value(GType enum_type, const gchar *nick, GError **error);
JsonNode *_matrix_json_node_deep_copy(JsonNode *node);
G_END_DECLS G_END_DECLS

View File

@@ -204,9 +204,226 @@ namespace Matrix {
ANSWER; ANSWER;
} }
[CCode (cheader_filename = "matrix-types.h")]
public struct FileInfo {
public void set_size(ssize size);
public ssize get_size();
public void set_mimetype(string? mimetype);
public string? get_mimetype();
public void set_from_json(Json.Node json_data);
public Json.Node get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-types.h")]
public struct AudioInfo {
public ssize get_size();
public void set_size(ssize size);
public string? get_mimetype();
public void set_mimetype(string? mimetype);
public int get_duration();
public void set_duration(int duration);
public void set_from_json(Json.Node json_data);
public Json.Node get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-types.h")]
public struct ImageInfo {
public ssize get_size();
public void set_size(ssize size);
public int get_height();
public void set_height(int height);
public int get_width();
public void set_width(int width);
string? mimetype;
public void set_from_json(Json.Node json_data);
public Json.Node get_json_node()
throws Matrix.Error;
public bool differs(ImageInfo other);
}
[CCode (cheader_filename = "matrix-types.h")]
public struct VideoInfo {
public ssize get_size();
public void set_size(ssize size);
public string? get_mimetype();
public void set_mimetype(string? mimetype);
public int get_duration();
public void set_duration(int duration);
public int get_width();
public void set_width(int witdh);
public int get_height();
public void set_height(int height);
public string? get_thumbnail_url();
public void set_thumbnail_url();
public ImageInfo? get_thumbnail_info();
public void set_image_info(ImageInfo? image_info);
public void
set_from_json(Json.Node json_data);
public Json.Node
get_json_node()
throws Matrix.Error;
}
/* Compact classes */
[CCode (cheader_filename = "matrix-compacts.h")]
public abstract class JsonCompact {
public JsonCompact();
public abstract Json.Node? get_json_node()
throws Matrix.Error;
public string get_json_data(out size_t datalen)
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class FilterRules : JsonCompact {
public uint limit { get; set; }
public string[] types { get; set; }
public string[] excluded_types { get; set; }
public string[] senders { get; set; }
public string[] excluded_senders { get; set; }
public string[] rooms { get; set; }
public string[] excluded_rooms { get; set; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class RoomFilter : JsonCompact {
public bool include_leave { get; set; default=true; }
public FilterRules? ephemeral { get; set; default = null; }
public FilterRules? state { get; set; default = null; }
public FilterRules? timeline { get; set; default = null; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class Filter : JsonCompact {
public string[] event_fields { get; set; }
public EventFormat event_format { get; set; default = Matrix.EventFormat.CLIENT; }
public FilterRules? presence_filter { get; set; default = null; }
public RoomFilter? room_filter { get; set; default = null; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class @3PidCredential : JsonCompact {
public string? id_server { get; set; default = null; }
public string? session_id { get; set; default = null; }
public string? client_secret { get; set; default = null; }
public override Json.Node?
get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class Pusher : JsonCompact {
public string? device_display_name { get; set; default = null; }
public string? app_display_name { get; set; default = null; }
public string? app_id { get; set; default = null; }
public bool append { get; set; default = true; }
public string? kind { get; set; default = null; }
public string? lang { get; set; default = null; }
public string? profile_tag { get; set; default = null; }
public string? pushkey { get; set; default = null; }
public Json.Node? data { get; set; default = null; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class EventContext : JsonCompact {
public int before_limit { get; set; default = -1; }
public int after_limit { get; set; default = -1; }
public bool include_profile { get; set; default = false; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class SearchGrouping : JsonCompact {
public SearchGroupBy key { get; set; default = SearchGroupBy.NONE; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class SearchGroupings : JsonCompact {
public SearchGrouping[] group_by { get; set; }
public override Json.Node?
get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class SearchRoomEvents : JsonCompact {
public SearchOrder order_by { get; set; default = SearchOrder.RECENT; }
public SearchKey[] keys { get; set; }
public EventContext? event_context { get; set; default = null; }
public bool include_state { get; set; default = false; }
public string? filter_id { get; set; default = null; }
public Filter? filter { get; set; default = null; }
public string search_term { get; set; }
public SearchGroupings? groupings { get; set; default = null; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
[CCode (cheader_filename = "matrix-compacts.h")]
public class SearchCategories : JsonCompact {
public SearchRoomEvents? room_events { get; set; default = null; }
public override Json.Node? get_json_node()
throws Matrix.Error;
}
/* Utilities */ /* Utilities */
[CCode (cheader_filename = "utils.h", cname = "_matrix_g_enum_to_string")] [CCode (cheader_filename = "utils.h", cname = "_matrix_g_enum_to_string")]
public string? _g_enum_value_to_nick(GLib.Type enum_type, int value, bool convert_dashes = true); public string? _g_enum_value_to_nick(GLib.Type enum_type, int value, char convert_dashes = '_');
[CCode (cheader_filename = "utils.h", cname = "_matrix_g_enum_nick_to_value")]
public int _g_enum_nick_to_value(GLib.Type enum_type, string nick)
throws Matrix.Error;
[CCode (cheader_filename = "utils.h", cname = "_matrix_json_node_deep_copy")]
public Json.Node? _json_node_deep_copy(Json.Node? node);
[CCode (cheader_filename = "matrix-profile.h")]
public class Profile : GLib.Object {
public GLib.TimeSpan age {get;}
public string? avatar_url {get; set;}
public string? display_name {get; set;}
public Profile();
}
/** /**
* The major version number of the Matrix.org GLib SDK. * The major version number of the Matrix.org GLib SDK.