[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 <Cytoplasm/Str.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <Schema/Filter.h> #include <Schema/Filter.h>
@ -204,6 +205,11 @@ FilterDecode(Db *db, char *user, char *filterStr, char **errp)
Filter *ret; Filter *ret;
DbRef *filterRef; DbRef *filterRef;
HashMap *filterObj; HashMap *filterObj;
FILE *fakeFile;
Stream *fakeStream;
char *err;
if (!db || !user || !filterStr) if (!db || !user || !filterStr)
{ {
if (errp) if (errp)
@ -216,8 +222,6 @@ FilterDecode(Db *db, char *user, char *filterStr, char **errp)
if (*filterStr != '{') if (*filterStr != '{')
{ {
char *err;
filterRef = DbLock(db, 3, "filters", user, filterStr); filterRef = DbLock(db, 3, "filters", user, filterStr);
filterObj = DbJson(filterRef); filterObj = DbJson(filterRef);
ret = Malloc(sizeof(*ret)); ret = Malloc(sizeof(*ret));
@ -238,14 +242,30 @@ FilterDecode(Db *db, char *user, char *filterStr, char **errp)
return ret; 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) if (errp)
{ {
*errp = "Unimplemented feature: decoding from a raw JSON object"; *errp = err;
} }
JsonFree(filterObj);
Free(ret);
return NULL; return NULL;
} }
JsonFree(filterObj);
return ret;
}
void void
FilterDestroy(Filter *filter) FilterDestroy(Filter *filter)
{ {

View file

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