]> git.sesse.net Git - casparcg/commitdiff
Filter unprintable characters that might be inside of received message.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 10 Feb 2012 10:36:35 +0000 (10:36 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 10 Feb 2012 10:36:35 +0000 (10:36 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/trunk@2332 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/log/log.h
protocol/amcp/AMCPProtocolStrategy.cpp
protocol/cii/CIIProtocolStrategy.cpp

index a850f793b8764c93a36560f2e42e4100c153f981..c1e782abfc1fdd6222d31f335b6406aaadbd876a 100644 (file)
@@ -36,6 +36,9 @@
 #include <boost/log/sources/severity_logger.hpp>\r
 #include <boost/log/sources/record_ostream.hpp>\r
 \r
+#include <string>\r
+#include <locale>\r
+\r
 namespace caspar { namespace log {\r
        \r
 namespace internal{\r
@@ -95,6 +98,20 @@ BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
 \r
 void set_log_level(const std::wstring& lvl);\r
 \r
+template<typename T>\r
+inline void replace_nonprintable(std::basic_string<T, std::char_traits<T>, std::allocator<T>>& str, T with)\r
+{\r
+       std::locale loc;\r
+       std::replace_if(str.begin(), str.end(), [&](T c)->bool { return !std::isprint(c, loc); }, with);\r
+}\r
+\r
+template<typename T>\r
+inline std::basic_string<T> replace_nonprintable_copy(std::basic_string<T, std::char_traits<T>, std::allocator<T>> str, T with)\r
+{\r
+       replace_nonprintable(str, with);\r
+       return str;\r
+}\r
+\r
 }}\r
 \r
 #if defined(_MSC_VER)\r
index d7abbfeeb509100a327f54c8e08ac1a3053e9f24..f51f2da206cff299191d524786f90d91881c15a3 100644 (file)
@@ -112,7 +112,7 @@ void AMCPProtocolStrategy::Parse(const TCHAR* pData, int charCount, ClientInfoPt
 \r
 void AMCPProtocolStrategy::ProcessMessage(const std::wstring& message, ClientInfoPtr& pClientInfo)\r
 {      \r
-       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message + L"\\r\\n";\r
+       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << log::replace_nonprintable_copy(message, L'?') + L"\\r\\n";\r
        \r
        bool bError = true;\r
        MessageParserState state = New;\r
index 6499ae9b3447752481a5c8d20fa4316d9a792599..3fb2ff320c33228db5437da3a3475ed4351dc43c 100644 (file)
@@ -85,7 +85,7 @@ void CIIProtocolStrategy::Parse(const TCHAR* pData, int charCount, IO::ClientInf
 \r
 void CIIProtocolStrategy::ProcessMessage(const std::wstring& message, IO::ClientInfoPtr pClientInfo)\r
 {      \r
-       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message + L"\\r\\n";\r
+       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << log::replace_nonprintable_copy(message, L'?') + L"\\r\\n";\r
 \r
        std::vector<std::wstring> tokens;\r
        int tokenCount = TokenizeMessage(message, &tokens);\r