From 878d72910cccf4f84c7cb45bb4c11134920f3166 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 18 Aug 2015 11:49:54 +0000 Subject: - naming conflict; - warning fixes; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14988 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/StopSpamMod/src/options.cpp | 323 ++++++++++++++++------------------ plugins/StopSpamMod/src/utilities.cpp | 188 +++++++++----------- 2 files changed, 235 insertions(+), 276 deletions(-) (limited to 'plugins/StopSpamMod/src') diff --git a/plugins/StopSpamMod/src/options.cpp b/plugins/StopSpamMod/src/options.cpp index 5b05c9696b..8b1698f996 100755 --- a/plugins/StopSpamMod/src/options.cpp +++ b/plugins/StopSpamMod/src/options.cpp @@ -19,124 +19,106 @@ int CreateCListGroup(TCHAR* szGroupName); -char * pluginDescription = LPGEN("No more spam! Robots can't go! Only human beings invited!\r\n\r\nThis plugin works pretty simple:\r\nWhile messages from users on your contact list go as there is no any anti-spam software, messages from unknown users are not delivered to you. But also they are not ignored, this plugin replies with a simple question, and if user gives the right answer, plugin adds him to your contact list so that he can contact you."); -TCHAR const * defQuestion = TranslateT("Spammers made me to install small anti-spam system you are now speaking with.\r\nPlease reply \"nospam\" without quotes and spaces if you want to contact me."); +char *pluginDescription = LPGEN("No more spam! Robots can't go! Only human beings invited!\r\n\r\nThis plugin works pretty simple:\r\nWhile messages from users on your contact list go as there is no any anti-spam software, messages from unknown users are not delivered to you. But also they are not ignored, this plugin replies with a simple question, and if user gives the right answer, plugin adds him to your contact list so that he can contact you."); +TCHAR const *defQuestion = TranslateT("Spammers made me to install small anti-spam system you are now speaking with.\r\nPlease reply \"nospam\" without quotes and spaces if you want to contact me."); INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) - { + switch (msg) { case WM_INITDIALOG: - { - SetDlgItemTextA(hwnd, ID_DESCRIPTION, pluginDescription); - TranslateDialogDefault(hwnd); - SetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, gbMaxQuestCount, FALSE); - CheckDlgButton(hwnd, ID_INFTALKPROT, gbInfTalkProtection ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwnd, ID_ADDPERMANENT, gbAddPermanent ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwnd, ID_HANDLEAUTHREQ, gbHandleAuthReq ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwnd, ID_HIDECONTACTS, gbHideContacts ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwnd, ID_IGNORESPAMMERS, gbIgnoreContacts ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwnd, ID_LOGSPAMTOFILE, gbLogToFile ? BST_CHECKED : BST_UNCHECKED); - } + SetDlgItemTextA(hwnd, ID_DESCRIPTION, pluginDescription); + TranslateDialogDefault(hwnd); + SetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, gbMaxQuestCount, FALSE); + CheckDlgButton(hwnd, ID_INFTALKPROT, gbInfTalkProtection ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwnd, ID_ADDPERMANENT, gbAddPermanent ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwnd, ID_HANDLEAUTHREQ, gbHandleAuthReq ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwnd, ID_HIDECONTACTS, gbHideContacts ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwnd, ID_IGNORESPAMMERS, gbIgnoreContacts ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwnd, ID_LOGSPAMTOFILE, gbLogToFile ? BST_CHECKED : BST_UNCHECKED); return TRUE; - case WM_COMMAND:{ - switch (LOWORD(wParam)) - { + + case WM_COMMAND: + switch (LOWORD(wParam)) { case ID_MAXQUESTCOUNT: - { - if (EN_CHANGE != HIWORD(wParam) || (HWND)lParam != GetFocus()) - return FALSE; - break; - } + if (EN_CHANGE != HIWORD(wParam) || (HWND)lParam != GetFocus()) + return FALSE; + break; } SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - } break; + case WM_NOTIFY: - { - NMHDR* nmhdr = (NMHDR*)lParam; - switch (nmhdr->code) + NMHDR* nmhdr = (NMHDR*)lParam; + switch (nmhdr->code) { + case PSN_APPLY: { - case PSN_APPLY: - { - db_set_dw(NULL, pluginName, "maxQuestCount", gbMaxQuestCount = GetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, NULL, FALSE)); - db_set_b(NULL, pluginName, "infTalkProtection", gbInfTalkProtection = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_INFTALKPROT)); - db_set_b(NULL, pluginName, "addPermanent", gbAddPermanent = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_ADDPERMANENT)); - db_set_b(NULL, pluginName, "handleAuthReq", gbHandleAuthReq = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_HANDLEAUTHREQ)); - db_set_b(NULL, pluginName, "HideContacts", gbHideContacts = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_HIDECONTACTS)); - db_set_b(NULL, pluginName, "IgnoreContacts", gbIgnoreContacts = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_IGNORESPAMMERS)); - db_set_b(NULL, pluginName, "LogSpamToFile", gbLogToFile = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_LOGSPAMTOFILE)); - } - return TRUE; + db_set_dw(NULL, pluginName, "maxQuestCount", gbMaxQuestCount = GetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, NULL, FALSE)); + db_set_b(NULL, pluginName, "infTalkProtection", gbInfTalkProtection = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_INFTALKPROT)); + db_set_b(NULL, pluginName, "addPermanent", gbAddPermanent = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_ADDPERMANENT)); + db_set_b(NULL, pluginName, "handleAuthReq", gbHandleAuthReq = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_HANDLEAUTHREQ)); + db_set_b(NULL, pluginName, "HideContacts", gbHideContacts = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_HIDECONTACTS)); + db_set_b(NULL, pluginName, "IgnoreContacts", gbIgnoreContacts = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_IGNORESPAMMERS)); + db_set_b(NULL, pluginName, "LogSpamToFile", gbLogToFile = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_LOGSPAMTOFILE)); } + return TRUE; } - break; + break; } return FALSE; } INT_PTR CALLBACK MessagesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - - switch(msg) - { + switch (msg) { case WM_INITDIALOG: - { - TranslateDialogDefault(hwnd); - SetDlgItemText(hwnd, ID_QUESTION, gbQuestion.c_str()); - SetDlgItemText(hwnd, ID_ANSWER, gbAnswer.c_str()); - SetDlgItemText(hwnd, ID_CONGRATULATION, gbCongratulation.c_str()); - SetDlgItemText(hwnd, ID_AUTHREPL, gbAuthRepl.c_str()); - EnableWindow(GetDlgItem(hwnd, ID_ANSWER), !gbMathExpression); - variables_skin_helpbutton(hwnd, IDC_VARS); - gbVarsServiceExist?EnableWindow(GetDlgItem(hwnd, IDC_VARS),1):EnableWindow(GetDlgItem(hwnd, IDC_VARS),0); - } + TranslateDialogDefault(hwnd); + SetDlgItemText(hwnd, ID_QUESTION, gbQuestion.c_str()); + SetDlgItemText(hwnd, ID_ANSWER, gbAnswer.c_str()); + SetDlgItemText(hwnd, ID_CONGRATULATION, gbCongratulation.c_str()); + SetDlgItemText(hwnd, ID_AUTHREPL, gbAuthRepl.c_str()); + EnableWindow(GetDlgItem(hwnd, ID_ANSWER), !gbMathExpression); + variables_skin_helpbutton(hwnd, IDC_VARS); + gbVarsServiceExist ? EnableWindow(GetDlgItem(hwnd, IDC_VARS), 1) : EnableWindow(GetDlgItem(hwnd, IDC_VARS), 0); return TRUE; + case WM_COMMAND: - { - switch(LOWORD(wParam)) - { - case ID_QUESTION: - case ID_ANSWER: - case ID_AUTHREPL: - case ID_CONGRATULATION: - { - if (EN_CHANGE != HIWORD(wParam) || (HWND)lParam != GetFocus()) - return FALSE; - break; - } - case ID_RESTOREDEFAULTS: - SetDlgItemText(hwnd, ID_QUESTION, defQuestion); - SetDlgItemText(hwnd, ID_ANSWER, _T("nospam")); - SetDlgItemText(hwnd, ID_AUTHREPL, TranslateT("StopSpam: send a message and reply to an anti-spam bot question.")); - SetDlgItemText(hwnd, ID_CONGRATULATION, TranslateT("Congratulations! You just passed human/robot test. Now you can write me a message.")); - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - return TRUE; - case IDC_VARS: - variables_showhelp(hwnd, msg, VHF_FULLDLG|VHF_SETLASTSUBJECT, NULL, NULL); - return TRUE; - } + switch (LOWORD(wParam)) { + case ID_QUESTION: + case ID_ANSWER: + case ID_AUTHREPL: + case ID_CONGRATULATION: + if (EN_CHANGE != HIWORD(wParam) || (HWND)lParam != GetFocus()) + return FALSE; + break; + + case ID_RESTOREDEFAULTS: + SetDlgItemText(hwnd, ID_QUESTION, defQuestion); + SetDlgItemText(hwnd, ID_ANSWER, _T("nospam")); + SetDlgItemText(hwnd, ID_AUTHREPL, TranslateT("StopSpam: send a message and reply to an anti-spam bot question.")); + SetDlgItemText(hwnd, ID_CONGRATULATION, TranslateT("Congratulations! You just passed human/robot test. Now you can write me a message.")); SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); + return TRUE; + + case IDC_VARS: + variables_showhelp(hwnd, msg, VHF_FULLDLG | VHF_SETLASTSUBJECT, NULL, NULL); + return TRUE; } + SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); break; + case WM_NOTIFY: - { - NMHDR* nmhdr = (NMHDR*)lParam; - switch (nmhdr->code) - { - case PSN_APPLY: - { - db_set_ws(NULL, pluginName, "question", GetDlgItemString(hwnd, ID_QUESTION).c_str()); - gbQuestion = DBGetContactSettingStringPAN(NULL, pluginName, "question", defQuestion); - db_set_ws(NULL, pluginName, "answer", GetDlgItemString(hwnd, ID_ANSWER).c_str()); - gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); - db_set_ws(NULL, pluginName, "authrepl", GetDlgItemString(hwnd, ID_AUTHREPL).c_str()); - gbAuthRepl = DBGetContactSettingStringPAN(NULL, pluginName, "authrepl", TranslateT("StopSpam: send a message and reply to an anti-spam bot question.")); - db_set_ws(NULL, pluginName, "congratulation", GetDlgItemString(hwnd, ID_CONGRATULATION).c_str()); - gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", TranslateT("Congratulations! You just passed human/robot test. Now you can write me a message.")); - } - return TRUE; - } + NMHDR *nmhdr = (NMHDR*)lParam; + switch (nmhdr->code) { + case PSN_APPLY: + db_set_ws(NULL, pluginName, "question", GetDlgItemString(hwnd, ID_QUESTION).c_str()); + gbQuestion = DBGetContactSettingStringPAN(NULL, pluginName, "question", defQuestion); + db_set_ws(NULL, pluginName, "answer", GetDlgItemString(hwnd, ID_ANSWER).c_str()); + gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); + db_set_ws(NULL, pluginName, "authrepl", GetDlgItemString(hwnd, ID_AUTHREPL).c_str()); + gbAuthRepl = DBGetContactSettingStringPAN(NULL, pluginName, "authrepl", TranslateT("StopSpam: send a message and reply to an anti-spam bot question.")); + db_set_ws(NULL, pluginName, "congratulation", GetDlgItemString(hwnd, ID_CONGRATULATION).c_str()); + gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", TranslateT("Congratulations! You just passed human/robot test. Now you can write me a message.")); + return TRUE; } break; } @@ -145,97 +127,90 @@ INT_PTR CALLBACK MessagesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar INT_PTR CALLBACK ProtoDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) - { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwnd); - int n; + int nAccs; PROTOACCOUNT **pppd; - Proto_EnumAccounts(&n, &pppd); - for (int i = 0; i < n; ++i) + Proto_EnumAccounts(&nAccs, &pppd); + for (int i = 0; i < nAccs; ++i) SendDlgItemMessageA(hwnd, (ProtoInList(pppd[i]->szModuleName) ? ID_USEDPROTO : ID_ALLPROTO), LB_ADDSTRING, 0, (LPARAM)pppd[i]->szModuleName); return TRUE; case WM_COMMAND: - switch(LOWORD(wParam)) - { + switch (LOWORD(wParam)) { + WPARAM n; case ID_ADD: - { - WPARAM n = (WPARAM)SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETCURSEL, 0, 0); - if(LB_ERR != n) { - size_t len = SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETTEXTLEN, n, 0); - if(LB_ERR != len) { - TCHAR * buf = new TCHAR[len + 1]; - SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETTEXT, n, (LPARAM)buf); - SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_ADDSTRING, 0, (LPARAM)buf); - delete []buf; - SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_DELETESTRING, n, 0); - } + n = (WPARAM)SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETCURSEL, 0, 0); + if (LB_ERR != n) { + size_t len = SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETTEXTLEN, n, 0); + if (LB_ERR != len) { + TCHAR * buf = new TCHAR[len + 1]; + SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETTEXT, n, (LPARAM)buf); + SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_ADDSTRING, 0, (LPARAM)buf); + delete[]buf; + SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_DELETESTRING, n, 0); } } break; + case ID_REMOVE: - { - WPARAM n = (WPARAM)SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETCURSEL, 0, 0); - if(LB_ERR != n) { - size_t len = SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETTEXTLEN, n, 0); - if(LB_ERR != len) { - TCHAR * buf = new TCHAR[len + 1]; - SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETTEXT, n, (LPARAM)buf); - SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_ADDSTRING, 0, (LPARAM)buf); - delete []buf; - SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_DELETESTRING, n, 0); - } + n = (WPARAM)SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETCURSEL, 0, 0); + if (LB_ERR != n) { + size_t len = SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETTEXTLEN, n, 0); + if (LB_ERR != len) { + TCHAR * buf = new TCHAR[len + 1]; + SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETTEXT, n, (LPARAM)buf); + SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_ADDSTRING, 0, (LPARAM)buf); + delete[]buf; + SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_DELETESTRING, n, 0); } } break; + case ID_ADDALL: - for(;;) - { + for (;;) { LRESULT count = SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETCOUNT, 0, 0); - if(!count || LB_ERR == count) + if (!count || LB_ERR == count) break; SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_SETCURSEL, 0, 0); SendMessage(hwnd, WM_COMMAND, ID_ADD, 0); } break; + case ID_REMOVEALL: - for(;;) - { + for (;;) { LRESULT count = SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETCOUNT, 0, 0); - if(!count || LB_ERR == count) + if (!count || LB_ERR == count) break; SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_SETCURSEL, 0, 0); SendMessage(hwnd, WM_COMMAND, ID_REMOVE, 0); } break; + default: return FALSE; } SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); return TRUE; + case WM_NOTIFY: - { - NMHDR* nmhdr = (NMHDR*)lParam; - switch (nmhdr->code) - { - case PSN_APPLY: - { - LRESULT count = SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETCOUNT, 0, 0); - std::ostringstream out; - for(int i = 0; i < count; ++i) { - size_t len = SendDlgItemMessageA(hwnd, ID_USEDPROTO, LB_GETTEXTLEN, i, 0); - if(LB_ERR != len) { - char * buf = new char[len + 1]; - SendDlgItemMessageA(hwnd, ID_USEDPROTO, LB_GETTEXT, i, (LPARAM)buf); - out << buf << "\r\n"; - delete []buf; - } - } - db_set_s(NULL, pluginName, "protoList", out.str().c_str()); + NMHDR* nmhdr = (NMHDR*)lParam; + switch (nmhdr->code) { + case PSN_APPLY: + LRESULT count = SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETCOUNT, 0, 0); + std::ostringstream out; + for (int i = 0; i < count; ++i) { + size_t len = SendDlgItemMessageA(hwnd, ID_USEDPROTO, LB_GETTEXTLEN, i, 0); + if (LB_ERR != len) { + char * buf = new char[len + 1]; + SendDlgItemMessageA(hwnd, ID_USEDPROTO, LB_GETTEXT, i, (LPARAM)buf); + out << buf << "\r\n"; + delete[]buf; } - return TRUE; } + db_set_s(NULL, pluginName, "protoList", out.str().c_str()); + return TRUE; } break; } @@ -244,12 +219,12 @@ INT_PTR CALLBACK ProtoDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwnd); CheckDlgButton(hwnd, IDC_INVIS_DISABLE, gbInvisDisable ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwnd, IDC_CASE_INSENSITIVE, gbCaseInsensitive ? BST_CHECKED : BST_UNCHECKED); - gbDosServiceExist?EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION),1):EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION),0); + gbDosServiceExist ? EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION), 1) : EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION), 0); CheckDlgButton(hwnd, ID_DOS_INTEGRATION, gbDosServiceIntegration ? BST_CHECKED : BST_UNCHECKED); SetDlgItemText(hwnd, ID_SPECIALGROUPNAME, gbSpammersGroup.c_str()); CheckDlgButton(hwnd, ID_SPECIALGROUP, gbSpecialGroup ? BST_CHECKED : BST_UNCHECKED); @@ -273,13 +248,13 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar MessageBox(hwnd, TranslateT("If math expression is turned on, you can use following expression in message text:\nXX+XX-X/X*X\neach X will be replaced by one random number and answer will be expression result.\nMessage must contain only one expression without spaces."), TranslateT("Info"), MB_OK); break; - case IDC_INVIS_DISABLE: - case IDC_CASE_INSENSITIVE: + case IDC_INVIS_DISABLE: + case IDC_CASE_INSENSITIVE: case ID_DOS_INTEGRATION: - case ID_SPECIALGROUPNAME: - case ID_SPECIALGROUP: - case ID_EXCLUDE: - case ID_REMOVE_TMP: + case ID_SPECIALGROUPNAME: + case ID_SPECIALGROUP: + case ID_EXCLUDE: + case ID_REMOVE_TMP: case ID_REMOVE_TMP_ALL: case ID_IGNOREURL: case IDC_AUTOAUTH: @@ -299,52 +274,50 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar case PSN_APPLY: db_set_b(NULL, pluginName, "CaseInsensitive", gbCaseInsensitive = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_CASE_INSENSITIVE)); db_set_b(NULL, pluginName, "DisableInInvis", gbInvisDisable = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_INVIS_DISABLE)); - db_set_b(NULL, pluginName, "DOSIntegration", gbDosServiceIntegration = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_DOS_INTEGRATION)); + db_set_b(NULL, pluginName, "DOSIntegration", gbDosServiceIntegration = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_DOS_INTEGRATION)); { static tstring NewGroupName, CurrentGroupName; NewGroupName = GetDlgItemString(hwnd, ID_SPECIALGROUPNAME); CurrentGroupName = gbSpammersGroup = DBGetContactSettingStringPAN(NULL, pluginName, "SpammersGroup", _T("0")); if (mir_wstrcmp(CurrentGroupName.c_str(), NewGroupName.c_str()) != 0) { bool GroupExist = Clist_GroupExists(NewGroupName.c_str()) != NULL; - db_set_ws(NULL,pluginName, "SpammersGroup", NewGroupName.c_str()); - gbSpammersGroup = DBGetContactSettingStringPAN(NULL,pluginName,"SpammersGroup", _T("Spammers")); - if(!GroupExist && gbSpecialGroup) + db_set_ws(NULL, pluginName, "SpammersGroup", NewGroupName.c_str()); + gbSpammersGroup = DBGetContactSettingStringPAN(NULL, pluginName, "SpammersGroup", _T("Spammers")); + if (!GroupExist && gbSpecialGroup) CreateCListGroup((TCHAR*)gbSpammersGroup.c_str()); } } - db_set_b(NULL, pluginName, "SpecialGroup", gbSpecialGroup = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_SPECIALGROUP)); - db_set_b(NULL, pluginName, "ExcludeContacts", gbExclude = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_EXCLUDE)); - db_set_b(NULL, pluginName, "DelExcluded", gbDelExcluded = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_REMOVE_TMP)); - db_set_b(NULL, pluginName, "DelAllTempory", gbDelAllTempory = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_REMOVE_TMP_ALL)); - db_set_b(NULL, pluginName, "IgnoreURL", gbIgnoreURL = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_IGNOREURL)); - - db_set_b(NULL, pluginName, "AutoAuth", gbAutoAuth = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_AUTOAUTH)); - db_set_b(NULL, pluginName, "AutoAddToServerList", gbAutoAddToServerList = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_ADDTOSRVLST)); - db_set_b(NULL, pluginName, "AutoReqAuth", gbAutoReqAuth = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_REQAUTH)); - db_set_b(NULL, pluginName, "RegexMatch", gbRegexMatch = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_REGEX)); - db_set_b(NULL, pluginName, "HistoryLog", gbHistoryLog = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_HISTORY_LOG)); - db_set_b(NULL, pluginName, "MathExpression", gbMathExpression = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_MATH_QUESTION)); + db_set_b(NULL, pluginName, "SpecialGroup", gbSpecialGroup = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_SPECIALGROUP)); + db_set_b(NULL, pluginName, "ExcludeContacts", gbExclude = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_EXCLUDE)); + db_set_b(NULL, pluginName, "DelExcluded", gbDelExcluded = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_REMOVE_TMP)); + db_set_b(NULL, pluginName, "DelAllTempory", gbDelAllTempory = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_REMOVE_TMP_ALL)); + db_set_b(NULL, pluginName, "IgnoreURL", gbIgnoreURL = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_IGNOREURL)); + db_set_b(NULL, pluginName, "AutoAuth", gbAutoAuth = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_AUTOAUTH)); + db_set_b(NULL, pluginName, "AutoAddToServerList", gbAutoAddToServerList = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_ADDTOSRVLST)); + db_set_b(NULL, pluginName, "AutoReqAuth", gbAutoReqAuth = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_REQAUTH)); + db_set_b(NULL, pluginName, "RegexMatch", gbRegexMatch = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_REGEX)); + db_set_b(NULL, pluginName, "HistoryLog", gbHistoryLog = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_HISTORY_LOG)); + db_set_b(NULL, pluginName, "MathExpression", gbMathExpression = BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_MATH_QUESTION)); { static tstring NewAGroupName, CurrentAGroupName; NewAGroupName = GetDlgItemString(hwnd, IDC_AUTOADDGROUP); CurrentAGroupName = gbAutoAuthGroup = DBGetContactSettingStringPAN(NULL, pluginName, "AutoAuthGroup", _T("0")); if (mir_wstrcmp(CurrentAGroupName.c_str(), NewAGroupName.c_str()) != 0) { bool GroupExist = Clist_GroupExists(NewAGroupName.c_str()) != NULL; - db_set_ws(NULL,pluginName, "AutoAuthGroup", NewAGroupName.c_str()); - gbAutoAuthGroup = DBGetContactSettingStringPAN(NULL,pluginName,"AutoAuthGroup", _T("Not Spammers")); - if(!GroupExist && gbAutoAddToServerList) + db_set_ws(NULL, pluginName, "AutoAuthGroup", NewAGroupName.c_str()); + gbAutoAuthGroup = DBGetContactSettingStringPAN(NULL, pluginName, "AutoAuthGroup", _T("Not Spammers")); + if (!GroupExist && gbAutoAddToServerList) CreateCListGroup((TCHAR*)gbAutoAuthGroup.c_str()); } } return TRUE; } - break; + break; } return FALSE; } - HINSTANCE hInst; MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l) { diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index bbbc910ed0..2cad3a82a6 100755 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -15,17 +15,16 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include "stdafx.h" tstring DBGetContactSettingStringPAN(MCONTACT hContact, char const * szModule, char const * szSetting, tstring errorValue) { DBVARIANT dbv; //if(db_get(hContact, szModule, szSetting, &dbv)) - if(db_get_ts(hContact, szModule, szSetting, &dbv)) + if (db_get_ts(hContact, szModule, szSetting, &dbv)) return errorValue; -// if(DBVT_TCHAR == dbv.type ) - errorValue = dbv.ptszVal; + // if(DBVT_TCHAR == dbv.type ) + errorValue = dbv.ptszVal; db_free(&dbv); return errorValue; } @@ -34,10 +33,10 @@ std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const * szMod { DBVARIANT dbv; //if(db_get(hContact, szModule, szSetting, &dbv)) - if(db_get_s(hContact, szModule, szSetting, &dbv)) + if (db_get_s(hContact, szModule, szSetting, &dbv)) return errorValue; -// if(DBVT_ASCIIZ == dbv.type ) - errorValue = dbv.pszVal; + // if(DBVT_ASCIIZ == dbv.type ) + errorValue = dbv.pszVal; db_free(&dbv); return errorValue; } @@ -50,7 +49,7 @@ tstring &GetDlgItemString(HWND hwnd, int id) GetWindowText(h, buf, len + 1); static tstring s; s = buf; - delete []buf; + delete[]buf; return s; } @@ -78,26 +77,27 @@ int CreateCListGroup(TCHAR* szGroupName) void DeleteCListGroupsByName(TCHAR* szGroupName) { BYTE ConfirmDelete = db_get_b(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT); - if(ConfirmDelete) + if (ConfirmDelete) db_set_b(NULL, "CList", "ConfirmDelete", 0); TCHAR *szGroup; - for (int i=1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) - if( !mir_wstrcmp(szGroupName, szGroup)) + for (int i = 1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) + if (!mir_wstrcmp(szGroupName, szGroup)) CallService(MS_CLIST_GROUPDELETE, i, 0); - if(ConfirmDelete) + if (ConfirmDelete) db_set_b(NULL, "CList", "ConfirmDelete", ConfirmDelete); } -int RemoveTmp(WPARAM,LPARAM) +int RemoveTmp(WPARAM, LPARAM) { void CleanThread(); CleanThread(); return 0; } -tstring variables_parse(tstring const &tstrFormat, MCONTACT hContact){ +tstring variables_parse(tstring const &tstrFormat, MCONTACT hContact) +{ if (gbVarsServiceExist) { FORMATINFO fi; TCHAR *tszParsed; @@ -142,27 +142,25 @@ const int Stricmp(const TCHAR *str, const TCHAR *substr) TCHAR* ReqGetText(DBEVENTINFO* dbei) { - if ( !dbei->pBlob ) + if (!dbei->pBlob) return 0; - char * ptr=(char *)&dbei->pBlob[sizeof(DWORD)*2]; - int len=dbei->cbBlob-sizeof(DWORD)*2; - int i=0; + char * ptr = (char *)&dbei->pBlob[sizeof(DWORD) * 2]; + int len = dbei->cbBlob - sizeof(DWORD) * 2; + int i = 0; - while(len && (i<4)) - { - if(!ptr[0]) i++; + while (len && (i < 4)) { + if (!ptr[0]) i++; ptr++; len--; }; - if(len) - { - char * tstr=(char *)mir_alloc(len+1); + if (len) { + char * tstr = (char *)mir_alloc(len + 1); memcpy(tstr, ptr, len); - tstr[len]=0; + tstr[len] = 0; WCHAR* msg = NULL; - msg=(dbei->flags&DBEF_UTF)?mir_utf8decodeW(tstr):mir_a2u(tstr); + msg = (dbei->flags&DBEF_UTF) ? mir_utf8decodeW(tstr) : mir_a2u(tstr); mir_free(tstr); return (TCHAR *)msg; }; @@ -171,8 +169,8 @@ TCHAR* ReqGetText(DBEVENTINFO* dbei) BOOL IsUrlContains(TCHAR * Str) { - const int CountUrl=11; - const TCHAR URL[CountUrl][5]= + const int CountUrl = 11; + const TCHAR URL[CountUrl][5] = { L"http", L"www", @@ -187,12 +185,11 @@ BOOL IsUrlContains(TCHAR * Str) L".tv" }; - if(Str && mir_tstrlen(Str)>0) { + if (Str && mir_tstrlen(Str) > 0) { TCHAR *StrLower = NEWTSTR_MALLOC(Str); CharLowerBuff(StrLower, (int)mir_tstrlen(StrLower)); - for (int i=0; ipfnGetContactDisplayName(hContact, 0); - LogContactId=(LogProtocol==_T(""))?_T(""):GetContactUid(hContact,LogProtocol); + LogProtocol = DBGetContactSettingStringPAN(hContact, "Protocol", "p", _T("")); + LogContactName = (TCHAR*)pcli->pfnGetContactDisplayName(hContact, 0); + LogContactId = (LogProtocol == _T("")) ? _T("") : GetContactUid(hContact, LogProtocol); // Name, UID and Protocol Log line - LogStrW=_T("[")+LogTime.substr(0,LogTime.length()-1)+_T("] ")+ - LogContactId+_T(" - ")+ - LogContactName+_T(" (")+ - LogProtocol+_T("): ")+ - message+_T("\n"); + LogStrW = _T("[") + LogTime.substr(0, LogTime.length() - 1) + _T("] ") + + LogContactId + _T(" - ") + + LogContactName + _T(" (") + + LogProtocol + _T("): ") + + message + _T("\n"); - char * buf=mir_u2a(LogStrW.c_str()); - file.write(buf,LogStrW.length()); + char *buf = mir_u2a(LogStrW.c_str()); + file.write(buf, LogStrW.length()); mir_free(buf); file.close(); @@ -285,24 +280,22 @@ boost::mutex clean_mutex; void CleanProtocolTmpThread(std::string proto) { - while(true) - { + while (true) { UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); - if(status > ID_STATUS_OFFLINE) + if (status > ID_STATUS_OFFLINE) break; boost::this_thread::sleep(boost::posix_time::seconds(2)); } std::list contacts; - for(MCONTACT hContact = db_find_first(proto.c_str()); hContact; hContact = db_find_next(hContact, proto.c_str())) - if(db_get_b(hContact, "CList", "NotOnList", 0)|| (_T("Not In List")== DBGetContactSettingStringPAN(hContact,"CList","Group",_T("")))) + for (MCONTACT hContact = db_find_first(proto.c_str()); hContact; hContact = db_find_next(hContact, proto.c_str())) + if (db_get_b(hContact, "CList", "NotOnList", 0) || (_T("Not In List") == DBGetContactSettingStringPAN(hContact, "CList", "Group", _T("")))) contacts.push_back(hContact); boost::this_thread::sleep(boost::posix_time::seconds(5)); clean_mutex.lock(); std::list::iterator end = contacts.end(); - for(std::list::iterator i = contacts.begin(); i != end; ++i) - { + for (std::list::iterator i = contacts.begin(); i != end; ++i) { LogSpamToFile(*i, _T("Deleted")); HistoryLogFunc(*i, "Deleted"); CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0); @@ -312,24 +305,22 @@ void CleanProtocolTmpThread(std::string proto) void CleanProtocolExclThread(std::string proto) { - while(true) - { + while (true) { UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); - if(status > ID_STATUS_OFFLINE) + if (status > ID_STATUS_OFFLINE) break; boost::this_thread::sleep(boost::posix_time::seconds(2)); } std::list contacts; - for(MCONTACT hContact = db_find_first(proto.c_str()); hContact; hContact = db_find_next(hContact, proto.c_str())) - if(db_get_b(hContact, "CList", "NotOnList", 0) && db_get_b(hContact, pluginName, "Excluded", 0)) + for (MCONTACT hContact = db_find_first(proto.c_str()); hContact; hContact = db_find_next(hContact, proto.c_str())) + if (db_get_b(hContact, "CList", "NotOnList", 0) && db_get_b(hContact, pluginName, "Excluded", 0)) contacts.push_back(hContact); boost::this_thread::sleep(boost::posix_time::seconds(5)); clean_mutex.lock(); std::list::iterator end = contacts.end(); - for(std::list::iterator i = contacts.begin(); i != end; ++i) - { + for (std::list::iterator i = contacts.begin(); i != end; ++i) { LogSpamToFile(*i, _T("Deleted")); HistoryLogFunc(*i, "Deleted"); CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0); @@ -343,17 +334,15 @@ void CleanThread() int count = 0; PROTOACCOUNT **accounts; Proto_EnumAccounts(&count, &accounts); - for(int i = 0; i < count; i++) - { - if(!strstr(accounts[i]->szModuleName, "MetaContacts") && !strstr(accounts[i]->szModuleName, "Weather")) //not real protocols + for (int i = 0; i < count; i++) + if (!strstr(accounts[i]->szModuleName, "MetaContacts") && !strstr(accounts[i]->szModuleName, "Weather")) //not real protocols protocols.push_back(accounts[i]->szModuleName); - } + std::list::iterator end = protocols.end(); - for(std::list::iterator i = protocols.begin(); i != end; ++i) - { - if(gbDelAllTempory) + for (std::list::iterator i = protocols.begin(); i != end; ++i) { + if (gbDelAllTempory) new boost::thread(boost::bind(&CleanProtocolTmpThread, *i)); - if(gbDelExcluded) + if (gbDelExcluded) new boost::thread(boost::bind(&CleanProtocolExclThread, *i)); } } @@ -365,23 +354,22 @@ void HistoryLog(MCONTACT hContact, char *data, int event_type, int flags) Event.eventType = event_type; Event.flags = flags | DBEF_UTF; Event.timestamp = (DWORD)time(NULL); - Event.cbBlob = (DWORD)mir_strlen(data)+1; + Event.cbBlob = (DWORD)mir_strlen(data) + 1; Event.pBlob = (PBYTE)_strdup(data); db_event_add(hContact, &Event); } void HistoryLogFunc(MCONTACT hContact, std::string message) { - if(gbHistoryLog) - { - if(hContact == INVALID_CONTACT_ID) + if (gbHistoryLog) { + if (hContact == INVALID_CONTACT_ID) return; std::string msg = message; msg.append("\n"); msg.append("Protocol: ").append(GetContactProto(hContact)).append(" Contact: "); msg.append(toUTF8((TCHAR*)pcli->pfnGetContactDisplayName(hContact, 0))).append(" ID: "); - msg.append(toUTF8(GetContactUid(hContact,toUTF16(GetContactProto(hContact))))); + msg.append(toUTF8(GetContactUid(hContact, toUTF16(GetContactProto(hContact))))); HistoryLog(NULL, (char*)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ); } } @@ -389,11 +377,10 @@ void HistoryLogFunc(MCONTACT hContact, std::string message) std::string toUTF8(std::wstring str) { std::string ustr; - try{ - utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); + try { + utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); } - catch(const std::exception&) - { + catch (const std::exception&) { //TODO: handle utf8cpp exceptions } return ustr; @@ -408,12 +395,11 @@ std::wstring toUTF16(std::string str) //convert as much as possible { std::wstring ustr; std::string tmpstr; - try{ - utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); - utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); + try { + utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); + utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); } - catch(const std::exception &) - { + catch (const std::exception &) { //TODO: handle utf8cpp exceptions } return ustr; @@ -424,8 +410,8 @@ std::string get_random_num(int length) std::string chars("123456789"); std::string data; boost::random_device rng; - boost::variate_generator> gen(rng, boost::uniform_int<>(0, (int)chars.length()-1)); - for(int i = 0; i < length; ++i) + boost::variate_generator> gen(rng, boost::uniform_int<>(0, (int)chars.length() - 1)); + for (int i = 0; i < length; ++i) data += chars[gen()]; return data; } -- cgit v1.2.3