diff options
author | George Hazan <george.hazan@gmail.com> | 2023-09-27 12:39:05 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-09-27 12:39:05 +0300 |
commit | d484c7e92f0bdadfe93689d3cdaa501650f15740 (patch) | |
tree | 62f83e4bdcd7fe64f260602358fb63566a33038b /plugins/StopSpamMod/src | |
parent | 82d166baff3cf2926cf8e95c8b41a43cae612c0a (diff) |
code cleaning
Diffstat (limited to 'plugins/StopSpamMod/src')
-rw-r--r-- | plugins/StopSpamMod/src/stopspam.cpp | 42 | ||||
-rw-r--r-- | plugins/StopSpamMod/src/utilities.cpp | 75 | ||||
-rw-r--r-- | plugins/StopSpamMod/src/utilities.h | 11 |
3 files changed, 51 insertions, 77 deletions
diff --git a/plugins/StopSpamMod/src/stopspam.cpp b/plugins/StopSpamMod/src/stopspam.cpp index 4b52c0b6e5..ae9e4bcb9e 100644 --- a/plugins/StopSpamMod/src/stopspam.cpp +++ b/plugins/StopSpamMod/src/stopspam.cpp @@ -17,7 +17,7 @@ #include "stdafx.h" -int OnDbEventAdded(WPARAM hContact, LPARAM hDbEvent) +int OnDbEventAdded(WPARAM, LPARAM hDbEvent) { DB::EventInfo dbei(hDbEvent); if (!dbei) @@ -30,34 +30,32 @@ int OnDbEventAdded(WPARAM hContact, LPARAM hDbEvent) // event is an auth request if (gbHandleAuthReq) { if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) { - MCONTACT hcntct = DbGetAuthEventContact(&dbei); + DB::AUTH_BLOB blob(dbei.pBlob); // if request is from unknown or not marked Answered contact - int a = !Contact::OnList(hcntct); - int b = !g_plugin.getByte(hcntct, "Answered"); - - if (a && b) { - // ...send message - + MCONTACT hContact = blob.get_contact(); + if (!Contact::OnList(hContact) && !g_plugin.getByte(hContact, "Answered")) { if (gbHideContacts) - Contact::Hide(hcntct); + Contact::Hide(hContact); + if (gbSpecialGroup) - Clist_SetGroup(hcntct, gbSpammersGroup.c_str()); - uint8_t msg = 1; - if (gbIgnoreURL) { - wchar_t* EventText = ReqGetText(&dbei); //else return NULL - msg = !IsUrlContains(EventText); - mir_free(EventText); - } + Clist_SetGroup(hContact, gbSpammersGroup.c_str()); + + bool isMessage = true; + if (gbIgnoreURL) + isMessage = !IsUrlContains(Utf2T(blob.get_reason())); + if (gbInvisDisable) { if (Proto_GetStatus(dbei.szModule) == ID_STATUS_INVISIBLE) - msg = 0; + isMessage = false; else if (db_get_w(hContact, dbei.szModule, "ApparentMode", 0) == ID_STATUS_OFFLINE) - msg = 0; //is it useful ? + isMessage = false; //is it useful ? } - if (msg) { - ptrA buff(mir_utf8encodeW(variables_parse(gbAuthRepl, hcntct).c_str())); - ProtoChainSend(hcntct, PSS_MESSAGE, 0, (LPARAM)buff); + + // ...send message + if (isMessage) { + ptrA buff(mir_utf8encodeW(variables_parse(gbAuthRepl, hContact).c_str())); + ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buff); } return 1; } @@ -191,7 +189,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) return 0; } // URL contains check - bSendMsg = (bSendMsg && gbIgnoreURL) ? (!IsUrlContains((wchar_t *)message.c_str())) : bSendMsg; + bSendMsg = (bSendMsg && gbIgnoreURL) ? (!IsUrlContains(message.c_str())) : bSendMsg; // if message message does not contain infintite talk protection prefix // and question count for this contact is less then maximum if (bSendMsg) { diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index b2f72ccc48..da3e855812 100644 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -125,64 +125,41 @@ const int Stricmp(const wchar_t *str, const wchar_t *substr) return i;
}
-wchar_t* ReqGetText(DBEVENTINFO* dbei)
-{
- if (!dbei->pBlob)
- return nullptr;
-
- char * ptr = (char *)&dbei->pBlob[sizeof(uint32_t) * 2];
- int len = dbei->cbBlob - sizeof(uint32_t) * 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_t* msg = nullptr;
- msg = (dbei->flags&DBEF_UTF) ? mir_utf8decodeW(tstr) : mir_a2u(tstr);
- mir_free(tstr);
- return (wchar_t *)msg;
- };
- return nullptr;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
-BOOL IsUrlContains(wchar_t * Str)
+static const wchar_t *URL[] =
{
- const int CountUrl = 11;
- const wchar_t 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 && mir_wstrlen(Str) > 0) {
+ L"http",
+ L"www",
+ L".ru",
+ L".com",
+ L".de",
+ L".cz",
+ L".org",
+ L".net",
+ L".su",
+ L".ua",
+ L".tv"
+};
+
+bool IsUrlContains(const wchar_t *Str)
+{
+ if (mir_wstrlen(Str) > 0) {
wchar_t *StrLower = mir_wstrdup(Str);
- CharLowerBuff(StrLower, (int)mir_wstrlen(StrLower));
- for (int i = 0; i < CountUrl; i++)
- if (wcsstr(StrLower, URL[i])) {
+ CharLowerW(StrLower);
+
+ for (auto &it : URL)
+ if (wcsstr(StrLower, it)) {
mir_free(StrLower);
- return 1;
+ return true;
}
mir_free(StrLower);
}
- return 0;
+ return false;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
wstring GetContactUid(MCONTACT hContact, wstring Protocol)
{
char *szProto = mir_utf8encodeW(Protocol.c_str());
diff --git a/plugins/StopSpamMod/src/utilities.h b/plugins/StopSpamMod/src/utilities.h index 5b0d724408..9d2a77fb2b 100644 --- a/plugins/StopSpamMod/src/utilities.h +++ b/plugins/StopSpamMod/src/utilities.h @@ -1,16 +1,15 @@ #pragma once -std::wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const * szModule, char const * szSetting, std::wstring errorValue); -std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const * szModule, char const * szSetting, std::string errorValue); +std::wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const *szModule, char const *szSetting, std::wstring errorValue); +std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const *szModule, char const *szSetting, std::string errorValue); std::wstring &GetDlgItemString(HWND hwnd, int id); std::string &GetProtoList(); bool ProtoInList(const char *szProto); std::wstring variables_parse(std::wstring const &tstrFormat, MCONTACT hContact); const int Stricmp(const wchar_t *str, const wchar_t *substr); -//const int Stristr(const wchar_t *str, const wchar_t *substr); -wchar_t* ReqGetText(DBEVENTINFO* dbei); -BOOL IsUrlContains(wchar_t * Str); -void DeleteCListGroupsByName(wchar_t* szGroupName); + +bool IsUrlContains(const wchar_t *Str); +void DeleteCListGroupsByName(wchar_t *szGroupName); void LogSpamToFile(MCONTACT hContact, std::wstring message); std::string toUTF8(std::wstring str); std::string toUTF8(std::string str); |