diff options
-rw-r--r-- | stopspam.cpp | 17 | ||||
-rw-r--r-- | stopspam_10.vcxproj | 2 | ||||
-rw-r--r-- | utilities.cpp | 81 | ||||
-rw-r--r-- | utilities.h | 5 |
4 files changed, 64 insertions, 41 deletions
diff --git a/stopspam.cpp b/stopspam.cpp index 07aee1e..e0ee3f6 100644 --- a/stopspam.cpp +++ b/stopspam.cpp @@ -49,13 +49,8 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam) DBWriteContactSettingTString(hcntct, "CList", "Group", gbSpammersGroup.c_str()); BYTE msg = 1; if(gbIgnoreURL){ - TCHAR* EventText = ReqGetText(&dbei); //work only UTF, else return NULL - if(EventText&&_tcslen(EventText) > 0) - if(Stristr(EventText, _T("http")) || Stristr(EventText, _T("www")) || Stristr(EventText, _T(".ru")) || Stristr(EventText, _T(".com")) || Stristr(EventText, _T(".de")) || Stristr(EventText, _T(".cz")) || Stristr(EventText, _T(".org")) || Stristr(EventText, _T(".net")) || Stristr(EventText, _T(".su"))) - { - mir_free(EventText); - msg=0; - }; + TCHAR* EventText = ReqGetText(&dbei); //else return NULL + msg=!IsUrlContains(EventText); mir_free(EventText); }; if(gbInvisDisable) @@ -202,13 +197,11 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) } 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)) - ; + // URL contains check + msg=(msg&&gbIgnoreURL)?(!IsUrlContains((TCHAR *) message.c_str())):msg; // if message message does not contain infintite talk protection prefix // and question count for this contact is less then maximum - else if(msg) + if(msg) { if((!gbInfTalkProtection || tstring::npos==message.find(_T("StopSpam automatic message:\r\n"))) && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount)) diff --git a/stopspam_10.vcxproj b/stopspam_10.vcxproj index 6fbd3bf..925b56c 100644 --- a/stopspam_10.vcxproj +++ b/stopspam_10.vcxproj @@ -262,7 +262,7 @@ </ClCompile> <Link> <OutputFile>$(OutDir)$(ProjectName).dll</OutputFile> - <GenerateDebugInformation>true</GenerateDebugInformation> + <GenerateDebugInformation>false</GenerateDebugInformation> <SubSystem>Windows</SubSystem> <OptimizeReferences>true</OptimizeReferences> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/utilities.cpp b/utilities.cpp index 8349430..b7475f6 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -164,7 +164,7 @@ const int Stricmp(const TCHAR *str, const TCHAR *substr) return i; } - +/* const int Stristr(const TCHAR *str, const TCHAR *substr) { int i = 0; @@ -182,36 +182,65 @@ const int Stristr(const TCHAR *str, const TCHAR *substr) return i; } - +*/ TCHAR* ReqGetText(DBEVENTINFO* dbei) { if ( !dbei->pBlob ) return 0; - if ( dbei->flags & DBEF_UTF ) // UTF only - { - char * ptr=(char *)&dbei->pBlob[sizeof(DWORD)*2]; - int len=dbei->cbBlob-sizeof(DWORD)*2; - int i=0; + char * ptr=(char *)&dbei->pBlob[sizeof(DWORD)*2]; + int len=dbei->cbBlob-sizeof(DWORD)*2; + int i=0; - while(len&&(i<4)) - { - if(!ptr[0]) i++; - ptr++; - len--; - }; - - if(len){ - char * tstr=(char *)mir_alloc(len+1); - memcpy(tstr, ptr, len); - tstr[len]=0; - WCHAR* msg = NULL; - //mir_utf8decodecp( tstr, egt->codepage, &msg ); - msg=mir_utf8decodeW(tstr); - mir_free(tstr); - return (TCHAR *)msg; - }; - - } + 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]= + { + _T("http"), + _T("www"), + _T(".ru"), + _T(".com"), + _T(".de"), + _T(".cz"), + _T(".org"), + _T(".net"), + _T(".su"), + _T(".ua"), + _T(".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; +}
\ No newline at end of file diff --git a/utilities.h b/utilities.h index ed3159e..ee56cc2 100644 --- a/utilities.h +++ b/utilities.h @@ -6,5 +6,6 @@ bool ProtoInList(std::string proto); void RemoveExcludedUsers(); tstring variables_parse(tstring const &tstrFormat, HANDLE hContact); const int Stricmp(const TCHAR *str, const TCHAR *substr); -const int Stristr(const TCHAR *str, const TCHAR *substr); -TCHAR* ReqGetText(DBEVENTINFO* dbei);
\ No newline at end of file +//const int Stristr(const TCHAR *str, const TCHAR *substr); +TCHAR* ReqGetText(DBEVENTINFO* dbei); +BOOL IsUrlContains(TCHAR * Str);
\ No newline at end of file |