Akonadi

handler.h
1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2006 Till Adam <[email protected]> *
3  * *
4  * SPDX-License-Identifier: LGPL-2.0-or-later *
5  ***************************************************************************/
6 #ifndef AKONADIHANDLER_H
7 #define AKONADIHANDLER_H
8 
9 #include "connection.h"
10 #include "exception.h"
11 #include "global.h"
12 
13 #include <private/protocol_p.h>
14 
15 namespace Akonadi
16 {
17 namespace Server
18 {
19 class AkonadiServer;
20 class Response;
21 
22 AKONADI_EXCEPTION_MAKE_INSTANCE(HandlerException);
23 
32 class Handler
33 {
34 public:
35  Handler() = delete;
36  Handler(const Handler &) = delete;
37  Handler(Handler &&) noexcept = delete;
38  Handler &operator=(const Handler &) = delete;
39  Handler &operator=(Handler &&) noexcept = delete;
40 
41  virtual ~Handler() = default;
42 
48  void setTag(quint64 tag);
49 
53  quint64 tag() const;
54 
55  void setCommand(const Protocol::CommandPtr &cmd);
56  Protocol::CommandPtr command() const;
57 
64  static std::unique_ptr<Handler> findHandlerForCommandAlwaysAllowed(Protocol::Command::Type cmd, AkonadiServer &akonadi);
65 
72  static std::unique_ptr<Handler> findHandlerForCommandNonAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi);
73 
80  static std::unique_ptr<Handler> findHandlerForCommandAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi);
81 
82  void setConnection(Connection *connection);
83  Connection *connection() const;
84  DataStore *storageBackend() const;
85 
86  AkonadiServer &akonadi() const;
87 
88  bool failureResponse(const char *response);
89  bool failureResponse(const QByteArray &response);
90  bool failureResponse(const QString &response);
91 
92  template<typename T> inline bool successResponse();
93  template<typename T> inline bool successResponse(T &&response);
94 
95  template<typename T> inline void sendResponse(T &&response);
96  template<typename T> inline void sendResponse();
97 
102  virtual bool parseStream() = 0;
103 
104  bool checkScopeConstraints(const Scope &scope, int permittedScopes);
105 
106 protected:
107  Handler(AkonadiServer &akonadi);
108 
109 private:
110  AkonadiServer &m_akonadi;
111  quint64 m_tag = 0;
112  Connection *m_connection = nullptr;
113  bool m_sentFailureResponse = false;
114 
115 protected:
116  Protocol::CommandPtr m_command;
117 };
118 
119 template<typename T> inline bool Handler::successResponse()
120 {
121  sendResponse<T>(T{});
122  return true;
123 }
124 
125 template<typename T> inline bool Handler::successResponse(T &&response)
126 {
127  sendResponse<T>(std::move(response));
128  return true;
129 }
130 
131 template<typename T> inline void Handler::sendResponse()
132 {
133  m_connection->sendResponse<T>(T{});
134 }
135 
136 template<typename T> inline void Handler::sendResponse(T &&response)
137 {
138  m_connection->sendResponse<T>(std::move(response));
139 }
140 
141 } // namespace Server
142 } // namespace Akonadi
143 
144 #endif
static std::unique_ptr< Handler > findHandlerForCommandAlwaysAllowed(Protocol::Command::Type cmd, AkonadiServer &akonadi)
Find a handler for a command that is always allowed, like LOGOUT.
Definition: handler.cpp:53
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:32
void setTag(quint64 tag)
Set the tag of the command to be processed, and thus of the response generated by this handler...
Definition: handler.cpp:179
quint64 tag() const
The tag of the command associated with this handler.
Definition: handler.cpp:184
Helper integration between Akonadi and Qt.
static std::unique_ptr< Handler > findHandlerForCommandAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi)
Find a handler for a command that is allowed when the client is authenticated, like LIST...
Definition: handler.cpp:62
This class handles all the database access.
Definition: datastore.h:95
static std::unique_ptr< Handler > findHandlerForCommandNonAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi)
Find a handler for a command that is allowed when the client is not yet authenticated, like LOGIN.
Definition: handler.cpp:43
virtual bool parseStream()=0
Parse and handle the IMAP message using the streaming parser.
An Connection represents one connection of a client to the server.
Definition: connection.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 27 2021 23:16:32 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.