forked from Telodendria/Telodendria
[ADD/WIP] Generate back a default configuration.
This commit is contained in:
parent
f6313101fd
commit
224eb644ee
3 changed files with 62 additions and 12 deletions
|
@ -12,14 +12,8 @@
|
||||||
"type": "struct"
|
"type": "struct"
|
||||||
},
|
},
|
||||||
|
|
||||||
"HttpHandler *": { "type": "extern" },
|
|
||||||
"void *": { "type": "extern" },
|
|
||||||
|
|
||||||
"ConfigListener": {
|
"ConfigListener": {
|
||||||
"fields": {
|
"fields": {
|
||||||
"handler": { "type": "HttpHandler *", "ignore": true },
|
|
||||||
"handlerArgs": { "type": "void *", "ignore": true },
|
|
||||||
|
|
||||||
"port": { "type": "integer", "required": true },
|
"port": { "type": "integer", "required": true },
|
||||||
"threads": { "type": "integer", "required": false },
|
"threads": { "type": "integer", "required": false },
|
||||||
"maxConnections": { "type": "integer", "required": false },
|
"maxConnections": { "type": "integer", "required": false },
|
||||||
|
|
1
config.json
Normal file
1
config.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"log":{"output":"stdout"},"listen":[{"port":8008,"tls":{}}],"registration":false,"serverName":"localhost","baseUrl":"http:\/\/localhost:8008\/","federation":true}
|
65
src/Config.c
65
src/Config.c
|
@ -28,14 +28,17 @@
|
||||||
#include <Cytoplasm/Array.h>
|
#include <Cytoplasm/Array.h>
|
||||||
#include <Cytoplasm/Str.h>
|
#include <Cytoplasm/Str.h>
|
||||||
#include <Cytoplasm/Db.h>
|
#include <Cytoplasm/Db.h>
|
||||||
#include <Cytoplasm/HttpServer.h>
|
|
||||||
#include <Cytoplasm/Log.h>
|
#include <Cytoplasm/Log.h>
|
||||||
#include <Cytoplasm/Int64.h>
|
#include <Cytoplasm/Int64.h>
|
||||||
|
#include <Cytoplasm/Util.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <grp.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#ifndef HOST_NAME_MAX
|
#ifndef HOST_NAME_MAX
|
||||||
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
|
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
|
||||||
|
@ -45,7 +48,6 @@ Config *
|
||||||
ConfigParse(HashMap * config)
|
ConfigParse(HashMap * config)
|
||||||
{
|
{
|
||||||
Config *tConfig;
|
Config *tConfig;
|
||||||
JsonValue *value;
|
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
@ -74,6 +76,7 @@ ConfigParse(HashMap * config)
|
||||||
tConfig->err = "Couldn't allocate enough memory for 'baseUrl'.";
|
tConfig->err = "Couldn't allocate enough memory for 'baseUrl'.";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
snprintf(tConfig->baseUrl, len, "https://%s/", tConfig->serverName);
|
||||||
}
|
}
|
||||||
if (!tConfig->log.timestampFormat)
|
if (!tConfig->log.timestampFormat)
|
||||||
{
|
{
|
||||||
|
@ -113,12 +116,64 @@ ConfigExists(Db * db)
|
||||||
int
|
int
|
||||||
ConfigCreateDefault(Db * db)
|
ConfigCreateDefault(Db * db)
|
||||||
{
|
{
|
||||||
DbRef *ref;
|
Config config;
|
||||||
|
ConfigListener *listener;
|
||||||
|
|
||||||
HashMap *json;
|
HashMap *json;
|
||||||
Array *listeners;
|
|
||||||
HashMap *listen;
|
DbRef *ref;
|
||||||
|
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
memset(&config, 0, sizeof(Config));
|
||||||
|
|
||||||
|
|
||||||
|
config.log.output = CONFIG_LOG_OUTPUT_FILE;
|
||||||
|
|
||||||
|
config.runAs.gid = StrDuplicate(getgrgid(getgid())->gr_name);
|
||||||
|
config.runAs.uid = StrDuplicate(getpwuid(getuid())->pw_name);
|
||||||
|
|
||||||
|
config.registration = 0;
|
||||||
|
config.federation = 1;
|
||||||
|
|
||||||
|
gethostname(config.serverName, HOST_NAME_MAX);
|
||||||
|
len = strlen(config.serverName) + 10;
|
||||||
|
config.baseUrl = Malloc(len);
|
||||||
|
snprintf(config.baseUrl, len, "https://%s/", config.serverName);
|
||||||
|
|
||||||
|
config.listen = ArrayCreate();
|
||||||
|
listener = Malloc(sizeof(ConfigListener));
|
||||||
|
listener->maxConnections = Int64Create(0, 0);
|
||||||
|
listener->port = Int64Create(0, 8008);
|
||||||
|
listener->threads = Int64Create(0, 0);
|
||||||
|
|
||||||
|
listener->tls.key = NULL;
|
||||||
|
listener->tls.cert = NULL;
|
||||||
|
ArrayAdd(config.listen, listener);
|
||||||
|
|
||||||
|
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");
|
||||||
|
if (!ref)
|
||||||
|
{
|
||||||
|
ConfigFree(&config);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
DbJsonSet(ref, json);
|
||||||
|
DbUnlock(db, ref);
|
||||||
|
|
||||||
|
ConfigFree(&config);
|
||||||
|
JsonFree(json);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
Config *
|
Config *
|
||||||
ConfigLock(Db * db)
|
ConfigLock(Db * db)
|
||||||
|
|
Loading…
Reference in a new issue