2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief Config internal header */
17 #ifndef IH_SENF_Scheduler_Console_Config_
18 #define IH_SENF_Scheduler_Console_Config_ 1
21 #include <boost/noncopyable.hpp>
22 #include <boost/intrusive_ptr.hpp>
23 #include "Executor.hh"
24 #include <senf/Utils/intrusive_refcount.hh>
25 #include <senf/Utils/DiscardStream.hh>
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 /** \brief Internal: Executor wrapper implementing restricted execution
35 A RestrictedExecutor will only process commands which a re children of a given node. It does
36 \e not follow any links.
38 class RestrictedExecutor
42 typedef void result_type;
44 //-/////////////////////////////////////////////////////////////////////////////////////////
45 //\/name Structors and default members
48 RestrictedExecutor(DirectoryNode & root = senf::console::root());
51 //-/////////////////////////////////////////////////////////////////////////////////////////
53 void execute(std::ostream & output, ParseCommandInfo const & command);
55 /**< Output will be written to \a output.
56 Same as operator()(). */
58 void operator()(std::ostream & output, ParseCommandInfo const & command);
60 /**< Output will be written to \a output.
63 GenericNode & getNode(ParseCommandInfo const & command);
65 bool complete() const; ///< \c true, if all nodes have been parsed
66 bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
67 void reset(); ///< Reset node parse info state
68 /**< After a call to reset(), all information about already
69 parsed nodes is cleared. Calling parse() will parse the
70 complete config file again. */
72 DirectoryNode & root() const;
73 void chroot(DirectoryNode & node);
75 std::ostream & stream();
82 void policyCallback(DirectoryNode & dir, std::string const & item);
83 void insertParsedNode(DirectoryNode & node);
85 typedef std::vector<DirectoryNode::weak_ptr> ParsedNodes;
88 ParsedNodes parsedNodes_;
89 DirectoryNode::ptr restrict_;
90 DiscardStream stream_;
92 friend class RestrictGuard;
95 /** \brief Internal: Set restricted node of a RestrictedExecutor
97 A RestrictGuard will set the node to which to restrict. It will automatically reset the node
100 class RestrictedExecutor::RestrictGuard
103 //-/////////////////////////////////////////////////////////////////////////////////////////
104 //\/name Structors and default members
107 explicit RestrictGuard(RestrictedExecutor & executor);
108 RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict);
112 //-/////////////////////////////////////////////////////////////////////////////////////////
117 RestrictedExecutor & executor_;
121 /** \brief Internal: ConfigSource base class
123 All configuration sources derive from ConfigSource. A ConigSource somehow reads
124 configuration commands and passes them to a RestrictedExecutor.
127 : public senf::intrusive_refcount
130 typedef boost::intrusive_ptr<ConfigSource> ptr;
131 virtual ~ConfigSource();
133 void parse(RestrictedExecutor & executor);
138 virtual void v_parse(RestrictedExecutor & executor) = 0;
143 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 // comment-column: 40
151 // c-file-style: "senf"
152 // indent-tabs-mode: nil
153 // ispell-local-dictionary: "american"
154 // compile-command: "scons -u test"