WIP: remove the old database abstraction layer

remove such classes:
- DbBase
- DbConn
- DbTextStream
- Db

while here:
- remove: TextStream, SLog, TexTextStream
This commit is contained in:
2024-06-22 18:03:54 +02:00
parent 5d457f3d4b
commit 6aa100f12c
138 changed files with 6658 additions and 12402 deletions
+17 -67
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2023, Tomasz Sowa
* Copyright (c) 2010-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -103,13 +103,7 @@ App::App()
cur.session = nullptr;
cur.mount = nullptr;
db_conn.set_dependency(&winix_base);
db.set_dependency(&winix_base);
db.SetConn(db_conn);
plugin.set_dependency(&winix_model);
plugin.SetDb(&db);
plugin.SetCur(&cur);
plugin.SetSystem(&system);
plugin.SetFunctions(&functions);
@@ -128,7 +122,6 @@ App::App()
//functions.SetConfig(&config);
functions.SetCur(&cur);
functions.SetDb(&db);
functions.SetSystem(&system);
functions.SetTemplates(&templates);
//functions.SetSynchro(&synchro);
@@ -138,7 +131,6 @@ App::App()
system.set_dependency(&winix_model);
//system.SetConfig(&config);
system.SetCur(&cur);
system.SetDb(&db);
//system.SetSynchro(&synchro);
system.SetFunctions(&functions);
system.SetSessionManager(&session_manager);
@@ -146,7 +138,6 @@ App::App()
templates.set_dependency(&winix_request);
templates.SetConfig(&config);
templates.SetCur(&cur);
templates.SetDb(&db);
templates.SetSystem(&system);
templates.SetFunctions(&functions);
templates.SetSessionManager(&session_manager);
@@ -174,38 +165,10 @@ Log & App::GetMainLog()
}
bool App::TranslateFCGInames(char * sock, char * sock_user, char * sock_group)
{
if( !wide_to_utf8(config.fcgi_socket, sock, WINIX_OS_PATH_SIZE) )
{
log << log1 << "App: I cannot correctly change FastCGI socket path to utf-8 string" << logend;
return false;
}
if( config.fcgi_set_socket_owner )
{
if( !wide_to_utf8(config.fcgi_socket_user, sock_user, WINIX_OS_USERNAME_SIZE) )
{
log << log1 << "App: I cannot correctly change FastCGI user name to utf-8 string" << logend;
return false;
}
if( !wide_to_utf8(config.fcgi_socket_group, sock_group, WINIX_OS_USERNAME_SIZE) )
{
log << log1 << "App: I cannot correctly change FastCGI group name to utf-8 string" << logend;
return false;
}
}
return true;
}
/*
* chmod and chown of the socket are set before winix drops privileges
*/
bool App::InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_group)
bool App::InitFCGIChmodChownSocket(const char * sock)
{
if( config.fcgi_set_socket_chmod )
{
@@ -218,7 +181,11 @@ bool App::InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_gr
if( config.fcgi_set_socket_owner )
{
passwd * pw = getpwnam(sock_user);
std::string sock_user, sock_group;
pt::wide_to_utf8(config.fcgi_socket_user, sock_user);
pt::wide_to_utf8(config.fcgi_socket_group, sock_group);
passwd * pw = getpwnam(sock_user.c_str());
if( !pw )
{
@@ -226,7 +193,7 @@ bool App::InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_gr
return false;
}
group * gr = getgrnam(sock_group);
group * gr = getgrnam(sock_group.c_str());
if( !gr )
{
@@ -248,17 +215,13 @@ return true;
bool App::InitFCGI()
{
char sock[WINIX_OS_PATH_SIZE];
char sock_user[WINIX_OS_USERNAME_SIZE];
char sock_group[WINIX_OS_USERNAME_SIZE];
std::string sock, sock_user, sock_group;
pt::wide_to_utf8(config.fcgi_socket, sock);
if( !TranslateFCGInames(sock, sock_user, sock_group) )
return false;
unlink(sock);
unlink(sock.c_str());
log << log3 << "App: trying to create a fcgi connection socket: " << sock << logend << logsave;
fcgi_socket = FCGX_OpenSocket(sock, config.fcgi_socket_listen);
fcgi_socket = FCGX_OpenSocket(sock.c_str(), config.fcgi_socket_listen);
/*
* WARNING:
* when there is a problem with creating the socket then FCGX_OpenSocket will call exit()
@@ -273,16 +236,16 @@ char sock_group[WINIX_OS_USERNAME_SIZE];
log << log3 << "App: FastCGI socket number: " << fcgi_socket << logend;
if( !InitFCGIChmodChownSocket(sock, sock_user, sock_group) )
if( !InitFCGIChmodChownSocket(sock.c_str()) )
return false;
if( FCGX_Init() != 0 )
{
log << log1 << "App: FCGX_Init fails" << logend;
log << log1 << "App: FCGX_Init has failed" << logend;
return false;
}
return true;
return true;
}
@@ -385,7 +348,6 @@ bool App::Init()
model_connector.set_winix_mounts(&system.mounts);
model_connector.set_winix_users(&system.users);
model_connector.set_winix_groups(&system.groups);
model_connector.set_winix_session_logger(nullptr); // will be set for each request
model_connector.set_winix_session(nullptr); // will be set for each request
model_connector.set_winix_locale(&TemplatesFunctions::locale);
model_connector.set_winix_session_manager(&session_manager);
@@ -400,17 +362,6 @@ bool App::Init()
if( !TryToMakeDatabaseMigration() )
return false;
// will be removed
if( !config.db_conn_string.empty() )
db_conn.SetConnParam(config.db_conn_string);
else
db_conn.SetConnParam(config.db_host, config.db_hostaddr, config.db_port, config.db_database, config.db_user, config.db_pass);
if( !db_conn.WaitForConnection(config.db_startup_connection_max_attempts, config.db_startup_connection_attempt_delay) )
return false;
db.LogQueries(config.log_db_query);
compress.set_dependency(&winix_base);
compress.Init();
@@ -827,7 +778,6 @@ void App::ClearAfterRequest()
model_connector.set_winix_request(nullptr);
model_connector.set_winix_session(nullptr);
model_connector.set_winix_session_logger(nullptr);
log << logendrequest;
}
@@ -1580,10 +1530,10 @@ void App::LogUserGroups()
bool App::DropPrivileges(char * user, char * group)
{
if( !wide_to_utf8(config.user, user, WINIX_OS_USERNAME_SIZE) )
if( !pt::wide_to_utf8(config.user, (char*)user, WINIX_OS_USERNAME_SIZE) )
return false;
if( !wide_to_utf8(config.group, group, WINIX_OS_USERNAME_SIZE) )
if( !pt::wide_to_utf8(config.group, (char*)group, WINIX_OS_USERNAME_SIZE) )
return false;
return true;