forked from lda/telodendria
Fix references to old LOG_ constants
This commit is contained in:
parent
399939654a
commit
70bdf81df7
7 changed files with 84 additions and 94 deletions
2
TODO.txt
2
TODO.txt
|
@ -25,7 +25,7 @@ Due: January 1, 2023
|
||||||
[ ] Document send-patch
|
[ ] Document send-patch
|
||||||
[~] Convert documentation to man pages
|
[~] Convert documentation to man pages
|
||||||
[~] Internal API docs
|
[~] Internal API docs
|
||||||
[~] Array
|
[x] Array
|
||||||
[x] Base64
|
[x] Base64
|
||||||
[ ] CanonicalJson
|
[ ] CanonicalJson
|
||||||
[ ] Config
|
[ ] Config
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.Dd $Mdocdate: September 30 2022 $
|
.Dd $Mdocdate: November 24 2022 $
|
||||||
.Dt ARRAY 3
|
.Dt ARRAY 3
|
||||||
.Os Telodendria Project
|
.Os Telodendria Project
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -24,6 +24,10 @@
|
||||||
.Fn ArrayDelete "Array *" "size_t"
|
.Fn ArrayDelete "Array *" "size_t"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn ArraySort "Array *" "int (*) (void *, void *)"
|
.Fn ArraySort "Array *" "int (*) (void *, void *)"
|
||||||
|
.Ft Array *
|
||||||
|
.Fn ArrayFromVarArgs "size_t" "va_list"
|
||||||
|
.Ft Array *
|
||||||
|
.Fn ArrayDuplicate "Array *"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
These functions implement a simple array data structure that
|
These functions implement a simple array data structure that
|
||||||
is automatically resized as necessary when new values are added.
|
is automatically resized as necessary when new values are added.
|
||||||
|
@ -85,9 +89,23 @@ the opposite: the second element should appear after the first in the array.
|
||||||
.Pp
|
.Pp
|
||||||
.Fn ArrayGet
|
.Fn ArrayGet
|
||||||
is used to get the element at the specified index.
|
is used to get the element at the specified index.
|
||||||
|
.Pp
|
||||||
|
.Fn ArrayFromVarArgs
|
||||||
|
is used to convert a variadic arguments list into an Array. In many
|
||||||
|
cases, the Array API is much easier to work with than
|
||||||
|
.Fn va_arg
|
||||||
|
and friends.
|
||||||
|
.Pp
|
||||||
|
.Fn ArrayDuplicate
|
||||||
|
duplicates an existing array. Note that Arrays only hold
|
||||||
|
pointers to data, not the data itself, so the duplicated array will
|
||||||
|
point to the same places in memory as the original array.
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
.Fn ArrayCreate
|
.Fn ArrayCreate ,
|
||||||
returns a pointer on the heap to a newly allocated array structure, or
|
.Fn ArrayFromVarArgs ,
|
||||||
|
and
|
||||||
|
.Fn ArrayDuplicate
|
||||||
|
return a pointer on the heap to a newly allocated array structure, or
|
||||||
.Dv NULL
|
.Dv NULL
|
||||||
if the allocation fails.
|
if the allocation fails.
|
||||||
.Pp
|
.Pp
|
||||||
|
|
12
src/Log.c
12
src/Log.c
|
@ -59,7 +59,7 @@ LogConfigCreate(void)
|
||||||
|
|
||||||
memset(config, 0, sizeof(LogConfig));
|
memset(config, 0, sizeof(LogConfig));
|
||||||
|
|
||||||
LogConfigLevelSet(config, LOG_MESSAGE);
|
LogConfigLevelSet(config, LOG_INFO);
|
||||||
LogConfigIndentSet(config, 0);
|
LogConfigIndentSet(config, 0);
|
||||||
LogConfigOutputSet(config, NULL); /* Will set to stdout */
|
LogConfigOutputSet(config, NULL); /* Will set to stdout */
|
||||||
LogConfigFlagSet(config, LOG_FLAG_COLOR);
|
LogConfigFlagSet(config, LOG_FLAG_COLOR);
|
||||||
|
@ -154,9 +154,9 @@ LogConfigLevelSet(LogConfig * config, int level)
|
||||||
|
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
case LOG_ERROR:
|
case LOG_ERR:
|
||||||
case LOG_WARNING:
|
case LOG_WARNING:
|
||||||
case LOG_MESSAGE:
|
case LOG_INFO:
|
||||||
case LOG_DEBUG:
|
case LOG_DEBUG:
|
||||||
config->level = level;
|
config->level = level;
|
||||||
default:
|
default:
|
||||||
|
@ -311,16 +311,16 @@ Log(LogConfig * config, int level, const char *msg,...)
|
||||||
case LOG_CRIT:
|
case LOG_CRIT:
|
||||||
indicator = 'X';
|
indicator = 'X';
|
||||||
break;
|
break;
|
||||||
case LOG_ERROR:
|
case LOG_ERR:
|
||||||
indicator = 'x';
|
indicator = 'x';
|
||||||
break;
|
break;
|
||||||
case LOG_WARNING:
|
case LOG_WARNING:
|
||||||
indicator = '!';
|
indicator = '!';
|
||||||
break;
|
break;
|
||||||
case LOG_TASK:
|
case LOG_NOTICE:
|
||||||
indicator = '~';
|
indicator = '~';
|
||||||
break;
|
break;
|
||||||
case LOG_MESSAGE:
|
case LOG_INFO:
|
||||||
indicator = '>';
|
indicator = '>';
|
||||||
break;
|
break;
|
||||||
case LOG_DEBUG:
|
case LOG_DEBUG:
|
||||||
|
|
|
@ -39,6 +39,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
MatrixHttpHandlerArgs *args = (MatrixHttpHandlerArgs *) argp;
|
MatrixHttpHandlerArgs *args = (MatrixHttpHandlerArgs *) argp;
|
||||||
|
|
||||||
LogConfig *lc = args->lc;
|
LogConfig *lc = args->lc;
|
||||||
|
Db *db = args->db;
|
||||||
|
|
||||||
HashMap *requestHeaders = HttpRequestHeaders(context);
|
HashMap *requestHeaders = HttpRequestHeaders(context);
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
|
@ -54,7 +55,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
||||||
|
|
||||||
requestPath = HttpRequestPath(context);
|
requestPath = HttpRequestPath(context);
|
||||||
|
|
||||||
Log(lc, LOG_MESSAGE, "%s %s",
|
Log(lc, LOG_INFO, "%s %s",
|
||||||
HttpRequestMethodToString(HttpRequestMethodGet(context)),
|
HttpRequestMethodToString(HttpRequestMethodGet(context)),
|
||||||
requestPath);
|
requestPath);
|
||||||
|
|
||||||
|
|
|
@ -104,23 +104,23 @@ typedef enum ArgFlag
|
||||||
static void
|
static void
|
||||||
TelodendriaPrintHeader(LogConfig * lc)
|
TelodendriaPrintHeader(LogConfig * lc)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_MESSAGE,
|
Log(lc, LOG_INFO,
|
||||||
" _____ _ _ _ _");
|
" _____ _ _ _ _");
|
||||||
Log(lc, LOG_MESSAGE,
|
Log(lc, LOG_INFO,
|
||||||
"|_ _|__| | ___ __| | ___ _ __ __| |_ __(_) __ _");
|
"|_ _|__| | ___ __| | ___ _ __ __| |_ __(_) __ _");
|
||||||
Log(lc, LOG_MESSAGE,
|
Log(lc, LOG_INFO,
|
||||||
" | |/ _ \\ |/ _ \\ / _` |/ _ \\ '_ \\ / _` | '__| |/ _` |");
|
" | |/ _ \\ |/ _ \\ / _` |/ _ \\ '_ \\ / _` | '__| |/ _` |");
|
||||||
Log(lc, LOG_MESSAGE,
|
Log(lc, LOG_INFO,
|
||||||
" | | __/ | (_) | (_| | __/ | | | (_| | | | | (_| |");
|
" | | __/ | (_) | (_| | __/ | | | (_| | | | | (_| |");
|
||||||
Log(lc, LOG_MESSAGE,
|
Log(lc, LOG_INFO,
|
||||||
" |_|\\___|_|\\___/ \\__,_|\\___|_| |_|\\__,_|_| |_|\\__,_|");
|
" |_|\\___|_|\\___/ \\__,_|\\___|_| |_|\\__,_|_| |_|\\__,_|");
|
||||||
Log(lc, LOG_MESSAGE, "Telodendria v" TELODENDRIA_VERSION);
|
Log(lc, LOG_INFO, "Telodendria v" TELODENDRIA_VERSION);
|
||||||
Log(lc, LOG_MESSAGE, "");
|
Log(lc, LOG_INFO, "");
|
||||||
Log(lc, LOG_MESSAGE,
|
Log(lc, LOG_INFO,
|
||||||
"Copyright (C) 2022 Jordan Bancino <@jordan:bancino.net>");
|
"Copyright (C) 2022 Jordan Bancino <@jordan:bancino.net>");
|
||||||
Log(lc, LOG_MESSAGE,
|
Log(lc, LOG_INFO,
|
||||||
"Documentation/Support: https://telodendria.io");
|
"Documentation/Support: https://telodendria.io");
|
||||||
Log(lc, LOG_MESSAGE, "");
|
Log(lc, LOG_INFO, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -170,7 +170,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (pledge("stdio rpath wpath cpath flock inet dns getpw id unveil", NULL) != 0)
|
if (pledge("stdio rpath wpath cpath flock inet dns getpw id unveil", NULL) != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Pledge failed: %s", strerror(errno));
|
Log(lc, LOG_ERR, "Pledge failed: %s", strerror(errno));
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (!configArg)
|
if (!configArg)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "No configuration file specified.");
|
Log(lc, LOG_ERR, "No configuration file specified.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ main(int argc, char **argv)
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (unveil(configArg, "r") != 0)
|
if (unveil(configArg, "r") != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to unveil() configuration file '%s' for reading.", configArg);
|
Log(lc, LOG_ERR, "Unable to unveil() configuration file '%s' for reading.", configArg);
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -229,18 +229,18 @@ main(int argc, char **argv)
|
||||||
configFile = fopen(configArg, "r");
|
configFile = fopen(configArg, "r");
|
||||||
if (!configFile)
|
if (!configFile)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to open configuration file '%s' for reading.", configArg);
|
Log(lc, LOG_ERR, "Unable to open configuration file '%s' for reading.", configArg);
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(lc, LOG_TASK, "Processing configuration file '%s'.", configArg);
|
Log(lc, LOG_NOTICE, "Processing configuration file '%s'.", configArg);
|
||||||
|
|
||||||
configParseResult = ConfigParse(configFile);
|
configParseResult = ConfigParse(configFile);
|
||||||
if (!ConfigParseResultOk(configParseResult))
|
if (!ConfigParseResultOk(configParseResult))
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Syntax error on line %d.",
|
Log(lc, LOG_ERR, "Syntax error on line %d.",
|
||||||
ConfigParseResultLineNumber(configParseResult));
|
ConfigParseResultLineNumber(configParseResult));
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
@ -262,14 +262,14 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (flags & ARG_CONFIGTEST)
|
if (flags & ARG_CONFIGTEST)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_MESSAGE, "Configuration is OK.");
|
Log(lc, LOG_INFO, "Configuration is OK.");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (unveil(tConfig->dataDir, "rwc") != 0)
|
if (unveil(tConfig->dataDir, "rwc") != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unveil of data directory failed: %s", strerror(errno));
|
Log(lc, LOG_ERR, "Unveil of data directory failed: %s", strerror(errno));
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (chdir(tConfig->dataDir) != 0)
|
if (chdir(tConfig->dataDir) != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to change into data directory: %s.", strerror(errno));
|
Log(lc, LOG_ERR, "Unable to change into data directory: %s.", strerror(errno));
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -308,12 +308,12 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (!logFile)
|
if (!logFile)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to open log file for appending.");
|
Log(lc, LOG_ERR, "Unable to open log file for appending.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(lc, LOG_MESSAGE, "Logging to the log file. Check there for all future messages.");
|
Log(lc, LOG_INFO, "Logging to the log file. Check there for all future messages.");
|
||||||
LogConfigOutputSet(lc, logFile);
|
LogConfigOutputSet(lc, logFile);
|
||||||
}
|
}
|
||||||
else if (tConfig->flags & TELODENDRIA_LOG_STDOUT)
|
else if (tConfig->flags & TELODENDRIA_LOG_STDOUT)
|
||||||
|
@ -322,7 +322,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
else if (tConfig->flags & TELODENDRIA_LOG_SYSLOG)
|
else if (tConfig->flags & TELODENDRIA_LOG_SYSLOG)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_MESSAGE, "Logging to the syslog. Check there for all future messages.");
|
Log(lc, LOG_INFO, "Logging to the syslog. Check there for all future messages.");
|
||||||
LogConfigFlagSet(lc, LOG_FLAG_SYSLOG);
|
LogConfigFlagSet(lc, LOG_FLAG_SYSLOG);
|
||||||
|
|
||||||
openlog("telodendria", LOG_PID | LOG_NDELAY, LOG_DAEMON);
|
openlog("telodendria", LOG_PID | LOG_NDELAY, LOG_DAEMON);
|
||||||
|
@ -332,8 +332,8 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unknown logging method in flags: '%d'", tConfig->flags);
|
Log(lc, LOG_ERR, "Unknown logging method in flags: '%d'", tConfig->flags);
|
||||||
Log(lc, LOG_ERROR, "This is a programmer error; please report it.");
|
Log(lc, LOG_ERR, "This is a programmer error; please report it.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ main(int argc, char **argv)
|
||||||
MatrixHttpHandler, &matrixArgs);
|
MatrixHttpHandler, &matrixArgs);
|
||||||
if (!httpServer)
|
if (!httpServer)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to create HTTP server on port %d: %s",
|
Log(lc, LOG_ERR, "Unable to create HTTP server on port %d: %s",
|
||||||
tConfig->listenPort, strerror(errno));
|
tConfig->listenPort, strerror(errno));
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
@ -376,7 +376,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (!userInfo || !groupInfo)
|
if (!userInfo || !groupInfo)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to locate the user/group specified in the configuration.");
|
Log(lc, LOG_ERR, "Unable to locate the user/group specified in the configuration.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (setgid(groupInfo->gr_gid) != 0 || setuid(userInfo->pw_uid) != 0)
|
if (setgid(groupInfo->gr_gid) != 0 || setuid(userInfo->pw_uid) != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to set process uid/gid.");
|
Log(lc, LOG_ERR, "Unable to set process uid/gid.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -474,21 +474,21 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (!matrixArgs.db)
|
if (!matrixArgs.db)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to open data directory as a database.");
|
Log(lc, LOG_ERR, "Unable to open data directory as a database.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(lc, LOG_TASK, "Starting server...");
|
Log(lc, LOG_NOTICE, "Starting server...");
|
||||||
|
|
||||||
if (!HttpServerStart(httpServer))
|
if (!HttpServerStart(httpServer))
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to start HTTP server.");
|
Log(lc, LOG_ERR, "Unable to start HTTP server.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(lc, LOG_MESSAGE, "Listening on port: %d", tConfig->listenPort);
|
Log(lc, LOG_INFO, "Listening on port: %d", tConfig->listenPort);
|
||||||
|
|
||||||
sigAction.sa_handler = TelodendriaSignalHandler;
|
sigAction.sa_handler = TelodendriaSignalHandler;
|
||||||
sigfillset(&sigAction.sa_mask);
|
sigfillset(&sigAction.sa_mask);
|
||||||
|
@ -496,7 +496,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (sigaction(SIGINT, &sigAction, NULL) < 0)
|
if (sigaction(SIGINT, &sigAction, NULL) < 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unable to install signal handler.");
|
Log(lc, LOG_ERR, "Unable to install signal handler.");
|
||||||
exit = EXIT_FAILURE;
|
exit = EXIT_FAILURE;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ main(int argc, char **argv)
|
||||||
HttpServerJoin(httpServer);
|
HttpServerJoin(httpServer);
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
Log(lc, LOG_TASK, "Shutting down...");
|
Log(lc, LOG_NOTICE, "Shutting down...");
|
||||||
if (httpServer)
|
if (httpServer)
|
||||||
{
|
{
|
||||||
HttpServerFree(httpServer);
|
HttpServerFree(httpServer);
|
||||||
|
|
|
@ -50,19 +50,19 @@ IsInteger(char *str)
|
||||||
#define GET_DIRECTIVE(name) \
|
#define GET_DIRECTIVE(name) \
|
||||||
directive = (ConfigDirective *) HashMapGet(config, name); \
|
directive = (ConfigDirective *) HashMapGet(config, name); \
|
||||||
if (!directive) { \
|
if (!directive) { \
|
||||||
Log(lc, LOG_ERROR, "Missing required configuration directive: '%s'.", name); \
|
Log(lc, LOG_ERR, "Missing required configuration directive: '%s'.", name); \
|
||||||
goto error; \
|
goto error; \
|
||||||
} \
|
} \
|
||||||
children = ConfigChildrenGet(directive); \
|
children = ConfigChildrenGet(directive); \
|
||||||
value = ConfigValuesGet(directive); \
|
value = ConfigValuesGet(directive); \
|
||||||
|
|
||||||
#define ASSERT_NO_CHILDREN(name) if (children) { \
|
#define ASSERT_NO_CHILDREN(name) if (children) { \
|
||||||
Log(lc, LOG_ERROR, "Unexpected child values in directive: '%s'.", name); \
|
Log(lc, LOG_ERR, "Unexpected child values in directive: '%s'.", name); \
|
||||||
goto error; \
|
goto error; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ASSERT_VALUES(name, expected) if (ArraySize(value) != expected) { \
|
#define ASSERT_VALUES(name, expected) if (ArraySize(value) != expected) { \
|
||||||
Log(lc, LOG_ERROR, \
|
Log(lc, LOG_ERR, \
|
||||||
"Wrong value count in directive '%s': got '%d', but expected '%d'.", \
|
"Wrong value count in directive '%s': got '%d', but expected '%d'.", \
|
||||||
name, ArraySize(value), expected); \
|
name, ArraySize(value), expected); \
|
||||||
goto error; \
|
goto error; \
|
||||||
|
@ -108,7 +108,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
tConfig->listenPort = (unsigned short) atoi(ArrayGet(value, 0));
|
tConfig->listenPort = (unsigned short) atoi(ArrayGet(value, 0));
|
||||||
if (!tConfig->listenPort)
|
if (!tConfig->listenPort)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Expected numeric value for listen port, got '%s'.", ArrayGet(value, 1));
|
Log(lc, LOG_ERR, "Expected numeric value for listen port, got '%s'.", ArrayGet(value, 1));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
tConfig->baseUrl = Malloc(strlen(tConfig->serverName) + 10);
|
tConfig->baseUrl = Malloc(strlen(tConfig->serverName) + 10);
|
||||||
if (!tConfig->baseUrl)
|
if (!tConfig->baseUrl)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Error allocating memory for default config value 'base-url'.");
|
Log(lc, LOG_ERR, "Error allocating memory for default config value 'base-url'.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
COPY_VALUE(tConfig->gid, 1);
|
COPY_VALUE(tConfig->gid, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log(lc, LOG_ERROR,
|
Log(lc, LOG_ERR,
|
||||||
"Wrong value count in directive 'id': got '%d', but expected 1 or 2.",
|
"Wrong value count in directive 'id': got '%d', but expected 1 or 2.",
|
||||||
ArraySize(value));
|
ArraySize(value));
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -204,13 +204,13 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
tConfig->threads = atoi(ArrayGet(value, 0));
|
tConfig->threads = atoi(ArrayGet(value, 0));
|
||||||
if (!tConfig->threads)
|
if (!tConfig->threads)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "threads must be greater than zero");
|
Log(lc, LOG_ERR, "threads must be greater than zero");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR,
|
Log(lc, LOG_ERR,
|
||||||
"Expected integer for directive 'threads', "
|
"Expected integer for directive 'threads', "
|
||||||
"but got '%s'.", ArrayGet(value, 0));
|
"but got '%s'.", ArrayGet(value, 0));
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -231,13 +231,13 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
tConfig->maxConnections = atoi(ArrayGet(value, 0));
|
tConfig->maxConnections = atoi(ArrayGet(value, 0));
|
||||||
if (!tConfig->maxConnections)
|
if (!tConfig->maxConnections)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "max-connections must be greater than zero.");
|
Log(lc, LOG_ERR, "max-connections must be greater than zero.");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Expected integer for max-connections, got '%s'", ArrayGet(value, 0));
|
Log(lc, LOG_ERR, "Expected integer for max-connections, got '%s'", ArrayGet(value, 0));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
}
|
}
|
||||||
else if (strcmp(ArrayGet(value, 0), "false") != 0)
|
else if (strcmp(ArrayGet(value, 0), "false") != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR,
|
Log(lc, LOG_ERR,
|
||||||
"Expected boolean value for directive 'federation', "
|
"Expected boolean value for directive 'federation', "
|
||||||
"but got '%s'.", ArrayGet(value, 0));
|
"but got '%s'.", ArrayGet(value, 0));
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -272,7 +272,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
}
|
}
|
||||||
else if (strcmp(ArrayGet(value, 0), "false") != 0)
|
else if (strcmp(ArrayGet(value, 0), "false") != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR,
|
Log(lc, LOG_ERR,
|
||||||
"Expected boolean value for directive 'registration', "
|
"Expected boolean value for directive 'registration', "
|
||||||
"but got '%s'.", ArrayGet(value, 0));
|
"but got '%s'.", ArrayGet(value, 0));
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -293,14 +293,14 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
size = ArraySize(ConfigValuesGet(cDirective));
|
size = ArraySize(ConfigValuesGet(cDirective));
|
||||||
if (size > 1)
|
if (size > 1)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Expected 1 value for log.level, got %d.", size);
|
Log(lc, LOG_ERR, "Expected 1 value for log.level, got %d.", size);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
cVal = ArrayGet(ConfigValuesGet(cDirective), 0);
|
cVal = ArrayGet(ConfigValuesGet(cDirective), 0);
|
||||||
if (strcmp(cVal, "message") == 0)
|
if (strcmp(cVal, "message") == 0)
|
||||||
{
|
{
|
||||||
tConfig->logLevel = LOG_MESSAGE;
|
tConfig->logLevel = LOG_INFO;
|
||||||
}
|
}
|
||||||
else if (strcmp(cVal, "debug") == 0)
|
else if (strcmp(cVal, "debug") == 0)
|
||||||
{
|
{
|
||||||
|
@ -308,7 +308,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
}
|
}
|
||||||
else if (strcmp(cVal, "task") == 0)
|
else if (strcmp(cVal, "task") == 0)
|
||||||
{
|
{
|
||||||
tConfig->logLevel = LOG_TASK;
|
tConfig->logLevel = LOG_NOTICE;
|
||||||
}
|
}
|
||||||
else if (strcmp(cVal, "warning") == 0)
|
else if (strcmp(cVal, "warning") == 0)
|
||||||
{
|
{
|
||||||
|
@ -316,11 +316,11 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
}
|
}
|
||||||
else if (strcmp(cVal, "error") == 0)
|
else if (strcmp(cVal, "error") == 0)
|
||||||
{
|
{
|
||||||
tConfig->logLevel = LOG_ERROR;
|
tConfig->logLevel = LOG_ERR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Invalid value for log.level: '%s'.", cVal);
|
Log(lc, LOG_ERR, "Invalid value for log.level: '%s'.", cVal);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
size = ArraySize(ConfigValuesGet(cDirective));
|
size = ArraySize(ConfigValuesGet(cDirective));
|
||||||
if (size > 1)
|
if (size > 1)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Expected 1 value for log.level, got %d.", size);
|
Log(lc, LOG_ERR, "Expected 1 value for log.level, got %d.", size);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
size = ArraySize(ConfigValuesGet(cDirective));
|
size = ArraySize(ConfigValuesGet(cDirective));
|
||||||
if (size > 1)
|
if (size > 1)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Expected 1 value for log.level, got %d.", size);
|
Log(lc, LOG_ERR, "Expected 1 value for log.level, got %d.", size);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
}
|
}
|
||||||
else if (strcmp(cVal, "false") != 0)
|
else if (strcmp(cVal, "false") != 0)
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Expected boolean value for log.color, got '%s'.", cVal);
|
Log(lc, LOG_ERR, "Expected boolean value for log.color, got '%s'.", cVal);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log(lc, LOG_ERROR, "Unknown log value '%s', expected 'stdout', 'file', or 'syslog'.",
|
Log(lc, LOG_ERR, "Unknown log value '%s', expected 'stdout', 'file', or 'syslog'.",
|
||||||
ArrayGet(value, 0));
|
ArrayGet(value, 0));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,23 +22,6 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Log.h: A heavily-modified version of Shlog, a simple C logging
|
|
||||||
* facility that allows for colorful output, timestamps, and custom
|
|
||||||
* log levels. This library differs from Shlog in that the naming
|
|
||||||
* conventions have been updated to be consistent with Telodendria.
|
|
||||||
*
|
|
||||||
* Shlog was originally a learning project. It worked well, however,
|
|
||||||
* and produced elegant logging output, so it was chosen to be the
|
|
||||||
* main logging mechanism of Telodendria. The original Shlog project
|
|
||||||
* is now dead; Shlog lives on now only as Telodendria's logging
|
|
||||||
* mechanism.
|
|
||||||
*
|
|
||||||
* In the name of simplicity and portability, I opted to use an
|
|
||||||
* in-house logging system instead of syslog(), or other system logging
|
|
||||||
* mechanisms. However, this API could easily be patched to allow
|
|
||||||
* logging via other mechanisms that support the same features.
|
|
||||||
*/
|
|
||||||
#ifndef TELODENDRIA_LOG_H
|
#ifndef TELODENDRIA_LOG_H
|
||||||
#define TELODENDRIA_LOG_H
|
#define TELODENDRIA_LOG_H
|
||||||
|
|
||||||
|
@ -46,18 +29,6 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* I used to define all my own constants, but now I use
|
|
||||||
* those defined in syslog.h. Instead of replacing all the
|
|
||||||
* references, I just map the old names to the new ones. If
|
|
||||||
* you're ever bored one day, you can remove these, and then
|
|
||||||
* go fix all the compiler errors that arise. Should be pretty
|
|
||||||
* easy, just mind numbing.
|
|
||||||
*/
|
|
||||||
#define LOG_ERROR LOG_ERR
|
|
||||||
#define LOG_TASK LOG_NOTICE
|
|
||||||
#define LOG_MESSAGE LOG_INFO
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The possible flags that can be applied to alter the behavior of
|
* The possible flags that can be applied to alter the behavior of
|
||||||
* the logger.
|
* the logger.
|
||||||
|
|
Loading…
Reference in a new issue