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:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -46,7 +46,6 @@
|
||||
#include <fcgiapp.h>
|
||||
|
||||
#include "sessionmanager.h"
|
||||
#include "db/db.h"
|
||||
#include "functions/functions.h"
|
||||
#include "templates/templates.h"
|
||||
#include "compress.h"
|
||||
@@ -99,10 +98,6 @@ public:
|
||||
// users sessions
|
||||
SessionManager session_manager;
|
||||
|
||||
// database (DEPRACATED)
|
||||
Db db;
|
||||
DbConn db_conn;
|
||||
|
||||
// an unique id for each request
|
||||
size_t request_id;
|
||||
|
||||
@@ -170,8 +165,7 @@ private:
|
||||
|
||||
bool AddSystemThreads();
|
||||
|
||||
bool TranslateFCGInames(char * sock, char * sock_user, char * sock_group);
|
||||
bool InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_group);
|
||||
bool InitFCGIChmodChownSocket(const char * sock);
|
||||
bool DropPrivileges(char * user, char * group);
|
||||
bool DropPrivileges(const char * user, uid_t uid, gid_t gid, bool additional_groups);
|
||||
bool CheckAccessFromPlugins();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -42,13 +42,6 @@ namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
void Dirs::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
void Dirs::SetCur(Cur * pcur)
|
||||
{
|
||||
cur = pcur;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "dircontainer.h"
|
||||
#include "db/db.h"
|
||||
#include "request.h"
|
||||
#include "models/item.h"
|
||||
#include "winixmodeldeprecated.h"
|
||||
@@ -65,7 +64,6 @@ public:
|
||||
void ReadDirs();
|
||||
|
||||
void SetCur(Cur * pcur);
|
||||
void SetDb(Db * pdb);
|
||||
void SetNotify(Notify * pnotify);
|
||||
|
||||
void set_dependency(WinixModelDeprecated * winix_model);
|
||||
@@ -130,7 +128,6 @@ public:
|
||||
private:
|
||||
|
||||
Cur * cur;
|
||||
Db * db;
|
||||
Notify * notify;
|
||||
|
||||
DirContainer dir_tab;
|
||||
|
||||
@@ -59,7 +59,7 @@ void Groups::Clear()
|
||||
}
|
||||
|
||||
|
||||
void Groups::ReadGroups(Db * db)
|
||||
void Groups::ReadGroups()
|
||||
{
|
||||
Clear();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,7 +39,6 @@
|
||||
|
||||
#include "models/group.h"
|
||||
#include "ugcontainer.h"
|
||||
#include "db/db.h"
|
||||
#include "winixmodeldeprecated.h"
|
||||
|
||||
|
||||
@@ -64,7 +63,7 @@ public:
|
||||
|
||||
Groups();
|
||||
void Clear();
|
||||
void ReadGroups(Db * db);
|
||||
void ReadGroups();
|
||||
Group * GetGroup(long group_id);
|
||||
Group * GetGroup(const std::wstring & name);
|
||||
long GetGroupId(const std::wstring & name);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <ctime>
|
||||
#include "image.h"
|
||||
#include "core/misc.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "system.h"
|
||||
#include "lock.h"
|
||||
@@ -44,14 +45,6 @@ namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
void Image::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
void Image::SetConfig(Config * pconfig)
|
||||
{
|
||||
config = pconfig;
|
||||
@@ -292,19 +285,13 @@ bool end;
|
||||
|
||||
|
||||
|
||||
void Image::Add(const std::wstring & in, TextStream<std::string> & out)
|
||||
{
|
||||
pt::wide_to_utf8(in, add_tempa);
|
||||
out << add_tempa;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Image::EscapePath(const std::string & path, TextStream<std::string> & out, bool clear_stream)
|
||||
void Image::EscapePath(const std::string & path, pt::TextStream & out, bool clear_stream)
|
||||
{
|
||||
if( clear_stream )
|
||||
out.Clear();
|
||||
out.clear();
|
||||
|
||||
out << '"';
|
||||
|
||||
@@ -402,9 +389,9 @@ bool Image::CreateInputFileName()
|
||||
// second thread (objects locked)
|
||||
void Image::CreateTmpFileName()
|
||||
{
|
||||
stream_tmp_path.Clear();
|
||||
stream_tmp_path.clear();
|
||||
stream_tmp_path << config->upload_dir << L"/tmp/image_" << std::time(0);
|
||||
pt::wide_to_utf8(stream_tmp_path.Str(), tmp_file_name);
|
||||
stream_tmp_path.to_str(tmp_file_name);
|
||||
}
|
||||
|
||||
|
||||
@@ -427,8 +414,8 @@ bool Image::CreateCommand()
|
||||
if( !CreateInputFileName() )
|
||||
return false;
|
||||
|
||||
command.Clear();
|
||||
Add(config->convert_cmd, command);
|
||||
command.clear();
|
||||
command << config->convert_cmd;
|
||||
|
||||
command << " ";
|
||||
EscapePath(input_file_name, command, false);
|
||||
@@ -472,7 +459,7 @@ bool Image::CreateCommand()
|
||||
command << " ";
|
||||
EscapePath(tmp_file_name, command, false);
|
||||
|
||||
log << log4 << "Image: running: " << command.Str() << logend;
|
||||
log << log4 << "Image: running: " << command << logend;
|
||||
|
||||
|
||||
return true;
|
||||
@@ -553,7 +540,10 @@ void Image::SaveImage()
|
||||
|
||||
if( system->MakeFilePath(file_work, dst_path, thumb, true, config->upload_dirs_chmod, config->upload_group_int) )
|
||||
{
|
||||
if( RenameFile(stream_tmp_path.Str(), dst_path) )
|
||||
std::wstring from;
|
||||
stream_tmp_path.to_str(from);
|
||||
|
||||
if( RenameFile(from, dst_path) )
|
||||
{
|
||||
// it doesn't matter for us if there is an error when chmod/chown on a file
|
||||
// the admin (root) will correct it
|
||||
@@ -562,10 +552,10 @@ void Image::SaveImage()
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Image: cannot move a temporary file: " << stream_tmp_path.Str()
|
||||
log << log1 << "Image: cannot move a temporary file: " << stream_tmp_path
|
||||
<< ", to: " << dst_path << logend;
|
||||
|
||||
Winix::RemoveFile(stream_tmp_path.Str());
|
||||
Winix::RemoveFile(from);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -582,7 +572,9 @@ void Image::CreateImage()
|
||||
{
|
||||
if( CreateCommand() )
|
||||
{
|
||||
int res = std::system(command.CStr());
|
||||
std::string command_str;
|
||||
command.to_str(command_str);
|
||||
int res = std::system(command_str.c_str());
|
||||
|
||||
if( res == 0 )
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -38,8 +38,6 @@
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "basethread.h"
|
||||
#include "textstream.h"
|
||||
#include "db/db.h"
|
||||
#include "core/config.h"
|
||||
#include "models/item.h"
|
||||
|
||||
@@ -116,7 +114,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
void SetDb(Db * pdb);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetSystem(System * psystem);
|
||||
|
||||
@@ -147,7 +144,6 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
Db * db;
|
||||
Config * config;
|
||||
System * system;
|
||||
|
||||
@@ -185,9 +181,8 @@ private:
|
||||
// only for second thread
|
||||
ImageItem item_work;
|
||||
std::wstring src_path, dst_path;
|
||||
TextStream<std::string> command;
|
||||
TextStream<std::wstring> stream_tmp_path;
|
||||
std::string add_tempa;
|
||||
pt::TextStream command;
|
||||
pt::WTextStream stream_tmp_path;
|
||||
std::string input_file_name;
|
||||
std::string tmp_file_name;
|
||||
Item file_work;
|
||||
@@ -200,9 +195,8 @@ private:
|
||||
void SaveImage();
|
||||
void CreateImage();
|
||||
void SelectAspect(size_t cx, size_t cy);
|
||||
void EscapePath(const std::string & path, TextStream<std::string> & out, bool clear_stream = true);
|
||||
void EscapePath(const std::string & path, pt::TextStream & out, bool clear_stream = true);
|
||||
void CheckParam(ImageItem & item);
|
||||
void Add(const std::wstring & in, TextStream<std::string> & out);
|
||||
void ImageSavedCorrectly();
|
||||
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
||||
* Copyright (c) 2011-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -74,12 +74,6 @@ enum LogManipulators
|
||||
*/
|
||||
logendrequest,
|
||||
|
||||
/*
|
||||
* it would be better to the SLog to have its own manipulators
|
||||
*/
|
||||
loginfo,
|
||||
logerror,
|
||||
logwarning
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -855,7 +855,7 @@ bool IsFile(const wchar_t * file)
|
||||
struct stat sb;
|
||||
char file_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !wide_to_utf8(file, file_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(file, (char*)file_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
return (stat(file_name, &sb) == 0);
|
||||
@@ -877,7 +877,7 @@ char dir_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !IsFile(dir) )
|
||||
{
|
||||
if( !wide_to_utf8(dir, dir_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(dir, (char*)dir_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
if( mkdir(dir_name, 0777) < 0 )
|
||||
@@ -953,7 +953,7 @@ struct group * result;
|
||||
char group_name[WINIX_OS_USERNAME_SIZE];
|
||||
char buffer[512];
|
||||
|
||||
if( !wide_to_utf8(name, group_name, WINIX_OS_USERNAME_SIZE) )
|
||||
if( !pt::wide_to_utf8(name, (char*)group_name, WINIX_OS_USERNAME_SIZE) )
|
||||
return -1;
|
||||
|
||||
if( getgrnam_r(group_name, &gr, buffer, sizeof(buffer)/sizeof(char), &result) != 0 )
|
||||
@@ -989,7 +989,7 @@ bool SetPriv(const wchar_t * name, int priv, int group)
|
||||
{
|
||||
char file_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !wide_to_utf8(name, file_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(name, (char*)file_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
if( chmod(file_name, priv) < 0 )
|
||||
@@ -1047,10 +1047,10 @@ char src_name[WINIX_OS_PATH_SIZE];
|
||||
char dst_name[WINIX_OS_PATH_SIZE];
|
||||
FILE * in, * out;
|
||||
|
||||
if( !wide_to_utf8(src, src_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(src, (char*)src_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
if( !wide_to_utf8(dst, dst_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(dst, (char*)dst_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
in = fopen(src_name, "rb");
|
||||
@@ -1092,7 +1092,7 @@ bool RemoveFile(const wchar_t * file)
|
||||
{
|
||||
char file_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !wide_to_utf8(file, file_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(file, (char*)file_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
return unlink(file_name) == 0;
|
||||
@@ -1111,10 +1111,10 @@ bool RenameFile(const wchar_t * from, const wchar_t * to)
|
||||
char from_name[WINIX_OS_PATH_SIZE];
|
||||
char to_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !wide_to_utf8(from, from_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(from, (char*)from_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
if( !wide_to_utf8(to, to_name, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(to, (char*)to_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
return rename(from_name, to_name) == 0;
|
||||
@@ -1138,7 +1138,7 @@ std::ifstream get_file_content;
|
||||
if( clear_content )
|
||||
content.clear();
|
||||
|
||||
if( !wide_to_utf8(file_path, file, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(file_path, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
||||
@@ -1170,7 +1170,7 @@ std::ifstream get_file_content;
|
||||
if( clear_content )
|
||||
content.clear();
|
||||
|
||||
if( !wide_to_utf8(file_path, file, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(file_path, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
||||
@@ -1205,7 +1205,7 @@ std::ifstream get_file_content;
|
||||
if( clear_content )
|
||||
content.clear();
|
||||
|
||||
if( !wide_to_utf8(file_path, file, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(file_path, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
||||
@@ -1544,29 +1544,6 @@ void JSONescapeStream(const std::wstring & in, pt::WTextStream & out)
|
||||
|
||||
|
||||
|
||||
bool wide_to_utf8(const wchar_t * wide_string, char * utf8, size_t utf8_size)
|
||||
{
|
||||
bool res = pt::wide_to_utf8(wide_string, utf8, utf8_size);
|
||||
|
||||
if( !res )
|
||||
{
|
||||
/*
|
||||
* either the 'utf8' buffer is too small or there was an error when converting
|
||||
*/
|
||||
//log << log1 << "Misc: I cannot convert from a wide string to an UTF-8 string, original string was: "
|
||||
// << wide_string << logend;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool wide_to_utf8(const std::wstring & wide_string, char * utf8, size_t utf8_size)
|
||||
{
|
||||
return wide_to_utf8(wide_string.c_str(), utf8, utf8_size);
|
||||
}
|
||||
|
||||
|
||||
void calculate_timespec_diff(timespec & start, timespec & stop, timespec & result)
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -996,16 +996,6 @@ void JSONescapeStream(const std::wstring & in, pt::WTextStream & out);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* converting from a wide string to an UTF-8 string
|
||||
* and puts a log if the conversion fails
|
||||
*
|
||||
* it uses pt::wide_to_utf8()
|
||||
*/
|
||||
bool wide_to_utf8(const wchar_t * wide_string, char * utf8, size_t utf8_size);
|
||||
bool wide_to_utf8(const std::wstring & wide_string, char * utf8, size_t utf8_size);
|
||||
|
||||
|
||||
/*
|
||||
* calculate diff between start and stop timespec
|
||||
*
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-2022, Tomasz Sowa
|
||||
* Copyright (c) 2009-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,8 +35,6 @@
|
||||
#include "mounts.h"
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "db/db.h"
|
||||
#include "cur.h"
|
||||
#include "dirs.h"
|
||||
|
||||
|
||||
@@ -115,12 +113,6 @@ void Mounts::SetDirs(Dirs * pdirs)
|
||||
}
|
||||
|
||||
|
||||
void Mounts::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
int Mounts::AddMountType(const wchar_t * type)
|
||||
{
|
||||
mount_type_tab.push_back(type);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-2022, Tomasz Sowa
|
||||
* Copyright (c) 2009-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,9 +41,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "mount.h"
|
||||
#include "error.h"
|
||||
#include "db/db.h"
|
||||
#include "request.h"
|
||||
#include "mountparser.h"
|
||||
#include "winixmodeldeprecated.h"
|
||||
|
||||
@@ -51,7 +48,7 @@
|
||||
namespace Winix
|
||||
{
|
||||
class Dirs;
|
||||
|
||||
class Request;
|
||||
|
||||
|
||||
class Mounts : public WinixModelDeprecated
|
||||
@@ -113,7 +110,6 @@ public:
|
||||
int MountParLang() { return mount_par_lang; }
|
||||
|
||||
void SetDirs(Dirs * pdirs);
|
||||
void SetDb(Db * pdb);
|
||||
|
||||
// dir_id, mount_point
|
||||
typedef std::map<long, Mount> MountTab;
|
||||
@@ -142,7 +138,6 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
Db * db;
|
||||
Dirs * dirs;
|
||||
|
||||
bool skip_static;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -65,7 +65,6 @@ Plugin::Plugin()
|
||||
{
|
||||
current_plugin = -1;
|
||||
|
||||
db = nullptr;
|
||||
cur = nullptr;
|
||||
system = nullptr;
|
||||
functions = nullptr;
|
||||
@@ -83,12 +82,6 @@ Plugin::~Plugin()
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::SetSystem(System * psystem)
|
||||
{
|
||||
system = psystem;
|
||||
@@ -145,14 +138,13 @@ void Plugin::Unlock()
|
||||
bool Plugin::SetDependencyForPluginInfo(morm::ModelConnector * pmodel_connector, Log * plog, Cur * pcur, PluginInfo & info)
|
||||
{
|
||||
// for safety we call a plugin function only when all our pointers are not null
|
||||
bool res = (pmodel_connector && plog && pcur && db && config && system && functions && templates && synchro && session_manager && winix_request);
|
||||
bool res = (pmodel_connector && plog && pcur && config && system && functions && templates && synchro && session_manager && winix_request);
|
||||
|
||||
if( !res )
|
||||
{
|
||||
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
|
||||
}
|
||||
|
||||
info.db = db;
|
||||
info.config = config;
|
||||
info.cur = pcur;
|
||||
info.system = system;
|
||||
@@ -198,8 +190,8 @@ void * Plugin::LoadInitFun(const wchar_t * filename, Fun1 & fun_init)
|
||||
{
|
||||
char file[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !wide_to_utf8(filename, file, WINIX_OS_PATH_SIZE) )
|
||||
return 0;
|
||||
if( !pt::wide_to_utf8(filename, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||
return nullptr;
|
||||
|
||||
void * p = dlopen(file, RTLD_NOW | RTLD_LOCAL);
|
||||
|
||||
@@ -207,7 +199,7 @@ char file[WINIX_OS_PATH_SIZE];
|
||||
{
|
||||
log << log1 << "Plugin: cannot load a plugin: \"" << filename << "\"" << logend;
|
||||
log << log1 << "Plugin: dlerror: " << dlerror() << logend;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fun_init = (Fun1)dlsym(p, "Init");
|
||||
@@ -218,14 +210,14 @@ char file[WINIX_OS_PATH_SIZE];
|
||||
<< " (there is no Init() function)" << logend;
|
||||
|
||||
dlclose(p);
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
log << log2 << "Plugin: plugin loaded"
|
||||
<< ", file: " << filename
|
||||
<< ", index: " << plugins.size() << logend;
|
||||
|
||||
return p;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -99,7 +99,6 @@ struct PluginInfo
|
||||
|
||||
|
||||
// objects from winix which are accessible from a plugin
|
||||
Db * db;
|
||||
Config * config;
|
||||
Cur * cur;
|
||||
System * system;
|
||||
@@ -208,7 +207,6 @@ public:
|
||||
Plugin();
|
||||
~Plugin();
|
||||
|
||||
void SetDb(Db * pdb);
|
||||
void SetSystem(System * psystem);
|
||||
void SetCur(Cur * cur);
|
||||
void SetFunctions(Functions * pfunctions);
|
||||
@@ -253,7 +251,6 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
Db * db;
|
||||
Cur * cur;
|
||||
System * system;
|
||||
Functions * functions;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -42,7 +42,6 @@
|
||||
#include "models/item.h"
|
||||
#include "error.h"
|
||||
#include "config.h"
|
||||
#include "textstream.h"
|
||||
#include "templates/htmltextstream.h"
|
||||
#include "date/date.h"
|
||||
#include "space/space.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -105,7 +105,6 @@ void Session::Clear(bool clear_plugin_data)
|
||||
start_date.Clear();
|
||||
last_date.Clear();
|
||||
|
||||
log_buffer.Clear();
|
||||
last_css.clear();
|
||||
ip_ban = 0;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,7 +43,6 @@
|
||||
#include "models/user.h"
|
||||
#include "plugindata.h"
|
||||
#include "rebus.h"
|
||||
#include "textstream.h"
|
||||
#include "date/date.h"
|
||||
#include "ipban.h"
|
||||
|
||||
@@ -115,9 +114,6 @@ public:
|
||||
PluginData plugin_data;
|
||||
|
||||
|
||||
// buffer for the session log
|
||||
TextStream<std::wstring> log_buffer;
|
||||
|
||||
// !! IMPROVE ME it is still needed?
|
||||
// css cannot be taken directly from the mountpoint?
|
||||
// table with css files
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <limits>
|
||||
#include "sessionmanager.h"
|
||||
#include "core/misc.h"
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "session.h"
|
||||
@@ -713,7 +714,7 @@ char file_path[WINIX_OS_PATH_SIZE];
|
||||
return;
|
||||
}
|
||||
|
||||
if( !wide_to_utf8(config->session_file, file_path, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(config->session_file, (char*)file_path, WINIX_OS_PATH_SIZE) )
|
||||
return;
|
||||
|
||||
std::ofstream file(file_path);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -60,7 +60,7 @@ char file_path[WINIX_OS_PATH_SIZE];
|
||||
|
||||
container.Clear();
|
||||
|
||||
if( !wide_to_utf8(path, file_path, WINIX_OS_PATH_SIZE) )
|
||||
if( !pt::wide_to_utf8(path, (char*)file_path, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
file.open(file_path, std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
@@ -1,257 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "slog.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
SLog::SLog()
|
||||
{
|
||||
cur = 0;
|
||||
locale = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SLog::SetCur(Cur * pcur)
|
||||
{
|
||||
cur = pcur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SLog::SetLocale(Locale * plocale)
|
||||
{
|
||||
locale = plocale;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const void * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const char * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::string * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::string & s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const wchar_t * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::wstring * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::wstring & s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(int s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(long s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(char s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(wchar_t s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(size_t s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(double s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const pt::Date & date)
|
||||
{
|
||||
return PutLog(date);
|
||||
}
|
||||
|
||||
|
||||
|
||||
SLog & SLog::operator<<(LogManipulators m)
|
||||
{
|
||||
if( cur && cur->session )
|
||||
{
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
switch(m)
|
||||
{
|
||||
case logend:
|
||||
buf << '\n';
|
||||
|
||||
if( buf.Size() > WINIX_SLOG_MAX_LOG_SIZE )
|
||||
{
|
||||
buf.Clear();
|
||||
(*this) << logwarning << T("slog_turn_over") << " " << WINIX_SLOG_MAX_LOG_SIZE << logend;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case loginfo:
|
||||
case logwarning:
|
||||
case logerror:
|
||||
buf << (wchar_t)(int)m;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SLog & SLog::TranslateText(const char * str)
|
||||
{
|
||||
pt::utf8_to_wide(str, key_temp);
|
||||
return TranslateText(key_temp.c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::TranslateText(const wchar_t * str)
|
||||
{
|
||||
if( cur && cur->session )
|
||||
{
|
||||
const std::wstring * trans = 0;
|
||||
|
||||
if( locale )
|
||||
trans = &locale->Get(str);
|
||||
|
||||
// !! IMPROVE ME "Not translated" add to locale
|
||||
if( !trans || trans->empty() )
|
||||
cur->session->log_buffer << "Not translated: " << str;
|
||||
else
|
||||
cur->session->log_buffer << trans;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const TranslateTextHelper<const char*> & raw)
|
||||
{
|
||||
return TranslateText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const TranslateTextHelper<const wchar_t*> & raw)
|
||||
{
|
||||
return TranslateText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<const std::string*> raw)
|
||||
{
|
||||
return TranslateText(raw.par->c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<const std::wstring*> raw)
|
||||
{
|
||||
return TranslateText(raw.par->c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<std::string> raw)
|
||||
{
|
||||
return TranslateText(raw.par.c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<std::wstring> raw)
|
||||
{
|
||||
return TranslateText(raw.par.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_slog
|
||||
#define headerfile_winix_core_slog
|
||||
|
||||
#include "cur.h"
|
||||
#include "logmanipulators.h"
|
||||
#include "templates/locale.h"
|
||||
#include "textstream/textstream.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
#define WINIX_SLOG_MAX_LOG_SIZE 10240
|
||||
|
||||
|
||||
/*
|
||||
session logger
|
||||
|
||||
sample:
|
||||
#include "log.h" (or slog.h)
|
||||
slog << logerror << "message" << "something" << logend;
|
||||
slog << logwarning << T("message_to_translate") << x << logend;
|
||||
|
||||
if the latter example "message_to_translate" will be taken from locales
|
||||
currently following manipulators are taken into account:
|
||||
loginfo - the message in a normal info
|
||||
logwarning - this is a warning
|
||||
logerror - this is an error
|
||||
logend - end of a line -- we have one kind of a message (info, warning, error) per line
|
||||
|
||||
loginfo, logwarning, logerror should be specified at the beginning of a line
|
||||
(other manipulators are skipped)
|
||||
*/
|
||||
class SLog
|
||||
{
|
||||
public:
|
||||
|
||||
SLog();
|
||||
|
||||
void SetCur(Cur * pcur);
|
||||
void SetLocale(Locale * plocale);
|
||||
|
||||
template<class RawType>
|
||||
struct TranslateTextHelper
|
||||
{
|
||||
const RawType & par;
|
||||
|
||||
TranslateTextHelper(const TranslateTextHelper<RawType> & p) : par(p.par) {}
|
||||
TranslateTextHelper(const RawType & p) : par(p) {}
|
||||
};
|
||||
|
||||
SLog & operator<<(const void * s);
|
||||
SLog & operator<<(const char * s);
|
||||
SLog & operator<<(const std::string * s);
|
||||
SLog & operator<<(const std::string & s);
|
||||
SLog & operator<<(const wchar_t * s);
|
||||
SLog & operator<<(const std::wstring * s);
|
||||
SLog & operator<<(const std::wstring & s);
|
||||
SLog & operator<<(int s);
|
||||
SLog & operator<<(long s);
|
||||
SLog & operator<<(char s);
|
||||
SLog & operator<<(wchar_t s);
|
||||
SLog & operator<<(size_t s);
|
||||
SLog & operator<<(double s);
|
||||
SLog & operator<<(LogManipulators m);
|
||||
SLog & operator<<(const pt::Date & date);
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
SLog & operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
||||
|
||||
|
||||
SLog & TranslateText(const char * str);
|
||||
SLog & TranslateText(const wchar_t * str);
|
||||
|
||||
template<size_t str_size>
|
||||
SLog & operator<<(const TranslateTextHelper<const char [str_size]> & raw) { return TranslateText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
SLog & operator<<(const TranslateTextHelper<const wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
SLog & operator<<(const TranslateTextHelper<wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
||||
|
||||
SLog & operator<<(const TranslateTextHelper<const char*> & raw);
|
||||
SLog & operator<<(const TranslateTextHelper<const wchar_t*> & raw);
|
||||
SLog & operator<<(TranslateTextHelper<const std::string*> raw);
|
||||
SLog & operator<<(TranslateTextHelper<const std::wstring*> raw);
|
||||
SLog & operator<<(TranslateTextHelper<std::string> raw);
|
||||
SLog & operator<<(TranslateTextHelper<std::wstring> raw);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
template<class LogParam>
|
||||
SLog & PutLog(const LogParam & par);
|
||||
|
||||
Cur * cur;
|
||||
Locale * locale;
|
||||
std::wstring key_temp;
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<class RawType>
|
||||
SLog::TranslateTextHelper<RawType> T(const RawType & par)
|
||||
{
|
||||
return SLog::TranslateTextHelper<RawType>(par);
|
||||
}
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
SLog & SLog::operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
||||
{
|
||||
return PutLog(buf);
|
||||
}
|
||||
|
||||
|
||||
template<class LogParam>
|
||||
SLog & SLog::PutLog(const LogParam & par)
|
||||
{
|
||||
if( cur && cur->session )
|
||||
cur->session->log_buffer << par;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -58,12 +58,6 @@ void System::SetCur(Cur * pcur)
|
||||
//}
|
||||
|
||||
|
||||
void System::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
}
|
||||
|
||||
|
||||
//void System::SetSynchro(Synchro * psynchro)
|
||||
//{
|
||||
// synchro = psynchro;
|
||||
@@ -129,23 +123,21 @@ bool System::Init()
|
||||
//thread_manager.SetSynchro(synchro);
|
||||
thread_manager.Init();
|
||||
|
||||
dirs.SetDb(db);
|
||||
dirs.SetCur(cur); // only one method is using cur, can be passed as a parameter to the method
|
||||
dirs.SetNotify(¬ify);
|
||||
dirs.ReadDirs();
|
||||
|
||||
mounts.SkipStaticDirs(config->dont_use_static_dirs);
|
||||
mounts.SetDirs(&dirs);
|
||||
mounts.SetDb(db);
|
||||
mounts.CreateMounts();
|
||||
mounts.ReadMounts();
|
||||
|
||||
// users.SetCur(cur);
|
||||
// users.SetSessionManager(session_manager);
|
||||
users.set_connector(model_connector);
|
||||
users.ReadUsers(db);
|
||||
users.ReadUsers();
|
||||
|
||||
groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione
|
||||
groups.ReadGroups();
|
||||
|
||||
rebus.SetCur(cur);
|
||||
rebus.Init();
|
||||
@@ -160,7 +152,6 @@ bool System::Init()
|
||||
if( !notify.Init() )
|
||||
return false;
|
||||
|
||||
image.SetDb(db);
|
||||
image.SetConfig(config);
|
||||
image.SetSystem(this);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "job.h"
|
||||
#include "dirs.h"
|
||||
#include "mounts.h"
|
||||
#include "db/db.h"
|
||||
#include "request.h"
|
||||
#include "config.h"
|
||||
#include "crypt.h"
|
||||
@@ -116,7 +115,6 @@ public:
|
||||
|
||||
void SetCur(Cur * pcur);
|
||||
//void SetConfig(Config * pconfig);
|
||||
void SetDb(Db * pdb);
|
||||
//void SetSynchro(Synchro * psynchro);
|
||||
void SetFunctions(Functions * pfunctions);
|
||||
void SetSessionManager(SessionManager * sm);
|
||||
@@ -229,7 +227,6 @@ public:
|
||||
private:
|
||||
|
||||
Cur * cur;
|
||||
Db * db;
|
||||
//Config * config;
|
||||
//Synchro * synchro;
|
||||
Functions * functions;
|
||||
|
||||
@@ -1,666 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_textstream
|
||||
#define headerfile_winix_core_textstream
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "misc.h"
|
||||
#include "space/space.h"
|
||||
#include "date/date.h"
|
||||
#include "textstream/textstream.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
a special class representing a stream buffer
|
||||
similar to std::ostringstream
|
||||
|
||||
StringType can be either std::string or std::wstring
|
||||
|
||||
this class uses UTF-8 <-> wide characters conversions:
|
||||
if StringType is std::string:
|
||||
operator<<(const char*) only copies the input string
|
||||
operator<<(const wchar_t*) converts from wide characters to UTF-8
|
||||
(similary for an operator with std::string and std::wstring)
|
||||
if StringType is std::wstring:
|
||||
operator<<(const char*) converts from UTF-8 to wide characters
|
||||
operator<<(const wchar_t*) only copies the input string
|
||||
(similary for an operator with std::string and std::wstring)
|
||||
|
||||
*/
|
||||
template<class StringType>
|
||||
class TextStream
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename StringType::value_type CharType;
|
||||
typedef typename StringType::value_type char_type;
|
||||
typedef typename StringType::iterator iterator;
|
||||
typedef typename StringType::const_iterator const_iterator;
|
||||
|
||||
void Clear();
|
||||
void clear(); // utf8 methods call clear(), in the future Clear() will be renamed to clear()
|
||||
bool Empty() const;
|
||||
size_t Size() const;
|
||||
void Reserve(size_t len);
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
|
||||
const StringType & Str() const;
|
||||
const CharType * CStr() const;
|
||||
|
||||
void Str(const StringType & str);
|
||||
void Str(const StringType && str);
|
||||
|
||||
void to_str(std::string & str, bool clear_string = true) const;
|
||||
void to_str(std::wstring & str, bool clear_string = true) const;
|
||||
void to_string(std::string & str, bool clear_string = true) const;
|
||||
void to_string(std::wstring & str, bool clear_string = true) const;
|
||||
|
||||
CharType operator[](size_t index);
|
||||
|
||||
TextStream & operator<<(const char * str);
|
||||
TextStream & operator<<(const std::string * str);
|
||||
TextStream & operator<<(const std::string & str);
|
||||
|
||||
TextStream & operator<<(const wchar_t * str);
|
||||
TextStream & operator<<(const std::wstring * str);
|
||||
TextStream & operator<<(const std::wstring & str);
|
||||
|
||||
TextStream & operator<<(char);
|
||||
TextStream & operator<<(wchar_t);
|
||||
TextStream & operator<<(int);
|
||||
TextStream & operator<<(long);
|
||||
TextStream & operator<<(unsigned int);
|
||||
TextStream & operator<<(unsigned long);
|
||||
TextStream & operator<<(double);
|
||||
TextStream & operator<<(const void *);// printing a pointer
|
||||
TextStream & operator<<(const pt::Space & space);
|
||||
TextStream & operator<<(const pt::Date & date);
|
||||
|
||||
TextStream & operator<<(const TextStream & stream);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TextStream & operator<<(const pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
||||
|
||||
TextStream & Write(const char * buf, size_t len);
|
||||
TextStream & Write(const wchar_t * buf, size_t len);
|
||||
TextStream & write(const char * buf, size_t len); // for compatibility with standard library (Ezc uses it)
|
||||
TextStream & write(const wchar_t * buf, size_t len);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
StringType buffer;
|
||||
|
||||
void Convert(wchar_t c, std::string & dst);
|
||||
void Convert(wchar_t c, std::wstring & dst);
|
||||
|
||||
void Convert(const char * src, size_t len, std::wstring & dst);
|
||||
void Convert(const char * src, std::wstring & dst);
|
||||
void Convert(const std::string & src, std::wstring & dst);
|
||||
|
||||
void Convert(const wchar_t * src, size_t len, std::string & dst);
|
||||
void Convert(const wchar_t * src, std::string & dst);
|
||||
void Convert(const std::wstring & src, std::string & dst);
|
||||
|
||||
void Convert(const char * src, size_t len, std::string & dst);
|
||||
void Convert(const char * src, std::string & dst);
|
||||
void Convert(const std::string & src, std::string & dst);
|
||||
|
||||
void Convert(const wchar_t * src, size_t len, std::wstring & dst);
|
||||
void Convert(const wchar_t * src, std::wstring & dst);
|
||||
void Convert(const std::wstring & src, std::wstring & dst);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Clear()
|
||||
{
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::clear()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
bool TextStream<StringType>::Empty() const
|
||||
{
|
||||
return buffer.empty();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
size_t TextStream<StringType>::Size() const
|
||||
{
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Reserve(size_t len)
|
||||
{
|
||||
buffer.reserve(len);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
typename TextStream<StringType>::iterator TextStream<StringType>::begin()
|
||||
{
|
||||
return buffer.begin();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
typename TextStream<StringType>::iterator TextStream<StringType>::end()
|
||||
{
|
||||
return buffer.end();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
typename TextStream<StringType>::const_iterator TextStream<StringType>::begin() const
|
||||
{
|
||||
return buffer.begin();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
typename TextStream<StringType>::const_iterator TextStream<StringType>::end() const
|
||||
{
|
||||
return buffer.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
const StringType & TextStream<StringType>::Str() const
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
const typename TextStream<StringType>::CharType * TextStream<StringType>::CStr() const
|
||||
{
|
||||
return buffer.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Str(const StringType & str)
|
||||
{
|
||||
buffer = str;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Str(const StringType && str)
|
||||
{
|
||||
buffer = std::move(str);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::to_str(std::string & str, bool clear_string) const
|
||||
{
|
||||
return to_string(str, clear_string);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::to_str(std::wstring & str, bool clear_string) const
|
||||
{
|
||||
return to_string(str, clear_string);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::to_string(std::string & str, bool clear_string) const
|
||||
{
|
||||
if( clear_string )
|
||||
str.clear();
|
||||
|
||||
if constexpr (sizeof(typename StringType::value_type) == sizeof(char))
|
||||
{
|
||||
str.append(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
pt::wide_to_utf8(buffer, str, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::to_string(std::wstring & str, bool clear_string) const
|
||||
{
|
||||
if( clear_string )
|
||||
str.clear();
|
||||
|
||||
if constexpr (sizeof(typename StringType::value_type) == sizeof(wchar_t))
|
||||
{
|
||||
str.append(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
pt::utf8_to_wide(buffer, str, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
typename TextStream<StringType>::CharType TextStream<StringType>::operator[](size_t index)
|
||||
{
|
||||
return buffer[index];
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const char * str)
|
||||
{
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
|
||||
{
|
||||
Convert(*str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
|
||||
{
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
|
||||
{
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
|
||||
{
|
||||
Convert(*str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
|
||||
{
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(char v)
|
||||
{
|
||||
/*
|
||||
* there is no any possibility to treat 'v' as UTF-8 character if we have got
|
||||
* only one character so we only copy it
|
||||
*/
|
||||
buffer += v;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
|
||||
{
|
||||
Convert(v, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(int v)
|
||||
{
|
||||
wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(long v)
|
||||
{
|
||||
wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned int v)
|
||||
{
|
||||
wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned long v)
|
||||
{
|
||||
wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(double v)
|
||||
{
|
||||
char buf[50];
|
||||
|
||||
sprintf(buf, "%f", v);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const void * v)
|
||||
{
|
||||
wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
buf[0] = '0';
|
||||
buf[1] = 'x';
|
||||
|
||||
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
|
||||
{
|
||||
Convert(buf, len, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::write(const char * buf, size_t len)
|
||||
{
|
||||
return Write(buf, len);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
Convert(buf, len, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
return Write(buf, len);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const pt::Space & space)
|
||||
{
|
||||
space.serialize_to_space_stream(*this, true);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const pt::Date & date)
|
||||
{
|
||||
date.Serialize(*this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const TextStream<StringType> & stream)
|
||||
{
|
||||
buffer.append(stream.buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(
|
||||
const pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
|
||||
{
|
||||
typename pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
||||
|
||||
for(i=arg.begin() ; i != arg.end() ; ++i)
|
||||
buffer += static_cast<char_type>(*i);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(wchar_t c, std::string & dst)
|
||||
{
|
||||
pt::int_to_utf8((int)c, dst, false);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(wchar_t c, std::wstring & dst)
|
||||
{
|
||||
dst += c;
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const char * src, size_t len, std::wstring & dst)
|
||||
{
|
||||
pt::utf8_to_wide(src, len, dst, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const char * src, std::wstring & dst)
|
||||
{
|
||||
pt::utf8_to_wide(src, dst, false);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const std::string & src, std::wstring & dst)
|
||||
{
|
||||
pt::utf8_to_wide(src, dst, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::string & dst)
|
||||
{
|
||||
pt::wide_to_utf8(src, len, dst, false);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const wchar_t * src, std::string & dst)
|
||||
{
|
||||
pt::wide_to_utf8(src, dst, false);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const std::wstring & src, std::string & dst)
|
||||
{
|
||||
pt::wide_to_utf8(src, dst, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const char * src, size_t len, std::string & dst)
|
||||
{
|
||||
// we suppose that append is smart enough and we don't have to use reserve()
|
||||
dst.append(src, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const char * src, std::string & dst)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
Convert(src, len, dst);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const std::string & src, std::string & dst)
|
||||
{
|
||||
dst.append(src);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::wstring & dst)
|
||||
{
|
||||
// we suppose that append is smart enough and we don't have to use reserve()
|
||||
dst.append(src, len);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const wchar_t * src, std::wstring & dst)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
Convert(src, len, dst);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const std::wstring & src, std::wstring & dst)
|
||||
{
|
||||
dst.append(src);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2022, Tomasz Sowa
|
||||
* Copyright (c) 2011-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -114,7 +114,6 @@ bool ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
||||
data.model_connector.set_winix_mounts(nullptr);
|
||||
data.model_connector.set_winix_users(nullptr);
|
||||
data.model_connector.set_winix_groups(nullptr);
|
||||
data.model_connector.set_winix_session_logger(nullptr);
|
||||
data.model_connector.set_winix_session(nullptr);
|
||||
data.model_connector.set_winix_locale(nullptr); // null for a moment, may will be changed
|
||||
data.model_connector.set_winix_session_manager(nullptr);// null for a moment, may will be changed
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#include "users.h"
|
||||
#include "sessionmanager.h"
|
||||
#include "slog.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -87,7 +86,7 @@ void Users::Clear()
|
||||
|
||||
|
||||
|
||||
void Users::ReadUsers(Db * db)
|
||||
void Users::ReadUsers()
|
||||
{
|
||||
Clear();
|
||||
|
||||
@@ -195,11 +194,10 @@ return result;
|
||||
|
||||
|
||||
// private
|
||||
bool Users::LoginUserCheckSession(bool use_ses_log)
|
||||
bool Users::LoginUserCheckSession()
|
||||
{
|
||||
Session * session = get_session();
|
||||
Log * log = get_logger();
|
||||
SLog * slog = get_session_logger();
|
||||
|
||||
if( !session )
|
||||
return false;
|
||||
@@ -209,8 +207,8 @@ bool Users::LoginUserCheckSession(bool use_ses_log)
|
||||
if( log )
|
||||
(*log) << log1 << "Users: I cannot login a user on a temporary session" << logend;
|
||||
|
||||
if( slog && use_ses_log )
|
||||
(*slog) << logerror << T(L"service_unavailable") << logend;
|
||||
// if( slog && use_ses_log )
|
||||
// (*slog) << logerror << T(L"service_unavailable") << logend;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -220,19 +218,18 @@ return true;
|
||||
|
||||
|
||||
// private
|
||||
User * Users::LoginUserCheckStatus(long user_id, bool use_ses_log)
|
||||
User * Users::LoginUserCheckStatus(long user_id)
|
||||
{
|
||||
User * puser = GetUser(user_id);
|
||||
Log * log = get_logger();
|
||||
SLog * slog = get_session_logger();
|
||||
|
||||
if( !puser )
|
||||
{
|
||||
if( log )
|
||||
(*log) << log1 << "Users: user id: " << user_id << " is not in system.users table" << logend;
|
||||
|
||||
if( slog && use_ses_log )
|
||||
(*slog) << logerror << T(L"service_unavailable") << logend;
|
||||
// if( slog && use_ses_log )
|
||||
// (*slog) << logerror << T(L"service_unavailable") << logend;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -242,17 +239,17 @@ User * Users::LoginUserCheckStatus(long user_id, bool use_ses_log)
|
||||
(*log) << log1 << "Users: user id: " << user_id << " is not ready for logging in (status: "
|
||||
<< puser->status << ")" << logend;
|
||||
|
||||
if( slog && use_ses_log )
|
||||
{
|
||||
if( puser->status == WINIX_ACCOUNT_NOT_ACTIVATED )
|
||||
(*slog) << logerror << T(L"account_not_activated") << logend;
|
||||
else
|
||||
if( puser->status == WINIX_ACCOUNT_SUSPENDED )
|
||||
(*slog) << logerror << T(L"account_suspended") << logend;
|
||||
else
|
||||
if( puser->status == WINIX_ACCOUNT_BLOCKED )
|
||||
(*slog) << logerror << T(L"account_banned") << logend;
|
||||
}
|
||||
// if( slog && use_ses_log )
|
||||
// {
|
||||
// if( puser->status == WINIX_ACCOUNT_NOT_ACTIVATED )
|
||||
// (*slog) << logerror << T(L"account_not_activated") << logend;
|
||||
// else
|
||||
// if( puser->status == WINIX_ACCOUNT_SUSPENDED )
|
||||
// (*slog) << logerror << T(L"account_suspended") << logend;
|
||||
// else
|
||||
// if( puser->status == WINIX_ACCOUNT_BLOCKED )
|
||||
// (*slog) << logerror << T(L"account_banned") << logend;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -262,17 +259,17 @@ return puser;
|
||||
|
||||
|
||||
|
||||
bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
|
||||
bool Users::LoginUser(long user_id, bool remember_me)
|
||||
{
|
||||
Config * config = get_config();
|
||||
|
||||
if( !config || !config->use_internal_loggin_mechanism )
|
||||
return false;
|
||||
|
||||
if( !LoginUserCheckSession(use_ses_log) )
|
||||
if( !LoginUserCheckSession() )
|
||||
return false;
|
||||
|
||||
User * puser = LoginUserCheckStatus(user_id, use_ses_log);
|
||||
User * puser = LoginUserCheckStatus(user_id);
|
||||
Log * log = get_logger();
|
||||
Session * session = get_session();
|
||||
SessionManager * session_manager = get_session_manager();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "ugcontainer.h"
|
||||
#include "lastcontainer.h"
|
||||
#include "cur.h"
|
||||
#include "db/db.h"
|
||||
#include "models/winixmodel.h"
|
||||
|
||||
|
||||
@@ -73,7 +72,7 @@ public:
|
||||
// void SetSessionManager(SessionManager * sm);
|
||||
|
||||
void Clear();
|
||||
void ReadUsers(Db * db);
|
||||
void ReadUsers();
|
||||
bool AddUser(const User & user);
|
||||
bool IsUser(const std::wstring & name);
|
||||
User * GetUser(long user_id);
|
||||
@@ -84,7 +83,7 @@ public:
|
||||
SizeType Size();
|
||||
bool Remove(long user_id);
|
||||
|
||||
bool LoginUser(long user_id, bool remember_me, bool use_ses_log = false);
|
||||
bool LoginUser(long user_id, bool remember_me);
|
||||
size_t LogoutUser(long user_id);
|
||||
void LogoutCurrentUser();
|
||||
|
||||
@@ -104,8 +103,8 @@ private:
|
||||
//SessionManager * session_manager;
|
||||
long how_many_logged;
|
||||
|
||||
bool LoginUserCheckSession(bool use_ses_log);
|
||||
User * LoginUserCheckStatus(long user_id, bool use_ses_log);
|
||||
bool LoginUserCheckSession();
|
||||
User * LoginUserCheckStatus(long user_id);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018, Tomasz Sowa
|
||||
* Copyright (c) 2018-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -55,7 +55,6 @@ WinixRequest::~WinixRequest()
|
||||
void WinixRequest::set_cur(Cur * cur)
|
||||
{
|
||||
this->cur = cur;
|
||||
slog.SetCur(cur);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +67,6 @@ void WinixRequest::set_session_manager(SessionManager * session_manager)
|
||||
void WinixRequest::set_locale(Locale * locale)
|
||||
{
|
||||
this->locale = locale;
|
||||
slog.SetLocale(locale);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018, Tomasz Sowa
|
||||
* Copyright (c) 2018-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "core/winixsystem.h"
|
||||
#include "core/cur.h"
|
||||
#include "core/sessionmanager.h"
|
||||
#include "core/slog.h"
|
||||
#include "templates/locale.h"
|
||||
|
||||
|
||||
@@ -66,8 +65,6 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
SLog slog;
|
||||
|
||||
Cur * cur;
|
||||
Locale * locale; // locales can be used not only in templates -- should be moved to a better place
|
||||
SessionManager * session_manager; // may it should be moved to WinixSystem or System?
|
||||
|
||||
Reference in New Issue
Block a user