changed: GroupItem plugin has been renamed to Group

it's nearly finished
         now we are using three levels from Space (ConfParser)
         - group set
         - group
         - values
         


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@773 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-10-16 21:33:45 +00:00
parent c7b6ca67a2
commit 0550212b64
28 changed files with 594 additions and 401 deletions

27
plugins/group/Makefile Executable file
View File

@@ -0,0 +1,27 @@
include Makefile.o.dep
name = group.so
all: $(name)
$(name): $(o)
$(CXX) -shared -Wl,-soname,$(name).so -o $(name) $(CXXFLAGS) *.o
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $<
depend:
makedepend -Y. -I../.. -I../../../ezc/src -f- *.cpp > Makefile.dep
echo -n "o = " > Makefile.o.dep
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
clean:
rm -f *.o
rm -f $(name)
include Makefile.dep

141
plugins/group/Makefile.dep Executable file
View File

@@ -0,0 +1,141 @@
# DO NOT DELETE
groupinfo.o: groupinfo.h groups.h ../../core/confparser.h ../../core/item.h
groupinfo.o: ../../core/system.h ../../core/dirs.h ../../core/item.h
groupinfo.o: ../../core/dircontainer.h ../../db/db.h ../../db/dbbase.h
groupinfo.o: ../../db/dbconn.h ../../db/dbtextstream.h
groupinfo.o: ../../core/textstream.h ../../core/misc.h
groupinfo.o: ../../core/requesttypes.h ../../core/error.h
groupinfo.o: ../../db/dbitemquery.h ../../db/dbitemcolumns.h
groupinfo.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
groupinfo.o: ../../core/ugcontainer.h ../../core/log.h
groupinfo.o: ../../core/textstream.h ../../core/logmanipulators.h
groupinfo.o: ../../core/slog.h ../../core/cur.h ../../core/request.h
groupinfo.o: ../../core/error.h ../../core/config.h ../../core/confparser.h
groupinfo.o: ../../core/htmlfilter.h ../../templates/htmltextstream.h
groupinfo.o: ../../core/session.h ../../core/user.h ../../core/plugindata.h
groupinfo.o: ../../core/rebus.h ../../core/mount.h ../../templates/locale.h
groupinfo.o: ../../notify/notify.h ../../notify/notifypool.h
groupinfo.o: ../../templates/patterns.h ../../templates/locale.h
groupinfo.o: ../../templates/localefilter.h ../../../ezc/src/ezc.h
groupinfo.o: ../../../ezc/src/utf8.h ../../../ezc/src/generator.h
groupinfo.o: ../../../ezc/src/pattern.h ../../../ezc/src/functions.h
groupinfo.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
groupinfo.o: ../../notify/notifythread.h ../../core/basethread.h
groupinfo.o: ../../core/synchro.h ../../notify/templatesnotify.h
groupinfo.o: ../../core/config.h ../../core/users.h ../../core/ugcontainer.h
groupinfo.o: ../../core/lastcontainer.h ../../templates/misc.h
groupinfo.o: ../../templates/htmltextstream.h ../../core/mounts.h
groupinfo.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
groupinfo.o: ../../core/users.h ../../core/loadavg.h ../../core/image.h
groupinfo.o: ../../core/basethread.h ../../core/threadmanager.h
groupinfo.o: ../../core/log.h
groups.o: groups.h ../../core/confparser.h ../../core/log.h
init.o: ../../core/log.h ../../core/plugin.h ../../core/pluginmsg.h
init.o: ../../core/log.h ../../core/textstream.h ../../core/logmanipulators.h
init.o: ../../core/slog.h ../../core/cur.h ../../core/request.h
init.o: ../../core/requesttypes.h ../../core/item.h ../../core/error.h
init.o: ../../core/config.h ../../core/confparser.h ../../core/htmlfilter.h
init.o: ../../templates/htmltextstream.h ../../core/textstream.h
init.o: ../../core/misc.h ../../core/session.h ../../core/user.h
init.o: ../../core/plugindata.h ../../core/rebus.h ../../core/mount.h
init.o: ../../templates/locale.h ../../core/confparser.h ../../core/system.h
init.o: ../../core/dirs.h ../../core/dircontainer.h ../../db/db.h
init.o: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
init.o: ../../core/error.h ../../db/dbitemquery.h ../../core/item.h
init.o: ../../db/dbitemcolumns.h ../../core/user.h ../../core/group.h
init.o: ../../core/dircontainer.h ../../core/ugcontainer.h
init.o: ../../notify/notify.h ../../notify/notifypool.h
init.o: ../../templates/patterns.h ../../templates/locale.h
init.o: ../../templates/localefilter.h ../../../ezc/src/ezc.h
init.o: ../../../ezc/src/utf8.h ../../../ezc/src/generator.h
init.o: ../../../ezc/src/pattern.h ../../../ezc/src/functions.h
init.o: ../../../ezc/src/funinfo.h ../../../ezc/src/stringconv.h
init.o: ../../notify/notifythread.h ../../core/basethread.h
init.o: ../../core/synchro.h ../../notify/templatesnotify.h
init.o: ../../core/config.h ../../core/users.h ../../core/ugcontainer.h
init.o: ../../core/lastcontainer.h ../../templates/misc.h
init.o: ../../templates/htmltextstream.h ../../core/mounts.h
init.o: ../../core/mountparser.h ../../core/crypt.h ../../core/run.h
init.o: ../../core/users.h groups.h ../../core/loadavg.h ../../core/image.h
init.o: ../../core/basethread.h ../../core/threadmanager.h
init.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h
init.o: ../../functions/functions.h ../../functions/functionbase.h
init.o: ../../core/request.h ../../core/system.h ../../core/synchro.h
init.o: ../../functions/functionparser.h ../../core/cur.h
init.o: ../../functions/adduser.h ../../functions/cat.h
init.o: ../../functions/chmod.h ../../functions/privchanger.h
init.o: ../../functions/chown.h ../../functions/ckeditor.h
init.o: ../../functions/cp.h ../../functions/default.h
init.o: ../../functions/download.h ../../functions/emacs.h
init.o: ../../functions/last.h ../../functions/login.h
init.o: ../../functions/logout.h ../../functions/ln.h ../../functions/ls.h
init.o: ../../functions/mkdir.h ../../functions/mv.h
init.o: ../../functions/nicedit.h ../../functions/node.h
init.o: ../../functions/passwd.h ../../functions/priv.h
init.o: ../../functions/reload.h ../../functions/rm.h ../../functions/sort.h
init.o: ../../functions/specialdefault.h ../../functions/stat.h
init.o: ../../functions/subject.h ../../functions/template.h
init.o: ../../functions/tinymce.h ../../functions/uname.h
init.o: ../../functions/upload.h ../../functions/uptime.h
init.o: ../../functions/who.h ../../functions/vim.h ../../core/htmlfilter.h
init.o: ../../templates/templates.h ../../templates/patterncacher.h
init.o: ../../templates/indexpatterns.h ../../templates/patterns.h
init.o: ../../templates/changepatterns.h ../../core/sessionmanager.h
init.o: groupinfo.h
templates.o: ../../templates/templates.h ../../../ezc/src/ezc.h
templates.o: ../../../ezc/src/utf8.h ../../../ezc/src/generator.h
templates.o: ../../../ezc/src/pattern.h ../../core/item.h
templates.o: ../../../ezc/src/functions.h ../../../ezc/src/funinfo.h
templates.o: ../../../ezc/src/stringconv.h ../../core/misc.h
templates.o: ../../core/requesttypes.h ../../templates/patterncacher.h
templates.o: ../../core/item.h ../../templates/indexpatterns.h
templates.o: ../../templates/patterns.h ../../templates/locale.h
templates.o: ../../templates/changepatterns.h
templates.o: ../../templates/htmltextstream.h ../../templates/localefilter.h
templates.o: ../../core/config.h ../../core/cur.h ../../core/system.h
templates.o: ../../core/dirs.h ../../core/dircontainer.h ../../db/db.h
templates.o: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
templates.o: ../../core/textstream.h ../../core/error.h
templates.o: ../../db/dbitemquery.h ../../db/dbitemcolumns.h
templates.o: ../../core/user.h ../../core/group.h ../../core/dircontainer.h
templates.o: ../../core/ugcontainer.h ../../core/log.h
templates.o: ../../core/textstream.h ../../core/logmanipulators.h
templates.o: ../../core/slog.h ../../core/cur.h ../../core/request.h
templates.o: ../../core/error.h ../../core/config.h ../../core/confparser.h
templates.o: ../../core/htmlfilter.h ../../templates/htmltextstream.h
templates.o: ../../core/session.h ../../core/user.h ../../core/plugindata.h
templates.o: ../../core/rebus.h ../../core/mount.h ../../templates/locale.h
templates.o: ../../core/confparser.h ../../notify/notify.h
templates.o: ../../notify/notifypool.h ../../templates/patterns.h
templates.o: ../../notify/notifythread.h ../../core/basethread.h
templates.o: ../../core/synchro.h ../../notify/templatesnotify.h
templates.o: ../../core/users.h ../../core/ugcontainer.h
templates.o: ../../core/lastcontainer.h ../../templates/misc.h
templates.o: ../../core/mounts.h ../../core/mountparser.h ../../core/crypt.h
templates.o: ../../core/run.h ../../core/users.h groups.h
templates.o: ../../core/loadavg.h ../../core/image.h ../../core/basethread.h
templates.o: ../../core/threadmanager.h ../../core/sessionmanager.h
templates.o: ../../core/htmlfilter.h ../../core/plugin.h
templates.o: ../../core/pluginmsg.h ../../core/system.h
templates.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h
templates.o: ../../functions/functions.h ../../functions/functionbase.h
templates.o: ../../core/request.h ../../core/synchro.h
templates.o: ../../functions/functionparser.h ../../functions/adduser.h
templates.o: ../../functions/cat.h ../../functions/chmod.h
templates.o: ../../functions/privchanger.h ../../functions/chown.h
templates.o: ../../functions/ckeditor.h ../../functions/cp.h
templates.o: ../../functions/default.h ../../functions/download.h
templates.o: ../../functions/emacs.h ../../functions/last.h
templates.o: ../../functions/login.h ../../functions/logout.h
templates.o: ../../functions/ln.h ../../functions/ls.h
templates.o: ../../functions/mkdir.h ../../functions/mv.h
templates.o: ../../functions/nicedit.h ../../functions/node.h
templates.o: ../../functions/passwd.h ../../functions/priv.h
templates.o: ../../functions/reload.h ../../functions/rm.h
templates.o: ../../functions/sort.h ../../functions/specialdefault.h
templates.o: ../../functions/stat.h ../../functions/subject.h
templates.o: ../../functions/template.h ../../functions/tinymce.h
templates.o: ../../functions/uname.h ../../functions/upload.h
templates.o: ../../functions/uptime.h ../../functions/who.h
templates.o: ../../functions/vim.h groupinfo.h ../../core/misc.h

1
plugins/group/Makefile.o.dep Executable file
View File

@@ -0,0 +1 @@
o = groupinfo.o groups.o init.o templates.o

178
plugins/group/groupinfo.cpp Executable file
View File

@@ -0,0 +1,178 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "groupinfo.h"
#include "core/log.h"
#include "core/system.h"
namespace GroupItem
{
GroupInfo::GroupInfo()
{
mount_par_group_conf = -1;
}
void GroupInfo::SetSystem(System * psystem)
{
system = psystem;
}
void GroupInfo::SetConfig(Config * pconfig)
{
config = pconfig;
}
Groups * GroupInfo::FindGroups(long dir_id)
{
GroupsWrap::iterator i = groups_wrap.find(dir_id);
if( i == groups_wrap.end() )
return 0;
return &(i->second.groups);
}
bool GroupInfo::ParseGroups(const std::wstring & str, Groups & groups)
{
groups.Clear();
Space & space = *groups.GetSpace();
conf_parser.SetSpace(space);
conf_parser.UTF8(config->utf8);
if( conf_parser.ParseString(str) == ConfParser::ok )
{
groups.Reindex();
}
else
{
slog << logerror << "Syntax error in line: " << conf_parser.line << logend;
log << log1 << "Syntax error in line: " << conf_parser.line << logend;
groups.Clear();
}
return conf_parser.status == ConfParser::ok;
}
void GroupInfo::MarkAllGroupsToDelete()
{
GroupsWrap::iterator i = groups_wrap.begin();
for( ; i != groups_wrap.end() ; ++i)
i->second.to_delete = true;
}
void GroupInfo::DeleteAllMarkedGroups()
{
GroupsWrap::iterator inext;
GroupsWrap::iterator i = groups_wrap.begin();
while( i != groups_wrap.end() )
{
inext = i;
++inext;
if( i->second.to_delete )
{
log << log3 << "GroupItem: deleting group for dir id: " << i->first << logend;
groups_wrap.erase(i);
}
i = inext;
}
}
bool GroupInfo::GetConfContent(const std::wstring & path)
{
int status = system->FollowAllLinks(path, config_dir_tab, config_file, false, false, false);
if( status != 1 )
{
log << log1 << "GroupItem: problem with reading a config file: " << path << ", status: " << status << logend;
return false;
}
return true;
}
// if skip_existing_configs is true then only new config files will be parsed
void GroupInfo::ReadGroupsConf(Mounts & mounts, bool skip_existing_configs)
{
Mounts::MountTab::const_iterator i;
const Mounts::MountTab * mtab = mounts.GetMountTab();
// loop through all mount points
for(i=mtab->begin() ; i!=mtab->end() ; ++i)
{
const Mount & mount = i->second;
if( mount.param[mount_par_group_conf].defined &&
mount.param[mount_par_group_conf].arg.size() == 1 )
{
const std::wstring & file_name = mount.param[mount_par_group_conf].arg[0];
GroupsWrap::iterator c = groups_wrap.find(mount.dir_id);
bool exists = (c != groups_wrap.end() && c->second.file_name == file_name);
if( exists )
c->second.to_delete = false;
if( !(skip_existing_configs && exists) )
{
if( GetConfContent(file_name) )
{
log << log3 << "GroupItem: parsing conf file: " << config_file.url << logend;
groups_wrap[mount.dir_id].file_name = file_name;
if( !ParseGroups(config_file.content, groups_wrap[mount.dir_id].groups) )
groups_wrap[mount.dir_id].to_delete = true;
}
else
{
if( exists )
c->second.to_delete = true;
}
}
}
}
}
// if skip_existing_configs is true then only new config files will be parsed
void GroupInfo::ReadGroupsConfigs(bool skip_existing_configs)
{
MarkAllGroupsToDelete();
ReadGroupsConf(system->mounts, skip_existing_configs);
DeleteAllMarkedGroups();
}
}

86
plugins/group/groupinfo.h Executable file
View File

@@ -0,0 +1,86 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_plugins_groupitem_groupinfo
#define headerfile_winix_plugins_groupitem_groupinfo
#include <string>
#include <vector>
#include "groups.h"
#include "core/confparser.h"
#include "core/item.h"
#include "core/system.h"
#include "core/config.h"
namespace GroupItem
{
struct GroupsWrapItem
{
bool to_delete;
std::wstring file_name;
Groups groups;
GroupsWrapItem()
{
to_delete = false;
}
};
class GroupInfo
{
public:
GroupInfo();
void SetSystem(System * psystem);
void SetConfig(Config * pconfig);
void ReadGroupsConfigs(bool skip_existing_configs);
Groups * FindGroups(long dir_id); // can return a null pointer
int mount_par_group_conf;
private:
System * system;
Config * config;
// map[mount_dir_id] -> GroupsWrapItem
typedef std::map<long, GroupsWrapItem> GroupsWrap;
GroupsWrap groups_wrap;
ConfParser conf_parser;
std::vector<Item*> config_dir_tab;
Item config_file;
void MarkAllGroupsToDelete();
void DeleteAllMarkedGroups();
bool GetConfContent(const std::wstring & path);
bool ParseGroupsConf(long mount_dir_id, const std::wstring & path);
bool ParseGroups(const std::wstring & str, Groups & groups);
void ReadGroupsConf(Mounts & mounts, bool skip_existing_configs);
};
}
#endif

216
plugins/group/groups.cpp Executable file
View File

@@ -0,0 +1,216 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include <limits>
#include "groups.h"
#include "core/log.h"
namespace GroupItem
{
Space * Groups::GetSpace()
{
return &space;
}
void Groups::Reindex()
{
set_index.clear();
group_index_tab.clear();
size_t seti = 0;
while( seti < space.spaces.size() )
{
const std::wstring & name = space.spaces[seti]->name;
if( set_index.find(name) == set_index.end() )
{
set_index[name] = seti;
group_index_tab.push_back(GroupIndex());
ReindexGroups(group_index_tab.back(), *space.spaces[seti]);
seti += 1;
}
else
{
slog << logerror << "set: " << name << " already defined (skipping)" << logend;
space.spaces.erase(space.spaces.begin() + seti);
}
}
}
void Groups::ReindexGroups(GroupIndex & group_index, Space & set)
{
size_t i, v;
// loop through all groups in the set
for( i=0 ; i < set.spaces.size() ; ++i )
{
Space & group = *set.spaces[i];
const std::wstring & key = group.Text(L"key", L"value");
// loop through all values in the group
for(v=0 ; v<group.spaces.size() ; )
{
Space::Table::iterator vali = group.spaces[v]->table.find(key);
if( vali != group.spaces[v]->table.end() && vali->second.size() == 1 )
{
GroupIndex::iterator g = group_index.find(vali->second[0]);
if( g == group_index.end() )
{
group_index[vali->second[0]] = i;
v += 1;
}
else
{
slog << logwarning << "set: " << set.name << " has a group with a duplicated value: "
<< vali->second[0] << " (skipping)" << logend;
group.spaces.erase(group.spaces.begin() + v);
}
}
else
{
slog << logwarning << "set: " << set.name << " has a group without a value (skipping)" << logend;
group.spaces.erase(group.spaces.begin() + v);
}
}
SortValues(group);
}
}
void Groups::SortValues(Space & group)
{
sort_by = group.Text(L"sort_by");
sort_asc = (group.Text(L"sort_asc", L"true") == L"true");
if( !sort_by.empty() )
{
group.ListText(L"sort", sort_value);
std::sort(group.spaces.begin(), group.spaces.end(), SortFunHelper(this));
}
}
bool Groups::SortFunHelper::operator()(Space * sp1, Space * sp2)
{
const std::wstring & val1 = sp1->Text(groups->sort_by, L"");
const std::wstring & val2 = sp2->Text(groups->sort_by, L"");
if( groups->sort_asc )
return SortValue(val1) < SortValue(val2);
else
return SortValue(val1) > SortValue(val2);
}
size_t Groups::SortFunHelper::SortValue(const std::wstring & val)
{
for(size_t i=0 ; i<groups->sort_value.size() ; ++i)
if( val == groups->sort_value[i] )
return i;
return std::numeric_limits<size_t>::max();
}
bool Groups::Find(const std::wstring & set, const std::wstring & value, size_t & seti, size_t & groupi)
{
SetIndex::iterator i = set_index.find(set);
if( i != set_index.end() )
{
if( i->second < group_index_tab.size() )
{
GroupIndex::iterator viter = group_index_tab[i->second].find(value);
if( viter != group_index_tab[i->second].end() )
{
seti = i->second;
groupi = viter->second;
return true;
}
}
}
return false;
}
const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option)
{
if( seti < space.spaces.size() )
{
Space & groups = *space.spaces[seti];
if( groupi < groups.spaces.size() )
{
Space & value = *groups.spaces[groupi];
if( valuei < value.spaces.size() )
return value.spaces[valuei]->Text(option);
}
}
return empty_str;
}
const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const std::wstring & option)
{
return GetOption(seti, groupi, valuei, option.c_str());
}
size_t Groups::Size(size_t seti, size_t groupi)
{
if( seti < space.spaces.size() )
{
Space & groups = *space.spaces[seti];
if( groupi < groups.spaces.size() )
return groups.spaces[groupi]->spaces.size();
}
return 0;
}
void Groups::Clear()
{
space.Clear();
set_index.clear();
group_index_tab.clear();
}
}

130
plugins/group/groups.h Executable file
View File

@@ -0,0 +1,130 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_plugins_groupitem_groups
#define headerfile_winix_plugins_groupitem_groups
#include <map>
#include <vector>
#include <string>
#include "core/confparser.h"
namespace GroupItem
{
class Groups
{
public:
/*
reading all space
(sets and groups)
*/
Space * GetSpace();
/*
building all indexes
*/
void Reindex();
bool Find(const std::wstring & set, const std::wstring & value, size_t & seti, size_t & groupi);
/*
*/
size_t Size(size_t seti, size_t groupi);
const std::wstring & GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option);
const std::wstring & GetOption(size_t seti, size_t groupi, size_t valuei, const std::wstring & option);
/*
removing all groups
*/
void Clear();
private:
/*
our space:
set1 (
# group1
(
( value = "value1"
other = "foo" )
( value = "something"
other = "x" )
)
# group2
(
)
) # end of set1
# we can have more sets
# sets should have a unique name
# groups don't have a name
*/
Space space;
/*
indexes to a set of groups
*/
typedef std::map<std::wstring, size_t> SetIndex;
SetIndex set_index;
/*
indexes to a groups in a set
mapping: value->group index
*/
typedef std::map<std::wstring, size_t> GroupIndex;
/*
group indexes in a specified set
std::vector<how many sets there are>
*/
std::vector<GroupIndex> group_index_tab;
const std::wstring empty_str;
std::wstring sort_by;
bool sort_asc;
Space::Value sort_value;
struct SortFunHelper
{
Groups * groups;
SortFunHelper(Groups * pgroups) : groups(pgroups) {};
size_t SortValue(const std::wstring & val);
bool operator()(Space * sp1, Space * sp2);
};
void ReindexGroups(GroupIndex & group_index, Space & set);
void SortValues(Space & group);
};
}
#endif

76
plugins/group/init.cpp Executable file
View File

@@ -0,0 +1,76 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "core/log.h"
#include "core/plugin.h"
#include "groupinfo.h"
extern "C" void Init(PluginInfo &);
namespace GroupItem
{
const wchar_t plugin_name[] = L"group";
GroupInfo group_info;
void AddMountPar(PluginInfo & info)
{
group_info.mount_par_group_conf = info.system->mounts.AddMountPar(L"group_conf");
}
void FstabChanged(PluginInfo & info)
{
group_info.ReadGroupsConfigs(true);
}
void ProcessRequest(PluginInfo & info)
{
if( info.cur->request->function == &info.functions->fun_reload )
{
if( info.cur->request->IsParam(L"group") )
group_info.ReadGroupsConfigs(false);
}
}
void AddEzcFunctions(PluginInfo & info);
} // namespace
void Init(PluginInfo & info)
{
using namespace GroupItem;
plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions);
plugin.Assign(WINIX_ADD_MOUNTS, AddMountPar);
plugin.Assign(WINIX_FSTAB_CHANGED, FstabChanged);
plugin.Assign(WINIX_PROCESS_REQUEST, ProcessRequest);
group_info.SetSystem(info.system);
group_info.SetConfig(info.config);
info.p1 = (void*)(plugin_name);
}

128
plugins/group/templates.cpp Executable file
View File

@@ -0,0 +1,128 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011, Tomasz Sowa
* All rights reserved.
*
*/
#include "templates/templates.h"
#include "core/plugin.h"
#include "groupinfo.h"
#include "core/misc.h"
namespace GroupItem
{
using namespace TemplatesFunctions;
using TemplatesFunctions::system;
extern GroupInfo group_info;
static bool group_tab_found = false;
static Groups * pgroups;
static size_t req_id = 0;
static size_t set_index;
static size_t group_index;
static size_t value_index;
static std::wstring last_set, last_value;
static std::wstring path;
void group_tab_init(const std::wstring & set, const std::wstring & value)
{
if( req_id != cur->request->id || last_set != set || last_value != value )
{
req_id = cur->request->id;
pgroups = group_info.FindGroups(cur->mount->dir_id);
last_set = set;
last_value = value;
group_tab_found = false;
if( pgroups && pgroups->Find(set, value, set_index, group_index) )
group_tab_found = true;
}
}
void group_tab(Info & i)
{
if( i.params.size() == 2 )
{
group_tab_init(i.params[0], i.params[1]);
value_index = i.iter;
if( group_tab_found )
i.res = value_index < pgroups->Size(set_index, group_index);
}
else
{
group_tab_found = false;
}
}
void group_link_tab(Info & i)
{
if( i.params.size() == 1 )
{
system->dirs.MakePath(cur->request->dir_tab, path);
if( cur->request->is_item )
path += cur->request->item.url;
else
NoLastSlash(path);
group_tab_init(i.params[0], path);
value_index = i.iter;
if( group_tab_found )
i.res = value_index < pgroups->Size(set_index, group_index);
}
else
{
group_tab_found = false;
}
}
void group_tab_value(Info & i)
{
if( group_tab_found )
{
if( !i.par.empty() )
i.out << pgroups->GetOption(set_index, group_index, value_index, i.par);
else
i.out << pgroups->GetOption(set_index, group_index, value_index, L"value");
}
}
void AddEzcFunctions(PluginInfo & info)
{
using TemplatesFunctions::EzcFun;
EzcFun * fun = reinterpret_cast<EzcFun*>(info.p1);
/*
*/
fun->Insert("group_tab", group_tab);
fun->Insert("group_link_tab", group_link_tab);
fun->Insert("group_tab_value", group_tab_value);
}
} // namespace