MTXClient: Add support for logging out

FossilOrigin-Name: c29845b7b81229ea7bf062304824a4087c160629216064ae1a647fe8286826bb
This commit is contained in:
Jonathan Schleifer 2020-10-03 16:21:34 +00:00
parent 023ed62f5a
commit 77a2d20fc7
11 changed files with 209 additions and 25 deletions

View file

@ -22,22 +22,24 @@
#import <ObjFW/ObjFW.h>
#import "MTXRequest.h"
OF_ASSUME_NONNULL_BEGIN
@interface MTXLoginFailedException: OFException
@property (readonly, nonatomic) OFString *user;
@property (readonly, nonatomic) OFURL *homeserver;
@property (readonly, nonatomic) int statusCode;
@property (readonly, nonatomic) OFDictionary<OFString *, id> *response;
@property (readonly, nonatomic) mtx_response_t response;
+ (instancetype)exceptionWithUser: (OFString *)user
homeserver: (OFURL *)homeserver
statusCode: (int)statusCode
response: (OFDictionary<OFString *, id> *)response;
response: (mtx_response_t)response;
- (instancetype)initWithUser: (OFString *)user
homeserver: (OFURL *)homeserver
statusCode: (int)statusCode
response: (OFDictionary<OFString *, id> *)response;
response: (mtx_response_t)response;
@end
OF_ASSUME_NONNULL_END

View file

@ -26,7 +26,7 @@
+ (instancetype)exceptionWithUser: (OFString *)user
homeserver: (OFURL *)homeserver
statusCode: (int)statusCode
response: (OFDictionary<OFString *, id> *)response
response: (mtx_response_t)response
{
return [[[self alloc] initWithUser: user
homeserver: homeserver
@ -37,7 +37,7 @@
- (instancetype)initWithUser: (OFString *)user
homeserver: (OFURL *)homeserver
statusCode: (int)statusCode
response: (OFDictionary<OFString *, id> *)response
response: (mtx_response_t)response
{
self = [super init];
@ -62,4 +62,11 @@
[super dealloc];
}
- (OFString *)description
{
return [OFString stringWithFormat:
@"Failed to log in user %@ on %@: %@",
_user, _homeserver, _response];
}
@end

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2020, Jonathan Schleifer <js@nil.im>
*
* https://fossil.nil.im/objmatrix
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* 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 "MTXRequest.h"
OF_ASSUME_NONNULL_BEGIN
@class MTXClient;
@interface MTXLogoutFailedException: OFException
@property (readonly, nonatomic) MTXClient *client;
@property (readonly, nonatomic) int statusCode;
@property (readonly, nonatomic) mtx_response_t response;
+ (instancetype)exceptionWithClient: (MTXClient *)client
statusCode: (int)statusCode
response: (mtx_response_t)response;
- (instancetype)initWithClient: (OFString *)user
statusCode: (int)statusCode
response: (mtx_response_t)response;
@end
OF_ASSUME_NONNULL_END

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2020, Jonathan Schleifer <js@nil.im>
*
* https://fossil.nil.im/objmatrix
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* 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 "MTXLogoutFailedException.h"
#import "MTXClient.h"
@implementation MTXLogoutFailedException
+ (instancetype)exceptionWithClient: (MTXClient *)client
statusCode: (int)statusCode
response: (mtx_response_t)response
{
return [[[self alloc] initWithClient: client
statusCode: statusCode
response: response] autorelease];
}
- (instancetype)initWithClient: (MTXClient *)client
statusCode: (int)statusCode
response: (mtx_response_t)response
{
self = [super init];
@try {
_client = [client retain];
_statusCode = statusCode;
_response = [response copy];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_client release];
[_response release];
[super dealloc];
}
- (OFString *)description
{
return [OFString stringWithFormat:
@"Failed to log out user %@: %@", _client.userID, _response];
}
@end

View file

@ -3,7 +3,8 @@ include ../../extra.mk
STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A}
STATIC_LIB_NOINST = ${EXCEPTIONS_A}
SRCS = MTXLoginFailedException.m
SRCS = MTXLoginFailedException.m \
MTXLogoutFailedException.m
INCLUDES = ${SRCS:.m=.h}
include ../../buildsys.mk