From ae45a2d311cca04e337d221656ed0668103d2a53 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Thu, 23 Aug 2012 04:27:50 +0000 Subject: [PATCH] porting 1.4.4 rev. 1929, 1939 (SF# 3552680 et. al) --- Foundation/include/Poco/AbstractEvent.h | 2 ++ Foundation/include/Poco/AtomicCounter.h | 18 +++++++++++------- Net/include/Poco/Net/MessageHeader.h | 7 ++++++- Net/src/MessageHeader.cpp | 14 ++++++++++++++ Net/src/WebSocketImpl.cpp | 21 ++++++++++++++++++++- libversion | 2 +- 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Foundation/include/Poco/AbstractEvent.h b/Foundation/include/Poco/AbstractEvent.h index f32c3edce..b8a41074f 100644 --- a/Foundation/include/Poco/AbstractEvent.h +++ b/Foundation/include/Poco/AbstractEvent.h @@ -171,6 +171,8 @@ class AbstractEvent /// to create the PriorityDelegate. { public: + typedef TArgs Args; + AbstractEvent(): _executeAsync(this, &AbstractEvent::executeAsyncImpl), _enabled(true) diff --git a/Foundation/include/Poco/AtomicCounter.h b/Foundation/include/Poco/AtomicCounter.h index 1c8f2cc3a..07a37a6a5 100644 --- a/Foundation/include/Poco/AtomicCounter.h +++ b/Foundation/include/Poco/AtomicCounter.h @@ -42,15 +42,19 @@ #include "Poco/Foundation.h" #if POCO_OS == POCO_OS_WINDOWS_NT -#include "Poco/UnWindows.h" + #include "Poco/UnWindows.h" #elif POCO_OS == POCO_OS_MAC_OS_X -#include -#elif ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) && (defined(__x86_64__) || defined(__i386__)) -#if !defined(POCO_HAVE_GCC_ATOMICS) -#define POCO_HAVE_GCC_ATOMICS -#endif + #include +#elif ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2) || __GNUC__ > 4) && (defined(__x86_64__) || defined(__i386__)) + #if !defined(POCO_HAVE_GCC_ATOMICS) && !defined(POCO_NO_GCC_ATOMICS) + #define POCO_HAVE_GCC_ATOMICS + #endif +#elif ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3) || __GNUC__ > 4) + #if !defined(POCO_HAVE_GCC_ATOMICS) && !defined(POCO_NO_GCC_ATOMICS) + #define POCO_HAVE_GCC_ATOMICS + #endif #else -#include "Poco/Mutex.h" + #include "Poco/Mutex.h" #endif // POCO_OS diff --git a/Net/include/Poco/Net/MessageHeader.h b/Net/include/Poco/Net/MessageHeader.h index aab8196da..32aac6a30 100644 --- a/Net/include/Poco/Net/MessageHeader.h +++ b/Net/include/Poco/Net/MessageHeader.h @@ -122,7 +122,12 @@ public: /// Specify 0 for unlimited (not recommended). /// /// The default limit is 100. - + + bool hasToken(const std::string& fieldName, const std::string& token) const; + /// Returns true iff the field with the given fieldName contains + /// the given token. Tokens in a header field are expected to be + /// comma-separated and are case insensitive. + static void splitElements(const std::string& s, std::vector& elements, bool ignoreEmpty = true); /// Splits the given string into separate elements. Elements are expected /// to be separated by commas. diff --git a/Net/src/MessageHeader.cpp b/Net/src/MessageHeader.cpp index 625449aa2..3ed951805 100644 --- a/Net/src/MessageHeader.cpp +++ b/Net/src/MessageHeader.cpp @@ -139,6 +139,20 @@ void MessageHeader::setFieldLimit(int limit) } +bool MessageHeader::hasToken(const std::string& fieldName, const std::string& token) const +{ + std::string field = get(fieldName, ""); + std::vector tokens; + splitElements(field, tokens, true); + for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) + { + if (Poco::icompare(*it, token) == 0) + return true; + } + return false; +} + + void MessageHeader::splitElements(const std::string& s, std::vector& elements, bool ignoreEmpty) { elements.clear(); diff --git a/Net/src/WebSocketImpl.cpp b/Net/src/WebSocketImpl.cpp index 4ed746f23..e1f155582 100644 --- a/Net/src/WebSocketImpl.cpp +++ b/Net/src/WebSocketImpl.cpp @@ -118,9 +118,28 @@ int WebSocketImpl::sendBytes(const void* buffer, int length, int flags) int WebSocketImpl::receiveBytes(void* buffer, int length, int) { char header[MAX_HEADER_LENGTH]; - int n = _pStreamSocketImpl->receiveBytes(header, MAX_HEADER_LENGTH); + int n = _pStreamSocketImpl->receiveBytes(header, 2); + if (n == 1) + { + n += _pStreamSocketImpl->receiveBytes(header + 1, 1); + } + if (n == 2) + { + Poco::UInt8 lengthByte = static_cast(header[1]) & 0x7f; + if (lengthByte + 2 < MAX_HEADER_LENGTH) + { + n = _pStreamSocketImpl->receiveBytes(header + 2, lengthByte); + } + else + { + n = _pStreamSocketImpl->receiveBytes(header + 2, MAX_HEADER_LENGTH - 2); + } + } + else throw WebSocketException("Incomplete frame received", WebSocket::WS_ERR_INCOMPLETE_FRAME); + if (n > 0) { + n += 2; Poco::MemoryInputStream istr(header, n); Poco::BinaryReader reader(istr, Poco::BinaryReader::NETWORK_BYTE_ORDER); Poco::UInt8 flags; diff --git a/libversion b/libversion index 8351c1939..60d3b2f4a 100644 --- a/libversion +++ b/libversion @@ -1 +1 @@ -14 +15