Compare commits

..

86 Commits

Author SHA1 Message Date
tomasz.sowa 6a452ffed0 version changed to 0.7.3 2021-05-27 12:21:59 +02:00
Tomek fc24570062 fixed compilation: pikotools is in src subdirectory now 2021-05-27 12:04:41 +02:00
tomasz.sowa aa71abd725 some workarounds in Thread plugin (don't show stale info in html forms) 2021-05-27 10:29:26 +02:00
tomasz.sowa fb64f5e456 fixed: reply winix function (from thread plugin) didn't add a reply - system->Add() didn't set the model_connector to the item 2021-05-26 19:55:50 +02:00
tomasz.sowa 61fe6ea219 updated to the new api from ezc: changed semantic of [def] and Vars moved outside of Generator 2021-05-23 10:14:08 +02:00
tomasz.sowa d30c7254eb updated uikit to 3.6.22 2021-05-22 13:03:15 +02:00
tomasz.sowa 06be33ba5f make depend 2021-05-21 23:06:57 +02:00
tomasz.sowa b2cffa39e1 added models Thread and ThreadFiles in thread plugin 2021-05-21 23:06:48 +02:00
tomasz.sowa 86ef2529b1 fixed in some places: system->AddFile() returns bool now instead of Error 2021-05-21 17:41:16 +02:00
tomasz.sowa f1b9d1b870 updated to the new pikotools api: changed the way how child_spaces are created in Space class 2021-05-21 17:17:17 +02:00
tomasz.sowa fe67b5d72a updated to the new pikotools api: snake_case names of methods from SpaceParser 2021-05-21 04:51:58 +02:00
tomasz.sowa 27720afaf2 updated to the new pikotools api: SpaceParser::SetSpace(...) methods have been removed 2021-05-21 01:37:42 +02:00
tomasz.sowa 8bb585d97d updated to the new pikotools api: changed utf8 functions PascalCase to snake_case 2021-05-21 00:41:27 +02:00
tomasz.sowa 8c523ce8b9 make depend 2021-05-21 00:32:58 +02:00
tomasz.sowa e48a28a5c8 namespace PT renamed to pt 2021-05-20 20:59:12 +02:00
tomasz.sowa d66a36cf21 make depend 2021-05-14 03:32:03 +02:00
tomasz.sowa a94e09f0aa added support for Model migrations
now we have a table core.migration and each model (User, Group, Item, ItemContent and a new Migration) have its own
row in the table with a version number

added to config:
db_make_migration_if_needed and db_stop_if_migration_fails (need description yet)
2021-05-14 03:31:29 +02:00
tomasz.sowa 4df10de6b7 methods eq() from finder can have now a table name 2021-05-13 19:33:19 +02:00
tomasz.sowa 6d07535dad updated uikit to 3.6.21 version 2021-05-13 06:24:44 +02:00
tomasz.sowa ee354d2ded renamed in Models: map_fields() to fields(), prepare_table() to table() 2021-05-13 03:29:41 +02:00
tomasz.sowa e64bd1fba8 added more html tags to extraAllowedContent (ckeditor) 2021-05-13 03:24:37 +02:00
tomasz.sowa 031e673c51 fixed: passwd winix function: pass_encrypted was not cleared if we are not using rsa for encrypting passwords anymore 2021-05-13 02:02:15 +02:00
tomasz.sowa 801c9a2cda make depend 2021-05-11 22:22:10 +02:00
tomasz.sowa 685b3ca5ee Makefile: source files from pikotools are now in pikotools/src 2021-05-11 22:22:03 +02:00
tomasz.sowa f1af7e2eeb updated to the current pikotools api from branch api2021 2021-05-11 22:20:46 +02:00
tomasz.sowa 85f9fda984 fixed: in passwd winix function: clear password hash when using rsa encoding 2021-05-11 22:15:52 +02:00
tomasz.sowa bb513b0187 make depend 2021-04-30 01:35:40 +02:00
tomasz.sowa 4277f90bad start working on User and Group classes
- User and Group has been moved to 'models' directory
- removed UserPass struct (passwords fields were put to User struct)
not working yet, we need support for binary blobs in morm
2021-04-30 01:34:48 +02:00
tomasz.sowa ccda2bc2fd added option do_migration_to_winix_fullmorm do the config (only temporarily)
if true then we make Item::do_migration() and exit
2021-04-14 14:13:47 +02:00
tomasz.sowa 4b71530f4c added to Config:
bool Config::HasValue(const wchar_t * name, const wchar_t * value)
2021-04-12 18:55:04 +02:00
tomasz.sowa a8a9db53be remove some Lock() and Unlock() from Plugin 2021-04-11 12:09:42 +02:00
tomasz.sowa 634cf07d44 using Winix::Lock object instead of Lock() method in ThreadManager 2021-04-10 21:12:28 +02:00
tomasz.sowa 0e0c006d5a fixed: thread locking problem in Image: method Lock() was used instead of Winix::Lock object 2021-04-10 19:46:50 +02:00
tomasz.sowa 486067a4b2 clang thread sanitizer reported a data race in App::Start()
synchro.was_stop_signal was read without locking

==================
WARNING: ThreadSanitizer: data race (pid=13831)
  Write of size 1 at 0x000000dc4d18 by thread T1 (mutexes: write M44):
    #0 Winix::App::SpecialThreadForSignals(void*) /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/app.cpp:2226:31 (winix.so+0x1f7465)

  Previous read of size 1 at 0x000000dc4d18 by main thread:
    #0 Winix::App::Start() /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/app.cpp:651:18 (winix.so+0x1ee9af)
    #1 main /disk2Tc/home/tomek/roboczy/prog/winix/winixd/main/main.cpp:222:6 (winix+0x2d74c1)

  Location is global 'Winix::app' of size 65840 at 0x000000db5908 (winix+0x000000dc4d18)

  Mutex M44 (0x000000dc4d10) created at:
    #0 pthread_mutex_lock /disk2Tb/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:4153:3 (winix+0x2ac204)
    #1 Winix::Synchro::Lock() /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/synchro.cpp:68:12 (winix.so+0x2e5822)
    #2 Winix::Lock::Lock(Winix::Synchro*) /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/lock.cpp:53:11 (winix.so+0x295522)
    #3 Winix::FileLog::get_local_date(PT::Date const&) /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/filelog.cpp:98:8 (winix.so+0x261183)
    #4 Winix::Log::PrintDate(PT::Date const&) /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/log.cpp:80:30 (winix.so+0x295a21)
    #5 Winix::LogInfo(Winix::Log&, Winix::LogManipulators, char const*, bool, char const*) /disk2Tc/home/tomek/roboczy/prog/winix/winixd/main/main.cpp:104:6 (winix+0x2d69ec)
    #6 main /disk2Tc/home/tomek/roboczy/prog/winix/winixd/main/main.cpp:190:2 (winix+0x2d7363)

  Thread T1 (tid=100187, running) created by main thread at:
    #0 pthread_create /disk2Tb/usr/src/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:962:3 (winix+0x295bb3)
    #1 Winix::App::StartThreads() /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/app.cpp:2246:2 (winix.so+0x1f7549)
    #2 main /disk2Tc/home/tomek/roboczy/prog/winix/winixd/main/main.cpp:212:6 (winix+0x2d743e)

SUMMARY: ThreadSanitizer: data race /disk2Tc/home/tomek/roboczy/prog/winix/winixd/core/app.cpp:2226:31 in Winix::App::SpecialThreadForSignals(void*)
==================
2021-04-10 17:14:51 +02:00
tomasz.sowa 35e10ed469 updated to the new Pikotools api (new Space struct) 2021-04-09 17:50:58 +02:00
tomasz.sowa 00b980e74b make depend 2021-04-09 16:02:54 +02:00
tomasz.sowa efdc0e7c97 etc/time_zones.conf changed values: "true" -> true, "false" -> false 2021-04-09 10:25:10 +02:00
tomasz.sowa 8b64d2066f changed: new space characters in etc/time_zones.conf:
( -> {
 ) -> }
2021-03-31 20:26:30 +02:00
tomasz.sowa 8d87d9a875 changed in Makefile: we have now one lib pikotools/pikotools.a
make depend
2021-03-31 20:25:09 +02:00
tomasz.sowa 8fc1848ecc uikit updated to 3.6.18 2021-03-31 20:21:24 +02:00
tomasz.sowa bbc0a67153 added support for new morm api
- field(...) methods from Model take now FT structure instead of insertable/updatable/primary_key boolean flags
- table name is set in a prepare_table() method now
- added meta and admin_meta from ItemContent (morm has a field() method with PT::Space argument now)
2021-03-11 18:48:18 +01:00
tomasz.sowa e8ba2a7bd1 fixed: incorrect status was set when editing a file
now System::EditFile() returns boolean
2021-03-11 18:42:26 +01:00
tomasz.sowa 23f1c112a4 make depend 2021-03-10 16:40:22 +01:00
tomasz.sowa 4d76e53554 in after_insert() methods: changed get_last_sequence -> get_last_sequence_for_primary_key 2021-03-09 18:16:29 +01:00
tomasz.sowa 73352e680e Make depend 2021-03-08 21:10:33 +01:00
tomasz.sowa 57aad8b454 removed from Item: update() and save() methods which take the 'url_was_changed' argument
and added ItemModelData (based on morm::ModelData) class which has 'prepare_unique_url' field,
an object of this class is passed to update(), insert() and save() methods

fixed: Dirs::CheckRootDir(): update should update childs too (privileges)

WIP: #4
2021-03-08 21:06:50 +01:00
tomasz.sowa ab5c44a2cb removed some old methods for adding/editing Item from Db 2021-02-25 00:17:07 +01:00
tomasz.sowa 3e84eb9dbf Makefile deps 2021-02-25 00:15:03 +01:00
tomasz.sowa afbe82e9f4 changed the way how prefixes are added to urls
instead at the end we adding a prefix before an extension, e.g: filename_(2).jpg
2021-02-25 00:12:45 +01:00
tomasz.sowa 51b1aed483 removed DbItemQuery and DbItemColumns which were used for database accessing for Item class 2021-02-24 22:54:36 +01:00
tomasz.sowa 32e93a04c5 Item class has been moved to a new directory 'models', a new class has been added: ItemContent
and same fields from Item were moved to ItemContent

Item
- id
- parent_id
- type (file, dir, symlink)
- url
- subject
- template (html template)
- sort_index
- content_id

ItemContent
- id
- ref -> references (renamed)
- user_id
- modification_user_id
- group_id
- privileges
- date_creation
- date_modification
- guest_name
- link_to
- link_redirect
- file_path
- file_fs
- file_type
- file_size
- has_thumb -> file_has_thumb (renamed)
- hash -> file_hash (renamed)
- hash_type -> file_hash_type (renamed)
- content -> content_raw (renamed)
- content_type -> content_raw_type (renamed)
- content_parsed
- content_parsed_type
- meta
- ameta -> meta_admin (renamed)
- modify_index (removed)

WIP: #4
2021-02-24 01:19:47 +01:00
tomasz.sowa 3d7ece15f8 changed version to 0.7.2 2021-02-18 21:07:05 +01:00
tomasz.sowa 541597f355 fixed: in TimeZone::SetTzDst() was used operator && instead of || 2021-02-17 18:36:50 +01:00
tomasz.sowa 5fe843d76b set -std=c++20 in Makefile 2021-02-17 18:07:05 +01:00
tomasz.sowa 3191369ece added 'using PT::FileLog::init' to FileLog to suppress clang warning:
warning: 'Winix::FileLog::init' hides overloaded virtual function [-Woverloaded-virtual]
2021-02-17 18:06:00 +01:00
tomasz.sowa a4de11d69c fixed: Image did not use 'savelog' when creating logs
before commit 4832c7db4b the logs were lost, but after 4832c7db4b
the logs were printed when winix shuts down

in 4832c7db4b at the end of BaseThread::StartRoutine()
has been added a call to save_log()
2021-02-17 16:17:36 +01:00
tomasz.sowa 4832c7db4b fixed: clang address sanitizer reports that there is an use after free bug at the end when winix shuts down:
==3859==ERROR: AddressSanitizer: heap-use-after-free on address 0x61b0000053e0 at pc 0x000800697160 bp 0x7fffffffcfb0 sp 0x7fffffffcfa8
READ of size 8 at 0x61b0000053e0 thread T0
    #0 0x80069715f in PT::MemBuffer<wchar_t, 256ul, 4096ul>::empty() const /usr/home/tomek/roboczy/prog/web.ttmath.org/../pikotools/membuffer/membuffer.h:675:9
    #1 0x80069700d in PT::TextStreamBase<wchar_t, 256ul, 4096ul>::empty() const /usr/home/tomek/roboczy/prog/web.ttmath.org/../pikotools/textstream/textstream.h:161:16
    #2 0x8009af0e3 in PT::FileLog::save_log(PT::TextStreamBase<wchar_t, 256ul, 4096ul>*) /usr/home/tomek/roboczy/prog/pikotools/log/filelog.cpp:105:14
    #3 0x8009b3f8a in PT::Log::save_log() /usr/home/tomek/roboczy/prog/pikotools/log/log.cpp:461:13
    #4 0x8009b3d72 in PT::Log::save_log_and_clear() /usr/home/tomek/roboczy/prog/pikotools/log/log.cpp:448:2
    #5 0x8009b0627 in PT::Log::~Log() /usr/home/tomek/roboczy/prog/pikotools/log/log.cpp:62:2
    #6 0x8007288e7 in Winix::Log::~Log() /usr/home/tomek/roboczy/prog/winix/winixd/core/log.cpp:56:1
    #7 0x8007eac96 in Winix::WinixBase::~WinixBase() /usr/home/tomek/roboczy/prog/winix/winixd/core/winixbase.cpp:51:1
    #8 0x8007eb097 in Winix::WinixModel::~WinixModel() /usr/home/tomek/roboczy/prog/winix/winixd/core/winixmodel.cpp:52:1
    #9 0x80069e552 in Winix::BaseThread::~BaseThread() /usr/home/tomek/roboczy/prog/winix/winixd/core/basethread.cpp:54:1
    #10 0x2f8132 in Winix::Job::~Job() /usr/home/tomek/roboczy/prog/web.ttmath.org/../winix/winixd/core/job.h:54:7
    #11 0x2e0c8a in Winix::System::~System() /usr/home/tomek/roboczy/prog/web.ttmath.org/../winix/winixd/core/system.h:67:7
    #12 0x2df017 in Winix::App::~App() /usr/home/tomek/roboczy/prog/web.ttmath.org/../winix/winixd/core/app.h:70:7
    #13 0x800cc9f50 in __cxa_finalize /hddraidzfs/usr/src/lib/libc/stdlib/atexit.c:238:5
    #14 0x800c5ef10 in exit /hddraidzfs/usr/src/lib/libc/stdlib/exit.c:74:2
    #15 0x25c935 in _start /hddraidzfs/usr/src/lib/csu/amd64/crt1.c:76:2

0x61b0000053e0 is located 1632 bytes inside of 1656-byte region [0x61b000004d80,0x61b0000053f8)
freed by thread T0 here:
    #0 0x2dc07d in operator delete(void*) /hddraidzfs/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:160:3
    #1 0x8007c3b2c in Winix::ThreadManager::StopAll() /usr/home/tomek/roboczy/prog/winix/winixd/core/threadmanager.cpp:189:3
    #2 0x800647474 in Winix::App::WaitForThreads() /usr/home/tomek/roboczy/prog/winix/winixd/core/app.cpp:2122:24
    #3 0x800647311 in Winix::App::Close() /usr/home/tomek/roboczy/prog/winix/winixd/core/app.cpp:340:2
    #4 0x2dec7c in main /usr/home/tomek/roboczy/prog/winix/winixd/main/main.cpp:224:6
    #5 0x25c92e in _start /hddraidzfs/usr/src/lib/csu/amd64/crt1.c:76:7
    #6 0x80033efff  (<unknown module>)

previously allocated by thread T0 here:
    #0 0x2db81d in operator new(unsigned long) /hddraidzfs/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:99:3
    #1 0x8007c17c3 in Winix::ThreadManager::Add(Winix::BaseThread*, wchar_t const*) /usr/home/tomek/roboczy/prog/winix/winixd/core/threadmanager.cpp:77:26
    #2 0x8007b0b81 in Winix::System::Init() /usr/home/tomek/roboczy/prog/winix/winixd/core/system.cpp:170:17
    #3 0x8006468d4 in Winix::App::Init() /usr/home/tomek/roboczy/prog/winix/winixd/core/app.cpp:295:9
    #4 0x2deb7e in main /usr/home/tomek/roboczy/prog/winix/winixd/main/main.cpp:206:11
    #5 0x25c92e in _start /hddraidzfs/usr/src/lib/csu/amd64/crt1.c:76:7
    #6 0x80033efff  (<unknown module>)

in ThreadManager::StopAll() there is item.thread_item_data pointer which was freed (the pointer was pointing to an object with a log_buffer)
but internal Log buffer from item.object was pointing to that object and when thread_tab.clear() was called then the d-ctor was called
and then save_log_and_clear() method was called and tried to use the freed object.
2021-02-17 15:58:05 +01:00
tomasz.sowa be83d62f96 changed html in index templates: [include "index_head_functions_add.html"] -> [include "index_head_adder.html"] 2021-02-16 20:10:29 +01:00
tomasz.sowa 3fd2ef1da4 renamed: html/index_head_functions_add.html -> html/index_head_adder.html 2021-02-16 20:01:38 +01:00
tomasz.sowa d861384889 Merge pull request 'uikit' (#3) from uikit into master
Reviewed-on: #3
2021-02-16 19:52:36 +01:00
tomasz.sowa cfd8e88e57 changed markup in fun_thread.html, removed item_options.html (was not used by winix)
WIP: #2
2021-02-16 19:44:57 +01:00
tomasz.sowa 8169cb5a7e added uikit markup for uname winix function
WIP: #2
2021-02-16 19:28:42 +01:00
tomasz.sowa 8c85cd7346 added uikit markup for stat winix function
WIP: #2
2021-02-16 19:25:36 +01:00
tomasz.sowa 4e202833b2 added uikit markup for rmuser winix function
WIP: #2
2021-02-16 19:21:53 +01:00
tomasz.sowa 4a163bd170 added uikit markup for pw winix function
WIP: #2
2021-02-16 19:12:15 +01:00
tomasz.sowa 85fbc1b882 added uikit markup for man winix function
WIP: #2
2021-02-16 19:03:01 +01:00
tomasz.sowa 61810ff6f9 added uikit markup for last winix function
WIP: #2
2021-02-16 18:56:18 +01:00
tomasz.sowa 3a4a29f56d added uikit markup for ipban winix function
WIP: #2
2021-02-16 18:53:12 +01:00
tomasz.sowa 1fb7ece1b3 fixed: in imgcrop: data-uk-lightbox interfere with menu buttons
WIP: #2
2021-02-16 18:46:39 +01:00
tomasz.sowa f3879dd3a4 added lightbox effect on images in imgcrop winix function
WIP: #2
2021-02-16 18:40:48 +01:00
tomasz.sowa 561014886f added uikit markup for imgcrop winix function
WIP: #2
2021-02-16 18:35:55 +01:00
tomasz.sowa a2b19547a3 fixed: in Functions::CheckSpecialFile() after parsing new mount points
the cur->mount pointer was pointing at the old mount object
(which may no longer exists)
2021-02-16 17:23:36 +01:00
tomasz.sowa 93477091d1 added uikit markup for gallery winix funcion (gallery plugin)
- the main gallery is now 'uikit'
- lightbox updated to version 2.11.3 (now it is using jQuery, beforehand prototype.js was used)
- aino-gallery is called galleriajs now (and updated to 1.6.1)
- themes from galleriajs were removed and some new themes has been added (azur, twelve, folio, fullscreen)
- removed some old mount types for galleries (galleriathumb, galleria1.2.9, galleriathumb1.2.9)

WIP: #2
2021-02-16 16:31:52 +01:00
tomasz.sowa 64d3c62945 added uikit markup for export winix function (plugin export)
WIP: #2
2021-02-16 13:11:39 +01:00
tomasz.sowa 134e27f70a modified login template - removed uk-border-pill class
WIP: #2
2021-02-16 12:56:15 +01:00
tomasz.sowa 5205aa089b modified index templates
some meta information moved to index_head_functions_add.html

WIP: #2
2021-02-16 12:55:35 +01:00
tomasz.sowa b5b9655c1e modified buttons in thread winix function
WIP: #2
2021-02-16 12:54:05 +01:00
tomasz.sowa 173d0894fa modified buttons in showthreads winix function
WIP: #2
2021-02-16 12:52:49 +01:00
tomasz.sowa de6b050fb5 fixed comment in ls html template 2021-02-16 12:51:06 +01:00
tomasz.sowa 37da5e81c5 added uikit markup for createticket, showtickets, ticket winix functions (plugin ticket)
WIP: #2
2021-02-15 19:52:03 +01:00
tomasz.sowa ae8637d455 added uikit markup for: createthread, reply, showthreads and thread winix functions 2021-02-12 18:57:14 +01:00
tomasz.sowa 22a45697fa added uikit markup for subject winix function 2021-02-09 18:48:48 +01:00
tomasz.sowa 55462fca9f added uikit markup for uptime winix function 2021-02-09 18:26:30 +01:00
tomasz.sowa 2799a66c16 added uikit markup for who winix function 2021-02-09 18:11:37 +01:00
tomasz.sowa 9832b17fc2 updated uikit to 3.6.16 2021-02-09 18:10:01 +01:00
tomasz.sowa 8146f42492 added uikit markup for seo winix function 2021-02-08 02:01:37 +01:00
274 changed files with 9715 additions and 11991 deletions
+7 -4
View File
@@ -27,14 +27,14 @@ endif
# CXX = g++-4.8
ifndef CXXFLAGS
CXXFLAGS = -Wall -O0 -g -fPIC -pthread -std=c++17 -I/usr/local/include -I/usr/include/postgresql -DEZC_HAS_SPECIAL_STREAM
CXXFLAGS = -Wall -O0 -g -fPIC -pthread -std=c++20 -I/usr/local/include -I/usr/include/postgresql -I$(GLOBAL_WORKING_DIR)/pikotools/src -I$(GLOBAL_WORKING_DIR)/morm/src -DEZC_HAS_SPECIAL_STREAM -DPT_HAS_MORM
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
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/src
ifndef LDFLAGS
LDFLAGS = -L/usr/local/lib
@@ -61,6 +61,7 @@ all: winix.so plugins winix
winix.so: $(winix.src.files)
@cd core ; $(MAKE) -e
@cd models ; $(MAKE) -e
@cd db ; $(MAKE) -e
@cd functions ; $(MAKE) -e
@cd notify ; $(MAKE) -e
@@ -69,7 +70,7 @@ winix.so: $(winix.src.files)
@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
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(winix_include_paths) core/*.o db/*.o models/*.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/src/pikotools.a $(GLOBAL_WORKING_DIR)/morm/src/morm.a $(LDFLAGS) -lfcgi -lpq -lz -lpthread -lcurl -Wl,-no-whole-archive
winix: winix.so $(winix.src.files)
@@ -96,6 +97,7 @@ FORCE:
clean:
@cd core ; $(MAKE) -e clean
@cd db ; $(MAKE) -e clean
@cd models ; $(MAKE) -e clean
@cd functions ; $(MAKE) -e clean
@cd templates ; $(MAKE) -e clean
@cd notify ; $(MAKE) -e clean
@@ -123,6 +125,7 @@ clean:
depend:
@cd core ; $(MAKE) -e depend
@cd db ; $(MAKE) -e depend
@cd models ; $(MAKE) -e depend
@cd functions ; $(MAKE) -e depend
@cd templates ; $(MAKE) -e depend
@cd notify ; $(MAKE) -e depend
@@ -144,7 +147,7 @@ depend:
# 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)/pikotools/src -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
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -3,7 +3,7 @@ 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
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/src
all: $(o)
+477 -926
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1 +1 @@
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o filelog.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionidmanager.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o
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 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 users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o
+188 -124
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2019, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@
#include "functions/functions.h"
#include "utf8/utf8.h"
#include "convert/convert.h"
#include "models/migration.h"
namespace Winix
@@ -182,13 +182,13 @@ void App::InitPlugins()
bool App::InitFCGI(char * sock, char * sock_user, char * sock_group)
{
if( !WideToUTF8(config.fcgi_socket, sock, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(config.fcgi_socket, sock, WINIX_OS_PATH_SIZE) )
return false;
if( !WideToUTF8(config.fcgi_socket_user, sock_user, WINIX_OS_USERNAME_SIZE) )
if( !wide_to_utf8(config.fcgi_socket_user, sock_user, WINIX_OS_USERNAME_SIZE) )
return false;
if( !WideToUTF8(config.fcgi_socket_group, sock_group, WINIX_OS_USERNAME_SIZE) )
if( !wide_to_utf8(config.fcgi_socket_group, sock_group, WINIX_OS_USERNAME_SIZE) )
return false;
return true;
@@ -273,6 +273,51 @@ return true;
bool App::DoDatabaseMigration()
{
bool ok = true;
Migration migration;
User user;
ItemContent item_content;
Item item;
Group group;
ok = ok && Migration::do_migration(&model_connector, migration);
ok = ok && Migration::do_migration(&model_connector, user);
/*
* do migration of ItemContent before Item
* Item::do_migration_to_3() requires that ItemContent should have new columns
*
*/
ok = ok && Migration::do_migration(&model_connector, item_content);
ok = ok && Migration::do_migration(&model_connector, item);
ok = ok && Migration::do_migration(&model_connector, group);
return ok;
}
bool App::TryToMakeDatabaseMigration()
{
if( config.db_make_migration_if_needed )
{
if( !DoDatabaseMigration() )
{
if( config.db_stop_if_migration_fails )
{
log << log1 << "App: database migration failed, stopping winix" << logend;
return false;
}
}
}
return true;
}
bool App::Init()
{
postgresql_connector.set_conn_param(config.db_database, config.db_user, config.db_pass);
@@ -282,11 +327,13 @@ bool App::Init()
model_connector.set_flat_connector(json_connector);
model_connector.set_db_connector(postgresql_connector);
//model_connector.set_doc_connector(doc_html_connector);
model_connector.set_logger(log);
if( !TryToMakeDatabaseMigration() )
return false;
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
db_conn.WaitForConnection();
db.PostgreSQLsmallerThan10(config.db_postgresql_smaller_than_10);
db.LogQueries(config.log_db_query);
cur.request->Clear();
@@ -495,6 +542,14 @@ void App::ProcessRequestThrow()
{
functions.Parse(); // parsing directories, files, functions and parameters
/*
* set global connector for now
* in the future each thread will have its own model_connector
*
* don't set connector for item_tab - it will be moved out from request
*/
cur.request->item.set_connector(model_connector);
if( !cur.request->dir_tab.empty() )
{
cur.mount = system.mounts.CalcCurMount();
@@ -616,6 +671,8 @@ void App::ClearAfterRequest()
system.mounts.pmount = cur.mount; // IMPROVE ME system.mounts.pmount will be removed
// send_data_buf doesn't have to be cleared and it is better to not clear it (optimizing)
cur.request->item.set_connector(nullptr);
log << logendrequest;
}
catch(...)
@@ -629,20 +686,26 @@ void App::ClearAfterRequest()
void App::Start()
{
while( !synchro.was_stop_signal && FCGX_Accept_r(&fcgi_request) == 0 )
bool was_stop_signal = false;
{
Lock();
Winix::Lock lock(synchro);
was_stop_signal = synchro.was_stop_signal;
}
while( !was_stop_signal && FCGX_Accept_r(&fcgi_request) == 0 )
{
Winix::Lock lock(synchro);
if( synchro.was_stop_signal )
{
was_stop_signal = true;
FCGX_Finish_r(&fcgi_request);
}
else
{
ProcessRequest();
}
Unlock();
}
}
@@ -691,16 +754,7 @@ void App::CreateJSONAnswer()
json_out_stream << L"}\n,\n\"info\": ";
}
if( req.info_serializer )
{
req.info_serializer->Serialize(req.info, json_out_stream, true);
}
else
{
json_out_stream << L"{}";
log << log1 << "App: Request::info_serializer not defined" << logend;
}
req.info.serialize_to_json_stream(json_out_stream, false);
log << log3 << "App: sending JSON answer";
if( !req.return_info_only )
@@ -761,7 +815,7 @@ void App::Make()
if( cur.session->ip_ban && cur.session->ip_ban->IsIPBanned() )
{
PT::Date date(cur.session->ip_ban->expires);
pt::Date date(cur.session->ip_ban->expires);
// IMPROVE ME there is no slog now
//slog << logerror << T("this_ip_is_banned_until") << ' ' << date << " UTC" << logend;
@@ -822,16 +876,19 @@ void App::LogEnvironmentVariables()
void App::LogEnvironmentHTTPVariables()
{
PT::Space::Table::iterator i = cur.request->headers_in.table.begin();
for( ; i != cur.request->headers_in.table.end() ; ++i)
if( cur.request->headers_in.is_object() )
{
log << log1 << "HTTP Env: " << i->first << "=";
pt::Space::ObjectType::iterator i = cur.request->headers_in.value.value_object.begin();
if( i->second.size() == 1 )
log << i->second[0] << logend;
else
log << "(incorrect value table size, should be one but is " << i->second.size() << ")" << logend;
for( ; i != cur.request->headers_in.value.value_object.end() ; ++i)
{
log << log1 << "HTTP Env: " << i->first << "=";
if( i->second->is_wstr() )
log << *i->second->get_wstr() << logend;
else
log << "(incorrect value type, expected wstr)" << logend;
}
}
}
@@ -877,7 +934,7 @@ void App::SetEnv(const char * name, std::wstring & env)
if( v )
{
PT::UTF8ToWide(v, env);
pt::utf8_to_wide(v, env);
}
}
@@ -910,12 +967,12 @@ void App::ReadEnvHTTPVariables()
{
char * env = *e;
if( PT::IsSubStringNoCasep("HTTP_", env) )
if( pt::is_substr_nc("HTTP_", env) )
{
env += http_prefix_len;
// cookies we have in a different table
if( !PT::IsSubStringNoCasep("COOKIE=", env) )
if( !pt::is_substr_nc("COOKIE=", env) )
{
if( SaveEnvHTTPVariable(env) )
{
@@ -945,7 +1002,7 @@ bool App::SaveEnvHTTPVariable(const char * env)
for( ; env[i] != 0 && env[i] != '=' && i < Request::INPUT_HEADER_NAME_MAX_LENGTH ; ++i)
{
header_name[i] = PT::ToLower(env[i]);
header_name[i] = pt::to_lower(env[i]);
}
header_name[i] = 0;
@@ -974,11 +1031,12 @@ bool App::SaveEnvHTTPVariable(const char * env)
return false;
}
PT::UTF8ToWide(header_name, http_header);
pt::utf8_to_wide(header_name, http_header_name);
pt::utf8_to_wide(header_value, http_header_value);
std::wstring & inserted_header = cur.request->headers_in.Add(http_header, L"", true);
PT::UTF8ToWide(header_value, inserted_header);
http_header.clear();
cur.request->headers_in.add(http_header_name, http_header_value);
http_header_name.clear();
http_header_value.clear();
return true;
}
@@ -990,11 +1048,11 @@ void App::ReadEnvRemoteIP()
if( config.check_proxy_ip_header )
{
http_header = L"HTTP_";
http_header += config.proxy_ip_header;
PT::ToUpper(http_header);
http_header_name = L"HTTP_";
http_header_name += config.proxy_ip_header;
pt::to_upper_emplace(http_header_name);
PT::WideToUTF8(http_header, http_header_8bit);
pt::wide_to_utf8(http_header_name, http_header_8bit);
v = FCGX_GetParam(http_header_8bit.c_str(), fcgi_request.envp);
}
else
@@ -1005,7 +1063,7 @@ void App::ReadEnvRemoteIP()
if( v )
{
cur.request->ip = (int)inet_addr(v);
PT::UTF8ToWide(v, cur.request->ip_str);
pt::utf8_to_wide(v, cur.request->ip_str);
}
}
@@ -1018,16 +1076,16 @@ void App::CheckRequestMethod()
if( !cur.request->env_request_method.empty() )
{
if( PT::ToLower(cur.request->env_request_method[0]) == 'g' )
if( pt::to_lower(cur.request->env_request_method[0]) == 'g' )
cur.request->method = Request::get;
else
if( PT::ToLower(cur.request->env_request_method[0]) == 'p' )
if( pt::to_lower(cur.request->env_request_method[0]) == 'p' )
cur.request->method = Request::post;
else
if( PT::ToLower(cur.request->env_request_method[0]) == 'h' )
if( pt::to_lower(cur.request->env_request_method[0]) == 'h' )
cur.request->method = Request::head;
else
if( PT::ToLower(cur.request->env_request_method[0]) == 'd' )
if( pt::to_lower(cur.request->env_request_method[0]) == 'd' )
cur.request->method = Request::delete_;
}
}
@@ -1043,7 +1101,7 @@ void App::CheckSSL()
if( config.assume_connection_is_through_ssl )
cur.request->using_ssl = true;
else
if( PT::EqualNoCase(cur.request->env_https.c_str(), L"on") )
if( pt::is_equal_nc(cur.request->env_https.c_str(), L"on") )
cur.request->using_ssl = true;
}
@@ -1078,7 +1136,6 @@ void App::ReadPostJson()
const int buffer_len = sizeof(buffer) / sizeof(char) - 1;
int read_len;
post_json_parser.SetSpace(cur.request->post_in);
post_buffer.clear();
post_buffer.reserve(1024 * 1024 * 5); // IMPROVEME add to config?
@@ -1087,7 +1144,7 @@ void App::ReadPostJson()
do
{
// IMPROVE ME
// we can read to PT::TextBuffer and make a PT::JSONToSpaceParser::Parse(PT::TextBuffer &) method
// we can read to pt::TextBuffer and make a pt::JSONToSpaceParser::Parse(pt::TextBuffer &) method
read_len = FCGX_GetStr(buffer, buffer_len, fcgi_request.in);
if( read_len > 0 )
@@ -1097,13 +1154,17 @@ void App::ReadPostJson()
if( !post_buffer.empty() )
{
PT::JSONToSpaceParser::Status status = post_json_parser.ParseString(post_buffer.c_str());
pt::SpaceParser::Status status = space_parser.parse_json(post_buffer.c_str(), cur.request->post_in);
post_buffer.clear();
if( status != PT::JSONToSpaceParser::ok )
if( status != pt::SpaceParser::ok )
{
log << log1 << "App: cannot parse the input stream as a JSON object, status: " << (int)status << logend;
cur.request->post_in.Clear();
log << log1 << "App: cannot parse the input stream as an JSON object";
if( status == pt::SpaceParser::syntax_error )
log << ", syntax error in line: " << space_parser.get_last_parsed_line() << logend;
cur.request->post_in.clear();
// return an error (http error of some kind?)
}
}
@@ -1122,13 +1183,13 @@ void App::ReadPostVars()
if( cur.request->method == Request::post || cur.request->method == Request::delete_ )
{
if( PT::IsSubStringNoCase(L"multipart/form-data", cur.request->env_content_type.c_str()) )
if( pt::is_substr_nc(L"multipart/form-data", cur.request->env_content_type.c_str()) )
{
log << log3 << "App: post content type: multipart/form-data" << logend;
post_multi_parser.Parse(fcgi_request.in, cur.request->post_tab, cur.request->post_file_tab);
}
else
if( PT::IsSubStringNoCase(L"application/json", cur.request->env_content_type.c_str()) )
if( pt::is_substr_nc(L"application/json", cur.request->env_content_type.c_str()) )
{
log << log3 << "App: post content type: application/json" << logend;
ReadPostJson();
@@ -1184,7 +1245,7 @@ void App::PrepareSessionCookie()
}
else
{
PT::Date expires = cur.request->start_time + config.session_remember_max_idle;
pt::Date expires = cur.request->start_time + config.session_remember_max_idle;
cur.request->AddCookie(config.http_session_id_name, cookie_id_string, expires);
}
}
@@ -1193,9 +1254,9 @@ void App::PrepareSessionCookie()
bool App::AddHeader(const wchar_t * name, const wchar_t * value)
{
if( !cur.request->out_headers.GetValue(name) )
if( !cur.request->out_headers.has_key(name) )
{
cur.request->out_headers.Add(name, value);
cur.request->out_headers.add(name, value);
return true;
}
@@ -1205,9 +1266,9 @@ return false;
bool App::AddHeader(const std::wstring & name, const std::wstring & value)
{
if( !cur.request->out_headers.GetValue(name) )
if( !cur.request->out_headers.has_key(name) )
{
cur.request->out_headers.Add(name, value);
cur.request->out_headers.add(name, value);
return true;
}
@@ -1215,11 +1276,11 @@ return false;
}
bool App::AddHeader(const wchar_t * name, const PT::WTextStream & value)
bool App::AddHeader(const wchar_t * name, const pt::WTextStream & value)
{
if( !cur.request->out_headers.GetValue(name) )
if( !cur.request->out_headers.has_key(name) )
{
cur.request->out_headers.Add(name, value);
cur.request->out_headers.add_stream(name, value);
return true;
}
@@ -1227,11 +1288,11 @@ return false;
}
bool App::AddHeader(const std::wstring & name, const PT::WTextStream & value)
bool App::AddHeader(const std::wstring & name, const pt::WTextStream & value)
{
if( !cur.request->out_headers.GetValue(name) )
if( !cur.request->out_headers.has_key(name) )
{
cur.request->out_headers.Add(name, value);
cur.request->out_headers.add_stream(name, value);
return true;
}
@@ -1239,7 +1300,7 @@ return false;
}
bool App::PrepareHeadersStaticCreateResource(PT::WTextStream & out_path)
bool App::PrepareHeadersStaticCreateResource(pt::WTextStream & out_path)
{
size_t i = 0;
Item * dir = system.dirs.GetDir(system.mounts.pmount->dir_id);
@@ -1286,7 +1347,7 @@ void App::PrepareHeadersStatic()
return;
}
PT::WTextStream path;
pt::WTextStream path;
path << config.static_dirs[index] << L"/";
if( !PrepareHeadersStaticCreateResource(path) )
@@ -1304,34 +1365,29 @@ void App::PrepareHeadersStatic()
void App::PrepareHeaderContentType()
{
std::wstring * value = 0;
if( !cur.request->out_headers.GetValue(L"Content-Type") )
if( !cur.request->out_headers.has_key(L"Content-Type") )
{
if( cur.request->return_json )
{
value = &cur.request->out_headers.Add(L"Content-Type", L"application/json");
cur.request->out_headers.add(L"Content-Type", L"application/json; charset=UTF-8");
}
else
{
switch( config.content_type_header )
{
case 1:
value = &cur.request->out_headers.Add(L"Content-Type", L"application/xhtml+xml");
cur.request->out_headers.add(L"Content-Type", L"application/xhtml+xml; charset=UTF-8");
break;
case 2:
value = &cur.request->out_headers.Add(L"Content-Type", L"application/xml");
cur.request->out_headers.add(L"Content-Type", L"application/xml; charset=UTF-8");
break;
case 0:
default:
value = &cur.request->out_headers.Add(L"Content-Type", L"text/html");
cur.request->out_headers.add(L"Content-Type", L"text/html; charset=UTF-8");
}
}
if( value )
*value += L"; charset=UTF-8";
}
}
@@ -1413,7 +1469,7 @@ void App::PrepareHeadersNormal(Header header, size_t output_size)
if( output_size != static_cast<size_t>(-1) )
{
PT::WTextStream buf;
pt::WTextStream buf;
buf << output_size;
AddHeader(L"Content-Length", buf);
}
@@ -1426,25 +1482,32 @@ void App::PrepareHeadersNormal(Header header, size_t output_size)
// and if compression is enabled the client's browser will not be able to decompress the stream
void App::SendHeaders()
{
PT::Space::Table::iterator i;
PT::Space & headers = cur.request->out_headers;
pt::Space::ObjectType::iterator i;
pt::Space & headers = cur.request->out_headers;
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_HEADERS, &headers);
for(i=headers.table.begin() ; i != headers.table.end() ; ++i)
if( headers.is_object() )
{
if( i->second.size() == 1 )
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_HEADERS, &headers);
for(i=headers.value.value_object.begin() ; i != headers.value.value_object.end() ; ++i)
{
PT::WideToUTF8(i->first, aheader_name);
PT::WideToUTF8(i->second[0], aheader_value);
if( i->second->is_wstr() )
{
pt::wide_to_utf8(i->first, aheader_name);
pt::wide_to_utf8(*i->second->get_wstr(), aheader_value);
FCGX_PutS(aheader_name.c_str(), fcgi_request.out);
FCGX_PutS(": ", fcgi_request.out);
FCGX_PutS(aheader_value.c_str(), fcgi_request.out);
FCGX_PutS("\r\n", fcgi_request.out);
FCGX_PutS(aheader_name.c_str(), fcgi_request.out);
FCGX_PutS(": ", fcgi_request.out);
FCGX_PutS(aheader_value.c_str(), fcgi_request.out);
FCGX_PutS("\r\n", fcgi_request.out);
if( config.log_http_answer_headers )
log << log1 << "HTTP Header: " << aheader_name << ": " << aheader_value << logend;
if( config.log_http_answer_headers )
log << log1 << "HTTP Header: " << aheader_name << ": " << aheader_value << logend;
}
else
{
log << log2 << "Skipping HTTP Header: " << i->first << " - it's not a wstr" << logend;
}
}
}
}
@@ -1453,26 +1516,33 @@ void App::SendHeaders()
void App::SendCookies()
{
PT::Space::Table::iterator i;
PT::Space & cookies = cur.request->out_cookies;
pt::Space::ObjectType::iterator i;
pt::Space & cookies = cur.request->out_cookies;
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_COOKIES, &cookies);
for(i=cookies.table.begin() ; i != cookies.table.end() ; ++i)
if( cookies.is_object() )
{
if( i->second.size() == 1 )
plugin.Call(WINIX_PREPARE_TO_SEND_HTTP_COOKIES, &cookies);
for(i=cookies.value.value_object.begin() ; i != cookies.value.value_object.end() ; ++i)
{
PT::WideToUTF8(i->first, aheader_name);
PT::WideToUTF8(i->second[0], aheader_value);
if( i->second->is_wstr() )
{
pt::wide_to_utf8(i->first, aheader_name);
pt::wide_to_utf8(*i->second->get_wstr(), aheader_value);
FCGX_PutS("Set-Cookie: ", fcgi_request.out);
FCGX_PutS(aheader_name.c_str(), fcgi_request.out);
FCGX_PutS("=", fcgi_request.out);
FCGX_PutS(aheader_value.c_str(), fcgi_request.out);
FCGX_PutS("\r\n", fcgi_request.out);
FCGX_PutS("Set-Cookie: ", fcgi_request.out);
FCGX_PutS(aheader_name.c_str(), fcgi_request.out);
FCGX_PutS("=", fcgi_request.out);
FCGX_PutS(aheader_value.c_str(), fcgi_request.out);
FCGX_PutS("\r\n", fcgi_request.out);
if( config.log_http_answer_headers )
log << log1 << "HTTP Header: Set-Cookie: " << aheader_name << "=" << aheader_value << logend;
if( config.log_http_answer_headers )
log << log1 << "HTTP Header: Set-Cookie: " << aheader_name << "=" << aheader_value << logend;
}
else
{
log << log2 << "Skipping Cookie: " << i->first << " - it's not a wstr" << logend;
}
}
}
}
@@ -1511,16 +1581,16 @@ void App::PrepareHeaders(bool compressing, int compress_encoding, Header header,
void App::PrepareStandardJSONFields()
{
PT::Space & info = cur.request->info;
pt::Space & info = cur.request->info;
if( !info.GetFirstValue(L"status") )
if( !info.has_key(L"status") )
{
info.Add(L"status", cur.request->status);
info.add(L"status", cur.request->status);
}
if( !cur.request->redirect_to.empty() && !info.GetFirstValue(L"redirect_to") )
if( !cur.request->redirect_to.empty() && !info.has_key(L"redirect_to") )
{
info.Add(L"redirect_to", cur.request->redirect_to);
info.add(L"redirect_to", cur.request->redirect_to);
}
}
@@ -1717,7 +1787,7 @@ size_t output_size = 0;
SelectCompression(source->length(), compressing, compress_encoding);
PT::WideToUTF8(*source, output_8bit);
pt::wide_to_utf8(*source, output_8bit);
// !! IMPROVE ME add to log the binary stream as well
if( config.log_server_answer )
@@ -1815,12 +1885,6 @@ int compress_encoding;
void App::SendAnswer()
{
if( !cur.request->info_serializer )
{
json_generic_serializer.Clear(); // !! IMPROVE ME add to the end of a request
cur.request->info_serializer = &json_generic_serializer;
}
if( cur.request->return_json )
PrepareStandardJSONFields();
@@ -1957,10 +2021,10 @@ void App::LogUserGroups()
bool App::DropPrivileges(char * user, char * group)
{
if( !WideToUTF8(config.user, user, WINIX_OS_USERNAME_SIZE) )
if( !wide_to_utf8(config.user, user, WINIX_OS_USERNAME_SIZE) )
return false;
if( !WideToUTF8(config.group, group, WINIX_OS_USERNAME_SIZE) )
if( !wide_to_utf8(config.group, group, WINIX_OS_USERNAME_SIZE) )
return false;
return true;
@@ -2205,7 +2269,7 @@ int sig;
app->synchro.was_stop_signal = true;
FCGX_ShutdownPending();
PT::WideToUTF8(app->config.fcgi_socket, app->socket_to_send_on_exit);
pt::wide_to_utf8(app->config.fcgi_socket, app->socket_to_send_on_exit);
app->Unlock();
app->SendEmptyFastCGIPacket();
+12 -9
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,7 +54,6 @@
#include "cookieparser.h"
#include "postmultiparser.h"
#include "acceptencodingparser.h"
#include "space/jsontospaceparser.h"
#include "winixrequest.h"
#include "log/log.h"
@@ -144,7 +143,7 @@ private:
PostParser post_parser;
PostMultiParser post_multi_parser;
PT::JSONToSpaceParser post_json_parser;
pt::SpaceParser space_parser;
std::string post_buffer;
CookieParser cookie_parser;
@@ -156,14 +155,14 @@ private:
pthread_t signal_thread;
std::string socket_to_send_on_exit;
std::string send_data_buf;
PT::SpaceToJSON json_generic_serializer;
TextStream<std::wstring> json_out_stream;
std::string aheader_name, aheader_value;
std::wstring html_filtered;
std::string output_8bit;
BinaryPage compressed_output;
std::wstring cookie_id_string;
std::wstring http_header;
std::wstring http_header_name;
std::wstring http_header_value;
std::string http_header_8bit;
morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector
@@ -182,7 +181,7 @@ private:
//////////////////////////
// log_buffer for the main thread
PT::WTextStream log_buffer;
pt::WTextStream log_buffer;
// logger only for App object
Log log;
@@ -239,9 +238,9 @@ private:
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);
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();
@@ -267,6 +266,10 @@ private:
void CreateStaticTree();
bool DoDatabaseMigration();
bool TryToMakeDatabaseMigration();
// !! IMPROVE ME
// !! move to the session manager?
time_t last_sessions_save;
+3 -2
View File
@@ -54,13 +54,13 @@ 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);
}
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);
}
@@ -254,6 +254,7 @@ void * BaseThread::StartRoutine(void * this_object)
}
}
base->save_log();
pthread_exit(0);
return 0;
}
+2 -2
View File
@@ -54,8 +54,8 @@ public:
BaseThread();
virtual ~BaseThread();
void set_main_log_buffer(PT::WTextStream * log_buffer);
void set_main_file_log(PT::FileLog * file_log);
void set_main_log_buffer(pt::WTextStream * log_buffer);
void set_main_file_log(pt::FileLog * file_log);
// work mode
+35 -67
View File
@@ -55,7 +55,7 @@ void Config::SetFileLog(FileLog * file_log)
}
void Config::SetLogBuffer(PT::WTextStream * log_buffer)
void Config::SetLogBuffer(pt::WTextStream * log_buffer)
{
log.SetLogBuffer(log_buffer);
}
@@ -66,26 +66,22 @@ void Config::ShowError()
switch( parser.status )
{
case PT::SpaceParser::no_space:
log << log2 << "Config: space not set" << logend;
break;
case PT::SpaceParser::ok:
case pt::SpaceParser::ok:
log << log2 << "Config: syntax ok" << logend;
break;
case PT::SpaceParser::cant_open_file:
case pt::SpaceParser::cant_open_file:
if( errors_to_stdout )
std::wcout << L"Config: I cannot open a config file: " << config_file << std::endl;
log << log1 << "Config: cant open a config file: " << config_file << logend;
break;
case PT::SpaceParser::syntax_error:
case pt::SpaceParser::syntax_error:
if( errors_to_stdout )
std::wcout << "Config: syntax error, line: " << parser.line << std::endl;
std::wcout << "Config: syntax error, line: " << parser.get_last_parsed_line() << std::endl;
log << log1 << "Config: syntax error, line: " << parser.line << logend;
log << log1 << "Config: syntax error, line: " << parser.get_last_parsed_line() << logend;
break;
}
}
@@ -106,11 +102,9 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
}
log << log2 << "Config: reading a config file" << logend;
pt::SpaceParser::Status status = parser.parse_space_file(config_file, space);
parser.SetSpace(space);
PT::SpaceParser::Status status = parser.Parse(config_file);
if( status == PT::SpaceParser::ok )
if( status == pt::SpaceParser::ok )
{
AssignValues(stdout_is_closed);
SetAdditionalVariables();
@@ -194,7 +188,8 @@ void Config::AssignValues(bool stdout_is_closed)
db_database = Text(L"db_database");
db_user = Text(L"db_user");
db_pass = Text(L"db_pass");
db_postgresql_smaller_than_10 = Bool(L"db_postgresql_smaller_than_10", false);
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");
@@ -382,150 +377,123 @@ void Config::CheckPasswd()
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)
{
return space.Text(name, def);
return space.to_wstr(name, def);
}
std::wstring Config::Text(const std::wstring & name, const wchar_t * def)
{
return space.Text(name, def);
}
std::wstring & Config::TextRef(const wchar_t * name)
{
return space.TextRef(name);
}
std::wstring & Config::TextRef(const wchar_t * name, const wchar_t * def)
{
return space.TextRef(name, def);
}
std::wstring & Config::TextRef(const std::wstring & name, const wchar_t * def)
{
return space.TextRef(name, def);
return space.to_wstr(name, def);
}
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)
{
return space.Int(name, def);
return space.to_int(name, 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)
{
return space.Long(name);
return space.to_long(name);
}
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)
{
return space.Long(name, def);
return space.to_long(name, def);
}
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)
{
return space.Size(name, def);
return space.to_ulong(name, 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)
{
return space.Bool(name);
return space.to_bool(name);
}
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)
{
return space.Bool(name, def);
return space.to_bool(name, def);
}
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)
{
return space.ListText(name, list);
return space.to_list(name, list);
}
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)
{
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);
//}
+11 -15
View File
@@ -198,10 +198,11 @@ public:
std::wstring db_user;
std::wstring db_pass;
// is the PostgreSQL later than 10
// default false
// if true then we are not using ROW() statements in sql query
bool db_postgresql_smaller_than_10;
// make database migration if needed
//
bool db_make_migration_if_needed;
bool db_stop_if_migration_fails;
// the name of the cookie which has the session identifier
std::wstring http_session_id_name;
@@ -619,6 +620,7 @@ public:
// 2 - application/xml - for XHTML 1.0 or for XHTML 1.1
// default: 0
// if utf8 is true then "; charset=UTF-8" will also be appended
// may it would be better to set just the string here instead of integers?
int content_type_header;
// global umask
@@ -793,10 +795,6 @@ public:
std::wstring Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const wchar_t * def);
std::wstring & TextRef(const wchar_t * name);
std::wstring & TextRef(const wchar_t * name, const wchar_t * def);
std::wstring & TextRef(const std::wstring & name, const wchar_t * def);
int Int(const wchar_t *);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
@@ -812,25 +810,23 @@ public:
bool ListText(const wchar_t * name, std::vector<std::wstring> & list);
bool ListText(const std::wstring & name, std::vector<std::wstring> & list);
bool HasValue(const wchar_t * name, const wchar_t * value);
bool HasValue(const wchar_t * name, const std::wstring & value);
bool HasValue(const std::wstring & name, const wchar_t * value);
bool HasValue(const wchar_t * name, const wchar_t * value);
bool HasValue(const std::wstring & name, const std::wstring & value);
// for debug
void Print(std::wostream & out);
//void Print(std::wostream & out);
// raw access to the config
PT::Space space;
pt::Space space;
void SetFileLog(FileLog * file_log);
void SetLogBuffer(PT::WTextStream * log_buffer);
void SetLogBuffer(pt::WTextStream * log_buffer);
private:
PT::SpaceParser parser;
pt::SpaceParser parser;
bool errors_to_stdout;
Log log;
+32 -28
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2018, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* 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.set_dependency(this);
PT::WideToUTF8(config->opensll_path, command);
pt::wide_to_utf8(config->opensll_path, command);
run.Cmd(command);
run.Par("dgst");
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)
{
PT::WideToUTF8(in, inlen, bufina);
pt::wide_to_utf8(in, inlen, bufina);
int res = HashBin(hash, bufina.c_str(), bufina.size(), out);
bufina.clear();
@@ -211,7 +211,7 @@ bool Crypt::RSA(bool encrypt, const char * keypath, const char * in, size_t inle
return false;
run.Clear();
PT::WideToUTF8(config->opensll_path, command);
pt::wide_to_utf8(config->opensll_path, command);
run.Cmd(command);
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)
{
PT::WideToUTF8(keypath, keypatha);
pt::wide_to_utf8(keypath, keypatha);
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;
up.pass_hash_salted = false;
user.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_salted = up.pass;
pass_org = user.password;
pass_salted = user.password;
pass_salted += salt;
if( HashHex(up.pass_type, pass_salted, up.pass) )
if( HashHex(user.pass_type, pass_salted, user.password) )
{
if( !salt.empty() )
up.pass_hash_salted = true;
user.pass_hash_salted = true;
}
else
{
log << log1 << "Crypt: problem with generating a hash, the password will not be hashed" << logend;
up.pass = pass_org;
up.pass_type = WINIX_CRYPT_HASH_NONE;
user.password = pass_org;
user.pass_type = WINIX_CRYPT_HASH_NONE;
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;
ClearString(up.pass_encrypted);
ClearString(user.pass_encrypted);
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;
}
else
{
ClearString(up.pass_encrypted);
ClearString(user.pass_encrypted);
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);
PassCrypt(path_to_rsa_private_key, up);
PassHash(salt, user);
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();
if( config->pass_hash_use_salt && !config->pass_hash_salt.empty() )
PassHash(config->pass_hash_salt, up);
PassHash(config->pass_hash_salt, user);
else
PassHash(empty, up);
PassHash(empty, user);
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
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,7 @@
#include <string>
#include "run.h"
#include "config.h"
#include "user.h"
#include "models/user.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
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
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)
*/
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_encrypted - encrypted password (if not empty)
*/
void PassHashCrypt(UserPass & up);
void PassHashCrypt(User & user);
/*
+2 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,8 +37,8 @@
#include <list>
#include <map>
#include "item.h"
#include "winixbase.h"
#include "models/item.h"
namespace Winix
+36 -20
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <ctime>
#include "dirs.h"
#include "error.h"
#include "notify/notify.h"
@@ -76,7 +77,7 @@ void Dirs::Clear()
bool Dirs::HasReadExecAccessForRoot(const Item & item)
{
// there must be at least one 'x' (for the root)
return (item.privileges & 01111) != 0;
return (item.item_content.privileges & 01111) != 0;
}
@@ -88,28 +89,32 @@ void Dirs::CheckRootDir()
{
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;
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;
}
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.parent_id = -1;
root.user_id = -1;
root.group_id = -1;
root.privileges = 07555;
root.item_content.user_id = -1;
root.item_content.group_id = -1;
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)
// !! zrobic jakis wyjatek do wprowadzania roota?
if( db->AddItem(root) == WINIX_ERR_OK )
if( root.insert(item_data) )
{
dir_tab.PushBack(root);
}
@@ -122,7 +127,15 @@ void Dirs::ReadDirs()
{
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();
dir_tab.FindSpecialFolders();
}
@@ -723,7 +736,7 @@ 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 )
*pdir = 0;
@@ -731,9 +744,11 @@ Error Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int not
if( item.type != Item::dir )
return WINIX_ERR_DIR_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 )
{
Item * d = AddDir(item);
@@ -764,10 +779,11 @@ Item * Dirs::CreateVarDir()
if( root )
{
v.set_connector(root->get_connector());
v.parent_id = root->id;
v.user_id = root->user_id;
v.group_id = root->group_id;
v.privileges = root->privileges;
v.item_content.user_id = root->item_content.user_id;
v.item_content.group_id = root->item_content.group_id;
v.item_content.privileges = root->item_content.privileges;
v.subject = L"var";
v.url = L"var";
v.type = Item::dir;
+3 -4
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,12 +39,11 @@
#include <vector>
#include <map>
#include <string>
#include "item.h"
#include "dircontainer.h"
#include "db/db.h"
#include "request.h"
#include "winixmodel.h"
#include "models/item.h"
@@ -115,7 +114,7 @@ public:
Item * CreateVarDir();
// !! 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
// "/" -> 0 (root dir)
+3 -3
View File
@@ -66,7 +66,7 @@ void FileLog::set_synchro(Synchro * synchro)
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;
}
@@ -91,7 +91,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 )
{
@@ -100,7 +100,7 @@ PT::Date FileLog::get_local_date(const PT::Date & date)
if( tz )
{
PT::Date local_date = tz->ToLocal(date);
pt::Date local_date = tz->ToLocal(date);
return local_date;
}
else
+7 -3
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018, Tomasz Sowa
* Copyright (c) 2018-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -49,7 +49,7 @@ namespace Winix
class TimeZones;
class FileLog : public PT::FileLog
class FileLog : public pt::FileLog
{
public:
@@ -58,10 +58,14 @@ public:
void set_synchro(Synchro * synchro);
// 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 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();
bool should_save_each_line();
+11 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,7 +63,16 @@ void Groups::ReadGroups(Db * db)
{
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);
}
}
+1 -1
View File
@@ -37,7 +37,7 @@
#include <map>
#include "group.h"
#include "models/group.h"
#include "ugcontainer.h"
#include "db/db.h"
#include "winixmodel.h"
+4 -4
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -143,7 +143,7 @@ void HttpSimpleParser::ReadName()
}
if( getchar_returns_utf8_chars )
PT::UTF8ToWide(utf8_token, last_name);
pt::utf8_to_wide(utf8_token, last_name);
if( last_c == '=' )
last_c = GetChar();
@@ -173,7 +173,7 @@ void HttpSimpleParser::ReadQuotedValue()
}
if( getchar_returns_utf8_chars )
PT::UTF8ToWide(utf8_token, last_value);
pt::utf8_to_wide(utf8_token, last_value);
if( last_c == '"' )
last_c = GetChar();
@@ -204,7 +204,7 @@ void HttpSimpleParser::ReadNormalValue()
}
if( getchar_returns_utf8_chars )
PT::UTF8ToWide(utf8_token, last_value);
pt::utf8_to_wide(utf8_token, last_value);
}
+37 -22
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -267,7 +267,7 @@ bool end;
do
{
class Lock lock_object(synchro);
Winix::Lock lock_object(synchro);
if( i != image_tab.end() )
{
@@ -294,7 +294,7 @@ bool end;
void Image::Add(const std::wstring & in, TextStream<std::string> & out)
{
PT::WideToUTF8(in, add_tempa);
pt::wide_to_utf8(in, add_tempa);
out << add_tempa;
}
@@ -377,7 +377,7 @@ bool Image::CreateInputFileName()
{
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
<< " doesn't have a thumbnail yet (skipping)" << logend;
@@ -387,7 +387,7 @@ bool Image::CreateInputFileName()
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;
}
else
@@ -404,7 +404,7 @@ void Image::CreateTmpFileName()
{
stream_tmp_path.Clear();
stream_tmp_path << config->upload_dir << L"/tmp/image_" << std::time(0);
PT::WideToUTF8(stream_tmp_path.Str(), tmp_file_name);
pt::wide_to_utf8(stream_tmp_path.Str(), tmp_file_name);
}
@@ -412,13 +412,16 @@ void Image::CreateTmpFileName()
// second thread (objects are not locked)
bool Image::CreateCommand()
{
class Lock lock_object(synchro);
Winix::Lock lock_object(synchro);
iq.SetAll(true, false);
iq.WhereId(item_work.file_id);
// iq.SetAll(true, false);
// 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
if( db->GetItem(file_work, iq) != WINIX_ERR_OK )
if( !file_work.found() )
return false;
if( !CreateInputFileName() )
@@ -483,10 +486,13 @@ void Image::ImageSavedCorrectly()
{
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;
db->EditHasThumbById(true, file_work.id);
file_work.item_content.file_has_thumb = true;
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;
@@ -525,14 +531,22 @@ void Image::ImageSavedCorrectly()
// second thread (objects are not locked)
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
iq.SetAll(true, false);
iq.WhereId(item_work.file_id);
//iq.SetAll(true, false);
//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 ||
item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB ||
item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB );
@@ -558,7 +572,7 @@ void Image::SaveImage()
{
log << log1 << "Image: cannot create a destination path" << logend;
}
}
//}
}
@@ -576,11 +590,12 @@ void Image::CreateImage()
}
else
{
class Lock lock_object(synchro);
log << log3 << "Image: some problems with creating an image"
<< ", 'convert' process returned: " << res << logend;
}
}
log << logsave;
}
@@ -597,8 +612,8 @@ void Image::CreateImage()
void Image::CreateThumbnail()
{
PT::WideToUTF8(item_work.source, sourcea);
PT::WideToUTF8(item_work.dst, dsta);
pt::wide_to_utf8(item_work.source, sourcea);
pt::wide_to_utf8(item_work.dst, dsta);
MagickWandGenesis();
+2 -3
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,8 +40,8 @@
#include "basethread.h"
#include "textstream.h"
#include "db/db.h"
#include "core/item.h"
#include "core/config.h"
#include "models/item.h"
namespace Winix
@@ -187,7 +187,6 @@ private:
std::wstring src_path, dst_path;
TextStream<std::string> command;
TextStream<std::wstring> stream_tmp_path;
DbItemQuery iq;
std::string add_tempa;
std::string input_file_name;
std::string tmp_file_name;
+2 -2
View File
@@ -148,7 +148,7 @@ void IPBanContainer::PrintTab()
{
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: ";
date = ipban_tab[i].expires;
@@ -168,7 +168,7 @@ void IPBanContainer::PrintTab2()
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: ";
date = ipban.expires;
-156
View File
@@ -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
+4 -4
View File
@@ -60,7 +60,7 @@ void Job::CheckPriority(int & priority) const
// first thread (objects locked)
void Job::Add(PT::Space & job, int priority)
void Job::Add(pt::Space & job, int priority)
{
CheckPriority(priority);
jobs_queue_tab[priority].push(job);
@@ -150,7 +150,7 @@ bool is_empty;
Lock();
// references will not be invalidated after insertion to jobs_queue
// (jobs_queue is std::queue and it uses std::deque by default)
PT::Space & job = jobs_queue.front();
pt::Space & job = jobs_queue.front();
Unlock();
DoJob(job);
@@ -165,7 +165,7 @@ bool is_empty;
// second thread (objects not locked)
void Job::DoJob(PT::Space & job)
void Job::DoJob(pt::Space & job)
{
try
{
@@ -181,7 +181,7 @@ void Job::DoJob(PT::Space & job)
// second thread (objects not locked)
void Job::DoWinixJob(PT::Space & job)
void Job::DoWinixJob(pt::Space & job)
{
//log << log1 << "standard winix job: " << job.Text(L"type") << logend;
}
+4 -4
View File
@@ -61,7 +61,7 @@ public:
add a new job to the queue
priority: 0-31 (0 - the lowest priority, 31 - the highest priority)
*/
void Add(PT::Space & job, int priority = 0);
void Add(pt::Space & job, int priority = 0);
/*
@@ -81,7 +81,7 @@ public:
private:
typedef std::queue<PT::Space> JobsQueue;
typedef std::queue<pt::Space> JobsQueue;
typedef std::vector<JobsQueue> JobsQueueTab;
JobsQueueTab jobs_queue_tab;
@@ -102,8 +102,8 @@ private:
bool SignalReceived();
void Do();
void DoQueue(JobsQueue & jobs_queue);
void DoJob(PT::Space & job);
void DoWinixJob(PT::Space & job);
void DoJob(pt::Space & job);
void DoWinixJob(pt::Space & job);
};
+2 -2
View File
@@ -69,8 +69,8 @@ struct LastItem
long session_id;
// start logging and end logging
PT::Date start;
PT::Date end;
pt::Date start;
pt::Date end;
LastItem();
+34 -28
View File
@@ -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);
@@ -86,7 +86,7 @@ void Log::PrintDate(const PT::Date & date)
Log & Log::operator<<(const void * s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -94,7 +94,7 @@ Log & Log::operator<<(const void * s)
Log & Log::operator<<(const char * s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -102,7 +102,7 @@ Log & Log::operator<<(const char * s)
Log & Log::operator<<(const std::string & s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -110,7 +110,7 @@ Log & Log::operator<<(const std::string & s)
Log & Log::operator<<(const std::string * s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -121,7 +121,7 @@ Log & Log::operator<<(const std::string * s)
Log & Log::operator<<(const wchar_t * s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -129,7 +129,7 @@ Log & Log::operator<<(const wchar_t * s)
Log & Log::operator<<(const std::wstring & s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -137,7 +137,7 @@ Log & Log::operator<<(const std::wstring & s)
Log & Log::operator<<(const std::wstring * s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -145,7 +145,7 @@ Log & Log::operator<<(const std::wstring * s)
Log & Log::operator<<(int s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -153,7 +153,7 @@ Log & Log::operator<<(int s)
Log & Log::operator<<(long s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -162,21 +162,21 @@ Log & Log::operator<<(long s)
Log & Log::operator<<(char s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
Log & Log::operator<<(wchar_t s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
Log & Log::operator<<(size_t s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
@@ -184,54 +184,60 @@ Log & Log::operator<<(size_t s)
Log & Log::operator<<(double s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
Log & Log::operator<<(const PT::Space & s)
Log & Log::operator<<(const pt::Space & s)
{
PT::Log::operator<<(s);
pt::Log::operator<<(s);
return *this;
}
Log & Log::operator<<(const PT::Date & date)
Log & Log::operator<<(const pt::Date & date)
{
PT::Log::operator<<(date);
pt::Log::operator<<(date);
return *this;
}
Log & Log::operator<<(morm::Model & model)
{
pt::Log::operator<<(model);
return *this;
}
Log & Log::operator<<(LogManipulators m)
{
switch(m)
{
case LogManipulators::log1:
PT::Log::operator<<(PT::Log::log1);
pt::Log::operator<<(pt::Log::log1);
break;
case LogManipulators::log2:
PT::Log::operator<<(PT::Log::log2);
pt::Log::operator<<(pt::Log::log2);
break;
case LogManipulators::log3:
PT::Log::operator<<(PT::Log::log3);
pt::Log::operator<<(pt::Log::log3);
break;
case LogManipulators::log4:
PT::Log::operator<<(PT::Log::log4);
pt::Log::operator<<(pt::Log::log4);
break;
case LogManipulators::logend:
PT::Log::operator<<(PT::Log::logend);
pt::Log::operator<<(pt::Log::logend);
break;
case LogManipulators::logsave:
PT::Log::operator<<(PT::Log::logsave);
pt::Log::operator<<(pt::Log::logsave);
break;
case LogManipulators::logendrequest:
@@ -268,27 +274,27 @@ return *this;
Log & Log::LogString(const std::string & value, size_t max_size)
{
PT::Log::LogString(value, max_size);
pt::Log::LogString(value, max_size);
return *this;
}
Log & Log::LogString(const std::wstring & value, size_t max_size)
{
PT::Log::LogString(value, max_size);
pt::Log::LogString(value, max_size);
return *this;
}
Log & Log::LogBinary(const char * blob, size_t blob_len)
{
PT::Log::LogBinary(blob, blob_len);
pt::Log::LogBinary(blob, blob_len);
return *this;
}
Log & Log::LogBinary(const std::string & blob)
{
PT::Log::LogBinary(blob);
pt::Log::LogBinary(blob);
return *this;
}
+8 -7
View File
@@ -51,7 +51,7 @@ namespace Winix
class Log : public PT::Log
class Log : public pt::Log
{
public:
@@ -75,14 +75,15 @@ public:
virtual Log & operator<<(wchar_t s);
virtual Log & operator<<(size_t s);
virtual Log & operator<<(double s);
virtual Log & operator<<(const PT::Space & space);
virtual Log & operator<<(const pt::Space & space);
virtual Log & operator<<(LogManipulators m);
virtual Log & operator<<(const PT::Date & date);
virtual Log & operator<<(const pt::Date & date);
virtual Log & operator<<(morm::Model & model);
virtual void PrintDate(const PT::Date & date);
virtual void PrintDate(const pt::Date & date);
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);
@@ -111,9 +112,9 @@ private:
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;
}
+91 -66
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* 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,
0x2029, 0x202F, 0x205F, 0x3000 };
PT::WTextStream tmp_qencode;
pt::WTextStream tmp_qencode;
}
@@ -331,7 +331,7 @@ void CorrectUrlOnlyAllowedChar(std::wstring & url)
{
CorrectUrlDots(url);
CorrectUrlChars(url);
PT::ToLower(url);
pt::to_lower_emplace(url);
Trim(url, '_');
if( url.empty() || url == L"." )
@@ -408,7 +408,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);
}
@@ -416,14 +416,14 @@ const wchar_t * DateToStr(const PT::Date & d)
const wchar_t * DateToStr(time_t t)
{
PT::Date date = t;
pt::Date date = t;
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);
}
@@ -431,7 +431,7 @@ const wchar_t * DateToStrWithoutHours(const PT::Date & d)
const wchar_t * DateToStrWithoutHours(time_t t)
{
PT::Date date = t;
pt::Date date = t;
return DateToStrWithoutHours(date);
}
@@ -460,7 +460,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);
}
@@ -468,7 +468,7 @@ const char * DateToStrCookie(const PT::Date & d)
const char * DateToStrCookie(time_t t)
{
PT::Date date = t;
pt::Date date = t;
return DateToStrCookie(date);
}
@@ -493,9 +493,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)
{
@@ -509,7 +509,7 @@ return buf;
}
PT::WTextStream IPToStr(int ip)
pt::WTextStream IPToStr(int ip)
{
return IPToStr(static_cast<unsigned int>(ip));
}
@@ -854,7 +854,7 @@ bool IsFile(const wchar_t * file)
struct stat sb;
char file_name[WINIX_OS_PATH_SIZE];
if( !WideToUTF8(file, file_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(file, file_name, WINIX_OS_PATH_SIZE) )
return false;
return (stat(file_name, &sb) == 0);
@@ -876,7 +876,7 @@ char dir_name[WINIX_OS_PATH_SIZE];
if( !IsFile(dir) )
{
if( !WideToUTF8(dir, dir_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(dir, dir_name, WINIX_OS_PATH_SIZE) )
return false;
if( mkdir(dir_name, 0777) < 0 )
@@ -952,7 +952,7 @@ struct group * result;
char group_name[WINIX_OS_USERNAME_SIZE];
char buffer[512];
if( !WideToUTF8(name, group_name, WINIX_OS_USERNAME_SIZE) )
if( !wide_to_utf8(name, group_name, WINIX_OS_USERNAME_SIZE) )
return -1;
if( getgrnam_r(group_name, &gr, buffer, sizeof(buffer)/sizeof(char), &result) != 0 )
@@ -988,7 +988,7 @@ bool SetPriv(const wchar_t * name, int priv, int group)
{
char file_name[WINIX_OS_PATH_SIZE];
if( !WideToUTF8(name, file_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(name, file_name, WINIX_OS_PATH_SIZE) )
return false;
if( chmod(file_name, priv) < 0 )
@@ -1046,10 +1046,10 @@ char src_name[WINIX_OS_PATH_SIZE];
char dst_name[WINIX_OS_PATH_SIZE];
FILE * in, * out;
if( !WideToUTF8(src, src_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(src, src_name, WINIX_OS_PATH_SIZE) )
return false;
if( !WideToUTF8(dst, dst_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(dst, dst_name, WINIX_OS_PATH_SIZE) )
return false;
in = fopen(src_name, "rb");
@@ -1091,7 +1091,7 @@ bool RemoveFile(const wchar_t * file)
{
char file_name[WINIX_OS_PATH_SIZE];
if( !WideToUTF8(file, file_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(file, file_name, WINIX_OS_PATH_SIZE) )
return false;
return unlink(file_name) == 0;
@@ -1110,10 +1110,10 @@ bool RenameFile(const wchar_t * from, const wchar_t * to)
char from_name[WINIX_OS_PATH_SIZE];
char to_name[WINIX_OS_PATH_SIZE];
if( !WideToUTF8(from, from_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(from, from_name, WINIX_OS_PATH_SIZE) )
return false;
if( !WideToUTF8(to, to_name, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(to, to_name, WINIX_OS_PATH_SIZE) )
return false;
return rename(from_name, to_name) == 0;
@@ -1137,7 +1137,7 @@ std::ifstream get_file_content;
if( clear_content )
content.clear();
if( !WideToUTF8(file_path, file, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(file_path, file, WINIX_OS_PATH_SIZE) )
return false;
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
@@ -1148,7 +1148,7 @@ std::ifstream get_file_content;
/*
* 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();
return true;
@@ -1161,30 +1161,55 @@ 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
// if there is no an extension it returns a pointer to the last '\0' character
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(i=0 ; name[i] != 0 ; ++i);
for( ; *name != 0 ; ++name)
{
if( *name == '.' )
{
dot_ptr = name;
}
}
if( i == 0 )
return name; // ops, the name is empty
return dot_ptr ? dot_ptr + 1 : name;
}
// remember the end of the string
ilast = i;
// looking for the last dot
for(--i ; i>0 && name[i] != '.' ; --i);
void PrepareNewFileName(const wchar_t * src, const wchar_t * postfix, std::wstring & res, bool clear_res)
{
bool has_ext = false;
const wchar_t * ext = GetFileExt(src);
if( name[i] != '.' )
return name + ilast; // ops, there is not a dot
if( clear_res )
res.clear();
// the extensions starts from i+1
// and can be empty (if the last character is a dot)
size_t len = ext - src;
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 +1219,31 @@ int SelectFileType(const wchar_t * file_name)
// as an image we're using only those types which can be rendered
// by a web browser
if( PT::EqualNoCase(ext, L"jpg") ||
PT::EqualNoCase(ext, L"jpeg") ||
PT::EqualNoCase(ext, L"jpe") ||
PT::EqualNoCase(ext, L"pic") ||
PT::EqualNoCase(ext, L"tga") ||
PT::EqualNoCase(ext, L"gif") ||
PT::EqualNoCase(ext, L"bmp") ||
PT::EqualNoCase(ext, L"png") )
if( pt::is_equal_nc(ext, L"jpg") ||
pt::is_equal_nc(ext, L"jpeg") ||
pt::is_equal_nc(ext, L"jpe") ||
pt::is_equal_nc(ext, L"pic") ||
pt::is_equal_nc(ext, L"tga") ||
pt::is_equal_nc(ext, L"gif") ||
pt::is_equal_nc(ext, L"bmp") ||
pt::is_equal_nc(ext, L"png") )
return WINIX_ITEM_FILETYPE_IMAGE;
if( PT::EqualNoCase(ext, L"pdf") ||
PT::EqualNoCase(ext, L"doc") ||
PT::EqualNoCase(ext, L"xls") ||
PT::EqualNoCase(ext, L"txt") ||
PT::EqualNoCase(ext, L"ods") ||
PT::EqualNoCase(ext, L"odt") )
if( pt::is_equal_nc(ext, L"pdf") ||
pt::is_equal_nc(ext, L"doc") ||
pt::is_equal_nc(ext, L"xls") ||
pt::is_equal_nc(ext, L"txt") ||
pt::is_equal_nc(ext, L"ods") ||
pt::is_equal_nc(ext, L"odt") )
return WINIX_ITEM_FILETYPE_DOCUMENT;
if( PT::EqualNoCase(ext, L"avi") ||
PT::EqualNoCase(ext, L"mp4") ||
PT::EqualNoCase(ext, L"flv") ||
PT::EqualNoCase(ext, L"mpg") ||
PT::EqualNoCase(ext, L"mpeg") ||
PT::EqualNoCase(ext, L"mkv") ||
PT::EqualNoCase(ext, L"wmv") )
if( pt::is_equal_nc(ext, L"avi") ||
pt::is_equal_nc(ext, L"mp4") ||
pt::is_equal_nc(ext, L"flv") ||
pt::is_equal_nc(ext, L"mpg") ||
pt::is_equal_nc(ext, L"mpeg") ||
pt::is_equal_nc(ext, L"mkv") ||
pt::is_equal_nc(ext, L"wmv") )
return WINIX_ITEM_FILETYPE_VIDEO;
return WINIX_ITEM_FILETYPE_UNKNOWN;
@@ -1255,7 +1280,7 @@ void UrlEncode(const wchar_t * in, std::string & out, bool clear_out)
{
static std::string ain;
PT::WideToUTF8(in, ain);
pt::wide_to_utf8(in, ain);
if( clear_out )
out.clear();
@@ -1276,7 +1301,7 @@ void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out)
{
static std::string ain;
PT::WideToUTF8(in, ain);
pt::wide_to_utf8(in, ain);
if( clear_out )
out.clear();
@@ -1347,7 +1372,7 @@ int c1, c2;
url_utf8[index] = 0;
return PT::UTF8ToWide(url_utf8, out, false);
return pt::utf8_to_wide(url_utf8, out, false);
}
@@ -1391,9 +1416,9 @@ void RemovePostFileTmp(PostFileTab & post_file_tab)
}
bool WideToUTF8(const wchar_t * wide_string, char * utf8, size_t utf8_size)
bool wide_to_utf8(const wchar_t * wide_string, char * utf8, size_t utf8_size)
{
bool res = PT::WideToUTF8(wide_string, utf8, utf8_size);
bool res = pt::wide_to_utf8(wide_string, utf8, utf8_size);
if( !res )
{
@@ -1408,9 +1433,9 @@ return res;
}
bool WideToUTF8(const std::wstring & wide_string, char * utf8, size_t utf8_size)
bool wide_to_utf8(const std::wstring & wide_string, char * utf8, size_t utf8_size)
{
return WideToUTF8(wide_string.c_str(), utf8, utf8_size);
return wide_to_utf8(wide_string.c_str(), utf8, utf8_size);
}
+28 -23
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,6 @@
#include <sstream>
#include <ctime>
#include <cstdio>
#include "item.h"
#include "requesttypes.h"
#include "date/date.h"
#include "textstream/textstream.h"
@@ -78,6 +77,7 @@ double Tod(const wchar_t * str);
// if the buffer is too small it will be terminated at the beginning (empty string)
// and the function returns false
// IMPROVEME now we can use Toa from Pikotools
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10)
{
@@ -238,13 +238,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, 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 * DateToStrWithoutHours(const PT::Date & d);
const wchar_t * DateToStrWithoutHours(const pt::Date & d);
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(const PT::Date & d);
const char * DateToStrCookie(const pt::Date & d);
const char * DateToStrCookie(time_t t);
// depracated
@@ -253,8 +253,8 @@ const wchar_t * IpToStr(unsigned int ip_);
// in a new code we can use WTextStream in such a way
// DateToStr() etc can use it too
PT::WTextStream IPToStr(unsigned int ip);
PT::WTextStream IPToStr(int ip);
pt::WTextStream IPToStr(unsigned int ip);
pt::WTextStream IPToStr(int ip);
@@ -420,7 +420,7 @@ size_t i = 0;
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.insert(i, replace);
@@ -664,6 +664,11 @@ bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool cl
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 std::wstring & file_name);
@@ -676,7 +681,7 @@ int SelectFileType(const std::wstring & file_name);
// thread safe
template<typename char_type, size_t stack_size, size_t heap_block_size>
void UrlEncode(char c,
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
bool clear_out = true)
{
char buffer[10];
@@ -708,7 +713,7 @@ size_t buflen = sizeof(buffer)/sizeof(char);
// thread safe
template<typename char_type, size_t stack_size, size_t heap_block_size>
void UrlEncode(const char * in,
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
bool clear_out = true)
{
if( clear_out )
@@ -722,7 +727,7 @@ void UrlEncode(const char * in,
// thread safe
template<typename char_type, size_t stack_size, size_t heap_block_size>
void UrlEncode(const std::string & in,
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
bool clear_out = true)
{
UrlEncode(in.c_str(), out, clear_out);
@@ -733,12 +738,12 @@ void UrlEncode(const std::string & in,
// not thread safe
template<typename char_type, size_t stack_size, size_t heap_block_size>
void UrlEncode(const wchar_t * in,
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
bool clear_out = true)
{
static std::string ain;
PT::WideToUTF8(in, ain);
pt::wide_to_utf8(in, ain);
if( clear_out )
out.clear();
@@ -751,7 +756,7 @@ static std::string ain;
// not thread safe
template<typename char_type, size_t stack_size, size_t heap_block_size>
void UrlEncode(const std::wstring & in,
PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
bool clear_out = true)
{
UrlEncode(in.c_str(), out, clear_out);
@@ -763,14 +768,14 @@ void UrlEncode(const std::wstring & in,
template<class StringType>
void UrlEncode(char c, StringType & out, bool clear_out = true)
{
static PT::TextStream tmp;
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
// !! 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);
@@ -797,7 +802,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>
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') ||
(c>='a' && c<='z') ||
@@ -812,7 +817,7 @@ void QEncodeAddChar(char_type c, PT::TextStreamBase<char_type, stack_size, heap_
size_t len1 = sizeof(buf1) / 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)
{
@@ -845,7 +850,7 @@ void QEncodeAddChar(char_type c, PT::TextStreamBase<char_type, stack_size, heap_
charset, encoding, encoded-text, and delimiters."
*/
template<typename char_type, size_t stack_size, size_t heap_block_size>
void QEncode(const wchar_t * in, PT::TextStreamBase<char_type, stack_size, heap_block_size> & out,
void QEncode(const wchar_t * in, pt::TextStreamBase<char_type, stack_size, heap_block_size> & out,
bool clear = true)
{
if( clear )
@@ -861,7 +866,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>
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)
{
if( clear )
@@ -979,10 +984,10 @@ void JSONescape(Stream & out, const StringType & str)
* converting from a wide string to an UTF-8 string
* and puts a log if the conversion fails
*
* it uses PT::WideToUTF8()
* it uses pt::wide_to_utf8()
*/
bool WideToUTF8(const wchar_t * wide_string, char * utf8, size_t utf8_size);
bool WideToUTF8(const std::wstring & wide_string, char * utf8, size_t utf8_size);
bool wide_to_utf8(const wchar_t * wide_string, char * utf8, size_t utf8_size);
bool wide_to_utf8(const std::wstring & wide_string, char * utf8, size_t utf8_size);
+2 -3
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,11 +40,10 @@
#include <vector>
#include <stdlib.h>
#include <limits.h>
#include "mount.h"
#include "item.h"
#include "dirs.h"
#include "winixmodel.h"
#include "models/item.h"
+20 -15
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2009-2018, Tomasz Sowa
* Copyright (c) 2009-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -222,13 +222,18 @@ void Mounts::ReadMounts(const std::wstring & mounts)
mount_parser.Parse(mounts, mount_tab);
CalcCurMount();
// IMPROVE ME
// 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((Session*)0, WINIX_FSTAB_CHANGED);
}
// reading from /etc/fstab
Error Mounts::ReadMounts()
void Mounts::ReadMounts()
{
static std::wstring file = L"fstab";
@@ -237,27 +242,27 @@ Error Mounts::ReadMounts()
if( !etc )
{
log << log1 << "M: there is no /etc directory" << logend;
return WINIX_ERR_NO_ITEM;
return;
}
Item fstab;
Error err = db->GetItem(etc->id, file, fstab);
morm::Finder<Item> finder(model_connector);
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;
return err;
return;
}
if( err != WINIX_ERR_OK )
{
log << log1 << "M: cannot read /etc/fstab" << logend;
return err;
}
// if( err != WINIX_ERR_OK )
// {
// log << log1 << "M: cannot read /etc/fstab" << logend;
// return err;
// }
ReadMounts(fstab.content);
return WINIX_ERR_OK;
ReadMounts(fstab.item_content.content_raw);
}
+1 -1
View File
@@ -124,7 +124,7 @@ public:
void CreateMounts();
void ReadMounts(const std::wstring & mounts);
Error ReadMounts();
void ReadMounts();
Mount * CalcCurMount();
Mount * CalcMount(long dir_id);
+12 -9
View File
@@ -69,6 +69,9 @@ void PluginInfo::set_dependency_for(WinixBase & winix_base)
void PluginInfo::set_dependency_for(WinixModel * winix_model)
{
plugin->SetDependencyFor(winix_model);
//model_connector = winix_model->get_model_connector();
// CHECKME what about model_connector here?
}
void PluginInfo::set_dependency_for(WinixModel & winix_model)
@@ -196,9 +199,7 @@ bool Plugin::SetDependency(PluginInfo & info)
if( !res )
{
Lock();
log << log1 << "Plugin: cannot call a function - some of the winix pointers are null" << logend;
Unlock();
}
info.db = db;
@@ -211,6 +212,14 @@ bool Plugin::SetDependency(PluginInfo & info)
info.session_manager = session_manager;
info.plugin = this;
/*
* FIXME
* if we call a message from a different thread then a different model connector is needed
* (each thread should have its own model connector)
*
*/
info.model_connector = system->get_model_connector();
info.log.SetDependency(&log);
return res;
@@ -256,7 +265,7 @@ void * Plugin::LoadInitFun(const wchar_t * filename, Fun1 & fun_init)
{
char file[WINIX_OS_PATH_SIZE];
if( !WideToUTF8(filename, file, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(filename, file, WINIX_OS_PATH_SIZE) )
return 0;
void * p = dlopen(file, RTLD_NOW | RTLD_LOCAL);
@@ -371,9 +380,7 @@ void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo
{
if( config->log_plugin_call )
{
Lock();
log << log1 << "Plugin: calling plugin id: " << slot->second.index << ", message: " << message << logend;
Unlock();
}
slot->second.is_running = true;
@@ -388,20 +395,16 @@ void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo
if( config->log_plugin_call )
{
Lock();
log << log1 << "Plugin: returning from plugin id: " << slot->second.index << ", message: " << message
<< ", result: " << (info.res? "true" : "false") << logend;
Unlock();
}
}
else
{
Lock();
log << log1 << "Plugin: id: " << slot->second.index
<< ", message: " << message
<< ", recurrences are not allowed" << logend;
Unlock();
}
}
+4 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@
#include "pluginmsg.h"
#include "plugindata.h"
#include "winixbase.h"
#include "modelconnector.h"
@@ -81,6 +81,7 @@ struct Session;
// move me to a different file
// may it should be based on WinixModel?
struct PluginInfo
{
// these variables are used for some purposes
@@ -108,6 +109,7 @@ struct PluginInfo
Plugin * plugin;
morm::ModelConnector * model_connector;
// a session
// some messages are sent in a session's context e.g. logging a user
+4 -4
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -382,14 +382,14 @@ void PostMultiParser::ReadContent()
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);
}
void PostMultiParser::ConvStr(const std::string & src, std::wstring & dst)
{
PT::UTF8ToWide(src, dst);
pt::utf8_to_wide(src, dst);
}
@@ -496,7 +496,7 @@ size_t buf_len = sizeof(buf)/sizeof(wchar_t);
tmp_filename_postfix += 1;
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);
// !! IMPROVE ME dodac ustawienie chmod config.upload_files_chmod dla tymczasowego pliku
+1 -1
View File
@@ -77,7 +77,7 @@ protected:
{
log << log2 << "Method POST, name: \"" << name << "\"";
if( log_value_size > 0 && !PT::IsSubStringNoCase(L"pass", name.c_str()) )
if( log_value_size > 0 && !pt::is_substr_nc(L"pass", name.c_str()) )
{
log << ", value: ";
+6 -6
View File
@@ -93,15 +93,15 @@ void Request::Clear()
post_tab.clear();
post_file_tab.clear();
cookie_tab.clear();
post_in.Clear();
post_in.clear();
is_postin_used = false;
method = unknown_method;
headers_in.Clear();
headers_in.clear();
out_headers.Clear();
out_cookies.Clear();
out_headers.clear();
out_cookies.clear();
page_generated = false;
@@ -117,6 +117,7 @@ void Request::Clear()
item_tab.clear();
item.Clear();
item.set_connector(nullptr);
dir_tab.clear();
last_item = &item;
is_item = false;
@@ -139,8 +140,7 @@ void Request::Clear()
subdomain.clear();
return_info_only = false;
info.Clear();
info_serializer = 0;
info.clear();
return_json = false;
out_bin_stream.clear();
+17 -23
View File
@@ -39,14 +39,13 @@
#include <sstream>
#include <vector>
#include "requesttypes.h"
#include "item.h"
#include "models/item.h"
#include "error.h"
#include "config.h"
#include "textstream.h"
#include "templates/htmltextstream.h"
#include "date/date.h"
#include "space/space.h"
#include "space/spacetojson.h"
#include "textstream/textstream.h"
#include "outstreams.h"
@@ -89,7 +88,7 @@ struct Request
they are set when a request starts
*/
time_t start_time;
PT::Date start_date;
pt::Date start_date;
@@ -119,13 +118,13 @@ struct Request
/*
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?
*/
PostTab post_tab;
PostFileTab post_file_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
// input headers (without cookies)
@@ -135,7 +134,7 @@ struct Request
// 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
// each header has a different name here, cookies we have in a different container (cookie_tab)
PT::Space headers_in;
pt::Space headers_in;
/*
@@ -233,11 +232,11 @@ struct Request
bool send_as_attachment;
// 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
// 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)
@@ -306,12 +305,7 @@ struct Request
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;
pt::Space info;
@@ -388,14 +382,14 @@ struct Request
// setting a cookie
// name - cookie name (either const wchar_t, or std::wstring or PT::WTextStream)
// value - cookie value (can be everything which can be put to PT::WTextStream stream)
// name - cookie name (either const wchar_t, or std::wstring or pt::WTextStream)
// value - cookie value (can be everything which can be put to pt::WTextStream stream)
// the return std::wstring reference is a reference to the cookie inserted value (in out_cookies structure)
template<typename NameType, typename ValueType>
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date * expires = 0);
void AddCookie(const NameType & name, const ValueType & value, pt::Date * expires = 0);
template<typename NameType, typename ValueType>
std::wstring & AddCookie(const NameType & name, const ValueType & value, PT::Date & expires);
void AddCookie(const NameType & name, const ValueType & value, pt::Date & expires);
@@ -415,9 +409,9 @@ private:
template<typename NameType, typename ValueType>
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date * expires)
void Request::AddCookie(const NameType & name, const ValueType & value, pt::Date * expires)
{
PT::WTextStream cookie;
pt::WTextStream cookie;
cookie << value;
@@ -439,14 +433,14 @@ PT::WTextStream cookie;
will be lost (the session cookie will be overwritten in the client's browser)
*/
return out_cookies.Add(name, cookie);
out_cookies.add_stream(name, cookie);
}
template<typename NameType, typename ValueType>
std::wstring & Request::AddCookie(const NameType & name, const ValueType & value, PT::Date & expires)
void Request::AddCookie(const NameType & name, const ValueType & value, pt::Date & expires)
{
return AddCookie(name, value, &expires);
AddCookie(name, value, &expires);
}
+1 -1
View File
@@ -77,7 +77,7 @@ typedef std::vector<Param> ParamTab;
typedef std::map<std::wstring, std::wstring> CookieTab;
typedef PT::TextStreamBase<char, 1, 4096> BinaryPage;
typedef pt::TextStreamBase<char, 1, 4096> BinaryPage;
+4 -5
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,9 +39,8 @@
#include <string>
#include <ctime>
#include <map>
#include "item.h"
#include "error.h"
#include "user.h"
#include "models/user.h"
#include "plugindata.h"
#include "rebus.h"
#include "textstream.h"
@@ -82,12 +81,12 @@ struct Session
// when this session was created
// (the same values)
time_t start_time;
PT::Date start_date;
pt::Date start_date;
// when this session was last used
// (the same values)
time_t last_time;
PT::Date last_date;
pt::Date last_date;
// when there was a last get request
// (used to calculate spam or invalid login attempts etc.)
+14 -15
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2014-2018, Tomasz Sowa
* Copyright (c) 2014-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -86,12 +86,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::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)
dest_key[i].clear();
@@ -100,7 +100,7 @@ std::string key_ascii, key_base64_decoded;
{
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) )
{
@@ -140,21 +140,20 @@ void SessionIdManager::InitializeAesKeys()
bool SessionIdManager::ReadKeysFromFile(const wchar_t * file)
{
PT::Space space;
PT::SpaceParser parser;
PT::Date date;
pt::Space space;
pt::SpaceParser parser;
pt::Date date;
parser.SetSpace(space);
PT::SpaceParser::Status status = parser.Parse(file);
pt::SpaceParser::Status status = parser.parse_space_file(file, space);
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 )
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();
ReadKey(L"key_tab1", space, key_tab1);
@@ -166,7 +165,7 @@ PT::Date date;
log << log1 << "SIM: I cannot read the session keys from: " << file << logend;
}
return status == PT::SpaceParser::ok;
return status == pt::SpaceParser::ok;
}
@@ -196,8 +195,8 @@ void SessionIdManager::SaveKeysToFile(std::vector<std::string> & keys)
bool SessionIdManager::SaveKeysToFile(const wchar_t * file)
{
PT::Date date = last_key_generated;
PT::WideToUTF8(file, file_name_ascii);
pt::Date date = last_key_generated;
pt::wide_to_utf8(file, file_name_ascii);
out_file.clear();
out_file.open(file_name_ascii, std::ios_base::binary | std::ios_base::out);
+1 -1
View File
@@ -124,7 +124,7 @@ private:
bool ReadKeysFromFile(const std::wstring & file);
bool SaveKeysToFile(const wchar_t * file);
bool SaveKeysToFile(const std::wstring & file);
void ReadKey(const wchar_t * name, PT::Space & space, std::vector<std::string> & dest_key);
void ReadKey(const wchar_t * name, pt::Space & space, std::vector<std::string> & dest_key);
bool AreKeysCorrect(size_t index);
void GenerateKeys(size_t index, time_t cur_utc_time);
void CheckKeys(time_t cur_utc_time);
+3 -3
View File
@@ -256,7 +256,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_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;
}
@@ -444,7 +444,7 @@ bool SessionManager::IsIPBanned()
else
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;
return true;
}
@@ -688,7 +688,7 @@ char file_path[WINIX_OS_PATH_SIZE];
if( config->session_file.empty() )
return;
if( !WideToUTF8(config->session_file, file_path, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(config->session_file, file_path, WINIX_OS_PATH_SIZE) )
return;
std::ofstream file(file_path);
+1 -1
View File
@@ -60,7 +60,7 @@ char file_path[WINIX_OS_PATH_SIZE];
container.Clear();
if( !WideToUTF8(path, file_path, WINIX_OS_PATH_SIZE) )
if( !wide_to_utf8(path, file_path, WINIX_OS_PATH_SIZE) )
return false;
file.open(file_path, std::ios_base::in | std::ios_base::binary);
+3 -3
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -144,7 +144,7 @@ SLog & SLog::operator<<(double s)
}
SLog & SLog::operator<<(const PT::Date & date)
SLog & SLog::operator<<(const pt::Date & date)
{
return PutLog(date);
}
@@ -189,7 +189,7 @@ return *this;
SLog & SLog::TranslateText(const char * str)
{
PT::UTF8ToWide(str, key_temp);
pt::utf8_to_wide(str, key_temp);
return TranslateText(key_temp.c_str());
}
+3 -3
View File
@@ -99,10 +99,10 @@ public:
SLog & operator<<(size_t s);
SLog & operator<<(double s);
SLog & operator<<(LogManipulators m);
SLog & operator<<(const PT::Date & date);
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 & operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
SLog & TranslateText(const char * str);
@@ -148,7 +148,7 @@ SLog::TranslateTextHelper<RawType> T(const 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)
SLog & SLog::operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
{
return PutLog(buf);
}
+107 -70
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -219,7 +219,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
*/
void System::PutUrlProto(bool can_use_ssl, PT::TextStream & str, bool clear_stream)
void System::PutUrlProto(bool can_use_ssl, pt::TextStream & str, bool clear_stream)
{
if( clear_stream )
str.clear();
@@ -241,7 +241,7 @@ void System::PutUrlProto(std::wstring & str, bool clear_str)
}
void System::PutUrlProto(PT::TextStream & str, bool clear_stream)
void System::PutUrlProto(pt::TextStream & str, bool clear_stream)
{
return PutUrlProto(config->use_ssl, str, clear_stream);
}
@@ -337,14 +337,23 @@ void System::RedirectTo(long item_id, const wchar_t * postfix, bool use_reqtype)
else
{
// item_id is pointing to a file
DbItemQuery iq;
// DbItemQuery iq;
iq.SetAllSel(false);
iq.WhereId(item_id);
iq.sel_parent_id = true;
iq.sel_url = true;
// iq.SetAllSel(false);
// iq.WhereId(item_id);
// iq.sel_parent_id = 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) )
cur->request->redirect_to += item_temp.url;
@@ -528,7 +537,7 @@ bool System::CanChangeUser(const Item & item, long new_user_id)
// super user is allowed everything
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
return false;
@@ -548,7 +557,7 @@ bool System::CanChangeGroup(const Item & item, long new_group_id)
// super user is allowed everything
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
// he can change only into a group in which he is a member of, or into a 'no_group'
@@ -556,7 +565,7 @@ bool System::CanChangeGroup(const Item & item, long new_group_id)
if( !cur->session->puser || cur->session->puser->id == -1 )
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;
if( new_group_id == -1 )
@@ -582,14 +591,14 @@ bool System::CanChangePrivileges(const Item & item, int new_priv)
// super user is allowed everything
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
if( !cur->session->puser || cur->session->puser->id == -1 )
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;
}
@@ -608,27 +617,27 @@ bool System::HasAccess(const Item & item, int mask)
// super user is allowed everything
return true;
if( cur->session->puser && item.user_id != -1 && cur->session->puser->id == item.user_id )
if( cur->session->puser && item.item_content.user_id != -1 && cur->session->puser->id == item.item_content.user_id )
{
// the owner
return ((item.privileges >> 9) & mask) == mask;
return ((item.item_content.privileges >> 9) & mask) == mask;
}
if( cur->session->puser && item.group_id != -1 && cur->session->puser->IsMemberOf(item.group_id) )
if( cur->session->puser && item.item_content.group_id != -1 && cur->session->puser->IsMemberOf(item.item_content.group_id) )
{
// group
return ((item.privileges >> 6) & mask) == mask;
return ((item.item_content.privileges >> 6) & mask) == mask;
}
if( cur->session->puser )
{
// others -- others logged people
return ((item.privileges >> 3) & mask) == mask;
return ((item.item_content.privileges >> 3) & mask) == mask;
}
// guests -- not logged people
return (item.privileges & mask) == mask;
return (item.item_content.privileges & mask) == mask;
}
@@ -656,7 +665,7 @@ bool System::HasReadExecAccess(const Item & item)
{
// there must be at least one 'x' (for the root)
// !! CHECK ME: is it applicable to directories too?
return (item.privileges & 01111) != 0;
return (item.item_content.privileges & 01111) != 0;
}
return HasAccess(item, 5); // r+x
@@ -746,7 +755,7 @@ int System::NewPrivileges(int creation_mask)
{
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;
}
else
@@ -774,7 +783,7 @@ bool System::CanRemoveRenameChild(const Item & dir, long child_item_user_id)
if( !HasWriteAccess(dir) )
return false;
if( (dir.privileges & 010000) == 0 )
if( (dir.item_content.privileges & 010000) == 0 )
// there is no a sticky bit set to this directory
return true;
@@ -783,10 +792,10 @@ bool System::CanRemoveRenameChild(const Item & dir, long child_item_user_id)
if( cur->session->puser->super_user )
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 ||
cur->session->puser->id == dir.user_id )
cur->session->puser->id == dir.item_content.user_id )
return true;
}
}
@@ -867,12 +876,12 @@ return puser->IsMemberOf(group);
// the path depends on parent_id
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( !item.file_path.empty() && item.file_path[0] == '/' )
item.file_path.erase(0, 1);
if( !item.item_content.file_path.empty() && item.item_content.file_path[0] == '/' )
item.item_content.file_path.erase(0, 1);
}
else
{
@@ -897,7 +906,7 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
buffer[0] = '0';
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
if( (wcslen(hash) & 1) != 0 )
@@ -905,16 +914,16 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
for(size_t i=0 ; hash[i] != 0 ; i+=2)
{
item.file_path += hash[i];
item.file_path += hash[i+1];
item.item_content.file_path += hash[i];
item.item_content.file_path += hash[i+1];
if( hash[i+2] != 0 )
item.file_path += '/';
item.item_content.file_path += '/';
}
// one character more to make sure the path is unique
// (we can have a directory without the character)
item.file_path += '_';
item.item_content.file_path += '_';
return true;
}
@@ -939,18 +948,18 @@ bool res;
if( !pmount || pmount->fs != mounts.MountFsHashfs() )
{
res = CreateNewFileSimpleFs(item);
item.file_fs = mounts.MountFsSimplefs();
item.item_content.file_fs = mounts.MountFsSimplefs();
}
else
{
res = CreateNewFileHashFs(item);
item.file_fs = mounts.MountFsHashfs();
item.item_content.file_fs = mounts.MountFsHashfs();
}
if( res )
item.file_path += item.url;
item.item_content.file_path += item.url;
else
item.file_path.clear();
item.item_content.file_path.clear();
return res;
}
@@ -968,7 +977,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
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;
return false;
@@ -976,7 +985,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
path = config->upload_dir;
if( item.file_fs == mounts.MountFsHashfs() )
if( item.item_content.file_fs == mounts.MountFsHashfs() )
path += L"/hashfs";
else
path += L"/simplefs";
@@ -988,11 +997,11 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
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;
path += '/';
path += item.file_path;
path += item.item_content.file_path;
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 )
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
<< ", 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 )
return WINIX_ERR_FILE_EXPECTED;
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
cur->request->item.modification_user_id = -1;
cur->request->item.item_content.modification_user_id = -1;
item.SetDateModifyToNow();
Error status = db->EditItemById(item, with_url);
item.item_content.SetDateModifyToNow();
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);
@@ -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;
@@ -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;
@@ -1184,7 +1201,17 @@ int System::FollowLink(const std::vector<Item*> & current_dir_tab, const std::ws
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;
else
return 2;
@@ -1213,12 +1240,12 @@ bool System::FollowAllLinksDirFound(std::vector<Item*> & out_dir_tab,
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( !(stop_on_link_redirect && out_dir_tab.back()->link_redirect==1) )
link_to_temp = out_dir_tab.back()->link_to;
if( !(stop_on_link_redirect && out_dir_tab.back()->item_content.link_redirect==1) )
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.link_to.empty() )
if( out_item.item_content.link_to.empty() )
{
log << log1 << "System: symlink empty" << logend;
return false;
}
else
{
if( !(stop_on_link_redirect && out_item.link_redirect==1) )
link_to_temp = out_item.link_to;
if( !(stop_on_link_redirect && out_item.item_content.link_redirect==1) )
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->last_item = cur->request->dir_tab.back();
if( !cur->request->dir_tab.back()->link_to.empty() )
RedirectTo(cur->request->dir_tab.back()->link_to);
if( !cur->request->dir_tab.back()->item_content.link_to.empty() )
RedirectTo(cur->request->dir_tab.back()->item_content.link_to);
log << log3 << "System: current directory changed" << logend;
}
@@ -1404,7 +1431,7 @@ bool System::FollowAllLinks(const std::wstring & link_to,
cur->request->last_item = &cur->request->item;
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;
}
@@ -1459,27 +1486,37 @@ bool System::AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url,
return false;
}
if( db->GetItem(var->id, url, file_content_item) == WINIX_ERR_OK )
morm::Finder<Item> finder(model_connector);
bool status = finder.select().where().eq(L"parent_id", var->id).eq(L"url", url).get(file_content_item);
//if( db->GetItem(var->id, url, file_content_item) == WINIX_ERR_OK )
if( status )
{
if( overwrite_existing )
db->DelItem(file_content_item);
{
file_content_item.remove();
//db->DelItem(file_content_item);
}
else
{
return true;
}
}
file_content_item.Clear();
file_content_item.parent_id = var->id;
file_content_item.user_id = var->user_id;
file_content_item.group_id = var->group_id;
file_content_item.privileges = 07555; // !! IMPROVE ME: may it should be added as a parameter to this function?
file_content_item.item_content.user_id = var->item_content.user_id;
file_content_item.item_content.group_id = var->item_content.group_id;
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.url = url;
file_content_item.type = Item::file;
file_content_item.html_template = config->templates_index_raw;
file_content_item.content = file_content;
file_content_item.content_type = Item::ct_other;
file_content_item.item_content.content_raw = file_content;
file_content_item.item_content.content_raw_type = ItemContent::ct_other;
return AddFile(file_content_item, false) == WINIX_ERR_OK;
return AddFile(file_content_item, false);
}
+8 -6
View File
@@ -109,6 +109,8 @@ public:
TimeZones time_zones;
using WinixModel::get_model_connector;
void SetCur(Cur * pcur);
//void SetConfig(Config * pconfig);
void SetDb(Db * pdb);
@@ -125,9 +127,9 @@ public:
bool IsSSLRequired(bool try_to_use_ssl);
bool IsSSLRequired();
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::TextStream & str, bool clear_stream = true);
void PutUrlProto(std::wstring & str, bool clear_str = true);
void PutUrlProto(PT::TextStream & str, bool clear_stream = true);
void PutUrlProto(pt::TextStream & str, bool clear_stream = 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);
@@ -178,15 +180,15 @@ public:
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
Error 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 AddFile(Item & item, 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);
PT::Date ToLocal(const PT::Date & utc_date);
pt::Date ToLocal(const pt::Date & utc_date);
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,
+16 -16
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -104,11 +104,11 @@ public:
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);
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 & 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);
@@ -396,9 +396,9 @@ TextStream<StringType> & TextStream<StringType>::write(const wchar_t * buf, size
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Space & space)
TextStream<StringType> & TextStream<StringType>::operator<<(const pt::Space & space)
{
space.Serialize(*this, true, false);
space.serialize_to_space_stream(*this, true);
return *this;
}
@@ -406,7 +406,7 @@ return *this;
template<class StringType>
TextStream<StringType> & TextStream<StringType>::operator<<(const PT::Date & date)
TextStream<StringType> & TextStream<StringType>::operator<<(const pt::Date & date)
{
date.Serialize(*this);
@@ -417,9 +417,9 @@ 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)
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;
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);
@@ -434,7 +434,7 @@ return *this;
template<class StringType>
void TextStream<StringType>::Convert(wchar_t c, std::string & dst)
{
PT::IntToUTF8((int)c, dst, false);
pt::int_to_utf8((int)c, dst, false);
}
@@ -448,7 +448,7 @@ void TextStream<StringType>::Convert(wchar_t c, std::wstring & dst)
template<class StringType>
void TextStream<StringType>::Convert(const char * src, size_t len, std::wstring & dst)
{
PT::UTF8ToWide(src, len, dst, false);
pt::utf8_to_wide(src, len, dst, false);
}
@@ -456,14 +456,14 @@ void TextStream<StringType>::Convert(const char * src, size_t len, std::wstring
template<class StringType>
void TextStream<StringType>::Convert(const char * src, std::wstring & dst)
{
PT::UTF8ToWide(src, dst, false);
pt::utf8_to_wide(src, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const std::string & src, std::wstring & dst)
{
PT::UTF8ToWide(src, dst, false);
pt::utf8_to_wide(src, dst, false);
}
@@ -473,21 +473,21 @@ void TextStream<StringType>::Convert(const std::string & src, std::wstring & dst
template<class StringType>
void TextStream<StringType>::Convert(const wchar_t * src, size_t len, std::string & dst)
{
PT::WideToUTF8(src, len, dst, false);
pt::wide_to_utf8(src, len, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const wchar_t * src, std::string & dst)
{
PT::WideToUTF8(src, dst, false);
pt::wide_to_utf8(src, dst, false);
}
template<class StringType>
void TextStream<StringType>::Convert(const std::wstring & src, std::string & dst)
{
PT::WideToUTF8(src, dst, false);
pt::wide_to_utf8(src, dst, false);
}
+16 -13
View File
@@ -130,8 +130,7 @@ void ThreadManager::Add(BaseThread & pbase, const std::wstring & thread_name)
void ThreadManager::StartAll()
{
synchro->Lock();
Winix::Lock lock(synchro);
int id = 0;
for(ThreadItem & item : thread_tab)
@@ -140,7 +139,7 @@ void ThreadManager::StartAll()
id += 1;
}
synchro->Unlock();
lock.Unlock();
were_started = true;
}
@@ -165,28 +164,32 @@ void ThreadManager::StopAll()
if( !were_started )
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;
for(ThreadItem & item : thread_tab)
{
log << log4 << "TM: waiting for thread " << id << " (" << item.object->ThreadId()
<< ", name: " << item.name << ")" << logend;
<< ", name: " << item.name << ")" << logend << logsave;
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.GetLogBuffer());
delete item.thread_item_data;
item.thread_item_data = nullptr;
id += 1;
}
+1 -1
View File
@@ -80,7 +80,7 @@ private:
morm::JSONConnector json_connector;
morm::PostgreSQLConnector postgresql_connector;
PT::WTextStream log_buffer;
pt::WTextStream log_buffer;
};
struct ThreadItem
+48 -32
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2018, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@ void TimeZone::Dst::Clear()
}
bool TimeZone::Dst::IsDstUsed(const PT::Date & date) const
bool TimeZone::Dst::IsDstUsed(const pt::Date & date) const
{
if( !has_dst )
return false;
@@ -70,7 +70,7 @@ return false;
}
int TimeZone::Dst::Compare(const PT::Date & date1, const PT::Date & date2) const
int TimeZone::Dst::Compare(const pt::Date & date1, const pt::Date & date2) const
{
// year is ignored
@@ -135,7 +135,7 @@ return &i->second;
time_t TimeZone::CalcLocalOffset(const PT::Date & utc_date)
time_t TimeZone::CalcLocalOffset(const pt::Date & utc_date)
{
time_t dst_offset = 0;
@@ -151,22 +151,22 @@ return offset + dst_offset;
time_t TimeZone::ToLocal(time_t utc_time)
{
time_t offset = CalcLocalOffset(PT::Date(utc_time));
time_t offset = CalcLocalOffset(pt::Date(utc_time));
return utc_time + offset;
}
PT::Date TimeZone::ToLocal(const PT::Date & utc_date)
pt::Date TimeZone::ToLocal(const pt::Date & utc_date)
{
PT::Date local(utc_date);
pt::Date local(utc_date);
local += CalcLocalOffset(utc_date);
return local;
}
time_t TimeZone::CalcUTCOffset(const PT::Date & local_date)
time_t TimeZone::CalcUTCOffset(const pt::Date & local_date)
{
time_t dst_offset = 0;
@@ -175,7 +175,7 @@ time_t dst_offset = 0;
if( dst && dst->has_dst )
{
// dst date ranges we have in UTC
PT::Date utc(local_date);
pt::Date utc(local_date);
utc -= (offset + dst->offset);
if( dst->IsDstUsed(utc) )
@@ -189,17 +189,17 @@ return offset + dst_offset;
time_t TimeZone::ToUTC(time_t local_time)
{
time_t offset = CalcUTCOffset(PT::Date(local_time));
time_t offset = CalcUTCOffset(pt::Date(local_time));
return local_time - offset;
}
PT::Date TimeZone::ToUTC(const PT::Date & local_date)
pt::Date TimeZone::ToUTC(const pt::Date & local_date)
{
time_t offset;
PT::Date utc(local_date);
pt::Date utc(local_date);
offset = CalcUTCOffset(local_date);
utc -= offset;
@@ -211,7 +211,7 @@ return utc;
time_t TimeZone::ParseStrOffset(const wchar_t * str)
{
PT::Date date;
pt::Date date;
bool is_sign = false;
time_t offset = 0;
@@ -240,39 +240,43 @@ return offset;
}
time_t TimeZone::GetOffset(PT::Space & space)
time_t TimeZone::GetOffset(pt::Space & space)
{
std::wstring * offset_str = space.GetFirstValue(L"offset_str");
std::wstring * offset_str = space.get_wstr(L"offset_str");
if( offset_str )
return ParseStrOffset(offset_str->c_str());
return space.Long(L"offset");
return space.to_long(L"offset");
}
bool TimeZone::SetTzDst(PT::Space & year)
bool TimeZone::SetTzDst(pt::Space & year)
{
time_t h24 = 60 * 60 * 24; // 24 hours
bool result = true;
Dst dst;
int year_int = Toi(year.name);
int year_int = 0;
std::wstring * year_name = year.find_child_space_name();
if( year_int < 1970 && year_int > 10000 )
if( year_name )
year_int = Toi(*year_name);
if( year_int < 1970 || year_int > 10000 )
return false;
dst.has_dst = year.Bool(L"has_dst", false);
dst.has_dst = year.to_bool(L"has_dst", false);
if( dst.has_dst )
{
dst.start.year = year_int;
dst.end.year = year_int;
if( !dst.start.ParseMonthDayTime(year.Text(L"start")) )
if( !dst.start.ParseMonthDayTime(year.to_wstr(L"start")) )
result = false;
if( !dst.end.ParseMonthDayTime(year.Text(L"end")) )
if( !dst.end.ParseMonthDayTime(year.to_wstr(L"end")) )
result = false;
dst.offset = GetOffset(year);
@@ -288,31 +292,43 @@ return result;
}
bool TimeZone::SetTz(PT::Space & space)
bool TimeZone::SetTz(pt::Space & space)
{
bool result = true;
name = space.name;
id = space.Int(L"id", -1);
name.clear();
std::wstring * space_name = space.find_child_space_name();
if( space_name )
name = *space_name;
id = space.to_int(L"id", -1);
offset = GetOffset(space);
time_t h24 = 60 * 60 * 24; // 24 hours
if( offset < -h24 || offset > h24 )
result = false;
PT::Space & dst = space.FindAddSpace(L"dst");
pt::Space * dst = space.find_child_space(L"dst");
for(size_t i=0 ; i<dst.spaces.size() ; ++i)
if( dst )
{
PT::Space & year = *dst.spaces[i];
pt::Space::TableType * child_table = dst->find_child_space_table();
if( !SetTzDst(year) )
if( child_table )
{
result = false;
break;
for(pt::Space * year : *child_table)
{
if( !SetTzDst(*year) )
{
result = false;
break;
}
}
}
}
return result;
return result;
}
+10 -10
View File
@@ -61,7 +61,7 @@ public:
// time zone daylight saving time (used if has_dst is true)
// the 'year' field is the same in 'start' and 'end'
// start and end are represented in UTC time
PT::Date start, end;
pt::Date start, end;
// time zone daylight saving time offset
// used when has_dst is true and the date is whithin start and end
@@ -74,7 +74,7 @@ public:
// checking whether specified 'date' is in the range of <start, end>
// the year field in date, start and end is ignored
// has_dst must be true
bool IsDstUsed(const PT::Date & date) const;
bool IsDstUsed(const pt::Date & date) const;
private:
@@ -83,7 +83,7 @@ public:
// return value less than zero if date1 is lower than date2
// and a value greater than zero if date1 is greater than date2
// the year field is ignored
int Compare(const PT::Date & date1, const PT::Date & date2) const;
int Compare(const pt::Date & date1, const pt::Date & date2) const;
};
@@ -106,23 +106,23 @@ public:
"tz_dst_end" the same as above
"tz_dst_offset" (long)
*/
bool SetTz(PT::Space & space);
bool SetTz(pt::Space & space);
/*
converting from UTC to local time
*/
time_t CalcLocalOffset(const PT::Date & utc_date);
time_t CalcLocalOffset(const pt::Date & utc_date);
time_t ToLocal(time_t utc_time);
PT::Date ToLocal(const PT::Date & utc_date);
pt::Date ToLocal(const pt::Date & utc_date);
/*
converting from local time to UTC
*/
time_t CalcUTCOffset(const PT::Date & local_date);
time_t CalcUTCOffset(const pt::Date & local_date);
time_t ToUTC(time_t local_time);
PT::Date ToUTC(const PT::Date & local_date);
pt::Date ToUTC(const pt::Date & local_date);
// return a Dst structure for the specified year
// or null if it not exists
@@ -155,8 +155,8 @@ public:
private:
time_t ParseStrOffset(const wchar_t * str);
time_t GetOffset(PT::Space & space);
bool SetTzDst(PT::Space & year);
time_t GetOffset(pt::Space & space);
bool SetTzDst(pt::Space & year);
};
+30 -29
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -123,37 +123,41 @@ bool TimeZones::Empty() const
void TimeZones::ParseZones()
{
for(size_t i=0 ; i<temp_space.spaces.size() ; ++i)
{
PT::Space & zone = *temp_space.spaces[i];
temp_zone.Clear();
pt::Space::TableType * child_table = temp_space.find_child_space_table();
if( temp_zone.SetTz(zone) )
if( child_table )
{
for(pt::Space * zone : *child_table)
{
if( !HasZone(temp_zone.id) )
temp_zone.Clear();
if( temp_zone.SetTz(*zone) )
{
if( temp_zone.id < zone_indices.size() )
if( !HasZone(temp_zone.id) )
{
zone_tab.push_back(temp_zone);
zone_indices[temp_zone.id] = zone_tab.size() - 1;
if( temp_zone.id < zone_indices.size() )
{
zone_tab.push_back(temp_zone);
zone_indices[temp_zone.id] = zone_tab.size() - 1;
}
else
{
log << log1 << "Tz: zone: " << temp_zone.name << " has too big id: "
<< temp_zone.id << " (skipping)" << logend;
}
}
else
{
log << log1 << "Tz: zone: " << temp_zone.name << " has too big id: "
<< temp_zone.id << " (skipping)" << logend;
log << log1 << "Tz: zone with id: " << temp_zone.id
<< " already exists (skipping)" << logend;
}
}
else
{
log << log1 << "Tz: zone with id: " << temp_zone.id
<< " already exists (skipping)" << logend;
log << log1 << "System: problem with reading time zone info from time zone: "
<< zone->get_child_space_name() << " (skipping) " << logend;
}
}
else
{
log << log1 << "System: problem with reading time zone info from time zone: "
<< zone.name << " (skipping) " << logend;
}
}
}
@@ -164,31 +168,28 @@ void TimeZones::ParseZones()
// just space by space (not implemented in Space at the moment)
bool TimeZones::ReadTimeZones(const wchar_t * path)
{
parser.SetSpace(temp_space);
zone_tab.clear();
temp_space.Clear();
pt::SpaceParser::Status status = parser.parse_space_file(path, temp_space);
PT::SpaceParser::Status status = parser.Parse(path);
if( status == PT::SpaceParser::ok )
if( status == pt::SpaceParser::ok )
{
ParseZones();
log << log2 << "Tz: time zones loaded, there are " << zone_tab.size() << " zones" << logend;
}
else
if( status == PT::SpaceParser::syntax_error )
if( status == pt::SpaceParser::syntax_error )
{
log << log1 << "TZ: error in time zone file, line: " << parser.line << logend;
log << log1 << "TZ: error in time zone file, line: " << parser.get_last_parsed_line() << logend;
}
else
if( status == PT::SpaceParser::cant_open_file )
if( status == pt::SpaceParser::cant_open_file )
{
log << log1 << "TZ: I cannot open the time zone file: " << path << logend;
}
temp_space.Clear();
temp_space.clear();
return status == PT::SpaceParser::ok;
return status == pt::SpaceParser::ok;
}
+2 -2
View File
@@ -98,8 +98,8 @@ private:
// everywhere we use zone_index we refer to this table
std::vector<TimeZone> zone_tab;
PT::SpaceParser parser;
PT::Space temp_space;
pt::SpaceParser parser;
pt::Space temp_space;
TimeZone temp_zone;
void ParseZones();
+12 -2
View File
@@ -79,8 +79,18 @@ void Users::Clear()
void Users::ReadUsers(Db * db)
{
Clear();
db->GetUsers(table);
Clear();
morm::Finder<User> finder(model_connector);
std::list<User> users_tmp = finder.
select().
get_list();
for(User & user : users_tmp)
{
table.PushBack(user);
}
}
+1 -1
View File
@@ -36,7 +36,7 @@
#define headerfile_winix_core_users
#include <map>
#include "user.h"
#include "models/user.h"
#include "ugcontainer.h"
#include "lastcontainer.h"
#include "cur.h"
+1 -1
View File
@@ -42,7 +42,7 @@ namespace Winix
#define WINIX_VER_MAJOR 0
#define WINIX_VER_MINOR 7
#define WINIX_VER_REVISION 1
#define WINIX_VER_REVISION 3
+9 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018, Tomasz Sowa
* Copyright (c) 2018-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,7 +63,7 @@ void WinixBase::set_synchro(Synchro * synchro)
}
void WinixBase::set_log_buffer(PT::WTextStream * log_buffer)
void WinixBase::set_log_buffer(pt::WTextStream * log_buffer)
{
log.SetLogBuffer(log_buffer);
}
@@ -90,6 +90,13 @@ void WinixBase::set_dependency(WinixBase * winix_base)
void WinixBase::save_log()
{
log << logsave;
}
}
+4 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018, Tomasz Sowa
* Copyright (c) 2018-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,13 +58,15 @@ public:
void set_config(Config * config);
void set_synchro(Synchro * synchro);
void set_log_buffer(PT::WTextStream * log_buffer);
void set_log_buffer(pt::WTextStream * log_buffer);
void set_file_log(FileLog * file_log);
Log * get_logger();
void set_dependency(WinixBase * winix_base);
void save_log();
protected:
+6
View File
@@ -65,6 +65,12 @@ void WinixModel::set_model_connector(morm::ModelConnector * model_connector)
}
morm::ModelConnector * WinixModel::get_model_connector()
{
return model_connector;
}
void WinixModel::set_dependency(WinixBase * winix_base)
{
WinixBase::set_dependency(winix_base);
+3 -1
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018, Tomasz Sowa
* Copyright (c) 2018-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,6 +52,8 @@ public:
virtual ~WinixModel();
void set_model_connector(morm::ModelConnector * model_connector);
morm::ModelConnector * get_model_connector();
void set_plugin(Plugin * plugin);
void set_dependency(WinixBase * winix_base);
+1 -1
View File
@@ -3,7 +3,7 @@ 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
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/src
all: $(o)
+23 -102
View File
@@ -2,143 +2,64 @@
db.o: db.h dbbase.h dbconn.h dbtextstream.h
db.o: ../../../winix/winixd/core/textstream.h
db.o: ../../../winix/winixd/core/misc.h ../../../winix/winixd/core/item.h
db.o: ../../../pikotools/space/space.h ../../../pikotools/textstream/types.h
db.o: ../../../pikotools/date/date.h ../../../pikotools/convert/inttostr.h
db.o: ../../../winix/winixd/core/misc.h
db.o: ../../../winix/winixd/core/requesttypes.h
db.o: ../../../pikotools/textstream/textstream.h
db.o: ../../../pikotools/membuffer/membuffer.h
db.o: ../../../pikotools/textstream/types.h ../../../pikotools/utf8/utf8.h
db.o: ../../../winix/winixd/core/winix_const.h
db.o: ../../../pikotools/convert/convert.h
db.o: ../../../pikotools/convert/inttostr.h
db.o: ../../../pikotools/convert/patternreplacer.h
db.o: ../../../pikotools/convert/strtoint.h ../../../pikotools/convert/text.h
db.o: ../../../winix/winixd/core/winixbase.h
db.o: ../../../winix/winixd/core/config.h
db.o: ../../../pikotools/space/spaceparser.h ../../../pikotools/space/space.h
db.o: ../../../winix/winixd/core/log.h
db.o: ../../../winix/winixd/core/config.h ../../../winix/winixd/core/log.h
db.o: ../../../winix/winixd/core/logmanipulators.h
db.o: ../../../pikotools/log/log.h ../../../pikotools/log/filelog.h
db.o: ../../../winix/winixd/core/log.h ../../../winix/winixd/core/synchro.h
db.o: ../../../winix/winixd/core/filelog.h
db.o: ../../../winix/winixd/core/synchro.h ../../../winix/winixd/core/log.h
db.o: ../../../winix/winixd/core/filelog.h ../../../winix/winixd/core/lock.h
db.o: ../../../winix/winixd/core/synchro.h ../../../winix/winixd/core/error.h
db.o: dbitemquery.h ../../../winix/winixd/core/item.h dbitemcolumns.h
db.o: ../../../winix/winixd/core/user.h ../../../winix/winixd/core/group.h
db.o: ../../../winix/winixd/models/user.h ../../../morm/src/model.h
db.o: ../../../morm/src/modelconnector.h ../../../morm/src/clearer.h
db.o: ../../../morm/src/dbconnector.h ../../../morm/src/queryresult.h
db.o: ../../../morm/src/ft.h ../../../morm/src/flatconnector.h
db.o: ../../../morm/src/dbexpression.h ../../../morm/src/baseexpression.h
db.o: ../../../morm/src/morm_types.h ../../../morm/src/modelenv.h
db.o: ../../../morm/src/modeldata.h ../../../morm/src/cursorhelper.h
db.o: ../../../morm/src/finderhelper.h ../../../morm/src/fieldvaluehelper.h
db.o: ../../../morm/src/flatexpression.h ../../../winix/winixd/models/group.h
db.o: ../../../winix/winixd/core/dircontainer.h
db.o: ../../../winix/winixd/core/winixbase.h
db.o: ../../../winix/winixd/models/item.h
db.o: ../../../winix/winixd/models/itemcontent.h
db.o: ../../../winix/winixd/core/ugcontainer.h
db.o: ../../../winix/winixd/core/misc.h
dbbase.o: dbbase.h dbconn.h dbtextstream.h
dbbase.o: ../../../winix/winixd/core/textstream.h
dbbase.o: ../../../winix/winixd/core/misc.h ../../../winix/winixd/core/item.h
dbbase.o: ../../../pikotools/space/space.h
dbbase.o: ../../../pikotools/textstream/types.h
dbbase.o: ../../../pikotools/date/date.h
dbbase.o: ../../../pikotools/convert/inttostr.h
dbbase.o: ../../../winix/winixd/core/misc.h
dbbase.o: ../../../winix/winixd/core/requesttypes.h
dbbase.o: ../../../pikotools/textstream/textstream.h
dbbase.o: ../../../pikotools/membuffer/membuffer.h
dbbase.o: ../../../pikotools/textstream/types.h
dbbase.o: ../../../pikotools/utf8/utf8.h
dbbase.o: ../../../winix/winixd/core/winix_const.h
dbbase.o: ../../../pikotools/convert/convert.h
dbbase.o: ../../../pikotools/convert/inttostr.h
dbbase.o: ../../../pikotools/convert/patternreplacer.h
dbbase.o: ../../../pikotools/convert/strtoint.h
dbbase.o: ../../../pikotools/convert/text.h
dbbase.o: ../../../winix/winixd/core/winixbase.h
dbbase.o: ../../../winix/winixd/core/config.h
dbbase.o: ../../../pikotools/space/spaceparser.h
dbbase.o: ../../../pikotools/space/space.h ../../../winix/winixd/core/log.h
dbbase.o: ../../../winix/winixd/core/logmanipulators.h
dbbase.o: ../../../pikotools/log/log.h ../../../pikotools/log/filelog.h
dbbase.o: ../../../winix/winixd/core/log.h
dbbase.o: ../../../winix/winixd/core/logmanipulators.h
dbbase.o: ../../../winix/winixd/core/filelog.h
dbbase.o: ../../../winix/winixd/core/synchro.h
dbbase.o: ../../../winix/winixd/core/log.h
dbbase.o: ../../../winix/winixd/core/filelog.h
dbbase.o: ../../../winix/winixd/core/lock.h
dbbase.o: ../../../winix/winixd/core/synchro.h
dbbase.o: ../../../winix/winixd/core/error.h
dbbase.o: ../../../winix/winixd/core/misc.h
dbconn.o: dbconn.h dbtextstream.h ../../../winix/winixd/core/textstream.h
dbconn.o: ../../../winix/winixd/core/misc.h ../../../winix/winixd/core/item.h
dbconn.o: ../../../pikotools/space/space.h
dbconn.o: ../../../pikotools/textstream/types.h
dbconn.o: ../../../pikotools/date/date.h
dbconn.o: ../../../pikotools/convert/inttostr.h
dbconn.o: ../../../winix/winixd/core/misc.h
dbconn.o: ../../../winix/winixd/core/requesttypes.h
dbconn.o: ../../../pikotools/textstream/textstream.h
dbconn.o: ../../../pikotools/membuffer/membuffer.h
dbconn.o: ../../../pikotools/textstream/types.h
dbconn.o: ../../../pikotools/utf8/utf8.h
dbconn.o: ../../../winix/winixd/core/winix_const.h
dbconn.o: ../../../pikotools/convert/convert.h
dbconn.o: ../../../pikotools/convert/inttostr.h
dbconn.o: ../../../pikotools/convert/patternreplacer.h
dbconn.o: ../../../pikotools/convert/strtoint.h
dbconn.o: ../../../pikotools/convert/text.h
dbconn.o: ../../../winix/winixd/core/winixbase.h
dbconn.o: ../../../winix/winixd/core/config.h
dbconn.o: ../../../pikotools/space/spaceparser.h
dbconn.o: ../../../pikotools/space/space.h ../../../winix/winixd/core/log.h
dbconn.o: ../../../winix/winixd/core/logmanipulators.h
dbconn.o: ../../../pikotools/log/log.h ../../../pikotools/log/filelog.h
dbconn.o: ../../../winix/winixd/core/log.h
dbconn.o: ../../../winix/winixd/core/logmanipulators.h
dbconn.o: ../../../winix/winixd/core/filelog.h
dbconn.o: ../../../winix/winixd/core/synchro.h
dbconn.o: ../../../winix/winixd/core/log.h
dbconn.o: ../../../winix/winixd/core/filelog.h
dbconn.o: ../../../winix/winixd/core/lock.h
dbconn.o: ../../../winix/winixd/core/synchro.h
dbconn.o: ../../../winix/winixd/core/error.h
dbitemcolumns.o: dbitemcolumns.h ../../../winix/winixd/core/item.h dbbase.h
dbitemcolumns.o: dbconn.h dbtextstream.h
dbitemcolumns.o: ../../../winix/winixd/core/textstream.h
dbitemcolumns.o: ../../../winix/winixd/core/misc.h
dbitemcolumns.o: ../../../winix/winixd/core/item.h
dbitemcolumns.o: ../../../pikotools/space/space.h
dbitemcolumns.o: ../../../pikotools/textstream/types.h
dbitemcolumns.o: ../../../pikotools/date/date.h
dbitemcolumns.o: ../../../pikotools/convert/inttostr.h
dbitemcolumns.o: ../../../winix/winixd/core/requesttypes.h
dbitemcolumns.o: ../../../pikotools/textstream/textstream.h
dbitemcolumns.o: ../../../pikotools/membuffer/membuffer.h
dbitemcolumns.o: ../../../pikotools/textstream/types.h
dbitemcolumns.o: ../../../pikotools/utf8/utf8.h
dbitemcolumns.o: ../../../winix/winixd/core/winix_const.h
dbitemcolumns.o: ../../../pikotools/convert/convert.h
dbitemcolumns.o: ../../../pikotools/convert/inttostr.h
dbitemcolumns.o: ../../../pikotools/convert/patternreplacer.h
dbitemcolumns.o: ../../../pikotools/convert/strtoint.h
dbitemcolumns.o: ../../../pikotools/convert/text.h
dbitemcolumns.o: ../../../winix/winixd/core/winixbase.h
dbitemcolumns.o: ../../../winix/winixd/core/config.h
dbitemcolumns.o: ../../../pikotools/space/spaceparser.h
dbitemcolumns.o: ../../../pikotools/space/space.h
dbitemcolumns.o: ../../../winix/winixd/core/log.h
dbitemcolumns.o: ../../../winix/winixd/core/logmanipulators.h
dbitemcolumns.o: ../../../pikotools/log/log.h
dbitemcolumns.o: ../../../pikotools/log/filelog.h
dbitemcolumns.o: ../../../winix/winixd/core/log.h
dbitemcolumns.o: ../../../winix/winixd/core/synchro.h
dbitemcolumns.o: ../../../winix/winixd/core/filelog.h
dbitemcolumns.o: ../../../winix/winixd/core/lock.h
dbitemcolumns.o: ../../../winix/winixd/core/synchro.h
dbitemcolumns.o: ../../../winix/winixd/core/error.h
dbitemquery.o: dbitemquery.h ../../../winix/winixd/core/item.h
dbtextstream.o: dbtextstream.h ../../../winix/winixd/core/textstream.h
dbtextstream.o: ../../../winix/winixd/core/misc.h
dbtextstream.o: ../../../winix/winixd/core/item.h
dbtextstream.o: ../../../pikotools/space/space.h
dbtextstream.o: ../../../pikotools/textstream/types.h
dbtextstream.o: ../../../pikotools/date/date.h
dbtextstream.o: ../../../pikotools/convert/inttostr.h
dbtextstream.o: ../../../winix/winixd/core/requesttypes.h
dbtextstream.o: ../../../pikotools/textstream/textstream.h
dbtextstream.o: ../../../pikotools/membuffer/membuffer.h
dbtextstream.o: ../../../pikotools/textstream/types.h
dbtextstream.o: ../../../pikotools/utf8/utf8.h
dbtextstream.o: ../../../winix/winixd/core/winix_const.h
dbtextstream.o: ../../../pikotools/convert/convert.h
dbtextstream.o: ../../../pikotools/convert/inttostr.h
dbtextstream.o: ../../../pikotools/convert/patternreplacer.h
dbtextstream.o: ../../../pikotools/convert/strtoint.h
dbtextstream.o: ../../../pikotools/convert/text.h
+1 -1
View File
@@ -1 +1 @@
o = db.o dbbase.o dbconn.o dbitemcolumns.o dbitemquery.o dbtextstream.o
o = db.o dbbase.o dbconn.o dbtextstream.o
+26 -1403
View File
File diff suppressed because it is too large Load Diff
+10 -90
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,11 +41,8 @@
#include <ctime>
#include <cstring>
#include "dbbase.h"
#include "dbitemquery.h"
#include "dbitemcolumns.h"
#include "core/item.h"
#include "core/user.h"
#include "core/group.h"
#include "models/user.h"
#include "models/group.h"
#include "core/dircontainer.h"
#include "core/ugcontainer.h"
@@ -54,24 +51,19 @@ namespace Winix
{
class Db : public DbBase
{
public:
// !! przerobic tak aby GetItem zwracalo wszystkie pozycja
// !! GetFile tylko dla plikow
// !! GetDir tylko dla katalogow
// !! GetFile i GetDir beda uzywac GetItem
Db() : item_cols(*this)
Db()
{
is_postgresql_smaller_than_10 = false;
}
void PostgreSQLsmallerThan10(bool is_smaller_than_10);
//void PostgreSQLsmallerThan10(bool is_smaller_than_10);
/*
bool GetUserPass(const std::wstring & login, long & user_id, UserPass & up);
Error AddUser(User & user, const UserPass & up);
Error ChangeUserPass(long user_id, const UserPass & up);
@@ -83,91 +75,19 @@ public:
Error ChangeUserTimeZone(long user_id, size_t time_zone_id);
Error RemoveUser(long user_id);
Error AddItem(Item & item);
Error EditItemById(Item & item, bool with_url = true);
Error EditItemByUrl(Item & item, bool with_url = true);
// !! nie zwracac zadnych kodow bledow?
void GetItems(std::vector<Item> & item_tab, const DbItemQuery & item_query);
void GetItems(std::vector<long> & item_tab, const DbItemQuery & item_query);
Error GetItem(Item & item, const DbItemQuery & item_query);
bool GetPriv(Item & item, long id);
Error EditPrivById(Item & item, long id); // !! dlaczego tu nie ma const?
Error EditParentUrlById(Item & item, long id);
Error EditFileById(const Item & item, long id); // file_path, file_fs, file_type
Error EditHasThumbById(bool has_thumb, long id);
Error EditMetaById(const PT::Space & meta, long id);
Error EditAdminMetaById(const PT::Space & meta, long id);
Error DelDirById(long id);
Error DelFileById(long file_id);
Error DelSymlinkById(long symlink_id);
Error EditSubjectById(Item & item, long id);
Error DelItem(const Item & item);
void GetDirs(DirContainer & dir_tab);
void GetUsers(UGContainer<User> & user_tab);
void GetGroups(UGContainer<Group> & group_tab);
// !! nowy interfejs
long Size(long parent_id, Item::Type type = Item::none);
Error GetItemById(long item_id, Item & item);
Error GetItem(long parent_id, const std::wstring & url, Item & item);
Error EditLinkItem(long id, const std::wstring & link_to, int link_redirect);
Error EditTemplateItemById(long id, const std::wstring & new_html_template);
long GetItemId(long parent_id, const std::wstring & url, Item::Type type);
long GetFileId(long parent_id, const std::wstring & url);
long GetDirId(long parent_id, const std::wstring & url);
Error AddHardLink(Item & item);
Error EditSortIndexItemById(long id, int sort_index);
protected:
DbTextStream query, query_create_url;
std::wstring temp_url;
Item dir_temp;
Item get_item_temp;
std::wstring iq_id_list;
DbItemColumns item_cols;
*/
bool is_postgresql_smaller_than_10;
std::wstring postgrsql_row_statement;
bool is_postgresql_smaller_than_10;
bool AddItemCreateUrlSubject(Item & item);
Error AddItemIntoContent(Item & item);
Error AddItemIntoItem(Item & item);
Error EditItemInItem(Item & item, bool with_url);
Error EditItemInContent(Item & item);
Error EditItemGetIdsByUrl(Item & item);
long GetContentId(long item_id);
Error DelItemDelItem(long item_id, int type);
Error DelItemDelContent(long content_id);
Error IncrementContentRef(long content_id);
Error DecrementContentRef(long content_id);
void GetItemsQuerySelect(const DbItemQuery & iq, DbTextStream & query, bool skip_other_sel);
void GetItemsQueryJoin(const DbItemQuery & iq, DbTextStream & query);
void GetItemsQueryWhere(const DbItemQuery & iq, DbTextStream & query);
void GetItemsQueryOrder(bool sort_asc);
void GetItemsQueryOrder(const DbItemQuery & iq, DbTextStream & query);
void GetItemsQueryLimit(const DbItemQuery & iq, DbTextStream & query);
PGresult * GetItemsQuery(const DbItemQuery & iq, DbTextStream & query, bool skip_other_sel = false);
PGresult * GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel = false);
};
+11 -14
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -187,7 +187,7 @@ const std::wstring & DbBase::AssertValueWide(PGresult * r, int row, int col)
const char * res = AssertValue(r, row, col);
static std::wstring temp_wide_value; // !! IMPROVE ME add as a class field (nonstatic)
PT::UTF8ToWide(res, temp_wide_value);
pt::utf8_to_wide(res, temp_wide_value);
return temp_wide_value;
}
@@ -211,7 +211,7 @@ void DbBase::AssertValueBin(PGresult * r, int row, int col, std::string & result
void DbBase::AssertValueWide(PGresult * r, int row, int col, std::wstring & result)
{
const char * res = AssertValue(r, row, col);
PT::UTF8ToWide(res, result);
pt::utf8_to_wide(res, result);
}
@@ -247,33 +247,30 @@ unsigned int DbBase::AssertValueUInt(PGresult * r, int row, int col)
PT::Date DbBase::AssertValueDate(PGresult * r, int row, int col)
pt::Date DbBase::AssertValueDate(PGresult * r, int row, int col)
{
PT::Date date = AssertValue(r, row, col);
pt::Date date = AssertValue(r, row, col);
return date;
}
bool DbBase::AssertValueSpace(PGresult * r, int row, int col, PT::Space & space)
bool DbBase::AssertValueSpace(PGresult * r, int row, int col, pt::Space & space)
{
const char * res = AssertValue(r, row, col);
conf_parser.SetSpace(space);
space.Clear();
pt::SpaceParser::Status status = conf_parser.parse_space(res, space);
PT::SpaceParser::Status status = conf_parser.ParseString(res);
if( status != PT::SpaceParser::ok )
if( status != pt::SpaceParser::ok )
{
log << log1 << "Db: a problem with parsing a PT::Space";
if( status == PT::SpaceParser::syntax_error )
log << ", syntax error at line: " << conf_parser.line;
if( status == pt::SpaceParser::syntax_error )
log << ", syntax error at line: " << conf_parser.get_last_parsed_line();
log << logend;
space.Clear();
space.clear();
return false;
}
+3 -3
View File
@@ -80,9 +80,9 @@ public:
bool AssertValueBool(PGresult * r, int row, int col);
unsigned long AssertValueULong(PGresult * r, int row, int col);
unsigned int AssertValueUInt(PGresult * r, int row, int col);
PT::Date AssertValueDate(PGresult * r, int row, int col);
pt::Date AssertValueDate(PGresult * r, int row, int col);
bool AssertValueSpace(PGresult * r, int row, int col, PT::Space & space);
bool AssertValueSpace(PGresult * r, int row, int col, pt::Space & space);
void ClearResult(PGresult * r);
long AssertCurrval(const char * table);
@@ -129,7 +129,7 @@ private:
char UnescapeBinHexToDigit(char hex);
DbTextStream bquery;
PT::SpaceParser conf_parser;
pt::SpaceParser conf_parser;
};
-123
View File
@@ -1,123 +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 "dbitemcolumns.h"
#include "dbbase.h"
#include "core/log.h"
namespace Winix
{
void DbItemColumns::SetColumns(PGresult * r)
{
// PQfnumber returns -1 if there is no such a column
id = PQfnumber(r, "id");
user_id = PQfnumber(r, "user_id");
group_id = PQfnumber(r, "group_id");
privileges = PQfnumber(r, "privileges");
date_creation = PQfnumber(r, "date_creation");
date_modification = PQfnumber(r, "date_modification");
url = PQfnumber(r, "url");
type = PQfnumber(r, "type");
parent_id = PQfnumber(r, "parent_id");
content_id = PQfnumber(r, "content_id");
link_to = PQfnumber(r, "link_to");
link_redirect = PQfnumber(r, "link_redirect");
subject = PQfnumber(r, "subject");
content = PQfnumber(r, "content");
content_type = PQfnumber(r, "content_type");
guest_name = PQfnumber(r, "guest_name");
html_template = PQfnumber(r, "template");
modification_user_id = PQfnumber(r, "modification_user_id");
file_path = PQfnumber(r, "file_path");
file_fs = PQfnumber(r, "file_fs");
file_type = PQfnumber(r, "file_type");
has_thumb = PQfnumber(r, "has_thumb");
hash = PQfnumber(r, "hash");
hash_type = PQfnumber(r, "hash_type");
file_size = PQfnumber(r, "file_size");
ref = PQfnumber(r, "ref");
modify_index = PQfnumber(r, "modify_index");
sort_index = PQfnumber(r, "sort_index");
meta = PQfnumber(r, "meta");
ameta = PQfnumber(r, "ameta");
}
void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
{
if( id != -1 ) item.id = db_base.AssertValueLong(r, row, id);
if( user_id != -1 ) item.user_id = db_base.AssertValueLong(r, row, user_id);
if( group_id != -1 ) item.group_id = db_base.AssertValueLong(r, row, group_id);
if( privileges != -1 ) item.privileges = db_base.AssertValueInt(r, row, privileges);
if( date_creation != -1 ) item.date_creation = db_base.AssertValueDate(r, row, date_creation);
if( date_modification != -1 ) item.date_modification = db_base.AssertValueDate(r, row, date_modification);
if( type != -1 ) item.type = static_cast<Item::Type>( db_base.AssertValueInt(r, row, type) );
if( parent_id != -1 ) item.parent_id = db_base.AssertValueLong(r, row, parent_id);
if( content_id != -1 ) item.content_id = db_base.AssertValueLong(r, row, content_id);
if( link_redirect != -1 ) item.link_redirect = db_base.AssertValueInt(r, row, link_redirect);
if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( db_base.AssertValueInt(r, row, content_type) );
if( modification_user_id != -1 ) item.modification_user_id = db_base.AssertValueLong(r, row, modification_user_id);
if( file_fs != -1 ) item.file_fs = db_base.AssertValueInt(r, row, file_fs);
if( file_type != -1 ) item.file_type = db_base.AssertValueInt(r, row, file_type);
if( has_thumb != -1 ) item.has_thumb = db_base.AssertValueBool(r, row, has_thumb);
if( hash != -1 ) db_base.AssertValueWide(r, row, hash, item.hash);
if( hash_type != -1 ) item.hash_type = db_base.AssertValueInt(r, row, hash_type);
if( file_size != -1 ) item.file_size = db_base.AssertValueLong(r, row, file_size);
if( ref != -1 ) item.ref = db_base.AssertValueInt(r, row, ref);
if( modify_index != -1 ) item.modify_index = db_base.AssertValueInt(r, row, modify_index);
if( url != -1 ) db_base.AssertValueWide(r, row, url, item.url);
if( content != -1 ) db_base.AssertValueWide(r, row, content, item.content);
if( subject != -1 ) db_base.AssertValueWide(r, row, subject, item.subject);
if( file_path != -1 ) db_base.AssertValueWide(r, row, file_path, item.file_path);
if( link_to != -1 ) db_base.AssertValueWide(r, row, link_to, item.link_to);
if( guest_name != -1 ) db_base.AssertValueWide(r, row, guest_name, item.guest_name);
if( html_template != -1 ) db_base.AssertValueWide(r, row, html_template, item.html_template);
if( sort_index != -1 ) item.sort_index = db_base.AssertValueInt(r, row, sort_index);
if( meta != -1 ) db_base.AssertValueSpace(r, row, meta, item.meta);
if( ameta != -1 ) db_base.AssertValueSpace(r, row, ameta, item.ameta);
}
} // namespace Winix
-164
View File
@@ -1,164 +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-2015, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "dbitemquery.h"
namespace Winix
{
DbItemQuery::DbItemQuery()
{
Clear();
}
void DbItemQuery::Clear()
{
sort_index_asc = true;
sort_date_asc = true;
SetAll(true, false);
id = -1;
id_tab = 0;
parent_id = -1;
type = Item::none;
file_type = WINIX_ITEM_FILETYPE_NONE;
type_equal = true;
file_type_equal = true;
limit = 0; // limit and offset not used by default
offset = 0;
}
void DbItemQuery::SetAllSel(bool sel)
{
sel_parent_id = sel;
sel_user_id = sel;
sel_group_id = sel;
sel_guest_name = sel;
sel_privileges = sel;
sel_date = sel;
sel_subject = sel;
sel_content = sel;
sel_url = sel;
sel_type = sel;
sel_link = sel;
sel_file = sel;
sel_html_template = sel;
sel_sort_index = sel;
sel_meta = sel;
}
void DbItemQuery::SetAllWhere(bool where_)
{
where_id = where_;
where_parent_id = where_;
where_type = where_;
where_file_type = where_;
}
void DbItemQuery::SetAll(bool sel, bool where_)
{
SetAllSel(sel);
SetAllWhere(where_);
}
void DbItemQuery::WhereId(long id_)
{
where_id = true;
id = id_;
}
void DbItemQuery::WhereIdIn(const std::vector<long> & id_tab_list)
{
id_tab = &id_tab_list;
}
void DbItemQuery::WhereParentId(long parent_id_)
{
where_parent_id = true;
parent_id = parent_id_;
}
void DbItemQuery::WhereType(Item::Type type_, bool equal)
{
where_type = true;
type = type_;
type_equal = equal;
}
void DbItemQuery::WhereFileType(int file_t, bool equal)
{
where_file_type = true;
file_type = file_t;
file_type_equal = equal;
}
void DbItemQuery::Limit(long l)
{
limit = l;
}
void DbItemQuery::Offset(long o)
{
offset = o;
}
} // namespace Winix
-112
View File
@@ -1,112 +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-2015, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_winix_db_dbitemquery
#define headerfile_winix_db_dbitemquery
#include <vector>
#include "core/item.h"
namespace Winix
{
struct DbItemQuery
{
// id and content_id is selected always
bool sel_parent_id; // parent_id
bool sel_user_id; // user_id, modification_user_id
bool sel_group_id; // group_id
bool sel_guest_name; // guest_name
bool sel_privileges; // privileges
bool sel_date; // date_creation, date_modification
bool sel_subject; // subject
bool sel_content; // content, content_type, ref, modify_index
bool sel_url; // url
bool sel_type; // type (dir, file, none)
bool sel_link; // link_to, link_redirect
bool sel_file; // file_path, file_fs, file_type, has_thumb, hash, hash_type, file_size
bool sel_html_template; // template
bool sel_sort_index; // sort_index
bool sel_meta; // meta and ameta (PT::Space)
bool where_id; //
bool where_parent_id; //
bool where_type;
bool where_file_type;
long id; // if where_id is true
long parent_id; // if where_parent_id is true
Item::Type type;
bool type_equal;
int file_type;
bool file_type_equal; // if true means file_type should be equal
bool sort_index_asc;
bool sort_date_asc;
const std::vector<long> * id_tab; // != 0 if WhereIdIn was used
long limit;
long offset;
DbItemQuery();
void Clear();
void SetAllSel(bool sel);
void SetAllWhere(bool where_);
void SetAll(bool sel, bool where_);
void WhereId(long id_);
void WhereIdIn(const std::vector<long> & id_tab_list);
void WhereParentId(long parent_id_);
void WhereType(Item::Type type_, bool equal = true);
void WhereFileType(int file_t, bool equal = true);
void Limit(long l); // setting 0 turns off
void Offset(long o); // setting 0 turns off
};
} // namespace Winix
#endif
+7 -7
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -225,11 +225,11 @@ return *this;
DbTextStream & DbTextStream::operator<<(RawText<PT::Date> date)
DbTextStream & DbTextStream::operator<<(RawText<pt::Date> date)
{
tmp_stream.Clear();
date.par.Serialize(tmp_stream);
PT::WideToUTF8(tmp_stream.CStr(), buffer, false);
pt::wide_to_utf8(tmp_stream.CStr(), buffer, false);
tmp_stream.Clear();
was_param = false;
@@ -290,7 +290,7 @@ DbTextStream & DbTextStream::ETextPutChar(wchar_t c)
buffer += "\\\'"; // don't use "''" because we use the method for PQconnectdb too
else
if( c != 0 )
PT::IntToUTF8(int(c), buffer, false);
pt::int_to_utf8(int(c), buffer, false);
return *this;
}
@@ -584,12 +584,12 @@ return *this;
DbTextStream & DbTextStream::operator<<(const PT::Space & space)
DbTextStream & DbTextStream::operator<<(const pt::Space & space)
{
tmp_stream.Clear();
// !! IMPROVE ME
// we can calculate how much memory is needed before serializing
space.Serialize(tmp_stream, true, false);
space.serialize_to_space_stream(tmp_stream, true);
operator<<(tmp_stream.Str());
tmp_stream.Clear();
@@ -597,7 +597,7 @@ return *this;
}
DbTextStream & DbTextStream::operator<<(const PT::Date & date)
DbTextStream & DbTextStream::operator<<(const pt::Date & date)
{
tmp_stream.Clear();
date.Serialize(tmp_stream);
+8 -8
View File
@@ -143,10 +143,10 @@ public:
DbTextStream & operator<<(RawText<unsigned long> raw);
DbTextStream & operator<<(RawText<double> raw);
DbTextStream & operator<<(RawText<void*> raw);
DbTextStream & operator<<(RawText<PT::Date> date);
DbTextStream & operator<<(RawText<pt::Date> date);
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
DbTextStream & operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw);
DbTextStream & operator<<(RawText<pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw);
/*
with escaping
@@ -183,11 +183,11 @@ public:
DbTextStream & operator<<(double);
DbTextStream & operator<<(const void *);
DbTextStream & operator<<(const std::vector<long> & tabid);
DbTextStream & operator<<(const PT::Space & space);
DbTextStream & operator<<(const PT::Date & date);
DbTextStream & operator<<(const pt::Space & space);
DbTextStream & operator<<(const pt::Date & date);
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
DbTextStream & operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
DbTextStream & operator<<(const pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
private:
@@ -202,7 +202,7 @@ private:
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
DbTextStream & DbTextStream::operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw)
DbTextStream & DbTextStream::operator<<(RawText<pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw)
{
TextStream<std::string>::operator<<(raw.par);
@@ -212,9 +212,9 @@ return *this;
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
DbTextStream & DbTextStream::operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
DbTextStream & DbTextStream::operator<<(const pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
{
typename PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
typename pt::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
if( was_param )
buffer += ", ";
+704 -704
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -3,7 +3,7 @@ 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
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/src
all: $(o)
+1194 -1915
View File
File diff suppressed because it is too large Load Diff
+6 -7
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2013-2018, Tomasz Sowa
* Copyright (c) 2013-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,18 +55,17 @@ Account::Account()
bool Account::ActivateAccount(User * puser, long code, bool use_ses_log)
{
std::wstring * user_code_str = puser->aenv.GetFirstValue(L"activation_code");
std::wstring * user_code_str = puser->aenv.get_wstr(L"activation_code");
if( user_code_str )
{
if( Tol(*user_code_str) == code )
{
if( db->ChangeUserStatus(puser->id, WINIX_ACCOUNT_READY) == WINIX_ERR_OK )
{
puser->aenv.Remove(L"activation_code");
db->ChangeUserAdminEnv(puser->id, puser->aenv);
puser->status = WINIX_ACCOUNT_READY;
puser->status = WINIX_ACCOUNT_READY;
puser->aenv.remove(L"activation_code");
if( puser->update() )
{
log << log2 << "Account: account: " << puser->name << " activated" << logend;
if( use_ses_log )
+10 -7
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -162,11 +162,11 @@ return true;
*/
bool AddUser::AddNewUser(User & user, const std::wstring & pass)
{
up.has_pass = true;
up.pass = pass;
system->crypt.PassHashCrypt(up);
user.has_pass = true;
user.password = pass;
system->crypt.PassHashCrypt(user);
if( db->AddUser(user, up) == WINIX_ERR_OK )
if( user.insert() )
{
if( system->users.AddUser(user) )
{
@@ -213,7 +213,10 @@ bool AddUser::AddNewUser(const std::wstring & login,
bool try_login,
bool use_ses_log)
{
user.Clear();
user.set_connector(model_connector);
user.clear();
//user.Clear();
user.name = login;
user.email = email;
user.super_user = false;
@@ -229,7 +232,7 @@ bool AddUser::AddNewUser(const std::wstring & login,
if( user.status == WINIX_ACCOUNT_NOT_ACTIVATED )
{
code = std::rand();
user.aenv.Add(L"activation_code", code);
user.aenv.add(L"activation_code", code);
}
if( AddNewUser(user, pass) )
+2 -3
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,7 +36,7 @@
#define headerfile_winix_functions_adduser
#include "functionbase.h"
#include "core/user.h"
#include "models/user.h"
namespace Winix
{
@@ -69,7 +69,6 @@ public:
private:
UserPass up;
User user;
};
+40 -24
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -135,15 +135,15 @@ bool Cp::CopyStaticFile(const std::wstring & from, const std::wstring & to)
void Cp::CopyStaticFile(Item & item)
{
bool res1, res2, res3, res4, res5;
bool ok = true;
res1 = system->MakeFilePath(item, old_path, false);
res2 = !item.has_thumb || system->MakeFilePath(item, old_path_thumb, true);
res3 = system->CreateNewFile(item);
res4 = system->MakeFilePath(item, new_path, false, true, config->upload_dirs_chmod);
res5 = !item.has_thumb || system->MakeFilePath(item, new_path_thumb, true, true, config->upload_dirs_chmod);
ok = ok && system->MakeFilePath(item, old_path, false);
ok = ok && (!item.item_content.file_has_thumb || system->MakeFilePath(item, old_path_thumb, true));
ok = ok && system->CreateNewFile(item);
ok = ok && system->MakeFilePath(item, new_path, false, true, config->upload_dirs_chmod);
ok = ok && (!item.item_content.file_has_thumb || system->MakeFilePath(item, new_path_thumb, true, true, config->upload_dirs_chmod));
if( !res1 || !res2 || !res3 || !res4 || !res5 )
if( !ok )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
@@ -151,9 +151,15 @@ bool res1, res2, res3, res4, res5;
if( CopyStaticFile(old_path, new_path) )
{
cur->request->status = db->EditFileById(item, item.id);
//cur->request->status = db->EditFileById(item, item.id);
item.propagate_connector();
if( item.has_thumb )
if( !item.item_content.update() )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
if( item.item_content.file_has_thumb )
CopyStaticFile(old_path_thumb, new_path_thumb);
}
}
@@ -162,9 +168,9 @@ bool res1, res2, res3, res4, res5;
void Cp::SetNewAttributes(Item & item)
{
item.user_id = new_user;
item.group_id = new_group;
item.SetDateModifyToNow();
item.item_content.user_id = new_user;
item.item_content.group_id = new_group;
item.item_content.SetDateModifyToNow();
}
@@ -174,11 +180,12 @@ void Cp::CopyFile(Item & item, long dst_dir_id)
SetNewAttributes(item);
item.parent_id = dst_dir_id;
cur->request->status = db->AddItem(item);
if( cur->request->status == WINIX_ERR_OK )
// cur->request->status = db->AddItem(item);
// if( cur->request->status == WINIX_ERR_OK )
if( item.insert() )
{
if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
if( item.item_content.file_type != WINIX_ITEM_FILETYPE_NONE )
CopyStaticFile(item);
plugin->Call(WINIX_FILE_COPIED, &item);
@@ -195,7 +202,7 @@ void Cp::CopyFileOrSymlink(Item & item, long dst_dir_id)
{
if( system->dirs.CreateDirTab(item.parent_id, symlink_dir_tab) )
{
int res = system->FollowAllLinks(symlink_dir_tab, item.link_to, symlink_dir_tab, item);
int res = system->FollowAllLinks(symlink_dir_tab, item.item_content.link_to, symlink_dir_tab, item);
if( res == 0 )
CopyDirTree(*symlink_dir_tab.back(), dst_dir_id);
@@ -215,11 +222,11 @@ void Cp::CopyFileOrSymlink(Item & item, long dst_dir_id)
void Cp::Prepare()
{
iq.SetAll(true, false);
iq.WhereType(Item::dir, false);
// iq.SetAll(true, false);
// iq.WhereType(Item::dir, false);
new_user = -1;
new_group = dir_tab.back()->group_id;
new_group = dir_tab.back()->item_content.group_id;
if( cur->session->puser )
new_user = cur->session->puser->id;
@@ -232,8 +239,17 @@ void Cp::Prepare()
void Cp::CopyFilesInDir(const Item & dir, long dst_dir_id)
{
iq.WhereParentId(dir.id);
db->GetItems(item_tab, iq);
morm::Finder<Item> finder(model_connector);
item_tab = finder.
select().
where().
neq(L"type", static_cast<int>(Item::dir)).
eq(L"parent_id", dir.id).
get_vector();
//iq.WhereParentId(dir.id);
//db->GetItems(item_tab, iq);
for(size_t i=0 ; i<item_tab.size() ; ++i)
CopyFileOrSymlink(item_tab[i], dst_dir_id);
@@ -291,8 +307,8 @@ long Cp::CopyDirTree(const Item & dir, long dst_dir_id)
if( remove_defaults )
{
temp.link_to.clear();
temp.link_redirect = 0;
temp.item_content.link_to.clear();
temp.item_content.link_redirect = 0;
}
cur->request->status = system->dirs.AddDirectory(temp);
+1 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,6 @@ public:
private:
Item temp;
DbItemQuery iq;
bool remove_defaults;
bool preserve_attr;
bool follow_symlinks;
+9 -9
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,18 +58,18 @@ bool Default::HasAccess()
void Default::MakePost()
{
Item & dir = *cur->request->dir_tab.back();
dir.propagate_connector();
dir.link_to = cur->request->PostVar(L"linkto");
dir.link_redirect = cur->request->IsPostVar(L"makeredirect") ? 1 : 0;
TrimWhite(dir.link_to);
dir.item_content.link_to = cur->request->PostVar(L"linkto");
dir.item_content.link_redirect = cur->request->IsPostVar(L"makeredirect") ? 1 : 0;
TrimWhite(dir.item_content.link_to);
// !! dodac sprawdzenie czy link_to jest pusty teraz
// !! IMPROVEME dodac sprawdzenie czy link_to jest pusty teraz
cur->request->status = db->EditLinkItem(dir.id, dir.link_to, dir.link_redirect);
if( cur->request->status == WINIX_ERR_OK )
//cur->request->status = db->EditLinkItem(dir.id, dir.link_to, dir.link_redirect);
if( dir.item_content.update() )
{
log << log2 << "Default: changed link_to: " << dir.link_to << ", for dir_id: " << dir.id << logend;
log << log2 << "Default: changed link_to: " << dir.item_content.link_to << ", for dir_id: " << dir.id << logend;
system->RedirectToLastDir();
}
}
+4 -4
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,8 +63,8 @@ void Download::MakeGet()
if( !system->HasReadAccess(cur->request->item) ||
cur->request->item.file_type == WINIX_ITEM_FILETYPE_NONE ||
cur->request->item.file_path.empty() )
cur->request->item.item_content.file_type == WINIX_ITEM_FILETYPE_NONE ||
cur->request->item.item_content.file_path.empty() )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
@@ -72,7 +72,7 @@ void Download::MakeGet()
cur->request->send_as_attachment = cur->request->IsParam(L"attachment");
if( cur->request->item.has_thumb && cur->request->IsParam(L"thumb") )
if( cur->request->item.item_content.file_has_thumb && cur->request->IsParam(L"thumb") )
system->MakeFilePath(cur->request->item, cur->request->x_sendfile, true);
else
system->MakeFilePath(cur->request->item, cur->request->x_sendfile);
+7 -4
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -149,12 +149,15 @@ void Emacs::MakePost()
{
cur->request->is_item = true; // !! moze lepiej nie ustawiac is_item? (bo jak wystapi blad np dodania do bazy danych
// to formularz edycji zmieni sie z 'dodaj' na 'edytuj'
cur->request->item.privileges = system->NewFilePrivileges();
cur->request->status = system->AddFile(cur->request->item, NotifyCodeAdd());
cur->request->item.item_content.privileges = system->NewFilePrivileges();
cur->request->status = system->AddFile(cur->request->item, NotifyCodeAdd()) ? WINIX_ERR_OK : WINIX_ERR_PERMISSION_DENIED;
}
else
{
cur->request->status = system->EditFile(cur->request->item, cur->request->item.url != old_url, NotifyCodeEdit());
if( system->EditFile(cur->request->item, cur->request->item.url != old_url, NotifyCodeEdit()) )
cur->request->status = WINIX_ERR_OK;
else
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
if( cur->request->status == WINIX_ERR_OK )
+54 -73
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2018, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,7 +47,6 @@ Env::Env()
{
fun.url = L"env";
puser = 0;
req_id = 0;
}
@@ -64,9 +63,6 @@ bool Env::HasAccess()
return false;
}
if( !GetUser() )
return false;
return true;
}
@@ -74,69 +70,60 @@ return true;
bool Env::Parse(const std::wstring & env_str)
{
space.Clear();
conf_parser.SetSpace(space);
return (conf_parser.ParseString(env_str) == PT::SpaceParser::ok);
return (conf_parser.parse_space(env_str, space) == pt::SpaceParser::ok);
}
bool Env::EditAdminEnv(long user_id, const std::wstring & env_str, bool use_ses_log)
bool Env::EditAdminEnv(const std::wstring & env_str, bool use_ses_log)
{
if( Parse(env_str) )
{
if( db->ChangeUserAdminEnv(user_id, space) == WINIX_ERR_OK )
puser->aenv = space;
if( puser->update() )
{
User * puser = system->users.GetUser(user_id);
if( puser )
puser->aenv = space;
return true;
}
else
{
log << log1 << "Evn: a database problem with changing environment variables for user: "
<< cur->session->puser->name << ", id: " << cur->session->puser->id << logend;
log << log1 << "Evn: a database problem with changing admin environment variables for user: "
<< puser->name << ", id: " << puser->id << logend;
}
}
else
{
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
log << log2 << "Env: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend;
}
return false;
}
bool Env::EditEnv(long user_id, const std::wstring & env_str, bool use_ses_log)
bool Env::EditEnv(const std::wstring & env_str, bool use_ses_log)
{
if( Parse(env_str) )
{
if( db->ChangeUserEnv(user_id, space) == WINIX_ERR_OK )
puser->env = space;
if( puser->update() )
{
User * puser = system->users.GetUser(user_id);
if( puser )
puser->env = space;
return true;
}
else
{
log << log1 << "Evn: a database problem with changing admin environment variables for user: "
<< cur->session->puser->name << ", id: " << cur->session->puser->id << logend;
<< puser->name << ", id: " << puser->id << logend;
}
}
else
{
log << log2 << "Env: Syntax error in line: " << conf_parser.line << logend;
log << log2 << "Env: Syntax error in line: " << conf_parser.get_last_parsed_line() << logend;
if( use_ses_log )
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.line << logend;
slog << logerror << T("syntax_error_in_line") << ' ' << conf_parser.get_last_parsed_line() << logend;
}
return false;
@@ -146,67 +133,61 @@ return false;
void Env::SaveEnv()
{
if( GetUser() )
const std::wstring & env_str = cur->request->PostVar(L"envvar");
bool status = false;
if( cur->request->IsParam(L"a") )
{
const std::wstring & env_str = cur->request->PostVar(L"envvar");
long user_id = GetUser()->id;
bool status = false;
if( cur->request->IsParam(L"a") )
{
if( cur->session->puser->super_user )
status = EditAdminEnv(user_id, env_str, true);
}
else
{
status = EditEnv(user_id, env_str, true);
}
if( status )
system->RedirectToLastItem();
if( cur->session->puser->super_user )
status = EditAdminEnv(env_str, true);
}
}
User * Env::GetUser()
{
if( cur->request->id != req_id )
else
{
req_id = cur->request->id;
puser = 0;
if( cur->session->puser )
{
if( cur->session->puser->super_user && cur->request->IsPostVar(L"userid") )
{
long id = Tol(cur->request->PostVar(L"userid"));
puser = system->users.GetUser(id);
}
else
{
puser = cur->session->puser;
}
}
status = EditEnv(env_str, true);
}
return puser;
if( status )
system->RedirectToLastItem();
}
void Env::MakePost()
{
puser = nullptr;
if( cur->session->puser )
{
puser = cur->session->puser;
if( cur->request->IsPostVar(L"changeuser") )
{
// show environments variables for the specified user
if( GetUser() )
log << log2 << "Env: changing user to: " << GetUser()->name << ", id: " << GetUser()->id << logend;
if( puser->super_user && cur->request->IsPostVar(L"userid") )
{
long id = Tol(cur->request->PostVar(L"userid"));
puser = system->users.GetUser(id);
if( puser )
{
log << log2 << "Env: changing user to: " << puser->name << ", id: " << puser->id << logend;
}
}
}
if( puser )
{
/*
* this puser should be set in a new struct (based on Model)
* and put to templates
*
*/
SaveEnv();
}
else
{
// save environment variables
SaveEnv();
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
}
}
}
+6 -10
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,22 +52,18 @@ public:
Env();
bool EditAdminEnv(long user_id, const std::wstring & env_str, bool use_ses_log = false);
bool EditEnv(long user_id, const std::wstring & env_str, bool use_ses_log = false);
bool HasAccess();
void MakePost();
// used mainly by templates
// can return a null pointer
User * GetUser();
private:
PT::SpaceParser conf_parser;
PT::Space space;
pt::SpaceParser conf_parser;
pt::Space space;
User * puser;
size_t req_id;
bool EditAdminEnv(const std::wstring & env_str, bool use_ses_log = false);
bool EditEnv(const std::wstring & env_str, bool use_ses_log = false);
bool Parse(const std::wstring & env_str);
void SaveEnv();
+4 -4
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,9 +47,9 @@ FunctionBase::FunctionBase()
need_ssl = false;
need_session = true;
fun.user_id = -1;
fun.group_id = -1;
fun.privileges = 07555;
fun.item_content.user_id = -1;
fun.item_content.group_id = -1;
fun.item_content.privileges = 07555;
fun.parent_id = -1;
fun.id = -1;
fun.type = Item::file;
+2 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,7 +37,6 @@
#include <string>
#include <vector>
#include "core/item.h"
#include "db/db.h"
#include "core/request.h"
#include "core/config.h"
@@ -45,6 +44,7 @@
#include "core/synchro.h"
#include "notify/notify.h"
#include "core/winixrequest.h"
#include "models/item.h"
+21 -12
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,10 +34,10 @@
#include "functionparser.h"
#include "core/log.h"
#include "core/item.h"
#include "core/error.h"
#include "functions.h"
#include "utf8/utf8.h"
#include "models/item.h"
@@ -141,17 +141,26 @@ bool FunctionParser::CheckAddItem()
{
// cur->request->dir_tab has at least one element
long parent_id = cur->request->dir_tab.back()->id;
Error status = db->GetItem(parent_id, name, cur->request->item);
if( status == WINIX_ERR_OK )
morm::Finder<Item> finder(model_connector);
finder.
select().
where().
eq(L"parent_id", parent_id).
eq(L"url", name).
get(cur->request->item);
//Error status = db->GetItem(parent_id, name, cur->request->item);
//if( status == WINIX_ERR_OK )
if( cur->request->item.found() )
{
log << log3 << "FP: Item: id: " << cur->request->item.id << ", url: " << cur->request->item.url << logend;
cur->request->last_item = &cur->request->item;
cur->request->is_item = true;
return true;
}
if( status == WINIX_ERR_NO_ITEM )
else
{
log << log3 << "FP: No Item: url: " << name << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
@@ -287,7 +296,7 @@ void FunctionParser::ParseAnchor()
while( *path )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, cur->request->anchor);
pt::utf8_to_wide(name_ascii, cur->request->anchor);
if( !cur->request->anchor.empty() )
log << log3 << "FP: anchor: " << cur->request->anchor << logend;
@@ -359,7 +368,7 @@ void FunctionParser::ReadName()
while( *path && *path!='/' && *path!='?' && *path!='#' )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, name);
pt::utf8_to_wide(name_ascii, name);
}
@@ -370,7 +379,7 @@ void FunctionParser::ReadOrdinaryParName()
while( *path && *path!='=' && *path!='&' && *path!='#' )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, name);
pt::utf8_to_wide(name_ascii, name);
}
@@ -384,7 +393,7 @@ void FunctionParser::ReadOrdinaryParValue()
while( *path && *path!='&' && *path!='#' )
value_ascii += GetChar();
PT::UTF8ToWide(value_ascii, value);
pt::utf8_to_wide(value_ascii, value);
}
@@ -395,7 +404,7 @@ void FunctionParser::ReadWinixParName()
while( *path && *path!='/' && *path!=':' && *path!='#' )
name_ascii += GetChar();
PT::UTF8ToWide(name_ascii, name);
pt::utf8_to_wide(name_ascii, name);
}
@@ -409,7 +418,7 @@ void FunctionParser::ReadWinixParValue()
while( *path && *path!='/' && *path!='#' )
value_ascii += GetChar();
PT::UTF8ToWide(value_ascii, value);
pt::utf8_to_wide(value_ascii, value);
}
+25 -23
View File
@@ -168,7 +168,9 @@ Error Functions::CheckSpecialFile(const Item & item)
{
log << log3 << "Functions: reloading mount points" << logend;
system->mounts.ReadMounts(item.content);
cur->mount = system->mounts.GetEmptyMount();
system->mounts.ReadMounts(item.item_content.content_raw);
cur->mount = system->mounts.pmount;
templates->ReadNewIndexTemplates();
templates->ReadNewChangeTemplates();
@@ -300,7 +302,7 @@ void Functions::Parse()
void Functions::SetDefaultFunctionForFile()
{
if( cur->request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
if( cur->request->item.item_content.file_type != WINIX_ITEM_FILETYPE_NONE )
cur->request->function = &fun_download;
else
if( system->HasReadExecAccess(cur->request->item) )
@@ -357,13 +359,13 @@ void Functions::CheckFunctionFollowDir(bool was_default_function)
if( was_default_function )
{
if( cur->request->dir_tab.back()->link_redirect == 1 )
if( cur->request->dir_tab.back()->item_content.link_redirect == 1 )
{
system->RedirectTo(cur->request->dir_tab.back()->link_to);
system->RedirectTo(cur->request->dir_tab.back()->item_content.link_to);
}
else
{
if( system->FollowAllLinks(cur->request->dir_tab.back()->link_to, true, true) )
if( system->FollowAllLinks(cur->request->dir_tab.back()->item_content.link_to, true, true) )
SetDefaultFunction();
}
}
@@ -373,15 +375,15 @@ void Functions::CheckFunctionFollowDir(bool was_default_function)
void Functions::CheckFunctionFollowSymlink(bool was_default_function)
{
if( cur->request->item.link_redirect == 1 )
if( cur->request->item.item_content.link_redirect == 1 )
{
if( was_default_function )
system->RedirectTo(cur->request->item.link_to);
system->RedirectTo(cur->request->item.item_content.link_to);
else
system->RedirectWithFunctionAndParamsTo(cur->request->item.link_to);
system->RedirectWithFunctionAndParamsTo(cur->request->item.item_content.link_to);
}
else
if( system->FollowAllLinks(cur->request->item.link_to, true, true) )
if( system->FollowAllLinks(cur->request->item.item_content.link_to, true, true) )
{
if( was_default_function )
SetDefaultFunction();
@@ -413,7 +415,7 @@ bool was_default_function = false;
if( cur->request->status != WINIX_ERR_OK || !cur->request->redirect_to.empty() )
return;
if( !cur->request->is_item && !cur->request->dir_tab.back()->link_to.empty() )
if( !cur->request->is_item && !cur->request->dir_tab.back()->item_content.link_to.empty() )
CheckFunctionFollowDir(was_default_function);
else
if( cur->request->is_item && cur->request->item.type == Item::symlink && cur->request->function && cur->request->function->follow_symlinks )
@@ -601,7 +603,7 @@ void Functions::ReadItemFilterHtml(Item & item)
html_filter.ClearOrphans();
// SetNoFilterTag doesn't have to be called (default empty tag)
html_filter.Filter(cur->request->PostVar(L"itemcontent"), item.content);
html_filter.Filter(cur->request->PostVar(L"itemcontent"), item.item_content.content_raw);
}
@@ -616,13 +618,13 @@ void Functions::ReadItemContent(Item & item, const std::wstring & content_type)
if( filter_html )
ReadItemFilterHtml(item);
else
cur->request->PostVar(L"itemcontent", item.content);
cur->request->PostVar(L"itemcontent", item.item_content.content_raw);
}
void Functions::ReadItemContentWithType(Item & item)
{
item.content_type = Item::ct_formatted_text; // default is formatted text
item.item_content.content_raw_type = ItemContent::ct_formatted_text; // default is formatted text
cur->request->PostVar(L"contenttype", temp);
ReadItemContent(item, temp);
@@ -631,10 +633,10 @@ void Functions::ReadItemContentWithType(Item & item)
// ct_text and ct_formatted_text can use everyone
if( temp == L"0" )
item.content_type = Item::ct_text;
item.item_content.content_raw_type = ItemContent::ct_text;
else
if( temp == L"1" )
item.content_type = Item::ct_formatted_text;
item.item_content.content_raw_type = ItemContent::ct_formatted_text;
// those below need special privileges
@@ -647,19 +649,19 @@ void Functions::ReadItemContentWithType(Item & item)
if( temp == L"2" )
{
if( system->CanUseHtml(user_id) )
item.content_type = Item::ct_html;
item.item_content.content_raw_type = ItemContent::ct_html;
}
else
if( temp == L"3" )
{
if( system->CanUseBBCode(user_id) )
item.content_type = Item::ct_bbcode;
item.item_content.content_raw_type = ItemContent::ct_bbcode;
}
else
if( temp == L"4" )
{
if( system->CanUseOther(user_id) )
item.content_type = Item::ct_other;
item.item_content.content_raw_type = ItemContent::ct_other;
}
}
@@ -689,16 +691,16 @@ void Functions::SetUser(Item & item)
{
if( cur->session && cur->session->puser )
{
item.user_id = cur->session->puser->id;
item.guest_name.clear();
item.item_content.user_id = cur->session->puser->id;
item.item_content.guest_name.clear();
}
else
{
item.user_id = -1;
cur->request->PostVar(L"guestname", item.guest_name);
item.item_content.user_id = -1;
cur->request->PostVar(L"guestname", item.item_content.guest_name);
}
item.group_id = cur->request->dir_tab.back()->group_id;
item.item_content.group_id = cur->request->dir_tab.back()->item_content.group_id;
}
+18 -7
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2013-2014, Tomasz Sowa
* Copyright (c) 2013-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,15 +61,26 @@ bool ImgCrop::HasAccess()
}
void ImgCrop::GetDirContent()
{
iq.sel_type = Item::file;
iq.sel_content = false;
// iq.sel_type = Item::file;
// iq.sel_content = false;
//
// iq.WhereParentId(cur->request->dir_tab.back()->id);
// iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
iq.WhereParentId(cur->request->dir_tab.back()->id);
iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
morm::Finder<Item> finder(model_connector);
db->GetItems(cur->request->item_tab, iq);
cur->request->item_tab = finder.
select().
where().
eq(L"type", static_cast<int>(Item::file)).
eq(L"parent_id", cur->request->dir_tab.back()->id).
eq(L"content", L"file_type", WINIX_ITEM_FILETYPE_IMAGE).
get_vector();
//db->GetItems(cur->request->item_tab, iq);
system->CheckWriteAccessToItems(cur->request->item_tab);
}
@@ -89,7 +100,7 @@ void ImgCrop::MakePost()
Item & item = cur->request->item;
if( cur->request->is_item && item.type == Item::file && item.file_type == WINIX_ITEM_FILETYPE_IMAGE )
if( cur->request->is_item && item.type == Item::file && item.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
{
if( system->HasWriteAccess(item) )
{
+2 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2013-2014, Tomasz Sowa
* Copyright (c) 2013-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@ public:
private:
DbItemQuery iq;
//DbItemQuery iq;
void GetDirContent();
+2 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -89,7 +89,7 @@ size_t tmp_ip_len = sizeof(tmp_ip_str) / sizeof(char);
if( cur->session->ip_ban )
cur_ip = cur->session->ip_ban->ip;
if( WideToUTF8(cur->request->ParamValue(L"removeip"), tmp_ip_str, tmp_ip_len) )
if( wide_to_utf8(cur->request->ParamValue(L"removeip"), tmp_ip_str, tmp_ip_len) )
{
int ip = (int)inet_addr(tmp_ip_str);
session_manager->RemoveIPBan(ip);
+12 -6
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,17 +62,19 @@ bool Ln::HasAccess()
bool Ln::CreateSymbolicLink(long parent_id, const wchar_t * link_to, const wchar_t * url, bool link_redirect)
{
item.set_connector(model_connector);
item.Clear(); // setting the date to now
item.type = Item::symlink;
item.parent_id = parent_id;
item.url = url;
item.link_to = link_to;
item.link_redirect = static_cast<int>(link_redirect);
item.privileges = system->NewFilePrivileges();
item.item_content.link_to = link_to;
item.item_content.link_redirect = static_cast<int>(link_redirect);
item.item_content.privileges = system->NewFilePrivileges();
functions->SetUser(item);
functions->PrepareUrl(item);
return db->AddItem(item) == WINIX_ERR_OK;
return item.insert();
//return db->AddItem(item) == WINIX_ERR_OK;
}
@@ -124,7 +126,11 @@ bool Ln::CreateHardLink(const std::vector<Item*> & dirs, const std::wstring & li
item.url = url;
functions->PrepareUrl(item);
return db->AddHardLink(item) == WINIX_ERR_OK;
/*
* IMPROVEME
*
*/
//return db->AddHardLink(item) == WINIX_ERR_OK;
}
return false;
+2 -2
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* Copyright (c) 2012-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,7 @@ void Locale::MakePost()
if( TemplatesFunctions::locale.HasLanguage(locale_id) )
{
cur->session->puser->locale_id = locale_id;
db->ChangeUserLocale(cur->session->puser->id, locale_id);
cur->session->puser->update();
TemplatesFunctions::locale.SetCurLang(locale_id);
}
else
+30 -21
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,22 +55,21 @@ Login::Login()
void Login::ClearTmpStruct()
{
system->crypt.ClearString(pass_decrypted);
system->crypt.ClearString(pass_hashed);
system->crypt.ClearString(up.pass);
system->crypt.ClearString(up.pass_encrypted);
system->crypt.ClearString(up2.pass);
system->crypt.ClearString(up2.pass_encrypted);
// system->crypt.ClearString(up.pass);
// system->crypt.ClearString(up.pass_encrypted);
// system->crypt.ClearString(up2.pass);
// system->crypt.ClearString(up2.pass_encrypted);
}
bool Login::CheckPasswords(const std::wstring & password)
bool Login::CheckPasswords(User & user, const std::wstring & password)
{
if( !up.pass_encrypted.empty() )
if( !user.pass_encrypted.empty() )
{
if( system->crypt.RSA(false, config->pass_rsa_private_key, up.pass_encrypted, pass_decrypted) )
if( system->crypt.RSA(false, config->pass_rsa_private_key, user.pass_encrypted, pass_decrypted) )
{
PT::UTF8ToWide(pass_decrypted, up.pass);
pt::utf8_to_wide(pass_decrypted, user.password);
}
else
{
@@ -79,22 +78,22 @@ bool Login::CheckPasswords(const std::wstring & password)
}
}
pass_hashed = password;
up2.pass_type = up.pass_type;
up2.pass = password;
std::wstring password_from_db = user.password;
user.password = password;
if( up.pass_hash_salted )
if( user.pass_hash_salted )
salt = config->pass_hash_salt;
else
salt.clear();
if( !system->crypt.PassHash(salt, up2) )
if( !system->crypt.PassHash(salt, user) )
{
log << log1 << "Login: I cannot hash a password, login failure" << logend;
return false;
}
bool result = (up.pass == up2.pass);
// compare char by char until the end of the strings (time attacks)
bool result = (user.password == password_from_db);
if( !result )
log << log2 << "Login: incorrect login/password" << logend;
@@ -114,15 +113,25 @@ bool Login::CheckUserPass(const std::wstring & login, const std::wstring & passw
{
bool result;
if( db->GetUserPass(login, user_id, up) )
morm::Finder<User> finder(model_connector);
User user = finder.
select().
where().
eq(L"login", login).
get();
if( user.found() )
{
if( up.has_pass )
user_id = user.id;
if( user.has_pass )
{
result = CheckPasswords(password);
result = CheckPasswords(user, password);
}
else
{
log << log2 << "Login: this account has not a password set yet" << logend;
log << log2 << "Login: this account has no a password set yet" << logend;
result = false;
}
}
@@ -164,7 +173,7 @@ void Login::CheckBan()
if( ip_ban->expires < expires )
ip_ban->expires = expires;
PT::Date date(ip_ban->expires);
pt::Date date(ip_ban->expires);
log << log2 << "Login: logging from this IP address has been blocked until to: " << date << " UTC" << logend;
}
else

Some files were not shown because too many files have changed in this diff Show More