summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src/misc.cpp
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2015-01-27 07:01:46 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2015-01-27 07:01:46 +0000
commit950aaf82c22eede84e5e36f77181274144ce8b7d (patch)
tree6c90a492741a92a8291944f5077c99fd10012a50 /protocols/VKontakte/src/misc.cpp
parent24c5c5da5e34c0cfb1f6798afb3029f85d5dd062 (diff)
VKontakte:
add option for non-standard (by VEG) urlDecode message version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@11923 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte/src/misc.cpp')
-rw-r--r--protocols/VKontakte/src/misc.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index 9576d09224..b49d4424e2 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -80,6 +80,48 @@ HANDLE GetIconHandle(int iCommand)
/////////////////////////////////////////////////////////////////////////////////////////
+static const char szHexDigits[] = "0123456789ABCDEF";
+
+char* ExpUrlEncode(const char *szUrl, bool strict)
+{
+ if (szUrl == NULL)
+ return NULL;
+
+ const BYTE *s;
+ int outputLen;
+ for (outputLen = 0, s = (const BYTE*)szUrl; *s; s++) {
+ if ((*s & 0x80 && !strict) || // UTF-8 multibyte
+ ('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 == NULL)
+ return NULL;
+
+ char *d = szOutput;
+ for (s = (const BYTE*)szUrl; *s; s++) {
+ if ((*s & 0x80 && !strict) || // UTF-8 multibyte
+ ('0' <= *s && *s <= '9') || //0-9
+ ('A' <= *s && *s <= 'Z') || //ABC...XYZ
+ ('a' <= *s && *s <= 'z') || //abc...xyz
+ *s == '~' || *s == '-' || *s == '_' || *s == '.') *d++ = *s;
+ else if (*s == ' ') *d++ = '+';
+ else {
+ *d++ = '%';
+ *d++ = szHexDigits[*s >> 4];
+ *d++ = szHexDigits[*s & 0xF];
+ }
+ }
+ *d = '\0';
+ return szOutput;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
AsyncHttpRequest::AsyncHttpRequest()
{
cbSize = sizeof(NETLIBHTTPREQUEST);
@@ -91,6 +133,7 @@ AsyncHttpRequest::AsyncHttpRequest()
bNeedsRestart = false;
bIsMainConn = false;
m_pFunc = NULL;
+ bExpUrlEncode = false;
}
AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url, bool bSecure, VK_REQUEST_HANDLER pFunc)
@@ -98,6 +141,7 @@ AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url
cbSize = sizeof(NETLIBHTTPREQUEST);
m_bApiReq = true;
bIsMainConn = false;
+ bExpUrlEncode = ppro->m_bUseNonStandardUrlEncode;
AddHeader("Connection", "keep-alive");
AddHeader("Accept-Encoding", "booo");