00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Scheduler_Console_Executor_
00027 #define HH_SENF_Scheduler_Console_Executor_ 1
00028
00029
00030 #include <boost/utility.hpp>
00031 #include "Parse.hh"
00032 #include <senf/Utils/Logger/SenfLog.hh>
00033 #include "Node.hh"
00034
00035
00036
00037
00038 namespace senf {
00039 namespace console {
00040
00057 class Executor
00058 : boost::noncopyable
00059 {
00060 SENF_LOG_CLASS_AREA();
00061 SENF_LOG_DEFAULT_LEVEL( senf::log::VERBOSE );
00062 public:
00063
00064
00065
00067 struct ExitException {};
00068
00070 typedef boost::function<void (DirectoryNode &,std::string const &)> SecurityPolicy;
00071
00073 struct IgnoreCommandException {};
00074
00075 typedef void result_type;
00076
00077
00078
00079
00080
00081 Executor();
00082
00083
00084
00085
00086 void execute(std::ostream & output, ParseCommandInfo const & command);
00088
00091 void operator()(std::ostream & output, ParseCommandInfo const & command);
00093
00095 GenericNode & getNode(ParseCommandInfo const & command);
00096 DirectoryNode & cwd() const;
00097 void cwd(DirectoryNode & dir);
00098 std::string cwdPath() const;
00099 bool skipping() const;
00100
00101 bool autocd() const;
00102
00106 Executor & autocd(bool v);
00107
00109 bool autocomplete() const;
00110
00115 Executor & autocomplete(bool v);
00116
00119 DirectoryNode & chroot() const;
00120
00124 Executor & chroot(DirectoryNode & node);
00125
00130 Executor & policy(SecurityPolicy policy = SecurityPolicy());
00131
00134 protected:
00135
00136 private:
00137 typedef std::vector<DirectoryNode::weak_ptr> Path;
00138
00139 void exec(std::ostream & output, ParseCommandInfo const & command);
00140
00141 void cd(ParseCommandInfo::TokensRange dir);
00142 void ls(std::ostream & output, ParseCommandInfo::TokensRange dir);
00143 void ll(std::ostream & output, ParseCommandInfo::TokensRange dir);
00144 void lr(std::ostream & output, ParseCommandInfo::TokensRange dir);
00145 void pushd(ParseCommandInfo::TokensRange dir);
00146 void popd();
00147 void exit();
00148 void help(std::ostream & output, ParseCommandInfo::TokensRange path);
00149
00150 GenericNode & traverseNode(ParseCommandInfo::TokensRange const & path);
00151 void traverseDirectory(ParseCommandInfo::TokensRange const & path,
00152 Path & dir);
00153 std::string complete(DirectoryNode & dir, std::string const & name);
00154
00155 struct InvalidPathException {
00156 std::string path;
00157 InvalidPathException() : path() {}
00158 InvalidPathException(std::string path_) : path(path_) {}
00159
00160 };
00161 struct InvalidDirectoryException {
00162 std::string path;
00163 InvalidDirectoryException() : path() {}
00164 InvalidDirectoryException(std::string path_) : path(path_) {}
00165 };
00166 struct InvalidCommandException {};
00167
00168 DirectoryNode::ptr root_;
00169 SecurityPolicy policy_;
00170 mutable Path cwd_;
00171 Path oldCwd_;
00172
00173 typedef std::vector<Path> DirStack;
00174 DirStack dirstack_;
00175
00176 bool autocd_;
00177 bool autocomplete_;
00178 };
00179
00180 void senf_console_format_value(DirectoryNode::ptr value, std::ostream & os);
00181
00182 }}
00183
00184
00185 #include "Executor.cci"
00186
00187
00188 #endif
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199