Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f54df8d600 | |||
| d8451ceaa0 | |||
| 62f178c2ee | |||
| eb4e7343e7 | |||
| 5274e8e8ff | |||
| ae2a885d6c | |||
| 901663b145 | |||
| dc301d4c50 | |||
| 34f0535a26 | |||
| af0e2a778d | |||
| 904f1e70f2 | |||
| ddf7ef30ad | |||
| 0a43870e76 | |||
| f875bd2944 | |||
| c9bf20201b | |||
| 76314aab10 | |||
| 3547d326b8 | |||
| 0ecb2ac70e | |||
| 8f8defe0de | |||
| db5572e864 | |||
| 1100cf75d7 | |||
| 4fda06b547 | |||
| fb18b2238e | |||
| 5266a7e4e5 | |||
| 8196fb77d1 | |||
| 4abf6642f7 | |||
| e3284dcfbc | |||
| f064ff6b3d | |||
| bfa5d8cc05 | |||
| 6614919c13 | |||
| 8379acdb7f | |||
| 160ddc258d | |||
| 01892d2766 | |||
| 222955a2e7 | |||
| 37b22c3559 | |||
| afbd522362 | |||
| a4bed3ab14 |
30
Makefile
Executable file → Normal file
30
Makefile
Executable file → Normal file
@@ -3,16 +3,22 @@
|
||||
include Makefile.dep
|
||||
|
||||
|
||||
#ifndef CXX
|
||||
# temporarily workaround: forcing using clang (CXX is defined by the OS and is equal to g++)
|
||||
CXX = clang++
|
||||
#endif
|
||||
|
||||
ifndef CXXFLAGS
|
||||
CXXFLAGS = -Wall -O0 -g -fPIC -pthread -std=c++11 -I/usr/local/include -DEZC_USE_WINIX_LOGGER -DEZC_HAS_SPECIAL_STREAM
|
||||
ifeq ($(OSTYPE), FreeBSD)
|
||||
CXX = clang++
|
||||
else
|
||||
CXX = g++-4.8
|
||||
endif
|
||||
|
||||
|
||||
|
||||
ifndef CXXFLAGS
|
||||
CXXFLAGS = -Wall -O0 -g -fPIC -pthread -std=c++11 -I/usr/local/include -I/usr/include/postgresql -DEZC_USE_WINIX_LOGGER -DEZC_HAS_SPECIAL_STREAM
|
||||
endif
|
||||
|
||||
ifndef AR
|
||||
AR = ar
|
||||
endif
|
||||
|
||||
ifndef CXXWINIXINCLUDEFLAGS
|
||||
# these flags are used for compiling and making dependencies (make depend)
|
||||
# it's better to not using any system directories like -I/usr/local/include here
|
||||
@@ -51,7 +57,7 @@ winix.so: $(winix.src.files)
|
||||
@cd ../ezc/src ; $(MAKE) -e
|
||||
@cd ../tito/src ; $(MAKE) -e
|
||||
@cd ../pikotools ; $(MAKE) -e
|
||||
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a ../tito/src/tito.a ../pikotools/utf8/utf8.a ../pikotools/space/space.a ../pikotools/mainparser/mainparser.a ../pikotools/date/date.a $(LDFLAGS) -lfcgi -lpq -lz -lfetch -lpthread -lcurl -Wl,-no-whole-archive
|
||||
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a ../tito/src/tito.a ../pikotools/utf8/utf8.a ../pikotools/space/space.a ../pikotools/mainparser/mainparser.a ../pikotools/date/date.a $(LDFLAGS) -lfcgi -lpq -lz -lpthread -lcurl -Wl,-no-whole-archive
|
||||
|
||||
|
||||
winix: winix.so $(winix.src.files)
|
||||
@@ -131,19 +137,19 @@ install: all
|
||||
# etc configs
|
||||
rm -Rf $(winix_install_dir)/etc
|
||||
mkdir -p $(winix_install_dir)/etc
|
||||
cp -rf etc/ $(winix_install_dir)/etc/
|
||||
cp -rf etc/* $(winix_install_dir)/etc/
|
||||
# html templates
|
||||
rm -Rf $(winix_install_dir)/html
|
||||
mkdir -p $(winix_install_dir)/html
|
||||
cp -rf html/ $(winix_install_dir)/html/
|
||||
cp -rf html/* $(winix_install_dir)/html/
|
||||
# txt templates
|
||||
rm -Rf $(winix_install_dir)/txt
|
||||
mkdir -p $(winix_install_dir)/txt
|
||||
cp -rf txt/ $(winix_install_dir)/txt/
|
||||
cp -rf txt/* $(winix_install_dir)/txt/
|
||||
# locales
|
||||
rm -Rf $(winix_install_dir)/locale
|
||||
mkdir -p $(winix_install_dir)/locale
|
||||
cp -rf locale/ $(winix_install_dir)/locale/
|
||||
cp -rf locale/* $(winix_install_dir)/locale/
|
||||
# plugins
|
||||
rm -Rf $(winix_install_dir)/plugins
|
||||
mkdir -p $(winix_install_dir)/plugins
|
||||
|
||||
File diff suppressed because one or more lines are too long
0
core/Makefile
Executable file → Normal file
0
core/Makefile
Executable file → Normal file
682
core/Makefile.dep
Executable file → Normal file
682
core/Makefile.dep
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
2
core/Makefile.o.dep
Executable file → Normal file
2
core/Makefile.o.dep
Executable file → Normal 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 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 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
|
||||
|
||||
63
core/acceptbaseparser.cpp
Executable file → Normal file
63
core/acceptbaseparser.cpp
Executable file → Normal file
@@ -1,14 +1,41 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <wchar.h>
|
||||
#include "acceptbaseparser.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -33,28 +60,11 @@ void AcceptBaseParser::SkipWhite()
|
||||
}
|
||||
|
||||
|
||||
void AcceptBaseParser::RemoveWhiteFromEnd(std::string & str)
|
||||
{
|
||||
if( str.empty() )
|
||||
return;
|
||||
|
||||
size_t i = str.size() - 1;
|
||||
|
||||
for( ; i!=0 && IsWhite(str[i]) ; --i);
|
||||
|
||||
if( !IsWhite(str[i]) )
|
||||
++i;
|
||||
|
||||
if( i < str.size() )
|
||||
str.erase(i); // erasing until the end of the string
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AcceptBaseParser::ReadParameter()
|
||||
{
|
||||
param.clear();
|
||||
|
||||
SkipWhite();
|
||||
|
||||
while( *text!=0 && *text!=',' && *text!=';' )
|
||||
@@ -63,14 +73,13 @@ void AcceptBaseParser::ReadParameter()
|
||||
++text;
|
||||
}
|
||||
|
||||
RemoveWhiteFromEnd(param);
|
||||
TrimWhite(param);
|
||||
}
|
||||
|
||||
|
||||
void AcceptBaseParser::ReadQ()
|
||||
{
|
||||
q = 1.0;
|
||||
|
||||
SkipWhite();
|
||||
|
||||
if( *text != ';' )
|
||||
@@ -88,7 +97,7 @@ void AcceptBaseParser::ReadQ()
|
||||
++text; // skipping '='
|
||||
|
||||
SkipWhite();
|
||||
q = strtod(text, (char**)&text);
|
||||
q = wcstod(text, (wchar_t**)&text);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +111,7 @@ void AcceptBaseParser::SkipParam()
|
||||
|
||||
|
||||
|
||||
void AcceptBaseParser::Parse(const char * str)
|
||||
void AcceptBaseParser::Parse(const wchar_t * str)
|
||||
{
|
||||
text = str;
|
||||
Init();
|
||||
@@ -118,6 +127,12 @@ void AcceptBaseParser::Parse(const char * str)
|
||||
|
||||
|
||||
|
||||
void AcceptBaseParser::Parse(const std::wstring & str)
|
||||
{
|
||||
Parse(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
41
core/acceptbaseparser.h
Executable file → Normal file
41
core/acceptbaseparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_acceptbaseparser
|
||||
@@ -20,29 +45,29 @@ namespace Winix
|
||||
|
||||
|
||||
// sample (you must create your own class derived from this one):
|
||||
// object.Parse(" text/html ; , ; q = 45, application / xhtml+xml ; q = 0.4 , application/xml ; q = 0.9 , */* ; q = 0.8 ");
|
||||
// object.Parse(L" text/html ; , ; q = 45, application / xhtml+xml ; q = 0.4 , application/xml ; q = 0.9 , */* ; q = 0.8 ");
|
||||
class AcceptBaseParser
|
||||
{
|
||||
public:
|
||||
|
||||
void Parse(const char * str);
|
||||
void Parse(const wchar_t * str);
|
||||
void Parse(const std::wstring & str);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
virtual void Init() {} ;
|
||||
virtual void Param(const std::string & param, double q) = 0;
|
||||
virtual void Param(const std::wstring & param, double q) = 0;
|
||||
|
||||
bool IsWhite(int c);
|
||||
void SkipWhite();
|
||||
void RemoveWhiteFromEnd(std::string & str);
|
||||
void ReadParameter();
|
||||
void ReadQ();
|
||||
void SkipParam();
|
||||
|
||||
|
||||
const char * text;
|
||||
std::string param;
|
||||
const wchar_t * text;
|
||||
std::wstring param;
|
||||
double q;
|
||||
};
|
||||
|
||||
|
||||
43
core/acceptencodingparser.h
Executable file → Normal file
43
core/acceptencodingparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_acceptencodingparser
|
||||
@@ -35,7 +60,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void ParseAndLog(const char * str)
|
||||
void ParseAndLog(const wchar_t * str)
|
||||
{
|
||||
Parse(str);
|
||||
|
||||
@@ -59,6 +84,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void ParseAndLog(const std::wstring & str)
|
||||
{
|
||||
ParseAndLog(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void Init()
|
||||
@@ -68,14 +99,14 @@ private:
|
||||
}
|
||||
|
||||
|
||||
void Param(const std::string & param, double q)
|
||||
void Param(const std::wstring & param, double q)
|
||||
{
|
||||
if( param=="deflate" && q!=0.0 )
|
||||
if( param == L"deflate" && q!=0.0 )
|
||||
{
|
||||
accept_deflate = true;
|
||||
}
|
||||
|
||||
if( param=="gzip" && q!=0.0 )
|
||||
if( param == L"gzip" && q!=0.0 )
|
||||
{
|
||||
accept_gzip = true;
|
||||
}
|
||||
|
||||
456
core/app.cpp
Executable file → Normal file
456
core/app.cpp
Executable file → Normal file
@@ -1,13 +1,40 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2015, 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 <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <unistd.h>
|
||||
@@ -15,7 +42,8 @@
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <utility>
|
||||
#include <curl/curl.h>
|
||||
#include <fastcgi.h>
|
||||
#include <stddef.h>
|
||||
#include "app.h"
|
||||
#include "plugin.h"
|
||||
#include "misc.h"
|
||||
@@ -89,12 +117,70 @@ App::App()
|
||||
|
||||
|
||||
|
||||
bool App::InitFCGI(char * sock, char * sock_user, char * sock_group)
|
||||
{
|
||||
if( !WideToUTF8(config.fcgi_socket, sock, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
if( !WideToUTF8(config.fcgi_socket_user, sock_user, WINIX_OS_USERNAME_SIZE) )
|
||||
return false;
|
||||
|
||||
if( !WideToUTF8(config.fcgi_socket_group, sock_group, WINIX_OS_USERNAME_SIZE) )
|
||||
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)
|
||||
{
|
||||
if( chmod(sock, config.fcgi_socket_chmod) < 0 )
|
||||
{
|
||||
log << log1 << "App: I cannot chmod a FastCGI socket, check fcgi_socket_chmod in the config" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
passwd * pw = getpwnam(sock_user);
|
||||
|
||||
if( !pw )
|
||||
{
|
||||
log << log1 << "App: there is no a user: " << config.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
group * gr = getgrnam(sock_group);
|
||||
|
||||
if( !gr )
|
||||
{
|
||||
log << log1 << "App: there is no a group: " << config.fcgi_socket_group << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( chown(sock, pw->pw_uid, gr->gr_gid) < 0 )
|
||||
{
|
||||
log << log1 << "App: I cannot chown a FastCGI socket, check fcgi_socket_user "
|
||||
<< "and fcgi_socket_group in the config" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool App::InitFCGI()
|
||||
{
|
||||
const char * sock = config.fcgi_socket.c_str();
|
||||
unlink(sock);
|
||||
char sock[WINIX_OS_PATH_SIZE];
|
||||
char sock_user[WINIX_OS_USERNAME_SIZE];
|
||||
char sock_group[WINIX_OS_USERNAME_SIZE];
|
||||
|
||||
fcgi_socket = FCGX_OpenSocket(sock, 100); // !! dodac 100 do konfiga
|
||||
if( !InitFCGI(sock, sock_user, sock_group) )
|
||||
return false;
|
||||
|
||||
unlink(sock);
|
||||
fcgi_socket = FCGX_OpenSocket(sock, config.fcgi_socket_listen);
|
||||
|
||||
if( fcgi_socket < 0 )
|
||||
{
|
||||
@@ -103,25 +189,9 @@ bool App::InitFCGI()
|
||||
}
|
||||
|
||||
log << log3 << "App: FastCGI socket number: " << fcgi_socket << logend;
|
||||
chmod(sock, config.fcgi_socket_chmod);
|
||||
|
||||
passwd * pw = getpwnam(config.fcgi_socket_user.c_str());
|
||||
|
||||
if( !pw )
|
||||
{
|
||||
log << log1 << "App: there is no user: " << config.fcgi_socket_user << logend;
|
||||
if( !InitFCGIChmodChownSocket(sock, sock_user, sock_group) )
|
||||
return false;
|
||||
}
|
||||
|
||||
group * gr = getgrnam(config.fcgi_socket_group.c_str());
|
||||
|
||||
if( !gr )
|
||||
{
|
||||
log << log1 << "App: there is no group: " << config.fcgi_socket_group << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
chown(sock, pw->pw_uid, gr->gr_gid);
|
||||
|
||||
if( FCGX_Init() != 0 )
|
||||
{
|
||||
@@ -154,18 +224,17 @@ bool App::Init()
|
||||
|
||||
// init notify after templates (it uses locales from templates)
|
||||
system.notify.ReadTemplates();
|
||||
session_manager.InitBanList();
|
||||
|
||||
session_manager.InitTmpSession();
|
||||
session_manager.InitBanList();
|
||||
session_manager.InitCookieEncoding();
|
||||
session_manager.LoadSessions();
|
||||
|
||||
CreateStaticTree();
|
||||
|
||||
post_parser.UTF8(config.utf8);
|
||||
post_parser.LogValueSize(config.log_post_value_size);
|
||||
// post_multi_parser has a pointer to the config
|
||||
|
||||
cookie_parser.UTF8(config.utf8);
|
||||
|
||||
plugin.Call((Session*)0, WINIX_PLUGIN_INIT);
|
||||
|
||||
return true;
|
||||
@@ -193,7 +262,7 @@ void App::BaseUrlRedirect(int code, bool add_subdomain)
|
||||
}
|
||||
|
||||
cur.request->redirect_to += config.base_url;
|
||||
AssignString(cur.request->env_request_uri, cur.request->redirect_to, false);
|
||||
cur.request->redirect_to += cur.request->env_request_uri;
|
||||
// cur.request->env_request_uri should not be UrlEncoded because it contains slashes
|
||||
cur.request->redirect_type = code;
|
||||
}
|
||||
@@ -216,7 +285,7 @@ bool App::BaseUrlRedirect()
|
||||
if( cur.request->method == Request::post )
|
||||
return false;
|
||||
|
||||
if( Equal(config.base_url.c_str(), cur.request->env_http_host) )
|
||||
if( config.base_url == cur.request->env_http_host )
|
||||
return false;
|
||||
|
||||
BaseUrlRedirect(config.base_url_redirect_code, false);
|
||||
@@ -239,11 +308,33 @@ void App::CheckIfNeedSSLredirect()
|
||||
|
||||
if( config.use_ssl )
|
||||
{
|
||||
if( !cur.request->using_ssl )
|
||||
if( config.use_ssl_only_for_logged_users )
|
||||
{
|
||||
if( !config.use_ssl_only_for_logged_users ||
|
||||
cur.session->puser ||
|
||||
(cur.request->function && cur.request->function->need_ssl) )
|
||||
bool function_need_ssl = (cur.request->function && cur.request->function->need_ssl);
|
||||
|
||||
if( cur.request->using_ssl )
|
||||
{
|
||||
if( !cur.session->puser && !function_need_ssl )
|
||||
{
|
||||
log << log3 << "App: this operation should NOT be used through SSL" << logend;
|
||||
BaseUrlRedirect(config.use_ssl_redirect_code, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( cur.session->puser || function_need_ssl )
|
||||
{
|
||||
log << log3 << "App: this operation should be used through SSL" << logend;
|
||||
BaseUrlRedirect(config.use_ssl_redirect_code, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* use ssl for everyone
|
||||
*/
|
||||
if( !cur.request->using_ssl )
|
||||
{
|
||||
log << log3 << "App: this operation should be used through SSL" << logend;
|
||||
BaseUrlRedirect(config.use_ssl_redirect_code, true);
|
||||
@@ -320,7 +411,28 @@ void App::ProcessRequestThrow()
|
||||
}
|
||||
|
||||
plugin.Call(WINIX_SESSION_CHANGED);
|
||||
functions.Parse(); // parsing directories,files,functions and parameters
|
||||
|
||||
if( cur.request->env_request_uri.size() <= WINIX_URL_MAX_SIZE )
|
||||
{
|
||||
functions.Parse(); // parsing directories, files, functions and parameters
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* IMPROVE ME
|
||||
* it will not have the root directory set
|
||||
* so as a response only a blank page is shown
|
||||
* (root directory is set in funcions.Parse())
|
||||
*
|
||||
* IMPROVE ME
|
||||
* we can add a better return code (http status):
|
||||
* http://www.ietf.org/rfc/rfc2616.txt
|
||||
* "A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle"
|
||||
*
|
||||
*/
|
||||
cur.request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
log << log1 << "App: the URL is too long: " << cur.request->env_request_uri.size() << logend;
|
||||
}
|
||||
|
||||
cur.mount = system.mounts.CalcCurMount();
|
||||
|
||||
@@ -475,7 +587,7 @@ void App::CreateJSONAnswer()
|
||||
}
|
||||
|
||||
|
||||
// !! zmienic na lepsza nazwe
|
||||
// !! IMPROVE ME change to a better name
|
||||
void App::MakePage()
|
||||
{
|
||||
bool sent = false;
|
||||
@@ -492,7 +604,8 @@ bool sent = false;
|
||||
{
|
||||
if( cur.request->function == &functions.fun_cat )
|
||||
{
|
||||
cur.request->out_streams[0] << cur.request->item.content; // !! CHECK ME is it ok?
|
||||
TemplatesFunctions::item_print_content(cur.request->out_streams[0],
|
||||
cur.request->item.content, cur.request->item.content_type);
|
||||
sent = true;
|
||||
}
|
||||
else
|
||||
@@ -529,9 +642,9 @@ void App::CheckPostRedirect()
|
||||
}
|
||||
|
||||
|
||||
// zmienic nazwe np na ProcessRequest
|
||||
// !! ta nazwa chyba juz zajeta...
|
||||
// !! IMPROVE ME need some refactoring
|
||||
// !! IMPROVE ME change to a better name
|
||||
// may ProcessRequest()? but probably it is already defined...
|
||||
// this method needs some refactoring
|
||||
void App::Make()
|
||||
{
|
||||
if( cur.request->dir_tab.empty() )
|
||||
@@ -546,8 +659,6 @@ void App::Make()
|
||||
if( cur.session->ip_ban && cur.session->ip_ban->IsIPBanned() )
|
||||
{
|
||||
PT::Date date(cur.session->ip_ban->expires);
|
||||
|
||||
log << log2 << "App: this IP address is banned until to: " << date << " UTC" << logend;
|
||||
slog << logerror << T("this_ip_is_banned_until") << ' ' << date << " UTC" << logend;
|
||||
|
||||
cur.request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
@@ -611,17 +722,21 @@ void App::LogEnvironmentVariables()
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* reading the request (without GET parameters in the URL)
|
||||
*/
|
||||
void App::ReadRequest()
|
||||
{
|
||||
ReadEnvVariables();
|
||||
ReadEnvRemoteIP();
|
||||
CheckRequestMethod();
|
||||
CheckSSL();
|
||||
SetSubdomain();
|
||||
|
||||
LogAccess();
|
||||
|
||||
ReadGetPostVars();
|
||||
ReadPostVars();
|
||||
|
||||
cookie_parser.Parse(cur.request->env_http_cookie, cur.request->cookie_tab);
|
||||
accept_encoding_parser.ParseAndLog(cur.request->env_http_accept_encoding);
|
||||
|
||||
@@ -637,51 +752,63 @@ void App::ReadRequest()
|
||||
|
||||
|
||||
|
||||
void App::SetEnv(const char * & env, const char * name)
|
||||
void App::SetEnv(const char * name, std::wstring & env)
|
||||
{
|
||||
const char * v = FCGX_GetParam(name, fcgi_request.envp);
|
||||
const char * v = FCGX_GetParam(name, fcgi_request.envp);
|
||||
|
||||
if( v )
|
||||
env = v;
|
||||
|
||||
// by default env is set to an empty string (in cur.request->Clear() method)
|
||||
{
|
||||
PT::UTF8ToWide(v, env);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void App::ReadEnvVariables()
|
||||
{
|
||||
// we store that values because FCGX_GetParam has O(n) complexity
|
||||
// with this variables (env_*) we have O(1)
|
||||
|
||||
SetEnv(cur.request->env_request_method, "REQUEST_METHOD"); // !! mozna nie uzywac tego, teraz mamy w strukturze fcgi_request
|
||||
SetEnv(cur.request->env_request_uri, "REQUEST_URI");
|
||||
SetEnv(cur.request->env_http_cookie, "HTTP_COOKIE");
|
||||
SetEnv(cur.request->env_remote_addr, "REMOTE_ADDR");
|
||||
SetEnv(cur.request->env_http_host, "HTTP_HOST");
|
||||
SetEnv(cur.request->env_http_user_agent, "HTTP_USER_AGENT");
|
||||
SetEnv(cur.request->env_fcgi_role, "FCGI_ROLE");
|
||||
SetEnv(cur.request->env_content_type, "CONTENT_TYPE");
|
||||
SetEnv(cur.request->env_http_accept_encoding, "HTTP_ACCEPT_ENCODING");
|
||||
SetEnv(cur.request->env_https, "HTTPS");
|
||||
|
||||
cur.request->ip = (int)inet_addr(cur.request->env_remote_addr);
|
||||
SetEnv("REQUEST_METHOD", cur.request->env_request_method);
|
||||
SetEnv("REQUEST_URI", cur.request->env_request_uri);
|
||||
SetEnv("HTTP_COOKIE", cur.request->env_http_cookie);
|
||||
SetEnv("REMOTE_ADDR", cur.request->env_remote_addr);
|
||||
SetEnv("HTTP_HOST", cur.request->env_http_host);
|
||||
SetEnv("HTTP_USER_AGENT", cur.request->env_http_user_agent);
|
||||
SetEnv("FCGI_ROLE", cur.request->env_fcgi_role);
|
||||
SetEnv("CONTENT_TYPE", cur.request->env_content_type);
|
||||
SetEnv("HTTP_ACCEPT_ENCODING", cur.request->env_http_accept_encoding);
|
||||
SetEnv("HTTPS", cur.request->env_https);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void App::ReadEnvRemoteIP()
|
||||
{
|
||||
const char * v = FCGX_GetParam("REMOTE_ADDR", fcgi_request.envp);
|
||||
|
||||
if( v )
|
||||
{
|
||||
cur.request->ip = (int)inet_addr(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void App::CheckRequestMethod()
|
||||
{
|
||||
cur.request->method = Request::unknown_method;
|
||||
|
||||
if( ToSmall(cur.request->env_request_method[0]) == 'g' )
|
||||
cur.request->method = Request::get;
|
||||
else
|
||||
if( ToSmall(cur.request->env_request_method[0]) == 'p' )
|
||||
cur.request->method = Request::post;
|
||||
else
|
||||
if( ToSmall(cur.request->env_request_method[0]) == 'h' )
|
||||
cur.request->method = Request::head;
|
||||
|
||||
if( !cur.request->env_request_method.empty() )
|
||||
{
|
||||
if( ToSmall(cur.request->env_request_method[0]) == 'g' )
|
||||
cur.request->method = Request::get;
|
||||
else
|
||||
if( ToSmall(cur.request->env_request_method[0]) == 'p' )
|
||||
cur.request->method = Request::post;
|
||||
else
|
||||
if( ToSmall(cur.request->env_request_method[0]) == 'h' )
|
||||
cur.request->method = Request::head;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -692,14 +819,14 @@ void App::CheckSSL()
|
||||
// value "on" exists in lighttpd server
|
||||
// make sure that for other servers is "on" too
|
||||
|
||||
if( EqualNoCase(cur.request->env_https, "on") )
|
||||
if( EqualNoCase(cur.request->env_https.c_str(), L"on") )
|
||||
cur.request->using_ssl = true;
|
||||
}
|
||||
|
||||
|
||||
void App::SetSubdomain()
|
||||
{
|
||||
CreateSubdomain(config.base_url.c_str(), cur.request->env_http_host, cur.request->subdomain);
|
||||
CreateSubdomain(config.base_url.c_str(), cur.request->env_http_host.c_str(), cur.request->subdomain);
|
||||
}
|
||||
|
||||
|
||||
@@ -721,15 +848,11 @@ void App::LogAccess()
|
||||
|
||||
|
||||
|
||||
|
||||
void App::ReadGetPostVars()
|
||||
void App::ReadPostVars()
|
||||
{
|
||||
// get parameters we have always
|
||||
//get_parser.Parse(cur.request->env_request_uri, cur.request->get_tab);
|
||||
|
||||
if( cur.request->method == Request::post )
|
||||
{
|
||||
if( IsSubStringNoCase("multipart/form-data", cur.request->env_content_type) )
|
||||
if( IsSubStringNoCase(L"multipart/form-data", cur.request->env_content_type.c_str()) )
|
||||
{
|
||||
log << log3 << "App: post content type: multipart/form-data" << logend;
|
||||
post_multi_parser.Parse(fcgi_request.in, cur.request->post_tab, cur.request->post_file_tab);
|
||||
@@ -746,49 +869,51 @@ void App::ReadGetPostVars()
|
||||
|
||||
void App::CheckIE()
|
||||
{
|
||||
char * msie = strstr(cur.request->env_http_user_agent, "MSIE");
|
||||
|
||||
if( msie )
|
||||
cur.request->browser_msie = true;
|
||||
else
|
||||
cur.request->browser_msie = false;
|
||||
size_t msie = cur.request->env_http_user_agent.find(L"MSIE");
|
||||
cur.request->browser_msie = (msie != std::wstring::npos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void App::CheckKonqueror()
|
||||
{
|
||||
char * kon = strstr(cur.request->env_http_user_agent, "Konqueror");
|
||||
|
||||
if( kon )
|
||||
cur.request->browser_konqueror = true;
|
||||
else
|
||||
cur.request->browser_konqueror = false;
|
||||
size_t kon = cur.request->env_http_user_agent.find(L"Konqueror");
|
||||
cur.request->browser_konqueror = (kon != std::wstring::npos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void App::PrepareSessionCookie()
|
||||
{
|
||||
if( !cur.session || cur.session->id==0 )
|
||||
return;
|
||||
|
||||
if( config.session_cookie_encode )
|
||||
{
|
||||
if( !session_manager.EncodeSessionId(cur.session->id, cur.session->id_index, cookie_id_string) )
|
||||
Toa(cur.session->id, cookie_id_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
Toa(cur.session->id, cookie_id_string);
|
||||
}
|
||||
|
||||
|
||||
if( !cur.session->puser || !cur.session->remember_me )
|
||||
{
|
||||
cur.request->AddCookie(config.http_session_id_name, cur.session->id);
|
||||
cur.request->AddCookie(config.http_session_id_name, cookie_id_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
PT::Date expires = cur.request->start_time + config.session_remember_max_idle;
|
||||
cur.request->AddCookie(config.http_session_id_name, cur.session->id, expires);
|
||||
cur.request->AddCookie(config.http_session_id_name, cookie_id_string, expires);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::AddHeader(const wchar_t * name, const wchar_t * value)
|
||||
{
|
||||
if( !cur.request->out_headers.GetValue(name) )
|
||||
@@ -849,7 +974,7 @@ bool App::PrepareHeadersStaticCreateResource(PT::WTextStream & out_path)
|
||||
}
|
||||
|
||||
size_t how_many_dirs = system.dirs.DirLevel(dir->id);
|
||||
const char * path = SkipDirs(cur.request->env_request_uri, how_many_dirs);
|
||||
const wchar_t * path = SkipDirs(cur.request->env_request_uri.c_str(), how_many_dirs);
|
||||
|
||||
// the path begins with a slash only if how_many_dirs is zero
|
||||
while( *path == '/' )
|
||||
@@ -928,7 +1053,7 @@ void App::PrepareHeaderContentType()
|
||||
}
|
||||
}
|
||||
|
||||
if( value && config.utf8 )
|
||||
if( value )
|
||||
*value += L"; charset=UTF-8";
|
||||
}
|
||||
}
|
||||
@@ -1040,11 +1165,19 @@ void App::SendHeaders()
|
||||
FCGX_PutS("\r\n", fcgi_request.out);
|
||||
|
||||
if( config.log_http_answer_headers )
|
||||
log << "HTTP Header: " << aheader_name << ": " << aheader_value << logend;
|
||||
log << log1 << "HTTP Header: " << aheader_name << ": " << aheader_value << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class RawType>
|
||||
DbTextStream::RawText<RawType> R(const RawType & par)
|
||||
{
|
||||
return DbTextStream::RawText<RawType>(par);
|
||||
}
|
||||
|
||||
|
||||
void App::SendCookies()
|
||||
{
|
||||
PT::Space::TableSingle::iterator i;
|
||||
@@ -1064,7 +1197,7 @@ void App::SendCookies()
|
||||
FCGX_PutS("\r\n", fcgi_request.out);
|
||||
|
||||
if( config.log_http_answer_headers )
|
||||
log << "HTTP Header: " << "Set-Cookie: " << aheader_name << "=" << aheader_value << logend;
|
||||
log << log1 << "HTTP Header: Set-Cookie: " << aheader_name << "=" << aheader_value << logend;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1270,10 +1403,7 @@ size_t output_size = 0;
|
||||
|
||||
SelectCompression(source->length(), compressing, compress_encoding);
|
||||
|
||||
if( config.utf8 )
|
||||
PT::WideToUTF8(*source, output_8bit);
|
||||
else
|
||||
AssignString(*source, output_8bit);
|
||||
PT::WideToUTF8(*source, output_8bit);
|
||||
|
||||
// !! IMPROVE ME add to log the binary stream as well
|
||||
if( config.log_server_answer )
|
||||
@@ -1499,13 +1629,27 @@ void App::LogUserGroups()
|
||||
|
||||
|
||||
|
||||
bool App::DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool additional_groups)
|
||||
|
||||
bool App::DropPrivileges(char * user, char * group)
|
||||
{
|
||||
if( !WideToUTF8(config.user, user, WINIX_OS_USERNAME_SIZE) )
|
||||
return false;
|
||||
|
||||
if( !WideToUTF8(config.group, group, WINIX_OS_USERNAME_SIZE) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::DropPrivileges(const char * user, uid_t uid, gid_t gid, bool additional_groups)
|
||||
{
|
||||
if( additional_groups )
|
||||
{
|
||||
if( initgroups(user.c_str(), gid) < 0 )
|
||||
if( initgroups(user, gid) < 0 )
|
||||
{
|
||||
log << log1 << "App: I can't init groups for user: " << user << logend;
|
||||
log << log1 << "App: I can't init groups for a user: " << user << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1519,7 +1663,7 @@ bool App::DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool ad
|
||||
}
|
||||
|
||||
// for setting real and saved gid too
|
||||
if( setgid(gid) )
|
||||
if( setgid(gid) < 0 )
|
||||
{
|
||||
log << log1 << "App: I can't change real and saved gid" << logend;
|
||||
return false;
|
||||
@@ -1542,8 +1686,12 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::DropPrivileges()
|
||||
{
|
||||
char user_name[WINIX_OS_USERNAME_SIZE];
|
||||
char group_name[WINIX_OS_USERNAME_SIZE];
|
||||
|
||||
if( getuid()!=0 && geteuid()!=0 )
|
||||
return true;
|
||||
|
||||
@@ -1551,20 +1699,23 @@ bool App::DropPrivileges()
|
||||
|
||||
if( config.user.empty() )
|
||||
{
|
||||
log << log1 << "App: you should specify user name in the config file "
|
||||
log << log1 << "App: in the config file you should specify a user name and a group "
|
||||
<< "to which I have to drop privileges" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( config.group.empty() )
|
||||
{
|
||||
log << log1 << "App: you should specify group name in the config file "
|
||||
log << log1 << "App: you should specify a group name in the config file "
|
||||
<< "to which I have to drop privileges" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
passwd * p = getpwnam(config.user.c_str());
|
||||
group * g = getgrnam(config.group.c_str());
|
||||
if( !DropPrivileges(user_name, group_name) )
|
||||
return false;
|
||||
|
||||
passwd * p = getpwnam(user_name);
|
||||
group * g = getgrnam(group_name);
|
||||
|
||||
if( !p )
|
||||
{
|
||||
@@ -1578,7 +1729,7 @@ bool App::DropPrivileges()
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !DropPrivileges(config.user, p->pw_uid, g->gr_gid, config.additional_groups) )
|
||||
if( !DropPrivileges(user_name, p->pw_uid, g->gr_gid, config.additional_groups) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -1648,30 +1799,73 @@ void App::WaitForThreads()
|
||||
|
||||
|
||||
|
||||
void App::FetchPageOnExit()
|
||||
|
||||
|
||||
/*
|
||||
we send a one FastCGI record at the end when winix closes (to wake up the main thread)
|
||||
this method is called from the special thread
|
||||
|
||||
typedef struct {
|
||||
unsigned char version;
|
||||
unsigned char type;
|
||||
unsigned char requestIdB1;
|
||||
unsigned char requestIdB0;
|
||||
unsigned char contentLengthB1;
|
||||
unsigned char contentLengthB0;
|
||||
unsigned char paddingLength;
|
||||
unsigned char reserved;
|
||||
unsigned char contentData[contentLength];
|
||||
unsigned char paddingData[paddingLength];
|
||||
} FCGI_Record;
|
||||
*/
|
||||
void App::SendEmptyFastCGIPacket()
|
||||
{
|
||||
// stupid trick to break FCGX_Accept_r() function
|
||||
// even with FCGX_InitRequest(..., ..., FCGI_FAIL_ACCEPT_ON_INTR) the FCGX_Accept_r
|
||||
// doesn't want to break on a signal
|
||||
// so we request one page from the server for exiting from FCGX_Accept_r
|
||||
std::string msg;
|
||||
sockaddr_un to;
|
||||
int res;
|
||||
|
||||
Lock();
|
||||
CURL * curl = curl_easy_init();
|
||||
Unlock();
|
||||
int s = socket(PF_LOCAL, SOCK_STREAM, 0);
|
||||
|
||||
if( curl )
|
||||
if( s < 0 )
|
||||
return;
|
||||
|
||||
memset(&to, 0, sizeof(to));
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
to.sun_len = offsetof(sockaddr_un, sun_path)
|
||||
+ socket_to_send_on_exit.size()
|
||||
+ 1; // terminating zero
|
||||
#endif
|
||||
|
||||
to.sun_family = AF_UNIX;
|
||||
snprintf(to.sun_path, sizeof(to.sun_path)/sizeof(char), "%s", socket_to_send_on_exit.c_str());
|
||||
|
||||
// actually we can send one byte only
|
||||
msg += FCGI_VERSION_1;
|
||||
msg += FCGI_GET_VALUES;
|
||||
msg += (char)0; // requestid
|
||||
msg += (char)0;
|
||||
msg += (char)0; // contentlength
|
||||
msg += (char)0;
|
||||
msg += (char)0; // padding length
|
||||
msg += (char)0;
|
||||
msg += (char)0; // reserved
|
||||
|
||||
res = connect(s, (sockaddr*)&to, sizeof(to));
|
||||
|
||||
if( res == 0 )
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url_to_fetch_on_exit.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
|
||||
curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
send(s, msg.c_str(), msg.size(), 0);
|
||||
}
|
||||
|
||||
close(s);
|
||||
}
|
||||
|
||||
|
||||
void * App::SpecialThreadForSignals(void * app_object)
|
||||
{
|
||||
sigset_t set;
|
||||
int sig;
|
||||
|
||||
App * app = reinterpret_cast<App*>(app_object);
|
||||
|
||||
@@ -1680,18 +1874,16 @@ sigset_t set;
|
||||
sigaddset(&set, SIGINT);
|
||||
|
||||
// waiting for SIGTERM or SIGINT
|
||||
sigwait(&set, 0);
|
||||
sigwait(&set, &sig);
|
||||
|
||||
app->Lock();
|
||||
app->synchro.was_stop_signal = true;
|
||||
FCGX_ShutdownPending();
|
||||
|
||||
// here we don't have to use SSL version so we always use config.url_proto
|
||||
PT::WideToUTF8(app->config.url_proto, app->url_to_fetch_on_exit);
|
||||
PT::WideToUTF8(app->config.base_url, app->url_to_fetch_on_exit, false);
|
||||
PT::WideToUTF8(app->config.fcgi_socket, app->socket_to_send_on_exit);
|
||||
app->Unlock();
|
||||
|
||||
app->FetchPageOnExit();
|
||||
app->SendEmptyFastCGIPacket();
|
||||
|
||||
pthread_exit(0);
|
||||
return 0;
|
||||
|
||||
44
core/app.h
Executable file → Normal file
44
core/app.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_app
|
||||
@@ -122,7 +147,7 @@ private:
|
||||
int fcgi_socket;
|
||||
Synchro synchro;
|
||||
pthread_t signal_thread;
|
||||
std::string url_to_fetch_on_exit;
|
||||
std::string socket_to_send_on_exit;
|
||||
std::string send_data_buf;
|
||||
PT::SpaceToJSON json_generic_serializer;
|
||||
TextStream<std::wstring> json_out_stream;
|
||||
@@ -130,7 +155,12 @@ private:
|
||||
std::wstring html_filtered;
|
||||
std::string output_8bit;
|
||||
BinaryPage compressed_output;
|
||||
std::wstring cookie_id_string;
|
||||
|
||||
bool InitFCGI(char * sock, char * sock_user, char * sock_group);
|
||||
bool InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_group);
|
||||
bool DropPrivileges(char * user, char * group);
|
||||
bool DropPrivileges(const char * user, uid_t uid, gid_t gid, bool additional_groups);
|
||||
bool CheckAccessFromPlugins();
|
||||
void ProcessRequestThrow();
|
||||
void ProcessRequest();
|
||||
@@ -153,9 +183,10 @@ private:
|
||||
|
||||
void LogEnvironmentVariables();
|
||||
|
||||
void SetEnv(const char * & env, const char * name);
|
||||
void SetEnv(const char * name, std::wstring & env);
|
||||
void ReadEnvVariables();
|
||||
void ReadGetPostVars();
|
||||
void ReadEnvRemoteIP();
|
||||
void ReadPostVars();
|
||||
|
||||
void CheckIE();
|
||||
void CheckKonqueror();
|
||||
@@ -192,10 +223,9 @@ private:
|
||||
void LogUsers();
|
||||
void LogEffectiveGroups(std::vector<gid_t> & tab);
|
||||
void LogGroups();
|
||||
bool DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool additional_groups);
|
||||
|
||||
static void * SpecialThreadForSignals(void*);
|
||||
void FetchPageOnExit();
|
||||
void SendEmptyFastCGIPacket();
|
||||
|
||||
void CreateStaticTree();
|
||||
|
||||
|
||||
29
core/basethread.cpp
Executable file → Normal file
29
core/basethread.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
29
core/basethread.h
Executable file → Normal file
29
core/basethread.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_basethread
|
||||
|
||||
29
core/bbcodeparser.cpp
Executable file → Normal file
29
core/bbcodeparser.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bbcodeparser.h"
|
||||
|
||||
29
core/bbcodeparser.h
Executable file → Normal file
29
core/bbcodeparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_bbcodeparser
|
||||
|
||||
29
core/compress.cpp
Executable file → Normal file
29
core/compress.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "compress.h"
|
||||
|
||||
29
core/compress.h
Executable file → Normal file
29
core/compress.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_compress
|
||||
|
||||
108
core/config.cpp
Executable file → Normal file
108
core/config.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, 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 "config.h"
|
||||
@@ -45,14 +70,14 @@ void Config::ShowError()
|
||||
|
||||
case PT::SpaceParser::cant_open_file:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: cant open a config file: " << config_file << std::endl;
|
||||
std::wcout << L"Config: I cannot open a config file: " << config_file << std::endl;
|
||||
|
||||
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
||||
break;
|
||||
|
||||
case PT::SpaceParser::syntax_error:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: syntax error, line: " << parser.line << std::endl;
|
||||
std::wcout << "Config: syntax error, line: " << parser.line << std::endl;
|
||||
|
||||
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
||||
break;
|
||||
@@ -77,7 +102,6 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
|
||||
parser.SplitSingle(true);
|
||||
parser.UTF8(true); // config is always read in UTF-8
|
||||
parser.SetSpace(space);
|
||||
|
||||
PT::SpaceParser::Status status = parser.Parse(config_file);
|
||||
@@ -100,19 +124,21 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
|
||||
void Config::AssignValues(bool stdout_is_closed)
|
||||
{
|
||||
server_mode = Text(L"server_mode");
|
||||
demonize = Bool(L"demonize", true);
|
||||
|
||||
user = AText(L"user");
|
||||
group = AText(L"group");
|
||||
user = Text(L"user");
|
||||
group = Text(L"group");
|
||||
additional_groups = Bool(L"additional_groups", true);
|
||||
|
||||
log_file = AText(L"log_file");
|
||||
log_notify_file = AText(L"log_notify_file");
|
||||
log_file = Text(L"log_file");
|
||||
log_notify_file = Text(L"log_notify_file");
|
||||
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
|
||||
fcgi_socket = AText(L"fcgi_socket");
|
||||
fcgi_socket = Text(L"fcgi_socket");
|
||||
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
|
||||
fcgi_socket_user = AText(L"fcgi_socket_user");
|
||||
fcgi_socket_group = AText(L"fcgi_socket_group");
|
||||
fcgi_socket_user = Text(L"fcgi_socket_user");
|
||||
fcgi_socket_group = Text(L"fcgi_socket_group");
|
||||
fcgi_socket_listen = Int(L"fcgi_socket_listen", 100);
|
||||
log_level = Int(L"log_level", 1);
|
||||
log_request = Int(L"log_request", 1);
|
||||
log_save_each_line = Bool(L"log_save_each_line", false);
|
||||
@@ -132,6 +158,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
NoLastSlash(upload_dir);
|
||||
NoLastSlash(common_dir);
|
||||
|
||||
upload_group = Text(L"upload_group");
|
||||
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
|
||||
upload_files_chmod = Int(L"upload_files_chmod", 0640);
|
||||
ListText(L"static_dirs", static_dirs);
|
||||
@@ -158,9 +185,9 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
||||
|
||||
http_session_id_name = Text(L"http_session_id_name", L"session_id");
|
||||
db_database = AText(L"db_database");
|
||||
db_user = AText(L"db_user");
|
||||
db_pass = AText(L"db_pass");
|
||||
db_database = Text(L"db_database");
|
||||
db_user = Text(L"db_user");
|
||||
db_pass = Text(L"db_pass");
|
||||
item_url_empty = Text(L"item_url_empty");
|
||||
|
||||
url_proto = Text(L"url_proto", L"http://");
|
||||
@@ -188,8 +215,17 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
|
||||
session_max_idle = Int(L"session_max_idle", 10800); // 3h
|
||||
session_remember_max_idle = Int(L"session_remember_max_idle", 16070400); // 3 months
|
||||
session_file = AText(L"session_file");
|
||||
session_file = Text(L"session_file");
|
||||
session_max = Size(L"session_max", 1000000);
|
||||
session_cookie_encode = Bool(L"session_cookie_encode", false);
|
||||
session_keys_file = Text(L"session_keys_file");
|
||||
session_allow_index_difference = Size(L"session_allow_index_difference", 8);
|
||||
session_index_time_increment = Long(L"session_index_time_increment", 30);
|
||||
session_key_renew_time = Size(L"session_key_renew_time", 172800); // 2 days
|
||||
broken_encoded_cookie_treshold = Size(L"broken_encoded_cookie_treshold", 2);
|
||||
session_hijacking_treshold = Size(L"session_hijacking_treshold", 128);
|
||||
no_session_cookie_treshold = Size(L"no_session_cookie_treshold", 128);
|
||||
no_session_cookie_ban_mode = Int(L"no_session_cookie_ban_mode", 0);
|
||||
|
||||
compression = Bool(L"compression", true);
|
||||
compression_page_min_size = Size(L"compression_page_min_size", 512);
|
||||
@@ -202,6 +238,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
html_filter_tabs = Size(L"html_filter_tabs", 2);
|
||||
html_filter_orphans = Bool(L"html_filter_orphans", true);
|
||||
html_filter_orphans_mode_str = Text(L"html_filter_orphans_mode_str", L"nbsp");
|
||||
html_filter_nofilter_tag = Text(L"html_filter_nofilter_tag", L"nofilter");
|
||||
|
||||
locale_dir = Text(L"locale_dir");
|
||||
locale_dir_default = Text(L"locale_dir_default");
|
||||
@@ -220,7 +257,6 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
NoLastSlash(plugins_dir);
|
||||
ListText(L"plugins", plugin_file);
|
||||
|
||||
utf8 = Bool(L"utf8", true);
|
||||
symlinks_follow_max = Size(L"symlinks_follow_max", 20);
|
||||
|
||||
ticket_form_prefix = Text(L"ticket_form_prefix", L"ticketparam");
|
||||
@@ -238,11 +274,13 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
pattern_cacher_how_many_delete = Size(L"pattern_cacher_how_many_delete", 30);
|
||||
|
||||
content_type_header = Int(L"content_type_header", 0);
|
||||
umask = Int(L"umask", 0222);
|
||||
umask = Int(L"umask", 0222);
|
||||
|
||||
ezc_max_elements = Size(L"ezc_max_elements", 50000);
|
||||
ezc_max_loop_elements = Size(L"ezc_max_loop_elements", 5000);
|
||||
ezc_out_streams_size = Size(L"ezc_out_streams_size", 16);
|
||||
ezc_error_prefix = Text(L"ezc_error_prefix", L"<!-- ");
|
||||
ezc_error_postfix = Text(L"ezc_error_postfix", L" -->");
|
||||
|
||||
account_need_email_verification = Bool(L"account_need_email_verification", true);
|
||||
reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400);
|
||||
@@ -266,6 +304,8 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
incorrect_login_cannot_login_treshold = Size(L"incorrect_login_cannot_login_treshold", 20);
|
||||
incorrect_login_cannot_login_delay = Size(L"incorrect_login_cannot_login_delay", 1800);
|
||||
|
||||
|
||||
pid_file = Text(L"pid_file", L"");
|
||||
}
|
||||
|
||||
|
||||
@@ -292,6 +332,17 @@ void Config::SetAdditionalVariables()
|
||||
|
||||
if( locale_files.empty() )
|
||||
locale_files.push_back(L"en");
|
||||
|
||||
if( !upload_group.empty() )
|
||||
upload_group_int = GetGroupId(upload_group);
|
||||
else
|
||||
upload_group_int = -1;
|
||||
|
||||
if( session_cookie_encode && session_keys_file.empty() )
|
||||
session_cookie_encode = false;
|
||||
|
||||
if( session_index_time_increment < 0 )
|
||||
session_index_time_increment = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -338,25 +389,6 @@ std::wstring & Config::Text(const std::wstring & name, const wchar_t * def)
|
||||
}
|
||||
|
||||
|
||||
std::string & Config::AText(const wchar_t * name)
|
||||
{
|
||||
return space.AText(name);
|
||||
}
|
||||
|
||||
|
||||
std::string & Config::AText(const wchar_t * name, const char * def)
|
||||
{
|
||||
return space.AText(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::string & Config::AText(const std::wstring & name, const char * def)
|
||||
{
|
||||
return space.AText(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Config::Int(const wchar_t * name)
|
||||
{
|
||||
return space.Int(name);
|
||||
|
||||
197
core/config.h
Executable file → Normal file
197
core/config.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, 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_config
|
||||
@@ -28,19 +53,26 @@ public:
|
||||
|
||||
// name of the config file
|
||||
// this is the parameter passed to winix programm
|
||||
std::string config_file;
|
||||
std::wstring config_file;
|
||||
|
||||
// server mode
|
||||
// you can assign any string to it such as "production" "dev"
|
||||
// this value is not used by winix itself
|
||||
// you can refer to it from [server_mode] and [server_mode_is] ezc functions
|
||||
std::wstring server_mode;
|
||||
|
||||
|
||||
// start as a demon (in the background)
|
||||
// default: true
|
||||
bool demonize;
|
||||
|
||||
// system user name (to which drop privileges)
|
||||
// system user's name to whom winix should drop privileges
|
||||
// used only if winix is started as the root
|
||||
std::string user;
|
||||
std::wstring user;
|
||||
|
||||
// system group name (to which drop privileges)
|
||||
// system group's name to which drop privileges
|
||||
// used only if winix is started as the root
|
||||
std::string group;
|
||||
std::wstring group;
|
||||
|
||||
// setting additional effective groups from /etc/group
|
||||
// by using initgroups()
|
||||
@@ -49,23 +81,25 @@ public:
|
||||
bool additional_groups;
|
||||
|
||||
// log file name, log file name for notifications (sending emails, etc)
|
||||
std::string log_file, log_notify_file;
|
||||
std::wstring log_file, log_notify_file;
|
||||
|
||||
// the log level (how much info should be inserted to logs)
|
||||
// 1 - minimum
|
||||
// 2 - (default)
|
||||
// 3 - maximum - all logs
|
||||
int log_level;
|
||||
|
||||
// logging to stdout too
|
||||
// only if demonize is 'false'
|
||||
// this option is valid only if 'demonize' option is set to 'false'
|
||||
// default: false
|
||||
bool log_stdout;
|
||||
|
||||
// how many requests should be saved in the same time
|
||||
// if you have a very busy server you can incrase this value
|
||||
// default: 1
|
||||
int log_request;
|
||||
|
||||
// whether to save each line of the config (use it for debug purposes)
|
||||
// whether to save each line of the config (used for debugging purposes)
|
||||
// default: false
|
||||
bool log_save_each_line;
|
||||
|
||||
@@ -80,6 +114,7 @@ public:
|
||||
bool log_server_answer;
|
||||
|
||||
// logging db queries
|
||||
// warning: use it only on a developer's server as it logs the hashes of passwords too
|
||||
// default: false
|
||||
bool log_db_query;
|
||||
|
||||
@@ -89,7 +124,7 @@ public:
|
||||
|
||||
// how many characters in values should be logged from POST parameters
|
||||
// default: 80
|
||||
// set to 0 to turn off
|
||||
// set to 0 to turn it off
|
||||
size_t log_post_value_size;
|
||||
|
||||
// request delimiter in the log file, default "---------"
|
||||
@@ -104,16 +139,24 @@ public:
|
||||
bool log_http_answer_headers;
|
||||
|
||||
// fast cgi: socket (unix domain)
|
||||
std::string fcgi_socket;
|
||||
std::wstring fcgi_socket;
|
||||
|
||||
// fast cgi: socket permissions
|
||||
// chmod and chown of the socket are set before winix drops privileges
|
||||
int fcgi_socket_chmod;
|
||||
|
||||
// fast cgi: owner of the socket
|
||||
std::string fcgi_socket_user;
|
||||
// chmod and chown of the socket are set before winix drops privileges
|
||||
std::wstring fcgi_socket_user;
|
||||
|
||||
// fast cgi: group of the socket
|
||||
std::string fcgi_socket_group;
|
||||
// chmod and chown of the socket are set before winix drops privileges
|
||||
std::wstring fcgi_socket_group;
|
||||
|
||||
// fcgi_socket_listen is the listen queue depth used in the listen() call
|
||||
// when creating a FastCGI socket for the web server
|
||||
// default: 100
|
||||
int fcgi_socket_listen;
|
||||
|
||||
std::wstring templates_dir;
|
||||
std::wstring templates_dir_default; // html templates from winix
|
||||
@@ -132,39 +175,99 @@ public:
|
||||
// default: index.html
|
||||
std::wstring templates_index;
|
||||
|
||||
// if true then only root can use 'template' function
|
||||
// if true then only root can use 'template' winix function
|
||||
// default: false
|
||||
bool template_only_root_use_template_fun;
|
||||
|
||||
std::string db_database;
|
||||
std::string db_user;
|
||||
std::string db_pass;
|
||||
// the database name, user name and a password for the PostgreSQL database
|
||||
std::wstring db_database;
|
||||
std::wstring db_user;
|
||||
std::wstring db_pass;
|
||||
|
||||
// the name of the cookie which has the session identifier
|
||||
std::wstring http_session_id_name;
|
||||
|
||||
// string used in a place where is a user (or group) selected
|
||||
// !! IMPROVE ME should be moved to locales
|
||||
std::wstring priv_no_user;
|
||||
std::wstring priv_no_group;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (iddle time)
|
||||
// time in seconds when a user will be automatically logged out (iddle time)
|
||||
// default: 10800 = 3 hours
|
||||
int session_max_idle;
|
||||
|
||||
// time in seconds when the user will be automatically logged out (when he selected 'remember me' option)
|
||||
// time in seconds when a user will be automatically logged out
|
||||
// when he has selected the 'remember me' option when logging in
|
||||
// this time is usually greater than session_max_idle
|
||||
// default: 16070400 = 3 months
|
||||
int session_remember_max_idle;
|
||||
|
||||
// this file is used when the program is starting and ending
|
||||
std::string session_file;
|
||||
// a file to which winix stores sessions info
|
||||
// it is used when winix starts (boots) and quits
|
||||
std::wstring session_file;
|
||||
|
||||
// how many sessions can be (zero turn off this checking)
|
||||
// default: 1000000 (one milion)
|
||||
size_t session_max;
|
||||
|
||||
// allow the html output to be compressed
|
||||
// whether or not we should encode the session cookie
|
||||
// (we have a special algorithm)
|
||||
// default: false
|
||||
bool session_cookie_encode;
|
||||
|
||||
// if session_cookie_encode is true then you should provide
|
||||
// a file where AES keys will be stored
|
||||
std::wstring session_keys_file;
|
||||
|
||||
// each session has an index -- an unsigned int value
|
||||
// this value is sent in the cookie string (is encoded)
|
||||
// and is incremented when session_index_time_increment time is passed since the last incrementing
|
||||
// if a client sent the cookie back the difference between
|
||||
// current index and the index in the cookie should be less than or equal to session_allow_index_difference
|
||||
// default: 8
|
||||
size_t session_allow_index_difference;
|
||||
|
||||
// the time which should pass after the session index is incremented
|
||||
// default: 30
|
||||
// (session_allow_index_difference + 1) * session_index_time_increment should be less than a time
|
||||
// load of a page and all elements on it such as images (of course it depends on client's download too)
|
||||
time_t session_index_time_increment;
|
||||
|
||||
// time in seconds after a new AES key pair should be generated
|
||||
// we have 256 pairs of keys so this time multiplied by 256 should not be less than
|
||||
// the max time of a session (session_remember_max_idle),
|
||||
// by default: 256 * 2 days = 512 days = 1.4 year > 3 months (session_remember_max_idle)
|
||||
// default: 172800 = 2 days (max: 2678400 = 1 month, min: 10)
|
||||
size_t session_key_renew_time;
|
||||
|
||||
// after how many broken encoded cookie we should ban the current IP
|
||||
// default: 2 (value in the range <0 - 65535>)
|
||||
size_t broken_encoded_cookie_treshold;
|
||||
|
||||
// after how many incorrect session identifiers (or session indices) we should ban the current IP
|
||||
// do not set this value too low, as people connecting from the same IP address (from behind a NAT)
|
||||
// would be banned if they have an old session cookie remembered in the browser
|
||||
// default: 128 (value in the range <0 - 65535>)
|
||||
size_t session_hijacking_treshold;
|
||||
|
||||
// after how many times a client will be banned if it did not send a session cookie
|
||||
// this can be a bot such as a Google Bot or just people connecting from a NAT and all have the same IP
|
||||
// default: 128 (value in the range <0 - 65535>)
|
||||
size_t no_session_cookie_treshold;
|
||||
|
||||
// the way we behave when no_session_cookie_treshold limit is exceeded
|
||||
// 0 - if a client doesn't send a session cookie again then use a temporary session
|
||||
// (other sessions from this IP address are not affected)
|
||||
// 1 - add this IP address to ban list and create a temporary session
|
||||
// (this will block other sessions from this IP address too)
|
||||
// default: 0
|
||||
int no_session_cookie_ban_mode;
|
||||
|
||||
// allow the winix output to be compressed
|
||||
// default: true
|
||||
bool compression;
|
||||
|
||||
// if the output is shorter than this value then it will not be compressed
|
||||
// compress only if the output is greater or equal to this value
|
||||
// default: 512 bytes
|
||||
size_t compression_page_min_size;
|
||||
|
||||
@@ -191,12 +294,12 @@ public:
|
||||
bool html_filter_trim_white;
|
||||
|
||||
// when long words should be broken (a space will be inserted)
|
||||
// default: after 60 non white characters will be put a space
|
||||
// default: after 60 non white characters there will be put a space
|
||||
// set zero to turn off
|
||||
size_t html_filter_break_word;
|
||||
|
||||
// when long lines should be broken (a new line character will be inserted)
|
||||
// default: 80
|
||||
// default: 110
|
||||
// set zero to turn off
|
||||
size_t html_filter_wrap_line;
|
||||
|
||||
@@ -214,10 +317,18 @@ public:
|
||||
std::wstring html_filter_orphans_mode_str;
|
||||
HTMLFilter::OrphanMode html_filter_orphans_mode;
|
||||
|
||||
// the html nofilter tag
|
||||
// content betweeng these tags (opening and closing) will not be filtered
|
||||
// and this tag will not be included in the html output
|
||||
// default: nofilter
|
||||
std::wstring html_filter_nofilter_tag;
|
||||
|
||||
// the url of a new empty item (if there is not the subject too)
|
||||
// !! IMPROVE ME should be moved to locale
|
||||
std::wstring item_url_empty;
|
||||
|
||||
// maximum length of a file send by post multipart form
|
||||
// default: 8388608 - 8MB
|
||||
// 0 - not used
|
||||
size_t post_file_max;
|
||||
|
||||
@@ -250,6 +361,14 @@ public:
|
||||
// default: empty
|
||||
std::wstring common_dir;
|
||||
|
||||
// system group's name for new uploaded files (created directories in the file system)
|
||||
// it can be empty (it is not used then)
|
||||
std::wstring upload_group;
|
||||
|
||||
// this value will be set based on upload_group
|
||||
// will be -1 if upload_group is empty or if it is invalid
|
||||
int upload_group_int;
|
||||
|
||||
// chmod of newly created directories (under upload_dir)
|
||||
// default: 0750
|
||||
int upload_dirs_chmod;
|
||||
@@ -411,11 +530,6 @@ public:
|
||||
// (if true the html code for root is not filtered)
|
||||
bool editors_html_safe_mode_skip_root;
|
||||
|
||||
// charset used in templates, locales, logs etc.
|
||||
// default: true (UTF-8)
|
||||
// if false it means 8-bit ASCII
|
||||
bool utf8;
|
||||
|
||||
// how many maximum symlinks can be followed
|
||||
// (symlinks on directories as well)
|
||||
// default: 20
|
||||
@@ -498,6 +612,13 @@ public:
|
||||
// default: 16 (64 maximum)
|
||||
size_t ezc_out_streams_size;
|
||||
|
||||
// prefix and postfix used when there is an error in Ezc patterns
|
||||
// default:
|
||||
// prefix: "<!-- "
|
||||
// postfix: " -->"
|
||||
std::wstring ezc_error_prefix;
|
||||
std::wstring ezc_error_postfix;
|
||||
|
||||
// when true then when a user want to create a new account
|
||||
// he has to provide his email and a message will be sent back to him
|
||||
// with a link to activate the account
|
||||
@@ -581,7 +702,7 @@ public:
|
||||
|
||||
// how many incorrect logins there must have been passed to display a captcha
|
||||
// next to the login form
|
||||
// default: 3
|
||||
// default: 3 (value in the range <0 - 65535>)
|
||||
size_t incorrect_login_captcha_treshold;
|
||||
|
||||
// the way how we prevent to login if there are too many incorrect login attempts
|
||||
@@ -592,7 +713,7 @@ public:
|
||||
int incorrect_login_cannot_login_mode;
|
||||
|
||||
// after how many incorrect login attempts we do the incorrect_login_cannot_login_mode action
|
||||
// default: 20
|
||||
// default: 20 (value in the range <0 - 65535>)
|
||||
size_t incorrect_login_cannot_login_treshold;
|
||||
|
||||
// used when incorrect_login_cannot_login_mode is zero
|
||||
@@ -602,6 +723,10 @@ public:
|
||||
// will be taken accordingly
|
||||
size_t incorrect_login_cannot_login_delay;
|
||||
|
||||
// pid file (a full path to a pid file)
|
||||
// default: empty which means there is not a pid file used
|
||||
// pid file is saved after winix has dropped privileges
|
||||
std::wstring pid_file;
|
||||
|
||||
|
||||
|
||||
@@ -611,9 +736,6 @@ public:
|
||||
std::wstring & Text(const wchar_t * name);
|
||||
std::wstring & Text(const wchar_t * name, const wchar_t * def);
|
||||
std::wstring & Text(const std::wstring & name, const wchar_t * def);
|
||||
std::string & AText(const wchar_t * name);
|
||||
std::string & AText(const wchar_t * name, const char * def);
|
||||
std::string & AText(const std::wstring & name, const char * def);
|
||||
|
||||
int Int(const wchar_t *);
|
||||
int Int(const wchar_t * name, int def);
|
||||
@@ -645,7 +767,6 @@ public:
|
||||
private:
|
||||
|
||||
PT::SpaceParser parser;
|
||||
std::string default_str;
|
||||
bool errors_to_stdout;
|
||||
|
||||
void ShowError();
|
||||
|
||||
81
core/cookieparser.h
Executable file → Normal file
81
core/cookieparser.h
Executable file → Normal file
@@ -1,16 +1,40 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_cookieparser
|
||||
#define headerfile_winix_core_cookieparser
|
||||
|
||||
#include <fcgiapp.h>
|
||||
#include "httpsimpleparser.h"
|
||||
#include "requesttypes.h"
|
||||
#include "log.h"
|
||||
@@ -24,10 +48,8 @@ namespace Winix
|
||||
class CookieParser : public HttpSimpleParser
|
||||
{
|
||||
|
||||
const char * cookie_string;
|
||||
const wchar_t * cookie_string;
|
||||
CookieTab * cookie_tab;
|
||||
std::wstring temp_name, temp_value;
|
||||
bool input_as_utf8;
|
||||
|
||||
|
||||
protected:
|
||||
@@ -38,32 +60,23 @@ protected:
|
||||
if( !cookie_string || *cookie_string == 0 )
|
||||
return -1;
|
||||
|
||||
return (int)(unsigned char)*(cookie_string++);
|
||||
}
|
||||
|
||||
void ConvStr(const std::string & src, std::wstring & dst)
|
||||
{
|
||||
if( input_as_utf8 )
|
||||
PT::UTF8ToWide(src, dst);
|
||||
else
|
||||
AssignString(src, dst);
|
||||
return (int)*(cookie_string++);
|
||||
}
|
||||
|
||||
virtual void Parameter(std::string & name, std::string & value)
|
||||
|
||||
|
||||
virtual void Parameter(std::wstring & name, std::wstring & value)
|
||||
{
|
||||
// Cookie names are case insensitive according to section 3.1 of RFC 2965
|
||||
// (we don't use locale here)
|
||||
ToLower(name);
|
||||
|
||||
ConvStr(name, temp_name);
|
||||
ConvStr(value, temp_value);
|
||||
|
||||
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(temp_name, temp_value) );
|
||||
log << log2 << "Cookie, name: \"" << temp_name << "\", value: \"" << temp_value << "\"";
|
||||
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(name, value) );
|
||||
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
|
||||
|
||||
if( res.second == false )
|
||||
{
|
||||
res.first->second = temp_value;
|
||||
res.first->second = value;
|
||||
log << " (overwritten)";
|
||||
}
|
||||
|
||||
@@ -76,28 +89,28 @@ public:
|
||||
|
||||
CookieParser()
|
||||
{
|
||||
input_as_utf8 = false;
|
||||
HttpSimpleParser::separator = ';';
|
||||
HttpSimpleParser::value_can_be_quoted = true;
|
||||
HttpSimpleParser::skip_white_chars = true;
|
||||
HttpSimpleParser::recognize_special_chars = false;
|
||||
HttpSimpleParser::separator = ';';
|
||||
HttpSimpleParser::value_can_be_quoted = true;
|
||||
HttpSimpleParser::skip_white_chars = true;
|
||||
HttpSimpleParser::recognize_special_chars = false;
|
||||
HttpSimpleParser::getchar_returns_utf8_chars = false;
|
||||
}
|
||||
|
||||
|
||||
void UTF8(bool utf)
|
||||
{
|
||||
input_as_utf8 = utf;
|
||||
}
|
||||
|
||||
// cookie_string can be null
|
||||
void Parse(const char * cookie_string_, CookieTab & cookie_tab_)
|
||||
void Parse(const wchar_t * cookie_string_, CookieTab & cookie_tab_)
|
||||
{
|
||||
cookie_string = cookie_string_;
|
||||
cookie_tab = &cookie_tab_;
|
||||
cookie_tab = &cookie_tab_;
|
||||
|
||||
HttpSimpleParser::Parse();
|
||||
}
|
||||
|
||||
void Parse(const std::wstring & cookie_string_, CookieTab & cookie_tab_)
|
||||
{
|
||||
Parse(cookie_string_.c_str(), cookie_tab_);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
29
core/crypt.cpp
Executable file → Normal file
29
core/crypt.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
29
core/crypt.h
Executable file → Normal file
29
core/crypt.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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_crypt
|
||||
|
||||
29
core/cur.h
Executable file → Normal file
29
core/cur.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_cur
|
||||
|
||||
29
core/dircontainer.cpp
Executable file → Normal file
29
core/dircontainer.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dircontainer.h"
|
||||
|
||||
29
core/dircontainer.h
Executable file → Normal file
29
core/dircontainer.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_dircontainer
|
||||
|
||||
29
core/dirs.cpp
Executable file → Normal file
29
core/dirs.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dirs.h"
|
||||
|
||||
29
core/dirs.h
Executable file → Normal file
29
core/dirs.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_dirs
|
||||
|
||||
29
core/error.h
Executable file → Normal file
29
core/error.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_error
|
||||
|
||||
29
core/group.h
Executable file → Normal file
29
core/group.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_group
|
||||
|
||||
29
core/groups.cpp
Executable file → Normal file
29
core/groups.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "groups.h"
|
||||
|
||||
29
core/groups.h
Executable file → Normal file
29
core/groups.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_groups
|
||||
|
||||
158
core/htmlfilter.cpp
Executable file → Normal file
158
core/htmlfilter.cpp
Executable file → Normal file
@@ -1,15 +1,41 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "htmlfilter.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
@@ -198,6 +224,13 @@ void HTMLFilter::SafeMode(bool safe_mode_)
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::SetNoFilterTag(const std::wstring & tag_name)
|
||||
{
|
||||
no_filter_tag = tag_name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HTMLFilter::Item & HTMLFilter::GetItem(size_t i)
|
||||
{
|
||||
@@ -345,7 +378,6 @@ void HTMLFilter::PutLastTagWithClosingTag()
|
||||
{
|
||||
const wchar_t * start = pchar;
|
||||
|
||||
|
||||
while( *pchar != 0 )
|
||||
{
|
||||
if( IsOpeningTagMark() )
|
||||
@@ -367,6 +399,31 @@ const wchar_t * start = pchar;
|
||||
}
|
||||
|
||||
|
||||
// used with <nofilter> </nofilter> tags
|
||||
void HTMLFilter::PutTextBetweenLastTagWithClosingTag()
|
||||
{
|
||||
const wchar_t * start = pchar, * end = pchar;
|
||||
|
||||
while( *pchar != 0 )
|
||||
{
|
||||
if( IsOpeningTagMark() )
|
||||
{
|
||||
if( IsClosingTagForLastItem() )
|
||||
{
|
||||
PopStack();
|
||||
CheckNewLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pchar += 1;
|
||||
end = pchar;
|
||||
}
|
||||
}
|
||||
|
||||
Put(start, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -449,16 +506,34 @@ void HTMLFilter::ReadItemAttrValue(bool has_quote)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
// sprawdzic to wszedzie bo teraz jest tablica
|
||||
attr_value.clear();
|
||||
attr_value_temp.clear();
|
||||
|
||||
// !! moze dodac obsluge escepowania cudzyslowu? sprawdzic czy to jest dostepne w htmlu
|
||||
for( i=0 ; *pchar && *pchar != '\"' && !IsClosingTagMark() && (has_quote || (*pchar!=10 && !IsWhite(*pchar)) ); ++i )
|
||||
// !! dodac obsluge pojedynczego cudzyslowu
|
||||
|
||||
for(i=0 ; *pchar && *pchar != '\"' && !IsClosingTagMark() && (has_quote || (*pchar!=10 && !IsWhite(*pchar)) ); ++i )
|
||||
{
|
||||
if( *pchar==10 || IsWhite(*pchar) )
|
||||
{
|
||||
if( !attr_value_temp.empty() )
|
||||
{
|
||||
attr_value.push_back(attr_value_temp);
|
||||
attr_value_temp.clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
if( i < WINIX_HTMLFILTER_ATTR_VALUE_MAXLEN )
|
||||
attr_value += *pchar;
|
||||
attr_value_temp += *pchar;
|
||||
|
||||
++pchar;
|
||||
}
|
||||
|
||||
if( !attr_value_temp.empty() )
|
||||
{
|
||||
attr_value.push_back(attr_value_temp);
|
||||
attr_value_temp.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -720,14 +795,22 @@ void HTMLFilter::PutClosingTagMark()
|
||||
|
||||
|
||||
|
||||
// !! zmienic na lepsza nazwe
|
||||
// bo to nie zwraca true jesli tag jest safe
|
||||
bool HTMLFilter::IsTagSafe(const wchar_t * tag)
|
||||
{
|
||||
if( !safe_mode )
|
||||
return true;
|
||||
|
||||
if( IsNameEqual(tag, no_filter_tag.c_str()) )
|
||||
return false;
|
||||
|
||||
static const wchar_t * unsafe_tags[] = {
|
||||
L"script", L"iframe", L"frame", L"frameset",
|
||||
L"applet", L"head", L"meta", L"html", L"link", L"body"
|
||||
L"applet", L"base", L"body",
|
||||
L"embed", L"head", L"html",
|
||||
L"frame", L"frameset",L"iframe",
|
||||
L"link", L"meta", L"param"
|
||||
L"object", L"script"
|
||||
};
|
||||
|
||||
size_t len = sizeof(unsafe_tags) / sizeof(const wchar_t*);
|
||||
@@ -755,7 +838,8 @@ bool HTMLFilter::IsTagSafe(const std::wstring & tag)
|
||||
bool HTMLFilter::PutOpeningTag()
|
||||
{
|
||||
if( !IsTagSafe(LastItem().name) )
|
||||
// dodac tutaj skipniecie calego tagu
|
||||
// !! IMPROVE ME
|
||||
// !! dodac tutaj skipniecie calego tagu
|
||||
return false;
|
||||
|
||||
PutOpeningTagMark();
|
||||
@@ -945,6 +1029,9 @@ const wchar_t * last_non_white = pchar;
|
||||
|
||||
bool HTMLFilter::PrintOpeningItem()
|
||||
{
|
||||
if( IsNameEqual(no_filter_tag, LastItem().name) )
|
||||
return true;
|
||||
|
||||
if( last_new_line )
|
||||
{
|
||||
PutNewLine();
|
||||
@@ -981,6 +1068,8 @@ bool HTMLFilter::ReadItemAttr()
|
||||
pchar += 1; // skipping '='
|
||||
SkipWhiteLines();
|
||||
|
||||
|
||||
// !! dodac obsluge pojedynczego cudzyslowu
|
||||
bool has_quote = (*pchar == '\"');
|
||||
|
||||
if( has_quote )
|
||||
@@ -1001,28 +1090,46 @@ bool HTMLFilter::CheckItemAttr()
|
||||
if( attr_has_value && IsNameEqual(L"lang", attr_name) )
|
||||
{
|
||||
LastItem().porphans = 0;
|
||||
attr_value_lower = attr_value;
|
||||
ToLower(attr_value_lower);
|
||||
|
||||
OrphansTab::iterator i = orphans_tab.find(attr_value_lower);
|
||||
if( !attr_value.empty() )
|
||||
{
|
||||
// we are taking the first value only
|
||||
attr_value_lower = attr_value[0];
|
||||
ToLower(attr_value_lower);
|
||||
|
||||
if( i != orphans_tab.end() )
|
||||
LastItem().porphans = &i->second;
|
||||
OrphansTab::iterator i = orphans_tab.find(attr_value_lower);
|
||||
|
||||
if( i != orphans_tab.end() )
|
||||
LastItem().porphans = &i->second;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::PrinItemAttr()
|
||||
void HTMLFilter::PrintItemAttr()
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( IsNameEqual(no_filter_tag, LastItem().name) )
|
||||
return;
|
||||
|
||||
Put(' ');
|
||||
Put(attr_name);
|
||||
|
||||
if( attr_has_value )
|
||||
{
|
||||
Put(L"=\"");
|
||||
Put(attr_value);
|
||||
|
||||
for(i=0 ; i<attr_value.size() ; ++i)
|
||||
{
|
||||
Put(attr_value[i]);
|
||||
|
||||
if( i + 1 < attr_value.size() )
|
||||
Put(' ');
|
||||
}
|
||||
|
||||
Put('\"');
|
||||
}
|
||||
}
|
||||
@@ -1064,15 +1171,18 @@ void HTMLFilter::ReadItemOpening()
|
||||
while( ReadItemAttr() )
|
||||
{
|
||||
if( CheckItemAttr() )
|
||||
PrinItemAttr();
|
||||
PrintItemAttr();
|
||||
}
|
||||
|
||||
SkipAndCheckClosingTag(); // here LastItem().type can be changed to 'simple'
|
||||
|
||||
if( LastItem().type == Item::simple )
|
||||
Put(L" /");
|
||||
if( !IsNameEqual(no_filter_tag, LastItem().name) )
|
||||
{
|
||||
if( LastItem().type == Item::simple )
|
||||
Put(L" /");
|
||||
|
||||
PutClosingTagMark();
|
||||
PutClosingTagMark();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1196,6 +1306,11 @@ bool HTMLFilter::IsLastTag(const wchar_t * name)
|
||||
}
|
||||
|
||||
|
||||
bool HTMLFilter::IsLastTag(const std::wstring & name)
|
||||
{
|
||||
return IsNameEqual(name, LastItem().name);
|
||||
}
|
||||
|
||||
|
||||
// checking exceptions for opening tags
|
||||
void HTMLFilter::CheckExceptions()
|
||||
@@ -1222,6 +1337,9 @@ void HTMLFilter::CheckExceptions()
|
||||
if( IsLastTag(L"pre") || IsLastTag(L"textarea") )
|
||||
PutLastTagWithClosingTag();
|
||||
|
||||
if( IsLastTag(no_filter_tag) )
|
||||
PutTextBetweenLastTagWithClosingTag();
|
||||
|
||||
if( IsLastTag(L"body") )
|
||||
LastItem().has_body_tag = true;
|
||||
}
|
||||
|
||||
48
core/htmlfilter.h
Executable file → Normal file
48
core/htmlfilter.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_htmlfilter
|
||||
@@ -110,6 +135,11 @@ public:
|
||||
void InsertTabs(size_t tabsize);
|
||||
|
||||
|
||||
// set a name of a html tag which will be used as 'nofilter' tag
|
||||
// elements between such tags are not filtered (similarly as in <pre> and <textarea>)
|
||||
// these tags (opening and closing) will no be placed in the html output
|
||||
void SetNoFilterTag(const std::wstring & tag_name);
|
||||
|
||||
// orphans are checked only in 'body' tag
|
||||
void AssignOrphans(const wchar_t * lang_code, const std::vector<std::wstring> & otab);
|
||||
void AssignOrphans(const std::wstring & lang_code, const std::vector<std::wstring> & otab);
|
||||
@@ -143,6 +173,9 @@ protected:
|
||||
typedef std::map<std::wstring, Orphans> OrphansTab;
|
||||
OrphansTab orphans_tab;
|
||||
|
||||
// html <nofilter> tag name
|
||||
std::wstring no_filter_tag;
|
||||
|
||||
|
||||
struct Item
|
||||
{
|
||||
@@ -173,6 +206,10 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
virtual methods
|
||||
*/
|
||||
@@ -223,6 +260,7 @@ protected:
|
||||
bool IsNameEqual(const std::wstring & name1, const std::wstring & name2, size_t len);
|
||||
|
||||
bool IsLastTag(const wchar_t * name);
|
||||
bool IsLastTag(const std::wstring & name);
|
||||
bool IsTagSafe(const wchar_t * tag);
|
||||
bool IsTagSafe(const std::wstring & tag);
|
||||
|
||||
@@ -254,7 +292,7 @@ protected:
|
||||
|
||||
bool ReadItemAttr();
|
||||
bool CheckItemAttr();
|
||||
void PrinItemAttr();
|
||||
void PrintItemAttr();
|
||||
|
||||
void ReadItemClosing();
|
||||
void ReadItemSpecial();
|
||||
@@ -270,6 +308,7 @@ protected:
|
||||
void PutNormalNonWhite(const wchar_t * & str, const wchar_t * end);
|
||||
void PutNormalWhite(const wchar_t * & str, const wchar_t * end);
|
||||
void PutLastTagWithClosingTag();
|
||||
void PutTextBetweenLastTagWithClosingTag();
|
||||
void PutTabs(size_t len);
|
||||
void PutNonBreakingSpace();
|
||||
void PutNewLine();
|
||||
@@ -288,7 +327,8 @@ protected:
|
||||
size_t tab_size;
|
||||
OrphanMode orphan_mode;
|
||||
std::wstring attr_name;
|
||||
std::wstring attr_value;
|
||||
std::vector<std::wstring> attr_value;
|
||||
std::wstring attr_value_temp;
|
||||
std::wstring attr_value_lower;
|
||||
bool attr_has_value;
|
||||
std::wstring lang_code_lower;
|
||||
|
||||
160
core/httpsimpleparser.cpp
Executable file → Normal file
160
core/httpsimpleparser.cpp
Executable file → Normal file
@@ -1,13 +1,41 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "httpsimpleparser.h"
|
||||
#include "misc.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -16,14 +44,12 @@ namespace Winix
|
||||
|
||||
|
||||
|
||||
void HttpSimpleParser::ToLower(std::string & s)
|
||||
void HttpSimpleParser::ToLower(std::wstring & s)
|
||||
{
|
||||
std::string::iterator i;
|
||||
|
||||
for(i=s.begin() ; i!= s.end() ; ++i)
|
||||
for(wchar_t & c : s)
|
||||
{
|
||||
if( *i>='A' && *i<='Z' )
|
||||
*i = *i - 'A' + 'a';
|
||||
if( c>='A' && c<='Z' )
|
||||
c = c - 'A' + 'a';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,38 +71,6 @@ void HttpSimpleParser::SkipWhiteChars()
|
||||
|
||||
|
||||
|
||||
void HttpSimpleParser::TrimWhiteChars(std::string & s)
|
||||
{
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
std::string::size_type i;
|
||||
|
||||
for(i = 0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
||||
|
||||
if( i == s.size() )
|
||||
{
|
||||
// all characters are white
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if( i > 0 )
|
||||
// there are some white characters at the beginning
|
||||
s.erase(0, i);
|
||||
|
||||
|
||||
// s is not empty now (i was not equal s.size())
|
||||
// and we have some non white characters
|
||||
// we stops at the last non white character
|
||||
for(i = s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
||||
|
||||
if( i != s.size()-1 )
|
||||
// there are some white characters at the end
|
||||
// we're starting from i+1 even when i==0 (there are some non white characters)
|
||||
s.erase(i+1, s.size() - i - 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int HttpSimpleParser::ParseHalfHex(int c)
|
||||
@@ -127,33 +121,42 @@ void HttpSimpleParser::CheckSpecialChar()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void HttpSimpleParser::ReadName()
|
||||
{
|
||||
// we're checking 'separator' and '=' because the string is allowed not having '=' (the value is optional)
|
||||
|
||||
utf8_token.clear();
|
||||
last_name.clear();
|
||||
|
||||
for( ; last_c!=-1 && last_c!=separator && last_c!='=' ; last_c = GetChar() )
|
||||
{
|
||||
if( recognize_special_chars )
|
||||
CheckSpecialChar();
|
||||
|
||||
if( last_c != -1 )
|
||||
last_name += last_c;
|
||||
{
|
||||
if( getchar_returns_utf8_chars )
|
||||
utf8_token += last_c;
|
||||
else
|
||||
last_name += last_c;
|
||||
}
|
||||
}
|
||||
|
||||
if( getchar_returns_utf8_chars )
|
||||
PT::UTF8ToWide(utf8_token, last_name);
|
||||
|
||||
if( last_c == '=' )
|
||||
last_c = GetChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HttpSimpleParser::ReadQuotedValue()
|
||||
{
|
||||
// skipping '"'
|
||||
last_c = GetChar();
|
||||
|
||||
utf8_token.clear();
|
||||
last_value.clear();
|
||||
|
||||
for( ; last_c!=-1 && last_c!='"' ; last_c = GetChar() )
|
||||
{
|
||||
@@ -161,9 +164,16 @@ void HttpSimpleParser::ReadQuotedValue()
|
||||
CheckSpecialChar();
|
||||
|
||||
if( last_c != -1 )
|
||||
last_value += last_c;
|
||||
{
|
||||
if( getchar_returns_utf8_chars )
|
||||
utf8_token += last_c;
|
||||
else
|
||||
last_value += last_c;
|
||||
}
|
||||
}
|
||||
|
||||
if( getchar_returns_utf8_chars )
|
||||
PT::UTF8ToWide(utf8_token, last_value);
|
||||
|
||||
if( last_c == '"' )
|
||||
last_c = GetChar();
|
||||
@@ -174,26 +184,39 @@ void HttpSimpleParser::ReadQuotedValue()
|
||||
}
|
||||
|
||||
|
||||
void HttpSimpleParser::ReadNormalValue()
|
||||
{
|
||||
utf8_token.clear();
|
||||
last_value.clear();
|
||||
|
||||
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() )
|
||||
{
|
||||
if( recognize_special_chars )
|
||||
CheckSpecialChar();
|
||||
|
||||
if( last_c != -1 )
|
||||
{
|
||||
if( getchar_returns_utf8_chars )
|
||||
utf8_token += last_c;
|
||||
else
|
||||
last_value += last_c;
|
||||
}
|
||||
}
|
||||
|
||||
if( getchar_returns_utf8_chars )
|
||||
PT::UTF8ToWide(utf8_token, last_value);
|
||||
}
|
||||
|
||||
|
||||
void HttpSimpleParser::ReadValue()
|
||||
{
|
||||
if( skip_white_chars )
|
||||
SkipWhiteChars();
|
||||
|
||||
if( value_can_be_quoted && last_c == '"' )
|
||||
{
|
||||
ReadQuotedValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() )
|
||||
{
|
||||
if( recognize_special_chars )
|
||||
CheckSpecialChar();
|
||||
|
||||
if( last_c != -1 )
|
||||
last_value += last_c;
|
||||
}
|
||||
}
|
||||
ReadNormalValue();
|
||||
|
||||
|
||||
if( last_c == separator )
|
||||
@@ -203,6 +226,21 @@ void HttpSimpleParser::ReadValue()
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* there can be some important values like passwords so its better
|
||||
* to clear them now
|
||||
*/
|
||||
void HttpSimpleParser::Clear()
|
||||
{
|
||||
Overwrite(last_name);
|
||||
Overwrite(last_value);
|
||||
Overwrite(utf8_token);
|
||||
last_name.clear();
|
||||
last_value.clear();
|
||||
utf8_token.clear();
|
||||
}
|
||||
|
||||
|
||||
void HttpSimpleParser::Parse()
|
||||
{
|
||||
for( last_c = GetChar() ; last_c != -1 ; )
|
||||
@@ -217,12 +255,14 @@ void HttpSimpleParser::Parse()
|
||||
|
||||
if( skip_white_chars )
|
||||
{
|
||||
TrimWhiteChars(last_name);
|
||||
TrimWhiteChars(last_value);
|
||||
TrimWhite(last_name);
|
||||
TrimWhite(last_value);
|
||||
}
|
||||
|
||||
Parameter(last_name, last_value); // user definied function
|
||||
}
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
55
core/httpsimpleparser.h
Executable file → Normal file
55
core/httpsimpleparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_httpsimpleparser
|
||||
@@ -27,26 +52,33 @@ protected:
|
||||
bool skip_white_chars;
|
||||
bool recognize_special_chars;
|
||||
|
||||
int ParseHalfHex(int c);
|
||||
// if false then GetChar() returns wide characters (converted to int)
|
||||
// if true then GetChar() returns utf8 characters (we have to convert them from utf8 to wide chars)
|
||||
bool getchar_returns_utf8_chars;
|
||||
|
||||
int ParseHalfHex(int c);
|
||||
void ReadName();
|
||||
void ReadQuotedValue();
|
||||
void ReadNormalValue();
|
||||
void ReadValue();
|
||||
void Clear();
|
||||
|
||||
std::string last_name;
|
||||
std::string last_value;
|
||||
std::wstring last_name;
|
||||
std::wstring last_value;
|
||||
std::string utf8_token;
|
||||
|
||||
int last_c;
|
||||
int separator;
|
||||
|
||||
// '-1' means end (eof)
|
||||
// when there is an eof this method can be called more than once (it should always return -1 in such a case)
|
||||
virtual int GetChar() = 0;
|
||||
virtual void Parameter(std::string & last_name, std::string & last_value) = 0;
|
||||
virtual void Parameter(std::wstring & last_name, std::wstring & last_value) = 0;
|
||||
|
||||
void ToLower(std::string & s);
|
||||
void ToLower(std::wstring & s);
|
||||
bool IsWhite(int c);
|
||||
|
||||
void SkipWhiteChars();
|
||||
void TrimWhiteChars(std::string & s);
|
||||
void CheckSpecialChar();
|
||||
|
||||
void Parse();
|
||||
@@ -59,9 +91,10 @@ public:
|
||||
{
|
||||
separator = '&';
|
||||
read_name = true;
|
||||
value_can_be_quoted = false;
|
||||
skip_white_chars = false;
|
||||
recognize_special_chars = true;
|
||||
value_can_be_quoted = false;
|
||||
skip_white_chars = false;
|
||||
recognize_special_chars = true;
|
||||
getchar_returns_utf8_chars = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
34
core/image.cpp
Executable file → Normal file
34
core/image.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
@@ -514,10 +539,13 @@ void Image::SaveImage()
|
||||
item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB ||
|
||||
item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB );
|
||||
|
||||
if( system->MakeFilePath(file_work, dst_path, thumb, true, config->upload_dirs_chmod) )
|
||||
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) )
|
||||
{
|
||||
// it doesn't matter for us if there is an error when chmod/chown on a file
|
||||
// the admin (root) will correct it
|
||||
SetPriv(dst_path, config->upload_files_chmod, config->upload_group_int);
|
||||
ImageSavedCorrectly();
|
||||
}
|
||||
else
|
||||
|
||||
29
core/image.h
Executable file → Normal file
29
core/image.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_image
|
||||
|
||||
57
core/ipban.h
57
core/ipban.h
@@ -1,9 +1,34 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -62,11 +87,21 @@ struct IPBan
|
||||
// the ban level to a greater value
|
||||
time_t expires;
|
||||
|
||||
|
||||
// how many incorrect login attempts there are
|
||||
unsigned int incorrect_login_events;
|
||||
unsigned short int incorrect_login_events;
|
||||
|
||||
// in the future there can be more *_events fields
|
||||
// how many incorrect encoded cookie were sent
|
||||
// only used if config.session_cookie_encode is true and session_keys_file is defined
|
||||
unsigned short int broken_encoded_cookie_events;
|
||||
|
||||
// how many incorrect session identifiers were sent
|
||||
unsigned short int session_hijacking_events;
|
||||
|
||||
// client didn't send a session cookie
|
||||
// it can be a bot or just someone wants to DOS the server
|
||||
// (a new session will be create)
|
||||
unsigned short int no_session_cookie_events;
|
||||
|
||||
|
||||
bool HasFlag(int flag) const
|
||||
@@ -98,7 +133,7 @@ struct IPBan
|
||||
}
|
||||
|
||||
|
||||
void AddNextBanLevel(time_t level1_expires, time_t level2_expires, time_t level3_expires)
|
||||
void IncrementBanLevel(time_t level1_expires, time_t level2_expires, time_t level3_expires)
|
||||
{
|
||||
if( HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL3) )
|
||||
{
|
||||
@@ -139,14 +174,20 @@ struct IPBan
|
||||
flags = 0;
|
||||
last_used = 0;
|
||||
expires = 0;
|
||||
incorrect_login_events = 0;
|
||||
incorrect_login_events = 0;
|
||||
broken_encoded_cookie_events = 0;
|
||||
session_hijacking_events = 0;
|
||||
no_session_cookie_events = 0;
|
||||
}
|
||||
|
||||
|
||||
void ClearAfterRemovingBan()
|
||||
void ResetEventsCounters()
|
||||
{
|
||||
ClearFlag(WINIX_IPBAN_FLAG_ACTIVE);
|
||||
incorrect_login_events = 0;
|
||||
incorrect_login_events = 0;
|
||||
broken_encoded_cookie_events = 0;
|
||||
session_hijacking_events = 0;
|
||||
no_session_cookie_events = 0;
|
||||
expires = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
29
core/item.cpp
Executable file → Normal file
29
core/item.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "item.h"
|
||||
|
||||
29
core/item.h
Executable file → Normal file
29
core/item.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_item
|
||||
|
||||
29
core/job.cpp
Executable file → Normal file
29
core/job.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "job.h"
|
||||
|
||||
29
core/job.h
Executable file → Normal file
29
core/job.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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_jobs
|
||||
|
||||
29
core/lastcontainer.cpp
Executable file → Normal file
29
core/lastcontainer.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
29
core/lastcontainer.h
Executable file → Normal file
29
core/lastcontainer.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-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_lastcontainer
|
||||
|
||||
38
core/loadavg.cpp
Executable file → Normal file
38
core/loadavg.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -176,8 +201,12 @@ void LoadAvg::StartRequest()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void LoadAvg::StopRequest()
|
||||
{
|
||||
char buf[50];
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &stop_req);
|
||||
|
||||
double dr = (stop_req.tv_sec - start_req.tv_sec);
|
||||
@@ -191,7 +220,10 @@ void LoadAvg::StopRequest()
|
||||
current5.req += 1;
|
||||
current15.req += 1;
|
||||
|
||||
log << log2 << "LA: request took: " << dr << "s" << logend;
|
||||
sprintf(buf, "%f", dr);
|
||||
SetNonZeroDigitsAfterComma(buf, 2);
|
||||
|
||||
log << log2 << "LA: request took: " << buf << "s" << logend;
|
||||
was_stop_request = true;
|
||||
}
|
||||
|
||||
|
||||
29
core/loadavg.h
Executable file → Normal file
29
core/loadavg.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_loadavg
|
||||
|
||||
29
core/lock.cpp
Executable file → Normal file
29
core/lock.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lock.h"
|
||||
|
||||
29
core/lock.h
Executable file → Normal file
29
core/lock.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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_lock
|
||||
|
||||
33
core/log.cpp
Executable file → Normal file
33
core/log.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
@@ -53,14 +78,14 @@ int Log::LogLevel()
|
||||
|
||||
|
||||
|
||||
void Log::Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests)
|
||||
void Log::Init(int log_level_, bool save_each_line_, const std::wstring & log_file_, bool log_std, int log_max_requests)
|
||||
{
|
||||
log_level = log_level_;
|
||||
log_file = log_file_;
|
||||
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
|
||||
}
|
||||
|
||||
31
core/log.h
Executable file → Normal file
31
core/log.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_log
|
||||
@@ -37,7 +62,7 @@ public:
|
||||
~Log();
|
||||
|
||||
void SetTimeZones(TimeZones * ptime_zones);
|
||||
void Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests);
|
||||
void Init(int log_level_, bool save_each_line_, const std::wstring & log_file_, bool log_std, int log_max_requests);
|
||||
|
||||
Log & operator<<(const void * s);
|
||||
Log & operator<<(const char * s);
|
||||
|
||||
29
core/logmanipulators.h
Executable file → Normal file
29
core/logmanipulators.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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_logmanipulators
|
||||
|
||||
685
core/misc.cpp
Executable file → Normal file
685
core/misc.cpp
Executable file → Normal file
@@ -1,14 +1,40 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <grp.h>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include "misc.h"
|
||||
@@ -25,20 +51,26 @@ namespace Winix
|
||||
namespace misc_private
|
||||
{
|
||||
// white_chars table should be sorted
|
||||
// we do not treat a new line character (10) as a white character
|
||||
// we do not treat a new line character (10) as a white character here
|
||||
static const wchar_t white_chars[] = { 0x0009, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0,
|
||||
0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004,
|
||||
0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028,
|
||||
0x2029, 0x202F, 0x205F, 0x3000 };
|
||||
|
||||
std::ifstream get_file_content;
|
||||
std::string get_file_content_ansi;
|
||||
|
||||
PT::WTextStream tmp_qencode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* IMPROVE ME
|
||||
* we ca add our own functions with treat_new_line_as_white flag
|
||||
* and with a pointer pointing after the number
|
||||
*
|
||||
* Toi(const wchar_t * str, const wchar_t ** str_after, bool treat_new_line_as_white);
|
||||
* Toi(const wchar_t * str, bool treat_new_line_as_white);
|
||||
* Toi(const std::wstring & str, bool treat_new_line_as_white);
|
||||
*
|
||||
*/
|
||||
int Toi(const std::string & str, int base)
|
||||
{
|
||||
return Toi(str.c_str(), base);
|
||||
@@ -151,7 +183,7 @@ return buffer;
|
||||
|
||||
void Toa(int value, std::string & res, int base, bool clear)
|
||||
{
|
||||
static char buffer[50];
|
||||
static char buffer[50]; // !! IMPROVE ME this 'static' is not needed here?
|
||||
size_t len = sizeof(buffer) / sizeof(char);
|
||||
|
||||
if( clear )
|
||||
@@ -164,7 +196,7 @@ size_t len = sizeof(buffer) / sizeof(char);
|
||||
|
||||
void Toa(long value, std::string & res, int base, bool clear)
|
||||
{
|
||||
static char buffer[50];
|
||||
static char buffer[50]; // !! IMPROVE ME the same as above
|
||||
size_t len = sizeof(buffer) / sizeof(char);
|
||||
|
||||
if( clear )
|
||||
@@ -177,7 +209,7 @@ size_t len = sizeof(buffer) / sizeof(char);
|
||||
|
||||
void Toa(int value, std::wstring & res, int base, bool clear)
|
||||
{
|
||||
static wchar_t buffer[50];
|
||||
static wchar_t buffer[50]; // !!
|
||||
size_t len = sizeof(buffer) / sizeof(wchar_t);
|
||||
|
||||
if( clear )
|
||||
@@ -190,7 +222,7 @@ size_t len = sizeof(buffer) / sizeof(wchar_t);
|
||||
|
||||
void Toa(long value, std::wstring & res, int base, bool clear)
|
||||
{
|
||||
static wchar_t buffer[50];
|
||||
static wchar_t buffer[50]; // !!
|
||||
size_t len = sizeof(buffer) / sizeof(wchar_t);
|
||||
|
||||
if( clear )
|
||||
@@ -204,142 +236,43 @@ size_t len = sizeof(buffer) / sizeof(wchar_t);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AssignString(const char * src, size_t len, std::wstring & dst, bool clear)
|
||||
void SetNonZeroDigitsAfterComma(char * str, size_t digits)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
bool was_comma = false;
|
||||
bool was_not_zero = false;
|
||||
size_t zeroes = 0;
|
||||
size_t not_zeroes = 0;
|
||||
|
||||
if( dst.capacity() < dst.size() + len )
|
||||
dst.reserve(dst.size() + len + 128);
|
||||
for(size_t i=0 ; str[i] != 0 ; ++i)
|
||||
{
|
||||
if( str[i] == '.' || str[i] == ',' )
|
||||
{
|
||||
was_comma = true;
|
||||
}
|
||||
else
|
||||
if( was_comma )
|
||||
{
|
||||
if( str[i] == '0' && !was_not_zero )
|
||||
{
|
||||
zeroes += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
was_not_zero = true;
|
||||
not_zeroes += 1;
|
||||
|
||||
for(size_t i=0 ; i<len ; ++i )
|
||||
dst += static_cast<unsigned char>(src[i]);
|
||||
if( not_zeroes >= digits )
|
||||
{
|
||||
str[i+1] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AssignString(const char * src, std::wstring & dst, bool clear)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
AssignString(src, len, dst, clear);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const std::string & src, std::wstring & dst, bool clear)
|
||||
{
|
||||
AssignString(src.c_str(), src.size(), dst, clear);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AssignString(const wchar_t * src, size_t len, std::string & dst, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
if( dst.capacity() < dst.size() + len )
|
||||
dst.reserve(dst.size() + len + 128);
|
||||
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
dst += static_cast<char>(src[i]);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const wchar_t * src, std::string & dst, bool clear)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
AssignString(src, len, dst, clear);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const std::wstring & src, std::string & dst, bool clear)
|
||||
{
|
||||
AssignString(src.c_str(), src.size(), dst, clear);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AssignString(const char * src, size_t len, std::string & dst, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
// we suppose that append is smart enough and we don't have to use reserve()
|
||||
dst.append(src, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AssignString(const char * src, std::string & dst, bool clear)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
AssignString(src, len, dst, clear);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AssignString(const std::string & src, std::string & dst, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
dst.append(src);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const wchar_t * src, size_t len, std::wstring & dst, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
// we suppose that append is smart enough and we don't have to use reserve()
|
||||
dst.append(src, len);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const wchar_t * src, std::wstring & dst, bool clear)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
AssignString(src, len, dst, clear);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AssignString(const std::wstring & src, std::wstring & dst, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
dst.append(src);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool CorrectUrlChar(wchar_t c)
|
||||
{
|
||||
@@ -584,9 +517,9 @@ PT::WTextStream IPToStr(int ip)
|
||||
|
||||
|
||||
/*
|
||||
we do not treat a new line character (10) as a white character
|
||||
by default we do not treat a new line character (10) as a white character
|
||||
*/
|
||||
bool IsWhite(wchar_t c)
|
||||
bool IsWhite(wchar_t c, bool treat_new_line_as_white)
|
||||
{
|
||||
using misc_private::white_chars;
|
||||
|
||||
@@ -594,6 +527,9 @@ using misc_private::white_chars;
|
||||
size_t o1 = 0;
|
||||
size_t o2 = len - 1;
|
||||
|
||||
if( c == 10 )
|
||||
return treat_new_line_as_white ? true : false;
|
||||
|
||||
if( c < white_chars[o1] || c > white_chars[o2] )
|
||||
return false;
|
||||
|
||||
@@ -626,13 +562,7 @@ bool IsWhite(const wchar_t * str, bool treat_new_line_as_white)
|
||||
{
|
||||
for( ; *str != 0 ; ++str )
|
||||
{
|
||||
if( *str == '\n' )
|
||||
{
|
||||
if( !treat_new_line_as_white )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if( !IsWhite(*str) )
|
||||
if( !IsWhite(*str, treat_new_line_as_white) )
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -651,6 +581,95 @@ bool IsWhite(const std::wstring & str, bool treat_new_line_as_white)
|
||||
|
||||
|
||||
|
||||
void TrimWhite(std::wstring & s, bool trim_new_line_too)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && IsWhite(s[i], trim_new_line_too) ; --i);
|
||||
|
||||
if( i==0 && IsWhite(s[i], trim_new_line_too) )
|
||||
{
|
||||
// the whole string has white characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting white characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, std::wstring::npos);
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && IsWhite(s[i], trim_new_line_too) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const wchar_t * SkipWhite(const wchar_t * s, bool treat_new_line_as_white)
|
||||
{
|
||||
while( IsWhite(*s, treat_new_line_as_white) )
|
||||
++s;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TrimFirst(std::wstring & s, wchar_t c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for the 'c' characters at the beginning
|
||||
for(i=0 ; i<s.size() && s[i]==c ; ++i);
|
||||
|
||||
// deleting the 'c' characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
void TrimLast(std::wstring & s, wchar_t c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for the 'c' characters at the end
|
||||
for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
|
||||
|
||||
if( i==0 && s[i]==c )
|
||||
{
|
||||
// the whole string has the 'c' characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting 'c' characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, std::wstring::npos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Trim(std::wstring & s, wchar_t c)
|
||||
{
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
TrimLast(s, c);
|
||||
TrimFirst(s, c);
|
||||
}
|
||||
|
||||
|
||||
bool IsLastSlash(const std::wstring & path)
|
||||
@@ -662,27 +681,113 @@ return path[path.size()-1] == '/';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const char * SkipWhite(const char * s)
|
||||
bool IsInt(const wchar_t * str, bool treat_new_line_as_white, bool allow_negative_value)
|
||||
{
|
||||
while( IsWhite(*s) )
|
||||
++s;
|
||||
size_t digit = 0;
|
||||
|
||||
return s;
|
||||
str = SkipWhite(str, treat_new_line_as_white);
|
||||
|
||||
if( allow_negative_value && *str == '-' )
|
||||
str += 1;
|
||||
|
||||
while( *str>='0' && *str<='9' )
|
||||
{
|
||||
digit += 1;
|
||||
str += 1;
|
||||
}
|
||||
|
||||
if( digit == 0 )
|
||||
return false;
|
||||
|
||||
str = SkipWhite(str, treat_new_line_as_white);
|
||||
|
||||
if( *str != 0 )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsInt(const wchar_t * str, bool treat_new_line_as_white)
|
||||
{
|
||||
return IsInt(str, treat_new_line_as_white, true);
|
||||
}
|
||||
|
||||
|
||||
const wchar_t * SkipWhite(const wchar_t * s)
|
||||
bool IsInt(const std::wstring & str, bool treat_new_line_as_white)
|
||||
{
|
||||
while( IsWhite(*s) )
|
||||
++s;
|
||||
|
||||
return s;
|
||||
return IsInt(str.c_str(), treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool IsSize(const wchar_t * str, bool treat_new_line_as_white)
|
||||
{
|
||||
return IsInt(str, treat_new_line_as_white, false);
|
||||
}
|
||||
|
||||
|
||||
bool IsSize(const std::wstring & str, bool treat_new_line_as_white)
|
||||
{
|
||||
return IsSize(str.c_str(), treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool IsFloat(const wchar_t * str, bool treat_new_line_as_white)
|
||||
{
|
||||
size_t digit = 0;
|
||||
size_t comma = 0;
|
||||
|
||||
str = SkipWhite(str, treat_new_line_as_white);
|
||||
|
||||
if( *str == '-' )
|
||||
str += 1;
|
||||
|
||||
while( (*str == ',' || *str == '.') || (*str>='0' && *str<='9') )
|
||||
{
|
||||
if( *str == ',' || *str == '.' )
|
||||
comma += 1;
|
||||
else
|
||||
digit += 1;
|
||||
|
||||
str += 1;
|
||||
}
|
||||
|
||||
if( comma > 1 || digit == 0 )
|
||||
return false;
|
||||
|
||||
str = SkipWhite(str, treat_new_line_as_white);
|
||||
|
||||
if( *str != 0 )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool IsFloat(const std::wstring & str, bool treat_new_line_as_white)
|
||||
{
|
||||
return IsFloat(str.c_str(), treat_new_line_as_white);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Overwrite(std::string & str)
|
||||
{
|
||||
for(char & c : str)
|
||||
c = 0;
|
||||
}
|
||||
|
||||
void Overwrite(std::wstring & str)
|
||||
{
|
||||
for(wchar_t & c : str)
|
||||
c = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
wchar_t ToSmall(wchar_t c)
|
||||
{
|
||||
if( c>='A' && c<='Z' )
|
||||
@@ -766,11 +871,12 @@ bool ValidateEmail(const std::wstring & email)
|
||||
bool IsFile(const wchar_t * file)
|
||||
{
|
||||
struct stat sb;
|
||||
static std::string afile;
|
||||
char file_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
PT::WideToUTF8(file, afile);
|
||||
if( !WideToUTF8(file, file_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
return (stat(afile.c_str(), &sb) == 0);
|
||||
return (stat(file_name, &sb) == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -780,37 +886,43 @@ bool IsFile(const std::wstring & file)
|
||||
}
|
||||
|
||||
|
||||
bool CreateDir(const wchar_t * dir, int priv)
|
||||
/*
|
||||
* group can be -1 (it is not used then)
|
||||
*/
|
||||
bool CreateDir(const wchar_t * dir, int priv, int group)
|
||||
{
|
||||
static std::string adir;
|
||||
char dir_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !IsFile(dir) )
|
||||
{
|
||||
PT::WideToUTF8(dir, adir);
|
||||
if( !WideToUTF8(dir, dir_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
if( mkdir(adir.c_str(), priv) < 0 )
|
||||
if( mkdir(dir_name, 0777) < 0 )
|
||||
{
|
||||
log << log1 << "Can't create a directory on fs: " << adir << logend;
|
||||
log << log1 << "Can't create a directory on fs: " << dir << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return SetPriv(dir, priv, group);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CreateDir(const std::wstring & dir, int priv)
|
||||
bool CreateDir(const std::wstring & dir, int priv, int group)
|
||||
{
|
||||
return CreateDir(dir.c_str(), priv);
|
||||
return CreateDir(dir.c_str(), priv, group);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// creating directories (can be more than one)
|
||||
// 'dirs' can begin with a slash (will be skipped)
|
||||
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv, bool skip_last)
|
||||
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv, int group, bool skip_last)
|
||||
{
|
||||
static std::wstring temp;
|
||||
static std::wstring temp; // !! IMPROVE ME change to char[WINIX_OS_PATH_SIZE] or just remove 'static'
|
||||
const wchar_t * p = dirs;
|
||||
|
||||
temp = base_dir; // we start creating from 'base_dir'
|
||||
@@ -834,7 +946,7 @@ const wchar_t * p = dirs;
|
||||
temp += *p;
|
||||
|
||||
if( !skip_last || *p!=0 )
|
||||
if( !CreateDir(temp.c_str(), priv) )
|
||||
if( !CreateDir(temp.c_str(), priv, group) )
|
||||
return false;
|
||||
|
||||
temp += '/';
|
||||
@@ -845,9 +957,82 @@ return true;
|
||||
|
||||
|
||||
|
||||
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv, bool skip_last)
|
||||
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv, int group, bool skip_last)
|
||||
{
|
||||
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv, skip_last);
|
||||
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv, group, skip_last);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int GetGroupId(const wchar_t * name)
|
||||
{
|
||||
struct group gr;
|
||||
struct group * result;
|
||||
char group_name[WINIX_OS_USERNAME_SIZE];
|
||||
char buffer[512];
|
||||
|
||||
if( !WideToUTF8(name, group_name, WINIX_OS_USERNAME_SIZE) )
|
||||
return -1;
|
||||
|
||||
if( getgrnam_r(group_name, &gr, buffer, sizeof(buffer)/sizeof(char), &result) != 0 )
|
||||
{
|
||||
log << log1 << "Misc: I cannot get the group_id for group name: " << name << logend;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* there is no such a group in /etc/group
|
||||
*/
|
||||
if( result == 0 )
|
||||
{
|
||||
log << log1 << "Misc: There is no a group with name: " << name << logend;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return gr.gr_gid;
|
||||
}
|
||||
|
||||
|
||||
int GetGroupId(const std::wstring & name)
|
||||
{
|
||||
return GetGroupId(name.c_str());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* setting priveleges and a group id on a file or on a directory
|
||||
* group can be -1 (it is not used then)
|
||||
*/
|
||||
bool SetPriv(const wchar_t * name, int priv, int group)
|
||||
{
|
||||
char file_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !WideToUTF8(name, file_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
if( chmod(file_name, priv) < 0 )
|
||||
{
|
||||
log << log1 << "Misc: Can't set proper fs privileges on: " << name << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( group != -1 )
|
||||
{
|
||||
if( chown(file_name, geteuid(), group) < 0 )
|
||||
{
|
||||
log << log1 << "Can't set proper fs group on: " << name
|
||||
<< ", group id was: " << group << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SetPriv(const std::wstring & name, int priv, int group)
|
||||
{
|
||||
return SetPriv(name.c_str(), priv, group);
|
||||
}
|
||||
|
||||
|
||||
@@ -876,18 +1061,22 @@ return true;
|
||||
|
||||
bool CopyFile(const wchar_t * src, const wchar_t * dst)
|
||||
{
|
||||
static std::string asrc, adst;
|
||||
char src_name[WINIX_OS_PATH_SIZE];
|
||||
char dst_name[WINIX_OS_PATH_SIZE];
|
||||
FILE * in, * out;
|
||||
|
||||
PT::WideToUTF8(src, asrc);
|
||||
PT::WideToUTF8(dst, adst);
|
||||
if( !WideToUTF8(src, src_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
in = fopen(asrc.c_str(), "rb");
|
||||
if( !WideToUTF8(dst, dst_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
in = fopen(src_name, "rb");
|
||||
|
||||
if( !in )
|
||||
return false;
|
||||
|
||||
out = fopen(adst.c_str(), "wb");
|
||||
out = fopen(dst_name, "wb");
|
||||
|
||||
if( !out )
|
||||
{
|
||||
@@ -904,7 +1093,7 @@ FILE * in, * out;
|
||||
res = false;
|
||||
|
||||
if( !res )
|
||||
remove(adst.c_str());
|
||||
remove(dst_name);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -919,11 +1108,12 @@ bool CopyFile(const std::wstring & src, const std::wstring & dst)
|
||||
|
||||
bool RemoveFile(const wchar_t * file)
|
||||
{
|
||||
static std::string afile;
|
||||
char file_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
PT::WideToUTF8(file, afile);
|
||||
if( !WideToUTF8(file, file_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
return unlink(afile.c_str()) == 0;
|
||||
return unlink(file_name) == 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -936,12 +1126,16 @@ bool RemoveFile(const std::wstring & file)
|
||||
|
||||
bool RenameFile(const wchar_t * from, const wchar_t * to)
|
||||
{
|
||||
static std::string afrom, ato;
|
||||
char from_name[WINIX_OS_PATH_SIZE];
|
||||
char to_name[WINIX_OS_PATH_SIZE];
|
||||
|
||||
PT::WideToUTF8(from, afrom);
|
||||
PT::WideToUTF8(to, ato);
|
||||
if( !WideToUTF8(from, from_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
return rename(afrom.c_str(), ato.c_str()) == 0;
|
||||
if( !WideToUTF8(to, to_name, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
return rename(from_name, to_name) == 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -954,19 +1148,25 @@ bool RenameFile(const std::wstring & from, const std::wstring & to)
|
||||
|
||||
|
||||
|
||||
bool GetUTF8File(const char * file_path, std::wstring & content, bool clear_content)
|
||||
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content)
|
||||
{
|
||||
using namespace misc_private;
|
||||
char file[WINIX_OS_PATH_SIZE];
|
||||
std::ifstream get_file_content;
|
||||
|
||||
if( clear_content )
|
||||
content.clear();
|
||||
|
||||
get_file_content.clear();
|
||||
get_file_content.open(file_path, std::ios_base::in | std::ios_base::binary);
|
||||
if( !WideToUTF8(file_path, file, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
if( !get_file_content )
|
||||
return false;
|
||||
|
||||
/*
|
||||
* we don't report any errors when converting from UTF8 to wide characters here
|
||||
*/
|
||||
PT::UTF8ToWide(get_file_content, content);
|
||||
get_file_content.close();
|
||||
|
||||
@@ -974,21 +1174,6 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content)
|
||||
{
|
||||
using namespace misc_private;
|
||||
|
||||
PT::WideToUTF8(file_path, get_file_content_ansi);
|
||||
return GetUTF8File(get_file_content_ansi.c_str(), content, clear_content);
|
||||
}
|
||||
|
||||
|
||||
bool GetUTF8File(const std::string & file_path, std::wstring & content, bool clear_content)
|
||||
{
|
||||
return GetUTF8File(file_path.c_str(), content, clear_content);
|
||||
}
|
||||
|
||||
|
||||
bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content)
|
||||
{
|
||||
return GetUTF8File(file_path.c_str(), content, clear_content);
|
||||
@@ -1128,6 +1313,69 @@ void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out)
|
||||
|
||||
|
||||
|
||||
bool UrlDecodeFromHex(int c, int & out)
|
||||
{
|
||||
if( c>='0' && c<='9' )
|
||||
{
|
||||
out = c - '0';
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( c>='a' && c<='f' )
|
||||
{
|
||||
out = c - 'a' + 10;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( c>='A' && c<='F' )
|
||||
{
|
||||
out = c - 'A' + 10;
|
||||
return true;
|
||||
}
|
||||
|
||||
out = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool UrlDecode(const char * url, std::wstring & out, bool clear_out)
|
||||
{
|
||||
char url_utf8[WINIX_URL_MAX_SIZE];
|
||||
size_t index = 0;
|
||||
int c1, c2;
|
||||
|
||||
if( clear_out )
|
||||
out.clear();
|
||||
|
||||
while( *url && index < WINIX_URL_MAX_SIZE-1 )
|
||||
{
|
||||
if( *url == '%' && *(url+1) && *(url+2) &&
|
||||
UrlDecodeFromHex(*(url+1), c1) && UrlDecodeFromHex(*(url+2), c2) )
|
||||
{
|
||||
url_utf8[index++] = (c1 << 4) + c2;
|
||||
url += 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
url_utf8[index++] = *url;
|
||||
url += 1;
|
||||
}
|
||||
}
|
||||
|
||||
url_utf8[index] = 0;
|
||||
|
||||
return PT::UTF8ToWide(url_utf8, out, false);
|
||||
}
|
||||
|
||||
|
||||
bool UrlDecode(const std::string & url, std::wstring & out, bool clear_out)
|
||||
{
|
||||
return UrlDecode(url.c_str(), out, clear_out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QEncode(const std::wstring & in, std::string & out, bool clear)
|
||||
{
|
||||
@@ -1160,6 +1408,27 @@ void RemovePostFileTmp(PostFileTab & post_file_tab)
|
||||
}
|
||||
|
||||
|
||||
bool WideToUTF8(const wchar_t * wide_string, char * utf8, size_t utf8_size)
|
||||
{
|
||||
bool res = PT::WideToUTF8(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 WideToUTF8(const std::wstring & wide_string, char * utf8, size_t utf8_size)
|
||||
{
|
||||
return WideToUTF8(wide_string.c_str(), utf8, utf8_size);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
254
core/misc.h
Executable file → Normal file
254
core/misc.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_misc
|
||||
@@ -19,6 +44,9 @@
|
||||
#include "date/date.h"
|
||||
#include "textstream/textstream.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "winix_const.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -186,33 +214,19 @@ void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
|
||||
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
conversions between ascii text and wide characters
|
||||
(destination is always std::string or std::wstring)
|
||||
|
||||
characters are copied as they are without any locales checking
|
||||
*/
|
||||
|
||||
void AssignString(const char * src, size_t len, std::wstring & dst, bool clear = true);
|
||||
void AssignString(const char * src, std::wstring & dst, bool clear = true);
|
||||
void AssignString(const std::string & src, std::wstring & dst, bool clear = true);
|
||||
|
||||
void AssignString(const wchar_t * src, size_t len, std::string & dst, bool clear = true);
|
||||
void AssignString(const wchar_t * src, std::string & dst, bool clear = true);
|
||||
void AssignString(const std::wstring & src, std::string & dst, bool clear = true);
|
||||
|
||||
void AssignString(const char * src, size_t len, std::string & dst, bool clear = true);
|
||||
void AssignString(const char * src, std::string & dst, bool clear = true);
|
||||
void AssignString(const std::string & src, std::string & dst, bool clear = true);
|
||||
|
||||
void AssignString(const wchar_t * src, size_t len, std::wstring & dst, bool clear = true);
|
||||
void AssignString(const wchar_t * src, std::wstring & dst, bool clear = true);
|
||||
void AssignString(const std::wstring & src, std::wstring & dst, bool clear = true);
|
||||
|
||||
|
||||
|
||||
* this method make sure that there is no more than 'digits' non zero digits
|
||||
* in the given string
|
||||
*
|
||||
*
|
||||
* samples (if parameter 'digits' is equal to two):
|
||||
* "0.0001234" -> "0.00012"
|
||||
* "10" -> "10"
|
||||
* "123.345" -> "123.34"
|
||||
* "55.1003" -> "55.10"
|
||||
*
|
||||
*/
|
||||
void SetNonZeroDigitsAfterComma(char * str, size_t digits);
|
||||
|
||||
|
||||
bool CorrectUrlChar(wchar_t c);
|
||||
@@ -243,94 +257,74 @@ PT::WTextStream IPToStr(int ip);
|
||||
|
||||
|
||||
|
||||
bool IsWhite(wchar_t s);
|
||||
bool IsWhite(wchar_t s, bool treat_new_line_as_white = false);
|
||||
bool IsWhite(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsWhite(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
void TrimWhite(std::wstring & s, bool trim_new_line_too = false);
|
||||
|
||||
const wchar_t * SkipWhite(const wchar_t * s, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
void TrimFirst(std::wstring & s, wchar_t c);
|
||||
void TrimLast(std::wstring & s, wchar_t c);
|
||||
void Trim(std::wstring & s, wchar_t c);
|
||||
|
||||
|
||||
bool IsLastSlash(const std::wstring & path);
|
||||
|
||||
template<class StringType>
|
||||
void TrimWhite(StringType & s)
|
||||
{
|
||||
typename StringType::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
||||
|
||||
if( i==0 && IsWhite(s[i]) )
|
||||
{
|
||||
// the whole string has white characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting white characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, StringType::npos);
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns true if str is an integer number
|
||||
* white strings at the beginning and at the end are ignored
|
||||
* e.g. returns true for:
|
||||
* " 10 "
|
||||
* " -20 "
|
||||
* e.g. returns false for:
|
||||
* ""
|
||||
* "- 20"
|
||||
* "z"
|
||||
*/
|
||||
bool IsInt(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsInt(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TrimFirst(StringType & s, wchar_t c)
|
||||
{
|
||||
typename StringType::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for the 'c' characters at the beginning
|
||||
for(i=0 ; i<s.size() && s[i]==c ; ++i);
|
||||
|
||||
// deleting the 'c' characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
/*
|
||||
* returns true if str is a non-negative integer number
|
||||
* white strings at the beginning and at the end are ignored
|
||||
* e.g. returns true for:
|
||||
* " 0 "
|
||||
* " 10 "
|
||||
* " 20 "
|
||||
* e.g. returns false for:
|
||||
* ""
|
||||
* " -20 "
|
||||
* "z"
|
||||
*/
|
||||
bool IsSize(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsSize(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TrimLast(StringType & s, wchar_t c)
|
||||
{
|
||||
typename StringType::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for the 'c' characters at the end
|
||||
for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
|
||||
|
||||
if( i==0 && s[i]==c )
|
||||
{
|
||||
// the whole string has the 'c' characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting 'c' characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, StringType::npos);
|
||||
}
|
||||
/*
|
||||
* returns true if str is a floating point number
|
||||
* white strings at the beginning and at the end are ignored
|
||||
* as a decimal comma can be a dot or a comma
|
||||
* e.g. returns true for:
|
||||
* " 10 "
|
||||
* " -20.3 "
|
||||
* " 30,5 "
|
||||
* e.g. returns false for:
|
||||
* ""
|
||||
* "- 20.1"
|
||||
* "20.1.2"
|
||||
* "z"
|
||||
*/
|
||||
bool IsFloat(const wchar_t * str, bool treat_new_line_as_white = false);
|
||||
bool IsFloat(const std::wstring & str, bool treat_new_line_as_white = false);
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void Trim(StringType & s, wchar_t c)
|
||||
{
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
TrimLast(s, c);
|
||||
TrimFirst(s, c);
|
||||
}
|
||||
|
||||
void Overwrite(std::string & str);
|
||||
void Overwrite(std::wstring & str);
|
||||
|
||||
|
||||
|
||||
@@ -387,8 +381,7 @@ bool was_comma = false;
|
||||
wchar_t ToSmall(wchar_t c);
|
||||
void ToSmall(std::wstring & s);
|
||||
|
||||
const char * SkipWhite(const char * s);
|
||||
const wchar_t * SkipWhite(const wchar_t * s);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -723,27 +716,31 @@ bool ValidateEmail(const std::wstring & email);
|
||||
|
||||
bool IsFile(const wchar_t * file);
|
||||
bool IsFile(const std::wstring & file);
|
||||
bool CreateDir(const wchar_t * dir, int priv);
|
||||
bool CreateDir(const std::wstring & dir, int priv);
|
||||
bool CreateDir(const wchar_t * dir, int priv, int group = -1);
|
||||
bool CreateDir(const std::wstring & dir, int priv, int group = -1);
|
||||
|
||||
// creating directories (dirs) under base_dir (base_dir must exist)
|
||||
// if skip_last == true then last part from dir is treated as a file (the last directory is not created)
|
||||
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, bool skip_last = false);
|
||||
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv = 0755, bool skip_last = false);
|
||||
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, int group = -1, bool skip_last = false);
|
||||
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv = 0755, int group = -1, bool skip_last = false);
|
||||
|
||||
int GetGroupId(const wchar_t * name);
|
||||
int GetGroupId(const std::wstring & name);
|
||||
|
||||
bool SetPriv(const wchar_t * name, int priv, int group = -1);
|
||||
bool SetPriv(const std::wstring & name, int priv, int group = -1);
|
||||
|
||||
bool CopyFile(FILE * in, FILE * out);
|
||||
bool CopyFile(const wchar_t * src, const wchar_t * dst);
|
||||
bool CopyFile(const wchar_t * src, const wchar_t * dst);
|
||||
bool CopyFile(const std::wstring & src, const std::wstring & dst);
|
||||
|
||||
bool RemoveFile(const wchar_t * file);
|
||||
bool RemoveFile(const std::wstring & file);
|
||||
|
||||
bool RenameFile(const wchar_t * from, const wchar_t * to);
|
||||
bool RenameFile(const wchar_t * from, const wchar_t * to);
|
||||
bool RenameFile(const std::wstring & from, const std::wstring & to);
|
||||
|
||||
bool GetUTF8File(const char * file_path, std::wstring & content, bool clear_content = true);
|
||||
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content = true);
|
||||
bool GetUTF8File(const std::string & file_path, std::wstring & content, bool clear_content = true);
|
||||
bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content = true);
|
||||
|
||||
|
||||
@@ -866,6 +863,19 @@ void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out = tru
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* decoding a URL
|
||||
*
|
||||
* return false is the url is too long (longer than WINIX_URL_MAX_SIZE)
|
||||
* or it cannot be correctly converted from UTF8 to wide characters
|
||||
*
|
||||
*/
|
||||
bool UrlDecode(const char * url, std::wstring & out, bool clear_out = true);
|
||||
bool UrlDecode(const std::string & url, std::wstring & out, bool clear_out = true);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void QEncodeAddChar(char_type c, PT::TextStreamBase<char_type, stack_size, heap_block_size> & out)
|
||||
@@ -1045,6 +1055,18 @@ void JSONescape(Stream & out, const StringType & str)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* converting from a wide string to an UTF-8 string
|
||||
* and puts a log if the conversion fails
|
||||
*
|
||||
* it uses PT::WideToUTF8()
|
||||
*/
|
||||
bool WideToUTF8(const wchar_t * wide_string, char * utf8, size_t utf8_size);
|
||||
bool WideToUTF8(const std::wstring & wide_string, char * utf8, size_t utf8_size);
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
29
core/mount.cpp
Executable file → Normal file
29
core/mount.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mount.h"
|
||||
|
||||
29
core/mount.h
Executable file → Normal file
29
core/mount.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
29
core/mountparser.cpp
Executable file → Normal file
29
core/mountparser.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mountparser.h"
|
||||
|
||||
29
core/mountparser.h
Executable file → Normal file
29
core/mountparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_mountparser
|
||||
|
||||
29
core/mounts.cpp
Executable file → Normal file
29
core/mounts.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mounts.h"
|
||||
|
||||
29
core/mounts.h
Executable file → Normal file
29
core/mounts.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
56
core/plugin.cpp
Executable file → Normal file
56
core/plugin.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
@@ -161,17 +186,18 @@ void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector<std
|
||||
}
|
||||
|
||||
|
||||
void Plugin::LoadPlugin(const std::string & filename)
|
||||
{
|
||||
LoadPlugin(filename.c_str());
|
||||
}
|
||||
|
||||
|
||||
// we don't have to use Lock() here because plusings are read
|
||||
// we don't have to use Lock() here because plugins are read
|
||||
// before threads are started
|
||||
void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
|
||||
void * Plugin::LoadInitFun(const wchar_t * filename, Fun1 & fun_init)
|
||||
{
|
||||
void * p = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
|
||||
char file[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( !WideToUTF8(filename, file, WINIX_OS_PATH_SIZE) )
|
||||
return 0;
|
||||
|
||||
void * p = dlopen(file, RTLD_NOW | RTLD_LOCAL);
|
||||
|
||||
if( !p )
|
||||
{
|
||||
@@ -180,7 +206,7 @@ void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fun_init = (Fun1)dlfunc(p, "Init");
|
||||
fun_init = (Fun1)dlsym(p, "Init");
|
||||
|
||||
if( !fun_init )
|
||||
{
|
||||
@@ -200,7 +226,7 @@ return p;
|
||||
|
||||
|
||||
|
||||
void Plugin::LoadPlugin(const char * filename)
|
||||
void Plugin::LoadPlugin(const wchar_t * filename)
|
||||
{
|
||||
Fun1 fun_init;
|
||||
void * plugin_handle;
|
||||
@@ -230,19 +256,13 @@ PluginInfo info;
|
||||
}
|
||||
|
||||
|
||||
void Plugin::LoadPlugin(const wchar_t * filename)
|
||||
{
|
||||
AssignString(filename, afilename);
|
||||
LoadPlugin(afilename.c_str());
|
||||
}
|
||||
|
||||
|
||||
void Plugin::LoadPlugin(const std::wstring & filename)
|
||||
{
|
||||
LoadPlugin(filename.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Plugin::HasPlugin(const wchar_t * name)
|
||||
{
|
||||
if( *name == 0 )
|
||||
|
||||
36
core/plugin.h
Executable file → Normal file
36
core/plugin.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_plugin
|
||||
@@ -41,7 +66,7 @@ namespace Winix
|
||||
|
||||
in the Init you can add your own functions by using plugin.Assign() method
|
||||
and you can set the name of the plugin by setting info.p1 pointer
|
||||
to a string buffer (const char *)
|
||||
to a string buffer (const wchar_t *)
|
||||
(this buffer will not be copied so it should not be destroyed after Init finishes)
|
||||
also in Init you can only use logger (log) info.config and info.db objects
|
||||
(the rest winix objects are not initialized yet)
|
||||
@@ -176,8 +201,6 @@ public:
|
||||
void SetSynchro(Synchro * psynchro);
|
||||
void SetSessionManager(SessionManager * psession_manager);
|
||||
|
||||
void LoadPlugin(const char * filename);
|
||||
void LoadPlugin(const std::string & filename);
|
||||
void LoadPlugin(const wchar_t * filename);
|
||||
void LoadPlugin(const std::wstring & filename);
|
||||
|
||||
@@ -231,14 +254,13 @@ private:
|
||||
SessionManager * session_manager;
|
||||
|
||||
std::wstring temp_path; // used when loading plugins
|
||||
std::string afilename;
|
||||
|
||||
Plugins plugins;
|
||||
|
||||
typedef std::multimap<int, Slot> Slots;
|
||||
Slots slots;
|
||||
|
||||
void * LoadInitFun(const char * filename, Fun1 & fun_init);
|
||||
void * LoadInitFun(const wchar_t * filename, Fun1 & fun_init);
|
||||
void Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info);
|
||||
|
||||
bool SetPointers(PluginInfo & info);
|
||||
|
||||
29
core/plugindata.cpp
Executable file → Normal file
29
core/plugindata.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "plugindata.h"
|
||||
|
||||
29
core/plugindata.h
Executable file → Normal file
29
core/plugindata.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_plugindata
|
||||
|
||||
36
core/pluginmsg.h
Executable file → Normal file
36
core/pluginmsg.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -20,6 +45,7 @@ namespace Winix
|
||||
|
||||
// here you can add your own EZC functions ([function])
|
||||
// PluginInfo.p1 is a pointer to Ezc::Functions object
|
||||
// PluginInfo.p2 is a pointer to Ezc::Objects object
|
||||
// session pointer is null
|
||||
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
|
||||
|
||||
@@ -243,8 +269,8 @@ namespace Winix
|
||||
#define WINIX_BASE_URL_REDIRECT 31030
|
||||
|
||||
// raw POST parameters
|
||||
// in p1 there is a pointer to std::string meaning a parameter's name
|
||||
// in p2 there is a pointer to std::string value
|
||||
// in p1 there is a pointer to std::wstring meaning a parameter's name
|
||||
// in p2 there is a pointer to std::wstring value
|
||||
// this is sent only from PostParser
|
||||
// PostMultiParser (multipart/form-data html forms) doesn't send this messsage
|
||||
// there is no a session set (session pointer is null)
|
||||
|
||||
38
core/postmultiparser.cpp
Executable file → Normal file
38
core/postmultiparser.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -363,10 +388,7 @@ void PostMultiParser::ReadContent()
|
||||
|
||||
void PostMultiParser::ConvStr(const std::string & src, std::wstring & dst)
|
||||
{
|
||||
if( config->utf8 )
|
||||
PT::UTF8ToWide(src, dst);
|
||||
else
|
||||
AssignString(src, dst);
|
||||
PT::UTF8ToWide(src, dst);
|
||||
}
|
||||
|
||||
|
||||
@@ -459,7 +481,7 @@ void PostMultiParser::CheckBoundaryEnd()
|
||||
|
||||
void PostMultiParser::CreateTmpFile()
|
||||
{
|
||||
wchar_t buf[1024];
|
||||
wchar_t buf[WINIX_OS_PATH_SIZE];
|
||||
size_t buf_len = sizeof(buf)/sizeof(wchar_t);
|
||||
|
||||
if( config->upload_dir.empty() )
|
||||
@@ -476,7 +498,7 @@ size_t buf_len = sizeof(buf)/sizeof(wchar_t);
|
||||
PT::WideToUTF8(tmp_filename, atmp_filename);
|
||||
|
||||
tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
|
||||
// !! dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
|
||||
// !! IMPROVE ME dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
|
||||
|
||||
if( !tmp_file )
|
||||
{
|
||||
|
||||
29
core/postmultiparser.h
Executable file → Normal file
29
core/postmultiparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_postmultiparser
|
||||
|
||||
76
core/postparser.h
Executable file → Normal file
76
core/postparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_postparser
|
||||
@@ -17,7 +42,6 @@
|
||||
#include "misc.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
#include "plugin.h"
|
||||
|
||||
|
||||
@@ -28,18 +52,14 @@ namespace Winix
|
||||
|
||||
class PostParser : public HttpSimpleParser
|
||||
{
|
||||
|
||||
FCGX_Stream * in;
|
||||
PostTab * post_tab;
|
||||
std::wstring temp_name, temp_value;
|
||||
bool input_as_utf8;
|
||||
size_t log_value_size;
|
||||
int var_index;
|
||||
bool has_winix_post_params_msg;
|
||||
bool has_winix_raw_post_msg;
|
||||
std::string raw_post;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -54,20 +74,20 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
void CreateLog(bool param_added)
|
||||
void CreateLog(bool param_added, const std::wstring & name, const std::wstring & value)
|
||||
{
|
||||
log << log2 << "Method POST, name: \"" << temp_name << "\"";
|
||||
log << log2 << "Method POST, name: \"" << name << "\"";
|
||||
|
||||
if( log_value_size > 0 && !IsSubStringNoCase(L"pass", temp_name.c_str()) )
|
||||
if( log_value_size > 0 && !IsSubStringNoCase(L"pass", name.c_str()) )
|
||||
{
|
||||
log << ", value: ";
|
||||
|
||||
if( temp_value.size() > log_value_size )
|
||||
if( value.size() > log_value_size )
|
||||
log << "(first " << log_value_size << " characters) ";
|
||||
|
||||
log << "\"";
|
||||
log.LogString(temp_value, log_value_size);
|
||||
log << "\" (size: " << temp_value.size() << ")";
|
||||
log.LogString(value, log_value_size);
|
||||
log << "\" (size: " << value.size() << ")";
|
||||
}
|
||||
|
||||
if( param_added == false )
|
||||
@@ -77,16 +97,8 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
void ConvStr(const std::string & src, std::wstring & dst)
|
||||
{
|
||||
if( input_as_utf8 )
|
||||
PT::UTF8ToWide(src, dst);
|
||||
else
|
||||
AssignString(src, dst);
|
||||
}
|
||||
|
||||
|
||||
virtual void Parameter(std::string & name, std::string & value)
|
||||
virtual void Parameter(std::wstring & name, std::wstring & value)
|
||||
{
|
||||
bool added;
|
||||
std::pair<PostTab::iterator, bool> res;
|
||||
@@ -94,22 +106,19 @@ protected:
|
||||
if( has_winix_post_params_msg )
|
||||
plugin.Call(0, WINIX_POST_PARAMS, &name, &value);
|
||||
|
||||
ConvStr(name, temp_name);
|
||||
ConvStr(value, temp_value);
|
||||
|
||||
res = post_tab->insert( std::make_pair(temp_name, temp_value) );
|
||||
res = post_tab->insert( std::make_pair(name, value) );
|
||||
added = res.second;
|
||||
|
||||
if( !added )
|
||||
{
|
||||
temp_name += L"_inc";
|
||||
temp_name += Toa(var_index);
|
||||
res = post_tab->insert( std::make_pair(temp_name, temp_value) );
|
||||
name += L"_inc";
|
||||
name += Toa(var_index);
|
||||
res = post_tab->insert( std::make_pair(name, value) );
|
||||
added = res.second;
|
||||
var_index += 1;
|
||||
}
|
||||
|
||||
CreateLog(added);
|
||||
CreateLog(added, name, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,13 +126,8 @@ public:
|
||||
|
||||
PostParser()
|
||||
{
|
||||
input_as_utf8 = false;
|
||||
log_value_size = 0;
|
||||
}
|
||||
|
||||
void UTF8(bool utf)
|
||||
{
|
||||
input_as_utf8 = utf;
|
||||
HttpSimpleParser::getchar_returns_utf8_chars = true;
|
||||
}
|
||||
|
||||
void LogValueSize(size_t s)
|
||||
|
||||
29
core/rebus.cpp
Executable file → Normal file
29
core/rebus.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
29
core/rebus.h
Executable file → Normal file
29
core/rebus.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_rebus
|
||||
|
||||
59
core/request.cpp
Executable file → Normal file
59
core/request.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "request.h"
|
||||
@@ -21,7 +46,7 @@ namespace Winix
|
||||
|
||||
|
||||
|
||||
Request::Request() : char_empty(0)
|
||||
Request::Request()
|
||||
{
|
||||
id = 0;
|
||||
config = 0;
|
||||
@@ -46,12 +71,16 @@ size_t len = 16;
|
||||
if( len < 1 || len > 64 )
|
||||
len = 16;
|
||||
|
||||
out_streams.resize(len);
|
||||
use_html_filter.resize(len);
|
||||
if( out_streams.size() != len )
|
||||
out_streams.resize(len);
|
||||
|
||||
if( use_html_filter.size() != len )
|
||||
use_html_filter.resize(len);
|
||||
|
||||
for(size_t i=0 ; i<out_streams.size() ; ++i)
|
||||
{
|
||||
out_streams[i].Clear();
|
||||
out_streams[i].Escape(true);
|
||||
use_html_filter[i] = true;
|
||||
}
|
||||
}
|
||||
@@ -77,16 +106,16 @@ void Request::Clear()
|
||||
|
||||
page_generated = false;
|
||||
|
||||
env_request_method = &char_empty;
|
||||
env_request_uri = &char_empty;
|
||||
env_http_cookie = &char_empty;
|
||||
env_remote_addr = &char_empty;
|
||||
env_http_host = &char_empty;
|
||||
env_http_user_agent = &char_empty;
|
||||
env_fcgi_role = &char_empty;
|
||||
env_content_type = &char_empty;
|
||||
env_http_accept_encoding = &char_empty;
|
||||
env_https = &char_empty;
|
||||
env_request_method.clear();
|
||||
env_request_uri.clear();
|
||||
env_http_cookie.clear();
|
||||
env_remote_addr.clear();
|
||||
env_http_host.clear();
|
||||
env_http_user_agent.clear();
|
||||
env_http_accept_encoding.clear();
|
||||
env_fcgi_role.clear();
|
||||
env_content_type.clear();
|
||||
env_https.clear();
|
||||
|
||||
item_tab.clear();
|
||||
item.Clear();
|
||||
|
||||
57
core/request.h
Executable file → Normal file
57
core/request.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_request
|
||||
@@ -98,19 +123,16 @@ struct Request
|
||||
|
||||
|
||||
// environment variables
|
||||
// they are not null -- when the server doesn't have such a variable
|
||||
// it will be pointing into 'char_empty' which is default '\0'
|
||||
// !! IMPROVE ME change it to std::wstring, or may PT::Space too?
|
||||
const char * env_request_method;
|
||||
const char * env_request_uri;
|
||||
const char * env_http_cookie;
|
||||
const char * env_remote_addr;
|
||||
const char * env_http_host;
|
||||
const char * env_http_user_agent;
|
||||
const char * env_http_accept_encoding;
|
||||
const char * env_fcgi_role;
|
||||
const char * env_content_type;
|
||||
const char * env_https;
|
||||
std::wstring env_request_method;
|
||||
std::wstring env_request_uri;
|
||||
std::wstring env_http_cookie;
|
||||
std::wstring env_remote_addr;
|
||||
std::wstring env_http_host;
|
||||
std::wstring env_http_user_agent;
|
||||
std::wstring env_http_accept_encoding;
|
||||
std::wstring env_fcgi_role;
|
||||
std::wstring env_content_type;
|
||||
std::wstring env_https;
|
||||
|
||||
// current IP address of the remote host (read from REMOTE_ADDR environment variable)
|
||||
// (at the moment only IPv4 are supported)
|
||||
@@ -352,10 +374,6 @@ private:
|
||||
|
||||
Config * config;
|
||||
|
||||
// contains '\0'
|
||||
// used to set env_* pointers to the empty value
|
||||
const char char_empty;
|
||||
|
||||
// used in ParamValue() and PostVar() when there is no such a param
|
||||
const std::wstring str_empty;
|
||||
|
||||
@@ -365,6 +383,7 @@ private:
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename NameType, typename ValueType>
|
||||
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date * expires)
|
||||
{
|
||||
|
||||
29
core/requesttypes.h
Executable file → Normal file
29
core/requesttypes.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_requesttypes
|
||||
|
||||
29
core/run.cpp
Executable file → Normal file
29
core/run.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
29
core/run.h
Executable file → Normal file
29
core/run.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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_run
|
||||
|
||||
53
core/session.cpp
Executable file → Normal file
53
core/session.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "session.h"
|
||||
@@ -64,18 +89,20 @@ void Session::SetTimesTo(time_t time)
|
||||
// clear_plugin_data is used when clearing the temporary session
|
||||
void Session::Clear(bool clear_plugin_data)
|
||||
{
|
||||
id = 0;
|
||||
puser = 0;
|
||||
rebus_item = 0;
|
||||
rebus_checked = false;
|
||||
remember_me = false;
|
||||
new_session = true;
|
||||
spam_score = 0;
|
||||
remove_me = false;
|
||||
id = 0;
|
||||
id_index = 0;
|
||||
id_index_changed = 0;
|
||||
puser = 0;
|
||||
rebus_item = 0;
|
||||
rebus_checked = false;
|
||||
remember_me = false;
|
||||
new_session = true;
|
||||
spam_score = 0;
|
||||
remove_me = false;
|
||||
|
||||
start_time = 0;
|
||||
last_time = 0;
|
||||
last_time_get = 0;
|
||||
start_time = 0;
|
||||
last_time = 0;
|
||||
last_time_get = 0;
|
||||
start_date.Clear();
|
||||
last_date.Clear();
|
||||
|
||||
|
||||
36
core/session.h
Executable file → Normal file
36
core/session.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_session
|
||||
@@ -42,6 +67,13 @@ struct Session
|
||||
// 0 - means that there is a temporary session
|
||||
long id;
|
||||
|
||||
// a session index
|
||||
// incremented each time a request to this session is made
|
||||
unsigned int id_index;
|
||||
|
||||
// the last time when id_index was incremented
|
||||
time_t id_index_changed;
|
||||
|
||||
// true if the session was created now
|
||||
bool new_session;
|
||||
|
||||
|
||||
29
core/sessioncontainer.cpp
Executable file → Normal file
29
core/sessioncontainer.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sessioncontainer.h"
|
||||
|
||||
29
core/sessioncontainer.h
Executable file → Normal file
29
core/sessioncontainer.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_sessioncontainer
|
||||
|
||||
561
core/sessionidmanager.cpp
Normal file
561
core/sessionidmanager.cpp
Normal file
@@ -0,0 +1,561 @@
|
||||
/*
|
||||
* 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) 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "sessionidmanager.h"
|
||||
#include "space/spaceparser.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "date/date.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
SessionIdManager::SessionIdManager()
|
||||
{
|
||||
algorithm_type = 'a';
|
||||
key_tab_size = 256;
|
||||
key_index = 0;
|
||||
last_key_generated = 0;
|
||||
key_renew_time = 60;
|
||||
was_inited = false;
|
||||
}
|
||||
|
||||
|
||||
void SessionIdManager::Init(const std::wstring & keys_file)
|
||||
{
|
||||
was_inited = true;
|
||||
|
||||
key_tab1.resize(key_tab_size);
|
||||
key_tab2.resize(key_tab_size);
|
||||
|
||||
aes1.resize(key_tab_size);
|
||||
aes2.resize(key_tab_size);
|
||||
|
||||
key_file_name = keys_file;
|
||||
ReadKeysFromFile(key_file_name);
|
||||
}
|
||||
|
||||
|
||||
void SessionIdManager::SetKeyRenewTime(time_t renew_time)
|
||||
{
|
||||
key_renew_time = renew_time;
|
||||
|
||||
if( key_renew_time < 10 )
|
||||
key_renew_time = 10;
|
||||
|
||||
time_t one_month = 60 * 60 * 24 * 31;
|
||||
|
||||
if( key_renew_time > one_month )
|
||||
key_renew_time = one_month;
|
||||
}
|
||||
|
||||
|
||||
void SessionIdManager::ReadKey(const wchar_t * name, PT::Space & space, std::vector<std::string> & dest_key)
|
||||
{
|
||||
std::vector<std::wstring> keys;
|
||||
std::string key_ascii, key_base64_decoded;
|
||||
|
||||
space.ListText(name, keys);
|
||||
|
||||
for(size_t i=0 ; i<key_tab_size ; ++i)
|
||||
dest_key[i].clear();
|
||||
|
||||
for(size_t i=0 ; i<keys.size() && i<key_tab_size ; ++i)
|
||||
{
|
||||
dest_key[i].clear();
|
||||
|
||||
if( PT::WideToUTF8(keys[i], key_ascii) )
|
||||
{
|
||||
if( base64.Decode(key_ascii, key_base64_decoded) )
|
||||
{
|
||||
size_t len = key_base64_decoded.size();
|
||||
|
||||
if( len == 16 || len == 24 || len == 32 )
|
||||
{
|
||||
dest_key[i] = key_base64_decoded;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SessionIdManager::InitializeAesKeys(size_t index)
|
||||
{
|
||||
if( !aes1[index].Key((unsigned char*)key_tab1[index].c_str(), key_tab1[index].size()) )
|
||||
log << log1 << "SIM: I cannot initialize a key1, size of the key: " << key_tab1[index].size() << logend;
|
||||
|
||||
if( !aes2[index].Key((unsigned char*)key_tab2[index].c_str(), key_tab2[index].size()) )
|
||||
log << log1 << "SIM: I cannot initialize a key2, size of the key: " << key_tab2[index].size() << logend;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SessionIdManager::InitializeAesKeys()
|
||||
{
|
||||
for(size_t i=0 ; i < key_tab_size ; ++i)
|
||||
{
|
||||
if( AreKeysCorrect(i) )
|
||||
InitializeAesKeys(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionIdManager::ReadKeysFromFile(const wchar_t * file)
|
||||
{
|
||||
PT::Space space;
|
||||
PT::SpaceParser parser;
|
||||
PT::Date date;
|
||||
|
||||
parser.SetSpace(space);
|
||||
PT::SpaceParser::Status status = parser.Parse(file);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
key_index = space.Size(L"key_index");
|
||||
|
||||
if( key_index >= 256 )
|
||||
key_index = 0;
|
||||
|
||||
if( date.Parse(space.Text(L"last_key_generated", L"0")) )
|
||||
last_key_generated = date.ToTime();
|
||||
|
||||
ReadKey(L"key_tab1", space, key_tab1);
|
||||
ReadKey(L"key_tab2", space, key_tab2);
|
||||
InitializeAesKeys();
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "SIM: I cannot read the session keys from: " << file << logend;
|
||||
}
|
||||
|
||||
return status == PT::SpaceParser::ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionIdManager::ReadKeysFromFile(const std::wstring & file)
|
||||
{
|
||||
return ReadKeysFromFile(file.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionIdManager::SaveKeysToFile(std::vector<std::string> & keys)
|
||||
{
|
||||
out_file << "(\n";
|
||||
|
||||
for(size_t i=0 ; i<keys.size() ; ++i)
|
||||
{
|
||||
base64.Encode(keys[i], tmp_key_base64_encoded);
|
||||
out_file << '\"' << tmp_key_base64_encoded << "\"\n";
|
||||
}
|
||||
|
||||
out_file << ")\n\n";
|
||||
tmp_key_base64_encoded.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionIdManager::SaveKeysToFile(const wchar_t * file)
|
||||
{
|
||||
PT::Date date = last_key_generated;
|
||||
PT::WideToUTF8(file, file_name_ascii);
|
||||
|
||||
out_file.clear();
|
||||
out_file.open(file_name_ascii, std::ios_base::binary | std::ios_base::out);
|
||||
|
||||
if( out_file )
|
||||
{
|
||||
out_file << "key_index = " << key_index << "\n";
|
||||
|
||||
out_file << "last_key_generated = \"";
|
||||
date.Serialize(out_file);
|
||||
out_file << "\"\n\n";
|
||||
|
||||
out_file << "key_tab1 = ";
|
||||
SaveKeysToFile(key_tab1);
|
||||
|
||||
out_file << "key_tab2 = ";
|
||||
SaveKeysToFile(key_tab2);
|
||||
|
||||
out_file.flush();
|
||||
}
|
||||
|
||||
out_file.close();
|
||||
file_name_ascii.clear();
|
||||
SetPriv(file, 0600);
|
||||
|
||||
return !out_file.fail();
|
||||
}
|
||||
|
||||
|
||||
bool SessionIdManager::SaveKeysToFile(const std::wstring & file)
|
||||
{
|
||||
return SaveKeysToFile(file.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionIdManager::AreKeysCorrect(size_t index)
|
||||
{
|
||||
if( index >= 256 )
|
||||
return false;
|
||||
|
||||
size_t len = key_tab1[index].size();
|
||||
|
||||
if( len != 16 && len != 24 && len != 32 )
|
||||
return false;
|
||||
|
||||
len = key_tab2[index].size();
|
||||
|
||||
if( len != 16 && len != 24 && len != 32 )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* IMPROVE ME
|
||||
* we need a better algorithm
|
||||
*/
|
||||
void SessionIdManager::GenerateKey(std::string & key, time_t cur_utc_time)
|
||||
{
|
||||
unsigned int pid = (unsigned int)getpid();
|
||||
unsigned int t = (unsigned int)cur_utc_time;
|
||||
|
||||
key.clear();
|
||||
|
||||
for(size_t i=0 ; i<16 ; ++i)
|
||||
{
|
||||
unsigned int r = rand();
|
||||
unsigned int v = r ^ pid ^ t;
|
||||
v = ((v >> 24) ^ (v >> 16) ^ (v >> 8) ^ v) & 0xff;
|
||||
|
||||
key.push_back((unsigned char)v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionIdManager::GenerateKeys(size_t index, time_t cur_utc_time)
|
||||
{
|
||||
GenerateKey(key_tab1[index], cur_utc_time);
|
||||
GenerateKey(key_tab2[index], cur_utc_time);
|
||||
InitializeAesKeys(index);
|
||||
|
||||
last_key_generated = cur_utc_time;
|
||||
|
||||
if( !SaveKeysToFile(key_file_name) )
|
||||
log << log2 << "SIM: I cannot save the session keys to: " << key_file_name << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionIdManager::CheckKeys(time_t cur_utc_time)
|
||||
{
|
||||
if( !AreKeysCorrect(key_index) )
|
||||
{
|
||||
log << log1 << "SIM: keys with index: " << key_index << " are incorrect, generating new keys" << logend;
|
||||
|
||||
GenerateKeys(key_index, cur_utc_time);
|
||||
}
|
||||
else
|
||||
if( last_key_generated + key_renew_time < cur_utc_time )
|
||||
{
|
||||
key_index += 1;
|
||||
|
||||
if( key_index >= key_tab_size )
|
||||
key_index = 0;
|
||||
|
||||
log << log2 << "SIM: generating new AES keys with index: " << key_index << logend;
|
||||
|
||||
GenerateKeys(key_index, cur_utc_time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionIdManager::RandPadding(size_t & pad_top_size, char & pad_top_value,
|
||||
size_t & pad_bottom_size, char & pad_bottom_value)
|
||||
{
|
||||
pad_top_size = (std::rand() * 5) / RAND_MAX; // multiply by 5 (not by 4)
|
||||
|
||||
if( pad_top_size > 4 )
|
||||
pad_top_size = 4;
|
||||
|
||||
pad_top_size += 5; // now pad_top_size is from <5;9>
|
||||
pad_top_value = (char)std::rand();
|
||||
|
||||
pad_bottom_size = 14 - pad_top_size; // pad_bottom_size is from <5;9> too
|
||||
pad_bottom_value = (char)std::rand();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionIdManager::AppendSum(std::string & str)
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
s += (int)(unsigned char)str[i];
|
||||
|
||||
str += (unsigned char)s;
|
||||
}
|
||||
|
||||
|
||||
void SessionIdManager::AppendXor(std::string & str)
|
||||
{
|
||||
int s = 0;
|
||||
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
s ^= (int)(unsigned char)str[i];
|
||||
|
||||
str += (unsigned char)s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionIdManager::CopyString(const std::string & in, std::wstring & out)
|
||||
{
|
||||
out.clear();
|
||||
|
||||
if( out.capacity() < in.size() )
|
||||
out.reserve(in.size());
|
||||
|
||||
for(size_t i=0 ; i<in.size() ; ++i)
|
||||
out += in[i];
|
||||
}
|
||||
|
||||
|
||||
void SessionIdManager::CopyString(const std::wstring & in, std::string & out)
|
||||
{
|
||||
out.clear();
|
||||
|
||||
if( out.capacity() < in.size() )
|
||||
out.reserve(in.size());
|
||||
|
||||
for(size_t i=0 ; i<in.size() ; ++i)
|
||||
out += in[i];
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionIdManager::Encode(std::string & str)
|
||||
{
|
||||
if( str.size() != 34 )
|
||||
return false;
|
||||
|
||||
if( !aes1[key_index].Encode((unsigned char*)string_token.c_str()+2, 16) )
|
||||
{
|
||||
log << log1 << "SIM: I cannot AES encode the first part of the token" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !aes2[key_index].Encode((unsigned char*)string_token.c_str()+16+2, 16) )
|
||||
{
|
||||
log << log1 << "SIM: I cannot AES encode the second part of the token" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SessionIdManager::EncodeToken(size_t id, unsigned int index, time_t cur_utc_time, std::wstring & token)
|
||||
{
|
||||
size_t pad_top_size;
|
||||
size_t pad_bottom_size;
|
||||
char pad_top_value;
|
||||
char pad_bottom_value;
|
||||
|
||||
string_token.clear();
|
||||
string_token.reserve(50);
|
||||
|
||||
if( !was_inited )
|
||||
return false;
|
||||
|
||||
CheckKeys(cur_utc_time);
|
||||
RandPadding(pad_top_size, pad_top_value, pad_bottom_size, pad_bottom_value);
|
||||
|
||||
string_token += algorithm_type;
|
||||
string_token += (unsigned char)key_index;
|
||||
string_token += pad_top_value;
|
||||
string_token += pad_bottom_value;
|
||||
string_token += (unsigned char)pad_top_size;
|
||||
string_token += (unsigned char)pad_bottom_size;
|
||||
string_token.append(pad_top_size, pad_top_value);
|
||||
Append(string_token, id);
|
||||
Append(string_token, index);
|
||||
string_token.append(pad_bottom_size, pad_bottom_value);
|
||||
AppendSum(string_token);
|
||||
AppendXor(string_token);
|
||||
|
||||
if( !Encode(string_token) )
|
||||
return false;
|
||||
|
||||
base64.Encode(string_token, string_token_base64);
|
||||
CopyString(string_token_base64, token);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SessionIdManager::IsPaddingCorrect(const char * str, size_t len, char val)
|
||||
{
|
||||
if( len < 5 || len > 9 )
|
||||
return false;
|
||||
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
if( str[i] != val )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SessionIdManager::DecodeAES(const char * str, size_t key)
|
||||
{
|
||||
if( !aes1[key].Decode((unsigned char*)str, 16) )
|
||||
{
|
||||
log << log1 << "SIM: I cannot AES decode the first block" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !aes2[key].Decode((unsigned char*)str + 16, 16) )
|
||||
{
|
||||
log << log1 << "SIM: I cannot AES decode the second block" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SessionIdManager::CheckControlSums(const char * str)
|
||||
{
|
||||
char old_sum = *(str++);
|
||||
char old_xor = *(str++);
|
||||
|
||||
string_token.erase(string_token.size()-2);
|
||||
|
||||
AppendSum(string_token);
|
||||
AppendXor(string_token);
|
||||
|
||||
if( old_sum != string_token[string_token.size()-2] ||
|
||||
old_xor != string_token[string_token.size()-1] )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SessionIdManager::DecodeTokenA(size_t & id, unsigned int & index)
|
||||
{
|
||||
size_t pad_top_size;
|
||||
size_t pad_bottom_size;
|
||||
char pad_top_value;
|
||||
char pad_bottom_value;
|
||||
|
||||
const char * str = string_token.c_str() + 1;
|
||||
size_t key = (unsigned char)(*str);
|
||||
|
||||
str += 1;
|
||||
|
||||
if( !DecodeAES(str, key) )
|
||||
return false;
|
||||
|
||||
pad_top_value = *(str++);
|
||||
pad_bottom_value = *(str++);
|
||||
pad_top_size = (unsigned char)*(str++);
|
||||
pad_bottom_size = (unsigned char)*(str++);
|
||||
|
||||
if( pad_bottom_size != 14 - pad_top_size )
|
||||
return false;
|
||||
|
||||
if( !IsPaddingCorrect(str, pad_top_size, pad_top_value) )
|
||||
return false;
|
||||
|
||||
str += pad_top_size;
|
||||
|
||||
Read(str, id);
|
||||
str += 8; // sizeof(id), it's better to use constant '8' instead of sizeof() operator
|
||||
// because at the beginning we are making a test whether the string size is equal to 34
|
||||
// (in the future sizeof(size_t) can be different from 8)
|
||||
Read(str, index);
|
||||
str += 4; // sizeof(index)
|
||||
|
||||
if( !IsPaddingCorrect(str, pad_bottom_size, pad_bottom_value) )
|
||||
return false;
|
||||
|
||||
str += pad_bottom_size;
|
||||
|
||||
return CheckControlSums(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionIdManager::DecodeToken(const std::wstring & token, size_t & id, unsigned int & index)
|
||||
{
|
||||
if( !was_inited )
|
||||
return false;
|
||||
|
||||
CopyString(token, string_token_base64);
|
||||
|
||||
if( !base64.Decode(string_token_base64, string_token) )
|
||||
return false;
|
||||
|
||||
if( string_token.size() != 34 )
|
||||
return false;
|
||||
|
||||
if( string_token[0] == 'a' )
|
||||
return DecodeTokenA(id, index);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
199
core/sessionidmanager.h
Normal file
199
core/sessionidmanager.h
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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) 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_sessionidmanager
|
||||
#define headerfile_winix_core_sessionidmanager
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include "base64.h"
|
||||
#include "space/space.h"
|
||||
#include "aes.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* this class is used to encode/decode the session cookie
|
||||
* in which there is a session id and a session's index
|
||||
*
|
||||
* session index is incremented each time a request comes to this session
|
||||
*
|
||||
* format of the encoded token:
|
||||
* 1 byte - algorithm type, currently only one algorithm: 'a'
|
||||
* 1 byte - an AES keys pair index
|
||||
* ---- below everything is encoded by AES (two 128 bits blocks, first block
|
||||
* is encoded by the first key and the second block is encoded by the second key) ------
|
||||
* 1 byte - top padding value
|
||||
* 1 byte - bottom padding value
|
||||
* 1 byte - top padding size
|
||||
* 1 byte - bottom padding size
|
||||
* 5-9 bytes - top padding
|
||||
* 8 bytes - the session id
|
||||
* 4 bytes - the session index
|
||||
* 5-9 bytes - bottom padding (bottom_padding_size = 14 - top_padding_size)
|
||||
* 1 byte - the sum of all previous bytes
|
||||
* 1 byte - the xor of all previous bytes (with the previous sum too)
|
||||
*
|
||||
* and at the end everyting is base64 encoded
|
||||
*
|
||||
*
|
||||
*/
|
||||
class SessionIdManager
|
||||
{
|
||||
public:
|
||||
|
||||
SessionIdManager();
|
||||
|
||||
/*
|
||||
* initialization
|
||||
* this method takes about 1MB memory more (for AES key expansions)
|
||||
* if you do not need the session cookie to be enrypted then don't call this method
|
||||
*
|
||||
*/
|
||||
void Init(const std::wstring & keys_file);
|
||||
|
||||
/*
|
||||
* how often a new AES key pairs should be generated
|
||||
*/
|
||||
void SetKeyRenewTime(time_t renew_time);
|
||||
|
||||
/*
|
||||
* encode/decode the session cookie
|
||||
* make sure the Init() method is called first
|
||||
*/
|
||||
bool EncodeToken(size_t id, unsigned int index, time_t cur_utc_time, std::wstring & token);
|
||||
bool DecodeToken(const std::wstring & token, size_t & id, unsigned int & index);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool was_inited;
|
||||
char algorithm_type;
|
||||
std::string string_token, string_token_base64;
|
||||
std::vector<std::string> key_tab1, key_tab2;
|
||||
size_t key_index;
|
||||
time_t last_key_generated;
|
||||
time_t key_renew_time;
|
||||
Tito::Base64 base64;
|
||||
size_t key_tab_size;
|
||||
std::ofstream out_file;
|
||||
std::string tmp_key_base64_encoded;
|
||||
std::wstring key_file_name;
|
||||
std::string file_name_ascii;
|
||||
std::vector<Tito::AES> aes1, aes2;
|
||||
|
||||
bool ReadKeysFromFile(const wchar_t * file);
|
||||
bool ReadKeysFromFile(const std::wstring & file);
|
||||
bool SaveKeysToFile(const wchar_t * file);
|
||||
bool SaveKeysToFile(const std::wstring & file);
|
||||
void ReadKey(const wchar_t * name, PT::Space & space, std::vector<std::string> & dest_key);
|
||||
bool AreKeysCorrect(size_t index);
|
||||
void GenerateKeys(size_t index, time_t cur_utc_time);
|
||||
void CheckKeys(time_t cur_utc_time);
|
||||
void GenerateKey(std::string & key, time_t cur_utc_time);
|
||||
void SaveKeysToFile(std::vector<std::string> & keys);
|
||||
void InitializeAesKeys();
|
||||
void RandPadding(size_t & pad_top_size, char & pad_top_value, size_t & pad_bottom_size, char & pad_bottom_value);
|
||||
void AppendSum(std::string & str);
|
||||
void AppendXor(std::string & str);
|
||||
void CopyString(const std::string & in, std::wstring & out);
|
||||
void CopyString(const std::wstring & in, std::string & out);
|
||||
bool Encode(std::string & str);
|
||||
bool DecodeTokenA(size_t & id, unsigned int & index);
|
||||
bool IsPaddingCorrect(const char * str, size_t len, char val);
|
||||
bool CheckControlSums(const char * str);
|
||||
void InitializeAesKeys(size_t index);
|
||||
bool DecodeAES(const char * str, size_t key);
|
||||
|
||||
template<typename Value>
|
||||
void Append(std::string & str, Value val);
|
||||
|
||||
template<typename Value>
|
||||
void Read(const char * str, Value & val);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename Value>
|
||||
void SessionIdManager::Append(std::string & str, Value val)
|
||||
{
|
||||
int move = sizeof(Value) * 8 - 8;
|
||||
int v;
|
||||
|
||||
do
|
||||
{
|
||||
if( move > 0 )
|
||||
v = ((val >> move) & 0xff);
|
||||
else
|
||||
v = val & 0xff;
|
||||
|
||||
str += (unsigned char)v;
|
||||
move -= 8;
|
||||
}
|
||||
while( move >= 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename Value>
|
||||
void SessionIdManager::Read(const char * str, Value & val)
|
||||
{
|
||||
val = 0;
|
||||
|
||||
for(size_t i=0 ; i<sizeof(Value) ; ++i)
|
||||
{
|
||||
val = val << 8;
|
||||
val = val | (unsigned char)str[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
359
core/sessionmanager.cpp
Executable file → Normal file
359
core/sessionmanager.cpp
Executable file → Normal file
@@ -1,13 +1,39 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <limits>
|
||||
#include "sessionmanager.h"
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
@@ -60,12 +86,26 @@ void SessionManager::SetLastContainer(LastContainer * plast_container)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionManager::InitBanList()
|
||||
{
|
||||
ban_tab.SetMaxSize(config->ban_list_soft_max_size, config->ban_list_max_size);
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::InitCookieEncoding()
|
||||
{
|
||||
if( config->session_cookie_encode && !config->session_keys_file.empty() )
|
||||
session_id_manager.Init(config->session_keys_file);
|
||||
|
||||
session_id_manager.SetKeyRenewTime(config->session_key_renew_time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
size_t SessionManager::Size()
|
||||
{
|
||||
return session_tab.Size();
|
||||
@@ -81,7 +121,15 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
bool SessionManager::EncodeSessionId(long id, unsigned int index, std::wstring & str)
|
||||
{
|
||||
return session_id_manager.EncodeToken((size_t)id, index, cur->request->start_time, str);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMPROVE ME we need a better algorithm
|
||||
*/
|
||||
long SessionManager::CreateSessionId()
|
||||
{
|
||||
long id;
|
||||
@@ -134,17 +182,19 @@ SessionContainer::Iterator i = session_tab.End();
|
||||
|
||||
if( i != session_tab.End() )
|
||||
{
|
||||
is_session_set = true;
|
||||
session = &(*i);
|
||||
session->new_session = true;
|
||||
session->SetTimesTo(cur->request->start_time);
|
||||
session->id_index = (unsigned int)session->id;
|
||||
session->id_index += std::rand();
|
||||
|
||||
log << log2 << "SM: created a new session: " << session->id << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is a problem with generating a new session id
|
||||
// we do not set a session cookie
|
||||
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
|
||||
log << log1 << "SM: cannot create a session id" << logend;
|
||||
SetTemporarySession();
|
||||
}
|
||||
}
|
||||
@@ -152,82 +202,280 @@ SessionContainer::Iterator i = session_tab.End();
|
||||
|
||||
void SessionManager::SetTemporarySession()
|
||||
{
|
||||
is_session_set = true;
|
||||
|
||||
session = &temporary_session;
|
||||
session->Clear(false);
|
||||
session->SetTimesTo(cur->request->start_time);
|
||||
session->new_session = false; // temporary session was initialized at the beginning
|
||||
|
||||
log << log2 << "SM: using temporary session" << logend;
|
||||
}
|
||||
|
||||
|
||||
unsigned int SessionManager::CalculateIndexDifference(Session & ses, unsigned int index)
|
||||
{
|
||||
unsigned int difference;
|
||||
|
||||
if( index > ses.id_index )
|
||||
difference = std::numeric_limits<unsigned int>::max() - index + ses.id_index + 1;
|
||||
else
|
||||
difference = ses.id_index - index;
|
||||
|
||||
return difference;
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::SetSessionPutLogInfo(Session & ses, bool has_index, unsigned int difference)
|
||||
{
|
||||
log << log2 << "SM: session: " << ses.id;
|
||||
|
||||
if( has_index )
|
||||
log << ", index difference: " << (size_t)difference;
|
||||
|
||||
if( ses.puser )
|
||||
log << log2 << ", user: " << ses.puser->name << ", id: " << ses.puser->id;
|
||||
|
||||
log << log2 << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionManager::SetSessionFromCookie(const std::wstring & cookie)
|
||||
void SessionManager::IncrementBanLevel(IPBan * ip_ban)
|
||||
{
|
||||
long id = Tol(cookie.c_str());
|
||||
SessionContainer::Iterator s = session_tab.FindById(id);
|
||||
ip_ban->SetFlag(WINIX_IPBAN_FLAG_ACTIVE);
|
||||
|
||||
if( s == session_tab.End() || s->remove_me )
|
||||
ip_ban->IncrementBanLevel(cur->request->start_time + (time_t)config->ban_level_1_delay,
|
||||
cur->request->start_time + (time_t)config->ban_level_2_delay,
|
||||
cur->request->start_time + (time_t)config->ban_level_3_delay);
|
||||
|
||||
PT::Date date(ip_ban->expires);
|
||||
log << log2 << "SM: this IP address has been banned to: " << date << " UTC" << logend;
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::SetFirstExpirationTime(IPBan * ip_ban)
|
||||
{
|
||||
time_t expiry = cur->request->start_time + (time_t)config->ban_level_1_delay;
|
||||
|
||||
if( ip_ban->expires < expiry )
|
||||
ip_ban->expires = expiry;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionManager::BrokenCookieCheckBan()
|
||||
{
|
||||
if( !current_ip_ban )
|
||||
current_ip_ban = &AddIPToBanList(cur->request->ip, cur->request->start_time);
|
||||
|
||||
if( current_ip_ban->broken_encoded_cookie_events < config->broken_encoded_cookie_treshold )
|
||||
{
|
||||
current_ip_ban->broken_encoded_cookie_events += 1;
|
||||
SetFirstExpirationTime(current_ip_ban);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "SM: too many incorrect encoded cookies were sent from this IP" << logend;
|
||||
IncrementBanLevel(current_ip_ban);
|
||||
SetTemporarySession();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::IncorrectSessionCheckBan()
|
||||
{
|
||||
if( !current_ip_ban )
|
||||
current_ip_ban = &AddIPToBanList(cur->request->ip, cur->request->start_time);
|
||||
|
||||
if( current_ip_ban->session_hijacking_events < config->session_hijacking_treshold )
|
||||
{
|
||||
current_ip_ban->session_hijacking_events += 1;
|
||||
SetFirstExpirationTime(current_ip_ban);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "SM: too many incorrect sessions identifiers were sent from this IP" << logend;
|
||||
IncrementBanLevel(current_ip_ban);
|
||||
SetTemporarySession();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionManager::NoSessionCookieCheckBan()
|
||||
{
|
||||
if( !current_ip_ban )
|
||||
current_ip_ban = &AddIPToBanList(cur->request->ip, cur->request->start_time);
|
||||
|
||||
if( current_ip_ban->no_session_cookie_events < config->no_session_cookie_treshold )
|
||||
{
|
||||
current_ip_ban->no_session_cookie_events += 1;
|
||||
SetFirstExpirationTime(current_ip_ban);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "SM: too many times you have not sent a session cookie" << logend;
|
||||
|
||||
if( config->no_session_cookie_ban_mode == 1 )
|
||||
IncrementBanLevel(current_ip_ban);
|
||||
|
||||
SetTemporarySession();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionManager::IsSessionCorrect(long id, bool has_index, unsigned int index,
|
||||
const SessionContainer::Iterator & s, unsigned int & difference)
|
||||
{
|
||||
difference = 0;
|
||||
|
||||
if( id == 0 )
|
||||
{
|
||||
log << log3 << "SM: id 0 is reserved for the temporary session" << logend;
|
||||
IncorrectSessionCheckBan();
|
||||
return false;
|
||||
|
||||
// that session is in the table
|
||||
session = &(*s);
|
||||
session->new_session = false;
|
||||
session->last_time = cur->request->start_time;
|
||||
session->last_date = cur->request->start_time;
|
||||
}
|
||||
|
||||
if( cur->request->method == Request::get )
|
||||
session->last_time_get = cur->request->start_time;
|
||||
if( s == session_tab.End() )
|
||||
{
|
||||
log << log3 << "SM: there is no a session with id: " << id << logend;
|
||||
IncorrectSessionCheckBan();
|
||||
return false;
|
||||
}
|
||||
|
||||
log << log2 << "SM: session: " << session->id;
|
||||
if( s->remove_me )
|
||||
{
|
||||
log << log3 << "SM: session: " << id << " is marked for removing" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( session->puser )
|
||||
log << log2 << ", user: " << session->puser->name << ", id: " << session->puser->id;
|
||||
|
||||
log << log2 << logend;
|
||||
if( has_index )
|
||||
{
|
||||
difference = CalculateIndexDifference(*s, index);
|
||||
|
||||
if( (size_t)difference > config->session_allow_index_difference )
|
||||
{
|
||||
log << log2 << "SM: an incorrect session index for session: " << id
|
||||
<< ", index difference: " << (size_t)difference << logend;
|
||||
|
||||
IncorrectSessionCheckBan();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionManager::SetSession()
|
||||
bool SessionManager::SetSessionFromCookie(long id, bool has_index, unsigned int index)
|
||||
{
|
||||
current_ip_ban = ban_tab.FindIP(cur->request->ip);
|
||||
unsigned int difference;
|
||||
bool is_session_correct;
|
||||
|
||||
if( current_ip_ban && current_ip_ban->IsIPBanned() )
|
||||
SessionContainer::Iterator s = session_tab.FindById(id);
|
||||
is_session_correct = IsSessionCorrect(id, has_index, index, s, difference);
|
||||
|
||||
if( is_session_correct )
|
||||
{
|
||||
if( current_ip_ban->expires != 0 && cur->request->start_time >= current_ip_ban->expires )
|
||||
is_session_set = true;
|
||||
session = &(*s);
|
||||
session->new_session = false;
|
||||
session->last_time = cur->request->start_time;
|
||||
session->last_date = cur->request->start_date;
|
||||
|
||||
if( session->id_index_changed + config->session_index_time_increment < cur->request->start_time )
|
||||
{
|
||||
log << log2 << "SM: removing a ban from this IP and resetting events counter" << logend;
|
||||
current_ip_ban->ClearAfterRemovingBan();
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "SM: this ip is bannned, using a temporary session" << logend;
|
||||
SetTemporarySession();
|
||||
session->ip_ban = current_ip_ban;
|
||||
return;
|
||||
session->id_index += 1;
|
||||
session->id_index_changed = cur->request->start_time;
|
||||
}
|
||||
|
||||
if( cur->request->method == Request::get )
|
||||
session->last_time_get = cur->request->start_time;
|
||||
|
||||
SetSessionPutLogInfo(*session, has_index, difference);
|
||||
}
|
||||
|
||||
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
|
||||
return is_session_correct;
|
||||
}
|
||||
|
||||
if( i == cur->request->cookie_tab.end() )
|
||||
|
||||
|
||||
|
||||
bool SessionManager::SetSessionFromCookie(const std::wstring & cookie)
|
||||
{
|
||||
if( config->session_cookie_encode )
|
||||
{
|
||||
CreateSession();
|
||||
size_t id;
|
||||
unsigned int index;
|
||||
|
||||
if( !session_id_manager.DecodeToken(cookie, id, index) )
|
||||
{
|
||||
log << log2 << "SM: an incorrect cookie string was sent" << logend;
|
||||
BrokenCookieCheckBan();
|
||||
return false;
|
||||
}
|
||||
|
||||
return SetSessionFromCookie((long)id, true, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !SetSessionFromCookie(i->second) )
|
||||
{
|
||||
// there is no such a session
|
||||
// deleting the old cookie
|
||||
cur->request->cookie_tab.erase(i);
|
||||
long id = Tol(cookie.c_str());
|
||||
return SetSessionFromCookie(id, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// and creating a new one
|
||||
CreateSession();
|
||||
|
||||
bool SessionManager::IsIPBanned()
|
||||
{
|
||||
current_ip_ban = ban_tab.FindIP(cur->request->ip);
|
||||
|
||||
if( current_ip_ban )
|
||||
{
|
||||
current_ip_ban->last_used = cur->request->start_time;
|
||||
|
||||
if( current_ip_ban->expires != 0 && cur->request->start_time >= current_ip_ban->expires )
|
||||
{
|
||||
log << log2 << "SM: resetting events counters for this IP" << logend;
|
||||
current_ip_ban->ResetEventsCounters();
|
||||
}
|
||||
else
|
||||
if( current_ip_ban->IsIPBanned() )
|
||||
{
|
||||
PT::Date date = current_ip_ban->expires;
|
||||
log << log2 << "SM: this ip is bannned to: " << date << logend;
|
||||
SetTemporarySession();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::SetSession()
|
||||
{
|
||||
is_session_set = false;
|
||||
|
||||
if( !IsIPBanned() )
|
||||
{
|
||||
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
|
||||
|
||||
if( i != cur->request->cookie_tab.end() )
|
||||
{
|
||||
if( !SetSessionFromCookie(i->second) )
|
||||
cur->request->cookie_tab.erase(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
NoSessionCookieCheckBan();
|
||||
}
|
||||
}
|
||||
|
||||
if( !is_session_set )
|
||||
CreateSession();
|
||||
|
||||
session->ip_ban = current_ip_ban;
|
||||
}
|
||||
|
||||
@@ -375,10 +623,15 @@ SessionContainer::Iterator i;
|
||||
|
||||
void SessionManager::SaveSessions()
|
||||
{
|
||||
char file_path[WINIX_OS_PATH_SIZE];
|
||||
|
||||
if( config->session_file.empty() )
|
||||
return;
|
||||
|
||||
std::ofstream file(config->session_file.c_str());
|
||||
if( !WideToUTF8(config->session_file, file_path, WINIX_OS_PATH_SIZE) )
|
||||
return;
|
||||
|
||||
std::ofstream file(file_path);
|
||||
|
||||
if( !file )
|
||||
{
|
||||
@@ -396,14 +649,15 @@ void SessionManager::SaveSessions()
|
||||
if( i->id != 0 && i->puser && !i->remove_me )
|
||||
{
|
||||
file << i->id << ' ' << i->puser->id << ' ' << i->remember_me << ' ';
|
||||
file << (long)i->start_time << ' ' << (long)i->last_time << std::endl;
|
||||
file << (long)i->start_time << ' ' << (long)i->last_time << ' ';
|
||||
file << i->id_index << std::endl;
|
||||
|
||||
++len;
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
chmod(config->session_file.c_str(), 0600);
|
||||
chmod(file_path, 0600);
|
||||
|
||||
log << log2 << "SM: saved " << len << " session(s)" << logend;
|
||||
}
|
||||
@@ -451,6 +705,15 @@ IPBan & SessionManager::AddIPToBanList(int ip)
|
||||
}
|
||||
|
||||
|
||||
IPBan & SessionManager::AddIPToBanList(int ip, time_t last_used)
|
||||
{
|
||||
IPBan & ban = ban_tab.AddIP(ip);
|
||||
ban.last_used = last_used;
|
||||
|
||||
return ban;
|
||||
}
|
||||
|
||||
|
||||
size_t SessionManager::BanListSize()
|
||||
{
|
||||
return ban_tab.Size();
|
||||
|
||||
64
core/sessionmanager.h
Executable file → Normal file
64
core/sessionmanager.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_sessionmanager
|
||||
@@ -21,6 +46,7 @@
|
||||
#include "system.h"
|
||||
#include "synchro.h"
|
||||
#include "basethread.h"
|
||||
#include "sessionidmanager.h"
|
||||
|
||||
|
||||
|
||||
@@ -48,8 +74,12 @@ public:
|
||||
void DeleteSessions(); // deleting all sessions
|
||||
bool ChangeSessionId(long old_id);
|
||||
|
||||
void InitBanList();
|
||||
void IncrementBanLevel(IPBan * ip_ban);
|
||||
|
||||
void InitTmpSession();
|
||||
void InitBanList();
|
||||
void InitCookieEncoding();
|
||||
|
||||
void UninitTmpSession();
|
||||
|
||||
Session * GetTmpSession();
|
||||
@@ -65,38 +95,50 @@ public:
|
||||
size_t MarkAllSessionsToRemove(long user_id);
|
||||
|
||||
IPBan & AddIPToBanList(int ip);
|
||||
IPBan & AddIPToBanList(int ip, time_t last_used);
|
||||
size_t BanListSize();
|
||||
IPBan & GetIPBan(size_t index);
|
||||
void RemoveIPBan(int ip);
|
||||
void ClearIPBanList();
|
||||
|
||||
|
||||
bool EncodeSessionId(long id, unsigned int index, std::wstring & str);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Config * config;
|
||||
Cur * cur;
|
||||
System * system;
|
||||
|
||||
LastContainer * last_container;
|
||||
|
||||
// current session - set by SetSession()
|
||||
Session * session;
|
||||
|
||||
SessionContainer session_tab;
|
||||
IPBanContainer ban_tab;
|
||||
|
||||
IPBan * current_ip_ban;
|
||||
|
||||
// session with id 0
|
||||
bool is_session_set;
|
||||
Session temporary_session;
|
||||
SessionIdManager session_id_manager;
|
||||
|
||||
bool IsSession(long s);
|
||||
|
||||
long CreateSessionId();
|
||||
void CreateSession();
|
||||
bool IsSessionCorrect(long id, bool has_index, unsigned int index, const SessionContainer::Iterator & s, unsigned int & difference);
|
||||
bool SetSessionFromCookie(long id, bool has_index, unsigned int index);
|
||||
bool SetSessionFromCookie(const std::wstring & cookie);
|
||||
void SetTemporarySession();
|
||||
unsigned int CalculateIndexDifference(Session & ses, unsigned int index);
|
||||
void SetSessionPutLogInfo(Session & ses, bool has_index, unsigned int difference);
|
||||
bool IsIPBanned();
|
||||
void SetFirstExpirationTime(IPBan * ip_ban);
|
||||
void BrokenCookieCheckBan();
|
||||
void IncorrectSessionCheckBan();
|
||||
void NoSessionCookieCheckBan();
|
||||
|
||||
// second thread
|
||||
|
||||
/*
|
||||
* second thread
|
||||
*/
|
||||
int deleted;
|
||||
virtual void Work();
|
||||
void CheckSession(SessionContainer::Iterator & i);
|
||||
|
||||
42
core/sessionparser.cpp
Executable file → Normal file
42
core/sessionparser.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sessionparser.h"
|
||||
@@ -17,7 +42,7 @@ namespace Winix
|
||||
|
||||
|
||||
|
||||
bool SessionParser::Parse(const std::string & path, SessionContainer & container)
|
||||
bool SessionParser::Parse(const std::wstring & path, SessionContainer & container)
|
||||
{
|
||||
return Parse(path.c_str(), container);
|
||||
}
|
||||
@@ -29,10 +54,16 @@ void SessionParser::SetUsers(Users * pusers)
|
||||
}
|
||||
|
||||
|
||||
bool SessionParser::Parse(const char * path, SessionContainer & container)
|
||||
bool SessionParser::Parse(const wchar_t * path, SessionContainer & container)
|
||||
{
|
||||
char file_path[WINIX_OS_PATH_SIZE];
|
||||
|
||||
container.Clear();
|
||||
file.open(path, std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
if( !WideToUTF8(path, file_path, WINIX_OS_PATH_SIZE) )
|
||||
return false;
|
||||
|
||||
file.open(file_path, std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
if( !file )
|
||||
{
|
||||
@@ -98,6 +129,7 @@ void SessionParser::MakeSession(long id, long user_id, SessionContainer & contai
|
||||
i->remember_me = ReadLong();
|
||||
i->start_time = ReadLong();
|
||||
i->last_time = ReadLong();
|
||||
i->id_index = ReadLong();
|
||||
i->start_date = i->start_time;
|
||||
i->last_date = i->last_time;
|
||||
// !! IMPROVE ME we do not save last_time_get
|
||||
|
||||
33
core/sessionparser.h
Executable file → Normal file
33
core/sessionparser.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_sessionparser
|
||||
@@ -26,8 +51,8 @@ class SessionParser
|
||||
{
|
||||
public:
|
||||
|
||||
bool Parse(const char * path, SessionContainer & container);
|
||||
bool Parse(const std::string & path, SessionContainer & container);
|
||||
bool Parse(const wchar_t * path, SessionContainer & container);
|
||||
bool Parse(const std::wstring & path, SessionContainer & container);
|
||||
void SetUsers(Users * pusers);
|
||||
|
||||
private:
|
||||
|
||||
32
core/slog.cpp
Executable file → Normal file
32
core/slog.cpp
Executable file → Normal file
@@ -1,13 +1,39 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "slog.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -163,7 +189,7 @@ return *this;
|
||||
|
||||
SLog & SLog::TranslateText(const char * str)
|
||||
{
|
||||
AssignString(str, key_temp);
|
||||
PT::UTF8ToWide(str, key_temp);
|
||||
return TranslateText(key_temp.c_str());
|
||||
}
|
||||
|
||||
|
||||
29
core/slog.h
Executable file → Normal file
29
core/slog.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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
|
||||
|
||||
66
core/synchro.cpp
Executable file → Normal file
66
core/synchro.cpp
Executable file → Normal file
@@ -1,25 +1,64 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include "synchro.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
Synchro::Synchro() : mutex(PTHREAD_MUTEX_INITIALIZER)
|
||||
Synchro::Synchro()
|
||||
{
|
||||
was_stop_signal = false;
|
||||
ref = 0;
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/*
|
||||
* on FreeBSD a pthread's pthread_mutex_lock() is checking for deadlocks by default
|
||||
*/
|
||||
mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#else
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
pthread_mutex_init(&mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -28,29 +67,34 @@ bool Synchro::Lock()
|
||||
{
|
||||
int res = pthread_mutex_lock(&mutex);
|
||||
|
||||
if( res == EDEADLK )
|
||||
if( res == 0 )
|
||||
{
|
||||
// Lock() method in this thread was called before
|
||||
ref += 1;
|
||||
ref[pthread_self()] = 1;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( res == EDEADLK )
|
||||
{
|
||||
ref = 0;
|
||||
// Lock() method in this thread was called before
|
||||
ref[pthread_self()] += 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return res == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Synchro::Unlock()
|
||||
{
|
||||
if( ref > 0 )
|
||||
int & r = ref[pthread_self()];
|
||||
|
||||
if( r > 1 )
|
||||
{
|
||||
ref -= 1;
|
||||
r -= 1;
|
||||
}
|
||||
else
|
||||
if( r == 1 )
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
34
core/synchro.h
Executable file → Normal file
34
core/synchro.h
Executable file → Normal file
@@ -1,16 +1,42 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_synchro
|
||||
#define headerfile_winix_core_synchro
|
||||
|
||||
#include <pthread.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -35,9 +61,9 @@ struct Synchro
|
||||
|
||||
private:
|
||||
|
||||
// deadlock counter
|
||||
// deadlock counter for each thread
|
||||
// we can call Lock() more than one in the same thread
|
||||
int ref;
|
||||
std::map<pthread_t, int> ref;
|
||||
|
||||
};
|
||||
|
||||
|
||||
51
core/system.cpp
Executable file → Normal file
51
core/system.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
@@ -717,7 +742,7 @@ int System::NewDirPrivileges()
|
||||
|
||||
bool System::CanUseHtml(long user_id)
|
||||
{
|
||||
return IsMemberOfGroup(user_id, L"allow_html");
|
||||
return IsSuperUser(user_id) || IsMemberOfGroup(user_id, L"allow_html");
|
||||
}
|
||||
|
||||
|
||||
@@ -730,11 +755,22 @@ bool System::CanUseBBCode(long user_id)
|
||||
|
||||
bool System::CanUseRaw(long user_id)
|
||||
{
|
||||
return IsMemberOfGroup(user_id, L"allow_raw");
|
||||
return IsSuperUser(user_id) || IsMemberOfGroup(user_id, L"allow_raw");
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool System::IsSuperUser(long user_id)
|
||||
{
|
||||
User * puser = users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
return puser->super_user;
|
||||
}
|
||||
|
||||
|
||||
bool System::IsMemberOfGroup(long user_id, const wchar_t * group_name)
|
||||
{
|
||||
User * puser = users.GetUser(user_id);
|
||||
@@ -742,9 +778,6 @@ bool System::IsMemberOfGroup(long user_id, const wchar_t * group_name)
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
return true; // !! ?? zakladamy ze administrator jest czlonkiem wszystkich grup? dlaczego?
|
||||
|
||||
long group = groups.GetGroupId(group_name);
|
||||
|
||||
if( group == -1 )
|
||||
@@ -852,7 +885,7 @@ return res;
|
||||
|
||||
// making a global file path (in the unix file system)
|
||||
// you should call CreateNewFile before
|
||||
bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bool create_dir, int chmod)
|
||||
bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bool create_dir, int chmod, int group)
|
||||
{
|
||||
path.clear();
|
||||
|
||||
@@ -882,7 +915,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
||||
path += L"/normal";
|
||||
|
||||
|
||||
if( create_dir && !CreateDirs(path, item.file_path, chmod, true) )
|
||||
if( create_dir && !CreateDirs(path, item.file_path, chmod, group, true) )
|
||||
return false;
|
||||
|
||||
path += '/';
|
||||
|
||||
32
core/system.h
Executable file → Normal file
32
core/system.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_system
|
||||
@@ -135,11 +160,12 @@ public:
|
||||
bool CanUseBBCode(long user_id);
|
||||
bool CanUseRaw(long user_id);
|
||||
|
||||
bool IsSuperUser(long user_id);
|
||||
bool IsMemberOfGroup(long user_id, const wchar_t * group_name);
|
||||
|
||||
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
|
||||
bool CreateNewFile(Item & item);
|
||||
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755);
|
||||
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755, int group = -1);
|
||||
|
||||
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
||||
|
||||
|
||||
219
core/textstream.h
Executable file → Normal file
219
core/textstream.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-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_textstream
|
||||
@@ -16,6 +41,7 @@
|
||||
#include "space/space.h"
|
||||
#include "date/date.h"
|
||||
#include "textstream/textstream.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -29,7 +55,17 @@ namespace Winix
|
||||
similar to std::ostringstream
|
||||
|
||||
StringType can be either std::string or std::wstring
|
||||
this class doesn't use UTF-8 in any kind
|
||||
|
||||
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
|
||||
@@ -74,16 +110,35 @@ public:
|
||||
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 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 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;
|
||||
std::wstring space_str; // for using with spaces
|
||||
|
||||
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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -153,7 +208,7 @@ typename TextStream<StringType>::CharType TextStream<StringType>::operator[](siz
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const char * str)
|
||||
{
|
||||
AssignString(str, buffer, false);
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -162,7 +217,7 @@ return *this;
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
|
||||
{
|
||||
AssignString(*str, buffer, false);
|
||||
Convert(*str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -171,7 +226,7 @@ return *this;
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
|
||||
{
|
||||
AssignString(str, buffer, false);
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -181,7 +236,7 @@ return *this;
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
|
||||
{
|
||||
AssignString(str, buffer, false);
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -190,7 +245,7 @@ return *this;
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
|
||||
{
|
||||
AssignString(*str, buffer, false);
|
||||
Convert(*str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -199,7 +254,7 @@ return *this;
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
|
||||
{
|
||||
AssignString(str, buffer, false);
|
||||
Convert(str, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -209,6 +264,10 @@ 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;
|
||||
@@ -218,7 +277,7 @@ return *this;
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
|
||||
{
|
||||
buffer += static_cast<CharType>(v);
|
||||
Convert(v, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -231,7 +290,7 @@ wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
AssignString(buf, buffer, false);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -244,7 +303,7 @@ wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
AssignString(buf, buffer, false);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -257,7 +316,7 @@ wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
AssignString(buf, buffer, false);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -270,7 +329,7 @@ wchar_t buf[50];
|
||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
|
||||
Toa(v, buf, len);
|
||||
AssignString(buf, buffer, false);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -282,7 +341,7 @@ TextStream<StringType> & TextStream<StringType>::operator<<(double v)
|
||||
char buf[50];
|
||||
|
||||
sprintf(buf, "%f", v);
|
||||
AssignString(buf, buffer, false);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -298,7 +357,7 @@ size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||
buf[1] = 'x';
|
||||
|
||||
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
|
||||
AssignString(buf, buffer, false);
|
||||
Convert(buf, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -307,7 +366,7 @@ return *this;
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
|
||||
{
|
||||
AssignString(buf, len, buffer, false);
|
||||
Convert(buf, len, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -323,7 +382,7 @@ TextStream<StringType> & TextStream<StringType>::write(const char * buf, size_t
|
||||
template<class StringType>
|
||||
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
AssignString(buf, len, buffer, false);
|
||||
Convert(buf, len, buffer);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -371,6 +430,124 @@ return *this;
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(wchar_t c, std::string & dst)
|
||||
{
|
||||
PT::IntToUTF8((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::UTF8ToWide(src, len, dst, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const char * src, std::wstring & dst)
|
||||
{
|
||||
PT::UTF8ToWide(src, dst, false);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const std::string & src, std::wstring & dst)
|
||||
{
|
||||
PT::UTF8ToWide(src, dst, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::string & dst)
|
||||
{
|
||||
PT::WideToUTF8(src, len, dst, false);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const wchar_t * src, std::string & dst)
|
||||
{
|
||||
PT::WideToUTF8(src, dst, false);
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
void TextStream<StringType>::Convert(const std::wstring & src, std::string & dst)
|
||||
{
|
||||
PT::WideToUTF8(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
|
||||
|
||||
|
||||
|
||||
29
core/threadmanager.cpp
Executable file → Normal file
29
core/threadmanager.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
29
core/threadmanager.h
Executable file → Normal file
29
core/threadmanager.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* 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_threadmanager
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -139,7 +164,6 @@ void TimeZones::ParseZones()
|
||||
// just space by space (not implemented in Space at the moment)
|
||||
bool TimeZones::ReadTimeZones(const wchar_t * path)
|
||||
{
|
||||
parser.UTF8(true);
|
||||
parser.SetSpace(temp_space);
|
||||
zone_tab.clear();
|
||||
temp_space.Clear();
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
29
core/ugcontainer.h
Executable file → Normal file
29
core/ugcontainer.h
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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_ugcontainer
|
||||
|
||||
30
core/user.cpp
Executable file → Normal file
30
core/user.cpp
Executable file → Normal file
@@ -1,10 +1,35 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "user.h"
|
||||
@@ -37,6 +62,7 @@ void User::Clear()
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool User::IsMemberOf(long group)
|
||||
{
|
||||
std::vector<long>::iterator i;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user