C++11 compatible
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#include "IXUniquePtr.h"
|
||||
#include <cassert>
|
||||
#include <errno.h>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <Shlwapi.h>
|
||||
#else
|
||||
@ -86,7 +87,7 @@ namespace ix
|
||||
|
||||
std::atomic<bool> SocketOpenSSL::_openSSLInitializationSuccessful(false);
|
||||
std::once_flag SocketOpenSSL::_openSSLInitFlag;
|
||||
std::array<std::mutex, CRYPTO_num_locks()> openSSLMutexes;
|
||||
std::vector<std::unique_ptr<std::mutex>> openSSLMutexes;
|
||||
|
||||
SocketOpenSSL::SocketOpenSSL(const SocketTLSOptions& tlsOptions, int fd)
|
||||
: Socket(fd)
|
||||
@ -111,6 +112,11 @@ namespace ix
|
||||
|
||||
if (CRYPTO_get_locking_callback() == nullptr)
|
||||
{
|
||||
openSSLMutexes.clear();
|
||||
for (int i = 0; i < CRYPTO_num_locks(); ++i)
|
||||
{
|
||||
openSSLMutexes.push_back(ix::make_unique<std::mutex>());
|
||||
}
|
||||
CRYPTO_set_locking_callback(SocketOpenSSL::openSSLLockingCallback);
|
||||
}
|
||||
#endif
|
||||
@ -128,11 +134,11 @@ namespace ix
|
||||
{
|
||||
if (mode & CRYPTO_LOCK)
|
||||
{
|
||||
openSSLMutexes[type].lock();
|
||||
openSSLMutexes[type]->lock();
|
||||
}
|
||||
else
|
||||
{
|
||||
openSSLMutexes[type].unlock();
|
||||
openSSLMutexes[type]->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
37
ixwebsocket/IXStrCaseCompare.cpp
Normal file
37
ixwebsocket/IXStrCaseCompare.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* IXStrCaseCompare.cpp
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2020 Machine Zone. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "IXStrCaseCompare.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
bool CaseInsensitiveLess::NocaseCompare::operator()(const unsigned char& c1,
|
||||
const unsigned char& c2) const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return std::tolower(c1, std::locale()) < std::tolower(c2, std::locale());
|
||||
#else
|
||||
return std::tolower(c1) < std::tolower(c2);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CaseInsensitiveLess::cmp(const std::string& s1, const std::string& s2)
|
||||
{
|
||||
return std::lexicographical_compare(s1.begin(),
|
||||
s1.end(), // source range
|
||||
s2.begin(),
|
||||
s2.end(), // dest range
|
||||
NocaseCompare()); // comparison
|
||||
}
|
||||
|
||||
bool CaseInsensitiveLess::operator()(const std::string& s1, const std::string& s2) const
|
||||
{
|
||||
return CaseInsensitiveLess::cmp(s1, s2);
|
||||
}
|
||||
} // namespace ix
|
25
ixwebsocket/IXStrCaseCompare.h
Normal file
25
ixwebsocket/IXStrCaseCompare.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* IXStrCaseCompare.h
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2020 Machine Zone. All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
struct CaseInsensitiveLess
|
||||
{
|
||||
// Case Insensitive compare_less binary function
|
||||
struct NocaseCompare
|
||||
{
|
||||
bool operator()(const unsigned char& c1, const unsigned char& c2) const;
|
||||
};
|
||||
|
||||
static bool cmp(const std::string& s1, const std::string& s2);
|
||||
|
||||
bool operator()(const std::string& s1, const std::string& s2) const;
|
||||
};
|
||||
} // namespace ix
|
@ -11,6 +11,7 @@
|
||||
#include "IXUrlParser.h"
|
||||
#include "IXUserAgent.h"
|
||||
#include "IXWebSocketHandshakeKeyGen.h"
|
||||
#include "IXStrCaseCompare.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
@ -35,9 +36,7 @@ namespace ix
|
||||
|
||||
bool WebSocketHandshake::insensitiveStringCompare(const std::string& a, const std::string& b)
|
||||
{
|
||||
return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char a, char b) {
|
||||
return tolower(a) == tolower(b);
|
||||
});
|
||||
return CaseInsensitiveLess::cmp(a, b);
|
||||
}
|
||||
|
||||
std::string WebSocketHandshake::genRandomString(const int len)
|
||||
|
@ -12,25 +12,6 @@
|
||||
|
||||
namespace ix
|
||||
{
|
||||
bool CaseInsensitiveLess::NocaseCompare::operator()(const unsigned char& c1,
|
||||
const unsigned char& c2) const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return std::tolower(c1, std::locale()) < std::tolower(c2, std::locale());
|
||||
#else
|
||||
return std::tolower(c1) < std::tolower(c2);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CaseInsensitiveLess::operator()(const std::string& s1, const std::string& s2) const
|
||||
{
|
||||
return std::lexicographical_compare(s1.begin(),
|
||||
s1.end(), // source range
|
||||
s2.begin(),
|
||||
s2.end(), // dest range
|
||||
NocaseCompare()); // comparison
|
||||
}
|
||||
|
||||
std::pair<bool, WebSocketHttpHeaders> parseHttpHeaders(
|
||||
std::unique_ptr<Socket>& socket, const CancellationRequest& isCancellationRequested)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "IXCancellationRequest.h"
|
||||
#include "IXStrCaseCompare.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -15,17 +16,6 @@ namespace ix
|
||||
{
|
||||
class Socket;
|
||||
|
||||
struct CaseInsensitiveLess
|
||||
{
|
||||
// Case Insensitive compare_less binary function
|
||||
struct NocaseCompare
|
||||
{
|
||||
bool operator()(const unsigned char& c1, const unsigned char& c2) const;
|
||||
};
|
||||
|
||||
bool operator()(const std::string& s1, const std::string& s2) const;
|
||||
};
|
||||
|
||||
using WebSocketHttpHeaders = std::map<std::string, std::string, CaseInsensitiveLess>;
|
||||
|
||||
std::pair<bool, WebSocketHttpHeaders> parseHttpHeaders(
|
||||
|
Reference in New Issue
Block a user