diff --git a/src/Filter.c b/src/Filter.c index d08fe87..9fee396 100644 --- a/src/Filter.c +++ b/src/Filter.c @@ -29,6 +29,7 @@ #include #include +#include #include @@ -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,12 +242,28 @@ FilterDecode(Db *db, char *user, char *filterStr, char **errp) return ret; } - /* TODO: Decode JSON here... */ - if (errp) + /* 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)) { - *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 diff --git a/src/Routes/RouteStaticLogin.c b/src/Routes/RouteStaticLogin.c index 13748fa..ffcd2d6 100644 --- a/src/Routes/RouteStaticLogin.c +++ b/src/Routes/RouteStaticLogin.c @@ -52,8 +52,8 @@ ROUTE_IMPL(RouteStaticLogin, path, argp) StreamPuts(stream, "function buildRequest(user, pass) {" " var d = findGetParameter('device_id');" - " var i = findGetParameter('initial_device_display_name');" - " var r = findGetParameter('refresh_token') === 'true';" + " var i = findGetParameter('initial_device_display_name');" + " var r = findGetParameter('refresh_token') === 'true';" " var request = {};" " request['type'] = 'm.login.password';" " request['identifier'] = {" @@ -88,9 +88,9 @@ ROUTE_IMPL(RouteStaticLogin, path, argp) StreamPuts(stream, "onFormSubmit('login-form', (frm) => {" " var user = document.getElementById('user').value;" - " var pass = document.getElementById('password').value;" + " var pass = document.getElementById('password').value;" " if (!user || !pass) {" - " setFormError('Please provide a username and password.');" + " setFormError('Please provide a username and password.');" " return;" " }" " setFormError(null);" diff --git a/src/User.c b/src/User.c index 4c1e7e5..ff0dcaa 100644 --- a/src/User.c +++ b/src/User.c @@ -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;