forked from Telodendria/Telodendria
Compare commits
No commits in common. "a7d6dfc8709560f56b21b0022eef19674074ef50" and "f6313101fdde3ab0630e3845774f0dead2756a66" have entirely different histories.
a7d6dfc870
...
f6313101fd
2 changed files with 12 additions and 61 deletions
|
@ -12,8 +12,14 @@
|
||||||
"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 },
|
||||||
|
|
67
src/Config.c
67
src/Config.c
|
@ -28,17 +28,14 @@
|
||||||
#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
|
||||||
|
@ -48,6 +45,7 @@ Config *
|
||||||
ConfigParse(HashMap * config)
|
ConfigParse(HashMap * config)
|
||||||
{
|
{
|
||||||
Config *tConfig;
|
Config *tConfig;
|
||||||
|
JsonValue *value;
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
@ -76,7 +74,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -116,63 +113,11 @@ ConfigExists(Db * db)
|
||||||
int
|
int
|
||||||
ConfigCreateDefault(Db * db)
|
ConfigCreateDefault(Db * db)
|
||||||
{
|
{
|
||||||
Config config;
|
|
||||||
ConfigListener *listener;
|
|
||||||
|
|
||||||
HashMap *json;
|
|
||||||
|
|
||||||
DbRef *ref;
|
DbRef *ref;
|
||||||
|
HashMap *json;
|
||||||
size_t len;
|
Array *listeners;
|
||||||
|
HashMap *listen;
|
||||||
memset(&config, 0, sizeof(Config));
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
DbJsonSet(ref, json);
|
|
||||||
DbUnlock(db, ref);
|
|
||||||
|
|
||||||
ConfigFree(&config);
|
|
||||||
JsonFree(json);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Config *
|
Config *
|
||||||
|
|
Loading…
Reference in a new issue