diff options
Diffstat (limited to 'plugins/Spamotron/src/bayes.cpp')
-rw-r--r-- | plugins/Spamotron/src/bayes.cpp | 96 |
1 files changed, 48 insertions, 48 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);
}
|