Compare commits
491 Commits
0.2.0
...
f6077da614
| Author | SHA1 | Date | |
|---|---|---|---|
| f6077da614 | |||
| 499db7e3eb | |||
| 50da49a3ed | |||
| 6afd5c637e | |||
| 31a6aac9d3 | |||
| 3c3660914f | |||
| cd0ae231dc | |||
| a8bc741883 | |||
| 05b3525863 | |||
| 337f563bd4 | |||
| c9fe09ebe3 | |||
| db1c63a350 | |||
| 7cc2dcd1fc | |||
| bcde392ce3 | |||
| 8d046f6280 | |||
| 9a6696699f | |||
| 56f2eec597 | |||
| d29b33532d | |||
| a16e82bf54 | |||
| 46c17cc441 | |||
| 2099092e16 | |||
| 88b7517337 | |||
| 619236329c | |||
| 76160a5ba6 | |||
| e95f32231a | |||
| be81307faa | |||
| 177e58da4e | |||
| 4c2efc08fd | |||
| ae03922491 | |||
| ab005118ba | |||
| eec8635af4 | |||
| 5060997d2a | |||
| 0ac5a21a14 | |||
| def0f8d144 | |||
| 8895f0dcac | |||
| 4f8db81c85 | |||
| aa388e248d | |||
| e5d7403c54 | |||
| 4f57d6134c | |||
| 03f6b54a5b | |||
| 63ef007ca1 | |||
| 603e0679e7 | |||
| b90445de4a | |||
| 491dd27ebf | |||
| 89d303f375 | |||
| a2ffc1e81c | |||
| a7c47140ae | |||
| ebd7f85fdb | |||
| 833c04776f | |||
| 919c2f62f5 | |||
| 8f6004d444 | |||
| 1b8f5dc673 | |||
| 027a8ec428 | |||
| d1e7765e98 | |||
| 2d1b2e6b6e | |||
| 350fc551e5 | |||
| 1c05c31721 | |||
| 08123fe6ac | |||
| 35b93b1655 | |||
| 436a198c36 | |||
| aa58faf145 | |||
| dcc6d35cba | |||
| 3f29cdc01e | |||
| ba7d55b7c1 | |||
| 6252a0e732 | |||
| ca14b1a427 | |||
| b01db89942 | |||
| fd421c54e3 | |||
| 55992b5066 | |||
| a5dfc9974f | |||
| 7b4a17c934 | |||
| c2a1097dd5 | |||
| ccf78dcb02 | |||
| 3eff400d88 | |||
| 5ab816b5be | |||
| e57840faed | |||
| 240bf4dc5d | |||
| abd1500f07 | |||
| 42144bb31c | |||
| 7ed41a03ae | |||
| 1286ceeddf | |||
| 145efe937c | |||
| ed5adb3f23 | |||
| 7d0508961e | |||
| e53e2e6af9 | |||
| 4fafd2a478 | |||
| f15da4d049 | |||
| 057607f9e5 | |||
| c433b3fd41 | |||
| 632b49ab90 | |||
| f54df8d600 | |||
| d8451ceaa0 | |||
| 62f178c2ee | |||
| eb4e7343e7 | |||
| 5274e8e8ff | |||
| ae2a885d6c | |||
| 901663b145 | |||
| dc301d4c50 | |||
| 34f0535a26 | |||
| af0e2a778d | |||
| 904f1e70f2 | |||
| ddf7ef30ad | |||
| 0a43870e76 | |||
| f875bd2944 | |||
| c9bf20201b | |||
| 76314aab10 | |||
| 3547d326b8 | |||
| 0ecb2ac70e | |||
| 8f8defe0de | |||
| db5572e864 | |||
| 1100cf75d7 | |||
| 4fda06b547 | |||
| fb18b2238e | |||
| 5266a7e4e5 | |||
| 8196fb77d1 | |||
| 4abf6642f7 | |||
| e3284dcfbc | |||
| f064ff6b3d | |||
| bfa5d8cc05 | |||
| 6614919c13 | |||
| 8379acdb7f | |||
| 160ddc258d | |||
| 01892d2766 | |||
| 222955a2e7 | |||
| 37b22c3559 | |||
| afbd522362 | |||
| a4bed3ab14 | |||
| 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 | |||
| 18ecd46a01 | |||
| af8fbdae72 | |||
| c84997be30 | |||
| 06551d6084 | |||
| 84145d7cc8 | |||
| 426beae796 | |||
| aadf12c7b3 | |||
| 1b60935d08 | |||
| d68731fd55 | |||
| ba63c8c661 | |||
| 15487b347f | |||
| e7e90c6527 | |||
| ca5421347a | |||
| c8a57f2046 | |||
| 583df13139 | |||
| 5049961e17 | |||
| 18492e5d61 | |||
| d4d9f89d1d | |||
| ecf19034ae | |||
| 00521c490e | |||
| 3071df227a | |||
| 915cabdf97 | |||
| 61ac29b2de | |||
| ab84a5169e | |||
| 3fad25b8c8 | |||
| 8154c403d8 | |||
| bb83aed20d | |||
| 600c9fc907 | |||
| 5d09eb149c | |||
| e854fe3681 | |||
| 36c8822e6c | |||
| 9b29cce1a4 | |||
| 508f06339e | |||
| 0a9cdd2f15 | |||
| 7f77b6e3ec | |||
| 9507b0b1ba | |||
| ad9d6f4301 | |||
| b721fb6860 | |||
| 5f46cd2ea5 | |||
| 35efed9fef | |||
| 08e53919e2 | |||
| 933c8841ff | |||
| 518281e101 | |||
| 515d4bab0d | |||
| 8e72a820dd | |||
| f1f0fa34cb | |||
| 5010ef93e8 | |||
| e6679a3192 | |||
| 7cf8d5d2d3 | |||
| 14198eca41 | |||
| c6473f20dc | |||
| 9c34cb5862 | |||
| 149fd1629f | |||
| c48241f78a | |||
| a1bee81a5b | |||
| 1b053c03ba | |||
| 33057acd62 | |||
| 07511a2eb0 | |||
| 69c634d53f | |||
| 7bc17a9202 | |||
| d94a08b991 | |||
| a8b8c1feec | |||
| a589e5a090 | |||
| 8b1db3304f | |||
| 23aedd68b0 | |||
| f48f08a98b | |||
| 81dd88d25a | |||
| c92081d6e1 | |||
| d6e80f5a23 | |||
| 37cf71234c | |||
| 3b655f39e1 | |||
| eec0ddf466 | |||
| ca4e53bb0f | |||
| d9f2e91806 | |||
| 7bfed62526 | |||
| b63ac98f40 | |||
| 1e7d297c0e | |||
| f3cd3b88b9 | |||
| 9a199cd834 | |||
| c3fac2e83f | |||
| c7f6d2727c | |||
| 9901c63ede | |||
| 76897b8a83 | |||
| 217cf1420b | |||
| 6897192364 | |||
| 031ace3fe5 | |||
| e4683b9a05 | |||
| 93da32cfb3 | |||
| 62a0e52092 | |||
| 262ba10443 | |||
| 50cb88c5ed | |||
| 76e32703ac | |||
| d9f5fbaf04 | |||
| 16bb238518 | |||
| 759135fd7d | |||
| 56075857f2 | |||
| 8d3c7500d8 | |||
| 1e3f5e8695 | |||
| 08f5865c72 | |||
| ff3c141138 | |||
| fe31e0e849 | |||
| 2a26968c6c | |||
| fe8774953a | |||
| 4a7f036561 | |||
| 612f260938 | |||
| 2ad666d221 | |||
| aff4cc516e | |||
| 6fbcffe63b | |||
| ebd868fa33 | |||
| 71a63cc70e | |||
| 3702efc5be | |||
| 16e51cd4e5 | |||
| 87747fab06 | |||
| 4fe3d4339f | |||
| a276fb6b79 | |||
| fa8d8f9ea0 | |||
| c58031cbf4 | |||
| 4aae12fc63 | |||
| 256a8fb5c5 | |||
| 3c5a7cd664 | |||
| 796985472a | |||
| 7e0014865e | |||
| cd74d1887a | |||
| adf36e71ce | |||
| fc3c303d30 | |||
| 0e50977779 | |||
| ed9feaf542 | |||
| 09d427b4ba | |||
| 5dac8af300 | |||
| 1493a6180a | |||
| 848ddcebd7 | |||
| 71763d340e | |||
| 89daf6489d | |||
| 356e93914b | |||
| 5523d0c27a | |||
| 590a94523e | |||
| 3c95b84633 | |||
| 59943c87cd | |||
| 3f9a46b1f7 | |||
| 81faca041a | |||
| 60fccea703 | |||
| 118bf1fc65 | |||
| ce7ae3edd4 | |||
| 717eb526fb | |||
| 9241fddb1e | |||
| 2dff0bed72 | |||
| 4827c116f0 | |||
| 848afac803 | |||
| 13b0204427 | |||
| dc5f002de3 | |||
| 2ca44ec361 | |||
| c62d48160a | |||
| 9129f1b82a | |||
| 378cfc0c3d | |||
| 7db71d43e0 | |||
| 85b678a8fb | |||
| 9902ce2b78 | |||
| 394c7b22a2 | |||
| f99c993d96 | |||
| 1eb42446f8 | |||
| 3d001e7458 | |||
| 2dd3fc7df8 | |||
| f46677dfc0 | |||
| e94ccc86f8 | |||
| e778903dab | |||
| a1ea298a43 | |||
| 7a4a8e0fe2 | |||
| bbaefd0f77 | |||
| 951d0e8653 | |||
| 7d73d048c8 | |||
| a48766871d | |||
| 406cb4a619 | |||
| 9418cc7a69 | |||
| 20f6fbcf84 | |||
| 327f18525c | |||
| 8a0ea59c77 | |||
| f6ad846927 | |||
| 114b5724f8 |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
.cproject
|
||||
.project
|
||||
.settings/
|
||||
*.o
|
||||
*.so
|
||||
winixd/winix
|
||||
53
Makefile
53
Makefile
@@ -1,53 +0,0 @@
|
||||
CC = g++
|
||||
CFLAGS = -Wall -pedantic -g -I/usr/local/include -L/usr/local/lib
|
||||
name = cmslu.fcgi
|
||||
|
||||
export CC
|
||||
export CFLAGS
|
||||
|
||||
|
||||
all: $(name)
|
||||
|
||||
|
||||
|
||||
$(name): core content confparser templates ezc
|
||||
g++ -o $(name) $(CFLAGS) core/core.a content/content.a confparser/confparser.a templates/templates.a ../ezc/src/ezc.a -lfcgi -lpq
|
||||
|
||||
|
||||
|
||||
core: FORCE
|
||||
@cd core ; $(MAKE) -e
|
||||
|
||||
templates: FORCE
|
||||
@cd templates ; $(MAKE) -e
|
||||
|
||||
confparser: FORCE
|
||||
@cd confparser ; $(MAKE) -e
|
||||
|
||||
content: FORCE
|
||||
@cd content ; $(MAKE) -e
|
||||
|
||||
ezc: FORCE
|
||||
@cd ../ezc/src ; $(MAKE) -e
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
@cd core ; $(MAKE) -e clean
|
||||
@cd templates ; $(MAKE) -e clean
|
||||
@cd confparser ; $(MAKE) -e clean
|
||||
@cd content ; $(MAKE) -e clean
|
||||
@cd ../ezc/src ; $(MAKE) -e clean
|
||||
rm -f $(name)
|
||||
|
||||
|
||||
FORCE:
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
cd core ; $(MAKE) -e depend
|
||||
cd templates ; $(MAKE) -e depend
|
||||
cd confparser ; $(MAKE) -e depend
|
||||
cd content ; $(MAKE) -e depend
|
||||
cd ../ezc/src ; $(MAKE) -e depend
|
||||
@@ -1,29 +0,0 @@
|
||||
o = confparser.o
|
||||
|
||||
|
||||
|
||||
all: confparser.a
|
||||
|
||||
|
||||
confparser.a: $(o)
|
||||
ar rcs confparser.a $(o)
|
||||
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -f- *.cpp > Makefile.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.a
|
||||
|
||||
|
||||
include Makefile.dep
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
confparser.o: confparser.h
|
||||
@@ -1,208 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "confparser.h"
|
||||
|
||||
|
||||
ConfParser::ConfParser()
|
||||
{
|
||||
separator = '=';
|
||||
commentary = '#';
|
||||
}
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::Parse(const char * file_name)
|
||||
{
|
||||
file.open( file_name );
|
||||
|
||||
if( !file )
|
||||
return cant_open_file;
|
||||
|
||||
line = 1;
|
||||
table.clear();
|
||||
ReadChar();
|
||||
status = ParseFile();
|
||||
|
||||
file.close();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::ParseFile()
|
||||
{
|
||||
while( lastc != -1 )
|
||||
{
|
||||
if( ReadVariable() )
|
||||
{
|
||||
if( lastc != separator )
|
||||
return syntax_error;
|
||||
|
||||
ReadChar(); // skipping separator
|
||||
|
||||
if( !ReadValue() )
|
||||
return syntax_error;
|
||||
|
||||
table.insert( std::make_pair(variable, value) );
|
||||
}
|
||||
|
||||
if( lastc == commentary )
|
||||
SkipLine();
|
||||
|
||||
if( lastc != -1 && lastc != '\n' )
|
||||
return syntax_error;
|
||||
|
||||
ReadChar(); // skipping '\n' if was
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::IsValueSimpleChar(int c)
|
||||
{
|
||||
if( c==-1 || c=='\n' || IsWhite(c) || c==commentary )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::ReadVariable()
|
||||
{
|
||||
variable.clear();
|
||||
|
||||
SkipWhite();
|
||||
|
||||
while( IsVariableChar(lastc) )
|
||||
{
|
||||
variable += lastc;
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
SkipWhite();
|
||||
|
||||
return !variable.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValue()
|
||||
{
|
||||
value.clear();
|
||||
|
||||
SkipWhite();
|
||||
|
||||
|
||||
if( lastc == '"' )
|
||||
// quoted value
|
||||
return ReadValueQuoted();
|
||||
else
|
||||
return ReadValueSimple();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValueQuoted()
|
||||
{
|
||||
ReadChar(); // skipping the first quote
|
||||
|
||||
while( lastc != '\n' && lastc != '"' && lastc != -1 )
|
||||
{
|
||||
if( lastc == '\\' )
|
||||
ReadChar();
|
||||
|
||||
value += lastc;
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
if( lastc != '"' )
|
||||
return false;
|
||||
|
||||
ReadChar(); // skipping the last quote
|
||||
|
||||
SkipWhite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadValueSimple()
|
||||
{
|
||||
while( IsValueSimpleChar(lastc) )
|
||||
{
|
||||
value += lastc;
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
SkipWhite();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::ReadChar()
|
||||
{
|
||||
lastc = file.get();
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
|
||||
return lastc;
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::IsWhite(int c)
|
||||
{
|
||||
if( c==' ' || c=='\t' || c==13 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::SkipWhite()
|
||||
{
|
||||
while( IsWhite(lastc) )
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::SkipLine()
|
||||
{
|
||||
while( lastc != -1 && lastc != '\n' )
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileconfparser
|
||||
#define headerfileconfparser
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
class ConfParser
|
||||
{
|
||||
public:
|
||||
|
||||
enum Status { ok, cant_open_file, syntax_error };
|
||||
|
||||
ConfParser();
|
||||
Status Parse(const char * file_name);
|
||||
|
||||
|
||||
// last status
|
||||
Status status;
|
||||
|
||||
// line in which there is a syntax_error
|
||||
int line;
|
||||
|
||||
typedef std::map<std::string, std::string> Table;
|
||||
Table table;
|
||||
|
||||
private:
|
||||
|
||||
// last read variable, value
|
||||
std::string variable, value;
|
||||
|
||||
// separator between a variable and a value, usually '='
|
||||
int separator;
|
||||
|
||||
// commentary char
|
||||
int commentary;
|
||||
|
||||
// last read char
|
||||
int lastc;
|
||||
|
||||
// current file
|
||||
std::ifstream file;
|
||||
|
||||
|
||||
Status ParseFile();
|
||||
|
||||
bool IsVariableChar(int c);
|
||||
bool IsValueSimpleChar(int c);
|
||||
|
||||
bool ReadVariable();
|
||||
bool ReadValue();
|
||||
bool ReadValueQuoted();
|
||||
bool ReadValueSimple();
|
||||
|
||||
int ReadChar();
|
||||
bool IsWhite(int c);
|
||||
void SkipWhite();
|
||||
void SkipLine();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
o = content.o privileges.o emacs.o login.o rm.o cat.o logout.o ls.o node.o
|
||||
|
||||
|
||||
all: content.a
|
||||
|
||||
content.a: $(o)
|
||||
ar rcs content.a $(o)
|
||||
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -f- *.cpp > Makefile.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.a
|
||||
|
||||
|
||||
|
||||
include Makefile.dep
|
||||
@@ -1,108 +0,0 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
cat.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
cat.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
cat.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
cat.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
cat.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
cat.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
cat.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
cat.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
cat.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
cat.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
cat.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
content.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
content.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
content.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
content.o: ../core/user.h ../core/group.h ../core/ugcontainer.h
|
||||
content.o: ../core/users.h ../core/groups.h ../core/functions.h
|
||||
content.o: ../core/function.h ../core/request.h ../core/requesttypes.h
|
||||
content.o: ../core/session.h ../core/done.h ../core/getparser.h
|
||||
content.o: ../core/httpsimpleparser.h ../core/postparser.h
|
||||
content.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
content.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
content.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
content.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
emacs.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
emacs.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
emacs.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
emacs.o: ../core/user.h ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
emacs.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
emacs.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
emacs.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
emacs.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
emacs.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
emacs.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
emacs.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
emacs.o: ../core/data.h
|
||||
login.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
login.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
login.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
login.o: ../core/user.h ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
login.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
login.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
login.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
login.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
login.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
login.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
login.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
login.o: ../core/data.h
|
||||
logout.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
logout.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
logout.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h
|
||||
logout.o: ../core/user.h ../core/group.h ../core/ugcontainer.h
|
||||
logout.o: ../core/users.h ../core/groups.h ../core/functions.h
|
||||
logout.o: ../core/function.h ../core/request.h ../core/requesttypes.h
|
||||
logout.o: ../core/session.h ../core/done.h ../core/getparser.h
|
||||
logout.o: ../core/httpsimpleparser.h ../core/postparser.h
|
||||
logout.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
logout.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
logout.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
logout.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
ls.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
ls.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
ls.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
ls.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
ls.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
ls.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
ls.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
ls.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
ls.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
ls.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
ls.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
node.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
node.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
node.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
node.o: ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
node.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
node.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
node.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
node.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
node.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
node.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
node.o: ../core/data.h
|
||||
privileges.o: content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
privileges.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h
|
||||
privileges.o: ../core/error.h ../core/dirs.h ../core/db.h
|
||||
privileges.o: ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
privileges.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
privileges.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
privileges.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
privileges.o: ../core/getparser.h ../core/httpsimpleparser.h
|
||||
privileges.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
privileges.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
privileges.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h
|
||||
privileges.o: ../core/function.h ../core/functionparser.h ../core/request.h
|
||||
privileges.o: ../core/data.h
|
||||
rm.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h
|
||||
rm.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h
|
||||
rm.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
rm.o: ../core/group.h ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
rm.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
rm.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
rm.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
rm.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
rm.o: ../core/log.h ../core/misc.h ../core/function.h
|
||||
rm.o: ../core/functionparser.h ../core/request.h ../core/data.h
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunCat()
|
||||
{
|
||||
if( !request.is_item )
|
||||
{
|
||||
log << log1 << "Content: Cat function requires an item" << logend;
|
||||
request.status = Error::item_required;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( !request.HasReadAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,256 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
bool Content::Init()
|
||||
{
|
||||
templates.Read();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Content::DirsHaveReadExecPerm()
|
||||
{
|
||||
std::vector<Item*>::iterator i;
|
||||
|
||||
for(i = request.dir_table.begin() ; i!=request.dir_table.end() ; ++i)
|
||||
{
|
||||
if( !request.HasReadExecAccess(**i) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::SetDefaultFunction()
|
||||
{
|
||||
if( request.is_item )
|
||||
{
|
||||
request.pfunction = data.functions.GetFunction(Function::cat);
|
||||
|
||||
if( request.pfunction )
|
||||
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
long default_item = request.dir_table.back()->default_item;
|
||||
|
||||
if( default_item == -1 )
|
||||
{
|
||||
request.pfunction = data.functions.GetFunction(Function::ls);
|
||||
|
||||
if( request.pfunction )
|
||||
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log3 << "Content: Default item: id: " << default_item << logend;
|
||||
RedirectTo(default_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::MakeStandardFunction()
|
||||
{
|
||||
if( !request.pfunction )
|
||||
SetDefaultFunction();
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Content: no function (neither cat nor ls)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( request.pfunction->code == Function::logout )
|
||||
FunLogout();
|
||||
else
|
||||
if( request.pfunction->code == Function::cat )
|
||||
FunCat();
|
||||
else
|
||||
if( request.pfunction->code == Function::ls )
|
||||
FunLs();
|
||||
else
|
||||
if( request.pfunction->code == Function::emacs )
|
||||
FunEmacs();
|
||||
else
|
||||
if( request.pfunction->code == Function::privileges )
|
||||
FunPrivileges();
|
||||
else
|
||||
if( request.pfunction->code == Function::rm )
|
||||
FunRm();
|
||||
else
|
||||
if( request.pfunction->code == Function::node )
|
||||
FunNode();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::MakePost()
|
||||
{
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Content: MakePost: no function" << logend;
|
||||
request.status = Error::no_function;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch( request.pfunction->code )
|
||||
{
|
||||
case Function::emacs:
|
||||
PostFunEmacs();
|
||||
break;
|
||||
|
||||
case Function::privileges:
|
||||
PostFunPrivileges();
|
||||
break;
|
||||
|
||||
case Function::login:
|
||||
PostFunLogin();
|
||||
break;
|
||||
|
||||
default:
|
||||
log << log1 << "Content: unknown post function" << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::Make()
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
{
|
||||
log << log1 << "Content: there is no a root dir" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
// request.status can be changed by function_parser
|
||||
if( request.status == Error::ok )
|
||||
{
|
||||
if( DirsHaveReadExecPerm() )
|
||||
{
|
||||
if( request.method == Request::post )
|
||||
MakePost();
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
if( request.status == Error::ok )
|
||||
MakeStandardFunction();
|
||||
}
|
||||
else
|
||||
request.status = Error::permision_denied;
|
||||
}
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
templates.Generate();
|
||||
|
||||
|
||||
//request.PrintGetTable();
|
||||
//request.PrintEnv();
|
||||
//request.PrintIn();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
|
||||
// !! moze zwracac jakas wartosc?
|
||||
void Content::RedirectTo(const Item & item)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url;
|
||||
|
||||
|
||||
if( item.type == Item::dir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
data.dirs.MakePath(item.id, path);
|
||||
request.str += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !data.dirs.MakePath(item.parent_id, path) )
|
||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << item.id << logend;
|
||||
|
||||
request.str += path;
|
||||
request.str += item.url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::RedirectTo(long item_id)
|
||||
{
|
||||
std::string path;
|
||||
Item * pdir;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url;
|
||||
pdir = data.dirs.GetDir(item_id);
|
||||
|
||||
|
||||
if( pdir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
data.dirs.MakePath(pdir->id, path);
|
||||
request.str += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! zrobic nowy interfejs
|
||||
// !! GetItem pozamieniac na GetFile
|
||||
db.GetItem(request.item_table, item_id);
|
||||
|
||||
if( !request.item_table.empty() )
|
||||
{
|
||||
if( !data.dirs.MakePath(request.item_table[0].parent_id, path) )
|
||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << request.item_table[0].id << ", requested directory id: " << request.item_table[0].parent_id << logend;
|
||||
|
||||
request.str += path + request.item_table[0].url;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: Can't redirect: no such item: id: " << item_id << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecontent
|
||||
#define headerfilecontent
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fcgiapp.h>
|
||||
|
||||
#include "../templates/templates.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/error.h"
|
||||
#include "../core/misc.h"
|
||||
#include "../core/db.h"
|
||||
#include "../core/user.h"
|
||||
#include "../core/function.h"
|
||||
#include "../core/functionparser.h"
|
||||
|
||||
|
||||
|
||||
class Content
|
||||
{
|
||||
Templates templates;
|
||||
|
||||
|
||||
|
||||
|
||||
void PrepareUrl(Item & item);
|
||||
|
||||
|
||||
void SetDefaultFunction();
|
||||
bool DirsHaveReadExecPerm();
|
||||
|
||||
void MakeStandardFunction();
|
||||
|
||||
|
||||
|
||||
void MakePost();
|
||||
|
||||
void FunCat();
|
||||
void FunLogout();
|
||||
void FunLs();
|
||||
void FunEmacs();
|
||||
void FunPrivileges();
|
||||
void FunRm();
|
||||
void FunNode();
|
||||
|
||||
void PostFunLogin();
|
||||
void PostFunEmacsAdd();
|
||||
void PostFunEmacsEdit(bool with_url);
|
||||
void PostFunEmacs();
|
||||
void PostFunPrivileges();
|
||||
|
||||
void RedirectTo(const Item & item);
|
||||
void RedirectTo(long item_id);
|
||||
|
||||
public:
|
||||
|
||||
bool Init();
|
||||
|
||||
void Make();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PrepareUrl(Item & item)
|
||||
{
|
||||
CorrectUrl(item);
|
||||
|
||||
if( data.functions.GetFunction(item.url) )
|
||||
{
|
||||
// the name provided by an user is the same as a name of a function
|
||||
// we add one underscore character at the beginning
|
||||
|
||||
// names of functions should not begin with an underscore '_'
|
||||
// and we can simply add one '_' at the beginning
|
||||
// and the name will be unique
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacsAdd()
|
||||
{
|
||||
request.session->done = Done::added_item;
|
||||
|
||||
request.is_item = true;
|
||||
|
||||
request.item.user_id = request.session->puser ? request.session->puser->id : -1;
|
||||
request.item.group_id = -1;
|
||||
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
||||
request.item.parent_id = request.dir_table.back()->id;
|
||||
request.item.type = Item::file;
|
||||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back() ) )
|
||||
throw Error(Error::permision_denied);
|
||||
|
||||
request.session->done_status = db.AddItem(request.item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacsEdit(bool with_url)
|
||||
{
|
||||
request.session->done = Done::edited_item;
|
||||
|
||||
if( !request.HasWriteAccess(request.item) )
|
||||
throw Error(Error::permision_denied);
|
||||
|
||||
request.session->done_status = db.EditItemById(request.item, with_url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacs()
|
||||
{
|
||||
try
|
||||
{
|
||||
// these old values are ignored (if exists)
|
||||
request.item.url = request.PostVar("url");
|
||||
request.item.subject = request.PostVar("subject");
|
||||
request.item.content = request.PostVar("content");
|
||||
|
||||
bool with_url = false;
|
||||
|
||||
if( !request.is_item || request.PostVar("old_url") != request.item.url )
|
||||
with_url = true;
|
||||
|
||||
PrepareUrl(request.item);
|
||||
|
||||
if( request.is_item )
|
||||
PostFunEmacsEdit(with_url);
|
||||
else
|
||||
PostFunEmacsAdd();
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
request.session->done_status = e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.session->item = request.item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: PostFunEmacs: Error: " << request.session->done_status << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunEmacs()
|
||||
{
|
||||
if( !request.is_item )
|
||||
{
|
||||
// adding a new item
|
||||
if( !request.HasReadWriteAccess(*request.dir_table.back()) )
|
||||
request.status = Error::permision_denied;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// editing an existing item
|
||||
if( !request.HasReadWriteAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PostFunLogin()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string & login = request.PostVar("login");
|
||||
std::string & pass = request.PostVar("password");
|
||||
long user_id;
|
||||
|
||||
if( db.CheckUser(login, pass, user_id) )
|
||||
{
|
||||
request.session->puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !request.session->puser )
|
||||
{
|
||||
log << log1 << "Content: user: " << login << " is in the database but is not in data.users" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
log << log2 << "User " << login << " (id: " << user_id << ") logged" << logend;
|
||||
|
||||
if( request.is_item )
|
||||
{
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
RedirectTo(*request.dir_table.back());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const Error &)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunLogout()
|
||||
{
|
||||
if( request.session->puser )
|
||||
{
|
||||
log << log2 << "User: " << request.session->puser->name << ", id: " << request.session->puser->id << " logged out" << logend;
|
||||
|
||||
request.session->puser = 0;
|
||||
}
|
||||
|
||||
request.result = Request::redirect;
|
||||
std::string path;
|
||||
|
||||
data.dirs.MakePath(request.dir_table.back()->id, path);
|
||||
|
||||
request.str = data.base_url + path;
|
||||
|
||||
if( request.is_item )
|
||||
request.str += request.item.url;
|
||||
|
||||
request.session->done = Done::loggedout;
|
||||
request.session->done_timer = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunLs()
|
||||
{
|
||||
if( request.is_item )
|
||||
{
|
||||
// we're showing only the item
|
||||
request.item_table.push_back( request.item );
|
||||
return;
|
||||
}
|
||||
|
||||
// we're showing the whole directory
|
||||
Item item_ref;
|
||||
|
||||
item_ref.parent_id = request.dir_table.back()->id;
|
||||
|
||||
// !! zrobic inna metode, inny interfejs (jako parametr niech bierze parent_id), i zeby nie odczytywala contentu i subjectu (a moze tylko subject? przyda sie przy ls -l)
|
||||
db.GetItems(request.item_table, item_ref);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunNode()
|
||||
{
|
||||
if( request.param_table.empty() )
|
||||
{
|
||||
//request.status = Error
|
||||
//!!zglosic 404
|
||||
return;
|
||||
}
|
||||
|
||||
long id = atol( request.param_table[0]->c_str() );
|
||||
|
||||
RedirectTo(id);
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PostFunPrivileges()
|
||||
{
|
||||
// !! narazie tylko dla plikow
|
||||
if( !request.is_item )
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
long user_id = data.users.GetUserId( request.PostVar("user") );
|
||||
long group_id = data.groups.GetGroupId( request.PostVar("group") );
|
||||
int privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
|
||||
|
||||
if( !request.CanChangeUser(request.item, user_id) )
|
||||
throw Error(Error::cant_change_user);
|
||||
|
||||
if( !request.CanChangeGroup(request.item, group_id) )
|
||||
throw Error(Error::cant_change_group);
|
||||
|
||||
if( !request.CanChangePrivileges(request.item, privileges) )
|
||||
throw Error(Error::cant_change_privileges);
|
||||
|
||||
request.item.user_id = user_id;
|
||||
request.item.group_id = group_id;
|
||||
request.item.privileges = privileges;
|
||||
|
||||
request.session->done = Done::privileged_item;
|
||||
request.session->done_status = db.EditPrivById(request.item, request.item.id);
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "Content: FunChmod: Error: " << e << logend;
|
||||
request.session->done_status = e;
|
||||
}
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.session->item = request.item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: PostFunPrivileges: Error: " << static_cast<int>(request.session->done_status) << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunPrivileges()
|
||||
{
|
||||
if( !request.is_item )
|
||||
{
|
||||
// !! chwilowi tylko dla plikow
|
||||
request.status == Error::item_required;
|
||||
return;
|
||||
}
|
||||
|
||||
// you must be an owner of the item (or a superuser)
|
||||
// !! moze wykorzystac request.CanChangeUser() ?
|
||||
if( !request.session->puser || (!request.session->puser->super_user && request.session->puser->id != request.item.user_id) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::FunRm()
|
||||
{
|
||||
// !! narazie usuwanie tylko dla plikow
|
||||
|
||||
if( !request.is_item )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) || !request.HasWriteAccess(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( request.param_table.empty() )
|
||||
{
|
||||
// we'll put some information about the deleted item (on the next page)
|
||||
request.session->item = request.item;
|
||||
|
||||
// !! zmienic interfejs dla db.DelItem
|
||||
if( db.DelItem( request.item ) )
|
||||
{
|
||||
request.session->done_status = Error::ok;
|
||||
log << log2 << "Content: deleted item: subject: " << request.item.subject << ", id: " << request.item.id << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
request.session->done_status = Error::db_no_item;
|
||||
}
|
||||
|
||||
request.session->done = Done::deleted_item;
|
||||
request.result = Request::redirect;
|
||||
|
||||
RedirectTo(*request.dir_table.back());
|
||||
|
||||
request.session->done_timer = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( request.IsParam("potwierdz") )
|
||||
{
|
||||
//request.result = Request::del_item_confirm;
|
||||
}
|
||||
else
|
||||
request.result = Request::err404;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
o = data.o log.o sessionmanager.o requestcontroller.o dircontainer.o session.o main.o done.o request.o misc.o httpsimpleparser.o db.o error.o db_itemcolumns.o users.o config.o dirs.o groups.o function.o functionparser.o functions.o
|
||||
|
||||
|
||||
|
||||
all: core.a
|
||||
|
||||
core.a: $(o)
|
||||
ar rcs core.a $(o)
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -f- *.cpp > Makefile.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.a
|
||||
|
||||
|
||||
include Makefile.dep
|
||||
@@ -1,61 +0,0 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
config.o: config.h ../confparser/confparser.h error.h log.h data.h misc.h
|
||||
config.o: item.h dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
|
||||
config.o: users.h groups.h functions.h function.h
|
||||
data.o: data.h misc.h log.h item.h error.h dirs.h db.h dircontainer.h user.h
|
||||
data.o: group.h ugcontainer.h users.h groups.h functions.h function.h
|
||||
db.o: db.h log.h item.h misc.h error.h dircontainer.h user.h group.h
|
||||
db.o: ugcontainer.h
|
||||
db_itemcolumns.o: db.h log.h item.h misc.h error.h dircontainer.h user.h
|
||||
db_itemcolumns.o: group.h ugcontainer.h
|
||||
dircontainer.o: dircontainer.h item.h log.h
|
||||
dirs.o: dirs.h item.h error.h log.h db.h misc.h dircontainer.h user.h group.h
|
||||
dirs.o: ugcontainer.h
|
||||
done.o: done.h
|
||||
error.o: error.h log.h
|
||||
function.o: function.h log.h item.h
|
||||
functionparser.o: functionparser.h request.h requesttypes.h log.h session.h
|
||||
functionparser.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
|
||||
functionparser.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
|
||||
functionparser.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
|
||||
functionparser.o: functions.h
|
||||
functions.o: functions.h function.h log.h item.h
|
||||
groups.o: groups.h group.h db.h log.h item.h misc.h error.h dircontainer.h
|
||||
groups.o: user.h ugcontainer.h
|
||||
httpsimpleparser.o: httpsimpleparser.h
|
||||
log.o: log.h
|
||||
main.o: requestcontroller.h data.h misc.h log.h item.h error.h dirs.h db.h
|
||||
main.o: dircontainer.h user.h group.h ugcontainer.h users.h groups.h
|
||||
main.o: functions.h function.h request.h requesttypes.h session.h done.h
|
||||
main.o: getparser.h httpsimpleparser.h postparser.h cookieparser.h
|
||||
main.o: ../content/content.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
main.o: ../core/data.h ../core/request.h ../core/item.h ../core/db.h
|
||||
main.o: ../core/error.h ../core/user.h ../core/group.h ../core/users.h
|
||||
main.o: ../core/groups.h ../core/log.h ../core/misc.h ../core/function.h
|
||||
main.o: ../core/functionparser.h sessionmanager.h config.h
|
||||
main.o: ../confparser/confparser.h
|
||||
misc.o: misc.h log.h item.h
|
||||
request.o: request.h requesttypes.h log.h session.h error.h item.h done.h
|
||||
request.o: user.h getparser.h httpsimpleparser.h postparser.h cookieparser.h
|
||||
request.o: function.h
|
||||
requestcontroller.o: requestcontroller.h data.h misc.h log.h item.h error.h
|
||||
requestcontroller.o: dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
|
||||
requestcontroller.o: users.h groups.h functions.h function.h request.h
|
||||
requestcontroller.o: requesttypes.h session.h done.h getparser.h
|
||||
requestcontroller.o: httpsimpleparser.h postparser.h cookieparser.h
|
||||
requestcontroller.o: ../content/content.h ../templates/templates.h
|
||||
requestcontroller.o: ../../ezc/src/ezc.h ../core/data.h ../core/request.h
|
||||
requestcontroller.o: ../core/item.h ../core/db.h ../core/error.h
|
||||
requestcontroller.o: ../core/user.h ../core/group.h ../core/users.h
|
||||
requestcontroller.o: ../core/groups.h ../core/log.h ../core/misc.h
|
||||
requestcontroller.o: ../core/function.h ../core/functionparser.h
|
||||
requestcontroller.o: sessionmanager.h
|
||||
session.o: session.h requesttypes.h error.h log.h item.h done.h user.h
|
||||
sessionmanager.o: sessionmanager.h request.h requesttypes.h log.h session.h
|
||||
sessionmanager.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
|
||||
sessionmanager.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
|
||||
sessionmanager.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
|
||||
sessionmanager.o: functions.h
|
||||
users.o: users.h user.h db.h log.h item.h misc.h error.h dircontainer.h
|
||||
users.o: group.h ugcontainer.h
|
||||
199
core/config.cpp
199
core/config.cpp
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
Config::Config()
|
||||
{
|
||||
default_int = 0;
|
||||
default_bool = false;
|
||||
|
||||
errors_to_stdout = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//!! czy tu w ogole mozemy uzywac log << ?
|
||||
//!! przeciez jeszcze nie zostal przetworzony plik konfiguracyjny
|
||||
|
||||
|
||||
void Config::ShowError()
|
||||
{
|
||||
|
||||
switch( conf_parser.status )
|
||||
{
|
||||
case ConfParser::ok:
|
||||
log << log2 << "Config: syntax ok" << logend;
|
||||
break;
|
||||
|
||||
case ConfParser::cant_open_file:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: cant open a config file: " << data.config_file << std::endl;
|
||||
|
||||
log << log1 << "Config: cant open a config file: " << data.config_file << logend;
|
||||
break;
|
||||
|
||||
case ConfParser::syntax_error:
|
||||
if( errors_to_stdout )
|
||||
std::cout << "Config: syntax error, line: " << conf_parser.line << std::endl;
|
||||
|
||||
log << log1 << "Config: syntax error, line: " << conf_parser.line << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Config::ReadConfig(bool errors_to_stdout_)
|
||||
{
|
||||
errors_to_stdout = errors_to_stdout_;
|
||||
|
||||
if( data.config_file.empty() )
|
||||
{
|
||||
log << log2 << "Config: name of the config file is empty" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
|
||||
ConfParser::Status status = conf_parser.Parse( data.config_file.c_str() );
|
||||
|
||||
|
||||
if( status == ConfParser::ok )
|
||||
{
|
||||
AssignValues();
|
||||
|
||||
data.SetAdditionalVariables();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Config::AssignValues()
|
||||
{
|
||||
data.log_file = Text("log_file");
|
||||
data.fcgi_socket = Text("fcgi_socket");
|
||||
data.fcgi_socket_chmod = Int("fcgi_socket_chmod");
|
||||
data.fcgi_socket_user = Text("fcgi_socket_user");
|
||||
data.fcgi_socket_group = Text("fcgi_socket_group");
|
||||
data.log_level = Int("log_level");
|
||||
|
||||
if( !data.stdout_is_closed )
|
||||
data.log_stdout = Bool("log_stdout");
|
||||
else
|
||||
data.log_stdout = false;
|
||||
|
||||
data.templates = Text("templates");
|
||||
data.default_index = Text("default_index");
|
||||
data.http_session_id_name = Text("http_session_id_name");
|
||||
data.db_database = Text("db_database");
|
||||
data.db_user = Text("db_user");
|
||||
data.db_pass = Text("db_pass");
|
||||
data.base_url = Text("base_url");
|
||||
|
||||
NoLastSlash(data.base_url);
|
||||
|
||||
data.one_item_is_showed = Bool("one_item_is_showed");
|
||||
|
||||
data.priv_no_user = Text("priv_no_user");
|
||||
data.priv_no_group = Text("priv_no_group");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::string & Config::Text(const char * name)
|
||||
{
|
||||
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
||||
|
||||
if( i == conf_parser.table.end() )
|
||||
{
|
||||
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: \"" << default_str << "\"" << logend;
|
||||
return default_str;
|
||||
}
|
||||
|
||||
log << log3 << "Config: " << name << "=" << i->second << logend;
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int Config::Int(const char * name)
|
||||
{
|
||||
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
||||
|
||||
if( i == conf_parser.table.end() || i->second.empty() )
|
||||
{
|
||||
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << default_int << logend;
|
||||
return default_int;
|
||||
}
|
||||
|
||||
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
|
||||
log << log3 << "Config: " << name << "=" << res << logend;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Config::Bool(const char * name)
|
||||
{
|
||||
ConfParser::Table::iterator i = conf_parser.table.find(name);
|
||||
|
||||
if( i == conf_parser.table.end() )
|
||||
{
|
||||
log << log2 << "Config: warning: " << name << " is not defined in the config, default will be: " << (default_bool?"true":"false") << logend;
|
||||
return default_int;
|
||||
}
|
||||
|
||||
bool res = default_int;
|
||||
|
||||
if( i->second == "true" || i->second == "1" || i->second == "yes" )
|
||||
res = true;
|
||||
|
||||
log << log3 << "Config: " << name << "=" << (res?"true":"false") << logend;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Config::NoLastSlash(std::string & s)
|
||||
{
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
log << log2 << "Config: removing the last slash from: " << s << logend;
|
||||
|
||||
if( *(--s.end()) == '/' )
|
||||
s.erase(--s.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileconfig
|
||||
#define headerfileconfig
|
||||
|
||||
|
||||
#include "../confparser/confparser.h"
|
||||
#include "error.h"
|
||||
#include "data.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
class Config
|
||||
{
|
||||
|
||||
public:
|
||||
Config();
|
||||
bool ReadConfig(bool errors_to_stdout_);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
ConfParser conf_parser;
|
||||
void ShowError();
|
||||
void AssignValues();
|
||||
|
||||
|
||||
std::string & Text(const char *);
|
||||
int Int(const char *);
|
||||
bool Bool(const char *);
|
||||
|
||||
std::string default_str;
|
||||
int default_int;
|
||||
bool default_bool;
|
||||
|
||||
|
||||
bool errors_to_stdout;
|
||||
|
||||
void NoLastSlash(std::string & s);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecookieparser
|
||||
#define headerfilecookieparser
|
||||
|
||||
#include <fcgiapp.h>
|
||||
#include "httpsimpleparser.h"
|
||||
#include "requesttypes.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class CookieParser : public HttpSimpleParser
|
||||
{
|
||||
|
||||
const char * cookie_string;
|
||||
CookieTable & cookie_table;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual int GetChar()
|
||||
{
|
||||
if( !cookie_string || *cookie_string == 0 )
|
||||
return -1;
|
||||
|
||||
return (int)(unsigned char)*(cookie_string++);
|
||||
}
|
||||
|
||||
|
||||
virtual void Parameter(std::string & name, std::string & value)
|
||||
{
|
||||
// Cookie names are case insensitive according to section 3.1 of RFC 2965
|
||||
ToLower(name);
|
||||
|
||||
std::pair<CookieTable::iterator, bool> res = cookie_table.insert( std::make_pair(name, value) );
|
||||
|
||||
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
|
||||
|
||||
if( res.second == false )
|
||||
log << log2 << " (skipped)";
|
||||
|
||||
log << log2 << logend;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
CookieParser(const char * cookie_string_, CookieTable & cookie_table_) : cookie_string(cookie_string_), cookie_table(cookie_table_)
|
||||
{
|
||||
HttpSimpleParser::separator = ';';
|
||||
HttpSimpleParser::value_can_be_quoted = true;
|
||||
HttpSimpleParser::skip_white_chars = true;
|
||||
HttpSimpleParser::recognize_special_chars = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
||||
Data::Data()
|
||||
{
|
||||
signal_hup = false;
|
||||
stdout_is_closed = false;
|
||||
|
||||
// the rest will be read from a config file
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Data::SetAdditionalVariables()
|
||||
{
|
||||
SetHttpHost();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Data::SetHttpHost()
|
||||
{
|
||||
if( strncmp(base_url.c_str(), "http://", 7) == 0 )
|
||||
base_url_http_host = base_url.substr(7);
|
||||
else
|
||||
if( strncmp(base_url.c_str(), "https://", 8) == 0 )
|
||||
base_url_http_host = base_url.substr(8);
|
||||
else
|
||||
base_url_http_host.clear();
|
||||
|
||||
if( base_url_http_host.empty() )
|
||||
return;
|
||||
|
||||
// removing the last slash (if it is present)
|
||||
if( base_url_http_host[ base_url_http_host.size() - 1 ] == '/' )
|
||||
base_url_http_host.erase( base_url_http_host.end() - 1 );
|
||||
}
|
||||
132
core/data.h
132
core/data.h
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfiledata
|
||||
#define headerfiledata
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string.h>
|
||||
|
||||
#include "misc.h"
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "dirs.h"
|
||||
#include "users.h"
|
||||
#include "groups.h"
|
||||
#include "functions.h"
|
||||
|
||||
|
||||
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// members read from a config file
|
||||
|
||||
// name of the config file (full path can be)
|
||||
std::string config_file;
|
||||
|
||||
// log file name
|
||||
std::string log_file;
|
||||
|
||||
// 1 - minimum
|
||||
// 2 - (default)
|
||||
// 3 - maximum - all logs
|
||||
int log_level;
|
||||
|
||||
// logging to stdout too
|
||||
bool log_stdout;
|
||||
|
||||
|
||||
// fast cgi: socket (unix domain)
|
||||
std::string fcgi_socket;
|
||||
|
||||
// fast cgi: socket permissions
|
||||
int fcgi_socket_chmod;
|
||||
|
||||
// fast cgi: owner of the socket
|
||||
std::string fcgi_socket_user;
|
||||
|
||||
// fast cgi: group of the socket
|
||||
std::string fcgi_socket_group;
|
||||
|
||||
std::string templates;
|
||||
std::string default_index;
|
||||
|
||||
std::string db_database;
|
||||
std::string db_user;
|
||||
std::string db_pass;
|
||||
std::string base_url;
|
||||
std::string 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;
|
||||
|
||||
// if there is one item in a directory
|
||||
// it will be showed
|
||||
// (instead of showing directory contents)
|
||||
// !! wywalic to, nie bedzie uzywane
|
||||
bool one_item_is_showed;
|
||||
|
||||
// string used in a place where is a user (or group) selected
|
||||
std::string priv_no_user;
|
||||
std::string priv_no_group;
|
||||
|
||||
|
||||
// end config members
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
|
||||
// false at the beginning
|
||||
bool stdout_is_closed;
|
||||
|
||||
// true if there was SIGHUP signal
|
||||
volatile bool signal_hup;
|
||||
|
||||
// contains current directories tree
|
||||
Dirs dirs;
|
||||
|
||||
// based on base_url
|
||||
// set by SetAdditionalVariables()
|
||||
std::string base_url_http_host;
|
||||
|
||||
// call this method after the config file is read
|
||||
void SetAdditionalVariables();
|
||||
|
||||
|
||||
|
||||
// users
|
||||
Users users;
|
||||
|
||||
// groups
|
||||
Groups groups;
|
||||
|
||||
// functions (ls, cat, etc)
|
||||
Functions functions;
|
||||
|
||||
|
||||
Data();
|
||||
|
||||
|
||||
private:
|
||||
void SetHttpHost();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
extern Data data;
|
||||
|
||||
|
||||
#endif
|
||||
1153
core/db.cpp
1153
core/db.cpp
File diff suppressed because it is too large
Load Diff
110
core/db.h
110
core/db.h
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecoredb
|
||||
#define headerfilecoredb
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <libpq-fe.h>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
#include "log.h"
|
||||
#include "item.h"
|
||||
#include "misc.h"
|
||||
#include "error.h"
|
||||
#include "dircontainer.h"
|
||||
#include "user.h"
|
||||
#include "group.h"
|
||||
#include "ugcontainer.h"
|
||||
|
||||
|
||||
class Db
|
||||
{
|
||||
public:
|
||||
|
||||
Db();
|
||||
~Db();
|
||||
|
||||
void Init(const std::string & database, const std::string & user, const std::string & pass);
|
||||
bool CheckUser(std::string & login, std::string & password, long & user_id);
|
||||
Error AddItem(Item & item);
|
||||
Error EditItemById(Item & item, bool with_subject = true);
|
||||
Error EditItemByUrl(Item & item, bool with_subject = true);
|
||||
void CheckAllUrlSubject();
|
||||
void GetItems(std::vector<Item> & item_table, Item & item_ref);
|
||||
void GetItem(std::vector<Item> & item_table, long id);
|
||||
bool GetPriv(Item & item, long id);
|
||||
Error EditPrivById(Item & item, long id);
|
||||
|
||||
bool DelItem(const Item & item);
|
||||
void GetDirs(DirContainer & dir_table);
|
||||
void GetUsers(UGContainer<User> & user_table);
|
||||
void GetGroups(UGContainer<Group> & group_table);
|
||||
|
||||
// !! nowy interfejs
|
||||
Error GetItem(long parent_id, const std::string & url, Item & item);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
PGconn * pg_conn;
|
||||
std::string db_database, db_user, db_pass;
|
||||
|
||||
void Connect();
|
||||
void Close();
|
||||
void AssertConnection();
|
||||
std::string Escape(const std::string & s);
|
||||
std::string Escape(const char * s);
|
||||
PGresult * AssertQuery(const std::string & q);
|
||||
void AssertResultStatus(PGresult * r, ExecStatusType t);
|
||||
static int AssertColumn(PGresult * r, const char * column_name);
|
||||
static const char * AssertValue(PGresult * r, int row, int col);
|
||||
void ClearResult(PGresult * r);
|
||||
long AssertCurrval(const char * table);
|
||||
bool AddItemCreateUrlSubject(Item & item);
|
||||
|
||||
Error AddItemIntoContent(Item & item);
|
||||
Error AddItemIntoItem(Item & item);
|
||||
|
||||
Error EditItemInItem(Item & item, bool with_subject);
|
||||
Error EditItemInContent(Item & item);
|
||||
Error EditItemGetId(Item & item);
|
||||
Error EditItemGetContentId(Item & item);
|
||||
|
||||
void CheckAllUrlSubjectModifyItem(Item & item);
|
||||
|
||||
PGresult * GetItemsQuery(Item & item_ref);
|
||||
|
||||
bool DelItemDelItem(const Item & item);
|
||||
void DelItemDelContent(const Item & item);
|
||||
Error DelItemCountContents(const Item & item, long & contents);
|
||||
|
||||
|
||||
struct ItemColumns
|
||||
{
|
||||
int id, user_id, group_id, privileges, url, type, parent_id, content_id, default_item, subject, content, content_type;
|
||||
|
||||
void SetColumns(PGresult * r);
|
||||
void SetItem(PGresult * r, long row, Item & item);
|
||||
};
|
||||
|
||||
|
||||
}; // class Db
|
||||
|
||||
|
||||
extern Db db;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "db.h"
|
||||
|
||||
|
||||
|
||||
void Db::ItemColumns::SetColumns(PGresult * r)
|
||||
{
|
||||
// PQfnumber returns -1 if there is no such a column
|
||||
id = PQfnumber(r, "id"); // !! why item.id doesn't work?
|
||||
user_id = PQfnumber(r, "user_id");
|
||||
group_id = PQfnumber(r, "group_id");
|
||||
privileges = PQfnumber(r, "privileges");
|
||||
url = PQfnumber(r, "url");
|
||||
type = PQfnumber(r, "type");
|
||||
parent_id = PQfnumber(r, "parent_id");
|
||||
content_id = PQfnumber(r, "content_id");
|
||||
default_item = PQfnumber(r, "default_item");
|
||||
subject = PQfnumber(r, "subject");
|
||||
content = PQfnumber(r, "content");
|
||||
content_type = PQfnumber(r, "content_type");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item)
|
||||
{
|
||||
if( id != -1 ) item.id = atol( Db::AssertValue(r, row, id) );
|
||||
if( user_id != -1 ) item.user_id = atol( Db::AssertValue(r, row, user_id) );
|
||||
if( group_id != -1 ) item.group_id = atol( Db::AssertValue(r, row, group_id) );
|
||||
if( privileges != -1 ) item.privileges = atoi( Db::AssertValue(r, row, privileges) );
|
||||
if( url != -1 ) item.url = Db::AssertValue(r, row, url);
|
||||
if( type != -1 ) item.type = static_cast<Item::Type>( atoi( Db::AssertValue(r, row, type) ) );
|
||||
if( parent_id != -1 ) item.parent_id = atol( Db::AssertValue(r, row, parent_id) );
|
||||
if( content_id != -1 ) item.content_id = atol( Db::AssertValue(r, row, content_id) );
|
||||
if( default_item != -1 ) item.default_item = atol( Db::AssertValue(r, row, default_item) );
|
||||
if( subject != -1 ) item.subject = Db::AssertValue(r, row, subject);
|
||||
if( content != -1 ) item.content = Db::AssertValue(r, row, content);
|
||||
if( content_type != -1 ) item.content_type = atoi( Db::AssertValue(r, row, content_type) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dircontainer.h"
|
||||
|
||||
|
||||
|
||||
DirContainer::DirContainer()
|
||||
{
|
||||
is_root = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DirContainer::Iterator DirContainer::GetRoot()
|
||||
{
|
||||
if( !is_root )
|
||||
return table.end();
|
||||
|
||||
return table.begin() + root_index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DirContainer::Iterator DirContainer::Begin()
|
||||
{
|
||||
return table.begin();
|
||||
}
|
||||
|
||||
|
||||
DirContainer::Iterator DirContainer::End()
|
||||
{
|
||||
return table.end();
|
||||
}
|
||||
|
||||
|
||||
DirContainer::SizeType DirContainer::Size()
|
||||
{
|
||||
return table.size();
|
||||
}
|
||||
|
||||
bool DirContainer::Empty()
|
||||
{
|
||||
return table.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DirContainer::PushBack(const Item & item)
|
||||
{
|
||||
bool rebuild_indexes = false;
|
||||
|
||||
if( table.size() == table.capacity() )
|
||||
rebuild_indexes = true;
|
||||
|
||||
|
||||
if( item.parent_id == -1 )
|
||||
{
|
||||
if( is_root )
|
||||
log << log1 << "DirCont: more than one root dir - skipped, id: " << item.id << logend;
|
||||
else
|
||||
{
|
||||
is_root = true;
|
||||
root_index = table.size();
|
||||
}
|
||||
}
|
||||
|
||||
table.push_back(item);
|
||||
log << log2 << "DirCont: added item, id: " << item.id << ", parent_id: " << item.parent_id << logend;
|
||||
|
||||
|
||||
if( rebuild_indexes )
|
||||
RebuildIndexes();
|
||||
else
|
||||
AddIndexes( --table.end() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void DirContainer::Clear()
|
||||
{
|
||||
table.clear();
|
||||
table_id.clear();
|
||||
table_parent.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DirContainer::Iterator DirContainer::FindId(long id)
|
||||
{
|
||||
TableId::iterator i = table_id.find(id);
|
||||
|
||||
if( i == table_id.end() )
|
||||
return table.end();
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DirContainer::AddIndexes(Iterator item)
|
||||
{
|
||||
table_id.insert( std::make_pair(item->id, item) );
|
||||
table_parent.insert( std::make_pair(item->parent_id, item) );
|
||||
|
||||
log << log2 << "DirCont: added indexes to item, id: " << item->id << ", parent_id: " << item->parent_id << logend;
|
||||
}
|
||||
|
||||
|
||||
void DirContainer::RebuildIndexes()
|
||||
{
|
||||
Iterator i;
|
||||
|
||||
log << log2 << "DirCont: rebuilding indexes" << logend;
|
||||
|
||||
table_id.clear();
|
||||
table_parent.clear();
|
||||
|
||||
for(i=table.begin() ; i!=table.end() ; ++i)
|
||||
AddIndexes( i );
|
||||
|
||||
log << log2 << "DirCont: indexes rebuilt, table.size: " << table.size() << ", table_id.size: " << table_id.size() << ", table_parent.size: " << table_parent.size() << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DirContainer::ParentIterator DirContainer::ParentBegin()
|
||||
{
|
||||
return table_parent.begin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
DirContainer::ParentIterator DirContainer::ParentEnd()
|
||||
{
|
||||
return table_parent.end();
|
||||
}
|
||||
|
||||
|
||||
DirContainer::ParentSizeType DirContainer::ParentSize()
|
||||
{
|
||||
return table_parent.size();
|
||||
}
|
||||
|
||||
|
||||
bool DirContainer::ParentEmpty()
|
||||
{
|
||||
return table_parent.empty();
|
||||
}
|
||||
|
||||
|
||||
DirContainer::ParentIterator DirContainer::FindFirstParent(long parent)
|
||||
{
|
||||
ParentIterator i = table_parent.lower_bound(parent);
|
||||
|
||||
if( i == table_parent.end() || i->first != parent )
|
||||
return table_parent.end();
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
DirContainer::ParentIterator DirContainer::NextParent(ParentIterator i)
|
||||
{
|
||||
if( i == table_parent.end() )
|
||||
return table_parent.end();
|
||||
|
||||
long parent = i->first;
|
||||
++i;
|
||||
|
||||
if( i == table_parent.end() || i->first != parent )
|
||||
return table_parent.end();
|
||||
|
||||
return i;
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfiledircontainer
|
||||
#define headerfiledircontainer
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "item.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
class DirContainer
|
||||
{
|
||||
|
||||
public:
|
||||
typedef std::vector<Item> Table;
|
||||
typedef Table::iterator Iterator;
|
||||
typedef Table::size_type SizeType;
|
||||
|
||||
typedef std::map<long, Iterator> TableId;
|
||||
typedef std::multimap<long, Iterator> TableParent;
|
||||
typedef TableParent::iterator ParentIterator;
|
||||
typedef TableParent::size_type ParentSizeType;
|
||||
|
||||
|
||||
DirContainer();
|
||||
|
||||
Iterator GetRoot();
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
SizeType Size();
|
||||
bool Empty();
|
||||
void PushBack(const Item & item);
|
||||
void Clear();
|
||||
|
||||
Iterator FindId(long id);
|
||||
|
||||
ParentIterator ParentBegin();
|
||||
ParentIterator ParentEnd();
|
||||
ParentSizeType ParentSize();
|
||||
bool ParentEmpty();
|
||||
ParentIterator FindFirstParent(long parent);
|
||||
ParentIterator NextParent(ParentIterator pi);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void AddIndexes(Iterator item);
|
||||
void RebuildIndexes();
|
||||
|
||||
// main table with dirs
|
||||
Table table;
|
||||
|
||||
// true if there is a root dir in the table
|
||||
bool is_root;
|
||||
|
||||
// root dir
|
||||
SizeType root_index;
|
||||
|
||||
// indexes
|
||||
TableId table_id;
|
||||
TableParent table_parent;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
337
core/dirs.cpp
337
core/dirs.cpp
@@ -1,337 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dirs.h"
|
||||
|
||||
|
||||
void Dirs::Clear()
|
||||
{
|
||||
dir_table.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Dirs::CheckRootDir()
|
||||
{
|
||||
DirContainer::ParentIterator i;
|
||||
long roots = 0;
|
||||
|
||||
|
||||
for( i=dir_table.FindFirstParent(-1) ; i!=dir_table.ParentEnd() ; i=dir_table.NextParent(i) )
|
||||
++roots;
|
||||
|
||||
if( roots == 0 )
|
||||
{
|
||||
log << log1 << "Dirs: there is no a root dir in the database" << logend;
|
||||
Clear();
|
||||
}
|
||||
else
|
||||
if( roots > 1 )
|
||||
{
|
||||
log << log1 << "Dirs: there are more than one root dir in the database" << logend;
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Dirs::ReadDirs()
|
||||
{
|
||||
Clear();
|
||||
|
||||
db.GetDirs(dir_table);
|
||||
CheckRootDir();
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::GetRootDir(Item ** item)
|
||||
{
|
||||
DirContainer::Iterator root = dir_table.GetRoot();
|
||||
|
||||
if( root == dir_table.End() )
|
||||
return false;
|
||||
|
||||
*item = &(*root);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::GetDir(const std::string & name, long parent, Item ** item)
|
||||
{
|
||||
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
||||
|
||||
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
||||
if( i->second->url == name )
|
||||
{
|
||||
*item = &(*i->second);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::ExtractName(const char * & s, std::string & name)
|
||||
{
|
||||
name.clear();
|
||||
|
||||
// skipping first slashes (can be more than one)
|
||||
for( ; *s == '/' ; ++s);
|
||||
|
||||
for( ; *s != 0 && *s != '/' ; ++s)
|
||||
name += *s;
|
||||
|
||||
return !name.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! moze lepiej zwracac wskaznik do Item i kiedy nie ma katalogu to zwracac 0 ?
|
||||
bool Dirs::GetDir(const std::string & path, Item ** item)
|
||||
{
|
||||
DirContainer::Iterator root = dir_table.GetRoot();
|
||||
|
||||
if( root == dir_table.End() )
|
||||
// ops, we do not have a root dir
|
||||
return false;
|
||||
|
||||
Item * pitem = &(*root);
|
||||
|
||||
std::string name;
|
||||
const char * s = path.c_str();
|
||||
|
||||
while( ExtractName(s, name) )
|
||||
{
|
||||
if( !GetDir(name, pitem->id, &pitem) )
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
*item = pitem;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! ten interfejs jes bylejaki
|
||||
// !! moze lepiej zwracac id i kiedy nie ma katalogu to -1 (przeciez to jest wartosc ktora nie moze pojawic sie w indeksie)
|
||||
bool Dirs::GetDirId(const std::string & path, long * id)
|
||||
{
|
||||
Item * pitem;
|
||||
|
||||
if( !GetDir(path, &pitem) )
|
||||
return false;
|
||||
|
||||
*id = pitem->id;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::GetDirId(const std::string & name, long parent, long * id)
|
||||
{
|
||||
Item * pitem;
|
||||
|
||||
if( !GetDir(name, parent, &pitem) )
|
||||
return false;
|
||||
|
||||
*id = pitem->id;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Dirs::IsDir(long id)
|
||||
{
|
||||
DirContainer::Iterator i = dir_table.FindId(id);
|
||||
|
||||
if( i == dir_table.End() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Dirs::GetDirChilds(long parent, std::vector<Item> & childs_table)
|
||||
{
|
||||
if( parent != -1 && !IsDir(parent) )
|
||||
return false;
|
||||
|
||||
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
||||
|
||||
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
||||
childs_table.push_back( *i->second );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
|
||||
{
|
||||
if( parent != -1 && !IsDir(parent) )
|
||||
return false;
|
||||
|
||||
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
||||
|
||||
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
||||
childs_table.push_back( &(*i->second) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// dodatkowo moze metoda AppendPath dodajaca sciezke do biezacego stringa?
|
||||
// albo tutaj stringa nie czyscic?
|
||||
// O(m * log n) (m- how many parts are in 'id')
|
||||
bool Dirs::MakePath(long id, std::string & path)
|
||||
{
|
||||
DirContainer::Iterator i;
|
||||
|
||||
path = '/';
|
||||
|
||||
while( true )
|
||||
{
|
||||
i = dir_table.FindId(id);
|
||||
|
||||
if( i == dir_table.End() )
|
||||
return false;
|
||||
|
||||
if( i->parent_id == -1 )
|
||||
return true;
|
||||
|
||||
id = i->parent_id;
|
||||
|
||||
|
||||
path.insert(0, i->url);
|
||||
path.insert(path.begin(), '/');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// with exceptions
|
||||
|
||||
Item * Dirs::GetDirT(const std::string & path)
|
||||
{
|
||||
Item * pitem;
|
||||
|
||||
if( !GetDir(path, &pitem) )
|
||||
throw Error(Error::incorrect_dir);
|
||||
|
||||
return pitem;
|
||||
}
|
||||
|
||||
|
||||
Item * Dirs::GetDirT(const std::string & name, long parent)
|
||||
{
|
||||
Item * pitem;
|
||||
|
||||
if( !GetDir(name, parent, &pitem) )
|
||||
throw Error(Error::incorrect_dir);
|
||||
|
||||
return pitem;
|
||||
|
||||
}
|
||||
|
||||
|
||||
long Dirs::GetDirIdT(const std::string & path)
|
||||
{
|
||||
long id;
|
||||
|
||||
if( !GetDirId(path, &id) )
|
||||
throw Error(Error::incorrect_dir);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
long Dirs::GetDirIdT(const std::string & name, long parent)
|
||||
{
|
||||
long id;
|
||||
|
||||
if( !GetDirId(name, parent, &id) )
|
||||
throw Error(Error::incorrect_dir);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! nowy interfejs
|
||||
|
||||
|
||||
|
||||
Item * Dirs::GetRootDir()
|
||||
{
|
||||
DirContainer::Iterator root = dir_table.GetRoot();
|
||||
|
||||
if( root == dir_table.End() )
|
||||
return 0;
|
||||
|
||||
return &(*root);
|
||||
}
|
||||
|
||||
|
||||
Item * Dirs::GetDir(const std::string & name, long parent)
|
||||
{
|
||||
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
||||
|
||||
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
||||
if( i->second->url == name )
|
||||
return &(*i->second);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Item * Dirs::GetDir(const std::string & path)
|
||||
{
|
||||
DirContainer::Iterator root = dir_table.GetRoot();
|
||||
|
||||
if( root == dir_table.End() )
|
||||
// ops, we do not have a root dir
|
||||
return 0;
|
||||
|
||||
Item * pitem = &(*root);
|
||||
|
||||
std::string name;
|
||||
const char * s = path.c_str();
|
||||
|
||||
while( ExtractName(s, name) )
|
||||
{
|
||||
pitem = GetDir(name, pitem->id);
|
||||
|
||||
if( !pitem )
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return pitem;
|
||||
}
|
||||
|
||||
|
||||
Item * Dirs::GetDir(long id)
|
||||
{
|
||||
DirContainer::Iterator i = dir_table.FindId(id);
|
||||
|
||||
if( i == dir_table.End() )
|
||||
return 0;
|
||||
|
||||
return &(*i);
|
||||
}
|
||||
|
||||
89
core/dirs.h
89
core/dirs.h
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfiledirs
|
||||
#define headerfiledirs
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "db.h"
|
||||
#include "dircontainer.h"
|
||||
|
||||
|
||||
|
||||
class Dirs
|
||||
{
|
||||
|
||||
private:
|
||||
public: // !! temporarily
|
||||
|
||||
|
||||
DirContainer dir_table;
|
||||
|
||||
bool ExtractName(const char * & s, std::string & name);
|
||||
void CheckRootDir();
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void Clear();
|
||||
void ReadDirs();
|
||||
|
||||
// without any exceptions
|
||||
// these methods return false in a case the path or name (with a specific parent) are invalid
|
||||
// we do not support '..' in a path (for security reason)
|
||||
|
||||
bool IsDir(long id);
|
||||
|
||||
bool GetRootDir(Item ** item);
|
||||
|
||||
bool GetDir(const std::string & path, Item ** item);
|
||||
bool GetDir(const std::string & name, long parent, Item ** item);
|
||||
|
||||
bool GetDirId(const std::string & path, long * id);
|
||||
bool GetDirId(const std::string & name, long parent, long * id);
|
||||
|
||||
//!! ta nie bedzie chyba potrzebna
|
||||
bool GetDirChilds(long parent, std::vector<Item> & childs_table); // only returns dir-children
|
||||
|
||||
bool GetDirChilds(long parent, std::vector<Item*> & childs_table); // only returns dir-children
|
||||
|
||||
bool MakePath(long id, std::string & path);
|
||||
|
||||
|
||||
// with an Error exception
|
||||
// if the path or name are invalid these methods throw an exception
|
||||
Item * GetDirT(const std::string & path);
|
||||
Item * GetDirT(const std::string & name, long parent);
|
||||
long GetDirIdT(const std::string & path);
|
||||
long GetDirIdT(const std::string & name, long parent);
|
||||
|
||||
|
||||
|
||||
// !! nowy interfejs
|
||||
|
||||
// returns null if there is no a root dir
|
||||
Item * GetRootDir();
|
||||
Item * GetDir(const std::string & name, long parent);
|
||||
Item * GetDir(const std::string & path);
|
||||
Item * GetDir(long id);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "done.h"
|
||||
|
||||
|
||||
Done::Done()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Done::Done(Code c) : code(c)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Done & Done::operator=(Code c)
|
||||
{
|
||||
code = c;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool Done::operator==(Code c) const
|
||||
{
|
||||
return code == c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Done::operator!=(Code c) const
|
||||
{
|
||||
return code != c;
|
||||
}
|
||||
|
||||
|
||||
Done::operator int()
|
||||
{
|
||||
return static_cast<int>( code );
|
||||
}
|
||||
47
core/done.h
47
core/done.h
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfiledone
|
||||
#define headerfiledone
|
||||
|
||||
|
||||
|
||||
// what has been done
|
||||
class Done
|
||||
{
|
||||
public:
|
||||
|
||||
enum Code
|
||||
{
|
||||
none = 0,
|
||||
added_item,
|
||||
edited_item,
|
||||
deleted_item,
|
||||
privileged_item,
|
||||
loggedout
|
||||
};
|
||||
|
||||
|
||||
Done();
|
||||
Done(Code c);
|
||||
Done & operator=(Code c);
|
||||
bool operator==(Code c) const;
|
||||
bool operator!=(Code c) const;
|
||||
|
||||
operator int();
|
||||
|
||||
private:
|
||||
|
||||
Code code;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "error.h"
|
||||
|
||||
|
||||
|
||||
Error::Error()
|
||||
{
|
||||
code = unknown;
|
||||
}
|
||||
|
||||
|
||||
Error::Error(Code c) : code(c)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Error::Error(int i)
|
||||
{
|
||||
code = static_cast<Code>(i);
|
||||
}
|
||||
|
||||
|
||||
Error::Error(const Error & e)
|
||||
{
|
||||
code = e.code;
|
||||
}
|
||||
|
||||
|
||||
Error::operator int() const
|
||||
{
|
||||
return static_cast<int>(code);
|
||||
}
|
||||
|
||||
|
||||
Error & Error::operator=(Code c)
|
||||
{
|
||||
code = c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Error & Error::operator=(const Error & e)
|
||||
{
|
||||
code = e.code;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Error::operator==(Code c) const
|
||||
{
|
||||
return code == c;
|
||||
}
|
||||
|
||||
|
||||
bool Error::operator!=(Code c) const
|
||||
{
|
||||
return code != c;
|
||||
}
|
||||
|
||||
bool Error::operator==(const Error & e) const
|
||||
{
|
||||
return code == e.code;
|
||||
}
|
||||
|
||||
|
||||
bool Error::operator!=(const Error & e) const
|
||||
{
|
||||
return code != e.code;
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const Error & e)
|
||||
{
|
||||
out << static_cast<int>(e.code);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Log & operator<<(Log & out, const Error & e)
|
||||
{
|
||||
out << static_cast<int>(e.code);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
80
core/error.h
80
core/error.h
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileerror
|
||||
#define headerfileerror
|
||||
|
||||
#include <iostream>
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class Error
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum Code
|
||||
{
|
||||
ok = 0,
|
||||
incorrect_path,
|
||||
db_fatal_error_during_connecting,
|
||||
db_incorrect_query,
|
||||
db_incorrent_result_status,
|
||||
db_no_column,
|
||||
db_no_item, // !! zamienic na no_item
|
||||
db_incorrect_login,
|
||||
db_more_than_one_login,
|
||||
db_err_currval,
|
||||
no_postvar,
|
||||
incorrect_dir,
|
||||
cant_change_user,
|
||||
cant_change_group,
|
||||
cant_change_privileges,
|
||||
permision_denied, // !! permission_denied (dwa ss)
|
||||
no_root_dir,
|
||||
no_function, // !! zamienic na no_function
|
||||
|
||||
item_required, // !! zamienic na no_item (i usunac db_no_item)
|
||||
|
||||
unknown = 1000
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Error();
|
||||
Error(Code c);
|
||||
Error(int i);
|
||||
Error(const Error & e);
|
||||
Error & operator=(Code c);
|
||||
Error & operator=(const Error & e);
|
||||
|
||||
operator int() const;
|
||||
|
||||
bool operator==(Code c) const;
|
||||
bool operator!=(Code c) const;
|
||||
bool operator==(const Error & e) const;
|
||||
bool operator!=(const Error & e) const;
|
||||
|
||||
friend std::ostream & operator<<(std::ostream & out, const Error & e);
|
||||
friend Log & operator<<(Log & out, const Error & e);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Code code;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "function.h"
|
||||
|
||||
|
||||
|
||||
Function::Function()
|
||||
{
|
||||
code = none;
|
||||
}
|
||||
|
||||
|
||||
Function::Function(const Function & f)
|
||||
{
|
||||
code = f.code;
|
||||
item = f.item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Function & Function::operator=(const Function & f)
|
||||
{
|
||||
code = f.code;
|
||||
item = f.item;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilefunction
|
||||
#define headerfilefunction
|
||||
|
||||
#include <iostream>
|
||||
#include "log.h"
|
||||
#include "item.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class Function
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum Code
|
||||
{
|
||||
none,
|
||||
ls,
|
||||
cat,
|
||||
node,
|
||||
emacs,
|
||||
privileges,
|
||||
rm,
|
||||
login,
|
||||
logout
|
||||
};
|
||||
|
||||
|
||||
Code code;
|
||||
Item item;
|
||||
|
||||
|
||||
Function();
|
||||
Function(const Function & f);
|
||||
Function & operator=(const Function & f);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "functionparser.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::SkipEmptyString(const char * msg)
|
||||
{
|
||||
for( ; get_index != get_table_len && request.get_table[get_index].empty() ; ++get_index )
|
||||
log << log3 << msg << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseDirectories()
|
||||
{
|
||||
Item * pdir = data.dirs.GetRootDir();
|
||||
|
||||
if( !pdir )
|
||||
{
|
||||
// there is no the root dir
|
||||
request.status = Error::no_root_dir;
|
||||
return;
|
||||
}
|
||||
|
||||
while( true )
|
||||
{
|
||||
request.dir_table.push_back( pdir );
|
||||
log << log3 << "FP: Directory: ";
|
||||
|
||||
if( pdir->parent_id == -1 )
|
||||
log << "(root)" << logend;
|
||||
else
|
||||
log << pdir->url << logend;
|
||||
|
||||
SkipEmptyString("FP: Directory: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
break;
|
||||
|
||||
pdir = data.dirs.GetDir(request.get_table[get_index], pdir->id);
|
||||
|
||||
if( !pdir )
|
||||
break;
|
||||
|
||||
++get_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseItem()
|
||||
{
|
||||
SkipEmptyString("FP: Item: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
return;
|
||||
|
||||
// request.dir_table has at least one element
|
||||
long parent_id = request.dir_table.back()->id;
|
||||
const std::string & url = request.get_table[get_index];
|
||||
|
||||
request.status = db.GetItem(parent_id, url, request.item);
|
||||
|
||||
if( request.status == Error::ok )
|
||||
{
|
||||
++get_index;
|
||||
request.is_item = true;
|
||||
log << log3 << "FP: Item: id: " << request.item.id << ", url: " << request.item.url << logend;
|
||||
}
|
||||
else
|
||||
log << log3 << "FP: No Item: url: " << url << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseFunction()
|
||||
{
|
||||
SkipEmptyString("FP: Function: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
return;
|
||||
|
||||
request.pfunction = data.functions.GetFunction(request.get_table[get_index]);
|
||||
|
||||
|
||||
if( request.pfunction )
|
||||
{
|
||||
++get_index;
|
||||
log << log3 << "FP: Function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseParams()
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
SkipEmptyString("FP: Params: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
break;
|
||||
|
||||
request.param_table.push_back( &request.get_table[get_index] );
|
||||
log << log3 << "FP: Params: " << request.get_table[get_index] << logend;
|
||||
|
||||
++get_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::Parse()
|
||||
{
|
||||
request.status = Error::ok;
|
||||
get_index = 0;
|
||||
get_table_len = request.get_table.size();
|
||||
request.pfunction = 0;
|
||||
request.is_item = false;
|
||||
|
||||
ParseDirectories();
|
||||
|
||||
if( request.status != Error::ok )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
ParseItem();
|
||||
|
||||
if( request.status != Error::ok )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request.pfunction && get_index != get_table_len )
|
||||
{
|
||||
request.status = Error::no_function;
|
||||
log << log3 << "FP: Parse: unknown function: \"" << request.get_table[get_index] << "\"" << logend;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ParseParams();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilefunctionparser
|
||||
#define headerfilefunctionparser
|
||||
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "data.h"
|
||||
#include "db.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FunctionParser
|
||||
{
|
||||
GetTable::size_type get_index;
|
||||
GetTable::size_type get_table_len;
|
||||
|
||||
void SkipEmptyString(const char * msg);
|
||||
|
||||
void ParseDirectories();
|
||||
void ParseItem();
|
||||
void ParseFunction();
|
||||
void ParseParams();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void Parse();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Functions::Clear()
|
||||
{
|
||||
table.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Functions::ReadFunctions()
|
||||
{
|
||||
Clear();
|
||||
|
||||
Function f;
|
||||
|
||||
f.item.user_id = -1;
|
||||
f.item.group_id = -1;
|
||||
f.item.privileges = 0644;
|
||||
f.item.parent_id = -1; // !! temporarily doesn't matter
|
||||
f.item.id = -1;
|
||||
f.item.type = Item::file;
|
||||
|
||||
// in the future we will read these functions from the database
|
||||
f.code = Function::ls;
|
||||
f.item.url = "list";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
|
||||
f.code = Function::cat;
|
||||
f.item.url = "wyswietl";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
|
||||
f.code = Function::node;
|
||||
f.item.url = "node";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
|
||||
f.code = Function::emacs;
|
||||
f.item.url = "edytuj";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
|
||||
f.code = Function::privileges;
|
||||
f.item.url = "uprawnienia";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
|
||||
f.code = Function::rm;
|
||||
f.item.url = "usun";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
|
||||
f.code = Function::logout;
|
||||
f.item.url = "wyloguj";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
|
||||
f.code = Function::login;
|
||||
f.item.url = "login";
|
||||
table.insert( std::make_pair(f.item.url, f) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Function * Functions::GetFunction(const std::string & name)
|
||||
{
|
||||
Table::iterator i = table.find(name);
|
||||
|
||||
if( i == table.end() )
|
||||
return 0;
|
||||
|
||||
return &(i->second);
|
||||
}
|
||||
|
||||
|
||||
// !! in the future there will be a special container where we can search through the Code object
|
||||
Function * Functions::GetFunction(Function::Code code)
|
||||
{
|
||||
Table::iterator i = table.begin();
|
||||
|
||||
for( ; i != table.end() ; ++i )
|
||||
{
|
||||
if( i->second.code == code )
|
||||
return &(i->second);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilefunctions
|
||||
#define headerfilefunctions
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "function.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class Functions
|
||||
{
|
||||
|
||||
typedef std::map<std::string, Function> Table;
|
||||
Table table;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
void Clear();
|
||||
void ReadFunctions();
|
||||
|
||||
Function * GetFunction(const std::string & name);
|
||||
Function * GetFunction(Function::Code code);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilegetparser
|
||||
#define headerfilegetparser
|
||||
|
||||
#include "httpsimpleparser.h"
|
||||
#include "requesttypes.h"
|
||||
|
||||
|
||||
class GetParser : public HttpSimpleParser
|
||||
{
|
||||
|
||||
const char * get_string;
|
||||
GetTable & get_table;
|
||||
|
||||
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)
|
||||
{
|
||||
get_table.push_back(value);
|
||||
|
||||
log << log2 << "Get, value: \"" << value << "\"" << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
GetParser(const char * get_string_, GetTable & get_table_) : get_string(get_string_), get_table(get_table_)
|
||||
{
|
||||
HttpSimpleParser::separator = '/';
|
||||
HttpSimpleParser::read_name = false;
|
||||
|
||||
if( get_string && *get_string == separator ) // one '/' at the beginning
|
||||
++get_string;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
43
core/group.h
43
core/group.h
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilegroup
|
||||
#define headerfilegroup
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
struct Group
|
||||
{
|
||||
long id;
|
||||
std::string name; // group name
|
||||
std::vector<long> members; // users id
|
||||
|
||||
Group()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = -1;
|
||||
name.clear();
|
||||
members.clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
118
core/groups.cpp
118
core/groups.cpp
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "groups.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Groups::Groups()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Groups::Clear()
|
||||
{
|
||||
table.Clear();
|
||||
}
|
||||
|
||||
|
||||
void Groups::ReadGroups()
|
||||
{
|
||||
Clear();
|
||||
|
||||
db.GetGroups(table);
|
||||
}
|
||||
|
||||
|
||||
Group * Groups::GetGroup(long group_id)
|
||||
{
|
||||
Table::Iterator i = table.FindId(group_id);
|
||||
|
||||
if( i == table.End() )
|
||||
return 0;
|
||||
|
||||
return &(*i);
|
||||
}
|
||||
|
||||
|
||||
Group * Groups::GetGroup(const std::string & name)
|
||||
{
|
||||
Table::Iterator i = table.FindName(name);
|
||||
|
||||
if( i == table.End() )
|
||||
return 0;
|
||||
|
||||
return &(*i);
|
||||
}
|
||||
|
||||
|
||||
long Groups::GetGroupId(const std::string & name)
|
||||
{
|
||||
Group * pgroup = GetGroup(name);
|
||||
|
||||
if( !pgroup )
|
||||
return -1;
|
||||
|
||||
return pgroup->id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Groups::Iterator Groups::Begin()
|
||||
{
|
||||
return table.Begin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Groups::Iterator Groups::End()
|
||||
{
|
||||
return table.End();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Groups::SizeType Groups::Size()
|
||||
{
|
||||
return table.Size();
|
||||
}
|
||||
|
||||
|
||||
Group & Groups::operator[](Groups::SizeType pos)
|
||||
{
|
||||
return table[pos];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilegroups
|
||||
#define headerfilegroups
|
||||
|
||||
#include <map>
|
||||
#include "group.h"
|
||||
#include "db.h"
|
||||
#include "ugcontainer.h"
|
||||
|
||||
|
||||
class Groups
|
||||
{
|
||||
typedef UGContainer<Group> Table;
|
||||
|
||||
Table table;
|
||||
|
||||
public:
|
||||
|
||||
typedef Table::Iterator Iterator;
|
||||
typedef Table::SizeType SizeType;
|
||||
|
||||
Groups();
|
||||
void Clear();
|
||||
void ReadGroups();
|
||||
Group * GetGroup(long group_id);
|
||||
Group * GetGroup(const std::string & name);
|
||||
long GetGroupId(const std::string & name);
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
SizeType Size();
|
||||
Group & operator[](SizeType pos);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,231 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "httpsimpleparser.h"
|
||||
|
||||
|
||||
void HttpSimpleParser::ToLower(std::string & s)
|
||||
{
|
||||
std::string::iterator i;
|
||||
|
||||
for(i=s.begin() ; i!= s.end() ; ++i)
|
||||
{
|
||||
if( *i>='A' && *i<='Z' )
|
||||
*i = *i - 'A' + 'a';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool HttpSimpleParser::IsWhite(int c)
|
||||
{
|
||||
if( c==' ' || c=='\t' )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void HttpSimpleParser::SkipWhiteChars()
|
||||
{
|
||||
while( IsWhite(last_c) )
|
||||
last_c = GetChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if( c>='a' && c<='z' )
|
||||
c += 'A' - 'a'; // to upper case
|
||||
|
||||
|
||||
if( c >= 'A' )
|
||||
c = c - 'A' + 10;
|
||||
else
|
||||
c = c - '0';
|
||||
|
||||
c &= 0xf;
|
||||
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void HttpSimpleParser::CheckSpecialChar()
|
||||
{
|
||||
if( last_c == '%' )
|
||||
{
|
||||
int c1 = GetChar();
|
||||
int c2 = GetChar();
|
||||
|
||||
if( c1==-1 || c2==-1 )
|
||||
last_c = -1;
|
||||
|
||||
c1 = ParseHalfHex(c1);
|
||||
c2 = ParseHalfHex(c2);
|
||||
|
||||
last_c = (c1 << 4) + c2;
|
||||
}
|
||||
else
|
||||
if( last_c == '+' )
|
||||
{
|
||||
last_c = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void HttpSimpleParser::ReadName()
|
||||
{
|
||||
// we're checking 'separator' and '=' because the string is allowed not having '=' (the value is optional)
|
||||
|
||||
for( ; last_c!=-1 && last_c!=separator && last_c!='=' ; last_c = GetChar() )
|
||||
{
|
||||
if( recognize_special_chars )
|
||||
CheckSpecialChar();
|
||||
|
||||
if( last_c != -1 )
|
||||
last_name += last_c;
|
||||
}
|
||||
|
||||
|
||||
if( last_c == '=' )
|
||||
last_c = GetChar();
|
||||
}
|
||||
|
||||
|
||||
void HttpSimpleParser::ReadQuotedValue()
|
||||
{
|
||||
// skipping '"'
|
||||
last_c = GetChar();
|
||||
|
||||
|
||||
for( ; last_c!=-1 && last_c!='"' ; last_c = GetChar() )
|
||||
{
|
||||
if( recognize_special_chars )
|
||||
CheckSpecialChar();
|
||||
|
||||
if( last_c != -1 )
|
||||
last_value += last_c;
|
||||
}
|
||||
|
||||
|
||||
if( last_c == '"' )
|
||||
last_c = GetChar();
|
||||
|
||||
// looking for a separator (skipping)
|
||||
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
void HttpSimpleParser::ReadValue()
|
||||
{
|
||||
if( skip_white_chars )
|
||||
SkipWhiteChars();
|
||||
|
||||
if( value_can_be_quoted && last_c == '"' )
|
||||
{
|
||||
ReadQuotedValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
for( ; last_c!=-1 && last_c!=separator ; last_c = GetChar() )
|
||||
{
|
||||
if( recognize_special_chars )
|
||||
CheckSpecialChar();
|
||||
|
||||
if( last_c != -1 )
|
||||
last_value += last_c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( last_c == separator )
|
||||
last_c = GetChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void HttpSimpleParser::Parse()
|
||||
{
|
||||
for( last_c = GetChar() ; last_c != -1 ; )
|
||||
{
|
||||
last_name.clear();
|
||||
last_value.clear();
|
||||
|
||||
if( read_name )
|
||||
ReadName();
|
||||
|
||||
ReadValue();
|
||||
|
||||
if( skip_white_chars )
|
||||
{
|
||||
TrimWhiteChars(last_name);
|
||||
TrimWhiteChars(last_value);
|
||||
}
|
||||
|
||||
Parameter(last_name, last_value); // user definied function
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilehttpsimpleparser
|
||||
#define headerfilehttpsimpleparser
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
class HttpSimpleParser
|
||||
{
|
||||
protected:
|
||||
|
||||
bool read_name;
|
||||
bool value_can_be_quoted;
|
||||
bool skip_white_chars;
|
||||
bool recognize_special_chars;
|
||||
|
||||
int ParseHalfHex(int c);
|
||||
void ReadName();
|
||||
void ReadQuotedValue();
|
||||
void ReadValue();
|
||||
|
||||
std::string last_name;
|
||||
std::string last_value;
|
||||
|
||||
int last_c;
|
||||
int separator;
|
||||
|
||||
// '-1' means end (eof)
|
||||
virtual int GetChar() = 0;
|
||||
virtual void Parameter(std::string & last_name, std::string & last_value) = 0;
|
||||
|
||||
void ToLower(std::string & s);
|
||||
bool IsWhite(int c);
|
||||
|
||||
void SkipWhiteChars();
|
||||
void TrimWhiteChars(std::string & s);
|
||||
void CheckSpecialChar();
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
HttpSimpleParser()
|
||||
{
|
||||
separator = '&';
|
||||
read_name = true;
|
||||
value_can_be_quoted = false;
|
||||
skip_white_chars = false;
|
||||
recognize_special_chars = true;
|
||||
}
|
||||
|
||||
|
||||
void Parse();
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
95
core/item.h
95
core/item.h
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileitem
|
||||
#define headerfileitem
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
|
||||
struct Item
|
||||
{
|
||||
long id;
|
||||
|
||||
|
||||
long user_id;
|
||||
long group_id;
|
||||
int privileges;
|
||||
|
||||
|
||||
std::string subject;
|
||||
std::string content;
|
||||
std::string url;
|
||||
|
||||
|
||||
int content_type;
|
||||
|
||||
|
||||
enum Type
|
||||
{
|
||||
dir = 0,
|
||||
file = 1,
|
||||
|
||||
|
||||
|
||||
none = 1000
|
||||
};
|
||||
|
||||
Type type;
|
||||
|
||||
//item_type;
|
||||
|
||||
long parent_id;
|
||||
long default_item;
|
||||
|
||||
|
||||
// used by the database
|
||||
long content_id;
|
||||
|
||||
|
||||
Item()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = -1;
|
||||
|
||||
user_id = -1;
|
||||
group_id = -1;
|
||||
privileges = 0;
|
||||
|
||||
subject.clear();
|
||||
content.clear();
|
||||
url.clear();
|
||||
|
||||
content_type = 0;
|
||||
|
||||
type = none;
|
||||
parent_id = -1;
|
||||
default_item = -1;
|
||||
|
||||
content_id = -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
171
core/log.cpp
171
core/log.cpp
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
||||
Log::Log()
|
||||
{
|
||||
log_level = 3;
|
||||
current_level = 4; // nothing to log (call Init() first)
|
||||
}
|
||||
|
||||
|
||||
void Log::Init(int log_l, const std::string & log_f, bool log_std)
|
||||
{
|
||||
log_level = log_l;
|
||||
log_file = log_f;
|
||||
log_stdout = log_std;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Log & Log::operator<<(const char * s)
|
||||
{
|
||||
if( !s )
|
||||
return *this;
|
||||
|
||||
buffer << s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(const std::string & s)
|
||||
{
|
||||
buffer << s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(int s)
|
||||
{
|
||||
buffer << s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(long s)
|
||||
{
|
||||
buffer << s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Log & Log::operator<<(char s)
|
||||
{
|
||||
buffer << s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(size_t s)
|
||||
{
|
||||
buffer << s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Log & Log::operator<<(Manipulators m)
|
||||
{
|
||||
switch(m)
|
||||
{
|
||||
case logend:
|
||||
SaveLog();
|
||||
buffer.str( "" );
|
||||
break;
|
||||
|
||||
case log1:
|
||||
current_level = 1;
|
||||
break;
|
||||
|
||||
case log2:
|
||||
current_level = 2;
|
||||
break;
|
||||
|
||||
case log3:
|
||||
current_level = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Log::SaveLog()
|
||||
{
|
||||
int attempt = 2;
|
||||
|
||||
if( current_level > log_level )
|
||||
return;
|
||||
|
||||
if( log_stdout )
|
||||
std::cout << buffer.str() << std::endl;
|
||||
|
||||
|
||||
if( log_file.empty() )
|
||||
return;
|
||||
|
||||
std::ofstream file;
|
||||
|
||||
do
|
||||
{
|
||||
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
|
||||
|
||||
// if( !file )
|
||||
// sleep(1);
|
||||
}
|
||||
while( --attempt > 0 && !file );
|
||||
|
||||
if( !file )
|
||||
return;
|
||||
|
||||
file << buffer.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
57
core/log.h
57
core/log.h
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilelog
|
||||
#define headerfilelog
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
// !! dodac manipulator logsave, logi zostana zapisane pod koniec wykonywania jednego requesta (albo po kilku w zaleznosci od jakiejs opcji w konfigu)
|
||||
// logsave zostanie wywolane w requestcontroller.cpp przy konczeniu wykonywania requesta
|
||||
enum Manipulators { logend, log1, log2, log3 };
|
||||
|
||||
|
||||
|
||||
class Log
|
||||
{
|
||||
std::ostringstream buffer;
|
||||
int log_level, current_level;
|
||||
std::string log_file;
|
||||
bool log_stdout;
|
||||
|
||||
public:
|
||||
|
||||
Log();
|
||||
|
||||
void Init(int log_l, const std::string & log_f, bool log_std);
|
||||
|
||||
Log & operator<<(const char * s);
|
||||
Log & operator<<(const std::string & s);
|
||||
Log & operator<<(int s);
|
||||
Log & operator<<(long s);
|
||||
Log & operator<<(char s);
|
||||
Log & operator<<(size_t s);
|
||||
Log & operator<<(Manipulators m);
|
||||
|
||||
void SaveLog();
|
||||
};
|
||||
|
||||
|
||||
|
||||
extern Log log;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
118
core/main.cpp
118
core/main.cpp
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
#include "requestcontroller.h"
|
||||
#include "data.h"
|
||||
#include "log.h"
|
||||
#include "request.h"
|
||||
#include "db.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
|
||||
// singletons
|
||||
// first 'data' then 'log' then 'request'
|
||||
Data data;
|
||||
Log log;
|
||||
Request request;
|
||||
Db db;
|
||||
Config config;
|
||||
|
||||
|
||||
|
||||
|
||||
void signal_term(int)
|
||||
{
|
||||
log << log1 << "cmslu stopped" << logend;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void signal_hup(int)
|
||||
{
|
||||
log << log3 << "SIGHUP received" << logend;
|
||||
data.signal_hup = true;
|
||||
config.ReadConfig(false); /* errors not to stdout */
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_syntax()
|
||||
{
|
||||
std::cout << "Syntax:" << std::endl;
|
||||
std::cout << " cmslu.fcgi config_file" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argv, char ** argc)
|
||||
{
|
||||
RequestController req_controller;
|
||||
|
||||
std::srand(std::time(0));
|
||||
|
||||
if( argv != 2 )
|
||||
{
|
||||
print_syntax();
|
||||
return 1;
|
||||
}
|
||||
|
||||
data.config_file = argc[1];
|
||||
|
||||
|
||||
|
||||
if( !config.ReadConfig(true) ) /* errors to stdout */
|
||||
return 2;
|
||||
|
||||
|
||||
// closing descriptors only at the beginning
|
||||
close(2);
|
||||
|
||||
if( !data.log_stdout )
|
||||
{
|
||||
close(1);
|
||||
data.stdout_is_closed = true;
|
||||
}
|
||||
|
||||
|
||||
signal(SIGTERM, signal_term);
|
||||
signal(SIGINT, signal_term);
|
||||
signal(SIGHUP, signal_hup);
|
||||
|
||||
|
||||
while( true )
|
||||
{
|
||||
log.Init(data.log_level, data.log_file, data.log_stdout);
|
||||
db.Init(data.db_database, data.db_user, data.db_pass);
|
||||
|
||||
if( !req_controller.Init() )
|
||||
return 1;
|
||||
|
||||
log << log2 << "checking for table consistency:" << logend;
|
||||
// !! zrobic wyjatek dla root
|
||||
//db.CheckAllUrlSubject();
|
||||
|
||||
log << log1 << "cmslu started" << logend;
|
||||
|
||||
req_controller.Loop();
|
||||
|
||||
if( data.signal_hup )
|
||||
data.signal_hup = false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
190
core/misc.cpp
190
core/misc.cpp
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void ToString(std::string & s, int value)
|
||||
{
|
||||
static char buffer[50];
|
||||
|
||||
sprintf(buffer, "%d", value);
|
||||
s = buffer;
|
||||
}
|
||||
|
||||
|
||||
void ToString(std::string & s, long value)
|
||||
{
|
||||
static char buffer[50];
|
||||
|
||||
sprintf(buffer, "%ld", value);
|
||||
s = buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool CorrectUrlChar(char c)
|
||||
{
|
||||
if( (c >= 'a' && c <='z') ||
|
||||
(c >= 'A' && c <='Z') ||
|
||||
(c >= '0' && c <='9') ||
|
||||
(c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CorrectUrl(Item & item)
|
||||
{
|
||||
std::string::iterator i;
|
||||
|
||||
for(i = item.url.begin(); i!=item.url.end() ; ++i)
|
||||
{
|
||||
if( !CorrectUrlChar(*i) )
|
||||
{
|
||||
int c = ChangeLocalChar(*i);
|
||||
|
||||
if( CorrectUrlChar(c) )
|
||||
*i = c;
|
||||
else
|
||||
*i = '_';
|
||||
}
|
||||
}
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
|
||||
else
|
||||
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
||||
// url must begin with a letter
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
}
|
||||
|
||||
|
||||
void SetUrlFromSubject(Item & item)
|
||||
{
|
||||
item.url = item.subject;
|
||||
CorrectUrl(item);
|
||||
|
||||
/*
|
||||
std::string::iterator i;
|
||||
|
||||
item.url.clear();
|
||||
|
||||
for(i = item.subject.begin(); i!=item.subject.end() ; ++i)
|
||||
{
|
||||
int c = ChangeLocalChar(*i);
|
||||
|
||||
if( (c >= 'a' && c <='z') ||
|
||||
(c >= 'A' && c <='Z') ||
|
||||
(c >= '0' && c <='9') ||
|
||||
(c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
|
||||
)
|
||||
{
|
||||
item.url += c;
|
||||
}
|
||||
else
|
||||
item.url += '_';
|
||||
}
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
|
||||
else
|
||||
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
||||
// url must begin with a letter
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int polish_letters_simple[] =
|
||||
{ 'a', 'A',
|
||||
'c', 'C',
|
||||
's', 'S',
|
||||
'e', 'E',
|
||||
'l', 'L',
|
||||
'o', 'O',
|
||||
'z', 'Z',
|
||||
'z', 'Z',
|
||||
'n', 'N', 0 }; // 0 - terminating
|
||||
|
||||
|
||||
int polish_letters_iso88592[] =
|
||||
{ 0xb1, 0xa1,
|
||||
0xe6, 0xc6,
|
||||
0xb6, 0xa6,
|
||||
0xea, 0xca,
|
||||
0xb3, 0xa3,
|
||||
0xf3, 0xd3,
|
||||
0xbf, 0xaf,
|
||||
0xbc, 0xac,
|
||||
0xf1, 0xd1, 0 };
|
||||
|
||||
|
||||
|
||||
int ChangeLocalChar(unsigned char c)
|
||||
{
|
||||
// if( language == polish_iso88592 )
|
||||
|
||||
for(int i = 0 ; polish_letters_iso88592[i] ; ++i)
|
||||
{
|
||||
if( polish_letters_simple[i] == 0 )
|
||||
{
|
||||
log << log1 << "localization tables don't have the same size" << logend;
|
||||
return c;
|
||||
}
|
||||
|
||||
if( polish_letters_iso88592[i] == c )
|
||||
return polish_letters_simple[i];
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
void HtmlEscape(std::ostringstream & out, const std::string & in)
|
||||
{
|
||||
std::string::const_iterator i;
|
||||
|
||||
for(i = in.begin() ; i != in.end() ; ++i)
|
||||
{
|
||||
if( *i == '<' )
|
||||
out << "<";
|
||||
else
|
||||
if( *i == '>' )
|
||||
out << ">";
|
||||
else
|
||||
if( *i == '&' )
|
||||
out << "&";
|
||||
else
|
||||
out << *i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string HtmlEscape(const std::string & in)
|
||||
{
|
||||
std::ostringstream out;
|
||||
|
||||
HtmlEscape(out, in);
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
36
core/misc.h
36
core/misc.h
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilemisc
|
||||
#define headerfilemisc
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "log.h"
|
||||
#include "item.h"
|
||||
|
||||
#define MAJOR_VER 0
|
||||
#define MINOR_VER 2
|
||||
#define REVISION_VER 0
|
||||
|
||||
|
||||
void ToString(std::string & s, int value);
|
||||
void ToString(std::string & s, long value);
|
||||
int ChangeLocalChar(unsigned char c);
|
||||
|
||||
bool CorrectUrlChar(char c);
|
||||
void CorrectUrl(Item & item);
|
||||
void SetUrlFromSubject(Item & item);
|
||||
|
||||
void HtmlEscape(std::ostringstream & out, const std::string & in);
|
||||
std::string HtmlEscape(const std::string & in);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilepostparser
|
||||
#define headerfilepostparser
|
||||
|
||||
#include <fcgiapp.h>
|
||||
#include <string>
|
||||
#include "httpsimpleparser.h"
|
||||
#include "requesttypes.h"
|
||||
|
||||
|
||||
class PostParser : public HttpSimpleParser
|
||||
{
|
||||
|
||||
FCGX_Stream * in;
|
||||
PostTable & post_table;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual int GetChar()
|
||||
{
|
||||
return FCGX_GetChar(in);
|
||||
}
|
||||
|
||||
|
||||
virtual void Parameter(std::string & name, std::string & value)
|
||||
{
|
||||
std::pair<PostTable::iterator, bool> res = post_table.insert( std::make_pair(name, value) );
|
||||
|
||||
log << log2 << "Method POST, name: \"" << name << "\", value: \"" << value << "\"";
|
||||
|
||||
if( res.second == false )
|
||||
log << log2 << " (skipped)";
|
||||
|
||||
log << log2 << logend;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
PostParser(FCGX_Stream * in_, PostTable & post_table_) : in(in_), post_table(post_table_)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
481
core/request.cpp
481
core/request.cpp
@@ -1,481 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "request.h"
|
||||
|
||||
|
||||
|
||||
Request::Request() : char_empty(0)
|
||||
{
|
||||
id = 0;
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Request::Clear()
|
||||
{
|
||||
// warning: don't clear: in, out, err, env
|
||||
|
||||
// id is never 0
|
||||
if( ++id == 0 )
|
||||
++id;
|
||||
|
||||
get_table.clear();
|
||||
post_table.clear();
|
||||
cookie_table.clear();
|
||||
|
||||
method = none;
|
||||
|
||||
headers.str("");
|
||||
page.str("");
|
||||
debug.str("");
|
||||
|
||||
env_request_method = &char_empty;
|
||||
env_request_uri = &char_empty;
|
||||
env_http_cookie = &char_empty;
|
||||
env_remote_addr = &char_empty;
|
||||
env_http_host = &char_empty;
|
||||
|
||||
|
||||
session = 0;
|
||||
|
||||
result = err404; // !! tutaj moze cos lepszego, cos w stylu 'not implemented'
|
||||
|
||||
// dir = -1;
|
||||
// cur_dir_table.clear();
|
||||
item_table.clear();
|
||||
// dir_table2.clear();
|
||||
|
||||
item.Clear();
|
||||
str.clear();
|
||||
|
||||
dir_table.clear();
|
||||
is_item = false;
|
||||
pfunction = 0;
|
||||
param_table.clear();
|
||||
|
||||
status = Error::ok;
|
||||
}
|
||||
|
||||
|
||||
void Request::CopyFirstItem()
|
||||
{
|
||||
if( !request.item_table.empty() )
|
||||
request.item = request.item_table[0];
|
||||
else
|
||||
{
|
||||
request.item.Clear();
|
||||
|
||||
log << log1 << "Request::CopyFirstItem: item_table is empty" << logend;
|
||||
request.result = err_internal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// value can be null
|
||||
void Request::SetCookie(const char * name, const char * value)
|
||||
{
|
||||
request.headers << "Set-Cookie: " << name << "=";
|
||||
|
||||
if( value && value[0]!=0 )
|
||||
request.headers << value;
|
||||
else
|
||||
request.headers << "\"\"";
|
||||
|
||||
request.headers << "; path=/\r\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::SetCookie(const char * name, long value)
|
||||
{
|
||||
request.headers << "Set-Cookie: " << name << "=" << value << "; path=/\r\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Request::IsPostVar(const char * var)
|
||||
{
|
||||
PostTable::iterator p;
|
||||
|
||||
p = post_table.find(var);
|
||||
|
||||
if( p == post_table.end() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string & Request::PostVar(const char * var)
|
||||
{
|
||||
PostTable::iterator p;
|
||||
|
||||
p = post_table.find(var);
|
||||
|
||||
if( p == post_table.end() )
|
||||
{
|
||||
throw Error(Error::no_postvar);
|
||||
}
|
||||
|
||||
return p->second;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
bool Request::PostVar(const char * var, std::string & result)
|
||||
{
|
||||
PostTable::iterator p;
|
||||
|
||||
p = post_table.find(var);
|
||||
|
||||
if( p == post_table.end() )
|
||||
return false;
|
||||
|
||||
result = p->second;
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
void Request::PrintGetTable()
|
||||
{
|
||||
debug << "get_table: " << get_table.size() << "\n";
|
||||
|
||||
for(GetTable::iterator i = get_table.begin() ; i != get_table.end() ; ++i)
|
||||
debug << " \"" << *i << "\"\n";
|
||||
|
||||
debug << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Request::PrintEnv()
|
||||
{
|
||||
char ** e;
|
||||
|
||||
debug << "environment variables:\n";
|
||||
|
||||
for( e = env ; *e ; ++e )
|
||||
debug << ' ' << *e << "\n";
|
||||
|
||||
debug << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Request::PrintIn()
|
||||
{
|
||||
char buf[100];
|
||||
int buf_len = sizeof(buf) / sizeof(char);
|
||||
int len;
|
||||
|
||||
debug << "fcgi input:\n";
|
||||
|
||||
do
|
||||
{
|
||||
len = FCGX_GetStr(buf, buf_len - 1, in);
|
||||
|
||||
if( len != 0 )
|
||||
{
|
||||
buf[len] = 0;
|
||||
debug << buf;
|
||||
}
|
||||
}
|
||||
while( len == buf_len - 1 );
|
||||
|
||||
debug << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char * Request::SetEnvVar(const char * var)
|
||||
{
|
||||
const char * v = FCGX_GetParam(var, env);
|
||||
|
||||
if( v )
|
||||
return v;
|
||||
|
||||
// char_empty contains '\0'
|
||||
return &char_empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::ReadEnvVariables()
|
||||
{
|
||||
// we store that values because FCGX_GetParam has O(n) complexity
|
||||
// with this variables (env_*) we have O(1)
|
||||
|
||||
env_request_method = SetEnvVar("REQUEST_METHOD");
|
||||
env_request_uri = SetEnvVar("REQUEST_URI");
|
||||
env_http_cookie = SetEnvVar("HTTP_COOKIE");
|
||||
env_remote_addr = SetEnvVar("REMOTE_ADDR");
|
||||
env_http_host = SetEnvVar("HTTP_HOST");
|
||||
env_http_user_agent = SetEnvVar("HTTP_USER_AGENT");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::CheckMethod()
|
||||
{
|
||||
method = none;
|
||||
|
||||
if( env_request_method[0] == 'G' )
|
||||
method = get;
|
||||
else
|
||||
if( env_request_method[0] == 'P' )
|
||||
method = post;
|
||||
}
|
||||
|
||||
|
||||
void Request::ReadParameters()
|
||||
{
|
||||
// !!some parameters (get) we have always
|
||||
// if( method == get )
|
||||
{
|
||||
GetParser get_parser(env_request_uri, get_table);
|
||||
get_parser.Parse();
|
||||
}
|
||||
|
||||
if( method == post )
|
||||
{
|
||||
PostParser post_parser(in, post_table);
|
||||
post_parser.Parse();
|
||||
}
|
||||
|
||||
CookieParser cookie_parser(env_http_cookie, cookie_table);
|
||||
cookie_parser.Parse();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::StandardLog()
|
||||
{
|
||||
time_t t = std::time(0);
|
||||
std::tm * loct = std::localtime(&t);
|
||||
|
||||
char buffer[70];
|
||||
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
|
||||
int(loct->tm_mon + 1),
|
||||
int(loct->tm_mday),
|
||||
int(loct->tm_hour),
|
||||
int(loct->tm_min),
|
||||
int(loct->tm_sec));
|
||||
|
||||
log << log1 << buffer << env_remote_addr << ' ' << env_request_method << ' ' << env_request_uri << ' ' << env_http_user_agent << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// reading everything
|
||||
void Request::Read()
|
||||
{
|
||||
ReadEnvVariables();
|
||||
StandardLog();
|
||||
CheckMethod();
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Request::SendAll()
|
||||
{
|
||||
if( result == redirect )
|
||||
{
|
||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
|
||||
FCGX_FPrintF(out, "Location: %s\r\n", str.c_str());
|
||||
|
||||
log << log2 << "Redirect to: " << str << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
FCGX_PutS("Status: 200 OK\r\n", out);
|
||||
FCGX_PutS("Content-Type: Text/Html\r\n", out);
|
||||
}
|
||||
|
||||
|
||||
FCGX_PutS(headers.str().c_str(), out);
|
||||
FCGX_PutS("\r\n", out);
|
||||
|
||||
|
||||
if( result == redirect )
|
||||
// if there is a redirect we do not send a content
|
||||
return;
|
||||
|
||||
FCGX_PutS(page.str().c_str(), out);
|
||||
|
||||
const std::string & d = debug.str();
|
||||
|
||||
if( !d.empty() )
|
||||
{
|
||||
FCGX_PutS("\n<!--\n", out);
|
||||
FCGX_PutS(d.c_str(), out);
|
||||
FCGX_PutS("\n-->\n", out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::IsParam(const char * s)
|
||||
{
|
||||
std::vector<std::string*>::iterator i;
|
||||
|
||||
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
|
||||
{
|
||||
if( **i == s )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::CanChangeUser(const Item & item, long new_user_id)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.user_id != new_user_id )
|
||||
// only super user can change the owner of an item
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanChangeGroup(const Item & item, long new_group_id)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.group_id != new_group_id )
|
||||
{
|
||||
// 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'
|
||||
|
||||
if( !session->puser )
|
||||
return false;
|
||||
|
||||
if( session->puser->id != item.user_id )
|
||||
return false;
|
||||
|
||||
if( new_group_id == -1 )
|
||||
return true;
|
||||
|
||||
if( !session->puser->IsMemberOf(new_group_id) )
|
||||
return false;
|
||||
|
||||
// is logged, is the owner of the item, is the member of the new group
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanChangePrivileges(const Item & item, int new_priv)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.privileges != new_priv )
|
||||
{
|
||||
// the owner of an item is allowed to change the privileges
|
||||
|
||||
if( !session->puser )
|
||||
return false;
|
||||
|
||||
if( session->puser->id != item.user_id )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Request::HasAccess(const Item & item, int mask)
|
||||
{
|
||||
if( !session )
|
||||
// session must be set
|
||||
return false;
|
||||
|
||||
if( session->puser && session->puser->super_user )
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( session->puser && session->puser->id == item.user_id )
|
||||
{
|
||||
// the owner
|
||||
return ((item.privileges >> 6) & mask) == mask;
|
||||
}
|
||||
|
||||
if( session->puser && session->puser->IsMemberOf(item.group_id) )
|
||||
{
|
||||
// group
|
||||
return ((item.privileges >> 3) & mask) == mask;
|
||||
}
|
||||
|
||||
// others
|
||||
|
||||
return (item.privileges & mask) == mask;
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasReadAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 4);
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasWriteAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 2);
|
||||
}
|
||||
|
||||
bool Request::HasReadWriteAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 6); // r+w
|
||||
}
|
||||
|
||||
|
||||
bool Request::HasReadExecAccess(const Item & item)
|
||||
{
|
||||
return HasAccess(item, 5); // r+x
|
||||
}
|
||||
|
||||
|
||||
|
||||
176
core/request.h
176
core/request.h
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilerequest
|
||||
#define headerfilerequest
|
||||
|
||||
#include <fcgiapp.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include "requesttypes.h"
|
||||
#include "log.h"
|
||||
#include "session.h"
|
||||
|
||||
#include "getparser.h"
|
||||
#include "postparser.h"
|
||||
#include "cookieparser.h"
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "function.h"
|
||||
|
||||
|
||||
struct Request
|
||||
{
|
||||
// request id
|
||||
// is incremented for each request and is never 0
|
||||
// (from -1 will be incremented twice)
|
||||
// it's used for some optimalization e.g. in templates
|
||||
size_t id;
|
||||
|
||||
|
||||
FCGX_Stream * in, * out, * err;
|
||||
FCGX_ParamArray env; // defined as 'char **'
|
||||
|
||||
|
||||
enum Method { get, post, none } method;
|
||||
|
||||
|
||||
// headers, page and debug
|
||||
std::ostringstream headers, page, debug;
|
||||
|
||||
|
||||
GetTable get_table;
|
||||
PostTable post_table;
|
||||
CookieTable cookie_table;
|
||||
|
||||
// environment variables
|
||||
// they are not null -- when the server doesn't have such a variable it will be pointing into 'char_empty' which is default '\0'
|
||||
const char * env_request_method;
|
||||
const char * env_request_uri;
|
||||
const char * env_http_cookie;
|
||||
const char * env_remote_addr;
|
||||
const char * env_http_host;
|
||||
const char * env_http_user_agent;
|
||||
|
||||
// current session
|
||||
// is set after calling session_manager.SetSession()
|
||||
Session * session;
|
||||
|
||||
|
||||
// 'done_status' is set if 'done' is different than 'nothing'
|
||||
Error done_status; // !! wywalic - jest przeciez w session
|
||||
|
||||
// what to do
|
||||
enum Result { err_internal, err404, err_per_denied, show_dir, show_item, show_item_by_id, add_item, edit_item, del_item, del_item_confirm, confirm, redirect, logout } result; // zamienic na to_do
|
||||
|
||||
|
||||
|
||||
// !! nowe skladowe
|
||||
|
||||
// current directory
|
||||
// !! zapewnic aby byl minimum jeden katalog (root)
|
||||
|
||||
// !! moze nazwac to poprostu dir?
|
||||
std::vector<Item*> dir_table;
|
||||
|
||||
bool is_item;
|
||||
|
||||
// this item is used for many purposes such as editing, adding an item etc.
|
||||
Item item;
|
||||
|
||||
// null if there is no a function
|
||||
Function * pfunction;
|
||||
|
||||
// !! moze nazwac to poprostu param?
|
||||
std::vector<std::string*> param_table;
|
||||
|
||||
Error status;
|
||||
|
||||
// ------------------
|
||||
|
||||
// !! stare skladowe
|
||||
// current directory e.g. /foo/bar
|
||||
//std::vector<Item> cur_dir_table;
|
||||
// id of the last directory (bar) or -1
|
||||
//long dir;
|
||||
|
||||
// ------------------
|
||||
|
||||
// items in the current directory
|
||||
// maybe without contents?
|
||||
std::vector<Item> item_table;
|
||||
|
||||
// directories in the current directory
|
||||
//std::vector<Item> dir_table2;
|
||||
|
||||
|
||||
// this string is used for many purposes such as redirecting
|
||||
std::string str;
|
||||
|
||||
// for debugging
|
||||
void PrintGetTable();
|
||||
void PrintEnv();
|
||||
void PrintIn();
|
||||
|
||||
Request();
|
||||
void Clear();
|
||||
|
||||
|
||||
bool IsParam(const char * s);
|
||||
|
||||
void SetCookie(const char * name, const char * value);
|
||||
void SetCookie(const char * name, long value);
|
||||
|
||||
bool IsPostVar(const char * var);
|
||||
std::string & PostVar(const char * var); // with a throw
|
||||
//bool PostVar(const char * var, std::string & result);
|
||||
|
||||
// item_table[0] -> item
|
||||
// !! to tez nie bedzie potrzebne
|
||||
void CopyFirstItem();
|
||||
|
||||
|
||||
void ReadEnvVariables();
|
||||
void CheckMethod();
|
||||
void ReadParameters();
|
||||
void Read();
|
||||
void SendAll();
|
||||
|
||||
|
||||
bool CanChangeUser(const Item & item, long new_user_id);
|
||||
bool CanChangeGroup(const Item & item, long new_group_id);
|
||||
bool CanChangePrivileges(const Item & item, int new_priv);
|
||||
|
||||
bool HasAccess(const Item & item, int mask);
|
||||
bool HasReadAccess(const Item & item);
|
||||
bool HasWriteAccess(const Item & item);
|
||||
bool HasReadWriteAccess(const Item & item);
|
||||
bool HasReadExecAccess(const Item & item);
|
||||
|
||||
|
||||
private:
|
||||
// used to set some env_* variables into it, when the server didn't set that variable
|
||||
// it contains '\0'
|
||||
const char char_empty;
|
||||
|
||||
const char * SetEnvVar(const char * var);
|
||||
|
||||
void StandardLog();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
extern Request request;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "requestcontroller.h"
|
||||
|
||||
|
||||
|
||||
RequestController::RequestController()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RequestController::~RequestController()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
void RequestController::Close()
|
||||
{
|
||||
// don't call close(0)
|
||||
// it will be closed next time during dup(s,0)
|
||||
|
||||
// if you closed the descriptor here
|
||||
// then the database would have that descriptor (during connecting)
|
||||
// and there'll be a problem in the next loop (after SIGHUP)
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RequestController::Init()
|
||||
{
|
||||
const char * sock = data.fcgi_socket.c_str();
|
||||
|
||||
unlink(sock);
|
||||
|
||||
|
||||
|
||||
int s = FCGX_OpenSocket(sock, 10);
|
||||
|
||||
if( s < 0 )
|
||||
{
|
||||
log << log1 << "An error during creating a socket" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
chmod(sock, data.fcgi_socket_chmod);
|
||||
|
||||
passwd * pw = getpwnam(data.fcgi_socket_user.c_str());
|
||||
|
||||
if( !pw )
|
||||
{
|
||||
log << log1 << "There is no user: " << data.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
group * gr = getgrnam(data.fcgi_socket_group.c_str());
|
||||
|
||||
if( !gr )
|
||||
{
|
||||
log << log1 << "There is no group: " << data.fcgi_socket_group << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
chown(sock, pw->pw_uid, gr->gr_gid);
|
||||
|
||||
|
||||
|
||||
if( setuid(pw->pw_uid) < 0 )
|
||||
{
|
||||
log << log1 << "I can't change the user into: " << data.fcgi_socket_user << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if( setgid(gr->gr_gid) < 0 )
|
||||
{
|
||||
int e = errno;
|
||||
|
||||
log << log1 << "I can't change the group into: " << data.fcgi_socket_group << " " << gr->gr_gid << logend;
|
||||
log << log1 << "errno: " << e << logend;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
dup2(s, 0);
|
||||
|
||||
//
|
||||
|
||||
data.dirs.ReadDirs();
|
||||
data.users.ReadUsers();
|
||||
data.groups.ReadGroups();
|
||||
data.functions.ReadFunctions();
|
||||
//
|
||||
|
||||
if( !content.Init() )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RequestController::BaseUrlRedirect()
|
||||
{
|
||||
if( request.env_request_uri[0] == 0 )
|
||||
return false;
|
||||
|
||||
if( data.base_url_http_host == request.env_http_host )
|
||||
return false;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url + (request.env_request_uri + 1); // +1 means skipping the first slash from env_request_uri
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RequestController::Loop()
|
||||
{
|
||||
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
|
||||
{
|
||||
log << log2 << "---------------------------------------------------------------------------------" << logend;
|
||||
|
||||
try
|
||||
{
|
||||
request.Clear();
|
||||
request.Read();
|
||||
|
||||
// when BaseUrlRedirect() return true we didn't have to set everything in request.Read()
|
||||
// in the future request.Read() can be split and at the beginning only environment variables will be read
|
||||
// and then BaseUrlRedirect() will be called (for performance)
|
||||
if( !BaseUrlRedirect() )
|
||||
{
|
||||
session_manager.SetSession(); // set request.session as well
|
||||
request.session->CheckTimers();
|
||||
|
||||
function_parser.Parse();
|
||||
|
||||
content.Make();
|
||||
}
|
||||
|
||||
request.SendAll();
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
log << log1 << "uncaught std exception: " << e.what() << logend;
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "uncaught exception: Error: " << e << logend;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
log << log1 << "uncaught exception" << logend;
|
||||
}
|
||||
|
||||
|
||||
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
|
||||
if( data.signal_hup )
|
||||
{
|
||||
FCGX_Finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilerequestcontroller
|
||||
#define headerfilerequestcontroller
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "data.h"
|
||||
#include "log.h"
|
||||
#include "request.h"
|
||||
#include "../content/content.h"
|
||||
#include "sessionmanager.h"
|
||||
#include "postparser.h"
|
||||
#include "cookieparser.h"
|
||||
|
||||
|
||||
class RequestController
|
||||
{
|
||||
Content content;
|
||||
SessionManager session_manager;
|
||||
|
||||
bool BaseUrlRedirect();
|
||||
|
||||
FunctionParser function_parser;
|
||||
|
||||
public:
|
||||
|
||||
RequestController();
|
||||
~RequestController();
|
||||
|
||||
bool Init();
|
||||
void Close();
|
||||
void Loop();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilerequesttypes
|
||||
#define headerfilerequesttypes
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
// some global types used by Request class
|
||||
typedef std::vector<std::string> GetTable;
|
||||
typedef std::map<std::string, std::string> PostTable;
|
||||
typedef std::map<std::string, std::string> CookieTable;
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "session.h"
|
||||
|
||||
|
||||
Session::Session()
|
||||
{
|
||||
Clear();
|
||||
|
||||
time = std::time(0);
|
||||
}
|
||||
|
||||
|
||||
void Session::Clear()
|
||||
{
|
||||
id = 0;
|
||||
time = 0;
|
||||
puser = 0;
|
||||
done = Done::none;
|
||||
done_status = Error::ok;
|
||||
item.Clear();
|
||||
done_timer = 0;
|
||||
}
|
||||
|
||||
|
||||
bool Session::operator==(const Session & s) const
|
||||
{
|
||||
return id == s.id;
|
||||
}
|
||||
|
||||
|
||||
bool Session::operator<(const Session & s) const
|
||||
{
|
||||
return id < s.id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Session::DecTimer(int & timer)
|
||||
{
|
||||
if( timer == 0 )
|
||||
return false;
|
||||
|
||||
--timer;
|
||||
|
||||
if( timer == 0 )
|
||||
return true; // we must clear our variables
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Session::CheckTimers()
|
||||
{
|
||||
if( DecTimer(done_timer) )
|
||||
{
|
||||
done = Done::none;
|
||||
done_status = Error::ok;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecoresession
|
||||
#define headerfilecoresession
|
||||
|
||||
#include <ctime>
|
||||
#include "requesttypes.h"
|
||||
#include "error.h"
|
||||
#include "item.h"
|
||||
#include "done.h"
|
||||
#include "user.h"
|
||||
|
||||
|
||||
|
||||
struct Session
|
||||
{
|
||||
// 0 - means that there is no session
|
||||
long id;
|
||||
|
||||
// when this session was created
|
||||
int time;
|
||||
|
||||
// 0 - means that nobody is logged
|
||||
User * puser;
|
||||
|
||||
// what is done
|
||||
Done done;
|
||||
Error done_status;
|
||||
|
||||
int done_timer;
|
||||
|
||||
|
||||
// used for many purposes, depending on 'done'
|
||||
Item item;
|
||||
|
||||
|
||||
// -------------------
|
||||
|
||||
Session();
|
||||
virtual void Clear();
|
||||
bool operator==(const Session & s) const;
|
||||
bool operator<(const Session & s) const;
|
||||
bool DecTimer(int & timer);
|
||||
void CheckTimers();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sessionmanager.h"
|
||||
|
||||
|
||||
bool SessionManager::IsSession(long s)
|
||||
{
|
||||
SessionTable::iterator i;
|
||||
|
||||
Session temp;
|
||||
|
||||
temp.id = s;
|
||||
|
||||
i = session_table.find(temp);
|
||||
|
||||
if( i == session_table.end() )
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
long SessionManager::CreateSessionId()
|
||||
{
|
||||
long id;
|
||||
|
||||
// make sure to call std::srand() somewhere at the beginning
|
||||
// id must be != 0 (0 is reserved)
|
||||
do
|
||||
{
|
||||
if( sizeof(long) == 8 )
|
||||
{
|
||||
id = ((unsigned long)std::rand()) << 32 + std::rand();
|
||||
}
|
||||
else
|
||||
{
|
||||
id = std::rand();
|
||||
}
|
||||
|
||||
id += std::time(0);
|
||||
|
||||
if( id < 0 )
|
||||
id = -id;
|
||||
|
||||
}
|
||||
while( id == 0 ); // 0 reserved for a temporary session
|
||||
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::CreateTemporarySession()
|
||||
{
|
||||
Session s;
|
||||
|
||||
s.id = 0;
|
||||
SessionTable::iterator i = session_table.find( s ); // looking for id=0
|
||||
|
||||
if( i == session_table.end() )
|
||||
{
|
||||
std::pair<SessionTable::iterator,bool> res = session_table.insert(s);
|
||||
request.session = const_cast<Session*>( &(*res.first) );
|
||||
}
|
||||
else
|
||||
{
|
||||
request.session = const_cast<Session*>( &(*i) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::CreateSession()
|
||||
{
|
||||
Session s;
|
||||
int attempts = 100;
|
||||
|
||||
for( ; attempts > 0 ; --attempts )
|
||||
{
|
||||
s.id = CreateSessionId();
|
||||
|
||||
std::pair<SessionTable::iterator,bool> res = session_table.insert(s);
|
||||
|
||||
if( res.second == true )
|
||||
{
|
||||
// the insertion took place
|
||||
|
||||
request.session = const_cast<Session*>( &(*res.first) );
|
||||
request.SetCookie(data.http_session_id_name.c_str(), request.session->id);
|
||||
log << log1 << "created a new session: " << s.id << logend;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// there is a problem with generating a new session id
|
||||
// we do not set a session cookie
|
||||
CreateTemporarySession();
|
||||
log << log1 << "cannot create a session id (temporary used: with id 0)" << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionManager::SetSession()
|
||||
{
|
||||
CookieTable::iterator i = request.cookie_table.find(data.http_session_id_name);
|
||||
|
||||
if( i == request.cookie_table.end() )
|
||||
{
|
||||
CreateSession();
|
||||
}
|
||||
else
|
||||
{
|
||||
Session temp;
|
||||
temp.id = atol(i->second.c_str());
|
||||
SessionTable::iterator s = session_table.find(temp);
|
||||
|
||||
if( s != session_table.end() )
|
||||
{
|
||||
// that session is in the table
|
||||
request.session = const_cast<Session*>( &(*s) );
|
||||
log << log1 << "session: " << s->id << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is no such a session
|
||||
// deleting the old cookie
|
||||
request.cookie_table.erase(i);
|
||||
|
||||
// and creating a new one
|
||||
CreateSession();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// request.session is set now
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilesessionmanager
|
||||
#define headerfilesessionmanager
|
||||
|
||||
#include <set>
|
||||
#include <ctime>
|
||||
|
||||
#include "request.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
#include "session.h"
|
||||
#include "db.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class SessionManager
|
||||
{
|
||||
// !! zamienic na map
|
||||
typedef std::set<Session> SessionTable;
|
||||
|
||||
SessionTable session_table;
|
||||
|
||||
bool IsSession(long s);
|
||||
|
||||
long CreateSessionId();
|
||||
void CreateTemporarySession();
|
||||
void CreateSession();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void SetSession();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,191 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileugcontainer
|
||||
#define headerfileugcontainer
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
class UGContainer
|
||||
{
|
||||
|
||||
public:
|
||||
typedef typename std::vector<Type> Table;
|
||||
typedef typename Table::iterator Iterator;
|
||||
typedef typename Table::size_type SizeType;
|
||||
|
||||
typedef typename std::map<long, SizeType> TableId;
|
||||
typedef typename std::map<std::string, SizeType> TableName;
|
||||
|
||||
|
||||
UGContainer();
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
SizeType Size();
|
||||
bool Empty();
|
||||
Iterator PushBack(const Type & type);
|
||||
void Clear();
|
||||
|
||||
Iterator FindId(long id);
|
||||
Iterator FindName(const std::string & name);
|
||||
|
||||
Type & operator[](SizeType pos);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void AddIndexes(SizeType pos);
|
||||
void RebuildIndexes();
|
||||
|
||||
// main table
|
||||
Table table;
|
||||
|
||||
// indexes
|
||||
TableId table_id;
|
||||
TableName table_name;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
UGContainer<Type>::UGContainer() // : table(100)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename UGContainer<Type>::Iterator UGContainer<Type>::Begin()
|
||||
{
|
||||
return table.begin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename UGContainer<Type>::Iterator UGContainer<Type>::End()
|
||||
{
|
||||
return table.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename UGContainer<Type>::SizeType UGContainer<Type>::Size()
|
||||
{
|
||||
return table.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool UGContainer<Type>::Empty()
|
||||
{
|
||||
return table.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename UGContainer<Type>::Iterator UGContainer<Type>::PushBack(const Type & type)
|
||||
{
|
||||
table.push_back(type);
|
||||
log << log2 << "UGCont: added, id: " << type.id << ", name: " << type.name << logend;
|
||||
|
||||
AddIndexes( table.size() - 1 );
|
||||
|
||||
return --table.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
void UGContainer<Type>::Clear()
|
||||
{
|
||||
table.clear();
|
||||
table_id.clear();
|
||||
table_name.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename UGContainer<Type>::Iterator UGContainer<Type>::FindId(long id)
|
||||
{
|
||||
typename TableId::iterator i = table_id.find(id);
|
||||
|
||||
if( i == table_id.end() )
|
||||
return table.end();
|
||||
|
||||
return table.begin() + i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename UGContainer<Type>::Iterator UGContainer<Type>::FindName(const std::string & name)
|
||||
{
|
||||
typename TableName::iterator i = table_name.find(name);
|
||||
|
||||
if( i == table_name.end() )
|
||||
return table.end();
|
||||
|
||||
return table.begin() + i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
void UGContainer<Type>::AddIndexes(UGContainer<Type>::SizeType pos)
|
||||
{
|
||||
table_id.insert( std::make_pair(table[pos].id, pos) );
|
||||
table_name.insert( std::make_pair(table[pos].name, pos) );
|
||||
|
||||
log << log2 << "UGCont: added indexes to: id: " << table[pos].id << ", name: " << table[pos].name << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
void UGContainer<Type>::RebuildIndexes()
|
||||
{
|
||||
log << log2 << "UGCont: rebuilding indexes" << logend;
|
||||
|
||||
table_id.clear();
|
||||
table_name.clear();
|
||||
|
||||
SizeType i, len = table.size();
|
||||
|
||||
|
||||
for(i=0 ; i!=len ; ++i)
|
||||
AddIndexes( i );
|
||||
|
||||
log << log2 << "UGCont: indexes rebuilt, table.size: " << table.size() << ", table_id.size: "
|
||||
<< table_id.size() << ", table_name.size: " << table_name.size() << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type & UGContainer<Type>::operator[](UGContainer<Type>::SizeType pos)
|
||||
{
|
||||
if( pos >= table.size() )
|
||||
throw std::out_of_range("UGContainer: operator[]: index is out of range");
|
||||
|
||||
return table[pos];
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
53
core/user.h
53
core/user.h
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileuser
|
||||
#define headerfileuser
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct User
|
||||
{
|
||||
long id;
|
||||
std::string name;
|
||||
bool super_user;
|
||||
std::vector<long> groups;
|
||||
|
||||
User()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = -1;
|
||||
name.clear();
|
||||
super_user = false;
|
||||
groups.clear();
|
||||
}
|
||||
|
||||
|
||||
bool IsMemberOf(long group)
|
||||
{
|
||||
std::vector<long>::iterator i;
|
||||
|
||||
for(i=groups.begin() ; i!=groups.end() ; ++i)
|
||||
if( *i == group )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
109
core/users.cpp
109
core/users.cpp
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "users.h"
|
||||
|
||||
|
||||
|
||||
Users::Users()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Users::Clear()
|
||||
{
|
||||
table.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Users::ReadUsers()
|
||||
{
|
||||
Clear();
|
||||
|
||||
db.GetUsers(table);
|
||||
}
|
||||
|
||||
|
||||
|
||||
User * Users::GetUser(long user_id)
|
||||
{
|
||||
Table::Iterator i = table.FindId(user_id);
|
||||
|
||||
if( i == table.End() )
|
||||
return 0;
|
||||
|
||||
return &(*i);
|
||||
}
|
||||
|
||||
|
||||
User * Users::GetUser(const std::string & name)
|
||||
{
|
||||
Table::Iterator i = table.FindName(name);
|
||||
|
||||
if( i == table.End() )
|
||||
return 0;
|
||||
|
||||
return &(*i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
long Users::GetUserId(const std::string & name)
|
||||
{
|
||||
User * puser = GetUser(name);
|
||||
|
||||
if( !puser )
|
||||
return -1;
|
||||
|
||||
return puser->id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Users::Iterator Users::Begin()
|
||||
{
|
||||
return table.Begin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Users::Iterator Users::End()
|
||||
{
|
||||
return table.End();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Users::SizeType Users::Size()
|
||||
{
|
||||
return table.Size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
User & Users::operator[](Users::SizeType pos)
|
||||
{
|
||||
return table[pos];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
54
core/users.h
54
core/users.h
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfileusers
|
||||
#define headerfileusers
|
||||
|
||||
#include <map>
|
||||
#include "user.h"
|
||||
#include "db.h"
|
||||
#include "ugcontainer.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class Users
|
||||
{
|
||||
|
||||
typedef UGContainer<User> Table;
|
||||
Table table;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
typedef Table::Iterator Iterator;
|
||||
typedef Table::SizeType SizeType;
|
||||
|
||||
|
||||
Users();
|
||||
void Clear();
|
||||
void ReadUsers();
|
||||
User * GetUser(long user_id);
|
||||
User * GetUser(const std::string & name);
|
||||
long GetUserId(const std::string & name);
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
SizeType Size();
|
||||
User & operator[](SizeType pos);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
o = templates.o sys.o item.o doc.o user.o dir.o done.o priv.o
|
||||
|
||||
|
||||
all: templates.a
|
||||
|
||||
templates.a: $(o)
|
||||
ar rcs templates.a $(o)
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. -f- *.cpp > Makefile.dep
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.a
|
||||
|
||||
|
||||
include Makefile.dep
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
dir.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
dir.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
dir.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
dir.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
dir.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
dir.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
dir.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
dir.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
dir.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
dir.o: ../core/log.h
|
||||
doc.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
doc.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
doc.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
doc.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
doc.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
doc.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
doc.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
doc.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
doc.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
doc.o: ../core/log.h
|
||||
done.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
done.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
done.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
done.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
done.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
done.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
done.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
done.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
done.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
done.o: ../core/log.h
|
||||
item.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
item.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
item.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
item.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
item.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
item.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
item.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
item.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
item.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
item.o: ../core/log.h
|
||||
priv.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
priv.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
priv.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
priv.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
priv.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
priv.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
priv.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
priv.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
priv.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
priv.o: ../core/log.h
|
||||
sys.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
sys.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
sys.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
sys.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
sys.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
sys.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
sys.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
sys.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
sys.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
sys.o: ../core/log.h
|
||||
templates.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
templates.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
templates.o: ../core/db.h ../core/dircontainer.h ../core/user.h
|
||||
templates.o: ../core/group.h ../core/ugcontainer.h ../core/users.h
|
||||
templates.o: ../core/groups.h ../core/functions.h ../core/function.h
|
||||
templates.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
templates.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
|
||||
templates.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
|
||||
templates.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
|
||||
templates.o: ../core/users.h ../core/groups.h ../core/log.h
|
||||
user.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
|
||||
user.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
|
||||
user.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
|
||||
user.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
|
||||
user.o: ../core/functions.h ../core/function.h ../core/request.h
|
||||
user.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
user.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
|
||||
user.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
|
||||
user.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
|
||||
user.o: ../core/log.h
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void dir(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a<request.dir_table.size() ; ++a)
|
||||
{
|
||||
HtmlEscape(i.out, request.dir_table[a]->url);
|
||||
i.out << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static std::vector<Item*> dir_childs_table;
|
||||
static size_t dir_childs_index;
|
||||
|
||||
// request.id is never 0 and we can start dir_childs_reqid from 0
|
||||
static size_t dir_childs_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void dir_childs_tab(Info & i)
|
||||
{
|
||||
if( dir_childs_reqid != request.id )
|
||||
{
|
||||
dir_childs_reqid = request.id;
|
||||
dir_childs_table.clear();
|
||||
|
||||
if( !request.dir_table.empty() )
|
||||
data.dirs.GetDirChilds(request.dir_table.back()->id, dir_childs_table);
|
||||
}
|
||||
|
||||
dir_childs_index = i.iter;
|
||||
i.result = dir_childs_index < dir_childs_table.size();
|
||||
}
|
||||
|
||||
|
||||
void dir_childs_tab_url(Info & i)
|
||||
{
|
||||
if( dir_childs_index < dir_childs_table.size() )
|
||||
HtmlEscape(i.out, dir_childs_table[dir_childs_index]->url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t dir_index;
|
||||
|
||||
|
||||
void dir_tab(Info & i)
|
||||
{
|
||||
dir_index = i.iter;
|
||||
i.result = dir_index < request.dir_table.size();
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_url(Info & i)
|
||||
{
|
||||
if( dir_index < request.dir_table.size() )
|
||||
HtmlEscape(i.out, request.dir_table[dir_index]->url);
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_link(Info & i)
|
||||
{
|
||||
i.out << data.base_url;
|
||||
|
||||
for(size_t a = 0 ; a <= dir_index && a < request.dir_table.size() ; ++a)
|
||||
{
|
||||
HtmlEscape(i.out, request.dir_table[a]->url);
|
||||
i.out << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void doc_language(Info & i)
|
||||
{
|
||||
// at the moment only Polish language
|
||||
i.out << "pl";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_title(Info & i)
|
||||
{
|
||||
size_t a = 0;
|
||||
|
||||
// from 1 means skipping the root directory
|
||||
for(a = 1 ; a<request.dir_table.size() ; ++a)
|
||||
i.out << " / " << request.dir_table[a]->url;
|
||||
|
||||
if( request.is_item )
|
||||
i.out << " / " << request.item.subject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_charset(Info & i)
|
||||
{
|
||||
i.out << "iso-8859-2";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void doc_base_url(Info & i)
|
||||
{
|
||||
i.out << data.base_url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_current_url(Info & i)
|
||||
{
|
||||
i.out << request.env_request_uri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_status_error(Info & i)
|
||||
{
|
||||
i.result = request.status != Error::ok;
|
||||
}
|
||||
|
||||
|
||||
void doc_status_code(Info & i)
|
||||
{
|
||||
i.out << static_cast<int>( request.status );
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void done_errors(Info & i)
|
||||
{
|
||||
i.result = request.session->done_status != Error::ok;
|
||||
}
|
||||
|
||||
|
||||
void done_status(Info & i)
|
||||
{
|
||||
i.out << static_cast<int>( request.session->done_status );
|
||||
}
|
||||
|
||||
|
||||
void done_status_incorrect_dir(Info & i)
|
||||
{
|
||||
i.result = request.session->done_status == Error::incorrect_dir;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void done_added_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::added_item;
|
||||
}
|
||||
|
||||
|
||||
void done_edited_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::edited_item;
|
||||
}
|
||||
|
||||
|
||||
void done_deleted_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::deleted_item;
|
||||
}
|
||||
|
||||
|
||||
void done_privileged_item(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::privileged_item;
|
||||
}
|
||||
|
||||
|
||||
void done_loggedout(Info & i)
|
||||
{
|
||||
i.result = request.session->done == Done::loggedout;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void item_is(Info & i)
|
||||
{
|
||||
i.result = request.is_item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_id(Info & i)
|
||||
{
|
||||
i.out << request.item.id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_subject(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.item.subject);
|
||||
}
|
||||
|
||||
|
||||
void item_subject_noescape(Info & i)
|
||||
{
|
||||
i.out << request.item.subject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_content(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.item.content);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_content_noescape(Info & i)
|
||||
{
|
||||
i.out << request.item.content;
|
||||
}
|
||||
|
||||
|
||||
void item_privileges(Info & i)
|
||||
{
|
||||
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
||||
}
|
||||
|
||||
|
||||
void item_dir(Info & i)
|
||||
{
|
||||
dir(i);
|
||||
}
|
||||
|
||||
|
||||
void item_url(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.item.url);
|
||||
}
|
||||
|
||||
|
||||
void item_link(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, data.base_url);
|
||||
item_dir(i);
|
||||
item_url(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void item_old_id(Info & i)
|
||||
{
|
||||
i.out << request.session->item.id;
|
||||
}
|
||||
|
||||
|
||||
void item_old_subject(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.session->item.subject);
|
||||
}
|
||||
|
||||
|
||||
void item_old_subject_noescape(Info & i)
|
||||
{
|
||||
i.out << request.session->item.subject;
|
||||
}
|
||||
|
||||
|
||||
void item_old_content(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.session->item.content);
|
||||
}
|
||||
|
||||
|
||||
void item_old_content_noescape(Info & i)
|
||||
{
|
||||
i.out << request.session->item.content;
|
||||
}
|
||||
|
||||
|
||||
void item_old_privileges(Info & i)
|
||||
{
|
||||
i.out << std::setbase(8) << request.session->item.privileges << std::setbase(10);
|
||||
}
|
||||
|
||||
|
||||
void item_old_dir(Info & i)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
if( data.dirs.MakePath(request.session->item.parent_id, path) )
|
||||
HtmlEscape(i.out, path);
|
||||
else
|
||||
i.out << "/the path does not exist/";
|
||||
}
|
||||
|
||||
|
||||
void item_old_url(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.session->item.url);
|
||||
}
|
||||
|
||||
|
||||
void item_old_link(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, data.base_url);
|
||||
item_old_dir(i);
|
||||
item_old_url(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t item_index;
|
||||
|
||||
|
||||
void item_tab(Info & i)
|
||||
{
|
||||
item_index = i.iter;
|
||||
i.result = item_index < request.item_table.size();
|
||||
}
|
||||
|
||||
|
||||
void item_tab_id(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << request.item_table[item_index].id;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_subject(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
HtmlEscape(i.out, request.item_table[item_index].subject);
|
||||
}
|
||||
|
||||
void item_tab_subject_noescape(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << request.item_table[item_index].subject;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_content(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
HtmlEscape(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_content_noescape(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << request.item_table[item_index].content;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_privileges(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
i.out << std::setbase(8) << request.item_table[item_index].privileges << std::setbase(10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_dir(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
{
|
||||
std::string path;
|
||||
|
||||
if( data.dirs.MakePath(request.item_table[item_index].parent_id, path) )
|
||||
HtmlEscape(i.out, path);
|
||||
else
|
||||
i.out << "/the path does not exist/";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_url(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
HtmlEscape(i.out, request.item_table[item_index].url);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_link(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
{
|
||||
HtmlEscape(i.out, data.base_url);
|
||||
item_tab_dir(i);
|
||||
item_tab_url(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
static std::vector<long> priv_user_table;
|
||||
static size_t priv_user_index;
|
||||
static size_t priv_user_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_init()
|
||||
{
|
||||
priv_user_reqid = request.id;
|
||||
priv_user_table.clear();
|
||||
|
||||
if( !request.session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_user_table.push_back(request.item.user_id);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->super_user )
|
||||
{
|
||||
// super user is allowed to change to any user
|
||||
for(size_t i=0 ; i<data.users.Size() ; ++i)
|
||||
priv_user_table.push_back( data.users[i].id );
|
||||
|
||||
// as well to nobody (-1)
|
||||
priv_user_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// others
|
||||
priv_user_table.push_back(request.item.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_user_tab(Info & i)
|
||||
{
|
||||
if( priv_user_reqid != request.id )
|
||||
priv_user_tab_init();
|
||||
|
||||
priv_user_index = i.iter;
|
||||
i.result = priv_user_index < priv_user_table.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_name(Info & i)
|
||||
{
|
||||
if( priv_user_index < priv_user_table.size() )
|
||||
{
|
||||
long uid = priv_user_table[priv_user_index];
|
||||
|
||||
if( uid != -1 )
|
||||
{
|
||||
User * puser = data.users.GetUser( uid );
|
||||
|
||||
if( puser )
|
||||
HtmlEscape(i.out, puser->name);
|
||||
else
|
||||
i.out << "user_id: " << uid;
|
||||
}
|
||||
else
|
||||
{
|
||||
HtmlEscape(i.out, data.priv_no_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_isdefault(Info & i)
|
||||
{
|
||||
if( priv_user_index < priv_user_table.size() )
|
||||
{
|
||||
long uid = priv_user_table[priv_user_index];
|
||||
|
||||
if( uid == request.item.user_id )
|
||||
i.result = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static std::vector<long> priv_group_table;
|
||||
static size_t priv_group_index;
|
||||
static size_t priv_group_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_init()
|
||||
{
|
||||
priv_group_reqid = request.id;
|
||||
priv_group_table.clear();
|
||||
|
||||
if( !request.session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->super_user )
|
||||
{
|
||||
// super user is allowed to change to any group
|
||||
for(size_t i=0 ; i<data.groups.Size() ; ++i)
|
||||
priv_group_table.push_back( data.groups[i].id );
|
||||
|
||||
// as well to nogroup (-1)
|
||||
priv_group_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->id == request.item.user_id )
|
||||
{
|
||||
bool was_current_group = false;
|
||||
// owner of the item -- is allowed to change only to a group in which he belongs to
|
||||
for(size_t i=0 ; i<request.session->puser->groups.size() ; ++i)
|
||||
{
|
||||
priv_group_table.push_back( request.session->puser->groups[i] );
|
||||
|
||||
if( request.item.group_id == request.session->puser->groups[i] )
|
||||
was_current_group = true;
|
||||
}
|
||||
|
||||
// we're showing the item.group_id if it's different
|
||||
if( !was_current_group )
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
|
||||
// switching to -1 is allowed too
|
||||
priv_group_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not the owner and not a super user -- the same as not logged
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_group_tab(Info & i)
|
||||
{
|
||||
if( priv_group_reqid != request.id )
|
||||
priv_group_tab_init();
|
||||
|
||||
priv_group_index = i.iter;
|
||||
i.result = priv_group_index < priv_group_table.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_name(Info & i)
|
||||
{
|
||||
if( priv_group_index < priv_group_table.size() )
|
||||
{
|
||||
long gid = priv_group_table[priv_group_index];
|
||||
|
||||
if( gid != -1 )
|
||||
{
|
||||
Group * pgroup = data.groups.GetGroup( gid );
|
||||
|
||||
if( pgroup )
|
||||
HtmlEscape(i.out, pgroup->name);
|
||||
else
|
||||
i.out << "group_id: " << gid;
|
||||
}
|
||||
else
|
||||
{
|
||||
HtmlEscape(i.out, data.priv_no_group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_isdefault(Info & i)
|
||||
{
|
||||
if( priv_group_index < priv_group_table.size() )
|
||||
{
|
||||
long gid = priv_group_table[priv_group_index];
|
||||
|
||||
if( gid == request.item.group_id )
|
||||
i.result = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void sys_ver_major(Info & i)
|
||||
{
|
||||
i.out << MAJOR_VER;
|
||||
}
|
||||
|
||||
|
||||
void sys_ver_minor(Info & i)
|
||||
{
|
||||
i.out << MINOR_VER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void sys_ver_revision(Info & i)
|
||||
{
|
||||
i.out << REVISION_VER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
@@ -1,312 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
Ezc::Pattern pat_index;
|
||||
Ezc::Pattern pat_fun_cat;
|
||||
Ezc::Pattern pat_fun_ls;
|
||||
Ezc::Pattern pat_fun_emacs;
|
||||
Ezc::Pattern pat_fun_privileges;
|
||||
Ezc::Pattern pat_fun_rm;
|
||||
Ezc::Pattern pat_err_item_required;
|
||||
Ezc::Pattern pat_err_404;
|
||||
Ezc::Pattern pat_err_per_denied;
|
||||
Ezc::Pattern pat_err_others;
|
||||
|
||||
|
||||
|
||||
Ezc::Functions functions;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// !! tymczasowa funkcja
|
||||
void is_group_tv(Info & i)
|
||||
{
|
||||
long gid = data.groups.GetGroupId("tv");
|
||||
|
||||
if( request.session->puser && request.session->puser->IsMemberOf(gid) )
|
||||
i.result = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * content_for_function()
|
||||
{
|
||||
Ezc::Pattern * p = 0;
|
||||
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Templates: no function" << logend;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
switch( request.pfunction->code )
|
||||
{
|
||||
case Function::cat:
|
||||
p = &pat_fun_cat;
|
||||
break;
|
||||
|
||||
case Function::ls:
|
||||
p = &pat_fun_ls;
|
||||
break;
|
||||
|
||||
case Function::rm:
|
||||
p = &pat_fun_rm;
|
||||
break;
|
||||
|
||||
case Function::emacs:
|
||||
p = &pat_fun_emacs;
|
||||
break;
|
||||
|
||||
case Function::privileges:
|
||||
p = &pat_fun_privileges;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void content(Info & i)
|
||||
{
|
||||
Ezc::Pattern * p = 0;
|
||||
|
||||
switch( request.status )
|
||||
{
|
||||
case Error::ok:
|
||||
p = content_for_function();
|
||||
break;
|
||||
|
||||
case Error::item_required:
|
||||
p = &pat_err_item_required;
|
||||
break;
|
||||
|
||||
case Error::permision_denied:
|
||||
p = &pat_err_per_denied;
|
||||
break;
|
||||
|
||||
case Error::db_no_item:
|
||||
case Error::no_function:
|
||||
p = &pat_err_404;
|
||||
break;
|
||||
|
||||
default:
|
||||
p = &pat_err_others;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if( p )
|
||||
{
|
||||
Ezc::Generator gen(i.out, *p, functions);
|
||||
gen.Generate();
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "<!-- there are not any patterns -->";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
void Templates::CreateFunctions()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
functions.Clear();
|
||||
|
||||
|
||||
/*
|
||||
sys
|
||||
*/
|
||||
functions.Insert("sys_ver_major", sys_ver_major);
|
||||
functions.Insert("sys_ver_minor", sys_ver_minor);
|
||||
functions.Insert("sys_ver_revision", sys_ver_revision);
|
||||
|
||||
|
||||
/*
|
||||
doc
|
||||
*/
|
||||
functions.Insert("doc_language", doc_language);
|
||||
functions.Insert("doc_title", doc_title);
|
||||
functions.Insert("doc_charset", doc_charset);
|
||||
functions.Insert("doc_base_url", doc_base_url);
|
||||
functions.Insert("doc_current_url", doc_current_url);
|
||||
functions.Insert("doc_status_error", doc_status_error);
|
||||
functions.Insert("doc_status_code", doc_status_code);
|
||||
|
||||
|
||||
/*
|
||||
item
|
||||
*/
|
||||
functions.Insert("item_is", item_is);
|
||||
functions.Insert("item_id", item_id);
|
||||
functions.Insert("item_subject", item_subject);
|
||||
functions.Insert("item_subject_noescape", item_subject_noescape);
|
||||
functions.Insert("item_content", item_content);
|
||||
functions.Insert("item_content_noescape", item_content_noescape);
|
||||
functions.Insert("item_privileges", item_privileges);
|
||||
functions.Insert("item_dir", item_dir);
|
||||
functions.Insert("item_url", item_url);
|
||||
functions.Insert("item_link", item_link);
|
||||
|
||||
functions.Insert("item_old_id", item_old_id);
|
||||
functions.Insert("item_old_subject", item_old_subject);
|
||||
functions.Insert("item_old_subject_noescape", item_old_subject_noescape);
|
||||
functions.Insert("item_old_content", item_old_content);
|
||||
functions.Insert("item_old_content_noescape", item_old_content_noescape);
|
||||
functions.Insert("item_old_privileges", item_old_privileges);
|
||||
functions.Insert("item_old_dir", item_old_dir);
|
||||
functions.Insert("item_old_url", item_old_url);
|
||||
functions.Insert("item_old_link", item_old_link);
|
||||
|
||||
functions.Insert("item_tab", item_tab);
|
||||
functions.Insert("item_tab_id", item_tab_id);
|
||||
functions.Insert("item_tab_subject", item_tab_subject);
|
||||
functions.Insert("item_tab_subject_noescape", item_tab_subject_noescape);
|
||||
functions.Insert("item_tab_content", item_tab_content);
|
||||
functions.Insert("item_tab_content_noescape", item_tab_content_noescape);
|
||||
functions.Insert("item_tab_privileges", item_tab_privileges);
|
||||
functions.Insert("item_tab_dir", item_tab_dir);
|
||||
functions.Insert("item_tab_url", item_tab_url);
|
||||
functions.Insert("item_tab_link", item_tab_link);
|
||||
|
||||
|
||||
/*
|
||||
dir
|
||||
*/
|
||||
functions.Insert("dir", dir);
|
||||
|
||||
functions.Insert("dir_childs_tab", dir_childs_tab);
|
||||
functions.Insert("dir_childs_tab_url", dir_childs_tab_url);
|
||||
|
||||
functions.Insert("dir_tab", dir_tab);
|
||||
functions.Insert("dir_tab_url", dir_tab_url);
|
||||
functions.Insert("dir_tab_link", dir_tab_link);
|
||||
|
||||
|
||||
/*
|
||||
user
|
||||
*/
|
||||
functions.Insert("user_name", user_name);
|
||||
functions.Insert("user_logged", user_logged);
|
||||
functions.Insert("user_super_user", user_super_user);
|
||||
|
||||
|
||||
/*
|
||||
privileges
|
||||
*/
|
||||
functions.Insert("priv_user_tab", priv_user_tab);
|
||||
functions.Insert("priv_user_tab_name", priv_user_tab_name);
|
||||
functions.Insert("priv_user_tab_isdefault", priv_user_tab_isdefault);
|
||||
|
||||
functions.Insert("priv_group_tab", priv_group_tab);
|
||||
functions.Insert("priv_group_tab_name", priv_group_tab_name);
|
||||
functions.Insert("priv_group_tab_isdefault", priv_group_tab_isdefault);
|
||||
|
||||
|
||||
/*
|
||||
done
|
||||
*/
|
||||
functions.Insert("done_errors", done_errors);
|
||||
functions.Insert("done_status", done_status);
|
||||
functions.Insert("done_status_incorrect_dir", done_status_incorrect_dir);
|
||||
functions.Insert("done_added_item", done_added_item);
|
||||
functions.Insert("done_edited_item", done_edited_item);
|
||||
functions.Insert("done_deleted_item", done_deleted_item);
|
||||
functions.Insert("done_privileged_item", done_privileged_item);
|
||||
functions.Insert("done_loggedout", done_loggedout);
|
||||
|
||||
|
||||
/*
|
||||
others
|
||||
*/
|
||||
functions.Insert("content", content);
|
||||
|
||||
|
||||
// !! tymczasowa
|
||||
functions.Insert("is_group_tv", is_group_tv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Templates::Read()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
pat_index.Directory(data.templates);
|
||||
pat_index.ParseFile(data.default_index);
|
||||
|
||||
pat_err_404.Directory(data.templates);
|
||||
pat_err_404.ParseFile("err_404.html");
|
||||
|
||||
pat_err_per_denied.Directory(data.templates);
|
||||
pat_err_per_denied.ParseFile("err_per_denied.html");
|
||||
|
||||
pat_fun_cat.Directory(data.templates);
|
||||
pat_fun_cat.ParseFile("fun_cat.html");
|
||||
|
||||
pat_fun_ls.Directory(data.templates);
|
||||
pat_fun_ls.ParseFile("fun_ls.html");
|
||||
|
||||
pat_fun_rm.Directory(data.templates);
|
||||
pat_fun_rm.ParseFile("fun_rm.html");
|
||||
|
||||
pat_err_item_required.Directory(data.templates);
|
||||
pat_err_item_required.ParseFile("err_item_required.html");
|
||||
|
||||
pat_fun_emacs.Directory(data.templates);
|
||||
pat_fun_emacs.ParseFile("fun_emacs.html");
|
||||
|
||||
pat_fun_privileges.Directory(data.templates);
|
||||
pat_fun_privileges.ParseFile("fun_privileges.html");
|
||||
|
||||
pat_err_others.Directory(data.templates);
|
||||
pat_err_others.ParseFile("err_others.html");
|
||||
|
||||
CreateFunctions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Templates::Generate()
|
||||
{
|
||||
using namespace TemplatesFunctions;
|
||||
|
||||
|
||||
Ezc::Generator generator(request.page, pat_index, functions);
|
||||
|
||||
generator.Generate();
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfiletemplates
|
||||
#define headerfiletemplates
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "../../ezc/src/ezc.h"
|
||||
#include "../core/data.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/item.h"
|
||||
#include "../core/db.h"
|
||||
#include "../core/error.h"
|
||||
#include "../core/user.h"
|
||||
#include "../core/group.h"
|
||||
#include "../core/users.h"
|
||||
#include "../core/groups.h"
|
||||
#include "../core/log.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
using Ezc::Info;
|
||||
|
||||
/*
|
||||
sys
|
||||
*/
|
||||
void sys_ver_major(Info & i);
|
||||
void sys_ver_minor(Info & i);
|
||||
void sys_ver_revision(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
doc
|
||||
*/
|
||||
void doc_language(Info & i);
|
||||
void doc_title(Info & i);
|
||||
void doc_charset(Info & i);
|
||||
void doc_base_url(Info & i);
|
||||
void doc_current_url(Info & i);
|
||||
void doc_status_error(Info & i);
|
||||
void doc_status_code(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
item
|
||||
*/
|
||||
void item_is(Info & i);
|
||||
void item_id(Info & i);
|
||||
void item_subject(Info & i);
|
||||
void item_subject_noescape(Info & i);
|
||||
void item_content(Info & i);
|
||||
void item_content_noescape(Info & i);
|
||||
void item_privileges(Info & i);
|
||||
void item_dir(Info & i); // the same as full_dir()
|
||||
void item_url(Info & i);
|
||||
void item_link(Info & i);
|
||||
|
||||
// !! wprowadzic item_old_is ?
|
||||
void item_old_id(Info & i);
|
||||
void item_old_subject(Info & i);
|
||||
void item_old_subject_noescape(Info & i);
|
||||
void item_old_content(Info & i);
|
||||
void item_old_content_noescape(Info & i);
|
||||
void item_old_privileges(Info & i);
|
||||
void item_old_dir(Info & i);
|
||||
void item_old_url(Info & i);
|
||||
void item_old_link(Info & i);
|
||||
|
||||
void item_tab(Info & i);
|
||||
void item_tab_id(Info & i);
|
||||
void item_tab_subject(Info & i);
|
||||
void item_tab_subject_noescape(Info & i);
|
||||
void item_tab_content(Info & i);
|
||||
void item_tab_content_noescape(Info & i);
|
||||
void item_tab_privileges(Info & i);
|
||||
void item_tab_dir(Info & i);
|
||||
void item_tab_url(Info & i);
|
||||
void item_tab_link(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
dir
|
||||
*/
|
||||
void dir(Info & i);
|
||||
|
||||
void dir_childs_tab(Info & i);
|
||||
void dir_childs_tab_url(Info & i);
|
||||
|
||||
void dir_tab(Info & i);
|
||||
void dir_tab_url(Info & i);
|
||||
void dir_tab_link(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
user
|
||||
*/
|
||||
void user_name(Info & i);
|
||||
void user_logged(Info & i);
|
||||
void user_super_user(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
privileges
|
||||
*/
|
||||
void priv_user_tab(Info & i);
|
||||
void priv_user_tab_name(Info & i);
|
||||
void priv_user_tab_isdefault(Info & i);
|
||||
|
||||
void priv_group_tab(Info & i);
|
||||
void priv_group_tab_name(Info & i);
|
||||
void priv_group_tab_isdefault(Info & i);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
done
|
||||
*/
|
||||
void done_errors(Info & i);
|
||||
void done_status(Info & i);
|
||||
void done_status_incorrect_dir(Info & i);
|
||||
|
||||
void done_added_item(Info & i);
|
||||
void done_edited_item(Info & i);
|
||||
void done_deleted_item(Info & i);
|
||||
void done_privileged_item(Info & i);
|
||||
void done_loggedout(Info & i);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
class Templates
|
||||
{
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void Read();
|
||||
void Generate();
|
||||
|
||||
void CreateFunctions();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void user_logged(Info & i)
|
||||
{
|
||||
i.result = request.session->puser != 0;
|
||||
}
|
||||
|
||||
|
||||
void user_name(Info & i)
|
||||
{
|
||||
if( !request.session->puser )
|
||||
return;
|
||||
|
||||
i.out << request.session->puser->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void user_super_user(Info & i)
|
||||
{
|
||||
if( request.session->puser && request.session->puser->super_user )
|
||||
i.result = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
182
winixd/Makefile
Normal file
182
winixd/Makefile
Normal file
@@ -0,0 +1,182 @@
|
||||
# Makefile for GNU make
|
||||
|
||||
include Makefile.dep
|
||||
|
||||
|
||||
# https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors
|
||||
GLOBAL_WORKING_DIR := $(shell pwd)/../..
|
||||
|
||||
|
||||
current_path := $(shell pwd)
|
||||
global_relative_working_dir := $(shell relative_path $(current_path) $(GLOBAL_WORKING_DIR))
|
||||
|
||||
|
||||
|
||||
ifeq ($(CXX), g++)
|
||||
CXX = g++6
|
||||
endif
|
||||
|
||||
ifndef CXX
|
||||
ifeq ($(OSTYPE), FreeBSD)
|
||||
CXX = clang++
|
||||
else
|
||||
CXX = g++6
|
||||
endif
|
||||
endif
|
||||
|
||||
# CXX = g++-4.8
|
||||
|
||||
ifndef CXXFLAGS
|
||||
CXXFLAGS = -Wall -O0 -g -fPIC -pthread -std=c++17 -I/usr/local/include -I/usr/include/postgresql -DEZC_HAS_SPECIAL_STREAM
|
||||
endif
|
||||
|
||||
ifndef AR
|
||||
AR = ar
|
||||
endif
|
||||
|
||||
winix_include_paths = -I$(global_relative_working_dir)/winix/winixd -I$(global_relative_working_dir)/ezc/src -I$(global_relative_working_dir)/tito/src -I$(global_relative_working_dir)/morm/src -I$(global_relative_working_dir)/pikotools
|
||||
|
||||
ifndef LDFLAGS
|
||||
LDFLAGS = -L/usr/local/lib
|
||||
endif
|
||||
|
||||
|
||||
|
||||
# for make install
|
||||
winix_install_dir = /usr/local/winix
|
||||
|
||||
|
||||
export CXX
|
||||
export CXXFLAGS
|
||||
export LDFLAGS
|
||||
export GLOBAL_WORKING_DIR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
all: winix.so plugins winix
|
||||
|
||||
|
||||
|
||||
winix.so: $(winix.src.files)
|
||||
@cd core ; $(MAKE) -e
|
||||
@cd db ; $(MAKE) -e
|
||||
@cd functions ; $(MAKE) -e
|
||||
@cd notify ; $(MAKE) -e
|
||||
@cd templates ; $(MAKE) -e
|
||||
@cd $(GLOBAL_WORKING_DIR)/ezc/src ; $(MAKE) -e
|
||||
@cd $(GLOBAL_WORKING_DIR)/tito/src ; $(MAKE) -e
|
||||
@cd $(GLOBAL_WORKING_DIR)/pikotools ; $(MAKE) -e
|
||||
@cd $(GLOBAL_WORKING_DIR)/morm/src ; $(MAKE) -e
|
||||
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(winix_include_paths) core/*.o db/*.o functions/*.o templates/*.o notify/*.o $(GLOBAL_WORKING_DIR)/ezc/src/ezc.a $(GLOBAL_WORKING_DIR)/tito/src/tito.a $(GLOBAL_WORKING_DIR)/pikotools/convert/convert.a $(GLOBAL_WORKING_DIR)/pikotools/utf8/utf8.a $(GLOBAL_WORKING_DIR)/pikotools/space/space.a $(GLOBAL_WORKING_DIR)/pikotools/mainparser/mainparser.a $(GLOBAL_WORKING_DIR)/pikotools/date/date.a $(GLOBAL_WORKING_DIR)/pikotools/log/log.a $(GLOBAL_WORKING_DIR)/morm/src/morm.a $(LDFLAGS) -lfcgi -lpq -lz -lpthread -lcurl -Wl,-no-whole-archive
|
||||
|
||||
|
||||
winix: winix.so $(winix.src.files)
|
||||
@cd main ; $(MAKE) -e
|
||||
$(CXX) -o winix $(CXXFLAGS) $(LDFLAGS) main/*.o winix.so -lfcgi
|
||||
|
||||
|
||||
|
||||
plugins: FORCE
|
||||
@cd plugins/stats ; $(MAKE) -e
|
||||
@cd plugins/thread ; $(MAKE) -e
|
||||
@cd plugins/ticket ; $(MAKE) -e
|
||||
@cd plugins/gallery ; $(MAKE) -e
|
||||
@cd plugins/group ; $(MAKE) -e
|
||||
@cd plugins/menu ; $(MAKE) -e
|
||||
@cd plugins/export ; $(MAKE) -e
|
||||
@cd plugins/mailregister ; $(MAKE) -e
|
||||
@cd plugins/seo ; $(MAKE) -e
|
||||
|
||||
|
||||
FORCE:
|
||||
|
||||
|
||||
clean:
|
||||
@cd core ; $(MAKE) -e clean
|
||||
@cd db ; $(MAKE) -e clean
|
||||
@cd functions ; $(MAKE) -e clean
|
||||
@cd templates ; $(MAKE) -e clean
|
||||
@cd notify ; $(MAKE) -e clean
|
||||
@cd plugins/stats ; $(MAKE) -e clean
|
||||
@cd plugins/thread ; $(MAKE) -e clean
|
||||
@cd plugins/ticket ; $(MAKE) -e clean
|
||||
@cd plugins/gallery ; $(MAKE) -e clean
|
||||
@cd plugins/group ; $(MAKE) -e clean
|
||||
@cd plugins/menu ; $(MAKE) -e clean
|
||||
@cd plugins/export ; $(MAKE) -e clean
|
||||
@cd plugins/mailregister ; $(MAKE) -e clean
|
||||
@cd plugins/seo ; $(MAKE) -e clean
|
||||
@cd $(GLOBAL_WORKING_DIR)/ezc/src ; $(MAKE) -e clean
|
||||
@cd $(GLOBAL_WORKING_DIR)/tito/src ; $(MAKE) -e clean
|
||||
@cd $(GLOBAL_WORKING_DIR)/pikotools ; $(MAKE) -e clean
|
||||
@cd $(GLOBAL_WORKING_DIR)/morm/src ; $(MAKE) -e clean
|
||||
@cd main ; $(MAKE) -e clean
|
||||
rm -f winix.so
|
||||
rm -f winix
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
@cd core ; $(MAKE) -e depend
|
||||
@cd db ; $(MAKE) -e depend
|
||||
@cd functions ; $(MAKE) -e depend
|
||||
@cd templates ; $(MAKE) -e depend
|
||||
@cd notify ; $(MAKE) -e depend
|
||||
@cd plugins/stats ; $(MAKE) -e depend
|
||||
@cd plugins/thread ; $(MAKE) -e depend
|
||||
@cd plugins/ticket ; $(MAKE) -e depend
|
||||
@cd plugins/gallery ; $(MAKE) -e depend
|
||||
@cd plugins/group ; $(MAKE) -e depend
|
||||
@cd plugins/menu ; $(MAKE) -e depend
|
||||
@cd plugins/export ; $(MAKE) -e depend
|
||||
@cd plugins/mailregister ; $(MAKE) -e depend
|
||||
@cd plugins/seo ; $(MAKE) -e depend
|
||||
@cd $(GLOBAL_WORKING_DIR)/ezc/src ; $(MAKE) -e depend
|
||||
@cd $(GLOBAL_WORKING_DIR)/tito/src ; $(MAKE) -e depend
|
||||
@cd $(GLOBAL_WORKING_DIR)/pikotools ; $(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
|
||||
# use $(global_relative_working_dir) here to put relative paths to Makefile.dep
|
||||
find -E $(global_relative_working_dir)/ezc/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||
find -E $(global_relative_working_dir)/tito/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||
find -E $(global_relative_working_dir)/pikotools -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||
find -E $(global_relative_working_dir)/morm/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
||||
|
||||
|
||||
|
||||
install: all
|
||||
# installing binaries
|
||||
rm -Rf $(winix_install_dir)/bin
|
||||
mkdir -p $(winix_install_dir)/bin
|
||||
cp winix $(winix_install_dir)/bin
|
||||
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
|
||||
rm -Rf $(winix_install_dir)/html
|
||||
mkdir -p $(winix_install_dir)/html
|
||||
cp -rf html/* $(winix_install_dir)/html/
|
||||
# txt templates
|
||||
rm -Rf $(winix_install_dir)/txt
|
||||
mkdir -p $(winix_install_dir)/txt
|
||||
cp -rf txt/* $(winix_install_dir)/txt/
|
||||
# locales
|
||||
rm -Rf $(winix_install_dir)/locale
|
||||
mkdir -p $(winix_install_dir)/locale
|
||||
cp -rf locale/* $(winix_install_dir)/locale/
|
||||
# plugins
|
||||
rm -Rf $(winix_install_dir)/plugins
|
||||
mkdir -p $(winix_install_dir)/plugins
|
||||
find plugins/ -name "*.so" | xargs -I foo cp foo $(winix_install_dir)/plugins/
|
||||
# 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 "{}" "+"
|
||||
|
||||
1
winixd/Makefile.dep
Normal file
1
winixd/Makefile.dep
Normal file
File diff suppressed because one or more lines are too long
24
winixd/core/Makefile
Normal file
24
winixd/core/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
include Makefile.o.dep
|
||||
|
||||
current_path := $(shell pwd)
|
||||
global_relative_working_dir := $(shell relative_path $(current_path) $(GLOBAL_WORKING_DIR))
|
||||
|
||||
winix_include_paths = -I$(global_relative_working_dir)/winix/winixd -I$(global_relative_working_dir)/ezc/src -I$(global_relative_working_dir)/tito/src -I$(global_relative_working_dir)/morm/src -I$(global_relative_working_dir)/pikotools
|
||||
|
||||
|
||||
all: $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(winix_include_paths) $<
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. $(winix_include_paths) -f- *.cpp > Makefile.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
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
||||
include Makefile.dep
|
||||
1593
winixd/core/Makefile.dep
Normal file
1593
winixd/core/Makefile.dep
Normal file
File diff suppressed because it is too large
Load Diff
1
winixd/core/Makefile.o.dep
Normal file
1
winixd/core/Makefile.o.dep
Normal file
@@ -0,0 +1 @@
|
||||
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o filelog.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionidmanager.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o
|
||||
138
winixd/core/acceptbaseparser.cpp
Normal file
138
winixd/core/acceptbaseparser.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-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 <wchar.h>
|
||||
#include "acceptbaseparser.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
bool AcceptBaseParser::IsWhite(int c)
|
||||
{
|
||||
if( c==' ' || c=='\t' )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void AcceptBaseParser::SkipWhite()
|
||||
{
|
||||
while( IsWhite(*text) )
|
||||
++text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AcceptBaseParser::ReadParameter()
|
||||
{
|
||||
param.clear();
|
||||
SkipWhite();
|
||||
|
||||
while( *text!=0 && *text!=',' && *text!=';' )
|
||||
{
|
||||
param += *text;
|
||||
++text;
|
||||
}
|
||||
|
||||
TrimWhite(param);
|
||||
}
|
||||
|
||||
|
||||
void AcceptBaseParser::ReadQ()
|
||||
{
|
||||
q = 1.0;
|
||||
SkipWhite();
|
||||
|
||||
if( *text != ';' )
|
||||
return;
|
||||
|
||||
++text; // skipping a semicolon
|
||||
|
||||
while( *text!=0 && *text!=',' && *text!='=' )
|
||||
// skipping until ',' or '='
|
||||
++text;
|
||||
|
||||
if( *text==0 || *text==',' )
|
||||
return;
|
||||
|
||||
++text; // skipping '='
|
||||
|
||||
SkipWhite();
|
||||
q = wcstod(text, (wchar_t**)&text);
|
||||
}
|
||||
|
||||
|
||||
void AcceptBaseParser::SkipParam()
|
||||
{
|
||||
SkipWhite();
|
||||
|
||||
if( *text == ',' )
|
||||
++text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AcceptBaseParser::Parse(const wchar_t * str)
|
||||
{
|
||||
text = str;
|
||||
Init();
|
||||
|
||||
while( *text != 0 )
|
||||
{
|
||||
ReadParameter();
|
||||
ReadQ();
|
||||
SkipParam();
|
||||
Param(param, q);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AcceptBaseParser::Parse(const std::wstring & str)
|
||||
{
|
||||
Parse(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
81
winixd/core/acceptbaseparser.h
Normal file
81
winixd/core/acceptbaseparser.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_acceptbaseparser
|
||||
#define headerfile_winix_core_acceptbaseparser
|
||||
|
||||
#include <string>
|
||||
#include "winixbase.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// sample (you must create your own class derived from this one):
|
||||
// object.Parse(L" text/html ; , ; q = 45, application / xhtml+xml ; q = 0.4 , application/xml ; q = 0.9 , */* ; q = 0.8 ");
|
||||
class AcceptBaseParser : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
void Parse(const wchar_t * str);
|
||||
void Parse(const std::wstring & str);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
virtual void Init() {} ;
|
||||
virtual void Param(const std::wstring & param, double q) = 0;
|
||||
|
||||
bool IsWhite(int c);
|
||||
void SkipWhite();
|
||||
void ReadParameter();
|
||||
void ReadQ();
|
||||
void SkipParam();
|
||||
|
||||
|
||||
const wchar_t * text;
|
||||
std::wstring param;
|
||||
double q;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
124
winixd/core/acceptencodingparser.h
Normal file
124
winixd/core/acceptencodingparser.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_acceptencodingparser
|
||||
#define headerfile_winix_core_acceptencodingparser
|
||||
|
||||
#include "acceptbaseparser.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
class AcceptEncodingParser : public AcceptBaseParser
|
||||
{
|
||||
public:
|
||||
|
||||
bool AcceptDeflate()
|
||||
{
|
||||
return accept_deflate;
|
||||
}
|
||||
|
||||
|
||||
bool AcceptGzip()
|
||||
{
|
||||
return accept_gzip;
|
||||
}
|
||||
|
||||
|
||||
void ParseAndLog(const wchar_t * str)
|
||||
{
|
||||
Parse(str);
|
||||
|
||||
if( accept_deflate || accept_gzip )
|
||||
{
|
||||
log << log3 << "AEP: ";
|
||||
|
||||
if( accept_deflate )
|
||||
{
|
||||
log << "accept deflate";
|
||||
|
||||
if( accept_gzip )
|
||||
log << ", ";
|
||||
}
|
||||
|
||||
if( accept_gzip )
|
||||
log << "accept gzip";
|
||||
|
||||
log << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ParseAndLog(const std::wstring & str)
|
||||
{
|
||||
ParseAndLog(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void Init()
|
||||
{
|
||||
accept_deflate = false;
|
||||
accept_gzip = false;
|
||||
}
|
||||
|
||||
|
||||
void Param(const std::wstring & param, double q)
|
||||
{
|
||||
if( param == L"deflate" && q!=0.0 )
|
||||
{
|
||||
accept_deflate = true;
|
||||
}
|
||||
|
||||
if( param == L"gzip" && q!=0.0 )
|
||||
{
|
||||
accept_gzip = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool accept_deflate;
|
||||
bool accept_gzip;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
2255
winixd/core/app.cpp
Normal file
2255
winixd/core/app.cpp
Normal file
File diff suppressed because it is too large
Load Diff
281
winixd/core/app.h
Normal file
281
winixd/core/app.h
Normal file
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* 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-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_app
|
||||
#define headerfile_winix_core_app
|
||||
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
#include <fcgiapp.h>
|
||||
|
||||
#include "sessionmanager.h"
|
||||
#include "db/db.h"
|
||||
#include "functions/functions.h"
|
||||
#include "templates/templates.h"
|
||||
#include "compress.h"
|
||||
#include "postparser.h"
|
||||
#include "cookieparser.h"
|
||||
#include "postmultiparser.h"
|
||||
#include "acceptencodingparser.h"
|
||||
#include "space/jsontospaceparser.h"
|
||||
|
||||
#include "winixrequest.h"
|
||||
#include "log/log.h"
|
||||
#include "filelog.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
class App
|
||||
{
|
||||
public:
|
||||
|
||||
App();
|
||||
|
||||
bool InitFCGI();
|
||||
bool DropPrivileges();
|
||||
void InitLoggers();
|
||||
Log & GetMainLog();
|
||||
void InitPlugins();
|
||||
bool Init();
|
||||
void Start();
|
||||
void Close();
|
||||
void LogUserGroups();
|
||||
bool Demonize();
|
||||
void SetStopSignal();
|
||||
bool WasStopSignal();
|
||||
bool Lock();
|
||||
void Unlock();
|
||||
void StartThreads();
|
||||
void WaitForThreads();
|
||||
|
||||
// configuration read from a config file
|
||||
Config config;
|
||||
|
||||
// pointers to the current request and a session
|
||||
Cur cur;
|
||||
|
||||
// temporary one request object
|
||||
// current request
|
||||
Request req;
|
||||
|
||||
// users sessions
|
||||
SessionManager session_manager;
|
||||
|
||||
// database (DEPRACATED)
|
||||
Db db;
|
||||
DbConn db_conn;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
model
|
||||
*/
|
||||
|
||||
// ...
|
||||
System system;
|
||||
|
||||
// functions (ls, cat, emacs, ...)
|
||||
Functions functions;
|
||||
|
||||
// false at the beginning
|
||||
// !! IMPROVE ME moze to do loggera dac?
|
||||
bool stdout_is_closed;
|
||||
|
||||
|
||||
/*
|
||||
view
|
||||
*/
|
||||
|
||||
Templates templates;
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
enum Header
|
||||
{
|
||||
h_200,
|
||||
h_404,
|
||||
h_403
|
||||
};
|
||||
|
||||
PostParser post_parser;
|
||||
PostMultiParser post_multi_parser;
|
||||
PT::JSONToSpaceParser post_json_parser;
|
||||
std::string post_buffer;
|
||||
|
||||
CookieParser cookie_parser;
|
||||
AcceptEncodingParser accept_encoding_parser;
|
||||
Compress compress;
|
||||
FCGX_Request fcgi_request;
|
||||
int fcgi_socket;
|
||||
Synchro synchro;
|
||||
pthread_t signal_thread;
|
||||
std::string socket_to_send_on_exit;
|
||||
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;
|
||||
std::wstring cookie_id_string;
|
||||
std::wstring http_header;
|
||||
std::string http_header_8bit;
|
||||
|
||||
morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector
|
||||
morm::JSONConnector json_connector;
|
||||
morm::PostgreSQLConnector postgresql_connector;
|
||||
|
||||
// objects for main thread
|
||||
WinixBase winix_base;
|
||||
WinixModel winix_model;
|
||||
WinixSystem winix_system;
|
||||
WinixRequest winix_request;
|
||||
// ///////////////////////
|
||||
|
||||
Plugin plugin;
|
||||
|
||||
//////////////////////////
|
||||
|
||||
// log_buffer for the main thread
|
||||
PT::WTextStream log_buffer;
|
||||
|
||||
// logger only for App object
|
||||
Log log;
|
||||
|
||||
// file logger, one object for every Log objects
|
||||
FileLog file_log;
|
||||
|
||||
bool InitFCGI(char * sock, char * sock_user, char * sock_group);
|
||||
bool InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_group);
|
||||
bool DropPrivileges(char * user, char * group);
|
||||
bool DropPrivileges(const char * user, uid_t uid, gid_t gid, bool additional_groups);
|
||||
bool CheckAccessFromPlugins();
|
||||
void ProcessRequestThrow();
|
||||
void ProcessRequest();
|
||||
void BaseUrlRedirect(int code, bool add_subdomain);
|
||||
bool BaseUrlRedirect();
|
||||
void CheckIfNeedSSLredirect();
|
||||
void SetLocale();
|
||||
void CheckPostRedirect();
|
||||
void MakePage();
|
||||
void Make();
|
||||
void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji??
|
||||
void LogAccess();
|
||||
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
||||
void CreateJSONAnswer();
|
||||
|
||||
void ReadRequest();
|
||||
void SendTextAnswer();
|
||||
void SendBinaryAnswer();
|
||||
void SendAnswer();
|
||||
|
||||
void LogEnvironmentVariables();
|
||||
void LogEnvironmentHTTPVariables();
|
||||
|
||||
void SetEnv(const char * name, std::wstring & env);
|
||||
void ReadEnvVariables();
|
||||
void ReadEnvHTTPVariables();
|
||||
bool SaveEnvHTTPVariable(const char * env);
|
||||
void ReadEnvRemoteIP();
|
||||
void ReadPostJson();
|
||||
void ReadPostVars();
|
||||
|
||||
void CheckIE();
|
||||
void CheckKonqueror();
|
||||
void CheckRequestMethod();
|
||||
void CheckSSL();
|
||||
void SetSubdomain();
|
||||
|
||||
|
||||
Header GetHTTPStatusCode();
|
||||
void PrepareSessionCookie();
|
||||
void FilterContent();
|
||||
void SendHeaders();
|
||||
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);
|
||||
void PrepareStandardJSONFields();
|
||||
int SelectDeflateVersion();
|
||||
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
||||
bool CanSendContent();
|
||||
void ClearAfterRequest();
|
||||
|
||||
void LogUser(const char * msg, uid_t id);
|
||||
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
|
||||
void LogUsers();
|
||||
void LogEffectiveGroups(std::vector<gid_t> & tab);
|
||||
void LogGroups();
|
||||
|
||||
static void * SpecialThreadForSignals(void*);
|
||||
void SendEmptyFastCGIPacket();
|
||||
|
||||
void CreateStaticTree();
|
||||
|
||||
// !! IMPROVE ME
|
||||
// !! move to the session manager?
|
||||
time_t last_sessions_save;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
280
winixd/core/basethread.cpp
Normal file
280
winixd/core/basethread.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* 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-2019, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include "basethread.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
||||
{
|
||||
synchro = 0;
|
||||
thread_id = 0;
|
||||
work_mode = 0;
|
||||
wake_up_was_called = false;
|
||||
}
|
||||
|
||||
|
||||
BaseThread::~BaseThread()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::set_main_log_buffer(PT::WTextStream * log_buffer)
|
||||
{
|
||||
main_log.SetLogBuffer(log_buffer);
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::set_main_file_log(PT::FileLog * file_log)
|
||||
{
|
||||
main_log.SetFileLog(file_log);
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::Mode(int mode)
|
||||
{
|
||||
work_mode = mode;
|
||||
}
|
||||
|
||||
|
||||
pthread_t BaseThread::ThreadId()
|
||||
{
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool BaseThread::Lock()
|
||||
{
|
||||
return synchro->Lock();
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::Unlock()
|
||||
{
|
||||
synchro->Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool BaseThread::IsExitSignal()
|
||||
{
|
||||
bool res = true;
|
||||
|
||||
if( Lock() )
|
||||
{
|
||||
res = synchro->was_stop_signal;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool BaseThread::BaseInit()
|
||||
{
|
||||
bool init_status = false;
|
||||
|
||||
if( Lock() )
|
||||
{
|
||||
init_status = Init(); // your virtual method
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return init_status;
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::BaseUninit()
|
||||
{
|
||||
if( Lock() )
|
||||
{
|
||||
Uninit(); // your virtual method
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool BaseThread::BaseSignalReceived()
|
||||
{
|
||||
bool make_do = false;
|
||||
|
||||
wake_up_was_called = false;
|
||||
|
||||
try
|
||||
{
|
||||
make_do = SignalReceived(); // your short-time virtual method (objects are locked)
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
|
||||
return make_do;
|
||||
}
|
||||
|
||||
|
||||
// this is called only if your SignalReceived() returned true
|
||||
void BaseThread::BaseDo()
|
||||
{
|
||||
try
|
||||
{
|
||||
Do(); // your long-time virtual method (objects are *not* locked)
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// use it with Lock and Unlock
|
||||
bool BaseThread::WaitForSignal()
|
||||
{
|
||||
if( synchro->was_stop_signal || wake_up_was_called )
|
||||
return true;
|
||||
|
||||
return pthread_cond_wait(&thread_signal, &synchro->mutex) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// you should use this method with: synchro->Lock() and Unlock()
|
||||
void BaseThread::WakeUpThread()
|
||||
{
|
||||
wake_up_was_called = true;
|
||||
pthread_cond_signal(&thread_signal);
|
||||
}
|
||||
|
||||
|
||||
// use it with Lock and Unlock
|
||||
// it breaks only if there was a stop signal or the time has expired
|
||||
bool BaseThread::WaitForSignalSleep(time_t second)
|
||||
{
|
||||
timespec t;
|
||||
int res;
|
||||
|
||||
if( synchro->was_stop_signal )
|
||||
return true;
|
||||
|
||||
t.tv_sec = time(0) + second;
|
||||
t.tv_nsec = 0;
|
||||
|
||||
do
|
||||
{
|
||||
res = pthread_cond_timedwait(&thread_signal, &synchro->mutex, &t);
|
||||
}
|
||||
while( res == 0 && !synchro->was_stop_signal );
|
||||
// above condition means there was a signal
|
||||
// but it was not a stop signal so we should still wait
|
||||
|
||||
return res == 0 || res == ETIMEDOUT;
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::WaitForThread()
|
||||
{
|
||||
pthread_join(thread_id, 0);
|
||||
}
|
||||
|
||||
|
||||
void BaseThread::SignalLoop()
|
||||
{
|
||||
bool make_do;
|
||||
|
||||
do
|
||||
{
|
||||
if( Lock() )
|
||||
{
|
||||
make_do = false;
|
||||
|
||||
if( WaitForSignal() ) // automatically unlock, wait and lock again when signal comes
|
||||
if( !synchro->was_stop_signal )
|
||||
make_do = BaseSignalReceived(); // your short-time virtual method will be called (objects locked)
|
||||
|
||||
Unlock(); // unlocking from WaitForSignal()
|
||||
|
||||
if( make_do )
|
||||
BaseDo(); // your long-time virtual method will be called (objects *not* locked)
|
||||
}
|
||||
}
|
||||
while( !IsExitSignal() );
|
||||
}
|
||||
|
||||
|
||||
void * BaseThread::StartRoutine(void * this_object)
|
||||
{
|
||||
BaseThread * base = reinterpret_cast<BaseThread*>(this_object);
|
||||
|
||||
if( base->synchro )
|
||||
{
|
||||
if( base->BaseInit() )
|
||||
{
|
||||
if( base->work_mode == 0 )
|
||||
base->SignalLoop();
|
||||
else
|
||||
base->Work();
|
||||
|
||||
base->BaseUninit();
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool BaseThread::StartThread()
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
int res = pthread_create(&thread_id, &attr, StartRoutine, this);
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
return res == 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
168
winixd/core/basethread.h
Normal file
168
winixd/core/basethread.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2019, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_basethread
|
||||
#define headerfile_winix_core_basethread
|
||||
|
||||
#include <pthread.h>
|
||||
#include "synchro.h"
|
||||
#include "winixmodel.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
class BaseThread : public WinixModel
|
||||
{
|
||||
public:
|
||||
|
||||
BaseThread();
|
||||
virtual ~BaseThread();
|
||||
|
||||
void set_main_log_buffer(PT::WTextStream * log_buffer);
|
||||
void set_main_file_log(PT::FileLog * file_log);
|
||||
|
||||
|
||||
// work mode
|
||||
// we have two modes:
|
||||
// 0 - there is a loop with SignalReceived() and Do()
|
||||
// if SignalReceived() returns true then Do() is called
|
||||
// 1 - only Work() method is called
|
||||
// the thread exits after Work() has finished
|
||||
// default: 0
|
||||
void Mode(int mode);
|
||||
|
||||
// starting the second thread
|
||||
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
|
||||
// (if it waits for the signal)
|
||||
// you should use it with: synchro->Lock() and Unlock()
|
||||
// if the thread doesn't wait on a signal then nothing is done
|
||||
virtual void WakeUpThread();
|
||||
|
||||
// waiting until the thread exits
|
||||
// you should call WakeUpThread() before
|
||||
virtual void WaitForThread();
|
||||
|
||||
// initialize the thread
|
||||
// (global objects are locked)
|
||||
// if it returns false then the thread immediately exits
|
||||
// default: true
|
||||
virtual bool Init() { return true; }
|
||||
|
||||
// uninitialize the thread
|
||||
// this is called before the thread is prepare to detach
|
||||
// (global objects are locked)
|
||||
// it's called only if Init() returned true
|
||||
virtual void Uninit() {}
|
||||
|
||||
// returns the thread id
|
||||
// this identifier is set by StartThread() metdhod
|
||||
pthread_t ThreadId();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// logger for the main thread
|
||||
Log main_log;
|
||||
|
||||
// log from WinixBase is meant to be used by the other thread
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// signal came (work mode = 0 - default)
|
||||
// signal comes when an other thread calls WakeUpThread() method
|
||||
// check specific job and return true to call Do() next
|
||||
// (global objects are locked -- copy some global objects to local variables)
|
||||
virtual bool SignalReceived() { return false; };
|
||||
|
||||
// if SignalReceived() returned true then this method is called
|
||||
// global objects are *not* locked -- use only your local variables
|
||||
// if you have to do something on global objects use synchro->Lock() and synchro->Unlock()
|
||||
virtual void Do() {}
|
||||
|
||||
// this method is called after Init() when Mode(1) is used
|
||||
// this is for long-time job
|
||||
// this method is called only once
|
||||
// global objects are *not* locked
|
||||
virtual void Work() {}
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
pthread_t thread_id; // thread id - set by StartThread()
|
||||
pthread_cond_t thread_signal;
|
||||
int work_mode;
|
||||
bool wake_up_was_called;
|
||||
|
||||
void SignalLoop();
|
||||
static void * StartRoutine(void *);
|
||||
bool BaseInit();
|
||||
void BaseUninit();
|
||||
bool BaseSignalReceived();
|
||||
void BaseDo();
|
||||
bool WaitForSignal();
|
||||
bool WaitForSignalSleep(time_t second);
|
||||
|
||||
bool Lock();
|
||||
void Unlock();
|
||||
|
||||
// if the work done by Do() is long time consuming you should periodically check
|
||||
// wheter there was a signal for exiting, and if it was just simply return from Do()
|
||||
// (it's checking with locking and unlocking)
|
||||
bool IsExitSignal();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
636
winixd/core/bbcodeparser.cpp
Normal file
636
winixd/core/bbcodeparser.cpp
Normal file
@@ -0,0 +1,636 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "bbcodeparser.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
bool BBCODEParser::Equal(const wchar_t * str1, const wchar_t * str2)
|
||||
{
|
||||
while( *str1 == *str2 && *str1 != 0 )
|
||||
{
|
||||
str1 += 1;
|
||||
str2 += 1;
|
||||
}
|
||||
|
||||
return *str1 == *str2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool BBCODEParser::IsValidCharForName(int c)
|
||||
{
|
||||
if( (c>='a' && c<='z') ||
|
||||
(c>='A' && c<='Z') ||
|
||||
c=='*' || c=='_')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool BBCODEParser::IsOpeningTagMark(wchar_t c)
|
||||
{
|
||||
return (c == '[');
|
||||
}
|
||||
|
||||
|
||||
bool BBCODEParser::IsClosingTagMark(wchar_t c)
|
||||
{
|
||||
return (c == ']');
|
||||
}
|
||||
|
||||
bool BBCODEParser::IsClosingXmlSimpleTagMark(wchar_t c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// there are no commentaries in bbcode
|
||||
bool BBCODEParser::IsOpeningCommentaryTagMark(const wchar_t *)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
size_t BBCODEParser::OpeningCommentaryTagMarkSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool BBCODEParser::SkipCommentaryTagIfExists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// one enter will generate one <br>
|
||||
// two enters or more will generate only two br (<br><br>)
|
||||
void BBCODEParser::PutNormalText(const wchar_t * str, const wchar_t * end)
|
||||
{
|
||||
int br_len;
|
||||
|
||||
if( *pchar == 0 )
|
||||
{
|
||||
// trimming last white characters at end of the user text
|
||||
while( str<end && (IsWhite(*(end-1)) || *(end-1)==10) )
|
||||
--end;
|
||||
}
|
||||
|
||||
|
||||
while( str < end )
|
||||
{
|
||||
if( *str == 10 )
|
||||
{
|
||||
++str;
|
||||
br_len = 1;
|
||||
|
||||
// skipping white characters without a new line character
|
||||
while( str < end && IsWhite(*str) )
|
||||
++str;
|
||||
|
||||
if( str < end && *str == 10 )
|
||||
{
|
||||
br_len = 2;
|
||||
|
||||
// skipping white characters with new line characters
|
||||
while( str < end && (IsWhite(*str) || *str==10) )
|
||||
++str;
|
||||
}
|
||||
|
||||
if( !has_open_ol_tag && !has_open_ul_tag && !has_open_li_tag )
|
||||
{
|
||||
for(int i=0 ; i < br_len ; ++i)
|
||||
(*out_string) += L"<br>\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintEscape(*str);
|
||||
++str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::CheckExceptions()
|
||||
{
|
||||
if( stack_len >= 2 )
|
||||
{
|
||||
if( pstack[stack_len-1].type == Item::opening &&
|
||||
pstack[stack_len-2].type == Item::opening &&
|
||||
IsNameEqual(L"*", pstack[stack_len-1].name) &&
|
||||
IsNameEqual(L"*", pstack[stack_len-2].name) )
|
||||
{
|
||||
// removing the last [*] from the stack
|
||||
// </li> was put automatically
|
||||
PopStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
bbcode format:
|
||||
[bbcodetag=value]some text[/bbcodetag]
|
||||
the value can be quoted, e.g.
|
||||
[bbcodetag="value"]some text[/bbcodetag], or
|
||||
[bbcodetag='value']some text[/bbcodetag]
|
||||
|
||||
the third string below (in tags table) is 'html_argument' from Tags,
|
||||
it can contain a special character % followed by a string which means:
|
||||
%1 - "value" escaped as for html
|
||||
%2 - "some text" escaped as for html
|
||||
%u1 - "value" trimmed and escaped as for url-es
|
||||
%u2 - "some text" trimmed and escaped as for url-es
|
||||
%% - one %
|
||||
|
||||
if you are using %2 or %u2 then "some text" is not treated as bbcode, e.g.
|
||||
[bbcodetag=value]some [b]text[/b][/bbcodetag] will produce:
|
||||
<htmltag arg="value">some [b]text[/b]</htmltag> (the inner tags [b][/b] were not parsed)
|
||||
|
||||
also when using %2 or %u2 the closing bbcode tag is skipped
|
||||
(if you want this tag then you can put it in 'html_argument')
|
||||
|
||||
and when using u (%u1 or %u2) the argument is trimmed from whitespaces and new lines
|
||||
at the beginning and at the end
|
||||
(because otherwise a space would be changed to %20 and this were probably not what you really wanted)
|
||||
*/
|
||||
const BBCODEParser::Tags * BBCODEParser::FindTag(const wchar_t * tag)
|
||||
{
|
||||
static Tags tags[] = {
|
||||
{L"*", L"li", L">", false},
|
||||
{L"b", L"em", L">", true},
|
||||
{L"i", L"span", L" class=\"bbitalic\">", true},
|
||||
{L"u", L"span", L" class=\"bbunderline\">", true},
|
||||
{L"s", L"span", L" class=\"bbstrike\">", true},
|
||||
{L"code", L"code", L" class=\"bbcode\">", false},
|
||||
{L"list", L"ul", L" class=\"bblist\">", false},
|
||||
{L"color", L"span", L" class=\"bbcol%1\">", true},
|
||||
{L"url", L"a", L" href=\"%u1\">", true},
|
||||
{L"img", L"img", L" alt=\"%1\" src=\"%u2\">", true},
|
||||
{L"quote", L"div", L" class=\"bbquote\">\n<span class=\"bbquotewho\">%1</span><br>\n", false},
|
||||
};
|
||||
|
||||
size_t i;
|
||||
size_t len = sizeof(tags) / sizeof(Tags);
|
||||
|
||||
for(i=0 ; i<len ; ++i)
|
||||
{
|
||||
if( Equal(tag, tags[i].bbcode) )
|
||||
return &tags[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const BBCODEParser::Tags * BBCODEParser::FindTag(const std::wstring & tag)
|
||||
{
|
||||
return FindTag(tag.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end)
|
||||
{
|
||||
// skipping white characters from the argument
|
||||
while( start<end && IsWhite(*start) )
|
||||
++start;
|
||||
|
||||
// skipping first '=' character if exists
|
||||
if( start<end && *start == '=' )
|
||||
++start;
|
||||
|
||||
// skipping white characters from the argument
|
||||
// at the beginning
|
||||
while( start<end && IsWhite(*start) )
|
||||
++start;
|
||||
|
||||
// and at the end
|
||||
while( start<end && IsWhite(*(end-1)) )
|
||||
--end;
|
||||
|
||||
|
||||
if( start<end && (*start=='\'' || *start=='\"') )
|
||||
{
|
||||
++start;
|
||||
|
||||
if( start<end && *(start-1) == *(end-1) )
|
||||
--end;
|
||||
|
||||
// skipping white characters after a first quote char [url = " ww...."]
|
||||
while( start<end && IsWhite(*start) )
|
||||
++start;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PrintEncode(int c)
|
||||
{
|
||||
if( c == '&' )
|
||||
{
|
||||
(*out_string) += L"&";
|
||||
}
|
||||
else
|
||||
if( (c>='a' && c<='z') ||
|
||||
(c>='A' && c<='Z') ||
|
||||
(c>='0' && c<='9') ||
|
||||
(c=='_' || c=='?' || c=='.' || c==',' || c=='/' || c=='-' ||
|
||||
c=='+' || c=='*' || c=='(' || c==')' || c=='=' || c==':')
|
||||
)
|
||||
{
|
||||
(*out_string) += c;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t buffer[20];
|
||||
swprintf(buffer, 20, L"%02X", c);
|
||||
|
||||
(*out_string) += '%';
|
||||
(*out_string) += buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::PrintEscape(int c, bool change_quote)
|
||||
{
|
||||
if( c == '<' )
|
||||
{
|
||||
(*out_string) += L"<";
|
||||
}
|
||||
else
|
||||
if( c == '>' )
|
||||
{
|
||||
(*out_string) += L">";
|
||||
}
|
||||
else
|
||||
if( c == '&' )
|
||||
{
|
||||
(*out_string) += L"&";
|
||||
}
|
||||
else
|
||||
if( c == '\"' && change_quote )
|
||||
{
|
||||
(*out_string) += L""";
|
||||
}
|
||||
else
|
||||
{
|
||||
(*out_string) += c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::PrintArgumentEncode(const wchar_t * start, const wchar_t * end)
|
||||
{
|
||||
PrintArgumentCheckQuotes(start, end);
|
||||
TrimWhiteWithNewLines(start, end);
|
||||
|
||||
for( ; start<end ; ++start )
|
||||
PrintEncode(*start);
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::PrintArgumentEscape(const wchar_t * start, const wchar_t * end)
|
||||
{
|
||||
PrintArgumentCheckQuotes(start, end);
|
||||
|
||||
for( ; start<end ; ++start )
|
||||
PrintEscape(*start, true); // quotes are escaped as well here
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition)
|
||||
{
|
||||
if( Equal(tag->html_tag, tag_name) )
|
||||
{
|
||||
if( condition )
|
||||
{
|
||||
PutClosingTag(tag);
|
||||
(*out_string) += '\n';
|
||||
}
|
||||
|
||||
condition = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::CheckOpeningTag(const Tags * tag)
|
||||
{
|
||||
bool has_list_tag = has_open_ul_tag || has_open_ol_tag;
|
||||
|
||||
CheckOpeningTag(tag, L"li", has_open_li_tag);
|
||||
CheckOpeningTag(tag, L"ul", has_open_ul_tag);
|
||||
CheckOpeningTag(tag, L"ol", has_open_ol_tag);
|
||||
|
||||
if( has_open_li_tag && !has_list_tag )
|
||||
{
|
||||
(*out_string) += L"<ul>\n";
|
||||
has_open_ul_tag = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote)
|
||||
{
|
||||
for( ; start < end ; ++start)
|
||||
PrintEscape(*start, change_quote);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PrintEncode(const wchar_t * start, const wchar_t * end)
|
||||
{
|
||||
for( ; start < end ; ++start)
|
||||
PrintEncode(*start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PutOpeningTagFromEzc()
|
||||
{
|
||||
// this can be a tag from Ezc templates system
|
||||
(*out_string) += '[';
|
||||
(*out_string) += LastItem().name;
|
||||
|
||||
const wchar_t * start = pchar;
|
||||
|
||||
while( *pchar && *pchar!=']' )
|
||||
++pchar;
|
||||
|
||||
if( *pchar == ']' )
|
||||
++pchar;
|
||||
|
||||
Put(start, pchar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u)
|
||||
{
|
||||
if( has_u )
|
||||
PrintArgumentEncode(arg_start, arg_end);
|
||||
else
|
||||
PrintArgumentEscape(arg_start, arg_end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end)
|
||||
{
|
||||
while( start < end && (IsWhite(*start) || *start==10) )
|
||||
++start;
|
||||
|
||||
while( start < end && (IsWhite(*(end-1)) || *(end-1)==10) )
|
||||
--end;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PutHtmlArgument2(const Tags * tag, bool has_u)
|
||||
{
|
||||
const wchar_t * start = pchar;
|
||||
const wchar_t * end = pchar;
|
||||
bool first_tag_removed = false;
|
||||
|
||||
while( *pchar != 0 )
|
||||
{
|
||||
if( IsOpeningTagMark(*pchar) )
|
||||
{
|
||||
if( IsClosingTagForLastItem() )
|
||||
{
|
||||
// the last tag is skipped when using patterns with %2 or %u2
|
||||
|
||||
PopStack(); // removing opening tag from the stack
|
||||
first_tag_removed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pchar += 1;
|
||||
end = pchar;
|
||||
}
|
||||
}
|
||||
|
||||
if( !first_tag_removed )
|
||||
PopStack(); // user has forgotten to close the tag
|
||||
|
||||
if( has_u )
|
||||
{
|
||||
TrimWhiteWithNewLines(start, end);
|
||||
PrintEncode(start, end);
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintEscape(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end)
|
||||
{
|
||||
const wchar_t * pattern = tag->html_argument;
|
||||
bool has_u;
|
||||
|
||||
while( *pattern )
|
||||
{
|
||||
if( *pattern == '%' )
|
||||
{
|
||||
++pattern;
|
||||
has_u = false;
|
||||
|
||||
if( *pattern == 'u' )
|
||||
{
|
||||
++pattern;
|
||||
has_u = true;
|
||||
}
|
||||
|
||||
if( *pattern == '1' )
|
||||
{
|
||||
++pattern;
|
||||
PutHtmlArgument1(arg_start, arg_end, has_u);
|
||||
}
|
||||
else
|
||||
if( *pattern == '2' )
|
||||
{
|
||||
++pattern;
|
||||
PutHtmlArgument2(tag, has_u);
|
||||
}
|
||||
else
|
||||
if( *pattern == '%' )
|
||||
{
|
||||
(*out_string) += '%';
|
||||
++pattern;
|
||||
}
|
||||
// else unrecognized, will be printed next time as a normal character
|
||||
}
|
||||
else
|
||||
{
|
||||
(*out_string) += *pattern;
|
||||
++pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::PutOpeningTagFromBBCode(const Tags * tag)
|
||||
{
|
||||
CheckOpeningTag(tag);
|
||||
PutOpeningTagMark();
|
||||
Put(tag->html_tag);
|
||||
|
||||
const wchar_t * start = pchar;
|
||||
|
||||
while( *pchar && *pchar != ']' )
|
||||
++pchar;
|
||||
|
||||
PutHtmlArgument(tag, start, pchar);
|
||||
|
||||
if( *pchar == ']' )
|
||||
++pchar;
|
||||
|
||||
if( !tag->inline_tag )
|
||||
{
|
||||
Put(10);
|
||||
SkipWhiteLines();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool BBCODEParser::PutOpeningTag()
|
||||
{
|
||||
const Tags * tag = FindTag(LastItem().name);
|
||||
|
||||
if( !tag )
|
||||
PutOpeningTagFromEzc();
|
||||
else
|
||||
PutOpeningTagFromBBCode(tag);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::PutClosingTag(const Tags * tag)
|
||||
{
|
||||
if( !tag )
|
||||
return; // skipping the tag
|
||||
|
||||
PutOpeningTagMark();
|
||||
(*out_string) += '/';
|
||||
(*out_string) += tag->html_tag;
|
||||
PutClosingTagMark();
|
||||
|
||||
if( !tag->inline_tag )
|
||||
{
|
||||
(*out_string) += L"\n";
|
||||
SkipWhiteLines();
|
||||
}
|
||||
|
||||
if( Equal(tag->html_tag, L"li") )
|
||||
has_open_li_tag = false;
|
||||
|
||||
if( Equal(tag->html_tag, L"ol") )
|
||||
has_open_ol_tag = false;
|
||||
|
||||
if( Equal(tag->html_tag, L"ul") )
|
||||
has_open_ul_tag = false;
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::PutClosingTag(const wchar_t * tag_name)
|
||||
{
|
||||
const Tags * tag = FindTag(tag_name);
|
||||
PutClosingTag(tag);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BBCODEParser::Init()
|
||||
{
|
||||
has_open_li_tag = false;
|
||||
has_open_ol_tag = false;
|
||||
has_open_ul_tag = false;
|
||||
|
||||
SkipWhiteLines();
|
||||
}
|
||||
|
||||
|
||||
void BBCODEParser::Uninit()
|
||||
{
|
||||
if( has_open_li_tag )
|
||||
(*out_string) += L"</li>\n";
|
||||
|
||||
if( has_open_ol_tag )
|
||||
(*out_string) += L"</ol>\n";
|
||||
|
||||
if( has_open_ul_tag )
|
||||
(*out_string) += L"</ul>\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
127
winixd/core/bbcodeparser.h
Normal file
127
winixd/core/bbcodeparser.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_bbcodeparser
|
||||
#define headerfile_winix_core_bbcodeparser
|
||||
|
||||
#include "htmlfilter.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
class BBCODEParser : public HTMLFilter
|
||||
{
|
||||
|
||||
struct Tags
|
||||
{
|
||||
const wchar_t * bbcode;
|
||||
const wchar_t * html_tag;
|
||||
const wchar_t * html_argument; // with closing '>'
|
||||
bool inline_tag;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
virtual methods
|
||||
(from HTMLFilter class)
|
||||
*/
|
||||
virtual void Init();
|
||||
virtual void Uninit();
|
||||
|
||||
virtual bool IsOpeningTagMark(wchar_t c);
|
||||
virtual bool IsClosingTagMark(wchar_t c);
|
||||
virtual bool IsClosingXmlSimpleTagMark(wchar_t c);
|
||||
|
||||
virtual bool IsOpeningCommentaryTagMark(const wchar_t *);
|
||||
virtual size_t OpeningCommentaryTagMarkSize();
|
||||
|
||||
virtual bool IsValidCharForName(int c);
|
||||
virtual void CheckExceptions();
|
||||
virtual bool SkipCommentaryTagIfExists();
|
||||
|
||||
virtual bool PutOpeningTag();
|
||||
virtual void PutClosingTag(const wchar_t * tag);
|
||||
|
||||
virtual void PutNormalText(const wchar_t * str, const wchar_t * end);
|
||||
virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
others
|
||||
*/
|
||||
bool Equal(const wchar_t * str1, const wchar_t * str2);
|
||||
|
||||
void PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u);
|
||||
void PutHtmlArgument2(const Tags * tag, bool has_u);
|
||||
void PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end);
|
||||
|
||||
void PutOpeningTagFromEzc();
|
||||
void PutOpeningTagFromBBCode(const Tags * tag);
|
||||
|
||||
const Tags * FindTag(const wchar_t * tag);
|
||||
const Tags * FindTag(const std::wstring & tag);
|
||||
void PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end);
|
||||
|
||||
void PrintEscape(int c, bool change_quote = false);
|
||||
void PrintEncode(int c);
|
||||
|
||||
void PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote = false);
|
||||
void PrintEncode(const wchar_t * start, const wchar_t * end);
|
||||
|
||||
void PrintArgumentEncode(const wchar_t * start, const wchar_t * end);
|
||||
void PrintArgumentEscape(const wchar_t * start, const wchar_t * end);
|
||||
|
||||
void PutClosingTag(const Tags * tag);
|
||||
|
||||
void CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition);
|
||||
void CheckOpeningTag(const Tags * tag);
|
||||
|
||||
void TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end);
|
||||
|
||||
|
||||
|
||||
bool has_open_ol_tag; // has open html <ol> tag
|
||||
bool has_open_ul_tag; // has open html <ul> tag
|
||||
bool has_open_li_tag; // has open html <li> tag
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
433
winixd/core/compress.cpp
Normal file
433
winixd/core/compress.cpp
Normal file
@@ -0,0 +1,433 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "compress.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
Compress::Compress()
|
||||
{
|
||||
buffer_in = 0;
|
||||
buffer_out = 0;
|
||||
buffer_max_len = 65536; // 64KB
|
||||
ready_for_compress = false;
|
||||
compress_level = 6;
|
||||
raw_deflate_inited = false;
|
||||
deflate_inited = false;
|
||||
gzip_inited = false;
|
||||
}
|
||||
|
||||
|
||||
Compress::~Compress()
|
||||
{
|
||||
delete [] buffer_in;
|
||||
delete [] buffer_out;
|
||||
|
||||
if( raw_deflate_inited )
|
||||
deflateEnd(&strm_raw_deflate);
|
||||
|
||||
if( deflate_inited )
|
||||
deflateEnd(&strm_deflate);
|
||||
|
||||
if( gzip_inited )
|
||||
deflateEnd(&strm_gzip);
|
||||
}
|
||||
|
||||
|
||||
bool Compress::AllocateMemory()
|
||||
{
|
||||
if( buffer_in )
|
||||
delete [] buffer_in;
|
||||
|
||||
if( buffer_out )
|
||||
delete [] buffer_out;
|
||||
|
||||
buffer_in = 0;
|
||||
buffer_out = 0;
|
||||
|
||||
try
|
||||
{
|
||||
buffer_in = new char[buffer_max_len];
|
||||
buffer_out = new char[buffer_max_len];
|
||||
}
|
||||
catch(const std::bad_alloc &)
|
||||
{
|
||||
log << log1 << "Compress: can't allocate memory" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Compress::InitRawDeflate()
|
||||
{
|
||||
raw_deflate_inited = false;
|
||||
|
||||
strm_raw_deflate.next_in = 0;
|
||||
strm_raw_deflate.zalloc = Z_NULL;
|
||||
strm_raw_deflate.zfree = Z_NULL;
|
||||
strm_raw_deflate.opaque = Z_NULL;
|
||||
|
||||
int ret = deflateInit2(&strm_raw_deflate, compress_level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
|
||||
|
||||
if( ret != Z_OK )
|
||||
log << log1 << "Compress: problem with deflateInit2() for raw deflate" << logend;
|
||||
else
|
||||
raw_deflate_inited = true;
|
||||
|
||||
return ret == Z_OK;
|
||||
}
|
||||
|
||||
|
||||
bool Compress::InitDeflate()
|
||||
{
|
||||
deflate_inited = false;
|
||||
|
||||
strm_deflate.next_in = 0;
|
||||
strm_deflate.zalloc = Z_NULL;
|
||||
strm_deflate.zfree = Z_NULL;
|
||||
strm_deflate.opaque = Z_NULL;
|
||||
|
||||
int ret = deflateInit2(&strm_deflate, compress_level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
|
||||
|
||||
if( ret != Z_OK )
|
||||
log << log1 << "Compress: problem with deflateInit2() for deflate" << logend;
|
||||
else
|
||||
deflate_inited = true;
|
||||
|
||||
return ret == Z_OK;
|
||||
}
|
||||
|
||||
|
||||
bool Compress::InitGzip()
|
||||
{
|
||||
gzip_inited = false;
|
||||
|
||||
strm_gzip.next_in = 0;
|
||||
strm_gzip.zalloc = Z_NULL;
|
||||
strm_gzip.zfree = Z_NULL;
|
||||
strm_gzip.opaque = Z_NULL;
|
||||
|
||||
int ret = deflateInit2(&strm_gzip, compress_level, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
|
||||
|
||||
if( ret != Z_OK )
|
||||
log << log1 << "Compress: problem with deflateInit2() for gzip" << logend;
|
||||
else
|
||||
gzip_inited = true;
|
||||
|
||||
return ret == Z_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
return:
|
||||
0 - ok
|
||||
1 - can't allocate memory
|
||||
100 - unknown error
|
||||
*/
|
||||
int Compress::Init(int compress_level_)
|
||||
{
|
||||
compress_level = compress_level_;
|
||||
|
||||
if( !AllocateMemory() )
|
||||
return 1;
|
||||
|
||||
if( InitRawDeflate() && InitDeflate() && InitGzip() )
|
||||
ready_for_compress = true;
|
||||
else
|
||||
return 100;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int Compress::MakeCompress(z_stream & strm, const char * source, size_t source_len, BinaryPage & out_stream, int encoding)
|
||||
{
|
||||
int ret, flush;
|
||||
size_t have;
|
||||
|
||||
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*)source;
|
||||
source += 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_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 );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
z_stream * Compress::SelectStream(int encoding)
|
||||
{
|
||||
z_stream * pstrm;
|
||||
|
||||
if( encoding == 0 )
|
||||
pstrm = &strm_raw_deflate;
|
||||
else
|
||||
if( encoding == 1 )
|
||||
pstrm = &strm_deflate;
|
||||
else
|
||||
pstrm = &strm_gzip;
|
||||
|
||||
return pstrm;
|
||||
}
|
||||
|
||||
|
||||
void Compress::ResetStream(z_stream * pstrm, int encoding)
|
||||
{
|
||||
if( deflateReset(pstrm) != Z_OK )
|
||||
{
|
||||
log << log1 << "Compress: problem with deflateReset()" << logend;
|
||||
|
||||
deflateEnd(pstrm);
|
||||
|
||||
if( encoding == 0 )
|
||||
InitRawDeflate();
|
||||
else
|
||||
if( encoding == 1 )
|
||||
InitDeflate();
|
||||
else
|
||||
InitGzip();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Compress::PutLog(size_t source_len, int encoding)
|
||||
{
|
||||
double ratio = 100.0 - (double(last_out_size) / double(source_len) * 100.0);
|
||||
char buffer[30];
|
||||
sprintf(buffer, "%.1f", ratio);
|
||||
|
||||
log << log2 << "Compress: ";
|
||||
|
||||
if( encoding == 0 )
|
||||
log << "raw deflate";
|
||||
else
|
||||
if( encoding == 1 )
|
||||
log << "deflate";
|
||||
else
|
||||
log << "gzip";
|
||||
|
||||
log << ", original size: " << source_len << ", size after compressing: "
|
||||
<< (int)last_out_size << ", ratio: " << buffer << "%" << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
return:
|
||||
0 - ok;
|
||||
1 - can't allocate memory
|
||||
2 - error during compressing
|
||||
3 - not inited (use Init() first)
|
||||
100 - unknown
|
||||
*/
|
||||
int Compress::Compressing(const char * source, size_t source_len, BinaryPage & out_stream, int encoding)
|
||||
{
|
||||
int ret;
|
||||
z_stream * pstrm;
|
||||
|
||||
last_out_size = 0;
|
||||
out_stream.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( source_len == 0 )
|
||||
return 0;
|
||||
|
||||
pstrm = SelectStream(encoding);
|
||||
ret = MakeCompress(*pstrm, source, source_len, out_stream, encoding);
|
||||
ResetStream(pstrm, encoding);
|
||||
PutLog(source_len, encoding);
|
||||
|
||||
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
|
||||
|
||||
102
winixd/core/compress.h
Normal file
102
winixd/core/compress.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_compress
|
||||
#define headerfile_winix_core_compress
|
||||
|
||||
#include <cstring>
|
||||
#include <zlib.h>
|
||||
#include "requesttypes.h"
|
||||
#include "winixbase.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
class Compress : public WinixBase
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
Compress();
|
||||
~Compress();
|
||||
|
||||
int Init(int compress_level_ = 6);
|
||||
|
||||
/*
|
||||
encoding:
|
||||
0 - raw deflate data with no zlib header or trailer, and will not compute an adler32 check value
|
||||
(for Internet Explorer)
|
||||
1 - deflate
|
||||
2 - gzip
|
||||
*/
|
||||
int Compressing(const char * source, size_t source_len, BinaryPage & out_stream, int encoding = 2);
|
||||
int Compressing(const BinaryPage & in, BinaryPage & out, int encoding = 2);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool AllocateMemory();
|
||||
bool InitRawDeflate();
|
||||
bool InitDeflate();
|
||||
bool InitGzip();
|
||||
|
||||
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);
|
||||
void ResetStream(z_stream * pstrm, int encoding);
|
||||
void PutLog(size_t source_len, int encoding);
|
||||
void CopyToInputBuffer(BinaryPage::const_iterator & i, size_t len);
|
||||
|
||||
int compress_level;
|
||||
size_t buffer_max_len;
|
||||
|
||||
// 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;
|
||||
bool raw_deflate_inited, deflate_inited, gzip_inited;
|
||||
bool ready_for_compress;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
537
winixd/core/config.cpp
Normal file
537
winixd/core/config.cpp
Normal file
@@ -0,0 +1,537 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
#include "crypt.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
Config::Config()
|
||||
{
|
||||
errors_to_stdout = true;
|
||||
}
|
||||
|
||||
|
||||
void Config::SetFileLog(FileLog * file_log)
|
||||
{
|
||||
log.SetFileLog(file_log);
|
||||
}
|
||||
|
||||
|
||||
void Config::SetLogBuffer(PT::WTextStream * log_buffer)
|
||||
{
|
||||
log.SetLogBuffer(log_buffer);
|
||||
}
|
||||
|
||||
|
||||
void Config::ShowError()
|
||||
{
|
||||
|
||||
switch( parser.status )
|
||||
{
|
||||
case PT::SpaceParser::no_space:
|
||||
log << log2 << "Config: space not set" << logend;
|
||||
break;
|
||||
|
||||
case PT::SpaceParser::ok:
|
||||
log << log2 << "Config: syntax ok" << logend;
|
||||
break;
|
||||
|
||||
case PT::SpaceParser::cant_open_file:
|
||||
if( errors_to_stdout )
|
||||
std::wcout << L"Config: I cannot open a config file: " << config_file << std::endl;
|
||||
|
||||
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
||||
break;
|
||||
|
||||
case PT::SpaceParser::syntax_error:
|
||||
if( errors_to_stdout )
|
||||
std::wcout << "Config: syntax error, line: " << parser.line << std::endl;
|
||||
|
||||
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
{
|
||||
errors_to_stdout = errors_to_stdout_;
|
||||
|
||||
if( config_file.empty() )
|
||||
{
|
||||
log << log2 << "Config: name of the config file is empty" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
|
||||
parser.SetSpace(space);
|
||||
PT::SpaceParser::Status status = parser.Parse(config_file);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
AssignValues(stdout_is_closed);
|
||||
SetAdditionalVariables();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Config::AssignValues(bool stdout_is_closed)
|
||||
{
|
||||
server_mode = Text(L"server_mode");
|
||||
demonize = Bool(L"demonize", true);
|
||||
|
||||
user = Text(L"user");
|
||||
group = Text(L"group");
|
||||
additional_groups = Bool(L"additional_groups", true);
|
||||
|
||||
log_file = Text(L"log_file");
|
||||
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
|
||||
fcgi_socket = Text(L"fcgi_socket");
|
||||
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
|
||||
fcgi_socket_user = Text(L"fcgi_socket_user");
|
||||
fcgi_socket_group = Text(L"fcgi_socket_group");
|
||||
fcgi_socket_listen = Int(L"fcgi_socket_listen", 100);
|
||||
log_level = Int(L"log_level", 1);
|
||||
log_request = Int(L"log_request", 1);
|
||||
log_save_each_line = Bool(L"log_save_each_line", false);
|
||||
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_db_query = Bool(L"log_db_query", false);
|
||||
log_plugin_call = Bool(L"log_plugin_call", false);
|
||||
log_post_value_size = Size(L"log_post_value_size", 80);
|
||||
log_env_variables = Bool(L"log_env_variables", false);
|
||||
log_env_http_variables = Bool(L"log_env_http_variables", false);
|
||||
log_http_answer_headers = Bool(L"log_http_answer_headers", false);
|
||||
|
||||
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
|
||||
|
||||
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_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);
|
||||
thumb_mode = Int(L"thumb_mode", 2);
|
||||
thumb_cx = Size(L"thumb_cx", 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");
|
||||
|
||||
templates_dir = Text(L"templates_dir");
|
||||
templates_dir_default = Text(L"templates_dir_default");
|
||||
txt_templates_dir = Text(L"txt_templates_dir");
|
||||
txt_templates_dir_default = Text(L"txt_templates_dir_default");
|
||||
templates_fun_prefix = Text(L"templates_fun_prefix", L"fun_");
|
||||
templates_fun_postfix = Text(L"templates_fun_postfix", L".html");
|
||||
templates_index = Text(L"templates_index", L"index.html");
|
||||
templates_index_raw = Text(L"templates_index_raw", L"index_raw.html");
|
||||
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
||||
|
||||
http_session_id_name = Text(L"http_session_id_name", L"session_id");
|
||||
db_database = Text(L"db_database");
|
||||
db_user = Text(L"db_user");
|
||||
db_pass = Text(L"db_pass");
|
||||
db_postgresql_smaller_than_10 = Bool(L"db_postgresql_smaller_than_10", false);
|
||||
|
||||
item_url_empty = Text(L"item_url_empty");
|
||||
|
||||
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", false);
|
||||
use_ssl_redirect_code = Int(L"use_ssl_redirect_code", 303);
|
||||
assume_connection_is_through_ssl = Bool(L"assume_connection_is_through_ssl", false);
|
||||
|
||||
base_url = Text(L"base_url");
|
||||
base_url_static = Text(L"base_url_static");
|
||||
base_url_common = Text(L"base_url_common");
|
||||
|
||||
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_static);
|
||||
NoLastSlash(base_url_common);
|
||||
|
||||
priv_no_user = Text(L"priv_no_user", L"-- no user --");
|
||||
priv_no_group = Text(L"priv_no_group", L"-- no group --");
|
||||
|
||||
session_max_idle = Int(L"session_max_idle", 10800); // 3h
|
||||
session_remember_max_idle = Int(L"session_remember_max_idle", 16070400); // 3 months
|
||||
session_file = Text(L"session_file");
|
||||
session_max = Size(L"session_max", 1000000);
|
||||
session_cookie_encode = Bool(L"session_cookie_encode", false);
|
||||
session_keys_file = Text(L"session_keys_file");
|
||||
session_allow_index_difference = Size(L"session_allow_index_difference", 8);
|
||||
session_index_time_increment = Long(L"session_index_time_increment", 30);
|
||||
session_key_renew_time = Size(L"session_key_renew_time", 172800); // 2 days
|
||||
broken_encoded_cookie_treshold = Size(L"broken_encoded_cookie_treshold", 2);
|
||||
session_hijacking_treshold = Size(L"session_hijacking_treshold", 128);
|
||||
no_session_cookie_treshold = Size(L"no_session_cookie_treshold", 128);
|
||||
no_session_cookie_ban_mode = Int(L"no_session_cookie_ban_mode", 0);
|
||||
|
||||
compression = Bool(L"compression", true);
|
||||
compression_page_min_size = Size(L"compression_page_min_size", 512);
|
||||
compression_encoding = Int(L"compression_encoding", 20);
|
||||
|
||||
html_filter = Bool(L"html_filter", true);
|
||||
html_filter_trim_white = Bool(L"html_filter_trim_white", true);
|
||||
html_filter_break_word = Int(L"html_filter_break_word", 60);
|
||||
html_filter_wrap_line = Int(L"html_filter_wrap_line", 110);
|
||||
html_filter_tabs = Size(L"html_filter_tabs", 2);
|
||||
html_filter_orphans = Bool(L"html_filter_orphans", true);
|
||||
html_filter_orphans_mode_str = Text(L"html_filter_orphans_mode_str", L"nbsp");
|
||||
html_filter_nofilter_tag = Text(L"html_filter_nofilter_tag", L"nofilter");
|
||||
|
||||
locale_dir = Text(L"locale_dir");
|
||||
locale_dir_default = Text(L"locale_dir_default");
|
||||
locale_max_id = Size(L"locale_max_id", 100);
|
||||
locale_default_id = Size(L"locale_default_id", 0);
|
||||
ListText(L"locale_files", locale_files);
|
||||
|
||||
title_separator = Text(L"title_separator", L" / ");
|
||||
|
||||
http_header_send_file = Text(L"http_header_send_file", L"X-LIGHTTPD-send-file");
|
||||
|
||||
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);
|
||||
|
||||
plugins_dir = Text(L"plugins_dir", L"/usr/local/winix/plugins");
|
||||
NoLastSlash(plugins_dir);
|
||||
ListText(L"plugins", plugin_file);
|
||||
|
||||
symlinks_follow_max = Size(L"symlinks_follow_max", 20);
|
||||
|
||||
ticket_form_prefix = Text(L"ticket_form_prefix", L"ticketparam");
|
||||
|
||||
pass_min_size = Size(L"pass_min_size", 5);
|
||||
pass_type = Int(L"pass_type", 12);
|
||||
pass_hash_use_salt = Bool(L"pass_hash_use_salt", false);
|
||||
pass_hash_salt = Text(L"pass_hash_salt");
|
||||
pass_use_rsa = Bool(L"pass_use_rsa", false);
|
||||
pass_rsa_private_key = Text(L"pass_rsa_private_key");
|
||||
|
||||
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", 128);
|
||||
ezc_error_prefix = Text(L"ezc_error_prefix", L"<!-- ");
|
||||
ezc_error_postfix = Text(L"ezc_error_postfix", L" -->");
|
||||
|
||||
account_need_email_verification = Bool(L"account_need_email_verification", true);
|
||||
reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400);
|
||||
|
||||
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"");
|
||||
allow_ezc_out_in_executable_items = Bool(L"allow_ezc_out_in_executable_items", false);
|
||||
|
||||
check_proxy_ip_header = Bool(L"check_proxy_ip_header", false);
|
||||
proxy_ip_header = Text(L"proxy_ip_header", L"X_Real_IP");
|
||||
|
||||
antispam_list_max_size = Size(L"antispam_list_max_size", 10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Config::SetAdditionalVariables()
|
||||
{
|
||||
for(size_t i=0 ; i<static_dirs.size() ; ++i)
|
||||
NoLastSlash(static_dirs[i]);
|
||||
|
||||
CheckPasswd();
|
||||
|
||||
if( content_type_header < 0 || content_type_header > 2 )
|
||||
content_type_header = 0;
|
||||
|
||||
if( locale_default_id > locale_max_id )
|
||||
locale_default_id = locale_max_id;
|
||||
|
||||
if( locale_files.empty() )
|
||||
locale_files.push_back(L"en");
|
||||
|
||||
if( !upload_group.empty() )
|
||||
upload_group_int = GetGroupId(upload_group);
|
||||
else
|
||||
upload_group_int = -1;
|
||||
|
||||
if( session_cookie_encode && session_keys_file.empty() )
|
||||
session_cookie_encode = false;
|
||||
|
||||
if( session_index_time_increment < 0 )
|
||||
session_index_time_increment = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Config::CheckPasswd()
|
||||
{
|
||||
switch(pass_type)
|
||||
{
|
||||
case WINIX_CRYPT_HASH_NONE:
|
||||
case WINIX_CRYPT_HASH_MD4:
|
||||
case WINIX_CRYPT_HASH_MD5:
|
||||
case WINIX_CRYPT_HASH_SHA1:
|
||||
case WINIX_CRYPT_HASH_SHA224:
|
||||
case WINIX_CRYPT_HASH_SHA256:
|
||||
case WINIX_CRYPT_HASH_SHA384:
|
||||
case WINIX_CRYPT_HASH_SHA512:
|
||||
break;
|
||||
|
||||
default:
|
||||
pass_type = WINIX_CRYPT_HASH_SHA256;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::wstring Config::Text(const wchar_t * name)
|
||||
{
|
||||
return space.Text(name);
|
||||
}
|
||||
|
||||
|
||||
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
return space.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::wstring Config::Text(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
return space.Text(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::wstring & Config::TextRef(const wchar_t * name)
|
||||
{
|
||||
return space.TextRef(name);
|
||||
}
|
||||
|
||||
|
||||
std::wstring & Config::TextRef(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
return space.TextRef(name, def);
|
||||
}
|
||||
|
||||
|
||||
std::wstring & Config::TextRef(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
return space.TextRef(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const wchar_t * name)
|
||||
{
|
||||
return space.Int(name);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const wchar_t * name, int def)
|
||||
{
|
||||
return space.Int(name, def);
|
||||
}
|
||||
|
||||
|
||||
int Config::Int(const std::wstring & name, int 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)
|
||||
{
|
||||
return space.Size(name);
|
||||
}
|
||||
|
||||
|
||||
size_t Config::Size(const wchar_t * name, size_t def)
|
||||
{
|
||||
return space.Size(name, def);
|
||||
}
|
||||
|
||||
|
||||
size_t Config::Size(const std::wstring & name, size_t def)
|
||||
{
|
||||
return space.Size(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const wchar_t * name)
|
||||
{
|
||||
return space.Bool(name);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const wchar_t * name, bool def)
|
||||
{
|
||||
return space.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
bool Config::Bool(const std::wstring & name, bool def)
|
||||
{
|
||||
return space.Bool(name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||
{
|
||||
return space.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
bool Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||
{
|
||||
return space.ListText(name, list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Config::HasValue(const wchar_t * name, const wchar_t * value)
|
||||
{
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
848
winixd/core/config.h
Normal file
848
winixd/core/config.h
Normal file
@@ -0,0 +1,848 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_config
|
||||
#define headerfile_winix_core_config
|
||||
|
||||
#include <string>
|
||||
#include "space/spaceparser.h"
|
||||
#include "log.h"
|
||||
#include "filelog.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
|
||||
// name of the config file
|
||||
// this is the parameter passed to winix programm
|
||||
std::wstring config_file;
|
||||
|
||||
// server mode
|
||||
// you can assign any string to it such as "production" "dev"
|
||||
// this value is not used by winix itself
|
||||
// you can refer to it from [server_mode] and [server_mode_is] ezc functions
|
||||
std::wstring server_mode;
|
||||
|
||||
|
||||
// start as a demon (in the background)
|
||||
// default: true
|
||||
bool demonize;
|
||||
|
||||
// system user's name to whom winix should drop privileges
|
||||
// used only if winix is started as the root
|
||||
std::wstring user;
|
||||
|
||||
// system group's name to which drop privileges
|
||||
// used only if winix is started as the root
|
||||
std::wstring group;
|
||||
|
||||
// setting additional effective groups from /etc/group
|
||||
// by using initgroups()
|
||||
// used only if winix is started as the root
|
||||
// default: true
|
||||
bool additional_groups;
|
||||
|
||||
// log file name
|
||||
std::wstring log_file;
|
||||
|
||||
// the log level (how much info should be inserted to logs)
|
||||
// 1 - minimum
|
||||
// 2 - (default)
|
||||
// 3 - maximum - all logs
|
||||
int log_level;
|
||||
|
||||
// logging to stdout too
|
||||
// this option is valid only if 'demonize' option is set to 'false'
|
||||
// default: false
|
||||
bool log_stdout;
|
||||
|
||||
// how many requests should be saved in the same time
|
||||
// if you have a very busy server you can incrase this value
|
||||
// default: 1
|
||||
int log_request;
|
||||
|
||||
// whether to save each line of the config (used for debugging purposes)
|
||||
// default: false
|
||||
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
|
||||
// warning: use it only on a developer's server as it logs the hashes of passwords too
|
||||
// default: false
|
||||
bool log_db_query;
|
||||
|
||||
// logging when a plugin function is called
|
||||
// default: false
|
||||
bool log_plugin_call;
|
||||
|
||||
|
||||
// how many characters in values should be logged from POST parameters
|
||||
// default: 80
|
||||
// set to 0 to turn it off
|
||||
size_t log_post_value_size;
|
||||
|
||||
// request delimiter in the log file, default "---------"
|
||||
std::wstring log_delimiter;
|
||||
|
||||
// log environment variables (fastcgi environment)
|
||||
bool log_env_variables;
|
||||
|
||||
// log environment http variables (only HTTP_* variables from fastcgi environment)
|
||||
bool log_env_http_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)
|
||||
std::wstring fcgi_socket;
|
||||
|
||||
// fast cgi: socket permissions
|
||||
// chmod and chown of the socket are set before winix drops privileges
|
||||
int fcgi_socket_chmod;
|
||||
|
||||
// fast cgi: owner of the socket
|
||||
// chmod and chown of the socket are set before winix drops privileges
|
||||
std::wstring fcgi_socket_user;
|
||||
|
||||
// fast cgi: group of the socket
|
||||
// chmod and chown of the socket are set before winix drops privileges
|
||||
std::wstring fcgi_socket_group;
|
||||
|
||||
// fcgi_socket_listen is the listen queue depth used in the listen() call
|
||||
// when creating a FastCGI socket for the web server
|
||||
// default: 100
|
||||
int fcgi_socket_listen;
|
||||
|
||||
std::wstring templates_dir;
|
||||
std::wstring templates_dir_default; // html templates from winix
|
||||
|
||||
std::wstring txt_templates_dir;
|
||||
std::wstring txt_templates_dir_default; // txt (notifications) templates from winix
|
||||
|
||||
// prefix and postfix for functions templates
|
||||
// default:
|
||||
// prefix: "fun_"
|
||||
// postfix: ".html"
|
||||
std::wstring templates_fun_prefix;
|
||||
std::wstring templates_fun_postfix;
|
||||
|
||||
// main html template
|
||||
// default: index.html
|
||||
std::wstring templates_index;
|
||||
|
||||
// html template used to send raw content
|
||||
// default: index_raw.html
|
||||
std::wstring templates_index_raw;
|
||||
|
||||
// if true then only root can use 'template' winix function
|
||||
// default: false
|
||||
bool template_only_root_use_template_fun;
|
||||
|
||||
// the database name, user name and a password for the PostgreSQL database
|
||||
std::wstring db_database;
|
||||
std::wstring db_user;
|
||||
std::wstring db_pass;
|
||||
|
||||
// is the PostgreSQL later than 10
|
||||
// default false
|
||||
// if true then we are not using ROW() statements in sql query
|
||||
bool db_postgresql_smaller_than_10;
|
||||
|
||||
// the name of the cookie which has the session identifier
|
||||
std::wstring http_session_id_name;
|
||||
|
||||
// string used in a place where is a user (or group) selected
|
||||
// !! IMPROVE ME should be moved to locales
|
||||
std::wstring priv_no_user;
|
||||
std::wstring priv_no_group;
|
||||
|
||||
// time in seconds when a user will be automatically logged out (iddle time)
|
||||
// default: 10800 = 3 hours
|
||||
int session_max_idle;
|
||||
|
||||
// time in seconds when a user will be automatically logged out
|
||||
// when he has selected the 'remember me' option when logging in
|
||||
// this time is usually greater than session_max_idle
|
||||
// default: 16070400 = 3 months
|
||||
int session_remember_max_idle;
|
||||
|
||||
// a file to which winix stores sessions info
|
||||
// it is used when winix starts (boots) and quits
|
||||
std::wstring session_file;
|
||||
|
||||
// how many sessions can be (zero turn off this checking)
|
||||
// default: 1000000 (one milion)
|
||||
size_t session_max;
|
||||
|
||||
// whether or not we should encode the session cookie
|
||||
// (we have a special algorithm)
|
||||
// default: false
|
||||
bool session_cookie_encode;
|
||||
|
||||
// if session_cookie_encode is true then you should provide
|
||||
// a file where AES keys will be stored
|
||||
std::wstring session_keys_file;
|
||||
|
||||
// each session has an index -- an unsigned int value
|
||||
// this value is sent in the cookie string (is encoded)
|
||||
// and is incremented when session_index_time_increment time is passed since the last incrementing
|
||||
// if a client sent the cookie back the difference between
|
||||
// current index and the index in the cookie should be less than or equal to session_allow_index_difference
|
||||
// default: 8
|
||||
size_t session_allow_index_difference;
|
||||
|
||||
// the time which should pass after the session index is incremented
|
||||
// default: 30
|
||||
// (session_allow_index_difference + 1) * session_index_time_increment should be less than a time
|
||||
// load of a page and all elements on it such as images (of course it depends on client's download too)
|
||||
time_t session_index_time_increment;
|
||||
|
||||
// time in seconds after a new AES key pair should be generated
|
||||
// we have 256 pairs of keys so this time multiplied by 256 should not be less than
|
||||
// the max time of a session (session_remember_max_idle),
|
||||
// by default: 256 * 2 days = 512 days = 1.4 year > 3 months (session_remember_max_idle)
|
||||
// default: 172800 = 2 days (max: 2678400 = 1 month, min: 10)
|
||||
size_t session_key_renew_time;
|
||||
|
||||
// after how many broken encoded cookie we should ban the current IP
|
||||
// default: 2 (value in the range <0 - 65535>)
|
||||
size_t broken_encoded_cookie_treshold;
|
||||
|
||||
// after how many incorrect session identifiers (or session indices) we should ban the current IP
|
||||
// do not set this value too low, as people connecting from the same IP address (from behind a NAT)
|
||||
// would be banned if they have an old session cookie remembered in the browser
|
||||
// default: 128 (value in the range <0 - 65535>)
|
||||
size_t session_hijacking_treshold;
|
||||
|
||||
// after how many times a client will be banned (or given temporary session) if it did not send a session cookie
|
||||
// this can be a bot such as a Google Bot or just people connecting from a NAT and all have the same IP
|
||||
// default: 128 (value in the range <0 - 65535>)
|
||||
size_t no_session_cookie_treshold;
|
||||
|
||||
// the way we behave when no_session_cookie_treshold limit is exceeded
|
||||
// 0 - if a client doesn't send a session cookie again then use a temporary session
|
||||
// (other sessions from this IP address are not affected)
|
||||
// 1 - add this IP address to ban list and create a temporary session
|
||||
// (this will block other sessions from this IP address too)
|
||||
// default: 0
|
||||
int no_session_cookie_ban_mode;
|
||||
|
||||
// allow the winix output to be compressed
|
||||
// default: true
|
||||
bool compression;
|
||||
|
||||
// compress only if the output is greater or equal to this value
|
||||
// default: 512 bytes
|
||||
size_t compression_page_min_size;
|
||||
|
||||
// 1 - use deflate if available (or raw deflate for Internet Explorer) or don't compress
|
||||
// 2 - use gzip if available or don't compress
|
||||
// 10 - prefer deflate -- use deflate (or raw deflate for IE) if both deflate and gzip are available
|
||||
// 20 - prefer gzip -- use gzip if both deflate and gzip are available
|
||||
// default: 20
|
||||
int compression_encoding;
|
||||
|
||||
// plugins directory
|
||||
// default: /usr/local/winix/plugins
|
||||
std::wstring plugins_dir;
|
||||
|
||||
// plugins
|
||||
// you can provide either a relative path (plugins_dir will be used)
|
||||
// or a full path to a plugin
|
||||
std::vector<std::wstring> plugin_file;
|
||||
|
||||
// should the html code be cleaned by the html filter
|
||||
bool html_filter;
|
||||
|
||||
// should white characters be trimmed
|
||||
bool html_filter_trim_white;
|
||||
|
||||
// when long words should be broken (a space will be inserted)
|
||||
// default: after 60 non white characters there will be put a space
|
||||
// set zero to turn off
|
||||
size_t html_filter_break_word;
|
||||
|
||||
// when long lines should be broken (a new line character will be inserted)
|
||||
// default: 110
|
||||
// set zero to turn off
|
||||
size_t html_filter_wrap_line;
|
||||
|
||||
// how many spaces will be put at one tree level
|
||||
// default: 2
|
||||
size_t html_filter_tabs;
|
||||
|
||||
// use checking for 'orphans' for a specicic language
|
||||
// default: true
|
||||
bool html_filter_orphans;
|
||||
|
||||
// orphans mode
|
||||
// either: "nbsp" or "160"
|
||||
// default: "nbsp"
|
||||
std::wstring html_filter_orphans_mode_str;
|
||||
|
||||
// the html nofilter tag
|
||||
// content betweeng these tags (opening and closing) will not be filtered
|
||||
// and this tag will not be included in the html output
|
||||
// default: nofilter
|
||||
std::wstring html_filter_nofilter_tag;
|
||||
|
||||
// the url of a new empty item (if there is not the subject too)
|
||||
// !! IMPROVE ME should be moved to locale
|
||||
std::wstring item_url_empty;
|
||||
|
||||
// maximum length of a file send by post multipart form
|
||||
// default: 8388608 - 8MB
|
||||
// 0 - not used
|
||||
size_t post_file_max;
|
||||
|
||||
// directory for static files
|
||||
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)
|
||||
// default: 0750
|
||||
int upload_dirs_chmod;
|
||||
|
||||
// chmod of newly created files (under upload_dir)
|
||||
// default: 0640
|
||||
int upload_files_chmod;
|
||||
|
||||
// create a thumbnail from an image
|
||||
// default: true
|
||||
bool create_thumb;
|
||||
|
||||
// the mode of creating a thumbnail
|
||||
// width means thumb_cx, height means thumb_cy
|
||||
// 1: Width given, height automagically selected to preserve aspect ratio.
|
||||
// 2: Height given, width automagically selected to preserve aspect ratio.
|
||||
// 3: Maximum values of height and width given, aspect ratio preserved.
|
||||
// 4: Minimum values of width and height given, aspect ratio preserved.
|
||||
// 5: Width and height emphatically given, original aspect ratio ignored.
|
||||
// 6: Change as per widthxheight (3) but only if an image dimension exceeds a specified dimension.
|
||||
// 7: Change dimensions only if both image dimensions are less than specified dimensions.
|
||||
// default: 2
|
||||
int thumb_mode;
|
||||
|
||||
// width of thumbnails
|
||||
// default: 150
|
||||
size_t thumb_cx;
|
||||
|
||||
// height of thumbnails
|
||||
// default: 150
|
||||
size_t thumb_cy;
|
||||
|
||||
// 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
|
||||
std::wstring convert_cmd;
|
||||
|
||||
// directory with locale files
|
||||
std::wstring locale_dir;
|
||||
|
||||
// directory with default locale files (those from winix)
|
||||
std::wstring locale_dir_default;
|
||||
|
||||
// locale files (e.g. "en", "pl")
|
||||
// default: only one item: en
|
||||
std::vector<std::wstring> locale_files;
|
||||
|
||||
// a maximum value of a locale identifier
|
||||
// default: 100 (maximum: 1000)
|
||||
// each locale files should have its own identifier (in "winix_locale_id" field)
|
||||
// from zero to this value
|
||||
size_t locale_max_id;
|
||||
|
||||
// locale for not logged users
|
||||
// or for newly created accounts
|
||||
// default: 0
|
||||
size_t locale_default_id;
|
||||
|
||||
// url protocol
|
||||
// default: http://
|
||||
std::wstring url_proto;
|
||||
|
||||
// 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: false
|
||||
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;
|
||||
|
||||
// winix is testing an environment variable "HTTPS" for the value "on"
|
||||
// to think that the connection is made via SSL
|
||||
// you can set assume_connection_is_through_ssl to true for the winix
|
||||
// to not testing any environment variables but just think the connection
|
||||
// was made by https (useful when using proxy)
|
||||
// default: false
|
||||
bool assume_connection_is_through_ssl;
|
||||
|
||||
// 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;
|
||||
|
||||
// static content not authorized by winix
|
||||
// (e.g. static.someserver.com)
|
||||
std::wstring base_url_static;
|
||||
|
||||
// additional static server for common content (not authorized)
|
||||
// (e.g. common.someserver.com)
|
||||
std::wstring base_url_common;
|
||||
|
||||
// separator used in <title> html tag
|
||||
std::wstring title_separator;
|
||||
|
||||
// http header recognized by www server as a file to send back
|
||||
// default: X-LIGHTTPD-send-file
|
||||
std::wstring http_header_send_file;
|
||||
|
||||
// in editors (emacs, ckeditor,...) the html will be filtered and unsafe tags
|
||||
// will be dropped (script, frame, etc.)
|
||||
// default: true;
|
||||
bool editors_html_safe_mode;
|
||||
|
||||
// don't filter the html code for root
|
||||
// default: true
|
||||
// (if true the html code for root is not filtered)
|
||||
bool editors_html_safe_mode_skip_root;
|
||||
|
||||
// how many maximum symlinks can be followed
|
||||
// (symlinks on directories as well)
|
||||
// default: 20
|
||||
size_t symlinks_follow_max;
|
||||
|
||||
// the prefix of a name of html form controls used in the ticket plugin
|
||||
// default: ticketparam
|
||||
std::wstring ticket_form_prefix;
|
||||
|
||||
// the minimal size of a user's password
|
||||
// default: 5
|
||||
size_t pass_min_size;
|
||||
|
||||
// how passwords should be stored
|
||||
// 0 - plain text
|
||||
// 1 - md4 hash
|
||||
// 2 - md5 hash
|
||||
// 10 - sha1 hash
|
||||
// 11 - sha224 hash
|
||||
// 12 - sha256 hash (default)
|
||||
// 13 - sha384 hash
|
||||
// 14 - sha512 hash
|
||||
int pass_type;
|
||||
|
||||
// whether the passwords' hashes should be salted or not
|
||||
// this affects newly created accounts
|
||||
// default: false
|
||||
bool pass_hash_use_salt;
|
||||
|
||||
// salt to a password's hash
|
||||
// default empty
|
||||
// !! once you set this salt don't change it any more (people wouldn't be allowed to login)
|
||||
std::wstring pass_hash_salt;
|
||||
|
||||
// whether the passwords' hashes should be encrypted
|
||||
// this affects newly created accounts
|
||||
// default: false
|
||||
bool pass_use_rsa;
|
||||
|
||||
// path to a RSA private key
|
||||
// this is actually private + public key in one file
|
||||
// generated by "openssl genrsa"
|
||||
// default empty which means encryption will not be used
|
||||
// !! once you set these keys don't change it any more (people wouldn't be allowed to login)
|
||||
std::wstring pass_rsa_private_key;
|
||||
|
||||
// path to 'openssl'
|
||||
// default: /usr/bin/openssl
|
||||
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
|
||||
// those streams used in ajax responses
|
||||
// you can use no more [ezc out] statements than this limit
|
||||
// default: 128
|
||||
size_t ezc_out_streams_size;
|
||||
|
||||
// prefix and postfix used when there is an error in Ezc patterns
|
||||
// default:
|
||||
// prefix: "<!-- "
|
||||
// postfix: " -->"
|
||||
std::wstring ezc_error_prefix;
|
||||
std::wstring ezc_error_postfix;
|
||||
|
||||
// when true then when a user want to create a new account
|
||||
// he has to provide his email and a message will be sent back to him
|
||||
// with a link to activate the account
|
||||
// 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 (value in the range <0 - 65535>)
|
||||
size_t incorrect_login_captcha_treshold;
|
||||
|
||||
// the way how we prevent to login if there are too many incorrect login attempts
|
||||
// 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 (value in the range <0 - 65535>)
|
||||
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;
|
||||
|
||||
// allow to use [ezc out] statement in executable items (used in 'run' winix function)
|
||||
// default false
|
||||
// warning: if you enable this options a user can override a different output stream when using ajax
|
||||
bool allow_ezc_out_in_executable_items;
|
||||
|
||||
|
||||
// check whether there is a 'log_proxy_ip_header' header
|
||||
// and if so then log the IP address from it
|
||||
// default: false
|
||||
bool check_proxy_ip_header;
|
||||
|
||||
// proxy header representing the real IP address of a client
|
||||
// default: X_Real_IP
|
||||
std::wstring proxy_ip_header;
|
||||
|
||||
// antispam mechanizm
|
||||
// size of an list for map: form_id to counter_id for anonymous users (each session has such an map)
|
||||
// this value allowes you to open the same or different html form in the browser more than once
|
||||
// and each form has its own form_id and counter_id
|
||||
// default: 10 (max ten forms can be open in different tabs)
|
||||
size_t antispam_list_max_size;
|
||||
|
||||
|
||||
Config();
|
||||
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
|
||||
|
||||
/*
|
||||
*
|
||||
* CHECK ME
|
||||
* there was a change in Pikotools
|
||||
* before Text() returns a reference to the std::wstring
|
||||
*
|
||||
*/
|
||||
std::wstring Text(const wchar_t * name);
|
||||
std::wstring Text(const wchar_t * name, const wchar_t * def);
|
||||
std::wstring Text(const std::wstring & name, const wchar_t * def);
|
||||
|
||||
std::wstring & TextRef(const wchar_t * name);
|
||||
std::wstring & TextRef(const wchar_t * name, const wchar_t * def);
|
||||
std::wstring & TextRef(const std::wstring & name, const wchar_t * def);
|
||||
|
||||
int Int(const wchar_t *);
|
||||
int Int(const wchar_t * 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 * 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);
|
||||
bool ListText(const wchar_t * 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
|
||||
void Print(std::wostream & out);
|
||||
|
||||
// raw access to the config
|
||||
PT::Space space;
|
||||
|
||||
|
||||
void SetFileLog(FileLog * file_log);
|
||||
void SetLogBuffer(PT::WTextStream * log_buffer);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
PT::SpaceParser parser;
|
||||
bool errors_to_stdout;
|
||||
Log log;
|
||||
|
||||
void ShowError();
|
||||
void AssignValues(bool stdout_is_closed);
|
||||
void SetAdditionalVariables();
|
||||
void CheckPasswd();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
121
winixd/core/cookieparser.h
Normal file
121
winixd/core/cookieparser.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_cookieparser
|
||||
#define headerfile_winix_core_cookieparser
|
||||
|
||||
#include "httpsimpleparser.h"
|
||||
#include "requesttypes.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
class CookieParser : public HttpSimpleParser
|
||||
{
|
||||
|
||||
const wchar_t * cookie_string;
|
||||
CookieTab * cookie_tab;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual int GetChar()
|
||||
{
|
||||
if( !cookie_string || *cookie_string == 0 )
|
||||
return -1;
|
||||
|
||||
return (int)*(cookie_string++);
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void Parameter(std::wstring & name, std::wstring & value)
|
||||
{
|
||||
// Cookie names are case insensitive according to section 3.1 of RFC 2965
|
||||
// (we don't use locale here)
|
||||
ToLower(name);
|
||||
|
||||
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(name, value) );
|
||||
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
|
||||
|
||||
if( res.second == false )
|
||||
{
|
||||
res.first->second = value;
|
||||
log << " (overwritten)";
|
||||
}
|
||||
|
||||
log << logend;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
CookieParser()
|
||||
{
|
||||
HttpSimpleParser::separator = ';';
|
||||
HttpSimpleParser::value_can_be_quoted = true;
|
||||
HttpSimpleParser::skip_white_chars = true;
|
||||
HttpSimpleParser::recognize_special_chars = false;
|
||||
HttpSimpleParser::getchar_returns_utf8_chars = false;
|
||||
}
|
||||
|
||||
|
||||
// cookie_string can be null
|
||||
void Parse(const wchar_t * cookie_string_, CookieTab & cookie_tab_)
|
||||
{
|
||||
cookie_string = cookie_string_;
|
||||
cookie_tab = &cookie_tab_;
|
||||
|
||||
HttpSimpleParser::Parse();
|
||||
}
|
||||
|
||||
void Parse(const std::wstring & cookie_string_, CookieTab & cookie_tab_)
|
||||
{
|
||||
Parse(cookie_string_.c_str(), cookie_tab_);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
356
winixd/core/crypt.cpp
Normal file
356
winixd/core/crypt.cpp
Normal file
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* 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-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include "crypt.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "log.h"
|
||||
#include "misc.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
//void Crypt::SetConfig(Config * pconfig)
|
||||
//{
|
||||
// config = pconfig;
|
||||
//}
|
||||
|
||||
|
||||
void Crypt::set_dependency(WinixBase * winix_base)
|
||||
{
|
||||
WinixBase::set_dependency(winix_base);
|
||||
run.set_dependency(winix_base);
|
||||
}
|
||||
|
||||
|
||||
char Crypt::ConvertToHexForm(int val)
|
||||
{
|
||||
if( val < 10 )
|
||||
return val + '0';
|
||||
|
||||
return val - 10 + 'a';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const char * in, size_t inlen, std::string & out)
|
||||
{
|
||||
out.clear();
|
||||
|
||||
if( !config )
|
||||
return false;
|
||||
|
||||
run.Clear();
|
||||
run.set_dependency(this);
|
||||
PT::WideToUTF8(config->opensll_path, command);
|
||||
run.Cmd(command);
|
||||
run.Par("dgst");
|
||||
run.Par("-binary");
|
||||
|
||||
switch(hash)
|
||||
{
|
||||
case WINIX_CRYPT_HASH_MD4: run.Par("-md4"); break;
|
||||
case WINIX_CRYPT_HASH_MD5: run.Par("-md5"); break;
|
||||
case WINIX_CRYPT_HASH_SHA1: run.Par("-sha1"); break;
|
||||
case WINIX_CRYPT_HASH_SHA224: run.Par("-sha224"); break;
|
||||
case WINIX_CRYPT_HASH_SHA256: run.Par("-sha256"); break;
|
||||
case WINIX_CRYPT_HASH_SHA384: run.Par("-sha384"); break;
|
||||
case WINIX_CRYPT_HASH_SHA512: run.Par("-sha512"); break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return run.Go(in, inlen, out) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const char * in, std::string & out)
|
||||
{
|
||||
size_t len = strlen(in);
|
||||
return HashBin(hash, in, len, out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const std::string & in, std::string & out)
|
||||
{
|
||||
return HashBin(hash, in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out)
|
||||
{
|
||||
PT::WideToUTF8(in, inlen, bufina);
|
||||
int res = HashBin(hash, bufina.c_str(), bufina.size(), out);
|
||||
bufina.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const wchar_t * in, std::string & out)
|
||||
{
|
||||
size_t len = wcslen(in);
|
||||
return HashBin(hash, in, len, out);
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::HashBin(int hash, const std::wstring & in, std::string & 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);
|
||||
}
|
||||
|
||||
|
||||
bool IsAllWhite(const char * str)
|
||||
{
|
||||
for( ; *str ; ++str)
|
||||
{
|
||||
if( !(IsWhite(*str) || *str==10) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::RSA(bool encrypt, const char * keypath, const char * in, size_t inlen, std::string & out)
|
||||
{
|
||||
out.clear();
|
||||
|
||||
if( !config || IsAllWhite(keypath) )
|
||||
return false;
|
||||
|
||||
run.Clear();
|
||||
PT::WideToUTF8(config->opensll_path, command);
|
||||
run.Cmd(command);
|
||||
|
||||
run.Par("rsautl");
|
||||
run.Par("-inkey");
|
||||
run.Par(keypath);
|
||||
|
||||
if(encrypt)
|
||||
run.Par("-encrypt");
|
||||
else
|
||||
run.Par("-decrypt");
|
||||
|
||||
return run.Go(in, inlen, out) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::RSA(bool encrypt, const char * keypath, const std::string & in, std::string & out)
|
||||
{
|
||||
return RSA(encrypt, keypath, in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::RSA(bool encrypt, const std::string & keypath, const std::string & in, std::string & out)
|
||||
{
|
||||
return RSA(encrypt, keypath.c_str(), in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out)
|
||||
{
|
||||
PT::WideToUTF8(keypath, keypatha);
|
||||
return RSA(encrypt, keypatha.c_str(), in, inlen, out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const std::string & in, std::string & out)
|
||||
{
|
||||
return RSA(encrypt, keypath, in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
bool Crypt::RSA(bool encrypt, const std::wstring & keypath, const std::string & in, std::string & out)
|
||||
{
|
||||
return RSA(encrypt, keypath.c_str(), in.c_str(), in.size(), out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
|
||||
{
|
||||
bool result = true;
|
||||
up.pass_hash_salted = false;
|
||||
|
||||
if( up.pass_type != WINIX_CRYPT_HASH_NONE )
|
||||
{
|
||||
pass_org = up.pass;
|
||||
pass_salted = up.pass;
|
||||
pass_salted += salt;
|
||||
|
||||
if( HashHex(up.pass_type, pass_salted, up.pass) )
|
||||
{
|
||||
if( !salt.empty() )
|
||||
up.pass_hash_salted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
|
||||
|
||||
up.pass = pass_org;
|
||||
up.pass_type = WINIX_CRYPT_HASH_NONE;
|
||||
result = false;
|
||||
}
|
||||
|
||||
ClearString(pass_salted);
|
||||
ClearString(pass_org);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Crypt::PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up)
|
||||
{
|
||||
bool result = false;
|
||||
ClearString(up.pass_encrypted);
|
||||
|
||||
if( !path_to_rsa_private_key.empty() )
|
||||
{
|
||||
PT::WideToUTF8(up.pass, passa);
|
||||
|
||||
if( RSA(true, path_to_rsa_private_key, passa, up.pass_encrypted) )
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearString(up.pass_encrypted);
|
||||
log << log1 << "AddUser: problem with encrypting, the password will not be encrypted!" << logend;
|
||||
}
|
||||
|
||||
ClearString(passa);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Crypt::PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up)
|
||||
{
|
||||
PassHash(salt, up);
|
||||
PassCrypt(path_to_rsa_private_key, up);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Crypt::PassHashCrypt(UserPass & up)
|
||||
{
|
||||
up.pass_type = config->pass_type;
|
||||
empty.clear();
|
||||
|
||||
if( config->pass_hash_use_salt && !config->pass_hash_salt.empty() )
|
||||
PassHash(config->pass_hash_salt, up);
|
||||
else
|
||||
PassHash(empty, up);
|
||||
|
||||
|
||||
if( config->pass_use_rsa && !config->pass_rsa_private_key.empty() )
|
||||
PassCrypt(config->pass_rsa_private_key, up);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
299
winixd/core/crypt.h
Normal file
299
winixd/core/crypt.h
Normal file
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* 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_crypt
|
||||
#define headerfile_winix_core_crypt
|
||||
|
||||
#include <string>
|
||||
#include "run.h"
|
||||
#include "config.h"
|
||||
#include "user.h"
|
||||
#include "winixbase.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
/*
|
||||
the kind of hashes we are able to obtain in winix
|
||||
*/
|
||||
#define WINIX_CRYPT_HASH_NONE 0
|
||||
#define WINIX_CRYPT_HASH_MD4 1
|
||||
#define WINIX_CRYPT_HASH_MD5 2
|
||||
#define WINIX_CRYPT_HASH_SHA1 10
|
||||
#define WINIX_CRYPT_HASH_SHA224 11
|
||||
#define WINIX_CRYPT_HASH_SHA256 12
|
||||
#define WINIX_CRYPT_HASH_SHA384 13
|
||||
#define WINIX_CRYPT_HASH_SHA512 14
|
||||
|
||||
|
||||
|
||||
/*
|
||||
calculating hashes, encrypting and decrypting with RSA
|
||||
*/
|
||||
class Crypt : public WinixBase
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
void set_dependency(WinixBase * winix_base);
|
||||
|
||||
|
||||
//void SetConfig(Config * pconfig);
|
||||
|
||||
|
||||
/*
|
||||
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 binary form
|
||||
*/
|
||||
bool HashBin(int hash, const char * in, size_t inlen, std::string & out);
|
||||
bool HashBin(int hash, const char * in, std::string & out);
|
||||
bool HashBin(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 binary form
|
||||
*/
|
||||
bool HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out);
|
||||
bool HashBin(int hash, const wchar_t * in, std::string & 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);
|
||||
|
||||
|
||||
/*
|
||||
encrypt/decrypt by using RSA algorithm
|
||||
|
||||
input:
|
||||
encrypt - true means encrypting, false means decrypting
|
||||
keypath - path to a RSA private key (this is a private and public key in one file)
|
||||
in - input buffer
|
||||
inlen - the size of the buffer
|
||||
|
||||
output:
|
||||
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 std::string & in, std::string & out);
|
||||
bool RSA(bool encrypt, const std::string & keypath, const std::string & in, std::string & out);
|
||||
bool RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out);
|
||||
bool RSA(bool encrypt, const wchar_t * keypath, const std::string & in, std::string & out);
|
||||
bool RSA(bool encrypt, const std::wstring & keypath, const std::string & in, std::string & out);
|
||||
|
||||
|
||||
/*
|
||||
this method creates a hash from the given plain text password
|
||||
|
||||
input.
|
||||
salt - salt for the hash
|
||||
up.pass_type - what kind of hash do you want - look at WINIX_CRYPT_HASH_* macros (in crypt.h)
|
||||
up.pass - plain text password
|
||||
|
||||
if salt is empty then the hash will not be salted
|
||||
|
||||
output:
|
||||
up.pass_type - (can be changed to 0 when there is a problem with generating a hash)
|
||||
up.pass - hash from the password (or plain text if up.pass_type was zero)
|
||||
up.pass_hash_salted (true if the hash is salted - when salt was not empty)
|
||||
|
||||
if there is a problem with generating a hash the method stores a plain text password
|
||||
and changes up.pass_type to zero (plain text passwords are not salted)
|
||||
*/
|
||||
bool PassHash(const std::wstring & salt, UserPass & up);
|
||||
|
||||
|
||||
/*
|
||||
this method encrypts the given password
|
||||
|
||||
input:
|
||||
path_to_rsa_private_key - a path to rsa private key (this are a private and public keys both in one file)
|
||||
up.pass - given password (can be a plain text or a hash)
|
||||
|
||||
if path_to_rsa_private_key is empty then the password will not be encrypted
|
||||
|
||||
output:
|
||||
up.pass_encrypted
|
||||
|
||||
if there is a problem (or the path to the key is empty) then up.pass_encrypted will be empty
|
||||
and the method returns false
|
||||
*/
|
||||
bool PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up);
|
||||
|
||||
|
||||
/*
|
||||
this method creates a hash from the given plain text password and then encrypts it
|
||||
|
||||
input:
|
||||
salt - salt for the hash
|
||||
path_to_rsa_private_key - a path to rsa private key (this are a private and public keys both in one file)
|
||||
up.pass_type - what kind of hash do you want - look at WINIX_CRYPT_HASH_* macros (in crypt.h)
|
||||
up.pass - plain text password
|
||||
|
||||
if salt is empty then the hash will not be salted
|
||||
if path_to_rsa_private_key is empty then the password will not be encrypted
|
||||
|
||||
output:
|
||||
up.pass_type - (can be changed to 0 when there is a problem with generating a hash)
|
||||
up.pass - hash from the password (or plain text if up.pass_type was zero)
|
||||
up.pass_hash_salted (true if the hash is salted - when salt was not empty)
|
||||
up.pass_encrypted - encrypted password (if not empty)
|
||||
|
||||
*/
|
||||
void PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up);
|
||||
|
||||
|
||||
/*
|
||||
this method creates a hash from the given plain text password and then encrypts it
|
||||
|
||||
input:
|
||||
up.pass - plain text password
|
||||
|
||||
output:
|
||||
up.pass_type - what kind of hash there is in up.pass
|
||||
up.pass - hash from the password (or plain text if up.pass_type is zero)
|
||||
up.pass_hash_salted - true if the hash is salted (plain text are never salted)
|
||||
up.pass_encrypted - encrypted password (if not empty)
|
||||
*/
|
||||
void PassHashCrypt(UserPass & up);
|
||||
|
||||
|
||||
/*
|
||||
putting some characters into the string and then calling clear()
|
||||
*/
|
||||
template<class StringType>
|
||||
void ClearString(StringType & str);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//Config * config;
|
||||
Run run;
|
||||
std::string command, bufina, keypatha;
|
||||
//std::wstring pass_salted;//, pass_hashed;
|
||||
//std::string pass_hasheda, pass_encrypteda;
|
||||
|
||||
std::wstring pass_salted, pass_org;
|
||||
std::string passa, out_temp;
|
||||
std::wstring empty;
|
||||
|
||||
|
||||
template<typename StringType>
|
||||
void ConvertToHexForm(const std::string & in, StringType & out);
|
||||
|
||||
char ConvertToHexForm(int val);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename StringType>
|
||||
void Crypt::ClearString(StringType & str)
|
||||
{
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
str[i] = 0x0c;
|
||||
|
||||
str.clear();
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user