forked from Telodendria/Telodendria
[ADD/UNTESTED] Set ServerPart on room creation
Not tested as of now!
This commit is contained in:
parent
9ffa37d7a7
commit
1753c2188b
3 changed files with 27 additions and 10 deletions
26
src/Room.c
26
src/Room.c
|
@ -63,15 +63,22 @@ struct Room
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
GenerateRoomId(void)
|
GenerateRoomId(ServerPart s)
|
||||||
{
|
{
|
||||||
return StrRandom(32); /* TODO: Add extra room info somehow
|
CommonID cid;
|
||||||
* (I don't feel like theres really a way to
|
char *string;
|
||||||
* get the server info where we're doing that.) */
|
|
||||||
|
cid.sigil = '!';
|
||||||
|
cid.local = StrRandom(32);
|
||||||
|
cid.server = s;
|
||||||
|
string = ParserRecomposeCommonID(cid);
|
||||||
|
Free(cid.local);
|
||||||
|
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
Room *
|
Room *
|
||||||
RoomCreate(Db * db, User *user, RoomCreateRequest * req)
|
RoomCreate(Db * db, User *user, RoomCreateRequest * req, ServerPart s)
|
||||||
{
|
{
|
||||||
Room *room;
|
Room *room;
|
||||||
char *version_string, *full_creator;
|
char *version_string, *full_creator;
|
||||||
|
@ -92,9 +99,9 @@ RoomCreate(Db * db, User *user, RoomCreateRequest * req)
|
||||||
}
|
}
|
||||||
room = Malloc(sizeof(Room));
|
room = Malloc(sizeof(Room));
|
||||||
room->db = db;
|
room->db = db;
|
||||||
room->id = GenerateRoomId(); /* TODO: Check config. */
|
room->creator.hostname = s.hostname ? StrDuplicate(s.hostname) : NULL;
|
||||||
room->creator.hostname = NULL;
|
room->creator.port = s.port ? StrDuplicate(s.port) : NULL;
|
||||||
room->creator.port = NULL;
|
room->id = GenerateRoomId(s);
|
||||||
room->version = version_num;
|
room->version = version_num;
|
||||||
|
|
||||||
room->state_ref = DbCreate(db, 3, "rooms", room->id, "state");
|
room->state_ref = DbCreate(db, 3, "rooms", room->id, "state");
|
||||||
|
@ -1350,6 +1357,9 @@ RoomEventSendV1(Room * room, HashMap * event)
|
||||||
RoomAddEventV1(room, pdu);
|
RoomAddEventV1(room, pdu);
|
||||||
valid = true;
|
valid = true;
|
||||||
|
|
||||||
|
/* If it is a client event, we should make sure that we shout at
|
||||||
|
* every other homeserver about our new event. */
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,12 +41,17 @@ ROUTE_IMPL(RouteCreateRoom, path, argp)
|
||||||
Db *db = args->matrixArgs->db;
|
Db *db = args->matrixArgs->db;
|
||||||
RoomCreateRequest parsed;
|
RoomCreateRequest parsed;
|
||||||
User *user = NULL;
|
User *user = NULL;
|
||||||
|
Config cfg;
|
||||||
|
ServerPart server;
|
||||||
|
|
||||||
char *token;
|
char *token;
|
||||||
char *err;
|
char *err;
|
||||||
|
|
||||||
(void) path;
|
(void) path;
|
||||||
|
|
||||||
|
ConfigLock(db, &cfg);
|
||||||
|
ParseServerPart(cfg.serverName, &server);
|
||||||
|
|
||||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||||
{
|
{
|
||||||
err = "Unknown request method.";
|
err = "Unknown request method.";
|
||||||
|
@ -86,7 +91,7 @@ ROUTE_IMPL(RouteCreateRoom, path, argp)
|
||||||
JsonFree(request);
|
JsonFree(request);
|
||||||
request = NULL;
|
request = NULL;
|
||||||
|
|
||||||
if (!(room = RoomCreate(db, user, &parsed)))
|
if (!(room = RoomCreate(db, user, &parsed, server)))
|
||||||
{
|
{
|
||||||
err = "Couldn't create room.";
|
err = "Couldn't create room.";
|
||||||
/* Consider another error status. */
|
/* Consider another error status. */
|
||||||
|
@ -102,5 +107,7 @@ finish:
|
||||||
JsonFree(request);
|
JsonFree(request);
|
||||||
RoomUnlock(room);
|
RoomUnlock(room);
|
||||||
UserUnlock(user);
|
UserUnlock(user);
|
||||||
|
ConfigUnlock(&cfg);
|
||||||
|
ServerPartFree(server);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ typedef struct Room Room;
|
||||||
* Create a new room in the given database using the given
|
* Create a new room in the given database using the given
|
||||||
* RoomCreateRequest.
|
* RoomCreateRequest.
|
||||||
*/
|
*/
|
||||||
extern Room * RoomCreate(Db *, User *, RoomCreateRequest *);
|
extern Room * RoomCreate(Db *, User *, RoomCreateRequest *, ServerPart);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock the existing room in the specified database,
|
* Lock the existing room in the specified database,
|
||||||
|
|
Loading…
Reference in a new issue