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/CrashDumper/src/upload.cpp | 5 +- plugins/FileAsMessage/src/dialog.cpp | 135 ++------------------- plugins/LotusNotify/LotusNotify_10.vcxproj | 28 ----- plugins/LotusNotify/LotusNotify_10.vcxproj.filters | 87 ------------- plugins/NewsAggregator/Src/Utils.cpp | 4 +- plugins/SmileyAdd/src/customsmiley.cpp | 12 +- plugins/SmileyAdd/src/smileys.cpp | 28 ++--- plugins/Watrack/proto/proto.pas | 37 +++--- 8 files changed, 46 insertions(+), 290 deletions(-) (limited to 'plugins') 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->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 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx - - {df00f0a3-e7f1-4ece-8f78-92cd020c62d1} - @@ -44,90 +41,6 @@ Header Files - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - - - notesapi - Header Files 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 -- cgit v1.2.3