diff --git a/content/Makefile b/content/Makefile index c10cc4b..e1b0940 100755 --- a/content/Makefile +++ b/content/Makefile @@ -1,4 +1,4 @@ -o = content.o privileges.o emacs.o login.o rm.o cat.o logout.o ls.o node.o +o = content.o privileges.o emacs.o login.o rm.o cat.o logout.o ls.o node.o mkdir.o all: content.a diff --git a/content/Makefile.dep b/content/Makefile.dep index c5744b6..a657ac2 100755 --- a/content/Makefile.dep +++ b/content/Makefile.dep @@ -70,6 +70,18 @@ ls.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h ls.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h ls.o: ../core/log.h ../core/misc.h ../core/function.h ls.o: ../core/functionparser.h ../core/request.h ../core/data.h +mkdir.o: content.h ../templates/templates.h ../../ezc/src/ezc.h +mkdir.o: ../core/data.h ../core/misc.h ../core/log.h ../core/item.h +mkdir.o: ../core/error.h ../core/dirs.h ../core/db.h ../core/dircontainer.h +mkdir.o: ../core/user.h ../core/group.h ../core/ugcontainer.h ../core/users.h +mkdir.o: ../core/groups.h ../core/functions.h ../core/function.h +mkdir.o: ../core/request.h ../core/requesttypes.h ../core/session.h +mkdir.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h +mkdir.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h +mkdir.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h +mkdir.o: ../core/users.h ../core/groups.h ../core/log.h ../core/misc.h +mkdir.o: ../core/function.h ../core/functionparser.h ../core/request.h +mkdir.o: ../core/data.h node.o: content.h ../templates/templates.h ../../ezc/src/ezc.h ../core/data.h node.o: ../core/misc.h ../core/log.h ../core/item.h ../core/error.h node.o: ../core/dirs.h ../core/db.h ../core/dircontainer.h ../core/user.h diff --git a/content/content.cpp b/content/content.cpp index 7bb148b..9b394cf 100755 --- a/content/content.cpp +++ b/content/content.cpp @@ -99,6 +99,9 @@ void Content::MakeStandardFunction() if( request.pfunction->code == Function::emacs ) FunEmacs(); else + if( request.pfunction->code == Function::mkdir ) + FunMkdir(); + else if( request.pfunction->code == Function::privileges ) FunPrivileges(); else @@ -129,6 +132,10 @@ void Content::MakePost() PostFunEmacs(); break; + case Function::mkdir: + PostFunMkdir(); + break; + case Function::privileges: PostFunPrivileges(); break; diff --git a/content/content.h b/content/content.h index 36ffc14..2ba751b 100755 --- a/content/content.h +++ b/content/content.h @@ -50,11 +50,13 @@ class Content void FunPrivileges(); void FunRm(); void FunNode(); + void FunMkdir(); void PostFunLogin(); void PostFunEmacsAdd(); void PostFunEmacsEdit(bool with_url); void PostFunEmacs(); + void PostFunMkdir(); void PostFunPrivileges(); void RedirectTo(const Item & item); diff --git a/core/data.cpp b/core/data.cpp index bf145e5..01eaaf4 100755 --- a/core/data.cpp +++ b/core/data.cpp @@ -36,12 +36,5 @@ void Data::SetHttpHost() if( strncmp(base_url.c_str(), "https://", 8) == 0 ) base_url_http_host = base_url.substr(8); else - base_url_http_host.clear(); - - if( base_url_http_host.empty() ) - return; - - // removing the last slash (if it is present) - if( base_url_http_host[ base_url_http_host.size() - 1 ] == '/' ) - base_url_http_host.erase( base_url_http_host.end() - 1 ); + base_url_http_host.clear(); // if empty the RequestController::BaseUrlRedirect() returns false and no redirecting will be done } diff --git a/core/db.cpp b/core/db.cpp index e1f311b..bee1805 100755 --- a/core/db.cpp +++ b/core/db.cpp @@ -401,13 +401,14 @@ Error Db::AddItemIntoItem(Item & item) { AssertConnection(); std::ostringstream query; - query << "insert into core.item (user_id, group_id, privileges, type, parent_id, content_id, url) values ("; + query << "insert into core.item (user_id, group_id, privileges, type, parent_id, content_id, default_item, url) values ("; query << '\'' << item.user_id << "', "; query << '\'' << item.group_id << "', "; query << '\'' << item.privileges << "', "; query << '\'' << static_cast(item.type) << "', "; query << '\'' << item.parent_id << "', "; query << '\'' << item.content_id << "', "; + query << '\'' << item.default_item << "', "; url_without_id = AddItemCreateUrlSubject(item); @@ -473,8 +474,13 @@ return result; Error Db::AddItem(Item & item) { - Error result = AddItemIntoContent(item); + Error result = Error::ok; + if( item.type == Item::file ) + result = AddItemIntoContent(item); + else + item.content_id = -1; + if( result == Error::ok ) result = AddItemIntoItem(item); diff --git a/core/dircontainer.cpp b/core/dircontainer.cpp index 13684ed..3f373a3 100755 --- a/core/dircontainer.cpp +++ b/core/dircontainer.cpp @@ -72,7 +72,7 @@ bool rebuild_indexes = false; } table.push_back(item); - log << log2 << "DirCont: added item, id: " << item.id << ", parent_id: " << item.parent_id << logend; + log << log2 << "DirCont: added dir, url: " << item.url << ", id: " << item.id << ", parent_id: " << item.parent_id << logend; if( rebuild_indexes ) @@ -113,7 +113,7 @@ void DirContainer::AddIndexes(Iterator item) table_id.insert( std::make_pair(item->id, item) ); table_parent.insert( std::make_pair(item->parent_id, item) ); - log << log2 << "DirCont: added indexes to item, id: " << item->id << ", parent_id: " << item->parent_id << logend; + log << log2 << "DirCont: added indexes to dir, id: " << item->id << ", parent_id: " << item->parent_id << logend; } diff --git a/core/dirs.cpp b/core/dirs.cpp index 45f4c7e..d38c845 100755 --- a/core/dirs.cpp +++ b/core/dirs.cpp @@ -335,3 +335,11 @@ Item * Dirs::GetDir(long id) return &(*i); } + + + +void Dirs::AddDir(const Item & item) +{ + dir_table.PushBack(item); +} + diff --git a/core/dirs.h b/core/dirs.h index c8cb4f9..8275565 100755 --- a/core/dirs.h +++ b/core/dirs.h @@ -81,7 +81,7 @@ public: Item * GetDir(const std::string & path); Item * GetDir(long id); - + void AddDir(const Item & item); }; diff --git a/core/done.h b/core/done.h index 928b39d..8653e0a 100755 --- a/core/done.h +++ b/core/done.h @@ -24,6 +24,7 @@ public: edited_item, deleted_item, privileged_item, + added_dir, loggedout }; diff --git a/core/function.h b/core/function.h index ddafd77..1ab6155 100755 --- a/core/function.h +++ b/core/function.h @@ -29,6 +29,7 @@ public: cat, node, emacs, + mkdir, privileges, rm, login, diff --git a/core/functions.cpp b/core/functions.cpp index c006f5d..cdc5a52 100755 --- a/core/functions.cpp +++ b/core/functions.cpp @@ -51,6 +51,10 @@ void Functions::ReadFunctions() f.item.url = "edytuj"; table.insert( std::make_pair(f.item.url, f) ); + f.code = Function::mkdir; + f.item.url = "mkdir"; + table.insert( std::make_pair(f.item.url, f) ); + f.code = Function::privileges; f.item.url = "uprawnienia"; table.insert( std::make_pair(f.item.url, f) ); diff --git a/core/item.h b/core/item.h index fbfd295..11b393e 100755 --- a/core/item.h +++ b/core/item.h @@ -52,6 +52,7 @@ long default_item; // used by the database +// !! moze da sie w ogole z tego zrezygnowac? long content_id; diff --git a/core/requestcontroller.cpp b/core/requestcontroller.cpp index abbb05b..3eecda4 100755 --- a/core/requestcontroller.cpp +++ b/core/requestcontroller.cpp @@ -113,15 +113,16 @@ return true; bool RequestController::BaseUrlRedirect() { - if( request.env_request_uri[0] == 0 ) + if( data.base_url_http_host.empty() ) return false; 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 + 1); // +1 means skipping the first slash from env_request_uri + request.str = data.base_url + request.env_request_uri; + log << log3 << "RC: BaseUrlRedirect from: " << request.env_http_host << logend; return true; } diff --git a/core/sessionmanager.cpp b/core/sessionmanager.cpp index 3a18cbe..c4ae470 100755 --- a/core/sessionmanager.cpp +++ b/core/sessionmanager.cpp @@ -95,7 +95,7 @@ int attempts = 100; request.session = const_cast( &(*res.first) ); request.SetCookie(data.http_session_id_name.c_str(), request.session->id); - log << log1 << "created a new session: " << s.id << logend; + log << log2 << "SM: created a new session: " << s.id << logend; return; } @@ -104,7 +104,7 @@ int attempts = 100; // there is a problem with generating a new session id // we do not set a session cookie CreateTemporarySession(); - log << log1 << "cannot create a session id (temporary used: with id 0)" << logend; + log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend; } @@ -127,7 +127,7 @@ void SessionManager::SetSession() { // that session is in the table request.session = const_cast( &(*s) ); - log << log1 << "session: " << s->id << logend; + log << log1 << "SM: session: " << s->id << logend; } else { diff --git a/templates/done.cpp b/templates/done.cpp index c5a7647..121bf70 100755 --- a/templates/done.cpp +++ b/templates/done.cpp @@ -66,6 +66,15 @@ void done_loggedout(Info & i) + +void done_added_dir(Info & i) +{ + i.result = request.session->done == Done::added_dir; +} + + + + } // namespace TemplatesFunctions diff --git a/templates/templates.cpp b/templates/templates.cpp index b978f15..0822dce 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -18,6 +18,7 @@ Ezc::Pattern pat_index; Ezc::Pattern pat_fun_cat; Ezc::Pattern pat_fun_ls; Ezc::Pattern pat_fun_emacs; +Ezc::Pattern pat_fun_mkdir; Ezc::Pattern pat_fun_privileges; Ezc::Pattern pat_fun_rm; Ezc::Pattern pat_err_item_required; @@ -75,6 +76,10 @@ Ezc::Pattern * p = 0; p = &pat_fun_emacs; break; + case Function::mkdir: + p = &pat_fun_mkdir; + break; + case Function::privileges: p = &pat_fun_privileges; break; @@ -245,7 +250,8 @@ void Templates::CreateFunctions() functions.Insert("done_deleted_item", done_deleted_item); functions.Insert("done_privileged_item", done_privileged_item); functions.Insert("done_loggedout", done_loggedout); - + functions.Insert("done_added_dir", done_added_dir); + /* others @@ -289,6 +295,9 @@ void Templates::Read() pat_fun_emacs.Directory(data.templates); pat_fun_emacs.ParseFile("fun_emacs.html"); + pat_fun_mkdir.Directory(data.templates); + pat_fun_mkdir.ParseFile("fun_mkdir.html"); + pat_fun_privileges.Directory(data.templates); pat_fun_privileges.ParseFile("fun_privileges.html"); diff --git a/templates/templates.h b/templates/templates.h index 9b8f9a3..b8dc444 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -133,12 +133,13 @@ namespace TemplatesFunctions void done_edited_item(Info & i); void done_deleted_item(Info & i); void done_privileged_item(Info & i); + + void done_added_dir(Info & i); + void done_loggedout(Info & i); - - } // namespace TemplatesFunctions