From 3ad2582c4a4a6378f294f9256ecbcbdf0ae88e3a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 3 May 2018 16:02:14 +0200 Subject: mir_forkThread - stronger typizatioin for thread function parameter --- plugins/GmailNotifier/src/notify.cpp | 149 ++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 74 deletions(-) (limited to 'plugins/GmailNotifier/src/notify.cpp') diff --git a/plugins/GmailNotifier/src/notify.cpp b/plugins/GmailNotifier/src/notify.cpp index ee1bbc04e4..8222d5c4cf 100644 --- a/plugins/GmailNotifier/src/notify.cpp +++ b/plugins/GmailNotifier/src/notify.cpp @@ -1,5 +1,76 @@ #include "stdafx.h" +static void __cdecl Login_ThreadFunc(Account *curAcc) +{ + if (curAcc == nullptr) + return; + + HANDLE hTempFile; + DWORD dwBytesWritten, dwBufSize = 1024; + char szTempName[MAX_PATH]; + char buffer[1024]; + char *str_temp; + char lpPathBuffer[1024]; + + if (GetBrowser(lpPathBuffer)) { + if (opt.AutoLogin == 0) { + if (curAcc->hosted[0]) { + mir_strcat(lpPathBuffer, "https://mail.google.com/a/"); + mir_strcat(lpPathBuffer, curAcc->hosted); + mir_strcat(lpPathBuffer, "/?logout"); + } + else { + mir_strcat(lpPathBuffer, "https://mail.google.com/mail/?logout"); + } + } + else { + if (curAcc->hosted[0]) { + GetTempPathA(dwBufSize, buffer); + GetTempFileNameA(buffer, "gmail", 0, szTempName); + + hTempFile = CreateFileA(szTempName, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + mir_strcpy(buffer, FORMDATA1); + mir_strcat(buffer, curAcc->hosted); + mir_strcat(buffer, FORMDATA2); + mir_strcat(buffer, curAcc->hosted); + mir_strcat(buffer, FORMDATA3); + mir_strcat(buffer, ""); + WriteFile(hTempFile, buffer, (DWORD)mir_strlen(buffer), &dwBytesWritten, nullptr); + CloseHandle(hTempFile); + mir_strcat(lpPathBuffer, szTempName); + } + else { + char *szEncodedURL = mir_urlEncode(curAcc->name); + mir_strcat(lpPathBuffer, LINK); + mir_strcat(lpPathBuffer, szEncodedURL); + //mir_strcat(lpPathBuffer, "&Passwd="); + //mir_strcat(lpPathBuffer, mir_urlEncode(curAcc->pass)); + if (opt.AutoLogin == 1) + mir_strcat(lpPathBuffer, "&PersistentCookie=yes"); + mir_free(szEncodedURL); + } + } + } + + STARTUPINFOA suInfo = { 0 }; + PROCESS_INFORMATION procInfo; + suInfo.cb = sizeof(suInfo); + suInfo.wShowWindow = SW_MAXIMIZE; + if (CreateProcessA(nullptr, lpPathBuffer, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &suInfo, &procInfo)) + CloseHandle(procInfo.hProcess); + + if (curAcc->hosted[0]) { + Sleep(30000); + DeleteFileA(szTempName); + } +} + int OpenBrowser(WPARAM hContact, LPARAM) { char *proto = GetContactProto(hContact); @@ -16,7 +87,7 @@ int OpenBrowser(WPARAM hContact, LPARAM) DeleteResults(curAcc->results.next); curAcc->results.next = nullptr; } - mir_forkthread(Login_ThreadFunc, curAcc); + mir_forkThread(Login_ThreadFunc, curAcc); } return FALSE; } @@ -27,6 +98,8 @@ INT_PTR Notifying(WPARAM, LPARAM lParam) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { MCONTACT hContact = PUGetContact(hWnd); @@ -76,7 +149,7 @@ void NotifyUser(Account *curAcc) dbei.eventType = EVENTTYPE_MESSAGE; dbei.flags = DBEF_READ; dbei.szModule = MODULE_NAME; - dbei.timestamp = time(nullptr); + dbei.timestamp = time(0); resultLink *prst = curAcc->results.next; for (int i = 0; i < newMails; i++) { @@ -135,75 +208,3 @@ void DeleteResults(resultLink *prst) free(prst); } } - -void __cdecl Login_ThreadFunc(void *lpParam) -{ - if (lpParam == nullptr) - return; - - HANDLE hTempFile; - DWORD dwBytesWritten, dwBufSize = 1024; - char szTempName[MAX_PATH]; - char buffer[1024]; - char *str_temp; - char lpPathBuffer[1024]; - Account *curAcc = (Account *)lpParam; - - if (GetBrowser(lpPathBuffer)) { - if (opt.AutoLogin == 0) { - if (curAcc->hosted[0]) { - mir_strcat(lpPathBuffer, "https://mail.google.com/a/"); - mir_strcat(lpPathBuffer, curAcc->hosted); - mir_strcat(lpPathBuffer, "/?logout"); - } - else { - mir_strcat(lpPathBuffer, "https://mail.google.com/mail/?logout"); - } - } - else { - if (curAcc->hosted[0]) { - GetTempPathA(dwBufSize, buffer); - GetTempFileNameA(buffer, "gmail", 0, szTempName); - - hTempFile = CreateFileA(szTempName, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - mir_strcpy(buffer, FORMDATA1); - mir_strcat(buffer, curAcc->hosted); - mir_strcat(buffer, FORMDATA2); - mir_strcat(buffer, curAcc->hosted); - mir_strcat(buffer, FORMDATA3); - mir_strcat(buffer, ""); - WriteFile(hTempFile, buffer, (DWORD)mir_strlen(buffer), &dwBytesWritten, nullptr); - CloseHandle(hTempFile); - mir_strcat(lpPathBuffer, szTempName); - } - else { - char *szEncodedURL = mir_urlEncode(curAcc->name); - mir_strcat(lpPathBuffer, LINK); - mir_strcat(lpPathBuffer, szEncodedURL); - //mir_strcat(lpPathBuffer, "&Passwd="); - //mir_strcat(lpPathBuffer, mir_urlEncode(curAcc->pass)); - if (opt.AutoLogin == 1) - mir_strcat(lpPathBuffer, "&PersistentCookie=yes"); - mir_free(szEncodedURL); - } - } - } - - STARTUPINFOA suInfo = { 0 }; - PROCESS_INFORMATION procInfo; - suInfo.cb = sizeof(suInfo); - suInfo.wShowWindow = SW_MAXIMIZE; - if (CreateProcessA(nullptr, lpPathBuffer, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &suInfo, &procInfo)) - CloseHandle(procInfo.hProcess); - - if (curAcc->hosted[0]) { - Sleep(30000); - DeleteFileA(szTempName); - } -} -- cgit v1.2.3