diff --git a/src/cpp/ripple/HttpsClient.cpp b/src/cpp/ripple/HttpsClient.cpp index a2c5bb385b..9e4c313c7a 100644 --- a/src/cpp/ripple/HttpsClient.cpp +++ b/src/cpp/ripple/HttpsClient.cpp @@ -473,7 +473,7 @@ void HttpsClient::sendSMS(boost::asio::io_service& io_service, const std::string % theConfig.SMS_TO % theConfig.SMS_KEY % theConfig.SMS_SECRET - % strText); + % urlEncode(strText)); // cLog(lsINFO) << "SMS: Request:" << strURI; cLog(lsINFO) << "SMS: Request: '" << strText << "'"; diff --git a/src/cpp/ripple/utils.cpp b/src/cpp/ripple/utils.cpp index 4c6d5707b4..de771bc7b9 100644 --- a/src/cpp/ripple/utils.cpp +++ b/src/cpp/ripple/utils.cpp @@ -187,6 +187,38 @@ std::string strCopy(const std::vector& vucSrc) } +extern std::string urlEncode(const std::string& strSrc) +{ + std::string strDst; + int iOutput = 0; + int iSize = strSrc.length(); + + strDst.resize(iSize*3); + + for (int iInput = 0; iInput < iSize; iInput++) { + unsigned char c = strSrc[iInput]; + + if (c == ' ') + { + strDst[iOutput++] = '+'; + } + else if (isalnum(c)) + { + strDst[iOutput++] = c; + } + else + { + strDst[iOutput++] = '%'; + strDst[iOutput++] = charHex(c >> 4); + strDst[iOutput++] = charHex(c & 15); + } + } + + strDst.resize(iOutput); + + return strDst; +} + // // DH support // diff --git a/src/cpp/ripple/utils.h b/src/cpp/ripple/utils.h index 2c60a773f3..19333c3bee 100644 --- a/src/cpp/ripple/utils.h +++ b/src/cpp/ripple/utils.h @@ -103,6 +103,8 @@ int iToSeconds(boost::posix_time::ptime ptWhen); boost::posix_time::ptime ptFromSeconds(int iSeconds); uint64_t utFromSeconds(int iSeconds); +extern std::string urlEncode(const std::string& strSrc); + /* void intIPtoStr(int ip,std::string& retStr); int strIPtoInt(std::string& ipStr); @@ -214,8 +216,8 @@ DH* DH_der_load(const std::string& strDer); std::string DH_der_gen(int iKeyLength); void getRand(unsigned char *buf, int num); -inline static void getRand(char *buf, int num) { return getRand(reinterpret_cast(buf), num); } -inline static void getRand(void *buf, int num) { return getRand(reinterpret_cast(buf), num); } +inline static void getRand(char *buf, int num) { return getRand(reinterpret_cast(buf), num); } +inline static void getRand(void *buf, int num) { return getRand(reinterpret_cast(buf), num); } inline std::string strGetEnv(const std::string& strKey) {