diff --git a/content/Makefile.dep b/content/Makefile.dep index c7e81e6..0d4b13a 100755 --- a/content/Makefile.dep +++ b/content/Makefile.dep @@ -16,7 +16,8 @@ content.o: ../core/error.h ../core/db.h ../core/group.h content.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h content.o: ../core/dirs.h ../core/users.h ../core/groups.h content.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h -content.o: ../core/mount.h ../core/misc.h +content.o: ../core/mount.h ../core/misc.h ../core/plugin.h ../core/request.h +content.o: ../core/data.h ../core/pluginmsg.h createthread.o: content.h ../core/item.h ../templates/templates.h createthread.o: ../templates/patterncacher.h ../core/thread.h createthread.o: ../core/request.h ../core/requesttypes.h ../core/session.h diff --git a/content/content.h b/content/content.h index 9019f43..9abed65 100755 --- a/content/content.h +++ b/content/content.h @@ -24,7 +24,7 @@ class Content { Templates templates; - + void CheckSpecialFile(); void PrepareUrl(Item & item); diff --git a/content/emacs.cpp b/content/emacs.cpp index e722cae..9fb31a0 100755 --- a/content/emacs.cpp +++ b/content/emacs.cpp @@ -16,6 +16,24 @@ +void Content::CheckSpecialFile() +{ + static std::string fstab = "fstab"; + + Item * etc = data.dirs.GetEtcDir(); + + if( !etc ) + return; + + if( request.item.parent_id != etc->id ) + return; + + if( request.item.url == fstab ) + { + log << log3 << "Content: reloading mount points" << logend; + data.mounts.ReadMounts(request.item.content); + } +} @@ -118,6 +136,7 @@ bool adding = true; else PostFunEmacsEdit(with_url); + CheckSpecialFile(); } catch(const Error & e) { diff --git a/core/Makefile.dep b/core/Makefile.dep index c348532..d8cb6c5 100755 --- a/core/Makefile.dep +++ b/core/Makefile.dep @@ -42,7 +42,7 @@ mounts.o: mounts.h mount.h data.h dirs.h item.h dircontainer.h users.h user.h mounts.o: ugcontainer.h log.h groups.h group.h functions.h function.h mounts.o: lastcontainer.h request.h requesttypes.h session.h done.h error.h mounts.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h -mounts.o: mountparser.h +mounts.o: mountparser.h db.h notify.o: log.h notify.h ../templatesnotify/templatesnotify.h ../core/mount.h notify.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h notify.o: groups.h group.h functions.h function.h lastcontainer.h mounts.h diff --git a/core/dircontainer.cpp b/core/dircontainer.cpp index 0229b55..43c80e0 100755 --- a/core/dircontainer.cpp +++ b/core/dircontainer.cpp @@ -14,6 +14,7 @@ DirContainer::DirContainer() { is_root = false; + is_etc = false; } @@ -27,6 +28,14 @@ return root_iter; } +DirContainer::Iterator DirContainer::GetEtc() +{ + if( !is_etc ) + return table.end(); + +return etc_iter; +} + DirContainer::Iterator DirContainer::Begin() { @@ -51,6 +60,30 @@ bool DirContainer::Empty() } +// looking for '/etc' +// 'root' is found beforehand +void DirContainer::FindSpecialFolders() +{ +static std::string etc = "etc"; + + is_etc = false; + + if( !is_root ) + return; + + DirContainer::ParentIterator i = FindFirstParent(root_iter->id); + + for( ; i!=ParentEnd() ; i = NextParent(i) ) + { + if( i->second->url == etc ) + { + is_etc = true; + etc_iter = i->second; + break; + } + } +} + DirContainer::Iterator DirContainer::PushBack(const Item & item) { diff --git a/core/dircontainer.h b/core/dircontainer.h index c44f2de..ee676ee 100755 --- a/core/dircontainer.h +++ b/core/dircontainer.h @@ -33,6 +33,7 @@ public: DirContainer(); Iterator GetRoot(); + Iterator GetEtc(); Iterator Begin(); Iterator End(); @@ -52,6 +53,7 @@ public: ParentIterator FindFirstParent(long parent); ParentIterator NextParent(ParentIterator pi); + void FindSpecialFolders(); private: @@ -64,6 +66,12 @@ private: // root Iterator root_iter; + // true if there is a etc dir in the table + bool is_etc; + + // etc + Iterator etc_iter; + // indexes TableId table_id; TableParent table_parent; diff --git a/core/dirs.cpp b/core/dirs.cpp index 6e38c61..8fe1ba8 100755 --- a/core/dirs.cpp +++ b/core/dirs.cpp @@ -56,6 +56,7 @@ void Dirs::ReadDirs() db.GetDirs(dir_table); CheckRootDir(); + dir_table.FindSpecialFolders(); } @@ -294,6 +295,17 @@ return &(*root); } +Item * Dirs::GetEtcDir() +{ + DirContainer::Iterator etc = dir_table.GetEtc(); + + if( etc == dir_table.End() ) + return 0; + +return &(*etc); +} + + Item * Dirs::GetDir(const std::string & name, long parent) { DirContainer::ParentIterator i = dir_table.FindFirstParent(parent); diff --git a/core/dirs.h b/core/dirs.h index 8d5c13f..f3325e7 100755 --- a/core/dirs.h +++ b/core/dirs.h @@ -62,10 +62,10 @@ public: // returns null if there is no a root dir Item * GetRootDir(); + Item * GetEtcDir(); Item * GetDir(const std::string & name, long parent); Item * GetDir(const std::string & path); Item * GetDir(long id); - Item * AddDir(const Item & item); diff --git a/core/error.h b/core/error.h index 5e765c5..699563e 100755 --- a/core/error.h +++ b/core/error.h @@ -50,7 +50,7 @@ public: mount_no_param, no_thread, - + empty, unknown = 1000 diff --git a/core/mountparser.cpp b/core/mountparser.cpp index 7fdfa23..bf692d1 100755 --- a/core/mountparser.cpp +++ b/core/mountparser.cpp @@ -133,6 +133,12 @@ void MountParser::ReadMountType() SkipWhite(); ReadWord(temp); + if( temp.empty() ) + { + // an empty line (some white characters only) + err = Error::empty; + } + else if( temp == "cms" ) { mount.type = Mount::cms; @@ -201,6 +207,13 @@ void MountParser::ReadRow(std::map & output) { ReadMountType(); + if( err == Error::empty ) + { + err = Error::ok; + SkipLine(); + return; + } + if( err == Error::ok ) ReadMountPoint(); @@ -208,10 +221,7 @@ void MountParser::ReadRow(std::map & output) ReadMountParams(); if( err == Error::ok ) - { output.insert( std::make_pair(mount.dir_id, mount) ); - } - SkipLine(); } diff --git a/core/mounts.cpp b/core/mounts.cpp index dee5f57..614769a 100755 --- a/core/mounts.cpp +++ b/core/mounts.cpp @@ -12,23 +12,15 @@ #include "request.h" #include "log.h" #include "mountparser.h" +#include "db.h" -void Mounts::ReadMounts() + +// reading from 'mounts' +void Mounts::ReadMounts(const std::string & mounts) { MountParser mp; - - // !! tymczasowo - bedzie odczyt z bazy z /etc/fstab - - std::string temp = - "cms / withheader, withinfo \n" - "thread /news desc, withheader, thread_with_header, thread_with_info, restrictcreatethread(-1) \n" - "thread /forum asc, withheader, withinfo, thread_with_info, restrictcreatethread(3), only_root_can_remove, can_use_emacs_on(4), can_use_mkdir_on(3)"; - - - - - Error err = mp.Parse(temp, mount_table); + Error err = mp.Parse(mounts, mount_table); if( err != Error::ok ) { @@ -39,6 +31,39 @@ void Mounts::ReadMounts() +// reading from /etc/fstab +void Mounts::ReadMounts() +{ + static std::string file = "fstab"; + + Item * etc = data.dirs.GetEtcDir(); + + if( !etc ) + { + log << log1 << "M: there is no /etc directory" << logend; + return; + } + + Item fstab; + Error err = db.GetItem(etc->id, file, fstab); + + if( err == Error::db_no_item ) + { + log << log1 << "M: there is no /etc/fstab file" << logend; + return; + } + + if( err != Error::ok ) + { + log << log1 << "M: cannot read /etc/fstab" << logend; + return; + } + + ReadMounts(fstab.content); +} + + + /* diff --git a/core/mounts.h b/core/mounts.h index 9a6a8df..5cfbf84 100755 --- a/core/mounts.h +++ b/core/mounts.h @@ -13,6 +13,7 @@ #include +#include #include "mount.h" @@ -21,6 +22,7 @@ class Mounts { public: + void ReadMounts(const std::string & mounts); void ReadMounts(); void CalculateCurrentMountType(); diff --git a/core/sessionmanager.cpp b/core/sessionmanager.cpp index 4d28f4a..615cb06 100755 --- a/core/sessionmanager.cpp +++ b/core/sessionmanager.cpp @@ -105,7 +105,7 @@ int attempts = 100; void SessionManager::SetSession() { CookieTable::iterator i = request.cookie_table.find(data.http_session_id_name); - + if( i == request.cookie_table.end() ) { CreateSession();