1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

database: log incoming messages

First trial. Not covering all cases yet.
This commit is contained in:
Michael Vetter 2020-03-19 12:10:54 +01:00
parent a7163b24f3
commit 8045a32c4a
3 changed files with 40 additions and 0 deletions

View File

@ -33,10 +33,15 @@
*
*/
#define _GNU_SOURCE 1
#include <sqlite3.h>
#include <stdio.h>
#include <glib.h>
#include "log.h"
#include "config/files.h"
#include "xmpp/xmpp.h"
static sqlite3 *g_chatlog_database;
@ -84,3 +89,28 @@ log_database_close(void)
sqlite3_close(g_chatlog_database);
sqlite3_shutdown();
}
void
log_database_add(ProfMessage *message) {
char *err_msg;
char *query;
//gchar *date_fmt = g_date_time_format_iso8601(message->timestamp);
gchar *date_fmt = g_date_time_format(message->timestamp, "%Y/%m/%d %H:%M:%S");
if (asprintf(&query, "INSERT INTO `ChatLogs` (`jid`, `message`, `timestamp`) VALUES ('%s', '%s', '%s')",
message->jid->barejid, message->plain, date_fmt) == -1) {
log_error("log_database_add(): could not allocate memory");
return;
}
g_free(date_fmt);
if( SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
if (err_msg) {
log_error("SQLite error: %s", err_msg);
sqlite3_free(err_msg);
} else {
log_error("Unknown SQLite error");
}
}
free(query);
}

View File

@ -38,6 +38,7 @@
bool log_database_init(void);
void log_database_close(void);
void log_database_add(ProfMessage *message);
#endif // DATABASE_H

View File

@ -42,6 +42,7 @@
#include "profanity.h"
#include "log.h"
#include "database.h"
#include "config/preferences.h"
#include "config/tlscerts.h"
#include "config/account.h"
@ -324,6 +325,7 @@ sv_ev_room_message(ProfMessage *message)
GList *triggers = prefs_message_get_triggers(message->plain);
_clean_incoming_message(message);
log_database_add(message);
mucwin_incoming_msg(mucwin, message, mentions, triggers, TRUE);
g_slist_free(mentions);
@ -397,6 +399,7 @@ sv_ev_incoming_private_message(ProfMessage *message)
}
_clean_incoming_message(message);
log_database_add(message);
privwin_incoming_msg(privatewin, message);
chat_log_msg_in(message);
@ -420,6 +423,7 @@ sv_ev_delayed_private_message(ProfMessage *message)
}
_clean_incoming_message(message);
log_database_add(message);
privwin_incoming_msg(privatewin, message);
chat_log_msg_in(message);
@ -532,6 +536,7 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
if (message->plain) {
message->enc = PROF_MSG_ENC_PGP;
_clean_incoming_message(message);
log_database_add(message);
chatwin_incoming_msg(chatwin, message, new_win);
if (logit) {
chat_log_pgp_msg_in(message);
@ -547,6 +552,7 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
message->enc = PROF_MSG_ENC_PLAIN;
message->plain = strdup(message->body);
_clean_incoming_message(message);
log_database_add(message);
chatwin_incoming_msg(chatwin, message, new_win);
chat_log_msg_in(message);
chatwin->pgp_recv = FALSE;
@ -569,6 +575,7 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
}
_clean_incoming_message(message);
log_database_add(message);
chatwin_incoming_msg(chatwin, message, new_win);
chat_log_otr_msg_in(message);
@ -584,6 +591,7 @@ static void
_sv_ev_incoming_omemo(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message, gboolean logit)
{
_clean_incoming_message(message);
log_database_add(message);
chatwin_incoming_msg(chatwin, message, new_win);
if (logit) {
chat_log_omemo_msg_in(message);
@ -599,6 +607,7 @@ _sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, ProfMessage *messa
message->enc = PROF_MSG_ENC_PLAIN;
message->plain = strdup(message->body);
_clean_incoming_message(message);
log_database_add(message);
chatwin_incoming_msg(chatwin, message, new_win);
if (logit) {
chat_log_msg_in(message);