4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Config non-inline non-template implementation */
30 #include <senf/Utils/membind.hh>
32 //#include "Config.mpp"
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37 // senf::console::detail::RestrictedExecutor
39 prefix_ senf::console::detail::RestrictedExecutor::RestrictedExecutor(DirectoryNode & root)
43 .policy(senf::membind(&RestrictedExecutor::policyCallback, this));
47 senf::console::detail::RestrictedExecutor::execute(std::ostream & output,
48 ParseCommandInfo const & command)
50 executor_.execute(output, command);
54 senf::console::detail::RestrictedExecutor::operator()(std::ostream & output,
55 ParseCommandInfo const & command)
57 execute(output, command);
60 prefix_ senf::console::GenericNode &
61 senf::console::detail::RestrictedExecutor::getNode(ParseCommandInfo const & command)
63 return executor_.getNode(command);
66 prefix_ bool senf::console::detail::RestrictedExecutor::parsed(GenericNode & node)
69 ParsedNodes::const_iterator i (parsedNodes_.begin());
70 ParsedNodes::const_iterator const i_end (parsedNodes_.end());
71 for (; i != i_end; ++i)
72 if ( ! i->expired() && node.isChildOf(*(i->lock())) )
77 prefix_ void senf::console::detail::RestrictedExecutor::policyCallback(DirectoryNode & dir,
78 std::string const & name)
80 if (dir.hasChild(name)) {
81 GenericNode & item (dir.get(name));
82 if (restrict_ && ! item.isChildOf(*restrict_) && ! item.isDirectory())
83 throw Executor::IgnoreCommandException();
85 throw Executor::IgnoreCommandException();
87 else if (restrict_ && ! dir.isChildOf(*restrict_))
88 throw Executor::IgnoreCommandException();
94 RemoveNodesFn(senf::console::DirectoryNode::ptr newNode) : newNode_ (newNode) {}
96 bool operator()(senf::console::DirectoryNode::weak_ptr node) const
97 { return node.expired() || node.lock()->isChildOf(*newNode_); }
99 senf::console::DirectoryNode::ptr newNode_;
104 senf::console::detail::RestrictedExecutor::insertParsedNode(DirectoryNode & node)
107 std::remove_if(parsedNodes_.begin(), parsedNodes_.end(), RemoveNodesFn(node.thisptr())),
109 parsedNodes_.push_back(node.thisptr());
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
113 // senf::console::ConfigBundle
115 prefix_ void senf::console::ConfigBundle::parse()
117 detail::RestrictedExecutor::RestrictGuard guard (executor_);
121 prefix_ void senf::console::ConfigBundle::parse(DirectoryNode & restrict)
123 detail::RestrictedExecutor::RestrictGuard guard (executor_, restrict);
127 prefix_ void senf::console::ConfigBundle::parseInternal()
129 // It is valid to add additional sources at the end while parsing ...
130 for (Sources::const_iterator i (sources_.begin()); i != sources_.end(); ++i)
131 (*i)->parse(executor_);
134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 // senf::console::detail::RestrictedExecutor::RestrictGuard
137 prefix_ senf::console::detail::RestrictedExecutor::RestrictGuard::
138 RestrictGuard(RestrictedExecutor & executor)
139 : executor_ (executor)
141 // This MUST BE root() not chroot() since restriction does NOT follow symlinks.
142 // Therefore, if chroot() is a directory of symlinks, restricting to it will
144 executor_.restrict_ = senf::console::root().thisptr();
147 prefix_ senf::console::detail::RestrictedExecutor::RestrictGuard::
148 RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict)
149 : executor_ (executor)
151 executor_.restrict_ = restrict.thisptr();
154 prefix_ senf::console::detail::RestrictedExecutor::RestrictGuard::~RestrictGuard()
156 if (! std::uncaught_exception())
157 executor_.insertParsedNode( *executor_.restrict_ );
158 executor_.restrict_ = senf::console::root().thisptr();
161 //-/////////////////////////////////////////////////////////////////////////////////////////////////
162 // senf::console::detail::ConfigSource
164 prefix_ senf::console::detail::ConfigSource::~ConfigSource()
167 //-/////////////////////////////////////////////////////////////////////////////////////////////////
169 //#include "Config.mpp"
175 // comment-column: 40
176 // c-file-style: "senf"
177 // indent-tabs-mode: nil
178 // ispell-local-dictionary: "american"
179 // compile-command: "scons -u test"