forked from Telodendria/Telodendria
[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
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:
parent
3e5d9dbe62
commit
2b6805672b
3 changed files with 32 additions and 13 deletions
32
src/Filter.c
32
src/Filter.c
|
@ -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,12 +242,28 @@ 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
|
||||||
if (errp)
|
* 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))
|
||||||
{
|
{
|
||||||
*errp = "Unimplemented feature: decoding from a raw JSON object";
|
if (errp)
|
||||||
|
{
|
||||||
|
*errp = err;
|
||||||
|
}
|
||||||
|
JsonFree(filterObj);
|
||||||
|
Free(ret);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
|
JsonFree(filterObj);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -52,8 +52,8 @@ ROUTE_IMPL(RouteStaticLogin, path, argp)
|
||||||
StreamPuts(stream,
|
StreamPuts(stream,
|
||||||
"function buildRequest(user, pass) {"
|
"function buildRequest(user, pass) {"
|
||||||
" var d = findGetParameter('device_id');"
|
" var d = findGetParameter('device_id');"
|
||||||
" var i = findGetParameter('initial_device_display_name');"
|
" var i = findGetParameter('initial_device_display_name');"
|
||||||
" var r = findGetParameter('refresh_token') === 'true';"
|
" var r = findGetParameter('refresh_token') === 'true';"
|
||||||
" var request = {};"
|
" var request = {};"
|
||||||
" request['type'] = 'm.login.password';"
|
" request['type'] = 'm.login.password';"
|
||||||
" request['identifier'] = {"
|
" request['identifier'] = {"
|
||||||
|
@ -88,9 +88,9 @@ ROUTE_IMPL(RouteStaticLogin, path, argp)
|
||||||
StreamPuts(stream,
|
StreamPuts(stream,
|
||||||
"onFormSubmit('login-form', (frm) => {"
|
"onFormSubmit('login-form', (frm) => {"
|
||||||
" var user = document.getElementById('user').value;"
|
" var user = document.getElementById('user').value;"
|
||||||
" var pass = document.getElementById('password').value;"
|
" var pass = document.getElementById('password').value;"
|
||||||
" if (!user || !pass) {"
|
" if (!user || !pass) {"
|
||||||
" setFormError('Please provide a username and password.');"
|
" setFormError('Please provide a username and password.');"
|
||||||
" return;"
|
" return;"
|
||||||
" }"
|
" }"
|
||||||
" setFormError(null);"
|
" setFormError(null);"
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue