Compare commits
574 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c32ed6ce28
|
|||
|
6631ba0641
|
|||
|
98320fe174
|
|||
|
b8105cf9cc
|
|||
|
d7a93916e3
|
|||
|
cec9dfc0e1
|
|||
|
893b3d9fff
|
|||
|
7de9d1a819
|
|||
|
8748a63532
|
|||
|
5eed025419
|
|||
|
f2e416b0f8
|
|||
|
1c7043fa3e
|
|||
|
2bd4c5b35e
|
|||
|
f4481a84f4
|
|||
|
4c740690e0
|
|||
|
128c79cdc4
|
|||
|
7082677b2f
|
|||
|
257d8bbade
|
|||
|
a6ca71b131
|
|||
|
8634716aa7
|
|||
|
8a12629740
|
|||
|
b07f2f7a59
|
|||
|
da90ef8e40
|
|||
|
197f684488
|
|||
|
e63838faeb
|
|||
|
89b37db48e
|
|||
|
68e7f44a76
|
|||
|
2490e2cc68
|
|||
|
b2f4c065ea
|
|||
|
20b40597fd
|
|||
|
7df78838aa
|
|||
|
b3bd9c6cf0
|
|||
|
dadff8329e
|
|||
|
c30b7db041
|
|||
|
6aa100f12c
|
|||
|
5d457f3d4b
|
|||
|
af0d34beb9
|
|||
|
d122917f83
|
|||
|
612501217c
|
|||
|
d86ab8f9c0
|
|||
|
5a33563722
|
|||
|
1c850b12ec
|
|||
|
140b4495df
|
|||
|
8b0b25ed0a
|
|||
|
eacdcfb980
|
|||
|
132e7aa937
|
|||
|
d9f3b69dde
|
|||
|
de753070a8
|
|||
|
c1c6e6a588
|
|||
|
291147503f
|
|||
|
dbf7dfab82
|
|||
|
b753464608
|
|||
|
544ef298aa
|
|||
|
065a2d182f
|
|||
|
f4470ccbe7
|
|||
|
71ad4869ce
|
|||
|
09dc6782c8
|
|||
|
0cebb2dc52
|
|||
|
0724ca8eb3
|
|||
|
53991e54e1
|
|||
|
df7ae1c6ea
|
|||
|
d1f5d9aa88
|
|||
|
a54d70bed4
|
|||
|
bcde5c628a
|
|||
|
f241eb0a18
|
|||
|
74c0c936f6
|
|||
|
79babc916a
|
|||
|
a08bf9f804
|
|||
|
966577cd58
|
|||
|
8f20c8f67c
|
|||
|
f6c04b2d00
|
|||
|
0474c76a3d
|
|||
|
7a29a072be
|
|||
|
24c2ecb8dd
|
|||
|
7a1cea63bf
|
|||
|
e600aebaae
|
|||
|
5e45ad3417
|
|||
|
79e971cb76
|
|||
|
edee581ecf
|
|||
|
f7e077a7c5
|
|||
|
6a9504fd5f
|
|||
|
6d256e6512
|
|||
|
cf383fa026
|
|||
|
c86536d660
|
|||
|
dba87d6213
|
|||
|
52f9d399ca
|
|||
|
7b7a962f19
|
|||
|
c37722c29a
|
|||
|
ca509d3a86
|
|||
|
bf79e46411
|
|||
|
08821eb440
|
|||
|
d7878b5564
|
|||
|
0b52ae80dd
|
|||
|
3e46d8b4b4
|
|||
|
1655ae3562
|
|||
|
dda325bbbf
|
|||
|
c326c2a095
|
|||
|
bf386e2286
|
|||
|
e822e13dc8
|
|||
|
cc2c008bfd
|
|||
|
b8a8013d4c
|
|||
|
12ed77aeb1
|
|||
|
7476048da6
|
|||
|
8a307790c0
|
|||
|
a49b10ed2d
|
|||
|
6a2da642b0
|
|||
|
b836c77950
|
|||
|
2aa4eee20d
|
|||
|
9ada82c4aa
|
|||
|
aa9b83f740
|
|||
|
4ddfd2cd3a
|
|||
|
d15f5e4fa4
|
|||
|
2e455f97ac
|
|||
|
f664cc1a53
|
|||
|
ae505f3201
|
|||
|
d5433cddf1
|
|||
|
52773a271c
|
|||
|
e9311989ab
|
|||
|
7b63c01033
|
|||
| 5972b2bb39 | |||
| f182978ea5 | |||
| ebb8132808 | |||
| 1bd1762258 | |||
| 00b0e251f4 | |||
| 14e32df8c9 | |||
| aa938f05ca | |||
| 4583ab28ed | |||
| 9c0cd6eb5e | |||
| 32c30cf536 | |||
| a8b7a9e122 | |||
| d07ff5b881 | |||
| 66fae598c2 | |||
| 589e889822 | |||
| 89249f1297 | |||
| 2bd56c87e4 | |||
| 204688464e | |||
| 1d0956abab | |||
| c2013ff47f | |||
| 624bf47c8d | |||
| cdd395efa5 | |||
| 47f6e2234c | |||
| 1648092cd5 | |||
| 99fbf6ca27 | |||
| f050fc2316 | |||
| 1015baf111 | |||
| 04f0a2f808 | |||
| 1da240afb9 | |||
| 77a00f5989 | |||
| f3d6494ae5 | |||
| 8edd0ef07a | |||
| 3855ea9fa7 | |||
| a81839fd9c | |||
| 03035f038f | |||
| baa870edbd | |||
| c8bc23312b | |||
| d5e6fb7c54 | |||
| 6138497fe0 | |||
| 05ecac8426 | |||
| 222a1c8a1f | |||
| 04164ff967 | |||
| 9f64692ede | |||
| 8b9ad5d079 | |||
| bff435db9a | |||
| e09a93bd72 | |||
| e378fcfe3b | |||
| a7a338f28e | |||
| a19158cb62 | |||
| 778ed01a55 | |||
| 217f42b7c6 | |||
| a34db6505d | |||
| 7dc117da5e | |||
| b1441366f4 | |||
| c730b85629 | |||
| d3a440fa0a | |||
| 5f77ce619e | |||
| 5dd34c802e | |||
| 3609d94c09 | |||
| 5dc00e95e7 | |||
| e88615226b | |||
| ca1a854fd1 | |||
| ceb5336ca1 | |||
| f651df6e1f | |||
| 6266eac729 | |||
| de972de948 | |||
| 55f48e4f3a | |||
| 39ab07508f | |||
| 968660e8ca | |||
| 4b46ba1fe3 | |||
| a164e6e21e | |||
| 82281b4363 | |||
| 9d8d35b64f | |||
| 33f6a9a213 | |||
| e5ed1d6ae8 | |||
| 9e6a5b2d37 | |||
| c85a724fec | |||
| 2e8f4d1a26 | |||
| 522b57ade4 | |||
| d4da6aa518 | |||
| 979ef907fe | |||
| b2d92b85a0 | |||
| 8d6d0ddbf8 | |||
| 8da76134ce | |||
| 179daf743e | |||
| bcb009b606 | |||
| 327c215e5d | |||
| b484071818 | |||
| 31e826d893 | |||
| e29f912358 | |||
| 26226de865 | |||
| 56d87c4410 | |||
| ebfa5f7405 | |||
| ba16cf41fe | |||
| 01c10bad0e | |||
| 7d1fb3c04e | |||
| 9e222f5b80 | |||
| 3b5658ff8f | |||
| 5e89c4004a | |||
| 9602c28d96 | |||
| 0fd680b496 | |||
| 37d3a44b24 | |||
| da2dec447b | |||
| c6c50a5d23 | |||
| 98c1e8daad | |||
| f99191aa6f | |||
| df04075f1c | |||
| 3d2a635e34 | |||
| aad5db9a6a | |||
| 43ebbdaa33 | |||
| 92c7f90b95 | |||
| aae93d018b | |||
| 7a115a3970 | |||
| 64e5114947 | |||
| 4f8b5e649a | |||
| e0d9989d74 | |||
| 0fe680ef4a | |||
| e182c0a21b | |||
| c8edd241d5 | |||
| a544ccd1a7 | |||
| 7df2205b40 | |||
| 265e843d02 | |||
| 22a8a97389 | |||
| bb74f2a423 | |||
| 2033168db2 | |||
| e377f144fd | |||
| 234ebf8ce8 | |||
| 09cf3c9fa9 | |||
| df32899581 | |||
| 33e8df11c5 | |||
| 75daf37bbd | |||
| d0d2cfb22c | |||
| f7b5ac0dc8 | |||
| 227dd923d6 | |||
| f6cb9a8aed | |||
| b615dc7e6e | |||
| 944560dd2b | |||
| 1d6d29e24d | |||
| ff8e9e6b32 | |||
| 557555c4b3 | |||
| f8e1037476 | |||
| 35cb54324f | |||
| 119497bb01 | |||
| dfd6475a81 | |||
| d6d5236a03 | |||
| a327a26bd5 | |||
| d5ebb7ca12 | |||
| 3e46c5674c | |||
| c4b5565995 | |||
| 3f5eabeaa1 | |||
| 9b8e48e7b2 | |||
| c3122fb82f | |||
| 1741597d52 | |||
| 9c5c74ba84 | |||
| 26ed7b80be | |||
| 55ac9a61ed | |||
| 7673264fe1 | |||
| 42dc43b036 | |||
| ef22d951a0 | |||
| e95dc834a3 | |||
| b424988d1b | |||
| 22134b6cc0 | |||
| f861c0761e | |||
| 1899d5ee17 | |||
| 17bd48ece3 | |||
| c5c02d7f44 | |||
| ba6159964b | |||
| b834971f5e | |||
| 9dc15d536c | |||
| 2e45cb6ac9 | |||
| 2dcfeaa688 | |||
| 9d65d931d0 | |||
| 746aa41111 | |||
| 175dd17416 | |||
| 619936c12e | |||
| 732144df01 | |||
| df3f04a951 | |||
| 0f78968579 | |||
| 66173c7a31 | |||
| 3f934d9aec | |||
| df0cc131fe | |||
| ba60f9da8a | |||
| 4569198b9d | |||
| ccbbb59af7 | |||
| 3a5af25eaf | |||
| 1d18b7fa12 | |||
| 472490c239 | |||
| b6340a30d2 | |||
| bf1f0954b9 | |||
| 2f1cdcf379 | |||
| 443c2023d9 | |||
| 2c5062ba22 | |||
| 99df807095 | |||
| 8ab07d11b1 | |||
| a1c0f6f7f0 | |||
| 672737a0d8 | |||
| ade96bf6d3 | |||
| 801fc062ef | |||
| f35840e7de | |||
| 79eda7abb0 | |||
| e7c7324058 | |||
| d8c1a81bcb | |||
| 94f96c11cb | |||
| ec94dff7d7 | |||
| ebd791a256 | |||
| 4db421d6c3 | |||
| ab89ffe096 | |||
| 53fe5c35b9 | |||
| f2f2c851df | |||
| 6dddc5e948 | |||
| 9688b1a26a | |||
| 81df52f6ca | |||
| 6e4f8f5191 | |||
| 22de3322ae | |||
| e6fae4598c | |||
| ba331dea4a | |||
| 1292a56d1b | |||
| 6a452ffed0 | |||
| fc24570062 | |||
| aa71abd725 | |||
| fb64f5e456 | |||
| 61fe6ea219 | |||
| d30c7254eb | |||
| 06be33ba5f | |||
| b2cffa39e1 | |||
| 86ef2529b1 | |||
| f1b9d1b870 | |||
| fe67b5d72a | |||
| 27720afaf2 | |||
| 8bb585d97d | |||
| 8c523ce8b9 | |||
| e48a28a5c8 | |||
| d66a36cf21 | |||
| a94e09f0aa | |||
| 4df10de6b7 | |||
| 6d07535dad | |||
| ee354d2ded | |||
| e64bd1fba8 | |||
| 031e673c51 | |||
| 801c9a2cda | |||
| 685b3ca5ee | |||
| f1af7e2eeb | |||
| 85f9fda984 | |||
| bb513b0187 | |||
| 4277f90bad | |||
| ccda2bc2fd | |||
| 4b71530f4c | |||
| a8a9db53be | |||
| 634cf07d44 | |||
| 0e0c006d5a | |||
| 486067a4b2 | |||
| 35e10ed469 | |||
| 00b980e74b | |||
| efdc0e7c97 | |||
| 8b64d2066f | |||
| 8d87d9a875 | |||
| 8fc1848ecc | |||
| bbc0a67153 | |||
| e8ba2a7bd1 | |||
| 23f1c112a4 | |||
| 4d76e53554 | |||
| 73352e680e | |||
| 57aad8b454 | |||
| ab5c44a2cb | |||
| 3e84eb9dbf | |||
| afbe82e9f4 | |||
| 51b1aed483 | |||
| 32e93a04c5 | |||
| 3d7ece15f8 | |||
| 541597f355 | |||
| 5fe843d76b | |||
| 3191369ece | |||
| a4de11d69c | |||
| 4832c7db4b | |||
| be83d62f96 | |||
| 3fd2ef1da4 | |||
| d861384889 | |||
| cfd8e88e57 | |||
| 8169cb5a7e | |||
| 8c85cd7346 | |||
| 4e202833b2 | |||
| 4a163bd170 | |||
| 85fbc1b882 | |||
| 61810ff6f9 | |||
| 3a4a29f56d | |||
| 1fb7ece1b3 | |||
| f3879dd3a4 | |||
| 561014886f | |||
| a2b19547a3 | |||
| 93477091d1 | |||
| 64d3c62945 | |||
| 134e27f70a | |||
| 5205aa089b | |||
| b5b9655c1e | |||
| 173d0894fa | |||
| de6b050fb5 | |||
| 37da5e81c5 | |||
| ae8637d455 | |||
| 22a45697fa | |||
| 55462fca9f | |||
| 2799a66c16 | |||
| 9832b17fc2 | |||
| 8146f42492 | |||
| 9df146af3b | |||
| a7629f638f | |||
| e75918f5ed | |||
| 9698c25bc4 | |||
| bbe2bd48d8 | |||
| 0cc565ae80 | |||
| aa74d96fed | |||
| ac6ede6aef | |||
| 10e291bb39 | |||
| 7a25e333db | |||
| a9b9d0badf | |||
| a69e160f85 | |||
| 56d53a455d | |||
| 572afd360a | |||
| ec6f946b97 | |||
| acfd87e548 | |||
| aa228732e3 | |||
| 840c222190 | |||
| 4408957770 | |||
| 89814cbc2e | |||
| fdcefae264 | |||
| 0139919d14 | |||
| 9476bcc7b6 | |||
| 4625451c85 | |||
| 1e345f5010 | |||
| 31befcba44 | |||
| 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 |
@@ -0,0 +1,21 @@
|
|||||||
|
# EditorConfig
|
||||||
|
# https://editorconfig.org/
|
||||||
|
# https://editorconfig-specification.readthedocs.io/
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Unix-style newlines with a newline ending every file
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
# 4 space indentation
|
||||||
|
[*.{h,cpp,html,css,js,conf,txt}]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
# Tab indentation (no size specified)
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
.cproject
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
*.o
|
||||||
|
*.so
|
||||||
|
/winixd/winix
|
||||||
|
/winixcli/src/winix
|
||||||
|
/winixcli/m
|
||||||
|
/.clangd
|
||||||
|
/.qtcreator/
|
||||||
|
/.qtc_clangd/
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-pthread, -std=c++20, -I%%%CURRENT_DIR%%%/winixd, -I%%%GLOBAL_WORKING_DIR%%%/pikotools/src, -I%%%GLOBAL_WORKING_DIR%%%/ezc/src, -I%%%GLOBAL_WORKING_DIR%%%/morm/src, -I%%%GLOBAL_WORKING_DIR%%%/tito/src, -I/usr/include, -I/usr/local/include, -I/usr/local/include/postgresql, -DPT_HAS_MORM_LIBRARY, -DEZC_HAS_MORM_LIBRARY, -DMORM_HAS_EZC_LIBRARY]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-std=c20
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#define PT_HAS_MORM_LIBRARY 1
|
||||||
|
#define EZC_HAS_MORM_LIBRARY 1
|
||||||
|
#define MORM_HAS_EZC_LIBRARY 1
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[General]
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<!-- Written by QtCreator 14.0.1, 2024-09-20T16:21:10. -->
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>EnvironmentId</variable>
|
||||||
|
<value type="QByteArray">%%%QT_ENVIRONMENT_ID%%%</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
<value type="qlonglong">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
|
<value type="QString" key="language">Cpp</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||||
|
<value type="QString" key="language">QmlJS</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
|
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">2</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||||
|
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||||
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
|
<value type="int" key="ClangTools.ParallelJobs">3</value>
|
||||||
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="QString" key="DeviceType">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">%%%QT_DEFAULT_PROFILE_ID%%%</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">%%%CURRENT_DIR%%%</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">all</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand">/usr/local/bin/gmake</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand">/usr/local/bin/gmake</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
|
<value type="qlonglong">1</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>Version</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-std=c++20
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
Executable
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
CURRENT_DIR=$(pwd)
|
||||||
|
GLOBAL_WORKING_DIR=$(realpath ${CURRENT_DIR}/..)
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
# make sure the current directory is correct
|
||||||
|
if [ ! -d ${CURRENT_DIR}/.templates ] ; then
|
||||||
|
echo "this script should be called by make: make clangd (one level up)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# change / to \/ in paths
|
||||||
|
CURRENT_DIR_FOR_SED=$(echo ${CURRENT_DIR} | sed 's/\//\\\//g')
|
||||||
|
GLOBAL_WORKING_DIR_FOR_SED=$(echo ${GLOBAL_WORKING_DIR} | sed 's/\//\\\//g')
|
||||||
|
|
||||||
|
|
||||||
|
if [ -f "${CURRENT_DIR}/.templates/.clangd" ] ; then
|
||||||
|
if [ ! -f "${CURRENT_DIR}/.clangd" ] ; then
|
||||||
|
cat "${CURRENT_DIR}/.templates/.clangd" | \
|
||||||
|
sed -e "s/%%%CURRENT_DIR%%%/${CURRENT_DIR_FOR_SED}/g" \
|
||||||
|
-e "s/%%%GLOBAL_WORKING_DIR%%%/${GLOBAL_WORKING_DIR_FOR_SED}/g" > \
|
||||||
|
${CURRENT_DIR}/.clangd
|
||||||
|
|
||||||
|
echo "added a ${CURRENT_DIR}/.clangd file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
Executable
+105
@@ -0,0 +1,105 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
CURRENT_DIR=$(pwd)
|
||||||
|
GLOBAL_WORKING_DIR=$(realpath ${CURRENT_DIR}/..)
|
||||||
|
QTCREATOR_DIR=${CURRENT_DIR}/.qtcreator
|
||||||
|
|
||||||
|
# ----------
|
||||||
|
|
||||||
|
# make sure the current directory is correct
|
||||||
|
if [ ! -d ${CURRENT_DIR}/.templates ] ; then
|
||||||
|
echo "this script should be called by make: make qtcreator (one level up)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
qtcreatorini=~/.config/QtProject/QtCreator.ini
|
||||||
|
qtprofiles=~/.config/QtProject/qtcreator/profiles.xml
|
||||||
|
|
||||||
|
if [ ! -f "$qtcreatorini" ] ; then
|
||||||
|
echo "I cannot find a $qtcreatorini file"
|
||||||
|
echo "this file is needed to take an EnvironmentId parameter"
|
||||||
|
echo "if QTCreator was recently installed make sure you have opened it at least once"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$qtprofiles" ] ; then
|
||||||
|
echo "I cannot find a $qtprofiles file"
|
||||||
|
echo "this file is needed to take a default profile id parameter"
|
||||||
|
echo "if QTCreator was recently installed make sure you have opened it at least once"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
qtenvironmentid=`grep -F 'Settings\EnvironmentId' "$qtcreatorini" | grep -Eo '\{[a-zA-Z0-9-]+\}'`
|
||||||
|
qtdefaultprofileid=`grep -A 1 -F '<variable>Profile.Default</variable>' "$qtprofiles" | tail -n 1 | grep -Eo '\{[a-zA-Z0-9-]+\}'`
|
||||||
|
|
||||||
|
if [ -z "$qtenvironmentid" ] ; then
|
||||||
|
echo "I cannot read a Settings\EnvironmentId parameter from $qtcreatorini file"
|
||||||
|
exit 4
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$qtdefaultprofileid" ] ; then
|
||||||
|
echo "I cannot read a Profile.Default parameter from $qtprofiles file"
|
||||||
|
exit 5
|
||||||
|
fi
|
||||||
|
|
||||||
|
# change / to \/ in paths
|
||||||
|
CURRENT_DIR_FOR_SED=$(echo ${CURRENT_DIR} | sed 's/\//\\\//g')
|
||||||
|
GLOBAL_WORKING_DIR_FOR_SED=$(echo ${GLOBAL_WORKING_DIR} | sed 's/\//\\\//g')
|
||||||
|
|
||||||
|
was_qtcreator_dir=0
|
||||||
|
|
||||||
|
if [ -d "${QTCREATOR_DIR}" ] ; then
|
||||||
|
was_qtcreator_dir=1
|
||||||
|
else
|
||||||
|
echo "Your QTCreator EnvironmentId is: $qtenvironmentid"
|
||||||
|
echo "Your QTCreator default profile id is: $qtdefaultprofileid"
|
||||||
|
mkdir -p "${QTCREATOR_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "${QTCREATOR_DIR}" ] ; then
|
||||||
|
|
||||||
|
if [ -d ${CURRENT_DIR}/.templates/.qtcreator ] ; then
|
||||||
|
cd ${CURRENT_DIR}/.templates/.qtcreator
|
||||||
|
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
|
||||||
|
for i in * ; do
|
||||||
|
if [ ! -f "${QTCREATOR_DIR}/$i" ] ; then
|
||||||
|
cat "$i" | \
|
||||||
|
sed -e "s/%%%CURRENT_DIR%%%/${CURRENT_DIR_FOR_SED}/g" \
|
||||||
|
-e "s/%%%GLOBAL_WORKING_DIR%%%/${GLOBAL_WORKING_DIR_FOR_SED}/g" \
|
||||||
|
-e "s/%%%QT_ENVIRONMENT_ID%%%/${qtenvironmentid}/g" \
|
||||||
|
-e "s/%%%QT_DEFAULT_PROFILE_ID%%%/${qtdefaultprofileid}/g" > \
|
||||||
|
"${QTCREATOR_DIR}/$i"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $was_qtcreator_dir -eq 0 ] ; then
|
||||||
|
echo "QTCreator files generated to ${QTCREATOR_DIR} directory"
|
||||||
|
echo "select an 'open project...' option and find a ${QTCREATOR_DIR}/*.creator file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
find ${QTCREATOR_DIR} -name "*.files" | while read projectfiles ; do
|
||||||
|
|
||||||
|
cd ${CURRENT_DIR}/winixd
|
||||||
|
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
find ../winixd -type f \( -iname "*.cpp" -o -iname "*.h" \) | sort > ${projectfiles}
|
||||||
|
echo "file ${projectfiles} has been updated"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd ${CURRENT_DIR}/winixcli
|
||||||
|
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
find ../winixcli -type f \( -iname "*.cpp" -o -iname "*.h" \) | sort >> ${projectfiles}
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
Copyright (c) 2012-2022, Tomasz Sowa
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
@@ -1,155 +1,62 @@
|
|||||||
# Makefile for GNU make
|
|
||||||
|
|
||||||
include Makefile.dep
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CXX
|
|
||||||
# temporarily workaround: forcing using clang (CXX is defined by the OS and is equal to g++)
|
|
||||||
CXX = clang++
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ifndef CXXFLAGS
|
|
||||||
CXXFLAGS = -Wall -O0 -g -fPIC -pthread -std=c++11 -I/usr/local/include -DEZC_USE_WINIX_LOGGER -DEZC_HAS_SPECIAL_STREAM
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
ifndef CXXWINIXINCLUDEFLAGS
|
|
||||||
# these flags are used for compiling and making dependencies (make depend)
|
|
||||||
# it's better to not using any system directories like -I/usr/local/include here
|
|
||||||
CXXWINIXINCLUDEFLAGS = -I../../winix -I../../../winix -I../../ezc/src -I../../../ezc/src -I../../tito/src -I../../../tito/src -I../../pikotools -I../../../pikotools
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifndef LDFLAGS
|
|
||||||
LDFLAGS = -L/usr/local/lib
|
|
||||||
endif
|
|
||||||
|
|
||||||
# this macro is used in ezc's Makefile
|
|
||||||
EZC_USE_WINIX_LOGGER = yes
|
|
||||||
|
|
||||||
|
|
||||||
# for make install
|
|
||||||
winix_install_dir = /usr/local/winix
|
|
||||||
|
|
||||||
|
|
||||||
export CXX
|
export CXX
|
||||||
export CXXFLAGS
|
export CXXFLAGS
|
||||||
export CXXWINIXINCLUDEFLAGS
|
|
||||||
export LDFLAGS
|
export LDFLAGS
|
||||||
export EZC_USE_WINIX_LOGGER
|
|
||||||
|
|
||||||
|
|
||||||
all: winix.so plugins winix
|
all: winixd winixcli
|
||||||
|
|
||||||
|
|
||||||
|
winixd: FORCE
|
||||||
winix.so: $(winix.src.files)
|
$(MAKE) -C winixd
|
||||||
@cd core ; $(MAKE) -e
|
|
||||||
@cd db ; $(MAKE) -e
|
|
||||||
@cd functions ; $(MAKE) -e
|
|
||||||
@cd notify ; $(MAKE) -e
|
|
||||||
@cd templates ; $(MAKE) -e
|
|
||||||
@cd ../ezc/src ; $(MAKE) -e
|
|
||||||
@cd ../tito/src ; $(MAKE) -e
|
|
||||||
@cd ../pikotools ; $(MAKE) -e
|
|
||||||
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a ../tito/src/tito.a ../pikotools/utf8/utf8.a ../pikotools/space/space.a ../pikotools/mainparser/mainparser.a ../pikotools/date/date.a $(LDFLAGS) -lfcgi -lpq -lz -lfetch -lpthread -lcurl -Wl,-no-whole-archive
|
|
||||||
|
|
||||||
|
|
||||||
winix: winix.so $(winix.src.files)
|
winixcli: FORCE
|
||||||
@cd main ; $(MAKE) -e
|
$(MAKE) -C winixcli
|
||||||
$(CXX) -o winix $(CXXFLAGS) $(LDFLAGS) main/*.o winix.so -lfcgi
|
|
||||||
|
|
||||||
|
|
||||||
|
clean: FORCE
|
||||||
|
$(MAKE) -C winixd clean
|
||||||
|
$(MAKE) -C winixcli clean
|
||||||
|
|
||||||
plugins: FORCE
|
|
||||||
@cd plugins/stats ; $(MAKE) -e
|
cleanall: FORCE
|
||||||
@cd plugins/thread ; $(MAKE) -e
|
$(MAKE) -C winixd cleanall
|
||||||
@cd plugins/ticket ; $(MAKE) -e
|
$(MAKE) -C winixcli clean
|
||||||
@cd plugins/gallery ; $(MAKE) -e
|
|
||||||
@cd plugins/group ; $(MAKE) -e
|
|
||||||
@cd plugins/menu ; $(MAKE) -e
|
depend: FORCE
|
||||||
@cd plugins/export ; $(MAKE) -e
|
$(MAKE) -C winixd depend
|
||||||
|
$(MAKE) -C winixcli depend
|
||||||
|
|
||||||
|
|
||||||
|
install: FORCE
|
||||||
|
$(MAKE) -C winixd install
|
||||||
|
#$(MAKE) -C winixcli depend
|
||||||
|
|
||||||
|
|
||||||
|
clangd: FORCE
|
||||||
|
@.templates/install_clangd.sh
|
||||||
|
|
||||||
|
|
||||||
|
clangdall: clangd
|
||||||
|
@$(MAKE) -C ../pikotools clangd
|
||||||
|
@$(MAKE) -C ../morm clangd
|
||||||
|
@$(MAKE) -C ../ezc clangd
|
||||||
|
@$(MAKE) -C ../tito clangd
|
||||||
|
|
||||||
|
|
||||||
|
qtcreator: clangd
|
||||||
|
@.templates/install_qtcreator.sh
|
||||||
|
|
||||||
|
|
||||||
|
qtcreatorall: qtcreator
|
||||||
|
@$(MAKE) -C ../pikotools qtcreator
|
||||||
|
@$(MAKE) -C ../morm qtcreator
|
||||||
|
@$(MAKE) -C ../ezc qtcreator
|
||||||
|
@$(MAKE) -C ../tito qtcreator
|
||||||
|
|
||||||
|
|
||||||
FORCE:
|
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 ../ezc/src ; $(MAKE) -e clean
|
|
||||||
@cd ../tito/src ; $(MAKE) -e clean
|
|
||||||
@cd ../pikotools ; $(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 ../ezc/src ; $(MAKE) -e depend
|
|
||||||
@cd ../tito/src ; $(MAKE) -e depend
|
|
||||||
@cd ../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
|
|
||||||
find -E ../ezc/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
find -E ../tito/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
find -E ../pikotools -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
install: all
|
|
||||||
# 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 "{}" "+"
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,19 +0,0 @@
|
|||||||
include Makefile.o.dep
|
|
||||||
|
|
||||||
|
|
||||||
all: $(o)
|
|
||||||
|
|
||||||
|
|
||||||
%.o: %.cpp
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) $<
|
|
||||||
|
|
||||||
|
|
||||||
depend:
|
|
||||||
makedepend -Y. $(CXXWINIXINCLUDEFLAGS) -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
|
|
||||||
-1081
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
|||||||
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include "acceptbaseparser.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::RemoveWhiteFromEnd(std::string & str)
|
|
||||||
{
|
|
||||||
if( str.empty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
size_t i = str.size() - 1;
|
|
||||||
|
|
||||||
for( ; i!=0 && IsWhite(str[i]) ; --i);
|
|
||||||
|
|
||||||
if( !IsWhite(str[i]) )
|
|
||||||
++i;
|
|
||||||
|
|
||||||
if( i < str.size() )
|
|
||||||
str.erase(i); // erasing until the end of the string
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AcceptBaseParser::ReadParameter()
|
|
||||||
{
|
|
||||||
param.clear();
|
|
||||||
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
while( *text!=0 && *text!=',' && *text!=';' )
|
|
||||||
{
|
|
||||||
param += *text;
|
|
||||||
++text;
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoveWhiteFromEnd(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 = strtod(text, (char**)&text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AcceptBaseParser::SkipParam()
|
|
||||||
{
|
|
||||||
SkipWhite();
|
|
||||||
|
|
||||||
if( *text == ',' )
|
|
||||||
++text;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AcceptBaseParser::Parse(const char * str)
|
|
||||||
{
|
|
||||||
text = str;
|
|
||||||
Init();
|
|
||||||
|
|
||||||
while( *text != 0 )
|
|
||||||
{
|
|
||||||
ReadParameter();
|
|
||||||
ReadQ();
|
|
||||||
SkipParam();
|
|
||||||
Param(param, q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_acceptbaseparser
|
|
||||||
#define headerfile_winix_core_acceptbaseparser
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// sample (you must create your own class derived from this one):
|
|
||||||
// object.Parse(" text/html ; , ; q = 45, application / xhtml+xml ; q = 0.4 , application/xml ; q = 0.9 , */* ; q = 0.8 ");
|
|
||||||
class AcceptBaseParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
void Parse(const char * str);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
virtual void Init() {} ;
|
|
||||||
virtual void Param(const std::string & param, double q) = 0;
|
|
||||||
|
|
||||||
bool IsWhite(int c);
|
|
||||||
void SkipWhite();
|
|
||||||
void RemoveWhiteFromEnd(std::string & str);
|
|
||||||
void ReadParameter();
|
|
||||||
void ReadQ();
|
|
||||||
void SkipParam();
|
|
||||||
|
|
||||||
|
|
||||||
const char * text;
|
|
||||||
std::string param;
|
|
||||||
double q;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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 char * 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void Init()
|
|
||||||
{
|
|
||||||
accept_deflate = false;
|
|
||||||
accept_gzip = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Param(const std::string & param, double q)
|
|
||||||
{
|
|
||||||
if( param=="deflate" && q!=0.0 )
|
|
||||||
{
|
|
||||||
accept_deflate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( param=="gzip" && q!=0.0 )
|
|
||||||
{
|
|
||||||
accept_gzip = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool accept_deflate;
|
|
||||||
bool accept_gzip;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-1738
File diff suppressed because it is too large
Load Diff
-213
@@ -1,213 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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 "config.h"
|
|
||||||
#include "system.h"
|
|
||||||
#include "mounts.h"
|
|
||||||
#include "request.h"
|
|
||||||
#include "synchro.h"
|
|
||||||
#include "sessionmanager.h"
|
|
||||||
#include "db/db.h"
|
|
||||||
#include "functions/functions.h"
|
|
||||||
#include "templates/templates.h"
|
|
||||||
#include "compress.h"
|
|
||||||
#include "postparser.h"
|
|
||||||
#include "cookieparser.h"
|
|
||||||
#include "postmultiparser.h"
|
|
||||||
#include "acceptencodingparser.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class App
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
App();
|
|
||||||
|
|
||||||
bool InitFCGI();
|
|
||||||
bool DropPrivileges();
|
|
||||||
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
|
|
||||||
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;
|
|
||||||
CookieParser cookie_parser;
|
|
||||||
AcceptEncodingParser accept_encoding_parser;
|
|
||||||
Compress compress;
|
|
||||||
FCGX_Request fcgi_request;
|
|
||||||
int fcgi_socket;
|
|
||||||
Synchro synchro;
|
|
||||||
pthread_t signal_thread;
|
|
||||||
std::string url_to_fetch_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;
|
|
||||||
|
|
||||||
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 SetEnv(const char * & env, const char * name);
|
|
||||||
void ReadEnvVariables();
|
|
||||||
void ReadGetPostVars();
|
|
||||||
|
|
||||||
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);
|
|
||||||
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();
|
|
||||||
bool DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool additional_groups);
|
|
||||||
|
|
||||||
static void * SpecialThreadForSignals(void*);
|
|
||||||
void FetchPageOnExit();
|
|
||||||
|
|
||||||
void CreateStaticTree();
|
|
||||||
|
|
||||||
// !! IMPROVE ME
|
|
||||||
// !! move to the session manager?
|
|
||||||
time_t last_sessions_save;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,601 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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()
|
|
||||||
{
|
|
||||||
return (*pchar == '[');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// there are no commentaries in bbcode
|
|
||||||
bool BBCODEParser::IsOpeningCommentaryTagMark()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::SkipCommentaryTagIfExists()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::IsClosingTagMark()
|
|
||||||
{
|
|
||||||
return (*pchar == ']');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::IsClosingXmlSimpleTagMark()
|
|
||||||
{
|
|
||||||
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() )
|
|
||||||
{
|
|
||||||
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
|
|
||||||
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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();
|
|
||||||
virtual bool IsOpeningCommentaryTagMark();
|
|
||||||
virtual bool IsClosingTagMark();
|
|
||||||
virtual bool IsClosingXmlSimpleTagMark();
|
|
||||||
|
|
||||||
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
|
|
||||||
-479
@@ -1,479 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "plugin.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "crypt.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Config::Config()
|
|
||||||
{
|
|
||||||
errors_to_stdout = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//!! czy tu w ogole mozemy uzywac log << ?
|
|
||||||
//!! przeciez jeszcze nie zostal przetworzony plik konfiguracyjny
|
|
||||||
|
|
||||||
|
|
||||||
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::cout << "Config: cant open a config file: " << config_file << std::endl;
|
|
||||||
|
|
||||||
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PT::SpaceParser::syntax_error:
|
|
||||||
if( errors_to_stdout )
|
|
||||||
std::cout << "Config: syntax error, line: " << parser.line << std::endl;
|
|
||||||
|
|
||||||
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.SplitSingle(true);
|
|
||||||
parser.UTF8(true); // config is always read in UTF-8
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
demonize = Bool(L"demonize", true);
|
|
||||||
|
|
||||||
user = AText(L"user");
|
|
||||||
group = AText(L"group");
|
|
||||||
additional_groups = Bool(L"additional_groups", true);
|
|
||||||
|
|
||||||
log_file = AText(L"log_file");
|
|
||||||
log_notify_file = AText(L"log_notify_file");
|
|
||||||
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
|
|
||||||
fcgi_socket = AText(L"fcgi_socket");
|
|
||||||
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
|
|
||||||
fcgi_socket_user = AText(L"fcgi_socket_user");
|
|
||||||
fcgi_socket_group = AText(L"fcgi_socket_group");
|
|
||||||
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_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_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");
|
|
||||||
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
|
||||||
|
|
||||||
http_session_id_name = Text(L"http_session_id_name", L"session_id");
|
|
||||||
db_database = AText(L"db_database");
|
|
||||||
db_user = AText(L"db_user");
|
|
||||||
db_pass = AText(L"db_pass");
|
|
||||||
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", true);
|
|
||||||
use_ssl_redirect_code = Int(L"use_ssl_redirect_code", 303);
|
|
||||||
|
|
||||||
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 = AText(L"session_file");
|
|
||||||
session_max = Size(L"session_max", 1000000);
|
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
utf8 = Bool(L"utf8", true);
|
|
||||||
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", 16);
|
|
||||||
|
|
||||||
account_need_email_verification = Bool(L"account_need_email_verification", true);
|
|
||||||
reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400);
|
|
||||||
|
|
||||||
time_zone_default_id = Size(L"time_zone_default_id", 34);
|
|
||||||
time_zone_max_id = Size(L"time_zone_max_id", 130);
|
|
||||||
|
|
||||||
etc_dir = Text(L"etc_dir", L"");
|
|
||||||
time_zones_file = Text(L"time_zones_file", L"time_zones.conf");
|
|
||||||
|
|
||||||
use_ban_list = Bool(L"use_ban_list", true);
|
|
||||||
ban_list_soft_max_size = Size(L"ban_list_soft_max_size", 50000);
|
|
||||||
ban_list_max_size = Size(L"ban_list_max_size", 51000);
|
|
||||||
ban_level_1_delay = Size(L"ban_level_1_delay", 1800);
|
|
||||||
ban_level_2_delay = Size(L"ban_level_2_delay", 86400);
|
|
||||||
ban_level_3_delay = Size(L"ban_level_3_delay", 604800);
|
|
||||||
|
|
||||||
incorrect_login_min_time_between_get_post = Size(L"incorrect_login_min_time_between_get_post", 2);
|
|
||||||
incorrect_login_captcha_treshold = Size(L"incorrect_login_captcha_treshold", 3);
|
|
||||||
incorrect_login_cannot_login_mode = Int(L"incorrect_login_cannot_login_mode", 0);
|
|
||||||
incorrect_login_cannot_login_treshold = Size(L"incorrect_login_cannot_login_treshold", 20);
|
|
||||||
incorrect_login_cannot_login_delay = Size(L"incorrect_login_cannot_login_delay", 1800);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Config::SetAdditionalVariables()
|
|
||||||
{
|
|
||||||
if( html_filter_orphans_mode_str == L"160" )
|
|
||||||
html_filter_orphans_mode = HTMLFilter::orphan_160space;
|
|
||||||
else
|
|
||||||
html_filter_orphans_mode = HTMLFilter::orphan_nbsp;
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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::string & Config::AText(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return space.AText(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string & Config::AText(const wchar_t * name, const char * def)
|
|
||||||
{
|
|
||||||
return space.AText(name, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string & Config::AText(const std::wstring & name, const char * def)
|
|
||||||
{
|
|
||||||
return space.AText(name, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Config::Int(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return space.Int(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-666
@@ -1,666 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_config
|
|
||||||
#define headerfile_winix_core_config
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "space/spaceparser.h"
|
|
||||||
#include "htmlfilter.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Config
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
// name of the config file
|
|
||||||
// this is the parameter passed to winix programm
|
|
||||||
std::string config_file;
|
|
||||||
|
|
||||||
// start as a demon (in the background)
|
|
||||||
// default: true
|
|
||||||
bool demonize;
|
|
||||||
|
|
||||||
// system user name (to which drop privileges)
|
|
||||||
// used only if winix is started as the root
|
|
||||||
std::string user;
|
|
||||||
|
|
||||||
// system group name (to which drop privileges)
|
|
||||||
// used only if winix is started as the root
|
|
||||||
std::string 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, log file name for notifications (sending emails, etc)
|
|
||||||
std::string log_file, log_notify_file;
|
|
||||||
|
|
||||||
// 1 - minimum
|
|
||||||
// 2 - (default)
|
|
||||||
// 3 - maximum - all logs
|
|
||||||
int log_level;
|
|
||||||
|
|
||||||
// logging to stdout too
|
|
||||||
// only if demonize is 'false'
|
|
||||||
// default: false
|
|
||||||
bool log_stdout;
|
|
||||||
|
|
||||||
// how many requests should be saved in the same time
|
|
||||||
// default: 1
|
|
||||||
int log_request;
|
|
||||||
|
|
||||||
// whether to save each line of the config (use it for debug 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
|
|
||||||
// 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 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 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::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::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;
|
|
||||||
|
|
||||||
// if true then only root can use 'template' function
|
|
||||||
// default: false
|
|
||||||
bool template_only_root_use_template_fun;
|
|
||||||
|
|
||||||
std::string db_database;
|
|
||||||
std::string db_user;
|
|
||||||
std::string db_pass;
|
|
||||||
|
|
||||||
std::wstring http_session_id_name;
|
|
||||||
|
|
||||||
// string used in a place where is a user (or group) selected
|
|
||||||
std::wstring priv_no_user;
|
|
||||||
std::wstring priv_no_group;
|
|
||||||
|
|
||||||
// time in seconds when the user will be automatically logged out (iddle time)
|
|
||||||
int session_max_idle;
|
|
||||||
|
|
||||||
// time in seconds when the user will be automatically logged out (when he selected 'remember me' option)
|
|
||||||
// this time is usually greater than session_max_idle
|
|
||||||
int session_remember_max_idle;
|
|
||||||
|
|
||||||
// this file is used when the program is starting and ending
|
|
||||||
std::string session_file;
|
|
||||||
|
|
||||||
// how many sessions can be (zero turn off this checking)
|
|
||||||
// default: 1000000 (one milion)
|
|
||||||
size_t session_max;
|
|
||||||
|
|
||||||
// allow the html output to be compressed
|
|
||||||
// default: true
|
|
||||||
bool compression;
|
|
||||||
|
|
||||||
// if the output is shorter than this value then it will not be compressed
|
|
||||||
// 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 will be put a space
|
|
||||||
// set zero to turn off
|
|
||||||
size_t html_filter_break_word;
|
|
||||||
|
|
||||||
// when long lines should be broken (a new line character will be inserted)
|
|
||||||
// default: 80
|
|
||||||
// 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;
|
|
||||||
HTMLFilter::OrphanMode html_filter_orphans_mode;
|
|
||||||
|
|
||||||
// the url of a new empty item (if there is not the subject too)
|
|
||||||
std::wstring item_url_empty;
|
|
||||||
|
|
||||||
// maximum length of a file send by post multipart form
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// 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: true
|
|
||||||
bool use_ssl_only_for_logged_users;
|
|
||||||
|
|
||||||
// if current connection is without SSL and should be made through SSL
|
|
||||||
// or if is via SSL and should be done in plain text
|
|
||||||
// then we make a redirect
|
|
||||||
// default: 303
|
|
||||||
int use_ssl_redirect_code;
|
|
||||||
|
|
||||||
// when the HOST_HTTP environment variable is not equal to 'base_url'
|
|
||||||
// (the part 'http://' and the last slash is removed)
|
|
||||||
// the server will redirect into base_url + 'REQUEST_URI'
|
|
||||||
// it's useful when you want to redirect from 'mydomain.tld' into 'www.mydomain.tld' etc.
|
|
||||||
// set this option to false if you have multiple subdomains
|
|
||||||
// default: false
|
|
||||||
bool base_url_redirect;
|
|
||||||
|
|
||||||
// the HTTP code used during the base redirect
|
|
||||||
// default: 301
|
|
||||||
int base_url_redirect_code;
|
|
||||||
|
|
||||||
// the main address of the site (e.g. www.someserver.com)
|
|
||||||
// (without http:// prefix)
|
|
||||||
std::wstring base_url;
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// charset used in templates, locales, logs etc.
|
|
||||||
// default: true (UTF-8)
|
|
||||||
// if false it means 8-bit ASCII
|
|
||||||
bool utf8;
|
|
||||||
|
|
||||||
// how many maximum symlinks can be followed
|
|
||||||
// (symlinks on directories as well)
|
|
||||||
// default: 20
|
|
||||||
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
|
|
||||||
// default: 16 (64 maximum)
|
|
||||||
size_t ezc_out_streams_size;
|
|
||||||
|
|
||||||
// when true then when a user want to create a new account
|
|
||||||
// he has to provide his email and a message will be sent back to him
|
|
||||||
// with a link to activate the account
|
|
||||||
// default: true
|
|
||||||
bool account_need_email_verification;
|
|
||||||
|
|
||||||
// when a user forgot his password we are able to send an email to him
|
|
||||||
// with a link to the page where there is a html form for setting a new password
|
|
||||||
// this option tells how long (in seconds) the link is valid
|
|
||||||
// default: 86400 (24 hours)
|
|
||||||
long reset_password_code_expiration_time;
|
|
||||||
|
|
||||||
// time zone identifier for not logged users
|
|
||||||
// or for newly created accounts
|
|
||||||
// those identifiers you can see in etc/time_zones.conf file
|
|
||||||
// or by using timezone winix function with 'a' parameter (timezone/a) (!!IMPROVE ME NOT IMPLEMENTED YET)
|
|
||||||
// default: 34 (Coordinated Universal Time UTC+00:00)
|
|
||||||
size_t time_zone_default_id;
|
|
||||||
|
|
||||||
// a maximum value of a time zone identifier
|
|
||||||
// time zones with an id greater than this will be skipped
|
|
||||||
// default: 130 (maximum: 1000)
|
|
||||||
size_t time_zone_max_id;
|
|
||||||
|
|
||||||
// a directory in which there are some config files
|
|
||||||
// used mainly when winix starts
|
|
||||||
// default: empty (means not for using)
|
|
||||||
std::wstring etc_dir;
|
|
||||||
|
|
||||||
// a file in etc_dir with time zones info
|
|
||||||
// default: time_zones.conf
|
|
||||||
// this is a Space structure with all time zones
|
|
||||||
// with following format:
|
|
||||||
// "tz_-12:00" ( # the name of a space is also a key to the locale files
|
|
||||||
// tz_offset_str = "-12:00" # a string representing the offset from UTC in a format: [+|-]HH:MM
|
|
||||||
// tz_has_dst = "false" # whether the time zone has daylight saving time (bool)
|
|
||||||
// tz_dst_offset = "" # offset of the daylight saving time
|
|
||||||
// tz_dst_start = "" # when the daylight saving time starts, format: MM:DD HH:MM:SS
|
|
||||||
// tz_dst_end = "") # when the daylight saving time ends, format: MM:DD HH:MM:SS
|
|
||||||
// each time zone is in a seperate space
|
|
||||||
std::wstring time_zones_file;
|
|
||||||
|
|
||||||
// turn on the IP ban mechanizm
|
|
||||||
// we have got three levels of bans (level 1, level 2, and the highest level 3)
|
|
||||||
// default: true
|
|
||||||
bool use_ban_list;
|
|
||||||
|
|
||||||
// the so called 'soft' max size
|
|
||||||
// read below description for explanation
|
|
||||||
// this is introduced to avoid deleting only one record from the ban list
|
|
||||||
// default: 50000
|
|
||||||
size_t ban_list_soft_max_size;
|
|
||||||
|
|
||||||
// this is the 'hard' max size of an IP's ban list
|
|
||||||
// if there are more records than this value
|
|
||||||
// then some of them will be removed (until the size will be ban_list_soft_max_size equal)
|
|
||||||
// this value should be a little larger from ban_list_soft_max_size
|
|
||||||
// default: 51000
|
|
||||||
size_t ban_list_max_size;
|
|
||||||
|
|
||||||
// delay in seconds of the first level ban
|
|
||||||
// default: 1800 (30 minutes)
|
|
||||||
// it means withing the next 30 minutes you see only 'you are banned...' message on your webbrowser
|
|
||||||
size_t ban_level_1_delay;
|
|
||||||
|
|
||||||
// delay in seconds of the second level ban
|
|
||||||
// default: 86400 (24 hours)
|
|
||||||
size_t ban_level_2_delay;
|
|
||||||
|
|
||||||
// delay in seconds of the third level ban
|
|
||||||
// default: 604800 (7 days)
|
|
||||||
size_t ban_level_3_delay;
|
|
||||||
|
|
||||||
// the minimum time in seconds which has to pass between the first GET request
|
|
||||||
// (showing your the login form) and the second POST request (which sends the
|
|
||||||
// login and password to the server)
|
|
||||||
// if the time is shorter then the login attempt is treated as incorrect
|
|
||||||
// (the same as if you provide incorrect user/password)
|
|
||||||
// default: 2
|
|
||||||
size_t incorrect_login_min_time_between_get_post;
|
|
||||||
|
|
||||||
// how many incorrect logins there must have been passed to display a captcha
|
|
||||||
// next to the login form
|
|
||||||
// default: 3
|
|
||||||
size_t incorrect_login_captcha_treshold;
|
|
||||||
|
|
||||||
// the way how we prevent to login if there are too many incorrect login attempts
|
|
||||||
// 0 - 'block logging' - do not show the login form in 'login' winix function
|
|
||||||
// (instead a warning message will be printed)
|
|
||||||
// 1 - add to ban list (warning: people from this IP will not be able to see your site and do anything)
|
|
||||||
// default: 0
|
|
||||||
int incorrect_login_cannot_login_mode;
|
|
||||||
|
|
||||||
// after how many incorrect login attempts we do the incorrect_login_cannot_login_mode action
|
|
||||||
// default: 20
|
|
||||||
size_t incorrect_login_cannot_login_treshold;
|
|
||||||
|
|
||||||
// used when incorrect_login_cannot_login_mode is zero
|
|
||||||
// it is the time which should be passed to allow logging
|
|
||||||
// default: 1800 (30 minutes)
|
|
||||||
// if incorrect_login_cannot_login_mode is one then ban_level_X_delay times
|
|
||||||
// will be taken accordingly
|
|
||||||
size_t incorrect_login_cannot_login_delay;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Config();
|
|
||||||
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
|
|
||||||
|
|
||||||
std::wstring & Text(const wchar_t * name);
|
|
||||||
std::wstring & Text(const wchar_t * name, const wchar_t * def);
|
|
||||||
std::wstring & Text(const std::wstring & name, const wchar_t * def);
|
|
||||||
std::string & AText(const wchar_t * name);
|
|
||||||
std::string & AText(const wchar_t * name, const char * def);
|
|
||||||
std::string & AText(const std::wstring & name, const char * def);
|
|
||||||
|
|
||||||
int Int(const wchar_t *);
|
|
||||||
int Int(const wchar_t * name, int def);
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
PT::SpaceParser parser;
|
|
||||||
std::string default_str;
|
|
||||||
bool errors_to_stdout;
|
|
||||||
|
|
||||||
void ShowError();
|
|
||||||
void AssignValues(bool stdout_is_closed);
|
|
||||||
void SetAdditionalVariables();
|
|
||||||
void CheckPasswd();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_cookieparser
|
|
||||||
#define headerfile_winix_core_cookieparser
|
|
||||||
|
|
||||||
#include <fcgiapp.h>
|
|
||||||
#include "httpsimpleparser.h"
|
|
||||||
#include "requesttypes.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CookieParser : public HttpSimpleParser
|
|
||||||
{
|
|
||||||
|
|
||||||
const char * cookie_string;
|
|
||||||
CookieTab * cookie_tab;
|
|
||||||
std::wstring temp_name, temp_value;
|
|
||||||
bool input_as_utf8;
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
|
|
||||||
virtual int GetChar()
|
|
||||||
{
|
|
||||||
if( !cookie_string || *cookie_string == 0 )
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return (int)(unsigned char)*(cookie_string++);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConvStr(const std::string & src, std::wstring & dst)
|
|
||||||
{
|
|
||||||
if( input_as_utf8 )
|
|
||||||
PT::UTF8ToWide(src, dst);
|
|
||||||
else
|
|
||||||
AssignString(src, dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Parameter(std::string & name, std::string & value)
|
|
||||||
{
|
|
||||||
// Cookie names are case insensitive according to section 3.1 of RFC 2965
|
|
||||||
// (we don't use locale here)
|
|
||||||
ToLower(name);
|
|
||||||
|
|
||||||
ConvStr(name, temp_name);
|
|
||||||
ConvStr(value, temp_value);
|
|
||||||
|
|
||||||
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(temp_name, temp_value) );
|
|
||||||
log << log2 << "Cookie, name: \"" << temp_name << "\", value: \"" << temp_value << "\"";
|
|
||||||
|
|
||||||
if( res.second == false )
|
|
||||||
{
|
|
||||||
res.first->second = temp_value;
|
|
||||||
log << " (overwritten)";
|
|
||||||
}
|
|
||||||
|
|
||||||
log << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
CookieParser()
|
|
||||||
{
|
|
||||||
input_as_utf8 = false;
|
|
||||||
HttpSimpleParser::separator = ';';
|
|
||||||
HttpSimpleParser::value_can_be_quoted = true;
|
|
||||||
HttpSimpleParser::skip_white_chars = true;
|
|
||||||
HttpSimpleParser::recognize_special_chars = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UTF8(bool utf)
|
|
||||||
{
|
|
||||||
input_as_utf8 = utf;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cookie_string can be null
|
|
||||||
void Parse(const char * cookie_string_, CookieTab & cookie_tab_)
|
|
||||||
{
|
|
||||||
cookie_string = cookie_string_;
|
|
||||||
cookie_tab = &cookie_tab_;
|
|
||||||
|
|
||||||
HttpSimpleParser::Parse();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_cur
|
|
||||||
#define headerfile_winix_core_cur
|
|
||||||
|
|
||||||
#include "request.h"
|
|
||||||
#include "session.h"
|
|
||||||
#include "mount.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
current request and session
|
|
||||||
*/
|
|
||||||
struct Cur
|
|
||||||
{
|
|
||||||
Request * request;
|
|
||||||
Session * session;
|
|
||||||
Mount * mount;
|
|
||||||
|
|
||||||
// those pointers are never null, if there is no a session for the user
|
|
||||||
// the 'session' pointer pointers at a special temporary session
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_group
|
|
||||||
#define headerfile_winix_core_group
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Group
|
|
||||||
{
|
|
||||||
long id;
|
|
||||||
std::wstring name; // group name
|
|
||||||
std::vector<long> members; // users id
|
|
||||||
|
|
||||||
Group()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
id = -1;
|
|
||||||
name.clear();
|
|
||||||
members.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-101
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "groups.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Groups::Groups()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Groups::Clear()
|
|
||||||
{
|
|
||||||
table.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Groups::ReadGroups(Db * db)
|
|
||||||
{
|
|
||||||
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::wstring & name)
|
|
||||||
{
|
|
||||||
Table::Iterator i = table.FindName(name);
|
|
||||||
|
|
||||||
if( i == table.End() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return &(*i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long Groups::GetGroupId(const std::wstring & 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Groups::Remove(long group_id)
|
|
||||||
{
|
|
||||||
return table.Remove(group_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_groups
|
|
||||||
#define headerfile_winix_core_groups
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "group.h"
|
|
||||||
#include "ugcontainer.h"
|
|
||||||
#include "db/db.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Groups
|
|
||||||
{
|
|
||||||
typedef UGContainer<Group> Table;
|
|
||||||
|
|
||||||
Table table;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef Table::Iterator Iterator;
|
|
||||||
typedef Table::SizeType SizeType;
|
|
||||||
|
|
||||||
Groups();
|
|
||||||
void Clear();
|
|
||||||
void ReadGroups(Db * db);
|
|
||||||
Group * GetGroup(long group_id);
|
|
||||||
Group * GetGroup(const std::wstring & name);
|
|
||||||
long GetGroupId(const std::wstring & name);
|
|
||||||
Iterator Begin();
|
|
||||||
Iterator End();
|
|
||||||
SizeType Size();
|
|
||||||
bool Remove(long group_id);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-1406
File diff suppressed because it is too large
Load Diff
@@ -1,306 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_htmlfilter
|
|
||||||
#define headerfile_winix_core_htmlfilter
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// max length of a name of a html tag (with terminating null)
|
|
||||||
#define WINIX_HTMLFILTER_ITEM_NAME_MAXLEN 30
|
|
||||||
|
|
||||||
// max length of a html lang attribute (e.g. "en", "pl")
|
|
||||||
#define WINIX_HTMLFILTER_ITEM_LANG_MAXLEN 10
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_HTMLFILTER_ATTR_NAME_MAXLEN 40
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_HTMLFILTER_ATTR_VALUE_MAXLEN 500
|
|
||||||
|
|
||||||
|
|
||||||
// depth of the html tree
|
|
||||||
#define WINIX_HTMLFILTER_STACK_MAXLEN 100
|
|
||||||
|
|
||||||
// length of a buffer used for printing
|
|
||||||
// it should be at least: WINIX_HTMLFILTER_ITEM_NAME_MAXLEN+3
|
|
||||||
#define WINIX_HTMLFILTER_BUFFER_MAXLEN 2048
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
very lightweight filter for html
|
|
||||||
(without using any dynamic memory - some memory is allocated only at the beginning - in ctors)
|
|
||||||
this filter has O(n) complexity over the whole html string
|
|
||||||
|
|
||||||
such tags as: <script> <pre> <textarea> are treated in a special way
|
|
||||||
all characters between the opening and closing tag (<script>....</script>) are untouched
|
|
||||||
|
|
||||||
if the filter finds that there are not closed tags it will close them,
|
|
||||||
if the filter finds a closing tag which doesn't have an opening tag - it will skip it
|
|
||||||
|
|
||||||
tags which don't need to be closed: meta, input, br, img, link
|
|
||||||
look at CheckExceptions() method
|
|
||||||
|
|
||||||
the filter recognizes xml simple tags (with / at the end) such as: <br />
|
|
||||||
*/
|
|
||||||
class HTMLFilter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum OrphanMode
|
|
||||||
{
|
|
||||||
orphan_nbsp, // putting " " string
|
|
||||||
orphan_160space // putting 160 ascii code
|
|
||||||
};
|
|
||||||
|
|
||||||
HTMLFilter();
|
|
||||||
HTMLFilter(const HTMLFilter & f);
|
|
||||||
HTMLFilter & operator=(const HTMLFilter & f);
|
|
||||||
~HTMLFilter();
|
|
||||||
|
|
||||||
|
|
||||||
// main methods used for filtering
|
|
||||||
void Filter(const wchar_t * in, std::wstring & out);
|
|
||||||
void Filter(const std::wstring & in, std::wstring & out);
|
|
||||||
|
|
||||||
|
|
||||||
// insert a white space into long words
|
|
||||||
// (only between html tags)
|
|
||||||
// skipped in such tags: script, pre, textarea
|
|
||||||
// break_after - after how many characters insert a space (0 - off)
|
|
||||||
void BreakWord(size_t break_after_);
|
|
||||||
|
|
||||||
// insert a new line character into long lines
|
|
||||||
// (only between html tags)
|
|
||||||
// skipped in such tags: script, pre, textarea
|
|
||||||
// wrap_line - after how many characters wrap a line (0 - off)
|
|
||||||
// lines are wrapped only in 'body' tag (useful for text in 'title' tag which is in 'head' section)
|
|
||||||
void WrapLine(size_t wrap_line_);
|
|
||||||
|
|
||||||
// trimming white characters (with new lines)
|
|
||||||
// at the beginning, at the end and in the middle of a string
|
|
||||||
// only between html tags
|
|
||||||
// at the beginning and at the end only one space is left
|
|
||||||
// skipped in such tags: script, pre, textarea
|
|
||||||
// false by default
|
|
||||||
void TrimWhite(bool trim);
|
|
||||||
|
|
||||||
|
|
||||||
// first tabs in a tree
|
|
||||||
// default: 2 (spaces)
|
|
||||||
// set 0 to turn off
|
|
||||||
void InsertTabs(size_t tabsize);
|
|
||||||
|
|
||||||
|
|
||||||
// orphans are checked only in 'body' tag
|
|
||||||
void AssignOrphans(const wchar_t * lang_code, const std::vector<std::wstring> & otab);
|
|
||||||
void AssignOrphans(const std::wstring & lang_code, const std::vector<std::wstring> & otab);
|
|
||||||
void ClearOrphans();
|
|
||||||
|
|
||||||
|
|
||||||
// check 'orphans' for the specicic language
|
|
||||||
// if an orphan is detected then the non-break space (" " or ascii 160 code) will be put
|
|
||||||
// default disable (lang_none)
|
|
||||||
void OrphansMode(OrphanMode mode = orphan_nbsp);
|
|
||||||
|
|
||||||
|
|
||||||
// skipping some unsafe tags
|
|
||||||
// (script, iframe, frame, frameset, applet, head, meta, html, link, body, ...)
|
|
||||||
void SafeMode(bool safe_mode_);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// orphans for one language
|
|
||||||
struct Orphans
|
|
||||||
{
|
|
||||||
std::vector<std::wstring> tab;
|
|
||||||
size_t max_len;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// orphans for all languages
|
|
||||||
// map<language_code, Orphans>
|
|
||||||
typedef std::map<std::wstring, Orphans> OrphansTab;
|
|
||||||
OrphansTab orphans_tab;
|
|
||||||
|
|
||||||
|
|
||||||
struct Item
|
|
||||||
{
|
|
||||||
std::wstring name; // max size: WINIX_HTMLFILTER_ITEM_NAME_MAXLEN
|
|
||||||
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
opening, /* sample: <h1> */
|
|
||||||
closing, /* sample: </h1> */
|
|
||||||
simple, /* sample: <br/> */
|
|
||||||
special, /* sample: <!doctype> */
|
|
||||||
none
|
|
||||||
} type;
|
|
||||||
|
|
||||||
// is there a new line after this tag
|
|
||||||
bool new_line;
|
|
||||||
|
|
||||||
// current orphans table
|
|
||||||
// (will be propagated)
|
|
||||||
Orphans * porphans;
|
|
||||||
|
|
||||||
// this item or one from its parents is a 'body' html tag
|
|
||||||
// (will be propagated)
|
|
||||||
bool has_body_tag;
|
|
||||||
|
|
||||||
void Clear();
|
|
||||||
Item();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
virtual methods
|
|
||||||
*/
|
|
||||||
virtual void Init();
|
|
||||||
virtual void Uninit();
|
|
||||||
|
|
||||||
virtual bool IsOpeningTagMark();
|
|
||||||
virtual bool IsOpeningCommentaryTagMark();
|
|
||||||
virtual bool IsClosingTagMark();
|
|
||||||
virtual bool IsClosingXmlSimpleTagMark();
|
|
||||||
|
|
||||||
virtual bool IsValidCharForName(int c);
|
|
||||||
virtual bool IsValidCharForAttrName(int c);
|
|
||||||
virtual void CheckExceptions();
|
|
||||||
virtual bool SkipCommentaryTagIfExists();
|
|
||||||
|
|
||||||
virtual void Put(wchar_t c);
|
|
||||||
virtual void Put(const wchar_t * str);
|
|
||||||
virtual void Put(const wchar_t * str, const wchar_t * end);
|
|
||||||
virtual void Put(const std::wstring & str);
|
|
||||||
|
|
||||||
virtual void PutOpeningTagMark();
|
|
||||||
virtual void PutClosingTagMark();
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
Item & GetItem(size_t i);
|
|
||||||
Item & LastItem();
|
|
||||||
|
|
||||||
wchar_t ToLower(wchar_t c);
|
|
||||||
void ToLower(std::wstring & str);
|
|
||||||
|
|
||||||
bool IsNameEqual(const wchar_t * name1, const wchar_t * name2);
|
|
||||||
bool IsNameEqual(const wchar_t * name1, const std::wstring & name2);
|
|
||||||
bool IsNameEqual(const std::wstring & name1, const wchar_t * name2);
|
|
||||||
bool IsNameEqual(const std::wstring & name1, const std::wstring & name2);
|
|
||||||
|
|
||||||
bool IsNameEqual(const wchar_t * name1, const wchar_t * name2, size_t len);
|
|
||||||
bool IsNameEqual(const wchar_t * name1, const std::wstring & name2, size_t len);
|
|
||||||
bool IsNameEqual(const std::wstring & name1, const wchar_t * name2, size_t len);
|
|
||||||
bool IsNameEqual(const std::wstring & name1, const std::wstring & name2, size_t len);
|
|
||||||
|
|
||||||
bool IsLastTag(const wchar_t * name);
|
|
||||||
bool IsTagSafe(const wchar_t * tag);
|
|
||||||
bool IsTagSafe(const std::wstring & tag);
|
|
||||||
|
|
||||||
int CheckOrphan(const wchar_t * str, const wchar_t * end, const std::wstring & orphan_str);
|
|
||||||
bool CheckOrphan(const wchar_t * str, const wchar_t * end, const std::vector<std::wstring> & orphans);
|
|
||||||
bool CheckOrphan(const wchar_t * str, const wchar_t * end);
|
|
||||||
|
|
||||||
bool IsWhite(int c);
|
|
||||||
void SkipWhite();
|
|
||||||
void SkipWhiteLines();
|
|
||||||
void SkipWhiteWithFirstNewLine();
|
|
||||||
void SkipWhiteLines(const wchar_t * & str, const wchar_t * end);
|
|
||||||
bool IsClosingTagForLastItem();
|
|
||||||
size_t OpeningCommentaryTagMarkSize();
|
|
||||||
void SkipAndCheckClosingTag();
|
|
||||||
|
|
||||||
void PopStack();
|
|
||||||
bool PushStack();
|
|
||||||
void CheckNewLine();
|
|
||||||
void CheckStackPrintRest();
|
|
||||||
void AddForgottenTags();
|
|
||||||
void CheckClosingTags();
|
|
||||||
void ReadNormalText();
|
|
||||||
bool PrintRest();
|
|
||||||
bool PrintOpeningItem();
|
|
||||||
void ReadItemName();
|
|
||||||
void ReadItemAttrName();
|
|
||||||
void ReadItemAttrValue(bool has_quote);
|
|
||||||
|
|
||||||
bool ReadItemAttr();
|
|
||||||
bool CheckItemAttr();
|
|
||||||
void PrinItemAttr();
|
|
||||||
|
|
||||||
void ReadItemClosing();
|
|
||||||
void ReadItemSpecial();
|
|
||||||
void ReadItemOpening();
|
|
||||||
bool ReadItem();
|
|
||||||
void ReadLoop();
|
|
||||||
void Read();
|
|
||||||
|
|
||||||
void CheckChar(wchar_t c);
|
|
||||||
|
|
||||||
void CheckLineWrap();
|
|
||||||
bool HasSemiloconAround(const wchar_t * str, const wchar_t * end);
|
|
||||||
void PutNormalNonWhite(const wchar_t * & str, const wchar_t * end);
|
|
||||||
void PutNormalWhite(const wchar_t * & str, const wchar_t * end);
|
|
||||||
void PutLastTagWithClosingTag();
|
|
||||||
void PutTabs(size_t len);
|
|
||||||
void PutNonBreakingSpace();
|
|
||||||
void PutNewLine();
|
|
||||||
void CalcOrphansMaxLen(Orphans & orphans);
|
|
||||||
|
|
||||||
const wchar_t * pchar;
|
|
||||||
Item empty;
|
|
||||||
Item * pstack; // stack pointer
|
|
||||||
size_t stack_len; // length of the stack
|
|
||||||
wchar_t * buffer; // buffer used when printing
|
|
||||||
std::wstring * out_string;
|
|
||||||
bool last_new_line;
|
|
||||||
size_t break_after; // insert a space into long words after 'break_after' characters
|
|
||||||
size_t wrap_line; // insert a new line character into long lines
|
|
||||||
bool trim_white; // trimming white characters
|
|
||||||
size_t tab_size;
|
|
||||||
OrphanMode orphan_mode;
|
|
||||||
std::wstring attr_name;
|
|
||||||
std::wstring attr_value;
|
|
||||||
std::wstring attr_value_lower;
|
|
||||||
bool attr_has_value;
|
|
||||||
std::wstring lang_code_lower;
|
|
||||||
size_t line_len; //length of the current line (without first spaces which create the html tree)
|
|
||||||
bool safe_mode; // skipping some unsafe tags
|
|
||||||
Orphans orphans_temp;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "httpsimpleparser.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_httpsimpleparser
|
|
||||||
#define headerfile_winix_core_httpsimpleparser
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
void Parse();
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
HttpSimpleParser()
|
|
||||||
{
|
|
||||||
separator = '&';
|
|
||||||
read_name = true;
|
|
||||||
value_can_be_quoted = false;
|
|
||||||
skip_white_chars = false;
|
|
||||||
recognize_special_chars = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_ipbancontainer
|
|
||||||
#define headerfile_winix_core_ipbancontainer
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "ipban.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IPBanContainer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
IPBanContainer();
|
|
||||||
|
|
||||||
IPBan & AddIP(int ip);
|
|
||||||
IPBan * FindIP(int ip);
|
|
||||||
void Sort();
|
|
||||||
size_t Size();
|
|
||||||
IPBan & GetIPBan(size_t index);
|
|
||||||
void SetMaxSize(size_t soft_size, size_t size);
|
|
||||||
void RemoveIP(int ip);
|
|
||||||
void Clear();
|
|
||||||
bool IsSorted();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::vector<IPBan> ipban_tab;
|
|
||||||
bool is_ipban_tab_sorted;
|
|
||||||
size_t soft_max_size, max_size;
|
|
||||||
std::vector<size_t> sort_helper_tab;
|
|
||||||
|
|
||||||
static bool SortIPBansFunction(const IPBan & ip1, const IPBan & ip2);
|
|
||||||
void RemoveOldRecords();
|
|
||||||
void PrintTab();
|
|
||||||
void PrintTab2();
|
|
||||||
|
|
||||||
struct SortByLastUsedHelper
|
|
||||||
{
|
|
||||||
IPBanContainer * container;
|
|
||||||
|
|
||||||
SortByLastUsedHelper(IPBanContainer * c) : container(c) {}
|
|
||||||
bool operator()(size_t index1, size_t index2);
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "item.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "crypt.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Item::Item()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// !! IMPROVE ME
|
|
||||||
// now we have Request::start_time and Request::start_date
|
|
||||||
// we can somehow get the current time from the request
|
|
||||||
// may setting the date should be completetly removed from here?
|
|
||||||
void Item::SetDateToNow()
|
|
||||||
{
|
|
||||||
date_creation = std::time(0);
|
|
||||||
date_modification = date_creation;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Item::SetDateModifyToNow()
|
|
||||||
{
|
|
||||||
date_modification = std::time(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Item::Clear()
|
|
||||||
{
|
|
||||||
id = -1;
|
|
||||||
|
|
||||||
user_id = -1;
|
|
||||||
group_id = -1;
|
|
||||||
privileges = 0;
|
|
||||||
modification_user_id = -1;
|
|
||||||
|
|
||||||
guest_name.clear();
|
|
||||||
|
|
||||||
subject.clear();
|
|
||||||
content.clear();
|
|
||||||
modify_index = 0;
|
|
||||||
url.clear();
|
|
||||||
|
|
||||||
content_type = ct_formatted_text;
|
|
||||||
|
|
||||||
type = none;
|
|
||||||
parent_id = -1;
|
|
||||||
|
|
||||||
link_to.clear();
|
|
||||||
link_redirect = false;
|
|
||||||
|
|
||||||
content_id = -1;
|
|
||||||
ref = 1;
|
|
||||||
|
|
||||||
file_path.clear();
|
|
||||||
file_fs = -1;
|
|
||||||
file_type = WINIX_ITEM_FILETYPE_NONE;
|
|
||||||
hash.clear();
|
|
||||||
hash_type = WINIX_CRYPT_HASH_NONE;
|
|
||||||
file_size = 0;
|
|
||||||
has_thumb = false;
|
|
||||||
|
|
||||||
html_template.clear();
|
|
||||||
sort_index = 0;
|
|
||||||
meta.Clear();
|
|
||||||
ameta.Clear();
|
|
||||||
|
|
||||||
SetDateToNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
-128
@@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_item
|
|
||||||
#define headerfile_winix_core_item
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "space/space.h"
|
|
||||||
#include "date/date.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_ITEM_FILETYPE_NONE 0
|
|
||||||
#define WINIX_ITEM_FILETYPE_IMAGE 1
|
|
||||||
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
|
|
||||||
#define WINIX_ITEM_FILETYPE_VIDEO 3
|
|
||||||
#define WINIX_ITEM_FILETYPE_UNKNOWN 10
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Item
|
|
||||||
{
|
|
||||||
long id;
|
|
||||||
long parent_id;
|
|
||||||
|
|
||||||
|
|
||||||
long user_id;
|
|
||||||
long group_id;
|
|
||||||
std::wstring guest_name; // used as a user name when user_id is equal -1
|
|
||||||
|
|
||||||
long modification_user_id; // who has modified the item last (not taken into account when checking permissions)
|
|
||||||
|
|
||||||
int privileges;
|
|
||||||
|
|
||||||
PT::Date date_creation;
|
|
||||||
PT::Date date_modification;
|
|
||||||
|
|
||||||
std::wstring subject;
|
|
||||||
std::wstring content;
|
|
||||||
|
|
||||||
std::wstring url;
|
|
||||||
int modify_index;
|
|
||||||
|
|
||||||
enum ContentType
|
|
||||||
{
|
|
||||||
ct_text = 0,
|
|
||||||
ct_formatted_text,
|
|
||||||
ct_html,
|
|
||||||
ct_bbcode,
|
|
||||||
ct_raw
|
|
||||||
};
|
|
||||||
|
|
||||||
ContentType content_type;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
dir = 0,
|
|
||||||
file = 1,
|
|
||||||
symlink = 2,
|
|
||||||
|
|
||||||
none = 1000
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
|
|
||||||
// used when type is symlink or to a directory too (function 'default')
|
|
||||||
std::wstring link_to;
|
|
||||||
int link_redirect; // !! IMPROVE ME should it be 'bool'?
|
|
||||||
|
|
||||||
|
|
||||||
// static file (if exists)
|
|
||||||
std::wstring file_path; // relative file path
|
|
||||||
int file_fs; // file system type where the file was saved
|
|
||||||
int file_type; // file type (none, image, doc, etc)
|
|
||||||
bool has_thumb; // whether or not we have a thumbnail
|
|
||||||
std::wstring hash; // file hash (md4, md5, ...)
|
|
||||||
int hash_type; // hash type WINIX_CRYPT_HASH_* (see crypt.h)
|
|
||||||
size_t file_size; // size of the file
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring html_template;
|
|
||||||
|
|
||||||
|
|
||||||
// sort index used when displaying a group of items
|
|
||||||
int sort_index;
|
|
||||||
|
|
||||||
|
|
||||||
// meta information
|
|
||||||
PT::Space meta;
|
|
||||||
PT::Space ameta;
|
|
||||||
|
|
||||||
|
|
||||||
// methods
|
|
||||||
Item();
|
|
||||||
void SetDateToNow();
|
|
||||||
void SetDateModifyToNow();
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
// used by the database
|
|
||||||
long content_id; // content id in 'content' table
|
|
||||||
int ref; // content references
|
|
||||||
|
|
||||||
friend class Db;
|
|
||||||
friend struct DbItemColumns;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-173
@@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "job.h"
|
|
||||||
#include "plugin.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Job::Job()
|
|
||||||
{
|
|
||||||
jobs_queue_tab.resize(WINIX_JOBS_HOW_MANY_PRIORITIES);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Job::CheckPriority(int & priority) const
|
|
||||||
{
|
|
||||||
if( priority < 0 )
|
|
||||||
priority = 0;
|
|
||||||
|
|
||||||
if( priority >= WINIX_JOBS_HOW_MANY_PRIORITIES )
|
|
||||||
priority = WINIX_JOBS_HOW_MANY_PRIORITIES - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// first thread (objects locked)
|
|
||||||
void Job::Add(PT::Space & job, int priority)
|
|
||||||
{
|
|
||||||
CheckPriority(priority);
|
|
||||||
jobs_queue_tab[priority].push(job);
|
|
||||||
WakeUpThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Job::Size(int priority) const
|
|
||||||
{
|
|
||||||
CheckPriority(priority);
|
|
||||||
return jobs_queue_tab[priority].size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Job::Size() const
|
|
||||||
{
|
|
||||||
size_t sum = 0;
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<WINIX_JOBS_HOW_MANY_PRIORITIES ; ++i)
|
|
||||||
sum += Size(i);
|
|
||||||
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Job::Empty(int priority) const
|
|
||||||
{
|
|
||||||
CheckPriority(priority);
|
|
||||||
return jobs_queue_tab[priority].empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Job::Empty() const
|
|
||||||
{
|
|
||||||
for(size_t i=0 ; i<WINIX_JOBS_HOW_MANY_PRIORITIES ; ++i)
|
|
||||||
if( !Empty(i) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
second thread
|
|
||||||
*/
|
|
||||||
|
|
||||||
// second thread (objects locked)
|
|
||||||
bool Job::SignalReceived()
|
|
||||||
{
|
|
||||||
return !Empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked)
|
|
||||||
void Job::Do()
|
|
||||||
{
|
|
||||||
size_t i = WINIX_JOBS_HOW_MANY_PRIORITIES;
|
|
||||||
bool is_empty;
|
|
||||||
|
|
||||||
while( i-- > 0 && !IsExitSignal() )
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Lock();
|
|
||||||
is_empty = Empty(i);
|
|
||||||
Unlock();
|
|
||||||
|
|
||||||
if( !is_empty )
|
|
||||||
DoQueue(jobs_queue_tab[i]);
|
|
||||||
}
|
|
||||||
while( !is_empty && !IsExitSignal() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked, jobs_queue is not empty)
|
|
||||||
void Job::DoQueue(JobsQueue & jobs_queue)
|
|
||||||
{
|
|
||||||
bool is_empty;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Lock();
|
|
||||||
// references will not be invalidated after insertion to jobs_queue
|
|
||||||
// (jobs_queue is std::queue and it uses std::deque by default)
|
|
||||||
PT::Space & job = jobs_queue.front();
|
|
||||||
Unlock();
|
|
||||||
|
|
||||||
DoJob(job);
|
|
||||||
|
|
||||||
Lock();
|
|
||||||
jobs_queue.pop();
|
|
||||||
is_empty = jobs_queue.empty();
|
|
||||||
Unlock();
|
|
||||||
}
|
|
||||||
while( !is_empty && !IsExitSignal() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked)
|
|
||||||
void Job::DoJob(PT::Space & job)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PluginRes res = plugin.Call((Session*)0, WINIX_JOB, &job);
|
|
||||||
|
|
||||||
if( res.res_true == 0 )
|
|
||||||
DoWinixJob(job);
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked)
|
|
||||||
void Job::DoWinixJob(PT::Space & job)
|
|
||||||
{
|
|
||||||
Lock();
|
|
||||||
//log << log1 << "standard winix job: " << job.Text(L"type") << logend;
|
|
||||||
Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-90
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_jobs
|
|
||||||
#define headerfile_winix_core_jobs
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <queue>
|
|
||||||
#include "basethread.h"
|
|
||||||
#include "space/space.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_JOBS_HOW_MANY_PRIORITIES 32
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Job : public BaseThread
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
Job();
|
|
||||||
|
|
||||||
/*
|
|
||||||
add a new job to the queue
|
|
||||||
priority: 0-31 (0 - the lowest priority, 31 - the highest priority)
|
|
||||||
*/
|
|
||||||
void Add(PT::Space & job, int priority = 0);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
queue size, and size of all jobs in any priority
|
|
||||||
*/
|
|
||||||
size_t Size(int priority) const;
|
|
||||||
size_t Size() const;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
true if specified queue is empty
|
|
||||||
or if all queues are empty
|
|
||||||
*/
|
|
||||||
bool Empty(int priority) const;
|
|
||||||
bool Empty() const;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
typedef std::queue<PT::Space> JobsQueue;
|
|
||||||
typedef std::vector<JobsQueue> JobsQueueTab;
|
|
||||||
JobsQueueTab jobs_queue_tab;
|
|
||||||
|
|
||||||
void CheckPriority(int & priority) const;
|
|
||||||
void SaveToFile();
|
|
||||||
void ReadFromFile();
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
second thread
|
|
||||||
*/
|
|
||||||
|
|
||||||
// standard winix jobs
|
|
||||||
// Image image;
|
|
||||||
// sending emails
|
|
||||||
// etc.
|
|
||||||
|
|
||||||
bool SignalReceived();
|
|
||||||
void Do();
|
|
||||||
void DoQueue(JobsQueue & jobs_queue);
|
|
||||||
void DoJob(PT::Space & job);
|
|
||||||
void DoWinixJob(PT::Space & job);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2009-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_lastcontainer
|
|
||||||
#define headerfile_winix_core_lastcontainer
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
#include <cstring>
|
|
||||||
#include <ctime>
|
|
||||||
#include "date/date.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// how many items we store in the 'last' function
|
|
||||||
#define WINIX_LASTCONTAINER_TABLE_SIZE 100
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct LastItem
|
|
||||||
{
|
|
||||||
long user_id;
|
|
||||||
|
|
||||||
// additional we store the whole string-name
|
|
||||||
// (you can delete a user from the database but we can still print the name)
|
|
||||||
std::wstring name;
|
|
||||||
|
|
||||||
// ip address
|
|
||||||
unsigned int ip;
|
|
||||||
|
|
||||||
// session id (used when logging out)
|
|
||||||
long session_id;
|
|
||||||
|
|
||||||
// start logging and end logging
|
|
||||||
PT::Date start;
|
|
||||||
PT::Date end;
|
|
||||||
|
|
||||||
|
|
||||||
LastItem();
|
|
||||||
bool IsLoggedOut();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LastContainer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef std::list<LastItem> LastTab;
|
|
||||||
typedef LastTab::iterator Iterator;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Iterator Begin();
|
|
||||||
Iterator End();
|
|
||||||
void UserLogin(long user_id, const std::wstring & name, unsigned int ip, long session_id);
|
|
||||||
void UserLogout(long user_id, long session_id);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
LastTab last_tab;
|
|
||||||
Iterator FindNotLoggedOut(long user_id, long session_id);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-121
@@ -1,121 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_loadavg
|
|
||||||
#define headerfile_winix_core_loadavg
|
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// in seconds
|
|
||||||
#define WINIX_LOADAVG_GRANULARITY1 2
|
|
||||||
#define WINIX_LOADAVG_GRANULARITY5 15
|
|
||||||
#define WINIX_LOADAVG_GRANULARITY15 45
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LoadAvg
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LoadAvg();
|
|
||||||
~LoadAvg();
|
|
||||||
LoadAvg & operator=(const LoadAvg & l);
|
|
||||||
LoadAvg(const LoadAvg & l);
|
|
||||||
|
|
||||||
void StartRequest();
|
|
||||||
void StopRequest();
|
|
||||||
|
|
||||||
double LoadAvgNow(); // load average withing last WINIX_LOADAVG_GRANULARITY1 seconds
|
|
||||||
double LoadAvg1();
|
|
||||||
double LoadAvg5();
|
|
||||||
double LoadAvg15();
|
|
||||||
|
|
||||||
double ReqPerSecNow();
|
|
||||||
double ReqPerSec1();
|
|
||||||
double ReqPerSec5();
|
|
||||||
double ReqPerSec15();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
struct Times
|
|
||||||
{
|
|
||||||
double dr; // time for the request (in seconds)
|
|
||||||
double dp; // time for the pause between requestes (in seconds)
|
|
||||||
long req; // how many requests
|
|
||||||
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
dr = 0.0;
|
|
||||||
dp = 0.0;
|
|
||||||
req = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Times & operator=(const Times & t)
|
|
||||||
{
|
|
||||||
dr = t.dr;
|
|
||||||
dp = t.dp;
|
|
||||||
req = t.req;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void CheckTimers();
|
|
||||||
void UpdateTimer1();
|
|
||||||
void UpdateTimer5();
|
|
||||||
void UpdateTimer15();
|
|
||||||
|
|
||||||
Times current1;
|
|
||||||
Times current5;
|
|
||||||
Times current15;
|
|
||||||
|
|
||||||
void CreateTable(size_t seconds, size_t granulatiry, Times* & tab, size_t & len);
|
|
||||||
void CreateTable();
|
|
||||||
|
|
||||||
void MoveTab(Times * tab, size_t len);
|
|
||||||
void SumTab(Times * tab, size_t len, double expected, Times & t);
|
|
||||||
|
|
||||||
void Calculate1();
|
|
||||||
void Calculate5();
|
|
||||||
void Calculate15();
|
|
||||||
|
|
||||||
bool was_stop_request;
|
|
||||||
timespec start_req, stop_req;
|
|
||||||
|
|
||||||
Times * tab1;
|
|
||||||
size_t len1;
|
|
||||||
|
|
||||||
Times * tab5;
|
|
||||||
size_t len5;
|
|
||||||
|
|
||||||
Times * tab15;
|
|
||||||
size_t len15;
|
|
||||||
|
|
||||||
double cache_load1;
|
|
||||||
double cache_load5;
|
|
||||||
double cache_load15;
|
|
||||||
|
|
||||||
double cache_req_per_sec1;
|
|
||||||
double cache_req_per_sec5;
|
|
||||||
double cache_req_per_sec15;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "lock.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Lock::Lock()
|
|
||||||
{
|
|
||||||
synchro = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Lock::Lock(Synchro * synchro_)
|
|
||||||
{
|
|
||||||
synchro = synchro_;
|
|
||||||
synchro->Lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Lock::Lock(Synchro & synchro_)
|
|
||||||
{
|
|
||||||
synchro = &synchro_;
|
|
||||||
synchro->Lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Lock::~Lock()
|
|
||||||
{
|
|
||||||
Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Lock::Unlock()
|
|
||||||
{
|
|
||||||
if( synchro )
|
|
||||||
{
|
|
||||||
synchro->Unlock();
|
|
||||||
synchro = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_lock
|
|
||||||
#define headerfile_winix_core_lock
|
|
||||||
|
|
||||||
#include "synchro.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Lock
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
Lock(Synchro * synchro_);
|
|
||||||
Lock(Synchro & synchro_);
|
|
||||||
|
|
||||||
~Lock();
|
|
||||||
|
|
||||||
void Unlock();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Synchro * synchro;
|
|
||||||
|
|
||||||
Lock();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-462
@@ -1,462 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "log.h"
|
|
||||||
#include <ctime>
|
|
||||||
#include <string.h>
|
|
||||||
#include "utf8/utf8.h"
|
|
||||||
#include "timezones.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log::Log()
|
|
||||||
{
|
|
||||||
log_level = 1;
|
|
||||||
current_level = 100; // nothing to log (call Init() first)
|
|
||||||
request = 0;
|
|
||||||
max_requests = 1;
|
|
||||||
lines = 0;
|
|
||||||
max_lines = 5000;
|
|
||||||
log_file_open = false;
|
|
||||||
time_zones = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Log::~Log()
|
|
||||||
{
|
|
||||||
SaveLogAndClear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Log::SetTimeZones(TimeZones * ptime_zones)
|
|
||||||
{
|
|
||||||
time_zones = ptime_zones;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Log::LogLevel()
|
|
||||||
{
|
|
||||||
return log_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Log::Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests)
|
|
||||||
{
|
|
||||||
log_level = log_level_;
|
|
||||||
log_file = log_file_;
|
|
||||||
log_stdout = log_std;
|
|
||||||
max_requests = log_max_requests;
|
|
||||||
save_each_line = save_each_line_;
|
|
||||||
|
|
||||||
// don't open the file here
|
|
||||||
// because it would be created with the root as an owner
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Log::OpenFile()
|
|
||||||
{
|
|
||||||
if( !log_file.empty() )
|
|
||||||
{
|
|
||||||
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
|
|
||||||
log_file_open = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Log::PrintDate(const PT::Date & date, size_t time_zone_id)
|
|
||||||
{
|
|
||||||
if( time_zones )
|
|
||||||
{
|
|
||||||
TimeZone * tz = time_zones->GetZone(time_zone_id);
|
|
||||||
|
|
||||||
if( tz )
|
|
||||||
{
|
|
||||||
PT::Date local_date = tz->ToLocal(date);
|
|
||||||
log << local_date;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*this) << date << " UTC"; // unknown time zone identifier
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*this) << date << " UTC"; // time_zones object was not set
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const void * s)
|
|
||||||
{
|
|
||||||
if( current_level > log_level )
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
buffer << s;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const char * s)
|
|
||||||
{
|
|
||||||
if( current_level > log_level )
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
if( !s )
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
buffer << s;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const std::string & s)
|
|
||||||
{
|
|
||||||
if( current_level > log_level )
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
buffer << s;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const std::string * s)
|
|
||||||
{
|
|
||||||
if( current_level > log_level )
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
buffer << *s;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const wchar_t * s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
if( s )
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const std::wstring & s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const std::wstring * s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << *s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(int s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(long s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(char s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(wchar_t s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(size_t s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(double s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const PT::Space & s)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const PT::Date & date)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << date;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(LogManipulators m)
|
|
||||||
{
|
|
||||||
switch(m)
|
|
||||||
{
|
|
||||||
case logend:
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
buffer << '\n';
|
|
||||||
lines += 1;
|
|
||||||
|
|
||||||
if( save_each_line )
|
|
||||||
SaveLogAndClear();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case logsave:
|
|
||||||
SaveLogAndClear();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case logendrequest:
|
|
||||||
if( ++request >= max_requests || lines > max_lines )
|
|
||||||
SaveLogAndClear();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case log1:
|
|
||||||
current_level = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case log2:
|
|
||||||
current_level = 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case log3:
|
|
||||||
current_level = 3;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case log4:
|
|
||||||
current_level = 4;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char Log::GetHEXdigit(unsigned char c)
|
|
||||||
{
|
|
||||||
if( c < 10 )
|
|
||||||
return c + '0';
|
|
||||||
|
|
||||||
return c - 10 + 'A';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Log::ToHEX(char * buf, unsigned char c)
|
|
||||||
{
|
|
||||||
buf[0] = GetHEXdigit(c >> 4);
|
|
||||||
buf[1] = GetHEXdigit(c & 0xf);
|
|
||||||
buf[2] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Log::LogBinary(const char * blob, size_t blob_len)
|
|
||||||
{
|
|
||||||
size_t i=0;
|
|
||||||
char buf[3];
|
|
||||||
|
|
||||||
|
|
||||||
while( i < blob_len )
|
|
||||||
{
|
|
||||||
size_t oldi = i;
|
|
||||||
|
|
||||||
for(size_t a=0 ; a<16 ; ++a)
|
|
||||||
{
|
|
||||||
if( i < blob_len )
|
|
||||||
{
|
|
||||||
ToHEX(buf, blob[i]);
|
|
||||||
buffer << buf << ' ';
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if( a == 7 )
|
|
||||||
{
|
|
||||||
if( i < blob_len )
|
|
||||||
buffer << "- ";
|
|
||||||
else
|
|
||||||
buffer << " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = oldi;
|
|
||||||
buffer << ' ';
|
|
||||||
|
|
||||||
for(size_t a=0 ; a<16 && i<blob_len ; ++a, ++i)
|
|
||||||
{
|
|
||||||
if( blob[i] > 31 && blob[i] < 127 )
|
|
||||||
buffer << blob[i];
|
|
||||||
else
|
|
||||||
buffer << '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
(*this) << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Log::LogBinary(const std::string & blob)
|
|
||||||
{
|
|
||||||
LogBinary(blob.c_str(), blob.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Log::SystemErr(int err)
|
|
||||||
{
|
|
||||||
(*this) << "errno: " << err;
|
|
||||||
|
|
||||||
const char * err_msg = strerror(err);
|
|
||||||
|
|
||||||
if( err_msg )
|
|
||||||
(*this) << " (" << err_msg << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Log::SaveLogAndClear()
|
|
||||||
{
|
|
||||||
SaveLog();
|
|
||||||
|
|
||||||
buffer.Clear();
|
|
||||||
request = 0;
|
|
||||||
lines = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Log::SaveLog()
|
|
||||||
{
|
|
||||||
if( buffer.Str().empty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if( log_stdout )
|
|
||||||
PT::WideToUTF8(buffer.Str(), std::cout);
|
|
||||||
|
|
||||||
if( log_file.empty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if( !log_file_open || !file )
|
|
||||||
{
|
|
||||||
file.close();
|
|
||||||
file.clear();
|
|
||||||
|
|
||||||
OpenFile();
|
|
||||||
|
|
||||||
if( !file )
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PT::WideToUTF8(buffer.Str(), file);
|
|
||||||
file.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
-174
@@ -1,174 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_log
|
|
||||||
#define headerfile_winix_core_log
|
|
||||||
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include "textstream.h"
|
|
||||||
#include "logmanipulators.h"
|
|
||||||
#include "textstream/textstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TimeZones;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Log
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
Log();
|
|
||||||
~Log();
|
|
||||||
|
|
||||||
void SetTimeZones(TimeZones * ptime_zones);
|
|
||||||
void Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests);
|
|
||||||
|
|
||||||
Log & operator<<(const void * s);
|
|
||||||
Log & operator<<(const char * s);
|
|
||||||
Log & operator<<(const std::string * s);
|
|
||||||
Log & operator<<(const std::string & s);
|
|
||||||
Log & operator<<(const wchar_t * s);
|
|
||||||
Log & operator<<(const std::wstring * s);
|
|
||||||
Log & operator<<(const std::wstring & s);
|
|
||||||
Log & operator<<(int s);
|
|
||||||
Log & operator<<(long s);
|
|
||||||
Log & operator<<(char s);
|
|
||||||
Log & operator<<(wchar_t s);
|
|
||||||
Log & operator<<(size_t s);
|
|
||||||
Log & operator<<(double s);
|
|
||||||
Log & operator<<(const PT::Space & space);
|
|
||||||
Log & operator<<(LogManipulators m);
|
|
||||||
Log & operator<<(const PT::Date & date);
|
|
||||||
|
|
||||||
void PrintDate(const PT::Date & date, size_t time_zone_id);
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
||||||
Log & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void LogString(const StringType & value, size_t max_size);
|
|
||||||
|
|
||||||
void LogBinary(const char * blob, size_t blob_len);
|
|
||||||
void LogBinary(const std::string & blob);
|
|
||||||
|
|
||||||
|
|
||||||
void SystemErr(int err);
|
|
||||||
void SaveLog();
|
|
||||||
void SaveLogAndClear();
|
|
||||||
|
|
||||||
int LogLevel();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// time zones for printing the time in the log file
|
|
||||||
TimeZones * time_zones;
|
|
||||||
|
|
||||||
// buffer for the log
|
|
||||||
TextStream<std::wstring> buffer;
|
|
||||||
|
|
||||||
// log lovel from the config file
|
|
||||||
int log_level;
|
|
||||||
|
|
||||||
// current level set by a modifier (e.g. log << log3)
|
|
||||||
int current_level;
|
|
||||||
|
|
||||||
// current request for logging
|
|
||||||
// starts from zero and incremented after logendrequest modifier
|
|
||||||
int request;
|
|
||||||
|
|
||||||
// how many request to save at once
|
|
||||||
int max_requests;
|
|
||||||
|
|
||||||
// file log
|
|
||||||
std::string log_file;
|
|
||||||
std::ofstream file;
|
|
||||||
|
|
||||||
// logging to stdout
|
|
||||||
bool log_stdout;
|
|
||||||
|
|
||||||
// how many lines there are in the buffer
|
|
||||||
int lines;
|
|
||||||
|
|
||||||
// is the config file already open
|
|
||||||
bool log_file_open;
|
|
||||||
|
|
||||||
// how many lines can be in the config buffer
|
|
||||||
// default: 5000
|
|
||||||
int max_lines;
|
|
||||||
|
|
||||||
// whether to save each line (for debug)
|
|
||||||
bool save_each_line;
|
|
||||||
|
|
||||||
void OpenFile();
|
|
||||||
char GetHEXdigit(unsigned char c);
|
|
||||||
void ToHEX(char * buf, unsigned char c);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void Log::LogString(const StringType & value, size_t max_size)
|
|
||||||
{
|
|
||||||
size_t min_size = value.size() < max_size ? value.size() : max_size;
|
|
||||||
|
|
||||||
if( current_level <= log_level )
|
|
||||||
{
|
|
||||||
for(size_t i=0 ; i<min_size ; ++i)
|
|
||||||
{
|
|
||||||
if( value[i] < 32 )
|
|
||||||
buffer << '.';
|
|
||||||
else
|
|
||||||
buffer << value[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
||||||
Log & Log::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
|
||||||
{
|
|
||||||
if( current_level <= log_level )
|
|
||||||
buffer << buf;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern Log log;
|
|
||||||
extern Log nlog;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// for convenience, we have to use only #include "log.h" in the winix
|
|
||||||
#include "slog.h"
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_logmanipulators
|
|
||||||
#define headerfile_winix_core_logmanipulators
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
log1 - the first level
|
|
||||||
log2
|
|
||||||
log3
|
|
||||||
log4 - the last level (debug level)
|
|
||||||
logend - the end of a line
|
|
||||||
logendrequest - end of a current request
|
|
||||||
logsave - current log buffer is saved and cleared
|
|
||||||
|
|
||||||
manipulators used by the session logger (SLog)
|
|
||||||
loginfo - normal info to a user
|
|
||||||
logerror - we are reporting an error
|
|
||||||
logwarning - we are reporting a warning
|
|
||||||
|
|
||||||
make sure that loginfo, logerror and logwarning have values less than 32 (space)
|
|
||||||
their are used as control codes in a string
|
|
||||||
*/
|
|
||||||
enum LogManipulators
|
|
||||||
{
|
|
||||||
log1,
|
|
||||||
log2,
|
|
||||||
log3,
|
|
||||||
log4,
|
|
||||||
logend,
|
|
||||||
logendrequest,
|
|
||||||
logsave,
|
|
||||||
|
|
||||||
loginfo,
|
|
||||||
logerror,
|
|
||||||
logwarning
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-1166
File diff suppressed because it is too large
Load Diff
-120
@@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2009-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mount.h"
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Mount::Mount()
|
|
||||||
{
|
|
||||||
dir_id = -1;
|
|
||||||
type = -1;
|
|
||||||
fs = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Mount::ClearParams()
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for(i=0 ; i<param.size() ; ++i)
|
|
||||||
param[i].Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Mount::IsPar(int code)
|
|
||||||
{
|
|
||||||
if( code < 0 || code >= (int)param.size() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( !param[code].defined )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Mount::IsArg(int code, const wchar_t * arg)
|
|
||||||
{
|
|
||||||
ParamRow::ParamArg::iterator i;
|
|
||||||
|
|
||||||
if( code < 0 || code >= (int)param.size() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( !param[code].defined )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for(i=param[code].arg.begin() ; i!=param[code].arg.end() ; ++i)
|
|
||||||
{
|
|
||||||
if( *i == arg )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Mount::IsArg(int code, const std::wstring & arg)
|
|
||||||
{
|
|
||||||
return IsArg(code, arg.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Mount::IsArg(int code, int arg)
|
|
||||||
{
|
|
||||||
ParamRow::ParamArg::iterator i;
|
|
||||||
|
|
||||||
if( code < 0 || code >= (int)param.size() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( !param[code].defined )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for(i=param[code].arg.begin() ; i!=param[code].arg.end() ; ++i)
|
|
||||||
{
|
|
||||||
if( Toi(*i) == arg )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & Mount::Arg(int code, int arg) const
|
|
||||||
{
|
|
||||||
if( code < 0 || code >= (int)param.size() )
|
|
||||||
return empty_str;
|
|
||||||
|
|
||||||
if( !param[code].defined )
|
|
||||||
return empty_str;
|
|
||||||
|
|
||||||
if( arg >= (int)param[code].arg.size() )
|
|
||||||
return empty_str;
|
|
||||||
|
|
||||||
return param[code].arg[arg];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & Mount::FirstArg(int code) const
|
|
||||||
{
|
|
||||||
return Arg(code, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2009-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_mount
|
|
||||||
#define headerfile_winix_core_mount
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Mount
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
struct ParamRow
|
|
||||||
{
|
|
||||||
typedef std::vector<std::wstring> ParamArg;
|
|
||||||
|
|
||||||
bool defined;
|
|
||||||
ParamArg arg;
|
|
||||||
|
|
||||||
ParamRow() { defined = false; }
|
|
||||||
void Clear() { defined = false; arg.clear(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<ParamRow> Param;
|
|
||||||
|
|
||||||
|
|
||||||
long dir_id;
|
|
||||||
int type;
|
|
||||||
int fs;
|
|
||||||
Param param;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Mount();
|
|
||||||
void ClearParams();
|
|
||||||
|
|
||||||
bool IsPar(int code);
|
|
||||||
|
|
||||||
bool IsArg(int code, const wchar_t * arg);
|
|
||||||
bool IsArg(int code, const std::wstring & arg);
|
|
||||||
bool IsArg(int code, int arg);
|
|
||||||
|
|
||||||
// returning the arg argument if defined (or an empty string)
|
|
||||||
const std::wstring & Arg(int code, int arg) const;
|
|
||||||
|
|
||||||
// returning the first argument (arg=0) if defined (or an empty string)
|
|
||||||
const std::wstring & FirstArg(int code) const;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// for Arg() methods when the argument is not defined
|
|
||||||
const std::wstring empty_str;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,164 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "plugindata.h"
|
|
||||||
#include "plugin.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "session.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::PluginData()
|
|
||||||
{
|
|
||||||
session = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::PluginData(const PluginData & p)
|
|
||||||
{
|
|
||||||
operator=(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData & PluginData::operator=(const PluginData & p)
|
|
||||||
{
|
|
||||||
// we don't copy all pointers - only resize the table
|
|
||||||
// pointers will be set to zero
|
|
||||||
Resize(p.Size());
|
|
||||||
session = 0;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::~PluginData()
|
|
||||||
{
|
|
||||||
DeleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PluginData::SetSession(Session * ses)
|
|
||||||
{
|
|
||||||
session = ses;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PluginData::Assign(size_t index, PluginDataBase * data)
|
|
||||||
{
|
|
||||||
if( index >= table.size() )
|
|
||||||
Resize(index+1);
|
|
||||||
|
|
||||||
table[index] = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PluginData::Assign(PluginDataBase * data)
|
|
||||||
{
|
|
||||||
if( plugin.current_plugin == -1 )
|
|
||||||
{
|
|
||||||
log << log1 << "PD: Assign(PluginDataBase*) should be called only from plugins" << logend;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Assign(plugin.current_plugin, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginDataBase * PluginData::Get(size_t index)
|
|
||||||
{
|
|
||||||
if( index >= table.size() )
|
|
||||||
Resize(index+1);
|
|
||||||
|
|
||||||
return table[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginDataBase * PluginData::Get()
|
|
||||||
{
|
|
||||||
if( plugin.current_plugin == -1 )
|
|
||||||
{
|
|
||||||
log << log1 << "PD: Get() should be called only from plugins" << logend;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Get(plugin.current_plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PluginData::DeleteAll()
|
|
||||||
{
|
|
||||||
bool all_null = true;
|
|
||||||
|
|
||||||
/*
|
|
||||||
when we copy a session's object (and this object then)
|
|
||||||
we resize the table and there are only null pointers there
|
|
||||||
consequently if all pointers are null there is no sens
|
|
||||||
to send WINIX_PLUGIN_SESSION_DATA_REMOVE
|
|
||||||
*/
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<table.size() ; ++i)
|
|
||||||
{
|
|
||||||
if( table[i] != 0 )
|
|
||||||
{
|
|
||||||
all_null = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
in the future this message may be removed
|
|
||||||
and we directly 'delete' the pointers
|
|
||||||
*/
|
|
||||||
|
|
||||||
if( !all_null )
|
|
||||||
plugin.Call(session, WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
|
||||||
|
|
||||||
table.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t PluginData::Size() const
|
|
||||||
{
|
|
||||||
return table.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PluginData::Resize(size_t new_size)
|
|
||||||
{
|
|
||||||
size_t old_size = table.size();
|
|
||||||
|
|
||||||
if( old_size == new_size )
|
|
||||||
return;
|
|
||||||
|
|
||||||
table.resize(new_size);
|
|
||||||
|
|
||||||
for(size_t i = old_size ; i<new_size ; ++i)
|
|
||||||
table[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_plugindata
|
|
||||||
#define headerfile_winix_core_plugindata
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Session;
|
|
||||||
|
|
||||||
|
|
||||||
struct PluginDataBase
|
|
||||||
{
|
|
||||||
virtual ~PluginDataBase() {}
|
|
||||||
|
|
||||||
/*
|
|
||||||
!! CHECK ME
|
|
||||||
it is still in use?
|
|
||||||
|
|
||||||
when deleting sessions we first call Clear() method
|
|
||||||
consequently the destructor has nothing to do
|
|
||||||
(and it does not throw an exception)
|
|
||||||
*/
|
|
||||||
virtual void Clear() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PluginData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
PluginData();
|
|
||||||
PluginData(const PluginData & p);
|
|
||||||
PluginData & operator=(const PluginData & p);
|
|
||||||
~PluginData();
|
|
||||||
|
|
||||||
void SetSession(Session * ses);
|
|
||||||
|
|
||||||
void Assign(size_t index, PluginDataBase * data);
|
|
||||||
void Assign(PluginDataBase * data);
|
|
||||||
|
|
||||||
PluginDataBase * Get(size_t index);
|
|
||||||
PluginDataBase * Get();
|
|
||||||
|
|
||||||
void DeleteAll();
|
|
||||||
|
|
||||||
size_t Size() const;
|
|
||||||
void Resize(size_t new_size);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Session * session;
|
|
||||||
std::vector<PluginDataBase*> table;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_postparser
|
|
||||||
#define headerfile_winix_core_postparser
|
|
||||||
|
|
||||||
#include <fcgiapp.h>
|
|
||||||
#include <string>
|
|
||||||
#include "httpsimpleparser.h"
|
|
||||||
#include "requesttypes.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "utf8/utf8.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "plugin.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PostParser : public HttpSimpleParser
|
|
||||||
{
|
|
||||||
|
|
||||||
FCGX_Stream * in;
|
|
||||||
PostTab * post_tab;
|
|
||||||
std::wstring temp_name, temp_value;
|
|
||||||
bool input_as_utf8;
|
|
||||||
size_t log_value_size;
|
|
||||||
int var_index;
|
|
||||||
bool has_winix_post_params_msg;
|
|
||||||
bool has_winix_raw_post_msg;
|
|
||||||
std::string raw_post;
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
|
|
||||||
virtual int GetChar()
|
|
||||||
{
|
|
||||||
int c = FCGX_GetChar(in);
|
|
||||||
|
|
||||||
if( c != -1 && has_winix_raw_post_msg )
|
|
||||||
raw_post += c;
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CreateLog(bool param_added)
|
|
||||||
{
|
|
||||||
log << log2 << "Method POST, name: \"" << temp_name << "\"";
|
|
||||||
|
|
||||||
if( log_value_size > 0 && !IsSubStringNoCase(L"pass", temp_name.c_str()) )
|
|
||||||
{
|
|
||||||
log << ", value: ";
|
|
||||||
|
|
||||||
if( temp_value.size() > log_value_size )
|
|
||||||
log << "(first " << log_value_size << " characters) ";
|
|
||||||
|
|
||||||
log << "\"";
|
|
||||||
log.LogString(temp_value, log_value_size);
|
|
||||||
log << "\" (size: " << temp_value.size() << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
if( param_added == false )
|
|
||||||
log << log2 << " (skipped)";
|
|
||||||
|
|
||||||
log << log2 << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ConvStr(const std::string & src, std::wstring & dst)
|
|
||||||
{
|
|
||||||
if( input_as_utf8 )
|
|
||||||
PT::UTF8ToWide(src, dst);
|
|
||||||
else
|
|
||||||
AssignString(src, dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
virtual void Parameter(std::string & name, std::string & value)
|
|
||||||
{
|
|
||||||
bool added;
|
|
||||||
std::pair<PostTab::iterator, bool> res;
|
|
||||||
|
|
||||||
if( has_winix_post_params_msg )
|
|
||||||
plugin.Call(0, WINIX_POST_PARAMS, &name, &value);
|
|
||||||
|
|
||||||
ConvStr(name, temp_name);
|
|
||||||
ConvStr(value, temp_value);
|
|
||||||
|
|
||||||
res = post_tab->insert( std::make_pair(temp_name, temp_value) );
|
|
||||||
added = res.second;
|
|
||||||
|
|
||||||
if( !added )
|
|
||||||
{
|
|
||||||
temp_name += L"_inc";
|
|
||||||
temp_name += Toa(var_index);
|
|
||||||
res = post_tab->insert( std::make_pair(temp_name, temp_value) );
|
|
||||||
added = res.second;
|
|
||||||
var_index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateLog(added);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
PostParser()
|
|
||||||
{
|
|
||||||
input_as_utf8 = false;
|
|
||||||
log_value_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UTF8(bool utf)
|
|
||||||
{
|
|
||||||
input_as_utf8 = utf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogValueSize(size_t s)
|
|
||||||
{
|
|
||||||
log_value_size = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parse(FCGX_Stream * in_, PostTab & post_tab_)
|
|
||||||
{
|
|
||||||
in = in_;
|
|
||||||
post_tab = &post_tab_;
|
|
||||||
var_index = 1;
|
|
||||||
raw_post.clear();
|
|
||||||
|
|
||||||
has_winix_post_params_msg = plugin.HasMessage(WINIX_POST_PARAMS);
|
|
||||||
has_winix_raw_post_msg = plugin.HasMessage(WINIX_RAW_POST_STRING);
|
|
||||||
|
|
||||||
HttpSimpleParser::Parse();
|
|
||||||
|
|
||||||
if( has_winix_raw_post_msg )
|
|
||||||
plugin.Call(0, WINIX_RAW_POST_STRING, &raw_post);
|
|
||||||
|
|
||||||
raw_post.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_rebus
|
|
||||||
#define headerfile_winix_core_rebus
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Cur;
|
|
||||||
|
|
||||||
|
|
||||||
class Rebus
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
struct Item
|
|
||||||
{
|
|
||||||
int key;
|
|
||||||
std::wstring question;
|
|
||||||
int answer;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
void Init();
|
|
||||||
Item * Rand();
|
|
||||||
bool IsAnswerOk(Item * item, const std::wstring & answer);
|
|
||||||
bool CheckRebus();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Cur * cur;
|
|
||||||
|
|
||||||
bool InitPair(int a, int b, Item & item);
|
|
||||||
|
|
||||||
std::vector<Item> table;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,316 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "request.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "plugin.h"
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Request::Request() : char_empty(0)
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
config = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Request::SetConfig(Config * pconfig)
|
|
||||||
{
|
|
||||||
config = pconfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Request::ClearOutputStreams()
|
|
||||||
{
|
|
||||||
size_t len = 16;
|
|
||||||
|
|
||||||
if( config )
|
|
||||||
len = config->ezc_out_streams_size;
|
|
||||||
|
|
||||||
if( len < 1 || len > 64 )
|
|
||||||
len = 16;
|
|
||||||
|
|
||||||
out_streams.resize(len);
|
|
||||||
use_html_filter.resize(len);
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<out_streams.size() ; ++i)
|
|
||||||
{
|
|
||||||
out_streams[i].Clear();
|
|
||||||
use_html_filter[i] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Request::Clear()
|
|
||||||
{
|
|
||||||
// id is never 0
|
|
||||||
if( ++id == 0 )
|
|
||||||
++id;
|
|
||||||
|
|
||||||
RemovePostFileTmp(post_file_tab);
|
|
||||||
ClearOutputStreams();
|
|
||||||
|
|
||||||
post_tab.clear();
|
|
||||||
post_file_tab.clear();
|
|
||||||
cookie_tab.clear();
|
|
||||||
|
|
||||||
method = unknown_method;
|
|
||||||
|
|
||||||
out_headers.Clear();
|
|
||||||
out_cookies.Clear();
|
|
||||||
|
|
||||||
page_generated = false;
|
|
||||||
|
|
||||||
env_request_method = &char_empty;
|
|
||||||
env_request_uri = &char_empty;
|
|
||||||
env_http_cookie = &char_empty;
|
|
||||||
env_remote_addr = &char_empty;
|
|
||||||
env_http_host = &char_empty;
|
|
||||||
env_http_user_agent = &char_empty;
|
|
||||||
env_fcgi_role = &char_empty;
|
|
||||||
env_content_type = &char_empty;
|
|
||||||
env_http_accept_encoding = &char_empty;
|
|
||||||
env_https = &char_empty;
|
|
||||||
|
|
||||||
item_tab.clear();
|
|
||||||
item.Clear();
|
|
||||||
dir_tab.clear();
|
|
||||||
last_item = &item;
|
|
||||||
is_item = false;
|
|
||||||
function = 0;
|
|
||||||
param_tab.clear();
|
|
||||||
anchor.clear();
|
|
||||||
|
|
||||||
status = WINIX_ERR_OK;
|
|
||||||
|
|
||||||
browser_msie = false;
|
|
||||||
redirect_to.clear();
|
|
||||||
redirect_type = 303;
|
|
||||||
x_sendfile.clear();
|
|
||||||
send_as_attachment = false;
|
|
||||||
|
|
||||||
using_ssl = false;
|
|
||||||
|
|
||||||
start_time = 0;
|
|
||||||
start_date.Clear();
|
|
||||||
|
|
||||||
subdomain.clear();
|
|
||||||
return_info_only = false;
|
|
||||||
info.Clear();
|
|
||||||
info_serializer = 0;
|
|
||||||
return_json = false;
|
|
||||||
|
|
||||||
out_bin_stream.clear();
|
|
||||||
send_bin_stream = false;
|
|
||||||
|
|
||||||
gen_trim_white = false;
|
|
||||||
gen_skip_new_line = false;
|
|
||||||
gen_use_special_chars = false;
|
|
||||||
|
|
||||||
ip = 0;
|
|
||||||
use_200_status_for_not_found_and_permission_denied = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Request::RequestStarts()
|
|
||||||
{
|
|
||||||
// clearing it is better to use at the end of a request
|
|
||||||
// so starting is much faster
|
|
||||||
|
|
||||||
start_time = std::time(0);
|
|
||||||
start_date = start_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::IsPostVar(const wchar_t * var)
|
|
||||||
{
|
|
||||||
PostTab::iterator p;
|
|
||||||
|
|
||||||
p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::IsPostVar(const std::wstring & var)
|
|
||||||
{
|
|
||||||
PostTab::iterator p;
|
|
||||||
|
|
||||||
p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & Request::PostVar(const wchar_t * var)
|
|
||||||
{
|
|
||||||
PostTab::iterator p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
return str_empty;
|
|
||||||
|
|
||||||
return p->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & Request::PostVar(const std::wstring & var)
|
|
||||||
{
|
|
||||||
PostTab::iterator p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
return str_empty;
|
|
||||||
|
|
||||||
return p->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::PostVar(const wchar_t * var, std::wstring & result)
|
|
||||||
{
|
|
||||||
PostTab::iterator p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
{
|
|
||||||
result.clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = p->second;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::PostVar(const std::wstring & var, std::wstring & result)
|
|
||||||
{
|
|
||||||
PostTab::iterator p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
{
|
|
||||||
result.clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = p->second;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring * Request::PostVarp(const wchar_t * var)
|
|
||||||
{
|
|
||||||
PostTab::iterator p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return &p->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring * Request::PostVarp(const std::wstring & var)
|
|
||||||
{
|
|
||||||
PostTab::iterator p = post_tab.find(var);
|
|
||||||
|
|
||||||
if( p == post_tab.end() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return &p->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::AllPostVarEmpty()
|
|
||||||
{
|
|
||||||
PostTab::iterator i;
|
|
||||||
|
|
||||||
for(i=post_tab.begin() ; i!=post_tab.end() ; ++i)
|
|
||||||
if( !i->second.empty() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::IsParam(const wchar_t * param_name)
|
|
||||||
{
|
|
||||||
ParamTab::iterator i;
|
|
||||||
|
|
||||||
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
||||||
{
|
|
||||||
if( i->name == param_name )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Request::IsParam(const std::wstring & param_name)
|
|
||||||
{
|
|
||||||
ParamTab::iterator i;
|
|
||||||
|
|
||||||
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
||||||
{
|
|
||||||
if( i->name == param_name )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & Request::ParamValue(const wchar_t * param_name)
|
|
||||||
{
|
|
||||||
ParamTab::iterator i;
|
|
||||||
|
|
||||||
for(i=param_tab.begin() ; i!=param_tab.end() ; ++i)
|
|
||||||
{
|
|
||||||
if( i->name == param_name )
|
|
||||||
return i->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str_empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & Request::ParamValue(const std::wstring & param_name)
|
|
||||||
{
|
|
||||||
return ParamValue(param_name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-409
@@ -1,409 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_request
|
|
||||||
#define headerfile_winix_core_request
|
|
||||||
|
|
||||||
#include <fcgiapp.h>
|
|
||||||
#include <sstream>
|
|
||||||
#include <vector>
|
|
||||||
#include "requesttypes.h"
|
|
||||||
#include "item.h"
|
|
||||||
#include "error.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "textstream.h"
|
|
||||||
#include "templates/htmltextstream.h"
|
|
||||||
#include "date/date.h"
|
|
||||||
#include "space/space.h"
|
|
||||||
#include "space/spacetojson.h"
|
|
||||||
#include "textstream/textstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FunctionBase;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Request
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
request id
|
|
||||||
is incremented for each request and is never 0
|
|
||||||
(from -1 will be incremented to one)
|
|
||||||
it's used for some optimizations e.g. in templates
|
|
||||||
*/
|
|
||||||
size_t id;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
request start time
|
|
||||||
Time() methods are very slow so it is better to directly use those two values
|
|
||||||
they are set when a request starts
|
|
||||||
*/
|
|
||||||
time_t start_time;
|
|
||||||
PT::Date start_date;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* variables representing input from client's browser
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
the HTTP method
|
|
||||||
!! IMPROVE ME add the rest methods here
|
|
||||||
*/
|
|
||||||
enum Method { get, post, head, unknown_method } method;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
subdomain
|
|
||||||
subdomain = HTTP_HOST environment variable - config->base_url
|
|
||||||
*/
|
|
||||||
std::wstring subdomain;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
raw parameters
|
|
||||||
!! CHECK ME may post_tab and cookie_tab should be changed to PT::Space now?
|
|
||||||
or may change the name to cookie_in? or in_cookie?
|
|
||||||
*/
|
|
||||||
PostTab post_tab;
|
|
||||||
PostFileTab post_file_tab;
|
|
||||||
CookieTab cookie_tab;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
html anchor (those part of URI after '#' character)
|
|
||||||
*/
|
|
||||||
std::wstring anchor;
|
|
||||||
|
|
||||||
|
|
||||||
// environment variables
|
|
||||||
// they are not null -- when the server doesn't have such a variable
|
|
||||||
// it will be pointing into 'char_empty' which is default '\0'
|
|
||||||
// !! IMPROVE ME change it to std::wstring, or may PT::Space too?
|
|
||||||
const char * env_request_method;
|
|
||||||
const char * env_request_uri;
|
|
||||||
const char * env_http_cookie;
|
|
||||||
const char * env_remote_addr;
|
|
||||||
const char * env_http_host;
|
|
||||||
const char * env_http_user_agent;
|
|
||||||
const char * env_http_accept_encoding;
|
|
||||||
const char * env_fcgi_role;
|
|
||||||
const char * env_content_type;
|
|
||||||
const char * env_https;
|
|
||||||
|
|
||||||
// current IP address of the remote host (read from REMOTE_ADDR environment variable)
|
|
||||||
// (at the moment only IPv4 are supported)
|
|
||||||
int ip;
|
|
||||||
|
|
||||||
// true if the browser is Microsoft Internet Explorer
|
|
||||||
bool browser_msie;
|
|
||||||
|
|
||||||
// true if the browser is Konqueror
|
|
||||||
bool browser_konqueror;
|
|
||||||
|
|
||||||
// true if we are using an encrypted connection (SSL)
|
|
||||||
bool using_ssl;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
request input variables representing the winix filesystem
|
|
||||||
*/
|
|
||||||
|
|
||||||
// current directory
|
|
||||||
std::vector<Item*> dir_tab;
|
|
||||||
|
|
||||||
// true if a file exists
|
|
||||||
bool is_item;
|
|
||||||
|
|
||||||
// current file (valid if is_item is true)
|
|
||||||
Item item;
|
|
||||||
|
|
||||||
// current winix function
|
|
||||||
// null if there is no a function
|
|
||||||
FunctionBase * function;
|
|
||||||
|
|
||||||
// parameters (name:value)
|
|
||||||
ParamTab param_tab;
|
|
||||||
|
|
||||||
// this is a pointer either to the item (if exists) or to the last directory
|
|
||||||
Item * last_item;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* variables for generating output to the client's browser
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// request status
|
|
||||||
// !! CHANGE ME it'll be better to use ordinary http result codes
|
|
||||||
Error status;
|
|
||||||
|
|
||||||
// if not empty means an address for redirecting to
|
|
||||||
// it should be url-encoded
|
|
||||||
std::wstring redirect_to;
|
|
||||||
|
|
||||||
// a redirect type
|
|
||||||
// following redirect types are supported:
|
|
||||||
// 300 Multiple Choices
|
|
||||||
// 301 Moved Permanently
|
|
||||||
// 302 Found
|
|
||||||
// 303 See Other (default)
|
|
||||||
// 307 Temporary Redirect
|
|
||||||
int redirect_type;
|
|
||||||
|
|
||||||
// send header X-LIGHTTPD-send-file with path to a file
|
|
||||||
std::wstring x_sendfile;
|
|
||||||
|
|
||||||
// send as attachment (causes generating header: content-disposition: attachment)
|
|
||||||
bool send_as_attachment;
|
|
||||||
|
|
||||||
// headers send to the client (without cookies)
|
|
||||||
PT::Space out_headers;
|
|
||||||
|
|
||||||
// cookies send to the client
|
|
||||||
// a value can be either a cookie value or the whole cookie string (with domain, date etc)
|
|
||||||
PT::Space out_cookies;
|
|
||||||
|
|
||||||
// winix can return either a text answer or a binary answer
|
|
||||||
// if send_bin_stream is true then the binary answer is sent (out_bin_stream)
|
|
||||||
// or if send_bin_stream is false then the text answer is sent
|
|
||||||
// default: false
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// winix answer send to the client's browser
|
|
||||||
// |
|
|
||||||
// |
|
|
||||||
// depending on send_bin_stream
|
|
||||||
// (if false) ------------------------------------------------- (if true)
|
|
||||||
// | |
|
|
||||||
// text answer binary answer
|
|
||||||
// | |
|
|
||||||
// depending on return_json sending out_bin_stream
|
|
||||||
// (if false) ------------------------------------ (if true)
|
|
||||||
// | |
|
|
||||||
// normal request ajax request
|
|
||||||
// | |
|
|
||||||
// sending out_streams[0] |
|
|
||||||
// |
|
|
||||||
// |
|
|
||||||
// depending on return_info_only
|
|
||||||
// (if false) ------------------------------------------------------ (if true)
|
|
||||||
// | |
|
|
||||||
// generating JSON object from: generating JSON object only from info
|
|
||||||
// out_streams and info, e.g.: e.g.:
|
|
||||||
// { { info object serialized here }
|
|
||||||
// "stream_1": "some html content",
|
|
||||||
// "stream_2": "some other html content",
|
|
||||||
// "info": { info object serialized here }
|
|
||||||
// }
|
|
||||||
// note that out_streams[0] is not sent
|
|
||||||
// in JSON answers
|
|
||||||
//
|
|
||||||
//
|
|
||||||
bool send_bin_stream;
|
|
||||||
|
|
||||||
// binary page sent to the client if send_bin_stream is true
|
|
||||||
BinaryPage out_bin_stream;
|
|
||||||
|
|
||||||
// when returning the text answer we can either return the whole html page (normal requests)
|
|
||||||
// or a JSON object (for requests generated from AJAX)
|
|
||||||
// if return_json is false then we return the whole html page (which is in out_streams[0])
|
|
||||||
// if return_json is true we are creating an JSON object from out_streams
|
|
||||||
// (zero stream is ignored) and from info space (see above picture)
|
|
||||||
// (or just only from info if return_info_only is true)
|
|
||||||
// default: false
|
|
||||||
// return_json is set to true by App at the beginning of a request
|
|
||||||
// if reqtype:json parameter is present (in the url)
|
|
||||||
// note: return_json is only valid if send_bin_stream is false
|
|
||||||
bool return_json;
|
|
||||||
|
|
||||||
// main text output streams where the html otput is generated from ezc templates
|
|
||||||
// the zero stream (out_streams[0]) is used as the main stream
|
|
||||||
// to which the whole html page (with doctype, head, body) is generated
|
|
||||||
// the rest streams can be only used in ajax requests (send in JSON format to the client)
|
|
||||||
// in ezc templates you can use [ezc stream ...] keyword
|
|
||||||
// to switch between streams e.g. [ezc stream "0" "2"]
|
|
||||||
std::vector<HtmlTextStream> out_streams;
|
|
||||||
|
|
||||||
// if true the JSON object is generated only from info (out_streams are not used)
|
|
||||||
// default: false
|
|
||||||
bool return_info_only;
|
|
||||||
|
|
||||||
// additional info added when sending the JSON answer
|
|
||||||
PT::Space info;
|
|
||||||
|
|
||||||
// info serializer
|
|
||||||
// if not set then the json_generic_serializer from App will be used
|
|
||||||
// default: null (json_generic_serializer used)
|
|
||||||
PT::SpaceToJSON * info_serializer;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if set to true then the standard template system will not be used
|
|
||||||
// default: false
|
|
||||||
bool page_generated;
|
|
||||||
|
|
||||||
// whether or not the html filter should be used
|
|
||||||
// the size of the table is the same as out_streams
|
|
||||||
// default: all items true
|
|
||||||
std::vector<bool> use_html_filter;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if this variable is true then winix always return 200 OK header
|
|
||||||
// when the status would be 404 (not found) or 403 (permission denied)
|
|
||||||
// default: false
|
|
||||||
bool use_200_status_for_not_found_and_permission_denied;
|
|
||||||
|
|
||||||
// options used by ezc generators
|
|
||||||
bool gen_trim_white;
|
|
||||||
bool gen_skip_new_line;
|
|
||||||
bool gen_use_special_chars;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
additional variables used for common uses
|
|
||||||
*/
|
|
||||||
|
|
||||||
// usually items in the current directory (depends on the function)
|
|
||||||
std::vector<Item> item_tab;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Request();
|
|
||||||
void SetConfig(Config * pconfig);
|
|
||||||
|
|
||||||
void RequestStarts();
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool IsParam(const wchar_t * param_name);
|
|
||||||
bool IsParam(const std::wstring & param_name);
|
|
||||||
const std::wstring & ParamValue(const wchar_t * param_name); // returns an empty string if there is no such a parameter
|
|
||||||
const std::wstring & ParamValue(const std::wstring & param_name); // returns an empty string if there is no such a parameter
|
|
||||||
|
|
||||||
bool IsPostVar(const wchar_t * var);
|
|
||||||
bool IsPostVar(const std::wstring & var);
|
|
||||||
const std::wstring & PostVar(const wchar_t * var); // returns an empty string if there is no such a parameter
|
|
||||||
const std::wstring & PostVar(const std::wstring & var); // returns an empty string if there is no such a parameter
|
|
||||||
bool PostVar(const wchar_t * var, std::wstring & result);
|
|
||||||
bool PostVar(const std::wstring & var, std::wstring & result);
|
|
||||||
std::wstring * PostVarp(const wchar_t * var);
|
|
||||||
std::wstring * PostVarp(const std::wstring & var);
|
|
||||||
|
|
||||||
bool AllPostVarEmpty(); // returning true if all post vars are empty
|
|
||||||
|
|
||||||
|
|
||||||
// setting a cookie
|
|
||||||
// name - cookie name (either const wchar_t, or std::wstring or PT::WTextStream)
|
|
||||||
// value - cookie value (can be everything which can be put to PT::WTextStream stream)
|
|
||||||
// the return std::wstring reference is a reference to the cookie inserted value (in out_cookies structure)
|
|
||||||
template<typename NameType, typename ValueType>
|
|
||||||
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date * expires = 0);
|
|
||||||
|
|
||||||
template<typename NameType, typename ValueType>
|
|
||||||
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date & expires);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Config * config;
|
|
||||||
|
|
||||||
// contains '\0'
|
|
||||||
// used to set env_* pointers to the empty value
|
|
||||||
const char char_empty;
|
|
||||||
|
|
||||||
// used in ParamValue() and PostVar() when there is no such a param
|
|
||||||
const std::wstring str_empty;
|
|
||||||
|
|
||||||
void ClearOutputStreams();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename NameType, typename ValueType>
|
|
||||||
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date * expires)
|
|
||||||
{
|
|
||||||
PT::WTextStream cookie;
|
|
||||||
|
|
||||||
cookie << value;
|
|
||||||
|
|
||||||
if( cookie.empty() )
|
|
||||||
cookie << L"\"\""; // cookie empty value
|
|
||||||
|
|
||||||
if( expires )
|
|
||||||
cookie << L"; expires=" << DateToStrCookie(*expires) << L" GMT";
|
|
||||||
|
|
||||||
cookie << L"; path=/; domain=" << config->base_url;
|
|
||||||
|
|
||||||
/*
|
|
||||||
!! IMPROVE ME add an option to the config
|
|
||||||
|
|
||||||
don't use '; secure' flag if you are using both sites (with SSL
|
|
||||||
and without SSL) -- with secure flag the cookie is sent only through
|
|
||||||
SSL and if you accidentally open a new window without SSL (http://)
|
|
||||||
then winix will create a new session for you and the previous session (https://)
|
|
||||||
will be lost (the session cookie will be overwritten in the client's browser)
|
|
||||||
*/
|
|
||||||
|
|
||||||
return out_cookies.Add(name, cookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename NameType, typename ValueType>
|
|
||||||
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date & expires)
|
|
||||||
{
|
|
||||||
return AddCookie(name, value, &expires);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_requesttypes
|
|
||||||
#define headerfile_winix_core_requesttypes
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include "textstream/textstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! IMPROVE ME
|
|
||||||
// !! narazie uzywane tylko w post multi parserze
|
|
||||||
// dodac do zwyklego parsera post
|
|
||||||
#define WINIX_POSTTABLE_MAXSIZE 50
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct PostFile
|
|
||||||
{
|
|
||||||
std::wstring filename; // original file name
|
|
||||||
std::wstring tmp_filename; // file with content (in /tmp)
|
|
||||||
size_t file_size;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// parameters from get name:value
|
|
||||||
struct Param
|
|
||||||
{
|
|
||||||
std::wstring name;
|
|
||||||
std::wstring value;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// some global types used by Request class
|
|
||||||
typedef std::map<std::wstring, std::wstring> PostTab;
|
|
||||||
typedef std::map<std::wstring, PostFile> PostFileTab;
|
|
||||||
typedef std::vector<Param> ParamTab;
|
|
||||||
|
|
||||||
typedef std::map<std::wstring, std::wstring> CookieTab;
|
|
||||||
|
|
||||||
|
|
||||||
typedef PT::TextStreamBase<char, 1, 4096> BinaryPage;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "session.h"
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Session::Session()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
plugin_data.SetSession(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Session::Session(const Session & ses)
|
|
||||||
{
|
|
||||||
operator=(ses);
|
|
||||||
}
|
|
||||||
|
|
||||||
Session & Session::operator=(const Session & ses)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
we can only copy ses.id because it is needen in SessionContainer
|
|
||||||
it have indexes to id
|
|
||||||
*/
|
|
||||||
|
|
||||||
Clear();
|
|
||||||
id = ses.id;
|
|
||||||
plugin_data.SetSession(this);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Session::SetTimesTo(time_t time)
|
|
||||||
{
|
|
||||||
start_time = time;
|
|
||||||
start_date = time;
|
|
||||||
|
|
||||||
last_time = start_time;
|
|
||||||
last_date = start_date;
|
|
||||||
|
|
||||||
// the first request can be a POST (it doesn't matter)
|
|
||||||
last_time_get = start_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// clear_plugin_data is used when clearing the temporary session
|
|
||||||
void Session::Clear(bool clear_plugin_data)
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
puser = 0;
|
|
||||||
rebus_item = 0;
|
|
||||||
rebus_checked = false;
|
|
||||||
remember_me = false;
|
|
||||||
new_session = true;
|
|
||||||
spam_score = 0;
|
|
||||||
remove_me = false;
|
|
||||||
|
|
||||||
start_time = 0;
|
|
||||||
last_time = 0;
|
|
||||||
last_time_get = 0;
|
|
||||||
start_date.Clear();
|
|
||||||
last_date.Clear();
|
|
||||||
|
|
||||||
log_buffer.Clear();
|
|
||||||
last_css.clear();
|
|
||||||
ip_ban = 0;
|
|
||||||
|
|
||||||
if( clear_plugin_data )
|
|
||||||
plugin_data.Resize(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// clearing some variables when a request is ended (just for safety)
|
|
||||||
void Session::ClearAfterRequest()
|
|
||||||
{
|
|
||||||
// ip_ban list can be sorted by SessionManager (in the special thread)
|
|
||||||
ip_ban = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
-107
@@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_session
|
|
||||||
#define headerfile_winix_core_session
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <ctime>
|
|
||||||
#include "item.h"
|
|
||||||
#include "error.h"
|
|
||||||
#include "user.h"
|
|
||||||
#include "plugindata.h"
|
|
||||||
#include "rebus.h"
|
|
||||||
#include "textstream.h"
|
|
||||||
#include "date/date.h"
|
|
||||||
#include "ipban.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Session
|
|
||||||
{
|
|
||||||
Session();
|
|
||||||
Session(const Session & ses);
|
|
||||||
Session & operator=(const Session & ses);
|
|
||||||
|
|
||||||
void SetTimesTo(time_t time);
|
|
||||||
void Clear(bool clear_plugin_data = true);
|
|
||||||
void ClearAfterRequest();
|
|
||||||
|
|
||||||
|
|
||||||
// 0 - means that there is a temporary session
|
|
||||||
long id;
|
|
||||||
|
|
||||||
// true if the session was created now
|
|
||||||
bool new_session;
|
|
||||||
|
|
||||||
// when this session was created
|
|
||||||
// (the same values)
|
|
||||||
time_t start_time;
|
|
||||||
PT::Date start_date;
|
|
||||||
|
|
||||||
// when this session was last used
|
|
||||||
// (the same values)
|
|
||||||
time_t last_time;
|
|
||||||
PT::Date last_date;
|
|
||||||
|
|
||||||
// when there was a last get request
|
|
||||||
// (used to calculate spam or invalid login attempts etc.)
|
|
||||||
time_t last_time_get;
|
|
||||||
|
|
||||||
|
|
||||||
// 0 - means that nobody is logged
|
|
||||||
User * puser;
|
|
||||||
|
|
||||||
// if false the session will end when the user browser is shutdown
|
|
||||||
bool remember_me;
|
|
||||||
|
|
||||||
|
|
||||||
// rebus - set by rebus_question(Info & i) from templates
|
|
||||||
Rebus::Item * rebus_item;
|
|
||||||
bool rebus_checked;
|
|
||||||
|
|
||||||
|
|
||||||
int spam_score;
|
|
||||||
|
|
||||||
// if true then this session will be removed by SessionManager
|
|
||||||
// without checking the time expiration
|
|
||||||
bool remove_me;
|
|
||||||
|
|
||||||
PluginData plugin_data;
|
|
||||||
|
|
||||||
|
|
||||||
// buffer for the session log
|
|
||||||
TextStream<std::wstring> log_buffer;
|
|
||||||
|
|
||||||
// !! IMPROVE ME it is still needed?
|
|
||||||
// css cannot be taken directly from the mountpoint?
|
|
||||||
// table with css files
|
|
||||||
// used by some javascript wysiwyg editors (ckeditor, tinymce)
|
|
||||||
std::vector<std::wstring> last_css;
|
|
||||||
|
|
||||||
// pointer to IPBan struct if exists for this IP
|
|
||||||
// many sessions can pointer to the same IPBan struct
|
|
||||||
// (it can be null)
|
|
||||||
IPBan * ip_ban;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_sessioncontainer
|
|
||||||
#define headerfile_winix_core_sessioncontainer
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <map>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
#include "session.h"
|
|
||||||
#include "cur.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionContainer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef std::list<Session> Table;
|
|
||||||
typedef Table::iterator Iterator;
|
|
||||||
typedef std::map<long, Iterator> IndexId;
|
|
||||||
typedef IndexId::iterator IdIterator;
|
|
||||||
|
|
||||||
|
|
||||||
SessionContainer();
|
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
void SetConfig(Config * pconfig);
|
|
||||||
void SetTmpSession(Session * psession);
|
|
||||||
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
size_t Size();
|
|
||||||
Iterator Begin();
|
|
||||||
Iterator End();
|
|
||||||
Session & Back();
|
|
||||||
Iterator AddSession(long id);
|
|
||||||
Iterator FindById(long);
|
|
||||||
|
|
||||||
IdIterator IdBegin();
|
|
||||||
IdIterator IdEnd();
|
|
||||||
|
|
||||||
void EraseById(long id);
|
|
||||||
|
|
||||||
bool ChangeSessionId(Iterator ses, long new_id);
|
|
||||||
bool ChangeSessionId(long old_id, long new_id);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Table table;
|
|
||||||
IndexId index_id;
|
|
||||||
|
|
||||||
Cur * cur;
|
|
||||||
Config * config;
|
|
||||||
Session * tmp_session;
|
|
||||||
|
|
||||||
Session empty_session;
|
|
||||||
|
|
||||||
// in FreeBSD implementation (GCC) list::size() has linear complexity
|
|
||||||
// so we use our own table_size with O(1)
|
|
||||||
size_t table_size;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,611 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include "sessionmanager.h"
|
|
||||||
#include "request.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "session.h"
|
|
||||||
#include "sessionparser.h"
|
|
||||||
#include "plugin.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SessionManager::SessionManager()
|
|
||||||
{
|
|
||||||
temporary_session.id = 0;
|
|
||||||
session = &temporary_session;
|
|
||||||
session_tab.SetTmpSession(&temporary_session);
|
|
||||||
|
|
||||||
// thread work mode
|
|
||||||
work_mode = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::SetCur(Cur * pcur)
|
|
||||||
{
|
|
||||||
cur = pcur;
|
|
||||||
session_tab.SetCur(pcur);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::SetConfig(Config * pconfig)
|
|
||||||
{
|
|
||||||
config = pconfig;
|
|
||||||
session_tab.SetConfig(pconfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::SetSystem(System * psystem)
|
|
||||||
{
|
|
||||||
system = psystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::SetLastContainer(LastContainer * plast_container)
|
|
||||||
{
|
|
||||||
last_container = plast_container;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::InitBanList()
|
|
||||||
{
|
|
||||||
ban_tab.SetMaxSize(config->ban_list_soft_max_size, config->ban_list_max_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t SessionManager::Size()
|
|
||||||
{
|
|
||||||
return session_tab.Size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SessionManager::IsSession(long id)
|
|
||||||
{
|
|
||||||
if( session_tab.FindById(id) == session_tab.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::CreateSession()
|
|
||||||
{
|
|
||||||
int attempts = 100;
|
|
||||||
SessionContainer::Iterator i = session_tab.End();
|
|
||||||
|
|
||||||
if( config->session_max == 0 || session_tab.Size() < config->session_max )
|
|
||||||
{
|
|
||||||
for( ; i == session_tab.End() && attempts > 0 ; --attempts )
|
|
||||||
{
|
|
||||||
long id = CreateSessionId();
|
|
||||||
i = session_tab.AddSession(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log2 << "SM: sessions limit exceeded (" << config->session_max << ")" << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( i != session_tab.End() )
|
|
||||||
{
|
|
||||||
session = &(*i);
|
|
||||||
session->new_session = true;
|
|
||||||
session->SetTimesTo(cur->request->start_time);
|
|
||||||
|
|
||||||
log << log2 << "SM: created a new session: " << session->id << logend;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// there is a problem with generating a new session id
|
|
||||||
// we do not set a session cookie
|
|
||||||
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
|
|
||||||
SetTemporarySession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::SetTemporarySession()
|
|
||||||
{
|
|
||||||
session = &temporary_session;
|
|
||||||
session->Clear(false);
|
|
||||||
session->SetTimesTo(cur->request->start_time);
|
|
||||||
session->new_session = false; // temporary session was initialized at the beginning
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SessionManager::SetSessionFromCookie(const std::wstring & cookie)
|
|
||||||
{
|
|
||||||
long id = Tol(cookie.c_str());
|
|
||||||
SessionContainer::Iterator s = session_tab.FindById(id);
|
|
||||||
|
|
||||||
if( s == session_tab.End() || s->remove_me )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// that session is in the table
|
|
||||||
session = &(*s);
|
|
||||||
session->new_session = false;
|
|
||||||
session->last_time = cur->request->start_time;
|
|
||||||
session->last_date = cur->request->start_time;
|
|
||||||
|
|
||||||
if( cur->request->method == Request::get )
|
|
||||||
session->last_time_get = cur->request->start_time;
|
|
||||||
|
|
||||||
log << log2 << "SM: session: " << session->id;
|
|
||||||
|
|
||||||
if( session->puser )
|
|
||||||
log << log2 << ", user: " << session->puser->name << ", id: " << session->puser->id;
|
|
||||||
|
|
||||||
log << log2 << logend;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::SetSession()
|
|
||||||
{
|
|
||||||
current_ip_ban = ban_tab.FindIP(cur->request->ip);
|
|
||||||
|
|
||||||
if( current_ip_ban && current_ip_ban->IsIPBanned() )
|
|
||||||
{
|
|
||||||
if( current_ip_ban->expires != 0 && cur->request->start_time >= current_ip_ban->expires )
|
|
||||||
{
|
|
||||||
log << log2 << "SM: removing a ban from this IP and resetting events counter" << logend;
|
|
||||||
current_ip_ban->ClearAfterRemovingBan();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log2 << "SM: this ip is bannned, using a temporary session" << logend;
|
|
||||||
SetTemporarySession();
|
|
||||||
session->ip_ban = current_ip_ban;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
|
|
||||||
|
|
||||||
if( i == cur->request->cookie_tab.end() )
|
|
||||||
{
|
|
||||||
CreateSession();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( !SetSessionFromCookie(i->second) )
|
|
||||||
{
|
|
||||||
// there is no such a session
|
|
||||||
// deleting the old cookie
|
|
||||||
cur->request->cookie_tab.erase(i);
|
|
||||||
|
|
||||||
// and creating a new one
|
|
||||||
CreateSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
session->ip_ban = current_ip_ban;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Session * SessionManager::FindSession(long id)
|
|
||||||
{
|
|
||||||
SessionContainer::Iterator i = session_tab.FindById(id);
|
|
||||||
|
|
||||||
if( i != session_tab.End() )
|
|
||||||
return &*i;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SessionContainer::Iterator SessionManager::SessionBegin()
|
|
||||||
{
|
|
||||||
return session_tab.Begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SessionContainer::Iterator SessionManager::SessionEnd()
|
|
||||||
{
|
|
||||||
return session_tab.End();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::DeleteSessions()
|
|
||||||
{
|
|
||||||
SessionContainer::Iterator i;
|
|
||||||
|
|
||||||
for(i=session_tab.Begin() ; i!=session_tab.End() ; ++i)
|
|
||||||
{
|
|
||||||
if( i->puser && !i->remember_me )
|
|
||||||
{
|
|
||||||
plugin.Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
|
||||||
last_container->UserLogout(i->puser->id, i->id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
session_tab.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
don't change a session's id when a user is logged
|
|
||||||
the session id is in last_container and the user would not be
|
|
||||||
correctly removed from the container
|
|
||||||
*/
|
|
||||||
bool SessionManager::ChangeSessionId(long old_id)
|
|
||||||
{
|
|
||||||
int attempts = 100;
|
|
||||||
bool changed = false;
|
|
||||||
long new_id;
|
|
||||||
SessionContainer::Iterator i = session_tab.FindById(old_id);
|
|
||||||
|
|
||||||
if( i != session_tab.End() )
|
|
||||||
{
|
|
||||||
for( ; !changed && attempts > 0 ; --attempts )
|
|
||||||
{
|
|
||||||
new_id = CreateSessionId();
|
|
||||||
changed = session_tab.ChangeSessionId(i, new_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( changed )
|
|
||||||
plugin.Call(&(*i), WINIX_SESSION_CHANGED_ID, old_id, new_id);
|
|
||||||
else
|
|
||||||
log << log1 << "SM: I cannot create a new session id (still uses old one)" << logend;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log2 << "SM: there is no a session with id: " << old_id << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::InitTmpSession()
|
|
||||||
{
|
|
||||||
Session * old_session = cur->session;
|
|
||||||
|
|
||||||
log << log4 << "SM: initializing temporary session" << logend;
|
|
||||||
cur->session = &temporary_session;
|
|
||||||
plugin.Call(WINIX_SESSION_CREATED);
|
|
||||||
|
|
||||||
cur->session = old_session;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::UninitTmpSession()
|
|
||||||
{
|
|
||||||
Session * old_session = cur->session;
|
|
||||||
|
|
||||||
log << log4 << "SM: uninitializing temporary session" << logend;
|
|
||||||
cur->session = &temporary_session;
|
|
||||||
cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
|
||||||
cur->session->plugin_data.Resize(0);
|
|
||||||
|
|
||||||
cur->session = old_session;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::LoadSessions()
|
|
||||||
{
|
|
||||||
SessionParser sp;
|
|
||||||
SessionContainer::Iterator i;
|
|
||||||
|
|
||||||
// sessions will be overwritten (pointers are invalidated)
|
|
||||||
cur->session = &temporary_session;
|
|
||||||
|
|
||||||
sp.SetUsers(&system->users);
|
|
||||||
sp.Parse(config->session_file, session_tab);
|
|
||||||
|
|
||||||
for(i=session_tab.Begin() ; i != session_tab.End() ; ++i)
|
|
||||||
{
|
|
||||||
i->plugin_data.Resize(plugin.Size());
|
|
||||||
plugin.Call(&(*i), WINIX_SESSION_CREATED);
|
|
||||||
|
|
||||||
/*
|
|
||||||
!! IMPROVE ME
|
|
||||||
we do not add it to the last_container (we don't have IP address stored yet)
|
|
||||||
*/
|
|
||||||
|
|
||||||
if( i->puser )
|
|
||||||
plugin.Call(&(*i), WINIX_USER_LOGGED);
|
|
||||||
}
|
|
||||||
|
|
||||||
cur->session = &temporary_session;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::SaveSessions()
|
|
||||||
{
|
|
||||||
if( config->session_file.empty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::ofstream file(config->session_file.c_str());
|
|
||||||
|
|
||||||
if( !file )
|
|
||||||
{
|
|
||||||
log << log1 << "SM: cannot open the session file for writing - sessions lost" << logend;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log << log2 << "SM: saving sessions" << logend;
|
|
||||||
long len = 0;
|
|
||||||
|
|
||||||
SessionContainer::Iterator i = session_tab.Begin();
|
|
||||||
|
|
||||||
for( ; i!=session_tab.End() ; ++i )
|
|
||||||
{
|
|
||||||
if( i->id != 0 && i->puser && !i->remove_me )
|
|
||||||
{
|
|
||||||
file << i->id << ' ' << i->puser->id << ' ' << i->remember_me << ' ';
|
|
||||||
file << (long)i->start_time << ' ' << (long)i->last_time << std::endl;
|
|
||||||
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
chmod(config->session_file.c_str(), 0600);
|
|
||||||
|
|
||||||
log << log2 << "SM: saved " << len << " session(s)" << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Session * SessionManager::GetTmpSession()
|
|
||||||
{
|
|
||||||
return &temporary_session;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Session * SessionManager::GetCurSession()
|
|
||||||
{
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// returns how many sessions was marked to remove
|
|
||||||
size_t SessionManager::MarkAllSessionsToRemove(long user_id)
|
|
||||||
{
|
|
||||||
size_t how_many = 0;
|
|
||||||
SessionContainer::Iterator i;
|
|
||||||
|
|
||||||
for(i=session_tab.Begin() ; i!=session_tab.End() ; ++i)
|
|
||||||
{
|
|
||||||
if( i->puser && i->puser->id == user_id )
|
|
||||||
{
|
|
||||||
plugin.Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
|
||||||
last_container->UserLogout(i->puser->id, i->id);
|
|
||||||
i->remove_me = true;
|
|
||||||
i->puser = 0;
|
|
||||||
how_many += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return how_many;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
IPBan & SessionManager::AddIPToBanList(int ip)
|
|
||||||
{
|
|
||||||
return ban_tab.AddIP(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t SessionManager::BanListSize()
|
|
||||||
{
|
|
||||||
return ban_tab.Size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
IPBan & SessionManager::GetIPBan(size_t index)
|
|
||||||
{
|
|
||||||
return ban_tab.GetIPBan(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::RemoveIPBan(int ip)
|
|
||||||
{
|
|
||||||
ban_tab.RemoveIP(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::ClearIPBanList()
|
|
||||||
{
|
|
||||||
ban_tab.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* sessions gc (second thread)
|
|
||||||
* sessions are only removed here
|
|
||||||
* SessionContainer::IndexId can be removed from the other thread
|
|
||||||
* (when ChangeSessionId() method is called)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void SessionManager::Work()
|
|
||||||
{
|
|
||||||
bool exit = false;
|
|
||||||
SessionContainer::Iterator i;
|
|
||||||
|
|
||||||
deleted = 0;
|
|
||||||
|
|
||||||
Lock();
|
|
||||||
i = session_tab.Begin();
|
|
||||||
Unlock();
|
|
||||||
|
|
||||||
while( !exit )
|
|
||||||
{
|
|
||||||
Lock();
|
|
||||||
|
|
||||||
CheckWheterIPListIsSorted();
|
|
||||||
CheckSession(i);
|
|
||||||
exit = synchro->was_stop_signal;
|
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// objects locked
|
|
||||||
void SessionManager::CheckWheterIPListIsSorted()
|
|
||||||
{
|
|
||||||
if( !ban_tab.IsSorted() )
|
|
||||||
{
|
|
||||||
log << log4 << "SM: sorting the ban list" << logend;
|
|
||||||
ban_tab.Sort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// it's called from the other thread (with Lock and Unlock)
|
|
||||||
void SessionManager::CheckSession(SessionContainer::Iterator & i)
|
|
||||||
{
|
|
||||||
const int deleted_max_at_once = 10;
|
|
||||||
|
|
||||||
if( i == session_tab.End() )
|
|
||||||
{
|
|
||||||
if( deleted > 0 )
|
|
||||||
{
|
|
||||||
deleted = 0;
|
|
||||||
log << logsave;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = session_tab.Begin();
|
|
||||||
WaitForSignalSleep(10);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( i->remove_me || IsSessionOutdated(*i) )
|
|
||||||
{
|
|
||||||
Session * ses = &(*i);
|
|
||||||
++i;
|
|
||||||
DeleteSession(ses);
|
|
||||||
++deleted;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( deleted >= deleted_max_at_once )
|
|
||||||
{
|
|
||||||
log << logsave;
|
|
||||||
WaitForSignalSleep(1);
|
|
||||||
deleted = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// it's called from the other thread (with Lock and Unlock)
|
|
||||||
bool SessionManager::IsSessionOutdated(const Session & s) const
|
|
||||||
{
|
|
||||||
bool outdated;
|
|
||||||
|
|
||||||
if( s.remember_me )
|
|
||||||
{
|
|
||||||
outdated = s.last_time < std::time(0) - config->session_remember_max_idle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
outdated = s.last_time < std::time(0) - config->session_max_idle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return outdated;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's called from the other thread (with Lock and Unlock)
|
|
||||||
void SessionManager::DeleteSession(Session * del_session)
|
|
||||||
{
|
|
||||||
if( del_session->puser )
|
|
||||||
{
|
|
||||||
plugin.Call(del_session, WINIX_PREPARE_USER_TO_LOGOUT, del_session->puser);
|
|
||||||
last_container->UserLogout(del_session->puser->id, del_session->id);
|
|
||||||
del_session->puser = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
long id = del_session->id;
|
|
||||||
|
|
||||||
plugin.Call(del_session, WINIX_PREPARE_SESSION_TO_REMOVE);
|
|
||||||
session_tab.EraseById(del_session->id);
|
|
||||||
plugin.Call((Session*)0, WINIX_SESSION_REMOVED, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* end of sessions gc
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_sessionmanager
|
|
||||||
#define headerfile_winix_core_sessionmanager
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
#include "sessioncontainer.h"
|
|
||||||
#include "ipbancontainer.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "request.h"
|
|
||||||
#include "lastcontainer.h"
|
|
||||||
#include "system.h"
|
|
||||||
#include "synchro.h"
|
|
||||||
#include "basethread.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionManager : public BaseThread
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
SessionManager();
|
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
void SetConfig(Config * pconfig);
|
|
||||||
void SetSystem(System * psystem);
|
|
||||||
void SetLastContainer(LastContainer * plast_container);
|
|
||||||
|
|
||||||
|
|
||||||
// can return a null pointer
|
|
||||||
Session * FindSession(long id);
|
|
||||||
|
|
||||||
void SetSession();
|
|
||||||
void DeleteSessions(); // deleting all sessions
|
|
||||||
bool ChangeSessionId(long old_id);
|
|
||||||
|
|
||||||
void InitBanList();
|
|
||||||
void InitTmpSession();
|
|
||||||
void UninitTmpSession();
|
|
||||||
|
|
||||||
Session * GetTmpSession();
|
|
||||||
Session * GetCurSession();
|
|
||||||
|
|
||||||
void LoadSessions();
|
|
||||||
void SaveSessions();
|
|
||||||
|
|
||||||
SessionContainer::Iterator SessionBegin();
|
|
||||||
SessionContainer::Iterator SessionEnd();
|
|
||||||
|
|
||||||
size_t Size();
|
|
||||||
size_t MarkAllSessionsToRemove(long user_id);
|
|
||||||
|
|
||||||
IPBan & AddIPToBanList(int ip);
|
|
||||||
size_t BanListSize();
|
|
||||||
IPBan & GetIPBan(size_t index);
|
|
||||||
void RemoveIPBan(int ip);
|
|
||||||
void ClearIPBanList();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Config * config;
|
|
||||||
Cur * cur;
|
|
||||||
System * system;
|
|
||||||
|
|
||||||
LastContainer * last_container;
|
|
||||||
|
|
||||||
// current session - set by SetSession()
|
|
||||||
Session * session;
|
|
||||||
|
|
||||||
SessionContainer session_tab;
|
|
||||||
IPBanContainer ban_tab;
|
|
||||||
|
|
||||||
IPBan * current_ip_ban;
|
|
||||||
|
|
||||||
// session with id 0
|
|
||||||
Session temporary_session;
|
|
||||||
|
|
||||||
bool IsSession(long s);
|
|
||||||
|
|
||||||
long CreateSessionId();
|
|
||||||
void CreateSession();
|
|
||||||
bool SetSessionFromCookie(const std::wstring & cookie);
|
|
||||||
void SetTemporarySession();
|
|
||||||
|
|
||||||
// second thread
|
|
||||||
int deleted;
|
|
||||||
virtual void Work();
|
|
||||||
void CheckSession(SessionContainer::Iterator & i);
|
|
||||||
bool IsSessionOutdated(const Session & s) const;
|
|
||||||
void DeleteSession(Session * del_session);
|
|
||||||
void CheckWheterIPListIsSorted();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_sessionparser
|
|
||||||
#define headerfile_winix_core_sessionparser
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
#include "session.h"
|
|
||||||
#include "sessioncontainer.h"
|
|
||||||
#include "users.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool Parse(const char * path, SessionContainer & container);
|
|
||||||
bool Parse(const std::string & path, SessionContainer & container);
|
|
||||||
void SetUsers(Users * pusers);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Users * users;
|
|
||||||
|
|
||||||
bool Parse(SessionContainer & container);
|
|
||||||
void MakeSession(long id, long user_id, SessionContainer & container);
|
|
||||||
|
|
||||||
bool IsWhite(int c);
|
|
||||||
bool IsDigit(int c);
|
|
||||||
void SkipWhite();
|
|
||||||
void SkipLine();
|
|
||||||
|
|
||||||
long ReadLong();
|
|
||||||
|
|
||||||
std::ifstream file;
|
|
||||||
int last; // last character
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-231
@@ -1,231 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "slog.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog::SLog()
|
|
||||||
{
|
|
||||||
cur = 0;
|
|
||||||
locale = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SLog::SetCur(Cur * pcur)
|
|
||||||
{
|
|
||||||
cur = pcur;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SLog::SetLocale(Locale * plocale)
|
|
||||||
{
|
|
||||||
locale = plocale;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const void * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const char * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::string * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::string & s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const wchar_t * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::wstring * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::wstring & s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(int s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(long s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(char s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(wchar_t s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(size_t s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(double s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const PT::Date & date)
|
|
||||||
{
|
|
||||||
return PutLog(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(LogManipulators m)
|
|
||||||
{
|
|
||||||
if( cur && cur->session )
|
|
||||||
{
|
|
||||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
|
||||||
|
|
||||||
switch(m)
|
|
||||||
{
|
|
||||||
case logend:
|
|
||||||
buf << '\n';
|
|
||||||
|
|
||||||
if( buf.Size() > WINIX_SLOG_MAX_LOG_SIZE )
|
|
||||||
{
|
|
||||||
buf.Clear();
|
|
||||||
(*this) << logwarning << T("slog_turn_over") << " " << WINIX_SLOG_MAX_LOG_SIZE << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case loginfo:
|
|
||||||
case logwarning:
|
|
||||||
case logerror:
|
|
||||||
buf << (wchar_t)(int)m;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::TranslateText(const char * str)
|
|
||||||
{
|
|
||||||
AssignString(str, key_temp);
|
|
||||||
return TranslateText(key_temp.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::TranslateText(const wchar_t * str)
|
|
||||||
{
|
|
||||||
if( cur && cur->session )
|
|
||||||
{
|
|
||||||
const std::wstring * trans = 0;
|
|
||||||
|
|
||||||
if( locale )
|
|
||||||
trans = &locale->Get(str);
|
|
||||||
|
|
||||||
// !! IMPROVE ME "Not translated" add to locale
|
|
||||||
if( !trans || trans->empty() )
|
|
||||||
cur->session->log_buffer << "Not translated: " << str;
|
|
||||||
else
|
|
||||||
cur->session->log_buffer << trans;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const TranslateTextHelper<const char*> & raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const TranslateTextHelper<const wchar_t*> & raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<const std::string*> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<const std::wstring*> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<std::string> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<std::wstring> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
-150
@@ -1,150 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_slog
|
|
||||||
#define headerfile_winix_core_slog
|
|
||||||
|
|
||||||
#include "cur.h"
|
|
||||||
#include "logmanipulators.h"
|
|
||||||
#include "templates/locale.h"
|
|
||||||
#include "textstream/textstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_SLOG_MAX_LOG_SIZE 10240
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
session logger
|
|
||||||
|
|
||||||
sample:
|
|
||||||
#include "log.h" (or slog.h)
|
|
||||||
slog << logerror << "message" << "something" << logend;
|
|
||||||
slog << logwarning << T("message_to_translate") << x << logend;
|
|
||||||
|
|
||||||
if the latter example "message_to_translate" will be taken from locales
|
|
||||||
currently following manipulators are taken into account:
|
|
||||||
loginfo - the message in a normal info
|
|
||||||
logwarning - this is a warning
|
|
||||||
logerror - this is an error
|
|
||||||
logend - end of a line -- we have one kind of a message (info, warning, error) per line
|
|
||||||
|
|
||||||
loginfo, logwarning, logerror should be specified at the beginning of a line
|
|
||||||
(other manipulators are skipped)
|
|
||||||
*/
|
|
||||||
class SLog
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
SLog();
|
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
void SetLocale(Locale * plocale);
|
|
||||||
|
|
||||||
template<class RawType>
|
|
||||||
struct TranslateTextHelper
|
|
||||||
{
|
|
||||||
const RawType & par;
|
|
||||||
|
|
||||||
TranslateTextHelper(const TranslateTextHelper<RawType> & p) : par(p.par) {}
|
|
||||||
TranslateTextHelper(const RawType & p) : par(p) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
SLog & operator<<(const void * s);
|
|
||||||
SLog & operator<<(const char * s);
|
|
||||||
SLog & operator<<(const std::string * s);
|
|
||||||
SLog & operator<<(const std::string & s);
|
|
||||||
SLog & operator<<(const wchar_t * s);
|
|
||||||
SLog & operator<<(const std::wstring * s);
|
|
||||||
SLog & operator<<(const std::wstring & s);
|
|
||||||
SLog & operator<<(int s);
|
|
||||||
SLog & operator<<(long s);
|
|
||||||
SLog & operator<<(char s);
|
|
||||||
SLog & operator<<(wchar_t s);
|
|
||||||
SLog & operator<<(size_t s);
|
|
||||||
SLog & operator<<(double s);
|
|
||||||
SLog & operator<<(LogManipulators m);
|
|
||||||
SLog & operator<<(const PT::Date & date);
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
||||||
SLog & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
|
||||||
|
|
||||||
|
|
||||||
SLog & TranslateText(const char * str);
|
|
||||||
SLog & TranslateText(const wchar_t * str);
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const char [str_size]> & raw) { return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const char*> & raw);
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const wchar_t*> & raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<const std::string*> raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<const std::wstring*> raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<std::string> raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<std::wstring> raw);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
template<class LogParam>
|
|
||||||
SLog & PutLog(const LogParam & par);
|
|
||||||
|
|
||||||
Cur * cur;
|
|
||||||
Locale * locale;
|
|
||||||
std::wstring key_temp;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<class RawType>
|
|
||||||
SLog::TranslateTextHelper<RawType> T(const RawType & par)
|
|
||||||
{
|
|
||||||
return SLog::TranslateTextHelper<RawType>(par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
||||||
SLog & SLog::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
|
||||||
{
|
|
||||||
return PutLog(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class LogParam>
|
|
||||||
SLog & SLog::PutLog(const LogParam & par)
|
|
||||||
{
|
|
||||||
if( cur && cur->session )
|
|
||||||
cur->session->log_buffer << par;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern SLog slog;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include "synchro.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Synchro::Synchro() : mutex(PTHREAD_MUTEX_INITIALIZER)
|
|
||||||
{
|
|
||||||
was_stop_signal = false;
|
|
||||||
ref = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Synchro::Lock()
|
|
||||||
{
|
|
||||||
int res = pthread_mutex_lock(&mutex);
|
|
||||||
|
|
||||||
if( res == EDEADLK )
|
|
||||||
{
|
|
||||||
// Lock() method in this thread was called before
|
|
||||||
ref += 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ref = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Synchro::Unlock()
|
|
||||||
{
|
|
||||||
if( ref > 0 )
|
|
||||||
{
|
|
||||||
ref -= 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pthread_mutex_unlock(&mutex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_synchro
|
|
||||||
#define headerfile_winix_core_synchro
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Synchro
|
|
||||||
{
|
|
||||||
// one global mutex
|
|
||||||
pthread_mutex_t mutex;
|
|
||||||
|
|
||||||
|
|
||||||
// true when winix is closing
|
|
||||||
volatile bool was_stop_signal;
|
|
||||||
|
|
||||||
|
|
||||||
Synchro();
|
|
||||||
|
|
||||||
bool Lock();
|
|
||||||
void Unlock();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// deadlock counter
|
|
||||||
// we can call Lock() more than one in the same thread
|
|
||||||
int ref;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,379 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_textstream
|
|
||||||
#define headerfile_winix_core_textstream
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <ctime>
|
|
||||||
#include "misc.h"
|
|
||||||
#include "space/space.h"
|
|
||||||
#include "date/date.h"
|
|
||||||
#include "textstream/textstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
a special class representing a stream buffer
|
|
||||||
similar to std::ostringstream
|
|
||||||
|
|
||||||
StringType can be either std::string or std::wstring
|
|
||||||
this class doesn't use UTF-8 in any kind
|
|
||||||
*/
|
|
||||||
template<class StringType>
|
|
||||||
class TextStream
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef typename StringType::value_type CharType;
|
|
||||||
typedef typename StringType::value_type char_type;
|
|
||||||
|
|
||||||
void Clear();
|
|
||||||
bool Empty() const;
|
|
||||||
size_t Size() const;
|
|
||||||
void Reserve(size_t len);
|
|
||||||
|
|
||||||
const StringType & Str() const;
|
|
||||||
const CharType * CStr() const;
|
|
||||||
|
|
||||||
void Str(const StringType & str);
|
|
||||||
void Str(const StringType && str);
|
|
||||||
|
|
||||||
CharType operator[](size_t index);
|
|
||||||
|
|
||||||
TextStream & operator<<(const char * str);
|
|
||||||
TextStream & operator<<(const std::string * str);
|
|
||||||
TextStream & operator<<(const std::string & str);
|
|
||||||
|
|
||||||
TextStream & operator<<(const wchar_t * str);
|
|
||||||
TextStream & operator<<(const std::wstring * str);
|
|
||||||
TextStream & operator<<(const std::wstring & str);
|
|
||||||
|
|
||||||
TextStream & operator<<(char);
|
|
||||||
TextStream & operator<<(wchar_t);
|
|
||||||
TextStream & operator<<(int);
|
|
||||||
TextStream & operator<<(long);
|
|
||||||
TextStream & operator<<(unsigned int);
|
|
||||||
TextStream & operator<<(unsigned long);
|
|
||||||
TextStream & operator<<(double);
|
|
||||||
TextStream & operator<<(const void *);// printing a pointer
|
|
||||||
TextStream & operator<<(const PT::Space & space);
|
|
||||||
TextStream & operator<<(const PT::Date & date);
|
|
||||||
|
|
||||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
|
||||||
TextStream & operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
|
||||||
|
|
||||||
TextStream & Write(const char * buf, size_t len);
|
|
||||||
TextStream & Write(const wchar_t * buf, size_t len);
|
|
||||||
TextStream & write(const char * buf, size_t len); // for compatibility with standard library (Ezc uses it)
|
|
||||||
TextStream & write(const wchar_t * buf, size_t len);
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
StringType buffer;
|
|
||||||
std::wstring space_str; // for using with spaces
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Clear()
|
|
||||||
{
|
|
||||||
buffer.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
bool TextStream<StringType>::Empty() const
|
|
||||||
{
|
|
||||||
return buffer.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
size_t TextStream<StringType>::Size() const
|
|
||||||
{
|
|
||||||
return buffer.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Reserve(size_t len)
|
|
||||||
{
|
|
||||||
buffer.reserve(len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
const StringType & TextStream<StringType>::Str() const
|
|
||||||
{
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
const typename TextStream<StringType>::CharType * TextStream<StringType>::CStr() const
|
|
||||||
{
|
|
||||||
return buffer.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Str(const StringType & str)
|
|
||||||
{
|
|
||||||
buffer = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Str(const StringType && str)
|
|
||||||
{
|
|
||||||
buffer = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
typename TextStream<StringType>::CharType TextStream<StringType>::operator[](size_t index)
|
|
||||||
{
|
|
||||||
return buffer[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const char * str)
|
|
||||||
{
|
|
||||||
AssignString(str, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
|
|
||||||
{
|
|
||||||
AssignString(*str, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
|
|
||||||
{
|
|
||||||
AssignString(str, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
|
|
||||||
{
|
|
||||||
AssignString(str, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
|
|
||||||
{
|
|
||||||
AssignString(*str, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
|
|
||||||
{
|
|
||||||
AssignString(str, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(char v)
|
|
||||||
{
|
|
||||||
buffer += v;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
|
|
||||||
{
|
|
||||||
buffer += static_cast<CharType>(v);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(int v)
|
|
||||||
{
|
|
||||||
wchar_t buf[50];
|
|
||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
|
||||||
|
|
||||||
Toa(v, buf, len);
|
|
||||||
AssignString(buf, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(long v)
|
|
||||||
{
|
|
||||||
wchar_t buf[50];
|
|
||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
|
||||||
|
|
||||||
Toa(v, buf, len);
|
|
||||||
AssignString(buf, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned int v)
|
|
||||||
{
|
|
||||||
wchar_t buf[50];
|
|
||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
|
||||||
|
|
||||||
Toa(v, buf, len);
|
|
||||||
AssignString(buf, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(unsigned long v)
|
|
||||||
{
|
|
||||||
wchar_t buf[50];
|
|
||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
|
||||||
|
|
||||||
Toa(v, buf, len);
|
|
||||||
AssignString(buf, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(double v)
|
|
||||||
{
|
|
||||||
char buf[50];
|
|
||||||
|
|
||||||
sprintf(buf, "%f", v);
|
|
||||||
AssignString(buf, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const void * v)
|
|
||||||
{
|
|
||||||
wchar_t buf[50];
|
|
||||||
size_t len = sizeof(buf) / sizeof(wchar_t);
|
|
||||||
|
|
||||||
buf[0] = '0';
|
|
||||||
buf[1] = 'x';
|
|
||||||
|
|
||||||
Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16);
|
|
||||||
AssignString(buf, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
|
|
||||||
{
|
|
||||||
AssignString(buf, len, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::write(const char * buf, size_t len)
|
|
||||||
{
|
|
||||||
return Write(buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::Write(const wchar_t * buf, size_t len)
|
|
||||||
{
|
|
||||||
AssignString(buf, len, buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::write(const wchar_t * buf, size_t len)
|
|
||||||
{
|
|
||||||
return Write(buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Space & space)
|
|
||||||
{
|
|
||||||
space.Serialize(*this, true, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Date & date)
|
|
||||||
{
|
|
||||||
date.Serialize(*this);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(
|
|
||||||
const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
|
|
||||||
{
|
|
||||||
typename PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
|
||||||
|
|
||||||
for(i=arg.begin() ; i != arg.end() ; ++i)
|
|
||||||
buffer += static_cast<char_type>(*i);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
#include "threadmanager.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ThreadManager::ThreadManager()
|
|
||||||
{
|
|
||||||
were_started = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::SetSynchro(Synchro * psynchro)
|
|
||||||
{
|
|
||||||
synchro = psynchro;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Init()
|
|
||||||
{
|
|
||||||
sigset_t set;
|
|
||||||
|
|
||||||
sigemptyset(&set);
|
|
||||||
sigaddset(&set, SIGTERM);
|
|
||||||
sigaddset(&set, SIGINT);
|
|
||||||
|
|
||||||
// blocking SIGTERM and SIGINT
|
|
||||||
// new threads will have the signals blocked too
|
|
||||||
pthread_sigmask(SIG_BLOCK, &set, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
|
||||||
{
|
|
||||||
ThreadItem item;
|
|
||||||
|
|
||||||
item.object = pbase;
|
|
||||||
item.name = thread_name;
|
|
||||||
thread_tab.push_back(item);
|
|
||||||
|
|
||||||
if( were_started )
|
|
||||||
Start(thread_tab.size() - 1);
|
|
||||||
else
|
|
||||||
log << log4 << "TM: added a thread to the queue, number: " << (thread_tab.size()-1)
|
|
||||||
<< ", name: " << thread_name << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread & pbase, const wchar_t * thread_name)
|
|
||||||
{
|
|
||||||
Add(&pbase, thread_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread * pbase, const std::wstring & thread_name)
|
|
||||||
{
|
|
||||||
Add(pbase, thread_name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread & pbase, const std::wstring & thread_name)
|
|
||||||
{
|
|
||||||
Add(&pbase, thread_name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::StartAll()
|
|
||||||
{
|
|
||||||
synchro->Lock();
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
|
||||||
Start(i);
|
|
||||||
|
|
||||||
synchro->Unlock();
|
|
||||||
|
|
||||||
were_started = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Start(size_t i)
|
|
||||||
{
|
|
||||||
if( i < thread_tab.size() )
|
|
||||||
{
|
|
||||||
thread_tab[i].object->SetSynchro(synchro);
|
|
||||||
|
|
||||||
if( thread_tab[i].object->StartThread() )
|
|
||||||
{
|
|
||||||
log << log4 << "TM: thread " << i << " (" << thread_tab[i].object->ThreadId() << ", name: "
|
|
||||||
<< thread_tab[i].name << ") started" << logend;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log4 << "TM: cannot run a thread, thread number: " << i
|
|
||||||
<< ", name: " << thread_tab[i].name << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::StopAll()
|
|
||||||
{
|
|
||||||
if( !were_started )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// WakeUpThread() should be used with Lock/Unlock
|
|
||||||
synchro->Lock();
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
|
||||||
thread_tab[i].object->WakeUpThread();
|
|
||||||
|
|
||||||
synchro->Unlock();
|
|
||||||
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<thread_tab.size() ; ++i)
|
|
||||||
{
|
|
||||||
log << log4 << "TM: waiting for thread " << i << " (" << thread_tab[i].object->ThreadId()
|
|
||||||
<< ", name: " << thread_tab[i].name << ")" << logend;
|
|
||||||
|
|
||||||
thread_tab[i].object->WaitForThread();
|
|
||||||
|
|
||||||
log << log4 << "TM: thread " << i << " terminated" << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_threadmanager
|
|
||||||
#define headerfile_winix_core_threadmanager
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "basethread.h"
|
|
||||||
#include "synchro.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ThreadManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
ThreadManager();
|
|
||||||
|
|
||||||
// synchro object
|
|
||||||
void SetSynchro(Synchro * psynchro);
|
|
||||||
|
|
||||||
// initializing
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
// adding a new thread to the queue
|
|
||||||
// the thread will be running only if we call StartAll() before
|
|
||||||
// otherwise the thread will be waiting for StartAll()
|
|
||||||
void Add(BaseThread * pbase, const wchar_t * thread_name);
|
|
||||||
void Add(BaseThread & pbase, const wchar_t * thread_name);
|
|
||||||
void Add(BaseThread * pbase, const std::wstring & thread_name);
|
|
||||||
void Add(BaseThread & pbase, const std::wstring & thread_name);
|
|
||||||
|
|
||||||
// starting all threads
|
|
||||||
void StartAll();
|
|
||||||
|
|
||||||
// sending a stop signal to all threads
|
|
||||||
// and waiting until they finish
|
|
||||||
void StopAll();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
struct ThreadItem
|
|
||||||
{
|
|
||||||
BaseThread * object;
|
|
||||||
std::wstring name;
|
|
||||||
};
|
|
||||||
|
|
||||||
Synchro * synchro;
|
|
||||||
typedef std::vector<ThreadItem> ThreadTab;
|
|
||||||
ThreadTab thread_tab;
|
|
||||||
bool were_started;
|
|
||||||
|
|
||||||
void Start(size_t i);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,297 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "timezone.h"
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TimeZone::Dst::Dst()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TimeZone::Dst::Clear()
|
|
||||||
{
|
|
||||||
has_dst = false;
|
|
||||||
start.Clear();
|
|
||||||
end.Clear();
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TimeZone::Dst::IsDstUsed(const PT::Date & date) const
|
|
||||||
{
|
|
||||||
if( !has_dst )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( Compare(start, date) <= 0 ) // !! CHECK ME <= or < ? (what about the one second?)
|
|
||||||
if( Compare(date, end) < 0 )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int TimeZone::Dst::Compare(const PT::Date & date1, const PT::Date & date2) const
|
|
||||||
{
|
|
||||||
// year is ignored
|
|
||||||
|
|
||||||
if( date1.month != date2.month )
|
|
||||||
return date1.month - date2.month;
|
|
||||||
|
|
||||||
if( date1.day != date2.day )
|
|
||||||
return date1.day - date2.day;
|
|
||||||
|
|
||||||
if( date1.hour != date2.hour )
|
|
||||||
return date1.hour - date2.hour;
|
|
||||||
|
|
||||||
if( date1.min != date2.min )
|
|
||||||
return date1.min - date2.min;
|
|
||||||
|
|
||||||
if( date1.sec != date2.sec )
|
|
||||||
return date1.sec - date2.sec;
|
|
||||||
|
|
||||||
// dates are equal
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TimeZone::TimeZone()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void TimeZone::Clear()
|
|
||||||
{
|
|
||||||
name.clear();
|
|
||||||
id = 0;
|
|
||||||
offset = 0;
|
|
||||||
dst_map.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TimeZone::Dst * TimeZone::FindDst(int year)
|
|
||||||
{
|
|
||||||
if( dst_map.empty() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
DstMap::iterator i = dst_map.lower_bound(year);
|
|
||||||
|
|
||||||
if( i == dst_map.begin() && i->first > year )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if( i == dst_map.end() )
|
|
||||||
return &(--i)->second;
|
|
||||||
|
|
||||||
if( i != dst_map.begin() && i->first > year )
|
|
||||||
return &(--i)->second;
|
|
||||||
|
|
||||||
return &i->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
time_t TimeZone::CalcLocalOffset(const PT::Date & utc_date)
|
|
||||||
{
|
|
||||||
time_t dst_offset = 0;
|
|
||||||
|
|
||||||
Dst * dst = FindDst(utc_date.year);
|
|
||||||
|
|
||||||
if( dst && dst->IsDstUsed(utc_date) )
|
|
||||||
dst_offset = dst->offset;
|
|
||||||
|
|
||||||
return offset + dst_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
time_t TimeZone::ToLocal(time_t utc_time)
|
|
||||||
{
|
|
||||||
time_t offset = CalcLocalOffset(PT::Date(utc_time));
|
|
||||||
|
|
||||||
return utc_time + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PT::Date TimeZone::ToLocal(const PT::Date & utc_date)
|
|
||||||
{
|
|
||||||
PT::Date local(utc_date);
|
|
||||||
local += CalcLocalOffset(utc_date);
|
|
||||||
|
|
||||||
return local;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
time_t TimeZone::CalcUTCOffset(const PT::Date & local_date)
|
|
||||||
{
|
|
||||||
time_t dst_offset = 0;
|
|
||||||
|
|
||||||
Dst * dst = FindDst(local_date.year);
|
|
||||||
|
|
||||||
if( dst && dst->has_dst )
|
|
||||||
{
|
|
||||||
// dst date ranges we have in UTC
|
|
||||||
PT::Date utc(local_date);
|
|
||||||
utc -= (offset + dst->offset);
|
|
||||||
|
|
||||||
if( dst->IsDstUsed(utc) )
|
|
||||||
dst_offset = dst->offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
return offset + dst_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
time_t TimeZone::ToUTC(time_t local_time)
|
|
||||||
{
|
|
||||||
time_t offset = CalcUTCOffset(PT::Date(local_time));
|
|
||||||
|
|
||||||
return local_time - offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PT::Date TimeZone::ToUTC(const PT::Date & local_date)
|
|
||||||
{
|
|
||||||
time_t offset;
|
|
||||||
PT::Date utc(local_date);
|
|
||||||
|
|
||||||
offset = CalcUTCOffset(local_date);
|
|
||||||
utc -= offset;
|
|
||||||
|
|
||||||
return utc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
time_t TimeZone::ParseStrOffset(const wchar_t * str)
|
|
||||||
{
|
|
||||||
PT::Date date;
|
|
||||||
bool is_sign = false;
|
|
||||||
time_t offset = 0;
|
|
||||||
|
|
||||||
str = SkipWhite(str);
|
|
||||||
|
|
||||||
if( *str == '-' )
|
|
||||||
{
|
|
||||||
is_sign = true;
|
|
||||||
str += 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( *str == '+' )
|
|
||||||
{
|
|
||||||
str += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( date.ParseTime(str) )
|
|
||||||
{
|
|
||||||
offset = date.hour * 60 * 60 + date.min * 60 + date.sec;
|
|
||||||
|
|
||||||
if( is_sign )
|
|
||||||
offset = -offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
time_t TimeZone::GetOffset(PT::Space & space)
|
|
||||||
{
|
|
||||||
std::wstring * offset_str = space.GetValue(L"offset_str");
|
|
||||||
|
|
||||||
if( offset_str )
|
|
||||||
return ParseStrOffset(offset_str->c_str());
|
|
||||||
|
|
||||||
return space.Long(L"offset");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TimeZone::SetTzDst(PT::Space & year)
|
|
||||||
{
|
|
||||||
time_t h24 = 60 * 60 * 24; // 24 hours
|
|
||||||
bool result = true;
|
|
||||||
Dst dst;
|
|
||||||
|
|
||||||
int year_int = Toi(year.name);
|
|
||||||
|
|
||||||
if( year_int < 1970 && year_int > 10000 )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
dst.has_dst = year.Bool(L"has_dst", false);
|
|
||||||
|
|
||||||
if( dst.has_dst )
|
|
||||||
{
|
|
||||||
dst.start.year = year_int;
|
|
||||||
dst.end.year = year_int;
|
|
||||||
|
|
||||||
if( !dst.start.ParseMonthDayTime(year.Text(L"start")) )
|
|
||||||
result = false;
|
|
||||||
|
|
||||||
if( !dst.end.ParseMonthDayTime(year.Text(L"end")) )
|
|
||||||
result = false;
|
|
||||||
|
|
||||||
dst.offset = GetOffset(year);
|
|
||||||
|
|
||||||
if( dst.offset < -h24 || dst.offset > h24 )
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( result )
|
|
||||||
dst_map[year_int] = dst;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TimeZone::SetTz(PT::Space & space)
|
|
||||||
{
|
|
||||||
bool result = true;
|
|
||||||
name = space.name;
|
|
||||||
id = space.Int(L"id", -1);
|
|
||||||
offset = GetOffset(space);
|
|
||||||
time_t h24 = 60 * 60 * 24; // 24 hours
|
|
||||||
|
|
||||||
if( offset < -h24 || offset > h24 )
|
|
||||||
result = false;
|
|
||||||
|
|
||||||
PT::Space & dst = space.FindAddSpace(L"dst");
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<dst.spaces.size() ; ++i)
|
|
||||||
{
|
|
||||||
PT::Space & year = *dst.spaces[i];
|
|
||||||
|
|
||||||
if( !SetTzDst(year) )
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
-145
@@ -1,145 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_timezone
|
|
||||||
#define headerfile_winix_core_timezone
|
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include <map>
|
|
||||||
#include "date/date.h"
|
|
||||||
#include "space/space.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TimeZone
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
struct Dst
|
|
||||||
{
|
|
||||||
// true if a time zone has daylight saving time
|
|
||||||
bool has_dst;
|
|
||||||
|
|
||||||
// time zone daylight saving time (used if has_dst is true)
|
|
||||||
// the 'year' field is the same in 'start' and 'end'
|
|
||||||
// start and end are represented in UTC time
|
|
||||||
PT::Date start, end;
|
|
||||||
|
|
||||||
// time zone daylight saving time offset
|
|
||||||
// used when has_dst is true and the date is whithin start and end
|
|
||||||
// this offset should be added to time zone offset
|
|
||||||
time_t offset;
|
|
||||||
|
|
||||||
Dst();
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
// checking whether specified 'date' is in the range of <start, end>
|
|
||||||
// the year field in date, start and end is ignored
|
|
||||||
// has_dst must be true
|
|
||||||
bool IsDstUsed(const PT::Date & date) const;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Compare returns zero if date1 and date2 are equal
|
|
||||||
// return value less than zero if date1 is lower than date2
|
|
||||||
// and a value greater than zero if date1 is greater than date2
|
|
||||||
// the year field is ignored
|
|
||||||
int Compare(const PT::Date & date1, const PT::Date & date2) const;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
TimeZone();
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*/
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
reading zime zone values from Space struct (tz_id is skipped)
|
|
||||||
the space struct should have:
|
|
||||||
"tz_offset" (long)
|
|
||||||
"tz_has_dst" (bool)
|
|
||||||
if tz_has_dst is true then also:
|
|
||||||
"tz_dst_start" date in the following format: MM:DD HH[:MM[:SS]]
|
|
||||||
"tz_dst_end" the same as above
|
|
||||||
"tz_dst_offset" (long)
|
|
||||||
*/
|
|
||||||
bool SetTz(PT::Space & space);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
converting from UTC to local time
|
|
||||||
*/
|
|
||||||
time_t CalcLocalOffset(const PT::Date & utc_date);
|
|
||||||
time_t ToLocal(time_t utc_time);
|
|
||||||
PT::Date ToLocal(const PT::Date & utc_date);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
converting from local time to UTC
|
|
||||||
*/
|
|
||||||
time_t CalcUTCOffset(const PT::Date & local_date);
|
|
||||||
time_t ToUTC(time_t local_time);
|
|
||||||
PT::Date ToUTC(const PT::Date & local_date);
|
|
||||||
|
|
||||||
// return a Dst structure for the specified year
|
|
||||||
// or null if it not exists
|
|
||||||
// this method can return a Dst structure for earlier year than 'year'
|
|
||||||
// if 'year' doesn't exist
|
|
||||||
Dst * FindDst(int year);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// a time zone name
|
|
||||||
// this is a key to locale
|
|
||||||
std::wstring name;
|
|
||||||
|
|
||||||
// each locale has its own identifier
|
|
||||||
size_t id;
|
|
||||||
|
|
||||||
// time zone offset (in seconds)
|
|
||||||
time_t offset;
|
|
||||||
|
|
||||||
// daylight saving time map
|
|
||||||
// year -> Dst
|
|
||||||
// if there is not a specified year we are taking the lower year, e.g.
|
|
||||||
// if we are looking for 2010 and there is no such a year then we take 2009
|
|
||||||
// (or 2008 if 2009 not exists etc)
|
|
||||||
typedef std::map<int, Dst> DstMap;
|
|
||||||
DstMap dst_map;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
time_t ParseStrOffset(const wchar_t * str);
|
|
||||||
time_t GetOffset(PT::Space & space);
|
|
||||||
bool SetTzDst(PT::Space & year);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "timezones.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TimeZones::TimeZones()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TimeZones::Clear()
|
|
||||||
{
|
|
||||||
zone_tab.clear();
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<zone_indices.size() ; ++i)
|
|
||||||
zone_indices[i] = size_t(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TimeZones::SetTimeZoneMaxId(size_t max_id)
|
|
||||||
{
|
|
||||||
if( max_id > 1000 )
|
|
||||||
{
|
|
||||||
max_id = 1000;
|
|
||||||
log << log1 << "TZ: time_zone_max_id is too big (changed to 1000)" << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t old_size = zone_indices.size();
|
|
||||||
zone_indices.resize(max_id + 1);
|
|
||||||
|
|
||||||
for(size_t i=old_size ; i<zone_indices.size() ; ++i)
|
|
||||||
zone_indices[i] = size_t(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool TimeZones::HasZone(size_t zone_id)
|
|
||||||
{
|
|
||||||
if( zone_id < zone_indices.size() )
|
|
||||||
return zone_indices[zone_id] < zone_tab.size();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TimeZone * TimeZones::GetZone(size_t zone_id)
|
|
||||||
{
|
|
||||||
if( zone_id < zone_indices.size() )
|
|
||||||
{
|
|
||||||
size_t index = zone_indices[zone_id];
|
|
||||||
|
|
||||||
if( index < zone_tab.size() )
|
|
||||||
return &zone_tab[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TimeZone * TimeZones::GetZoneByIndex(size_t zone_index)
|
|
||||||
{
|
|
||||||
if( zone_index < zone_tab.size() )
|
|
||||||
return &zone_tab[zone_index];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t TimeZones::Size() const
|
|
||||||
{
|
|
||||||
return zone_tab.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TimeZones::Empty() const
|
|
||||||
{
|
|
||||||
return zone_tab.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void TimeZones::ParseZones()
|
|
||||||
{
|
|
||||||
for(size_t i=0 ; i<temp_space.spaces.size() ; ++i)
|
|
||||||
{
|
|
||||||
PT::Space & zone = *temp_space.spaces[i];
|
|
||||||
temp_zone.Clear();
|
|
||||||
|
|
||||||
if( temp_zone.SetTz(zone) )
|
|
||||||
{
|
|
||||||
if( !HasZone(temp_zone.id) )
|
|
||||||
{
|
|
||||||
if( temp_zone.id < zone_indices.size() )
|
|
||||||
{
|
|
||||||
zone_tab.push_back(temp_zone);
|
|
||||||
zone_indices[temp_zone.id] = zone_tab.size() - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Tz: zone: " << temp_zone.name << " has too big id: "
|
|
||||||
<< temp_zone.id << " (skipping)" << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Tz: zone with id: " << temp_zone.id
|
|
||||||
<< " already exists (skipping)" << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "System: problem with reading time zone info from time zone: "
|
|
||||||
<< zone.name << " (skipping) " << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! IMPROVE ME
|
|
||||||
// in the future we do not have to read the whole file
|
|
||||||
// just space by space (not implemented in Space at the moment)
|
|
||||||
bool TimeZones::ReadTimeZones(const wchar_t * path)
|
|
||||||
{
|
|
||||||
parser.UTF8(true);
|
|
||||||
parser.SetSpace(temp_space);
|
|
||||||
zone_tab.clear();
|
|
||||||
temp_space.Clear();
|
|
||||||
|
|
||||||
PT::SpaceParser::Status status = parser.Parse(path);
|
|
||||||
|
|
||||||
if( status == PT::SpaceParser::ok )
|
|
||||||
{
|
|
||||||
ParseZones();
|
|
||||||
log << log2 << "Tz: time zones loaded, there are " << zone_tab.size() << " zones" << logend;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( status == PT::SpaceParser::syntax_error )
|
|
||||||
{
|
|
||||||
log << log1 << "TZ: error in time zone file, line: " << parser.line << logend;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( status == PT::SpaceParser::cant_open_file )
|
|
||||||
{
|
|
||||||
log << log1 << "TZ: I cannot open the time zone file: " << path << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp_space.Clear();
|
|
||||||
|
|
||||||
return status == PT::SpaceParser::ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool TimeZones::ReadTimeZones(const std::wstring & path)
|
|
||||||
{
|
|
||||||
return ReadTimeZones(path.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "user.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
User::User()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void User::Clear()
|
|
||||||
{
|
|
||||||
id = -1;
|
|
||||||
name.clear();
|
|
||||||
super_user = false;
|
|
||||||
groups.clear();
|
|
||||||
email.clear();
|
|
||||||
notify = 0;
|
|
||||||
env.Clear();
|
|
||||||
aenv.Clear();
|
|
||||||
status = WINIX_ACCOUNT_BLOCKED;
|
|
||||||
locale_id = 0;
|
|
||||||
time_zone_id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool User::IsMemberOf(long group)
|
|
||||||
{
|
|
||||||
std::vector<long>::iterator i;
|
|
||||||
|
|
||||||
for(i=groups.begin() ; i!=groups.end() ; ++i)
|
|
||||||
if( *i == group )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
-116
@@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_user
|
|
||||||
#define headerfile_winix_core_user
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "space/space.h"
|
|
||||||
#include "date/date.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_ACCOUNT_MAX_LOGIN_SIZE 250
|
|
||||||
#define WINIX_ACCOUNT_MAX_PASSWORD_SIZE 250
|
|
||||||
#define WINIX_ACCOUNT_MAX_EMAIL_SIZE 250
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// account status
|
|
||||||
// 1 - a user has created its account -- an email was sent back to him
|
|
||||||
#define WINIX_ACCOUNT_NOT_ACTIVATED 1
|
|
||||||
|
|
||||||
// 2 - a user clicked on the link in the mail and now can normally use his account
|
|
||||||
#define WINIX_ACCOUNT_READY 2
|
|
||||||
|
|
||||||
// 3 - account was suspended
|
|
||||||
#define WINIX_ACCOUNT_SUSPENDED 3
|
|
||||||
|
|
||||||
// 4 - account was banned
|
|
||||||
#define WINIX_ACCOUNT_BLOCKED 4
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
a user can login only to an account which status is equal to WINIX_ACCOUNT_READY
|
|
||||||
|
|
||||||
actually there is no difference between WINIX_ACCOUNT_SUSPENDED and WINIX_ACCOUNT_BANNED
|
|
||||||
only a different message will be present on the website
|
|
||||||
|
|
||||||
you can use other values of status in your plugins - this not have any impact on winix
|
|
||||||
the default 'login' winix function only allowes to login a user who has WINIX_ACCOUNT_READY value
|
|
||||||
but you can provide your own 'login' function which can work in a different way
|
|
||||||
|
|
||||||
winix knows that user is login when cur->session->puser pointer is set
|
|
||||||
(when the pointer is not null then winix do not check what the value of 'status' is --
|
|
||||||
the status is only tested in 'login' function)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
a temporary struct used for hashing and encrypting a user's password
|
|
||||||
*/
|
|
||||||
struct UserPass
|
|
||||||
{
|
|
||||||
int pass_type; // the kind of hash (WINIX_CRYPT_HASH_* see crypt.h)
|
|
||||||
std::wstring pass; // password hashed or plain text if pass_type==0
|
|
||||||
std::string pass_encrypted; // password encrypted
|
|
||||||
bool pass_hash_salted; // true when the hash was salted (plain text passwords are never salted)
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct User
|
|
||||||
{
|
|
||||||
long id;
|
|
||||||
std::wstring name;
|
|
||||||
bool super_user;
|
|
||||||
std::vector<long> groups;
|
|
||||||
std::wstring email;
|
|
||||||
int notify;
|
|
||||||
|
|
||||||
|
|
||||||
// environment variables which can be set by this user
|
|
||||||
// use 'env' winix function
|
|
||||||
PT::Space env;
|
|
||||||
|
|
||||||
// environment variables set only by an administrator
|
|
||||||
// an administrator can use 'env' winix function with 'a' parameter
|
|
||||||
PT::Space aenv;
|
|
||||||
|
|
||||||
// account status
|
|
||||||
// WINIX_ACCOUNT_*
|
|
||||||
// a user can normally login only when status is WINIX_ACCOUNT_READY
|
|
||||||
int status;
|
|
||||||
|
|
||||||
// locale identifier
|
|
||||||
size_t locale_id;
|
|
||||||
|
|
||||||
// time zone identifier
|
|
||||||
size_t time_zone_id;
|
|
||||||
|
|
||||||
|
|
||||||
User();
|
|
||||||
|
|
||||||
void Clear();
|
|
||||||
bool IsMemberOf(long group);
|
|
||||||
bool ReadMonthDayTime(PT::Date & date, const wchar_t * str);
|
|
||||||
bool SetTzFromEnv();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-301
@@ -1,301 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include "users.h"
|
|
||||||
#include "sessionmanager.h"
|
|
||||||
#include "plugin.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Users::Users()
|
|
||||||
{
|
|
||||||
how_many_logged = 0; // !! CHECK ME may it should be moved to Clear() method?
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Users::SetCur(Cur * pcur)
|
|
||||||
{
|
|
||||||
cur = pcur;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Users::SetSessionManager(SessionManager * sm)
|
|
||||||
{
|
|
||||||
session_manager = sm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Users::Clear()
|
|
||||||
{
|
|
||||||
table.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Users::ReadUsers(Db * db)
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
db->GetUsers(table);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Users::AddUser(const User & user)
|
|
||||||
{
|
|
||||||
Table::Iterator i = table.PushBack(user);
|
|
||||||
|
|
||||||
return (i != table.End());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Users::IsUser(const std::wstring & name)
|
|
||||||
{
|
|
||||||
return table.Is(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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::wstring & name)
|
|
||||||
{
|
|
||||||
Table::Iterator i = table.FindName(name);
|
|
||||||
|
|
||||||
if( i == table.End() )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return &(*i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long Users::GetUserId(const std::wstring & 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Users::Remove(long user_id)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
User * puser = GetUser(user_id);
|
|
||||||
|
|
||||||
if( puser )
|
|
||||||
{
|
|
||||||
LogoutUser(user_id);
|
|
||||||
plugin.Call(WINIX_PREPARE_TO_REMOVE_USER, puser);
|
|
||||||
result = table.Remove(user_id);
|
|
||||||
|
|
||||||
if( result )
|
|
||||||
plugin.Call(WINIX_USER_REMOVED, user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// private
|
|
||||||
bool Users::LoginUserCheckSession(bool use_ses_log)
|
|
||||||
{
|
|
||||||
if( !cur->session )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( cur->session->id == 0 )
|
|
||||||
{
|
|
||||||
log << log1 << "Users: I cannot login a user on a temporary session" << logend;
|
|
||||||
|
|
||||||
if( use_ses_log )
|
|
||||||
slog << logerror << T(L"service_unavailable") << logend;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// private
|
|
||||||
User * Users::LoginUserCheckStatus(long user_id, bool use_ses_log)
|
|
||||||
{
|
|
||||||
User * puser = GetUser(user_id);
|
|
||||||
|
|
||||||
if( !puser )
|
|
||||||
{
|
|
||||||
log << log1 << "Users: user id: " << user_id << " is not in system.users table" << logend;
|
|
||||||
|
|
||||||
if( use_ses_log )
|
|
||||||
slog << logerror << T(L"service_unavailable") << logend;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( puser->status != WINIX_ACCOUNT_READY )
|
|
||||||
{
|
|
||||||
log << log1 << "Users: user id: " << user_id << " is not ready for logging in (status: "
|
|
||||||
<< puser->status << ")" << logend;
|
|
||||||
|
|
||||||
if( use_ses_log )
|
|
||||||
{
|
|
||||||
if( puser->status == WINIX_ACCOUNT_NOT_ACTIVATED )
|
|
||||||
slog << logerror << T(L"account_not_activated") << logend;
|
|
||||||
else
|
|
||||||
if( puser->status == WINIX_ACCOUNT_SUSPENDED )
|
|
||||||
slog << logerror << T(L"account_suspended") << logend;
|
|
||||||
else
|
|
||||||
if( puser->status == WINIX_ACCOUNT_BLOCKED )
|
|
||||||
slog << logerror << T(L"account_banned") << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return puser;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
|
|
||||||
{
|
|
||||||
if( !LoginUserCheckSession(use_ses_log) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
User * puser = LoginUserCheckStatus(user_id, use_ses_log);
|
|
||||||
|
|
||||||
if( !puser )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
PluginRes res = plugin.Call(WINIX_PREPARE_USER_TO_LOGIN, puser);
|
|
||||||
|
|
||||||
if( res.res_false > 0 )
|
|
||||||
{
|
|
||||||
log << log3 << "Users: login prevented by a plugin" << logend;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( cur->session->puser )
|
|
||||||
LogoutCurrentUser();
|
|
||||||
|
|
||||||
cur->session->puser = puser;
|
|
||||||
cur->session->spam_score = 0;
|
|
||||||
cur->session->remember_me = remember_me;
|
|
||||||
|
|
||||||
// change session id before last.UserLogin()
|
|
||||||
if( !cur->session->new_session )
|
|
||||||
session_manager->ChangeSessionId(cur->session->id);
|
|
||||||
|
|
||||||
last.UserLogin(user_id, cur->session->puser->name, inet_addr(cur->request->env_remote_addr), cur->session->id);
|
|
||||||
how_many_logged += 1;
|
|
||||||
|
|
||||||
log << log2 << "Users: user " << cur->session->puser->name << " (id: " << user_id << ") logged" << logend;
|
|
||||||
plugin.Call(WINIX_USER_LOGGED);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t Users::LogoutUser(long user_id)
|
|
||||||
{
|
|
||||||
size_t how_many = 0;
|
|
||||||
User * puser = GetUser(user_id);
|
|
||||||
|
|
||||||
if( puser )
|
|
||||||
{
|
|
||||||
log << log2 << "Users: logging out user " << puser->name << ", id: "
|
|
||||||
<< puser->id << " from all sessions" << logend;
|
|
||||||
|
|
||||||
// WINIX_PREPARE_USER_TO_LOGOUT will be sent by MarkAllSessionsToRemove()
|
|
||||||
how_many = session_manager->MarkAllSessionsToRemove(user_id);
|
|
||||||
how_many_logged -= how_many;
|
|
||||||
|
|
||||||
if( how_many )
|
|
||||||
log << log3 << "Users: " << how_many << " user(s) were logged out" << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
return how_many;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Users::LogoutCurrentUser()
|
|
||||||
{
|
|
||||||
if( !cur->session || !cur->session->puser )
|
|
||||||
return;
|
|
||||||
|
|
||||||
log << log2 << "Users: user " << cur->session->puser->name << ", id: "
|
|
||||||
<< cur->session->puser->id << " logged out" << logend;
|
|
||||||
|
|
||||||
plugin.Call(WINIX_PREPARE_USER_TO_LOGOUT, cur->session->puser);
|
|
||||||
last.UserLogout(cur->session->puser->id, cur->session->id);
|
|
||||||
|
|
||||||
if( how_many_logged > 0 ) // for safety
|
|
||||||
how_many_logged -= 1;
|
|
||||||
|
|
||||||
cur->session->puser = 0;
|
|
||||||
cur->session->remember_me = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Users::IncrementLoggedUsers()
|
|
||||||
{
|
|
||||||
how_many_logged += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long Users::HowManyLogged()
|
|
||||||
{
|
|
||||||
return how_many_logged;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_users
|
|
||||||
#define headerfile_winix_core_users
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include "user.h"
|
|
||||||
#include "ugcontainer.h"
|
|
||||||
#include "lastcontainer.h"
|
|
||||||
#include "cur.h"
|
|
||||||
#include "db/db.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionManager;
|
|
||||||
|
|
||||||
|
|
||||||
class Users
|
|
||||||
{
|
|
||||||
typedef UGContainer<User> Table;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef Table::Iterator Iterator;
|
|
||||||
typedef Table::SizeType SizeType;
|
|
||||||
|
|
||||||
LastContainer last;
|
|
||||||
|
|
||||||
Users();
|
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
void SetSessionManager(SessionManager * sm);
|
|
||||||
|
|
||||||
void Clear();
|
|
||||||
void ReadUsers(Db * db);
|
|
||||||
bool AddUser(const User & user);
|
|
||||||
bool IsUser(const std::wstring & name);
|
|
||||||
User * GetUser(long user_id);
|
|
||||||
User * GetUser(const std::wstring & name);
|
|
||||||
long GetUserId(const std::wstring & name);
|
|
||||||
Iterator Begin();
|
|
||||||
Iterator End();
|
|
||||||
SizeType Size();
|
|
||||||
bool Remove(long user_id);
|
|
||||||
|
|
||||||
bool LoginUser(long user_id, bool remember_me, bool use_ses_log = false);
|
|
||||||
size_t LogoutUser(long user_id);
|
|
||||||
void LogoutCurrentUser();
|
|
||||||
|
|
||||||
void IncrementLoggedUsers();
|
|
||||||
long HowManyLogged();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Table table;
|
|
||||||
Cur * cur;
|
|
||||||
SessionManager * session_manager;
|
|
||||||
long how_many_logged;
|
|
||||||
|
|
||||||
bool LoginUserCheckSession(bool use_ses_log);
|
|
||||||
User * LoginUserCheckStatus(long user_id, bool use_ses_log);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_version
|
|
||||||
#define headerfile_winix_core_version
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_VER_MAJOR 0
|
|
||||||
#define WINIX_VER_MINOR 6
|
|
||||||
#define WINIX_VER_REVISION 0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
include Makefile.o.dep
|
|
||||||
|
|
||||||
|
|
||||||
all: $(o)
|
|
||||||
|
|
||||||
|
|
||||||
%.o: %.cpp
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) $<
|
|
||||||
|
|
||||||
|
|
||||||
depend:
|
|
||||||
makedepend -Y. $(CXXWINIXINCLUDEFLAGS) -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
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
# DO NOT DELETE
|
|
||||||
|
|
||||||
db.o: db.h dbbase.h dbconn.h dbtextstream.h ../../winix/core/textstream.h
|
|
||||||
db.o: ../../winix/core/misc.h ../../winix/core/item.h
|
|
||||||
db.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
|
||||||
db.o: ../../pikotools/date/date.h ../../winix/core/requesttypes.h
|
|
||||||
db.o: ../../pikotools/textstream/textstream.h
|
|
||||||
db.o: ../../pikotools/convert/convert.h ../../pikotools/convert/inttostr.h
|
|
||||||
db.o: ../../pikotools/membuffer/membuffer.h
|
|
||||||
db.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
|
|
||||||
db.o: ../../winix/core/error.h ../../pikotools/space/spaceparser.h
|
|
||||||
db.o: ../../pikotools/space/space.h dbitemquery.h ../../winix/core/item.h
|
|
||||||
db.o: dbitemcolumns.h ../../winix/core/user.h ../../winix/core/group.h
|
|
||||||
db.o: ../../winix/core/dircontainer.h ../../winix/core/ugcontainer.h
|
|
||||||
db.o: ../../winix/core/log.h ../../winix/core/textstream.h
|
|
||||||
db.o: ../../winix/core/logmanipulators.h ../../winix/core/slog.h
|
|
||||||
db.o: ../../winix/core/cur.h ../../winix/core/request.h
|
|
||||||
db.o: ../../winix/core/error.h ../../winix/core/config.h
|
|
||||||
db.o: ../../winix/core/htmlfilter.h ../../winix/templates/htmltextstream.h
|
|
||||||
db.o: ../../pikotools/space/spacetojson.h ../../winix/core/session.h
|
|
||||||
db.o: ../../winix/core/user.h ../../winix/core/plugindata.h
|
|
||||||
db.o: ../../winix/core/rebus.h ../../winix/core/ipban.h
|
|
||||||
db.o: ../../winix/core/mount.h ../../winix/templates/locale.h
|
|
||||||
db.o: ../../winix/core/log.h ../../winix/core/misc.h
|
|
||||||
dbbase.o: dbbase.h dbconn.h dbtextstream.h ../../winix/core/textstream.h
|
|
||||||
dbbase.o: ../../winix/core/misc.h ../../winix/core/item.h
|
|
||||||
dbbase.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
|
||||||
dbbase.o: ../../pikotools/date/date.h ../../winix/core/requesttypes.h
|
|
||||||
dbbase.o: ../../pikotools/textstream/textstream.h
|
|
||||||
dbbase.o: ../../pikotools/convert/convert.h
|
|
||||||
dbbase.o: ../../pikotools/convert/inttostr.h
|
|
||||||
dbbase.o: ../../pikotools/membuffer/membuffer.h
|
|
||||||
dbbase.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
|
|
||||||
dbbase.o: ../../winix/core/error.h ../../pikotools/space/spaceparser.h
|
|
||||||
dbbase.o: ../../pikotools/space/space.h ../../winix/core/log.h
|
|
||||||
dbbase.o: ../../winix/core/misc.h
|
|
||||||
dbconn.o: dbconn.h dbtextstream.h ../../winix/core/textstream.h
|
|
||||||
dbconn.o: ../../winix/core/misc.h ../../winix/core/item.h
|
|
||||||
dbconn.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
|
||||||
dbconn.o: ../../pikotools/date/date.h ../../winix/core/requesttypes.h
|
|
||||||
dbconn.o: ../../pikotools/textstream/textstream.h
|
|
||||||
dbconn.o: ../../pikotools/convert/convert.h
|
|
||||||
dbconn.o: ../../pikotools/convert/inttostr.h
|
|
||||||
dbconn.o: ../../pikotools/membuffer/membuffer.h
|
|
||||||
dbconn.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
|
|
||||||
dbconn.o: ../../winix/core/log.h ../../winix/core/error.h
|
|
||||||
dbitemcolumns.o: dbitemcolumns.h ../../winix/core/item.h dbbase.h dbconn.h
|
|
||||||
dbitemcolumns.o: dbtextstream.h ../../winix/core/textstream.h
|
|
||||||
dbitemcolumns.o: ../../winix/core/misc.h ../../winix/core/item.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/space/space.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/textstream/types.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/date/date.h ../../winix/core/requesttypes.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/textstream/textstream.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/convert/convert.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/convert/inttostr.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/membuffer/membuffer.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/textstream/types.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/utf8/utf8.h ../../winix/core/error.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/space/spaceparser.h
|
|
||||||
dbitemcolumns.o: ../../pikotools/space/space.h ../../winix/core/log.h
|
|
||||||
dbitemquery.o: dbitemquery.h ../../winix/core/item.h
|
|
||||||
dbtextstream.o: dbtextstream.h ../../winix/core/textstream.h
|
|
||||||
dbtextstream.o: ../../winix/core/misc.h ../../winix/core/item.h
|
|
||||||
dbtextstream.o: ../../pikotools/space/space.h
|
|
||||||
dbtextstream.o: ../../pikotools/textstream/types.h
|
|
||||||
dbtextstream.o: ../../pikotools/date/date.h ../../winix/core/requesttypes.h
|
|
||||||
dbtextstream.o: ../../pikotools/textstream/textstream.h
|
|
||||||
dbtextstream.o: ../../pikotools/convert/convert.h
|
|
||||||
dbtextstream.o: ../../pikotools/convert/inttostr.h
|
|
||||||
dbtextstream.o: ../../pikotools/membuffer/membuffer.h
|
|
||||||
dbtextstream.o: ../../pikotools/textstream/types.h
|
|
||||||
dbtextstream.o: ../../pikotools/utf8/utf8.h
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
o = db.o dbbase.o dbconn.o dbitemcolumns.o dbitemquery.o dbtextstream.o
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_db_db
|
|
||||||
#define headerfile_winix_db_db
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <ctime>
|
|
||||||
#include <cstring>
|
|
||||||
#include "dbbase.h"
|
|
||||||
#include "dbitemquery.h"
|
|
||||||
#include "dbitemcolumns.h"
|
|
||||||
#include "core/item.h"
|
|
||||||
#include "core/user.h"
|
|
||||||
#include "core/group.h"
|
|
||||||
#include "core/dircontainer.h"
|
|
||||||
#include "core/ugcontainer.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Db : public DbBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
// !! przerobic tak aby GetItem zwracalo wszystkie pozycja
|
|
||||||
// !! GetFile tylko dla plikow
|
|
||||||
// !! GetDir tylko dla katalogow
|
|
||||||
// !! GetFile i GetDir beda uzywac GetItem
|
|
||||||
|
|
||||||
Db() : item_cols(*this)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool GetUserPass(const std::wstring & login, long & user_id, UserPass & up);
|
|
||||||
Error AddUser(User & user, const UserPass & up);
|
|
||||||
Error ChangeUserPass(long user_id, const UserPass & up);
|
|
||||||
Error ChangeUserEnv(long user_id, const PT::Space & space);
|
|
||||||
Error ChangeUserAdminEnv(long user_id, const PT::Space & space);
|
|
||||||
Error ChangeUserStatus(long user_id, int status);
|
|
||||||
Error ChangeUserEmail(long user_id, const std::wstring & email);
|
|
||||||
Error ChangeUserLocale(long user_id, size_t locale_id);
|
|
||||||
Error ChangeUserTimeZone(long user_id, size_t time_zone_id);
|
|
||||||
Error RemoveUser(long user_id);
|
|
||||||
|
|
||||||
Error AddItem(Item & item);
|
|
||||||
Error EditItemById(Item & item, bool with_url = true);
|
|
||||||
Error EditItemByUrl(Item & item, bool with_url = true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! nie zwracac zadnych kodow bledow?
|
|
||||||
void GetItems(std::vector<Item> & item_tab, const DbItemQuery & item_query);
|
|
||||||
void GetItems(std::vector<long> & item_tab, const DbItemQuery & item_query);
|
|
||||||
Error GetItem(Item & item, const DbItemQuery & item_query);
|
|
||||||
|
|
||||||
bool GetPriv(Item & item, long id);
|
|
||||||
Error EditPrivById(Item & item, long id); // !! dlaczego tu nie ma const?
|
|
||||||
Error EditParentUrlById(Item & item, long id);
|
|
||||||
Error EditFileById(const Item & item, long id); // file_path, file_fs, file_type
|
|
||||||
Error EditHasThumbById(bool has_thumb, long id);
|
|
||||||
Error EditMetaById(const PT::Space & meta, long id);
|
|
||||||
Error EditAdminMetaById(const PT::Space & meta, long id);
|
|
||||||
|
|
||||||
Error DelDirById(long id);
|
|
||||||
Error DelFileById(long file_id);
|
|
||||||
Error DelSymlinkById(long symlink_id);
|
|
||||||
|
|
||||||
Error EditSubjectById(Item & item, long id);
|
|
||||||
|
|
||||||
|
|
||||||
Error DelItem(const Item & item);
|
|
||||||
void GetDirs(DirContainer & dir_tab);
|
|
||||||
void GetUsers(UGContainer<User> & user_tab);
|
|
||||||
void GetGroups(UGContainer<Group> & group_tab);
|
|
||||||
|
|
||||||
// !! nowy interfejs
|
|
||||||
long Size(long parent_id, Item::Type type = Item::none);
|
|
||||||
|
|
||||||
Error GetItemById(long item_id, Item & item);
|
|
||||||
Error GetItem(long parent_id, const std::wstring & url, Item & item);
|
|
||||||
Error EditLinkItem(long id, const std::wstring & link_to, int link_redirect);
|
|
||||||
Error EditTemplateItemById(long id, const std::wstring & new_html_template);
|
|
||||||
|
|
||||||
long GetItemId(long parent_id, const std::wstring & url, Item::Type type);
|
|
||||||
long GetFileId(long parent_id, const std::wstring & url);
|
|
||||||
long GetDirId(long parent_id, const std::wstring & url);
|
|
||||||
|
|
||||||
Error AddHardLink(Item & item);
|
|
||||||
Error EditSortIndexItemById(long id, int sort_index);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
DbTextStream query, query_create_url;
|
|
||||||
std::wstring temp_url;
|
|
||||||
Item dir_temp;
|
|
||||||
Item get_item_temp;
|
|
||||||
std::wstring iq_id_list;
|
|
||||||
DbItemColumns item_cols;
|
|
||||||
|
|
||||||
|
|
||||||
bool AddItemCreateUrlSubject(Item & item);
|
|
||||||
|
|
||||||
Error AddItemIntoContent(Item & item);
|
|
||||||
Error AddItemIntoItem(Item & item);
|
|
||||||
|
|
||||||
Error EditItemInItem(Item & item, bool with_url);
|
|
||||||
Error EditItemInContent(Item & item);
|
|
||||||
Error EditItemGetIdsByUrl(Item & item);
|
|
||||||
long GetContentId(long item_id);
|
|
||||||
|
|
||||||
|
|
||||||
Error DelItemDelItem(long item_id, int type);
|
|
||||||
Error DelItemDelContent(long content_id);
|
|
||||||
|
|
||||||
Error IncrementContentRef(long content_id);
|
|
||||||
Error DecrementContentRef(long content_id);
|
|
||||||
|
|
||||||
void GetItemsQuerySelect(const DbItemQuery & iq, DbTextStream & query, bool skip_other_sel);
|
|
||||||
void GetItemsQueryJoin(const DbItemQuery & iq, DbTextStream & query);
|
|
||||||
void GetItemsQueryWhere(const DbItemQuery & iq, DbTextStream & query);
|
|
||||||
void GetItemsQueryOrder(const DbItemQuery & iq, DbTextStream & query);
|
|
||||||
void GetItemsQueryLimit(const DbItemQuery & iq, DbTextStream & query);
|
|
||||||
PGresult * GetItemsQuery(const DbItemQuery & iq, DbTextStream & query, bool skip_other_sel = false);
|
|
||||||
PGresult * GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel = false);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-602
@@ -1,602 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <limits>
|
|
||||||
#include "dbbase.h"
|
|
||||||
#include "core/log.h"
|
|
||||||
#include "core/error.h"
|
|
||||||
#include "core/misc.h"
|
|
||||||
#include "utf8/utf8.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbBase::DbBase()
|
|
||||||
{
|
|
||||||
db_conn = 0;
|
|
||||||
log_queries = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::SetConn(DbConn * conn)
|
|
||||||
{
|
|
||||||
db_conn = conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::SetConn(DbConn & conn)
|
|
||||||
{
|
|
||||||
db_conn = &conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbConn * DbBase::GetConn()
|
|
||||||
{
|
|
||||||
return db_conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::LogQueries(bool log_q)
|
|
||||||
{
|
|
||||||
log_queries = log_q;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PGresult * DbBase::AssertQuery(const char * q)
|
|
||||||
{
|
|
||||||
if( log_queries )
|
|
||||||
log << log1 << "Db: executing query: " << q << logend;
|
|
||||||
|
|
||||||
bool bad_query = false;
|
|
||||||
PGresult * r = PQexec(db_conn->GetPgConn(), q);
|
|
||||||
|
|
||||||
if( !r )
|
|
||||||
{
|
|
||||||
bad_query = true;
|
|
||||||
|
|
||||||
if( PQstatus(db_conn->GetPgConn()) != CONNECTION_OK )
|
|
||||||
{
|
|
||||||
db_conn->AssertConnection();
|
|
||||||
r = PQexec(db_conn->GetPgConn(), q);
|
|
||||||
|
|
||||||
if( r )
|
|
||||||
bad_query = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( bad_query )
|
|
||||||
{
|
|
||||||
log << log1 << "Db: Problem with this query: \"" << q << '\"' << logend;
|
|
||||||
log << log1 << "Db: " << PQerrorMessage(db_conn->GetPgConn()) << logend;
|
|
||||||
|
|
||||||
throw Error(WINIX_ERR_DB_INCORRECT_QUERY);
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PGresult * DbBase::AssertQuery(const DbTextStream & query)
|
|
||||||
{
|
|
||||||
return AssertQuery(query.CStr());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PGresult * DbBase::AssertQuery(const char * q, ExecStatusType t)
|
|
||||||
{
|
|
||||||
PGresult * r = AssertQuery(q);
|
|
||||||
AssertResult(r, t);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PGresult * DbBase::AssertQuery(const DbTextStream & query, ExecStatusType t)
|
|
||||||
{
|
|
||||||
return AssertQuery(query.CStr(), t);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::AssertResult(PGresult * r, ExecStatusType t)
|
|
||||||
{
|
|
||||||
if( PQresultStatus(r) != t )
|
|
||||||
{
|
|
||||||
log << log1 << "Db: Incorrect result status: " << PQerrorMessage(db_conn->GetPgConn()) << logend;
|
|
||||||
|
|
||||||
throw Error(WINIX_ERR_DB_INCORRENT_RESULT_STATUS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int DbBase::AssertColumn(PGresult * r, const char * column_name)
|
|
||||||
{
|
|
||||||
int c = PQfnumber(r, column_name);
|
|
||||||
|
|
||||||
if( c == -1 )
|
|
||||||
{
|
|
||||||
log << log1 << "Db: there is no column: " << column_name << logend;
|
|
||||||
throw Error(WINIX_ERR_DB_NO_COLUMN);
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char * DbBase::AssertValue(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
const char * res = PQgetvalue(r, row, col);
|
|
||||||
|
|
||||||
if( !res )
|
|
||||||
{
|
|
||||||
log << log1 << "Db: there is no such an item in the result, row:" << row << ", col:" << col << logend;
|
|
||||||
throw Error(WINIX_ERR_NO_ITEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const std::wstring & DbBase::AssertValueWide(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
const char * res = AssertValue(r, row, col);
|
|
||||||
static std::wstring temp_wide_value; // !! IMPROVE ME add as a class field (nonstatic)
|
|
||||||
|
|
||||||
PT::UTF8ToWide(res, temp_wide_value);
|
|
||||||
|
|
||||||
return temp_wide_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result)
|
|
||||||
{
|
|
||||||
result.clear();
|
|
||||||
|
|
||||||
const char * res = AssertValue(r, row, col);
|
|
||||||
int len = PQgetlength(r, row, col);
|
|
||||||
|
|
||||||
if( len <= 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
UnescapeBin(res, len, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::AssertValueWide(PGresult * r, int row, int col, std::wstring & result)
|
|
||||||
{
|
|
||||||
const char * res = AssertValue(r, row, col);
|
|
||||||
PT::UTF8ToWide(res, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long DbBase::AssertValueLong(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
return strtol( AssertValue(r, row, col), 0, 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int DbBase::AssertValueInt(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
return (int)strtol( AssertValue(r, row, col), 0, 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DbBase::AssertValueBool(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
const char * s = AssertValue(r, row, col);
|
|
||||||
return (s[0]=='t' || s[0]=='y' || s[0]=='1');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long DbBase::AssertValueULong(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
return strtoul( AssertValue(r, row, col), 0, 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int DbBase::AssertValueUInt(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
return (unsigned int)strtoul( AssertValue(r, row, col), 0, 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PT::Date DbBase::AssertValueDate(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
PT::Date date = AssertValue(r, row, col);
|
|
||||||
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DbBase::AssertValueSpace(PGresult * r, int row, int col, PT::Space & space, bool split_single)
|
|
||||||
{
|
|
||||||
const char * res = AssertValue(r, row, col);
|
|
||||||
|
|
||||||
conf_parser.UTF8(true);
|
|
||||||
conf_parser.SplitSingle(split_single);
|
|
||||||
conf_parser.SetSpace(space);
|
|
||||||
space.Clear();
|
|
||||||
|
|
||||||
PT::SpaceParser::Status status = conf_parser.ParseString(res);
|
|
||||||
|
|
||||||
if( status != PT::SpaceParser::ok )
|
|
||||||
{
|
|
||||||
log << log1 << "Db: a problem with parsing a PT::Space";
|
|
||||||
|
|
||||||
if( status == PT::SpaceParser::syntax_error )
|
|
||||||
log << ", syntax error at line: " << conf_parser.line;
|
|
||||||
|
|
||||||
log << logend;
|
|
||||||
|
|
||||||
space.Clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::ClearResult(PGresult * r)
|
|
||||||
{
|
|
||||||
if( r )
|
|
||||||
PQclear(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DbBase::IsNull(PGresult * r, int row, int col)
|
|
||||||
{
|
|
||||||
return PQgetisnull(r, row, col) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int DbBase::Rows(PGresult * r)
|
|
||||||
{
|
|
||||||
// PQntuples - Returns the number of rows (tuples) in the query result. Because it returns
|
|
||||||
// an integer result, large result sets might overflow the return value on 32-bit operating systems.
|
|
||||||
return PQntuples(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int DbBase::Cols(PGresult * r)
|
|
||||||
{
|
|
||||||
// PQnfields - Returns the number of columns (fields) in each row of the query result.
|
|
||||||
return PQnfields(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long DbBase::AffectedRows(PGresult * r)
|
|
||||||
{
|
|
||||||
// PQcmdTuples - This function returns a string containing the number of rows affected by the SQL
|
|
||||||
// statement that generated the PGresult. This function can only be used following the execution
|
|
||||||
// of an INSERT, UPDATE, DELETE, MOVE, FETCH, or COPY statement, or [...]
|
|
||||||
char * rows_str = PQcmdTuples(r); // can be an empty string
|
|
||||||
long rows = 0;
|
|
||||||
|
|
||||||
if( rows_str )
|
|
||||||
{
|
|
||||||
rows = strtol(rows_str, 0, 10);
|
|
||||||
// strtol - If an overflow or underflow occurs, errno is set to ERANGE
|
|
||||||
// and the function return value is clamped according to the following table:
|
|
||||||
// Function underflow overflow
|
|
||||||
// strtol() LONG_MIN LONG_MAX
|
|
||||||
|
|
||||||
if( rows < 0 )
|
|
||||||
rows = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long DbBase::AssertCurrval(const char * table)
|
|
||||||
{
|
|
||||||
PGresult * r;
|
|
||||||
|
|
||||||
bquery.Clear();
|
|
||||||
bquery << R("select currval(")
|
|
||||||
<< table
|
|
||||||
<< R(");");
|
|
||||||
|
|
||||||
r = AssertQuery(bquery);
|
|
||||||
AssertResult(r, PGRES_TUPLES_OK);
|
|
||||||
|
|
||||||
if( Rows(r) != 1 )
|
|
||||||
{
|
|
||||||
log << log1 << "Db: error (currval) for table: " << table << ", " << PQerrorMessage(db_conn->GetPgConn()) << logend;
|
|
||||||
throw Error(WINIX_ERR_DB_ERR_CURRVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return AssertValueLong(r, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::CreateIdList(const std::vector<long> & id_tab, std::wstring & list, bool add_parentheses)
|
|
||||||
{
|
|
||||||
wchar_t buffer[50];
|
|
||||||
size_t buffer_len = sizeof(buffer) / sizeof(wchar_t);
|
|
||||||
|
|
||||||
list.clear();
|
|
||||||
|
|
||||||
if( add_parentheses )
|
|
||||||
list += '(';
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<id_tab.size() ; ++i)
|
|
||||||
{
|
|
||||||
Toa((unsigned long)id_tab[i], buffer, buffer_len);
|
|
||||||
list += buffer;
|
|
||||||
|
|
||||||
if( i+1 < id_tab.size() )
|
|
||||||
list += ',';
|
|
||||||
}
|
|
||||||
|
|
||||||
if( add_parentheses )
|
|
||||||
list += ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error DbBase::DoCommand(const DbTextStream & command)
|
|
||||||
{
|
|
||||||
PGresult * r = 0;
|
|
||||||
Error status = WINIX_ERR_OK;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
r = AssertQuery(command);
|
|
||||||
AssertResult(r, PGRES_COMMAND_OK);
|
|
||||||
}
|
|
||||||
catch(const Error & e)
|
|
||||||
{
|
|
||||||
status = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClearResult(r);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error DbBase::DoCommand(const char * command)
|
|
||||||
{
|
|
||||||
PGresult * r = 0;
|
|
||||||
Error status = WINIX_ERR_OK;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
r = AssertQuery(command);
|
|
||||||
AssertResult(r, PGRES_COMMAND_OK);
|
|
||||||
}
|
|
||||||
catch(const Error & e)
|
|
||||||
{
|
|
||||||
status = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClearResult(r);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error DbBase::BeginTrans()
|
|
||||||
{
|
|
||||||
return DoCommand("BEGIN;");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error DbBase::RollbackTrans()
|
|
||||||
{
|
|
||||||
return DoCommand("ROLLBACK;");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error DbBase::CommitTrans()
|
|
||||||
{
|
|
||||||
return DoCommand("COMMIT;");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool DbBase::EndTrans(bool everything_ok)
|
|
||||||
{
|
|
||||||
bool result;
|
|
||||||
|
|
||||||
if( everything_ok )
|
|
||||||
{
|
|
||||||
result = (CommitTrans() == WINIX_ERR_OK);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RollbackTrans();
|
|
||||||
// we return the old err code
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Error DbBase::EndTrans(Error err)
|
|
||||||
{
|
|
||||||
if( err == WINIX_ERR_OK )
|
|
||||||
{
|
|
||||||
err = CommitTrans();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we return the old err code
|
|
||||||
RollbackTrans();
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
converting from a bytea
|
|
||||||
the old way (escape format)
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
int DbBase::CharToInt(char c)
|
|
||||||
{
|
|
||||||
return (int)(unsigned char)(c-'0');
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DbBase::IsCorrectOctalDigit(char c)
|
|
||||||
{
|
|
||||||
return c>='0' && c<='7';
|
|
||||||
}
|
|
||||||
|
|
||||||
// moves 'i' at least once
|
|
||||||
// return -1 if there is en error
|
|
||||||
int DbBase::UnescapeBin(const char * str, size_t & i, size_t len)
|
|
||||||
{
|
|
||||||
if( str[i] != '\\' )
|
|
||||||
return str[i++];
|
|
||||||
|
|
||||||
i += 1;
|
|
||||||
|
|
||||||
if( i >= len )
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if( str[i] == '\\' )
|
|
||||||
return str[i++];
|
|
||||||
|
|
||||||
if( i+2 >= len )
|
|
||||||
{
|
|
||||||
i = len;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !IsCorrectOctalDigit(str[i]) ||
|
|
||||||
!IsCorrectOctalDigit(str[i+1]) ||
|
|
||||||
!IsCorrectOctalDigit(str[i+2]) )
|
|
||||||
{
|
|
||||||
i += 3;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int c = 8*8*CharToInt(str[i]) + 8*CharToInt(str[i+1]) + CharToInt(str[i+2]);
|
|
||||||
|
|
||||||
i += 3;
|
|
||||||
|
|
||||||
if( c<0 || c>255 )
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DbBase::UnescapeBin(const char * str, size_t len, std::string & out, bool clear_out)
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
if( clear_out )
|
|
||||||
out.clear();
|
|
||||||
|
|
||||||
while( i < len )
|
|
||||||
{
|
|
||||||
c = UnescapeBin(str, i, len);
|
|
||||||
|
|
||||||
if( c != -1 )
|
|
||||||
out += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
converting from a bytea
|
|
||||||
the new way (hex format)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
char DbBase::UnescapeBinHexToDigit(char hex)
|
|
||||||
{
|
|
||||||
if( hex>='0' && hex<='9' )
|
|
||||||
return hex - '0';
|
|
||||||
|
|
||||||
if( hex>='a' && hex<='z' )
|
|
||||||
return hex - 'a' + 10;
|
|
||||||
|
|
||||||
if( hex>='A' && hex<='Z' )
|
|
||||||
return hex - 'A' + 10;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbBase::UnescapeBin(const char * str, size_t len, std::string & out, bool clear_out)
|
|
||||||
{
|
|
||||||
if( clear_out )
|
|
||||||
out.clear();
|
|
||||||
|
|
||||||
if( len < 2 || str[0]!='\\' || str[1]!='x' )
|
|
||||||
{
|
|
||||||
log << log1 << "Db: unsupported binary format (skipping)" << logend;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(size_t i=2 ; i + 1 < len ; i+=2 )
|
|
||||||
{
|
|
||||||
int c1 = UnescapeBinHexToDigit(str[i]);
|
|
||||||
int c2 = UnescapeBinHexToDigit(str[i+1]);
|
|
||||||
|
|
||||||
out += ((c1 << 4) | c2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
end of converting from bytea
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-118
@@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_db_dbbase
|
|
||||||
#define headerfile_winix_db_dbbase
|
|
||||||
|
|
||||||
|
|
||||||
#include "dbconn.h"
|
|
||||||
#include "dbtextstream.h"
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include "core/error.h"
|
|
||||||
#include "space/spaceparser.h"
|
|
||||||
#include "date/date.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DbBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
DbBase();
|
|
||||||
|
|
||||||
void SetConn(DbConn * conn);
|
|
||||||
void SetConn(DbConn & conn);
|
|
||||||
DbConn * GetConn();
|
|
||||||
|
|
||||||
void LogQueries(bool log_q);
|
|
||||||
|
|
||||||
PGresult * AssertQuery(const char * query);
|
|
||||||
PGresult * AssertQuery(const DbTextStream & query);
|
|
||||||
PGresult * AssertQuery(const char * q, ExecStatusType t);
|
|
||||||
PGresult * AssertQuery(const DbTextStream & query, ExecStatusType t);
|
|
||||||
void AssertResult(PGresult * r, ExecStatusType t);
|
|
||||||
static int AssertColumn(PGresult * r, const char * column_name);
|
|
||||||
|
|
||||||
// static assignments
|
|
||||||
static const char * AssertValue(PGresult * r, int row, int col);
|
|
||||||
static const std::wstring & AssertValueWide(PGresult * r, int row, int col); // warning: this method uses a static buffer
|
|
||||||
static void AssertValueWide(PGresult * r, int row, int col, std::wstring & result);
|
|
||||||
static void AssertValueBin(PGresult * r, int row, int col, std::string & result);
|
|
||||||
static long AssertValueLong(PGresult * r, int row, int col);
|
|
||||||
static int AssertValueInt(PGresult * r, int row, int col);
|
|
||||||
static bool AssertValueBool(PGresult * r, int row, int col);
|
|
||||||
static unsigned long AssertValueULong(PGresult * r, int row, int col);
|
|
||||||
static unsigned int AssertValueUInt(PGresult * r, int row, int col);
|
|
||||||
static PT::Date AssertValueDate(PGresult * r, int row, int col);
|
|
||||||
|
|
||||||
// non static assignments
|
|
||||||
bool AssertValueSpace(PGresult * r, int row, int col, PT::Space & space, bool split_single = true);
|
|
||||||
|
|
||||||
void ClearResult(PGresult * r);
|
|
||||||
long AssertCurrval(const char * table);
|
|
||||||
|
|
||||||
bool IsNull(PGresult * r, int row, int col);
|
|
||||||
int Rows(PGresult * r);
|
|
||||||
int Cols(PGresult * r);
|
|
||||||
long AffectedRows(PGresult * r);
|
|
||||||
|
|
||||||
void CreateIdList(const std::vector<long> & id_tab, std::wstring & list, bool add_parentheses = true);
|
|
||||||
|
|
||||||
Error DoCommand(const DbTextStream & command);
|
|
||||||
Error DoCommand(const char * command);
|
|
||||||
Error BeginTrans();
|
|
||||||
Error RollbackTrans();
|
|
||||||
Error CommitTrans();
|
|
||||||
Error EndTrans(Error err);
|
|
||||||
|
|
||||||
// new API (returns only bool)
|
|
||||||
bool EndTrans(bool everything_ok);
|
|
||||||
|
|
||||||
static void UnescapeBin(const char * str, size_t len, std::string & out, bool clear_out = true);
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// a helper method for escaping strings
|
|
||||||
template<class RawType>
|
|
||||||
DbTextStream::RawText<RawType> R(const RawType & par)
|
|
||||||
{
|
|
||||||
return DbTextStream::RawText<RawType>(par);
|
|
||||||
}
|
|
||||||
|
|
||||||
DbConn * db_conn;
|
|
||||||
bool log_queries;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// static int CharToInt(char c);
|
|
||||||
// static bool IsCorrectOctalDigit(char c);
|
|
||||||
// static int UnescapeBin(const char * str, size_t & i, size_t len);
|
|
||||||
|
|
||||||
static char UnescapeBinHexToDigit(char hex);
|
|
||||||
|
|
||||||
DbTextStream bquery;
|
|
||||||
PT::SpaceParser conf_parser;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-161
@@ -1,161 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "dbconn.h"
|
|
||||||
#include "core/log.h"
|
|
||||||
#include "core/error.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbConn::DbConn()
|
|
||||||
{
|
|
||||||
pg_conn = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbConn::~DbConn()
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PGconn * DbConn::GetPgConn()
|
|
||||||
{
|
|
||||||
return pg_conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbConn::SetConnParam(const std::string & d, const std::string & u, const std::string & p)
|
|
||||||
{
|
|
||||||
db_database = d;
|
|
||||||
db_user = u;
|
|
||||||
db_pass = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbConn::Connect()
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
|
|
||||||
conn_info.Clear();
|
|
||||||
conn_info.SetExtented(false);
|
|
||||||
|
|
||||||
conn_info << R("dbname=") << db_database
|
|
||||||
<< R(" user=") << db_user
|
|
||||||
<< R(" password=") << db_pass;
|
|
||||||
|
|
||||||
pg_conn = PQconnectdb(conn_info.CStr());
|
|
||||||
|
|
||||||
// warning! pg_conn can be not null but there cannnot be a connection established
|
|
||||||
// use PQstatus(pg_conn) to check whether the connection works fine
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbConn::LogConnectionSocket()
|
|
||||||
{
|
|
||||||
log << log2 << "Db: connection to the database works fine" << logend;
|
|
||||||
log << log3 << "Db: connection socket: " << PQsocket(pg_conn) << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbConn::WaitForConnection()
|
|
||||||
{
|
|
||||||
if( !pg_conn || PQstatus(pg_conn) != CONNECTION_OK )
|
|
||||||
{
|
|
||||||
log << log3 << "Db: waiting for the db to be ready...." << logend << logsave;
|
|
||||||
|
|
||||||
while( !AssertConnection(false, false) )
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
LogConnectionSocket();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbConn::Close()
|
|
||||||
{
|
|
||||||
if( pg_conn )
|
|
||||||
{
|
|
||||||
PQfinish(pg_conn);
|
|
||||||
pg_conn = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool DbConn::AssertConnection(bool put_log, bool throw_if_no_connection)
|
|
||||||
{
|
|
||||||
bool was_connection = true;
|
|
||||||
|
|
||||||
|
|
||||||
if( !pg_conn )
|
|
||||||
{
|
|
||||||
was_connection = false;
|
|
||||||
Connect();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( PQstatus(pg_conn) != CONNECTION_OK )
|
|
||||||
{
|
|
||||||
if( put_log )
|
|
||||||
log << log2 << "Db: connection to the database is lost, trying to recover" << logend;
|
|
||||||
|
|
||||||
was_connection = false;
|
|
||||||
PQreset(pg_conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( pg_conn && PQstatus(pg_conn) == CONNECTION_OK )
|
|
||||||
{
|
|
||||||
if( !was_connection )
|
|
||||||
{
|
|
||||||
if( put_log )
|
|
||||||
LogConnectionSocket();
|
|
||||||
|
|
||||||
SetDbParameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( put_log )
|
|
||||||
log << log1 << "Db: connection to db server cannot be established" << logend;
|
|
||||||
|
|
||||||
if( throw_if_no_connection )
|
|
||||||
throw Error(WINIX_ERR_DB_FATAL_ERROR_DURING_CONNECTING);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbConn::SetDbParameters()
|
|
||||||
{
|
|
||||||
if( PQsetClientEncoding(pg_conn, "UTF8") == -1 )
|
|
||||||
log << log1 << "Db: Can't set the proper client encoding" << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
-59
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_db_dbconn
|
|
||||||
#define headerfile_winix_db_dbconn
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <libpq-fe.h>
|
|
||||||
#include "dbtextstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DbConn
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
DbConn();
|
|
||||||
~DbConn();
|
|
||||||
|
|
||||||
void SetConnParam(const std::string & database, const std::string & user, const std::string & pass);
|
|
||||||
void Connect();
|
|
||||||
void WaitForConnection();
|
|
||||||
void Close();
|
|
||||||
bool AssertConnection(bool put_log = true, bool throw_if_no_connection = true);
|
|
||||||
void SetDbParameters();
|
|
||||||
PGconn * GetPgConn();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void LogConnectionSocket();
|
|
||||||
|
|
||||||
PGconn * pg_conn;
|
|
||||||
std::string db_database, db_user, db_pass;
|
|
||||||
DbTextStream conn_info;
|
|
||||||
|
|
||||||
// a helper method for escaping strings
|
|
||||||
template<class RawType>
|
|
||||||
DbTextStream::RawText<RawType> R(const RawType & par)
|
|
||||||
{
|
|
||||||
return DbTextStream::RawText<RawType>(par);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "dbitemcolumns.h"
|
|
||||||
#include "dbbase.h"
|
|
||||||
#include "core/log.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemColumns::SetColumns(PGresult * r)
|
|
||||||
{
|
|
||||||
// PQfnumber returns -1 if there is no such a column
|
|
||||||
id = PQfnumber(r, "id");
|
|
||||||
user_id = PQfnumber(r, "user_id");
|
|
||||||
group_id = PQfnumber(r, "group_id");
|
|
||||||
privileges = PQfnumber(r, "privileges");
|
|
||||||
date_creation = PQfnumber(r, "date_creation");
|
|
||||||
date_modification = PQfnumber(r, "date_modification");
|
|
||||||
url = PQfnumber(r, "url");
|
|
||||||
type = PQfnumber(r, "type");
|
|
||||||
parent_id = PQfnumber(r, "parent_id");
|
|
||||||
content_id = PQfnumber(r, "content_id");
|
|
||||||
link_to = PQfnumber(r, "link_to");
|
|
||||||
link_redirect = PQfnumber(r, "link_redirect");
|
|
||||||
subject = PQfnumber(r, "subject");
|
|
||||||
content = PQfnumber(r, "content");
|
|
||||||
content_type = PQfnumber(r, "content_type");
|
|
||||||
guest_name = PQfnumber(r, "guest_name");
|
|
||||||
html_template = PQfnumber(r, "template");
|
|
||||||
modification_user_id = PQfnumber(r, "modification_user_id");
|
|
||||||
file_path = PQfnumber(r, "file_path");
|
|
||||||
file_fs = PQfnumber(r, "file_fs");
|
|
||||||
file_type = PQfnumber(r, "file_type");
|
|
||||||
has_thumb = PQfnumber(r, "has_thumb");
|
|
||||||
hash = PQfnumber(r, "hash");
|
|
||||||
hash_type = PQfnumber(r, "hash_type");
|
|
||||||
file_size = PQfnumber(r, "file_size");
|
|
||||||
ref = PQfnumber(r, "ref");
|
|
||||||
modify_index = PQfnumber(r, "modify_index");
|
|
||||||
sort_index = PQfnumber(r, "sort_index");
|
|
||||||
meta = PQfnumber(r, "meta");
|
|
||||||
ameta = PQfnumber(r, "ameta");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
|
|
||||||
{
|
|
||||||
if( id != -1 ) item.id = DbBase::AssertValueLong(r, row, id);
|
|
||||||
if( user_id != -1 ) item.user_id = DbBase::AssertValueLong(r, row, user_id);
|
|
||||||
if( group_id != -1 ) item.group_id = DbBase::AssertValueLong(r, row, group_id);
|
|
||||||
if( privileges != -1 ) item.privileges = DbBase::AssertValueInt(r, row, privileges);
|
|
||||||
if( date_creation != -1 ) item.date_creation = DbBase::AssertValueDate(r, row, date_creation);
|
|
||||||
if( date_modification != -1 ) item.date_modification = DbBase::AssertValueDate(r, row, date_modification);
|
|
||||||
if( type != -1 ) item.type = static_cast<Item::Type>( DbBase::AssertValueInt(r, row, type) );
|
|
||||||
if( parent_id != -1 ) item.parent_id = DbBase::AssertValueLong(r, row, parent_id);
|
|
||||||
if( content_id != -1 ) item.content_id = DbBase::AssertValueLong(r, row, content_id);
|
|
||||||
if( link_redirect != -1 ) item.link_redirect = DbBase::AssertValueInt(r, row, link_redirect);
|
|
||||||
if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( DbBase::AssertValueInt(r, row, content_type) );
|
|
||||||
if( modification_user_id != -1 ) item.modification_user_id = DbBase::AssertValueLong(r, row, modification_user_id);
|
|
||||||
if( file_fs != -1 ) item.file_fs = DbBase::AssertValueInt(r, row, file_fs);
|
|
||||||
if( file_type != -1 ) item.file_type = DbBase::AssertValueInt(r, row, file_type);
|
|
||||||
if( has_thumb != -1 ) item.has_thumb = DbBase::AssertValueBool(r, row, has_thumb);
|
|
||||||
if( hash != -1 ) DbBase::AssertValueWide(r, row, hash, item.hash);
|
|
||||||
if( hash_type != -1 ) item.hash_type = DbBase::AssertValueInt(r, row, hash_type);
|
|
||||||
if( file_size != -1 ) item.file_size = DbBase::AssertValueLong(r, row, file_size);
|
|
||||||
|
|
||||||
if( ref != -1 ) item.ref = DbBase::AssertValueInt(r, row, ref);
|
|
||||||
if( modify_index != -1 ) item.modify_index = DbBase::AssertValueInt(r, row, modify_index);
|
|
||||||
|
|
||||||
if( url != -1 ) DbBase::AssertValueWide(r, row, url, item.url);
|
|
||||||
if( content != -1 ) DbBase::AssertValueWide(r, row, content, item.content);
|
|
||||||
if( subject != -1 ) DbBase::AssertValueWide(r, row, subject, item.subject);
|
|
||||||
if( file_path != -1 ) DbBase::AssertValueWide(r, row, file_path, item.file_path);
|
|
||||||
if( link_to != -1 ) DbBase::AssertValueWide(r, row, link_to, item.link_to);
|
|
||||||
if( guest_name != -1 ) DbBase::AssertValueWide(r, row, guest_name, item.guest_name);
|
|
||||||
if( html_template != -1 ) DbBase::AssertValueWide(r, row, html_template, item.html_template);
|
|
||||||
if( sort_index != -1 ) item.sort_index = DbBase::AssertValueInt(r, row, sort_index);
|
|
||||||
|
|
||||||
if( meta != -1 ) db_base.AssertValueSpace(r, row, meta, item.meta);
|
|
||||||
if( ameta != -1 ) db_base.AssertValueSpace(r, row, ameta, item.ameta);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_db_dbitemcolumns
|
|
||||||
#define headerfile_winix_db_dbitemcolumns
|
|
||||||
|
|
||||||
#include <libpq-fe.h>
|
|
||||||
#include "core/item.h"
|
|
||||||
#include "dbbase.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct DbItemColumns
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
int user_id;
|
|
||||||
int group_id;
|
|
||||||
int privileges;
|
|
||||||
int date_creation;
|
|
||||||
int date_modification;
|
|
||||||
int url;
|
|
||||||
int type;
|
|
||||||
int parent_id;
|
|
||||||
int content_id;
|
|
||||||
int link_to;
|
|
||||||
int link_redirect;
|
|
||||||
int subject;
|
|
||||||
int content;
|
|
||||||
int content_type;
|
|
||||||
int guest_name;
|
|
||||||
int modification_user_id;
|
|
||||||
int html_template;
|
|
||||||
int file_path;
|
|
||||||
int file_fs;
|
|
||||||
int file_type;
|
|
||||||
int has_thumb;
|
|
||||||
int hash;
|
|
||||||
int hash_type;
|
|
||||||
int file_size;
|
|
||||||
int ref;
|
|
||||||
int modify_index;
|
|
||||||
int sort_index;
|
|
||||||
int meta;
|
|
||||||
int ameta;
|
|
||||||
|
|
||||||
DbItemColumns(DbBase & db_base_) : db_base(db_base_)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetColumns(PGresult * r);
|
|
||||||
void SetItem(PGresult * r, long row, Item & item);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
DbBase & db_base;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "dbitemquery.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbItemQuery::DbItemQuery()
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::Clear()
|
|
||||||
{
|
|
||||||
sort_asc = true;
|
|
||||||
|
|
||||||
SetAll(true, false);
|
|
||||||
|
|
||||||
id = -1;
|
|
||||||
id_tab = 0;
|
|
||||||
parent_id = -1;
|
|
||||||
type = Item::none;
|
|
||||||
file_type = WINIX_ITEM_FILETYPE_NONE;
|
|
||||||
|
|
||||||
type_equal = true;
|
|
||||||
file_type_equal = true;
|
|
||||||
|
|
||||||
limit = 0; // limit and offset not used by default
|
|
||||||
offset = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::SetAllSel(bool sel)
|
|
||||||
{
|
|
||||||
sel_parent_id = sel;
|
|
||||||
sel_user_id = sel;
|
|
||||||
sel_group_id = sel;
|
|
||||||
sel_guest_name = sel;
|
|
||||||
sel_privileges = sel;
|
|
||||||
sel_date = sel;
|
|
||||||
sel_subject = sel;
|
|
||||||
sel_content = sel;
|
|
||||||
sel_url = sel;
|
|
||||||
sel_type = sel;
|
|
||||||
sel_link = sel;
|
|
||||||
sel_file = sel;
|
|
||||||
sel_html_template = sel;
|
|
||||||
sel_sort_index = sel;
|
|
||||||
sel_meta = sel;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::SetAllWhere(bool where_)
|
|
||||||
{
|
|
||||||
where_id = where_;
|
|
||||||
where_parent_id = where_;
|
|
||||||
where_type = where_;
|
|
||||||
where_file_type = where_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::SetAll(bool sel, bool where_)
|
|
||||||
{
|
|
||||||
SetAllSel(sel);
|
|
||||||
SetAllWhere(where_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::WhereId(long id_)
|
|
||||||
{
|
|
||||||
where_id = true;
|
|
||||||
id = id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::WhereIdIn(const std::vector<long> & id_tab_list)
|
|
||||||
{
|
|
||||||
id_tab = &id_tab_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::WhereParentId(long parent_id_)
|
|
||||||
{
|
|
||||||
where_parent_id = true;
|
|
||||||
parent_id = parent_id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::WhereType(Item::Type type_, bool equal)
|
|
||||||
{
|
|
||||||
where_type = true;
|
|
||||||
type = type_;
|
|
||||||
type_equal = equal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::WhereFileType(int file_t, bool equal)
|
|
||||||
{
|
|
||||||
where_file_type = true;
|
|
||||||
file_type = file_t;
|
|
||||||
file_type_equal = equal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::Limit(long l)
|
|
||||||
{
|
|
||||||
limit = l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbItemQuery::Offset(long o)
|
|
||||||
{
|
|
||||||
offset = o;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_db_dbitemquery
|
|
||||||
#define headerfile_winix_db_dbitemquery
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "core/item.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct DbItemQuery
|
|
||||||
{
|
|
||||||
// id and content_id is selected always
|
|
||||||
bool sel_parent_id; // parent_id
|
|
||||||
bool sel_user_id; // user_id, modification_user_id
|
|
||||||
bool sel_group_id; // group_id
|
|
||||||
bool sel_guest_name; // guest_name
|
|
||||||
bool sel_privileges; // privileges
|
|
||||||
bool sel_date; // date_creation, date_modification
|
|
||||||
bool sel_subject; // subject
|
|
||||||
bool sel_content; // content, content_type, ref, modify_index
|
|
||||||
bool sel_url; // url
|
|
||||||
bool sel_type; // type (dir, file, none)
|
|
||||||
bool sel_link; // link_to, link_redirect
|
|
||||||
bool sel_file; // file_path, file_fs, file_type, has_thumb, hash, hash_type, file_size
|
|
||||||
bool sel_html_template; // template
|
|
||||||
bool sel_sort_index; // sort_index
|
|
||||||
bool sel_meta; // meta and ameta (PT::Space)
|
|
||||||
|
|
||||||
bool where_id; //
|
|
||||||
bool where_parent_id; //
|
|
||||||
bool where_type;
|
|
||||||
bool where_file_type;
|
|
||||||
|
|
||||||
long id; // if where_id is true
|
|
||||||
long parent_id; // if where_parent_id is true
|
|
||||||
Item::Type type;
|
|
||||||
bool type_equal;
|
|
||||||
int file_type;
|
|
||||||
bool file_type_equal; // if true means file_type should be equal
|
|
||||||
bool sort_asc;
|
|
||||||
|
|
||||||
const std::vector<long> * id_tab; // != 0 if WhereIdIn was used
|
|
||||||
|
|
||||||
long limit;
|
|
||||||
long offset;
|
|
||||||
|
|
||||||
DbItemQuery();
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
void SetAllSel(bool sel);
|
|
||||||
void SetAllWhere(bool where_);
|
|
||||||
void SetAll(bool sel, bool where_);
|
|
||||||
|
|
||||||
void WhereId(long id_);
|
|
||||||
void WhereIdIn(const std::vector<long> & id_tab_list);
|
|
||||||
void WhereParentId(long parent_id_);
|
|
||||||
void WhereType(Item::Type type_, bool equal = true);
|
|
||||||
void WhereFileType(int file_t, bool equal = true);
|
|
||||||
|
|
||||||
void Limit(long l); // setting 0 turns off
|
|
||||||
void Offset(long o); // setting 0 turns off
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,612 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "dbtextstream.h"
|
|
||||||
#include "utf8/utf8.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream::DbTextStream()
|
|
||||||
{
|
|
||||||
was_param = false;
|
|
||||||
ext_escape = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DbTextStream::SetExtented(bool ext)
|
|
||||||
{
|
|
||||||
ext_escape = ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
without escaping
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::PutText(const char * str)
|
|
||||||
{
|
|
||||||
buffer += str;
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::PutText(const std::string * str)
|
|
||||||
{
|
|
||||||
return PutText(str->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::PutText(const std::string & str)
|
|
||||||
{
|
|
||||||
return PutText(str.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::PutText(const wchar_t * str)
|
|
||||||
{
|
|
||||||
PT::WideToUTF8(str, buffer, false);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::PutText(const std::wstring * str)
|
|
||||||
{
|
|
||||||
return PutText(str->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::PutText(const std::wstring & str)
|
|
||||||
{
|
|
||||||
return PutText(str.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<const char*> raw)
|
|
||||||
{
|
|
||||||
return PutText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<const wchar_t*> raw)
|
|
||||||
{
|
|
||||||
return PutText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<const std::string*> raw)
|
|
||||||
{
|
|
||||||
return PutText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<const std::wstring*> raw)
|
|
||||||
{
|
|
||||||
return PutText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<std::string> raw)
|
|
||||||
{
|
|
||||||
return PutText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<std::wstring> raw)
|
|
||||||
{
|
|
||||||
return PutText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<bool> raw)
|
|
||||||
{
|
|
||||||
if( raw.par )
|
|
||||||
PutText("true");
|
|
||||||
else
|
|
||||||
PutText("false");
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<char> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<wchar_t> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<int> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<long> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<unsigned int> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<unsigned long> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<double> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<void*> raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<PT::Date> date)
|
|
||||||
{
|
|
||||||
tmp_stream.Clear();
|
|
||||||
date.par.Serialize(tmp_stream);
|
|
||||||
AssignString(tmp_stream.CStr(), buffer, false);
|
|
||||||
tmp_stream.Clear();
|
|
||||||
|
|
||||||
was_param = false;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
with escaping
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
old PostgreSQL Escape Format
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
DbTextStream & DbTextStream::EBinPutChar(char c_)
|
|
||||||
{
|
|
||||||
char buf[20];
|
|
||||||
|
|
||||||
int c = (unsigned char)c_;
|
|
||||||
|
|
||||||
if( (c>=0 && c<=31) || c>=127 || c=='\'' || c=='\\' )
|
|
||||||
{
|
|
||||||
sprintf(buf, "\\\\%03o", c);
|
|
||||||
buffer += buf;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// get hex digit for c_ between <0, 15>
|
|
||||||
char DbTextStream::EBinGetHex(char c)
|
|
||||||
{
|
|
||||||
if( c < 10 )
|
|
||||||
return c + '0';
|
|
||||||
|
|
||||||
return c - 10 + 'A';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EBinPutChar(char c)
|
|
||||||
{
|
|
||||||
buffer += EBinGetHex(((unsigned char)c) >> 4);
|
|
||||||
buffer += EBinGetHex(((unsigned char)c) & 0x0f);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::ETextPutChar(char c)
|
|
||||||
{
|
|
||||||
if( c == '\\' )
|
|
||||||
buffer += "\\\\";
|
|
||||||
else
|
|
||||||
if( c == '\'' )
|
|
||||||
buffer += "\\\'"; // don't use "''" because we use the method for PQconnectdb too
|
|
||||||
else
|
|
||||||
if( c != 0 )
|
|
||||||
buffer += c;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::ETextPutChar(wchar_t c)
|
|
||||||
{
|
|
||||||
if( c == '\\' )
|
|
||||||
buffer += "\\\\";
|
|
||||||
else
|
|
||||||
if( c == '\'' )
|
|
||||||
buffer += "\\\'"; // don't use "''" because we use the method for PQconnectdb too
|
|
||||||
else
|
|
||||||
if( c != 0 )
|
|
||||||
PT::IntToUTF8(int(c), buffer, false);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutText(const char * str)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
if( ext_escape )
|
|
||||||
buffer += 'E';
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
|
|
||||||
for( ; *str ; ++str )
|
|
||||||
ETextPutChar(*str);
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutText(const std::string * str)
|
|
||||||
{
|
|
||||||
return EPutText(str->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutText(const std::string & str)
|
|
||||||
{
|
|
||||||
return EPutText(str.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutText(const wchar_t * str)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
if( ext_escape )
|
|
||||||
buffer += 'E';
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
|
|
||||||
for( ; *str ; ++str )
|
|
||||||
ETextPutChar(*str);
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutText(const std::wstring * str)
|
|
||||||
{
|
|
||||||
return EPutText(str->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutText(const std::wstring & str)
|
|
||||||
{
|
|
||||||
return EPutText(str.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// this method can escaped 0 in the middle of the string
|
|
||||||
DbTextStream & DbTextStream::EPutBin(const char * str, size_t len)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
if( ext_escape )
|
|
||||||
buffer += 'E';
|
|
||||||
|
|
||||||
buffer += "\'\\\\x";
|
|
||||||
|
|
||||||
for(size_t i = 0 ; i < len ; ++i)
|
|
||||||
EBinPutChar(str[i]);
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutBin(const std::string * str)
|
|
||||||
{
|
|
||||||
return EPutBin(str->c_str(), str->size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::EPutBin(const std::string & str)
|
|
||||||
{
|
|
||||||
return EPutBin(str.c_str(), str.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const char * str)
|
|
||||||
{
|
|
||||||
return EPutText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const std::string * str)
|
|
||||||
{
|
|
||||||
return EPutText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const std::string & str)
|
|
||||||
{
|
|
||||||
return EPutText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const wchar_t * str)
|
|
||||||
{
|
|
||||||
return EPutText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const std::wstring * str)
|
|
||||||
{
|
|
||||||
return EPutText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const std::wstring & str)
|
|
||||||
{
|
|
||||||
return EPutText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(bool v)
|
|
||||||
{
|
|
||||||
if( v )
|
|
||||||
EPutText("true");
|
|
||||||
else
|
|
||||||
EPutText("false");
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(char v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
if( ext_escape )
|
|
||||||
buffer += 'E';
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
ETextPutChar(v);
|
|
||||||
buffer += '\'';
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(wchar_t v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
if( ext_escape )
|
|
||||||
buffer += 'E';
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
ETextPutChar(v);
|
|
||||||
buffer += '\'';
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(int v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
TextStream<std::string>::operator<<(v);
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(long v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
TextStream<std::string>::operator<<(v);
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(unsigned int v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
TextStream<std::string>::operator<<(v);
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(unsigned long v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
TextStream<std::string>::operator<<(v);
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(double v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
TextStream<std::string>::operator<<(v);
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const void * v)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
buffer += '\''; // !! not needed here?
|
|
||||||
TextStream<std::string>::operator<<(v);
|
|
||||||
buffer += '\'';
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const std::vector<long> & tabid)
|
|
||||||
{
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
buffer += '(';
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<tabid.size(); ++i)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(tabid[i]);
|
|
||||||
|
|
||||||
if( i + 1 < tabid.size() )
|
|
||||||
buffer += ',';
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += ')';
|
|
||||||
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const PT::Space & space)
|
|
||||||
{
|
|
||||||
tmp_stream.Clear();
|
|
||||||
// !! IMPROVE ME
|
|
||||||
// we can calculate how much memory is needed before serializing
|
|
||||||
space.Serialize(tmp_stream, true, false);
|
|
||||||
operator<<(tmp_stream.Str());
|
|
||||||
tmp_stream.Clear();
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream & DbTextStream::operator<<(const PT::Date & date)
|
|
||||||
{
|
|
||||||
tmp_stream.Clear();
|
|
||||||
date.Serialize(tmp_stream);
|
|
||||||
operator<<(tmp_stream.Str());
|
|
||||||
tmp_stream.Clear();
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_db_dbtextstream
|
|
||||||
#define headerfile_winix_db_dbtextstream
|
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include "core/textstream.h"
|
|
||||||
#include "textstream/textstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
DbTextStream is used as a buffer for creating a database's query
|
|
||||||
By default all operators<< escape its string artuments. If you don't want
|
|
||||||
to escape an argument you should use a helper function R() (raw argument)
|
|
||||||
note: you have to define the function yourself, we do not provide it
|
|
||||||
because such a short name would make a mess in namespaces
|
|
||||||
|
|
||||||
sample:
|
|
||||||
create a helper function R as follows:
|
|
||||||
|
|
||||||
template<class RawType>
|
|
||||||
DbTextStream::RawText<RawType> R(const RawType & par)
|
|
||||||
{
|
|
||||||
return DbTextStream::RawText<RawType>(par);
|
|
||||||
}
|
|
||||||
|
|
||||||
now you can use DbTextStream in an easy way:
|
|
||||||
|
|
||||||
DbTextStream query;
|
|
||||||
std::string key = "some string";
|
|
||||||
query << R("select * from table where key=") << key << R(";");
|
|
||||||
|
|
||||||
in above example only the key is escaped.
|
|
||||||
|
|
||||||
Also with escaping operators<< insert commas between parameters, e.g.:
|
|
||||||
|
|
||||||
query << R("insert into table (key1, key2, key3) values (")
|
|
||||||
<< key1
|
|
||||||
<< key2
|
|
||||||
<< key3
|
|
||||||
<< R(");");
|
|
||||||
|
|
||||||
between key1 key2 and key3 are commas inserted automatically
|
|
||||||
*/
|
|
||||||
class DbTextStream : public TextStream<std::string>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
a helper struct to select a proper operator<<
|
|
||||||
(for non-escaping versions of these operators)
|
|
||||||
*/
|
|
||||||
template<class RawType>
|
|
||||||
struct RawText
|
|
||||||
{
|
|
||||||
const RawType & par;
|
|
||||||
|
|
||||||
RawText(const RawText<RawType> & p) : par(p.par) {}
|
|
||||||
RawText(const RawType & p) : par(p) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
DbTextStream();
|
|
||||||
|
|
||||||
// extented escaping: adding E character before the first quote e.g. E'string'
|
|
||||||
// default: true
|
|
||||||
void SetExtented(bool ext);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
without escaping
|
|
||||||
*/
|
|
||||||
|
|
||||||
DbTextStream & PutText(const char *);
|
|
||||||
DbTextStream & PutText(const std::string *);
|
|
||||||
DbTextStream & PutText(const std::string &);
|
|
||||||
DbTextStream & PutText(const wchar_t * str);
|
|
||||||
DbTextStream & PutText(const std::wstring * str);
|
|
||||||
DbTextStream & PutText(const std::wstring & str);
|
|
||||||
|
|
||||||
/*
|
|
||||||
we need this template operator for such calling:
|
|
||||||
dbtextstream_object << R("some string");
|
|
||||||
"some string" is actually a table (not a pointer)
|
|
||||||
*/
|
|
||||||
template<size_t str_size>
|
|
||||||
DbTextStream & operator<<(RawText<char [str_size]> raw) { return PutText(raw.par); }
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
DbTextStream & operator<<(RawText<wchar_t [str_size]> raw) { return PutText(raw.par); }
|
|
||||||
|
|
||||||
DbTextStream & operator<<(RawText<const char*> raw);
|
|
||||||
DbTextStream & operator<<(RawText<const wchar_t*> raw);
|
|
||||||
DbTextStream & operator<<(RawText<const std::string*> raw);
|
|
||||||
DbTextStream & operator<<(RawText<const std::wstring*> raw);
|
|
||||||
DbTextStream & operator<<(RawText<std::string> raw);
|
|
||||||
DbTextStream & operator<<(RawText<std::wstring> raw);
|
|
||||||
DbTextStream & operator<<(RawText<bool> raw);
|
|
||||||
DbTextStream & operator<<(RawText<char> raw);
|
|
||||||
DbTextStream & operator<<(RawText<wchar_t> raw);
|
|
||||||
DbTextStream & operator<<(RawText<int> raw);
|
|
||||||
DbTextStream & operator<<(RawText<long> raw);
|
|
||||||
DbTextStream & operator<<(RawText<unsigned int> raw);
|
|
||||||
DbTextStream & operator<<(RawText<unsigned long> raw);
|
|
||||||
DbTextStream & operator<<(RawText<double> raw);
|
|
||||||
DbTextStream & operator<<(RawText<void*> raw);
|
|
||||||
DbTextStream & operator<<(RawText<PT::Date> date);
|
|
||||||
|
|
||||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
|
||||||
DbTextStream & operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw);
|
|
||||||
|
|
||||||
/*
|
|
||||||
with escaping
|
|
||||||
*/
|
|
||||||
|
|
||||||
DbTextStream & EBinPutChar(char c);
|
|
||||||
DbTextStream & ETextPutChar(char c);
|
|
||||||
DbTextStream & ETextPutChar(wchar_t c);
|
|
||||||
|
|
||||||
DbTextStream & EPutText(const char * str);
|
|
||||||
DbTextStream & EPutText(const std::string * str);
|
|
||||||
DbTextStream & EPutText(const std::string & str);
|
|
||||||
DbTextStream & EPutText(const wchar_t * str);
|
|
||||||
DbTextStream & EPutText(const std::wstring * str);
|
|
||||||
DbTextStream & EPutText(const std::wstring & str);
|
|
||||||
|
|
||||||
DbTextStream & EPutBin(const char * str, size_t len);
|
|
||||||
DbTextStream & EPutBin(const std::string * str);
|
|
||||||
DbTextStream & EPutBin(const std::string & str);
|
|
||||||
|
|
||||||
DbTextStream & operator<<(const char * str);
|
|
||||||
DbTextStream & operator<<(const std::string * str);
|
|
||||||
DbTextStream & operator<<(const std::string & str);
|
|
||||||
DbTextStream & operator<<(const wchar_t * str);
|
|
||||||
DbTextStream & operator<<(const std::wstring * str);
|
|
||||||
DbTextStream & operator<<(const std::wstring & str);
|
|
||||||
DbTextStream & operator<<(bool);
|
|
||||||
DbTextStream & operator<<(char);
|
|
||||||
DbTextStream & operator<<(wchar_t);
|
|
||||||
DbTextStream & operator<<(int);
|
|
||||||
DbTextStream & operator<<(long);
|
|
||||||
DbTextStream & operator<<(unsigned int);
|
|
||||||
DbTextStream & operator<<(unsigned long);
|
|
||||||
DbTextStream & operator<<(double);
|
|
||||||
DbTextStream & operator<<(const void *);
|
|
||||||
DbTextStream & operator<<(const std::vector<long> & tabid);
|
|
||||||
DbTextStream & operator<<(const PT::Space & space);
|
|
||||||
DbTextStream & operator<<(const PT::Date & date);
|
|
||||||
|
|
||||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
|
||||||
DbTextStream & operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool was_param;
|
|
||||||
bool ext_escape;
|
|
||||||
TextStream<std::wstring> tmp_stream;
|
|
||||||
|
|
||||||
char EBinGetHex(char c);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
|
||||||
DbTextStream & DbTextStream::operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw)
|
|
||||||
{
|
|
||||||
TextStream<std::string>::operator<<(raw.par);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
|
||||||
DbTextStream & DbTextStream::operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
|
|
||||||
{
|
|
||||||
typename PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
|
||||||
|
|
||||||
if( was_param )
|
|
||||||
buffer += ", ";
|
|
||||||
|
|
||||||
if( ext_escape )
|
|
||||||
buffer += 'E';
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
|
|
||||||
for(i=arg.begin() ; i != arg.end() ; ++i)
|
|
||||||
ETextPutChar(*i);
|
|
||||||
|
|
||||||
buffer += '\'';
|
|
||||||
was_param = true;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-1700
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
|||||||
include Makefile.o.dep
|
|
||||||
|
|
||||||
|
|
||||||
all: $(o)
|
|
||||||
|
|
||||||
|
|
||||||
%.o: %.cpp
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) $<
|
|
||||||
|
|
||||||
|
|
||||||
depend:
|
|
||||||
makedepend -Y. $(CXXWINIXINCLUDEFLAGS) -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
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
|||||||
o = account.o adduser.o cat.o chmod.o chown.o ckeditor.o cp.o default.o download.o emacs.o env.o functionbase.o functionparser.o functions.o imgcrop.o ipban.o last.o ln.o locale.o login.o logout.o ls.o man.o meta.o mkdir.o mount.o mv.o nicedit.o node.o passwd.o priv.o privchanger.o pw.o reload.o rm.o rmuser.o run.o sort.o specialdefault.o stat.o subject.o template.o timezone.o tinymce.o uname.o upload.o uptime.o vim.o who.o
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "account.h"
|
|
||||||
#include "core/log.h"
|
|
||||||
#include "core/misc.h"
|
|
||||||
#include "functions/functions.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
namespace Fun
|
|
||||||
{
|
|
||||||
|
|
||||||
Account::Account()
|
|
||||||
{
|
|
||||||
fun.url = L"account";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Account::ActivateAccount(User * puser, long code, bool use_ses_log)
|
|
||||||
{
|
|
||||||
std::wstring * user_code_str = puser->aenv.GetValue(L"activation_code");
|
|
||||||
|
|
||||||
if( user_code_str )
|
|
||||||
{
|
|
||||||
if( Tol(*user_code_str) == code )
|
|
||||||
{
|
|
||||||
if( db->ChangeUserStatus(puser->id, WINIX_ACCOUNT_READY) == WINIX_ERR_OK )
|
|
||||||
{
|
|
||||||
puser->aenv.Remove(L"activation_code");
|
|
||||||
db->ChangeUserAdminEnv(puser->id, puser->aenv);
|
|
||||||
puser->status = WINIX_ACCOUNT_READY;
|
|
||||||
|
|
||||||
log << log2 << "Account: account: " << puser->name << " activated" << logend;
|
|
||||||
|
|
||||||
if( use_ses_log )
|
|
||||||
slog << loginfo << T(L"account_activated") << logend;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Account: account not activated -- database error" << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// !! IMPROVE ME if too many errors from the same IP address
|
|
||||||
// add this ip to the banip list
|
|
||||||
|
|
||||||
log << log2 << "Account: incorrect activation code" << logend;
|
|
||||||
|
|
||||||
if( use_ses_log )
|
|
||||||
slog << logerror << T(L"incorrect_activation_code") << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Account: there is no activation_code value in an admin environment" << logend;
|
|
||||||
|
|
||||||
if( use_ses_log )
|
|
||||||
slog << loginfo << T(L"account_cannot_be_activated") << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Account::ActivateAccount(const std::wstring & login, long code, bool use_ses_log)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
User * puser = system->users.GetUser(login);
|
|
||||||
|
|
||||||
if( puser )
|
|
||||||
{
|
|
||||||
if( puser->status == WINIX_ACCOUNT_NOT_ACTIVATED )
|
|
||||||
{
|
|
||||||
result = ActivateAccount(puser, code, use_ses_log);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log2 << "Account: this account is already activated" << logend;
|
|
||||||
|
|
||||||
if( use_ses_log )
|
|
||||||
slog << loginfo << T(L"account_already_activated") << logend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log1 << "Account: there is no a user: " << login << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Account::ActivateAccount()
|
|
||||||
{
|
|
||||||
const std::wstring & login = cur->request->ParamValue(L"login");
|
|
||||||
long code = Tol(cur->request->ParamValue(L"code"));
|
|
||||||
|
|
||||||
if( !login.empty() )
|
|
||||||
{
|
|
||||||
ActivateAccount(login, code, true);
|
|
||||||
system->RedirectToLastItem();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Account::MakePost()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Account::MakeGet()
|
|
||||||
{
|
|
||||||
if( cur->request->IsParam(L"activate") )
|
|
||||||
ActivateAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is not publicly distributed
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_functions_account
|
|
||||||
#define headerfile_winix_functions_account
|
|
||||||
|
|
||||||
#include "functionbase.h"
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
namespace Fun
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
class Account : public FunctionBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
Account();
|
|
||||||
|
|
||||||
void MakeGet();
|
|
||||||
void MakePost();
|
|
||||||
|
|
||||||
bool ActivateAccount(const std::wstring & login, long code, bool use_ses_log = false);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool ActivateAccount(User * puser, long code, bool use_ses_log);
|
|
||||||
void ActivateAccount();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
} // 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