diff options
Diffstat (limited to 'plugins/StopSpamMod')
-rwxr-xr-x | plugins/StopSpamMod/src/options.cpp | 802 | ||||
-rwxr-xr-x | plugins/StopSpamMod/src/utilities.cpp | 873 |
2 files changed, 820 insertions, 855 deletions
diff --git a/plugins/StopSpamMod/src/options.cpp b/plugins/StopSpamMod/src/options.cpp index c38dd8f771..4205a6a19b 100755 --- a/plugins/StopSpamMod/src/options.cpp +++ b/plugins/StopSpamMod/src/options.cpp @@ -1,414 +1,388 @@ -/* Copyright (C) Miklashevsky Roman, sss, elzor -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "headers.h" - -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) - { - case WM_INITDIALOG: - { - SetDlgItemTextA(hwnd, ID_DESCRIPTION, pluginDescription); - TranslateDialogDefault(hwnd); - SetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, gbMaxQuestCount, FALSE); - SendDlgItemMessage(hwnd, ID_INFTALKPROT, BM_SETCHECK, gbInfTalkProtection ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_ADDPERMANENT, BM_SETCHECK, gbAddPermanent ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_HANDLEAUTHREQ, BM_SETCHECK, gbHandleAuthReq ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_HIDECONTACTS, BM_SETCHECK, gbHideContacts ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_IGNORESPAMMERS, BM_SETCHECK, gbIgnoreContacts ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_LOGSPAMTOFILE, BM_SETCHECK, gbLogToFile ? BST_CHECKED : BST_UNCHECKED, 0); - } - return TRUE; - case WM_COMMAND:{ - switch (LOWORD(wParam)) - { - case ID_MAXQUESTCOUNT: - { - 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) - { - 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 == SendDlgItemMessage(hwnd, ID_INFTALKPROT, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "addPermanent", gbAddPermanent = BST_CHECKED == SendDlgItemMessage(hwnd, ID_ADDPERMANENT, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "handleAuthReq", gbHandleAuthReq = BST_CHECKED == SendDlgItemMessage(hwnd, ID_HANDLEAUTHREQ, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "HideContacts", gbHideContacts = BST_CHECKED == SendDlgItemMessage(hwnd, ID_HIDECONTACTS, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "IgnoreContacts", gbIgnoreContacts = BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNORESPAMMERS, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "LogSpamToFile", gbLogToFile = BST_CHECKED == SendDlgItemMessage(hwnd, ID_LOGSPAMTOFILE, BM_GETCHECK, 0, 0)); - } - return TRUE; - } - } - break; - } - return FALSE; -} - -INT_PTR CALLBACK MessagesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - - 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); - } - 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, TranslateT("nospam")); - SetDlgItemText(hwnd, ID_AUTHREPL, TranslateT("StopSpam: send a message and reply to a 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", TranslateT("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 a 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; - } - return FALSE; -} - -INT_PTR CALLBACK ProtoDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch(msg) - { - case WM_INITDIALOG: - { - TranslateDialogDefault(hwnd); - int n; - PROTOACCOUNT **pppd; - if(!ProtoEnumAccounts(&n, &pppd)) - for (int i = 0; i < n; ++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)) - { - 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); - } - } - } - 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); - } - } - } - break; - case ID_ADDALL: - for(;;) - { - LRESULT count = SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETCOUNT, 0, 0); - 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(;;) - { - LRESULT count = SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETCOUNT, 0, 0); - 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()); - } - return TRUE; - } - } - break; - } - return FALSE; -} - -INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch(msg) - { - case WM_INITDIALOG: { - TranslateDialogDefault(hwnd); - SendDlgItemMessage(hwnd, IDC_INVIS_DISABLE, BM_SETCHECK, gbInvisDisable ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, IDC_CASE_INSENSITIVE, BM_SETCHECK, gbCaseInsensitive ? BST_CHECKED : BST_UNCHECKED, 0); - gbDosServiceExist?EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION),1):EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION),0); - SendDlgItemMessage(hwnd, ID_DOS_INTEGRATION, BM_SETCHECK, gbDosServiceIntegration ? BST_CHECKED : BST_UNCHECKED, 0); - SetDlgItemText(hwnd, ID_SPECIALGROUPNAME, gbSpammersGroup.c_str()); - SendDlgItemMessage(hwnd, ID_SPECIALGROUP, BM_SETCHECK, gbSpecialGroup ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_EXCLUDE, BM_SETCHECK, gbExclude ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_REMOVE_TMP, BM_SETCHECK, gbDelExcluded ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_REMOVE_TMP_ALL, BM_SETCHECK, gbDelAllTempory ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, ID_IGNOREURL, BM_SETCHECK, gbIgnoreURL ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, IDC_AUTOAUTH, BM_SETCHECK, gbAutoAuth ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, IDC_ADDTOSRVLST, BM_SETCHECK, gbAutoAddToServerList ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, IDC_REQAUTH, BM_SETCHECK, gbAutoReqAuth ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, IDC_REGEX, BM_SETCHECK, gbRegexMatch ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_SETCHECK, gbHistoryLog ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage(hwnd, IDC_MATH_QUESTION, BM_SETCHECK, gbMathExpression ? BST_CHECKED : BST_UNCHECKED, 0 ); - - SetDlgItemText(hwnd, IDC_AUTOADDGROUP, gbAutoAuthGroup.c_str()); - } - return TRUE; - case WM_COMMAND: { - switch (LOWORD(wParam)) - { - case IDC_MATH_DETAILS: { - 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 ID_DOS_INTEGRATION: - case ID_SPECIALGROUPNAME: - case ID_SPECIALGROUP: - case ID_EXCLUDE: - case ID_REMOVE_TMP: - case ID_REMOVE_TMP_ALL: - case ID_IGNOREURL: - case IDC_AUTOAUTH: - case IDC_ADDTOSRVLST: - case IDC_REQAUTH: - case IDC_AUTOADDGROUP: - case IDC_REGEX: - case IDC_HISTORY_LOG: - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - break; - } - } - break; - case WM_NOTIFY: { - NMHDR* nmhdr = (NMHDR*)lParam; - switch (nmhdr->code) - { - case PSN_APPLY: { - db_set_b(NULL, pluginName, "CaseInsensitive", gbCaseInsensitive = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_CASE_INSENSITIVE, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "DisableInInvis", gbInvisDisable = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_INVIS_DISABLE, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "DOSIntegration", gbDosServiceIntegration = BST_CHECKED == SendDlgItemMessage(hwnd, ID_DOS_INTEGRATION, BM_GETCHECK, 0, 0)); - { - static tstring NewGroupName, CurrentGroupName; - NewGroupName = GetDlgItemString(hwnd, ID_SPECIALGROUPNAME); - CurrentGroupName = gbSpammersGroup = DBGetContactSettingStringPAN(NULL, pluginName, "SpammersGroup", _T("0")); - if (wcscmp(CurrentGroupName.c_str(), NewGroupName.c_str()) != 0) { - int GroupNumber = 0; - BYTE GroupExist = 0; - TCHAR szValue[96] = {0}; - char szNumber[32] = {0}; - extern int CreateCListGroup(TCHAR* szGroupName); - strcpy(szNumber, "0"); - while (strcmp(DBGetContactSettingStringPAN_A(NULL, "CListGroups", szNumber, "0").c_str(), "0") != 0) { - _itoa(GroupNumber, szNumber, 10); - wcscpy(szValue, DBGetContactSettingStringPAN(NULL, "CListGroups", szNumber, _T("0")).c_str()); - if (wcscmp(NewGroupName.c_str(), szValue + 1) == 0) { - GroupExist = 1; - break; - } - GroupNumber++; - } - 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 == SendDlgItemMessage(hwnd, ID_SPECIALGROUP, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "ExcludeContacts", gbExclude = BST_CHECKED == SendDlgItemMessage(hwnd, ID_EXCLUDE, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "DelExcluded", gbDelExcluded = BST_CHECKED == SendDlgItemMessage(hwnd, ID_REMOVE_TMP, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "DelAllTempory", gbDelAllTempory = BST_CHECKED == SendDlgItemMessage(hwnd, ID_REMOVE_TMP_ALL, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "IgnoreURL", gbIgnoreURL = BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNOREURL, BM_GETCHECK, 0, 0)); - - db_set_b(NULL, pluginName, "AutoAuth", gbAutoAuth = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_AUTOAUTH, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "AutoAddToServerList", gbAutoAddToServerList = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_ADDTOSRVLST, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "AutoReqAuth", gbAutoReqAuth = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REQAUTH, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "RegexMatch", gbRegexMatch = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REGEX, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "HistoryLog", gbHistoryLog = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_GETCHECK, 0, 0)); - db_set_b(NULL, pluginName, "MathExpression", gbMathExpression = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_MATH_QUESTION, BM_GETCHECK, 0, 0)); - - { - static tstring NewAGroupName, CurrentAGroupName; - NewAGroupName = GetDlgItemString(hwnd, IDC_AUTOADDGROUP); - CurrentAGroupName = gbAutoAuthGroup = DBGetContactSettingStringPAN(NULL, pluginName, "AutoAuthGroup", _T("0")); - if (wcscmp(CurrentAGroupName.c_str(), NewAGroupName.c_str()) != 0) { - int GroupNumber = 0; - BYTE GroupExist = 0; - TCHAR szValue[96] = {0}; - char szNumber[32] = {0}; - extern int CreateCListGroup(TCHAR* szGroupName); - strcpy(szNumber, "0"); - while (strcmp(DBGetContactSettingStringPAN_A(NULL, "CListGroups", szNumber, "0").c_str(), "0") != 0) { - _itoa(GroupNumber, szNumber, 10); - wcscpy(szValue, DBGetContactSettingStringPAN(NULL, "CListGroups", szNumber, _T("0")).c_str()); - if (wcscmp(NewAGroupName.c_str(), szValue + 1) == 0) { - GroupExist = 1; - break; - } - GroupNumber++; - } - 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; - } - return FALSE; -} - - -HINSTANCE hInst; -MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l) -{ - OPTIONSDIALOGPAGE odp = {0}; - odp.cbSize = sizeof(odp); - odp.ptszGroup = LPGENT("Message Sessions"); - odp.ptszTitle = LPGENT("StopSpam"); - odp.position = -1; - odp.hInstance = hInst; - odp.flags = ODPF_TCHAR; - - odp.ptszTab = LPGENT("General"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAIN); - odp.pfnDlgProc = MainDlgProc; - Options_AddPage(w, &odp); - - - odp.ptszTab = LPGENT("Messages"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_MESSAGES); - odp.pfnDlgProc = MessagesDlgProc; - Options_AddPage(w, &odp); - - odp.ptszTab = LPGENT("Accounts"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROTO); - odp.pfnDlgProc = ProtoDlgProc; - Options_AddPage(w, &odp); - - odp.ptszTab = LPGENT("Advanced"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_ADVANCED); - odp.pfnDlgProc = AdvancedDlgProc; - Options_AddPage(w, &odp); - - return 0; -} +/* Copyright (C) Miklashevsky Roman, sss, elzor
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "headers.h"
+
+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.");
+
+INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg)
+ {
+ case WM_INITDIALOG:
+ {
+ SetDlgItemTextA(hwnd, ID_DESCRIPTION, pluginDescription);
+ TranslateDialogDefault(hwnd);
+ SetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, gbMaxQuestCount, FALSE);
+ SendDlgItemMessage(hwnd, ID_INFTALKPROT, BM_SETCHECK, gbInfTalkProtection ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_ADDPERMANENT, BM_SETCHECK, gbAddPermanent ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_HANDLEAUTHREQ, BM_SETCHECK, gbHandleAuthReq ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_HIDECONTACTS, BM_SETCHECK, gbHideContacts ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_IGNORESPAMMERS, BM_SETCHECK, gbIgnoreContacts ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_LOGSPAMTOFILE, BM_SETCHECK, gbLogToFile ? BST_CHECKED : BST_UNCHECKED, 0);
+ }
+ return TRUE;
+ case WM_COMMAND:{
+ switch (LOWORD(wParam))
+ {
+ case ID_MAXQUESTCOUNT:
+ {
+ 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)
+ {
+ 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 == SendDlgItemMessage(hwnd, ID_INFTALKPROT, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "addPermanent", gbAddPermanent = BST_CHECKED == SendDlgItemMessage(hwnd, ID_ADDPERMANENT, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "handleAuthReq", gbHandleAuthReq = BST_CHECKED == SendDlgItemMessage(hwnd, ID_HANDLEAUTHREQ, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "HideContacts", gbHideContacts = BST_CHECKED == SendDlgItemMessage(hwnd, ID_HIDECONTACTS, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "IgnoreContacts", gbIgnoreContacts = BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNORESPAMMERS, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "LogSpamToFile", gbLogToFile = BST_CHECKED == SendDlgItemMessage(hwnd, ID_LOGSPAMTOFILE, BM_GETCHECK, 0, 0));
+ }
+ return TRUE;
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+INT_PTR CALLBACK MessagesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+
+ 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);
+ }
+ 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, TranslateT("nospam"));
+ SetDlgItemText(hwnd, ID_AUTHREPL, TranslateT("StopSpam: send a message and reply to a 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", TranslateT("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 a 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;
+ }
+ return FALSE;
+}
+
+INT_PTR CALLBACK ProtoDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg)
+ {
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwnd);
+ int n;
+ PROTOACCOUNT **pppd;
+ if(!ProtoEnumAccounts(&n, &pppd))
+ for (int i = 0; i < n; ++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))
+ {
+ 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);
+ }
+ }
+ }
+ 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);
+ }
+ }
+ }
+ break;
+ case ID_ADDALL:
+ for(;;)
+ {
+ LRESULT count = SendDlgItemMessage(hwnd, ID_ALLPROTO, LB_GETCOUNT, 0, 0);
+ 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(;;)
+ {
+ LRESULT count = SendDlgItemMessage(hwnd, ID_USEDPROTO, LB_GETCOUNT, 0, 0);
+ 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());
+ }
+ return TRUE;
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg)
+ {
+ case WM_INITDIALOG: {
+ TranslateDialogDefault(hwnd);
+ SendDlgItemMessage(hwnd, IDC_INVIS_DISABLE, BM_SETCHECK, gbInvisDisable ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, IDC_CASE_INSENSITIVE, BM_SETCHECK, gbCaseInsensitive ? BST_CHECKED : BST_UNCHECKED, 0);
+ gbDosServiceExist?EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION),1):EnableWindow(GetDlgItem(hwnd, ID_DOS_INTEGRATION),0);
+ SendDlgItemMessage(hwnd, ID_DOS_INTEGRATION, BM_SETCHECK, gbDosServiceIntegration ? BST_CHECKED : BST_UNCHECKED, 0);
+ SetDlgItemText(hwnd, ID_SPECIALGROUPNAME, gbSpammersGroup.c_str());
+ SendDlgItemMessage(hwnd, ID_SPECIALGROUP, BM_SETCHECK, gbSpecialGroup ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_EXCLUDE, BM_SETCHECK, gbExclude ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_REMOVE_TMP, BM_SETCHECK, gbDelExcluded ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_REMOVE_TMP_ALL, BM_SETCHECK, gbDelAllTempory ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, ID_IGNOREURL, BM_SETCHECK, gbIgnoreURL ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, IDC_AUTOAUTH, BM_SETCHECK, gbAutoAuth ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, IDC_ADDTOSRVLST, BM_SETCHECK, gbAutoAddToServerList ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, IDC_REQAUTH, BM_SETCHECK, gbAutoReqAuth ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, IDC_REGEX, BM_SETCHECK, gbRegexMatch ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_SETCHECK, gbHistoryLog ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendDlgItemMessage(hwnd, IDC_MATH_QUESTION, BM_SETCHECK, gbMathExpression ? BST_CHECKED : BST_UNCHECKED, 0 );
+
+ SetDlgItemText(hwnd, IDC_AUTOADDGROUP, gbAutoAuthGroup.c_str());
+ }
+ return TRUE;
+ case WM_COMMAND: {
+ switch (LOWORD(wParam))
+ {
+ case IDC_MATH_DETAILS: {
+ 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 ID_DOS_INTEGRATION:
+ case ID_SPECIALGROUPNAME:
+ case ID_SPECIALGROUP:
+ case ID_EXCLUDE:
+ case ID_REMOVE_TMP:
+ case ID_REMOVE_TMP_ALL:
+ case ID_IGNOREURL:
+ case IDC_AUTOAUTH:
+ case IDC_ADDTOSRVLST:
+ case IDC_REQAUTH:
+ case IDC_AUTOADDGROUP:
+ case IDC_REGEX:
+ case IDC_HISTORY_LOG:
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ break;
+ }
+ }
+ break;
+ case WM_NOTIFY: {
+ NMHDR* nmhdr = (NMHDR*)lParam;
+ switch (nmhdr->code)
+ {
+ case PSN_APPLY: {
+ db_set_b(NULL, pluginName, "CaseInsensitive", gbCaseInsensitive = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_CASE_INSENSITIVE, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "DisableInInvis", gbInvisDisable = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_INVIS_DISABLE, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "DOSIntegration", gbDosServiceIntegration = BST_CHECKED == SendDlgItemMessage(hwnd, ID_DOS_INTEGRATION, BM_GETCHECK, 0, 0));
+ {
+ static tstring NewGroupName, CurrentGroupName;
+ NewGroupName = GetDlgItemString(hwnd, ID_SPECIALGROUPNAME);
+ CurrentGroupName = gbSpammersGroup = DBGetContactSettingStringPAN(NULL, pluginName, "SpammersGroup", _T("0"));
+ if (wcscmp(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)
+ CreateCListGroup((TCHAR*)gbSpammersGroup.c_str());
+ }
+ }
+ db_set_b(NULL, pluginName, "SpecialGroup", gbSpecialGroup = BST_CHECKED == SendDlgItemMessage(hwnd, ID_SPECIALGROUP, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "ExcludeContacts", gbExclude = BST_CHECKED == SendDlgItemMessage(hwnd, ID_EXCLUDE, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "DelExcluded", gbDelExcluded = BST_CHECKED == SendDlgItemMessage(hwnd, ID_REMOVE_TMP, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "DelAllTempory", gbDelAllTempory = BST_CHECKED == SendDlgItemMessage(hwnd, ID_REMOVE_TMP_ALL, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "IgnoreURL", gbIgnoreURL = BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNOREURL, BM_GETCHECK, 0, 0));
+
+ db_set_b(NULL, pluginName, "AutoAuth", gbAutoAuth = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_AUTOAUTH, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "AutoAddToServerList", gbAutoAddToServerList = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_ADDTOSRVLST, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "AutoReqAuth", gbAutoReqAuth = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REQAUTH, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "RegexMatch", gbRegexMatch = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REGEX, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "HistoryLog", gbHistoryLog = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_GETCHECK, 0, 0));
+ db_set_b(NULL, pluginName, "MathExpression", gbMathExpression = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_MATH_QUESTION, BM_GETCHECK, 0, 0));
+
+ {
+ static tstring NewAGroupName, CurrentAGroupName;
+ NewAGroupName = GetDlgItemString(hwnd, IDC_AUTOADDGROUP);
+ CurrentAGroupName = gbAutoAuthGroup = DBGetContactSettingStringPAN(NULL, pluginName, "AutoAuthGroup", _T("0"));
+ if (wcscmp(CurrentAGroupName.c_str(), NewAGroupName.c_str()) != 0) {
+ bool GroupExist = Clist_GroupExists(NewAGroupName.c_str());
+ 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;
+ }
+ return FALSE;
+}
+
+
+HINSTANCE hInst;
+MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l)
+{
+ OPTIONSDIALOGPAGE odp = {0};
+ odp.cbSize = sizeof(odp);
+ odp.ptszGroup = LPGENT("Message Sessions");
+ odp.ptszTitle = LPGENT("StopSpam");
+ odp.position = -1;
+ odp.hInstance = hInst;
+ odp.flags = ODPF_TCHAR;
+
+ odp.ptszTab = LPGENT("General");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAIN);
+ odp.pfnDlgProc = MainDlgProc;
+ Options_AddPage(w, &odp);
+
+
+ odp.ptszTab = LPGENT("Messages");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_MESSAGES);
+ odp.pfnDlgProc = MessagesDlgProc;
+ Options_AddPage(w, &odp);
+
+ odp.ptszTab = LPGENT("Accounts");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROTO);
+ odp.pfnDlgProc = ProtoDlgProc;
+ Options_AddPage(w, &odp);
+
+ odp.ptszTab = LPGENT("Advanced");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_ADVANCED);
+ odp.pfnDlgProc = AdvancedDlgProc;
+ Options_AddPage(w, &odp);
+
+ return 0;
+}
diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index 647293687a..46707c67fa 100755 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -1,445 +1,436 @@ -/* Copyright (C) Miklashevsky Roman, sss, elzor -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - - -#include "headers.h" - -tstring DBGetContactSettingStringPAN(HANDLE 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)) - return errorValue; -// if(DBVT_TCHAR == dbv.type ) - errorValue = dbv.ptszVal; - db_free(&dbv); - return errorValue; -} - -std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue) -{ - DBVARIANT dbv; - //if(db_get(hContact, szModule, szSetting, &dbv)) - if(db_get_s(hContact, szModule, szSetting, &dbv)) - return errorValue; -// if(DBVT_ASCIIZ == dbv.type ) - errorValue = dbv.pszVal; - db_free(&dbv); - return errorValue; -} - -tstring &GetDlgItemString(HWND hwnd, int id) -{ - HWND h = GetDlgItem(hwnd, id); - int len = GetWindowTextLength(h); - TCHAR * buf = new TCHAR[len + 1]; - GetWindowText(h, buf, len + 1); - static tstring s; - s = buf; - delete []buf; - return s; -} - -std::string &GetProtoList() -{ - static std::string s; - return s = DBGetContactSettingStringPAN_A(NULL, pluginName, "protoList", "ICQ\r\n"); -} - -bool ProtoInList(std::string proto) -{ - return std::string::npos != GetProtoList().find(proto + "\r\n"); -} - -int CreateCListGroup(TCHAR* szGroupName) -{ - int hGroup = CallService(MS_CLIST_GROUPCREATE, 0, 0); - - TCHAR* usTmp = szGroupName; - pcli->pfnRenameGroup(hGroup, usTmp); - - return hGroup; -} - -void DeleteCListGroupsByName(TCHAR* szGroupName) -{ - int GroupNumber = 0; - TCHAR szValue[96] = {0}; - char szNumber[32] = {0}; - strcpy(szNumber, "0"); - BYTE ConfirmDelete=db_get_b(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT); - if(ConfirmDelete) - db_set_b(NULL, "CList", "ConfirmDelete", 0); - while(strcmp(DBGetContactSettingStringPAN_A(NULL, "CListGroups", szNumber, "0").c_str(), "0") != 0) - { - wcscpy(szValue, DBGetContactSettingStringPAN(NULL, "CListGroups", szNumber, _T("0")).c_str()); - if(wcscmp(szGroupName, szValue + 1) == 0) - CallService(MS_CLIST_GROUPDELETE, (WPARAM)(HANDLE)GroupNumber+1, 0); // bug or ??? @_@ - GroupNumber++; -#if defined(_MSC_VER) && _MSC_VER >= 1300 - _itoa_s(GroupNumber, szNumber, sizeof(szNumber), 10); -#else - _itoa(GroupNumber, szNumber, 10); -#endif - }; - if(ConfirmDelete) - db_set_b(NULL, "CList", "ConfirmDelete", ConfirmDelete); -} - -int RemoveTmp(WPARAM,LPARAM) -{ - void CleanThread(); - CleanThread(); - return 0; -} -tstring variables_parse(tstring const &tstrFormat, HANDLE hContact){ - if (gbVarsServiceExist) { - FORMATINFO fi; - TCHAR *tszParsed; - tstring tstrResult; - - ZeroMemory(&fi, sizeof(fi)); - fi.cbSize = sizeof(fi); - fi.tszFormat = _tcsdup(tstrFormat.c_str()); - fi.hContact = hContact; - fi.flags |= FIF_TCHAR; - tszParsed = (TCHAR *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0); - free(fi.tszFormat); - if (tszParsed) { - tstrResult = tszParsed; - mir_free(tszParsed); - return tstrResult; - } - } - return tstrFormat; -} - -// case-insensitive _tcscmp -//by nullbie as i remember... -#define NEWTSTR_MALLOC(A) (A==NULL) ? NULL : _tcscpy((TCHAR*)mir_alloc(sizeof(TCHAR)*(_tcslen(A)+1)),A) -const int Stricmp(const TCHAR *str, const TCHAR *substr) -{ - int i = 0; - - TCHAR *str_up = NEWTSTR_MALLOC(str); - TCHAR *substr_up = NEWTSTR_MALLOC(substr); - - CharUpperBuff(str_up, lstrlen(str_up)); - CharUpperBuff(substr_up, lstrlen(substr_up)); - - i = _tcscmp(str_up, substr_up); - - mir_free(str_up); - mir_free(substr_up); - - return i; -} - -TCHAR* ReqGetText(DBEVENTINFO* dbei) -{ - if ( !dbei->pBlob ) - return 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++; - ptr++; - len--; - }; - - if(len) - { - char * tstr=(char *)mir_alloc(len+1); - memcpy(tstr, ptr, len); - tstr[len]=0; - WCHAR* msg = NULL; - msg=(dbei->flags&DBEF_UTF)?mir_utf8decodeW(tstr):mir_a2u(tstr); - mir_free(tstr); - return (TCHAR *)msg; - }; - return 0; -} - -BOOL IsUrlContains(TCHAR * Str) -{ - const int CountUrl=11; - const TCHAR URL[CountUrl][5]= - { - L"http", - L"www", - L".ru", - L".com", - L".de", - L".cz", - L".org", - L".net", - L".su", - L".ua", - L".tv" - }; - - if(Str && _tcslen(Str)>0) { - TCHAR *StrLower = NEWTSTR_MALLOC(Str); - CharLowerBuff(StrLower, lstrlen(StrLower)); - for (int i=0; i<CountUrl; i++) - if(_tcsstr (StrLower, URL[i])) - { - mir_free(StrLower); - return 1; - } - mir_free(StrLower); - } - return 0; -} - -tstring GetContactUid(HANDLE hContact, tstring Protocol) -{ - tstring Uid; - TCHAR dUid[32]={0}; - char aUid[32]={0}; - char *szProto = mir_utf8encodeW(Protocol.c_str()); - CONTACTINFO ci; - ZeroMemory((void *)&ci, sizeof(ci)); - - ci.hContact = hContact; - ci.szProto = szProto; - ci.cbSize = sizeof(ci); - - ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - Uid=ci.pszVal; - mir_free((void *)ci.pszVal); - break; - case CNFT_DWORD: -#if defined(_MSC_VER) && _MSC_VER >= 1300 - - _itoa_s(ci.dVal,aUid,32,10); -#else - _itoa(ci.dVal,aUid,10); - -#endif - OemToChar(aUid, dUid); - Uid=dUid; - break; - default: - Uid=_T(""); - break; - }; - } - mir_free(szProto); - return Uid; -} - -void LogSpamToFile(HANDLE hContact, tstring message) -{ - if (!gbLogToFile) return; - - tstring LogStrW, LogTime, LogProtocol, LogContactId, LogContactName; - tstring filename; - std::fstream file; - TCHAR pszName[MAX_PATH]; - +/* Copyright (C) Miklashevsky Roman, sss, elzor
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+
+#include "headers.h"
+
+tstring DBGetContactSettingStringPAN(HANDLE 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))
+ return errorValue;
+// if(DBVT_TCHAR == dbv.type )
+ errorValue = dbv.ptszVal;
+ db_free(&dbv);
+ return errorValue;
+}
+
+std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue)
+{
+ DBVARIANT dbv;
+ //if(db_get(hContact, szModule, szSetting, &dbv))
+ if(db_get_s(hContact, szModule, szSetting, &dbv))
+ return errorValue;
+// if(DBVT_ASCIIZ == dbv.type )
+ errorValue = dbv.pszVal;
+ db_free(&dbv);
+ return errorValue;
+}
+
+tstring &GetDlgItemString(HWND hwnd, int id)
+{
+ HWND h = GetDlgItem(hwnd, id);
+ int len = GetWindowTextLength(h);
+ TCHAR * buf = new TCHAR[len + 1];
+ GetWindowText(h, buf, len + 1);
+ static tstring s;
+ s = buf;
+ delete []buf;
+ return s;
+}
+
+std::string &GetProtoList()
+{
+ static std::string s;
+ return s = DBGetContactSettingStringPAN_A(NULL, pluginName, "protoList", "ICQ\r\n");
+}
+
+bool ProtoInList(std::string proto)
+{
+ return std::string::npos != GetProtoList().find(proto + "\r\n");
+}
+
+int CreateCListGroup(TCHAR* szGroupName)
+{
+ int hGroup = CallService(MS_CLIST_GROUPCREATE, 0, 0);
+
+ TCHAR* usTmp = szGroupName;
+ pcli->pfnRenameGroup(hGroup, usTmp);
+
+ return hGroup;
+}
+
+void DeleteCListGroupsByName(TCHAR* szGroupName)
+{
+ BYTE ConfirmDelete = db_get_b(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT);
+ if(ConfirmDelete)
+ db_set_b(NULL, "CList", "ConfirmDelete", 0);
+
+ TCHAR *szGroup;
+ for (int i=1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++)
+ if( !wcscmp(szGroupName, szGroup))
+ CallService(MS_CLIST_GROUPDELETE, i, 0);
+
+ if(ConfirmDelete)
+ db_set_b(NULL, "CList", "ConfirmDelete", ConfirmDelete);
+}
+
+int RemoveTmp(WPARAM,LPARAM)
+{
+ void CleanThread();
+ CleanThread();
+ return 0;
+}
+
+tstring variables_parse(tstring const &tstrFormat, HANDLE hContact){
+ if (gbVarsServiceExist) {
+ FORMATINFO fi;
+ TCHAR *tszParsed;
+ tstring tstrResult;
+
+ ZeroMemory(&fi, sizeof(fi));
+ fi.cbSize = sizeof(fi);
+ fi.tszFormat = _tcsdup(tstrFormat.c_str());
+ fi.hContact = hContact;
+ fi.flags |= FIF_TCHAR;
+ tszParsed = (TCHAR *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0);
+ free(fi.tszFormat);
+ if (tszParsed) {
+ tstrResult = tszParsed;
+ mir_free(tszParsed);
+ return tstrResult;
+ }
+ }
+ return tstrFormat;
+}
+
+// case-insensitive _tcscmp
+//by nullbie as i remember...
+#define NEWTSTR_MALLOC(A) (A==NULL) ? NULL : _tcscpy((TCHAR*)mir_alloc(sizeof(TCHAR)*(_tcslen(A)+1)),A)
+const int Stricmp(const TCHAR *str, const TCHAR *substr)
+{
+ int i = 0;
+
+ TCHAR *str_up = NEWTSTR_MALLOC(str);
+ TCHAR *substr_up = NEWTSTR_MALLOC(substr);
+
+ CharUpperBuff(str_up, lstrlen(str_up));
+ CharUpperBuff(substr_up, lstrlen(substr_up));
+
+ i = _tcscmp(str_up, substr_up);
+
+ mir_free(str_up);
+ mir_free(substr_up);
+
+ return i;
+}
+
+TCHAR* ReqGetText(DBEVENTINFO* dbei)
+{
+ if ( !dbei->pBlob )
+ return 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++;
+ ptr++;
+ len--;
+ };
+
+ if(len)
+ {
+ char * tstr=(char *)mir_alloc(len+1);
+ memcpy(tstr, ptr, len);
+ tstr[len]=0;
+ WCHAR* msg = NULL;
+ msg=(dbei->flags&DBEF_UTF)?mir_utf8decodeW(tstr):mir_a2u(tstr);
+ mir_free(tstr);
+ return (TCHAR *)msg;
+ };
+ return 0;
+}
+
+BOOL IsUrlContains(TCHAR * Str)
+{
+ const int CountUrl=11;
+ const TCHAR URL[CountUrl][5]=
+ {
+ L"http",
+ L"www",
+ L".ru",
+ L".com",
+ L".de",
+ L".cz",
+ L".org",
+ L".net",
+ L".su",
+ L".ua",
+ L".tv"
+ };
+
+ if(Str && _tcslen(Str)>0) {
+ TCHAR *StrLower = NEWTSTR_MALLOC(Str);
+ CharLowerBuff(StrLower, lstrlen(StrLower));
+ for (int i=0; i<CountUrl; i++)
+ if(_tcsstr (StrLower, URL[i]))
+ {
+ mir_free(StrLower);
+ return 1;
+ }
+ mir_free(StrLower);
+ }
+ return 0;
+}
+
+tstring GetContactUid(HANDLE hContact, tstring Protocol)
+{
+ tstring Uid;
+ TCHAR dUid[32]={0};
+ char aUid[32]={0};
+ char *szProto = mir_utf8encodeW(Protocol.c_str());
+ CONTACTINFO ci;
+ ZeroMemory((void *)&ci, sizeof(ci));
+
+ ci.hContact = hContact;
+ ci.szProto = szProto;
+ ci.cbSize = sizeof(ci);
+
+ ci.dwFlag = CNF_DISPLAYUID | CNF_TCHAR;
+ if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) {
+ switch (ci.type) {
+ case CNFT_ASCIIZ:
+ Uid=ci.pszVal;
+ mir_free((void *)ci.pszVal);
+ break;
+ case CNFT_DWORD:
+#if defined(_MSC_VER) && _MSC_VER >= 1300
+
+ _itoa_s(ci.dVal,aUid,32,10);
+#else
+ _itoa(ci.dVal,aUid,10);
+
+#endif
+ OemToChar(aUid, dUid);
+ Uid=dUid;
+ break;
+ default:
+ Uid=_T("");
+ break;
+ };
+ }
+ mir_free(szProto);
+ return Uid;
+}
+
+void LogSpamToFile(HANDLE hContact, tstring message)
+{
+ if (!gbLogToFile) return;
+
+ tstring LogStrW, LogTime, LogProtocol, LogContactId, LogContactName;
+ tstring filename;
+ std::fstream file;
+ TCHAR pszName[MAX_PATH];
+
if (hStopSpamLogDirH)
FoldersGetCustomPathT(hStopSpamLogDirH, pszName, MAX_PATH, _T(""));
else
lstrcpyn(pszName, VARST( _T("%miranda_logpath%")), SIZEOF(pszName));
- - filename = pszName; - filename = filename + _T("\\stopspam_mod.log"); - - file.open(filename.c_str(),std::ios::out |std::ios::app); - - // Time Log line - time_t time_now; - tm *TimeNow; - time(&time_now); - TimeNow = localtime(&time_now); - LogTime=_wasctime( TimeNow ); - // Time Log line - - // Name, UID and Protocol Log line - LogProtocol=DBGetContactSettingStringPAN(hContact,"Protocol","p",_T("")); - LogContactName=(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR); - 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"); - - char * buf=mir_u2a(LogStrW.c_str()); - file.write(buf,LogStrW.length()); - mir_free(buf); - - file.close(); -} - -boost::mutex clean_mutex; - -void CleanProtocolTmpThread(std::string proto) -{ - while(true) - { - UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); - if(status > ID_STATUS_OFFLINE) - break; - boost::this_thread::sleep(boost::posix_time::seconds(2)); - } - - std::list<HANDLE> contacts; - for(HANDLE 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<HANDLE>::iterator end = contacts.end(); - for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i) - { - LogSpamToFile(*i, _T("Deleted")); - HistoryLogFunc(*i, "Deleted"); - CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0); - } - clean_mutex.unlock(); -} - -void CleanProtocolExclThread(std::string proto) -{ - while(true) - { - UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); - if(status > ID_STATUS_OFFLINE) - break; - boost::this_thread::sleep(boost::posix_time::seconds(2)); - } - - std::list<HANDLE> contacts; - for(HANDLE 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<HANDLE>::iterator end = contacts.end(); - for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i) - { - LogSpamToFile(*i, _T("Deleted")); - HistoryLogFunc(*i, "Deleted"); - CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0); - } - clean_mutex.unlock(); -} - -void CleanThread() -{ - std::list<std::string> protocols; - int count = 0; - PROTOACCOUNT **accounts; - ProtoEnumAccounts(&count, &accounts); - 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<std::string>::iterator end = protocols.end(); - for(std::list<std::string>::iterator i = protocols.begin(); i != end; ++i) - { - if(gbDelAllTempory) - boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolTmpThread, *i)); - if(gbDelExcluded) - boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolExclThread, *i)); - } -} - -void HistoryLog(HANDLE hContact, char *data, int event_type, int flags) -{ - DBEVENTINFO Event = { sizeof(Event) }; - Event.szModule = pluginName; - Event.eventType = event_type; - Event.flags = flags | DBEF_UTF; - Event.timestamp = (DWORD)time(NULL); - Event.cbBlob = strlen(data)+1; - Event.pBlob = (PBYTE)_strdup(data); - db_event_add(hContact, &Event); -} - -void HistoryLogFunc(HANDLE hContact, std::string message) -{ - if(gbHistoryLog) - { - if(hContact == INVALID_HANDLE_VALUE) - return; - std::string msg = message; - msg.append("\n"); - msg.append("Protocol: ").append(GetContactProto(hContact)).append(" Contact: "); - msg.append(toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR))).append(" ID: "); - msg.append(toUTF8(GetContactUid(hContact,toUTF16(GetContactProto(hContact))))); - HistoryLog(NULL, (char*)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ); - } -} - -std::string toUTF8(std::wstring str) -{ - std::string ustr; - try{ - utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); - } - catch(const std::exception&) - { - //TODO: handle utf8cpp exceptions - } - return ustr; -} - -std::string toUTF8(std::string str) -{ - return toUTF8(toUTF16(str)); -} - -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)); - } - catch(const std::exception &) - { - //TODO: handle utf8cpp exceptions - } - return ustr; -} - -std::string get_random_num(int length) -{ - std::string chars("123456789"); - std::string data; - boost::random_device rng; - boost::variate_generator<boost::random_device&, boost::uniform_int<>> gen(rng, boost::uniform_int<>(0, chars.length()-1)); - for(int i = 0; i < length; ++i) - data += chars[gen()]; - return data; -} +
+ filename = pszName;
+ filename = filename + _T("\\stopspam_mod.log");
+
+ file.open(filename.c_str(),std::ios::out |std::ios::app);
+
+ // Time Log line
+ time_t time_now;
+ tm *TimeNow;
+ time(&time_now);
+ TimeNow = localtime(&time_now);
+ LogTime=_wasctime( TimeNow );
+ // Time Log line
+
+ // Name, UID and Protocol Log line
+ LogProtocol=DBGetContactSettingStringPAN(hContact,"Protocol","p",_T(""));
+ LogContactName=(TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR);
+ 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");
+
+ char * buf=mir_u2a(LogStrW.c_str());
+ file.write(buf,LogStrW.length());
+ mir_free(buf);
+
+ file.close();
+}
+
+boost::mutex clean_mutex;
+
+void CleanProtocolTmpThread(std::string proto)
+{
+ while(true)
+ {
+ UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0);
+ if(status > ID_STATUS_OFFLINE)
+ break;
+ boost::this_thread::sleep(boost::posix_time::seconds(2));
+ }
+
+ std::list<HANDLE> contacts;
+ for(HANDLE 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<HANDLE>::iterator end = contacts.end();
+ for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i)
+ {
+ LogSpamToFile(*i, _T("Deleted"));
+ HistoryLogFunc(*i, "Deleted");
+ CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0);
+ }
+ clean_mutex.unlock();
+}
+
+void CleanProtocolExclThread(std::string proto)
+{
+ while(true)
+ {
+ UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0);
+ if(status > ID_STATUS_OFFLINE)
+ break;
+ boost::this_thread::sleep(boost::posix_time::seconds(2));
+ }
+
+ std::list<HANDLE> contacts;
+ for(HANDLE 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<HANDLE>::iterator end = contacts.end();
+ for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i)
+ {
+ LogSpamToFile(*i, _T("Deleted"));
+ HistoryLogFunc(*i, "Deleted");
+ CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0);
+ }
+ clean_mutex.unlock();
+}
+
+void CleanThread()
+{
+ std::list<std::string> protocols;
+ int count = 0;
+ PROTOACCOUNT **accounts;
+ ProtoEnumAccounts(&count, &accounts);
+ 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<std::string>::iterator end = protocols.end();
+ for(std::list<std::string>::iterator i = protocols.begin(); i != end; ++i)
+ {
+ if(gbDelAllTempory)
+ boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolTmpThread, *i));
+ if(gbDelExcluded)
+ boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolExclThread, *i));
+ }
+}
+
+void HistoryLog(HANDLE hContact, char *data, int event_type, int flags)
+{
+ DBEVENTINFO Event = { sizeof(Event) };
+ Event.szModule = pluginName;
+ Event.eventType = event_type;
+ Event.flags = flags | DBEF_UTF;
+ Event.timestamp = (DWORD)time(NULL);
+ Event.cbBlob = (DWORD)strlen(data)+1;
+ Event.pBlob = (PBYTE)_strdup(data);
+ db_event_add(hContact, &Event);
+}
+
+void HistoryLogFunc(HANDLE hContact, std::string message)
+{
+ if(gbHistoryLog)
+ {
+ if(hContact == INVALID_HANDLE_VALUE)
+ return;
+ std::string msg = message;
+ msg.append("\n");
+ msg.append("Protocol: ").append(GetContactProto(hContact)).append(" Contact: ");
+ msg.append(toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR))).append(" ID: ");
+ msg.append(toUTF8(GetContactUid(hContact,toUTF16(GetContactProto(hContact)))));
+ HistoryLog(NULL, (char*)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ);
+ }
+}
+
+std::string toUTF8(std::wstring str)
+{
+ std::string ustr;
+ try{
+ utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr));
+ }
+ catch(const std::exception&)
+ {
+ //TODO: handle utf8cpp exceptions
+ }
+ return ustr;
+}
+
+std::string toUTF8(std::string str)
+{
+ return toUTF8(toUTF16(str));
+}
+
+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));
+ }
+ catch(const std::exception &)
+ {
+ //TODO: handle utf8cpp exceptions
+ }
+ return ustr;
+}
+
+std::string get_random_num(int length)
+{
+ std::string chars("123456789");
+ std::string data;
+ boost::random_device rng;
+ boost::variate_generator<boost::random_device&, boost::uniform_int<>> gen(rng, boost::uniform_int<>(0, (int)chars.length()-1));
+ for(int i = 0; i < length; ++i)
+ data += chars[gen()];
+ return data;
+}
|