// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \file \brief Config internal header */ #ifndef IH_SENF_Scheduler_Console_Config_ #define IH_SENF_Scheduler_Console_Config_ 1 // Custom includes #include #include #include "Executor.hh" #include #include //-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { namespace console { namespace detail { /** \brief Internal: Executor wrapper implementing restricted execution A RestrictedExecutor will only process commands which a re children of a given node. It does \e not follow any links. */ class RestrictedExecutor : boost::noncopyable { public: typedef void result_type; //-///////////////////////////////////////////////////////////////////////////////////////// //\/name Structors and default members //\{ RestrictedExecutor(DirectoryNode & root = senf::console::root()); //\} //-///////////////////////////////////////////////////////////////////////////////////////// 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. Same as execute(). */ GenericNode & getNode(ParseCommandInfo const & command); bool complete() const; ///< \c true, if all nodes have been parsed bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed void reset(); ///< Reset node parse info state /**< After a call to reset(), all information about already parsed nodes is cleared. Calling parse() will parse the complete config file again. */ DirectoryNode & root() const; void chroot(DirectoryNode & node); std::ostream & stream(); class RestrictGuard; protected: private: void policyCallback(DirectoryNode & dir, std::string const & item); void insertParsedNode(DirectoryNode & node); typedef std::vector ParsedNodes; Executor executor_; ParsedNodes parsedNodes_; DirectoryNode::ptr restrict_; DiscardStream stream_; friend class RestrictGuard; }; /** \brief Internal: Set restricted node of a RestrictedExecutor A RestrictGuard will set the node to which to restrict. It will automatically reset the node in it's destructor. */ class RestrictedExecutor::RestrictGuard { public: //-///////////////////////////////////////////////////////////////////////////////////////// //\/name Structors and default members //\{ explicit RestrictGuard(RestrictedExecutor & executor); RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict); ~RestrictGuard(); //\} //-///////////////////////////////////////////////////////////////////////////////////////// protected: private: RestrictedExecutor & executor_; }; /** \brief Internal: ConfigSource base class All configuration sources derive from ConfigSource. A ConigSource somehow reads configuration commands and passes them to a RestrictedExecutor. */ class ConfigSource : public senf::intrusive_refcount { public: typedef boost::intrusive_ptr ptr; virtual ~ConfigSource(); void parse(RestrictedExecutor & executor); protected: private: virtual void v_parse(RestrictedExecutor & executor) = 0; }; }}} //-///////////////////////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: