added: to templates: an interface for getting information from Space
miscspace.h, miscspace.cpp changed: plugin ticket now as a config we use a PT::Space struct (not finished yet, only 'integer', 'select' and 'progress' are done) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@794 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010, Tomasz Sowa
|
||||
* Copyright (c) 2010-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "core/misc.h"
|
||||
#include "sessiondata.h"
|
||||
|
||||
|
||||
namespace Ticket
|
||||
{
|
||||
|
||||
@@ -67,6 +66,9 @@ void TicketInfo::SetFunctions(Functions * pfunctions)
|
||||
void TicketInfo::Clear()
|
||||
{
|
||||
ticket = &ticket_empty;
|
||||
item = &item_empty;
|
||||
item->Clear();
|
||||
// we use meta from item which should not be const
|
||||
|
||||
cur_conf_wrap = &cur_conf_wrap_empty;
|
||||
cur_conf = &cur_conf_empty;
|
||||
@@ -126,10 +128,46 @@ bool TicketInfo::ParseTicketConf(long mount_dir_id, const std::wstring & path)
|
||||
{
|
||||
log << log3 << "Ticket: parsing conf file: " << path << logend;
|
||||
|
||||
int code = ticket_parser.Parse(config_file.content, conf_tab[mount_dir_id].conf);
|
||||
conf_tab[mount_dir_id].file_name = path;
|
||||
log << log1 << config_file.content << logend;
|
||||
|
||||
return code == WINIX_TICKET_ERR_OK;
|
||||
conf_tab[mount_dir_id].file_name = path;
|
||||
conf_parser.UTF8(true);
|
||||
conf_parser.SetSpace(conf_tab[mount_dir_id].conf);
|
||||
conf_parser.SplitSingle(true);
|
||||
conf_tab[mount_dir_id].conf.Clear();
|
||||
|
||||
//log << log1 << "status: " << conf_parser.Parse(config_file.content) << logend;
|
||||
|
||||
return (conf_parser.ParseString(config_file.content) == PT::ConfParser::ok);
|
||||
}
|
||||
|
||||
|
||||
void TicketInfo::ReadTicketConf(const Mount & mount, bool skip_existing_configs)
|
||||
{
|
||||
if( mount.param[mount_par_ticket_conf].defined &&
|
||||
mount.param[mount_par_ticket_conf].arg.size() == 1 )
|
||||
{
|
||||
const std::wstring & file_name = mount.param[mount_par_ticket_conf].arg[0];
|
||||
ConfTab::iterator c = conf_tab.find(mount.dir_id);
|
||||
bool exists = (c != conf_tab.end() && c->second.file_name == file_name);
|
||||
|
||||
if( exists )
|
||||
c->second.to_delete = false;
|
||||
|
||||
if( !(skip_existing_configs && exists) )
|
||||
{
|
||||
if( GetConfContent(file_name) )
|
||||
{
|
||||
if( !ParseTicketConf(mount.dir_id, file_name) )
|
||||
conf_tab[mount.dir_id].to_delete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( exists )
|
||||
c->second.to_delete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,31 +181,7 @@ void TicketInfo::ReadTicketConf(Mounts & mounts, bool skip_existing_configs)
|
||||
for(i=mtab->begin() ; i!=mtab->end() ; ++i)
|
||||
{
|
||||
const Mount & mount = i->second;
|
||||
|
||||
if( mount.param[mount_par_ticket_conf].defined &&
|
||||
mount.param[mount_par_ticket_conf].arg.size() == 1 )
|
||||
{
|
||||
const std::wstring & file_name = mount.param[mount_par_ticket_conf].arg[0];
|
||||
ConfTab::iterator c = conf_tab.find(mount.dir_id);
|
||||
bool exists = (c != conf_tab.end() && c->second.file_name == file_name);
|
||||
|
||||
if( exists )
|
||||
c->second.to_delete = false;
|
||||
|
||||
if( !(skip_existing_configs && exists) )
|
||||
{
|
||||
if( GetConfContent(file_name) )
|
||||
{
|
||||
if( !ParseTicketConf(mount.dir_id, file_name) )
|
||||
conf_tab[mount.dir_id].to_delete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( exists )
|
||||
c->second.to_delete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ReadTicketConf(mount, skip_existing_configs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,10 +198,7 @@ void TicketInfo::ReadTicketConf(bool skip_existing_configs)
|
||||
|
||||
void TicketInfo::FindCurrentConf()
|
||||
{
|
||||
if( !system->mounts.pmount )
|
||||
return;
|
||||
|
||||
long dir_id = system->mounts.pmount->dir_id;
|
||||
long dir_id = cur->mount->dir_id;
|
||||
ConfTab::iterator i = conf_tab.find(dir_id);
|
||||
|
||||
if( i != conf_tab.end() )
|
||||
@@ -197,62 +208,103 @@ void TicketInfo::FindCurrentConf()
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Ticket: there is no ticket_conf parameter in the mount point (an empty used)" << logend;
|
||||
log << log1 << "Ticket: there is no a ticket_conf parameter in the mount point (an empty config used)" << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TicketInfo::CheckMinMaxValue(const TicketConf::TicketItem & conf_item, Ticket::TicketParam & par)
|
||||
{
|
||||
if( conf_item.type == TicketConf::TicketItem::TypeInteger ||
|
||||
conf_item.type == TicketConf::TicketItem::TypeProgress )
|
||||
{
|
||||
if( par.int_value < conf_item.integer_min )
|
||||
par.int_value = conf_item.integer_min;
|
||||
|
||||
if( par.int_value > conf_item.integer_max )
|
||||
par.int_value = conf_item.integer_max;
|
||||
|
||||
void TicketInfo::CheckMinMaxValue(PT::Space & space, Ticket::TicketParam & par)
|
||||
{
|
||||
if( space.Text(L"type") == L"integer" )
|
||||
{
|
||||
std::wstring * min_str = space.GetValue(L"min");
|
||||
std::wstring * max_str = space.GetValue(L"min");
|
||||
|
||||
if( min_str )
|
||||
{
|
||||
long minv = Tol(*min_str);
|
||||
|
||||
if( par.intv < minv )
|
||||
par.intv = minv;
|
||||
}
|
||||
|
||||
if( max_str )
|
||||
{
|
||||
long maxv = Tol(*max_str);
|
||||
|
||||
if( par.intv > maxv )
|
||||
par.intv = maxv;
|
||||
}
|
||||
}
|
||||
else
|
||||
if( conf_item.type == TicketConf::TicketItem::TypeSelect )
|
||||
if( space.Text(L"type") == L"progress" )
|
||||
{
|
||||
for(size_t a=0 ; a<conf_item.select.size() ; ++a)
|
||||
// !! dodac tez min/max
|
||||
if( par.intv < 0 )
|
||||
par.intv = 0;
|
||||
|
||||
if( par.intv > 100 )
|
||||
par.intv = 100;
|
||||
}
|
||||
else
|
||||
if( space.Text(L"type") == L"select" )
|
||||
{
|
||||
for(size_t a=0 ; a<space.spaces.size() ; ++a)
|
||||
{
|
||||
if( conf_item.select[a].id == par.int_value )
|
||||
PT::Space & sp = *space.spaces[a];
|
||||
|
||||
if( sp.name == L"option" && sp.Long(L"id") == par.intv )
|
||||
return;
|
||||
}
|
||||
|
||||
if( conf_item.select_default < conf_item.select.size() )
|
||||
par.int_value = conf_item.select[conf_item.select_default].id;
|
||||
else
|
||||
par.int_value = 0;
|
||||
par.intv = Tol(space.Text(L"default"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool TicketInfo::ReadTicketValue(const TicketConf::TicketItem & conf_item, Ticket::TicketParam & par, const std::wstring & value)
|
||||
PT::Space & TicketInfo::FindAddMetaByParam(PT::Space & meta, long param)
|
||||
{
|
||||
if( conf_item.type == TicketConf::TicketItem::TypeInteger ||
|
||||
conf_item.type == TicketConf::TicketItem::TypeProgress ||
|
||||
conf_item.type == TicketConf::TicketItem::TypeSelect )
|
||||
for(size_t i=0 ; i<meta.spaces.size() ; ++i)
|
||||
{
|
||||
par.int_value = Tol(value);
|
||||
par.str_value.clear();
|
||||
CheckMinMaxValue(conf_item, par);
|
||||
PT::Space & sp = *meta.spaces[i];
|
||||
|
||||
if( sp.name == L"param" && sp.Long(L"id") == param )
|
||||
return sp;
|
||||
}
|
||||
|
||||
PT::Space & sp = meta.AddSpace(L"param");
|
||||
sp.Add(L"id", param);
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool TicketInfo::ReadTicketValue(PT::Space & space, long param_id, Ticket::TicketParam & par, const std::wstring & value, PT::Space & meta)
|
||||
{
|
||||
if( space.Text(L"type") == L"integer" ||
|
||||
space.Text(L"type") == L"progress" ||
|
||||
space.Text(L"type") == L"select" )
|
||||
{
|
||||
par.intv = Tol(value);
|
||||
par.decv.clear();
|
||||
CheckMinMaxValue(space, par);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( conf_item.type == TicketConf::TicketItem::TypeString ||
|
||||
conf_item.type == TicketConf::TicketItem::TypeMultistring )
|
||||
if( space.Text(L"type") == L"string" ||
|
||||
space.Text(L"type") == L"multistring" )
|
||||
{
|
||||
par.int_value = 0;
|
||||
par.str_value = value;
|
||||
// !! dodac cos co sprawdzi czy string nie zawiera znakow konca linii
|
||||
PT::Space & sp = FindAddMetaByParam(meta, param_id);
|
||||
sp.Add(L"value", value);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if( conf_item.type == TicketConf::TicketItem::TypeImages ||
|
||||
conf_item.type == TicketConf::TicketItem::TypeFiles )
|
||||
if( space.Text(L"type") == L"images" ||
|
||||
space.Text(L"type") == L"files" )
|
||||
{
|
||||
if( !value.empty() )
|
||||
{
|
||||
@@ -260,148 +312,152 @@ bool TicketInfo::ReadTicketValue(const TicketConf::TicketItem & conf_item, Ticke
|
||||
}
|
||||
else
|
||||
{
|
||||
// an empty field from the html form
|
||||
// an empty field from the html form (ignoring)
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! dodac obsluge komunikatow
|
||||
// niech zostanie wyslany komunikat o dodawaniu nieznanego parametru
|
||||
// i jesli nic nie odpowie na ten komunikat to wtedy zglaszamy blad
|
||||
log << log1 << "Ticket: incorrect parameter, param: " << par.param << ", value: " << value << " (ignored)" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// file_map can be null
|
||||
bool TicketInfo::ReadTicketValue(const TicketConf::TicketItem & conf_item,
|
||||
Ticket::TicketParam & par, const PostFile & value, std::vector<long> * file_map)
|
||||
{
|
||||
bool add = false;
|
||||
|
||||
if( conf_item.type == TicketConf::TicketItem::TypeImages ||
|
||||
conf_item.type == TicketConf::TicketItem::TypeFiles )
|
||||
void TicketInfo::ReadTicketValue(PT::Space & space,
|
||||
long param_id,
|
||||
const PostFile & value,
|
||||
std::vector<long> & file_map,
|
||||
PT::Space & meta,
|
||||
Item & upload_dir)
|
||||
{
|
||||
file.Clear(); // clearing and setting date
|
||||
file.parent_id = upload_dir.id;
|
||||
file.type = Item::file;
|
||||
file.privileges = 0644; // !! tymczasowo
|
||||
file.file_type = SelectFileType(value.filename);
|
||||
file.url = value.filename;
|
||||
functions->PrepareUrl(file);
|
||||
functions->SetUser(file);
|
||||
functions->fun_upload.UploadFile(file, value.tmp_filename);
|
||||
|
||||
if( cur->request->status == WINIX_ERR_OK )
|
||||
{
|
||||
Item * upload_dir = system->dirs.GetDir(conf_item.upload_dir);
|
||||
PT::Space & sp = meta.AddSpace(L"param");
|
||||
|
||||
sp.Add(L"id", param_id);
|
||||
|
||||
if( file.file_type == WINIX_ITEM_FILETYPE_IMAGE )
|
||||
sp.Add(L"type", L"image");
|
||||
else
|
||||
sp.Add(L"type", L"file");
|
||||
|
||||
sp.Add(L"file_id", file.id);
|
||||
system->MakePath(file, file_path);
|
||||
sp.Add(L"path", file_path);
|
||||
|
||||
file_map.push_back(file.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Ticket: problem with uploading" << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TicketInfo::ReadTicketValue(PT::Space & space,
|
||||
long param_id, const PostFile & value, std::vector<long> & file_map, PT::Space & meta)
|
||||
{
|
||||
if( space.Text(L"type") == L"images" ||
|
||||
space.Text(L"type") == L"files" )
|
||||
{
|
||||
std::wstring & upload_path = space.Text(L"upload_dir");
|
||||
Item * upload_dir = system->dirs.GetDir(upload_path);
|
||||
|
||||
if( upload_dir )
|
||||
{
|
||||
file.Clear(); // clearing and setting date
|
||||
file.parent_id = upload_dir->id;
|
||||
file.type = Item::file;
|
||||
file.privileges = 0644; // !! tymczasowo
|
||||
file.file_type = SelectFileType(value.filename);
|
||||
file.url = value.filename;
|
||||
functions->PrepareUrl(file);
|
||||
functions->SetUser(file);
|
||||
functions->fun_upload.UploadFile(file, value.tmp_filename);
|
||||
|
||||
if( cur->request->status == WINIX_ERR_OK )
|
||||
{
|
||||
add = true;
|
||||
par.int_value = file.id;
|
||||
system->MakePath(file, par.str_value);
|
||||
|
||||
if( file_map )
|
||||
file_map->push_back(file.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Ticket: problem with uploading" << logend;
|
||||
}
|
||||
ReadTicketValue(space, param_id, value, file_map, meta, *upload_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Ticket: there is no upload dir: " << conf_item.upload_dir << logend;
|
||||
log << log1 << "Ticket: there is no an upload directory: " << upload_path << logend;
|
||||
}
|
||||
}
|
||||
|
||||
if( !add )
|
||||
log << log1 << "Ticket: file parameter, param: " << par.param << " ignored" << logend;
|
||||
|
||||
return add;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// if the ticket has param_id already then the parameter is changed
|
||||
// if no then it is added
|
||||
void TicketInfo::ReadTicketParam(Ticket & ticket, int param_id, const std::wstring & value)
|
||||
// adding a new parameter only if it not exists in ticket.par_tab
|
||||
void TicketInfo::ReadTicketParam(PT::Space & space, Ticket & ticket, long param_id, const std::wstring & value, PT::Space & meta)
|
||||
{
|
||||
bool exists = false;
|
||||
ticket_param.param = param_id;
|
||||
|
||||
ticket_param.Clear();
|
||||
|
||||
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
|
||||
for(size_t i2=0 ; i2<ticket.par_tab.size() ; ++i2)
|
||||
{
|
||||
if( param_id == cur_conf->tab[i].id )
|
||||
if( ticket.par_tab[i2].param == param_id )
|
||||
{
|
||||
for(size_t i2=0 ; i2<ticket.par_tab.size() ; ++i2)
|
||||
{
|
||||
if( ticket.par_tab[i2].param == param_id )
|
||||
{
|
||||
// parameter exists
|
||||
exists = true;
|
||||
ticket_param.param = param_id;
|
||||
// parameter param_id already exists in ticket.par_tab
|
||||
// (overwritting)
|
||||
|
||||
if( ReadTicketValue(cur_conf->tab[i], ticket_param, value) )
|
||||
ticket.par_tab[i2] = ticket_param;
|
||||
if( ReadTicketValue(space, param_id, ticket_param, value, meta) )
|
||||
ticket.par_tab[i2] = ticket_param;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !exists )
|
||||
{
|
||||
// adding a new parameter
|
||||
exists = true;
|
||||
ticket_param.param = param_id;
|
||||
|
||||
if( ReadTicketValue(cur_conf->tab[i], ticket_param, value) )
|
||||
ticket.par_tab.push_back(ticket_param);
|
||||
}
|
||||
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( !exists )
|
||||
log << log1 << "Ticket: skipped incorrect parameter: " << param_id << " (not defined in the config)" << logend;
|
||||
// adding a new parameter param_id
|
||||
if( ReadTicketValue(space, param_id, ticket_param, value, meta) )
|
||||
ticket.par_tab.push_back(ticket_param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const std::wstring & value, PT::Space & meta)
|
||||
{
|
||||
ticket_param.Clear();
|
||||
|
||||
for(size_t i=0 ; i<cur_conf->spaces.size() ; ++i)
|
||||
{
|
||||
PT::Space & space = *cur_conf->spaces[i];
|
||||
|
||||
if( space.name == L"param" && Tol(space.Text(L"id")) == param_id )
|
||||
{
|
||||
ReadTicketParam(space, ticket, param_id, value, meta);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
log << log1 << "Ticket: skipped incorrect parameter: " << param_id << " (not defined in the config)" << logend;
|
||||
}
|
||||
|
||||
|
||||
// always adds a new parameter
|
||||
// file_map can be null
|
||||
void TicketInfo::ReadTicketParam(Ticket & ticket, int param_id, const PostFile & value, std::vector<long> * file_map)
|
||||
void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const PostFile & value, std::vector<long> & file_map, PT::Space & meta)
|
||||
{
|
||||
bool exists = false;
|
||||
|
||||
ticket_param.Clear();
|
||||
|
||||
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
|
||||
for(size_t i=0 ; i<cur_conf->spaces.size() ; ++i)
|
||||
{
|
||||
if( param_id == cur_conf->tab[i].id )
|
||||
PT::Space & space = *cur_conf->spaces[i];
|
||||
|
||||
if( space.name == L"param" && Tol(space.Text(L"id")) == param_id )
|
||||
{
|
||||
exists = true;
|
||||
ticket_param.param = param_id;
|
||||
|
||||
if( ReadTicketValue(cur_conf->tab[i], ticket_param , value, file_map) )
|
||||
ticket.par_tab.push_back(ticket_param);
|
||||
|
||||
break;
|
||||
ReadTicketValue(space, param_id, value, file_map, meta);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( !exists )
|
||||
log << log1 << "Ticket: skipped incorrect parameter: " << param_id << " (not defined in the config)" << logend;
|
||||
log << log1 << "Ticket: skipped incorrect parameter: " << param_id << " (not defined in the config)" << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TicketInfo::ReadTicketParams(Ticket & ticket, bool clear_ticket, std::vector<long> * file_map)
|
||||
void TicketInfo::ReadTicketParams(Ticket & ticket, bool clear_ticket, std::vector<long> & file_map, PT::Space & meta)
|
||||
{
|
||||
PostTab::iterator i;
|
||||
PostFileTab::iterator i2;
|
||||
@@ -409,16 +465,18 @@ PostFileTab::iterator i2;
|
||||
if( clear_ticket )
|
||||
ticket.Clear();
|
||||
|
||||
PT::Space & ticket_meta = meta.FindAddSpace(L"ticket");
|
||||
|
||||
for(i=cur->request->post_tab.begin() ; i!=cur->request->post_tab.end() ; ++i)
|
||||
{
|
||||
if( IsSubString(config->ticket_form_prefix, i->first) )
|
||||
ReadTicketParam(ticket, Toi(i->first.c_str() + config->ticket_form_prefix.size()), i->second);
|
||||
ReadTicketParam(ticket, Tol(i->first.c_str() + config->ticket_form_prefix.size()), i->second, ticket_meta);
|
||||
}
|
||||
|
||||
for(i2=cur->request->post_file_tab.begin() ; i2!=cur->request->post_file_tab.end() ; ++i2)
|
||||
{
|
||||
if( IsSubString(config->ticket_form_prefix, i2->first) )
|
||||
ReadTicketParam(ticket, Toi(i2->first.c_str() + config->ticket_form_prefix.size()), i2->second, file_map);
|
||||
ReadTicketParam(ticket, Tol(i2->first.c_str() + config->ticket_form_prefix.size()), i2->second, file_map, ticket_meta);
|
||||
}
|
||||
|
||||
ticket.SortParTab();
|
||||
@@ -431,11 +489,16 @@ void TicketInfo::RemoveTicket(long file_id)
|
||||
{
|
||||
if( tdb->GetTicket(file_id, rm_ticket) == WINIX_ERR_OK )
|
||||
{
|
||||
// !! WTF?
|
||||
/*
|
||||
for(size_t i=0 ; i<rm_ticket.par_tab.size(); ++i)
|
||||
{
|
||||
long id = rm_ticket.par_tab[i].int_value;
|
||||
functions->fun_rm.RemoveItemById(id);
|
||||
}
|
||||
*/
|
||||
|
||||
//
|
||||
|
||||
tdb->RemoveTicket(file_id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user