1
0

Use more URL-Encoding when sending API requests.

This commit is contained in:
Alexander Harkness 2021-08-23 09:35:03 +01:00
parent a78de88ac3
commit 4b8952e438
4 changed files with 17 additions and 4 deletions

View File

@ -144,8 +144,8 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
// Create the GET request:
AString ActualAddress = m_Address;
ReplaceString(ActualAddress, "%USERNAME%", a_UserName);
ReplaceString(ActualAddress, "%SERVERID%", a_ServerId);
ReplaceURL(ActualAddress, "%USERNAME%", a_UserName);
ReplaceURL(ActualAddress, "%SERVERID%", a_ServerId);
AString Request;
Request += "GET " + ActualAddress + " HTTP/1.0\r\n";

View File

@ -783,7 +783,7 @@ void cMojangAPI::QueryUUIDToProfile(const cUUID & a_UUID)
{
// Create the request address:
AString Address = m_UUIDToProfileAddress;
ReplaceString(Address, "%UUID%", a_UUID.ToShortString());
ReplaceURL(Address, "%UUID%", a_UUID.ToShortString());
// Create the HTTP request:
AString Request;

View File

@ -365,6 +365,16 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString &
void ReplaceURL(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith)
{
auto ReplaceWith = URLEncode(iReplaceWith);
ReplaceString(iHayStack, iNeedle, ReplaceWith);
}
AString & RawBEToUTF8(const char * a_RawData, size_t a_NumShorts, AString & a_UTF8)
{
a_UTF8.clear();
@ -817,7 +827,7 @@ AString URLEncode(const AString & a_Text)
AString res;
auto len = a_Text.size();
res.reserve(len);
static const char HEX[] = "0123456789abcdef";
static const char HEX[] = "0123456789ABCDEF";
for (size_t i = 0; i < len; ++i)
{
if (isalnum(a_Text[i]))

View File

@ -90,6 +90,9 @@ extern size_t RateCompareString(const AString & s1, const AString & s2);
/** Replaces each occurence of iNeedle in iHayStack with iReplaceWith */
extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export
/** Replaces each occurence of iNeedle in iHayStack with iReplaceWith, after URL-encoding iReplaceWith */
extern void ReplaceURL(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith);
/** Converts a stream of BE shorts into UTF-8 string; returns a_UTF8. */
extern AString & RawBEToUTF8(const char * a_RawData, size_t a_NumShorts, AString & a_UTF8);