Core/PacketIO: Add a validating string helper class for use in packet classes

(cherry picked from commit f2f47f774f3d9c5da1a38b5f20cbfe59c2ff66af)
This commit is contained in:
Shauren
2021-12-23 23:55:58 +01:00
parent def97385cc
commit 3ebfa8cc64
6 changed files with 192 additions and 7 deletions
@@ -16,9 +16,48 @@
*/
#include "PacketUtilities.h"
#include "Hyperlinks.h"
#include "Errors.h"
#include <utf8.h>
#include <sstream>
WorldPackets::InvalidStringValueException::InvalidStringValueException(std::string const& value) : ByteBufferInvalidValueException("string", value.c_str())
{
}
WorldPackets::InvalidUtf8ValueException::InvalidUtf8ValueException(std::string const& value) : InvalidStringValueException(value)
{
}
WorldPackets::InvalidHyperlinkException::InvalidHyperlinkException(std::string const& value) : InvalidStringValueException(value)
{
}
WorldPackets::IllegalHyperlinkException::IllegalHyperlinkException(std::string const& value) : InvalidStringValueException(value)
{
}
bool WorldPackets::Strings::Utf8::Validate(std::string const& value)
{
if (!utf8::is_valid(value.begin(), value.end()))
throw InvalidUtf8ValueException(value);
return true;
}
bool WorldPackets::Strings::Hyperlinks::Validate(std::string const& value)
{
if (!Trinity::Hyperlinks::CheckAllLinks(value))
throw InvalidHyperlinkException(value);
return true;
}
bool WorldPackets::Strings::NoHyperlinks::Validate(std::string const& value)
{
if (value.find('|') != std::string::npos)
throw IllegalHyperlinkException(value);
return true;
}
WorldPackets::PacketArrayMaxCapacityException::PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit)
{
std::ostringstream builder;