we can create links (hard links, symbolic links) now

added winix functions: ln

winix function 'default' can be used without redirecting now

added new tickets types: TypeProgress, TypeString, TypeMultistring, TypeImages, TypeFiles
now tickets are combined with files
added winix functions: showtickets

fixed mountpoints:
when the default root mount was created its parameter table was empty
and it caused accessing to a non-existing objects

fixed logger:
modifiers (log1, log2, log3) were incorrectly treated
added modifier: log4 (debug info)

now we are moving threads to a new plugin 'thread'
created directory: plugins/thread
(not finished yet)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@704 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-01-05 21:24:11 +00:00
parent bb83aed20d
commit 8154c403d8
113 changed files with 5840 additions and 2972 deletions

View File

@@ -13,7 +13,7 @@
#include "core/error.h"
#include "core/log.h"
#include "core/misc.h"
#include "sessiondata.h"
namespace Ticket
@@ -39,6 +39,12 @@ void TicketInfo::SetDb(Db * pdb)
}
void TicketInfo::SetConfig(Config * pconfig)
{
config = pconfig;
}
void TicketInfo::SetSystem(System * psystem)
{
system = psystem;
@@ -51,45 +57,24 @@ void TicketInfo::SetRequest(Request * prequest)
}
void TicketInfo::SetFunctions(Functions * pfunctions)
{
functions = pfunctions;
}
void TicketInfo::Clear()
{
item.Clear();
is_ticket = false;
ticket.Clear();
ticket = &ticket_empty;
ticket_tab.clear();
cur_conf_wrap = &cur_conf_wrap_empty;
cur_conf = &cur_conf_empty;
}
cur_conf = &cur_conf_empty;
void TicketInfo::ReadTicket(long dir_id)
{
if( tdb->GetTicket(dir_id, ticket) == WINIX_ERR_OK )
{
is_ticket = true;
//db->GetItemById(ticket.item_id, item);
}
}
bool TicketInfo::SortTicketsFun(const Ticket & t1, const Ticket & t2)
{
return t1.sort_id > t2.sort_id;
}
void TicketInfo::SortTickets()
{
std::vector<Ticket>::iterator i;
for(i=ticket_tab.begin() ; i!=ticket_tab.end() ; ++i)
{
Item * dir = system->dirs.GetDir(i->dir_id);
i->sort_id = ( dir ) ? (unsigned long)Time(dir->date_creation) : 0;
}
std::sort(ticket_tab.begin(), ticket_tab.end(), SortTicketsFun);
item_tab.clear();
ticket_tab.clear();
item_sort_tab.clear();
}
@@ -126,25 +111,11 @@ void TicketInfo::DeleteAllMarkedConf()
bool TicketInfo::GetConfContent(const std::wstring & path)
{
long path_dir_id;
int status = system->FollowAllLinks(path, config_dir_tab, config_file, false, false, false);
if( system->dirs.AnalyzePath(path, path_dir_id, path_dir, path_file) != 0 )
if( status != 1 )
{
log << log1 << "Ticket: there is no file: " << path << logend;
return false;
}
Error err = db->GetItem(path_dir_id, path_file, item_conf);
if( err == WINIX_ERR_NO_ITEM )
{
log << log1 << "Ticket: there is no file: " << path << " in the database" << logend;
return false;
}
if( err != WINIX_ERR_OK )
{
log << log1 << "Ticket: db problem with fetching: " << path << logend;
log << log1 << "Ticket: problem with reading a config file: " << path << ", status: " << status << logend;
return false;
}
@@ -156,7 +127,7 @@ bool TicketInfo::ParseTicketConf(long mount_dir_id, const std::wstring & path)
{
log << log3 << "Ticket: parsing conf file: " << path << logend;
int code = ticket_parser.Parse(item_conf.content, conf_tab[mount_dir_id].conf);
int code = ticket_parser.Parse(config_file.content, conf_tab[mount_dir_id].conf);
conf_tab[mount_dir_id].file_name = path;
return code == WINIX_TICKET_ERR_OK;
@@ -218,39 +189,86 @@ void TicketInfo::FindCurrentConf()
return;
long dir_id = system->mounts.pmount->dir_id;
ConfTab::iterator i = conf_tab.find(dir_id);
if( i != conf_tab.end() )
{
cur_conf_wrap = &i->second;
cur_conf = &i->second.conf;
cur_conf = &i->second.conf;
}
else
{
log << log1 << "Ticket: there is no ticket_conf parameter in the mount point (an empty used)" << logend;
}
}
bool TicketInfo::CheckMinMaxValue(const TicketConf::TicketItem & ticket_item, Ticket::TicketParam & par)
{
if( ticket_item.type == TicketConf::TicketItem::TypeInteger )
{
if( par.value < ticket_item.integer_min )
par.value = ticket_item.integer_min;
if( par.value > ticket_item.integer_max )
par.value = ticket_item.integer_max;
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;
}
else
if( ticket_item.type == TicketConf::TicketItem::TypeSelect )
if( conf_item.type == TicketConf::TicketItem::TypeSelect )
{
for(size_t a=0 ; a<ticket_item.select.size() ; ++a)
for(size_t a=0 ; a<conf_item.select.size() ; ++a)
{
if( ticket_item.select[a].id == par.value )
return true;
if( conf_item.select[a].id == par.int_value )
return;
}
log << log1 << "Ticket: incorrect select's value, param: "
<< par.param << ", value: " << par.value << " (ignored)" << logend;
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;
}
}
bool TicketInfo::ReadTicketValue(const TicketConf::TicketItem & conf_item, Ticket::TicketParam & par, const std::wstring & value)
{
if( conf_item.type == TicketConf::TicketItem::TypeInteger ||
conf_item.type == TicketConf::TicketItem::TypeProgress ||
conf_item.type == TicketConf::TicketItem::TypeSelect )
{
par.int_value = Tol(value);
par.str_value.clear();
CheckMinMaxValue(conf_item, par);
}
else
if( conf_item.type == TicketConf::TicketItem::TypeString ||
conf_item.type == TicketConf::TicketItem::TypeMultistring )
{
par.int_value = 0;
par.str_value = value;
}
else
if( conf_item.type == TicketConf::TicketItem::TypeImages ||
conf_item.type == TicketConf::TicketItem::TypeFiles )
{
if( !value.empty() )
{
log << log1 << "Ticket: images or files should be added only by a specific html tag (ignored)" << logend;
}
else
{
// an empty field from the html form
}
return false;
}
else
{
log << log1 << "Ticket: incorrect parameter, param: " << par.param << ", value: " << value << " (ignored)" << logend;
return false;
}
@@ -258,43 +276,154 @@ return true;
}
bool TicketInfo::CheckMinMaxValue(Ticket::TicketParam & par)
// file_map can be null
bool TicketInfo::ReadTicketValue(const TicketConf::TicketItem & conf_item,
Ticket::TicketParam & par, const PostFile & value, std::vector<long> * file_map)
{
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
bool add = false;
if( conf_item.type == TicketConf::TicketItem::TypeImages ||
conf_item.type == TicketConf::TicketItem::TypeFiles )
{
if( par.param == cur_conf->tab[i].id )
return CheckMinMaxValue(cur_conf->tab[i], par);
Item * upload_dir = system->dirs.GetDir(conf_item.upload_dir);
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( request->status == WINIX_ERR_OK )
{
add = true;
system->MakePath(file, par.str_value);
if( file_map )
file_map->push_back(file.id);
}
else
{
log << log1 << "Ticket: problem with uploading" << logend;
}
}
else
{
log << log1 << "Ticket: there is no upload dir: " << conf_item.upload_dir << logend;
}
}
log << log1 << "Ticket: unknown param: " << par.param << " (ignored)" << logend;
if( !add )
log << log1 << "Ticket: file parameter, param: " << par.param << " ignored" << logend;
return false;
return add;
}
void TicketInfo::ReadTicketParams()
// 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)
{
bool exists = false;
ticket_param.Clear();
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
{
if( param_id == cur_conf->tab[i].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;
if( ReadTicketValue(cur_conf->tab[i], ticket_param, value) )
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;
}
}
if( !exists )
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)
{
bool exists = false;
ticket_param.Clear();
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
{
if( param_id == cur_conf->tab[i].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;
}
}
if( !exists )
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)
{
PostTab::iterator i;
const wchar_t parstr[] = L"ticketparam"; // !! dodac do konfiga? i szablony tez niech bior<6F> z konfiga
size_t parlen = sizeof(parstr) / sizeof(wchar_t) - 1;
Ticket::TicketParam param;
PostFileTab::iterator i2;
ticket.par_tab.clear();
if( clear_ticket )
ticket.Clear();
for(i=request->post_tab.begin() ; i!=request->post_tab.end() ; ++i)
{
if( IsSubString(parstr, i->first.c_str()) )
{
param.param = Toi(i->first.c_str() + parlen);
param.value = Toi(i->second);
if( IsSubString(config->ticket_form_prefix, i->first) )
ReadTicketParam(ticket, Toi(i->first.c_str() + config->ticket_form_prefix.size()), i->second);
}
if( CheckMinMaxValue(param) )
ticket.par_tab.push_back(param);
}
for(i2=request->post_file_tab.begin() ; i2!=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);
}
}
} // namespace