From ae38791df2c5291df809c21a1356b088935695fb Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Wed, 19 Apr 2023 02:07:38 +0000 Subject: [PATCH] Format code, remove dataDir from sample production.conf --- contrib/production.conf | 1 - src/Config.c | 10 +++++----- src/Json.c | 4 ++-- src/Main.c | 3 ++- src/Routes/RouteChangePwd.c | 1 + src/Routes/RouteLogin.c | 5 +++-- src/Routes/RouteRegister.c | 3 ++- src/Routes/RouteUserProfile.c | 1 + src/Routes/RouteWellKnown.c | 1 + src/Routes/RouteWhoami.c | 1 + src/Telodendria.c | 1 - src/include/Config.h | 12 ++++++------ src/include/Db.h | 2 +- src/include/Main.h | 33 ++++++++++++++++++++++++++++----- 14 files changed, 53 insertions(+), 25 deletions(-) diff --git a/contrib/production.conf b/contrib/production.conf index a5ef83b..c973fb4 100644 --- a/contrib/production.conf +++ b/contrib/production.conf @@ -2,7 +2,6 @@ "log": { "output": "file" }, - "dataDir": "/var/telodendria", "listen": [ { "port": 8008, diff --git a/src/Config.c b/src/Config.c index 383933c..221cc6a 100644 --- a/src/Config.c +++ b/src/Config.c @@ -323,7 +323,7 @@ ConfigFree(Config * tConfig) } Config * -ConfigParse(HashMap *config) +ConfigParse(HashMap * config) { Config *tConfig; JsonValue *value; @@ -416,13 +416,13 @@ error: } int -ConfigExists(Db *db) +ConfigExists(Db * db) { return DbExists(db, 1, "config"); } int -ConfigCreateDefault(Db *db) +ConfigCreateDefault(Db * db) { DbRef *ref; HashMap *json; @@ -466,7 +466,7 @@ ConfigCreateDefault(Db *db) } Config * -ConfigLock(Db *db) +ConfigLock(Db * db) { Config *config; DbRef *ref = DbLock(db, 1, "config"); @@ -487,7 +487,7 @@ ConfigLock(Db *db) } int -ConfigUnlock(Config *config) +ConfigUnlock(Config * config) { Db *db; DbRef *dbRef; diff --git a/src/Json.c b/src/Json.c index 74b4f4f..c4e7639 100644 --- a/src/Json.c +++ b/src/Json.c @@ -715,7 +715,7 @@ JsonFree(HashMap * object) } JsonValue * -JsonValueDuplicate(JsonValue *val) +JsonValueDuplicate(JsonValue * val) { JsonValue *new; size_t i; @@ -733,7 +733,7 @@ JsonValueDuplicate(JsonValue *val) new->type = val->type; - switch(val->type) + switch (val->type) { case JSON_OBJECT: new->as.object = JsonDuplicate(val->as.object); diff --git a/src/Main.c b/src/Main.c index 15a6130..84b4b16 100644 --- a/src/Main.c +++ b/src/Main.c @@ -292,7 +292,8 @@ start: Log(LOG_ERR, "Please restore from a backup."); exit = EXIT_FAILURE; goto finish; - } else if (!tConfig->ok) + } + else if (!tConfig->ok) { Log(LOG_ERR, tConfig->err); exit = EXIT_FAILURE; diff --git a/src/Routes/RouteChangePwd.c b/src/Routes/RouteChangePwd.c index 1d647fc..90fee75 100644 --- a/src/Routes/RouteChangePwd.c +++ b/src/Routes/RouteChangePwd.c @@ -66,6 +66,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp) char *newPassword; Config *config = ConfigLock(db); + if (!config) { Log(LOG_ERR, "Password endpoint failed to lock configuration."); diff --git a/src/Routes/RouteLogin.c b/src/Routes/RouteLogin.c index f07b668..ac94a83 100644 --- a/src/Routes/RouteLogin.c +++ b/src/Routes/RouteLogin.c @@ -58,6 +58,7 @@ ROUTE_IMPL(RouteLogin, path, argp) char *fullUsername; Config *config = ConfigLock(db); + if (!config) { Log(LOG_ERR, "Login endpoint failed to lock configuration."); @@ -283,13 +284,13 @@ ROUTE_IMPL(RouteLogin, path, argp) } fullUsername = StrConcat(4, "@", UserGetName(user), ":", - config->serverName); + config->serverName); HashMapSet(response, "user_id", JsonValueString(fullUsername)); Free(fullUsername); HashMapSet(response, "well_known", JsonValueObject( - MatrixClientWellKnown(config->baseUrl, config->identityServer))); + MatrixClientWellKnown(config->baseUrl, config->identityServer))); UserAccessTokenFree(loginInfo->accessToken); Free(loginInfo->refreshToken); diff --git a/src/Routes/RouteRegister.c b/src/Routes/RouteRegister.c index 6b84573..0f3f543 100644 --- a/src/Routes/RouteRegister.c +++ b/src/Routes/RouteRegister.c @@ -78,6 +78,7 @@ ROUTE_IMPL(RouteRegister, path, argp) DbRef *sessionRef; Config *config = ConfigLock(db); + if (!config) { Log(LOG_ERR, "Registration endpoint failed to lock configuration."); @@ -137,7 +138,7 @@ ROUTE_IMPL(RouteRegister, path, argp) } uiaResult = UiaComplete(uiaFlows, args->context, - db, request, &response, + db, request, &response, config); if (uiaResult < 0) diff --git a/src/Routes/RouteUserProfile.c b/src/Routes/RouteUserProfile.c index fe473a5..f329a34 100644 --- a/src/Routes/RouteUserProfile.c +++ b/src/Routes/RouteUserProfile.c @@ -49,6 +49,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp) char *value = NULL; Config *config = ConfigLock(db); + if (!config) { Log(LOG_ERR, "User profile endpoint failed to lock configuration."); diff --git a/src/Routes/RouteWellKnown.c b/src/Routes/RouteWellKnown.c index cee62f2..7fbeb2c 100644 --- a/src/Routes/RouteWellKnown.c +++ b/src/Routes/RouteWellKnown.c @@ -36,6 +36,7 @@ ROUTE_IMPL(RouteWellKnown, path, argp) HashMap *response; Config *config = ConfigLock(args->matrixArgs->db); + if (!config) { Log(LOG_ERR, "Well-known endpoint failed to lock configuration."); diff --git a/src/Routes/RouteWhoami.c b/src/Routes/RouteWhoami.c index 3967db4..b627cbb 100644 --- a/src/Routes/RouteWhoami.c +++ b/src/Routes/RouteWhoami.c @@ -46,6 +46,7 @@ ROUTE_IMPL(RouteWhoami, path, argp) char *deviceID; Config *config = ConfigLock(db); + if (!config) { Log(LOG_ERR, "Who am I endpoint failed to lock configuration."); diff --git a/src/Telodendria.c b/src/Telodendria.c index 68db2a9..d504af6 100644 --- a/src/Telodendria.c +++ b/src/Telodendria.c @@ -197,4 +197,3 @@ TelodendriaPrintHeader(void) "Documentation/Support: https://telodendria.io"); Log(LOG_INFO, ""); } - diff --git a/src/include/Config.h b/src/include/Config.h index 06a335a..e3833bd 100644 --- a/src/include/Config.h +++ b/src/include/Config.h @@ -65,21 +65,21 @@ typedef struct Config } Config; Config * -ConfigParse(HashMap *); + ConfigParse(HashMap *); void -ConfigFree(Config *); + ConfigFree(Config *); extern int -ConfigExists(Db *); + ConfigExists(Db *); extern int -ConfigCreateDefault(Db *); + ConfigCreateDefault(Db *); extern Config * -ConfigLock(Db *); + ConfigLock(Db *); extern int -ConfigUnlock(Config *); + ConfigUnlock(Config *); #endif /* TELODENDRIA_CONFIG_H */ diff --git a/src/include/Db.h b/src/include/Db.h index e0fc9cc..9b6f6dc 100644 --- a/src/include/Db.h +++ b/src/include/Db.h @@ -36,7 +36,7 @@ extern Db * DbOpen(char *, size_t); extern void -DbMaxCacheSet(Db *, size_t); + DbMaxCacheSet(Db *, size_t); extern void DbClose(Db *); diff --git a/src/include/Main.h b/src/include/Main.h index 5e8676c..3fc883c 100644 --- a/src/include/Main.h +++ b/src/include/Main.h @@ -1,16 +1,39 @@ +/* + * Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ #ifndef TELODENDRIA_MAIN_H #define TELODENDRIA_MAIN_H extern void -Restart(void); + Restart(void); extern void -Shutdown(void); + Shutdown(void); extern unsigned long -Uptime(void); + Uptime(void); extern int -main(int argc, char **argv); + main(int argc, char **argv); -#endif /* TELODENDRIA_MAIN_H */ +#endif /* TELODENDRIA_MAIN_H */