diff options
Diffstat (limited to 'src/input/inputEventHandler.h')
| -rw-r--r-- | src/input/inputEventHandler.h | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/src/input/inputEventHandler.h b/src/input/inputEventHandler.h index 44713c2..52e3338 100644 --- a/src/input/inputEventHandler.h +++ b/src/input/inputEventHandler.h @@ -18,6 +18,7 @@ #define INPUTEVENTHANDLER_H_ #include <QtGlobal> +#include <QtDebug> #include <QList> #include <QString> #include <QCoreApplication> @@ -97,26 +98,33 @@ public: namespace policy { enum SecurityFlags { - SEC_PHYSICAL_SEAT = 1, - SEC_PRIVILEGED_USER = 2 + SEC_FREE_FOR_ALL, + SEC_PHYSICAL_OR_PRIVILEGED }; bool allowPhysicalSeat(InputEvent const& evt, InputEventContext const* ctx); bool allowPrivilegedUser(InputEvent const& evt, InputEventContext const* ctx); -template<int flags = 0> -struct Security +struct SecurityAllowAny { bool allow(InputEvent const& evt, InputEventContext const* ctx) { - if((flags & SEC_PHYSICAL_SEAT) && !allowPhysicalSeat(evt, ctx)) - return false; - if((flags & SEC_PRIVILEGED_USER) && !allowPrivilegedUser(evt, ctx)) - return false; return true; } }; +struct SecurityAllowPhysicalOrPrivileged +{ + bool allow(InputEvent const& evt, InputEventContext const* ctx) + { + if(allowPhysicalSeat(evt, ctx)) + return true; + else if(allowPrivilegedUser(evt, ctx)) + return true; + return false; + } +}; + struct UnixLike; struct Linux; struct Windows; @@ -154,6 +162,8 @@ public: bool handle(InputEvent const& evt, InputEventContext const* context = 0) { if(!securityPolicy.allow(evt, context)) { + std::string evtStr = evt.toString(); + qWarning("Input Event %s has been denied by security policy", evtStr.c_str()); return true; } if(delegate.matches(evt, context)) { @@ -196,19 +206,32 @@ public: } }; -template<typename Delegate, typename SystemPolicy = policy::RequireNoSystem, typename SecurityPolicy = policy::Security<> > +template<typename Delegate, typename SystemPolicy = policy::RequireNoSystem, typename SecurityPolicy = void> struct Handler : public HandlerHelper<SystemPolicy::enabled, Delegate, SecurityPolicy> { }; -template<typename Begin, typename End> +template<typename DefaultSecurityPolicy, typename HandlerType> +struct ApplyDefaultSecurityPolicy +{ + typedef HandlerType type; +}; + +template<typename DefaultSecurityPolicy, typename Delegate, typename SystemPolicy> +struct ApplyDefaultSecurityPolicy<DefaultSecurityPolicy, Handler<Delegate, SystemPolicy, void> > +{ + typedef Handler<Delegate, SystemPolicy, DefaultSecurityPolicy> type; +}; + +template<typename DefaultSecurityPolicy, typename Begin, typename End> struct InputEventHandlerChainHelper { private: typedef typename boost::mpl::next<Begin>::type next_iterator_type; - typedef InputEventHandlerChainHelper<next_iterator_type, End> next_in_chain; + typedef InputEventHandlerChainHelper<DefaultSecurityPolicy, next_iterator_type, End> next_in_chain; - typedef typename boost::mpl::deref<Begin>::type handler_type; + typedef typename boost::mpl::deref<Begin>::type handler_entry_type; + typedef typename ApplyDefaultSecurityPolicy<DefaultSecurityPolicy, handler_entry_type>::type handler_type; handler_type _handler; next_in_chain _next; @@ -239,8 +262,8 @@ public: } }; -template<typename End> -struct InputEventHandlerChainHelper<End, End> +template<typename DefaultSecurityPolicy, typename End> +struct InputEventHandlerChainHelper<DefaultSecurityPolicy, End, End> { void handle(InputEvent const&, InputEventContext const* context = 0) { // do nothing @@ -261,8 +284,11 @@ struct InputEventHandlerChainHelper<End, End> } }; -template<typename Collection> -struct InputEventHandlerChain : public InputEventHandlerChainHelper<typename boost::mpl::begin<Collection>::type, typename boost::mpl::end<Collection>::type> +template<typename DefaultSecurityPolicy, typename Collection> +struct InputEventHandlerChain : + public InputEventHandlerChainHelper<DefaultSecurityPolicy, + typename boost::mpl::begin<Collection>::type, + typename boost::mpl::end<Collection>::type> { }; |
