summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-03-24 22:01:00 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-03-24 22:01:00 +0000
commit1e13a939b177960b7048b8532205bc369501d399 (patch)
treeedd1afd10b00d768db2280e4157bc198d6445b33 /src
parentc619ad70603e5355e68e78001df154c98306e805 (diff)
char* mir_urlEncode(const char *szUrl) added
git-svn-id: http://svn.miranda-ng.org/main/trunk@4180 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/mir_core/http.cpp58
-rw-r--r--src/mir_core/mir_core.def1
-rw-r--r--src/mir_core/mir_core_10.vcxproj1
-rw-r--r--src/mir_core/mir_core_10.vcxproj.filters3
-rw-r--r--src/mir_core/mir_core_11.vcxproj1
-rw-r--r--src/mir_core/mir_core_11.vcxproj.filters3
-rw-r--r--src/mir_core/subclass.cpp12
-rw-r--r--src/modules/netlib/netlib.cpp38
8 files changed, 80 insertions, 37 deletions
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 <http://www.gnu.org/licenses/>.
+*/
+
+#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 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="cmdline.cpp" />
+ <ClCompile Include="http.cpp" />
<ClCompile Include="icons.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
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 @@
<ClCompile Include="subclass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="http.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="commonheaders.h">
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 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="cmdline.cpp" />
+ <ClCompile Include="http.cpp" />
<ClCompile Include="icons.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
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 @@
<ClCompile Include="subclass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="http.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="commonheaders.h">
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;
}
diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp
index 4245a0e5d6..5758824627 100644
--- a/src/modules/netlib/netlib.cpp
+++ b/src/modules/netlib/netlib.cpp
@@ -409,43 +409,19 @@ INT_PTR NetlibShutdown(WPARAM wParam, LPARAM)
return 0;
}
-static const char szHexDigits[] = "0123456789ABCDEF";
INT_PTR NetlibHttpUrlEncode(WPARAM, LPARAM lParam)
{
- unsigned char *szOutput, *szInput = (unsigned char*)lParam;
- unsigned char *pszIn, *pszOut;
- int outputLen;
-
- if (szInput == NULL) {
+ if (lParam == NULL) {
SetLastError(ERROR_INVALID_PARAMETER);
- return (INT_PTR)(char*)NULL;
- }
- for (outputLen = 0, pszIn = szInput;*pszIn;pszIn++) {
- if ((48 <= *pszIn && *pszIn <= 57) || //0-9
- (65 <= *pszIn && *pszIn <= 90) || //ABC...XYZ
- (97 <= *pszIn && *pszIn <= 122) || //abc...xyz
- *pszIn == '-' || *pszIn == '_' || *pszIn == '.' || *pszIn == ' ') outputLen++;
- else outputLen+=3;
+ return NULL;
}
- szOutput = (unsigned char*)HeapAlloc(GetProcessHeap(), 0, outputLen+1);
- if (szOutput == NULL) {
+
+ char *p = mir_urlEncode((LPCSTR)lParam);
+ if (p == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
- return (INT_PTR)(unsigned char*)NULL;
- }
- for (pszOut = szOutput, pszIn = szInput;*pszIn;pszIn++) {
- if ((48 <= *pszIn && *pszIn <= 57) ||
- (65 <= *pszIn && *pszIn <= 90) ||
- (97 <= *pszIn && *pszIn <= 122) ||
- *pszIn == '-' || *pszIn == '_' || *pszIn == '.') *pszOut++=*pszIn;
- else if (*pszIn == ' ') *pszOut++='+';
- else {
- *pszOut++='%';
- *pszOut++=szHexDigits[*pszIn>>4];
- *pszOut++=szHexDigits[*pszIn&0xF];
- }
+ return NULL;
}
- *pszOut = '\0';
- return (INT_PTR)szOutput;
+ return (INT_PTR)p;
}
static const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";