#include <stdio.h>
#include <stdlib.h>
#include "../public/nsapi.h"
#include <cx/string.h>
#include "httplistener.h"
#include "log.h"
#include "configmanager.h"
static ServerConfiguration *current_config =
NULL;
static conf_global_vars_s global_vars;
void init_configuration_manager() {
init_server_config_parser();
}
NSAPI_PUBLIC conf_global_vars_s* conf_getglobals() {
return &global_vars;
}
int cfgmgr_load_config(CfgManager *mgr) {
ZERO(mgr,
sizeof(CfgManager));
ServerConfiguration *config = load_server_conf(mgr,
"config/server.conf");
if(!config) {
log_ereport(
LOG_FAILURE,
"cfgmgr: cannot load server config file %s",
"config/server.conf");
return 1;
}
mgr->cfg = config;
return 0;
}
int cfgmgr_apply_config(CfgManager *mgr) {
if(!apply_server_conf(mgr)) {
log_ereport(
LOG_FAILURE,
"cfgmgr: stage 2 config loading failed");
return 1;
}
if(current_config) {
if(migrate_server_conf(current_config, mgr->cfg)) {
log_ereport(
LOG_FAILURE,
"cfgmgr: config migration failed");
return 1;
}
cfg_unref(current_config);
}
current_config = mgr->cfg;
return 0;
}
ServerConfiguration *cfgmgr_get_server_config() {
return current_config;
}