diff options
author | George Hazan <george.hazan@gmail.com> | 2013-06-04 07:55:00 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-06-04 07:55:00 +0000 |
commit | 8751885ea79df4b666b65bb2b6900617785e0da7 (patch) | |
tree | 676db28129ece760d7ad354b2d39ba371453db8c | |
parent | 09476981eccbcae37ef4526f3fbcb18fca686ffa (diff) |
end of base64* zoo
git-svn-id: http://svn.miranda-ng.org/main/trunk@4879 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
29 files changed, 154 insertions, 813 deletions
diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc index 0b14858923..0be77bbe48 100644 --- a/include/delphi/m_core.inc +++ b/include/delphi/m_core.inc @@ -553,9 +553,9 @@ procedure mir_sha1_hash(dataIn:pmir_sha1_byte_t; len:int;hashout:SHA1Hash); stdc ///////////////////////////////////////////////////////////////////////////////
// strings
-function mir_base64_decode(str:pAnsiChar):pAnsiChar; stdcall;
+function mir_base64_decode(str:pAnsiChar; var resultSize:int):PByte; stdcall;
external CoreDLL name 'mir_base64_decode';
-function mir_base64_encode(str:pAnsiChar):pAnsiChar; stdcall;
+function mir_base64_encode(data:PByte; dataSize:int):pAnsiChar; stdcall;
external CoreDLL name 'mir_base64_encode';
function rtrim(str:pAnsiChar):pAnsiChar; stdcall;
diff --git a/include/delphi/m_netlib.inc b/include/delphi/m_netlib.inc index 69df8f5793..3c86e7517b 100644 --- a/include/delphi/m_netlib.inc +++ b/include/delphi/m_netlib.inc @@ -282,14 +282,6 @@ type combinePackets : int; // MIRANDA_VER >= 0x0900
end;
- PNETLIBBASE64 = ^TNETLIBBASE64;
- TNETLIBBASE64 = record
- pszEncoded: PAnsiChar;
- cchEncoded: int;
- pbDecoded : PByte;
- cbDecoded : int;
- end;
-
type
PNETLIBBUFFER = ^TNETLIBBUFFER;
TNETLIBBUFFER = record
@@ -506,43 +498,6 @@ const }
MS_NETLIB_URLENCODE:PAnsiChar = 'Netlib/UrlEncode';
- {
- wParam : 0
- lParam : Pointer to a TNETLIBBASE64 initialised structure
- Affects: Decodes a Base64 null terminated string, see notes
- Returns: [non zero] on success, NULL(0) on failure
- Notes : TNETLIBBASE64.pszEncoded and cchEncoded must contain a pointer to
- a buffer to use as input, and it's length, the length
- should not include space taken for null termination --
- -
- Output is placed in ..pbDecoded and ..cbDecoded for buffer and
- length of buffer -- the maxiumum output for a given input can
- be worked out with Netlib_GetBase64DecodedBufferSize() function
- see below.
- -
- For more information on Base64 see rfc-1421.
- Errors : ERROR_INVALID_PARAMETER, ERROR_INVALID_DATA, ERROR_BUFFER_OVERFLOW
- }
- MS_NETLIB_BASE64DECODE:PAnsiChar = 'Netlib/Base64Decode';
-
- {
- wParam : 0
- lParam : Pointer to an initialised TNETLIBBASE64 structure
- Affect : Base64 encode a string, see notes
- Returns: [non zero] on success, NULL(0) on failure
- Notes : TNETLIBBASE64.pbDecode and TNETLIBBASE64.cbDecoded contain
- the input buffer and it's length --
- TNETLIBBASE64.pszEncoded and TNETLIBBASE64.cchEncoded contain the
- buffer in which to put the output and it's length.
- -
- The maximum output size for a given input can be worked
- out with the function Netlib_GetBase64EncodedBufferSize() below
- .pszEncoded is null terminated, on return TNETLIBBASE64.cchEncoded
- is set to the actual length excluding 0.
- Errors : ERROR_INVALID_PARAMETER, ERROR_BUFFER_OVERFLOW
- }
- MS_NETLIB_BASE64ENCODE:PAnsiChar = 'Netlib/Base64Encode';
-
{
Converts string representation of IP and port into numerical SOCKADDR_INET
IPv4 could supplied in formats address:port or address
diff --git a/include/m_netlib.h b/include/m_netlib.h index 8403adfc97..c955d14317 100644 --- a/include/m_netlib.h +++ b/include/m_netlib.h @@ -389,40 +389,8 @@ typedef struct { //Errors: ERROR_INVALID_PARAMETER, ERROR_OUTOFMEMORY
#define MS_NETLIB_URLENCODE "Netlib/UrlEncode"
-//Base64 decode a string. See rfc1421.
-//wParam = 0
-//lParam = (LPARAM)(NETLIBBASE64*)&nlb64
-//Returns nonzero on success, 0 on failure ( !! this is different to most of the rest of Miranda, but consistent with netlib)
-//nlb64.pszEncoded and nlb64.cchEncoded contain the input string and its length
-//(excluding terminating zero).
-//nlb64.pbDecoded and nlb64.cbDecoded contain the buffer in which to put the
-//output and the length of this buffer. The maximum output size for a given
-//input is available from the macro Netlib_GetBase64DecodedBufferSize() below.
-//On return nlb64.cbDecoded is set to the actual length of the decoded data.
-//Errors: ERROR_INVALID_PARAMETER, ERROR_INVALID_DATA, ERROR_BUFFER_OVERFLOW
-typedef struct {
- char *pszEncoded;
- int cchEncoded;
- PBYTE pbDecoded;
- int cbDecoded;
-} NETLIBBASE64;
#define Netlib_GetBase64DecodedBufferSize(cchEncoded) (((cchEncoded)>>2)*3)
-#define MS_NETLIB_BASE64DECODE "Netlib/Base64Decode"
-
-//Base64 encode a string. See rfc1421.
-//wParam = 0
-//lParam = (LPARAM)(NETLIBBASE64*)&nlb64
-//Returns nonzero on success, 0 on failure ( !! this is different to most of the rest of Miranda, but consistent with netlib)
-//nlb64.pbDecoded and nlb64.cbDecoded contain the input buffer and its length
-//nlb64.pszEncoded and nlb64.cchEncoded contain the buffer in which to put the
-//output and the length of this buffer. The maximum output size for a given
-//input is available from the macro Netlib_GetBase64EncodedBufferSize() below.
-//nlb64.pszEncoded is terminated with a 0.
-//On return nlb64.cchEncoded is set to the actual length of the decoded data,
-//excluding the terminating 0.
-//Errors: ERROR_INVALID_PARAMETER, ERROR_BUFFER_OVERFLOW
#define Netlib_GetBase64EncodedBufferSize(cbDecoded) (((cbDecoded)*4+11)/12*4+1)
-#define MS_NETLIB_BASE64ENCODE "Netlib/Base64Encode"
// Converts string representation of IP and port into numerical SOCKADDR_INET
// IPv4 could supplied in formats address:port or address
diff --git a/include/m_utils.h b/include/m_utils.h index 3c8a01af89..17640c6d32 100644 --- a/include/m_utils.h +++ b/include/m_utils.h @@ -348,18 +348,6 @@ __forceinline INT_PTR Utils_AssertInsideScreen(RECT *rc) { //Always returns 0
#define MS_UTILS_GETRANDOM "Utils/GetRandom"
-//Generates Base64 encoded string
-//wParam = 0 (unused)
-//lParam = (LPARAM)(char*)pointer to source string
-//Returns (char*)pointer to encoded string
-#define MS_UTILS_ENCODEBASE64 "Utils/EncodeBase64"
-
-//Generates Base64 decoded string
-//wParam = 0 (unused)
-//lParam = (LPARAM)(char*)pointer to encoded string
-//Returns (char*)pointer to decoded string
-#define MS_UTILS_DECODEBASE64 "Utils/DecodeBase64"
-
//Replace variables in text
//wParam = (char*/TCHAR*/WCHAR*)string (depends on RVF_UNICODE/RVF_TCHAR flag)
//lParam = (REPLACEVARSDATA *) data about variables, item with key = 0 terminates the list
diff --git a/plugins/CrashDumper/src/upload.cpp b/plugins/CrashDumper/src/upload.cpp index 0097ff80be..2e614923f9 100644 --- a/plugins/CrashDumper/src/upload.cpp +++ b/plugins/CrashDumper/src/upload.cpp @@ -88,10 +88,7 @@ void CreateAuthString(char* auth) char str[110];
int len = mir_snprintf(str, sizeof(str), "%s:%s", user, pass);
-
- strcpy(auth, "Basic ");
- NETLIBBASE64 nlb = { auth+6, 250, (PBYTE)str, len };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
+ mir_snprintf(auth, 250, "Basic %s", ptrA( mir_base64_encode((PBYTE)str, len)));
}
diff --git a/plugins/FileAsMessage/src/dialog.cpp b/plugins/FileAsMessage/src/dialog.cpp index 8add3a7720..b103854565 100644 --- a/plugins/FileAsMessage/src/dialog.cpp +++ b/plugins/FileAsMessage/src/dialog.cpp @@ -6,111 +6,6 @@ char *szFEMode[] = "Send file"
};
-#define USE_BUILDIN_BASE64
-//
-// BASE64 encoding/decoding
-//
-#define Base64_GetDecodedBufferSize(cchEncoded) (((cchEncoded)>>2)*3)
-#define Base64_GetEncodedBufferSize(cbDecoded) (((cbDecoded)*4+11)/12*4+1)
-#ifdef USE_BUILDIN_BASE64
-#define Base64_Encode(nlb64) CallService(MS_NETLIB_BASE64ENCODE, 0, (LPARAM)nlb64)
-#define Base64_Decode(nlb64) CallService(MS_NETLIB_BASE64DECODE, 0, (LPARAM)nlb64)
-#else
-
-static char base64chars[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-#define Base64_Encode(nlb64) NetlibBase64Encode(0, (LPARAM)nlb64)
-#define Base64_Decode(nlb64) NetlibBase64Decode(0, (LPARAM)nlb64)
-
-int NetlibBase64Encode(WPARAM wParam,LPARAM lParam)
-{
- NETLIBBASE64 *nlb64=(NETLIBBASE64*)lParam;
- int iIn;
- char *pszOut;
- PBYTE pbIn;
-
- if(nlb64==NULL || nlb64->pszEncoded==NULL || nlb64->pbDecoded==NULL) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
- }
- if(nlb64->cchEncoded<Netlib_GetBase64EncodedBufferSize(nlb64->cbDecoded)) {
- SetLastError(ERROR_BUFFER_OVERFLOW);
- return 0;
- }
- nlb64->cchEncoded=Netlib_GetBase64EncodedBufferSize(nlb64->cbDecoded);
- for(iIn=0,pbIn=nlb64->pbDecoded,pszOut=nlb64->pszEncoded;iIn<nlb64->cbDecoded;iIn+=3,pbIn+=3,pszOut+=4) {
- pszOut[0]=base64chars[pbIn[0]>>2];
- if(nlb64->cbDecoded-iIn==1) {
- pszOut[1]=base64chars[(pbIn[0]&3)<<4];
- pszOut[2]='=';
- pszOut[3]='=';
- pszOut+=4;
- break;
- }
- pszOut[1]=base64chars[((pbIn[0]&3)<<4)|(pbIn[1]>>4)];
- if(nlb64->cbDecoded-iIn==2) {
- pszOut[2]=base64chars[(pbIn[1]&0xF)<<2];
- pszOut[3]='=';
- pszOut+=4;
- break;
- }
- pszOut[2]=base64chars[((pbIn[1]&0xF)<<2)|(pbIn[2]>>6)];
- pszOut[3]=base64chars[pbIn[2]&0x3F];
- }
- pszOut[0]='\0';
- return 1;
-}
-
-static BYTE Base64CharToInt(char c)
-{
- if(c>='A' && c<='Z') return c-'A';
- if(c>='a' && c<='z') return c-'a'+26;
- if(c>='0' && c<='9') return c-'0'+52;
- if(c=='+') return 62;
- if(c=='/') return 63;
- if(c=='=') return 64;
- return 255;
-}
-
-int NetlibBase64Decode(WPARAM wParam,LPARAM lParam)
-{
- NETLIBBASE64 *nlb64=(NETLIBBASE64*)lParam;
- char *pszIn;
- PBYTE pbOut;
- BYTE b1,b2,b3,b4;
- int iIn;
-
- if(nlb64==NULL || nlb64->pszEncoded==NULL || nlb64->pbDecoded==NULL) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
- }
- if(nlb64->cchEncoded&3) {
- SetLastError(ERROR_INVALID_DATA);
- return 0;
- }
- if(nlb64->cbDecoded<Netlib_GetBase64DecodedBufferSize(nlb64->cchEncoded)) {
- SetLastError(ERROR_BUFFER_OVERFLOW);
- return 0;
- }
- nlb64->cbDecoded=Netlib_GetBase64DecodedBufferSize(nlb64->cchEncoded);
- for(iIn=0,pszIn=nlb64->pszEncoded,pbOut=nlb64->pbDecoded;iIn<nlb64->cchEncoded;iIn+=4,pszIn+=4,pbOut+=3) {
- b1=Base64CharToInt(pszIn[0]);
- b2=Base64CharToInt(pszIn[1]);
- b3=Base64CharToInt(pszIn[2]);
- b4=Base64CharToInt(pszIn[3]);
- if(b1==255 || b1==64 || b2==255 || b2==64 || b3==255 || b4==255) {
- SetLastError(ERROR_INVALID_DATA);
- return 0;
- }
- pbOut[0]=(b1<<2)|(b2>>4);
- if(b3==64) {nlb64->cbDecoded-=2; break;}
- pbOut[1]=(b2<<4)|(b3>>2);
- if(b4==64) {nlb64->cbDecoded--; break;}
- pbOut[2]=b4|(b3<<6);
- }
- return 1;
-}
-#endif
-
char* ltoax(char* s, DWORD value)
{
if(value == 0)
@@ -472,8 +367,8 @@ int FILEECHO::createTransfer() }
else
{
- int EncodedMaxLen = Base64_GetEncodedBufferSize(Base64_GetDecodedBufferSize(chunkMaxLen));
- int DecodedMaxLen = Base64_GetDecodedBufferSize(EncodedMaxLen);
+ int EncodedMaxLen = Netlib_GetBase64EncodedBufferSize(Netlib_GetBase64DecodedBufferSize(chunkMaxLen));
+ int DecodedMaxLen = Netlib_GetBase64DecodedBufferSize(EncodedMaxLen);
codeSymb = '-';
chunkCount = (fileSize + DecodedMaxLen - 1) / DecodedMaxLen;
@@ -735,14 +630,8 @@ void FILEECHO::onSendTimer() }
else
{
- NETLIBBASE64 nlb;
-
- nlb.pbDecoded = data;
- nlb.cbDecoded = data_end - data;
- nlb.pszEncoded = (char*)buffer;
- nlb.cchEncoded = chunkMaxLen*2;
-
- Base64_Encode(&nlb);
+ ptrA enc( mir_base64_encode(data, data_end - data));
+ strncpy((char*)buffer, enc, chunkMaxLen*2);
}
char prefix[128];
@@ -810,18 +699,10 @@ void FILEECHO::cmdDATA(char *param) }
else
{
- NETLIBBASE64 nlb;
- uchar *temp_buffer;
-
- nlb.pszEncoded = param;
- nlb.cchEncoded = (int)_tcslen(param);
- temp_buffer = (uchar*)malloc(nlb.cchEncoded);
- nlb.pbDecoded = temp_buffer;
- nlb.cbDecoded = nlb.cchEncoded;
-
- Base64_Decode(&nlb);
- memcpy(data, temp_buffer, min(nlb.cbDecoded, data_end - data));
- data += nlb.cbDecoded;
+ unsigned bufLen;
+ mir_ptr<BYTE> buf((BYTE*)mir_base64_decode(param, &bufLen));
+ memcpy(data, buf, min(bufLen, data_end - data));
+ data += bufLen;
}
//
// let's check it up
diff --git a/plugins/LotusNotify/LotusNotify_10.vcxproj b/plugins/LotusNotify/LotusNotify_10.vcxproj index 1d11e42c2d..44ce191ae1 100644 --- a/plugins/LotusNotify/LotusNotify_10.vcxproj +++ b/plugins/LotusNotify/LotusNotify_10.vcxproj @@ -184,34 +184,6 @@ <ClInclude Include="src\debug.h" />
<ClInclude Include="src\lotusnotes.h" />
<ClInclude Include="src\LotusNotify.h" />
- <ClInclude Include="src\notesapi\include\bsafe.h" />
- <ClInclude Include="src\notesapi\include\bsafeerr.h" />
- <ClInclude Include="src\notesapi\include\darray.h" />
- <ClInclude Include="src\notesapi\include\dname.h" />
- <ClInclude Include="src\notesapi\include\extmgr.h" />
- <ClInclude Include="src\notesapi\include\global.h" />
- <ClInclude Include="src\notesapi\include\globerr.h" />
- <ClInclude Include="src\notesapi\include\idtable.h" />
- <ClInclude Include="src\notesapi\include\kfm.h" />
- <ClInclude Include="src\notesapi\include\mailserv.h" />
- <ClInclude Include="src\notesapi\include\misc.h" />
- <ClInclude Include="src\notesapi\include\nadtypes.h" />
- <ClInclude Include="src\notesapi\include\names.h" />
- <ClInclude Include="src\notesapi\include\nif.h" />
- <ClInclude Include="src\notesapi\include\nls.h" />
- <ClInclude Include="src\notesapi\include\ns.h" />
- <ClInclude Include="src\notesapi\include\nsfdata.h" />
- <ClInclude Include="src\notesapi\include\nsfdb.h" />
- <ClInclude Include="src\notesapi\include\nsferr.h" />
- <ClInclude Include="src\notesapi\include\nsfnote.h" />
- <ClInclude Include="src\notesapi\include\nsfsearc.h" />
- <ClInclude Include="src\notesapi\include\osenv.h" />
- <ClInclude Include="src\notesapi\include\osfile.h" />
- <ClInclude Include="src\notesapi\include\osmem.h" />
- <ClInclude Include="src\notesapi\include\osmisc.h" />
- <ClInclude Include="src\notesapi\include\ossignal.h" />
- <ClInclude Include="src\notesapi\include\pool.h" />
- <ClInclude Include="src\notesapi\include\stdnames.h" />
<ClInclude Include="src\resource.h" />
<ClInclude Include="src\stdafx.h" />
<ClInclude Include="src\version.h" />
diff --git a/plugins/LotusNotify/LotusNotify_10.vcxproj.filters b/plugins/LotusNotify/LotusNotify_10.vcxproj.filters index 5bc066e5c4..a132330333 100644 --- a/plugins/LotusNotify/LotusNotify_10.vcxproj.filters +++ b/plugins/LotusNotify/LotusNotify_10.vcxproj.filters @@ -13,9 +13,6 @@ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx</Extensions>
</Filter>
- <Filter Include="notesapi">
- <UniqueIdentifier>{df00f0a3-e7f1-4ece-8f78-92cd020c62d1}</UniqueIdentifier>
- </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\debug.cpp">
@@ -44,90 +41,6 @@ <ClInclude Include="src\resource.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\notesapi\include\stdnames.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\bsafe.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\bsafeerr.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\darray.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\dname.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\extmgr.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\global.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\globerr.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\idtable.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\kfm.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\mailserv.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\misc.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nadtypes.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\names.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nif.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nls.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\ns.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nsfdata.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nsfdb.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nsferr.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nsfnote.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\nsfsearc.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\osenv.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\osfile.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\osmem.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\osmisc.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\ossignal.h">
- <Filter>notesapi</Filter>
- </ClInclude>
- <ClInclude Include="src\notesapi\include\pool.h">
- <Filter>notesapi</Filter>
- </ClInclude>
<ClInclude Include="src\version.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp index 18bec6d18f..a1508e304c 100644 --- a/plugins/NewsAggregator/Src/Utils.cpp +++ b/plugins/NewsAggregator/Src/Utils.cpp @@ -115,9 +115,7 @@ void CreateAuthString(char *auth, HANDLE hContact, HWND hwndDlg) mir_free(tlogin);
mir_free(tpass);
- strcpy(auth, "Basic ");
- NETLIBBASE64 nlb = { auth+6, 250, (PBYTE)str, len };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
+ mir_snprintf(auth, 250, "Basic %s", ptrA(mir_base64_encode((PBYTE)str, len)));
}
VOID GetNewsData(TCHAR *tszUrl, char **szData, HANDLE hContact, HWND hwndDlg)
diff --git a/plugins/SmileyAdd/src/customsmiley.cpp b/plugins/SmileyAdd/src/customsmiley.cpp index 4c0a75a11a..a41920d140 100644 --- a/plugins/SmileyAdd/src/customsmiley.cpp +++ b/plugins/SmileyAdd/src/customsmiley.cpp @@ -77,14 +77,14 @@ bool SmileyCType::CreateTriggerText(char* text) int len = (int)strlen(text);
if (len == 0) return false;
- int reslen = Netlib_GetBase64DecodedBufferSize(len)+1;
- char* res = (char*)alloca(reslen);
-
- NETLIBBASE64 nlb = { text, len, ( PBYTE )res, reslen };
- if (!CallService(MS_NETLIB_BASE64DECODE, 0, LPARAM( &nlb ))) return false;
- res[nlb.cbDecoded] = 0;
+ unsigned reslen;
+ char* res = (char*)mir_base64_decode(text, &reslen);
+ if (res == NULL)
+ return false;
+ char save = res[reslen]; res[reslen] = 0; // safe because of mir_alloc
TCHAR *txt = mir_utf8decodeT(res);
+ res[reslen] = save;
if (txt == NULL) return false;
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index b63cbf4223..e81bc18c28 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -511,26 +511,24 @@ static void DecodeHTML(bkstring& str) }
-static IStream* DecodeBase64Data(const char* data)
+static IStream* DecodeBase64Data(const char* pData)
{
- NETLIBBASE64 nlb64;
- nlb64.pszEncoded = (char*)data;
- nlb64.cchEncoded = (int)strlen(data);
- nlb64.cbDecoded = Netlib_GetBase64DecodedBufferSize(nlb64.cchEncoded);
-
- IStream* pStream = NULL;
+ unsigned dataLen;
+ ptrA data((char*)mir_base64_decode(pData, &dataLen));
+ if (data == NULL)
+ return NULL;
// Read image list
- HGLOBAL hBuffer = GlobalAlloc(GMEM_MOVEABLE, nlb64.cbDecoded);
- if (hBuffer)
- {
- nlb64.pbDecoded = (PBYTE)GlobalLock(hBuffer);
- CallService(MS_NETLIB_BASE64DECODE, 0, (LPARAM)&nlb64);
- GlobalUnlock(hBuffer);
+ HGLOBAL hBuffer = GlobalAlloc(GMEM_MOVEABLE, dataLen);
+ if (!hBuffer)
+ return NULL;
- CreateStreamOnHGlobal(hBuffer, TRUE, &pStream);
- }
+ void *dst = GlobalLock(hBuffer);
+ memcpy(dst, data, dataLen);
+ GlobalUnlock(hBuffer);
+ IStream *pStream = NULL;
+ CreateStreamOnHGlobal(hBuffer, TRUE, &pStream);
return pStream;
}
diff --git a/plugins/Watrack/proto/proto.pas b/plugins/Watrack/proto/proto.pas index 416a610a31..5befc5e2d8 100644 --- a/plugins/Watrack/proto/proto.pas +++ b/plugins/Watrack/proto/proto.pas @@ -213,7 +213,9 @@ var ccs:PCCSDATA;
s:pWideChar;
buf:PWideChar;
- base64:TNETLIBBASE64;
+ data:PByte;
+ dataSize:int;
+ encodedStr:PAnsiChar;
// pos_artist,pos_title,pos_album:PwideChar;
pos_template:pWideChar;
curpos:pWideChar;
@@ -290,22 +292,22 @@ begin begin
if curpos<>nil then
begin
- base64.pbDecoded:=PByte(buf);
- base64.cbDecoded:=PAnsiChar(curpos)-PAnsiChar(buf);
+ data:=PByte(buf);
+ dataSize:=PAnsiChar(curpos)-PAnsiChar(buf);
end
else
begin
- base64.pbDecoded:=PByte(s);
- base64.cbDecoded:=(StrLenW(textpos)+3+1)*SizeOf(PWideChar);
+ data:=PByte(s);
+ dataSize:=(StrLenW(textpos)+3+1)*SizeOf(PWideChar);
end;
- base64.cchEncoded:=Netlib_GetBase64EncodedBufferSize(base64.cbDecoded);
- mGetMem(encbuf,base64.cchEncoded+1+Length(wpAnswer));
- base64.pszEncoded:=PAnsiChar(encbuf)+Length(wpAnswer);
+ encodedStr:=mir_base64_encode(data,dataSize);
+ mGetMem(encbuf,Length(encodedStr)+1+Length(wpAnswer));
StrCopy(PAnsiChar(encbuf),wpAnswer);
- CallService(MS_NETLIB_BASE64ENCODE,0,tlparam(@base64));
+ StrCopy(PAnsiChar(encbuf)+Length(wpAnswer),encodedStr);
+ mFreeMem(encodedStr);
+
if (HistMask and hmOutInfo)<>0 then
- AddEvent(ccs^.hContact,EVENTTYPE_WAT_ANSWER,DBEF_SENT,
- base64.pbDecoded,base64.cbDecoded);
+ AddEvent(ccs^.hContact,EVENTTYPE_WAT_ANSWER,DBEF_SENT,data,dataSize);
CallContactService(ccs^.hContact,PSS_MESSAGE,0,tlparam(encbuf));
end
else
@@ -348,14 +350,9 @@ begin else if StrCmp(PPROTORECVEVENT(ccs^.lParam)^.szMessage.a,wpAnswer,Length(wpAnswer))=0 then
begin
// decode
- base64.pszEncoded:=PPROTORECVEVENT(ccs^.lParam)^.szMessage.a+Length(wpAnswer);
- base64.cchEncoded:=StrLen(base64.pszEncoded);
- base64.cbDecoded :=Netlib_GetBase64DecodedBufferSize(base64.cchEncoded);
- mGetMem(base64.pbDecoded,base64.cbDecoded);
-
- CallService(MS_NETLIB_BASE64DECODE,0,tlparam(@base64));
+ data:=mir_base64_decode(PPROTORECVEVENT(ccs^.lParam)^.szMessage.a+Length(wpAnswer),dataSize);
- curpos:=pWideChar(base64.pbDecoded); // pos_artist:=curpos;
+ curpos:=pWideChar(data); // pos_artist:=curpos;
while curpos^<>#0 do inc(curpos); inc(curpos); // pos_title :=curpos;
while curpos^<>#0 do inc(curpos); inc(curpos); // pos_album :=curpos;
while curpos^<>#0 do inc(curpos); inc(curpos);
@@ -363,7 +360,7 @@ begin if (HistMask and hmInInfo)<>0 then
AddEvent(ccs^.hContact,EVENTTYPE_WAT_ANSWER,DBEF_READ,
- base64.pbDecoded,base64.cbDecoded,
+ data,dataSize,
PPROTORECVEVENT(ccs^.lParam)^.Timestamp);
// Action
@@ -372,7 +369,7 @@ begin MessageBoxW(0,TranslateW(pos_template),buf,MB_ICONINFORMATION);
- mFreeMem(base64.pbDecoded);
+ mFreeMem(data);
end
else if StrCmp(PPROTORECVEVENT(ccs^.lParam)^.szMessage.a,wpError,Length(wpError))=0 then
begin
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 2893d62016..dfa04d338d 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -214,15 +214,7 @@ void FacebookProto::ParseSmileys(std::string message, HANDLE hContact) std::string url = "http://graph.facebook.com/%s/picture";
utils::text::replace_first(&url, "%s", smiley.substr(2, smiley.length()-4));
-
- size_t slen = smiley.length();
- size_t rlen = Netlib_GetBase64EncodedBufferSize(slen);
- char* buf = (char*)mir_alloc(rlen);
-
- NETLIBBASE64 nlb = { buf, (int)rlen, (PBYTE)smiley.c_str(), (int)slen };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
-
- std::string b64 = buf;
+ std::string b64 = ptrA( mir_base64_encode((PBYTE)smiley.c_str(), (unsigned)smiley.length()));
b64 = utils::url::encode(b64);
std::tstring filename = GetAvatarFolder() + L"\\smileys\\" + (TCHAR*)_A2T(b64.c_str()) + _T(".jpg");
@@ -232,16 +224,15 @@ void FacebookProto::ParseSmileys(std::string message, HANDLE hContact) } else {
facy.save_url(url, filename, nlc);
}
- TCHAR *path = _tcsdup(filename.c_str());
+ TCHAR *path = _tcsdup(filename.c_str());
- SMADD_CONT cont;
- cont.cbSize = sizeof(SMADD_CONT);
- cont.hContact = hContact;
- cont.type = 1;
- cont.path = path;
+ SMADD_CONT cont;
+ cont.cbSize = sizeof(SMADD_CONT);
+ cont.hContact = hContact;
+ cont.type = 1;
+ cont.path = path;
- CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont);
- mir_free(path);
- //}
+ CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont);
+ mir_free(path);
}
}
diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp index 6773b61cf6..4b54e75e7f 100644 --- a/protocols/Gadu-Gadu/src/oauth.cpp +++ b/protocols/Gadu-Gadu/src/oauth.cpp @@ -232,29 +232,19 @@ int oauth_sign_request(LIST<OAUTHPARAMETER> ¶ms, const char *httpmethod, con if (!strcmp(signmethod, "HMAC-SHA1")) {
char *text = oauth_generate_signature(params, httpmethod, url);
- char *key;
char *csenc = oauth_uri_escape(consumer_secret);
char *tsenc = oauth_uri_escape(token_secret);
- mir_sha1_byte_t digest[MIR_SHA1_HASH_SIZE];
- NETLIBBASE64 nlb64 = {0};
- int signlen;
-
- key = (char *)mir_alloc(strlen(csenc) + strlen(tsenc) + 2);
+ char *key = (char *)mir_alloc(strlen(csenc) + strlen(tsenc) + 2);
strcpy(key, csenc);
strcat(key, "&");
strcat(key, tsenc);
mir_free(csenc);
mir_free(tsenc);
+ mir_sha1_byte_t digest[MIR_SHA1_HASH_SIZE];
hmacsha1_hash((BYTE*)text, (int)strlen(text), (BYTE*)key, (int)strlen(key), digest);
- signlen = Netlib_GetBase64EncodedBufferSize(MIR_SHA1_HASH_SIZE);
- sign = (char *)mir_alloc(signlen);
- nlb64.pszEncoded = sign;
- nlb64.cchEncoded = signlen;
- nlb64.pbDecoded = digest;
- nlb64.cbDecoded = MIR_SHA1_HASH_SIZE;
- CallService(MS_NETLIB_BASE64ENCODE, 0, (LPARAM)&nlb64);
+ sign = mir_base64_encode(digest, MIR_SHA1_HASH_SIZE);
mir_free(text);
mir_free(key);
diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index 9c258922be..5abe9160f2 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -433,13 +433,8 @@ static unsigned char* PKCS5_Padding(char* in, size_t &len) char* CMsnProto::GenerateLoginBlob(char* challenge)
{
- const size_t keylen = strlen(authSecretToken);
- size_t key1len = Netlib_GetBase64DecodedBufferSize(keylen);
- unsigned char* key1 = (unsigned char*)alloca(key1len);
-
- NETLIBBASE64 nlb = { authSecretToken, (int)keylen, key1, (int)key1len };
- CallService(MS_NETLIB_BASE64DECODE, 0, LPARAM(&nlb));
- key1len = nlb.cbDecoded;
+ unsigned key1len;
+ BYTE *key1 = (BYTE*)mir_base64_decode(authSecretToken, &key1len);
mir_sha1_byte_t key2[MIR_SHA1_HASH_SIZE+4];
mir_sha1_byte_t key3[MIR_SHA1_HASH_SIZE+4];
@@ -481,13 +476,7 @@ char* CMsnProto::GenerateLoginBlob(char* challenge) mir_free(newchl);
- const size_t rlen = Netlib_GetBase64EncodedBufferSize(pktsz);
- char* buf = (char*)mir_alloc(rlen);
-
- NETLIBBASE64 nlb1 = { buf, (int)rlen, userKey, (int)pktsz };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb1));
-
- return buf;
+ return mir_base64_encode(userKey, (unsigned)pktsz);
}
@@ -497,12 +486,8 @@ char* CMsnProto::HotmailLogin(const char* url) CallService(MS_UTILS_GETRANDOM, sizeof(nonce), (LPARAM)nonce);
const size_t hotSecretlen = strlen(hotSecretToken);
- size_t key1len = Netlib_GetBase64DecodedBufferSize(hotSecretlen);
- unsigned char* key1 = (unsigned char*)alloca(key1len);
-
- NETLIBBASE64 nlb = { hotSecretToken, (int)hotSecretlen, key1, (int)key1len };
- CallService(MS_NETLIB_BASE64DECODE, 0, LPARAM(&nlb));
- key1len = nlb.cbDecoded;
+ unsigned key1len;
+ BYTE *key1 = (BYTE*)mir_base64_decode(hotSecretToken, &key1len);
static const unsigned char encdata[] = "WS-SecureConversation";
const size_t data1len = sizeof(nonce) + sizeof(encdata) - 1;
@@ -518,11 +503,8 @@ char* CMsnProto::HotmailLogin(const char* url) char* xmlenc = (char*)alloca(xmlenclen);
UrlEncode(hotAuthToken, xmlenc, xmlenclen);
- size_t noncenclen = Netlib_GetBase64EncodedBufferSize(sizeof(nonce));
- char* noncenc = (char*)alloca(noncenclen);
- NETLIBBASE64 nlb1 = { noncenc, (int)noncenclen, nonce, sizeof(nonce) };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb1));
- noncenclen = nlb1.cchEncoded - 1;
+ ptrA noncenc( mir_base64_encode(nonce, sizeof(nonce)));
+ size_t noncenclen = lstrlenA(noncenc);
const size_t fnpstlen = strlen(xmlenc) + strlen(url) + 3*noncenclen + 100;
char* fnpst = (char*)mir_alloc(fnpstlen);
@@ -535,13 +517,10 @@ char* CMsnProto::HotmailLogin(const char* url) mir_sha1_byte_t hash[MIR_SHA1_HASH_SIZE];
hmac_sha1(hash, key2, sizeof(key2), (mir_sha1_byte_t*)fnpst, sz);
- NETLIBBASE64 nlb2 = { noncenc, (int)noncenclen, hash, sizeof(hash) };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb2));
+ noncenc = mir_base64_encode(hash, sizeof(hash));
sz += mir_snprintf(fnpst + sz, fnpstlen - sz, "&hash=");
-
UrlEncode(noncenc, fnpst + sz, fnpstlen - sz);
-
return fnpst;
}
diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp index b4b7ed8478..057f2f3111 100644 --- a/protocols/MSN/src/msn_commands.cpp +++ b/protocols/MSN/src/msn_commands.cpp @@ -302,15 +302,11 @@ void CMsnProto::sttCustomSmiley(const char* msgBody, char* email, char* nick, in ft->p2p_object[sz] = 0;
size_t slen = strlen(lastsml);
- size_t rlen = Netlib_GetBase64EncodedBufferSize(slen);
- char* buf = (char*)mir_alloc(rlen);
-
- NETLIBBASE64 nlb = { buf, (int)rlen, (PBYTE)lastsml, (int)slen };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
+ ptrA buf( mir_base64_encode((PBYTE)lastsml, (unsigned)slen));
+ int rlen = lstrlenA(buf);
char* smileyName = (char*)mir_alloc(rlen*3);
UrlEncode(buf, smileyName, rlen*3);
- mir_free(buf);
TCHAR path[MAX_PATH];
MSN_GetCustomSmileyFileName(hContact, path, SIZEOF(path), smileyName, iSmileyType);
diff --git a/protocols/MSN/src/msn_global.h b/protocols/MSN/src/msn_global.h index 2fe7bce1ed..aa7ed0f001 100644 --- a/protocols/MSN/src/msn_global.h +++ b/protocols/MSN/src/msn_global.h @@ -164,7 +164,6 @@ void stripBBCode(char* src); void stripColorCode(char* src);
void parseWLID(char* wlid, char** net, char** email, char** inst);
-char* MSN_Base64Decode(const char* str);
char* GetGlobalIp(void);
template <class chartype> void UrlDecode(chartype* str);
diff --git a/protocols/MSN/src/msn_mime.cpp b/protocols/MSN/src/msn_mime.cpp index 6ce94286da..e511d2017b 100644 --- a/protocols/MSN/src/msn_mime.cpp +++ b/protocols/MSN/src/msn_mime.cpp @@ -455,7 +455,7 @@ wchar_t* MimeHeaders::decode(const char* val) case 'b':
case 'B':
{
- char* dec = MSN_Base64Decode(fld);
+ char* dec = (char*)mir_base64_decode(fld, 0);
strcpy(fld, dec);
mir_free(dec);
break;
@@ -501,7 +501,7 @@ char* MimeHeaders::decodeMailBody(char* msgBody) else *(dst++) = *(src++);
}
*dst = 0;
- res = MSN_Base64Decode(msgBody);
+ res = (char*)mir_base64_decode(msgBody, 0);
}
else
{
diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp index bf31569fd8..dad0f8d79a 100644 --- a/protocols/MSN/src/msn_misc.cpp +++ b/protocols/MSN/src/msn_misc.cpp @@ -165,13 +165,10 @@ char* MSN_GetAvatarHash(char* szContext, char** pszUrl) ezxml_t xmli = ezxml_parse_str(NEWSTR_ALLOCA(szContext), strlen(szContext));
const char *szAvatarHash = ezxml_attr(xmli, "SHA1D");
if (szAvatarHash != NULL) {
- BYTE szActHash[MIR_SHA1_HASH_SIZE+2] = {0};
- const size_t len = strlen(szAvatarHash);
-
- NETLIBBASE64 nlb = { (char*)szAvatarHash, (int)len, szActHash, sizeof(szActHash) };
- int decod = CallService(MS_NETLIB_BASE64DECODE, 0, LPARAM(&nlb));
- if (decod != 0 && nlb.cbDecoded > 0)
- res = arrayToHex(szActHash, nlb.cbDecoded);
+ unsigned hashLen;
+ mir_ptr<BYTE> hash((BYTE*)mir_base64_decode(szAvatarHash, &hashLen));
+ if (hash)
+ res = arrayToHex(hash, hashLen);
if (pszUrl) {
const char *pszUrlAttr;
@@ -313,7 +310,6 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen {
mir_sha1_ctx sha1ctx;
BYTE sha1c[MIR_SHA1_HASH_SIZE], sha1d[MIR_SHA1_HASH_SIZE];
- char szSha1c[41], szSha1d[41];
char *szFname = mir_utf8encodeT(sztFname);
@@ -321,10 +317,7 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen mir_sha1_append(&sha1ctx, (mir_sha1_byte_t*)pData, (int)cbLen);
mir_sha1_finish(&sha1ctx, sha1d);
- {
- NETLIBBASE64 nlb = { szSha1d, sizeof(szSha1d), (PBYTE)sha1d, sizeof(sha1d) };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
- }
+ ptrA szSha1d( mir_base64_encode((PBYTE)sha1d, sizeof(sha1d)));
mir_sha1_init(&sha1ctx);
ezxml_t xmlp = ezxml_new("msnobj");
@@ -352,15 +345,12 @@ int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen ezxml_set_attr(xmlp, "Friendly", "AAA=");
mir_sha1_append(&sha1ctx, (PBYTE)"SHA1D", 5);
- mir_sha1_append(&sha1ctx, (PBYTE)szSha1d, (int)strlen(szSha1d));
+ mir_sha1_append(&sha1ctx, (PBYTE)(char*)szSha1d, (int)strlen(szSha1d));
ezxml_set_attr(xmlp, "SHA1D", szSha1d);
mir_sha1_finish(&sha1ctx, sha1c);
- {
- NETLIBBASE64 nlb = { szSha1c, sizeof(szSha1c), (PBYTE)sha1c, sizeof(sha1c) };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
- }
+ ptrA szSha1c( mir_base64_encode((PBYTE)sha1c, sizeof(sha1c)));
// ezxml_set_attr(xmlp, "SHA1C", szSha1c);
@@ -1293,32 +1283,6 @@ char* TWinErrorCode::getText() return mErrorText;
}
-char* MSN_Base64Decode(const char* str)
-{
- if (str == NULL) return NULL;
-
- size_t len = strlen(str);
- size_t reslen = Netlib_GetBase64DecodedBufferSize(len) + 4;
- char* res = (char*)mir_alloc(reslen);
-
- char* p = const_cast< char* >(str);
- if (len & 3) { // fix for stupid Kopete's base64 encoder
- char* p1 = (char*)alloca(len+5);
- memcpy(p1, p, len);
- p = p1;
- p1 += len;
- for (int i = 4 - (len & 3); i > 0; i--, p1++, len++)
- *p1 = '=';
- *p1 = 0;
- }
-
- NETLIBBASE64 nlb = { p, (int)len, (PBYTE)res, (int)reslen };
- if (!CallService(MS_NETLIB_BASE64DECODE, 0, LPARAM(&nlb))) nlb.cbDecoded = 0;
- res[nlb.cbDecoded] = 0;
-
- return res;
-}
-
bool CMsnProto::MSN_IsMyContact(HANDLE hContact)
{
const char* szProto = GetContactProto(hContact);
diff --git a/protocols/MSN/src/msn_p2p.cpp b/protocols/MSN/src/msn_p2p.cpp index 46a24488a7..09c32ac1d9 100644 --- a/protocols/MSN/src/msn_p2p.cpp +++ b/protocols/MSN/src/msn_p2p.cpp @@ -1215,7 +1215,7 @@ void CMsnProto::p2p_InitFileTransfer( if (p2p_getSessionByID(dwSessionId))
return;
- szContext = MSN_Base64Decode(szContext);
+ szContext = (char*)mir_base64_decode(szContext, 0);
filetransfer* ft = new filetransfer(this);
ft->p2p_acksessid = MSN_GenRandom();
@@ -2311,10 +2311,8 @@ void CMsnProto::p2p_invite(unsigned iAppID, filetransfer* ft, const char *wlid) if (!ft->bAccepted)
ft->p2p_sessionid = MSN_GenRandom();
- int cbContextEnc = Netlib_GetBase64EncodedBufferSize((int)cbContext);
- char* szContextEnc = (char*)alloca(cbContextEnc);
- NETLIBBASE64 nlb = { szContextEnc, cbContextEnc, (PBYTE)pContext, (int)cbContext };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
+ ptrA szContextEnc( mir_base64_encode((PBYTE)pContext, (unsigned)cbContext));
+ int cbContextEnc = lstrlenA(szContextEnc);
MimeHeaders chdrs(10);
chdrs.addString("EUF-GUID", szAppID);
diff --git a/protocols/MSN/src/msn_soapab.cpp b/protocols/MSN/src/msn_soapab.cpp index d0e1e6b32c..2010a9b6dd 100644 --- a/protocols/MSN/src/msn_soapab.cpp +++ b/protocols/MSN/src/msn_soapab.cpp @@ -972,15 +972,8 @@ bool CMsnProto::MSN_ABFind(const char* szMethod, const char* szGuid, bool deltas if (!msnLoggedIn && msnNsThread)
{
char *szCircleTicket = ezxml_txt(ezxml_get(body, "CircleResult", 0, "CircleTicket", -1));
- int cbCircleTicket = (int)strlen(szCircleTicket);
-
- int cbCircleTicketEnc = Netlib_GetBase64EncodedBufferSize(cbCircleTicket);
- char* szCircleTicketEnc = (char*)alloca(cbCircleTicketEnc);
-
- NETLIBBASE64 nlb = { szCircleTicketEnc, cbCircleTicketEnc, (PBYTE)szCircleTicket, cbCircleTicket };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
-
- if (szCircleTicketEnc[0])
+ ptrA szCircleTicketEnc( mir_base64_encode((PBYTE)szCircleTicket, (unsigned)strlen(szCircleTicket)));
+ if (szCircleTicketEnc)
msnNsThread->sendPacket("USR", "SHA A %s", szCircleTicketEnc);
}
diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index cbff0068a8..55d46c4c80 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -341,33 +341,23 @@ void CMsnProto::MSN_SetNicknameUtf(const char* nickname) void CMsnProto::msn_storeAvatarThread(void* arg)
{
StoreAvatarData* dat = (StoreAvatarData*)arg;
- char *szEncBuf = NULL;
+ ptrA szEncBuf;
if (dat)
- {
- size_t szEncPngSize = Netlib_GetBase64EncodedBufferSize(dat->dataSize);
- szEncBuf = (char*)mir_alloc(szEncPngSize);
- NETLIBBASE64 nlb = { szEncBuf, (int)szEncPngSize, dat->data, (int)dat->dataSize };
- CallService(MS_NETLIB_BASE64ENCODE, 0, LPARAM(&nlb));
- }
+ szEncBuf = mir_base64_encode(dat->data, (unsigned)dat->dataSize);
if (photoid[0] && dat)
- {
MSN_StoreUpdateDocument(dat->szName, dat->szMimeType, szEncBuf);
- }
- else
- {
+ else {
MSN_StoreUpdateProfile(NULL, NULL, 1);
- if (photoid[0])
- {
+ if (photoid[0]) {
MSN_StoreDeleteRelationships(true);
MSN_StoreDeleteRelationships(false);
photoid[0] = 0;
}
- if (dat)
- {
+ if (dat) {
MSN_StoreCreateDocument(dat->szName, dat->szMimeType, szEncBuf);
MSN_StoreCreateRelationships();
}
@@ -379,7 +369,6 @@ void CMsnProto::msn_storeAvatarThread(void* arg) if (dat)
{
- mir_free(szEncBuf);
mir_free(dat->szName);
mir_free(dat->data);
mir_free(dat);
diff --git a/protocols/Skype/src/skype_account.cpp b/protocols/Skype/src/skype_account.cpp index 2f1379048f..1121628193 100644 --- a/protocols/Skype/src/skype_account.cpp +++ b/protocols/Skype/src/skype_account.cpp @@ -180,12 +180,10 @@ void CSkypeProto::InitProxy() this->SetStr(SETUPKEY_HTTPS_PROXY_ADDR, address);
if (nlus.useProxyAuth)
{
- char *encodedPass = (char *)::CallService(MS_UTILS_ENCODEBASE64, 0, (LPARAM)nlus.szProxyAuthPassword);
+ ptrA encodedPass( mir_base64_encode((BYTE*)nlus.szProxyAuthPassword, lstrlenA(nlus.szProxyAuthPassword)));
- this->SetStr(SETUPKEY_HTTPS_PROXY_USER, nlus.szProxyAuthUser);
- this->SetStr(SETUPKEY_HTTPS_PROXY_PWD, encodedPass);
-
- ::mir_free(encodedPass);
+ this->SetStr(SETUPKEY_HTTPS_PROXY_USER, nlus.szProxyAuthUser);
+ this->SetStr(SETUPKEY_HTTPS_PROXY_PWD, (char*)encodedPass);
}
break;
@@ -197,12 +195,8 @@ void CSkypeProto::InitProxy() this->SetStr(SETUPKEY_SOCKS_PROXY_ADDR, address);
if (nlus.useProxyAuth)
{
- char *encodedPass = (char *)::CallService(MS_UTILS_ENCODEBASE64, 0, (LPARAM)nlus.szProxyAuthPassword);
-
- this->SetStr(SETUPKEY_SOCKS_PROXY_USER, nlus.szProxyAuthUser);
+ this->SetStr(SETUPKEY_SOCKS_PROXY_USER, nlus.szProxyAuthUser);
this->SetStr(SETUPKEY_SOCKS_PROXY_PWD, nlus.szProxyAuthPassword);
-
- ::mir_free(encodedPass);
}
break;
diff --git a/protocols/Skype/src/skype_runtime.cpp b/protocols/Skype/src/skype_runtime.cpp index 9824ef10bb..9d319ac7cd 100644 --- a/protocols/Skype/src/skype_runtime.cpp +++ b/protocols/Skype/src/skype_runtime.cpp @@ -7,45 +7,40 @@ char *CSkypeProto::LoadKeyPair()
{
HRSRC hResource = FindResource(g_hInstance, MAKEINTRESOURCE(IDR_KEY), L"BIN");
- if (hResource)
- {
- HGLOBAL hLoadedResource = LoadResource(g_hInstance, hResource);
- if (hLoadedResource)
- {
- LPVOID pLockedResource = LockResource(hLoadedResource);
+ if (hResource == NULL)
+ return NULL;
- if (pLockedResource)
- {
- aes_context ctx;
- char *key = (char *)::CallService(MS_UTILS_DECODEBASE64, 0, (LPARAM)MY_KEY);
+ HGLOBAL hLoadedResource = LoadResource(g_hInstance, hResource);
+ if (hLoadedResource == NULL)
+ return NULL;
- ::aes_set_key(&ctx, (unsigned char *)key, 128);
- ::mir_free(key);
+ LPVOID pLockedResource = LockResource(hLoadedResource);
+ if (pLockedResource == NULL)
+ return NULL;
- int length = ::SizeofResource(g_hInstance, hResource);
- if (length != 0)
- {
- char *pData = (char *)pLockedResource;
- if (!pData)
- return NULL;
+ aes_context ctx;
+ char *key = (char*)mir_base64_decode(MY_KEY, NULL);
- pData[length] = 0;
+ ::aes_set_key(&ctx, (unsigned char *)key, 128);
+ ::mir_free(key);
- unsigned char *bufD = (unsigned char *)::mir_alloc(length * 2);
- unsigned char *tmpD = (unsigned char *)::CallService(MS_UTILS_DECODEBASE64, 0, (LPARAM)pData);
+ int length = ::SizeofResource(g_hInstance, hResource);
+ if (length == 0)
+ return NULL;
- for (int i = 0; i < length; i += 16)
- aes_decrypt(&ctx, tmpD + i, bufD + i);
+ char *pData = (char *)alloca(length+1);
+ memcpy(pData, pLockedResource, length);
+ pData[length] = 0;
- ::mir_free(tmpD);
- //bufD[length] = 0; //cert should be null terminated
- return (char *)bufD;
- }
- }
- }
- }
+ unsigned char *bufD = (unsigned char *)::mir_alloc(length * 2);
+ unsigned char *tmpD = (unsigned char *)mir_base64_decode(pData, NULL);
+
+ for (int i = 0; i < length; i += 16)
+ aes_decrypt(&ctx, tmpD + i, bufD + i);
- return NULL;
+ ::mir_free(tmpD);
+ //bufD[length] = 0; //cert should be null terminated
+ return (char *)bufD;
}
int CSkypeProto::StartSkypeRuntime(const wchar_t *profileName)
diff --git a/protocols/Twitter/src/utility.cpp b/protocols/Twitter/src/utility.cpp index f40eecc2e5..e6126062b2 100644 --- a/protocols/Twitter/src/utility.cpp +++ b/protocols/Twitter/src/utility.cpp @@ -22,16 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. std::string b64encode(const std::string &s)
{
- NETLIBBASE64 encode;
- encode.cbDecoded = (int)s.length();
- encode.pbDecoded = (BYTE*)s.c_str();
- encode.cchEncoded = Netlib_GetBase64EncodedBufferSize(encode.cbDecoded);
- encode.pszEncoded = new char[encode.cchEncoded+1];
- CallService(MS_NETLIB_BASE64ENCODE,0,(LPARAM)&encode);
- std::string ret = encode.pszEncoded;
- delete[] encode.pszEncoded;
-
- return ret;
+ return std::string( ptrA( mir_base64_encode((BYTE*)s.c_str(), (unsigned)s.length())));
}
http::response mir_twitter::slurp(const std::string &url,http::method meth,
diff --git a/src/mir_core/utils.cpp b/src/mir_core/utils.cpp index 02593de4fa..be9022188f 100644 --- a/src/mir_core/utils.cpp +++ b/src/mir_core/utils.cpp @@ -220,8 +220,7 @@ MIR_CORE_DLL(char*) mir_base64_encode(const BYTE *input, unsigned inputLen) if (input == NULL)
return NULL;
- size_t i = 0;
- char chr[3], enc[4];
+ BYTE chr[3];
static char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
size_t length = inputLen;
@@ -230,22 +229,20 @@ MIR_CORE_DLL(char*) mir_base64_encode(const BYTE *input, unsigned inputLen) char *output = (char *)mir_alloc(nLength);
char *p = output;
- while (i < length)
+ for (size_t i=0; i < length; )
{
chr[0] = input[i++];
chr[1] = input[i++];
chr[2] = input[i++];
- enc[0] = chr[0] >> 2;
- enc[1] = ((chr[0] & 0x03) << 4) | (chr[1] >> 4);
- enc[2] = ((chr[1] & 0x0F) << 2) | (chr[2] >> 6);
- enc[3] = chr[2] & 0x3F;
-
- *p++ = cb64[enc[0]]; *p++ = cb64[enc[1]];
+ *p++ = cb64[ chr[0] >> 2 ];
+ *p++ = cb64[ ((chr[0] & 0x03) << 4) | (chr[1] >> 4) ];
+ BYTE b2 = ((chr[1] & 0x0F) << 2) | (chr[2] >> 6),
+ b3 = chr[2] & 0x3F;
if (i - 2 >= length) { *p++ = '='; *p++ = '='; }
- else if (i - 1 >= length) { *p++ = cb64[enc[2]]; *p++ = '='; }
- else { *p++ = cb64[enc[2]]; *p++ = cb64[enc[3]]; }
+ else if (i - 1 >= length) { *p++ = cb64[b2]; *p++ = '='; }
+ else { *p++ = cb64[b2]; *p++ = cb64[b3]; }
}
*p = 0;
@@ -281,12 +278,12 @@ MIR_CORE_DLL(void*) mir_base64_decode(const char *input, unsigned *outputLen) return NULL;
size_t i = 0;
- char chr[3], enc[4];
+ BYTE chr[3], enc[4];
size_t length = strlen(input);
- size_t nLength = (length / 4) * 3 + 1;
+ size_t nLength = (length / 4) * 3;
- char *output = (char *)mir_alloc(nLength);
+ char *output = (char *)mir_alloc(nLength+1);
char *p = output;
while (i < length)
diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp index f3ba8e0e12..b7a3bc3c2d 100644 --- a/src/modules/netlib/netlib.cpp +++ b/src/modules/netlib/netlib.cpp @@ -424,96 +424,6 @@ INT_PTR NetlibHttpUrlEncode(WPARAM, LPARAM lParam) return (INT_PTR)p;
}
-static const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-INT_PTR NetlibBase64Encode(WPARAM, LPARAM lParam)
-{
- NETLIBBASE64 *nlb64 = (NETLIBBASE64*)lParam;
- int iIn;
- char *pszOut;
- PBYTE pbIn;
-
- if (nlb64 == NULL || nlb64->pszEncoded == NULL || nlb64->pbDecoded == NULL) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
- }
- if (nlb64->cchEncoded<Netlib_GetBase64EncodedBufferSize(nlb64->cbDecoded)) {
- SetLastError(ERROR_BUFFER_OVERFLOW);
- return 0;
- }
- nlb64->cchEncoded = Netlib_GetBase64EncodedBufferSize(nlb64->cbDecoded);
- for (iIn = 0, pbIn = nlb64->pbDecoded, pszOut = nlb64->pszEncoded;iIn<nlb64->cbDecoded;iIn+=3, pbIn+=3, pszOut+=4) {
- pszOut[0] = base64chars[pbIn[0]>>2];
- if (nlb64->cbDecoded-iIn == 1) {
- pszOut[1] = base64chars[(pbIn[0]&3)<<4];
- pszOut[2] = '=';
- pszOut[3] = '=';
- pszOut+=4;
- break;
- }
- pszOut[1] = base64chars[((pbIn[0]&3)<<4)|(pbIn[1]>>4)];
- if (nlb64->cbDecoded-iIn == 2) {
- pszOut[2] = base64chars[(pbIn[1]&0xF)<<2];
- pszOut[3] = '=';
- pszOut+=4;
- break;
- }
- pszOut[2] = base64chars[((pbIn[1]&0xF)<<2)|(pbIn[2]>>6)];
- pszOut[3] = base64chars[pbIn[2]&0x3F];
- }
- pszOut[0] = '\0';
- return 1;
-}
-
-static BYTE Base64CharToInt(char c)
-{
- if (c>='A' && c <= 'Z') return c-'A';
- if (c>='a' && c <= 'z') return c-'a'+26;
- if (c>='0' && c <= '9') return c-'0'+52;
- if (c == '+') return 62;
- if (c == '/') return 63;
- if (c == '=') return 64;
- return 255;
-}
-
-INT_PTR NetlibBase64Decode(WPARAM, LPARAM lParam)
-{
- NETLIBBASE64 *nlb64 = (NETLIBBASE64*)lParam;
- char *pszIn;
- PBYTE pbOut;
- BYTE b1, b2, b3, b4;
- int iIn;
-
- if (nlb64 == NULL || nlb64->pszEncoded == NULL || nlb64->pbDecoded == NULL) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
- }
- if (nlb64->cchEncoded&3) {
- SetLastError(ERROR_INVALID_DATA);
- return 0;
- }
- if (nlb64->cbDecoded<Netlib_GetBase64DecodedBufferSize(nlb64->cchEncoded)) {
- SetLastError(ERROR_BUFFER_OVERFLOW);
- return 0;
- }
- nlb64->cbDecoded = Netlib_GetBase64DecodedBufferSize(nlb64->cchEncoded);
- for (iIn = 0, pszIn = nlb64->pszEncoded, pbOut = nlb64->pbDecoded;iIn<nlb64->cchEncoded;iIn+=4, pszIn+=4, pbOut+=3) {
- b1 = Base64CharToInt(pszIn[0]);
- b2 = Base64CharToInt(pszIn[1]);
- b3 = Base64CharToInt(pszIn[2]);
- b4 = Base64CharToInt(pszIn[3]);
- if (b1 == 255 || b1 == 64 || b2 == 255 || b2 == 64 || b3 == 255 || b4 == 255) {
- SetLastError(ERROR_INVALID_DATA);
- return 0;
- }
- pbOut[0] = (b1<<2)|(b2>>4);
- if (b3 == 64) {nlb64->cbDecoded-=2; break;}
- pbOut[1] = (b2<<4)|(b3>>2);
- if (b4 == 64) {nlb64->cbDecoded--; break;}
- pbOut[2] = b4|(b3<<6);
- }
- return 1;
-}
-
void UnloadNetlibModule(void)
{
if ( !bModuleInitialized) return;
@@ -619,8 +529,6 @@ int LoadNetlibModule(void) CreateServiceFunction(MS_NETLIB_SETSTICKYHEADERS, NetlibHttpSetSticky);
CreateServiceFunction(MS_NETLIB_GETSOCKET, NetlibGetSocket);
CreateServiceFunction(MS_NETLIB_URLENCODE, NetlibHttpUrlEncode);
- CreateServiceFunction(MS_NETLIB_BASE64ENCODE, NetlibBase64Encode);
- CreateServiceFunction(MS_NETLIB_BASE64DECODE, NetlibBase64Decode);
CreateServiceFunction(MS_NETLIB_SENDHTTPREQUEST, NetlibHttpSendRequest);
CreateServiceFunction(MS_NETLIB_RECVHTTPHEADERS, NetlibHttpRecvHeaders);
CreateServiceFunction(MS_NETLIB_FREEHTTPREQUESTSTRUCT, NetlibHttpFreeRequestStruct);
diff --git a/src/modules/netlib/netlibsecurity.cpp b/src/modules/netlib/netlibsecurity.cpp index 33656dc868..2f538a06fd 100644 --- a/src/modules/netlib/netlibsecurity.cpp +++ b/src/modules/netlib/netlibsecurity.cpp @@ -252,14 +252,7 @@ char* CompleteGssapi(HANDLE hSecurity, unsigned char *szChallenge, unsigned chls p += outBuffersDesc.pBuffers[i].cbBuffer;
}
- NETLIBBASE64 nlb64;
- nlb64.cbDecoded = ressz;
- nlb64.pbDecoded = response;
- nlb64.cchEncoded = Netlib_GetBase64EncodedBufferSize(nlb64.cbDecoded);
- nlb64.pszEncoded = (char*)alloca(nlb64.cchEncoded);
- if ( !NetlibBase64Encode(0, (LPARAM)&nlb64)) return NULL;
-
- return mir_strdup(nlb64.pszEncoded);
+ return mir_base64_encode(response, ressz);
}
char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, const TCHAR* login, const TCHAR* psw, bool http, unsigned& complete)
@@ -269,7 +262,7 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, SecBuffer outputSecurityToken, inputSecurityToken;
TimeStamp tokenExpiration;
ULONG contextAttributes;
- NETLIBBASE64 nlb64 = { 0 };
+ char *szOutputToken;
NtlmHandleType* hNtlm = (NtlmHandleType*)hSecurity;
@@ -282,30 +275,29 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, bool hasChallenge = szChallenge != NULL && szChallenge[0] != '\0';
if (hasChallenge)
{
- nlb64.cchEncoded = lstrlenA(szChallenge);
- nlb64.pszEncoded = (char*)szChallenge;
- nlb64.cbDecoded = Netlib_GetBase64DecodedBufferSize(nlb64.cchEncoded);
- nlb64.pbDecoded = (PBYTE)alloca(nlb64.cbDecoded);
- if ( !NetlibBase64Decode(0, (LPARAM)&nlb64)) return NULL;
+ unsigned tokenLen;
+ BYTE *token = (BYTE*)mir_base64_decode(szChallenge, &tokenLen);
+ if (token == NULL)
+ return NULL;
if (isGSSAPI && complete)
- return CompleteGssapi(hSecurity, nlb64.pbDecoded, nlb64.cbDecoded);
+ return CompleteGssapi(hSecurity, token, tokenLen);
inputBufferDescriptor.cBuffers = 1;
inputBufferDescriptor.pBuffers = &inputSecurityToken;
inputBufferDescriptor.ulVersion = SECBUFFER_VERSION;
inputSecurityToken.BufferType = SECBUFFER_TOKEN;
- inputSecurityToken.cbBuffer = nlb64.cbDecoded;
- inputSecurityToken.pvBuffer = nlb64.pbDecoded;
+ inputSecurityToken.cbBuffer = tokenLen;
+ inputSecurityToken.pvBuffer = token;
// try to decode the domain name from the NTLM challenge
if (login != NULL && login[0] != '\0' && !hNtlm->hasDomain)
{
- NtlmType2packet* pkt = (NtlmType2packet*)nlb64.pbDecoded;
+ NtlmType2packet* pkt = (NtlmType2packet*)token;
if ( !strncmp(pkt->sign, "NTLMSSP", 8) && pkt->type == 2)
{
- wchar_t* domainName = (wchar_t*)&nlb64.pbDecoded[pkt->targetName.offset];
+ wchar_t* domainName = (wchar_t*)&token[pkt->targetName.offset];
int domainLen = pkt->targetName.len;
// Negotiate ANSI? if yes, convert the ANSI name to unicode
@@ -412,8 +404,7 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, return NULL;
}
- nlb64.cbDecoded = outputSecurityToken.cbBuffer;
- nlb64.pbDecoded = (PBYTE)outputSecurityToken.pvBuffer;
+ szOutputToken = mir_base64_encode((PBYTE)outputSecurityToken.pvBuffer, outputSecurityToken.cbBuffer);
}
else
{
@@ -425,30 +416,25 @@ char* NtlmCreateResponseFromChallenge(HANDLE hSecurity, const char *szChallenge, size_t authLen = strlen(szLogin) + strlen(szPassw) + 5;
char *szAuth = (char*)alloca(authLen);
- nlb64.cbDecoded = mir_snprintf(szAuth, authLen, "%s:%s", szLogin, szPassw);
- nlb64.pbDecoded = (PBYTE)szAuth;
+ mir_snprintf(szAuth, authLen, "%s:%s", szLogin, szPassw);
+ szOutputToken = mir_strdup(szAuth);
complete = true;
mir_free(szPassw);
mir_free(szLogin);
}
- nlb64.cchEncoded = Netlib_GetBase64EncodedBufferSize(nlb64.cbDecoded);
- nlb64.pszEncoded = (char*)alloca(nlb64.cchEncoded);
- if ( !NetlibBase64Encode(0, (LPARAM)&nlb64)) return NULL;
+ if (szOutputToken == NULL)
+ return NULL;
- char* result;
- if (http)
- {
- char* szProvider = mir_t2a(hNtlm->szProvider);
- nlb64.cchEncoded += (int)strlen(szProvider) + 10;
- result = (char*)mir_alloc(nlb64.cchEncoded);
- mir_snprintf(result, nlb64.cchEncoded, "%s %s", szProvider, nlb64.pszEncoded);
- mir_free(szProvider);
- }
- else
- result = mir_strdup(nlb64.pszEncoded);
+ if (!http)
+ return mir_strdup(szOutputToken);
+ ptrA szProvider( mir_t2a(hNtlm->szProvider));
+ size_t resLen = strlen(szOutputToken) + strlen(szProvider) + 10;
+ char *result = (char*)mir_alloc(resLen);
+ mir_snprintf(result, resLen, "%s %s", szProvider, szOutputToken);
+ mir_free(szOutputToken);
return result;
}
diff --git a/src/modules/utils/utils.cpp b/src/modules/utils/utils.cpp index c6bd60a59b..5d0813c483 100644 --- a/src/modules/utils/utils.cpp +++ b/src/modules/utils/utils.cpp @@ -472,99 +472,6 @@ static INT_PTR GenerateRandom(WPARAM wParam, LPARAM lParam) /////////////////////////////////////////////////////////////////////////////////////////
-static INT_PTR EncodeBase64(WPARAM wParam, LPARAM lParam)
-{
- size_t i = 0;
- char chr[3], enc[4];
- static char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
- const char *input = (const char *)lParam;
- size_t length = strlen(input);
- size_t nLength = 4 * ((length + 2) / 3) + 1;
-
- char *output = (char *)mir_alloc(nLength);
- char *p = output;
-
- while (i < length)
- {
- chr[0] = input[i++];
- chr[1] = input[i++];
- chr[2] = input[i++];
-
- enc[0] = chr[0] >> 2;
- enc[1] = ((chr[0] & 0x03) << 4) | (chr[1] >> 4);
- enc[2] = ((chr[1] & 0x0F) << 2) | (chr[2] >> 6);
- enc[3] = chr[2] & 0x3F;
-
- *p++ = cb64[enc[0]]; *p++ = cb64[enc[1]];
-
- if (i - 2 >= length) { *p++ = '='; *p++ = '='; }
- else if (i - 1 >= length) { *p++ = cb64[enc[2]]; *p++ = '='; }
- else { *p++ = cb64[enc[2]]; *p++ = cb64[enc[3]]; }
- }
-
- *p = 0;
-
- return (INT_PTR)output;
-}
-
-static int Base64DecodeTable[] =
-{
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
- 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
- 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
- -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
- 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
- -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1
-};
-
-static INT_PTR DecodeBase64(WPARAM wParam, LPARAM lParam)
-{
- size_t i = 0;
- char chr[3], enc[4];
-
- const char *input = (const char *)lParam;
- size_t length = strlen(input);
- size_t nLength = (length / 4) * 3 + 1;
-
- char *output = (char *)mir_alloc(nLength);
- char *p = output;
-
- while (i < length)
- {
- enc[0] = Base64DecodeTable[input[i++]];
- enc[1] = Base64DecodeTable[input[i++]];
- enc[2] = Base64DecodeTable[input[i++]];
- enc[3] = Base64DecodeTable[input[i++]];
-
- if (enc[0] == -1 || enc[1] == -1) break;
-
- chr[0] = (enc[0] << 2) | (enc[1] >> 4);
- chr[1] = ((enc[1] & 15) << 4) | (enc[2] >> 2);
- chr[2] = ((enc[2] & 3) << 6) | enc[3];
-
- *p++ = chr[0];
-
- if (enc[2] != -1) *p++ = chr[1];
- if (enc[3] != -1) *p++ = chr[2];
- }
-
- *p = 0;
-
- return (INT_PTR)output;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
int LoadUtilsModule(void)
{
bModuleInitialized = TRUE;
@@ -579,9 +486,6 @@ int LoadUtilsModule(void) CreateServiceFunction(MS_UTILS_GETRANDOM, GenerateRandom);
CreateServiceFunction(MS_SYSTEM_RESTART, RestartMiranda);
- CreateServiceFunction(MS_UTILS_ENCODEBASE64, EncodeBase64);
- CreateServiceFunction(MS_UTILS_DECODEBASE64, DecodeBase64);
-
InitOpenUrl();
InitWindowList();
InitHyperlink();
|