From ec94dff7d7d2f0e5a97ccd5c1705670b8db0cd6b Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 18 Jun 2021 19:18:13 +0200 Subject: [PATCH] some ezc functions from templates/item.cpp moved to Item and ItemContent methods HasAccess() HasReadAccess() and similar moved from System to Item and ItemContent --- winixd/core/app.cpp | 18 +- winixd/core/dircontainer.cpp | 15 +- winixd/core/dircontainer.h | 6 +- winixd/core/dirs.cpp | 15 +- winixd/core/dirs.h | 2 + winixd/core/plugin.h | 2 +- winixd/core/request.cpp | 12 +- winixd/core/request.h | 13 +- winixd/core/session.h | 3 +- winixd/core/system.cpp | 54 +-- winixd/core/system.h | 1 - winixd/core/textstream.h | 8 +- winixd/core/threadmanager.cpp | 1 + winixd/functions/cat.cpp | 5 + winixd/functions/ls.cpp | 14 +- winixd/html/fun_ls.html | 29 +- winixd/models/item.cpp | 522 ++++++++++++++++---------- winixd/models/item.h | 34 +- winixd/models/itemcontent.cpp | 341 ++++++++++++++--- winixd/models/itemcontent.h | 69 +++- winixd/models/user.cpp | 6 +- winixd/models/user.h | 2 +- winixd/models/winixmodel.cpp | 169 +++++++++ winixd/models/winixmodel.h | 17 + winixd/models/winixmodelconnector.cpp | 70 ++++ winixd/models/winixmodelconnector.h | 14 + winixd/notify/notify.h | 2 +- winixd/templates/item.cpp | 255 ++++++------- winixd/templates/misc.cpp | 1 + winixd/templates/misc.h | 5 +- winixd/templates/templates.cpp | 46 +-- winixd/templates/templates.h | 48 +-- 32 files changed, 1255 insertions(+), 544 deletions(-) diff --git a/winixd/core/app.cpp b/winixd/core/app.cpp index 0c1fe9e..76e5a44 100644 --- a/winixd/core/app.cpp +++ b/winixd/core/app.cpp @@ -118,6 +118,9 @@ App::App() plugin.SetWinixRequest(&winix_request); req.SetConfig(&config); + req.set_connector(&model_connector); + + functions.set_dependency(&winix_request); // functions.set_config(&config); @@ -337,6 +340,7 @@ bool App::Init() model_connector.set_winix_users(&system.users); model_connector.set_winix_groups(&system.groups); model_connector.set_winix_session_logger(nullptr); // will be set for each request + model_connector.set_winix_session(nullptr); // will be set for each request if( !TryToMakeDatabaseMigration() ) return false; @@ -564,8 +568,13 @@ void App::ProcessRequestThrow() cur.mount = system.mounts.CalcCurMount(); cur.session = session_manager.PrepareSession(); + model_connector.set_winix_session(cur.session); + functions.CheckFunctionAndSymlink(); // here a function can be changed + cur.session = session_manager.CheckIfFunctionRequireSession(); + model_connector.set_winix_session(cur.session); + SetLocale(); if( cur.session->new_session ) @@ -624,6 +633,9 @@ void App::ProcessRequest() { try { + cur.request->set_connector(model_connector); + model_connector.set_winix_request(cur.request); + cur.request->RequestStarts(); system.load_avg.StartRequest(); log << log2 << config.log_delimiter << logend; @@ -680,7 +692,11 @@ 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); + model_connector.set_winix_request(nullptr); + model_connector.set_winix_session(nullptr); + model_connector.set_winix_session_logger(nullptr); + + cur.request->item.set_connector(nullptr); // it is needed? log << logendrequest; } diff --git a/winixd/core/dircontainer.cpp b/winixd/core/dircontainer.cpp index 76b2ab2..8290a22 100644 --- a/winixd/core/dircontainer.cpp +++ b/winixd/core/dircontainer.cpp @@ -81,13 +81,13 @@ return var_iter; } -DirContainer::Iterator DirContainer::Begin() +DirContainer::ConstIterator DirContainer::Begin() const { return table.begin(); } -DirContainer::Iterator DirContainer::End() +DirContainer::ConstIterator DirContainer::End() const { return table.end(); } @@ -255,6 +255,17 @@ return i->second; } +DirContainer::ConstIterator DirContainer::FindId(long id) const +{ + TableId::const_iterator i = table_id.find(id); + + if( i == table_id.end() ) + return table.end(); + +return i->second; +} + + DirContainer::ParentIterator DirContainer::ParentBegin() { diff --git a/winixd/core/dircontainer.h b/winixd/core/dircontainer.h index b1dcfe0..cb254c6 100644 --- a/winixd/core/dircontainer.h +++ b/winixd/core/dircontainer.h @@ -52,6 +52,7 @@ class DirContainer : public WinixBase public: typedef std::list Table; typedef Table::iterator Iterator; + typedef Table::const_iterator ConstIterator; typedef Table::size_type SizeType; typedef std::map TableId; @@ -66,8 +67,8 @@ public: Iterator GetEtc(); Iterator GetVar(); - Iterator Begin(); - Iterator End(); + ConstIterator Begin() const; + ConstIterator End() const; SizeType Size(); bool Empty(); Iterator PushBack(const Item & item); @@ -75,6 +76,7 @@ public: void Clear(); Iterator FindId(long id); + ConstIterator FindId(long id) const; bool DelById(long id); diff --git a/winixd/core/dirs.cpp b/winixd/core/dirs.cpp index 8ae26d6..2823693 100644 --- a/winixd/core/dirs.cpp +++ b/winixd/core/dirs.cpp @@ -456,9 +456,20 @@ Item * Dirs::GetDir(long id) DirContainer::Iterator i = dir_tab.FindId(id); if( i == dir_tab.End() ) - return 0; + return nullptr; -return &(*i); + return &(*i); +} + + +const Item * Dirs::GetDir(long id) const +{ + DirContainer::ConstIterator i = dir_tab.FindId(id); + + if( i == dir_tab.End() ) + return nullptr; + + return &(*i); } diff --git a/winixd/core/dirs.h b/winixd/core/dirs.h index 9ab6ded..909321d 100644 --- a/winixd/core/dirs.h +++ b/winixd/core/dirs.h @@ -109,6 +109,8 @@ public: Item * GetDir(long id); Item * AddDir(const Item & item); + const Item * GetDir(long id) const; + void CheckRootDir(); Item * CreateVarDir(); diff --git a/winixd/core/plugin.h b/winixd/core/plugin.h index 1a1fdef..21c7d7b 100644 --- a/winixd/core/plugin.h +++ b/winixd/core/plugin.h @@ -77,7 +77,7 @@ class WinixRequest; class Plugin; -struct Session; +class Session; // move me to a different file diff --git a/winixd/core/request.cpp b/winixd/core/request.cpp index dcaf44e..d5df691 100644 --- a/winixd/core/request.cpp +++ b/winixd/core/request.cpp @@ -55,7 +55,10 @@ Request::Request() void Request::fields() { - field(L"", L"dirs", dir_tab); + field(L"dirs", dir_tab); + field(L"is_item", is_item); + + field(L"current_dir", &Request::current_dir); } @@ -362,6 +365,13 @@ const std::wstring & Request::ParamValue(const std::wstring & param_name) +void Request::current_dir(morm::ModelWrapper ** model_wrapper) +{ + *model_wrapper = new morm::ModelWrapperModel(dir_tab.back()); +} + + + } // namespace Winix diff --git a/winixd/core/request.h b/winixd/core/request.h index add2749..aa33f30 100644 --- a/winixd/core/request.h +++ b/winixd/core/request.h @@ -64,8 +64,11 @@ class FunctionBase; -struct Request : public WinixModel +class Request : public WinixModel { +public: + + // how many input headers can be put to in_headers struct static const size_t MAX_INPUT_HEADERS = 32; @@ -413,6 +416,12 @@ private: void ClearOutputStreams(); + + void current_dir(morm::ModelWrapper ** model_wrapper); + + + MORM_MEMBER_FIELD(Request) + }; @@ -456,6 +465,8 @@ void Request::AddCookie(const NameType & name, const ValueType & value, pt::Date + + } // namespace Winix #endif diff --git a/winixd/core/session.h b/winixd/core/session.h index 7678e96..c6c5ea5 100644 --- a/winixd/core/session.h +++ b/winixd/core/session.h @@ -53,8 +53,9 @@ namespace Winix -struct Session +class Session { +public: Session(); Session(const Session & ses); diff --git a/winixd/core/system.cpp b/winixd/core/system.cpp index b993d88..e1abb67 100644 --- a/winixd/core/system.cpp +++ b/winixd/core/system.cpp @@ -606,69 +606,31 @@ return true; } -// private -bool System::HasAccess(const Item & item, int mask) -{ - if( !cur->session ) - // session must be set - return false; - - if( cur->session->puser && cur->session->puser->super_user ) - // super user is allowed everything - return true; - - if( cur->session->puser && item.item_content.user_id != -1 && cur->session->puser->id == item.item_content.user_id ) - { - // the owner - return ((item.item_content.privileges >> 9) & mask) == mask; - } - - if( cur->session->puser && item.item_content.group_id != -1 && cur->session->puser->IsMemberOf(item.item_content.group_id) ) - { - // group - return ((item.item_content.privileges >> 6) & mask) == mask; - } - - if( cur->session->puser ) - { - // others -- others logged people - return ((item.item_content.privileges >> 3) & mask) == mask; - } - - // guests -- not logged people - -return (item.item_content.privileges & mask) == mask; -} - - +// DEPRACATED bool System::HasReadAccess(const Item & item) { - return HasAccess(item, 4); + return item.item_content.has_read_access(); } +// DEPRACATED bool System::HasWriteAccess(const Item & item) { - return HasAccess(item, 2); + return item.item_content.has_write_access(); } +// DEPRACATED bool System::HasReadWriteAccess(const Item & item) { - return HasAccess(item, 6); // r+w + return item.item_content.has_read_write_access(); } +// DEPRACATED bool System::HasReadExecAccess(const Item & item) { - if( cur->session && cur->session->puser && cur->session->puser->super_user ) - { - // there must be at least one 'x' (for the root) - // !! CHECK ME: is it applicable to directories too? - return (item.item_content.privileges & 01111) != 0; - } - - return HasAccess(item, 5); // r+x + return item.item_content.has_read_exec_access(); } diff --git a/winixd/core/system.h b/winixd/core/system.h index 81dcb36..b293c43 100644 --- a/winixd/core/system.h +++ b/winixd/core/system.h @@ -239,7 +239,6 @@ private: std::vector root_follow_dir_tab; Item temp_follow_item; - bool HasAccess(const Item & item, int mask); int NewPrivileges(int creation_mask); bool CreateNewFileSimpleFs(Item & item); diff --git a/winixd/core/textstream.h b/winixd/core/textstream.h index 67cf4cb..19be74a 100644 --- a/winixd/core/textstream.h +++ b/winixd/core/textstream.h @@ -183,25 +183,25 @@ void TextStream::Reserve(size_t len) template -TextStream::iterator TextStream::begin() +typename TextStream::iterator TextStream::begin() { return buffer.begin(); } template -TextStream::iterator TextStream::end() +typename TextStream::iterator TextStream::end() { return buffer.end(); } template -TextStream::const_iterator TextStream::begin() const +typename TextStream::const_iterator TextStream::begin() const { return buffer.begin(); } template -TextStream::const_iterator TextStream::end() const +typename TextStream::const_iterator TextStream::end() const { return buffer.end(); } diff --git a/winixd/core/threadmanager.cpp b/winixd/core/threadmanager.cpp index fbf42a4..abecc78 100644 --- a/winixd/core/threadmanager.cpp +++ b/winixd/core/threadmanager.cpp @@ -104,6 +104,7 @@ void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name) data.model_connector.set_winix_users(nullptr); data.model_connector.set_winix_groups(nullptr); data.model_connector.set_winix_session_logger(nullptr); + data.model_connector.set_winix_session(nullptr); diff --git a/winixd/functions/cat.cpp b/winixd/functions/cat.cpp index 2d7252b..ab45377 100644 --- a/winixd/functions/cat.cpp +++ b/winixd/functions/cat.cpp @@ -67,7 +67,12 @@ void Cat::MakeGet() } cur->request->send_as_attachment = cur->request->IsParam(L"attachment"); + + + // IMPROVEME this will be put by a generic method from winix + // if output is html cur->request->models.Add(L"item", cur->request->item); + //////////////////////////////////////////////////////////// } diff --git a/winixd/functions/ls.cpp b/winixd/functions/ls.cpp index 1fb6fab..bc76e5e 100644 --- a/winixd/functions/ls.cpp +++ b/winixd/functions/ls.cpp @@ -101,11 +101,17 @@ void Ls::MakeGet() cur->request->models.Add(L"items", item_tab); cur->request->models.Add(L"child_dirs", dir_tab); - - // IMPROVEME this will be put by a generic method from winix - // if output is html - cur->request->models.Add(L"request", cur->request); } + + // IMPROVEME this will be put by a generic method from winix + // if output is html + cur->request->models.Add(L"request", cur->request); + + if( cur->request->is_item ) + { + cur->request->models.Add(L"item", cur->request->item); + } + //////////////////////////////////////////////////////////// } diff --git a/winixd/html/fun_ls.html b/winixd/html/fun_ls.html index dd362e4..2f28e35 100644 --- a/winixd/html/fun_ls.html +++ b/winixd/html/fun_ls.html @@ -1,5 +1,8 @@
+[# we can add a winix function called 'image_browser' or similar] +[# such a function can be used for ckeditor and for ordinary browsing] + [# !! IMPROVE ME: move this html code to a ckeditor template] [if winix_function_param_is "ckeditor_browse"] @@ -9,9 +12,9 @@
-
+
[# workaround: margin from first item from child_dirs overflows here] [if child_dirs]
    @@ -65,7 +68,7 @@

    {ls_header}

    [# !! improve me: we need a 'l' flag to a file too, now it's working for dirs only] - [if not item_is] + [if not request.is_item] [if winix_function_param_is "l"] @@ -83,9 +86,9 @@ [for child_dirs] d - [child_dirs_privileges] - [child_dirs_user] - [child_dirs_group] + [child_dirs.content.privileges_octal] + [child_dirs.content.user_name] + [child_dirs.content.group_name] [if child_dirs.is_parent_for_current_dir]
    ../ @@ -98,11 +101,11 @@ [for items] - [if items_type_is_symlink]l[else][if items_has_static_file]s[else]-[end][end] - [items_privileges] - [items_user] - [items_group] - [items.url][if items_type_is_symlink] -> [items_link_to][end] + [if items.type_is_symlink]l[else][if items.has_static_file]s[else]-[end][end] + [items.content.privileges_octal] + [items.content.user_name] + [items.content.group_name] + [items.url][if items.type_is_symlink] -> [items.content.link_to][end] [end] diff --git a/winixd/models/item.cpp b/winixd/models/item.cpp index c2f9926..625930d 100644 --- a/winixd/models/item.cpp +++ b/winixd/models/item.cpp @@ -37,6 +37,8 @@ #include "finder.h" #include "core/request.h" #include "templates/templates.h" +#include "core/session.h" + namespace Winix @@ -58,21 +60,32 @@ void Item::fields() int type_helper = static_cast(type); - field(L"id", id, morm::FT::no_insertable | morm::FT::no_updatable | morm::FT::primary_key); - field(L"parent_id", parent_id); - field(L"type", type_helper); - field(L"url", url); - field(L"subject", subject); - field(L"template", html_template); - field(L"sort_index", sort_index); + field(L"id", id, morm::FT::no_insertable | morm::FT::no_updatable | morm::FT::primary_key); + field(L"parent_id", parent_id); + field(L"type", type_helper); + field(L"url", url); + field(L"subject", subject); + field(L"template", html_template); + field(L"sort_index", sort_index); field(L"content_id", L"content", item_content, morm::FT::foreign_key); - field(L"is", &Item::is); - field(L"dir_link", &Item::dir_link); - field(L"link", &Item::link); + field(L"dir_link", &Item::dir_link); + field(L"link", &Item::link); field(L"is_parent_for_current_dir", &Item::is_parent_for_current_dir); - field(L"is_current_dir", &Item::is_current_dir); - field(L"is_root", &Item::is_root); + field(L"is_current_dir", &Item::is_current_dir); + field(L"is_root_dir", &Item::is_root_dir); + + field(L"type_is_symlink", &Item::type_is_symlink); + field(L"type_is_file", &Item::type_is_file); + field(L"type_is_dir", &Item::type_is_dir); + field(L"type_is_none", &Item::type_is_none); + + field(L"url_is", &Item::url_is); + + field(L"can_be_removed", &Item::can_be_removed); + field(L"has_read_access", &Item::has_read_access); + field(L"has_write_access", &Item::has_write_access); + // may we should add a method setTypeFromInt(int t)? @@ -156,8 +169,6 @@ bool Item::update(morm::ModelData * model_data, bool update_whole_tree) } - - void Item::Clear() { id = -1; @@ -171,199 +182,6 @@ void Item::Clear() } -CalcItemsHelper Item::calc_items_by_url(long parent_id, const std::wstring & url) -{ - morm::Finder finder(model_connector); - - CalcItemsHelper helper = finder. - prepare_to_select(). - raw("select count(id) as size, min(id) as item_id from core.item"). - where(). - eq(L"parent_id", parent_id). - eq(L"url", url). - get(); - - return helper; -} - - -/* - * may we should check for '.' and '..' here too? - */ -bool Item::prepare_url() -{ -std::wstring temp_url; -bool is_that_url; -const int max_index = 99; -size_t index = 1; -std::wstring postfix; - - // only root dir may not have the url - if( parent_id != -1 && url.empty() ) - url = L"_"; - - do - { - if( index > 1 ) - { - postfix = L"_("; - pt::Toa(index, postfix, false); - postfix += L")"; - } - - PrepareNewFileName(url, postfix, temp_url); - - CalcItemsHelper helper = calc_items_by_url(parent_id, temp_url); - - if( helper.size > 0 ) - { - is_that_url = true; - } - else - { - url = temp_url; - is_that_url = false; - } - - index += 1; - } - while( is_that_url && index <= max_index ); - -return !is_that_url; -} - - - -void Item::propagate_connector() -{ - item_content.set_connector(model_connector); -} - - -// IMPROVEME move me to a better place -void Item::print_dir(Ezc::FunInfo & env) -{ - Request * req = get_request(); - - if( req ) - { - for(size_t a=0 ; a < req->dir_tab.size() ; ++a) - env.out << req->dir_tab[a]->url << '/'; - } -} - - -// IMPROVEME move me to a better place -void Item::print_dir_without_slash(Ezc::FunInfo & env) -{ - Request * req = get_request(); - - if( req ) - { - for(size_t a=0 ; a < req->dir_tab.size() ; ++a) - { - env.out << req->dir_tab[a]->url; - - if( a < req->dir_tab.size()-1 ) - env.out << '/'; - } - } -} - - - - - -void Item::is(Ezc::FunInfo & env) -{ - Request * req = get_request(); - - if( req ) - { - env.res = req->is_item; - } -} - - -void Item::dir_link(Ezc::FunInfo & env) -{ - Dirs * dirs = get_dirs(); - std::vector dir_tab; - - if( dirs && dirs->CreateDirTab(parent_id, dir_tab) ) - { - for(Item * pitem : dir_tab) - { - env.out << pitem->url << '/'; - } - } -} - - -void Item::link(Ezc::FunInfo & env) -{ - Config * config = get_config(); - Request * req = get_request(); - - if( config && req ) - { - TemplatesFunctions::doc_proto(env); - - if( !req->subdomain.empty() ) - env.out << req->subdomain << '.'; - - env.out << config->base_url; - - if( parent_id == req->dir_tab.back()->id ) - { - print_dir(env); - } - else - { - dir_link(env); - } - - env.out << url; - } -} - - -void Item::is_parent_for_current_dir(Ezc::FunInfo & env) -{ - Request * req = get_request(); - - if( req ) - { - if( req->dir_tab.size() > 1 ) - { - env.res = (id == req->dir_tab[req->dir_tab.size() - 2]->id); - } - } -} - - -void Item::is_current_dir(Ezc::FunInfo & env) -{ - Request * req = get_request(); - - if( req ) - { - env.res = (id == req->dir_tab.back()->id); - } -} - -// rename to is_root_dir -void Item::is_root(Ezc::FunInfo & env) -{ - Request * req = get_request(); - - if( req ) - { - // add a test whether this is a directory (not a file or a symlink) - env.res = (parent_id == -1); - } -} - @@ -499,5 +317,295 @@ bool Item::do_migration_to_4() +bool Item::can_remove_child(const User * current_user, long child_user_id) const +{ + bool res = false; + + if( type == Type::dir ) + { + if( current_user && current_user->super_user ) + { + res = true; + } + else + { + res = item_content.has_write_access(current_user); + + if( res && item_content.is_sticky_bit_set() ) + { + // IMPROVEME what about if child_user_id is -1 (guest) + res = (item_content.user_id == child_user_id); + } + } + } + + return res; +} + + +bool Item::can_be_removed(const User * current_user) const +{ + bool res = false; + const Dirs * dirs = get_dirs(); + + if( dirs && parent_id != -1 ) + { + const Item * parent_dir = dirs->GetDir(parent_id); + + if( parent_dir ) + { + res = parent_dir->can_remove_child(current_user, id); + } + } + + return res; +} + + +bool Item::can_remove_child(long child_user_id) const +{ + return can_remove_child(get_current_user(), child_user_id); +} + + +bool Item::can_be_removed() const +{ + return can_be_removed(get_current_user()); +} + + +bool Item::has_read_access() +{ + return item_content.has_read_access(); +} + + +bool Item::has_write_access() +{ + return item_content.has_write_access(); +} + + +bool Item::type_is_symlink() const +{ + return (type == Type::symlink); +} + + +bool Item::type_is_file() const +{ + return (type == Type::file); +} + + +bool Item::type_is_dir() const +{ + return (type == Type::dir); +} + + +bool Item::type_is_none() const +{ + return (type == Type::none); +} + + +bool Item::is_root_dir() const +{ + return (type == Type::dir && parent_id == -1); +} + + + + + + +CalcItemsHelper Item::calc_items_by_url(long parent_id, const std::wstring & url) +{ + morm::Finder finder(model_connector); + + CalcItemsHelper helper = finder. + prepare_to_select(). + raw("select count(id) as size, min(id) as item_id from core.item"). + where(). + eq(L"parent_id", parent_id). + eq(L"url", url). + get(); + + return helper; +} + + +/* + * may we should check for '.' and '..' here too? + */ +bool Item::prepare_url() +{ +std::wstring temp_url; +bool is_that_url; +const int max_index = 99; +size_t index = 1; +std::wstring postfix; + + // only root dir may not have the url + if( parent_id != -1 && url.empty() ) + url = L"_"; + + do + { + if( index > 1 ) + { + postfix = L"_("; + pt::Toa(index, postfix, false); + postfix += L")"; + } + + PrepareNewFileName(url, postfix, temp_url); + + CalcItemsHelper helper = calc_items_by_url(parent_id, temp_url); + + if( helper.size > 0 ) + { + is_that_url = true; + } + else + { + url = temp_url; + is_that_url = false; + } + + index += 1; + } + while( is_that_url && index <= max_index ); + +return !is_that_url; +} + + + +void Item::propagate_connector() +{ + item_content.set_connector(model_connector); +} + + +// IMPROVEME move me to a better place +void Item::print_dir(EzcEnv & env) +{ + Request * req = get_request(); + + if( req ) + { + for(size_t a=0 ; a < req->dir_tab.size() ; ++a) + env.out << req->dir_tab[a]->url << '/'; + } +} + + +// IMPROVEME move me to a better place +void Item::print_dir_without_slash(EzcEnv & env) +{ + Request * req = get_request(); + + if( req ) + { + for(size_t a=0 ; a < req->dir_tab.size() ; ++a) + { + env.out << req->dir_tab[a]->url; + + if( a < req->dir_tab.size()-1 ) + env.out << '/'; + } + } +} + + + + + +void Item::dir_link(EzcEnv & env) +{ + Dirs * dirs = get_dirs(); + std::vector dir_tab; + + if( dirs && dirs->CreateDirTab(parent_id, dir_tab) ) + { + for(Item * pitem : dir_tab) + { + env.out << pitem->url << '/'; + } + } +} + + +void Item::link(EzcEnv & env) +{ + Config * config = get_config(); + Request * req = get_request(); + + if( config && req ) + { + TemplatesFunctions::doc_proto(env); + + if( !req->subdomain.empty() ) + env.out << req->subdomain << '.'; + + env.out << config->base_url; + + if( parent_id == req->dir_tab.back()->id ) + { + print_dir(env); + } + else + { + dir_link(env); + } + + env.out << url; + } +} + + +bool Item::is_parent_for_current_dir() const +{ + bool res = false; + const Request * req = get_request(); + + if( req ) + { + if( req->dir_tab.size() > 1 ) + { + res = (id == req->dir_tab[req->dir_tab.size() - 2]->id); + } + } + + return res; +} + + +bool Item::is_current_dir() const +{ + bool res = false; + const Request * req = get_request(); + + if( req ) + { + res = (id == req->dir_tab.back()->id); + } + + return res; +} + + + + +void Item::url_is(EzcEnv & env) +{ + env.res = (url == env.par); +} + + + + } // namespace Winix diff --git a/winixd/models/item.h b/winixd/models/item.h index 9c19cb1..d7f9213 100644 --- a/winixd/models/item.h +++ b/winixd/models/item.h @@ -46,6 +46,7 @@ #include "funinfo.h" #include "templates/htmltextstream.h" +#include "templates/misc.h" @@ -183,16 +184,23 @@ public: void propagate_connector(); + bool can_remove_child(const User * current_user, long child_user_id) const; + bool can_be_removed(const User * current_user) const; + bool can_remove_child(long child_user_id) const; + bool can_be_removed() const; - void print_dir(Ezc::FunInfo & env); - void print_dir_without_slash(Ezc::FunInfo & env); + bool has_read_access(); + bool has_write_access(); + + bool type_is_symlink() const; + bool type_is_file() const; + bool type_is_dir() const; + bool type_is_none() const; + + bool is_root_dir() const; + bool is_parent_for_current_dir() const; + bool is_current_dir() const; - void is(Ezc::FunInfo & env); - void dir_link(Ezc::FunInfo & env); - void link(Ezc::FunInfo & env); - void is_parent_for_current_dir(Ezc::FunInfo & env); - void is_current_dir(Ezc::FunInfo & env); - void is_root(Ezc::FunInfo & env); protected: @@ -204,7 +212,17 @@ protected: bool do_migration_to_3(); bool do_migration_to_4(); + void print_dir(EzcEnv & env); + void print_dir_without_slash(EzcEnv & env); + void dir_link(EzcEnv & env); + void link(EzcEnv & env); + + void url_is(EzcEnv & env); + + + MORM_MEMBER_FIELD(Item) + }; diff --git a/winixd/models/itemcontent.cpp b/winixd/models/itemcontent.cpp index 5a5e6a4..114571c 100644 --- a/winixd/models/itemcontent.cpp +++ b/winixd/models/itemcontent.cpp @@ -37,6 +37,9 @@ #include "core/misc.h" #include "templates/misc.h" #include "core/bbcodeparser.h" +#include "core/request.h" +#include "core/users.h" +#include "core/groups.h" namespace Winix @@ -83,7 +86,23 @@ void ItemContent::fields() field(L"meta_admin", meta_admin); field(L"print_content", &ItemContent::print_content); + field(L"has_static_file", &ItemContent::has_static_file); + field(L"privileges_octal", &ItemContent::privileges_octal); + field(L"user_name", &ItemContent::user_name); + field(L"group_name", &ItemContent::group_name); + field(L"type_is", &ItemContent::type_is); + field(L"is_empty", &ItemContent::is_empty); + field(L"file_type_is_none", &ItemContent::file_type_is_none); + field(L"file_type_is_image", &ItemContent::file_type_is_image); + field(L"file_type_is_video", &ItemContent::file_type_is_video); + field(L"file_type_is_sound", &ItemContent::file_type_is_sound); + + field(L"has_thumb", &ItemContent::has_thumb); + + + + // IMPROVEME prepare a setter functions which tests whether content_raw_type_helper and content_parsed_type_helper are correct values content_raw_type = static_cast(content_raw_type_helper); content_parsed_type = static_cast(content_parsed_type_helper); } @@ -153,66 +172,6 @@ void ItemContent::Clear() } -/* - * we're using the HtmlFilter only for those contents - * - */ -bool ItemContent::CanContentBeHtmlFiltered(ItemContent::ContentType ct) -{ - return ct == ct_text || ct == ct_formatted_text || ct == ct_html || ct == ct_bbcode; -} - -bool ItemContent::CanContentBeHtmlFiltered() -{ - return CanContentBeHtmlFiltered(content_raw_type); -} - - - - -void ItemContent::print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on) -{ - using TemplatesFunctions::R; - - if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) ) - out << R(""); - - if( content_type == ItemContent::ct_text ) - { - out << content; - } - else - if( content_type == ItemContent::ct_formatted_text ) - { - TemplatesFunctions::HtmlEscapeFormTxt(out, content); - } - else - if( content_type == ItemContent::ct_bbcode ) - { - static std::wstring out_temp; - out_temp.clear(); - out_temp.reserve(content.size()*2); - - BBCODEParser bbcode_parser; // IMPROVE ME move me to a better place - bbcode_parser.Filter(content.c_str(), out_temp); - out << R(out_temp); - } - else - { - // ct_html, ct_other - out << R(content); - } - - if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) ) - out << R(""); -} - - -void ItemContent::print_content(Ezc::FunInfo & env) -{ - print_content(env.out, content_raw, content_raw_type, true); // IMPROVE ME get the 'true' from the config (config->html_filter) -} - bool ItemContent::do_migration(int & current_table_version) { @@ -305,6 +264,268 @@ bool ItemContent::do_migration_to_3() } +bool ItemContent::has_access(const User * current_user, int mask) const +{ + if( current_user ) + { + if( current_user->super_user ) + { + // super user is allowed everything + return true; + } + + if( user_id != -1 && current_user->id == user_id ) + { + // the owner + return ((privileges >> 9) & mask) == mask; + } + + if( group_id != -1 && current_user->IsMemberOf(group_id) ) + { + // group + return ((privileges >> 6) & mask) == mask; + } + + // others -- others logged users + return ((privileges >> 3) & mask) == mask; + } + + // guests -- not logged users + return (privileges & mask) == mask; +} + + +bool ItemContent::has_read_access(const User * current_user) const +{ + return has_access(current_user, 4); // r +} + + +bool ItemContent::has_write_access(const User * current_user) const +{ + return has_access(current_user, 2); // w +} + + +bool ItemContent::has_read_write_access(const User * current_user) const +{ + return has_access(current_user, 6); // r+w +} + + +bool ItemContent::has_read_exec_access(const User * current_user) const +{ + if( current_user && current_user->super_user ) + { + // there must be at least one 'x' (for the root) + // !! CHECK ME: is it applicable to directories too? + return (privileges & 01111) != 0; + } + + return has_access(current_user, 5); // r+x +} + + +bool ItemContent::has_read_access() const +{ + return has_read_access(get_current_user()); +} + + +bool ItemContent::has_write_access() const +{ + return has_write_access(get_current_user()); +} + + +bool ItemContent::has_read_write_access() const +{ + return has_read_write_access(get_current_user()); +} + + +bool ItemContent::has_read_exec_access() const +{ + return has_read_exec_access(get_current_user()); +} + + +bool ItemContent::is_sticky_bit_set() const +{ + int mask = 010000; + return (privileges & mask) == mask; +} + + + + +/* + * we're using the HtmlFilter only for those contents + * + */ +bool ItemContent::CanContentBeHtmlFiltered(ItemContent::ContentType ct) +{ + return ct == ct_text || ct == ct_formatted_text || ct == ct_html || ct == ct_bbcode; +} + +bool ItemContent::CanContentBeHtmlFiltered() +{ + return CanContentBeHtmlFiltered(content_raw_type); +} + + + + +void ItemContent::print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on) +{ + using TemplatesFunctions::R; + + if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) ) + out << R(""); + + if( content_type == ItemContent::ct_text ) + { + out << content; + } + else + if( content_type == ItemContent::ct_formatted_text ) + { + TemplatesFunctions::HtmlEscapeFormTxt(out, content); + } + else + if( content_type == ItemContent::ct_bbcode ) + { + static std::wstring out_temp; + out_temp.clear(); + out_temp.reserve(content.size()*2); + + BBCODEParser bbcode_parser; // IMPROVE ME move me to a better place + bbcode_parser.Filter(content.c_str(), out_temp); + out << R(out_temp); + } + else + { + // ct_html, ct_other + out << R(content); + } + + if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) ) + out << R(""); +} + + +void ItemContent::print_content(EzcEnv & env) +{ + print_content(env.out, content_raw, content_raw_type, true); // IMPROVE ME get the 'true' from the config (config->html_filter) +} + + +void ItemContent::has_static_file(EzcEnv & env) +{ + env.res = file_type != WINIX_ITEM_FILETYPE_NONE && !file_path.empty(); +} + + +void ItemContent::privileges_octal(EzcEnv & env) +{ + env.out << Toa(privileges, 8); +} + + +void ItemContent::user_name(EzcEnv & env) +{ + Users * users = get_users(); + + if( users ) + { + User * puser = users->GetUser(user_id); + TemplatesFunctions::print_user_name(env, puser, guest_name); + } +} + + +void ItemContent::group_name(EzcEnv & env) +{ + Groups * groups = get_groups(); + + if( groups ) + { + Group * pgroup = groups->GetGroup(group_id); + + if( pgroup ) + env.out << pgroup->name; + else + env.out << group_id; + } +} + + + +void ItemContent::type_is(EzcEnv & env) +{ + if( content_raw_type == ItemContent::ct_text && env.par == L"text" ) + env.res = true; + else + if( content_raw_type == ItemContent::ct_formatted_text && env.par == L"formatted text" ) + env.res = true; + else + if( content_raw_type == ItemContent::ct_html && env.par == L"html" ) + env.res = true; + else + if( content_raw_type == ItemContent::ct_bbcode && env.par == L"bbcode" ) + env.res = true; + else + if( content_raw_type == ItemContent::ct_other && env.par == L"other" ) + env.res = true; +} + + +void ItemContent::is_empty(EzcEnv & env) +{ + env.res = content_raw.empty(); +} + + +void ItemContent::file_type_is_none(EzcEnv & env) +{ + env.res = file_type == WINIX_ITEM_FILETYPE_NONE; +} + + +/* + * when we change file_type to string the we can return true only for + * those images which can be able to show by a webbrowser + * + */ +void ItemContent::file_type_is_image(EzcEnv & env) +{ + env.res = file_type == WINIX_ITEM_FILETYPE_IMAGE; +} + +/* + * similar we can return true only for those videos which can be rendered by a webbrowser + */ +void ItemContent::file_type_is_video(EzcEnv & env) +{ + env.res = file_type == WINIX_ITEM_FILETYPE_VIDEO; +} + + +void ItemContent::file_type_is_sound(EzcEnv & env) +{ + //env.res = file_type == WINIX_ITEM_FILETYPE_; + env.res = false; +} + + + +void ItemContent::has_thumb(EzcEnv & env) +{ + env.res = file_has_thumb; +} + + + } // namespace Winix diff --git a/winixd/models/itemcontent.h b/winixd/models/itemcontent.h index b05f6ec..3ec66e1 100644 --- a/winixd/models/itemcontent.h +++ b/winixd/models/itemcontent.h @@ -36,10 +36,12 @@ #define headerfile_winix_models_itemcontent #include +#include "winixmodel.h" #include "space/space.h" #include "date/date.h" #include "model.h" #include "templates/htmltextstream.h" +#include "templates/misc.h" namespace Winix @@ -55,10 +57,33 @@ namespace Winix -class ItemContent : public morm::Model +class ItemContent : public WinixModel { public: + /* + * IMPROVEME + * + * the kind of content type would be better to be a string + * so instead of 'ContentType content_raw_type' we would have 'std::wstring content_raw_type' + * this allows us to use plugin system to define its own types such as markdown + * + * if we show an editor (such as emacs) then we call plugins with a specified message + * and each plugin will put a string if it provides a content type mechanism + * (we can have pt::Space as a parameter in plugins - this can be a table of strings) + * + * after user clicks 'save' button we send another message with content_raw and content_raw_type + * and we expect content_raw_parsed to be made by a plugin + * + * or we have two content_type strings, one for internal use and the other for locale files (to show to a user) + * or even three, the last one used as a description + * + * + * + * file_type should be a string, we can use libmagick library to get the correct type + * + */ + /* * may we should add ct_none? and this will be default (set in Clear method) */ @@ -124,7 +149,7 @@ public: /* - * name of a link in the case when type is a symlink or a directory + * name of a link in the case whct_texten type is a symlink or a directory */ std::wstring link_to; @@ -226,16 +251,24 @@ public: * what about clear() from Model? */ void Clear(); - - static bool CanContentBeHtmlFiltered(ItemContent::ContentType ct); - bool CanContentBeHtmlFiltered(); - - - static void print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on); - void print_content(Ezc::FunInfo & env); - bool do_migration(int & current_table_version); + static bool CanContentBeHtmlFiltered(ItemContent::ContentType ct); + static void print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on); + + bool CanContentBeHtmlFiltered(); + + bool has_read_access(const User * current_user) const; + bool has_write_access(const User * current_user) const; + bool has_read_write_access(const User * current_user) const; + bool has_read_exec_access(const User * current_user) const; + + bool has_read_access() const; + bool has_write_access() const; + bool has_read_write_access() const; + bool has_read_exec_access() const; + + bool is_sticky_bit_set() const; protected: @@ -244,6 +277,22 @@ protected: bool do_migration_to_2(); bool do_migration_to_3(); + bool has_access(const User * current_user, int mask) const; + + void print_content(EzcEnv & env); + void has_static_file(EzcEnv & env); + void privileges_octal(EzcEnv & env); + void user_name(EzcEnv & env); + void group_name(EzcEnv & env); + void type_is(EzcEnv & env); + void is_empty(EzcEnv & env); + void file_type_is_none(EzcEnv & env); + void file_type_is_image(EzcEnv & env); + void file_type_is_video(EzcEnv & env); + void file_type_is_sound(EzcEnv & env); + void has_thumb(EzcEnv & env); + + MORM_MEMBER_FIELD(ItemContent) }; diff --git a/winixd/models/user.cpp b/winixd/models/user.cpp index 693a934..35ce904 100644 --- a/winixd/models/user.cpp +++ b/winixd/models/user.cpp @@ -125,11 +125,11 @@ void User::clear_passwords() -bool User::IsMemberOf(long group) +bool User::IsMemberOf(long group) const { -std::vector::iterator i; +std::vector::const_iterator i; - for(i=groups.begin() ; i!=groups.end() ; ++i) + for(i=groups.cbegin() ; i!=groups.cend() ; ++i) if( *i == group ) return true; diff --git a/winixd/models/user.h b/winixd/models/user.h index 4540111..25d0411 100644 --- a/winixd/models/user.h +++ b/winixd/models/user.h @@ -137,7 +137,7 @@ public: void after_select(); void Clear(); // IMPROVEME what about clear() from Model? - bool IsMemberOf(long group); + bool IsMemberOf(long group) const; bool ReadMonthDayTime(pt::Date & date, const wchar_t * str); bool SetTzFromEnv(); diff --git a/winixd/models/winixmodel.cpp b/winixd/models/winixmodel.cpp index 14cbb5b..02f3624 100644 --- a/winixd/models/winixmodel.cpp +++ b/winixd/models/winixmodel.cpp @@ -33,6 +33,9 @@ */ #include "winixmodel.h" +#include "core/session.h" + + namespace Winix { @@ -141,6 +144,162 @@ SLog * WinixModel::get_session_logger() } +Session * WinixModel::get_session() +{ + WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_session(); + } + + return nullptr; +} + + +User * WinixModel::get_current_user() +{ + Session * session = get_session(); + + if( session ) + { + return session->puser; + } + + return nullptr; +} + + + +const Config * WinixModel::get_config() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_config(); + } + + return nullptr; +} + + +const Request * WinixModel::get_request() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_request(); + } + + return nullptr; +} + + +const Log * WinixModel::get_logger() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_logger(); + } + + return nullptr; +} + + +const Dirs * WinixModel::get_dirs() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_dirs(); + } + + return nullptr; +} + + +const Mounts * WinixModel::get_mounts() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_mounts(); + } + + return nullptr; +} + + +const Users * WinixModel::get_users() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_users(); + } + + return nullptr; +} + + +const Groups * WinixModel::get_groups() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_groups(); + } + + return nullptr; +} + + +const SLog * WinixModel::get_session_logger() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_session_logger(); + } + + return nullptr; +} + + +const Session * WinixModel::get_session() const +{ + const WinixModelConnector * connector = get_winix_model_connector(); + + if( connector ) + { + return connector->get_winix_session(); + } + + return nullptr; +} + + + +const User * WinixModel::get_current_user() const +{ + const Session * session = get_session(); + + if( session ) + { + return session->puser; + } + + return nullptr; +} @@ -155,6 +314,16 @@ WinixModelConnector * WinixModel::get_winix_model_connector() } +const WinixModelConnector * WinixModel::get_winix_model_connector() const +{ + if( model_connector ) + { + return dynamic_cast(model_connector); + } + + return nullptr; +} + diff --git a/winixd/models/winixmodel.h b/winixd/models/winixmodel.h index 5c53be3..993cdb4 100644 --- a/winixd/models/winixmodel.h +++ b/winixd/models/winixmodel.h @@ -50,6 +50,9 @@ class Mounts; class Users; class Groups; class SLog; +class Session; +class User; + class WinixModel : public morm::Model @@ -64,10 +67,24 @@ public: Users * get_users(); Groups * get_groups(); SLog * get_session_logger(); // FIXME always return null at the moment, should be set when a new request is created and clear at the end of a request + Session * get_session(); + User * get_current_user(); + + const Config * get_config() const; + const Request * get_request() const; + const Log * get_logger() const; // there is no need for logger to be const, we can do nothing with such a logger + const Dirs * get_dirs() const; + const Mounts * get_mounts() const; + const Users * get_users() const; + const Groups * get_groups() const; + const SLog * get_session_logger() const; // FIXME always return null at the moment, should be set when a new request is created and clear at the end of a request + const Session * get_session() const; + const User * get_current_user() const; protected: WinixModelConnector * get_winix_model_connector(); + const WinixModelConnector * get_winix_model_connector() const; }; diff --git a/winixd/models/winixmodelconnector.cpp b/winixd/models/winixmodelconnector.cpp index 3c7897f..a02ec49 100644 --- a/winixd/models/winixmodelconnector.cpp +++ b/winixd/models/winixmodelconnector.cpp @@ -49,6 +49,7 @@ WinixModelConnector::WinixModelConnector() users = nullptr; groups = nullptr; slog = nullptr; + session = nullptr; } @@ -93,12 +94,74 @@ Groups * WinixModelConnector::get_winix_groups() return groups; } + SLog * WinixModelConnector::get_winix_session_logger() { return slog; } +Session * WinixModelConnector::get_winix_session() +{ + return session; +} + + +const Config * WinixModelConnector::get_winix_config() const +{ + return config; +} + + +const Request * WinixModelConnector::get_winix_request() const +{ + return request; +} + + +const Log * WinixModelConnector::get_winix_logger() const +{ + return log; +} + + +const Dirs * WinixModelConnector::get_winix_dirs() const +{ + return dirs; +} + + +const Mounts * WinixModelConnector::get_winix_mounts() const +{ + return mounts; +} + + +const Users * WinixModelConnector::get_winix_users() const +{ + return users; +} + + +const Groups * WinixModelConnector::get_winix_groups() const +{ + return groups; +} + + +const SLog * WinixModelConnector::get_winix_session_logger() const +{ + return slog; +} + + +const Session * WinixModelConnector::get_winix_session() const +{ + return session; +} + + + void WinixModelConnector::set_winix_config(Config * config) { this->config = config; @@ -140,11 +203,18 @@ void WinixModelConnector::set_winix_groups(Groups * groups) this->groups = groups; } + void WinixModelConnector::set_winix_session_logger(SLog * slog) { this->slog = slog; } +void WinixModelConnector::set_winix_session(Session * session) +{ + this->session = session; +} + + } diff --git a/winixd/models/winixmodelconnector.h b/winixd/models/winixmodelconnector.h index 2876e53..26bb28f 100644 --- a/winixd/models/winixmodelconnector.h +++ b/winixd/models/winixmodelconnector.h @@ -48,6 +48,7 @@ class Mounts; class Users; class Groups; class SLog; +class Session; class WinixModelConnector : public morm::ModelConnector @@ -64,6 +65,17 @@ public: Users * get_winix_users(); Groups * get_winix_groups(); SLog * get_winix_session_logger(); + Session * get_winix_session(); + + const Config * get_winix_config() const; + const Request * get_winix_request() const; + const Log * get_winix_logger() const; + const Dirs * get_winix_dirs() const; + const Mounts * get_winix_mounts() const; + const Users * get_winix_users() const; + const Groups * get_winix_groups() const; + const SLog * get_winix_session_logger() const; + const Session * get_winix_session() const; void set_winix_config(Config * config); void set_winix_request(Request * request); @@ -73,6 +85,7 @@ public: void set_winix_users(Users * users); void set_winix_groups(Groups * groups); void set_winix_session_logger(SLog * slog); + void set_winix_session(Session * session); protected: @@ -85,6 +98,7 @@ protected: Users * users; Groups * groups; SLog * slog; + Session * session; }; diff --git a/winixd/notify/notify.h b/winixd/notify/notify.h index 7600461..c45881a 100644 --- a/winixd/notify/notify.h +++ b/winixd/notify/notify.h @@ -49,7 +49,7 @@ namespace Winix { -struct Request; +class Request; class Config; class Users; class Dirs; diff --git a/winixd/templates/item.cpp b/winixd/templates/item.cpp index c8a07bc..2b5c744 100644 --- a/winixd/templates/item.cpp +++ b/winixd/templates/item.cpp @@ -53,151 +53,152 @@ static EzcGen ezc_generator; -void item_is(Info & i) -{ - i.res = cur->request->is_item; -} +//void item_is(Info & i) +//{ +// i.res = cur->request->is_item; +//} -void item_no_is(Info & i) -{ - i.res = !cur->request->is_item; -} +//void item_no_is(Info & i) +//{ +// i.res = !cur->request->is_item; +//} -void item_id(Info & i) -{ - i.out << cur->request->last_item->id; -} +//void item_id(Info & i) +//{ +// i.out << cur->request->last_item->id; +//} -void item_subject(Info & i) -{ - i.out << cur->request->last_item->subject; -} +//void item_subject(Info & i) +//{ +// i.out << cur->request->last_item->subject; +//} -void item_subject_noescape(Info & i) -{ - i.out << R(cur->request->last_item->subject); -} +//void item_subject_noescape(Info & i) +//{ +// i.out << R(cur->request->last_item->subject); +//} -void item_content(Info & i) -{ - i.out << cur->request->last_item->item_content.content_raw; -} +//void item_content(Info & i) +//{ +// i.out << cur->request->last_item->item_content.content_raw; +//} -void item_content_noescape(Info & i) -{ - i.out << R(cur->request->last_item->item_content.content_raw); -} +//void item_content_noescape(Info & i) +//{ +// i.out << R(cur->request->last_item->item_content.content_raw); +//} -void item_content_type_is(Item & item, Info & i) -{ - i.res = false; - - if( item.item_content.content_raw_type == ItemContent::ct_text && i.par == L"text" ) - i.res = true; - else - if( item.item_content.content_raw_type == ItemContent::ct_formatted_text && i.par == L"formatted text" ) - i.res = true; - else - if( item.item_content.content_raw_type == ItemContent::ct_html && i.par == L"html" ) - i.res = true; - else - if( item.item_content.content_raw_type == ItemContent::ct_bbcode && i.par == L"bbcode" ) - i.res = true; - else - if( item.item_content.content_raw_type == ItemContent::ct_other && i.par == L"other" ) - i.res = true; -} +//void item_content_type_is(Item & item, Info & i) +//{ +// i.res = false; +// +// if( item.item_content.content_raw_type == ItemContent::ct_text && i.par == L"text" ) +// i.res = true; +// else +// if( item.item_content.content_raw_type == ItemContent::ct_formatted_text && i.par == L"formatted text" ) +// i.res = true; +// else +// if( item.item_content.content_raw_type == ItemContent::ct_html && i.par == L"html" ) +// i.res = true; +// else +// if( item.item_content.content_raw_type == ItemContent::ct_bbcode && i.par == L"bbcode" ) +// i.res = true; +// else +// if( item.item_content.content_raw_type == ItemContent::ct_other && i.par == L"other" ) +// i.res = true; +//} +// +// +//void item_content_type_is(Info & i) +//{ +// item_content_type_is(*cur->request->last_item, i); +//} -void item_content_type_is(Info & i) -{ - item_content_type_is(*cur->request->last_item, i); -} +//void item_content_is_empty(Info & i) +//{ +// i.res = cur->request->last_item->item_content.content_raw.empty(); +//} -void item_content_is_empty(Info & i) -{ - i.res = cur->request->last_item->item_content.content_raw.empty(); -} +//void item_privileges(Info & i) +//{ +// i.out << Toa(cur->request->last_item->item_content.privileges, 8); +//} -void item_privileges(Info & i) -{ - i.out << Toa(cur->request->last_item->item_content.privileges, 8); -} +// RENAMED TO item.dir_link +//void item_dir(Info & i) +//{ +// dir(i); +//} -void item_dir(Info & i) -{ - dir(i); -} +//void item_url(Info & i) +//{ +// i.out << cur->request->last_item->url; +//} -void item_url(Info & i) -{ - i.out << cur->request->last_item->url; -} +//void item_url_is(Info & i) +//{ +// i.res = (cur->request->last_item->url == i.par); +//} -void item_url_is(Info & i) -{ - i.res = (cur->request->last_item->url == i.par); -} +//void item_url_is_no(Info & i) +//{ +// i.res = (cur->request->last_item->url != i.par); +//} -void item_url_is_no(Info & i) -{ - i.res = (cur->request->last_item->url != i.par); -} - - -void item_link(Info & i) -{ - doc_proto(i); - - if( !cur->request->subdomain.empty() ) - i.out << cur->request->subdomain << '.'; - - i.out << config->base_url; - item_dir(i); - item_url(i); -} +//void item_link(Info & i) +//{ +// doc_proto(i); +// +// if( !cur->request->subdomain.empty() ) +// i.out << cur->request->subdomain << '.'; +// +// i.out << config->base_url; +// item_dir(i); +// item_url(i); +//} -void item_filetype_is_none(Info & i) -{ - i.res = cur->request->last_item->item_content.file_type == WINIX_ITEM_FILETYPE_NONE; -} +//void item_filetype_is_none(Info & i) +//{ +// i.res = cur->request->last_item->item_content.file_type == WINIX_ITEM_FILETYPE_NONE; +//} +// +// +//void item_filetype_is_image(Info & i) +//{ +// i.res = cur->request->last_item->item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE; +//} -void item_filetype_is_image(Info & i) -{ - i.res = cur->request->last_item->item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE; -} +//void item_has_static_file(Info & i) +//{ +// i.res = cur->request->last_item->item_content.file_type != WINIX_ITEM_FILETYPE_NONE && !cur->request->last_item->item_content.file_path.empty(); +//} -void item_has_static_file(Info & i) -{ - i.res = cur->request->last_item->item_content.file_type != WINIX_ITEM_FILETYPE_NONE && !cur->request->last_item->item_content.file_path.empty(); -} - - -void item_has_thumb(Info & i) -{ - i.res = cur->request->last_item->item_content.file_has_thumb; -} +//void item_has_thumb(Info & i) +//{ +// i.res = cur->request->last_item->item_content.file_has_thumb; +//} void item_can_read(Info & i) @@ -220,11 +221,11 @@ void item_can_remove(Info & i) } -void item_user(Info & i) -{ - User * puser = system->users.GetUser(cur->request->last_item->item_content.user_id); - print_user_name(i, puser, cur->request->last_item->item_content.guest_name); -} +//void item_user(Info & i) +//{ +// User * puser = system->users.GetUser(cur->request->last_item->item_content.user_id); +// print_user_name(i, puser, cur->request->last_item->item_content.guest_name); +//} @@ -325,22 +326,22 @@ void item_has_html_template(Info & i) } -void item_type_is_dir(Info & i) -{ - i.res = cur->request->last_item->type == Item::dir; -} - - -void item_type_is_file(Info & i) -{ - i.res = cur->request->last_item->type == Item::file; -} - - -void item_type_is_symlink(Info & i) -{ - i.res = cur->request->last_item->type == Item::symlink; -} +//void item_type_is_dir(Info & i) +//{ +// i.res = cur->request->last_item->type == Item::dir; +//} +// +// +//void item_type_is_file(Info & i) +//{ +// i.res = cur->request->last_item->type == Item::file; +//} +// +// +//void item_type_is_symlink(Info & i) +//{ +// i.res = cur->request->last_item->type == Item::symlink; +//} void item_is_link_to(Info & i) diff --git a/winixd/templates/misc.cpp b/winixd/templates/misc.cpp index 806d188..41df59f 100644 --- a/winixd/templates/misc.cpp +++ b/winixd/templates/misc.cpp @@ -155,6 +155,7 @@ void print_user_name(Info & i, User & user) } +// IMPROVEME move me to User class void print_user_name(Info & i, User * puser, const std::wstring & guest_name) { if( puser ) diff --git a/winixd/templates/misc.h b/winixd/templates/misc.h index a62a757..0195a5b 100644 --- a/winixd/templates/misc.h +++ b/winixd/templates/misc.h @@ -47,6 +47,9 @@ namespace Winix class User; +// Ezc::FunInfo<> will be renamed to Ezc::Env<> in the future +typedef Ezc::FunInfo EzcEnv; + namespace TemplatesFunctions { @@ -54,7 +57,7 @@ namespace TemplatesFunctions typedef Ezc::Functions EzcFun; typedef Ezc::Generator EzcGen; -typedef Ezc::FunInfo Info; +typedef Ezc::FunInfo Info; // deprecated template HtmlTextStream::RawText R(const RawType & par) diff --git a/winixd/templates/templates.cpp b/winixd/templates/templates.cpp index 7546193..9690c4b 100644 --- a/winixd/templates/templates.cpp +++ b/winixd/templates/templates.cpp @@ -432,30 +432,30 @@ void Templates::CreateFunctions() /* item */ - ezc_functions.Insert("item_is", item_is); - ezc_functions.Insert("item_no_is", item_no_is); - ezc_functions.Insert("item_id", item_id); - ezc_functions.Insert("item_subject", item_subject); - ezc_functions.Insert("item_subject_noescape", item_subject_noescape); - ezc_functions.Insert("item_content_is_empty", item_content_is_empty); - ezc_functions.Insert("item_content", item_content); - ezc_functions.Insert("item_content_noescape", item_content_noescape); - ezc_functions.Insert("item_content_type_is", item_content_type_is); - ezc_functions.Insert("item_privileges", item_privileges); - ezc_functions.Insert("item_dir", item_dir); - ezc_functions.Insert("item_url", item_url); - ezc_functions.Insert("item_url_is", item_url_is); - ezc_functions.Insert("item_url_is_no", item_url_is_no); - ezc_functions.Insert("item_link", item_link); - ezc_functions.Insert("item_filetype_is_none", item_filetype_is_none); - ezc_functions.Insert("item_filetype_is_image", item_filetype_is_image); - ezc_functions.Insert("item_has_static_file", item_has_static_file); - ezc_functions.Insert("item_has_thumb", item_has_thumb); + //ezc_functions.Insert("item_is", item_is); + //ezc_functions.Insert("item_no_is", item_no_is); +// ezc_functions.Insert("item_id", item_id); +// ezc_functions.Insert("item_subject", item_subject); +// ezc_functions.Insert("item_subject_noescape", item_subject_noescape); +// ezc_functions.Insert("item_content_is_empty", item_content_is_empty); +// ezc_functions.Insert("item_content", item_content); +// ezc_functions.Insert("item_content_noescape", item_content_noescape); +// ezc_functions.Insert("item_content_type_is", item_content_type_is); + //ezc_functions.Insert("item_privileges", item_privileges); +// ezc_functions.Insert("item_dir", item_dir); +// ezc_functions.Insert("item_url", item_url); +// ezc_functions.Insert("item_url_is", item_url_is); +// ezc_functions.Insert("item_url_is_no", item_url_is_no); +// ezc_functions.Insert("item_link", item_link); +// ezc_functions.Insert("item_filetype_is_none", item_filetype_is_none); +// ezc_functions.Insert("item_filetype_is_image", item_filetype_is_image); + //ezc_functions.Insert("item_has_static_file", item_has_static_file); +// ezc_functions.Insert("item_has_thumb", item_has_thumb); ezc_functions.Insert("item_can_read", item_can_read); ezc_functions.Insert("item_can_write", item_can_write); ezc_functions.Insert("item_can_remove", item_can_remove); - ezc_functions.Insert("item_user", item_user); + //ezc_functions.Insert("item_user", item_user); ezc_functions.Insert("item_modification_user", item_modification_user); ezc_functions.Insert("item_users_different", item_users_different); ezc_functions.Insert("item_date_creation", item_date_creation); @@ -467,9 +467,9 @@ void Templates::CreateFunctions() ezc_functions.Insert("item_guest_name", item_guest_name); ezc_functions.Insert("item_html_template", item_html_template); ezc_functions.Insert("item_has_html_template", item_has_html_template); - ezc_functions.Insert("item_type_is_dir", item_type_is_dir); - ezc_functions.Insert("item_type_is_file", item_type_is_file); - ezc_functions.Insert("item_type_is_symlink", item_type_is_symlink); +// ezc_functions.Insert("item_type_is_dir", item_type_is_dir); +// ezc_functions.Insert("item_type_is_file", item_type_is_file); +// ezc_functions.Insert("item_type_is_symlink", item_type_is_symlink); ezc_functions.Insert("item_is_link_to", item_is_link_to); ezc_functions.Insert("item_link_to", item_link_to); ezc_functions.Insert("item_is_link_redirect", item_is_link_redirect); diff --git a/winixd/templates/templates.h b/winixd/templates/templates.h index c7790c4..fb220cd 100644 --- a/winixd/templates/templates.h +++ b/winixd/templates/templates.h @@ -322,30 +322,30 @@ namespace TemplatesFunctions /* item */ - void item_is(Info & i); - void item_no_is(Info & i); - void item_id(Info & i); - void item_subject(Info & i); - void item_subject_noescape(Info & i); - void item_content(Info & i); - void item_content_noescape(Info & i); - void item_content_type_is(Item & item, Info & i); - void item_content_type_is(Info & i); - void item_content_is_empty(Info & i); - void item_privileges(Info & i); - void item_dir(Info & i); - void item_url(Info & i); - void item_url_is(Info & i); - void item_url_is_no(Info & i); - void item_link(Info & i); - void item_filetype_is_none(Info & i); - void item_filetype_is_image(Info & i); - void item_has_static_file(Info & i); - void item_has_thumb(Info & i); + //void item_is(Info & i); + //void item_no_is(Info & i); + //void item_id(Info & i); + //void item_subject(Info & i); + //void item_subject_noescape(Info & i); + //void item_content(Info & i); + //void item_content_noescape(Info & i); + //void item_content_type_is(Item & item, Info & i); + //void item_content_type_is(Info & i); + //void item_content_is_empty(Info & i); + //void item_privileges(Info & i); + //void item_dir(Info & i); // RENAMED TO item.dir_link + //void item_url(Info & i); + //void item_url_is(Info & i); + //void item_url_is_no(Info & i); + //void item_link(Info & i); + //void item_filetype_is_none(Info & i); + //void item_filetype_is_image(Info & i); + //void item_has_static_file(Info & i); + //void item_has_thumb(Info & i); void item_can_read(Info & i); void item_can_write(Info & i); void item_can_remove(Info & i); - void item_user(Info & i); + //void item_user(Info & i); void item_modification_user(Info & i); void item_users_different(Info & i); void item_date_creation(Info & i); @@ -357,9 +357,9 @@ namespace TemplatesFunctions void item_guest_name(Info & i); void item_html_template(Info & i); void item_has_html_template(Info & i); - void item_type_is_dir(Info & i); - void item_type_is_file(Info & i); - void item_type_is_symlink(Info & i); + //void item_type_is_dir(Info & i); + //void item_type_is_file(Info & i); + //void item_type_is_symlink(Info & i); void item_is_link_to(Info & i); void item_link_to(Info & i); void item_is_link_redirect(Info & i);