diff options
author | George Hazan <george.hazan@gmail.com> | 2013-08-14 17:49:08 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-08-14 17:49:08 +0000 |
commit | d30ebf7e3b54d8a5887c0f6c2382987f8ad80420 (patch) | |
tree | aee070e4136352c91fe6946c0f2b607edc369cd5 /protocols | |
parent | 3761434e0c1f631a78398226e53ca4a25431c2cd (diff) |
built-in base64 removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@5688 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Twitter/src/Base64Coder.cpp | 319 | ||||
-rw-r--r-- | protocols/Twitter/src/Base64Coder.h | 69 | ||||
-rw-r--r-- | protocols/Twitter/src/oauth.cpp | 11 | ||||
-rw-r--r-- | protocols/Twitter/src/stdafx.h | 3 | ||||
-rw-r--r-- | protocols/Twitter/src/twitter.cpp | 7 | ||||
-rw-r--r-- | protocols/Twitter/src/utility.h | 1 | ||||
-rw-r--r-- | protocols/Twitter/twitter_10.vcxproj | 2 | ||||
-rw-r--r-- | protocols/Twitter/twitter_10.vcxproj.filters | 6 | ||||
-rw-r--r-- | protocols/Twitter/twitter_11.vcxproj | 2 | ||||
-rw-r--r-- | protocols/Twitter/twitter_11.vcxproj.filters | 6 |
10 files changed, 5 insertions, 421 deletions
diff --git a/protocols/Twitter/src/Base64Coder.cpp b/protocols/Twitter/src/Base64Coder.cpp deleted file mode 100644 index 4944034c3e..0000000000 --- a/protocols/Twitter/src/Base64Coder.cpp +++ /dev/null @@ -1,319 +0,0 @@ -// Base64Coder.cpp: implementation of the Base64Coder class.
-// http://support.microsoft.com/kb/191239
-//////////////////////////////////////////////////////////////////////
-
-#include "Base64Coder.h"
-
-// Digits...
-static char Base64Digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-BOOL Base64Coder::m_Init = FALSE;
-char Base64Coder::m_DecodeTable[256];
-
-#ifndef PAGESIZE
-#define PAGESIZE 4096
-#endif
-
-#ifndef ROUNDTOPAGE
-#define ROUNDTOPAGE(a) (((a/4096)+1)*4096)
-#endif
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-Base64Coder::Base64Coder()
-: m_pDBuffer(NULL),
- m_pEBuffer(NULL),
- m_nDBufLen(0),
- m_nEBufLen(0)
-{
-
-}
-
-Base64Coder::~Base64Coder()
-{
- if(m_pDBuffer != NULL)
- delete [] m_pDBuffer;
-
- if(m_pEBuffer != NULL)
- delete [] m_pEBuffer;
-}
-
-LPCSTR Base64Coder::DecodedMessage() const
-{
- return (LPCSTR) m_pDBuffer;
-}
-
-LPCSTR Base64Coder::EncodedMessage() const
-{
- return (LPCSTR) m_pEBuffer;
-}
-
-void Base64Coder::AllocEncode(DWORD nSize)
-{
- if(m_nEBufLen < nSize)
- {
- if(m_pEBuffer != NULL)
- delete [] m_pEBuffer;
-
- m_nEBufLen = ROUNDTOPAGE(nSize);
- m_pEBuffer = new BYTE[m_nEBufLen];
- }
-
- ::ZeroMemory(m_pEBuffer, m_nEBufLen);
- m_nEDataLen = 0;
-}
-
-void Base64Coder::AllocDecode(DWORD nSize)
-{
- if(m_nDBufLen < nSize)
- {
- if(m_pDBuffer != NULL)
- delete [] m_pDBuffer;
-
- m_nDBufLen = ROUNDTOPAGE(nSize);
- m_pDBuffer = new BYTE[m_nDBufLen];
- }
-
- ::ZeroMemory(m_pDBuffer, m_nDBufLen);
- m_nDDataLen = 0;
-}
-
-void Base64Coder::SetEncodeBuffer(const PBYTE pBuffer, DWORD nBufLen)
-{
- DWORD i = 0;
-
- AllocEncode(nBufLen);
- while(i < nBufLen)
- {
- if(!_IsBadMimeChar(pBuffer[i]))
- {
- m_pEBuffer[m_nEDataLen] = pBuffer[i];
- m_nEDataLen++;
- }
-
- i++;
- }
-}
-
-void Base64Coder::SetDecodeBuffer(const PBYTE pBuffer, DWORD nBufLen)
-{
- AllocDecode(nBufLen);
- ::CopyMemory(m_pDBuffer, pBuffer, nBufLen);
- m_nDDataLen = nBufLen;
-}
-
-void Base64Coder::Encode(const PBYTE pBuffer, DWORD nBufLen)
-{
- SetDecodeBuffer(pBuffer, nBufLen);
- AllocEncode(nBufLen * 2);
-
- TempBucket Raw;
- DWORD nIndex = 0;
-
- while((nIndex + 3) <= nBufLen)
- {
- Raw.Clear();
- ::CopyMemory(&Raw, m_pDBuffer + nIndex, 3);
- Raw.nSize = 3;
- _EncodeToBuffer(Raw, m_pEBuffer + m_nEDataLen);
- nIndex += 3;
- m_nEDataLen += 4;
- }
-
- if(nBufLen > nIndex)
- {
- Raw.Clear();
- Raw.nSize = (BYTE) (nBufLen - nIndex);
- ::CopyMemory(&Raw, m_pDBuffer + nIndex, nBufLen - nIndex);
- _EncodeToBuffer(Raw, m_pEBuffer + m_nEDataLen);
- m_nEDataLen += 4;
- }
-}
-
-/*void Base64Coder::Encode(LPCSTR szMessage)
-{
- if(szMessage != NULL)
- Base64Coder::Encode((const PBYTE)szMessage, strlen(szMessage));
-}*/
-
-void Base64Coder::Decode(const PBYTE pBuffer, DWORD dwBufLen)
-{
- if(!Base64Coder::m_Init)
- _Init();
-
- SetEncodeBuffer(pBuffer, dwBufLen);
-
- AllocDecode(dwBufLen);
-
- TempBucket Raw;
-
- DWORD nIndex = 0;
-
- while((nIndex + 4) <= m_nEDataLen)
- {
- Raw.Clear();
- Raw.nData[0] = Base64Coder::m_DecodeTable[m_pEBuffer[nIndex]];
- Raw.nData[1] = Base64Coder::m_DecodeTable[m_pEBuffer[nIndex + 1]];
- Raw.nData[2] = Base64Coder::m_DecodeTable[m_pEBuffer[nIndex + 2]];
- Raw.nData[3] = Base64Coder::m_DecodeTable[m_pEBuffer[nIndex + 3]];
-
- if(Raw.nData[2] == 255)
- Raw.nData[2] = 0;
- if(Raw.nData[3] == 255)
- Raw.nData[3] = 0;
-
- Raw.nSize = 4;
- _DecodeToBuffer(Raw, m_pDBuffer + m_nDDataLen);
- nIndex += 4;
- m_nDDataLen += 3;
- }
-
- // If nIndex < m_nEDataLen, then we got a decode message without padding.
- // We may want to throw some kind of warning here, but we are still required
- // to handle the decoding as if it was properly padded.
- if(nIndex < m_nEDataLen)
- {
- Raw.Clear();
- for(DWORD i = nIndex; i < m_nEDataLen; i++)
- {
- Raw.nData[i - nIndex] = Base64Coder::m_DecodeTable[m_pEBuffer[i]];
- Raw.nSize++;
- if(Raw.nData[i - nIndex] == 255)
- Raw.nData[i - nIndex] = 0;
- }
-
- _DecodeToBuffer(Raw, m_pDBuffer + m_nDDataLen);
- m_nDDataLen += (m_nEDataLen - nIndex);
- }
-}
-
-/*void Base64Coder::Decode(LPCSTR szMessage)
-{
- if(szMessage != NULL)
- Base64Coder::Decode((const PBYTE)szMessage, strlen(szMessage));
-}*/
-
-DWORD Base64Coder::_DecodeToBuffer(const TempBucket &Decode, PBYTE pBuffer)
-{
- TempBucket Data;
- DWORD nCount = 0;
-
- _DecodeRaw(Data, Decode);
-
- for(int i = 0; i < 3; i++)
- {
- pBuffer[i] = Data.nData[i];
- if(pBuffer[i] != 255)
- nCount++;
- }
-
- return nCount;
-}
-
-
-void Base64Coder::_EncodeToBuffer(const TempBucket &Decode, PBYTE pBuffer)
-{
- TempBucket Data;
-
- _EncodeRaw(Data, Decode);
-
- for(int i = 0; i < 4; i++)
- pBuffer[i] = Base64Digits[Data.nData[i]];
-
- switch(Decode.nSize)
- {
- case 1:
- pBuffer[2] = '=';
- case 2:
- pBuffer[3] = '=';
- }
-}
-
-void Base64Coder::_DecodeRaw(TempBucket &Data, const TempBucket &Decode)
-{
- BYTE nTemp;
-
- Data.nData[0] = Decode.nData[0];
- Data.nData[0] <<= 2;
-
- nTemp = Decode.nData[1];
- nTemp >>= 4;
- nTemp &= 0x03;
- Data.nData[0] |= nTemp;
-
- Data.nData[1] = Decode.nData[1];
- Data.nData[1] <<= 4;
-
- nTemp = Decode.nData[2];
- nTemp >>= 2;
- nTemp &= 0x0F;
- Data.nData[1] |= nTemp;
-
- Data.nData[2] = Decode.nData[2];
- Data.nData[2] <<= 6;
- nTemp = Decode.nData[3];
- nTemp &= 0x3F;
- Data.nData[2] |= nTemp;
-}
-
-void Base64Coder::_EncodeRaw(TempBucket &Data, const TempBucket &Decode)
-{
- BYTE nTemp;
-
- Data.nData[0] = Decode.nData[0];
- Data.nData[0] >>= 2;
-
- Data.nData[1] = Decode.nData[0];
- Data.nData[1] <<= 4;
- nTemp = Decode.nData[1];
- nTemp >>= 4;
- Data.nData[1] |= nTemp;
- Data.nData[1] &= 0x3F;
-
- Data.nData[2] = Decode.nData[1];
- Data.nData[2] <<= 2;
-
- nTemp = Decode.nData[2];
- nTemp >>= 6;
-
- Data.nData[2] |= nTemp;
- Data.nData[2] &= 0x3F;
-
- Data.nData[3] = Decode.nData[2];
- Data.nData[3] &= 0x3F;
-}
-
-BOOL Base64Coder::_IsBadMimeChar(BYTE nData)
-{
- switch(nData)
- {
- case '\r': case '\n': case '\t': case ' ' :
- case '\b': case '\a': case '\f': case '\v':
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-void Base64Coder::_Init()
-{ // Initialize Decoding table.
-
- int i;
-
- for(i = 0; i < 256; i++)
- Base64Coder::m_DecodeTable[i] = -2;
-
- for(i = 0; i < 64; i++)
- {
- Base64Coder::m_DecodeTable[Base64Digits[i]] = i;
- Base64Coder::m_DecodeTable[Base64Digits[i]|0x80] = i;
- }
-
- Base64Coder::m_DecodeTable['='] = -1;
- Base64Coder::m_DecodeTable['='|0x80] = -1;
-
- Base64Coder::m_Init = TRUE;
-}
-
diff --git a/protocols/Twitter/src/Base64Coder.h b/protocols/Twitter/src/Base64Coder.h deleted file mode 100644 index d65868070e..0000000000 --- a/protocols/Twitter/src/Base64Coder.h +++ /dev/null @@ -1,69 +0,0 @@ -// Base64Coder.h: interface for the Base64Coder class.
-// http://support.microsoft.com/kb/191239
-//////////////////////////////////////////////////////////////////////
-
-#if !defined(AFX_BASE64CODER_H__B2E45717_0625_11D2_A80A_00C04FB6794C__INCLUDED_)
-#define AFX_BASE64CODER_H__B2E45717_0625_11D2_A80A_00C04FB6794C__INCLUDED_
-
-#if _MSC_VER >= 1000
-#pragma once
-#endif // _MSC_VER >= 1000
-
-#ifdef _AFXDLL
- #include <afx.h>
- typedef CString String;
-#else
- #include <windows.h>
- #include <string>
- typedef std::string String;
-#endif
-
-class Base64Coder
-{
- // Internal bucket class.
- class TempBucket
- {
- public:
- BYTE nData[4];
- BYTE nSize;
- void Clear() { ::ZeroMemory(nData, 4); nSize = 0; };
- };
-
- PBYTE m_pDBuffer;
- PBYTE m_pEBuffer;
- DWORD m_nDBufLen;
- DWORD m_nEBufLen;
- DWORD m_nDDataLen;
- DWORD m_nEDataLen;
-
-public:
- Base64Coder();
- virtual ~Base64Coder();
-
-public:
- virtual void Encode(const PBYTE, DWORD);
- virtual void Decode(const PBYTE, DWORD);
- //virtual void Encode(LPCSTR sMessage);
- //virtual void Decode(LPCSTR sMessage);
-
- virtual LPCSTR DecodedMessage() const;
- virtual LPCSTR EncodedMessage() const;
-
- virtual void AllocEncode(DWORD);
- virtual void AllocDecode(DWORD);
- virtual void SetEncodeBuffer(const PBYTE pBuffer, DWORD nBufLen);
- virtual void SetDecodeBuffer(const PBYTE pBuffer, DWORD nBufLen);
-
-protected:
- virtual void _EncodeToBuffer(const TempBucket &Decode, PBYTE pBuffer);
- virtual ULONG _DecodeToBuffer(const TempBucket &Decode, PBYTE pBuffer);
- virtual void _EncodeRaw(TempBucket &, const TempBucket &);
- virtual void _DecodeRaw(TempBucket &, const TempBucket &);
- virtual BOOL _IsBadMimeChar(BYTE);
-
- static char m_DecodeTable[256];
- static BOOL m_Init;
- void _Init();
-};
-
-#endif // !defined(AFX_BASE64CODER_H__B2E45717_0625_11D2_A80A_00C04FB6794C__INCLUDED_)
diff --git a/protocols/Twitter/src/oauth.cpp b/protocols/Twitter/src/oauth.cpp index 2235ca88ce..cfc4812191 100644 --- a/protocols/Twitter/src/oauth.cpp +++ b/protocols/Twitter/src/oauth.cpp @@ -643,14 +643,6 @@ ErrorExit: return hash;
}
-wstring mir_twitter::Base64String( const string& hash )
-{
- Base64Coder coder;
- coder.Encode((BYTE*)hash.c_str(), (DWORD)hash.size());
- wstring encoded = UTF8ToWide(coder.EncodedMessage());
- return encoded;
-}
-
wstring mir_twitter::OAuthCreateSignature( const wstring& signatureBase, const wstring& consumerSecret, const wstring& requestTokenSecret )
{
// URL encode key elements
@@ -662,7 +654,8 @@ wstring mir_twitter::OAuthCreateSignature( const wstring& signatureBase, const w string data = WideToUTF8(signatureBase);
string hash = HMACSHA1(keyBytes, data);
- wstring signature = Base64String(hash);
+ ptrA encoded( mir_base64_encode((PBYTE)hash.c_str(), (unsigned)hash.length()));
+ wstring signature = _A2T(encoded);
// URL encode the returned signature
signature = UrlEncode(signature);
diff --git a/protocols/Twitter/src/stdafx.h b/protocols/Twitter/src/stdafx.h index 6e216fce33..0c7fe57ab6 100644 --- a/protocols/Twitter/src/stdafx.h +++ b/protocols/Twitter/src/stdafx.h @@ -8,7 +8,6 @@ #include "targetver.h"
#include <Windows.h>
-//#include <WinInet.h>
#include <Shlwapi.h>
#include <Wincrypt.h>
#include <stdio.h>
@@ -22,11 +21,9 @@ #include <fstream>
typedef std::basic_string<TCHAR> tstring;
-//#define SIZEOF(x) (sizeof(x)/sizeof(*x))
#include "StringConv.h"
#include "StringUtil.h"
-#include "Base64Coder.h"
#include "Debug.h"
diff --git a/protocols/Twitter/src/twitter.cpp b/protocols/Twitter/src/twitter.cpp index 78f1582e29..81e55a2cad 100644 --- a/protocols/Twitter/src/twitter.cpp +++ b/protocols/Twitter/src/twitter.cpp @@ -445,7 +445,7 @@ string twitter::urlencode(const string &c) {
string escaped;
- int max = c.length();
+ size_t max = c.length();
for(int i=0; i<max; i++)
{
if ( (48 <= c[i] && c[i] <= 57) ||//0-9
@@ -516,11 +516,10 @@ static char *month_names[] = { "Jan","Feb","Mar","Apr","May","Jun", int parse_month(const char *m)
{
- for(size_t i=0; i<12; i++)
- {
+ for(int i=0; i<12; i++)
if(strcmp(month_names[i],m) == 0)
return i;
- }
+
return -1;
}
diff --git a/protocols/Twitter/src/utility.h b/protocols/Twitter/src/utility.h index c8f862e247..11d5b4f6ea 100644 --- a/protocols/Twitter/src/utility.h +++ b/protocols/Twitter/src/utility.h @@ -77,7 +77,6 @@ public: std::wstring OAuthCreateNonce();
std::wstring OAuthCreateTimestamp();
std::string HMACSHA1( const std::string& keyBytes, const std::string& data );
- std::wstring Base64String( const std::string& hash );
std::wstring OAuthCreateSignature( const std::wstring& signatureBase, const std::wstring& consumerSecret, const std::wstring& requestTokenSecret );
protected:
diff --git a/protocols/Twitter/twitter_10.vcxproj b/protocols/Twitter/twitter_10.vcxproj index 16f9ee9a8f..7679561d44 100644 --- a/protocols/Twitter/twitter_10.vcxproj +++ b/protocols/Twitter/twitter_10.vcxproj @@ -162,7 +162,6 @@ </ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="src\Base64Coder.cpp" />
<ClCompile Include="src\chat.cpp" />
<ClCompile Include="src\connection.cpp" />
<ClCompile Include="src\contacts.cpp" />
@@ -180,7 +179,6 @@ <ClCompile Include="src\utility.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\Base64Coder.h" />
<ClInclude Include="src\common.h" />
<ClInclude Include="src\http.h" />
<ClInclude Include="src\proto.h" />
diff --git a/protocols/Twitter/twitter_10.vcxproj.filters b/protocols/Twitter/twitter_10.vcxproj.filters index 2a1ef10e63..6f4ddc29a4 100644 --- a/protocols/Twitter/twitter_10.vcxproj.filters +++ b/protocols/Twitter/twitter_10.vcxproj.filters @@ -48,9 +48,6 @@ <ClCompile Include="src\utility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\Base64Coder.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\StringConv.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -104,9 +101,6 @@ <ClInclude Include="src\stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\Base64Coder.h">
- <Filter>Header Files</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\twitter.rc">
diff --git a/protocols/Twitter/twitter_11.vcxproj b/protocols/Twitter/twitter_11.vcxproj index 837da99ae8..6213b76668 100644 --- a/protocols/Twitter/twitter_11.vcxproj +++ b/protocols/Twitter/twitter_11.vcxproj @@ -165,7 +165,6 @@ </ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="src\Base64Coder.cpp" />
<ClCompile Include="src\chat.cpp" />
<ClCompile Include="src\connection.cpp" />
<ClCompile Include="src\contacts.cpp" />
@@ -183,7 +182,6 @@ <ClCompile Include="src\utility.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\Base64Coder.h" />
<ClInclude Include="src\common.h" />
<ClInclude Include="src\http.h" />
<ClInclude Include="src\proto.h" />
diff --git a/protocols/Twitter/twitter_11.vcxproj.filters b/protocols/Twitter/twitter_11.vcxproj.filters index 2a1ef10e63..6f4ddc29a4 100644 --- a/protocols/Twitter/twitter_11.vcxproj.filters +++ b/protocols/Twitter/twitter_11.vcxproj.filters @@ -48,9 +48,6 @@ <ClCompile Include="src\utility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\Base64Coder.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\StringConv.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -104,9 +101,6 @@ <ClInclude Include="src\stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\Base64Coder.h">
- <Filter>Header Files</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\twitter.rc">
|