the first part of reimplementing has been done
now we have app object and singletons are only: log logn plugin and app git-svn-id: svn://ttmath.org/publicrep/winix/trunk@628 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
216
core/config.cpp
216
core/config.cpp
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
|
||||
@@ -17,10 +16,6 @@
|
||||
|
||||
Config::Config()
|
||||
{
|
||||
default_str.clear();
|
||||
default_int = 0;
|
||||
default_bool = false;
|
||||
|
||||
errors_to_stdout = true;
|
||||
}
|
||||
|
||||
@@ -33,7 +28,7 @@ Config::Config()
|
||||
void Config::ShowError()
|
||||
{
|
||||
|
||||
switch( conf_parser.status )
|
||||
switch( parser.status )
|
||||
{
|
||||
case ConfParser::ok:
|
||||
log << log2 << "Config: syntax ok" << logend;
|
||||
@@ -41,16 +36,16 @@ void Config::ShowError()
|
||||
|
||||
case ConfParser::cant_open_file:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: cant open a config file: " << data.config_file << std::endl;
|
||||
std::cout << "Config: cant open a config file: " << config_file << std::endl;
|
||||
|
||||
log << log1 << "Config: cant open a config file: " << data.config_file << logend;
|
||||
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
||||
break;
|
||||
|
||||
case ConfParser::syntax_error:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: syntax error, line: " << conf_parser.line << std::endl;
|
||||
std::cout << "Config: syntax error, line: " << parser.line << std::endl;
|
||||
|
||||
log << log1 << "Config: syntax error, line: " << conf_parser.line << logend;
|
||||
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -60,11 +55,11 @@ void Config::ShowError()
|
||||
|
||||
|
||||
|
||||
bool Config::ReadConfig(bool errors_to_stdout_)
|
||||
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
{
|
||||
errors_to_stdout = errors_to_stdout_;
|
||||
|
||||
if( data.config_file.empty() )
|
||||
if( config_file.empty() )
|
||||
{
|
||||
log << log2 << "Config: name of the config file is empty" << logend;
|
||||
return false;
|
||||
@@ -72,14 +67,14 @@ bool Config::ReadConfig(bool errors_to_stdout_)
|
||||
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
|
||||
conf_parser.SplitSingle(true);
|
||||
ConfParser::Status status = conf_parser.Parse( data.config_file );
|
||||
parser.SplitSingle(true);
|
||||
ConfParser::Status status = parser.Parse( config_file );
|
||||
|
||||
|
||||
if( status == ConfParser::ok )
|
||||
{
|
||||
AssignValues();
|
||||
data.SetAdditionalVariables();
|
||||
AssignValues(stdout_is_closed);
|
||||
SetAdditionalVariables();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -92,177 +87,148 @@ bool Config::ReadConfig(bool errors_to_stdout_)
|
||||
|
||||
|
||||
|
||||
void Config::AssignValues()
|
||||
void Config::AssignValues(bool stdout_is_closed)
|
||||
{
|
||||
data.log_file = Text("log_file");
|
||||
data.log_notify_file = Text("log_notify_file");
|
||||
data.fcgi_socket = Text("fcgi_socket");
|
||||
data.fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
|
||||
data.fcgi_socket_user = Text("fcgi_socket_user");
|
||||
data.fcgi_socket_group = Text("fcgi_socket_group");
|
||||
data.log_level = Int("log_level", 1);
|
||||
data.log_request = Int("log_request", 1);
|
||||
log_file = Text("log_file");
|
||||
log_notify_file = Text("log_notify_file");
|
||||
fcgi_socket = Text("fcgi_socket");
|
||||
fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
|
||||
fcgi_socket_user = Text("fcgi_socket_user");
|
||||
fcgi_socket_group = Text("fcgi_socket_group");
|
||||
log_level = Int("log_level", 1);
|
||||
log_request = Int("log_request", 1);
|
||||
log_stdout = Bool("log_stdout", false);
|
||||
|
||||
if( !data.stdout_is_closed )
|
||||
data.log_stdout = Bool("log_stdout", false);
|
||||
else
|
||||
data.log_stdout = false;
|
||||
post_file_max = Int("post_file_max", 8388608); // 8 MB
|
||||
auth_simplefs_dir = Text("auth_simplefs_dir");
|
||||
auth_hashfs_dir = Text("auth_hashfs_dir");
|
||||
auth_tmp_dir = Text("auth_tmp_dir");
|
||||
|
||||
templates_dir = Text("templates_dir");
|
||||
templates_dir_default = Text("templates_dir_default");
|
||||
http_session_id_name = Text("http_session_id_name");
|
||||
db_database = Text("db_database");
|
||||
db_user = Text("db_user");
|
||||
db_pass = Text("db_pass");
|
||||
item_url_empty = Text("item_url_empty");
|
||||
|
||||
base_server = Text("base_server");
|
||||
base_url = Text("base_url");
|
||||
base_url_auth = Text("base_url_auth");
|
||||
base_url_static = Text("base_url_static");
|
||||
base_url_common = Text("base_url_common");
|
||||
|
||||
NoLastSlash(base_server);
|
||||
NoLastSlash(base_url);
|
||||
NoLastSlash(base_url_auth);
|
||||
NoLastSlash(base_url_static);
|
||||
NoLastSlash(base_url_common);
|
||||
|
||||
priv_no_user = Text("priv_no_user", "-- no user --");
|
||||
priv_no_group = Text("priv_no_group", "-- no group --");
|
||||
|
||||
data.post_file_max = Int("post_file_max", 8388608); // 8 MB
|
||||
data.auth_simplefs_dir = Text("auth_simplefs_dir");
|
||||
data.auth_hashfs_dir = Text("auth_hashfs_dir");
|
||||
data.auth_tmp_dir = Text("auth_tmp_dir");
|
||||
session_max_idle = Int("session_max_idle", 10800); // 3h
|
||||
session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
|
||||
session_file = Text("session_file");
|
||||
|
||||
data.templates_dir = Text("templates_dir");
|
||||
data.templates_dir_default = Text("templates_dir_default");
|
||||
data.http_session_id_name = Text("http_session_id_name");
|
||||
data.db_database = Text("db_database");
|
||||
data.db_user = Text("db_user");
|
||||
data.db_pass = Text("db_pass");
|
||||
data.item_url_empty = Text("item_url_empty");
|
||||
compression = Bool("compression", true);
|
||||
html_filter = Bool("html_filter", true);
|
||||
|
||||
data.base_server = Text("base_server");
|
||||
data.base_url = Text("base_url");
|
||||
data.base_url_auth = Text("base_url_auth");
|
||||
data.base_url_static = Text("base_url_static");
|
||||
data.base_url_common = Text("base_url_common");
|
||||
locale_str = Text("locale", "en");
|
||||
locale_dir = Text("locale_dir");
|
||||
locale_dir_default = Text("locale_dir_default");
|
||||
|
||||
NoLastSlash(data.base_server);
|
||||
NoLastSlash(data.base_url);
|
||||
NoLastSlash(data.base_url_auth);
|
||||
NoLastSlash(data.base_url_static);
|
||||
NoLastSlash(data.base_url_common);
|
||||
title_separator = Text("title_separator", " / ");
|
||||
|
||||
data.priv_no_user = Text("priv_no_user", "-- no user --");
|
||||
data.priv_no_group = Text("priv_no_group", "-- no group --");
|
||||
|
||||
data.session_max_idle = Int("session_max_idle", 10800); // 3h
|
||||
data.session_remember_max_idle = Int("session_remember_max_idle", 16070400); // 3 months
|
||||
data.session_file = Text("session_file");
|
||||
|
||||
data.compression = Bool("compression", true);
|
||||
data.html_filter = Bool("html_filter", true);
|
||||
|
||||
data.locale_str = Text("locale", "en");
|
||||
data.locale_dir = Text("locale_dir");
|
||||
data.locale_dir_default = Text("locale_dir_default");
|
||||
|
||||
data.title_separator = Text("title_separator", " / ");
|
||||
|
||||
|
||||
ListText(data.plugin_file, "plugins");
|
||||
parser.ListText("plugins", plugin_file);
|
||||
}
|
||||
|
||||
|
||||
void Config::SetAdditionalVariables()
|
||||
{
|
||||
SetHttpHost(base_url, base_url_http_host);
|
||||
SetHttpHost(base_url_auth, base_url_auth_http_host);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Config::SetHttpHost(const std::string & in, std::string & out)
|
||||
{
|
||||
if( strncmp(in.c_str(), "http://", 7) == 0 )
|
||||
out = in.substr(7);
|
||||
else
|
||||
if( strncmp(in.c_str(), "https://", 8) == 0 )
|
||||
out = in.substr(8);
|
||||
else
|
||||
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
|
||||
}
|
||||
|
||||
|
||||
std::string Config::Text(const char * name)
|
||||
{
|
||||
return Text(std::string(name), default_str);
|
||||
return parser.Text(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Config::Text(const char * name, const char * def)
|
||||
{
|
||||
return Text(std::string(name), std::string(def));
|
||||
return parser.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::string Config::Text(const std::string & name, const std::string & def)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i == conf_parser.table_single.end() )
|
||||
return def;
|
||||
|
||||
return i->second;
|
||||
return parser.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Config::Int(const char * name)
|
||||
{
|
||||
return Int(std::string(name), default_int);
|
||||
return parser.Int(name);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const char * name, int def)
|
||||
{
|
||||
return Int(std::string(name), def);
|
||||
return parser.Int(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const std::string & name, int def)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i == conf_parser.table_single.end() || i->second.empty() )
|
||||
return def;
|
||||
|
||||
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
|
||||
|
||||
return res;
|
||||
return parser.Int(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const char * name)
|
||||
{
|
||||
return Bool(std::string(name), default_bool);
|
||||
return parser.Bool(name);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const char * name, bool def)
|
||||
{
|
||||
return Bool(std::string(name), def);
|
||||
return parser.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const std::string & name, bool def)
|
||||
{
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i == conf_parser.table_single.end() || i->second.empty() )
|
||||
return def;
|
||||
|
||||
bool res = false;
|
||||
|
||||
if( EqualNoCase(i->second.c_str(), "true") ||
|
||||
EqualNoCase(i->second.c_str(), "yes") ||
|
||||
EqualNoCase(i->second.c_str(), "1")
|
||||
)
|
||||
res = true;
|
||||
|
||||
return res;
|
||||
return parser.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
// in lists we don't use default values
|
||||
void Config::ListText(std::vector<std::string> & list, const char * name)
|
||||
|
||||
void Config::ListText(const char * name, std::vector<std::string> & list)
|
||||
{
|
||||
ListText(list, std::string(name));
|
||||
parser.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
void Config::ListText(std::vector<std::string> & list, const std::string & name)
|
||||
void Config::ListText(const std::string & name, std::vector<std::string> & list)
|
||||
{
|
||||
list.clear();
|
||||
|
||||
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
|
||||
|
||||
if( i != conf_parser.table_single.end() )
|
||||
{
|
||||
list.push_back(i->second);
|
||||
return;
|
||||
}
|
||||
|
||||
ConfParser::Table::iterator z = conf_parser.table.find(name);
|
||||
|
||||
if( z != conf_parser.table.end() )
|
||||
{
|
||||
list = z->second;
|
||||
return;
|
||||
}
|
||||
parser.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user