start working on 0.7.x branch

- added FileLog which stores content to the file log
- now Log is only a wrapper - it puts messages to the local buffer and when logsave is used then the buffer is put to FileLog
- new base classes:
  WinixBase (Log, Config*, Synchro*)
  WinixModel : public WinixBase (morm::ModelConnector*, Plugin*)
  WinixSystem : public WinixModel (System*)
  WinixRequest : public WinixSystem (SLog, Cur*)
- singletons: log, slog, plugin are depracated - now references to them are in base classses (WinixBase, WinixModel)
- DbBase,  DbConn and Db are depracated - now we are using Morm project (in WinixModel there is a model_connector pointer)
  each thread will have its own ModelConnector





git-svn-id: svn://ttmath.org/publicrep/winix/branches/0.7.x@1146 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2018-11-21 11:03:53 +00:00
parent a7c47140ae
commit a2ffc1e81c
121 changed files with 7832 additions and 6662 deletions

View File

@@ -52,6 +52,7 @@
#include "convert/convert.h"
namespace Winix
{
@@ -64,36 +65,76 @@ App::App()
last_sessions_save = std::time(0);
fcgi_socket = -1;
log.SetLogBuffer(&log_buffer);
log.SetFileLog(&file_log);
log.Init(config.log_level, config.log_save_each_line, config.log_request);
// objects dependency for main thread
winix_base.set_config(&config);
winix_base.set_log_buffer(&log_buffer);
winix_base.set_file_log(&file_log);
winix_base.set_synchro(&synchro);
winix_model.set_dependency(&winix_base);
winix_model.set_plugin(&plugin);
winix_model.set_model_connector(&model_connector);
winix_system.set_dependency(&winix_model);
winix_system.set_system(&system);
winix_request.set_dependency(&winix_system);
winix_request.set_cur(&cur);
winix_request.set_session_manager(&session_manager);
winix_request.set_locale(&TemplatesFunctions::locale);
// //////////////////////////////////
config.SetFileLog(&file_log);
// temporary there is only one request
cur.request = &req;
cur.session = session_manager.GetTmpSession();
cur.mount = system.mounts.GetEmptyMount();
db_conn.set_dependency(&winix_base);
db.set_dependency(&winix_base);
db.SetConn(db_conn);
plugin.set_dependency(&winix_base);
plugin.SetDb(&db);
plugin.SetConfig(&config);
//plugin.SetConfig(&config);
plugin.SetCur(&cur);
plugin.SetSystem(&system);
plugin.SetFunctions(&functions);
plugin.SetTemplates(&templates);
plugin.SetSynchro(&synchro);
//plugin.SetSynchro(&synchro);
plugin.SetSessionManager(&session_manager);
plugin.SetWinixSystem(&winix_system);
req.SetConfig(&config);
functions.SetConfig(&config);
functions.set_dependency(&winix_request);
// functions.set_config(&config);
// functions.set_file_log(&file_log);
// functions.set_model_connector(&model_connector);
// functions.set_synchro(&synchro);
//functions.SetConfig(&config);
functions.SetCur(&cur);
functions.SetDb(&db);
functions.SetSystem(&system);
functions.SetTemplates(&templates);
functions.SetSynchro(&synchro);
//functions.SetSynchro(&synchro);
functions.SetSessionManager(&session_manager);
system.SetConfig(&config);
system.set_dependency(&winix_model);
//system.SetConfig(&config);
system.SetCur(&cur);
system.SetDb(&db);
system.SetSynchro(&synchro);
//system.SetSynchro(&synchro);
system.SetFunctions(&functions);
system.SetSessionManager(&session_manager);
@@ -104,20 +145,33 @@ App::App()
templates.SetFunctions(&functions);
templates.SetSessionManager(&session_manager);
session_manager.set_dependency(&winix_model); // zobaczyc czy wskoczy do przeciazonej metody w session manager
session_manager.SetLastContainer(&system.users.last);
session_manager.SetConfig(&config);
session_manager.SetCur(&cur);
session_manager.SetSystem(&system);
session_manager.SetSynchro(&synchro);
post_multi_parser.set_dependency(&winix_base);
post_multi_parser.SetConfig(&config);
slog.SetCur(&cur);
slog.SetLocale(&TemplatesFunctions::locale);
}
void App::InitFileLog()
{
file_log.set_synchro(&synchro);
file_log.set_time_zones(&system.time_zones);
file_log.init(config.log_file, config.log_stdout, config.log_time_zone_id);
}
void App::InitPlugins()
{
plugin.LoadPlugins(config.plugins_dir, config.plugin_file);
}
bool App::InitFCGI(char * sock, char * sock_user, char * sock_group)
{
if( !WideToUTF8(config.fcgi_socket, sock, WINIX_OS_PATH_SIZE) )
@@ -213,14 +267,27 @@ return true;
bool App::Init()
{
// temporarily
logger.init(config.log_level, config.log_save_each_line, L"/var/log/www/db.log", config.log_stdout);
postgresql_connector.set_logger(logger);
postgresql_connector.set_conn_param(config.db_database, config.db_user, config.db_pass);
postgresql_connector.wait_for_connection();
model_connector.set_flat_connector(json_connector);
model_connector.set_db_connector(postgresql_connector);
//model_connector.set_doc_connector(doc_html_connector);
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
db_conn.WaitForConnection();
db.PostgreSQLsmallerThan10(config.db_postgresql_smaller_than_10);
db.LogQueries(config.log_db_query);
cur.request->Clear();
compress.set_dependency(&winix_base);
compress.Init();
system.Init();
functions.Init();
templates.Init(); // init templates after functions are created
@@ -234,9 +301,14 @@ bool App::Init()
CreateStaticTree();
post_parser.set_dependency(&winix_model);
post_parser.LogValueSize(config.log_post_value_size);
// post_multi_parser has a pointer to the config
cookie_parser.set_dependency(&winix_model);
accept_encoding_parser.set_dependency(&winix_base);
plugin.Call((Session*)0, WINIX_PLUGIN_INIT);
return true;
@@ -246,10 +318,21 @@ return true;
void App::Close()
{
session_manager.SaveSessions();
session_manager.DeleteSessions();
cur.request->Clear();
session_manager.UninitTmpSession();
{
Winix::Lock lock(synchro);
plugin.Call((Winix::Session*)0, WINIX_CLOSE);
session_manager.SaveSessions();
session_manager.DeleteSessions();
cur.request->Clear();
session_manager.UninitTmpSession();
// now all sessions are cleared
}
WaitForThreads();
// now all others threads are terminated
}
@@ -673,7 +756,9 @@ void App::Make()
if( cur.session->ip_ban && cur.session->ip_ban->IsIPBanned() )
{
PT::Date date(cur.session->ip_ban->expires);
slog << logerror << T("this_ip_is_banned_until") << ' ' << date << " UTC" << logend;
// IMPROVE ME there is no slog now
//slog << logerror << T("this_ip_is_banned_until") << ' ' << date << " UTC" << logend;
cur.request->status = WINIX_ERR_PERMISSION_DENIED;
}
@@ -972,7 +1057,7 @@ void App::SetSubdomain()
void App::LogAccess()
{
log << log1;
log.PrintDate(cur.request->start_date, config.log_time_zone_id);
log.PrintDate(cur.request->start_date);
log << ' '
<< cur.request->ip_str << ' '