Skip to content
Snippets Groups Projects
Verified Commit 43e88905 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Handle more invalid room ids

parent ce47f0b2
No related branches found
No related tags found
No related merge requests found
Pipeline #3550 passed
......@@ -120,6 +120,21 @@ struct InvitedRoom
friend void from_json(const nlohmann::json &obj, InvitedRoom &room);
};
//! A room that the user has knocked on.
struct KnockedRoom
{
//! The state of a room that the user has knocked on.
//! These state events may only have the `sender`, `type`,
//! `state_key` and `content` keys present.
std::vector<events::collections::StrippedEvents> knock_state;
//! Returns the name of the room.
std::string name() const;
//! Returns the URL for the avatar of the room.
std::string avatar() const;
friend void from_json(const nlohmann::json &obj, KnockedRoom &room);
};
//! Room updates.
struct Rooms
{
......@@ -130,6 +145,9 @@ struct Rooms
//! The rooms that the user has been invited to.
std::map<std::string, InvitedRoom> invite;
//! The rooms that the user has knocked on.
std::map<std::string, KnockedRoom> knock;
friend void from_json(const nlohmann::json &obj, Rooms &rooms);
};
......
......@@ -139,19 +139,54 @@ from_json(const json &obj, InvitedRoom &room)
utils::parse_stripped_events(obj.at("invite_state").at("events"), room.invite_state);
}
void
from_json(const json &obj, KnockedRoom &room)
{
utils::parse_stripped_events(obj.at("knock_state").at("events"), room.knock_state);
}
void
from_json(const json &obj, Rooms &rooms)
{
if (obj.count("join") != 0) {
rooms.join = obj.at("join").get<std::map<std::string, JoinedRoom>>();
if (auto entries = obj.find("join"); entries != obj.end()) {
for (const auto &r : entries->items()) {
if (r.key().size() < 256) {
rooms.join.emplace_hint(rooms.join.end(), r.key(), r.value().get<JoinedRoom>());
} else {
mtx::utils::log::log()->warn("Skipping roomid which exceeds 255 bytes.");
}
}
}
if (auto entries = obj.find("leave"); entries != obj.end()) {
for (const auto &r : entries->items()) {
if (r.key().size() < 256) {
rooms.leave.emplace_hint(rooms.leave.end(), r.key(), r.value().get<LeftRoom>());
} else {
mtx::utils::log::log()->warn("Skipping roomid which exceeds 255 bytes.");
}
}
}
if (obj.count("leave") != 0) {
rooms.leave = obj.at("leave").get<std::map<std::string, LeftRoom>>();
if (auto entries = obj.find("invite"); entries != obj.end()) {
for (const auto &r : entries->items()) {
if (r.key().size() < 256) {
rooms.invite.emplace_hint(
rooms.invite.end(), r.key(), r.value().get<InvitedRoom>());
} else {
mtx::utils::log::log()->warn("Skipping roomid which exceeds 255 bytes.");
}
}
}
if (obj.count("invite") != 0) {
rooms.invite = obj.at("invite").get<std::map<std::string, InvitedRoom>>();
if (auto entries = obj.find("knock"); entries != obj.end()) {
for (const auto &r : entries->items()) {
if (r.key().size() < 256) {
rooms.knock.emplace_hint(rooms.knock.end(), r.key(), r.value().get<KnockedRoom>());
} else {
mtx::utils::log::log()->warn("Skipping roomid which exceeds 255 bytes.");
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment