Compare commits

...

3 commits

Author SHA1 Message Date
LDA
dfb950bc7f [MOD] Use keyed schemas for the sync
Some checks are pending
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Waiting to run
2024-08-27 18:56:38 +02:00
LDA
0a45cebbfe Merge branch 'master' of https://git.telodendria.io/Telodendria/Telodendria into roomwerk 2024-08-27 18:30:53 +02:00
lda
775b1d9571 Use hashtypes(c.f Cytoplasm#47) (#57)
This makes Telodendria compatible with Telodendria/Cytoplasm#47.

---

Please review the developer certificate of origin:

1. The contribution was created in whole or in part by me, and I have
the right to submit it under the open source licenses of the
Telodendria project; or
1. The contribution is based upon a previous work that, to the best of
my knowledge, is covered under an appropriate open source license and
I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
Telodendria project license; or
1. The contribution was provided directly to me by some other person
who certified (1), (2), or (3), and I have not modified it.
1. I understand and agree that this project and the contribution are
made public and that a record of the contribution—including all
personal information I submit with it—is maintained indefinitely
and may be redistributed consistent with this project or the open
source licenses involved.

- [x] I have read the Telodendria Project development certificate of
origin, and I certify that I have permission to submit this patch
under the conditions specified in it.

Co-authored-by: Jordan Bancino <jordan@bancino.net>
Co-authored-by: LDA <lda@ari.lt>
Reviewed-on: Telodendria/Telodendria#57
Co-authored-by: lda <lda@freetards.xyz>
Co-committed-by: lda <lda@freetards.xyz>
2024-08-27 09:47:25 -04:00
4 changed files with 25 additions and 27 deletions

View file

@ -88,8 +88,8 @@
}, },
"Rooms": { "Rooms": {
"fields": { "fields": {
"invite": { "type": "object" }, "invite": { "type": "{InvitedRooms}" },
"join": { "type": "object" } "join": { "type": "{JoinedRooms}" }
}, },
"type": "struct" "type": "struct"
}, },

View file

@ -155,22 +155,19 @@ ROUTE_IMPL(RouteSync, path, argp)
for (i = 0; i < ArraySize(invites); i++) for (i = 0; i < ArraySize(invites); i++)
{ {
char *roomId = ArrayGet(invites, i); char *roomId = ArrayGet(invites, i);
InvitedRooms invited = { 0 }; InvitedRooms *invited;
HashMap *invitedObject;
if (IsRoomFiltered(filterData, roomId)) if (IsRoomFiltered(filterData, roomId))
{ {
continue; continue;
} }
invited.invite_state.events = ArrayCreate(); invited = Malloc(sizeof(*invited));
invitedObject = InvitedRoomsToJson(&invited); memset(invited, 0, sizeof(*invited));
JsonSet(
sync.rooms.invite, /* TODO: Populate the invitestate */
JsonValueObject(invitedObject), invited->invite_state.events = ArrayCreate();
1, roomId HashMapSet(sync.rooms.invite, roomId, invited);
);
InvitedRoomsFree(&invited);
} }
UserFreeList(invites); UserFreeList(invites);
@ -180,10 +177,9 @@ ROUTE_IMPL(RouteSync, path, argp)
{ {
/* TODO: Rename these variables */ /* TODO: Rename these variables */
char *roomId = ArrayGet(joins, i); char *roomId = ArrayGet(joins, i);
JoinedRooms joined = { 0 }; JoinedRooms *joined;
char *firstEvent = NULL; char *firstEvent = NULL;
char *type, *key, *id; char *type, *key, *id;
HashMap *joinedObj;
State *state; State *state;
Array *el; Array *el;
size_t j; size_t j;
@ -194,12 +190,14 @@ ROUTE_IMPL(RouteSync, path, argp)
continue; continue;
} }
joined = Malloc(sizeof(*joined));
memset(joined, 0, sizeof(*joined));
el = UserGetEvents(user, currBatch, roomId); el = UserGetEvents(user, currBatch, roomId);
r = RoomLock(db, roomId); r = RoomLock(db, roomId);
state = StateCurrent(r); state = StateCurrent(r);
joined.timeline.events = ArrayCreate(); joined->timeline.events = ArrayCreate();
for (j = 0; j < ArraySize(el); j++) for (j = 0; j < ArraySize(el); j++)
{ {
char *event = ArrayGet(el, j); char *event = ArrayGet(el, j);
@ -217,18 +215,18 @@ ROUTE_IMPL(RouteSync, path, argp)
firstEvent = c->event_id; firstEvent = c->event_id;
} }
ArrayAdd(joined.timeline.events, c); ArrayAdd(joined->timeline.events, c);
} }
JsonFree(eventObj); JsonFree(eventObj);
JsonFree(filteredObj); JsonFree(filteredObj);
} }
joined.timeline.prev_batch = UserNewMessageToken( joined->timeline.prev_batch = UserNewMessageToken(
user, roomId, firstEvent user, roomId, firstEvent
); );
/* TODO: Don't shove the entire state. /* TODO: Don't shove the entire state.
* That's a recipe for disaster, especially on large rooms. */ * That's a recipe for disaster, especially on large rooms. */
joined.state.events = ArrayCreate(); joined->state.events = ArrayCreate();
while (StateIterate(state, &type, &key, (void **) &id)) while (StateIterate(state, &type, &key, (void **) &id))
{ {
HashMap *e = RoomEventFetch(r, id); HashMap *e = RoomEventFetch(r, id);
@ -238,7 +236,7 @@ ROUTE_IMPL(RouteSync, path, argp)
JsonFree(e); JsonFree(e);
ArrayAdd(joined.state.events, s); ArrayAdd(joined->state.events, s);
Free(type); Free(type);
Free(key); Free(key);
} }
@ -247,9 +245,7 @@ ROUTE_IMPL(RouteSync, path, argp)
RoomUnlock(r); RoomUnlock(r);
UserFreeList(el); UserFreeList(el);
joinedObj = JoinedRoomsToJson(&joined); HashMapSet(sync.rooms.join, roomId, joined);
HashMapSet(sync.rooms.join, roomId, JsonValueObject(joinedObj));
JoinedRoomsFree(&joined);
} }
UserFreeList(joins); UserFreeList(joins);

View file

@ -77,10 +77,12 @@ V1Cmp(void *a, void *b)
JsonValueAsString(JsonGet(e1, 1, "event_id")); JsonValueAsString(JsonGet(e1, 1, "event_id"));
char *e2id = char *e2id =
JsonValueAsString(JsonGet(e2, 1, "event_id")); JsonValueAsString(JsonGet(e2, 1, "event_id"));
/* Matrix, *seriously*? */
unsigned char *sha1 = Sha1(e1id); unsigned char *sha1 = Sha1(e1id);
unsigned char *sha2 = Sha1(e2id); unsigned char *sha2 = Sha1(e2id);
char *str1 = ShaToHex(sha1); char *str1 = ShaToHex(sha1, HASH_SHA1);
char *str2 = ShaToHex(sha2); char *str2 = ShaToHex(sha2, HASH_SHA1);
int ret = strcmp(str1, str2) * -1; int ret = strcmp(str1, str2) * -1;
Free(str1); Free(str1);

View file

@ -411,7 +411,7 @@ UserCheckPassword(User * user, char *password)
tmp = StrConcat(2, password, salt); tmp = StrConcat(2, password, salt);
hashBytes = Sha256(tmp); hashBytes = Sha256(tmp);
hashedPwd = ShaToHex(hashBytes); hashedPwd = ShaToHex(hashBytes, HASH_SHA256);
Free(tmp); Free(tmp);
Free(hashBytes); Free(hashBytes);
@ -442,7 +442,7 @@ UserSetPassword(User * user, char *password)
salt = StrRandom(16); salt = StrRandom(16);
tmpstr = StrConcat(2, password, salt); tmpstr = StrConcat(2, password, salt);
hashBytes = Sha256(tmpstr); hashBytes = Sha256(tmpstr);
hash = ShaToHex(hashBytes); hash = ShaToHex(hashBytes, HASH_SHA256);
JsonValueFree(HashMapSet(json, "salt", JsonValueString(salt))); JsonValueFree(HashMapSet(json, "salt", JsonValueString(salt)));
JsonValueFree(HashMapSet(json, "password", JsonValueString(hash))); JsonValueFree(HashMapSet(json, "password", JsonValueString(hash)));