refactoring
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@523 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
2ca44ec361
commit
dc5f002de3
|
@ -110,7 +110,7 @@ void Content::MakeStandardFunction()
|
||||||
if( !request.pfunction )
|
if( !request.pfunction )
|
||||||
SetDefaultFunction();
|
SetDefaultFunction();
|
||||||
|
|
||||||
if( request.result == Request::redirect )
|
if( !request.redirect_to.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ void Content::Make()
|
||||||
if( request.method == Request::post )
|
if( request.method == Request::post )
|
||||||
MakePost();
|
MakePost();
|
||||||
|
|
||||||
if( request.result == Request::redirect )
|
if( !request.redirect_to.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( request.status == Error::ok )
|
if( request.status == Error::ok )
|
||||||
|
@ -249,7 +249,7 @@ void Content::Make()
|
||||||
request.status = Error::permision_denied;
|
request.status = Error::permision_denied;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( request.result == Request::redirect )
|
if( !request.redirect_to.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( request.dir_table.empty() )
|
if( request.dir_table.empty() )
|
||||||
|
@ -275,23 +275,22 @@ void Content::RedirectTo(const Item & item)
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
request.result = Request::redirect;
|
request.redirect_to = data.base_url;
|
||||||
request.str = data.base_url;
|
|
||||||
|
|
||||||
|
|
||||||
if( item.type == Item::dir )
|
if( item.type == Item::dir )
|
||||||
{
|
{
|
||||||
// item_id is pointing to a directory
|
// item_id is pointing to a directory
|
||||||
data.dirs.MakePath(item.id, path);
|
data.dirs.MakePath(item.id, path);
|
||||||
request.str += path;
|
request.redirect_to += path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( !data.dirs.MakePath(item.parent_id, path) )
|
if( !data.dirs.MakePath(item.parent_id, path) )
|
||||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << item.id << logend;
|
log << log1 << "Content: Can't redirect: no dirs for item id: " << item.id << logend;
|
||||||
|
|
||||||
request.str += path;
|
request.redirect_to += path;
|
||||||
request.str += item.url;
|
request.redirect_to += item.url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,16 +301,15 @@ void Content::RedirectTo(long item_id)
|
||||||
std::string path;
|
std::string path;
|
||||||
Item * pdir;
|
Item * pdir;
|
||||||
|
|
||||||
request.result = Request::redirect;
|
request.redirect_to = data.base_url;
|
||||||
request.str = data.base_url;
|
pdir = data.dirs.GetDir(item_id);
|
||||||
pdir = data.dirs.GetDir(item_id);
|
|
||||||
|
|
||||||
|
|
||||||
if( pdir )
|
if( pdir )
|
||||||
{
|
{
|
||||||
// item_id is pointing to a directory
|
// item_id is pointing to a directory
|
||||||
data.dirs.MakePath(pdir->id, path);
|
data.dirs.MakePath(pdir->id, path);
|
||||||
request.str += path;
|
request.redirect_to += path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -324,7 +322,7 @@ Item * pdir;
|
||||||
if( !data.dirs.MakePath(request.item_table[0].parent_id, path) )
|
if( !data.dirs.MakePath(request.item_table[0].parent_id, path) )
|
||||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << request.item_table[0].id << ", requested directory id: " << request.item_table[0].parent_id << logend;
|
log << log1 << "Content: Can't redirect: no dirs for item id: " << request.item_table[0].id << ", requested directory id: " << request.item_table[0].parent_id << logend;
|
||||||
|
|
||||||
request.str += path + request.item_table[0].url;
|
request.redirect_to += path + request.item_table[0].url;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -386,9 +384,9 @@ bool Content::CheckRebus()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string & answer = request.PostVar("rebus");
|
std::string * answer = request.PostVar("rebus");
|
||||||
|
|
||||||
if( data.rebus.IsAnswerOk(request.session->rebus_item, answer) )
|
if( answer && data.rebus.IsAnswerOk(request.session->rebus_item, *answer) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(const Error &)
|
catch(const Error &)
|
||||||
|
@ -401,23 +399,16 @@ return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Content::SetUser()
|
void Content::SetUser(Item & item)
|
||||||
{
|
{
|
||||||
if( request.session->puser )
|
if( request.session->puser )
|
||||||
{
|
{
|
||||||
request.item.user_id = request.session->puser->id;
|
item.user_id = request.session->puser->id;
|
||||||
request.item.guest_name.clear();
|
item.guest_name.clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
request.item.user_id = -1;
|
item.user_id = -1;
|
||||||
|
request.PostVar("guestname", item.guest_name);
|
||||||
try
|
|
||||||
{
|
|
||||||
request.item.guest_name = request.PostVar("guestname");
|
|
||||||
}
|
|
||||||
catch(const Error &)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Content
|
||||||
|
|
||||||
void MakeStandardFunction();
|
void MakeStandardFunction();
|
||||||
|
|
||||||
void SetUser();
|
void SetUser(Item & item);
|
||||||
bool CheckRebus();
|
bool CheckRebus();
|
||||||
|
|
||||||
void MakePost();
|
void MakePost();
|
||||||
|
|
|
@ -37,29 +37,10 @@ void Content::PostFunCreateThread()
|
||||||
if( !CheckRebus() )
|
if( !CheckRebus() )
|
||||||
{
|
{
|
||||||
request.status = Error::rebus_bad_answer;
|
request.status = Error::rebus_bad_answer;
|
||||||
|
request.PostVar("url", request.item.url);
|
||||||
try
|
request.PostVar("subject", request.item.subject);
|
||||||
{
|
request.PostVar("content", request.item.content);
|
||||||
try
|
SetUser(request.item);
|
||||||
{
|
|
||||||
request.item.url = request.PostVar("url");
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
request.item.subject = request.PostVar("subject");
|
|
||||||
|
|
||||||
|
|
||||||
request.item.content = request.PostVar("content");
|
|
||||||
|
|
||||||
|
|
||||||
SetUser();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,13 @@ long Content::PostFunDefaultParsePath()
|
||||||
Item * pdir, * pdir2;
|
Item * pdir, * pdir2;
|
||||||
long defaultid = -1;
|
long defaultid = -1;
|
||||||
|
|
||||||
std::string & path = request.PostVar("defaultitem");
|
std::string * path = request.PostVar("defaultitem");
|
||||||
|
|
||||||
|
|
||||||
if( !path.empty() )
|
if( path && !path->empty() )
|
||||||
{
|
{
|
||||||
std::string dir, file;
|
std::string dir, file;
|
||||||
Dirs::SplitPath(path, dir, file);
|
Dirs::SplitPath(*path, dir, file);
|
||||||
|
|
||||||
pdir = data.dirs.GetDir(dir);
|
pdir = data.dirs.GetDir(dir);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ void Content::PostFunEmacsAdd()
|
||||||
|
|
||||||
request.is_item = true;
|
request.is_item = true;
|
||||||
|
|
||||||
SetUser();
|
SetUser(request.item);
|
||||||
|
|
||||||
request.item.group_id = -1;
|
request.item.group_id = -1;
|
||||||
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
||||||
|
@ -100,14 +100,8 @@ bool adding = true;
|
||||||
{
|
{
|
||||||
// these old values are ignored (if exists)
|
// these old values are ignored (if exists)
|
||||||
|
|
||||||
//!! tymczasowo, zabezpieczenie przed pustym url-em
|
request.PostVar("url", request.item.url);
|
||||||
try {
|
request.PostVar("subject", request.item.subject);
|
||||||
request.item.url = request.PostVar("url");
|
|
||||||
request.item.subject = request.PostVar("subject");
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if( request.item.subject.empty() )
|
if( request.item.subject.empty() )
|
||||||
request.item.subject = request.dir_table.back()->subject;
|
request.item.subject = request.dir_table.back()->subject;
|
||||||
|
@ -115,11 +109,12 @@ bool adding = true;
|
||||||
// !! nie bedzie obciazany modul wyszukujacy bardzo
|
// !! nie bedzie obciazany modul wyszukujacy bardzo
|
||||||
////////
|
////////
|
||||||
|
|
||||||
request.item.content = request.PostVar("content");
|
request.PostVar("content", request.item.content);
|
||||||
|
|
||||||
bool with_url = false;
|
bool with_url = false;
|
||||||
|
std::string * old_url = request.PostVar("old_url");
|
||||||
if( !request.is_item || request.PostVar("old_url") != request.item.url )
|
|
||||||
|
if( !request.is_item || (old_url && *old_url!=request.item.url) )
|
||||||
with_url = true;
|
with_url = true;
|
||||||
|
|
||||||
PrepareUrl(request.item);
|
PrepareUrl(request.item);
|
||||||
|
@ -127,7 +122,7 @@ bool adding = true;
|
||||||
if( !CheckRebus() )
|
if( !CheckRebus() )
|
||||||
{
|
{
|
||||||
request.status = Error::rebus_bad_answer;
|
request.status = Error::rebus_bad_answer;
|
||||||
SetUser();
|
SetUser(request.item);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,11 @@ void Content::PostFunLogin()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string & login = request.PostVar("login");
|
std::string * login = request.PostVar("login");
|
||||||
std::string & pass = request.PostVar("password");
|
std::string * pass = request.PostVar("password");
|
||||||
long user_id;
|
long user_id;
|
||||||
|
|
||||||
if( db.CheckUser(login, pass, user_id) )
|
if( login && pass && db.CheckUser(*login, *pass, user_id) )
|
||||||
{
|
{
|
||||||
request.session->puser = data.users.GetUser(user_id);
|
request.session->puser = data.users.GetUser(user_id);
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void Content::PostFunLogin()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.last.UserLogin(user_id, login, inet_addr(request.env_remote_addr), request.session->id);
|
data.last.UserLogin(user_id, *login, inet_addr(request.env_remote_addr), request.session->id);
|
||||||
|
|
||||||
log << log2 << "User " << login << " (id: " << user_id << ") logged" << logend;
|
log << log2 << "User " << login << " (id: " << user_id << ") logged" << logend;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,12 @@ void Content::FunLogout()
|
||||||
request.session->puser = 0;
|
request.session->puser = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.result = Request::redirect;
|
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
data.dirs.MakePath(request.dir_table.back()->id, path);
|
data.dirs.MakePath(request.dir_table.back()->id, path);
|
||||||
|
request.redirect_to = data.base_url + path;
|
||||||
request.str = data.base_url + path;
|
|
||||||
|
|
||||||
if( request.is_item )
|
if( request.is_item )
|
||||||
request.str += request.item.url;
|
request.redirect_to += request.item.url;
|
||||||
|
|
||||||
request.session->done = Done::loggedout;
|
request.session->done = Done::loggedout;
|
||||||
request.session->done_timer = 2;
|
request.session->done_timer = 2;
|
||||||
|
|
|
@ -28,22 +28,14 @@ void Content::PostFunMkdir(bool add_to_dir_table, int mask)
|
||||||
Item item;
|
Item item;
|
||||||
request.session->done = Done::added_dir;
|
request.session->done = Done::added_dir;
|
||||||
|
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
item.type = Item::dir;
|
item.type = Item::dir;
|
||||||
item.subject = request.PostVar("subject");
|
request.PostVar("subject", item.subject);
|
||||||
item.url = request.PostVar("url");
|
request.PostVar("url", item.url);
|
||||||
item.parent_id = request.dir_table.back()->id;
|
item.parent_id = request.dir_table.back()->id;
|
||||||
|
|
||||||
if( request.session->puser )
|
SetUser(item);
|
||||||
{
|
|
||||||
item.user_id = request.session->puser->id;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item.user_id = -1;
|
|
||||||
item.guest_name = request.PostVar("guestname");
|
|
||||||
}
|
|
||||||
|
|
||||||
item.group_id = -1;
|
item.group_id = -1;
|
||||||
item.privileges = mask;
|
item.privileges = mask;
|
||||||
|
@ -55,12 +47,12 @@ void Content::PostFunMkdir(bool add_to_dir_table, int mask)
|
||||||
|
|
||||||
request.session->done_status = db.AddItem(item);
|
request.session->done_status = db.AddItem(item);
|
||||||
|
|
||||||
}
|
/* }
|
||||||
catch(const Error & e)
|
catch(const Error & e)
|
||||||
{
|
{
|
||||||
request.session->done_status = e;
|
request.session->done_status = e;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if( request.session->done_status == Error::ok )
|
if( request.session->done_status == Error::ok )
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,9 +18,21 @@ void Content::PostFunPriv(Item & item)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long user_id = data.users.GetUserId( request.PostVar("user") );
|
std::string * user = request.PostVar("user");
|
||||||
long group_id = data.groups.GetGroupId( request.PostVar("group") );
|
std::string * group = request.PostVar("group");
|
||||||
int privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
|
std::string * priv = request.PostVar("privileges");
|
||||||
|
|
||||||
|
if( !user || !group || !priv )
|
||||||
|
{
|
||||||
|
log << log3 << "Content: PostFunPriv: there is no some post variables" << logend;
|
||||||
|
// some kind of error to report?
|
||||||
|
// !! wstawic nowy kod bledu i rzucic wyjatek jego (usunac powyzszy wpis log takze)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long user_id = data.users.GetUserId( *user );
|
||||||
|
long group_id = data.groups.GetGroupId( *group );
|
||||||
|
int privileges = strtol( priv->c_str() , 0, 8);
|
||||||
|
|
||||||
if( user_id==item.user_id && group_id==item.group_id && privileges==item.privileges )
|
if( user_id==item.user_id && group_id==item.group_id && privileges==item.privileges )
|
||||||
{
|
{
|
||||||
|
|
150
core/dirs.cpp
150
core/dirs.cpp
|
@ -60,34 +60,6 @@ void Dirs::ReadDirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::GetRootDir(Item ** item)
|
|
||||||
{
|
|
||||||
DirContainer::Iterator root = dir_table.GetRoot();
|
|
||||||
|
|
||||||
if( root == dir_table.End() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
*item = &(*root);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::GetDir(const std::string & name, long parent, Item ** item)
|
|
||||||
{
|
|
||||||
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
|
||||||
|
|
||||||
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
|
||||||
if( i->second->url == name )
|
|
||||||
{
|
|
||||||
*item = &(*i->second);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::ExtractName(const char * & s, std::string & name)
|
bool Dirs::ExtractName(const char * & s, std::string & name)
|
||||||
{
|
{
|
||||||
name.clear();
|
name.clear();
|
||||||
|
@ -103,62 +75,6 @@ return !name.empty();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! moze lepiej zwracac wskaznik do Item i kiedy nie ma katalogu to zwracac 0 ?
|
|
||||||
bool Dirs::GetDir(const std::string & path, Item ** item)
|
|
||||||
{
|
|
||||||
DirContainer::Iterator root = dir_table.GetRoot();
|
|
||||||
|
|
||||||
if( root == dir_table.End() )
|
|
||||||
// ops, we do not have a root dir
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Item * pitem = &(*root);
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
const char * s = path.c_str();
|
|
||||||
|
|
||||||
while( ExtractName(s, name) )
|
|
||||||
{
|
|
||||||
if( !GetDir(name, pitem->id, &pitem) )
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*item = pitem;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! ten interfejs jes bylejaki
|
|
||||||
// !! moze lepiej zwracac id i kiedy nie ma katalogu to -1 (przeciez to jest wartosc ktora nie moze pojawic sie w indeksie)
|
|
||||||
bool Dirs::GetDirId(const std::string & path, long * id)
|
|
||||||
{
|
|
||||||
Item * pitem;
|
|
||||||
|
|
||||||
if( !GetDir(path, &pitem) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
*id = pitem->id;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::GetDirId(const std::string & name, long parent, long * id)
|
|
||||||
{
|
|
||||||
Item * pitem;
|
|
||||||
|
|
||||||
if( !GetDir(name, parent, &pitem) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
*id = pitem->id;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::IsDir(long id)
|
bool Dirs::IsDir(long id)
|
||||||
|
@ -174,20 +90,6 @@ return true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::GetDirChilds(long parent, std::vector<Item> & childs_table)
|
|
||||||
{
|
|
||||||
if( parent != -1 && !IsDir(parent) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
|
|
||||||
|
|
||||||
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
|
|
||||||
childs_table.push_back( *i->second );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
|
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
|
||||||
{
|
{
|
||||||
if( parent != -1 && !IsDir(parent) )
|
if( parent != -1 && !IsDir(parent) )
|
||||||
|
@ -232,55 +134,6 @@ DirContainer::Iterator i;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// with exceptions
|
|
||||||
|
|
||||||
Item * Dirs::GetDirT(const std::string & path)
|
|
||||||
{
|
|
||||||
Item * pitem;
|
|
||||||
|
|
||||||
if( !GetDir(path, &pitem) )
|
|
||||||
throw Error(Error::incorrect_dir);
|
|
||||||
|
|
||||||
return pitem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Item * Dirs::GetDirT(const std::string & name, long parent)
|
|
||||||
{
|
|
||||||
Item * pitem;
|
|
||||||
|
|
||||||
if( !GetDir(name, parent, &pitem) )
|
|
||||||
throw Error(Error::incorrect_dir);
|
|
||||||
|
|
||||||
return pitem;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long Dirs::GetDirIdT(const std::string & path)
|
|
||||||
{
|
|
||||||
long id;
|
|
||||||
|
|
||||||
if( !GetDirId(path, &id) )
|
|
||||||
throw Error(Error::incorrect_dir);
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
long Dirs::GetDirIdT(const std::string & name, long parent)
|
|
||||||
{
|
|
||||||
long id;
|
|
||||||
|
|
||||||
if( !GetDirId(name, parent, &id) )
|
|
||||||
throw Error(Error::incorrect_dir);
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! nowy interfejs
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -417,8 +270,7 @@ void Dirs::DeleteDir(long id)
|
||||||
if( db.DelDirById(id) == Error::ok )
|
if( db.DelDirById(id) == Error::ok )
|
||||||
dir_table.DelById(id);
|
dir_table.DelById(id);
|
||||||
|
|
||||||
if( data.mounts.CurrentMountType() == Mount::thread )
|
db.RemoveThread(id);
|
||||||
db.RemoveThread(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
44
core/dirs.h
44
core/dirs.h
|
@ -19,6 +19,8 @@
|
||||||
#include "dircontainer.h"
|
#include "dircontainer.h"
|
||||||
|
|
||||||
|
|
||||||
|
// we do not support '..' in a path (for simplicity and security reasons)
|
||||||
|
|
||||||
|
|
||||||
class Dirs
|
class Dirs
|
||||||
{
|
{
|
||||||
|
@ -26,41 +28,17 @@ public:
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
void ReadDirs();
|
void ReadDirs();
|
||||||
|
|
||||||
// without any exceptions
|
|
||||||
// these methods return false in a case the path or name (with a specific parent) are invalid
|
|
||||||
// we do not support '..' in a path (for security reason)
|
|
||||||
|
|
||||||
bool IsDir(long id);
|
|
||||||
|
|
||||||
bool GetRootDir(Item ** item);
|
|
||||||
|
|
||||||
bool GetDir(const std::string & path, Item ** item);
|
|
||||||
bool GetDir(const std::string & name, long parent, Item ** item);
|
|
||||||
|
|
||||||
bool GetDirId(const std::string & path, long * id);
|
|
||||||
bool GetDirId(const std::string & name, long parent, long * id);
|
|
||||||
|
|
||||||
//!! ta nie bedzie chyba potrzebna
|
// these methods return false if there is no such a dir
|
||||||
bool GetDirChilds(long parent, std::vector<Item> & childs_table); // only returns dir-children
|
bool IsDir(long dir_id);
|
||||||
|
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_table);
|
||||||
|
bool MakePath(long dir_id, std::string & path);
|
||||||
|
|
||||||
bool GetDirChilds(long parent, std::vector<Item*> & childs_table); // only returns dir-children
|
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
|
||||||
|
|
||||||
bool MakePath(long id, std::string & path);
|
|
||||||
|
|
||||||
|
|
||||||
// with an Error exception
|
// these methods return null if there is no such a dir
|
||||||
// if the path or name are invalid these methods throw an exception
|
|
||||||
Item * GetDirT(const std::string & path);
|
|
||||||
Item * GetDirT(const std::string & name, long parent);
|
|
||||||
long GetDirIdT(const std::string & path);
|
|
||||||
long GetDirIdT(const std::string & name, long parent);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! nowy interfejs
|
|
||||||
|
|
||||||
// returns null if there is no a root dir
|
|
||||||
Item * GetRootDir();
|
Item * GetRootDir();
|
||||||
Item * GetEtcDir();
|
Item * GetEtcDir();
|
||||||
Item * GetDir(const std::string & name, long parent);
|
Item * GetDir(const std::string & name, long parent);
|
||||||
|
@ -68,13 +46,7 @@ public:
|
||||||
Item * GetDir(long id);
|
Item * GetDir(long id);
|
||||||
Item * AddDir(const Item & item);
|
Item * AddDir(const Item & item);
|
||||||
|
|
||||||
|
|
||||||
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
|
|
||||||
|
|
||||||
|
|
||||||
void DeleteDir(long id);
|
void DeleteDir(long id);
|
||||||
|
|
||||||
|
|
||||||
void CheckRootDir();
|
void CheckRootDir();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,14 @@ Log & Log::operator<<(const std::string & s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(const std::string * s)
|
||||||
|
{
|
||||||
|
buffer << *s;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(int s)
|
Log & Log::operator<<(int s)
|
||||||
{
|
{
|
||||||
buffer << s;
|
buffer << s;
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
|
|
||||||
void PutDate(Manipulators m);
|
void PutDate(Manipulators m);
|
||||||
Log & operator<<(const char * s);
|
Log & operator<<(const char * s);
|
||||||
|
Log & operator<<(const std::string * s);
|
||||||
Log & operator<<(const std::string & s);
|
Log & operator<<(const std::string & s);
|
||||||
Log & operator<<(int s);
|
Log & operator<<(int s);
|
||||||
Log & operator<<(long s);
|
Log & operator<<(long s);
|
||||||
|
|
|
@ -75,7 +75,7 @@ Mount Mounts::GetCurrentMountPoint()
|
||||||
|
|
||||||
Mount::Type Mounts::CurrentMountType()
|
Mount::Type Mounts::CurrentMountType()
|
||||||
{
|
{
|
||||||
return current_dir.type;
|
return current_dir.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mounts::CurrentMountIsParam(Mount::Param p)
|
bool Mounts::CurrentMountIsParam(Mount::Param p)
|
||||||
|
|
|
@ -59,17 +59,9 @@ void Request::Clear()
|
||||||
env_http_accept_encoding = &char_empty;
|
env_http_accept_encoding = &char_empty;
|
||||||
|
|
||||||
session = 0;
|
session = 0;
|
||||||
|
|
||||||
result = err404; // !! tutaj moze cos lepszego, cos w stylu 'not implemented'
|
|
||||||
|
|
||||||
// dir = -1;
|
|
||||||
// cur_dir_table.clear();
|
|
||||||
item_table.clear();
|
item_table.clear();
|
||||||
// dir_table2.clear();
|
|
||||||
|
|
||||||
item.Clear();
|
item.Clear();
|
||||||
str.clear();
|
|
||||||
|
|
||||||
dir_table.clear();
|
dir_table.clear();
|
||||||
is_item = false;
|
is_item = false;
|
||||||
pfunction = 0;
|
pfunction = 0;
|
||||||
|
@ -79,35 +71,16 @@ void Request::Clear()
|
||||||
|
|
||||||
is_thread = false;
|
is_thread = false;
|
||||||
thread.Clear();
|
thread.Clear();
|
||||||
|
|
||||||
thread_tab.clear();
|
thread_tab.clear();
|
||||||
|
|
||||||
notify_code = 0;
|
notify_code = 0;
|
||||||
|
|
||||||
browser_msie = false;
|
browser_msie = false;
|
||||||
|
redirect_to.clear();
|
||||||
// should be always empty
|
|
||||||
// this is only for safety
|
|
||||||
//string_empty.clear();
|
|
||||||
|
|
||||||
plugin.Call(CMSLU_REQUEST_CLEAR);
|
plugin.Call(CMSLU_REQUEST_CLEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Request::CopyFirstItem()
|
|
||||||
{
|
|
||||||
if( !request.item_table.empty() )
|
|
||||||
request.item = request.item_table[0];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
request.item.Clear();
|
|
||||||
|
|
||||||
log << log1 << "Request::CopyFirstItem: item_table is empty" << logend;
|
|
||||||
request.result = err_internal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// value can be null
|
// value can be null
|
||||||
|
@ -148,27 +121,21 @@ return true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string & Request::PostVar(const char * var)
|
std::string * Request::PostVar(const char * var)
|
||||||
{
|
{
|
||||||
PostTable::iterator p;
|
PostTable::iterator p = post_table.find(var);
|
||||||
|
|
||||||
p = post_table.find(var);
|
|
||||||
|
|
||||||
if( p == post_table.end() )
|
if( p == post_table.end() )
|
||||||
{
|
return 0;
|
||||||
throw Error(Error::no_postvar);
|
|
||||||
}
|
|
||||||
|
|
||||||
return p->second;
|
return &(p->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
bool Request::PostVar(const char * var, std::string & result)
|
bool Request::PostVar(const char * var, std::string & result)
|
||||||
{
|
{
|
||||||
PostTable::iterator p;
|
PostTable::iterator p = post_table.find(var);
|
||||||
|
|
||||||
p = post_table.find(var);
|
|
||||||
|
|
||||||
if( p == post_table.end() )
|
if( p == post_table.end() )
|
||||||
{
|
{
|
||||||
|
@ -180,7 +147,7 @@ bool Request::PostVar(const char * var, std::string & result)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -333,12 +300,12 @@ void Request::Read()
|
||||||
|
|
||||||
void Request::SendAll()
|
void Request::SendAll()
|
||||||
{
|
{
|
||||||
if( result == redirect )
|
if( !redirect_to.empty() )
|
||||||
{
|
{
|
||||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
|
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
|
||||||
FCGX_FPrintF(out, "Location: %s\r\n", str.c_str());
|
FCGX_FPrintF(out, "Location: %s\r\n", redirect_to.c_str());
|
||||||
|
|
||||||
log << log2 << "Redirect to: " << str << logend;
|
log << log2 << "Redirect to: " << redirect_to << logend;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -355,7 +322,7 @@ void Request::SendAll()
|
||||||
FCGX_PutS("\r\n", out);
|
FCGX_PutS("\r\n", out);
|
||||||
|
|
||||||
|
|
||||||
if( result == redirect )
|
if( !redirect_to.empty() )
|
||||||
// if there is a redirect we do not send a content
|
// if there is a redirect we do not send a content
|
||||||
return;
|
return;
|
||||||
//
|
//
|
||||||
|
|
|
@ -51,7 +51,8 @@ struct Request
|
||||||
CookieTable cookie_table;
|
CookieTable cookie_table;
|
||||||
|
|
||||||
// environment variables
|
// environment variables
|
||||||
// they are not null -- when the server doesn't have such a variable it will be pointing into 'char_empty' which is default '\0'
|
// they are not null -- when the server doesn't have such a variable
|
||||||
|
// it will be pointing into 'char_empty' which is default '\0'
|
||||||
const char * env_request_method;
|
const char * env_request_method;
|
||||||
const char * env_request_uri;
|
const char * env_request_uri;
|
||||||
const char * env_http_cookie;
|
const char * env_http_cookie;
|
||||||
|
@ -68,22 +69,7 @@ struct Request
|
||||||
// is set after calling session_manager.SetSession()
|
// is set after calling session_manager.SetSession()
|
||||||
Session * session;
|
Session * session;
|
||||||
|
|
||||||
|
|
||||||
// 'done_status' is set if 'done' is different than 'nothing'
|
|
||||||
Error done_status; // !! wywalic - jest przeciez w session
|
|
||||||
|
|
||||||
// what to do
|
|
||||||
// !! wywalic?
|
|
||||||
enum Result { err_internal, err404, err_per_denied, show_dir, show_item, show_item_by_id, add_item, edit_item, del_item, del_item_confirm, confirm, redirect, logout } result; // zamienic na to_do
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! nowe skladowe
|
|
||||||
|
|
||||||
// current directory
|
// current directory
|
||||||
// !! zapewnic aby byl minimum jeden katalog (root)
|
|
||||||
|
|
||||||
// !! moze nazwac to poprostu dir?
|
|
||||||
std::vector<Item*> dir_table;
|
std::vector<Item*> dir_table;
|
||||||
|
|
||||||
bool is_item;
|
bool is_item;
|
||||||
|
@ -102,33 +88,17 @@ struct Request
|
||||||
// last notify
|
// last notify
|
||||||
int notify_code;
|
int notify_code;
|
||||||
|
|
||||||
|
|
||||||
// ------------------
|
|
||||||
|
|
||||||
// !! stare skladowe
|
|
||||||
// current directory e.g. /foo/bar
|
|
||||||
//std::vector<Item> cur_dir_table;
|
|
||||||
// id of the last directory (bar) or -1
|
|
||||||
//long dir;
|
|
||||||
|
|
||||||
// ------------------
|
|
||||||
|
|
||||||
// items in the current directory
|
// items in the current directory
|
||||||
// maybe without contents?
|
// maybe without contents?
|
||||||
std::vector<Item> item_table;
|
std::vector<Item> item_table;
|
||||||
|
|
||||||
// directories in the current directory
|
|
||||||
//std::vector<Item> dir_table2;
|
|
||||||
|
|
||||||
// current thread (if exists)
|
// current thread (if exists)
|
||||||
|
|
||||||
bool is_thread;
|
bool is_thread;
|
||||||
Thread thread;
|
Thread thread;
|
||||||
|
|
||||||
std::vector<Thread> thread_tab;
|
std::vector<Thread> thread_tab;
|
||||||
|
|
||||||
// this string is used for many purposes such as redirecting
|
// if not empty means an address for redirecting to
|
||||||
std::string str;
|
std::string redirect_to;
|
||||||
|
|
||||||
// for debugging
|
// for debugging
|
||||||
void PrintGetTable();
|
void PrintGetTable();
|
||||||
|
@ -146,12 +116,8 @@ struct Request
|
||||||
void SetCookie(const char * name, long value);
|
void SetCookie(const char * name, long value);
|
||||||
|
|
||||||
bool IsPostVar(const char * var);
|
bool IsPostVar(const char * var);
|
||||||
std::string & PostVar(const char * var); // with a throw !!! wywalic te wyjatki ztad, niech zwraca pusty string jak nie znajdzie nic, albo referencje na jakis statyczny pusty string
|
std::string * PostVar(const char * var); // it can return null when there is no such a post variable
|
||||||
//bool PostVar(const char * var, std::string & result);
|
bool PostVar(const char * var, std::string & result);
|
||||||
|
|
||||||
// item_table[0] -> item
|
|
||||||
// !! to tez nie bedzie potrzebne
|
|
||||||
void CopyFirstItem();
|
|
||||||
|
|
||||||
|
|
||||||
void ReadEnvVariables();
|
void ReadEnvVariables();
|
||||||
|
@ -187,8 +153,6 @@ private:
|
||||||
// it contains '\0'
|
// it contains '\0'
|
||||||
const char char_empty;
|
const char char_empty;
|
||||||
|
|
||||||
// used when returning a reference to std::string (when the string doesn't exist)
|
|
||||||
const std::string string_empty;
|
|
||||||
|
|
||||||
const char * SetEnvVar(const char * var);
|
const char * SetEnvVar(const char * var);
|
||||||
|
|
||||||
|
|
|
@ -130,8 +130,7 @@ bool RequestController::BaseUrlRedirect()
|
||||||
if( data.base_url_http_host == request.env_http_host )
|
if( data.base_url_http_host == request.env_http_host )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
request.result = Request::redirect;
|
request.redirect_to = data.base_url + request.env_request_uri;
|
||||||
request.str = data.base_url + request.env_request_uri;
|
|
||||||
|
|
||||||
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
|
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue