diff --git a/src/Room.c b/src/Room.c index a4a5b97..2d80358 100644 --- a/src/Room.c +++ b/src/Room.c @@ -189,26 +189,26 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s) } /* Write out presets */ -#define SetIfExistent(pset) do { \ - if (pset##_preset) \ +#define SetIfExistent(p,a) do { \ + if (p##_preset) \ { \ content = HashMapCreate(); \ JsonSet( \ content, \ JsonValueString(join_rules_preset) \ - , 1, #pset); \ + , 1, a); \ event = RoomEventCreate( \ sender_str, \ - "m.room." #pset, "", content); \ + "m.room." #p, "", content); \ JsonFree(RoomEventSend(room, event)); \ JsonFree(event); \ } \ } \ while (0) - SetIfExistent(join_rules); - SetIfExistent(history_visibility); - SetIfExistent(guest_access); + SetIfExistent(join_rules, "join_rule"); + SetIfExistent(history_visibility, "history_visibility"); + SetIfExistent(guest_access, "guest_access"); #undef SetIfExistent /* User-provided initial states */ @@ -501,7 +501,7 @@ RoomIsJoinRule(Room * room, HashMap *state, char *jr) PrepareState(room, state, "m.room.join_rules", "", joinrule); ret = StrEquals( - JsonValueAsString(JsonGet(joinrule, 1, "join_rule")), + JsonValueAsString(JsonGet(joinrule, 2, "content", "join_rule")), jr); finish: FinishState(joinrule); @@ -1629,7 +1629,7 @@ RoomEventSendV1(Room * room, HashMap * event) { /* Reject this event as the current state does not allow it. * TODO: Make the auth check function return a string showing the - * error status to the user. */ + * errorr status to the user. */ goto finish; } RoomAddEventV1(room, pdu); @@ -2080,7 +2080,7 @@ RoomCanJoin(Room *room, char *user) room, StateGet(state, "m.room.join_rules", "") ); - joinRuleV = JsonValueAsString(HashMapGet(joinRule, "join_rule")); + joinRuleV = JsonValueAsString(JsonGet(joinRule, 2, "content", "join_rule")); if (StrEquals(joinRuleV, "public")) { diff --git a/src/Routes/RouteJoinRoom.c b/src/Routes/RouteJoinRoom.c index a0b324f..1069035 100644 --- a/src/Routes/RouteJoinRoom.c +++ b/src/Routes/RouteJoinRoom.c @@ -123,6 +123,14 @@ ROUTE_IMPL(RouteJoinRoom, path, argp) sender = ParserRecomposeCommonID(*id); room = RoomLock(db, roomId); + if (!room) + { + + err = "Room ID does not exist."; + HttpResponseStatus(args->context, HTTP_BAD_REQUEST); + response = MatrixErrorCreate(M_UNKNOWN, err); + goto finish; + } if (RoomContainsUser(room, sender)) { err = "User is already in the room."; @@ -151,6 +159,7 @@ ROUTE_IMPL(RouteJoinRoom, path, argp) finish: UserIdFree(id); + JsonFree(request); if (sender) { Free(sender); diff --git a/src/Routes/RouteVersions.c b/src/Routes/RouteVersions.c index 08560c3..ffa649b 100644 --- a/src/Routes/RouteVersions.c +++ b/src/Routes/RouteVersions.c @@ -37,6 +37,9 @@ ROUTE_IMPL(RouteVersions, path, argp) (void) argp; #define DECLARE_SPEC_VERSION(x) ArrayAdd(versions, JsonValueString(x)) + DECLARE_SPEC_VERSION("v1.0"); + DECLARE_SPEC_VERSION("v1.1"); + DECLARE_SPEC_VERSION("v1.2"); DECLARE_SPEC_VERSION("v1.3"); DECLARE_SPEC_VERSION("v1.4");