X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FExecutor.hh;h=e1265903b38655bd3f273eb0efd7d2e467174942;hb=456ee576285b76aa46240f8001f426757810dcc1;hp=d089083113176b545e54b723f1d97ea88ea801e1;hpb=d0776a27ffd63ab51b4e3419a8a6f87d11e60594;p=senf.git diff --git a/Console/Executor.hh b/Console/Executor.hh index d089083..e126590 100644 --- a/Console/Executor.hh +++ b/Console/Executor.hh @@ -58,16 +58,20 @@ namespace console { : boost::noncopyable { SENF_LOG_CLASS_AREA(); - SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE ); + SENF_LOG_DEFAULT_LEVEL( senf::log::VERBOSE ); public: /////////////////////////////////////////////////////////////////////////// // Types - typedef boost::iterator_range< ParseCommandInfo::argument_iterator> Arguments; - /// Thrown by built-in 'exit' command struct ExitException {}; + /// Executor policy function + typedef boost::function SecurityPolicy; + + /// Thrown by the SecurityPolicy to silently ignore a command + struct IgnoreCommandException {}; + /////////////////////////////////////////////////////////////////////////// //\/name Structors and default members ///\{ @@ -77,26 +81,72 @@ namespace console { ///\} /////////////////////////////////////////////////////////////////////////// - void operator()(ParseCommandInfo const & command, std::ostream & output); + void execute(std::ostream & output, ParseCommandInfo const & command); + ///< Execute command + /**< Output will be written to \a output. + Same as operator()(). */ + + void operator()(std::ostream & output, ParseCommandInfo const & command); ///< Execute command - /**< Output will be written to \a output. */ + /**< Output will be written to \a output. + Same as execute(). */ DirectoryNode & cwd() const; ///< Current working directory + bool autocd() const; ///< Get current autocd status + /**< if autocd is enabled, specifying a directory name as + command will cd to that directory. Disabled by + default (but enabled automatically by the interactive + console). */ + Executor & autocd(bool v); ///< Set autocd status + /**< \see autocd() */ + + bool autocomplete() const; ///< Get current autocomplete status + /**< if autocomplete is enabled, path components which can + be uniquely completed will be completed + automatically. Disabled by default (but enabled + automatically by the interactive console) void + autocomplete(bool v). */ + + Executor & autocomplete(bool v); ///< Set autocomplete status + /**< \see autocomplete() */ + + DirectoryNode & chroot() const; ///< Get root node + /**< The root node defaults to senf::console::root(). If + changed, all path references are relative to this node + and objects outside that tree cannot be accessed. */ + Executor & chroot(DirectoryNode & node); ///< chroot into given directory + /**< After this call, all path's are interpreted relative to + \a node and only nodes in the tree rooted at \a node + are accessible via the executor. This value defaults to + senf::console::root(). */ + + Executor & policy(SecurityPolicy policy); ///< Set security policy + /**< The security policy is called before traversing a node + to validate that access. */ + protected: private: - GenericNode & traverseNode(ParseCommandInfo::argument_value_type const & path); - DirectoryNode & traverseDirectory(ParseCommandInfo::argument_value_type const & path); - CommandNode & traverseCommand(ParseCommandInfo::CommandPathRange const & path); + GenericNode & traverseNode(ParseCommandInfo::TokensRange const & path); + GenericNode & traverseCommand(ParseCommandInfo::CommandPathRange const & path); + DirectoryNode & traverseDirectory(ParseCommandInfo::TokensRange const & path); + + template + GenericNode & traverse(DirectoryNode & dir, ForwardRange const & range); struct InvalidPathException {}; struct InvalidDirectoryException {}; struct InvalidCommandException {}; - + + DirectoryNode::ptr root_; + SecurityPolicy policy_; DirectoryNode::weak_ptr cwd_; DirectoryNode::weak_ptr oldCwd_; typedef std::vector DirStack; DirStack dirstack_; + + bool autocd_; + bool autocomplete_; }; @@ -104,7 +154,7 @@ namespace console { ///////////////////////////////hh.e//////////////////////////////////////// #include "Executor.cci" -//#include "Executor.ct" +#include "Executor.ct" //#include "Executor.cti" #endif