From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- .../httprequesthandler/HTTPImageHandler.cpp | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 xbmc/network/httprequesthandler/HTTPImageHandler.cpp (limited to 'xbmc/network/httprequesthandler/HTTPImageHandler.cpp') diff --git a/xbmc/network/httprequesthandler/HTTPImageHandler.cpp b/xbmc/network/httprequesthandler/HTTPImageHandler.cpp new file mode 100644 index 0000000..6cde13b --- /dev/null +++ b/xbmc/network/httprequesthandler/HTTPImageHandler.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2012-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 "HTTPImageHandler.h" + +#include "URL.h" +#include "filesystem/ImageFile.h" +#include "network/WebServer.h" +#include "utils/FileUtils.h" + + +CHTTPImageHandler::CHTTPImageHandler(const HTTPRequest &request) + : CHTTPFileHandler(request) +{ + std::string file; + int responseStatus = MHD_HTTP_BAD_REQUEST; + + // resolve the URL into a file path and a HTTP response status + if (m_request.pathUrl.size() > 7) + { + file = m_request.pathUrl.substr(7); + + XFILE::CImageFile imageFile; + const CURL pathToUrl(file); + if (imageFile.Exists(pathToUrl) && CFileUtils::CheckFileAccessAllowed(file)) + { + responseStatus = MHD_HTTP_OK; + struct __stat64 statBuffer; + if (imageFile.Stat(pathToUrl, &statBuffer) == 0) + { + SetLastModifiedDate(&statBuffer); + SetCanBeCached(true); + } + } + else + responseStatus = MHD_HTTP_NOT_FOUND; + } + + // set the file and the HTTP response status + SetFile(file, responseStatus); +} + +bool CHTTPImageHandler::CanHandleRequest(const HTTPRequest &request) const +{ + return request.pathUrl.find("/image/") == 0; +} -- cgit v1.2.3