diff --git a/src/libs/subsonic/CMakeLists.txt b/src/libs/subsonic/CMakeLists.txt index 40d18e89..76f2630c 100644 --- a/src/libs/subsonic/CMakeLists.txt +++ b/src/libs/subsonic/CMakeLists.txt @@ -25,6 +25,7 @@ add_library(lmssubsonic SHARED impl/responses/ReplayGain.cpp impl/responses/Song.cpp impl/responses/User.cpp + impl/ResponseFormat.cpp impl/ProtocolVersion.cpp impl/ParameterParsing.cpp impl/SubsonicId.cpp diff --git a/src/libs/subsonic/impl/RequestContext.hpp b/src/libs/subsonic/impl/RequestContext.hpp index f129a518..f3ddda2f 100644 --- a/src/libs/subsonic/impl/RequestContext.hpp +++ b/src/libs/subsonic/impl/RequestContext.hpp @@ -27,7 +27,7 @@ #include "ClientInfo.hpp" #include "ProtocolVersion.hpp" -#include "SubsonicResponse.hpp" +#include "ResponseFormat.hpp" namespace lms::db { diff --git a/src/libs/subsonic/impl/ResponseFormat.cpp b/src/libs/subsonic/impl/ResponseFormat.cpp new file mode 100644 index 00000000..11cb7601 --- /dev/null +++ b/src/libs/subsonic/impl/ResponseFormat.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#include "ResponseFormat.hpp" + +#include + +namespace lms::api::subsonic +{ + std::string_view ResponseFormatToMimeType(ResponseFormat format) + { + switch (format) + { + case ResponseFormat::xml: + return "text/xml"; + case ResponseFormat::json: + return "application/json"; + } + + return ""; + } +} // namespace lms::api::subsonic \ No newline at end of file diff --git a/src/libs/subsonic/impl/ResponseFormat.hpp b/src/libs/subsonic/impl/ResponseFormat.hpp new file mode 100644 index 00000000..c7e97552 --- /dev/null +++ b/src/libs/subsonic/impl/ResponseFormat.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#pragma once + +#include + +namespace lms::api::subsonic +{ + enum class ResponseFormat + { + xml, + json, + }; + + std::string_view ResponseFormatToMimeType(ResponseFormat format); +} // namespace lms::api::subsonic \ No newline at end of file diff --git a/src/libs/subsonic/impl/SubsonicResponse.cpp b/src/libs/subsonic/impl/SubsonicResponse.cpp index 76e4dee0..32060cfb 100644 --- a/src/libs/subsonic/impl/SubsonicResponse.cpp +++ b/src/libs/subsonic/impl/SubsonicResponse.cpp @@ -32,19 +32,6 @@ namespace lms::api::subsonic { - std::string_view ResponseFormatToMimeType(ResponseFormat format) - { - switch (format) - { - case ResponseFormat::xml: - return "text/xml"; - case ResponseFormat::json: - return "application/json"; - } - - return ""; - } - void Response::Node::setValue(std::string_view value) { assert(_children.empty() && _childrenArrays.empty() && _childrenValues.empty()); diff --git a/src/libs/subsonic/impl/SubsonicResponse.hpp b/src/libs/subsonic/impl/SubsonicResponse.hpp index 9b106f6f..1eec8665 100644 --- a/src/libs/subsonic/impl/SubsonicResponse.hpp +++ b/src/libs/subsonic/impl/SubsonicResponse.hpp @@ -28,6 +28,7 @@ #include "core/LiteralString.hpp" #include "ProtocolVersion.hpp" +#include "ResponseFormat.hpp" #include "SubsonicResponseAllocator.hpp" namespace lms::api::subsonic @@ -35,14 +36,6 @@ namespace lms::api::subsonic // Max count expected from all API methods that expose a count static inline constexpr std::size_t defaultMaxCountSize{ 1'000 }; - enum class ResponseFormat - { - xml, - json, - }; - - std::string_view ResponseFormatToMimeType(ResponseFormat format); - class Error { public: @@ -244,7 +237,7 @@ namespace lms::api::subsonic std::size_t _max; }; - class Response + class Response final { public: class Node @@ -306,7 +299,7 @@ namespace lms::api::subsonic static Response createOkResponse(ProtocolVersion protocolVersion); static Response createFailedResponse(ProtocolVersion protocolVersion, const Error& error); - virtual ~Response() {} + ~Response() = default; Response(const Response&) = delete; Response& operator=(const Response&) = delete; Response(Response&&) = default; diff --git a/src/libs/subsonic/impl/endpoints/MediaRetrieval.cpp b/src/libs/subsonic/impl/endpoints/MediaRetrieval.cpp index 4db5610e..a6b41938 100644 --- a/src/libs/subsonic/impl/endpoints/MediaRetrieval.cpp +++ b/src/libs/subsonic/impl/endpoints/MediaRetrieval.cpp @@ -36,6 +36,7 @@ #include "services/artwork/IArtworkService.hpp" #include "ParameterParsing.hpp" +#include "RequestContext.hpp" #include "SubsonicId.hpp" #include "responses/Lyrics.hpp" diff --git a/src/libs/subsonic/impl/endpoints/MediaRetrieval.hpp b/src/libs/subsonic/impl/endpoints/MediaRetrieval.hpp index d5be9ac7..4291466c 100644 --- a/src/libs/subsonic/impl/endpoints/MediaRetrieval.hpp +++ b/src/libs/subsonic/impl/endpoints/MediaRetrieval.hpp @@ -22,10 +22,12 @@ #include #include -#include "RequestContext.hpp" +#include "SubsonicResponse.hpp" namespace lms::api::subsonic { + class RequestContext; + Response handleGetLyrics(RequestContext& context); Response handleGetLyricsBySongId(RequestContext& context);