"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xbmc/network/WebServer.cpp" between
xbmc-19.0-Matrix.tar.gz and xbmc-19.1.tar.gz

About:

WebServer.cpp  (xbmc-19.0-Matrix):WebServer.cpp  (xbmc-19.1)
skipping to change at line 64 skipping to change at line 64
CHttpRanges ranges; CHttpRanges ranges;
size_t rangeCountTotal; size_t rangeCountTotal;
std::string boundary; std::string boundary;
std::string boundaryWithHeader; std::string boundaryWithHeader;
std::string boundaryEnd; std::string boundaryEnd;
bool boundaryWritten; bool boundaryWritten;
std::string contentType; std::string contentType;
uint64_t writePosition; uint64_t writePosition;
} HttpFileDownloadContext; } HttpFileDownloadContext;
Logger CWebServer::s_logger;
CWebServer::CWebServer() CWebServer::CWebServer()
: m_authenticationUsername("kodi"), : m_authenticationUsername("kodi"),
m_authenticationPassword(""), m_authenticationPassword(""),
m_key(), m_key(),
m_cert(), m_cert(),
m_logger(CServiceBroker::GetLogging().GetLogger("CWebServer")) m_logger(CServiceBroker::GetLogging().GetLogger("CWebServer"))
{ {
#if defined(TARGET_DARWIN) #if defined(TARGET_DARWIN)
void* stack_addr; void* stack_addr;
pthread_attr_t attr; pthread_attr_t attr;
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_getstack(&attr, &stack_addr, &m_thread_stacksize); pthread_attr_getstack(&attr, &stack_addr, &m_thread_stacksize);
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
// double the stack size under darwin, not sure why yet // double the stack size under darwin, not sure why yet
// but it stoped crashing using Kodi iOS remote -> play video. // but it stoped crashing using Kodi iOS remote -> play video.
// non-darwin will pass a value of zero which means 'system default' // non-darwin will pass a value of zero which means 'system default'
m_thread_stacksize *= 2; m_thread_stacksize *= 2;
m_logger->debug("increasing thread stack to {}", m_thread_stacksize); m_logger->debug("increasing thread stack to {}", m_thread_stacksize);
#endif #endif
if (s_logger == nullptr)
s_logger = CServiceBroker::GetLogging().GetLogger("CWebServer");
} }
static MHD_Response* create_response(size_t size, const void* data, int free, in t copy) static MHD_Response* create_response(size_t size, const void* data, int free, in t copy)
{ {
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
skipping to change at line 166 skipping to change at line 161
struct MHD_Connection* connection, struct MHD_Connection* connection,
const char* url, const char* url,
const char* method, const char* method,
const char* version, const char* version,
const char* upload_data, const char* upload_data,
size_t* upload_data_size, size_t* upload_data_size,
void** con_cls) void** con_cls)
{ {
if (cls == nullptr || con_cls == nullptr || *con_cls == nullptr) if (cls == nullptr || con_cls == nullptr || *con_cls == nullptr)
{ {
s_logger->error("invalid request received"); GetLogger()->error("invalid request received");
return MHD_NO; return MHD_NO;
} }
CWebServer* webServer = reinterpret_cast<CWebServer*>(cls); CWebServer* webServer = reinterpret_cast<CWebServer*>(cls);
if (webServer == nullptr) if (webServer == nullptr)
{ {
s_logger->error("invalid request received"); GetLogger()->error("invalid request received");
return MHD_NO; return MHD_NO;
} }
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, HTTPRequest request = {webServer, connection, connectionHandler->fullUri,
url, methodType, version}; url, methodType, version};
if (connectionHandler->isNew) if (connectionHandler->isNew)
webServer->LogRequest(request); webServer->LogRequest(request);
skipping to change at line 326 skipping to change at line 321
const char* transfer_encoding, const char* transfer_encoding,
const char* data, const char* data,
uint64_t off, uint64_t off,
size_t size) size_t size)
{ {
ConnectionHandler* conHandler = (ConnectionHandler*)cls; ConnectionHandler* conHandler = (ConnectionHandler*)cls;
if (conHandler == nullptr || conHandler->requestHandler == nullptr || key == n ullptr || if (conHandler == nullptr || conHandler->requestHandler == nullptr || key == n ullptr ||
data == nullptr || size == 0) data == nullptr || size == 0)
{ {
s_logger->error("unable to handle HTTP POST field"); GetLogger()->error("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;
} }
MHD_RESULT CWebServer::HandleRequest(const std::shared_ptr<IHTTPRequestHandler>& handler) MHD_RESULT CWebServer::HandleRequest(const std::shared_ptr<IHTTPRequestHandler>& handler)
{ {
if (handler == nullptr) if (handler == nullptr)
skipping to change at line 1029 skipping to change at line 1024
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);
// log the full URI // log the full URI
if (webServer == nullptr) if (webServer == nullptr)
s_logger->debug("request received for {}", uri); GetLogger()->debug("request received for {}", uri);
else else
webServer->LogRequest(uri); webServer->LogRequest(uri);
// create and return a new connection handler // create and return a new connection handler
return new ConnectionHandler(uri); return new ConnectionHandler(uri);
} }
void CWebServer::LogRequest(const char* uri) const void CWebServer::LogRequest(const char* uri) const
{ {
if (uri == nullptr) if (uri == nullptr)
skipping to change at line 1052 skipping to change at line 1047
m_logger->debug("request received for {}", uri); m_logger->debug("request received for {}", uri);
} }
ssize_t CWebServer::ContentReaderCallback(void* cls, uint64_t pos, char* buf, si ze_t max) ssize_t CWebServer::ContentReaderCallback(void* cls, uint64_t pos, char* buf, si ze_t max)
{ {
HttpFileDownloadContext* context = (HttpFileDownloadContext*)cls; HttpFileDownloadContext* context = (HttpFileDownloadContext*)cls;
if (context == nullptr || context->file == nullptr) if (context == nullptr || context->file == nullptr)
return -1; return -1;
if (CServiceBroker::GetLogging().CanLogComponent(LOGWEBSERVER)) if (CServiceBroker::GetLogging().CanLogComponent(LOGWEBSERVER))
s_logger->debug("[OUT] write maximum {} bytes from {} ({})", max, context->w GetLogger()->debug("[OUT] write maximum {} bytes from {} ({})", max, context
ritePosition, pos); ->writePosition,
pos);
// check if we need to add the end-boundary // check if we need to add the end-boundary
if (context->rangeCountTotal > 1 && context->ranges.IsEmpty()) if (context->rangeCountTotal > 1 && context->ranges.IsEmpty())
{ {
// put together the end-boundary // put together the end-boundary
std::string endBoundary = HttpRangeUtils::GenerateMultipartBoundaryEnd(conte xt->boundary); std::string endBoundary = HttpRangeUtils::GenerateMultipartBoundaryEnd(conte xt->boundary);
if ((unsigned int)max != endBoundary.size()) if ((unsigned int)max != endBoundary.size())
return -1; return -1;
// copy the boundary into the buffer // copy the boundary into the buffer
skipping to change at line 1124 skipping to change at line 1120
// read data from the file // read data from the file
ssize_t res = context->file->Read(buf, static_cast<size_t>(maximum)); ssize_t res = context->file->Read(buf, static_cast<size_t>(maximum));
if (res <= 0) if (res <= 0)
return -1; return -1;
// add the number of read bytes to the number of written bytes // add the number of read bytes to the number of written bytes
written += res; written += res;
if (CServiceBroker::GetLogging().CanLogComponent(LOGWEBSERVER)) if (CServiceBroker::GetLogging().CanLogComponent(LOGWEBSERVER))
s_logger->debug("[OUT] wrote {} bytes from {} in range ({} - {})", written, GetLogger()->debug("[OUT] wrote {} bytes from {} in range ({} - {})", writte
context->writePosition, start, end); n,
context->writePosition, start, end);
// update the current write position // update the current write position
context->writePosition += res; context->writePosition += res;
// if we have read all the data from the current range // if we have read all the data from the current range
// remove it from the list // remove it from the list
if (context->writePosition >= end + 1) if (context->writePosition >= end + 1)
{ {
context->ranges.Remove(0); context->ranges.Remove(0);
context->boundaryWritten = false; context->boundaryWritten = false;
skipping to change at line 1147 skipping to change at line 1143
return written; return written;
} }
void CWebServer::ContentReaderFreeCallback(void* cls) void CWebServer::ContentReaderFreeCallback(void* cls)
{ {
HttpFileDownloadContext* context = (HttpFileDownloadContext*)cls; HttpFileDownloadContext* context = (HttpFileDownloadContext*)cls;
delete context; delete context;
if (CServiceBroker::GetLogging().CanLogComponent(LOGWEBSERVER)) if (CServiceBroker::GetLogging().CanLogComponent(LOGWEBSERVER))
s_logger->debug("[OUT] done"); GetLogger()->debug("[OUT] done");
} }
// static logger for libmicrohttpd
static Logger GetMhdLogger() static Logger GetMhdLogger()
{ {
static Logger s_logger_mhd = CServiceBroker::GetLogging().GetLogger("libmicroh return CServiceBroker::GetLogging().GetLogger("libmicrohttpd");
ttpd");
return s_logger_mhd;
} }
// local helper // local helper
static void panicHandlerForMHD(void* unused, static void panicHandlerForMHD(void* unused,
const char* file, const char* file,
unsigned int line, unsigned int line,
const char* reason) const char* reason)
{ {
GetMhdLogger()->critical("serious error: reason \"{}\" in file \"{}\" at line {}", GetMhdLogger()->critical("serious error: reason \"{}\" in file \"{}\" at line {}",
reason ? reason : "", file ? file : "", line); reason ? reason : "", file ? file : "", line);
skipping to change at line 1441 skipping to change at line 1435
m_logger->debug("[OUT] {}: {}", name, value); m_logger->debug("[OUT] {}: {}", name, value);
#if MHD_VERSION >= 0x00096800 #if MHD_VERSION >= 0x00096800
if (name == MHD_HTTP_HEADER_CONTENT_LENGTH) if (name == MHD_HTTP_HEADER_CONTENT_LENGTH)
{ {
MHD_set_response_options(response, MHD_RF_INSANITY_HEADER_CONTENT_LENGTH, MH D_RO_END); MHD_set_response_options(response, MHD_RF_INSANITY_HEADER_CONTENT_LENGTH, MH D_RO_END);
} }
#endif #endif
return MHD_add_response_header(response, name.c_str(), value.c_str()); return MHD_add_response_header(response, name.c_str(), value.c_str());
} }
Logger CWebServer::GetLogger()
{
static Logger s_logger = CServiceBroker::GetLogging().GetLogger("CWebServer");
return s_logger;
}
 End of changes. 12 change blocks. 
18 lines changed or deleted 12 lines changed or added

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