From 1e13a939b177960b7048b8532205bc369501d399 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 24 Mar 2013 22:01:00 +0000 Subject: char* mir_urlEncode(const char *szUrl) added git-svn-id: http://svn.miranda-ng.org/main/trunk@4180 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/http.cpp | 58 ++++++++++++++++++++++++++++++++ src/mir_core/mir_core.def | 1 + src/mir_core/mir_core_10.vcxproj | 1 + src/mir_core/mir_core_10.vcxproj.filters | 3 ++ src/mir_core/mir_core_11.vcxproj | 1 + src/mir_core/mir_core_11.vcxproj.filters | 3 ++ src/mir_core/subclass.cpp | 12 +++---- 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/mir_core/http.cpp (limited to 'src/mir_core') diff --git a/src/mir_core/http.cpp b/src/mir_core/http.cpp new file mode 100644 index 0000000000..aa977fee45 --- /dev/null +++ b/src/mir_core/http.cpp @@ -0,0 +1,58 @@ +/* +Copyright (C) 2012-13 Miranda NG team (http://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "commonheaders.h" + +///////////////////////////////////////////////////////////////////////////////////////// + +static const char szHexDigits[] = "0123456789ABCDEF"; + +MIR_CORE_DLL(char*) mir_urlEncode(const char *szUrl) +{ + if (szUrl == NULL) + return NULL; + + const char *s; + int outputLen; + for (outputLen = 0, s = 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 == ' ') outputLen++; + else outputLen += 3; + } + + char *szOutput = (char*)mir_alloc(outputLen+1); + if (szOutput == NULL) + return NULL; + + char *d = szOutput; + for (s = 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 == '.') *d++ = *s; + else if (*s == ' ') *d++='+'; + else { + *d++ = '%'; + *d++ = szHexDigits[*s >> 4]; + *d++ = szHexDigits[*s & 0xF]; + } + } + *d = '\0'; + return szOutput; +} diff --git a/src/mir_core/mir_core.def b/src/mir_core/mir_core.def index 042b5bb9d9..6858f16234 100644 --- a/src/mir_core/mir_core.def +++ b/src/mir_core/mir_core.def @@ -141,3 +141,4 @@ mir_callNextSubclass @138 KillModuleSubclassing @139 mir_wstrndup @140 mir_unsubclassWindow @141 +mir_urlEncode @142 diff --git a/src/mir_core/mir_core_10.vcxproj b/src/mir_core/mir_core_10.vcxproj index a44a146761..fdb1c7da9d 100644 --- a/src/mir_core/mir_core_10.vcxproj +++ b/src/mir_core/mir_core_10.vcxproj @@ -27,6 +27,7 @@ + Create diff --git a/src/mir_core/mir_core_10.vcxproj.filters b/src/mir_core/mir_core_10.vcxproj.filters index 3c50baf5a8..1ccf05526a 100644 --- a/src/mir_core/mir_core_10.vcxproj.filters +++ b/src/mir_core/mir_core_10.vcxproj.filters @@ -61,6 +61,9 @@ Source Files + + Source Files + diff --git a/src/mir_core/mir_core_11.vcxproj b/src/mir_core/mir_core_11.vcxproj index 2a7728f708..84f2ad5cfa 100644 --- a/src/mir_core/mir_core_11.vcxproj +++ b/src/mir_core/mir_core_11.vcxproj @@ -27,6 +27,7 @@ + Create diff --git a/src/mir_core/mir_core_11.vcxproj.filters b/src/mir_core/mir_core_11.vcxproj.filters index 3c50baf5a8..1ccf05526a 100644 --- a/src/mir_core/mir_core_11.vcxproj.filters +++ b/src/mir_core/mir_core_11.vcxproj.filters @@ -61,6 +61,9 @@ Source Files + + Source Files + diff --git a/src/mir_core/subclass.cpp b/src/mir_core/subclass.cpp index a2e7530f0e..4bf17e5de2 100644 --- a/src/mir_core/subclass.cpp +++ b/src/mir_core/subclass.cpp @@ -43,7 +43,7 @@ static LRESULT CALLBACK MSubclassWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP return p->m_hooks[p->m_iHooks-1](hwnd, uMsg, wParam, lParam); return p->m_origWndProc(hwnd, uMsg, wParam, lParam); - } + } return DefWindowProc(hwnd, uMsg, wParam, lParam); } @@ -67,7 +67,7 @@ MIR_CORE_DLL(void) mir_subclassWindow(HWND hWnd, WNDPROC wndProc) p->m_hooks = (WNDPROC*)realloc(p->m_hooks, (p->m_iHooks+1)*sizeof(WNDPROC)); } - p->m_hooks[p->m_iHooks++] = wndProc; + p->m_hooks[p->m_iHooks++] = wndProc; } MIR_CORE_DLL(void) mir_subclassWindowFull(HWND hWnd, WNDPROC wndProc, WNDPROC oldWndProc) @@ -91,7 +91,7 @@ MIR_CORE_DLL(void) mir_subclassWindowFull(HWND hWnd, WNDPROC wndProc, WNDPROC ol p->m_hooks = (WNDPROC*)realloc(p->m_hooks, (p->m_iHooks+1)*sizeof(WNDPROC)); } - p->m_hooks[p->m_iHooks++] = wndProc; + p->m_hooks[p->m_iHooks++] = wndProc; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -141,14 +141,14 @@ MIR_CORE_DLL(LRESULT) mir_callNextSubclass(HWND hWnd, WNDPROC wndProc, UINT uMsg if (p->m_hooks[i] != wndProc) continue; - // next hook exists, call it + // next hook exists, call it if (i != 0) return p->m_hooks[i-1](hWnd, uMsg, wParam, lParam); // last hook called, ping the default window procedure if (uMsg != WM_DESTROY) return p->m_origWndProc(hWnd, uMsg, wParam, lParam); - + WNDPROC saveProc = p->m_origWndProc; arSubclass.remove(p); delete p; @@ -156,7 +156,7 @@ MIR_CORE_DLL(LRESULT) mir_callNextSubclass(HWND hWnd, WNDPROC wndProc, UINT uMsg SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)saveProc); return saveProc(hWnd, uMsg, wParam, lParam); } - + // invalid / closed hook return 0; } -- cgit v1.2.3