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 
10 #include "global.h"
11 #include "exception.h"
12 #include "connection.h"
13 
14 #include <private/protocol_p.h>
15 
16 namespace Akonadi
17 {
18 
19 namespace Server
20 {
21 
22 class AkonadiServer;
23 class Response;
24 
25 AKONADI_EXCEPTION_MAKE_INSTANCE(HandlerException);
26 
35 class Handler
36 {
37 public:
38  Handler() = delete;
39  Handler(const Handler &) = delete;
40  Handler(Handler &&) noexcept = delete;
41  Handler &operator=(const Handler &) = delete;
42  Handler &operator=(Handler &&) noexcept = delete;
43 
44  virtual ~Handler() = default;
45 
51  void setTag(quint64 tag);
52 
56  quint64 tag() const;
57 
58  void setCommand(const Protocol::CommandPtr &cmd);
59  Protocol::CommandPtr command() const;
60 
66  static std::unique_ptr<Handler> findHandlerForCommandAlwaysAllowed(Protocol::Command::Type cmd, AkonadiServer &akonadi);
67 
73  static std::unique_ptr<Handler> findHandlerForCommandNonAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi);
74 
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>
93  inline bool successResponse();
94  template<typename T>
95  inline bool successResponse(T &&response);
96 
97  template<typename T>
98  inline void sendResponse(T &&response);
99  template<typename T>
100  inline void sendResponse();
101 
106  virtual bool parseStream() = 0;
107 
108  bool checkScopeConstraints(const Scope &scope, int permittedScopes);
109 
110 protected:
111  Handler(AkonadiServer &akonadi);
112 
113 private:
114  AkonadiServer &m_akonadi;
115  quint64 m_tag = 0;
116  Connection *m_connection = nullptr;
117  bool m_sentFailureResponse = false;
118 
119 protected:
120  Protocol::CommandPtr m_command;
121 };
122 
123 template<typename T>
124 inline bool Handler::successResponse()
125 {
126  sendResponse<T>(T{});
127  return true;
128 }
129 
130 template<typename T>
131 inline bool Handler::successResponse(T &&response)
132 {
133  sendResponse<T>(std::move(response));
134  return true;
135 }
136 
137 template<typename T>
138 inline void Handler::sendResponse()
139 {
140  m_connection->sendResponse<T>(T{});
141 }
142 
143 template<typename T>
144 inline void Handler::sendResponse(T &&response)
145 {
146  m_connection->sendResponse<T>(std::move(response));
147 }
148 
149 } // namespace Server
150 } // namespace Akonadi
151 
152 #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:56
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:35
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:189
quint64 tag() const
The tag of the command associated with this handler.
Definition: handler.cpp:194
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:65
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:46
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:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 2 2020 23:15:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.