20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
* POSSIBILITY OF SUCH DAMAGE.
*/
#import "MTXClient.h"
#import "MTXRequest.h"
#import "MTXLoginFailedException.h"
static void
validateHomeserver(OFURL *homeserver)
{
if (![homeserver.scheme isEqual: @"http"] &&
![homeserver.scheme isEqual: @"https"])
@throw [OFUnsupportedProtocolException
|
>
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
* POSSIBILITY OF SUCH DAMAGE.
*/
#import "MTXClient.h"
#import "MTXRequest.h"
#import "MTXLoginFailedException.h"
#import "MTXLogoutFailedException.h"
static void
validateHomeserver(OFURL *homeserver)
{
if (![homeserver.scheme isEqual: @"http"] &&
![homeserver.scheme isEqual: @"https"])
@throw [OFUnsupportedProtocolException
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
@"identifier": @{
@"type": @"m.id.user",
@"user": user
},
@"password": password
};
[request asyncPerformWithBlock:
^ (OFDictionary<OFString *, id> *response, int statusCode,
id exception) {
if (exception != nil) {
block(nil, exception);
return;
}
if (statusCode != 200) {
id exception = [MTXLoginFailedException
|
|
<
|
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
@"identifier": @{
@"type": @"m.id.user",
@"user": user
},
@"password": password
};
[request asyncPerformWithBlock: ^ (mtx_response_t response,
int statusCode, id exception) {
if (exception != nil) {
block(nil, exception);
return;
}
if (statusCode != 200) {
id exception = [MTXLoginFailedException
|
166
167
168
169
170
171
172
173
|
@"\tUser ID = %@\n"
@"\tDevice ID = %@\n"
@"\tAccess token = %@\n"
@"\tHomeserver = %@\n"
@">",
self.class, _userID, _deviceID, _accessToken, _homeserver];
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
@"\tUser ID = %@\n"
@"\tDevice ID = %@\n"
@"\tAccess token = %@\n"
@"\tHomeserver = %@\n"
@">",
self.class, _userID, _deviceID, _accessToken, _homeserver];
}
- (MTXRequest *)requestWithPath: (OFString *)path
{
return [MTXRequest requestWithPath: path
accessToken: _accessToken
homeserver: _homeserver];
}
- (void)asyncLogOutWithBlock: (mtx_client_logout_block_t)block
{
void *pool = objc_autoreleasePoolPush();
MTXRequest *request =
[self requestWithPath: @"/_matrix/client/r0/logout"];
request.method = OF_HTTP_REQUEST_METHOD_POST;
[request asyncPerformWithBlock: ^ (mtx_response_t response,
int statusCode, id exception) {
if (exception != nil) {
block(exception);
return;
}
if (statusCode != 200) {
block([MTXLogoutFailedException
exceptionWithClient: self
statusCode: statusCode
response: response]);
return;
}
block(nil);
}];
objc_autoreleasePoolPop(pool);
}
@end
|