summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-10-01 21:54:07 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-10-01 21:54:07 +0000
commitea1e6bd24cdac5293c3e663a874d91f87745afe3 (patch)
tree1a23ce17565e4905ccbb780703bc212a09917aad /src
parent756c6e169bb748536a8c2f92f4b281ac480f481b (diff)
base64 decoder that skips \r & \n
git-svn-id: http://svn.miranda-ng.org/main/trunk@6293 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/mir_core/http.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/mir_core/http.cpp b/src/mir_core/http.cpp
index a4a44c86dc..ff81a8fcbb 100644
--- a/src/mir_core/http.cpp
+++ b/src/mir_core/http.cpp
@@ -139,19 +139,24 @@ MIR_CORE_DLL(void*) mir_base64_decode(const char *input, unsigned *outputLen)
char *p = output;
while (input < stop) {
- BYTE e0 = Base64DecodeTable[*input++];
- BYTE e1 = Base64DecodeTable[*input++];
- BYTE e2 = Base64DecodeTable[*input++];
- BYTE e3 = Base64DecodeTable[*input++];
+ BYTE e[4];
+ for (int i=0; i < 4; ) {
+ if (*input == '\n' || *input == '\r') // simply skip a char
+ input++;
+ else if (*input == 0) // do not advance input
+ e[i++] = (BYTE)-1;
+ else
+ e[i++] = Base64DecodeTable[*input++];
+ }
- if (e0 == (BYTE)-1 || e1 == (BYTE)-1)
+ if (e[0] == (BYTE)-1 || e[1] == (BYTE)-1)
break;
- *p++ = (e0 << 2) | (e1 >> 4);
- if (e2 != (BYTE)-1)
- *p++ = ((e1 & 15) << 4) | (e2 >> 2);
- if (e3 != (BYTE)-1)
- *p++ = ((e2 & 3) << 6) | e3;
+ *p++ = (e[0] << 2) | (e[1] >> 4);
+ if (e[2] != (BYTE)-1)
+ *p++ = ((e[1] & 15) << 4) | (e[2] >> 2);
+ if (e[3] != (BYTE)-1)
+ *p++ = ((e[2] & 3) << 6) | e[3];
}
*p = 0;