From 9395431a6fe57538cb6e7d9900a37e8d737bc80e Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 5 Apr 2010 19:07:46 +0300 Subject: dos2unix string termination --- eventhooker.cpp | 136 +++++----- eventhooker.h | 120 ++++----- globals.h | 40 +-- headers.h | 60 ++--- init.cpp | 424 +++++++++++++++---------------- options.cpp | 770 ++++++++++++++++++++++++++++---------------------------- resource.h | 108 ++++---- stopspam.cpp | 500 ++++++++++++++++++------------------ stopspam.h | 46 ++-- utilities.cpp | 330 ++++++++++++------------ utilities.h | 16 +- version.h | 12 +- 12 files changed, 1281 insertions(+), 1281 deletions(-) diff --git a/eventhooker.cpp b/eventhooker.cpp index f29e5b7..0160346 100644 --- a/eventhooker.cpp +++ b/eventhooker.cpp @@ -1,68 +1,68 @@ -/* eventhooker.cpp -* Copyright (C) Miklashevsky Roman -* -* 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 -#include "eventhooker.h" - -namespace miranda -{ - namespace - { - std::list eventHookerList; - } - - EventHooker::EventHooker(std::string name, MIRANDAHOOK fun) : name_(name), fun_(fun), handle_(0) - { - eventHookerList.push_back(this); - } - - EventHooker::~EventHooker() - { - eventHookerList.remove(this); - } - - void EventHooker::Hook() - { - handle_ = HookEvent(name_.c_str(), fun_); - } - - void EventHooker::Unhook() - { - if(handle_) - { - UnhookEvent(handle_); - handle_ = 0; - } - } - - void EventHooker::HookAll() - { - for(std::list::iterator it = eventHookerList.begin(); it != eventHookerList.end(); ++it) - { - (*it)->Hook(); - } - } - - void EventHooker::UnhookAll() - { - for(std::list::iterator it = eventHookerList.begin(); it != eventHookerList.end(); ++it) - { - (*it)->Unhook(); - } - } -} +/* eventhooker.cpp +* Copyright (C) Miklashevsky Roman +* +* 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 +#include "eventhooker.h" + +namespace miranda +{ + namespace + { + std::list eventHookerList; + } + + EventHooker::EventHooker(std::string name, MIRANDAHOOK fun) : name_(name), fun_(fun), handle_(0) + { + eventHookerList.push_back(this); + } + + EventHooker::~EventHooker() + { + eventHookerList.remove(this); + } + + void EventHooker::Hook() + { + handle_ = HookEvent(name_.c_str(), fun_); + } + + void EventHooker::Unhook() + { + if(handle_) + { + UnhookEvent(handle_); + handle_ = 0; + } + } + + void EventHooker::HookAll() + { + for(std::list::iterator it = eventHookerList.begin(); it != eventHookerList.end(); ++it) + { + (*it)->Hook(); + } + } + + void EventHooker::UnhookAll() + { + for(std::list::iterator it = eventHookerList.begin(); it != eventHookerList.end(); ++it) + { + (*it)->Unhook(); + } + } +} diff --git a/eventhooker.h b/eventhooker.h index b1ca2ab..8814613 100644 --- a/eventhooker.h +++ b/eventhooker.h @@ -1,60 +1,60 @@ -/* eventhooker.h - Helper for hooking events in Miranda. -* Copyright (C) Miklashevsky Roman -* -* To hook event just write -* MIRANDA_HOOK_EVENT('name of the event', wParam, lParam) { 'your code' } -* Include following in your Load function -* miranda::EventHooker::HookAll(); -* And following in your Unload function -* miranda::EventHooker::UnhookAll(); -* That's all -* -* 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. -*/ - -#ifndef EVENTHOOKER_H_C8EAA58A_7C4D_45f7_A88E_0E41FE93754D -#define EVENTHOOKER_H_C8EAA58A_7C4D_45f7_A88E_0E41FE93754D - -#pragma warning( once : 4430 ) - -#include -#include -#include - -namespace miranda -{ - -#define MIRANDA_HOOK_EVENT(NAME, WPARAMNAME, LPARAMNAME) \ - int NAME##_Handler(WPARAM,LPARAM);\ - miranda::EventHooker NAME##_Hooker(NAME, NAME##_Handler);\ - int NAME##_Handler(WPARAM WPARAMNAME, LPARAM LPARAMNAME) - - struct EventHooker - { - EventHooker(std::string name, MIRANDAHOOK fun); - ~EventHooker(); - void Hook(); - void Unhook(); - static void HookAll(); - static void UnhookAll(); - private: - std::string name_; - MIRANDAHOOK fun_; - HANDLE handle_; - }; - -} - -#endif +/* eventhooker.h - Helper for hooking events in Miranda. +* Copyright (C) Miklashevsky Roman +* +* To hook event just write +* MIRANDA_HOOK_EVENT('name of the event', wParam, lParam) { 'your code' } +* Include following in your Load function +* miranda::EventHooker::HookAll(); +* And following in your Unload function +* miranda::EventHooker::UnhookAll(); +* That's all +* +* 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. +*/ + +#ifndef EVENTHOOKER_H_C8EAA58A_7C4D_45f7_A88E_0E41FE93754D +#define EVENTHOOKER_H_C8EAA58A_7C4D_45f7_A88E_0E41FE93754D + +#pragma warning( once : 4430 ) + +#include +#include +#include + +namespace miranda +{ + +#define MIRANDA_HOOK_EVENT(NAME, WPARAMNAME, LPARAMNAME) \ + int NAME##_Handler(WPARAM,LPARAM);\ + miranda::EventHooker NAME##_Hooker(NAME, NAME##_Handler);\ + int NAME##_Handler(WPARAM WPARAMNAME, LPARAM LPARAMNAME) + + struct EventHooker + { + EventHooker(std::string name, MIRANDAHOOK fun); + ~EventHooker(); + void Hook(); + void Unhook(); + static void HookAll(); + static void UnhookAll(); + private: + std::string name_; + MIRANDAHOOK fun_; + HANDLE handle_; + }; + +} + +#endif diff --git a/globals.h b/globals.h index 9ae64b3..9a4643b 100644 --- a/globals.h +++ b/globals.h @@ -1,20 +1,20 @@ -#define pluginName "StopSpam" -/* -TCHAR const * defAnswer = _T("nospam"); -TCHAR const * defCongratulation = -_T("Congratulations! You just passed human/robot test. Now you can write me a message."); -char const * defProtoList = "ICQ\r\n"; -TCHAR const * infTalkProtPrefix = _T("StopSpam automatic message:\r\n"); -char const * answeredSetting = "Answered"; -char const * questCountSetting = "QuestionCount"; -TCHAR const * defAufrepl = _T("StopSpam: send a message and reply to a anti-spam bot question.");*/ - - -#ifdef _UNICODE -typedef std::wstring tstring; -#define PREF_TCHAR2 PREF_UTF -#else -typedef std::string tstring; -#define PREF_TCHAR2 0 -#endif //_UNICODE - +#define pluginName "StopSpam" +/* +TCHAR const * defAnswer = _T("nospam"); +TCHAR const * defCongratulation = +_T("Congratulations! You just passed human/robot test. Now you can write me a message."); +char const * defProtoList = "ICQ\r\n"; +TCHAR const * infTalkProtPrefix = _T("StopSpam automatic message:\r\n"); +char const * answeredSetting = "Answered"; +char const * questCountSetting = "QuestionCount"; +TCHAR const * defAufrepl = _T("StopSpam: send a message and reply to a anti-spam bot question.");*/ + + +#ifdef _UNICODE +typedef std::wstring tstring; +#define PREF_TCHAR2 PREF_UTF +#else +typedef std::string tstring; +#define PREF_TCHAR2 0 +#endif //_UNICODE + diff --git a/headers.h b/headers.h index 8295bc4..25f9570 100644 --- a/headers.h +++ b/headers.h @@ -1,30 +1,30 @@ -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#define VARIABLES_NOHELPER -#include - - -#include "globals.h" -#include "stopspam.h" -#include "options.h" -#include "eventhooker.h" -#include "version.h" -#include "resource.h" -#include "utilities.h" - -#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#define VARIABLES_NOHELPER +#include + + +#include "globals.h" +#include "stopspam.h" +#include "options.h" +#include "eventhooker.h" +#include "version.h" +#include "resource.h" +#include "utilities.h" + +#include diff --git a/init.cpp b/init.cpp index a1e8499..a2d3c99 100644 --- a/init.cpp +++ b/init.cpp @@ -1,212 +1,212 @@ -#include "headers.h" - - - -BOOL gbDosServiceExist = 0; -BOOL gbVarsServiceExist = 0; - -DWORD gbMaxQuestCount = 5; -BOOL gbInfTalkProtection = 0; -BOOL gbAddPermanent = 0; -BOOL gbHandleAuthReq = 1; -BOOL gbSpecialGroup = 0; -BOOL gbHideContacts = 1; -BOOL gbIgnoreContacts = 0; -BOOL gbExclude = 1; -BOOL gbDelExcluded = 0; -BOOL gbDosServiceIntegration = 0; -BOOL gbCaseInsensitive = 0; -BOOL gbInvisDisable = 0; -BOOL gbIgnoreURL = 1; -//BOOL gbDelNotInList = 0; -tstring gbSpammersGroup = _T("Spammers"); -tstring gbQuestion; -tstring gbAnswer; -tstring gbCongratulation; -std::wstring gbAuthRepl; -extern char * pluginDescription; -extern TCHAR const * defQuestion; -extern int RemoveTmp(WPARAM,LPARAM); - -struct MM_INTERFACE mmi; - -UTF8_INTERFACE utfi; - - - -///////////////////////////////////////////////////////////////////////////////////////// -// returns plugin's extended information - -// {553811EE-DEB6-48b8-8902-A8A00C1FD679} -#define MIID_STOPSPAM { 0x553811ee, 0xdeb6, 0x48b8, { 0x89, 0x2, 0xa8, 0xa0, 0xc, 0x1f, 0xd6, 0x79 } } - -PLUGININFOEX pluginInfoEx = { - sizeof(PLUGININFOEX), - 0, - PLUGIN_MAKE_VERSION(0, 0, 1, 7), - pluginDescription, - "Roman Miklashevsky", - "sss123next@list.ru", - "© 2004-2009 Roman Miklashevsky, A. Petkevich, Kosh&chka, sss", - "http://sss.chaoslab.ru:81/tracker/mim_plugs/", - UNICODE_AWARE, - 0, - MIID_STOPSPAM -}; - - -char *date() -{ - static char d[11]; - char *tmp = __DATE__, m[4], mn[3] = "01"; - m[0]=tmp[0]; - m[1]=tmp[1]; - m[2]=tmp[2]; - if(strstr(m,"Jan")) - strcpy(mn,"01"); - else if(strstr(m,"Feb")) - strcpy(mn,"02"); - else if(strstr(m,"Mar")) - strcpy(mn,"03"); - else if(strstr(m,"Apr")) - strcpy(mn,"04"); - else if(strstr(m,"May")) - strcpy(mn,"05"); - else if(strstr(m,"Jun")) - strcpy(mn,"06"); - else if(strstr(m,"Jul")) - strcpy(mn,"07"); - else if(strstr(m,"Aug")) - strcpy(mn,"08"); - else if(strstr(m,"Sep")) - strcpy(mn,"09"); - else if(strstr(m,"Oct")) - strcpy(mn,"10"); - else if(strstr(m,"Nov")) - strcpy(mn,"11"); - else if(strstr(m,"Dec")) - strcpy(mn,"12"); - d[0]=tmp[7]; - d[1]=tmp[8]; - d[2]=tmp[9]; - d[3]=tmp[10]; - d[4]='.'; - d[5]=mn[0]; - d[6]=mn[1]; - d[7]='.'; - if (tmp[4] == ' ') - d[8] = '0'; - else - d[8]=tmp[4]; - d[9]=tmp[5]; - return d; -} - - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) -{ - if ( mirandaVersion < PLUGIN_MAKE_VERSION( 0, 7, 0, 1 )) - return NULL; - { - static char plugname[52]; - strcpy(plugname, pluginName" mod ["); - strcat(plugname, date()); - strcat(plugname, " "); - strcat(plugname, __TIME__); - strcat(plugname, "]"); - pluginInfoEx.shortName = plugname; - } - - return &pluginInfoEx; -} - -extern tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue); - -void InitVars() -{ - gbDosServiceIntegration = DBGetContactSettingByte(NULL, pluginName, "DOSIntegration", 0); - gbSpammersGroup = DBGetContactSettingStringPAN(NULL, pluginName, "SpammersGroup", _T("Spammers")); - gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); - gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", _T("Congratulations! You just passed human/robot test. Now you can write me a message.")); - gbInfTalkProtection = DBGetContactSettingByte(NULL, pluginName, "infTalkProtection", 0); - gbAddPermanent = DBGetContactSettingByte(NULL, pluginName, "addPermanent", 0); - gbMaxQuestCount = DBGetContactSettingDword(NULL, pluginName, "maxQuestCount", 5); - gbHandleAuthReq = DBGetContactSettingByte(NULL, pluginName, "handleAuthReq", 1); - gbQuestion = DBGetContactSettingStringPAN(NULL, pluginName, "question", defQuestion); - gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); - gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", _T("Congratulations! You just passed human/robot test. Now you can write me a message.")); - gbAuthRepl = DBGetContactSettingStringPAN(NULL, pluginName, "authrepl", _T("StopSpam: send a message and reply to a anti-spam bot question.")); - gbSpecialGroup = DBGetContactSettingByte(NULL, pluginName, "SpecialGroup", 0); - gbHideContacts = DBGetContactSettingByte(NULL, pluginName, "HideContacts", 0); - gbIgnoreContacts = DBGetContactSettingByte(NULL, pluginName, "IgnoreContacts", 0); - gbExclude = DBGetContactSettingByte(NULL, pluginName, "ExcludeContacts", 1); - gbDelExcluded = DBGetContactSettingByte(NULL, pluginName, "DelExcluded", 0); - gbCaseInsensitive = DBGetContactSettingByte(NULL, pluginName, "CaseInsensitive", 0); - gbInvisDisable = DBGetContactSettingByte(NULL, pluginName, "DisableInInvis", 0); - gbIgnoreURL = DBGetContactSettingByte(NULL, pluginName, "IgnoreURL", 0); -// gbDelNotInList = DBGetContactSettingByte(NULL, pluginName, "DelNotInList", 0); -} - -static int OnSystemModulesLoaded(WPARAM wParam,LPARAM lParam) -{ - if (ServiceExists(MS_DOS_SERVICE)) - gbDosServiceExist = TRUE; - if (ServiceExists(MS_VARS_FORMATSTRING)) - gbVarsServiceExist = TRUE; - InitVars(); - if(gbDelExcluded) - RemoveExcludedUsers(); - return 0; -} - -PLUGINLINK *pluginLink; -HANDLE hEventFilter = 0, hOptInitialise = 0, hSettingChanged = 0; - - -BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) -{ - /*if(DLL_PROCESS_ATTACH == fdwReason) - hInst=hinstDLL; - return TRUE;*/ - hInst = hinstDLL; - return TRUE; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// returns plugin's interfaces information - -static const MUUID interfaces[] = { MIID_STOPSPAM, MIID_LAST }; - -extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) -{ - return interfaces; -} - - - -extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) -{ - pluginLink = link; - CLISTMENUITEM mi; - CreateServiceFunction("/RemoveTmp",RemoveTmp); - mir_getMMI(&mmi); - mir_getUTFI(&utfi); - HookEvent(ME_SYSTEM_MODULESLOADED, OnSystemModulesLoaded); - ZeroMemory(&mi,sizeof(mi)); - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFF; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Remove Temporary Contacts"; - mi.pszService="/RemoveTmp"; - CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi); - - miranda::EventHooker::HookAll(); - return 0; -} - -extern "C" int __declspec(dllexport) Unload(void) -{ - miranda::EventHooker::UnhookAll(); - return 0; -} +#include "headers.h" + + + +BOOL gbDosServiceExist = 0; +BOOL gbVarsServiceExist = 0; + +DWORD gbMaxQuestCount = 5; +BOOL gbInfTalkProtection = 0; +BOOL gbAddPermanent = 0; +BOOL gbHandleAuthReq = 1; +BOOL gbSpecialGroup = 0; +BOOL gbHideContacts = 1; +BOOL gbIgnoreContacts = 0; +BOOL gbExclude = 1; +BOOL gbDelExcluded = 0; +BOOL gbDosServiceIntegration = 0; +BOOL gbCaseInsensitive = 0; +BOOL gbInvisDisable = 0; +BOOL gbIgnoreURL = 1; +//BOOL gbDelNotInList = 0; +tstring gbSpammersGroup = _T("Spammers"); +tstring gbQuestion; +tstring gbAnswer; +tstring gbCongratulation; +std::wstring gbAuthRepl; +extern char * pluginDescription; +extern TCHAR const * defQuestion; +extern int RemoveTmp(WPARAM,LPARAM); + +struct MM_INTERFACE mmi; + +UTF8_INTERFACE utfi; + + + +///////////////////////////////////////////////////////////////////////////////////////// +// returns plugin's extended information + +// {553811EE-DEB6-48b8-8902-A8A00C1FD679} +#define MIID_STOPSPAM { 0x553811ee, 0xdeb6, 0x48b8, { 0x89, 0x2, 0xa8, 0xa0, 0xc, 0x1f, 0xd6, 0x79 } } + +PLUGININFOEX pluginInfoEx = { + sizeof(PLUGININFOEX), + 0, + PLUGIN_MAKE_VERSION(0, 0, 1, 7), + pluginDescription, + "Roman Miklashevsky", + "sss123next@list.ru", + "© 2004-2009 Roman Miklashevsky, A. Petkevich, Kosh&chka, sss", + "http://sss.chaoslab.ru:81/tracker/mim_plugs/", + UNICODE_AWARE, + 0, + MIID_STOPSPAM +}; + + +char *date() +{ + static char d[11]; + char *tmp = __DATE__, m[4], mn[3] = "01"; + m[0]=tmp[0]; + m[1]=tmp[1]; + m[2]=tmp[2]; + if(strstr(m,"Jan")) + strcpy(mn,"01"); + else if(strstr(m,"Feb")) + strcpy(mn,"02"); + else if(strstr(m,"Mar")) + strcpy(mn,"03"); + else if(strstr(m,"Apr")) + strcpy(mn,"04"); + else if(strstr(m,"May")) + strcpy(mn,"05"); + else if(strstr(m,"Jun")) + strcpy(mn,"06"); + else if(strstr(m,"Jul")) + strcpy(mn,"07"); + else if(strstr(m,"Aug")) + strcpy(mn,"08"); + else if(strstr(m,"Sep")) + strcpy(mn,"09"); + else if(strstr(m,"Oct")) + strcpy(mn,"10"); + else if(strstr(m,"Nov")) + strcpy(mn,"11"); + else if(strstr(m,"Dec")) + strcpy(mn,"12"); + d[0]=tmp[7]; + d[1]=tmp[8]; + d[2]=tmp[9]; + d[3]=tmp[10]; + d[4]='.'; + d[5]=mn[0]; + d[6]=mn[1]; + d[7]='.'; + if (tmp[4] == ' ') + d[8] = '0'; + else + d[8]=tmp[4]; + d[9]=tmp[5]; + return d; +} + + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + if ( mirandaVersion < PLUGIN_MAKE_VERSION( 0, 7, 0, 1 )) + return NULL; + { + static char plugname[52]; + strcpy(plugname, pluginName" mod ["); + strcat(plugname, date()); + strcat(plugname, " "); + strcat(plugname, __TIME__); + strcat(plugname, "]"); + pluginInfoEx.shortName = plugname; + } + + return &pluginInfoEx; +} + +extern tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue); + +void InitVars() +{ + gbDosServiceIntegration = DBGetContactSettingByte(NULL, pluginName, "DOSIntegration", 0); + gbSpammersGroup = DBGetContactSettingStringPAN(NULL, pluginName, "SpammersGroup", _T("Spammers")); + gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); + gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", _T("Congratulations! You just passed human/robot test. Now you can write me a message.")); + gbInfTalkProtection = DBGetContactSettingByte(NULL, pluginName, "infTalkProtection", 0); + gbAddPermanent = DBGetContactSettingByte(NULL, pluginName, "addPermanent", 0); + gbMaxQuestCount = DBGetContactSettingDword(NULL, pluginName, "maxQuestCount", 5); + gbHandleAuthReq = DBGetContactSettingByte(NULL, pluginName, "handleAuthReq", 1); + gbQuestion = DBGetContactSettingStringPAN(NULL, pluginName, "question", defQuestion); + gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); + gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", _T("Congratulations! You just passed human/robot test. Now you can write me a message.")); + gbAuthRepl = DBGetContactSettingStringPAN(NULL, pluginName, "authrepl", _T("StopSpam: send a message and reply to a anti-spam bot question.")); + gbSpecialGroup = DBGetContactSettingByte(NULL, pluginName, "SpecialGroup", 0); + gbHideContacts = DBGetContactSettingByte(NULL, pluginName, "HideContacts", 0); + gbIgnoreContacts = DBGetContactSettingByte(NULL, pluginName, "IgnoreContacts", 0); + gbExclude = DBGetContactSettingByte(NULL, pluginName, "ExcludeContacts", 1); + gbDelExcluded = DBGetContactSettingByte(NULL, pluginName, "DelExcluded", 0); + gbCaseInsensitive = DBGetContactSettingByte(NULL, pluginName, "CaseInsensitive", 0); + gbInvisDisable = DBGetContactSettingByte(NULL, pluginName, "DisableInInvis", 0); + gbIgnoreURL = DBGetContactSettingByte(NULL, pluginName, "IgnoreURL", 0); +// gbDelNotInList = DBGetContactSettingByte(NULL, pluginName, "DelNotInList", 0); +} + +static int OnSystemModulesLoaded(WPARAM wParam,LPARAM lParam) +{ + if (ServiceExists(MS_DOS_SERVICE)) + gbDosServiceExist = TRUE; + if (ServiceExists(MS_VARS_FORMATSTRING)) + gbVarsServiceExist = TRUE; + InitVars(); + if(gbDelExcluded) + RemoveExcludedUsers(); + return 0; +} + +PLUGINLINK *pluginLink; +HANDLE hEventFilter = 0, hOptInitialise = 0, hSettingChanged = 0; + + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + /*if(DLL_PROCESS_ATTACH == fdwReason) + hInst=hinstDLL; + return TRUE;*/ + hInst = hinstDLL; + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// returns plugin's interfaces information + +static const MUUID interfaces[] = { MIID_STOPSPAM, MIID_LAST }; + +extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) +{ + return interfaces; +} + + + +extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) +{ + pluginLink = link; + CLISTMENUITEM mi; + CreateServiceFunction("/RemoveTmp",RemoveTmp); + mir_getMMI(&mmi); + mir_getUTFI(&utfi); + HookEvent(ME_SYSTEM_MODULESLOADED, OnSystemModulesLoaded); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFF; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Remove Temporary Contacts"; + mi.pszService="/RemoveTmp"; + CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi); + + miranda::EventHooker::HookAll(); + return 0; +} + +extern "C" int __declspec(dllexport) Unload(void) +{ + miranda::EventHooker::UnhookAll(); + return 0; +} diff --git a/options.cpp b/options.cpp index 9ef6bcc..fabee4d 100644 --- a/options.cpp +++ b/options.cpp @@ -1,385 +1,385 @@ -#define MIRANDA_VER 0x0800 -#include "headers.h" - -char * pluginDescription = "No more spam! Robots can't go! Only human beings invited!\r\n\r\n" -"This plugin works pretty simple:\r\n" -"While 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 = -_T("Spammers made me to install small anti-spam system you are now speaking with.\r\n") -_T("Please 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); - } - 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: - { - DBWriteContactSettingDword(NULL, pluginName, "maxQuestCount", gbMaxQuestCount = - GetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, NULL, FALSE)); - DBWriteContactSettingByte(NULL, pluginName, "infTalkProtection", gbInfTalkProtection = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_INFTALKPROT, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "addPermanent", gbAddPermanent = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_ADDPERMANENT, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "handleAuthReq", gbHandleAuthReq = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_HANDLEAUTHREQ, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "HideContacts", gbHideContacts = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_HIDECONTACTS, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "IgnoreContacts", gbIgnoreContacts = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNORESPAMMERS, 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()); - 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, TranslateTS(defQuestion)); - SetDlgItemText(hwnd, ID_ANSWER, TranslateTS(_T("nospam"))); - SetDlgItemText(hwnd, ID_AUTHREPL, TranslateTS(_T("StopSpam: send a message and reply to a anti-spam bot question."))); - SetDlgItemText(hwnd, ID_CONGRATULATION, TranslateTS(_T("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: - { - DBWriteContactSettingTString(NULL, pluginName, "question", - GetDlgItemString(hwnd, ID_QUESTION).c_str()); - gbQuestion = DBGetContactSettingStringPAN(NULL, pluginName, "question", defQuestion); - DBWriteContactSettingTString(NULL, pluginName, "answer", - GetDlgItemString(hwnd, ID_ANSWER).c_str()); - gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); - DBWriteContactSettingTString(NULL, pluginName, "authrepl", - GetDlgItemString(hwnd, ID_AUTHREPL).c_str()); - gbAuthRepl = DBGetContactSettingStringPAN(NULL, pluginName, "authrepl", _T("StopSpam: send a message and reply to a anti-spam bot question.")); - DBWriteContactSettingTString(NULL, pluginName, "congratulation", - GetDlgItemString(hwnd, ID_CONGRATULATION).c_str()); - gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", _T("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; - PROTOCOLDESCRIPTOR** pppd; - if(!CallService(MS_PROTO_ENUMPROTOCOLS, (LPARAM)&n, (WPARAM)&pppd)) - for(int i = 0; i < n; ++i) - { - SendDlgItemMessageA(hwnd, (ProtoInList(pppd[i]->szName) ? ID_USEDPROTO : ID_ALLPROTO), - LB_ADDSTRING, 0, (LPARAM)pppd[i]->szName); - } - } - 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; - } - } - DBWriteContactSettingString(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_IGNOREURL, BM_SETCHECK, gbIgnoreURL ? BST_CHECKED : BST_UNCHECKED, 0); - } - return TRUE; - case WM_COMMAND:{ - switch (LOWORD(wParam)) - { - 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_IGNOREURL: - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - break; - - } - } - break; - case WM_NOTIFY: - { - NMHDR* nmhdr = (NMHDR*)lParam; - switch (nmhdr->code) - { - case PSN_APPLY: - { - DBWriteContactSettingByte(NULL, pluginName, "CaseInsensitive", gbCaseInsensitive = - BST_CHECKED == SendDlgItemMessage(hwnd, IDC_CASE_INSENSITIVE, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "DisableInInvis", gbInvisDisable = - BST_CHECKED == SendDlgItemMessage(hwnd, IDC_INVIS_DISABLE, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(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) - { -#if defined(_MSC_VER) && _MSC_VER >= 1300 - _itoa_s(GroupNumber, szNumber, sizeof(szNumber), 10); -#else - _itoa(GroupNumber, szNumber, 10); - -#endif - wcscpy(szValue, DBGetContactSettingStringPAN(NULL, "CListGroups", szNumber, _T("0")).c_str()); - if(wcscmp(NewGroupName.c_str(), szValue + 1) == 0) - { - GroupExist = 1; - break; - } - GroupNumber++; - } - DBWriteContactSettingTString(NULL,pluginName, "SpammersGroup", NewGroupName.c_str()); - gbSpammersGroup = DBGetContactSettingStringPAN(NULL,pluginName,"SpammersGroup", _T("Spammers")); - if(!GroupExist && gbSpecialGroup) - CreateCListGroup((TCHAR*)gbSpammersGroup.c_str()); - } - } - DBWriteContactSettingByte(NULL, pluginName, "SpecialGroup", gbSpecialGroup = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_SPECIALGROUP, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "ExcludeContacts", gbExclude = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_EXCLUDE, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "DelExcluded", gbDelExcluded = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_REMOVE_TMP, BM_GETCHECK, 0, 0)); - DBWriteContactSettingByte(NULL, pluginName, "IgnoreURL", gbIgnoreURL = - BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNOREURL, BM_GETCHECK, 0, 0)); - } - return TRUE; - } - } - break; - } - return FALSE; -} - - -HINSTANCE hInst; -MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l) -{ - OPTIONSDIALOGPAGE odp = {0}; - odp.cbSize = sizeof(odp); - odp.ptszGroup = _T("Message Sessions"); - odp.ptszTitle = _T(pluginName); - odp.position = -1; - odp.hInstance = hInst; - odp.flags = ODPF_TCHAR; - - odp.ptszTab = _T("Main"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAIN); - odp.pfnDlgProc = MainDlgProc; - CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); - - - odp.ptszTab = _T("Messages"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_MESSAGES); - odp.pfnDlgProc = MessagesDlgProc; - CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); - - odp.ptszTab = _T("Protocols"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROTO); - odp.pfnDlgProc = ProtoDlgProc; - CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); - - odp.ptszTab = _T("Advanced"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_ADVANCED); - odp.pfnDlgProc = AdvancedDlgProc; - odp.flags = odp.flags|ODPF_EXPERTONLY; - CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); - - return 0; -} - +#define MIRANDA_VER 0x0800 +#include "headers.h" + +char * pluginDescription = "No more spam! Robots can't go! Only human beings invited!\r\n\r\n" +"This plugin works pretty simple:\r\n" +"While 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 = +_T("Spammers made me to install small anti-spam system you are now speaking with.\r\n") +_T("Please 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); + } + 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: + { + DBWriteContactSettingDword(NULL, pluginName, "maxQuestCount", gbMaxQuestCount = + GetDlgItemInt(hwnd, ID_MAXQUESTCOUNT, NULL, FALSE)); + DBWriteContactSettingByte(NULL, pluginName, "infTalkProtection", gbInfTalkProtection = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_INFTALKPROT, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "addPermanent", gbAddPermanent = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_ADDPERMANENT, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "handleAuthReq", gbHandleAuthReq = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_HANDLEAUTHREQ, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "HideContacts", gbHideContacts = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_HIDECONTACTS, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "IgnoreContacts", gbIgnoreContacts = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNORESPAMMERS, 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()); + 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, TranslateTS(defQuestion)); + SetDlgItemText(hwnd, ID_ANSWER, TranslateTS(_T("nospam"))); + SetDlgItemText(hwnd, ID_AUTHREPL, TranslateTS(_T("StopSpam: send a message and reply to a anti-spam bot question."))); + SetDlgItemText(hwnd, ID_CONGRATULATION, TranslateTS(_T("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: + { + DBWriteContactSettingTString(NULL, pluginName, "question", + GetDlgItemString(hwnd, ID_QUESTION).c_str()); + gbQuestion = DBGetContactSettingStringPAN(NULL, pluginName, "question", defQuestion); + DBWriteContactSettingTString(NULL, pluginName, "answer", + GetDlgItemString(hwnd, ID_ANSWER).c_str()); + gbAnswer = DBGetContactSettingStringPAN(NULL, pluginName, "answer", _T("nospam")); + DBWriteContactSettingTString(NULL, pluginName, "authrepl", + GetDlgItemString(hwnd, ID_AUTHREPL).c_str()); + gbAuthRepl = DBGetContactSettingStringPAN(NULL, pluginName, "authrepl", _T("StopSpam: send a message and reply to a anti-spam bot question.")); + DBWriteContactSettingTString(NULL, pluginName, "congratulation", + GetDlgItemString(hwnd, ID_CONGRATULATION).c_str()); + gbCongratulation = DBGetContactSettingStringPAN(NULL, pluginName, "congratulation", _T("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; + PROTOCOLDESCRIPTOR** pppd; + if(!CallService(MS_PROTO_ENUMPROTOCOLS, (LPARAM)&n, (WPARAM)&pppd)) + for(int i = 0; i < n; ++i) + { + SendDlgItemMessageA(hwnd, (ProtoInList(pppd[i]->szName) ? ID_USEDPROTO : ID_ALLPROTO), + LB_ADDSTRING, 0, (LPARAM)pppd[i]->szName); + } + } + 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; + } + } + DBWriteContactSettingString(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_IGNOREURL, BM_SETCHECK, gbIgnoreURL ? BST_CHECKED : BST_UNCHECKED, 0); + } + return TRUE; + case WM_COMMAND:{ + switch (LOWORD(wParam)) + { + 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_IGNOREURL: + SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); + break; + + } + } + break; + case WM_NOTIFY: + { + NMHDR* nmhdr = (NMHDR*)lParam; + switch (nmhdr->code) + { + case PSN_APPLY: + { + DBWriteContactSettingByte(NULL, pluginName, "CaseInsensitive", gbCaseInsensitive = + BST_CHECKED == SendDlgItemMessage(hwnd, IDC_CASE_INSENSITIVE, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "DisableInInvis", gbInvisDisable = + BST_CHECKED == SendDlgItemMessage(hwnd, IDC_INVIS_DISABLE, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(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) + { +#if defined(_MSC_VER) && _MSC_VER >= 1300 + _itoa_s(GroupNumber, szNumber, sizeof(szNumber), 10); +#else + _itoa(GroupNumber, szNumber, 10); + +#endif + wcscpy(szValue, DBGetContactSettingStringPAN(NULL, "CListGroups", szNumber, _T("0")).c_str()); + if(wcscmp(NewGroupName.c_str(), szValue + 1) == 0) + { + GroupExist = 1; + break; + } + GroupNumber++; + } + DBWriteContactSettingTString(NULL,pluginName, "SpammersGroup", NewGroupName.c_str()); + gbSpammersGroup = DBGetContactSettingStringPAN(NULL,pluginName,"SpammersGroup", _T("Spammers")); + if(!GroupExist && gbSpecialGroup) + CreateCListGroup((TCHAR*)gbSpammersGroup.c_str()); + } + } + DBWriteContactSettingByte(NULL, pluginName, "SpecialGroup", gbSpecialGroup = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_SPECIALGROUP, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "ExcludeContacts", gbExclude = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_EXCLUDE, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "DelExcluded", gbDelExcluded = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_REMOVE_TMP, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "IgnoreURL", gbIgnoreURL = + BST_CHECKED == SendDlgItemMessage(hwnd, ID_IGNOREURL, BM_GETCHECK, 0, 0)); + } + return TRUE; + } + } + break; + } + return FALSE; +} + + +HINSTANCE hInst; +MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l) +{ + OPTIONSDIALOGPAGE odp = {0}; + odp.cbSize = sizeof(odp); + odp.ptszGroup = _T("Message Sessions"); + odp.ptszTitle = _T(pluginName); + odp.position = -1; + odp.hInstance = hInst; + odp.flags = ODPF_TCHAR; + + odp.ptszTab = _T("Main"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAIN); + odp.pfnDlgProc = MainDlgProc; + CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); + + + odp.ptszTab = _T("Messages"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_MESSAGES); + odp.pfnDlgProc = MessagesDlgProc; + CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); + + odp.ptszTab = _T("Protocols"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROTO); + odp.pfnDlgProc = ProtoDlgProc; + CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); + + odp.ptszTab = _T("Advanced"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_ADVANCED); + odp.pfnDlgProc = AdvancedDlgProc; + odp.flags = odp.flags|ODPF_EXPERTONLY; + CallService(MS_OPT_ADDPAGE, w, (LPARAM)&odp); + + return 0; +} + diff --git a/resource.h b/resource.h index ad7dab5..ed4a257 100644 --- a/resource.h +++ b/resource.h @@ -1,54 +1,54 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by stopspam.rc -// -#define IDD_MESSAGES 101 -#define IDD_MAIN 103 -#define ID_DESCRIPTION 1001 -#define ID_QUESTION 1002 -#define ID_ANSWER 1003 -#define ID_CONGRATULATION 1004 -#define ID_RESTOREDEFAULTS 1005 -#define ID_ADD 1005 -#define ID_ANSWER2 1007 -#define ID_AUTHREPL 1007 -#define ID_ALLPROTO 1008 -#define IDD_PROTO 1008 -#define ID_MAXQUESTCOUNT 1008 -#define ID_REMOVE 1009 -#define ID_SPECIALGROUPNAME 1009 -#define IDD_ADVANCED 1009 -#define ID_USEDPROTO 1010 -#define ID_REMOVEALL 1011 -#define ID_ADDALL 1012 -#define ID_INFTALKPROT 1013 -#define ID_ADDPERMANENT 1014 -#define ID_ADDPERMANENT2 1015 -#define ID_HANDLEAUTHREQ 1015 -#define ID_DOS_INTEGRATION 1016 -#define ID_SPECIALGROUP 1017 -#define IDC_BUTTON1 1017 -#define IDC_VARS 1017 -#define ID_HIDECONTACTS 1018 -#define IDC_CASE_INSENSITIVE 1018 -#define ID_IGNORESPAMMERS 1019 -#define IDC_CHECK2 1019 -#define IDC_INVIS_DISABLE 1019 -#define ID_REMOVE_TMP 1020 -#define IDC_CUSTOM1 1020 -#define ID_REMOVE_TMP2 1021 -#define ID_EXCLUDE 1021 -#define ID_ADDPERMANENT3 1022 -#define ID_DEL_NO_IN_LIST 1022 -#define ID_IGNOREURL 1023 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 104 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1021 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by stopspam.rc +// +#define IDD_MESSAGES 101 +#define IDD_MAIN 103 +#define ID_DESCRIPTION 1001 +#define ID_QUESTION 1002 +#define ID_ANSWER 1003 +#define ID_CONGRATULATION 1004 +#define ID_RESTOREDEFAULTS 1005 +#define ID_ADD 1005 +#define ID_ANSWER2 1007 +#define ID_AUTHREPL 1007 +#define ID_ALLPROTO 1008 +#define IDD_PROTO 1008 +#define ID_MAXQUESTCOUNT 1008 +#define ID_REMOVE 1009 +#define ID_SPECIALGROUPNAME 1009 +#define IDD_ADVANCED 1009 +#define ID_USEDPROTO 1010 +#define ID_REMOVEALL 1011 +#define ID_ADDALL 1012 +#define ID_INFTALKPROT 1013 +#define ID_ADDPERMANENT 1014 +#define ID_ADDPERMANENT2 1015 +#define ID_HANDLEAUTHREQ 1015 +#define ID_DOS_INTEGRATION 1016 +#define ID_SPECIALGROUP 1017 +#define IDC_BUTTON1 1017 +#define IDC_VARS 1017 +#define ID_HIDECONTACTS 1018 +#define IDC_CASE_INSENSITIVE 1018 +#define ID_IGNORESPAMMERS 1019 +#define IDC_CHECK2 1019 +#define IDC_INVIS_DISABLE 1019 +#define ID_REMOVE_TMP 1020 +#define IDC_CUSTOM1 1020 +#define ID_REMOVE_TMP2 1021 +#define ID_EXCLUDE 1021 +#define ID_ADDPERMANENT3 1022 +#define ID_DEL_NO_IN_LIST 1022 +#define ID_IGNOREURL 1023 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 104 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1021 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/stopspam.cpp b/stopspam.cpp index d071a08..890d559 100644 --- a/stopspam.cpp +++ b/stopspam.cpp @@ -1,250 +1,250 @@ -#include "headers.h" - -MIRANDA_HOOK_EVENT(ME_DB_CONTACT_ADDED, w, l) -{ - return 0; -} - - -MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam) -{ - HANDLE hContact = (HANDLE)wParam; - HANDLE hDbEvent = (HANDLE)lParam; - - DBEVENTINFO dbei = {0}; - dbei.cbSize = sizeof(dbei); - dbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0); - if(-1 == dbei.cbBlob) - return 0; - - dbei.pBlob = new BYTE[dbei.cbBlob]; - CallService(MS_DB_EVENT_GET, lParam, (LPARAM)&dbei); - - // if event is in protocol that is not despammed - if(!ProtoInList(dbei.szModule)) { - delete dbei.pBlob; - return 0; - } - - // event is an auth request - if(gbHandleAuthReq) - { - if(!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) - { - HANDLE hcntct; - hcntct=*((PHANDLE)(dbei.pBlob+sizeof(DWORD))); - - - // if request is from unknown or not marked Answered contact - - int a = DBGetContactSettingByte(hcntct, "CList", "NotOnList", 0); - int b = !DBGetContactSettingByte(hcntct, pluginName, "Answered", 0); - - if(a && b)// - { - // ...send message - - if(gbHideContacts) - DBWriteContactSettingByte(hcntct, "CList", "Hidden", 1); - if(gbSpecialGroup) - DBWriteContactSettingTString(hcntct, "CList", "Group", gbSpammersGroup.c_str()); - - BYTE msg = 1; - if(gbInvisDisable) - { - if(CallProtoService(dbei.szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE) - msg = 0; - else if(DBGetContactSettingWord(hContact,dbei.szModule,"ApparentMode",0) == ID_STATUS_OFFLINE) - msg = 0; //is it useful ? - } - if(msg) - // int a = CallService(allowService.c_str(), (WPARAM)hDbEvent, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str())); - CallContactService(hcntct, PSS_MESSAGE, PREF_TCHAR, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str())); - - delete dbei.pBlob; - return 1; - } - } - } - delete dbei.pBlob; - return 0; -} - -MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) -{ - HANDLE hContact = (HANDLE)w; - DBEVENTINFO * dbei = (DBEVENTINFO*)l; - - - // if event is in protocol that is not despammed - if(!ProtoInList(dbei->szModule)) - { - // ...let the event go its way - return 0; - } - //do not check excluded contact - - if(DBGetContactSettingByte(hContact, pluginName, "Answered", 0)) - return 0; - if(DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) - { - if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) - DBDeleteContactSetting(hContact, pluginName, "Excluded"); - return 0; - } - //we want block not only messages, i seen many types other eventtype flood - if(dbei->flags & DBEF_READ) - // ...let the event go its way - return 0; - //mark contact which we trying to contact for exclude from check - if((dbei->flags & DBEF_SENT) && DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) - && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount) && gbExclude) - { - DBWriteContactSettingByte(hContact, pluginName, "Excluded", 1); - return 0; - } - // if message is from known or marked Answered contact - if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) - // ...let the event go its way - return 0; - // if message is corrupted or empty it cannot be an answer. - if(!dbei->cbBlob || !dbei->pBlob) - // reject processing of the event - return 1; - - tstring message; - - if(dbei->flags & DBEF_UTF){ - WCHAR* msg_u; - char* msg_a = mir_strdup(( char* )dbei->pBlob ); - mir_utf8decode( msg_a, &msg_u ); -#ifdef _UNICODE - message = msg_u; -#else - message = mir_u2a(msg_u); -#endif - } - else{ -#ifdef _UNICODE - message = mir_a2u((char*)(dbei->pBlob)); -#else - message = (char*)(dbei->pBlob); -#endif - } - - // if message contains right answer... - - BYTE msg = 1; - if(gbInvisDisable) - { - if(CallProtoService(dbei->szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE) - msg = 0; - else if(DBGetContactSettingWord(hContact,dbei->szModule,"ApparentMode",0) == ID_STATUS_OFFLINE) - msg = 0; //is it useful ? - } - if(gbCaseInsensitive?(!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))):( !_tcscmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str())))) - { - // unhide contact - DBDeleteContactSetting(hContact, "CList", "Hidden"); - - // mark contact as Answered - DBWriteContactSettingByte(hContact, pluginName, "Answered", 1); - - //add contact permanently - if(gbAddPermanent) //do not use this ) - DBDeleteContactSetting(hContact, "CList", "NotOnList"); - - // send congratulation - if(msg) - { -#ifdef _UNICODE - char * buf=mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str()); - CallContactService(hContact, PSS_MESSAGE, PREF_TCHAR, (LPARAM)buf); - mir_free(buf); -#else - CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)GetCongratulation().c_str()); -#endif - } - - // process the event - return 0; - } - - if(gbIgnoreURL) - if((message.find_first_of(_T("http"),0) != std::string::npos) || (message.find_first_of(_T("www"),0) != std::string::npos) || (message.find_first_of(_T(".ru"),0) != std::string::npos) || (message.find_first_of(_T(".com"),0) != std::string::npos) || (message.find_first_of(_T(".de"),0) != std::string::npos) || (message.find_first_of(_T(".cz"),0) != std::string::npos) || (message.find_first_of(_T(".org"),0) != std::string::npos) || (message.find_first_of(_T(".net"),0) != std::string::npos) || (message.find_first_of(_T(".su"),0) != std::string::npos)) - ; - // if message message does not contain infintite talk protection prefix - // and question count for this contact is less then maximum - else if(msg) - { - if((!gbInfTalkProtection || tstring::npos==message.find(_T("StopSpam automatic message:\r\n"))) - && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount)) - { - // send question - tstring q = _T("StopSpam automatic message:\r\n") + variables_parse(gbQuestion, hContact); - -#ifdef _UNICODE - char * buf=mir_utf8encodeW(q.c_str()); - CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)buf); - mir_free(buf); -#else - CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)q.c_str()); -#endif - - // increment question count - DWORD questCount = DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0); - DBWriteContactSettingDword(hContact, pluginName, "QuestionCount", questCount + 1); - } - else - { - if (gbDosServiceExist) - { - if(gbDosServiceIntegration) - { - int i; - i = rand()%255*13; - CallService(MS_DOS_SERVICE, (WPARAM)hContact, (LPARAM)i); - } - } - if(gbIgnoreContacts) - { - DBWriteContactSettingDword(hContact, "Ignore", "Mask1", 0x0000007F); - } - } - } - if(gbHideContacts) - DBWriteContactSettingByte(hContact, "CList", "Hidden", 1); - if(gbSpecialGroup) - DBWriteContactSettingTString(hContact, "CList", "Group", gbSpammersGroup.c_str()); - DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1); - - // save message from contact - dbei->flags |= DBEF_READ; - CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)dbei); - - // reject processing of the event - return 1; -} - - -MIRANDA_HOOK_EVENT(ME_DB_CONTACT_SETTINGCHANGED, w, l) -{ - HANDLE hContact = (HANDLE)w; - DBCONTACTWRITESETTING * cws = (DBCONTACTWRITESETTING*)l; - - // if CList/NotOnList is being deleted then remove answeredSetting - if(strcmp(cws->szModule, "CList")) - return 0; - if(strcmp(cws->szSetting, "NotOnList")) - return 0; - if(!cws->value.type) - { - DBDeleteContactSetting(hContact, pluginName, "Answered"); - DBDeleteContactSetting(hContact, pluginName, "QuestionCount"); - } - - return 0; -} - - - +#include "headers.h" + +MIRANDA_HOOK_EVENT(ME_DB_CONTACT_ADDED, w, l) +{ + return 0; +} + + +MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam) +{ + HANDLE hContact = (HANDLE)wParam; + HANDLE hDbEvent = (HANDLE)lParam; + + DBEVENTINFO dbei = {0}; + dbei.cbSize = sizeof(dbei); + dbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0); + if(-1 == dbei.cbBlob) + return 0; + + dbei.pBlob = new BYTE[dbei.cbBlob]; + CallService(MS_DB_EVENT_GET, lParam, (LPARAM)&dbei); + + // if event is in protocol that is not despammed + if(!ProtoInList(dbei.szModule)) { + delete dbei.pBlob; + return 0; + } + + // event is an auth request + if(gbHandleAuthReq) + { + if(!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) + { + HANDLE hcntct; + hcntct=*((PHANDLE)(dbei.pBlob+sizeof(DWORD))); + + + // if request is from unknown or not marked Answered contact + + int a = DBGetContactSettingByte(hcntct, "CList", "NotOnList", 0); + int b = !DBGetContactSettingByte(hcntct, pluginName, "Answered", 0); + + if(a && b)// + { + // ...send message + + if(gbHideContacts) + DBWriteContactSettingByte(hcntct, "CList", "Hidden", 1); + if(gbSpecialGroup) + DBWriteContactSettingTString(hcntct, "CList", "Group", gbSpammersGroup.c_str()); + + BYTE msg = 1; + if(gbInvisDisable) + { + if(CallProtoService(dbei.szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE) + msg = 0; + else if(DBGetContactSettingWord(hContact,dbei.szModule,"ApparentMode",0) == ID_STATUS_OFFLINE) + msg = 0; //is it useful ? + } + if(msg) + // int a = CallService(allowService.c_str(), (WPARAM)hDbEvent, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str())); + CallContactService(hcntct, PSS_MESSAGE, PREF_TCHAR, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str())); + + delete dbei.pBlob; + return 1; + } + } + } + delete dbei.pBlob; + return 0; +} + +MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) +{ + HANDLE hContact = (HANDLE)w; + DBEVENTINFO * dbei = (DBEVENTINFO*)l; + + + // if event is in protocol that is not despammed + if(!ProtoInList(dbei->szModule)) + { + // ...let the event go its way + return 0; + } + //do not check excluded contact + + if(DBGetContactSettingByte(hContact, pluginName, "Answered", 0)) + return 0; + if(DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) + { + if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) + DBDeleteContactSetting(hContact, pluginName, "Excluded"); + return 0; + } + //we want block not only messages, i seen many types other eventtype flood + if(dbei->flags & DBEF_READ) + // ...let the event go its way + return 0; + //mark contact which we trying to contact for exclude from check + if((dbei->flags & DBEF_SENT) && DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) + && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount) && gbExclude) + { + DBWriteContactSettingByte(hContact, pluginName, "Excluded", 1); + return 0; + } + // if message is from known or marked Answered contact + if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) + // ...let the event go its way + return 0; + // if message is corrupted or empty it cannot be an answer. + if(!dbei->cbBlob || !dbei->pBlob) + // reject processing of the event + return 1; + + tstring message; + + if(dbei->flags & DBEF_UTF){ + WCHAR* msg_u; + char* msg_a = mir_strdup(( char* )dbei->pBlob ); + mir_utf8decode( msg_a, &msg_u ); +#ifdef _UNICODE + message = msg_u; +#else + message = mir_u2a(msg_u); +#endif + } + else{ +#ifdef _UNICODE + message = mir_a2u((char*)(dbei->pBlob)); +#else + message = (char*)(dbei->pBlob); +#endif + } + + // if message contains right answer... + + BYTE msg = 1; + if(gbInvisDisable) + { + if(CallProtoService(dbei->szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE) + msg = 0; + else if(DBGetContactSettingWord(hContact,dbei->szModule,"ApparentMode",0) == ID_STATUS_OFFLINE) + msg = 0; //is it useful ? + } + if(gbCaseInsensitive?(!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))):( !_tcscmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str())))) + { + // unhide contact + DBDeleteContactSetting(hContact, "CList", "Hidden"); + + // mark contact as Answered + DBWriteContactSettingByte(hContact, pluginName, "Answered", 1); + + //add contact permanently + if(gbAddPermanent) //do not use this ) + DBDeleteContactSetting(hContact, "CList", "NotOnList"); + + // send congratulation + if(msg) + { +#ifdef _UNICODE + char * buf=mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str()); + CallContactService(hContact, PSS_MESSAGE, PREF_TCHAR, (LPARAM)buf); + mir_free(buf); +#else + CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)GetCongratulation().c_str()); +#endif + } + + // process the event + return 0; + } + + if(gbIgnoreURL) + if((message.find_first_of(_T("http"),0) != std::string::npos) || (message.find_first_of(_T("www"),0) != std::string::npos) || (message.find_first_of(_T(".ru"),0) != std::string::npos) || (message.find_first_of(_T(".com"),0) != std::string::npos) || (message.find_first_of(_T(".de"),0) != std::string::npos) || (message.find_first_of(_T(".cz"),0) != std::string::npos) || (message.find_first_of(_T(".org"),0) != std::string::npos) || (message.find_first_of(_T(".net"),0) != std::string::npos) || (message.find_first_of(_T(".su"),0) != std::string::npos)) + ; + // if message message does not contain infintite talk protection prefix + // and question count for this contact is less then maximum + else if(msg) + { + if((!gbInfTalkProtection || tstring::npos==message.find(_T("StopSpam automatic message:\r\n"))) + && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount)) + { + // send question + tstring q = _T("StopSpam automatic message:\r\n") + variables_parse(gbQuestion, hContact); + +#ifdef _UNICODE + char * buf=mir_utf8encodeW(q.c_str()); + CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)buf); + mir_free(buf); +#else + CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)q.c_str()); +#endif + + // increment question count + DWORD questCount = DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0); + DBWriteContactSettingDword(hContact, pluginName, "QuestionCount", questCount + 1); + } + else + { + if (gbDosServiceExist) + { + if(gbDosServiceIntegration) + { + int i; + i = rand()%255*13; + CallService(MS_DOS_SERVICE, (WPARAM)hContact, (LPARAM)i); + } + } + if(gbIgnoreContacts) + { + DBWriteContactSettingDword(hContact, "Ignore", "Mask1", 0x0000007F); + } + } + } + if(gbHideContacts) + DBWriteContactSettingByte(hContact, "CList", "Hidden", 1); + if(gbSpecialGroup) + DBWriteContactSettingTString(hContact, "CList", "Group", gbSpammersGroup.c_str()); + DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1); + + // save message from contact + dbei->flags |= DBEF_READ; + CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)dbei); + + // reject processing of the event + return 1; +} + + +MIRANDA_HOOK_EVENT(ME_DB_CONTACT_SETTINGCHANGED, w, l) +{ + HANDLE hContact = (HANDLE)w; + DBCONTACTWRITESETTING * cws = (DBCONTACTWRITESETTING*)l; + + // if CList/NotOnList is being deleted then remove answeredSetting + if(strcmp(cws->szModule, "CList")) + return 0; + if(strcmp(cws->szSetting, "NotOnList")) + return 0; + if(!cws->value.type) + { + DBDeleteContactSetting(hContact, pluginName, "Answered"); + DBDeleteContactSetting(hContact, pluginName, "QuestionCount"); + } + + return 0; +} + + + diff --git a/stopspam.h b/stopspam.h index fd76f99..ea7a963 100644 --- a/stopspam.h +++ b/stopspam.h @@ -1,23 +1,23 @@ - -extern BOOL gbDosServiceExist; -extern BOOL gbVarsServiceExist; -extern DWORD gbMaxQuestCount; -extern BOOL gbInfTalkProtection; -extern BOOL gbAddPermanent; -extern BOOL gbHandleAuthReq; -extern BOOL gbSpecialGroup; -extern BOOL gbHideContacts; -extern BOOL gbIgnoreContacts; -extern BOOL gbExclude; -extern BOOL gbDelExcluded; -extern BOOL gbDosServiceIntegration; -extern BOOL gbDelNotInList; -extern BOOL gbCaseInsensitive; -extern BOOL gbInvisDisable; -extern BOOL gbIgnoreURL; -extern tstring gbSpammersGroup; -extern tstring gbQuestion; -extern tstring gbAnswer; -extern tstring gbCongratulation; -extern std::wstring gbAuthRepl; - + +extern BOOL gbDosServiceExist; +extern BOOL gbVarsServiceExist; +extern DWORD gbMaxQuestCount; +extern BOOL gbInfTalkProtection; +extern BOOL gbAddPermanent; +extern BOOL gbHandleAuthReq; +extern BOOL gbSpecialGroup; +extern BOOL gbHideContacts; +extern BOOL gbIgnoreContacts; +extern BOOL gbExclude; +extern BOOL gbDelExcluded; +extern BOOL gbDosServiceIntegration; +extern BOOL gbDelNotInList; +extern BOOL gbCaseInsensitive; +extern BOOL gbInvisDisable; +extern BOOL gbIgnoreURL; +extern tstring gbSpammersGroup; +extern tstring gbQuestion; +extern tstring gbAnswer; +extern tstring gbCongratulation; +extern std::wstring gbAuthRepl; + diff --git a/utilities.cpp b/utilities.cpp index 4910b00..d935cae 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1,165 +1,165 @@ -#include "headers.h" - -tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue) -{ - DBVARIANT dbv; - //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) - if(DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) - return errorValue; -// if(DBVT_TCHAR == dbv.type ) - errorValue = dbv.ptszVal; - DBFreeVariant(&dbv); - return errorValue; -} - -std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue) -{ - DBVARIANT dbv; - //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) - if(DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) - return errorValue; -// if(DBVT_ASCIIZ == dbv.type ) - errorValue = dbv.pszVal; - DBFreeVariant(&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; - CLIST_INTERFACE *clint = NULL; - - if (ServiceExists(MS_CLIST_RETRIEVE_INTERFACE)) - clint = (CLIST_INTERFACE*)CallService(MS_CLIST_RETRIEVE_INTERFACE, 0, 0); - - hGroup = CallService(MS_CLIST_GROUPCREATE, 0, 0); - - TCHAR* usTmp = szGroupName; - - clint->pfnRenameGroup(hGroup, usTmp); - - return hGroup; -} - - -void RemoveExcludedUsers() -{ - HANDLE hContact; - HANDLE ToRemove[4096]; - int i = 0,a = 0; - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - if(hContact) - { - do - { - if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) - { - ToRemove[i] = hContact; - i++; - } - } - while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); - ToRemove[i] = INVALID_HANDLE_VALUE; - while(ToRemove[a] != INVALID_HANDLE_VALUE) - { - CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); - a++; - } - } -} - -void RemoveTemporaryUsers() -{ - HANDLE hContact; - HANDLE ToRemove[4096]; - int i = 0, a= 0; - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - if(hContact) - { - do - { - if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) - { - ToRemove[i] = hContact; - i++; - } - } - while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); - ToRemove[i] = INVALID_HANDLE_VALUE; - while(ToRemove[a] != INVALID_HANDLE_VALUE) - { - CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); - a++; - } - } -} -int RemoveTmp(WPARAM,LPARAM) -{ - RemoveTemporaryUsers(); - 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; - CallService(MS_VARS_FREEMEMORY, (WPARAM)tszParsed, 0); - return tstrResult; - } - } - return tstrFormat; -} - -// case-insensitive _tcsstr -//by nullbie as i remember... -#define NEWTSTR_MALLOC(A) (A==NULL)?NULL:_tcscpy((TCHAR*)malloc(sizeof(TCHAR)*(_tcslen(A)+1)),A) -const int Stricmp(const TCHAR *str, const TCHAR *substr) -{ - int i; - 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; -} +#include "headers.h" + +tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue) +{ + DBVARIANT dbv; + //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) + if(DBGetContactSettingTString(hContact, szModule, szSetting, &dbv)) + return errorValue; +// if(DBVT_TCHAR == dbv.type ) + errorValue = dbv.ptszVal; + DBFreeVariant(&dbv); + return errorValue; +} + +std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue) +{ + DBVARIANT dbv; + //if(DBGetContactSetting(hContact, szModule, szSetting, &dbv)) + if(DBGetContactSettingString(hContact, szModule, szSetting, &dbv)) + return errorValue; +// if(DBVT_ASCIIZ == dbv.type ) + errorValue = dbv.pszVal; + DBFreeVariant(&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; + CLIST_INTERFACE *clint = NULL; + + if (ServiceExists(MS_CLIST_RETRIEVE_INTERFACE)) + clint = (CLIST_INTERFACE*)CallService(MS_CLIST_RETRIEVE_INTERFACE, 0, 0); + + hGroup = CallService(MS_CLIST_GROUPCREATE, 0, 0); + + TCHAR* usTmp = szGroupName; + + clint->pfnRenameGroup(hGroup, usTmp); + + return hGroup; +} + + +void RemoveExcludedUsers() +{ + HANDLE hContact; + HANDLE ToRemove[4096]; + int i = 0,a = 0; + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + if(hContact) + { + do + { + if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) + { + ToRemove[i] = hContact; + i++; + } + } + while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); + ToRemove[i] = INVALID_HANDLE_VALUE; + while(ToRemove[a] != INVALID_HANDLE_VALUE) + { + CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); + a++; + } + } +} + +void RemoveTemporaryUsers() +{ + HANDLE hContact; + HANDLE ToRemove[4096]; + int i = 0, a= 0; + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + if(hContact) + { + do + { + if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)) + { + ToRemove[i] = hContact; + i++; + } + } + while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact, 0)); + ToRemove[i] = INVALID_HANDLE_VALUE; + while(ToRemove[a] != INVALID_HANDLE_VALUE) + { + CallService(MS_DB_CONTACT_DELETE, (WPARAM)ToRemove[a], 0); + a++; + } + } +} +int RemoveTmp(WPARAM,LPARAM) +{ + RemoveTemporaryUsers(); + 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; + CallService(MS_VARS_FREEMEMORY, (WPARAM)tszParsed, 0); + return tstrResult; + } + } + return tstrFormat; +} + +// case-insensitive _tcsstr +//by nullbie as i remember... +#define NEWTSTR_MALLOC(A) (A==NULL)?NULL:_tcscpy((TCHAR*)malloc(sizeof(TCHAR)*(_tcslen(A)+1)),A) +const int Stricmp(const TCHAR *str, const TCHAR *substr) +{ + int i; + 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; +} diff --git a/utilities.h b/utilities.h index c913491..04866f7 100644 --- a/utilities.h +++ b/utilities.h @@ -1,8 +1,8 @@ -tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue); -std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue); -tstring &GetDlgItemString(HWND hwnd, int id); -std::string &GetProtoList(); -bool ProtoInList(std::string proto); -void RemoveExcludedUsers(); -tstring variables_parse(tstring const &tstrFormat, HANDLE hContact); -const int Stricmp(const TCHAR *str, const TCHAR *substr); +tstring DBGetContactSettingStringPAN(HANDLE hContact, char const * szModule, char const * szSetting, tstring errorValue); +std::string DBGetContactSettingStringPAN_A(HANDLE hContact, char const * szModule, char const * szSetting, std::string errorValue); +tstring &GetDlgItemString(HWND hwnd, int id); +std::string &GetProtoList(); +bool ProtoInList(std::string proto); +void RemoveExcludedUsers(); +tstring variables_parse(tstring const &tstrFormat, HANDLE hContact); +const int Stricmp(const TCHAR *str, const TCHAR *substr); diff --git a/version.h b/version.h index 9f7c792..1641ff5 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ -#ifndef VERSION_H_CAA3B062_9BEE_40e6_A9F9_20BBF467731B -#define VERSION_H_CAA3B062_9BEE_40e6_A9F9_20BBF467731B - -#define SUBWCREV (0) - -#endif +#ifndef VERSION_H_CAA3B062_9BEE_40e6_A9F9_20BBF467731B +#define VERSION_H_CAA3B062_9BEE_40e6_A9F9_20BBF467731B + +#define SUBWCREV (0) + +#endif -- cgit v1.2.3