forked from lda/telodendria
Format code, remove dataDir from sample production.conf
This commit is contained in:
parent
0cca38115a
commit
ae38791df2
14 changed files with 53 additions and 25 deletions
|
@ -2,7 +2,6 @@
|
||||||
"log": {
|
"log": {
|
||||||
"output": "file"
|
"output": "file"
|
||||||
},
|
},
|
||||||
"dataDir": "/var/telodendria",
|
|
||||||
"listen": [
|
"listen": [
|
||||||
{
|
{
|
||||||
"port": 8008,
|
"port": 8008,
|
||||||
|
|
10
src/Config.c
10
src/Config.c
|
@ -323,7 +323,7 @@ ConfigFree(Config * tConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
Config *
|
Config *
|
||||||
ConfigParse(HashMap *config)
|
ConfigParse(HashMap * config)
|
||||||
{
|
{
|
||||||
Config *tConfig;
|
Config *tConfig;
|
||||||
JsonValue *value;
|
JsonValue *value;
|
||||||
|
@ -416,13 +416,13 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ConfigExists(Db *db)
|
ConfigExists(Db * db)
|
||||||
{
|
{
|
||||||
return DbExists(db, 1, "config");
|
return DbExists(db, 1, "config");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ConfigCreateDefault(Db *db)
|
ConfigCreateDefault(Db * db)
|
||||||
{
|
{
|
||||||
DbRef *ref;
|
DbRef *ref;
|
||||||
HashMap *json;
|
HashMap *json;
|
||||||
|
@ -466,7 +466,7 @@ ConfigCreateDefault(Db *db)
|
||||||
}
|
}
|
||||||
|
|
||||||
Config *
|
Config *
|
||||||
ConfigLock(Db *db)
|
ConfigLock(Db * db)
|
||||||
{
|
{
|
||||||
Config *config;
|
Config *config;
|
||||||
DbRef *ref = DbLock(db, 1, "config");
|
DbRef *ref = DbLock(db, 1, "config");
|
||||||
|
@ -487,7 +487,7 @@ ConfigLock(Db *db)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ConfigUnlock(Config *config)
|
ConfigUnlock(Config * config)
|
||||||
{
|
{
|
||||||
Db *db;
|
Db *db;
|
||||||
DbRef *dbRef;
|
DbRef *dbRef;
|
||||||
|
|
|
@ -715,7 +715,7 @@ JsonFree(HashMap * object)
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue *
|
JsonValue *
|
||||||
JsonValueDuplicate(JsonValue *val)
|
JsonValueDuplicate(JsonValue * val)
|
||||||
{
|
{
|
||||||
JsonValue *new;
|
JsonValue *new;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -733,7 +733,7 @@ JsonValueDuplicate(JsonValue *val)
|
||||||
|
|
||||||
new->type = val->type;
|
new->type = val->type;
|
||||||
|
|
||||||
switch(val->type)
|
switch (val->type)
|
||||||
{
|
{
|
||||||
case JSON_OBJECT:
|
case JSON_OBJECT:
|
||||||
new->as.object = JsonDuplicate(val->as.object);
|
new->as.object = JsonDuplicate(val->as.object);
|
||||||
|
|
|
@ -292,7 +292,8 @@ start:
|
||||||
Log(LOG_ERR, "Please restore from a backup.");
|
Log(LOG_ERR, "Please restore from a backup.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (!tConfig->ok)
|
}
|
||||||
|
else if (!tConfig->ok)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, tConfig->err);
|
Log(LOG_ERR, tConfig->err);
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
|
|
|
@ -66,6 +66,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
||||||
char *newPassword;
|
char *newPassword;
|
||||||
|
|
||||||
Config *config = ConfigLock(db);
|
Config *config = ConfigLock(db);
|
||||||
|
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Password endpoint failed to lock configuration.");
|
Log(LOG_ERR, "Password endpoint failed to lock configuration.");
|
||||||
|
|
|
@ -58,6 +58,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
||||||
char *fullUsername;
|
char *fullUsername;
|
||||||
|
|
||||||
Config *config = ConfigLock(db);
|
Config *config = ConfigLock(db);
|
||||||
|
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Login endpoint failed to lock configuration.");
|
Log(LOG_ERR, "Login endpoint failed to lock configuration.");
|
||||||
|
@ -283,13 +284,13 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
||||||
}
|
}
|
||||||
|
|
||||||
fullUsername = StrConcat(4, "@", UserGetName(user), ":",
|
fullUsername = StrConcat(4, "@", UserGetName(user), ":",
|
||||||
config->serverName);
|
config->serverName);
|
||||||
HashMapSet(response, "user_id", JsonValueString(fullUsername));
|
HashMapSet(response, "user_id", JsonValueString(fullUsername));
|
||||||
Free(fullUsername);
|
Free(fullUsername);
|
||||||
|
|
||||||
HashMapSet(response, "well_known",
|
HashMapSet(response, "well_known",
|
||||||
JsonValueObject(
|
JsonValueObject(
|
||||||
MatrixClientWellKnown(config->baseUrl, config->identityServer)));
|
MatrixClientWellKnown(config->baseUrl, config->identityServer)));
|
||||||
|
|
||||||
UserAccessTokenFree(loginInfo->accessToken);
|
UserAccessTokenFree(loginInfo->accessToken);
|
||||||
Free(loginInfo->refreshToken);
|
Free(loginInfo->refreshToken);
|
||||||
|
|
|
@ -78,6 +78,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
||||||
DbRef *sessionRef;
|
DbRef *sessionRef;
|
||||||
|
|
||||||
Config *config = ConfigLock(db);
|
Config *config = ConfigLock(db);
|
||||||
|
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Registration endpoint failed to lock configuration.");
|
Log(LOG_ERR, "Registration endpoint failed to lock configuration.");
|
||||||
|
@ -137,7 +138,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
||||||
}
|
}
|
||||||
|
|
||||||
uiaResult = UiaComplete(uiaFlows, args->context,
|
uiaResult = UiaComplete(uiaFlows, args->context,
|
||||||
db, request, &response,
|
db, request, &response,
|
||||||
config);
|
config);
|
||||||
|
|
||||||
if (uiaResult < 0)
|
if (uiaResult < 0)
|
||||||
|
|
|
@ -49,6 +49,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
||||||
char *value = NULL;
|
char *value = NULL;
|
||||||
|
|
||||||
Config *config = ConfigLock(db);
|
Config *config = ConfigLock(db);
|
||||||
|
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "User profile endpoint failed to lock configuration.");
|
Log(LOG_ERR, "User profile endpoint failed to lock configuration.");
|
||||||
|
|
|
@ -36,6 +36,7 @@ ROUTE_IMPL(RouteWellKnown, path, argp)
|
||||||
HashMap *response;
|
HashMap *response;
|
||||||
|
|
||||||
Config *config = ConfigLock(args->matrixArgs->db);
|
Config *config = ConfigLock(args->matrixArgs->db);
|
||||||
|
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Well-known endpoint failed to lock configuration.");
|
Log(LOG_ERR, "Well-known endpoint failed to lock configuration.");
|
||||||
|
|
|
@ -46,6 +46,7 @@ ROUTE_IMPL(RouteWhoami, path, argp)
|
||||||
char *deviceID;
|
char *deviceID;
|
||||||
|
|
||||||
Config *config = ConfigLock(db);
|
Config *config = ConfigLock(db);
|
||||||
|
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Who am I endpoint failed to lock configuration.");
|
Log(LOG_ERR, "Who am I endpoint failed to lock configuration.");
|
||||||
|
|
|
@ -197,4 +197,3 @@ TelodendriaPrintHeader(void)
|
||||||
"Documentation/Support: https://telodendria.io");
|
"Documentation/Support: https://telodendria.io");
|
||||||
Log(LOG_INFO, "");
|
Log(LOG_INFO, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,21 +65,21 @@ typedef struct Config
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
Config *
|
Config *
|
||||||
ConfigParse(HashMap *);
|
ConfigParse(HashMap *);
|
||||||
|
|
||||||
void
|
void
|
||||||
ConfigFree(Config *);
|
ConfigFree(Config *);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
ConfigExists(Db *);
|
ConfigExists(Db *);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
ConfigCreateDefault(Db *);
|
ConfigCreateDefault(Db *);
|
||||||
|
|
||||||
extern Config *
|
extern Config *
|
||||||
ConfigLock(Db *);
|
ConfigLock(Db *);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
ConfigUnlock(Config *);
|
ConfigUnlock(Config *);
|
||||||
|
|
||||||
#endif /* TELODENDRIA_CONFIG_H */
|
#endif /* TELODENDRIA_CONFIG_H */
|
||||||
|
|
|
@ -36,7 +36,7 @@ extern Db *
|
||||||
DbOpen(char *, size_t);
|
DbOpen(char *, size_t);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
DbMaxCacheSet(Db *, size_t);
|
DbMaxCacheSet(Db *, size_t);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
DbClose(Db *);
|
DbClose(Db *);
|
||||||
|
|
|
@ -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
|
#ifndef TELODENDRIA_MAIN_H
|
||||||
#define TELODENDRIA_MAIN_H
|
#define TELODENDRIA_MAIN_H
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
Restart(void);
|
Restart(void);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
Shutdown(void);
|
Shutdown(void);
|
||||||
|
|
||||||
extern unsigned long
|
extern unsigned long
|
||||||
Uptime(void);
|
Uptime(void);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
main(int argc, char **argv);
|
main(int argc, char **argv);
|
||||||
|
|
||||||
#endif /* TELODENDRIA_MAIN_H */
|
#endif /* TELODENDRIA_MAIN_H */
|
||||||
|
|
Loading…
Reference in a new issue