2009-04-20 00:13:21 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mountparser.h"
|
|
|
|
#include "data.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "log.h"
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MountParser::IsWhite(int c)
|
|
|
|
{
|
|
|
|
if( c==' ' || c=='\t' || c==13 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MountParser::SkipWhite()
|
|
|
|
{
|
|
|
|
while( IsWhite(*pinput) )
|
|
|
|
++pinput;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MountParser::SkipLine()
|
|
|
|
{
|
|
|
|
while( *pinput && *pinput != 10 )
|
|
|
|
++pinput;
|
|
|
|
|
|
|
|
if( *pinput == 10 )
|
|
|
|
++pinput;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MountParser::ReadWord(std::string & res)
|
|
|
|
{
|
|
|
|
res.clear();
|
|
|
|
|
|
|
|
while( *pinput && *pinput!=10 && !IsWhite(*pinput) )
|
|
|
|
{
|
|
|
|
res += *pinput;
|
|
|
|
++pinput;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 01:49:28 +02:00
|
|
|
void MountParser::ReadParam(std::string & res)
|
|
|
|
{
|
|
|
|
res.clear();
|
|
|
|
|
|
|
|
while( *pinput && *pinput!=10 && *pinput!=',' && !IsWhite(*pinput) )
|
|
|
|
{
|
|
|
|
res += *pinput;
|
|
|
|
++pinput;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *pinput==',' )
|
|
|
|
++pinput;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
void MountParser::ReadMountType()
|
|
|
|
{
|
|
|
|
SkipWhite();
|
|
|
|
ReadWord(temp);
|
|
|
|
|
|
|
|
if( temp == "cms" )
|
|
|
|
{
|
2009-04-21 01:49:28 +02:00
|
|
|
mount.type = Mount::cms;
|
2009-04-20 00:13:21 +02:00
|
|
|
log << log3 << "MP: mount type: cms" << logend;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( temp == "thread" )
|
|
|
|
{
|
2009-04-21 01:49:28 +02:00
|
|
|
mount.type = Mount::thread;
|
2009-04-20 00:13:21 +02:00
|
|
|
log << log3 << "MP: mount type: thread" << logend;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = Error::mount_unknown;
|
|
|
|
log << log1 << "MP: unknown mount type: " << temp << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MountParser::ReadMountPoint()
|
|
|
|
{
|
|
|
|
SkipWhite();
|
|
|
|
|
|
|
|
// !! narazie bez cudzyslowow
|
|
|
|
ReadWord(temp);
|
|
|
|
|
|
|
|
pdir = data.dirs.GetDir(temp);
|
|
|
|
|
|
|
|
if( pdir )
|
|
|
|
{
|
2009-04-21 01:49:28 +02:00
|
|
|
mount.dir_id = pdir->id;
|
2009-04-20 00:13:21 +02:00
|
|
|
log << log3 << "MP: mount point: " << temp << logend;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-20 23:10:31 +02:00
|
|
|
err = Error::no_mountpoint;
|
2009-04-20 00:13:21 +02:00
|
|
|
log << log1 << "MP: there is no such a mount point: " << temp << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-21 01:49:28 +02:00
|
|
|
void MountParser::ReadMountParams()
|
|
|
|
{
|
|
|
|
SkipWhite();
|
|
|
|
|
|
|
|
for( ReadParam(temp) ; !temp.empty() ; ReadParam(temp) )
|
|
|
|
{
|
|
|
|
if( !mount.ParseStrParam(temp) )
|
|
|
|
{
|
|
|
|
log << log1 << "MP: unknown mount param: " << temp << logend;
|
|
|
|
err = Error::mount_no_param;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log3 << "MP: mount param: " << temp << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-20 00:13:21 +02:00
|
|
|
void MountParser::ReadRow(std::map<long, Mount> & output)
|
|
|
|
{
|
|
|
|
ReadMountType();
|
|
|
|
|
|
|
|
if( err == Error::ok )
|
|
|
|
ReadMountPoint();
|
|
|
|
|
2009-04-21 01:49:28 +02:00
|
|
|
if( err == Error::ok )
|
|
|
|
ReadMountParams();
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
if( err == Error::ok )
|
|
|
|
{
|
2009-04-21 01:49:28 +02:00
|
|
|
output.insert( std::make_pair(mount.dir_id, mount) );
|
2009-04-20 00:13:21 +02:00
|
|
|
}
|
2009-04-21 01:49:28 +02:00
|
|
|
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
SkipLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Error MountParser::Parse(const std::string & input, std::map<long, Mount> & output)
|
|
|
|
{
|
|
|
|
pinput = input.c_str();
|
|
|
|
err = Error::ok;
|
|
|
|
output.clear();
|
|
|
|
|
|
|
|
while( *pinput && err == Error::ok )
|
|
|
|
ReadRow(output);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|