some ezc functions from templates/item.cpp moved to Item and ItemContent
methods HasAccess() HasReadAccess() and similar moved from System to Item and ItemContent
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -52,6 +52,7 @@ class DirContainer : public WinixBase
|
||||
public:
|
||||
typedef std::list<Item> Table;
|
||||
typedef Table::iterator Iterator;
|
||||
typedef Table::const_iterator ConstIterator;
|
||||
typedef Table::size_type SizeType;
|
||||
|
||||
typedef std::map<long, Iterator> 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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -109,6 +109,8 @@ public:
|
||||
Item * GetDir(long id);
|
||||
Item * AddDir(const Item & item);
|
||||
|
||||
const Item * GetDir(long id) const;
|
||||
|
||||
void CheckRootDir();
|
||||
|
||||
Item * CreateVarDir();
|
||||
|
||||
@@ -77,7 +77,7 @@ class WinixRequest;
|
||||
|
||||
|
||||
class Plugin;
|
||||
struct Session;
|
||||
class Session;
|
||||
|
||||
|
||||
// move me to a different file
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -53,8 +53,9 @@ namespace Winix
|
||||
|
||||
|
||||
|
||||
struct Session
|
||||
class Session
|
||||
{
|
||||
public:
|
||||
|
||||
Session();
|
||||
Session(const Session & ses);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -239,7 +239,6 @@ private:
|
||||
std::vector<Item*> root_follow_dir_tab;
|
||||
Item temp_follow_item;
|
||||
|
||||
bool HasAccess(const Item & item, int mask);
|
||||
int NewPrivileges(int creation_mask);
|
||||
|
||||
bool CreateNewFileSimpleFs(Item & item);
|
||||
|
||||
@@ -183,25 +183,25 @@ void TextStream<StringType>::Reserve(size_t len)
|
||||
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType>::iterator TextStream<StringType>::begin()
|
||||
typename TextStream<StringType>::iterator TextStream<StringType>::begin()
|
||||
{
|
||||
return buffer.begin();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType>::iterator TextStream<StringType>::end()
|
||||
typename TextStream<StringType>::iterator TextStream<StringType>::end()
|
||||
{
|
||||
return buffer.end();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType>::const_iterator TextStream<StringType>::begin() const
|
||||
typename TextStream<StringType>::const_iterator TextStream<StringType>::begin() const
|
||||
{
|
||||
return buffer.begin();
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
TextStream<StringType>::const_iterator TextStream<StringType>::end() const
|
||||
typename TextStream<StringType>::const_iterator TextStream<StringType>::end() const
|
||||
{
|
||||
return buffer.end();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user