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
pull/3/head
Tomasz Sowa 2018-11-21 11:03:53 +00:00
parent a7c47140ae
commit a2ffc1e81c
121 changed files with 7832 additions and 6662 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionidmanager.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o filelog.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionidmanager.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,6 +36,7 @@
#define headerfile_winix_core_acceptbaseparser
#include <string>
#include "winixbase.h"
namespace Winix
@ -46,7 +47,7 @@ namespace Winix
// sample (you must create your own class derived from this one):
// object.Parse(L" text/html ; , ; q = 45, application / xhtml+xml ; q = 0.4 , application/xml ; q = 0.9 , */* ; q = 0.8 ");
class AcceptBaseParser
class AcceptBaseParser : public WinixBase
{
public:

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 << ' '

View File

@ -45,11 +45,6 @@
#include <errno.h>
#include <fcgiapp.h>
#include "config.h"
#include "system.h"
#include "mounts.h"
#include "request.h"
#include "synchro.h"
#include "sessionmanager.h"
#include "db/db.h"
#include "functions/functions.h"
@ -61,6 +56,10 @@
#include "acceptencodingparser.h"
#include "space/jsontospaceparser.h"
#include "winixrequest.h"
#include "logger/logger.h"
#include "filelog.h"
namespace Winix
{
@ -76,6 +75,8 @@ public:
bool InitFCGI();
bool DropPrivileges();
void InitFileLog();
void InitPlugins();
bool Init();
void Start();
void Close();
@ -101,7 +102,7 @@ public:
// users sessions
SessionManager session_manager;
// database
// database (DEPRACATED)
Db db;
DbConn db_conn;
@ -129,6 +130,11 @@ public:
Templates templates;
FileLog file_log;
private:
enum Header
@ -162,6 +168,27 @@ private:
std::wstring http_header;
std::string http_header_8bit;
PT::Logger logger; // temporarily
morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector
morm::JSONConnector json_connector;
morm::PostgreSQLConnector postgresql_connector;
// objects for main thread
WinixBase winix_base;
WinixModel winix_model;
WinixSystem winix_system;
WinixRequest winix_request;
// ///////////////////////
Plugin plugin;
//////////////////////////
// log_buffer for the main thread
TextStream<std::wstring> log_buffer;
// logger only for App object
Log log;
bool InitFCGI(char * sock, char * sock_user, char * sock_group);
bool InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_group);

View File

@ -37,6 +37,8 @@
#include <pthread.h>
#include "synchro.h"
#include "winixmodel.h"
namespace Winix
@ -45,7 +47,7 @@ namespace Winix
class BaseThread
class BaseThread : public WinixModel
{
public:

View File

@ -38,6 +38,7 @@
#include <cstring>
#include <zlib.h>
#include "requesttypes.h"
#include "winixbase.h"
namespace Winix
@ -45,7 +46,7 @@ namespace Winix
class Compress
class Compress : public WinixBase
{
public:

View File

@ -34,7 +34,6 @@
#include "config.h"
#include "log.h"
#include "plugin.h"
#include "misc.h"
#include "crypt.h"
@ -50,9 +49,13 @@ Config::Config()
}
void Config::SetFileLog(FileLog * file_log)
{
log.SetFileLog(file_log);
//!! czy tu w ogole mozemy uzywac log << ?
//!! przeciez jeszcze nie zostal przetworzony plik konfiguracyjny
// the config is not read yet so we put some constants here
log.Init(3, false, 1);
}
void Config::ShowError()
@ -130,7 +133,6 @@ void Config::AssignValues(bool stdout_is_closed)
additional_groups = Bool(L"additional_groups", true);
log_file = Text(L"log_file");
log_notify_file = Text(L"log_notify_file");
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
fcgi_socket = Text(L"fcgi_socket");
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);

View File

@ -38,6 +38,9 @@
#include <string>
#include "space/spaceparser.h"
#include "htmlfilter.h"
#include "log.h"
#include "filelog.h"
namespace Winix
@ -80,8 +83,8 @@ public:
// default: true
bool additional_groups;
// log file name, log file name for notifications (sending emails, etc)
std::wstring log_file, log_notify_file;
// log file name
std::wstring log_file;
// the log level (how much info should be inserted to logs)
// 1 - minimum
@ -818,11 +821,13 @@ public:
// raw access to the config
PT::Space space;
void SetFileLog(FileLog * file_log);
private:
PT::SpaceParser parser;
bool errors_to_stdout;
Log log;
void ShowError();
void AssignValues(bool stdout_is_closed);

View File

@ -44,12 +44,18 @@ namespace Winix
void Crypt::SetConfig(Config * pconfig)
{
config = pconfig;
}
//void Crypt::SetConfig(Config * pconfig)
//{
// config = pconfig;
//}
void Crypt::set_dependency(WinixBase * winix_base)
{
WinixBase::set_dependency(winix_base);
run.set_dependency(winix_base);
}
char Crypt::ConvertToHexForm(int val)
{
@ -70,6 +76,7 @@ bool Crypt::HashBin(int hash, const char * in, size_t inlen, std::string & out)
return false;
run.Clear();
run.set_dependency(this);
PT::WideToUTF8(config->opensll_path, command);
run.Cmd(command);
run.Par("dgst");

View File

@ -39,6 +39,8 @@
#include "run.h"
#include "config.h"
#include "user.h"
#include "winixbase.h"
namespace Winix
@ -63,12 +65,15 @@ namespace Winix
/*
calculating hashes, encrypting and decrypting with RSA
*/
class Crypt
class Crypt : public WinixBase
{
public:
void SetConfig(Config * pconfig);
void set_dependency(WinixBase * winix_base);
//void SetConfig(Config * pconfig);
/*
@ -240,7 +245,7 @@ public:
private:
Config * config;
//Config * config;
Run run;
std::string command, bufina, keypatha;
//std::wstring pass_salted;//, pass_hashed;

View File

@ -38,6 +38,7 @@
#include <list>
#include <map>
#include "item.h"
#include "winixbase.h"
namespace Winix
@ -45,7 +46,7 @@ namespace Winix
class DirContainer
class DirContainer : public WinixBase
{
public:

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -34,7 +34,7 @@
#include "dirs.h"
#include "error.h"
#include "log.h"
#include "notify/notify.h"
namespace Winix

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -44,19 +44,21 @@
#include "dircontainer.h"
#include "db/db.h"
#include "request.h"
#include "notify/notify.h"
#include "winixmodel.h"
namespace Winix
{
class Notify;
// !! IMPROVE ME
// we do not support '..' in a path (for simplicity and security reasons)
// (we will support '..' in the future)
class Dirs
class Dirs : public WinixModel
{
public:

168
winixd/core/filelog.cpp Normal file
View File

@ -0,0 +1,168 @@
/*
* 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) 2008-2018, 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 "filelog.h"
#include <ctime>
#include <string.h>
#include "utf8/utf8.h"
#include "timezones.h"
namespace Winix
{
FileLog::FileLog()
{
log_stdout = false;
log_file_open = false;
time_zones = nullptr;
synchro = nullptr;
log_time_zone_id = 0;
}
FileLog::~FileLog()
{
}
void FileLog::set_synchro(Synchro * synchro)
{
this->synchro = synchro;
}
void FileLog::init(const std::wstring & log_file, bool log_stdout, size_t log_time_zone_id)
{
this->log_stdout = log_stdout;
this->log_time_zone_id = log_time_zone_id;
PT::WideToUTF8(log_file, this->log_file);
// don't open the file here
// because it would be created with the root as an owner
}
void FileLog::set_time_zones(TimeZones * time_zones)
{
this->time_zones = time_zones;
}
PT::Date FileLog::get_local_date(const PT::Date & date)
{
if( time_zones )
{
TimeZone * tz = time_zones->GetZone(log_time_zone_id);
if( tz )
{
PT::Date local_date = tz->ToLocal(date);
return local_date;
}
else
{
return date;
}
}
else
{
return date;
}
}
void FileLog::open_file()
{
if( !log_file.empty() )
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
log_file_open = true;
}
}
void FileLog::save_log(TextStream<std::wstring> * buffer)
{
if( buffer->Str().empty() )
return;
if( synchro )
{
synchro->Lock();
}
try
{
if( log_stdout )
PT::WideToUTF8(buffer->Str(), std::cout);
if( log_file.empty() )
return;
if( !log_file_open || !file )
{
file.close();
file.clear();
open_file();
if( !file )
return;
}
PT::WideToUTF8(buffer->Str(), file);
file.flush();
}
catch(...)
{
}
if( synchro )
{
synchro->Unlock();
}
}
} // namespace Winix

95
winixd/core/filelog.h Normal file
View File

@ -0,0 +1,95 @@
/*
* 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) 2018, 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_filelog
#define headerfile_winix_core_filelog
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
#include "textstream.h"
#include "core/synchro.h"
namespace Winix
{
class TimeZones;
class FileLog
{
public:
FileLog();
~FileLog();
void set_synchro(Synchro * synchro);
void init(const std::wstring & log_file, bool log_stdout, size_t log_time_zone_id);
void save_log(TextStream<std::wstring> * buffer);
void set_time_zones(TimeZones * time_zones);
PT::Date get_local_date(const PT::Date & date);
private:
// file log
std::string log_file;
std::ofstream file;
// logging to stdout
bool log_stdout;
// is the config file already open
bool log_file_open;
size_t log_time_zone_id;
TimeZones * time_zones;
Synchro * synchro;
void open_file();
};
} // namespace Winix
#endif

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -46,6 +46,13 @@ Groups::Groups()
}
void Groups::set_dependency(WinixModel * winix_model)
{
WinixModel::set_dependency(winix_model);
table.set_dependency(winix_model);
}
void Groups::Clear()
{
table.Clear();

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -40,6 +40,8 @@
#include "group.h"
#include "ugcontainer.h"
#include "db/db.h"
#include "winixmodel.h"
namespace Winix
@ -47,7 +49,7 @@ namespace Winix
class Groups
class Groups : public WinixModel
{
typedef UGContainer<Group> Table;
@ -55,6 +57,8 @@ Table table;
public:
void set_dependency(WinixModel * winix_model);
typedef Table::Iterator Iterator;
typedef Table::SizeType SizeType;

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,6 +36,7 @@
#define headerfile_winix_core_httpsimpleparser
#include <string>
#include "winixmodel.h"
namespace Winix
@ -43,7 +44,7 @@ namespace Winix
class HttpSimpleParser
class HttpSimpleParser : public WinixModel
{
protected:

View File

@ -35,9 +35,7 @@
#include <ctime>
#include "image.h"
#include "utf8/utf8.h"
#include "log.h"
#include "system.h"
#include "plugin.h"
#include "lock.h"
@ -492,34 +490,34 @@ void Image::ImageSavedCorrectly()
}
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
plugin.Call((Session*)0, WINIX_CREATED_THUMB, &file_work);
plugin->Call((Session*)0, WINIX_CREATED_THUMB, &file_work);
}
else
if( item_work.type == WINIX_IMAGE_TYPE_RESIZE )
{
log << log3 << "Image: image resized: " << dst_path << logend;
plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
plugin->Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
}
else
if( item_work.type == WINIX_IMAGE_TYPE_CROP )
{
log << log3 << "Image: image cropped: " << dst_path << logend;
// !! IMPROVE ME add a correct message
//plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
//plugin->Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
}
else
if( item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB )
{
log << log3 << "Image: image thumbnail cropped: " << dst_path << logend;
// !! IMPROVE ME add a correct message
//plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
//plugin->Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
}
else
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB )
{
log << log3 << "Image: a new thumbnail from an original image was cropped: " << dst_path << logend;
// !! IMPROVE ME add a correct message
//plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
//plugin->Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
}
}

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* Copyright (c) 2012-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,6 +37,8 @@
#include <vector>
#include "ipban.h"
#include "winixmodel.h"
namespace Winix
@ -44,7 +46,7 @@ namespace Winix
class IPBanContainer
class IPBanContainer : public WinixModel
{
public:

View File

@ -169,7 +169,7 @@ void Job::DoJob(PT::Space & job)
{
try
{
PluginRes res = plugin.Call((Session*)0, WINIX_JOB, &job);
PluginRes res = plugin->Call((Session*)0, WINIX_JOB, &job);
if( res.res_true == 0 )
DoWinixJob(job);

View File

@ -40,6 +40,7 @@
#include <cstring>
#include <ctime>
#include "date/date.h"
#include "winixbase.h"
@ -81,7 +82,7 @@ struct LastItem
class LastContainer
class LastContainer : public WinixBase
{
public:

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -34,7 +34,7 @@
#include "loadavg.h"
#include "log.h"
namespace Winix

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,6 +36,7 @@
#define headerfile_winix_core_loadavg
#include <ctime>
#include "winixbase.h"
namespace Winix
@ -51,7 +52,7 @@ namespace Winix
class LoadAvg
class LoadAvg : WinixBase
{
public:
LoadAvg();

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2018, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,7 +36,7 @@
#include <ctime>
#include <string.h>
#include "utf8/utf8.h"
#include "timezones.h"
namespace Winix
@ -52,8 +52,9 @@ Log::Log()
max_requests = 1;
lines = 0;
max_lines = 5000;
log_file_open = false;
time_zones = 0;
file_log = nullptr;
save_each_line = false;
buffer = nullptr;
}
@ -63,13 +64,30 @@ Log::~Log()
}
void Log::SetTimeZones(TimeZones * ptime_zones)
void Log::SetLogBuffer(TextStream<std::wstring> * buffer)
{
time_zones = ptime_zones;
this->buffer = buffer;
}
void Log::SetFileLog(FileLog * pfile_log)
{
this->file_log = pfile_log;
}
FileLog * Log::GetFileLog()
{
return file_log;
}
void Log::SetDependency(Log * log)
{
buffer = log->buffer;
file_log = log->file_log;
}
int Log::LogLevel()
{
@ -78,48 +96,24 @@ int Log::LogLevel()
void Log::Init(int log_level_, bool save_each_line_, const std::wstring & log_file_, bool log_std, int log_max_requests)
void Log::Init(int log_level, bool save_each_line, int max_requests)
{
log_level = log_level_;
log_stdout = log_std;
max_requests = log_max_requests;
save_each_line = save_each_line_;
PT::WideToUTF8(log_file_, log_file);
// don't open the file here
// because it would be created with the root as an owner
this->log_level = log_level;
this->save_each_line = save_each_line;
this->max_requests = max_requests;
}
void Log::OpenFile()
void Log::PrintDate(const PT::Date & date)
{
if( !log_file.empty() )
if( file_log )
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
log_file_open = true;
}
}
void Log::PrintDate(const PT::Date & date, size_t time_zone_id)
{
if( time_zones )
{
TimeZone * tz = time_zones->GetZone(time_zone_id);
if( tz )
{
PT::Date local_date = tz->ToLocal(date);
log << local_date;
}
else
{
(*this) << date << " UTC"; // unknown time zone identifier
}
(*this) << file_log->get_local_date(date);
}
else
{
(*this) << date << " UTC"; // time_zones object was not set
(*this) << date;
}
}
@ -127,10 +121,11 @@ void Log::PrintDate(const PT::Date & date, size_t time_zone_id)
Log & Log::operator<<(const void * s)
{
if( current_level > log_level )
return *this;
if( current_level <= log_level && buffer )
{
(*buffer) << s;
}
buffer << s;
return *this;
}
@ -138,13 +133,10 @@ Log & Log::operator<<(const void * s)
Log & Log::operator<<(const char * s)
{
if( current_level > log_level )
return *this;
if( !s )
return *this;
buffer << s;
if( current_level <= log_level && buffer && s )
{
(*buffer) << s;
}
return *this;
}
@ -153,10 +145,11 @@ return *this;
Log & Log::operator<<(const std::string & s)
{
if( current_level > log_level )
return *this;
if( current_level <= log_level && buffer )
{
(*buffer) << s;
}
buffer << s;
return *this;
}
@ -164,10 +157,11 @@ Log & Log::operator<<(const std::string & s)
Log & Log::operator<<(const std::string * s)
{
if( current_level > log_level )
return *this;
if( current_level <= log_level && buffer )
{
(*buffer) << *s;
}
buffer << *s;
return *this;
}
@ -178,10 +172,9 @@ Log & Log::operator<<(const std::string * s)
Log & Log::operator<<(const wchar_t * s)
{
if( current_level <= log_level )
if( current_level <= log_level && buffer && s )
{
if( s )
buffer << s;
(*buffer) << s;
}
return *this;
@ -191,9 +184,9 @@ return *this;
Log & Log::operator<<(const std::wstring & s)
{
if( current_level <= log_level )
if( current_level <= log_level && buffer )
{
buffer << s;
(*buffer) << s;
}
return *this;
@ -203,9 +196,9 @@ Log & Log::operator<<(const std::wstring & s)
Log & Log::operator<<(const std::wstring * s)
{
if( current_level <= log_level )
if( current_level <= log_level && buffer )
{
buffer << *s;
(*buffer) << *s;