From fe8cad9c083c13e3556ae0babaa1eff049ee4551 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 5 Oct 2013 15:55:44 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@6348 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/StopSpamPlus/src/eventhooker.cpp | 2 +- plugins/StopSpamPlus/src/events.cpp | 97 ++++++++++++-------------------- plugins/StopSpamPlus/src/opt_proto.cpp | 6 +- plugins/StopSpamPlus/src/settings.cpp | 4 +- plugins/StopSpamPlus/src/stopspam.cpp | 4 +- plugins/StopSpamPlus/src/utils.cpp | 2 +- 6 files changed, 44 insertions(+), 71 deletions(-) diff --git a/plugins/StopSpamPlus/src/eventhooker.cpp b/plugins/StopSpamPlus/src/eventhooker.cpp index 82db13b7e8..56493eaa76 100644 --- a/plugins/StopSpamPlus/src/eventhooker.cpp +++ b/plugins/StopSpamPlus/src/eventhooker.cpp @@ -42,7 +42,7 @@ namespace miranda void EventHooker::Unhook() { - if(handle_) + if (handle_) { UnhookEvent(handle_); handle_ = 0; diff --git a/plugins/StopSpamPlus/src/events.cpp b/plugins/StopSpamPlus/src/events.cpp index 1f1ef5caf1..3f9c7bb1d7 100644 --- a/plugins/StopSpamPlus/src/events.cpp +++ b/plugins/StopSpamPlus/src/events.cpp @@ -10,78 +10,61 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam) if (-1 == dbei.cbBlob) return 0; - dbei.pBlob = new BYTE[dbei.cbBlob]; + mir_ptr blob((LPBYTE)mir_alloc(dbei.cbBlob)); + dbei.pBlob = blob; db_event_get(hDbEvent, &dbei); // if event is in protocol that is not despammed - if(plSets->ProtoDisabled(dbei.szModule)) { - delete [] dbei.pBlob; + if (plSets->ProtoDisabled(dbei.szModule)) return 0; - } // event is an auth request - if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) - { + if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) { HANDLE hcntct = DbGetAuthEventContact(&dbei); // if request is from unknown or not marked Answered contact //and if I don't sent message to this contact - - if(db_get_b(hcntct, "CList", "NotOnList", 0) && - !db_get_b(hcntct, pluginName, answeredSetting, 0) && - !IsExistMyMessage(hcntct)) - { - if (!plSets->HandleAuthReq.Get()) - { - - char * buf=mir_utf8encodeW(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str()); - CallContactService(hcntct, PSS_MESSAGE, PREF_UTF, (LPARAM)buf); - mir_free(buf); - + if (db_get_b(hcntct, "CList", "NotOnList", 0) && !db_get_b(hcntct, pluginName, answeredSetting, 0) && !IsExistMyMessage(hcntct)) { + if (!plSets->HandleAuthReq.Get()) { + char *buf = mir_utf8encodeW(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str()); + CallContactService(hcntct, PSS_MESSAGE, PREF_UTF, (LPARAM)buf); + mir_free(buf); } - char *AuthRepl; - - AuthRepl=mir_u2a(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str()); // ...send message - std::string allowService = dbei.szModule; - allowService += PS_AUTHDENY; - CallService(allowService.c_str(), (WPARAM)hDbEvent, (LPARAM)AuthRepl); - - mir_free(AuthRepl); + char *AuthRepl = mir_u2a(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str()); + ProtoCallService(dbei.szModule, PS_AUTHDENY, (WPARAM)hDbEvent, (LPARAM)AuthRepl); + mir_free(AuthRepl); db_set_b(hcntct, "CList", "NotOnList", 1); db_set_b(hcntct, "CList", "Hidden", 1); if (!plSets->HistLog.Get()) db_event_delete(0, hDbEvent); - delete [] dbei.pBlob; return 1; } } - delete [] dbei.pBlob; return 0; } MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) { HANDLE hContact = (HANDLE)w; - - if (!l) //fix potential DEP crash + DBEVENTINFO *dbei = (DBEVENTINFO*)l; + if (dbei == NULL) //fix potential DEP crash return 0; - DBEVENTINFO * dbei = (DBEVENTINFO*)l; // if event is in protocol that is not despammed - if(plSets->ProtoDisabled(dbei->szModule)) + if (plSets->ProtoDisabled(dbei->szModule)) // ...let the event go its way return 0; // if event is not a message, or if the message has been read or sent... - if(dbei->flags & DBEF_SENT || dbei->flags & DBEF_READ || dbei->eventType != EVENTTYPE_MESSAGE ) + if (dbei->flags & DBEF_SENT || dbei->flags & DBEF_READ || dbei->eventType != EVENTTYPE_MESSAGE ) // ...let the event go its way return 0; // if message is from known or marked Answered contact - if(db_get_b(hContact, pluginName, answeredSetting, 0)) + if (db_get_b(hContact, pluginName, answeredSetting, 0)) // ...let the event go its way return 0; @@ -91,7 +74,7 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) return 0; //if I sent message to this contact - if(IsExistMyMessage(hContact)) + if (IsExistMyMessage(hContact)) return 0; // if message is corrupted or empty it cannot be an answer. @@ -101,19 +84,15 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) tstring message; - if(dbei->flags & DBEF_UTF){ + if (dbei->flags & DBEF_UTF){ WCHAR* msg_u=mir_utf8decodeW((char*)dbei->pBlob); - message = msg_u; - mir_free(msg_u); } - else{ - + else { WCHAR* msg_u = mir_a2u((char*)(dbei->pBlob)); message = msg_u; mir_free(msg_u); - } // if message equal right answer... @@ -121,19 +100,13 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) answers.append(plSets->AnswSplitString.Get()); tstring::size_type pos = 0; tstring::size_type prev_pos = 0; - while((pos = answers.find(plSets->AnswSplitString.Get(), pos)) != tstring::npos) - { + while((pos = answers.find(plSets->AnswSplitString.Get(), pos)) != tstring::npos) { // get one of answers and trim witespace chars - tstring answer = trim(answers.substr(prev_pos, pos - prev_pos)); + tstring answer = trim(answers.substr(prev_pos, pos - prev_pos)); // if answer not empty - if (answer.length() > 0) - { + if (answer.length() > 0) { // if message equal right answer... - if (plSets->AnswNotCaseSens.Get() ? - !lstrcmpi(message.c_str(), answer.c_str()) : - !lstrcmp(message.c_str(), answer.c_str()) - ) - { + if (plSets->AnswNotCaseSens.Get() ? !lstrcmpi(message.c_str(), answer.c_str()) : !lstrcmp(message.c_str(), answer.c_str())) { // unhide contact db_unset(hContact, "CList", "Hidden"); @@ -141,7 +114,7 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) db_set_b(hContact, pluginName, answeredSetting, 1); //add contact permanently - if(plSets->AddPermanent.Get()) + if (plSets->AddPermanent.Get()) db_unset(hContact, "CList", "NotOnList"); // send congratulation @@ -154,12 +127,12 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) return 1; } } - prev_pos = ++pos; - } + prev_pos = ++pos; + } // if message message does not contain infintite talk protection prefix // and question count for this contact is less then maximum - if ( (!plSets->InfTalkProtection.Get() || tstring::npos==message.find(infTalkProtPrefix)) + if ((!plSets->InfTalkProtection.Get() || tstring::npos == message.find(infTalkProtPrefix)) && (!plSets->MaxQuestCount.Get() || db_get_dw(hContact, pluginName, questCountSetting, 0) < plSets->MaxQuestCount.Get())) { // send question @@ -174,9 +147,9 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) // increment question count DWORD questCount = db_get_dw(hContact, pluginName, questCountSetting, 0); db_set_dw(hContact, pluginName, questCountSetting, questCount + 1); - - // hide contact from contact list } + + // hide contact from contact list db_set_b(hContact, "CList", "NotOnList", 1); db_set_b(hContact, "CList", "Hidden", 1); @@ -216,15 +189,15 @@ MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l) MIRANDA_HOOK_EVENT(ME_DB_CONTACT_SETTINGCHANGED, w, l) { HANDLE hContact = (HANDLE)w; - DBCONTACTWRITESETTING * cws = (DBCONTACTWRITESETTING*)l; + DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)l; // if CList/NotOnList is being deleted then remove answeredSetting - if(strcmp(cws->szModule, "CList")) + if (strcmp(cws->szModule, "CList")) return 0; - if(strcmp(cws->szSetting, "NotOnList")) + if (strcmp(cws->szSetting, "NotOnList")) return 0; - if (!cws->value.type) - { + + if (!cws->value.type) { db_unset(hContact, pluginName, answeredSetting); db_unset(hContact, pluginName, questCountSetting); } diff --git a/plugins/StopSpamPlus/src/opt_proto.cpp b/plugins/StopSpamPlus/src/opt_proto.cpp index bb56aca7ba..86ba136999 100644 --- a/plugins/StopSpamPlus/src/opt_proto.cpp +++ b/plugins/StopSpamPlus/src/opt_proto.cpp @@ -24,11 +24,11 @@ int FillTree(HWND hwnd) TreeView_DeleteAllItems(hwnd); - if(CallService(MS_PROTO_ENUMACCOUNTS, (LPARAM)&n, (WPARAM)&pa)) + if (CallService(MS_PROTO_ENUMACCOUNTS, (LPARAM)&n, (WPARAM)&pa)) return FALSE; for ( i = 0; i < n; i++ ) { - if(IsAccountEnabled( pa[i] )) { + if (IsAccountEnabled( pa[i] )) { PD = ( ProtocolData* )mir_alloc( sizeof( ProtocolData )); PD->RealName = pa[i]->szModuleName; PD->enabled = IsProtoIM( pa[i]); @@ -88,7 +88,7 @@ INT_PTR CALLBACK ProtoDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if (tvi.lParam!=0) { ProtocolData* ppd = ( ProtocolData* )tvi.lParam; - if(ppd->enabled && ppd->show) + if (ppd->enabled && ppd->show) out << ppd->RealName << " "; } diff --git a/plugins/StopSpamPlus/src/settings.cpp b/plugins/StopSpamPlus/src/settings.cpp index 52dcc274a2..bb061256cb 100644 --- a/plugins/StopSpamPlus/src/settings.cpp +++ b/plugins/StopSpamPlus/src/settings.cpp @@ -4,7 +4,7 @@ tstring db_usage::DBGetPluginSetting(std::string const &name, tstring const &defValue) { DBVARIANT dbv; - if(db_get_ts(NULL, pluginName, name.c_str(), &dbv)) + if (db_get_ts(NULL, pluginName, name.c_str(), &dbv)) return defValue; tstring value = dbv.ptszVal; db_free(&dbv); @@ -15,7 +15,7 @@ tstring db_usage::DBGetPluginSetting(std::string const &name, tstring const &def std::string db_usage::DBGetPluginSetting(std::string const &name, std::string const &defValue) { DBVARIANT dbv; - if(db_get_s(NULL, pluginName, name.c_str(), &dbv)) + if (db_get_s(NULL, pluginName, name.c_str(), &dbv)) return defValue; std::string value = dbv.pszVal; db_free(&dbv); diff --git a/plugins/StopSpamPlus/src/stopspam.cpp b/plugins/StopSpamPlus/src/stopspam.cpp index ddfc002053..0a5d5b046f 100644 --- a/plugins/StopSpamPlus/src/stopspam.cpp +++ b/plugins/StopSpamPlus/src/stopspam.cpp @@ -64,12 +64,12 @@ extern "C" int __declspec(dllexport) Unload(void) { miranda::EventHooker::UnhookAll(); - if(hFunc) + if (hFunc) { DestroyServiceFunction(hFunc); hFunc = 0; } - if(hTempRemove) + if (hTempRemove) { DestroyServiceFunction(hTempRemove); hFunc = 0; diff --git a/plugins/StopSpamPlus/src/utils.cpp b/plugins/StopSpamPlus/src/utils.cpp index ca4c46c292..d6faed1bfc 100644 --- a/plugins/StopSpamPlus/src/utils.cpp +++ b/plugins/StopSpamPlus/src/utils.cpp @@ -20,7 +20,7 @@ bool IsExistMyMessage(HANDLE hContact) if (db_event_get(hDbEvent, &dbei)) break; - if(dbei.flags & DBEF_SENT){ + if (dbei.flags & DBEF_SENT){ // mark contact as Answered db_set_b(hContact, pluginName, answeredSetting, 1); // ...let the event go its way -- cgit v1.2.3