Adjust to ObjFW changes
FossilOrigin-Name: 531eb84cf5c27b39f7701dfa446886e2962aad9a8b60c3623e3b70833b18c592
This commit is contained in:
parent
0166881d65
commit
4252cbf3f2
10 changed files with 69 additions and 55 deletions
|
@ -1,5 +1,5 @@
|
|||
package_format 1
|
||||
package_depends_on ObjOpenSSL
|
||||
package_depends_on ObjFWTLS
|
||||
package_depends_on ObjSQLite3
|
||||
LIBS="-lobjmatrix $LIBS"
|
||||
FRAMEWORK_LIBS="-framework ObjMatrix $FRAMEWORK_LIBS"
|
||||
|
|
|
@ -9,8 +9,7 @@ It is currently in early development stages.
|
|||
|
||||
## How to build it?
|
||||
|
||||
You need [ObjFW](https://objfw.nil.im),
|
||||
[ObjOpenSSL](https://fossil.nil.im/objopenssl) and
|
||||
You need [ObjFW](https://objfw.nil.im) 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
|
||||
|
@ -18,7 +17,7 @@ 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 objsqlite3 objmatrix; do
|
||||
$ for i in objfw objsqlite3 objmatrix; do
|
||||
fossil clone https://fossil.nil.im/$i $i.fossil &&
|
||||
mkdir $i &&
|
||||
cd $i &&
|
||||
|
|
|
@ -16,10 +16,10 @@ AS_IF([test x"$OBJFW_CONFIG" = x""], [
|
|||
AC_MSG_ERROR(You need ObjFW and objfw-config installed!)
|
||||
])
|
||||
|
||||
AS_IF([$OBJFW_CONFIG --package ObjOpenSSL], [
|
||||
OBJFW_CONFIG_FLAGS="$OBJFW_CONFIG_FLAGS --package ObjOpenSSL"
|
||||
AS_IF([$OBJFW_CONFIG --package ObjFWTLS], [
|
||||
OBJFW_CONFIG_FLAGS="$OBJFW_CONFIG_FLAGS --package ObjFWTLS"
|
||||
], [
|
||||
AC_MSG_ERROR(ObjOpenSSL not found!)
|
||||
AC_MSG_ERROR(ObjFWTLS not found!)
|
||||
])
|
||||
AS_IF([$OBJFW_CONFIG --package ObjSQLite3], [
|
||||
OBJFW_CONFIG_FLAGS="$OBJFW_CONFIG_FLAGS --package ObjSQLite3"
|
||||
|
|
|
@ -92,7 +92,7 @@ typedef void (^MTXClientRoomJoinBlock)(OFString *_Nullable roomID,
|
|||
/**
|
||||
* @brief The homeserver used by the client.
|
||||
*/
|
||||
@property (readonly, nonatomic) OFURL *homeserver;
|
||||
@property (readonly, nonatomic) OFIRI *homeserver;
|
||||
|
||||
/**
|
||||
* @brief The storage used by the client.
|
||||
|
@ -118,14 +118,14 @@ typedef void (^MTXClientRoomJoinBlock)(OFString *_Nullable roomID,
|
|||
* @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 homeserver The IRI 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: (OFIRI *)homeserver
|
||||
storage: (id <MTXStorage>)storage;
|
||||
|
||||
/**
|
||||
|
@ -139,7 +139,7 @@ typedef void (^MTXClientRoomJoinBlock)(OFString *_Nullable roomID,
|
|||
*/
|
||||
+ (void)logInWithUser: (OFString *)user
|
||||
password: (OFString *)password
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
storage: (id <MTXStorage>)storage
|
||||
block: (MTXClientLoginBlock)block;
|
||||
|
||||
|
@ -150,14 +150,14 @@ typedef void (^MTXClientRoomJoinBlock)(OFString *_Nullable roomID,
|
|||
* @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 homeserver The IRI 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
|
||||
homeserver: (OFIRI *)homeserver
|
||||
storage: (id <MTXStorage>)storage
|
||||
OF_DESIGNATED_INITIALIZER;
|
||||
|
||||
|
|
|
@ -32,12 +32,12 @@
|
|||
#import "MTXSyncFailedException.h"
|
||||
|
||||
static void
|
||||
validateHomeserver(OFURL *homeserver)
|
||||
validateHomeserver(OFIRI *homeserver)
|
||||
{
|
||||
if (![homeserver.scheme isEqual: @"http"] &&
|
||||
![homeserver.scheme isEqual: @"https"])
|
||||
@throw [OFUnsupportedProtocolException
|
||||
exceptionWithURL: homeserver];
|
||||
exceptionWithIRI: homeserver];
|
||||
|
||||
if (homeserver.path != nil && ![homeserver.path isEqual: @"/"])
|
||||
@throw [OFInvalidArgumentException exception];
|
||||
|
@ -55,7 +55,7 @@ validateHomeserver(OFURL *homeserver)
|
|||
+ (instancetype)clientWithUserID: (OFString *)userID
|
||||
deviceID: (OFString *)deviceID
|
||||
accessToken: (OFString *)accessToken
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
storage: (id <MTXStorage>)storage
|
||||
{
|
||||
return [[[self alloc] initWithUserID: userID
|
||||
|
@ -67,7 +67,7 @@ validateHomeserver(OFURL *homeserver)
|
|||
|
||||
+ (void)logInWithUser: (OFString *)user
|
||||
password: (OFString *)password
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
storage: (id <MTXStorage>)storage
|
||||
block: (MTXClientLoginBlock)block
|
||||
{
|
||||
|
@ -112,22 +112,24 @@ validateHomeserver(OFURL *homeserver)
|
|||
if (![userID isKindOfClass: OFString.class] ||
|
||||
![deviceID isKindOfClass: OFString.class] ||
|
||||
![accessToken isKindOfClass: OFString.class]) {
|
||||
block(nil, [OFInvalidServerReplyException exception]);
|
||||
block(nil,
|
||||
[OFInvalidServerResponseException exception]);
|
||||
return;
|
||||
}
|
||||
|
||||
OFString *baseURL =
|
||||
OFString *baseIRI =
|
||||
response[@"well_known"][@"m.homeserver"][@"base_url"];
|
||||
if (baseURL != nil &&
|
||||
![baseURL isKindOfClass: OFString.class]) {
|
||||
block(nil, [OFInvalidServerReplyException exception]);
|
||||
if (baseIRI != nil &&
|
||||
![baseIRI isKindOfClass: OFString.class]) {
|
||||
block(nil,
|
||||
[OFInvalidServerResponseException exception]);
|
||||
return;
|
||||
}
|
||||
|
||||
OFURL *realHomeserver;
|
||||
if (baseURL != nil) {
|
||||
OFIRI *realHomeserver;
|
||||
if (baseIRI != nil) {
|
||||
@try {
|
||||
realHomeserver = [OFURL URLWithString: baseURL];
|
||||
realHomeserver = [OFIRI IRIWithString: baseIRI];
|
||||
} @catch (id e) {
|
||||
block(nil, e);
|
||||
return;
|
||||
|
@ -149,7 +151,7 @@ validateHomeserver(OFURL *homeserver)
|
|||
- (instancetype)initWithUserID: (OFString *)userID
|
||||
deviceID: (OFString *)deviceID
|
||||
accessToken: (OFString *)accessToken
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
storage: (id <MTXStorage>)storage
|
||||
{
|
||||
self = [super init];
|
||||
|
@ -212,11 +214,20 @@ validateHomeserver(OFURL *homeserver)
|
|||
MTXRequest *request = [self
|
||||
requestWithPath: @"/_matrix/client/r0/sync"];
|
||||
unsigned long long timeoutMs = _syncTimeout * 1000;
|
||||
OFMutableDictionary<OFString *, OFString *> *query =
|
||||
[OFMutableDictionary dictionaryWithObject: @(timeoutMs).stringValue
|
||||
forKey: @"timeout"];
|
||||
query[@"since"] = [_storage nextBatchForDeviceID: _deviceID];
|
||||
request.query = query;
|
||||
OFMutableArray<OFPair <OFString *, OFString *> *> *queryItems =
|
||||
[OFMutableArray array];
|
||||
OFString *since = [_storage nextBatchForDeviceID: _deviceID];
|
||||
|
||||
[queryItems addObject:
|
||||
[OFPair pairWithFirstObject: @"timeout"
|
||||
secondObject: @(timeoutMs).stringValue]];
|
||||
|
||||
if (since != nil)
|
||||
[queryItems addObject:
|
||||
[OFPair pairWithFirstObject: @"since"
|
||||
secondObject: since]];
|
||||
|
||||
request.queryItems = queryItems;
|
||||
[request performWithBlock: ^ (MTXResponse response, int statusCode,
|
||||
id exception) {
|
||||
if (exception != nil) {
|
||||
|
@ -238,7 +249,8 @@ validateHomeserver(OFURL *homeserver)
|
|||
if (![nextBatch isKindOfClass: OFString.class]) {
|
||||
if (_syncExceptionHandler != NULL)
|
||||
_syncExceptionHandler(
|
||||
[OFInvalidServerReplyException exception]);
|
||||
[OFInvalidServerResponseException
|
||||
exception]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -324,13 +336,15 @@ validateHomeserver(OFURL *homeserver)
|
|||
|
||||
OFArray<OFString *> *joinedRooms = response[@"joined_rooms"];
|
||||
if (![joinedRooms isKindOfClass: OFArray.class]) {
|
||||
block(nil, [OFInvalidServerReplyException exception]);
|
||||
block(nil,
|
||||
[OFInvalidServerResponseException exception]);
|
||||
return;
|
||||
}
|
||||
for (OFString *room in joinedRooms) {
|
||||
if (![room isKindOfClass: OFString.class]) {
|
||||
block(nil,
|
||||
[OFInvalidServerReplyException exception]);
|
||||
[OFInvalidServerResponseException
|
||||
exception]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +379,8 @@ validateHomeserver(OFURL *homeserver)
|
|||
|
||||
OFString *roomID = response[@"room_id"];
|
||||
if (![roomID isKindOfClass: OFString.class]) {
|
||||
block(nil, [OFInvalidServerReplyException exception]);
|
||||
block(nil,
|
||||
[OFInvalidServerResponseException exception]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,9 +54,9 @@ typedef void (^MTXRequestBlock)(MTXResponse _Nullable response, int statusCode,
|
|||
@property (readonly, nonatomic, nullable) OFString *accessToken;
|
||||
|
||||
/**
|
||||
* @brief The URL of the homeserver to send the request to.
|
||||
* @brief The IRI of the homeserver to send the request to.
|
||||
*/
|
||||
@property (readonly, nonatomic) OFURL *homeserver;
|
||||
@property (readonly, nonatomic) OFIRI *homeserver;
|
||||
|
||||
/**
|
||||
* @brief The HTTP request method.
|
||||
|
@ -71,10 +71,10 @@ typedef void (^MTXRequestBlock)(MTXResponse _Nullable response, int statusCode,
|
|||
@property (copy, nonatomic) OFString *path;
|
||||
|
||||
/**
|
||||
* @brief The query for the request.
|
||||
* @brief The query items for the request.
|
||||
*/
|
||||
@property (copy, nullable, nonatomic)
|
||||
OFDictionary<OFString *, OFString *> *query;
|
||||
OFArray<OFPair<OFString *, OFString *> *> *queryItems;
|
||||
|
||||
/**
|
||||
* @brief An optional body to send along with the request.
|
||||
|
@ -92,7 +92,7 @@ typedef void (^MTXRequestBlock)(MTXResponse _Nullable response, int statusCode,
|
|||
*/
|
||||
+ (instancetype)requestWithPath: (OFString *)path
|
||||
accessToken: (nullable OFString *)accessToken
|
||||
homeserver: (OFURL *)homeserver;
|
||||
homeserver: (OFIRI *)homeserver;
|
||||
|
||||
/**
|
||||
* @brief Initializes an already allocated request with the specified access
|
||||
|
@ -104,7 +104,7 @@ typedef void (^MTXRequestBlock)(MTXResponse _Nullable response, int statusCode,
|
|||
*/
|
||||
- (instancetype)initWithPath: (OFString *)path
|
||||
accessToken: (nullable OFString *)accessToken
|
||||
homeserver: (OFURL *)homeserver;
|
||||
homeserver: (OFIRI *)homeserver;
|
||||
|
||||
/**
|
||||
* @brief Performs the request and calls the specified block once the request
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
+ (instancetype)requestWithPath: (OFString *)path
|
||||
accessToken: (OFString *)accessToken
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
{
|
||||
return [[[self alloc] initWithPath: path
|
||||
accessToken: accessToken
|
||||
|
@ -39,7 +39,7 @@
|
|||
|
||||
- (instancetype)initWithPath: (OFString *)path
|
||||
accessToken: (OFString *)accessToken
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
|
@ -91,11 +91,11 @@
|
|||
|
||||
if (_block != nil)
|
||||
/* Not the best exception to indicate it's already in-flight. */
|
||||
@throw [OFAlreadyConnectedException exception];
|
||||
@throw [OFAlreadyOpenException exceptionWithObject: self];
|
||||
|
||||
OFMutableURL *requestURL = [[_homeserver mutableCopy] autorelease];
|
||||
requestURL.path = _path;
|
||||
requestURL.queryDictionary = _query;
|
||||
OFMutableIRI *requestIRI = [[_homeserver mutableCopy] autorelease];
|
||||
requestIRI.path = _path;
|
||||
requestIRI.queryItems = _queryItems;
|
||||
|
||||
OFMutableDictionary *headers = [OFMutableDictionary dictionary];
|
||||
headers[@"User-Agent"] = @"ObjMatrix";
|
||||
|
@ -105,7 +105,7 @@
|
|||
if (_body != nil)
|
||||
headers[@"Content-Length"] = @(_body.count).stringValue;
|
||||
|
||||
OFHTTPRequest *request = [OFHTTPRequest requestWithURL: requestURL];
|
||||
OFHTTPRequest *request = [OFHTTPRequest requestWithIRI: requestIRI];
|
||||
request.method = _method;
|
||||
request.headers = headers;
|
||||
|
||||
|
|
|
@ -28,16 +28,16 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@interface MTXLoginFailedException: OFException
|
||||
@property (readonly, nonatomic) OFString *user;
|
||||
@property (readonly, nonatomic) OFURL *homeserver;
|
||||
@property (readonly, nonatomic) OFIRI *homeserver;
|
||||
@property (readonly, nonatomic) int statusCode;
|
||||
@property (readonly, nonatomic) MTXResponse response;
|
||||
|
||||
+ (instancetype)exceptionWithUser: (OFString *)user
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
statusCode: (int)statusCode
|
||||
response: (MTXResponse)response;
|
||||
- (instancetype)initWithUser: (OFString *)user
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
statusCode: (int)statusCode
|
||||
response: (MTXResponse)response;
|
||||
@end
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
@implementation MTXLoginFailedException
|
||||
+ (instancetype)exceptionWithUser: (OFString *)user
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
statusCode: (int)statusCode
|
||||
response: (MTXResponse)response
|
||||
{
|
||||
|
@ -35,7 +35,7 @@
|
|||
}
|
||||
|
||||
- (instancetype)initWithUser: (OFString *)user
|
||||
homeserver: (OFURL *)homeserver
|
||||
homeserver: (OFIRI *)homeserver
|
||||
statusCode: (int)statusCode
|
||||
response: (MTXResponse)response
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@ OF_APPLICATION_DELEGATE(Tests)
|
|||
OFString *_roomID;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching
|
||||
- (void)applicationDidFinishLaunching: (OFNotification *)notification
|
||||
{
|
||||
__auto_type environment = OFApplication.environment;
|
||||
if (environment[@"OBJMATRIX_USER"] == nil ||
|
||||
|
@ -47,7 +47,7 @@ OF_APPLICATION_DELEGATE(Tests)
|
|||
[OFApplication terminateWithStatus: 1];
|
||||
}
|
||||
|
||||
OFURL *homeserver = [OFURL URLWithString: environment[@"OBJMATRIX_HS"]];
|
||||
OFIRI *homeserver = [OFIRI IRIWithString: environment[@"OBJMATRIX_HS"]];
|
||||
id <MTXStorage> storage =
|
||||
[MTXSQLite3Storage storageWithPath: @"tests.db"];
|
||||
[MTXClient logInWithUser: environment[@"OBJMATRIX_USER"]
|
Loading…
Add table
Add a link
Reference in a new issue