diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp')
-rw-r--r-- | xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp b/xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp new file mode 100644 index 0000000..fa47144 --- /dev/null +++ b/xbmc/network/httprequesthandler/HTTPWebinterfaceAddonsHandler.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "HTTPWebinterfaceAddonsHandler.h" + +#include "ServiceBroker.h" +#include "addons/Addon.h" +#include "addons/AddonManager.h" +#include "addons/addoninfo/AddonType.h" +#include "network/WebServer.h" + +#define ADDON_HEADER "<html><head><title>Add-on List</title></head><body>\n<h1>Available web interfaces:</h1>\n<ul>\n" + +bool CHTTPWebinterfaceAddonsHandler::CanHandleRequest(const HTTPRequest &request) const +{ + return (request.pathUrl.compare("/addons") == 0 || request.pathUrl.compare("/addons/") == 0); +} + +MHD_RESULT CHTTPWebinterfaceAddonsHandler::HandleRequest() +{ + m_responseData = ADDON_HEADER; + ADDON::VECADDONS addons; + if (!CServiceBroker::GetAddonMgr().GetAddons(addons, ADDON::AddonType::WEB_INTERFACE) || + addons.empty()) + { + m_response.type = HTTPError; + m_response.status = MHD_HTTP_INTERNAL_SERVER_ERROR; + + return MHD_YES; + } + + for (const auto& addon : addons) + m_responseData += "<li><a href=/addons/" + addon->ID() + "/>" + addon->Name() + "</a></li>\n"; + + m_responseData += "</ul>\n</body></html>"; + + m_responseRange.SetData(m_responseData.c_str(), m_responseData.size()); + + m_response.type = HTTPMemoryDownloadNoFreeCopy; + m_response.status = MHD_HTTP_OK; + m_response.contentType = "text/html"; + m_response.totalLength = m_responseData.size(); + + return MHD_YES; +} + +HttpResponseRanges CHTTPWebinterfaceAddonsHandler::GetResponseData() const +{ + HttpResponseRanges ranges; + ranges.push_back(m_responseRange); + + return ranges; +} + + |