added: default values for variables read from the config file
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@547 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
3f9a46b1f7
commit
59943c87cd
|
@ -16,6 +16,7 @@
|
|||
|
||||
Config::Config()
|
||||
{
|
||||
default_str.clear();
|
||||
default_int = 0;
|
||||
default_bool = false;
|
||||
|
||||
|
@ -94,21 +95,20 @@ void Config::AssignValues()
|
|||
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");
|
||||
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");
|
||||
data.log_level = Int("log_level", 1);
|
||||
|
||||
if( !data.stdout_is_closed )
|
||||
data.log_stdout = Bool("log_stdout");
|
||||
data.log_stdout = Bool("log_stdout", false);
|
||||
else
|
||||
data.log_stdout = false;
|
||||
|
||||
data.post_file_max = Int("post_file_max");
|
||||
data.post_file_max = Int("post_file_max", 8388608); // 8 MB
|
||||
data.static_auth_dir = Text("static_auth_dir");
|
||||
|
||||
data.templates = Text("templates");
|
||||
data.default_index = Text("default_index");
|
||||
data.http_session_id_name = Text("http_session_id_name");
|
||||
data.db_database = Text("db_database");
|
||||
data.db_user = Text("db_user");
|
||||
|
@ -127,80 +127,100 @@ void Config::AssignValues()
|
|||
data.base_url_static = data.base_url_static_prefix + data.base_server;
|
||||
data.base_url_static_auth = data.base_url_static_auth_prefix + data.base_server;
|
||||
|
||||
data.one_item_is_showed = Bool("one_item_is_showed");
|
||||
|
||||
data.priv_no_user = Text("priv_no_user");
|
||||
data.priv_no_group = Text("priv_no_group");
|
||||
data.priv_no_user = Text("priv_no_user", "-- no user --");
|
||||
data.priv_no_group = Text("priv_no_group", "-- no group --");
|
||||
|
||||
data.session_max_iddle = Int("session_max_iddle");
|
||||
data.session_remember_max_iddle = Int("session_remember_max_iddle");
|
||||
data.session_max_iddle = Int("session_max_iddle", 10800); // 3h
|
||||
data.session_remember_max_iddle = Int("session_remember_max_iddle", 16070400); // 3 months
|
||||
data.session_file = Text("session_file");
|
||||
|
||||
data.compression = Bool("compression");
|
||||
data.compression = Bool("compression", true);
|
||||
|
||||
std::string p = Text("plugin");
|
||||
data.plugin_file.push_back(p);
|
||||
|
||||
data.html_filter = Bool("html_filter");
|
||||
data.html_filter = Bool("html_filter", true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// !! mozna dodac drugi argument -- wartosc domyslna
|
||||
std::string & Config::Text(const char * name)
|
||||
const std::string & Config::Text(const char * name)
|
||||
{
|
||||
return Text(std::string(name), default_str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::string & Config::Text(const char * name, const char * def)
|
||||
{
|
||||
return Text(std::string(name), std::string(def));
|
||||
}
|
||||
|
||||
|
||||
const std::string & Config::Text(const std::string & name, const std::string & def)
|
||||
{
|
||||
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
||||
|
||||
if( i == conf_parser.table.end() )
|
||||
{
|
||||
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: \"" << default_str << "\"" << logend;
|
||||
return default_str;
|
||||
}
|
||||
|
||||
log << log3 << "Config: " << name << "=" << i->second << logend;
|
||||
return def;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! mozna dodac drugi argument -- wartosc domyslna
|
||||
int Config::Int(const char * name)
|
||||
{
|
||||
return Int(std::string(name), default_int);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const char * name, int def)
|
||||
{
|
||||
return Int(std::string(name), def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const std::string & name, int def)
|
||||
{
|
||||
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
||||
|
||||
if( i == conf_parser.table.end() || i->second.empty() )
|
||||
{
|
||||
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << default_int << logend;
|
||||
return default_int;
|
||||
}
|
||||
return def;
|
||||
|
||||
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
|
||||
log << log3 << "Config: " << name << "=" << res << logend;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! mozna dodac drugi argument -- wartosc domyslna
|
||||
bool Config::Bool(const char * name)
|
||||
{
|
||||
return Bool(std::string(name), default_bool);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const char * name, bool def)
|
||||
{
|
||||
return Bool(std::string(name), def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const std::string & name, bool def)
|
||||
{
|
||||
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
||||
|
||||
if( i == conf_parser.table.end() )
|
||||
{
|
||||
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << (default_bool?"true":"false") << logend;
|
||||
return default_int;
|
||||
}
|
||||
if( i == conf_parser.table.end() || i->second.empty() )
|
||||
return def;
|
||||
|
||||
bool res = default_bool;
|
||||
|
||||
if( i->second == "true" || i->second == "1" || i->second == "yes" )
|
||||
bool res = false;
|
||||
|
||||
if( EqualNoCase(i->second.c_str(), "true") ||
|
||||
EqualNoCase(i->second.c_str(), "yes") ||
|
||||
EqualNoCase(i->second.c_str(), "1")
|
||||
)
|
||||
res = true;
|
||||
|
||||
log << log3 << "Config: " << name << "=" << (res?"true":"false") << logend;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -33,12 +33,20 @@ private:
|
|||
void AssignValues();
|
||||
|
||||
|
||||
std::string & Text(const char *);
|
||||
const std::string & Text(const char *);
|
||||
const std::string & Text(const char * name, const char * def);
|
||||
const std::string & Text(const std::string & name, const std::string & def);
|
||||
|
||||
int Int(const char *);
|
||||
int Int(const char * name, int def);
|
||||
int Int(const std::string & name, int def);
|
||||
|
||||
bool Bool(const char *);
|
||||
bool Bool(const char * name, bool def);
|
||||
bool Bool(const std::string & name, bool def);
|
||||
|
||||
std::string default_str;
|
||||
int default_int;
|
||||
int default_int;
|
||||
bool default_bool;
|
||||
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@ public:
|
|||
std::string fcgi_socket_group;
|
||||
|
||||
std::string templates;
|
||||
std::string default_index;
|
||||
|
||||
std::string db_database;
|
||||
std::string db_user;
|
||||
|
@ -77,12 +76,6 @@ public:
|
|||
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
|
||||
bool base_url_redirect;
|
||||
|
||||
// if there is one item in a directory
|
||||
// it will be showed
|
||||
// (instead of showing directory contents)
|
||||
// !! wywalic to, nie bedzie uzywane
|
||||
bool one_item_is_showed;
|
||||
|
||||
// string used in a place where is a user (or group) selected
|
||||
std::string priv_no_user;
|
||||
std::string priv_no_group;
|
||||
|
|
|
@ -481,6 +481,21 @@ return false;
|
|||
}
|
||||
|
||||
|
||||
bool EqualNoCase(const char * short_str, const char * long_str)
|
||||
{
|
||||
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
|
||||
{
|
||||
++short_str;
|
||||
++long_str;
|
||||
}
|
||||
|
||||
if( *short_str == 0 && *long_str == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ValidateEmail(const std::string & email)
|
||||
{
|
||||
if( email.empty() )
|
||||
|
|
|
@ -55,7 +55,7 @@ const char * ToStr(int value);
|
|||
|
||||
bool IsSubString(const char * short_str, const char * long_str);
|
||||
bool IsSubStringNoCase(const char * short_str, const char * long_str);
|
||||
|
||||
bool EqualNoCase(const char * short_str, const char * long_str);
|
||||
|
||||
bool ValidateEmail(const std::string & email);
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ void Templates::ReadTemplates()
|
|||
using namespace TemplatesFunctions;
|
||||
|
||||
pat_index.Directory(data.templates);
|
||||
pat_index.ParseFile(data.default_index);
|
||||
pat_index.ParseFile("index.html");
|
||||
|
||||
pat_err_404.Directory(data.templates);
|
||||
pat_err_404.ParseFile("err_404.html");
|
||||
|
|
Loading…
Reference in New Issue