Commit 4c8f7c9d authored by john selbie's avatar john selbie

replace all NULL with nullptr

parent 98a7e939
...@@ -110,8 +110,8 @@ HRESULT CreateConfigFromCommandLine(ClientCmdLineArgs& args, StunClientLogicConf ...@@ -110,8 +110,8 @@ HRESULT CreateConfigFromCommandLine(ClientCmdLineArgs& args, StunClientLogicConf
socketconfig.socktype = SOCK_DGRAM; socketconfig.socktype = SOCK_DGRAM;
socketconfig.addrLocal = CSocketAddress(0, 0); socketconfig.addrLocal = CSocketAddress(0, 0);
ChkIfA(pConfig == NULL, E_INVALIDARG); ChkIfA(pConfig == nullptr, E_INVALIDARG);
ChkIfA(pSocketConfig==NULL, E_INVALIDARG); ChkIfA(pSocketConfig==nullptr, E_INVALIDARG);
// family (protocol type) ------------------------------------ // family (protocol type) ------------------------------------
...@@ -341,7 +341,7 @@ void TcpClientLoop(StunClientLogicConfig& config, ClientSocketConfig& socketconf ...@@ -341,7 +341,7 @@ void TcpClientLoop(StunClientLogicConfig& config, ClientSocketConfig& socketconf
int ret; int ret;
size_t bytes_sent, bytes_recv; size_t bytes_sent, bytes_recv;
size_t bytes_to_send, max_bytes_recv, remaining; size_t bytes_to_send, max_bytes_recv, remaining;
uint8_t* pData=NULL; uint8_t* pData=nullptr;
size_t readsize; size_t readsize;
CStunMessageReader reader; CStunMessageReader reader;
StunClientResults results; StunClientResults results;
...@@ -568,7 +568,7 @@ HRESULT UdpClientLoop(StunClientLogicConfig& config, const ClientSocketConfig& s ...@@ -568,7 +568,7 @@ HRESULT UdpClientLoop(StunClientLogicConfig& config, const ClientSocketConfig& s
tv.tv_usec = 500000; // half-second tv.tv_usec = 500000; // half-second
tv.tv_sec = config.timeoutSeconds; tv.tv_sec = config.timeoutSeconds;
ret = select(sock+1, &set, NULL, NULL, &tv); ret = select(sock+1, &set, nullptr, nullptr, &tv);
if (ret > 0) if (ret > 0)
{ {
ret = ::recvfromex(sock, spMsg->GetData(), spMsg->GetAllocatedSize(), MSG_DONTWAIT, &addrRemote, &addrLocal); ret = ::recvfromex(sock, spMsg->GetData(), spMsg->GetAllocatedSize(), MSG_DONTWAIT, &addrRemote, &addrLocal);
......
...@@ -52,10 +52,10 @@ HRESULT CCmdLineParser::AddOption(const char* pszName, int has_arg, std::string* ...@@ -52,10 +52,10 @@ HRESULT CCmdLineParser::AddOption(const char* pszName, int has_arg, std::string*
HRESULT hr = S_OK; HRESULT hr = S_OK;
OptionDetail od; OptionDetail od;
ChkIfA(pszName==NULL, E_INVALIDARG); ChkIfA(pszName==nullptr, E_INVALIDARG);
ChkIfA(has_arg < 0, E_INVALIDARG); ChkIfA(has_arg < 0, E_INVALIDARG);
ChkIfA(has_arg > 2, E_INVALIDARG); ChkIfA(has_arg > 2, E_INVALIDARG);
ChkIfA(pStrResult==NULL, E_INVALIDARG); ChkIfA(pStrResult==nullptr, E_INVALIDARG);
od.has_arg = has_arg; od.has_arg = has_arg;
od.pStrResult = pStrResult; od.pStrResult = pStrResult;
...@@ -115,7 +115,7 @@ HRESULT CCmdLineParser::ParseCommandLine(int argc, char** argv, int startindex, ...@@ -115,7 +115,7 @@ HRESULT CCmdLineParser::ParseCommandLine(int argc, char** argv, int startindex,
continue; continue;
} }
if ((longopts[index].has_arg != 0) && (optarg != NULL)) if ((longopts[index].has_arg != 0) && (optarg != nullptr))
{ {
_listOptionDetails[index].pStrResult->assign(optarg); _listOptionDetails[index].pStrResult->assign(optarg);
} }
......
...@@ -69,7 +69,7 @@ static const uint32_t crc_table[256] = { ...@@ -69,7 +69,7 @@ static const uint32_t crc_table[256] = {
/* ========================================================================= */ /* ========================================================================= */
uint32_t crc32(uint32_t crc, uint8_t* buf, size_t len) uint32_t crc32(uint32_t crc, uint8_t* buf, size_t len)
{ {
if (buf == NULL) return 0L; if (buf == nullptr) return 0L;
crc = crc ^ 0xffffffffL; crc = crc ^ 0xffffffffL;
while (len >= 8) while (len >= 8)
{ {
......
...@@ -96,10 +96,10 @@ protected: ...@@ -96,10 +96,10 @@ protected:
ItemNode* Find(const K& key, size_t* pHashIndex=NULL, ItemNode** ppPrev=NULL) ItemNode* Find(const K& key, size_t* pHashIndex=nullptr, ItemNode** ppPrev=nullptr)
{ {
size_t hashindex = ((size_t)(FastHash_Hash(key))) % _tsize; size_t hashindex = ((size_t)(FastHash_Hash(key))) % _tsize;
ItemNode* pPrev = NULL; ItemNode* pPrev = nullptr;
ItemNode* pProbe = _lookuptable[hashindex]; ItemNode* pProbe = _lookuptable[hashindex];
while (pProbe) while (pProbe)
{ {
...@@ -129,7 +129,7 @@ protected: ...@@ -129,7 +129,7 @@ protected:
{ {
int index = 0; int index = 0;
if ((_indexlist == NULL) || (_size == 0)) if ((_indexlist == nullptr) || (_size == 0))
{ {
return; return;
} }
...@@ -171,7 +171,7 @@ protected: ...@@ -171,7 +171,7 @@ protected:
// if size is 0, then that's an error // if size is 0, then that's an error
// if there is no indexlist, then just bail // if there is no indexlist, then just bail
if ( (_size == 0) || if ( (_size == 0) ||
(_indexlist == NULL) || (_indexlist == nullptr) ||
((_size > 1) && (_fIndexValid==false))) ((_size > 1) && (_fIndexValid==false)))
{ {
return; return;
...@@ -209,7 +209,7 @@ public: ...@@ -209,7 +209,7 @@ public:
FastHashBase() FastHashBase()
{ {
Init(0, 0, NULL, NULL, NULL, NULL); Init(0, 0, nullptr, nullptr, nullptr, nullptr);
} }
...@@ -226,10 +226,10 @@ public: ...@@ -226,10 +226,10 @@ public:
_nodes = nodelist; _nodes = nodelist;
_itemnodes = itemnodelist; _itemnodes = itemnodelist;
_freelist = NULL; _freelist = nullptr;
_lookuptable = table; _lookuptable = table;
_indexlist = indexlist; _indexlist = indexlist;
_fIndexValid = (_indexlist != NULL); _fIndexValid = (_indexlist != nullptr);
_indexStart = 0; _indexStart = 0;
Reset(); Reset();
...@@ -238,12 +238,12 @@ public: ...@@ -238,12 +238,12 @@ public:
void Reset() void Reset()
{ {
if (_lookuptable != NULL) if (_lookuptable != nullptr)
{ {
memset(_lookuptable, '\0', sizeof(ItemNodePtr)*_tsize); memset(_lookuptable, '\0', sizeof(ItemNodePtr)*_tsize);
} }
if ((_fsize > 0) && (_itemnodes != NULL)) if ((_fsize > 0) && (_itemnodes != nullptr))
{ {
for (size_t x = 0; x < _fsize; x++) for (size_t x = 0; x < _fsize; x++)
{ {
...@@ -251,19 +251,19 @@ public: ...@@ -251,19 +251,19 @@ public:
_itemnodes[x].index = x; _itemnodes[x].index = x;
} }
_itemnodes[_fsize-1].pNext = NULL; _itemnodes[_fsize-1].pNext = nullptr;
} }
_freelist = _itemnodes; _freelist = _itemnodes;
_size = 0; _size = 0;
_fIndexValid = (_indexlist != NULL); // index is valid when we are empty _fIndexValid = (_indexlist != nullptr); // index is valid when we are empty
_indexStart = 0; _indexStart = 0;
} }
bool IsValid() bool IsValid()
{ {
return ((_tsize > 0) && (_fsize > 0) && (_itemnodes != NULL) && (_lookuptable != NULL) && (_nodes != NULL)); return ((_tsize > 0) && (_fsize > 0) && (_itemnodes != nullptr) && (_lookuptable != nullptr) && (_nodes != nullptr));
} }
size_t Size() size_t Size()
...@@ -284,11 +284,11 @@ public: ...@@ -284,11 +284,11 @@ public:
int Insert(const K& key, V& value) int Insert(const K& key, V& value)
{ {
size_t hashindex = FastHash_Hash(key) % _tsize; size_t hashindex = FastHash_Hash(key) % _tsize;
ItemNode* pInsert = NULL; ItemNode* pInsert = nullptr;
ItemNode* pHead = _lookuptable[hashindex]; ItemNode* pHead = _lookuptable[hashindex];
Item* pItem = NULL; Item* pItem = nullptr;
if (_freelist == NULL) if (_freelist == nullptr)
{ {
return -1; return -1;
} }
...@@ -317,18 +317,18 @@ public: ...@@ -317,18 +317,18 @@ public:
{ {
size_t hashindex; size_t hashindex;
ItemNode* pPrev = NULL; ItemNode* pPrev = nullptr;
ItemNode* pNode = Find(key, &hashindex, &pPrev); ItemNode* pNode = Find(key, &hashindex, &pPrev);
ItemNode* pNext = NULL; ItemNode* pNext = nullptr;
if (pNode == NULL) if (pNode == nullptr)
{ {
return -1; return -1;
} }
pNext = pNode->pNext; pNext = pNode->pNext;
if (pPrev == NULL) if (pPrev == nullptr)
{ {
_lookuptable[hashindex] = pNext; _lookuptable[hashindex] = pNext;
} }
...@@ -350,7 +350,7 @@ public: ...@@ -350,7 +350,7 @@ public:
V* Lookup(const K& key) V* Lookup(const K& key)
{ {
V* pValue = NULL; V* pValue = nullptr;
ItemNode* pNode = Find(key); ItemNode* pNode = Find(key);
if (pNode) if (pNode)
{ {
...@@ -362,7 +362,7 @@ public: ...@@ -362,7 +362,7 @@ public:
bool Exists(const K& key) bool Exists(const K& key)
{ {
return (Find(key) != NULL); return (Find(key) != nullptr);
} }
Item* LookupByIndex(size_t index) Item* LookupByIndex(size_t index)
...@@ -370,9 +370,9 @@ public: ...@@ -370,9 +370,9 @@ public:
int itemindex; int itemindex;
int indexadjusted; int indexadjusted;
if ((index >= _size) || (_indexlist == NULL)) if ((index >= _size) || (_indexlist == nullptr))
{ {
return NULL; return nullptr;
} }
if (_fIndexValid == false) if (_fIndexValid == false)
...@@ -380,7 +380,7 @@ public: ...@@ -380,7 +380,7 @@ public:
ReIndex(); ReIndex();
if (_fIndexValid == false) if (_fIndexValid == false)
{ {
return NULL; return nullptr;
} }
} }
...@@ -392,7 +392,7 @@ public: ...@@ -392,7 +392,7 @@ public:
V* LookupValueByIndex(size_t index) V* LookupValueByIndex(size_t index)
{ {
Item* pItem = LookupByIndex(index); Item* pItem = LookupByIndex(index);
return pItem ? &pItem->value : NULL; return pItem ? &pItem->value : nullptr;
} }
}; };
...@@ -447,18 +447,18 @@ protected: ...@@ -447,18 +447,18 @@ protected:
public: public:
FastHashDynamic() : FastHashDynamic() :
_nodesarray(NULL), _nodesarray(nullptr),
_itemnodesarray(NULL), _itemnodesarray(nullptr),
_lookuptablearray(NULL), _lookuptablearray(nullptr),
_indexarray(NULL) _indexarray(nullptr)
{ {
} }
FastHashDynamic(size_t fsize, size_t tsize) : FastHashDynamic(size_t fsize, size_t tsize) :
_nodesarray(NULL), _nodesarray(nullptr),
_itemnodesarray(NULL), _itemnodesarray(nullptr),
_lookuptablearray(NULL), _lookuptablearray(nullptr),
_indexarray(NULL) _indexarray(nullptr)
{ {
InitTable(fsize, tsize); InitTable(fsize, tsize);
} }
...@@ -488,7 +488,7 @@ public: ...@@ -488,7 +488,7 @@ public:
_lookuptablearray = new ItemNodePtr[tsize]; _lookuptablearray = new ItemNodePtr[tsize];
_indexarray = new int[fsize]; _indexarray = new int[fsize];
if ((_nodesarray == NULL) || (_itemnodesarray == NULL) || (_lookuptablearray == NULL) || (_indexarray==NULL)) if ((_nodesarray == nullptr) || (_itemnodesarray == nullptr) || (_lookuptablearray == nullptr) || (_indexarray==nullptr))
{ {
ResetTable(); ResetTable();
return -1; return -1;
...@@ -501,18 +501,18 @@ public: ...@@ -501,18 +501,18 @@ public:
void ResetTable() void ResetTable()
{ {
delete [] _nodesarray; delete [] _nodesarray;
_nodesarray = NULL; _nodesarray = nullptr;
delete [] _itemnodesarray; delete [] _itemnodesarray;
_itemnodesarray = NULL; _itemnodesarray = nullptr;
delete [] _lookuptablearray; delete [] _lookuptablearray;
_lookuptablearray = NULL; _lookuptablearray = nullptr;
delete [] _indexarray; delete [] _indexarray;
_indexarray = NULL; _indexarray = nullptr;
this->Init(0,0, NULL, NULL, NULL, NULL); this->Init(0,0, nullptr, nullptr, nullptr, nullptr);
} }
......
...@@ -24,7 +24,7 @@ static uint32_t GetMillisecondCounterUnix() ...@@ -24,7 +24,7 @@ static uint32_t GetMillisecondCounterUnix()
uint64_t milliseconds = 0; uint64_t milliseconds = 0;
uint32_t retvalue; uint32_t retvalue;
timeval tv = {}; timeval tv = {};
gettimeofday(&tv, NULL); gettimeofday(&tv, nullptr);
milliseconds = (tv.tv_sec * (unsigned long long)1000) + (tv.tv_usec / 1000); milliseconds = (tv.tv_sec * (unsigned long long)1000) + (tv.tv_usec / 1000);
retvalue = (uint32_t)(milliseconds & (unsigned long long)0xffffffff); retvalue = (uint32_t)(milliseconds & (unsigned long long)0xffffffff);
return retvalue; return retvalue;
......
...@@ -27,7 +27,7 @@ static void SplitParagraphIntoWords(const char* pszLine, std::vector<std::string ...@@ -27,7 +27,7 @@ static void SplitParagraphIntoWords(const char* pszLine, std::vector<std::string
{ {
std::string strWord; std::string strWord;
if (pszLine == NULL) if (pszLine == nullptr)
{ {
return; return;
} }
...@@ -60,7 +60,7 @@ static void SplitInputIntoParagraphs(const char* pszInput, std::vector<std::stri ...@@ -60,7 +60,7 @@ static void SplitInputIntoParagraphs(const char* pszInput, std::vector<std::stri
// blindly scan to the next \r or \n // blindly scan to the next \r or \n
std::string strParagraph; std::string strParagraph;
if (pszInput == NULL) if (pszInput == nullptr)
{ {
return; return;
} }
...@@ -107,7 +107,7 @@ static void PrintParagraph(const char* psz, size_t width) ...@@ -107,7 +107,7 @@ static void PrintParagraph(const char* psz, size_t width)
return; return;
} }
if (psz==NULL) if (psz==nullptr)
{ {
return; return;
} }
......
...@@ -30,7 +30,7 @@ namespace StringHelper ...@@ -30,7 +30,7 @@ namespace StringHelper
{ {
bool IsNullOrEmpty(const char* psz) bool IsNullOrEmpty(const char* psz)
{ {
return ((psz == NULL) || (psz[0] == '\0')); return ((psz == nullptr) || (psz[0] == '\0'));
} }
...@@ -41,7 +41,7 @@ namespace StringHelper ...@@ -41,7 +41,7 @@ namespace StringHelper
std::string str2; std::string str2;
const int diff = ('a' - 'A'); const int diff = ('a' - 'A');
if ((psz == NULL) || (length == 0)) if ((psz == nullptr) || (length == 0))
{ {
return; return;
} }
...@@ -68,7 +68,7 @@ namespace StringHelper ...@@ -68,7 +68,7 @@ namespace StringHelper
{ {
const char* psz = str.c_str(); const char* psz = str.c_str();
if (psz == NULL) if (psz == nullptr)
{ {
return; return;
} }
...@@ -108,7 +108,7 @@ namespace StringHelper ...@@ -108,7 +108,7 @@ namespace StringHelper
{ {
int nVal = 0; int nVal = 0;
if (IsNullOrEmpty(psz) || (pnResult==NULL)) if (IsNullOrEmpty(psz) || (pnResult==nullptr))
{ {
return -1; return -1;
} }
......
...@@ -23,17 +23,17 @@ ...@@ -23,17 +23,17 @@
void GetDefaultAdapters(int family, ifaddrs* pList, ifaddrs** ppAddrPrimary, ifaddrs** ppAddrAlternate) void GetDefaultAdapters(int family, ifaddrs* pList, ifaddrs** ppAddrPrimary, ifaddrs** ppAddrAlternate)
{ {
ifaddrs* pAdapter = NULL; ifaddrs* pAdapter = nullptr;
*ppAddrPrimary = NULL; *ppAddrPrimary = nullptr;
*ppAddrAlternate = NULL; *ppAddrAlternate = nullptr;
pAdapter = pList; pAdapter = pList;
while (pAdapter) while (pAdapter)
{ {
if ( (pAdapter->ifa_addr != NULL) && (pAdapter->ifa_addr->sa_family == family) && (pAdapter->ifa_flags & IFF_UP) && !(pAdapter->ifa_flags & IFF_LOOPBACK)) if ( (pAdapter->ifa_addr != nullptr) && (pAdapter->ifa_addr->sa_family == family) && (pAdapter->ifa_flags & IFF_UP) && !(pAdapter->ifa_flags & IFF_LOOPBACK))
{ {
if (*ppAddrPrimary == NULL) if (*ppAddrPrimary == nullptr)
{ {
*ppAddrPrimary = pAdapter; *ppAddrPrimary = pAdapter;
} }
...@@ -55,9 +55,9 @@ bool HasAtLeastTwoAdapters(int family) ...@@ -55,9 +55,9 @@ bool HasAtLeastTwoAdapters(int family)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ifaddrs* pList = NULL; ifaddrs* pList = nullptr;
ifaddrs* pAdapter1 = NULL; ifaddrs* pAdapter1 = nullptr;
ifaddrs* pAdapter2 = NULL; ifaddrs* pAdapter2 = nullptr;
bool fRet = false; bool fRet = false;
ChkIf(getifaddrs(&pList) < 0, ERRNOHR); ChkIf(getifaddrs(&pList) < 0, ERRNOHR);
...@@ -83,12 +83,12 @@ Cleanup: ...@@ -83,12 +83,12 @@ Cleanup:
HRESULT GetBestAddressForSocketBind(bool fPrimary, int family, uint16_t port, CSocketAddress* pSocketAddr) HRESULT GetBestAddressForSocketBind(bool fPrimary, int family, uint16_t port, CSocketAddress* pSocketAddr)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ifaddrs* pList = NULL; ifaddrs* pList = nullptr;
ifaddrs* pAdapter = NULL; ifaddrs* pAdapter = nullptr;
ifaddrs* pAdapter1 = NULL; ifaddrs* pAdapter1 = nullptr;
ifaddrs* pAdapter2 = NULL; ifaddrs* pAdapter2 = nullptr;
ChkIfA(pSocketAddr == NULL, E_INVALIDARG); ChkIfA(pSocketAddr == nullptr, E_INVALIDARG);
ChkIf(getifaddrs(&pList) < 0, ERRNOHR); ChkIf(getifaddrs(&pList) < 0, ERRNOHR);
...@@ -96,8 +96,8 @@ HRESULT GetBestAddressForSocketBind(bool fPrimary, int family, uint16_t port, CS ...@@ -96,8 +96,8 @@ HRESULT GetBestAddressForSocketBind(bool fPrimary, int family, uint16_t port, CS
pAdapter = fPrimary ? pAdapter1 : pAdapter2; pAdapter = fPrimary ? pAdapter1 : pAdapter2;
ChkIf(pAdapter==NULL, E_FAIL); ChkIf(pAdapter==nullptr, E_FAIL);
ChkIfA(pAdapter->ifa_addr==NULL, E_UNEXPECTED); ChkIfA(pAdapter->ifa_addr==nullptr, E_UNEXPECTED);
*pSocketAddr = CSocketAddress(*pAdapter->ifa_addr); *pSocketAddr = CSocketAddress(*pAdapter->ifa_addr);
pSocketAddr->SetPort(port); pSocketAddr->SetPort(port);
...@@ -111,14 +111,14 @@ Cleanup: ...@@ -111,14 +111,14 @@ Cleanup:
HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint16_t port, CSocketAddress* pSocketAddr) HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint16_t port, CSocketAddress* pSocketAddr)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ifaddrs* pList = NULL; ifaddrs* pList = nullptr;
ifaddrs* pAdapter = NULL; ifaddrs* pAdapter = nullptr;
ifaddrs* pAdapterFound = NULL; ifaddrs* pAdapterFound = nullptr;
ChkIfA(pszAdapterName == NULL, E_INVALIDARG); ChkIfA(pszAdapterName == nullptr, E_INVALIDARG);
ChkIfA(pszAdapterName[0] == '\0', E_INVALIDARG); ChkIfA(pszAdapterName[0] == '\0', E_INVALIDARG);
ChkIfA(pSocketAddr == NULL, E_INVALIDARG); ChkIfA(pSocketAddr == nullptr, E_INVALIDARG);
...@@ -127,7 +127,7 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1 ...@@ -127,7 +127,7 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1
pAdapter = pList; pAdapter = pList;
while (pAdapter) while (pAdapter)
{ {
if ((pAdapter->ifa_addr != NULL) && (pAdapter->ifa_name != NULL) && (family == pAdapter->ifa_addr->sa_family)) if ((pAdapter->ifa_addr != nullptr) && (pAdapter->ifa_name != nullptr) && (family == pAdapter->ifa_addr->sa_family))
{ {
if (strcmp(pAdapter->ifa_name, pszAdapterName) == 0) if (strcmp(pAdapter->ifa_name, pszAdapterName) == 0)
{ {
...@@ -142,11 +142,11 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1 ...@@ -142,11 +142,11 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1
// If pszAdapterName is an IP address, convert it into a sockaddr and compare the address field with that of the adapter // If pszAdapterName is an IP address, convert it into a sockaddr and compare the address field with that of the adapter
// Note: an alternative approach would be to convert pAdapter->ifa_addr to a string and then do a string compare. // Note: an alternative approach would be to convert pAdapter->ifa_addr to a string and then do a string compare.
// But then it would be difficult to match "::1" with "0:0:0:0:0:0:0:1" and other formats of IPV6 strings // But then it would be difficult to match "::1" with "0:0:0:0:0:0:0:1" and other formats of IPV6 strings
if ((pAdapterFound == NULL) && ((family == AF_INET) || (family == AF_INET6)) ) if ((pAdapterFound == nullptr) && ((family == AF_INET) || (family == AF_INET6)) )
{ {
uint8_t addrbytes[sizeof(in6_addr)] = {}; uint8_t addrbytes[sizeof(in6_addr)] = {};
int comparesize = (family == AF_INET) ? sizeof(in_addr) : sizeof(in6_addr); int comparesize = (family == AF_INET) ? sizeof(in_addr) : sizeof(in6_addr);
void* pCmp = NULL; void* pCmp = nullptr;
if (inet_pton(family, pszAdapterName, addrbytes) == 1) if (inet_pton(family, pszAdapterName, addrbytes) == 1)
...@@ -154,7 +154,7 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1 ...@@ -154,7 +154,7 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1
pAdapter = pList; pAdapter = pList;
while (pAdapter) while (pAdapter)
{ {
if ((pAdapter->ifa_addr != NULL) && (family == pAdapter->ifa_addr->sa_family)) if ((pAdapter->ifa_addr != nullptr) && (family == pAdapter->ifa_addr->sa_family))
{ {
// offsetof(sockaddr_in, sin_addr) != offsetof(sockaddr_in6, sin6_addr) // offsetof(sockaddr_in, sin_addr) != offsetof(sockaddr_in6, sin6_addr)
// so you really can't do too many casting tricks like you can with sockaddr and sockaddr_in // so you really can't do too many casting tricks like you can with sockaddr and sockaddr_in
...@@ -182,7 +182,7 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1 ...@@ -182,7 +182,7 @@ HRESULT GetSocketAddressForAdapter(int family, const char* pszAdapterName, uint1
} }
} }
ChkIf(pAdapterFound == NULL, E_FAIL); ChkIf(pAdapterFound == nullptr, E_FAIL);
{ {
*pSocketAddr = CSocketAddress(*(pAdapterFound->ifa_addr)); *pSocketAddr = CSocketAddress(*(pAdapterFound->ifa_addr));
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
CEpoll::CEpoll() : CEpoll::CEpoll() :
_epollfd(-1), _epollfd(-1),
_events(NULL), _events(nullptr),
_sizeEvents(0), _sizeEvents(0),
_pendingCount(0), _pendingCount(0),
_currentEventIndex(0) _currentEventIndex(0)
...@@ -116,7 +116,7 @@ HRESULT CEpoll::Initialize(size_t maxSockets) ...@@ -116,7 +116,7 @@ HRESULT CEpoll::Initialize(size_t maxSockets)
_sizeEvents = maxSockets; _sizeEvents = maxSockets;
_events = new epoll_event[maxSockets]; _events = new epoll_event[maxSockets];
ChkIf(_events == NULL, E_OUTOFMEMORY); ChkIf(_events == nullptr, E_OUTOFMEMORY);
_pendingCount = 0; _pendingCount = 0;
...@@ -138,7 +138,7 @@ HRESULT CEpoll::Close() ...@@ -138,7 +138,7 @@ HRESULT CEpoll::Close()
} }
delete [] _events; delete [] _events;
_events = NULL; _events = nullptr;
_sizeEvents = 0; _sizeEvents = 0;
_pendingCount = 0; _pendingCount = 0;
_currentEventIndex = 0; _currentEventIndex = 0;
...@@ -173,7 +173,7 @@ HRESULT CEpoll::Remove(int fd) ...@@ -173,7 +173,7 @@ HRESULT CEpoll::Remove(int fd)
// we just got notified for isn't going to be within the _events array // we just got notified for isn't going to be within the _events array
HRESULT hr = S_OK; HRESULT hr = S_OK;
epoll_event ev={}; // pass empty ev, because some implementations of epoll_ctl can't handle a NULL event struct epoll_event ev={}; // pass empty ev, because some implementations of epoll_ctl can't handle a nullptr event struct
ChkIfA(fd == -1, E_INVALIDARG); ChkIfA(fd == -1, E_INVALIDARG);
ChkIfA(_epollfd==-1, E_UNEXPECTED); ChkIfA(_epollfd==-1, E_UNEXPECTED);
...@@ -203,7 +203,7 @@ Cleanup: ...@@ -203,7 +203,7 @@ Cleanup:
HRESULT CEpoll::WaitForNextEvent(PollEvent* pPollEvent, int timeoutMilliseconds) HRESULT CEpoll::WaitForNextEvent(PollEvent* pPollEvent, int timeoutMilliseconds)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
epoll_event *pEvent = NULL; epoll_event *pEvent = nullptr;
int ret = 0; int ret = 0;
ChkIfA(_epollfd==-1, E_UNEXPECTED); ChkIfA(_epollfd==-1, E_UNEXPECTED);
...@@ -342,7 +342,7 @@ HRESULT CPoll::Add(int fd, uint32_t eventflags) ...@@ -342,7 +342,7 @@ HRESULT CPoll::Add(int fd, uint32_t eventflags)
ChkIfA(_fInitialized == false, E_FAIL); ChkIfA(_fInitialized == false, E_FAIL);
ChkIfA(_hashtable.Lookup(fd)!=NULL, E_UNEXPECTED); ChkIfA(_hashtable.Lookup(fd)!=nullptr, E_UNEXPECTED);
pfd.events = ToNativeFlags(eventflags); pfd.events = ToNativeFlags(eventflags);
pfd.fd = fd; pfd.fd = fd;
...@@ -357,7 +357,7 @@ HRESULT CPoll::Remove(int fd) ...@@ -357,7 +357,7 @@ HRESULT CPoll::Remove(int fd)
{ {
// See notes below why pPos is declared volatile. Gets around a compiler bug // See notes below why pPos is declared volatile. Gets around a compiler bug
volatile size_t* pPos = NULL; volatile size_t* pPos = nullptr;
size_t size = _fds.size(); size_t size = _fds.size();
size_t pos; size_t pos;
...@@ -371,7 +371,7 @@ HRESULT CPoll::Remove(int fd) ...@@ -371,7 +371,7 @@ HRESULT CPoll::Remove(int fd)
pPos = _hashtable.Lookup(fd); pPos = _hashtable.Lookup(fd);
ChkIfA(pPos == NULL, E_FAIL); ChkIfA(pPos == nullptr, E_FAIL);
pos = *pPos; pos = *pPos;
...@@ -384,7 +384,7 @@ HRESULT CPoll::Remove(int fd) ...@@ -384,7 +384,7 @@ HRESULT CPoll::Remove(int fd)
_fds[pos] = _fds[size-1]; _fds[pos] = _fds[size-1];
pPos = _hashtable.Lookup(_fds[pos].fd); pPos = _hashtable.Lookup(_fds[pos].fd);
ASSERT(pPos != NULL); ASSERT(pPos != nullptr);
// If the volatile declaration above was not made, this block of code // If the volatile declaration above was not made, this block of code
// gets over-optimized on older GCC compilers (g++ 4.2.1 on BSD) with with -O2 // gets over-optimized on older GCC compilers (g++ 4.2.1 on BSD) with with -O2
...@@ -402,7 +402,7 @@ Cleanup: ...@@ -402,7 +402,7 @@ Cleanup:
HRESULT CPoll::ChangeEventSet(int fd, uint32_t eventflags) HRESULT CPoll::ChangeEventSet(int fd, uint32_t eventflags)
{ {
size_t* pPos = NULL; size_t* pPos = nullptr;
size_t pos; size_t pos;
HRESULT hr = S_OK; HRESULT hr = S_OK;
size_t size = _fds.size(); size_t size = _fds.size();
...@@ -413,7 +413,7 @@ HRESULT CPoll::ChangeEventSet(int fd, uint32_t eventflags) ...@@ -413,7 +413,7 @@ HRESULT CPoll::ChangeEventSet(int fd, uint32_t eventflags)
ChkIf(size == 0, E_FAIL); ChkIf(size == 0, E_FAIL);
pPos = _hashtable.Lookup(fd); pPos = _hashtable.Lookup(fd);
ChkIfA(pPos == NULL, E_FAIL); ChkIfA(pPos == nullptr, E_FAIL);
pos = *pPos; pos = *pPos;
ChkIfA(pos >= size, E_FAIL); ChkIfA(pos >= size, E_FAIL);
ChkIfA(_fds[pos].fd != fd, E_FAIL); ChkIfA(_fds[pos].fd != fd, E_FAIL);
...@@ -428,12 +428,12 @@ HRESULT CPoll::WaitForNextEvent(PollEvent* pPollEvent, int timeoutMilliseconds) ...@@ -428,12 +428,12 @@ HRESULT CPoll::WaitForNextEvent(PollEvent* pPollEvent, int timeoutMilliseconds)
HRESULT hr = S_OK; HRESULT hr = S_OK;
int ret; int ret;
size_t size = _fds.size(); size_t size = _fds.size();
pollfd* list = NULL; pollfd* list = nullptr;
bool fFound = false; bool fFound = false;
ChkIfA(_fInitialized == false, E_FAIL); ChkIfA(_fInitialized == false, E_FAIL);
ChkIfA(pPollEvent == NULL, E_INVALIDARG); ChkIfA(pPollEvent == nullptr, E_INVALIDARG);
pPollEvent->eventflags = 0; pPollEvent->eventflags = 0;
ChkIf(size == 0, S_FALSE); ChkIf(size == 0, S_FALSE);
......
...@@ -8,7 +8,7 @@ RateLimiter::RateLimiter(size_t tablesize, bool isUsingLock) ...@@ -8,7 +8,7 @@ RateLimiter::RateLimiter(size_t tablesize, bool isUsingLock)
{ {
_table.InitTable(tablesize, tablesize/2); _table.InitTable(tablesize, tablesize/2);
this->_isUsingLock = isUsingLock; this->_isUsingLock = isUsingLock;
pthread_mutex_init(&_mutex, NULL); pthread_mutex_init(&_mutex, nullptr);
} }
RateLimiter::~RateLimiter() RateLimiter::~RateLimiter()
...@@ -19,7 +19,7 @@ RateLimiter::~RateLimiter() ...@@ -19,7 +19,7 @@ RateLimiter::~RateLimiter()
time_t RateLimiter::get_time() time_t RateLimiter::get_time()
{ {
return time(NULL); return time(nullptr);
} }
uint64_t RateLimiter::get_rate(const RateTracker* pRT) uint64_t RateLimiter::get_rate(const RateTracker* pRT)
...@@ -82,7 +82,7 @@ bool RateLimiter::RateCheckImpl(const CSocketAddress& addr) ...@@ -82,7 +82,7 @@ bool RateLimiter::RateCheckImpl(const CSocketAddress& addr)
// //
if (pRT == NULL) if (pRT == nullptr)
{ {
RateTracker rt; RateTracker rt;
rt.count = 1; rt.count = 1;
......
...@@ -72,11 +72,11 @@ ssize_t recvfromex(int sockfd, void* buf, size_t len, int flags, CSocketAddress* ...@@ -72,11 +72,11 @@ ssize_t recvfromex(int sockfd, void* buf, size_t len, int flags, CSocketAddress*
if (pDstAddr) if (pDstAddr)
{ {
struct cmsghdr* pCmsg = NULL; struct cmsghdr* pCmsg = nullptr;
InitSocketAddress(addrRemote.ss_family, pDstAddr); InitSocketAddress(addrRemote.ss_family, pDstAddr);
for (pCmsg = CMSG_FIRSTHDR(&hdr); pCmsg != NULL; pCmsg = CMSG_NXTHDR(&hdr, pCmsg)) for (pCmsg = CMSG_FIRSTHDR(&hdr); pCmsg != nullptr; pCmsg = CMSG_NXTHDR(&hdr, pCmsg))
{ {
// IPV6 address ---------------------------------------------------------- // IPV6 address ----------------------------------------------------------
if ((pCmsg->cmsg_level == IPPROTO_IPV6) && (pCmsg->cmsg_type == IPV6_PKTINFO) && CMSG_DATA(pCmsg)) if ((pCmsg->cmsg_level == IPPROTO_IPV6) && (pCmsg->cmsg_type == IPV6_PKTINFO) && CMSG_DATA(pCmsg))
......
...@@ -26,7 +26,7 @@ HRESULT ResolveHostName(const char* pszHostName, int family, bool fNumericOnly, ...@@ -26,7 +26,7 @@ HRESULT ResolveHostName(const char* pszHostName, int family, bool fNumericOnly,
int ret; int ret;
HRESULT hr = S_OK; HRESULT hr = S_OK;
addrinfo* pResultList = NULL; addrinfo* pResultList = nullptr;
addrinfo hints = {}; addrinfo hints = {};
...@@ -34,7 +34,7 @@ HRESULT ResolveHostName(const char* pszHostName, int family, bool fNumericOnly, ...@@ -34,7 +34,7 @@ HRESULT ResolveHostName(const char* pszHostName, int family, bool fNumericOnly,
StringHelper::Trim(strHostName); StringHelper::Trim(strHostName);
ChkIf(strHostName.length() == 0, E_INVALIDARG); ChkIf(strHostName.length() == 0, E_INVALIDARG);
ChkIf(pAddr==NULL, E_INVALIDARG); ChkIf(pAddr==nullptr, E_INVALIDARG);
hints.ai_family = family; hints.ai_family = family;
if (fNumericOnly) if (fNumericOnly)
...@@ -45,17 +45,17 @@ HRESULT ResolveHostName(const char* pszHostName, int family, bool fNumericOnly, ...@@ -45,17 +45,17 @@ HRESULT ResolveHostName(const char* pszHostName, int family, bool fNumericOnly,
// without a socktype hint, getaddrinfo will return 3x the number of addresses (SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW) // without a socktype hint, getaddrinfo will return 3x the number of addresses (SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW)
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
ret = getaddrinfo(strHostName.c_str(), NULL, &hints, &pResultList); ret = getaddrinfo(strHostName.c_str(), nullptr, &hints, &pResultList);
ChkIf(ret != 0, ERRNO_TO_HRESULT(ret)); ChkIf(ret != 0, ERRNO_TO_HRESULT(ret));
ChkIf(pResultList==NULL, E_FAIL) ChkIf(pResultList==nullptr, E_FAIL)
// just pick the first one found // just pick the first one found
*pAddr = CSocketAddress(*(pResultList->ai_addr)); *pAddr = CSocketAddress(*(pResultList->ai_addr));
Cleanup: Cleanup:
if (pResultList != NULL) // android will crash if passed NULL if (pResultList != nullptr) // android will crash if passed nullptr
{ {
::freeaddrinfo(pResultList); ::freeaddrinfo(pResultList);
} }
......
...@@ -77,7 +77,7 @@ void LogHR(uint16_t level, HRESULT hr) ...@@ -77,7 +77,7 @@ void LogHR(uint16_t level, HRESULT hr)
{ {
uint32_t facility = HRESULT_FACILITY(hr); uint32_t facility = HRESULT_FACILITY(hr);
char msg[400]; char msg[400];
const char* pMsg = NULL; const char* pMsg = nullptr;
bool fGotMsg = false; bool fGotMsg = false;
if (facility == FACILITY_ERRNO) if (facility == FACILITY_ERRNO)
...@@ -261,7 +261,7 @@ HRESULT BuildServerConfigurationFromArgs(StartupArgs& argsIn, CStunServerConfig* ...@@ -261,7 +261,7 @@ HRESULT BuildServerConfigurationFromArgs(StartupArgs& argsIn, CStunServerConfig*
ChkIfA(pConfigOut == NULL, E_INVALIDARG); ChkIfA(pConfigOut == nullptr, E_INVALIDARG);
// normalize the args. The "trim" is not needed for command line args, but will be useful when we have an "init file" for initializing the server // normalize the args. The "trim" is not needed for command line args, but will be useful when we have an "init file" for initializing the server
......
...@@ -34,13 +34,13 @@ static HRESULT LookupPassword(bool fWithRealm, const char* pszUserName, const ch ...@@ -34,13 +34,13 @@ static HRESULT LookupPassword(bool fWithRealm, const char* pszUserName, const ch
if (fWithRealm) if (fWithRealm)
{ {
if ((pszRealm == NULL) || (strcmp(pszRealm, c_szRealm))) if ((pszRealm == nullptr) || (strcmp(pszRealm, c_szRealm)))
{ {
return E_FAIL; return E_FAIL;
} }
} }
if (pszUserName == NULL) if (pszUserName == nullptr)
{ {
return E_FAIL; return E_FAIL;
} }
...@@ -81,7 +81,7 @@ HRESULT CShortTermAuth::DoAuthCheck(AuthAttributes* pAuthAttributes, AuthRespons ...@@ -81,7 +81,7 @@ HRESULT CShortTermAuth::DoAuthCheck(AuthAttributes* pAuthAttributes, AuthRespons
return S_OK; return S_OK;
} }
if (SUCCEEDED(LookupPassword(false, pAuthAttributes->szUser, NULL, pResponse->szPassword))) if (SUCCEEDED(LookupPassword(false, pAuthAttributes->szUser, nullptr, pResponse->szPassword)))
{ {
// Returning "AllowConditional" indicates that the request can be accepted if and only if the // Returning "AllowConditional" indicates that the request can be accepted if and only if the
// message integrity attribute can be validated with the value placed into pResponse->szPassword // message integrity attribute can be validated with the value placed into pResponse->szPassword
...@@ -160,7 +160,7 @@ HRESULT CLongTermAuth::CreateNonce(char *pszNonce) ...@@ -160,7 +160,7 @@ HRESULT CLongTermAuth::CreateNonce(char *pszNonce)
// If you use this code, make sure you change the value of c_szPrivateKey! // If you use this code, make sure you change the value of c_szPrivateKey!
time_t thetime = time(NULL); time_t thetime = time(nullptr);
uint8_t hmacresult[20] = {}; uint8_t hmacresult[20] = {};
char szHMAC[20*2+1]; char szHMAC[20*2+1];
char szTime[sizeof(time_t)*4]; char szTime[sizeof(time_t)*4];
...@@ -180,12 +180,12 @@ HRESULT CLongTermAuth::CreateNonce(char *pszNonce) ...@@ -180,12 +180,12 @@ HRESULT CLongTermAuth::CreateNonce(char *pszNonce)
HRESULT CLongTermAuth::ValidateNonce(char* pszNonce) HRESULT CLongTermAuth::ValidateNonce(char* pszNonce)
{ {
time_t thecurrenttime = time(NULL); time_t thecurrenttime = time(nullptr);
time_t thetime; time_t thetime;
uint8_t hmacresult[20] = {}; uint8_t hmacresult[20] = {};
char szHMAC[20*2+1]; char szHMAC[20*2+1];
char szNonce[100]; char szNonce[100];
char *pRightHalf = NULL; char *pRightHalf = nullptr;
time_t diff; time_t diff;
unsigned int len = ARRAYSIZE(hmacresult); unsigned int len = ARRAYSIZE(hmacresult);
...@@ -194,7 +194,7 @@ HRESULT CLongTermAuth::ValidateNonce(char* pszNonce) ...@@ -194,7 +194,7 @@ HRESULT CLongTermAuth::ValidateNonce(char* pszNonce)
pRightHalf = strstr(szNonce, ":"); pRightHalf = strstr(szNonce, ":");
if (pRightHalf == NULL) if (pRightHalf == nullptr)
{ {
return E_FAIL; return E_FAIL;
} }
......
...@@ -149,7 +149,7 @@ HRESULT CStunServer::Initialize(const CStunServerConfig& config) ...@@ -149,7 +149,7 @@ HRESULT CStunServer::Initialize(const CStunServerConfig& config)
// create one thread for all the sockets // create one thread for all the sockets
CStunSocketThread* pThread = new CStunSocketThread(); CStunSocketThread* pThread = new CStunSocketThread();
ChkIf(pThread==NULL, E_OUTOFMEMORY); ChkIf(pThread==nullptr, E_OUTOFMEMORY);
_threads.push_back(pThread); _threads.push_back(pThread);
...@@ -160,7 +160,7 @@ HRESULT CStunServer::Initialize(const CStunServerConfig& config) ...@@ -160,7 +160,7 @@ HRESULT CStunServer::Initialize(const CStunServerConfig& config)
Logging::LogMsg(LL_DEBUG, "Configuring multi-threaded mode with %d threads per socket\n", config.nThreadsPerSocket); Logging::LogMsg(LL_DEBUG, "Configuring multi-threaded mode with %d threads per socket\n", config.nThreadsPerSocket);
// N threads for every socket // N threads for every socket
CStunSocketThread* pThread = NULL; CStunSocketThread* pThread = nullptr;
for (size_t index = 0; index < ARRAYSIZE(_arrSockets); index++) for (size_t index = 0; index < ARRAYSIZE(_arrSockets); index++)
{ {
if (_arrSockets[index].IsValid()) if (_arrSockets[index].IsValid())
...@@ -170,7 +170,7 @@ HRESULT CStunServer::Initialize(const CStunServerConfig& config) ...@@ -170,7 +170,7 @@ HRESULT CStunServer::Initialize(const CStunServerConfig& config)
for (int t = 0; t < config.nThreadsPerSocket; t++) for (int t = 0; t < config.nThreadsPerSocket; t++)
{ {
pThread = new CStunSocketThread(); pThread = new CStunSocketThread();
ChkIf(pThread==NULL, E_OUTOFMEMORY); ChkIf(pThread==nullptr, E_OUTOFMEMORY);
_threads.push_back(pThread); _threads.push_back(pThread);
Chk(pThread->Init(_arrSockets, &tsa, _spAuth, rolePrimaryRecv, spLimiter)); Chk(pThread->Init(_arrSockets, &tsa, _spAuth, rolePrimaryRecv, spLimiter));
} }
...@@ -208,7 +208,7 @@ HRESULT CStunServer::Shutdown() ...@@ -208,7 +208,7 @@ HRESULT CStunServer::Shutdown()
{ {
CStunSocketThread* pThread = _threads[index]; CStunSocketThread* pThread = _threads[index];
delete pThread; delete pThread;
_threads[index] = NULL; _threads[index] = nullptr;
} }
_threads.clear(); _threads.clear();
...@@ -229,7 +229,7 @@ HRESULT CStunServer::Start() ...@@ -229,7 +229,7 @@ HRESULT CStunServer::Start()
for (size_t index = 0; index < len; index++) for (size_t index = 0; index < len; index++)
{ {
CStunSocketThread* pThread = _threads[index]; CStunSocketThread* pThread = _threads[index];
if (pThread != NULL) if (pThread != nullptr)
{ {
// set the "exit flag" that each thread looks at when it wakes up from waiting // set the "exit flag" that each thread looks at when it wakes up from waiting
ChkA(pThread->Start()); ChkA(pThread->Start());
...@@ -254,7 +254,7 @@ HRESULT CStunServer::Stop() ...@@ -254,7 +254,7 @@ HRESULT CStunServer::Stop()
for (size_t index = 0; index < len; index++) for (size_t index = 0; index < len; index++)
{ {
CStunSocketThread* pThread = _threads[index]; CStunSocketThread* pThread = _threads[index];
if (pThread != NULL) if (pThread != nullptr)
{ {
// set the "exit flag" that each thread looks at when it wakes up from waiting // set the "exit flag" that each thread looks at when it wakes up from waiting
pThread->SignalForStop(false); pThread->SignalForStop(false);
...@@ -268,7 +268,7 @@ HRESULT CStunServer::Stop() ...@@ -268,7 +268,7 @@ HRESULT CStunServer::Stop()
// Post a bunch of empty buffers to get the threads unblocked from whatever socket call they are on // Post a bunch of empty buffers to get the threads unblocked from whatever socket call they are on
// In multi-threaded mode, this may wake up a different thread. But that's ok, since all threads start and stop together // In multi-threaded mode, this may wake up a different thread. But that's ok, since all threads start and stop together
if (pThread != NULL) if (pThread != nullptr)
{ {
pThread->SignalForStop(true); pThread->SignalForStop(true);
} }
...@@ -278,7 +278,7 @@ HRESULT CStunServer::Stop() ...@@ -278,7 +278,7 @@ HRESULT CStunServer::Stop()
{ {
CStunSocketThread* pThread = _threads[index]; CStunSocketThread* pThread = _threads[index];
if (pThread != NULL) if (pThread != nullptr)
{ {
pThread->WaitForStopAndClose(); pThread->WaitForStopAndClose();
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "stunconnection.h" #include "stunconnection.h"
CConnectionPool::CConnectionPool() : CConnectionPool::CConnectionPool() :
_freelist(NULL) _freelist(nullptr)
{ {
} }
...@@ -30,10 +30,10 @@ HRESULT CConnectionPool::Grow() ...@@ -30,10 +30,10 @@ HRESULT CConnectionPool::Grow()
for (size_t i = 0; i < c_growrate; i++) for (size_t i = 0; i < c_growrate; i++)
{ {
StunConnection* pConn = NULL; StunConnection* pConn = nullptr;
pConn = new StunConnection(); pConn = new StunConnection();
if (pConn == NULL) if (pConn == nullptr)
{ {
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
...@@ -41,7 +41,7 @@ HRESULT CConnectionPool::Grow() ...@@ -41,7 +41,7 @@ HRESULT CConnectionPool::Grow()
pConn->_spOutputBuffer = CRefCountedBuffer(new CBuffer(MAX_STUN_MESSAGE_SIZE)); pConn->_spOutputBuffer = CRefCountedBuffer(new CBuffer(MAX_STUN_MESSAGE_SIZE));
pConn->_spReaderBuffer = CRefCountedBuffer(new CBuffer(MAX_STUN_MESSAGE_SIZE)); pConn->_spReaderBuffer = CRefCountedBuffer(new CBuffer(MAX_STUN_MESSAGE_SIZE));
if ((pConn->_spOutputBuffer == NULL) || (pConn->_spReaderBuffer == NULL)) if ((pConn->_spOutputBuffer == nullptr) || (pConn->_spReaderBuffer == nullptr))
{ {
delete pConn; delete pConn;
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
...@@ -56,20 +56,20 @@ HRESULT CConnectionPool::Grow() ...@@ -56,20 +56,20 @@ HRESULT CConnectionPool::Grow()
StunConnection* CConnectionPool::GetConnection(int sock, SocketRole role) StunConnection* CConnectionPool::GetConnection(int sock, SocketRole role)
{ {
StunConnection* pConn = NULL; StunConnection* pConn = nullptr;
if (_freelist == NULL) if (_freelist == nullptr)
{ {
Grow(); Grow();
if (_freelist == NULL) if (_freelist == nullptr)
{ {
return NULL; // out of memory ? return nullptr; // out of memory ?
} }
} }
pConn = _freelist; pConn = _freelist;
_freelist = pConn->pNext; _freelist = pConn->pNext;
pConn->pNext = NULL; pConn->pNext = nullptr;
// prep this connection for usage // prep this connection for usage
pConn->_reader.Reset(); pConn->_reader.Reset();
...@@ -78,7 +78,7 @@ StunConnection* CConnectionPool::GetConnection(int sock, SocketRole role) ...@@ -78,7 +78,7 @@ StunConnection* CConnectionPool::GetConnection(int sock, SocketRole role)
pConn->_stunsocket.Attach(sock); pConn->_stunsocket.Attach(sock);
pConn->_stunsocket.SetRole(role); pConn->_stunsocket.SetRole(role);
pConn->_txCount = 0; pConn->_txCount = 0;
pConn->_timeStart = time(NULL); pConn->_timeStart = time(nullptr);
pConn->_idHashTable = -1; pConn->_idHashTable = -1;
return pConn; return pConn;
......
...@@ -43,7 +43,7 @@ CStunSocketThread::~CStunSocketThread() ...@@ -43,7 +43,7 @@ CStunSocketThread::~CStunSocketThread()
void CStunSocketThread::ClearSocketArray() void CStunSocketThread::ClearSocketArray()
{ {
_arrSendSockets = NULL; _arrSendSockets = nullptr;
_socks.clear(); _socks.clear();
} }
...@@ -55,8 +55,8 @@ HRESULT CStunSocketThread::Init(CStunSocket* arrayOfFourSockets, TransportAddres ...@@ -55,8 +55,8 @@ HRESULT CStunSocketThread::Init(CStunSocket* arrayOfFourSockets, TransportAddres
ChkIfA(_fThreadIsValid, E_UNEXPECTED); ChkIfA(_fThreadIsValid, E_UNEXPECTED);
ChkIfA(arrayOfFourSockets == NULL, E_INVALIDARG); ChkIfA(arrayOfFourSockets == nullptr, E_INVALIDARG);
ChkIfA(pTSA == NULL, E_INVALIDARG); ChkIfA(pTSA == nullptr, E_INVALIDARG);
// if this thread was configured to listen on a single socket (aka "multi-threaded mode"), then // if this thread was configured to listen on a single socket (aka "multi-threaded mode"), then
// validate that it exists // validate that it exists
...@@ -128,7 +128,7 @@ void CStunSocketThread::UninitThreadBuffers() ...@@ -128,7 +128,7 @@ void CStunSocketThread::UninitThreadBuffers()
_spBufferIn.reset(); _spBufferIn.reset();
_spBufferOut.reset(); _spBufferOut.reset();
_msgIn.pReader = NULL; _msgIn.pReader = nullptr;
_msgOut.spBufferOut.reset(); _msgOut.spBufferOut.reset();
} }
...@@ -142,7 +142,7 @@ HRESULT CStunSocketThread::Start() ...@@ -142,7 +142,7 @@ HRESULT CStunSocketThread::Start()
ChkIfA(_socks.size() <= 0, E_FAIL); ChkIfA(_socks.size() <= 0, E_FAIL);
err = ::pthread_create(&_pthread, NULL, CStunSocketThread::ThreadFunction, this); err = ::pthread_create(&_pthread, nullptr, CStunSocketThread::ThreadFunction, this);
ChkIfA(err != 0, ERRNO_TO_HRESULT(err)); ChkIfA(err != 0, ERRNO_TO_HRESULT(err));
_fThreadIsValid = true; _fThreadIsValid = true;
...@@ -170,7 +170,7 @@ HRESULT CStunSocketThread::SignalForStop(bool fPostMessages) ...@@ -170,7 +170,7 @@ HRESULT CStunSocketThread::SignalForStop(bool fPostMessages)
{ {
char data = 'x'; char data = 'x';
ASSERT(_socks[index] != NULL); ASSERT(_socks[index] != nullptr);
CSocketAddress addr(_socks[index]->GetLocalAddress()); CSocketAddress addr(_socks[index]->GetLocalAddress());
...@@ -195,7 +195,7 @@ HRESULT CStunSocketThread::SignalForStop(bool fPostMessages) ...@@ -195,7 +195,7 @@ HRESULT CStunSocketThread::SignalForStop(bool fPostMessages)
HRESULT CStunSocketThread::WaitForStopAndClose() HRESULT CStunSocketThread::WaitForStopAndClose()
{ {
void* pRetValFromThread = NULL; void* pRetValFromThread = nullptr;
if (_fThreadIsValid) if (_fThreadIsValid)
{ {
...@@ -217,7 +217,7 @@ HRESULT CStunSocketThread::WaitForStopAndClose() ...@@ -217,7 +217,7 @@ HRESULT CStunSocketThread::WaitForStopAndClose()
void* CStunSocketThread::ThreadFunction(void* pThis) void* CStunSocketThread::ThreadFunction(void* pThis)
{ {
((CStunSocketThread*)pThis)->Run(); ((CStunSocketThread*)pThis)->Run();
return NULL; return nullptr;
} }
// returns an index into _socks, not _arrSockets // returns an index into _socks, not _arrSockets
...@@ -226,7 +226,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData() ...@@ -226,7 +226,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData()
fd_set set = {}; fd_set set = {};
int nHighestSockValue = 0; int nHighestSockValue = 0;
int ret; int ret;
CStunSocket* pReadySocket = NULL; CStunSocket* pReadySocket = nullptr;
UNREFERENCED_VARIABLE(ret); // only referenced in ASSERT UNREFERENCED_VARIABLE(ret); // only referenced in ASSERT
size_t nSocketCount = _socks.size(); size_t nSocketCount = _socks.size();
...@@ -239,7 +239,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData() ...@@ -239,7 +239,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData()
for (size_t index = 0; index < nSocketCount; index++) for (size_t index = 0; index < nSocketCount; index++)
{ {
ASSERT(_socks[index] != NULL); ASSERT(_socks[index] != nullptr);
int sock = _socks[index]->GetSocketHandle(); int sock = _socks[index]->GetSocketHandle();
ASSERT(sock != -1); ASSERT(sock != -1);
FD_SET(sock, &set); FD_SET(sock, &set);
...@@ -247,7 +247,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData() ...@@ -247,7 +247,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData()
} }
// wait indefinitely for a socket // wait indefinitely for a socket
ret = ::select(nHighestSockValue+1, &set, NULL, NULL, NULL); ret = ::select(nHighestSockValue+1, &set, nullptr, nullptr, nullptr);
ASSERT(ret > 0); // This will be a benign assert, and should never happen. But I will want to know if it does ASSERT(ret > 0); // This will be a benign assert, and should never happen. But I will want to know if it does
...@@ -266,7 +266,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData() ...@@ -266,7 +266,7 @@ CStunSocket* CStunSocketThread::WaitForSocketData()
} }
} }
ASSERT(pReadySocket != NULL); ASSERT(pReadySocket != nullptr);
return pReadySocket; return pReadySocket;
} }
...@@ -306,16 +306,16 @@ void CStunSocketThread::Run() ...@@ -306,16 +306,16 @@ void CStunSocketThread::Run()
break; break;
} }
ASSERT(pSocket != NULL); ASSERT(pSocket != nullptr);
if (pSocket == NULL) if (pSocket == nullptr)
{ {
// just go back to waiting; // just go back to waiting;
continue; continue;
} }
} }
ASSERT(pSocket != NULL); ASSERT(pSocket != nullptr);
// now receive the data // now receive the data
_spBufferIn->SetSize(0); _spBufferIn->SetSize(0);
...@@ -342,7 +342,7 @@ void CStunSocketThread::Run() ...@@ -342,7 +342,7 @@ void CStunSocketThread::Run()
Logging::LogMsg(LL_VERBOSE, "recvfrom returns %d from %s on local interface %s on thread %lu", ret, szIPRemote, szIPLocal, (unsigned long)threadid); Logging::LogMsg(LL_VERBOSE, "recvfrom returns %d from %s on local interface %s on thread %lu", ret, szIPRemote, szIPLocal, (unsigned long)threadid);
allowed_to_pass = (_spLimiter.get() != NULL) ? _spLimiter->RateCheck(_msgIn.addrRemote) : true; allowed_to_pass = (_spLimiter.get() != nullptr) ? _spLimiter->RateCheck(_msgIn.addrRemote) : true;
if (allowed_to_pass == false) if (allowed_to_pass == false)
{ {
......
...@@ -78,7 +78,7 @@ void CTCPStunThread::Reset() ...@@ -78,7 +78,7 @@ void CTCPStunThread::Reset()
_pNewConnList = &_hashConnections1; _pNewConnList = &_hashConnections1;
_pOldConnList = &_hashConnections2; _pOldConnList = &_hashConnections2;
_timeLastSweep = time(NULL); _timeLastSweep = time(nullptr);
} }
...@@ -222,7 +222,7 @@ CStunSocket* CTCPStunThread::GetListenSocket(int sock) ...@@ -222,7 +222,7 @@ CStunSocket* CTCPStunThread::GetListenSocket(int sock)
} }
} }
} }
return NULL; return nullptr;
} }
...@@ -305,7 +305,7 @@ HRESULT CTCPStunThread::Start() ...@@ -305,7 +305,7 @@ HRESULT CTCPStunThread::Start()
ChkIf(_pipe[0] == -1, E_UNEXPECTED); // Init hasn't been called ChkIf(_pipe[0] == -1, E_UNEXPECTED); // Init hasn't been called
_fNeedToExit = false; _fNeedToExit = false;
ret = ::pthread_create(&_pthread, NULL, ThreadFunction, this); ret = ::pthread_create(&_pthread, nullptr, ThreadFunction, this);
ChkIfA(ret != 0, ERRNO_TO_HRESULT(ret)); ChkIfA(ret != 0, ERRNO_TO_HRESULT(ret));
_fThreadIsValid = true; _fThreadIsValid = true;
...@@ -317,7 +317,7 @@ Cleanup: ...@@ -317,7 +317,7 @@ Cleanup:
HRESULT CTCPStunThread::Stop() HRESULT CTCPStunThread::Stop()
{ {
void* pRetValueFromThread = NULL; void* pRetValueFromThread = nullptr;
if (_fThreadIsValid) if (_fThreadIsValid)
{ {
...@@ -341,7 +341,7 @@ HRESULT CTCPStunThread::Stop() ...@@ -341,7 +341,7 @@ HRESULT CTCPStunThread::Stop()
void* CTCPStunThread::ThreadFunction(void* pThis) void* CTCPStunThread::ThreadFunction(void* pThis)
{ {
((CTCPStunThread*)pThis)->Run(); ((CTCPStunThread*)pThis)->Run();
return NULL; return nullptr;
} }
int CTCPStunThread::GetTimeoutSeconds() int CTCPStunThread::GetTimeoutSeconds()
...@@ -365,14 +365,14 @@ void CTCPStunThread::Run() ...@@ -365,14 +365,14 @@ void CTCPStunThread::Run()
Logging::LogMsg(LL_DEBUG, "Starting TCP listening thread (%d sockets)\n", _countSocks); Logging::LogMsg(LL_DEBUG, "Starting TCP listening thread (%d sockets)\n", _countSocks);
_timeLastSweep = time(NULL); _timeLastSweep = time(nullptr);
while (_fNeedToExit == false) while (_fNeedToExit == false)
{ {
PollEvent pollevent = {}; PollEvent pollevent = {};
// wait for a notification // wait for a notification
int timeout = GetTimeoutSeconds(); int timeout = GetTimeoutSeconds();
CStunSocket* pListenSocket = NULL; CStunSocket* pListenSocket = nullptr;
// turn off epoll eventing from the listen sockets if we are at max connections // turn off epoll eventing from the listen sockets if we are at max connections
// otherwise, make sure it is enabled. // otherwise, make sure it is enabled.
...@@ -429,16 +429,16 @@ void CTCPStunThread::Run() ...@@ -429,16 +429,16 @@ void CTCPStunThread::Run()
void CTCPStunThread::ProcessConnectionEvent(int sock, uint32_t eventflags) void CTCPStunThread::ProcessConnectionEvent(int sock, uint32_t eventflags)
{ {
StunConnection** ppConn = NULL; StunConnection** ppConn = nullptr;
StunConnection* pConn = NULL; StunConnection* pConn = nullptr;
ppConn = _pNewConnList->Lookup(sock); ppConn = _pNewConnList->Lookup(sock);
if (ppConn == NULL) if (ppConn == nullptr)
{ {
ppConn = _pOldConnList->Lookup(sock); ppConn = _pOldConnList->Lookup(sock);
} }
if ((ppConn == NULL) || (*ppConn == NULL)) if ((ppConn == nullptr) || (*ppConn == nullptr))
{ {
Logging::LogMsg(LL_DEBUG, "Warning - ProcessConnectionEvent could not resolve socket into connection (socket == %d)", sock); Logging::LogMsg(LL_DEBUG, "Warning - ProcessConnectionEvent could not resolve socket into connection (socket == %d)", sock);
return; return;
...@@ -489,7 +489,7 @@ StunConnection* CTCPStunThread::AcceptConnection(CStunSocket* pListenSocket) ...@@ -489,7 +489,7 @@ StunConnection* CTCPStunThread::AcceptConnection(CStunSocket* pListenSocket)
int socktmp = -1; int socktmp = -1;
sockaddr_storage addrClient; sockaddr_storage addrClient;
socklen_t socklen = sizeof(addrClient); socklen_t socklen = sizeof(addrClient);
StunConnection* pConn = NULL; StunConnection* pConn = nullptr;
HRESULT hr = S_OK; HRESULT hr = S_OK;
int insertresult; int insertresult;
int err; int err;
...@@ -513,7 +513,7 @@ StunConnection* CTCPStunThread::AcceptConnection(CStunSocket* pListenSocket) ...@@ -513,7 +513,7 @@ StunConnection* CTCPStunThread::AcceptConnection(CStunSocket* pListenSocket)
clientsock = socktmp; clientsock = socktmp;
pConn = _connectionpool.GetConnection(clientsock, role); pConn = _connectionpool.GetConnection(clientsock, role);
ChkIfA(pConn == NULL, E_FAIL); // Our connection pool has nothing left to give, only thing to do is abort this connection and close the socket ChkIfA(pConn == nullptr, E_FAIL); // Our connection pool has nothing left to give, only thing to do is abort this connection and close the socket
socktmp = -1; socktmp = -1;
ChkA(pConn->_stunsocket.SetNonBlocking(true)); ChkA(pConn->_stunsocket.SetNonBlocking(true));
...@@ -542,7 +542,7 @@ Cleanup: ...@@ -542,7 +542,7 @@ Cleanup:
if (FAILED(hr)) if (FAILED(hr))
{ {
CloseConnection(pConn); CloseConnection(pConn);
pConn = NULL; pConn = nullptr;
if (socktmp != -1) if (socktmp != -1)
{ {
close(socktmp); close(socktmp);
...@@ -625,7 +625,7 @@ HRESULT CTCPStunThread::ReceiveBytesForConnection(StunConnection* pConn) ...@@ -625,7 +625,7 @@ HRESULT CTCPStunThread::ReceiveBytesForConnection(StunConnection* pConn)
// so we can't assume the connection is still alive. And if it's not alive, pConn likely got deleted // so we can't assume the connection is still alive. And if it's not alive, pConn likely got deleted
// either refetch from the hash tables, or invent an out parameter on WriteBytesForConnection and ConsumeRemoteClose to better propagate the close state of the connection // either refetch from the hash tables, or invent an out parameter on WriteBytesForConnection and ConsumeRemoteClose to better propagate the close state of the connection
pConn = NULL; pConn = nullptr;
break; break;
} }
...@@ -647,14 +647,14 @@ HRESULT CTCPStunThread::WriteBytesForConnection(StunConnection* pConn) ...@@ -647,14 +647,14 @@ HRESULT CTCPStunThread::WriteBytesForConnection(StunConnection* pConn)
HRESULT hr = S_OK; HRESULT hr = S_OK;
int sock = pConn->_stunsocket.GetSocketHandle(); int sock = pConn->_stunsocket.GetSocketHandle();
int sent = -1; int sent = -1;
uint8_t* pData = NULL; uint8_t* pData = nullptr;
size_t bytestotal, bytesremaining; size_t bytestotal, bytesremaining;
bool fForceClose = false; bool fForceClose = false;
int err; int err;
ASSERT(pConn != NULL); ASSERT(pConn != nullptr);
pData = pConn->_spOutputBuffer->GetData(); pData = pConn->_spOutputBuffer->GetData();
bytestotal = pConn->_spOutputBuffer->GetSize(); bytestotal = pConn->_spOutputBuffer->GetSize();
...@@ -695,7 +695,7 @@ HRESULT CTCPStunThread::WriteBytesForConnection(StunConnection* pConn) ...@@ -695,7 +695,7 @@ HRESULT CTCPStunThread::WriteBytesForConnection(StunConnection* pConn)
// go back to listening for read events // go back to listening for read events
ChkA(_spPolling->ChangeEventSet(sock, EPOLL_CLIENT_READ_EVENT_SET)); ChkA(_spPolling->ChangeEventSet(sock, EPOLL_CLIENT_READ_EVENT_SET));
pConn = NULL; pConn = nullptr;
break; break;
} }
// loop back and try to send the remaining bytes // loop back and try to send the remaining bytes
...@@ -752,8 +752,8 @@ void CTCPStunThread::CloseAllConnections(StunThreadConnectionMap* pConnMap) ...@@ -752,8 +752,8 @@ void CTCPStunThread::CloseAllConnections(StunThreadConnectionMap* pConnMap)
void CTCPStunThread::SweepDeadConnections() void CTCPStunThread::SweepDeadConnections()
{ {
time_t timeCurrent = time(NULL); time_t timeCurrent = time(nullptr);
StunThreadConnectionMap* pSwap = NULL; StunThreadConnectionMap* pSwap = nullptr;
// should we try to scale the timeout based on the active number of connections? // should we try to scale the timeout based on the active number of connections?
...@@ -766,7 +766,7 @@ void CTCPStunThread::SweepDeadConnections() ...@@ -766,7 +766,7 @@ void CTCPStunThread::SweepDeadConnections()
CloseAllConnections(_pOldConnList); CloseAllConnections(_pOldConnList);
_timeLastSweep = time(NULL); _timeLastSweep = time(nullptr);
pSwap = _pOldConnList; pSwap = _pOldConnList;
...@@ -792,7 +792,7 @@ CTCPServer::CTCPServer() ...@@ -792,7 +792,7 @@ CTCPServer::CTCPServer()
{ {
for (size_t i = 0; i < ARRAYSIZE(_threads); i++) for (size_t i = 0; i < ARRAYSIZE(_threads); i++)
{ {
_threads[i] = NULL; _threads[i] = nullptr;
} }
} }
...@@ -835,7 +835,7 @@ HRESULT CTCPServer::Initialize(const CStunServerConfig& config) ...@@ -835,7 +835,7 @@ HRESULT CTCPServer::Initialize(const CStunServerConfig& config)
std::shared_ptr<RateLimiter> spLimiter; std::shared_ptr<RateLimiter> spLimiter;
bool fMultithreaded = false; // hardwire TCP to be non-threaded until we can figure this all out bool fMultithreaded = false; // hardwire TCP to be non-threaded until we can figure this all out
ChkIfA(_threads[0] != NULL, E_UNEXPECTED); // we can't already be initialized, right? ChkIfA(_threads[0] != nullptr, E_UNEXPECTED); // we can't already be initialized, right?
// optional code: create an authentication provider and initialize it here (if you want authentication) // optional code: create an authentication provider and initialize it here (if you want authentication)
// set the _spAuth member to reference it // set the _spAuth member to reference it
...@@ -906,7 +906,7 @@ HRESULT CTCPServer::Shutdown() ...@@ -906,7 +906,7 @@ HRESULT CTCPServer::Shutdown()
{ {
// destructor of each TCP thread will stop the thread before returning // destructor of each TCP thread will stop the thread before returning
delete _threads[role]; delete _threads[role];
_threads[role] = NULL; _threads[role] = nullptr;
} }
_spAuth.reset(); _spAuth.reset();
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
CDataStream::CDataStream() : CDataStream::CDataStream() :
_pBuffer(NULL), _pBuffer(nullptr),
_pos(0), _pos(0),
_fNoGrow(false) _fNoGrow(false)
{ {
...@@ -47,7 +47,7 @@ HRESULT CDataStream::SetSizeHint(size_t size) ...@@ -47,7 +47,7 @@ HRESULT CDataStream::SetSizeHint(size_t size)
void CDataStream::Reset() void CDataStream::Reset()
{ {
_spBuffer.reset(); _spBuffer.reset();
_pBuffer = NULL; _pBuffer = nullptr;
_pos = 0; _pos = 0;
_fNoGrow = false; _fNoGrow = false;
} }
...@@ -142,7 +142,7 @@ HRESULT CDataStream::Write(const void* data, size_t size) ...@@ -142,7 +142,7 @@ HRESULT CDataStream::Write(const void* data, size_t size)
size_t currentSize = GetSize(); size_t currentSize = GetSize();
HRESULT hr = S_OK; HRESULT hr = S_OK;
if ((size == 0) || (data == NULL)) if ((size == 0) || (data == nullptr))
{ {
return E_FAIL; return E_FAIL;
} }
...@@ -227,10 +227,10 @@ HRESULT CDataStream::GetBuffer(CRefCountedBuffer* pBuffer) ...@@ -227,10 +227,10 @@ HRESULT CDataStream::GetBuffer(CRefCountedBuffer* pBuffer)
return hr; return hr;
} }
// unsafe because the pointer is not guaranteed to be valid after subsequent writes. Could also be NULL if nothing has been written // unsafe because the pointer is not guaranteed to be valid after subsequent writes. Could also be nullptr if nothing has been written
uint8_t* CDataStream::GetDataPointerUnsafe() uint8_t* CDataStream::GetDataPointerUnsafe()
{ {
uint8_t* pRet = NULL; uint8_t* pRet = nullptr;
if (_pBuffer) if (_pBuffer)
{ {
......
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
CStunRequestHandler::CStunRequestHandler() : CStunRequestHandler::CStunRequestHandler() :
_pAuth(NULL), _pAuth(nullptr),
_pAddrSet(NULL), _pAddrSet(nullptr),
_pMsgIn(NULL), _pMsgIn(nullptr),
_pMsgOut(NULL), _pMsgOut(nullptr),
_integrity(), // zero-init _integrity(), // zero-init
_error(), // zero-init _error(), // zero-init
_fRequestHasResponsePort(false), _fRequestHasResponsePort(false),
...@@ -43,13 +43,13 @@ HRESULT CStunRequestHandler::ProcessRequest(const StunMessageIn& msgIn, StunMess ...@@ -43,13 +43,13 @@ HRESULT CStunRequestHandler::ProcessRequest(const StunMessageIn& msgIn, StunMess
CStunRequestHandler handler; CStunRequestHandler handler;
// parameter checking // parameter checking
ChkIfA(msgIn.pReader==NULL, E_INVALIDARG); ChkIfA(msgIn.pReader==nullptr, E_INVALIDARG);
ChkIfA(IsValidSocketRole(msgIn.socketrole)==false, E_INVALIDARG); ChkIfA(IsValidSocketRole(msgIn.socketrole)==false, E_INVALIDARG);
ChkIfA(msgOut.spBufferOut==NULL, E_INVALIDARG); ChkIfA(msgOut.spBufferOut==nullptr, E_INVALIDARG);
ChkIfA(msgOut.spBufferOut->GetAllocatedSize() < MAX_STUN_MESSAGE_SIZE, E_INVALIDARG); ChkIfA(msgOut.spBufferOut->GetAllocatedSize() < MAX_STUN_MESSAGE_SIZE, E_INVALIDARG);
ChkIf(pAddressSet == NULL, E_INVALIDARG); ChkIf(pAddressSet == nullptr, E_INVALIDARG);
// If we get something that can't be validated as a stun message, don't send back a response // If we get something that can't be validated as a stun message, don't send back a response
// STUN RFC may suggest sending back a "500", but I think that's the wrong approach. // STUN RFC may suggest sending back a "500", but I think that's the wrong approach.
...@@ -128,7 +128,7 @@ HRESULT CStunRequestHandler::ProcessRequestImpl() ...@@ -128,7 +128,7 @@ HRESULT CStunRequestHandler::ProcessRequestImpl()
if (_error.errorcode == 0) if (_error.errorcode == 0)
{ {
hrResult = ValidateAuth(); // returns S_OK if _pAuth is NULL hrResult = ValidateAuth(); // returns S_OK if _pAuth is nullptr
// if auth didn't succeed, but didn't set an error code, then setup a generic error response // if auth didn't succeed, but didn't set an error code, then setup a generic error response
if (FAILED(hrResult) && (_error.errorcode == 0)) if (FAILED(hrResult) && (_error.errorcode == 0))
...@@ -373,7 +373,7 @@ HRESULT CStunRequestHandler::ValidateAuth() ...@@ -373,7 +373,7 @@ HRESULT CStunRequestHandler::ValidateAuth()
// aliases // aliases
CStunMessageReader& reader = *(_pMsgIn->pReader); CStunMessageReader& reader = *(_pMsgIn->pReader);
if (_pAuth == NULL) if (_pAuth == nullptr)
{ {
return S_OK; // nothing to do if there is no auth mechanism in place return S_OK; // nothing to do if there is no auth mechanism in place
} }
......
...@@ -128,7 +128,7 @@ size_t CSocketAddress::GetIPImpl(void* pAddr, size_t length, bool fNBO) const ...@@ -128,7 +128,7 @@ size_t CSocketAddress::GetIPImpl(void* pAddr, size_t length, bool fNBO) const
HRESULT hr = S_OK; HRESULT hr = S_OK;
size_t bytescopied = 0; size_t bytescopied = 0;
ChkIfA(pAddr == NULL, E_INVALIDARG); ChkIfA(pAddr == nullptr, E_INVALIDARG);
ChkIfA(length <= 0, E_INVALIDARG); ChkIfA(length <= 0, E_INVALIDARG);
ChkIfA(length < GetIPLength(), E_INVALIDARG); ChkIfA(length < GetIPLength(), E_INVALIDARG);
...@@ -291,14 +291,14 @@ HRESULT CSocketAddress::ToStringBuffer(char* pszAddrBytes, size_t length) const ...@@ -291,14 +291,14 @@ HRESULT CSocketAddress::ToStringBuffer(char* pszAddrBytes, size_t length) const
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
int family = GetFamily(); int family = GetFamily();
const void *pAddrBytes = NULL; const void *pAddrBytes = nullptr;
const char* pszResult = NULL; const char* pszResult = nullptr;
const size_t portLength = 6; // colon plus 5 digit string e.g. ":55555" const size_t portLength = 6; // colon plus 5 digit string e.g. ":55555"
char szPort[portLength+1]; char szPort[portLength+1];
char delimiter = (family == AF_INET) ? ':' : '.'; char delimiter = (family == AF_INET) ? ':' : '.';
ChkIfA(pszAddrBytes == NULL, E_INVALIDARG); ChkIfA(pszAddrBytes == nullptr, E_INVALIDARG);
ChkIf(length <= 0, E_INVALIDARG); ChkIf(length <= 0, E_INVALIDARG);
pszAddrBytes[0] = 0; pszAddrBytes[0] = 0;
...@@ -319,7 +319,7 @@ HRESULT CSocketAddress::ToStringBuffer(char* pszAddrBytes, size_t length) const ...@@ -319,7 +319,7 @@ HRESULT CSocketAddress::ToStringBuffer(char* pszAddrBytes, size_t length) const
pszResult = ::inet_ntop(family, pAddrBytes, pszAddrBytes, length); pszResult = ::inet_ntop(family, pAddrBytes, pszAddrBytes, length);
ChkIf(pszResult == NULL, ERRNOHR); ChkIf(pszResult == nullptr, ERRNOHR);
sprintf(szPort, "%c%d", delimiter, GetPort()); sprintf(szPort, "%c%d", delimiter, GetPort());
#if DEBUG #if DEBUG
...@@ -338,7 +338,7 @@ HRESULT CSocketAddress::GetLocalHost(uint16_t family, CSocketAddress* pAddr) ...@@ -338,7 +338,7 @@ HRESULT CSocketAddress::GetLocalHost(uint16_t family, CSocketAddress* pAddr)
{ {
if ( ((family != AF_INET) && (family != AF_INET6)) || if ( ((family != AF_INET) && (family != AF_INET6)) ||
(pAddr == NULL)) (pAddr == nullptr))
{ {
ASSERT(false); ASSERT(false);
return E_FAIL; return E_FAIL;
......
...@@ -126,7 +126,7 @@ HRESULT CStunMessageBuilder::AddRandomTransactionId(StunTransactionId* pTransId) ...@@ -126,7 +126,7 @@ HRESULT CStunMessageBuilder::AddRandomTransactionId(StunTransactionId* pTransId)
{ {
entropy ^= getpid(); entropy ^= getpid();
entropy ^= reinterpret_cast<uintptr_t>(this); entropy ^= reinterpret_cast<uintptr_t>(this);
entropy ^= time(NULL); entropy ^= time(nullptr);
entropy ^= AtomicIncrement(&g_sequence_number); entropy ^= AtomicIncrement(&g_sequence_number);
} }
...@@ -170,7 +170,7 @@ HRESULT CStunMessageBuilder::AddAttribute(uint16_t attribType, const void* data, ...@@ -170,7 +170,7 @@ HRESULT CStunMessageBuilder::AddAttribute(uint16_t attribType, const void* data,
HRESULT hr = S_OK; HRESULT hr = S_OK;
uint16_t sizeheader = size; uint16_t sizeheader = size;
if (data == NULL) if (data == nullptr)
{ {
size = 0; size = 0;
} }
...@@ -221,7 +221,7 @@ HRESULT CStunMessageBuilder::AddErrorCode(uint16_t errorNumber, const char* pszR ...@@ -221,7 +221,7 @@ HRESULT CStunMessageBuilder::AddErrorCode(uint16_t errorNumber, const char* pszR
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
uint8_t padBytes[4] = {0}; uint8_t padBytes[4] = {0};
size_t strsize = (pszReason==NULL) ? 0 : strlen(pszReason); size_t strsize = (pszReason==nullptr) ? 0 : strlen(pszReason);
size_t size = strsize + 4; size_t size = strsize + 4;
size_t sizeheader = size; size_t sizeheader = size;
size_t padding = 0; size_t padding = 0;
...@@ -277,7 +277,7 @@ HRESULT CStunMessageBuilder::AddUnknownAttributes(const uint16_t* arr, size_t co ...@@ -277,7 +277,7 @@ HRESULT CStunMessageBuilder::AddUnknownAttributes(const uint16_t* arr, size_t co
uint16_t unpaddedsize = size; uint16_t unpaddedsize = size;
bool fPad = false; bool fPad = false;
ChkIfA(arr == NULL, E_INVALIDARG); ChkIfA(arr == nullptr, E_INVALIDARG);
ChkIfA(count <= 0, E_INVALIDARG); ChkIfA(count <= 0, E_INVALIDARG);
// fix for RFC 3489. Since legacy clients can't understand implicit padding rules // fix for RFC 3489. Since legacy clients can't understand implicit padding rules
...@@ -422,7 +422,7 @@ HRESULT CStunMessageBuilder::AddFingerprintAttribute() ...@@ -422,7 +422,7 @@ HRESULT CStunMessageBuilder::AddFingerprintAttribute()
{ {
uint32_t value; uint32_t value;
CRefCountedBuffer spBuffer; CRefCountedBuffer spBuffer;
uint8_t* pData = NULL; uint8_t* pData = nullptr;
size_t length = 0; size_t length = 0;
int offset; int offset;
...@@ -478,15 +478,15 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityImpl(uint8_t* key, size_t keysiz ...@@ -478,15 +478,15 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityImpl(uint8_t* key, size_t keysiz
const size_t c_hmacsize = 20; const size_t c_hmacsize = 20;
uint8_t hmacvaluedummy[c_hmacsize] = {}; // zero-init uint8_t hmacvaluedummy[c_hmacsize] = {}; // zero-init
unsigned int resultlength = c_hmacsize; unsigned int resultlength = c_hmacsize;
uint8_t* pDstBuf = NULL; uint8_t* pDstBuf = nullptr;
CRefCountedBuffer spBuffer; CRefCountedBuffer spBuffer;
void* pData = NULL; void* pData = nullptr;
size_t length = 0; size_t length = 0;
unsigned char* pHashResult = NULL; unsigned char* pHashResult = nullptr;
UNREFERENCED_VARIABLE(pHashResult); UNREFERENCED_VARIABLE(pHashResult);
ChkIfA(key==NULL || keysize <= 0, E_INVALIDARG); ChkIfA(key==nullptr || keysize <= 0, E_INVALIDARG);
// add in a "zero-init" HMAC value. This adds 24 bytes to the length // add in a "zero-init" HMAC value. This adds 24 bytes to the length
Chk(AddAttribute(STUN_ATTRIBUTE_MESSAGEINTEGRITY, hmacvaluedummy, ARRAYSIZE(hmacvaluedummy))); Chk(AddAttribute(STUN_ATTRIBUTE_MESSAGEINTEGRITY, hmacvaluedummy, ARRAYSIZE(hmacvaluedummy)));
...@@ -508,7 +508,7 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityImpl(uint8_t* key, size_t keysiz ...@@ -508,7 +508,7 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityImpl(uint8_t* key, size_t keysiz
#ifndef __APPLE__ #ifndef __APPLE__
pHashResult = HMAC(EVP_sha1(), key, keysize, (uint8_t*)pData, length, pDstBuf, &resultlength); pHashResult = HMAC(EVP_sha1(), key, keysize, (uint8_t*)pData, length, pDstBuf, &resultlength);
ASSERT(resultlength == 20); ASSERT(resultlength == 20);
ASSERT(pHashResult != NULL); ASSERT(pHashResult != nullptr);
#else #else
CCHmac(kCCHmacAlgSHA1, key, keysize,(uint8_t*)pData, length, pDstBuf); CCHmac(kCCHmacAlgSHA1, key, keysize,(uint8_t*)pData, length, pDstBuf);
UNREFERENCED_VARIABLE(resultlength); UNREFERENCED_VARIABLE(resultlength);
...@@ -530,7 +530,7 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityLongTerm(const char* pszUserName ...@@ -530,7 +530,7 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityLongTerm(const char* pszUserName
uint8_t key[MAX_KEY_SIZE + 1]; // long enough for 64-char strings and two semicolons and a null char for debugging uint8_t key[MAX_KEY_SIZE + 1]; // long enough for 64-char strings and two semicolons and a null char for debugging
uint8_t hash[MD5_DIGEST_LENGTH] = {}; uint8_t hash[MD5_DIGEST_LENGTH] = {};
uint8_t* pResult = NULL; uint8_t* pResult = nullptr;
uint8_t* pDst = key; uint8_t* pDst = key;
size_t lenUserName = pszUserName ? strlen(pszUserName) : 0; size_t lenUserName = pszUserName ? strlen(pszUserName) : 0;
...@@ -575,7 +575,7 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityLongTerm(const char* pszUserName ...@@ -575,7 +575,7 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityLongTerm(const char* pszUserName
pResult = CC_MD5(key, lenTotal, hash); pResult = CC_MD5(key, lenTotal, hash);
#endif #endif
ASSERT(pResult != NULL); ASSERT(pResult != nullptr);
hr= AddMessageIntegrityImpl(hash, MD5_DIGEST_LENGTH); hr= AddMessageIntegrityImpl(hash, MD5_DIGEST_LENGTH);
Cleanup: Cleanup:
......
...@@ -140,12 +140,12 @@ HRESULT CStunClientLogic::GetNextMessage(CRefCountedBuffer& spMsg, CSocketAddres ...@@ -140,12 +140,12 @@ HRESULT CStunClientLogic::GetNextMessage(CRefCountedBuffer& spMsg, CSocketAddres
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
uint32_t diff = 0; uint32_t diff = 0;
IStunClientTest* pCurrentTest = NULL; IStunClientTest* pCurrentTest = nullptr;
bool fReadyToReturn = false; bool fReadyToReturn = false;
ChkIfA(_fInitialized == false, E_FAIL); ChkIfA(_fInitialized == false, E_FAIL);
ChkIfA(spMsg->GetAllocatedSize() == 0, E_INVALIDARG); ChkIfA(spMsg->GetAllocatedSize() == 0, E_INVALIDARG);
ChkIfA(pAddrDest == NULL, E_INVALIDARG); ChkIfA(pAddrDest == nullptr, E_INVALIDARG);
// clients should pass in the expected size // clients should pass in the expected size
ChkIfA(spMsg->GetAllocatedSize() < MAX_STUN_MESSAGE_SIZE, E_INVALIDARG); ChkIfA(spMsg->GetAllocatedSize() < MAX_STUN_MESSAGE_SIZE, E_INVALIDARG);
...@@ -219,7 +219,7 @@ Cleanup: ...@@ -219,7 +219,7 @@ Cleanup:
HRESULT CStunClientLogic::ProcessResponse(CRefCountedBuffer& spMsg, CSocketAddress& addrRemote, CSocketAddress& addrLocal) HRESULT CStunClientLogic::ProcessResponse(CRefCountedBuffer& spMsg, CSocketAddress& addrRemote, CSocketAddress& addrLocal)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
IStunClientTest* pCurrentTest = NULL; IStunClientTest* pCurrentTest = nullptr;
ChkIfA(_fInitialized == false, E_FAIL); ChkIfA(_fInitialized == false, E_FAIL);
ChkIfA(spMsg->GetSize() == 0, E_INVALIDARG); ChkIfA(spMsg->GetSize() == 0, E_INVALIDARG);
...@@ -241,7 +241,7 @@ Cleanup: ...@@ -241,7 +241,7 @@ Cleanup:
HRESULT CStunClientLogic::GetResults(StunClientResults* pResults) HRESULT CStunClientLogic::GetResults(StunClientResults* pResults)
{ {
HRESULT hr=S_OK; HRESULT hr=S_OK;
ChkIfA(pResults == NULL, E_INVALIDARG); ChkIfA(pResults == nullptr, E_INVALIDARG);
*pResults = _results; *pResults = _results;
Cleanup: Cleanup:
return hr; return hr;
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
CStunClientTestBase::CStunClientTestBase() : CStunClientTestBase::CStunClientTestBase() :
_fInit(false), _fInit(false),
_pConfig(NULL), _pConfig(nullptr),
_pResults(NULL), _pResults(nullptr),
_fCompleted(false), _fCompleted(false),
_transid() // zero-init _transid() // zero-init
{ {
...@@ -38,8 +38,8 @@ HRESULT CStunClientTestBase::Init(StunClientLogicConfig* pConfig, StunClientResu ...@@ -38,8 +38,8 @@ HRESULT CStunClientTestBase::Init(StunClientLogicConfig* pConfig, StunClientResu
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ChkIfA(pConfig == NULL, E_INVALIDARG); ChkIfA(pConfig == nullptr, E_INVALIDARG);
ChkIfA(pResults == NULL, E_INVALIDARG); ChkIfA(pResults == nullptr, E_INVALIDARG);
_fInit = true; _fInit = true;
_pConfig = pConfig; _pConfig = pConfig;
......
...@@ -93,7 +93,7 @@ uint16_t CStunMessageReader::HowManyBytesNeeded() ...@@ -93,7 +93,7 @@ uint16_t CStunMessageReader::HowManyBytesNeeded()
bool CStunMessageReader::HasFingerprintAttribute() bool CStunMessageReader::HasFingerprintAttribute()
{ {
StunAttribute *pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_FINGERPRINT); StunAttribute *pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_FINGERPRINT);
return (pAttrib != NULL); return (pAttrib != nullptr);
} }
bool CStunMessageReader::IsFingerprintAttributeValid() bool CStunMessageReader::IsFingerprintAttributeValid()
...@@ -104,13 +104,13 @@ bool CStunMessageReader::IsFingerprintAttributeValid() ...@@ -104,13 +104,13 @@ bool CStunMessageReader::IsFingerprintAttributeValid()
size_t size=0; size_t size=0;
uint32_t computedValue=1; uint32_t computedValue=1;
uint32_t readValue=0; uint32_t readValue=0;
uint8_t* ptr = NULL; uint8_t* ptr = nullptr;
// the fingerprint attribute MUST be the last attribute in the stream. // the fingerprint attribute MUST be the last attribute in the stream.
// If it's not, then the code below will return false // If it's not, then the code below will return false
ChkIf(pAttrib==NULL, E_FAIL); ChkIf(pAttrib==nullptr, E_FAIL);
ChkIfA(pAttrib->attributeType != STUN_ATTRIBUTE_FINGERPRINT, E_FAIL); ChkIfA(pAttrib->attributeType != STUN_ATTRIBUTE_FINGERPRINT, E_FAIL);
...@@ -122,7 +122,7 @@ bool CStunMessageReader::IsFingerprintAttributeValid() ...@@ -122,7 +122,7 @@ bool CStunMessageReader::IsFingerprintAttributeValid()
ChkIf(size < STUN_HEADER_SIZE, E_FAIL); ChkIf(size < STUN_HEADER_SIZE, E_FAIL);
ptr = spBuffer->GetData(); ptr = spBuffer->GetData();
ChkIfA(ptr==NULL, E_FAIL); ChkIfA(ptr==nullptr, E_FAIL);
computedValue = ::crc32(0, ptr, size-8); computedValue = ::crc32(0, ptr, size-8);
computedValue = computedValue ^ STUN_FINGERPRINT_XOR; computedValue = computedValue ^ STUN_FINGERPRINT_XOR;
...@@ -137,7 +137,7 @@ Cleanup: ...@@ -137,7 +137,7 @@ Cleanup:
bool CStunMessageReader::HasMessageIntegrityAttribute() bool CStunMessageReader::HasMessageIntegrityAttribute()
{ {
return (NULL != _mapAttributes.Lookup(STUN_ATTRIBUTE_MESSAGEINTEGRITY)); return (nullptr != _mapAttributes.Lookup(STUN_ATTRIBUTE_MESSAGEINTEGRITY));
} }
HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylength) HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylength)
...@@ -151,7 +151,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen ...@@ -151,7 +151,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
uint8_t hmaccomputed[c_hmacsize] = {}; // zero-init uint8_t hmaccomputed[c_hmacsize] = {}; // zero-init
unsigned int hmaclength = c_hmacsize; unsigned int hmaclength = c_hmacsize;
#ifndef __APPLE__ #ifndef __APPLE__
HMAC_CTX* ctx = NULL; HMAC_CTX* ctx = nullptr;
#if OPENSSL_VERSION_NUMBER < 0x10100000L #if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX ctxData = {}; HMAC_CTX ctxData = {};
ctx = &ctxData; ctx = &ctxData;
...@@ -160,7 +160,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen ...@@ -160,7 +160,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
ctx = HMAC_CTX_new(); ctx = HMAC_CTX_new();
#endif #endif
#else #else
CCHmacContext* ctx = NULL; CCHmacContext* ctx = nullptr;
CCHmacContext ctxData = {}; CCHmacContext ctxData = {};
ctx = &ctxData; ctx = &ctxData;
...@@ -171,7 +171,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen ...@@ -171,7 +171,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
size_t len, nChunks; size_t len, nChunks;
CDataStream stream; CDataStream stream;
CRefCountedBuffer spBuffer; CRefCountedBuffer spBuffer;
StunAttribute* pAttribIntegrity=NULL; StunAttribute* pAttribIntegrity=nullptr;
int cmp = 0; int cmp = 0;
bool fContextInit = false; bool fContextInit = false;
...@@ -183,12 +183,12 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen ...@@ -183,12 +183,12 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
ChkIf(_indexMessageIntegrity == -1, E_FAIL); ChkIf(_indexMessageIntegrity == -1, E_FAIL);
// can a key be empty? // can a key be empty?
ChkIfA(key==NULL, E_INVALIDARG); ChkIfA(key==nullptr, E_INVALIDARG);
ChkIfA(keylength==0, E_INVALIDARG); ChkIfA(keylength==0, E_INVALIDARG);
pAttribIntegrity = _mapAttributes.Lookup(::STUN_ATTRIBUTE_MESSAGEINTEGRITY); pAttribIntegrity = _mapAttributes.Lookup(::STUN_ATTRIBUTE_MESSAGEINTEGRITY);
ChkIf(pAttribIntegrity == NULL, E_FAIL); ChkIf(pAttribIntegrity == nullptr, E_FAIL);
ChkIf(pAttribIntegrity->size != c_hmacsize, E_FAIL); ChkIf(pAttribIntegrity->size != c_hmacsize, E_FAIL);
...@@ -206,7 +206,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen ...@@ -206,7 +206,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
#if OPENSSL_VERSION_NUMBER < 0x10100000L // could be lower! #if OPENSSL_VERSION_NUMBER < 0x10100000L // could be lower!
HMAC_Init(ctx, key, keylength, EVP_sha1()); HMAC_Init(ctx, key, keylength, EVP_sha1());
#else #else
HMAC_Init_ex(ctx, key, keylength, EVP_sha1(), NULL); HMAC_Init_ex(ctx, key, keylength, EVP_sha1(), nullptr);
#endif #endif
#else #else
CCHmacInit(ctx, kCCHmacAlgSHA1, key, keylength); CCHmacInit(ctx, kCCHmacAlgSHA1, key, keylength);
...@@ -299,7 +299,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrityLong(const char* pszUser, co ...@@ -299,7 +299,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrityLong(const char* pszUser, co
HRESULT hr = S_OK; HRESULT hr = S_OK;
const size_t MAX_KEY_SIZE = MAX_STUN_AUTH_STRING_SIZE*3 + 2; const size_t MAX_KEY_SIZE = MAX_STUN_AUTH_STRING_SIZE*3 + 2;
uint8_t key[MAX_KEY_SIZE + 1]; // long enough for 64-char strings and two semicolons and a null char uint8_t key[MAX_KEY_SIZE + 1]; // long enough for 64-char strings and two semicolons and a null char
uint8_t* pData = NULL; uint8_t* pData = nullptr;
uint8_t* pDst = key; uint8_t* pDst = key;
size_t totallength = 0; size_t totallength = 0;
...@@ -314,7 +314,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrityLong(const char* pszUser, co ...@@ -314,7 +314,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrityLong(const char* pszUser, co
totallength = userLength + realmLength + passwordlength + 2; // +2 for two semi-colons totallength = userLength + realmLength + passwordlength + 2; // +2 for two semi-colons
pData = GetStream().GetDataPointerUnsafe(); pData = GetStream().GetDataPointerUnsafe();
ChkIfA(pData==NULL, E_FAIL); ChkIfA(pData==nullptr, E_FAIL);
if (userLength > 0) if (userLength > 0)
{ {
...@@ -343,7 +343,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrityLong(const char* pszUser, co ...@@ -343,7 +343,7 @@ HRESULT CStunMessageReader::ValidateMessageIntegrityLong(const char* pszUser, co
ASSERT((pDst-key) == totallength); ASSERT((pDst-key) == totallength);
#ifndef __APPLE__ #ifndef __APPLE__
ChkIfA(NULL == MD5(key, totallength, hash), E_FAIL); ChkIfA(nullptr == MD5(key, totallength, hash), E_FAIL);
#else #else
CC_MD5(key, totallength, hash); CC_MD5(key, totallength, hash);
#endif #endif
...@@ -362,7 +362,7 @@ HRESULT CStunMessageReader::GetAttributeByIndex(int index, StunAttribute* pAttri ...@@ -362,7 +362,7 @@ HRESULT CStunMessageReader::GetAttributeByIndex(int index, StunAttribute* pAttri
{ {
StunAttribute* pFound = _mapAttributes.LookupValueByIndex((size_t)index); StunAttribute* pFound = _mapAttributes.LookupValueByIndex((size_t)index);
if (pFound == NULL) if (pFound == nullptr)
{ {
return E_FAIL; return E_FAIL;
} }
...@@ -378,7 +378,7 @@ HRESULT CStunMessageReader::GetAttributeByType(uint16_t attributeType, StunAttri ...@@ -378,7 +378,7 @@ HRESULT CStunMessageReader::GetAttributeByType(uint16_t attributeType, StunAttri
{ {
StunAttribute* pFound = _mapAttributes.Lookup(attributeType); StunAttribute* pFound = _mapAttributes.Lookup(attributeType);
if (pFound == NULL) if (pFound == nullptr)
{ {
return E_FAIL; return E_FAIL;
} }
...@@ -398,20 +398,20 @@ int CStunMessageReader::GetAttributeCount() ...@@ -398,20 +398,20 @@ int CStunMessageReader::GetAttributeCount()
HRESULT CStunMessageReader::GetResponsePort(uint16_t* pPort) HRESULT CStunMessageReader::GetResponsePort(uint16_t* pPort)
{ {
StunAttribute* pAttrib = NULL; StunAttribute* pAttrib = nullptr;
HRESULT hr = S_OK; HRESULT hr = S_OK;
uint16_t portNBO; uint16_t portNBO;
uint8_t *pData = NULL; uint8_t *pData = nullptr;
ChkIfA(pPort == NULL, E_INVALIDARG); ChkIfA(pPort == nullptr, E_INVALIDARG);
pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_RESPONSE_PORT); pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_RESPONSE_PORT);
ChkIf(pAttrib == NULL, E_FAIL); ChkIf(pAttrib == nullptr, E_FAIL);
ChkIf(pAttrib->size != STUN_ATTRIBUTE_RESPONSE_PORT_SIZE, E_UNEXPECTED); ChkIf(pAttrib->size != STUN_ATTRIBUTE_RESPONSE_PORT_SIZE, E_UNEXPECTED);
pData = _stream.GetDataPointerUnsafe(); pData = _stream.GetDataPointerUnsafe();
ChkIf(pData==NULL, E_UNEXPECTED); ChkIf(pData==nullptr, E_UNEXPECTED);
memcpy(&portNBO, pData + pAttrib->offset, STUN_ATTRIBUTE_RESPONSE_PORT_SIZE); memcpy(&portNBO, pData + pAttrib->offset, STUN_ATTRIBUTE_RESPONSE_PORT_SIZE);
*pPort = ntohs(portNBO); *pPort = ntohs(portNBO);
...@@ -422,19 +422,19 @@ Cleanup: ...@@ -422,19 +422,19 @@ Cleanup:
HRESULT CStunMessageReader::GetChangeRequest(StunChangeRequestAttribute* pChangeRequest) HRESULT CStunMessageReader::GetChangeRequest(StunChangeRequestAttribute* pChangeRequest)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
uint8_t *pData = NULL; uint8_t *pData = nullptr;
StunAttribute *pAttrib; StunAttribute *pAttrib;
uint32_t value = 0; uint32_t value = 0;
ChkIfA(pChangeRequest == NULL, E_INVALIDARG); ChkIfA(pChangeRequest == nullptr, E_INVALIDARG);
pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_CHANGEREQUEST); pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_CHANGEREQUEST);
ChkIf(pAttrib == NULL, E_FAIL); ChkIf(pAttrib == nullptr, E_FAIL);
ChkIf(pAttrib->size != STUN_ATTRIBUTE_CHANGEREQUEST_SIZE, E_UNEXPECTED); ChkIf(pAttrib->size != STUN_ATTRIBUTE_CHANGEREQUEST_SIZE, E_UNEXPECTED);
pData = _stream.GetDataPointerUnsafe(); pData = _stream.GetDataPointerUnsafe();
ChkIf(pData==NULL, E_UNEXPECTED); ChkIf(pData==nullptr, E_UNEXPECTED);
memcpy(&value, pData + pAttrib->offset, STUN_ATTRIBUTE_CHANGEREQUEST_SIZE); memcpy(&value, pData + pAttrib->offset, STUN_ATTRIBUTE_CHANGEREQUEST_SIZE);
...@@ -459,13 +459,13 @@ HRESULT CStunMessageReader::GetPaddingAttributeSize(uint16_t* pSizePadding) ...@@ -459,13 +459,13 @@ HRESULT CStunMessageReader::GetPaddingAttributeSize(uint16_t* pSizePadding)
HRESULT hr = S_OK; HRESULT hr = S_OK;
StunAttribute *pAttrib; StunAttribute *pAttrib;
ChkIfA(pSizePadding == NULL, E_INVALIDARG); ChkIfA(pSizePadding == nullptr, E_INVALIDARG);
*pSizePadding = 0; *pSizePadding = 0;
pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_PADDING); pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_PADDING);
ChkIf(pAttrib == NULL, E_FAIL); ChkIf(pAttrib == nullptr, E_FAIL);
*pSizePadding = pAttrib->size; *pSizePadding = pAttrib->size;
...@@ -476,16 +476,16 @@ Cleanup: ...@@ -476,16 +476,16 @@ Cleanup:
HRESULT CStunMessageReader::GetErrorCode(uint16_t* pErrorNumber) HRESULT CStunMessageReader::GetErrorCode(uint16_t* pErrorNumber)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
uint8_t* ptr = NULL; uint8_t* ptr = nullptr;
uint8_t cl = 0; uint8_t cl = 0;
uint8_t num = 0; uint8_t num = 0;
StunAttribute* pAttrib; StunAttribute* pAttrib;
ChkIf(pErrorNumber==NULL, E_INVALIDARG); ChkIf(pErrorNumber==nullptr, E_INVALIDARG);
pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_ERRORCODE); pAttrib = _mapAttributes.Lookup(STUN_ATTRIBUTE_ERRORCODE);
ChkIf(pAttrib == NULL, E_FAIL); ChkIf(pAttrib == nullptr, E_FAIL);
// first 21 bits of error-code attribute must be zero. // first 21 bits of error-code attribute must be zero.
// followed by 3 bits of "class" and 8 bits for the error number modulo 100 // followed by 3 bits of "class" and 8 bits for the error number modulo 100
...@@ -505,9 +505,9 @@ HRESULT CStunMessageReader::GetAddressHelper(uint16_t attribType, CSocketAddress ...@@ -505,9 +505,9 @@ HRESULT CStunMessageReader::GetAddressHelper(uint16_t attribType, CSocketAddress
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
StunAttribute* pAttrib = _mapAttributes.Lookup(attribType); StunAttribute* pAttrib = _mapAttributes.Lookup(attribType);
uint8_t *pAddrStart = NULL; uint8_t *pAddrStart = nullptr;
ChkIf(pAttrib == NULL, E_FAIL); ChkIf(pAttrib == nullptr, E_FAIL);
pAddrStart = _stream.GetDataPointerUnsafe() + pAttrib->offset; pAddrStart = _stream.GetDataPointerUnsafe() + pAttrib->offset;
Chk(::GetMappedAddress(pAddrStart, pAttrib->size, pAddr)); Chk(::GetMappedAddress(pAddrStart, pAttrib->size, pAddr));
...@@ -582,8 +582,8 @@ HRESULT CStunMessageReader::GetStringAttributeByType(uint16_t attributeType, cha ...@@ -582,8 +582,8 @@ HRESULT CStunMessageReader::GetStringAttributeByType(uint16_t attributeType, cha
HRESULT hr = S_OK; HRESULT hr = S_OK;
StunAttribute* pAttrib = _mapAttributes.Lookup(attributeType); StunAttribute* pAttrib = _mapAttributes.Lookup(attributeType);
ChkIfA(pszValue == NULL, E_INVALIDARG); ChkIfA(pszValue == nullptr, E_INVALIDARG);
ChkIf(pAttrib == NULL, E_INVALIDARG); ChkIf(pAttrib == nullptr, E_INVALIDARG);
// size needs to be 1 greater than attrib.size so we can properly copy over a null char at the end // size needs to be 1 greater than attrib.size so we can properly copy over a null char at the end
ChkIf(pAttrib->size >= size, E_INVALIDARG); ChkIf(pAttrib->size >= size, E_INVALIDARG);
...@@ -860,7 +860,7 @@ HRESULT CStunMessageReader::GetBuffer(CRefCountedBuffer* pRefBuffer) ...@@ -860,7 +860,7 @@ HRESULT CStunMessageReader::GetBuffer(CRefCountedBuffer* pRefBuffer)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ChkIf(pRefBuffer == NULL, E_INVALIDARG); ChkIf(pRefBuffer == nullptr, E_INVALIDARG);
Chk(_stream.GetBuffer(pRefBuffer)); Chk(_stream.GetBuffer(pRefBuffer));
Cleanup: Cleanup:
......
...@@ -42,7 +42,7 @@ HRESULT GetMappedAddress(uint8_t* pData, size_t size, CSocketAddress* pAddr) ...@@ -42,7 +42,7 @@ HRESULT GetMappedAddress(uint8_t* pData, size_t size, CSocketAddress* pAddr)
CRefCountedBuffer spBuffer(new CBuffer(pData, size, false)); CRefCountedBuffer spBuffer(new CBuffer(pData, size, false));
CDataStream stream(spBuffer); CDataStream stream(spBuffer);
ChkIfA(pAddr==NULL, E_INVALIDARG); ChkIfA(pAddr==nullptr, E_INVALIDARG);
Chk(stream.SeekDirect(1)); // skip over the zero byte Chk(stream.SeekDirect(1)); // skip over the zero byte
......
...@@ -328,7 +328,7 @@ HRESULT CTestClientLogic::TestBehaviorAndFiltering(bool fBehaviorTest, NatBehavi ...@@ -328,7 +328,7 @@ HRESULT CTestClientLogic::TestBehaviorAndFiltering(bool fBehaviorTest, NatBehavi
stunmsgOut.spBufferOut = spMsgResponse; stunmsgOut.spBufferOut = spMsgResponse;
spMsgResponse->SetSize(0); spMsgResponse->SetSize(0);
ChkA(::CStunRequestHandler::ProcessRequest(stunmsgIn, stunmsgOut, &_tsa, NULL)); ChkA(::CStunRequestHandler::ProcessRequest(stunmsgIn, stunmsgOut, &_tsa, nullptr));
// simulate the message coming back // simulate the message coming back
......
...@@ -38,7 +38,7 @@ HRESULT CTestFastHash::AddOne(int val) ...@@ -38,7 +38,7 @@ HRESULT CTestFastHash::AddOne(int val)
Item item; Item item;
item.key = val; item.key = val;
int ret; int ret;
Item* pValue = NULL; Item* pValue = nullptr;
ret = _hashtable.Insert(val, item); ret = _hashtable.Insert(val, item);
ChkIf(ret < 0, E_FAIL); ChkIf(ret < 0, E_FAIL);
...@@ -46,7 +46,7 @@ HRESULT CTestFastHash::AddOne(int val) ...@@ -46,7 +46,7 @@ HRESULT CTestFastHash::AddOne(int val)
ChkIf(_hashtable.Exists(val)==false, E_FAIL); ChkIf(_hashtable.Exists(val)==false, E_FAIL);
pValue = _hashtable.Lookup(val); pValue = _hashtable.Lookup(val);
ChkIf(pValue == NULL, E_FAIL); ChkIf(pValue == nullptr, E_FAIL);
ChkIf(pValue->key != val, E_FAIL); ChkIf(pValue->key != val, E_FAIL);
...@@ -65,7 +65,7 @@ HRESULT CTestFastHash::RemoveOne(int val) ...@@ -65,7 +65,7 @@ HRESULT CTestFastHash::RemoveOne(int val)
ChkIf(_hashtable.Exists(val), E_FAIL); ChkIf(_hashtable.Exists(val), E_FAIL);
ChkIf(_hashtable.Lookup(val) != NULL, E_FAIL); ChkIf(_hashtable.Lookup(val) != nullptr, E_FAIL);
Cleanup: Cleanup:
return hr; return hr;
...@@ -105,12 +105,12 @@ HRESULT CTestFastHash::ValidateRangeInSet(int first, int last) ...@@ -105,12 +105,12 @@ HRESULT CTestFastHash::ValidateRangeInSet(int first, int last)
for (int x = first; x <= last; x++) for (int x = first; x <= last; x++)
{ {
Item* pValue = NULL; Item* pValue = nullptr;
ChkIf(_hashtable.Exists(x)==false, E_FAIL); ChkIf(_hashtable.Exists(x)==false, E_FAIL);
pValue = _hashtable.Lookup(x); pValue = _hashtable.Lookup(x);
ChkIf(pValue == NULL, E_FAIL); ChkIf(pValue == nullptr, E_FAIL);
ChkIf(pValue->key != x, E_FAIL); ChkIf(pValue->key != x, E_FAIL);
} }
...@@ -124,7 +124,7 @@ HRESULT CTestFastHash::ValidateRangeNotInSet(int first, int last) ...@@ -124,7 +124,7 @@ HRESULT CTestFastHash::ValidateRangeNotInSet(int first, int last)
for (int x = first; x <= last; x++) for (int x = first; x <= last; x++)
{ {
ChkIf(_hashtable.Lookup(x) != NULL, E_FAIL); ChkIf(_hashtable.Lookup(x) != nullptr, E_FAIL);
ChkIf(_hashtable.Exists(x), E_FAIL); ChkIf(_hashtable.Exists(x), E_FAIL);
} }
...@@ -145,7 +145,7 @@ HRESULT CTestFastHash::ValidateRangeInIndex(int first, int last) ...@@ -145,7 +145,7 @@ HRESULT CTestFastHash::ValidateRangeInIndex(int first, int last)
{ {
Item* pItem = _hashtable.LookupValueByIndex(x); Item* pItem = _hashtable.LookupValueByIndex(x);
if (pItem == NULL) if (pItem == nullptr)
{ {
continue; continue;
} }
......
...@@ -31,13 +31,13 @@ HRESULT CTestIntegrity::TestMessageIntegrity(bool fWithFingerprint, bool fLongCr ...@@ -31,13 +31,13 @@ HRESULT CTestIntegrity::TestMessageIntegrity(bool fWithFingerprint, bool fLongCr
CStunMessageBuilder builder; CStunMessageBuilder builder;
CStunMessageReader reader; CStunMessageReader reader;
uint8_t *pMsg = NULL; uint8_t *pMsg = nullptr;
size_t sizeMsg = 0; size_t sizeMsg = 0;
CStunMessageReader::ReaderParseState state; CStunMessageReader::ReaderParseState state;
CRefCountedBuffer spBuffer; CRefCountedBuffer spBuffer;
builder.AddBindingRequestHeader(); builder.AddBindingRequestHeader();
builder.AddRandomTransactionId(NULL); builder.AddRandomTransactionId(nullptr);
builder.AddUserName(pszUserName); builder.AddUserName(pszUserName);
builder.AddRealm(pszRealm); builder.AddRealm(pszRealm);
......
...@@ -271,7 +271,7 @@ HRESULT CTestMessageHandler::Test1() ...@@ -271,7 +271,7 @@ HRESULT CTestMessageHandler::Test1()
msgOut.spBufferOut = spBufferOut; msgOut.spBufferOut = spBufferOut;
msgOut.socketrole = RoleAA; // deliberately wrong - so we can validate if it got changed to RolePP msgOut.socketrole = RoleAA; // deliberately wrong - so we can validate if it got changed to RolePP
ChkA(CStunRequestHandler::ProcessRequest(msgIn, msgOut, &tas, NULL)); ChkA(CStunRequestHandler::ProcessRequest(msgIn, msgOut, &tas, nullptr));
reader.Reset(); reader.Reset();
ChkIfA(CStunMessageReader::BodyValidated != reader.AddBytes(spBufferOut->GetData(), spBufferOut->GetSize()), E_FAIL); ChkIfA(CStunMessageReader::BodyValidated != reader.AddBytes(spBufferOut->GetData(), spBufferOut->GetSize()), E_FAIL);
...@@ -339,7 +339,7 @@ HRESULT CTestMessageHandler::Test2() ...@@ -339,7 +339,7 @@ HRESULT CTestMessageHandler::Test2()
msgOut.socketrole = RolePP; // deliberate initialized wrong msgOut.socketrole = RolePP; // deliberate initialized wrong
msgOut.spBufferOut = spBufferOut; msgOut.spBufferOut = spBufferOut;
ChkA(CStunRequestHandler::ProcessRequest(msgIn, msgOut, &tas, NULL)); ChkA(CStunRequestHandler::ProcessRequest(msgIn, msgOut, &tas, nullptr));
// parse the response // parse the response
reader.Reset(); reader.Reset();
......
...@@ -358,7 +358,7 @@ HRESULT CTestPolling::Test2() ...@@ -358,7 +358,7 @@ HRESULT CTestPolling::Test2()
continue; continue;
} }
ChkA(ConsumeEvent(&fd, NULL)); ChkA(ConsumeEvent(&fd, nullptr));
if (randresult == 3) if (randresult == 3)
{ {
......
...@@ -72,7 +72,7 @@ HRESULT CTestReader::Test1() ...@@ -72,7 +72,7 @@ HRESULT CTestReader::Test1()
CStunMessageReader::ReaderParseState state; CStunMessageReader::ReaderParseState state;
// reader is expecting at least enough bytes to fill the header // reader is expecting at least enough bytes to fill the header
ChkIfA(reader.AddBytes(NULL, 0) != CStunMessageReader::HeaderNotRead, E_FAIL); ChkIfA(reader.AddBytes(nullptr, 0) != CStunMessageReader::HeaderNotRead, E_FAIL);
ChkIfA(reader.HowManyBytesNeeded() != STUN_HEADER_SIZE, E_FAIL); ChkIfA(reader.HowManyBytesNeeded() != STUN_HEADER_SIZE, E_FAIL);
state = reader.AddBytes(req, requestsize); state = reader.AddBytes(req, requestsize);
......
...@@ -112,7 +112,7 @@ HRESULT CTestRecvFromEx::DoTest(bool fIPV6) ...@@ -112,7 +112,7 @@ HRESULT CTestRecvFromEx::DoTest(bool fIPV6)
FD_SET(socketRecv.GetSocketHandle(), &set); FD_SET(socketRecv.GetSocketHandle(), &set);
tv.tv_sec = 3; tv.tv_sec = 3;
ret = select(socketRecv.GetSocketHandle()+1, &set, NULL, NULL, &tv); ret = select(socketRecv.GetSocketHandle()+1, &set, nullptr, nullptr, &tv);
ChkIfA(ret <= 0, E_UNEXPECTED); ChkIfA(ret <= 0, E_UNEXPECTED);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment