From a74f0c69c1ea1dd3f5aa105609159f3929041b49 Mon Sep 17 00:00:00 2001 From: Karlson2k Date: Fri, 12 Dec 2014 22:00:42 +0300 Subject: [PATCH] WebServer: write messages from MHD to log --- xbmc/network/WebServer.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/xbmc/network/WebServer.cpp b/xbmc/network/WebServer.cpp index 86b80752fcc67..e51b87672b4f0 100644 --- a/xbmc/network/WebServer.cpp +++ b/xbmc/network/WebServer.cpp @@ -1035,6 +1035,27 @@ void CWebServer::ContentReaderFreeCallback(void *cls) #endif } +// local helper +static void logFromMHD(void* unused, const char* fmt, va_list ap) +{ + if (fmt == NULL || fmt[0] == 0) + CLog::Log(LOGERROR, "CWebServer: MHD reported error with empty string"); + else + { + std::string errDsc = StringUtils::FormatV(fmt, ap); + if (errDsc.empty()) + CLog::Log(LOGERROR, "CWebServer: MHD reported error with unprintable string \"%s\"", fmt); + else + { + if (errDsc.at(errDsc.length() - 1) == '\n') + errDsc.erase(errDsc.length() - 1); + + // Most common error is "aborted connection", so log it at LOGDEBUG level + CLog::Log(LOGDEBUG, "CWebServer [MHD]: %s", errDsc.c_str()); + } + } +} + struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port) { unsigned int timeout = 60 * 60 * 24; @@ -1050,6 +1071,9 @@ struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port) // otherwise on libmicrohttpd 0.4.4-1 it spins a busy loop MHD_USE_THREAD_PER_CONNECTION #endif +#if (MHD_VERSION >= 0x00040001) + | MHD_USE_DEBUG /* Print MHD error messages to log */ +#endif , port, NULL, @@ -1063,6 +1087,9 @@ struct MHD_Daemon* CWebServer::StartMHD(unsigned int flags, int port) MHD_OPTION_CONNECTION_LIMIT, 512, MHD_OPTION_CONNECTION_TIMEOUT, timeout, MHD_OPTION_URI_LOG_CALLBACK, &CWebServer::UriRequestLogger, this, +#if (MHD_VERSION >= 0x00040001) + MHD_OPTION_EXTERNAL_LOGGER, &logFromMHD, NULL, +#endif // MHD_VERSION >= 0x00040001 MHD_OPTION_END); }