More validation of server responses
FossilOrigin-Name: 71e1a46c8f9d7dbfa9a5fe55fbdb37778b928491105a4c901e768699617ef090
This commit is contained in:
parent
c7fc35fb0f
commit
c4a1bd7932
1 changed files with 23 additions and 3 deletions
|
@ -98,14 +98,21 @@ validateHomeserver(OFURL *homeserver)
|
||||||
OFString *userID = response[@"user_id"];
|
OFString *userID = response[@"user_id"];
|
||||||
OFString *deviceID = response[@"device_id"];
|
OFString *deviceID = response[@"device_id"];
|
||||||
OFString *accessToken = response[@"access_token"];
|
OFString *accessToken = response[@"access_token"];
|
||||||
if (userID == nil || deviceID == nil ||
|
if (![userID isKindOfClass: OFString.class] ||
|
||||||
accessToken == nil) {
|
![deviceID isKindOfClass: OFString.class] ||
|
||||||
|
![accessToken isKindOfClass: OFString.class]) {
|
||||||
block(nil, [OFInvalidServerReplyException exception]);
|
block(nil, [OFInvalidServerReplyException exception]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OFString *baseURL =
|
OFString *baseURL =
|
||||||
response[@"well_known"][@"m.homeserver"][@"base_url"];
|
response[@"well_known"][@"m.homeserver"][@"base_url"];
|
||||||
|
if (baseURL != nil &&
|
||||||
|
![baseURL isKindOfClass: OFString.class]) {
|
||||||
|
block(nil, [OFInvalidServerReplyException exception]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OFURL *realHomeserver;
|
OFURL *realHomeserver;
|
||||||
if (baseURL != nil) {
|
if (baseURL != nil) {
|
||||||
@try {
|
@try {
|
||||||
|
@ -218,7 +225,7 @@ validateHomeserver(OFURL *homeserver)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusCode != 200 || response[@"joined_rooms"] == nil) {
|
if (statusCode != 200) {
|
||||||
block(nil, [MTXFetchRoomListFailedException
|
block(nil, [MTXFetchRoomListFailedException
|
||||||
exceptionWithClient: self
|
exceptionWithClient: self
|
||||||
statusCode: statusCode
|
statusCode: statusCode
|
||||||
|
@ -226,6 +233,19 @@ validateHomeserver(OFURL *homeserver)
|
||||||
return;
|
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);
|
block(response[@"joined_rooms"], nil);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue