From c68165979e5741aa201a9ac951e37fee4ca362cc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 15 Aug 2013 08:01:11 +0000 Subject: we use bin2hex now instead of mir_snprintf("%02x") git-svn-id: http://svn.miranda-ng.org/main/trunk@5699 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- bin10/lib/mir_core.lib | Bin 50334 -> 50334 bytes bin10/lib/mir_core64.lib | Bin 45804 -> 45804 bytes bin11/lib/mir_core.lib | Bin 50334 -> 50334 bytes bin11/lib/mir_core64.lib | Bin 45804 -> 45804 bytes plugins/CmdLine/src/utils.cpp | 64 +++++++++++++++------------------ plugins/Exchange/src/utils.cpp | 53 +++++++-------------------- plugins/PluginUpdater/src/checksum.cpp | 5 +-- plugins/YAMN/src/proto/pop3/pop3.cpp | 12 +++---- protocols/Gadu-Gadu/src/avatar.cpp | 8 ++--- protocols/Gadu-Gadu/src/oauth.cpp | 6 +--- protocols/JabberG/src/jabber.h | 1 - protocols/JabberG/src/jabber_file.cpp | 2 +- protocols/JabberG/src/jabber_iqid.cpp | 3 +- protocols/JabberG/src/jabber_svc.cpp | 3 +- protocols/JabberG/src/jabber_util.cpp | 26 ++------------ protocols/JabberG/src/jabber_vcard.cpp | 5 ++- 16 files changed, 56 insertions(+), 132 deletions(-) diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib index e801d4686d..a24dcf97d5 100644 Binary files a/bin10/lib/mir_core.lib and b/bin10/lib/mir_core.lib differ diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib index 9523446aba..34369a56c8 100644 Binary files a/bin10/lib/mir_core64.lib and b/bin10/lib/mir_core64.lib differ diff --git a/bin11/lib/mir_core.lib b/bin11/lib/mir_core.lib index fc21ec1695..ceda7d9ebf 100644 Binary files a/bin11/lib/mir_core.lib and b/bin11/lib/mir_core.lib differ diff --git a/bin11/lib/mir_core64.lib b/bin11/lib/mir_core64.lib index 883fa9b5a5..917eae0aec 100644 Binary files a/bin11/lib/mir_core64.lib and b/bin11/lib/mir_core64.lib differ diff --git a/plugins/CmdLine/src/utils.cpp b/plugins/CmdLine/src/utils.cpp index 37514b60d9..6f0dba3271 100644 --- a/plugins/CmdLine/src/utils.cpp +++ b/plugins/CmdLine/src/utils.cpp @@ -47,7 +47,7 @@ int Log(char *format, ...) strftime(str, sizeof(str), "%d %b %Y @ %H:%M:%S: ", now); fputs(str, fout); va_start(vararg, format); - + tBytes = mir_vsnprintf(str, sizeof(str), format, vararg); if (tBytes > 0) { @@ -77,7 +77,7 @@ int Info(char *title, char *format, ...) str[tBytes] = 0; } va_end(vararg); - return MessageBoxA(0, str, title, MB_OK | MB_ICONINFORMATION); + return MessageBoxA(0, str, title, MB_OK | MB_ICONINFORMATION); } int MyPUShowMessage(char *lpzText, BYTE kind) @@ -88,7 +88,7 @@ int MyPUShowMessage(char *lpzText, BYTE kind) } else{ char *title = (kind == SM_NOTIFY) ? Translate("Notify") : Translate("Warning"); - + return MessageBox(NULL, lpzText, title, MB_OK | (kind == SM_NOTIFY) ? MB_ICONINFORMATION : MB_ICONEXCLAMATION); } } @@ -101,16 +101,8 @@ char *BinToHex(int size, PBYTE data) char buffer[32] = {0}; //should be more than enough int maxSize = size * 2 + HEX_SIZE + 1; szresult = (char *) new char[ maxSize ]; - memset(szresult, 0, maxSize); - mir_snprintf(buffer, SIZEOF(buffer), "%0*X", HEX_SIZE, size); - strcpy(szresult, buffer); - int i; - for (i = 0; i < size; i++) - { - mir_snprintf(buffer, SIZEOF(buffer), "%02X", data[i]); - strcpy(szresult + (HEX_SIZE + i * 2), buffer); - } - return szresult; + mir_snprintf(szresult, maxSize, "%0*X", HEX_SIZE, size); + return bin2hex(data, size, szresult + HEX_SIZE); } void HexToBin(char *inData, ULONG &size, LPBYTE &outData) @@ -210,14 +202,14 @@ int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, return GetStringFromDatabase(NULL, ModuleName, szSettingName, szError, szResult, count); } -#pragma warning (disable: 4312) +#pragma warning (disable: 4312) TCHAR *GetContactName(HANDLE hContact, char *szProto) { CONTACTINFO ctInfo; INT_PTR ret; char proto[200]; - - ZeroMemory((void *) &ctInfo, sizeof(ctInfo)); + + ZeroMemory((void *) &ctInfo, sizeof(ctInfo)); ctInfo.cbSize = sizeof(ctInfo); if (szProto) { @@ -230,7 +222,7 @@ TCHAR *GetContactName(HANDLE hContact, char *szProto) ctInfo.dwFlag = CNF_DISPLAY; #ifdef _UNICODE ctInfo.dwFlag += CNF_UNICODE; -#endif +#endif ctInfo.hContact = hContact; //_debug_message("retrieving contact name for %d", hContact); ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo); @@ -252,7 +244,7 @@ TCHAR *GetContactName(HANDLE hContact, char *szProto) } #pragma warning (default: 4312) -#pragma warning (disable: 4312) +#pragma warning (disable: 4312) void GetContactProto(HANDLE hContact, char *szProto, size_t size) { GetStringFromDatabase(hContact, "Protocol", "p", NULL, szProto, size); @@ -273,7 +265,7 @@ TCHAR *GetContactID(HANDLE hContact, char *szProto) CONTACTINFO ctInfo; INT_PTR ret; - ZeroMemory((void *) &ctInfo, sizeof(ctInfo)); + ZeroMemory((void *) &ctInfo, sizeof(ctInfo)); ctInfo.cbSize = sizeof(ctInfo); ctInfo.szProto = szProto; ctInfo.dwFlag = CNF_UNIQUEID; @@ -292,35 +284,35 @@ TCHAR *GetContactID(HANDLE hContact, char *szProto) { mir_sntprintf(tmp, SIZEOF(tmp), _T("%d"), ctInfo.bVal); buffer = _tcsdup(tmp); - + break; } - + case CNFT_WORD: { mir_sntprintf(tmp, SIZEOF(tmp), _T("%d"), ctInfo.wVal); buffer = _tcsdup(tmp); - + break; } - + case CNFT_DWORD: { mir_sntprintf(tmp, SIZEOF(tmp), _T("%ld"), ctInfo.dVal); buffer = _tcsdup(tmp); - + break; } - + case CNFT_ASCIIZ: default: { buffer = _tcsdup(ctInfo.pszVal); - + break; } } - + } mir_free(ctInfo.pszVal); @@ -345,18 +337,18 @@ HANDLE GetContactFromID(TCHAR *szID, char *szProto) for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { GetContactProto(hContact, cProtocol, sizeof(cProtocol)); TCHAR *szHandle = GetContactID(hContact, cProtocol); - + tmp = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, 0); STRNCPY(dispName, tmp, sizeof(dispName)); - + if ((szHandle) && ((_tcsicmp(szHandle, szID) == 0) || (_tcsicmp(dispName, szID) == 0)) && ((szProto == NULL) || (_stricmp(szProto, cProtocol) == 0))) found = 1; if (szHandle) free(szHandle); - + if (found) return hContact; } - + return NULL; } #pragma warning (default: 4312) @@ -388,7 +380,7 @@ void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors) { RECT rParent; RECT rChild; - + if (parentPos->flags & SWP_NOSIZE) { return; @@ -421,10 +413,10 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, rTmp.right = (parentPos->x + parentPos->cx) - rParent->right; rTmp.bottom = (parentPos->y + parentPos->cy) - rParent->bottom; rTmp.top = parentPos->y - rParent->top; - + cx = (rTmp.left) ? -rTmp.left : rTmp.right; - cy = (rTmp.top) ? -rTmp.top : rTmp.bottom; - + cy = (rTmp.top) ? -rTmp.top : rTmp.bottom; + rChild.right += cx; rChild.bottom += cy; //expanded the window accordingly, now we need to enforce the anchors @@ -451,6 +443,6 @@ inline char *STRNCPY(char *output, const char *input, size_t size) { char *res = strncpy(output, input, size); output[size - 1] = 0; - + return res; } \ No newline at end of file diff --git a/plugins/Exchange/src/utils.cpp b/plugins/Exchange/src/utils.cpp index 0e5adb4831..b3b5da1217 100644 --- a/plugins/Exchange/src/utils.cpp +++ b/plugins/Exchange/src/utils.cpp @@ -45,7 +45,7 @@ int Log(char *format, ...) } va_start(vararg, format); - + tBytes = mir_vsnprintf(str, sizeof(str), format, vararg); if (tBytes > 0) { @@ -75,7 +75,7 @@ int Info(char *title, char *format, ...) str[tBytes] = 0; } va_end(vararg); - return MessageBoxA(0, str, title, MB_OK | MB_ICONINFORMATION); + return MessageBoxA(0, str, title, MB_OK | MB_ICONINFORMATION); } #define HEX_SIZE 8 @@ -86,36 +86,9 @@ char *BinToHex(int size, PBYTE data) char buffer[32] = {0}; //should be more than enough int maxSize = size * 2 + HEX_SIZE + 1; szresult = (char *) new char[ maxSize ]; - memset(szresult, 0, maxSize); - mir_snprintf(buffer, SIZEOF(buffer), "%0*X", HEX_SIZE, size); - strcpy(szresult, buffer); - int i; - for (i = 0; i < size; i++) - { - mir_snprintf(buffer, SIZEOF(buffer), "%02X", data[i]); - strcpy(szresult + (HEX_SIZE + i * 2), buffer); - } - return szresult; -} -/* -TCHAR *BinToHex(int size, PBYTE data) -{ - TCHAR *szresult = NULL; - TCHAR buffer[32] = {0}; //should be more than enough - int maxSize = size * 2 + HEX_SIZE + 1; - szresult = (TCHAR *) new TCHAR[ maxSize ]; - memset(szresult, 0, maxSize); - mir_sntprintf(buffer,_countof(buffer), _T("%0*X"), HEX_SIZE, size); - _tcsncpy(szresult, buffer,_countof(buffer)); - int i; - for (i = 0; i < size; i++) - { - mir_sntprintf(buffer, _countof(buffer),_T("%02X"), data[i]); - _tcsncpy(szresult + (HEX_SIZE + i * 2), buffer,_countof(buffer)); - } - return szresult; + mir_snprintf(szresult, maxSize, "%0*X", HEX_SIZE, size); + return bin2hex(data, size, szresult + HEX_SIZE); } -*/ void HexToBin(TCHAR *inData, ULONG &size, LPBYTE &outData) { @@ -179,7 +152,7 @@ void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors) { RECT rParent; RECT rChild; - + if (parentPos->flags & SWP_NOSIZE) { return; @@ -212,10 +185,10 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, rTmp.right = (parentPos->x + parentPos->cx) - rParent->right; rTmp.bottom = (parentPos->y + parentPos->cy) - rParent->bottom; rTmp.top = parentPos->y - rParent->top; - + cx = (rTmp.left) ? -rTmp.left : rTmp.right; - cy = (rTmp.top) ? -rTmp.top : rTmp.bottom; - + cy = (rTmp.top) ? -rTmp.top : rTmp.bottom; + rChild.right += cx; rChild.bottom += cy; //expanded the window accordingly, now we need to enforce the anchors @@ -241,17 +214,17 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, DWORD WINAPI CheckEmailWorkerThread(LPVOID data) { EnterCriticalSection(&csCheck); - + int bForceAttempt = (int) data; - + if (!exchangeServer.IsConnected()) { exchangeServer.Connect(bForceAttempt); } exchangeServer.Check(bForceAttempt); - + LeaveCriticalSection(&csCheck); - + return 0; } @@ -260,7 +233,7 @@ int ThreadCheckEmail(int bForceAttempt) DWORD idThread; HANDLE hCheckThread = CreateThread(NULL, NULL, CheckEmailWorkerThread, (void *) bForceAttempt, 0, &idThread); CloseHandle(hCheckThread); - + return 0; } diff --git a/plugins/PluginUpdater/src/checksum.cpp b/plugins/PluginUpdater/src/checksum.cpp index 9d0a38bcaa..cda58f10eb 100644 --- a/plugins/PluginUpdater/src/checksum.cpp +++ b/plugins/PluginUpdater/src/checksum.cpp @@ -269,9 +269,6 @@ LBL_NotPE: BYTE digest[16]; mir_md5_finish(&pms, digest); - - for (int i=0; i < sizeof(digest); i++) - sprintf(szDest + i*2, "%02x", digest[i]); //!!!!!!!!!!! - + bin2hex(digest, sizeof(digest), szDest); return RESULT_OK; } diff --git a/plugins/YAMN/src/proto/pop3/pop3.cpp b/plugins/YAMN/src/proto/pop3/pop3.cpp index 8ca1f2bfb2..a66c85e7af 100644 --- a/plugins/YAMN/src/proto/pop3/pop3.cpp +++ b/plugins/YAMN/src/proto/pop3/pop3.cpp @@ -238,7 +238,6 @@ char* CPop3Client::APOP(char* name, char* pw, char* timestamp) char query[512]; char *Result; unsigned char digest[16]; - char hexdigest[40]; if (timestamp==NULL) throw POP3Error=(DWORD)EPOP3_APOP; @@ -247,13 +246,10 @@ char* CPop3Client::APOP(char* name, char* pw, char* timestamp) mir_md5_append(&ctx,(const unsigned char *)timestamp,(unsigned int)strlen(timestamp)); mir_md5_append(&ctx,(const unsigned char *)pw,(unsigned int)strlen(pw)); mir_md5_finish(&ctx, digest); - hexdigest[0]='\0'; - for (int i=0; i < 16; i++) { - char tmp[4]; - mir_snprintf(tmp, SIZEOF(tmp), "%02x", digest[i]); - strcat(hexdigest, tmp); - } - mir_snprintf(query, SIZEOF(query), "APOP %s %s\r\n", name, hexdigest); + + char hexdigest[40]; + mir_snprintf(query, SIZEOF(query), "APOP %s %s\r\n", name, bin2hex(digest, sizeof(digest), hexdigest)); + NetClient->Send(query); Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); if (AckFlag==POP3_FERR) diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp index 42685a821f..400182613c 100644 --- a/protocols/Gadu-Gadu/src/avatar.cpp +++ b/protocols/Gadu-Gadu/src/avatar.cpp @@ -109,18 +109,14 @@ bool GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts) char *gg_avatarhash(char *param) { - mir_sha1_byte_t digest[MIR_SHA1_HASH_SIZE]; char *result; - int i; if (param == NULL || (result = (char *)mir_alloc(MIR_SHA1_HASH_SIZE * 2 + 1)) == NULL) return NULL; + mir_sha1_byte_t digest[MIR_SHA1_HASH_SIZE]; mir_sha1_hash((BYTE*)param, (int)strlen(param), digest); - for (i = 0; i < MIR_SHA1_HASH_SIZE; i++) - mir_snprintf(result + (i<<1), 2, "%02x", digest[i]); - - return result; + return bin2hex(digest, sizeof(digest), result); } void GGPROTO::requestAvatarTransfer(HANDLE hContact, char *szAvatarURL) diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp index 701b0508bc..e2484a3838 100644 --- a/protocols/Gadu-Gadu/src/oauth.cpp +++ b/protocols/Gadu-Gadu/src/oauth.cpp @@ -273,11 +273,7 @@ char *oauth_generate_nonce() mir_md5_byte_t digest[16]; mir_md5_hash((BYTE*)(char*)str, (int)strlen(str), digest); - - char *result = (char *)mir_alloc(32 + 1); - for (int i = 0; i < 16; i++) - mir_snprintf(result + (i<<1), 2, "%02x", digest[i]); - return result; + return bin2hex(digest, sizeof(digest), (char *)mir_alloc(32 + 1)); } char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD signmethod, diff --git a/protocols/JabberG/src/jabber.h b/protocols/JabberG/src/jabber.h index 294072106e..6303e824b2 100644 --- a/protocols/JabberG/src/jabber.h +++ b/protocols/JabberG/src/jabber.h @@ -744,7 +744,6 @@ TCHAR* __stdcall JabberStrFixLines(const TCHAR *str); char* __stdcall JabberUnixToDos(const char* str); WCHAR* __stdcall JabberUnixToDosW(const WCHAR* str); void __stdcall JabberHttpUrlDecode(TCHAR* str); -TCHAR* __stdcall JabberHttpUrlEncode(const TCHAR *str); int __stdcall JabberCombineStatus(int status1, int status2); TCHAR* __stdcall JabberErrorStr(int errorCode); TCHAR* __stdcall JabberErrorMsg(HXML errorNode, int* errorCode = NULL); diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp index aed856545a..62d1fa49ef 100644 --- a/protocols/JabberG/src/jabber_file.cpp +++ b/protocols/JabberG/src/jabber_file.cpp @@ -293,7 +293,7 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft) else p = ft->std.ptszFiles[i]; - TCHAR *pFileName = JabberHttpUrlEncode(p); + char *pFileName = mir_urlEncode( ptrA( mir_utf8encodeT(p))); if (pFileName != NULL) { int id = SerialNext(); if (ft->iqId) mir_free(ft->iqId); diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index f584333bbe..ea759258f5 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -1480,8 +1480,7 @@ LBL_ErrFormat: mir_sha1_init(&sha); mir_sha1_append(&sha, (mir_sha1_byte_t*)(char*)body, resultLen); mir_sha1_finish(&sha, digest); - for (int i=0; i<20; i++) - mir_snprintf(buffer + (i << 1), 2, "%02x", digest[i]); + bin2hex(digest, sizeof(digest), buffer); GetAvatarFileName(hContact, tszFileName, SIZEOF(tszFileName)); _tcsncpy(AI.filename, tszFileName, SIZEOF(AI.filename)); diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index 6dd9166276..4048dccf74 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -324,8 +324,7 @@ INT_PTR __cdecl CJabberProto::JabberSetAvatar(WPARAM, LPARAM lParam) DeleteFile(tFileName); char buf[MIR_SHA1_HASH_SIZE*2+1]; - for (int i=0; i='A' && *p<='Z') || (*p>='a' && *p<='z') || (*p>='0' && *p<='9') || strchr("$-_.+!*'(),", *p) != NULL) { - *q = *p; - } - else { - mir_sntprintf(q, size, _T("%%%02X"), *p); - q += 2; - } - } - *q = '\0'; - return res; -} - void __stdcall JabberHttpUrlDecode(TCHAR* str) { TCHAR *p, *q; @@ -1651,8 +1630,7 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param) mir_sha1_init(&sha); mir_sha1_append(&sha, (mir_sha1_byte_t*)res->pData, res->dataLength); mir_sha1_finish(&sha, digest); - for (int i=0; i<20; i++) - mir_snprintf(buffer + (i << 1), 2, "%02x", digest[i]); + bin2hex(digest, sizeof(digest), buffer); ptrA cmpsha( getStringA(AI.hContact, "AvatarSaved")); if (cmpsha == NULL || strnicmp(cmpsha, buffer, sizeof(buffer))) { diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp index d916441f3c..21cf96574c 100644 --- a/protocols/JabberG/src/jabber_vcard.cpp +++ b/protocols/JabberG/src/jabber_vcard.cpp @@ -1178,9 +1178,8 @@ void CJabberProto::SetServerVcard(BOOL bPhotoChanged, TCHAR* szPhotoFileName) mir_sha1_finish(&sha1ctx, digest); char buf[MIR_SHA1_HASH_SIZE*2+1]; - for (int j=0; j