summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src/misc.cpp
diff options
context:
space:
mode:
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");