ObjMatrix  Check-in [3c84d235e5]

Overview
Comment:Add support for storage
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3c84d235e55a6f4481f3ccfb4007113716902901544f9a1f011723767ecaa1e4
User & Date: js on 2020-10-03 19:47:26
Other Links: manifest | tags
Context
2020-10-03
21:56
Initial support for sync check-in: 17e299f073 user: js tags: trunk
19:47
Add support for storage check-in: 3c84d235e5 user: js tags: trunk
18:09
Add support for sending messages check-in: cce4e8d73a user: js tags: trunk
Changes

Modified .fossil-settings/ignore-glob from [c22fcfdab0] to [79fab73028].

15
16
17
18
19
20
21

15
16
17
18
19
20
21
22







+
autom4te.cache
buildsys.mk
config.log
config.status
configure
extra.mk
tests/tests
tests/tests.db

Modified ObjMatrix.oc from [6bd6e1275a] to [b6196c65e4].

1
2

3
4
1
2
3
4
5


+


package_format 1
package_depends_on ObjOpenSSL
package_depends_on ObjSQLite3
LIBS="-lobjmatrix $LIBS"
FRAMEWORK_LIBS="-framework ObjMatrix $FRAMEWORK_LIBS"

Modified README.md from [5a0e754e31] to [a1d3dbcd6f].

1
2
3
4
5
6
7
8
9
10
11
12
13



14
15
16
17
18
19
20

21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9
10
11


12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28











-
-
+
+
+






-
+







# ObjMatrix

## What is ObjMatrix?

ObjMatrix is a [Matrix](https://matrix.org) client library for
[ObjFW](https://objfw.nil.im).

It is currently in early development stages.

## How to build it?

You need [ObjFW](https://objfw.nil.im) and
[ObjOpenSSL](https://fossil.nil.im/objopenssl) installed in order to do this.
You need [ObjFW](https://objfw.nil.im),
[ObjOpenSSL](https://fossil.nil.im/objopenssl) and
[ObjSQLite3](https://fossil.nil.im/objsqlite3) installed in order to do this.

ObjMatrix uses modern Objective-C, and hence cannot be compiled with GCC, but
only with Clang. So install Clang first and ObjFW will automatically pick it up.

You can install them all like this:

    $ for i in objfw objopenssl objmatrix; do
    $ for i in objfw objopenssl objsqlite3 objmatrix; do
          fossil clone https://fossil.nil.im/$i $i.fossil &&
          mkdir $i &&
          cd $i &&
          fossil open ../$i.fossil &&
          ./autogen.sh &&
          ./configure &&
          make &&

Modified configure.ac from [045e406d38] to [d887e5a7de].

16
17
18
19
20
21
22





23
24
25
26
27
28
29
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+
+
+
+
+







	AC_MSG_ERROR(You need ObjFW and objfw-config installed!)
])

AS_IF([$OBJFW_CONFIG --package ObjOpenSSL], [
	OBJFW_CONFIG_FLAGS="$OBJFW_CONFIG_FLAGS --package ObjOpenSSL"
], [
	AC_MSG_ERROR(ObjOpenSSL not found!)
])
AS_IF([$OBJFW_CONFIG --package ObjSQLite3], [
	OBJFW_CONFIG_FLAGS="$OBJFW_CONFIG_FLAGS --package ObjSQLite3"
], [
	AC_MSG_ERROR(ObjSQLite3 not found!)
])

test x"$OBJC" = x"" && OBJC="$($OBJFW_CONFIG --objc)"

AC_LANG([Objective C])
AC_PROG_OBJC
AC_PROG_OBJCPP

Modified src/MTXClient.h from [b94a3d1693] to [2463af8d3c].

17
18
19
20
21
22
23


24
25
26
27
28
29
30
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32







+
+







 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import <ObjFW/ObjFW.h>

#import "MTXStorage.h"

OF_ASSUME_NONNULL_BEGIN

@class MTXClient;

/**
 * @brief A block called when a new login succeeded or failed.
81
82
83
84
85
86
87





88
89
90
91


92
93

94
95
96
97
98
99


100
101
102






103
104
105
106

107
108
109
110
111
112


113
114

115
116
117
118
119
120



121
122
123
124
125
126
127
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150







+
+
+
+
+




+
+


+





-
+
+



+
+
+
+
+
+




+






+
+


+





-
+
+
+







@property (readonly, nonatomic) OFString *accessToken;

/**
 * @brief The homeserver used by the client.
 */
@property (readonly, nonatomic) OFURL *homeserver;

/**
 * @brief The storage used by the client.
 */
@property (readonly, nonatomic) id <MTXStorage> storage;

/**
 * @brief Creates a new client with the specified access token on the specified
 *	  homeserver.
 *
 * @param userID The user ID for the client
 * @param deviceID The device ID for the client
 * @param accessToken The access token for the client
 * @param homeserver The URL of the homeserver
 * @param storage The storage the client should use
 * @return An autoreleased MTXClient
 */
+ (instancetype)clientWithUserID: (OFString *)userID
			deviceID: (OFString *)deviceID
		     accessToken: (OFString *)accessToken
		      homeserver: (OFURL *)homeserver;
		      homeserver: (OFURL *)homeserver
			 storage: (id <MTXStorage>)storage;

/**
 * @brief Logs into the homeserver and creates a new client.
 *
 * @param user The user to log into
 * @param password The password to log in with
 * @param homeserver The homeserver to log into
 * @param storage The storage the client should use
 * @param block A block to call once login succeeded or failed
 */
+ (void)logInWithUser: (OFString *)user
	     password: (OFString *)password
	   homeserver: (OFURL *)homeserver
	      storage: (id <MTXStorage>)storage
		block: (mtx_client_login_block_t)block;

/**
 * @brief Initializes an already allocated client with the specified access
 *	  token on the specified homeserver.
 *
 * @param userID The user ID for the client
 * @param deviceID The device ID for the client
 * @param accessToken The access token for the client
 * @param homeserver The URL of the homeserver
 * @param storage The storage the client should use
 * @return An initialized MTXClient
 */
- (instancetype)initWithUserID: (OFString *)userID
		      deviceID: (OFString *)deviceID
		   accessToken: (OFString *)accessToken
		    homeserver: (OFURL *)homeserver OF_DESIGNATED_INITIALIZER;
		    homeserver: (OFURL *)homeserver
		       storage: (id <MTXStorage>)storage
    OF_DESIGNATED_INITIALIZER;

/**
 * @brief Logs out the device and invalidates the access token.
 *
 * @warning The client can no longer be used after this succeeded!
 *
 * @param block A block to call when logging out succeeded or failed

Modified src/MTXClient.m from [654eca2334] to [a5246fd62c].

47
48
49
50
51
52
53

54
55
56
57
58


59
60
61
62
63

64
65
66
67
68
69
70
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73







+




-
+
+





+







}

@implementation MTXClient
+ (instancetype)clientWithUserID: (OFString *)userID
			deviceID: (OFString *)deviceID
		     accessToken: (OFString *)accessToken
		      homeserver: (OFURL *)homeserver
			 storage: (id <MTXStorage>)storage
{
	return [[[self alloc] initWithUserID: userID
				    deviceID: deviceID
				 accessToken: accessToken
				  homeserver: homeserver] autorelease];
				  homeserver: homeserver
				     storage: storage] autorelease];
}

+ (void)logInWithUser: (OFString *)user
	     password: (OFString *)password
	   homeserver: (OFURL *)homeserver
	      storage: (id <MTXStorage>)storage
		block: (mtx_client_login_block_t)block
{
	void *pool = objc_autoreleasePoolPush();

	validateHomeserver(homeserver);

	MTXRequest *request = [MTXRequest
123
124
125
126
127
128
129
130

131
132
133
134




135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
126
127
128
129
130
131
132

133




134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181







-
+
-
-
-
-
+
+
+
+










+










+














+







			} @catch (id e) {
				block(nil, e);
				return;
			}
		} else
			realHomeserver = homeserver;

		MTXClient *client = [MTXClient
		MTXClient *client = [MTXClient clientWithUserID: userID
		    clientWithUserID: userID
			    deviceID: deviceID
			 accessToken: accessToken
			  homeserver: realHomeserver];
						       deviceID: deviceID
						    accessToken: accessToken
						     homeserver: realHomeserver
							storage: storage];
		block(client, nil);
	}];

	objc_autoreleasePoolPop(pool);
}

- (instancetype)initWithUserID: (OFString *)userID
		      deviceID: (OFString *)deviceID
		   accessToken: (OFString *)accessToken
		    homeserver: (OFURL *)homeserver
		       storage: (id <MTXStorage>)storage
{
	self = [super init];

	@try {
		validateHomeserver(homeserver);

		_userID = [userID copy];
		_deviceID = [deviceID copy];
		_accessToken = [accessToken copy];
		_homeserver = [homeserver copy];
		_storage = [storage retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_userID release];
	[_deviceID release];
	[_accessToken release];
	[_homeserver release];
	[_storage release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:

Added src/MTXSQLite3Storage.h version [2d04e9845e].

Added src/MTXSQLite3Storage.m version [a4e0f0eb93].

Added src/MTXStorage.h version [68a1513741].

Modified src/Makefile from [0adfd37e81] to [6f19b186f7].

1
2
3
4
5
6
7
8
9
10
11


12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22










-
+
+


+







include ../extra.mk

SUBDIRS = exceptions

SHARED_LIB = ${OBJMATRIX_SHARED_LIB}
STATIC_LIB = ${OBJMATRIX_STATIC_LIB}
FRAMEWORK = ${OBJMATRIX_FRAMEWORK}
LIB_MAJOR = ${OBJMATRIX_LIB_MAJOR}
LIB_MINOR = ${OBJMATRIX_LIB_MINOR}

SRCS = MTXClient.m	\
SRCS = MTXClient.m		\
       MTXSQLite3Storage.m	\
       MTXRequest.m
INCLUDES := ${SRCS:.m=.h}	\
	    MTXStorage.h	\
	    ObjMatrix.h

OBJS_EXTRA = ${EXCEPTIONS_EXCEPTIONS_A}
LIB_OBJS_EXTRA = ${EXCEPTIONS_EXCEPTIONS_LIB_A}

include ../buildsys.mk

Modified src/ObjMatrix.h from [c891ec6342] to [45c5ea7f4a].

18
19
20
21
22
23
24


25
26
27
28
29
30
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32







+
+






 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "MTXClient.h"
#import "MTXRequest.h"
#import "MTXSQLite3Storage.h"
#import "MTXStorage.h"

#import "MTXFetchRoomListFailedException.h"
#import "MTXJoinRoomFailedException.h"
#import "MTXLeaveRoomFailedException.h"
#import "MTXLoginFailedException.h"
#import "MTXLogoutFailedException.h"

Modified tests/tests.m from [fa8fe451a7] to [9a4477a98b].

43
44
45
46
47
48
49


50
51
52

53
54
55
56
57
58
59
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62







+
+



+







		[of_stderr writeString: @"Please set OBJMATRIX_USER, "
					@"OBJMATRIX_PASS and OBJMATRIX_HS in "
					@"the environment!\n"];
		[OFApplication terminateWithStatus: 1];
	}

	OFURL *homeserver = [OFURL URLWithString: environment[@"OBJMATRIX_HS"]];
	id <MTXStorage> storage =
	    [MTXSQLite3Storage storageWithPath: @"tests.db"];
	[MTXClient logInWithUser: environment[@"OBJMATRIX_USER"]
			password: environment[@"OBJMATRIX_PASS"]
		      homeserver: homeserver
			 storage: storage
			   block: ^ (MTXClient *client, id exception) {
		if (exception != nil) {
			of_log(@"Error logging in: %@", exception);
			[OFApplication terminateWithStatus: 1];
		}

		_client = [client retain];