added ticket parser: plugins/ticket/ticketparser.h plugins/ticket/ticketparser.cpp

git-svn-id: svn://ttmath.org/publicrep/winix/trunk@663 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-10-11 20:42:49 +00:00
parent 07511a2eb0
commit 33057acd62
23 changed files with 777 additions and 86 deletions

View File

@@ -11,7 +11,7 @@
#include <ctime>
#include "ticketinfo.h"
#include "core/error.h"
#include "core/log.h"
namespace Ticket
@@ -81,4 +81,124 @@ std::vector<Ticket>::iterator i;
}
void TicketInfo::MarkAllConfToDelete()
{
ConfTab::iterator i = conf_tab.begin();
for( ; i!=conf_tab.end() ; ++i)
i->second.to_delete = true;
}
void TicketInfo::DeleteAllMarkedConf()
{
ConfTab::iterator inext;
ConfTab::iterator i = conf_tab.begin();
while( i != conf_tab.end() )
{
inext = i;
++inext;
if( i->second.to_delete )
{
log << log3 << "Ticket: deleting ticket conf for dir id: " << i->first << logend;
conf_tab.erase(i);
}
i = inext;
}
}
bool TicketInfo::GetConfContent(const std::string & path)
{
long path_dir_id;
if( system->dirs.AnalyzePath(path, path_dir_id, path_dir, path_file) != 0 )
{
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;
return false;
}
return true;
}
bool TicketInfo::ParseTicketConf(long mount_dir_id, const std::string & path)
{
log << log3 << "Ticket: parsing conf file: " << path << logend;
int code = ticket_parser.Parse(item_conf.content, conf_tab[mount_dir_id].conf);
conf_tab[mount_dir_id].file_name = path;
return code == WINIX_TICKET_ERR_OK;
}
// if skip_existing_configs is true then only new config files will be parsed
void TicketInfo::ReadTicketConf(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_ticket_conf].defined &&
mount.param[mount_par_ticket_conf].arg.size() == 1 )
{
const std::string & 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;
}
}
}
}
}
// if skip_existing_configs is true then only new config files will be parsed
void TicketInfo::ReadTicketConf(bool skip_existing_configs)
{
MarkAllConfToDelete();
ReadTicketConf(system->mounts, skip_existing_configs);
DeleteAllMarkedConf();
}
} // namespace