From 35df0639c0bd3ad7f1a7f73604b859e100a6c50c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 24 Nov 2017 22:25:19 +0300 Subject: GMailNotifier: major rework to Miranda Netlib functions --- plugins/GmailNotifier/src/check.cpp | 258 +++++++++++++++------------------- plugins/GmailNotifier/src/main.cpp | 27 ++-- plugins/GmailNotifier/src/notify.cpp | 10 +- plugins/GmailNotifier/src/options.cpp | 92 ++++++------ plugins/GmailNotifier/src/stdafx.h | 31 ++-- plugins/GmailNotifier/src/utility.cpp | 42 +++--- plugins/GmailNotifier/src/version.h | 4 +- 7 files changed, 225 insertions(+), 239 deletions(-) (limited to 'plugins') diff --git a/plugins/GmailNotifier/src/check.cpp b/plugins/GmailNotifier/src/check.cpp index e2d5af213a..9a74b69765 100644 --- a/plugins/GmailNotifier/src/check.cpp +++ b/plugins/GmailNotifier/src/check.cpp @@ -2,151 +2,7 @@ #pragma comment(lib, "Wininet.lib") - -void CheckMailInbox(Account *curAcc) -{ - // internet connection handle - // internet request handle - HINTERNET hHTTPConnection = nullptr, hHTTPRequest = nullptr; - - DBVARIANT dbv; - static char *contentType = "Content-Type: application/x-www-form-urlencoded"; - char requestBuffer[256] = "continue=https%3A%2F%2Fmail.google.com%2Fa%2F"; - char fileBuffer[_MAX_DOWN_BUFFER] = ""; - char *tail; - char str[64]; - char temp[_MAX_DOWN_BUFFER] = ""; - unsigned long bufferLength; - - if (curAcc->IsChecking) - return; - - curAcc->IsChecking = TRUE; - - if (!db_get_s(curAcc->hContact, "CList", "MyHandle", &dbv)) { - mir_strcpy(curAcc->results.content, dbv.pszVal); - db_free(&dbv); - } - else mir_strcpy(curAcc->results.content, curAcc->name); - - tail = strstr(curAcc->results.content, " ["); - if (tail) *tail = '\0'; - mir_strcat(curAcc->results.content, " ["); - - mir_strcpy(str, curAcc->results.content); - mir_strcat(str, Translate("Checking...")); - mir_strcat(str, "]"); - - db_set_s(curAcc->hContact, "CList", "MyHandle", str); - // internet open handle - HINTERNET hHTTPOpen = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0); - if (!hHTTPOpen) { - mir_strcat(curAcc->results.content, Translate("Can't open Internet!")); - goto error_handle; - } - - if (curAcc->hosted[0]) { - hHTTPConnection = InternetConnectA(hHTTPOpen, - "www.google.com", - INTERNET_DEFAULT_HTTPS_PORT, - nullptr, - nullptr, - INTERNET_SERVICE_HTTP, - 0, - 0); - - if (!hHTTPConnection) { - mir_strcat(curAcc->results.content, Translate("Can't reach server!")); - goto error_handle; - } - mir_strcpy(str, "/a/"); - mir_strcat(str, curAcc->hosted); - mir_strcat(str, "/LoginAction"); - hHTTPRequest = HttpOpenRequestA(hHTTPConnection, "POST", str, HTTP_VERSIONA, nullptr, nullptr, INTERNET_FLAG_SECURE, 0); - mir_strcat(requestBuffer, curAcc->hosted); - mir_strcat(requestBuffer, "%2Ffeed%2Fatom&service=mail&userName="); - mir_strcat(requestBuffer, curAcc->name); - tail = strchr(requestBuffer, '@'); - *tail = '\0'; - mir_strcat(requestBuffer, "&password="); - mir_strcat(requestBuffer, curAcc->pass); - if (!HttpSendRequestA(hHTTPRequest, contentType, (int)mir_strlen(contentType) + 1, requestBuffer, (int)mir_strlen(requestBuffer) + 1)) { - mir_strcpy(curAcc->results.content, Translate("Can't send account data!")); - goto error_handle; - } - - InternetCloseHandle(hHTTPConnection); - InternetCloseHandle(hHTTPRequest); - hHTTPRequest = nullptr; - } - - hHTTPConnection = InternetConnectA(hHTTPOpen, "mail.google.com", INTERNET_DEFAULT_HTTPS_PORT, nullptr, nullptr, INTERNET_SERVICE_HTTP, 0, 0); - if (!hHTTPConnection) { - mir_strcat(curAcc->results.content, Translate("Can't reach server!")); - goto error_handle; - } - if (curAcc->hosted[0]) { - mir_strcpy(str, "/a/"); - mir_strcat(str, curAcc->hosted); - mir_strcat(str, "/feed/atom"); - } - else mir_strcpy(str, "/mail/feed/atom"); - - hHTTPRequest = HttpOpenRequest(hHTTPConnection, L"GET", _A2T(str), nullptr, nullptr, nullptr, INTERNET_FLAG_SECURE | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0); - InternetSetOption(hHTTPRequest, INTERNET_OPTION_USERNAME, _A2T(curAcc->name), (int)mir_strlen(curAcc->name) + 1); - InternetSetOption(hHTTPRequest, INTERNET_OPTION_PASSWORD, _A2T(curAcc->pass), (int)mir_strlen(curAcc->pass) + 1); - if (!HttpSendRequest(hHTTPRequest, nullptr, 0, nullptr, 0)) { - mir_strcat(curAcc->results.content, Translate("Can't get RSS feed!")); - goto error_handle; - } - while (InternetReadFile(hHTTPRequest, temp, _MAX_DOWN_BUFFER, &bufferLength) && bufferLength > 0) { - temp[bufferLength] = '\0'; - mir_strcat(fileBuffer, temp); - } - - fileBuffer[_MAX_DOWN_BUFFER - 1] = '\0'; - curAcc->results_num = ParsePage(fileBuffer, &curAcc->results); - if (curAcc->results_num == -1) { - mir_strcat(curAcc->results.content, Translate("Wrong name or password!")); - goto error_handle; - } - InternetCloseHandle(hHTTPOpen); - InternetCloseHandle(hHTTPConnection); - InternetCloseHandle(hHTTPRequest); - - mir_strcat(curAcc->results.content, _itoa(curAcc->results_num, str, 10)); - mir_strcat(curAcc->results.content, "]"); - - curAcc->IsChecking = FALSE; - return; - -error_handle: - curAcc->results_num = -1; - InternetCloseHandle(hHTTPOpen); - InternetCloseHandle(hHTTPConnection); - InternetCloseHandle(hHTTPRequest); - - mir_strcat(curAcc->results.content, "]"); - - curAcc->IsChecking = FALSE; -} - -void __cdecl Check_ThreadFunc(void *lpParam) -{ - InternetSetCookieA("https://mail.google.com/mail/", "GX", ""); - if (lpParam) { - CheckMailInbox((Account *)lpParam); - NotifyUser((Account *)lpParam); - } - else { - for (int i = 0; i < acc_num && GetContactProto(acc[i].hContact); i++) { - CheckMailInbox(&acc[i]); - NotifyUser(&acc[i]); - } - } -} - -int ParsePage(char *page, resultLink *prst) +static int ParsePage(char *page, resultLink *prst) { char *str_head; char *str_tail; @@ -155,8 +11,6 @@ int ParsePage(char *page, resultLink *prst) wchar_t str[64]; prst->next = nullptr; - if (strstr(page, "Unauthorized")) - return -1; if (!(str_head = strstr(page, ""))) return 0; @@ -186,3 +40,113 @@ int ParsePage(char *page, resultLink *prst) prst->next = nullptr; return num; } + +void CheckMailInbox(Account *curAcc) +{ + if (curAcc->IsChecking) + return; + + curAcc->IsChecking = true; + + mir_strcpy(curAcc->results.content, curAcc->name); + mir_strcat(curAcc->results.content, " ["); + + char str[64]; + mir_snprintf(str, "%s%s]", curAcc->results.content, Translate("Checking...")); + db_set_s(curAcc->hContact, "CList", "MyHandle", str); + + if (curAcc->hosted[0]) { + CMStringA szUrl(FORMAT, "https://www.google.com/a/%s/LoginAction", curAcc->hosted); + CMStringA szBody("continue=https%3A%2F%2Fmail.google.com%2Fa%2F"); + szBody.Append(curAcc->hosted); + szBody.Append("%2Ffeed%2Fatom&service=mail&userName="); + char *tail = strchr(curAcc->name, '@'); + if (tail) *tail = 0; + szBody.Append(curAcc->name); + if (tail) *tail = '@'; + szBody.Append("&password="); + szBody.Append(curAcc->pass); + + NETLIBHTTPHEADER headers[1] = { + { "Content-Type", "application/x-www-form-urlencoded" } + }; + + NETLIBHTTPREQUEST nlr = {}; + nlr.cbSize = sizeof(nlr); + nlr.szUrl = szUrl.GetBuffer(); + nlr.requestType = REQUEST_POST; + nlr.headersCount = _countof(headers); + nlr.headers = headers; + nlr.dataLength = szBody.GetLength(); + nlr.pData = szBody.GetBuffer(); + + NETLIBHTTPREQUEST *nlu = Netlib_HttpTransaction(hNetlibUser, &nlr); + if (nlu == nullptr || nlu->resultCode != 200) { + mir_strcpy(curAcc->results.content, Translate("Can't send account data!")); + + Netlib_FreeHttpRequest(nlu); + curAcc->results_num = -1; + mir_strcat(curAcc->results.content, "]"); + curAcc->IsChecking = false; + return; + } + + Netlib_FreeHttpRequest(nlu); + } + + // go! + CMStringA loginPass(FORMAT, "%s:%s", curAcc->name, curAcc->pass); + ptrA loginPassEncoded(mir_base64_encode((BYTE*)loginPass.c_str(), loginPass.GetLength())); + + CMStringA szUrl("https://mail.google.com"), szAuth(FORMAT, "Basic %s", loginPassEncoded.get()); + if (curAcc->hosted[0]) + szUrl.AppendFormat("/a/%s/feed/atom", curAcc->hosted); + else + szUrl.Append("/mail/feed/atom"); + + NETLIBHTTPHEADER headers[1] = { + { "Authorization", szAuth.GetBuffer() } + }; + + NETLIBHTTPREQUEST nlr = {}; + nlr.cbSize = sizeof(nlr); + nlr.szUrl = szUrl.GetBuffer(); + nlr.requestType = REQUEST_GET; + + NETLIBHTTPREQUEST *nlu = Netlib_HttpTransaction(hNetlibUser, &nlr); + if (nlu == nullptr) { + if (nlr.resultCode == 401) + mir_strcat(curAcc->results.content, Translate("Wrong name or password!")); + else + mir_strcat(curAcc->results.content, Translate("Can't get RSS feed!")); + Netlib_FreeHttpRequest(nlu); + + curAcc->results_num = -1; + mir_strcat(curAcc->results.content, "]"); + curAcc->IsChecking = false; + return; + } + + curAcc->results_num = ParsePage(nlu->pData, &curAcc->results); + mir_strcat(curAcc->results.content, _itoa(curAcc->results_num, str, 10)); + mir_strcat(curAcc->results.content, "]"); + + curAcc->IsChecking = false; +} + +void __cdecl Check_ThreadFunc(void *lpParam) +{ + if (lpParam) { + CheckMailInbox((Account *)lpParam); + NotifyUser((Account *)lpParam); + } + else { + for (int i = 0; i < g_accs.getCount(); i++) { + Account &acc = g_accs[i]; + if (GetContactProto(acc.hContact)) { + CheckMailInbox(&acc); + NotifyUser(&acc); + } + } + } +} diff --git a/plugins/GmailNotifier/src/main.cpp b/plugins/GmailNotifier/src/main.cpp index 451c125205..ff6946fadc 100644 --- a/plugins/GmailNotifier/src/main.cpp +++ b/plugins/GmailNotifier/src/main.cpp @@ -15,10 +15,11 @@ HINSTANCE hInst; int hLangpack; UINT hTimer; HANDLE hMirandaStarted, hOptionsInitial; +HNETLIBUSER hNetlibUser; NOTIFYICONDATA niData; optionSettings opt; -int acc_num = 0; -Account *acc; + +OBJLIST g_accs(1); BOOL optionWindowIsOpen = FALSE; short ID_STATUS_NONEW; @@ -99,6 +100,12 @@ extern "C" int __declspec(dllexport) Load() pd.type = PROTOTYPE_VIRTUAL; Proto_RegisterModule(&pd); + NETLIBUSER nlu = {}; + nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_NOHTTPSOPTION | NUF_UNICODE; + nlu.szSettingsModule = MODULE_NAME; + nlu.szDescriptiveName.w = TranslateT("Gmail Notifier connection"); + hNetlibUser = Netlib_RegisterUser(&nlu); + CreateProtoServiceFunction(MODULE_NAME, PS_GETCAPS, GetCaps); CreateProtoServiceFunction(MODULE_NAME, PS_GETSTATUS, GetStatus); CreateProtoServiceFunction(MODULE_NAME, PS_GETNAME, GetName); @@ -127,13 +134,13 @@ extern "C" int __declspec(dllexport) Load() BuildList(); ID_STATUS_NONEW = opt.UseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE; - for (int i = 0; i < acc_num; i++) - db_set_dw(acc[i].hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); + for (int i = 0; i < g_accs.getCount(); i++) + db_set_dw(g_accs[i].hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); hTimer = SetTimer(nullptr, 0, opt.circleTime * 60000, TimerProc); hMirandaStarted = HookEvent(ME_SYSTEM_MODULESLOADED, OnMirandaStart); hOptionsInitial = HookEvent(ME_OPT_INITIALISE, OptInit); - + CreateServiceFunction(MODULE_NAME "/MenuCommand", PluginMenuCommand); CMenuItem mi; @@ -155,9 +162,13 @@ extern "C" int __declspec(dllexport) Unload(void) { if (hTimer) KillTimer(nullptr, hTimer); - for (int i = 0; i < acc_num; i++) - DeleteResults(acc[i].results.next); - free(acc); + + for (int i = 0; i < g_accs.getCount(); i++) + DeleteResults(g_accs[i].results.next); + g_accs.destroy(); + + Netlib_CloseHandle(hNetlibUser); + UnhookEvent(hMirandaStarted); UnhookEvent(hOptionsInitial); return 0; diff --git a/plugins/GmailNotifier/src/notify.cpp b/plugins/GmailNotifier/src/notify.cpp index e49421dc5d..ee1bbc04e4 100644 --- a/plugins/GmailNotifier/src/notify.cpp +++ b/plugins/GmailNotifier/src/notify.cpp @@ -36,12 +36,12 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA case UM_INITPOPUP: curAcc->popUpHwnd = hWnd; break; - + case WM_COMMAND: if (HIWORD(wParam) == STN_CLICKED) OpenBrowser((WPARAM)hContact, 0); break; - + case WM_CONTEXTMENU: PUDeletePopup(hWnd); curAcc->popUpHwnd = nullptr; @@ -54,7 +54,7 @@ void NotifyUser(Account *curAcc) { if (optionWindowIsOpen) return; - + db_set_s(curAcc->hContact, "CList", "MyHandle", curAcc->results.content); switch (curAcc->results_num) { case 0: @@ -63,11 +63,11 @@ void NotifyUser(Account *curAcc) if (curAcc->oldResults_num != 0) db_set_w(curAcc->hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); break; - + case -1: db_set_w(curAcc->hContact, MODULE_NAME, "Status", ID_STATUS_AWAY); break; - + default: db_set_w(curAcc->hContact, MODULE_NAME, "Status", ID_STATUS_OCCUPIED); int newMails = (curAcc->oldResults_num == -1) ? (curAcc->results_num) : (curAcc->results_num - curAcc->oldResults_num); diff --git a/plugins/GmailNotifier/src/options.cpp b/plugins/GmailNotifier/src/options.cpp index 4978d80214..a3f781c8b1 100644 --- a/plugins/GmailNotifier/src/options.cpp +++ b/plugins/GmailNotifier/src/options.cpp @@ -1,19 +1,23 @@ #include "stdafx.h" -static void SaveButton(HWND hwndDlg,HWND hwndCombo, int curIndex) { - if (GetDlgItemTextA(hwndDlg, IDC_NAME, acc[curIndex].name, _countof(acc[curIndex].name))) { - char *tail = strstr(acc[curIndex].name, "@"); +static void SaveButton(HWND hwndDlg, HWND hwndCombo, int curIndex) +{ + Account &acc = g_accs[curIndex]; + if (GetDlgItemTextA(hwndDlg, IDC_NAME, acc.name, _countof(acc.name))) { + char *tail = strstr(acc.name, "@"); if (tail && mir_strcmp(tail + 1, "gmail.com") != 0) - mir_strcpy(acc[curIndex].hosted, tail + 1); + mir_strcpy(acc.hosted, tail + 1); SendMessageA(hwndCombo, CB_DELETESTRING, curIndex, 0); - SendMessageA(hwndCombo, CB_INSERTSTRING, curIndex, (LPARAM)acc[curIndex].name); + SendMessageA(hwndCombo, CB_INSERTSTRING, curIndex, (LPARAM)acc.name); SendMessageA(hwndCombo, CB_SETCURSEL, curIndex, 0); - db_set_s(acc[curIndex].hContact, MODULE_NAME, "name", acc[curIndex].name); - db_set_s(acc[curIndex].hContact, MODULE_NAME, "Nick", acc[curIndex].name); - GetDlgItemTextA(hwndDlg, IDC_PASS, acc[curIndex].pass, _countof(acc[curIndex].pass)); - db_set_s(acc[curIndex].hContact, MODULE_NAME, "Password", acc[curIndex].pass); + db_set_s(acc.hContact, MODULE_NAME, "name", acc.name); + db_set_s(acc.hContact, MODULE_NAME, "Nick", acc.name); + + GetDlgItemTextA(hwndDlg, IDC_PASS, acc.pass, _countof(acc.pass)); + db_set_s(acc.hContact, MODULE_NAME, "Password", acc.pass); } } + static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { int ShowControl; @@ -22,7 +26,7 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA static bool bInit = false; HWND hwndCombo = GetDlgItem(hwndDlg, IDC_NAME); - if (acc_num) { + if (g_accs.getCount()) { EnableWindow(hwndCombo, TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_PASS), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTNSAV), TRUE); @@ -42,11 +46,11 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA optionWindowIsOpen = TRUE; BuildList(); - for (int i = 0; i < acc_num; i++) - SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LONG_PTR)acc[i].name); + for (int i = 0; i < g_accs.getCount(); i++) + SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LONG_PTR)g_accs[i].name); SendMessage(hwndCombo, CB_SETCURSEL, curIndex, 0); - if (curIndex < acc_num) - SetDlgItemTextA(hwndDlg, IDC_PASS, acc[curIndex].pass); + if (curIndex < g_accs.getCount()) + SetDlgItemTextA(hwndDlg, IDC_PASS, g_accs[curIndex].pass); SetDlgItemInt(hwndDlg, IDC_CIRCLE, opt.circleTime, FALSE); if (opt.notifierOnTray) @@ -141,50 +145,58 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; + case IDC_BTNADD: - acc_num++; - acc = (Account *)realloc(acc, acc_num * sizeof(Account)); - curIndex = SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LPARAM)""); - memset(&acc[curIndex], 0, sizeof(Account)); - SendMessage(hwndCombo, CB_SETCURSEL, curIndex, 0); - SetDlgItemTextA(hwndDlg, IDC_PASS, ""); - SetFocus(hwndCombo); - acc[curIndex].hContact = db_add_contact(); - Proto_AddToContact(acc[curIndex].hContact, MODULE_NAME); + { + Account *p = new Account(); + p->hContact = db_add_contact(); + Proto_AddToContact(p->hContact, MODULE_NAME); + g_accs.insert(p); + + curIndex = SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LPARAM)""); + SendMessage(hwndCombo, CB_SETCURSEL, curIndex, 0); + SetDlgItemTextA(hwndDlg, IDC_PASS, ""); + SetFocus(hwndCombo); + } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; - + case IDC_BTNSAV: - SaveButton(hwndDlg,hwndCombo, curIndex); + SaveButton(hwndDlg, hwndCombo, curIndex); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_BTNDEL: - acc_num--; - SendMessage(hwndCombo, CB_DELETESTRING, curIndex, 0); - DeleteResults(acc[curIndex].results.next); - acc[curIndex].results.next = nullptr; - db_delete_contact(acc[curIndex].hContact); - for (int i = curIndex; i < acc_num; i++) - acc[i] = acc[i + 1]; - curIndex = 0; - SendMessage(hwndCombo, CB_SETCURSEL, 0, 0); - SetDlgItemTextA(hwndDlg, IDC_PASS, acc[0].pass); + { + SendMessage(hwndCombo, CB_DELETESTRING, curIndex, 0); + + Account &acc = g_accs[curIndex]; + DeleteResults(acc.results.next); + db_delete_contact(acc.hContact); + g_accs.remove(curIndex); + + curIndex = 0; + SendMessage(hwndCombo, CB_SETCURSEL, 0, 0); + if (g_accs.getCount()) + SetDlgItemTextA(hwndDlg, IDC_PASS, g_accs[0].pass); + } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_NAME: if (HIWORD(wParam) == CBN_SELCHANGE) { curIndex = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0); - SetDlgItemTextA(hwndDlg, IDC_PASS, acc[curIndex].pass); + SetDlgItemTextA(hwndDlg, IDC_PASS, g_accs[curIndex].pass); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; + case IDC_CIRCLE: case IDC_DURATION: if (!bInit && (HIWORD(wParam) == EN_CHANGE)) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; + case IDC_ONLINE: case IDC_SHOWICON: case IDC_AUTOLOGIN: @@ -197,7 +209,7 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: - SaveButton(hwndDlg,hwndCombo, curIndex); + SaveButton(hwndDlg, hwndCombo, curIndex); opt.circleTime = GetDlgItemInt(hwndDlg, IDC_CIRCLE, nullptr, FALSE); if (opt.circleTime > 0) { KillTimer(nullptr, hTimer); @@ -244,12 +256,12 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA db_set_dw(NULL, MODULE_NAME, "LogThreads", opt.LogThreads); ID_STATUS_NONEW = opt.UseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE; - for (int i = 0; i < acc_num; i++) - db_set_w(acc[i].hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); + for (int i = 0; i < g_accs.getCount(); i++) + db_set_w(g_accs[i].hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); } return TRUE; - case WM_DESTROY: + case WM_CLOSE: optionWindowIsOpen = FALSE; return TRUE; } diff --git a/plugins/GmailNotifier/src/stdafx.h b/plugins/GmailNotifier/src/stdafx.h index b24ccc862c..470fb6209b 100644 --- a/plugins/GmailNotifier/src/stdafx.h +++ b/plugins/GmailNotifier/src/stdafx.h @@ -1,5 +1,4 @@ #include -#include #include #include #include "resource.h" @@ -35,24 +34,27 @@ // #define STR5 ">');document.gmail.submit();" //#define LINK2 "https://www.google.com/a/altmanoptik.com/LoginAction?continue=https%3A%2F%2Fmail.google.com%2Fhosted%2Faltmanoptik.com&service=mail&userName=test&password=123456" -typedef struct s_resultLink{ +struct resultLink +{ char content[64]; - struct s_resultLink *next; -}resultLink; + struct resultLink *next; +}; -typedef struct s_Account{ +struct Account : public MZeroedObject +{ char name[256]; char pass[256]; char hosted[64]; MCONTACT hContact; int oldResults_num; - int results_num; + int results_num; resultLink results; HWND popUpHwnd; - BOOL IsChecking; -}Account; + bool IsChecking; +}; -typedef struct s_optionSettings{ +struct optionSettings +{ int circleTime; BOOL notifierOnTray; BOOL notifierOnPop; @@ -64,12 +66,12 @@ typedef struct s_optionSettings{ BOOL UseOnline; int AutoLogin; BOOL LogThreads; -}optionSettings; +}; -extern int acc_num; -extern Account *acc; +extern OBJLIST g_accs; extern optionSettings opt; extern HINSTANCE hInst; +extern HNETLIBUSER hNetlibUser; extern UINT hTimer; extern short ID_STATUS_NONEW; extern BOOL optionWindowIsOpen; @@ -78,13 +80,12 @@ INT_PTR Notifying(WPARAM, LPARAM); INT_PTR PluginMenuCommand(WPARAM, LPARAM); void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD); BOOL GetBrowser(char *); -//void CheckMailInbox(Account *); + void NotifyUser(Account *); int OptInit(WPARAM, LPARAM); void Check_ThreadFunc(void *); void Login_ThreadFunc(void *); -int OpenBrowser(WPARAM , LPARAM); -int ParsePage(char *, resultLink *); +int OpenBrowser(WPARAM, LPARAM); void DeleteResults(resultLink *); void BuildList(void); diff --git a/plugins/GmailNotifier/src/utility.cpp b/plugins/GmailNotifier/src/utility.cpp index eb243b8f57..cadc6820db 100644 --- a/plugins/GmailNotifier/src/utility.cpp +++ b/plugins/GmailNotifier/src/utility.cpp @@ -2,31 +2,29 @@ void BuildList(void) { - DBVARIANT dbv; + g_accs.destroy(); - acc_num = 0; for (MCONTACT hContact = db_find_first(MODULE_NAME); hContact; hContact = db_find_next(hContact, MODULE_NAME)) { - if (!db_get_s(hContact, MODULE_NAME, "name", &dbv)) { - acc_num++; - acc = (Account *)realloc(acc, acc_num * sizeof(Account)); - memset(&acc[acc_num-1], 0, sizeof(Account)); - acc[acc_num-1].hContact = hContact; - mir_strcpy(acc[acc_num-1].name, dbv.pszVal); + ptrA szName(db_get_sa(hContact, MODULE_NAME, "name")); + if (szName != nullptr) { + Account *p = new Account; + p->hContact = hContact; + mir_strcpy(p->name, szName); CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE); - db_free(&dbv); - - if (!db_get_s(hContact, MODULE_NAME, "Password", &dbv)) { - mir_strcpy(acc[acc_num-1].pass, dbv.pszVal); - db_free(&dbv); - } + + ptrA szPassword(db_get_sa(hContact, MODULE_NAME, "Password")); + if (szPassword != nullptr) + mir_strcpy(p->pass, szPassword); + g_accs.insert(p); } } - for (int i = 0; i < acc_num; i++) { - char *tail = strchr(acc[i].name, '@'); + for (int i = 0; i < g_accs.getCount(); i++) { + Account &acc = g_accs[i]; + char *tail = strchr(acc.name, '@'); if (tail && mir_strcmp(tail + 1, "gmail.com") != 0) - mir_strcpy(acc[i].hosted, tail + 1); - acc[i].IsChecking = FALSE; + mir_strcpy(acc.hosted, tail + 1); + acc.IsChecking = false; } } @@ -72,9 +70,9 @@ BOOL GetBrowser(char *str) Account* GetAccountByContact(MCONTACT hContact) { - for (int i = 0; i < acc_num; i++) - if (acc[i].hContact == hContact) - return &acc[i]; + for (int i = 0; i < g_accs.getCount(); i++) + if (g_accs[i].hContact == hContact) + return &g_accs[i]; return nullptr; -} \ No newline at end of file +} diff --git a/plugins/GmailNotifier/src/version.h b/plugins/GmailNotifier/src/version.h index 784dcc7076..74bd805294 100644 --- a/plugins/GmailNotifier/src/version.h +++ b/plugins/GmailNotifier/src/version.h @@ -1,5 +1,5 @@ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 3 +#define __MAJOR_VERSION 1 +#define __MINOR_VERSION 0 #define __RELEASE_NUM 1 #define __BUILD_NUM 1 -- cgit v1.2.3