porting 1.4.4 rev. 1929, 1939 (SF# 3552680 et. al)

This commit is contained in:
Aleksandar Fabijanic 2012-08-23 04:27:50 +00:00
parent 91b3ca4421
commit ae45a2d311
6 changed files with 54 additions and 10 deletions

View File

@ -171,6 +171,8 @@ class AbstractEvent
/// to create the PriorityDelegate. /// to create the PriorityDelegate.
{ {
public: public:
typedef TArgs Args;
AbstractEvent(): AbstractEvent():
_executeAsync(this, &AbstractEvent::executeAsyncImpl), _executeAsync(this, &AbstractEvent::executeAsyncImpl),
_enabled(true) _enabled(true)

View File

@ -42,15 +42,19 @@
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#if POCO_OS == POCO_OS_WINDOWS_NT #if POCO_OS == POCO_OS_WINDOWS_NT
#include "Poco/UnWindows.h" #include "Poco/UnWindows.h"
#elif POCO_OS == POCO_OS_MAC_OS_X #elif POCO_OS == POCO_OS_MAC_OS_X
#include <libkern/OSAtomic.h> #include <libkern/OSAtomic.h>
#elif ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) && (defined(__x86_64__) || defined(__i386__)) #elif ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2) || __GNUC__ > 4) && (defined(__x86_64__) || defined(__i386__))
#if !defined(POCO_HAVE_GCC_ATOMICS) #if !defined(POCO_HAVE_GCC_ATOMICS) && !defined(POCO_NO_GCC_ATOMICS)
#define POCO_HAVE_GCC_ATOMICS #define POCO_HAVE_GCC_ATOMICS
#endif #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 #else
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
#endif // POCO_OS #endif // POCO_OS

View File

@ -122,7 +122,12 @@ public:
/// Specify 0 for unlimited (not recommended). /// Specify 0 for unlimited (not recommended).
/// ///
/// The default limit is 100. /// 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<std::string>& elements, bool ignoreEmpty = true); static void splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true);
/// Splits the given string into separate elements. Elements are expected /// Splits the given string into separate elements. Elements are expected
/// to be separated by commas. /// to be separated by commas.

View File

@ -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<std::string> tokens;
splitElements(field, tokens, true);
for (std::vector<std::string>::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<std::string>& elements, bool ignoreEmpty) void MessageHeader::splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty)
{ {
elements.clear(); elements.clear();

View File

@ -118,9 +118,28 @@ int WebSocketImpl::sendBytes(const void* buffer, int length, int flags)
int WebSocketImpl::receiveBytes(void* buffer, int length, int) int WebSocketImpl::receiveBytes(void* buffer, int length, int)
{ {
char header[MAX_HEADER_LENGTH]; 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<Poco::UInt8>(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) if (n > 0)
{ {
n += 2;
Poco::MemoryInputStream istr(header, n); Poco::MemoryInputStream istr(header, n);
Poco::BinaryReader reader(istr, Poco::BinaryReader::NETWORK_BYTE_ORDER); Poco::BinaryReader reader(istr, Poco::BinaryReader::NETWORK_BYTE_ORDER);
Poco::UInt8 flags; Poco::UInt8 flags;

View File

@ -1 +1 @@
14 15