diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/database.c | 30 | ||||
-rw-r--r-- | src/database.h | 1 | ||||
-rw-r--r-- | src/event/server_events.c | 9 |
3 files changed, 40 insertions, 0 deletions
diff --git a/src/database.c b/src/database.c index 2d857d08..7c84ee33 100644 --- a/src/database.c +++ b/src/database.c @@ -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); +} diff --git a/src/database.h b/src/database.h index 11560385..fc95b7d0 100644 --- a/src/database.h +++ b/src/database.h @@ -38,6 +38,7 @@ bool log_database_init(void); void log_database_close(void); +void log_database_add(ProfMessage *message); #endif // DATABASE_H diff --git a/src/event/server_events.c b/src/event/server_events.c index ea4277b2..6c7d0430 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -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); |