278 lines
5.4 KiB
C++
Executable File
278 lines
5.4 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "config.h"
|
|
#include "log.h"
|
|
#include "plugin.h"
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
Config::Config()
|
|
{
|
|
errors_to_stdout = true;
|
|
}
|
|
|
|
|
|
|
|
//!! czy tu w ogole mozemy uzywac log << ?
|
|
//!! przeciez jeszcze nie zostal przetworzony plik konfiguracyjny
|
|
|
|
|
|
void Config::ShowError()
|
|
{
|
|
|
|
switch( parser.status )
|
|
{
|
|
case ConfParser::ok:
|
|
log << log2 << "Config: syntax ok" << logend;
|
|
break;
|
|
|
|
case ConfParser::cant_open_file:
|
|
if( errors_to_stdout )
|
|
std::cout << "Config: cant open a config file: " << config_file << std::endl;
|
|
|
|
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: " << parser.line << std::endl;
|
|
|
|
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
|
{
|
|
errors_to_stdout = errors_to_stdout_;
|
|
|
|
if( config_file.empty() )
|
|
{
|
|
log << log2 << "Config: name of the config file is empty" << logend;
|
|
return false;
|
|
}
|
|
|
|
log << log2 << "Config: reading a config file" << logend;
|
|
|
|
parser.SplitSingle(true);
|
|
ConfParser::Status status = parser.Parse( config_file );
|
|
|
|
|
|
if( status == ConfParser::ok )
|
|
{
|
|
AssignValues(stdout_is_closed);
|
|
SetAdditionalVariables();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
ShowError();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void Config::AssignValues(bool stdout_is_closed)
|
|
{
|
|
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);
|
|
|
|
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 --");
|
|
|
|
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");
|
|
|
|
compression = Bool("compression", true);
|
|
html_filter = Bool("html_filter", true);
|
|
|
|
locale_str = Text("locale", "en");
|
|
locale_dir = Text("locale_dir");
|
|
locale_dir_default = Text("locale_dir_default");
|
|
|
|
title_separator = Text("title_separator", " / ");
|
|
|
|
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 parser.Text(name);
|
|
}
|
|
|
|
|
|
std::string Config::Text(const char * name, const char * def)
|
|
{
|
|
return parser.Text(name, def);
|
|
}
|
|
|
|
|
|
std::string Config::Text(const std::string & name, const std::string & def)
|
|
{
|
|
return parser.Text(name, def);
|
|
}
|
|
|
|
|
|
int Config::Int(const char * name)
|
|
{
|
|
return parser.Int(name);
|
|
}
|
|
|
|
|
|
int Config::Int(const char * name, int def)
|
|
{
|
|
return parser.Int(name, def);
|
|
}
|
|
|
|
|
|
int Config::Int(const std::string & name, int def)
|
|
{
|
|
return parser.Int(name, def);
|
|
}
|
|
|
|
|
|
bool Config::Bool(const char * name)
|
|
{
|
|
return parser.Bool(name);
|
|
}
|
|
|
|
|
|
bool Config::Bool(const char * name, bool def)
|
|
{
|
|
return parser.Bool(name, def);
|
|
}
|
|
|
|
|
|
bool Config::Bool(const std::string & name, bool def)
|
|
{
|
|
return parser.Bool(name, def);
|
|
}
|
|
|
|
|
|
|
|
void Config::ListText(const char * name, std::vector<std::string> & list)
|
|
{
|
|
parser.ListText(name, list);
|
|
}
|
|
|
|
|
|
void Config::ListText(const std::string & name, std::vector<std::string> & list)
|
|
{
|
|
parser.ListText(name, list);
|
|
}
|
|
|
|
|
|
|
|
void Config::NoLastSlash(std::string & s)
|
|
{
|
|
if( s.empty() )
|
|
return;
|
|
|
|
|
|
size_t i = s.size();
|
|
|
|
for( ; i>0 && s[i-1]=='/' ; --i);
|
|
|
|
if( i < s.size() )
|
|
s.erase(i);
|
|
}
|
|
|
|
|
|
|
|
void Config::NoFirstHttp(std::string & s)
|
|
{
|
|
if( s.empty() )
|
|
return;
|
|
|
|
const char http[] = "http://";
|
|
const char https[] = "https://";
|
|
|
|
if( IsSubStringNoCase(http, s.c_str()) )
|
|
{
|
|
s.erase(0, sizeof(http)/sizeof(char));
|
|
}
|
|
else
|
|
if( IsSubStringNoCase(https, s.c_str()) )
|
|
{
|
|
s.erase(0, sizeof(https)/sizeof(char));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|