"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xbmc/network/WebServer.cpp" between
xbmc-18.7.1-Leia.tar.gz and xbmc-18.8-Leia.tar.gz

About: XBMC is a software media player and entertainment hub for digital media that plays almost all popular audio and video formats around (new name "Kodi").

WebServer.cpp  (xbmc-18.7.1-Leia):WebServer.cpp  (xbmc-18.8-Leia)
skipping to change at line 89 skipping to change at line 89
{ {
MHD_ResponseMemoryMode mode = MHD_RESPMEM_PERSISTENT; MHD_ResponseMemoryMode mode = MHD_RESPMEM_PERSISTENT;
if (copy) if (copy)
mode = MHD_RESPMEM_MUST_COPY; mode = MHD_RESPMEM_MUST_COPY;
else if (free) else if (free)
mode = MHD_RESPMEM_MUST_FREE; mode = MHD_RESPMEM_MUST_FREE;
//! @bug libmicrohttpd isn't const correct //! @bug libmicrohttpd isn't const correct
return MHD_create_response_from_buffer(size, const_cast<void*>(data), mode); return MHD_create_response_from_buffer(size, const_cast<void*>(data), mode);
} }
int CWebServer::AskForAuthentication(const HTTPRequest& request) const MHD_RESULT CWebServer::AskForAuthentication(const HTTPRequest& request) const
{ {
struct MHD_Response *response = create_response(0, nullptr, MHD_NO, MHD_NO); struct MHD_Response *response = create_response(0, nullptr, MHD_NO, MHD_NO);
if (!response) if (!response)
{ {
CLog::Log(LOGERROR, "CWebServer[%hu]: unable to create HTTP Unauthorized res ponse", m_port); CLog::Log(LOGERROR, "CWebServer[%hu]: unable to create HTTP Unauthorized res ponse", m_port);
return MHD_NO; return MHD_NO;
} }
int ret = AddHeader(response, MHD_HTTP_HEADER_CONNECTION, "close"); MHD_RESULT ret = AddHeader(response, MHD_HTTP_HEADER_CONNECTION, "close");
if (!ret) if (!ret)
{ {
CLog::Log(LOGERROR, "CWebServer[%hu]: unable to prepare HTTP Unauthorized re sponse", m_port); CLog::Log(LOGERROR, "CWebServer[%hu]: unable to prepare HTTP Unauthorized re sponse", m_port);
MHD_destroy_response(response); MHD_destroy_response(response);
return MHD_NO; return MHD_NO;
} }
LogResponse(request, MHD_HTTP_UNAUTHORIZED); LogResponse(request, MHD_HTTP_UNAUTHORIZED);
ret = MHD_queue_basic_auth_fail_response(request.connection, "XBMC", response) // This MHD_RESULT cast is only necessary for libmicrohttpd 0.9.71
; // The return type of MHD_queue_basic_auth_fail_response was fixed for future
versions
// See https://git.gnunet.org/libmicrohttpd.git/commit/?id=860b42e9180da4dcd7e
8690a3fcdb4e37e5772c5
ret = static_cast<MHD_RESULT>(MHD_queue_basic_auth_fail_response(request.conne
ction, "XBMC", response));
MHD_destroy_response(response); MHD_destroy_response(response);
return ret; return ret;
} }
bool CWebServer::IsAuthenticated(const HTTPRequest& request) const bool CWebServer::IsAuthenticated(const HTTPRequest& request) const
{ {
CSingleLock lock(m_critSection); CSingleLock lock(m_critSection);
if (!m_authenticationRequired) if (!m_authenticationRequired)
skipping to change at line 138 skipping to change at line 141
// compare the received username and password // compare the received username and password
bool authenticated = m_authenticationUsername.compare(username) == 0 && bool authenticated = m_authenticationUsername.compare(username) == 0 &&
m_authenticationPassword.compare(password) == 0; m_authenticationPassword.compare(password) == 0;
free(username); free(username);
free(password); free(password);
return authenticated; return authenticated;
} }
int CWebServer::AnswerToConnection(void *cls, struct MHD_Connection *connection, MHD_RESULT CWebServer::AnswerToConnection(void *cls, struct MHD_Connection *conn ection,
const char *url, const char *method, const char *url, const char *method,
const char *version, const char *upload_data, const char *version, const char *upload_data,
size_t *upload_data_size, void **con_cls) size_t *upload_data_size, void **con_cls)
{ {
if (cls == nullptr || con_cls == nullptr || *con_cls == nullptr) if (cls == nullptr || con_cls == nullptr || *con_cls == nullptr)
{ {
CLog::Log(LOGERROR, "CWebServer[unknown]: invalid request received"); CLog::Log(LOGERROR, "CWebServer[unknown]: invalid request received");
return MHD_NO; return MHD_NO;
} }
skipping to change at line 166 skipping to change at line 169
ConnectionHandler* connectionHandler = reinterpret_cast<ConnectionHandler*>(*c on_cls); ConnectionHandler* connectionHandler = reinterpret_cast<ConnectionHandler*>(*c on_cls);
HTTPMethod methodType = GetHTTPMethod(method); HTTPMethod methodType = GetHTTPMethod(method);
HTTPRequest request = { webServer, connection, connectionHandler->fullUri, url , methodType, version }; HTTPRequest request = { webServer, connection, connectionHandler->fullUri, url , methodType, version };
if (connectionHandler->isNew) if (connectionHandler->isNew)
webServer->LogRequest(request); webServer->LogRequest(request);
return webServer->HandlePartialRequest(connection, connectionHandler, request, upload_data, upload_data_size, con_cls); return webServer->HandlePartialRequest(connection, connectionHandler, request, upload_data, upload_data_size, con_cls);
} }
int CWebServer::HandlePartialRequest(struct MHD_Connection *connection, Connecti onHandler* connectionHandler, const HTTPRequest& request, const char *upload_dat a, size_t *upload_data_size, void **con_cls) MHD_RESULT CWebServer::HandlePartialRequest(struct MHD_Connection *connection, C onnectionHandler* connectionHandler, const HTTPRequest& request, const char *upl oad_data, size_t *upload_data_size, void **con_cls)
{ {
std::unique_ptr<ConnectionHandler> conHandler(connectionHandler); std::unique_ptr<ConnectionHandler> conHandler(connectionHandler);
// remember if the request was new // remember if the request was new
bool isNewRequest = conHandler->isNew; bool isNewRequest = conHandler->isNew;
// because now it isn't anymore // because now it isn't anymore
conHandler->isNew = false; conHandler->isNew = false;
// reset con_cls and set it if still necessary // reset con_cls and set it if still necessary
*con_cls = nullptr; *con_cls = nullptr;
skipping to change at line 279 skipping to change at line 282
// it's unusual to get more than one call to AnswerToConnection for none-POS T requests, but let's handle it anyway // it's unusual to get more than one call to AnswerToConnection for none-POS T requests, but let's handle it anyway
auto requestHandler = FindRequestHandler(request); auto requestHandler = FindRequestHandler(request);
if (requestHandler != nullptr) if (requestHandler != nullptr)
return HandleRequest(requestHandler); return HandleRequest(requestHandler);
} }
CLog::Log(LOGERROR, "CWebServer[%hu]: couldn't find any request handler for %s ", m_port, request.pathUrl.c_str()); CLog::Log(LOGERROR, "CWebServer[%hu]: couldn't find any request handler for %s ", m_port, request.pathUrl.c_str());
return SendErrorResponse(request, MHD_HTTP_NOT_FOUND, request.method); return SendErrorResponse(request, MHD_HTTP_NOT_FOUND, request.method);
} }
int CWebServer::HandlePostField(void *cls, enum MHD_ValueKind kind, const char * key, MHD_RESULT CWebServer::HandlePostField(void *cls, enum MHD_ValueKind kind, const char *key,
const char *filename, const char *content_type, const char *filename, const char *content_type,
const char *transfer_encoding, const char *data, uint64_t off, const char *transfer_encoding, const char *data, uint64_t off,
size_t size) size_t size)
{ {
ConnectionHandler *conHandler = (ConnectionHandler *)cls; ConnectionHandler *conHandler = (ConnectionHandler *)cls;
if (conHandler == nullptr || conHandler->requestHandler == nullptr || if (conHandler == nullptr || conHandler->requestHandler == nullptr ||
key == nullptr || data == nullptr || size == 0) key == nullptr || data == nullptr || size == 0)
{ {
CLog::Log(LOGERROR, "CWebServer: unable to handle HTTP POST field"); CLog::Log(LOGERROR, "CWebServer: unable to handle HTTP POST field");
return MHD_NO; return MHD_NO;
} }
conHandler->requestHandler->AddPostField(key, std::string(data, size)); conHandler->requestHandler->AddPostField(key, std::string(data, size));
return MHD_YES; return MHD_YES;
} }
int CWebServer::HandleRequest(const std::shared_ptr<IHTTPRequestHandler>& handle r) MHD_RESULT CWebServer::HandleRequest(const std::shared_ptr<IHTTPRequestHandler>& handler)
{ {
if (handler == nullptr) if (handler == nullptr)
return MHD_NO; return MHD_NO;
HTTPRequest request = handler->GetRequest(); HTTPRequest request = handler->GetRequest();
int ret = handler->HandleRequest(); MHD_RESULT ret = handler->HandleRequest();
if (ret == MHD_NO) if (ret == MHD_NO)
{ {
CLog::Log(LOGERROR, "CWebServer[%hu]: failed to handle HTTP request for %s", m_port, request.pathUrl.c_str()); CLog::Log(LOGERROR, "CWebServer[%hu]: failed to handle HTTP request for %s", m_port, request.pathUrl.c_str());
return SendErrorResponse(request, MHD_HTTP_INTERNAL_SERVER_ERROR, request.me thod); return SendErrorResponse(request, MHD_HTTP_INTERNAL_SERVER_ERROR, request.me thod);
} }
const HTTPResponseDetails &responseDetails = handler->GetResponseDetails(); const HTTPResponseDetails &responseDetails = handler->GetResponseDetails();
struct MHD_Response *response = nullptr; struct MHD_Response *response = nullptr;
switch (responseDetails.type) switch (responseDetails.type)
{ {
skipping to change at line 351 skipping to change at line 354
if (ret == MHD_NO) if (ret == MHD_NO)
{ {
CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create HTTP response for %s" , m_port, request.pathUrl.c_str()); CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create HTTP response for %s" , m_port, request.pathUrl.c_str());
return SendErrorResponse(request, MHD_HTTP_INTERNAL_SERVER_ERROR, request.me thod); return SendErrorResponse(request, MHD_HTTP_INTERNAL_SERVER_ERROR, request.me thod);
} }
return FinalizeRequest(handler, responseDetails.status, response); return FinalizeRequest(handler, responseDetails.status, response);
} }
int CWebServer::FinalizeRequest(const std::shared_ptr<IHTTPRequestHandler>& hand ler, int responseStatus, struct MHD_Response *response) MHD_RESULT CWebServer::FinalizeRequest(const std::shared_ptr<IHTTPRequestHandler >& handler, int responseStatus, struct MHD_Response *response)
{ {
if (handler == nullptr || response == nullptr) if (handler == nullptr || response == nullptr)
return MHD_NO; return MHD_NO;
const HTTPRequest &request = handler->GetRequest(); const HTTPRequest &request = handler->GetRequest();
const HTTPResponseDetails &responseDetails = handler->GetResponseDetails(); const HTTPResponseDetails &responseDetails = handler->GetResponseDetails();
// if the request handler has set a content type and it hasn't been set as a h eader, add it // if the request handler has set a content type and it hasn't been set as a h eader, add it
if (!responseDetails.contentType.empty()) if (!responseDetails.contentType.empty())
handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_TYPE, responseDetails.con tentType); handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_TYPE, responseDetails.con tentType);
skipping to change at line 565 skipping to change at line 568
} }
void CWebServer::FinalizePostDataProcessing(ConnectionHandler *connectionHandler ) const void CWebServer::FinalizePostDataProcessing(ConnectionHandler *connectionHandler ) const
{ {
if (connectionHandler->postprocessor == nullptr) if (connectionHandler->postprocessor == nullptr)
return; return;
MHD_destroy_post_processor(connectionHandler->postprocessor); MHD_destroy_post_processor(connectionHandler->postprocessor);
} }
int CWebServer::CreateMemoryDownloadResponse(const std::shared_ptr<IHTTPRequestH andler>& handler, struct MHD_Response *&response) const MHD_RESULT CWebServer::CreateMemoryDownloadResponse(const std::shared_ptr<IHTTPR equestHandler>& handler, struct MHD_Response *&response) const
{ {
if (handler == nullptr) if (handler == nullptr)
return MHD_NO; return MHD_NO;
const HTTPRequest &request = handler->GetRequest(); const HTTPRequest &request = handler->GetRequest();
const HTTPResponseDetails &responseDetails = handler->GetResponseDetails(); const HTTPResponseDetails &responseDetails = handler->GetResponseDetails();
HttpResponseRanges responseRanges = handler->GetResponseData(); HttpResponseRanges responseRanges = handler->GetResponseData();
// check if the response is completely empty // check if the response is completely empty
if (responseRanges.empty()) if (responseRanges.empty())
skipping to change at line 623 skipping to change at line 626
return CreateMemoryDownloadResponse(request.connection, responseData, resp onseDataLength, true, true, response); return CreateMemoryDownloadResponse(request.connection, responseData, resp onseDataLength, true, true, response);
default: default:
return SendErrorResponse(request, MHD_HTTP_INTERNAL_SERVER_ERROR, request. method); return SendErrorResponse(request, MHD_HTTP_INTERNAL_SERVER_ERROR, request. method);
} }
} }
return CreateRangedMemoryDownloadResponse(handler, response); return CreateRangedMemoryDownloadResponse(handler, response);
} }
int CWebServer::CreateRangedMemoryDownloadResponse(const std::shared_ptr<IHTTPRe questHandler>& handler, struct MHD_Response *&response) const MHD_RESULT CWebServer::CreateRangedMemoryDownloadResponse(const std::shared_ptr< IHTTPRequestHandler>& handler, struct MHD_Response *&response) const
{ {
if (handler == nullptr) if (handler == nullptr)
return MHD_NO; return MHD_NO;
const HTTPRequest &request = handler->GetRequest(); const HTTPRequest &request = handler->GetRequest();
const HTTPResponseDetails &responseDetails = handler->GetResponseDetails(); const HTTPResponseDetails &responseDetails = handler->GetResponseDetails();
HttpResponseRanges responseRanges = handler->GetResponseData(); HttpResponseRanges responseRanges = handler->GetResponseData();
// if there's no or only one range this is not the right place // if there's no or only one range this is not the right place
if (responseRanges.size() <= 1) if (responseRanges.size() <= 1)
skipping to change at line 703 skipping to change at line 706
result += HttpRangeUtils::GenerateMultipartBoundaryEnd(multipartBoundary); result += HttpRangeUtils::GenerateMultipartBoundaryEnd(multipartBoundary);
// add Content-Length header // add Content-Length header
handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_LENGTH, StringUtils::Format ("%" PRIu64, static_cast<uint64_t>(result.size()))); handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_LENGTH, StringUtils::Format ("%" PRIu64, static_cast<uint64_t>(result.size())));
// finally create the response // finally create the response
return CreateMemoryDownloadResponse(request.connection, result.c_str(), result .size(), false, true, response); return CreateMemoryDownloadResponse(request.connection, result.c_str(), result .size(), false, true, response);
} }
int CWebServer::CreateRedirect(struct MHD_Connection *connection, const std::str ing &strURL, struct MHD_Response *&response) const MHD_RESULT CWebServer::CreateRedirect(struct MHD_Connection *connection, const s td::string &strURL, struct MHD_Response *&response) const
{ {
response = create_response(0, nullptr, MHD_NO, MHD_NO); response = create_response(0, nullptr, MHD_NO, MHD_NO);
if (response == nullptr) if (response == nullptr)
{ {
CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create HTTP redirect respons e to %s", m_port, strURL.c_str()); CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create HTTP redirect respons e to %s", m_port, strURL.c_str());
return MHD_NO; return MHD_NO;
} }
AddHeader(response, MHD_HTTP_HEADER_LOCATION, strURL); AddHeader(response, MHD_HTTP_HEADER_LOCATION, strURL);
return MHD_YES; return MHD_YES;
} }
int CWebServer::CreateFileDownloadResponse(const std::shared_ptr<IHTTPRequestHan dler>& handler, struct MHD_Response *&response) const MHD_RESULT CWebServer::CreateFileDownloadResponse(const std::shared_ptr<IHTTPReq uestHandler>& handler, struct MHD_Response *&response) const
{ {
if (handler == nullptr) if (handler == nullptr)
return MHD_NO; return MHD_NO;
const HTTPRequest &request = handler->GetRequest(); const HTTPRequest &request = handler->GetRequest();
const HTTPResponseDetails &responseDetails = handler->GetResponseDetails(); const HTTPResponseDetails &responseDetails = handler->GetResponseDetails();
HttpResponseRanges responseRanges = handler->GetResponseData(); HttpResponseRanges responseRanges = handler->GetResponseData();
std::shared_ptr<XFILE::CFile> file = std::make_shared<XFILE::CFile>(); std::shared_ptr<XFILE::CFile> file = std::make_shared<XFILE::CFile>();
std::string filePath = handler->GetResponseFile(); std::string filePath = handler->GetResponseFile();
skipping to change at line 853 skipping to change at line 856
handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_LENGTH, StringUtils::Form at("%" PRId64, fileLength)); handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_LENGTH, StringUtils::Form at("%" PRId64, fileLength));
} }
// set the Content-Type header // set the Content-Type header
if (!mimeType.empty()) if (!mimeType.empty())
handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_TYPE, mimeType); handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_TYPE, mimeType);
return MHD_YES; return MHD_YES;
} }
int CWebServer::CreateErrorResponse(struct MHD_Connection *connection, int respo nseType, HTTPMethod method, struct MHD_Response *&response) const MHD_RESULT CWebServer::CreateErrorResponse(struct MHD_Connection *connection, in t responseType, HTTPMethod method, struct MHD_Response *&response) const
{ {
size_t payloadSize = 0; size_t payloadSize = 0;
const void *payload = nullptr; const void *payload = nullptr;
if (method != HEAD) if (method != HEAD)
{ {
switch (responseType) switch (responseType)
{ {
case MHD_HTTP_NOT_FOUND: case MHD_HTTP_NOT_FOUND:
payloadSize = strlen(PAGE_FILE_NOT_FOUND); payloadSize = strlen(PAGE_FILE_NOT_FOUND);
skipping to change at line 884 skipping to change at line 887
response = create_response(payloadSize, payload, MHD_NO, MHD_NO); response = create_response(payloadSize, payload, MHD_NO, MHD_NO);
if (response == nullptr) if (response == nullptr)
{ {
CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create a HTTP %d error respo nse", m_port, responseType); CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create a HTTP %d error respo nse", m_port, responseType);
return MHD_NO; return MHD_NO;
} }
return MHD_YES; return MHD_YES;
} }
int CWebServer::CreateMemoryDownloadResponse(struct MHD_Connection *connection, const void *data, size_t size, bool free, bool copy, struct MHD_Response *&respo nse) const MHD_RESULT CWebServer::CreateMemoryDownloadResponse(struct MHD_Connection *conne ction, const void *data, size_t size, bool free, bool copy, struct MHD_Response *&response) const
{ {
response = create_response(size, const_cast<void*>(data), free ? MHD_YES : MHD _NO, copy ? MHD_YES : MHD_NO); response = create_response(size, const_cast<void*>(data), free ? MHD_YES : MHD _NO, copy ? MHD_YES : MHD_NO);
if (response == nullptr) if (response == nullptr)
{ {
CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create a HTTP download respo nse", m_port); CLog::Log(LOGERROR, "CWebServer[%hu]: failed to create a HTTP download respo nse", m_port);
return MHD_NO; return MHD_NO;
} }
return MHD_YES; return MHD_YES;
} }
int CWebServer::SendResponse(const HTTPRequest& request, int responseStatus, MHD _Response *response) const MHD_RESULT CWebServer::SendResponse(const HTTPRequest& request, int responseStat us, MHD_Response *response) const
{ {
LogResponse(request, responseStatus); LogResponse(request, responseStatus);
int ret = MHD_queue_response(request.connection, responseStatus, response); MHD_RESULT ret = MHD_queue_response(request.connection, responseStatus, respon se);
MHD_destroy_response(response); MHD_destroy_response(response);
return ret; return ret;
} }
int CWebServer::SendErrorResponse(const HTTPRequest& request, int errorType, HTT PMethod method) const MHD_RESULT CWebServer::SendErrorResponse(const HTTPRequest& request, int errorTy pe, HTTPMethod method) const
{ {
struct MHD_Response *response = nullptr; struct MHD_Response *response = nullptr;
int ret = CreateErrorResponse(request.connection, errorType, method, response) ; MHD_RESULT ret = CreateErrorResponse(request.connection, errorType, method, re sponse);
if (ret == MHD_NO) if (ret == MHD_NO)
return MHD_NO; return MHD_NO;
return SendResponse(request, errorType, response); return SendResponse(request, errorType, response);
} }
void* CWebServer::UriRequestLogger(void *cls, const char *uri) void* CWebServer::UriRequestLogger(void *cls, const char *uri)
{ {
CWebServer *webServer = reinterpret_cast<CWebServer*>(cls); CWebServer *webServer = reinterpret_cast<CWebServer*>(cls);
skipping to change at line 1299 skipping to change at line 1302
std::string CWebServer::CreateMimeTypeFromExtension(const char *ext) std::string CWebServer::CreateMimeTypeFromExtension(const char *ext)
{ {
if (strcmp(ext, ".kar") == 0) if (strcmp(ext, ".kar") == 0)
return "audio/midi"; return "audio/midi";
if (strcmp(ext, ".tbn") == 0) if (strcmp(ext, ".tbn") == 0)
return "image/jpeg"; return "image/jpeg";
return CMime::GetMimeType(ext); return CMime::GetMimeType(ext);
} }
int CWebServer::AddHeader(struct MHD_Response *response, const std::string &name , const std::string &value) const MHD_RESULT CWebServer::AddHeader(struct MHD_Response *response, const std::strin g &name, const std::string &value) const
{ {
if (response == nullptr || name.empty()) if (response == nullptr || name.empty())
return 0; return MHD_NO;
CLog::Log(LOGDEBUG, LOGWEBSERVER, "CWebServer[%hu] [OUT] %s: %s", m_port, name .c_str(), value.c_str()); CLog::Log(LOGDEBUG, LOGWEBSERVER, "CWebServer[%hu] [OUT] %s: %s", m_port, name .c_str(), value.c_str());
return MHD_add_response_header(response, name.c_str(), value.c_str()); return MHD_add_response_header(response, name.c_str(), value.c_str());
} }
 End of changes. 21 change blocks. 
22 lines changed or deleted 27 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)