[ADD/WIP] Try to parse a filter from raw JSON
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

This commit is contained in:
LDA 2024-08-14 02:59:40 +02:00
parent 3e5d9dbe62
commit 2b6805672b
3 changed files with 32 additions and 13 deletions

View file

@ -29,6 +29,7 @@
#include <Cytoplasm/Str.h>
#include <string.h>
#include <stdio.h>
#include <Schema/Filter.h>
@ -204,6 +205,11 @@ FilterDecode(Db *db, char *user, char *filterStr, char **errp)
Filter *ret;
DbRef *filterRef;
HashMap *filterObj;
FILE *fakeFile;
Stream *fakeStream;
char *err;
if (!db || !user || !filterStr)
{
if (errp)
@ -216,8 +222,6 @@ FilterDecode(Db *db, char *user, char *filterStr, char **errp)
if (*filterStr != '{')
{
char *err;
filterRef = DbLock(db, 3, "filters", user, filterStr);
filterObj = DbJson(filterRef);
ret = Malloc(sizeof(*ret));
@ -238,14 +242,30 @@ FilterDecode(Db *db, char *user, char *filterStr, char **errp)
return ret;
}
/* TODO: Decode JSON here... */
/* TODO: This should be it's own JSON function, in my
* opinion. */
fakeFile = fmemopen(filterStr, strlen(filterStr), "r");
fakeStream = StreamFile(fakeFile);
filterObj = JsonDecode(fakeStream);
StreamClose(fakeStream); /* auto-frees fakeFile */
ret = Malloc(sizeof(*ret));
memset(ret, 0, sizeof(*ret));
if (!FilterFromJson(filterObj, ret, &err))
{
if (errp)
{
*errp = "Unimplemented feature: decoding from a raw JSON object";
*errp = err;
}
JsonFree(filterObj);
Free(ret);
return NULL;
}
JsonFree(filterObj);
return ret;
}
void
FilterDestroy(Filter *filter)
{

View file

@ -1744,8 +1744,7 @@ UserAwaitNotification(char *user, int await)
}
else if (entry)
{
/* Another thread's awaiting...
* TODO: Manage these conditions. */
/* Another thread's awaiting... TODO: Manage these conditions. */
Log(LOG_ERR,
"Unimplemented feature: awaiting for other threads."
);
@ -1783,7 +1782,7 @@ UserAwaitNotification(char *user, int await)
while (!entry->notified)
{
code = pthread_cond_timedwait(&entry->cond, &entry->lock, &timeout);
if ((code == ETIMEDOUT))
if (code == ETIMEDOUT)
{
timedout = true;
break;