summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-01-28 15:51:04 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-01-28 15:51:04 +0300
commitac6607c5f76566c2c840ca3955a22448738df9b3 (patch)
treeb697dbe07b88ac8fefb5f00a003c95710b3bbbeb /src
parente787987f54733bd58f69ced43a506aa7fc42fb7c (diff)
mir_urlDecode & mir_urlEncode to return CMStringA
Diffstat (limited to 'src')
-rw-r--r--src/core/stdcrypt/src/stdafx.h1
-rw-r--r--src/core/stdfile/src/stdafx.h1
-rw-r--r--src/mir_app/src/MHttpRequest.cpp4
-rw-r--r--src/mir_app/src/stdafx.h1
-rwxr-xr-xsrc/mir_core/src/http.cpp68
-rw-r--r--src/mir_core/src/stdafx.h1
6 files changed, 25 insertions, 51 deletions
diff --git a/src/core/stdcrypt/src/stdafx.h b/src/core/stdcrypt/src/stdafx.h
index 2ae40fe576..6ce79cf7e1 100644
--- a/src/core/stdcrypt/src/stdafx.h
+++ b/src/core/stdcrypt/src/stdafx.h
@@ -58,7 +58,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_ignore.h>
#include <m_icolib.h>
#include <m_timezones.h>
-#include <m_string.h>
#include <m_crypto.h>
#include "version.h"
diff --git a/src/core/stdfile/src/stdafx.h b/src/core/stdfile/src/stdafx.h
index 31e8c09be0..acd785ff7c 100644
--- a/src/core/stdfile/src/stdafx.h
+++ b/src/core/stdfile/src/stdafx.h
@@ -66,7 +66,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_icolib.h>
#include <m_timezones.h>
#include <m_metacontacts.h>
-#include <m_string.h>
#include "version.h"
diff --git a/src/mir_app/src/MHttpRequest.cpp b/src/mir_app/src/MHttpRequest.cpp
index 0ffd73f894..832b087bc5 100644
--- a/src/mir_app/src/MHttpRequest.cpp
+++ b/src/mir_app/src/MHttpRequest.cpp
@@ -78,7 +78,7 @@ MIR_APP_DLL(MHttpRequest*) operator<<(MHttpRequest *pReq, const CHAR_PARAM &para
CMStringA &s = pReq->m_szParam;
if (!s.IsEmpty())
s.AppendChar('&');
- s.AppendFormat("%s=%s", param.szName, ptrA(mir_urlEncode(param.szValue)));
+ s.AppendFormat("%s=%s", param.szName, mir_urlEncode(param.szValue).c_str());
return pReq;
}
@@ -88,6 +88,6 @@ MIR_APP_DLL(MHttpRequest*) operator<<(MHttpRequest *pReq, const WCHAR_PARAM &par
CMStringA &s = pReq->m_szParam;
if (!s.IsEmpty())
s.AppendChar('&');
- s.AppendFormat("%s=%s", param.szName, ptrA(mir_urlEncode(szValue)));
+ s.AppendFormat("%s=%s", param.szName, mir_urlEncode(szValue).c_str());
return pReq;
}
diff --git a/src/mir_app/src/stdafx.h b/src/mir_app/src/stdafx.h
index f9c6d70b84..17179644b5 100644
--- a/src/mir_app/src/stdafx.h
+++ b/src/mir_app/src/stdafx.h
@@ -61,7 +61,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <win2k.h>
#include <m_system.h>
-#include <m_string.h>
#include <newpluginapi.h>
#include <m_database.h>
#include <m_db_int.h>
diff --git a/src/mir_core/src/http.cpp b/src/mir_core/src/http.cpp
index d1386e4519..312647405e 100755
--- a/src/mir_core/src/http.cpp
+++ b/src/mir_core/src/http.cpp
@@ -21,71 +21,49 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static const char szHexDigits[] = "0123456789ABCDEF";
-MIR_CORE_DLL(char*) mir_urlDecode(const char *szUrl)
+MIR_CORE_DLL(CMStringA) mir_urlDecode(const char *szUrl)
{
if (szUrl == nullptr)
- return nullptr;
-
- char *ret = mir_strdup(szUrl);
+ return CMStringA();
- for (char *p = ret; *p; p++) {
- switch (*p) {
- case '%':
- int ii;
- sscanf(p+1, "%2x", &ii);
- strdel(p, 2);
- *p = ii;
- break;
+ CMStringA ret(szUrl);
+ ret.Replace("+", " ");
- case '+':
- *p = ' ';
- break;
- }
+ for (int i = ret.Find("%", 0); i != -1; i = ret.Find("%", i)) {
+ int ii;
+ sscanf(ret.c_str()+i+1, "%2x", &ii);
+ ret.Delete(i, 3);
+ ret.Insert(i, ii);
}
return ret;
}
-MIR_CORE_DLL(char*) mir_urlEncode(const char *szUrl)
+MIR_CORE_DLL(CMStringA) mir_urlEncode(const char *szUrl)
{
if (szUrl == nullptr)
- return nullptr;
+ return CMStringA();
- const BYTE *s;
- int outputLen;
- for (outputLen = 0, s = (const BYTE*)szUrl; *s; s++) {
- if (('0' <= *s && *s <= '9') || //0-9
- ('A' <= *s && *s <= 'Z') || //ABC...XYZ
- ('a' <= *s && *s <= 'z') || //abc...xyz
- *s == '-' || *s == '_' || *s == '.' || *s == ' ' || *s == '~')
- outputLen++;
- else
- outputLen += 3;
- }
-
- char *szOutput = (char*)mir_alloc(outputLen+1);
- if (szOutput == nullptr)
- return nullptr;
+ CMStringA ret;
- char *d = szOutput;
- for (s = (const BYTE*)szUrl; *s; s++) {
- if (('0' <= *s && *s <= '9') || //0-9
- ('A' <= *s && *s <= 'Z') || //ABC...XYZ
- ('a' <= *s && *s <= 'z') || //abc...xyz
+ for (const BYTE *s = (const BYTE*)szUrl; *s; s++) {
+ if (('0' <= *s && *s <= '9') || // 0-9
+ ('A' <= *s && *s <= 'Z') || // ABC...XYZ
+ ('a' <= *s && *s <= 'z') || // abc...xyz
*s == '-' || *s == '_' || *s == '.' || *s == '~')
{
- *d++ = *s;
+ ret.AppendChar(*s);
}
else if (*s == ' ') {
- *d++ = '+';
+ ret.AppendChar('+');
}
else {
- *d++ = '%';
- *d++ = szHexDigits[*s >> 4];
- *d++ = szHexDigits[*s & 0xF];
+ ret.AppendChar('%');
+ ret.AppendChar(szHexDigits[*s >> 4]);
+ ret.AppendChar(szHexDigits[*s & 0xF]);
}
}
- *d = '\0';
- return szOutput;
+
+ return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_core/src/stdafx.h b/src/mir_core/src/stdafx.h
index 60155a4846..6486e2fbfa 100644
--- a/src/mir_core/src/stdafx.h
+++ b/src/mir_core/src/stdafx.h
@@ -56,7 +56,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_db_int.h>
#include <newpluginapi.h>
#include <m_langpack.h>
-#include <m_string.h>
#include <m_metacontacts.h>
#include <m_skin.h>
#include <m_icolib.h>