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
master
Tomasz Sowa 2 years ago
parent 3d7ece15f8
commit 32e93a04c5

@ -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/convert/convert.a $(GLOBAL_WORKING_DIR)/pikotools/utf8/utf8.a $(GLOBAL_WORKING_DIR)/pikotools/space/space.a $(GLOBAL_WORKING_DIR)/pikotools/mainparser/mainparser.a $(GLOBAL_WORKING_DIR)/pikotools/date/date.a $(GLOBAL_WORKING_DIR)/pikotools/log/log.a $(GLOBAL_WORKING_DIR)/morm/src/morm.a $(LDFLAGS) -lfcgi -lpq -lz -lpthread -lcurl -Wl,-no-whole-archive
winix: winix.so $(winix.src.files)
@ -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

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

@ -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 user.o users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o

@ -284,6 +284,14 @@ bool App::Init()
model_connector.set_db_connector(postgresql_connector);
//model_connector.set_doc_connector(doc_html_connector);
// temporary
Item item_temp;
item_temp.set_connector(model_connector);
item_temp.do_migration(&model_connector);
//std::exit(0);
// -----------
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
db_conn.WaitForConnection();
db.PostgreSQLsmallerThan10(config.db_postgresql_smaller_than_10);

@ -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

@ -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
@ -76,7 +76,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 +88,33 @@ 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->update(false, false);
//db->EditPrivById(*i, i->id);
}
return;
}
log << log1 << "Dirs: there is no a root directory in the database (creating one)" << logend;
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;
// !! 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( db->AddItem(root) == WINIX_ERR_OK )
// {
// dir_tab.PushBack(root);
// }
if( root.insert() )
{
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;

@ -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)

@ -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
@ -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;
@ -414,11 +414,19 @@ bool Image::CreateCommand()
{
class 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);
{
// IMPROVEME we need a seperate model_connector for this thread
Lock();
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 +491,16 @@ 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;
{
// IMPROVEME we need a separate model_connector for this thread
Lock();
file_work.update(false, false);
//db->EditHasThumbById(true, file_work.id);
}
}
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
@ -528,11 +542,23 @@ void Image::SaveImage()
class 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);
morm::Finder<Item> finder(model_connector);
if( db->GetItem(file_work, iq) == WINIX_ERR_OK )
{
// IMPROVEME we need a seperate model_connector for this thread
Lock();
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 +584,7 @@ void Image::SaveImage()
{
log << log1 << "Image: cannot create a destination path" << logend;
}
}
//}
}

@ -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;

@ -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

@ -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"

@ -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"

@ -233,7 +233,7 @@ void Mounts::ReadMounts(const std::wstring & mounts)
// reading from /etc/fstab
Error Mounts::ReadMounts()
void Mounts::ReadMounts()
{
static std::wstring file = L"fstab";
@ -242,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 )
{
log << log1 << "M: there is no /etc/fstab file" << logend;
return err;
}
// Error err = db->GetItem(etc->id, file, fstab);
if( err != WINIX_ERR_OK )
if( !fstab.found() )
{
log << log1 << "M: cannot read /etc/fstab" << logend;
return err;
log << log1 << "M: there is no /etc/fstab file" << logend;
return;
}
ReadMounts(fstab.content);
// if( err != WINIX_ERR_OK )
// {
// log << log1 << "M: cannot read /etc/fstab" << logend;
// return err;
// }
return WINIX_ERR_OK;
ReadMounts(fstab.item_content.content_raw);
}

@ -124,7 +124,7 @@ public:
void CreateMounts();
void ReadMounts(const std::wstring & mounts);
Error ReadMounts();
void ReadMounts();
Mount * CalcCurMount();
Mount * CalcMount(long dir_id);

@ -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)

@ -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

@ -39,7 +39,7 @@
#include <sstream>
#include <vector>
#include "requesttypes.h"
#include "item.h"
#include "models/item.h"
#include "error.h"
#include "config.h"
#include "textstream.h"

@ -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 <string>
#include <ctime>
#include <map>
#include "item.h"
#include "error.h"
#include "user.h"
#include "plugindata.h"

@ -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
@ -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
@ -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,16 @@ 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);
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 +1061,22 @@ 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();
bool status = item.update(with_url, true);
//Error status = db->EditItemById(item, with_url);
if( status == WINIX_ERR_OK )
if( status )
{
TemplatesFunctions::pattern_cacher.UpdatePattern(item);
@ -1184,7 +1197,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 +1236,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 +1275,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 +1415,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 +1427,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,25 +1482,35 @@ 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;
}

@ -178,8 +178,8 @@ 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);

@ -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);

@ -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);

@ -2,11 +2,11 @@
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/space/space.h ../../../pikotools/textstream/types.h
db.o: ../../../pikotools/date/date.h ../../../pikotools/convert/inttostr.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
@ -23,21 +23,30 @@ 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 ../../../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: dbitemquery.h dbitemcolumns.h ../../../winix/winixd/core/user.h
db.o: ../../../winix/winixd/core/group.h
db.o: ../../../winix/winixd/core/dircontainer.h
db.o: ../../../winix/winixd/core/winixbase.h
db.o: ../../../winix/winixd/models/item.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/flatconnector.h ../../../morm/src/dbexpression.h
db.o: ../../../morm/src/baseexpression.h ../../../morm/src/morm_types.h
db.o: ../../../morm/src/modelenv.h ../../../morm/src/modeldata.h
db.o: ../../../morm/src/cursorhelper.h ../../../morm/src/finderhelper.h
db.o: ../../../morm/src/fieldvaluehelper.h ../../../morm/src/flatexpression.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: ../../../winix/winixd/core/misc.h
dbbase.o: ../../../winix/winixd/core/requesttypes.h
dbbase.o: ../../../pikotools/textstream/textstream.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/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
@ -61,13 +70,13 @@ 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: ../../../winix/winixd/core/misc.h
dbconn.o: ../../../winix/winixd/core/requesttypes.h
dbconn.o: ../../../pikotools/textstream/textstream.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/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
@ -89,17 +98,15 @@ 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.