ObjMatrix  Diff

Differences From Artifact [e2e1bfaf11]:

To Artifact [bc5bbe8ab6]:


21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35







-
+







 */

#import "MTXRequest.h"

@implementation MTXRequest
{
	OFData *_body;
	mtx_request_block_t _block;
	MTXRequestBlock _block;
}

+ (instancetype)requestWithPath: (OFString *)path
		    accessToken: (OFString *)accessToken
		     homeserver: (OFURL *)homeserver
{
	return [[[self alloc] initWithPath: path
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57







-
+







{
	self = [super init];

	@try {
		_accessToken = [accessToken copy];
		_homeserver = [homeserver copy];
		_path = [path copy];
		_method = OF_HTTP_REQUEST_METHOD_GET;
		_method = OFHTTPRequestMethodGet;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
69
70
71
72
73
74
75
76

77
78

79
80
81
82
83
84
85
86

87
88
89
90

91
92
93
94
95
96
97
69
70
71
72
73
74
75

76


77
78
79
80
81
82
83
84

85

86
87

88
89
90
91
92
93
94
95







-
+
-
-
+







-
+
-


-
+







- (void)setBody: (OFDictionary<OFString *, id> *)body
{
	void *pool = objc_autoreleasePoolPush();

	[_body release];

	OFString *JSONString = [body JSONRepresentation];
	_body = [[OFData alloc]
	_body = [[OFData alloc] initWithItems: JSONString.UTF8String
	    initWithItems: JSONString.UTF8String
		    count: JSONString.UTF8StringLength];
					count: JSONString.UTF8StringLength];

	objc_autoreleasePoolPop(pool);
}

- (OFDictionary<OFString *, id> *)body
{
	return [OFString stringWithUTF8String: _body.items
				       length: _body.count]
				       length: _body.count].objectByParsingJSON;
	    .objectByParsingJSON;
}

- (void)performWithBlock: (mtx_request_block_t)block
- (void)performWithBlock: (MTXRequestBlock)block
{
	void *pool = objc_autoreleasePoolPush();

	if (_block != nil)
		/* Not the best exception to indicate it's already in-flight. */
		@throw [OFAlreadyConnectedException exception];

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
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







-
+










-
+
-


-
+







	  exception: (id)exception
{
	if (response != nil &&
	    [exception isKindOfClass: [OFHTTPRequestFailedException class]])
		exception = nil;

	/* Reset to nil first, so that another one can be performed. */
	mtx_request_block_t block = _block;
	MTXRequestBlock block = _block;
	_block = nil;

	if (exception == nil) {
		@try {
			OFMutableData *responseData = [OFMutableData data];
			while (!response.atEndOfStream) {
				char buffer[512];
				size_t length = [response readIntoBuffer: buffer
								  length: 512];

				[responseData addItems: buffer
				[responseData addItems: buffer count: length];
						 count: length];
			}

			mtx_response_t responseJSON = [OFString
			MTXResponse responseJSON = [OFString
			    stringWithUTF8String: responseData.items
					  length: responseData.count]
			    .objectByParsingJSON;

			block(responseJSON, response.statusCode, nil);
		} @catch (id e) {
			block(nil, response.statusCode, e);