From 087300b294b87ab2705244908ec932a5a8c98262 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 13 Dec 2014 19:53:55 +0000 Subject: fix for the url extractor git-svn-id: http://svn.miranda-ng.org/main/trunk@11377 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TabSRMM/src/chat/window.cpp | 1 + plugins/TabSRMM/src/infopanel.cpp | 9 ++++----- plugins/TabSRMM/src/msgdialog.cpp | 26 +++++++------------------- plugins/TabSRMM/src/utils.cpp | 21 ++++++++++----------- plugins/TabSRMM/src/utils.h | 2 +- 5 files changed, 23 insertions(+), 36 deletions(-) (limited to 'plugins') diff --git a/plugins/TabSRMM/src/chat/window.cpp b/plugins/TabSRMM/src/chat/window.cpp index 0dc798560b..1f320d304a 100644 --- a/plugins/TabSRMM/src/chat/window.cpp +++ b/plugins/TabSRMM/src/chat/window.cpp @@ -204,6 +204,7 @@ bool IsStringValidLink(TCHAR* pszText) { if (pszText == NULL) return false; + if (mir_tstrlen(pszText) < 5 || _tcschr(pszText, '"')) return false; diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp index 3c99a77283..68d8d58d04 100644 --- a/plugins/TabSRMM/src/infopanel.cpp +++ b/plugins/TabSRMM/src/infopanel.cpp @@ -1575,11 +1575,10 @@ INT_PTR CALLBACK CTip::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam switch (((ENLINK*)lParam)->msg) { case WM_LBUTTONUP: ENLINK *e = reinterpret_cast(lParam); - const TCHAR *tszUrl = Utils::extractURLFromRichEdit(e, m_hRich); - if (tszUrl) { - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)tszUrl); - mir_free(const_cast(tszUrl)); - } + ptrT tszUrl(Utils::extractURLFromRichEdit(e, m_hRich)); + if (tszUrl) + CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, tszUrl); + ::DestroyWindow(hwnd); } } diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 0b14a60e49..a97008bf54 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -2064,24 +2064,12 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_RBUTTONDOWN: case WM_LBUTTONUP: { - CHARRANGE sel; - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_EXGETSEL, 0, (LPARAM)&sel); - if (sel.cpMin != sel.cpMax) - break; - - TEXTRANGEW tr; - tr.chrg = ((ENLINK*)lParam)->chrg; - tr.lpstrText = (TCHAR*)_alloca(sizeof(TCHAR)*(tr.chrg.cpMax - tr.chrg.cpMin + 8)); - SendDlgItemMessage(hwndDlg, IDC_LOG, EM_GETTEXTRANGE, 0, (LPARAM)&tr); - if (_tcschr(tr.lpstrText, '@') != NULL && _tcschr(tr.lpstrText, ':') == NULL && _tcschr(tr.lpstrText, '/') == NULL) { - memmove(tr.lpstrText + 7, tr.lpstrText, tr.chrg.cpMax - tr.chrg.cpMin + 1); - memcpy(tr.lpstrText, _T("mailto:"), 7); - } - if (!IsStringValidLink(tr.lpstrText)) + ptrT tszUrl(Utils::extractURLFromRichEdit((ENLINK*)lParam, GetDlgItem(hwndDlg, IDC_LOG))); + if (!IsStringValidLink(tszUrl)) break; if (((ENLINK*)lParam)->msg != WM_RBUTTONDOWN) { - CallService(MS_UTILS_OPENURL, OUF_TCHAR, (LPARAM)tr.lpstrText); + CallService(MS_UTILS_OPENURL, OUF_TCHAR, tszUrl); SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); break; } @@ -2093,11 +2081,11 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP ClientToScreen(((NMHDR*)lParam)->hwndFrom, &pt); switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL)) { case IDM_OPENNEW: - CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)tr.lpstrText); + CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, tszUrl); break; case IDM_OPENEXISTING: - CallService(MS_UTILS_OPENURL, OUF_TCHAR, (LPARAM)tr.lpstrText); + CallService(MS_UTILS_OPENURL, OUF_TCHAR, tszUrl); break; case IDM_COPYLINK: @@ -2105,9 +2093,9 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; EmptyClipboard(); - HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(TCHAR)*(mir_tstrlen(tr.lpstrText) + 1)); + HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(TCHAR)*(mir_tstrlen(tszUrl) + 1)); TCHAR *buf = (TCHAR*)GlobalLock(hData); - mir_tstrcpy(buf, tr.lpstrText); + mir_tstrcpy(buf, tszUrl); GlobalUnlock(hData); SetClipboardData(CF_UNICODETEXT, hData); CloseClipboard(); diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index 960def80c4..80bded6da8 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -959,23 +959,22 @@ bool Utils::extractResource(const HMODULE h, const UINT uID, const TCHAR *tszNam // @param hwndRich - rich edit window handle // @return wchar_t* extracted URL -const wchar_t* Utils::extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich) +TCHAR* Utils::extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich) { - TEXTRANGEW tr = {0}; - CHARRANGE sel = {0}; - - ::SendMessageW(hwndRich, EM_EXGETSEL, 0, (LPARAM)&sel); + CHARRANGE sel = {0}; + ::SendMessage(hwndRich, EM_EXGETSEL, 0, (LPARAM)&sel); if (sel.cpMin != sel.cpMax) return 0; + TEXTRANGE tr; tr.chrg = _e->chrg; - tr.lpstrText = (wchar_t *)mir_alloc(2 * (tr.chrg.cpMax - tr.chrg.cpMin + 8)); - ::SendMessageW(hwndRich, EM_GETTEXTRANGE, 0, (LPARAM)&tr); - if (wcschr(tr.lpstrText, '@') != NULL && wcschr(tr.lpstrText, ':') == NULL && wcschr(tr.lpstrText, '/') == NULL) { - ::memmove(tr.lpstrText + 7, tr.lpstrText, sizeof(wchar_t) * (tr.chrg.cpMax - tr.chrg.cpMin + 1)); - ::memcpy(tr.lpstrText, L"mailto:", 7 * sizeof(wchar_t)); + tr.lpstrText = (TCHAR*)mir_alloc(sizeof(TCHAR) * (tr.chrg.cpMax - tr.chrg.cpMin + 8)); + ::SendMessage(hwndRich, EM_GETTEXTRANGE, 0, (LPARAM)&tr); + if (_tcschr(tr.lpstrText, '@') != NULL && _tcschr(tr.lpstrText, ':') == NULL && _tcschr(tr.lpstrText, '/') == NULL) { + mir_tstrncpy(tr.lpstrText, _T("mailto:"), 7); + mir_tstrncpy(tr.lpstrText + 7, tr.lpstrText, tr.chrg.cpMax - tr.chrg.cpMin + 1); } - return(tr.lpstrText); + return tr.lpstrText; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/TabSRMM/src/utils.h b/plugins/TabSRMM/src/utils.h index 34b4c5039d..35d91c1b9a 100644 --- a/plugins/TabSRMM/src/utils.h +++ b/plugins/TabSRMM/src/utils.h @@ -107,7 +107,7 @@ public: static HMODULE loadSystemLibrary(const wchar_t* szFilename); static INT_PTR CALLBACK PopupDlgProcError(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - static LPCTSTR extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich); + static LPTSTR extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich); static size_t CopyToClipBoard(const wchar_t *str, const HWND hwndOwner); -- cgit v1.2.3