1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

db: log all incoming and outgoing messages

This commit is contained in:
Michael Vetter 2020-03-28 01:16:31 +01:00
parent def2123216
commit a0a4fd0426
6 changed files with 64 additions and 25 deletions

View File

@ -156,38 +156,34 @@ log_database_close(void)
}
}
void
log_database_add_incoming_chat(ProfMessage *message) {
static void
_log_database_add_incoming(ProfMessage *message, const char * const type)
{
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(message, "chat", message->jid->barejid, myjid->barejid);
_add_to_db(message, type, message->jid->barejid, myjid->barejid);
jid_destroy(myjid);
}
void
log_database_add_incoming_chat(ProfMessage *message) {
_log_database_add_incoming(message, "chat");
}
void
log_database_add_incoming_muc(ProfMessage *message) {
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(message, "muc", message->jid->barejid, myjid->barejid);
jid_destroy(myjid);
_log_database_add_incoming(message, "muc");
}
void
log_database_add_incoming_muc_pm(ProfMessage *message) {
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(message, "mucpm", message->jid->barejid, myjid->barejid);
jid_destroy(myjid);
_log_database_add_incoming(message, "mucpm");
}
void
log_database_add_outgoing(const char * const id, const char * const barejid, const char * const message, const char *const replace_id)
static void
_log_database_add_outgoing(const char * const type, const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc)
{
ProfMessage *msg = message_init();
@ -196,16 +192,35 @@ log_database_add_outgoing(const char * const id, const char * const barejid, con
msg->plain = message ? strdup(message) : NULL;
msg->replace_id = replace_id ? strdup(replace_id) : NULL;
msg->timestamp = g_date_time_new_now_local(); //TODO: get from outside. best to have whole ProfMessage from outside
msg->enc = enc;
const char *jid = connection_get_fulljid();
Jid *myjid = jid_create(jid);
_add_to_db(msg, "chat", myjid->barejid, msg->jid->barejid);
_add_to_db(msg, type, myjid->barejid, msg->jid->barejid);
jid_destroy(myjid);
message_free(msg);
}
void
log_database_add_outgoing_chat(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc)
{
_log_database_add_outgoing("chat", id, barejid, message, replace_id, enc);
}
void
log_database_add_outgoing_muc(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc)
{
_log_database_add_outgoing("muc", id, barejid, message, replace_id, enc);
}
void
log_database_add_outgoing_muc_pm(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc)
{
_log_database_add_outgoing("mucpm", id, barejid, message, replace_id, enc);
}
static void
_add_to_db(ProfMessage *message, const char * const type, const char * const from_jid, const char * const to_jid)
{

View File

@ -44,7 +44,9 @@ gboolean log_database_init(ProfAccount *account);
void log_database_add_incoming_chat(ProfMessage *message);
void log_database_add_incoming_muc(ProfMessage *message);
void log_database_add_incoming_muc_pm(ProfMessage *message);
void log_database_add_outgoing(const char * const id, const char * const barejid, const char * const message, const char *const replace_id);
void log_database_add_outgoing_chat(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc);
void log_database_add_outgoing_muc(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc);
void log_database_add_outgoing_muc_pm(const char * const id, const char * const barejid, const char * const message, const char *const replace_id, prof_enc_t enc);
void log_database_close(void);
#endif // DATABASE_H

View File

@ -139,6 +139,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
free(id);
} else {
@ -146,6 +147,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
}
@ -166,6 +168,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt);
free(id);
}
@ -184,11 +187,13 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
}
@ -207,11 +212,13 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (chatwin->is_omemo) {
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
}
@ -230,6 +237,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (chatwin->is_omemo) {
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
free(id);
} else {
@ -237,6 +245,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
}
@ -256,16 +265,19 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (chatwin->is_omemo) {
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
free(id);
} else if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
}
@ -284,11 +296,13 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (chatwin->is_omemo) {
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
free(id);
} else if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
free(id);
} else {
@ -296,7 +310,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing(id, chatwin->barejid, plugin_msg, replace_id);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
}
@ -315,6 +329,7 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
#ifndef HAVE_OMEMO
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
free(id);
@ -349,11 +364,13 @@ cl_ev_send_muc_msg_corrected(ProfMucWin *mucwin, const char *const msg, const ch
if (mucwin->is_omemo) {
char *id = omemo_on_message_send((ProfWin *)mucwin, plugin_msg, FALSE, TRUE, replace_id);
groupchat_log_omemo_msg_out(mucwin->roomjid, plugin_msg);
log_database_add_outgoing_muc(id, mucwin->roomjid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
mucwin_outgoing_msg(mucwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, replace_id);
free(id);
} else {
char *id = message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url, replace_id);
groupchat_log_msg_out(mucwin->roomjid, plugin_msg);
log_database_add_outgoing_muc(id, mucwin->roomjid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
mucwin_outgoing_msg(mucwin, plugin_msg, id, PROF_MSG_ENC_NONE, replace_id);
free(id);
}
@ -366,6 +383,7 @@ cl_ev_send_muc_msg_corrected(ProfMucWin *mucwin, const char *const msg, const ch
#ifndef HAVE_OMEMO
char *id = message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url, replace_id);
groupchat_log_msg_out(mucwin->roomjid, plugin_msg);
log_database_add_outgoing_muc(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
mucwin_outgoing_msg(mucwin, plugin_msg, id, PROF_MSG_ENC_NONE, replace_id);
free(id);
@ -392,9 +410,11 @@ cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg, const char *
char *plugin_msg = plugins_pre_priv_message_send(privwin->fulljid, msg);
Jid *jidp = jid_create(privwin->fulljid);
message_send_private(privwin->fulljid, plugin_msg, oob_url);
char *id = message_send_private(privwin->fulljid, plugin_msg, oob_url);
chat_log_msg_out(jidp->barejid, plugin_msg, jidp->resourcepart);
log_database_add_outgoing_muc_pm(id, privwin->fulljid, plugin_msg, NULL, PROF_MSG_ENC_NONE);
privwin_outgoing_msg(privwin, plugin_msg);
free(id);
plugins_post_priv_message_send(privwin->fulljid, plugin_msg);

View File

@ -40,6 +40,7 @@
#include <glib.h>
#include "log.h"
#include "database.h"
#include "config/preferences.h"
#include "config/files.h"
#include "otr/otr.h"
@ -348,6 +349,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char *const message, gboolean re
if (encrypted) {
id = message_send_chat_otr(chatwin->barejid, encrypted, request_receipt, replace_id);
chat_log_otr_msg_out(chatwin->barejid, message, NULL);
log_database_add_outgoing_chat(id, chatwin->barejid, message, replace_id, PROF_MSG_ENC_OTR);
chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_ENC_OTR, request_receipt, replace_id);
otr_free_message(encrypted);
free(id);

View File

@ -508,7 +508,7 @@ message_send_chat_omemo(const char *const jid, uint32_t sid, GList *keys,
}
#endif
void
char*
message_send_private(const char *const fulljid, const char *const msg, const char *const oob_url)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
@ -517,14 +517,14 @@ message_send_private(const char *const fulljid, const char *const msg, const cha
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id);
xmpp_message_set_body(message, msg);
free(id);
if (oob_url) {
stanza_attach_x_oob_url(ctx, message, oob_url);
}
_send_message_stanza(message);
xmpp_stanza_release(message);
return id;
}
char*

View File

@ -175,7 +175,7 @@ char* message_send_chat(const char *const barejid, const char *const msg, const
char* message_send_chat_otr(const char *const barejid, const char *const msg, gboolean request_receipt, const char *const replace_id);
char* message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean request_receipt, const char *const replace_id);
char* message_send_chat_omemo(const char *const jid, uint32_t sid, GList *keys, const unsigned char *const iv, size_t iv_len, const unsigned char *const ciphertext, size_t ciphertext_len, gboolean request_receipt, gboolean muc, const char *const replace_id);
void message_send_private(const char *const fulljid, const char *const msg, const char *const oob_url);
char* message_send_private(const char *const fulljid, const char *const msg, const char *const oob_url);
char* message_send_groupchat(const char *const roomjid, const char *const msg, const char *const oob_url, const char *const replace_id);
void message_send_groupchat_subject(const char *const roomjid, const char *const subject);
void message_send_inactive(const char *const jid);