forked from Telodendria/Telodendria
[MOD/FIX] Leaves, fix leaks
Some checks failed
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Has been cancelled
Some checks failed
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Has been cancelled
This commit is contained in:
parent
fde6f092b4
commit
19359045e9
4 changed files with 77 additions and 31 deletions
|
@ -2341,10 +2341,6 @@ RoomJoin(Room *room, User *user)
|
||||||
pdu = RoomEventSend(room, event);
|
pdu = RoomEventSend(room, event);
|
||||||
|
|
||||||
ret = !!pdu;
|
ret = !!pdu;
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
UserAddJoin(user, room->id);
|
|
||||||
}
|
|
||||||
end:
|
end:
|
||||||
UserIdFree(userId);
|
UserIdFree(userId);
|
||||||
JsonFree(event);
|
JsonFree(event);
|
||||||
|
|
|
@ -81,7 +81,7 @@ RouterBuild(void)
|
||||||
R("/_matrix/client/v3/rooms/(.*)/state/(.*)/(.*)", RouteSendState);
|
R("/_matrix/client/v3/rooms/(.*)/state/(.*)/(.*)", RouteSendState);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/state/(.*)", RouteSendState);
|
R("/_matrix/client/v3/rooms/(.*)/state/(.*)", RouteSendState);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/event/(.*)", RouteFetchEvent);
|
R("/_matrix/client/v3/rooms/(.*)/event/(.*)", RouteFetchEvent);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/join", RouteJoinRoom);
|
R("/_matrix/client/v3/rooms/(.*)/(join|leave)", RouteJoinRoom);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/(kick|ban)", RouteKickRoom);
|
R("/_matrix/client/v3/rooms/(.*)/(kick|ban)", RouteKickRoom);
|
||||||
R("/_matrix/client/v3/rooms/(.*)/messages", RouteMessages);
|
R("/_matrix/client/v3/rooms/(.*)/messages", RouteMessages);
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ ROUTE_IMPL(RouteJoinRoom, path, argp)
|
||||||
CommonID *id = NULL;
|
CommonID *id = NULL;
|
||||||
|
|
||||||
char *roomId = ArrayGet(path, 0);
|
char *roomId = ArrayGet(path, 0);
|
||||||
|
char *action = ArrayGet(path, 1);
|
||||||
char *sender = NULL, *serverName = NULL;
|
char *sender = NULL, *serverName = NULL;
|
||||||
|
|
||||||
Room *room = NULL;
|
Room *room = NULL;
|
||||||
|
@ -107,37 +108,75 @@ ROUTE_IMPL(RouteJoinRoom, path, argp)
|
||||||
room = RoomLock(db, roomId);
|
room = RoomLock(db, roomId);
|
||||||
if (!room)
|
if (!room)
|
||||||
{
|
{
|
||||||
|
|
||||||
err = "Room ID does not exist.";
|
err = "Room ID does not exist.";
|
||||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||||
response = MatrixErrorCreate(M_UNKNOWN, err);
|
response = MatrixErrorCreate(M_UNKNOWN, err);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
if (RoomContainsUser(room, sender))
|
if (StrEquals(action, "join"))
|
||||||
{
|
{
|
||||||
err = "User is already in the room.";
|
if (RoomContainsUser(room, sender))
|
||||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
{
|
||||||
response = MatrixErrorCreate(M_FORBIDDEN, err);
|
err = "User is already in the room.";
|
||||||
goto finish;
|
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||||
}
|
response = MatrixErrorCreate(M_FORBIDDEN, err);
|
||||||
if (!RoomCanJoin(room, sender))
|
goto finish;
|
||||||
{
|
}
|
||||||
err = "User cannot be in the room.";
|
if (!RoomCanJoin(room, sender))
|
||||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
{
|
||||||
response = MatrixErrorCreate(M_FORBIDDEN, err);
|
err = "User cannot be in the room.";
|
||||||
goto finish;
|
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||||
}
|
response = MatrixErrorCreate(M_FORBIDDEN, err);
|
||||||
/* TODO: Custom reason parameter. */
|
goto finish;
|
||||||
if (!RoomJoin(room, user))
|
}
|
||||||
{
|
/* TODO: Custom reason parameter. */
|
||||||
err = "User could not be the room due to unknown reasons.";
|
if (!RoomJoin(room, user))
|
||||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
{
|
||||||
response = MatrixErrorCreate(M_UNKNOWN, err);
|
err = "User could not be the room due to unknown reasons.";
|
||||||
goto finish;
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
response = MatrixErrorCreate(M_UNKNOWN, err);
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
response = HashMapCreate();
|
response = HashMapCreate();
|
||||||
JsonSet(response, JsonValueString(roomId), 1, "room_id");
|
JsonSet(response, JsonValueString(roomId), 1, "room_id");
|
||||||
|
}
|
||||||
|
else if (StrEquals(action, "leave"))
|
||||||
|
{
|
||||||
|
HashMap *membership, *content;
|
||||||
|
HashMap *pduResponse;
|
||||||
|
|
||||||
|
if (!RoomContainsUser(room, sender))
|
||||||
|
{
|
||||||
|
err = "User is not already in the room.";
|
||||||
|
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||||
|
response = MatrixErrorCreate(M_FORBIDDEN, err);
|
||||||
|
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
content = HashMapCreate();
|
||||||
|
membership = RoomEventCreate(
|
||||||
|
sender, "m.room.member", sender,
|
||||||
|
content
|
||||||
|
);
|
||||||
|
|
||||||
|
HashMapSet(content, "membership", JsonValueString("leave"));
|
||||||
|
pduResponse = RoomEventSend(room, membership);
|
||||||
|
if (!pduResponse)
|
||||||
|
{
|
||||||
|
err = "Couldn't accept leave event";
|
||||||
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
response = MatrixErrorCreate(M_UNKNOWN, err);
|
||||||
|
|
||||||
|
JsonFree(membership);
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
JsonFree(pduResponse);
|
||||||
|
JsonFree(membership);
|
||||||
|
|
||||||
|
response = HashMapCreate();
|
||||||
|
}
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
UserIdFree(id);
|
UserIdFree(id);
|
||||||
|
@ -237,7 +276,6 @@ ROUTE_IMPL(RouteKickRoom, path, argp)
|
||||||
id->sigil = '@';
|
id->sigil = '@';
|
||||||
sender = ParserRecomposeCommonID(*id);
|
sender = ParserRecomposeCommonID(*id);
|
||||||
|
|
||||||
Log(LOG_INFO, "sender=%s", sender);
|
|
||||||
room = RoomLock(db, roomId);
|
room = RoomLock(db, roomId);
|
||||||
if (!RoomContainsUser(room, sender))
|
if (!RoomContainsUser(room, sender))
|
||||||
{
|
{
|
||||||
|
|
14
src/User.c
14
src/User.c
|
@ -1038,6 +1038,13 @@ UserAddInvite(User *user, char *roomId)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!user->inviteRef)
|
||||||
|
{
|
||||||
|
user->inviteRef = DbCreate(user->db,
|
||||||
|
3, "users", user->name, "invites"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
data = DbJson(user->inviteRef);
|
data = DbJson(user->inviteRef);
|
||||||
|
|
||||||
JsonValueFree(HashMapSet(data, roomId, JsonValueNull()));
|
JsonValueFree(HashMapSet(data, roomId, JsonValueNull()));
|
||||||
|
@ -1087,9 +1094,14 @@ UserAddJoin(User *user, char *roomId)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!user->joinRef)
|
||||||
|
{
|
||||||
|
user->joinRef = DbCreate(user->db, 3, "users", user->name, "joins");
|
||||||
|
}
|
||||||
|
|
||||||
data = DbJson(user->joinRef);
|
data = DbJson(user->joinRef);
|
||||||
|
|
||||||
if (!HashMapGet(data, roomId))
|
if (data && !HashMapGet(data, roomId))
|
||||||
{
|
{
|
||||||
JsonValueFree(HashMapSet(data, roomId, JsonValueNull()));
|
JsonValueFree(HashMapSet(data, roomId, JsonValueNull()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue