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 "../../Utils/membind.hh"
32 //#include "Config.mpp"
34 ///////////////////////////////cc.p////////////////////////////////////////
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_ bool senf::console::detail::RestrictedExecutor::parsed(GenericNode & node)
63 ParsedNodes::const_iterator i (parsedNodes_.begin());
64 ParsedNodes::const_iterator const i_end (parsedNodes_.end());
65 for (; i != i_end; ++i)
66 if ( ! i->expired() && node.isChildOf(*(i->lock())) )
71 prefix_ void senf::console::detail::RestrictedExecutor::policyCallback(DirectoryNode & dir,
72 std::string const & name)
74 if (dir.hasChild(name)) {
75 GenericNode & item (dir.get(name));
76 if (restrict_ && ! item.isChildOf(*restrict_) && ! item.isDirectory())
77 throw Executor::IgnoreCommandException();
79 throw Executor::IgnoreCommandException();
81 else if (restrict_ && ! dir.isChildOf(*restrict_))
82 throw Executor::IgnoreCommandException();
88 RemoveNodesFn(senf::console::DirectoryNode::ptr newNode) : newNode_ (newNode) {}
90 bool operator()(senf::console::DirectoryNode::weak_ptr node) const
91 { return node.expired() || node.lock()->isChildOf(*newNode_); }
93 senf::console::DirectoryNode::ptr newNode_;
98 senf::console::detail::RestrictedExecutor::insertParsedNode(DirectoryNode & node)
101 std::remove_if(parsedNodes_.begin(), parsedNodes_.end(), RemoveNodesFn(node.thisptr())),
103 parsedNodes_.push_back(node.thisptr());
106 ///////////////////////////////////////////////////////////////////////////
107 // senf::console::ConfigBundle
109 prefix_ void senf::console::ConfigBundle::parse()
111 detail::RestrictedExecutor::RestrictGuard guard (executor_);
115 prefix_ void senf::console::ConfigBundle::parse(DirectoryNode & restrict)
117 detail::RestrictedExecutor::RestrictGuard guard (executor_, restrict);
121 prefix_ void senf::console::ConfigBundle::parseInternal()
123 Sources::const_iterator i (sources_.begin());
124 Sources::const_iterator const i_end (sources_.end());
125 for (; i != i_end; ++i)
126 (*i)->parse(executor_);
129 ///////////////////////////////////////////////////////////////////////////
130 // senf::console::detail::RestrictedExecutor::RestrictGuard
132 prefix_ senf::console::detail::RestrictedExecutor::RestrictGuard::
133 RestrictGuard(RestrictedExecutor & executor)
134 : executor_ (executor)
136 // This MUST BE root() not chroot() since restriction does NOT follow symlinks.
137 // Therefore, if chroot() is a directory of symlinks, restricting to it will
139 executor_.restrict_ = senf::console::root().thisptr();
142 prefix_ senf::console::detail::RestrictedExecutor::RestrictGuard::
143 RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict)
144 : executor_ (executor)
146 executor_.restrict_ = restrict.thisptr();
149 prefix_ senf::console::detail::RestrictedExecutor::RestrictGuard::~RestrictGuard()
151 if (! std::uncaught_exception())
152 executor_.insertParsedNode( *executor_.restrict_ );
153 executor_.restrict_ = senf::console::root().thisptr();
156 ///////////////////////////////////////////////////////////////////////////
157 // senf::console::detail::ConfigSource
159 prefix_ senf::console::detail::ConfigSource::~ConfigSource()
162 ///////////////////////////////cc.e////////////////////////////////////////
164 //#include "Config.mpp"
170 // comment-column: 40
171 // c-file-style: "senf"
172 // indent-tabs-mode: nil
173 // ispell-local-dictionary: "american"
174 // compile-command: "scons -u test"