Akonadi

handler.h
1 /***************************************************************************
2  * Copyright (C) 2006 by Till Adam <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as *
6  * published by the Free Software Foundation; either version 2 of the *
7  * License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public *
15  * License along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 #ifndef AKONADIHANDLER_H
20 #define AKONADIHANDLER_H
21 
22 
23 #include "global.h"
24 #include "exception.h"
25 #include "connection.h"
26 
27 #include <private/protocol_p.h>
28 
29 namespace Akonadi
30 {
31 
32 namespace Server
33 {
34 
35 class AkonadiServer;
36 class Response;
37 
38 AKONADI_EXCEPTION_MAKE_INSTANCE(HandlerException);
39 
48 class Handler
49 {
50 public:
51  Handler() = delete;
52  Handler(const Handler &) = delete;
53  Handler(Handler &&) noexcept = delete;
54  Handler &operator=(const Handler &) = delete;
55  Handler &operator=(Handler &&) noexcept = delete;
56 
57  virtual ~Handler() = default;
58 
64  void setTag(quint64 tag);
65 
69  quint64 tag() const;
70 
71  void setCommand(const Protocol::CommandPtr &cmd);
72  Protocol::CommandPtr command() const;
73 
79  static std::unique_ptr<Handler> findHandlerForCommandAlwaysAllowed(Protocol::Command::Type cmd, AkonadiServer &akonadi);
80 
86  static std::unique_ptr<Handler> findHandlerForCommandNonAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi);
87 
93  static std::unique_ptr<Handler> findHandlerForCommandAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi);
94 
95  void setConnection(Connection *connection);
96  Connection *connection() const;
97  DataStore *storageBackend() const;
98 
99  AkonadiServer &akonadi() const;
100 
101  bool failureResponse(const char *response);
102  bool failureResponse(const QByteArray &response);
103  bool failureResponse(const QString &response);
104 
105  template<typename T>
106  inline bool successResponse();
107  template<typename T>
108  inline bool successResponse(T &&response);
109 
110  template<typename T>
111  inline void sendResponse(T &&response);
112  template<typename T>
113  inline void sendResponse();
114 
119  virtual bool parseStream() = 0;
120 
121  bool checkScopeConstraints(const Scope &scope, int permittedScopes);
122 
123 protected:
124  Handler(AkonadiServer &akonadi);
125 
126 private:
127  AkonadiServer &m_akonadi;
128  quint64 m_tag = 0;
129  Connection *m_connection = nullptr;
130  bool m_sentFailureResponse = false;
131 
132 protected:
133  Protocol::CommandPtr m_command;
134 };
135 
136 template<typename T>
137 inline bool Handler::successResponse()
138 {
139  sendResponse<T>(T{});
140  return true;
141 }
142 
143 template<typename T>
144 inline bool Handler::successResponse(T &&response)
145 {
146  sendResponse<T>(std::move(response));
147  return true;
148 }
149 
150 template<typename T>
151 inline void Handler::sendResponse()
152 {
153  m_connection->sendResponse<T>(T{});
154 }
155 
156 template<typename T>
157 inline void Handler::sendResponse(T &&response)
158 {
159  m_connection->sendResponse<T>(std::move(response));
160 }
161 
162 } // namespace Server
163 } // namespace Akonadi
164 
165 #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:69
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:48
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:203
quint64 tag() const
The tag of the command associated with this handler.
Definition: handler.cpp:208
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:78
This class handles all the database access.
Definition: datastore.h:108
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:59
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:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jun 6 2020 23:09:05 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.