Compare commits
199 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8196fb77d1 | |||
| 4abf6642f7 | |||
| e3284dcfbc | |||
| f064ff6b3d | |||
| bfa5d8cc05 | |||
| 6614919c13 | |||
| 8379acdb7f | |||
| 160ddc258d | |||
| 01892d2766 | |||
| 222955a2e7 | |||
| 37b22c3559 | |||
| afbd522362 | |||
| a4bed3ab14 | |||
| 7468e7a36c | |||
| 145445c713 | |||
| 7fa9314c6b | |||
| 5d37b6c6ae | |||
| fe1f84e29d | |||
| 83e27a6653 | |||
| ee9c68b04e | |||
| c04874397b | |||
| 375604edd6 | |||
| 3e32f3784f | |||
| 5c4a54d998 | |||
| 3af3ac3f6f | |||
| d801f53154 | |||
| a6b06f82e9 | |||
| b7f3f84080 | |||
| 26715bdd4c | |||
| 083fa7857f | |||
| 9ffda3e070 | |||
| 81160dbbe9 | |||
| 7c266b85e2 | |||
| 48cdca7549 | |||
| 1c401eae3b | |||
| 0e9eb30b5d | |||
| c10c9393c0 | |||
| 8705b3437c | |||
| aed891764a | |||
| 495499d12f | |||
| 8d9a021eab | |||
| be6e09c5af | |||
| 293e426ed4 | |||
| 60f2337b73 | |||
| ce8152de2f | |||
| 496a1979d2 | |||
| fd698ca7b9 | |||
| b4b368d324 | |||
| 825694c880 | |||
| 32750a7d50 | |||
| 0045c6c72c | |||
| 4809016b78 | |||
| 6e2ba65524 | |||
| 8033ac66c4 | |||
| 9ef3736989 | |||
| 099dd55d0c | |||
| 53b4175d00 | |||
| 8aa6f08e08 | |||
| c5024598cb | |||
| dfcf6b29c0 | |||
| 7f48d1eb2e | |||
| eaa97995d2 | |||
| 14f997b844 | |||
| 26e87b20b1 | |||
| 5cdf6eff36 | |||
| 4ed535a3b7 | |||
| da15323c2f | |||
| bd1f717b4c | |||
| 72013046fc | |||
| 14ae19143f | |||
| d8260d8383 | |||
| 9174555ff8 | |||
| 0c6ddc2218 | |||
| 43b4075b16 | |||
| 8f8e44fee5 | |||
| 260c12894d | |||
| adf273479a | |||
| 54480da405 | |||
| 90261b2005 | |||
| cc71c225a3 | |||
| e739f30088 | |||
| 51d95b49a0 | |||
| b5c155b927 | |||
| 5a5fe1b0cc | |||
| 1c4e010fc1 | |||
| d8d523d983 | |||
| 1c2589a2f2 | |||
| 1ec61ffa11 | |||
| ca0a5c9cbe | |||
| 8dd31e737f | |||
| e98cca7fbc | |||
| 9830b0a50f | |||
| f76a0ca3e9 | |||
| 5a6d1991ac | |||
| 329e2d8001 | |||
| 403cca5aad | |||
| b8ff5d4cfc | |||
| 54e6c07efc | |||
| d11cda3577 | |||
| abafb80caf | |||
| e0dd85ca99 | |||
| 2c38fe180e | |||
| 0d0f12b394 | |||
| 86d6c96aeb | |||
| b605fb0a77 | |||
| ec773e5f29 | |||
| 9d5d088b4a | |||
| 1b858f5782 | |||
| 5b845f1d03 | |||
| db9d381a43 | |||
| 0df088e1e2 | |||
| 67099d5d06 | |||
| 07e8e0c63c | |||
| ecc89d8596 | |||
| c94b0311b6 | |||
| fc33b4f882 | |||
| 1da1eef768 | |||
| baf10a9ba9 | |||
| bcea4f9464 | |||
| 920290e9dc | |||
| 1d83cf42a1 | |||
| 09bfdf9e77 | |||
| e83fd91423 | |||
| 70421b7bd1 | |||
| 71ae70f670 | |||
| b1b3cea64e | |||
| 2712c57f15 | |||
| 0b528c7225 | |||
| b7007da5a9 | |||
| 489310ba1c | |||
| 6c2c12fe5e | |||
| e61f0db57e | |||
| 3e3546a2fd | |||
| d2fa3b7171 | |||
| 0e9f587591 | |||
| 9208b15167 | |||
| a45fb30e0a | |||
| 97c7edafd6 | |||
| 1a51b1adc7 | |||
| 9d2be5c50d | |||
| f381f24402 | |||
| f6db85fcdb | |||
| 9687d5cd66 | |||
| 6e2d00bc5b | |||
| 5aaab89cd8 | |||
| 7407d24586 | |||
| c9931da5ba | |||
| 4311f06ade | |||
| 8b64b5d372 | |||
| 631ca4f8a3 | |||
| 424618de38 | |||
| b2d3ca9543 | |||
| cb33f20a24 | |||
| 973d804db2 | |||
| 84eaa6b7b6 | |||
| f967a428ce | |||
| 543d464cbc | |||
| 43470b2a41 | |||
| fa05e25a9d | |||
| fe2f1605f1 | |||
| 48b5c167bf | |||
| 08a0a36dfd | |||
| d135c31ca0 | |||
| dce68221ad | |||
| 93273bd470 | |||
| 92f7c11999 | |||
| 024ce8e73c | |||
| 7902389ef1 | |||
| 1e9ab2f805 | |||
| 0550212b64 | |||
| c7b6ca67a2 | |||
| 9dae2de2fa | |||
| 968593106e | |||
| 302cb0130d | |||
| 89efaa790f | |||
| 60f0e62c23 | |||
| f113e2ef31 | |||
| 39923d6617 | |||
| 72be443414 | |||
| 392e8060ba | |||
| 8c01b0f6c0 | |||
| b984475e49 | |||
| 4f114ea33c | |||
| 5b8a9c0108 | |||
| ee6500ac65 | |||
| 3b2a1c3f25 | |||
| 4d87359aca | |||
| c37c1ff812 | |||
| 1812a2e9ad | |||
| ccc02f41bf | |||
| eaf10c70b7 | |||
| 06f42dd9cb | |||
| 1d6ff73aad | |||
| 700a6fe643 | |||
| 0a7432b059 | |||
| b369fda1d9 | |||
| c49c35cfbd | |||
| fb4742e165 | |||
| fce45b93a2 |
@@ -1,36 +1,65 @@
|
|||||||
# Makefile for GNU make
|
# Makefile for GNU make
|
||||||
|
|
||||||
|
include Makefile.dep
|
||||||
|
|
||||||
ifndef CXX
|
|
||||||
CXX = g++
|
ifeq ($(OSTYPE), FreeBSD)
|
||||||
|
CXX = clang++
|
||||||
|
else
|
||||||
|
CXX = g++-4.8
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ifndef CXXFLAGS
|
ifndef CXXFLAGS
|
||||||
CXXFLAGS = -fPIC -Wall -pedantic -O2 -I/usr/local/include -I/home/tomek/roboczy/winix -I/home/tomek/roboczy/ezc/src -L/usr/local/lib -DEZC_USE_WINIX_LOGGER -DEZC_HAS_SPECIAL_STREAM
|
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
|
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
|
||||||
|
CXXWINIXINCLUDEFLAGS = -I../../winix -I../../../winix -I../../ezc/src -I../../../ezc/src -I../../tito/src -I../../../tito/src -I../../pikotools -I../../../pikotools
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifndef LDFLAGS
|
||||||
|
LDFLAGS = -L/usr/local/lib
|
||||||
|
endif
|
||||||
|
|
||||||
|
# this macro is used in ezc's Makefile
|
||||||
|
EZC_USE_WINIX_LOGGER = yes
|
||||||
|
|
||||||
|
|
||||||
|
# for make install
|
||||||
|
winix_install_dir = /usr/local/winix
|
||||||
|
|
||||||
|
|
||||||
export CXX
|
export CXX
|
||||||
export CXXFLAGS
|
export CXXFLAGS
|
||||||
|
export CXXWINIXINCLUDEFLAGS
|
||||||
|
export LDFLAGS
|
||||||
|
export EZC_USE_WINIX_LOGGER
|
||||||
|
|
||||||
|
|
||||||
all: winix.so plugins winix
|
all: winix.so plugins winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
winix.so: FORCE
|
winix.so: $(winix.src.files)
|
||||||
@cd core ; $(MAKE) -e
|
@cd core ; $(MAKE) -e
|
||||||
@cd db ; $(MAKE) -e
|
@cd db ; $(MAKE) -e
|
||||||
@cd functions ; $(MAKE) -e
|
@cd functions ; $(MAKE) -e
|
||||||
@cd notify ; $(MAKE) -e
|
@cd notify ; $(MAKE) -e
|
||||||
@cd templates ; $(MAKE) -e
|
@cd templates ; $(MAKE) -e
|
||||||
@cd ../ezc/src ; $(MAKE) -e
|
@cd ../ezc/src ; $(MAKE) -e
|
||||||
$(CXX) -shared -o winix.so $(CXXFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a -lfcgi -lpq -lz -lpthread -lfetch
|
@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 -lpthread -lcurl -Wl,-no-whole-archive
|
||||||
|
|
||||||
|
|
||||||
winix: FORCE
|
winix: winix.so $(winix.src.files)
|
||||||
@cd main ; $(MAKE) -e
|
@cd main ; $(MAKE) -e
|
||||||
# use the full path with winix.so
|
$(CXX) -o winix $(CXXFLAGS) $(LDFLAGS) main/*.o winix.so -lfcgi
|
||||||
$(CXX) -o winix $(CXXFLAGS) main/*.o /home/tomek/roboczy/winix/winix.so
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +68,9 @@ plugins: FORCE
|
|||||||
@cd plugins/thread ; $(MAKE) -e
|
@cd plugins/thread ; $(MAKE) -e
|
||||||
@cd plugins/ticket ; $(MAKE) -e
|
@cd plugins/ticket ; $(MAKE) -e
|
||||||
@cd plugins/gallery ; $(MAKE) -e
|
@cd plugins/gallery ; $(MAKE) -e
|
||||||
@cd plugins/groupitem ; $(MAKE) -e
|
@cd plugins/group ; $(MAKE) -e
|
||||||
|
@cd plugins/menu ; $(MAKE) -e
|
||||||
|
@cd plugins/export ; $(MAKE) -e
|
||||||
|
|
||||||
|
|
||||||
FORCE:
|
FORCE:
|
||||||
@@ -55,8 +86,12 @@ clean:
|
|||||||
@cd plugins/thread ; $(MAKE) -e clean
|
@cd plugins/thread ; $(MAKE) -e clean
|
||||||
@cd plugins/ticket ; $(MAKE) -e clean
|
@cd plugins/ticket ; $(MAKE) -e clean
|
||||||
@cd plugins/gallery ; $(MAKE) -e clean
|
@cd plugins/gallery ; $(MAKE) -e clean
|
||||||
@cd plugins/groupitem ; $(MAKE) -e clean
|
@cd plugins/group ; $(MAKE) -e clean
|
||||||
|
@cd plugins/menu ; $(MAKE) -e clean
|
||||||
|
@cd plugins/export ; $(MAKE) -e clean
|
||||||
@cd ../ezc/src ; $(MAKE) -e clean
|
@cd ../ezc/src ; $(MAKE) -e clean
|
||||||
|
@cd ../tito/src ; $(MAKE) -e clean
|
||||||
|
@cd ../pikotools ; $(MAKE) -e clean
|
||||||
@cd main ; $(MAKE) -e clean
|
@cd main ; $(MAKE) -e clean
|
||||||
rm -f winix.so
|
rm -f winix.so
|
||||||
rm -f winix
|
rm -f winix
|
||||||
@@ -75,32 +110,49 @@ depend:
|
|||||||
@cd plugins/thread ; $(MAKE) -e depend
|
@cd plugins/thread ; $(MAKE) -e depend
|
||||||
@cd plugins/ticket ; $(MAKE) -e depend
|
@cd plugins/ticket ; $(MAKE) -e depend
|
||||||
@cd plugins/gallery ; $(MAKE) -e depend
|
@cd plugins/gallery ; $(MAKE) -e depend
|
||||||
@cd plugins/groupitem ; $(MAKE) -e depend
|
@cd plugins/group ; $(MAKE) -e depend
|
||||||
|
@cd plugins/menu ; $(MAKE) -e depend
|
||||||
|
@cd plugins/export ; $(MAKE) -e depend
|
||||||
@cd ../ezc/src ; $(MAKE) -e depend
|
@cd ../ezc/src ; $(MAKE) -e depend
|
||||||
|
@cd ../tito/src ; $(MAKE) -e depend
|
||||||
|
@cd ../pikotools ; $(MAKE) -e depend
|
||||||
@cd main ; $(MAKE) -e depend
|
@cd main ; $(MAKE) -e depend
|
||||||
|
echo -n "winix.src.files = " > Makefile.dep
|
||||||
|
find -E . -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||||
|
find -E ../ezc/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||||
|
find -E ../tito/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||||
|
find -E ../pikotools -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
# binaries
|
# installing binaries
|
||||||
mkdir -p /usr/local/winix/bin
|
rm -Rf $(winix_install_dir)/bin
|
||||||
cp winix.so /usr/local/winix/bin
|
mkdir -p $(winix_install_dir)/bin
|
||||||
# use the full path with winix.so (we have to recompile winix with a new path to winix.so)
|
cp winix $(winix_install_dir)/bin
|
||||||
$(CXX) -o /usr/local/winix/bin/winix $(CXXFLAGS) main/*.o /usr/local/winix/bin/winix.so
|
cp winix.so $(winix_install_dir)/bin
|
||||||
|
# etc configs
|
||||||
|
rm -Rf $(winix_install_dir)/etc
|
||||||
|
mkdir -p $(winix_install_dir)/etc
|
||||||
|
cp -rf etc/* $(winix_install_dir)/etc/
|
||||||
# html templates
|
# html templates
|
||||||
mkdir -p /usr/local/winix/html
|
rm -Rf $(winix_install_dir)/html
|
||||||
cp -rf html/ /usr/local/winix/html/
|
mkdir -p $(winix_install_dir)/html
|
||||||
find /usr/local/winix/html/ -type d -name ".svn" | xargs -I foo rm -fr foo
|
cp -rf html/* $(winix_install_dir)/html/
|
||||||
# txt templates
|
# txt templates
|
||||||
mkdir -p /usr/local/winix/txt
|
rm -Rf $(winix_install_dir)/txt
|
||||||
cp -rf txt/ /usr/local/winix/txt/
|
mkdir -p $(winix_install_dir)/txt
|
||||||
find /usr/local/winix/txt/ -type d -name ".svn" | xargs -I foo rm -fr foo
|
cp -rf txt/* $(winix_install_dir)/txt/
|
||||||
# locales
|
# locales
|
||||||
mkdir -p /usr/local/winix/locale
|
rm -Rf $(winix_install_dir)/locale
|
||||||
cp -rf locale/ /usr/local/winix/locale/
|
mkdir -p $(winix_install_dir)/locale
|
||||||
find /usr/local/winix/locale/ -type d -name ".svn" | xargs -I foo rm -fr foo
|
cp -rf locale/* $(winix_install_dir)/locale/
|
||||||
# plugins
|
# plugins
|
||||||
mkdir -p /usr/local/winix/plugins
|
rm -Rf $(winix_install_dir)/plugins
|
||||||
find plugins/ -name "*.so" | xargs -I foo cp foo /usr/local/winix/plugins/
|
mkdir -p $(winix_install_dir)/plugins
|
||||||
# removed provileges for others
|
find plugins/ -name "*.so" | xargs -I foo cp foo $(winix_install_dir)/plugins/
|
||||||
find /usr/local/winix -exec chmod o-r,o-x,o-w "{}" "+"
|
# deleting subversion directories
|
||||||
|
find $(winix_install_dir) -type d -name ".svn" | xargs -I foo rm -fr foo
|
||||||
|
# removing privileges for others
|
||||||
|
find $(winix_install_dir) -exec chmod o-r,o-x,o-w "{}" "+"
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
+2
-2
@@ -5,11 +5,11 @@ all: $(o)
|
|||||||
|
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
$(CXX) -c $(CXXFLAGS) $<
|
$(CXX) -c $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) $<
|
||||||
|
|
||||||
|
|
||||||
depend:
|
depend:
|
||||||
makedepend -Y. -I.. -I../../ezc/src -f- *.cpp > Makefile.dep
|
makedepend -Y. $(CXXWINIXINCLUDEFLAGS) -f- *.cpp > Makefile.dep
|
||||||
echo -n "o = " > Makefile.o.dep
|
echo -n "o = " > Makefile.o.dep
|
||||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||||
|
|
||||||
|
|||||||
+1093
-383
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1 +1 @@
|
|||||||
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o confparser.o crypt.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o item.o lastcontainer.o loadavg.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 synchro.o system.o textstream.o thumb.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 sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o
|
||||||
|
|||||||
+49
-24
@@ -1,13 +1,46 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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 <wchar.h>
|
||||||
#include "acceptbaseparser.h"
|
#include "acceptbaseparser.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -27,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()
|
void AcceptBaseParser::ReadParameter()
|
||||||
{
|
{
|
||||||
param.clear();
|
param.clear();
|
||||||
|
|
||||||
SkipWhite();
|
SkipWhite();
|
||||||
|
|
||||||
while( *text!=0 && *text!=',' && *text!=';' )
|
while( *text!=0 && *text!=',' && *text!=';' )
|
||||||
@@ -57,14 +73,13 @@ void AcceptBaseParser::ReadParameter()
|
|||||||
++text;
|
++text;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveWhiteFromEnd(param);
|
TrimWhite(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AcceptBaseParser::ReadQ()
|
void AcceptBaseParser::ReadQ()
|
||||||
{
|
{
|
||||||
q = 1.0;
|
q = 1.0;
|
||||||
|
|
||||||
SkipWhite();
|
SkipWhite();
|
||||||
|
|
||||||
if( *text != ';' )
|
if( *text != ';' )
|
||||||
@@ -82,7 +97,7 @@ void AcceptBaseParser::ReadQ()
|
|||||||
++text; // skipping '='
|
++text; // skipping '='
|
||||||
|
|
||||||
SkipWhite();
|
SkipWhite();
|
||||||
q = strtod(text, (char**)&text);
|
q = wcstod(text, (wchar_t**)&text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +111,7 @@ void AcceptBaseParser::SkipParam()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AcceptBaseParser::Parse(const char * str)
|
void AcceptBaseParser::Parse(const wchar_t * str)
|
||||||
{
|
{
|
||||||
text = str;
|
text = str;
|
||||||
Init();
|
Init();
|
||||||
@@ -111,3 +126,13 @@ void AcceptBaseParser::Parse(const char * str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AcceptBaseParser::Parse(const std::wstring & str)
|
||||||
|
{
|
||||||
|
Parse(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+42
-9
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_acceptbaseparser
|
||||||
@@ -13,35 +38,43 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// sample (you must create your own class derived from this one):
|
// 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
|
class AcceptBaseParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Parse(const char * str);
|
void Parse(const wchar_t * str);
|
||||||
|
void Parse(const std::wstring & str);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
virtual void Init() {} ;
|
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);
|
bool IsWhite(int c);
|
||||||
void SkipWhite();
|
void SkipWhite();
|
||||||
void RemoveWhiteFromEnd(std::string & str);
|
|
||||||
void ReadParameter();
|
void ReadParameter();
|
||||||
void ReadQ();
|
void ReadQ();
|
||||||
void SkipParam();
|
void SkipParam();
|
||||||
|
|
||||||
|
|
||||||
const char * text;
|
const wchar_t * text;
|
||||||
std::string param;
|
std::wstring param;
|
||||||
double q;
|
double q;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_acceptencodingparser
|
||||||
@@ -14,6 +39,11 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AcceptEncodingParser : public AcceptBaseParser
|
class AcceptEncodingParser : public AcceptBaseParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -30,7 +60,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ParseAndLog(const char * str)
|
void ParseAndLog(const wchar_t * str)
|
||||||
{
|
{
|
||||||
Parse(str);
|
Parse(str);
|
||||||
|
|
||||||
@@ -54,6 +84,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ParseAndLog(const std::wstring & str)
|
||||||
|
{
|
||||||
|
ParseAndLog(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
@@ -63,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;
|
accept_deflate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( param=="gzip" && q!=0.0 )
|
if( param == L"gzip" && q!=0.0 )
|
||||||
{
|
{
|
||||||
accept_gzip = true;
|
accept_gzip = true;
|
||||||
}
|
}
|
||||||
@@ -82,4 +118,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1009
-258
File diff suppressed because it is too large
Load Diff
+93
-30
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_app
|
||||||
@@ -30,7 +55,6 @@
|
|||||||
#include "functions/functions.h"
|
#include "functions/functions.h"
|
||||||
#include "templates/templates.h"
|
#include "templates/templates.h"
|
||||||
#include "compress.h"
|
#include "compress.h"
|
||||||
#include "getparser.h"
|
|
||||||
#include "postparser.h"
|
#include "postparser.h"
|
||||||
#include "cookieparser.h"
|
#include "cookieparser.h"
|
||||||
#include "postmultiparser.h"
|
#include "postmultiparser.h"
|
||||||
@@ -38,6 +62,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
@@ -82,24 +111,16 @@ public:
|
|||||||
model
|
model
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// file system
|
// ...
|
||||||
System system;
|
System system;
|
||||||
|
|
||||||
// false at the beginning
|
|
||||||
// !! moze to do loggera dac?
|
|
||||||
bool stdout_is_closed;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
controllers
|
|
||||||
(note that the whole app object is actually a controller too)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// functions (ls, cat, emacs, ...)
|
// functions (ls, cat, emacs, ...)
|
||||||
Functions functions;
|
Functions functions;
|
||||||
|
|
||||||
|
// false at the beginning
|
||||||
|
// !! IMPROVE ME moze to do loggera dac?
|
||||||
|
bool stdout_is_closed;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
view
|
view
|
||||||
@@ -117,64 +138,106 @@ private:
|
|||||||
h_403
|
h_403
|
||||||
};
|
};
|
||||||
|
|
||||||
GetParser get_parser;
|
|
||||||
PostParser post_parser;
|
PostParser post_parser;
|
||||||
PostMultiParser post_multi_parser;
|
PostMultiParser post_multi_parser;
|
||||||
CookieParser cookie_parser;
|
CookieParser cookie_parser;
|
||||||
AcceptEncodingParser accept_encoding_parser;
|
AcceptEncodingParser accept_encoding_parser;
|
||||||
Compress compress;
|
Compress compress;
|
||||||
std::wstring clean_html, html_with_debug;
|
|
||||||
FCGX_Request fcgi_request;
|
FCGX_Request fcgi_request;
|
||||||
int fcgi_socket;
|
int fcgi_socket;
|
||||||
Synchro synchro;
|
Synchro synchro;
|
||||||
pthread_t signal_thread;
|
pthread_t signal_thread;
|
||||||
std::string url_to_fetch_on_exit;
|
std::string url_to_fetch_on_exit;
|
||||||
std::string source_a;
|
std::string send_data_buf;
|
||||||
|
PT::SpaceToJSON json_generic_serializer;
|
||||||
|
TextStream<std::wstring> json_out_stream;
|
||||||
|
std::string aheader_name, aheader_value;
|
||||||
|
std::wstring html_filtered;
|
||||||
|
std::string output_8bit;
|
||||||
|
BinaryPage compressed_output;
|
||||||
|
|
||||||
|
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 ProcessRequestThrow();
|
||||||
void ProcessRequest();
|
void ProcessRequest();
|
||||||
|
void BaseUrlRedirect(int code, bool add_subdomain);
|
||||||
bool BaseUrlRedirect();
|
bool BaseUrlRedirect();
|
||||||
|
void CheckIfNeedSSLredirect();
|
||||||
|
void SetLocale();
|
||||||
|
void CheckPostRedirect();
|
||||||
void MakePage();
|
void MakePage();
|
||||||
void Make();
|
void Make();
|
||||||
void SaveSessionsIfNeeded(); // !! wywalic do menagera sesji??
|
void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji??
|
||||||
void LogAccess();
|
void LogAccess();
|
||||||
|
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
||||||
|
void CreateJSONAnswer();
|
||||||
|
|
||||||
void ReadRequest();
|
void ReadRequest();
|
||||||
|
void SendTextAnswer();
|
||||||
|
void SendBinaryAnswer();
|
||||||
void SendAnswer();
|
void SendAnswer();
|
||||||
|
|
||||||
void SetEnv(const char * & env, const char * name);
|
void LogEnvironmentVariables();
|
||||||
|
|
||||||
|
void SetEnv(const char * name, std::wstring & env);
|
||||||
void ReadEnvVariables();
|
void ReadEnvVariables();
|
||||||
void ReadGetPostVars();
|
void ReadEnvRemoteIP();
|
||||||
|
void ReadPostVars();
|
||||||
|
|
||||||
void CheckIE();
|
void CheckIE();
|
||||||
void CheckKonqueror();
|
void CheckKonqueror();
|
||||||
void CheckRequestMethod();
|
void CheckRequestMethod();
|
||||||
void CheckFCGIRole();
|
void CheckSSL();
|
||||||
|
void SetSubdomain();
|
||||||
|
|
||||||
|
|
||||||
|
Header GetHTTPStatusCode();
|
||||||
void PrepareSessionCookie();
|
void PrepareSessionCookie();
|
||||||
void AddDebugInfo(std::wstring & out);
|
void FilterContent();
|
||||||
void FilterCompressSend(bool compressing, int compress_encoding, const std::wstring & source_ref);
|
void SendHeaders();
|
||||||
void SendHeaders(bool compressing, int compress_encoding, Header header);
|
void SendCookies();
|
||||||
|
bool AddHeader(const wchar_t * name, const wchar_t * value);
|
||||||
|
bool AddHeader(const std::wstring & name, const std::wstring & value);
|
||||||
|
bool AddHeader(const wchar_t * name, const PT::WTextStream & value);
|
||||||
|
bool AddHeader(const std::wstring & name, const PT::WTextStream & value);
|
||||||
|
bool PrepareHeadersStaticCreateResource(PT::WTextStream & out_path);
|
||||||
|
void PrepareHeadersStatic();
|
||||||
|
void PrepareHeaderContentType();
|
||||||
|
void PrepareHeadersForbidden();
|
||||||
|
void PrepareHeadersRedirect();
|
||||||
|
void PrepareHeadersSendFile();
|
||||||
|
void PrepareHeadersCompression(int compress_encoding);
|
||||||
|
void PrepareHeadersNormal(Header header, size_t output_size);
|
||||||
|
void PrepareHeaders(bool compressing, int compress_encoding, Header header, size_t output_size);
|
||||||
int SelectDeflateVersion();
|
int SelectDeflateVersion();
|
||||||
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
||||||
bool CanSendContent(Header header);
|
bool CanSendContent();
|
||||||
|
void ClearAfterRequest();
|
||||||
|
|
||||||
void LogUser(const char * msg, uid_t id);
|
void LogUser(const char * msg, uid_t id);
|
||||||
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
|
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
|
||||||
void LogUsers();
|
void LogUsers();
|
||||||
void LogEffectiveGroups(std::vector<gid_t> & tab);
|
void LogEffectiveGroups(std::vector<gid_t> & tab);
|
||||||
void LogGroups();
|
void LogGroups();
|
||||||
bool DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool additional_groups);
|
|
||||||
|
|
||||||
static void * SpecialThreadForSignals(void*);
|
static void * SpecialThreadForSignals(void*);
|
||||||
|
static size_t FetchPageOnExitCurlCallback(char *ptr, size_t size, size_t nmemb, void *userdata);
|
||||||
void FetchPageOnExit();
|
void FetchPageOnExit();
|
||||||
|
|
||||||
void CreateStaticTree();
|
void CreateStaticTree();
|
||||||
|
|
||||||
// !! dodac do session managera?
|
// !! IMPROVE ME
|
||||||
|
// !! move to the session manager?
|
||||||
time_t last_sessions_save;
|
time_t last_sessions_save;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+43
-4
@@ -1,15 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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 <errno.h>
|
||||||
#include "basethread.h"
|
#include "basethread.h"
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
||||||
@@ -21,6 +49,7 @@ BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BaseThread::SetSynchro(Synchro * psynchro)
|
void BaseThread::SetSynchro(Synchro * psynchro)
|
||||||
{
|
{
|
||||||
synchro = psynchro;
|
synchro = psynchro;
|
||||||
@@ -34,6 +63,12 @@ void BaseThread::Mode(int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pthread_t BaseThread::ThreadId()
|
||||||
|
{
|
||||||
|
return thread_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BaseThread::Lock()
|
bool BaseThread::Lock()
|
||||||
{
|
{
|
||||||
@@ -230,3 +265,7 @@ pthread_attr_t attr;
|
|||||||
return res == 0;
|
return res == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+47
-10
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_basethread
|
||||||
@@ -14,6 +39,11 @@
|
|||||||
#include "synchro.h"
|
#include "synchro.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseThread
|
class BaseThread
|
||||||
{
|
{
|
||||||
@@ -36,20 +66,19 @@ public:
|
|||||||
// starting the second thread
|
// starting the second thread
|
||||||
bool StartThread();
|
bool StartThread();
|
||||||
|
|
||||||
|
|
||||||
|
// virtual methods which should/can be inherited by your class
|
||||||
|
// the methods will be called from the other thread
|
||||||
|
|
||||||
// wake up the second thread
|
// wake up the second thread
|
||||||
// (if it waits for the signal)
|
// (if it waits for the signal)
|
||||||
// you should use it with: synchro->Lock() and Unlock()
|
// you should use it with: synchro->Lock() and Unlock()
|
||||||
// if the thread doesn't wait on a signal then nothing is done
|
// if the thread doesn't wait on a signal then nothing is done
|
||||||
void WakeUpThread();
|
virtual void WakeUpThread();
|
||||||
|
|
||||||
// waiting until the thread exits
|
// waiting until the thread exits
|
||||||
// you should call WakeUpThread() before
|
// you should call WakeUpThread() before
|
||||||
void WaitForThread();
|
virtual void WaitForThread();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// virtual methods which should/can be inherited by your class
|
|
||||||
// the methods will be called from the other thread
|
|
||||||
|
|
||||||
// initialize the thread
|
// initialize the thread
|
||||||
// (global objects are locked)
|
// (global objects are locked)
|
||||||
@@ -63,6 +92,11 @@ public:
|
|||||||
// it's called only if Init() returned true
|
// it's called only if Init() returned true
|
||||||
virtual void Uninit() {}
|
virtual void Uninit() {}
|
||||||
|
|
||||||
|
// returns the thread id
|
||||||
|
// this identifier is set by StartThread() metdhod
|
||||||
|
pthread_t ThreadId();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -116,6 +150,9 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+37
-3
@@ -1,15 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "bbcodeparser.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::Equal(const wchar_t * str1, const wchar_t * str2)
|
bool BBCODEParser::Equal(const wchar_t * str1, const wchar_t * str2)
|
||||||
@@ -590,3 +619,8 @@ void BBCODEParser::Uninit()
|
|||||||
if( has_open_ul_tag )
|
if( has_open_ul_tag )
|
||||||
(*out_string) += L"</ul>\n";
|
(*out_string) += L"</ul>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+35
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_bbcodeparser
|
||||||
@@ -13,6 +38,9 @@
|
|||||||
#include "htmlfilter.h"
|
#include "htmlfilter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BBCODEParser : public HTMLFilter
|
class BBCODEParser : public HTMLFilter
|
||||||
@@ -90,4 +118,8 @@ class BBCODEParser : public HTMLFilter
|
|||||||
bool has_open_li_tag; // has open html <li> tag
|
bool has_open_li_tag; // has open html <li> tag
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+157
-15
@@ -1,21 +1,51 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "compress.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Compress::Compress()
|
Compress::Compress()
|
||||||
{
|
{
|
||||||
buffer = 0;
|
buffer_in = 0;
|
||||||
|
buffer_out = 0;
|
||||||
buffer_max_len = 65536; // 64KB
|
buffer_max_len = 65536; // 64KB
|
||||||
ready_for_compress = false;
|
ready_for_compress = false;
|
||||||
compress_level = 6;
|
compress_level = 6;
|
||||||
@@ -27,8 +57,8 @@ Compress::Compress()
|
|||||||
|
|
||||||
Compress::~Compress()
|
Compress::~Compress()
|
||||||
{
|
{
|
||||||
if( buffer )
|
delete [] buffer_in;
|
||||||
delete [] buffer;
|
delete [] buffer_out;
|
||||||
|
|
||||||
if( raw_deflate_inited )
|
if( raw_deflate_inited )
|
||||||
deflateEnd(&strm_raw_deflate);
|
deflateEnd(&strm_raw_deflate);
|
||||||
@@ -43,17 +73,23 @@ Compress::~Compress()
|
|||||||
|
|
||||||
bool Compress::AllocateMemory()
|
bool Compress::AllocateMemory()
|
||||||
{
|
{
|
||||||
if( buffer )
|
if( buffer_in )
|
||||||
delete [] buffer;
|
delete [] buffer_in;
|
||||||
|
|
||||||
|
if( buffer_out )
|
||||||
|
delete [] buffer_out;
|
||||||
|
|
||||||
|
buffer_in = 0;
|
||||||
|
buffer_out = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buffer = new char[buffer_max_len];
|
buffer_in = new char[buffer_max_len];
|
||||||
|
buffer_out = new char[buffer_max_len];
|
||||||
}
|
}
|
||||||
catch(const std::bad_alloc &)
|
catch(const std::bad_alloc &)
|
||||||
{
|
{
|
||||||
log << log1 << "Compress: can't allocate memory" << logend;
|
log << log1 << "Compress: can't allocate memory" << logend;
|
||||||
buffer = 0;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +169,6 @@ int Compress::Init(int compress_level_)
|
|||||||
{
|
{
|
||||||
compress_level = compress_level_;
|
compress_level = compress_level_;
|
||||||
|
|
||||||
if( buffer == 0 )
|
|
||||||
if( !AllocateMemory() )
|
if( !AllocateMemory() )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -147,7 +182,9 @@ return 0;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Compress::MakeCompress(z_stream & strm, const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding)
|
|
||||||
|
|
||||||
|
int Compress::MakeCompress(z_stream & strm, const char * source, size_t source_len, BinaryPage & out_stream, int encoding)
|
||||||
{
|
{
|
||||||
int ret, flush;
|
int ret, flush;
|
||||||
size_t have;
|
size_t have;
|
||||||
@@ -163,7 +200,7 @@ size_t have;
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
strm.avail_out = buffer_max_len;
|
strm.avail_out = buffer_max_len;
|
||||||
strm.next_out = (Bytef*)buffer;
|
strm.next_out = (Bytef*)buffer_out;
|
||||||
ret = deflate(&strm, flush);
|
ret = deflate(&strm, flush);
|
||||||
|
|
||||||
if( ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR )
|
if( ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR )
|
||||||
@@ -174,7 +211,70 @@ size_t have;
|
|||||||
|
|
||||||
have = buffer_max_len - strm.avail_out;
|
have = buffer_max_len - strm.avail_out;
|
||||||
last_out_size += have;
|
last_out_size += have;
|
||||||
FCGX_PutStr(buffer, have, out_stream);
|
out_stream.write(buffer_out, have);
|
||||||
|
}
|
||||||
|
while( strm.avail_out == 0 );
|
||||||
|
|
||||||
|
if( strm.avail_in != 0 )
|
||||||
|
{
|
||||||
|
log << log1 << "Compress: problem with deflate() - not all input is used" << logend;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while( flush != Z_FINISH );
|
||||||
|
|
||||||
|
|
||||||
|
if( ret != Z_STREAM_END )
|
||||||
|
{
|
||||||
|
log << log1 << "Compress: problem with deflate() - stream not complete" << logend;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Compress::CopyToInputBuffer(BinaryPage::const_iterator & i, size_t len)
|
||||||
|
{
|
||||||
|
for(size_t a=0 ; a<len ; ++a, ++i)
|
||||||
|
buffer_in[a] = *i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// new way
|
||||||
|
int Compress::MakeCompress(z_stream & strm, const BinaryPage & page, BinaryPage & out, int encoding)
|
||||||
|
{
|
||||||
|
int ret, flush;
|
||||||
|
size_t have;
|
||||||
|
BinaryPage::const_iterator i = page.begin();
|
||||||
|
|
||||||
|
size_t source_len = page.size();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
strm.avail_in = (source_len > buffer_max_len) ? buffer_max_len : source_len;
|
||||||
|
source_len -= strm.avail_in;
|
||||||
|
flush = (source_len == 0) ? Z_FINISH : Z_NO_FLUSH;
|
||||||
|
strm.next_in = (Bytef*)buffer_in;
|
||||||
|
CopyToInputBuffer(i, strm.avail_in);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
strm.avail_out = buffer_max_len;
|
||||||
|
strm.next_out = (Bytef*)buffer_out;
|
||||||
|
ret = deflate(&strm, flush);
|
||||||
|
|
||||||
|
if( ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR )
|
||||||
|
{
|
||||||
|
log << log1 << "Compress: problem with deflate()" << logend;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
have = buffer_max_len - strm.avail_out;
|
||||||
|
last_out_size += have;
|
||||||
|
out.write(buffer_out, have);
|
||||||
}
|
}
|
||||||
while( strm.avail_out == 0 );
|
while( strm.avail_out == 0 );
|
||||||
|
|
||||||
@@ -263,12 +363,13 @@ void Compress::PutLog(size_t source_len, int encoding)
|
|||||||
3 - not inited (use Init() first)
|
3 - not inited (use Init() first)
|
||||||
100 - unknown
|
100 - unknown
|
||||||
*/
|
*/
|
||||||
int Compress::CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding)
|
int Compress::Compressing(const char * source, size_t source_len, BinaryPage & out_stream, int encoding)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
z_stream * pstrm;
|
z_stream * pstrm;
|
||||||
|
|
||||||
last_out_size = 0;
|
last_out_size = 0;
|
||||||
|
out_stream.clear();
|
||||||
|
|
||||||
if( !ready_for_compress )
|
if( !ready_for_compress )
|
||||||
{
|
{
|
||||||
@@ -276,6 +377,8 @@ z_stream * pstrm;
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !! CHECK ME
|
||||||
|
// it is correct to immediately return? what about headers in the compressed page?
|
||||||
if( source_len == 0 )
|
if( source_len == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -289,3 +392,42 @@ return ret;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
return:
|
||||||
|
0 - ok;
|
||||||
|
1 - can't allocate memory
|
||||||
|
2 - error during compressing
|
||||||
|
3 - not inited (use Init() first)
|
||||||
|
100 - unknown
|
||||||
|
*/
|
||||||
|
int Compress::Compressing(const BinaryPage & in, BinaryPage & out, int encoding)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
z_stream * pstrm;
|
||||||
|
|
||||||
|
last_out_size = 0;
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
if( !ready_for_compress )
|
||||||
|
{
|
||||||
|
log << log1 << "Compress: not ready yet" << logend;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// !! CHECK ME
|
||||||
|
// it is correct to immediately return? what about headers in the compressed page?
|
||||||
|
if( in.empty() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
pstrm = SelectStream(encoding);
|
||||||
|
ret = MakeCompress(*pstrm, in, out, encoding);
|
||||||
|
ResetStream(pstrm, encoding);
|
||||||
|
PutLog(in.size(), encoding);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+49
-8
@@ -1,18 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_compress
|
||||||
#define headerfile_winix_core_compress
|
#define headerfile_winix_core_compress
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fcgiapp.h>
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
#include "requesttypes.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Compress
|
class Compress
|
||||||
@@ -32,8 +62,9 @@ public:
|
|||||||
1 - deflate
|
1 - deflate
|
||||||
2 - gzip
|
2 - gzip
|
||||||
*/
|
*/
|
||||||
int CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding = 2);
|
int Compressing(const char * source, size_t source_len, BinaryPage & out_stream, int encoding = 2);
|
||||||
size_t last_out_size;
|
int Compressing(const BinaryPage & in, BinaryPage & out, int encoding = 2);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -42,14 +73,21 @@ private:
|
|||||||
bool InitDeflate();
|
bool InitDeflate();
|
||||||
bool InitGzip();
|
bool InitGzip();
|
||||||
|
|
||||||
int MakeCompress(z_stream & strm, const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding);
|
int MakeCompress(z_stream & strm, const char * source, size_t source_len, BinaryPage & out_stream, int encoding);
|
||||||
|
int MakeCompress(z_stream & strm, const BinaryPage & page, BinaryPage & out, int encoding);
|
||||||
z_stream * SelectStream(int encoding);
|
z_stream * SelectStream(int encoding);
|
||||||
void ResetStream(z_stream * pstrm, int encoding);
|
void ResetStream(z_stream * pstrm, int encoding);
|
||||||
void PutLog(size_t source_len, int encoding);
|
void PutLog(size_t source_len, int encoding);
|
||||||
|
void CopyToInputBuffer(BinaryPage::const_iterator & i, size_t len);
|
||||||
|
|
||||||
int compress_level;
|
int compress_level;
|
||||||
size_t buffer_max_len;
|
size_t buffer_max_len;
|
||||||
char * buffer;
|
|
||||||
|
// size of the last compressed page
|
||||||
|
size_t last_out_size;
|
||||||
|
|
||||||
|
char * buffer_in;
|
||||||
|
char * buffer_out;
|
||||||
z_stream strm_raw_deflate, strm_deflate, strm_gzip;
|
z_stream strm_raw_deflate, strm_deflate, strm_gzip;
|
||||||
bool raw_deflate_inited, deflate_inited, gzip_inited;
|
bool raw_deflate_inited, deflate_inited, gzip_inited;
|
||||||
bool ready_for_compress;
|
bool ready_for_compress;
|
||||||
@@ -57,4 +95,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+203
-118
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "config.h"
|
||||||
@@ -14,6 +39,10 @@
|
|||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Config::Config()
|
Config::Config()
|
||||||
{
|
{
|
||||||
@@ -31,20 +60,24 @@ void Config::ShowError()
|
|||||||
|
|
||||||
switch( parser.status )
|
switch( parser.status )
|
||||||
{
|
{
|
||||||
case ConfParser::ok:
|
case PT::SpaceParser::no_space:
|
||||||
|
log << log2 << "Config: space not set" << logend;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PT::SpaceParser::ok:
|
||||||
log << log2 << "Config: syntax ok" << logend;
|
log << log2 << "Config: syntax ok" << logend;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConfParser::cant_open_file:
|
case PT::SpaceParser::cant_open_file:
|
||||||
if( errors_to_stdout )
|
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;
|
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConfParser::syntax_error:
|
case PT::SpaceParser::syntax_error:
|
||||||
if( errors_to_stdout )
|
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;
|
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
||||||
break;
|
break;
|
||||||
@@ -69,11 +102,11 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
|||||||
log << log2 << "Config: reading a config file" << logend;
|
log << log2 << "Config: reading a config file" << logend;
|
||||||
|
|
||||||
parser.SplitSingle(true);
|
parser.SplitSingle(true);
|
||||||
parser.UTF8(true); // config is always read in UTF-8
|
parser.SetSpace(space);
|
||||||
ConfParser::Status status = parser.Parse( config_file );
|
|
||||||
|
|
||||||
|
PT::SpaceParser::Status status = parser.Parse(config_file);
|
||||||
|
|
||||||
if( status == ConfParser::ok )
|
if( status == PT::SpaceParser::ok )
|
||||||
{
|
{
|
||||||
AssignValues(stdout_is_closed);
|
AssignValues(stdout_is_closed);
|
||||||
SetAdditionalVariables();
|
SetAdditionalVariables();
|
||||||
@@ -93,33 +126,52 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
{
|
{
|
||||||
demonize = Bool(L"demonize", true);
|
demonize = Bool(L"demonize", true);
|
||||||
|
|
||||||
user = AText(L"user");
|
user = Text(L"user");
|
||||||
group = AText(L"group");
|
group = Text(L"group");
|
||||||
additional_groups = Bool(L"additional_groups", true);
|
additional_groups = Bool(L"additional_groups", true);
|
||||||
|
|
||||||
log_file = AText(L"log_file");
|
log_file = Text(L"log_file");
|
||||||
log_notify_file = AText(L"log_notify_file");
|
log_notify_file = Text(L"log_notify_file");
|
||||||
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
|
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_chmod = Int(L"fcgi_socket_chmod", 0770);
|
||||||
fcgi_socket_user = AText(L"fcgi_socket_user");
|
fcgi_socket_user = Text(L"fcgi_socket_user");
|
||||||
fcgi_socket_group = AText(L"fcgi_socket_group");
|
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_level = Int(L"log_level", 1);
|
||||||
log_request = Int(L"log_request", 1);
|
log_request = Int(L"log_request", 1);
|
||||||
log_save_each_line = Bool(L"log_save_each_line", false);
|
log_save_each_line = Bool(L"log_save_each_line", false);
|
||||||
|
log_time_zone_id = Size(L"log_time_zone_id", 34);
|
||||||
|
log_server_answer = Bool(L"log_server_answer", false);
|
||||||
log_stdout = Bool(L"log_stdout", false);
|
log_stdout = Bool(L"log_stdout", false);
|
||||||
log_db_query = Bool(L"log_db_query", false);
|
log_db_query = Bool(L"log_db_query", false);
|
||||||
log_plugin_call = Bool(L"log_plugin_call", false);
|
log_plugin_call = Bool(L"log_plugin_call", false);
|
||||||
log_post_value_size = Size(L"log_post_value_size", 80);
|
log_post_value_size = Size(L"log_post_value_size", 80);
|
||||||
|
log_env_variables = Bool(L"log_env_variables", false);
|
||||||
|
log_http_answer_headers = Bool(L"log_http_answer_headers", false);
|
||||||
|
|
||||||
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
|
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
|
||||||
|
|
||||||
upload_dir = Text(L"upload_dir");
|
upload_dir = Text(L"upload_dir");
|
||||||
|
common_dir = Text(L"common_dir");
|
||||||
|
NoLastSlash(upload_dir);
|
||||||
|
NoLastSlash(common_dir);
|
||||||
|
|
||||||
|
upload_group = Text(L"upload_group");
|
||||||
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
|
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
|
||||||
upload_files_chmod = Int(L"upload_files_chmod", 0640);
|
upload_files_chmod = Int(L"upload_files_chmod", 0640);
|
||||||
|
ListText(L"static_dirs", static_dirs);
|
||||||
|
dont_use_static_dirs = Bool(L"dont_use_static_dirs", false);
|
||||||
create_thumb = Bool(L"create_thumb", true);
|
create_thumb = Bool(L"create_thumb", true);
|
||||||
thumb_mode = Int(L"thumb_mode", 2);
|
thumb_mode = Int(L"thumb_mode", 2);
|
||||||
thumb_cx = Size(L"thumb_cx", 150);
|
thumb_cx = Size(L"thumb_cx", 150);
|
||||||
thumb_cy = Size(L"thumb_cy", 150);
|
thumb_cy = Size(L"thumb_cy", 150);
|
||||||
|
thumb_quality = Int(L"thumb_quality", 92);
|
||||||
|
image_resize = Bool(L"image_resize", true);
|
||||||
|
image_mode = Int(L"image_mode", 6);
|
||||||
|
image_cx = Size(L"image_cx", 1000);
|
||||||
|
image_cy = Size(L"image_cy", 800);
|
||||||
|
image_quality = Int(L"image_quality", 92);
|
||||||
convert_cmd = Text(L"convert_cmd", L"/usr/local/bin/convert");
|
convert_cmd = Text(L"convert_cmd", L"/usr/local/bin/convert");
|
||||||
|
|
||||||
templates_dir = Text(L"templates_dir");
|
templates_dir = Text(L"templates_dir");
|
||||||
@@ -131,18 +183,28 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
templates_index = Text(L"templates_index", L"index.html");
|
templates_index = Text(L"templates_index", L"index.html");
|
||||||
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
||||||
|
|
||||||
http_session_id_name = AText(L"http_session_id_name");
|
http_session_id_name = Text(L"http_session_id_name", L"session_id");
|
||||||
db_database = AText(L"db_database");
|
db_database = Text(L"db_database");
|
||||||
db_user = AText(L"db_user");
|
db_user = Text(L"db_user");
|
||||||
db_pass = AText(L"db_pass");
|
db_pass = Text(L"db_pass");
|
||||||
item_url_empty = Text(L"item_url_empty");
|
item_url_empty = Text(L"item_url_empty");
|
||||||
|
|
||||||
base_server = Text(L"base_server");
|
url_proto = Text(L"url_proto", L"http://");
|
||||||
|
url_ssl_proto = Text(L"url_ssl_proto", L"https://");
|
||||||
|
|
||||||
|
use_ssl = Bool(L"use_ssl", false);
|
||||||
|
use_ssl_static = Bool(L"use_ssl_static", false);
|
||||||
|
use_ssl_common = Bool(L"use_ssl_common", false);
|
||||||
|
use_ssl_only_for_logged_users = Bool(L"use_ssl_only_for_logged_users", true);
|
||||||
|
use_ssl_redirect_code = Int(L"use_ssl_redirect_code", 303);
|
||||||
|
|
||||||
base_url = Text(L"base_url");
|
base_url = Text(L"base_url");
|
||||||
base_url_static = Text(L"base_url_static");
|
base_url_static = Text(L"base_url_static");
|
||||||
base_url_common = Text(L"base_url_common");
|
base_url_common = Text(L"base_url_common");
|
||||||
|
|
||||||
NoLastSlash(base_server);
|
base_url_redirect = Bool(L"base_url_redirect", false);
|
||||||
|
base_url_redirect_code = Int(L"base_url_redirect_code", 301);
|
||||||
|
|
||||||
NoLastSlash(base_url);
|
NoLastSlash(base_url);
|
||||||
NoLastSlash(base_url_static);
|
NoLastSlash(base_url_static);
|
||||||
NoLastSlash(base_url_common);
|
NoLastSlash(base_url_common);
|
||||||
@@ -152,7 +214,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
|
|
||||||
session_max_idle = Int(L"session_max_idle", 10800); // 3h
|
session_max_idle = Int(L"session_max_idle", 10800); // 3h
|
||||||
session_remember_max_idle = Int(L"session_remember_max_idle", 16070400); // 3 months
|
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_max = Size(L"session_max", 1000000);
|
||||||
|
|
||||||
compression = Bool(L"compression", true);
|
compression = Bool(L"compression", true);
|
||||||
@@ -165,17 +227,18 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
html_filter_wrap_line = Int(L"html_filter_wrap_line", 110);
|
html_filter_wrap_line = Int(L"html_filter_wrap_line", 110);
|
||||||
html_filter_tabs = Size(L"html_filter_tabs", 2);
|
html_filter_tabs = Size(L"html_filter_tabs", 2);
|
||||||
html_filter_orphans = Bool(L"html_filter_orphans", true);
|
html_filter_orphans = Bool(L"html_filter_orphans", true);
|
||||||
html_filter_orphans_mode_str = AText(L"html_filter_orphans_mode_str", L"nbsp");
|
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 = Text(L"locale_dir");
|
||||||
locale_dir_default = Text(L"locale_dir_default");
|
locale_dir_default = Text(L"locale_dir_default");
|
||||||
locale_default = Text(L"locale_default");
|
locale_max_id = Size(L"locale_max_id", 100);
|
||||||
|
locale_default_id = Size(L"locale_default_id", 0);
|
||||||
ListText(L"locale_files", locale_files);
|
ListText(L"locale_files", locale_files);
|
||||||
|
|
||||||
title_separator = Text(L"title_separator", L" / ");
|
title_separator = Text(L"title_separator", L" / ");
|
||||||
|
|
||||||
http_header_send_file = Text(L"http_header_send_file", L"X-LIGHTTPD-send-file");
|
http_header_send_file = Text(L"http_header_send_file", L"X-LIGHTTPD-send-file");
|
||||||
debug_info = Bool(L"debug_info", false);
|
|
||||||
|
|
||||||
editors_html_safe_mode = Bool(L"editors_html_safe_mode", true);
|
editors_html_safe_mode = Bool(L"editors_html_safe_mode", true);
|
||||||
editors_html_safe_mode_skip_root = Bool(L"editors_html_safe_mode_skip_root", true);
|
editors_html_safe_mode_skip_root = Bool(L"editors_html_safe_mode_skip_root", true);
|
||||||
@@ -184,10 +247,6 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
NoLastSlash(plugins_dir);
|
NoLastSlash(plugins_dir);
|
||||||
ListText(L"plugins", plugin_file);
|
ListText(L"plugins", plugin_file);
|
||||||
|
|
||||||
time_zone_offset = Int(L"time_zone_offset", 0);
|
|
||||||
time_zone_offset_guest = Int(L"time_zone_offset_guest", 0);
|
|
||||||
|
|
||||||
utf8 = Bool(L"utf8", true);
|
|
||||||
symlinks_follow_max = Size(L"symlinks_follow_max", 20);
|
symlinks_follow_max = Size(L"symlinks_follow_max", 20);
|
||||||
|
|
||||||
ticket_form_prefix = Text(L"ticket_form_prefix", L"ticketparam");
|
ticket_form_prefix = Text(L"ticket_form_prefix", L"ticketparam");
|
||||||
@@ -200,6 +259,40 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
pass_rsa_private_key = Text(L"pass_rsa_private_key");
|
pass_rsa_private_key = Text(L"pass_rsa_private_key");
|
||||||
|
|
||||||
opensll_path = Text(L"opensll_path", L"/usr/bin/openssl");
|
opensll_path = Text(L"opensll_path", L"/usr/bin/openssl");
|
||||||
|
|
||||||
|
pattern_cacher_when_delete = Size(L"pattern_cacher_when_delete", 130);
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
account_need_email_verification = Bool(L"account_need_email_verification", true);
|
||||||
|
reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400);
|
||||||
|
|
||||||
|
time_zone_default_id = Size(L"time_zone_default_id", 34);
|
||||||
|
time_zone_max_id = Size(L"time_zone_max_id", 130);
|
||||||
|
|
||||||
|
etc_dir = Text(L"etc_dir", L"");
|
||||||
|
time_zones_file = Text(L"time_zones_file", L"time_zones.conf");
|
||||||
|
|
||||||
|
use_ban_list = Bool(L"use_ban_list", true);
|
||||||
|
ban_list_soft_max_size = Size(L"ban_list_soft_max_size", 50000);
|
||||||
|
ban_list_max_size = Size(L"ban_list_max_size", 51000);
|
||||||
|
ban_level_1_delay = Size(L"ban_level_1_delay", 1800);
|
||||||
|
ban_level_2_delay = Size(L"ban_level_2_delay", 86400);
|
||||||
|
ban_level_3_delay = Size(L"ban_level_3_delay", 604800);
|
||||||
|
|
||||||
|
incorrect_login_min_time_between_get_post = Size(L"incorrect_login_min_time_between_get_post", 2);
|
||||||
|
incorrect_login_captcha_treshold = Size(L"incorrect_login_captcha_treshold", 3);
|
||||||
|
incorrect_login_cannot_login_mode = Int(L"incorrect_login_cannot_login_mode", 0);
|
||||||
|
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"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -208,53 +301,37 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
|
|
||||||
void Config::SetAdditionalVariables()
|
void Config::SetAdditionalVariables()
|
||||||
{
|
{
|
||||||
SetHttpHost(base_url, base_url_http_host);
|
if( html_filter_orphans_mode_str == L"160" )
|
||||||
|
|
||||||
if( html_filter_orphans_mode_str == "160" )
|
|
||||||
html_filter_orphans_mode = HTMLFilter::orphan_160space;
|
html_filter_orphans_mode = HTMLFilter::orphan_160space;
|
||||||
else
|
else
|
||||||
html_filter_orphans_mode = HTMLFilter::orphan_nbsp;
|
html_filter_orphans_mode = HTMLFilter::orphan_nbsp;
|
||||||
|
|
||||||
CheckLocale();
|
for(size_t i=0 ; i<static_dirs.size() ; ++i)
|
||||||
|
NoLastSlash(static_dirs[i]);
|
||||||
|
|
||||||
CheckPasswd();
|
CheckPasswd();
|
||||||
}
|
|
||||||
|
|
||||||
|
if( content_type_header < 0 || content_type_header > 2 )
|
||||||
|
content_type_header = 0;
|
||||||
|
|
||||||
|
if( locale_default_id > locale_max_id )
|
||||||
void Config::CheckLocale()
|
locale_default_id = locale_max_id;
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
if( locale_files.empty() )
|
if( locale_files.empty() )
|
||||||
locale_files.push_back(L"en");
|
locale_files.push_back(L"en");
|
||||||
|
|
||||||
if( locale_default.empty() )
|
upload_group_int = GetGroupId(upload_group);
|
||||||
locale_default = locale_files[0];
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<locale_files.size() ; ++i)
|
|
||||||
{
|
|
||||||
if( locale_files[i] == locale_default )
|
|
||||||
{
|
|
||||||
locale_default_index = i;
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !found )
|
|
||||||
{
|
|
||||||
// we have at least one item
|
|
||||||
locale_default = locale_files[0];
|
|
||||||
locale_default_index = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Config::CheckPasswd()
|
void Config::CheckPasswd()
|
||||||
{
|
{
|
||||||
switch(pass_type)
|
switch(pass_type)
|
||||||
{
|
{
|
||||||
case WINIX_CRYPT_HASH_PLAIN:
|
case WINIX_CRYPT_HASH_NONE:
|
||||||
case WINIX_CRYPT_HASH_MD4:
|
case WINIX_CRYPT_HASH_MD4:
|
||||||
case WINIX_CRYPT_HASH_MD5:
|
case WINIX_CRYPT_HASH_MD5:
|
||||||
case WINIX_CRYPT_HASH_SHA1:
|
case WINIX_CRYPT_HASH_SHA1:
|
||||||
@@ -270,135 +347,143 @@ void Config::CheckPasswd()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::SetHttpHost(const std::wstring & in, std::wstring & out)
|
|
||||||
{
|
|
||||||
const char http[] = "http://";
|
|
||||||
const char https[] = "https://";
|
|
||||||
size_t http_len = sizeof(http) / sizeof(char) - 1;
|
|
||||||
size_t https_len = sizeof(https) / sizeof(char) - 1;
|
|
||||||
|
|
||||||
if( IsSubString(http, in.c_str()) )
|
|
||||||
out = in.substr(http_len);
|
std::wstring & Config::Text(const wchar_t * name)
|
||||||
else
|
{
|
||||||
if( IsSubString(https, in.c_str()) )
|
return space.Text(name);
|
||||||
out = in.substr(https_len);
|
|
||||||
else
|
|
||||||
out.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::wstring Config::Text(const wchar_t * name)
|
std::wstring & Config::Text(const wchar_t * name, const wchar_t * def)
|
||||||
{
|
{
|
||||||
return parser.Text(name);
|
return space.Text(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
|
std::wstring & Config::Text(const std::wstring & name, const wchar_t * def)
|
||||||
{
|
{
|
||||||
return parser.Text(name, def);
|
return space.Text(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::wstring Config::Text(const std::wstring & name, const std::wstring & def)
|
|
||||||
{
|
|
||||||
return parser.Text(name, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string Config::AText(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return parser.AText(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string Config::AText(const wchar_t * name, const wchar_t * def)
|
|
||||||
{
|
|
||||||
return parser.AText(name, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string Config::AText(const std::wstring & name, const std::wstring & def)
|
|
||||||
{
|
|
||||||
return parser.AText(name, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Config::Int(const wchar_t * name)
|
int Config::Int(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return parser.Int(name);
|
return space.Int(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Config::Int(const wchar_t * name, int def)
|
int Config::Int(const wchar_t * name, int def)
|
||||||
{
|
{
|
||||||
return parser.Int(name, def);
|
return space.Int(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Config::Int(const std::wstring & name, int def)
|
int Config::Int(const std::wstring & name, int def)
|
||||||
{
|
{
|
||||||
return parser.Int(name, def);
|
return space.Int(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long Config::Long(const wchar_t * name)
|
||||||
|
{
|
||||||
|
return space.Long(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
long Config::Long(const wchar_t * name, long def)
|
||||||
|
{
|
||||||
|
return space.Long(name, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
long Config::Long(const std::wstring & name, long def)
|
||||||
|
{
|
||||||
|
return space.Long(name, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Config::Size(const wchar_t * name)
|
size_t Config::Size(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return parser.Size(name);
|
return space.Size(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t Config::Size(const wchar_t * name, size_t def)
|
size_t Config::Size(const wchar_t * name, size_t def)
|
||||||
{
|
{
|
||||||
return parser.Size(name, def);
|
return space.Size(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t Config::Size(const std::wstring & name, size_t def)
|
size_t Config::Size(const std::wstring & name, size_t def)
|
||||||
{
|
{
|
||||||
return parser.Size(name, def);
|
return space.Size(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::Bool(const wchar_t * name)
|
bool Config::Bool(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return parser.Bool(name);
|
return space.Bool(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::Bool(const wchar_t * name, bool def)
|
bool Config::Bool(const wchar_t * name, bool def)
|
||||||
{
|
{
|
||||||
return parser.Bool(name, def);
|
return space.Bool(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::Bool(const std::wstring & name, bool def)
|
bool Config::Bool(const std::wstring & name, bool def)
|
||||||
{
|
{
|
||||||
return parser.Bool(name, def);
|
return space.Bool(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
bool Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||||
{
|
{
|
||||||
parser.ListText(name, list);
|
return space.ListText(name, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
bool Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||||
{
|
{
|
||||||
parser.ListText(name, list);
|
return space.ListText(name, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::Print(std::ostream & out)
|
|
||||||
|
bool Config::HasValue(const wchar_t * name, const wchar_t * value)
|
||||||
{
|
{
|
||||||
parser.Print(out);
|
return space.HasValue(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::HasValue(const wchar_t * name, const std::wstring & value)
|
||||||
|
{
|
||||||
|
return space.HasValue(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::HasValue(const std::wstring & name, const wchar_t * value)
|
||||||
|
{
|
||||||
|
return space.HasValue(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::HasValue(const std::wstring & name, const std::wstring & value)
|
||||||
|
{
|
||||||
|
return space.HasValue(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Config::Print(std::wostream & out)
|
||||||
|
{
|
||||||
|
space.Serialize(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+391
-88
@@ -1,20 +1,50 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_config
|
||||||
#define headerfile_winix_core_config
|
#define headerfile_winix_core_config
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "confparser.h"
|
#include "space/spaceparser.h"
|
||||||
#include "htmlfilter.h"
|
#include "htmlfilter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
@@ -23,19 +53,19 @@ public:
|
|||||||
|
|
||||||
// name of the config file
|
// name of the config file
|
||||||
// this is the parameter passed to winix programm
|
// this is the parameter passed to winix programm
|
||||||
std::string config_file;
|
std::wstring config_file;
|
||||||
|
|
||||||
// start as a demon (in the background)
|
// start as a demon (in the background)
|
||||||
// default: true
|
// default: true
|
||||||
bool demonize;
|
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
|
// 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
|
// used only if winix is started as the root
|
||||||
std::string group;
|
std::wstring group;
|
||||||
|
|
||||||
// setting additional effective groups from /etc/group
|
// setting additional effective groups from /etc/group
|
||||||
// by using initgroups()
|
// by using initgroups()
|
||||||
@@ -44,27 +74,40 @@ public:
|
|||||||
bool additional_groups;
|
bool additional_groups;
|
||||||
|
|
||||||
// log file name, log file name for notifications (sending emails, etc)
|
// 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
|
// 1 - minimum
|
||||||
// 2 - (default)
|
// 2 - (default)
|
||||||
// 3 - maximum - all logs
|
// 3 - maximum - all logs
|
||||||
int log_level;
|
int log_level;
|
||||||
|
|
||||||
// logging to stdout too
|
// logging to stdout too
|
||||||
// only if demonize is 'false'
|
// this option is valid only if 'demonize' option is set to 'false'
|
||||||
// default: false
|
// default: false
|
||||||
bool log_stdout;
|
bool log_stdout;
|
||||||
|
|
||||||
// how many requests should be saved in the same time
|
// how many requests should be saved in the same time
|
||||||
|
// if you have a very busy server you can incrase this value
|
||||||
// default: 1
|
// default: 1
|
||||||
int log_request;
|
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
|
// default: false
|
||||||
bool log_save_each_line;
|
bool log_save_each_line;
|
||||||
|
|
||||||
|
// time zone identifier used in log messages
|
||||||
|
// this affects only the first line of logs (where there is IP address, request method etc)
|
||||||
|
// see time_zone_default_id below for more info
|
||||||
|
// default: 34 (Coordinated Universal Time UTC+00:00)
|
||||||
|
size_t log_time_zone_id;
|
||||||
|
|
||||||
|
// put to log what server is sending back to the client (html/json etc)
|
||||||
|
// default: false
|
||||||
|
bool log_server_answer;
|
||||||
|
|
||||||
// logging db queries
|
// logging db queries
|
||||||
|
// warning: use it only on a developer's server as it logs the hashes of passwords too
|
||||||
// default: false
|
// default: false
|
||||||
bool log_db_query;
|
bool log_db_query;
|
||||||
|
|
||||||
@@ -74,23 +117,39 @@ public:
|
|||||||
|
|
||||||
// how many characters in values should be logged from POST parameters
|
// how many characters in values should be logged from POST parameters
|
||||||
// default: 80
|
// default: 80
|
||||||
// set to 0 to turn off
|
// set to 0 to turn it off
|
||||||
size_t log_post_value_size;
|
size_t log_post_value_size;
|
||||||
|
|
||||||
// request delimiter in the log file, default "---------"
|
// request delimiter in the log file, default "---------"
|
||||||
std::wstring log_delimiter;
|
std::wstring log_delimiter;
|
||||||
|
|
||||||
|
// log environment variables (fastcgi environment)
|
||||||
|
bool log_env_variables;
|
||||||
|
|
||||||
|
// log headers (+cookies) which are returned to the client
|
||||||
|
// this is what winix has generated -- the web server can change or add other headers
|
||||||
|
// default: false
|
||||||
|
bool log_http_answer_headers;
|
||||||
|
|
||||||
// fast cgi: socket (unix domain)
|
// fast cgi: socket (unix domain)
|
||||||
std::string fcgi_socket;
|
std::wstring fcgi_socket;
|
||||||
|
|
||||||
// fast cgi: socket permissions
|
// fast cgi: socket permissions
|
||||||
|
// chmod and chown of the socket are set before winix drops privileges
|
||||||
int fcgi_socket_chmod;
|
int fcgi_socket_chmod;
|
||||||
|
|
||||||
// fast cgi: owner of the socket
|
// 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
|
// 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;
|
||||||
std::wstring templates_dir_default; // html templates from winix
|
std::wstring templates_dir_default; // html templates from winix
|
||||||
@@ -109,44 +168,46 @@ public:
|
|||||||
// default: index.html
|
// default: index.html
|
||||||
std::wstring templates_index;
|
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
|
// default: false
|
||||||
bool template_only_root_use_template_fun;
|
bool template_only_root_use_template_fun;
|
||||||
|
|
||||||
std::string db_database;
|
// the database name, user name and a password for the PostgreSQL database
|
||||||
std::string db_user;
|
std::wstring db_database;
|
||||||
std::string db_pass;
|
std::wstring db_user;
|
||||||
|
std::wstring db_pass;
|
||||||
|
|
||||||
std::string http_session_id_name;
|
// the name of the cookie which has the session identifier
|
||||||
|
std::wstring http_session_id_name;
|
||||||
// when the HOST_HTTP environment variable doesn't point into 'base_url' (the part 'http://' and the last slash is removed)
|
|
||||||
// the server will redirect into 'base_url' + 'REQUEST_URI'
|
|
||||||
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
|
|
||||||
bool base_url_redirect;
|
|
||||||
|
|
||||||
// string used in a place where is a user (or group) selected
|
// 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_user;
|
||||||
std::wstring priv_no_group;
|
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;
|
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
|
// this time is usually greater than session_max_idle
|
||||||
|
// default: 16070400 = 3 months
|
||||||
int session_remember_max_idle;
|
int session_remember_max_idle;
|
||||||
|
|
||||||
// this file is used when the program is starting and ending
|
// a file to which winix stores sessions info
|
||||||
std::string session_file;
|
// it is used when winix starts (boots) and quits
|
||||||
|
std::wstring session_file;
|
||||||
|
|
||||||
// how many sessions can be (zero turn off this checking)
|
// how many sessions can be (zero turn off this checking)
|
||||||
// default: 1000000 (one milion)
|
// default: 1000000 (one milion)
|
||||||
size_t session_max;
|
size_t session_max;
|
||||||
|
|
||||||
// allow the html output to be compressed
|
// allow the winix output to be compressed
|
||||||
// default: true
|
// default: true
|
||||||
bool compression;
|
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
|
// default: 512 bytes
|
||||||
size_t compression_page_min_size;
|
size_t compression_page_min_size;
|
||||||
|
|
||||||
@@ -173,12 +234,12 @@ public:
|
|||||||
bool html_filter_trim_white;
|
bool html_filter_trim_white;
|
||||||
|
|
||||||
// when long words should be broken (a space will be inserted)
|
// 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
|
// set zero to turn off
|
||||||
size_t html_filter_break_word;
|
size_t html_filter_break_word;
|
||||||
|
|
||||||
// when long lines should be broken (a new line character will be inserted)
|
// when long lines should be broken (a new line character will be inserted)
|
||||||
// default: 80
|
// default: 110
|
||||||
// set zero to turn off
|
// set zero to turn off
|
||||||
size_t html_filter_wrap_line;
|
size_t html_filter_wrap_line;
|
||||||
|
|
||||||
@@ -193,19 +254,61 @@ public:
|
|||||||
// orphans mode
|
// orphans mode
|
||||||
// either: "nbsp" or "160"
|
// either: "nbsp" or "160"
|
||||||
// default: "nbsp"
|
// default: "nbsp"
|
||||||
std::string html_filter_orphans_mode_str;
|
std::wstring html_filter_orphans_mode_str;
|
||||||
HTMLFilter::OrphanMode html_filter_orphans_mode;
|
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)
|
// 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;
|
std::wstring item_url_empty;
|
||||||
|
|
||||||
// maximum length of a file send by post multipart form
|
// maximum length of a file send by post multipart form
|
||||||
|
// default: 8388608 - 8MB
|
||||||
// 0 - not used
|
// 0 - not used
|
||||||
size_t post_file_max;
|
size_t post_file_max;
|
||||||
|
|
||||||
// directory for static files
|
// directory for static files
|
||||||
std::wstring upload_dir;
|
std::wstring upload_dir;
|
||||||
|
|
||||||
|
// additional static directories *not* managed by winix
|
||||||
|
// you can refer to this directories by using 'static' mount point
|
||||||
|
// e.g.
|
||||||
|
// let we say in the config you have:
|
||||||
|
// static_dirs = ("/home/a", "/home/b", "/home/c")
|
||||||
|
// and in /etc/fstab (in winix) you have such a line:
|
||||||
|
// "static /my/dir simplefs static(2)"
|
||||||
|
// above line in /etc/fstab means that when a user enters http://domain.com/my/dir/file.txt
|
||||||
|
// then "file.txt" will be taken from "/home/c/file.txt"
|
||||||
|
// this is useful for some javascript files which are protected from running from other domains
|
||||||
|
std::vector<std::wstring> static_dirs;
|
||||||
|
|
||||||
|
// sometimes you can have trouble when you have set an incorrect static path in /etc/fstab
|
||||||
|
// in such a case set dont_use_static_dirs to true
|
||||||
|
// and winix will behave as there are not any static directories
|
||||||
|
// so you can correct your mistake and then set this value to false
|
||||||
|
bool dont_use_static_dirs;
|
||||||
|
|
||||||
|
// static common directory
|
||||||
|
// this is a place where there are some common javascripts, images, css files
|
||||||
|
// winix is allowed to read some files from there
|
||||||
|
// for example ckeditor config, vim config and so on
|
||||||
|
// winix read it as a ezc template and put it into database
|
||||||
|
// 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)
|
// chmod of newly created directories (under upload_dir)
|
||||||
// default: 0750
|
// default: 0750
|
||||||
int upload_dirs_chmod;
|
int upload_dirs_chmod;
|
||||||
@@ -238,7 +341,36 @@ public:
|
|||||||
// default: 150
|
// default: 150
|
||||||
size_t thumb_cy;
|
size_t thumb_cy;
|
||||||
|
|
||||||
// the convert program
|
// quality of thumbnails
|
||||||
|
// from 0 (the worst) to 100 (the best)
|
||||||
|
// more info: http://www.imagemagick.org/script/command-line-options.php?ImageMagick=p4jtel7557hovd34ui3tgb54h6#quality
|
||||||
|
// default: 92
|
||||||
|
int thumb_quality;
|
||||||
|
|
||||||
|
// resizing images
|
||||||
|
// this not affects thumbnails
|
||||||
|
// default: true
|
||||||
|
bool image_resize;
|
||||||
|
|
||||||
|
// the mode of resizing an image
|
||||||
|
// the same as 'thumb_mode' above
|
||||||
|
// default: 6
|
||||||
|
int image_mode;
|
||||||
|
|
||||||
|
// width of images
|
||||||
|
// default: 1000
|
||||||
|
size_t image_cx;
|
||||||
|
|
||||||
|
// height of images
|
||||||
|
// default: 800
|
||||||
|
size_t image_cy;
|
||||||
|
|
||||||
|
// quality of an image (the same as in thumbnails)
|
||||||
|
// from 0 (the worst) to 100 (the best)
|
||||||
|
// default: 92
|
||||||
|
int image_quality;
|
||||||
|
|
||||||
|
// the convert program (ImageMagic) (for images and thumbnails)
|
||||||
// default: /usr/local/bin/convert
|
// default: /usr/local/bin/convert
|
||||||
std::wstring convert_cmd;
|
std::wstring convert_cmd;
|
||||||
|
|
||||||
@@ -252,24 +384,73 @@ public:
|
|||||||
// default: only one item: en
|
// default: only one item: en
|
||||||
std::vector<std::wstring> locale_files;
|
std::vector<std::wstring> locale_files;
|
||||||
|
|
||||||
// default locale
|
// a maximum value of a locale identifier
|
||||||
// default: the first item from locale_files
|
// default: 100 (maximum: 1000)
|
||||||
std::wstring locale_default;
|
// each locale files should have its own identifier (in "winix_locale_id" field)
|
||||||
|
// from zero to this value
|
||||||
|
size_t locale_max_id;
|
||||||
|
|
||||||
// default locale - index to locale_files
|
// locale for not logged users
|
||||||
// not available in config -- set automatically based on locale_default
|
// or for newly created accounts
|
||||||
size_t locale_default_index;
|
// default: 0
|
||||||
|
size_t locale_default_id;
|
||||||
|
|
||||||
// the main address of the server (e.g. someserver.com) (without the 'www' part etc)
|
// url protocol
|
||||||
std::wstring base_server;
|
// default: http://
|
||||||
|
std::wstring url_proto;
|
||||||
|
|
||||||
// the main address of the site (e.g. http://www.someserver.com)
|
// url protocol when using SSL
|
||||||
|
// default: https://
|
||||||
|
std::wstring url_ssl_proto;
|
||||||
|
|
||||||
|
// enables SSL
|
||||||
|
// it means this site should be accessed through SSL encrypted connection
|
||||||
|
// default: false
|
||||||
|
bool use_ssl;
|
||||||
|
|
||||||
|
// enables SSL for static content
|
||||||
|
// used mainly in templates, look at doc_base_url_static ezc function
|
||||||
|
// default: false
|
||||||
|
bool use_ssl_static;
|
||||||
|
|
||||||
|
// enables SSL for common content
|
||||||
|
// used mainly in templates, look at doc_base_url_common ezc function
|
||||||
|
// default: false
|
||||||
|
bool use_ssl_common;
|
||||||
|
|
||||||
|
// if SSL is enabled then if this is true the SSL will be used
|
||||||
|
// only for logged users
|
||||||
|
// default: true
|
||||||
|
bool use_ssl_only_for_logged_users;
|
||||||
|
|
||||||
|
// if current connection is without SSL and should be made through SSL
|
||||||
|
// or if is via SSL and should be done in plain text
|
||||||
|
// then we make a redirect
|
||||||
|
// default: 303
|
||||||
|
int use_ssl_redirect_code;
|
||||||
|
|
||||||
|
// when the HOST_HTTP environment variable is not equal to 'base_url'
|
||||||
|
// (the part 'http://' and the last slash is removed)
|
||||||
|
// the server will redirect into base_url + 'REQUEST_URI'
|
||||||
|
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
|
||||||
|
// set this option to false if you have multiple subdomains
|
||||||
|
// default: false
|
||||||
|
bool base_url_redirect;
|
||||||
|
|
||||||
|
// the HTTP code used during the base redirect
|
||||||
|
// default: 301
|
||||||
|
int base_url_redirect_code;
|
||||||
|
|
||||||
|
// the main address of the site (e.g. www.someserver.com)
|
||||||
|
// (without http:// prefix)
|
||||||
std::wstring base_url;
|
std::wstring base_url;
|
||||||
|
|
||||||
// static content not authorized by winix
|
// static content not authorized by winix
|
||||||
|
// (e.g. static.someserver.com)
|
||||||
std::wstring base_url_static;
|
std::wstring base_url_static;
|
||||||
|
|
||||||
// additional static server for common content (not authorized)
|
// additional static server for common content (not authorized)
|
||||||
|
// (e.g. common.someserver.com)
|
||||||
std::wstring base_url_common;
|
std::wstring base_url_common;
|
||||||
|
|
||||||
// separator used in <title> html tag
|
// separator used in <title> html tag
|
||||||
@@ -279,9 +460,6 @@ public:
|
|||||||
// default: X-LIGHTTPD-send-file
|
// default: X-LIGHTTPD-send-file
|
||||||
std::wstring http_header_send_file;
|
std::wstring http_header_send_file;
|
||||||
|
|
||||||
// prints additional information (in the end of the html page as a commentary)
|
|
||||||
bool debug_info;
|
|
||||||
|
|
||||||
// in editors (emacs, ckeditor,...) the html will be filtered and unsafe tags
|
// in editors (emacs, ckeditor,...) the html will be filtered and unsafe tags
|
||||||
// will be dropped (script, frame, etc.)
|
// will be dropped (script, frame, etc.)
|
||||||
// default: true;
|
// default: true;
|
||||||
@@ -292,20 +470,6 @@ public:
|
|||||||
// (if true the html code for root is not filtered)
|
// (if true the html code for root is not filtered)
|
||||||
bool editors_html_safe_mode_skip_root;
|
bool editors_html_safe_mode_skip_root;
|
||||||
|
|
||||||
// temporarily we do not support time zones per user
|
|
||||||
// there is one offset for all users
|
|
||||||
// default: 0
|
|
||||||
int time_zone_offset;
|
|
||||||
|
|
||||||
// time zone offset for guests (not logged users)
|
|
||||||
// default: 0
|
|
||||||
int time_zone_offset_guest;
|
|
||||||
|
|
||||||
// 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
|
// how many maximum symlinks can be followed
|
||||||
// (symlinks on directories as well)
|
// (symlinks on directories as well)
|
||||||
// default: 20
|
// default: 20
|
||||||
@@ -352,66 +516,205 @@ public:
|
|||||||
// !! once you set these keys don't change it any more (people wouldn't be allowed to login)
|
// !! once you set these keys don't change it any more (people wouldn't be allowed to login)
|
||||||
std::wstring pass_rsa_private_key;
|
std::wstring pass_rsa_private_key;
|
||||||
|
|
||||||
|
|
||||||
// path to 'openssl'
|
// path to 'openssl'
|
||||||
// default: /usr/bin/openssl
|
// default: /usr/bin/openssl
|
||||||
std::wstring opensll_path;
|
std::wstring opensll_path;
|
||||||
|
|
||||||
/*
|
// setting when we should delete patterns (EZC patterns)
|
||||||
*/
|
// we are deleting when we have more (or equal) patterns than 'when_delete'
|
||||||
|
// and then we are deleting 'how_many_del' patterns
|
||||||
|
// those patterns comes from items (pages) with executable bit set
|
||||||
|
size_t pattern_cacher_when_delete;
|
||||||
|
size_t pattern_cacher_how_many_delete;
|
||||||
|
|
||||||
|
// header "Content-Type" send to the client
|
||||||
|
// 0 - text/html - for HTML
|
||||||
|
// 1 - application/xhtml+xml - for XHTML 1.0
|
||||||
|
// 2 - application/xml - for XHTML 1.0 or for XHTML 1.1
|
||||||
|
// default: 0
|
||||||
|
// if utf8 is true then "; charset=UTF-8" will also be appended
|
||||||
|
int content_type_header;
|
||||||
|
|
||||||
|
// global umask
|
||||||
|
// it is used when an user doesn't have your own umask or for guests (not logged users)
|
||||||
|
// default: 0222
|
||||||
|
int umask;
|
||||||
|
|
||||||
|
// maximum number for elements through the whole template
|
||||||
|
// default: 50000
|
||||||
|
size_t ezc_max_elements;
|
||||||
|
|
||||||
|
// maximum number of each [for] loop
|
||||||
|
// default: 5000 (from ezc generator)
|
||||||
|
size_t ezc_max_loop_elements;
|
||||||
|
|
||||||
|
// how many output streams do we have in Request class
|
||||||
|
// default: 16 (64 maximum)
|
||||||
|
size_t ezc_out_streams_size;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// default: true
|
||||||
|
bool account_need_email_verification;
|
||||||
|
|
||||||
|
// when a user forgot his password we are able to send an email to him
|
||||||
|
// with a link to the page where there is a html form for setting a new password
|
||||||
|
// this option tells how long (in seconds) the link is valid
|
||||||
|
// default: 86400 (24 hours)
|
||||||
|
long reset_password_code_expiration_time;
|
||||||
|
|
||||||
|
// time zone identifier for not logged users
|
||||||
|
// or for newly created accounts
|
||||||
|
// those identifiers you can see in etc/time_zones.conf file
|
||||||
|
// or by using timezone winix function with 'a' parameter (timezone/a) (!!IMPROVE ME NOT IMPLEMENTED YET)
|
||||||
|
// default: 34 (Coordinated Universal Time UTC+00:00)
|
||||||
|
size_t time_zone_default_id;
|
||||||
|
|
||||||
|
// a maximum value of a time zone identifier
|
||||||
|
// time zones with an id greater than this will be skipped
|
||||||
|
// default: 130 (maximum: 1000)
|
||||||
|
size_t time_zone_max_id;
|
||||||
|
|
||||||
|
// a directory in which there are some config files
|
||||||
|
// used mainly when winix starts
|
||||||
|
// default: empty (means not for using)
|
||||||
|
std::wstring etc_dir;
|
||||||
|
|
||||||
|
// a file in etc_dir with time zones info
|
||||||
|
// default: time_zones.conf
|
||||||
|
// this is a Space structure with all time zones
|
||||||
|
// with following format:
|
||||||
|
// "tz_-12:00" ( # the name of a space is also a key to the locale files
|
||||||
|
// tz_offset_str = "-12:00" # a string representing the offset from UTC in a format: [+|-]HH:MM
|
||||||
|
// tz_has_dst = "false" # whether the time zone has daylight saving time (bool)
|
||||||
|
// tz_dst_offset = "" # offset of the daylight saving time
|
||||||
|
// tz_dst_start = "" # when the daylight saving time starts, format: MM:DD HH:MM:SS
|
||||||
|
// tz_dst_end = "") # when the daylight saving time ends, format: MM:DD HH:MM:SS
|
||||||
|
// each time zone is in a seperate space
|
||||||
|
std::wstring time_zones_file;
|
||||||
|
|
||||||
|
// turn on the IP ban mechanizm
|
||||||
|
// we have got three levels of bans (level 1, level 2, and the highest level 3)
|
||||||
|
// default: true
|
||||||
|
bool use_ban_list;
|
||||||
|
|
||||||
|
// the so called 'soft' max size
|
||||||
|
// read below description for explanation
|
||||||
|
// this is introduced to avoid deleting only one record from the ban list
|
||||||
|
// default: 50000
|
||||||
|
size_t ban_list_soft_max_size;
|
||||||
|
|
||||||
|
// this is the 'hard' max size of an IP's ban list
|
||||||
|
// if there are more records than this value
|
||||||
|
// then some of them will be removed (until the size will be ban_list_soft_max_size equal)
|
||||||
|
// this value should be a little larger from ban_list_soft_max_size
|
||||||
|
// default: 51000
|
||||||
|
size_t ban_list_max_size;
|
||||||
|
|
||||||
|
// delay in seconds of the first level ban
|
||||||
|
// default: 1800 (30 minutes)
|
||||||
|
// it means withing the next 30 minutes you see only 'you are banned...' message on your webbrowser
|
||||||
|
size_t ban_level_1_delay;
|
||||||
|
|
||||||
|
// delay in seconds of the second level ban
|
||||||
|
// default: 86400 (24 hours)
|
||||||
|
size_t ban_level_2_delay;
|
||||||
|
|
||||||
|
// delay in seconds of the third level ban
|
||||||
|
// default: 604800 (7 days)
|
||||||
|
size_t ban_level_3_delay;
|
||||||
|
|
||||||
|
// the minimum time in seconds which has to pass between the first GET request
|
||||||
|
// (showing your the login form) and the second POST request (which sends the
|
||||||
|
// login and password to the server)
|
||||||
|
// if the time is shorter then the login attempt is treated as incorrect
|
||||||
|
// (the same as if you provide incorrect user/password)
|
||||||
|
// default: 2
|
||||||
|
size_t incorrect_login_min_time_between_get_post;
|
||||||
|
|
||||||
|
// how many incorrect logins there must have been passed to display a captcha
|
||||||
|
// next to the login form
|
||||||
|
// default: 3
|
||||||
|
size_t incorrect_login_captcha_treshold;
|
||||||
|
|
||||||
|
// the way how we prevent to login if there are too many incorrect login attempts
|
||||||
|
// 0 - 'block logging' - do not show the login form in 'login' winix function
|
||||||
|
// (instead a warning message will be printed)
|
||||||
|
// 1 - add to ban list (warning: people from this IP will not be able to see your site and do anything)
|
||||||
|
// default: 0
|
||||||
|
int incorrect_login_cannot_login_mode;
|
||||||
|
|
||||||
|
// after how many incorrect login attempts we do the incorrect_login_cannot_login_mode action
|
||||||
|
// default: 20
|
||||||
|
size_t incorrect_login_cannot_login_treshold;
|
||||||
|
|
||||||
|
// used when incorrect_login_cannot_login_mode is zero
|
||||||
|
// it is the time which should be passed to allow logging
|
||||||
|
// default: 1800 (30 minutes)
|
||||||
|
// if incorrect_login_cannot_login_mode is one then ban_level_X_delay times
|
||||||
|
// 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;
|
||||||
|
|
||||||
// based on base_url
|
|
||||||
// set by SetAdditionalVariables()
|
|
||||||
// without the first part http:// (or https://) or the whole string is empty
|
|
||||||
std::wstring base_url_http_host;
|
|
||||||
|
|
||||||
|
|
||||||
Config();
|
Config();
|
||||||
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
|
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
|
||||||
|
|
||||||
std::wstring Text(const wchar_t * name);
|
std::wstring & Text(const wchar_t * name);
|
||||||
std::wstring Text(const wchar_t * name, const wchar_t * def);
|
std::wstring & Text(const wchar_t * name, const wchar_t * def);
|
||||||
std::wstring Text(const std::wstring & name, const std::wstring & 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 wchar_t * def);
|
|
||||||
std::string AText(const std::wstring & name, const std::wstring & def);
|
|
||||||
|
|
||||||
int Int(const wchar_t *);
|
int Int(const wchar_t *);
|
||||||
int Int(const wchar_t * name, int def);
|
int Int(const wchar_t * name, int def);
|
||||||
int Int(const std::wstring & name, int def);
|
int Int(const std::wstring & name, int def);
|
||||||
|
long Long(const wchar_t *);
|
||||||
|
long Long(const wchar_t * name, long def);
|
||||||
|
long Long(const std::wstring & name, long def);
|
||||||
size_t Size(const wchar_t *);
|
size_t Size(const wchar_t *);
|
||||||
size_t Size(const wchar_t * name, size_t def);
|
size_t Size(const wchar_t * name, size_t def);
|
||||||
size_t Size(const std::wstring & name, size_t def);
|
size_t Size(const std::wstring & name, size_t def);
|
||||||
bool Bool(const wchar_t *);
|
bool Bool(const wchar_t *);
|
||||||
bool Bool(const wchar_t * name, bool def);
|
bool Bool(const wchar_t * name, bool def);
|
||||||
bool Bool(const std::wstring & name, bool def);
|
bool Bool(const std::wstring & name, bool def);
|
||||||
void ListText(const wchar_t * name, std::vector<std::wstring> & list);
|
bool ListText(const wchar_t * name, std::vector<std::wstring> & list);
|
||||||
void ListText(const std::wstring & name, std::vector<std::wstring> & list);
|
bool ListText(const std::wstring & name, std::vector<std::wstring> & list);
|
||||||
|
|
||||||
|
bool HasValue(const wchar_t * name, const wchar_t * value);
|
||||||
|
bool HasValue(const wchar_t * name, const std::wstring & value);
|
||||||
|
bool HasValue(const std::wstring & name, const wchar_t * value);
|
||||||
|
bool HasValue(const std::wstring & name, const std::wstring & value);
|
||||||
|
|
||||||
// for debug
|
// for debug
|
||||||
void Print(std::ostream & out);
|
void Print(std::wostream & out);
|
||||||
|
|
||||||
|
// raw access to the config
|
||||||
|
PT::Space space;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
PT::SpaceParser parser;
|
||||||
|
bool errors_to_stdout;
|
||||||
|
|
||||||
void ShowError();
|
void ShowError();
|
||||||
void AssignValues(bool stdout_is_closed);
|
void AssignValues(bool stdout_is_closed);
|
||||||
void SetHttpHost(const std::wstring & in, std::wstring & out);
|
|
||||||
void SetAdditionalVariables();
|
void SetAdditionalVariables();
|
||||||
void CheckLocale();
|
|
||||||
void CheckPasswd();
|
void CheckPasswd();
|
||||||
|
|
||||||
ConfParser parser;
|
|
||||||
|
|
||||||
std::string default_str;
|
|
||||||
int default_int;
|
|
||||||
bool default_bool;
|
|
||||||
|
|
||||||
bool errors_to_stdout;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,729 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <wchar.h>
|
|
||||||
#include "confparser.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "utf8.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfParser::ConfParser()
|
|
||||||
{
|
|
||||||
// you can change this separators to what you want
|
|
||||||
// you shoud not use only white characters here (as expected by IsWhite() method)
|
|
||||||
// and new line characters ('\n')
|
|
||||||
separator = '=';
|
|
||||||
commentary = '#';
|
|
||||||
list_start = '(';
|
|
||||||
list_end = ')';
|
|
||||||
list_delimiter = ',';
|
|
||||||
split_single = false;
|
|
||||||
skip_empty = false;
|
|
||||||
use_escape_char = true;
|
|
||||||
input_as_utf8 = false;
|
|
||||||
|
|
||||||
default_str = L"";
|
|
||||||
default_int = 0;
|
|
||||||
default_size = 0;
|
|
||||||
default_bool = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::SplitSingle(bool split)
|
|
||||||
{
|
|
||||||
split_single = split;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::SkipEmpty(bool skip)
|
|
||||||
{
|
|
||||||
skip_empty = skip;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::UseEscapeChar(bool escape)
|
|
||||||
{
|
|
||||||
use_escape_char = escape;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfParser::Status ConfParser::Parse(const char * file_name)
|
|
||||||
{
|
|
||||||
line = 1;
|
|
||||||
table.clear();
|
|
||||||
table_single.clear();
|
|
||||||
|
|
||||||
file.clear();
|
|
||||||
file.open( file_name );
|
|
||||||
|
|
||||||
if( file )
|
|
||||||
{
|
|
||||||
status = ParseFile();
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = cant_open_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfParser::Status ConfParser::Parse(const std::string & file_name)
|
|
||||||
{
|
|
||||||
return Parse(file_name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfParser::Status ConfParser::Parse(const wchar_t * file_name)
|
|
||||||
{
|
|
||||||
Ezc::WideToUTF8(file_name, afile_name);
|
|
||||||
return Parse(afile_name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfParser::Status ConfParser::Parse(const std::wstring & file_name)
|
|
||||||
{
|
|
||||||
return Parse(file_name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfParser::Status ConfParser::ParseFile()
|
|
||||||
{
|
|
||||||
ReadChar();
|
|
||||||
SkipWhiteLines();
|
|
||||||
|
|
||||||
while( lastc != -1 )
|
|
||||||
{
|
|
||||||
if( !ReadVariable() )
|
|
||||||
return syntax_error;
|
|
||||||
|
|
||||||
if( lastc != separator )
|
|
||||||
return syntax_error;
|
|
||||||
|
|
||||||
if( !ReadValue() )
|
|
||||||
return syntax_error;
|
|
||||||
|
|
||||||
AddOption();
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
if( lastc != -1 && lastc != '\n' )
|
|
||||||
return syntax_error; // some characters have left at the end of an option
|
|
||||||
|
|
||||||
SkipWhiteLines();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::IsVariableChar(int c)
|
|
||||||
{
|
|
||||||
if( (c>='a' && c<='z') ||
|
|
||||||
(c>='A' && c<='Z') ||
|
|
||||||
(c>='0' && c<='9') ||
|
|
||||||
c=='.' || c==',' || c=='_' )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::AddOption()
|
|
||||||
{
|
|
||||||
if( value.empty() && skip_empty )
|
|
||||||
{
|
|
||||||
DeleteFromTable(variable);
|
|
||||||
DeleteFromTableSingle(variable);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( split_single && value.size() == 1 )
|
|
||||||
{
|
|
||||||
table_single[variable] = value[0];
|
|
||||||
DeleteFromTable(variable);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
table[variable] = value;
|
|
||||||
DeleteFromTableSingle(variable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::DeleteFromTable(const std::wstring & var)
|
|
||||||
{
|
|
||||||
Table::iterator i = table.find(var);
|
|
||||||
|
|
||||||
if( i != table.end() )
|
|
||||||
table.erase(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::DeleteFromTableSingle(const std::wstring & var)
|
|
||||||
{
|
|
||||||
TableSingle::iterator i = table_single.find(var);
|
|
||||||
|
|
||||||
if( i != table_single.end() )
|
|
||||||
table_single.erase(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::ReadVariable()
|
|
||||||
{
|
|
||||||
variable.clear();
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
while( IsVariableChar(lastc) )
|
|
||||||
{
|
|
||||||
variable += lastc;
|
|
||||||
ReadChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
return !variable.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::ReadValue()
|
|
||||||
{
|
|
||||||
value.clear();
|
|
||||||
ReadChar(); // skipping separator '='
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
if( lastc == list_start )
|
|
||||||
return ReadValueList();
|
|
||||||
else
|
|
||||||
return ReadValueNoList();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::ReadValueList()
|
|
||||||
{
|
|
||||||
ReadChar(); // skipping first list character '('
|
|
||||||
SkipWhiteLines(); // lists can be split into several lines
|
|
||||||
|
|
||||||
while( lastc != -1 && lastc != list_end )
|
|
||||||
{
|
|
||||||
if( !ReadValueNoList(true) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( lastc == list_delimiter )
|
|
||||||
ReadChar();
|
|
||||||
|
|
||||||
SkipWhiteLines();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( lastc != list_end )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ReadChar(); // skipping last list character ')'
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::ReadValueNoList(bool use_list_delimiter)
|
|
||||||
{
|
|
||||||
bool res;
|
|
||||||
|
|
||||||
value_item.clear();
|
|
||||||
|
|
||||||
if( lastc == '"' )
|
|
||||||
{
|
|
||||||
res = ReadValueQuoted(); // quoted value
|
|
||||||
|
|
||||||
if( res )
|
|
||||||
value.push_back(value_item);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
res = ReadValueSimple(use_list_delimiter);
|
|
||||||
|
|
||||||
if( res && !value_item.empty() )
|
|
||||||
value.push_back(value_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::ReadValueQuoted()
|
|
||||||
{
|
|
||||||
ReadChar(); // skipping the first quote
|
|
||||||
|
|
||||||
while( lastc != '"' && lastc != -1 )
|
|
||||||
{
|
|
||||||
if( use_escape_char && lastc == '\\' )
|
|
||||||
ReadChar();
|
|
||||||
|
|
||||||
value_item += lastc;
|
|
||||||
ReadChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( lastc != '"' )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ReadChar(); // skipping the last quote
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::ReadValueSimple(bool use_list_delimiter)
|
|
||||||
{
|
|
||||||
int list_delimiter1 = -1;
|
|
||||||
int list_delimiter2 = -1;
|
|
||||||
|
|
||||||
if( use_list_delimiter )
|
|
||||||
{
|
|
||||||
list_delimiter1 = list_delimiter;
|
|
||||||
list_delimiter2 = list_end;
|
|
||||||
}
|
|
||||||
|
|
||||||
while( lastc!=-1 && lastc!='\n' && lastc!=commentary &&
|
|
||||||
lastc!=list_delimiter1 && lastc!=list_delimiter2 )
|
|
||||||
{
|
|
||||||
value_item += lastc;
|
|
||||||
ReadChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
Trim(value_item);
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ConfParser::ReadUTF8Char()
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
bool correct;
|
|
||||||
|
|
||||||
lastc = -1;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Ezc::UTF8ToInt(file, c, correct);
|
|
||||||
|
|
||||||
if( !file )
|
|
||||||
return lastc;
|
|
||||||
}
|
|
||||||
while( !correct );
|
|
||||||
|
|
||||||
lastc = c;
|
|
||||||
|
|
||||||
if( lastc == '\n' )
|
|
||||||
++line;
|
|
||||||
|
|
||||||
return lastc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ConfParser::ReadASCIIChar()
|
|
||||||
{
|
|
||||||
lastc = file.get();
|
|
||||||
|
|
||||||
if( lastc == '\n' )
|
|
||||||
++line;
|
|
||||||
|
|
||||||
return lastc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ConfParser::ReadChar()
|
|
||||||
{
|
|
||||||
if( input_as_utf8 )
|
|
||||||
return ReadUTF8Char();
|
|
||||||
|
|
||||||
return ReadASCIIChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::IsWhite(int c)
|
|
||||||
{
|
|
||||||
// dont use '\n' here
|
|
||||||
// 13 (\r) is at the end of a line in a dos file \r\n
|
|
||||||
// 160 is an unbreakable space
|
|
||||||
if( c==' ' || c=='\t' || c==13 || c==160 )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::SkipWhite()
|
|
||||||
{
|
|
||||||
while( IsWhite(lastc) || lastc == commentary )
|
|
||||||
{
|
|
||||||
if( lastc == commentary )
|
|
||||||
SkipLine();
|
|
||||||
else
|
|
||||||
ReadChar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::SkipWhiteLines()
|
|
||||||
{
|
|
||||||
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
|
|
||||||
{
|
|
||||||
if( lastc == commentary )
|
|
||||||
SkipLine();
|
|
||||||
else
|
|
||||||
ReadChar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::SkipLine()
|
|
||||||
{
|
|
||||||
while( lastc != -1 && lastc != '\n' )
|
|
||||||
ReadChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::Trim(std::wstring & s)
|
|
||||||
{
|
|
||||||
std::wstring::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, std::wstring::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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring ConfParser::Text(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return Text(std::wstring(name), default_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring ConfParser::Text(const wchar_t * name, const wchar_t * def)
|
|
||||||
{
|
|
||||||
return Text(std::wstring(name), std::wstring(def));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring ConfParser::Text(const std::wstring & name, const std::wstring & def)
|
|
||||||
{
|
|
||||||
TableSingle::iterator i = table_single.find(name);
|
|
||||||
|
|
||||||
if( i == table_single.end() )
|
|
||||||
{
|
|
||||||
Table::iterator t = table.find(name);
|
|
||||||
|
|
||||||
if( t == table.end() || t->second.empty() )
|
|
||||||
return def;
|
|
||||||
|
|
||||||
return t->second[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return i->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string ConfParser::AText(const wchar_t * name)
|
|
||||||
{
|
|
||||||
std::wstring res = Text(name);
|
|
||||||
std::string ares;
|
|
||||||
|
|
||||||
Ezc::WideToUTF8(res, ares);
|
|
||||||
|
|
||||||
return ares;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string ConfParser::AText(const wchar_t * name, const wchar_t * def)
|
|
||||||
{
|
|
||||||
std::wstring res = Text(name, def);
|
|
||||||
std::string ares;
|
|
||||||
|
|
||||||
Ezc::WideToUTF8(res, ares);
|
|
||||||
|
|
||||||
return ares;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string ConfParser::AText(const std::wstring & name, const std::wstring & def)
|
|
||||||
{
|
|
||||||
std::wstring res = Text(name, def);
|
|
||||||
std::string ares;
|
|
||||||
|
|
||||||
Ezc::WideToUTF8(res, ares);
|
|
||||||
|
|
||||||
return ares;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ConfParser::Int(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return Int(std::wstring(name), default_int);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ConfParser::Int(const wchar_t * name, int def)
|
|
||||||
{
|
|
||||||
return Int(std::wstring(name), def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ConfParser::ToInt(const std::wstring & value)
|
|
||||||
{
|
|
||||||
long res = (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
|
|
||||||
|
|
||||||
return static_cast<int>(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ConfParser::Int(const std::wstring & name, int def)
|
|
||||||
{
|
|
||||||
TableSingle::iterator i = table_single.find(name);
|
|
||||||
|
|
||||||
if( i == table_single.end() )
|
|
||||||
{
|
|
||||||
Table::iterator t = table.find(name);
|
|
||||||
|
|
||||||
if( t == table.end() || t->second.empty() )
|
|
||||||
return def;
|
|
||||||
|
|
||||||
return ToInt(t->second[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToInt(i->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t ConfParser::Size(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return Size(std::wstring(name), default_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t ConfParser::Size(const wchar_t * name, size_t def)
|
|
||||||
{
|
|
||||||
return Size(std::wstring(name), def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t ConfParser::ToSize(const std::wstring & value)
|
|
||||||
{
|
|
||||||
unsigned long res = (value[0] == '0')? wcstoul(value.c_str() + 1, 0, 8) : wcstoul(value.c_str(), 0, 10);
|
|
||||||
|
|
||||||
return static_cast<size_t>(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t ConfParser::Size(const std::wstring & name, size_t def)
|
|
||||||
{
|
|
||||||
TableSingle::iterator i = table_single.find(name);
|
|
||||||
|
|
||||||
if( i == table_single.end() )
|
|
||||||
{
|
|
||||||
Table::iterator t = table.find(name);
|
|
||||||
|
|
||||||
if( t == table.end() || t->second.empty() )
|
|
||||||
return def;
|
|
||||||
|
|
||||||
return ToSize(t->second[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToSize(i->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::Bool(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return Bool(std::wstring(name), default_bool);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::Bool(const wchar_t * name, bool def)
|
|
||||||
{
|
|
||||||
return Bool(std::wstring(name), def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::ToBool(const std::wstring & value)
|
|
||||||
{
|
|
||||||
return ( EqualNoCase(value.c_str(), L"true") ||
|
|
||||||
EqualNoCase(value.c_str(), L"yes") ||
|
|
||||||
EqualNoCase(value.c_str(), L"1")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ConfParser::Bool(const std::wstring & name, bool def)
|
|
||||||
{
|
|
||||||
TableSingle::iterator i = table_single.find(name);
|
|
||||||
|
|
||||||
if( i == table_single.end() )
|
|
||||||
{
|
|
||||||
Table::iterator t = table.find(name);
|
|
||||||
|
|
||||||
if( t == table.end() || t->second.empty() )
|
|
||||||
return def;
|
|
||||||
|
|
||||||
return ToBool(t->second[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToBool(i->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::SetDefaultText(const std::wstring & def)
|
|
||||||
{
|
|
||||||
default_str = def;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfParser::SetDefaultInt(int def)
|
|
||||||
{
|
|
||||||
default_int = def;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfParser::SetDefaultSize(size_t def)
|
|
||||||
{
|
|
||||||
default_size = def;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfParser::SetDefaultBool(bool def)
|
|
||||||
{
|
|
||||||
default_bool = def;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// in lists we don't use default values
|
|
||||||
void ConfParser::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
|
||||||
{
|
|
||||||
ListText(std::wstring(name), list);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
|
||||||
{
|
|
||||||
list.clear();
|
|
||||||
|
|
||||||
ConfParser::TableSingle::iterator i = table_single.find(name);
|
|
||||||
|
|
||||||
if( i != table_single.end() )
|
|
||||||
{
|
|
||||||
list.push_back(i->second);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfParser::Table::iterator z = table.find(name);
|
|
||||||
|
|
||||||
if( z != table.end() )
|
|
||||||
{
|
|
||||||
list = z->second;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::UTF8(bool utf)
|
|
||||||
{
|
|
||||||
input_as_utf8 = utf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConfParser::Print(std::ostream & out)
|
|
||||||
{
|
|
||||||
TableSingle::iterator i1;
|
|
||||||
|
|
||||||
for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1)
|
|
||||||
{
|
|
||||||
Ezc::WideToUTF8(i1->first, out);
|
|
||||||
out << '=';
|
|
||||||
Ezc::WideToUTF8(i1->second, out);
|
|
||||||
out << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Table::iterator i2;
|
|
||||||
Value::iterator i3;
|
|
||||||
|
|
||||||
for(i2 = table.begin() ; i2 != table.end() ; ++i2)
|
|
||||||
{
|
|
||||||
Ezc::WideToUTF8(i2->first, out);
|
|
||||||
out << '=';
|
|
||||||
|
|
||||||
for(i3 = i2->second.begin() ; i3 != i2->second.end() ; ++i3)
|
|
||||||
{
|
|
||||||
Ezc::WideToUTF8(*i3, out);
|
|
||||||
out << ',';
|
|
||||||
}
|
|
||||||
|
|
||||||
out << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,406 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfileconfparser
|
|
||||||
#define headerfileconfparser
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
A parser for parsing config files.
|
|
||||||
|
|
||||||
A config file can look like this:
|
|
||||||
variable1 = value 1
|
|
||||||
variable2 = " value 2 "
|
|
||||||
variable3 = (value 1, value 2)
|
|
||||||
variable4 = (" value 1 " , "value2", value 3)
|
|
||||||
|
|
||||||
sample of use:
|
|
||||||
ConfParser parser;
|
|
||||||
parser.Parse("/path/to/config");
|
|
||||||
|
|
||||||
if( parser.status == ConfParser::ok )
|
|
||||||
{
|
|
||||||
// the whole config we have in parser.table (parser.table_single)
|
|
||||||
}
|
|
||||||
|
|
||||||
config syntax:
|
|
||||||
option = list
|
|
||||||
|
|
||||||
list can consists of any number of items, if you're using more than one item you should
|
|
||||||
use brackets ()
|
|
||||||
|
|
||||||
for one item the brackets can be ommited:
|
|
||||||
option = value
|
|
||||||
white characters at the beginning of the value (and at the end) will be trimmed,
|
|
||||||
or you can use quotes:
|
|
||||||
option = "value"
|
|
||||||
option2 = "value with spaces at the end "
|
|
||||||
|
|
||||||
the form without quotes:
|
|
||||||
option = value
|
|
||||||
should be written in one line, so this is not allowed:
|
|
||||||
option =
|
|
||||||
value
|
|
||||||
you can use a new line characters only between brackets and quotes:
|
|
||||||
option = "this is
|
|
||||||
a multiline string"
|
|
||||||
option = ( value1,
|
|
||||||
value2 )
|
|
||||||
|
|
||||||
but there is one requirement: the first character " or ( should be in the same line,
|
|
||||||
so this is not allowed
|
|
||||||
option =
|
|
||||||
"this is wrong"
|
|
||||||
but this is ok:
|
|
||||||
option = "
|
|
||||||
that is ok"
|
|
||||||
|
|
||||||
empty lists:
|
|
||||||
option = ()
|
|
||||||
this creates an empty list: parser.table['option'].empty() == true
|
|
||||||
|
|
||||||
option =
|
|
||||||
this creates an empty list too (the same as previously)
|
|
||||||
|
|
||||||
option = ""
|
|
||||||
but this doesn't create an empty list, it creates a list with one (empty) item
|
|
||||||
|
|
||||||
commentaries:
|
|
||||||
# this is a commentary (until the end of the line)
|
|
||||||
option = value # this is a commentary too
|
|
||||||
|
|
||||||
commentaries are treated as white characters, other example:
|
|
||||||
option = ( # this is my list
|
|
||||||
"value 1" # this is a value one
|
|
||||||
value 2 # and this is a value two
|
|
||||||
) # end of my list
|
|
||||||
|
|
||||||
overwriting:
|
|
||||||
option1 = some value
|
|
||||||
option1 = other value
|
|
||||||
# always the last option is used so option1 is "other value"
|
|
||||||
|
|
||||||
list delimiter:
|
|
||||||
option1 = (value1, value2, value3)
|
|
||||||
option2 = ("value1", "value2", "value3")
|
|
||||||
above we're using a comma ',' as a list delimiter but when using quotes (second line)
|
|
||||||
the commas can be omitted:
|
|
||||||
option2 = ("value1" "value2" "value3")
|
|
||||||
|
|
||||||
white characters:
|
|
||||||
the name of an option cannot consist of white characters
|
|
||||||
some option = value # this is wrong
|
|
||||||
some_option = value # this is ok
|
|
||||||
|
|
||||||
which characters are allowed in an option name is defined by IsVariableChar() method
|
|
||||||
|
|
||||||
you can use white characters in values
|
|
||||||
option = value with spaces or tabs
|
|
||||||
white characters at the beginning and at the end will be trimmed,
|
|
||||||
so if you want them use quotes:
|
|
||||||
option = " other value with spaces "
|
|
||||||
|
|
||||||
special characters in quoted strings:
|
|
||||||
option = "this is a string with \" a quote inside"
|
|
||||||
the option will be: this is a string with " a quote inside
|
|
||||||
\\ - means one \
|
|
||||||
basically: \char produces char
|
|
||||||
so:
|
|
||||||
"\a" gives "a"
|
|
||||||
"\\" gives "\"
|
|
||||||
"\Z" gives "Z" and so on
|
|
||||||
you can call UseEscapeChar(false) to turn this off
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
class ConfParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
ConfParser();
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
status of parsing
|
|
||||||
*/
|
|
||||||
enum Status { ok, cant_open_file, syntax_error };
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
the last status of parsing, set by Parse() methods
|
|
||||||
*/
|
|
||||||
Status status;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
the main methods used to parse
|
|
||||||
file_name is the path to a file
|
|
||||||
*/
|
|
||||||
Status Parse(const char * file_name);
|
|
||||||
Status Parse(const std::string & file_name);
|
|
||||||
Status Parse(const wchar_t * file_name);
|
|
||||||
Status Parse(const std::wstring & file_name);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
a number of a line in which there is a syntax_error
|
|
||||||
*/
|
|
||||||
int line;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
this is the table which represents your config file
|
|
||||||
in the Table map: the first (key) is your 'option' and the second is 'list'
|
|
||||||
*/
|
|
||||||
typedef std::vector<std::wstring> Value;
|
|
||||||
typedef std::map<std::wstring, Value> Table;
|
|
||||||
Table table;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if your config file consists mainly of single forms such as:
|
|
||||||
option = value
|
|
||||||
option2 = value2
|
|
||||||
then you can call SplitSingle(true) for not inserting single values to
|
|
||||||
previous 'table' but instead to 'table_single'
|
|
||||||
table_single as the second parameter takes only std::wstring (instead of the whole std::vector)
|
|
||||||
so you can save a little memory from not using std::vector
|
|
||||||
*/
|
|
||||||
typedef std::map<std::wstring, std::wstring> TableSingle;
|
|
||||||
TableSingle table_single;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if your list consists of only one item, e.g:
|
|
||||||
option1 = value 1
|
|
||||||
option2 = "value 2"
|
|
||||||
option3 = ( "value 3" )
|
|
||||||
then if you call SplitSingle(true) then such values will be stored in
|
|
||||||
'table_single' instead of 'table' map
|
|
||||||
default: false
|
|
||||||
*/
|
|
||||||
void SplitSingle(bool split);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if true then empty lists, e.g:
|
|
||||||
option =
|
|
||||||
option2 = ()
|
|
||||||
will be omitted (not inserted to 'table' or 'table_single')
|
|
||||||
default: false
|
|
||||||
*/
|
|
||||||
void SkipEmpty(bool skip);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
'\' character is used to escape other characters in a quoted string
|
|
||||||
so "some \t t\"ext" will produce "some t t"ext"
|
|
||||||
(this is only use in quoted string)
|
|
||||||
default: true
|
|
||||||
*/
|
|
||||||
void UseEscapeChar(bool escape);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
those methods are used to extract information from table or table_single
|
|
||||||
as a parameter they take the name of an option
|
|
||||||
and a default value (if there is no such a parameter),
|
|
||||||
they return appropriate value (either text, int or boolean)
|
|
||||||
(in lists they return the first item if exists)
|
|
||||||
*/
|
|
||||||
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 std::wstring & def);
|
|
||||||
std::string AText(const wchar_t * name);
|
|
||||||
std::string AText(const wchar_t * name, const wchar_t * def);
|
|
||||||
std::string AText(const std::wstring & name, const std::wstring & def);
|
|
||||||
int Int(const wchar_t *);
|
|
||||||
int Int(const wchar_t * name, int def);
|
|
||||||
int Int(const std::wstring & name, int def);
|
|
||||||
size_t Size(const wchar_t *);
|
|
||||||
size_t Size(const wchar_t * name, size_t def);
|
|
||||||
size_t Size(const std::wstring & name, size_t def);
|
|
||||||
bool Bool(const wchar_t *);
|
|
||||||
bool Bool(const wchar_t * name, bool def);
|
|
||||||
bool Bool(const std::wstring & name, bool def);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
some default values
|
|
||||||
used in Text() Int() or Bool() when you don't explicitly set the default value
|
|
||||||
|
|
||||||
if you don't set it directly then:
|
|
||||||
default text is: "" (empty)
|
|
||||||
default int or size is: 0
|
|
||||||
default bool is: false
|
|
||||||
*/
|
|
||||||
void SetDefaultText(const std::wstring & def);
|
|
||||||
void SetDefaultInt(int def);
|
|
||||||
void SetDefaultSize(size_t def);
|
|
||||||
void SetDefaultBool(bool def);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
those methods are used to extract lists
|
|
||||||
note: if there is one option in table_single they will return it
|
|
||||||
*/
|
|
||||||
void ListText(const wchar_t * name, std::vector<std::wstring> & list);
|
|
||||||
void ListText(const std::wstring & name, std::vector<std::wstring> & list);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if true then the input file is treated as UTF-8
|
|
||||||
*/
|
|
||||||
void UTF8(bool utf);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
printing the content
|
|
||||||
(for debug purposes)
|
|
||||||
*/
|
|
||||||
void Print(std::ostream & out);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/*
|
|
||||||
last read variable (option)
|
|
||||||
*/
|
|
||||||
std::wstring variable;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
last read list item
|
|
||||||
*/
|
|
||||||
std::wstring value_item;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
last read list
|
|
||||||
*/
|
|
||||||
Value value;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
separator between a variable and a value, default: '='
|
|
||||||
*/
|
|
||||||
int separator;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
commentary char, default: '#'
|
|
||||||
*/
|
|
||||||
int commentary;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
list starting character, default: '('
|
|
||||||
*/
|
|
||||||
int list_start;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
list ending character, default: ')'
|
|
||||||
*/
|
|
||||||
int list_end;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
list delimiter, default: ','
|
|
||||||
*/
|
|
||||||
int list_delimiter;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
last read char
|
|
||||||
or -1 if the end
|
|
||||||
*/
|
|
||||||
int lastc;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
current file
|
|
||||||
*/
|
|
||||||
std::ifstream file;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if true then lists with one item will be put into 'table_single' table
|
|
||||||
default: false
|
|
||||||
*/
|
|
||||||
bool split_single;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if true then empty lists, e.g:
|
|
||||||
option =
|
|
||||||
option2 = ()
|
|
||||||
will be omitted (not inserted to 'table' or 'table_single')
|
|
||||||
default: false
|
|
||||||
*/
|
|
||||||
bool skip_empty;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
input file is in UTF-8
|
|
||||||
default: false
|
|
||||||
*/
|
|
||||||
bool input_as_utf8;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if true you can use an escape character '\' in quoted values
|
|
||||||
*/
|
|
||||||
bool use_escape_char;
|
|
||||||
|
|
||||||
std::string afile_name;
|
|
||||||
|
|
||||||
std::wstring default_str;
|
|
||||||
int default_int;
|
|
||||||
size_t default_size;
|
|
||||||
bool default_bool;
|
|
||||||
|
|
||||||
int ToInt(const std::wstring & value);
|
|
||||||
size_t ToSize(const std::wstring & value);
|
|
||||||
bool ToBool(const std::wstring & value);
|
|
||||||
|
|
||||||
Status ParseFile();
|
|
||||||
void AddOption();
|
|
||||||
|
|
||||||
void DeleteFromTable(const std::wstring & var);
|
|
||||||
void DeleteFromTableSingle(const std::wstring & var);
|
|
||||||
|
|
||||||
bool ReadVariable();
|
|
||||||
bool ReadValue();
|
|
||||||
bool ReadValueList();
|
|
||||||
bool ReadValueNoList(bool use_list_delimiter = false);
|
|
||||||
bool ReadValueQuoted();
|
|
||||||
bool ReadValueSimple(bool use_list_delimiter = false);
|
|
||||||
|
|
||||||
int ReadUTF8Char();
|
|
||||||
int ReadASCIIChar();
|
|
||||||
int ReadChar();
|
|
||||||
bool IsWhite(int c);
|
|
||||||
bool IsVariableChar(int c);
|
|
||||||
void SkipWhite();
|
|
||||||
void SkipWhiteLines();
|
|
||||||
void SkipLine();
|
|
||||||
void Trim(std::wstring & s);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+47
-9
@@ -1,26 +1,54 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_cookieparser
|
||||||
#define headerfile_winix_core_cookieparser
|
#define headerfile_winix_core_cookieparser
|
||||||
|
|
||||||
#include <fcgiapp.h>
|
|
||||||
#include "httpsimpleparser.h"
|
#include "httpsimpleparser.h"
|
||||||
#include "requesttypes.h"
|
#include "requesttypes.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CookieParser : public HttpSimpleParser
|
class CookieParser : public HttpSimpleParser
|
||||||
{
|
{
|
||||||
|
|
||||||
const char * cookie_string;
|
const wchar_t * cookie_string;
|
||||||
CookieTab * cookie_tab;
|
CookieTab * cookie_tab;
|
||||||
|
|
||||||
|
|
||||||
@@ -32,17 +60,18 @@ protected:
|
|||||||
if( !cookie_string || *cookie_string == 0 )
|
if( !cookie_string || *cookie_string == 0 )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return (int)(unsigned char)*(cookie_string++);
|
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
|
// Cookie names are case insensitive according to section 3.1 of RFC 2965
|
||||||
|
// (we don't use locale here)
|
||||||
ToLower(name);
|
ToLower(name);
|
||||||
|
|
||||||
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(name, value) );
|
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(name, value) );
|
||||||
|
|
||||||
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
|
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
|
||||||
|
|
||||||
if( res.second == false )
|
if( res.second == false )
|
||||||
@@ -64,11 +93,12 @@ public:
|
|||||||
HttpSimpleParser::value_can_be_quoted = true;
|
HttpSimpleParser::value_can_be_quoted = true;
|
||||||
HttpSimpleParser::skip_white_chars = true;
|
HttpSimpleParser::skip_white_chars = true;
|
||||||
HttpSimpleParser::recognize_special_chars = false;
|
HttpSimpleParser::recognize_special_chars = false;
|
||||||
|
HttpSimpleParser::getchar_returns_utf8_chars = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cookie_string can be null
|
// 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_string = cookie_string_;
|
||||||
cookie_tab = &cookie_tab_;
|
cookie_tab = &cookie_tab_;
|
||||||
@@ -76,8 +106,16 @@ public:
|
|||||||
HttpSimpleParser::Parse();
|
HttpSimpleParser::Parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Parse(const std::wstring & cookie_string_, CookieTab & cookie_tab_)
|
||||||
|
{
|
||||||
|
Parse(cookie_string_.c_str(), cookie_tab_);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+118
-43
@@ -1,42 +1,68 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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>
|
#include <cstring>
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
#include "utf8.h"
|
#include "utf8/utf8.h"
|
||||||
#include "misc.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Crypt::SetConfig(Config * pconfig)
|
void Crypt::SetConfig(Config * pconfig)
|
||||||
{
|
{
|
||||||
config = pconfig;
|
config = pconfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Crypt::TrimLastWhite(std::string & str)
|
|
||||||
|
char Crypt::ConvertToHexForm(int val)
|
||||||
{
|
{
|
||||||
if( str.empty() )
|
if( val < 10 )
|
||||||
return;
|
return val + '0';
|
||||||
|
|
||||||
size_t i = str.size();
|
return val - 10 + 'a';
|
||||||
|
|
||||||
while( i > 0 && (IsWhite(str[i-1]) || str[i-1]==10) )
|
|
||||||
i -= 1;
|
|
||||||
|
|
||||||
if( i < str.size() )
|
|
||||||
str.erase(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
|
|
||||||
|
|
||||||
|
bool Crypt::HashBin(int hash, const char * in, size_t inlen, std::string & out)
|
||||||
{
|
{
|
||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
@@ -44,9 +70,10 @@ bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
run.Clear();
|
run.Clear();
|
||||||
Ezc::WideToUTF8(config->opensll_path, command);
|
PT::WideToUTF8(config->opensll_path, command);
|
||||||
run.Cmd(command);
|
run.Cmd(command);
|
||||||
run.Par("dgst");
|
run.Par("dgst");
|
||||||
|
run.Par("-binary");
|
||||||
|
|
||||||
switch(hash)
|
switch(hash)
|
||||||
{
|
{
|
||||||
@@ -62,52 +89,96 @@ bool Crypt::Hash(int hash, const char * in, size_t inlen, std::string & out)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = run.Go(in, inlen, out) == 0;
|
return run.Go(in, inlen, out) == 0;
|
||||||
TrimLastWhite(out);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const char * in, std::string & out)
|
bool Crypt::HashBin(int hash, const char * in, std::string & out)
|
||||||
{
|
{
|
||||||
size_t len = strlen(in);
|
size_t len = strlen(in);
|
||||||
return Hash(hash, in, len, out);
|
return HashBin(hash, in, len, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const std::string & in, std::string & out)
|
bool Crypt::HashBin(int hash, const std::string & in, std::string & out)
|
||||||
{
|
{
|
||||||
return Hash(hash, in.c_str(), in.size(), out);
|
return HashBin(hash, in.c_str(), in.size(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const wchar_t * in, size_t inlen, std::wstring & out)
|
bool Crypt::HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out)
|
||||||
{
|
{
|
||||||
Ezc::WideToUTF8(in, inlen, bufina);
|
PT::WideToUTF8(in, inlen, bufina);
|
||||||
int res = Hash(hash, bufina.c_str(), bufina.size(), bufouta);
|
int res = HashBin(hash, bufina.c_str(), bufina.size(), out);
|
||||||
|
bufina.clear();
|
||||||
// the output hash is not a UTF8 string
|
|
||||||
// it consists only from ascii letters
|
|
||||||
AssignString(bufouta, out);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const wchar_t * in, std::wstring & out)
|
bool Crypt::HashBin(int hash, const wchar_t * in, std::string & out)
|
||||||
{
|
{
|
||||||
size_t len = wcslen(in);
|
size_t len = wcslen(in);
|
||||||
return Hash(hash, in, len, out);
|
return HashBin(hash, in, len, out);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Crypt::Hash(int hash, const std::wstring & in, std::wstring & out)
|
|
||||||
|
bool Crypt::HashBin(int hash, const std::wstring & in, std::string & out)
|
||||||
{
|
{
|
||||||
return Hash(hash, in.c_str(), in.size(), out);
|
return HashBin(hash, in.c_str(), in.size(), out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Crypt::HashHex(int hash, const char * in, size_t inlen, std::string & out)
|
||||||
|
{
|
||||||
|
int res = HashBin(hash, in, inlen, out_temp);
|
||||||
|
|
||||||
|
ConvertToHexForm(out_temp, out);
|
||||||
|
out_temp.clear();
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Crypt::HashHex(int hash, const char * in, std::string & out)
|
||||||
|
{
|
||||||
|
size_t len = strlen(in);
|
||||||
|
return HashHex(hash, in, len, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Crypt::HashHex(int hash, const std::string & in, std::string & out)
|
||||||
|
{
|
||||||
|
return HashHex(hash, in.c_str(), in.size(), out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Crypt::HashHex(int hash, const wchar_t * in, size_t inlen, std::wstring & out)
|
||||||
|
{
|
||||||
|
int res = HashBin(hash, in, inlen, out_temp);
|
||||||
|
|
||||||
|
ConvertToHexForm(out_temp, out);
|
||||||
|
out_temp.clear();
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Crypt::HashHex(int hash, const wchar_t * in, std::wstring & out)
|
||||||
|
{
|
||||||
|
size_t len = wcslen(in);
|
||||||
|
return HashHex(hash, in, len, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Crypt::HashHex(int hash, const std::wstring & in, std::wstring & out)
|
||||||
|
{
|
||||||
|
return HashHex(hash, in.c_str(), in.size(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,7 +203,7 @@ bool Crypt::RSA(bool encrypt, const char * keypath, const char * in, size_t inle
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
run.Clear();
|
run.Clear();
|
||||||
Ezc::WideToUTF8(config->opensll_path, command);
|
PT::WideToUTF8(config->opensll_path, command);
|
||||||
run.Cmd(command);
|
run.Cmd(command);
|
||||||
|
|
||||||
run.Par("rsautl");
|
run.Par("rsautl");
|
||||||
@@ -164,7 +235,7 @@ bool Crypt::RSA(bool encrypt, const std::string & keypath, const std::string & i
|
|||||||
|
|
||||||
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out)
|
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out)
|
||||||
{
|
{
|
||||||
Ezc::WideToUTF8(keypath, keypatha);
|
PT::WideToUTF8(keypath, keypatha);
|
||||||
return RSA(encrypt, keypatha.c_str(), in, inlen, out);
|
return RSA(encrypt, keypatha.c_str(), in, inlen, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,13 +264,13 @@ bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
|
|||||||
bool result = true;
|
bool result = true;
|
||||||
up.pass_hash_salted = false;
|
up.pass_hash_salted = false;
|
||||||
|
|
||||||
if( up.pass_type != WINIX_CRYPT_HASH_PLAIN )
|
if( up.pass_type != WINIX_CRYPT_HASH_NONE )
|
||||||
{
|
{
|
||||||
pass_org = up.pass;
|
pass_org = up.pass;
|
||||||
pass_salted = up.pass;
|
pass_salted = up.pass;
|
||||||
pass_salted += salt;
|
pass_salted += salt;
|
||||||
|
|
||||||
if( Hash(up.pass_type, pass_salted, up.pass) )
|
if( HashHex(up.pass_type, pass_salted, up.pass) )
|
||||||
{
|
{
|
||||||
if( !salt.empty() )
|
if( !salt.empty() )
|
||||||
up.pass_hash_salted = true;
|
up.pass_hash_salted = true;
|
||||||
@@ -209,7 +280,7 @@ bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
|
|||||||
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
|
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
|
||||||
|
|
||||||
up.pass = pass_org;
|
up.pass = pass_org;
|
||||||
up.pass_type = WINIX_CRYPT_HASH_PLAIN;
|
up.pass_type = WINIX_CRYPT_HASH_NONE;
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +300,7 @@ bool Crypt::PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & u
|
|||||||
|
|
||||||
if( !path_to_rsa_private_key.empty() )
|
if( !path_to_rsa_private_key.empty() )
|
||||||
{
|
{
|
||||||
Ezc::WideToUTF8(up.pass, passa);
|
PT::WideToUTF8(up.pass, passa);
|
||||||
|
|
||||||
if( RSA(true, path_to_rsa_private_key, passa, up.pass_encrypted) )
|
if( RSA(true, path_to_rsa_private_key, passa, up.pass_encrypted) )
|
||||||
{
|
{
|
||||||
@@ -271,3 +342,7 @@ void Crypt::PassHashCrypt(UserPass & up)
|
|||||||
PassCrypt(config->pass_rsa_private_key, up);
|
PassCrypt(config->pass_rsa_private_key, up);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+104
-19
@@ -1,26 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_crypt
|
||||||
#define headerfile_winix_core_crypt
|
#define headerfile_winix_core_crypt
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "run.h"
|
#include "run.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
the kind of hashes we are able to obtain in winix
|
the kind of hashes we are able to obtain in winix
|
||||||
*/
|
*/
|
||||||
#define WINIX_CRYPT_HASH_PLAIN 0
|
#define WINIX_CRYPT_HASH_NONE 0
|
||||||
#define WINIX_CRYPT_HASH_MD4 1
|
#define WINIX_CRYPT_HASH_MD4 1
|
||||||
#define WINIX_CRYPT_HASH_MD5 2
|
#define WINIX_CRYPT_HASH_MD5 2
|
||||||
#define WINIX_CRYPT_HASH_SHA1 10
|
#define WINIX_CRYPT_HASH_SHA1 10
|
||||||
@@ -50,11 +79,11 @@ public:
|
|||||||
in - input buffer
|
in - input buffer
|
||||||
inlen - the length of the buffer
|
inlen - the length of the buffer
|
||||||
output:
|
output:
|
||||||
out - the hash
|
out - the hash in binary form
|
||||||
*/
|
*/
|
||||||
bool Hash(int hash, const char * in, size_t inlen, std::string & out);
|
bool HashBin(int hash, const char * in, size_t inlen, std::string & out);
|
||||||
bool Hash(int hash, const char * in, std::string & out);
|
bool HashBin(int hash, const char * in, std::string & out);
|
||||||
bool Hash(int hash, const std::string & in, std::string & out);
|
bool HashBin(int hash, const std::string & in, std::string & out);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -66,11 +95,43 @@ public:
|
|||||||
in - input buffer
|
in - input buffer
|
||||||
inlen - the length of the buffer
|
inlen - the length of the buffer
|
||||||
output:
|
output:
|
||||||
out - the hash
|
out - the hash in binary form
|
||||||
*/
|
*/
|
||||||
bool Hash(int hash, const wchar_t * in, size_t inlen, std::wstring & out);
|
bool HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out);
|
||||||
bool Hash(int hash, const wchar_t * in, std::wstring & out);
|
bool HashBin(int hash, const wchar_t * in, std::string & out);
|
||||||
bool Hash(int hash, const std::wstring & in, std::wstring & out);
|
bool HashBin(int hash, const std::wstring & in, std::string & out);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
calculating a hash from a given input
|
||||||
|
|
||||||
|
input:
|
||||||
|
hash - the kind of the hash - WINIX_CRYPT_HASH_*
|
||||||
|
in - input buffer
|
||||||
|
inlen - the length of the buffer
|
||||||
|
output:
|
||||||
|
out - the hash in the hex form (one byte is saved as two hex digits)
|
||||||
|
*/
|
||||||
|
bool HashHex(int hash, const char * in, size_t inlen, std::string & out);
|
||||||
|
bool HashHex(int hash, const char * in, std::string & out);
|
||||||
|
bool HashHex(int hash, const std::string & in, std::string & out);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
calculating a hash from a given input
|
||||||
|
the input string is first changed to UTF8 and then hash is calculated
|
||||||
|
|
||||||
|
input:
|
||||||
|
hash - the kind of the hash - WINIX_CRYPT_HASH_*
|
||||||
|
in - input buffer
|
||||||
|
inlen - the length of the buffer
|
||||||
|
output:
|
||||||
|
out - the hash in the hex form (one byte is saved as two hex digits)
|
||||||
|
the 'out' here is std::wstring (not std::string like beforehand)
|
||||||
|
*/
|
||||||
|
bool HashHex(int hash, const wchar_t * in, size_t inlen, std::wstring & out);
|
||||||
|
bool HashHex(int hash, const wchar_t * in, std::wstring & out);
|
||||||
|
bool HashHex(int hash, const std::wstring & in, std::wstring & out);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -83,7 +144,7 @@ public:
|
|||||||
inlen - the size of the buffer
|
inlen - the size of the buffer
|
||||||
|
|
||||||
output:
|
output:
|
||||||
out - encrypted or decrypted buffer
|
out - encrypted or decrypted buffer (always binary)
|
||||||
*/
|
*/
|
||||||
bool RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out);
|
bool RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out);
|
||||||
bool RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out);
|
bool RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out);
|
||||||
@@ -179,22 +240,27 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void TrimLastWhite(std::string & str);
|
|
||||||
|
|
||||||
Config * config;
|
Config * config;
|
||||||
Run run;
|
Run run;
|
||||||
std::string command, bufina, bufouta, keypatha;
|
std::string command, bufina, keypatha;
|
||||||
//std::wstring pass_salted;//, pass_hashed;
|
//std::wstring pass_salted;//, pass_hashed;
|
||||||
//std::string pass_hasheda, pass_encrypteda;
|
//std::string pass_hasheda, pass_encrypteda;
|
||||||
|
|
||||||
std::wstring pass_salted, pass_org;
|
std::wstring pass_salted, pass_org;
|
||||||
std::string passa;
|
std::string passa, out_temp;
|
||||||
std::wstring empty;
|
std::wstring empty;
|
||||||
|
|
||||||
|
|
||||||
|
template<typename StringType>
|
||||||
|
void ConvertToHexForm(const std::string & in, StringType & out);
|
||||||
|
|
||||||
|
char ConvertToHexForm(int val);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
template<typename StringType>
|
||||||
void Crypt::ClearString(StringType & str)
|
void Crypt::ClearString(StringType & str)
|
||||||
{
|
{
|
||||||
for(size_t i=0 ; i<str.size() ; ++i)
|
for(size_t i=0 ; i<str.size() ; ++i)
|
||||||
@@ -204,6 +270,25 @@ void Crypt::ClearString(StringType & str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename StringType>
|
||||||
|
void Crypt::ConvertToHexForm(const std::string & in, StringType & out)
|
||||||
|
{
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
if( in.size() * 2 > out.capacity() )
|
||||||
|
out.reserve(in.size() * 2);
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<in.size() ; ++i)
|
||||||
|
{
|
||||||
|
out += ConvertToHexForm(((unsigned char)in[i]) >> 4);
|
||||||
|
out += ConvertToHexForm(((unsigned char)in[i]) & 0x0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+37
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_cur
|
||||||
@@ -12,6 +37,12 @@
|
|||||||
|
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
#include "mount.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -21,6 +52,7 @@ struct Cur
|
|||||||
{
|
{
|
||||||
Request * request;
|
Request * request;
|
||||||
Session * session;
|
Session * session;
|
||||||
|
Mount * mount;
|
||||||
|
|
||||||
// those pointers are never null, if there is no a session for the user
|
// those pointers are never null, if there is no a session for the user
|
||||||
// the 'session' pointer pointers at a special temporary session
|
// the 'session' pointer pointers at a special temporary session
|
||||||
@@ -29,6 +61,8 @@ struct Cur
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+38
-3
@@ -1,16 +1,46 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "dircontainer.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring DirContainer::dir_etc = L"etc";
|
std::wstring DirContainer::dir_etc = L"etc";
|
||||||
std::wstring DirContainer::dir_var = L"var";
|
std::wstring DirContainer::dir_var = L"var";
|
||||||
|
|
||||||
@@ -328,3 +358,8 @@ bool DirContainer::DelById(long id)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+37
-4
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_dircontainer
|
||||||
@@ -15,6 +40,10 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DirContainer
|
class DirContainer
|
||||||
{
|
{
|
||||||
@@ -48,7 +77,7 @@ public:
|
|||||||
|
|
||||||
bool DelById(long id);
|
bool DelById(long id);
|
||||||
|
|
||||||
ParentIterator ParentBegin();
|
ParentIterator ParentBegin(); // IMPROVE ME: may it should be renamed to ChildBegin() similarly as FindFirstChild() ?
|
||||||
ParentIterator ParentEnd();
|
ParentIterator ParentEnd();
|
||||||
ParentSizeType ParentSize();
|
ParentSizeType ParentSize();
|
||||||
bool ParentEmpty();
|
bool ParentEmpty();
|
||||||
@@ -92,4 +121,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+160
-31
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "dirs.h"
|
||||||
@@ -12,6 +37,9 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Dirs::SetDb(Db * pdb)
|
void Dirs::SetDb(Db * pdb)
|
||||||
@@ -41,7 +69,7 @@ void Dirs::Clear()
|
|||||||
bool Dirs::HasReadExecAccessForRoot(const Item & item)
|
bool Dirs::HasReadExecAccessForRoot(const Item & item)
|
||||||
{
|
{
|
||||||
// there must be at least one 'x' (for the root)
|
// there must be at least one 'x' (for the root)
|
||||||
return (item.privileges & 01111) != 0; // !! in the future there'll be another 'x'
|
return (item.privileges & 01111) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -53,8 +81,8 @@ void Dirs::CheckRootDir()
|
|||||||
{
|
{
|
||||||
if( !HasReadExecAccessForRoot(*i) )
|
if( !HasReadExecAccessForRoot(*i) )
|
||||||
{
|
{
|
||||||
i->privileges = 0755;
|
i->privileges = 07555;
|
||||||
log << log1 << "Dirs: there is no access for root (admin) to the root dir, setting 0755 for root dir" << logend;
|
log << log1 << "Dirs: there is no access for a root (admin) to the root dir, setting 07555 for the root directory" << logend;
|
||||||
db->EditPrivById(*i, i->id);
|
db->EditPrivById(*i, i->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +90,7 @@ void Dirs::CheckRootDir()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log << log1 << "Dirs: there is no a root dir in the database (creating one)" << logend;
|
log << log1 << "Dirs: there is no a root directory in the database (creating one)" << logend;
|
||||||
|
|
||||||
Item root;
|
Item root;
|
||||||
|
|
||||||
@@ -70,7 +98,7 @@ void Dirs::CheckRootDir()
|
|||||||
root.parent_id = -1;
|
root.parent_id = -1;
|
||||||
root.user_id = -1;
|
root.user_id = -1;
|
||||||
root.group_id = -1;
|
root.group_id = -1;
|
||||||
root.privileges = 0755;
|
root.privileges = 07555;
|
||||||
|
|
||||||
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
|
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
|
||||||
// !! zrobic jakis wyjatek do wprowadzania roota?
|
// !! zrobic jakis wyjatek do wprowadzania roota?
|
||||||
@@ -158,10 +186,10 @@ DirContainer::ParentIterator Dirs::ParentEnd()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// dodatkowo moze metoda AppendPath dodajaca sciezke do biezacego stringa?
|
// !! dodatkowo moze metoda AppendPath dodajaca sciezke do biezacego stringa?
|
||||||
// albo tutaj stringa nie czyscic?
|
// albo tutaj stringa nie czyscic?
|
||||||
// O(m * log n) (m- how many parts are in 'id')
|
// O(m * log n) (m- how many parts are in 'id')
|
||||||
// path with a slash at the end
|
// path with a slash at the end and at the beginning
|
||||||
bool Dirs::MakePath(long id, std::wstring & path, bool clear_path)
|
bool Dirs::MakePath(long id, std::wstring & path, bool clear_path)
|
||||||
{
|
{
|
||||||
DirContainer::Iterator i;
|
DirContainer::Iterator i;
|
||||||
@@ -197,6 +225,69 @@ DirContainer::Iterator i;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Dirs::MakePath(const std::vector<Item*> dir_tab, std::wstring & path, bool clear_path)
|
||||||
|
{
|
||||||
|
if( clear_path )
|
||||||
|
path.clear();
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<dir_tab.size() ; ++i)
|
||||||
|
{
|
||||||
|
path += dir_tab[i]->url;
|
||||||
|
path += '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
size_t Dirs::DirLevel(long id)
|
||||||
|
{
|
||||||
|
DirContainer::Iterator i;
|
||||||
|
size_t level = 0;
|
||||||
|
|
||||||
|
while( true )
|
||||||
|
{
|
||||||
|
i = dir_tab.FindId(id);
|
||||||
|
|
||||||
|
if( i == dir_tab.End() ||
|
||||||
|
i->parent_id == id ) // means a loop (something wrong in the db)
|
||||||
|
{
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( i->parent_id == -1 )
|
||||||
|
return level;
|
||||||
|
|
||||||
|
id = i->parent_id;
|
||||||
|
level += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Dirs::IsChild(long parent_id, long child_id)
|
||||||
|
{
|
||||||
|
if( child_id == parent_id )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DirContainer::Iterator i;
|
||||||
|
|
||||||
|
while( child_id != -1 )
|
||||||
|
{
|
||||||
|
i = dir_tab.FindId(child_id);
|
||||||
|
|
||||||
|
if( i == dir_tab.End() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( i->parent_id == parent_id )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
child_id = i->parent_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::ChangeParent(long dir_id, long new_parent_id)
|
bool Dirs::ChangeParent(long dir_id, long new_parent_id)
|
||||||
{
|
{
|
||||||
return dir_tab.ChangeParent(dir_id, new_parent_id);
|
return dir_tab.ChangeParent(dir_id, new_parent_id);
|
||||||
@@ -288,7 +379,7 @@ return &(*etc);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Item * Dirs::GetDir(const std::wstring & name, long parent)
|
Item * Dirs::GetDir(const wchar_t * name, long parent)
|
||||||
{
|
{
|
||||||
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
|
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
|
||||||
|
|
||||||
@@ -300,9 +391,18 @@ return 0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Item * Dirs::GetDir(const std::wstring & name, long parent)
|
||||||
Item * Dirs::GetDir(const std::wstring & path)
|
|
||||||
{
|
{
|
||||||
|
return GetDir(name.c_str(), parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Item * Dirs::GetDir(const wchar_t * path)
|
||||||
|
{
|
||||||
|
if( *path == 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
DirContainer::Iterator root = dir_tab.GetRoot();
|
DirContainer::Iterator root = dir_tab.GetRoot();
|
||||||
|
|
||||||
if( root == dir_tab.End() )
|
if( root == dir_tab.End() )
|
||||||
@@ -310,13 +410,11 @@ Item * Dirs::GetDir(const std::wstring & path)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Item * pitem = &(*root);
|
Item * pitem = &(*root);
|
||||||
|
const wchar_t * s = path;
|
||||||
|
|
||||||
std::wstring name; // !! dodac jako skladowa klasy
|
while( ExtractName(s, get_dir_temp) )
|
||||||
const wchar_t * s = path.c_str();
|
|
||||||
|
|
||||||
while( ExtractName(s, name) )
|
|
||||||
{
|
{
|
||||||
pitem = GetDir(name, pitem->id);
|
pitem = GetDir(get_dir_temp, pitem->id);
|
||||||
|
|
||||||
if( !pitem )
|
if( !pitem )
|
||||||
return 0;
|
return 0;
|
||||||
@@ -326,6 +424,13 @@ return pitem;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Item * Dirs::GetDir(const std::wstring & path)
|
||||||
|
{
|
||||||
|
return GetDir(path.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Item * Dirs::GetDir(long id)
|
Item * Dirs::GetDir(long id)
|
||||||
{
|
{
|
||||||
DirContainer::Iterator i = dir_tab.FindId(id);
|
DirContainer::Iterator i = dir_tab.FindId(id);
|
||||||
@@ -440,14 +545,18 @@ void Dirs::CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
size_t Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to)
|
!! IMPROVE ME
|
||||||
|
may dir_tab can be empty when link_to is not relative?
|
||||||
|
and now the algorith doesn't check if link_to is not relative (it only uses dir_tab)
|
||||||
|
*/
|
||||||
|
bool Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to, size_t & i)
|
||||||
{
|
{
|
||||||
if( dir_tab.empty() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
size_t i = 0;
|
|
||||||
size_t old_i;
|
size_t old_i;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
if( dir_tab.empty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
@@ -455,7 +564,7 @@ size_t Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_
|
|||||||
for( ; i<link_to.size() && link_to[i] == '/' ; ++i);
|
for( ; i<link_to.size() && link_to[i] == '/' ; ++i);
|
||||||
|
|
||||||
if( i == link_to.size() )
|
if( i == link_to.size() )
|
||||||
return i; // end of the path
|
return true; // end of the path
|
||||||
|
|
||||||
// creating a name
|
// creating a name
|
||||||
old_i = i;
|
old_i = i;
|
||||||
@@ -464,13 +573,27 @@ size_t Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_
|
|||||||
for( ; i<link_to.size() && link_to[i] != '/' ; ++i)
|
for( ; i<link_to.size() && link_to[i] != '/' ; ++i)
|
||||||
analyze_temp += link_to[i];
|
analyze_temp += link_to[i];
|
||||||
|
|
||||||
|
if( analyze_temp == L".." )
|
||||||
|
{
|
||||||
|
if( dir_tab.size() <= 1 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dir_tab.pop_back();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( analyze_temp != L"." )
|
||||||
|
{
|
||||||
Item * pdir = GetDir(analyze_temp, dir_tab.back()->id);
|
Item * pdir = GetDir(analyze_temp, dir_tab.back()->id);
|
||||||
|
|
||||||
if( !pdir )
|
if( !pdir )
|
||||||
return old_i; // analyze_temp is not a directory
|
{
|
||||||
|
i = old_i;
|
||||||
|
return true; // analyze_temp is not a directory
|
||||||
|
}
|
||||||
|
|
||||||
dir_tab.push_back(pdir);
|
dir_tab.push_back(pdir);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -480,7 +603,10 @@ size_t Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_
|
|||||||
|
|
||||||
int Dirs::FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item)
|
int Dirs::FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item)
|
||||||
{
|
{
|
||||||
size_t i = AnalyzeDir(dir_tab, link_to);
|
size_t i;
|
||||||
|
|
||||||
|
if( !AnalyzeDir(dir_tab, link_to, i) )
|
||||||
|
return 2; // incorrect link_to
|
||||||
|
|
||||||
if( i < link_to.size() )
|
if( i < link_to.size() )
|
||||||
{
|
{
|
||||||
@@ -513,7 +639,7 @@ return 0;
|
|||||||
4 - current_dir_tab was empty
|
4 - current_dir_tab was empty
|
||||||
|
|
||||||
current_dir_tab can be the same container as out_dir_tab
|
current_dir_tab can be the same container as out_dir_tab
|
||||||
link_to can be a relative path (without the first slash)
|
link_to can be a relative path (without the first slash) and can contain ".." or "."
|
||||||
*/
|
*/
|
||||||
int Dirs::FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
int Dirs::FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
||||||
std::vector<Item*> & out_dir_tab, std::wstring & out_item)
|
std::vector<Item*> & out_dir_tab, std::wstring & out_item)
|
||||||
@@ -632,9 +758,9 @@ Item * Dirs::CreateVarDir()
|
|||||||
if( root )
|
if( root )
|
||||||
{
|
{
|
||||||
v.parent_id = root->id;
|
v.parent_id = root->id;
|
||||||
v.user_id = -1;
|
v.user_id = root->user_id;
|
||||||
v.group_id = -1;
|
v.group_id = root->group_id;
|
||||||
v.privileges = 0755;
|
v.privileges = root->privileges;
|
||||||
v.subject = L"var";
|
v.subject = L"var";
|
||||||
v.url = L"var";
|
v.url = L"var";
|
||||||
v.type = Item::dir;
|
v.type = Item::dir;
|
||||||
@@ -658,3 +784,6 @@ void Dirs::LogDir(const std::vector<Item*> & dir_tab)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+53
-4
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_dirs
|
||||||
@@ -22,7 +47,13 @@
|
|||||||
#include "notify/notify.h"
|
#include "notify/notify.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// !! IMPROVE ME
|
||||||
// we do not support '..' in a path (for simplicity and security reasons)
|
// we do not support '..' in a path (for simplicity and security reasons)
|
||||||
|
// (we will support '..' in the future)
|
||||||
|
|
||||||
|
|
||||||
class Dirs
|
class Dirs
|
||||||
@@ -40,12 +71,14 @@ public:
|
|||||||
bool IsDir(long dir_id);
|
bool IsDir(long dir_id);
|
||||||
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
|
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
|
||||||
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
|
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
|
||||||
|
void MakePath(const std::vector<Item*> dir_tab, std::wstring & path, bool clear_path = true);
|
||||||
bool ChangeParent(long dir_id, long new_parent_id);
|
bool ChangeParent(long dir_id, long new_parent_id);
|
||||||
|
|
||||||
bool HasParent(long dir_id, long parent_id);
|
bool HasParent(long dir_id, long parent_id);
|
||||||
|
|
||||||
bool DelDir(long dir_id);
|
bool DelDir(long dir_id);
|
||||||
|
|
||||||
|
// if returns true then out_dir_tab is not empty
|
||||||
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
|
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
|
||||||
|
|
||||||
void LogDir(const std::vector<Item*> & dir_tab);
|
void LogDir(const std::vector<Item*> & dir_tab);
|
||||||
@@ -65,7 +98,10 @@ public:
|
|||||||
Item * GetRootDir();
|
Item * GetRootDir();
|
||||||
Item * GetEtcDir();
|
Item * GetEtcDir();
|
||||||
Item * GetVarDir();
|
Item * GetVarDir();
|
||||||
|
|
||||||
|
Item * GetDir(const wchar_t * name, long parent);
|
||||||
Item * GetDir(const std::wstring & name, long parent);
|
Item * GetDir(const std::wstring & name, long parent);
|
||||||
|
Item * GetDir(const wchar_t * path);
|
||||||
Item * GetDir(const std::wstring & path);
|
Item * GetDir(const std::wstring & path);
|
||||||
Item * GetDir(long id);
|
Item * GetDir(long id);
|
||||||
Item * AddDir(const Item & item);
|
Item * AddDir(const Item & item);
|
||||||
@@ -77,6 +113,15 @@ public:
|
|||||||
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
||||||
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
||||||
|
|
||||||
|
// returns how many levels of directories there are
|
||||||
|
// "/" -> 0 (root dir)
|
||||||
|
// "/abc" -> 1
|
||||||
|
// "/abc/def" -> 2
|
||||||
|
size_t DirLevel(long id);
|
||||||
|
|
||||||
|
// checking if child_id is really a child of parent_id
|
||||||
|
bool IsChild(long parent_id, long child_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Cur * cur;
|
Cur * cur;
|
||||||
@@ -88,8 +133,9 @@ private:
|
|||||||
std::wstring temp_link_to;
|
std::wstring temp_link_to;
|
||||||
|
|
||||||
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
|
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
|
||||||
size_t AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to);
|
bool AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to, size_t & i);
|
||||||
std::wstring analyze_temp;
|
std::wstring analyze_temp;
|
||||||
|
std::wstring get_dir_temp;
|
||||||
|
|
||||||
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
|
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
|
||||||
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);
|
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);
|
||||||
@@ -100,4 +146,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+42
-9
@@ -1,17 +1,45 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_error
|
||||||
#define headerfile_winix_core_error
|
#define headerfile_winix_core_error
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include "log.h"
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_ERR_OK 0
|
#define WINIX_ERR_OK 0
|
||||||
//#define WINIX_ERR_INCORRECT_PATH 1
|
//#define WINIX_ERR_INCORRECT_PATH 1
|
||||||
@@ -48,10 +76,10 @@
|
|||||||
|
|
||||||
#define WINIX_ERR_NO_TICKET 24
|
#define WINIX_ERR_NO_TICKET 24
|
||||||
|
|
||||||
#define WINIX_ERR_PASSWORDS_DIFFERENT 25
|
//#define WINIX_ERR_PASSWORDS_DIFFERENT 25
|
||||||
#define WINIX_ERR_PASSWORD_TOO_SHORT 26
|
//#define WINIX_ERR_PASSWORD_TOO_SHORT 26
|
||||||
#define WINIX_ERR_USER_EXISTS 27
|
//#define WINIX_ERR_USER_EXISTS 27
|
||||||
#define WINIX_ERR_LOGIN_EMPTY 28
|
//#define WINIX_ERR_LOGIN_EMPTY 28
|
||||||
#define WINIX_DIFFERENT_MOUNT_POINTS 29
|
#define WINIX_DIFFERENT_MOUNT_POINTS 29
|
||||||
|
|
||||||
|
|
||||||
@@ -68,11 +96,16 @@
|
|||||||
|
|
||||||
//#define WINIX_ERR_UNKNOWN 1000
|
//#define WINIX_ERR_UNKNOWN 1000
|
||||||
#define WINIX_NOTHING_TO_DO 109
|
#define WINIX_NOTHING_TO_DO 109
|
||||||
|
#define WINIX_ERR_INCORRECT_URI 110
|
||||||
|
|
||||||
|
#define WINIX_ERR_INTERNAL_ERROR 2000
|
||||||
|
|
||||||
|
|
||||||
typedef int Error;
|
typedef int Error;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_getparser
|
|
||||||
#define headerfile_winix_core_getparser
|
|
||||||
|
|
||||||
#include "httpsimpleparser.h"
|
|
||||||
#include "requesttypes.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "utf8.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
|
||||||
class GetParser : public HttpSimpleParser
|
|
||||||
{
|
|
||||||
|
|
||||||
const char * get_string;
|
|
||||||
GetTab * get_tab;
|
|
||||||
std::wstring temp;
|
|
||||||
bool input_as_utf8;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
virtual int GetChar()
|
|
||||||
{
|
|
||||||
if( !get_string || *get_string == 0 )
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return (int)(unsigned char)*(get_string++);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
virtual void Parameter(std::string &, std::string & value)
|
|
||||||
{
|
|
||||||
if( input_as_utf8 )
|
|
||||||
Ezc::UTF8ToWide(value, temp);
|
|
||||||
else
|
|
||||||
AssignString(value, temp);
|
|
||||||
|
|
||||||
get_tab->push_back(temp);
|
|
||||||
log << log2 << "Get, value: \"" << temp << "\"" << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
GetParser()
|
|
||||||
{
|
|
||||||
HttpSimpleParser::separator = '/';
|
|
||||||
HttpSimpleParser::read_name = false;
|
|
||||||
input_as_utf8 = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UTF8(bool utf)
|
|
||||||
{
|
|
||||||
input_as_utf8 = utf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get_string_ can be null
|
|
||||||
void Parse(const char * get_string_, GetTab & get_tab_)
|
|
||||||
{
|
|
||||||
get_string = get_string_;
|
|
||||||
get_tab = &get_tab_;
|
|
||||||
|
|
||||||
if( get_string && *get_string == separator )
|
|
||||||
{
|
|
||||||
// skipping one '/' at the beginning
|
|
||||||
++get_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpSimpleParser::Parse();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+34
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_group
|
||||||
@@ -14,6 +39,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Group
|
struct Group
|
||||||
{
|
{
|
||||||
@@ -38,6 +67,8 @@ struct Group
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+34
-24
@@ -1,15 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "groups.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Groups::Groups()
|
Groups::Groups()
|
||||||
@@ -86,31 +114,13 @@ Groups::SizeType Groups::Size()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Group & Groups::operator[](Groups::SizeType pos)
|
bool Groups::Remove(long group_id)
|
||||||
{
|
{
|
||||||
return table[pos];
|
return table.Remove(group_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+34
-6
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_groups
|
||||||
@@ -17,6 +42,10 @@
|
|||||||
#include "db/db.h"
|
#include "db/db.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Groups
|
class Groups
|
||||||
{
|
{
|
||||||
@@ -38,15 +67,14 @@ public:
|
|||||||
Iterator Begin();
|
Iterator Begin();
|
||||||
Iterator End();
|
Iterator End();
|
||||||
SizeType Size();
|
SizeType Size();
|
||||||
Group & operator[](SizeType pos);
|
bool Remove(long group_id);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+139
-14
@@ -1,16 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "htmlfilter.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void HTMLFilter::Item::Clear()
|
void HTMLFilter::Item::Clear()
|
||||||
{
|
{
|
||||||
name.clear();
|
name.clear();
|
||||||
@@ -193,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)
|
HTMLFilter::Item & HTMLFilter::GetItem(size_t i)
|
||||||
{
|
{
|
||||||
@@ -340,7 +378,6 @@ void HTMLFilter::PutLastTagWithClosingTag()
|
|||||||
{
|
{
|
||||||
const wchar_t * start = pchar;
|
const wchar_t * start = pchar;
|
||||||
|
|
||||||
|
|
||||||
while( *pchar != 0 )
|
while( *pchar != 0 )
|
||||||
{
|
{
|
||||||
if( IsOpeningTagMark() )
|
if( IsOpeningTagMark() )
|
||||||
@@ -362,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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -444,16 +506,34 @@ void HTMLFilter::ReadItemAttrValue(bool has_quote)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
// sprawdzic to wszedzie bo teraz jest tablica
|
||||||
attr_value.clear();
|
attr_value.clear();
|
||||||
|
attr_value_temp.clear();
|
||||||
|
|
||||||
// !! moze dodac obsluge escepowania cudzyslowu? sprawdzic czy to jest dostepne w htmlu
|
// !! dodac obsluge pojedynczego cudzyslowu
|
||||||
for( i=0 ; *pchar && *pchar != '\"' && !IsClosingTagMark() && (has_quote || (*pchar!=10 && !IsWhite(*pchar)) ); ++i )
|
|
||||||
|
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 )
|
if( i < WINIX_HTMLFILTER_ATTR_VALUE_MAXLEN )
|
||||||
attr_value += *pchar;
|
attr_value_temp += *pchar;
|
||||||
|
|
||||||
++pchar;
|
++pchar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( !attr_value_temp.empty() )
|
||||||
|
{
|
||||||
|
attr_value.push_back(attr_value_temp);
|
||||||
|
attr_value_temp.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -715,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)
|
bool HTMLFilter::IsTagSafe(const wchar_t * tag)
|
||||||
{
|
{
|
||||||
if( !safe_mode )
|
if( !safe_mode )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if( IsNameEqual(tag, no_filter_tag.c_str()) )
|
||||||
|
return false;
|
||||||
|
|
||||||
static const wchar_t * unsafe_tags[] = {
|
static const wchar_t * unsafe_tags[] = {
|
||||||
L"script", L"iframe", L"frame", L"frameset",
|
L"applet", L"base", L"body",
|
||||||
L"applet", L"head", L"meta", L"html", L"link", 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*);
|
size_t len = sizeof(unsafe_tags) / sizeof(const wchar_t*);
|
||||||
@@ -750,7 +838,8 @@ bool HTMLFilter::IsTagSafe(const std::wstring & tag)
|
|||||||
bool HTMLFilter::PutOpeningTag()
|
bool HTMLFilter::PutOpeningTag()
|
||||||
{
|
{
|
||||||
if( !IsTagSafe(LastItem().name) )
|
if( !IsTagSafe(LastItem().name) )
|
||||||
// dodac tutaj skipniecie calego tagu
|
// !! IMPROVE ME
|
||||||
|
// !! dodac tutaj skipniecie calego tagu
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
PutOpeningTagMark();
|
PutOpeningTagMark();
|
||||||
@@ -940,6 +1029,9 @@ const wchar_t * last_non_white = pchar;
|
|||||||
|
|
||||||
bool HTMLFilter::PrintOpeningItem()
|
bool HTMLFilter::PrintOpeningItem()
|
||||||
{
|
{
|
||||||
|
if( IsNameEqual(no_filter_tag, LastItem().name) )
|
||||||
|
return true;
|
||||||
|
|
||||||
if( last_new_line )
|
if( last_new_line )
|
||||||
{
|
{
|
||||||
PutNewLine();
|
PutNewLine();
|
||||||
@@ -976,6 +1068,8 @@ bool HTMLFilter::ReadItemAttr()
|
|||||||
pchar += 1; // skipping '='
|
pchar += 1; // skipping '='
|
||||||
SkipWhiteLines();
|
SkipWhiteLines();
|
||||||
|
|
||||||
|
|
||||||
|
// !! dodac obsluge pojedynczego cudzyslowu
|
||||||
bool has_quote = (*pchar == '\"');
|
bool has_quote = (*pchar == '\"');
|
||||||
|
|
||||||
if( has_quote )
|
if( has_quote )
|
||||||
@@ -996,7 +1090,11 @@ bool HTMLFilter::CheckItemAttr()
|
|||||||
if( attr_has_value && IsNameEqual(L"lang", attr_name) )
|
if( attr_has_value && IsNameEqual(L"lang", attr_name) )
|
||||||
{
|
{
|
||||||
LastItem().porphans = 0;
|
LastItem().porphans = 0;
|
||||||
attr_value_lower = attr_value;
|
|
||||||
|
if( !attr_value.empty() )
|
||||||
|
{
|
||||||
|
// we are taking the first value only
|
||||||
|
attr_value_lower = attr_value[0];
|
||||||
ToLower(attr_value_lower);
|
ToLower(attr_value_lower);
|
||||||
|
|
||||||
OrphansTab::iterator i = orphans_tab.find(attr_value_lower);
|
OrphansTab::iterator i = orphans_tab.find(attr_value_lower);
|
||||||
@@ -1004,20 +1102,34 @@ bool HTMLFilter::CheckItemAttr()
|
|||||||
if( i != orphans_tab.end() )
|
if( i != orphans_tab.end() )
|
||||||
LastItem().porphans = &i->second;
|
LastItem().porphans = &i->second;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HTMLFilter::PrinItemAttr()
|
void HTMLFilter::PrintItemAttr()
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if( IsNameEqual(no_filter_tag, LastItem().name) )
|
||||||
|
return;
|
||||||
|
|
||||||
Put(' ');
|
Put(' ');
|
||||||
Put(attr_name);
|
Put(attr_name);
|
||||||
|
|
||||||
if( attr_has_value )
|
if( attr_has_value )
|
||||||
{
|
{
|
||||||
Put(L"=\"");
|
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('\"');
|
Put('\"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1059,16 +1171,19 @@ void HTMLFilter::ReadItemOpening()
|
|||||||
while( ReadItemAttr() )
|
while( ReadItemAttr() )
|
||||||
{
|
{
|
||||||
if( CheckItemAttr() )
|
if( CheckItemAttr() )
|
||||||
PrinItemAttr();
|
PrintItemAttr();
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipAndCheckClosingTag(); // here LastItem().type can be changed to 'simple'
|
SkipAndCheckClosingTag(); // here LastItem().type can be changed to 'simple'
|
||||||
|
|
||||||
|
if( !IsNameEqual(no_filter_tag, LastItem().name) )
|
||||||
|
{
|
||||||
if( LastItem().type == Item::simple )
|
if( LastItem().type == Item::simple )
|
||||||
Put(L" /");
|
Put(L" /");
|
||||||
|
|
||||||
PutClosingTagMark();
|
PutClosingTagMark();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1191,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
|
// checking exceptions for opening tags
|
||||||
void HTMLFilter::CheckExceptions()
|
void HTMLFilter::CheckExceptions()
|
||||||
@@ -1202,6 +1322,7 @@ void HTMLFilter::CheckExceptions()
|
|||||||
IsLastTag(L"img") ||
|
IsLastTag(L"img") ||
|
||||||
IsLastTag(L"link") ||
|
IsLastTag(L"link") ||
|
||||||
IsLastTag(L"param") ||
|
IsLastTag(L"param") ||
|
||||||
|
IsLastTag(L"col") ||
|
||||||
IsLastTag(L"area") )
|
IsLastTag(L"area") )
|
||||||
{
|
{
|
||||||
LastItem().type = Item::simple;
|
LastItem().type = Item::simple;
|
||||||
@@ -1216,6 +1337,9 @@ void HTMLFilter::CheckExceptions()
|
|||||||
if( IsLastTag(L"pre") || IsLastTag(L"textarea") )
|
if( IsLastTag(L"pre") || IsLastTag(L"textarea") )
|
||||||
PutLastTagWithClosingTag();
|
PutLastTagWithClosingTag();
|
||||||
|
|
||||||
|
if( IsLastTag(no_filter_tag) )
|
||||||
|
PutTextBetweenLastTagWithClosingTag();
|
||||||
|
|
||||||
if( IsLastTag(L"body") )
|
if( IsLastTag(L"body") )
|
||||||
LastItem().has_body_tag = true;
|
LastItem().has_body_tag = true;
|
||||||
}
|
}
|
||||||
@@ -1396,4 +1520,5 @@ void HTMLFilter::Read()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+52
-5
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_htmlfilter
|
||||||
@@ -16,6 +41,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// max length of a name of a html tag (with terminating null)
|
// max length of a name of a html tag (with terminating null)
|
||||||
@@ -106,6 +135,11 @@ public:
|
|||||||
void InsertTabs(size_t tabsize);
|
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
|
// orphans are checked only in 'body' tag
|
||||||
void AssignOrphans(const wchar_t * lang_code, const std::vector<std::wstring> & otab);
|
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);
|
void AssignOrphans(const std::wstring & lang_code, const std::vector<std::wstring> & otab);
|
||||||
@@ -139,6 +173,9 @@ protected:
|
|||||||
typedef std::map<std::wstring, Orphans> OrphansTab;
|
typedef std::map<std::wstring, Orphans> OrphansTab;
|
||||||
OrphansTab orphans_tab;
|
OrphansTab orphans_tab;
|
||||||
|
|
||||||
|
// html <nofilter> tag name
|
||||||
|
std::wstring no_filter_tag;
|
||||||
|
|
||||||
|
|
||||||
struct Item
|
struct Item
|
||||||
{
|
{
|
||||||
@@ -169,6 +206,10 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
virtual methods
|
virtual methods
|
||||||
*/
|
*/
|
||||||
@@ -219,6 +260,7 @@ protected:
|
|||||||
bool IsNameEqual(const std::wstring & name1, const std::wstring & name2, size_t len);
|
bool IsNameEqual(const std::wstring & name1, const std::wstring & name2, size_t len);
|
||||||
|
|
||||||
bool IsLastTag(const wchar_t * name);
|
bool IsLastTag(const wchar_t * name);
|
||||||
|
bool IsLastTag(const std::wstring & name);
|
||||||
bool IsTagSafe(const wchar_t * tag);
|
bool IsTagSafe(const wchar_t * tag);
|
||||||
bool IsTagSafe(const std::wstring & tag);
|
bool IsTagSafe(const std::wstring & tag);
|
||||||
|
|
||||||
@@ -250,7 +292,7 @@ protected:
|
|||||||
|
|
||||||
bool ReadItemAttr();
|
bool ReadItemAttr();
|
||||||
bool CheckItemAttr();
|
bool CheckItemAttr();
|
||||||
void PrinItemAttr();
|
void PrintItemAttr();
|
||||||
|
|
||||||
void ReadItemClosing();
|
void ReadItemClosing();
|
||||||
void ReadItemSpecial();
|
void ReadItemSpecial();
|
||||||
@@ -266,6 +308,7 @@ protected:
|
|||||||
void PutNormalNonWhite(const wchar_t * & str, const wchar_t * end);
|
void PutNormalNonWhite(const wchar_t * & str, const wchar_t * end);
|
||||||
void PutNormalWhite(const wchar_t * & str, const wchar_t * end);
|
void PutNormalWhite(const wchar_t * & str, const wchar_t * end);
|
||||||
void PutLastTagWithClosingTag();
|
void PutLastTagWithClosingTag();
|
||||||
|
void PutTextBetweenLastTagWithClosingTag();
|
||||||
void PutTabs(size_t len);
|
void PutTabs(size_t len);
|
||||||
void PutNonBreakingSpace();
|
void PutNonBreakingSpace();
|
||||||
void PutNewLine();
|
void PutNewLine();
|
||||||
@@ -284,7 +327,8 @@ protected:
|
|||||||
size_t tab_size;
|
size_t tab_size;
|
||||||
OrphanMode orphan_mode;
|
OrphanMode orphan_mode;
|
||||||
std::wstring attr_name;
|
std::wstring attr_name;
|
||||||
std::wstring attr_value;
|
std::vector<std::wstring> attr_value;
|
||||||
|
std::wstring attr_value_temp;
|
||||||
std::wstring attr_value_lower;
|
std::wstring attr_value_lower;
|
||||||
bool attr_has_value;
|
bool attr_has_value;
|
||||||
std::wstring lang_code_lower;
|
std::wstring lang_code_lower;
|
||||||
@@ -295,5 +339,8 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+102
-64
@@ -1,23 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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 "httpsimpleparser.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "utf8/utf8.h"
|
||||||
|
|
||||||
|
|
||||||
void HttpSimpleParser::ToLower(std::string & s)
|
|
||||||
|
namespace Winix
|
||||||
{
|
{
|
||||||
std::string::iterator i;
|
|
||||||
|
|
||||||
for(i=s.begin() ; i!= s.end() ; ++i)
|
|
||||||
|
|
||||||
|
|
||||||
|
void HttpSimpleParser::ToLower(std::wstring & s)
|
||||||
|
{
|
||||||
|
for(wchar_t & c : s)
|
||||||
{
|
{
|
||||||
if( *i>='A' && *i<='Z' )
|
if( c>='A' && c<='Z' )
|
||||||
*i = *i - 'A' + 'a';
|
c = c - 'A' + 'a';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,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)
|
int HttpSimpleParser::ParseHalfHex(int c)
|
||||||
@@ -121,33 +121,42 @@ void HttpSimpleParser::CheckSpecialChar()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void HttpSimpleParser::ReadName()
|
void HttpSimpleParser::ReadName()
|
||||||
{
|
{
|
||||||
// we're checking 'separator' and '=' because the string is allowed not having '=' (the value is optional)
|
// 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() )
|
for( ; last_c!=-1 && last_c!=separator && last_c!='=' ; last_c = GetChar() )
|
||||||
{
|
{
|
||||||
if( recognize_special_chars )
|
if( recognize_special_chars )
|
||||||
CheckSpecialChar();
|
CheckSpecialChar();
|
||||||
|
|
||||||
if( last_c != -1 )
|
if( last_c != -1 )
|
||||||
|
{
|
||||||
|
if( getchar_returns_utf8_chars )
|
||||||
|
utf8_token += last_c;
|
||||||
|
else
|
||||||
last_name += last_c;
|
last_name += last_c;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( getchar_returns_utf8_chars )
|
||||||
|
PT::UTF8ToWide(utf8_token, last_name);
|
||||||
|
|
||||||
if( last_c == '=' )
|
if( last_c == '=' )
|
||||||
last_c = GetChar();
|
last_c = GetChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void HttpSimpleParser::ReadQuotedValue()
|
void HttpSimpleParser::ReadQuotedValue()
|
||||||
{
|
{
|
||||||
// skipping '"'
|
// skipping '"'
|
||||||
last_c = GetChar();
|
last_c = GetChar();
|
||||||
|
utf8_token.clear();
|
||||||
|
last_value.clear();
|
||||||
|
|
||||||
for( ; last_c!=-1 && last_c!='"' ; last_c = GetChar() )
|
for( ; last_c!=-1 && last_c!='"' ; last_c = GetChar() )
|
||||||
{
|
{
|
||||||
@@ -155,9 +164,16 @@ void HttpSimpleParser::ReadQuotedValue()
|
|||||||
CheckSpecialChar();
|
CheckSpecialChar();
|
||||||
|
|
||||||
if( last_c != -1 )
|
if( last_c != -1 )
|
||||||
|
{
|
||||||
|
if( getchar_returns_utf8_chars )
|
||||||
|
utf8_token += last_c;
|
||||||
|
else
|
||||||
last_value += last_c;
|
last_value += last_c;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( getchar_returns_utf8_chars )
|
||||||
|
PT::UTF8ToWide(utf8_token, last_value);
|
||||||
|
|
||||||
if( last_c == '"' )
|
if( last_c == '"' )
|
||||||
last_c = GetChar();
|
last_c = GetChar();
|
||||||
@@ -168,27 +184,40 @@ void HttpSimpleParser::ReadQuotedValue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HttpSimpleParser::ReadValue()
|
void HttpSimpleParser::ReadNormalValue()
|
||||||
{
|
{
|
||||||
if( skip_white_chars )
|
utf8_token.clear();
|
||||||
SkipWhiteChars();
|
last_value.clear();
|
||||||
|
|
||||||
if( value_can_be_quoted && last_c == '"' )
|
|
||||||
{
|
|
||||||
ReadQuotedValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() )
|
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() )
|
||||||
{
|
{
|
||||||
if( recognize_special_chars )
|
if( recognize_special_chars )
|
||||||
CheckSpecialChar();
|
CheckSpecialChar();
|
||||||
|
|
||||||
if( last_c != -1 )
|
if( last_c != -1 )
|
||||||
|
{
|
||||||
|
if( getchar_returns_utf8_chars )
|
||||||
|
utf8_token += last_c;
|
||||||
|
else
|
||||||
last_value += last_c;
|
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
|
||||||
|
ReadNormalValue();
|
||||||
|
|
||||||
|
|
||||||
if( last_c == separator )
|
if( last_c == separator )
|
||||||
last_c = GetChar();
|
last_c = GetChar();
|
||||||
@@ -197,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()
|
void HttpSimpleParser::Parse()
|
||||||
{
|
{
|
||||||
for( last_c = GetChar() ; last_c != -1 ; )
|
for( last_c = GetChar() ; last_c != -1 ; )
|
||||||
@@ -211,25 +255,19 @@ void HttpSimpleParser::Parse()
|
|||||||
|
|
||||||
if( skip_white_chars )
|
if( skip_white_chars )
|
||||||
{
|
{
|
||||||
TrimWhiteChars(last_name);
|
TrimWhite(last_name);
|
||||||
TrimWhiteChars(last_value);
|
TrimWhite(last_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Parameter(last_name, last_value); // user definied function
|
Parameter(last_name, last_value); // user definied function
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+48
-9
@@ -1,19 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_httpsimpleparser
|
||||||
#define headerfile_winix_core_httpsimpleparser
|
#define headerfile_winix_core_httpsimpleparser
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class HttpSimpleParser
|
class HttpSimpleParser
|
||||||
{
|
{
|
||||||
@@ -24,26 +52,33 @@ protected:
|
|||||||
bool skip_white_chars;
|
bool skip_white_chars;
|
||||||
bool recognize_special_chars;
|
bool recognize_special_chars;
|
||||||
|
|
||||||
|
// 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);
|
int ParseHalfHex(int c);
|
||||||
void ReadName();
|
void ReadName();
|
||||||
void ReadQuotedValue();
|
void ReadQuotedValue();
|
||||||
|
void ReadNormalValue();
|
||||||
void ReadValue();
|
void ReadValue();
|
||||||
|
void Clear();
|
||||||
|
|
||||||
std::string last_name;
|
std::wstring last_name;
|
||||||
std::string last_value;
|
std::wstring last_value;
|
||||||
|
std::string utf8_token;
|
||||||
|
|
||||||
int last_c;
|
int last_c;
|
||||||
int separator;
|
int separator;
|
||||||
|
|
||||||
// '-1' means end (eof)
|
// '-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 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);
|
bool IsWhite(int c);
|
||||||
|
|
||||||
void SkipWhiteChars();
|
void SkipWhiteChars();
|
||||||
void TrimWhiteChars(std::string & s);
|
|
||||||
void CheckSpecialChar();
|
void CheckSpecialChar();
|
||||||
|
|
||||||
void Parse();
|
void Parse();
|
||||||
@@ -59,10 +94,14 @@ public:
|
|||||||
value_can_be_quoted = false;
|
value_can_be_quoted = false;
|
||||||
skip_white_chars = false;
|
skip_white_chars = false;
|
||||||
recognize_special_chars = true;
|
recognize_special_chars = true;
|
||||||
|
getchar_returns_utf8_chars = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Executable
+631
@@ -0,0 +1,631 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-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>
|
||||||
|
#include "image.h"
|
||||||
|
#include "utf8/utf8.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "system.h"
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "lock.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Image::SetDb(Db * pdb)
|
||||||
|
{
|
||||||
|
db = pdb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Image::SetConfig(Config * pconfig)
|
||||||
|
{
|
||||||
|
config = pconfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Image::SetSystem(System * psystem)
|
||||||
|
{
|
||||||
|
system = psystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
Image::Scale Image::GetImageScale(long dir_id)
|
||||||
|
{
|
||||||
|
Scale scale;
|
||||||
|
|
||||||
|
Mount * m = system->mounts.CalcMount(dir_id);
|
||||||
|
scale.cx = config->image_cx;
|
||||||
|
scale.cy = config->image_cy;
|
||||||
|
scale.aspect_mode = config->image_mode;
|
||||||
|
scale.quality = config->image_quality;
|
||||||
|
|
||||||
|
// reading width and height from the mount point (if exists)
|
||||||
|
int index = system->mounts.MountParImageSize();
|
||||||
|
|
||||||
|
if( m && m->param[index].defined && m->param[index].arg.size() == 2 )
|
||||||
|
{
|
||||||
|
scale.cx = Tol(m->param[index].arg[0]);
|
||||||
|
scale.cy = Tol(m->param[index].arg[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reading image mode from the mount point (if exists)
|
||||||
|
index = system->mounts.MountParImageMode();
|
||||||
|
|
||||||
|
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||||
|
scale.aspect_mode = Toi(m->param[index].arg[0]);
|
||||||
|
|
||||||
|
// reading image quality from the mount point (if exists)
|
||||||
|
index = system->mounts.MountParImageQuality();
|
||||||
|
|
||||||
|
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||||
|
scale.quality = Toi(m->param[index].arg[0]);
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
Image::Scale Image::GetThumbScale(long dir_id)
|
||||||
|
{
|
||||||
|
Scale scale;
|
||||||
|
|
||||||
|
Mount * m = system->mounts.CalcMount(dir_id);
|
||||||
|
scale.cx = config->thumb_cx;
|
||||||
|
scale.cy = config->thumb_cy;
|
||||||
|
scale.aspect_mode = config->thumb_mode;
|
||||||
|
scale.quality = config->thumb_quality;
|
||||||
|
|
||||||
|
// reading width and height from the mount point (if exists)
|
||||||
|
int index = system->mounts.MountParThumbSize();
|
||||||
|
|
||||||
|
if( m && m->param[index].defined && m->param[index].arg.size() == 2 )
|
||||||
|
{
|
||||||
|
scale.cx = Tol(m->param[index].arg[0]);
|
||||||
|
scale.cy = Tol(m->param[index].arg[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reading thumb mode from the mount point (if exists)
|
||||||
|
index = system->mounts.MountParThumbMode();
|
||||||
|
|
||||||
|
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||||
|
scale.aspect_mode = Toi(m->param[index].arg[0]);
|
||||||
|
|
||||||
|
// reading image quality from the mount point (if exists)
|
||||||
|
index = system->mounts.MountParThumbQuality();
|
||||||
|
|
||||||
|
if( m && m->param[index].defined && m->param[index].arg.size() == 1 )
|
||||||
|
scale.quality = Toi(m->param[index].arg[0]);
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Image::Resize(long file_id, size_t cx, size_t cy, int aspect_mode, int quality)
|
||||||
|
{
|
||||||
|
item_temp.type = WINIX_IMAGE_TYPE_RESIZE;
|
||||||
|
item_temp.file_id = file_id;
|
||||||
|
item_temp.cx = cx;
|
||||||
|
item_temp.cy = cy;
|
||||||
|
item_temp.aspect_mode = aspect_mode;
|
||||||
|
item_temp.quality = quality;
|
||||||
|
|
||||||
|
CheckParam(item_temp);
|
||||||
|
image_tab.insert(image_tab.end(), item_temp);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Image::CreateThumb(long file_id, size_t thumb_cx, size_t thumb_cy, int aspect_mode, int quality)
|
||||||
|
{
|
||||||
|
item_temp.type = WINIX_IMAGE_TYPE_CREATE_THUMB;
|
||||||
|
item_temp.file_id = file_id;
|
||||||
|
item_temp.thumb_cx = thumb_cx;
|
||||||
|
item_temp.thumb_cy = thumb_cy;
|
||||||
|
item_temp.aspect_mode = aspect_mode;
|
||||||
|
item_temp.quality = quality;
|
||||||
|
|
||||||
|
CheckParam(item_temp);
|
||||||
|
image_tab.insert(image_tab.end(), item_temp);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Image::Crop(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy, int quality)
|
||||||
|
{
|
||||||
|
item_temp.type = WINIX_IMAGE_TYPE_CROP;
|
||||||
|
item_temp.file_id = file_id;
|
||||||
|
item_temp.xoffset = xoffset;
|
||||||
|
item_temp.yoffset = yoffset;
|
||||||
|
item_temp.cx = cx;
|
||||||
|
item_temp.cy = cy;
|
||||||
|
item_temp.quality = quality;
|
||||||
|
|
||||||
|
CheckParam(item_temp);
|
||||||
|
image_tab.insert(image_tab.end(), item_temp);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Image::CropThumb(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy, int quality)
|
||||||
|
{
|
||||||
|
item_temp.type = WINIX_IMAGE_TYPE_CROP_THUMB;
|
||||||
|
item_temp.file_id = file_id;
|
||||||
|
item_temp.xoffset = xoffset;
|
||||||
|
item_temp.yoffset = yoffset;
|
||||||
|
item_temp.cx = cx;
|
||||||
|
item_temp.cy = cy;
|
||||||
|
item_temp.quality = quality;
|
||||||
|
|
||||||
|
CheckParam(item_temp);
|
||||||
|
image_tab.insert(image_tab.end(), item_temp);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Image::CropNewThumb(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy,
|
||||||
|
size_t thumb_cx, size_t thumb_cy, int aspect_mode, int quality)
|
||||||
|
{
|
||||||
|
item_temp.type = WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB;
|
||||||
|
item_temp.file_id = file_id;
|
||||||
|
item_temp.xoffset = xoffset;
|
||||||
|
item_temp.yoffset = yoffset;
|
||||||
|
item_temp.cx = cx;
|
||||||
|
item_temp.cy = cy;
|
||||||
|
item_temp.thumb_cx = thumb_cx;
|
||||||
|
item_temp.thumb_cy = thumb_cy;
|
||||||
|
item_temp.aspect_mode = aspect_mode;
|
||||||
|
item_temp.quality = quality;
|
||||||
|
|
||||||
|
CheckParam(item_temp);
|
||||||
|
image_tab.insert(image_tab.end(), item_temp);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Image::CheckParam(ImageItem & item)
|
||||||
|
{
|
||||||
|
SetMinMax(item.aspect_mode, 1, 7);
|
||||||
|
SetMinMax(item.quality, 0, 100);
|
||||||
|
SetMinMax(item.cx, 1, 30000);
|
||||||
|
SetMinMax(item.cy, 1, 30000);
|
||||||
|
SetMinMax(item.thumb_cx, 1, 30000);
|
||||||
|
SetMinMax(item.thumb_cy, 1, 30000);
|
||||||
|
SetMinMax(item.xoffset, 0, 30000);
|
||||||
|
SetMinMax(item.yoffset, 0, 30000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects locked)
|
||||||
|
bool Image::SignalReceived()
|
||||||
|
{
|
||||||
|
return !image_tab.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects not locked)
|
||||||
|
void Image::Do()
|
||||||
|
{
|
||||||
|
ImageTab::iterator i;
|
||||||
|
bool end;
|
||||||
|
|
||||||
|
Lock();
|
||||||
|
i = image_tab.begin();
|
||||||
|
Unlock();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
class Lock lock_object(synchro);
|
||||||
|
|
||||||
|
if( i != image_tab.end() )
|
||||||
|
{
|
||||||
|
item_work = *i;
|
||||||
|
image_tab.erase(i++);
|
||||||
|
end = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
end = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock_object.Unlock();
|
||||||
|
|
||||||
|
if( !end )
|
||||||
|
CreateImage();
|
||||||
|
|
||||||
|
}
|
||||||
|
while( !end && !IsExitSignal() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Image::Add(const std::wstring & in, TextStream<std::string> & out)
|
||||||
|
{
|
||||||
|
PT::WideToUTF8(in, add_tempa);
|
||||||
|
out << add_tempa;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Image::EscapePath(const std::string & path, TextStream<std::string> & out, bool clear_stream)
|
||||||
|
{
|
||||||
|
if( clear_stream )
|
||||||
|
out.Clear();
|
||||||
|
|
||||||
|
out << '"';
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<path.size() ; ++i)
|
||||||
|
{
|
||||||
|
if( path[i] == '"' )
|
||||||
|
out << '\\';
|
||||||
|
|
||||||
|
if( path[i] != 0 )
|
||||||
|
out << path[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
out << '\"';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
from: http://www.imagemagick.org/script/command-line-processing.php#geometry
|
||||||
|
|
||||||
|
scale% Height and width both scaled by specified percentage.
|
||||||
|
scale-x%xscale-y% Height and width individually scaled by specified percentages. (Only one % symbol needed.)
|
||||||
|
width Width given, height automagically selected to preserve aspect ratio.
|
||||||
|
xheight Height given, width automagically selected to preserve aspect ratio.
|
||||||
|
widthxheight Maximum values of height and width given, aspect ratio preserved.
|
||||||
|
widthxheight^ Minimum values of width and height given, aspect ratio preserved.
|
||||||
|
widthxheight! Width and height emphatically given, original aspect ratio ignored.
|
||||||
|
widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension.
|
||||||
|
widthxheight< Change dimensions only if both image dimensions exceed specified dimensions.
|
||||||
|
*/
|
||||||
|
void Image::SelectAspect(size_t cx, size_t cy)
|
||||||
|
{
|
||||||
|
switch( item_work.aspect_mode )
|
||||||
|
{
|
||||||
|
case WINIX_IMAGE_MODE_1:
|
||||||
|
command << cx;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WINIX_IMAGE_MODE_3:
|
||||||
|
command << cx << "x" << cy;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WINIX_IMAGE_MODE_4:
|
||||||
|
command << '"' << cx << "x" << cy << "^\"";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WINIX_IMAGE_MODE_5:
|
||||||
|
command << '"' << cx << "x" << cy << "!\"";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WINIX_IMAGE_MODE_6:
|
||||||
|
command << '"' << cx << "x" << cy << ">\"";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WINIX_IMAGE_MODE_7:
|
||||||
|
command << '"' << cx << "x" << cy << "<\"";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WINIX_IMAGE_MODE_2:
|
||||||
|
default:
|
||||||
|
command << "x" << cy;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects locked)
|
||||||
|
bool Image::CreateInputFileName()
|
||||||
|
{
|
||||||
|
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB);
|
||||||
|
|
||||||
|
if( thumb && !file_work.has_thumb )
|
||||||
|
{
|
||||||
|
log << log1 << "Image: file id: " << file_work.id << ", url: " << file_work.url
|
||||||
|
<< " doesn't have a thumbnail yet (skipping)" << logend;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( system->MakeFilePath(file_work, src_path, thumb) )
|
||||||
|
{
|
||||||
|
PT::WideToUTF8(src_path, input_file_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log1 << "Image: cannot create a source path" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects locked)
|
||||||
|
void Image::CreateTmpFileName()
|
||||||
|
{
|
||||||
|
stream_tmp_path.Clear();
|
||||||
|
stream_tmp_path << config->upload_dir << L"/tmp/image_" << std::time(0);
|
||||||
|
PT::WideToUTF8(stream_tmp_path.Str(), tmp_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects are not locked)
|
||||||
|
bool Image::CreateCommand()
|
||||||
|
{
|
||||||
|
class Lock lock_object(synchro);
|
||||||
|
|
||||||
|
iq.SetAll(true, false);
|
||||||
|
iq.WhereId(item_work.file_id);
|
||||||
|
|
||||||
|
// the file could have been changed especially when there is a long queue of files
|
||||||
|
if( db->GetItem(file_work, iq) != WINIX_ERR_OK )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( !CreateInputFileName() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
command.Clear();
|
||||||
|
Add(config->convert_cmd, command);
|
||||||
|
|
||||||
|
command << " ";
|
||||||
|
EscapePath(input_file_name, command, false);
|
||||||
|
command << " -quiet -quality " << item_work.quality;
|
||||||
|
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_RESIZE )
|
||||||
|
{
|
||||||
|
command << " -resize ";
|
||||||
|
SelectAspect(item_work.cx, item_work.cy);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB )
|
||||||
|
{
|
||||||
|
command << " -strip -thumbnail ";
|
||||||
|
SelectAspect(item_work.thumb_cx, item_work.thumb_cy);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CROP )
|
||||||
|
{
|
||||||
|
command << " -crop " << item_work.cx << "x" << item_work.cy
|
||||||
|
<< "+" << item_work.xoffset << "+" << item_work.yoffset << " +repage ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB )
|
||||||
|
{
|
||||||
|
command << " -strip -crop " << item_work.cx << "x" << item_work.cy
|
||||||
|
<< "+" << item_work.xoffset << "+" << item_work.yoffset
|
||||||
|
<< " +repage ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB )
|
||||||
|
{
|
||||||
|
command << " -strip -crop " << item_work.cx << "x" << item_work.cy
|
||||||
|
<< "+" << item_work.xoffset << "+" << item_work.yoffset
|
||||||
|
<< " +repage -thumbnail ";
|
||||||
|
SelectAspect(item_work.thumb_cx, item_work.thumb_cy);
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateTmpFileName();
|
||||||
|
|
||||||
|
command << " ";
|
||||||
|
EscapePath(tmp_file_name, command, false);
|
||||||
|
|
||||||
|
log << log4 << "Image: running: " << command.Str() << logend;
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects are locked)
|
||||||
|
void Image::ImageSavedCorrectly()
|
||||||
|
{
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB )
|
||||||
|
{
|
||||||
|
if( !file_work.has_thumb )
|
||||||
|
{
|
||||||
|
file_work.has_thumb = true;
|
||||||
|
db->EditHasThumbById(true, file_work.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
|
||||||
|
plugin.Call((Session*)0, WINIX_CREATED_THUMB, &file_work);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_RESIZE )
|
||||||
|
{
|
||||||
|
log << log3 << "Image: image resized: " << dst_path << logend;
|
||||||
|
plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CROP )
|
||||||
|
{
|
||||||
|
log << log3 << "Image: image cropped: " << dst_path << logend;
|
||||||
|
// !! IMPROVE ME add a correct message
|
||||||
|
//plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB )
|
||||||
|
{
|
||||||
|
log << log3 << "Image: image thumbnail cropped: " << dst_path << logend;
|
||||||
|
// !! IMPROVE ME add a correct message
|
||||||
|
//plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB )
|
||||||
|
{
|
||||||
|
log << log3 << "Image: a new thumbnail from an original image was cropped: " << dst_path << logend;
|
||||||
|
// !! IMPROVE ME add a correct message
|
||||||
|
//plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects are not locked)
|
||||||
|
void Image::SaveImage()
|
||||||
|
{
|
||||||
|
class Lock lock_object(synchro);
|
||||||
|
|
||||||
|
// the file could have been changed especially when creating the image lasted too long
|
||||||
|
iq.SetAll(true, false);
|
||||||
|
iq.WhereId(item_work.file_id);
|
||||||
|
|
||||||
|
if( db->GetItem(file_work, iq) == WINIX_ERR_OK )
|
||||||
|
{
|
||||||
|
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB ||
|
||||||
|
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, 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
|
||||||
|
{
|
||||||
|
log << log1 << "Image: cannot move a temporary file: " << stream_tmp_path.Str()
|
||||||
|
<< ", to: " << dst_path << logend;
|
||||||
|
|
||||||
|
Winix::RemoveFile(stream_tmp_path.Str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log1 << "Image: cannot create a destination path" << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects are not locked)
|
||||||
|
void Image::CreateImage()
|
||||||
|
{
|
||||||
|
if( CreateCommand() )
|
||||||
|
{
|
||||||
|
int res = std::system(command.CStr());
|
||||||
|
|
||||||
|
if( res == 0 )
|
||||||
|
{
|
||||||
|
SaveImage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
class Lock lock_object(synchro);
|
||||||
|
log << log3 << "Image: some problems with creating an image"
|
||||||
|
<< ", 'convert' process returned: " << res << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects are not locked)
|
||||||
|
// !! there is a problem with GIF files
|
||||||
|
// Bus error (core dumped)
|
||||||
|
/*
|
||||||
|
#include "wand/MagickWand.h"
|
||||||
|
|
||||||
|
// compiler options:
|
||||||
|
// include: -I/usr/local/include/ImageMagick
|
||||||
|
// link with: `MagickWand-config --ldflags --libs`
|
||||||
|
|
||||||
|
void Image::CreateThumbnail()
|
||||||
|
{
|
||||||
|
PT::WideToUTF8(item_work.source, sourcea);
|
||||||
|
PT::WideToUTF8(item_work.dst, dsta);
|
||||||
|
|
||||||
|
MagickWandGenesis();
|
||||||
|
|
||||||
|
MagickWand * wand = NewMagickWand();
|
||||||
|
|
||||||
|
if( MagickReadImage(wand, sourcea.c_str()) )
|
||||||
|
{
|
||||||
|
MagickThumbnailImage(wand, item_work.cx, item_work.cy);
|
||||||
|
|
||||||
|
if( MagickWriteImage(wand, dsta.c_str()) )
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
|
log << log3 << "Image: created a thumbnail: " << dsta << logend;
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DestroyMagickWand(wand);
|
||||||
|
|
||||||
|
MagickWandTerminus();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
Executable
+215
@@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-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
|
||||||
|
#define headerfile_winix_core_image
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include "basethread.h"
|
||||||
|
#include "textstream.h"
|
||||||
|
#include "db/db.h"
|
||||||
|
#include "core/item.h"
|
||||||
|
#include "core/config.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class System;
|
||||||
|
|
||||||
|
|
||||||
|
// aspect modes:
|
||||||
|
// Width given, height automagically selected to preserve aspect ratio.
|
||||||
|
#define WINIX_IMAGE_MODE_1 1
|
||||||
|
|
||||||
|
// Height given, width automagically selected to preserve aspect ratio.
|
||||||
|
#define WINIX_IMAGE_MODE_2 2
|
||||||
|
|
||||||
|
// Maximum values of height and width given, aspect ratio preserved.
|
||||||
|
#define WINIX_IMAGE_MODE_3 3
|
||||||
|
|
||||||
|
// Minimum values of width and height given, aspect ratio preserved.
|
||||||
|
#define WINIX_IMAGE_MODE_4 4
|
||||||
|
|
||||||
|
// Width and height emphatically given, original aspect ratio ignored.
|
||||||
|
#define WINIX_IMAGE_MODE_5 5
|
||||||
|
|
||||||
|
// Change as per widthxheight but only if an image dimension exceeds a specified dimension.
|
||||||
|
#define WINIX_IMAGE_MODE_6 6
|
||||||
|
|
||||||
|
// Change dimensions only if both image dimensions are less than specified dimensions.
|
||||||
|
#define WINIX_IMAGE_MODE_7 7
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// resizing
|
||||||
|
#define WINIX_IMAGE_TYPE_RESIZE 1
|
||||||
|
|
||||||
|
// generating a thumbnail
|
||||||
|
#define WINIX_IMAGE_TYPE_CREATE_THUMB 2
|
||||||
|
|
||||||
|
// cropping an image
|
||||||
|
#define WINIX_IMAGE_TYPE_CROP 3
|
||||||
|
|
||||||
|
// cropping an thumbnail
|
||||||
|
#define WINIX_IMAGE_TYPE_CROP_THUMB 4
|
||||||
|
|
||||||
|
// creating by cropping a new thumbnail (from an original image)
|
||||||
|
#define WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB 5
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
class Image : public BaseThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
struct Scale
|
||||||
|
{
|
||||||
|
size_t cx;
|
||||||
|
size_t cy;
|
||||||
|
int aspect_mode;
|
||||||
|
int quality;
|
||||||
|
|
||||||
|
Scale()
|
||||||
|
{
|
||||||
|
cx = cy = 1;
|
||||||
|
aspect_mode = 2;
|
||||||
|
quality = 100;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void SetDb(Db * pdb);
|
||||||
|
void SetConfig(Config * pconfig);
|
||||||
|
void SetSystem(System * psystem);
|
||||||
|
|
||||||
|
|
||||||
|
// returning scale info for a directory
|
||||||
|
Scale GetImageScale(long dir_id);
|
||||||
|
|
||||||
|
// returning scale info (for thumbnails) for a directory
|
||||||
|
Scale GetThumbScale(long dir_id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Resize(long file_id, size_t cx, size_t cy, int aspect_mode, int quality);
|
||||||
|
|
||||||
|
// creating a new thumbnail from an original image
|
||||||
|
void CreateThumb(long file_id, size_t thumb_cx, size_t thumb_cy, int aspect_mode, int quality);
|
||||||
|
|
||||||
|
// cropping an image (the thumbnail is not changed)
|
||||||
|
void Crop(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy, int quality);
|
||||||
|
|
||||||
|
// cropping an existing thumbnail
|
||||||
|
void CropThumb(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy, int quality);
|
||||||
|
|
||||||
|
// creating and cropping a new thumbnail (from an original image)
|
||||||
|
void CropNewThumb(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy,
|
||||||
|
size_t thumb_cx, size_t thumb_cy, int aspect_mode, int quality);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Db * db;
|
||||||
|
Config * config;
|
||||||
|
System * system;
|
||||||
|
|
||||||
|
struct ImageItem
|
||||||
|
{
|
||||||
|
int type; // WINIX_IMAGE_TYPE_*
|
||||||
|
long file_id;
|
||||||
|
size_t cx;
|
||||||
|
size_t cy;
|
||||||
|
size_t xoffset; // xoffset and yoffset are used when cropping
|
||||||
|
size_t yoffset;
|
||||||
|
size_t thumb_cx;
|
||||||
|
size_t thumb_cy;
|
||||||
|
int aspect_mode;
|
||||||
|
int quality;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename int_type>
|
||||||
|
void SetMinMax(int_type & var, int var_min, int var_max)
|
||||||
|
{
|
||||||
|
if( static_cast<int>(var) < var_min )
|
||||||
|
var = var_min;
|
||||||
|
|
||||||
|
if( static_cast<int>(var) > var_max )
|
||||||
|
var = var_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// queue of thumbnails to create
|
||||||
|
typedef std::list<ImageItem> ImageTab;
|
||||||
|
ImageTab image_tab;
|
||||||
|
ImageItem item_temp;
|
||||||
|
|
||||||
|
// only for second thread
|
||||||
|
ImageItem item_work;
|
||||||
|
std::wstring src_path, dst_path;
|
||||||
|
TextStream<std::string> command;
|
||||||
|
TextStream<std::wstring> stream_tmp_path;
|
||||||
|
DbItemQuery iq;
|
||||||
|
std::string add_tempa;
|
||||||
|
std::string input_file_name;
|
||||||
|
std::string tmp_file_name;
|
||||||
|
Item file_work;
|
||||||
|
|
||||||
|
virtual bool SignalReceived();
|
||||||
|
virtual void Do();
|
||||||
|
bool CreateCommand();
|
||||||
|
bool CreateInputFileName();
|
||||||
|
void CreateTmpFileName();
|
||||||
|
void SaveImage();
|
||||||
|
void CreateImage();
|
||||||
|
void SelectAspect(size_t cx, size_t cy);
|
||||||
|
void EscapePath(const std::string & path, TextStream<std::string> & out, bool clear_stream = true);
|
||||||
|
void CheckParam(ImageItem & item);
|
||||||
|
void Add(const std::wstring & in, TextStream<std::string> & out);
|
||||||
|
void ImageSavedCorrectly();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
+185
@@ -0,0 +1,185 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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_ipban
|
||||||
|
#define headerfile_winix_core_ipban
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// telling if the IPBan record is active
|
||||||
|
// we have two records: active and non active
|
||||||
|
// non active records is something like a history
|
||||||
|
// it is used to remember the last ban level
|
||||||
|
// so based on this in the future a next greater ban can be calculated
|
||||||
|
#define WINIX_IPBAN_FLAG_ACTIVE 1
|
||||||
|
|
||||||
|
// current ban level
|
||||||
|
// (if one of these flag is set and the record is active then it means the IP is banned at the moment)
|
||||||
|
// level 1: banned for short time
|
||||||
|
// level 2: can be set after level 1 has expired and the attacker still have not given up
|
||||||
|
// banned for some longer time in level 1
|
||||||
|
// level 3: can be set after level 2
|
||||||
|
// banned for much more time
|
||||||
|
#define WINIX_IPBAN_FLAG_BAN_LEVEL1 2
|
||||||
|
#define WINIX_IPBAN_FLAG_BAN_LEVEL2 4
|
||||||
|
#define WINIX_IPBAN_FLAG_BAN_LEVEL3 8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct defining some restrictions to an IP address
|
||||||
|
*/
|
||||||
|
struct IPBan
|
||||||
|
{
|
||||||
|
// at the moment only IPv4 are supported
|
||||||
|
int ip;
|
||||||
|
|
||||||
|
// one or more flags from WINIX_IPBAN_FLAG_*
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
// when this record was last used
|
||||||
|
time_t last_used;
|
||||||
|
|
||||||
|
// when the restrictions (ban) should be removed
|
||||||
|
// valid only if some of WINIX_IPBAN_FLAG_BAN_LEVELX flags are set
|
||||||
|
// actually we do not remove the record but unsets WINIX_IPBAN_FLAG_ACTIVE flag
|
||||||
|
// so in the future we can check whether we need to change
|
||||||
|
// the ban level to a greater value
|
||||||
|
time_t expires;
|
||||||
|
|
||||||
|
// how many incorrect login attempts there are
|
||||||
|
unsigned int incorrect_login_events;
|
||||||
|
|
||||||
|
// in the future there can be more *_events fields
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool HasFlag(int flag) const
|
||||||
|
{
|
||||||
|
return (flags & flag) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SetFlag(int flag)
|
||||||
|
{
|
||||||
|
flags = flags | flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ClearFlag(int flag)
|
||||||
|
{
|
||||||
|
flags = flags & (~flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool IsIPBanned() const
|
||||||
|
{
|
||||||
|
if( !HasFlag(WINIX_IPBAN_FLAG_ACTIVE) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL1) ||
|
||||||
|
HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL2) ||
|
||||||
|
HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AddNextBanLevel(time_t level1_expires, time_t level2_expires, time_t level3_expires)
|
||||||
|
{
|
||||||
|
if( HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL3) )
|
||||||
|
{
|
||||||
|
expires = level3_expires;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL2) )
|
||||||
|
{
|
||||||
|
SetFlag(WINIX_IPBAN_FLAG_BAN_LEVEL3);
|
||||||
|
expires = level3_expires;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL1) )
|
||||||
|
{
|
||||||
|
SetFlag(WINIX_IPBAN_FLAG_BAN_LEVEL2);
|
||||||
|
expires = level2_expires;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetFlag(WINIX_IPBAN_FLAG_BAN_LEVEL1);
|
||||||
|
expires = level1_expires;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IPBan()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
ip = 0;
|
||||||
|
flags = 0;
|
||||||
|
last_used = 0;
|
||||||
|
expires = 0;
|
||||||
|
incorrect_login_events = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ClearAfterRemovingBan()
|
||||||
|
{
|
||||||
|
ClearFlag(WINIX_IPBAN_FLAG_ACTIVE);
|
||||||
|
incorrect_login_events = 0;
|
||||||
|
expires = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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 <algorithm>
|
||||||
|
#include "ipbancontainer.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "date/date.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IPBanContainer::IPBanContainer()
|
||||||
|
{
|
||||||
|
is_ipban_tab_sorted = true; // an empty list is sorted
|
||||||
|
soft_max_size = 100;
|
||||||
|
max_size = 110;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IPBanContainer::SetMaxSize(size_t soft_size, size_t size)
|
||||||
|
{
|
||||||
|
soft_max_size = soft_size;
|
||||||
|
max_size = size;
|
||||||
|
|
||||||
|
if( max_size < soft_max_size )
|
||||||
|
max_size = soft_max_size + 1;
|
||||||
|
|
||||||
|
ipban_tab.reserve(max_size);
|
||||||
|
sort_helper_tab.reserve(max_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// returning a reference to the added (or existed) record
|
||||||
|
IPBan & IPBanContainer::AddIP(int ip)
|
||||||
|
{
|
||||||
|
IPBan * old_ip_ban = FindIP(ip);
|
||||||
|
|
||||||
|
if( !old_ip_ban )
|
||||||
|
{
|
||||||
|
IPBan ip_ban;
|
||||||
|
ip_ban.ip = ip;
|
||||||
|
|
||||||
|
if( ipban_tab.size() >= max_size )
|
||||||
|
RemoveOldRecords();
|
||||||
|
|
||||||
|
ipban_tab.push_back(ip_ban);
|
||||||
|
is_ipban_tab_sorted = false;
|
||||||
|
return ipban_tab.back();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return *old_ip_ban;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IPBanContainer::RemoveIP(int ip)
|
||||||
|
{
|
||||||
|
IPBan * ipban = FindIP(ip);
|
||||||
|
|
||||||
|
if( ipban )
|
||||||
|
{
|
||||||
|
size_t index = ipban - &ipban_tab[0];
|
||||||
|
ipban_tab.erase(ipban_tab.begin() + index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool IPBanContainer::IsSorted()
|
||||||
|
{
|
||||||
|
return is_ipban_tab_sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IPBanContainer::Clear()
|
||||||
|
{
|
||||||
|
ipban_tab.clear();
|
||||||
|
is_ipban_tab_sorted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// we need to remove some old records for the size of the container
|
||||||
|
// to be less or equal to soft_max_size
|
||||||
|
void IPBanContainer::RemoveOldRecords()
|
||||||
|
{
|
||||||
|
size_t to_remove = 0;
|
||||||
|
|
||||||
|
if( ipban_tab.size() >= soft_max_size )
|
||||||
|
to_remove = ipban_tab.size() - soft_max_size;
|
||||||
|
|
||||||
|
if( to_remove > 0 )
|
||||||
|
{
|
||||||
|
sort_helper_tab.resize(ipban_tab.size());
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<ipban_tab.size() ; ++i)
|
||||||
|
sort_helper_tab[i] = i;
|
||||||
|
|
||||||
|
std::sort(sort_helper_tab.begin(), sort_helper_tab.end(), SortByLastUsedHelper(this));
|
||||||
|
sort_helper_tab.resize(to_remove);
|
||||||
|
std::sort(sort_helper_tab.begin(), sort_helper_tab.end());
|
||||||
|
|
||||||
|
while( to_remove-- > 0 )
|
||||||
|
ipban_tab.erase(ipban_tab.begin() + sort_helper_tab[to_remove]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// for debug purposes
|
||||||
|
void IPBanContainer::PrintTab()
|
||||||
|
{
|
||||||
|
log << log4 << "ipban_tab (size: " << ipban_tab.size() << ")" << logend;
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<ipban_tab.size() ; ++i)
|
||||||
|
{
|
||||||
|
log << log4 << i << ": ip: " << ipban_tab[i].ip << ", flags: " << ipban_tab[i].flags << ", last_used: ";
|
||||||
|
|
||||||
|
PT::Date date(ipban_tab[i].last_used);
|
||||||
|
log << date << ", expires: ";
|
||||||
|
|
||||||
|
date = ipban_tab[i].expires;
|
||||||
|
log << date << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// for debug purposes
|
||||||
|
void IPBanContainer::PrintTab2()
|
||||||
|
{
|
||||||
|
log << log4 << "sort_helper_tab (size: " << sort_helper_tab.size() << ")" << logend;
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<sort_helper_tab.size() ; ++i)
|
||||||
|
{
|
||||||
|
IPBan & ipban = ipban_tab[sort_helper_tab[i]];
|
||||||
|
|
||||||
|
log << log4 << i << ": ip: " << ipban.ip << ", flags: " << ipban.flags << ", last_used: ";
|
||||||
|
|
||||||
|
PT::Date date(ipban.last_used);
|
||||||
|
log << date << ", expires: ";
|
||||||
|
|
||||||
|
date = ipban.expires;
|
||||||
|
log << date << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool IPBanContainer::SortByLastUsedHelper::operator()(size_t index1, size_t index2)
|
||||||
|
{
|
||||||
|
if( index1 < container->ipban_tab.size() &&
|
||||||
|
index2 < container->ipban_tab.size() )
|
||||||
|
{
|
||||||
|
IPBan & ip1 = container->ipban_tab[index1];
|
||||||
|
IPBan & ip2 = container->ipban_tab[index2];
|
||||||
|
|
||||||
|
// prefer to select records which do not have WINIX_IPBAN_FLAG_ACTIVE
|
||||||
|
if( ip1.HasFlag(WINIX_IPBAN_FLAG_ACTIVE) !=
|
||||||
|
ip2.HasFlag(WINIX_IPBAN_FLAG_ACTIVE) )
|
||||||
|
{
|
||||||
|
return ip2.HasFlag(WINIX_IPBAN_FLAG_ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ip1.last_used < ip2.last_used;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IPBan * IPBanContainer::FindIP(int ip)
|
||||||
|
{
|
||||||
|
// !! IMPROVE ME add binary search if is_ipban_tab_sorted is true
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<ipban_tab.size() ; ++i)
|
||||||
|
{
|
||||||
|
if( ipban_tab[i].ip == ip )
|
||||||
|
{
|
||||||
|
return &ipban_tab[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IPBan & IPBanContainer::GetIPBan(size_t index)
|
||||||
|
{
|
||||||
|
return ipban_tab[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IPBanContainer::Sort()
|
||||||
|
{
|
||||||
|
std::sort(ipban_tab.begin(), ipban_tab.end(), SortIPBansFunction);
|
||||||
|
is_ipban_tab_sorted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
size_t IPBanContainer::Size()
|
||||||
|
{
|
||||||
|
return ipban_tab.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool IPBanContainer::SortIPBansFunction(const IPBan & ip1, const IPBan & ip2)
|
||||||
|
{
|
||||||
|
return ip1.ip < ip2.ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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_ipbancontainer
|
||||||
|
#define headerfile_winix_core_ipbancontainer
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "ipban.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class IPBanContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
IPBanContainer();
|
||||||
|
|
||||||
|
IPBan & AddIP(int ip);
|
||||||
|
IPBan * FindIP(int ip);
|
||||||
|
void Sort();
|
||||||
|
size_t Size();
|
||||||
|
IPBan & GetIPBan(size_t index);
|
||||||
|
void SetMaxSize(size_t soft_size, size_t size);
|
||||||
|
void RemoveIP(int ip);
|
||||||
|
void Clear();
|
||||||
|
bool IsSorted();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<IPBan> ipban_tab;
|
||||||
|
bool is_ipban_tab_sorted;
|
||||||
|
size_t soft_max_size, max_size;
|
||||||
|
std::vector<size_t> sort_helper_tab;
|
||||||
|
|
||||||
|
static bool SortIPBansFunction(const IPBan & ip1, const IPBan & ip2);
|
||||||
|
void RemoveOldRecords();
|
||||||
|
void PrintTab();
|
||||||
|
void PrintTab2();
|
||||||
|
|
||||||
|
struct SortByLastUsedHelper
|
||||||
|
{
|
||||||
|
IPBanContainer * container;
|
||||||
|
|
||||||
|
SortByLastUsedHelper(IPBanContainer * c) : container(c) {}
|
||||||
|
bool operator()(size_t index1, size_t index2);
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
+49
-6
@@ -1,14 +1,45 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "item.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "crypt.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -18,16 +49,20 @@ Item::Item()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// !! IMPROVE ME
|
||||||
|
// now we have Request::start_time and Request::start_date
|
||||||
|
// we can somehow get the current time from the request
|
||||||
|
// may setting the date should be completetly removed from here?
|
||||||
void Item::SetDateToNow()
|
void Item::SetDateToNow()
|
||||||
{
|
{
|
||||||
date_creation = Time(std::time(0));
|
date_creation = std::time(0);
|
||||||
date_modification = date_creation;
|
date_modification = date_creation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item::SetDateModifyToNow()
|
void Item::SetDateModifyToNow()
|
||||||
{
|
{
|
||||||
date_modification = Time(std::time(0));
|
date_modification = std::time(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,12 +96,20 @@ void Item::Clear()
|
|||||||
file_path.clear();
|
file_path.clear();
|
||||||
file_fs = -1;
|
file_fs = -1;
|
||||||
file_type = WINIX_ITEM_FILETYPE_NONE;
|
file_type = WINIX_ITEM_FILETYPE_NONE;
|
||||||
|
hash.clear();
|
||||||
|
hash_type = WINIX_CRYPT_HASH_NONE;
|
||||||
|
file_size = 0;
|
||||||
has_thumb = false;
|
has_thumb = false;
|
||||||
|
|
||||||
html_template.clear();
|
html_template.clear();
|
||||||
|
sort_index = 0;
|
||||||
|
meta.Clear();
|
||||||
|
ameta.Clear();
|
||||||
|
|
||||||
SetDateToNow();
|
SetDateToNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+82
-35
@@ -1,88 +1,132 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_item
|
||||||
#define headerfile_winix_core_item
|
#define headerfile_winix_core_item
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "space/space.h"
|
||||||
|
#include "date/date.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_ITEM_FILETYPE_NONE 0
|
#define WINIX_ITEM_FILETYPE_NONE 0
|
||||||
#define WINIX_ITEM_FILETYPE_IMAGE 1
|
#define WINIX_ITEM_FILETYPE_IMAGE 1
|
||||||
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
|
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
|
||||||
#define WINIX_ITEM_FILETYPE_UNKNOWN 3
|
#define WINIX_ITEM_FILETYPE_VIDEO 3
|
||||||
|
#define WINIX_ITEM_FILETYPE_UNKNOWN 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Item
|
struct Item
|
||||||
{
|
{
|
||||||
long id;
|
long id;
|
||||||
long parent_id;
|
long parent_id;
|
||||||
|
|
||||||
|
|
||||||
long user_id;
|
long user_id;
|
||||||
long group_id;
|
long group_id;
|
||||||
std::wstring guest_name; // used as a user name when user_id is equal -1
|
std::wstring guest_name; // used as a user name when user_id is equal -1
|
||||||
|
|
||||||
long modification_user_id; // who has modified the item last (not taken into account when checking permissions)
|
long modification_user_id; // who has modified the item last (not taken into account when checking permissions)
|
||||||
|
|
||||||
int privileges;
|
int privileges;
|
||||||
|
|
||||||
tm date_creation;
|
PT::Date date_creation;
|
||||||
tm date_modification;
|
PT::Date date_modification;
|
||||||
|
|
||||||
std::wstring subject;
|
std::wstring subject;
|
||||||
std::wstring content;
|
std::wstring content;
|
||||||
|
|
||||||
std::wstring url;
|
std::wstring url;
|
||||||
int modify_index;
|
int modify_index;
|
||||||
|
|
||||||
enum ContentType
|
enum ContentType
|
||||||
{
|
{
|
||||||
ct_text = 0,
|
ct_text = 0,
|
||||||
ct_formatted_text,
|
ct_formatted_text,
|
||||||
ct_html,
|
ct_html,
|
||||||
ct_bbcode,
|
ct_bbcode,
|
||||||
ct_raw
|
ct_raw
|
||||||
};
|
};
|
||||||
|
|
||||||
ContentType content_type;
|
ContentType content_type;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
dir = 0,
|
dir = 0,
|
||||||
file = 1,
|
file = 1,
|
||||||
symlink = 2,
|
symlink = 2,
|
||||||
|
|
||||||
none = 1000
|
none = 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
|
|
||||||
|
|
||||||
// used when type is symlink or to a directory too (function 'default')
|
// used when type is symlink or to a directory too (function 'default')
|
||||||
std::wstring link_to;
|
std::wstring link_to;
|
||||||
int link_redirect;
|
int link_redirect; // !! IMPROVE ME should it be 'bool'?
|
||||||
|
|
||||||
|
|
||||||
// static file (if exists)
|
// static file (if exists)
|
||||||
std::wstring file_path; // relative file path
|
std::wstring file_path; // relative file path
|
||||||
int file_fs; // file system type where the file was saved
|
int file_fs; // file system type where the file was saved
|
||||||
int file_type; // file type (none, image, doc, etc)
|
int file_type; // file type (none, image, doc, etc)
|
||||||
bool has_thumb;
|
bool has_thumb; // whether or not we have a thumbnail
|
||||||
|
std::wstring hash; // file hash (md4, md5, ...)
|
||||||
|
int hash_type; // hash type WINIX_CRYPT_HASH_* (see crypt.h)
|
||||||
|
size_t file_size; // size of the file
|
||||||
|
|
||||||
|
|
||||||
std::wstring html_template;
|
std::wstring html_template;
|
||||||
|
|
||||||
|
|
||||||
|
// sort index used when displaying a group of items
|
||||||
|
int sort_index;
|
||||||
|
|
||||||
|
|
||||||
|
// meta information
|
||||||
|
PT::Space meta;
|
||||||
|
PT::Space ameta;
|
||||||
|
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
@@ -98,9 +142,12 @@ private:
|
|||||||
int ref; // content references
|
int ref; // content references
|
||||||
|
|
||||||
friend class Db;
|
friend class Db;
|
||||||
friend class DbItemColumns;
|
friend struct DbItemColumns;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Executable
+198
@@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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"
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Job::Job()
|
||||||
|
{
|
||||||
|
jobs_queue_tab.resize(WINIX_JOBS_HOW_MANY_PRIORITIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Job::CheckPriority(int & priority) const
|
||||||
|
{
|
||||||
|
if( priority < 0 )
|
||||||
|
priority = 0;
|
||||||
|
|
||||||
|
if( priority >= WINIX_JOBS_HOW_MANY_PRIORITIES )
|
||||||
|
priority = WINIX_JOBS_HOW_MANY_PRIORITIES - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Job::Add(PT::Space & job, int priority)
|
||||||
|
{
|
||||||
|
CheckPriority(priority);
|
||||||
|
jobs_queue_tab[priority].push(job);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
size_t Job::Size(int priority) const
|
||||||
|
{
|
||||||
|
CheckPriority(priority);
|
||||||
|
return jobs_queue_tab[priority].size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
size_t Job::Size() const
|
||||||
|
{
|
||||||
|
size_t sum = 0;
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<WINIX_JOBS_HOW_MANY_PRIORITIES ; ++i)
|
||||||
|
sum += Size(i);
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Job::Empty(int priority) const
|
||||||
|
{
|
||||||
|
CheckPriority(priority);
|
||||||
|
return jobs_queue_tab[priority].empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Job::Empty() const
|
||||||
|
{
|
||||||
|
for(size_t i=0 ; i<WINIX_JOBS_HOW_MANY_PRIORITIES ; ++i)
|
||||||
|
if( !Empty(i) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
second thread
|
||||||
|
*/
|
||||||
|
|
||||||
|
// second thread (objects locked)
|
||||||
|
bool Job::SignalReceived()
|
||||||
|
{
|
||||||
|
return !Empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects not locked)
|
||||||
|
void Job::Do()
|
||||||
|
{
|
||||||
|
size_t i = WINIX_JOBS_HOW_MANY_PRIORITIES;
|
||||||
|
bool is_empty;
|
||||||
|
|
||||||
|
while( i-- > 0 && !IsExitSignal() )
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
|
is_empty = Empty(i);
|
||||||
|
Unlock();
|
||||||
|
|
||||||
|
if( !is_empty )
|
||||||
|
DoQueue(jobs_queue_tab[i]);
|
||||||
|
}
|
||||||
|
while( !is_empty && !IsExitSignal() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects not locked, jobs_queue is not empty)
|
||||||
|
void Job::DoQueue(JobsQueue & jobs_queue)
|
||||||
|
{
|
||||||
|
bool is_empty;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
|
// references will not be invalidated after insertion to jobs_queue
|
||||||
|
// (jobs_queue is std::queue and it uses std::deque by default)
|
||||||
|
PT::Space & job = jobs_queue.front();
|
||||||
|
Unlock();
|
||||||
|
|
||||||
|
DoJob(job);
|
||||||
|
|
||||||
|
Lock();
|
||||||
|
jobs_queue.pop();
|
||||||
|
is_empty = jobs_queue.empty();
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
while( !is_empty && !IsExitSignal() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects not locked)
|
||||||
|
void Job::DoJob(PT::Space & job)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PluginRes res = plugin.Call((Session*)0, WINIX_JOB, &job);
|
||||||
|
|
||||||
|
if( res.res_true == 0 )
|
||||||
|
DoWinixJob(job);
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects not locked)
|
||||||
|
void Job::DoWinixJob(PT::Space & job)
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
|
//log << log1 << "standard winix job: " << job.Text(L"type") << logend;
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Executable
+115
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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
|
||||||
|
#define headerfile_winix_core_jobs
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include "basethread.h"
|
||||||
|
#include "space/space.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define WINIX_JOBS_HOW_MANY_PRIORITIES 32
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Job : public BaseThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Job();
|
||||||
|
|
||||||
|
/*
|
||||||
|
add a new job to the queue
|
||||||
|
priority: 0-31 (0 - the lowest priority, 31 - the highest priority)
|
||||||
|
*/
|
||||||
|
void Add(PT::Space & job, int priority = 0);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
queue size, and size of all jobs in any priority
|
||||||
|
*/
|
||||||
|
size_t Size(int priority) const;
|
||||||
|
size_t Size() const;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
true if specified queue is empty
|
||||||
|
or if all queues are empty
|
||||||
|
*/
|
||||||
|
bool Empty(int priority) const;
|
||||||
|
bool Empty() const;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
typedef std::queue<PT::Space> JobsQueue;
|
||||||
|
typedef std::vector<JobsQueue> JobsQueueTab;
|
||||||
|
JobsQueueTab jobs_queue_tab;
|
||||||
|
|
||||||
|
void CheckPriority(int & priority) const;
|
||||||
|
void SaveToFile();
|
||||||
|
void ReadFromFile();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
second thread
|
||||||
|
*/
|
||||||
|
|
||||||
|
// standard winix jobs
|
||||||
|
// Image image;
|
||||||
|
// sending emails
|
||||||
|
// etc.
|
||||||
|
|
||||||
|
bool SignalReceived();
|
||||||
|
void Do();
|
||||||
|
void DoQueue(JobsQueue & jobs_queue);
|
||||||
|
void DoJob(PT::Space & job);
|
||||||
|
void DoWinixJob(PT::Space & job);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
+50
-18
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -13,28 +38,23 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LastItem::LastItem()
|
LastItem::LastItem()
|
||||||
{
|
{
|
||||||
user_id = 0;
|
user_id = 0;
|
||||||
ip = 0;
|
ip = 0;
|
||||||
session_id = 0;
|
session_id = 0;
|
||||||
memset((char*)&start, 0, sizeof(start));
|
|
||||||
memset((char*)&end, 0, sizeof(end));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LastItem::IsLoggedOut()
|
bool LastItem::IsLoggedOut()
|
||||||
{
|
{
|
||||||
if( end.tm_sec == 0 &&
|
return end.year > 1970;
|
||||||
end.tm_min == 0 &&
|
|
||||||
end.tm_hour == 0 &&
|
|
||||||
end.tm_mday == 0 &&
|
|
||||||
end.tm_mon == 0 &&
|
|
||||||
end.tm_year == 0 )
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +107,7 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
|
|||||||
li.name = name;
|
li.name = name;
|
||||||
li.ip = ip;
|
li.ip = ip;
|
||||||
li.session_id = session_id;
|
li.session_id = session_id;
|
||||||
li.start = Time(std::time(0));
|
li.start = std::time(0);
|
||||||
|
|
||||||
last_tab.insert(last_tab.end(), li);
|
last_tab.insert(last_tab.end(), li);
|
||||||
|
|
||||||
@@ -103,10 +123,22 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
|
|||||||
|
|
||||||
if( i != last_tab.end() )
|
if( i != last_tab.end() )
|
||||||
{
|
{
|
||||||
i->end = Time(std::time(0));
|
i->end = std::time(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log << log4 << "LC: there is no such a user to log out" << logend;
|
/*
|
||||||
|
!! IMPROVE ME
|
||||||
|
users read from the session file (at boot time)
|
||||||
|
are not added to LastContainer
|
||||||
|
*/
|
||||||
|
|
||||||
|
log << log4 << "LC: there is no such a user to log out: user_id: "
|
||||||
|
<< user_id << " ses_id: " << session_id << logend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+40
-5
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_lastcontainer
|
||||||
@@ -14,6 +39,12 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include "date/date.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -37,8 +68,8 @@ struct LastItem
|
|||||||
long session_id;
|
long session_id;
|
||||||
|
|
||||||
// start logging and end logging
|
// start logging and end logging
|
||||||
tm start;
|
PT::Date start;
|
||||||
tm end;
|
PT::Date end;
|
||||||
|
|
||||||
|
|
||||||
LastItem();
|
LastItem();
|
||||||
@@ -74,4 +105,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+37
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -12,6 +37,10 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LoadAvg::LoadAvg()
|
LoadAvg::LoadAvg()
|
||||||
{
|
{
|
||||||
@@ -370,3 +399,8 @@ double LoadAvg::ReqPerSec15()
|
|||||||
|
|
||||||
return cache_req_per_sec15;
|
return cache_req_per_sec15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+35
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_loadavg
|
||||||
@@ -13,6 +38,10 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// in seconds
|
// in seconds
|
||||||
@@ -110,5 +139,8 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Executable
+82
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Lock::Lock()
|
||||||
|
{
|
||||||
|
synchro = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Lock::Lock(Synchro * synchro_)
|
||||||
|
{
|
||||||
|
synchro = synchro_;
|
||||||
|
synchro->Lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Lock::Lock(Synchro & synchro_)
|
||||||
|
{
|
||||||
|
synchro = &synchro_;
|
||||||
|
synchro->Lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Lock::~Lock()
|
||||||
|
{
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Lock::Unlock()
|
||||||
|
{
|
||||||
|
if( synchro )
|
||||||
|
{
|
||||||
|
synchro->Unlock();
|
||||||
|
synchro = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
Executable
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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
|
||||||
|
#define headerfile_winix_core_lock
|
||||||
|
|
||||||
|
#include "synchro.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Lock
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Lock(Synchro * synchro_);
|
||||||
|
Lock(Synchro & synchro_);
|
||||||
|
|
||||||
|
~Lock();
|
||||||
|
|
||||||
|
void Unlock();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Synchro * synchro;
|
||||||
|
|
||||||
|
Lock();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
+176
-47
@@ -1,16 +1,47 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "log.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "utf8.h"
|
#include "utf8/utf8.h"
|
||||||
|
#include "timezones.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log::Log()
|
Log::Log()
|
||||||
@@ -22,6 +53,7 @@ Log::Log()
|
|||||||
lines = 0;
|
lines = 0;
|
||||||
max_lines = 5000;
|
max_lines = 5000;
|
||||||
log_file_open = false;
|
log_file_open = false;
|
||||||
|
time_zones = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -31,14 +63,29 @@ Log::~Log()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Log::Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests)
|
|
||||||
|
void Log::SetTimeZones(TimeZones * ptime_zones)
|
||||||
|
{
|
||||||
|
time_zones = ptime_zones;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int Log::LogLevel()
|
||||||
|
{
|
||||||
|
return log_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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_level = log_level_;
|
||||||
log_file = log_file_;
|
|
||||||
log_stdout = log_std;
|
log_stdout = log_std;
|
||||||
max_requests = log_max_requests;
|
max_requests = log_max_requests;
|
||||||
save_each_line = save_each_line_;
|
save_each_line = save_each_line_;
|
||||||
|
|
||||||
|
PT::WideToUTF8(log_file_, log_file);
|
||||||
// don't open the file here
|
// don't open the file here
|
||||||
// because it would be created with the root as an owner
|
// because it would be created with the root as an owner
|
||||||
}
|
}
|
||||||
@@ -54,25 +101,30 @@ void Log::OpenFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Log::PutDate(Manipulators m)
|
void Log::PrintDate(const PT::Date & date, size_t time_zone_id)
|
||||||
{
|
{
|
||||||
// logs are related to localtime
|
if( time_zones )
|
||||||
|
{
|
||||||
|
TimeZone * tz = time_zones->GetZone(time_zone_id);
|
||||||
|
|
||||||
time_t t = std::time(0);
|
if( tz )
|
||||||
std::tm * loct = std::localtime(&t);
|
{
|
||||||
|
PT::Date local_date = tz->ToLocal(date);
|
||||||
char buffer[70];
|
log << local_date;
|
||||||
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
|
}
|
||||||
int(loct->tm_mon + 1),
|
else
|
||||||
int(loct->tm_mday),
|
{
|
||||||
int(loct->tm_hour),
|
(*this) << date << " UTC"; // unknown time zone identifier
|
||||||
int(loct->tm_min),
|
}
|
||||||
int(loct->tm_sec));
|
}
|
||||||
|
else
|
||||||
(*this) << m << buffer;
|
{
|
||||||
|
(*this) << date << " UTC"; // time_zones object was not set
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const void * s)
|
Log & Log::operator<<(const void * s)
|
||||||
{
|
{
|
||||||
if( current_level > log_level )
|
if( current_level > log_level )
|
||||||
@@ -234,7 +286,31 @@ Log & Log::operator<<(double s)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(Manipulators m)
|
Log & Log::operator<<(const PT::Space & s)
|
||||||
|
{
|
||||||
|
if( current_level <= log_level )
|
||||||
|
{
|
||||||
|
buffer << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(const PT::Date & date)
|
||||||
|
{
|
||||||
|
if( current_level <= log_level )
|
||||||
|
{
|
||||||
|
buffer << date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(LogManipulators m)
|
||||||
{
|
{
|
||||||
switch(m)
|
switch(m)
|
||||||
{
|
{
|
||||||
@@ -273,6 +349,9 @@ Log & Log::operator<<(Manipulators m)
|
|||||||
case log4:
|
case log4:
|
||||||
current_level = 4;
|
current_level = 4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@@ -280,6 +359,79 @@ return *this;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char Log::GetHEXdigit(unsigned char c)
|
||||||
|
{
|
||||||
|
if( c < 10 )
|
||||||
|
return c + '0';
|
||||||
|
|
||||||
|
return c - 10 + 'A';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Log::ToHEX(char * buf, unsigned char c)
|
||||||
|
{
|
||||||
|
buf[0] = GetHEXdigit(c >> 4);
|
||||||
|
buf[1] = GetHEXdigit(c & 0xf);
|
||||||
|
buf[2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Log::LogBinary(const char * blob, size_t blob_len)
|
||||||
|
{
|
||||||
|
size_t i=0;
|
||||||
|
char buf[3];
|
||||||
|
|
||||||
|
|
||||||
|
while( i < blob_len )
|
||||||
|
{
|
||||||
|
size_t oldi = i;
|
||||||
|
|
||||||
|
for(size_t a=0 ; a<16 ; ++a)
|
||||||
|
{
|
||||||
|
if( i < blob_len )
|
||||||
|
{
|
||||||
|
ToHEX(buf, blob[i]);
|
||||||
|
buffer << buf << ' ';
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if( a == 7 )
|
||||||
|
{
|
||||||
|
if( i < blob_len )
|
||||||
|
buffer << "- ";
|
||||||
|
else
|
||||||
|
buffer << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i = oldi;
|
||||||
|
buffer << ' ';
|
||||||
|
|
||||||
|
for(size_t a=0 ; a<16 && i<blob_len ; ++a, ++i)
|
||||||
|
{
|
||||||
|
if( blob[i] > 31 && blob[i] < 127 )
|
||||||
|
buffer << blob[i];
|
||||||
|
else
|
||||||
|
buffer << '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
(*this) << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Log::LogBinary(const std::string & blob)
|
||||||
|
{
|
||||||
|
LogBinary(blob.c_str(), blob.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Log::SystemErr(int err)
|
void Log::SystemErr(int err)
|
||||||
{
|
{
|
||||||
(*this) << "errno: " << err;
|
(*this) << "errno: " << err;
|
||||||
@@ -307,7 +459,7 @@ void Log::SaveLog()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if( log_stdout )
|
if( log_stdout )
|
||||||
Ezc::WideToUTF8(buffer.Str(), std::cout);
|
PT::WideToUTF8(buffer.Str(), std::cout);
|
||||||
|
|
||||||
if( log_file.empty() )
|
if( log_file.empty() )
|
||||||
return;
|
return;
|
||||||
@@ -323,7 +475,7 @@ void Log::SaveLog()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ezc::WideToUTF8(buffer.Str(), file);
|
PT::WideToUTF8(buffer.Str(), file);
|
||||||
file.flush();
|
file.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,28 +483,5 @@ void Log::SaveLog()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+81
-14
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_log
|
||||||
@@ -16,16 +41,17 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "textstream.h"
|
#include "textstream.h"
|
||||||
|
#include "logmanipulators.h"
|
||||||
|
#include "textstream/textstream.h"
|
||||||
|
|
||||||
|
|
||||||
// log1 - the first level
|
namespace Winix
|
||||||
// log2
|
{
|
||||||
// log3
|
|
||||||
// log4 - the last level (debug level)
|
|
||||||
// logend - the end of a line
|
|
||||||
// logendrequest - end of a current request
|
class TimeZones;
|
||||||
// logsave - current log buffer is saved and cleared
|
|
||||||
enum Manipulators { log1, log2, log3, log4, logend, logendrequest, logsave };
|
|
||||||
|
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
@@ -35,9 +61,9 @@ public:
|
|||||||
Log();
|
Log();
|
||||||
~Log();
|
~Log();
|
||||||
|
|
||||||
void Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests);
|
void SetTimeZones(TimeZones * ptime_zones);
|
||||||
|
void Init(int log_level_, bool save_each_line_, const std::wstring & log_file_, bool log_std, int log_max_requests);
|
||||||
|
|
||||||
void PutDate(Manipulators m);
|
|
||||||
Log & operator<<(const void * s);
|
Log & operator<<(const void * s);
|
||||||
Log & operator<<(const char * s);
|
Log & operator<<(const char * s);
|
||||||
Log & operator<<(const std::string * s);
|
Log & operator<<(const std::string * s);
|
||||||
@@ -51,17 +77,35 @@ public:
|
|||||||
Log & operator<<(wchar_t s);
|
Log & operator<<(wchar_t s);
|
||||||
Log & operator<<(size_t s);
|
Log & operator<<(size_t s);
|
||||||
Log & operator<<(double s);
|
Log & operator<<(double s);
|
||||||
Log & operator<<(Manipulators m);
|
Log & operator<<(const PT::Space & space);
|
||||||
|
Log & operator<<(LogManipulators m);
|
||||||
|
Log & operator<<(const PT::Date & date);
|
||||||
|
|
||||||
|
void PrintDate(const PT::Date & date, size_t time_zone_id);
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
Log & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
void LogString(const StringType & value, size_t max_size);
|
void LogString(const StringType & value, size_t max_size);
|
||||||
|
|
||||||
|
void LogBinary(const char * blob, size_t blob_len);
|
||||||
|
void LogBinary(const std::string & blob);
|
||||||
|
|
||||||
|
|
||||||
void SystemErr(int err);
|
void SystemErr(int err);
|
||||||
void SaveLog();
|
void SaveLog();
|
||||||
void SaveLogAndClear();
|
void SaveLogAndClear();
|
||||||
|
|
||||||
|
int LogLevel();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
// time zones for printing the time in the log file
|
||||||
|
TimeZones * time_zones;
|
||||||
|
|
||||||
// buffer for the log
|
// buffer for the log
|
||||||
TextStream<std::wstring> buffer;
|
TextStream<std::wstring> buffer;
|
||||||
|
|
||||||
@@ -99,6 +143,8 @@ private:
|
|||||||
bool save_each_line;
|
bool save_each_line;
|
||||||
|
|
||||||
void OpenFile();
|
void OpenFile();
|
||||||
|
char GetHEXdigit(unsigned char c);
|
||||||
|
void ToHEX(char * buf, unsigned char c);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,10 +169,31 @@ size_t min_size = value.size() < max_size ? value.size() : max_size;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
Log & Log::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
||||||
|
{
|
||||||
|
if( current_level <= log_level )
|
||||||
|
buffer << buf;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern Log log;
|
extern Log log;
|
||||||
extern Log nlog;
|
extern Log nlog;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// for convenience, we have to use only #include "log.h" in the winix
|
||||||
|
#include "slog.h"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Executable
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winix_core_logmanipulators
|
||||||
|
#define headerfile_winix_core_logmanipulators
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
log1 - the first level
|
||||||
|
log2
|
||||||
|
log3
|
||||||
|
log4 - the last level (debug level)
|
||||||
|
logend - the end of a line
|
||||||
|
logendrequest - end of a current request
|
||||||
|
logsave - current log buffer is saved and cleared
|
||||||
|
|
||||||
|
manipulators used by the session logger (SLog)
|
||||||
|
loginfo - normal info to a user
|
||||||
|
logerror - we are reporting an error
|
||||||
|
logwarning - we are reporting a warning
|
||||||
|
|
||||||
|
make sure that loginfo, logerror and logwarning have values less than 32 (space)
|
||||||
|
their are used as control codes in a string
|
||||||
|
*/
|
||||||
|
enum LogManipulators
|
||||||
|
{
|
||||||
|
log1,
|
||||||
|
log2,
|
||||||
|
log3,
|
||||||
|
log4,
|
||||||
|
logend,
|
||||||
|
logendrequest,
|
||||||
|
logsave,
|
||||||
|
|
||||||
|
loginfo,
|
||||||
|
logerror,
|
||||||
|
logwarning
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
+561
-350
File diff suppressed because it is too large
Load Diff
+708
-57
@@ -1,21 +1,57 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_misc
|
||||||
#define headerfile_winix_core_misc
|
#define headerfile_winix_core_misc
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "requesttypes.h"
|
||||||
|
#include "date/date.h"
|
||||||
|
#include "textstream/textstream.h"
|
||||||
|
#include "utf8/utf8.h"
|
||||||
|
#include "winix_const.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -33,6 +69,11 @@ long Tol(const std::wstring & str, int base = 10);
|
|||||||
long Tol(const char * str, int base = 10);
|
long Tol(const char * str, int base = 10);
|
||||||
long Tol(const wchar_t * str, int base = 10);
|
long Tol(const wchar_t * str, int base = 10);
|
||||||
|
|
||||||
|
double Tod(const std::string & str);
|
||||||
|
double Tod(const std::wstring & str);
|
||||||
|
double Tod(const char * str);
|
||||||
|
double Tod(const wchar_t * str);
|
||||||
|
|
||||||
|
|
||||||
// if the buffer is too small it will be terminated at the beginning (empty string)
|
// if the buffer is too small it will be terminated at the beginning (empty string)
|
||||||
// and the function returns false
|
// and the function returns false
|
||||||
@@ -118,14 +159,55 @@ bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
these methos don't take the buffer size
|
||||||
|
make sure the buffer size is sufficient big
|
||||||
|
2^64 - 1 = 18446744073709551615 = 20 characters (plus minus sign and plus terminating zero)
|
||||||
|
so the buffer should have at least 22 characters
|
||||||
|
!! CHECK ME check the size whether is correct
|
||||||
|
*/
|
||||||
|
template<class CharType>
|
||||||
|
bool Toa(unsigned long value, CharType * buffer)
|
||||||
|
{
|
||||||
|
size_t sufficient_space = 25;
|
||||||
|
return Toa(value, buffer, sufficient_space);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharType>
|
||||||
|
bool Toa(long value, CharType * buffer)
|
||||||
|
{
|
||||||
|
size_t sufficient_space = 25;
|
||||||
|
return Toa(value, buffer, sufficient_space);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharType>
|
||||||
|
bool Toa(unsigned int value, CharType * buffer)
|
||||||
|
{
|
||||||
|
size_t sufficient_space = 25;
|
||||||
|
return Toa(value, buffer, sufficient_space);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CharType>
|
||||||
|
bool Toa(int value, CharType * buffer)
|
||||||
|
{
|
||||||
|
size_t sufficient_space = 25;
|
||||||
|
return Toa(value, buffer, sufficient_space);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// warning: it uses its own static buffer
|
// warning: it uses its own static buffer
|
||||||
// one buffer for both these functions
|
// one buffer for both these functions
|
||||||
|
// !! REMOVE ME they are deprecated (don't use it)
|
||||||
const wchar_t * Toa(unsigned int value, int base = 10);
|
const wchar_t * Toa(unsigned int value, int base = 10);
|
||||||
const wchar_t * Toa(unsigned long value, int base = 10);
|
const wchar_t * Toa(unsigned long value, int base = 10);
|
||||||
const wchar_t * Toa(int value, int base = 10);
|
const wchar_t * Toa(int value, int base = 10);
|
||||||
const wchar_t * Toa(long value, int base = 10);
|
const wchar_t * Toa(long value, int base = 10);
|
||||||
|
|
||||||
|
|
||||||
void Toa(int value, std::string & res, int base = 10, bool clear = true);
|
void Toa(int value, std::string & res, int base = 10, bool clear = true);
|
||||||
void Toa(long value, std::string & res, int base = 10, bool clear = true);
|
void Toa(long value, std::string & res, int base = 10, bool clear = true);
|
||||||
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
|
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
|
||||||
@@ -133,34 +215,6 @@ 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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CorrectUrlChar(wchar_t c);
|
bool CorrectUrlChar(wchar_t c);
|
||||||
void CorrectUrlDots(std::wstring & url);
|
void CorrectUrlDots(std::wstring & url);
|
||||||
void CorrectUrlChars(std::wstring & url);
|
void CorrectUrlChars(std::wstring & url);
|
||||||
@@ -169,21 +223,30 @@ void CorrectUrlOnlyAllowedChar(std::wstring & url);
|
|||||||
|
|
||||||
const wchar_t * DateToStr(int year, int month, int day);
|
const wchar_t * DateToStr(int year, int month, int day);
|
||||||
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec);
|
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec);
|
||||||
const wchar_t * DateToStr(const tm * ptm);
|
const wchar_t * DateToStr(const PT::Date & d);
|
||||||
const wchar_t * DateToStr(const tm & rtm);
|
|
||||||
const wchar_t * DateToStr(time_t t);
|
const wchar_t * DateToStr(time_t t);
|
||||||
const wchar_t * DateToStrWithoutHours(const tm * ptm);
|
const wchar_t * DateToStrWithoutHours(const PT::Date & d);
|
||||||
const wchar_t * DateToStrWithoutHours(const tm & rtm);
|
|
||||||
const wchar_t * DateToStrWithoutHours(time_t t);
|
const wchar_t * DateToStrWithoutHours(time_t t);
|
||||||
|
|
||||||
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
|
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
|
||||||
const char * DateToStrCookie(const tm * ptm);
|
const char * DateToStrCookie(const PT::Date & d);
|
||||||
const char * DateToStrCookie(const tm & rtm);
|
|
||||||
const char * DateToStrCookie(time_t t);
|
const char * DateToStrCookie(time_t t);
|
||||||
|
|
||||||
|
// depracated
|
||||||
|
// not thread safe
|
||||||
const wchar_t * IpToStr(unsigned int ip_);
|
const wchar_t * IpToStr(unsigned int ip_);
|
||||||
|
|
||||||
|
// in a new code we can use WTextStream in such a way
|
||||||
|
// DateToStr() etc can use it too
|
||||||
|
PT::WTextStream IPToStr(unsigned int ip);
|
||||||
|
PT::WTextStream IPToStr(int ip);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool IsWhite(wchar_t s);
|
bool IsWhite(wchar_t s);
|
||||||
|
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);
|
||||||
|
bool IsLastSlash(const std::wstring & path);
|
||||||
|
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
void TrimWhite(StringType & s)
|
void TrimWhite(StringType & s)
|
||||||
@@ -217,7 +280,24 @@ typename StringType::size_type i;
|
|||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
void Trim(StringType & s, wchar_t c)
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
void TrimLast(StringType & s, wchar_t c)
|
||||||
{
|
{
|
||||||
typename StringType::size_type i;
|
typename StringType::size_type i;
|
||||||
|
|
||||||
@@ -237,16 +317,77 @@ typename StringType::size_type i;
|
|||||||
// deleting 'c' characters at the end
|
// deleting 'c' characters at the end
|
||||||
if( i != s.size() - 1 )
|
if( i != s.size() - 1 )
|
||||||
s.erase(i+1, StringType::npos);
|
s.erase(i+1, StringType::npos);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
void MaxSize(StringType & str, size_t max_size)
|
||||||
|
{
|
||||||
|
if( str.size() > max_size )
|
||||||
|
str.erase(max_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this method removing all characters from given string
|
||||||
|
only digits are allowed and if allow_comma then one comma (or dot)
|
||||||
|
character is allowed
|
||||||
|
|
||||||
|
if change_to_dot is true then if a comma exists then it is changed to a dot
|
||||||
|
*/
|
||||||
|
template<class StringType>
|
||||||
|
void OnlyDigit(StringType & s, bool allow_comma = true, bool change_to_dot = true)
|
||||||
|
{
|
||||||
|
typename StringType::size_type i;
|
||||||
|
bool was_comma = false;
|
||||||
|
|
||||||
|
if( s.empty() )
|
||||||
|
{
|
||||||
|
s = '0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0 ; i<s.size() ; )
|
||||||
|
{
|
||||||
|
if( (s[i]>='0' && s[i]<='9') ||
|
||||||
|
(allow_comma && !was_comma && (s[i]=='.' || s[i]==',')) )
|
||||||
|
{
|
||||||
|
if( change_to_dot && s[i] == ',' )
|
||||||
|
s[i] = '.';
|
||||||
|
|
||||||
|
if( s[i]=='.' || s[i]==',' )
|
||||||
|
was_comma = true;
|
||||||
|
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s.erase(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wchar_t ToSmall(wchar_t c);
|
wchar_t ToSmall(wchar_t c);
|
||||||
void ToSmall(std::wstring & s);
|
void ToSmall(std::wstring & s);
|
||||||
|
|
||||||
@@ -256,7 +397,7 @@ const wchar_t * SkipWhite(const wchar_t * s);
|
|||||||
|
|
||||||
|
|
||||||
template<class StringType1, class StringType2>
|
template<class StringType1, class StringType2>
|
||||||
bool IsSubString(const StringType1 * short_str, const StringType2 * long_str)
|
bool IsSubStringp(const StringType1 * short_str, const StringType2 * long_str)
|
||||||
{
|
{
|
||||||
while( *short_str && *long_str && wchar_t(*short_str) == wchar_t(*long_str) )
|
while( *short_str && *long_str && wchar_t(*short_str) == wchar_t(*long_str) )
|
||||||
{
|
{
|
||||||
@@ -272,12 +413,18 @@ return false;
|
|||||||
|
|
||||||
|
|
||||||
template<class StringType1, class StringType2>
|
template<class StringType1, class StringType2>
|
||||||
bool IsSubString(const StringType1 & short_str, const StringType2 & long_str)
|
bool IsSubString(const StringType1 * short_str, const StringType2 * long_str)
|
||||||
{
|
{
|
||||||
return IsSubString(short_str.c_str(), long_str.c_str());
|
return IsSubStringp(short_str, long_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType1, class StringType2>
|
||||||
|
bool IsSubString(const StringType1 & short_str, const StringType2 & long_str)
|
||||||
|
{
|
||||||
|
return IsSubStringp(short_str.c_str(), long_str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class StringType1, class StringType2>
|
template<class StringType1, class StringType2>
|
||||||
bool IsSubStringNoCase(const StringType1 * short_str, const StringType2 * long_str)
|
bool IsSubStringNoCase(const StringType1 * short_str, const StringType2 * long_str)
|
||||||
@@ -351,6 +498,36 @@ bool EqualNoCase(const StringType1 & str1, const StringType2 & str2)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
looking for 'look_for' string in 'buf' and replacing it with 'replace'
|
||||||
|
'replace' can be empty (so only 'look_for' will be deleted)
|
||||||
|
*/
|
||||||
|
template<class StringType>
|
||||||
|
void ReplaceString(StringType & buf, const StringType & look_for, const StringType & replace)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
if( look_for.empty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
while( i < buf.size() )
|
||||||
|
{
|
||||||
|
if( IsSubString(look_for.c_str(), buf.c_str() + i) )
|
||||||
|
{
|
||||||
|
buf.erase(i, look_for.size());
|
||||||
|
buf.insert(i, replace);
|
||||||
|
i += replace.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
void NoLastSlash(StringType & s)
|
void NoLastSlash(StringType & s)
|
||||||
{
|
{
|
||||||
@@ -389,19 +566,180 @@ void NoFirstHttp(StringType & s)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this method returns true if there are two dots meaning 'go up' somewhere in the path
|
||||||
|
|
||||||
|
for example such paths return true:
|
||||||
|
".."
|
||||||
|
"test/../path"
|
||||||
|
"test/where/../"
|
||||||
|
"test/where/.."
|
||||||
|
"../abc"
|
||||||
|
*/
|
||||||
|
template<class StringType>
|
||||||
|
bool PathHasUpDir(const StringType * str)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
while( str[i] )
|
||||||
|
{
|
||||||
|
if( str[i]=='.' && str[i+1]=='.' )
|
||||||
|
{
|
||||||
|
i += 2;
|
||||||
|
|
||||||
|
if( str[i]=='/' || str[i]==0 )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// skipping until to next slash
|
||||||
|
while( str[i] && str[i]!='/' )
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
// skipping the slash (or slashes)
|
||||||
|
while( str[i]=='/' )
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
bool PathHasUpDir(const StringType & str)
|
||||||
|
{
|
||||||
|
return PathHasUpDir(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this method calculates how many directories there are in the given path
|
||||||
|
input:
|
||||||
|
str - path
|
||||||
|
last_is_dir - true if the last part of the path should be treated as a directory too
|
||||||
|
|
||||||
|
samples:
|
||||||
|
HowManyDirs("", false) -> 0
|
||||||
|
HowManyDirs("", true) -> 0
|
||||||
|
HowManyDirs("abc", false) -> 0
|
||||||
|
HowManyDirs("abc", true) -> 1
|
||||||
|
HowManyDirs("/abc/", true) -> 1
|
||||||
|
HowManyDirs("////", false) -> 0
|
||||||
|
HowManyDirs("////", true) -> 0
|
||||||
|
HowManyDirs("////abc", false) -> 0
|
||||||
|
HowManyDirs("////abc", true) -> 1
|
||||||
|
HowManyDirs("/var/static", false) -> 1
|
||||||
|
HowManyDirs("/var/static", true) -> 2
|
||||||
|
HowManyDirs("/var/static/", false) -> 2
|
||||||
|
HowManyDirs("/var/static/", true) -> 2
|
||||||
|
*/
|
||||||
|
template<class StringType>
|
||||||
|
size_t HowManyDirs(const StringType * str, bool is_last_dir = false)
|
||||||
|
{
|
||||||
|
size_t res = 0;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
// first slash (root dir) is not calculated
|
||||||
|
while( str[i]=='/' )
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
while( str[i] )
|
||||||
|
{
|
||||||
|
if( str[i]=='/' )
|
||||||
|
{
|
||||||
|
res += 1;
|
||||||
|
|
||||||
|
while( str[i]=='/' )
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( is_last_dir && i>0 && str[i-1]!='/' )
|
||||||
|
res += 1;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
size_t HowManyDirs(const StringType & str, bool is_last_dir = false)
|
||||||
|
{
|
||||||
|
return HowManyDirs(str.c_str(), is_last_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this method skips some first directories from given path
|
||||||
|
|
||||||
|
samples:
|
||||||
|
SkipDirs("/var/test", 1) -> "test"
|
||||||
|
SkipDirs("/var/test/somewhere", 1) -> "test/somewhere"
|
||||||
|
SkipDirs("/var/test/somewhere", 2) -> "somewhere"
|
||||||
|
SkipDirs("/var/test/somewhere", 10) -> ""
|
||||||
|
*/
|
||||||
|
template<class StringType>
|
||||||
|
const StringType * SkipDirs(const StringType * str, size_t how_many_skip)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
size_t skipped = 0;
|
||||||
|
|
||||||
|
if( how_many_skip == 0 )
|
||||||
|
return str;
|
||||||
|
|
||||||
|
// first slash (root dir) is not calculated
|
||||||
|
while( str[i]=='/' )
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
while( str[i] )
|
||||||
|
{
|
||||||
|
if( str[i]=='/' )
|
||||||
|
{
|
||||||
|
skipped += 1;
|
||||||
|
|
||||||
|
while( str[i]=='/' )
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
if( skipped == how_many_skip )
|
||||||
|
return str+i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool IsEmailCorrectChar(wchar_t c);
|
||||||
|
bool ValidateEmail(const wchar_t * email);
|
||||||
bool ValidateEmail(const std::wstring & email);
|
bool ValidateEmail(const std::wstring & email);
|
||||||
|
|
||||||
bool IsFile(const wchar_t * file);
|
bool IsFile(const wchar_t * file);
|
||||||
bool IsFile(const std::wstring & file);
|
bool IsFile(const std::wstring & file);
|
||||||
bool CreateDir(const wchar_t * dir, int priv);
|
bool CreateDir(const wchar_t * dir, int priv, int group = -1);
|
||||||
bool CreateDir(const std::wstring & dir, int priv);
|
bool CreateDir(const std::wstring & dir, int priv, int group = -1);
|
||||||
|
|
||||||
// creating directories (dirs) under base_dir (base_dir must exist)
|
// 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)
|
// 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 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, 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(FILE * in, FILE * out);
|
||||||
bool CopyFile(const wchar_t * src, const wchar_t * dst);
|
bool CopyFile(const wchar_t * src, const wchar_t * dst);
|
||||||
@@ -413,21 +751,334 @@ 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 RenameFile(const std::wstring & from, const std::wstring & to);
|
||||||
|
|
||||||
|
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content = true);
|
||||||
|
bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content = true);
|
||||||
|
|
||||||
|
|
||||||
const wchar_t * GetFileExt(const wchar_t * name);
|
const wchar_t * GetFileExt(const wchar_t * name);
|
||||||
int SelectFileType(const wchar_t * file_name);
|
int SelectFileType(const wchar_t * file_name);
|
||||||
int SelectFileType(const std::wstring & file_name);
|
int SelectFileType(const std::wstring & file_name);
|
||||||
|
|
||||||
|
|
||||||
time_t Time(const tm & par);
|
|
||||||
time_t Time(const tm * par);
|
|
||||||
tm Time(time_t par);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// thread safe
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void UrlEncode(char c,
|
||||||
|
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear_out = true)
|
||||||
|
{
|
||||||
|
char buffer[10];
|
||||||
|
size_t buflen = sizeof(buffer)/sizeof(char);
|
||||||
|
|
||||||
|
if( clear_out )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
if( (c >= 'a' && c <= 'z') ||
|
||||||
|
(c >= 'A' && c <= 'Z') ||
|
||||||
|
(c >= '0' && c <= '9') ||
|
||||||
|
c == '.' || c == ',' || c == '-' || c == '_' || c == '(' || c == ')' )
|
||||||
|
{
|
||||||
|
out << c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Toa(static_cast<unsigned char>(c), buffer, buflen, 16);
|
||||||
|
out << '%';
|
||||||
|
|
||||||
|
if( buffer[1] == 0 )
|
||||||
|
out << '0'; // there is only one character in the buffer
|
||||||
|
|
||||||
|
out << buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// thread safe
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void UrlEncode(const char * in,
|
||||||
|
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear_out = true)
|
||||||
|
{
|
||||||
|
if( clear_out )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
for(size_t i=0 ; in[i] != 0 ; ++i)
|
||||||
|
UrlEncode(in[i], out, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// thread safe
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void UrlEncode(const std::string & in,
|
||||||
|
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear_out = true)
|
||||||
|
{
|
||||||
|
UrlEncode(in.c_str(), out, clear_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// not thread safe
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void UrlEncode(const wchar_t * in,
|
||||||
|
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear_out = true)
|
||||||
|
{
|
||||||
|
static std::string ain;
|
||||||
|
|
||||||
|
PT::WideToUTF8(in, ain);
|
||||||
|
|
||||||
|
if( clear_out )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
for(size_t i=0 ; i < ain.size() ; ++i)
|
||||||
|
UrlEncode(ain[i], out, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// not thread safe
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void UrlEncode(const std::wstring & in,
|
||||||
|
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear_out = true)
|
||||||
|
{
|
||||||
|
UrlEncode(in.c_str(), out, clear_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// no thread safe
|
||||||
|
template<class StringType>
|
||||||
|
void UrlEncode(char c, StringType & out, bool clear_out = true)
|
||||||
|
{
|
||||||
|
static PT::TextStream tmp;
|
||||||
|
|
||||||
|
UrlEncode(c, tmp);
|
||||||
|
tmp.to_string(out, clear_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// !! IMROVE ME we need some UrlEncode methods with PT::TextBuffer instead of std::string
|
||||||
|
|
||||||
|
|
||||||
|
void UrlEncode(const char * in, std::string & out, bool clear_out = true);
|
||||||
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
|
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
|
||||||
|
void UrlEncode(const wchar_t * in, std::string & out, bool clear_out = true);
|
||||||
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
|
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
|
||||||
|
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out = true);
|
||||||
|
void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out = true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
if( (c>='A' && c<='Z') ||
|
||||||
|
(c>='a' && c<='z') ||
|
||||||
|
(c>='0' && c<='9') )
|
||||||
|
{
|
||||||
|
out << c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char buf1[10];
|
||||||
|
char buf2[10];
|
||||||
|
|
||||||
|
size_t len1 = sizeof(buf1) / sizeof(char);
|
||||||
|
size_t len2 = sizeof(buf2) / sizeof(char);
|
||||||
|
size_t len = PT::IntToUTF8(int(c), buf1, len1);
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<len ; ++i)
|
||||||
|
{
|
||||||
|
// make sure that it produces *capital* letters (ABC...)
|
||||||
|
Toa((unsigned long)(unsigned char)buf1[i], buf2, len2, 16);
|
||||||
|
out << '=';
|
||||||
|
|
||||||
|
if( buf2[1] == 0 )
|
||||||
|
out << '0';
|
||||||
|
|
||||||
|
out << buf2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this encoding is used in mails headers
|
||||||
|
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
|
||||||
|
http://www.faqs.org/rfcs/rfc1522.html
|
||||||
|
|
||||||
|
we have:
|
||||||
|
charset = UTF-8
|
||||||
|
encoding = Q
|
||||||
|
|
||||||
|
current limitation:
|
||||||
|
we do not support checking the maximum length:
|
||||||
|
"An encoded-word may not be more than 75 characters long, including
|
||||||
|
charset, encoding, encoded-text, and delimiters."
|
||||||
|
*/
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void QEncode(const wchar_t * in, PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear = true)
|
||||||
|
{
|
||||||
|
if( clear )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
out << "=?UTF-8?Q?";
|
||||||
|
|
||||||
|
for( ; *in ; ++in)
|
||||||
|
QEncodeAddChar(*in, out);
|
||||||
|
|
||||||
|
out << "?=";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void QEncode(const std::wstring & in, PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear = true)
|
||||||
|
{
|
||||||
|
if( clear )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
out << "=?UTF-8?Q?";
|
||||||
|
|
||||||
|
// do not use QEncode(in.c_str()) as 'in' can have a zero byte
|
||||||
|
for(size_t i=0 ; i<in.size() ; ++i)
|
||||||
|
QEncodeAddChar(in[i], out);
|
||||||
|
|
||||||
|
out << "?=";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void QEncode(const std::wstring & in, std::string & out, bool clear = true);
|
void QEncode(const std::wstring & in, std::string & out, bool clear = true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void RemovePostFileTmp(PostFileTab & post_file_tab);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
short_str is removed from long_str (and a last dots are removed too)
|
||||||
|
and the result is stored in out
|
||||||
|
|
||||||
|
sample:
|
||||||
|
short_str: "mydomain.tld"
|
||||||
|
long_str: "www.subdomain.mydomain.tld"
|
||||||
|
out: "www.subdomain"
|
||||||
|
|
||||||
|
short_str: "mydomain.tld"
|
||||||
|
long_str: "otherdifferentstring"
|
||||||
|
out: ""
|
||||||
|
*/
|
||||||
|
template<class StringType1, class StringType2, class StringType3>
|
||||||
|
void CreateSubdomain(const StringType1 * short_str, const StringType2 * long_str, StringType3 & out)
|
||||||
|
{
|
||||||
|
size_t i1, i2;
|
||||||
|
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
for(i1=0 ; short_str[i1] != 0 ; ++i1);
|
||||||
|
for(i2=0 ; long_str[i2] != 0 ; ++i2);
|
||||||
|
|
||||||
|
if( i1 >= i2 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// i1 is < i2
|
||||||
|
|
||||||
|
while( i1-- > 0 )
|
||||||
|
{
|
||||||
|
i2 -= 1;
|
||||||
|
|
||||||
|
if( short_str[i1] != long_str[i2] )
|
||||||
|
return; // short_str is not a last substring of long_str
|
||||||
|
}
|
||||||
|
|
||||||
|
while( i2>0 && long_str[i2-1] == '.' )
|
||||||
|
i2 -= 1;
|
||||||
|
|
||||||
|
for(i1=0 ; i1 < i2 ; ++i1)
|
||||||
|
out += long_str[i1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename IntType>
|
||||||
|
void SetMinMax(IntType & val, IntType min_val, IntType max_val)
|
||||||
|
{
|
||||||
|
if( val < min_val )
|
||||||
|
val = min_val;
|
||||||
|
|
||||||
|
if( val > max_val )
|
||||||
|
val = max_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class Stream, class StringType>
|
||||||
|
void JSONescape(Stream & out, const StringType & str)
|
||||||
|
{
|
||||||
|
// !! IMPROVE ME (optimizing)
|
||||||
|
// it is better to not write one by one character
|
||||||
|
// but use write method insted
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<str.size() ; ++i)
|
||||||
|
{
|
||||||
|
switch(str[i])
|
||||||
|
{
|
||||||
|
case 0: out << '\\'; out << '0'; break;
|
||||||
|
case '\r': out << '\\'; out << 'r'; break;
|
||||||
|
case '\n': out << '\\'; out << 'n'; break;
|
||||||
|
case '\t': out << '\\'; out << 't'; break;
|
||||||
|
case 0x08: out << '\\'; out << 'b'; break;
|
||||||
|
case 0x0c: out << '\\'; out << 'f'; break;
|
||||||
|
case '\\': out << '\\'; out << '\\'; break;
|
||||||
|
//case '/': out << '\\'; out << '/'; break; // slash doesn't have to be escaped
|
||||||
|
case '"': out << '\\'; out << '\"'; break;
|
||||||
|
default:
|
||||||
|
out << str[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+37
-3
@@ -1,16 +1,46 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "mount.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Mount::Mount()
|
Mount::Mount()
|
||||||
{
|
{
|
||||||
@@ -109,3 +139,7 @@ const std::wstring & Mount::FirstArg(int code) const
|
|||||||
return Arg(code, 0);
|
return Arg(code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+35
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +41,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Mount
|
class Mount
|
||||||
{
|
{
|
||||||
@@ -67,5 +96,8 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+166
-50
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "mountparser.h"
|
||||||
@@ -12,12 +37,32 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MountParser::MountParser()
|
MountParser::MountParser()
|
||||||
{
|
{
|
||||||
dirs = 0;
|
dirs = 0;
|
||||||
|
skip_static = false;
|
||||||
mount_type_tab = 0;
|
mount_type_tab = 0;
|
||||||
mount_fs_tab = 0;
|
mount_fs_tab = 0;
|
||||||
mount_par_tab = 0;
|
mount_par_tab = 0;
|
||||||
|
static_mount_id = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void MountParser::SkipStaticDirs(bool skip)
|
||||||
|
{
|
||||||
|
skip_static = skip;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MountParser::SetStaticMountId(int id)
|
||||||
|
{
|
||||||
|
static_mount_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -233,15 +278,14 @@ return -1;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MountParser::ReadMountType()
|
bool MountParser::ReadMountType()
|
||||||
{
|
{
|
||||||
ReadWord(temp);
|
ReadWord(temp);
|
||||||
|
|
||||||
if( temp.empty() )
|
if( temp.empty() )
|
||||||
{
|
{
|
||||||
// an empty line (some white characters only)
|
// an empty line (some white characters only)
|
||||||
err = WINIX_ERR_EMPTY;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mount.type = FindIndex(mount_type_tab, temp);
|
mount.type = FindIndex(mount_type_tab, temp);
|
||||||
@@ -252,34 +296,38 @@ void MountParser::ReadMountType()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = WINIX_ERR_MOUNT_UNKNOWN;
|
|
||||||
log << log1 << "MP: unknown mount type: " << temp << logend;
|
log << log1 << "MP: unknown mount type: " << temp << logend;
|
||||||
|
slog << logerror << T("unknown_mount_type") << ": " << temp << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mount.type != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MountParser::ReadMountPoint()
|
bool MountParser::ReadMountPoint()
|
||||||
{
|
{
|
||||||
ReadWord(temp);
|
ReadWord(last_dir);
|
||||||
|
|
||||||
pdir = dirs->GetDir(temp);
|
pdir = dirs->GetDir(last_dir);
|
||||||
|
|
||||||
if( pdir )
|
if( pdir )
|
||||||
{
|
{
|
||||||
mount.dir_id = pdir->id;
|
mount.dir_id = pdir->id;
|
||||||
log << log3 << "MP: mount point (directory): " << temp << logend;
|
log << log3 << "MP: mount point (directory): " << last_dir << logend;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = WINIX_ERR_NO_MOUNTPOINT;
|
log << log1 << "MP: there is no such a mount point (directory): " << last_dir << logend;
|
||||||
log << log1 << "MP: there is no such a mount point (directory): " << temp << logend;
|
slog << logerror << T("no_such_dir") << ": " << last_dir << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pdir != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MountParser::ReadFs()
|
bool MountParser::ReadFs()
|
||||||
{
|
{
|
||||||
ReadWord(temp);
|
ReadWord(temp);
|
||||||
mount.fs = FindIndex(mount_fs_tab, temp);
|
mount.fs = FindIndex(mount_fs_tab, temp);
|
||||||
@@ -290,9 +338,11 @@ void MountParser::ReadFs()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = WINIX_ERR_UNKNOWN_FILESYSTEM;
|
|
||||||
log << log1 << "MP: unknown filesystem: " << temp << logend;
|
log << log1 << "MP: unknown filesystem: " << temp << logend;
|
||||||
|
slog << logerror << T("unknown_filesystem") << ": " << temp << " (" << last_dir << ")" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mount.fs != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -332,39 +382,118 @@ void MountParser::ReadMountParams()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log << log1 << "MP: unknown mount param: " << temp << " (skipped)" << logend;
|
log << log1 << "MP: unknown mount param: " << temp << logend;
|
||||||
|
slog << logwarning << T("unknown_mount_param") << ": " << temp << " (" << T("skipped") << ")" << logend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MountParser::ReadRow(std::map<long, Mount> & output)
|
void MountParser::AddParams(Mount::Param & src, Mount::Param & dst)
|
||||||
{
|
{
|
||||||
ReadMountType();
|
if( src.size() != dst.size() )
|
||||||
|
|
||||||
if( err == WINIX_ERR_EMPTY )
|
|
||||||
{
|
{
|
||||||
err = WINIX_ERR_OK;
|
log << log1 << "MP: addparams: incorrect sizes" << logend;
|
||||||
SkipLine();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( err == WINIX_ERR_OK )
|
for(size_t p=0 ; p < src.size() ; ++p)
|
||||||
ReadMountPoint();
|
{
|
||||||
|
if( src[p].defined && !dst[p].defined )
|
||||||
|
dst[p] = src[p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( err == WINIX_ERR_OK )
|
|
||||||
ReadFs();
|
|
||||||
|
|
||||||
if( err == WINIX_ERR_OK )
|
|
||||||
|
|
||||||
|
bool MountParser::AddParamsBefore(long dir_id)
|
||||||
|
{
|
||||||
|
std::map<long, Mount>::iterator i = poutput->find(dir_id);
|
||||||
|
|
||||||
|
if( i == poutput->end() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
AddParams(i->second.param, mount_inserted.first->second.param);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
adding all non-existing parameters to this mount point from parents
|
||||||
|
*/
|
||||||
|
void MountParser::AddParamsBefore()
|
||||||
|
{
|
||||||
|
if( !pdir )
|
||||||
|
return;
|
||||||
|
|
||||||
|
Item * dir;
|
||||||
|
long dir_id = pdir->parent_id;
|
||||||
|
|
||||||
|
while( dir_id != -1 )
|
||||||
|
{
|
||||||
|
if( AddParamsBefore(dir_id) )
|
||||||
|
{
|
||||||
|
// we don't have to check others parents
|
||||||
|
// the parameters are already copied
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = dirs->GetDir(dir_id);
|
||||||
|
|
||||||
|
if( !dir )
|
||||||
|
break;
|
||||||
|
|
||||||
|
dir_id = dir->parent_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
adding all non-existing parameters to childs (childs to this mount point)
|
||||||
|
*/
|
||||||
|
void MountParser::AddParamsAfter()
|
||||||
|
{
|
||||||
|
std::map<long, Mount>::iterator i = poutput->begin();
|
||||||
|
|
||||||
|
for( ; i != poutput->end() ; ++i)
|
||||||
|
{
|
||||||
|
if( dirs->IsChild(mount_inserted.first->second.dir_id, i->first) )
|
||||||
|
AddParams(mount_inserted.first->second.param, i->second.param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MountParser::ReadRow()
|
||||||
|
{
|
||||||
|
if( ReadMountType() && ReadMountPoint() && ReadFs() )
|
||||||
|
{
|
||||||
ReadMountParams();
|
ReadMountParams();
|
||||||
|
|
||||||
if( err == WINIX_ERR_OK )
|
if( skip_static && mount.type==static_mount_id )
|
||||||
{
|
{
|
||||||
std::pair<std::map<long, Mount>::iterator, bool> res = output.insert( std::make_pair(mount.dir_id, mount) );
|
log << log1 << "MP: static mount points are skipped (dont_use_static_dirs in config is true)" << logend;
|
||||||
|
slog << logwarning << T("skipped_static_mount") << ": " << last_dir << logend;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mount_inserted = poutput->insert( std::make_pair(mount.dir_id, mount) );
|
||||||
|
|
||||||
if( !res.second )
|
if( mount_inserted.second )
|
||||||
|
{
|
||||||
|
AddParamsBefore();
|
||||||
|
AddParamsAfter();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
log << log1 << "MP: this mount point exists (skipped)" << logend;
|
log << log1 << "MP: this mount point exists (skipped)" << logend;
|
||||||
|
slog << logwarning << T("mount_exists") << ": " << last_dir << " (" << T("skipped") << ")" << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipLine();
|
SkipLine();
|
||||||
@@ -373,40 +502,27 @@ void MountParser::ReadRow(std::map<long, Mount> & output)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error MountParser::Parse(const std::wstring & input, std::map<long, Mount> & output)
|
void MountParser::Parse(const std::wstring & input, std::map<long, Mount> & output)
|
||||||
{
|
{
|
||||||
if( !dirs || !mount_type_tab || !mount_fs_tab || !mount_par_tab )
|
if( !dirs || !mount_type_tab || !mount_fs_tab || !mount_par_tab )
|
||||||
{
|
{
|
||||||
log << log1 << "pdir: " << pdir << logend;
|
|
||||||
log << log1 << "type: " << mount_type_tab << logend;
|
|
||||||
log << log1 << "fs: " << mount_fs_tab << logend;
|
|
||||||
log << log1 << "par: " << mount_par_tab << logend;
|
|
||||||
|
|
||||||
log << log1 << "MP: input tables not set" << logend;
|
log << log1 << "MP: input tables not set" << logend;
|
||||||
return WINIX_NOTHING_TO_DO; // !! may a better code?
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pinput = input.c_str();
|
pinput = input.c_str();
|
||||||
err = WINIX_ERR_OK;
|
poutput = &output;
|
||||||
|
|
||||||
mount.param.resize(mount_par_tab->size());
|
mount.param.resize(mount_par_tab->size());
|
||||||
mount.ClearParams();
|
mount.ClearParams();
|
||||||
|
poutput->clear();
|
||||||
|
|
||||||
output.clear();
|
while( *pinput )
|
||||||
|
ReadRow();
|
||||||
while( *pinput && err == WINIX_ERR_OK )
|
|
||||||
ReadRow(output);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+55
-13
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_mountparser
|
||||||
@@ -18,17 +43,25 @@
|
|||||||
|
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "error.h"
|
|
||||||
#include "dirs.h"
|
#include "dirs.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MountParser
|
class MountParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MountParser();
|
MountParser();
|
||||||
Error Parse(const std::wstring & input, std::map<long, Mount> & output);
|
|
||||||
|
void SkipStaticDirs(bool skip);
|
||||||
|
void SetStaticMountId(int id);
|
||||||
|
|
||||||
|
void Parse(const std::wstring & input, std::map<long, Mount> & output);
|
||||||
void SetDirs(Dirs * pdirs);
|
void SetDirs(Dirs * pdirs);
|
||||||
void SetMountTypeTab(const std::vector<std::wstring> & tab);
|
void SetMountTypeTab(const std::vector<std::wstring> & tab);
|
||||||
void SetMountFsTab(const std::vector<std::wstring> & tab);
|
void SetMountFsTab(const std::vector<std::wstring> & tab);
|
||||||
@@ -37,6 +70,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
Dirs * dirs;
|
Dirs * dirs;
|
||||||
|
bool skip_static;
|
||||||
|
int static_mount_id;
|
||||||
|
|
||||||
const std::vector<std::wstring> * mount_type_tab;
|
const std::vector<std::wstring> * mount_type_tab;
|
||||||
const std::vector<std::wstring> * mount_fs_tab;
|
const std::vector<std::wstring> * mount_fs_tab;
|
||||||
@@ -54,24 +89,31 @@ private:
|
|||||||
void ReadParamName(std::wstring & res);
|
void ReadParamName(std::wstring & res);
|
||||||
void ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args);
|
void ReadParam(std::wstring & res, Mount::ParamRow::ParamArg & args);
|
||||||
int FindIndex(const std::vector<std::wstring> * tab, const std::wstring & value);
|
int FindIndex(const std::vector<std::wstring> * tab, const std::wstring & value);
|
||||||
void ReadMountType();
|
bool ReadMountType();
|
||||||
void ReadMountPoint();
|
bool ReadMountPoint();
|
||||||
void ReadFs();
|
bool ReadFs();
|
||||||
void LogMountParams();
|
void LogMountParams();
|
||||||
void ReadMountParams();
|
void ReadMountParams();
|
||||||
void ReadRow(std::map<long, Mount> & output);
|
void ReadRow();
|
||||||
|
void AddParams(Mount::Param & src, Mount::Param & dst);
|
||||||
|
bool AddParamsBefore(long dir_id);
|
||||||
|
void AddParamsBefore();
|
||||||
|
void AddParamsAfter();
|
||||||
|
|
||||||
const wchar_t * pinput;
|
const wchar_t * pinput;
|
||||||
std::wstring temp;
|
std::wstring temp;
|
||||||
|
std::wstring last_dir;
|
||||||
std::wstring temp_arg;
|
std::wstring temp_arg;
|
||||||
Mount::ParamRow::ParamArg param_args;
|
Mount::ParamRow::ParamArg param_args;
|
||||||
|
|
||||||
|
|
||||||
Mount mount;
|
Mount mount;
|
||||||
|
|
||||||
Item * pdir;
|
Item * pdir;
|
||||||
Error err;
|
std::map<long, Mount> * poutput;
|
||||||
|
std::pair<std::map<long, Mount>::iterator, bool> mount_inserted;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+72
-22
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "mounts.h"
|
||||||
@@ -15,16 +40,29 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Mounts::Mounts()
|
Mounts::Mounts()
|
||||||
{
|
{
|
||||||
pmount = &empty_mount;
|
pmount = &empty_mount;
|
||||||
|
skip_static = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mounts::SkipStaticDirs(bool skip)
|
||||||
|
{
|
||||||
|
skip_static = skip;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Mounts::CreateMountType()
|
void Mounts::CreateMountType()
|
||||||
{
|
{
|
||||||
mount_type_cms = AddMountType(L"cms");
|
mount_type_cms = AddMountType(L"cms");
|
||||||
|
mount_type_static = AddMountType(L"static");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,13 +78,18 @@ void Mounts::CreateMountPar()
|
|||||||
mount_par_page = AddMountPar(L"page");
|
mount_par_page = AddMountPar(L"page");
|
||||||
mount_par_thumb_size = AddMountPar(L"thumb_size");
|
mount_par_thumb_size = AddMountPar(L"thumb_size");
|
||||||
mount_par_thumb_mode = AddMountPar(L"thumb_mode");
|
mount_par_thumb_mode = AddMountPar(L"thumb_mode");
|
||||||
//mount_par_thread = AddMountPar(L"thread");
|
mount_par_thumb_quality = AddMountPar(L"thumb_quality");
|
||||||
//mount_par_createthread_on = AddMountPar(L"createthread_on");
|
mount_par_image_size = AddMountPar(L"image_size");
|
||||||
mount_par_only_root_remove = AddMountPar(L"only_root_remove");
|
mount_par_image_mode = AddMountPar(L"image_mode");
|
||||||
|
mount_par_image_quality = AddMountPar(L"image_quality");
|
||||||
mount_par_emacs_on = AddMountPar(L"emacs_on");
|
mount_par_emacs_on = AddMountPar(L"emacs_on");
|
||||||
mount_par_mkdir_on = AddMountPar(L"mkdir_on");
|
mount_par_mkdir_on = AddMountPar(L"mkdir_on");
|
||||||
mount_par_app = AddMountPar(L"app");
|
mount_par_app = AddMountPar(L"app");
|
||||||
mount_par_html_template = AddMountPar(L"html_template");
|
mount_par_html_template = AddMountPar(L"html_template");
|
||||||
|
mount_par_change_template = AddMountPar(L"change_template");
|
||||||
|
mount_par_static = AddMountPar(L"static");
|
||||||
|
mount_par_css = AddMountPar(L"css");
|
||||||
|
mount_par_lang = AddMountPar(L"lang");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -56,7 +99,7 @@ void Mounts::CreateMounts()
|
|||||||
CreateMountFs();
|
CreateMountFs();
|
||||||
CreateMountPar();
|
CreateMountPar();
|
||||||
|
|
||||||
plugin.Call(WINIX_ADD_MOUNTS);
|
plugin.Call((Session*)0, WINIX_ADD_MOUNTS);
|
||||||
|
|
||||||
empty_mount.param.resize(mount_par_tab.size());
|
empty_mount.param.resize(mount_par_tab.size());
|
||||||
empty_mount.ClearParams();
|
empty_mount.ClearParams();
|
||||||
@@ -165,25 +208,19 @@ const std::wstring & Mounts::GetMountPar(int id)
|
|||||||
|
|
||||||
|
|
||||||
// reading from 'mounts'
|
// reading from 'mounts'
|
||||||
Error Mounts::ReadMounts(const std::wstring & mounts)
|
void Mounts::ReadMounts(const std::wstring & mounts)
|
||||||
{
|
{
|
||||||
|
mount_parser.SkipStaticDirs(skip_static);
|
||||||
|
mount_parser.SetStaticMountId(mount_type_static);
|
||||||
mount_parser.SetDirs(dirs);
|
mount_parser.SetDirs(dirs);
|
||||||
mount_parser.SetMountTypeTab(mount_type_tab);
|
mount_parser.SetMountTypeTab(mount_type_tab);
|
||||||
mount_parser.SetMountFsTab(mount_fs_tab);
|
mount_parser.SetMountFsTab(mount_fs_tab);
|
||||||
mount_parser.SetMountParTab(mount_par_tab);
|
mount_parser.SetMountParTab(mount_par_tab);
|
||||||
|
|
||||||
Error err = mount_parser.Parse(mounts, mount_tab);
|
mount_parser.Parse(mounts, mount_tab);
|
||||||
|
|
||||||
if( err != WINIX_ERR_OK )
|
|
||||||
{
|
|
||||||
log << log1 << "M: some problems with mountpoints (mountpoints table will be empty)" << logend;
|
|
||||||
mount_tab.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
CalcCurMount();
|
CalcCurMount();
|
||||||
plugin.Call(WINIX_FSTAB_CHANGED);
|
plugin.Call((Session*)0, WINIX_FSTAB_CHANGED);
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -216,7 +253,9 @@ Error Mounts::ReadMounts()
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReadMounts(fstab.content);
|
ReadMounts(fstab.content);
|
||||||
|
|
||||||
|
return WINIX_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -246,7 +285,7 @@ void Mounts::MountCmsForRoot()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Mounts::CalcCurMount()
|
Mount * Mounts::CalcCurMount()
|
||||||
{
|
{
|
||||||
std::vector<Item*>::reverse_iterator i;
|
std::vector<Item*>::reverse_iterator i;
|
||||||
|
|
||||||
@@ -255,7 +294,7 @@ std::vector<Item*>::reverse_iterator i;
|
|||||||
// when the program starts (when the dir_tab is empty()
|
// when the program starts (when the dir_tab is empty()
|
||||||
// we don't want to call MountCmsForRoot()
|
// we don't want to call MountCmsForRoot()
|
||||||
if( cur->request->dir_tab.empty() )
|
if( cur->request->dir_tab.empty() )
|
||||||
return;
|
return pmount;
|
||||||
|
|
||||||
for(i = cur->request->dir_tab.rbegin() ; i!=cur->request->dir_tab.rend() ; ++i)
|
for(i = cur->request->dir_tab.rbegin() ; i!=cur->request->dir_tab.rend() ; ++i)
|
||||||
{
|
{
|
||||||
@@ -266,7 +305,7 @@ std::vector<Item*>::reverse_iterator i;
|
|||||||
pmount = &(m->second);
|
pmount = &(m->second);
|
||||||
log << log2 << "M: current mount point is: " << GetMountType(pmount->type)
|
log << log2 << "M: current mount point is: " << GetMountType(pmount->type)
|
||||||
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
||||||
return;
|
return pmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +314,8 @@ std::vector<Item*>::reverse_iterator i;
|
|||||||
MountCmsForRoot();
|
MountCmsForRoot();
|
||||||
log << log2 << "M: current mount point is: " << GetMountType(pmount->type) << " (default)"
|
log << log2 << "M: current mount point is: " << GetMountType(pmount->type) << " (default)"
|
||||||
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
||||||
|
|
||||||
|
return pmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -305,3 +346,12 @@ const Mounts::MountTab * Mounts::GetMountTab()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Mount * Mounts::GetEmptyMount()
|
||||||
|
{
|
||||||
|
return &empty_mount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+67
-12
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -23,11 +48,19 @@
|
|||||||
#include "mountparser.h"
|
#include "mountparser.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Mounts
|
class Mounts
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
void SkipStaticDirs(bool skip);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mount point's types
|
mount point's types
|
||||||
*/
|
*/
|
||||||
@@ -37,6 +70,7 @@ public:
|
|||||||
|
|
||||||
// id of a specific mount type (the id is always valid)
|
// id of a specific mount type (the id is always valid)
|
||||||
int MountTypeCms() { return mount_type_cms; }
|
int MountTypeCms() { return mount_type_cms; }
|
||||||
|
int MountTypeStatic() { return mount_type_static; }
|
||||||
|
|
||||||
// return -1 if there is no such a mount type
|
// return -1 if there is no such a mount type
|
||||||
// or index otherwhise
|
// or index otherwhise
|
||||||
@@ -65,14 +99,18 @@ public:
|
|||||||
int MountParPage() { return mount_par_page; }
|
int MountParPage() { return mount_par_page; }
|
||||||
int MountParThumbSize() { return mount_par_thumb_size; }
|
int MountParThumbSize() { return mount_par_thumb_size; }
|
||||||
int MountParThumbMode() { return mount_par_thumb_mode; }
|
int MountParThumbMode() { return mount_par_thumb_mode; }
|
||||||
//int MountParThread() { return mount_par_thread; }
|
int MountParThumbQuality() { return mount_par_thumb_quality; }
|
||||||
//int MountParCreatethreadOn() { return mount_par_createthread_on; }
|
int MountParImageSize() { return mount_par_image_size; }
|
||||||
int MountParOnlyRootRemove() { return mount_par_only_root_remove; }
|
int MountParImageMode() { return mount_par_image_mode; }
|
||||||
|
int MountParImageQuality() { return mount_par_image_quality; }
|
||||||
int MountParEmacsOn() { return mount_par_emacs_on; }
|
int MountParEmacsOn() { return mount_par_emacs_on; }
|
||||||
int MountParMkdirOn() { return mount_par_mkdir_on; }
|
int MountParMkdirOn() { return mount_par_mkdir_on; }
|
||||||
int MountParApp() { return mount_par_app; }
|
int MountParApp() { return mount_par_app; }
|
||||||
int MountParHtmlTemplate() { return mount_par_html_template; }
|
int MountParHtmlTemplate() { return mount_par_html_template; }
|
||||||
|
int MountParChangeTemplate() { return mount_par_change_template; }
|
||||||
|
int MountParStatic() { return mount_par_static; }
|
||||||
|
int MountParCss() { return mount_par_css; }
|
||||||
|
int MountParLang() { return mount_par_lang; }
|
||||||
|
|
||||||
void SetDirs(Dirs * pdirs);
|
void SetDirs(Dirs * pdirs);
|
||||||
void SetDb(Db * pdb);
|
void SetDb(Db * pdb);
|
||||||
@@ -84,25 +122,33 @@ public:
|
|||||||
Mounts();
|
Mounts();
|
||||||
void CreateMounts();
|
void CreateMounts();
|
||||||
|
|
||||||
Error ReadMounts(const std::wstring & mounts);
|
void ReadMounts(const std::wstring & mounts);
|
||||||
Error ReadMounts();
|
Error ReadMounts();
|
||||||
|
|
||||||
void CalcCurMount();
|
Mount * CalcCurMount();
|
||||||
Mount * CalcMount(long dir_id);
|
Mount * CalcMount(long dir_id);
|
||||||
|
|
||||||
// current mount point
|
// current mount point
|
||||||
// will not be null after calling CalcCurMount() or ReadMounts([...])
|
// will not be null after calling CalcCurMount() or ReadMounts([...])
|
||||||
|
// !! nie korzystac obecnie z niego
|
||||||
|
// korzystac z cur->mount
|
||||||
|
// a tez zostanie wycofany
|
||||||
Mount * pmount;
|
Mount * pmount;
|
||||||
|
|
||||||
|
|
||||||
const MountTab * GetMountTab();
|
const MountTab * GetMountTab();
|
||||||
|
|
||||||
|
// at the beginning used to initialize cur->mount
|
||||||
|
Mount * GetEmptyMount();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Db * db;
|
Db * db;
|
||||||
Dirs * dirs;
|
Dirs * dirs;
|
||||||
Cur * cur;
|
Cur * cur;
|
||||||
|
|
||||||
|
bool skip_static;
|
||||||
|
|
||||||
Mount empty_mount;
|
Mount empty_mount;
|
||||||
const std::wstring empty_str;
|
const std::wstring empty_str;
|
||||||
|
|
||||||
@@ -111,6 +157,7 @@ private:
|
|||||||
std::vector<std::wstring> mount_type_tab;
|
std::vector<std::wstring> mount_type_tab;
|
||||||
|
|
||||||
int mount_type_cms;
|
int mount_type_cms;
|
||||||
|
int mount_type_static;
|
||||||
|
|
||||||
// simplefs
|
// simplefs
|
||||||
// hashfs
|
// hashfs
|
||||||
@@ -124,13 +171,18 @@ private:
|
|||||||
int mount_par_page;
|
int mount_par_page;
|
||||||
int mount_par_thumb_size;
|
int mount_par_thumb_size;
|
||||||
int mount_par_thumb_mode;
|
int mount_par_thumb_mode;
|
||||||
//int mount_par_thread;
|
int mount_par_thumb_quality;
|
||||||
//int mount_par_createthread_on;
|
int mount_par_image_size;
|
||||||
int mount_par_only_root_remove;
|
int mount_par_image_mode;
|
||||||
|
int mount_par_image_quality;
|
||||||
int mount_par_emacs_on;
|
int mount_par_emacs_on;
|
||||||
int mount_par_mkdir_on;
|
int mount_par_mkdir_on;
|
||||||
int mount_par_app;
|
int mount_par_app;
|
||||||
int mount_par_html_template;
|
int mount_par_html_template;
|
||||||
|
int mount_par_change_template;
|
||||||
|
int mount_par_static;
|
||||||
|
int mount_par_css;
|
||||||
|
int mount_par_lang;
|
||||||
|
|
||||||
|
|
||||||
MountTab mount_tab;
|
MountTab mount_tab;
|
||||||
@@ -143,5 +195,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+173
-67
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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>
|
#include <dlfcn.h>
|
||||||
@@ -14,6 +39,9 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::UnloadPlugins()
|
void Plugin::UnloadPlugins()
|
||||||
@@ -41,9 +69,6 @@ Plugin::Plugin()
|
|||||||
templates = 0;
|
templates = 0;
|
||||||
synchro = 0;
|
synchro = 0;
|
||||||
session_manager = 0;
|
session_manager = 0;
|
||||||
|
|
||||||
ret_false = 0;
|
|
||||||
ret_true = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -101,6 +126,21 @@ void Plugin::SetSessionManager(SessionManager * psession_manager)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Lock()
|
||||||
|
{
|
||||||
|
if( synchro )
|
||||||
|
synchro->Lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Unlock()
|
||||||
|
{
|
||||||
|
if( synchro )
|
||||||
|
synchro->Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Plugin::SetPointers(PluginInfo & info)
|
bool Plugin::SetPointers(PluginInfo & info)
|
||||||
{
|
{
|
||||||
@@ -108,7 +148,11 @@ bool Plugin::SetPointers(PluginInfo & info)
|
|||||||
bool res = (db && config && cur && system && functions && templates && synchro && session_manager);
|
bool res = (db && config && cur && system && functions && templates && synchro && session_manager);
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
|
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
info.db = db;
|
info.db = db;
|
||||||
info.config = config;
|
info.config = config;
|
||||||
@@ -142,16 +186,18 @@ void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector<std
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::LoadPlugin(const std::string & filename)
|
|
||||||
|
|
||||||
|
// we don't have to use Lock() here because plugins are read
|
||||||
|
// before threads are started
|
||||||
|
void * Plugin::LoadInitFun(const wchar_t * filename, Fun1 & fun_init)
|
||||||
{
|
{
|
||||||
LoadPlugin(filename.c_str());
|
char file[WINIX_OS_PATH_SIZE];
|
||||||
}
|
|
||||||
|
|
||||||
|
if( !WideToUTF8(filename, file, WINIX_OS_PATH_SIZE) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
void * p = dlopen(file, RTLD_NOW | RTLD_LOCAL);
|
||||||
void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
|
|
||||||
{
|
|
||||||
void * p = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
|
|
||||||
|
|
||||||
if( !p )
|
if( !p )
|
||||||
{
|
{
|
||||||
@@ -160,7 +206,7 @@ void * Plugin::LoadInitFun(const char * filename, Fun1 & fun_init)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun_init = (Fun1)dlfunc(p, "Init");
|
fun_init = (Fun1)dlsym(p, "Init");
|
||||||
|
|
||||||
if( !fun_init )
|
if( !fun_init )
|
||||||
{
|
{
|
||||||
@@ -180,7 +226,7 @@ return p;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::LoadPlugin(const char * filename)
|
void Plugin::LoadPlugin(const wchar_t * filename)
|
||||||
{
|
{
|
||||||
Fun1 fun_init;
|
Fun1 fun_init;
|
||||||
void * plugin_handle;
|
void * plugin_handle;
|
||||||
@@ -210,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)
|
void Plugin::LoadPlugin(const std::wstring & filename)
|
||||||
{
|
{
|
||||||
LoadPlugin(filename.c_str());
|
LoadPlugin(filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Plugin::HasPlugin(const wchar_t * name)
|
bool Plugin::HasPlugin(const wchar_t * name)
|
||||||
{
|
{
|
||||||
if( *name == 0 )
|
if( *name == 0 )
|
||||||
@@ -245,24 +285,34 @@ bool Plugin::HasPlugin(const std::wstring & name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Plugin::HasMessage(int message)
|
||||||
|
{
|
||||||
|
return (slots.find(message) != slots.end());
|
||||||
|
}
|
||||||
|
|
||||||
void Plugin::Call(int message, Slots::iterator & slot, PluginInfo & info)
|
|
||||||
|
void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info)
|
||||||
{
|
{
|
||||||
if( !SetPointers(info) )
|
if( !SetPointers(info) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
current_plugin = slot->second.index;
|
current_plugin = slot->second.index;
|
||||||
info.plugin_id = current_plugin;
|
info.plugin_id = current_plugin;
|
||||||
|
info.session = ses;
|
||||||
|
|
||||||
if( current_plugin != -1 )
|
if( current_plugin != -1 && ses )
|
||||||
info.plugin_data_base = cur->session->plugin_data.Get(current_plugin);
|
info.plugin_data_base = ses->plugin_data.Get(current_plugin);
|
||||||
else
|
else
|
||||||
info.plugin_data_base = 0;
|
info.plugin_data_base = 0;
|
||||||
|
|
||||||
if( !slot->second.is_running )
|
if( !slot->second.is_running )
|
||||||
{
|
{
|
||||||
if( config->log_plugin_call )
|
if( config->log_plugin_call )
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
|
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
slot->second.is_running = true;
|
slot->second.is_running = true;
|
||||||
|
|
||||||
@@ -275,27 +325,30 @@ void Plugin::Call(int message, Slots::iterator & slot, PluginInfo & info)
|
|||||||
slot->second.is_running = false;
|
slot->second.is_running = false;
|
||||||
|
|
||||||
if( config->log_plugin_call )
|
if( config->log_plugin_call )
|
||||||
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message << logend;
|
{
|
||||||
|
Lock();
|
||||||
|
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message
|
||||||
|
<< ", result: " << (info.res? "true" : "false") << logend;
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Lock();
|
||||||
log << log1 << "Plugin: id: " << slot->second.index
|
log << log1 << "Plugin: id: " << slot->second.index
|
||||||
<< ", message: " << message
|
<< ", message: " << message
|
||||||
<< ", recurrences are not allowed" << logend;
|
<< ", recurrences are not allowed" << logend;
|
||||||
|
Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, void * p2_, long l1_, long l2_)
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
// how many plugins return 'false' and 'true'
|
PluginRes res;
|
||||||
// we are using local variables because Call() method can be called
|
|
||||||
// from a plugin too (one Call() can execute another Call())
|
|
||||||
int ret_false_loc = 0;
|
|
||||||
int ret_true_loc = 0;
|
|
||||||
int old_current_plugin = current_plugin;
|
int old_current_plugin = current_plugin;
|
||||||
PluginInfo info;
|
PluginInfo info;
|
||||||
|
|
||||||
@@ -309,88 +362,132 @@ PluginInfo info;
|
|||||||
info.l1 = l1_;
|
info.l1 = l1_;
|
||||||
info.l2 = l2_;
|
info.l2 = l2_;
|
||||||
|
|
||||||
Call(message, i, info);
|
Call(ses, message, i, info);
|
||||||
|
|
||||||
if( info.res )
|
if( info.res )
|
||||||
++ret_true_loc;
|
++res.res_true;
|
||||||
else
|
else
|
||||||
++ret_false_loc;
|
++res.res_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_plugin = old_current_plugin;
|
current_plugin = old_current_plugin;
|
||||||
ret_false = ret_false_loc;
|
|
||||||
ret_true = ret_true_loc;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message)
|
PluginRes Plugin::Call(int message)
|
||||||
{
|
{
|
||||||
Call(message, 0, 0, 0, 0);
|
return Call(cur->session, message, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_)
|
PluginRes Plugin::Call(int message, void * p1_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, 0, 0, 0);
|
return Call(cur->session, message, p1_, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, void * p2_)
|
PluginRes Plugin::Call(int message, void * p1_, void * p2_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, p2_, 0, 0);
|
return Call(cur->session, message, p1_, p2_, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, long l1_)
|
PluginRes Plugin::Call(int message, long l1_)
|
||||||
{
|
{
|
||||||
Call(message, 0, 0, l1_, 0);
|
return Call(cur->session, message, 0, 0, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, long l1_, long l2_)
|
PluginRes Plugin::Call(int message, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
Call(message, 0, 0, l1_, l2_);
|
return Call(cur->session, message, 0, 0, l1_, l2_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, long l1_)
|
PluginRes Plugin::Call(int message, void * p1_, long l1_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, 0, l1_, 0);
|
return Call(cur->session, message, p1_, 0, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
PluginRes Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, 0, l1_, l2_);
|
return Call(cur->session, message, p1_, 0, l1_, l2_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
PluginRes Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, p2_, l1_, 0);
|
return Call(cur->session, message, p1_, p2_, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message)
|
||||||
|
{
|
||||||
|
return Call(ses, message, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_)
|
||||||
|
{
|
||||||
|
return Call(ses, message, p1_, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_)
|
||||||
|
{
|
||||||
|
return Call(ses, message, p1_, p2_, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message, long l1_)
|
||||||
|
{
|
||||||
|
return Call(ses, message, 0, 0, l1_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message, long l1_, long l2_)
|
||||||
|
{
|
||||||
|
return Call(ses, message, 0, 0, l1_, l2_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_)
|
||||||
|
{
|
||||||
|
return Call(ses, message, p1_, 0, l1_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_, long l2_)
|
||||||
|
{
|
||||||
|
return Call(ses, message, p1_, 0, l1_, l2_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_)
|
||||||
|
{
|
||||||
|
return Call(ses, message, p1_, p2_, l1_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Plugin::Size()
|
size_t Plugin::Size()
|
||||||
{
|
{
|
||||||
return plugins.size();
|
return plugins.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
int Plugin::True()
|
!! IMPROVE ME
|
||||||
{
|
Assign() can work only if other threads are not started
|
||||||
return ret_true;
|
we can add some barrier/flag so when other threads starts
|
||||||
}
|
then we cannot use Assign() method
|
||||||
|
*/
|
||||||
|
|
||||||
int Plugin::False()
|
|
||||||
{
|
|
||||||
return ret_false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Assign(int message, Fun1 fun1)
|
void Plugin::Assign(int message, Fun1 fun1)
|
||||||
{
|
{
|
||||||
Slot s;
|
Slot s;
|
||||||
@@ -420,3 +517,12 @@ Slot s;
|
|||||||
log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend;
|
log << log3 << "Plugin: added function for message: " << message << ", plugin index: " << s.index << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Plugin::Plugins * Plugin::GetPlugins()
|
||||||
|
{
|
||||||
|
return &plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+104
-42
@@ -1,12 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
#ifndef headerfile_winix_core_plugin
|
||||||
#define headerfile_winix_core_plugin
|
#define headerfile_winix_core_plugin
|
||||||
@@ -26,6 +50,12 @@
|
|||||||
#include "templates/templates.h"
|
#include "templates/templates.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
all your plugin functions can have signature either:
|
all your plugin functions can have signature either:
|
||||||
void my_function(PluginInfo & info); or
|
void my_function(PluginInfo & info); or
|
||||||
@@ -36,7 +66,7 @@
|
|||||||
|
|
||||||
in the Init you can add your own functions by using plugin.Assign() method
|
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
|
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)
|
(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
|
also in Init you can only use logger (log) info.config and info.db objects
|
||||||
(the rest winix objects are not initialized yet)
|
(the rest winix objects are not initialized yet)
|
||||||
@@ -67,8 +97,17 @@ struct PluginInfo
|
|||||||
Synchro * synchro;
|
Synchro * synchro;
|
||||||
SessionManager * session_manager;
|
SessionManager * session_manager;
|
||||||
|
|
||||||
// pointer to the plugin session (can be null if not set by the plugin)
|
// a session
|
||||||
// you should use WINIX_SESSION_CREATED and WINIX_SESSION_REMOVE
|
// some messages are sent in a session's context e.g. logging a user
|
||||||
|
// this pointer in not always the same as cur->session, it is preferred
|
||||||
|
// to use this pointer instead of cur->session
|
||||||
|
// (cur->session can point at a temporary object)
|
||||||
|
// this pointer can be null
|
||||||
|
Session * session;
|
||||||
|
|
||||||
|
// pointer to the plugin session (can be null if not set by the plugin or if session is null)
|
||||||
|
// this is taken from session->plugin_data.Get()
|
||||||
|
// you should use WINIX_SESSION_CREATED and WINIX_PLUGIN_SESSION_DATA_REMOVE
|
||||||
// to create your plugin's session data
|
// to create your plugin's session data
|
||||||
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
|
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
|
||||||
|
|
||||||
@@ -87,6 +126,7 @@ struct PluginInfo
|
|||||||
l2 = 0;
|
l2 = 0;
|
||||||
|
|
||||||
plugin_id = -1;
|
plugin_id = -1;
|
||||||
|
session = 0;
|
||||||
plugin_data_base = 0;
|
plugin_data_base = 0;
|
||||||
|
|
||||||
res = false;
|
res = false;
|
||||||
@@ -94,6 +134,22 @@ struct PluginInfo
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this structure tells how many plugins returned true and false
|
||||||
|
*/
|
||||||
|
struct PluginRes
|
||||||
|
{
|
||||||
|
int res_false;
|
||||||
|
int res_true;
|
||||||
|
|
||||||
|
PluginRes()
|
||||||
|
{
|
||||||
|
res_false = 0;
|
||||||
|
res_true = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Plugin
|
class Plugin
|
||||||
{
|
{
|
||||||
@@ -124,6 +180,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PluginsItem
|
||||||
|
{
|
||||||
|
void * handle;
|
||||||
|
const wchar_t * plugin_name; // plugin name (can be null if was not set by the plugin)
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<PluginsItem> Plugins;
|
||||||
|
|
||||||
|
|
||||||
Plugin();
|
Plugin();
|
||||||
~Plugin();
|
~Plugin();
|
||||||
@@ -137,8 +201,6 @@ public:
|
|||||||
void SetSynchro(Synchro * psynchro);
|
void SetSynchro(Synchro * psynchro);
|
||||||
void SetSessionManager(SessionManager * psession_manager);
|
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 wchar_t * filename);
|
||||||
void LoadPlugin(const std::wstring & filename);
|
void LoadPlugin(const std::wstring & filename);
|
||||||
|
|
||||||
@@ -148,32 +210,38 @@ public:
|
|||||||
bool HasPlugin(const wchar_t * name);
|
bool HasPlugin(const wchar_t * name);
|
||||||
bool HasPlugin(const std::wstring & name);
|
bool HasPlugin(const std::wstring & name);
|
||||||
|
|
||||||
void Call(int message);
|
bool HasMessage(int message);
|
||||||
void Call(int message, void * p1_);
|
|
||||||
void Call(int message, void * p1_, void * p2_);
|
PluginRes Call(int message);
|
||||||
void Call(int message, long l1_);
|
PluginRes Call(int message, void * p1_);
|
||||||
void Call(int message, long l1_, long l2_);
|
PluginRes Call(int message, void * p1_, void * p2_);
|
||||||
void Call(int message, void * p1_, long l1_);
|
PluginRes Call(int message, long l1_);
|
||||||
void Call(int message, void * p1_, long l1_, long l2_);
|
PluginRes Call(int message, long l1_, long l2_);
|
||||||
void Call(int message, void * p1_, void * p2_, long l1_);
|
PluginRes Call(int message, void * p1_, long l1_);
|
||||||
void Call(int message, void * p1_, void * p2_, long l1_, long l2_);
|
PluginRes Call(int message, void * p1_, long l1_, long l2_);
|
||||||
|
PluginRes Call(int message, void * p1_, void * p2_, long l1_);
|
||||||
|
PluginRes Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_);
|
||||||
|
|
||||||
|
PluginRes Call(Session * ses, int message);
|
||||||
|
PluginRes Call(Session * ses, int message, void * p1_);
|
||||||
|
PluginRes Call(Session * ses, int message, void * p1_, void * p2_);
|
||||||
|
PluginRes Call(Session * ses, int message, long l1_);
|
||||||
|
PluginRes Call(Session * ses, int message, long l1_, long l2_);
|
||||||
|
PluginRes Call(Session * ses, int message, void * p1_, long l1_);
|
||||||
|
PluginRes Call(Session * ses, int message, void * p1_, long l1_, long l2_);
|
||||||
|
PluginRes Call(Session * ses, int message, void * p1_, void * p2_, long l1_);
|
||||||
|
|
||||||
// how many plugins there are
|
// how many plugins there are
|
||||||
size_t Size();
|
size_t Size();
|
||||||
|
|
||||||
// how many plugins returned 'true'
|
|
||||||
// from last Call()
|
|
||||||
int True();
|
|
||||||
|
|
||||||
// how many plugins returned 'false'
|
|
||||||
// from last Call()
|
|
||||||
int False();
|
|
||||||
|
|
||||||
// assign a function to a message
|
// assign a function to a message
|
||||||
// you can assign more than one function to a specific message
|
// you can assign more than one function to a specific message
|
||||||
void Assign(int message, Fun1);
|
void Assign(int message, Fun1);
|
||||||
void Assign(int message, Fun2);
|
void Assign(int message, Fun2);
|
||||||
|
|
||||||
|
// return a const pointer to the plugin tab
|
||||||
|
const Plugins * GetPlugins();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Db * db;
|
Db * db;
|
||||||
@@ -185,29 +253,19 @@ private:
|
|||||||
Synchro * synchro;
|
Synchro * synchro;
|
||||||
SessionManager * session_manager;
|
SessionManager * session_manager;
|
||||||
|
|
||||||
int ret_false;
|
std::wstring temp_path; // used when loading plugins
|
||||||
int ret_true;
|
|
||||||
|
|
||||||
std::wstring temp_path;
|
|
||||||
|
|
||||||
struct PluginsItem
|
|
||||||
{
|
|
||||||
void * handle;
|
|
||||||
const wchar_t * plugin_name; // plugin name (can be null if was not set by the plugin)
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<PluginsItem> Plugins;
|
|
||||||
Plugins plugins;
|
Plugins plugins;
|
||||||
|
|
||||||
typedef std::multimap<int, Slot> Slots;
|
typedef std::multimap<int, Slot> Slots;
|
||||||
Slots slots;
|
Slots slots;
|
||||||
|
|
||||||
std::string afilename;
|
void * LoadInitFun(const wchar_t * filename, Fun1 & fun_init);
|
||||||
|
void Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info);
|
||||||
void * LoadInitFun(const char * filename, Fun1 & fun_init);
|
|
||||||
void Call(int message, Slots::iterator & slot, PluginInfo & info);
|
|
||||||
|
|
||||||
bool SetPointers(PluginInfo & info);
|
bool SetPointers(PluginInfo & info);
|
||||||
|
void Lock();
|
||||||
|
void Unlock();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -215,5 +273,9 @@ private:
|
|||||||
|
|
||||||
extern Plugin plugin;
|
extern Plugin plugin;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+100
-36
@@ -1,17 +1,85 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "plugindata.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "session.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData::PluginData()
|
||||||
|
{
|
||||||
|
session = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData::PluginData(const PluginData & p)
|
||||||
|
{
|
||||||
|
operator=(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData & PluginData::operator=(const PluginData & p)
|
||||||
|
{
|
||||||
|
// we don't copy all pointers - only resize the table
|
||||||
|
// pointers will be set to zero
|
||||||
|
Resize(p.Size());
|
||||||
|
session = 0;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData::~PluginData()
|
||||||
|
{
|
||||||
|
DeleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PluginData::SetSession(Session * ses)
|
||||||
|
{
|
||||||
|
session = ses;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -62,46 +130,37 @@ return Get(plugin.current_plugin);
|
|||||||
|
|
||||||
void PluginData::DeleteAll()
|
void PluginData::DeleteAll()
|
||||||
{
|
{
|
||||||
if( table.empty() )
|
bool all_null = true;
|
||||||
return;
|
|
||||||
|
|
||||||
plugin.Call(WINIX_SESSION_REMOVE);
|
/*
|
||||||
|
when we copy a session's object (and this object then)
|
||||||
|
we resize the table and there are only null pointers there
|
||||||
|
consequently if all pointers are null there is no sens
|
||||||
|
to send WINIX_PLUGIN_SESSION_DATA_REMOVE
|
||||||
|
*/
|
||||||
|
|
||||||
for(size_t i=0 ; i<table.size() ; ++i)
|
for(size_t i=0 ; i<table.size() ; ++i)
|
||||||
table[i] = 0;
|
{
|
||||||
|
if( table[i] != 0 )
|
||||||
|
{
|
||||||
|
all_null = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
in the future this message may be removed
|
||||||
|
and we directly 'delete' the pointers
|
||||||
|
*/
|
||||||
|
|
||||||
|
if( !all_null )
|
||||||
|
plugin.Call(session, WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
||||||
|
|
||||||
|
table.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::PluginData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::PluginData(const PluginData & p)
|
|
||||||
{
|
|
||||||
operator=(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData & PluginData::operator=(const PluginData & p)
|
|
||||||
{
|
|
||||||
// we don't copy all pointers - only resize the table
|
|
||||||
// pointers will be set to zero
|
|
||||||
Resize(p.Size());
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::~PluginData()
|
|
||||||
{
|
|
||||||
DeleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t PluginData::Size() const
|
size_t PluginData::Size() const
|
||||||
@@ -123,3 +182,8 @@ size_t old_size = table.size();
|
|||||||
for(size_t i = old_size ; i<new_size ; ++i)
|
for(size_t i = old_size ; i<new_size ; ++i)
|
||||||
table[i] = 0;
|
table[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+54
-8
@@ -1,24 +1,64 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_plugindata
|
||||||
#define headerfile_winix_core_plugindata
|
#define headerfile_winix_core_plugindata
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct Session;
|
||||||
|
|
||||||
|
|
||||||
struct PluginDataBase
|
struct PluginDataBase
|
||||||
{
|
{
|
||||||
virtual ~PluginDataBase() {}
|
virtual ~PluginDataBase() {}
|
||||||
|
|
||||||
|
/*
|
||||||
|
!! CHECK ME
|
||||||
|
it is still in use?
|
||||||
|
|
||||||
|
when deleting sessions we first call Clear() method
|
||||||
|
consequently the destructor has nothing to do
|
||||||
|
(and it does not throw an exception)
|
||||||
|
*/
|
||||||
|
virtual void Clear() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -28,6 +68,13 @@ class PluginData
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
PluginData();
|
||||||
|
PluginData(const PluginData & p);
|
||||||
|
PluginData & operator=(const PluginData & p);
|
||||||
|
~PluginData();
|
||||||
|
|
||||||
|
void SetSession(Session * ses);
|
||||||
|
|
||||||
void Assign(size_t index, PluginDataBase * data);
|
void Assign(size_t index, PluginDataBase * data);
|
||||||
void Assign(PluginDataBase * data);
|
void Assign(PluginDataBase * data);
|
||||||
|
|
||||||
@@ -36,21 +83,20 @@ public:
|
|||||||
|
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
|
|
||||||
PluginData();
|
|
||||||
PluginData(const PluginData & p);
|
|
||||||
PluginData & operator=(const PluginData & p);
|
|
||||||
~PluginData();
|
|
||||||
|
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
void Resize(size_t new_size);
|
void Resize(size_t new_size);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Session * session;
|
||||||
std::vector<PluginDataBase*> table;
|
std::vector<PluginDataBase*> table;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+253
-31
@@ -1,18 +1,51 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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_pluginmsg
|
#ifndef headerfile_winix_core_pluginmsg
|
||||||
#define headerfile_winix_core_pluginmsg
|
#define headerfile_winix_core_pluginmsg
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// here you can add your own EZC functions ([function])
|
// here you can add your own EZC functions ([function])
|
||||||
// PluginInfo.p1 is a pointer to Ezc::Functions object
|
// PluginInfo.p1 is a pointer to Ezc::Functions object
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
|
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
|
||||||
|
|
||||||
// here you can add your own EZC functions to notify system
|
// here you can add your own EZC functions to notify system
|
||||||
@@ -24,79 +57,264 @@
|
|||||||
// Ezc::Functions<NotifyStream> ezc_functions;
|
// Ezc::Functions<NotifyStream> ezc_functions;
|
||||||
// and Notify Stream is:
|
// and Notify Stream is:
|
||||||
// typedef TextStream<std::wstring> NotifyStream;
|
// typedef TextStream<std::wstring> NotifyStream;
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS 998
|
#define WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS 998
|
||||||
|
|
||||||
// winix function and parameters have been parsed
|
// winix function and parameters have been parsed
|
||||||
// the request.status is OK
|
// the request.status is OK
|
||||||
// (the winix function was not called yet)
|
// (the winix function was not called yet)
|
||||||
#define WINIX_PREPARE_REQUEST 2000
|
#define WINIX_PREPARE_REQUEST 20000
|
||||||
|
|
||||||
// post and get functions have done their jobs
|
// post and get functions have done their jobs
|
||||||
// now you can act
|
// now you can act
|
||||||
// this is called only if the request.status is OK
|
// this is called only if the request.status is OK
|
||||||
#define WINIX_PROCESS_REQUEST 2001
|
#define WINIX_PROCESS_REQUEST 20010
|
||||||
|
|
||||||
// prepere your content for displaying
|
// prepere your content for displaying
|
||||||
// this is called after WINIX_PROCESS_REQUEST
|
// this is called after WINIX_PROCESS_REQUEST
|
||||||
// and when there is not a redirect
|
// and when there is not a redirect
|
||||||
// request.status is not checked here
|
// request.status is not checked here
|
||||||
#define WINIX_CONTENT_MAKE 2002
|
#define WINIX_CONTENT_MAKE 20020
|
||||||
|
|
||||||
// here you can attach your own session data (based on PluginDataBase class)
|
// here you can attach your own session data (based on PluginDataBase class)
|
||||||
// call request.session->plugin_data.Assign(pointer)
|
// call cur->session->plugin_data.Assign(pointer)
|
||||||
#define WINIX_SESSION_CREATED 3000
|
#define WINIX_SESSION_CREATED 30000
|
||||||
|
|
||||||
// here you should remove your session data
|
// here you should remove your session data
|
||||||
#define WINIX_SESSION_REMOVE 3001
|
// this message can be sent even if you don't assing your plugin data
|
||||||
|
#define WINIX_PLUGIN_SESSION_DATA_REMOVE 30010
|
||||||
|
|
||||||
// when a session is changed (you can save a pointer to your data here)
|
// when a session is changed (you can save a pointer to your data here)
|
||||||
#define WINIX_SESSION_CHANGED 3002
|
// 'session changed' means that there is a new request
|
||||||
|
// !! IMPROVE ME it has to be changed to a better name
|
||||||
|
#define WINIX_SESSION_CHANGED 30020
|
||||||
|
|
||||||
|
// a session has changed its id
|
||||||
|
// it is typically when you are logging in
|
||||||
|
// 'login' winix function will change the session id (for security reasons)
|
||||||
|
// in l1 you have the old id, in l2 you have the new id
|
||||||
|
#define WINIX_SESSION_CHANGED_ID 30025
|
||||||
|
|
||||||
|
// a session is going to be removed
|
||||||
|
// it is called from session manager's thread (with lock/unlock)
|
||||||
|
#define WINIX_PREPARE_SESSION_TO_REMOVE 30027
|
||||||
|
|
||||||
|
// a session has been removed
|
||||||
|
// it is called from session manager's thread (with lock/unlock)
|
||||||
|
// in l1 you have the old session id
|
||||||
|
#define WINIX_SESSION_REMOVED 30029
|
||||||
|
|
||||||
// the winix is closing
|
// the winix is closing
|
||||||
// the is not any session available (cur->session is null)
|
// there is not any sessions available (cur->session is null)
|
||||||
#define WINIX_CLOSE 3004
|
// session pointer is null
|
||||||
|
#define WINIX_CLOSE 30040
|
||||||
|
|
||||||
|
// preparing to remove a file (rm function)
|
||||||
|
// in p1 you have a pointer to the Item struct (file)
|
||||||
|
// valid members are:
|
||||||
|
// id, parent_id, type, url, file_path, file_fs, file_type, has_thumb, hash, hash_type, file_size
|
||||||
|
// user_id, group_id, privileges
|
||||||
|
// (sometimes rest members can be valid as well -- when you call directly fun_rm->RemoveFileOrSymlink() method)
|
||||||
|
#define WINIX_FILE_PREPARE_TO_REMOVE 30045
|
||||||
|
|
||||||
// a file or symlink was removed (rm function)
|
// a file or symlink was removed (rm function)
|
||||||
// PluginInfo::l1 is the file (item) id
|
// in p1 you have a pointer to the Item struct (old file)
|
||||||
// !! moze zmienic nazwe i dodac symlink w nazwie?
|
// valid members are the same as in WINIX_FILE_PREPARE_TO_REMOVE
|
||||||
#define WINIX_FILE_REMOVED 3005
|
#define WINIX_FILE_REMOVED 30050
|
||||||
|
|
||||||
// directory was removed (rm function)
|
|
||||||
// PluginInfo::l1 is the dir id
|
|
||||||
#define WINIX_DIR_REMOVED 3006
|
|
||||||
|
|
||||||
// preparing to remove a directory (rm function)
|
// preparing to remove a directory (rm function)
|
||||||
// PluginInfo::l1 is the dir id
|
// in p1 you have a pointer to the Item struct (directory)
|
||||||
#define WINIX_DIR_PREPARE_TO_REMOVE 3007
|
// this message is sent after checking the directory permissions
|
||||||
|
// so consequently if there is no any database error then the
|
||||||
|
// directory will be removed
|
||||||
|
// and after removed WINIX_DIR_REMOVED message is sent
|
||||||
|
#define WINIX_DIR_PREPARE_TO_REMOVE 30070
|
||||||
|
|
||||||
|
// directory was removed (rm function)
|
||||||
|
// PluginInfo::l1 is the directory id
|
||||||
|
#define WINIX_DIR_REMOVED 30060
|
||||||
|
|
||||||
// winix is initialized,
|
// winix is initialized,
|
||||||
// now you can initialize your plugin
|
// now you can initialize your plugin
|
||||||
#define WINIX_PLUGIN_INIT 3008
|
// session pointer is null
|
||||||
|
#define WINIX_PLUGIN_INIT 30080
|
||||||
|
|
||||||
// here you can add your own mount point, file systems, mount parameters
|
// here you can add your own mount point, file systems, mount parameters
|
||||||
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
|
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
|
||||||
#define WINIX_ADD_MOUNTS 3009
|
// session pointer is null
|
||||||
|
#define WINIX_ADD_MOUNTS 30090
|
||||||
|
|
||||||
// add plugin functions here
|
// add plugin functions (winix functions) here
|
||||||
#define WINIX_CREATE_FUNCTIONS 3010
|
// call info.functions->Add() to add a function
|
||||||
|
// session pointer is null
|
||||||
|
#define WINIX_CREATE_FUNCTIONS 30100
|
||||||
|
|
||||||
// choose a default function
|
// choose a default function
|
||||||
// if you do not select it then it will be choosen by winix
|
// if you do not select it then it will be choosen by winix
|
||||||
#define WINIX_SELECT_DEFAULT_FUNCTION 3011
|
#define WINIX_SELECT_DEFAULT_FUNCTION 30110
|
||||||
|
|
||||||
// /etc/fstab has been changed
|
// /etc/fstab has been changed
|
||||||
// now we have new mount points
|
// now we have new mount points
|
||||||
#define WINIX_FSTAB_CHANGED 3012
|
// session pointer is null
|
||||||
|
#define WINIX_FSTAB_CHANGED 30120
|
||||||
|
|
||||||
// here you add your own template to notification system
|
// here you add your own template to notification system
|
||||||
// call system->notify.AddTemplate() method
|
// call system->notify.AddTemplate() method
|
||||||
// with a template file name
|
// with a template file name
|
||||||
#define WINIX_NOTIFY_ADD_TEMPLATE 3013
|
// session pointer is null
|
||||||
|
#define WINIX_NOTIFY_ADD_TEMPLATE 30130
|
||||||
|
|
||||||
|
// the request is being ended
|
||||||
|
// you can clear some of your objects here
|
||||||
|
#define WINIX_END_REQUEST 30140
|
||||||
|
|
||||||
|
// a new file (page) has been added
|
||||||
|
// in p1 you have a pointer to the Item struct
|
||||||
|
#define WINIX_FILE_ADDED 30150
|
||||||
|
|
||||||
|
// a file (page) has been changed (edited)
|
||||||
|
// in p1 you have a pointer to the Item struct
|
||||||
|
#define WINIX_FILE_CHANGED 30160
|
||||||
|
|
||||||
|
// a new directory has been added
|
||||||
|
// in p1 you have a pointer to the Item struct
|
||||||
|
#define WINIX_DIR_ADDED 30155
|
||||||
|
|
||||||
|
// a file (page) has been copied
|
||||||
|
// in p1 you have a pointer to the Item struct
|
||||||
|
// not every fields of Item struct are filled
|
||||||
|
#define WINIX_FILE_COPIED 30170
|
||||||
|
|
||||||
|
// a file will be moved
|
||||||
|
// in p1 you have a pointer to the Item struct
|
||||||
|
// valid members are:
|
||||||
|
// id, parent_id, type, url, file_path, file_fs, file_type, has_thumb, hash, hash_type, file_size
|
||||||
|
// user_id, group_id, privileges, meta
|
||||||
|
// (sometimes rest members can be valid as well -- when you call directly fun_rm->RemoveFileOrSymlink() method)
|
||||||
|
#define WINIX_FILE_PREPARE_TO_MOVE 30180
|
||||||
|
|
||||||
|
// a file has been moved
|
||||||
|
// in p1 you have a pointer to the Item struct (new file)
|
||||||
|
// valid members are the same as in WINIX_FILE_PREPARE_TO_MOVE
|
||||||
|
#define WINIX_FILE_MOVED 30190
|
||||||
|
|
||||||
|
// a thumbnail was created
|
||||||
|
// this message is called from another thread
|
||||||
|
// the thread called Lock() before sending this message
|
||||||
|
// in p1 you have a pointer to the Item struct
|
||||||
|
// session pointer is null
|
||||||
|
#define WINIX_CREATED_THUMB 30500
|
||||||
|
|
||||||
|
// an image has been resized
|
||||||
|
// this message is called from another thread
|
||||||
|
// the thread called Lock() before sending this message
|
||||||
|
// in p1 you have a pointer to the Item struct
|
||||||
|
// session pointer is null
|
||||||
|
#define WINIX_IMAGE_RESIZED 30520
|
||||||
|
|
||||||
|
// content of a directory was sorted
|
||||||
|
// (winix 'sort' function was used)
|
||||||
|
// in p1 you have a pointer to the Item struct (of the directory)
|
||||||
|
// this is from system->dirs so you should not change the item
|
||||||
|
#define WINIX_DIR_CONTENT_SORTED 30500
|
||||||
|
|
||||||
|
// a user will be logged in
|
||||||
|
// set PluginInfo::res to false (it is by default) to prevent logging the user
|
||||||
|
// directly after this message (if you do not return false)
|
||||||
|
// a WINIX_USER_LOGGED is sent
|
||||||
|
// in p1 you have a pointer to User struct
|
||||||
|
// (if at least one plugin returns false then the user will not be logged)
|
||||||
|
// this message is not sent when winix starts and sessions are read from a sessions file
|
||||||
|
// in such a case only WINIX_USER_LOGGED will be sent
|
||||||
|
#define WINIX_PREPARE_USER_TO_LOGIN 30550
|
||||||
|
|
||||||
|
// a user has been logged
|
||||||
|
// send from 'login' winix function
|
||||||
|
// this message is also called when winix starts and reads sessions
|
||||||
|
// from the session file
|
||||||
|
#define WINIX_USER_LOGGED 30600
|
||||||
|
|
||||||
|
// a user is going to logout
|
||||||
|
// in p1 you have a pointer to User struct
|
||||||
|
// the message is also sent from the session GC (special thread for deleting sessions)
|
||||||
|
// in such a case is sent with Lock() and Unlock()
|
||||||
|
// so *don't* use Lock() in your procedure
|
||||||
|
#define WINIX_PREPARE_USER_TO_LOGOUT 30610
|
||||||
|
|
||||||
|
// here you add your own html templates
|
||||||
|
// call TemplatesFunctions::patterns.Add(L"file_name.html")
|
||||||
|
// the method returns an index which you have to remember
|
||||||
|
// and you can get the template with patterns.Get(index, lang_index)
|
||||||
|
// it returns a pointer to Ezc::Pattern (or null pointer if the index is wrong)
|
||||||
|
// the message will be sent too whenever 'reload/templates' winix function is called
|
||||||
|
// templates you should add only in this message
|
||||||
|
// in other cases after 'reload' function the indexes would be wrong
|
||||||
|
// session pointer is null
|
||||||
|
#define WINIX_ADD_TEMPLATE 31000
|
||||||
|
|
||||||
|
// a user will be removed
|
||||||
|
// in p1 you have a pointer to the User struct
|
||||||
|
// directly after this message a WINIX_USER_REMOVED will be sent
|
||||||
|
#define WINIX_PREPARE_TO_REMOVE_USER 31010
|
||||||
|
|
||||||
|
// a user has been removed
|
||||||
|
// in l1 you have the old user_id
|
||||||
|
#define WINIX_USER_REMOVED 31020
|
||||||
|
|
||||||
|
// here you can check if the domain part of the URL address is correct
|
||||||
|
// if no then set cur-request->redirect_to
|
||||||
|
// and winix will do a 'base url redirect' without making any winix functions
|
||||||
|
// the session pointer in info is null
|
||||||
|
#define WINIX_BASE_URL_REDIRECT 31030
|
||||||
|
|
||||||
|
// raw POST parameters
|
||||||
|
// 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)
|
||||||
|
// this message is sent for each name value pairs
|
||||||
|
//
|
||||||
|
#define WINIX_POST_PARAMS 31040
|
||||||
|
|
||||||
|
// this is the raw string sent in POST method
|
||||||
|
// in p1 there is a pointer to std::string object
|
||||||
|
#define WINIX_RAW_POST_STRING 31050
|
||||||
|
|
||||||
|
// this message is sent before calling MakePost() or MakeGet()
|
||||||
|
// if you return false (which is default) you can prevent the access
|
||||||
|
// to the resource
|
||||||
|
#define WINIX_CHECK_PLUGIN_ACCESS 31060
|
||||||
|
|
||||||
|
// http headers (without cookies) were created and are ready to send
|
||||||
|
// here you can make some changes to them
|
||||||
|
// in p1 you have a pointer to the PT::Space (Request::out_headers)
|
||||||
|
#define WINIX_PREPARE_TO_SEND_HTTP_HEADERS 31070
|
||||||
|
|
||||||
|
// http cookies were created and are ready to send
|
||||||
|
// here you can make some changes to them
|
||||||
|
// in p1 you have a pointer to the PT::Space (Request::out_cookies)
|
||||||
|
#define WINIX_PREPARE_TO_SEND_HTTP_COOKIES 31080
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
messages sent from other threads
|
||||||
|
!! IMPROVE ME check if some above messages should be moved here
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// a job has to be done
|
||||||
|
// this is sent from the other thread (without locking)
|
||||||
|
// in p1 you have a pointer to PT::Space
|
||||||
|
// session is null
|
||||||
|
// if you process the job then return 'true' from the processing method (from plugin call)
|
||||||
|
// so this prevent to make a standard (system) job
|
||||||
|
#define WINIX_JOB 31200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// the request is ended
|
|
||||||
// you can clear some of your object here
|
|
||||||
#define WINIX_END_REQUEST 3014
|
|
||||||
|
|
||||||
// values from 4000 - 4099 reserved for 'thread' plugin
|
// values from 4000 - 4099 reserved for 'thread' plugin
|
||||||
// see plugins/thread/pluginmsg.h
|
// see plugins/thread/pluginmsg.h
|
||||||
@@ -105,5 +323,9 @@
|
|||||||
// see plugins/ticket/pluginmsg.h
|
// see plugins/ticket/pluginmsg.h
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+62
-39
@@ -1,16 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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 <unistd.h>
|
||||||
#include "postmultiparser.h"
|
#include "postmultiparser.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "utf8.h"
|
#include "utf8/utf8.h"
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PostMultiParser::PostMultiParser()
|
PostMultiParser::PostMultiParser()
|
||||||
@@ -353,6 +386,12 @@ void PostMultiParser::ReadContent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PostMultiParser::ConvStr(const std::string & src, std::wstring & dst)
|
||||||
|
{
|
||||||
|
PT::UTF8ToWide(src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PostMultiParser::AddNormalPostVar()
|
void PostMultiParser::AddNormalPostVar()
|
||||||
{
|
{
|
||||||
if( post_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
|
if( post_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
|
||||||
@@ -362,20 +401,10 @@ void PostMultiParser::AddNormalPostVar()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConvStr(name, namew);
|
||||||
|
ConvStr(content, contentw);
|
||||||
|
|
||||||
if( config->utf8 )
|
bool added = InsertPostVar(*post_tab, namew, contentw);
|
||||||
{
|
|
||||||
Ezc::UTF8ToWide(name, namew);
|
|
||||||
Ezc::UTF8ToWide(content, contentw);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AssignString(name, namew);
|
|
||||||
AssignString(content, contentw);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<PostTab::iterator, bool> res = post_tab->insert( std::make_pair(namew, contentw) );
|
|
||||||
bool added = res.second;
|
|
||||||
|
|
||||||
log << log2 << "PMP: POST var, name: \"" << namew << "\"";
|
log << log2 << "PMP: POST var, name: \"" << namew << "\"";
|
||||||
|
|
||||||
@@ -395,20 +424,12 @@ void PostMultiParser::AddFilePostVar()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( config->utf8 )
|
ConvStr(name, namew);
|
||||||
{
|
ConvStr(filename, post_file_temp.filename);
|
||||||
Ezc::UTF8ToWide(name, namew);
|
|
||||||
Ezc::UTF8ToWide(filename, post_file_temp.filename);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AssignString(name, namew);
|
|
||||||
AssignString(filename, post_file_temp.filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
post_file_temp.tmp_filename = tmp_filename;
|
post_file_temp.tmp_filename = tmp_filename;
|
||||||
std::pair<PostFileTab::iterator, bool> res = post_file_tab->insert( std::make_pair(namew, post_file_temp) );
|
post_file_temp.file_size = content_len;
|
||||||
bool added = res.second;
|
|
||||||
|
bool added = InsertPostVar(*post_file_tab, namew, post_file_temp);
|
||||||
|
|
||||||
log << log2 << "PMP: POST FILE var, name: \"" << namew << "\"";
|
log << log2 << "PMP: POST FILE var, name: \"" << namew << "\"";
|
||||||
|
|
||||||
@@ -424,15 +445,10 @@ void PostMultiParser::AddPostVar()
|
|||||||
if( name.empty() )
|
if( name.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
if( filename.empty() )
|
if( filename.empty() )
|
||||||
{
|
|
||||||
AddNormalPostVar();
|
AddNormalPostVar();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
AddFilePostVar();
|
AddFilePostVar();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -465,7 +481,7 @@ void PostMultiParser::CheckBoundaryEnd()
|
|||||||
|
|
||||||
void PostMultiParser::CreateTmpFile()
|
void PostMultiParser::CreateTmpFile()
|
||||||
{
|
{
|
||||||
wchar_t buf[1024];
|
wchar_t buf[WINIX_OS_PATH_SIZE];
|
||||||
size_t buf_len = sizeof(buf)/sizeof(wchar_t);
|
size_t buf_len = sizeof(buf)/sizeof(wchar_t);
|
||||||
|
|
||||||
if( config->upload_dir.empty() )
|
if( config->upload_dir.empty() )
|
||||||
@@ -479,10 +495,10 @@ size_t buf_len = sizeof(buf)/sizeof(wchar_t);
|
|||||||
tmp_filename_postfix += 1;
|
tmp_filename_postfix += 1;
|
||||||
|
|
||||||
tmp_filename = buf;
|
tmp_filename = buf;
|
||||||
Ezc::WideToUTF8(tmp_filename, atmp_filename);
|
PT::WideToUTF8(tmp_filename, atmp_filename);
|
||||||
|
|
||||||
tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
|
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 )
|
if( !tmp_file )
|
||||||
{
|
{
|
||||||
@@ -569,6 +585,7 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab
|
|||||||
in = in_;
|
in = in_;
|
||||||
last = 0;
|
last = 0;
|
||||||
err = WINIX_ERR_OK;
|
err = WINIX_ERR_OK;
|
||||||
|
var_index = 1;
|
||||||
line_end_dos = false;
|
line_end_dos = false;
|
||||||
in_buffer_ind = WINIX_POSTMULTI_INPUT_BUFFER;
|
in_buffer_ind = WINIX_POSTMULTI_INPUT_BUFFER;
|
||||||
in_buffer_len = WINIX_POSTMULTI_INPUT_BUFFER;
|
in_buffer_len = WINIX_POSTMULTI_INPUT_BUFFER;
|
||||||
@@ -587,6 +604,7 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab
|
|||||||
|
|
||||||
if( err != WINIX_ERR_OK )
|
if( err != WINIX_ERR_OK )
|
||||||
{
|
{
|
||||||
|
RemovePostFileTmp(*post_file_tab);
|
||||||
post_tab->clear();
|
post_tab->clear();
|
||||||
post_file_tab->clear();
|
post_file_tab->clear();
|
||||||
|
|
||||||
@@ -596,3 +614,8 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+68
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_postmultiparser
|
||||||
@@ -16,6 +41,12 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "requesttypes.h"
|
#include "requesttypes.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 2 MB
|
// 2 MB
|
||||||
@@ -53,6 +84,7 @@ private:
|
|||||||
PostFileTab * post_file_tab;
|
PostFileTab * post_file_tab;
|
||||||
|
|
||||||
int last; // last read character
|
int last; // last read character
|
||||||
|
int var_index; // used as a postfix to the same name (is auto increment)
|
||||||
|
|
||||||
bool line_end_dos;
|
bool line_end_dos;
|
||||||
std::string boundary;
|
std::string boundary;
|
||||||
@@ -67,6 +99,7 @@ private:
|
|||||||
PostFile post_file_temp;
|
PostFile post_file_temp;
|
||||||
|
|
||||||
void LogFirst(const std::string & to_log, size_t len);
|
void LogFirst(const std::string & to_log, size_t len);
|
||||||
|
void ConvStr(const std::string & src, std::wstring & dst);
|
||||||
|
|
||||||
bool IsWhite(int c);
|
bool IsWhite(int c);
|
||||||
void SkipWhite();
|
void SkipWhite();
|
||||||
@@ -94,7 +127,39 @@ private:
|
|||||||
|
|
||||||
void ReadChar();
|
void ReadChar();
|
||||||
|
|
||||||
|
|
||||||
|
template<class Container, class Value>
|
||||||
|
bool InsertPostVar(Container & container, std::wstring & key, const Value & value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class Container, class Value>
|
||||||
|
bool PostMultiParser::InsertPostVar(Container & container, std::wstring & key, const Value & value)
|
||||||
|
{
|
||||||
|
bool added;
|
||||||
|
std::pair<typename Container::iterator, bool> res;
|
||||||
|
|
||||||
|
res = container.insert( std::make_pair(key, value) );
|
||||||
|
added = res.second;
|
||||||
|
|
||||||
|
if( !added )
|
||||||
|
{
|
||||||
|
key += L"_inc";
|
||||||
|
key += Toa(var_index);
|
||||||
|
res = container.insert( std::make_pair(key, value) );
|
||||||
|
added = res.second;
|
||||||
|
var_index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return added;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+83
-34
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2011, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_postparser
|
||||||
@@ -15,45 +40,54 @@
|
|||||||
#include "httpsimpleparser.h"
|
#include "httpsimpleparser.h"
|
||||||
#include "requesttypes.h"
|
#include "requesttypes.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "utf8.h"
|
#include "utf8/utf8.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "config.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PostParser : public HttpSimpleParser
|
class PostParser : public HttpSimpleParser
|
||||||
{
|
{
|
||||||
|
|
||||||
FCGX_Stream * in;
|
FCGX_Stream * in;
|
||||||
PostTab * post_tab;
|
PostTab * post_tab;
|
||||||
std::wstring temp_name, temp_value;
|
|
||||||
bool input_as_utf8;
|
|
||||||
size_t log_value_size;
|
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:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
virtual int GetChar()
|
virtual int GetChar()
|
||||||
{
|
{
|
||||||
return FCGX_GetChar(in);
|
int c = FCGX_GetChar(in);
|
||||||
|
|
||||||
|
if( c != -1 && has_winix_raw_post_msg )
|
||||||
|
raw_post += c;
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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: ";
|
log << ", value: ";
|
||||||
|
|
||||||
if( temp_value.size() > log_value_size )
|
if( value.size() > log_value_size )
|
||||||
log << "(first " << log_value_size << " characters) ";
|
log << "(first " << log_value_size << " characters) ";
|
||||||
|
|
||||||
log << "\"";
|
log << "\"";
|
||||||
log.LogString(temp_value, log_value_size);
|
log.LogString(value, log_value_size);
|
||||||
log << "\" (size: " << temp_value.size() << ")";
|
log << "\" (size: " << value.size() << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( param_added == false )
|
if( param_added == false )
|
||||||
@@ -63,21 +97,28 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void Parameter(std::string & name, std::string & value)
|
|
||||||
|
virtual void Parameter(std::wstring & name, std::wstring & value)
|
||||||
{
|
{
|
||||||
if( input_as_utf8 )
|
bool added;
|
||||||
|
std::pair<PostTab::iterator, bool> res;
|
||||||
|
|
||||||
|
if( has_winix_post_params_msg )
|
||||||
|
plugin.Call(0, WINIX_POST_PARAMS, &name, &value);
|
||||||
|
|
||||||
|
res = post_tab->insert( std::make_pair(name, value) );
|
||||||
|
added = res.second;
|
||||||
|
|
||||||
|
if( !added )
|
||||||
{
|
{
|
||||||
Ezc::UTF8ToWide(name, temp_name);
|
name += L"_inc";
|
||||||
Ezc::UTF8ToWide(value, temp_value);
|
name += Toa(var_index);
|
||||||
}
|
res = post_tab->insert( std::make_pair(name, value) );
|
||||||
else
|
added = res.second;
|
||||||
{
|
var_index += 1;
|
||||||
AssignString(name, temp_name);
|
|
||||||
AssignString(value, temp_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<PostTab::iterator, bool> res = post_tab->insert( std::make_pair(temp_name, temp_value) );
|
CreateLog(added, name, value);
|
||||||
CreateLog(res.second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -85,14 +126,8 @@ public:
|
|||||||
|
|
||||||
PostParser()
|
PostParser()
|
||||||
{
|
{
|
||||||
input_as_utf8 = false;
|
|
||||||
log_value_size = 0;
|
log_value_size = 0;
|
||||||
}
|
HttpSimpleParser::getchar_returns_utf8_chars = true;
|
||||||
|
|
||||||
|
|
||||||
void UTF8(bool utf)
|
|
||||||
{
|
|
||||||
input_as_utf8 = utf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogValueSize(size_t s)
|
void LogValueSize(size_t s)
|
||||||
@@ -104,11 +139,25 @@ public:
|
|||||||
{
|
{
|
||||||
in = in_;
|
in = in_;
|
||||||
post_tab = &post_tab_;
|
post_tab = &post_tab_;
|
||||||
|
var_index = 1;
|
||||||
|
raw_post.clear();
|
||||||
|
|
||||||
|
has_winix_post_params_msg = plugin.HasMessage(WINIX_POST_PARAMS);
|
||||||
|
has_winix_raw_post_msg = plugin.HasMessage(WINIX_RAW_POST_STRING);
|
||||||
|
|
||||||
HttpSimpleParser::Parse();
|
HttpSimpleParser::Parse();
|
||||||
|
|
||||||
|
if( has_winix_raw_post_msg )
|
||||||
|
plugin.Call(0, WINIX_RAW_POST_STRING, &raw_post);
|
||||||
|
|
||||||
|
raw_post.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+37
-9
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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 <cstdlib>
|
||||||
@@ -15,6 +40,11 @@
|
|||||||
#include "cur.h"
|
#include "cur.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Rebus::SetCur(Cur * pcur)
|
void Rebus::SetCur(Cur * pcur)
|
||||||
{
|
{
|
||||||
@@ -149,7 +179,9 @@ bool Rebus::CheckRebus()
|
|||||||
if( IsAnswerOk(cur->session->rebus_item, cur->request->PostVar(L"rebus")) )
|
if( IsAnswerOk(cur->session->rebus_item, cur->request->PostVar(L"rebus")) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
log << log1 << "Rebus: rebus has an incorrect answer" << logend;
|
log << log1 << "Rebus: rebus has an incorrect answer, expected: "
|
||||||
|
<< cur->session->rebus_item->answer << logend;
|
||||||
|
|
||||||
// don't add cur->session->spam_score when the rebus has incorrect answer
|
// don't add cur->session->spam_score when the rebus has incorrect answer
|
||||||
// a user could have made a mistake
|
// a user could have made a mistake
|
||||||
|
|
||||||
@@ -160,9 +192,5 @@ return false;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+38
-4
@@ -1,20 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_rebus
|
||||||
#define headerfile_winix_core_rebus
|
#define headerfile_winix_core_rebus
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Cur;
|
struct Cur;
|
||||||
|
|
||||||
|
|
||||||
@@ -48,4 +77,9 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+141
-72
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "request.h"
|
||||||
@@ -14,13 +39,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Request::Request() : char_empty(0)
|
|
||||||
|
Request::Request()
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
config = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -32,18 +61,23 @@ void Request::SetConfig(Config * pconfig)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Request::ClearPostFileTmp()
|
void Request::ClearOutputStreams()
|
||||||
{
|
{
|
||||||
// deleting temporary files (if exists)
|
size_t len = 16;
|
||||||
|
|
||||||
while( !post_file_tab.empty() )
|
if( config )
|
||||||
|
len = config->ezc_out_streams_size;
|
||||||
|
|
||||||
|
if( len < 1 || len > 64 )
|
||||||
|
len = 16;
|
||||||
|
|
||||||
|
out_streams.resize(len);
|
||||||
|
use_html_filter.resize(len);
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<out_streams.size() ; ++i)
|
||||||
{
|
{
|
||||||
const std::wstring & tmp_filename = post_file_tab.begin()->second.tmp_filename;
|
out_streams[i].Clear();
|
||||||
|
use_html_filter[i] = true;
|
||||||
if( RemoveFile(tmp_filename) )
|
|
||||||
log << log3 << "Request: deleted tmp file: " << tmp_filename << logend;
|
|
||||||
|
|
||||||
post_file_tab.erase(post_file_tab.begin());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,78 +88,83 @@ void Request::Clear()
|
|||||||
if( ++id == 0 )
|
if( ++id == 0 )
|
||||||
++id;
|
++id;
|
||||||
|
|
||||||
ClearPostFileTmp();
|
RemovePostFileTmp(post_file_tab);
|
||||||
|
ClearOutputStreams();
|
||||||
|
|
||||||
get_tab.clear();
|
|
||||||
post_tab.clear();
|
post_tab.clear();
|
||||||
post_file_tab.clear();
|
post_file_tab.clear();
|
||||||
cookie_tab.clear();
|
cookie_tab.clear();
|
||||||
|
|
||||||
method = none;
|
method = unknown_method;
|
||||||
role = responder;
|
|
||||||
|
|
||||||
headers.Clear();
|
out_headers.Clear();
|
||||||
page.Clear();
|
out_cookies.Clear();
|
||||||
debug.Clear();
|
|
||||||
|
|
||||||
env_request_method = &char_empty;
|
page_generated = false;
|
||||||
env_request_uri = &char_empty;
|
|
||||||
env_http_cookie = &char_empty;
|
env_request_method.clear();
|
||||||
env_remote_addr = &char_empty;
|
env_request_uri.clear();
|
||||||
env_http_host = &char_empty;
|
env_http_cookie.clear();
|
||||||
env_http_user_agent = &char_empty;
|
env_remote_addr.clear();
|
||||||
env_fcgi_role = &char_empty;
|
env_http_host.clear();
|
||||||
env_content_type = &char_empty;
|
env_http_user_agent.clear();
|
||||||
env_http_accept_encoding = &char_empty;
|
env_http_accept_encoding.clear();
|
||||||
|
env_fcgi_role.clear();
|
||||||
|
env_content_type.clear();
|
||||||
|
env_https.clear();
|
||||||
|
|
||||||
item_tab.clear();
|
item_tab.clear();
|
||||||
item.Clear();
|
item.Clear();
|
||||||
dir_tab.clear();
|
dir_tab.clear();
|
||||||
last_item = &item;
|
last_item = &item;
|
||||||
is_item = false;
|
is_item = false;
|
||||||
function = 0; // !! dodac jakas empty funkcje
|
function = 0;
|
||||||
param_tab.clear();
|
param_tab.clear();
|
||||||
|
anchor.clear();
|
||||||
|
|
||||||
status = WINIX_ERR_OK;
|
status = WINIX_ERR_OK;
|
||||||
|
|
||||||
browser_msie = false;
|
browser_msie = false;
|
||||||
redirect_to.clear();
|
redirect_to.clear();
|
||||||
|
redirect_type = 303;
|
||||||
x_sendfile.clear();
|
x_sendfile.clear();
|
||||||
send_as_attachment = false;
|
send_as_attachment = false;
|
||||||
|
|
||||||
|
using_ssl = false;
|
||||||
|
|
||||||
|
start_time = 0;
|
||||||
|
start_date.Clear();
|
||||||
|
|
||||||
|
subdomain.clear();
|
||||||
|
return_info_only = false;
|
||||||
|
info.Clear();
|
||||||
|
info_serializer = 0;
|
||||||
|
return_json = false;
|
||||||
|
|
||||||
|
out_bin_stream.clear();
|
||||||
|
send_bin_stream = false;
|
||||||
|
|
||||||
|
gen_trim_white = false;
|
||||||
|
gen_skip_new_line = false;
|
||||||
|
gen_use_special_chars = false;
|
||||||
|
|
||||||
|
ip = 0;
|
||||||
|
use_200_status_for_not_found_and_permission_denied = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Request::RequestStarts()
|
||||||
// value can be null
|
|
||||||
void Request::SetCookie(const char * name, const char * value, tm * expires)
|
|
||||||
{
|
{
|
||||||
headers << "Set-Cookie: " << name << "=";
|
// clearing it is better to use at the end of a request
|
||||||
|
// so starting is much faster
|
||||||
|
|
||||||
if( value && value[0]!=0 )
|
start_time = std::time(0);
|
||||||
headers << value;
|
start_date = start_time;
|
||||||
else
|
|
||||||
headers << "\"\"";
|
|
||||||
|
|
||||||
if( expires )
|
|
||||||
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
|
||||||
|
|
||||||
headers << "; path=/; domain=." << config->base_server << "\r\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Request::SetCookie(const char * name, long value, tm * expires)
|
|
||||||
{
|
|
||||||
headers << "Set-Cookie: " << name << "=" << value;
|
|
||||||
|
|
||||||
if( expires )
|
|
||||||
headers << "; expires=" << DateToStrCookie(expires) << " GMT";
|
|
||||||
|
|
||||||
headers << "; path=/; domain=." << config->base_server << "\r\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::IsPostVar(const wchar_t * var)
|
bool Request::IsPostVar(const wchar_t * var)
|
||||||
{
|
{
|
||||||
@@ -140,6 +179,18 @@ return true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Request::IsPostVar(const std::wstring & var)
|
||||||
|
{
|
||||||
|
PostTab::iterator p;
|
||||||
|
|
||||||
|
p = post_tab.find(var);
|
||||||
|
|
||||||
|
if( p == post_tab.end() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & Request::PostVar(const wchar_t * var)
|
const std::wstring & Request::PostVar(const wchar_t * var)
|
||||||
{
|
{
|
||||||
@@ -152,6 +203,17 @@ return p->second;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const std::wstring & Request::PostVar(const std::wstring & var)
|
||||||
|
{
|
||||||
|
PostTab::iterator p = post_tab.find(var);
|
||||||
|
|
||||||
|
if( p == post_tab.end() )
|
||||||
|
return str_empty;
|
||||||
|
|
||||||
|
return p->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::PostVar(const wchar_t * var, std::wstring & result)
|
bool Request::PostVar(const wchar_t * var, std::wstring & result)
|
||||||
{
|
{
|
||||||
@@ -169,6 +231,23 @@ return true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Request::PostVar(const std::wstring & var, std::wstring & result)
|
||||||
|
{
|
||||||
|
PostTab::iterator p = post_tab.find(var);
|
||||||
|
|
||||||
|
if( p == post_tab.end() )
|
||||||
|
{
|
||||||
|
result.clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = p->second;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring * Request::PostVarp(const wchar_t * var)
|
std::wstring * Request::PostVarp(const wchar_t * var)
|
||||||
{
|
{
|
||||||
PostTab::iterator p = post_tab.find(var);
|
PostTab::iterator p = post_tab.find(var);
|
||||||
@@ -180,30 +259,17 @@ return &p->second;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::wstring * Request::PostVarp(const std::wstring & var)
|
||||||
void Request::PrintGetTab()
|
|
||||||
{
|
{
|
||||||
debug << "get_tab: " << get_tab.size() << "\n";
|
PostTab::iterator p = post_tab.find(var);
|
||||||
|
|
||||||
for(GetTab::iterator i = get_tab.begin() ; i != get_tab.end() ; ++i)
|
if( p == post_tab.end() )
|
||||||
debug << " \"" << *i << "\"\n";
|
return 0;
|
||||||
|
|
||||||
debug << '\n';
|
return &p->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void Request::PrintEnv()
|
|
||||||
{
|
|
||||||
char ** e;
|
|
||||||
|
|
||||||
debug << "environment variables:\n";
|
|
||||||
|
|
||||||
for( e = env ; *e ; ++e )
|
|
||||||
debug << ' ' << *e << "\n";
|
|
||||||
|
|
||||||
debug << '\n';
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::AllPostVarEmpty()
|
bool Request::AllPostVarEmpty()
|
||||||
@@ -269,4 +335,7 @@ const std::wstring & Request::ParamValue(const std::wstring & param_name)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+334
-60
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_request
|
||||||
@@ -19,6 +44,16 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "textstream.h"
|
#include "textstream.h"
|
||||||
#include "templates/htmltextstream.h"
|
#include "templates/htmltextstream.h"
|
||||||
|
#include "date/date.h"
|
||||||
|
#include "space/space.h"
|
||||||
|
#include "space/spacetojson.h"
|
||||||
|
#include "textstream/textstream.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FunctionBase;
|
class FunctionBase;
|
||||||
@@ -28,39 +63,80 @@ class FunctionBase;
|
|||||||
|
|
||||||
struct Request
|
struct Request
|
||||||
{
|
{
|
||||||
// request id
|
/*
|
||||||
// is incremented for each request and is never 0
|
request id
|
||||||
// (from -1 will be incremented twice)
|
is incremented for each request and is never 0
|
||||||
// it's used for some optimalizations e.g. in templates
|
(from -1 will be incremented to one)
|
||||||
|
it's used for some optimizations e.g. in templates
|
||||||
|
*/
|
||||||
size_t id;
|
size_t id;
|
||||||
|
|
||||||
// !! moze pozbyc sie tego none?
|
|
||||||
enum Method { get, post, head, none } method;
|
|
||||||
enum Role { responder, authorizer } role;
|
|
||||||
|
|
||||||
// headers, page and debug
|
/*
|
||||||
//std::ostringstream headers, page, debug;
|
request start time
|
||||||
TextStream<std::string> headers;
|
Time() methods are very slow so it is better to directly use those two values
|
||||||
HtmlTextStream page, debug;
|
they are set when a request starts
|
||||||
|
*/
|
||||||
|
time_t start_time;
|
||||||
|
PT::Date start_date;
|
||||||
|
|
||||||
// raw parameters
|
|
||||||
GetTab get_tab;
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* variables representing input from client's browser
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
the HTTP method
|
||||||
|
!! IMPROVE ME add the rest methods here
|
||||||
|
*/
|
||||||
|
enum Method { get, post, head, unknown_method } method;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
subdomain
|
||||||
|
subdomain = HTTP_HOST environment variable - config->base_url
|
||||||
|
*/
|
||||||
|
std::wstring subdomain;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
raw parameters
|
||||||
|
!! CHECK ME may post_tab and cookie_tab should be changed to PT::Space now?
|
||||||
|
or may change the name to cookie_in? or in_cookie?
|
||||||
|
*/
|
||||||
PostTab post_tab;
|
PostTab post_tab;
|
||||||
PostFileTab post_file_tab;
|
PostFileTab post_file_tab;
|
||||||
CookieTab cookie_tab;
|
CookieTab cookie_tab;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
html anchor (those part of URI after '#' character)
|
||||||
|
*/
|
||||||
|
std::wstring anchor;
|
||||||
|
|
||||||
|
|
||||||
// environment variables
|
// environment variables
|
||||||
// they are not null -- when the server doesn't have such a variable
|
std::wstring env_request_method;
|
||||||
// it will be pointing into 'char_empty' which is default '\0'
|
std::wstring env_request_uri;
|
||||||
const char * env_request_method;
|
std::wstring env_http_cookie;
|
||||||
const char * env_request_uri;
|
std::wstring env_remote_addr;
|
||||||
const char * env_http_cookie;
|
std::wstring env_http_host;
|
||||||
const char * env_remote_addr;
|
std::wstring env_http_user_agent;
|
||||||
const char * env_http_host;
|
std::wstring env_http_accept_encoding;
|
||||||
const char * env_http_user_agent;
|
std::wstring env_fcgi_role;
|
||||||
const char * env_http_accept_encoding;
|
std::wstring env_content_type;
|
||||||
const char * env_fcgi_role;
|
std::wstring env_https;
|
||||||
const char * env_content_type;
|
|
||||||
|
// current IP address of the remote host (read from REMOTE_ADDR environment variable)
|
||||||
|
// (at the moment only IPv4 are supported)
|
||||||
|
int ip;
|
||||||
|
|
||||||
// true if the browser is Microsoft Internet Explorer
|
// true if the browser is Microsoft Internet Explorer
|
||||||
bool browser_msie;
|
bool browser_msie;
|
||||||
@@ -68,13 +144,21 @@ struct Request
|
|||||||
// true if the browser is Konqueror
|
// true if the browser is Konqueror
|
||||||
bool browser_konqueror;
|
bool browser_konqueror;
|
||||||
|
|
||||||
|
// true if we are using an encrypted connection (SSL)
|
||||||
|
bool using_ssl;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
request input variables representing the winix filesystem
|
||||||
|
*/
|
||||||
|
|
||||||
// current directory
|
// current directory
|
||||||
std::vector<Item*> dir_tab;
|
std::vector<Item*> dir_tab;
|
||||||
|
|
||||||
// true if a file exists
|
// true if a file exists
|
||||||
bool is_item;
|
bool is_item;
|
||||||
|
|
||||||
// current file (if exists)
|
// current file (valid if is_item is true)
|
||||||
Item item;
|
Item item;
|
||||||
|
|
||||||
// current winix function
|
// current winix function
|
||||||
@@ -84,71 +168,261 @@ struct Request
|
|||||||
// parameters (name:value)
|
// parameters (name:value)
|
||||||
ParamTab param_tab;
|
ParamTab param_tab;
|
||||||
|
|
||||||
// request status
|
|
||||||
Error status;
|
|
||||||
|
|
||||||
// usually items in the current directory (depends on the function)
|
|
||||||
std::vector<Item> item_tab;
|
|
||||||
|
|
||||||
// if not empty means an address for redirecting to
|
|
||||||
std::wstring redirect_to;
|
|
||||||
std::string aredirect_to;
|
|
||||||
|
|
||||||
// send header X-LIGHTTPD-send-file with path to a file
|
|
||||||
std::wstring x_sendfile;
|
|
||||||
|
|
||||||
// send as attachment (causing header: content-disposition: attachment)
|
|
||||||
bool send_as_attachment;
|
|
||||||
|
|
||||||
// this is a pointer either to the item (if exists) or to the last directory
|
// this is a pointer either to the item (if exists) or to the last directory
|
||||||
Item * last_item;
|
Item * last_item;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* variables for generating output to the client's browser
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// request status
|
||||||
|
// !! CHANGE ME it'll be better to use ordinary http result codes
|
||||||
|
Error status;
|
||||||
|
|
||||||
|
// if not empty means an address for redirecting to
|
||||||
|
// it should be url-encoded
|
||||||
|
std::wstring redirect_to;
|
||||||
|
|
||||||
|
// a redirect type
|
||||||
|
// following redirect types are supported:
|
||||||
|
// 300 Multiple Choices
|
||||||
|
// 301 Moved Permanently
|
||||||
|
// 302 Found
|
||||||
|
// 303 See Other (default)
|
||||||
|
// 307 Temporary Redirect
|
||||||
|
int redirect_type;
|
||||||
|
|
||||||
|
// send header X-LIGHTTPD-send-file with path to a file
|
||||||
|
std::wstring x_sendfile;
|
||||||
|
|
||||||
|
// send as attachment (causes generating header: content-disposition: attachment)
|
||||||
|
bool send_as_attachment;
|
||||||
|
|
||||||
|
// headers send to the client (without cookies)
|
||||||
|
PT::Space out_headers;
|
||||||
|
|
||||||
|
// cookies send to the client
|
||||||
|
// a value can be either a cookie value or the whole cookie string (with domain, date etc)
|
||||||
|
PT::Space out_cookies;
|
||||||
|
|
||||||
|
// winix can return either a text answer or a binary answer
|
||||||
|
// if send_bin_stream is true then the binary answer is sent (out_bin_stream)
|
||||||
|
// or if send_bin_stream is false then the text answer is sent
|
||||||
|
// default: false
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// winix answer send to the client's browser
|
||||||
|
// |
|
||||||
|
// |
|
||||||
|
// depending on send_bin_stream
|
||||||
|
// (if false) ------------------------------------------------- (if true)
|
||||||
|
// | |
|
||||||
|
// text answer binary answer
|
||||||
|
// | |
|
||||||
|
// depending on return_json sending out_bin_stream
|
||||||
|
// (if false) ------------------------------------ (if true)
|
||||||
|
// | |
|
||||||
|
// normal request ajax request
|
||||||
|
// | |
|
||||||
|
// sending out_streams[0] |
|
||||||
|
// |
|
||||||
|
// |
|
||||||
|
// depending on return_info_only
|
||||||
|
// (if false) ------------------------------------------------------ (if true)
|
||||||
|
// | |
|
||||||
|
// generating JSON object from: generating JSON object only from info
|
||||||
|
// out_streams and info, e.g.: e.g.:
|
||||||
|
// { { info object serialized here }
|
||||||
|
// "stream_1": "some html content",
|
||||||
|
// "stream_2": "some other html content",
|
||||||
|
// "info": { info object serialized here }
|
||||||
|
// }
|
||||||
|
// note that out_streams[0] is not sent
|
||||||
|
// in JSON answers
|
||||||
|
//
|
||||||
|
//
|
||||||
|
bool send_bin_stream;
|
||||||
|
|
||||||
|
// binary page sent to the client if send_bin_stream is true
|
||||||
|
BinaryPage out_bin_stream;
|
||||||
|
|
||||||
|
// when returning the text answer we can either return the whole html page (normal requests)
|
||||||
|
// or a JSON object (for requests generated from AJAX)
|
||||||
|
// if return_json is false then we return the whole html page (which is in out_streams[0])
|
||||||
|
// if return_json is true we are creating an JSON object from out_streams
|
||||||
|
// (zero stream is ignored) and from info space (see above picture)
|
||||||
|
// (or just only from info if return_info_only is true)
|
||||||
|
// default: false
|
||||||
|
// return_json is set to true by App at the beginning of a request
|
||||||
|
// if reqtype:json parameter is present (in the url)
|
||||||
|
// note: return_json is only valid if send_bin_stream is false
|
||||||
|
bool return_json;
|
||||||
|
|
||||||
|
// main text output streams where the html otput is generated from ezc templates
|
||||||
|
// the zero stream (out_streams[0]) is used as the main stream
|
||||||
|
// to which the whole html page (with doctype, head, body) is generated
|
||||||
|
// the rest streams can be only used in ajax requests (send in JSON format to the client)
|
||||||
|
// in ezc templates you can use [ezc stream ...] keyword
|
||||||
|
// to switch between streams e.g. [ezc stream "0" "2"]
|
||||||
|
std::vector<HtmlTextStream> out_streams;
|
||||||
|
|
||||||
|
// if true the JSON object is generated only from info (out_streams are not used)
|
||||||
|
// default: false
|
||||||
|
bool return_info_only;
|
||||||
|
|
||||||
|
// additional info added when sending the JSON answer
|
||||||
|
PT::Space info;
|
||||||
|
|
||||||
|
// info serializer
|
||||||
|
// if not set then the json_generic_serializer from App will be used
|
||||||
|
// default: null (json_generic_serializer used)
|
||||||
|
PT::SpaceToJSON * info_serializer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if set to true then the standard template system will not be used
|
||||||
|
// default: false
|
||||||
|
bool page_generated;
|
||||||
|
|
||||||
|
// whether or not the html filter should be used
|
||||||
|
// the size of the table is the same as out_streams
|
||||||
|
// default: all items true
|
||||||
|
std::vector<bool> use_html_filter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if this variable is true then winix always return 200 OK header
|
||||||
|
// when the status would be 404 (not found) or 403 (permission denied)
|
||||||
|
// default: false
|
||||||
|
bool use_200_status_for_not_found_and_permission_denied;
|
||||||
|
|
||||||
|
// options used by ezc generators
|
||||||
|
bool gen_trim_white;
|
||||||
|
bool gen_skip_new_line;
|
||||||
|
bool gen_use_special_chars;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
additional variables used for common uses
|
||||||
|
*/
|
||||||
|
|
||||||
|
// usually items in the current directory (depends on the function)
|
||||||
|
std::vector<Item> item_tab;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Request();
|
Request();
|
||||||
void SetConfig(Config * pconfig);
|
void SetConfig(Config * pconfig);
|
||||||
|
|
||||||
|
void RequestStarts();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
// for debugging
|
|
||||||
void PrintGetTab();
|
|
||||||
//void PrintEnv();
|
|
||||||
|
|
||||||
|
|
||||||
bool IsParam(const wchar_t * param_name);
|
bool IsParam(const wchar_t * param_name);
|
||||||
bool IsParam(const std::wstring & param_name);
|
bool IsParam(const std::wstring & param_name);
|
||||||
const std::wstring & ParamValue(const wchar_t * param_name); // returns empty string if there is no such a parameter
|
const std::wstring & ParamValue(const wchar_t * param_name); // returns an empty string if there is no such a parameter
|
||||||
const std::wstring & ParamValue(const std::wstring & param_name); // returns empty string if there is no such a parameter
|
const std::wstring & ParamValue(const std::wstring & param_name); // returns an empty string if there is no such a parameter
|
||||||
|
|
||||||
void SetCookie(const char * name, const char * value, tm * expires = 0);
|
|
||||||
void SetCookie(const char * name, long value, tm * expires = 0);
|
|
||||||
|
|
||||||
bool IsPostVar(const wchar_t * var);
|
bool IsPostVar(const wchar_t * var);
|
||||||
const std::wstring & PostVar(const wchar_t * var); // !! zamienic na referencje nie do sta³ej (bez const)
|
bool IsPostVar(const std::wstring & var);
|
||||||
|
const std::wstring & PostVar(const wchar_t * var); // returns an empty string if there is no such a parameter
|
||||||
|
const std::wstring & PostVar(const std::wstring & var); // returns an empty string if there is no such a parameter
|
||||||
bool PostVar(const wchar_t * var, std::wstring & result);
|
bool PostVar(const wchar_t * var, std::wstring & result);
|
||||||
|
bool PostVar(const std::wstring & var, std::wstring & result);
|
||||||
std::wstring * PostVarp(const wchar_t * var);
|
std::wstring * PostVarp(const wchar_t * var);
|
||||||
|
std::wstring * PostVarp(const std::wstring & var);
|
||||||
|
|
||||||
bool AllPostVarEmpty(); // returning true if all post vars are empty
|
bool AllPostVarEmpty(); // returning true if all post vars are empty
|
||||||
|
|
||||||
void SendAll();
|
|
||||||
|
// setting a cookie
|
||||||
|
// name - cookie name (either const wchar_t, or std::wstring or PT::WTextStream)
|
||||||
|
// value - cookie value (can be everything which can be put to PT::WTextStream stream)
|
||||||
|
// the return std::wstring reference is a reference to the cookie inserted value (in out_cookies structure)
|
||||||
|
template<typename NameType, typename ValueType>
|
||||||
|
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date * expires = 0);
|
||||||
|
|
||||||
|
template<typename NameType, typename ValueType>
|
||||||
|
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date & expires);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Config * config;
|
Config * config;
|
||||||
|
|
||||||
void ClearPostFileTmp();
|
|
||||||
|
|
||||||
// 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
|
// used in ParamValue() and PostVar() when there is no such a param
|
||||||
const std::wstring str_empty;
|
const std::wstring str_empty;
|
||||||
|
|
||||||
|
void ClearOutputStreams();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename NameType, typename ValueType>
|
||||||
|
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date * expires)
|
||||||
|
{
|
||||||
|
PT::WTextStream cookie;
|
||||||
|
|
||||||
|
cookie << value;
|
||||||
|
|
||||||
|
if( cookie.empty() )
|
||||||
|
cookie << L"\"\""; // cookie empty value
|
||||||
|
|
||||||
|
if( expires )
|
||||||
|
cookie << L"; expires=" << DateToStrCookie(*expires) << L" GMT";
|
||||||
|
|
||||||
|
cookie << L"; path=/; domain=" << config->base_url;
|
||||||
|
|
||||||
|
/*
|
||||||
|
!! IMPROVE ME add an option to the config
|
||||||
|
|
||||||
|
don't use '; secure' flag if you are using both sites (with SSL
|
||||||
|
and without SSL) -- with secure flag the cookie is sent only through
|
||||||
|
SSL and if you accidentally open a new window without SSL (http://)
|
||||||
|
then winix will create a new session for you and the previous session (https://)
|
||||||
|
will be lost (the session cookie will be overwritten in the client's browser)
|
||||||
|
*/
|
||||||
|
|
||||||
|
return out_cookies.Add(name, cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename NameType, typename ValueType>
|
||||||
|
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date & expires)
|
||||||
|
{
|
||||||
|
return AddCookie(name, value, &expires);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+44
-5
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_requesttypes
|
||||||
@@ -13,17 +38,26 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include "textstream/textstream.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !! IMPROVE ME
|
||||||
// !! narazie uzywane tylko w post multi parserze
|
// !! narazie uzywane tylko w post multi parserze
|
||||||
// dodac do zwyklego parsera post
|
// dodac do zwyklego parsera post
|
||||||
#define WINIX_POSTTABLE_MAXSIZE 50
|
#define WINIX_POSTTABLE_MAXSIZE 50
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct PostFile
|
struct PostFile
|
||||||
{
|
{
|
||||||
std::wstring filename; // original file name
|
std::wstring filename; // original file name
|
||||||
std::wstring tmp_filename; // file with content (in /tmp)
|
std::wstring tmp_filename; // file with content (in /tmp)
|
||||||
|
size_t file_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -36,13 +70,18 @@ struct Param
|
|||||||
|
|
||||||
|
|
||||||
// some global types used by Request class
|
// some global types used by Request class
|
||||||
typedef std::vector<std::wstring> GetTab;
|
|
||||||
typedef std::map<std::wstring, std::wstring> PostTab;
|
typedef std::map<std::wstring, std::wstring> PostTab;
|
||||||
typedef std::map<std::wstring, PostFile> PostFileTab;
|
typedef std::map<std::wstring, PostFile> PostFileTab;
|
||||||
typedef std::vector<Param> ParamTab;
|
typedef std::vector<Param> ParamTab;
|
||||||
|
|
||||||
typedef std::map<std::string, std::string> CookieTab;
|
typedef std::map<std::wstring, std::wstring> CookieTab;
|
||||||
|
|
||||||
|
|
||||||
|
typedef PT::TextStreamBase<char, 1, 4096> BinaryPage;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+38
-3
@@ -1,21 +1,52 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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/types.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <cstring>
|
||||||
#include "run.h"
|
#include "run.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Run::Run()
|
Run::Run()
|
||||||
{
|
{
|
||||||
@@ -181,6 +212,7 @@ void Run::ChildThrow()
|
|||||||
|
|
||||||
execve(command, par, env);
|
execve(command, par, env);
|
||||||
// if we are here then there is something wrong (execve failed)
|
// if we are here then there is something wrong (execve failed)
|
||||||
|
// !! IMPROVE ME may add exit() ?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -383,3 +415,6 @@ int Run::Go(std::string & out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+38
-3
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_run
|
||||||
@@ -12,6 +37,12 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -159,5 +190,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+90
-14
@@ -1,50 +1,126 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "session.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Session::Session()
|
Session::Session()
|
||||||
{
|
{
|
||||||
SetTimeToNow();
|
|
||||||
Clear();
|
Clear();
|
||||||
|
plugin_data.SetSession(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Session::SetTimeToNow()
|
|
||||||
{
|
|
||||||
time = std::time(0);
|
|
||||||
tm_time = Time(time);
|
|
||||||
|
|
||||||
last_time = time;
|
Session::Session(const Session & ses)
|
||||||
tm_last_time = tm_time;
|
{
|
||||||
|
operator=(ses);
|
||||||
|
}
|
||||||
|
|
||||||
|
Session & Session::operator=(const Session & ses)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
we can only copy ses.id because it is needen in SessionContainer
|
||||||
|
it have indexes to id
|
||||||
|
*/
|
||||||
|
|
||||||
|
Clear();
|
||||||
|
id = ses.id;
|
||||||
|
plugin_data.SetSession(this);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Session::SetTimesTo(time_t time)
|
||||||
|
{
|
||||||
|
start_time = time;
|
||||||
|
start_date = time;
|
||||||
|
|
||||||
|
last_time = start_time;
|
||||||
|
last_date = start_date;
|
||||||
|
|
||||||
// the first request can be a POST (it doesn't matter)
|
// the first request can be a POST (it doesn't matter)
|
||||||
last_time_get = time;
|
last_time_get = start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// this doesn't clear times
|
|
||||||
void Session::Clear()
|
// clear_plugin_data is used when clearing the temporary session
|
||||||
|
void Session::Clear(bool clear_plugin_data)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
time = 0;
|
|
||||||
puser = 0;
|
puser = 0;
|
||||||
rebus_item = 0;
|
rebus_item = 0;
|
||||||
rebus_checked = false;
|
rebus_checked = false;
|
||||||
remember_me = false;
|
remember_me = false;
|
||||||
new_session = true;
|
new_session = true;
|
||||||
spam_score = 0;
|
spam_score = 0;
|
||||||
|
remove_me = false;
|
||||||
|
|
||||||
|
start_time = 0;
|
||||||
|
last_time = 0;
|
||||||
|
last_time_get = 0;
|
||||||
|
start_date.Clear();
|
||||||
|
last_date.Clear();
|
||||||
|
|
||||||
|
log_buffer.Clear();
|
||||||
|
last_css.clear();
|
||||||
|
ip_ban = 0;
|
||||||
|
|
||||||
|
if( clear_plugin_data )
|
||||||
plugin_data.Resize(0);
|
plugin_data.Resize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// clearing some variables when a request is ended (just for safety)
|
||||||
|
void Session::ClearAfterRequest()
|
||||||
|
{
|
||||||
|
// ip_ban list can be sorted by SessionManager (in the special thread)
|
||||||
|
ip_ban = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+70
-14
@@ -1,29 +1,69 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_session
|
||||||
#define headerfile_winix_core_session
|
#define headerfile_winix_core_session
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "plugindata.h"
|
#include "plugindata.h"
|
||||||
#include "rebus.h"
|
#include "rebus.h"
|
||||||
|
#include "textstream.h"
|
||||||
|
#include "date/date.h"
|
||||||
|
#include "ipban.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// when deleting Sessions you should set request.session into the session object as well
|
|
||||||
// this allows to delete plugins session data
|
|
||||||
// because a session object has plugin_data object
|
|
||||||
// and in its destructor the plugin.Call(WINIX_SESSION_REMOVE) is called
|
|
||||||
struct Session
|
struct Session
|
||||||
{
|
{
|
||||||
|
Session();
|
||||||
|
Session(const Session & ses);
|
||||||
|
Session & operator=(const Session & ses);
|
||||||
|
|
||||||
|
void SetTimesTo(time_t time);
|
||||||
|
void Clear(bool clear_plugin_data = true);
|
||||||
|
void ClearAfterRequest();
|
||||||
|
|
||||||
|
|
||||||
// 0 - means that there is a temporary session
|
// 0 - means that there is a temporary session
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
@@ -32,18 +72,19 @@ struct Session
|
|||||||
|
|
||||||
// when this session was created
|
// when this session was created
|
||||||
// (the same values)
|
// (the same values)
|
||||||
time_t time;
|
time_t start_time;
|
||||||
tm tm_time;
|
PT::Date start_date;
|
||||||
|
|
||||||
// when this session was last used
|
// when this session was last used
|
||||||
// (the same values)
|
// (the same values)
|
||||||
time_t last_time;
|
time_t last_time;
|
||||||
tm tm_last_time;
|
PT::Date last_date;
|
||||||
|
|
||||||
// when there was a last get request
|
// when there was a last get request
|
||||||
// (used to calculate spam)
|
// (used to calculate spam or invalid login attempts etc.)
|
||||||
time_t last_time_get;
|
time_t last_time_get;
|
||||||
|
|
||||||
|
|
||||||
// 0 - means that nobody is logged
|
// 0 - means that nobody is logged
|
||||||
User * puser;
|
User * puser;
|
||||||
|
|
||||||
@@ -58,19 +99,34 @@ struct Session
|
|||||||
|
|
||||||
int spam_score;
|
int spam_score;
|
||||||
|
|
||||||
|
// if true then this session will be removed by SessionManager
|
||||||
|
// without checking the time expiration
|
||||||
|
bool remove_me;
|
||||||
|
|
||||||
PluginData plugin_data;
|
PluginData plugin_data;
|
||||||
|
|
||||||
|
|
||||||
|
// buffer for the session log
|
||||||
|
TextStream<std::wstring> log_buffer;
|
||||||
|
|
||||||
|
// !! IMPROVE ME it is still needed?
|
||||||
|
// css cannot be taken directly from the mountpoint?
|
||||||
|
// table with css files
|
||||||
|
// used by some javascript wysiwyg editors (ckeditor, tinymce)
|
||||||
|
std::vector<std::wstring> last_css;
|
||||||
|
|
||||||
|
// pointer to IPBan struct if exists for this IP
|
||||||
|
// many sessions can pointer to the same IPBan struct
|
||||||
|
// (it can be null)
|
||||||
|
IPBan * ip_ban;
|
||||||
|
|
||||||
Session();
|
|
||||||
void SetTimeToNow();
|
|
||||||
void Clear();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+96
-13
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "sessioncontainer.h"
|
||||||
@@ -12,6 +37,11 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SessionContainer::SessionContainer()
|
SessionContainer::SessionContainer()
|
||||||
{
|
{
|
||||||
@@ -44,25 +74,29 @@ Table::iterator i = table.begin();
|
|||||||
|
|
||||||
log << log3 << "SC: deleting all sessions" << logend;
|
log << log3 << "SC: deleting all sessions" << logend;
|
||||||
|
|
||||||
|
cur->session = tmp_session;
|
||||||
|
|
||||||
// don't use table.clear();
|
// don't use table.clear();
|
||||||
// because plugins session data would not be erased
|
// because plugins session data would not be erased
|
||||||
// we must set cur->session for each session and then delete it
|
|
||||||
while( i != table.end() )
|
while( i != table.end() )
|
||||||
{
|
{
|
||||||
cur->session = &(*i);
|
i->plugin_data.DeleteAll(); // it's better to call it here instead in the destructor
|
||||||
table.erase(i++);
|
table.erase(i++);
|
||||||
}
|
}
|
||||||
|
|
||||||
// erasing indexes
|
// erasing indexes
|
||||||
index_id.clear();
|
index_id.clear();
|
||||||
table_size = 0;
|
table_size = 0;
|
||||||
cur->session = tmp_session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionContainer::EraseById(IdIterator i)
|
void SessionContainer::EraseById(long id)
|
||||||
{
|
{
|
||||||
|
IndexId::iterator i = index_id.find(id);
|
||||||
|
|
||||||
|
if( i != index_id.end() )
|
||||||
|
{
|
||||||
Session * old_session = tmp_session;
|
Session * old_session = tmp_session;
|
||||||
|
|
||||||
if( cur->session != &(*i->second) )
|
if( cur->session != &(*i->second) )
|
||||||
@@ -71,11 +105,21 @@ void SessionContainer::EraseById(IdIterator i)
|
|||||||
cur->session = &(*i->second);
|
cur->session = &(*i->second);
|
||||||
|
|
||||||
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
|
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
|
||||||
|
|
||||||
|
// call first DeleteAll() because if not then it would be called from the destructor
|
||||||
|
// and there'll be a problem if it throws an exception there
|
||||||
|
i->second->plugin_data.DeleteAll();
|
||||||
table.erase(i->second);
|
table.erase(i->second);
|
||||||
index_id.erase(i);
|
index_id.erase(i);
|
||||||
table_size -= 1;
|
table_size -= 1;
|
||||||
|
|
||||||
cur->session = old_session;
|
cur->session = old_session;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log1 << "SC: I cannot delete a session with id: " << id
|
||||||
|
<< " (there is no such a session)" << logend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,23 +162,24 @@ SessionContainer::IdIterator SessionContainer::IdEnd()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SessionContainer::PushBack(const Session & session)
|
SessionContainer::Iterator SessionContainer::AddSession(long id)
|
||||||
{
|
{
|
||||||
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(session.id, table.end()) );
|
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(id, table.end()) );
|
||||||
|
|
||||||
if( !index_id_res.second )
|
if( !index_id_res.second )
|
||||||
{
|
{
|
||||||
// that element already exists (was not inserted now)
|
// that element already exists (was not inserted now)
|
||||||
return false;
|
return End();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator last = table.insert(table.end(), session);
|
Iterator last = table.insert(table.end(), empty_session);
|
||||||
|
last->id = id;
|
||||||
index_id_res.first->second = last;
|
index_id_res.first->second = last;
|
||||||
table_size += 1;
|
table_size += 1;
|
||||||
|
|
||||||
log << log3 << "SC: added session, id: " << session.id << logend;
|
log << log3 << "SC: added session, id: " << id << logend;
|
||||||
|
|
||||||
return true;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -153,9 +198,47 @@ return i->second;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionContainer::ChangeSessionId(SessionContainer::Iterator ses, long new_id)
|
||||||
|
{
|
||||||
|
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(new_id, ses) );
|
||||||
|
|
||||||
|
if( !index_id_res.second )
|
||||||
|
{
|
||||||
|
log << log1 << "SC: session with id: " << new_id << " already exists" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long old_id = ses->id;
|
||||||
|
index_id.erase(old_id); // remove the old index
|
||||||
|
ses->id = new_id;
|
||||||
|
log << log3 << "SC: changed session id from: " << old_id << " to " << new_id << logend;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionContainer::ChangeSessionId(long old_id, long new_id)
|
||||||
|
{
|
||||||
|
IndexId::iterator i = index_id.find(old_id);
|
||||||
|
|
||||||
|
if( i != index_id.end() )
|
||||||
|
{
|
||||||
|
return ChangeSessionId(i->second, new_id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log2 << "SC: there is no a session with id: " << old_id << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+44
-9
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_sessioncontainer
|
||||||
@@ -19,15 +44,16 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionContainer
|
class SessionContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// when deleting Sessions you should set request.session into the session object
|
|
||||||
// this allows to delete plugins session data
|
|
||||||
// because a session object has plugin_data object
|
|
||||||
// and in its destructor the plugin.Call(WINIX_SESSION_REMOVE) is called
|
|
||||||
typedef std::list<Session> Table;
|
typedef std::list<Session> Table;
|
||||||
typedef Table::iterator Iterator;
|
typedef Table::iterator Iterator;
|
||||||
typedef std::map<long, Iterator> IndexId;
|
typedef std::map<long, Iterator> IndexId;
|
||||||
@@ -46,13 +72,16 @@ public:
|
|||||||
Iterator Begin();
|
Iterator Begin();
|
||||||
Iterator End();
|
Iterator End();
|
||||||
Session & Back();
|
Session & Back();
|
||||||
bool PushBack(const Session & session);
|
Iterator AddSession(long id);
|
||||||
Iterator FindById(long);
|
Iterator FindById(long);
|
||||||
|
|
||||||
IdIterator IdBegin();
|
IdIterator IdBegin();
|
||||||
IdIterator IdEnd();
|
IdIterator IdEnd();
|
||||||
|
|
||||||
void EraseById(IdIterator i);
|
void EraseById(long id);
|
||||||
|
|
||||||
|
bool ChangeSessionId(Iterator ses, long new_id);
|
||||||
|
bool ChangeSessionId(long old_id, long new_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -63,6 +92,8 @@ private:
|
|||||||
Config * config;
|
Config * config;
|
||||||
Session * tmp_session;
|
Session * tmp_session;
|
||||||
|
|
||||||
|
Session empty_session;
|
||||||
|
|
||||||
// in FreeBSD implementation (GCC) list::size() has linear complexity
|
// in FreeBSD implementation (GCC) list::size() has linear complexity
|
||||||
// so we use our own table_size with O(1)
|
// so we use our own table_size with O(1)
|
||||||
size_t table_size;
|
size_t table_size;
|
||||||
@@ -70,4 +101,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+244
-41
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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 <sys/stat.h>
|
||||||
@@ -17,6 +42,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -57,6 +85,11 @@ void SessionManager::SetLastContainer(LastContainer * plast_container)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionManager::InitBanList()
|
||||||
|
{
|
||||||
|
ban_tab.SetMaxSize(config->ban_list_soft_max_size, config->ban_list_max_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t SessionManager::Size()
|
size_t SessionManager::Size()
|
||||||
{
|
{
|
||||||
@@ -84,7 +117,7 @@ long id;
|
|||||||
{
|
{
|
||||||
if( sizeof(long) == 8 )
|
if( sizeof(long) == 8 )
|
||||||
{
|
{
|
||||||
id = ((unsigned long)std::rand()) << 32 + std::rand();
|
id = (((unsigned long)std::rand()) << 32) + std::rand();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -109,17 +142,14 @@ return id;
|
|||||||
void SessionManager::CreateSession()
|
void SessionManager::CreateSession()
|
||||||
{
|
{
|
||||||
int attempts = 100;
|
int attempts = 100;
|
||||||
bool added = false;
|
SessionContainer::Iterator i = session_tab.End();
|
||||||
|
|
||||||
new_session.SetTimeToNow();
|
|
||||||
new_session.Clear();
|
|
||||||
|
|
||||||
if( config->session_max == 0 || session_tab.Size() < config->session_max )
|
if( config->session_max == 0 || session_tab.Size() < config->session_max )
|
||||||
{
|
{
|
||||||
for( ; !added && attempts > 0 ; --attempts )
|
for( ; i == session_tab.End() && attempts > 0 ; --attempts )
|
||||||
{
|
{
|
||||||
new_session.id = CreateSessionId();
|
long id = CreateSessionId();
|
||||||
added = session_tab.PushBack(new_session);
|
i = session_tab.AddSession(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -127,43 +157,50 @@ bool added = false;
|
|||||||
log << log2 << "SM: sessions limit exceeded (" << config->session_max << ")" << logend;
|
log << log2 << "SM: sessions limit exceeded (" << config->session_max << ")" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( added )
|
if( i != session_tab.End() )
|
||||||
{
|
{
|
||||||
session = &session_tab.Back();
|
session = &(*i);
|
||||||
session->new_session = true;
|
session->new_session = true;
|
||||||
|
session->SetTimesTo(cur->request->start_time);
|
||||||
|
|
||||||
log << log2 << "SM: created a new session: " << session->id << logend;
|
log << log2 << "SM: created a new session: " << session->id << logend;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// there is a problem with generating a new session id
|
// there is a problem with generating a new session id
|
||||||
// we do not set a session cookie
|
// we do not set a session cookie
|
||||||
session = &temporary_session;
|
|
||||||
session->SetTimeToNow();
|
|
||||||
session->Clear(); // !! uwaga ten Clear wyczysci plugins data
|
|
||||||
session->new_session = false; // temporary session was initialized at the beginning
|
|
||||||
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
|
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
|
||||||
|
SetTemporarySession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionManager::SetTemporarySession()
|
||||||
|
{
|
||||||
|
session = &temporary_session;
|
||||||
|
session->Clear(false);
|
||||||
|
session->SetTimesTo(cur->request->start_time);
|
||||||
|
session->new_session = false; // temporary session was initialized at the beginning
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SessionManager::SetSessionFromCookie(const std::string & cookie)
|
|
||||||
|
bool SessionManager::SetSessionFromCookie(const std::wstring & cookie)
|
||||||
{
|
{
|
||||||
long id = Tol(cookie.c_str());
|
long id = Tol(cookie.c_str());
|
||||||
SessionContainer::Iterator s = session_tab.FindById(id);
|
SessionContainer::Iterator s = session_tab.FindById(id);
|
||||||
|
|
||||||
if( s == session_tab.End() )
|
if( s == session_tab.End() || s->remove_me )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// that session is in the table
|
// that session is in the table
|
||||||
session = &(*s);
|
session = &(*s);
|
||||||
session->new_session = false;
|
session->new_session = false;
|
||||||
session->last_time = std::time(0);
|
session->last_time = cur->request->start_time;
|
||||||
session->tm_last_time = Time(session->last_time);
|
session->last_date = cur->request->start_time;
|
||||||
|
|
||||||
if( cur->request->method == Request::get )
|
if( cur->request->method == Request::get )
|
||||||
session->last_time_get = session->last_time;
|
session->last_time_get = cur->request->start_time;
|
||||||
|
|
||||||
log << log2 << "SM: session: " << session->id;
|
log << log2 << "SM: session: " << session->id;
|
||||||
|
|
||||||
@@ -179,6 +216,24 @@ return true;
|
|||||||
|
|
||||||
void SessionManager::SetSession()
|
void SessionManager::SetSession()
|
||||||
{
|
{
|
||||||
|
current_ip_ban = ban_tab.FindIP(cur->request->ip);
|
||||||
|
|
||||||
|
if( current_ip_ban && current_ip_ban->IsIPBanned() )
|
||||||
|
{
|
||||||
|
if( current_ip_ban->expires != 0 && cur->request->start_time >= current_ip_ban->expires )
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
|
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
|
||||||
|
|
||||||
if( i == cur->request->cookie_tab.end() )
|
if( i == cur->request->cookie_tab.end() )
|
||||||
@@ -197,10 +252,23 @@ void SessionManager::SetSession()
|
|||||||
CreateSession();
|
CreateSession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session->ip_ban = current_ip_ban;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Session * SessionManager::FindSession(long id)
|
||||||
|
{
|
||||||
|
SessionContainer::Iterator i = session_tab.FindById(id);
|
||||||
|
|
||||||
|
if( i != session_tab.End() )
|
||||||
|
return &*i;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SessionContainer::Iterator SessionManager::SessionBegin()
|
SessionContainer::Iterator SessionManager::SessionBegin()
|
||||||
{
|
{
|
||||||
return session_tab.Begin();
|
return session_tab.Begin();
|
||||||
@@ -220,11 +288,57 @@ SessionContainer::Iterator SessionManager::SessionEnd()
|
|||||||
|
|
||||||
void SessionManager::DeleteSessions()
|
void SessionManager::DeleteSessions()
|
||||||
{
|
{
|
||||||
|
SessionContainer::Iterator i;
|
||||||
|
|
||||||
|
for(i=session_tab.Begin() ; i!=session_tab.End() ; ++i)
|
||||||
|
{
|
||||||
|
if( i->puser && !i->remember_me )
|
||||||
|
{
|
||||||
|
plugin.Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
||||||
|
last_container->UserLogout(i->puser->id, i->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
session_tab.Clear();
|
session_tab.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
don't change a session's id when a user is logged
|
||||||
|
the session id is in last_container and the user would not be
|
||||||
|
correctly removed from the container
|
||||||
|
*/
|
||||||
|
bool SessionManager::ChangeSessionId(long old_id)
|
||||||
|
{
|
||||||
|
int attempts = 100;
|
||||||
|
bool changed = false;
|
||||||
|
long new_id;
|
||||||
|
SessionContainer::Iterator i = session_tab.FindById(old_id);
|
||||||
|
|
||||||
|
if( i != session_tab.End() )
|
||||||
|
{
|
||||||
|
for( ; !changed && attempts > 0 ; --attempts )
|
||||||
|
{
|
||||||
|
new_id = CreateSessionId();
|
||||||
|
changed = session_tab.ChangeSessionId(i, new_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( changed )
|
||||||
|
plugin.Call(&(*i), WINIX_SESSION_CHANGED_ID, old_id, new_id);
|
||||||
|
else
|
||||||
|
log << log1 << "SM: I cannot create a new session id (still uses old one)" << logend;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log2 << "SM: there is no a session with id: " << old_id << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::InitTmpSession()
|
void SessionManager::InitTmpSession()
|
||||||
{
|
{
|
||||||
Session * old_session = cur->session;
|
Session * old_session = cur->session;
|
||||||
@@ -244,7 +358,7 @@ void SessionManager::UninitTmpSession()
|
|||||||
|
|
||||||
log << log4 << "SM: uninitializing temporary session" << logend;
|
log << log4 << "SM: uninitializing temporary session" << logend;
|
||||||
cur->session = &temporary_session;
|
cur->session = &temporary_session;
|
||||||
cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_SESSION_REMOVE);
|
cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
||||||
cur->session->plugin_data.Resize(0);
|
cur->session->plugin_data.Resize(0);
|
||||||
|
|
||||||
cur->session = old_session;
|
cur->session = old_session;
|
||||||
@@ -266,8 +380,15 @@ SessionContainer::Iterator i;
|
|||||||
for(i=session_tab.Begin() ; i != session_tab.End() ; ++i)
|
for(i=session_tab.Begin() ; i != session_tab.End() ; ++i)
|
||||||
{
|
{
|
||||||
i->plugin_data.Resize(plugin.Size());
|
i->plugin_data.Resize(plugin.Size());
|
||||||
cur->session = &(*i);
|
plugin.Call(&(*i), WINIX_SESSION_CREATED);
|
||||||
plugin.Call(WINIX_SESSION_CREATED);
|
|
||||||
|
/*
|
||||||
|
!! IMPROVE ME
|
||||||
|
we do not add it to the last_container (we don't have IP address stored yet)
|
||||||
|
*/
|
||||||
|
|
||||||
|
if( i->puser )
|
||||||
|
plugin.Call(&(*i), WINIX_USER_LOGGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur->session = &temporary_session;
|
cur->session = &temporary_session;
|
||||||
@@ -279,10 +400,15 @@ SessionContainer::Iterator i;
|
|||||||
|
|
||||||
void SessionManager::SaveSessions()
|
void SessionManager::SaveSessions()
|
||||||
{
|
{
|
||||||
|
char file_path[WINIX_OS_PATH_SIZE];
|
||||||
|
|
||||||
if( config->session_file.empty() )
|
if( config->session_file.empty() )
|
||||||
return;
|
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 )
|
if( !file )
|
||||||
{
|
{
|
||||||
@@ -297,17 +423,17 @@ void SessionManager::SaveSessions()
|
|||||||
|
|
||||||
for( ; i!=session_tab.End() ; ++i )
|
for( ; i!=session_tab.End() ; ++i )
|
||||||
{
|
{
|
||||||
if( i->id != 0 && i->puser )
|
if( i->id != 0 && i->puser && !i->remove_me )
|
||||||
{
|
{
|
||||||
file << i->id << ' ' << i->puser->id << ' ' << i->remember_me << ' ';
|
file << i->id << ' ' << i->puser->id << ' ' << i->remember_me << ' ';
|
||||||
file << (long)i->time << ' ' << (long)i->last_time << std::endl;
|
file << (long)i->start_time << ' ' << (long)i->last_time << std::endl;
|
||||||
|
|
||||||
++len;
|
++len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
chmod(config->session_file.c_str(), 0600);
|
chmod(file_path, 0600);
|
||||||
|
|
||||||
log << log2 << "SM: saved " << len << " session(s)" << logend;
|
log << log2 << "SM: saved " << len << " session(s)" << logend;
|
||||||
}
|
}
|
||||||
@@ -327,32 +453,83 @@ Session * SessionManager::GetCurSession()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// returns how many sessions was marked to remove
|
||||||
|
size_t SessionManager::MarkAllSessionsToRemove(long user_id)
|
||||||
|
{
|
||||||
|
size_t how_many = 0;
|
||||||
|
SessionContainer::Iterator i;
|
||||||
|
|
||||||
|
for(i=session_tab.Begin() ; i!=session_tab.End() ; ++i)
|
||||||
|
{
|
||||||
|
if( i->puser && i->puser->id == user_id )
|
||||||
|
{
|
||||||
|
plugin.Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
||||||
|
last_container->UserLogout(i->puser->id, i->id);
|
||||||
|
i->remove_me = true;
|
||||||
|
i->puser = 0;
|
||||||
|
how_many += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return how_many;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IPBan & SessionManager::AddIPToBanList(int ip)
|
||||||
|
{
|
||||||
|
return ban_tab.AddIP(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t SessionManager::BanListSize()
|
||||||
|
{
|
||||||
|
return ban_tab.Size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IPBan & SessionManager::GetIPBan(size_t index)
|
||||||
|
{
|
||||||
|
return ban_tab.GetIPBan(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionManager::RemoveIPBan(int ip)
|
||||||
|
{
|
||||||
|
ban_tab.RemoveIP(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionManager::ClearIPBanList()
|
||||||
|
{
|
||||||
|
ban_tab.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* sessions gc (second thread)
|
* sessions gc (second thread)
|
||||||
*
|
* sessions are only removed here
|
||||||
|
* SessionContainer::IndexId can be removed from the other thread
|
||||||
|
* (when ChangeSessionId() method is called)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SessionManager::Work()
|
void SessionManager::Work()
|
||||||
{
|
{
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
SessionContainer::IndexId::iterator i;
|
SessionContainer::Iterator i;
|
||||||
|
|
||||||
deleted = 0;
|
deleted = 0;
|
||||||
|
|
||||||
Lock();
|
Lock();
|
||||||
i = session_tab.IdBegin();
|
i = session_tab.Begin();
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
while( !exit )
|
while( !exit )
|
||||||
{
|
{
|
||||||
Lock();
|
Lock();
|
||||||
|
|
||||||
|
CheckWheterIPListIsSorted();
|
||||||
CheckSession(i);
|
CheckSession(i);
|
||||||
exit = synchro->was_stop_signal;
|
exit = synchro->was_stop_signal;
|
||||||
|
|
||||||
@@ -361,12 +538,23 @@ SessionContainer::IndexId::iterator i;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// objects locked
|
||||||
|
void SessionManager::CheckWheterIPListIsSorted()
|
||||||
|
{
|
||||||
|
if( !ban_tab.IsSorted() )
|
||||||
|
{
|
||||||
|
log << log4 << "SM: sorting the ban list" << logend;
|
||||||
|
ban_tab.Sort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// it's called from the other thread (with Lock and Unlock)
|
// it's called from the other thread (with Lock and Unlock)
|
||||||
void SessionManager::CheckSession(SessionContainer::IndexId::iterator & i)
|
void SessionManager::CheckSession(SessionContainer::Iterator & i)
|
||||||
{
|
{
|
||||||
const int deleted_max_at_once = 10;
|
const int deleted_max_at_once = 10;
|
||||||
|
|
||||||
if( i == session_tab.IdEnd() )
|
if( i == session_tab.End() )
|
||||||
{
|
{
|
||||||
if( deleted > 0 )
|
if( deleted > 0 )
|
||||||
{
|
{
|
||||||
@@ -374,14 +562,16 @@ const int deleted_max_at_once = 10;
|
|||||||
log << logsave;
|
log << logsave;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = session_tab.IdBegin();
|
i = session_tab.Begin();
|
||||||
WaitForSignalSleep(10);
|
WaitForSignalSleep(10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( IsSessionOutdated(*i->second) )
|
if( i->remove_me || IsSessionOutdated(*i) )
|
||||||
{
|
{
|
||||||
DeleteSession(i++);
|
Session * ses = &(*i);
|
||||||
|
++i;
|
||||||
|
DeleteSession(ses);
|
||||||
++deleted;
|
++deleted;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -405,9 +595,13 @@ bool SessionManager::IsSessionOutdated(const Session & s) const
|
|||||||
bool outdated;
|
bool outdated;
|
||||||
|
|
||||||
if( s.remember_me )
|
if( s.remember_me )
|
||||||
|
{
|
||||||
outdated = s.last_time < std::time(0) - config->session_remember_max_idle;
|
outdated = s.last_time < std::time(0) - config->session_remember_max_idle;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
outdated = s.last_time < std::time(0) - config->session_max_idle;
|
outdated = s.last_time < std::time(0) - config->session_max_idle;
|
||||||
|
}
|
||||||
|
|
||||||
return outdated;
|
return outdated;
|
||||||
}
|
}
|
||||||
@@ -415,14 +609,20 @@ return outdated;
|
|||||||
|
|
||||||
|
|
||||||
// it's called from the other thread (with Lock and Unlock)
|
// it's called from the other thread (with Lock and Unlock)
|
||||||
void SessionManager::DeleteSession(SessionContainer::IdIterator i)
|
void SessionManager::DeleteSession(Session * del_session)
|
||||||
{
|
{
|
||||||
Session * del_session = &(*i->second);
|
|
||||||
|
|
||||||
if( del_session->puser )
|
if( del_session->puser )
|
||||||
|
{
|
||||||
|
plugin.Call(del_session, WINIX_PREPARE_USER_TO_LOGOUT, del_session->puser);
|
||||||
last_container->UserLogout(del_session->puser->id, del_session->id);
|
last_container->UserLogout(del_session->puser->id, del_session->id);
|
||||||
|
del_session->puser = 0;
|
||||||
|
}
|
||||||
|
|
||||||
session_tab.EraseById(i);
|
long id = del_session->id;
|
||||||
|
|
||||||
|
plugin.Call(del_session, WINIX_PREPARE_SESSION_TO_REMOVE);
|
||||||
|
session_tab.EraseById(del_session->id);
|
||||||
|
plugin.Call((Session*)0, WINIX_SESSION_REMOVED, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -436,3 +636,6 @@ void SessionManager::DeleteSession(SessionContainer::IdIterator i)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+58
-10
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_sessionmanager
|
||||||
@@ -14,6 +39,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include "sessioncontainer.h"
|
#include "sessioncontainer.h"
|
||||||
|
#include "ipbancontainer.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "lastcontainer.h"
|
#include "lastcontainer.h"
|
||||||
@@ -23,6 +49,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionManager : public BaseThread
|
class SessionManager : public BaseThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -34,9 +65,15 @@ public:
|
|||||||
void SetSystem(System * psystem);
|
void SetSystem(System * psystem);
|
||||||
void SetLastContainer(LastContainer * plast_container);
|
void SetLastContainer(LastContainer * plast_container);
|
||||||
|
|
||||||
|
|
||||||
|
// can return a null pointer
|
||||||
|
Session * FindSession(long id);
|
||||||
|
|
||||||
void SetSession();
|
void SetSession();
|
||||||
void DeleteSessions(); // deleting all sessions
|
void DeleteSessions(); // deleting all sessions
|
||||||
|
bool ChangeSessionId(long old_id);
|
||||||
|
|
||||||
|
void InitBanList();
|
||||||
void InitTmpSession();
|
void InitTmpSession();
|
||||||
void UninitTmpSession();
|
void UninitTmpSession();
|
||||||
|
|
||||||
@@ -50,6 +87,13 @@ public:
|
|||||||
SessionContainer::Iterator SessionEnd();
|
SessionContainer::Iterator SessionEnd();
|
||||||
|
|
||||||
size_t Size();
|
size_t Size();
|
||||||
|
size_t MarkAllSessionsToRemove(long user_id);
|
||||||
|
|
||||||
|
IPBan & AddIPToBanList(int ip);
|
||||||
|
size_t BanListSize();
|
||||||
|
IPBan & GetIPBan(size_t index);
|
||||||
|
void RemoveIPBan(int ip);
|
||||||
|
void ClearIPBanList();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -63,28 +107,32 @@ private:
|
|||||||
Session * session;
|
Session * session;
|
||||||
|
|
||||||
SessionContainer session_tab;
|
SessionContainer session_tab;
|
||||||
|
IPBanContainer ban_tab;
|
||||||
|
|
||||||
|
IPBan * current_ip_ban;
|
||||||
|
|
||||||
// session with id 0
|
// session with id 0
|
||||||
Session temporary_session;
|
Session temporary_session;
|
||||||
|
|
||||||
// for adding a new session to the container
|
|
||||||
Session new_session;
|
|
||||||
|
|
||||||
bool IsSession(long s);
|
bool IsSession(long s);
|
||||||
|
|
||||||
long CreateSessionId();
|
long CreateSessionId();
|
||||||
void CreateSession();
|
void CreateSession();
|
||||||
bool SetSessionFromCookie(const std::string & cookie);
|
bool SetSessionFromCookie(const std::wstring & cookie);
|
||||||
|
void SetTemporarySession();
|
||||||
|
|
||||||
// second thread
|
// second thread
|
||||||
int deleted;
|
int deleted;
|
||||||
virtual void Work();
|
virtual void Work();
|
||||||
void CheckSession(SessionContainer::IndexId::iterator & i);
|
void CheckSession(SessionContainer::Iterator & i);
|
||||||
bool IsSessionOutdated(const Session & s) const;
|
bool IsSessionOutdated(const Session & s) const;
|
||||||
void DeleteSession(SessionContainer::IdIterator i);
|
void DeleteSession(Session * del_session);
|
||||||
|
void CheckWheterIPListIsSorted();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+71
-30
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "sessionparser.h"
|
||||||
@@ -12,8 +37,12 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
return Parse(path.c_str(), container);
|
||||||
}
|
}
|
||||||
@@ -25,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();
|
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 )
|
if( !file )
|
||||||
{
|
{
|
||||||
@@ -51,33 +86,19 @@ bool SessionParser::Parse(SessionContainer & container)
|
|||||||
file format, each rows:
|
file format, each rows:
|
||||||
session_id(long) user_id(long) remember_me(0|1) time(long) last_time(long)
|
session_id(long) user_id(long) remember_me(0|1) time(long) last_time(long)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
long user_id;
|
|
||||||
|
|
||||||
session.Clear();
|
|
||||||
last = file.get();
|
last = file.get();
|
||||||
|
|
||||||
log << log2 << "SP: reading sessions from the session file" << logend;
|
log << log2 << "SP: reading sessions from the session file" << logend;
|
||||||
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
session.id = ReadLong();
|
long id = ReadLong();
|
||||||
|
|
||||||
if( file.eof() )
|
if( file.eof() )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
user_id = ReadLong();
|
long user_id = ReadLong();
|
||||||
session.remember_me = ReadLong();
|
MakeSession(id, user_id, container);
|
||||||
session.time = ReadLong();
|
|
||||||
session.last_time = ReadLong();
|
|
||||||
|
|
||||||
if( MakeSession(user_id) )
|
|
||||||
{
|
|
||||||
users->IncrementLoggedUsers();
|
|
||||||
container.PushBack(session);
|
|
||||||
log << log2 << "SP: read session id: " << session.id << " for user: " << session.puser->name << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkipLine();
|
SkipLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,22 +108,38 @@ return true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SessionParser::MakeSession(long user_id)
|
void SessionParser::MakeSession(long id, long user_id, SessionContainer & container)
|
||||||
{
|
{
|
||||||
User * puser = users->GetUser(user_id);
|
User * puser = users->GetUser(user_id);
|
||||||
|
|
||||||
if( !puser )
|
if( !puser )
|
||||||
{
|
{
|
||||||
log << log1 << "SP: there is no a user with id: " << user_id << " (skipped)" << logend;
|
log << log1 << "SP: there is no a user with id: " << user_id << " (skipped)" << logend;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session.puser = puser;
|
SessionContainer::Iterator i = container.AddSession(id);
|
||||||
session.new_session = true;
|
|
||||||
session.tm_time = Time(session.time);
|
|
||||||
session.tm_last_time = Time(session.last_time);
|
|
||||||
|
|
||||||
return true;
|
if( i != container.End() )
|
||||||
|
{
|
||||||
|
i->Clear();
|
||||||
|
i->id = id;
|
||||||
|
i->puser = puser;
|
||||||
|
i->new_session = true;
|
||||||
|
i->remember_me = ReadLong();
|
||||||
|
i->start_time = ReadLong();
|
||||||
|
i->last_time = ReadLong();
|
||||||
|
i->start_date = i->start_time;
|
||||||
|
i->last_date = i->last_time;
|
||||||
|
// !! IMPROVE ME we do not save last_time_get
|
||||||
|
|
||||||
|
users->IncrementLoggedUsers();
|
||||||
|
log << log2 << "SP: read session id: " << id << " for user: " << puser->name << logend;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log1 << "SP: session with id: " << id << " already exists (skipping)" << logend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -164,3 +201,7 @@ bool is_sign = false;
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+39
-7
@@ -1,10 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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-2010, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_sessionparser
|
||||||
@@ -17,13 +42,17 @@
|
|||||||
#include "users.h"
|
#include "users.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionParser
|
class SessionParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool Parse(const char * path, SessionContainer & container);
|
bool Parse(const wchar_t * path, SessionContainer & container);
|
||||||
bool Parse(const std::string & path, SessionContainer & container);
|
bool Parse(const std::wstring & path, SessionContainer & container);
|
||||||
void SetUsers(Users * pusers);
|
void SetUsers(Users * pusers);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -31,7 +60,7 @@ private:
|
|||||||
Users * users;
|
Users * users;
|
||||||
|
|
||||||
bool Parse(SessionContainer & container);
|
bool Parse(SessionContainer & container);
|
||||||
bool MakeSession(long user_id);
|
void MakeSession(long id, long user_id, SessionContainer & container);
|
||||||
|
|
||||||
bool IsWhite(int c);
|
bool IsWhite(int c);
|
||||||
bool IsDigit(int c);
|
bool IsDigit(int c);
|
||||||
@@ -42,10 +71,13 @@ private:
|
|||||||
|
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
int last; // last character
|
int last; // last character
|
||||||
Session session;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Executable
+257
@@ -0,0 +1,257 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "slog.h"
|
||||||
|
#include "utf8/utf8.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SLog::SLog()
|
||||||
|
{
|
||||||
|
cur = 0;
|
||||||
|
locale = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SLog::SetCur(Cur * pcur)
|
||||||
|
{
|
||||||
|
cur = pcur;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SLog::SetLocale(Locale * plocale)
|
||||||
|
{
|
||||||
|
locale = plocale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const void * s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const char * s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const std::string * s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const std::string & s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const wchar_t * s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const std::wstring * s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const std::wstring & s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(int s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(long s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(char s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(wchar_t s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(size_t s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(double s)
|
||||||
|
{
|
||||||
|
return PutLog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const PT::Date & date)
|
||||||
|
{
|
||||||
|
return PutLog(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(LogManipulators m)
|
||||||
|
{
|
||||||
|
if( cur && cur->session )
|
||||||
|
{
|
||||||
|
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||||
|
|
||||||
|
switch(m)
|
||||||
|
{
|
||||||
|
case logend:
|
||||||
|
buf << '\n';
|
||||||
|
|
||||||
|
if( buf.Size() > WINIX_SLOG_MAX_LOG_SIZE )
|
||||||
|
{
|
||||||
|
buf.Clear();
|
||||||
|
(*this) << logwarning << T("slog_turn_over") << " " << WINIX_SLOG_MAX_LOG_SIZE << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case loginfo:
|
||||||
|
case logwarning:
|
||||||
|
case logerror:
|
||||||
|
buf << (wchar_t)(int)m;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::TranslateText(const char * str)
|
||||||
|
{
|
||||||
|
PT::UTF8ToWide(str, key_temp);
|
||||||
|
return TranslateText(key_temp.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::TranslateText(const wchar_t * str)
|
||||||
|
{
|
||||||
|
if( cur && cur->session )
|
||||||
|
{
|
||||||
|
const std::wstring * trans = 0;
|
||||||
|
|
||||||
|
if( locale )
|
||||||
|
trans = &locale->Get(str);
|
||||||
|
|
||||||
|
// !! IMPROVE ME "Not translated" add to locale
|
||||||
|
if( !trans || trans->empty() )
|
||||||
|
cur->session->log_buffer << "Not translated: " << str;
|
||||||
|
else
|
||||||
|
cur->session->log_buffer << trans;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const TranslateTextHelper<const char*> & raw)
|
||||||
|
{
|
||||||
|
return TranslateText(raw.par);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(const TranslateTextHelper<const wchar_t*> & raw)
|
||||||
|
{
|
||||||
|
return TranslateText(raw.par);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(TranslateTextHelper<const std::string*> raw)
|
||||||
|
{
|
||||||
|
return TranslateText(raw.par->c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(TranslateTextHelper<const std::wstring*> raw)
|
||||||
|
{
|
||||||
|
return TranslateText(raw.par->c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(TranslateTextHelper<std::string> raw)
|
||||||
|
{
|
||||||
|
return TranslateText(raw.par.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SLog & SLog::operator<<(TranslateTextHelper<std::wstring> raw)
|
||||||
|
{
|
||||||
|
return TranslateText(raw.par.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
Executable
+175
@@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winix_core_slog
|
||||||
|
#define headerfile_winix_core_slog
|
||||||
|
|
||||||
|
#include "cur.h"
|
||||||
|
#include "logmanipulators.h"
|
||||||
|
#include "templates/locale.h"
|
||||||
|
#include "textstream/textstream.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define WINIX_SLOG_MAX_LOG_SIZE 10240
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
session logger
|
||||||
|
|
||||||
|
sample:
|
||||||
|
#include "log.h" (or slog.h)
|
||||||
|
slog << logerror << "message" << "something" << logend;
|
||||||
|
slog << logwarning << T("message_to_translate") << x << logend;
|
||||||
|
|
||||||
|
if the latter example "message_to_translate" will be taken from locales
|
||||||
|
currently following manipulators are taken into account:
|
||||||
|
loginfo - the message in a normal info
|
||||||
|
logwarning - this is a warning
|
||||||
|
logerror - this is an error
|
||||||
|
logend - end of a line -- we have one kind of a message (info, warning, error) per line
|
||||||
|
|
||||||
|
loginfo, logwarning, logerror should be specified at the beginning of a line
|
||||||
|
(other manipulators are skipped)
|
||||||
|
*/
|
||||||
|
class SLog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
SLog();
|
||||||
|
|
||||||
|
void SetCur(Cur * pcur);
|
||||||
|
void SetLocale(Locale * plocale);
|
||||||
|
|
||||||
|
template<class RawType>
|
||||||
|
struct TranslateTextHelper
|
||||||
|
{
|
||||||
|
const RawType & par;
|
||||||
|
|
||||||
|
TranslateTextHelper(const TranslateTextHelper<RawType> & p) : par(p.par) {}
|
||||||
|
TranslateTextHelper(const RawType & p) : par(p) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
SLog & operator<<(const void * s);
|
||||||
|
SLog & operator<<(const char * s);
|
||||||
|
SLog & operator<<(const std::string * s);
|
||||||
|
SLog & operator<<(const std::string & s);
|
||||||
|
SLog & operator<<(const wchar_t * s);
|
||||||
|
SLog & operator<<(const std::wstring * s);
|
||||||
|
SLog & operator<<(const std::wstring & s);
|
||||||
|
SLog & operator<<(int s);
|
||||||
|
SLog & operator<<(long s);
|
||||||
|
SLog & operator<<(char s);
|
||||||
|
SLog & operator<<(wchar_t s);
|
||||||
|
SLog & operator<<(size_t s);
|
||||||
|
SLog & operator<<(double s);
|
||||||
|
SLog & operator<<(LogManipulators m);
|
||||||
|
SLog & operator<<(const PT::Date & date);
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
SLog & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
||||||
|
|
||||||
|
|
||||||
|
SLog & TranslateText(const char * str);
|
||||||
|
SLog & TranslateText(const wchar_t * str);
|
||||||
|
|
||||||
|
template<size_t str_size>
|
||||||
|
SLog & operator<<(const TranslateTextHelper<const char [str_size]> & raw) { return TranslateText(raw.par); }
|
||||||
|
|
||||||
|
template<size_t str_size>
|
||||||
|
SLog & operator<<(const TranslateTextHelper<const wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
||||||
|
|
||||||
|
template<size_t str_size>
|
||||||
|
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }
|
||||||
|
|
||||||
|
template<size_t str_size>
|
||||||
|
SLog & operator<<(const TranslateTextHelper<wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
||||||
|
|
||||||
|
SLog & operator<<(const TranslateTextHelper<const char*> & raw);
|
||||||
|
SLog & operator<<(const TranslateTextHelper<const wchar_t*> & raw);
|
||||||
|
SLog & operator<<(TranslateTextHelper<const std::string*> raw);
|
||||||
|
SLog & operator<<(TranslateTextHelper<const std::wstring*> raw);
|
||||||
|
SLog & operator<<(TranslateTextHelper<std::string> raw);
|
||||||
|
SLog & operator<<(TranslateTextHelper<std::wstring> raw);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
template<class LogParam>
|
||||||
|
SLog & PutLog(const LogParam & par);
|
||||||
|
|
||||||
|
Cur * cur;
|
||||||
|
Locale * locale;
|
||||||
|
std::wstring key_temp;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class RawType>
|
||||||
|
SLog::TranslateTextHelper<RawType> T(const RawType & par)
|
||||||
|
{
|
||||||
|
return SLog::TranslateTextHelper<RawType>(par);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
SLog & SLog::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
||||||
|
{
|
||||||
|
return PutLog(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class LogParam>
|
||||||
|
SLog & SLog::PutLog(const LogParam & par)
|
||||||
|
{
|
||||||
|
if( cur && cur->session )
|
||||||
|
cur->session->log_buffer << par;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern SLog slog;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
+77
-5
@@ -1,35 +1,107 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "synchro.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Synchro::Synchro() : mutex(PTHREAD_MUTEX_INITIALIZER)
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Synchro::Synchro()
|
||||||
{
|
{
|
||||||
was_stop_signal = false;
|
was_stop_signal = false;
|
||||||
|
|
||||||
|
#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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Synchro::Lock()
|
bool Synchro::Lock()
|
||||||
{
|
{
|
||||||
return pthread_mutex_lock(&mutex) == 0;
|
int res = pthread_mutex_lock(&mutex);
|
||||||
|
|
||||||
|
if( res == 0 )
|
||||||
|
{
|
||||||
|
ref[pthread_self()] = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( res == EDEADLK )
|
||||||
|
{
|
||||||
|
// Lock() method in this thread was called before
|
||||||
|
ref[pthread_self()] += 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Synchro::Unlock()
|
void Synchro::Unlock()
|
||||||
{
|
{
|
||||||
|
int & r = ref[pthread_self()];
|
||||||
|
|
||||||
|
if( r > 1 )
|
||||||
|
{
|
||||||
|
r -= 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( r == 1 )
|
||||||
|
{
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+43
-3
@@ -1,16 +1,46 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_synchro
|
||||||
#define headerfile_winix_core_synchro
|
#define headerfile_winix_core_synchro
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -28,9 +58,19 @@ struct Synchro
|
|||||||
|
|
||||||
bool Lock();
|
bool Lock();
|
||||||
void Unlock();
|
void Unlock();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// deadlock counter for each thread
|
||||||
|
// we can call Lock() more than one in the same thread
|
||||||
|
std::map<pthread_t, int> ref;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+507
-67
@@ -1,17 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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"
|
#include "system.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "templates/templates.h"
|
#include "templates/templates.h"
|
||||||
#include "functions/functionbase.h"
|
#include "functions/functions.h"
|
||||||
|
#include "plugin.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -39,15 +71,51 @@ void System::SetSynchro(Synchro * psynchro)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::SetFunctions(Functions * pfunctions)
|
||||||
|
{
|
||||||
|
functions = pfunctions;
|
||||||
|
}
|
||||||
|
|
||||||
|
void System::SetSessionManager(SessionManager * sm)
|
||||||
|
{
|
||||||
|
session_manager = sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::ReadTimeZones()
|
||||||
|
{
|
||||||
|
if( config->etc_dir.empty() )
|
||||||
|
{
|
||||||
|
log << log1 << "System: I cannot read time zones, set etc_dir directory in the config" << logend;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( config->time_zones_file.empty() )
|
||||||
|
{
|
||||||
|
log << log1 << "System:: I cannot read time zones, set time_zones_file in the config" << logend;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
name_temp = config->etc_dir;
|
||||||
|
name_temp += '/';
|
||||||
|
name_temp += config->time_zones_file;
|
||||||
|
|
||||||
|
time_zones.SetTimeZoneMaxId(config->time_zone_max_id);
|
||||||
|
time_zones.ReadTimeZones(name_temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void System::Init()
|
void System::Init()
|
||||||
{
|
{
|
||||||
|
thread_manager.SetSynchro(synchro);
|
||||||
|
thread_manager.Init();
|
||||||
|
|
||||||
dirs.SetDb(db);
|
dirs.SetDb(db);
|
||||||
dirs.SetCur(cur);
|
dirs.SetCur(cur);
|
||||||
dirs.SetNotify(¬ify);
|
dirs.SetNotify(¬ify);
|
||||||
dirs.ReadDirs();
|
dirs.ReadDirs();
|
||||||
|
|
||||||
|
mounts.SkipStaticDirs(config->dont_use_static_dirs);
|
||||||
mounts.SetDirs(&dirs);
|
mounts.SetDirs(&dirs);
|
||||||
mounts.SetDb(db);
|
mounts.SetDb(db);
|
||||||
mounts.SetCur(cur);
|
mounts.SetCur(cur);
|
||||||
@@ -55,34 +123,99 @@ void System::Init()
|
|||||||
mounts.ReadMounts();
|
mounts.ReadMounts();
|
||||||
|
|
||||||
users.SetCur(cur);
|
users.SetCur(cur);
|
||||||
|
users.SetSessionManager(session_manager);
|
||||||
users.ReadUsers(db);
|
users.ReadUsers(db);
|
||||||
users.SetTimeZoneOffset(config->time_zone_offset);
|
|
||||||
groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione
|
groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione
|
||||||
|
|
||||||
rebus.SetCur(cur);
|
rebus.SetCur(cur);
|
||||||
rebus.Init();
|
rebus.Init();
|
||||||
|
|
||||||
notify.SetSynchro(synchro);
|
|
||||||
notify.SetCur(cur);
|
notify.SetCur(cur);
|
||||||
notify.SetConfig(config);
|
notify.SetConfig(config);
|
||||||
notify.SetUsers(&users);
|
notify.SetUsers(&users);
|
||||||
notify.SetDirs(&dirs);
|
notify.SetDirs(&dirs);
|
||||||
|
notify.SetThreadManager(&thread_manager);
|
||||||
notify.Init();
|
notify.Init();
|
||||||
|
|
||||||
thumb.SetSynchro(synchro);
|
image.SetDb(db);
|
||||||
thumb.SetDb(db);
|
image.SetConfig(config);
|
||||||
thumb.SetConfig(config);
|
image.SetSystem(this);
|
||||||
thumb.SetSystem(this);
|
thread_manager.Add(&image, L"image");
|
||||||
|
|
||||||
crypt.SetConfig(config);
|
crypt.SetConfig(config);
|
||||||
|
|
||||||
|
// SetSynchro will be called by ThreadManager itself
|
||||||
|
// job.ReadFromFile();
|
||||||
|
thread_manager.Add(&job, L"job");
|
||||||
|
|
||||||
|
ReadTimeZones();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::PutUrlProto(bool can_use_ssl, std::wstring & str, bool clear_str)
|
||||||
|
{
|
||||||
|
bool ssl = false;
|
||||||
|
|
||||||
|
if( clear_str )
|
||||||
|
str.clear();
|
||||||
|
|
||||||
|
if( can_use_ssl )
|
||||||
|
{
|
||||||
|
if( !config->use_ssl_only_for_logged_users ||
|
||||||
|
cur->session->puser ||
|
||||||
|
(cur->request->function && cur->request->function->need_ssl) )
|
||||||
|
{
|
||||||
|
str += config->url_ssl_proto;
|
||||||
|
ssl = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !ssl )
|
||||||
|
str += config->url_proto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::CreateItemLink(long parent_id, const std::wstring & url, const std::wstring & subdomain,
|
||||||
|
std::wstring & link, bool clear_str)
|
||||||
|
{
|
||||||
|
PutUrlProto(config->use_ssl, link, clear_str);
|
||||||
|
|
||||||
|
if( !subdomain.empty() )
|
||||||
|
{
|
||||||
|
link += subdomain;
|
||||||
|
link += '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
link += config->base_url;
|
||||||
|
dirs.MakePath(parent_id, link, false); // !! IMPROVE ME may some kind of error checks here?
|
||||||
|
link += url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::CreateItemLink(const Item & item, std::wstring & link, bool clear_str)
|
||||||
|
{
|
||||||
|
CreateItemLink(item.parent_id, item.url, cur->request->subdomain, link, clear_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// !! IMPROVE ME
|
||||||
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
|
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
|
||||||
// !! moze zwracac jakas wartosc?
|
// !! moze zwracac jakas wartosc?
|
||||||
void System::RedirectTo(const Item & item, const wchar_t * postfix)
|
/*
|
||||||
|
postfix will not be UrlEncoded
|
||||||
|
*/
|
||||||
|
void System::RedirectTo(const Item & item, const wchar_t * postfix, bool use_reqtype)
|
||||||
{
|
{
|
||||||
cur->request->redirect_to = config->base_url;
|
PutUrlProto(config->use_ssl, cur->request->redirect_to);
|
||||||
|
|
||||||
|
if( !cur->request->subdomain.empty() )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += cur->request->subdomain;
|
||||||
|
cur->request->redirect_to += '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
cur->request->redirect_to += config->base_url;
|
||||||
|
|
||||||
if( item.type == Item::dir )
|
if( item.type == Item::dir )
|
||||||
{
|
{
|
||||||
@@ -98,13 +231,30 @@ void System::RedirectTo(const Item & item, const wchar_t * postfix)
|
|||||||
|
|
||||||
if( postfix )
|
if( postfix )
|
||||||
cur->request->redirect_to += postfix;
|
cur->request->redirect_to += postfix;
|
||||||
|
|
||||||
|
if( use_reqtype && cur->request->IsParam(L"reqtype") )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += L"/-/reqtype:";
|
||||||
|
cur->request->redirect_to += cur->request->ParamValue(L"reqtype");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void System::RedirectTo(long item_id, const wchar_t * postfix)
|
/*
|
||||||
|
postfix will not be UrlEncoded
|
||||||
|
*/
|
||||||
|
void System::RedirectTo(long item_id, const wchar_t * postfix, bool use_reqtype)
|
||||||
{
|
{
|
||||||
cur->request->redirect_to = config->base_url;
|
PutUrlProto(config->use_ssl, cur->request->redirect_to);
|
||||||
|
|
||||||
|
if( !cur->request->subdomain.empty() )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += cur->request->subdomain;
|
||||||
|
cur->request->redirect_to += '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
cur->request->redirect_to += config->base_url;
|
||||||
Item * pdir = dirs.GetDir(item_id);
|
Item * pdir = dirs.GetDir(item_id);
|
||||||
|
|
||||||
if( pdir )
|
if( pdir )
|
||||||
@@ -135,14 +285,32 @@ void System::RedirectTo(long item_id, const wchar_t * postfix)
|
|||||||
|
|
||||||
if( postfix )
|
if( postfix )
|
||||||
cur->request->redirect_to += postfix;
|
cur->request->redirect_to += postfix;
|
||||||
|
|
||||||
|
if( use_reqtype && cur->request->IsParam(L"reqtype") )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += L"/-/reqtype:";
|
||||||
|
cur->request->redirect_to += cur->request->ParamValue(L"reqtype");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void System::RedirectTo(const std::wstring & url)
|
|
||||||
{
|
|
||||||
cur->request->redirect_to = config->base_url;
|
|
||||||
|
|
||||||
if( !url.empty() && url[0] == '/' )
|
/*
|
||||||
|
url will not be UrlEncoded
|
||||||
|
*/
|
||||||
|
void System::RedirectTo(const wchar_t * url, bool use_reqtype)
|
||||||
|
{
|
||||||
|
PutUrlProto(config->use_ssl, cur->request->redirect_to);
|
||||||
|
|
||||||
|
if( !cur->request->subdomain.empty() )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += cur->request->subdomain;
|
||||||
|
cur->request->redirect_to += '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
cur->request->redirect_to += config->base_url;
|
||||||
|
|
||||||
|
if( url[0] == '/' )
|
||||||
{
|
{
|
||||||
// absolute path
|
// absolute path
|
||||||
cur->request->redirect_to += url;
|
cur->request->redirect_to += url;
|
||||||
@@ -161,9 +329,28 @@ void System::RedirectTo(const std::wstring & url)
|
|||||||
cur->request->redirect_to += url;
|
cur->request->redirect_to += url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( use_reqtype && cur->request->IsParam(L"reqtype") )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += L"/-/reqtype:";
|
||||||
|
cur->request->redirect_to += cur->request->ParamValue(L"reqtype");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
url will not be UrlEncoded
|
||||||
|
*/
|
||||||
|
void System::RedirectTo(const std::wstring & url, bool use_reqtype)
|
||||||
|
{
|
||||||
|
RedirectTo(url.c_str(), use_reqtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
params will be UrlEncoded
|
||||||
|
*/
|
||||||
void System::AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str)
|
void System::AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str)
|
||||||
{
|
{
|
||||||
if( clear_str )
|
if( clear_str )
|
||||||
@@ -172,19 +359,22 @@ void System::AddParams(const ParamTab & param_tab, std::wstring & str, bool clea
|
|||||||
for(size_t i=0 ; i<param_tab.size() ; ++i)
|
for(size_t i=0 ; i<param_tab.size() ; ++i)
|
||||||
{
|
{
|
||||||
str += '/';
|
str += '/';
|
||||||
str += param_tab[i].name;
|
UrlEncode(param_tab[i].name, str, false);
|
||||||
|
|
||||||
if( !param_tab[i].value.empty() )
|
if( !param_tab[i].value.empty() )
|
||||||
{
|
{
|
||||||
str += ':';
|
str += ':';
|
||||||
str += param_tab[i].value;
|
UrlEncode(param_tab[i].value, str, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void System::RedirectWithFunctionAndParamsTo(const std::wstring & url)
|
url will not be UrlEncoded
|
||||||
|
params will be UrlEncoded
|
||||||
|
*/
|
||||||
|
void System::RedirectWithFunctionAndParamsTo(const wchar_t * url)
|
||||||
{
|
{
|
||||||
RedirectTo(url);
|
RedirectTo(url);
|
||||||
|
|
||||||
@@ -193,25 +383,68 @@ void System::RedirectWithFunctionAndParamsTo(const std::wstring & url)
|
|||||||
|
|
||||||
cur->request->redirect_to += '/';
|
cur->request->redirect_to += '/';
|
||||||
cur->request->redirect_to += cur->request->function->fun.url;
|
cur->request->redirect_to += cur->request->function->fun.url;
|
||||||
|
|
||||||
AddParams(cur->request->param_tab, cur->request->redirect_to, false);
|
AddParams(cur->request->param_tab, cur->request->redirect_to, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void System::RedirectToLastDir()
|
/*
|
||||||
|
url will not be UrlEncoded
|
||||||
|
params will be UrlEncoded
|
||||||
|
*/
|
||||||
|
void System::RedirectWithFunctionAndParamsTo(const std::wstring & url)
|
||||||
|
{
|
||||||
|
RedirectWithFunctionAndParamsTo(url.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::RedirectToLastDir(const wchar_t * postfix, bool use_reqtype)
|
||||||
{
|
{
|
||||||
if( !cur->request->dir_tab.empty() )
|
if( !cur->request->dir_tab.empty() )
|
||||||
RedirectTo( *cur->request->dir_tab.back() );
|
RedirectTo( *cur->request->dir_tab.back(), postfix, use_reqtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void System::RedirectToLastItem()
|
void System::RedirectToLastItem(const wchar_t * postfix, bool use_reqtype)
|
||||||
{
|
{
|
||||||
if( cur->request->last_item )
|
if( cur->request->last_item )
|
||||||
RedirectTo( *cur->request->last_item );
|
RedirectTo( *cur->request->last_item, postfix, use_reqtype );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::RedirectToLastFunction(const wchar_t * postfix, bool use_reqtype)
|
||||||
|
{
|
||||||
|
RedirectToLastDir(0, false);
|
||||||
|
TrimLast(cur->request->redirect_to, '/');
|
||||||
|
|
||||||
|
if( cur->request->is_item )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += '/';
|
||||||
|
cur->request->redirect_to += cur->request->item.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( cur->request->function )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += '/';
|
||||||
|
cur->request->redirect_to += cur->request->function->fun.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( postfix )
|
||||||
|
{
|
||||||
|
cur->request->redirect_to += '/';
|
||||||
|
cur->request->redirect_to += postfix;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( use_reqtype && cur->request->IsParam(L"reqtype") )
|
||||||
|
{
|
||||||
|
if( !cur->request->function && !postfix )
|
||||||
|
cur->request->redirect_to += L"/-";
|
||||||
|
|
||||||
|
cur->request->redirect_to += L"/reqtype:";
|
||||||
|
cur->request->redirect_to += cur->request->ParamValue(L"reqtype");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool System::CanChangeUser(const Item & item, long new_user_id)
|
bool System::CanChangeUser(const Item & item, long new_user_id)
|
||||||
{
|
{
|
||||||
@@ -223,12 +456,12 @@ bool System::CanChangeUser(const Item & item, long new_user_id)
|
|||||||
// super user is allowed everything
|
// super user is allowed everything
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// !! przeciez to prosciej mozna zapisac
|
if( item.user_id == -1 || new_user_id == -1 || item.user_id != new_user_id )
|
||||||
// albo dac od razu return false
|
|
||||||
if( item.user_id != new_user_id )
|
|
||||||
// only super user can change the owner of an item
|
// only super user can change the owner of an item
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// item.user_id is equal new_user_id -- we return true
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,10 +481,10 @@ bool System::CanChangeGroup(const Item & item, long new_group_id)
|
|||||||
// user is allowed to change the group only if he is an owner of the item
|
// user is allowed to change the group only if he is an owner of the item
|
||||||
// he can change only into a group in which he is a member of, or into a 'no_group'
|
// he can change only into a group in which he is a member of, or into a 'no_group'
|
||||||
|
|
||||||
if( !cur->session->puser )
|
if( !cur->session->puser || cur->session->puser->id == -1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( cur->session->puser->id != item.user_id )
|
if( item.user_id == -1 || cur->session->puser->id != item.user_id )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( new_group_id == -1 )
|
if( new_group_id == -1 )
|
||||||
@@ -281,10 +514,10 @@ bool System::CanChangePrivileges(const Item & item, int new_priv)
|
|||||||
{
|
{
|
||||||
// the owner of an item is allowed to change the privileges
|
// the owner of an item is allowed to change the privileges
|
||||||
|
|
||||||
if( !cur->session->puser )
|
if( !cur->session->puser || cur->session->puser->id == -1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( cur->session->puser->id != item.user_id )
|
if( item.user_id == -1 || cur->session->puser->id != item.user_id )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +525,7 @@ return true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// private
|
||||||
bool System::HasAccess(const Item & item, int mask)
|
bool System::HasAccess(const Item & item, int mask)
|
||||||
{
|
{
|
||||||
if( !cur->session )
|
if( !cur->session )
|
||||||
@@ -303,19 +536,25 @@ bool System::HasAccess(const Item & item, int mask)
|
|||||||
// super user is allowed everything
|
// super user is allowed everything
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( cur->session->puser && cur->session->puser->id == item.user_id )
|
if( cur->session->puser && item.user_id != -1 && cur->session->puser->id == item.user_id )
|
||||||
{
|
{
|
||||||
// the owner
|
// the owner
|
||||||
|
return ((item.privileges >> 9) & mask) == mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( cur->session->puser && item.group_id != -1 && cur->session->puser->IsMemberOf(item.group_id) )
|
||||||
|
{
|
||||||
|
// group
|
||||||
return ((item.privileges >> 6) & mask) == mask;
|
return ((item.privileges >> 6) & mask) == mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( cur->session->puser && cur->session->puser->IsMemberOf(item.group_id) )
|
if( cur->session->puser )
|
||||||
{
|
{
|
||||||
// group
|
// others -- others logged people
|
||||||
return ((item.privileges >> 3) & mask) == mask;
|
return ((item.privileges >> 3) & mask) == mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// others
|
// guests -- not logged people
|
||||||
|
|
||||||
return (item.privileges & mask) == mask;
|
return (item.privileges & mask) == mask;
|
||||||
}
|
}
|
||||||
@@ -344,8 +583,8 @@ bool System::HasReadExecAccess(const Item & item)
|
|||||||
if( cur->session && cur->session->puser && cur->session->puser->super_user )
|
if( cur->session && cur->session->puser && cur->session->puser->super_user )
|
||||||
{
|
{
|
||||||
// there must be at least one 'x' (for the root)
|
// there must be at least one 'x' (for the root)
|
||||||
|
// !! CHECK ME: is it applicable to directories too?
|
||||||
return (item.privileges & 0111) != 0;
|
return (item.privileges & 01111) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return HasAccess(item, 5); // r+x
|
return HasAccess(item, 5); // r+x
|
||||||
@@ -394,6 +633,7 @@ bool System::DirsHaveReadExecPerm()
|
|||||||
|
|
||||||
|
|
||||||
// if we don't have access we only remove the item from the table
|
// if we don't have access we only remove the item from the table
|
||||||
|
// !! moze zamienic nazwe na CheckReadAccessToItems ?
|
||||||
void System::CheckAccessToItems(std::vector<Item> & item_tab)
|
void System::CheckAccessToItems(std::vector<Item> & item_tab)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@@ -412,6 +652,93 @@ size_t i = 0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void System::CheckWriteAccessToItems(std::vector<Item> & item_tab)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
while( i < item_tab.size() )
|
||||||
|
{
|
||||||
|
if( !HasWriteAccess(item_tab[i]) )
|
||||||
|
{
|
||||||
|
item_tab.erase(item_tab.begin() + i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int System::NewPrivileges(int creation_mask)
|
||||||
|
{
|
||||||
|
if( cur && cur->session && cur->session->puser )
|
||||||
|
{
|
||||||
|
int umask = cur->session->puser->env.Int(L"umask", config->umask);
|
||||||
|
return (~umask) & creation_mask;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (~config->umask) & creation_mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
from man sticky:
|
||||||
|
A directory whose `sticky bit' is set becomes an append-only directory,
|
||||||
|
or, more accurately, a directory in which the deletion of files is
|
||||||
|
restricted. A file in a sticky directory may only be removed or renamed
|
||||||
|
by a user if the user has write permission for the directory and the user
|
||||||
|
is the owner of the file, the owner of the directory, or the super-user.
|
||||||
|
This feature is usefully applied to directories such as /tmp which must
|
||||||
|
be publicly writable but should deny users the license to arbitrarily
|
||||||
|
delete or rename each others' files.
|
||||||
|
*/
|
||||||
|
bool System::CanRemoveRenameChild(const Item & dir, long child_item_user_id)
|
||||||
|
{
|
||||||
|
if( dir.type != Item::dir )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( !HasWriteAccess(dir) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( (dir.privileges & 010000) == 0 )
|
||||||
|
// there is no a sticky bit set to this directory
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if( cur->session->puser )
|
||||||
|
{
|
||||||
|
if( cur->session->puser->super_user )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if( dir.user_id != -1 && cur->session->puser->id != -1 && child_item_user_id != -1 )
|
||||||
|
{
|
||||||
|
if( cur->session->puser->id == child_item_user_id ||
|
||||||
|
cur->session->puser->id == dir.user_id )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int System::NewFilePrivileges()
|
||||||
|
{
|
||||||
|
return NewPrivileges(06666);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int System::NewDirPrivileges()
|
||||||
|
{
|
||||||
|
return NewPrivileges(07777);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool System::CanUseHtml(long user_id)
|
bool System::CanUseHtml(long user_id)
|
||||||
{
|
{
|
||||||
@@ -550,7 +877,7 @@ return res;
|
|||||||
|
|
||||||
// making a global file path (in the unix file system)
|
// making a global file path (in the unix file system)
|
||||||
// you should call CreateNewFile before
|
// 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();
|
path.clear();
|
||||||
|
|
||||||
@@ -580,7 +907,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
|||||||
path += L"/normal";
|
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;
|
return false;
|
||||||
|
|
||||||
path += '/';
|
path += '/';
|
||||||
@@ -617,7 +944,7 @@ return res;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error System::AddFile(Item & item, int notify_code)
|
Error System::AddFile(Item & item, int notify_code, bool call_plugins)
|
||||||
{
|
{
|
||||||
if( item.type != Item::file )
|
if( item.type != Item::file )
|
||||||
return WINIX_ERR_FILE_EXPECTED;
|
return WINIX_ERR_FILE_EXPECTED;
|
||||||
@@ -631,6 +958,9 @@ Error System::AddFile(Item & item, int notify_code)
|
|||||||
|
|
||||||
if( notify_code )
|
if( notify_code )
|
||||||
notify.ItemChanged(notify_code, item);
|
notify.ItemChanged(notify_code, item);
|
||||||
|
|
||||||
|
if( call_plugins )
|
||||||
|
plugin.Call(WINIX_FILE_ADDED, &item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -639,7 +969,7 @@ return status;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error System::EditFile(Item & item, bool with_url, int notify_code)
|
Error System::EditFile(Item & item, bool with_url, int notify_code, bool call_plugins)
|
||||||
{
|
{
|
||||||
if( item.type != Item::file )
|
if( item.type != Item::file )
|
||||||
return WINIX_ERR_FILE_EXPECTED;
|
return WINIX_ERR_FILE_EXPECTED;
|
||||||
@@ -660,6 +990,9 @@ Error System::EditFile(Item & item, bool with_url, int notify_code)
|
|||||||
|
|
||||||
if( notify_code )
|
if( notify_code )
|
||||||
notify.ItemChanged(notify_code, item);
|
notify.ItemChanged(notify_code, item);
|
||||||
|
|
||||||
|
if( call_plugins )
|
||||||
|
plugin.Call(WINIX_FILE_CHANGED, &item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -667,39 +1000,85 @@ return status;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
time_t System::LocalTime(time_t gmt_time)
|
|
||||||
|
time_t System::ToLocal(time_t utc_time)
|
||||||
{
|
{
|
||||||
int time_offset;
|
size_t tz_id;
|
||||||
|
|
||||||
if( cur->session && cur->session->puser )
|
if( cur->session && cur->session->puser )
|
||||||
time_offset = cur->session->puser->time_zone_offset;
|
tz_id = cur->session->puser->time_zone_id;
|
||||||
else
|
else
|
||||||
time_offset = config->time_zone_offset_guest;
|
tz_id = config->time_zone_default_id;
|
||||||
|
|
||||||
return gmt_time + (time_t)time_offset;
|
TimeZone * tz = time_zones.GetZone(tz_id);
|
||||||
|
|
||||||
|
if( tz )
|
||||||
|
return tz->ToLocal(utc_time);
|
||||||
|
|
||||||
|
return utc_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tm System::LocalTime(const tm * ptm)
|
|
||||||
|
PT::Date System::ToLocal(const PT::Date & utc_date)
|
||||||
{
|
{
|
||||||
time_t t;
|
size_t tz_id;
|
||||||
tm rtm;
|
|
||||||
|
|
||||||
t = Time(ptm);
|
if( cur->session && cur->session->puser )
|
||||||
t = LocalTime(t);
|
tz_id = cur->session->puser->time_zone_id;
|
||||||
rtm = Time(t);
|
else
|
||||||
|
tz_id = config->time_zone_default_id;
|
||||||
|
|
||||||
return rtm;
|
TimeZone * tz = time_zones.GetZone(tz_id);
|
||||||
|
|
||||||
|
if( tz )
|
||||||
|
return tz->ToLocal(utc_date);
|
||||||
|
|
||||||
|
return utc_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tm System::LocalTime(const tm & ptm)
|
|
||||||
|
|
||||||
|
time_t System::ToUTC(time_t local_time)
|
||||||
{
|
{
|
||||||
return LocalTime(&ptm);
|
size_t tz_id;
|
||||||
|
|
||||||
|
if( cur->session && cur->session->puser )
|
||||||
|
tz_id = cur->session->puser->time_zone_id;
|
||||||
|
else
|
||||||
|
tz_id = config->time_zone_default_id;
|
||||||
|
|
||||||
|
TimeZone * tz = time_zones.GetZone(tz_id);
|
||||||
|
|
||||||
|
if( tz )
|
||||||
|
return tz->ToUTC(local_time);
|
||||||
|
|
||||||
|
return local_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PT::Date System::ToUTC(const PT::Date & local_date)
|
||||||
|
{
|
||||||
|
size_t tz_id;
|
||||||
|
|
||||||
|
if( cur->session && cur->session->puser )
|
||||||
|
tz_id = cur->session->puser->time_zone_id;
|
||||||
|
else
|
||||||
|
tz_id = config->time_zone_default_id;
|
||||||
|
|
||||||
|
TimeZone * tz = time_zones.GetZone(tz_id);
|
||||||
|
|
||||||
|
if( tz )
|
||||||
|
return tz->ToUTC(local_date);
|
||||||
|
|
||||||
|
return local_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
return codes:
|
return codes:
|
||||||
ok:
|
ok:
|
||||||
@@ -784,6 +1163,12 @@ bool System::FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( check_access && !HasReadAccess(out_item) )
|
||||||
|
{
|
||||||
|
log << log1 << "System: no read access to the file or symlink" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if( out_item.type == Item::symlink )
|
if( out_item.type == Item::symlink )
|
||||||
{
|
{
|
||||||
if( out_item.link_to.empty() )
|
if( out_item.link_to.empty() )
|
||||||
@@ -792,18 +1177,10 @@ bool System::FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if( !check_access || HasReadAccess(out_item) )
|
|
||||||
{
|
{
|
||||||
if( !(stop_on_link_redirect && out_item.link_redirect==1) )
|
if( !(stop_on_link_redirect && out_item.link_redirect==1) )
|
||||||
link_to_temp = out_item.link_to;
|
link_to_temp = out_item.link_to;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "System: no read access to the symlink" << logend;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -861,6 +1238,8 @@ int System::FollowAllLinks(const std::vector<Item*> & current_dir_tab, const std
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// !! CHECK ME
|
||||||
|
// FollowLink is using link_to_temp temporary variable too
|
||||||
res = FollowLink(current_dir_tab, link_to_temp, out_dir_tab, out_item);
|
res = FollowLink(current_dir_tab, link_to_temp, out_dir_tab, out_item);
|
||||||
link_to_temp.clear();
|
link_to_temp.clear();
|
||||||
|
|
||||||
@@ -964,3 +1343,64 @@ return ok;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
adding a new file to winix
|
||||||
|
file_path - a name of a static file (from common directory)
|
||||||
|
url - url of a file which will be inserted (in /var directory)
|
||||||
|
|
||||||
|
current limitation:
|
||||||
|
warning: the url is not prepared by PrepareUrl() (PrepareUrl is from functions)
|
||||||
|
*/
|
||||||
|
bool System::AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url, bool overwrite_existing)
|
||||||
|
{
|
||||||
|
if( config->common_dir.empty() )
|
||||||
|
{
|
||||||
|
log << log1 << "System: can't open a file from common directory, common_dir not set in the config" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_name = config->common_dir;
|
||||||
|
file_name += '/';
|
||||||
|
file_name += file_path;
|
||||||
|
|
||||||
|
if( !GetUTF8File(file_name, file_content) )
|
||||||
|
{
|
||||||
|
log << log1 << "System: can't open a file: " << file_name << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Item * var = dirs.CreateVarDir();
|
||||||
|
|
||||||
|
if( !var )
|
||||||
|
{
|
||||||
|
log << log1 << "System: can't create /var directory" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( db->GetItem(var->id, url, file_content_item) == WINIX_ERR_OK )
|
||||||
|
{
|
||||||
|
if( overwrite_existing )
|
||||||
|
db->DelItem(file_content_item);
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_content_item.Clear();
|
||||||
|
file_content_item.parent_id = var->id;
|
||||||
|
file_content_item.user_id = var->user_id;
|
||||||
|
file_content_item.group_id = var->group_id;
|
||||||
|
file_content_item.privileges = 07555; // !! IMPROVE ME: may it should be added as a parameter to this function?
|
||||||
|
file_content_item.subject = url;
|
||||||
|
file_content_item.url = url;
|
||||||
|
file_content_item.type = Item::file;
|
||||||
|
file_content_item.content_type = Item::ct_raw;
|
||||||
|
file_content_item.content = file_content;
|
||||||
|
|
||||||
|
return AddFile(file_content_item, false) == WINIX_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+111
-19
@@ -1,16 +1,42 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_system
|
||||||
#define headerfile_winix_core_system
|
#define headerfile_winix_core_system
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include "job.h"
|
||||||
#include "dirs.h"
|
#include "dirs.h"
|
||||||
#include "mounts.h"
|
#include "mounts.h"
|
||||||
#include "db/db.h"
|
#include "db/db.h"
|
||||||
@@ -22,10 +48,19 @@
|
|||||||
#include "rebus.h"
|
#include "rebus.h"
|
||||||
#include "loadavg.h"
|
#include "loadavg.h"
|
||||||
#include "synchro.h"
|
#include "synchro.h"
|
||||||
#include "thumb.h"
|
#include "image.h"
|
||||||
|
#include "threadmanager.h"
|
||||||
#include "notify/notify.h"
|
#include "notify/notify.h"
|
||||||
|
#include "timezones.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Functions;
|
||||||
|
class SessionManager;
|
||||||
|
|
||||||
|
|
||||||
// file system
|
// file system
|
||||||
@@ -54,8 +89,8 @@ public:
|
|||||||
// notifications (by emails)
|
// notifications (by emails)
|
||||||
Notify notify;
|
Notify notify;
|
||||||
|
|
||||||
// thumbnails (special thread)
|
// images (resizing, generating thumbnails)
|
||||||
Thumb thumb;
|
Image image;
|
||||||
|
|
||||||
// the time when the winix starts
|
// the time when the winix starts
|
||||||
time_t system_start;
|
time_t system_start;
|
||||||
@@ -63,25 +98,44 @@ public:
|
|||||||
// cryptography and hashes
|
// cryptography and hashes
|
||||||
Crypt crypt;
|
Crypt crypt;
|
||||||
|
|
||||||
|
// thread management
|
||||||
|
ThreadManager thread_manager;
|
||||||
|
|
||||||
|
// jobs
|
||||||
|
Job job;
|
||||||
|
|
||||||
|
// time zones read from etc/time_zones.conf
|
||||||
|
// when winix starts
|
||||||
|
TimeZones time_zones;
|
||||||
|
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
void SetCur(Cur * pcur);
|
||||||
void SetConfig(Config * pconfig);
|
void SetConfig(Config * pconfig);
|
||||||
void SetDb(Db * pdb);
|
void SetDb(Db * pdb);
|
||||||
void SetSynchro(Synchro * psynchro);
|
void SetSynchro(Synchro * psynchro);
|
||||||
|
void SetFunctions(Functions * pfunctions);
|
||||||
|
void SetSessionManager(SessionManager * sm);
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
void AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str = true);
|
void AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str = true);
|
||||||
|
|
||||||
void RedirectTo(const Item & item, const wchar_t * postfix = 0);
|
void PutUrlProto(bool can_use_ssl, std::wstring & str, bool clear_str = true);
|
||||||
void RedirectTo(long item_id, const wchar_t * postfix = 0);
|
void RedirectTo(const Item & item, const wchar_t * postfix = 0, bool use_reqtype = true);
|
||||||
void RedirectTo(const std::wstring & url);
|
void RedirectTo(long item_id, const wchar_t * postfix = 0, bool use_reqtype = true);
|
||||||
|
void RedirectTo(const wchar_t * url, bool use_reqtype = true);
|
||||||
|
void RedirectTo(const std::wstring & url, bool use_reqtype = true);
|
||||||
|
void RedirectWithFunctionAndParamsTo(const wchar_t * url);
|
||||||
void RedirectWithFunctionAndParamsTo(const std::wstring & url);
|
void RedirectWithFunctionAndParamsTo(const std::wstring & url);
|
||||||
void RedirectToLastDir();
|
void RedirectToLastDir(const wchar_t * postfix = 0, bool use_reqtype = true);
|
||||||
void RedirectToLastItem(); // redirect to an item if exists or to the last directory
|
void RedirectToLastItem(const wchar_t * postfix = 0, bool use_reqtype = true); // redirect to an item if exists or to the last directory
|
||||||
|
void RedirectToLastFunction(const wchar_t * postfix = 0, bool use_reqtype = true);
|
||||||
|
|
||||||
|
|
||||||
bool CanChangeUser(const Item & item, long new_user_id);
|
bool CanChangeUser(const Item & item, long new_user_id);
|
||||||
bool CanChangeGroup(const Item & item, long new_group_id);
|
bool CanChangeGroup(const Item & item, long new_group_id);
|
||||||
bool CanChangePrivileges(const Item & item, int new_priv);
|
bool CanChangePrivileges(const Item & item, int new_priv);
|
||||||
bool HasAccess(const Item & item, int mask);
|
|
||||||
|
|
||||||
bool HasReadAccess(const Item & item);
|
bool HasReadAccess(const Item & item);
|
||||||
bool HasWriteAccess(const Item & item);
|
bool HasWriteAccess(const Item & item);
|
||||||
bool HasReadWriteAccess(const Item & item);
|
bool HasReadWriteAccess(const Item & item);
|
||||||
@@ -90,6 +144,17 @@ public:
|
|||||||
bool HasReadExecAccessToPath(const std::vector<Item*> & dir_tab);
|
bool HasReadExecAccessToPath(const std::vector<Item*> & dir_tab);
|
||||||
bool DirsHaveReadExecPerm();
|
bool DirsHaveReadExecPerm();
|
||||||
void CheckAccessToItems(std::vector<Item> & item_tab);
|
void CheckAccessToItems(std::vector<Item> & item_tab);
|
||||||
|
void CheckWriteAccessToItems(std::vector<Item> & item_tab);
|
||||||
|
|
||||||
|
/*
|
||||||
|
this method checks the sticky bit and write permissions
|
||||||
|
it returns true if we can remove/rename an item for the given child_item_user_id user id
|
||||||
|
*/
|
||||||
|
bool CanRemoveRenameChild(const Item & dir, long child_item_user_id);
|
||||||
|
|
||||||
|
int NewFilePrivileges();
|
||||||
|
int NewDirPrivileges();
|
||||||
|
|
||||||
|
|
||||||
bool CanUseHtml(long user_id);
|
bool CanUseHtml(long user_id);
|
||||||
bool CanUseBBCode(long user_id);
|
bool CanUseBBCode(long user_id);
|
||||||
@@ -99,17 +164,20 @@ public:
|
|||||||
|
|
||||||
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
|
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
|
||||||
bool CreateNewFile(Item & item);
|
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);
|
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
||||||
|
|
||||||
Error AddFile(Item & item, int notify_code = 0);
|
Error AddFile(Item & item, int notify_code = 0, bool call_plugins = true);
|
||||||
Error EditFile(Item & item, bool with_url = true, int notify_code = 0);
|
Error EditFile(Item & item, bool with_url = true, int notify_code = 0, bool call_plugins = true);
|
||||||
|
|
||||||
|
|
||||||
|
time_t ToLocal(time_t utc_time);
|
||||||
|
PT::Date ToLocal(const PT::Date & utc_date);
|
||||||
|
|
||||||
|
time_t ToUTC(time_t local_time);
|
||||||
|
PT::Date ToUTC(const PT::Date & local_date);
|
||||||
|
|
||||||
// converting GMT time to local time (different for each user)
|
|
||||||
time_t LocalTime(time_t gmt_time);
|
|
||||||
tm LocalTime(const tm * ptm);
|
|
||||||
tm LocalTime(const tm & ptm);
|
|
||||||
|
|
||||||
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
||||||
std::vector<Item*> & out_dir_tab, Item & out_item);
|
std::vector<Item*> & out_dir_tab, Item & out_item);
|
||||||
@@ -127,21 +195,41 @@ public:
|
|||||||
bool FollowAllLinks(const std::wstring & link_to,
|
bool FollowAllLinks(const std::wstring & link_to,
|
||||||
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
|
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
|
||||||
|
|
||||||
|
|
||||||
|
bool AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url, bool overwrite_existing = true);
|
||||||
|
|
||||||
|
// reloading time zones
|
||||||
|
void ReadTimeZones();
|
||||||
|
|
||||||
|
|
||||||
|
void CreateItemLink(long parent_id, const std::wstring & url, const std::wstring & subdomain,
|
||||||
|
std::wstring & link, bool clear_str = true);
|
||||||
|
|
||||||
|
void CreateItemLink(const Item & item, std::wstring & link, bool clear_str = true);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Cur * cur;
|
Cur * cur;
|
||||||
Db * db;
|
Db * db;
|
||||||
Config * config;
|
Config * config;
|
||||||
Synchro * synchro;
|
Synchro * synchro;
|
||||||
|
Functions * functions;
|
||||||
|
SessionManager * session_manager;
|
||||||
|
|
||||||
Item item_temp;
|
Item item_temp;
|
||||||
std::wstring link_to_temp, name_temp;
|
std::wstring link_to_temp, name_temp;
|
||||||
|
std::wstring file_content, file_name;
|
||||||
|
Item file_content_item;
|
||||||
|
|
||||||
// for FollowAllLinks
|
// for FollowAllLinks
|
||||||
std::vector<Item*> temp_follow_dir_tab;
|
std::vector<Item*> temp_follow_dir_tab;
|
||||||
std::vector<Item*> root_follow_dir_tab;
|
std::vector<Item*> root_follow_dir_tab;
|
||||||
Item temp_follow_item;
|
Item temp_follow_item;
|
||||||
|
|
||||||
|
bool HasAccess(const Item & item, int mask);
|
||||||
|
int NewPrivileges(int creation_mask);
|
||||||
|
|
||||||
bool CreateNewFileSimpleFs(Item & item);
|
bool CreateNewFileSimpleFs(Item & item);
|
||||||
bool CreateNewFileHashFs(Item & item);
|
bool CreateNewFileHashFs(Item & item);
|
||||||
|
|
||||||
@@ -153,5 +241,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "textstream.h"
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
+279
-19
@@ -1,17 +1,53 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of Winix
|
* 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, Tomasz Sowa
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||||
* All rights reserved.
|
* 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
|
#ifndef headerfile_winix_core_textstream
|
||||||
#define headerfile_winix_core_textstream
|
#define headerfile_winix_core_textstream
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <ctime>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "space/space.h"
|
||||||
|
#include "date/date.h"
|
||||||
|
#include "textstream/textstream.h"
|
||||||
|
#include "utf8/utf8.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -19,7 +55,17 @@
|
|||||||
similar to std::ostringstream
|
similar to std::ostringstream
|
||||||
|
|
||||||
StringType can be either std::string or std::wstring
|
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>
|
template<class StringType>
|
||||||
class TextStream
|
class TextStream
|
||||||
@@ -37,6 +83,11 @@ public:
|
|||||||
const StringType & Str() const;
|
const StringType & Str() const;
|
||||||
const CharType * CStr() const;
|
const CharType * CStr() const;
|
||||||
|
|
||||||
|
void Str(const StringType & str);
|
||||||
|
void Str(const StringType && str);
|
||||||
|
|
||||||
|
CharType operator[](size_t index);
|
||||||
|
|
||||||
TextStream & operator<<(const char * str);
|
TextStream & operator<<(const char * str);
|
||||||
TextStream & operator<<(const std::string * str);
|
TextStream & operator<<(const std::string * str);
|
||||||
TextStream & operator<<(const std::string & str);
|
TextStream & operator<<(const std::string & str);
|
||||||
@@ -53,16 +104,41 @@ public:
|
|||||||
TextStream & operator<<(unsigned long);
|
TextStream & operator<<(unsigned long);
|
||||||
TextStream & operator<<(double);
|
TextStream & operator<<(double);
|
||||||
TextStream & operator<<(const void *);// printing a pointer
|
TextStream & operator<<(const void *);// printing a pointer
|
||||||
|
TextStream & operator<<(const PT::Space & space);
|
||||||
|
TextStream & operator<<(const PT::Date & date);
|
||||||
|
|
||||||
|
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 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);
|
TextStream & write(const wchar_t * buf, size_t len);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
StringType buffer;
|
StringType buffer;
|
||||||
|
|
||||||
|
void Convert(wchar_t c, std::string & dst);
|
||||||
|
void Convert(wchar_t c, std::wstring & dst);
|
||||||
|
|
||||||
|
void Convert(const char * src, size_t len, std::wstring & dst);
|
||||||
|
void Convert(const char * src, std::wstring & dst);
|
||||||
|
void Convert(const std::string & src, std::wstring & dst);
|
||||||
|
|
||||||
|
void Convert(const wchar_t * src, size_t len, std::string & dst);
|
||||||
|
void Convert(const wchar_t * src, std::string & dst);
|
||||||
|
void Convert(const std::wstring & src, std::string & dst);
|
||||||
|
|
||||||
|
void Convert(const char * src, size_t len, std::string & dst);
|
||||||
|
void Convert(const char * src, std::string & dst);
|
||||||
|
void Convert(const std::string & src, std::string & dst);
|
||||||
|
|
||||||
|
void Convert(const wchar_t * src, size_t len, std::wstring & dst);
|
||||||
|
void Convert(const wchar_t * src, std::wstring & dst);
|
||||||
|
void Convert(const std::wstring & src, std::wstring & dst);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -106,11 +182,33 @@ const typename TextStream<StringType>::CharType * TextStream<StringType>::CStr()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
void TextStream<StringType>::Str(const StringType & str)
|
||||||
|
{
|
||||||
|
buffer = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
void TextStream<StringType>::Str(const StringType && str)
|
||||||
|
{
|
||||||
|
buffer = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
typename TextStream<StringType>::CharType TextStream<StringType>::operator[](size_t index)
|
||||||
|
{
|
||||||
|
return buffer[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const char * str)
|
TextStream<StringType> & TextStream<StringType>::operator<<(const char * str)
|
||||||
{
|
{
|
||||||
AssignString(str, buffer, false);
|
Convert(str, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -119,7 +217,7 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
|
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
|
||||||
{
|
{
|
||||||
AssignString(*str, buffer, false);
|
Convert(*str, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -128,7 +226,7 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
|
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
|
||||||
{
|
{
|
||||||
AssignString(str, buffer, false);
|
Convert(str, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -138,7 +236,7 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
|
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
|
||||||
{
|
{
|
||||||
AssignString(str, buffer, false);
|
Convert(str, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -147,7 +245,7 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
|
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
|
||||||
{
|
{
|
||||||
AssignString(*str, buffer, false);
|
Convert(*str, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -156,7 +254,7 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
|
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
|
||||||
{
|
{
|
||||||
AssignString(str, buffer, false);
|
Convert(str, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -166,6 +264,10 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(char v)
|
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;
|
buffer += v;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@@ -175,7 +277,7 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
|
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
|
||||||
{
|
{
|
||||||
buffer += static_cast<CharType>(v);
|
Convert(v, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -188,7 +290,7 @@ wchar_t buf[50];
|
|||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||||
|
|
||||||
Toa(v, buf, len);
|
Toa(v, buf, len);
|
||||||
AssignString(buf, buffer, false);
|
Convert(buf, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -201,7 +303,7 @@ wchar_t buf[50];
|
|||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||||
|
|
||||||
Toa(v, buf, len);
|
Toa(v, buf, len);
|
||||||
AssignString(buf, buffer, false);
|
Convert(buf, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -214,7 +316,7 @@ wchar_t buf[50];
|
|||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||||
|
|
||||||
Toa(v, buf, len);
|
Toa(v, buf, len);
|
||||||
AssignString(buf, buffer, false);
|
Convert(buf, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -227,7 +329,7 @@ wchar_t buf[50];
|
|||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
size_t len = sizeof(buf) / sizeof(wchar_t);
|
||||||
|
|
||||||
Toa(v, buf, len);
|
Toa(v, buf, len);
|
||||||
AssignString(buf, buffer, false);
|
Convert(buf, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -239,7 +341,7 @@ TextStream<StringType> & TextStream<StringType>::operator<<(double v)
|
|||||||
char buf[50];
|
char buf[50];
|
||||||
|
|
||||||
sprintf(buf, "%f", v);
|
sprintf(buf, "%f", v);
|
||||||
AssignString(buf, buffer, false);
|
Convert(buf, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -255,7 +357,7 @@ size_t len = sizeof(buf) / sizeof(wchar_t);
|
|||||||
buf[1] = 'x';
|
buf[1] = 'x';
|
||||||
|
|
||||||
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
|
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
|
||||||
AssignString(buf, buffer, false);
|
Convert(buf, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -264,7 +366,7 @@ return *this;
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
|
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
|
||||||
{
|
{
|
||||||
AssignString(buf, len, buffer, false);
|
Convert(buf, len, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -280,7 +382,7 @@ TextStream<StringType> & TextStream<StringType>::write(const char * buf, size_t
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
|
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
AssignString(buf, len, buffer, false);
|
Convert(buf, len, buffer);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -292,5 +394,163 @@ TextStream<StringType> & TextStream<StringType>::write(const wchar_t * buf, size
|
|||||||
return Write(buf, len);
|
return Write(buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Space & space)
|
||||||
|
{
|
||||||
|
space.Serialize(*this, true, false);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Date & date)
|
||||||
|
{
|
||||||
|
date.Serialize(*this);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||||
|
TextStream<StringType> & TextStream<StringType>::operator<<(
|
||||||
|
const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
|
||||||
|
{
|
||||||
|
typename PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
||||||
|
|
||||||
|
for(i=arg.begin() ; i != arg.end() ; ++i)
|
||||||
|
buffer += static_cast<char_type>(*i);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
void TextStream<StringType>::Convert(wchar_t c, std::string & dst)
|
||||||
|
{
|
||||||
|
PT::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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Executable
+170
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include "threadmanager.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ThreadManager::ThreadManager()
|
||||||
|
{
|
||||||
|
were_started = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::SetSynchro(Synchro * psynchro)
|
||||||
|
{
|
||||||
|
synchro = psynchro;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::Init()
|
||||||
|
{
|
||||||
|
sigset_t set;
|
||||||
|
|
||||||
|
sigemptyset(&set);
|
||||||
|
sigaddset(&set, SIGTERM);
|
||||||
|
sigaddset(&set, SIGINT);
|
||||||
|
|
||||||
|
// blocking SIGTERM and SIGINT
|
||||||
|
// new threads will have the signals blocked too
|
||||||
|
pthread_sigmask(SIG_BLOCK, &set, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
||||||
|
{
|
||||||
|
ThreadItem item;
|
||||||
|
|
||||||
|
item.object = pbase;
|
||||||
|
item.name = thread_name;
|
||||||
|
thread_tab.push_back(item);
|
||||||
|
|
||||||
|
if( were_started )
|
||||||
|
Start(thread_tab.size() - 1);
|
||||||
|
else
|
||||||
|
log << log4 << "TM: added a thread to the queue, number: " << (thread_tab.size()-1)
|
||||||
|
<< ", name: " << thread_name << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::Add(BaseThread & pbase, const wchar_t * thread_name)
|
||||||
|
{
|
||||||
|
Add(&pbase, thread_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::Add(BaseThread * pbase, const std::wstring & thread_name)
|
||||||
|
{
|
||||||
|
Add(pbase, thread_name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadManager::Add(BaseThread & pbase, const std::wstring & thread_name)
|
||||||
|
{
|
||||||
|
Add(&pbase, thread_name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::StartAll()
|
||||||
|
{
|
||||||
|
synchro->Lock();
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||||
|
Start(i);
|
||||||
|
|
||||||
|
synchro->Unlock();
|
||||||
|
|
||||||
|
were_started = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::Start(size_t i)
|
||||||
|
{
|
||||||
|
if( i < thread_tab.size() )
|
||||||
|
{
|
||||||
|
thread_tab[i].object->SetSynchro(synchro);
|
||||||
|
|
||||||
|
if( thread_tab[i].object->StartThread() )
|
||||||
|
{
|
||||||
|
log << log4 << "TM: thread " << i << " (" << thread_tab[i].object->ThreadId() << ", name: "
|
||||||
|
<< thread_tab[i].name << ") started" << logend;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log4 << "TM: cannot run a thread, thread number: " << i
|
||||||
|
<< ", name: " << thread_tab[i].name << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ThreadManager::StopAll()
|
||||||
|
{
|
||||||
|
if( !were_started )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// WakeUpThread() should be used with Lock/Unlock
|
||||||
|
synchro->Lock();
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||||
|
thread_tab[i].object->WakeUpThread();
|
||||||
|
|
||||||
|
synchro->Unlock();
|
||||||
|
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
||||||
|
{
|
||||||
|
log << log4 << "TM: waiting for thread " << i << " (" << thread_tab[i].object->ThreadId()
|
||||||
|
<< ", name: " << thread_tab[i].name << ")" << logend;
|
||||||
|
|
||||||
|
thread_tab[i].object->WaitForThread();
|
||||||
|
|
||||||
|
log << log4 << "TM: thread " << i << " terminated" << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
Executable
+99
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winix_core_threadmanager
|
||||||
|
#define headerfile_winix_core_threadmanager
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "basethread.h"
|
||||||
|
#include "synchro.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ThreadManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
ThreadManager();
|
||||||
|
|
||||||
|
// synchro object
|
||||||
|
void SetSynchro(Synchro * psynchro);
|
||||||
|
|
||||||
|
// initializing
|
||||||
|
void Init();
|
||||||
|
|
||||||
|
// adding a new thread to the queue
|
||||||
|
// the thread will be running only if we call StartAll() before
|
||||||
|
// otherwise the thread will be waiting for StartAll()
|
||||||
|
void Add(BaseThread * pbase, const wchar_t * thread_name);
|
||||||
|
void Add(BaseThread & pbase, const wchar_t * thread_name);
|
||||||
|
void Add(BaseThread * pbase, const std::wstring & thread_name);
|
||||||
|
void Add(BaseThread & pbase, const std::wstring & thread_name);
|
||||||
|
|
||||||
|
// starting all threads
|
||||||
|
void StartAll();
|
||||||
|
|
||||||
|
// sending a stop signal to all threads
|
||||||
|
// and waiting until they finish
|
||||||
|
void StopAll();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct ThreadItem
|
||||||
|
{
|
||||||
|
BaseThread * object;
|
||||||
|
std::wstring name;
|
||||||
|
};
|
||||||
|
|
||||||
|
Synchro * synchro;
|
||||||
|
typedef std::vector<ThreadItem> ThreadTab;
|
||||||
|
ThreadTab thread_tab;
|
||||||
|
bool were_started;
|
||||||
|
|
||||||
|
void Start(size_t i);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
-309
@@ -1,309 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include "thumb.h"
|
|
||||||
#include "utf8.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "system.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Thumb::SetDb(Db * pdb)
|
|
||||||
{
|
|
||||||
db = pdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Thumb::SetConfig(Config * pconfig)
|
|
||||||
{
|
|
||||||
config = pconfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Thumb::SetSystem(System * psystem)
|
|
||||||
{
|
|
||||||
system = psystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// first thread (objects locked)
|
|
||||||
void Thumb::CreateThumb(const Item & item, size_t cx, size_t cy, int aspect_mode)
|
|
||||||
{
|
|
||||||
item_temp.file = item;
|
|
||||||
item_temp.cx = cx;
|
|
||||||
item_temp.cy = cy;
|
|
||||||
item_temp.aspect_mode = aspect_mode;
|
|
||||||
|
|
||||||
thumb_tab.insert(thumb_tab.end(), item_temp);
|
|
||||||
WakeUpThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects locked)
|
|
||||||
bool Thumb::SignalReceived()
|
|
||||||
{
|
|
||||||
return !thumb_tab.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked)
|
|
||||||
void Thumb::Do()
|
|
||||||
{
|
|
||||||
ThumbTab::iterator i;
|
|
||||||
bool end;
|
|
||||||
|
|
||||||
Lock();
|
|
||||||
i = thumb_tab.begin();
|
|
||||||
Unlock();
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Lock();
|
|
||||||
|
|
||||||
if( i != thumb_tab.end() )
|
|
||||||
{
|
|
||||||
item_work = *i;
|
|
||||||
thumb_tab.erase(i++);
|
|
||||||
end = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
end = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Unlock();
|
|
||||||
|
|
||||||
if( !end )
|
|
||||||
CreateThumbnail();
|
|
||||||
|
|
||||||
}
|
|
||||||
while( !end && !IsExitSignal() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Thumb::EscapePath(const std::string & path)
|
|
||||||
{
|
|
||||||
command << '"';
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<path.size() ; ++i)
|
|
||||||
{
|
|
||||||
if( path[i] == '"' )
|
|
||||||
command << '\\';
|
|
||||||
|
|
||||||
command << path[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
command << "\" ";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
from: http://www.imagemagick.org/script/command-line-processing.php#geometry
|
|
||||||
|
|
||||||
scale% Height and width both scaled by specified percentage.
|
|
||||||
scale-x%xscale-y% Height and width individually scaled by specified percentages. (Only one % symbol needed.)
|
|
||||||
width Width given, height automagically selected to preserve aspect ratio.
|
|
||||||
xheight Height given, width automagically selected to preserve aspect ratio.
|
|
||||||
widthxheight Maximum values of height and width given, aspect ratio preserved.
|
|
||||||
widthxheight^ Minimum values of width and height given, aspect ratio preserved.
|
|
||||||
widthxheight! Width and height emphatically given, original aspect ratio ignored.
|
|
||||||
widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension.
|
|
||||||
widthxheight< Change dimensions only if both image dimensions exceed specified dimensions.
|
|
||||||
*/
|
|
||||||
void Thumb::SelectAspect()
|
|
||||||
{
|
|
||||||
switch( item_work.aspect_mode )
|
|
||||||
{
|
|
||||||
case WINIX_THUMB_MODE_1:
|
|
||||||
command << item_work.cx;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WINIX_THUMB_MODE_3:
|
|
||||||
command << item_work.cx << "x" << item_work.cy;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WINIX_THUMB_MODE_4:
|
|
||||||
command << '"' << item_work.cx << "x" << item_work.cy << "^\"";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WINIX_THUMB_MODE_5:
|
|
||||||
command << '"' << item_work.cx << "x" << item_work.cy << "!\"";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WINIX_THUMB_MODE_6:
|
|
||||||
command << '"' << item_work.cx << "x" << item_work.cy << ">\"";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WINIX_THUMB_MODE_7:
|
|
||||||
command << '"' << item_work.cx << "x" << item_work.cy << "<\"";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WINIX_THUMB_MODE_2:
|
|
||||||
default:
|
|
||||||
command << "x" << item_work.cy;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects are not locked)
|
|
||||||
bool Thumb::CreateCommand()
|
|
||||||
{
|
|
||||||
bool res;
|
|
||||||
|
|
||||||
command.Clear();
|
|
||||||
stream_tmp_path.Clear();
|
|
||||||
|
|
||||||
Lock();
|
|
||||||
|
|
||||||
Ezc::WideToUTF8(config->convert_cmd, tempa);
|
|
||||||
command << tempa << " -quiet -strip -thumbnail ";
|
|
||||||
SelectAspect();
|
|
||||||
command << " ";
|
|
||||||
|
|
||||||
if( system->MakeFilePath(item_work.file, src_path) )
|
|
||||||
{
|
|
||||||
Ezc::WideToUTF8(src_path, tempa);
|
|
||||||
EscapePath(tempa);
|
|
||||||
|
|
||||||
stream_tmp_path << config->upload_dir << L"/tmp/thumb_" << std::time(0);
|
|
||||||
Ezc::WideToUTF8(stream_tmp_path.Str(), string_tmp_patha);
|
|
||||||
EscapePath(string_tmp_patha);
|
|
||||||
|
|
||||||
res = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Thumb: cannot create a source path" << logend;
|
|
||||||
res = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Unlock();
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects are not locked)
|
|
||||||
void Thumb::SaveTmpThumbnail()
|
|
||||||
{
|
|
||||||
bool moved = false;
|
|
||||||
|
|
||||||
Lock();
|
|
||||||
|
|
||||||
// the file could have been changed especially when creating thumbnail lasted too long
|
|
||||||
iq.SetAll(false, false);
|
|
||||||
iq.sel_parent_id = true;
|
|
||||||
iq.sel_file = true;
|
|
||||||
iq.sel_url = true;
|
|
||||||
iq.sel_type = true;
|
|
||||||
iq.WhereId(item_work.file.id);
|
|
||||||
|
|
||||||
if( db->GetItem(item_work.file, iq) == WINIX_ERR_OK )
|
|
||||||
{
|
|
||||||
if( system->MakeFilePath(item_work.file, dst_path, true, true, config->upload_dirs_chmod) )
|
|
||||||
{
|
|
||||||
if( RenameFile(stream_tmp_path.Str(), dst_path) )
|
|
||||||
{
|
|
||||||
log << log3 << "Thumb: created a thumbnail: " << dst_path << logend;
|
|
||||||
db->EditHasThumbById(true, item_work.file.id);
|
|
||||||
moved = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Thumb: cannot move a temporary file: " << stream_tmp_path.Str() << ", to: " << dst_path << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Thumb: cannot create a destination path" << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !moved )
|
|
||||||
::RemoveFile(stream_tmp_path.Str());
|
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects are not locked)
|
|
||||||
void Thumb::CreateThumbnail()
|
|
||||||
{
|
|
||||||
if( !CreateCommand() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
int res = std::system(command.CStr());
|
|
||||||
|
|
||||||
if( res == 0 )
|
|
||||||
{
|
|
||||||
SaveTmpThumbnail();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Lock();
|
|
||||||
log << log3 << "Thumb: some problems with creating a thumbnail " << tempa
|
|
||||||
<< ", 'convert' process returned: " << res << logend;
|
|
||||||
Unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects are not locked)
|
|
||||||
// !! there is a problem with GIF files
|
|
||||||
// Bus error (core dumped)
|
|
||||||
/*
|
|
||||||
#include "wand/MagickWand.h"
|
|
||||||
|
|
||||||
// compiler options:
|
|
||||||
// include: -I/usr/local/include/ImageMagick
|
|
||||||
// link with: `MagickWand-config --ldflags --libs`
|
|
||||||
|
|
||||||
void Thumb::CreateThumbnail()
|
|
||||||
{
|
|
||||||
Ezc::WideToUTF8(item_work.source, sourcea);
|
|
||||||
Ezc::WideToUTF8(item_work.dst, dsta);
|
|
||||||
|
|
||||||
MagickWandGenesis();
|
|
||||||
|
|
||||||
MagickWand * wand = NewMagickWand();
|
|
||||||
|
|
||||||
if( MagickReadImage(wand, sourcea.c_str()) )
|
|
||||||
{
|
|
||||||
MagickThumbnailImage(wand, item_work.cx, item_work.cy);
|
|
||||||
|
|
||||||
if( MagickWriteImage(wand, dsta.c_str()) )
|
|
||||||
{
|
|
||||||
Lock();
|
|
||||||
log << log3 << "Thumb: created a thumbnail: " << dsta << logend;
|
|
||||||
Unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DestroyMagickWand(wand);
|
|
||||||
|
|
||||||
MagickWandTerminus();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_thumb
|
|
||||||
#define headerfile_winix_core_thumb
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
#include "basethread.h"
|
|
||||||
#include "textstream.h"
|
|
||||||
#include "db/db.h"
|
|
||||||
#include "core/item.h"
|
|
||||||
#include "core/config.h"
|
|
||||||
|
|
||||||
|
|
||||||
class System;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Width given, height automagically selected to preserve aspect ratio.
|
|
||||||
#define WINIX_THUMB_MODE_1 1
|
|
||||||
|
|
||||||
// Height given, width automagically selected to preserve aspect ratio.
|
|
||||||
#define WINIX_THUMB_MODE_2 2
|
|
||||||
|
|
||||||
// Maximum values of height and width given, aspect ratio preserved.
|
|
||||||
#define WINIX_THUMB_MODE_3 3
|
|
||||||
|
|
||||||
// Minimum values of width and height given, aspect ratio preserved.
|
|
||||||
#define WINIX_THUMB_MODE_4 4
|
|
||||||
|
|
||||||
// Width and height emphatically given, original aspect ratio ignored.
|
|
||||||
#define WINIX_THUMB_MODE_5 5
|
|
||||||
|
|
||||||
// Change as per widthxheight but only if an image dimension exceeds a specified dimension.
|
|
||||||
#define WINIX_THUMB_MODE_6 6
|
|
||||||
|
|
||||||
// Change dimensions only if both image dimensions are less than specified dimensions.
|
|
||||||
#define WINIX_THUMB_MODE_7 7
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Thumb : public BaseThread
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
void CreateThumb(const Item & item, size_t cx, size_t cy, int aspect_mode);
|
|
||||||
|
|
||||||
void SetDb(Db * pdb);
|
|
||||||
void SetConfig(Config * pconfig);
|
|
||||||
void SetSystem(System * psystem);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Db * db;
|
|
||||||
Config * config;
|
|
||||||
System * system;
|
|
||||||
|
|
||||||
struct ThumbItem
|
|
||||||
{
|
|
||||||
Item file;
|
|
||||||
size_t cx;
|
|
||||||
size_t cy;
|
|
||||||
int aspect_mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
// queue of thumbnails to create
|
|
||||||
typedef std::list<ThumbItem> ThumbTab;
|
|
||||||
ThumbTab thumb_tab;
|
|
||||||
ThumbItem item_temp;
|
|
||||||
|
|
||||||
// only for second thread
|
|
||||||
ThumbItem item_work;
|
|
||||||
std::wstring src_path, dst_path;
|
|
||||||
std::string tempa, string_tmp_patha;
|
|
||||||
TextStream<std::string> command;
|
|
||||||
TextStream<std::wstring> stream_tmp_path;
|
|
||||||
DbItemQuery iq;
|
|
||||||
|
|
||||||
virtual bool SignalReceived();
|
|
||||||
virtual void Do();
|
|
||||||
bool CreateCommand();
|
|
||||||
void SaveTmpThumbnail();
|
|
||||||
void CreateThumbnail();
|
|
||||||
void SelectAspect();
|
|
||||||
void EscapePath(const std::string & path);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,322 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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 "timezone.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TimeZone::Dst::Dst()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TimeZone::Dst::Clear()
|
||||||
|
{
|
||||||
|
has_dst = false;
|
||||||
|
start.Clear();
|
||||||
|
end.Clear();
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TimeZone::Dst::IsDstUsed(const PT::Date & date) const
|
||||||
|
{
|
||||||
|
if( !has_dst )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( Compare(start, date) <= 0 ) // !! CHECK ME <= or < ? (what about the one second?)
|
||||||
|
if( Compare(date, end) < 0 )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TimeZone::Dst::Compare(const PT::Date & date1, const PT::Date & date2) const
|
||||||
|
{
|
||||||
|
// year is ignored
|
||||||
|
|
||||||
|
if( date1.month != date2.month )
|
||||||
|
return date1.month - date2.month;
|
||||||
|
|
||||||
|
if( date1.day != date2.day )
|
||||||
|
return date1.day - date2.day;
|
||||||
|
|
||||||
|
if( date1.hour != date2.hour )
|
||||||
|
return date1.hour - date2.hour;
|
||||||
|
|
||||||
|
if( date1.min != date2.min )
|
||||||
|
return date1.min - date2.min;
|
||||||
|
|
||||||
|
if( date1.sec != date2.sec )
|
||||||
|
return date1.sec - date2.sec;
|
||||||
|
|
||||||
|
// dates are equal
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TimeZone::TimeZone()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TimeZone::Clear()
|
||||||
|
{
|
||||||
|
name.clear();
|
||||||
|
id = 0;
|
||||||
|
offset = 0;
|
||||||
|
dst_map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TimeZone::Dst * TimeZone::FindDst(int year)
|
||||||
|
{
|
||||||
|
if( dst_map.empty() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
DstMap::iterator i = dst_map.lower_bound(year);
|
||||||
|
|
||||||
|
if( i == dst_map.begin() && i->first > year )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if( i == dst_map.end() )
|
||||||
|
return &(--i)->second;
|
||||||
|
|
||||||
|
if( i != dst_map.begin() && i->first > year )
|
||||||
|
return &(--i)->second;
|
||||||
|
|
||||||
|
return &i->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
time_t TimeZone::CalcLocalOffset(const PT::Date & utc_date)
|
||||||
|
{
|
||||||
|
time_t dst_offset = 0;
|
||||||
|
|
||||||
|
Dst * dst = FindDst(utc_date.year);
|
||||||
|
|
||||||
|
if( dst && dst->IsDstUsed(utc_date) )
|
||||||
|
dst_offset = dst->offset;
|
||||||
|
|
||||||
|
return offset + dst_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
time_t TimeZone::ToLocal(time_t utc_time)
|
||||||
|
{
|
||||||
|
time_t offset = CalcLocalOffset(PT::Date(utc_time));
|
||||||
|
|
||||||
|
return utc_time + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PT::Date TimeZone::ToLocal(const PT::Date & utc_date)
|
||||||
|
{
|
||||||
|
PT::Date local(utc_date);
|
||||||
|
local += CalcLocalOffset(utc_date);
|
||||||
|
|
||||||
|
return local;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
time_t TimeZone::CalcUTCOffset(const PT::Date & local_date)
|
||||||
|
{
|
||||||
|
time_t dst_offset = 0;
|
||||||
|
|
||||||
|
Dst * dst = FindDst(local_date.year);
|
||||||
|
|
||||||
|
if( dst && dst->has_dst )
|
||||||
|
{
|
||||||
|
// dst date ranges we have in UTC
|
||||||
|
PT::Date utc(local_date);
|
||||||
|
utc -= (offset + dst->offset);
|
||||||
|
|
||||||
|
if( dst->IsDstUsed(utc) )
|
||||||
|
dst_offset = dst->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset + dst_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
time_t TimeZone::ToUTC(time_t local_time)
|
||||||
|
{
|
||||||
|
time_t offset = CalcUTCOffset(PT::Date(local_time));
|
||||||
|
|
||||||
|
return local_time - offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PT::Date TimeZone::ToUTC(const PT::Date & local_date)
|
||||||
|
{
|
||||||
|
time_t offset;
|
||||||
|
PT::Date utc(local_date);
|
||||||
|
|
||||||
|
offset = CalcUTCOffset(local_date);
|
||||||
|
utc -= offset;
|
||||||
|
|
||||||
|
return utc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
time_t TimeZone::ParseStrOffset(const wchar_t * str)
|
||||||
|
{
|
||||||
|
PT::Date date;
|
||||||
|
bool is_sign = false;
|
||||||
|
time_t offset = 0;
|
||||||
|
|
||||||
|
str = SkipWhite(str);
|
||||||
|
|
||||||
|
if( *str == '-' )
|
||||||
|
{
|
||||||
|
is_sign = true;
|
||||||
|
str += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( *str == '+' )
|
||||||
|
{
|
||||||
|
str += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( date.ParseTime(str) )
|
||||||
|
{
|
||||||
|
offset = date.hour * 60 * 60 + date.min * 60 + date.sec;
|
||||||
|
|
||||||
|
if( is_sign )
|
||||||
|
offset = -offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
time_t TimeZone::GetOffset(PT::Space & space)
|
||||||
|
{
|
||||||
|
std::wstring * offset_str = space.GetValue(L"offset_str");
|
||||||
|
|
||||||
|
if( offset_str )
|
||||||
|
return ParseStrOffset(offset_str->c_str());
|
||||||
|
|
||||||
|
return space.Long(L"offset");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TimeZone::SetTzDst(PT::Space & year)
|
||||||
|
{
|
||||||
|
time_t h24 = 60 * 60 * 24; // 24 hours
|
||||||
|
bool result = true;
|
||||||
|
Dst dst;
|
||||||
|
|
||||||
|
int year_int = Toi(year.name);
|
||||||
|
|
||||||
|
if( year_int < 1970 && year_int > 10000 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dst.has_dst = year.Bool(L"has_dst", false);
|
||||||
|
|
||||||
|
if( dst.has_dst )
|
||||||
|
{
|
||||||
|
dst.start.year = year_int;
|
||||||
|
dst.end.year = year_int;
|
||||||
|
|
||||||
|
if( !dst.start.ParseMonthDayTime(year.Text(L"start")) )
|
||||||
|
result = false;
|
||||||
|
|
||||||
|
if( !dst.end.ParseMonthDayTime(year.Text(L"end")) )
|
||||||
|
result = false;
|
||||||
|
|
||||||
|
dst.offset = GetOffset(year);
|
||||||
|
|
||||||
|
if( dst.offset < -h24 || dst.offset > h24 )
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( result )
|
||||||
|
dst_map[year_int] = dst;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TimeZone::SetTz(PT::Space & space)
|
||||||
|
{
|
||||||
|
bool result = true;
|
||||||
|
name = space.name;
|
||||||
|
id = space.Int(L"id", -1);
|
||||||
|
offset = GetOffset(space);
|
||||||
|
time_t h24 = 60 * 60 * 24; // 24 hours
|
||||||
|
|
||||||
|
if( offset < -h24 || offset > h24 )
|
||||||
|
result = false;
|
||||||
|
|
||||||
|
PT::Space & dst = space.FindAddSpace(L"dst");
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<dst.spaces.size() ; ++i)
|
||||||
|
{
|
||||||
|
PT::Space & year = *dst.spaces[i];
|
||||||
|
|
||||||
|
if( !SetTzDst(year) )
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
+170
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* 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) 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_timezone
|
||||||
|
#define headerfile_winix_core_timezone
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <map>
|
||||||
|
#include "date/date.h"
|
||||||
|
#include "space/space.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TimeZone
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
struct Dst
|
||||||
|
{
|
||||||
|
// true if a time zone has daylight saving time
|
||||||
|
bool has_dst;
|
||||||
|
|
||||||
|
// time zone daylight saving time (used if has_dst is true)
|
||||||
|
// the 'year' field is the same in 'start' and 'end'
|
||||||
|
// start and end are represented in UTC time
|
||||||
|
PT::Date start, end;
|
||||||
|
|
||||||
|
// time zone daylight saving time offset
|
||||||
|
// used when has_dst is true and the date is whithin start and end
|
||||||
|
// this offset should be added to time zone offset
|
||||||
|
time_t offset;
|
||||||
|
|
||||||
|
Dst();
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
// checking whether specified 'date' is in the range of <start, end>
|
||||||
|
// the year field in date, start and end is ignored
|
||||||
|
// has_dst must be true
|
||||||
|
bool IsDstUsed(const PT::Date & date) const;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// Compare returns zero if date1 and date2 are equal
|
||||||
|
// return value less than zero if date1 is lower than date2
|
||||||
|
// and a value greater than zero if date1 is greater than date2
|
||||||
|
// the year field is ignored
|
||||||
|
int Compare(const PT::Date & date1, const PT::Date & date2) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TimeZone();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
reading zime zone values from Space struct (tz_id is skipped)
|
||||||
|
the space struct should have:
|
||||||
|
"tz_offset" (long)
|
||||||
|
"tz_has_dst" (bool)
|
||||||
|
if tz_has_dst is true then also:
|
||||||
|
"tz_dst_start" date in the following format: MM:DD HH[:MM[:SS]]
|
||||||
|
"tz_dst_end" the same as above
|
||||||
|
"tz_dst_offset" (long)
|
||||||
|
*/
|
||||||
|
bool SetTz(PT::Space & space);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
converting from UTC to local time
|
||||||
|
*/
|
||||||
|
time_t CalcLocalOffset(const PT::Date & utc_date);
|
||||||
|
time_t ToLocal(time_t utc_time);
|
||||||
|
PT::Date ToLocal(const PT::Date & utc_date);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
converting from local time to UTC
|
||||||
|
*/
|
||||||
|
time_t CalcUTCOffset(const PT::Date & local_date);
|
||||||
|
time_t ToUTC(time_t local_time);
|
||||||
|
PT::Date ToUTC(const PT::Date & local_date);
|
||||||
|
|
||||||
|
// return a Dst structure for the specified year
|
||||||
|
// or null if it not exists
|
||||||
|
// this method can return a Dst structure for earlier year than 'year'
|
||||||
|
// if 'year' doesn't exist
|
||||||
|
Dst * FindDst(int year);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// a time zone name
|
||||||
|
// this is a key to locale
|
||||||
|
std::wstring name;
|
||||||
|
|
||||||
|
// each locale has its own identifier
|
||||||
|
size_t id;
|
||||||
|
|
||||||
|
// time zone offset (in seconds)
|
||||||
|
time_t offset;
|
||||||
|
|
||||||
|
// daylight saving time map
|
||||||
|
// year -> Dst
|
||||||
|
// if there is not a specified year we are taking the lower year, e.g.
|
||||||
|
// if we are looking for 2010 and there is no such a year then we take 2009
|
||||||
|
// (or 2008 if 2009 not exists etc)
|
||||||
|
typedef std::map<int, Dst> DstMap;
|
||||||
|
DstMap dst_map;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
time_t ParseStrOffset(const wchar_t * str);
|
||||||
|
time_t GetOffset(PT::Space & space);
|
||||||
|
bool SetTzDst(PT::Space & year);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user