refactoring
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@523 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
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)
|
||||
{
|
||||
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)
|
||||
@@ -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)
|
||||
{
|
||||
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 )
|
||||
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"
|
||||
|
||||
|
||||
// we do not support '..' in a path (for simplicity and security reasons)
|
||||
|
||||
|
||||
class Dirs
|
||||
{
|
||||
@@ -26,41 +28,17 @@ public:
|
||||
|
||||
void Clear();
|
||||
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
|
||||
bool GetDirChilds(long parent, std::vector<Item> & childs_table); // only returns dir-children
|
||||
// these methods return false if there is no such a dir
|
||||
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
|
||||
|
||||
bool MakePath(long id, std::string & path);
|
||||
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
|
||||
|
||||
|
||||
// with an Error exception
|
||||
// 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
|
||||
// these methods return null if there is no such a dir
|
||||
Item * GetRootDir();
|
||||
Item * GetEtcDir();
|
||||
Item * GetDir(const std::string & name, long parent);
|
||||
@@ -68,13 +46,7 @@ public:
|
||||
Item * GetDir(long id);
|
||||
Item * AddDir(const Item & item);
|
||||
|
||||
|
||||
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
|
||||
|
||||
|
||||
void DeleteDir(long id);
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
buffer << s;
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
|
||||
void PutDate(Manipulators m);
|
||||
Log & operator<<(const char * s);
|
||||
Log & operator<<(const std::string * s);
|
||||
Log & operator<<(const std::string & s);
|
||||
Log & operator<<(int s);
|
||||
Log & operator<<(long s);
|
||||
|
||||
@@ -75,7 +75,7 @@ Mount Mounts::GetCurrentMountPoint()
|
||||
|
||||
Mount::Type Mounts::CurrentMountType()
|
||||
{
|
||||
return current_dir.type;
|
||||
return current_dir.type;
|
||||
}
|
||||
|
||||
bool Mounts::CurrentMountIsParam(Mount::Param p)
|
||||
|
||||
@@ -59,17 +59,9 @@ void Request::Clear()
|
||||
env_http_accept_encoding = &char_empty;
|
||||
|
||||
session = 0;
|
||||
|
||||
result = err404; // !! tutaj moze cos lepszego, cos w stylu 'not implemented'
|
||||
|
||||
// dir = -1;
|
||||
// cur_dir_table.clear();
|
||||
item_table.clear();
|
||||
// dir_table2.clear();
|
||||
|
||||
item.Clear();
|
||||
str.clear();
|
||||
|
||||
dir_table.clear();
|
||||
is_item = false;
|
||||
pfunction = 0;
|
||||
@@ -79,35 +71,16 @@ void Request::Clear()
|
||||
|
||||
is_thread = false;
|
||||
thread.Clear();
|
||||
|
||||
thread_tab.clear();
|
||||
|
||||
notify_code = 0;
|
||||
|
||||
browser_msie = false;
|
||||
|
||||
// should be always empty
|
||||
// this is only for safety
|
||||
//string_empty.clear();
|
||||
redirect_to.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
|
||||
@@ -148,27 +121,21 @@ return true;
|
||||
|
||||
|
||||
|
||||
std::string & Request::PostVar(const char * var)
|
||||
std::string * Request::PostVar(const char * var)
|
||||
{
|
||||
PostTable::iterator p;
|
||||
|
||||
p = post_table.find(var);
|
||||
PostTable::iterator p = post_table.find(var);
|
||||
|
||||
if( p == post_table.end() )
|
||||
{
|
||||
throw Error(Error::no_postvar);
|
||||
}
|
||||
return 0;
|
||||
|
||||
return p->second;
|
||||
return &(p->second);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
bool Request::PostVar(const char * var, std::string & result)
|
||||
{
|
||||
PostTable::iterator p;
|
||||
|
||||
p = post_table.find(var);
|
||||
PostTable::iterator p = post_table.find(var);
|
||||
|
||||
if( p == post_table.end() )
|
||||
{
|
||||
@@ -180,7 +147,7 @@ bool Request::PostVar(const char * var, std::string & result)
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -333,12 +300,12 @@ void Request::Read()
|
||||
|
||||
void Request::SendAll()
|
||||
{
|
||||
if( result == redirect )
|
||||
if( !redirect_to.empty() )
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -355,7 +322,7 @@ void Request::SendAll()
|
||||
FCGX_PutS("\r\n", out);
|
||||
|
||||
|
||||
if( result == redirect )
|
||||
if( !redirect_to.empty() )
|
||||
// if there is a redirect we do not send a content
|
||||
return;
|
||||
//
|
||||
|
||||
@@ -51,7 +51,8 @@ struct Request
|
||||
CookieTable cookie_table;
|
||||
|
||||
// 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_uri;
|
||||
const char * env_http_cookie;
|
||||
@@ -68,22 +69,7 @@ struct Request
|
||||
// is set after calling session_manager.SetSession()
|
||||
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
|
||||
// !! zapewnic aby byl minimum jeden katalog (root)
|
||||
|
||||
// !! moze nazwac to poprostu dir?
|
||||
std::vector<Item*> dir_table;
|
||||
|
||||
bool is_item;
|
||||
@@ -102,33 +88,17 @@ struct Request
|
||||
// last notify
|
||||
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
|
||||
// maybe without contents?
|
||||
std::vector<Item> item_table;
|
||||
|
||||
// directories in the current directory
|
||||
//std::vector<Item> dir_table2;
|
||||
|
||||
// current thread (if exists)
|
||||
|
||||
bool is_thread;
|
||||
Thread thread;
|
||||
|
||||
std::vector<Thread> thread_tab;
|
||||
|
||||
// this string is used for many purposes such as redirecting
|
||||
std::string str;
|
||||
// if not empty means an address for redirecting to
|
||||
std::string redirect_to;
|
||||
|
||||
// for debugging
|
||||
void PrintGetTable();
|
||||
@@ -146,12 +116,8 @@ struct Request
|
||||
void SetCookie(const char * name, long value);
|
||||
|
||||
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
|
||||
//bool PostVar(const char * var, std::string & result);
|
||||
|
||||
// item_table[0] -> item
|
||||
// !! to tez nie bedzie potrzebne
|
||||
void CopyFirstItem();
|
||||
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);
|
||||
|
||||
|
||||
void ReadEnvVariables();
|
||||
@@ -187,8 +153,6 @@ private:
|
||||
// it contains '\0'
|
||||
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);
|
||||
|
||||
|
||||
@@ -130,8 +130,7 @@ bool RequestController::BaseUrlRedirect()
|
||||
if( data.base_url_http_host == request.env_http_host )
|
||||
return false;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url + request.env_request_uri;
|
||||
request.redirect_to = data.base_url + request.env_request_uri;
|
||||
|
||||
log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user