ObjMatrix  Check-in [71e1a46c8f]

Overview
Comment:More validation of server responses
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 71e1a46c8f9d7dbfa9a5fe55fbdb37778b928491105a4c901e768699617ef090
User & Date: js on 2020-10-03 17:20:34
Other Links: manifest | tags
Context
2020-10-03
17:23
Get rid of async prefix check-in: d18fbd29fb user: js tags: trunk
17:20
More validation of server responses check-in: 71e1a46c8f user: js tags: trunk
17:08
Add support for fetching room list check-in: 092c122c69 user: js tags: trunk
Changes

Modified src/MTXClient.m from [9f44985428] to [2e0008f3e6].

94
95
96
97
98
99
100

101
102
103
104
105
106
107
108






109
110
111
112
113
114
115
			block(nil, exception);
			return;
		}

		OFString *userID = response[@"user_id"];
		OFString *deviceID = response[@"device_id"];
		OFString *accessToken = response[@"access_token"];

		if (userID == nil || deviceID == nil ||
		    accessToken == nil) {
			block(nil, [OFInvalidServerReplyException exception]);
			return;
		}

		OFString *baseURL =
		    response[@"well_known"][@"m.homeserver"][@"base_url"];






		OFURL *realHomeserver;
		if (baseURL != nil) {
			@try {
				realHomeserver = [OFURL URLWithString: baseURL];
			} @catch (id e) {
				block(nil, e);
				return;







>
|
|






>
>
>
>
>
>







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
			block(nil, exception);
			return;
		}

		OFString *userID = response[@"user_id"];
		OFString *deviceID = response[@"device_id"];
		OFString *accessToken = response[@"access_token"];
		if (![userID isKindOfClass: OFString.class] ||
		    ![deviceID isKindOfClass: OFString.class] ||
		    ![accessToken isKindOfClass: OFString.class]) {
			block(nil, [OFInvalidServerReplyException exception]);
			return;
		}

		OFString *baseURL =
		    response[@"well_known"][@"m.homeserver"][@"base_url"];
		if (baseURL != nil &&
		    ![baseURL isKindOfClass: OFString.class]) {
			block(nil, [OFInvalidServerReplyException exception]);
			return;
		}

		OFURL *realHomeserver;
		if (baseURL != nil) {
			@try {
				realHomeserver = [OFURL URLWithString: baseURL];
			} @catch (id e) {
				block(nil, e);
				return;
214
215
216
217
218
219
220
221
222
223
224
225
226
227













228
229
230
231
232
233
234
	[request asyncPerformWithBlock: ^ (mtx_response_t response,
					    int statusCode, id exception) {
		if (exception != nil) {
			block(nil, exception);
			return;
		}

		if (statusCode != 200 || response[@"joined_rooms"] == nil) {
			block(nil, [MTXFetchRoomListFailedException
			    exceptionWithClient: self
				     statusCode: statusCode
				       response: response]);
			return;
		}














		block(response[@"joined_rooms"], nil);
	}];

	objc_autoreleasePoolPop(pool);
}
@end







|






>
>
>
>
>
>
>
>
>
>
>
>
>







221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
	[request asyncPerformWithBlock: ^ (mtx_response_t response,
					    int statusCode, id exception) {
		if (exception != nil) {
			block(nil, exception);
			return;
		}

		if (statusCode != 200) {
			block(nil, [MTXFetchRoomListFailedException
			    exceptionWithClient: self
				     statusCode: statusCode
				       response: response]);
			return;
		}

		OFArray<OFString *> *joinedRooms = response[@"joined_rooms"];
		if (![joinedRooms isKindOfClass: OFArray.class]) {
			block(nil, [OFInvalidServerReplyException exception]);
			return;
		}
		for (OFString *room in joinedRooms) {
			if (![room isKindOfClass: OFString.class]) {
				block(nil,
				    [OFInvalidServerReplyException exception]);
				return;
			}
		}

		block(response[@"joined_rooms"], nil);
	}];

	objc_autoreleasePoolPop(pool);
}
@end