2008-12-11 03:48:25 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2009-04-21 22:50:55 +02:00
|
|
|
* Copyright (c) 2008-2009, Tomasz Sowa
|
2008-12-11 03:48:25 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "log.h"
|
|
|
|
#include "data.h"
|
2009-11-13 21:40:11 +01:00
|
|
|
#include "plugin.h"
|
2008-12-11 03:48:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
Config::Config()
|
|
|
|
{
|
|
|
|
default_int = 0;
|
|
|
|
default_bool = false;
|
|
|
|
|
|
|
|
errors_to_stdout = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
//!! czy tu w ogole mozemy uzywac log << ?
|
|
|
|
//!! przeciez jeszcze nie zostal przetworzony plik konfiguracyjny
|
|
|
|
|
|
|
|
|
2008-12-11 03:48:25 +01:00
|
|
|
void Config::ShowError()
|
|
|
|
{
|
|
|
|
|
|
|
|
switch( conf_parser.status )
|
|
|
|
{
|
|
|
|
case ConfParser::ok:
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log2 << "Config: syntax ok" << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ConfParser::cant_open_file:
|
|
|
|
if( errors_to_stdout )
|
2008-12-30 02:05:03 +01:00
|
|
|
std::cout << "Config: cant open a config file: " << data.config_file << std::endl;
|
2008-12-11 03:48:25 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log1 << "Config: cant open a config file: " << data.config_file << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ConfParser::syntax_error:
|
|
|
|
if( errors_to_stdout )
|
2008-12-30 02:05:03 +01:00
|
|
|
std::cout << "Config: syntax error, line: " << conf_parser.line << std::endl;
|
2008-12-11 03:48:25 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log1 << "Config: syntax error, line: " << conf_parser.line << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Config::ReadConfig(bool errors_to_stdout_)
|
|
|
|
{
|
|
|
|
errors_to_stdout = errors_to_stdout_;
|
|
|
|
|
|
|
|
if( data.config_file.empty() )
|
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log2 << "Config: name of the config file is empty" << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log2 << "Config: reading a config file" << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
|
|
|
|
ConfParser::Status status = conf_parser.Parse( data.config_file.c_str() );
|
|
|
|
|
|
|
|
|
|
|
|
if( status == ConfParser::ok )
|
|
|
|
{
|
|
|
|
AssignValues();
|
2008-12-12 04:11:29 +01:00
|
|
|
|
|
|
|
data.SetAdditionalVariables();
|
2008-12-11 03:48:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowError();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Config::AssignValues()
|
|
|
|
{
|
|
|
|
data.log_file = Text("log_file");
|
2009-10-01 00:31:20 +02:00
|
|
|
data.log_notify_file = Text("log_notify_file");
|
2008-12-11 03:48:25 +01:00
|
|
|
data.fcgi_socket = Text("fcgi_socket");
|
|
|
|
data.fcgi_socket_chmod = Int("fcgi_socket_chmod");
|
|
|
|
data.fcgi_socket_user = Text("fcgi_socket_user");
|
|
|
|
data.fcgi_socket_group = Text("fcgi_socket_group");
|
|
|
|
data.log_level = Int("log_level");
|
|
|
|
|
|
|
|
if( !data.stdout_is_closed )
|
|
|
|
data.log_stdout = Bool("log_stdout");
|
|
|
|
else
|
|
|
|
data.log_stdout = false;
|
|
|
|
|
|
|
|
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");
|
|
|
|
data.db_pass = Text("db_pass");
|
|
|
|
data.base_url = Text("base_url");
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
NoLastSlash(data.base_url);
|
|
|
|
|
2008-12-11 03:48:25 +01:00
|
|
|
data.one_item_is_showed = Bool("one_item_is_showed");
|
2008-12-21 22:17:09 +01:00
|
|
|
|
|
|
|
data.priv_no_user = Text("priv_no_user");
|
|
|
|
data.priv_no_group = Text("priv_no_group");
|
2009-01-31 07:53:36 +01:00
|
|
|
|
2009-11-21 00:09:52 +01:00
|
|
|
data.session_max_iddle = Int("session_max_iddle");
|
|
|
|
data.session_remember_max_iddle = Int("session_remember_max_iddle");
|
|
|
|
data.session_file = Text("session_file");
|
|
|
|
|
2009-09-22 01:05:05 +02:00
|
|
|
data.compression = Bool("compression");
|
2009-11-13 21:40:11 +01:00
|
|
|
|
|
|
|
std::string p = Text("plugin");
|
|
|
|
data.plugin_file.push_back(p);
|
2009-12-09 01:42:40 +01:00
|
|
|
|
|
|
|
data.html_filter = Bool("html_filter");
|
2008-12-11 03:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-31 07:53:36 +01:00
|
|
|
// !! mozna dodac drugi argument -- wartosc domyslna
|
2008-12-11 03:48:25 +01:00
|
|
|
std::string & Config::Text(const char * name)
|
|
|
|
{
|
|
|
|
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
|
|
|
|
|
|
|
if( i == conf_parser.table.end() )
|
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: \"" << default_str << "\"" << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
return default_str;
|
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log3 << "Config: " << name << "=" << i->second << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-31 07:53:36 +01:00
|
|
|
// !! mozna dodac drugi argument -- wartosc domyslna
|
2008-12-11 03:48:25 +01:00
|
|
|
int Config::Int(const char * name)
|
|
|
|
{
|
|
|
|
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
|
|
|
|
|
|
|
if( i == conf_parser.table.end() || i->second.empty() )
|
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << default_int << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
return default_int;
|
|
|
|
}
|
|
|
|
|
|
|
|
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log3 << "Config: " << name << "=" << res << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-31 07:53:36 +01:00
|
|
|
// !! mozna dodac drugi argument -- wartosc domyslna
|
2008-12-11 03:48:25 +01:00
|
|
|
bool Config::Bool(const char * name)
|
|
|
|
{
|
|
|
|
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
|
|
|
|
|
|
|
if( i == conf_parser.table.end() )
|
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << (default_bool?"true":"false") << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
return default_int;
|
|
|
|
}
|
|
|
|
|
2009-12-09 01:42:40 +01:00
|
|
|
bool res = default_bool;
|
2008-12-11 03:48:25 +01:00
|
|
|
|
|
|
|
if( i->second == "true" || i->second == "1" || i->second == "yes" )
|
|
|
|
res = true;
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log3 << "Config: " << name << "=" << (res?"true":"false") << logend;
|
2008-12-11 03:48:25 +01:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void Config::NoLastSlash(std::string & s)
|
|
|
|
{
|
|
|
|
if( s.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
log << log2 << "Config: removing the last slash from: " << s << logend;
|
|
|
|
|
|
|
|
if( *(--s.end()) == '/' )
|
|
|
|
s.erase(--s.end());
|
|
|
|
}
|
2008-12-11 03:48:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|