From 8751885ea79df4b666b65bb2b6900617785e0da7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 4 Jun 2013 07:55:00 +0000 Subject: end of base64* zoo git-svn-id: http://svn.miranda-ng.org/main/trunk@4879 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/FileAsMessage/src/dialog.cpp | 135 +++-------------------------------- 1 file changed, 8 insertions(+), 127 deletions(-) (limited to 'plugins/FileAsMessage') 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->cchEncodedcbDecoded)) { - SetLastError(ERROR_BUFFER_OVERFLOW); - return 0; - } - nlb64->cchEncoded=Netlib_GetBase64EncodedBufferSize(nlb64->cbDecoded); - for(iIn=0,pbIn=nlb64->pbDecoded,pszOut=nlb64->pszEncoded;iIncbDecoded;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->cbDecodedcchEncoded)) { - SetLastError(ERROR_BUFFER_OVERFLOW); - return 0; - } - nlb64->cbDecoded=Netlib_GetBase64DecodedBufferSize(nlb64->cchEncoded); - for(iIn=0,pszIn=nlb64->pszEncoded,pbOut=nlb64->pbDecoded;iIncchEncoded;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 buf((BYTE*)mir_base64_decode(param, &bufLen)); + memcpy(data, buf, min(bufLen, data_end - data)); + data += bufLen; } // // let's check it up -- cgit v1.2.3