added support for UTF-8
now the UTF-8 is a default charset git-svn-id: svn://ttmath.org/publicrep/winix/trunk@677 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
225
core/config.cpp
225
core/config.cpp
@@ -68,6 +68,7 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
|
||||
parser.SplitSingle(true);
|
||||
parser.UTF8(true); // config is always read in UTF-8
|
||||
ConfParser::Status status = parser.Parse( config_file );
|
||||
|
||||
|
||||
@@ -89,47 +90,47 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
|
||||
void Config::AssignValues(bool stdout_is_closed)
|
||||
{
|
||||
demonize = Bool("demonize", true);
|
||||
demonize = Bool(L"demonize", true);
|
||||
|
||||
user = Text("user");
|
||||
group = Text("group");
|
||||
additional_groups = Bool("additional_groups", true);
|
||||
user = AText(L"user");
|
||||
group = AText(L"group");
|
||||
additional_groups = Bool(L"additional_groups", true);
|
||||
|
||||
log_file = Text("log_file");
|
||||
log_notify_file = Text("log_notify_file");
|
||||
log_delimiter = Text("log_delimiter", "---------------------------------------------------------------------------------");
|
||||
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);
|
||||
log_db_query = Bool("log_db_query", false);
|
||||
log_file = AText(L"log_file");
|
||||
log_notify_file = AText(L"log_notify_file");
|
||||
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
|
||||
fcgi_socket = AText(L"fcgi_socket");
|
||||
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
|
||||
fcgi_socket_user = AText(L"fcgi_socket_user");
|
||||
fcgi_socket_group = AText(L"fcgi_socket_group");
|
||||
log_level = Int(L"log_level", 1);
|
||||
log_request = Int(L"log_request", 1);
|
||||
log_stdout = Bool(L"log_stdout", false);
|
||||
log_db_query = Bool(L"log_db_query", 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");
|
||||
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
|
||||
auth_simplefs_dir = Text(L"auth_simplefs_dir");
|
||||
auth_hashfs_dir = Text(L"auth_hashfs_dir");
|
||||
auth_tmp_dir = Text(L"auth_tmp_dir");
|
||||
|
||||
templates_dir = Text("templates_dir");
|
||||
templates_dir_default = Text("templates_dir_default");
|
||||
templates_fun_prefix = Text("templates_fun_prefix", "fun_");
|
||||
templates_fun_postfix = Text("templates_fun_postfix", ".html");
|
||||
templates_index = Text("templates_index", "index.html");
|
||||
template_only_root_use_template_fun = Bool("template_only_root_use_template_fun", false);
|
||||
templates_dir = Text(L"templates_dir");
|
||||
templates_dir_default = Text(L"templates_dir_default");
|
||||
templates_fun_prefix = Text(L"templates_fun_prefix", L"fun_");
|
||||
templates_fun_postfix = Text(L"templates_fun_postfix", L".html");
|
||||
templates_index = Text(L"templates_index", L"index.html");
|
||||
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
||||
|
||||
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");
|
||||
http_session_id_name = AText(L"http_session_id_name");
|
||||
db_database = AText(L"db_database");
|
||||
db_user = AText(L"db_user");
|
||||
db_pass = AText(L"db_pass");
|
||||
item_url_empty = Text(L"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");
|
||||
base_server = Text(L"base_server");
|
||||
base_url = Text(L"base_url");
|
||||
base_url_auth = Text(L"base_url_auth");
|
||||
base_url_static = Text(L"base_url_static");
|
||||
base_url_common = Text(L"base_url_common");
|
||||
|
||||
NoLastSlash(base_server);
|
||||
NoLastSlash(base_url);
|
||||
@@ -137,43 +138,45 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
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 --");
|
||||
priv_no_user = Text(L"priv_no_user", L"-- no user --");
|
||||
priv_no_group = Text(L"priv_no_group", L"-- 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");
|
||||
session_max_idle = Int(L"session_max_idle", 10800); // 3h
|
||||
session_remember_max_idle = Int(L"session_remember_max_idle", 16070400); // 3 months
|
||||
session_file = AText(L"session_file");
|
||||
|
||||
compression = Bool("compression", true);
|
||||
compression_page_min_size = Int("compression_page_min_size", 512);
|
||||
compression = Bool(L"compression", true);
|
||||
compression_page_min_size = Int(L"compression_page_min_size", 512);
|
||||
|
||||
html_filter = Bool("html_filter", true);
|
||||
html_filter_trim_white = Bool("html_filter_trim_white", true);
|
||||
html_filter_break_lines = Int("html_filter_break_lines", 60);
|
||||
html_filter_tabs = Size("html_filter_tabs", 2);
|
||||
html_filter_orphans = Bool("html_filter_orphans", false);
|
||||
html_filter_orphans_lang_str = Text("html_filter_orphans_lang", "pl");
|
||||
html_filter_orphans_mode_str = Text("html_filter_orphans_mode_str", "nbsp");
|
||||
html_filter = Bool(L"html_filter", true);
|
||||
html_filter_trim_white = Bool(L"html_filter_trim_white", true);
|
||||
html_filter_break_lines = Int(L"html_filter_break_lines", 60);
|
||||
html_filter_tabs = Size(L"html_filter_tabs", 2);
|
||||
html_filter_orphans = Bool(L"html_filter_orphans", false);
|
||||
html_filter_orphans_lang_str = AText(L"html_filter_orphans_lang", L"pl");
|
||||
html_filter_orphans_mode_str = AText(L"html_filter_orphans_mode_str", L"nbsp");
|
||||
|
||||
locale_str = Text("locale", "en");
|
||||
locale_dir = Text("locale_dir");
|
||||
locale_dir_default = Text("locale_dir_default");
|
||||
locale_str = Text(L"locale", L"en");
|
||||
locale_dir = Text(L"locale_dir");
|
||||
locale_dir_default = Text(L"locale_dir_default");
|
||||
|
||||
title_separator = Text("title_separator", " / ");
|
||||
title_separator = Text(L"title_separator", L" / ");
|
||||
|
||||
http_header_send_file = Text("http_header_send_file", "X-LIGHTTPD-send-file");
|
||||
password_min_size = Size("password_min_size", 5);
|
||||
debug_info = Bool("debug_info", false);
|
||||
http_header_send_file = Text(L"http_header_send_file", L"X-LIGHTTPD-send-file");
|
||||
password_min_size = Size(L"password_min_size", 5);
|
||||
debug_info = Bool(L"debug_info", false);
|
||||
|
||||
editors_html_safe_mode = Bool("editors_html_safe_mode", true);
|
||||
editors_html_safe_mode_skip_root = Bool("editors_html_safe_mode_skip_root", true);
|
||||
editors_html_safe_mode = Bool(L"editors_html_safe_mode", true);
|
||||
editors_html_safe_mode_skip_root = Bool(L"editors_html_safe_mode_skip_root", true);
|
||||
|
||||
plugins_dir = Text("plugins_dir", "/usr/local/winix/plugins");
|
||||
plugins_dir = Text(L"plugins_dir", L"/usr/local/winix/plugins");
|
||||
NoLastSlash(plugins_dir);
|
||||
parser.ListText("plugins", plugin_file);
|
||||
parser.ListText(L"plugins", plugin_file);
|
||||
|
||||
time_zone_offset = Int("time_zone_offset", 0);
|
||||
time_zone_offset_guest = Int("time_zone_offset_guest", 0);
|
||||
time_zone_offset = Int(L"time_zone_offset", 0);
|
||||
time_zone_offset_guest = Int(L"time_zone_offset_guest", 0);
|
||||
|
||||
utf8 = Bool(L"utf8", true);
|
||||
}
|
||||
|
||||
|
||||
@@ -202,137 +205,130 @@ void Config::SetAdditionalVariables()
|
||||
|
||||
|
||||
|
||||
void Config::SetHttpHost(const std::string & in, std::string & out)
|
||||
void Config::SetHttpHost(const std::wstring & in, std::wstring & out)
|
||||
{
|
||||
if( strncmp(in.c_str(), "http://", 7) == 0 )
|
||||
out = in.substr(7);
|
||||
const char http[] = "http://";
|
||||
const char https[] = "https://";
|
||||
size_t http_len = sizeof(http) / sizeof(char) - 1;
|
||||
size_t https_len = sizeof(https) / sizeof(char) - 1;
|
||||
|
||||
if( IsSubString(http, in.c_str()) )
|
||||
out = in.substr(http_len);
|
||||
else
|
||||
if( strncmp(in.c_str(), "https://", 8) == 0 )
|
||||
out = in.substr(8);
|
||||
if( IsSubString(https, in.c_str()) )
|
||||
out = in.substr(https_len);
|
||||
else
|
||||
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
|
||||
}
|
||||
|
||||
|
||||
std::string Config::Text(const char * name)
|
||||
std::wstring Config::Text(const wchar_t * name)
|
||||
{
|
||||
return parser.Text(name);
|
||||
}
|
||||
|
||||
|
||||
std::string Config::Text(const char * name, const char * def)
|
||||
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
return parser.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::string Config::Text(const std::string & name, const std::string & def)
|
||||
std::wstring Config::Text(const std::wstring & name, const std::wstring & def)
|
||||
{
|
||||
return parser.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const char * name)
|
||||
std::string Config::AText(const wchar_t * name)
|
||||
{
|
||||
return parser.AText(name);
|
||||
}
|
||||
|
||||
|
||||
std::string Config::AText(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
return parser.AText(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::string Config::AText(const std::wstring & name, const std::wstring & def)
|
||||
{
|
||||
return parser.AText(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Config::Int(const wchar_t * name)
|
||||
{
|
||||
return parser.Int(name);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const char * name, int def)
|
||||
int Config::Int(const wchar_t * name, int def)
|
||||
{
|
||||
return parser.Int(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const std::string & name, int def)
|
||||
int Config::Int(const std::wstring & name, int def)
|
||||
{
|
||||
return parser.Int(name, def);
|
||||
}
|
||||
|
||||
|
||||
size_t Config::Size(const char * name)
|
||||
size_t Config::Size(const wchar_t * name)
|
||||
{
|
||||
return parser.Size(name);
|
||||
}
|
||||
|
||||
|
||||
size_t Config::Size(const char * name, size_t def)
|
||||
size_t Config::Size(const wchar_t * name, size_t def)
|
||||
{
|
||||
return parser.Size(name, def);
|
||||
}
|
||||
|
||||
|
||||
size_t Config::Size(const std::string & name, size_t def)
|
||||
size_t Config::Size(const std::wstring & name, size_t def)
|
||||
{
|
||||
return parser.Size(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const char * name)
|
||||
bool Config::Bool(const wchar_t * name)
|
||||
{
|
||||
return parser.Bool(name);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const char * name, bool def)
|
||||
bool Config::Bool(const wchar_t * name, bool def)
|
||||
{
|
||||
return parser.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const std::string & name, bool def)
|
||||
bool Config::Bool(const std::wstring & name, bool def)
|
||||
{
|
||||
return parser.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Config::ListText(const char * name, std::vector<std::string> & list)
|
||||
void Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||
{
|
||||
parser.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
void Config::ListText(const std::string & name, std::vector<std::string> & list)
|
||||
void Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||
{
|
||||
parser.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Config::NoLastSlash(std::string & s)
|
||||
void Config::Print(std::ostream & out)
|
||||
{
|
||||
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));
|
||||
}
|
||||
parser.Print(out);
|
||||
}
|
||||
|
||||
|
||||
@@ -341,4 +337,3 @@ void Config::NoFirstHttp(std::string & s)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user