Compare commits

..

No commits in common. "610b0807ce7a6b7b9d7cf4fd2b631a0672956c69" and "a7d6dfc8709560f56b21b0022eef19674074ef50" have entirely different histories.

3 changed files with 24 additions and 47 deletions

View file

@ -136,15 +136,11 @@ ConfigCreateDefault(Db * db)
config.registration = 0;
config.federation = 1;
/* Create serverName and baseUrl. */
config.serverName = Malloc(HOST_NAME_MAX + 1);
memset(config.serverName, 0, HOST_NAME_MAX + 1);
gethostname(config.serverName, HOST_NAME_MAX);
len = strlen(config.serverName) + 10;
config.baseUrl = Malloc(len);
snprintf(config.baseUrl, len, "https://%s/", config.serverName);
/* Add simple listener without TLS. */
config.listen = ArrayCreate();
listener = Malloc(sizeof(ConfigListener));
listener->maxConnections = Int64Create(0, 0);
@ -155,7 +151,13 @@ ConfigCreateDefault(Db * db)
listener->tls.cert = NULL;
ArrayAdd(config.listen, listener);
/* Write it all out to the configuration file. */
config.serverName = Malloc(HOST_NAME_MAX + 1);
/* TODO: Don't set that field(it has to because otherwise j2s will add
* a NULL byte it seems.) */
config.identityServer = StrDuplicate("");
json = ConfigToJson(&config);
ref = DbCreate(db, 1, "config");
@ -222,21 +224,3 @@ ConfigUnlock(Config * config)
ConfigFullyFree(config);
return DbUnlock(db, dbRef);
}
int
ConfigLogLevelToSyslog(ConfigLogLevel level)
{
switch (level)
{
case CONFIG_LOG_LEVEL_NOTICE:
return LOG_NOTICE;
case CONFIG_LOG_LEVEL_ERROR:
return LOG_ERR;
case CONFIG_LOG_LEVEL_MESSAGE:
return LOG_INFO;
case CONFIG_LOG_LEVEL_DEBUG:
return LOG_DEBUG;
case CONFIG_LOG_LEVEL_WARNING:
return LOG_WARNING;
}
return LOG_INFO;
}

View file

@ -281,6 +281,12 @@ start:
{
LogConfigTimeStampFormatSet(LogConfigGlobal(), tConfig->log.timestampFormat);
}
else
{
/* TODO */
/*Free(tConfig->logTimestamp);
tConfig->logTimestamp = NULL;*/
}
if (tConfig->log.color)
{
@ -291,11 +297,8 @@ start:
LogConfigFlagClear(LogConfigGlobal(), LOG_FLAG_COLOR);
}
LogConfigLevelSet(
LogConfigGlobal(),
flags & ARG_VERBOSE ?
LOG_DEBUG :
ConfigLogLevelToSyslog(tConfig->log.level));
/* TODO: Set level properly here. */
/*LogConfigLevelSet(LogConfigGlobal(), flags & ARG_VERBOSE ? LOG_DEBUG : tConfig->logLevel);*/
if (tConfig->log.output == CONFIG_LOG_OUTPUT_FILE)
{
@ -305,17 +308,13 @@ start:
{
Log(LOG_ERR, "Unable to open log file for appending.");
exit = EXIT_FAILURE;
tConfig->log.output = CONFIG_LOG_OUTPUT_STDOUT;
/*tConfig->flags &= CONFIG_LOG_STDOUT;*/
goto finish;
}
Log(LOG_INFO, "Logging to the log file. Check there for all future messages.");
LogConfigOutputSet(LogConfigGlobal(), logFile);
}
else if (tConfig->log.output == CONFIG_LOG_OUTPUT_STDOUT)
{
Log(LOG_DEBUG, "Already logging to standard output.");
}
else if (tConfig->log.output == CONFIG_LOG_OUTPUT_SYSLOG)
{
Log(LOG_INFO, "Logging to the syslog. Check there for all future messages.");
@ -358,30 +357,29 @@ start:
{
ConfigListener *serverCfg = ArrayGet(tConfig->listen, i);
/* TODO: Think of a nicer solution. */
HttpServerConfig args;
args.port = serverCfg->port;
args.threads = serverCfg->maxConnections;
args.maxConnections = serverCfg->maxConnections;
args.tlsCert = serverCfg->tls.cert;
args.tlsKey = serverCfg->tls.key;
args.flags = args.tlsCert && args.tlsKey ? HTTP_FLAG_TLS : HTTP_FLAG_NONE;
Log(LOG_DEBUG, "HTTP listener: %lu", i);
LogConfigIndent(LogConfigGlobal());
Log(LOG_DEBUG, "Port: %hu", serverCfg->port);
Log(LOG_DEBUG, "Threads: %u", serverCfg->threads);
Log(LOG_DEBUG, "Max Connections: %u", serverCfg->maxConnections);
Log(LOG_DEBUG, "Flags: %d", args.flags);
/*Log(LOG_DEBUG, "Flags: %d", serverCfg->flags);*/
Log(LOG_DEBUG, "TLS Cert: %s", serverCfg->tls.cert);
Log(LOG_DEBUG, "TLS Key: %s", serverCfg->tls.key);
LogConfigUnindent(LogConfigGlobal());
args.port = serverCfg->port;
args.threads = serverCfg->maxConnections;
args.maxConnections = serverCfg->maxConnections;
args.tlsCert = serverCfg->tls.cert;
args.tlsKey = serverCfg->tls.key;
args.handler = MatrixHttpHandler;
args.handlerArgs = &matrixArgs;
if (args.flags & HTTP_FLAG_TLS)
if (serverCfg->tls.cert && serverCfg->tls.key)
{
if (UInt64Eq(UtilLastModified(serverCfg->tls.cert), UInt64Create(0, 0)))
{

View file

@ -104,9 +104,4 @@ extern Config * ConfigLock(Db *);
*/
extern int ConfigUnlock(Config *);
/**
* Converts a ConfigLogLevel into a valid syslog level.
*/
extern int ConfigLogLevelToSyslog(ConfigLogLevel);
#endif /* TELODENDRIA_CONFIG_H */