Akonadi

handler.h
1/***************************************************************************
2 * SPDX-FileCopyrightText: 2006 Till Adam <adam@kde.org> *
3 * *
4 * SPDX-License-Identifier: LGPL-2.0-or-later *
5 ***************************************************************************/
6#pragma once
7
8#include "connection.h"
9#include "exception.h"
10#include "global.h"
11
12#include "private/protocol_p.h"
13
14namespace Akonadi
15{
16namespace Server
17{
18class AkonadiServer;
19class Response;
20
21AKONADI_EXCEPTION_MAKE_INSTANCE(HandlerException);
22
23/**
24 \defgroup akonadi_server_handler Command handlers
25
26 All commands supported by the Akonadi server are implemented as sub-classes of Akonadi::Handler.
27*/
28
29/**
30The handler interfaces describes an entity capable of handling an AkonadiIMAP command.*/
32{
33public:
34 Handler() = delete;
35 Handler(const Handler &) = delete;
36 Handler(Handler &&) noexcept = delete;
37 Handler &operator=(const Handler &) = delete;
38 Handler &operator=(Handler &&) noexcept = delete;
39
40 virtual ~Handler() = default;
41
42 /**
43 * Set the tag of the command to be processed, and thus of the response
44 * generated by this handler.
45 * @param tag The command tag, an alphanumerical string, normally.
46 */
47 void setTag(quint64 tag);
48
49 /**
50 * The tag of the command associated with this handler.
51 */
52 quint64 tag() const;
53
54 void setCommand(const Protocol::CommandPtr &cmd);
55 Protocol::CommandPtr command() const;
56
57 /**
58 * Find a handler for a command that is always allowed, like LOGOUT.
59 * @param cmd the command string
60 * @return an instance to the handler. The handler is deleted after @see handelLine is executed. The caller needs to delete the handler in case an exception
61 * is thrown from handelLine.
62 */
63 static std::unique_ptr<Handler> findHandlerForCommandAlwaysAllowed(Protocol::Command::Type cmd, AkonadiServer &akonadi);
64
65 /**
66 * Find a handler for a command that is allowed when the client is not yet authenticated, like LOGIN.
67 * @param cmd the command string
68 * @return an instance to the handler. The handler is deleted after @see handelLine is executed. The caller needs to delete the handler in case an exception
69 * is thrown from handelLine.
70 */
71 static std::unique_ptr<Handler> findHandlerForCommandNonAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi);
72
73 /**
74 * Find a handler for a command that is allowed when the client is authenticated, like LIST, FETCH, etc.
75 * @param cmd the command string
76 * @return an instance to the handler. The handler is deleted after @see handelLine is executed. The caller needs to delete the handler in case an exception
77 * is thrown from handelLine.
78 */
79 static std::unique_ptr<Handler> findHandlerForCommandAuthenticated(Protocol::Command::Type cmd, AkonadiServer &akonadi);
80
81 void setConnection(Connection *connection);
82 Connection *connection() const;
83 DataStore *storageBackend() const;
84
85 AkonadiServer &akonadi() const;
86
87 bool failureResponse(const char *response);
88 bool failureResponse(const QByteArray &response);
89 bool failureResponse(const QString &response);
90
91 template<typename T>
92 inline bool successResponse();
93 template<typename T>
94 inline bool successResponse(T &&response);
95
96 template<typename T>
97 inline void sendResponse(T &&response);
98 template<typename T>
99 inline void sendResponse();
100
101 /**
102 * Parse and handle the IMAP message using the streaming parser. The implementation MUST leave the trailing newline character(s) in the stream!
103 * @return true if parsed successfully, false in case of parse failure
104 */
105 virtual bool parseStream() = 0;
106
107 bool checkScopeConstraints(const Scope &scope, const QList<Scope::SelectionScope> &permittedScopes) const;
108
109protected:
110 Handler(AkonadiServer &akonadi);
111
112private:
113 AkonadiServer &m_akonadi;
114 quint64 m_tag = 0;
115 Connection *m_connection = nullptr;
116 bool m_sentFailureResponse = false;
117
118protected:
119 Protocol::CommandPtr m_command;
120};
121
122template<typename T>
123inline bool Handler::successResponse()
124{
125 sendResponse<T>(T{});
126 return true;
127}
128
129template<typename T>
130inline bool Handler::successResponse(T &&response)
131{
132 sendResponse<T>(std::move(response));
133 return true;
134}
135
136template<typename T>
137inline void Handler::sendResponse()
138{
139 m_connection->sendResponse<T>(T{});
140}
141
142template<typename T>
143inline void Handler::sendResponse(T &&response)
144{
145 m_connection->sendResponse<T>(std::move(response));
146}
147
148} // namespace Server
149} // namespace Akonadi
An Connection represents one connection of a client to the server.
Definition connection.h:39
This class handles all the database access.
Definition datastore.h:95
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:166
virtual bool parseStream()=0
Parse and handle the IMAP message using the streaming parser.
quint64 tag() const
The tag of the command associated with this handler.
Definition handler.cpp:171
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,...
Definition handler.cpp:40
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:59
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:50
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.