File indexing completed on 2024-06-23 05:07:02

0001 /*
0002     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "resourceselecthandler.h"
0008 
0009 #include "connection.h"
0010 
0011 using namespace Akonadi;
0012 using namespace Akonadi::Server;
0013 
0014 ResourceSelectHandler::ResourceSelectHandler(AkonadiServer &akonadi)
0015     : Handler(akonadi)
0016 {
0017 }
0018 
0019 bool ResourceSelectHandler::parseStream()
0020 {
0021     const auto &cmd = Protocol::cmdCast<Protocol::SelectResourceCommand>(m_command);
0022 
0023     CommandContext context = connection()->context();
0024     if (cmd.resourceId().isEmpty()) {
0025         context.setResource({});
0026         connection()->setContext(context);
0027         return successResponse<Protocol::SelectResourceResponse>();
0028     }
0029 
0030     const Resource res = Resource::retrieveByName(cmd.resourceId());
0031     if (!res.isValid()) {
0032         return failureResponse(cmd.resourceId() % QStringLiteral(" is not a valid resource identifier"));
0033     }
0034 
0035     context.setResource(res);
0036     connection()->setContext(context);
0037 
0038     return successResponse<Protocol::SelectResourceResponse>();
0039 }