Compare commits
467 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 | |||
| 337f563bd4 | |||
| c9fe09ebe3 | |||
| db1c63a350 | |||
| 7cc2dcd1fc | |||
| bcde392ce3 | |||
| 8d046f6280 | |||
| 9a6696699f | |||
| 56f2eec597 | |||
| d29b33532d | |||
| a16e82bf54 | |||
| 46c17cc441 | |||
| 2099092e16 |
@@ -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
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
.cproject
|
.cproject
|
||||||
.project
|
.project
|
||||||
.settings/
|
.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.
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
|
||||||
|
export CXX
|
||||||
|
export CXXFLAGS
|
||||||
|
export LDFLAGS
|
||||||
|
|
||||||
|
|
||||||
|
all: winixd winixcli
|
||||||
|
|
||||||
|
|
||||||
|
winixd: FORCE
|
||||||
|
$(MAKE) -C winixd
|
||||||
|
|
||||||
|
|
||||||
|
winixcli: FORCE
|
||||||
|
$(MAKE) -C winixcli
|
||||||
|
|
||||||
|
|
||||||
|
clean: FORCE
|
||||||
|
$(MAKE) -C winixd clean
|
||||||
|
$(MAKE) -C winixcli clean
|
||||||
|
|
||||||
|
|
||||||
|
cleanall: FORCE
|
||||||
|
$(MAKE) -C winixd cleanall
|
||||||
|
$(MAKE) -C winixcli clean
|
||||||
|
|
||||||
|
|
||||||
|
depend: FORCE
|
||||||
|
$(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:
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
|
||||||
|
export CXX
|
||||||
|
export CXXFLAGS
|
||||||
|
export LDFLAGS
|
||||||
|
|
||||||
|
|
||||||
|
all: src
|
||||||
|
|
||||||
|
|
||||||
|
src: FORCE
|
||||||
|
$(MAKE) -C src
|
||||||
|
|
||||||
|
|
||||||
|
clean: FORCE
|
||||||
|
$(MAKE) -C src clean
|
||||||
|
|
||||||
|
|
||||||
|
depend: FORCE
|
||||||
|
$(MAKE) -C src depend
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FORCE:
|
||||||
|
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
sourcefiles:=$(shell find . -name "*.cpp")
|
||||||
|
objfiles:=$(patsubst %.cpp,%.o,$(sourcefiles))
|
||||||
|
GLOBAL_WORKING_DIR := $(shell pwd)/../../..
|
||||||
|
|
||||||
|
|
||||||
|
WINIX_NEEDED_MACROS = -DPT_HAS_MORM_LIBRARY \
|
||||||
|
-DEZC_HAS_MORM_LIBRARY \
|
||||||
|
-DMORM_HAS_EZC_LIBRARY
|
||||||
|
|
||||||
|
|
||||||
|
ifndef CXX
|
||||||
|
CXX = g++
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifndef ADDITIONAL_CXXFLAGS
|
||||||
|
ADDITIONAL_CXXFLAGS=-O2
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifndef ADDITIONAL_LDFLAGS
|
||||||
|
ADDITIONAL_LDFLAGS=-s
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifndef CXXFLAGS
|
||||||
|
# /usr/include/postgresql is in Linux distros (Alpine)
|
||||||
|
CXXFLAGS = -Wall -pedantic -std=c++20 $(ADDITIONAL_CXXFLAGS) \
|
||||||
|
-I/usr/local/include \
|
||||||
|
-I/usr/include/postgresql \
|
||||||
|
-I$(GLOBAL_WORKING_DIR)/winix/winixcli \
|
||||||
|
-I$(GLOBAL_WORKING_DIR)/pikotools/src \
|
||||||
|
-I$(GLOBAL_WORKING_DIR)/morm/src \
|
||||||
|
-I$(GLOBAL_WORKING_DIR)/ezc/src \
|
||||||
|
-I$(GLOBAL_WORKING_DIR)/tito/src \
|
||||||
|
$(WINIX_NEEDED_MACROS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
LDFLAGS = -L/usr/local/lib $(ADDITIONAL_LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
export CXX
|
||||||
|
export CXXFLAGS
|
||||||
|
export LDFLAGS
|
||||||
|
export GLOBAL_WORKING_DIR
|
||||||
|
export WINIX_NEEDED_MACROS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
progname = winix
|
||||||
|
|
||||||
|
|
||||||
|
all: $(progname)
|
||||||
|
|
||||||
|
|
||||||
|
$(progname): $(objfiles) pikotools morm ezc
|
||||||
|
$(CXX) -o $(progname) $(CXXFLAGS) $(LDFLAGS) $(objfiles) $(GLOBAL_WORKING_DIR)/ezc/src/ezc.a $(GLOBAL_WORKING_DIR)/morm/src/morm.a $(GLOBAL_WORKING_DIR)/pikotools/src/pikotools.a
|
||||||
|
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: pikotools
|
||||||
|
.PHONY: morm
|
||||||
|
.PHONY: ezc
|
||||||
|
|
||||||
|
|
||||||
|
pikotools:
|
||||||
|
$(MAKE) -C ../../../pikotools
|
||||||
|
|
||||||
|
|
||||||
|
morm:
|
||||||
|
$(MAKE) -C ../../../morm/src
|
||||||
|
|
||||||
|
|
||||||
|
ezc:
|
||||||
|
$(MAKE) -C ../../../ezc/src
|
||||||
|
|
||||||
|
|
||||||
|
clean: FORCE
|
||||||
|
rm -f $(objfiles)
|
||||||
|
rm -f $(progname)
|
||||||
|
|
||||||
|
|
||||||
|
depend:
|
||||||
|
makedepend -w 10 -Y. -I../../../pikotools/src -I../../../morm/src -I../../../ezc/src -I../../../tito/src $(WINIX_NEEDED_MACROS) -f- $(sourcefiles) | sort -u > Makefile.dep
|
||||||
|
|
||||||
|
|
||||||
|
FORCE:
|
||||||
|
|
||||||
|
|
||||||
|
-include Makefile.dep
|
||||||
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
|
||||||
|
./main.o: ../../../ezc/src/blocks.h
|
||||||
|
./main.o: ../../../ezc/src/cache.h
|
||||||
|
./main.o: ../../../ezc/src/expressionparser.h
|
||||||
|
./main.o: ../../../ezc/src/ezc.h
|
||||||
|
./main.o: ../../../ezc/src/functions.h
|
||||||
|
./main.o: ../../../ezc/src/funinfo.h
|
||||||
|
./main.o: ../../../ezc/src/generator.h
|
||||||
|
./main.o: ../../../ezc/src/item.h
|
||||||
|
./main.o: ../../../ezc/src/models.h
|
||||||
|
./main.o: ../../../ezc/src/objects.h
|
||||||
|
./main.o: ../../../ezc/src/outstreams.h
|
||||||
|
./main.o: ../../../ezc/src/pattern.h
|
||||||
|
./main.o: ../../../ezc/src/patternparser.h
|
||||||
|
./main.o: ../../../ezc/src/version.h
|
||||||
|
./main.o: ../../../morm/src/baseexpression.h
|
||||||
|
./main.o: ../../../morm/src/baseobjectwrapper.h
|
||||||
|
./main.o: ../../../morm/src/clearer.h
|
||||||
|
./main.o: ../../../morm/src/cursorhelper.h
|
||||||
|
./main.o: ../../../morm/src/dbconnector.h
|
||||||
|
./main.o: ../../../morm/src/dbexpression.h
|
||||||
|
./main.o: ../../../morm/src/export.h
|
||||||
|
./main.o: ../../../morm/src/fieldvaluehelper.h
|
||||||
|
./main.o: ../../../morm/src/finderhelper.h
|
||||||
|
./main.o: ../../../morm/src/flatconnector.h
|
||||||
|
./main.o: ../../../morm/src/flatexpression.h
|
||||||
|
./main.o: ../../../morm/src/ft.h
|
||||||
|
./main.o: ../../../morm/src/model.h
|
||||||
|
./main.o: ../../../morm/src/modelconnector.h
|
||||||
|
./main.o: ../../../morm/src/modelcontainerwrapper.h
|
||||||
|
./main.o: ../../../morm/src/modeldata.h
|
||||||
|
./main.o: ../../../morm/src/modelenv.h
|
||||||
|
./main.o: ../../../morm/src/morm_types.h
|
||||||
|
./main.o: ../../../morm/src/queryresult.h
|
||||||
|
./main.o: ../../../morm/src/select.h
|
||||||
|
./main.o: ../../../morm/src/spacewrapper.h
|
||||||
|
./main.o: ../../../morm/src/wrapper.h
|
||||||
|
./main.o: ../../../pikotools/src/convert/inttostr.h
|
||||||
|
./main.o: ../../../pikotools/src/convert/misc.h
|
||||||
|
./main.o: ../../../pikotools/src/convert/strtoint.h
|
||||||
|
./main.o: ../../../pikotools/src/convert/text.h
|
||||||
|
./main.o: ../../../pikotools/src/date/date.h
|
||||||
|
./main.o: ../../../pikotools/src/log/filelog.h
|
||||||
|
./main.o: ../../../pikotools/src/log/log.h
|
||||||
|
./main.o: ../../../pikotools/src/mainoptions/mainoptionsparser.h
|
||||||
|
./main.o: ../../../pikotools/src/membuffer/membuffer.h
|
||||||
|
./main.o: ../../../pikotools/src/space/space.h
|
||||||
|
./main.o: ../../../pikotools/src/textstream/stream_private.h
|
||||||
|
./main.o: ../../../pikotools/src/textstream/stream.h
|
||||||
|
./main.o: ../../../pikotools/src/textstream/textstream.h
|
||||||
|
./main.o: ../../../pikotools/src/textstream/types.h
|
||||||
|
./main.o: ../../../pikotools/src/utf8/utf8.h
|
||||||
|
./main.o: misc.h
|
||||||
|
./main.o: pgmodeler.h
|
||||||
|
./misc.o: ../../../pikotools/src/convert/inttostr.h
|
||||||
|
./misc.o: ../../../pikotools/src/convert/misc.h
|
||||||
|
./misc.o: ../../../pikotools/src/space/space.h
|
||||||
|
./misc.o: ../../../pikotools/src/textstream/stream.h
|
||||||
|
./misc.o: ../../../pikotools/src/utf8/utf8.h
|
||||||
|
./misc.o: misc.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/convert/baseparser.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/convert/inttostr.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/convert/misc.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/date/date.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/html/htmlparser.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/membuffer/membuffer.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/space/space.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/textstream/stream_private.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/textstream/stream.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/textstream/textstream.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/textstream/types.h
|
||||||
|
./pgmodeler.o: ../../../pikotools/src/utf8/utf8.h
|
||||||
|
./pgmodeler.o: misc.h
|
||||||
|
./pgmodeler.o: pgmodeler.h
|
||||||
|
# DO NOT DELETE
|
||||||
@@ -0,0 +1,295 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022-2023, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "convert/strtoint.h"
|
||||||
|
#include "mainoptions/mainoptionsparser.h"
|
||||||
|
#include "pgmodeler.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "ezc.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// make a static method in MainOptionsParser?
|
||||||
|
std::wstring get_param(const pt::Space::TableType * input_mode)
|
||||||
|
{
|
||||||
|
if( input_mode && input_mode->size() > 0 )
|
||||||
|
{
|
||||||
|
pt::Space * first_par = (*input_mode)[0];
|
||||||
|
|
||||||
|
if( first_par->is_table() && first_par->table_size() > 0 )
|
||||||
|
{
|
||||||
|
return first_par->value.value_table.front()->to_wstr();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::wstring();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool use_pgmodeler(const std::wstring & input_file, const pt::Space & input_options, pt::Space & schema, bool sort_tables)
|
||||||
|
{
|
||||||
|
PGModeler pgmodeler;
|
||||||
|
return pgmodeler.parse(input_file, schema, sort_tables);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef pt::WTextStream MyStream;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// move me to a better place
|
||||||
|
void esc_tex(wchar_t c, pt::WTextStream & str)
|
||||||
|
{
|
||||||
|
if( c == '$' )
|
||||||
|
str << L"\\$";
|
||||||
|
else
|
||||||
|
if( c == '#' )
|
||||||
|
str << L"\\#";
|
||||||
|
else
|
||||||
|
if( c == '%' )
|
||||||
|
str << L"\\%";
|
||||||
|
else
|
||||||
|
if( c == '&' )
|
||||||
|
str << L"\\&";
|
||||||
|
else
|
||||||
|
if( c == '\\' )
|
||||||
|
str << L"$\\backslash$";
|
||||||
|
else
|
||||||
|
if( c == '{' )
|
||||||
|
str << L"$\\{$";
|
||||||
|
else
|
||||||
|
if( c == '}' )
|
||||||
|
str << L"$\\}$";
|
||||||
|
else
|
||||||
|
if( c == '^' )
|
||||||
|
str << L""; // !! IMPROVE ME add \char with specific code
|
||||||
|
else
|
||||||
|
if( c == '_' )
|
||||||
|
str << L"\\_";
|
||||||
|
else
|
||||||
|
if( c == '~' )
|
||||||
|
str << L""; // !! IMPROVE ME add \char with specific code
|
||||||
|
else
|
||||||
|
if( c == '-' )
|
||||||
|
str << L"{-}";
|
||||||
|
else
|
||||||
|
if( c != 0 )
|
||||||
|
str << c;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void fil_tex(Ezc::FunInfo<MyStream> & env)
|
||||||
|
{
|
||||||
|
auto i = env.in.begin();
|
||||||
|
|
||||||
|
for( ; i != env.in.end() ; ++i)
|
||||||
|
{
|
||||||
|
esc_tex(*i, env.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void fil_max_size(Ezc::FunInfo<MyStream> & env)
|
||||||
|
{
|
||||||
|
auto i = env.in.begin();
|
||||||
|
size_t max_len = pt::to_ul(env.par);
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
for( ; i != env.in.end() ; ++i)
|
||||||
|
{
|
||||||
|
if( len >= max_len )
|
||||||
|
{
|
||||||
|
env.out << ' ';
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( pt::is_white(*i) )
|
||||||
|
{
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
env.out << *i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cmp(Ezc::FunInfo<MyStream> & env)
|
||||||
|
{
|
||||||
|
if( env.params.size() >= 2 )
|
||||||
|
{
|
||||||
|
env.res = true;
|
||||||
|
|
||||||
|
for(size_t a=0 ; a < env.params.size() - 1 ; ++a)
|
||||||
|
{
|
||||||
|
if( env.params[a].str != env.params[a+1].str )
|
||||||
|
{
|
||||||
|
env.res = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool generate(const pt::Space & input_options, pt::Space & schema)
|
||||||
|
{
|
||||||
|
pt::WTextStream log_buffer;
|
||||||
|
pt::FileLog file_log;
|
||||||
|
pt::Log log;
|
||||||
|
|
||||||
|
file_log.init(L"log.txt", true, 4, true);
|
||||||
|
log.set_file_log(&file_log);
|
||||||
|
log.set_log_buffer(&log_buffer);
|
||||||
|
|
||||||
|
Ezc::Pattern pattern;
|
||||||
|
Ezc::PatternParser parser;
|
||||||
|
Ezc::Functions<MyStream> functions;
|
||||||
|
Ezc::Blocks blocks;
|
||||||
|
Ezc::Models models;
|
||||||
|
|
||||||
|
std::wstring dir = get_param(input_options.get_table(L"templates-dir"));
|
||||||
|
std::wstring template_file = get_param(input_options.get_table(L"template"));
|
||||||
|
|
||||||
|
if( dir.empty() )
|
||||||
|
{
|
||||||
|
std::cerr << "you have to set the templates directory with --templates-dir parameter" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( template_file.empty() )
|
||||||
|
{
|
||||||
|
std::cerr << "you have to set the template file name with --template_file parameter" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
functions.Insert("fil_tex", fil_tex);
|
||||||
|
functions.Insert("cmp", cmp);
|
||||||
|
functions.Insert("fil_max_size", fil_max_size);
|
||||||
|
|
||||||
|
parser.Directory(dir);
|
||||||
|
parser.SetBlocks(blocks);
|
||||||
|
parser.SetLogger(&log);
|
||||||
|
parser.ParseFile(template_file, pattern);
|
||||||
|
|
||||||
|
models.Add(L"schema", schema);
|
||||||
|
|
||||||
|
Ezc::Generator<MyStream, true, false> generator;
|
||||||
|
|
||||||
|
generator.SetPattern(pattern);
|
||||||
|
generator.SetFunctions(functions);
|
||||||
|
generator.SetModels(models);
|
||||||
|
|
||||||
|
MyStream str;
|
||||||
|
generator.SetLogger(log);
|
||||||
|
generator.Generate(str);
|
||||||
|
|
||||||
|
std::string tmp;
|
||||||
|
str.to_str(tmp);
|
||||||
|
std::cout << tmp << std::endl;
|
||||||
|
|
||||||
|
log << pt::Log::logsave;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, const char ** argv)
|
||||||
|
{
|
||||||
|
using namespace Winix;
|
||||||
|
|
||||||
|
pt::MainOptionsParser parser;
|
||||||
|
pt::Space input_options, args, schema;
|
||||||
|
|
||||||
|
args.add(L"input-mode", 1);
|
||||||
|
args.add(L"input-file", 1);
|
||||||
|
args.add(L"templates-dir", 1);
|
||||||
|
args.add(L"template", 1);
|
||||||
|
|
||||||
|
pt::MainOptionsParser::Status status = parser.parse(argc, argv, input_options, args);
|
||||||
|
|
||||||
|
std::wstring input_mode = get_param(input_options.get_table(L"input-mode"));
|
||||||
|
std::wstring input_file = get_param(input_options.get_table(L"input-file"));
|
||||||
|
|
||||||
|
if( input_mode.empty() )
|
||||||
|
{
|
||||||
|
std::cout << "you have to use --input-mode parameter" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
print("input-mode", input_mode);
|
||||||
|
print("input-file", input_file);
|
||||||
|
|
||||||
|
bool sort_tables = input_options.has_key(L"sort-tables");
|
||||||
|
|
||||||
|
if( input_mode == L"pgmodeler" )
|
||||||
|
{
|
||||||
|
if( !use_pgmodeler(input_file, input_options, schema, sort_tables) )
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "unknown --input-mode parameter, available are: pgmodeler" << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
generate(input_options, schema);
|
||||||
|
|
||||||
|
|
||||||
|
// for debug purposes
|
||||||
|
// std::string tmp;
|
||||||
|
// tmp = input_options.serialize_to_json_str(true);
|
||||||
|
// std::cout << tmp << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
void print_nonl(const char * msg, const std::wstring & str)
|
||||||
|
{
|
||||||
|
std::string str_utf8;
|
||||||
|
pt::wide_to_utf8(str, str_utf8);
|
||||||
|
std::cerr << msg << ": " << str_utf8;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print(const char * msg, const std::wstring & str)
|
||||||
|
{
|
||||||
|
print_nonl(msg, str);
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print(const char * msg, const std::wstring & str, int val)
|
||||||
|
{
|
||||||
|
print_nonl(msg, str);
|
||||||
|
std::cerr << ":" << val << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winixcli_src_misc
|
||||||
|
#define headerfile_winixcli_src_misc
|
||||||
|
|
||||||
|
#include "space/space.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
void print_nonl(const char * msg, const std::wstring & str);
|
||||||
|
void print(const char * msg, const std::wstring & str);
|
||||||
|
void print(const char * msg, const std::wstring & str, int val);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022-2023, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pgmodeler.h"
|
||||||
|
#include "html/htmlparser.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
PGModeler::PGModeler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PGModeler::~PGModeler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool PGModeler::parse(const std::wstring & input_file, pt::Space & schema, bool sort_tables)
|
||||||
|
{
|
||||||
|
schema.clear();
|
||||||
|
pt::HTMLParser parser;
|
||||||
|
|
||||||
|
pt::HTMLParser::Status status = parser.parse_xml_file(input_file, schema, true, true);
|
||||||
|
|
||||||
|
if( status == pt::HTMLParser::Status::cant_open_file )
|
||||||
|
{
|
||||||
|
print("cannot open the input file", input_file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( status == pt::HTMLParser::Status::syntax_error )
|
||||||
|
{
|
||||||
|
print("syntax error", input_file, parser.get_last_parsed_line());
|
||||||
|
schema.clear();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( sort_tables )
|
||||||
|
make_sort_tables(schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::pair<const std::wstring*, const std::wstring*> PGModeler::get_schema_table_names(const pt::Space & table)
|
||||||
|
{
|
||||||
|
const pt::Space * schema = table.get_space(L"schema");
|
||||||
|
const std::wstring * schema_name = nullptr;
|
||||||
|
const std::wstring * table_name = nullptr;
|
||||||
|
|
||||||
|
if( schema )
|
||||||
|
{
|
||||||
|
const pt::Space * attr = schema->get_space(L"attr");
|
||||||
|
|
||||||
|
if( attr )
|
||||||
|
{
|
||||||
|
schema_name = attr->get_wstr(L"name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const pt::Space * attr = table.get_space(L"attr");
|
||||||
|
|
||||||
|
if( attr )
|
||||||
|
{
|
||||||
|
table_name = attr->get_wstr(L"name");
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_pair(schema_name, table_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PGModeler::make_sort_tables(pt::Space & schema)
|
||||||
|
{
|
||||||
|
pt::Space * dbmodel = schema.get_space(L"dbmodel");
|
||||||
|
|
||||||
|
if( dbmodel )
|
||||||
|
{
|
||||||
|
pt::Space::TableType * table = dbmodel->get_table(L"table");
|
||||||
|
|
||||||
|
if( table )
|
||||||
|
{
|
||||||
|
std::sort(table->begin(), table->end(), [](const pt::Space * t1, const pt::Space * t2) -> bool {
|
||||||
|
auto t1_names = get_schema_table_names(*t1);
|
||||||
|
auto t2_names = get_schema_table_names(*t2);
|
||||||
|
|
||||||
|
if( t1_names.first && t2_names.second && t2_names.first && t2_names.second )
|
||||||
|
{
|
||||||
|
if( *t1_names.first != *t2_names.first )
|
||||||
|
{
|
||||||
|
return *t1_names.first < *t2_names.first;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return *t1_names.second < *t2_names.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022-2023, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winixcli_src_pgmodeler
|
||||||
|
#define headerfile_winixcli_src_pgmodeler
|
||||||
|
|
||||||
|
#include "space/space.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
class PGModeler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
PGModeler();
|
||||||
|
~PGModeler();
|
||||||
|
|
||||||
|
bool parse(const std::wstring & input_file, pt::Space & schema, bool sort_tables);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void make_sort_tables(pt::Space & schema);
|
||||||
|
static std::pair<const std::wstring *, const std::wstring *> get_schema_table_names(const pt::Space & table);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+108
-110
@@ -1,81 +1,86 @@
|
|||||||
# Makefile for GNU make
|
# GNU Makefile
|
||||||
|
|
||||||
include Makefile.dep
|
# sourcefiles: all *.cpp files except ./plugins subdirectory
|
||||||
|
# objfiles: corresponding *.o files
|
||||||
|
sourcefiles:=$(shell find . -name "*.cpp" -not \( -path ./plugins/\* \))
|
||||||
|
objfiles:=$(patsubst %.cpp,%.o,$(sourcefiles))
|
||||||
|
|
||||||
|
# sourcefiles_no_main: all *.cpp files except ./plugins and ./main subdirectories
|
||||||
|
sourcefiles_no_main:=$(shell find . -name "*.cpp" -not \( -path ./plugins/\* \) -not \( -path ./main/\* \))
|
||||||
|
objfiles_no_main:=$(patsubst %.cpp,%.o,$(sourcefiles_no_main))
|
||||||
|
|
||||||
# https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors
|
# sourcefiles_main: all *.cpp files from ./main subdirectory
|
||||||
GLOBAL_WORKING_DIR := $(shell pwd)/../..
|
sourcefiles_main:=$(shell find main -name "*.cpp")
|
||||||
|
objfiles_main:=$(patsubst %.cpp,%.o,$(sourcefiles_main))
|
||||||
|
|
||||||
current_path := $(shell pwd)
|
|
||||||
global_relative_working_dir := $(shell relative_path $(current_path) $(GLOBAL_WORKING_DIR))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(CXX), g++)
|
WINIX_PLUGINS_MAKEDEPEND_INCLUDES = -I../../../../winix/winixd \
|
||||||
CXX = g++6
|
-I../../../../pikotools/src \
|
||||||
endif
|
-I../../../../morm/src \
|
||||||
|
-I../../../../ezc/src \
|
||||||
|
-I../../../../tito/src
|
||||||
|
|
||||||
|
WINIX_NEEDED_MACROS = -DPT_HAS_MORM_LIBRARY \
|
||||||
|
-DEZC_HAS_MORM_LIBRARY \
|
||||||
|
-DMORM_HAS_EZC_LIBRARY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ifndef CXX
|
ifndef CXX
|
||||||
ifeq ($(OSTYPE), FreeBSD)
|
CXX = g++
|
||||||
CXX = clang++
|
|
||||||
else
|
|
||||||
CXX = g++6
|
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
# CXX = g++-4.8
|
|
||||||
|
|
||||||
ifndef CXXFLAGS
|
ifndef CXXFLAGS
|
||||||
CXXFLAGS = -Wall -O0 -g -fPIC -pthread -std=c++17 -I/usr/local/include -I/usr/include/postgresql -DEZC_HAS_SPECIAL_STREAM
|
# /usr/include/postgresql is in Linux distros (Alpine)
|
||||||
|
CXXFLAGS = -Wall -pedantic -O2 -std=c++20 -fPIC -pthread \
|
||||||
|
-I/usr/local/include \
|
||||||
|
-I/usr/include/postgresql \
|
||||||
|
-I../../winix/winixd \
|
||||||
|
-I../../pikotools/src \
|
||||||
|
-I../../morm/src \
|
||||||
|
-I../../ezc/src \
|
||||||
|
-I../../tito/src \
|
||||||
|
$(WINIX_PLUGINS_MAKEDEPEND_INCLUDES) \
|
||||||
|
$(WINIX_NEEDED_MACROS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef AR
|
|
||||||
AR = ar
|
|
||||||
endif
|
|
||||||
|
|
||||||
winix_include_paths = -I$(global_relative_working_dir)/winix/winixd -I$(global_relative_working_dir)/ezc/src -I$(global_relative_working_dir)/tito/src -I$(global_relative_working_dir)/morm/src -I$(global_relative_working_dir)/pikotools
|
|
||||||
|
|
||||||
ifndef LDFLAGS
|
ifndef LDFLAGS
|
||||||
LDFLAGS = -L/usr/local/lib
|
LDFLAGS = -L/usr/local/lib -s
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# for make install
|
# for make install
|
||||||
winix_install_dir = /usr/local/winix
|
ifndef WINIX_INSTALL_DIR
|
||||||
|
WINIX_INSTALL_DIR=/usr/local/winix
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(WINIX_INSTALL_DIR),)
|
||||||
|
$(error WINIX_INSTALL_DIR env variable cannot be empty)
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
export CXX
|
export CXX
|
||||||
export CXXFLAGS
|
export CXXFLAGS
|
||||||
export LDFLAGS
|
export LDFLAGS
|
||||||
export GLOBAL_WORKING_DIR
|
export WINIX_PLUGINS_MAKEDEPEND_INCLUDES
|
||||||
|
export WINIX_NEEDED_MACROS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all: winix winix.so plugins
|
||||||
|
|
||||||
|
|
||||||
all: winix.so plugins winix
|
winix: $(objfiles_main) winix.so
|
||||||
|
$(CXX) -o winix $(CXXFLAGS) $(LDFLAGS) $(objfiles_main) winix.so -lcurl
|
||||||
|
|
||||||
|
|
||||||
|
winix.so: $(objfiles_no_main)
|
||||||
winix.so: $(winix.src.files)
|
@cd ../../pikotools ; $(MAKE) -e
|
||||||
@cd core ; $(MAKE) -e
|
@cd ../../morm ; $(MAKE) -e
|
||||||
@cd db ; $(MAKE) -e
|
@cd ../../ezc ; $(MAKE) -e
|
||||||
@cd functions ; $(MAKE) -e
|
@cd ../../tito ; $(MAKE) -e
|
||||||
@cd notify ; $(MAKE) -e
|
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(objfiles_no_main) ../../pikotools/src/pikotools.a ../../morm/src/morm.a ../../ezc/src/ezc.a ../../tito/src/tito.a $(LDFLAGS) -lfcgi -lpq -lz -lpthread -lmagic -Wl,-no-whole-archive
|
||||||
@cd templates ; $(MAKE) -e
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/ezc/src ; $(MAKE) -e
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/tito/src ; $(MAKE) -e
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/pikotools ; $(MAKE) -e
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/morm/src ; $(MAKE) -e
|
|
||||||
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(winix_include_paths) core/*.o db/*.o functions/*.o templates/*.o notify/*.o $(GLOBAL_WORKING_DIR)/ezc/src/ezc.a $(GLOBAL_WORKING_DIR)/tito/src/tito.a $(GLOBAL_WORKING_DIR)/pikotools/convert/convert.a $(GLOBAL_WORKING_DIR)/pikotools/utf8/utf8.a $(GLOBAL_WORKING_DIR)/pikotools/space/space.a $(GLOBAL_WORKING_DIR)/pikotools/mainparser/mainparser.a $(GLOBAL_WORKING_DIR)/pikotools/date/date.a $(GLOBAL_WORKING_DIR)/pikotools/log/log.a $(GLOBAL_WORKING_DIR)/morm/src/morm.a $(LDFLAGS) -lfcgi -lpq -lz -lpthread -lcurl -Wl,-no-whole-archive
|
|
||||||
|
|
||||||
|
|
||||||
winix: winix.so $(winix.src.files)
|
|
||||||
@cd main ; $(MAKE) -e
|
|
||||||
$(CXX) -o winix $(CXXFLAGS) $(LDFLAGS) main/*.o winix.so -lfcgi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
plugins: FORCE
|
plugins: FORCE
|
||||||
@@ -90,15 +95,17 @@ plugins: FORCE
|
|||||||
@cd plugins/seo ; $(MAKE) -e
|
@cd plugins/seo ; $(MAKE) -e
|
||||||
|
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean: FORCE
|
||||||
@cd core ; $(MAKE) -e clean
|
rm -f $(objfiles)
|
||||||
@cd db ; $(MAKE) -e clean
|
rm -f winix.so
|
||||||
@cd functions ; $(MAKE) -e clean
|
rm -f winix
|
||||||
@cd templates ; $(MAKE) -e clean
|
|
||||||
@cd notify ; $(MAKE) -e clean
|
|
||||||
@cd plugins/stats ; $(MAKE) -e clean
|
@cd plugins/stats ; $(MAKE) -e clean
|
||||||
@cd plugins/thread ; $(MAKE) -e clean
|
@cd plugins/thread ; $(MAKE) -e clean
|
||||||
@cd plugins/ticket ; $(MAKE) -e clean
|
@cd plugins/ticket ; $(MAKE) -e clean
|
||||||
@@ -108,75 +115,66 @@ clean:
|
|||||||
@cd plugins/export ; $(MAKE) -e clean
|
@cd plugins/export ; $(MAKE) -e clean
|
||||||
@cd plugins/mailregister ; $(MAKE) -e clean
|
@cd plugins/mailregister ; $(MAKE) -e clean
|
||||||
@cd plugins/seo ; $(MAKE) -e clean
|
@cd plugins/seo ; $(MAKE) -e clean
|
||||||
@cd $(GLOBAL_WORKING_DIR)/ezc/src ; $(MAKE) -e clean
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/tito/src ; $(MAKE) -e clean
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/pikotools ; $(MAKE) -e clean
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/morm/src ; $(MAKE) -e clean
|
|
||||||
@cd main ; $(MAKE) -e clean
|
|
||||||
rm -f winix.so
|
|
||||||
rm -f winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cleanall: clean
|
||||||
|
@cd ../../pikotools ; $(MAKE) -e clean
|
||||||
|
@cd ../../morm ; $(MAKE) -e clean
|
||||||
|
@cd ../../ezc ; $(MAKE) -e clean
|
||||||
|
@cd ../../tito ; $(MAKE) -e clean
|
||||||
|
|
||||||
|
|
||||||
depend:
|
depend:
|
||||||
@cd core ; $(MAKE) -e depend
|
makedepend -w 10 -Y. -I../../pikotools/src -I../../morm/src -I../../ezc/src -I../../tito/src $(WINIX_NEEDED_MACROS) -f- $(sourcefiles) | sort -u > Makefile.dep
|
||||||
@cd db ; $(MAKE) -e depend
|
@cd plugins/stats ; $(MAKE) -e depend
|
||||||
@cd functions ; $(MAKE) -e depend
|
@cd plugins/thread ; $(MAKE) -e depend
|
||||||
@cd templates ; $(MAKE) -e depend
|
@cd plugins/ticket ; $(MAKE) -e depend
|
||||||
@cd notify ; $(MAKE) -e depend
|
@cd plugins/gallery ; $(MAKE) -e depend
|
||||||
@cd plugins/stats ; $(MAKE) -e depend
|
@cd plugins/group ; $(MAKE) -e depend
|
||||||
@cd plugins/thread ; $(MAKE) -e depend
|
@cd plugins/menu ; $(MAKE) -e depend
|
||||||
@cd plugins/ticket ; $(MAKE) -e depend
|
@cd plugins/export ; $(MAKE) -e depend
|
||||||
@cd plugins/gallery ; $(MAKE) -e depend
|
@cd plugins/mailregister ; $(MAKE) -e depend
|
||||||
@cd plugins/group ; $(MAKE) -e depend
|
@cd plugins/seo ; $(MAKE) -e depend
|
||||||
@cd plugins/menu ; $(MAKE) -e depend
|
@cd ../../pikotools ; $(MAKE) -e depend
|
||||||
@cd plugins/export ; $(MAKE) -e depend
|
@cd ../../morm ; $(MAKE) -e depend
|
||||||
@cd plugins/mailregister ; $(MAKE) -e depend
|
@cd ../../ezc ; $(MAKE) -e depend
|
||||||
@cd plugins/seo ; $(MAKE) -e depend
|
@cd ../../tito ; $(MAKE) -e depend
|
||||||
@cd $(GLOBAL_WORKING_DIR)/ezc/src ; $(MAKE) -e depend
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/tito/src ; $(MAKE) -e depend
|
|
||||||
@cd $(GLOBAL_WORKING_DIR)/pikotools ; $(MAKE) -e depend
|
|
||||||
@cd main ; $(MAKE) -e depend
|
|
||||||
echo -n "winix.src.files = " > Makefile.dep
|
|
||||||
find -E . -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
# use $(global_relative_working_dir) here to put relative paths to Makefile.dep
|
|
||||||
find -E $(global_relative_working_dir)/ezc/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
find -E $(global_relative_working_dir)/tito/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
find -E $(global_relative_working_dir)/pikotools -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
find -E $(global_relative_working_dir)/morm/src -type f -regex ".*\.h|.*\.cpp" | xargs -I foo echo -n foo " " >> Makefile.dep
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
# installing binaries
|
# installing the main binary
|
||||||
rm -Rf $(winix_install_dir)/bin
|
rm -Rf $(WINIX_INSTALL_DIR)/bin
|
||||||
mkdir -p $(winix_install_dir)/bin
|
mkdir -p $(WINIX_INSTALL_DIR)/bin
|
||||||
cp winix $(winix_install_dir)/bin
|
cp winix $(WINIX_INSTALL_DIR)/bin
|
||||||
cp winix.so $(winix_install_dir)/bin
|
# installing the winix.so library
|
||||||
|
rm -Rf $(WINIX_INSTALL_DIR)/lib
|
||||||
|
mkdir -p $(WINIX_INSTALL_DIR)/lib
|
||||||
|
cp winix.so $(WINIX_INSTALL_DIR)/lib
|
||||||
# etc configs
|
# etc configs
|
||||||
rm -Rf $(winix_install_dir)/etc
|
rm -Rf $(WINIX_INSTALL_DIR)/etc
|
||||||
mkdir -p $(winix_install_dir)/etc
|
mkdir -p $(WINIX_INSTALL_DIR)/etc
|
||||||
cp -rf etc/* $(winix_install_dir)/etc/
|
cp -rf etc/* $(WINIX_INSTALL_DIR)/etc/
|
||||||
# html templates
|
# html templates
|
||||||
rm -Rf $(winix_install_dir)/html
|
rm -Rf $(WINIX_INSTALL_DIR)/html
|
||||||
mkdir -p $(winix_install_dir)/html
|
mkdir -p $(WINIX_INSTALL_DIR)/html
|
||||||
cp -rf html/* $(winix_install_dir)/html/
|
cp -rf html/* $(WINIX_INSTALL_DIR)/html/
|
||||||
# txt templates
|
# txt templates
|
||||||
rm -Rf $(winix_install_dir)/txt
|
rm -Rf $(WINIX_INSTALL_DIR)/txt
|
||||||
mkdir -p $(winix_install_dir)/txt
|
mkdir -p $(WINIX_INSTALL_DIR)/txt
|
||||||
cp -rf txt/* $(winix_install_dir)/txt/
|
cp -rf txt/* $(WINIX_INSTALL_DIR)/txt/
|
||||||
# locales
|
# locales
|
||||||
rm -Rf $(winix_install_dir)/locale
|
rm -Rf $(WINIX_INSTALL_DIR)/locale
|
||||||
mkdir -p $(winix_install_dir)/locale
|
mkdir -p $(WINIX_INSTALL_DIR)/locale
|
||||||
cp -rf locale/* $(winix_install_dir)/locale/
|
cp -rf locale/* $(WINIX_INSTALL_DIR)/locale/
|
||||||
# plugins
|
# plugins
|
||||||
rm -Rf $(winix_install_dir)/plugins
|
rm -Rf $(WINIX_INSTALL_DIR)/plugins
|
||||||
mkdir -p $(winix_install_dir)/plugins
|
mkdir -p $(WINIX_INSTALL_DIR)/plugins
|
||||||
find plugins/ -name "*.so" | xargs -I foo cp foo $(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
|
# removing privileges for others
|
||||||
find $(winix_install_dir) -exec chmod o-r,o-x,o-w "{}" "+"
|
find $(WINIX_INSTALL_DIR) -exec chmod o-r,o-x,o-w "{}" "+"
|
||||||
|
|
||||||
|
|
||||||
|
-include Makefile.dep
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+18028
-1
File diff suppressed because one or more lines are too long
@@ -1,24 +0,0 @@
|
|||||||
include Makefile.o.dep
|
|
||||||
|
|
||||||
current_path := $(shell pwd)
|
|
||||||
global_relative_working_dir := $(shell relative_path $(current_path) $(GLOBAL_WORKING_DIR))
|
|
||||||
|
|
||||||
winix_include_paths = -I$(global_relative_working_dir)/winix/winixd -I$(global_relative_working_dir)/ezc/src -I$(global_relative_working_dir)/tito/src -I$(global_relative_working_dir)/morm/src -I$(global_relative_working_dir)/pikotools
|
|
||||||
|
|
||||||
|
|
||||||
all: $(o)
|
|
||||||
|
|
||||||
|
|
||||||
%.o: %.cpp
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(winix_include_paths) $<
|
|
||||||
|
|
||||||
|
|
||||||
depend:
|
|
||||||
makedepend -Y. $(winix_include_paths) -f- *.cpp > Makefile.dep
|
|
||||||
echo -n "o = " > Makefile.o.dep
|
|
||||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o
|
|
||||||
|
|
||||||
include Makefile.dep
|
|
||||||
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 filelog.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionidmanager.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o
|
|
||||||
+737
-1177
File diff suppressed because it is too large
Load Diff
+43
-91
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -46,27 +46,23 @@
|
|||||||
#include <fcgiapp.h>
|
#include <fcgiapp.h>
|
||||||
|
|
||||||
#include "sessionmanager.h"
|
#include "sessionmanager.h"
|
||||||
#include "db/db.h"
|
|
||||||
#include "functions/functions.h"
|
#include "functions/functions.h"
|
||||||
#include "templates/templates.h"
|
#include "templates/templates.h"
|
||||||
#include "compress.h"
|
#include "compress.h"
|
||||||
#include "postparser.h"
|
#include "postparser.h"
|
||||||
#include "cookieparser.h"
|
#include "cookieparser.h"
|
||||||
#include "postmultiparser.h"
|
#include "postmultiparser.h"
|
||||||
#include "acceptencodingparser.h"
|
#include "utils/acceptencodingparser.h"
|
||||||
#include "space/jsontospaceparser.h"
|
|
||||||
|
|
||||||
#include "winixrequest.h"
|
#include "winixrequest.h"
|
||||||
#include "log/log.h"
|
#include "log/log.h"
|
||||||
#include "filelog.h"
|
#include "filelog.h"
|
||||||
|
#include "models/winixmodelconnector.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -77,16 +73,19 @@ public:
|
|||||||
bool DropPrivileges();
|
bool DropPrivileges();
|
||||||
void InitLoggers();
|
void InitLoggers();
|
||||||
Log & GetMainLog();
|
Log & GetMainLog();
|
||||||
void InitPlugins();
|
bool InitializePlugins();
|
||||||
bool Init();
|
bool Init();
|
||||||
|
bool InitializeRequestForFastCGI(Request & request);
|
||||||
|
void SetRequestDependency(Request & request);
|
||||||
|
void InitializeNewRequest(Request & request);
|
||||||
|
void PutRequestToJob();
|
||||||
void Start();
|
void Start();
|
||||||
void Close();
|
void Close();
|
||||||
void LogUserGroups();
|
void LogUserGroups();
|
||||||
bool Demonize();
|
bool Demonize();
|
||||||
void SetStopSignal();
|
void SetStopSignal();
|
||||||
bool WasStopSignal();
|
bool WasStopSignal();
|
||||||
bool Lock();
|
Synchro * GetSynchro();
|
||||||
void Unlock();
|
|
||||||
void StartThreads();
|
void StartThreads();
|
||||||
void WaitForThreads();
|
void WaitForThreads();
|
||||||
|
|
||||||
@@ -96,22 +95,11 @@ public:
|
|||||||
// pointers to the current request and a session
|
// pointers to the current request and a session
|
||||||
Cur cur;
|
Cur cur;
|
||||||
|
|
||||||
// temporary one request object
|
|
||||||
// current request
|
|
||||||
Request req;
|
|
||||||
|
|
||||||
// users sessions
|
// users sessions
|
||||||
SessionManager session_manager;
|
SessionManager session_manager;
|
||||||
|
|
||||||
// database (DEPRACATED)
|
// an unique id for each request
|
||||||
Db db;
|
size_t request_id;
|
||||||
DbConn db_conn;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
model
|
|
||||||
*/
|
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
System system;
|
System system;
|
||||||
@@ -124,9 +112,6 @@ public:
|
|||||||
bool stdout_is_closed;
|
bool stdout_is_closed;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
view
|
|
||||||
*/
|
|
||||||
|
|
||||||
Templates templates;
|
Templates templates;
|
||||||
|
|
||||||
@@ -135,44 +120,32 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum Header
|
|
||||||
{
|
|
||||||
h_200,
|
|
||||||
h_404,
|
|
||||||
h_403
|
|
||||||
};
|
|
||||||
|
|
||||||
PostParser post_parser;
|
PostParser post_parser;
|
||||||
PostMultiParser post_multi_parser;
|
PostMultiParser post_multi_parser;
|
||||||
PT::JSONToSpaceParser post_json_parser;
|
pt::SpaceParser space_parser;
|
||||||
std::string post_buffer;
|
|
||||||
|
|
||||||
CookieParser cookie_parser;
|
CookieParser cookie_parser;
|
||||||
|
AcceptBaseParser accept_base_parser;
|
||||||
AcceptEncodingParser accept_encoding_parser;
|
AcceptEncodingParser accept_encoding_parser;
|
||||||
Compress compress;
|
Compress compress;
|
||||||
FCGX_Request fcgi_request;
|
|
||||||
int fcgi_socket;
|
int fcgi_socket;
|
||||||
Synchro synchro;
|
Synchro synchro;
|
||||||
pthread_t signal_thread;
|
pthread_t signal_thread;
|
||||||
std::string socket_to_send_on_exit;
|
std::string socket_to_send_on_exit;
|
||||||
std::string send_data_buf;
|
pt::WTextStream post_log_tmp_buffer;
|
||||||
PT::SpaceToJSON json_generic_serializer;
|
|
||||||
TextStream<std::wstring> json_out_stream;
|
|
||||||
std::string aheader_name, aheader_value;
|
|
||||||
std::wstring html_filtered;
|
|
||||||
std::string output_8bit;
|
|
||||||
BinaryPage compressed_output;
|
|
||||||
std::wstring cookie_id_string;
|
|
||||||
std::wstring http_header;
|
|
||||||
std::string http_header_8bit;
|
|
||||||
|
|
||||||
morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector
|
std::wstring http_header_name;
|
||||||
|
std::wstring http_header_value;
|
||||||
|
pt::WTextStream empty_response;
|
||||||
|
|
||||||
|
WinixModelConnector model_connector; // main thread model connector, each thread has its own connector
|
||||||
morm::JSONConnector json_connector;
|
morm::JSONConnector json_connector;
|
||||||
|
morm::XMLConnector xml_connector;
|
||||||
morm::PostgreSQLConnector postgresql_connector;
|
morm::PostgreSQLConnector postgresql_connector;
|
||||||
|
|
||||||
// objects for main thread
|
// objects for main thread
|
||||||
WinixBase winix_base;
|
WinixBase winix_base;
|
||||||
WinixModel winix_model;
|
WinixModelDeprecated winix_model;
|
||||||
WinixSystem winix_system;
|
WinixSystem winix_system;
|
||||||
WinixRequest winix_request;
|
WinixRequest winix_request;
|
||||||
// ///////////////////////
|
// ///////////////////////
|
||||||
@@ -182,19 +155,22 @@ private:
|
|||||||
//////////////////////////
|
//////////////////////////
|
||||||
|
|
||||||
// log_buffer for the main thread
|
// log_buffer for the main thread
|
||||||
PT::WTextStream log_buffer;
|
pt::WTextStream log_buffer;
|
||||||
|
|
||||||
// logger only for App object
|
// logger only for the main thread
|
||||||
Log log;
|
Log log;
|
||||||
|
|
||||||
// file logger, one object for every Log objects
|
// file logger, one object for all Log objects
|
||||||
FileLog file_log;
|
FileLog file_log;
|
||||||
|
|
||||||
bool InitFCGI(char * sock, char * sock_user, char * sock_group);
|
bool AddSystemThreads();
|
||||||
bool InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_group);
|
|
||||||
|
bool InitFCGIChmodChownSocket(const char * sock);
|
||||||
bool DropPrivileges(char * user, char * group);
|
bool DropPrivileges(char * user, char * group);
|
||||||
bool DropPrivileges(const char * user, uid_t uid, gid_t gid, bool additional_groups);
|
bool DropPrivileges(const char * user, uid_t uid, gid_t gid, bool additional_groups);
|
||||||
bool CheckAccessFromPlugins();
|
bool CheckAccessFromPlugins();
|
||||||
|
void MakeRenameMeToABetterName();
|
||||||
|
bool AddRootDir();
|
||||||
void ProcessRequestThrow();
|
void ProcessRequestThrow();
|
||||||
void ProcessRequest();
|
void ProcessRequest();
|
||||||
void BaseUrlRedirect(int code, bool add_subdomain);
|
void BaseUrlRedirect(int code, bool add_subdomain);
|
||||||
@@ -202,59 +178,31 @@ private:
|
|||||||
void CheckIfNeedSSLredirect();
|
void CheckIfNeedSSLredirect();
|
||||||
void SetLocale();
|
void SetLocale();
|
||||||
void CheckPostRedirect();
|
void CheckPostRedirect();
|
||||||
void MakePage();
|
void AddDefaultModels();
|
||||||
void Make();
|
|
||||||
void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji??
|
void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji??
|
||||||
void LogAccess();
|
void LogAccess();
|
||||||
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
|
||||||
void CreateJSONAnswer();
|
|
||||||
|
|
||||||
void ReadRequest();
|
void ReadRequest();
|
||||||
void SendTextAnswer();
|
|
||||||
void SendBinaryAnswer();
|
|
||||||
void SendAnswer();
|
|
||||||
|
|
||||||
void LogEnvironmentVariables();
|
void LogEnvironmentVariables();
|
||||||
void LogEnvironmentHTTPVariables();
|
void LogEnvironmentHTTPVariables();
|
||||||
|
void ParseAcceptHeader(const wchar_t * header_name, const std::wstring & env, std::vector<HeaderValue> & container, size_t max_len);
|
||||||
|
void ParseAcceptHeader();
|
||||||
|
void ParseAcceptLanguageHeader();
|
||||||
void SetEnv(const char * name, std::wstring & env);
|
void SetEnv(const char * name, std::wstring & env);
|
||||||
void ReadEnvVariables();
|
void ReadEnvVariables();
|
||||||
void ReadEnvHTTPVariables();
|
void ReadEnvHTTPVariables();
|
||||||
bool SaveEnvHTTPVariable(const char * env);
|
bool SaveEnvHTTPVariable(const char * env);
|
||||||
void ReadEnvRemoteIP();
|
void ReadInputPostToBuffer();
|
||||||
void ReadPostJson();
|
void ParsePostJson();
|
||||||
|
void ReadPostJson(bool copy_raw_post);
|
||||||
void ReadPostVars();
|
void ReadPostVars();
|
||||||
|
|
||||||
void CheckIE();
|
void CheckIE();
|
||||||
void CheckKonqueror();
|
void CheckKonqueror();
|
||||||
void CheckRequestMethod();
|
void CheckHtmx();
|
||||||
void CheckSSL();
|
bool IsRequestedFrame();
|
||||||
void SetSubdomain();
|
|
||||||
|
|
||||||
|
|
||||||
Header GetHTTPStatusCode();
|
|
||||||
void PrepareSessionCookie();
|
|
||||||
void FilterContent();
|
|
||||||
void SendHeaders();
|
void SendHeaders();
|
||||||
void SendCookies();
|
void SendCookies();
|
||||||
bool AddHeader(const wchar_t * name, const wchar_t * value);
|
|
||||||
bool AddHeader(const std::wstring & name, const std::wstring & value);
|
|
||||||
bool AddHeader(const wchar_t * name, const PT::WTextStream & value);
|
|
||||||
bool AddHeader(const std::wstring & name, const PT::WTextStream & value);
|
|
||||||
bool PrepareHeadersStaticCreateResource(PT::WTextStream & out_path);
|
|
||||||
void PrepareHeadersStatic();
|
|
||||||
void PrepareHeaderContentType();
|
|
||||||
void PrepareHeadersForbidden();
|
|
||||||
void PrepareHeadersRedirect();
|
|
||||||
void PrepareHeadersSendFile();
|
|
||||||
void PrepareHeadersCompression(int compress_encoding);
|
|
||||||
void PrepareHeadersNormal(Header header, size_t output_size);
|
|
||||||
void PrepareHeaders(bool compressing, int compress_encoding, Header header, size_t output_size);
|
|
||||||
void PrepareStandardJSONFields();
|
|
||||||
int SelectDeflateVersion();
|
|
||||||
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
|
||||||
bool CanSendContent();
|
|
||||||
void ClearAfterRequest();
|
void ClearAfterRequest();
|
||||||
|
void IncrementRequestId();
|
||||||
|
|
||||||
void LogUser(const char * msg, uid_t id);
|
void LogUser(const char * msg, uid_t id);
|
||||||
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
|
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
|
||||||
@@ -267,6 +215,10 @@ private:
|
|||||||
|
|
||||||
void CreateStaticTree();
|
void CreateStaticTree();
|
||||||
|
|
||||||
|
bool DoDatabaseMigration();
|
||||||
|
bool TryToMakeDatabaseMigration();
|
||||||
|
|
||||||
|
|
||||||
// !! IMPROVE ME
|
// !! IMPROVE ME
|
||||||
// !! move to the session manager?
|
// !! move to the session manager?
|
||||||
time_t last_sessions_save;
|
time_t last_sessions_save;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2019, Tomasz Sowa
|
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -42,10 +42,11 @@ namespace Winix
|
|||||||
|
|
||||||
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
BaseThread::BaseThread() : thread_signal(PTHREAD_COND_INITIALIZER)
|
||||||
{
|
{
|
||||||
synchro = 0;
|
synchro = nullptr;
|
||||||
thread_id = 0;
|
thread_id = 0;
|
||||||
work_mode = 0;
|
work_mode = 0;
|
||||||
wake_up_was_called = false;
|
wake_up_was_called = false;
|
||||||
|
main_model_connector = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,15 +55,21 @@ BaseThread::~BaseThread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BaseThread::set_main_log_buffer(PT::WTextStream * log_buffer)
|
void BaseThread::set_main_log_buffer(pt::WTextStream * log_buffer)
|
||||||
{
|
{
|
||||||
main_log.SetLogBuffer(log_buffer);
|
main_log.set_log_buffer(log_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BaseThread::set_main_file_log(PT::FileLog * file_log)
|
void BaseThread::set_main_file_log(pt::FileLog * file_log)
|
||||||
{
|
{
|
||||||
main_log.SetFileLog(file_log);
|
main_log.set_file_log(file_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BaseThread::set_main_model_connector(morm::ModelConnector * main_model_connector)
|
||||||
|
{
|
||||||
|
this->main_model_connector = main_model_connector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -254,6 +261,7 @@ void * BaseThread::StartRoutine(void * this_object)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base->save_log();
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-13
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2019, Tomasz Sowa
|
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "synchro.h"
|
#include "synchro.h"
|
||||||
#include "winixmodel.h"
|
#include "winixmodeldeprecated.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -47,16 +47,17 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseThread : public WinixModel
|
class BaseThread : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BaseThread();
|
BaseThread();
|
||||||
virtual ~BaseThread();
|
virtual ~BaseThread();
|
||||||
|
|
||||||
void set_main_log_buffer(PT::WTextStream * log_buffer);
|
void set_main_log_buffer(pt::WTextStream * log_buffer);
|
||||||
void set_main_file_log(PT::FileLog * file_log);
|
void set_main_file_log(pt::FileLog * file_log);
|
||||||
|
|
||||||
|
void set_main_model_connector(morm::ModelConnector * main_model_connector);
|
||||||
|
|
||||||
// work mode
|
// work mode
|
||||||
// we have two modes:
|
// we have two modes:
|
||||||
@@ -105,11 +106,13 @@ protected:
|
|||||||
|
|
||||||
// logger for the main thread
|
// logger for the main thread
|
||||||
Log main_log;
|
Log main_log;
|
||||||
|
// log from WinixBase is meant to be used by the second thread
|
||||||
|
|
||||||
// log from WinixBase is meant to be used by the other thread
|
// model connector for the main thread
|
||||||
|
// model_connector from the based class WinixModelDeprecated is meant to be used by the second thread
|
||||||
|
morm::ModelConnector * main_model_connector;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
|
|
||||||
// signal came (work mode = 0 - default)
|
// signal came (work mode = 0 - default)
|
||||||
@@ -141,12 +144,12 @@ protected:
|
|||||||
|
|
||||||
void SignalLoop();
|
void SignalLoop();
|
||||||
static void * StartRoutine(void *);
|
static void * StartRoutine(void *);
|
||||||
bool BaseInit();
|
virtual bool BaseInit();
|
||||||
void BaseUninit();
|
virtual void BaseUninit();
|
||||||
bool BaseSignalReceived();
|
virtual bool BaseSignalReceived();
|
||||||
void BaseDo();
|
virtual void BaseDo();
|
||||||
bool WaitForSignal();
|
virtual bool WaitForSignal();
|
||||||
bool WaitForSignalSleep(time_t second);
|
virtual bool WaitForSignalSleep(time_t second);
|
||||||
|
|
||||||
bool Lock();
|
bool Lock();
|
||||||
void Unlock();
|
void Unlock();
|
||||||
|
|||||||
@@ -1,636 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is distributed under the 2-Clause BSD licence.
|
|
||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bbcodeparser.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::Equal(const wchar_t * str1, const wchar_t * str2)
|
|
||||||
{
|
|
||||||
while( *str1 == *str2 && *str1 != 0 )
|
|
||||||
{
|
|
||||||
str1 += 1;
|
|
||||||
str2 += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *str1 == *str2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::IsValidCharForName(int c)
|
|
||||||
{
|
|
||||||
if( (c>='a' && c<='z') ||
|
|
||||||
(c>='A' && c<='Z') ||
|
|
||||||
c=='*' || c=='_')
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::IsOpeningTagMark(wchar_t c)
|
|
||||||
{
|
|
||||||
return (c == '[');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::IsClosingTagMark(wchar_t c)
|
|
||||||
{
|
|
||||||
return (c == ']');
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BBCODEParser::IsClosingXmlSimpleTagMark(wchar_t c)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// there are no commentaries in bbcode
|
|
||||||
bool BBCODEParser::IsOpeningCommentaryTagMark(const wchar_t *)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t BBCODEParser::OpeningCommentaryTagMarkSize()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::SkipCommentaryTagIfExists()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// one enter will generate one <br>
|
|
||||||
// two enters or more will generate only two br (<br><br>)
|
|
||||||
void BBCODEParser::PutNormalText(const wchar_t * str, const wchar_t * end)
|
|
||||||
{
|
|
||||||
int br_len;
|
|
||||||
|
|
||||||
if( *pchar == 0 )
|
|
||||||
{
|
|
||||||
// trimming last white characters at end of the user text
|
|
||||||
while( str<end && (IsWhite(*(end-1)) || *(end-1)==10) )
|
|
||||||
--end;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while( str < end )
|
|
||||||
{
|
|
||||||
if( *str == 10 )
|
|
||||||
{
|
|
||||||
++str;
|
|
||||||
br_len = 1;
|
|
||||||
|
|
||||||
// skipping white characters without a new line character
|
|
||||||
while( str < end && IsWhite(*str) )
|
|
||||||
++str;
|
|
||||||
|
|
||||||
if( str < end && *str == 10 )
|
|
||||||
{
|
|
||||||
br_len = 2;
|
|
||||||
|
|
||||||
// skipping white characters with new line characters
|
|
||||||
while( str < end && (IsWhite(*str) || *str==10) )
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !has_open_ol_tag && !has_open_ul_tag && !has_open_li_tag )
|
|
||||||
{
|
|
||||||
for(int i=0 ; i < br_len ; ++i)
|
|
||||||
(*out_string) += L"<br>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PrintEscape(*str);
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::CheckExceptions()
|
|
||||||
{
|
|
||||||
if( stack_len >= 2 )
|
|
||||||
{
|
|
||||||
if( pstack[stack_len-1].type == Item::opening &&
|
|
||||||
pstack[stack_len-2].type == Item::opening &&
|
|
||||||
IsNameEqual(L"*", pstack[stack_len-1].name) &&
|
|
||||||
IsNameEqual(L"*", pstack[stack_len-2].name) )
|
|
||||||
{
|
|
||||||
// removing the last [*] from the stack
|
|
||||||
// </li> was put automatically
|
|
||||||
PopStack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
bbcode format:
|
|
||||||
[bbcodetag=value]some text[/bbcodetag]
|
|
||||||
the value can be quoted, e.g.
|
|
||||||
[bbcodetag="value"]some text[/bbcodetag], or
|
|
||||||
[bbcodetag='value']some text[/bbcodetag]
|
|
||||||
|
|
||||||
the third string below (in tags table) is 'html_argument' from Tags,
|
|
||||||
it can contain a special character % followed by a string which means:
|
|
||||||
%1 - "value" escaped as for html
|
|
||||||
%2 - "some text" escaped as for html
|
|
||||||
%u1 - "value" trimmed and escaped as for url-es
|
|
||||||
%u2 - "some text" trimmed and escaped as for url-es
|
|
||||||
%% - one %
|
|
||||||
|
|
||||||
if you are using %2 or %u2 then "some text" is not treated as bbcode, e.g.
|
|
||||||
[bbcodetag=value]some [b]text[/b][/bbcodetag] will produce:
|
|
||||||
<htmltag arg="value">some [b]text[/b]</htmltag> (the inner tags [b][/b] were not parsed)
|
|
||||||
|
|
||||||
also when using %2 or %u2 the closing bbcode tag is skipped
|
|
||||||
(if you want this tag then you can put it in 'html_argument')
|
|
||||||
|
|
||||||
and when using u (%u1 or %u2) the argument is trimmed from whitespaces and new lines
|
|
||||||
at the beginning and at the end
|
|
||||||
(because otherwise a space would be changed to %20 and this were probably not what you really wanted)
|
|
||||||
*/
|
|
||||||
const BBCODEParser::Tags * BBCODEParser::FindTag(const wchar_t * tag)
|
|
||||||
{
|
|
||||||
static Tags tags[] = {
|
|
||||||
{L"*", L"li", L">", false},
|
|
||||||
{L"b", L"em", L">", true},
|
|
||||||
{L"i", L"span", L" class=\"bbitalic\">", true},
|
|
||||||
{L"u", L"span", L" class=\"bbunderline\">", true},
|
|
||||||
{L"s", L"span", L" class=\"bbstrike\">", true},
|
|
||||||
{L"code", L"code", L" class=\"bbcode\">", false},
|
|
||||||
{L"list", L"ul", L" class=\"bblist\">", false},
|
|
||||||
{L"color", L"span", L" class=\"bbcol%1\">", true},
|
|
||||||
{L"url", L"a", L" href=\"%u1\">", true},
|
|
||||||
{L"img", L"img", L" alt=\"%1\" src=\"%u2\">", true},
|
|
||||||
{L"quote", L"div", L" class=\"bbquote\">\n<span class=\"bbquotewho\">%1</span><br>\n", false},
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t i;
|
|
||||||
size_t len = sizeof(tags) / sizeof(Tags);
|
|
||||||
|
|
||||||
for(i=0 ; i<len ; ++i)
|
|
||||||
{
|
|
||||||
if( Equal(tag, tags[i].bbcode) )
|
|
||||||
return &tags[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BBCODEParser::Tags * BBCODEParser::FindTag(const std::wstring & tag)
|
|
||||||
{
|
|
||||||
return FindTag(tag.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end)
|
|
||||||
{
|
|
||||||
// skipping white characters from the argument
|
|
||||||
while( start<end && IsWhite(*start) )
|
|
||||||
++start;
|
|
||||||
|
|
||||||
// skipping first '=' character if exists
|
|
||||||
if( start<end && *start == '=' )
|
|
||||||
++start;
|
|
||||||
|
|
||||||
// skipping white characters from the argument
|
|
||||||
// at the beginning
|
|
||||||
while( start<end && IsWhite(*start) )
|
|
||||||
++start;
|
|
||||||
|
|
||||||
// and at the end
|
|
||||||
while( start<end && IsWhite(*(end-1)) )
|
|
||||||
--end;
|
|
||||||
|
|
||||||
|
|
||||||
if( start<end && (*start=='\'' || *start=='\"') )
|
|
||||||
{
|
|
||||||
++start;
|
|
||||||
|
|
||||||
if( start<end && *(start-1) == *(end-1) )
|
|
||||||
--end;
|
|
||||||
|
|
||||||
// skipping white characters after a first quote char [url = " ww...."]
|
|
||||||
while( start<end && IsWhite(*start) )
|
|
||||||
++start;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PrintEncode(int c)
|
|
||||||
{
|
|
||||||
if( c == '&' )
|
|
||||||
{
|
|
||||||
(*out_string) += L"&";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( (c>='a' && c<='z') ||
|
|
||||||
(c>='A' && c<='Z') ||
|
|
||||||
(c>='0' && c<='9') ||
|
|
||||||
(c=='_' || c=='?' || c=='.' || c==',' || c=='/' || c=='-' ||
|
|
||||||
c=='+' || c=='*' || c=='(' || c==')' || c=='=' || c==':')
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(*out_string) += c;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wchar_t buffer[20];
|
|
||||||
swprintf(buffer, 20, L"%02X", c);
|
|
||||||
|
|
||||||
(*out_string) += '%';
|
|
||||||
(*out_string) += buffer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PrintEscape(int c, bool change_quote)
|
|
||||||
{
|
|
||||||
if( c == '<' )
|
|
||||||
{
|
|
||||||
(*out_string) += L"<";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( c == '>' )
|
|
||||||
{
|
|
||||||
(*out_string) += L">";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( c == '&' )
|
|
||||||
{
|
|
||||||
(*out_string) += L"&";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( c == '\"' && change_quote )
|
|
||||||
{
|
|
||||||
(*out_string) += L""";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*out_string) += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PrintArgumentEncode(const wchar_t * start, const wchar_t * end)
|
|
||||||
{
|
|
||||||
PrintArgumentCheckQuotes(start, end);
|
|
||||||
TrimWhiteWithNewLines(start, end);
|
|
||||||
|
|
||||||
for( ; start<end ; ++start )
|
|
||||||
PrintEncode(*start);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PrintArgumentEscape(const wchar_t * start, const wchar_t * end)
|
|
||||||
{
|
|
||||||
PrintArgumentCheckQuotes(start, end);
|
|
||||||
|
|
||||||
for( ; start<end ; ++start )
|
|
||||||
PrintEscape(*start, true); // quotes are escaped as well here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition)
|
|
||||||
{
|
|
||||||
if( Equal(tag->html_tag, tag_name) )
|
|
||||||
{
|
|
||||||
if( condition )
|
|
||||||
{
|
|
||||||
PutClosingTag(tag);
|
|
||||||
(*out_string) += '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
condition = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::CheckOpeningTag(const Tags * tag)
|
|
||||||
{
|
|
||||||
bool has_list_tag = has_open_ul_tag || has_open_ol_tag;
|
|
||||||
|
|
||||||
CheckOpeningTag(tag, L"li", has_open_li_tag);
|
|
||||||
CheckOpeningTag(tag, L"ul", has_open_ul_tag);
|
|
||||||
CheckOpeningTag(tag, L"ol", has_open_ol_tag);
|
|
||||||
|
|
||||||
if( has_open_li_tag && !has_list_tag )
|
|
||||||
{
|
|
||||||
(*out_string) += L"<ul>\n";
|
|
||||||
has_open_ul_tag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote)
|
|
||||||
{
|
|
||||||
for( ; start < end ; ++start)
|
|
||||||
PrintEscape(*start, change_quote);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PrintEncode(const wchar_t * start, const wchar_t * end)
|
|
||||||
{
|
|
||||||
for( ; start < end ; ++start)
|
|
||||||
PrintEncode(*start);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PutOpeningTagFromEzc()
|
|
||||||
{
|
|
||||||
// this can be a tag from Ezc templates system
|
|
||||||
(*out_string) += '[';
|
|
||||||
(*out_string) += LastItem().name;
|
|
||||||
|
|
||||||
const wchar_t * start = pchar;
|
|
||||||
|
|
||||||
while( *pchar && *pchar!=']' )
|
|
||||||
++pchar;
|
|
||||||
|
|
||||||
if( *pchar == ']' )
|
|
||||||
++pchar;
|
|
||||||
|
|
||||||
Put(start, pchar);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u)
|
|
||||||
{
|
|
||||||
if( has_u )
|
|
||||||
PrintArgumentEncode(arg_start, arg_end);
|
|
||||||
else
|
|
||||||
PrintArgumentEscape(arg_start, arg_end);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end)
|
|
||||||
{
|
|
||||||
while( start < end && (IsWhite(*start) || *start==10) )
|
|
||||||
++start;
|
|
||||||
|
|
||||||
while( start < end && (IsWhite(*(end-1)) || *(end-1)==10) )
|
|
||||||
--end;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PutHtmlArgument2(const Tags * tag, bool has_u)
|
|
||||||
{
|
|
||||||
const wchar_t * start = pchar;
|
|
||||||
const wchar_t * end = pchar;
|
|
||||||
bool first_tag_removed = false;
|
|
||||||
|
|
||||||
while( *pchar != 0 )
|
|
||||||
{
|
|
||||||
if( IsOpeningTagMark(*pchar) )
|
|
||||||
{
|
|
||||||
if( IsClosingTagForLastItem() )
|
|
||||||
{
|
|
||||||
// the last tag is skipped when using patterns with %2 or %u2
|
|
||||||
|
|
||||||
PopStack(); // removing opening tag from the stack
|
|
||||||
first_tag_removed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pchar += 1;
|
|
||||||
end = pchar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !first_tag_removed )
|
|
||||||
PopStack(); // user has forgotten to close the tag
|
|
||||||
|
|
||||||
if( has_u )
|
|
||||||
{
|
|
||||||
TrimWhiteWithNewLines(start, end);
|
|
||||||
PrintEncode(start, end);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PrintEscape(start, end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end)
|
|
||||||
{
|
|
||||||
const wchar_t * pattern = tag->html_argument;
|
|
||||||
bool has_u;
|
|
||||||
|
|
||||||
while( *pattern )
|
|
||||||
{
|
|
||||||
if( *pattern == '%' )
|
|
||||||
{
|
|
||||||
++pattern;
|
|
||||||
has_u = false;
|
|
||||||
|
|
||||||
if( *pattern == 'u' )
|
|
||||||
{
|
|
||||||
++pattern;
|
|
||||||
has_u = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( *pattern == '1' )
|
|
||||||
{
|
|
||||||
++pattern;
|
|
||||||
PutHtmlArgument1(arg_start, arg_end, has_u);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( *pattern == '2' )
|
|
||||||
{
|
|
||||||
++pattern;
|
|
||||||
PutHtmlArgument2(tag, has_u);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if( *pattern == '%' )
|
|
||||||
{
|
|
||||||
(*out_string) += '%';
|
|
||||||
++pattern;
|
|
||||||
}
|
|
||||||
// else unrecognized, will be printed next time as a normal character
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*out_string) += *pattern;
|
|
||||||
++pattern;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PutOpeningTagFromBBCode(const Tags * tag)
|
|
||||||
{
|
|
||||||
CheckOpeningTag(tag);
|
|
||||||
PutOpeningTagMark();
|
|
||||||
Put(tag->html_tag);
|
|
||||||
|
|
||||||
const wchar_t * start = pchar;
|
|
||||||
|
|
||||||
while( *pchar && *pchar != ']' )
|
|
||||||
++pchar;
|
|
||||||
|
|
||||||
PutHtmlArgument(tag, start, pchar);
|
|
||||||
|
|
||||||
if( *pchar == ']' )
|
|
||||||
++pchar;
|
|
||||||
|
|
||||||
if( !tag->inline_tag )
|
|
||||||
{
|
|
||||||
Put(10);
|
|
||||||
SkipWhiteLines();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool BBCODEParser::PutOpeningTag()
|
|
||||||
{
|
|
||||||
const Tags * tag = FindTag(LastItem().name);
|
|
||||||
|
|
||||||
if( !tag )
|
|
||||||
PutOpeningTagFromEzc();
|
|
||||||
else
|
|
||||||
PutOpeningTagFromBBCode(tag);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PutClosingTag(const Tags * tag)
|
|
||||||
{
|
|
||||||
if( !tag )
|
|
||||||
return; // skipping the tag
|
|
||||||
|
|
||||||
PutOpeningTagMark();
|
|
||||||
(*out_string) += '/';
|
|
||||||
(*out_string) += tag->html_tag;
|
|
||||||
PutClosingTagMark();
|
|
||||||
|
|
||||||
if( !tag->inline_tag )
|
|
||||||
{
|
|
||||||
(*out_string) += L"\n";
|
|
||||||
SkipWhiteLines();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Equal(tag->html_tag, L"li") )
|
|
||||||
has_open_li_tag = false;
|
|
||||||
|
|
||||||
if( Equal(tag->html_tag, L"ol") )
|
|
||||||
has_open_ol_tag = false;
|
|
||||||
|
|
||||||
if( Equal(tag->html_tag, L"ul") )
|
|
||||||
has_open_ul_tag = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::PutClosingTag(const wchar_t * tag_name)
|
|
||||||
{
|
|
||||||
const Tags * tag = FindTag(tag_name);
|
|
||||||
PutClosingTag(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::Init()
|
|
||||||
{
|
|
||||||
has_open_li_tag = false;
|
|
||||||
has_open_ol_tag = false;
|
|
||||||
has_open_ul_tag = false;
|
|
||||||
|
|
||||||
SkipWhiteLines();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BBCODEParser::Uninit()
|
|
||||||
{
|
|
||||||
if( has_open_li_tag )
|
|
||||||
(*out_string) += L"</li>\n";
|
|
||||||
|
|
||||||
if( has_open_ol_tag )
|
|
||||||
(*out_string) += L"</ol>\n";
|
|
||||||
|
|
||||||
if( has_open_ul_tag )
|
|
||||||
(*out_string) += L"</ul>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is distributed under the 2-Clause BSD licence.
|
|
||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_bbcodeparser
|
|
||||||
#define headerfile_winix_core_bbcodeparser
|
|
||||||
|
|
||||||
#include "htmlfilter.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BBCODEParser : public HTMLFilter
|
|
||||||
{
|
|
||||||
|
|
||||||
struct Tags
|
|
||||||
{
|
|
||||||
const wchar_t * bbcode;
|
|
||||||
const wchar_t * html_tag;
|
|
||||||
const wchar_t * html_argument; // with closing '>'
|
|
||||||
bool inline_tag;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
virtual methods
|
|
||||||
(from HTMLFilter class)
|
|
||||||
*/
|
|
||||||
virtual void Init();
|
|
||||||
virtual void Uninit();
|
|
||||||
|
|
||||||
virtual bool IsOpeningTagMark(wchar_t c);
|
|
||||||
virtual bool IsClosingTagMark(wchar_t c);
|
|
||||||
virtual bool IsClosingXmlSimpleTagMark(wchar_t c);
|
|
||||||
|
|
||||||
virtual bool IsOpeningCommentaryTagMark(const wchar_t *);
|
|
||||||
virtual size_t OpeningCommentaryTagMarkSize();
|
|
||||||
|
|
||||||
virtual bool IsValidCharForName(int c);
|
|
||||||
virtual void CheckExceptions();
|
|
||||||
virtual bool SkipCommentaryTagIfExists();
|
|
||||||
|
|
||||||
virtual bool PutOpeningTag();
|
|
||||||
virtual void PutClosingTag(const wchar_t * tag);
|
|
||||||
|
|
||||||
virtual void PutNormalText(const wchar_t * str, const wchar_t * end);
|
|
||||||
virtual void ReadNormalTextSkipWhite(const wchar_t * & start, const wchar_t * & last_non_white);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
others
|
|
||||||
*/
|
|
||||||
bool Equal(const wchar_t * str1, const wchar_t * str2);
|
|
||||||
|
|
||||||
void PutHtmlArgument1(const wchar_t * arg_start, const wchar_t * arg_end, bool has_u);
|
|
||||||
void PutHtmlArgument2(const Tags * tag, bool has_u);
|
|
||||||
void PutHtmlArgument(const Tags * tag, const wchar_t * arg_start, const wchar_t * arg_end);
|
|
||||||
|
|
||||||
void PutOpeningTagFromEzc();
|
|
||||||
void PutOpeningTagFromBBCode(const Tags * tag);
|
|
||||||
|
|
||||||
const Tags * FindTag(const wchar_t * tag);
|
|
||||||
const Tags * FindTag(const std::wstring & tag);
|
|
||||||
void PrintArgumentCheckQuotes(const wchar_t * & start, const wchar_t * & end);
|
|
||||||
|
|
||||||
void PrintEscape(int c, bool change_quote = false);
|
|
||||||
void PrintEncode(int c);
|
|
||||||
|
|
||||||
void PrintEscape(const wchar_t * start, const wchar_t * end, bool change_quote = false);
|
|
||||||
void PrintEncode(const wchar_t * start, const wchar_t * end);
|
|
||||||
|
|
||||||
void PrintArgumentEncode(const wchar_t * start, const wchar_t * end);
|
|
||||||
void PrintArgumentEscape(const wchar_t * start, const wchar_t * end);
|
|
||||||
|
|
||||||
void PutClosingTag(const Tags * tag);
|
|
||||||
|
|
||||||
void CheckOpeningTag(const Tags * tag, const wchar_t * tag_name, bool & condition);
|
|
||||||
void CheckOpeningTag(const Tags * tag);
|
|
||||||
|
|
||||||
void TrimWhiteWithNewLines(const wchar_t * & start, const wchar_t * & end);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool has_open_ol_tag; // has open html <ol> tag
|
|
||||||
bool has_open_ul_tag; // has open html <ul> tag
|
|
||||||
bool has_open_li_tag; // has open html <li> tag
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -258,6 +258,8 @@ BinaryPage::const_iterator i = page.begin();
|
|||||||
source_len -= strm.avail_in;
|
source_len -= strm.avail_in;
|
||||||
flush = (source_len == 0) ? Z_FINISH : Z_NO_FLUSH;
|
flush = (source_len == 0) ? Z_FINISH : Z_NO_FLUSH;
|
||||||
strm.next_in = (Bytef*)buffer_in;
|
strm.next_in = (Bytef*)buffer_in;
|
||||||
|
|
||||||
|
// IMPROVE ME we can add an interface to pt::TextStreamBase<> and get all chunks of memory
|
||||||
CopyToInputBuffer(i, strm.avail_in);
|
CopyToInputBuffer(i, strm.avail_in);
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
+113
-97
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -45,47 +45,39 @@ namespace Winix
|
|||||||
|
|
||||||
Config::Config()
|
Config::Config()
|
||||||
{
|
{
|
||||||
errors_to_stdout = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::SetFileLog(FileLog * file_log)
|
void Config::SetFileLog(FileLog * file_log)
|
||||||
{
|
{
|
||||||
log.SetFileLog(file_log);
|
log.set_file_log(file_log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::SetLogBuffer(PT::WTextStream * log_buffer)
|
void Config::SetLogBuffer(pt::WTextStream * log_buffer)
|
||||||
{
|
{
|
||||||
log.SetLogBuffer(log_buffer);
|
log.set_log_buffer(log_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::ShowError()
|
void Config::ShowError(const std::wstring & config_file)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch( parser.status )
|
switch( parser.status )
|
||||||
{
|
{
|
||||||
case PT::SpaceParser::no_space:
|
case pt::SpaceParser::ok:
|
||||||
log << log2 << "Config: space not set" << logend;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PT::SpaceParser::ok:
|
case pt::SpaceParser::cant_open_file:
|
||||||
log << log2 << "Config: syntax ok" << logend;
|
log << log1 << "Config: I cannot open a config file: " << config_file << logend;
|
||||||
break;
|
|
||||||
|
|
||||||
case PT::SpaceParser::cant_open_file:
|
|
||||||
if( errors_to_stdout )
|
|
||||||
std::wcout << L"Config: I cannot open a config file: " << config_file << std::endl;
|
|
||||||
|
|
||||||
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PT::SpaceParser::syntax_error:
|
case pt::SpaceParser::syntax_error:
|
||||||
if( errors_to_stdout )
|
log << log1 << "Config: syntax error in file: " << config_file << ", line: "
|
||||||
std::wcout << "Config: syntax error, line: " << parser.line << std::endl;
|
<< parser.get_last_parsed_line() << ":" << parser.get_last_parsed_column() << logend;
|
||||||
|
break;
|
||||||
log << log1 << "Config: syntax error, line: " << parser.line << logend;
|
|
||||||
|
default:
|
||||||
|
// there are no limits sets when parsing the config file
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,38 +87,38 @@ void Config::ShowError()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
bool Config::ReadConfig(const std::wstring & config_file)
|
||||||
{
|
{
|
||||||
errors_to_stdout = errors_to_stdout_;
|
|
||||||
|
|
||||||
if( config_file.empty() )
|
if( config_file.empty() )
|
||||||
{
|
{
|
||||||
log << log2 << "Config: name of the config file is empty" << logend;
|
log << log2 << "Config: name of the config file is empty" << logend;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log << log2 << "Config: reading a config file" << logend;
|
log << log2 << "Config: reading a config file: " << config_file << logend;
|
||||||
|
pt::SpaceParser::Status status = parser.parse_space_file(config_file, space, false);
|
||||||
|
|
||||||
parser.SetSpace(space);
|
if( status == pt::SpaceParser::ok )
|
||||||
PT::SpaceParser::Status status = parser.Parse(config_file);
|
|
||||||
|
|
||||||
if( status == PT::SpaceParser::ok )
|
|
||||||
{
|
{
|
||||||
AssignValues(stdout_is_closed);
|
|
||||||
SetAdditionalVariables();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ShowError();
|
ShowError(config_file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Config::AssignValuesFromSpace()
|
||||||
|
{
|
||||||
|
AssignValues();
|
||||||
|
SetAdditionalVariables();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::AssignValues(bool stdout_is_closed)
|
|
||||||
|
void Config::AssignValues()
|
||||||
{
|
{
|
||||||
server_mode = Text(L"server_mode");
|
server_mode = Text(L"server_mode");
|
||||||
demonize = Bool(L"demonize", true);
|
demonize = Bool(L"demonize", true);
|
||||||
@@ -138,10 +130,13 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
log_file = Text(L"log_file");
|
log_file = Text(L"log_file");
|
||||||
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
|
log_delimiter = Text(L"log_delimiter", L"---------------------------------------------------------------------------------");
|
||||||
fcgi_socket = Text(L"fcgi_socket");
|
fcgi_socket = Text(L"fcgi_socket");
|
||||||
|
fcgi_set_socket_chmod = Bool(L"fcgi_set_socket_chmod", true);
|
||||||
|
fcgi_set_socket_owner = Bool(L"fcgi_set_socket_owner", true);
|
||||||
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
|
fcgi_socket_chmod = Int(L"fcgi_socket_chmod", 0770);
|
||||||
fcgi_socket_user = Text(L"fcgi_socket_user");
|
fcgi_socket_user = Text(L"fcgi_socket_user");
|
||||||
fcgi_socket_group = Text(L"fcgi_socket_group");
|
fcgi_socket_group = Text(L"fcgi_socket_group");
|
||||||
fcgi_socket_listen = Int(L"fcgi_socket_listen", 100);
|
fcgi_socket_listen = Int(L"fcgi_socket_listen", 1024);
|
||||||
|
fcgi_cannot_create_request_delay = Size(L"fcgi_cannot_create_request_delay", 3);
|
||||||
log_level = Int(L"log_level", 1);
|
log_level = Int(L"log_level", 1);
|
||||||
log_request = Int(L"log_request", 1);
|
log_request = Int(L"log_request", 1);
|
||||||
log_save_each_line = Bool(L"log_save_each_line", false);
|
log_save_each_line = Bool(L"log_save_each_line", false);
|
||||||
@@ -153,9 +148,15 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
log_post_value_size = Size(L"log_post_value_size", 80);
|
log_post_value_size = Size(L"log_post_value_size", 80);
|
||||||
log_env_variables = Bool(L"log_env_variables", false);
|
log_env_variables = Bool(L"log_env_variables", false);
|
||||||
log_env_http_variables = Bool(L"log_env_http_variables", false);
|
log_env_http_variables = Bool(L"log_env_http_variables", false);
|
||||||
|
log_whole_http_post = Bool(L"log_whole_http_post", false);
|
||||||
log_http_answer_headers = Bool(L"log_http_answer_headers", false);
|
log_http_answer_headers = Bool(L"log_http_answer_headers", false);
|
||||||
|
|
||||||
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
|
post_file_max = Size(L"post_file_max", 8388608); // 8 MB
|
||||||
|
post_json_max = Size(L"post_json_max", 8388608); // 8 MB
|
||||||
|
post_max_object_items = Size(L"post_max_object_items", 1024);
|
||||||
|
post_max_table_items = Size(L"post_max_table_items", 4096);
|
||||||
|
post_max_all_items = Size(L"post_max_all_items", 8192);
|
||||||
|
post_max_nested_objects = Size(L"post_max_nested_objects", 32);
|
||||||
|
|
||||||
upload_dir = Text(L"upload_dir");
|
upload_dir = Text(L"upload_dir");
|
||||||
common_dir = Text(L"common_dir");
|
common_dir = Text(L"common_dir");
|
||||||
@@ -186,14 +187,33 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
templates_fun_prefix = Text(L"templates_fun_prefix", L"fun_");
|
templates_fun_prefix = Text(L"templates_fun_prefix", L"fun_");
|
||||||
templates_fun_postfix = Text(L"templates_fun_postfix", L".html");
|
templates_fun_postfix = Text(L"templates_fun_postfix", L".html");
|
||||||
templates_index = Text(L"templates_index", L"index.html");
|
templates_index = Text(L"templates_index", L"index.html");
|
||||||
|
templates_index_generic = Text(L"templates_index_generic", L"index_generic.html");
|
||||||
templates_index_raw = Text(L"templates_index_raw", L"index_raw.html");
|
templates_index_raw = Text(L"templates_index_raw", L"index_raw.html");
|
||||||
|
templates_request_status = Text(L"templates_request_status", L"request_status.html");
|
||||||
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
template_only_root_use_template_fun = Bool(L"template_only_root_use_template_fun", false);
|
||||||
|
|
||||||
http_session_id_name = Text(L"http_session_id_name", L"session_id");
|
use_internal_session_mechanism = Bool(L"use_internal_session_mechanism", true);
|
||||||
|
use_internal_loggin_mechanism = Bool(L"use_internal_loggin_mechanism", true);
|
||||||
|
|
||||||
|
session_cookie_name = Text(L"session_cookie_name", L"session_id");
|
||||||
|
session_cookie_path = Text(L"session_cookie_path", L"/");
|
||||||
|
session_cookie_domain = Text(L"session_cookie_domain", L"");
|
||||||
|
session_cookie_same_site = Int(L"session_cookie_same_site", 0);
|
||||||
|
session_cookie_http_only = Bool(L"session_cookie_http_only", false);
|
||||||
|
session_cookie_secure = Bool(L"session_cookie_secure", false);
|
||||||
|
|
||||||
|
db_conn_string = Text(L"db_conn_string");
|
||||||
|
db_host = Text(L"db_host");
|
||||||
|
db_hostaddr = Text(L"db_hostaddr");
|
||||||
|
db_port = Text(L"db_port");
|
||||||
db_database = Text(L"db_database");
|
db_database = Text(L"db_database");
|
||||||
db_user = Text(L"db_user");
|
db_user = Text(L"db_user");
|
||||||
db_pass = Text(L"db_pass");
|
db_pass = Text(L"db_pass");
|
||||||
db_postgresql_smaller_than_10 = Bool(L"db_postgresql_smaller_than_10", false);
|
db_startup_connection_max_attempts = Size(L"db_startup_connection_max_attempts", 0);
|
||||||
|
db_startup_connection_attempt_delay = Size(L"db_startup_connection_attempt_delay", 5);
|
||||||
|
db_make_migration_if_needed = Bool(L"db_make_migration_if_needed", true);
|
||||||
|
db_stop_if_migration_fails = Bool(L"db_stop_if_migration_fails", true);
|
||||||
|
|
||||||
|
|
||||||
item_url_empty = Text(L"item_url_empty");
|
item_url_empty = Text(L"item_url_empty");
|
||||||
|
|
||||||
@@ -239,9 +259,8 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
compression_page_min_size = Size(L"compression_page_min_size", 512);
|
compression_page_min_size = Size(L"compression_page_min_size", 512);
|
||||||
compression_encoding = Int(L"compression_encoding", 20);
|
compression_encoding = Int(L"compression_encoding", 20);
|
||||||
|
|
||||||
html_filter = Bool(L"html_filter", true);
|
html_filter = Bool(L"html_filter", false);
|
||||||
html_filter_trim_white = Bool(L"html_filter_trim_white", true);
|
html_filter_white_char_mode = Int(L"html_filter_white_char_mode", 2);
|
||||||
html_filter_break_word = Int(L"html_filter_break_word", 60);
|
|
||||||
html_filter_wrap_line = Int(L"html_filter_wrap_line", 110);
|
html_filter_wrap_line = Int(L"html_filter_wrap_line", 110);
|
||||||
html_filter_tabs = Size(L"html_filter_tabs", 2);
|
html_filter_tabs = Size(L"html_filter_tabs", 2);
|
||||||
html_filter_orphans = Bool(L"html_filter_orphans", true);
|
html_filter_orphans = Bool(L"html_filter_orphans", true);
|
||||||
@@ -256,7 +275,9 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
|
|
||||||
title_separator = Text(L"title_separator", L" / ");
|
title_separator = Text(L"title_separator", L" / ");
|
||||||
|
|
||||||
http_header_send_file = Text(L"http_header_send_file", L"X-LIGHTTPD-send-file");
|
send_file_mode = Int(L"send_file_mode", 0);
|
||||||
|
send_file_header = Text(L"send_file_header", L"X-SENDFILE");
|
||||||
|
send_file_relative_prefix = Text(L"send_file_relative_prefix", L"upload-files-internal");
|
||||||
|
|
||||||
editors_html_safe_mode = Bool(L"editors_html_safe_mode", true);
|
editors_html_safe_mode = Bool(L"editors_html_safe_mode", true);
|
||||||
editors_html_safe_mode_skip_root = Bool(L"editors_html_safe_mode_skip_root", true);
|
editors_html_safe_mode_skip_root = Bool(L"editors_html_safe_mode_skip_root", true);
|
||||||
@@ -287,8 +308,20 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
ezc_max_elements = Size(L"ezc_max_elements", 50000);
|
ezc_max_elements = Size(L"ezc_max_elements", 50000);
|
||||||
ezc_max_loop_elements = Size(L"ezc_max_loop_elements", 5000);
|
ezc_max_loop_elements = Size(L"ezc_max_loop_elements", 5000);
|
||||||
ezc_out_streams_size = Size(L"ezc_out_streams_size", 128);
|
ezc_out_streams_size = Size(L"ezc_out_streams_size", 128);
|
||||||
ezc_error_prefix = Text(L"ezc_error_prefix", L"<!-- ");
|
request_frame_parameter = Text(L"request_frame_parameter", L"frame");
|
||||||
ezc_error_postfix = Text(L"ezc_error_postfix", L" -->");
|
request_all_frames_parameter = Text(L"request_all_frames_parameter", L"all_frames");
|
||||||
|
request_main_stream_parameter = Text(L"request_main_stream_parameter", L"main_stream");
|
||||||
|
|
||||||
|
request_frame_parameter_max_length = Size(L"request_frame_parameter_max_length", 128);
|
||||||
|
request_frame_parameter_max_frames = Size(L"request_frame_parameter_max_frames", 16);
|
||||||
|
|
||||||
|
xml_root = Text(L"xml_root", L"winix");
|
||||||
|
bin_stream_field = Text(L"bin_stream_field", L"bin_stream");
|
||||||
|
main_stream_field = Text(L"main_stream_field", L"main_stream");
|
||||||
|
ezc_frames_field = Text(L"ezc_frames_field", L"ezc_frames");
|
||||||
|
request_max_accept_fields = Size(L"request_max_accept_fields", 8);
|
||||||
|
request_max_accept_language_fields = Size(L"request_max_accept_language_fields", 8);
|
||||||
|
|
||||||
|
|
||||||
account_need_email_verification = Bool(L"account_need_email_verification", true);
|
account_need_email_verification = Bool(L"account_need_email_verification", true);
|
||||||
reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400);
|
reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400);
|
||||||
@@ -313,12 +346,22 @@ void Config::AssignValues(bool stdout_is_closed)
|
|||||||
incorrect_login_cannot_login_delay = Size(L"incorrect_login_cannot_login_delay", 1800);
|
incorrect_login_cannot_login_delay = Size(L"incorrect_login_cannot_login_delay", 1800);
|
||||||
|
|
||||||
pid_file = Text(L"pid_file", L"");
|
pid_file = Text(L"pid_file", L"");
|
||||||
allow_ezc_out_in_executable_items = Bool(L"allow_ezc_out_in_executable_items", false);
|
allow_ezc_frames_in_executable_items = Bool(L"allow_ezc_frames_in_executable_items", false);
|
||||||
|
|
||||||
check_proxy_ip_header = Bool(L"check_proxy_ip_header", false);
|
check_proxy_ip_header = Bool(L"check_proxy_ip_header", false);
|
||||||
proxy_ip_header = Text(L"proxy_ip_header", L"X_Real_IP");
|
proxy_ip_header = Text(L"proxy_ip_header", L"X_Real_IP");
|
||||||
|
|
||||||
|
use_antispam_mechanism_for_not_logged_users = Bool(L"use_antispam_mechanism_for_not_logged_users", true);
|
||||||
antispam_list_max_size = Size(L"antispam_list_max_size", 10);
|
antispam_list_max_size = Size(L"antispam_list_max_size", 10);
|
||||||
|
add_header_cache_no_store_in_htmx_request = Bool(L"add_header_cache_no_store_in_htmx_request", true);
|
||||||
|
|
||||||
|
request_queue_job_limit = Size(L"request_queue_job_limit", 1024);
|
||||||
|
|
||||||
|
ListText(L"allowed_origins", allowed_origins);
|
||||||
|
allow_all_origins = Bool(L"allow_all_origins", true);
|
||||||
|
are_cors_preflight_requests_available = Bool(L"are_cors_preflight_requests_available", false);
|
||||||
|
ListText(L"access_control_expose_headers", access_control_expose_headers);
|
||||||
|
access_control_allow_credentials = Bool(L"access_control_allow_credentials", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -381,150 +424,123 @@ void Config::CheckPasswd()
|
|||||||
|
|
||||||
std::wstring Config::Text(const wchar_t * name)
|
std::wstring Config::Text(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return space.Text(name);
|
return space.to_wstr(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
|
std::wstring Config::Text(const wchar_t * name, const wchar_t * def)
|
||||||
{
|
{
|
||||||
return space.Text(name, def);
|
return space.to_wstr(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::wstring Config::Text(const std::wstring & name, const wchar_t * def)
|
std::wstring Config::Text(const std::wstring & name, const wchar_t * def)
|
||||||
{
|
{
|
||||||
return space.Text(name, def);
|
return space.to_wstr(name, def);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring & Config::TextRef(const wchar_t * name)
|
|
||||||
{
|
|
||||||
return space.TextRef(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring & Config::TextRef(const wchar_t * name, const wchar_t * def)
|
|
||||||
{
|
|
||||||
return space.TextRef(name, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring & Config::TextRef(const std::wstring & name, const wchar_t * def)
|
|
||||||
{
|
|
||||||
return space.TextRef(name, def);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Config::Int(const wchar_t * name)
|
int Config::Int(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return space.Int(name);
|
return space.to_int(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Config::Int(const wchar_t * name, int def)
|
int Config::Int(const wchar_t * name, int def)
|
||||||
{
|
{
|
||||||
return space.Int(name, def);
|
return space.to_int(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Config::Int(const std::wstring & name, int def)
|
int Config::Int(const std::wstring & name, int def)
|
||||||
{
|
{
|
||||||
return space.Int(name, def);
|
return space.to_int(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long Config::Long(const wchar_t * name)
|
long Config::Long(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return space.Long(name);
|
return space.to_long(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
long Config::Long(const wchar_t * name, long def)
|
long Config::Long(const wchar_t * name, long def)
|
||||||
{
|
{
|
||||||
return space.Long(name, def);
|
return space.to_long(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
long Config::Long(const std::wstring & name, long def)
|
long Config::Long(const std::wstring & name, long def)
|
||||||
{
|
{
|
||||||
return space.Long(name, def);
|
return space.to_long(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Config::Size(const wchar_t * name)
|
size_t Config::Size(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return space.Size(name);
|
return space.to_ulong(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t Config::Size(const wchar_t * name, size_t def)
|
size_t Config::Size(const wchar_t * name, size_t def)
|
||||||
{
|
{
|
||||||
return space.Size(name, def);
|
return space.to_ulong(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t Config::Size(const std::wstring & name, size_t def)
|
size_t Config::Size(const std::wstring & name, size_t def)
|
||||||
{
|
{
|
||||||
return space.Size(name, def);
|
return space.to_ulong(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::Bool(const wchar_t * name)
|
bool Config::Bool(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return space.Bool(name);
|
return space.to_bool(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::Bool(const wchar_t * name, bool def)
|
bool Config::Bool(const wchar_t * name, bool def)
|
||||||
{
|
{
|
||||||
return space.Bool(name, def);
|
return space.to_bool(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::Bool(const std::wstring & name, bool def)
|
bool Config::Bool(const std::wstring & name, bool def)
|
||||||
{
|
{
|
||||||
return space.Bool(name, def);
|
return space.to_bool(name, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
bool Config::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||||
{
|
{
|
||||||
return space.ListText(name, list);
|
return space.to_list(name, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
bool Config::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||||
{
|
{
|
||||||
return space.ListText(name, list);
|
return space.to_list(name, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Config::HasValue(const wchar_t * name, const wchar_t * value)
|
bool Config::HasValue(const wchar_t * name, const wchar_t * value)
|
||||||
{
|
{
|
||||||
return space.HasValue(name, value);
|
return space.has_value(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)
|
bool Config::HasValue(const std::wstring & name, const std::wstring & value)
|
||||||
{
|
{
|
||||||
return space.HasValue(name, value);
|
return space.has_value(name.c_str(), value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Config::Print(std::wostream & out)
|
|
||||||
{
|
|
||||||
space.Serialize(out);
|
//void Config::Print(std::wostream & out)
|
||||||
}
|
//{
|
||||||
|
// space.serialize_to_space_stream(out);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+299
-48
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -53,10 +53,6 @@ class Config
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// name of the config file
|
|
||||||
// this is the parameter passed to winix programm
|
|
||||||
std::wstring config_file;
|
|
||||||
|
|
||||||
// server mode
|
// server mode
|
||||||
// you can assign any string to it such as "production" "dev"
|
// you can assign any string to it such as "production" "dev"
|
||||||
// this value is not used by winix itself
|
// this value is not used by winix itself
|
||||||
@@ -88,7 +84,8 @@ public:
|
|||||||
// the log level (how much info should be inserted to logs)
|
// the log level (how much info should be inserted to logs)
|
||||||
// 1 - minimum
|
// 1 - minimum
|
||||||
// 2 - (default)
|
// 2 - (default)
|
||||||
// 3 - maximum - all logs
|
// 3 - more logs
|
||||||
|
// 4 - maximum - all logs
|
||||||
int log_level;
|
int log_level;
|
||||||
|
|
||||||
// logging to stdout too
|
// logging to stdout too
|
||||||
@@ -97,7 +94,7 @@ public:
|
|||||||
bool log_stdout;
|
bool log_stdout;
|
||||||
|
|
||||||
// how many requests should be saved in the same time
|
// how many requests should be saved in the same time
|
||||||
// if you have a very busy server you can incrase this value
|
// if you have a very busy server you can increase this value
|
||||||
// default: 1
|
// default: 1
|
||||||
int log_request;
|
int log_request;
|
||||||
|
|
||||||
@@ -134,11 +131,17 @@ public:
|
|||||||
std::wstring log_delimiter;
|
std::wstring log_delimiter;
|
||||||
|
|
||||||
// log environment variables (fastcgi environment)
|
// log environment variables (fastcgi environment)
|
||||||
|
// default: false;
|
||||||
bool log_env_variables;
|
bool log_env_variables;
|
||||||
|
|
||||||
// log environment http variables (only HTTP_* variables from fastcgi environment)
|
// log environment http variables (only HTTP_* variables from fastcgi environment)
|
||||||
|
// default: false;
|
||||||
bool log_env_http_variables;
|
bool log_env_http_variables;
|
||||||
|
|
||||||
|
// log the whole http post structure (in json format) after parsing the post input
|
||||||
|
// default: false;
|
||||||
|
bool log_whole_http_post;
|
||||||
|
|
||||||
// log headers (+cookies) which are returned to the client
|
// log headers (+cookies) which are returned to the client
|
||||||
// this is what winix has generated -- the web server can change or add other headers
|
// this is what winix has generated -- the web server can change or add other headers
|
||||||
// default: false
|
// default: false
|
||||||
@@ -147,16 +150,29 @@ public:
|
|||||||
// fast cgi: socket (unix domain)
|
// fast cgi: socket (unix domain)
|
||||||
std::wstring fcgi_socket;
|
std::wstring fcgi_socket;
|
||||||
|
|
||||||
|
// fast cgi: whether to change chmod of the socket
|
||||||
|
// default: true
|
||||||
|
// if true then you should set fcgi_socket_chmod as well
|
||||||
|
bool fcgi_set_socket_chmod;
|
||||||
|
|
||||||
|
// fast cgi: whether to change owner/group of the socket
|
||||||
|
// default: true
|
||||||
|
// if true then you should set fcgi_socket_user and fcgi_socket_group as well
|
||||||
|
bool fcgi_set_socket_owner;
|
||||||
|
|
||||||
// fast cgi: socket permissions
|
// fast cgi: socket permissions
|
||||||
|
// taken into account if fcgi_set_socket_chmod is true
|
||||||
// chmod and chown of the socket are set before winix drops privileges
|
// chmod and chown of the socket are set before winix drops privileges
|
||||||
int fcgi_socket_chmod;
|
int fcgi_socket_chmod;
|
||||||
|
|
||||||
// fast cgi: owner of the socket
|
// fast cgi: owner of the socket
|
||||||
// chmod and chown of the socket are set before winix drops privileges
|
// chmod and chown of the socket are set before winix drops privileges
|
||||||
|
// taken into account if fcgi_set_socket_owner is true
|
||||||
std::wstring fcgi_socket_user;
|
std::wstring fcgi_socket_user;
|
||||||
|
|
||||||
// fast cgi: group of the socket
|
// fast cgi: group of the socket
|
||||||
// chmod and chown of the socket are set before winix drops privileges
|
// chmod and chown of the socket are set before winix drops privileges
|
||||||
|
// taken into account if fcgi_set_socket_owner is true
|
||||||
std::wstring fcgi_socket_group;
|
std::wstring fcgi_socket_group;
|
||||||
|
|
||||||
// fcgi_socket_listen is the listen queue depth used in the listen() call
|
// fcgi_socket_listen is the listen queue depth used in the listen() call
|
||||||
@@ -164,6 +180,12 @@ public:
|
|||||||
// default: 100
|
// default: 100
|
||||||
int fcgi_socket_listen;
|
int fcgi_socket_listen;
|
||||||
|
|
||||||
|
// in order to read a request we need to properly initialize a FastCGI structure by
|
||||||
|
// using FCGX_InitRequest function, if FCGX_InitRequest fails then we wait fcgi_cannot_create_request_delay
|
||||||
|
// seconds and trying again
|
||||||
|
// default: 3
|
||||||
|
size_t fcgi_cannot_create_request_delay;
|
||||||
|
|
||||||
std::wstring templates_dir;
|
std::wstring templates_dir;
|
||||||
std::wstring templates_dir_default; // html templates from winix
|
std::wstring templates_dir_default; // html templates from winix
|
||||||
|
|
||||||
@@ -181,26 +203,117 @@ public:
|
|||||||
// default: index.html
|
// default: index.html
|
||||||
std::wstring templates_index;
|
std::wstring templates_index;
|
||||||
|
|
||||||
|
// html template used to send generic content - without site-css styles and markup (only uikit)
|
||||||
|
// default: index_generic.html
|
||||||
|
std::wstring templates_index_generic;
|
||||||
|
|
||||||
// html template used to send raw content
|
// html template used to send raw content
|
||||||
// default: index_raw.html
|
// default: index_raw.html
|
||||||
std::wstring templates_index_raw;
|
std::wstring templates_index_raw;
|
||||||
|
|
||||||
|
// html template used to show a http status such as Forbidden or Not Found
|
||||||
|
// default: request_status.html
|
||||||
|
std::wstring templates_request_status;
|
||||||
|
|
||||||
// if true then only root can use 'template' winix function
|
// if true then only root can use 'template' winix function
|
||||||
// default: false
|
// default: false
|
||||||
bool template_only_root_use_template_fun;
|
bool template_only_root_use_template_fun;
|
||||||
|
|
||||||
|
// the database connection string
|
||||||
|
// https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNSTRING
|
||||||
|
// default: empty
|
||||||
|
// if empty then winix uses db_host and db_hostaddr
|
||||||
|
std::wstring db_conn_string;
|
||||||
|
|
||||||
|
// the database host name used if db_conn_string is empty
|
||||||
|
// default: empty
|
||||||
|
std::wstring db_host;
|
||||||
|
|
||||||
|
// the database host ip address used if db_conn_string is empty
|
||||||
|
// default: empty
|
||||||
|
// if db_host is empty and db_hostaddr is empty then winix connects to a Unix-domain socket
|
||||||
|
// meaning of db_host and db_hostaddr parameters is the same as described in
|
||||||
|
// https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNSTRING
|
||||||
|
//
|
||||||
|
// from above documentation:
|
||||||
|
// Using hostaddr allows the application to avoid a host name look-up, which might be important
|
||||||
|
// in applications with time constraints. However, a host name is required for GSSAPI or SSPI
|
||||||
|
// authentication methods, as well as for verify-full SSL certificate verification.
|
||||||
|
// The following rules are used:
|
||||||
|
//
|
||||||
|
// - If host is specified without hostaddr, a host name lookup occurs.
|
||||||
|
//
|
||||||
|
// - If hostaddr is specified without host, the value for hostaddr gives the server network address.
|
||||||
|
// The connection attempt will fail if the authentication method requires a host name.
|
||||||
|
//
|
||||||
|
// - If both host and hostaddr are specified, the value for hostaddr gives the server network address.
|
||||||
|
// The value for host is ignored unless the authentication method requires it, in which case it will
|
||||||
|
// be used as the host name.
|
||||||
|
std::wstring db_hostaddr;
|
||||||
|
|
||||||
|
// the database port number
|
||||||
|
std::wstring db_port;
|
||||||
|
|
||||||
// the database name, user name and a password for the PostgreSQL database
|
// the database name, user name and a password for the PostgreSQL database
|
||||||
std::wstring db_database;
|
std::wstring db_database;
|
||||||
std::wstring db_user;
|
std::wstring db_user;
|
||||||
std::wstring db_pass;
|
std::wstring db_pass;
|
||||||
|
|
||||||
// is the PostgreSQL later than 10
|
// specify how many times we can try to connect to the database at startup
|
||||||
// default false
|
// default 0 (infinite)
|
||||||
// if true then we are not using ROW() statements in sql query
|
size_t db_startup_connection_max_attempts;
|
||||||
bool db_postgresql_smaller_than_10;
|
|
||||||
|
// delay between each connection attempt at startup
|
||||||
|
// default 5 (seconds)
|
||||||
|
size_t db_startup_connection_attempt_delay;
|
||||||
|
|
||||||
|
// make database migration if needed
|
||||||
|
bool db_make_migration_if_needed;
|
||||||
|
|
||||||
|
// if a migration fails then stop winix
|
||||||
|
bool db_stop_if_migration_fails;
|
||||||
|
|
||||||
|
// use internal session mechanism
|
||||||
|
// default: true
|
||||||
|
// if false then we do not load/save and create internal sessions
|
||||||
|
// but there always be the temporary session object for a request
|
||||||
|
// also we do not load 'who' winix function
|
||||||
|
bool use_internal_session_mechanism;
|
||||||
|
|
||||||
|
// use internal loggin mechanism
|
||||||
|
// default: true
|
||||||
|
// if false then we do not load 'login' and 'logout' winix functions
|
||||||
|
// and the system will not allow to login through its api
|
||||||
|
bool use_internal_loggin_mechanism;
|
||||||
|
|
||||||
// the name of the cookie which has the session identifier
|
// the name of the cookie which has the session identifier
|
||||||
std::wstring http_session_id_name;
|
std::wstring session_cookie_name;
|
||||||
|
|
||||||
|
// session cookie path
|
||||||
|
// default: /
|
||||||
|
std::wstring session_cookie_path;
|
||||||
|
|
||||||
|
// session cookie domain
|
||||||
|
// if empty then the domain will be equal base_url
|
||||||
|
// default: empty
|
||||||
|
std::wstring session_cookie_domain;
|
||||||
|
|
||||||
|
// session cookie samesite attribute
|
||||||
|
// 0 - dont set the attribute
|
||||||
|
// 1 - Strict
|
||||||
|
// 2 - Lax
|
||||||
|
// 3 - None
|
||||||
|
// (values the same as values from CookieSameSite enum)
|
||||||
|
// default: 0
|
||||||
|
int session_cookie_same_site;
|
||||||
|
|
||||||
|
// whether or not set HttpOnly attribute on the session cookie
|
||||||
|
// default: false
|
||||||
|
bool session_cookie_http_only;
|
||||||
|
|
||||||
|
// whether or not set Secure attribute on the session cookie
|
||||||
|
// default: false
|
||||||
|
bool session_cookie_secure;
|
||||||
|
|
||||||
// string used in a place where is a user (or group) selected
|
// string used in a place where is a user (or group) selected
|
||||||
// !! IMPROVE ME should be moved to locales
|
// !! IMPROVE ME should be moved to locales
|
||||||
@@ -303,15 +416,15 @@ public:
|
|||||||
std::vector<std::wstring> plugin_file;
|
std::vector<std::wstring> plugin_file;
|
||||||
|
|
||||||
// should the html code be cleaned by the html filter
|
// should the html code be cleaned by the html filter
|
||||||
|
// default: false
|
||||||
bool html_filter;
|
bool html_filter;
|
||||||
|
|
||||||
// should white characters be trimmed
|
// how white characters between html tags are treated
|
||||||
bool html_filter_trim_white;
|
// 0 - WHITE_MODE_ORIGIN - they are copied from input to output
|
||||||
|
// 1 - WHITE_MODE_SINGLE_LINE - new line characters are removed
|
||||||
// when long words should be broken (a space will be inserted)
|
// 2 - WHITE_MODE_TREE - try to create a tree (some kind of pretty printing)
|
||||||
// default: after 60 non white characters there will be put a space
|
// default: 2
|
||||||
// set zero to turn off
|
int html_filter_white_char_mode;
|
||||||
size_t html_filter_break_word;
|
|
||||||
|
|
||||||
// when long lines should be broken (a new line character will be inserted)
|
// when long lines should be broken (a new line character will be inserted)
|
||||||
// default: 110
|
// default: 110
|
||||||
@@ -346,6 +459,35 @@ public:
|
|||||||
// 0 - not used
|
// 0 - not used
|
||||||
size_t post_file_max;
|
size_t post_file_max;
|
||||||
|
|
||||||
|
// maximum length of the input stream when parsing it as json
|
||||||
|
// default: 8388608 - 8MB
|
||||||
|
// set zero to disable checking
|
||||||
|
size_t post_json_max;
|
||||||
|
|
||||||
|
// maximum key/value pairs in one object when parsing post json structure
|
||||||
|
// default: 1024
|
||||||
|
// set zero to disable checking
|
||||||
|
// each winix function can set its own limits
|
||||||
|
size_t post_max_object_items;
|
||||||
|
|
||||||
|
// maximum items in one table when parsing post json structure
|
||||||
|
// default: 4096
|
||||||
|
// set zero to disable checking
|
||||||
|
// each winix function can set its own limits
|
||||||
|
size_t post_max_table_items;
|
||||||
|
|
||||||
|
// maximum items (key/values pairs of objects or table items) througout the whole post input json structure
|
||||||
|
// default: 8192
|
||||||
|
// set zero to disable checking
|
||||||
|
// each winix function can set its own limits
|
||||||
|
size_t post_max_all_items;
|
||||||
|
|
||||||
|
// maximum nested objects/tables when parsing post json structure
|
||||||
|
// default: 32
|
||||||
|
// set zero to disable checking
|
||||||
|
// each winix function can set its own limits
|
||||||
|
size_t post_max_nested_objects;
|
||||||
|
|
||||||
// directory for static files
|
// directory for static files
|
||||||
std::wstring upload_dir;
|
std::wstring upload_dir;
|
||||||
|
|
||||||
@@ -538,9 +680,39 @@ public:
|
|||||||
// separator used in <title> html tag
|
// separator used in <title> html tag
|
||||||
std::wstring title_separator;
|
std::wstring title_separator;
|
||||||
|
|
||||||
// http header recognized by www server as a file to send back
|
// how to send static files (uploaded by users) to the webserver
|
||||||
// default: X-LIGHTTPD-send-file
|
// 0 - winix will read the content of the file and send it back to the webserver
|
||||||
std::wstring http_header_send_file;
|
// 1 - winix will use send_file_header header with a full path to the file
|
||||||
|
// 2 - winix will use send_file_header header with a relative path to the file
|
||||||
|
// default: 0
|
||||||
|
// 0 can be be used with all webservers but it requires to copy the whole file content
|
||||||
|
// you can omit copying the content with values 1 or 2:
|
||||||
|
// for Apache set: 1
|
||||||
|
// for Lighttpd set: 1
|
||||||
|
// for Nginx set: 2
|
||||||
|
int send_file_mode;
|
||||||
|
|
||||||
|
// http header recognized by www server as a file to send back, used if send_file_mode is 1 or 2
|
||||||
|
// default: X-SENDFILE
|
||||||
|
// for Apache set: X-SENDFILE (Apache needs an external module: https://tn123.org/mod_xsendfile/)
|
||||||
|
// for Lighttpd set: X-LIGHTTPD-send-file (https://redmine.lighttpd.net/projects/1/wiki/X-LIGHTTPD-send-file)
|
||||||
|
// for Nginx set: X-Accel-Redirect (https://nginx.org/en/docs/http/ngx_http_core_module.html#internal)
|
||||||
|
std::wstring send_file_header;
|
||||||
|
|
||||||
|
// relative prefix used for sending static files if send_file_mode is 2
|
||||||
|
// default: "upload-files-internal"
|
||||||
|
// this prefix is added at the beginning of a relative file path e.g.
|
||||||
|
// /upload-files-internal/simplefs/normal/some_directories/file.jpg
|
||||||
|
//
|
||||||
|
// in Nginx config file use 'location' with the prefix, e.g:
|
||||||
|
// server {
|
||||||
|
// .....
|
||||||
|
// location /upload-files-internal/ {
|
||||||
|
// alias /path/to/winix/upload/; # trailing slash at the end
|
||||||
|
// internal;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
std::wstring send_file_relative_prefix;
|
||||||
|
|
||||||
// in editors (emacs, ckeditor,...) the html will be filtered and unsafe tags
|
// in editors (emacs, ckeditor,...) the html will be filtered and unsafe tags
|
||||||
// will be dropped (script, frame, etc.)
|
// will be dropped (script, frame, etc.)
|
||||||
@@ -615,6 +787,7 @@ public:
|
|||||||
// 2 - application/xml - for XHTML 1.0 or for XHTML 1.1
|
// 2 - application/xml - for XHTML 1.0 or for XHTML 1.1
|
||||||
// default: 0
|
// default: 0
|
||||||
// if utf8 is true then "; charset=UTF-8" will also be appended
|
// if utf8 is true then "; charset=UTF-8" will also be appended
|
||||||
|
// may it would be better to set just the string here instead of integers?
|
||||||
int content_type_header;
|
int content_type_header;
|
||||||
|
|
||||||
// global umask
|
// global umask
|
||||||
@@ -632,18 +805,56 @@ public:
|
|||||||
|
|
||||||
// how many output streams do we have in Request class
|
// how many output streams do we have in Request class
|
||||||
// those streams used in ajax responses
|
// those streams used in ajax responses
|
||||||
// you can use no more [ezc out] statements than this limit
|
// you can use no more [ezc frames] statements than this limit
|
||||||
// default: 128
|
// default: 128
|
||||||
size_t ezc_out_streams_size;
|
size_t ezc_out_streams_size;
|
||||||
|
|
||||||
// prefix and postfix used when there is an error in Ezc patterns
|
// the name of the url parameter for returning a frame, e.g. https://domain.tld/mydir/myfunction/frame:foo
|
||||||
// default:
|
// default: frame
|
||||||
// prefix: "<!-- "
|
std::wstring request_frame_parameter;
|
||||||
// postfix: " -->"
|
|
||||||
std::wstring ezc_error_prefix;
|
|
||||||
std::wstring ezc_error_postfix;
|
|
||||||
|
|
||||||
// when true then when a user want to create a new account
|
// the name of the url parameter for returning all frames, e.g. https://domain.tld/mydir/myfunction/all_frames
|
||||||
|
// default: all_frames
|
||||||
|
std::wstring request_all_frames_parameter;
|
||||||
|
|
||||||
|
// the name of the url parameter for returning the main ezc stream, e.g. https://domain.tld/mydir/myfunction/main_stream
|
||||||
|
// default: main_stream
|
||||||
|
std::wstring request_main_stream_parameter;
|
||||||
|
|
||||||
|
// max lenght of the url frame parameter
|
||||||
|
// default: 128
|
||||||
|
size_t request_frame_parameter_max_length;
|
||||||
|
|
||||||
|
// max number of frames in the frame url parameter (they are separated by a comma)
|
||||||
|
// default: 16
|
||||||
|
// if you need more frames you can use all_frames url parameter to return all frames
|
||||||
|
size_t request_frame_parameter_max_frames;
|
||||||
|
|
||||||
|
// the name of the root element when serializing request answer to xml
|
||||||
|
// default: winix
|
||||||
|
std::wstring xml_root;
|
||||||
|
|
||||||
|
// the name of the field of the binary stream when serializing a request
|
||||||
|
// default: bin_stream
|
||||||
|
std::wstring bin_stream_field;
|
||||||
|
|
||||||
|
// the name of the field of the main ezc stream when serializing a request
|
||||||
|
// default: main_stream
|
||||||
|
std::wstring main_stream_field;
|
||||||
|
|
||||||
|
// the name of the field (object) of the ezc frames when serializing a request
|
||||||
|
// default: ezc_frames
|
||||||
|
std::wstring ezc_frames_field;
|
||||||
|
|
||||||
|
// max Accept header mime types to be parsed in a request
|
||||||
|
// default: 8
|
||||||
|
size_t request_max_accept_fields;
|
||||||
|
|
||||||
|
// max Accept-Language languages to be parsed in a request
|
||||||
|
// default: 8
|
||||||
|
size_t request_max_accept_language_fields;
|
||||||
|
|
||||||
|
// 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
|
// he has to provide his email and a message will be sent back to him
|
||||||
// with a link to activate the account
|
// with a link to activate the account
|
||||||
// default: true
|
// default: true
|
||||||
@@ -752,10 +963,10 @@ public:
|
|||||||
// pid file is saved after winix has dropped privileges
|
// pid file is saved after winix has dropped privileges
|
||||||
std::wstring pid_file;
|
std::wstring pid_file;
|
||||||
|
|
||||||
// allow to use [ezc out] statement in executable items (used in 'run' winix function)
|
// allow to use [ezc frame] statements in executable items (used in 'run' winix function)
|
||||||
// default false
|
// default false
|
||||||
// warning: if you enable this options a user can override a different output stream when using ajax
|
// warning: if you enable this options a user can override a different output stream when using ajax
|
||||||
bool allow_ezc_out_in_executable_items;
|
bool allow_ezc_frames_in_executable_items;
|
||||||
|
|
||||||
|
|
||||||
// check whether there is a 'log_proxy_ip_header' header
|
// check whether there is a 'log_proxy_ip_header' header
|
||||||
@@ -767,7 +978,12 @@ public:
|
|||||||
// default: X_Real_IP
|
// default: X_Real_IP
|
||||||
std::wstring proxy_ip_header;
|
std::wstring proxy_ip_header;
|
||||||
|
|
||||||
// antispam mechanizm
|
// use an antispam mechanism for not logged users
|
||||||
|
// when they try to add a new item
|
||||||
|
// default: true
|
||||||
|
bool use_antispam_mechanism_for_not_logged_users;
|
||||||
|
|
||||||
|
// antispam mechanism
|
||||||
// size of an list for map: form_id to counter_id for anonymous users (each session has such an map)
|
// size of an list for map: form_id to counter_id for anonymous users (each session has such an map)
|
||||||
// this value allowes you to open the same or different html form in the browser more than once
|
// this value allowes you to open the same or different html form in the browser more than once
|
||||||
// and each form has its own form_id and counter_id
|
// and each form has its own form_id and counter_id
|
||||||
@@ -775,8 +991,50 @@ public:
|
|||||||
size_t antispam_list_max_size;
|
size_t antispam_list_max_size;
|
||||||
|
|
||||||
|
|
||||||
|
// send "Cache-Control: no-store, max-age=0" http header if a request is made by htmx library (ajax)
|
||||||
|
// if a webbrowser get a page from the cache then it will render just the last request without the whole html page (css, js, etc)
|
||||||
|
// https://github.com/bigskysoftware/htmx/issues/497
|
||||||
|
bool add_header_cache_no_store_in_htmx_request;
|
||||||
|
|
||||||
|
// a limit for the queue for requests
|
||||||
|
// when a request is scheduled to a job
|
||||||
|
// default: 1024
|
||||||
|
// if the limit is reached then the http status 503 Service Unavailable is returned
|
||||||
|
size_t request_queue_job_limit;
|
||||||
|
|
||||||
|
// list of allowed origins in cors requests
|
||||||
|
// can be set per controller in a method: virtual bool FunctionBase::IsOriginAvailable(const std::wstring & origin_url)
|
||||||
|
// default: empty
|
||||||
|
std::vector<std::wstring> allowed_origins;
|
||||||
|
|
||||||
|
// whether or not all origins are allowed if allowed_origins is empty
|
||||||
|
// default: true
|
||||||
|
// this is true by default because Origin header is sent not only in cors requests
|
||||||
|
// (you can still allow it in your function/controller by overriding IsOriginAvailable(...) method)
|
||||||
|
bool allow_all_origins;
|
||||||
|
|
||||||
|
// whether or not cors preflight requests are available
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
|
||||||
|
// default: false
|
||||||
|
bool are_cors_preflight_requests_available;
|
||||||
|
|
||||||
|
// list of additional headers sent in Access-Control-Expose-Headers header
|
||||||
|
// can be set per controller in a method: virtual void FunctionBase::AddAccessControlExposeHeadersHeader()
|
||||||
|
// default: empty
|
||||||
|
std::vector<std::wstring> access_control_expose_headers;
|
||||||
|
|
||||||
|
// if true return Access-Control-Allow-Credentials header equal "true"
|
||||||
|
// whethert credentials (e.g. cookies, authorization headers) are available in cors requests
|
||||||
|
// can be set per controller in a method: virtual bool FunctionBase::AreCorsCredentialsAvailable()
|
||||||
|
// default: false
|
||||||
|
bool access_control_allow_credentials;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Config();
|
Config();
|
||||||
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
|
bool ReadConfig(const std::wstring & config_file);
|
||||||
|
void AssignValuesFromSpace();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@@ -789,10 +1047,6 @@ public:
|
|||||||
std::wstring Text(const wchar_t * name, const wchar_t * def);
|
std::wstring Text(const wchar_t * name, const wchar_t * def);
|
||||||
std::wstring Text(const std::wstring & name, const wchar_t * def);
|
std::wstring Text(const std::wstring & name, const wchar_t * def);
|
||||||
|
|
||||||
std::wstring & TextRef(const wchar_t * name);
|
|
||||||
std::wstring & TextRef(const wchar_t * name, const wchar_t * def);
|
|
||||||
std::wstring & TextRef(const std::wstring & name, const wchar_t * def);
|
|
||||||
|
|
||||||
int Int(const wchar_t *);
|
int Int(const wchar_t *);
|
||||||
int Int(const wchar_t * name, int def);
|
int Int(const wchar_t * name, int def);
|
||||||
int Int(const std::wstring & name, int def);
|
int Int(const std::wstring & name, int def);
|
||||||
@@ -808,30 +1062,27 @@ public:
|
|||||||
bool ListText(const wchar_t * name, std::vector<std::wstring> & list);
|
bool ListText(const wchar_t * name, std::vector<std::wstring> & list);
|
||||||
bool ListText(const std::wstring & name, std::vector<std::wstring> & list);
|
bool ListText(const std::wstring & name, std::vector<std::wstring> & list);
|
||||||
|
|
||||||
bool HasValue(const wchar_t * name, const wchar_t * value);
|
bool HasValue(const wchar_t * name, const 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);
|
bool HasValue(const std::wstring & name, const std::wstring & value);
|
||||||
|
|
||||||
// for debug
|
// for debug
|
||||||
void Print(std::wostream & out);
|
//void Print(std::wostream & out);
|
||||||
|
|
||||||
// raw access to the config
|
// raw access to the config
|
||||||
PT::Space space;
|
pt::Space space;
|
||||||
|
|
||||||
|
|
||||||
void SetFileLog(FileLog * file_log);
|
void SetFileLog(FileLog * file_log);
|
||||||
void SetLogBuffer(PT::WTextStream * log_buffer);
|
void SetLogBuffer(pt::WTextStream * log_buffer);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
PT::SpaceParser parser;
|
pt::SpaceParser parser;
|
||||||
bool errors_to_stdout;
|
|
||||||
Log log;
|
Log log;
|
||||||
|
|
||||||
void ShowError();
|
void ShowError(const std::wstring & config_file);
|
||||||
void AssignValues(bool stdout_is_closed);
|
void AssignValues();
|
||||||
void SetAdditionalVariables();
|
void SetAdditionalVariables();
|
||||||
void CheckPasswd();
|
void CheckPasswd();
|
||||||
|
|
||||||
|
|||||||
+32
-28
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -78,7 +78,7 @@ bool Crypt::HashBin(int hash, const char * in, size_t inlen, std::string & out)
|
|||||||
|
|
||||||
run.Clear();
|
run.Clear();
|
||||||
run.set_dependency(this);
|
run.set_dependency(this);
|
||||||
PT::WideToUTF8(config->opensll_path, command);
|
pt::wide_to_utf8(config->opensll_path, command);
|
||||||
run.Cmd(command);
|
run.Cmd(command);
|
||||||
run.Par("dgst");
|
run.Par("dgst");
|
||||||
run.Par("-binary");
|
run.Par("-binary");
|
||||||
@@ -119,7 +119,7 @@ bool Crypt::HashBin(int hash, const std::string & in, std::string & out)
|
|||||||
|
|
||||||
bool Crypt::HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out)
|
bool Crypt::HashBin(int hash, const wchar_t * in, size_t inlen, std::string & out)
|
||||||
{
|
{
|
||||||
PT::WideToUTF8(in, inlen, bufina);
|
pt::wide_to_utf8(in, inlen, bufina);
|
||||||
int res = HashBin(hash, bufina.c_str(), bufina.size(), out);
|
int res = HashBin(hash, bufina.c_str(), bufina.size(), out);
|
||||||
bufina.clear();
|
bufina.clear();
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ bool Crypt::RSA(bool encrypt, const char * keypath, const char * in, size_t inle
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
run.Clear();
|
run.Clear();
|
||||||
PT::WideToUTF8(config->opensll_path, command);
|
pt::wide_to_utf8(config->opensll_path, command);
|
||||||
run.Cmd(command);
|
run.Cmd(command);
|
||||||
|
|
||||||
run.Par("rsautl");
|
run.Par("rsautl");
|
||||||
@@ -243,7 +243,7 @@ bool Crypt::RSA(bool encrypt, const std::string & keypath, const std::string & i
|
|||||||
|
|
||||||
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out)
|
bool Crypt::RSA(bool encrypt, const wchar_t * keypath, const char * in, size_t inlen, std::string & out)
|
||||||
{
|
{
|
||||||
PT::WideToUTF8(keypath, keypatha);
|
pt::wide_to_utf8(keypath, keypatha);
|
||||||
return RSA(encrypt, keypatha.c_str(), in, inlen, out);
|
return RSA(encrypt, keypatha.c_str(), in, inlen, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,28 +267,28 @@ bool Crypt::RSA(bool encrypt, const std::wstring & keypath, const std::string &
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::PassHash(const std::wstring & salt, UserPass & up)
|
bool Crypt::PassHash(const std::wstring & salt, User & user)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
up.pass_hash_salted = false;
|
user.is_pass_hash_salted = false;
|
||||||
|
|
||||||
if( up.pass_type != WINIX_CRYPT_HASH_NONE )
|
if( user.pass_type != WINIX_CRYPT_HASH_NONE )
|
||||||
{
|
{
|
||||||
pass_org = up.pass;
|
pass_org = user.password;
|
||||||
pass_salted = up.pass;
|
pass_salted = user.password;
|
||||||
pass_salted += salt;
|
pass_salted += salt;
|
||||||
|
|
||||||
if( HashHex(up.pass_type, pass_salted, up.pass) )
|
if( HashHex(user.pass_type, pass_salted, user.password) )
|
||||||
{
|
{
|
||||||
if( !salt.empty() )
|
if( !salt.empty() )
|
||||||
up.pass_hash_salted = true;
|
user.is_pass_hash_salted = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
|
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
|
||||||
|
|
||||||
up.pass = pass_org;
|
user.password = pass_org;
|
||||||
up.pass_type = WINIX_CRYPT_HASH_NONE;
|
user.pass_type = WINIX_CRYPT_HASH_NONE;
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,22 +301,23 @@ return result;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Crypt::PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up)
|
bool Crypt::PassCrypt(const std::wstring & path_to_rsa_private_key, User & user)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
ClearString(up.pass_encrypted);
|
ClearString(user.pass_encrypted);
|
||||||
|
|
||||||
if( !path_to_rsa_private_key.empty() )
|
if( !path_to_rsa_private_key.empty() )
|
||||||
{
|
{
|
||||||
PT::WideToUTF8(up.pass, passa);
|
pt::wide_to_utf8(user.password, passa);
|
||||||
|
|
||||||
if( RSA(true, path_to_rsa_private_key, passa, up.pass_encrypted) )
|
if( RSA(true, path_to_rsa_private_key, passa, user.pass_encrypted) )
|
||||||
{
|
{
|
||||||
|
ClearString(user.password);
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ClearString(up.pass_encrypted);
|
ClearString(user.pass_encrypted);
|
||||||
log << log1 << "AddUser: problem with encrypting, the password will not be encrypted!" << logend;
|
log << log1 << "AddUser: problem with encrypting, the password will not be encrypted!" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,27 +328,30 @@ return result;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Crypt::PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up)
|
void Crypt::PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, User & user)
|
||||||
{
|
{
|
||||||
PassHash(salt, up);
|
PassHash(salt, user);
|
||||||
PassCrypt(path_to_rsa_private_key, up);
|
PassCrypt(path_to_rsa_private_key, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void Crypt::PassHashCrypt(UserPass & up)
|
* we hashing user.password, may it would be better to get the password as a seperate argument?
|
||||||
|
*/
|
||||||
|
void Crypt::PassHashCrypt(User & user)
|
||||||
{
|
{
|
||||||
up.pass_type = config->pass_type;
|
user.pass_type = config->pass_type;
|
||||||
|
ClearString(user.pass_encrypted);
|
||||||
empty.clear();
|
empty.clear();
|
||||||
|
|
||||||
if( config->pass_hash_use_salt && !config->pass_hash_salt.empty() )
|
if( config->pass_hash_use_salt && !config->pass_hash_salt.empty() )
|
||||||
PassHash(config->pass_hash_salt, up);
|
PassHash(config->pass_hash_salt, user);
|
||||||
else
|
else
|
||||||
PassHash(empty, up);
|
PassHash(empty, user);
|
||||||
|
|
||||||
|
|
||||||
if( config->pass_use_rsa && !config->pass_rsa_private_key.empty() )
|
if( config->pass_use_rsa && !config->pass_rsa_private_key.empty() )
|
||||||
PassCrypt(config->pass_rsa_private_key, up);
|
PassCrypt(config->pass_rsa_private_key, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "run.h"
|
#include "run.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "user.h"
|
#include "models/user.h"
|
||||||
#include "winixbase.h"
|
#include "winixbase.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ public:
|
|||||||
if there is a problem with generating a hash the method stores a plain text password
|
if there is a problem with generating a hash the method stores a plain text password
|
||||||
and changes up.pass_type to zero (plain text passwords are not salted)
|
and changes up.pass_type to zero (plain text passwords are not salted)
|
||||||
*/
|
*/
|
||||||
bool PassHash(const std::wstring & salt, UserPass & up);
|
bool PassHash(const std::wstring & salt, User & user);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -195,7 +195,7 @@ public:
|
|||||||
if there is a problem (or the path to the key is empty) then up.pass_encrypted will be empty
|
if there is a problem (or the path to the key is empty) then up.pass_encrypted will be empty
|
||||||
and the method returns false
|
and the method returns false
|
||||||
*/
|
*/
|
||||||
bool PassCrypt(const std::wstring & path_to_rsa_private_key, UserPass & up);
|
bool PassCrypt(const std::wstring & path_to_rsa_private_key, User & user);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -217,7 +217,7 @@ public:
|
|||||||
up.pass_encrypted - encrypted password (if not empty)
|
up.pass_encrypted - encrypted password (if not empty)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, UserPass & up);
|
void PassHashCrypt(const std::wstring & salt, const std::wstring & path_to_rsa_private_key, User & user);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -232,7 +232,7 @@ public:
|
|||||||
up.pass_hash_salted - true if the hash is salted (plain text are never salted)
|
up.pass_hash_salted - true if the hash is salted (plain text are never salted)
|
||||||
up.pass_encrypted - encrypted password (if not empty)
|
up.pass_encrypted - encrypted password (if not empty)
|
||||||
*/
|
*/
|
||||||
void PassHashCrypt(UserPass & up);
|
void PassHashCrypt(User & user);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+9
-1
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -56,6 +56,14 @@ struct Cur
|
|||||||
|
|
||||||
// those pointers are never null, if there is no a session for the user
|
// those pointers are never null, if there is no a session for the user
|
||||||
// the 'session' pointer pointers at a special temporary session
|
// the 'session' pointer pointers at a special temporary session
|
||||||
|
|
||||||
|
Cur()
|
||||||
|
{
|
||||||
|
request = nullptr;
|
||||||
|
session = nullptr;
|
||||||
|
mount = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,13 +81,13 @@ return var_iter;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DirContainer::Iterator DirContainer::Begin()
|
DirContainer::ConstIterator DirContainer::Begin() const
|
||||||
{
|
{
|
||||||
return table.begin();
|
return table.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DirContainer::Iterator DirContainer::End()
|
DirContainer::ConstIterator DirContainer::End() const
|
||||||
{
|
{
|
||||||
return table.end();
|
return table.end();
|
||||||
}
|
}
|
||||||
@@ -255,6 +255,17 @@ return i->second;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DirContainer::ConstIterator DirContainer::FindId(long id) const
|
||||||
|
{
|
||||||
|
TableId::const_iterator i = table_id.find(id);
|
||||||
|
|
||||||
|
if( i == table_id.end() )
|
||||||
|
return table.end();
|
||||||
|
|
||||||
|
return i->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DirContainer::ParentIterator DirContainer::ParentBegin()
|
DirContainer::ParentIterator DirContainer::ParentBegin()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -37,8 +37,8 @@
|
|||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "item.h"
|
|
||||||
#include "winixbase.h"
|
#include "winixbase.h"
|
||||||
|
#include "models/item.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -52,6 +52,7 @@ class DirContainer : public WinixBase
|
|||||||
public:
|
public:
|
||||||
typedef std::list<Item> Table;
|
typedef std::list<Item> Table;
|
||||||
typedef Table::iterator Iterator;
|
typedef Table::iterator Iterator;
|
||||||
|
typedef Table::const_iterator ConstIterator;
|
||||||
typedef Table::size_type SizeType;
|
typedef Table::size_type SizeType;
|
||||||
|
|
||||||
typedef std::map<long, Iterator> TableId;
|
typedef std::map<long, Iterator> TableId;
|
||||||
@@ -66,8 +67,8 @@ public:
|
|||||||
Iterator GetEtc();
|
Iterator GetEtc();
|
||||||
Iterator GetVar();
|
Iterator GetVar();
|
||||||
|
|
||||||
Iterator Begin();
|
ConstIterator Begin() const;
|
||||||
Iterator End();
|
ConstIterator End() const;
|
||||||
SizeType Size();
|
SizeType Size();
|
||||||
bool Empty();
|
bool Empty();
|
||||||
Iterator PushBack(const Item & item);
|
Iterator PushBack(const Item & item);
|
||||||
@@ -75,6 +76,7 @@ public:
|
|||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
Iterator FindId(long id);
|
Iterator FindId(long id);
|
||||||
|
ConstIterator FindId(long id) const;
|
||||||
|
|
||||||
bool DelById(long id);
|
bool DelById(long id);
|
||||||
|
|
||||||
|
|||||||
+52
-32
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,7 +31,8 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
#include "dirs.h"
|
#include "dirs.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "notify/notify.h"
|
#include "notify/notify.h"
|
||||||
@@ -41,13 +42,6 @@ namespace Winix
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Dirs::SetDb(Db * pdb)
|
|
||||||
{
|
|
||||||
db = pdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Dirs::SetCur(Cur * pcur)
|
void Dirs::SetCur(Cur * pcur)
|
||||||
{
|
{
|
||||||
cur = pcur;
|
cur = pcur;
|
||||||
@@ -60,9 +54,9 @@ void Dirs::SetNotify(Notify * pnotify)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Dirs::set_dependency(WinixModel * winix_model)
|
void Dirs::set_dependency(WinixModelDeprecated * winix_model)
|
||||||
{
|
{
|
||||||
WinixModel::set_dependency(winix_model);
|
WinixModelDeprecated::set_dependency(winix_model);
|
||||||
dir_tab.set_dependency(winix_model);
|
dir_tab.set_dependency(winix_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +70,7 @@ void Dirs::Clear()
|
|||||||
bool Dirs::HasReadExecAccessForRoot(const Item & item)
|
bool Dirs::HasReadExecAccessForRoot(const Item & item)
|
||||||
{
|
{
|
||||||
// there must be at least one 'x' (for the root)
|
// there must be at least one 'x' (for the root)
|
||||||
return (item.privileges & 01111) != 0;
|
return (item.item_content.privileges & 01111) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,28 +82,32 @@ void Dirs::CheckRootDir()
|
|||||||
{
|
{
|
||||||
if( !HasReadExecAccessForRoot(*i) )
|
if( !HasReadExecAccessForRoot(*i) )
|
||||||
{
|
{
|
||||||
i->privileges = 07555;
|
i->item_content.privileges = 07555;
|
||||||
log << log1 << "Dirs: there is no access for a root (admin) to the root dir, setting 07555 for the root directory" << logend;
|
log << log1 << "Dirs: there is no access for a root (admin) to the root dir, setting 07555 for the root directory" << logend;
|
||||||
db->EditPrivById(*i, i->id);
|
i->item_content.set_connector(model_connector);
|
||||||
|
i->item_content.date_modification = std::time(nullptr);
|
||||||
|
i->item_content.save(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log << log1 << "Dirs: there is no a root directory in the database (creating one)" << logend;
|
log << log1 << "Dirs: there is no a root directory in the database (creating one)" << logend;
|
||||||
|
|
||||||
Item root;
|
ItemModelData item_data;
|
||||||
|
item_data.prepare_unique_url = false;
|
||||||
|
|
||||||
|
Item root;
|
||||||
|
root.set_connector(model_connector);
|
||||||
root.type = Item::dir;
|
root.type = Item::dir;
|
||||||
root.parent_id = -1;
|
root.parent_id = -1;
|
||||||
root.user_id = -1;
|
root.item_content.user_id = -1;
|
||||||
root.group_id = -1;
|
root.item_content.group_id = -1;
|
||||||
root.privileges = 07555;
|
root.item_content.privileges = 07555;
|
||||||
|
root.item_content.date_creation = std::time(nullptr);
|
||||||
|
root.item_content.date_modification = root.item_content.date_creation;
|
||||||
|
|
||||||
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
|
if( root.insert(item_data) )
|
||||||
// !! zrobic jakis wyjatek do wprowadzania roota?
|
|
||||||
if( db->AddItem(root) == WINIX_ERR_OK )
|
|
||||||
{
|
{
|
||||||
dir_tab.PushBack(root);
|
dir_tab.PushBack(root);
|
||||||
}
|
}
|
||||||
@@ -122,7 +120,15 @@ void Dirs::ReadDirs()
|
|||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
db->GetDirs(dir_tab);
|
//db->GetDirs(dir_tab);
|
||||||
|
morm::Finder<Item> finder(model_connector);
|
||||||
|
std::list<Item> all_dirs = finder.select().where().eq(L"type", static_cast<int>(Item::Type::dir)).get_list();
|
||||||
|
|
||||||
|
for(Item & item : all_dirs)
|
||||||
|
{
|
||||||
|
dir_tab.PushBack(item);
|
||||||
|
}
|
||||||
|
|
||||||
CheckRootDir();
|
CheckRootDir();
|
||||||
dir_tab.FindSpecialFolders();
|
dir_tab.FindSpecialFolders();
|
||||||
}
|
}
|
||||||
@@ -443,9 +449,20 @@ Item * Dirs::GetDir(long id)
|
|||||||
DirContainer::Iterator i = dir_tab.FindId(id);
|
DirContainer::Iterator i = dir_tab.FindId(id);
|
||||||
|
|
||||||
if( i == dir_tab.End() )
|
if( i == dir_tab.End() )
|
||||||
return 0;
|
return nullptr;
|
||||||
|
|
||||||
return &(*i);
|
return &(*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Item * Dirs::GetDir(long id) const
|
||||||
|
{
|
||||||
|
DirContainer::ConstIterator i = dir_tab.FindId(id);
|
||||||
|
|
||||||
|
if( i == dir_tab.End() )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return &(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -723,17 +740,19 @@ bool Dirs::DelDir(long dir_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Error Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int notify_code)
|
bool Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int notify_code)
|
||||||
{
|
{
|
||||||
if( pdir )
|
if( pdir )
|
||||||
*pdir = 0;
|
*pdir = 0;
|
||||||
|
|
||||||
if( item.type != Item::dir )
|
if( item.type != Item::dir )
|
||||||
return WINIX_ERR_DIR_EXPECTED;
|
return false;
|
||||||
|
|
||||||
Error status = db->AddItem(item);
|
//Error status = db->AddItem(item);
|
||||||
|
//item.set_connector(model_connector);
|
||||||
|
bool status = item.insert();
|
||||||
|
|
||||||
if( status == WINIX_ERR_OK )
|
if( status )
|
||||||
{
|
{
|
||||||
Item * d = AddDir(item);
|
Item * d = AddDir(item);
|
||||||
|
|
||||||
@@ -764,10 +783,11 @@ Item * Dirs::CreateVarDir()
|
|||||||
|
|
||||||
if( root )
|
if( root )
|
||||||
{
|
{
|
||||||
|
v.set_connector(root->get_connector());
|
||||||
v.parent_id = root->id;
|
v.parent_id = root->id;
|
||||||
v.user_id = root->user_id;
|
v.item_content.user_id = root->item_content.user_id;
|
||||||
v.group_id = root->group_id;
|
v.item_content.group_id = root->item_content.group_id;
|
||||||
v.privileges = root->privileges;
|
v.item_content.privileges = root->item_content.privileges;
|
||||||
v.subject = L"var";
|
v.subject = L"var";
|
||||||
v.url = L"var";
|
v.url = L"var";
|
||||||
v.type = Item::dir;
|
v.type = Item::dir;
|
||||||
|
|||||||
+8
-10
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -39,12 +39,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "item.h"
|
|
||||||
#include "dircontainer.h"
|
#include "dircontainer.h"
|
||||||
#include "db/db.h"
|
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "winixmodel.h"
|
#include "models/item.h"
|
||||||
|
#include "winixmodeldeprecated.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -58,7 +56,7 @@ class Notify;
|
|||||||
// (we will support '..' in the future)
|
// (we will support '..' in the future)
|
||||||
|
|
||||||
|
|
||||||
class Dirs : public WinixModel
|
class Dirs : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -66,10 +64,9 @@ public:
|
|||||||
void ReadDirs();
|
void ReadDirs();
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
void SetCur(Cur * pcur);
|
||||||
void SetDb(Db * pdb);
|
|
||||||
void SetNotify(Notify * pnotify);
|
void SetNotify(Notify * pnotify);
|
||||||
|
|
||||||
void set_dependency(WinixModel * winix_model);
|
void set_dependency(WinixModelDeprecated * winix_model);
|
||||||
|
|
||||||
// these methods return false if there is no such a dir
|
// these methods return false if there is no such a dir
|
||||||
bool IsDir(long dir_id);
|
bool IsDir(long dir_id);
|
||||||
@@ -110,12 +107,14 @@ public:
|
|||||||
Item * GetDir(long id);
|
Item * GetDir(long id);
|
||||||
Item * AddDir(const Item & item);
|
Item * AddDir(const Item & item);
|
||||||
|
|
||||||
|
const Item * GetDir(long id) const;
|
||||||
|
|
||||||
void CheckRootDir();
|
void CheckRootDir();
|
||||||
|
|
||||||
Item * CreateVarDir();
|
Item * CreateVarDir();
|
||||||
|
|
||||||
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
||||||
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
bool AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
||||||
|
|
||||||
// returns how many levels of directories there are
|
// returns how many levels of directories there are
|
||||||
// "/" -> 0 (root dir)
|
// "/" -> 0 (root dir)
|
||||||
@@ -129,7 +128,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
Cur * cur;
|
Cur * cur;
|
||||||
Db * db;
|
|
||||||
Notify * notify;
|
Notify * notify;
|
||||||
|
|
||||||
DirContainer dir_tab;
|
DirContainer dir_tab;
|
||||||
|
|||||||
+25
-14
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2019, Tomasz Sowa
|
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "utf8/utf8.h"
|
#include "utf8/utf8.h"
|
||||||
#include "timezones.h"
|
#include "timezones.h"
|
||||||
|
#include "plugin.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -49,6 +49,7 @@ FileLog::FileLog()
|
|||||||
{
|
{
|
||||||
time_zones = nullptr;
|
time_zones = nullptr;
|
||||||
synchro = nullptr;
|
synchro = nullptr;
|
||||||
|
plugin = nullptr;
|
||||||
log_time_zone_id = 0;
|
log_time_zone_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,9 +65,15 @@ void FileLog::set_synchro(Synchro * synchro)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FileLog::set_plugin(Plugin * plugin)
|
||||||
|
{
|
||||||
|
this->plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileLog::init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id)
|
void FileLog::init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id)
|
||||||
{
|
{
|
||||||
PT::FileLog::init(log_file, log_stdout, log_level, save_each_line);
|
pt::FileLog::init(log_file, log_stdout, log_level, save_each_line);
|
||||||
this->log_time_zone_id = log_time_zone_id;
|
this->log_time_zone_id = log_time_zone_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +98,7 @@ bool FileLog::should_save_each_line()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
PT::Date FileLog::get_local_date(const PT::Date & date)
|
pt::Date FileLog::get_local_date(const pt::Date & date)
|
||||||
{
|
{
|
||||||
if( time_zones )
|
if( time_zones )
|
||||||
{
|
{
|
||||||
@@ -100,7 +107,7 @@ PT::Date FileLog::get_local_date(const PT::Date & date)
|
|||||||
|
|
||||||
if( tz )
|
if( tz )
|
||||||
{
|
{
|
||||||
PT::Date local_date = tz->ToLocal(date);
|
pt::Date local_date = tz->ToLocal(date);
|
||||||
return local_date;
|
return local_date;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -116,19 +123,23 @@ PT::Date FileLog::get_local_date(const PT::Date & date)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool FileLog::synchro_lock()
|
void FileLog::save_log(pt::WTextStream * buffer)
|
||||||
{
|
{
|
||||||
return synchro->Lock();
|
if( !buffer->empty() )
|
||||||
|
{
|
||||||
|
Lock lock(synchro);
|
||||||
|
pt::FileLog::save_log(buffer);
|
||||||
|
|
||||||
|
// at the beginning when winix starts the plugin pointer is null
|
||||||
|
// this plugin is set after the plugin object is initialized
|
||||||
|
if( plugin )
|
||||||
|
{
|
||||||
|
plugin->Call(WINIX_SAVE_FILELOG, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileLog::synchro_unlock()
|
|
||||||
{
|
|
||||||
synchro->Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
} // namespace Winix
|
||||||
|
|||||||
+12
-9
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Tomasz Sowa
|
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -47,9 +47,9 @@
|
|||||||
namespace Winix
|
namespace Winix
|
||||||
{
|
{
|
||||||
class TimeZones;
|
class TimeZones;
|
||||||
|
class Plugin;
|
||||||
|
|
||||||
|
class FileLog : public pt::FileLog
|
||||||
class FileLog : public PT::FileLog
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -57,15 +57,22 @@ public:
|
|||||||
virtual ~FileLog();
|
virtual ~FileLog();
|
||||||
|
|
||||||
void set_synchro(Synchro * synchro);
|
void set_synchro(Synchro * synchro);
|
||||||
|
void set_plugin(Plugin * plugin);
|
||||||
|
|
||||||
|
// using pt::FileLog::init to suppress clang warning:
|
||||||
|
// warning: 'Winix::FileLog::init' hides overloaded virtual function [-Woverloaded-virtual]
|
||||||
|
using pt::FileLog::init;
|
||||||
|
|
||||||
void init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id);
|
void init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id);
|
||||||
|
|
||||||
void set_time_zones(TimeZones * time_zones);
|
void set_time_zones(TimeZones * time_zones);
|
||||||
PT::Date get_local_date(const PT::Date & date);
|
pt::Date get_local_date(const pt::Date & date);
|
||||||
|
|
||||||
int get_log_level();
|
int get_log_level();
|
||||||
bool should_save_each_line();
|
bool should_save_each_line();
|
||||||
|
|
||||||
|
void save_log(pt::WTextStream * buffer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -73,12 +80,8 @@ protected:
|
|||||||
size_t log_time_zone_id;
|
size_t log_time_zone_id;
|
||||||
|
|
||||||
TimeZones * time_zones;
|
TimeZones * time_zones;
|
||||||
|
|
||||||
Synchro * synchro;
|
Synchro * synchro;
|
||||||
|
Plugin * plugin; // can be null (only at the beginning when winix starts)
|
||||||
|
|
||||||
virtual bool synchro_lock();
|
|
||||||
virtual void synchro_unlock();
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+14
-5
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -46,9 +46,9 @@ Groups::Groups()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Groups::set_dependency(WinixModel * winix_model)
|
void Groups::set_dependency(WinixModelDeprecated * winix_model)
|
||||||
{
|
{
|
||||||
WinixModel::set_dependency(winix_model);
|
WinixModelDeprecated::set_dependency(winix_model);
|
||||||
table.set_dependency(winix_model);
|
table.set_dependency(winix_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,11 +59,20 @@ void Groups::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Groups::ReadGroups(Db * db)
|
void Groups::ReadGroups()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
db->GetGroups(table);
|
morm::Finder<Group> finder(model_connector);
|
||||||
|
|
||||||
|
std::vector<Group> groups_tmp = finder.
|
||||||
|
select().
|
||||||
|
get_vector();
|
||||||
|
|
||||||
|
for(Group & group : groups_tmp)
|
||||||
|
{
|
||||||
|
table.PushBack(group, group.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -37,10 +37,9 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "group.h"
|
#include "models/group.h"
|
||||||
#include "ugcontainer.h"
|
#include "ugcontainer.h"
|
||||||
#include "db/db.h"
|
#include "winixmodeldeprecated.h"
|
||||||
#include "winixmodel.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Groups : public WinixModel
|
class Groups : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
typedef UGContainer<Group> Table;
|
typedef UGContainer<Group> Table;
|
||||||
|
|
||||||
@@ -57,14 +56,14 @@ Table table;
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void set_dependency(WinixModel * winix_model);
|
void set_dependency(WinixModelDeprecated * winix_model);
|
||||||
|
|
||||||
typedef Table::Iterator Iterator;
|
typedef Table::Iterator Iterator;
|
||||||
typedef Table::SizeType SizeType;
|
typedef Table::SizeType SizeType;
|
||||||
|
|
||||||
Groups();
|
Groups();
|
||||||
void Clear();
|
void Clear();
|
||||||
void ReadGroups(Db * db);
|
void ReadGroups();
|
||||||
Group * GetGroup(long group_id);
|
Group * GetGroup(long group_id);
|
||||||
Group * GetGroup(const std::wstring & name);
|
Group * GetGroup(const std::wstring & name);
|
||||||
long GetGroupId(const std::wstring & name);
|
long GetGroupId(const std::wstring & name);
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
const wchar_t * Header::find_status_string_value(int http_status)
|
||||||
|
{
|
||||||
|
size_t table_len = sizeof(status_int_string_map) / sizeof(StatusIntStringMapHelper);
|
||||||
|
|
||||||
|
for(size_t i=0 ; i < table_len ; ++i)
|
||||||
|
{
|
||||||
|
if( status_int_string_map[i].status_int == http_status )
|
||||||
|
{
|
||||||
|
return status_int_string_map[i].status_str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Header::prepare_status_value(int http_status, pt::WTextStream & value, bool clear_value)
|
||||||
|
{
|
||||||
|
if( clear_value )
|
||||||
|
value.clear();
|
||||||
|
|
||||||
|
value << http_status;
|
||||||
|
const wchar_t * value_str = find_status_string_value(http_status);
|
||||||
|
|
||||||
|
if( value_str )
|
||||||
|
{
|
||||||
|
value << ' ' << value_str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Header::is_header_value_char_correct(wchar_t c)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* make sure to not allow at least \r or \r
|
||||||
|
*/
|
||||||
|
return c > 32 && c < 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Header::is_header_value_correct(const wchar_t * str)
|
||||||
|
{
|
||||||
|
for( ; *str ; ++str)
|
||||||
|
{
|
||||||
|
if( !is_header_value_char_correct(*str) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Header::is_header_value_correct(const std::wstring & str)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* dont use is_header_value_correct(str.c_str()) as there can be a null character (0) inside the string
|
||||||
|
*/
|
||||||
|
for(size_t i=0 ; i < str.size() ; ++i)
|
||||||
|
{
|
||||||
|
if( !is_header_value_char_correct(str[i]) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,225 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2024, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winix_core_header
|
||||||
|
#define headerfile_winix_core_header
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include <textstream/textstream.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
class Header
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/*
|
||||||
|
* headers' names
|
||||||
|
*/
|
||||||
|
static constexpr const wchar_t * content_type = L"Content-Type";
|
||||||
|
static constexpr const wchar_t * accept = L"Accept";
|
||||||
|
static constexpr const wchar_t * accept_language = L"Accept-Language";
|
||||||
|
static constexpr const wchar_t * authorization = L"Authorization";
|
||||||
|
static constexpr const wchar_t * allow = L"Allow";
|
||||||
|
static constexpr const wchar_t * very = L"Very";
|
||||||
|
static constexpr const wchar_t * origin = L"Origin";
|
||||||
|
static constexpr const wchar_t * access_control_allow_methods = L"Access-Control-Allow-Methods";
|
||||||
|
static constexpr const wchar_t * access_control_allow_origin = L"Access-Control-Allow-Origin";
|
||||||
|
static constexpr const wchar_t * access_control_allow_headers = L"Access-Control-Allow-Headers";
|
||||||
|
static constexpr const wchar_t * access_control_allow_credentials = L"Access-Control-Allow-Credentials";
|
||||||
|
static constexpr const wchar_t * access_control_expose_headers = L"Access-Control-Expose-Headers";
|
||||||
|
static constexpr const wchar_t * access_control_max_age = L"Access-Control-Max-Age";
|
||||||
|
|
||||||
|
static constexpr const wchar_t * hx_location = L"HX-Location";
|
||||||
|
static constexpr const wchar_t * hx_push_url = L"HX-Push-Url";
|
||||||
|
static constexpr const wchar_t * hx_redirect = L"HX-Redirect";
|
||||||
|
static constexpr const wchar_t * hx_refresh = L"HX-Refresh";
|
||||||
|
static constexpr const wchar_t * hx_replace_url = L"HX-Replace-Url";
|
||||||
|
static constexpr const wchar_t * hx_reswap = L"HX-Reswap";
|
||||||
|
static constexpr const wchar_t * hx_retarget = L"HX-Retarget";
|
||||||
|
static constexpr const wchar_t * hx_reselect = L"HX-Reselect";
|
||||||
|
static constexpr const wchar_t * hx_trigger = L"HX-Trigger";
|
||||||
|
static constexpr const wchar_t * hx_trigger_after_settle = L"HX-Trigger-After-Settle";
|
||||||
|
static constexpr const wchar_t * hx_trigger_after_swap = L"HX-Trigger-After-Swap";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* headers' names lower case
|
||||||
|
*/
|
||||||
|
static constexpr const wchar_t * content_type_lc = L"content-type";
|
||||||
|
static constexpr const wchar_t * accept_lc = L"accept";
|
||||||
|
static constexpr const wchar_t * accept_language_lc = L"accept-language";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* headers' values
|
||||||
|
*/
|
||||||
|
static constexpr const wchar_t * application_octet_stream = L"application/octet-stream";
|
||||||
|
|
||||||
|
static constexpr const wchar_t * text_html = L"text/html";
|
||||||
|
static constexpr const wchar_t * application_json = L"application/json";
|
||||||
|
static constexpr const wchar_t * application_xml = L"application/xml";
|
||||||
|
static constexpr const wchar_t * application_xhtml_xml = L"application/xhtml+xml";
|
||||||
|
static constexpr const wchar_t * text_csv = L"text/csv";
|
||||||
|
static constexpr const wchar_t * text_javascript = L"text/javascript";
|
||||||
|
static constexpr const wchar_t * text_xml = L"text/xml";
|
||||||
|
|
||||||
|
static constexpr const wchar_t * all_all = L"*/*";
|
||||||
|
static constexpr const wchar_t * text_all = L"text/*";
|
||||||
|
static constexpr const wchar_t * application_all = L"application/*";
|
||||||
|
|
||||||
|
static constexpr const wchar_t * text_html_utf8 = L"text/html; charset=UTF-8";
|
||||||
|
static constexpr const wchar_t * application_json_utf8 = L"application/json; charset=UTF-8";
|
||||||
|
static constexpr const wchar_t * application_xml_utf8 = L"application/xml; charset=UTF-8";
|
||||||
|
static constexpr const wchar_t * application_xhtml_xml_utf8 = L"application/xhtml+xml; charset=UTF-8";
|
||||||
|
static constexpr const wchar_t * text_csv_utf8 = L"text/csv; charset=UTF-8";
|
||||||
|
static constexpr const wchar_t * text_javascript_utf8 = L"text/javascript; charset=UTF-8";
|
||||||
|
static constexpr const wchar_t * text_xml_utf8 = L"text/xml; charset=UTF-8";
|
||||||
|
|
||||||
|
static constexpr const wchar_t * application_x_www_form_urlencoded = L"application/x-www-form-urlencoded";
|
||||||
|
static constexpr const wchar_t * multipart_form_data = L"multipart/form-data";
|
||||||
|
|
||||||
|
static constexpr const wchar_t * bearer = L"Bearer";
|
||||||
|
static constexpr const wchar_t * winix = L"Winix";
|
||||||
|
|
||||||
|
|
||||||
|
static const int status_200_ok = 200;
|
||||||
|
static const int status_201_created = 201;
|
||||||
|
static const int status_204_no_content = 204;
|
||||||
|
static const int status_300_multiple_choices = 300;
|
||||||
|
static const int status_301_moved_permanently = 301;
|
||||||
|
static const int status_302_found = 302;
|
||||||
|
static const int status_303_see_other = 303;
|
||||||
|
static const int status_307_temporary_redirect = 307;
|
||||||
|
static const int status_400_bad_request = 400;
|
||||||
|
static const int status_403_forbidden = 403;
|
||||||
|
static const int status_404_not_found = 404;
|
||||||
|
static const int status_414_uri_too_long = 414;
|
||||||
|
static const int status_422_unprocessable_entity = 422;
|
||||||
|
static const int status_500_internal_server_error = 500;
|
||||||
|
static const int status_503_service_unavailable = 503;
|
||||||
|
|
||||||
|
|
||||||
|
static constexpr const wchar_t * str_status_200 = L"OK";
|
||||||
|
static constexpr const wchar_t * str_status_201 = L"Created";
|
||||||
|
static constexpr const wchar_t * str_status_204 = L"No Content";
|
||||||
|
static constexpr const wchar_t * str_status_300 = L"Multiple Choices";
|
||||||
|
static constexpr const wchar_t * str_status_301 = L"Moved Permanently";
|
||||||
|
static constexpr const wchar_t * str_status_302 = L"Found";
|
||||||
|
static constexpr const wchar_t * str_status_303 = L"See Other";
|
||||||
|
static constexpr const wchar_t * str_status_307 = L"Temporary Redirect";
|
||||||
|
static constexpr const wchar_t * str_status_400 = L"Bad Request";
|
||||||
|
static constexpr const wchar_t * str_status_403 = L"Forbidden";
|
||||||
|
static constexpr const wchar_t * str_status_404 = L"Not Found";
|
||||||
|
static constexpr const wchar_t * str_status_414 = L"URI Too Long";
|
||||||
|
static constexpr const wchar_t * str_status_422 = L"Unprocessable Entity";
|
||||||
|
static constexpr const wchar_t * str_status_500 = L"Internal Server Error";
|
||||||
|
static constexpr const wchar_t * str_status_503 = L"Service Unavailable";
|
||||||
|
|
||||||
|
|
||||||
|
static const wchar_t * find_status_string_value(int http_status);
|
||||||
|
static void prepare_status_value(int http_status, pt::WTextStream & value, bool clear_value = true);
|
||||||
|
|
||||||
|
static bool is_header_value_char_correct(wchar_t c);
|
||||||
|
static bool is_header_value_correct(const wchar_t * str);
|
||||||
|
static bool is_header_value_correct(const std::wstring & str);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
struct StatusIntStringMapHelper
|
||||||
|
{
|
||||||
|
int status_int;
|
||||||
|
const wchar_t * status_str;
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr StatusIntStringMapHelper status_int_string_map[] = {
|
||||||
|
{status_200_ok, str_status_200},
|
||||||
|
{status_201_created, str_status_201},
|
||||||
|
{status_204_no_content, str_status_204},
|
||||||
|
{status_300_multiple_choices, str_status_300},
|
||||||
|
{status_301_moved_permanently, str_status_301},
|
||||||
|
{status_302_found, str_status_302},
|
||||||
|
{status_303_see_other, str_status_303},
|
||||||
|
{status_307_temporary_redirect, str_status_307},
|
||||||
|
{status_400_bad_request, str_status_400},
|
||||||
|
{status_403_forbidden, str_status_403},
|
||||||
|
{status_404_not_found, str_status_404},
|
||||||
|
{status_414_uri_too_long, str_status_414},
|
||||||
|
{status_422_unprocessable_entity, str_status_422},
|
||||||
|
{status_500_internal_server_error, str_status_500},
|
||||||
|
{status_503_service_unavailable, str_status_503},
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class HeaderValue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::wstring value;
|
||||||
|
double weight; // q parameter in some headers
|
||||||
|
|
||||||
|
|
||||||
|
HeaderValue()
|
||||||
|
{
|
||||||
|
weight = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void log_values(const std::vector<HeaderValue> & header_values, Log & log)
|
||||||
|
{
|
||||||
|
char buf[64];
|
||||||
|
bool is_first = true;
|
||||||
|
|
||||||
|
for(const HeaderValue & h: header_values)
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf)/sizeof(char), "%.3f", h.weight);
|
||||||
|
|
||||||
|
if( !is_first )
|
||||||
|
log << ", ";
|
||||||
|
|
||||||
|
log << h.value << ";q=" << buf;
|
||||||
|
is_first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,373 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is distributed under the 2-Clause BSD licence.
|
|
||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_htmlfilter
|
|
||||||
#define headerfile_winix_core_htmlfilter
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
#include "core/winixbase.h"
|
|
||||||
|
|
||||||
|
|
||||||
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 WinixBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum OrphanMode
|
|
||||||
{
|
|
||||||
orphan_nbsp, // putting " " string
|
|
||||||
orphan_160space // putting 160 ascii code
|
|
||||||
};
|
|
||||||
|
|
||||||
HTMLFilter();
|
|
||||||
HTMLFilter(const HTMLFilter & f);
|
|
||||||
HTMLFilter & operator=(const HTMLFilter & f);
|
|
||||||
virtual ~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);
|
|
||||||
|
|
||||||
// set a name of a html tag which will be used as 'nofilter' tag
|
|
||||||
// elements between such tags are not filtered (similarly as in <pre> and <textarea>)
|
|
||||||
// these tags (opening and closing) will no be placed in the html output
|
|
||||||
void SetNoFilterTag(const std::wstring & tag_name);
|
|
||||||
|
|
||||||
// orphans are checked only in 'body' tag
|
|
||||||
void AssignOrphans(const wchar_t * lang_code, const std::vector<std::wstring> & otab);
|
|
||||||
void AssignOrphans(const std::wstring & lang_code, const std::vector<std::wstring> & otab);
|
|
||||||
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(const std::wstring & orphan_mode);
|
|
||||||
|
|
||||||
// skipping some unsafe tags
|
|
||||||
// (script, iframe, frame, frameset, applet, head, meta, html, link, body, ...)
|
|
||||||
void SafeMode(bool safe_mode_);
|
|
||||||
|
|
||||||
// skip all html tags
|
|
||||||
// gives only text without markup
|
|
||||||
// but there can be commentaries
|
|
||||||
void SkipTags(bool skip_tags);
|
|
||||||
|
|
||||||
// skip commentaries
|
|
||||||
void SkipCommentaries(bool skip_commentaries);
|
|
||||||
|
|
||||||
// if true then entities such as are skipped
|
|
||||||
// this automatically turns on AnalyzeEntities
|
|
||||||
// in such a case FoundEntity callbacks are sent
|
|
||||||
void SkipEntities(bool skip_entities);
|
|
||||||
|
|
||||||
// analyze html entities such as
|
|
||||||
// virtual method: FoundEntity is called
|
|
||||||
// entities are analyzed in normal text and in attribute values such as <p class="a ">
|
|
||||||
void AnalyzeEntities(bool analyze_entities);
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
// html <nofilter> tag name
|
|
||||||
std::wstring no_filter_tag;
|
|
||||||
|
|
||||||
|
|
||||||
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(wchar_t c);
|
|
||||||
virtual bool IsClosingTagMark(wchar_t c);
|
|
||||||
virtual bool IsClosingXmlSimpleTagMark(wchar_t c);
|
|
||||||
virtual bool IsStartingEntityMark(wchar_t c);
|
|
||||||
virtual bool IsEndingEntityMark(wchar_t c);
|
|
||||||
|
|
||||||
virtual bool IsOpeningCommentaryTagMark(const wchar_t * str);
|
|
||||||
virtual size_t OpeningCommentaryTagMarkSize();
|
|
||||||
|
|
||||||
virtual bool IsValidCharForName(int c);
|
|
||||||
virtual bool IsValidCharForAttrName(int c);
|
|
||||||
virtual bool IsValidCharForEntityName(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 AnalyzeEntitiesAndPut(const wchar_t * str, const wchar_t * end, std::wstring * out);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
virtual void ItemFound();
|
|
||||||
virtual void EntityFound(const wchar_t * str, const wchar_t * end);
|
|
||||||
|
|
||||||
/*
|
|
||||||
others
|
|
||||||
*/
|
|
||||||
void SetSomeDefaults();
|
|
||||||
|
|
||||||
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 IsLastTag(const std::wstring & 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();
|
|
||||||
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 ReadItemAttrValueAdd(const wchar_t * value_start, const wchar_t * value_end);
|
|
||||||
void ReadItemAttrValue(bool has_quote, wchar_t quote_char);
|
|
||||||
|
|
||||||
bool ReadItemAttr();
|
|
||||||
bool CheckItemAttr();
|
|
||||||
void PrintItemAttr();
|
|
||||||
|
|
||||||
void ReadItemClosing();
|
|
||||||
void ReadItemSpecial();
|
|
||||||
void ReadItemOpening();
|
|
||||||
bool ReadItem();
|
|
||||||
void ReadLoop();
|
|
||||||
void Read();
|
|
||||||
|
|
||||||
void CheckChar(wchar_t c);
|
|
||||||
|
|
||||||
void CheckLineWrap();
|
|
||||||
bool HasEntityEndAround(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 PutEverythingUntilClosingTag(bool put_closing_tag_as_well);
|
|
||||||
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::vector<std::wstring> attr_value;
|
|
||||||
std::wstring attr_value_temp;
|
|
||||||
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;
|
|
||||||
bool skip_tags;
|
|
||||||
bool skip_commentaries;
|
|
||||||
bool skip_entities;
|
|
||||||
bool analyze_entities;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -143,7 +143,7 @@ void HttpSimpleParser::ReadName()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( getchar_returns_utf8_chars )
|
if( getchar_returns_utf8_chars )
|
||||||
PT::UTF8ToWide(utf8_token, last_name);
|
pt::utf8_to_wide(utf8_token, last_name);
|
||||||
|
|
||||||
if( last_c == '=' )
|
if( last_c == '=' )
|
||||||
last_c = GetChar();
|
last_c = GetChar();
|
||||||
@@ -173,7 +173,7 @@ void HttpSimpleParser::ReadQuotedValue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( getchar_returns_utf8_chars )
|
if( getchar_returns_utf8_chars )
|
||||||
PT::UTF8ToWide(utf8_token, last_value);
|
pt::utf8_to_wide(utf8_token, last_value);
|
||||||
|
|
||||||
if( last_c == '"' )
|
if( last_c == '"' )
|
||||||
last_c = GetChar();
|
last_c = GetChar();
|
||||||
@@ -204,7 +204,7 @@ void HttpSimpleParser::ReadNormalValue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( getchar_returns_utf8_chars )
|
if( getchar_returns_utf8_chars )
|
||||||
PT::UTF8ToWide(utf8_token, last_value);
|
pt::utf8_to_wide(utf8_token, last_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,8 @@
|
|||||||
#define headerfile_winix_core_httpsimpleparser
|
#define headerfile_winix_core_httpsimpleparser
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "winixmodel.h"
|
|
||||||
|
#include "winixmodeldeprecated.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -44,7 +45,7 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class HttpSimpleParser : public WinixModel
|
class HttpSimpleParser : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
+56
-49
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
#include "core/misc.h"
|
||||||
#include "utf8/utf8.h"
|
#include "utf8/utf8.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
@@ -44,14 +45,6 @@ namespace Winix
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Image::SetDb(Db * pdb)
|
|
||||||
{
|
|
||||||
db = pdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Image::SetConfig(Config * pconfig)
|
void Image::SetConfig(Config * pconfig)
|
||||||
{
|
{
|
||||||
config = pconfig;
|
config = pconfig;
|
||||||
@@ -267,7 +260,7 @@ bool end;
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
class Lock lock_object(synchro);
|
Winix::Lock lock_object(synchro);
|
||||||
|
|
||||||
if( i != image_tab.end() )
|
if( i != image_tab.end() )
|
||||||
{
|
{
|
||||||
@@ -292,19 +285,13 @@ bool end;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Image::Add(const std::wstring & in, TextStream<std::string> & out)
|
|
||||||
{
|
|
||||||
PT::WideToUTF8(in, add_tempa);
|
|
||||||
out << add_tempa;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Image::EscapePath(const std::string & path, pt::TextStream & out, bool clear_stream)
|
||||||
void Image::EscapePath(const std::string & path, TextStream<std::string> & out, bool clear_stream)
|
|
||||||
{
|
{
|
||||||
if( clear_stream )
|
if( clear_stream )
|
||||||
out.Clear();
|
out.clear();
|
||||||
|
|
||||||
out << '"';
|
out << '"';
|
||||||
|
|
||||||
@@ -377,7 +364,7 @@ bool Image::CreateInputFileName()
|
|||||||
{
|
{
|
||||||
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB);
|
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB);
|
||||||
|
|
||||||
if( thumb && !file_work.has_thumb )
|
if( thumb && !file_work.item_content.file_has_thumb )
|
||||||
{
|
{
|
||||||
log << log1 << "Image: file id: " << file_work.id << ", url: " << file_work.url
|
log << log1 << "Image: file id: " << file_work.id << ", url: " << file_work.url
|
||||||
<< " doesn't have a thumbnail yet (skipping)" << logend;
|
<< " doesn't have a thumbnail yet (skipping)" << logend;
|
||||||
@@ -387,7 +374,7 @@ bool Image::CreateInputFileName()
|
|||||||
|
|
||||||
if( system->MakeFilePath(file_work, src_path, thumb) )
|
if( system->MakeFilePath(file_work, src_path, thumb) )
|
||||||
{
|
{
|
||||||
PT::WideToUTF8(src_path, input_file_name);
|
pt::wide_to_utf8(src_path, input_file_name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -402,9 +389,9 @@ bool Image::CreateInputFileName()
|
|||||||
// second thread (objects locked)
|
// second thread (objects locked)
|
||||||
void Image::CreateTmpFileName()
|
void Image::CreateTmpFileName()
|
||||||
{
|
{
|
||||||
stream_tmp_path.Clear();
|
stream_tmp_path.clear();
|
||||||
stream_tmp_path << config->upload_dir << L"/tmp/image_" << std::time(0);
|
stream_tmp_path << config->upload_dir << L"/tmp/image_" << std::time(0);
|
||||||
PT::WideToUTF8(stream_tmp_path.Str(), tmp_file_name);
|
stream_tmp_path.to_str(tmp_file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -412,20 +399,23 @@ void Image::CreateTmpFileName()
|
|||||||
// second thread (objects are not locked)
|
// second thread (objects are not locked)
|
||||||
bool Image::CreateCommand()
|
bool Image::CreateCommand()
|
||||||
{
|
{
|
||||||
class Lock lock_object(synchro);
|
Winix::Lock lock_object(synchro);
|
||||||
|
|
||||||
iq.SetAll(true, false);
|
// iq.SetAll(true, false);
|
||||||
iq.WhereId(item_work.file_id);
|
// iq.WhereId(item_work.file_id);
|
||||||
|
|
||||||
|
morm::Finder<Item> finder(model_connector);
|
||||||
|
file_work = finder.select().where().eq(L"id", item_work.file_id).get();
|
||||||
|
|
||||||
// the file could have been changed especially when there is a long queue of files
|
// the file could have been changed especially when there is a long queue of files
|
||||||
if( db->GetItem(file_work, iq) != WINIX_ERR_OK )
|
if( !file_work.found() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !CreateInputFileName() )
|
if( !CreateInputFileName() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
command.Clear();
|
command.clear();
|
||||||
Add(config->convert_cmd, command);
|
command << config->convert_cmd;
|
||||||
|
|
||||||
command << " ";
|
command << " ";
|
||||||
EscapePath(input_file_name, command, false);
|
EscapePath(input_file_name, command, false);
|
||||||
@@ -469,7 +459,7 @@ bool Image::CreateCommand()
|
|||||||
command << " ";
|
command << " ";
|
||||||
EscapePath(tmp_file_name, command, false);
|
EscapePath(tmp_file_name, command, false);
|
||||||
|
|
||||||
log << log4 << "Image: running: " << command.Str() << logend;
|
log << log4 << "Image: running: " << command << logend;
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -483,34 +473,37 @@ void Image::ImageSavedCorrectly()
|
|||||||
{
|
{
|
||||||
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB )
|
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB )
|
||||||
{
|
{
|
||||||
if( !file_work.has_thumb )
|
if( !file_work.item_content.file_has_thumb )
|
||||||
{
|
{
|
||||||
file_work.has_thumb = true;
|
file_work.item_content.file_has_thumb = true;
|
||||||
db->EditHasThumbById(true, file_work.id);
|
|
||||||
|
file_work.propagate_connector();
|
||||||
|
file_work.item_content.update(false);
|
||||||
|
//db->EditHasThumbById(true, file_work.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
|
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
|
||||||
plugin->Call((Session*)0, WINIX_CREATED_THUMB, &file_work);
|
plugin->Call(model_connector, &log, nullptr, WINIX_CREATED_THUMB, &file_work, nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( item_work.type == WINIX_IMAGE_TYPE_RESIZE )
|
if( item_work.type == WINIX_IMAGE_TYPE_RESIZE )
|
||||||
{
|
{
|
||||||
log << log3 << "Image: image resized: " << dst_path << logend;
|
log << log3 << "Image: image resized: " << dst_path << logend;
|
||||||
plugin->Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
|
plugin->Call(model_connector, &log, nullptr, WINIX_IMAGE_RESIZED, &file_work, nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( item_work.type == WINIX_IMAGE_TYPE_CROP )
|
if( item_work.type == WINIX_IMAGE_TYPE_CROP )
|
||||||
{
|
{
|
||||||
log << log3 << "Image: image cropped: " << dst_path << logend;
|
log << log3 << "Image: image cropped: " << dst_path << logend;
|
||||||
// !! IMPROVE ME add a correct message
|
// !! IMPROVE ME add a correct message
|
||||||
//plugin->Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
|
//plugin->Call(model_connector, &log, nullptr, WINIX_IMAGE_RESIZED, &file_work, nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB )
|
if( item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB )
|
||||||
{
|
{
|
||||||
log << log3 << "Image: image thumbnail cropped: " << dst_path << logend;
|
log << log3 << "Image: image thumbnail cropped: " << dst_path << logend;
|
||||||
// !! IMPROVE ME add a correct message
|
// !! IMPROVE ME add a correct message
|
||||||
//plugin->Call((Session*)0, WINIX_IMAGE_RESIZED, &file_work);
|
//plugin->Call(model_connector, &log, nullptr, WINIX_IMAGE_RESIZED, &file_work, nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB )
|
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB )
|
||||||
@@ -525,21 +518,32 @@ void Image::ImageSavedCorrectly()
|
|||||||
// second thread (objects are not locked)
|
// second thread (objects are not locked)
|
||||||
void Image::SaveImage()
|
void Image::SaveImage()
|
||||||
{
|
{
|
||||||
class Lock lock_object(synchro);
|
Winix::Lock lock_object(synchro);
|
||||||
|
|
||||||
// the file could have been changed especially when creating the image lasted too long
|
// the file could have been changed especially when creating the image lasted too long
|
||||||
iq.SetAll(true, false);
|
//iq.SetAll(true, false);
|
||||||
iq.WhereId(item_work.file_id);
|
//iq.WhereId(item_work.file_id);
|
||||||
|
|
||||||
if( db->GetItem(file_work, iq) == WINIX_ERR_OK )
|
morm::Finder<Item> finder(model_connector);
|
||||||
{
|
file_work = finder.select().where().eq(L"id", item_work.file_id).get();
|
||||||
|
|
||||||
|
|
||||||
|
// the file could have been changed especially when there is a long queue of files
|
||||||
|
if( !file_work.found() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
//if( db->GetItem(file_work, iq) == WINIX_ERR_OK )
|
||||||
|
//{
|
||||||
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB ||
|
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB ||
|
||||||
item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB ||
|
item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB ||
|
||||||
item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB );
|
item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB );
|
||||||
|
|
||||||
if( system->MakeFilePath(file_work, dst_path, thumb, true, config->upload_dirs_chmod, config->upload_group_int) )
|
if( system->MakeFilePath(file_work, dst_path, thumb, true, config->upload_dirs_chmod, config->upload_group_int) )
|
||||||
{
|
{
|
||||||
if( RenameFile(stream_tmp_path.Str(), dst_path) )
|
std::wstring from;
|
||||||
|
stream_tmp_path.to_str(from);
|
||||||
|
|
||||||
|
if( RenameFile(from, dst_path) )
|
||||||
{
|
{
|
||||||
// it doesn't matter for us if there is an error when chmod/chown on a file
|
// it doesn't matter for us if there is an error when chmod/chown on a file
|
||||||
// the admin (root) will correct it
|
// the admin (root) will correct it
|
||||||
@@ -548,17 +552,17 @@ void Image::SaveImage()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log << log1 << "Image: cannot move a temporary file: " << stream_tmp_path.Str()
|
log << log1 << "Image: cannot move a temporary file: " << stream_tmp_path
|
||||||
<< ", to: " << dst_path << logend;
|
<< ", to: " << dst_path << logend;
|
||||||
|
|
||||||
Winix::RemoveFile(stream_tmp_path.Str());
|
Winix::RemoveFile(from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log << log1 << "Image: cannot create a destination path" << logend;
|
log << log1 << "Image: cannot create a destination path" << logend;
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -568,7 +572,9 @@ void Image::CreateImage()
|
|||||||
{
|
{
|
||||||
if( CreateCommand() )
|
if( CreateCommand() )
|
||||||
{
|
{
|
||||||
int res = std::system(command.CStr());
|
std::string command_str;
|
||||||
|
command.to_str(command_str);
|
||||||
|
int res = std::system(command_str.c_str());
|
||||||
|
|
||||||
if( res == 0 )
|
if( res == 0 )
|
||||||
{
|
{
|
||||||
@@ -576,11 +582,12 @@ void Image::CreateImage()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
class Lock lock_object(synchro);
|
|
||||||
log << log3 << "Image: some problems with creating an image"
|
log << log3 << "Image: some problems with creating an image"
|
||||||
<< ", 'convert' process returned: " << res << logend;
|
<< ", 'convert' process returned: " << res << logend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log << logsave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -597,8 +604,8 @@ void Image::CreateImage()
|
|||||||
|
|
||||||
void Image::CreateThumbnail()
|
void Image::CreateThumbnail()
|
||||||
{
|
{
|
||||||
PT::WideToUTF8(item_work.source, sourcea);
|
pt::wide_to_utf8(item_work.source, sourcea);
|
||||||
PT::WideToUTF8(item_work.dst, dsta);
|
pt::wide_to_utf8(item_work.dst, dsta);
|
||||||
|
|
||||||
MagickWandGenesis();
|
MagickWandGenesis();
|
||||||
|
|
||||||
|
|||||||
+5
-12
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -38,10 +38,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "basethread.h"
|
#include "basethread.h"
|
||||||
#include "textstream.h"
|
|
||||||
#include "db/db.h"
|
|
||||||
#include "core/item.h"
|
|
||||||
#include "core/config.h"
|
#include "core/config.h"
|
||||||
|
#include "models/item.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -116,7 +114,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void SetDb(Db * pdb);
|
|
||||||
void SetConfig(Config * pconfig);
|
void SetConfig(Config * pconfig);
|
||||||
void SetSystem(System * psystem);
|
void SetSystem(System * psystem);
|
||||||
|
|
||||||
@@ -147,7 +144,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Db * db;
|
|
||||||
Config * config;
|
Config * config;
|
||||||
System * system;
|
System * system;
|
||||||
|
|
||||||
@@ -185,10 +181,8 @@ private:
|
|||||||
// only for second thread
|
// only for second thread
|
||||||
ImageItem item_work;
|
ImageItem item_work;
|
||||||
std::wstring src_path, dst_path;
|
std::wstring src_path, dst_path;
|
||||||
TextStream<std::string> command;
|
pt::TextStream command;
|
||||||
TextStream<std::wstring> stream_tmp_path;
|
pt::WTextStream stream_tmp_path;
|
||||||
DbItemQuery iq;
|
|
||||||
std::string add_tempa;
|
|
||||||
std::string input_file_name;
|
std::string input_file_name;
|
||||||
std::string tmp_file_name;
|
std::string tmp_file_name;
|
||||||
Item file_work;
|
Item file_work;
|
||||||
@@ -201,9 +195,8 @@ private:
|
|||||||
void SaveImage();
|
void SaveImage();
|
||||||
void CreateImage();
|
void CreateImage();
|
||||||
void SelectAspect(size_t cx, size_t cy);
|
void SelectAspect(size_t cx, size_t cy);
|
||||||
void EscapePath(const std::string & path, TextStream<std::string> & out, bool clear_stream = true);
|
void EscapePath(const std::string & path, pt::TextStream & out, bool clear_stream = true);
|
||||||
void CheckParam(ImageItem & item);
|
void CheckParam(ImageItem & item);
|
||||||
void Add(const std::wstring & in, TextStream<std::string> & out);
|
|
||||||
void ImageSavedCorrectly();
|
void ImageSavedCorrectly();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ void IPBanContainer::PrintTab()
|
|||||||
{
|
{
|
||||||
log << log4 << i << ": ip: " << ipban_tab[i].ip << ", flags: " << ipban_tab[i].flags << ", last_used: ";
|
log << log4 << i << ": ip: " << ipban_tab[i].ip << ", flags: " << ipban_tab[i].flags << ", last_used: ";
|
||||||
|
|
||||||
PT::Date date(ipban_tab[i].last_used);
|
pt::Date date(ipban_tab[i].last_used);
|
||||||
log << date << ", expires: ";
|
log << date << ", expires: ";
|
||||||
|
|
||||||
date = ipban_tab[i].expires;
|
date = ipban_tab[i].expires;
|
||||||
@@ -168,7 +168,7 @@ void IPBanContainer::PrintTab2()
|
|||||||
|
|
||||||
log << log4 << i << ": ip: " << ipban.ip << ", flags: " << ipban.flags << ", last_used: ";
|
log << log4 << i << ": ip: " << ipban.ip << ", flags: " << ipban.flags << ", last_used: ";
|
||||||
|
|
||||||
PT::Date date(ipban.last_used);
|
pt::Date date(ipban.last_used);
|
||||||
log << date << ", expires: ";
|
log << date << ", expires: ";
|
||||||
|
|
||||||
date = ipban.expires;
|
date = ipban.expires;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ipban.h"
|
#include "ipban.h"
|
||||||
#include "winixmodel.h"
|
#include "winixmodeldeprecated.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IPBanContainer : public WinixModel
|
class IPBanContainer : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is distributed under the 2-Clause BSD licence.
|
|
||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2008-2016, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_item
|
|
||||||
#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_other, // no auto-formatting is applied
|
|
||||||
};
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
|
|
||||||
static bool CanContentBeHtmlFiltered(Item::ContentType ct);
|
|
||||||
bool CanContentBeHtmlFiltered();
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
+279
-31
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2019, Tomasz Sowa
|
* Copyright (c) 2012-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -35,6 +35,9 @@
|
|||||||
#include "job.h"
|
#include "job.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "functions/functions.h"
|
||||||
|
#include "lock.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -45,31 +48,115 @@ namespace Winix
|
|||||||
|
|
||||||
Job::Job()
|
Job::Job()
|
||||||
{
|
{
|
||||||
jobs_queue_tab.resize(WINIX_JOBS_HOW_MANY_PRIORITIES);
|
jobs_queue_tab.resize(PRIORITY_HIGHEST + 1);
|
||||||
|
cur = nullptr;
|
||||||
|
functions = nullptr;
|
||||||
|
mounts = nullptr;
|
||||||
|
load_avg = nullptr;
|
||||||
|
req_tab = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Job::CheckPriority(int & priority) const
|
void Job::SetCur(Cur * cur)
|
||||||
{
|
{
|
||||||
if( priority < 0 )
|
this->cur = cur;
|
||||||
priority = 0;
|
}
|
||||||
|
|
||||||
if( priority >= WINIX_JOBS_HOW_MANY_PRIORITIES )
|
|
||||||
priority = WINIX_JOBS_HOW_MANY_PRIORITIES - 1;
|
void Job::SetFunctions(Functions * functions)
|
||||||
|
{
|
||||||
|
this->functions = functions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Job::SetLoadAvg(LoadAvg * load_avg)
|
||||||
|
{
|
||||||
|
this->load_avg = load_avg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Job::SetMounts(Mounts * mounts)
|
||||||
|
{
|
||||||
|
this->mounts = mounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Job::SetReqTab(std::list<Request> * req_tab)
|
||||||
|
{
|
||||||
|
this->req_tab = req_tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Job::CheckPriority(size_t & priority) const
|
||||||
|
{
|
||||||
|
if( priority > PRIORITY_HIGHEST )
|
||||||
|
priority = PRIORITY_HIGHEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// first thread (objects locked)
|
// first thread (objects locked)
|
||||||
void Job::Add(PT::Space & job, int priority)
|
void Job::Add(pt::Space & job, size_t priority)
|
||||||
{
|
{
|
||||||
CheckPriority(priority);
|
CheckPriority(priority);
|
||||||
jobs_queue_tab[priority].push(job);
|
JobTask task;
|
||||||
|
task.job_type = JobTask::JOB_TYPE_DEFAULT;
|
||||||
|
task.job_id = JobTask::JOB_ID_DEFAULT;
|
||||||
|
task.job = job;
|
||||||
|
jobs_queue_tab[priority].push(task);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Job::Add(Request * request, pt::Space & job, size_t priority)
|
||||||
|
{
|
||||||
|
CheckPriority(priority);
|
||||||
|
JobTask task;
|
||||||
|
task.job_type = JobTask::JOB_TYPE_REQUEST_CONTINUATION;
|
||||||
|
task.job_id = JobTask::JOB_ID_DEFAULT;
|
||||||
|
task.request = request;
|
||||||
|
task.job = job;
|
||||||
|
jobs_queue_tab[priority].push(task);
|
||||||
WakeUpThread();
|
WakeUpThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Job::Size(int priority) const
|
// first thread (objects locked)
|
||||||
|
void Job::Add(long job_id, pt::Space & job, size_t priority)
|
||||||
|
{
|
||||||
|
CheckPriority(priority);
|
||||||
|
JobTask task;
|
||||||
|
task.job_type = JobTask::JOB_TYPE_DEFAULT;
|
||||||
|
task.job_id = job_id;
|
||||||
|
task.job = job;
|
||||||
|
jobs_queue_tab[priority].push(task);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// first thread (objects locked)
|
||||||
|
void Job::Add(long job_id, Request * request, pt::Space & job, size_t priority)
|
||||||
|
{
|
||||||
|
CheckPriority(priority);
|
||||||
|
JobTask task;
|
||||||
|
task.job_type = JobTask::JOB_TYPE_REQUEST_CONTINUATION;
|
||||||
|
task.job_id = job_id;
|
||||||
|
task.request = request;
|
||||||
|
task.job = job;
|
||||||
|
jobs_queue_tab[priority].push(task);
|
||||||
|
WakeUpThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Job::RegisterRequestJob(long job_id, RequestJobBase & request_job)
|
||||||
|
{
|
||||||
|
request_jobs.insert(std::make_pair(job_id, &request_job));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t Job::Size(size_t priority) const
|
||||||
{
|
{
|
||||||
CheckPriority(priority);
|
CheckPriority(priority);
|
||||||
return jobs_queue_tab[priority].size();
|
return jobs_queue_tab[priority].size();
|
||||||
@@ -81,14 +168,14 @@ size_t Job::Size() const
|
|||||||
{
|
{
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for(size_t i=0 ; i<WINIX_JOBS_HOW_MANY_PRIORITIES ; ++i)
|
for(size_t i=0 ; i <= PRIORITY_HIGHEST ; ++i)
|
||||||
sum += Size(i);
|
sum += Size(i);
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Job::Empty(int priority) const
|
bool Job::Empty(size_t priority) const
|
||||||
{
|
{
|
||||||
CheckPriority(priority);
|
CheckPriority(priority);
|
||||||
return jobs_queue_tab[priority].empty();
|
return jobs_queue_tab[priority].empty();
|
||||||
@@ -97,7 +184,7 @@ bool Job::Empty(int priority) const
|
|||||||
|
|
||||||
bool Job::Empty() const
|
bool Job::Empty() const
|
||||||
{
|
{
|
||||||
for(size_t i=0 ; i<WINIX_JOBS_HOW_MANY_PRIORITIES ; ++i)
|
for(size_t i=0 ; i <= PRIORITY_HIGHEST ; ++i)
|
||||||
if( !Empty(i) )
|
if( !Empty(i) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -111,6 +198,7 @@ return true;
|
|||||||
second thread
|
second thread
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects locked)
|
// second thread (objects locked)
|
||||||
bool Job::SignalReceived()
|
bool Job::SignalReceived()
|
||||||
{
|
{
|
||||||
@@ -121,19 +209,20 @@ bool Job::SignalReceived()
|
|||||||
// second thread (objects not locked)
|
// second thread (objects not locked)
|
||||||
void Job::Do()
|
void Job::Do()
|
||||||
{
|
{
|
||||||
size_t i = WINIX_JOBS_HOW_MANY_PRIORITIES;
|
size_t i = PRIORITY_HIGHEST + 1;
|
||||||
bool is_empty;
|
bool is_empty;
|
||||||
|
|
||||||
while( i-- > 0 && !IsExitSignal() )
|
while( i-- > 0 && !IsExitSignal() )
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Lock();
|
{
|
||||||
is_empty = Empty(i);
|
Winix::Lock lock(synchro);
|
||||||
Unlock();
|
is_empty = Empty(i);
|
||||||
|
}
|
||||||
|
|
||||||
if( !is_empty )
|
if( !is_empty )
|
||||||
DoQueue(jobs_queue_tab[i]);
|
DoQueue(jobs_queue_tab[i], i);
|
||||||
}
|
}
|
||||||
while( !is_empty && !IsExitSignal() );
|
while( !is_empty && !IsExitSignal() );
|
||||||
}
|
}
|
||||||
@@ -141,53 +230,212 @@ bool is_empty;
|
|||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked, jobs_queue is not empty)
|
// second thread (objects not locked, jobs_queue is not empty)
|
||||||
void Job::DoQueue(JobsQueue & jobs_queue)
|
void Job::DoQueue(JobsQueue & jobs_queue, size_t priority)
|
||||||
{
|
{
|
||||||
bool is_empty;
|
bool is_empty;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Lock();
|
|
||||||
// references will not be invalidated after insertion to jobs_queue
|
// references will not be invalidated after insertion to jobs_queue
|
||||||
// (jobs_queue is std::queue and it uses std::deque by default)
|
// (jobs_queue is std::queue and it uses std::deque by default)
|
||||||
PT::Space & job = jobs_queue.front();
|
JobTask * job_task = nullptr;
|
||||||
Unlock();
|
|
||||||
|
|
||||||
DoJob(job);
|
{
|
||||||
|
Winix::Lock lock(synchro);
|
||||||
|
|
||||||
Lock();
|
if( !jobs_queue.empty() )
|
||||||
jobs_queue.pop();
|
{
|
||||||
is_empty = jobs_queue.empty();
|
job_task = &jobs_queue.front();
|
||||||
Unlock();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( job_task )
|
||||||
|
{
|
||||||
|
DoJob(*job_task, priority);
|
||||||
|
|
||||||
|
{
|
||||||
|
Winix::Lock lock(synchro);
|
||||||
|
|
||||||
|
jobs_queue.pop();
|
||||||
|
is_empty = jobs_queue.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while( !is_empty && !IsExitSignal() );
|
while( !is_empty && !IsExitSignal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked)
|
// second thread (objects not locked)
|
||||||
void Job::DoJob(PT::Space & job)
|
void Job::DoJob(JobTask & task, size_t priority)
|
||||||
{
|
{
|
||||||
|
PluginRes res;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PluginRes res = plugin->Call((Session*)0, WINIX_JOB, &job);
|
main_log << logsave;
|
||||||
|
|
||||||
|
if( task.job_type == JobTask::JOB_TYPE_REQUEST_CONTINUATION )
|
||||||
|
{
|
||||||
|
res = DoRequestJobs(task, task.job_id, priority);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res = plugin->Call(model_connector, &log, nullptr, WINIX_JOB, &task.job, nullptr, task.job_type, task.job_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
log << logsave;
|
||||||
|
|
||||||
if( res.res_true == 0 )
|
if( res.res_true == 0 )
|
||||||
DoWinixJob(job);
|
{
|
||||||
|
DoWinixJob(task.job); // probably this will be removed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
|
log << log2 << "Job: an exception was catched when doing a job" << logend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects not locked)
|
// second thread (objects not locked)
|
||||||
void Job::DoWinixJob(PT::Space & job)
|
PluginRes Job::DoRequestJobs(JobTask & task, long job_id, size_t priority)
|
||||||
|
{
|
||||||
|
PluginRes res;
|
||||||
|
|
||||||
|
if( task.request )
|
||||||
|
{
|
||||||
|
auto jobs_iterator = request_jobs.lower_bound(job_id);
|
||||||
|
bool has_job = false;
|
||||||
|
|
||||||
|
while( jobs_iterator != request_jobs.end() && jobs_iterator->first == job_id )
|
||||||
|
{
|
||||||
|
task.request->run_state = Request::RunState::job_run;
|
||||||
|
jobs_iterator->second->set_dependency(this);
|
||||||
|
jobs_iterator->second->set_request(task.request);
|
||||||
|
jobs_iterator->second->do_job();
|
||||||
|
jobs_iterator++;
|
||||||
|
has_job = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !has_job )
|
||||||
|
{
|
||||||
|
log << log2 << "Job: I could not find a request job with id: " << job_id << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cur local_cur;
|
||||||
|
local_cur.request = task.request;
|
||||||
|
local_cur.request->run_state = Request::RunState::job_run;
|
||||||
|
local_cur.session = task.request->session;
|
||||||
|
local_cur.mount = task.request->mount;
|
||||||
|
|
||||||
|
{
|
||||||
|
Winix::Lock lock(synchro);
|
||||||
|
log << logsave;
|
||||||
|
Cur old_cur = *cur;
|
||||||
|
*cur = local_cur;
|
||||||
|
DoRequestContinuationJob(task, priority);
|
||||||
|
*cur = old_cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log2 << "Job: request continuation task doesn't have a request set, skipping the job and request continuation" << logend;
|
||||||
|
log << log2 << "Job: this is an internal error, the request if exists in the queue will never be removed" << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects locked)
|
||||||
|
// use main_log (after locking) for the logs to be in the correct order
|
||||||
|
void Job::DoRequestContinuationJob(JobTask & job_task, size_t priority)
|
||||||
|
{
|
||||||
|
if( cur->request->function )
|
||||||
|
{
|
||||||
|
main_log << config->log_delimiter << logend;
|
||||||
|
main_log << log3 << "Job: making a continuation for request " << cur->request << logend;
|
||||||
|
main_log << log4 << "Job: doing directory analysis again" << logend;
|
||||||
|
|
||||||
|
if( functions->ParseOnlyDirs() )
|
||||||
|
{
|
||||||
|
cur->mount = mounts->CalcCurMount(cur->request);
|
||||||
|
cur->request->mount = cur->mount;
|
||||||
|
cur->request->run_state = Request::RunState::job_continuation_run;
|
||||||
|
functions->ContinueMakeFunction();
|
||||||
|
|
||||||
|
if( cur->request->run_state == Request::RunState::assigned_to_job )
|
||||||
|
{
|
||||||
|
log << log3 << "Job: this request (" << cur->request << ") has been moved to the job queue again" << logend;
|
||||||
|
Add(cur->request->job_id, cur->request, cur->request->job, priority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
main_log << log4 << "Job: directories have not been correctly prepared, finishing the request" << logend;
|
||||||
|
cur->request->http_status = Header::status_500_internal_server_error;
|
||||||
|
cur->request->run_state = Request::RunState::prepare_to_finish;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
main_log << log2 << "Job: request continuation task doesn't have a funtion set, return 500 internal error" << logend;
|
||||||
|
cur->request->http_status = Header::status_500_internal_server_error;
|
||||||
|
cur->request->run_state = Request::RunState::prepare_to_finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( cur->request->run_state != Request::RunState::assigned_to_job )
|
||||||
|
{
|
||||||
|
cur->request->FinishRequest(); // if cur->request->function were null then templates functions would not work
|
||||||
|
load_avg->StopRequest(cur->request);
|
||||||
|
|
||||||
|
if( cur->request->function )
|
||||||
|
cur->request->function->clear();
|
||||||
|
|
||||||
|
cur->request->Clear();
|
||||||
|
cur->request->run_state = Request::RunState::finished;
|
||||||
|
RemoveOldRequest(cur->request);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( cur->request->function )
|
||||||
|
cur->request->function->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
main_log << logendrequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects not locked)
|
||||||
|
void Job::DoWinixJob(pt::Space & job)
|
||||||
{
|
{
|
||||||
//log << log1 << "standard winix job: " << job.Text(L"type") << logend;
|
//log << log1 << "standard winix job: " << job.Text(L"type") << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects locked)
|
||||||
|
// use main_log for the logs to be in the correct order
|
||||||
|
void Job::RemoveOldRequest(Request * request)
|
||||||
|
{
|
||||||
|
std::list<Request>::iterator i = req_tab->begin();
|
||||||
|
|
||||||
|
while( i != req_tab->end() )
|
||||||
|
{
|
||||||
|
if( &(*i) == request )
|
||||||
|
{
|
||||||
|
main_log << log3 << "Job: removing request " << request << logend;
|
||||||
|
req_tab->erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
} // namespace Winix
|
||||||
|
|||||||
+49
-13
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
* Copyright (c) 2012-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -32,22 +32,26 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_jobs
|
#ifndef headerfile_winix_core_job
|
||||||
#define headerfile_winix_core_jobs
|
#define headerfile_winix_core_job
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include "basethread.h"
|
#include "basethread.h"
|
||||||
#include "space/space.h"
|
#include "space/space.h"
|
||||||
|
#include "jobtask.h"
|
||||||
|
#include "cur.h"
|
||||||
|
#include "loadavg.h"
|
||||||
|
#include "mounts.h"
|
||||||
|
#include "requestjobs/requestjobbase.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
{
|
{
|
||||||
|
class Functions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_JOBS_HOW_MANY_PRIORITIES 32
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -55,19 +59,40 @@ class Job : public BaseThread
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static const size_t PRIORITY_LOWEST = 0;
|
||||||
|
static const size_t PRIORITY_HIGHEST = 31;
|
||||||
|
|
||||||
|
static const size_t PRIORITY_DEFAULT = 16;
|
||||||
|
static const size_t PRIORITY_REQUEST_CONTINUATION = 17;
|
||||||
|
|
||||||
|
|
||||||
Job();
|
Job();
|
||||||
|
|
||||||
|
void SetCur(Cur * cur);
|
||||||
|
void SetFunctions(Functions * functions);
|
||||||
|
void SetLoadAvg(LoadAvg * load_avg);
|
||||||
|
void SetMounts(Mounts * mounts);
|
||||||
|
void SetReqTab(std::list<Request> * req_tab);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
add a new job to the queue
|
add a new job to the queue
|
||||||
priority: 0-31 (0 - the lowest priority, 31 - the highest priority)
|
priority: 0-31 (0 - the lowest priority, 31 - the highest priority)
|
||||||
*/
|
*/
|
||||||
void Add(PT::Space & job, int priority = 0);
|
void Add(pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
||||||
|
void Add(Request * request, pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
||||||
|
|
||||||
|
void Add(long job_id, pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
||||||
|
void Add(long job_id, Request * request, pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* register a new request job worker
|
||||||
|
*/
|
||||||
|
void RegisterRequestJob(long job_id, RequestJobBase & request_job);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
queue size, and size of all jobs in any priority
|
queue size, and size of all jobs in any priority
|
||||||
*/
|
*/
|
||||||
size_t Size(int priority) const;
|
size_t Size(size_t priority) const;
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
|
|
||||||
|
|
||||||
@@ -75,17 +100,24 @@ public:
|
|||||||
true if specified queue is empty
|
true if specified queue is empty
|
||||||
or if all queues are empty
|
or if all queues are empty
|
||||||
*/
|
*/
|
||||||
bool Empty(int priority) const;
|
bool Empty(size_t priority) const;
|
||||||
bool Empty() const;
|
bool Empty() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef std::queue<PT::Space> JobsQueue;
|
Cur * cur;
|
||||||
|
Functions * functions;
|
||||||
|
LoadAvg * load_avg;
|
||||||
|
Mounts * mounts;
|
||||||
|
std::list<Request> * req_tab;
|
||||||
|
|
||||||
|
typedef std::queue<JobTask> JobsQueue;
|
||||||
typedef std::vector<JobsQueue> JobsQueueTab;
|
typedef std::vector<JobsQueue> JobsQueueTab;
|
||||||
JobsQueueTab jobs_queue_tab;
|
JobsQueueTab jobs_queue_tab;
|
||||||
|
std::multimap<long, RequestJobBase*> request_jobs;
|
||||||
|
|
||||||
void CheckPriority(int & priority) const;
|
void CheckPriority(size_t & priority) const;
|
||||||
void SaveToFile();
|
void SaveToFile();
|
||||||
void ReadFromFile();
|
void ReadFromFile();
|
||||||
|
|
||||||
@@ -101,9 +133,13 @@ private:
|
|||||||
|
|
||||||
bool SignalReceived();
|
bool SignalReceived();
|
||||||
void Do();
|
void Do();
|
||||||
void DoQueue(JobsQueue & jobs_queue);
|
void DoQueue(JobsQueue & jobs_queue, size_t priority);
|
||||||
void DoJob(PT::Space & job);
|
void DoJob(JobTask & task, size_t priority);
|
||||||
void DoWinixJob(PT::Space & job);
|
void DoRequestContinuationJob(JobTask & job_task, size_t priority);
|
||||||
|
void DoWinixJob(pt::Space & job);
|
||||||
|
void RemoveOldRequest(Request * request);
|
||||||
|
void RemoveAllJobsRequests();
|
||||||
|
PluginRes DoRequestJobs(JobTask & task, long job_id, size_t priority);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winix_core_jobtask
|
||||||
|
#define headerfile_winix_core_jobtask
|
||||||
|
|
||||||
|
#include "space/space.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
class Request;
|
||||||
|
|
||||||
|
|
||||||
|
class JobTask
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const long JOB_TYPE_DEFAULT = 1;
|
||||||
|
static const long JOB_TYPE_REQUEST_CONTINUATION = 2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the value of job_id will be defined by each controller
|
||||||
|
* so the default value is better to have -1 instead of for example 1
|
||||||
|
*/
|
||||||
|
static const long JOB_ID_DEFAULT = -1;
|
||||||
|
|
||||||
|
long job_type;
|
||||||
|
long job_id;
|
||||||
|
Request * request;
|
||||||
|
pt::Space job;
|
||||||
|
|
||||||
|
|
||||||
|
JobTask()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
job_type = JOB_TYPE_DEFAULT;
|
||||||
|
job_id = JOB_ID_DEFAULT;
|
||||||
|
request = nullptr;
|
||||||
|
job.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -69,8 +69,8 @@ struct LastItem
|
|||||||
long session_id;
|
long session_id;
|
||||||
|
|
||||||
// start logging and end logging
|
// start logging and end logging
|
||||||
PT::Date start;
|
pt::Date start;
|
||||||
PT::Date end;
|
pt::Date end;
|
||||||
|
|
||||||
|
|
||||||
LastItem();
|
LastItem();
|
||||||
|
|||||||
+13
-20
@@ -56,7 +56,8 @@ LoadAvg::LoadAvg()
|
|||||||
cache_req_per_sec5 = 0.0;
|
cache_req_per_sec5 = 0.0;
|
||||||
cache_req_per_sec15 = 0.0;
|
cache_req_per_sec15 = 0.0;
|
||||||
|
|
||||||
was_stop_request = false;
|
timespec_old_req_stop.tv_sec = 0;
|
||||||
|
timespec_old_req_stop.tv_nsec = 0;
|
||||||
|
|
||||||
CreateTable();
|
CreateTable();
|
||||||
}
|
}
|
||||||
@@ -76,7 +77,8 @@ LoadAvg & LoadAvg::operator=(const LoadAvg & l)
|
|||||||
cache_req_per_sec5 = l.cache_req_per_sec5;
|
cache_req_per_sec5 = l.cache_req_per_sec5;
|
||||||
cache_req_per_sec15 = l.cache_req_per_sec15;
|
cache_req_per_sec15 = l.cache_req_per_sec15;
|
||||||
|
|
||||||
was_stop_request = l.was_stop_request;
|
timespec_old_req_stop.tv_sec = l.timespec_old_req_stop.tv_sec;
|
||||||
|
timespec_old_req_stop.tv_nsec = l.timespec_old_req_stop.tv_nsec;
|
||||||
|
|
||||||
CreateTable();
|
CreateTable();
|
||||||
|
|
||||||
@@ -182,14 +184,14 @@ void LoadAvg::CheckTimers()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LoadAvg::StartRequest()
|
void LoadAvg::StartRequest(Request * req)
|
||||||
{
|
{
|
||||||
clock_gettime(CLOCK_REALTIME, &start_req);
|
if( timespec_old_req_stop.tv_sec != 0 )
|
||||||
|
|
||||||
if( was_stop_request )
|
|
||||||
{
|
{
|
||||||
double dp = (start_req.tv_sec - stop_req.tv_sec);
|
// we got at least one request in the past
|
||||||
dp += double(start_req.tv_nsec - stop_req.tv_nsec) / 1000000000.0; // make sure that tv_nsec has signed type
|
timespec diff;
|
||||||
|
calculate_timespec_diff(timespec_old_req_stop, req->timespec_req_start, diff);
|
||||||
|
double dp = timespec_to_double(diff);
|
||||||
|
|
||||||
current1.dp += dp;
|
current1.dp += dp;
|
||||||
current5.dp += dp;
|
current5.dp += dp;
|
||||||
@@ -203,14 +205,9 @@ void LoadAvg::StartRequest()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LoadAvg::StopRequest()
|
void LoadAvg::StopRequest(Request * req)
|
||||||
{
|
{
|
||||||
char buf[50];
|
double dr = timespec_to_double(req->timespec_req_diff);
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &stop_req);
|
|
||||||
|
|
||||||
double dr = (stop_req.tv_sec - start_req.tv_sec);
|
|
||||||
dr += double(stop_req.tv_nsec - start_req.tv_nsec) / 1000000000.0; // make sure that tv_nsec has signed type
|
|
||||||
|
|
||||||
current1.dr += dr;
|
current1.dr += dr;
|
||||||
current5.dr += dr;
|
current5.dr += dr;
|
||||||
@@ -220,11 +217,7 @@ char buf[50];
|
|||||||
current5.req += 1;
|
current5.req += 1;
|
||||||
current15.req += 1;
|
current15.req += 1;
|
||||||
|
|
||||||
sprintf(buf, "%f", dr);
|
timespec_old_req_stop = req->timespec_req_stop;
|
||||||
SetNonZeroDigitsAfterComma(buf, 2);
|
|
||||||
|
|
||||||
log << log2 << "LA: request took: " << buf << "s" << logend;
|
|
||||||
was_stop_request = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include "winixbase.h"
|
#include "winixbase.h"
|
||||||
|
#include "request.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -60,8 +61,8 @@ public:
|
|||||||
LoadAvg & operator=(const LoadAvg & l);
|
LoadAvg & operator=(const LoadAvg & l);
|
||||||
LoadAvg(const LoadAvg & l);
|
LoadAvg(const LoadAvg & l);
|
||||||
|
|
||||||
void StartRequest();
|
void StartRequest(Request * req);
|
||||||
void StopRequest();
|
void StopRequest(Request * req);
|
||||||
|
|
||||||
double LoadAvgNow(); // load average withing last WINIX_LOADAVG_GRANULARITY1 seconds
|
double LoadAvgNow(); // load average withing last WINIX_LOADAVG_GRANULARITY1 seconds
|
||||||
double LoadAvg1();
|
double LoadAvg1();
|
||||||
@@ -78,7 +79,7 @@ private:
|
|||||||
struct Times
|
struct Times
|
||||||
{
|
{
|
||||||
double dr; // time for the request (in seconds)
|
double dr; // time for the request (in seconds)
|
||||||
double dp; // time for the pause between requestes (in seconds)
|
double dp; // time for the pause between requestes(in seconds)
|
||||||
long req; // how many requests
|
long req; // how many requests
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
@@ -98,6 +99,8 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
timespec timespec_old_req_stop;
|
||||||
|
|
||||||
void CheckTimers();
|
void CheckTimers();
|
||||||
void UpdateTimer1();
|
void UpdateTimer1();
|
||||||
void UpdateTimer5();
|
void UpdateTimer5();
|
||||||
@@ -117,9 +120,7 @@ private:
|
|||||||
void Calculate5();
|
void Calculate5();
|
||||||
void Calculate15();
|
void Calculate15();
|
||||||
|
|
||||||
bool was_stop_request;
|
|
||||||
timespec start_req, stop_req;
|
|
||||||
|
|
||||||
Times * tab1;
|
Times * tab1;
|
||||||
size_t len1;
|
size_t len1;
|
||||||
|
|
||||||
|
|||||||
+130
-46
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2019, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -72,7 +72,7 @@ void Log::SetMaxRequests(int max_requests)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Log::PrintDate(const PT::Date & date)
|
void Log::PrintDate(const pt::Date & date)
|
||||||
{
|
{
|
||||||
FileLog * winix_file_log = dynamic_cast<FileLog*>(file_log);
|
FileLog * winix_file_log = dynamic_cast<FileLog*>(file_log);
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ void Log::PrintDate(const PT::Date & date)
|
|||||||
|
|
||||||
Log & Log::operator<<(const void * s)
|
Log & Log::operator<<(const void * s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ Log & Log::operator<<(const void * s)
|
|||||||
|
|
||||||
Log & Log::operator<<(const char * s)
|
Log & Log::operator<<(const char * s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ Log & Log::operator<<(const char * s)
|
|||||||
|
|
||||||
Log & Log::operator<<(const std::string & s)
|
Log & Log::operator<<(const std::string & s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ Log & Log::operator<<(const std::string & s)
|
|||||||
|
|
||||||
Log & Log::operator<<(const std::string * s)
|
Log & Log::operator<<(const std::string * s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,120 +118,197 @@ Log & Log::operator<<(const std::string * s)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const wchar_t * s)
|
Log & Log::operator<<(const wchar_t * s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const std::wstring & s)
|
Log & Log::operator<<(const std::wstring & s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const std::wstring * s)
|
Log & Log::operator<<(const std::wstring * s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(bool s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(short s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(int s)
|
Log & Log::operator<<(int s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(long s)
|
Log & Log::operator<<(long s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(long long s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(char s)
|
Log & Log::operator<<(char s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(unsigned char s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(wchar_t s)
|
Log & Log::operator<<(wchar_t s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(size_t s)
|
Log & Log::operator<<(char32_t s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(unsigned short s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(unsigned int s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(unsigned long s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(unsigned long long s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(float s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(double s)
|
Log & Log::operator<<(double s)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(long double s)
|
||||||
Log & Log::operator<<(const PT::Space & s)
|
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(s);
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(const pt::Stream & s)
|
||||||
Log & Log::operator<<(const PT::Date & date)
|
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(date);
|
pt::Log::operator<<(s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(const pt::Space & s)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(const pt::Date & date)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(date);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(morm::Model & model)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(model);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(LogManipulators m)
|
Log & Log::operator<<(LogManipulators m)
|
||||||
{
|
{
|
||||||
switch(m)
|
switch(m)
|
||||||
{
|
{
|
||||||
case LogManipulators::log1:
|
case LogManipulators::log1:
|
||||||
PT::Log::operator<<(PT::Log::log1);
|
pt::Log::operator<<(pt::Log::log1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LogManipulators::log2:
|
case LogManipulators::log2:
|
||||||
PT::Log::operator<<(PT::Log::log2);
|
pt::Log::operator<<(pt::Log::log2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LogManipulators::log3:
|
case LogManipulators::log3:
|
||||||
PT::Log::operator<<(PT::Log::log3);
|
pt::Log::operator<<(pt::Log::log3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LogManipulators::log4:
|
case LogManipulators::log4:
|
||||||
PT::Log::operator<<(PT::Log::log4);
|
pt::Log::operator<<(pt::Log::log4);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LogManipulators::logend:
|
case LogManipulators::logend:
|
||||||
PT::Log::operator<<(PT::Log::logend);
|
pt::Log::operator<<(pt::Log::logend);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LogManipulators::logsave:
|
case LogManipulators::logsave:
|
||||||
PT::Log::operator<<(PT::Log::logsave);
|
pt::Log::operator<<(pt::Log::logsave);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LogManipulators::logendrequest:
|
case LogManipulators::logendrequest:
|
||||||
@@ -246,7 +323,14 @@ Log & Log::operator<<(LogManipulators m)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(pt::Log::Manipulators m)
|
||||||
|
{
|
||||||
|
pt::Log::operator<<(m);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -265,33 +349,33 @@ return *this;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
Log & Log::LogString(const std::string & value, size_t max_size)
|
Log & Log::put_string(const std::string & value, size_t max_size)
|
||||||
{
|
{
|
||||||
PT::Log::LogString(value, max_size);
|
pt::Log::put_string(value, max_size);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::LogString(const std::wstring & value, size_t max_size)
|
Log & Log::put_string(const std::wstring & value, size_t max_size)
|
||||||
{
|
{
|
||||||
PT::Log::LogString(value, max_size);
|
pt::Log::put_string(value, max_size);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::LogBinary(const char * blob, size_t blob_len)
|
Log & Log::put_binary_blob(const char * blob, size_t blob_len)
|
||||||
{
|
{
|
||||||
PT::Log::LogBinary(blob, blob_len);
|
pt::Log::put_binary_blob(blob, blob_len);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log & Log::LogBinary(const std::string & blob)
|
Log & Log::put_binary_blob(const std::string & blob)
|
||||||
{
|
{
|
||||||
PT::Log::LogBinary(blob);
|
pt::Log::put_binary_blob(blob);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+37
-17
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2019, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -44,6 +44,8 @@
|
|||||||
#include "logmanipulators.h"
|
#include "logmanipulators.h"
|
||||||
#include "filelog.h"
|
#include "filelog.h"
|
||||||
#include "log/log.h"
|
#include "log/log.h"
|
||||||
|
#include "morm.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -51,7 +53,7 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Log : public PT::Log
|
class Log : public pt::Log
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -69,27 +71,45 @@ public:
|
|||||||
virtual Log & operator<<(const wchar_t * s);
|
virtual Log & operator<<(const wchar_t * s);
|
||||||
virtual Log & operator<<(const std::wstring * s);
|
virtual Log & operator<<(const std::wstring * s);
|
||||||
virtual Log & operator<<(const std::wstring & s);
|
virtual Log & operator<<(const std::wstring & s);
|
||||||
|
virtual Log & operator<<(char s);
|
||||||
|
virtual Log & operator<<(unsigned char);
|
||||||
|
virtual Log & operator<<(wchar_t s);
|
||||||
|
virtual Log & operator<<(char32_t s);
|
||||||
|
virtual Log & operator<<(bool);
|
||||||
|
virtual Log & operator<<(short);
|
||||||
virtual Log & operator<<(int s);
|
virtual Log & operator<<(int s);
|
||||||
virtual Log & operator<<(long s);
|
virtual Log & operator<<(long s);
|
||||||
virtual Log & operator<<(char s);
|
virtual Log & operator<<(long long);
|
||||||
virtual Log & operator<<(wchar_t s);
|
virtual Log & operator<<(unsigned short);
|
||||||
virtual Log & operator<<(size_t s);
|
virtual Log & operator<<(unsigned int);
|
||||||
|
virtual Log & operator<<(unsigned long);
|
||||||
|
virtual Log & operator<<(unsigned long long);
|
||||||
|
virtual Log & operator<<(float);
|
||||||
virtual Log & operator<<(double s);
|
virtual Log & operator<<(double s);
|
||||||
virtual Log & operator<<(const PT::Space & space);
|
virtual Log & operator<<(long double);
|
||||||
virtual Log & operator<<(LogManipulators m);
|
|
||||||
virtual Log & operator<<(const PT::Date & date);
|
|
||||||
|
|
||||||
virtual void PrintDate(const PT::Date & date);
|
virtual Log & operator<<(const pt::Stream & stream);
|
||||||
|
virtual Log & operator<<(const pt::Space & space);
|
||||||
|
virtual Log & operator<<(const pt::Date & date);
|
||||||
|
|
||||||
|
virtual Log & operator<<(LogManipulators m);
|
||||||
|
virtual Log & operator<<(pt::Log::Manipulators m);
|
||||||
|
virtual Log & operator<<(morm::Model & model);
|
||||||
|
|
||||||
|
|
||||||
|
virtual void PrintDate(const pt::Date & date);
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
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);
|
Log & operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
||||||
|
|
||||||
|
|
||||||
virtual Log & LogString(const std::string & value, size_t max_size);
|
/*
|
||||||
virtual Log & LogString(const std::wstring & value, size_t max_size);
|
virtual Log & put_string(const std::string & value, size_t max_size);
|
||||||
|
virtual Log & put_string(const std::wstring & value, size_t max_size);
|
||||||
|
|
||||||
virtual Log & LogBinary(const char * blob, size_t blob_len);
|
virtual Log & put_binary_blob(const char * blob, size_t blob_len);
|
||||||
virtual Log & LogBinary(const std::string & blob);
|
virtual Log & put_binary_blob(const std::string & blob);
|
||||||
|
*/
|
||||||
|
|
||||||
//virtual Log & SystemErr(int err);
|
//virtual Log & SystemErr(int err);
|
||||||
|
|
||||||
@@ -111,9 +131,9 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
Log & Log::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
Log & Log::operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
||||||
{
|
{
|
||||||
PT::Log::operator<<(buf);
|
pt::Log::operator<<(buf);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2018, Tomasz Sowa
|
* Copyright (c) 2011-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -69,11 +69,11 @@ enum LogManipulators
|
|||||||
logend,
|
logend,
|
||||||
logsave,
|
logsave,
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it is needed here?
|
||||||
|
*/
|
||||||
logendrequest,
|
logendrequest,
|
||||||
|
|
||||||
loginfo,
|
|
||||||
logerror,
|
|
||||||
logwarning
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+432
-107
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -57,7 +57,7 @@ namespace misc_private
|
|||||||
0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028,
|
0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028,
|
||||||
0x2029, 0x202F, 0x205F, 0x3000 };
|
0x2029, 0x202F, 0x205F, 0x3000 };
|
||||||
|
|
||||||
PT::WTextStream tmp_qencode;
|
pt::WTextStream tmp_qencode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ void CorrectUrlOnlyAllowedChar(std::wstring & url)
|
|||||||
{
|
{
|
||||||
CorrectUrlDots(url);
|
CorrectUrlDots(url);
|
||||||
CorrectUrlChars(url);
|
CorrectUrlChars(url);
|
||||||
PT::ToLower(url);
|
pt::to_lower_emplace(url);
|
||||||
Trim(url, '_');
|
Trim(url, '_');
|
||||||
|
|
||||||
if( url.empty() || url == L"." )
|
if( url.empty() || url == L"." )
|
||||||
@@ -359,7 +359,7 @@ void CorrectUrlOnlyAllowedChar(std::wstring & url)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// DEPRECATED now pt::Date can print a month in Roman numerals
|
||||||
const wchar_t * DateToStr(int year, int month, int day)
|
const wchar_t * DateToStr(int year, int month, int day)
|
||||||
{
|
{
|
||||||
static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
|
static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
|
||||||
@@ -383,6 +383,7 @@ static wchar_t buffer[100];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// DEPRECATED now pt::Date can print a month in Roman numerals
|
||||||
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec)
|
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec)
|
||||||
{
|
{
|
||||||
static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
|
static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
|
||||||
@@ -408,7 +409,7 @@ static wchar_t buffer[100];
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const wchar_t * DateToStr(const PT::Date & d)
|
const wchar_t * DateToStr(const pt::Date & d)
|
||||||
{
|
{
|
||||||
return DateToStr(d.year, d.month, d.day, d.hour, d.min, d.sec);
|
return DateToStr(d.year, d.month, d.day, d.hour, d.min, d.sec);
|
||||||
}
|
}
|
||||||
@@ -416,14 +417,14 @@ const wchar_t * DateToStr(const PT::Date & d)
|
|||||||
|
|
||||||
const wchar_t * DateToStr(time_t t)
|
const wchar_t * DateToStr(time_t t)
|
||||||
{
|
{
|
||||||
PT::Date date = t;
|
pt::Date date = t;
|
||||||
|
|
||||||
return DateToStr(date);
|
return DateToStr(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const wchar_t * DateToStrWithoutHours(const PT::Date & d)
|
const wchar_t * DateToStrWithoutHours(const pt::Date & d)
|
||||||
{
|
{
|
||||||
return DateToStr(d.year, d.month, d.day);
|
return DateToStr(d.year, d.month, d.day);
|
||||||
}
|
}
|
||||||
@@ -431,7 +432,7 @@ const wchar_t * DateToStrWithoutHours(const PT::Date & d)
|
|||||||
|
|
||||||
const wchar_t * DateToStrWithoutHours(time_t t)
|
const wchar_t * DateToStrWithoutHours(time_t t)
|
||||||
{
|
{
|
||||||
PT::Date date = t;
|
pt::Date date = t;
|
||||||
|
|
||||||
return DateToStrWithoutHours(date);
|
return DateToStrWithoutHours(date);
|
||||||
}
|
}
|
||||||
@@ -460,7 +461,7 @@ return buffer;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char * DateToStrCookie(const PT::Date & d)
|
const char * DateToStrCookie(const pt::Date & d)
|
||||||
{
|
{
|
||||||
return DateToStrCookie(d.year, d.month, d.day, d.hour, d.min, d.sec);
|
return DateToStrCookie(d.year, d.month, d.day, d.hour, d.min, d.sec);
|
||||||
}
|
}
|
||||||
@@ -468,7 +469,7 @@ const char * DateToStrCookie(const PT::Date & d)
|
|||||||
|
|
||||||
const char * DateToStrCookie(time_t t)
|
const char * DateToStrCookie(time_t t)
|
||||||
{
|
{
|
||||||
PT::Date date = t;
|
pt::Date date = t;
|
||||||
|
|
||||||
return DateToStrCookie(date);
|
return DateToStrCookie(date);
|
||||||
}
|
}
|
||||||
@@ -493,9 +494,9 @@ return buffer;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
PT::WTextStream IPToStr(unsigned int ip)
|
pt::WTextStream IPToStr(unsigned int ip)
|
||||||
{
|
{
|
||||||
PT::WTextStream buf;
|
pt::WTextStream buf;
|
||||||
|
|
||||||
for(int i=0 ; i<4 ; ++i, ip >>= 8)
|
for(int i=0 ; i<4 ; ++i, ip >>= 8)
|
||||||
{
|
{
|
||||||
@@ -509,7 +510,7 @@ return buf;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PT::WTextStream IPToStr(int ip)
|
pt::WTextStream IPToStr(int ip)
|
||||||
{
|
{
|
||||||
return IPToStr(static_cast<unsigned int>(ip));
|
return IPToStr(static_cast<unsigned int>(ip));
|
||||||
}
|
}
|
||||||
@@ -819,25 +820,35 @@ return correct;
|
|||||||
|
|
||||||
bool ValidateEmail(const wchar_t * email)
|
bool ValidateEmail(const wchar_t * email)
|
||||||
{
|
{
|
||||||
int at = 0; // how many '@'
|
int at = 0; // how many '@'
|
||||||
int dots_after_at = 0; // how many dots in the domain part
|
int dots_after_at = 0; // how many dots in the domain part
|
||||||
|
const size_t address_max_length = 64; // the max length before a '@'
|
||||||
|
const size_t domain_max_length = 255; // the max length after a '@'
|
||||||
|
size_t address_length = 0;
|
||||||
|
size_t domain_length = 0;
|
||||||
|
|
||||||
for(size_t i=0 ; email[i] != 0 ; ++i)
|
for(size_t i=0 ; email[i] != 0 ; ++i)
|
||||||
{
|
{
|
||||||
if( !IsEmailCorrectChar(email[i]) )
|
if( !IsEmailCorrectChar(email[i]) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( email[i] == '@' )
|
if( email[i] == '@' )
|
||||||
|
{
|
||||||
++at;
|
++at;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( at == 0 )
|
||||||
|
address_length += 1;
|
||||||
|
else
|
||||||
|
domain_length += 1;
|
||||||
|
|
||||||
if( email[i] == '.' && at > 0 )
|
if( email[i] == '.' && at > 0 )
|
||||||
++dots_after_at;
|
++dots_after_at;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( at != 1 || dots_after_at == 0 )
|
return at == 1 && dots_after_at > 0 && address_length <= address_max_length && domain_length <= domain_max_length;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -854,7 +865,7 @@ bool IsFile(const wchar_t * file)
|
|||||||
struct stat sb;
|
struct stat sb;
|
||||||
char file_name[WINIX_OS_PATH_SIZE];
|
char file_name[WINIX_OS_PATH_SIZE];
|
||||||
|
|
||||||
if( !WideToUTF8(file, file_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(file, (char*)file_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (stat(file_name, &sb) == 0);
|
return (stat(file_name, &sb) == 0);
|
||||||
@@ -876,7 +887,7 @@ char dir_name[WINIX_OS_PATH_SIZE];
|
|||||||
|
|
||||||
if( !IsFile(dir) )
|
if( !IsFile(dir) )
|
||||||
{
|
{
|
||||||
if( !WideToUTF8(dir, dir_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(dir, (char*)dir_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( mkdir(dir_name, 0777) < 0 )
|
if( mkdir(dir_name, 0777) < 0 )
|
||||||
@@ -952,7 +963,7 @@ struct group * result;
|
|||||||
char group_name[WINIX_OS_USERNAME_SIZE];
|
char group_name[WINIX_OS_USERNAME_SIZE];
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
|
|
||||||
if( !WideToUTF8(name, group_name, WINIX_OS_USERNAME_SIZE) )
|
if( !pt::wide_to_utf8(name, (char*)group_name, WINIX_OS_USERNAME_SIZE) )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if( getgrnam_r(group_name, &gr, buffer, sizeof(buffer)/sizeof(char), &result) != 0 )
|
if( getgrnam_r(group_name, &gr, buffer, sizeof(buffer)/sizeof(char), &result) != 0 )
|
||||||
@@ -988,7 +999,7 @@ bool SetPriv(const wchar_t * name, int priv, int group)
|
|||||||
{
|
{
|
||||||
char file_name[WINIX_OS_PATH_SIZE];
|
char file_name[WINIX_OS_PATH_SIZE];
|
||||||
|
|
||||||
if( !WideToUTF8(name, file_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(name, (char*)file_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( chmod(file_name, priv) < 0 )
|
if( chmod(file_name, priv) < 0 )
|
||||||
@@ -1046,10 +1057,10 @@ char src_name[WINIX_OS_PATH_SIZE];
|
|||||||
char dst_name[WINIX_OS_PATH_SIZE];
|
char dst_name[WINIX_OS_PATH_SIZE];
|
||||||
FILE * in, * out;
|
FILE * in, * out;
|
||||||
|
|
||||||
if( !WideToUTF8(src, src_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(src, (char*)src_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !WideToUTF8(dst, dst_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(dst, (char*)dst_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
in = fopen(src_name, "rb");
|
in = fopen(src_name, "rb");
|
||||||
@@ -1091,7 +1102,7 @@ bool RemoveFile(const wchar_t * file)
|
|||||||
{
|
{
|
||||||
char file_name[WINIX_OS_PATH_SIZE];
|
char file_name[WINIX_OS_PATH_SIZE];
|
||||||
|
|
||||||
if( !WideToUTF8(file, file_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(file, (char*)file_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return unlink(file_name) == 0;
|
return unlink(file_name) == 0;
|
||||||
@@ -1110,10 +1121,10 @@ bool RenameFile(const wchar_t * from, const wchar_t * to)
|
|||||||
char from_name[WINIX_OS_PATH_SIZE];
|
char from_name[WINIX_OS_PATH_SIZE];
|
||||||
char to_name[WINIX_OS_PATH_SIZE];
|
char to_name[WINIX_OS_PATH_SIZE];
|
||||||
|
|
||||||
if( !WideToUTF8(from, from_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(from, (char*)from_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !WideToUTF8(to, to_name, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(to, (char*)to_name, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return rename(from_name, to_name) == 0;
|
return rename(from_name, to_name) == 0;
|
||||||
@@ -1137,7 +1148,7 @@ std::ifstream get_file_content;
|
|||||||
if( clear_content )
|
if( clear_content )
|
||||||
content.clear();
|
content.clear();
|
||||||
|
|
||||||
if( !WideToUTF8(file_path, file, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(file_path, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
||||||
@@ -1148,7 +1159,7 @@ std::ifstream get_file_content;
|
|||||||
/*
|
/*
|
||||||
* we don't report any errors when converting from UTF8 to wide characters here
|
* we don't report any errors when converting from UTF8 to wide characters here
|
||||||
*/
|
*/
|
||||||
PT::UTF8ToWide(get_file_content, content);
|
pt::utf8_to_wide(get_file_content, content);
|
||||||
get_file_content.close();
|
get_file_content.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1161,30 +1172,126 @@ bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool cl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if there is not an extension it returns a pointer to the last '\0' character
|
bool GetUTF8File(const wchar_t * file_path, pt::WTextStream & content, bool clear_content)
|
||||||
|
{
|
||||||
|
char file[WINIX_OS_PATH_SIZE];
|
||||||
|
std::ifstream get_file_content;
|
||||||
|
|
||||||
|
if( clear_content )
|
||||||
|
content.clear();
|
||||||
|
|
||||||
|
if( !pt::wide_to_utf8(file_path, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
||||||
|
|
||||||
|
if( !get_file_content )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we don't report any errors when converting from UTF8 to wide characters here
|
||||||
|
*/
|
||||||
|
pt::utf8_to_wide(get_file_content, content);
|
||||||
|
get_file_content.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GetUTF8File(const std::wstring & file_path, pt::WTextStream & content, bool clear_content)
|
||||||
|
{
|
||||||
|
return GetUTF8File(file_path.c_str(), content, clear_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool GetBinaryFile(const wchar_t * file_path, BinaryPage & content, bool clear_content)
|
||||||
|
{
|
||||||
|
char file[WINIX_OS_PATH_SIZE];
|
||||||
|
char buffer[4096];
|
||||||
|
size_t buffer_len = sizeof(buffer) / sizeof(char);
|
||||||
|
std::ifstream get_file_content;
|
||||||
|
|
||||||
|
if( clear_content )
|
||||||
|
content.clear();
|
||||||
|
|
||||||
|
if( !pt::wide_to_utf8(file_path, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
||||||
|
|
||||||
|
if( !get_file_content )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
get_file_content.read(buffer, buffer_len);
|
||||||
|
content.write(buffer, get_file_content.gcount());
|
||||||
|
}
|
||||||
|
while( !get_file_content.eof() && get_file_content.good() );
|
||||||
|
|
||||||
|
get_file_content.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GetBinaryFile(const std::wstring & file_path, BinaryPage & content, bool clear_content)
|
||||||
|
{
|
||||||
|
return GetBinaryFile(file_path.c_str(), content, clear_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if there is no an extension it returns a pointer to the last '\0' character
|
||||||
const wchar_t * GetFileExt(const wchar_t * name)
|
const wchar_t * GetFileExt(const wchar_t * name)
|
||||||
{
|
{
|
||||||
size_t i, ilast;
|
const wchar_t * dot_ptr = nullptr;
|
||||||
|
|
||||||
// looking for the end of the name
|
for( ; *name != 0 ; ++name)
|
||||||
for(i=0 ; name[i] != 0 ; ++i);
|
{
|
||||||
|
if( *name == '.' )
|
||||||
|
{
|
||||||
|
dot_ptr = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( i == 0 )
|
return dot_ptr ? dot_ptr + 1 : name;
|
||||||
return name; // ops, the name is empty
|
}
|
||||||
|
|
||||||
// remember the end of the string
|
|
||||||
ilast = i;
|
|
||||||
|
|
||||||
// looking for the last dot
|
void PrepareNewFileName(const wchar_t * src, const wchar_t * postfix, std::wstring & res, bool clear_res)
|
||||||
for(--i ; i>0 && name[i] != '.' ; --i);
|
{
|
||||||
|
bool has_ext = false;
|
||||||
|
const wchar_t * ext = GetFileExt(src);
|
||||||
|
|
||||||
if( name[i] != '.' )
|
if( clear_res )
|
||||||
return name + ilast; // ops, there is not a dot
|
res.clear();
|
||||||
|
|
||||||
// the extensions starts from i+1
|
size_t len = ext - src;
|
||||||
// and can be empty (if the last character is a dot)
|
|
||||||
|
|
||||||
return name + i + 1;
|
if( len > 0 )
|
||||||
|
{
|
||||||
|
if( *(ext-1) == '.' )
|
||||||
|
{
|
||||||
|
len -= 1;
|
||||||
|
has_ext = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.append(src, len);
|
||||||
|
res.append(postfix);
|
||||||
|
|
||||||
|
if( has_ext )
|
||||||
|
res.append(1, '.');
|
||||||
|
|
||||||
|
res.append(ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PrepareNewFileName(const std::wstring & src, const std::wstring & postfix, std::wstring & res, bool clear_res)
|
||||||
|
{
|
||||||
|
return PrepareNewFileName(src.c_str(), postfix.c_str(), res, clear_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1194,31 +1301,31 @@ int SelectFileType(const wchar_t * file_name)
|
|||||||
|
|
||||||
// as an image we're using only those types which can be rendered
|
// as an image we're using only those types which can be rendered
|
||||||
// by a web browser
|
// by a web browser
|
||||||
if( PT::EqualNoCase(ext, L"jpg") ||
|
if( pt::is_equal_nc(ext, L"jpg") ||
|
||||||
PT::EqualNoCase(ext, L"jpeg") ||
|
pt::is_equal_nc(ext, L"jpeg") ||
|
||||||
PT::EqualNoCase(ext, L"jpe") ||
|
pt::is_equal_nc(ext, L"jpe") ||
|
||||||
PT::EqualNoCase(ext, L"pic") ||
|
pt::is_equal_nc(ext, L"pic") ||
|
||||||
PT::EqualNoCase(ext, L"tga") ||
|
pt::is_equal_nc(ext, L"tga") ||
|
||||||
PT::EqualNoCase(ext, L"gif") ||
|
pt::is_equal_nc(ext, L"gif") ||
|
||||||
PT::EqualNoCase(ext, L"bmp") ||
|
pt::is_equal_nc(ext, L"bmp") ||
|
||||||
PT::EqualNoCase(ext, L"png") )
|
pt::is_equal_nc(ext, L"png") )
|
||||||
return WINIX_ITEM_FILETYPE_IMAGE;
|
return WINIX_ITEM_FILETYPE_IMAGE;
|
||||||
|
|
||||||
if( PT::EqualNoCase(ext, L"pdf") ||
|
if( pt::is_equal_nc(ext, L"pdf") ||
|
||||||
PT::EqualNoCase(ext, L"doc") ||
|
pt::is_equal_nc(ext, L"doc") ||
|
||||||
PT::EqualNoCase(ext, L"xls") ||
|
pt::is_equal_nc(ext, L"xls") ||
|
||||||
PT::EqualNoCase(ext, L"txt") ||
|
pt::is_equal_nc(ext, L"txt") ||
|
||||||
PT::EqualNoCase(ext, L"ods") ||
|
pt::is_equal_nc(ext, L"ods") ||
|
||||||
PT::EqualNoCase(ext, L"odt") )
|
pt::is_equal_nc(ext, L"odt") )
|
||||||
return WINIX_ITEM_FILETYPE_DOCUMENT;
|
return WINIX_ITEM_FILETYPE_DOCUMENT;
|
||||||
|
|
||||||
if( PT::EqualNoCase(ext, L"avi") ||
|
if( pt::is_equal_nc(ext, L"avi") ||
|
||||||
PT::EqualNoCase(ext, L"mp4") ||
|
pt::is_equal_nc(ext, L"mp4") ||
|
||||||
PT::EqualNoCase(ext, L"flv") ||
|
pt::is_equal_nc(ext, L"flv") ||
|
||||||
PT::EqualNoCase(ext, L"mpg") ||
|
pt::is_equal_nc(ext, L"mpg") ||
|
||||||
PT::EqualNoCase(ext, L"mpeg") ||
|
pt::is_equal_nc(ext, L"mpeg") ||
|
||||||
PT::EqualNoCase(ext, L"mkv") ||
|
pt::is_equal_nc(ext, L"mkv") ||
|
||||||
PT::EqualNoCase(ext, L"wmv") )
|
pt::is_equal_nc(ext, L"wmv") )
|
||||||
return WINIX_ITEM_FILETYPE_VIDEO;
|
return WINIX_ITEM_FILETYPE_VIDEO;
|
||||||
|
|
||||||
return WINIX_ITEM_FILETYPE_UNKNOWN;
|
return WINIX_ITEM_FILETYPE_UNKNOWN;
|
||||||
@@ -1239,8 +1346,15 @@ void UrlEncode(const char * in, std::string & out, bool clear_out)
|
|||||||
if( clear_out )
|
if( clear_out )
|
||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
|
pt::TextStream stream;
|
||||||
|
|
||||||
for(size_t i=0 ; in[i] != 0 ; ++i)
|
for(size_t i=0 ; in[i] != 0 ; ++i)
|
||||||
UrlEncode(in[i], out, false);
|
{
|
||||||
|
UrlEncode(in[i], stream, true);
|
||||||
|
|
||||||
|
for(size_t s=0 ; s < stream.size() ; ++s)
|
||||||
|
out += stream[s];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1250,39 +1364,44 @@ void UrlEncode(const std::string & in, std::string & out, bool clear_out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//void UrlEncode(const wchar_t * in, std::string & out, bool clear_out)
|
||||||
void UrlEncode(const wchar_t * in, std::string & out, bool clear_out)
|
//{
|
||||||
{
|
// if( clear_out )
|
||||||
static std::string ain;
|
// out.clear();
|
||||||
|
//
|
||||||
PT::WideToUTF8(in, ain);
|
// pt::TextStream stream;
|
||||||
|
//
|
||||||
if( clear_out )
|
// for(size_t i=0 ; in[i] != 0 ; ++i)
|
||||||
out.clear();
|
// {
|
||||||
|
// UrlEncode(in[i], stream, true);
|
||||||
for(size_t i=0 ; i < ain.size() ; ++i)
|
//
|
||||||
UrlEncode(ain[i], out, false);
|
// for(size_t s=0 ; s < stream.size() ++i)
|
||||||
}
|
// out += stream[s];
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out)
|
//void UrlEncode(const std::wstring & in, std::string & out, bool clear_out)
|
||||||
{
|
//{
|
||||||
UrlEncode(in.c_str(), out, clear_out);
|
// UrlEncode(in.c_str(), out, clear_out);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out)
|
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out)
|
||||||
{
|
{
|
||||||
static std::string ain;
|
|
||||||
|
|
||||||
PT::WideToUTF8(in, ain);
|
|
||||||
|
|
||||||
if( clear_out )
|
if( clear_out )
|
||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
for(size_t i=0 ; i < ain.size() ; ++i)
|
pt::WTextStream stream;
|
||||||
UrlEncode(ain[i], out, false);
|
|
||||||
|
for(size_t i=0 ; in[i] != 0 ; ++i)
|
||||||
|
{
|
||||||
|
UrlEncode(in[i], stream, true);
|
||||||
|
|
||||||
|
for(size_t s=0 ; s < stream.size() ; ++s)
|
||||||
|
out += stream[s];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1293,6 +1412,27 @@ void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void UrlEncode(const pt::TextStream & in, pt::TextStream & out, bool clear_out)
|
||||||
|
{
|
||||||
|
if( clear_out )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
for(size_t i=0 ; i < in.size() ; ++i)
|
||||||
|
UrlEncode(in.get_char(i), out, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UrlEncode(const pt::WTextStream & in, pt::WTextStream & out, bool clear_out)
|
||||||
|
{
|
||||||
|
if( clear_out )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
for(size_t i=0 ; i < in.size() ; ++i)
|
||||||
|
UrlEncode(in.get_wchar(i), out, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool UrlDecodeFromHex(int c, int & out)
|
bool UrlDecodeFromHex(int c, int & out)
|
||||||
{
|
{
|
||||||
@@ -1347,7 +1487,7 @@ int c1, c2;
|
|||||||
|
|
||||||
url_utf8[index] = 0;
|
url_utf8[index] = 0;
|
||||||
|
|
||||||
return PT::UTF8ToWide(url_utf8, out, false);
|
return pt::utf8_to_wide(url_utf8, out, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1364,7 +1504,7 @@ using namespace misc_private;
|
|||||||
|
|
||||||
tmp_qencode.clear();
|
tmp_qencode.clear();
|
||||||
QEncode(in, tmp_qencode);
|
QEncode(in, tmp_qencode);
|
||||||
tmp_qencode.to_string(out, clear);
|
tmp_qencode.to_str(out, clear);
|
||||||
tmp_qencode.clear();
|
tmp_qencode.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1391,26 +1531,211 @@ void RemovePostFileTmp(PostFileTab & post_file_tab)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WideToUTF8(const wchar_t * wide_string, char * utf8, size_t utf8_size)
|
void JSONescapeStream(const pt::WTextStream & in, pt::WTextStream & out)
|
||||||
{
|
{
|
||||||
bool res = PT::WideToUTF8(wide_string, utf8, utf8_size);
|
pt::WTextStream::const_iterator i = in.begin();
|
||||||
|
|
||||||
if( !res )
|
for( ; i != in.end() ; ++i)
|
||||||
{
|
{
|
||||||
/*
|
JSONescape(*i, out);
|
||||||
* either the 'utf8' buffer is too small or there was an error when converting
|
|
||||||
*/
|
|
||||||
//log << log1 << "Misc: I cannot convert from a wide string to an UTF-8 string, original string was: "
|
|
||||||
// << wide_string << logend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WideToUTF8(const std::wstring & wide_string, char * utf8, size_t utf8_size)
|
void JSONescapeStream(const std::wstring & in, pt::WTextStream & out)
|
||||||
{
|
{
|
||||||
return WideToUTF8(wide_string.c_str(), utf8, utf8_size);
|
std::wstring::const_iterator i = in.begin();
|
||||||
|
|
||||||
|
for( ; i != in.end() ; ++i)
|
||||||
|
{
|
||||||
|
JSONescape(*i, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void calculate_timespec_diff(timespec & start, timespec & stop, timespec & result)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* copied from macro timespecsub(tsp, usp, vsp) which is defined in sys/time.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
result.tv_sec = stop.tv_sec - start.tv_sec;
|
||||||
|
result.tv_nsec = stop.tv_nsec - start.tv_nsec;
|
||||||
|
|
||||||
|
if( result.tv_nsec < 0 )
|
||||||
|
{
|
||||||
|
result.tv_sec--;
|
||||||
|
result.tv_nsec += 1000000000L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double timespec_to_double(timespec & val)
|
||||||
|
{
|
||||||
|
double val_double = val.tv_sec + val.tv_nsec / 1000000000.0;
|
||||||
|
return val_double;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void timespec_to_stream(timespec & val, pt::Stream & stream)
|
||||||
|
{
|
||||||
|
char buf[50];
|
||||||
|
|
||||||
|
double val_double = timespec_to_double(val);
|
||||||
|
sprintf(buf, "%f", val_double);
|
||||||
|
SetNonZeroDigitsAfterComma(buf, 2);
|
||||||
|
|
||||||
|
stream << buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void timespec_to_stream_with_unit(timespec & val, pt::Stream & stream)
|
||||||
|
{
|
||||||
|
char buf[50];
|
||||||
|
bool is_ms = false;
|
||||||
|
|
||||||
|
double val_double = timespec_to_double(val);
|
||||||
|
|
||||||
|
if( val_double < 0.1 )
|
||||||
|
{
|
||||||
|
is_ms = true;
|
||||||
|
val_double = val_double * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(buf, "%f", val_double);
|
||||||
|
SetNonZeroDigitsAfterComma(buf, 2);
|
||||||
|
|
||||||
|
stream << buf;
|
||||||
|
|
||||||
|
if( is_ms )
|
||||||
|
{
|
||||||
|
stream << "ms";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stream << "s";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void slice_by(const std::wstring & str, wchar_t c, std::vector<std::wstring> & out)
|
||||||
|
{
|
||||||
|
std::wstring tmp;
|
||||||
|
|
||||||
|
for(size_t i = 0 ; i < str.size() ; ++i)
|
||||||
|
{
|
||||||
|
if( str[i] == c )
|
||||||
|
{
|
||||||
|
if( !tmp.empty() )
|
||||||
|
{
|
||||||
|
out.push_back(tmp);
|
||||||
|
tmp.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp += str[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !tmp.empty() )
|
||||||
|
{
|
||||||
|
out.push_back(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool is_in_list(const std::wstring & item, const std::vector<std::wstring> & list)
|
||||||
|
{
|
||||||
|
return is_in_list_generic(item, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool is_in_list(const std::wstring & item, const std::list<std::wstring> & list)
|
||||||
|
{
|
||||||
|
return is_in_list_generic(item, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool is_in_list(const std::wstring & item, const std::set<std::wstring> & list)
|
||||||
|
{
|
||||||
|
return is_in_list_generic(item, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cookie_same_site_to_stream(CookieSameSite same_site, pt::Stream & stream)
|
||||||
|
{
|
||||||
|
switch(same_site)
|
||||||
|
{
|
||||||
|
case CookieSameSite::samesite_strict:
|
||||||
|
stream << L"Strict";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CookieSameSite::samesite_lax:
|
||||||
|
stream << L"Lax";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CookieSameSite::samesite_none:
|
||||||
|
stream << L"None";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void prepare_cookie_string(
|
||||||
|
pt::Stream & cookie,
|
||||||
|
const std::wstring * value_string,
|
||||||
|
const pt::Stream * value_stream,
|
||||||
|
pt::Date * expires,
|
||||||
|
const std::wstring * path,
|
||||||
|
const std::wstring * domain,
|
||||||
|
CookieSameSite cookie_same_site,
|
||||||
|
bool http_only,
|
||||||
|
bool secure)
|
||||||
|
{
|
||||||
|
if( value_string )
|
||||||
|
cookie << *value_string;
|
||||||
|
|
||||||
|
if( value_stream )
|
||||||
|
cookie << *value_stream;
|
||||||
|
|
||||||
|
if( cookie.empty() )
|
||||||
|
cookie << L"\"\""; // cookie empty value
|
||||||
|
|
||||||
|
if( expires )
|
||||||
|
cookie << L"; expires=" << DateToStrCookie(*expires) << L" GMT";
|
||||||
|
|
||||||
|
if( path && !path->empty() )
|
||||||
|
{
|
||||||
|
cookie << L"; path=" << *path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( domain && !domain->empty() )
|
||||||
|
cookie << L"; domain=" << *domain;
|
||||||
|
|
||||||
|
if( cookie_same_site != CookieSameSite::samesite_notset )
|
||||||
|
{
|
||||||
|
cookie << L"; SameSite=";
|
||||||
|
cookie_same_site_to_stream(cookie_same_site, cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( http_only )
|
||||||
|
cookie << L"; HttpOnly";
|
||||||
|
|
||||||
|
/*
|
||||||
|
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)
|
||||||
|
*/
|
||||||
|
if( secure )
|
||||||
|
cookie << L"; Secure";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+179
-79
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -36,10 +36,11 @@
|
|||||||
#define headerfile_winix_core_misc
|
#define headerfile_winix_core_misc
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "item.h"
|
|
||||||
#include "requesttypes.h"
|
#include "requesttypes.h"
|
||||||
#include "date/date.h"
|
#include "date/date.h"
|
||||||
#include "textstream/textstream.h"
|
#include "textstream/textstream.h"
|
||||||
@@ -78,6 +79,7 @@ double Tod(const wchar_t * str);
|
|||||||
|
|
||||||
// if the buffer is too small it will be terminated at the beginning (empty string)
|
// if the buffer is too small it will be terminated at the beginning (empty string)
|
||||||
// and the function returns false
|
// and the function returns false
|
||||||
|
// IMPROVEME now we can use Toa from Pikotools
|
||||||
template<class CharType>
|
template<class CharType>
|
||||||
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10)
|
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10)
|
||||||
{
|
{
|
||||||
@@ -238,13 +240,13 @@ void CorrectUrlOnlyAllowedChar(std::wstring & url);
|
|||||||
|
|
||||||
const wchar_t * DateToStr(int year, int month, int day);
|
const wchar_t * DateToStr(int year, int month, int day);
|
||||||
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec);
|
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec);
|
||||||
const wchar_t * DateToStr(const PT::Date & d);
|
const wchar_t * DateToStr(const pt::Date & d);
|
||||||
const wchar_t * DateToStr(time_t t);
|
const wchar_t * DateToStr(time_t t);
|
||||||
const wchar_t * DateToStrWithoutHours(const PT::Date & d);
|
const wchar_t * DateToStrWithoutHours(const pt::Date & d);
|
||||||
const wchar_t * DateToStrWithoutHours(time_t t);
|
const wchar_t * DateToStrWithoutHours(time_t t);
|
||||||
|
|
||||||
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
|
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
|
||||||
const char * DateToStrCookie(const PT::Date & d);
|
const char * DateToStrCookie(const pt::Date & d);
|
||||||
const char * DateToStrCookie(time_t t);
|
const char * DateToStrCookie(time_t t);
|
||||||
|
|
||||||
// depracated
|
// depracated
|
||||||
@@ -253,8 +255,8 @@ const wchar_t * IpToStr(unsigned int ip_);
|
|||||||
|
|
||||||
// in a new code we can use WTextStream in such a way
|
// in a new code we can use WTextStream in such a way
|
||||||
// DateToStr() etc can use it too
|
// DateToStr() etc can use it too
|
||||||
PT::WTextStream IPToStr(unsigned int ip);
|
pt::WTextStream IPToStr(unsigned int ip);
|
||||||
PT::WTextStream IPToStr(int ip);
|
pt::WTextStream IPToStr(int ip);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -420,7 +422,7 @@ size_t i = 0;
|
|||||||
|
|
||||||
while( i < buf.size() )
|
while( i < buf.size() )
|
||||||
{
|
{
|
||||||
if( PT::IsSubString(look_for.c_str(), buf.c_str() + i) )
|
if( pt::is_substr(look_for.c_str(), buf.c_str() + i) )
|
||||||
{
|
{
|
||||||
buf.erase(i, look_for.size());
|
buf.erase(i, look_for.size());
|
||||||
buf.insert(i, replace);
|
buf.insert(i, replace);
|
||||||
@@ -662,8 +664,19 @@ bool RenameFile(const std::wstring & from, const std::wstring & to);
|
|||||||
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content = true);
|
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content = true);
|
||||||
bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content = true);
|
bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content = true);
|
||||||
|
|
||||||
|
bool GetUTF8File(const wchar_t * file_path, pt::WTextStream & content, bool clear_content = true);
|
||||||
|
bool GetUTF8File(const std::wstring & file_path, pt::WTextStream & content, bool clear_content = true);
|
||||||
|
|
||||||
|
|
||||||
|
bool GetBinaryFile(const wchar_t * file_path, BinaryPage & content, bool clear_content = true);
|
||||||
|
bool GetBinaryFile(const std::wstring & file_path, BinaryPage & content, bool clear_content = true);
|
||||||
|
|
||||||
const wchar_t * GetFileExt(const wchar_t * name);
|
const wchar_t * GetFileExt(const wchar_t * name);
|
||||||
|
|
||||||
|
void PrepareNewFileName(const wchar_t * src, const wchar_t * postfix, std::wstring & res, bool clear_res = true);
|
||||||
|
void PrepareNewFileName(const std::wstring & src, const std::wstring & postfix, std::wstring & res, bool clear_res = true);
|
||||||
|
|
||||||
|
|
||||||
int SelectFileType(const wchar_t * file_name);
|
int SelectFileType(const wchar_t * file_name);
|
||||||
int SelectFileType(const std::wstring & file_name);
|
int SelectFileType(const std::wstring & file_name);
|
||||||
|
|
||||||
@@ -673,14 +686,11 @@ int SelectFileType(const std::wstring & file_name);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// thread safe
|
template<typename StreamType>
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
void UrlEncode(char c, StreamType & out, bool clear_out = true)
|
||||||
void UrlEncode(char c,
|
|
||||||
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
|
||||||
bool clear_out = true)
|
|
||||||
{
|
{
|
||||||
char buffer[10];
|
char buffer[10];
|
||||||
size_t buflen = sizeof(buffer)/sizeof(char);
|
size_t buflen = sizeof(buffer)/sizeof(char);
|
||||||
|
|
||||||
if( clear_out )
|
if( clear_out )
|
||||||
out.clear();
|
out.clear();
|
||||||
@@ -705,11 +715,33 @@ size_t buflen = sizeof(buffer)/sizeof(char);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// thread safe
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename StreamType>
|
||||||
void UrlEncode(const char * in,
|
void UrlEncode(wchar_t c, StreamType & out, bool clear_out = true)
|
||||||
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
{
|
||||||
bool clear_out = true)
|
char buffer[10];
|
||||||
|
size_t buflen = sizeof(buffer)/sizeof(char);
|
||||||
|
|
||||||
|
if( clear_out )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
// this conversion is not using surrogate pairs if wchar_t is 2 bytes long
|
||||||
|
size_t utf8_len = pt::int_to_utf8(static_cast<int>(c), buffer, buflen);
|
||||||
|
|
||||||
|
if( utf8_len > 0 )
|
||||||
|
{
|
||||||
|
for(size_t i=0 ; i < utf8_len ; ++i)
|
||||||
|
{
|
||||||
|
UrlEncode(buffer[i], out, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename StreamType>
|
||||||
|
void UrlEncode(const char * in, StreamType & out, bool clear_out = true)
|
||||||
{
|
{
|
||||||
if( clear_out )
|
if( clear_out )
|
||||||
out.clear();
|
out.clear();
|
||||||
@@ -719,67 +751,44 @@ void UrlEncode(const char * in,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// thread safe
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename StreamType>
|
||||||
void UrlEncode(const std::string & in,
|
void UrlEncode(const std::string & in, StreamType & out, bool clear_out = true)
|
||||||
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
|
||||||
bool clear_out = true)
|
|
||||||
{
|
{
|
||||||
UrlEncode(in.c_str(), out, clear_out);
|
UrlEncode(in.c_str(), out, clear_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// not thread safe
|
template<typename StreamType>
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
void UrlEncode(const wchar_t * in, StreamType & out, bool clear_out = true)
|
||||||
void UrlEncode(const wchar_t * in,
|
|
||||||
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
|
||||||
bool clear_out = true)
|
|
||||||
{
|
{
|
||||||
static std::string ain;
|
|
||||||
|
|
||||||
PT::WideToUTF8(in, ain);
|
|
||||||
|
|
||||||
if( clear_out )
|
if( clear_out )
|
||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
for(size_t i=0 ; i < ain.size() ; ++i)
|
for(size_t i=0 ; in[i] != 0 ; ++i)
|
||||||
UrlEncode(ain[i], out, false);
|
UrlEncode(in[i], out, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// not thread safe
|
template<typename StreamType>
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
void UrlEncode(const std::wstring & in, StreamType & out, bool clear_out = true)
|
||||||
void UrlEncode(const std::wstring & in,
|
|
||||||
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
|
||||||
bool clear_out = true)
|
|
||||||
{
|
{
|
||||||
UrlEncode(in.c_str(), out, clear_out);
|
UrlEncode(in.c_str(), out, clear_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// no thread safe
|
|
||||||
template<class StringType>
|
|
||||||
void UrlEncode(char c, StringType & out, bool clear_out = true)
|
|
||||||
{
|
|
||||||
static PT::TextStream tmp;
|
|
||||||
|
|
||||||
UrlEncode(c, tmp);
|
|
||||||
tmp.to_string(out, clear_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// !! IMROVE ME we need some UrlEncode methods with PT::TextBuffer instead of std::string
|
|
||||||
|
|
||||||
|
|
||||||
void UrlEncode(const char * in, std::string & out, bool clear_out = true);
|
void UrlEncode(const char * in, std::string & out, bool clear_out = true);
|
||||||
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
|
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
|
||||||
void UrlEncode(const wchar_t * in, std::string & out, bool clear_out = true);
|
//void UrlEncode(const wchar_t * in, std::string & out, bool clear_out = true);
|
||||||
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
|
//void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
|
||||||
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out = true);
|
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out = true);
|
||||||
void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out = true);
|
void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out = true);
|
||||||
|
|
||||||
|
void UrlEncode(const pt::TextStream & in, pt::TextStream & out, bool clear_out = true);
|
||||||
|
void UrlEncode(const pt::WTextStream & in, pt::WTextStream & out, bool clear_out = true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -797,7 +806,7 @@ bool UrlDecode(const std::string & url, std::wstring & out, bool clear_out = tr
|
|||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
void QEncodeAddChar(char_type c, PT::TextStreamBase<char_type, stack_size, heap_block_size> & out)
|
void QEncodeAddChar(char_type c, pt::TextStreamBase<char_type, stack_size, heap_block_size> & out)
|
||||||
{
|
{
|
||||||
if( (c>='A' && c<='Z') ||
|
if( (c>='A' && c<='Z') ||
|
||||||
(c>='a' && c<='z') ||
|
(c>='a' && c<='z') ||
|
||||||
@@ -812,7 +821,7 @@ void QEncodeAddChar(char_type c, PT::TextStreamBase<char_type, stack_size, heap_
|
|||||||
|
|
||||||
size_t len1 = sizeof(buf1) / sizeof(char);
|
size_t len1 = sizeof(buf1) / sizeof(char);
|
||||||
size_t len2 = sizeof(buf2) / sizeof(char);
|
size_t len2 = sizeof(buf2) / sizeof(char);
|
||||||
size_t len = PT::IntToUTF8(int(c), buf1, len1);
|
size_t len = pt::int_to_utf8(int(c), buf1, len1);
|
||||||
|
|
||||||
for(size_t i=0 ; i<len ; ++i)
|
for(size_t i=0 ; i<len ; ++i)
|
||||||
{
|
{
|
||||||
@@ -845,7 +854,7 @@ void QEncodeAddChar(char_type c, PT::TextStreamBase<char_type, stack_size, heap_
|
|||||||
charset, encoding, encoded-text, and delimiters."
|
charset, encoding, encoded-text, and delimiters."
|
||||||
*/
|
*/
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
void QEncode(const wchar_t * in, PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
void QEncode(const wchar_t * in, pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
bool clear = true)
|
bool clear = true)
|
||||||
{
|
{
|
||||||
if( clear )
|
if( clear )
|
||||||
@@ -861,7 +870,7 @@ void QEncode(const wchar_t * in, PT::TextStreamBase<char_type, stack_size, heap_
|
|||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
void QEncode(const std::wstring & in, PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
void QEncode(const std::wstring & in, pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
bool clear = true)
|
bool clear = true)
|
||||||
{
|
{
|
||||||
if( clear )
|
if( clear )
|
||||||
@@ -877,6 +886,7 @@ void QEncode(const std::wstring & in, PT::TextStreamBase<char_type, stack_size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// no thread safe
|
||||||
void QEncode(const std::wstring & in, std::string & out, bool clear = true);
|
void QEncode(const std::wstring & in, std::string & out, bool clear = true);
|
||||||
|
|
||||||
|
|
||||||
@@ -944,20 +954,11 @@ void SetMinMax(IntType & val, IntType min_val, IntType max_val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Stream>
|
||||||
|
void JSONescape(wchar_t c, Stream & out)
|
||||||
|
|
||||||
template<class Stream, class StringType>
|
|
||||||
void JSONescape(Stream & out, const StringType & str)
|
|
||||||
{
|
{
|
||||||
// !! IMPROVE ME (optimizing)
|
switch( c )
|
||||||
// it is better to not write one by one character
|
|
||||||
// but use write method insted
|
|
||||||
|
|
||||||
for(size_t i=0 ; i<str.size() ; ++i)
|
|
||||||
{
|
{
|
||||||
switch(str[i])
|
|
||||||
{
|
|
||||||
case 0: out << '\\'; out << '0'; break;
|
case 0: out << '\\'; out << '0'; break;
|
||||||
case '\r': out << '\\'; out << 'r'; break;
|
case '\r': out << '\\'; out << 'r'; break;
|
||||||
case '\n': out << '\\'; out << 'n'; break;
|
case '\n': out << '\\'; out << 'n'; break;
|
||||||
@@ -968,21 +969,120 @@ void JSONescape(Stream & out, const StringType & str)
|
|||||||
//case '/': out << '\\'; out << '/'; break; // slash doesn't have to be escaped
|
//case '/': out << '\\'; out << '/'; break; // slash doesn't have to be escaped
|
||||||
case '"': out << '\\'; out << '\"'; break;
|
case '"': out << '\\'; out << '\"'; break;
|
||||||
default:
|
default:
|
||||||
out << str[i];
|
out << c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType, class Stream>
|
||||||
|
void JSONescape(const StringType & str, Stream & out)
|
||||||
|
{
|
||||||
|
for(size_t i=0 ; i < str.size() ; ++i)
|
||||||
|
{
|
||||||
|
if constexpr(sizeof(char) == sizeof(typename StringType::value_type))
|
||||||
|
{
|
||||||
|
JSONescape(static_cast<wchar_t>(static_cast<unsigned char>(str[i])), out);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JSONescape(str[i], out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JSONescapeStream(const pt::WTextStream & in, pt::WTextStream & out);
|
||||||
|
void JSONescapeStream(const std::wstring & in, pt::WTextStream & out);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* converting from a wide string to an UTF-8 string
|
* calculate diff between start and stop timespec
|
||||||
* and puts a log if the conversion fails
|
*
|
||||||
|
* if start is greater than stop then the result is negative:
|
||||||
|
* - result.tv_sec is less than zero
|
||||||
|
* - result.tv_nsec is greater than or equal to zero (only if start.tv_nsec and stop.tv_nsec are correct values from zero to 1000000000L)
|
||||||
|
*
|
||||||
|
* 'double' value can be calculated in this way:
|
||||||
|
* double res = result.tv_sec + result.tv_nsec / 1000000000.0;
|
||||||
*
|
*
|
||||||
* it uses PT::WideToUTF8()
|
|
||||||
*/
|
*/
|
||||||
bool WideToUTF8(const wchar_t * wide_string, char * utf8, size_t utf8_size);
|
void calculate_timespec_diff(timespec & start, timespec & stop, timespec & result);
|
||||||
bool WideToUTF8(const std::wstring & wide_string, char * utf8, size_t utf8_size);
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* converts timespec to double in the following way:
|
||||||
|
* double val_double = val.tv_sec + val.tv_nsec / 1000000000.0;
|
||||||
|
*
|
||||||
|
* val.tv_sec can be negative (less than zero) but tv_nsec should be in the range [0, 1000000000.0)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
double timespec_to_double(timespec & val);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void timespec_to_stream(timespec & val, pt::Stream & stream);
|
||||||
|
void timespec_to_stream_with_unit(timespec & val, pt::Stream & stream);
|
||||||
|
|
||||||
|
|
||||||
|
void slice_by(const std::wstring & str, wchar_t c, std::vector<std::wstring> & out);
|
||||||
|
|
||||||
|
|
||||||
|
bool is_in_list(const std::wstring & item, const std::vector<std::wstring> & list);
|
||||||
|
bool is_in_list(const std::wstring & item, const std::list<std::wstring> & list);
|
||||||
|
bool is_in_list(const std::wstring & item, const std::set<std::wstring> & list);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename ContainerType>
|
||||||
|
bool is_in_list_generic(const std::wstring & item, const ContainerType & list)
|
||||||
|
{
|
||||||
|
for(const std::wstring & str : list)
|
||||||
|
{
|
||||||
|
if( str == item )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cookie_same_site_to_stream(CookieSameSite same_site, pt::Stream & stream);
|
||||||
|
|
||||||
|
|
||||||
|
void prepare_cookie_string(
|
||||||
|
pt::Stream & out_stream,
|
||||||
|
const std::wstring * value_string = nullptr,
|
||||||
|
const pt::Stream * value_stream = nullptr,
|
||||||
|
pt::Date * expires = nullptr,
|
||||||
|
const std::wstring * path = nullptr,
|
||||||
|
const std::wstring * domain = nullptr,
|
||||||
|
CookieSameSite cookie_same_site = CookieSameSite::samesite_notset,
|
||||||
|
bool http_only = false,
|
||||||
|
bool secure = false);
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
void q_encode(
|
||||||
|
const pt::TextStreamBase<char_type, stack_size, heap_block_size> & in,
|
||||||
|
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
|
||||||
|
bool clear = true)
|
||||||
|
{
|
||||||
|
if( clear )
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
out << "=?UTF-8?Q?";
|
||||||
|
|
||||||
|
// do not use QEncode(in.c_str()) as 'in' can have a null-terminating byte
|
||||||
|
typename pt::TextStreamBase<char_type, stack_size, heap_block_size>::const_iterator i = in.begin();
|
||||||
|
|
||||||
|
for( ; i != in.end() ; ++i)
|
||||||
|
QEncodeAddChar(*i, out);
|
||||||
|
|
||||||
|
out << "?=";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-2
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2014, Tomasz Sowa
|
* Copyright (c) 2009-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -43,14 +43,38 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
Mount::Mount()
|
Mount::Mount()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Mount::Mount(const Mount & m)
|
||||||
|
{
|
||||||
|
operator=(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Mount & Mount::operator=(const Mount & m)
|
||||||
|
{
|
||||||
|
dir_id = m.dir_id;
|
||||||
|
type = m.type;
|
||||||
|
fs = m.fs;
|
||||||
|
param = m.param;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Mount::Clear()
|
||||||
{
|
{
|
||||||
dir_id = -1;
|
dir_id = -1;
|
||||||
type = -1;
|
type = -1;
|
||||||
fs = -1;
|
fs = -1;
|
||||||
|
ClearParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Mount::ClearParams()
|
void Mount::ClearParams()
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|||||||
+5
-1
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2014, Tomasz Sowa
|
* Copyright (c) 2009-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -73,6 +73,10 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
Mount();
|
Mount();
|
||||||
|
Mount(const Mount & m);
|
||||||
|
Mount & operator=(const Mount & m);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
void ClearParams();
|
void ClearParams();
|
||||||
|
|
||||||
bool IsPar(int code);
|
bool IsPar(int code);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "mountparser.h"
|
#include "mountparser.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "dirs.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
* Copyright (c) 2010-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -40,20 +40,19 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
#include "item.h"
|
#include "models/item.h"
|
||||||
#include "dirs.h"
|
#include "winixmodeldeprecated.h"
|
||||||
#include "winixmodel.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
{
|
{
|
||||||
|
class Dirs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MountParser : public WinixModel
|
class MountParser : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
+26
-35
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2018, Tomasz Sowa
|
* Copyright (c) 2009-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -35,8 +35,7 @@
|
|||||||
#include "mounts.h"
|
#include "mounts.h"
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "db/db.h"
|
#include "dirs.h"
|
||||||
#include "cur.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -49,6 +48,7 @@ Mounts::Mounts()
|
|||||||
{
|
{
|
||||||
pmount = &empty_mount;
|
pmount = &empty_mount;
|
||||||
skip_static = false;
|
skip_static = false;
|
||||||
|
dirs = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ void Mounts::CreateMounts()
|
|||||||
CreateMountFs();
|
CreateMountFs();
|
||||||
CreateMountPar();
|
CreateMountPar();
|
||||||
|
|
||||||
plugin->Call((Session*)0, WINIX_ADD_MOUNTS);
|
plugin->Call(WINIX_ADD_MOUNTS);
|
||||||
|
|
||||||
empty_mount.param.resize(mount_par_tab.size());
|
empty_mount.param.resize(mount_par_tab.size());
|
||||||
empty_mount.ClearParams();
|
empty_mount.ClearParams();
|
||||||
@@ -113,18 +113,6 @@ void Mounts::SetDirs(Dirs * pdirs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Mounts::SetDb(Db * pdb)
|
|
||||||
{
|
|
||||||
db = pdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mounts::SetCur(Cur * pcur)
|
|
||||||
{
|
|
||||||
cur = pcur;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Mounts::AddMountType(const wchar_t * type)
|
int Mounts::AddMountType(const wchar_t * type)
|
||||||
{
|
{
|
||||||
mount_type_tab.push_back(type);
|
mount_type_tab.push_back(type);
|
||||||
@@ -221,14 +209,17 @@ void Mounts::ReadMounts(const std::wstring & mounts)
|
|||||||
|
|
||||||
mount_parser.Parse(mounts, mount_tab);
|
mount_parser.Parse(mounts, mount_tab);
|
||||||
|
|
||||||
CalcCurMount();
|
// IMPROVE ME
|
||||||
plugin->Call((Session*)0, WINIX_FSTAB_CHANGED);
|
// cur->mount is pointing to the empty mount (it is set in functions.cpp in CheckSpecialFile method)
|
||||||
|
// may would be better to call WINIX_FSTAB_CHANGED after the cur->mount is set?
|
||||||
|
// some plugins are using 'cur' object
|
||||||
|
plugin->Call(WINIX_FSTAB_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// reading from /etc/fstab
|
// reading from /etc/fstab
|
||||||
Error Mounts::ReadMounts()
|
void Mounts::ReadMounts()
|
||||||
{
|
{
|
||||||
static std::wstring file = L"fstab";
|
static std::wstring file = L"fstab";
|
||||||
|
|
||||||
@@ -237,27 +228,27 @@ Error Mounts::ReadMounts()
|
|||||||
if( !etc )
|
if( !etc )
|
||||||
{
|
{
|
||||||
log << log1 << "M: there is no /etc directory" << logend;
|
log << log1 << "M: there is no /etc directory" << logend;
|
||||||
return WINIX_ERR_NO_ITEM;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item fstab;
|
morm::Finder<Item> finder(model_connector);
|
||||||
Error err = db->GetItem(etc->id, file, fstab);
|
Item fstab = finder.select().where().eq(L"parent_id", etc->id).eq(L"url", file).get();
|
||||||
|
|
||||||
if( err == WINIX_ERR_NO_ITEM )
|
// Error err = db->GetItem(etc->id, file, fstab);
|
||||||
|
|
||||||
|
if( !fstab.found() )
|
||||||
{
|
{
|
||||||
log << log1 << "M: there is no /etc/fstab file" << logend;
|
log << log1 << "M: there is no /etc/fstab file" << logend;
|
||||||
return err;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( err != WINIX_ERR_OK )
|
// if( err != WINIX_ERR_OK )
|
||||||
{
|
// {
|
||||||
log << log1 << "M: cannot read /etc/fstab" << logend;
|
// log << log1 << "M: cannot read /etc/fstab" << logend;
|
||||||
return err;
|
// return err;
|
||||||
}
|
// }
|
||||||
|
|
||||||
ReadMounts(fstab.content);
|
ReadMounts(fstab.item_content.content_raw);
|
||||||
|
|
||||||
return WINIX_ERR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -287,7 +278,7 @@ void Mounts::MountCmsForRoot()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Mount * Mounts::CalcCurMount()
|
Mount * Mounts::CalcCurMount(Request * request)
|
||||||
{
|
{
|
||||||
std::vector<Item*>::reverse_iterator i;
|
std::vector<Item*>::reverse_iterator i;
|
||||||
|
|
||||||
@@ -295,10 +286,10 @@ std::vector<Item*>::reverse_iterator i;
|
|||||||
|
|
||||||
// when the program starts (when the dir_tab is empty()
|
// when the program starts (when the dir_tab is empty()
|
||||||
// we don't want to call MountCmsForRoot()
|
// we don't want to call MountCmsForRoot()
|
||||||
if( cur->request->dir_tab.empty() )
|
if( request->dir_tab.empty() )
|
||||||
return pmount;
|
return pmount;
|
||||||
|
|
||||||
for(i = cur->request->dir_tab.rbegin() ; i!=cur->request->dir_tab.rend() ; ++i)
|
for(i = request->dir_tab.rbegin() ; i!=request->dir_tab.rend() ; ++i)
|
||||||
{
|
{
|
||||||
std::map<long, Mount>::iterator m = mount_tab.find( (*i)->id );
|
std::map<long, Mount>::iterator m = mount_tab.find( (*i)->id );
|
||||||
|
|
||||||
|
|||||||
+7
-15
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2018, Tomasz Sowa
|
* Copyright (c) 2009-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -41,21 +41,17 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
#include "error.h"
|
|
||||||
#include "dirs.h"
|
|
||||||
#include "db/db.h"
|
|
||||||
#include "request.h"
|
|
||||||
#include "mountparser.h"
|
#include "mountparser.h"
|
||||||
#include "winixmodel.h"
|
#include "winixmodeldeprecated.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
{
|
{
|
||||||
|
class Dirs;
|
||||||
|
class Request;
|
||||||
|
|
||||||
|
|
||||||
|
class Mounts : public WinixModelDeprecated
|
||||||
|
|
||||||
class Mounts : public WinixModel
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -114,8 +110,6 @@ public:
|
|||||||
int MountParLang() { return mount_par_lang; }
|
int MountParLang() { return mount_par_lang; }
|
||||||
|
|
||||||
void SetDirs(Dirs * pdirs);
|
void SetDirs(Dirs * pdirs);
|
||||||
void SetDb(Db * pdb);
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
|
|
||||||
// dir_id, mount_point
|
// dir_id, mount_point
|
||||||
typedef std::map<long, Mount> MountTab;
|
typedef std::map<long, Mount> MountTab;
|
||||||
@@ -124,9 +118,9 @@ public:
|
|||||||
void CreateMounts();
|
void CreateMounts();
|
||||||
|
|
||||||
void ReadMounts(const std::wstring & mounts);
|
void ReadMounts(const std::wstring & mounts);
|
||||||
Error ReadMounts();
|
void ReadMounts();
|
||||||
|
|
||||||
Mount * CalcCurMount();
|
Mount * CalcCurMount(Request * request);
|
||||||
Mount * CalcMount(long dir_id);
|
Mount * CalcMount(long dir_id);
|
||||||
|
|
||||||
// current mount point
|
// current mount point
|
||||||
@@ -144,9 +138,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Db * db;
|
|
||||||
Dirs * dirs;
|
Dirs * dirs;
|
||||||
Cur * cur;
|
|
||||||
|
|
||||||
bool skip_static;
|
bool skip_static;
|
||||||
|
|
||||||
|
|||||||
+77
-175
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -48,44 +48,6 @@ namespace Winix
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* PluginInfo
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void PluginInfo::set_dependency_for(WinixBase * winix_base)
|
|
||||||
{
|
|
||||||
plugin->SetDependencyFor(winix_base);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginInfo::set_dependency_for(WinixBase & winix_base)
|
|
||||||
{
|
|
||||||
set_dependency_for(&winix_base);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginInfo::set_dependency_for(WinixModel * winix_model)
|
|
||||||
{
|
|
||||||
plugin->SetDependencyFor(winix_model);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginInfo::set_dependency_for(WinixModel & winix_model)
|
|
||||||
{
|
|
||||||
set_dependency_for(&winix_model);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Plugin
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::UnloadPlugins()
|
void Plugin::UnloadPlugins()
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@@ -103,13 +65,14 @@ Plugin::Plugin()
|
|||||||
{
|
{
|
||||||
current_plugin = -1;
|
current_plugin = -1;
|
||||||
|
|
||||||
db = nullptr;
|
|
||||||
cur = nullptr;
|
cur = nullptr;
|
||||||
system = nullptr;
|
system = nullptr;
|
||||||
functions = nullptr;
|
functions = nullptr;
|
||||||
templates = nullptr;
|
templates = nullptr;
|
||||||
session_manager = nullptr;
|
session_manager = nullptr;
|
||||||
winix_request = nullptr;
|
winix_request = nullptr;
|
||||||
|
|
||||||
|
plugin = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -119,29 +82,18 @@ Plugin::~Plugin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::SetDb(Db * pdb)
|
|
||||||
{
|
|
||||||
db = pdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
//void Plugin::SetConfig(Config * pconfig)
|
|
||||||
//{
|
|
||||||
// config = pconfig;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::SetCur(Cur * pcur)
|
|
||||||
{
|
|
||||||
cur = pcur;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::SetSystem(System * psystem)
|
void Plugin::SetSystem(System * psystem)
|
||||||
{
|
{
|
||||||
system = psystem;
|
system = psystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::SetCur(Cur * cur)
|
||||||
|
{
|
||||||
|
this->cur = cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::SetFunctions(Functions * pfunctions)
|
void Plugin::SetFunctions(Functions * pfunctions)
|
||||||
{
|
{
|
||||||
functions = pfunctions;
|
functions = pfunctions;
|
||||||
@@ -154,12 +106,6 @@ void Plugin::SetTemplates(Templates * ptemplates)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//void Plugin::SetSynchro(Synchro * psynchro)
|
|
||||||
//{
|
|
||||||
// synchro = psynchro;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::SetSessionManager(SessionManager * psession_manager)
|
void Plugin::SetSessionManager(SessionManager * psession_manager)
|
||||||
{
|
{
|
||||||
session_manager = psession_manager;
|
session_manager = psession_manager;
|
||||||
@@ -189,45 +135,33 @@ void Plugin::Unlock()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Plugin::SetDependency(PluginInfo & info)
|
bool Plugin::SetDependencyForPluginInfo(morm::ModelConnector * pmodel_connector, Log * plog, Cur * pcur, PluginInfo & info)
|
||||||
{
|
{
|
||||||
// for safety we call a plugin function only when all our pointers are not null
|
// for safety we call a plugin function only when all our pointers are not null
|
||||||
bool res = (db && config && cur && system && functions && templates && synchro && session_manager && winix_request);
|
bool res = (pmodel_connector && plog && pcur && config && system && functions && templates && synchro && session_manager && winix_request);
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
{
|
{
|
||||||
Lock();
|
|
||||||
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
|
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info.db = db;
|
|
||||||
info.config = config;
|
info.config = config;
|
||||||
info.cur = cur;
|
info.cur = pcur;
|
||||||
info.system = system;
|
info.system = system;
|
||||||
info.functions = functions;
|
info.functions = functions;
|
||||||
info.templates = templates;
|
info.templates = templates;
|
||||||
info.synchro = synchro;
|
info.synchro = synchro;
|
||||||
info.session_manager = session_manager;
|
info.session_manager = session_manager;
|
||||||
info.plugin = this;
|
info.plugin = this;
|
||||||
|
info.model_connector = pmodel_connector;;
|
||||||
|
|
||||||
info.log.SetDependency(&log);
|
info.log.set_log_buffer(plog->get_log_buffer());
|
||||||
|
info.log.set_file_log(plog->get_file_log());
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::SetDependencyFor(WinixBase * winix_base)
|
|
||||||
{
|
|
||||||
winix_base->set_dependency(winix_request);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::SetDependencyFor(WinixModel * winix_model)
|
|
||||||
{
|
|
||||||
winix_model->set_dependency(winix_request);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector<std::wstring> & plugins)
|
void Plugin::LoadPlugins(const std::wstring & plugins_dir, const std::vector<std::wstring> & plugins)
|
||||||
{
|
{
|
||||||
@@ -256,8 +190,8 @@ void * Plugin::LoadInitFun(const wchar_t * filename, Fun1 & fun_init)
|
|||||||
{
|
{
|
||||||
char file[WINIX_OS_PATH_SIZE];
|
char file[WINIX_OS_PATH_SIZE];
|
||||||
|
|
||||||
if( !WideToUTF8(filename, file, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(filename, (char*)file, WINIX_OS_PATH_SIZE) )
|
||||||
return 0;
|
return nullptr;
|
||||||
|
|
||||||
void * p = dlopen(file, RTLD_NOW | RTLD_LOCAL);
|
void * p = dlopen(file, RTLD_NOW | RTLD_LOCAL);
|
||||||
|
|
||||||
@@ -265,7 +199,7 @@ char file[WINIX_OS_PATH_SIZE];
|
|||||||
{
|
{
|
||||||
log << log1 << "Plugin: cannot load a plugin: \"" << filename << "\"" << logend;
|
log << log1 << "Plugin: cannot load a plugin: \"" << filename << "\"" << logend;
|
||||||
log << log1 << "Plugin: dlerror: " << dlerror() << logend;
|
log << log1 << "Plugin: dlerror: " << dlerror() << logend;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun_init = (Fun1)dlsym(p, "Init");
|
fun_init = (Fun1)dlsym(p, "Init");
|
||||||
@@ -276,14 +210,14 @@ char file[WINIX_OS_PATH_SIZE];
|
|||||||
<< " (there is no Init() function)" << logend;
|
<< " (there is no Init() function)" << logend;
|
||||||
|
|
||||||
dlclose(p);
|
dlclose(p);
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
log << log2 << "Plugin: plugin loaded"
|
log << log2 << "Plugin: plugin loaded"
|
||||||
<< ", file: " << filename
|
<< ", file: " << filename
|
||||||
<< ", index: " << plugins.size() << logend;
|
<< ", index: " << plugins.size() << logend;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -295,7 +229,7 @@ void * plugin_handle;
|
|||||||
int old_current_plugin;
|
int old_current_plugin;
|
||||||
PluginInfo info;
|
PluginInfo info;
|
||||||
|
|
||||||
if( !SetDependency(info) )
|
if( !SetDependencyForPluginInfo(model_connector, &log, cur, info) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( !(plugin_handle = LoadInitFun(filename, fun_init)) )
|
if( !(plugin_handle = LoadInitFun(filename, fun_init)) )
|
||||||
@@ -306,6 +240,10 @@ PluginInfo info;
|
|||||||
current_plugin = (int)plugins.size();
|
current_plugin = (int)plugins.size();
|
||||||
info.plugin_id = current_plugin;
|
info.plugin_id = current_plugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING:
|
||||||
|
* all pointers from Cur are null pointers here
|
||||||
|
*/
|
||||||
fun_init(info);
|
fun_init(info);
|
||||||
|
|
||||||
PluginsItem item;
|
PluginsItem item;
|
||||||
@@ -353,27 +291,24 @@ bool Plugin::HasMessage(int message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info)
|
void Plugin::Call(morm::ModelConnector * model_connector, Log * plog, Cur * cur, int message, Slots::iterator & slot, PluginInfo & info)
|
||||||
{
|
{
|
||||||
if( !SetDependency(info) )
|
if( !SetDependencyForPluginInfo(model_connector, plog, cur, info) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
current_plugin = slot->second.index;
|
current_plugin = slot->second.index;
|
||||||
info.plugin_id = current_plugin;
|
info.plugin_id = current_plugin;
|
||||||
info.session = ses;
|
|
||||||
|
|
||||||
if( current_plugin != -1 && ses )
|
if( current_plugin != -1 && cur->session && !cur->session->is_temporary_session() )
|
||||||
info.plugin_data_base = ses->plugin_data.Get(current_plugin);
|
info.plugin_data_base = cur->session->plugin_data.Get(current_plugin);
|
||||||
else
|
else
|
||||||
info.plugin_data_base = 0;
|
info.plugin_data_base = nullptr;
|
||||||
|
|
||||||
if( !slot->second.is_running )
|
if( !slot->second.is_running )
|
||||||
{
|
{
|
||||||
if( config->log_plugin_call )
|
if( config->log_plugin_call )
|
||||||
{
|
{
|
||||||
Lock();
|
|
||||||
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
|
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
slot->second.is_running = true;
|
slot->second.is_running = true;
|
||||||
@@ -388,156 +323,123 @@ void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo
|
|||||||
|
|
||||||
if( config->log_plugin_call )
|
if( config->log_plugin_call )
|
||||||
{
|
{
|
||||||
Lock();
|
|
||||||
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message
|
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message
|
||||||
<< ", result: " << (info.res? "true" : "false") << logend;
|
<< ", result: " << (info.res? "true" : "false") << logend;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Lock();
|
|
||||||
log << log1 << "Plugin: id: " << slot->second.index
|
log << log1 << "Plugin: id: " << slot->second.index
|
||||||
<< ", message: " << message
|
<< ", message: " << message
|
||||||
<< ", recurrences are not allowed" << logend;
|
<< ", recurrences are not allowed" << logend;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_)
|
|
||||||
|
PluginRes Plugin::Call(morm::ModelConnector * model_connector, Log * plog, Cur * cur, int message, void * p1, void * p2, long l1, long l2)
|
||||||
{
|
{
|
||||||
PluginRes res;
|
PluginRes res;
|
||||||
int old_current_plugin = current_plugin;
|
int old_current_plugin = current_plugin;
|
||||||
PluginInfo info;
|
PluginInfo info;
|
||||||
|
Cur local_cur;
|
||||||
|
|
||||||
|
if( !cur )
|
||||||
|
cur = &local_cur;
|
||||||
|
|
||||||
Slots::iterator i = slots.lower_bound(message);
|
Slots::iterator i = slots.lower_bound(message);
|
||||||
|
|
||||||
for( ; i!=slots.end() && i->first==message ; ++i )
|
for( ; i!=slots.end() && i->first==message ; ++i )
|
||||||
{
|
{
|
||||||
info.Clear();
|
info.Clear();
|
||||||
info.p1 = p1_;
|
info.p1 = p1;
|
||||||
info.p2 = p2_;
|
info.p2 = p2;
|
||||||
info.l1 = l1_;
|
info.l1 = l1;
|
||||||
info.l2 = l2_;
|
info.l2 = l2;
|
||||||
|
|
||||||
Call(ses, message, i, info);
|
Call(model_connector, plog, cur, message, i, info);
|
||||||
|
|
||||||
if( info.res )
|
if( info.has_res )
|
||||||
++res.res_true;
|
{
|
||||||
else
|
if( info.res )
|
||||||
++res.res_false;
|
++res.res_true;
|
||||||
|
else
|
||||||
|
++res.res_false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current_plugin = old_current_plugin;
|
current_plugin = old_current_plugin;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginRes Plugin::Call(morm::ModelConnector * model_connector, Log * plog, Session * session, Request * request, Mount * mount, int message, void * p1, void * p2, long l1, long l2)
|
||||||
|
{
|
||||||
|
Cur local_cur;
|
||||||
|
|
||||||
|
local_cur.session = session;
|
||||||
|
local_cur.request = request;
|
||||||
|
local_cur.mount = mount;
|
||||||
|
|
||||||
|
return Call(model_connector, plog, &local_cur, message, p1, p2, l1, l2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message)
|
PluginRes Plugin::Call(int message)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, 0, 0, 0, 0);
|
return Call(model_connector, &log, cur, message, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message, void * p1_)
|
PluginRes Plugin::Call(int message, void * p1_)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, p1_, 0, 0, 0);
|
return Call(model_connector, &log, cur, message, p1_, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message, void * p1_, void * p2_)
|
PluginRes Plugin::Call(int message, void * p1_, void * p2_)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, p1_, p2_, 0, 0);
|
return Call(model_connector, &log, cur, message, p1_, p2_, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message, long l1_)
|
PluginRes Plugin::Call(int message, long l1_)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, 0, 0, l1_, 0);
|
return Call(model_connector, &log, cur, message, 0, 0, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message, long l1_, long l2_)
|
PluginRes Plugin::Call(int message, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, 0, 0, l1_, l2_);
|
return Call(model_connector, &log, cur, message, 0, 0, l1_, l2_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message, void * p1_, long l1_)
|
PluginRes Plugin::Call(int message, void * p1_, long l1_)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, p1_, 0, l1_, 0);
|
return Call(model_connector, &log, cur, message, p1_, 0, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
PluginRes Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, p1_, 0, l1_, l2_);
|
return Call(model_connector, &log, cur, message, p1_, 0, l1_, l2_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
PluginRes Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
||||||
{
|
{
|
||||||
return Call(cur->session, message, p1_, p2_, l1_, 0);
|
return Call(model_connector, &log, cur, message, p1_, p2_, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message)
|
|
||||||
{
|
|
||||||
return Call(ses, message, 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, void * p1_)
|
|
||||||
{
|
|
||||||
return Call(ses, message, p1_, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_)
|
|
||||||
{
|
|
||||||
return Call(ses, message, p1_, p2_, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, long l1_)
|
|
||||||
{
|
|
||||||
return Call(ses, message, 0, 0, l1_, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, long l1_, long l2_)
|
|
||||||
{
|
|
||||||
return Call(ses, message, 0, 0, l1_, l2_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_)
|
|
||||||
{
|
|
||||||
return Call(ses, message, p1_, 0, l1_, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, void * p1_, long l1_, long l2_)
|
|
||||||
{
|
|
||||||
return Call(ses, message, p1_, 0, l1_, l2_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PluginRes Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_)
|
|
||||||
{
|
|
||||||
return Call(ses, message, p1_, p2_, l1_, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Plugin::Size()
|
size_t Plugin::Size()
|
||||||
{
|
{
|
||||||
return plugins.size();
|
return plugins.size();
|
||||||
|
|||||||
+26
-45
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -40,7 +40,9 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include "pluginmsg.h"
|
#include "pluginmsg.h"
|
||||||
#include "plugindata.h"
|
#include "plugindata.h"
|
||||||
#include "winixbase.h"
|
#include "winixmodeldeprecated.h"
|
||||||
|
#include "modelconnector.h"
|
||||||
|
#include "mount.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ class Functions;
|
|||||||
class Templates;
|
class Templates;
|
||||||
class SessionManager;
|
class SessionManager;
|
||||||
|
|
||||||
class WinixModel;
|
class WinixModelDeprecated;
|
||||||
class WinixRequest;
|
class WinixRequest;
|
||||||
|
|
||||||
|
|
||||||
@@ -77,10 +79,12 @@ class WinixRequest;
|
|||||||
|
|
||||||
|
|
||||||
class Plugin;
|
class Plugin;
|
||||||
struct Session;
|
class Session;
|
||||||
|
class Request;
|
||||||
|
|
||||||
|
|
||||||
// move me to a different file
|
// move me to a different file
|
||||||
|
// may it should be based on WinixModelDeprecated?
|
||||||
struct PluginInfo
|
struct PluginInfo
|
||||||
{
|
{
|
||||||
// these variables are used for some purposes
|
// these variables are used for some purposes
|
||||||
@@ -95,7 +99,6 @@ struct PluginInfo
|
|||||||
|
|
||||||
|
|
||||||
// objects from winix which are accessible from a plugin
|
// objects from winix which are accessible from a plugin
|
||||||
Db * db;
|
|
||||||
Config * config;
|
Config * config;
|
||||||
Cur * cur;
|
Cur * cur;
|
||||||
System * system;
|
System * system;
|
||||||
@@ -108,14 +111,7 @@ struct PluginInfo
|
|||||||
|
|
||||||
Plugin * plugin;
|
Plugin * plugin;
|
||||||
|
|
||||||
|
morm::ModelConnector * model_connector;
|
||||||
// a session
|
|
||||||
// some messages are sent in a session's context e.g. logging a user
|
|
||||||
// this pointer in not always the same as cur->session, it is preferred
|
|
||||||
// to use this pointer instead of cur->session
|
|
||||||
// (cur->session can point at a temporary object)
|
|
||||||
// this pointer can be null
|
|
||||||
Session * session;
|
|
||||||
|
|
||||||
// pointer to the plugin session (can be null if not set by the plugin or if session is null)
|
// pointer to the plugin session (can be null if not set by the plugin or if session is null)
|
||||||
// this is taken from session->plugin_data.Get()
|
// this is taken from session->plugin_data.Get()
|
||||||
@@ -123,18 +119,17 @@ struct PluginInfo
|
|||||||
// to create your plugin's session data
|
// to create your plugin's session data
|
||||||
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
|
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
|
||||||
|
|
||||||
|
// whether or not there is a res (bool) value set
|
||||||
|
// default: true
|
||||||
|
// if set to false then the 'res' is not taken into account when calculating how many plugins
|
||||||
|
// have returned true or false
|
||||||
|
bool has_res;
|
||||||
|
|
||||||
// function return status
|
// function return status
|
||||||
// default: false (if not set by the plugin)
|
// default: false (if not set by the plugin)
|
||||||
bool res;
|
bool res;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void set_dependency_for(WinixBase * winix_base);
|
|
||||||
void set_dependency_for(WinixBase & winix_base);
|
|
||||||
|
|
||||||
void set_dependency_for(WinixModel * winix_model);
|
|
||||||
void set_dependency_for(WinixModel & winix_model);
|
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
// pointers to winix objects are not cleared here
|
// pointers to winix objects are not cleared here
|
||||||
@@ -145,9 +140,9 @@ struct PluginInfo
|
|||||||
l2 = 0;
|
l2 = 0;
|
||||||
|
|
||||||
plugin_id = -1;
|
plugin_id = -1;
|
||||||
session = 0;
|
|
||||||
plugin_data_base = 0;
|
plugin_data_base = 0;
|
||||||
|
|
||||||
|
has_res = true;
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,11 +166,11 @@ struct PluginRes
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Plugin : public WinixBase
|
class Plugin : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// index of a plugin which is called by Call() method
|
// index of a plugin which is called by CallAllRegisteredMessages() method
|
||||||
// normally: -1
|
// normally: -1
|
||||||
int current_plugin;
|
int current_plugin;
|
||||||
|
|
||||||
@@ -212,13 +207,10 @@ public:
|
|||||||
Plugin();
|
Plugin();
|
||||||
~Plugin();
|
~Plugin();
|
||||||
|
|
||||||
void SetDb(Db * pdb);
|
|
||||||
//void SetConfig(Config * pconfig);
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
void SetSystem(System * psystem);
|
void SetSystem(System * psystem);
|
||||||
|
void SetCur(Cur * cur);
|
||||||
void SetFunctions(Functions * pfunctions);
|
void SetFunctions(Functions * pfunctions);
|
||||||
void SetTemplates(Templates * ptemplates);
|
void SetTemplates(Templates * ptemplates);
|
||||||
//void SetSynchro(Synchro * psynchro);
|
|
||||||
void SetSessionManager(SessionManager * psession_manager);
|
void SetSessionManager(SessionManager * psession_manager);
|
||||||
|
|
||||||
void SetWinixRequest(WinixRequest * winix_request);
|
void SetWinixRequest(WinixRequest * winix_request);
|
||||||
@@ -242,16 +234,9 @@ public:
|
|||||||
PluginRes Call(int message, void * p1_, long l1_);
|
PluginRes Call(int message, void * p1_, long l1_);
|
||||||
PluginRes Call(int message, void * p1_, long l1_, long l2_);
|
PluginRes Call(int message, void * p1_, long l1_, long l2_);
|
||||||
PluginRes Call(int message, void * p1_, void * p2_, long l1_);
|
PluginRes Call(int message, void * p1_, void * p2_, long l1_);
|
||||||
PluginRes Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_);
|
|
||||||
|
|
||||||
PluginRes Call(Session * ses, int message);
|
PluginRes Call(morm::ModelConnector * model_connector, Log * plog, Cur * cur, int message, void * p1 = nullptr, void * p2 = nullptr, long l1 = 0, long l2 = 0);
|
||||||
PluginRes Call(Session * ses, int message, void * p1_);
|
PluginRes Call(morm::ModelConnector * model_connector, Log * plog, Session * session, Request * request, Mount * mount, int message, void * p1 = nullptr, void * p2 = nullptr, long l1 = 0, long l2 = 0);
|
||||||
PluginRes Call(Session * ses, int message, void * p1_, void * p2_);
|
|
||||||
PluginRes Call(Session * ses, int message, long l1_);
|
|
||||||
PluginRes Call(Session * ses, int message, long l1_, long l2_);
|
|
||||||
PluginRes Call(Session * ses, int message, void * p1_, long l1_);
|
|
||||||
PluginRes Call(Session * ses, int message, void * p1_, long l1_, long l2_);
|
|
||||||
PluginRes Call(Session * ses, int message, void * p1_, void * p2_, long l1_);
|
|
||||||
|
|
||||||
// how many plugins there are
|
// how many plugins there are
|
||||||
size_t Size();
|
size_t Size();
|
||||||
@@ -266,16 +251,13 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Db * db;
|
|
||||||
//Config * config;
|
|
||||||
Cur * cur;
|
Cur * cur;
|
||||||
System * system;
|
System * system;
|
||||||
Functions * functions;
|
Functions * functions;
|
||||||
Templates * templates;
|
Templates * templates;
|
||||||
//Synchro * synchro;
|
|
||||||
SessionManager * session_manager;
|
SessionManager * session_manager;
|
||||||
|
|
||||||
WinixRequest * winix_request;
|
WinixRequest * winix_request; // is it needed anymore? !!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
std::wstring temp_path; // used when loading plugins
|
std::wstring temp_path; // used when loading plugins
|
||||||
|
|
||||||
@@ -285,11 +267,10 @@ private:
|
|||||||
Slots slots;
|
Slots slots;
|
||||||
|
|
||||||
void * LoadInitFun(const wchar_t * filename, Fun1 & fun_init);
|
void * LoadInitFun(const wchar_t * filename, Fun1 & fun_init);
|
||||||
void Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info);
|
void Call(morm::ModelConnector * model_connector, Log * plog, Cur * cur, int message, Slots::iterator & slot, PluginInfo & info);
|
||||||
|
|
||||||
bool SetDependency(PluginInfo & info);
|
|
||||||
void SetDependencyFor(WinixBase * winix_base);
|
bool SetDependencyForPluginInfo(morm::ModelConnector * pmodel_connector, Log * plog, Cur * pcur, PluginInfo & info);
|
||||||
void SetDependencyFor(WinixModel * winix_model);
|
|
||||||
void Lock();
|
void Lock();
|
||||||
void Unlock();
|
void Unlock();
|
||||||
|
|
||||||
|
|||||||
+29
-20
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2015, Tomasz Sowa
|
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -40,6 +40,8 @@
|
|||||||
namespace Winix
|
namespace Winix
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// IMPROVEME give some description
|
||||||
|
#define WINIX_MAKE_DATABASE_MIGRATION 997
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -105,10 +107,14 @@ namespace Winix
|
|||||||
// in l1 you have the old session id
|
// in l1 you have the old session id
|
||||||
#define WINIX_SESSION_REMOVED 30029
|
#define WINIX_SESSION_REMOVED 30029
|
||||||
|
|
||||||
// the winix is closing
|
// the winix is being closing
|
||||||
// there is not any sessions available (cur->session is null)
|
// there is not any sessions available (cur->session is null)
|
||||||
// session pointer is null
|
// session pointer is null
|
||||||
#define WINIX_CLOSE 30040
|
#define WINIX_PREPARE_TO_CLOSE 30040
|
||||||
|
|
||||||
|
// winix has been closes, all other threads are stopped now, this is a last message for the main thread
|
||||||
|
// there is not any sessions available (cur->session is null)
|
||||||
|
#define WINIX_QUIT 30041
|
||||||
|
|
||||||
// preparing to remove a file (rm function)
|
// preparing to remove a file (rm function)
|
||||||
// in p1 you have a pointer to the Item struct (file)
|
// in p1 you have a pointer to the Item struct (file)
|
||||||
@@ -138,8 +144,15 @@ namespace Winix
|
|||||||
// winix is initialized,
|
// winix is initialized,
|
||||||
// now you can initialize your plugin
|
// now you can initialize your plugin
|
||||||
// session pointer is null
|
// session pointer is null
|
||||||
|
// you have to set the result status to true (env.res) if your
|
||||||
|
// plugin was initialized correctly, otherwise winix will not start
|
||||||
#define WINIX_PLUGIN_INIT 30080
|
#define WINIX_PLUGIN_INIT 30080
|
||||||
|
|
||||||
|
// winix is ready to remove a plugin
|
||||||
|
// you can clear some plugin data here e.g. controllers
|
||||||
|
// all other threads are stopped now
|
||||||
|
#define WINIX_PLUGIN_QUIT 30081
|
||||||
|
|
||||||
// here you can add your own mount point, file systems, mount parameters
|
// here you can add your own mount point, file systems, mount parameters
|
||||||
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
|
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
|
||||||
// session pointer is null
|
// session pointer is null
|
||||||
@@ -167,6 +180,7 @@ namespace Winix
|
|||||||
|
|
||||||
// the request is being ended
|
// the request is being ended
|
||||||
// you can clear some of your objects here
|
// you can clear some of your objects here
|
||||||
|
// in p1 you have a pointer to the Request object
|
||||||
#define WINIX_END_REQUEST 30140
|
#define WINIX_END_REQUEST 30140
|
||||||
|
|
||||||
// a new file (page) has been added
|
// a new file (page) has been added
|
||||||
@@ -268,20 +282,6 @@ namespace Winix
|
|||||||
// the session pointer in info is null
|
// the session pointer in info is null
|
||||||
#define WINIX_BASE_URL_REDIRECT 31030
|
#define WINIX_BASE_URL_REDIRECT 31030
|
||||||
|
|
||||||
// raw POST parameters
|
|
||||||
// in p1 there is a pointer to std::wstring meaning a parameter's name
|
|
||||||
// in p2 there is a pointer to std::wstring value
|
|
||||||
// this is sent only from PostParser
|
|
||||||
// PostMultiParser (multipart/form-data html forms) doesn't send this messsage
|
|
||||||
// there is no a session set (session pointer is null)
|
|
||||||
// this message is sent for each name value pairs
|
|
||||||
//
|
|
||||||
#define WINIX_POST_PARAMS 31040
|
|
||||||
|
|
||||||
// this is the raw string sent in POST method
|
|
||||||
// in p1 there is a pointer to std::string object
|
|
||||||
#define WINIX_RAW_POST_STRING 31050
|
|
||||||
|
|
||||||
// this message is sent before calling MakePost() or MakeGet()
|
// this message is sent before calling MakePost() or MakeGet()
|
||||||
// if you return false (which is default) you can prevent the access
|
// if you return false (which is default) you can prevent the access
|
||||||
// to the resource
|
// to the resource
|
||||||
@@ -289,14 +289,23 @@ namespace Winix
|
|||||||
|
|
||||||
// http headers (without cookies) were created and are ready to send
|
// http headers (without cookies) were created and are ready to send
|
||||||
// here you can make some changes to them
|
// here you can make some changes to them
|
||||||
// in p1 you have a pointer to the PT::Space (Request::out_headers)
|
// in p1 you have a pointer to the pt::Space (Request::out_headers)
|
||||||
#define WINIX_PREPARE_TO_SEND_HTTP_HEADERS 31070
|
#define WINIX_PREPARE_TO_SEND_HTTP_HEADERS 31070
|
||||||
|
|
||||||
// http cookies were created and are ready to send
|
// http cookies were created and are ready to send
|
||||||
// here you can make some changes to them
|
// here you can make some changes to them
|
||||||
// in p1 you have a pointer to the PT::Space (Request::out_cookies)
|
// in p1 you have a pointer to the pt::Space (Request::out_cookies)
|
||||||
#define WINIX_PREPARE_TO_SEND_HTTP_COOKIES 31080
|
#define WINIX_PREPARE_TO_SEND_HTTP_COOKIES 31080
|
||||||
|
|
||||||
|
// a file log was saved
|
||||||
|
// in p1 you have a pointer to the pt::WTextStream buffer
|
||||||
|
// this can be called from a different thread but with locking
|
||||||
|
#define WINIX_SAVE_FILELOG 31090
|
||||||
|
|
||||||
|
// this message is sent when winix has been started
|
||||||
|
// it is called from the main thread (with locking)
|
||||||
|
#define WINIX_STARTED 31100
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
messages sent from other threads
|
messages sent from other threads
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -256,7 +256,7 @@ void PostMultiParser::LogFirst(const std::string & to_log, size_t len)
|
|||||||
log << "empty";
|
log << "empty";
|
||||||
|
|
||||||
log << "): \"";
|
log << "): \"";
|
||||||
log.LogString(to_log, len);
|
log.put_string(to_log, len);
|
||||||
log << "\"" << logend;
|
log << "\"" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,30 +382,23 @@ void PostMultiParser::ReadContent()
|
|||||||
|
|
||||||
log << log2 << "PMP: content size: " << content_len << " bytes" << logend;
|
log << log2 << "PMP: content size: " << content_len << " bytes" << logend;
|
||||||
|
|
||||||
if( !PT::IsSubStringNoCase("pass", name.c_str()) )
|
if( !pt::is_substr_nc("pass", name.c_str()) )
|
||||||
LogFirst(content, config->log_post_value_size);
|
LogFirst(content, config->log_post_value_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PostMultiParser::ConvStr(const std::string & src, std::wstring & dst)
|
void PostMultiParser::ConvStr(const std::string & src, std::wstring & dst)
|
||||||
{
|
{
|
||||||
PT::UTF8ToWide(src, dst);
|
pt::utf8_to_wide(src, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PostMultiParser::AddNormalPostVar()
|
void PostMultiParser::AddNormalPostVar()
|
||||||
{
|
{
|
||||||
if( post_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
|
|
||||||
{
|
|
||||||
err = WINIX_ERR_INPUT_TOO_LARGE;
|
|
||||||
log << log1 << "PMP: more than " << WINIX_POSTTABLE_MAXSIZE << " post variables (skipping)" << logend;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConvStr(name, namew);
|
ConvStr(name, namew);
|
||||||
ConvStr(content, contentw);
|
ConvStr(content, contentw);
|
||||||
|
|
||||||
bool added = InsertPostVar(*post_tab, namew, contentw);
|
bool added = request->AddPostVar(namew, contentw);
|
||||||
|
|
||||||
log << log2 << "PMP: POST var, name: \"" << namew << "\"";
|
log << log2 << "PMP: POST var, name: \"" << namew << "\"";
|
||||||
|
|
||||||
@@ -418,7 +411,7 @@ void PostMultiParser::AddNormalPostVar()
|
|||||||
|
|
||||||
void PostMultiParser::AddFilePostVar()
|
void PostMultiParser::AddFilePostVar()
|
||||||
{
|
{
|
||||||
if( post_file_tab->size() >= WINIX_POSTTABLE_MAXSIZE )
|
if( request->post_file_tab.size() >= WINIX_POSTTABLE_MAXSIZE )
|
||||||
{
|
{
|
||||||
err = WINIX_ERR_INPUT_TOO_LARGE;
|
err = WINIX_ERR_INPUT_TOO_LARGE;
|
||||||
log << log1 << "PMP: more than " << WINIX_POSTTABLE_MAXSIZE << " post file variables (skipping)" << logend;
|
log << log1 << "PMP: more than " << WINIX_POSTTABLE_MAXSIZE << " post file variables (skipping)" << logend;
|
||||||
@@ -430,7 +423,7 @@ void PostMultiParser::AddFilePostVar()
|
|||||||
post_file_temp.tmp_filename = tmp_filename;
|
post_file_temp.tmp_filename = tmp_filename;
|
||||||
post_file_temp.file_size = content_len;
|
post_file_temp.file_size = content_len;
|
||||||
|
|
||||||
bool added = InsertPostVar(*post_file_tab, namew, post_file_temp);
|
bool added = InsertPostVar(request->post_file_tab, namew, post_file_temp);
|
||||||
|
|
||||||
log << log2 << "PMP: POST FILE var, name: \"" << namew << "\"";
|
log << log2 << "PMP: POST FILE var, name: \"" << namew << "\"";
|
||||||
|
|
||||||
@@ -496,7 +489,7 @@ size_t buf_len = sizeof(buf)/sizeof(wchar_t);
|
|||||||
tmp_filename_postfix += 1;
|
tmp_filename_postfix += 1;
|
||||||
|
|
||||||
tmp_filename = buf;
|
tmp_filename = buf;
|
||||||
PT::WideToUTF8(tmp_filename, atmp_filename);
|
pt::wide_to_utf8(tmp_filename, atmp_filename);
|
||||||
|
|
||||||
tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
|
tmp_file.open(atmp_filename.c_str(), std::ios_base::binary | std::ios_base::out);
|
||||||
// !! IMPROVE ME dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
|
// !! IMPROVE ME dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
|
||||||
@@ -565,6 +558,9 @@ void PostMultiParser::ReadChar()
|
|||||||
|
|
||||||
in_buffer_len = FCGX_GetStr((char*)in_buffer, WINIX_POSTMULTI_INPUT_BUFFER, in);
|
in_buffer_len = FCGX_GetStr((char*)in_buffer, WINIX_POSTMULTI_INPUT_BUFFER, in);
|
||||||
in_buffer_ind = 0;
|
in_buffer_ind = 0;
|
||||||
|
|
||||||
|
if( copy_raw_post && in_buffer_len > 0 )
|
||||||
|
request->raw_post.write((char *)in_buffer, in_buffer_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( in_buffer_len == 0 )
|
if( in_buffer_len == 0 )
|
||||||
@@ -581,7 +577,7 @@ void PostMultiParser::ReadChar()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_)
|
Error PostMultiParser::Parse(FCGX_Stream * in_, Request & request, bool copy_raw_post)
|
||||||
{
|
{
|
||||||
in = in_;
|
in = in_;
|
||||||
last = 0;
|
last = 0;
|
||||||
@@ -590,8 +586,8 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab
|
|||||||
line_end_dos = false;
|
line_end_dos = false;
|
||||||
in_buffer_ind = WINIX_POSTMULTI_INPUT_BUFFER;
|
in_buffer_ind = WINIX_POSTMULTI_INPUT_BUFFER;
|
||||||
in_buffer_len = WINIX_POSTMULTI_INPUT_BUFFER;
|
in_buffer_len = WINIX_POSTMULTI_INPUT_BUFFER;
|
||||||
post_tab = &post_tab_;
|
this->request = &request;
|
||||||
post_file_tab = &post_file_tab_;
|
this->copy_raw_post = copy_raw_post;
|
||||||
tmp_filename_postfix = 1;
|
tmp_filename_postfix = 1;
|
||||||
|
|
||||||
ReadChar();
|
ReadChar();
|
||||||
@@ -605,9 +601,8 @@ Error PostMultiParser::Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab
|
|||||||
|
|
||||||
if( err != WINIX_ERR_OK )
|
if( err != WINIX_ERR_OK )
|
||||||
{
|
{
|
||||||
RemovePostFileTmp(*post_file_tab);
|
RemovePostFileTmp(request.post_file_tab);
|
||||||
post_tab->clear();
|
request.post_in.clear();
|
||||||
post_file_tab->clear();
|
|
||||||
|
|
||||||
if( err != WINIX_ERR_INPUT_TOO_LARGE && err != WINIX_ERR_CANT_CREATE_FILE )
|
if( err != WINIX_ERR_INPUT_TOO_LARGE && err != WINIX_ERR_CANT_CREATE_FILE )
|
||||||
log << log1 << "PMP: syntax error" << logend;
|
log << log1 << "PMP: syntax error" << logend;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
#include <fcgiapp.h>
|
#include <fcgiapp.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "requesttypes.h"
|
#include "request.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "winixbase.h"
|
#include "winixbase.h"
|
||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
~PostMultiParser();
|
~PostMultiParser();
|
||||||
|
|
||||||
void SetConfig(Config * pconfig);
|
void SetConfig(Config * pconfig);
|
||||||
Error Parse(FCGX_Stream * in_, PostTab & post_tab_, PostFileTab & post_file_tab_);
|
Error Parse(FCGX_Stream * in_, Request & request, bool copy_raw_post);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -80,9 +80,9 @@ private:
|
|||||||
int tmp_filename_postfix;
|
int tmp_filename_postfix;
|
||||||
size_t in_buffer_ind;
|
size_t in_buffer_ind;
|
||||||
size_t in_buffer_len;
|
size_t in_buffer_len;
|
||||||
|
bool copy_raw_post;
|
||||||
|
|
||||||
PostTab * post_tab;
|
Request * request;
|
||||||
PostFileTab * post_file_tab;
|
|
||||||
|
|
||||||
int last; // last read character
|
int last; // last read character
|
||||||
int var_index; // used as a postfix to the same name (is auto increment)
|
int var_index; // used as a postfix to the same name (is auto increment)
|
||||||
@@ -148,7 +148,7 @@ std::pair<typename Container::iterator, bool> res;
|
|||||||
if( !added )
|
if( !added )
|
||||||
{
|
{
|
||||||
key += L"_inc";
|
key += L"_inc";
|
||||||
key += Toa(var_index);
|
pt::Toa(var_index, key, false, 10, 5);
|
||||||
res = container.insert( std::make_pair(key, value) );
|
res = container.insert( std::make_pair(key, value) );
|
||||||
added = res.second;
|
added = res.second;
|
||||||
var_index += 1;
|
var_index += 1;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
* Copyright (c) 2022-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -32,97 +32,82 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "item.h"
|
#include <fcgiapp.h>
|
||||||
#include "misc.h"
|
#include <string>
|
||||||
#include "crypt.h"
|
#include "postparser.h"
|
||||||
|
#include "httpsimpleparser.h"
|
||||||
|
#include "convert/text.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
PostParser::PostParser()
|
||||||
|
|
||||||
Item::Item()
|
|
||||||
{
|
{
|
||||||
Clear();
|
log_value_size = 0;
|
||||||
|
HttpSimpleParser::getchar_returns_utf8_chars = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// !! IMPROVE ME
|
void PostParser::LogValueSize(size_t s)
|
||||||
// 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);
|
log_value_size = s;
|
||||||
date_modification = date_creation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item::SetDateModifyToNow()
|
void PostParser::Parse(FCGX_Stream * in, Request & request, bool copy_raw_post)
|
||||||
{
|
{
|
||||||
date_modification = std::time(0);
|
this->in = in;
|
||||||
|
this->request = &request;
|
||||||
|
this->copy_raw_post = copy_raw_post;
|
||||||
|
var_index = 1;
|
||||||
|
this->request->raw_post.clear();
|
||||||
|
|
||||||
|
HttpSimpleParser::Parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item::Clear()
|
int PostParser::GetChar()
|
||||||
{
|
{
|
||||||
id = -1;
|
int c = FCGX_GetChar(in);
|
||||||
|
|
||||||
|
if( c != -1 && copy_raw_post )
|
||||||
|
request->raw_post << static_cast<unsigned char>(c);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PostParser::CreateLog(bool param_added, const std::wstring & name, const std::wstring & value)
|
||||||
|
{
|
||||||
|
log << log2 << "Method POST, name: \"" << name << "\"";
|
||||||
|
|
||||||
user_id = -1;
|
if( log_value_size > 0 && !pt::is_substr_nc(L"pass", name.c_str()) )
|
||||||
group_id = -1;
|
{
|
||||||
privileges = 0;
|
log << ", value: ";
|
||||||
modification_user_id = -1;
|
|
||||||
|
|
||||||
guest_name.clear();
|
if( value.size() > log_value_size )
|
||||||
|
log << "(first " << log_value_size << " characters) ";
|
||||||
subject.clear();
|
|
||||||
content.clear();
|
log << "\"";
|
||||||
modify_index = 0;
|
log.put_string(value, log_value_size);
|
||||||
url.clear();
|
log << "\" (size: " << value.size() << ")";
|
||||||
|
}
|
||||||
content_type = ct_formatted_text;
|
|
||||||
|
|
||||||
type = none;
|
|
||||||
parent_id = -1;
|
|
||||||
|
|
||||||
link_to.clear();
|
if( param_added == false )
|
||||||
link_redirect = false;
|
log << log2 << " (skipped)";
|
||||||
|
|
||||||
content_id = -1;
|
log << log2 << logend;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
void PostParser::Parameter(std::wstring & name, std::wstring & value)
|
||||||
* we're using the HtmlFilter only for those contents
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
bool Item::CanContentBeHtmlFiltered(Item::ContentType ct)
|
|
||||||
{
|
{
|
||||||
return ct == ct_text || ct == ct_formatted_text || ct == ct_html || ct == ct_bbcode;
|
bool added = request->AddPostVar(name, value);
|
||||||
|
CreateLog(added, name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::CanContentBeHtmlFiltered()
|
|
||||||
{
|
|
||||||
return CanContentBeHtmlFiltered(content_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
} // namespace Winix
|
||||||
+15
-100
@@ -4,8 +4,8 @@
|
|||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -35,13 +35,9 @@
|
|||||||
#ifndef headerfile_winix_core_postparser
|
#ifndef headerfile_winix_core_postparser
|
||||||
#define headerfile_winix_core_postparser
|
#define headerfile_winix_core_postparser
|
||||||
|
|
||||||
#include <fcgiapp.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "httpsimpleparser.h"
|
#include "httpsimpleparser.h"
|
||||||
#include "requesttypes.h"
|
#include "request.h"
|
||||||
#include "misc.h"
|
|
||||||
#include "utf8/utf8.h"
|
|
||||||
#include "convert/text.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -51,106 +47,25 @@ namespace Winix
|
|||||||
|
|
||||||
class PostParser : public HttpSimpleParser
|
class PostParser : public HttpSimpleParser
|
||||||
{
|
{
|
||||||
FCGX_Stream * in;
|
|
||||||
PostTab * post_tab;
|
|
||||||
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, const std::wstring & name, const std::wstring & value)
|
|
||||||
{
|
|
||||||
log << log2 << "Method POST, name: \"" << name << "\"";
|
|
||||||
|
|
||||||
if( log_value_size > 0 && !PT::IsSubStringNoCase(L"pass", name.c_str()) )
|
|
||||||
{
|
|
||||||
log << ", value: ";
|
|
||||||
|
|
||||||
if( value.size() > log_value_size )
|
|
||||||
log << "(first " << log_value_size << " characters) ";
|
|
||||||
|
|
||||||
log << "\"";
|
|
||||||
log.LogString(value, log_value_size);
|
|
||||||
log << "\" (size: " << value.size() << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
if( param_added == false )
|
|
||||||
log << log2 << " (skipped)";
|
|
||||||
|
|
||||||
log << log2 << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual void Parameter(std::wstring & name, std::wstring & value)
|
|
||||||
{
|
|
||||||
bool added;
|
|
||||||
std::pair<PostTab::iterator, bool> res;
|
|
||||||
|
|
||||||
if( has_winix_post_params_msg )
|
|
||||||
plugin->Call(0, WINIX_POST_PARAMS, &name, &value);
|
|
||||||
|
|
||||||
res = post_tab->insert( std::make_pair(name, value) );
|
|
||||||
added = res.second;
|
|
||||||
|
|
||||||
if( !added )
|
|
||||||
{
|
|
||||||
name += L"_inc";
|
|
||||||
name += Toa(var_index);
|
|
||||||
res = post_tab->insert( std::make_pair(name, value) );
|
|
||||||
added = res.second;
|
|
||||||
var_index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateLog(added, name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PostParser()
|
PostParser();
|
||||||
{
|
void LogValueSize(size_t s);
|
||||||
log_value_size = 0;
|
void Parse(FCGX_Stream * in, Request & request, bool copy_raw_post);
|
||||||
HttpSimpleParser::getchar_returns_utf8_chars = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogValueSize(size_t s)
|
|
||||||
{
|
|
||||||
log_value_size = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Parse(FCGX_Stream * in_, PostTab & post_tab_)
|
protected:
|
||||||
{
|
|
||||||
in = in_;
|
|
||||||
post_tab = &post_tab_;
|
|
||||||
var_index = 1;
|
|
||||||
raw_post.clear();
|
|
||||||
|
|
||||||
has_winix_post_params_msg = plugin->HasMessage(WINIX_POST_PARAMS);
|
FCGX_Stream * in;
|
||||||
has_winix_raw_post_msg = plugin->HasMessage(WINIX_RAW_POST_STRING);
|
Request * request;
|
||||||
|
size_t log_value_size;
|
||||||
|
int var_index;
|
||||||
|
bool copy_raw_post;
|
||||||
|
|
||||||
HttpSimpleParser::Parse();
|
virtual int GetChar();
|
||||||
|
void CreateLog(bool param_added, const std::wstring & name, const std::wstring & value);
|
||||||
if( has_winix_raw_post_msg )
|
virtual void Parameter(std::wstring & name, std::wstring & value);
|
||||||
plugin->Call(0, WINIX_RAW_POST_STRING, &raw_post);
|
|
||||||
|
|
||||||
raw_post.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+2086
-100
File diff suppressed because it is too large
Load Diff
+334
-151
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -39,16 +39,23 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "requesttypes.h"
|
#include "requesttypes.h"
|
||||||
#include "item.h"
|
#include "models/item.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "textstream.h"
|
|
||||||
#include "templates/htmltextstream.h"
|
#include "templates/htmltextstream.h"
|
||||||
#include "date/date.h"
|
#include "date/date.h"
|
||||||
#include "space/space.h"
|
#include "space/space.h"
|
||||||
#include "space/spacetojson.h"
|
|
||||||
#include "textstream/textstream.h"
|
#include "textstream/textstream.h"
|
||||||
#include "outstreams.h"
|
#include "outstreams.h"
|
||||||
|
#include "models.h"
|
||||||
|
#include "models/winixmodel.h"
|
||||||
|
#include "header.h"
|
||||||
|
#include "compress.h"
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "mount.h"
|
||||||
|
#include "mounts.h"
|
||||||
|
#include "jobtask.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -58,12 +65,15 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
class FunctionBase;
|
class FunctionBase;
|
||||||
|
class Templates;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Request : public WinixModel
|
||||||
struct Request
|
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
// how many input headers can be put to in_headers struct
|
// how many input headers can be put to in_headers struct
|
||||||
static const size_t MAX_INPUT_HEADERS = 32;
|
static const size_t MAX_INPUT_HEADERS = 32;
|
||||||
|
|
||||||
@@ -82,14 +92,57 @@ struct Request
|
|||||||
*/
|
*/
|
||||||
size_t id;
|
size_t id;
|
||||||
|
|
||||||
|
// the state of the request
|
||||||
|
// not_assigned - the object is not being used
|
||||||
|
// normal_run - run in the main thread, this state is set after a new request is made
|
||||||
|
// assigned_to_job - the request is preserved and a new job will be called
|
||||||
|
// job_run - run in the job thread (objects are locked)
|
||||||
|
// finished - the request is finished and the object can be removed
|
||||||
|
enum RunState { not_assigned = 0, normal_run, assigned_to_job, job_run, job_continuation_run, prepare_to_finish, finished};
|
||||||
|
|
||||||
|
RunState run_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
request start time
|
* 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
|
* start_time is the same as timespec_req_start.tv_sec
|
||||||
|
* start_date is a pt::Date converted from start_time
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
timespec timespec_req_start;
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
PT::Date start_date;
|
pt::Date start_date;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* request stop time
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
timespec timespec_req_stop;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* request stop time - start time
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
timespec timespec_req_diff;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start time of the ezc engine (html templates)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
timespec timespec_ezc_engine_start;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* end time of the ezc engine (html templates)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
timespec timespec_ezc_engine_stop;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -107,7 +160,7 @@ struct Request
|
|||||||
the HTTP method
|
the HTTP method
|
||||||
!! IMPROVE ME add the rest methods here
|
!! IMPROVE ME add the rest methods here
|
||||||
*/
|
*/
|
||||||
enum Method { get, post, head, delete_, unknown_method } method;
|
enum Method { get, head, post, put, delete_, connect, options, trace, patch, unknown_method } method;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -119,14 +172,17 @@ struct Request
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
raw parameters
|
raw parameters
|
||||||
!! CHECK ME may post_tab and cookie_tab should be changed to PT::Space now?
|
!! 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?
|
or may change the name to cookie_in? or in_cookie?
|
||||||
*/
|
*/
|
||||||
PostTab post_tab;
|
|
||||||
PostFileTab post_file_tab;
|
PostFileTab post_file_tab;
|
||||||
CookieTab cookie_tab;
|
CookieTab cookie_tab;
|
||||||
PT::Space post_in;
|
pt::Space post_in;
|
||||||
bool is_postin_used;// temporarily, before all post variables will be put to post_in
|
|
||||||
|
/*
|
||||||
|
* raw post input used if a Function::NeedToCopyRawPost() returned true
|
||||||
|
*/
|
||||||
|
pt::TextStream raw_post;
|
||||||
|
|
||||||
// input headers (without cookies)
|
// input headers (without cookies)
|
||||||
// at the moment we are using FastCGI and HTTP headers are prefixed with 'HTTP_' string
|
// at the moment we are using FastCGI and HTTP headers are prefixed with 'HTTP_' string
|
||||||
@@ -135,7 +191,7 @@ struct Request
|
|||||||
// although https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 says that there can be more
|
// although https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 says that there can be more
|
||||||
// than one http header with the same name we do not support it
|
// than one http header with the same name we do not support it
|
||||||
// each header has a different name here, cookies we have in a different container (cookie_tab)
|
// each header has a different name here, cookies we have in a different container (cookie_tab)
|
||||||
PT::Space headers_in;
|
pt::Space headers_in;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -151,6 +207,8 @@ struct Request
|
|||||||
std::wstring env_http_host;
|
std::wstring env_http_host;
|
||||||
std::wstring env_http_user_agent;
|
std::wstring env_http_user_agent;
|
||||||
std::wstring env_http_accept_encoding;
|
std::wstring env_http_accept_encoding;
|
||||||
|
std::wstring env_http_accept;
|
||||||
|
std::wstring env_http_accept_language;
|
||||||
std::wstring env_fcgi_role;
|
std::wstring env_fcgi_role;
|
||||||
std::wstring env_content_type;
|
std::wstring env_content_type;
|
||||||
std::wstring env_https;
|
std::wstring env_https;
|
||||||
@@ -171,6 +229,8 @@ struct Request
|
|||||||
// true if we are using an encrypted connection (SSL)
|
// true if we are using an encrypted connection (SSL)
|
||||||
bool using_ssl;
|
bool using_ssl;
|
||||||
|
|
||||||
|
// true if the request is being made by ajax by htmx library
|
||||||
|
bool is_htmx_request;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
request input variables representing the winix filesystem
|
request input variables representing the winix filesystem
|
||||||
@@ -189,13 +249,23 @@ struct Request
|
|||||||
// null if there is no a function
|
// null if there is no a function
|
||||||
FunctionBase * function;
|
FunctionBase * function;
|
||||||
|
|
||||||
|
// current session (if exists, can be null)
|
||||||
|
Session * session;
|
||||||
|
|
||||||
|
// current mount point (can be null, it is treated as cms filesystem then)
|
||||||
|
Mount * mount;
|
||||||
|
|
||||||
// parameters (name:value)
|
// parameters (name:value)
|
||||||
ParamTab param_tab;
|
ParamTab param_tab;
|
||||||
|
|
||||||
// this is a pointer either to the item (if exists) or to the last directory
|
// this is a pointer either to the item (if exists) or to the last directory
|
||||||
Item * last_item;
|
Item * last_item;
|
||||||
|
|
||||||
|
// can we use gzip compression algorithm when sending content to the client
|
||||||
|
bool accept_gzip;
|
||||||
|
|
||||||
|
// can we use deflate compression algorithm when sending content to the client
|
||||||
|
bool accept_deflate;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -208,11 +278,101 @@ struct Request
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// the algorithm how a request's container is selected is shown below:
|
||||||
|
// (the whole answer's algorightm is implemented in PrepareAnswerType() method)
|
||||||
|
// ------------------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// at the beginning we set container_type to "raw" meaning simple text or html, then
|
||||||
|
// we check the "Accept" http header, if it is set then we set container_type accordingly:
|
||||||
|
//
|
||||||
|
// Accept | container_type
|
||||||
|
// -----------------------------------------------
|
||||||
|
// text/html | container_raw
|
||||||
|
// application/xhtml+xml | container_raw
|
||||||
|
// application/json | container_json
|
||||||
|
// application/xml | container_xml
|
||||||
|
// text/csv | container_csv
|
||||||
|
//
|
||||||
|
// next we check "container" url parameter, if it is set then we set container_type accordingly
|
||||||
|
// ("container" url parameter has higher precedence than "Accept" http header):
|
||||||
|
//
|
||||||
|
// container | container_type
|
||||||
|
// -----------------------------------------------
|
||||||
|
// raw | container_raw
|
||||||
|
// json | container_json
|
||||||
|
// xml | container_xml
|
||||||
|
// csv | container_csv
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Samples:
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller
|
||||||
|
// returns html answer from the main ezc stream
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/container:raw
|
||||||
|
// returns html answer from the main ezc stream (the same as above)
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/frame:abc
|
||||||
|
// returns "abc" frame as html
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/container:json
|
||||||
|
// returns all serialized models to json and no ezc streams
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/container:xml
|
||||||
|
// returns all serialized models to xml and no ezc streams
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/container:json/frame:abc,xyz
|
||||||
|
// returns all serialized models to json and two frames in 'ezc_frames' object
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/container:json/all_frames
|
||||||
|
// returns all serialized models to json and all frames in 'ezc_frames' object
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/container:json/main_stream
|
||||||
|
// returns all serialized models and the main ezc stream in 'main_stream' field
|
||||||
|
//
|
||||||
|
// http://domain.tld/dir/controller/container:json/main_stream/all_frames
|
||||||
|
// returns all serialized models to json, all frames and the main stream
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
bool send_bin_stream;
|
||||||
|
bool send_main_stream;
|
||||||
|
bool send_all_frames;
|
||||||
|
std::vector<std::wstring> send_frames;
|
||||||
|
|
||||||
|
bool use_ezc_engine;
|
||||||
|
bool serialize_models;
|
||||||
|
|
||||||
|
|
||||||
|
// change maybe answer_text -> container_text?
|
||||||
|
enum ContainerType
|
||||||
|
{
|
||||||
|
container_raw,
|
||||||
|
container_json,
|
||||||
|
container_xml,
|
||||||
|
container_csv,
|
||||||
|
};
|
||||||
|
|
||||||
|
ContainerType container_type;
|
||||||
|
|
||||||
|
|
||||||
|
// at the beginning those with higher priority
|
||||||
|
std::vector<HeaderValue> accept_mime_types;
|
||||||
|
|
||||||
|
// at the beginning those with higher priority
|
||||||
|
std::vector<HeaderValue> accept_languages;
|
||||||
|
|
||||||
// request status
|
// request status
|
||||||
// !! CHANGE ME it'll be better to use ordinary http result codes
|
// DEPRECATED, use http_status instead
|
||||||
Error status;
|
Error status;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* HTTP result status
|
||||||
|
* at the moment default is -1 which means it is not used (use status in such a case)
|
||||||
|
*/
|
||||||
|
int http_status;
|
||||||
|
|
||||||
// if not empty means an address for redirecting to
|
// if not empty means an address for redirecting to
|
||||||
// it should be url-encoded
|
// it should be url-encoded
|
||||||
std::wstring redirect_to;
|
std::wstring redirect_to;
|
||||||
@@ -233,100 +393,30 @@ struct Request
|
|||||||
bool send_as_attachment;
|
bool send_as_attachment;
|
||||||
|
|
||||||
// headers send to the client (without cookies) (may change to headers_out?)
|
// headers send to the client (without cookies) (may change to headers_out?)
|
||||||
PT::Space out_headers;
|
pt::Space out_headers;
|
||||||
|
|
||||||
// cookies send to the client
|
// cookies send to the client
|
||||||
// a value can be either a cookie value or the whole cookie string (with domain, date etc)
|
// a value can be either a cookie value or the whole cookie string (with domain, date etc)
|
||||||
PT::Space out_cookies;
|
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_main_stream |
|
|
||||||
// |
|
|
||||||
// |
|
|
||||||
// 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 }
|
|
||||||
// "out": { out_streams serialized here e.g.:
|
|
||||||
// "stream_name_1": "some html content",
|
|
||||||
// "stream_name_2": "some other html content"
|
|
||||||
// },
|
|
||||||
// "info": { info object serialized here }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
bool send_bin_stream;
|
|
||||||
|
|
||||||
// binary page sent to the client if send_bin_stream is true
|
// binary page sent to the client if answer_source is answer_bin_stream
|
||||||
BinaryPage out_bin_stream;
|
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_main_stream)
|
|
||||||
// if return_json is true we are creating an JSON object from out_streams
|
|
||||||
// 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 stream where the html otput is generated from ezc templates
|
// main text output stream where the html otput is generated from ezc templates
|
||||||
// here the whole html page (with doctype, head, body) is generated
|
// here the whole html page (with doctype, head, body) is generated
|
||||||
HtmlTextStream out_main_stream;
|
HtmlTextStream out_main_stream;
|
||||||
|
|
||||||
// text output streams used in ajax requests (send in JSON format to the client)
|
// text output streams used in ajax requests
|
||||||
// in ezc templates you can use [ezc out "stream_name"] keyword
|
// in ezc templates you can use [ezc frame "stream_name"] or just [frame "stream_name"] keyword
|
||||||
// to switch between streams
|
// to switch between streams
|
||||||
Ezc::OutStreams<HtmlTextStream> out_streams;
|
Ezc::OutStreams<HtmlTextStream, true> out_streams;
|
||||||
|
|
||||||
// if true the JSON object is generated only from info (out_streams are not used)
|
// models to return or to render through ezc library
|
||||||
// default: false
|
Ezc::Models models;
|
||||||
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 main html stream should be filtered by our html filter
|
|
||||||
bool out_main_stream_use_html_filter;
|
|
||||||
|
|
||||||
// whether or not the ajax streams should be filtered by our html filter
|
|
||||||
// this filter is only aplied to streams in "out" space, "info" space is not touched
|
|
||||||
bool out_streams_use_html_filter;
|
|
||||||
|
|
||||||
|
// filter html content with HTMLFilter, default the same as config.html_filter
|
||||||
|
bool use_html_filter;
|
||||||
|
|
||||||
// if this variable is true then winix always return 200 OK header
|
// if this variable is true then winix always return 200 OK header
|
||||||
// when the status would be 404 (not found) or 403 (permission denied)
|
// when the status would be 404 (not found) or 403 (permission denied)
|
||||||
@@ -338,32 +428,50 @@ struct Request
|
|||||||
bool gen_skip_new_line;
|
bool gen_skip_new_line;
|
||||||
bool gen_use_special_chars;
|
bool gen_use_special_chars;
|
||||||
|
|
||||||
|
// index template name
|
||||||
|
std::wstring html_template;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
additional variables used for common uses
|
additional variables used for common uses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// DEPRECATED will be removed
|
||||||
// usually items in the current directory (depends on the function)
|
// usually items in the current directory (depends on the function)
|
||||||
std::vector<Item> item_tab;
|
std::vector<Item> item_tab;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FastCGI request structure with pointers to input/output streams
|
||||||
|
*/
|
||||||
|
FCGX_Request fcgi_request;
|
||||||
|
|
||||||
|
|
||||||
|
long job_id; // the main id of your job
|
||||||
|
long job_second_id; // a secondary id of your job
|
||||||
|
pt::Space job;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Request();
|
Request();
|
||||||
void SetConfig(Config * pconfig);
|
|
||||||
|
void SetConfig(Config * config);
|
||||||
|
void SetTemplates(Templates * templates);
|
||||||
|
void SetCompress(Compress * compress);
|
||||||
|
void SetPlugin(Plugin * plugin);
|
||||||
|
void SetMounts(Mounts * mounts);
|
||||||
|
|
||||||
|
void set_json_connector(morm::JSONConnector * json_connector);
|
||||||
|
void set_xml_connector(morm::XMLConnector * xml_connector);
|
||||||
|
|
||||||
|
void fields();
|
||||||
|
|
||||||
|
|
||||||
void RequestStarts();
|
void RequestStarts();
|
||||||
|
void RequestEnds();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
void PrepareAnswerType();
|
||||||
|
|
||||||
bool IsParam(const wchar_t * param_name);
|
bool IsParam(const wchar_t * param_name);
|
||||||
bool IsParam(const std::wstring & param_name);
|
bool IsParam(const std::wstring & param_name);
|
||||||
@@ -373,6 +481,16 @@ struct Request
|
|||||||
std::wstring * ParamValuep(const wchar_t * param_name); // returns nullptr if there is no such a parameter
|
std::wstring * ParamValuep(const wchar_t * param_name); // returns nullptr if there is no such a parameter
|
||||||
std::wstring * ParamValuep(const std::wstring & param_name); // returns nullptr if there is no such a parameter
|
std::wstring * ParamValuep(const std::wstring & param_name); // returns nullptr if there is no such a parameter
|
||||||
|
|
||||||
|
void AddParam(const std::wstring & param_name, const std::wstring & param_value);
|
||||||
|
void AddParam(const wchar_t * param_name, const wchar_t * param_value);
|
||||||
|
|
||||||
|
void RemoveParam(const wchar_t * param_name);
|
||||||
|
void RemoveParam(const std::wstring & param_name);
|
||||||
|
|
||||||
|
pt::Space * AddPostVar(pt::Space & space, const wchar_t * name);
|
||||||
|
bool AddPostVar(const wchar_t * name, const wchar_t * value);
|
||||||
|
bool AddPostVar(const std::wstring & name, const std::wstring & value);
|
||||||
|
|
||||||
bool IsPostVar(const wchar_t * var);
|
bool IsPostVar(const wchar_t * var);
|
||||||
bool IsPostVar(const std::wstring & 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 wchar_t * var); // returns an empty string if there is no such a parameter
|
||||||
@@ -382,74 +500,139 @@ struct Request
|
|||||||
std::wstring * PostVarp(const wchar_t * var);
|
std::wstring * PostVarp(const wchar_t * var);
|
||||||
std::wstring * PostVarp(const std::wstring & var);
|
std::wstring * PostVarp(const std::wstring & var);
|
||||||
|
|
||||||
bool AllPostVarEmpty(); // returning true if all post vars are empty
|
void AddCookie(
|
||||||
|
const std::wstring & name,
|
||||||
|
const std::wstring * value_string = nullptr,
|
||||||
|
const pt::Stream * value_stream = nullptr,
|
||||||
|
pt::Date * expires = nullptr,
|
||||||
|
const std::wstring * path = nullptr,
|
||||||
|
const std::wstring * domain = nullptr,
|
||||||
|
CookieSameSite cookie_same_site = CookieSameSite::samesite_notset,
|
||||||
|
bool http_only = false,
|
||||||
|
bool secure = false);
|
||||||
|
|
||||||
|
void AddDefaultSessionCookie(const std::wstring & value, pt::Date * expires = nullptr);
|
||||||
|
|
||||||
|
bool has_frame(const wchar_t * frame);
|
||||||
|
bool has_frame(const std::wstring & frame);
|
||||||
|
|
||||||
|
void create_job(long job_id = JobTask::JOB_ID_DEFAULT, long job_secondary_id = JobTask::JOB_ID_DEFAULT);
|
||||||
|
void modify_status_code_if_needed();
|
||||||
|
|
||||||
|
// RENAMEME to add_header_if_not_exists
|
||||||
|
bool AddHeader(const wchar_t * name, const wchar_t * value);
|
||||||
|
bool AddHeader(const wchar_t * name, long 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);
|
||||||
|
|
||||||
|
void FinishRequest();
|
||||||
|
|
||||||
|
|
||||||
// setting a cookie
|
void SetEnv(const char * name, std::wstring & env);
|
||||||
// name - cookie name (either const wchar_t, or std::wstring or PT::WTextStream)
|
void ReadEnvVariables();
|
||||||
// value - cookie value (can be everything which can be put to PT::WTextStream stream)
|
void ReadEnvRemoteIP();
|
||||||
// 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>
|
static Method CheckRequestMethod(const wchar_t * name);
|
||||||
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date & expires);
|
void CheckRequestMethod();
|
||||||
|
|
||||||
|
void CheckSSL();
|
||||||
|
void SetSubdomain();
|
||||||
|
|
||||||
|
static void PutMethodName(Request::Method method, pt::Stream & stream);
|
||||||
|
void PutMethodName(pt::Stream & stream);
|
||||||
|
|
||||||
|
bool has_htmx_redirect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Config * config;
|
Config * config;
|
||||||
|
Templates * templates;
|
||||||
|
Compress * compress;
|
||||||
|
Plugin * plugin;
|
||||||
|
Mounts * mounts;
|
||||||
|
|
||||||
|
morm::JSONConnector * json_connector;
|
||||||
|
morm::XMLConnector * xml_connector;
|
||||||
|
|
||||||
|
BinaryPage output_8bit;
|
||||||
|
BinaryPage compressed_output;
|
||||||
|
pt::WTextStream output_tmp_filtered_stream;
|
||||||
|
pt::TextStream serialized_model;
|
||||||
|
std::string aheader_name, aheader_value;
|
||||||
|
std::wstring cookie_id_string;
|
||||||
|
std::string send_data_buf;
|
||||||
|
std::wstring http_header_name;
|
||||||
|
std::string http_header_8bit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// used in ParamValue() and PostVar() when there is no such a param
|
// used in ParamValue() and PostVar() when there is no such a param
|
||||||
const std::wstring str_empty;
|
const std::wstring str_empty;
|
||||||
|
|
||||||
void ClearOutputStreams();
|
void ClearOutputStreams();
|
||||||
|
|
||||||
|
void CheckAcceptHeader();
|
||||||
|
void CheckContainerParameter();
|
||||||
|
void PrepareFrameNames();
|
||||||
|
|
||||||
|
void current_dir(morm::Wrapper & wrapper);
|
||||||
|
void last_item_wrapper(morm::Wrapper & wrapper);
|
||||||
|
|
||||||
|
void http_status_error_title(EzcEnv & env);
|
||||||
|
void http_status_error_description(EzcEnv & env);
|
||||||
|
|
||||||
|
void PrepareAndSendAnswer();
|
||||||
|
void PrepareRawAnswer();
|
||||||
|
void PrepareJsonAnswer();
|
||||||
|
void PrepareXmlAnswer();
|
||||||
|
void PrepareCsvAnswer();
|
||||||
|
void PrepareContenerizedAnswer();
|
||||||
|
void PutSeparatorIfNeeded(bool put_separator);
|
||||||
|
void SerializeField(const wchar_t * field_name);
|
||||||
|
void SerializeClosingField(const wchar_t * field_name);
|
||||||
|
void SerializeFieldJson(const wchar_t * field_name);
|
||||||
|
void SerializeFieldXml(const wchar_t * field_name);
|
||||||
|
void SerializeClosingFieldXml(const wchar_t * field_name);
|
||||||
|
void SerializeFieldCsv(const wchar_t * field_name);
|
||||||
|
void SerializeStream(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||||
|
void SerializeStreamJson(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||||
|
void SerializeStreamXml(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||||
|
void SerializeStreamCsv(const pt::WTextStream & input_stream, const wchar_t * field_name);
|
||||||
|
void SerializeAllFrames();
|
||||||
|
void SerializeSpecificFrames();
|
||||||
|
void SerializeModels();
|
||||||
|
void SerializeModel(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||||
|
void SerializeModelJson(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||||
|
void SerializeModelXml(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||||
|
void SerializeModelCsv(morm::Wrapper & wrapper, const wchar_t * field_name);
|
||||||
|
void FilterHtmlIfNeeded(const pt::WTextStream & input_stream, BinaryPage & output, bool clear_stream = true);
|
||||||
|
void Send8bitOutput(BinaryPage & output);
|
||||||
|
void SendData(const BinaryPage & page, FCGX_Stream * out);
|
||||||
|
void UseEzcGenerator();
|
||||||
|
int SelectDeflateVersion();
|
||||||
|
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
|
||||||
|
void PrepareSessionCookie();
|
||||||
|
void PrepareHeaders(bool compressing, int compress_encoding, size_t output_size);
|
||||||
|
void ModifyStatusForRedirect();
|
||||||
|
void PrepareSendFileHeaderForStaticMountpoint();
|
||||||
|
void PrepareSendFileHeader();
|
||||||
|
void PrepareContentEncodingHeader(int compress_encoding);
|
||||||
|
void PrepareContentLengthHeader(size_t output_size);
|
||||||
|
void PrepareHeaderContentType();
|
||||||
|
void PrepareHeaderStatus(int http_status);
|
||||||
|
void SendHeaders();
|
||||||
|
void SendCookies();
|
||||||
|
bool CreateStaticResourcePath(pt::WTextStream & out_path);
|
||||||
|
bool CanSendContent();
|
||||||
|
void LogRequestTime();
|
||||||
|
|
||||||
|
MORM_MEMBER_FIELD(Request)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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
|
} // namespace Winix
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -45,12 +45,9 @@ namespace Winix
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// may move to config?
|
||||||
// !! IMPROVE ME
|
#define WINIX_POSTTABLE_MAXSIZE 1024
|
||||||
// !! narazie uzywane tylko w post multi parserze
|
#define WINIX_POSTTABLE_VALUE_TABLE_MAXSIZE 1024
|
||||||
// dodac do zwyklego parsera post
|
|
||||||
#define WINIX_POSTTABLE_MAXSIZE 50
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct PostFile
|
struct PostFile
|
||||||
@@ -69,15 +66,18 @@ struct Param
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum CookieSameSite {samesite_notset = 0, samesite_strict = 1, samesite_lax = 2, samesite_none = 3};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// some global types used by Request class
|
// some global types used by Request class
|
||||||
typedef std::map<std::wstring, std::wstring> PostTab;
|
|
||||||
typedef std::map<std::wstring, PostFile> PostFileTab;
|
typedef std::map<std::wstring, PostFile> PostFileTab;
|
||||||
typedef std::vector<Param> ParamTab;
|
typedef std::vector<Param> ParamTab;
|
||||||
|
|
||||||
typedef std::map<std::wstring, std::wstring> CookieTab;
|
typedef std::map<std::wstring, std::wstring> CookieTab;
|
||||||
|
|
||||||
|
|
||||||
typedef PT::TextStreamBase<char, 1, 4096> BinaryPage;
|
typedef pt::TextStreamBase<char, 1, 4096> BinaryPage;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -97,6 +97,7 @@ void Session::Clear(bool clear_plugin_data)
|
|||||||
new_session = true;
|
new_session = true;
|
||||||
spam_score = 0;
|
spam_score = 0;
|
||||||
remove_me = false;
|
remove_me = false;
|
||||||
|
allow_to_delete = true;
|
||||||
|
|
||||||
start_time = 0;
|
start_time = 0;
|
||||||
last_time = 0;
|
last_time = 0;
|
||||||
@@ -104,7 +105,6 @@ void Session::Clear(bool clear_plugin_data)
|
|||||||
start_date.Clear();
|
start_date.Clear();
|
||||||
last_date.Clear();
|
last_date.Clear();
|
||||||
|
|
||||||
log_buffer.Clear();
|
|
||||||
last_css.clear();
|
last_css.clear();
|
||||||
ip_ban = 0;
|
ip_ban = 0;
|
||||||
|
|
||||||
@@ -121,6 +121,11 @@ void Session::ClearAfterRequest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Session::is_temporary_session() const
|
||||||
|
{
|
||||||
|
return id == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
+18
-13
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -39,12 +39,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "item.h"
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "user.h"
|
#include "models/user.h"
|
||||||
#include "plugindata.h"
|
#include "plugindata.h"
|
||||||
#include "rebus.h"
|
#include "rebus.h"
|
||||||
#include "textstream.h"
|
|
||||||
#include "date/date.h"
|
#include "date/date.h"
|
||||||
#include "ipban.h"
|
#include "ipban.h"
|
||||||
|
|
||||||
@@ -54,8 +52,9 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Session
|
class Session
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
Session();
|
Session();
|
||||||
Session(const Session & ses);
|
Session(const Session & ses);
|
||||||
@@ -66,7 +65,7 @@ struct Session
|
|||||||
void ClearAfterRequest();
|
void ClearAfterRequest();
|
||||||
|
|
||||||
|
|
||||||
// 0 - means that there is a temporary session
|
// 0 - means that this is a temporary session
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
// a session index
|
// a session index
|
||||||
@@ -82,12 +81,12 @@ struct Session
|
|||||||
// when this session was created
|
// when this session was created
|
||||||
// (the same values)
|
// (the same values)
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
PT::Date start_date;
|
pt::Date start_date;
|
||||||
|
|
||||||
// when this session was last used
|
// when this session was last used
|
||||||
// (the same values)
|
// (the same values)
|
||||||
time_t last_time;
|
time_t last_time;
|
||||||
PT::Date last_date;
|
pt::Date last_date;
|
||||||
|
|
||||||
// when there was a last get request
|
// when there was a last get request
|
||||||
// (used to calculate spam or invalid login attempts etc.)
|
// (used to calculate spam or invalid login attempts etc.)
|
||||||
@@ -101,16 +100,20 @@ struct Session
|
|||||||
bool remember_me;
|
bool remember_me;
|
||||||
|
|
||||||
|
|
||||||
// if true then this session will be removed by SessionManager
|
// if remove_me is true and if allow_to_delete is true then this session will be
|
||||||
// without checking the time expiration
|
// removed by SessionManager without checking the time expiration
|
||||||
bool remove_me;
|
bool remove_me;
|
||||||
|
|
||||||
|
// if the session can be removed then this value is true (default)
|
||||||
|
// if we continue a request from a controller to a job
|
||||||
|
// then we set this value to false in order for the SessionManager
|
||||||
|
// to not delete this
|
||||||
|
bool allow_to_delete;
|
||||||
|
|
||||||
|
|
||||||
PluginData plugin_data;
|
PluginData plugin_data;
|
||||||
|
|
||||||
|
|
||||||
// buffer for the session log
|
|
||||||
TextStream<std::wstring> log_buffer;
|
|
||||||
|
|
||||||
// !! IMPROVE ME it is still needed?
|
// !! IMPROVE ME it is still needed?
|
||||||
// css cannot be taken directly from the mountpoint?
|
// css cannot be taken directly from the mountpoint?
|
||||||
// table with css files
|
// table with css files
|
||||||
@@ -133,6 +136,8 @@ struct Session
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool is_temporary_session() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -82,7 +82,7 @@ Table::iterator i = table.begin();
|
|||||||
{
|
{
|
||||||
if( i->plugin_data.HasAllocatedData() )
|
if( i->plugin_data.HasAllocatedData() )
|
||||||
{
|
{
|
||||||
plugin->Call(&*i, WINIX_PLUGIN_SESSION_DATA_REMOVE); // the session passed here is ok?
|
plugin->Call(model_connector, &log, &*i, nullptr, nullptr, WINIX_PLUGIN_SESSION_DATA_REMOVE, nullptr, nullptr, 0, 0); // the session passed here is ok?
|
||||||
}
|
}
|
||||||
|
|
||||||
//i->plugin_data.DeleteAll(); // it's better to call it here instead in the destructor
|
//i->plugin_data.DeleteAll(); // it's better to call it here instead in the destructor
|
||||||
@@ -116,7 +116,7 @@ IndexId::iterator i = index_id.find(id);
|
|||||||
|
|
||||||
if( i->second->plugin_data.HasAllocatedData() )
|
if( i->second->plugin_data.HasAllocatedData() )
|
||||||
{
|
{
|
||||||
plugin->Call(&*(i->second), WINIX_PLUGIN_SESSION_DATA_REMOVE); // the session passed here is ok?
|
plugin->Call(model_connector, &log, &*(i->second), nullptr, nullptr, WINIX_PLUGIN_SESSION_DATA_REMOVE, nullptr, nullptr, 0, 0); // the session passed here is ok?
|
||||||
}
|
}
|
||||||
|
|
||||||
//i->second->plugin_data.DeleteAll();
|
//i->second->plugin_data.DeleteAll();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "cur.h"
|
#include "cur.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "winixmodel.h"
|
#include "winixmodeldeprecated.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ namespace Winix
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionContainer : public WinixModel
|
class SessionContainer : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014-2018, Tomasz Sowa
|
* Copyright (c) 2014-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
#include "utf8/utf8.h"
|
#include "utf8/utf8.h"
|
||||||
#include "date/date.h"
|
#include "date/date.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "convert/text.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
@@ -48,8 +49,8 @@ namespace Winix
|
|||||||
|
|
||||||
SessionIdManager::SessionIdManager()
|
SessionIdManager::SessionIdManager()
|
||||||
{
|
{
|
||||||
algorithm_type = 'a';
|
algorithm_type = ALGORITHM_MULTIPLE_KEYS;
|
||||||
key_tab_size = 256;
|
key_tab_size = 0;
|
||||||
key_index = 0;
|
key_index = 0;
|
||||||
last_key_generated = 0;
|
last_key_generated = 0;
|
||||||
key_renew_time = 60;
|
key_renew_time = 60;
|
||||||
@@ -57,9 +58,12 @@ SessionIdManager::SessionIdManager()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionIdManager::Init(const std::wstring & keys_file)
|
|
||||||
|
void SessionIdManager::InitMultipleKeys(const std::wstring & keys_file)
|
||||||
{
|
{
|
||||||
|
algorithm_type = ALGORITHM_MULTIPLE_KEYS;
|
||||||
was_inited = true;
|
was_inited = true;
|
||||||
|
key_tab_size = 256;
|
||||||
|
|
||||||
key_tab1.resize(key_tab_size);
|
key_tab1.resize(key_tab_size);
|
||||||
key_tab2.resize(key_tab_size);
|
key_tab2.resize(key_tab_size);
|
||||||
@@ -72,6 +76,57 @@ void SessionIdManager::Init(const std::wstring & keys_file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionIdManager::InitSingleKeys(const std::wstring & key1, const std::wstring & key2)
|
||||||
|
{
|
||||||
|
algorithm_type = ALGORITHM_SINGLE_KEYS;
|
||||||
|
key_tab_size = 1;
|
||||||
|
|
||||||
|
key_tab1.resize(key_tab_size);
|
||||||
|
key_tab2.resize(key_tab_size);
|
||||||
|
|
||||||
|
aes1.resize(key_tab_size);
|
||||||
|
aes2.resize(key_tab_size);
|
||||||
|
|
||||||
|
was_inited = true;
|
||||||
|
was_inited = was_inited && InitializeKey(key1, key_tab1);
|
||||||
|
was_inited = was_inited && InitializeKey(key2, key_tab2);
|
||||||
|
|
||||||
|
if( was_inited )
|
||||||
|
{
|
||||||
|
InitializeAesKeys();
|
||||||
|
}
|
||||||
|
|
||||||
|
return was_inited;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionIdManager::IsInitialized()
|
||||||
|
{
|
||||||
|
return was_inited;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionIdManager::InitializeKey(const std::wstring & key, std::vector<std::string> & key_tab)
|
||||||
|
{
|
||||||
|
if( key.size() == 16 * 2 || key.size() == 24 * 2 || key.size() == 32 * 2 )
|
||||||
|
{
|
||||||
|
if( !pt::hex_string_to_bytes(key, key_tab[0]) )
|
||||||
|
{
|
||||||
|
log << log1 << "SIM: an incorrect character in a key, expected a hex digits in the range 0-9 or a-f" << logend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log1 << "SIM: provided key has size: " << key.size()
|
||||||
|
<< ", expected size is 16, 24 or 32 bytes (written as two hex digits each)" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionIdManager::SetKeyRenewTime(time_t renew_time)
|
void SessionIdManager::SetKeyRenewTime(time_t renew_time)
|
||||||
{
|
{
|
||||||
key_renew_time = renew_time;
|
key_renew_time = renew_time;
|
||||||
@@ -86,12 +141,12 @@ void SessionIdManager::SetKeyRenewTime(time_t renew_time)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionIdManager::ReadKey(const wchar_t * name, PT::Space & space, std::vector<std::string> & dest_key)
|
void SessionIdManager::ReadKey(const wchar_t * name, pt::Space & space, std::vector<std::string> & dest_key)
|
||||||
{
|
{
|
||||||
std::vector<std::wstring> keys;
|
std::vector<std::wstring> keys;
|
||||||
std::string key_ascii, key_base64_decoded;
|
std::string key_ascii, key_base64_decoded;
|
||||||
|
|
||||||
space.ListText(name, keys);
|
space.to_list(name, keys);
|
||||||
|
|
||||||
for(size_t i=0 ; i<key_tab_size ; ++i)
|
for(size_t i=0 ; i<key_tab_size ; ++i)
|
||||||
dest_key[i].clear();
|
dest_key[i].clear();
|
||||||
@@ -100,7 +155,7 @@ std::string key_ascii, key_base64_decoded;
|
|||||||
{
|
{
|
||||||
dest_key[i].clear();
|
dest_key[i].clear();
|
||||||
|
|
||||||
if( PT::WideToUTF8(keys[i], key_ascii) )
|
if( pt::wide_to_utf8(keys[i], key_ascii) )
|
||||||
{
|
{
|
||||||
if( base64.Decode(key_ascii, key_base64_decoded) )
|
if( base64.Decode(key_ascii, key_base64_decoded) )
|
||||||
{
|
{
|
||||||
@@ -140,21 +195,20 @@ void SessionIdManager::InitializeAesKeys()
|
|||||||
|
|
||||||
bool SessionIdManager::ReadKeysFromFile(const wchar_t * file)
|
bool SessionIdManager::ReadKeysFromFile(const wchar_t * file)
|
||||||
{
|
{
|
||||||
PT::Space space;
|
pt::Space space;
|
||||||
PT::SpaceParser parser;
|
pt::SpaceParser parser;
|
||||||
PT::Date date;
|
pt::Date date;
|
||||||
|
|
||||||
parser.SetSpace(space);
|
pt::SpaceParser::Status status = parser.parse_space_file(file, space);
|
||||||
PT::SpaceParser::Status status = parser.Parse(file);
|
|
||||||
|
|
||||||
if( status == PT::SpaceParser::ok )
|
if( status == pt::SpaceParser::ok )
|
||||||
{
|
{
|
||||||
key_index = space.Size(L"key_index");
|
key_index = space.to_ulong(L"key_index");
|
||||||
|
|
||||||
if( key_index >= 256 )
|
if( key_index >= 256 )
|
||||||
key_index = 0;
|
key_index = 0;
|
||||||
|
|
||||||
if( date.Parse(space.Text(L"last_key_generated", L"0")) )
|
if( date.Parse(space.to_wstr(L"last_key_generated", L"0")) )
|
||||||
last_key_generated = date.ToTime();
|
last_key_generated = date.ToTime();
|
||||||
|
|
||||||
ReadKey(L"key_tab1", space, key_tab1);
|
ReadKey(L"key_tab1", space, key_tab1);
|
||||||
@@ -166,7 +220,7 @@ PT::Date date;
|
|||||||
log << log1 << "SIM: I cannot read the session keys from: " << file << logend;
|
log << log1 << "SIM: I cannot read the session keys from: " << file << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status == PT::SpaceParser::ok;
|
return status == pt::SpaceParser::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -196,8 +250,8 @@ void SessionIdManager::SaveKeysToFile(std::vector<std::string> & keys)
|
|||||||
|
|
||||||
bool SessionIdManager::SaveKeysToFile(const wchar_t * file)
|
bool SessionIdManager::SaveKeysToFile(const wchar_t * file)
|
||||||
{
|
{
|
||||||
PT::Date date = last_key_generated;
|
pt::Date date = last_key_generated;
|
||||||
PT::WideToUTF8(file, file_name_ascii);
|
pt::wide_to_utf8(file, file_name_ascii);
|
||||||
|
|
||||||
out_file.clear();
|
out_file.clear();
|
||||||
out_file.open(file_name_ascii, std::ios_base::binary | std::ios_base::out);
|
out_file.open(file_name_ascii, std::ios_base::binary | std::ios_base::out);
|
||||||
@@ -379,6 +433,18 @@ void SessionIdManager::CopyString(const std::wstring & in, std::string & out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionIdManager::CopyString(const std::wstring_view & in, std::string & out)
|
||||||
|
{
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
if( out.capacity() < in.size() )
|
||||||
|
out.reserve(in.size());
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<in.size() ; ++i)
|
||||||
|
out += in[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SessionIdManager::Encode(std::string & str)
|
bool SessionIdManager::Encode(std::string & str)
|
||||||
{
|
{
|
||||||
@@ -401,6 +467,7 @@ return true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SessionIdManager::EncodeToken(size_t id, unsigned int index, time_t cur_utc_time, std::wstring & token)
|
bool SessionIdManager::EncodeToken(size_t id, unsigned int index, time_t cur_utc_time, std::wstring & token)
|
||||||
{
|
{
|
||||||
size_t pad_top_size;
|
size_t pad_top_size;
|
||||||
@@ -414,10 +481,14 @@ char pad_bottom_value;
|
|||||||
if( !was_inited )
|
if( !was_inited )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CheckKeys(cur_utc_time);
|
if( algorithm_type == ALGORITHM_MULTIPLE_KEYS )
|
||||||
|
{
|
||||||
|
CheckKeys(cur_utc_time);
|
||||||
|
}
|
||||||
|
|
||||||
RandPadding(pad_top_size, pad_top_value, pad_bottom_size, pad_bottom_value);
|
RandPadding(pad_top_size, pad_top_value, pad_bottom_size, pad_bottom_value);
|
||||||
|
|
||||||
string_token += algorithm_type;
|
string_token += GetAlgoritmTypeAsString();
|
||||||
string_token += (unsigned char)key_index;
|
string_token += (unsigned char)key_index;
|
||||||
string_token += pad_top_value;
|
string_token += pad_top_value;
|
||||||
string_token += pad_bottom_value;
|
string_token += pad_bottom_value;
|
||||||
@@ -489,17 +560,14 @@ return true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SessionIdManager::DecodeTokenA(size_t & id, unsigned int & index)
|
bool SessionIdManager::DecodeToken(size_t key, size_t & id, unsigned int & index)
|
||||||
{
|
{
|
||||||
size_t pad_top_size;
|
size_t pad_top_size;
|
||||||
size_t pad_bottom_size;
|
size_t pad_bottom_size;
|
||||||
char pad_top_value;
|
char pad_top_value;
|
||||||
char pad_bottom_value;
|
char pad_bottom_value;
|
||||||
|
|
||||||
const char * str = string_token.c_str() + 1;
|
const char * str = string_token.c_str() + 2;
|
||||||
size_t key = (unsigned char)(*str);
|
|
||||||
|
|
||||||
str += 1;
|
|
||||||
|
|
||||||
if( !DecodeAES(str, key) )
|
if( !DecodeAES(str, key) )
|
||||||
return false;
|
return false;
|
||||||
@@ -533,8 +601,31 @@ return CheckControlSums(str);
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionIdManager::DecodeToken(size_t & id, unsigned int & index)
|
||||||
|
{
|
||||||
|
size_t key = 0;
|
||||||
|
|
||||||
bool SessionIdManager::DecodeToken(const std::wstring & token, size_t & id, unsigned int & index)
|
if( string_token[0] == 'a' )
|
||||||
|
{
|
||||||
|
// it is ALGORITHM_MULTIPLE_KEYS
|
||||||
|
key = (unsigned char)string_token[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( string_token[0] == 'b' )
|
||||||
|
{
|
||||||
|
// it is ALGORITHM_SINGLE_KEYS
|
||||||
|
key = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DecodeToken(key, id, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionIdManager::DecodeToken(const std::wstring_view & token, size_t & id, unsigned int & index)
|
||||||
{
|
{
|
||||||
if( !was_inited )
|
if( !was_inited )
|
||||||
return false;
|
return false;
|
||||||
@@ -547,13 +638,21 @@ bool SessionIdManager::DecodeToken(const std::wstring & token, size_t & id, unsi
|
|||||||
if( string_token.size() != 34 )
|
if( string_token.size() != 34 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( string_token[0] == 'a' )
|
return DecodeToken(id, index);
|
||||||
return DecodeTokenA(id, index);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char SessionIdManager::GetAlgoritmTypeAsString()
|
||||||
|
{
|
||||||
|
if( algorithm_type == ALGORITHM_MULTIPLE_KEYS )
|
||||||
|
return 'a';
|
||||||
|
|
||||||
|
if( algorithm_type == ALGORITHM_SINGLE_KEYS )
|
||||||
|
return 'b';
|
||||||
|
|
||||||
|
return 'a';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
} // namespace Winix
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014-2018, Tomasz Sowa
|
* Copyright (c) 2014-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -83,30 +83,63 @@ public:
|
|||||||
SessionIdManager();
|
SessionIdManager();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* initialization
|
* we are using keys stored in a file
|
||||||
|
* those keys are automatically generated
|
||||||
|
* this is the default algorithm
|
||||||
|
*/
|
||||||
|
static const int ALGORITHM_MULTIPLE_KEYS = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we use only two keys
|
||||||
|
* those keys you have to provide
|
||||||
|
*/
|
||||||
|
static const int ALGORITHM_SINGLE_KEYS = 2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* initialization for ALGORITHM_MULTIPLE_KEYS algorithm
|
||||||
* this method takes about 1MB memory more (for AES key expansions)
|
* this method takes about 1MB memory more (for AES key expansions)
|
||||||
* if you do not need the session cookie to be enrypted then don't call this method
|
* if you do not need the session cookie to be enrypted then don't call this method
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void Init(const std::wstring & keys_file);
|
void InitMultipleKeys(const std::wstring & keys_file);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* initialization for ALGORITHM_SINGLE_KEYS algorithm
|
||||||
|
* keys should be provided as 16*2 or 24*2 or 32*2 hexadecimal characters
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool InitSingleKeys(const std::wstring & key1, const std::wstring & key2);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* true if the object is correctly initialized
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool IsInitialized();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* how often a new AES key pairs should be generated
|
* how often a new AES key pairs should be generated
|
||||||
|
* used with ALGORITHM_MULTIPLE_KEYS algorithm
|
||||||
*/
|
*/
|
||||||
void SetKeyRenewTime(time_t renew_time);
|
void SetKeyRenewTime(time_t renew_time);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* encode/decode the session cookie
|
* encode/decode the session cookie
|
||||||
* make sure the Init() method is called first
|
* make sure InitMultipleKeys() or InitSingleKeys() method is called first
|
||||||
|
*
|
||||||
|
* for ALGORITHM_SINGLE_KEYS algorithm the cur_utc_time parameter is ignored
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
bool EncodeToken(size_t id, unsigned int index, time_t cur_utc_time, std::wstring & token);
|
bool EncodeToken(size_t id, unsigned int index, time_t cur_utc_time, std::wstring & token);
|
||||||
bool DecodeToken(const std::wstring & token, size_t & id, unsigned int & index);
|
bool DecodeToken(const std::wstring_view & token, size_t & id, unsigned int & index);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool was_inited;
|
bool was_inited;
|
||||||
char algorithm_type;
|
int algorithm_type;
|
||||||
std::string string_token, string_token_base64;
|
std::string string_token, string_token_base64;
|
||||||
std::vector<std::string> key_tab1, key_tab2;
|
std::vector<std::string> key_tab1, key_tab2;
|
||||||
size_t key_index;
|
size_t key_index;
|
||||||
@@ -120,11 +153,12 @@ private:
|
|||||||
std::string file_name_ascii;
|
std::string file_name_ascii;
|
||||||
std::vector<Tito::AES> aes1, aes2;
|
std::vector<Tito::AES> aes1, aes2;
|
||||||
|
|
||||||
|
bool InitializeKey(const std::wstring & key, std::vector<std::string> & key_tab);
|
||||||
bool ReadKeysFromFile(const wchar_t * file);
|
bool ReadKeysFromFile(const wchar_t * file);
|
||||||
bool ReadKeysFromFile(const std::wstring & file);
|
bool ReadKeysFromFile(const std::wstring & file);
|
||||||
bool SaveKeysToFile(const wchar_t * file);
|
bool SaveKeysToFile(const wchar_t * file);
|
||||||
bool SaveKeysToFile(const std::wstring & file);
|
bool SaveKeysToFile(const std::wstring & file);
|
||||||
void ReadKey(const wchar_t * name, PT::Space & space, std::vector<std::string> & dest_key);
|
void ReadKey(const wchar_t * name, pt::Space & space, std::vector<std::string> & dest_key);
|
||||||
bool AreKeysCorrect(size_t index);
|
bool AreKeysCorrect(size_t index);
|
||||||
void GenerateKeys(size_t index, time_t cur_utc_time);
|
void GenerateKeys(size_t index, time_t cur_utc_time);
|
||||||
void CheckKeys(time_t cur_utc_time);
|
void CheckKeys(time_t cur_utc_time);
|
||||||
@@ -136,12 +170,15 @@ private:
|
|||||||
void AppendXor(std::string & str);
|
void AppendXor(std::string & str);
|
||||||
void CopyString(const std::string & in, std::wstring & out);
|
void CopyString(const std::string & in, std::wstring & out);
|
||||||
void CopyString(const std::wstring & in, std::string & out);
|
void CopyString(const std::wstring & in, std::string & out);
|
||||||
|
void CopyString(const std::wstring_view & in, std::string & out);
|
||||||
bool Encode(std::string & str);
|
bool Encode(std::string & str);
|
||||||
bool DecodeTokenA(size_t & id, unsigned int & index);
|
bool DecodeToken(size_t key, size_t & id, unsigned int & index);
|
||||||
|
bool DecodeToken(size_t & id, unsigned int & index);
|
||||||
bool IsPaddingCorrect(const char * str, size_t len, char val);
|
bool IsPaddingCorrect(const char * str, size_t len, char val);
|
||||||
bool CheckControlSums(const char * str);
|
bool CheckControlSums(const char * str);
|
||||||
void InitializeAesKeys(size_t index);
|
void InitializeAesKeys(size_t index);
|
||||||
bool DecodeAES(const char * str, size_t key);
|
bool DecodeAES(const char * str, size_t key);
|
||||||
|
char GetAlgoritmTypeAsString();
|
||||||
|
|
||||||
template<typename Value>
|
template<typename Value>
|
||||||
void Append(std::string & str, Value val);
|
void Append(std::string & str, Value val);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2019, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -35,11 +35,13 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "sessionmanager.h"
|
#include "sessionmanager.h"
|
||||||
|
#include "core/misc.h"
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "sessionparser.h"
|
#include "sessionparser.h"
|
||||||
#include "functions/functionbase.h"
|
#include "functions/functionbase.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -89,9 +91,9 @@ void SessionManager::SetLastContainer(LastContainer * plast_container)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::set_dependency(WinixModel * winix_model)
|
void SessionManager::set_dependency(WinixModelDeprecated * winix_model)
|
||||||
{
|
{
|
||||||
WinixModel::set_dependency(winix_model);
|
WinixModelDeprecated::set_dependency(winix_model);
|
||||||
session_tab.set_dependency(winix_model);
|
session_tab.set_dependency(winix_model);
|
||||||
session_id_manager.set_dependency(winix_model);
|
session_id_manager.set_dependency(winix_model);
|
||||||
}
|
}
|
||||||
@@ -107,7 +109,7 @@ void SessionManager::InitBanList()
|
|||||||
void SessionManager::InitCookieEncoding()
|
void SessionManager::InitCookieEncoding()
|
||||||
{
|
{
|
||||||
if( config->session_cookie_encode && !config->session_keys_file.empty() )
|
if( config->session_cookie_encode && !config->session_keys_file.empty() )
|
||||||
session_id_manager.Init(config->session_keys_file);
|
session_id_manager.InitMultipleKeys(config->session_keys_file);
|
||||||
|
|
||||||
session_id_manager.SetKeyRenewTime(config->session_key_renew_time);
|
session_id_manager.SetKeyRenewTime(config->session_key_renew_time);
|
||||||
}
|
}
|
||||||
@@ -241,7 +243,7 @@ void SessionManager::SetSessionPutLogInfo(Session & ses, bool has_index, unsigne
|
|||||||
main_log << ", index difference: " << (size_t)difference;
|
main_log << ", index difference: " << (size_t)difference;
|
||||||
|
|
||||||
if( ses.puser )
|
if( ses.puser )
|
||||||
main_log << log2 << ", user: " << ses.puser->name << ", id: " << ses.puser->id;
|
main_log << log2 << ", user: " << ses.puser->login << ", id: " << ses.puser->id;
|
||||||
|
|
||||||
main_log << log2 << logend;
|
main_log << log2 << logend;
|
||||||
}
|
}
|
||||||
@@ -256,7 +258,7 @@ void SessionManager::IncrementBanLevel(IPBan * ip_ban)
|
|||||||
cur->request->start_time + (time_t)config->ban_level_2_delay,
|
cur->request->start_time + (time_t)config->ban_level_2_delay,
|
||||||
cur->request->start_time + (time_t)config->ban_level_3_delay);
|
cur->request->start_time + (time_t)config->ban_level_3_delay);
|
||||||
|
|
||||||
PT::Date date(ip_ban->expires);
|
pt::Date date(ip_ban->expires);
|
||||||
main_log << log2 << "SM: this IP address has been banned to: " << date << " UTC" << logend;
|
main_log << log2 << "SM: this IP address has been banned to: " << date << " UTC" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,7 +446,7 @@ bool SessionManager::IsIPBanned()
|
|||||||
else
|
else
|
||||||
if( current_ip_ban->IsIPBanned() )
|
if( current_ip_ban->IsIPBanned() )
|
||||||
{
|
{
|
||||||
PT::Date date = current_ip_ban->expires;
|
pt::Date date = current_ip_ban->expires;
|
||||||
main_log << log2 << "SM: this ip is bannned to: " << date << " UTC" << logend;
|
main_log << log2 << "SM: this ip is bannned to: " << date << " UTC" << logend;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -474,31 +476,34 @@ Session * SessionManager::PrepareSession()
|
|||||||
{
|
{
|
||||||
session = nullptr;
|
session = nullptr;
|
||||||
|
|
||||||
if( !IsIPBanned() )
|
if( config->use_internal_session_mechanism )
|
||||||
{
|
{
|
||||||
CookieTab::iterator i = cur->request->cookie_tab.find(config->http_session_id_name);
|
if( !IsIPBanned() )
|
||||||
|
|
||||||
if( i != cur->request->cookie_tab.end() )
|
|
||||||
{
|
{
|
||||||
if( !SetSessionFromCookie(i->second) )
|
CookieTab::iterator i = cur->request->cookie_tab.find(config->session_cookie_name);
|
||||||
|
|
||||||
|
if( i != cur->request->cookie_tab.end() )
|
||||||
{
|
{
|
||||||
cur->request->cookie_tab.erase(i);
|
if( !SetSessionFromCookie(i->second) )
|
||||||
|
{
|
||||||
|
cur->request->cookie_tab.erase(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( cur->request->function && cur->request->function->need_session )
|
||||||
|
{
|
||||||
|
NoSessionCookieWasSent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if( cur->request->function && cur->request->function->need_session )
|
|
||||||
{
|
|
||||||
NoSessionCookieWasSent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !session && cur->request->function && cur->request->function->need_session )
|
if( !session && cur->request->function && cur->request->function->need_session )
|
||||||
{
|
|
||||||
if( !current_ip_ban || !current_ip_ban->IsIPBanned() )
|
|
||||||
{
|
{
|
||||||
CreateSession();
|
if( !current_ip_ban || !current_ip_ban->IsIPBanned() )
|
||||||
|
{
|
||||||
|
CreateSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,14 +520,17 @@ Session * SessionManager::PrepareSession()
|
|||||||
|
|
||||||
Session * SessionManager::CheckIfFunctionRequireSession()
|
Session * SessionManager::CheckIfFunctionRequireSession()
|
||||||
{
|
{
|
||||||
if( cur->request->function && cur->request->function->need_session )
|
if( config->use_internal_session_mechanism )
|
||||||
{
|
{
|
||||||
if( session == &temporary_session )
|
if( cur->request->function && cur->request->function->need_session )
|
||||||
{
|
{
|
||||||
if( !current_ip_ban || !current_ip_ban->IsIPBanned() )
|
if( session == &temporary_session )
|
||||||
{
|
{
|
||||||
CreateSession();
|
if( !current_ip_ban || !current_ip_ban->IsIPBanned() )
|
||||||
session->ip_ban = current_ip_ban;
|
{
|
||||||
|
CreateSession();
|
||||||
|
session->ip_ban = current_ip_ban;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -558,7 +566,7 @@ SessionContainer::Iterator SessionManager::SessionEnd()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// called from the main thread (from App::Close)
|
||||||
void SessionManager::DeleteSessions()
|
void SessionManager::DeleteSessions()
|
||||||
{
|
{
|
||||||
SessionContainer::Iterator i;
|
SessionContainer::Iterator i;
|
||||||
@@ -567,7 +575,7 @@ void SessionManager::DeleteSessions()
|
|||||||
{
|
{
|
||||||
if( i->puser && !i->remember_me )
|
if( i->puser && !i->remember_me )
|
||||||
{
|
{
|
||||||
plugin->Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_PREPARE_USER_TO_LOGOUT, i->puser, nullptr, 0, 0);
|
||||||
last_container->UserLogout(i->puser->id, i->id);
|
last_container->UserLogout(i->puser->id, i->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -599,7 +607,7 @@ SessionContainer::Iterator i = session_tab.FindById(old_id);
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( changed )
|
if( changed )
|
||||||
plugin->Call(&(*i), WINIX_SESSION_CHANGED_ID, old_id, new_id);
|
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_SESSION_CHANGED_ID, nullptr, nullptr, old_id, new_id);
|
||||||
else
|
else
|
||||||
main_log << log1 << "SM: I cannot create a new session id (still uses old one)" << logend;
|
main_log << log1 << "SM: I cannot create a new session id (still uses old one)" << logend;
|
||||||
}
|
}
|
||||||
@@ -612,19 +620,20 @@ return changed;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// called from the main thread (from App::Init)
|
||||||
void SessionManager::InitTmpSession()
|
void SessionManager::InitTmpSession()
|
||||||
{
|
{
|
||||||
Session * old_session = cur->session;
|
Session * old_session = cur->session;
|
||||||
|
|
||||||
main_log << log4 << "SM: initializing temporary session" << logend;
|
main_log << log4 << "SM: initializing temporary session" << logend;
|
||||||
cur->session = &temporary_session;
|
cur->session = &temporary_session;
|
||||||
plugin->Call(WINIX_SESSION_CREATED);
|
plugin->Call(main_model_connector, &main_log, nullptr, WINIX_SESSION_CREATED);
|
||||||
|
|
||||||
cur->session = old_session;
|
cur->session = old_session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// called from the main thread at the and (from App::Close)
|
||||||
void SessionManager::UninitTmpSession()
|
void SessionManager::UninitTmpSession()
|
||||||
{
|
{
|
||||||
Session * old_session = cur->session;
|
Session * old_session = cur->session;
|
||||||
@@ -635,43 +644,52 @@ void SessionManager::UninitTmpSession()
|
|||||||
|
|
||||||
if( cur->session->plugin_data.HasAllocatedData() )
|
if( cur->session->plugin_data.HasAllocatedData() )
|
||||||
{
|
{
|
||||||
plugin->Call(cur->session, WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
plugin->Call(main_model_connector, &main_log, cur->session, nullptr, nullptr, WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
//cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
||||||
|
|
||||||
cur->session->plugin_data.Resize(0);
|
cur->session->plugin_data.Resize(0);
|
||||||
|
|
||||||
cur->session = old_session;
|
cur->session = old_session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// called from the main thread (from App::Init)
|
||||||
void SessionManager::LoadSessions()
|
void SessionManager::LoadSessions()
|
||||||
{
|
{
|
||||||
SessionParser sp;
|
SessionParser sp;
|
||||||
SessionContainer::Iterator i;
|
SessionContainer::Iterator i;
|
||||||
|
|
||||||
sp.set_dependency(this);
|
if( config->use_internal_session_mechanism )
|
||||||
|
|
||||||
// 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());
|
if( !config->session_file.empty() )
|
||||||
plugin->Call(&(*i), WINIX_SESSION_CREATED);
|
{
|
||||||
|
sp.set_dependency(this);
|
||||||
|
|
||||||
/*
|
// sessions will be overwritten (pointers are invalidated)
|
||||||
!! IMPROVE ME
|
cur->session = &temporary_session;
|
||||||
we do not add it to the last_container (we don't have IP address stored yet)
|
|
||||||
*/
|
|
||||||
|
|
||||||
if( i->puser )
|
sp.SetUsers(&system->users);
|
||||||
plugin->Call(&(*i), WINIX_USER_LOGGED);
|
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(main_model_connector, &main_log, &(*i), nullptr, nullptr, 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(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_USER_LOGGED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// FIXME this log is not printed, why?
|
||||||
|
main_log << log1 << "SM: session_file config parameter is empty, not loading sessions" << logend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur->session = &temporary_session;
|
cur->session = &temporary_session;
|
||||||
@@ -685,10 +703,18 @@ void SessionManager::SaveSessions()
|
|||||||
{
|
{
|
||||||
char file_path[WINIX_OS_PATH_SIZE];
|
char file_path[WINIX_OS_PATH_SIZE];
|
||||||
|
|
||||||
if( config->session_file.empty() )
|
if( !config->use_internal_session_mechanism )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if( !WideToUTF8(config->session_file, file_path, WINIX_OS_PATH_SIZE) )
|
if( config->session_file.empty() )
|
||||||
|
{
|
||||||
|
main_log << log1 << "SM: session_file config parameter is empty, not saving sessions - sessions lost" << logend;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !pt::wide_to_utf8(config->session_file, (char*)file_path, WINIX_OS_PATH_SIZE) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::ofstream file(file_path);
|
std::ofstream file(file_path);
|
||||||
@@ -747,7 +773,7 @@ size_t SessionManager::MarkAllSessionsToRemove(long user_id)
|
|||||||
{
|
{
|
||||||
if( i->puser && i->puser->id == user_id )
|
if( i->puser && i->puser->id == user_id )
|
||||||
{
|
{
|
||||||
plugin->Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
||||||
last_container->UserLogout(i->puser->id, i->id);
|
last_container->UserLogout(i->puser->id, i->id);
|
||||||
i->remove_me = true;
|
i->remove_me = true;
|
||||||
i->puser = 0;
|
i->puser = 0;
|
||||||
@@ -860,7 +886,7 @@ const int deleted_max_at_once = 10;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( i->remove_me || IsSessionOutdated(*i) )
|
if( i->allow_to_delete && (i->remove_me || IsSessionOutdated(*i)) )
|
||||||
{
|
{
|
||||||
Session * ses = &(*i);
|
Session * ses = &(*i);
|
||||||
++i;
|
++i;
|
||||||
@@ -906,16 +932,16 @@ void SessionManager::DeleteSession(Session * del_session)
|
|||||||
{
|
{
|
||||||
if( del_session->puser )
|
if( del_session->puser )
|
||||||
{
|
{
|
||||||
plugin->Call(del_session, WINIX_PREPARE_USER_TO_LOGOUT, del_session->puser);
|
plugin->Call(model_connector, &log, del_session, nullptr, nullptr, WINIX_PREPARE_USER_TO_LOGOUT, del_session->puser, nullptr, 0, 0);
|
||||||
last_container->UserLogout(del_session->puser->id, del_session->id);
|
last_container->UserLogout(del_session->puser->id, del_session->id);
|
||||||
del_session->puser = 0;
|
del_session->puser = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long id = del_session->id;
|
long id = del_session->id;
|
||||||
|
|
||||||
plugin->Call(del_session, WINIX_PREPARE_SESSION_TO_REMOVE);
|
plugin->Call(model_connector, &log, del_session, nullptr, nullptr, WINIX_PREPARE_SESSION_TO_REMOVE, del_session->puser, nullptr, 0, 0);
|
||||||
session_tab.EraseById(del_session->id);
|
session_tab.EraseById(del_session->id);
|
||||||
plugin->Call((Session*)0, WINIX_SESSION_REMOVED, id);
|
plugin->Call(model_connector, &log, nullptr, WINIX_SESSION_REMOVED, nullptr, nullptr, id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2019, Tomasz Sowa
|
* Copyright (c) 2008-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -43,7 +43,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "lastcontainer.h"
|
#include "lastcontainer.h"
|
||||||
#include "system.h"
|
|
||||||
#include "synchro.h"
|
#include "synchro.h"
|
||||||
#include "basethread.h"
|
#include "basethread.h"
|
||||||
#include "sessionidmanager.h"
|
#include "sessionidmanager.h"
|
||||||
@@ -65,7 +64,7 @@ public:
|
|||||||
void SetSystem(System * psystem);
|
void SetSystem(System * psystem);
|
||||||
void SetLastContainer(LastContainer * plast_container);
|
void SetLastContainer(LastContainer * plast_container);
|
||||||
|
|
||||||
void set_dependency(WinixModel * winix_model);
|
void set_dependency(WinixModelDeprecated * winix_model);
|
||||||
|
|
||||||
// can return a null pointer
|
// can return a null pointer
|
||||||
Session * FindSession(long id);
|
Session * FindSession(long id);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
* Copyright (c) 2008-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -60,7 +60,7 @@ char file_path[WINIX_OS_PATH_SIZE];
|
|||||||
|
|
||||||
container.Clear();
|
container.Clear();
|
||||||
|
|
||||||
if( !WideToUTF8(path, file_path, WINIX_OS_PATH_SIZE) )
|
if( !pt::wide_to_utf8(path, (char*)file_path, WINIX_OS_PATH_SIZE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
file.open(file_path, std::ios_base::in | std::ios_base::binary);
|
file.open(file_path, std::ios_base::in | std::ios_base::binary);
|
||||||
@@ -135,7 +135,7 @@ void SessionParser::MakeSession(long id, long user_id, SessionContainer & contai
|
|||||||
// !! IMPROVE ME we do not save last_time_get
|
// !! IMPROVE ME we do not save last_time_get
|
||||||
|
|
||||||
users->IncrementLoggedUsers();
|
users->IncrementLoggedUsers();
|
||||||
log << log2 << "SP: read session id: " << id << " for user: " << puser->name << logend;
|
log << log2 << "SP: read session id: " << id << " for user: " << puser->login << logend;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,257 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is distributed under the 2-Clause BSD licence.
|
|
||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "slog.h"
|
|
||||||
#include "utf8/utf8.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog::SLog()
|
|
||||||
{
|
|
||||||
cur = 0;
|
|
||||||
locale = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SLog::SetCur(Cur * pcur)
|
|
||||||
{
|
|
||||||
cur = pcur;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SLog::SetLocale(Locale * plocale)
|
|
||||||
{
|
|
||||||
locale = plocale;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const void * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const char * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::string * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::string & s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const wchar_t * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::wstring * s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const std::wstring & s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(int s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(long s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(char s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(wchar_t s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(size_t s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(double s)
|
|
||||||
{
|
|
||||||
return PutLog(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const PT::Date & date)
|
|
||||||
{
|
|
||||||
return PutLog(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(LogManipulators m)
|
|
||||||
{
|
|
||||||
if( cur && cur->session )
|
|
||||||
{
|
|
||||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
|
||||||
|
|
||||||
switch(m)
|
|
||||||
{
|
|
||||||
case logend:
|
|
||||||
buf << '\n';
|
|
||||||
|
|
||||||
if( buf.Size() > WINIX_SLOG_MAX_LOG_SIZE )
|
|
||||||
{
|
|
||||||
buf.Clear();
|
|
||||||
(*this) << logwarning << T("slog_turn_over") << " " << WINIX_SLOG_MAX_LOG_SIZE << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case loginfo:
|
|
||||||
case logwarning:
|
|
||||||
case logerror:
|
|
||||||
buf << (wchar_t)(int)m;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::TranslateText(const char * str)
|
|
||||||
{
|
|
||||||
PT::UTF8ToWide(str, key_temp);
|
|
||||||
return TranslateText(key_temp.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::TranslateText(const wchar_t * str)
|
|
||||||
{
|
|
||||||
if( cur && cur->session )
|
|
||||||
{
|
|
||||||
const std::wstring * trans = 0;
|
|
||||||
|
|
||||||
if( locale )
|
|
||||||
trans = &locale->Get(str);
|
|
||||||
|
|
||||||
// !! IMPROVE ME "Not translated" add to locale
|
|
||||||
if( !trans || trans->empty() )
|
|
||||||
cur->session->log_buffer << "Not translated: " << str;
|
|
||||||
else
|
|
||||||
cur->session->log_buffer << trans;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const TranslateTextHelper<const char*> & raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(const TranslateTextHelper<const wchar_t*> & raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<const std::string*> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<const std::wstring*> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par->c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<std::string> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SLog & SLog::operator<<(TranslateTextHelper<std::wstring> raw)
|
|
||||||
{
|
|
||||||
return TranslateText(raw.par.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is distributed under the 2-Clause BSD licence.
|
|
||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_slog
|
|
||||||
#define headerfile_winix_core_slog
|
|
||||||
|
|
||||||
#include "cur.h"
|
|
||||||
#include "logmanipulators.h"
|
|
||||||
#include "templates/locale.h"
|
|
||||||
#include "textstream/textstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WINIX_SLOG_MAX_LOG_SIZE 10240
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
session logger
|
|
||||||
|
|
||||||
sample:
|
|
||||||
#include "log.h" (or slog.h)
|
|
||||||
slog << logerror << "message" << "something" << logend;
|
|
||||||
slog << logwarning << T("message_to_translate") << x << logend;
|
|
||||||
|
|
||||||
if the latter example "message_to_translate" will be taken from locales
|
|
||||||
currently following manipulators are taken into account:
|
|
||||||
loginfo - the message in a normal info
|
|
||||||
logwarning - this is a warning
|
|
||||||
logerror - this is an error
|
|
||||||
logend - end of a line -- we have one kind of a message (info, warning, error) per line
|
|
||||||
|
|
||||||
loginfo, logwarning, logerror should be specified at the beginning of a line
|
|
||||||
(other manipulators are skipped)
|
|
||||||
*/
|
|
||||||
class SLog
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
SLog();
|
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
|
||||||
void SetLocale(Locale * plocale);
|
|
||||||
|
|
||||||
template<class RawType>
|
|
||||||
struct TranslateTextHelper
|
|
||||||
{
|
|
||||||
const RawType & par;
|
|
||||||
|
|
||||||
TranslateTextHelper(const TranslateTextHelper<RawType> & p) : par(p.par) {}
|
|
||||||
TranslateTextHelper(const RawType & p) : par(p) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
SLog & operator<<(const void * s);
|
|
||||||
SLog & operator<<(const char * s);
|
|
||||||
SLog & operator<<(const std::string * s);
|
|
||||||
SLog & operator<<(const std::string & s);
|
|
||||||
SLog & operator<<(const wchar_t * s);
|
|
||||||
SLog & operator<<(const std::wstring * s);
|
|
||||||
SLog & operator<<(const std::wstring & s);
|
|
||||||
SLog & operator<<(int s);
|
|
||||||
SLog & operator<<(long s);
|
|
||||||
SLog & operator<<(char s);
|
|
||||||
SLog & operator<<(wchar_t s);
|
|
||||||
SLog & operator<<(size_t s);
|
|
||||||
SLog & operator<<(double s);
|
|
||||||
SLog & operator<<(LogManipulators m);
|
|
||||||
SLog & operator<<(const PT::Date & date);
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
||||||
SLog & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
|
||||||
|
|
||||||
|
|
||||||
SLog & TranslateText(const char * str);
|
|
||||||
SLog & TranslateText(const wchar_t * str);
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const char [str_size]> & raw) { return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
template<size_t str_size>
|
|
||||||
SLog & operator<<(const TranslateTextHelper<wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
|
||||||
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const char*> & raw);
|
|
||||||
SLog & operator<<(const TranslateTextHelper<const wchar_t*> & raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<const std::string*> raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<const std::wstring*> raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<std::string> raw);
|
|
||||||
SLog & operator<<(TranslateTextHelper<std::wstring> raw);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
template<class LogParam>
|
|
||||||
SLog & PutLog(const LogParam & par);
|
|
||||||
|
|
||||||
Cur * cur;
|
|
||||||
Locale * locale;
|
|
||||||
std::wstring key_temp;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<class RawType>
|
|
||||||
SLog::TranslateTextHelper<RawType> T(const RawType & par)
|
|
||||||
{
|
|
||||||
return SLog::TranslateTextHelper<RawType>(par);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
||||||
SLog & SLog::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
|
||||||
{
|
|
||||||
return PutLog(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class LogParam>
|
|
||||||
SLog & SLog::PutLog(const LogParam & par)
|
|
||||||
{
|
|
||||||
if( cur && cur->session )
|
|
||||||
cur->session->log_buffer << par;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+198
-140
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -58,12 +58,6 @@ void System::SetCur(Cur * pcur)
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
void System::SetDb(Db * pdb)
|
|
||||||
{
|
|
||||||
db = pdb;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//void System::SetSynchro(Synchro * psynchro)
|
//void System::SetSynchro(Synchro * psynchro)
|
||||||
//{
|
//{
|
||||||
// synchro = psynchro;
|
// synchro = psynchro;
|
||||||
@@ -81,13 +75,14 @@ void System::SetSessionManager(SessionManager * sm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void System::set_dependency(WinixModel * winix_model)
|
void System::set_dependency(WinixModelDeprecated * winix_model)
|
||||||
{
|
{
|
||||||
WinixModel::set_dependency(winix_model);
|
WinixModelDeprecated::set_dependency(winix_model);
|
||||||
|
|
||||||
dirs.set_dependency(this);
|
dirs.set_dependency(this);
|
||||||
mounts.set_dependency(this);
|
mounts.set_dependency(this);
|
||||||
users.set_dependency(this);
|
//users.set_dependency(this);
|
||||||
|
users.set_connector(model_connector);
|
||||||
groups.set_dependency(this);
|
groups.set_dependency(this);
|
||||||
rebus.set_dependency(this);
|
rebus.set_dependency(this);
|
||||||
load_avg.set_dependency(this);
|
load_avg.set_dependency(this);
|
||||||
@@ -123,28 +118,26 @@ void System::ReadTimeZones()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void System::Init()
|
bool System::Init()
|
||||||
{
|
{
|
||||||
//thread_manager.SetSynchro(synchro);
|
//thread_manager.SetSynchro(synchro);
|
||||||
thread_manager.Init();
|
thread_manager.Init();
|
||||||
|
|
||||||
dirs.SetDb(db);
|
|
||||||
dirs.SetCur(cur); // only one method is using cur, can be passed as a parameter to the method
|
dirs.SetCur(cur); // only one method is using cur, can be passed as a parameter to the method
|
||||||
dirs.SetNotify(¬ify);
|
dirs.SetNotify(¬ify);
|
||||||
dirs.ReadDirs();
|
dirs.ReadDirs();
|
||||||
|
|
||||||
mounts.SkipStaticDirs(config->dont_use_static_dirs);
|
mounts.SkipStaticDirs(config->dont_use_static_dirs);
|
||||||
mounts.SetDirs(&dirs);
|
mounts.SetDirs(&dirs);
|
||||||
mounts.SetDb(db);
|
|
||||||
mounts.SetCur(cur); // only one method is using cur, can be passed as a parameter to the method
|
|
||||||
mounts.CreateMounts();
|
mounts.CreateMounts();
|
||||||
mounts.ReadMounts();
|
mounts.ReadMounts();
|
||||||
|
|
||||||
users.SetCur(cur);
|
// users.SetCur(cur);
|
||||||
users.SetSessionManager(session_manager);
|
// users.SetSessionManager(session_manager);
|
||||||
users.ReadUsers(db);
|
users.set_connector(model_connector);
|
||||||
|
users.ReadUsers();
|
||||||
|
|
||||||
groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione
|
groups.ReadGroups();
|
||||||
|
|
||||||
rebus.SetCur(cur);
|
rebus.SetCur(cur);
|
||||||
rebus.Init();
|
rebus.Init();
|
||||||
@@ -155,21 +148,29 @@ void System::Init()
|
|||||||
notify.SetUsers(&users);
|
notify.SetUsers(&users);
|
||||||
notify.SetDirs(&dirs);
|
notify.SetDirs(&dirs);
|
||||||
notify.SetThreadManager(&thread_manager);
|
notify.SetThreadManager(&thread_manager);
|
||||||
notify.Init();
|
|
||||||
|
|
||||||
image.SetDb(db);
|
if( !notify.Init() )
|
||||||
|
return false;
|
||||||
|
|
||||||
image.SetConfig(config);
|
image.SetConfig(config);
|
||||||
image.SetSystem(this);
|
image.SetSystem(this);
|
||||||
thread_manager.Add(&image, L"image");
|
|
||||||
|
|
||||||
|
|
||||||
|
if( !thread_manager.Add(&image, L"image") )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
job.SetCur(cur);
|
||||||
|
job.SetFunctions(functions);
|
||||||
|
job.SetLoadAvg(&load_avg);
|
||||||
|
job.SetMounts(&mounts);
|
||||||
|
job.SetReqTab(&req_tab);
|
||||||
|
|
||||||
// SetSynchro will be called by ThreadManager itself
|
// SetSynchro will be called by ThreadManager itself
|
||||||
// job.ReadFromFile();
|
// job.ReadFromFile();
|
||||||
thread_manager.Add(&job, L"job");
|
if( !thread_manager.Add(&job, L"job") )
|
||||||
|
return false;
|
||||||
|
|
||||||
ReadTimeZones();
|
ReadTimeZones();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -219,7 +220,7 @@ void System::PutUrlProto(bool can_use_ssl, std::wstring & str, bool clear_str)
|
|||||||
/*
|
/*
|
||||||
* try_to_use_ssl is to be meant: config->use_ssl, config->use_ssl_static, config->use_ssl_common
|
* try_to_use_ssl is to be meant: config->use_ssl, config->use_ssl_static, config->use_ssl_common
|
||||||
*/
|
*/
|
||||||
void System::PutUrlProto(bool can_use_ssl, PT::TextStream & str, bool clear_stream)
|
void System::PutUrlProto(bool can_use_ssl, pt::Stream & str, bool clear_stream)
|
||||||
{
|
{
|
||||||
if( clear_stream )
|
if( clear_stream )
|
||||||
str.clear();
|
str.clear();
|
||||||
@@ -241,7 +242,7 @@ void System::PutUrlProto(std::wstring & str, bool clear_str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void System::PutUrlProto(PT::TextStream & str, bool clear_stream)
|
void System::PutUrlProto(pt::Stream & str, bool clear_stream)
|
||||||
{
|
{
|
||||||
return PutUrlProto(config->use_ssl, str, clear_stream);
|
return PutUrlProto(config->use_ssl, str, clear_stream);
|
||||||
}
|
}
|
||||||
@@ -337,14 +338,23 @@ void System::RedirectTo(long item_id, const wchar_t * postfix, bool use_reqtype)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// item_id is pointing to a file
|
// item_id is pointing to a file
|
||||||
DbItemQuery iq;
|
// DbItemQuery iq;
|
||||||
|
|
||||||
iq.SetAllSel(false);
|
// iq.SetAllSel(false);
|
||||||
iq.WhereId(item_id);
|
// iq.WhereId(item_id);
|
||||||
iq.sel_parent_id = true;
|
// iq.sel_parent_id = true;
|
||||||
iq.sel_url = true;
|
// iq.sel_url = true;
|
||||||
|
|
||||||
if( db->GetItem(item_temp, iq) == WINIX_ERR_OK )
|
morm::Finder<Item> finder(model_connector);
|
||||||
|
|
||||||
|
item_temp = finder.
|
||||||
|
select().
|
||||||
|
where().
|
||||||
|
eq(L"id", item_id).
|
||||||
|
get();
|
||||||
|
|
||||||
|
//if( db->GetItem(item_temp, iq) == WINIX_ERR_OK )
|
||||||
|
if( item_temp.found() )
|
||||||
{
|
{
|
||||||
if( dirs.MakePath(item_temp.parent_id, cur->request->redirect_to, false) )
|
if( dirs.MakePath(item_temp.parent_id, cur->request->redirect_to, false) )
|
||||||
cur->request->redirect_to += item_temp.url;
|
cur->request->redirect_to += item_temp.url;
|
||||||
@@ -524,11 +534,11 @@ bool System::CanChangeUser(const Item & item, long new_user_id)
|
|||||||
// session must be set
|
// session must be set
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( cur->session->puser && cur->session->puser->super_user )
|
if( cur->session->puser && cur->session->puser->is_super_user )
|
||||||
// super user is allowed everything
|
// super user is allowed everything
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( item.user_id == -1 || new_user_id == -1 || item.user_id != new_user_id )
|
if( item.item_content.user_id == -1 || new_user_id == -1 || item.item_content.user_id != new_user_id )
|
||||||
// only super user can change the owner of an item
|
// only super user can change the owner of an item
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -544,11 +554,11 @@ bool System::CanChangeGroup(const Item & item, long new_group_id)
|
|||||||
// session must be set
|
// session must be set
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( cur->session->puser && cur->session->puser->super_user )
|
if( cur->session->puser && cur->session->puser->is_super_user )
|
||||||
// super user is allowed everything
|
// super user is allowed everything
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( item.group_id != new_group_id )
|
if( item.item_content.group_id != new_group_id )
|
||||||
{
|
{
|
||||||
// user is allowed to change the group only if he is an owner of the item
|
// user is allowed to change the group only if he is an owner of the item
|
||||||
// he can change only into a group in which he is a member of, or into a 'no_group'
|
// he can change only into a group in which he is a member of, or into a 'no_group'
|
||||||
@@ -556,7 +566,7 @@ bool System::CanChangeGroup(const Item & item, long new_group_id)
|
|||||||
if( !cur->session->puser || cur->session->puser->id == -1 )
|
if( !cur->session->puser || cur->session->puser->id == -1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( item.user_id == -1 || cur->session->puser->id != item.user_id )
|
if( item.item_content.user_id == -1 || cur->session->puser->id != item.item_content.user_id )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( new_group_id == -1 )
|
if( new_group_id == -1 )
|
||||||
@@ -578,18 +588,18 @@ bool System::CanChangePrivileges(const Item & item, int new_priv)
|
|||||||
// session must be set
|
// session must be set
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( cur->session->puser && cur->session->puser->super_user )
|
if( cur->session->puser && cur->session->puser->is_super_user )
|
||||||
// super user is allowed everything
|
// super user is allowed everything
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( item.privileges != new_priv )
|
if( item.item_content.privileges != new_priv )
|
||||||
{
|
{
|
||||||
// the owner of an item is allowed to change the privileges
|
// the owner of an item is allowed to change the privileges
|
||||||
|
|
||||||
if( !cur->session->puser || cur->session->puser->id == -1 )
|
if( !cur->session->puser || cur->session->puser->id == -1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( item.user_id == -1 || cur->session->puser->id != item.user_id )
|
if( item.item_content.user_id == -1 || cur->session->puser->id != item.item_content.user_id )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,69 +607,31 @@ return true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private
|
// DEPRACATED
|
||||||
bool System::HasAccess(const Item & item, int mask)
|
|
||||||
{
|
|
||||||
if( !cur->session )
|
|
||||||
// session must be set
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( cur->session->puser && cur->session->puser->super_user )
|
|
||||||
// super user is allowed everything
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if( cur->session->puser && item.user_id != -1 && cur->session->puser->id == item.user_id )
|
|
||||||
{
|
|
||||||
// the owner
|
|
||||||
return ((item.privileges >> 9) & mask) == mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( cur->session->puser && item.group_id != -1 && cur->session->puser->IsMemberOf(item.group_id) )
|
|
||||||
{
|
|
||||||
// group
|
|
||||||
return ((item.privileges >> 6) & mask) == mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( cur->session->puser )
|
|
||||||
{
|
|
||||||
// others -- others logged people
|
|
||||||
return ((item.privileges >> 3) & mask) == mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
// guests -- not logged people
|
|
||||||
|
|
||||||
return (item.privileges & mask) == mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool System::HasReadAccess(const Item & item)
|
bool System::HasReadAccess(const Item & item)
|
||||||
{
|
{
|
||||||
return HasAccess(item, 4);
|
return item.item_content.has_read_access();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// DEPRACATED
|
||||||
bool System::HasWriteAccess(const Item & item)
|
bool System::HasWriteAccess(const Item & item)
|
||||||
{
|
{
|
||||||
return HasAccess(item, 2);
|
return item.item_content.has_write_access();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// DEPRACATED
|
||||||
bool System::HasReadWriteAccess(const Item & item)
|
bool System::HasReadWriteAccess(const Item & item)
|
||||||
{
|
{
|
||||||
return HasAccess(item, 6); // r+w
|
return item.item_content.has_read_write_access();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// DEPRACATED
|
||||||
bool System::HasReadExecAccess(const Item & item)
|
bool System::HasReadExecAccess(const Item & item)
|
||||||
{
|
{
|
||||||
if( cur->session && cur->session->puser && cur->session->puser->super_user )
|
return item.item_content.has_read_exec_access();
|
||||||
{
|
|
||||||
// there must be at least one 'x' (for the root)
|
|
||||||
// !! CHECK ME: is it applicable to directories too?
|
|
||||||
return (item.privileges & 01111) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HasAccess(item, 5); // r+x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -746,7 +718,7 @@ int System::NewPrivileges(int creation_mask)
|
|||||||
{
|
{
|
||||||
if( cur && cur->session && cur->session->puser )
|
if( cur && cur->session && cur->session->puser )
|
||||||
{
|
{
|
||||||
int umask = cur->session->puser->env.Int(L"umask", config->umask);
|
int umask = cur->session->puser->env.to_int(L"umask", config->umask);
|
||||||
return (~umask) & creation_mask;
|
return (~umask) & creation_mask;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -774,19 +746,19 @@ bool System::CanRemoveRenameChild(const Item & dir, long child_item_user_id)
|
|||||||
if( !HasWriteAccess(dir) )
|
if( !HasWriteAccess(dir) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( (dir.privileges & 010000) == 0 )
|
if( (dir.item_content.privileges & 010000) == 0 )
|
||||||
// there is no a sticky bit set to this directory
|
// there is no a sticky bit set to this directory
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( cur->session->puser )
|
if( cur->session->puser )
|
||||||
{
|
{
|
||||||
if( cur->session->puser->super_user )
|
if( cur->session->puser->is_super_user )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if( dir.user_id != -1 && cur->session->puser->id != -1 && child_item_user_id != -1 )
|
if( dir.item_content.user_id != -1 && cur->session->puser->id != -1 && child_item_user_id != -1 )
|
||||||
{
|
{
|
||||||
if( cur->session->puser->id == child_item_user_id ||
|
if( cur->session->puser->id == child_item_user_id ||
|
||||||
cur->session->puser->id == dir.user_id )
|
cur->session->puser->id == dir.item_content.user_id )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -840,7 +812,7 @@ bool System::IsSuperUser(long user_id)
|
|||||||
if( !puser )
|
if( !puser )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return puser->super_user;
|
return puser->is_super_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -867,12 +839,12 @@ return puser->IsMemberOf(group);
|
|||||||
// the path depends on parent_id
|
// the path depends on parent_id
|
||||||
bool System::CreateNewFileSimpleFs(Item & item)
|
bool System::CreateNewFileSimpleFs(Item & item)
|
||||||
{
|
{
|
||||||
bool res = dirs.MakePath(item.parent_id, item.file_path);
|
bool res = dirs.MakePath(item.parent_id, item.item_content.file_path);
|
||||||
|
|
||||||
if( res )
|
if( res )
|
||||||
{
|
{
|
||||||
if( !item.file_path.empty() && item.file_path[0] == '/' )
|
if( !item.item_content.file_path.empty() && item.item_content.file_path[0] == '/' )
|
||||||
item.file_path.erase(0, 1);
|
item.item_content.file_path.erase(0, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -897,7 +869,7 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
|
|||||||
buffer[0] = '0';
|
buffer[0] = '0';
|
||||||
swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)item.id);
|
swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)item.id);
|
||||||
|
|
||||||
item.file_path.clear();
|
item.item_content.file_path.clear();
|
||||||
|
|
||||||
// make sure that the length is even
|
// make sure that the length is even
|
||||||
if( (wcslen(hash) & 1) != 0 )
|
if( (wcslen(hash) & 1) != 0 )
|
||||||
@@ -905,16 +877,16 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
|
|||||||
|
|
||||||
for(size_t i=0 ; hash[i] != 0 ; i+=2)
|
for(size_t i=0 ; hash[i] != 0 ; i+=2)
|
||||||
{
|
{
|
||||||
item.file_path += hash[i];
|
item.item_content.file_path += hash[i];
|
||||||
item.file_path += hash[i+1];
|
item.item_content.file_path += hash[i+1];
|
||||||
|
|
||||||
if( hash[i+2] != 0 )
|
if( hash[i+2] != 0 )
|
||||||
item.file_path += '/';
|
item.item_content.file_path += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// one character more to make sure the path is unique
|
// one character more to make sure the path is unique
|
||||||
// (we can have a directory without the character)
|
// (we can have a directory without the character)
|
||||||
item.file_path += '_';
|
item.item_content.file_path += '_';
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -939,18 +911,18 @@ bool res;
|
|||||||
if( !pmount || pmount->fs != mounts.MountFsHashfs() )
|
if( !pmount || pmount->fs != mounts.MountFsHashfs() )
|
||||||
{
|
{
|
||||||
res = CreateNewFileSimpleFs(item);
|
res = CreateNewFileSimpleFs(item);
|
||||||
item.file_fs = mounts.MountFsSimplefs();
|
item.item_content.file_fs = mounts.MountFsSimplefs();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = CreateNewFileHashFs(item);
|
res = CreateNewFileHashFs(item);
|
||||||
item.file_fs = mounts.MountFsHashfs();
|
item.item_content.file_fs = mounts.MountFsHashfs();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( res )
|
if( res )
|
||||||
item.file_path += item.url;
|
item.item_content.file_path += item.url;
|
||||||
else
|
else
|
||||||
item.file_path.clear();
|
item.item_content.file_path.clear();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -968,7 +940,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( item.file_path.empty() || item.file_type == WINIX_ITEM_FILETYPE_NONE )
|
if( item.item_content.file_path.empty() || item.item_content.file_type == WINIX_ITEM_FILETYPE_NONE )
|
||||||
{
|
{
|
||||||
log << log1 << "System: MakePath: this item has not a static file" << logend;
|
log << log1 << "System: MakePath: this item has not a static file" << logend;
|
||||||
return false;
|
return false;
|
||||||
@@ -976,7 +948,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
|||||||
|
|
||||||
path = config->upload_dir;
|
path = config->upload_dir;
|
||||||
|
|
||||||
if( item.file_fs == mounts.MountFsHashfs() )
|
if( item.item_content.file_fs == mounts.MountFsHashfs() )
|
||||||
path += L"/hashfs";
|
path += L"/hashfs";
|
||||||
else
|
else
|
||||||
path += L"/simplefs";
|
path += L"/simplefs";
|
||||||
@@ -988,11 +960,48 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
|||||||
path += L"/normal";
|
path += L"/normal";
|
||||||
|
|
||||||
|
|
||||||
if( create_dir && !CreateDirs(path, item.file_path, chmod, group, true) )
|
if( create_dir && !CreateDirs(path, item.item_content.file_path, chmod, group, true) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
path += '/';
|
path += '/';
|
||||||
path += item.file_path;
|
path += item.item_content.file_path;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool System::MakeRelativeFilePath(const Item & item, const std::wstring & path_prefix, std::wstring & path, bool thumb)
|
||||||
|
{
|
||||||
|
path.clear();
|
||||||
|
|
||||||
|
if( item.item_content.file_path.empty() || item.item_content.file_type == WINIX_ITEM_FILETYPE_NONE )
|
||||||
|
{
|
||||||
|
log << log1 << "System: MakePath: this item has not a static file" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we allow the prefix to be empty
|
||||||
|
if( !path_prefix.empty() )
|
||||||
|
{
|
||||||
|
if( path_prefix[0] != '/' )
|
||||||
|
path += '/';
|
||||||
|
|
||||||
|
path += path_prefix;
|
||||||
|
TrimLast(path, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
if( item.item_content.file_fs == mounts.MountFsHashfs() )
|
||||||
|
path += L"/hashfs";
|
||||||
|
else
|
||||||
|
path += L"/simplefs";
|
||||||
|
|
||||||
|
if( thumb )
|
||||||
|
path += L"/thumb";
|
||||||
|
else
|
||||||
|
path += L"/normal";
|
||||||
|
|
||||||
|
path += '/';
|
||||||
|
path += item.item_content.file_path;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1025,14 +1034,17 @@ return res;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error System::AddFile(Item & item, int notify_code, bool call_plugins)
|
bool System::AddFile(Item & item, int notify_code, bool call_plugins)
|
||||||
{
|
{
|
||||||
if( item.type != Item::file )
|
if( item.type != Item::file )
|
||||||
return WINIX_ERR_FILE_EXPECTED;
|
return WINIX_ERR_FILE_EXPECTED;
|
||||||
|
|
||||||
Error status = db->AddItem(item);
|
|
||||||
|
//Error status = db->AddItem(item);
|
||||||
|
item.set_connector(model_connector);
|
||||||
|
bool status = item.insert();
|
||||||
|
|
||||||
if( status == WINIX_ERR_OK )
|
if( status )
|
||||||
{
|
{
|
||||||
log << log2 << "System: added a new file, url: " << item.url << ", id: " << item.id
|
log << log2 << "System: added a new file, url: " << item.url << ", id: " << item.id
|
||||||
<< ", parent_id: " << item.parent_id << logend;
|
<< ", parent_id: " << item.parent_id << logend;
|
||||||
@@ -1050,20 +1062,25 @@ return status;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Error System::EditFile(Item & item, bool with_url, int notify_code, bool call_plugins)
|
bool System::EditFile(Item & item, bool with_url, int notify_code, bool call_plugins)
|
||||||
{
|
{
|
||||||
if( item.type != Item::file )
|
if( item.type != Item::file )
|
||||||
return WINIX_ERR_FILE_EXPECTED;
|
return WINIX_ERR_FILE_EXPECTED;
|
||||||
|
|
||||||
if( cur->session && cur->session->puser )
|
if( cur->session && cur->session->puser )
|
||||||
cur->request->item.modification_user_id = cur->session->puser->id;
|
cur->request->item.item_content.modification_user_id = cur->session->puser->id;
|
||||||
else
|
else
|
||||||
cur->request->item.modification_user_id = -1;
|
cur->request->item.item_content.modification_user_id = -1;
|
||||||
|
|
||||||
item.SetDateModifyToNow();
|
item.item_content.SetDateModifyToNow();
|
||||||
Error status = db->EditItemById(item, with_url);
|
|
||||||
|
ItemModelData item_model_data;
|
||||||
|
item_model_data.prepare_unique_url = with_url;
|
||||||
|
|
||||||
|
bool status = item.update(item_model_data);
|
||||||
|
//Error status = db->EditItemById(item, with_url);
|
||||||
|
|
||||||
if( status == WINIX_ERR_OK )
|
if( status )
|
||||||
{
|
{
|
||||||
TemplatesFunctions::pattern_cacher.UpdatePattern(item);
|
TemplatesFunctions::pattern_cacher.UpdatePattern(item);
|
||||||
|
|
||||||
@@ -1101,7 +1118,7 @@ return utc_time;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
PT::Date System::ToLocal(const PT::Date & utc_date)
|
pt::Date System::ToLocal(const pt::Date & utc_date)
|
||||||
{
|
{
|
||||||
size_t tz_id;
|
size_t tz_id;
|
||||||
|
|
||||||
@@ -1140,7 +1157,7 @@ return local_time;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
PT::Date System::ToUTC(const PT::Date & local_date)
|
pt::Date System::ToUTC(const pt::Date & local_date)
|
||||||
{
|
{
|
||||||
size_t tz_id;
|
size_t tz_id;
|
||||||
|
|
||||||
@@ -1184,7 +1201,17 @@ int System::FollowLink(const std::vector<Item*> & current_dir_tab, const std::ws
|
|||||||
|
|
||||||
if( res == 1 )
|
if( res == 1 )
|
||||||
{
|
{
|
||||||
if( db->GetItem(out_dir_tab.back()->id, name_temp, out_item) == WINIX_ERR_OK )
|
morm::Finder<Item> finder(model_connector);
|
||||||
|
|
||||||
|
bool status = finder.
|
||||||
|
select().
|
||||||
|
where().
|
||||||
|
eq(L"parent_id", out_dir_tab.back()->id).
|
||||||
|
eq(L"url", name_temp).
|
||||||
|
get(out_item);
|
||||||
|
|
||||||
|
//if( db->GetItem(out_dir_tab.back()->id, name_temp, out_item) == WINIX_ERR_OK )
|
||||||
|
if( status )
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 2;
|
return 2;
|
||||||
@@ -1213,12 +1240,12 @@ bool System::FollowAllLinksDirFound(std::vector<Item*> & out_dir_tab,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !out_dir_tab.back()->link_to.empty() )
|
if( !out_dir_tab.back()->item_content.link_to.empty() )
|
||||||
{
|
{
|
||||||
if( follow_dir_default )
|
if( follow_dir_default )
|
||||||
{
|
{
|
||||||
if( !(stop_on_link_redirect && out_dir_tab.back()->link_redirect==1) )
|
if( !(stop_on_link_redirect && out_dir_tab.back()->item_content.link_redirect==1) )
|
||||||
link_to_temp = out_dir_tab.back()->link_to;
|
link_to_temp = out_dir_tab.back()->item_content.link_to;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1252,15 +1279,15 @@ bool System::FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab,
|
|||||||
|
|
||||||
if( out_item.type == Item::symlink )
|
if( out_item.type == Item::symlink )
|
||||||
{
|
{
|
||||||
if( out_item.link_to.empty() )
|
if( out_item.item_content.link_to.empty() )
|
||||||
{
|
{
|
||||||
log << log1 << "System: symlink empty" << logend;
|
log << log1 << "System: symlink empty" << logend;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( !(stop_on_link_redirect && out_item.link_redirect==1) )
|
if( !(stop_on_link_redirect && out_item.item_content.link_redirect==1) )
|
||||||
link_to_temp = out_item.link_to;
|
link_to_temp = out_item.item_content.link_to;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1392,8 +1419,8 @@ bool System::FollowAllLinks(const std::wstring & link_to,
|
|||||||
cur->request->item.Clear();
|
cur->request->item.Clear();
|
||||||
cur->request->last_item = cur->request->dir_tab.back();
|
cur->request->last_item = cur->request->dir_tab.back();
|
||||||
|
|
||||||
if( !cur->request->dir_tab.back()->link_to.empty() )
|
if( !cur->request->dir_tab.back()->item_content.link_to.empty() )
|
||||||
RedirectTo(cur->request->dir_tab.back()->link_to);
|
RedirectTo(cur->request->dir_tab.back()->item_content.link_to);
|
||||||
|
|
||||||
log << log3 << "System: current directory changed" << logend;
|
log << log3 << "System: current directory changed" << logend;
|
||||||
}
|
}
|
||||||
@@ -1404,12 +1431,13 @@ bool System::FollowAllLinks(const std::wstring & link_to,
|
|||||||
cur->request->last_item = &cur->request->item;
|
cur->request->last_item = &cur->request->item;
|
||||||
|
|
||||||
if( cur->request->item.type == Item::symlink )
|
if( cur->request->item.type == Item::symlink )
|
||||||
RedirectTo(cur->request->item.link_to); // cur->request->item.link_to is not empty
|
RedirectTo(cur->request->item.item_content.link_to); // cur->request->item.item_content.link_to is not empty
|
||||||
|
|
||||||
log << log3 << "System: current directory changed and the new file loaded" << logend;
|
log << log3 << "System: current directory changed and the new file loaded" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
mounts.CalcCurMount();
|
cur->mount = mounts.CalcCurMount(cur->request);
|
||||||
|
cur->request->mount = cur->mount;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1433,7 +1461,7 @@ return ok;
|
|||||||
current limitation:
|
current limitation:
|
||||||
warning: the url is not prepared by PrepareUrl() (PrepareUrl is from functions)
|
warning: the url is not prepared by PrepareUrl() (PrepareUrl is from functions)
|
||||||
*/
|
*/
|
||||||
bool System::AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url, bool overwrite_existing)
|
bool System::AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url, const wchar_t * mime_type, bool overwrite_existing)
|
||||||
{
|
{
|
||||||
if( config->common_dir.empty() )
|
if( config->common_dir.empty() )
|
||||||
{
|
{
|
||||||
@@ -1459,27 +1487,57 @@ bool System::AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( db->GetItem(var->id, url, file_content_item) == WINIX_ERR_OK )
|
morm::Finder<Item> finder(model_connector);
|
||||||
|
|
||||||
|
file_content_item = finder.select().where().eq(L"parent_id", var->id).eq(L"url", url).get();
|
||||||
|
|
||||||
|
if( file_content_item.found() )
|
||||||
{
|
{
|
||||||
if( overwrite_existing )
|
if( !overwrite_existing )
|
||||||
db->DelItem(file_content_item);
|
|
||||||
else
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
file_content_item.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
file_content_item.Clear();
|
file_content_item.Clear();
|
||||||
file_content_item.parent_id = var->id;
|
file_content_item.parent_id = var->id;
|
||||||
file_content_item.user_id = var->user_id;
|
file_content_item.item_content.user_id = var->item_content.user_id;
|
||||||
file_content_item.group_id = var->group_id;
|
file_content_item.item_content.group_id = var->item_content.group_id;
|
||||||
file_content_item.privileges = 07555; // !! IMPROVE ME: may it should be added as a parameter to this function?
|
file_content_item.item_content.privileges = 07555; // !! IMPROVE ME: may it should be added as a parameter to this function?
|
||||||
file_content_item.subject = url;
|
file_content_item.subject = url;
|
||||||
file_content_item.url = url;
|
file_content_item.url = url;
|
||||||
file_content_item.type = Item::file;
|
file_content_item.type = Item::file;
|
||||||
file_content_item.html_template = config->templates_index_raw;
|
file_content_item.html_template = config->templates_index_raw;
|
||||||
file_content_item.content = file_content;
|
file_content_item.item_content.content_raw = file_content;
|
||||||
file_content_item.content_type = Item::ct_other;
|
file_content_item.item_content.content_raw_type = ItemContent::ct_other;
|
||||||
|
|
||||||
return AddFile(file_content_item, false) == WINIX_ERR_OK;
|
if( mime_type )
|
||||||
|
file_content_item.item_content.file_mime_type = mime_type;
|
||||||
|
|
||||||
|
return AddFile(file_content_item, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void System::DeleteOldRequests(bool leave_one_object)
|
||||||
|
{
|
||||||
|
std::list<Request>::iterator i = req_tab.begin();
|
||||||
|
|
||||||
|
while( i != req_tab.end() )
|
||||||
|
{
|
||||||
|
// leave at least one object (even if it is finished)
|
||||||
|
if( (i->run_state == Request::RunState::finished || i->run_state == Request::RunState::not_assigned) && (!leave_one_object || req_tab.size() > 1) )
|
||||||
|
{
|
||||||
|
log << log3 << "System: removing a finished or not assigned request " << cur->request << logend;
|
||||||
|
std::list<Request>::iterator old_i = i;
|
||||||
|
++i;
|
||||||
|
req_tab.erase(old_i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+19
-15
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
* Copyright (c) 2010-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -39,7 +39,6 @@
|
|||||||
#include "job.h"
|
#include "job.h"
|
||||||
#include "dirs.h"
|
#include "dirs.h"
|
||||||
#include "mounts.h"
|
#include "mounts.h"
|
||||||
#include "db/db.h"
|
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
@@ -64,7 +63,7 @@ class SessionManager;
|
|||||||
|
|
||||||
|
|
||||||
// file system
|
// file system
|
||||||
class System : WinixModel
|
class System : public WinixModelDeprecated
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -108,26 +107,30 @@ public:
|
|||||||
// when winix starts
|
// when winix starts
|
||||||
TimeZones time_zones;
|
TimeZones time_zones;
|
||||||
|
|
||||||
|
// list of requests, if a request is to be continued in a job then it is preserved in the req_tab
|
||||||
|
// and a new Request is inserted for the next incoming request
|
||||||
|
std::list<Request> req_tab;
|
||||||
|
|
||||||
|
using WinixModelDeprecated::get_model_connector;
|
||||||
|
|
||||||
void SetCur(Cur * pcur);
|
void SetCur(Cur * pcur);
|
||||||
//void SetConfig(Config * pconfig);
|
//void SetConfig(Config * pconfig);
|
||||||
void SetDb(Db * pdb);
|
|
||||||
//void SetSynchro(Synchro * psynchro);
|
//void SetSynchro(Synchro * psynchro);
|
||||||
void SetFunctions(Functions * pfunctions);
|
void SetFunctions(Functions * pfunctions);
|
||||||
void SetSessionManager(SessionManager * sm);
|
void SetSessionManager(SessionManager * sm);
|
||||||
|
|
||||||
void set_dependency(WinixModel * winix_model);
|
void set_dependency(WinixModelDeprecated * winix_model);
|
||||||
|
|
||||||
void Init();
|
bool Init();
|
||||||
|
|
||||||
void AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str = true);
|
void AddParams(const ParamTab & param_tab, std::wstring & str, bool clear_str = true);
|
||||||
|
|
||||||
bool IsSSLRequired(bool try_to_use_ssl);
|
bool IsSSLRequired(bool try_to_use_ssl);
|
||||||
bool IsSSLRequired();
|
bool IsSSLRequired();
|
||||||
void PutUrlProto(bool can_use_ssl, std::wstring & str, bool clear_str = true);
|
void PutUrlProto(bool can_use_ssl, std::wstring & str, bool clear_str = true);
|
||||||
void PutUrlProto(bool can_use_ssl, PT::TextStream & str, bool clear_stream = true);
|
void PutUrlProto(bool can_use_ssl, pt::Stream & str, bool clear_stream = true);
|
||||||
void PutUrlProto(std::wstring & str, bool clear_str = true);
|
void PutUrlProto(std::wstring & str, bool clear_str = true);
|
||||||
void PutUrlProto(PT::TextStream & str, bool clear_stream = true);
|
void PutUrlProto(pt::Stream & str, bool clear_stream = true);
|
||||||
|
|
||||||
void RedirectTo(const Item & item, const wchar_t * postfix = 0, bool use_reqtype = true);
|
void RedirectTo(const Item & item, const wchar_t * postfix = 0, bool use_reqtype = true);
|
||||||
void RedirectTo(long item_id, const wchar_t * postfix = 0, bool use_reqtype = true);
|
void RedirectTo(long item_id, const wchar_t * postfix = 0, bool use_reqtype = true);
|
||||||
@@ -176,17 +179,19 @@ public:
|
|||||||
bool CreateNewFile(Item & item);
|
bool CreateNewFile(Item & item);
|
||||||
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755, int group = -1);
|
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755, int group = -1);
|
||||||
|
|
||||||
|
bool MakeRelativeFilePath(const Item & item, const std::wstring & path_prefix, std::wstring & path, bool thumb = false);
|
||||||
|
|
||||||
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
||||||
|
|
||||||
Error AddFile(Item & item, int notify_code = 0, bool call_plugins = true);
|
bool AddFile(Item & item, int notify_code = 0, bool call_plugins = true);
|
||||||
Error EditFile(Item & item, bool with_url = true, int notify_code = 0, bool call_plugins = true);
|
bool EditFile(Item & item, bool with_url = true, int notify_code = 0, bool call_plugins = true);
|
||||||
|
|
||||||
|
|
||||||
time_t ToLocal(time_t utc_time);
|
time_t ToLocal(time_t utc_time);
|
||||||
PT::Date ToLocal(const PT::Date & utc_date);
|
pt::Date ToLocal(const pt::Date & utc_date);
|
||||||
|
|
||||||
time_t ToUTC(time_t local_time);
|
time_t ToUTC(time_t local_time);
|
||||||
PT::Date ToUTC(const PT::Date & local_date);
|
pt::Date ToUTC(const pt::Date & local_date);
|
||||||
|
|
||||||
|
|
||||||
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
||||||
@@ -206,7 +211,7 @@ public:
|
|||||||
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
|
bool follow_dir_default = false, bool stop_on_link_redirect = false, bool check_access = true);
|
||||||
|
|
||||||
|
|
||||||
bool AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url, bool overwrite_existing = true);
|
bool AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url, const wchar_t * mime_type = nullptr, bool overwrite_existing = true);
|
||||||
|
|
||||||
// reloading time zones
|
// reloading time zones
|
||||||
void ReadTimeZones();
|
void ReadTimeZones();
|
||||||
@@ -217,11 +222,11 @@ public:
|
|||||||
|
|
||||||
void CreateItemLink(const Item & item, std::wstring & link, bool clear_str = true);
|
void CreateItemLink(const Item & item, std::wstring & link, bool clear_str = true);
|
||||||
|
|
||||||
|
void DeleteOldRequests(bool leave_one_object = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Cur * cur;
|
Cur * cur;
|
||||||
Db * db;
|
|
||||||
//Config * config;
|
//Config * config;
|
||||||
//Synchro * synchro;
|
//Synchro * synchro;
|
||||||
Functions * functions;
|
Functions * functions;
|
||||||
@@ -237,7 +242,6 @@ private:
|
|||||||
std::vector<Item*> root_follow_dir_tab;
|
std::vector<Item*> root_follow_dir_tab;
|
||||||
Item temp_follow_item;
|
Item temp_follow_item;
|
||||||
|
|
||||||
bool HasAccess(const Item & item, int mask);
|
|
||||||
int NewPrivileges(int creation_mask);
|
int NewPrivileges(int creation_mask);
|
||||||
|
|
||||||
bool CreateNewFileSimpleFs(Item & item);
|
bool CreateNewFileSimpleFs(Item & item);
|
||||||
|
|||||||
@@ -1,556 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of Winix
|
|
||||||
* and is distributed under the 2-Clause BSD licence.
|
|
||||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef headerfile_winix_core_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"
|
|
||||||
#include "utf8/utf8.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 uses UTF-8 <-> wide characters conversions:
|
|
||||||
if StringType is std::string:
|
|
||||||
operator<<(const char*) only copies the input string
|
|
||||||
operator<<(const wchar_t*) converts from wide characters to UTF-8
|
|
||||||
(similary for an operator with std::string and std::wstring)
|
|
||||||
if StringType is std::wstring:
|
|
||||||
operator<<(const char*) converts from UTF-8 to wide characters
|
|
||||||
operator<<(const wchar_t*) only copies the input string
|
|
||||||
(similary for an operator with std::string and std::wstring)
|
|
||||||
|
|
||||||
*/
|
|
||||||
template<class StringType>
|
|
||||||
class TextStream
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
void Convert(wchar_t c, std::string & dst);
|
|
||||||
void Convert(wchar_t c, std::wstring & dst);
|
|
||||||
|
|
||||||
void Convert(const char * src, size_t len, std::wstring & dst);
|
|
||||||
void Convert(const char * src, std::wstring & dst);
|
|
||||||
void Convert(const std::string & src, std::wstring & dst);
|
|
||||||
|
|
||||||
void Convert(const wchar_t * src, size_t len, std::string & dst);
|
|
||||||
void Convert(const wchar_t * src, std::string & dst);
|
|
||||||
void Convert(const std::wstring & src, std::string & dst);
|
|
||||||
|
|
||||||
void Convert(const char * src, size_t len, std::string & dst);
|
|
||||||
void Convert(const char * src, std::string & dst);
|
|
||||||
void Convert(const std::string & src, std::string & dst);
|
|
||||||
|
|
||||||
void Convert(const wchar_t * src, size_t len, std::wstring & dst);
|
|
||||||
void Convert(const wchar_t * src, std::wstring & dst);
|
|
||||||
void Convert(const std::wstring & src, std::wstring & dst);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
Convert(str, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string * str)
|
|
||||||
{
|
|
||||||
Convert(*str, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::string & str)
|
|
||||||
{
|
|
||||||
Convert(str, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const wchar_t * str)
|
|
||||||
{
|
|
||||||
Convert(str, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring * str)
|
|
||||||
{
|
|
||||||
Convert(*str, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(const std::wstring & str)
|
|
||||||
{
|
|
||||||
Convert(str, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(char v)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* there is no any possibility to treat 'v' as UTF-8 character if we have got
|
|
||||||
* only one character so we only copy it
|
|
||||||
*/
|
|
||||||
buffer += v;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(wchar_t v)
|
|
||||||
{
|
|
||||||
Convert(v, buffer);
|
|
||||||
|
|
||||||
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);
|
|
||||||
Convert(buf, buffer);
|
|
||||||
|
|
||||||
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);
|
|
||||||
Convert(buf, buffer);
|
|
||||||
|
|
||||||
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);
|
|
||||||
Convert(buf, buffer);
|
|
||||||
|
|
||||||
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);
|
|
||||||
Convert(buf, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::operator<<(double v)
|
|
||||||
{
|
|
||||||
char buf[50];
|
|
||||||
|
|
||||||
sprintf(buf, "%f", v);
|
|
||||||
Convert(buf, buffer);
|
|
||||||
|
|
||||||
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);
|
|
||||||
Convert(buf, buffer);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
TextStream<StringType> & TextStream<StringType>::Write(const char * buf, size_t len)
|
|
||||||
{
|
|
||||||
Convert(buf, len, buffer);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
Convert(buf, len, buffer);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(wchar_t c, std::string & dst)
|
|
||||||
{
|
|
||||||
PT::IntToUTF8((int)c, dst, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(wchar_t c, std::wstring & dst)
|
|
||||||
{
|
|
||||||
dst += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const char * src, size_t len, std::wstring & dst)
|
|
||||||
{
|
|
||||||
PT::UTF8ToWide(src, len, dst, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const char * src, std::wstring & dst)
|
|
||||||
{
|
|
||||||
PT::UTF8ToWide(src, dst, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const std::string & src, std::wstring & dst)
|
|
||||||
{
|
|
||||||
PT::UTF8ToWide(src, dst, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::string & dst)
|
|
||||||
{
|
|
||||||
PT::WideToUTF8(src, len, dst, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const wchar_t * src, std::string & dst)
|
|
||||||
{
|
|
||||||
PT::WideToUTF8(src, dst, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const std::wstring & src, std::string & dst)
|
|
||||||
{
|
|
||||||
PT::WideToUTF8(src, dst, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const char * src, size_t len, std::string & dst)
|
|
||||||
{
|
|
||||||
// we suppose that append is smart enough and we don't have to use reserve()
|
|
||||||
dst.append(src, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const char * src, std::string & dst)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
for(len=0 ; src[len] ; ++len){}
|
|
||||||
|
|
||||||
Convert(src, len, dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const std::string & src, std::string & dst)
|
|
||||||
{
|
|
||||||
dst.append(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::wstring & dst)
|
|
||||||
{
|
|
||||||
// we suppose that append is smart enough and we don't have to use reserve()
|
|
||||||
dst.append(src, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const wchar_t * src, std::wstring & dst)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
for(len=0 ; src[len] ; ++len){}
|
|
||||||
|
|
||||||
Convert(src, len, dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class StringType>
|
|
||||||
void TextStream<StringType>::Convert(const std::wstring & src, std::wstring & dst)
|
|
||||||
{
|
|
||||||
dst.append(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2019, Tomasz Sowa
|
* Copyright (c) 2011-2024, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -70,7 +70,7 @@ sigset_t set;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
bool ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
||||||
{
|
{
|
||||||
thread_tab.emplace_back();
|
thread_tab.emplace_back();
|
||||||
ThreadItem & item = thread_tab.back();
|
ThreadItem & item = thread_tab.back();
|
||||||
@@ -82,20 +82,45 @@ void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
|||||||
item.object->set_dependency(this);
|
item.object->set_dependency(this);
|
||||||
|
|
||||||
// main log buffer (from the main thread)
|
// main log buffer (from the main thread)
|
||||||
item.object->set_main_log_buffer(log.GetLogBuffer());
|
item.object->set_main_log_buffer(log.get_log_buffer());
|
||||||
item.object->set_main_file_log(log.GetFileLog());
|
item.object->set_main_file_log(log.get_file_log());
|
||||||
|
|
||||||
// the logger buffer and model_connector are different
|
// the logger buffer and model_connector are different
|
||||||
item.object->set_log_buffer(&data.log_buffer);
|
item.object->set_log_buffer(&data.log_buffer);
|
||||||
|
|
||||||
//data.postgresql_connector.set_logger(logger);
|
//data.postgresql_connector.set_logger(logger);
|
||||||
data.postgresql_connector.set_conn_param(config->db_database, config->db_user, config->db_pass);
|
if( !config->db_conn_string.empty() )
|
||||||
|
data.postgresql_connector.set_conn_param(config->db_conn_string);
|
||||||
|
else
|
||||||
|
data.postgresql_connector.set_conn_param(config->db_host, config->db_hostaddr, config->db_port, config->db_database, config->db_user, config->db_pass);
|
||||||
|
|
||||||
data.postgresql_connector.set_logger(item.object->get_logger());
|
data.postgresql_connector.set_logger(item.object->get_logger());
|
||||||
data.postgresql_connector.set_log_queries(config->log_db_query);
|
data.postgresql_connector.set_log_queries(config->log_db_query);
|
||||||
data.postgresql_connector.wait_for_connection();
|
|
||||||
|
if( !data.postgresql_connector.wait_for_connection(config->db_startup_connection_max_attempts, config->db_startup_connection_attempt_delay) )
|
||||||
|
{
|
||||||
|
Log * plog = item.object->get_logger();
|
||||||
|
(*plog) << logsave;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
data.model_connector.set_db_connector(data.postgresql_connector);
|
data.model_connector.set_db_connector(data.postgresql_connector);
|
||||||
data.model_connector.set_flat_connector(data.json_connector);
|
data.model_connector.set_flat_connector(data.json_connector);
|
||||||
|
data.model_connector.set_logger(item.object->get_logger());
|
||||||
|
data.model_connector.set_winix_config(config);
|
||||||
|
data.model_connector.set_winix_request(nullptr);
|
||||||
|
data.model_connector.set_winix_logger(item.object->get_logger());
|
||||||
|
data.model_connector.set_winix_dirs(nullptr);
|
||||||
|
data.model_connector.set_winix_mounts(nullptr);
|
||||||
|
data.model_connector.set_winix_users(nullptr);
|
||||||
|
data.model_connector.set_winix_groups(nullptr);
|
||||||
|
data.model_connector.set_winix_session(nullptr);
|
||||||
|
data.model_connector.set_winix_locale(nullptr); // null for a moment, may will be changed
|
||||||
|
data.model_connector.set_winix_session_manager(nullptr);// null for a moment, may will be changed
|
||||||
|
data.model_connector.set_winix_time_zones(nullptr); // null for a moment, may will be changed
|
||||||
|
data.model_connector.set_winix_pattern_cacher(nullptr); // null for a moment, may will be changed
|
||||||
|
|
||||||
|
item.object->set_main_model_connector(get_model_connector());
|
||||||
item.object->set_model_connector(&data.model_connector);
|
item.object->set_model_connector(&data.model_connector);
|
||||||
|
|
||||||
if( were_started )
|
if( were_started )
|
||||||
@@ -107,31 +132,33 @@ void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
|
|||||||
log << log4 << "TM: added a thread to the queue, number: " << (thread_tab.size()-1)
|
log << log4 << "TM: added a thread to the queue, number: " << (thread_tab.size()-1)
|
||||||
<< ", name: " << thread_name << logend;
|
<< ", name: " << thread_name << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread & pbase, const wchar_t * thread_name)
|
bool ThreadManager::Add(BaseThread & pbase, const wchar_t * thread_name)
|
||||||
{
|
{
|
||||||
Add(&pbase, thread_name);
|
return Add(&pbase, thread_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread * pbase, const std::wstring & thread_name)
|
bool ThreadManager::Add(BaseThread * pbase, const std::wstring & thread_name)
|
||||||
{
|
{
|
||||||
Add(pbase, thread_name.c_str());
|
return Add(pbase, thread_name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadManager::Add(BaseThread & pbase, const std::wstring & thread_name)
|
|
||||||
|
bool ThreadManager::Add(BaseThread & pbase, const std::wstring & thread_name)
|
||||||
{
|
{
|
||||||
Add(&pbase, thread_name.c_str());
|
return Add(&pbase, thread_name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadManager::StartAll()
|
void ThreadManager::StartAll()
|
||||||
{
|
{
|
||||||
synchro->Lock();
|
Winix::Lock lock(synchro);
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
for(ThreadItem & item : thread_tab)
|
for(ThreadItem & item : thread_tab)
|
||||||
@@ -140,7 +167,7 @@ void ThreadManager::StartAll()
|
|||||||
id += 1;
|
id += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchro->Unlock();
|
lock.Unlock();
|
||||||
|
|
||||||
were_started = true;
|
were_started = true;
|
||||||
}
|
}
|
||||||
@@ -165,28 +192,32 @@ void ThreadManager::StopAll()
|
|||||||
if( !were_started )
|
if( !were_started )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// WakeUpThread() should be used with Lock/Unlock
|
|
||||||
synchro->Lock();
|
|
||||||
|
|
||||||
for(ThreadItem & item : thread_tab)
|
|
||||||
{
|
{
|
||||||
item.object->WakeUpThread();
|
Winix::Lock lock(synchro);
|
||||||
|
|
||||||
|
for(ThreadItem & item : thread_tab)
|
||||||
|
{
|
||||||
|
// WakeUpThread() should be used with Lock/Unlock
|
||||||
|
item.object->WakeUpThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchro->Unlock();
|
|
||||||
|
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
for(ThreadItem & item : thread_tab)
|
for(ThreadItem & item : thread_tab)
|
||||||
{
|
{
|
||||||
log << log4 << "TM: waiting for thread " << id << " (" << item.object->ThreadId()
|
log << log4 << "TM: waiting for thread " << id << " (" << item.object->ThreadId()
|
||||||
<< ", name: " << item.name << ")" << logend;
|
<< ", name: " << item.name << ")" << logend << logsave;
|
||||||
|
|
||||||
item.object->WaitForThread();
|
item.object->WaitForThread();
|
||||||
log << log4 << "TM: thread " << id << " terminated" << logend;
|
log << log4 << "TM: thread " << id << " terminated" << logend << logsave;
|
||||||
|
|
||||||
|
// the thread is stopped and we can set the thread log buffer pointing to
|
||||||
|
// the main log buffer (from the main thread)
|
||||||
|
item.object->set_log_buffer(log.get_log_buffer());
|
||||||
|
|
||||||
delete item.thread_item_data;
|
delete item.thread_item_data;
|
||||||
|
item.thread_item_data = nullptr;
|
||||||
id += 1;
|
id += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user