Port MatrixError to C

This commit is contained in:
Gergely Polonkai 2017-11-02 08:29:46 +01:00
parent 9054fb2a72
commit 51a4b1492c
9 changed files with 337 additions and 214 deletions

1
.gitignore vendored
View File

@ -37,6 +37,7 @@ Makefile.in
/INSTALL
/ChangeLog
/src/matrix-version.h
/src/matrix-enumtypes.[ch]
/src/matrix-marshalers.[ch]
/src/stamp-matrix-marshalers
/docs/valadoc/gtk-doc/gtk-doc

View File

@ -194,6 +194,7 @@ AC_SUBST([MATRIX_GLIB_MICRO_VERSION], matrix_glib_micro_version)
AC_SUBST([MATRIX_GLIB_API_VERSION], matrix_glib_api_version)
AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal])
AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums])
AC_CONFIG_FILES([
Makefile

View File

@ -114,19 +114,27 @@ $(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c): vala-stamp
bin_PROGRAMS = test-api-client test-client
INST_H_SRC_FILES = \
matrix-c-types.h \
$(NULL)
INST_H_BUILT_FILES = \
matrix-version.h \
matrix-enumtypes.h \
matrix-marshalers.h \
$(NULL)
matrix_enum_headers = \
matrix-c-types.h \
$(NULL)
libmatrix_glib_0_0_la_SOURCES = \
$(INST_H_BUILT_FILES) \
matrix-marshalers.c \
$(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c) \
matrix-event-types.c \
matrix-version.c \
matrix-c-types.c \
matrix-enumtypes.c \
$(INST_H_SRC_FILES) \
$(NULL)
@ -157,6 +165,8 @@ dist_vapi_DATA = \
$(NULL)
BUILT_SOURCES += \
matrix-enumtypes.c \
matrix-enumtypes.h \
matrix-marshalers.c \
matrix-marshalers.h \
$(NULL)
@ -177,10 +187,22 @@ test_client_LDADD = \
CLEANFILES += $(BUILT_SOURCES)
EXTRA_DIST += \
matrix-enumtypes.h.template \
matrix-enumtypes.c.template \
matrix-marshalers.list \
$(INST_H_SRC_FILES) \
$(NULL)
matrix-enumtypes.h: $(matrix_enum_headers) matrix-enumtypes.h.template
$(AM_V_GEN) $(GLIB_MKENUMS) --template $(filter %.template,$^) \
$(filter-out %.template,$^) > $@.tmp \
&& mv $@.tmp $@
matrix-enumtypes.c: $(matrix_enum_headers) matrix-enumtypes.h matrix-enumtypes.c.template
$(AM_V_GEN) $(GLIB_MKENUMS) --template $(filter %.template,$^) \
$(filter-out %.template,$^) > $@.tmp \
&& mv $@.tmp $@
matrix-marshalers.h: stamp-matrix-marshalers
@true

91
src/matrix-c-types.c Normal file
View File

@ -0,0 +1,91 @@
/*
* 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);

77
src/matrix-c-types.h Normal file
View File

@ -0,0 +1,77 @@
/*
* 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_TYPE_H__
# define __MATRIX_TYPE_H__
# include <glib-object.h>
typedef enum {
MATRIX_ERROR_NONE,
MATRIX_ERROR_COMMUNICATION_ERROR,
MATRIX_ERROR_INCOMPLETE,
MATRIX_ERROR_BAD_REQUEST,
MATRIX_ERROR_BAD_RESPONSE,
MATRIX_ERROR_INVALID_ROOM_ID,
MATRIX_ERROR_UNKNOWN_VALUE,
MATRIX_ERROR_INVALID_TYPE,
MATRIX_ERROR_UNSUPPORTED,
MATRIX_ERROR_INVALID_FORMAT,
MATRIX_ERROR_UNAVAILABLE,
MATRIX_ERROR_NOT_FOUND,
MATRIX_ERROR_ALREADY_EXISTS,
/* Add Matrix-defined error codes under here, prefixing them with
* `MATRIX_ERROR_`, i.e. `M_FORBIDDEN` =>
* `MATRIX_ERROR_M_FORBIDDEN` */
MATRIX_ERROR_M_MISSING_TOKEN = 500,
MATRIX_ERROR_M_FORBIDDEN,
MATRIX_ERROR_M_UNKNOWN,
MATRIX_ERROR_M_UNKNOWN_TOKEN,
MATRIX_ERROR_M_NOT_JSON,
MATRIX_ERROR_M_UNRECOGNIZED,
MATRIX_ERROR_M_UNAUTHORIZED,
MATRIX_ERROR_M_BAD_JSON,
MATRIX_ERROR_M_USER_IN_USE,
MATRIX_ERROR_M_ROOM_IN_USE,
MATRIX_ERROR_M_BAD_PAGINATION,
MATRIX_ERROR_M_BAD_STATE,
MATRIX_ERROR_M_NOT_FOUND,
MATRIX_ERROR_M_GUEST_ACCESS_FORBIDDEN,
MATRIX_ERROR_M_LIMIT_EXCEEDED,
MATRIX_ERROR_M_CAPTCHA_NEEDED,
MATRIX_ERROR_M_CAPTCHA_INVALID,
MATRIX_ERROR_M_MISSING_PARAM,
MATRIX_ERROR_M_TOO_LARGE,
MATRIX_ERROR_M_EXCLUSIVE,
MATRIX_ERROR_M_THREEPID_AUTH_FAILED,
MATRIX_ERROR_M_THREEPID_IN_USE,
MATRIX_ERROR_M_INVALID_USERNAME,
/* Allow for a lot of Matrix.org defined codes. Do not define
* Matrix-specific error codes after this! */
MATRIX_ERROR_UNSPECIFIED = 16383,
MATRIX_ERROR_UNKNOWN_ERROR
} MatrixError;
# define MATRIX_ERROR matrix_error_quark()
GQuark matrix_error_quark(void);
#endif /* __MATRIX_TYPE_H__ */

View File

@ -0,0 +1,59 @@
/*** BEGIN file-header ***/
/*
* 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-enumtypes.h"
/*** END file-header ***/
/*** BEGIN file-production ***/
/* enumerations from @filename@ */
/*** END file-production ***/
/*** BEGIN value-header ***/
GType
@enum_name@_get_type(void)
{
static volatile gsize g_define_type_id__volatile = 0;
if (g_once_init_enter(&g_define_type_id__volatile)) {
static const G@Type@Value values[] = {
/*** END value-header ***/
/*** BEGIN value-production ***/
{
@VALUENAME@,
"@VALUENAME@",
"@valuenick@"
},
/*** END value-production ***/
/*** BEGIN value-tail ***/
{0, NULL, NULL}
};
GType g_define_type_id = g_@type@_register_static(
g_intern_static_string("@EnumName@"),
values);
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
}
return g_define_type_id__volatile;
}
/*** END value-tail ***/

View File

@ -0,0 +1,42 @@
/*** BEGIN file-header ***/
/*
* 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_ENUMTYPES_H__
#define __MATRIX_ENUMTYPES_H__
#include <glib-object.h>
/*** END file-header ***/
/*** BEGIN file-production ***/
/* enumerations from "@filename@" */
#include "@filename@"
/*** END file-production ***/
/*** BEGIN value-header ***/
GType @enum_name@_get_type(void);
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
/*** END value-header ***/
/*** BEGIN file-tail ***/
#endif /* __MATRIX_ENUMTYPES_H__ */
/*** END file-tail ***/

View File

@ -17,220 +17,6 @@
*/
namespace Matrix {
public errordomain Error {
/**
* no error. You should never see this.
*/
NONE,
/**
* there was a problem in communication (e.g. connection
* error)
*/
COMMUNICATION_ERROR,
/**
* the passed/generated data is incomplete
*/
INCOMPLETE,
/**
* the request is invalid
*/
BAD_REQUEST,
/**
* malformed response, or the response is not a JSON object
*/
BAD_RESPONSE,
/**
* the provided string doesnt contain a valid room ID
*/
INVALID_ROOM_ID,
/**
* the response from the Matrix.org server contains a value
* unknown to this library. These should be reported to the
* Matrix GLib SDK developers
*/
UNKNOWN_VALUE,
/**
* the provided type is invalid
*/
INVALID_TYPE,
/**
* the operation is unsupported
*/
UNSUPPORTED,
/**
* the format of the JSON node is invalid (e.g. it is an array
* instead of an object)
*/
INVALID_FORMAT,
/**
* the requested data is not cached yet. Clients getting this
* message may go online by some means to get the data
*/
UNAVAILABLE,
/**
* the requested data (e.g. member of a room) can not be found
*/
NOT_FOUND,
/**
* the data to create (e.g. when adding a new member to a Room
* object) already exists
*/
ALREADY_EXISTS,
/* Add Matrix-defined error codes under here, prefixing them with
* `MATRIX_ERROR_`, i.e. `M_FORBIDDEN` =>
* `MATRIX_ERROR_M_FORBIDDEN` */
/**
* authorization token is missing from the request
*/
M_MISSING_TOKEN = 500,
/**
* access was forbidden (e.g. due to a missing/invalid token,
* or using a bad password during login)
*/
M_FORBIDDEN,
/**
* an error unknown to the Matrix homeserver
*/
M_UNKNOWN,
/**
* the token provided is not known for the homeserver
*/
M_UNKNOWN_TOKEN,
/**
* illegal request, the content is not valid JSON
*/
M_NOT_JSON,
/**
* the homeserver didn't understand the request
*/
M_UNRECOGNIZED,
/**
* the request is unauthorized
*/
M_UNAUTHORIZED,
/**
* the JSON data is not in the required format
*/
M_BAD_JSON,
/**
* the specified username is in use
*/
M_USER_IN_USE,
/**
* the specified room is in use
*/
M_ROOM_IN_USE,
/**
* invalid pagination parameters
*/
M_BAD_PAGINATION,
/**
* invalid state event
*/
M_BAD_STATE,
/**
* the requested resource is not found
*/
M_NOT_FOUND,
/**
* guest access was requested, but ( it is forbidden
*/
M_GUEST_ACCESS_FORBIDDEN,
/**
* the request was rate limited
*/
M_LIMIT_EXCEEDED,
/**
* a captcha is needed to continue
*/
M_CAPTCHA_NEEDED,
/**
* the provided captcha is invalid
*/
M_CAPTCHA_INVALID,
/**
* a parameter is missing from the request
*/
M_MISSING_PARAM,
/**
* the request data is too large
*/
M_TOO_LARGE,
/**
* the desired user ID is in an exclusive namespace claimed by
* an application server
*/
M_EXCLUSIVE,
/**
* 3rd party authentication failed
*/
M_THREEPID_AUTH_FAILED,
/**
* the provided 3rd party ID is already in use
*/
M_THREEPID_IN_USE,
/**
* the given username is invalid
*/
M_INVALID_USERNAME,
/* Allow for a lot of Matrix.org defined codes. Do not define
* Matrix-specific error codes after this! */
/**
* no error code was sent by the homeserver. If you see this
* error, that usually indicates a homeserver bug
*/
UNSPECIFIED = 16383,
/**
* an error unknown to this library
*/
UNKNOWN_ERROR;
public static GLib.Quark
quark ()
{
return Quark.from_string("matrix-error-quark");
}
}
/**
* User account types.
*/

View File

@ -18,6 +18,50 @@
[CCode (cprefix = "Matrix", gir_namespace = "Matrix", gir_version = "0.0", lower_case_cprefix = "matrix_")]
namespace Matrix {
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ERROR_")]
public errordomain Error {
NONE,
COMMUNICATION_ERROR,
INCOMPLETE,
BAD_REQUEST,
BAD_RESPONSE,
INVALID_ROOM_ID,
UNKNOWN_VALUE,
INVALID_TYPE,
UNSUPPORTED,
INVALID_FORMAT,
UNAVAILABLE,
NOT_FOUND,
ALREADY_EXISTS,
M_MISSING_TOKEN,
M_FORBIDDEN,
M_UNKNOWN,
M_UNKNOWN_TOKEN,
M_NOT_JSON,
M_UNRECOGNIZED,
M_UNAUTHORIZED,
M_BAD_JSON,
M_USER_IN_USE,
M_ROOM_IN_USE,
M_BAD_PAGINATION,
M_BAD_STATE,
M_NOT_FOUND,
M_GUEST_ACCESS_FORBIDDEN,
M_LIMIT_EXCEEDED,
M_CAPTCHA_NEEDED,
M_CAPTCHA_INVALID,
M_MISSING_PARAM,
M_TOO_LARGE,
M_EXCLUSIVE,
M_THREEPID_AUTH_FAILED,
M_THREEPID_IN_USE,
M_INVALID_USERNAME,
UNSPECIFIED,
UNKNOWN_ERROR;
public static GLib.Quark quark ();
}
/**
* The major version number of the Matrix.org GLib SDK.
*/