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

Log incoming MUC messages if origin-id sais they dont come from us

Regards https://github.com/profanity-im/profanity/issues/1201
This commit is contained in:
Michael Vetter 2019-10-18 10:40:24 +02:00
parent 53640f6e97
commit 430b2eaa0d
3 changed files with 29 additions and 12 deletions

View File

@ -49,6 +49,7 @@
#include "event/common.h"
#include "plugins/plugins.h"
#include "ui/window_list.h"
#include "xmpp/connection.h"
#include "xmpp/muc.h"
#include "xmpp/chat_session.h"
#include "xmpp/roster_list.h"
@ -294,8 +295,25 @@ sv_ev_room_message(ProfMessage *message)
char *mynick = muc_nick(mucwin->roomjid);
// only log messages from others. we log our own via mucwin_outgoing_msg()
if (g_strcmp0(mynick, message->jid->resourcepart) != 0) {
// messages from ourselves
if (g_strcmp0(mynick, message->jid->resourcepart) == 0) {
// test if message was sent from this client
// we check the </origin-id> for this we calculate a hash into it so we can detect
// whether this client sent it. See connection_create_stanza_id()
gsize tmp_len;
char *tmp = (char*)g_base64_decode(message->id, &tmp_len);
if (tmp_len > 10) {
// log if not from this client
if (g_strcmp0(&tmp[10], connection_get_profanity_identifier()) != 0) {
if (message->enc == PROF_MSG_ENC_OMEMO) {
groupchat_log_omemo_msg_in(message->jid->barejid, message->jid->resourcepart, (char*)tmp);
} else {
groupchat_log_msg_in(message->jid->barejid, message->jid->resourcepart, message->plain);
}
}
}
// messages from others
} else {
if (message->enc == PROF_MSG_ENC_OMEMO) {
groupchat_log_omemo_msg_in(message->jid->barejid, message->jid->resourcepart, message->plain);
} else {

View File

@ -458,24 +458,17 @@ connection_free_uuid(char *uuid)
char*
connection_create_stanza_id(void)
{
unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE);
char *msgid = get_random_string(10);
assert(digest != NULL);
assert(msgid != NULL);
GString *signature = g_string_new("");
g_string_printf(signature, "%s%s", prof_identifier, msgid);
xmpp_sha1_digest((unsigned char*)signature->str, strlen(signature->str), digest);
g_string_printf(signature, "%s%s", msgid, prof_identifier);
char *b64 = g_base64_encode((unsigned char*)signature->str, signature->len);
g_string_free(signature, TRUE);
GString *id = g_string_new("");
g_string_printf(id, "%s%s", digest, msgid);
char *b64 = g_base64_encode((unsigned char*)id->str, XMPP_SHA1_DIGEST_SIZE);
g_string_free(id, TRUE);
assert(b64 != NULL);
free(digest);
return b64;
}
@ -687,3 +680,7 @@ static void _calculate_identifier(const char *barejid)
prof_identifier = b64;
}
char *connection_get_profanity_identifier(void) {
return prof_identifier;
}

View File

@ -64,4 +64,6 @@ void connection_remove_available_resource(const char *const resource);
char* connection_create_stanza_id(void);
char *connection_get_profanity_identifier(void);
#endif