diff options
author | Goraf <22941576+Goraf@users.noreply.github.com> | 2017-11-13 15:03:31 +0100 |
---|---|---|
committer | Goraf <22941576+Goraf@users.noreply.github.com> | 2017-11-13 15:07:33 +0100 |
commit | a7c24ca48995cf2bf436156302f96b91bf135409 (patch) | |
tree | 953835509ff1b778833e78fd7b74b05e05e77c84 /plugins/Spamotron | |
parent | 591ec17b1c99db7f120c22ca9fb20ae05fe78325 (diff) |
Code modernize ...
* replace 0/NULL with nullptr [using clang-tidy]
Diffstat (limited to 'plugins/Spamotron')
-rw-r--r-- | plugins/Spamotron/src/bayes.cpp | 96 | ||||
-rw-r--r-- | plugins/Spamotron/src/options.cpp | 8 | ||||
-rw-r--r-- | plugins/Spamotron/src/popups.cpp | 12 | ||||
-rw-r--r-- | plugins/Spamotron/src/spamotron.cpp | 40 | ||||
-rw-r--r-- | plugins/Spamotron/src/utils.cpp | 126 |
5 files changed, 141 insertions, 141 deletions
diff --git a/plugins/Spamotron/src/bayes.cpp b/plugins/Spamotron/src/bayes.cpp index aa377760a7..dc4d23e635 100644 --- a/plugins/Spamotron/src/bayes.cpp +++ b/plugins/Spamotron/src/bayes.cpp @@ -22,7 +22,7 @@ int CheckBayes() if (ServiceExists(MS_FOLDERS_REGISTER_PATH)) {
hBayesFolder = FoldersRegisterCustomPath(PLUGIN_NAME, Translate("Bayes database path"), bayesdb_tmp);
- } else hBayesFolder = 0;
+ } else hBayesFolder = nullptr;
if (hBayesFolder)
FoldersGetCustomPath(hBayesFolder, bayesdb_fullpath, MAX_PATH, bayesdb_tmp);
@@ -62,18 +62,18 @@ int OpenBayes() if (sqlite3_open(bayesdb_fullpath_utf8, &bayesdb) == SQLITE_OK)
{
- sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS spam (token blob(16), num int)", NULL, NULL, &errmsg);
- sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS ham (token blob(16), num int)", NULL, NULL, &errmsg);
- sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS stats (key varchar(32), value int)", NULL, NULL, &errmsg);
- sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS queue (contact int, msgtime int, message text)", NULL, NULL, &errmsg);
- sqlite3_prepare_v2(bayesdb, "SELECT count(1) FROM stats WHERE key='spam_msgcount' OR key='ham_msgcount'", -1, &stmt, NULL);
+ sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS spam (token blob(16), num int)", nullptr, nullptr, &errmsg);
+ sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS ham (token blob(16), num int)", nullptr, nullptr, &errmsg);
+ sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS stats (key varchar(32), value int)", nullptr, nullptr, &errmsg);
+ sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS queue (contact int, msgtime int, message text)", nullptr, nullptr, &errmsg);
+ sqlite3_prepare_v2(bayesdb, "SELECT count(1) FROM stats WHERE key='spam_msgcount' OR key='ham_msgcount'", -1, &stmt, nullptr);
if (sqlite3_step(stmt) == SQLITE_ROW)
if (sqlite3_column_int(stmt, 0) != 2) {
- sqlite3_exec(bayesdb, "INSERT INTO stats VALUES ('spam_msgcount', 0)", NULL, NULL, NULL);
- sqlite3_exec(bayesdb, "INSERT INTO stats VALUES ('ham_msgcount', 0)", NULL, NULL, NULL);
+ sqlite3_exec(bayesdb, "INSERT INTO stats VALUES ('spam_msgcount', 0)", nullptr, nullptr, nullptr);
+ sqlite3_exec(bayesdb, "INSERT INTO stats VALUES ('ham_msgcount', 0)", nullptr, nullptr, nullptr);
}
} else {
- MessageBoxA(NULL, bayesdb_fullpath_utf8, "Can't open database", MB_OK);
+ MessageBoxA(nullptr, bayesdb_fullpath_utf8, "Can't open database", MB_OK);
}
mir_free(bayesdb_fullpath_utf8);
@@ -87,8 +87,8 @@ int OpenBayes() bayesdb_fullpath_utf8 = mir_utf8encode(bayesdb_fullpath);
if (sqlite3_open(bayesdb_fullpath_utf8, &bayesdbg) == SQLITE_OK)
{
- sqlite3_exec(bayesdbg, "CREATE TABLE spam (token varchar(50), num int)", NULL, NULL, &errmsg);
- sqlite3_exec(bayesdbg, "CREATE TABLE ham (token varchar(50), num int)", NULL, NULL, &errmsg);
+ sqlite3_exec(bayesdbg, "CREATE TABLE spam (token varchar(50), num int)", nullptr, nullptr, &errmsg);
+ sqlite3_exec(bayesdbg, "CREATE TABLE ham (token varchar(50), num int)", nullptr, nullptr, &errmsg);
}
mir_free(bayesdb_fullpath_utf8);
#endif
@@ -108,10 +108,10 @@ int get_token_count(int type) int count = 0;
sqlite3_stmt *stmt;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
return 0;
mir_snprintf(q, "SELECT COUNT(1) FROM %s", type == SPAM ? "spam" : "ham");
- sqlite3_prepare_v2(bayesdb, q, -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, q, -1, &stmt, nullptr);
if (sqlite3_step(stmt) == SQLITE_ROW) {
count = sqlite3_column_int(stmt, 0);
}
@@ -124,10 +124,10 @@ int get_msg_count(int type) int count = 0;
sqlite3_stmt *stmt;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
return 0;
- sqlite3_prepare_v2(bayesdb, "SELECT value FROM stats WHERE key=?", -1, &stmt, NULL);
- sqlite3_bind_text(stmt, 1, type == SPAM ? "spam_msgcount" : "ham_msgcount", type == SPAM ? 13 : 12, NULL);
+ sqlite3_prepare_v2(bayesdb, "SELECT value FROM stats WHERE key=?", -1, &stmt, nullptr);
+ sqlite3_bind_text(stmt, 1, type == SPAM ? "spam_msgcount" : "ham_msgcount", type == SPAM ? 13 : 12, nullptr);
if (sqlite3_step(stmt) == SQLITE_ROW) {
count = sqlite3_column_int(stmt, 0);
}
@@ -163,12 +163,12 @@ int get_token_score(int type, char *token) BYTE digest[16];
sqlite3_stmt *stmt;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
return 0;
mir_snprintf(sql, "SELECT num FROM %s WHERE token=?", type == SPAM ? "spam" : "ham");
tokenhash(token, digest);
- sqlite3_prepare_v2(bayesdb, sql, -1, &stmt, NULL);
- sqlite3_bind_blob(stmt, 1, digest, 16, NULL);
+ sqlite3_prepare_v2(bayesdb, sql, -1, &stmt, nullptr);
+ sqlite3_bind_blob(stmt, 1, digest, 16, nullptr);
if (sqlite3_step(stmt) == SQLITE_ROW) {
score = sqlite3_column_int(stmt, 0);
@@ -181,10 +181,10 @@ double get_msg_score(wchar_t *msg) {
char *message, *token;
double spam_prob, ham_prob, tmp1 = 1, tmp2 = 1;
- double *scores = NULL;
+ double *scores = nullptr;
int spam_msgcount, ham_msgcount, n = 0, i;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
return 0;
message = mir_u2a(msg);
@@ -194,7 +194,7 @@ double get_msg_score(wchar_t *msg) while (token)
{
if (!is_token_valid(token)) {
- token = strtok(NULL, DELIMS);
+ token = strtok(nullptr, DELIMS);
continue;
}
scores = (double*)realloc(scores, sizeof(double)*(n + 1));
@@ -207,7 +207,7 @@ double get_msg_score(wchar_t *msg) ham_prob = ham_prob > 1.0 ? 1.0 : (ham_prob < 0.01 ? 0.01 : ham_prob);
scores[n++] = spam_prob / (spam_prob + ham_prob);
- token = strtok(NULL, DELIMS);
+ token = strtok(nullptr, DELIMS);
}
for (i = 0; i < n; i++) {
@@ -231,14 +231,14 @@ void queue_message(MCONTACT hContact, DWORD msgtime, wchar_t *message) if (_getOptB("BayesEnabled", defaultBayesEnabled) == 0)
return;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
OpenBayes();
- sqlite3_prepare_v2(bayesdb, "INSERT INTO queue VALUES(?,?,?)", -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, "INSERT INTO queue VALUES(?,?,?)", -1, &stmt, nullptr);
sqlite3_bind_int(stmt, 1, (DWORD)hContact);
sqlite3_bind_int(stmt, 2, msgtime);
tmp = mir_u2a(message);
- sqlite3_bind_text(stmt, 3, tmp, (int)mir_strlen(tmp), NULL);
+ sqlite3_bind_text(stmt, 3, tmp, (int)mir_strlen(tmp), nullptr);
sqlite3_step(stmt);
mir_free(tmp);
sqlite3_finalize(stmt);
@@ -251,10 +251,10 @@ void bayes_approve_contact(MCONTACT hContact) int d = 0;
sqlite3_stmt *stmt;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
return;
- sqlite3_prepare_v2(bayesdb, "SELECT message FROM queue WHERE contact=?", -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, "SELECT message FROM queue WHERE contact=?", -1, &stmt, nullptr);
sqlite3_bind_int(stmt, 1, (DWORD)hContact);
while (sqlite3_step(stmt) == SQLITE_ROW)
{
@@ -266,7 +266,7 @@ void bayes_approve_contact(MCONTACT hContact) }
sqlite3_finalize(stmt);
if (d) {
- sqlite3_prepare_v2(bayesdb, "DELETE FROM queue WHERE contact=?", -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, "DELETE FROM queue WHERE contact=?", -1, &stmt, nullptr);
sqlite3_bind_int(stmt, 1, (DWORD)hContact);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
@@ -276,16 +276,16 @@ void bayes_approve_contact(MCONTACT hContact) void dequeue_messages()
{
- time_t t = time(NULL);
+ time_t t = time(nullptr);
sqlite3_stmt *stmt;
const char *message;
wchar_t *messageW;
int d = 0;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
return;
- sqlite3_prepare_v2(bayesdb, "SELECT message FROM queue WHERE msgtime + ? < ?", -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, "SELECT message FROM queue WHERE msgtime + ? < ?", -1, &stmt, nullptr);
sqlite3_bind_int(stmt, 1, _getOptD("BayesWaitApprove", defaultBayesWaitApprove)*86400);
sqlite3_bind_int(stmt, 2, (DWORD)t);
while (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -297,7 +297,7 @@ void dequeue_messages() }
sqlite3_finalize(stmt);
if (d) {
- sqlite3_prepare_v2(bayesdb, "DELETE FROM queue WHERE msgtime + ? < ?", -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, "DELETE FROM queue WHERE msgtime + ? < ?", -1, &stmt, nullptr);
sqlite3_bind_int(stmt, 1, _getOptD("BayesWaitApprove", defaultBayesWaitApprove)*86400);
sqlite3_bind_int(stmt, 2, (DWORD)t);
sqlite3_step(stmt);
@@ -318,7 +318,7 @@ void learn(int type, wchar_t *msg) if (_getOptB("BayesEnabled", defaultBayesEnabled) == 0)
return;
- if (bayesdb == NULL)
+ if (bayesdb == nullptr)
OpenBayes();
message = mir_u2a(msg);
@@ -328,49 +328,49 @@ void learn(int type, wchar_t *msg) mir_snprintf(sql_update, "UPDATE %s SET num=num+1 WHERE token=?", type ? "spam" : "ham");
mir_snprintf(sql_insert, "INSERT INTO %s VALUES(?, 1)", type ? "spam" : "ham");
#ifdef _DEBUG
- sqlite3_exec(bayesdbg, "BEGIN", NULL, NULL, NULL);
+ sqlite3_exec(bayesdbg, "BEGIN", nullptr, nullptr, nullptr);
#endif
- sqlite3_exec(bayesdb, "BEGIN", NULL, NULL, NULL);
+ sqlite3_exec(bayesdb, "BEGIN", nullptr, nullptr, nullptr);
while (tok) {
if (!is_token_valid(tok)) {
- tok = strtok(NULL, DELIMS);
+ tok = strtok(nullptr, DELIMS);
continue;
}
tokenhash(tok, digest);
- sqlite3_prepare_v2(bayesdb, sql_select, -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, sql_select, -1, &stmt, nullptr);
sqlite3_bind_blob(stmt, 1, digest, 16, SQLITE_STATIC);
if (SQLITE_ROW == sqlite3_step(stmt)) {
sqlite3_finalize(stmt);
- sqlite3_prepare_v2(bayesdb, sql_update, -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, sql_update, -1, &stmt, nullptr);
} else {
sqlite3_finalize(stmt);
- sqlite3_prepare_v2(bayesdb, sql_insert, -1, &stmt, NULL);
+ sqlite3_prepare_v2(bayesdb, sql_insert, -1, &stmt, nullptr);
}
sqlite3_bind_blob(stmt, 1, digest, 16, SQLITE_STATIC);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
#ifdef _DEBUG
- sqlite3_prepare_v2(bayesdbg, sql_select, -1, &stmtdbg, NULL);
- sqlite3_bind_text(stmtdbg, 1, tok, (int)mir_strlen(tok), NULL);
+ sqlite3_prepare_v2(bayesdbg, sql_select, -1, &stmtdbg, nullptr);
+ sqlite3_bind_text(stmtdbg, 1, tok, (int)mir_strlen(tok), nullptr);
if (SQLITE_ROW == sqlite3_step(stmtdbg)) {
sqlite3_finalize(stmtdbg);
- sqlite3_prepare_v2(bayesdbg, sql_update, -1, &stmtdbg, NULL);
+ sqlite3_prepare_v2(bayesdbg, sql_update, -1, &stmtdbg, nullptr);
} else {
sqlite3_finalize(stmtdbg);
- sqlite3_prepare_v2(bayesdbg, sql_insert, -1, &stmtdbg, NULL);
+ sqlite3_prepare_v2(bayesdbg, sql_insert, -1, &stmtdbg, nullptr);
}
sqlite3_bind_text(stmtdbg, 1, tok, (int)mir_strlen(tok), SQLITE_STATIC);
sqlite3_step(stmtdbg);
sqlite3_finalize(stmtdbg);
#endif
- tok = strtok(NULL, DELIMS);
+ tok = strtok(nullptr, DELIMS);
}
- sqlite3_exec(bayesdb, sql_counter, NULL, NULL, NULL);
- sqlite3_exec(bayesdb, "COMMIT", NULL, NULL, NULL);
+ sqlite3_exec(bayesdb, sql_counter, nullptr, nullptr, nullptr);
+ sqlite3_exec(bayesdb, "COMMIT", nullptr, nullptr, nullptr);
#ifdef _DEBUG
- sqlite3_exec(bayesdbg, "COMMIT", NULL, NULL, NULL);
+ sqlite3_exec(bayesdbg, "COMMIT", nullptr, nullptr, nullptr);
#endif
mir_free(message);
}
diff --git a/plugins/Spamotron/src/options.cpp b/plugins/Spamotron/src/options.cpp index 1c528f9d52..f4d4733a49 100644 --- a/plugins/Spamotron/src/options.cpp +++ b/plugins/Spamotron/src/options.cpp @@ -83,7 +83,7 @@ BOOL _saveDlgItemScore(HWND hDialog, int controlID, char* option) len = GetWindowTextLength(GetDlgItem(hDialog, controlID));
tmp = (wchar_t *)malloc((len + 1)*sizeof(wchar_t));
GetDlgItemText(hDialog, controlID, tmp, len + 1);
- _setOptD(option, wcstod(tmp, NULL)/SCORE_C);
+ _setOptD(option, wcstod(tmp, nullptr)/SCORE_C);
return TRUE;
}
@@ -374,7 +374,7 @@ INT_PTR CALLBACK DlgProcOptionsQuestion(HWND optDlg, UINT msg, WPARAM wParam, LP break;
}
if (_saveDlgItemResponse(optDlg, IDC_OPT_RESPONSE, "Response") == -1) {
- MessageBox(NULL, TranslateT("Invalid regular expression.\nKeeping previous value."), L"Error", MB_OK);
+ MessageBox(nullptr, TranslateT("Invalid regular expression.\nKeeping previous value."), L"Error", MB_OK);
return FALSE;
}
_saveDlgItemText(optDlg, IDC_OPT_SUCCESS_RESPONSE, "SuccessResponse");
@@ -521,7 +521,7 @@ INT_PTR CALLBACK DlgProcOptionsBayes(HWND optDlg, UINT msg, WPARAM wParam, LPARA GetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, dbuf, len);
mir_snprintf(cbuf, "%0.04f", get_msg_score(dbuf));
SetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, L"");
- MessageBoxA(NULL, cbuf, Translate("Message score"), MB_OK);
+ MessageBoxA(nullptr, cbuf, Translate("Message score"), MB_OK);
free(dbuf);
return FALSE;
@@ -579,7 +579,7 @@ int OnOptInitialize(WPARAM wParam, LPARAM) odp.pszTemplate = MAKEINTRESOURCEA(IDD_SPAMOTRON_POPUPS);
odp.pfnDlgProc = DlgProcOptionsPopups;
odp.szGroup.a = LPGEN("Popups");
- odp.szTab.a = NULL;
+ odp.szTab.a = nullptr;
Options_AddPage(wParam, &odp);
}
return 0;
diff --git a/plugins/Spamotron/src/popups.cpp b/plugins/Spamotron/src/popups.cpp index 27bc8f392b..a5f6afde33 100644 --- a/plugins/Spamotron/src/popups.cpp +++ b/plugins/Spamotron/src/popups.cpp @@ -108,9 +108,9 @@ INT_PTR CALLBACK DlgProcOptionsPopups(HWND optDlg, UINT msg, WPARAM wParam, LPAR return FALSE;
break;
case IDC_OPT_POPUPS_PREVIEW:
- ShowPopupPreview(optDlg, POPUP_BLOCKED, NULL, TranslateT("Message blocked due to preview action"));
- ShowPopupPreview(optDlg, POPUP_APPROVED, NULL, TranslateT("Contact approved due to preview action"));
- ShowPopupPreview(optDlg, POPUP_CHALLENGE, NULL, TranslateT("Challenge sent to preview contact"));
+ ShowPopupPreview(optDlg, POPUP_BLOCKED, nullptr, TranslateT("Message blocked due to preview action"));
+ ShowPopupPreview(optDlg, POPUP_APPROVED, nullptr, TranslateT("Contact approved due to preview action"));
+ ShowPopupPreview(optDlg, POPUP_CHALLENGE, nullptr, TranslateT("Challenge sent to preview contact"));
return FALSE;
}
SendMessage(GetParent(optDlg), PSM_CHANGED, 0, 0);
@@ -155,19 +155,19 @@ int ShowPopupPreview(HWND optDlg, BYTE popupType, wchar_t *line1, wchar_t *line2 case POPUP_BLOCKED:
ppdp.colorText = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_BLOCKED_FOREGROUND,CPM_GETCOLOUR,0,0);
ppdp.colorBack = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_BLOCKED_BACKGROUND,CPM_GETCOLOUR,0,0);
- ppdp.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_BLOCKED_TIMEOUT, NULL, TRUE);
+ ppdp.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_BLOCKED_TIMEOUT, nullptr, TRUE);
ppdp.lchIcon = Skin_LoadIcon(SKINICON_OTHER_DELETE);
break;
case POPUP_APPROVED:
ppdp.colorText = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_FOREGROUND,CPM_GETCOLOUR,0,0);
ppdp.colorBack = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_BACKGROUND,CPM_GETCOLOUR,0,0);
- ppdp.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_APPROVED_TIMEOUT, NULL, TRUE);
+ ppdp.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_APPROVED_TIMEOUT, nullptr, TRUE);
ppdp.lchIcon = Skin_LoadIcon(SKINICON_OTHER_ADDCONTACT);
break;
case POPUP_CHALLENGE:
ppdp.colorText = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_CHALLENGE_FOREGROUND,CPM_GETCOLOUR,0,0);
ppdp.colorBack = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_CHALLENGE_BACKGROUND,CPM_GETCOLOUR,0,0);
- ppdp.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_CHALLENGE_TIMEOUT, NULL, TRUE);
+ ppdp.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_CHALLENGE_TIMEOUT, nullptr, TRUE);
ppdp.lchIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
break;
}
diff --git a/plugins/Spamotron/src/spamotron.cpp b/plugins/Spamotron/src/spamotron.cpp index 3cf7247c4a..f9462b77e6 100644 --- a/plugins/Spamotron/src/spamotron.cpp +++ b/plugins/Spamotron/src/spamotron.cpp @@ -42,7 +42,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) char protoOption[256] = {0};
int buflen = MAX_BUFFER_LENGTH;
wchar_t buf[MAX_BUFFER_LENGTH];
- wchar_t *challengeW = NULL, *tmpW = NULL;
+ wchar_t *challengeW = nullptr, *tmpW = nullptr;
wchar_t mexpr[64];
int maxmsglen = 0, a, b, i;
BOOL bayesEnabled = _getOptB("BayesEnabled", defaultBayesEnabled);
@@ -59,9 +59,9 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) /*** Dequeue and learn messages ***/
if (bayesEnabled && _getOptB("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved))
- if (time(NULL) - last_queue_check > 4*3600) { // dequeue every 4 hours
+ if (time(nullptr) - last_queue_check > 4*3600) { // dequeue every 4 hours
dequeue_messages();
- last_queue_check = time(NULL);
+ last_queue_check = time(nullptr);
}
/*** Check for conditional and unconditional approval ***/
@@ -121,9 +121,9 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) for(a = 4; a > 0; a--)
msgblob += mir_strlen(msgblob)+1;
}
- else msgblob = NULL;
+ else msgblob = nullptr;
- wchar_t *message = NULL;
+ wchar_t *message = nullptr;
if (dbei->flags & DBEF_UTF)
message = mir_utf8decodeW(msgblob);
else
@@ -132,7 +132,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) /*** Check for words in white-list ***/
if (_getOptB("ApproveOnMsgIn", defaultApproveOnMsgIn)) {
wchar_t *whitelist = (wchar_t*)malloc(2048 * sizeof(wchar_t));
- if (whitelist != NULL) {
+ if (whitelist != nullptr) {
_getOptS(whitelist, 2048, "ApproveOnMsgInWordlist", defaultApproveOnMsgInWordlist);
if (_isregex(whitelist)) {
if (_regmatch(message, whitelist))
@@ -140,12 +140,12 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) }
else {
wchar_t *ptok = wcstok(whitelist, L" ");
- while (ptok != NULL) {
+ while (ptok != nullptr) {
if (wcsstr(message, ptok)) {
bCorrectResponse = TRUE;
break;
}
- ptok = wcstok(NULL, L" ");
+ ptok = wcstok(nullptr, L" ");
}
}
free(whitelist);
@@ -205,7 +205,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) break;
case SPAMOTRON_MODE_MATH:
- if (message == NULL)
+ if (message == nullptr)
break;
_itow(_getCOptD(hContact, "ResponseMath", -1), buf, 10);
if (wcsstr(message, buf) && (mir_wstrlen(buf) == mir_wstrlen(message))) {
@@ -227,7 +227,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) T2Utf response(_getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse));
ProtoChainSend(hContact, PSS_MESSAGE, 0, response);
}
- _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), NULL);
+ _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), nullptr);
// Resubmit pending authorization request
if (_getCOptB(hContact, "AuthEventPending", FALSE)) {
@@ -236,7 +236,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) char* szAuthEventModule;
if (db_get(hContact, PLUGIN_NAME, "AuthEvent", &_dbv) == 0) {
DBEVENTINFO *_dbei = (DBEVENTINFO *)malloc(sizeof(DBEVENTINFO));
- if (_dbei != NULL) {
+ if (_dbei != nullptr) {
memcpy(&_dbei->cbBlob, _dbv.pbVal, sizeof(DWORD));
_dbei->eventType = EVENTTYPE_AUTHREQUEST;
_getCOptS(AuthEventModule, 100, hContact, "AuthEventModule", L"ICQ");
@@ -377,7 +377,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) else
_getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge);
_getOptS(buf, buflen, "Response", defaultResponse);
- srand(time(NULL));
+ srand(time(nullptr));
_setCOptD(hContact, "ResponseNum", rand() % get_response_num(buf));
ReplaceVarsNum(challengeW, maxmsglen, _getCOptD(hContact, "ResponseNum", 0));
ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(challengeW));
@@ -407,7 +407,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) db_set_b(hContact, "CList", "Delete", 1);
// Queue user message in Bayes db
- if (bayesEnabled && message != NULL)
+ if (bayesEnabled && message != nullptr)
queue_message(hContact, dbei->timestamp, message);
@@ -421,7 +421,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) _setCOptD(hContact, "MsgSentTime", dbei->timestamp);
// Save Last Msg and update SameMsgCount
- if (message != NULL) {
+ if (message != nullptr) {
if (mir_wstrcmp(_getCOptS(buf, buflen, hContact, "LastInMsg", L""), message) == 0)
_setCOptD(hContact, "SameMsgCount", 1 + _getCOptD(hContact, "SameMsgCount", 0));
else
@@ -429,7 +429,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) _setCOptTS(hContact, "LastInMsg", message);
}
- if (message != NULL)
+ if (message != nullptr)
mir_free(message);
// Finally silently save the message to contact history if corresponding option is set
@@ -437,7 +437,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) if (dbei->eventType == EVENTTYPE_AUTHREQUEST) {
// Save the request to database so that it can be automatically submitted on user approval
PBYTE eventdata = (PBYTE)malloc(sizeof(DWORD) + dbei->cbBlob);
- if (eventdata != NULL && dbei->cbBlob > 0) {
+ if (eventdata != nullptr && dbei->cbBlob > 0) {
memcpy(eventdata, &dbei->cbBlob, sizeof(DWORD));
memcpy(eventdata + sizeof(DWORD), dbei->pBlob, dbei->cbBlob);
db_set_blob(hContact, PLUGIN_NAME, "AuthEvent", eventdata, sizeof(DWORD) + dbei->cbBlob);
@@ -452,7 +452,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) DWORD dbei_size = 3 * sizeof(DWORD) + sizeof(WORD) + dbei->cbBlob + (DWORD)mir_strlen(dbei->szModule) + 1;
PBYTE eventdata = (PBYTE)malloc(dbei_size);
PBYTE pos = eventdata;
- if (eventdata != NULL && dbei->cbBlob > 0) {
+ if (eventdata != nullptr && dbei->cbBlob > 0) {
if (db_get(hContact, PLUGIN_NAME, "LastMsgEvents", &_dbv) == 0) {
eventdata = (PBYTE)realloc(eventdata, dbei_size + _dbv.cpbVal);
pos = eventdata;
@@ -512,14 +512,14 @@ extern "C" __declspec(dllexport) int Load() mir_getLP(&pluginInfo);
pcli = Clist_GetInterface();
- srand((unsigned)time(0));
- bayesdb = NULL;
+ srand((unsigned)time(nullptr));
+ bayesdb = nullptr;
if (_getOptB("BayesEnabled", defaultBayesEnabled)) {
if (CheckBayes()) {
OpenBayes();
if (_getOptB("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) {
dequeue_messages();
- last_queue_check = time(NULL);
+ last_queue_check = time(nullptr);
}
}
}
diff --git a/plugins/Spamotron/src/utils.cpp b/plugins/Spamotron/src/utils.cpp index fd963d0aa5..6084dc7a4d 100644 --- a/plugins/Spamotron/src/utils.cpp +++ b/plugins/Spamotron/src/utils.cpp @@ -4,8 +4,8 @@ wchar_t *_tcstolower(wchar_t *dst) { - if (dst == NULL) - return NULL; + if (dst == nullptr) + return nullptr; SIZE_T dst_len = mir_wstrlen(dst); for (SIZE_T i = 0; i < dst_len; i ++) @@ -15,8 +15,8 @@ wchar_t *_tcstolower(wchar_t *dst) wchar_t *_tcstoupper(wchar_t *dst) { - if (dst == NULL) - return NULL; + if (dst == nullptr) + return nullptr; SIZE_T dst_len = mir_wstrlen(dst); for (SIZE_T i = 0; i < dst_len; i ++) @@ -34,15 +34,15 @@ BOOL _isregex(wchar_t* strSearch) wchar_t regex_parse[] = L"/(.*)/([igsm]*)"; int ovector[9]; - if (strSearch == NULL) + if (strSearch == nullptr) return FALSE; - re = pcre16_compile(regex_parse, 0, &error, &erroroffs, NULL); - if (re == NULL) + re = pcre16_compile(regex_parse, 0, &error, &erroroffs, nullptr); + if (re == nullptr) return FALSE; regex = mir_wstrdup(strSearch); - if (regex == NULL) + if (regex == nullptr) goto err_out; - rc = pcre16_exec(re, NULL, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); + rc = pcre16_exec(re, nullptr, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); if (rc == 3) ret = TRUE; mir_free(regex); @@ -63,17 +63,17 @@ BOOL _isvalidregex(wchar_t* strSearch) wchar_t regex_parse[] = L"/(.*)/([igsm]*)"; int ovector[9]; - if (strSearch == NULL) + if (strSearch == nullptr) return FALSE; - re = pcre16_compile(regex_parse, 0, &error, &erroroffs, NULL); - if (re == NULL) + re = pcre16_compile(regex_parse, 0, &error, &erroroffs, nullptr); + if (re == nullptr) return FALSE; regex = mir_wstrdup(strSearch); - if (regex == NULL) { + if (regex == nullptr) { pcre16_free(re); return FALSE; } - rc = pcre16_exec(re, NULL, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); + rc = pcre16_exec(re, nullptr, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); pcre16_free(re); if (rc != 3) goto err_out; @@ -89,8 +89,8 @@ BOOL _isvalidregex(wchar_t* strSearch) if (wcsstr(mod, L"s")) opts |= PCRE_DOTALL; - re = pcre16_compile(regexp, opts, &error, &erroroffs, NULL); - if (re != NULL) { + re = pcre16_compile(regexp, opts, &error, &erroroffs, nullptr); + if (re != nullptr) { pcre16_free(re); ret = TRUE; } @@ -106,22 +106,22 @@ BOOL _regmatch(wchar_t* str, wchar_t* strSearch) pcre16 *re; const char *error; int erroroffs, rc; - wchar_t *regex, *regexp, *data = NULL, *mod; + wchar_t *regex, *regexp, *data = nullptr, *mod; int opts = 0; wchar_t regex_parse[] = L"^/(.*)/([igsm]*)"; int ovector[9]; - if (str == NULL || strSearch == NULL) + if (str == nullptr || strSearch == nullptr) return FALSE; - re = pcre16_compile(regex_parse, 0, &error, &erroroffs, NULL); - if (re == NULL) + re = pcre16_compile(regex_parse, 0, &error, &erroroffs, nullptr); + if (re == nullptr) return FALSE; // [TODO] and log some error regex = mir_wstrdup(strSearch); - if (regex == NULL) { + if (regex == nullptr) { pcre16_free(re); return FALSE; } - rc = pcre16_exec(re, NULL, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); + rc = pcre16_exec(re, nullptr, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); pcre16_free(re); if (rc != 3) goto err_out; // [TODO] and log some error (better check for valid regex on options save) @@ -131,7 +131,7 @@ BOOL _regmatch(wchar_t* str, wchar_t* strSearch) mod[ovector[5] - ovector[4]] = 0; data = mir_wstrdup(str); - if (data == NULL) + if (data == nullptr) goto err_out; if (wcsstr(mod, L"i")) opts |= PCRE_CASELESS; @@ -140,10 +140,10 @@ BOOL _regmatch(wchar_t* str, wchar_t* strSearch) if (wcsstr(mod, L"s")) opts |= PCRE_DOTALL; - re = pcre16_compile(regexp, opts, &error, &erroroffs, NULL); - if (re == NULL) + re = pcre16_compile(regexp, opts, &error, &erroroffs, nullptr); + if (re == nullptr) goto err_out; - rc = pcre16_exec(re, NULL, data, (int)mir_wstrlen(data), 0, 0, NULL, 0); + rc = pcre16_exec(re, nullptr, data, (int)mir_wstrlen(data), 0, 0, nullptr, 0); pcre16_free(re); if (rc >= 0) ret = TRUE; @@ -164,17 +164,17 @@ int get_response_id(const wchar_t* strvar) wchar_t regex[] = L"^%response([#-_]([0-9]+))?%$"; int ovector[9]; - if (strvar == NULL) + if (strvar == nullptr) return 0; - re = pcre16_compile(regex, 0, &error, &erroroffs, NULL); - if (re == NULL) + re = pcre16_compile(regex, 0, &error, &erroroffs, nullptr); + if (re == nullptr) return 0; // [TODO] and log some error _strvar = mir_wstrdup(strvar); - if (_strvar == NULL) { + if (_strvar == nullptr) { pcre16_free(re); return 0; } - rc = pcre16_exec(re, NULL, _strvar, (int)mir_wstrlen(_strvar), 0, 0, ovector, 9); + rc = pcre16_exec(re, nullptr, _strvar, (int)mir_wstrlen(_strvar), 0, 0, ovector, 9); pcre16_free(re); if (rc < 0) { ret = -1; @@ -193,15 +193,15 @@ int get_response_num(const wchar_t *str) int i = 0; wchar_t *tmp, *strc; - if (str == NULL) + if (str == nullptr) return 0; strc = mir_wstrdup(str); - if (strc == NULL) + if (strc == nullptr) return 0; tmp = wcstok(strc, L"\r\n"); while (tmp) { i ++; - tmp = wcstok(NULL, L"\r\n"); /* Move next. */ + tmp = wcstok(nullptr, L"\r\n"); /* Move next. */ } mir_free(strc); @@ -213,10 +213,10 @@ wchar_t* get_response(wchar_t* dst, unsigned int dstlen, int num) int i = 0; wchar_t *tmp, *src; - if (dst == NULL || dstlen == 0 || num < 0) + if (dst == nullptr || dstlen == 0 || num < 0) return dst; src = (wchar_t*)mir_alloc(MAX_BUFFER_LENGTH * sizeof(wchar_t)); - if (src == NULL) + if (src == nullptr) goto err_out; _getOptS(src, MAX_BUFFER_LENGTH, "Response", defaultResponse); tmp = wcstok(src, L"\r\n"); @@ -227,7 +227,7 @@ wchar_t* get_response(wchar_t* dst, unsigned int dstlen, int num) return dst; } i ++; - tmp = wcstok(NULL, L"\r\n"); /* Move next. */ + tmp = wcstok(nullptr, L"\r\n"); /* Move next. */ } mir_free(src); err_out: @@ -237,19 +237,19 @@ err_out: wchar_t* _tcsstr_cc(wchar_t* str, wchar_t* strSearch, BOOL cc) { - wchar_t *ret = NULL, *_str = NULL, *_strSearch = NULL; + wchar_t *ret = nullptr, *_str = nullptr, *_strSearch = nullptr; if (cc) return wcsstr(str, strSearch); _str = mir_wstrdup(str); - if (_str == NULL) + if (_str == nullptr) goto err_out; _strSearch = mir_wstrdup(strSearch); - if (_strSearch == NULL) + if (_strSearch == nullptr) goto err_out; ret = wcsstr(_tcstolower(_str), _tcstolower(_strSearch)); - if (ret != NULL) + if (ret != nullptr) ret = ((ret - _str) + str); err_out: mir_free(_str); @@ -261,16 +261,16 @@ err_out: BOOL Contains(wchar_t* dst, wchar_t* src) // Checks for occurence of substring from src in dst { BOOL ret = FALSE; - wchar_t *tsrc = NULL, *tdst = NULL, *token, *token_end; + wchar_t *tsrc = nullptr, *tdst = nullptr, *token, *token_end; SIZE_T dst_len; - if (dst == NULL || src == NULL) + if (dst == nullptr || src == nullptr) return FALSE; tsrc = mir_wstrdup(src); - if (tsrc == NULL) + if (tsrc == nullptr) goto err_out; tdst = mir_wstrdup(dst); - if (tdst == NULL) + if (tdst == nullptr) goto err_out; tdst = _tcstoupper(tdst); dst_len = mir_wstrlen(tdst); @@ -291,7 +291,7 @@ BOOL Contains(wchar_t* dst, wchar_t* src) // Checks for occurence of substring f ret = TRUE; break; } - token = wcstok(NULL, L","); /* Move next. */ + token = wcstok(nullptr, L","); /* Move next. */ } err_out: mir_free(tsrc); @@ -326,15 +326,15 @@ wchar_t* ReplaceVar(wchar_t *dst, unsigned int len, const wchar_t *var, const wc wchar_t *var_start; SIZE_T dst_len, var_len, rvar_len; - if (dst == NULL || var == NULL || rvar == NULL) - return NULL; + if (dst == nullptr || var == nullptr || rvar == nullptr) + return nullptr; dst_len = mir_wstrlen(dst); var_len = mir_wstrlen(var); rvar_len = mir_wstrlen(rvar); var_start = wcsstr(dst, var); while (var_start) { if (len < (dst_len + rvar_len - var_len + 1)) - return NULL; /* Out of buf space. */ + return nullptr; /* Out of buf space. */ memmove((var_start + rvar_len), (var_start + var_len), (((dst + dst_len + 1) - (var_start + var_len)) * sizeof(wchar_t))); @@ -362,34 +362,34 @@ wchar_t* ReplaceVarsNum(wchar_t *dst, unsigned int len, int num) pcre16 *re; const char *error; int erroroffs, rc; - wchar_t *_str, *tmp, **r = NULL, **tr, *ttmp, *dstcopy; + wchar_t *_str, *tmp, **r = nullptr, **tr, *ttmp, *dstcopy; wchar_t regex[] = L"%response([#-_]([0-9]+))?%"; int ovector[9]; - re = pcre16_compile(regex, 0, &error, &erroroffs, NULL); - if (re == NULL) + re = pcre16_compile(regex, 0, &error, &erroroffs, nullptr); + if (re == nullptr) return FALSE; // [TODO] and log some error _getOptS(response, _countof(response), "Response", defaultResponse); ttmp = wcstok(response, L"\r\n"); - for (i = 0; ttmp != NULL; i ++) { + for (i = 0; ttmp != nullptr; i ++) { tr = (wchar_t**)mir_realloc(r, ((i + 1) * sizeof(wchar_t*))); - if (tr == NULL) + if (tr == nullptr) goto err_out; r = tr; r[i] = ttmp; - ttmp = wcstok(NULL, L"\r\n"); /* Move next. */ + ttmp = wcstok(nullptr, L"\r\n"); /* Move next. */ } do { _str = mir_wstrdup(dst); dstcopy = mir_wstrdup(dst); - if (_str == NULL || dstcopy == NULL) { + if (_str == nullptr || dstcopy == nullptr) { mir_free(_str); mir_free(dstcopy); goto err_out; } - rc = pcre16_exec(re, NULL, _str, (int)mir_wstrlen(_str), 0, 0, ovector, 9); + rc = pcre16_exec(re, nullptr, _str, (int)mir_wstrlen(_str), 0, 0, ovector, 9); if (rc < 0) { ret = -1; } else if (rc == 3) { @@ -432,7 +432,7 @@ int _notify(MCONTACT hContact, BYTE type, wchar_t *message, wchar_t *origmessage if (_getOptB("LogActions", defaultLogActions)) { tmp = mir_u2a(msg); tmporig = mir_u2a(origmessage); - LogToSystemHistory(tmp, origmessage ? tmporig : NULL); + LogToSystemHistory(tmp, origmessage ? tmporig : nullptr); mir_free(tmp); mir_free(tmporig); } @@ -440,15 +440,15 @@ int _notify(MCONTACT hContact, BYTE type, wchar_t *message, wchar_t *origmessage if (_NOTIFYP) { if (type == POPUP_BLOCKED) { if (_getOptB("NotifyPopupBlocked", defaultNotifyPopupBlocked)) - ShowPopup(hContact, type, NULL, msg); + ShowPopup(hContact, type, nullptr, msg); } else if (type == POPUP_APPROVED) { if (_getOptB("NotifyPopupApproved", defaultNotifyPopupApproved)) - ShowPopup(hContact, type, NULL, msg); + ShowPopup(hContact, type, nullptr, msg); } else if (type == POPUP_CHALLENGE) { if (_getOptB("NotifyPopupChallenge", defaultNotifyPopupChallenge)) - ShowPopup(hContact, type, NULL, msg); + ShowPopup(hContact, type, nullptr, msg); } else { - ShowPopup(hContact, type, NULL, msg); + ShowPopup(hContact, type, nullptr, msg); } } return 0; @@ -459,7 +459,7 @@ int LogToSystemHistory(char *message, char *origmessage) char msg[MAX_BUFFER_LENGTH]; time_t tm; - if (message == NULL) + if (message == nullptr) return 0; DBEVENTINFO dbei = {}; |