/* * 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"); 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); 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); compression_page_min_size = Int("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"); locale_str = Text("locale", "en"); locale_dir = Text("locale_dir"); locale_dir_default = Text("locale_dir_default"); title_separator = Text("title_separator", " / "); 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); parser.ListText("plugins", plugin_file); } void Config::SetAdditionalVariables() { SetHttpHost(base_url, base_url_http_host); SetHttpHost(base_url_auth, base_url_auth_http_host); if( html_filter_orphans_lang_str == "pl" ) html_filter_orphans_lang = HTMLFilter::lang_pl; else if( html_filter_orphans_lang_str == "cz" ) html_filter_orphans_lang = HTMLFilter::lang_cz; else if( html_filter_orphans_lang_str == "sk" ) html_filter_orphans_lang = HTMLFilter::lang_sk; else html_filter_orphans_lang = HTMLFilter::lang_none; if( html_filter_orphans_mode_str == "160" ) html_filter_orphans_mode = HTMLFilter::orphan_160space; else html_filter_orphans_mode = HTMLFilter::orphan_nbsp; } 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); } size_t Config::Size(const char * name) { return parser.Size(name); } size_t Config::Size(const char * name, size_t def) { return parser.Size(name, def); } size_t Config::Size(const std::string & name, size_t def) { return parser.Size(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 & list) { parser.ListText(name, list); } void Config::ListText(const std::string & name, std::vector & 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)); } }