8 #include <private/scope_p.h>
10 #include "handler/collectioncopyhandler.h"
11 #include "handler/collectioncreatehandler.h"
12 #include "handler/collectiondeletehandler.h"
13 #include "handler/collectionfetchhandler.h"
14 #include "handler/collectionmodifyhandler.h"
15 #include "handler/collectionmovehandler.h"
16 #include "handler/collectionstatsfetchhandler.h"
17 #include "handler/itemcopyhandler.h"
18 #include "handler/itemcreatehandler.h"
19 #include "handler/itemdeletehandler.h"
20 #include "handler/itemfetchhandler.h"
21 #include "handler/itemlinkhandler.h"
22 #include "handler/itemmodifyhandler.h"
23 #include "handler/itemmovehandler.h"
24 #include "handler/loginhandler.h"
25 #include "handler/logouthandler.h"
26 #include "handler/relationfetchhandler.h"
27 #include "handler/relationmodifyhandler.h"
28 #include "handler/relationremovehandler.h"
29 #include "handler/resourceselecthandler.h"
30 #include "handler/searchcreatehandler.h"
31 #include "handler/searchhandler.h"
32 #include "handler/searchresulthandler.h"
33 #include "handler/tagcreatehandler.h"
34 #include "handler/tagdeletehandler.h"
35 #include "handler/tagfetchhandler.h"
36 #include "handler/tagmodifyhandler.h"
37 #include "handler/transactionhandler.h"
38 #include "storage/querybuilder.h"
41 using namespace Akonadi::Server;
46 if (cmd == Protocol::Command::Login) {
47 return std::make_unique<LoginHandler>(akonadi);
56 if (cmd == Protocol::Command::Logout) {
57 return std::make_unique<LogoutHandler>(akonadi);
65 case Protocol::Command::Invalid:
66 Q_ASSERT_X(cmd != Protocol::Command::Invalid, __FUNCTION__,
"Invalid command is not allowed");
68 case Protocol::Command::Hello:
69 Q_ASSERT_X(cmd != Protocol::Command::Hello, __FUNCTION__,
"Hello command is not allowed in this context");
71 case Protocol::Command::Login:
72 case Protocol::Command::Logout:
74 case Protocol::Command::_ResponseBit:
75 Q_ASSERT_X(cmd != Protocol::Command::_ResponseBit, __FUNCTION__,
"ResponseBit is not a valid command type");
78 case Protocol::Command::Transaction:
79 return std::make_unique<TransactionHandler>(akonadi);
81 case Protocol::Command::CreateItem:
82 return std::make_unique<ItemCreateHandler>(akonadi);
83 case Protocol::Command::CopyItems:
84 return std::make_unique<ItemCopyHandler>(akonadi);
85 case Protocol::Command::DeleteItems:
86 return std::make_unique<ItemDeleteHandler>(akonadi);
87 case Protocol::Command::FetchItems:
88 return std::make_unique<ItemFetchHandler>(akonadi);
89 case Protocol::Command::LinkItems:
90 return std::make_unique<ItemLinkHandler>(akonadi);
91 case Protocol::Command::ModifyItems:
92 return std::make_unique<ItemModifyHandler>(akonadi);
93 case Protocol::Command::MoveItems:
94 return std::make_unique<ItemMoveHandler>(akonadi);
96 case Protocol::Command::CreateCollection:
97 return std::make_unique<CollectionCreateHandler>(akonadi);
98 case Protocol::Command::CopyCollection:
99 return std::make_unique<CollectionCopyHandler>(akonadi);
100 case Protocol::Command::DeleteCollection:
101 return std::make_unique<CollectionDeleteHandler>(akonadi);
102 case Protocol::Command::FetchCollections:
103 return std::make_unique<CollectionFetchHandler>(akonadi);
104 case Protocol::Command::FetchCollectionStats:
105 return std::make_unique<CollectionStatsFetchHandler>(akonadi);
106 case Protocol::Command::ModifyCollection:
107 return std::make_unique<CollectionModifyHandler>(akonadi);
108 case Protocol::Command::MoveCollection:
109 return std::make_unique<CollectionMoveHandler>(akonadi);
111 case Protocol::Command::Search:
112 return std::make_unique<SearchHandler>(akonadi);
113 case Protocol::Command::SearchResult:
114 return std::make_unique<SearchResultHandler>(akonadi);
115 case Protocol::Command::StoreSearch:
116 return std::make_unique<SearchCreateHandler>(akonadi);
118 case Protocol::Command::CreateTag:
119 return std::make_unique<TagCreateHandler>(akonadi);
120 case Protocol::Command::DeleteTag:
121 return std::make_unique<TagDeleteHandler>(akonadi);
122 case Protocol::Command::FetchTags:
123 return std::make_unique<TagFetchHandler>(akonadi);
124 case Protocol::Command::ModifyTag:
125 return std::make_unique<TagModifyHandler>(akonadi);
127 case Protocol::Command::FetchRelations:
128 return std::make_unique<RelationFetchHandler>(akonadi);
129 case Protocol::Command::ModifyRelation:
130 return std::make_unique<RelationModifyHandler>(akonadi);
131 case Protocol::Command::RemoveRelations:
132 return std::make_unique<RelationRemoveHandler>(akonadi);
134 case Protocol::Command::SelectResource:
135 return std::make_unique<ResourceSelectHandler>(akonadi);
137 case Protocol::Command::StreamPayload:
138 Q_ASSERT_X(cmd != Protocol::Command::StreamPayload, __FUNCTION__,
"StreamPayload command is not allowed in this context");
141 case Protocol::Command::ItemChangeNotification:
142 Q_ASSERT_X(cmd != Protocol::Command::ItemChangeNotification, __FUNCTION__,
"ItemChangeNotification command is not allowed on this connection");
144 case Protocol::Command::CollectionChangeNotification:
145 Q_ASSERT_X(cmd != Protocol::Command::CollectionChangeNotification,
147 "CollectionChangeNotification command is not allowed on this connection");
149 case Protocol::Command::TagChangeNotification:
150 Q_ASSERT_X(cmd != Protocol::Command::TagChangeNotification, __FUNCTION__,
"TagChangeNotification command is not allowed on this connection");
152 case Protocol::Command::RelationChangeNotification:
153 Q_ASSERT_X(cmd != Protocol::Command::RelationChangeNotification, __FUNCTION__,
"RelationChangeNotification command is not allowed on this connection");
155 case Protocol::Command::SubscriptionChangeNotification:
156 Q_ASSERT_X(cmd != Protocol::Command::SubscriptionChangeNotification,
158 "SubscriptionChangeNotification command is not allowed on this connection");
160 case Protocol::Command::DebugChangeNotification:
161 Q_ASSERT_X(cmd != Protocol::Command::DebugChangeNotification, __FUNCTION__,
"DebugChangeNotification command is not allowed on this connection");
163 case Protocol::Command::ModifySubscription:
164 Q_ASSERT_X(cmd != Protocol::Command::ModifySubscription, __FUNCTION__,
"ModifySubscription command is not allowed on this connection");
166 case Protocol::Command::CreateSubscription:
167 Q_ASSERT_X(cmd != Protocol::Command::CreateSubscription, __FUNCTION__,
"CreateSubscription command is not allowed on this connection");
174 Handler::Handler(AkonadiServer &akonadi)
199 void Handler::setConnection(
Connection *connection)
201 m_connection = connection;
209 DataStore *Handler::storageBackend()
const
211 return m_connection->storageBackend();
214 AkonadiServer &Handler::akonadi()
const
219 bool Handler::failureResponse(
const QByteArray &failureMessage)
224 bool Handler::failureResponse(
const char *failureMessage)
229 bool Handler::failureResponse(
const QString &failureMessage)
234 if (!m_sentFailureResponse) {
235 m_sentFailureResponse =
true;
236 Protocol::ResponsePtr r = Protocol::Factory::response(m_command->type());
238 r->setError(1, failureMessage);
240 m_connection->sendResponse(m_tag, r);
246 bool Handler::checkScopeConstraints(
const Akonadi::Scope &scope,
int permittedScopes)
248 return scope.scope() & permittedScopes;