From cd997e12f2ecf29c927f9c8c36ade9261140b2c5 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 10 Aug 2013 14:04:29 +0000 Subject: - much more effective implementation of MS_FP_GETCLIENTICONT; - new service, MS_FP_GETCLIENTDESCRT, to avoid perversions git-svn-id: http://svn.miranda-ng.org/main/trunk@5633 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../ClientChangeNotify/src/ClientChangeNotify.cpp | 4 +- plugins/ExternalAPI/m_fingerprint.h | 21 ++++-- plugins/FingerprintNG/src/fingerprint.cpp | 83 +++++++++------------- 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp b/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp index 8a91324ae4..1a19e8ef1d 100644 --- a/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp +++ b/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp @@ -247,8 +247,8 @@ int ContactSettingChanged(WPARAM wParam, LPARAM lParam) sd.PopupOptPage = &PopupOptPage; if (!PopupOptPage.GetValue(IDC_POPUPOPTDLG_VERCHGNOTIFY) || !PopupOptPage.GetValue(IDC_POPUPOPTDLG_SHOWVER)) { if (bFingerprintExists) { - LPCTSTR ptszOldClient = Finger_IsSameClents(sd.OldMirVer, sd.OldMirVer); - LPCTSTR ptszClient = Finger_IsSameClents(sd.MirVer, sd.MirVer); + LPCTSTR ptszOldClient = Finger_GetClientDescr(sd.OldMirVer); + LPCTSTR ptszClient = Finger_GetClientDescr(sd.MirVer); if (ptszOldClient && ptszClient) { if (PerContactSetting != NOTIFY_ALMOST_ALWAYS && PerContactSetting != NOTIFY_ALWAYS && !PopupOptPage.GetValue(IDC_POPUPOPTDLG_VERCHGNOTIFY) && !_tcscmp(ptszClient, ptszOldClient)) return 0; diff --git a/plugins/ExternalAPI/m_fingerprint.h b/plugins/ExternalAPI/m_fingerprint.h index 3dd6cbd694..35fc75c260 100644 --- a/plugins/ExternalAPI/m_fingerprint.h +++ b/plugins/ExternalAPI/m_fingerprint.h @@ -30,9 +30,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /* * Service SameClientsW MS_FP_SAMECLIENTSW - * wParam - LPWSTR first MirVer value - * lParam - LPWSTR second MirVer value - * return LPWSTR: client desription (DO NOT DESTROY) if clients are same otherwise NULL + * wParam - LPCWSTR first MirVer value + * lParam - LPCWSTR second MirVer value + * returns LPCWSTR: client desription (DO NOT DESTROY) if clients are same otherwise NULL */ #define MS_FP_SAMECLIENTSW "Fingerprint/SameClientsW" @@ -40,6 +40,18 @@ __forceinline LPCWSTR Finger_IsSameClents(LPCWSTR pwszName1, LPCWSTR pwszName2) { return (LPCWSTR)CallService(MS_FP_SAMECLIENTSW, (WPARAM)pwszName1, (WPARAM)pwszName2); } +/* + * Service GetClientDescrW MS_FP_GETCLIENTDESCRW + * wParam - LPCWSTR MirVer value to get client for. + * lParam - NULL (unused) + * returns LPCWSTR: client description (DO NOT DESTROY) otherwise NULL + */ +#define MS_FP_GETCLIENTDESCRW "Fingerprint/GetClientDescrW" + +__forceinline LPCWSTR Finger_GetClientDescr(LPCWSTR pwszName) +{ return (LPCWSTR)CallService(MS_FP_GETCLIENTDESCRW, (WPARAM)pwszName, 0); +} + /* * Service GetClientIconW MS_FP_GETCLIENTICONW * wParam - LPWSTR MirVer value to get client for. @@ -49,8 +61,9 @@ __forceinline LPCWSTR Finger_IsSameClents(LPCWSTR pwszName1, LPCWSTR pwszName2) #define MS_FP_GETCLIENTICONW "Fingerprint/GetClientIconW" __forceinline HICON Finger_GetClientIcon(LPCWSTR pwszName, BOOL bNoCopy) -{ return (HICON)CallService(MS_FP_SAMECLIENTSW, (WPARAM)pwszName, bNoCopy); +{ return (HICON)CallService(MS_FP_GETCLIENTICONW, (WPARAM)pwszName, bNoCopy); } #define MS_FP_SAMECLIENTST MS_FP_SAMECLIENTSW +#define MS_FP_GETCLIENTDESCRT MS_FP_GETCLIENTDESCRW #define MS_FP_GETCLIENTICONT MS_FP_GETCLIENTICONW diff --git a/plugins/FingerprintNG/src/fingerprint.cpp b/plugins/FingerprintNG/src/fingerprint.cpp index 40327b3c7e..0d103be59e 100644 --- a/plugins/FingerprintNG/src/fingerprint.cpp +++ b/plugins/FingerprintNG/src/fingerprint.cpp @@ -773,66 +773,46 @@ static INT_PTR ServiceGetClientIconW(WPARAM wParam, LPARAM lParam) } /**************************************************************************************** - * ServiceSameClientW - * MS_FP_SAMECLIENTSW service implementation. - * wParam - LPWSTR first MirVer value - * lParam - LPWSTR second MirVer value - * return pointer to char string - client desription (do not destroy) if clients are same + * ServiceGetClientDescrW + * MS_FP_GETCLIENTDESCRW service implementation. + * wParam - LPCWSTR MirVer value + * lParam - (NULL) unused + * returns LPCWSTR: client desription (do not destroy) or NULL */ -static INT_PTR ServiceSameClientsW(WPARAM wParam, LPARAM lParam) +static INT_PTR ServiceGetClientDescrW(WPARAM wParam, LPARAM lParam) { - LPWSTR wszMirVerFirst = (LPWSTR)wParam; // MirVer value to get client for. - LPWSTR wszMirVerSecond = (LPWSTR)lParam; // MirVer value to get client for. - int firstIndex, secondIndex; - BOOL Result = FALSE; - - firstIndex = secondIndex = 0; - if (!wszMirVerFirst || !wszMirVerSecond) return (INT_PTR)NULL; //one of its is not null - - { - LPWSTR wszMirVerFirstUp, wszMirVerSecondUp; - size_t iMirVerFirstUpLen, iMirVerSecondUpLen; - - iMirVerFirstUpLen = wcslen(wszMirVerFirst) + 1; - iMirVerSecondUpLen = wcslen(wszMirVerSecond) + 1; - - wszMirVerFirstUp = (LPWSTR)mir_alloc(iMirVerFirstUpLen * sizeof(WCHAR)); - wszMirVerSecondUp = (LPWSTR)mir_alloc(iMirVerSecondUpLen * sizeof(WCHAR)); + LPWSTR wszMirVer = (LPWSTR)wParam; // MirVer value to get client for. + if (wszMirVer == NULL) + return 0; - wcscpy_s(wszMirVerFirstUp, iMirVerFirstUpLen, wszMirVerFirst); - wcscpy_s(wszMirVerSecondUp, iMirVerSecondUpLen, wszMirVerSecond); + LPWSTR wszMirVerUp = NEWWSTR_ALLOCA(wszMirVer); _wcsupr(wszMirVerUp); + if (wcscmp(wszMirVerUp, L"?") == 0) + return (INT_PTR)def_kn_fp_mask[UNKNOWN_MASK_NUMBER].szClientDescription; - _wcsupr_s(wszMirVerFirstUp, iMirVerFirstUpLen); - _wcsupr_s(wszMirVerSecondUp, iMirVerSecondUpLen); + for (int index = 0; index < DEFAULT_KN_FP_MASK_COUNT; index++) + if (WildCompareW(wszMirVerUp, def_kn_fp_mask[index].szMaskUpper)) + return (INT_PTR)def_kn_fp_mask[index].szClientDescription; - if (wcscmp(wszMirVerFirstUp, L"?") == 0) - firstIndex = UNKNOWN_MASK_NUMBER; - else - while(firstIndex < DEFAULT_KN_FP_MASK_COUNT) { - if (WildCompareW(wszMirVerFirstUp, def_kn_fp_mask[firstIndex].szMaskUpper)) - break; - firstIndex++; - } + return NULL; +} - if (wcscmp(wszMirVerSecondUp, L"?") == 0) - secondIndex = UNKNOWN_MASK_NUMBER; - else - while(secondIndex < DEFAULT_KN_FP_MASK_COUNT) { - if (WildCompareW(wszMirVerSecondUp, def_kn_fp_mask[secondIndex].szMaskUpper)) - break; - secondIndex++; - } +/**************************************************************************************** + * ServiceSameClientW + * MS_FP_SAMECLIENTSW service implementation. + * wParam - LPWSTR first MirVer value + * lParam - LPWSTR second MirVer value + * returns LPCWSTR: client desñription (do not destroy) if clients are same or NULL + */ - mir_free(wszMirVerFirstUp); - mir_free(wszMirVerSecondUp); +static INT_PTR ServiceSameClientsW(WPARAM wParam, LPARAM lParam) +{ + if (!wParam || !lParam) + return NULL; //one of its is not null - if (firstIndex == secondIndex && firstIndex < DEFAULT_KN_FP_MASK_COUNT) - { - return (INT_PTR)def_kn_fp_mask[firstIndex].szClientDescription; - } - } - return (INT_PTR)NULL; + INT_PTR res1 = ServiceGetClientDescrW(wParam, 0); + INT_PTR res2 = ServiceGetClientDescrW(lParam, 0); + return (res1 == res2 && res1 != 0) ? res1 : NULL; } /**************************************************************************************** @@ -976,6 +956,7 @@ void InitFingerModule() HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); CreateServiceFunction(MS_FP_SAMECLIENTSW, ServiceSameClientsW); + CreateServiceFunction(MS_FP_GETCLIENTDESCRW, ServiceGetClientDescrW); CreateServiceFunction(MS_FP_GETCLIENTICONW, ServiceGetClientIconW); } -- cgit v1.2.3